21 lines
879 B
TypeScript
21 lines
879 B
TypeScript
// Channel submissions target any conversation. EOF and Stop close the harness cleanly.
|
|
export async function serve(harness: any, context: any, afterSubmit?: () => Promise<void>) {
|
|
while (true) {
|
|
const input = await Deno.core.ops.op_input();
|
|
if (input === null || input.type === 'stop') {
|
|
await harness.waitForIdle(context);
|
|
return;
|
|
}
|
|
const conversation = await harness.conversation(input.conversation, context);
|
|
if (!conversation) throw new Error(`Unknown conversation: ${input.conversation}`);
|
|
const submission = await conversation.submit({
|
|
type: 'input', content: input.content, requestId: input.requestId,
|
|
}, context);
|
|
if (afterSubmit) {
|
|
const result = await submission.wait(context);
|
|
await afterSubmit();
|
|
if (result.status !== 'done') throw new Error(`Run ended: ${JSON.stringify(result)}`);
|
|
}
|
|
}
|
|
}
|