agents 0.12.3 → 0.12.4

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 (81) hide show
  1. package/dist/{agent-tool-types-DSteYkkS.d.ts → agent-tool-types-CM_50fcV.d.ts} +104 -87
  2. package/dist/agent-tool-types.d.ts +1 -1
  3. package/dist/agent-tools-BAdX1vdI.js.map +1 -1
  4. package/dist/{agent-tools-eGTCdVZX.d.ts → agent-tools-BylX6WXG.d.ts} +2 -2
  5. package/dist/agent-tools.d.ts +1 -1
  6. package/dist/agent-tools.js.map +1 -1
  7. package/dist/browser/ai.d.ts +2 -2
  8. package/dist/browser/ai.js +1 -1
  9. package/dist/browser/ai.js.map +1 -1
  10. package/dist/browser/index.d.ts +41 -10
  11. package/dist/browser/index.js +1 -1
  12. package/dist/browser/tanstack-ai.d.ts +2 -2
  13. package/dist/browser/tanstack-ai.js +1 -1
  14. package/dist/browser/tanstack-ai.js.map +1 -1
  15. package/dist/chat/index.d.ts +297 -148
  16. package/dist/chat/index.js +43 -14
  17. package/dist/chat/index.js.map +1 -1
  18. package/dist/{classPrivateFieldGet2-Bqby-AHD.js → classPrivateFieldGet2-CS51BNGR.js} +5 -5
  19. package/dist/cli/index.d.ts +1 -1
  20. package/dist/cli/index.js.map +1 -1
  21. package/dist/client-D1kFXo80.js.map +1 -1
  22. package/dist/client.d.ts +1 -1
  23. package/dist/client.js.map +1 -1
  24. package/dist/codemode/ai.d.ts +1 -1
  25. package/dist/{compaction-helpers-CSaqCmdE.js → compaction-helpers-DvcZnvQ1.js} +1 -1
  26. package/dist/{compaction-helpers-CSaqCmdE.js.map → compaction-helpers-DvcZnvQ1.js.map} +1 -1
  27. package/dist/{compaction-helpers-CzCq1-fF.d.ts → compaction-helpers-bYvP1o2S.d.ts} +10 -3
  28. package/dist/{do-oauth-client-provider-C38aWbFV.d.ts → do-oauth-client-provider-4OKQU9rT.d.ts} +1 -1
  29. package/dist/{email-X72-zjuq.d.ts → email-J0GGS3sa.d.ts} +1 -1
  30. package/dist/email.d.ts +2 -2
  31. package/dist/email.js.map +1 -1
  32. package/dist/experimental/memory/session/index.d.ts +126 -26
  33. package/dist/experimental/memory/session/index.js +13 -3
  34. package/dist/experimental/memory/session/index.js.map +1 -1
  35. package/dist/experimental/memory/utils/index.d.ts +41 -5
  36. package/dist/experimental/memory/utils/index.js +15 -5
  37. package/dist/experimental/memory/utils/index.js.map +1 -1
  38. package/dist/experimental/webmcp.d.ts +9 -3
  39. package/dist/experimental/webmcp.js.map +1 -1
  40. package/dist/{index-Biv6K70p.d.ts → index-DKey3P4s.d.ts} +26 -2
  41. package/dist/index.d.ts +48 -44
  42. package/dist/index.js +122 -85
  43. package/dist/index.js.map +1 -1
  44. package/dist/{internal_context-BvuGZieY.d.ts → internal_context-BZrMS0B5.d.ts} +1 -1
  45. package/dist/internal_context.d.ts +1 -1
  46. package/dist/mcp/client.d.ts +26 -2
  47. package/dist/mcp/do-oauth-client-provider.d.ts +10 -2
  48. package/dist/mcp/do-oauth-client-provider.js.map +1 -1
  49. package/dist/mcp/index.d.ts +54 -2
  50. package/dist/mcp/index.js +43 -19
  51. package/dist/mcp/index.js.map +1 -1
  52. package/dist/mcp/x402.d.ts +74 -17
  53. package/dist/mcp/x402.js.map +1 -1
  54. package/dist/observability/index.d.ts +16 -2
  55. package/dist/observability/index.js +1 -1
  56. package/dist/observability/index.js.map +1 -1
  57. package/dist/react.d.ts +2 -2
  58. package/dist/react.js.map +1 -1
  59. package/dist/{retries-fLD8cGNf.d.ts → retries-BVdRl5ZE.d.ts} +1 -1
  60. package/dist/retries.d.ts +1 -1
  61. package/dist/retries.js.map +1 -1
  62. package/dist/schedule.js.map +1 -1
  63. package/dist/serializable.d.ts +1 -1
  64. package/dist/{shared-Ch9slKdI.d.ts → shared-Cvj92byG.d.ts} +1 -1
  65. package/dist/{shared-C6l4ZKRN.js → shared-DzJYHisH.js} +3 -3
  66. package/dist/{shared-C6l4ZKRN.js.map → shared-DzJYHisH.js.map} +1 -1
  67. package/dist/sub-routing.d.ts +6 -6
  68. package/dist/sub-routing.js.map +1 -1
  69. package/dist/tool-output-truncation-CH-khbZ3.js +98 -0
  70. package/dist/tool-output-truncation-CH-khbZ3.js.map +1 -0
  71. package/dist/{types-DAHCZC_W.d.ts → types-_JjKmv-l.d.ts} +1 -1
  72. package/dist/types.d.ts +1 -1
  73. package/dist/types.js.map +1 -1
  74. package/dist/utils.js.map +1 -1
  75. package/dist/vite.js.map +1 -1
  76. package/dist/{workflow-types-DHs0L0KP.d.ts → workflow-types-Dkzg4hAx.d.ts} +1 -1
  77. package/dist/workflow-types.d.ts +1 -1
  78. package/dist/workflow-types.js.map +1 -1
  79. package/dist/workflows.d.ts +2 -2
  80. package/dist/workflows.js.map +1 -1
  81. package/package.json +9 -9
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import { __DO_NOT_USE_WILL_BREAK__agentContext } from "./internal_context.js";
2
2
  import { MessageType } from "./types.js";
3
3
  import { camelCaseToKebabCase } from "./utils.js";
4
4
  import { createHeaderBasedEmailResolver, signAgentHeaders } from "./email.js";
5
- import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldSet2, t as _classPrivateFieldGet2 } from "./classPrivateFieldGet2-Bqby-AHD.js";
5
+ import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldSet2, t as _classPrivateFieldGet2 } from "./classPrivateFieldGet2-CS51BNGR.js";
6
6
  import { SUB_PREFIX, getSubAgentByName, parseSubAgentPath, routeSubAgentRequest } from "./sub-routing.js";
7
7
  import { isErrorRetryable, tryN, validateRetryOptions } from "./retries.js";
8
8
  import { o as RPC_DO_PREFIX, r as MCPConnectionState, s as DisposableStore, t as MCPClientManager } from "./client-D1kFXo80.js";
@@ -587,6 +587,7 @@ var Agent = class Agent extends Server {
587
587
  this._persistenceHookMode = "none";
588
588
  this._isFacet = false;
589
589
  this._suppressProtocolBroadcasts = false;
590
+ this._protocolBroadcastExcludeIds = /* @__PURE__ */ new Set();
590
591
  this._cf_virtualSubAgentConnections = /* @__PURE__ */ new Map();
591
592
  this._parentPath = [];
592
593
  this._insideOnStart = false;
@@ -770,8 +771,16 @@ var Agent = class Agent extends Server {
770
771
  type: "cf_agent_identity"
771
772
  }));
772
773
  }
773
- if (this.state) connection.send(JSON.stringify({
774
- state: this.state,
774
+ const wasExcludedFromStateInitBroadcast = this._protocolBroadcastExcludeIds.has(connection.id);
775
+ let currentState;
776
+ this._protocolBroadcastExcludeIds.add(connection.id);
777
+ try {
778
+ currentState = this.state;
779
+ } finally {
780
+ if (!wasExcludedFromStateInitBroadcast) this._protocolBroadcastExcludeIds.delete(connection.id);
781
+ }
782
+ if (currentState !== void 0) connection.send(JSON.stringify({
783
+ state: currentState,
775
784
  type: "cf_agent_state"
776
785
  }));
777
786
  connection.send(JSON.stringify({
@@ -823,14 +832,17 @@ var Agent = class Agent extends Server {
823
832
  this.broadcastMcpServers();
824
833
  this._checkOrphanedWorkflows();
825
834
  await this._checkRunFibers();
826
- await this._reconcileAgentToolRuns();
835
+ const recoveredAgentToolFinishes = await this._reconcileAgentToolRuns({ deferFinishHooks: true });
827
836
  this._insideOnStart = true;
828
837
  this._warnedScheduleInOnStart.clear();
838
+ let result;
829
839
  try {
830
- return await _onStart(props);
840
+ result = await _onStart(props);
831
841
  } finally {
832
842
  this._insideOnStart = false;
833
843
  }
844
+ await this._runDeferredAgentToolFinishHooks(recoveredAgentToolFinishes);
845
+ return result;
834
846
  });
835
847
  });
836
848
  };
@@ -866,7 +878,7 @@ var Agent = class Agent extends Server {
866
878
  */
867
879
  _broadcastProtocol(msg, excludeIds = []) {
868
880
  if (this._suppressProtocolBroadcasts) return;
869
- const exclude = [...excludeIds];
881
+ const exclude = [...excludeIds, ...this._protocolBroadcastExcludeIds];
870
882
  for (const conn of this.getConnections()) if (!this.isConnectionProtocolEnabled(conn)) exclude.push(conn.id);
871
883
  this.broadcast(msg, exclude);
872
884
  }
@@ -1101,7 +1113,7 @@ var Agent = class Agent extends Server {
1101
1113
  *
1102
1114
  * IMPORTANT: This hook must be synchronous.
1103
1115
  */
1104
- validateStateChange(nextState, source) {}
1116
+ validateStateChange(_nextState, _source) {}
1105
1117
  /**
1106
1118
  * Called after the Agent's state has been persisted and broadcast to all clients.
1107
1119
  * This is a notification hook — errors here are routed to onError and do not
@@ -1110,7 +1122,7 @@ var Agent = class Agent extends Server {
1110
1122
  * @param state Updated state
1111
1123
  * @param source Source of the state update ("server" or a client connection)
1112
1124
  */
1113
- onStateChanged(state, source) {}
1125
+ onStateChanged(_state, _source) {}
1114
1126
  /**
1115
1127
  * @deprecated Renamed to `onStateChanged` — the behavior is identical.
1116
1128
  * `onStateUpdate` will be removed in the next major version.
@@ -1122,7 +1134,7 @@ var Agent = class Agent extends Server {
1122
1134
  * @param state Updated state
1123
1135
  * @param source Source of the state update ("server" or a client connection)
1124
1136
  */
1125
- onStateUpdate(state, source) {}
1137
+ onStateUpdate(_state, _source) {}
1126
1138
  /**
1127
1139
  * Dispatch to the appropriate persistence hook based on the mode
1128
1140
  * cached in the constructor. No prototype walks at call time.
@@ -2398,11 +2410,16 @@ var Agent = class Agent extends Server {
2398
2410
  if (!this._isSameAgentPathPrefix(selfPath, ownerPath)) throw new Error(`Schedule owner path does not descend from ${JSON.stringify(selfPath)}.`);
2399
2411
  if (selfPath.length === ownerPath.length) {
2400
2412
  await this._executeScheduleCallback(row);
2401
- return;
2413
+ return true;
2402
2414
  }
2403
2415
  const next = ownerPath[selfPath.length];
2404
- if (!this.hasSubAgent(next.className, next.name)) throw new Error(`Scheduled sub-agent ${next.className} "${next.name}" no longer exists.`);
2405
- await (await this._cf_resolveSubAgent(next.className, next.name))._cf_dispatchScheduledCallback(ownerPath, row);
2416
+ if (!this.hasSubAgent(next.className, next.name)) {
2417
+ const stalePath = ownerPath.slice(0, selfPath.length + 1);
2418
+ if (this._isFacet) await (await this._rootAlarmOwner())._cf_cleanupFacetPrefix(stalePath);
2419
+ else await this._cf_cleanupFacetPrefix(stalePath);
2420
+ return false;
2421
+ }
2422
+ return (await this._cf_resolveSubAgent(next.className, next.name))._cf_dispatchScheduledCallback(ownerPath, row);
2406
2423
  }
2407
2424
  /**
2408
2425
  * Recursively destroy a descendant facet identified by
@@ -2586,7 +2603,7 @@ var Agent = class Agent extends Server {
2586
2603
  if (row.type === "interval") this.sql`UPDATE cf_agents_schedules SET running = 1, execution_started_at = ${now} WHERE id = ${row.id}`;
2587
2604
  if (row.owner_path) try {
2588
2605
  const ownerPath = JSON.parse(row.owner_path);
2589
- await this._cf_dispatchScheduledCallback(ownerPath, row);
2606
+ executed = await this._cf_dispatchScheduledCallback(ownerPath, row);
2590
2607
  } catch (e) {
2591
2608
  console.error(`error dispatching scheduled callback "${row.callback}"`, e);
2592
2609
  this._emit("schedule:error", {
@@ -2603,8 +2620,10 @@ var Agent = class Agent extends Server {
2603
2620
  `;
2604
2621
  continue;
2605
2622
  }
2606
- else await this._executeScheduleCallback(row);
2607
- executed = true;
2623
+ else {
2624
+ await this._executeScheduleCallback(row);
2625
+ executed = true;
2626
+ }
2608
2627
  if (this._destroyed) return;
2609
2628
  if (!executed) continue;
2610
2629
  if (row.type === "cron") {
@@ -3238,7 +3257,7 @@ var Agent = class Agent extends Server {
3238
3257
  } catch {}
3239
3258
  return this._resultFromAgentToolRow(existing);
3240
3259
  }
3241
- return await this._replayAndInterruptAgentToolRun(cls, existing, "Agent tool run was still running, but live-tail reattachment is not supported in this runtime.");
3260
+ return await this._replayAndInterruptAgentToolRun(existing, "Agent tool run was still running, but live-tail reattachment is not supported in this runtime.");
3242
3261
  }
3243
3262
  const displayOrder = options.displayOrder ?? 0;
3244
3263
  const inputPreview = options.inputPreview ?? this._defaultAgentToolPreview(options.input);
@@ -3321,13 +3340,7 @@ var Agent = class Agent extends Server {
3321
3340
  status: "aborted",
3322
3341
  error: options.signal.reason instanceof Error ? options.signal.reason.message : String(options.signal.reason ?? "cancelled")
3323
3342
  };
3324
- this._updateAgentToolTerminal(runId, result);
3325
- this._broadcastAgentToolTerminal(options.parentToolCallId, sequence, result);
3326
- await this.onAgentToolFinish({
3327
- ...runInfo,
3328
- status: "aborted",
3329
- completedAt: Date.now()
3330
- }, result);
3343
+ await this._finishAgentToolRun(runInfo, result, { sequence });
3331
3344
  return result;
3332
3345
  } else {
3333
3346
  parentAbortListener = () => {
@@ -3351,24 +3364,15 @@ var Agent = class Agent extends Server {
3351
3364
  status: "aborted",
3352
3365
  error: options.signal.reason instanceof Error ? options.signal.reason.message : String(options.signal.reason ?? "cancelled")
3353
3366
  };
3354
- this._updateAgentToolTerminal(runId, result);
3355
- this._broadcastAgentToolTerminal(options.parentToolCallId, sequence, result);
3356
- await this.onAgentToolFinish({
3357
- ...runInfo,
3358
- status: "aborted",
3359
- completedAt: Date.now()
3360
- }, result);
3367
+ await this._finishAgentToolRun(runInfo, result, { sequence });
3361
3368
  return result;
3362
3369
  }
3363
3370
  const inspection = await adapter.inspectAgentToolRun(runId) ?? childStart;
3364
3371
  const result = this._terminalResultFromInspection(agentType, inspection);
3365
- this._updateAgentToolTerminal(runId, result, inspection.completedAt);
3366
- this._broadcastAgentToolTerminal(options.parentToolCallId, sequence, result);
3367
- await this.onAgentToolFinish({
3368
- ...runInfo,
3369
- status: result.status,
3370
- completedAt: Date.now()
3371
- }, result);
3372
+ await this._finishAgentToolRun(runInfo, result, {
3373
+ sequence,
3374
+ completedAt: inspection.completedAt
3375
+ });
3372
3376
  return result;
3373
3377
  } catch (error) {
3374
3378
  if (options.signal?.aborted) {
@@ -3379,13 +3383,7 @@ var Agent = class Agent extends Server {
3379
3383
  status: "aborted",
3380
3384
  error: options.signal.reason instanceof Error ? options.signal.reason.message : String(options.signal.reason ?? "cancelled")
3381
3385
  };
3382
- this._updateAgentToolTerminal(runId, result);
3383
- this._broadcastAgentToolTerminal(options.parentToolCallId, sequence, result);
3384
- await this.onAgentToolFinish({
3385
- ...runInfo,
3386
- status: "aborted",
3387
- completedAt: Date.now()
3388
- }, result);
3386
+ await this._finishAgentToolRun(runInfo, result, { sequence });
3389
3387
  return result;
3390
3388
  }
3391
3389
  const result = {
@@ -3394,13 +3392,7 @@ var Agent = class Agent extends Server {
3394
3392
  status: "error",
3395
3393
  error: error instanceof Error ? error.message : String(error)
3396
3394
  };
3397
- this._updateAgentToolTerminal(runId, result);
3398
- this._broadcastAgentToolTerminal(options.parentToolCallId, sequence, result);
3399
- await this.onAgentToolFinish({
3400
- ...runInfo,
3401
- status: "error",
3402
- completedAt: Date.now()
3403
- }, result);
3395
+ await this._finishAgentToolRun(runInfo, result, { sequence });
3404
3396
  return result;
3405
3397
  } finally {
3406
3398
  if (parentAbortListener && options.signal) options.signal.removeEventListener("abort", parentAbortListener);
@@ -3481,6 +3473,19 @@ var Agent = class Agent extends Server {
3481
3473
  ...row.error_message !== null ? { error: row.error_message } : {}
3482
3474
  };
3483
3475
  }
3476
+ _agentToolRunInfoFromRow(row, status = row.status, completedAt = row.completed_at ?? void 0) {
3477
+ return {
3478
+ runId: row.run_id,
3479
+ parentToolCallId: row.parent_tool_call_id ?? void 0,
3480
+ agentType: row.agent_type,
3481
+ inputPreview: this._parseAgentToolJson(row.input_preview),
3482
+ status,
3483
+ display: this._parseAgentToolJson(row.display_metadata),
3484
+ displayOrder: row.display_order,
3485
+ startedAt: row.started_at,
3486
+ completedAt
3487
+ };
3488
+ }
3484
3489
  _terminalResultFromInspection(agentType, inspection) {
3485
3490
  if (inspection.status === "completed") return {
3486
3491
  runId: inspection.runId,
@@ -3502,6 +3507,27 @@ var Agent = class Agent extends Server {
3502
3507
  error: inspection.error ?? "Agent tool run failed"
3503
3508
  };
3504
3509
  }
3510
+ async _finishAgentToolRun(run, result, options) {
3511
+ const completedAt = options?.completedAt ?? Date.now();
3512
+ this._updateAgentToolTerminal(run.runId, result, completedAt);
3513
+ if (options?.sequence !== void 0) this._broadcastAgentToolTerminal(run.parentToolCallId, options.sequence, result);
3514
+ const finish = () => this.onAgentToolFinish({
3515
+ ...run,
3516
+ status: result.status,
3517
+ completedAt
3518
+ }, result);
3519
+ if (options?.deferFinishHook) return finish;
3520
+ await finish();
3521
+ }
3522
+ async _runDeferredAgentToolFinishHooks(hooks) {
3523
+ for (const hook of hooks) try {
3524
+ await hook();
3525
+ } catch (error) {
3526
+ try {
3527
+ await this.onError(error);
3528
+ } catch {}
3529
+ }
3530
+ }
3505
3531
  _updateAgentToolTerminal(runId, result, completedAt = Date.now()) {
3506
3532
  this.sql`
3507
3533
  UPDATE cf_agent_tool_runs
@@ -3561,6 +3587,11 @@ var Agent = class Agent extends Server {
3561
3587
  }, replay, connection);
3562
3588
  return next;
3563
3589
  }
3590
+ async _broadcastAgentToolStoredChunks(row, sequence, replay, connection) {
3591
+ const child = await this._cf_resolveSubAgent(row.agent_type, row.run_id);
3592
+ const chunks = await this._asAgentToolChildAdapter(child).getAgentToolChunks(row.run_id);
3593
+ return this._broadcastAgentToolChunks(row.parent_tool_call_id ?? void 0, row.run_id, chunks, sequence, replay, connection);
3594
+ }
3564
3595
  async _forwardAgentToolStream(stream, parentToolCallId, runId, sequence, signal) {
3565
3596
  let next = sequence;
3566
3597
  if (signal?.aborted) return next;
@@ -3656,13 +3687,10 @@ var Agent = class Agent extends Server {
3656
3687
  if (!cls) throw new Error(`Agent tool class "${className}" is not exported.`);
3657
3688
  return cls;
3658
3689
  }
3659
- async _replayAndInterruptAgentToolRun(cls, row, message) {
3660
- const parentToolCallId = row.parent_tool_call_id ?? void 0;
3690
+ async _replayAndInterruptAgentToolRun(row, message) {
3661
3691
  let sequence = 1;
3662
3692
  try {
3663
- const child = await this.subAgent(cls, row.run_id);
3664
- const chunks = await this._asAgentToolChildAdapter(child).getAgentToolChunks(row.run_id);
3665
- sequence = this._broadcastAgentToolChunks(parentToolCallId, row.run_id, chunks, sequence);
3693
+ sequence = await this._broadcastAgentToolStoredChunks(row, sequence);
3666
3694
  } catch {}
3667
3695
  const result = {
3668
3696
  runId: row.run_id,
@@ -3670,8 +3698,7 @@ var Agent = class Agent extends Server {
3670
3698
  status: "interrupted",
3671
3699
  error: message
3672
3700
  };
3673
- this._updateAgentToolTerminal(row.run_id, result);
3674
- this._broadcastAgentToolTerminal(parentToolCallId, sequence, result);
3701
+ await this._finishAgentToolRun(this._agentToolRunInfoFromRow(row), result, { sequence });
3675
3702
  return result;
3676
3703
  }
3677
3704
  async _replayAgentToolRuns(connection) {
@@ -3693,9 +3720,7 @@ var Agent = class Agent extends Server {
3693
3720
  display: this._parseAgentToolJson(row.display_metadata)
3694
3721
  }, true, connection);
3695
3722
  try {
3696
- const child = await this.subAgent(this._agentToolClassByName(row.agent_type), row.run_id);
3697
- const chunks = await this._asAgentToolChildAdapter(child).getAgentToolChunks(row.run_id);
3698
- sequence = this._broadcastAgentToolChunks(parentToolCallId, row.run_id, chunks, sequence, true, connection);
3723
+ sequence = await this._broadcastAgentToolStoredChunks(row, sequence, true, connection);
3699
3724
  } catch {}
3700
3725
  if (this._isAgentToolTerminal(row.status)) this._broadcastAgentToolTerminal(parentToolCallId, sequence, {
3701
3726
  runId: row.run_id,
@@ -3707,40 +3732,52 @@ var Agent = class Agent extends Server {
3707
3732
  }, true, connection);
3708
3733
  }
3709
3734
  }
3710
- async _reconcileAgentToolRuns() {
3735
+ async _reconcileAgentToolRuns(options) {
3736
+ const deferredFinishes = [];
3711
3737
  const rows = this.sql`
3712
- SELECT run_id, agent_type FROM cf_agent_tool_runs
3738
+ SELECT run_id, parent_tool_call_id, agent_type, input_preview, status,
3739
+ summary, output_json, error_message, display_metadata, display_order,
3740
+ started_at, completed_at
3741
+ FROM cf_agent_tool_runs
3713
3742
  WHERE status IN ('starting', 'running')
3714
3743
  ORDER BY started_at ASC
3715
3744
  `;
3716
- for (const row of rows) try {
3717
- const cls = this._agentToolClassByName(row.agent_type);
3718
- if (!this.hasSubAgent(cls, row.run_id)) {
3719
- this._updateAgentToolTerminal(row.run_id, {
3745
+ for (const row of rows) {
3746
+ let sequence = 1;
3747
+ let completedAt;
3748
+ let result;
3749
+ try {
3750
+ const child = await this._cf_resolveSubAgent(row.agent_type, row.run_id);
3751
+ const inspection = await this._asAgentToolChildAdapter(child).inspectAgentToolRun(row.run_id);
3752
+ try {
3753
+ sequence = await this._broadcastAgentToolStoredChunks(row, sequence);
3754
+ } catch {}
3755
+ if (!inspection || inspection.status === "running" || inspection.status === "starting") result = {
3720
3756
  runId: row.run_id,
3721
3757
  agentType: row.agent_type,
3722
3758
  status: "interrupted",
3723
- error: "Agent tool child was not found during parent recovery."
3724
- });
3725
- continue;
3759
+ error: "Agent tool run was still running, but live-tail reattachment is not supported in this runtime."
3760
+ };
3761
+ else {
3762
+ result = this._terminalResultFromInspection(row.agent_type, inspection);
3763
+ completedAt = inspection.completedAt;
3764
+ }
3765
+ } catch {
3766
+ result = {
3767
+ runId: row.run_id,
3768
+ agentType: row.agent_type,
3769
+ status: "interrupted",
3770
+ error: "Agent tool run could not be inspected during parent recovery."
3771
+ };
3726
3772
  }
3727
- const child = await this.subAgent(cls, row.run_id);
3728
- const inspection = await this._asAgentToolChildAdapter(child).inspectAgentToolRun(row.run_id);
3729
- if (!inspection || inspection.status === "running" || inspection.status === "starting") this._updateAgentToolTerminal(row.run_id, {
3730
- runId: row.run_id,
3731
- agentType: row.agent_type,
3732
- status: "interrupted",
3733
- error: "Agent tool run was still running, but live-tail reattachment is not supported in this runtime."
3734
- });
3735
- else this._updateAgentToolTerminal(row.run_id, this._terminalResultFromInspection(row.agent_type, inspection), inspection.completedAt);
3736
- } catch {
3737
- this._updateAgentToolTerminal(row.run_id, {
3738
- runId: row.run_id,
3739
- agentType: row.agent_type,
3740
- status: "interrupted",
3741
- error: "Agent tool run could not be inspected during parent recovery."
3773
+ const deferredFinish = await this._finishAgentToolRun(this._agentToolRunInfoFromRow(row), result, {
3774
+ sequence,
3775
+ completedAt,
3776
+ deferFinishHook: options?.deferFinishHooks
3742
3777
  });
3778
+ if (deferredFinish) deferredFinishes.push(deferredFinish);
3743
3779
  }
3780
+ return deferredFinishes;
3744
3781
  }
3745
3782
  /**
3746
3783
  * Shared facet resolution — takes a CamelCase class name string