@ai-sdk/harness-deepagents 1.0.100 → 1.0.101

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @ai-sdk/harness-deepagents
2
2
 
3
+ ## 1.0.101
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [951c54d]
8
+ - @ai-sdk/harness@1.0.101
9
+
3
10
  ## 1.0.100
4
11
 
5
12
  ### Patch Changes
@@ -218,6 +218,7 @@ async function runBridge(options) {
218
218
  }
219
219
  }
220
220
  const pendingToolResults = /* @__PURE__ */ new Map();
221
+ const bufferedToolResults = [];
221
222
  const pendingToolApprovals = /* @__PURE__ */ new Map();
222
223
  const writeBridgeMeta = async (state) => {
223
224
  try {
@@ -397,9 +398,23 @@ async function runBridge(options) {
397
398
  const userMessages = createBridgeUserMessageQueue({ respond: emit });
398
399
  const turn = {
399
400
  emit,
400
- requestToolResult: (toolCallId) => new Promise((resolve) => {
401
- pendingToolResults.set(toolCallId, resolve);
402
- }),
401
+ requestToolResult: (requestInput) => {
402
+ const request = typeof requestInput === "string" ? { toolCallId: requestInput } : requestInput;
403
+ const bufferedIndex = bufferedToolResults.findIndex(
404
+ (buffered) => buffered.toolCallId === request.toolCallId || request.matches?.(buffered.result) === true
405
+ );
406
+ if (bufferedIndex >= 0) {
407
+ return Promise.resolve(
408
+ bufferedToolResults.splice(bufferedIndex, 1)[0].result
409
+ );
410
+ }
411
+ return new Promise((resolve) => {
412
+ pendingToolResults.set(request.toolCallId, {
413
+ resolve,
414
+ matches: request.matches
415
+ });
416
+ });
417
+ },
403
418
  requestToolApproval: (approvalId) => new Promise((resolve) => {
404
419
  pendingToolApprovals.set(approvalId, resolve);
405
420
  }),
@@ -441,10 +456,25 @@ async function runBridge(options) {
441
456
  return;
442
457
  }
443
458
  case "tool-result": {
444
- const resolver = pendingToolResults.get(msg.toolCallId);
445
- if (resolver) {
446
- pendingToolResults.delete(msg.toolCallId);
447
- resolver({ output: msg.output, isError: msg.isError });
459
+ const result = {
460
+ output: msg.output,
461
+ isError: msg.isError,
462
+ toolResult: msg.toolResult
463
+ };
464
+ const exactPending = pendingToolResults.get(msg.toolCallId);
465
+ const matchingPending = exactPending == null ? Array.from(pendingToolResults.entries()).find(
466
+ ([, pending2]) => pending2.matches?.(result) === true
467
+ ) : void 0;
468
+ const pending = exactPending ?? matchingPending?.[1];
469
+ const pendingId = exactPending != null ? msg.toolCallId : matchingPending?.[0];
470
+ if (pending != null && pendingId != null) {
471
+ pendingToolResults.delete(pendingId);
472
+ pending.resolve(result);
473
+ } else {
474
+ bufferedToolResults.push({
475
+ toolCallId: msg.toolCallId,
476
+ result
477
+ });
448
478
  }
449
479
  return;
450
480
  }