import { apiRequest } from './common.ts' export interface PromptVersion { id: string title: string content: string | null markdownContent: string | null promoted: boolean draft: boolean } export interface Prompt { id: string title: string projectId: string | null workspaceId: string inferencesPercentage: string layoutVersion: string customTags: string[] createdBy: string updatedBy: string deletedBy: string | null createdAt: string updatedAt: string deletedAt: string | null favorited?: boolean promotedVersion?: PromptVersion | null latestVersion?: PromptVersion | null } export interface ListPromptsOptions { projectId?: string workspaceId?: string includePromotedVersion?: boolean /** Return only the caller's personal drafts — the canvases with no project. */ personal?: boolean } /** * List prompts with optional filtering. * * With no filter the response mixes project canvases with the caller's own personal drafts. * `projectId` excludes drafts; `personal` returns nothing but drafts. */ export async function listPrompts(options?: ListPromptsOptions): Promise { if (options?.projectId && options?.personal) throw new Error('projectId and personal are mutually exclusive — personal drafts have no project.') const params = new URLSearchParams() if (options?.projectId) params.set('projectId', options.projectId) if (options?.workspaceId) params.set('workspaceId', options.workspaceId) if (options?.includePromotedVersion) params.set('includePromotedVersion', 'true') if (options?.personal) params.set('personal', 'true') const query = params.toString() return await apiRequest(`/prompt${query ? `?${query}` : ''}`) } /** * Get a single prompt by ID */ export async function getPrompt(promptId: string): Promise { return await apiRequest(`/prompt/${promptId}`) } /** * Get the promoted version of a prompt */ export async function getPromotedVersion(promptId: string): Promise { return await apiRequest(`/prompt/${promptId}/promoted-version`) }