Admin console can list workflow definitions, validate/publish draft versions, and view bootstrap template assets from the server API. Co-authored-by: Cursor <cursoragent@cursor.com>
83 lines
2.3 KiB
TypeScript
83 lines
2.3 KiB
TypeScript
import { authClient } from './auth';
|
|
|
|
export interface WorkflowDefinitionSummary {
|
|
id: number;
|
|
key: string;
|
|
name: string;
|
|
description: string;
|
|
status: string;
|
|
latest_published_version: number;
|
|
product_domain?: string;
|
|
}
|
|
|
|
export interface WorkflowVersionSummary {
|
|
id: number;
|
|
workflow_id: number;
|
|
version: number;
|
|
status: string;
|
|
definition_hash: string;
|
|
}
|
|
|
|
export interface ValidationIssue {
|
|
code: string;
|
|
message: string;
|
|
field?: string;
|
|
}
|
|
|
|
async function adminFetch(path: string, init?: RequestInit): Promise<Response> {
|
|
const token = authClient.getSessionToken();
|
|
return fetch(path, {
|
|
...init,
|
|
headers: {
|
|
...(init?.headers ?? {}),
|
|
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function listAdminWorkflows(): Promise<WorkflowDefinitionSummary[]> {
|
|
const resp = await adminFetch('/api/v1/admin/workflows');
|
|
if (!resp.ok) throw new Error('获取工作流列表失败');
|
|
const data = await resp.json();
|
|
return data.workflows ?? [];
|
|
}
|
|
|
|
export async function getAdminWorkflow(id: number): Promise<{
|
|
definition: WorkflowDefinitionSummary;
|
|
versions: WorkflowVersionSummary[];
|
|
}> {
|
|
const resp = await adminFetch(`/api/v1/admin/workflows/${id}`);
|
|
if (!resp.ok) throw new Error('获取工作流详情失败');
|
|
return resp.json();
|
|
}
|
|
|
|
export async function validateWorkflowVersion(workflowId: number, version: number): Promise<{
|
|
valid: boolean;
|
|
issues: ValidationIssue[];
|
|
}> {
|
|
const resp = await adminFetch(`/api/v1/admin/workflows/${workflowId}/versions/${version}/validate`, {
|
|
method: 'POST',
|
|
});
|
|
if (!resp.ok) throw new Error('校验失败');
|
|
return resp.json();
|
|
}
|
|
|
|
export async function publishWorkflowVersion(workflowId: number, version: number): Promise<void> {
|
|
const resp = await adminFetch(`/api/v1/admin/workflows/${workflowId}/versions/${version}/publish`, {
|
|
method: 'POST',
|
|
});
|
|
if (!resp.ok) {
|
|
const txt = await resp.text();
|
|
throw new Error(txt || '发布失败');
|
|
}
|
|
}
|
|
|
|
export async function listAdminTemplates(): Promise<
|
|
Array<{ id: number; asset_key: string; name: string; status: string }>
|
|
> {
|
|
const resp = await adminFetch('/api/v1/admin/templates');
|
|
if (!resp.ok) throw new Error('获取模板列表失败');
|
|
const data = await resp.json();
|
|
return data.templates ?? [];
|
|
}
|