SurfSense/surfsense_web/lib/apis/prompts-api.service.ts
DESKTOP-RTLN3BA\$punk a64c8205fe feat: implement ensure_publication for zero_publication management
- Added the ensure_publication function to create and verify the zero_publication if it is missing, ensuring idempotency during database initialization.
- Integrated ensure_publication into the create_db_and_tables function to prevent zero-cache crash loops on startup.
- Introduced a self-check script to validate the ensure_publication functionality on a create_all-bootstrapped database.
- Updated various components to reflect the transition from search space to workspace, including adjustments in imports and routing paths.
2026-07-05 23:17:13 -07:00

63 lines
1.9 KiB
TypeScript

import {
type PromptCreateRequest,
type PromptUpdateRequest,
promptCreateRequest,
promptDeleteResponse,
promptRead,
promptsListResponse,
promptUpdateRequest,
publicPromptsListResponse,
} from "@/contracts/types/prompts.types";
import { ValidationError } from "@/lib/error";
import { baseApiService } from "./base-api.service";
class PromptsApiService {
list = async (searchSpaceId?: number) => {
const params = new URLSearchParams();
if (searchSpaceId !== undefined) {
params.set("workspace_id", String(searchSpaceId));
}
const queryString = params.toString();
const url = queryString ? `/api/v1/prompts?${queryString}` : "/api/v1/prompts";
return baseApiService.get(url, promptsListResponse);
};
create = async (request: PromptCreateRequest) => {
const parsed = promptCreateRequest.safeParse(request);
if (!parsed.success) {
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
throw new ValidationError(`Invalid request: ${errorMessage}`);
}
return baseApiService.post("/api/v1/prompts", promptRead, {
body: parsed.data,
});
};
update = async (promptId: number, request: PromptUpdateRequest) => {
const parsed = promptUpdateRequest.safeParse(request);
if (!parsed.success) {
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
throw new ValidationError(`Invalid request: ${errorMessage}`);
}
return baseApiService.put(`/api/v1/prompts/${promptId}`, promptRead, {
body: parsed.data,
});
};
delete = async (promptId: number) => {
return baseApiService.delete(`/api/v1/prompts/${promptId}`, promptDeleteResponse);
};
listPublic = async () => {
return baseApiService.get("/api/v1/prompts/public", publicPromptsListResponse);
};
copy = async (promptId: number) => {
return baseApiService.post(`/api/v1/prompts/${promptId}/copy`, promptRead, {});
};
}
export const promptsApiService = new PromptsApiService();