@theoremjs/web 0.3.4-next.721.g7ff150a → 0.3.4-next.725.ge231cdc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/client/chat.js +28 -1
  2. package/package.json +2 -2
package/client/chat.js CHANGED
@@ -608,9 +608,36 @@ class Chat {
608
608
  },
609
609
  }), { turn: true, message: { restore: () => this.#restore(composerFieldsFromDraft(draft)) } });
610
610
  }
611
+ /** The gate on the reply still running that no answer is on its way to. */
612
+ #drawnGate() {
613
+ const { streamBlocks, answering } = this.#state;
614
+ for (const block of streamBlocks) {
615
+ if (block.kind !== 'tool' || block.tool.state?.phase !== 'gate')
616
+ continue;
617
+ const { callId, operationId } = block.tool;
618
+ if (operationId && callId !== answering?.callId)
619
+ return { callId, operationId };
620
+ }
621
+ return undefined;
622
+ }
611
623
  async #answerGate(resolution) {
612
- // why: Set once the run starts (not while another runs), and cleared once it has ended.
624
+ // why: Set once this answer shows on its gate (not while another's does), and cleared once it has ended.
613
625
  let started = false;
626
+ // why: A gate draws while its reply streams, but what waits is only settled when that run ends.
627
+ const running = this.#state.phase === 'gated' ? null : this.#run;
628
+ if (running) {
629
+ const gate = this.#drawnGate();
630
+ if (!gate || resolution.action === 'page')
631
+ return;
632
+ started = true;
633
+ this.#set({ answering: { ...gate, action: resolution.action } });
634
+ await running;
635
+ // invariant: An answer goes only to the gate it was given on.
636
+ if (this.#state.session.gatedTool?.operationId !== gate.operationId) {
637
+ this.#set({ answering: null });
638
+ return;
639
+ }
640
+ }
614
641
  try {
615
642
  await this.#runTurn(({ iface, view, transport, scope }) => {
616
643
  started = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theoremjs/web",
3
- "version": "0.3.4-next.721.g7ff150a",
3
+ "version": "0.3.4-next.725.ge231cdc",
4
4
  "description": "Theorem on the web platform, with no UI framework: Web-standard server handlers that serve a profile, and the browser client that talks to them.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -25,6 +25,6 @@
25
25
  },
26
26
  "peerDependencies": {
27
27
  "zod": "^4.6.5",
28
- "@theoremjs/agents": "^0.3.4-next.721.g7ff150a"
28
+ "@theoremjs/agents": "^0.3.4-next.725.ge231cdc"
29
29
  }
30
30
  }