@ai-sdk/harness-opencode 1.0.96 → 1.0.98

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,24 @@
1
1
  # @ai-sdk/harness-opencode
2
2
 
3
+ ## 1.0.98
4
+
5
+ ### Patch Changes
6
+
7
+ - c0c7fac: feat(harness): add reusable `createReadBridgeAsset()` helper function
8
+ - Updated dependencies [c0c7fac]
9
+ - @ai-sdk/harness@1.0.96
10
+
11
+ ## 1.0.97
12
+
13
+ ### Patch Changes
14
+
15
+ - c1941f0: fix(harness-opencode): emit per-step token usage and cost for task-linked OpenCode subagent sessions as raw stream events
16
+ - 371e954: feat(harness): add `createBridgeToken()` and `withBridgeToken()` helpers for bridge backed harness adapters
17
+ - 62f481f: fix(harness): fix bridge resolution to no longer look for an alternative path which could cause Turbopack errors
18
+ - Updated dependencies [371e954]
19
+ - Updated dependencies [87b4858]
20
+ - @ai-sdk/harness@1.0.95
21
+
3
22
  ## 1.0.96
4
23
 
5
24
  ### Patch Changes
@@ -2371,9 +2371,33 @@ async function consumeEvents({
2371
2371
  let processEvent = descendantEventProcessors.get(descendantSessionId);
2372
2372
  if (!processEvent) {
2373
2373
  const descendantState = createTranslationState();
2374
+ let currentEvent;
2375
+ let modelId;
2376
+ const emittedUsageStepIds = /* @__PURE__ */ new Set();
2374
2377
  processEvent = createEmitStreamEvent({
2375
2378
  state: descendantState,
2376
- emit: () => void 0,
2379
+ emit: (message) => {
2380
+ if (message.type !== "finish-step") return;
2381
+ const stepId = getSubagentStepId(currentEvent);
2382
+ if (!stepId || emittedUsageStepIds.has(stepId)) return;
2383
+ emittedUsageStepIds.add(stepId);
2384
+ const opencodeMetadata = asOpenCodeObject(
2385
+ message.harnessMetadata
2386
+ )?.opencode;
2387
+ const cost = asOpenCodeObject(opencodeMetadata)?.cost;
2388
+ emit({
2389
+ type: "raw",
2390
+ rawValue: {
2391
+ type: "opencode.subagent-usage",
2392
+ version: 1,
2393
+ sessionId: descendantSessionId,
2394
+ stepId,
2395
+ ...modelId ? { modelId } : {},
2396
+ usage: message.usage,
2397
+ ...typeof cost === "number" ? { cost } : {}
2398
+ }
2399
+ });
2400
+ },
2377
2401
  emitWarning: () => void 0,
2378
2402
  emitError: () => void 0,
2379
2403
  toWireToolName,
@@ -2385,6 +2409,19 @@ async function consumeEvents({
2385
2409
  stripWorkDir,
2386
2410
  formatError
2387
2411
  });
2412
+ const emitDescendantEvent = processEvent;
2413
+ processEvent = (descendantEvent) => {
2414
+ currentEvent = descendantEvent;
2415
+ if (descendantEvent.type === "message.updated") {
2416
+ const info = openCodeMessageInfoFromValue(
2417
+ descendantEvent.properties?.info
2418
+ );
2419
+ const providerID = stringValue2(info?.providerID);
2420
+ const modelID = stringValue2(info?.modelID);
2421
+ if (providerID && modelID) modelId = `${providerID}/${modelID}`;
2422
+ }
2423
+ emitDescendantEvent(descendantEvent);
2424
+ };
2388
2425
  descendantEventProcessors.set(descendantSessionId, processEvent);
2389
2426
  }
2390
2427
  processEvent(event);
@@ -2426,6 +2463,15 @@ async function consumeEvents({
2426
2463
  if (onEvent?.(event)) break;
2427
2464
  }
2428
2465
  }
2466
+ function getSubagentStepId(event) {
2467
+ if (event?.type === "message.part.updated") {
2468
+ const part = asOpenCodeObject(event.properties?.part);
2469
+ if (part?.type !== "step-finish") return void 0;
2470
+ return stringValue2(part.id) ?? stringValue2(part.messageID) ?? event.id;
2471
+ }
2472
+ if (event?.type !== "session.next.step.ended") return void 0;
2473
+ return stringValue2(event.properties?.stepID) ?? event.id;
2474
+ }
2429
2475
  function sanitizeMcpToolName(value) {
2430
2476
  return value.replace(/[^a-zA-Z0-9_-]/g, "_");
2431
2477
  }