feat(workflow): 补齐项目版本运行与工作台链路

This commit is contained in:
2026-06-01 04:18:01 +08:00
parent 5e0212d2a0
commit 8596f5074b
37 changed files with 1300 additions and 6 deletions

View File

@@ -0,0 +1,44 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import {
getWorkflowDefinition,
getWorkflowWorkspace,
listWorkflowDefinitions,
saveWorkflowDefinition,
} from '../workflow';
import { get, post } from '../request';
vi.mock('../request', () => ({
get: vi.fn(),
post: vi.fn(),
}));
describe('workflow api', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('maps workflow endpoints correctly', () => {
listWorkflowDefinitions();
getWorkflowDefinition('1001');
saveWorkflowDefinition({
projectId: '2001',
workflowCode: 'WF_RAG_SUPPORT',
workflowName: '知识问答流程',
status: 'DRAFT',
});
getWorkflowWorkspace('2001', '1001');
expect(get).toHaveBeenCalledWith('/workflows/definitions');
expect(get).toHaveBeenCalledWith('/workflows/definition/detail', { params: { id: '1001' } });
expect(post).toHaveBeenCalledWith('/workflows/definition/save', {
projectId: '2001',
workflowCode: 'WF_RAG_SUPPORT',
workflowName: '知识问答流程',
status: 'DRAFT',
});
expect(get).toHaveBeenCalledWith('/workflow-workspace/detail', {
params: { projectId: '2001', workflowId: '1001' },
});
});
});

View File

@@ -0,0 +1,87 @@
import { get, post } from './request';
export interface ProjectRecord {
id?: string;
projectCode: string;
projectName: string;
environment?: string;
publishStatus?: string;
currentVersion?: string;
remark?: string;
}
export interface WorkflowDefinitionRecord {
id?: string;
projectId: string;
workflowCode: string;
workflowName: string;
description?: string;
boundAgentId?: string;
status?: string;
remark?: string;
}
export interface WorkflowVersionRecord {
id?: string;
workflowId: string;
versionNo: number;
snapshotName: string;
graphJson: string;
publishStatus?: string;
publishedTime?: string;
remark?: string;
}
export interface WorkflowRunRecord {
id?: string;
workflowId: string;
workflowVersionId: string;
agentId?: string;
requestId: string;
runSource?: string;
status?: string;
inputJson?: string;
outputJson?: string;
durationMs?: number;
estimatedCost?: number;
remark?: string;
}
export interface WorkflowWorkspace {
projectId: string;
projectCode: string;
projectName: string;
environment?: string;
publishStatus?: string;
workflowId?: string;
workflowCode?: string;
workflowName?: string;
workflowStatus?: string;
currentPublishedVersionNo?: number;
latestRequestId?: string;
latestDurationMs?: number;
workflows: WorkflowDefinitionRecord[];
versions: WorkflowVersionRecord[];
recentRuns: WorkflowRunRecord[];
}
export function listWorkflowDefinitions() {
return get<WorkflowDefinitionRecord[]>('/workflows/definitions');
}
export function getWorkflowDefinition(id: string) {
return get<WorkflowDefinitionRecord>('/workflows/definition/detail', { params: { id } });
}
export function saveWorkflowDefinition(data: WorkflowDefinitionRecord) {
return post<boolean, WorkflowDefinitionRecord>('/workflows/definition/save', data);
}
export function getWorkflowWorkspace(projectId: string, workflowId?: string) {
return get<WorkflowWorkspace>('/workflow-workspace/detail', {
params: {
projectId,
workflowId,
},
});
}