import type { MindSpaceAgentJob } from '../types'; import { apiFetch } from './core'; import type { MindSpaceListPage } from './mindspace-pages'; export async function createMindSpaceAgentJob(input: { jobType: string; instruction: string; allowedAssetIds: string[]; outputType?: 'page_draft' | 'html_page' | 'markdown'; outputCategoryId?: string; idempotencyKey?: string; locale?: string; timezone?: string; capabilities?: { network?: boolean; shell?: boolean; createPage?: boolean; }; }): Promise { const result = await apiFetch<{ data: MindSpaceAgentJob }>('/mindspace/v1/agent/jobs', { method: 'POST', body: JSON.stringify({ job_type: input.jobType, instruction: input.instruction, allowed_asset_ids: input.allowedAssetIds, output_type: input.outputType ?? 'page_draft', output_category_id: input.outputCategoryId, idempotency_key: input.idempotencyKey, locale: input.locale, timezone: input.timezone, capabilities: input.capabilities, }), }); return result.data; } export async function getMindSpaceAgentJob(jobId: string): Promise { const result = await apiFetch<{ data: MindSpaceAgentJob }>( `/mindspace/v1/agent/jobs/${encodeURIComponent(jobId)}`, ); return result.data; } export async function listMindSpaceAgentJobs(options?: { limit?: number; offset?: number; }): Promise<{ items: MindSpaceAgentJob[]; page: MindSpaceListPage }> { const limit = options?.limit ?? 10; const offset = options?.offset ?? 0; const result = await apiFetch<{ data: MindSpaceAgentJob[]; page?: MindSpaceListPage }>( `/mindspace/v1/agent/jobs?limit=${encodeURIComponent(String(limit))}&offset=${encodeURIComponent(String(offset))}`, ); return { items: result.data, page: result.page ?? {} }; } export async function runMindSpaceAgentJob( jobId: string, ): Promise<{ started: boolean; jobId: string }> { const result = await apiFetch<{ data: { started: boolean; jobId: string } }>( `/mindspace/v1/agent/jobs/${encodeURIComponent(jobId)}/run`, { method: 'POST', body: JSON.stringify({}) }, ); return result.data; } export async function cancelMindSpaceAgentJob(jobId: string): Promise { const result = await apiFetch<{ data: MindSpaceAgentJob }>( `/mindspace/v1/agent/jobs/${encodeURIComponent(jobId)}/cancel`, { method: 'POST', body: JSON.stringify({}) }, ); return result.data; } export async function retryMindSpaceAgentJob(jobId: string): Promise { const result = await apiFetch<{ data: MindSpaceAgentJob }>( `/mindspace/v1/agent/jobs/${encodeURIComponent(jobId)}/retry`, { method: 'POST', body: JSON.stringify({}) }, ); return result.data; }