import {
approval,
skill,
tool,
createFileRuntimeStore,
createRuntime,
createRuntimeExecutor,
defineRuntimeHandler,
} from '@rpamis/comet/runtime';
const workflow = {
id: 'report',
version: '1',
entry: 'draft',
steps: {
draft: skill({ ref: 'draft' }),
approve: approval({ proposalFrom: 'draft' }),
publish: tool({ ref: 'publish' }),
},
transitions: [
{ from: 'draft', to: 'approve' },
{ from: 'approve', to: 'publish', on: 'approved' },
],
};
const host = createRuntimeExecutor({
id: 'host',
handlers: {
draft: defineRuntimeHandler({
type: 'invoke_skill',
parseInput: ({ input }) => {
if (typeof input !== 'string') throw new Error('Expected a topic');
return input;
},
execute: (topic) => ({ status: 'succeeded', output: `Report about ${topic}` }),
}),
publish: defineRuntimeHandler({
type: 'call_tool',
parseInput: ({ outputs }) => {
if (typeof outputs.draft !== 'string') throw new Error('Expected a report');
return outputs.draft;
},
execute: (report) => {
console.log(report);
return { status: 'succeeded', output: { published: true } };
},
}),
},
});
const runtime = createRuntime({
store: createFileRuntimeStore({ rootDir: './report-state' }),
workflows: [workflow],
executors: [host],
});
await runtime.start({
runId: 'report-1',
workflow: { id: 'report', version: '1' },
input: 'SDK integration',
});
const progress = await runtime.runUntilBlocked({ runId: 'report-1', executorId: 'host' });
console.log(progress.reason);
console.log(progress.run.waits.filter((wait) => wait.status === 'pending'));