agents 0.15.0 → 0.16.1

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 (53) hide show
  1. package/dist/{agent-tool-types-VPsjVYL0.d.ts → agent-tool-types-NofdbL9X.d.ts} +57 -4
  2. package/dist/agent-tool-types.d.ts +1 -1
  3. package/dist/{agent-tools-BGpgfpJT.d.ts → agent-tools-DLquv-dp.d.ts} +2 -2
  4. package/dist/agent-tools.d.ts +1 -1
  5. package/dist/browser/ai.d.ts +211 -7
  6. package/dist/browser/ai.js +236 -25
  7. package/dist/browser/ai.js.map +1 -1
  8. package/dist/browser/index.d.ts +133 -69
  9. package/dist/browser/index.js +3 -2
  10. package/dist/browser/tanstack-ai.d.ts +17 -7
  11. package/dist/browser/tanstack-ai.js +25 -19
  12. package/dist/browser/tanstack-ai.js.map +1 -1
  13. package/dist/chat/index.d.ts +111 -5
  14. package/dist/chat/index.js +207 -35
  15. package/dist/chat/index.js.map +1 -1
  16. package/dist/chat-sdk/index.d.ts +1 -1
  17. package/dist/{classPrivateFieldGet2-Beqsfu2Z.js → classPrivateFieldGet2-CZ7QjTXN.js} +5 -5
  18. package/dist/{classPrivateMethodInitSpec-B5ko1s2R.js → classPrivateMethodInitSpec-D-0__zd9.js} +2 -2
  19. package/dist/client.d.ts +19 -2
  20. package/dist/client.js +31 -11
  21. package/dist/client.js.map +1 -1
  22. package/dist/{compaction-helpers-BEUILPss.d.ts → compaction-helpers-DVcu5lPN.d.ts} +91 -12
  23. package/dist/connector-CrKhowfD.js +1291 -0
  24. package/dist/connector-CrKhowfD.js.map +1 -0
  25. package/dist/connector-v2M1zlZp.d.ts +659 -0
  26. package/dist/experimental/memory/session/index.d.ts +75 -12
  27. package/dist/experimental/memory/session/index.js +226 -21
  28. package/dist/experimental/memory/session/index.js.map +1 -1
  29. package/dist/experimental/memory/utils/index.d.ts +2 -2
  30. package/dist/{index-CPe1OtI0.d.ts → index-B7IbEeze.d.ts} +32 -1
  31. package/dist/index.d.ts +8 -2
  32. package/dist/index.js +119 -45
  33. package/dist/index.js.map +1 -1
  34. package/dist/mcp/client.d.ts +1 -1
  35. package/dist/mcp/index.d.ts +1 -1
  36. package/dist/mcp/index.js +1 -1
  37. package/dist/mcp/index.js.map +1 -1
  38. package/dist/observability/index.d.ts +1 -1
  39. package/dist/react.d.ts +12 -1
  40. package/dist/react.js +101 -30
  41. package/dist/react.js.map +1 -1
  42. package/dist/{retries-CF_HKSlJ.d.ts → retries-CwlpAGet.d.ts} +35 -5
  43. package/dist/retries.d.ts +9 -5
  44. package/dist/retries.js +87 -1
  45. package/dist/retries.js.map +1 -1
  46. package/dist/serializable.d.ts +1 -1
  47. package/dist/skills/index.js +2 -2
  48. package/dist/sub-routing.d.ts +1 -1
  49. package/dist/workflows.d.ts +1 -1
  50. package/package.json +11 -11
  51. package/dist/shared-4CAYLCTO.d.ts +0 -34
  52. package/dist/shared-wyII629d.js +0 -432
  53. package/dist/shared-wyII629d.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import {
2
- M as SessionMessage,
2
+ P as SessionMessage,
3
3
  a as alignBoundaryBackward,
4
4
  c as computeSummaryBudget,
5
5
  d as isCompactionMessage,
@@ -12,7 +12,7 @@ import {
12
12
  s as buildSummaryPrompt,
13
13
  t as COMPACTION_PREFIX,
14
14
  u as findTailCutByTokens
15
- } from "../../../compaction-helpers-BEUILPss.js";
15
+ } from "../../../compaction-helpers-DVcu5lPN.js";
16
16
 
17
17
  //#region src/experimental/memory/utils/tokens.d.ts
18
18
  /** Approximate characters per token for English text */
@@ -408,6 +408,37 @@ type AgentObservabilityEvent =
408
408
  toolCallIds?: string[];
409
409
  }
410
410
  >
411
+ | BaseEvent<
412
+ "chat:onstart:degraded",
413
+ {
414
+ /**
415
+ * Internal onStart step that failed and was skipped so the agent
416
+ * could still come up instead of bricking the DO (#1710).
417
+ */
418
+ step:
419
+ | "transcript-hydration"
420
+ | "scheduled-task-reconcile"
421
+ | "durable-work-recovery";
422
+ error: string;
423
+ }
424
+ >
425
+ | BaseEvent<
426
+ "chat:hydration:windowed",
427
+ {
428
+ /** Stored size of the full active path, in bytes. */ totalContentBytes: number /** The configured `hydrationByteBudget`. */;
429
+ budgetBytes: number /** Number of recent messages hydrated into the in-memory window. */;
430
+ hydratedMessages: number;
431
+ }
432
+ >
433
+ | BaseEvent<
434
+ "chat:media:evicted",
435
+ {
436
+ /** Stored messages rewritten during this eviction pass. */ messages: number /** Individual oversized parts evicted across those messages. */;
437
+ parts: number /** Total bytes removed from the stored transcript. */;
438
+ bytes: number /** Bytes preserved as workspace files (≤ `bytes`). */;
439
+ externalizedBytes: number;
440
+ }
441
+ >
411
442
  | BaseEvent<
412
443
  "chat:stream:stalled",
413
444
  {
@@ -730,4 +761,4 @@ export {
730
761
  MCPObservabilityEvent as s,
731
762
  ChannelEventMap as t
732
763
  };
733
- //# sourceMappingURL=index-CPe1OtI0.d.ts.map
764
+ //# sourceMappingURL=index-B7IbEeze.d.ts.map
package/dist/index.d.ts CHANGED
@@ -71,9 +71,13 @@ import {
71
71
  xt as normalizeServerId,
72
72
  y as AddRpcMcpServerOptions,
73
73
  z as MCPServer
74
- } from "./agent-tool-types-VPsjVYL0.js";
74
+ } from "./agent-tool-types-NofdbL9X.js";
75
75
  import { n as camelCaseToKebabCase } from "./utils-CGtGDSgA.js";
76
- import { t as RetryOptions } from "./retries-CF_HKSlJ.js";
76
+ import {
77
+ i as isPlatformTransientError,
78
+ n as isDurableObjectCodeUpdateReset,
79
+ t as RetryOptions
80
+ } from "./retries-CwlpAGet.js";
77
81
  import {
78
82
  n as AgentsOAuthProvider,
79
83
  r as DurableObjectOAuthClientProvider,
@@ -154,6 +158,8 @@ export {
154
158
  getAgentByName,
155
159
  getCurrentAgent,
156
160
  getSubAgentByName,
161
+ isDurableObjectCodeUpdateReset,
162
+ isPlatformTransientError,
157
163
  normalizeServerId,
158
164
  parseSubAgentPath,
159
165
  routeAgentEmail,
package/dist/index.js CHANGED
@@ -2,9 +2,9 @@ import { __DO_NOT_USE_WILL_BREAK__agentContext } from "./internal_context.js";
2
2
  import { MessageType } from "./types.js";
3
3
  import { camelCaseToKebabCase, isInternalJsStubProp } from "./utils.js";
4
4
  import { createHeaderBasedEmailResolver, signAgentHeaders } from "./email.js";
5
- import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldSet2, t as _classPrivateFieldGet2 } from "./classPrivateFieldGet2-Beqsfu2Z.js";
5
+ import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldSet2, t as _classPrivateFieldGet2 } from "./classPrivateFieldGet2-CZ7QjTXN.js";
6
6
  import { SUB_PREFIX, getSubAgentByName, parseSubAgentPath, routeSubAgentRequest } from "./sub-routing.js";
7
- import { isErrorRetryable, tryN, validateRetryOptions } from "./retries.js";
7
+ import { isDurableObjectCodeUpdateReset, isErrorRetryable, isPlatformTransientError, tryN, validateRetryOptions } from "./retries.js";
8
8
  import { a as MCPConnectionState, c as RPC_DO_PREFIX, i as normalizeServerId, l as DisposableStore, n as MCP_SERVER_ID_MAX_LENGTH, t as MCPClientManager } from "./client-FUizKzj2.js";
9
9
  import { DurableObjectOAuthClientProvider } from "./mcp/do-oauth-client-provider.js";
10
10
  import { genericObservability } from "./observability/index.js";
@@ -16,6 +16,18 @@ import { RpcTarget, exports } from "cloudflare:workers";
16
16
  import { Server, getServerByName, routePartykitRequest } from "partyserver";
17
17
  //#region src/index.ts
18
18
  let _Symbol$dispose;
19
+ function isClosedWebSocketSendError(error) {
20
+ return error instanceof TypeError && error.message.includes("WebSocket send() after close");
21
+ }
22
+ function sendRpcResponseIfOpen(connection, response) {
23
+ try {
24
+ connection.send(JSON.stringify(response));
25
+ return true;
26
+ } catch (error) {
27
+ if (isClosedWebSocketSendError(error)) return false;
28
+ throw error;
29
+ }
30
+ }
19
31
  /**
20
32
  * Type guard for RPC request messages
21
33
  */
@@ -116,6 +128,10 @@ function getNextCronTime(cron) {
116
128
  const DEFAULT_KEEP_ALIVE_INTERVAL_MS = 3e4;
117
129
  const DEFAULT_AGENT_TOOL_RECOVERY_TIMEOUT_MS = 2e3;
118
130
  const DEFAULT_AGENT_TOOL_RECOVERY_TOTAL_TIMEOUT_MS = 5e3;
131
+ const DESTROY_PENDING_KEY = "cf_agents_destroy_pending";
132
+ const DESTROY_ALARM_DELAY_MS = 1e3;
133
+ const FIBER_RECOVERY_MAX_BACKOFF_MS = 5 * 6e4;
134
+ const FIBER_RECOVERY_BACKOFF_MAX_EXP = 20;
119
135
  const DEFAULT_AGENT_TOOL_REATTACH_NO_PROGRESS_TIMEOUT_MS = 12e4;
120
136
  const DEFAULT_AGENT_TOOL_REATTACH_MAX_WINDOW_MS = Number.POSITIVE_INFINITY;
121
137
  const SUB_AGENT_IDENTITY_VERSION_LEGACY = "legacy";
@@ -319,36 +335,6 @@ function resolveRetryConfig(taskRetry, defaults) {
319
335
  maxDelayMs: taskRetry?.maxDelayMs ?? defaults.maxDelayMs
320
336
  };
321
337
  }
322
- /**
323
- * Whether an error is a transient "superseded isolate" failure — the invocation
324
- * is running on an isolate the platform has replaced with a new version (a
325
- * deploy / code update). For the rest of that invocation every operation throws
326
- * the same error (code never reloads mid-invocation), so in-process retries are
327
- * futile; but the next fresh invocation runs the new code and succeeds.
328
- *
329
- * workerd surfaces this as a plain `Error` with one of a few messages, all the
330
- * same failure class — a message match is the only signal:
331
- * - "Durable Object reset because its code was updated." (DO storage op on a
332
- * superseded isolate / deploy bounce)
333
- * - "This script has been upgraded. Please send a new request to connect to
334
- * the new version." (a stub/connection to a superseded script; the message
335
- * literally instructs the caller to retry on the new version)
336
- *
337
- * The match stays close to the verbatim platform strings (rather than a loose
338
- * "upgraded"/"reset" substring) so an ordinary application error that happens
339
- * to mention those words is NOT misclassified as a supersede — a false positive
340
- * would defer + re-run a genuinely-failing callback on the platform's alarm
341
- * retries instead of abandoning it.
342
- *
343
- * NOTE: "Network connection lost." is deliberately NOT included — it is a
344
- * connection error, not an isolate replacement, and may succeed on in-process
345
- * retry (it is gated by the CF `retryable` property via `isErrorRetryable`),
346
- * so it stays on the normal retry path rather than the immediate-defer path.
347
- */
348
- function isDurableObjectCodeUpdateReset(error) {
349
- const message = error instanceof Error ? error.message : typeof error === "string" ? error : "";
350
- return /reset because its code was updated|this script has been upgraded/i.test(message);
351
- }
352
338
  function getCurrentAgent() {
353
339
  const store = __DO_NOT_USE_WILL_BREAK__agentContext.getStore();
354
340
  if (!store) return {
@@ -720,6 +706,7 @@ var Agent = class Agent extends Server {
720
706
  this._managedFiberExecutions = /* @__PURE__ */ new Map();
721
707
  this._managedFiberTerminalWaiters = /* @__PURE__ */ new Map();
722
708
  this._runFiberRecoveryInProgress = false;
709
+ this._recoveryNoProgressScans = 0;
723
710
  this._ParentClass = Object.getPrototypeOf(this).constructor;
724
711
  this.initialState = DEFAULT_STATE;
725
712
  this.observability = genericObservability;
@@ -840,22 +827,20 @@ var Agent = class Agent extends Server {
840
827
  method,
841
828
  streaming: metadata?.streaming
842
829
  });
843
- const response = {
830
+ sendRpcResponseIfOpen(connection, {
844
831
  done: true,
845
832
  id,
846
833
  result,
847
834
  success: true,
848
835
  type: "rpc"
849
- };
850
- connection.send(JSON.stringify(response));
836
+ });
851
837
  } catch (e) {
852
- const response = {
838
+ sendRpcResponseIfOpen(connection, {
853
839
  error: e instanceof Error ? e.message : "Unknown error occurred",
854
840
  id: parsed.id,
855
841
  success: false,
856
842
  type: "rpc"
857
- };
858
- connection.send(JSON.stringify(response));
843
+ });
859
844
  console.error("RPC error:", e);
860
845
  this._emit("rpc:error", {
861
846
  method: parsed.method,
@@ -1068,6 +1053,9 @@ var Agent = class Agent extends Server {
1068
1053
  */
1069
1054
  _ensureConnectionWrapped(connection) {
1070
1055
  if (this._rawStateAccessors.has(connection)) return;
1056
+ try {
1057
+ if (connection.binaryType !== "arraybuffer") connection.binaryType = "arraybuffer";
1058
+ } catch {}
1071
1059
  const descriptor = Object.getOwnPropertyDescriptor(connection, "state");
1072
1060
  let getRaw;
1073
1061
  let setRaw;
@@ -2324,6 +2312,9 @@ var Agent = class Agent extends Server {
2324
2312
  if (disposed) return;
2325
2313
  disposed = true;
2326
2314
  this._keepAliveRefs = Math.max(0, this._keepAliveRefs - 1);
2315
+ if (this._keepAliveRefs === 0) this.ctx.waitUntil(this._scheduleNextAlarm().catch((e) => {
2316
+ console.error("[Agent] Failed to reschedule alarm after keepAlive dispose:", e);
2317
+ }));
2327
2318
  };
2328
2319
  }
2329
2320
  /**
@@ -2925,6 +2916,7 @@ var Agent = class Agent extends Server {
2925
2916
  const scanStartedAt = Date.now();
2926
2917
  const scanDeadlineMs = this._resolvedOptions.fiberRecoveryScanDeadlineMs;
2927
2918
  const fiberRecoveryMaxAgeMs = this._resolvedOptions.fiberRecoveryMaxAgeMs;
2919
+ let madeProgress = false;
2928
2920
  try {
2929
2921
  const rows = this.sql`SELECT id, name, snapshot, created_at FROM cf_agents_runs`;
2930
2922
  for (const row of rows) {
@@ -2961,6 +2953,7 @@ var Agent = class Agent extends Server {
2961
2953
  if (managedRow) {
2962
2954
  if (this._isTerminalFiberStatus(managedRow.status)) {
2963
2955
  this.sql`DELETE FROM cf_agents_runs WHERE id = ${row.id}`;
2956
+ madeProgress = true;
2964
2957
  this._notifyManagedFiberTerminal(row.id);
2965
2958
  continue;
2966
2959
  }
@@ -2987,6 +2980,7 @@ var Agent = class Agent extends Server {
2987
2980
  elapsedMs: Date.now() - row.created_at
2988
2981
  });
2989
2982
  this.sql`DELETE FROM cf_agents_runs WHERE id = ${row.id}`;
2983
+ madeProgress = true;
2990
2984
  }
2991
2985
  if (managedRow) this._notifyManagedFiberTerminal(row.id);
2992
2986
  }
@@ -3042,10 +3036,13 @@ var Agent = class Agent extends Server {
3042
3036
  elapsedMs: Date.now() - row.created_at
3043
3037
  });
3044
3038
  await this._runFiberRecoveryHook(ctx, row);
3039
+ madeProgress = true;
3045
3040
  this._notifyManagedFiberTerminal(row.fiber_id);
3046
3041
  }
3047
3042
  } finally {
3048
3043
  this._runFiberRecoveryInProgress = false;
3044
+ if (madeProgress) this._recoveryNoProgressScans = 0;
3045
+ else this._recoveryNoProgressScans = this._hasPendingFiberRecovery() ? this._recoveryNoProgressScans + 1 : 0;
3049
3046
  }
3050
3047
  }
3051
3048
  /** @internal */
@@ -3201,6 +3198,7 @@ var Agent = class Agent extends Server {
3201
3198
  }
3202
3199
  const isOneShotSchedule = row.type === "delayed" || row.type === "scheduled";
3203
3200
  const shouldDeferReset = (error) => isOneShotSchedule && isDurableObjectCodeUpdateReset(error);
3201
+ const shouldDeferOnExhaustion = (error) => isOneShotSchedule && isPlatformTransientError(error);
3204
3202
  try {
3205
3203
  this._emit("schedule:execute", {
3206
3204
  callback: row.callback,
@@ -3224,6 +3222,10 @@ var Agent = class Agent extends Server {
3224
3222
  console.warn(`Deferring scheduled callback "${row.callback}" to a fresh invocation after a Durable Object code-update reset; the one-shot row is preserved and the alarm will re-run on new code.`);
3225
3223
  throw e;
3226
3224
  }
3225
+ if (shouldDeferOnExhaustion(e)) {
3226
+ console.warn(`Deferring scheduled callback "${row.callback}" after exhausting in-process retries on a transient platform error; the one-shot row is preserved and the alarm will re-run once the platform recovers.`);
3227
+ throw e;
3228
+ }
3227
3229
  console.error(`error executing callback "${row.callback}" after ${maxAttempts} attempts`, e);
3228
3230
  this._emit("schedule:error", {
3229
3231
  callback: row.callback,
@@ -3237,7 +3239,35 @@ var Agent = class Agent extends Server {
3237
3239
  }
3238
3240
  });
3239
3241
  }
3242
+ /**
3243
+ * Whether any runFiber recovery work is still outstanding: orphaned
3244
+ * `cf_agents_runs` rows left by a dead process (excluding fibers currently
3245
+ * executing in memory, which already hold a keepAlive ref) or managed
3246
+ * ledger fibers stuck in a non-terminal state with no live run row.
3247
+ *
3248
+ * Used by `_scheduleNextAlarm` to arm a follow-up alarm so multi-pass
3249
+ * recovery (e.g. after a scan-deadline yield, or while retrying a throwing
3250
+ * recovery hook) resumes instead of starving.
3251
+ * @internal
3252
+ */
3253
+ _hasPendingFiberRecovery() {
3254
+ const runRows = this.sql`
3255
+ SELECT id FROM cf_agents_runs
3256
+ `;
3257
+ for (const row of runRows) if (!this._runFiberActiveFibers.has(row.id)) return true;
3258
+ return (this.sql`
3259
+ SELECT COUNT(*) AS count
3260
+ FROM cf_agents_fibers f
3261
+ LEFT JOIN cf_agents_runs r ON r.id = f.fiber_id
3262
+ WHERE f.status IN ('pending', 'running')
3263
+ AND r.id IS NULL
3264
+ `[0]?.count ?? 0) > 0;
3265
+ }
3240
3266
  async _scheduleNextAlarm() {
3267
+ if (await this._hasPendingDestroy()) {
3268
+ await this.ctx.storage.setAlarm(Date.now());
3269
+ return;
3270
+ }
3241
3271
  const nowMs = Date.now();
3242
3272
  const hungCutoffSeconds = Math.floor(nowMs / 1e3) - this._resolvedOptions.hungScheduleTimeoutSeconds;
3243
3273
  const readySchedules = this.sql`
@@ -3266,6 +3296,12 @@ var Agent = class Agent extends Server {
3266
3296
  const keepAliveMs = nowMs + this._resolvedOptions.keepAliveIntervalMs;
3267
3297
  nextTimeMs = nextTimeMs === null ? keepAliveMs : Math.min(nextTimeMs, keepAliveMs);
3268
3298
  }
3299
+ if (this._hasPendingFiberRecovery()) {
3300
+ const base = this._resolvedOptions.keepAliveIntervalMs;
3301
+ const exp = Math.min(this._recoveryNoProgressScans, FIBER_RECOVERY_BACKOFF_MAX_EXP);
3302
+ const recoveryMs = nowMs + Math.min(FIBER_RECOVERY_MAX_BACKOFF_MS, base * 2 ** exp);
3303
+ nextTimeMs = nextTimeMs === null ? recoveryMs : Math.min(nextTimeMs, recoveryMs);
3304
+ }
3269
3305
  if ((this.sql`
3270
3306
  SELECT COUNT(*) as count FROM cf_agents_facet_runs
3271
3307
  `[0]?.count ?? 0) > 0) {
@@ -3297,6 +3333,10 @@ var Agent = class Agent extends Server {
3297
3333
  * See {@link https://developers.cloudflare.com/agents/api-reference/schedule-tasks/}
3298
3334
  */
3299
3335
  async alarm() {
3336
+ if (await this._hasPendingDestroy()) {
3337
+ await this.destroy();
3338
+ return;
3339
+ }
3300
3340
  await super.alarm();
3301
3341
  const now = Math.floor(Date.now() / 1e3);
3302
3342
  const result = this.sql`
@@ -5167,6 +5207,7 @@ var Agent = class Agent extends Server {
5167
5207
  await (await this._rootAlarmOwner())._cf_destroyDescendantFacet(this.selfPath);
5168
5208
  return;
5169
5209
  }
5210
+ await this.ctx.storage.put(DESTROY_PENDING_KEY, true);
5170
5211
  this._dropInternalTablesForDestroy();
5171
5212
  await this.ctx.storage.deleteAlarm();
5172
5213
  await this.ctx.storage.deleteAll();
@@ -5178,6 +5219,42 @@ var Agent = class Agent extends Server {
5178
5219
  }, 0);
5179
5220
  this._emit("destroy");
5180
5221
  }
5222
+ /**
5223
+ * @internal Defer this agent's destruction to its own alarm invocation
5224
+ * instead of running it inline (#1625).
5225
+ *
5226
+ * `destroy()` is a multi-step I/O sequence (drop tables, delete alarm,
5227
+ * delete all storage, dispose connections). Running it on the `waitUntil`
5228
+ * of a request whose client has already disconnected — the MCP
5229
+ * Streamable-HTTP session-DELETE path — gives it little to no
5230
+ * post-invocation grace, so the runtime routinely cancels it mid-flight.
5231
+ * This method instead performs two fast storage writes (a durable
5232
+ * "condemned" marker and an immediate alarm) that the caller can await
5233
+ * before responding; the alarm then fires as a fresh invocation with its
5234
+ * own full execution budget and runs `destroy()` there. If even that
5235
+ * invocation is interrupted, the marker survives and the next wake
5236
+ * finishes teardown — see the `alarm()` preamble.
5237
+ *
5238
+ * Unlike `destroy()`, this method does not abort the isolate, so RPC
5239
+ * callers don't need to swallow an abort error.
5240
+ */
5241
+ async _cf_scheduleDestroy() {
5242
+ await this.__unsafe_ensureInitialized();
5243
+ if (this._isFacet) {
5244
+ await this.destroy();
5245
+ return;
5246
+ }
5247
+ await this.ctx.storage.put(DESTROY_PENDING_KEY, true);
5248
+ await this.ctx.storage.setAlarm(Date.now() + DESTROY_ALARM_DELAY_MS);
5249
+ }
5250
+ /**
5251
+ * Whether a (deferred or interrupted) destroy is pending. Reads the
5252
+ * durable marker directly — the in-memory `_isFacet` flag may not be
5253
+ * hydrated yet at the call sites, but facets never write the marker.
5254
+ */
5255
+ async _hasPendingDestroy() {
5256
+ return await this.ctx.storage.get(DESTROY_PENDING_KEY) === true;
5257
+ }
5181
5258
  /** @internal Drop every internal Agents SDK table during top-level destroy. */
5182
5259
  _dropInternalTablesForDestroy() {
5183
5260
  this.sql`DROP TABLE IF EXISTS cf_agents_mcp_servers`;
@@ -6334,8 +6411,7 @@ var StreamingResponse = class {
6334
6411
  success: true,
6335
6412
  type: "rpc"
6336
6413
  };
6337
- this._connection.send(JSON.stringify(response));
6338
- return true;
6414
+ return sendRpcResponseIfOpen(this._connection, response);
6339
6415
  }
6340
6416
  /**
6341
6417
  * End the stream and send the final chunk (if any)
@@ -6352,8 +6428,7 @@ var StreamingResponse = class {
6352
6428
  success: true,
6353
6429
  type: "rpc"
6354
6430
  };
6355
- this._connection.send(JSON.stringify(response));
6356
- return true;
6431
+ return sendRpcResponseIfOpen(this._connection, response);
6357
6432
  }
6358
6433
  /**
6359
6434
  * Send an error to the client and close the stream
@@ -6369,11 +6444,10 @@ var StreamingResponse = class {
6369
6444
  success: false,
6370
6445
  type: "rpc"
6371
6446
  };
6372
- this._connection.send(JSON.stringify(response));
6373
- return true;
6447
+ return sendRpcResponseIfOpen(this._connection, response);
6374
6448
  }
6375
6449
  };
6376
6450
  //#endregion
6377
- export { Agent, DEFAULT_AGENT_STATIC_OPTIONS, DurableObjectOAuthClientProvider, MCP_SERVER_ID_MAX_LENGTH, MessageType, SUB_PREFIX, SqlError, StreamingResponse, __DO_NOT_USE_WILL_BREAK__agentContext, callable, camelCaseToKebabCase, createHeaderBasedEmailResolver, getAgentByName, getCurrentAgent, getSubAgentByName, normalizeServerId, parseSubAgentPath, routeAgentEmail, routeAgentRequest, routeSubAgentRequest, unstable_callable };
6451
+ export { Agent, DEFAULT_AGENT_STATIC_OPTIONS, DurableObjectOAuthClientProvider, MCP_SERVER_ID_MAX_LENGTH, MessageType, SUB_PREFIX, SqlError, StreamingResponse, __DO_NOT_USE_WILL_BREAK__agentContext, callable, camelCaseToKebabCase, createHeaderBasedEmailResolver, getAgentByName, getCurrentAgent, getSubAgentByName, isDurableObjectCodeUpdateReset, isPlatformTransientError, normalizeServerId, parseSubAgentPath, routeAgentEmail, routeAgentRequest, routeSubAgentRequest, unstable_callable };
6378
6452
 
6379
6453
  //# sourceMappingURL=index.js.map