diff --git a/src/api/client.ts b/src/api/client.ts index cca0af6..e839822 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -18,7 +18,6 @@ import type { LlmConnectionTestResult, RechargeOrder, Message, - MindSpaceAgentJob, MindSpaceQuota, PlazaCategory, PlazaPostBrief, @@ -54,7 +53,6 @@ import { resetUnauthorizedGuard, sanitizeSessionEvent, } from './core'; -import type { MindSpaceListPage } from './mindspace-pages'; export { ApiError, resetUnauthorizedGuard, setUnauthorizedHandler } from './core'; export { buildMindSpaceConversationPackageManifestDownloadUrl, @@ -69,6 +67,14 @@ export { runMindSpaceCleanup, uploadMindSpaceAsset, } from './mindspace-assets'; +export { + cancelMindSpaceAgentJob, + createMindSpaceAgentJob, + getMindSpaceAgentJob, + listMindSpaceAgentJobs, + retryMindSpaceAgentJob, + runMindSpaceAgentJob, +} from './mindspace-agent-jobs'; export { bindMindSpacePageLiveEdit, closeMindSpacePageEditSession, @@ -642,83 +648,6 @@ export async function publishPageToPlaza(input: { return result.data.post; } -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; -} - export async function getAdminDashboardSummary(): Promise { const result = await portalFetch<{ summary: AdminDashboardSummary }>('/admin-api/summary'); return result.summary; diff --git a/src/api/mindspace-agent-jobs.ts b/src/api/mindspace-agent-jobs.ts new file mode 100644 index 0000000..a8955e4 --- /dev/null +++ b/src/api/mindspace-agent-jobs.ts @@ -0,0 +1,80 @@ +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; +}