import {
childWorkflow,
tool,
createRuntime,
createMemoryRuntimeStore,
createRuntimeExecutor,
defineRuntimeHandler,
} from '@rpamis/comet/runtime';
const child = {
id: 'source-check',
version: '1',
entry: 'check',
steps: { check: tool({ ref: 'check' }) },
};
const parent = {
id: 'report-with-check',
version: '1',
entry: 'facts',
steps: {
facts: childWorkflow({ workflow: { id: child.id, version: child.version } }),
summarize: tool({ ref: 'summarize' }),
},
transitions: [{ from: 'facts', to: 'summarize' }],
};
const host = createRuntimeExecutor({
id: 'host',
handlers: {
check: defineRuntimeHandler({
type: 'call_tool',
parseInput: ({ input }) => input,
execute: () => ({ status: 'succeeded', output: { checked: true } }),
}),
summarize: defineRuntimeHandler({
type: 'call_tool',
parseInput: ({ outputs }) => outputs.facts,
execute: (facts) => ({ status: 'succeeded', output: facts }),
}),
},
});
const runtime = createRuntime({
store: createMemoryRuntimeStore(),
workflows: [parent, child],
executors: [host],
});
await runtime.start({
runId: 'parent-1',
workflow: { id: parent.id, version: parent.version },
input: {},
});
let progress = await runtime.runUntilBlocked({ runId: 'parent-1', executorId: 'host' });
for (const childRun of progress.run.children) {
await runtime.runUntilBlocked({ runId: childRun.runId, executorId: 'host' });
}
progress = await runtime.runUntilBlocked({ runId: 'parent-1', executorId: 'host' });
console.log(progress.reason);
console.log(progress.run.children);
console.log(progress.run.outputs.summarize.value);