2026-01-26 16:11:55 +02:00
|
|
|
import {
|
2026-01-30 14:19:56 +02:00
|
|
|
type CreateSnapshotRequest,
|
|
|
|
|
type CreateSnapshotResponse,
|
|
|
|
|
createSnapshotRequest,
|
|
|
|
|
createSnapshotResponse,
|
|
|
|
|
type DeleteSnapshotRequest,
|
|
|
|
|
deleteSnapshotRequest,
|
2026-02-02 15:43:07 +02:00
|
|
|
type ListSearchSpaceSnapshotsRequest,
|
|
|
|
|
type ListSearchSpaceSnapshotsResponse,
|
2026-01-30 14:19:56 +02:00
|
|
|
type ListSnapshotsRequest,
|
|
|
|
|
type ListSnapshotsResponse,
|
2026-02-02 15:43:07 +02:00
|
|
|
listSearchSpaceSnapshotsRequest,
|
|
|
|
|
listSearchSpaceSnapshotsResponse,
|
2026-01-30 14:19:56 +02:00
|
|
|
listSnapshotsRequest,
|
|
|
|
|
listSnapshotsResponse,
|
2026-01-26 16:11:55 +02:00
|
|
|
} from "@/contracts/types/chat-threads.types";
|
|
|
|
|
import { ValidationError } from "../error";
|
|
|
|
|
import { baseApiService } from "./base-api.service";
|
|
|
|
|
|
|
|
|
|
class ChatThreadsApiService {
|
|
|
|
|
/**
|
2026-01-30 14:19:56 +02:00
|
|
|
* Create a public snapshot for a thread.
|
2026-01-26 16:11:55 +02:00
|
|
|
*/
|
2026-01-30 14:19:56 +02:00
|
|
|
createSnapshot = async (request: CreateSnapshotRequest): Promise<CreateSnapshotResponse> => {
|
|
|
|
|
const parsed = createSnapshotRequest.safeParse(request);
|
2026-01-26 16:11:55 +02:00
|
|
|
|
|
|
|
|
if (!parsed.success) {
|
|
|
|
|
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
|
|
|
|
|
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-30 14:19:56 +02:00
|
|
|
return baseApiService.post(
|
|
|
|
|
`/api/v1/threads/${parsed.data.thread_id}/snapshots`,
|
|
|
|
|
createSnapshotResponse
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* List all snapshots for a thread.
|
|
|
|
|
*/
|
|
|
|
|
listSnapshots = async (request: ListSnapshotsRequest): Promise<ListSnapshotsResponse> => {
|
|
|
|
|
const parsed = listSnapshotsRequest.safeParse(request);
|
|
|
|
|
|
|
|
|
|
if (!parsed.success) {
|
|
|
|
|
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
|
|
|
|
|
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return baseApiService.get(
|
|
|
|
|
`/api/v1/threads/${parsed.data.thread_id}/snapshots`,
|
|
|
|
|
listSnapshotsResponse
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete a specific snapshot.
|
|
|
|
|
*/
|
|
|
|
|
deleteSnapshot = async (request: DeleteSnapshotRequest): Promise<void> => {
|
|
|
|
|
const parsed = deleteSnapshotRequest.safeParse(request);
|
|
|
|
|
|
|
|
|
|
if (!parsed.success) {
|
|
|
|
|
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
|
|
|
|
|
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await baseApiService.delete(
|
|
|
|
|
`/api/v1/threads/${parsed.data.thread_id}/snapshots/${parsed.data.snapshot_id}`
|
2026-01-26 16:11:55 +02:00
|
|
|
);
|
|
|
|
|
};
|
2026-02-02 15:43:07 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* List all snapshots for a search space.
|
|
|
|
|
*/
|
|
|
|
|
listSearchSpaceSnapshots = async (
|
|
|
|
|
request: ListSearchSpaceSnapshotsRequest
|
|
|
|
|
): Promise<ListSearchSpaceSnapshotsResponse> => {
|
|
|
|
|
const parsed = listSearchSpaceSnapshotsRequest.safeParse(request);
|
|
|
|
|
|
|
|
|
|
if (!parsed.success) {
|
|
|
|
|
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
|
|
|
|
|
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return baseApiService.get(
|
|
|
|
|
`/api/v1/searchspaces/${parsed.data.search_space_id}/snapshots`,
|
|
|
|
|
listSearchSpaceSnapshotsResponse
|
|
|
|
|
);
|
|
|
|
|
};
|
2026-01-26 16:11:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const chatThreadsApiService = new ChatThreadsApiService();
|