78d1c88ca1
CI/CD Pipeline / Validate Code Quality And Tests (push) Successful in 1m44s
CI/CD Pipeline / Unit Tests (push) Successful in 1m44s
CI/CD Pipeline / Frontend Lint (push) Successful in 2m28s
CI/CD Pipeline / Build Production API Image (push) Has been skipped
CI/CD Pipeline / Build Production Worker Image (push) Has been skipped
CI/CD Pipeline / Build Production Web Image (push) Has been skipped
CI/CD Pipeline / Deploy Production (push) Has been skipped
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Integration Tests (push) Successful in 1m8s
CI/CD Pipeline / Build Staging API Image (push) Has been cancelled
CI/CD Pipeline / Build Staging Worker Image (push) Has been cancelled
CI/CD Pipeline / Build Staging Web Image (push) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (push) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (push) Has been cancelled
130 lines
3.4 KiB
TypeScript
130 lines
3.4 KiB
TypeScript
/**
|
||
* 任务相关 API
|
||
* 对接后端任务中心 API:
|
||
* - POST /api/v1/generation/tasks — 创建生成任务
|
||
* - GET /api/v1/tasks — 用户级任务列表(支持分页/筛选)
|
||
* - GET /api/v1/tasks/{task_id} — 任务详情(含 error_info)
|
||
* - POST /api/v1/tasks/{task_id}/retry — 重试失败任务
|
||
*/
|
||
import apiClient from "./client";
|
||
|
||
/* ──────────── 类型定义 ──────────── */
|
||
|
||
/** 任务状态 */
|
||
export type TaskStatus =
|
||
"pending" | "waiting" | "running" | "completed" | "failed" | "cancelled";
|
||
|
||
/** 任务类型 */
|
||
export type TaskType = "ingest" | "generation" | string;
|
||
|
||
/** 错误详情 */
|
||
export interface TaskErrorInfo {
|
||
error_type: string;
|
||
error_message: string;
|
||
failed_step: string;
|
||
stack_trace?: string;
|
||
}
|
||
|
||
/** 任务条目(对应用户级 UserTaskResponse) */
|
||
export interface TaskItem {
|
||
id: string;
|
||
task_type: TaskType;
|
||
project_id: string;
|
||
template_id?: string;
|
||
status: TaskStatus;
|
||
progress: number;
|
||
current_step: string;
|
||
error_message: string;
|
||
user_message: string;
|
||
retryable: boolean;
|
||
source_id: string;
|
||
/** 错误详情(失败任务) */
|
||
error_info?: TaskErrorInfo;
|
||
/** 耗时(秒) */
|
||
duration_seconds?: number;
|
||
created_at?: string | null;
|
||
updated_at?: string | null;
|
||
}
|
||
|
||
/** 任务列表查询参数 */
|
||
export interface TaskListParams {
|
||
page?: number;
|
||
page_size?: number;
|
||
status?: TaskStatus | "all";
|
||
task_type?: TaskType | "all";
|
||
}
|
||
|
||
/** 任务列表分页响应 */
|
||
export interface TaskListResponse {
|
||
items: TaskItem[];
|
||
total: number;
|
||
page: number;
|
||
page_size: number;
|
||
}
|
||
|
||
/** 创建生成任务请求参数 */
|
||
export interface CreateGenerationTaskRequest {
|
||
template_id: string;
|
||
asset_ids: string[];
|
||
title_ids: string[];
|
||
voice_ids: string[];
|
||
}
|
||
|
||
/** 创建生成任务响应(对齐后端 GenerationTaskResponse) */
|
||
export interface CreateGenerationTaskResponse {
|
||
id: string;
|
||
project_id: string;
|
||
asset_library_id: string;
|
||
strategy_id: string;
|
||
voice_library_id: string;
|
||
template_id: string;
|
||
asset_ids: string[];
|
||
title_ids: string[];
|
||
voice_ids: string[];
|
||
status: string;
|
||
progress: number;
|
||
result_count: number;
|
||
error_message: string;
|
||
}
|
||
|
||
/* ──────────── API 函数 ──────────── */
|
||
|
||
/** 创建生成任务(一键生成) */
|
||
export const createGenerationTask = async (
|
||
params: CreateGenerationTaskRequest,
|
||
): Promise<CreateGenerationTaskResponse> => {
|
||
const { data } = await apiClient.post<CreateGenerationTaskResponse>(
|
||
"/generation/tasks",
|
||
params,
|
||
);
|
||
return data;
|
||
};
|
||
|
||
/** 获取任务列表(支持分页和筛选) */
|
||
export const getTasks = async (
|
||
params?: TaskListParams,
|
||
): Promise<TaskListResponse> => {
|
||
const { data } = await apiClient.get<TaskListResponse>("/tasks", {
|
||
params,
|
||
});
|
||
return data;
|
||
};
|
||
|
||
/** 获取当前用户的所有任务(兼容旧接口,跨 project) */
|
||
export const getUserTasks = async (): Promise<TaskItem[]> => {
|
||
const { data } = await apiClient.get("/tasks");
|
||
return data.items || data || [];
|
||
};
|
||
|
||
/** 获取单个任务详情(含 error_info) */
|
||
export const getTask = async (taskId: string): Promise<TaskItem> => {
|
||
const { data } = await apiClient.get(`/tasks/${taskId}`);
|
||
return data;
|
||
};
|
||
|
||
/** 重试失败的任务 */
|
||
export const retryTask = async (taskId: string): Promise<TaskItem> => {
|
||
const { data } = await apiClient.post(`/tasks/${taskId}/retry`);
|
||
return data;
|
||
};
|