import path from 'node:path';
import { loadWorkflowApplication } from '@rpamis/comet/applications';
import { createRuntime } from '@rpamis/comet/runtime';
const application = await loadWorkflowApplication({
file: path.resolve('local-report/application.json'),
projectRoot: process.cwd(),
runId: 'report-1',
});
const runtime = createRuntime({ ...application.implementation, store: application.store });
await runtime.start({
runId: 'report-1',
workflow: { id: 'report-publishing', version: '1' },
input: { title: '项目周报', body: '本周完成了三个已验收任务。', sources: ['本地任务记录'] },
});
let progress = await runtime.runUntilBlocked({ runId: 'report-1', executorId: 'report-local' });
for (const child of progress.run.children) {
await runtime.runUntilBlocked({ runId: child.runId, executorId: 'report-local' });
}
progress = await runtime.runUntilBlocked({ runId: 'report-1', executorId: 'report-local' });
const wait = progress.run.waits.find((item) => item.status === 'pending');
console.log(progress.reason);
if (wait) console.log(wait.proposal);
if (process.argv.includes('--approve')) {
if (!wait) throw new Error('No pending approval');
await runtime.resolveWait({
runId: progress.run.runId,
waitId: wait.id,
proposalHash: wait.proposalHash,
decisionId: 'report-publication-1',
choice: 'approved',
});
progress = await runtime.runUntilBlocked({ runId: 'report-1', executorId: 'report-local' });
console.log(progress.reason);
}
console.log(progress.run.outputs.publish?.value);