import {
skill,
tool,
createRuntime,
createMemoryRuntimeStore,
createRuntimeExecutor,
defineRuntimeHandler,
} from '@rpamis/comet/runtime';
const workflow = {
id: 'parallel-report',
version: '1',
entry: ['draft', 'sources'],
steps: {
draft: skill({ ref: 'draft' }),
sources: tool({ ref: 'sources' }),
compose: tool({ ref: 'compose', join: ['draft', 'sources'] }),
},
transitions: [
{ from: 'draft', to: 'compose' },
{ from: 'sources', to: 'compose' },
],
};
const host = createRuntimeExecutor({
id: 'host',
handlers: {
draft: defineRuntimeHandler({
type: 'invoke_skill',
parseInput: ({ input }) => input,
execute: () => ({ status: 'succeeded', output: '本周交付了 SDK 使用指南。' }),
}),
sources: defineRuntimeHandler({
type: 'call_tool',
parseInput: ({ input }) => input,
execute: () => ({ status: 'succeeded', output: ['文档验收记录'] }),
}),
compose: defineRuntimeHandler({
type: 'call_tool',
parseInput: ({ outputs }) => outputs,
execute: ({ draft, sources }) => ({
status: 'succeeded',
output: { draft, sources },
}),
}),
},
});
const runtime = createRuntime({
store: createMemoryRuntimeStore(),
workflows: [workflow],
executors: [host],
});
await runtime.start({
runId: 'parallel-1',
workflow: { id: workflow.id, version: workflow.version },
input: {},
});
const progress = await runtime.runUntilBlocked({ runId: 'parallel-1', executorId: 'host' });
console.log(progress.reason);
console.log(progress.run.outputs.compose.value);