Files
short-drama-agent-front/src/features/projects/api.ts
T

46 lines
2.3 KiB
TypeScript

import { request, optionalResource } from '../../lib/http'
import type { Checkpoint } from '../workflows/types'
import type { WorkflowExecutionStart } from '../workflows/execution.types'
import type {
CreateProjectInput,
DramaState,
Project,
ProjectDetail,
ProjectStageReadiness,
ProjectDurationBudgetSummary,
UpdateProjectInput
} from './types'
/** 项目与 Create Drama API;路径严格对应后端 dev。 */
export const projectsApi = {
list: (signal?: AbortSignal) => request<Project[]>('/projects', { signal }),
detail: (id: string, signal?: AbortSignal) =>
request<ProjectDetail>(`/projects/${encodeURIComponent(id)}`, { signal }),
durationBudget: (id: string, signal?: AbortSignal) =>
request<ProjectDurationBudgetSummary>(`/projects/${encodeURIComponent(id)}/duration-budget`, { signal }),
stageReadiness: (id: string, signal?: AbortSignal) =>
request<ProjectStageReadiness>(`/projects/${encodeURIComponent(id)}/stage-readiness`, { signal }),
create: (input: CreateProjectInput) =>
request<{ projectId: string; status: string; executionId: string }>('/projects', {
method: 'POST',
body: input
}),
update: (id: string, input: UpdateProjectInput) =>
request<Project>(`/projects/${encodeURIComponent(id)}`, { method: 'PUT', body: input }),
deleteReadiness: (id: string, signal?: AbortSignal) =>
request<{
projectId: string
canDelete: boolean
totalActiveTasks: number
activeTasks: Record<string, number>
}>(`/projects/${encodeURIComponent(id)}/delete-readiness`, { signal }),
delete: (id: string) =>
request<{ id: string; deleted: boolean }>(`/projects/${encodeURIComponent(id)}`, { method: 'DELETE' }),
state: (id: string, signal?: AbortSignal) =>
optionalResource(request<DramaState>(`/projects/${encodeURIComponent(id)}/state`, { signal })),
checkpoints: (id: string, signal?: AbortSignal) =>
request<Checkpoint[]>(`/projects/${encodeURIComponent(id)}/checkpoints`, { signal }),
resume: (id: string, action: 'resume-generation' | 'resume-rewrite') =>
request<WorkflowExecutionStart>(`/projects/${encodeURIComponent(id)}/${action}`, { method: 'POST' })
}