@ai-sdk/harness-opencode 1.0.170 → 1.0.173

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,28 @@
1
1
  # @ai-sdk/harness-opencode
2
2
 
3
+ ## 1.0.173
4
+
5
+ ### Patch Changes
6
+
7
+ - 504536a: Send a tool call to the host before its approval request. OpenCode asks for permission while the call is still pending and reports it as running only afterwards, so with `allow-reads` or `allow-edits` the approval request reached `HarnessAgent` first and the turn failed with "emitted approval request ... for unknown tool call".
8
+
9
+ ## 1.0.172
10
+
11
+ ### Patch Changes
12
+
13
+ - @ai-sdk/harness@1.0.170
14
+
15
+ ## 1.0.171
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [7716e18]
20
+ - Updated dependencies [5c247e9]
21
+ - Updated dependencies [dcd2f8d]
22
+ - @ai-sdk/provider-utils@5.0.72
23
+ - @ai-sdk/provider@4.0.35
24
+ - @ai-sdk/harness@1.0.169
25
+
3
26
  ## 1.0.170
4
27
 
5
28
  ### Patch Changes
@@ -1846,6 +1846,7 @@ const TOOL_KIND = {
1846
1846
  skill: "edit",
1847
1847
  todowrite: "edit"
1848
1848
  };
1849
+ const APPROVAL_TOOL_CALL_WAIT_MS = 5e3;
1849
1850
  const HARNESS_CLIENT_APP = env.AI_SDK_HARNESS_CLIENT_APP;
1850
1851
  const args = parseArgs(argv.slice(2));
1851
1852
  const workdir = args.workdir ?? emitFatal("Missing --workdir argument.");
@@ -2480,9 +2481,31 @@ async function consumeEvents({ client, sessionId, permissionMode, inactiveBuilti
2480
2481
  const registerSubagentSession = (sourceSessionId) => function register({ parentSessionId, sessionId: subagentSessionId }) {
2481
2482
  if (parentSessionId === sourceSessionId && taskSessionIds.has(sourceSessionId)) taskSessionIds.add(subagentSessionId);
2482
2483
  };
2484
+ const sentToolCallIds = /* @__PURE__ */ new Set();
2485
+ const approvalsAwaitingToolCall = /* @__PURE__ */ new Map();
2486
+ const emitToHost = (message) => {
2487
+ emit(message);
2488
+ if (message.type !== "tool-call") return;
2489
+ const toolCallId = String(message.toolCallId);
2490
+ sentToolCallIds.add(toolCallId);
2491
+ approvalsAwaitingToolCall.get(toolCallId)?.();
2492
+ };
2493
+ const emitApprovalRequest = async (message) => {
2494
+ const toolCallId = String(message.toolCallId);
2495
+ if (!sentToolCallIds.has(toolCallId)) {
2496
+ let timeout;
2497
+ await new Promise((resolve) => {
2498
+ timeout = setTimeout(resolve, APPROVAL_TOOL_CALL_WAIT_MS);
2499
+ approvalsAwaitingToolCall.set(toolCallId, resolve);
2500
+ });
2501
+ clearTimeout(timeout);
2502
+ approvalsAwaitingToolCall.delete(toolCallId);
2503
+ }
2504
+ emit(message);
2505
+ };
2483
2506
  const emitStreamEvent = createEmitStreamEvent({
2484
2507
  state,
2485
- emit,
2508
+ emit: emitToHost,
2486
2509
  emitWarning: turn.emitWarning,
2487
2510
  emitError: turn.emitError,
2488
2511
  toWireToolName,
@@ -2596,6 +2619,7 @@ async function consumeEvents({ client, sessionId, permissionMode, inactiveBuilti
2596
2619
  if (consumeEvent(next.value)) break;
2597
2620
  }
2598
2621
  } finally {
2622
+ for (const release of approvalsAwaitingToolCall.values()) release();
2599
2623
  iterator.return?.();
2600
2624
  }
2601
2625
  function consumeEvent(rawEvent) {
@@ -2624,7 +2648,7 @@ async function consumeEvents({ client, sessionId, permissionMode, inactiveBuilti
2624
2648
  permissionMode,
2625
2649
  inactiveBuiltinToolNames,
2626
2650
  turn,
2627
- emit,
2651
+ emit: isDescendant ? emit : emitApprovalRequest,
2628
2652
  event,
2629
2653
  waitFor
2630
2654
  }));
@@ -2634,7 +2658,7 @@ async function consumeEvents({ client, sessionId, permissionMode, inactiveBuilti
2634
2658
  permissionMode,
2635
2659
  inactiveBuiltinToolNames,
2636
2660
  turn,
2637
- emit,
2661
+ emit: isDescendant ? emit : emitApprovalRequest,
2638
2662
  event,
2639
2663
  waitFor
2640
2664
  }));
@@ -2754,7 +2778,7 @@ async function selectPermissionReply({ action, resources, requestID, toolCallId,
2754
2778
  toolName,
2755
2779
  inactiveBuiltinToolNames
2756
2780
  })) {
2757
- emit({
2781
+ await emit({
2758
2782
  type: "tool-approval-request",
2759
2783
  approvalId: requestID,
2760
2784
  toolCallId
@@ -2772,7 +2796,7 @@ async function selectPermissionReply({ action, resources, requestID, toolCallId,
2772
2796
  };
2773
2797
  const kind = TOOL_KIND[toolName] ?? "bash";
2774
2798
  if (permissionMode === "allow-edits" ? kind === "readonly" || kind === "edit" : kind === "readonly") return { reply: "always" };
2775
- emit({
2799
+ await emit({
2776
2800
  type: "tool-approval-request",
2777
2801
  approvalId: requestID,
2778
2802
  toolCallId