import capabilities from './workflowContextCapabilities.json' with { type: 'json' }; export const WORKFLOW_CONTEXT_CAPABILITIES = capabilities as Readonly< Record >; export interface WorkflowPipelineSuccess { ok: true; index: number; value: T; } export interface WorkflowPipelineFailure { ok: false; index: number; error: { name: string; message: string; code?: string }; } export interface WorkflowPipelineResult { results: (WorkflowPipelineSuccess | WorkflowPipelineFailure)[]; succeeded: number; failed: number; } /** Public V2 contract. Function signatures remain structural so the registry is the key truth. */ export interface WorkflowContext { input: { values: Record; resources: Record }; runtime: Record; model: Record any>; tools: Record any>; exec: Record any>; fs: Record any>; flow: Record any>; check: Record any>; state: Record any>; output: Record any>; } export function assertWorkflowContextShape(value: object): void { const context = value as Record; for (const [group, names] of Object.entries(WORKFLOW_CONTEXT_CAPABILITIES)) { const actual = context[group]; if (!actual || typeof actual !== 'object') { throw new Error(`WorkflowContext 缺少能力组 wf.${group}`); } const keys = Object.keys(actual).sort(); const expected = [...names].sort(); const missing = expected.filter((name) => !keys.includes(name)); const extra = keys.filter((name) => !expected.includes(name)); if (missing.length || extra.length) { throw new Error( `WorkflowContext wf.${group} 与能力注册表不同步` + `${missing.length ? `;缺少 ${missing.join(', ')}` : ''}` + `${extra.length ? `;多出 ${extra.join(', ')}` : ''}`, ); } } }