@standardagents/builder 0.40.3 → 0.40.5-next.3b25e2a

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.
package/dist/runtime.d.ts CHANGED
@@ -1230,6 +1230,7 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
1230
1230
  */
1231
1231
  deliverClientToolResult(toolCallId: string, ok: boolean, result?: string, error?: string, deliveredByClientId?: string, deliveredGeneration?: number, deliveryToken?: string, internalAuthorization?: typeof INTERNAL_TOOL_DELIVERY): Promise<{
1232
1232
  side: "a" | "b";
1233
+ resume: boolean;
1233
1234
  } | null>;
1234
1235
  /** Default time to wait for the client to accept a stream open. */
1235
1236
  private static readonly CLIENT_STREAM_OPEN_TIMEOUT_MS;
package/dist/runtime.js CHANGED
@@ -26077,7 +26077,7 @@ ${resultContent}${attachmentSummary}`;
26077
26077
  void 0,
26078
26078
  INTERNAL_TOOL_DELIVERY
26079
26079
  );
26080
- if (delivered) sides.add(delivered.side);
26080
+ if (delivered?.resume) sides.add(delivered.side);
26081
26081
  }
26082
26082
  if (threadId) {
26083
26083
  for (const side of sides) {
@@ -26379,14 +26379,17 @@ ${resultContent}${attachmentSummary}`;
26379
26379
  deliveredResultWaiters = /* @__PURE__ */ new Map();
26380
26380
  notifyDeliveredResultWaiters(toolCallId) {
26381
26381
  const waiters = this.deliveredResultWaiters?.get(toolCallId);
26382
- if (!waiters) return;
26382
+ if (!waiters || waiters.size === 0) return false;
26383
26383
  this.deliveredResultWaiters.delete(toolCallId);
26384
+ let notified = false;
26384
26385
  for (const wake of waiters) {
26385
26386
  try {
26386
26387
  wake();
26388
+ notified = true;
26387
26389
  } catch {
26388
26390
  }
26389
26391
  }
26392
+ return notified;
26390
26393
  }
26391
26394
  /**
26392
26395
  * Await a parked forwarded call's delivered result: one immediate read,
@@ -26531,37 +26534,46 @@ ${resultContent}${attachmentSummary}`;
26531
26534
  const side = pending.side === "b" ? "b" : "a";
26532
26535
  const content = ok ? result ?? "" : `Error: ${error ?? "tool failed"}`;
26533
26536
  const toolStatus = ok ? "success" : "error";
26534
- await this.ctx.storage.sql.exec(
26535
- `UPDATE messages SET content = ?, tool_status = ? WHERE tool_call_id = ? AND role = 'tool'`,
26536
- content,
26537
- toolStatus,
26538
- toolCallId
26539
- );
26540
- const updated = await this.ctx.storage.sql.exec(
26541
- `SELECT COUNT(*) AS total FROM messages WHERE tool_call_id = ? AND role = 'tool'`,
26542
- toolCallId
26543
- );
26544
- if (Number(updated.toArray()[0]?.total ?? 0) === 0) {
26545
- const toolRow = await this.ctx.storage.sql.exec(
26546
- `SELECT tool FROM pending_client_calls WHERE tool_call_id = ? LIMIT 1`,
26537
+ const resultMessageId = crypto.randomUUID();
26538
+ const resultCreatedAt = Date.now() * TIMESTAMP_MULTIPLIER;
26539
+ const accepted = this.ctx.storage.transactionSync(() => {
26540
+ const claimed = this.ctx.storage.sql.exec(
26541
+ `UPDATE pending_client_calls
26542
+ SET status = 'resolved'
26543
+ WHERE tool_call_id = ? AND status = 'pending'`,
26547
26544
  toolCallId
26548
26545
  );
26549
- await this.ctx.storage.sql.exec(
26550
- `INSERT INTO messages (id, role, content, name, tool_call_id, tool_status, created_at, status, prompt)
26551
- VALUES (?, 'tool', ?, ?, ?, ?, ?, 'completed', NULL)`,
26552
- crypto.randomUUID(),
26546
+ if (claimed.rowsWritten !== 1) return false;
26547
+ this.ctx.storage.sql.exec(
26548
+ `UPDATE messages SET content = ?, tool_status = ? WHERE tool_call_id = ? AND role = 'tool'`,
26553
26549
  content,
26554
- toolRow.toArray()[0]?.tool ?? null,
26555
- toolCallId,
26556
26550
  toolStatus,
26557
- Date.now() * TIMESTAMP_MULTIPLIER
26551
+ toolCallId
26558
26552
  );
26559
- }
26560
- await this.ctx.storage.sql.exec(
26561
- `UPDATE pending_client_calls SET status = 'resolved' WHERE tool_call_id = ?`,
26562
- toolCallId
26563
- );
26564
- this.notifyDeliveredResultWaiters(toolCallId);
26553
+ const updated = this.ctx.storage.sql.exec(
26554
+ `SELECT COUNT(*) AS total FROM messages WHERE tool_call_id = ? AND role = 'tool'`,
26555
+ toolCallId
26556
+ );
26557
+ if (Number(updated.toArray()[0]?.total ?? 0) === 0) {
26558
+ const toolRow = this.ctx.storage.sql.exec(
26559
+ `SELECT tool FROM pending_client_calls WHERE tool_call_id = ? LIMIT 1`,
26560
+ toolCallId
26561
+ );
26562
+ this.ctx.storage.sql.exec(
26563
+ `INSERT INTO messages (id, role, content, name, tool_call_id, tool_status, created_at, status, prompt)
26564
+ VALUES (?, 'tool', ?, ?, ?, ?, ?, 'completed', NULL)`,
26565
+ resultMessageId,
26566
+ content,
26567
+ toolRow.toArray()[0]?.tool ?? null,
26568
+ toolCallId,
26569
+ toolStatus,
26570
+ resultCreatedAt
26571
+ );
26572
+ }
26573
+ return true;
26574
+ });
26575
+ if (!accepted) return null;
26576
+ const resumedInline = this.notifyDeliveredResultWaiters(toolCallId);
26565
26577
  try {
26566
26578
  const msgCursor = await this.ctx.storage.sql.exec(
26567
26579
  `SELECT id, role, content, name, tool_call_id, tool_status, created_at, depth
@@ -26572,7 +26584,7 @@ ${resultContent}${attachmentSummary}`;
26572
26584
  if (msg) this.broadcastMessage(msg);
26573
26585
  } catch {
26574
26586
  }
26575
- return { side };
26587
+ return { side, resume: !resumedInline };
26576
26588
  }
26577
26589
  // ─── Runtime byte streams ──────────────────────────────────────────────────
26578
26590
  // The existing bridge frames carry opaque capability metadata and bytes