Skip to content

Commit 700e46c

Browse files
authored
Revert to promise-based waiting for pattern tool results (#1887)
* Revert to promise-based waiting for pattern tool results Fixes `searchWeb` * Format pass
1 parent ac44631 commit 700e46c

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

packages/runner/src/builtins/llm-dialog.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@ async function invokeToolCall(
358358
await ensureSourceCharmRunning(runtime, charmMeta);
359359
}
360360

361+
const { resolve, promise } = Promise.withResolvers<any>();
362+
361363
// runSynced charm
362364
runtime.editWithRetry((tx) => {
363365
if (pattern) {
@@ -372,12 +374,22 @@ async function invokeToolCall(
372374
}
373375
});
374376

375-
await runtime.idle();
376-
377-
// If this was a pattern, stop it now that we have the result
378-
if (pattern) runtime.runner.stop(result);
377+
if (pattern) {
378+
// wait until we know we have the result of the tool call
379+
// not just that the transaction has been comitted
380+
const cancel = result.sink((r) => {
381+
r !== undefined && resolve(r);
382+
});
383+
const resultValue = await promise;
384+
cancel();
379385

380-
return { type: "json", value: result.get() };
386+
// stop it now that we have the result
387+
runtime.runner.stop(result);
388+
return { type: "json", value: resultValue };
389+
} else {
390+
await runtime.idle();
391+
return { type: "json", value: result.get() };
392+
}
381393
}
382394

383395
/**

0 commit comments

Comments
 (0)