host: expose harness state and actions over the world API
This commit is contained in:
@@ -20477,13 +20477,24 @@ async function openStorage(path) {
|
||||
}
|
||||
|
||||
// input.ts
|
||||
async function serve(harness2, context, afterSubmit) {
|
||||
async function serve(harness2, context, afterSubmit, api) {
|
||||
const pending = /* @__PURE__ */ new Set();
|
||||
const track2 = (work) => {
|
||||
const task = work.catch((error) => Deno.core.ops.op_output(`${String(error)}
|
||||
`)).finally(() => pending.delete(task));
|
||||
pending.add(task);
|
||||
};
|
||||
while (true) {
|
||||
const input = await Deno.core.ops.op_input();
|
||||
if (input === null || input.type === "stop") {
|
||||
await harness2.waitForIdle(context);
|
||||
await Promise.all(pending);
|
||||
return;
|
||||
}
|
||||
if (input.type === "api") {
|
||||
track2(api.handle(input));
|
||||
continue;
|
||||
}
|
||||
const conversation = await harness2.conversation(input.conversation, context);
|
||||
if (!conversation) throw new Error(`Unknown conversation: ${input.conversation}`);
|
||||
const submission2 = await conversation.submit({
|
||||
@@ -20492,9 +20503,10 @@ async function serve(harness2, context, afterSubmit) {
|
||||
requestId: input.requestId
|
||||
}, context);
|
||||
if (afterSubmit) {
|
||||
const result = await submission2.wait(context);
|
||||
await afterSubmit();
|
||||
if (result.status !== "done") throw new Error(`Run ended: ${JSON.stringify(result)}`);
|
||||
track2(submission2.wait(context).then(async (result) => {
|
||||
await afterSubmit();
|
||||
if (result.status !== "done") throw new Error(`Run ended: ${JSON.stringify(result)}`);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user