agents 0.19.0 → 0.20.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 (57) hide show
  1. package/README.md +24 -19
  2. package/dist/{agent-tool-types-BNUGGBzQ.d.ts → agent-tool-types-BC-WFlsz.d.ts} +1026 -400
  3. package/dist/agent-tool-types.d.ts +1 -1
  4. package/dist/{agent-tools-BFbzVLFc.d.ts → agent-tools-DeHe9Xov.d.ts} +2 -2
  5. package/dist/agent-tools.d.ts +1 -1
  6. package/dist/browser/ai.js +1 -1
  7. package/dist/browser/index.js +1 -1
  8. package/dist/chat/index.d.ts +2 -2
  9. package/dist/chat-sdk/index.d.ts +1 -1
  10. package/dist/client-invoker-BNSZxAkv.d.ts +20 -0
  11. package/dist/client-invoker-VNZ7X0nn.js +57 -0
  12. package/dist/client-invoker-VNZ7X0nn.js.map +1 -0
  13. package/dist/{client-CcjiFpTf.js → client-zqKcsyFa.js} +434 -168
  14. package/dist/client-zqKcsyFa.js.map +1 -0
  15. package/dist/client.d.ts +1 -1
  16. package/dist/cloudflare-BduZwmYK.js +204 -0
  17. package/dist/cloudflare-BduZwmYK.js.map +1 -0
  18. package/dist/{connector-CdldGF3h.js → connector-KEJnl6e5.js} +2 -2
  19. package/dist/connector-KEJnl6e5.js.map +1 -0
  20. package/dist/{do-oauth-client-provider-D4ZwyBDu.d.ts → do-oauth-client-provider-VTZj2VtM.d.ts} +23 -11
  21. package/dist/experimental/webmcp.js +1 -1
  22. package/dist/handler-stateless-CIkKPETH.js +318 -0
  23. package/dist/handler-stateless-CIkKPETH.js.map +1 -0
  24. package/dist/handler-stateless-C_bo-Ytq.d.ts +107 -0
  25. package/dist/index.d.ts +14 -12
  26. package/dist/index.js +30 -20
  27. package/dist/index.js.map +1 -1
  28. package/dist/mcp/client.d.ts +22 -18
  29. package/dist/mcp/client.js +1 -1
  30. package/dist/mcp/do-oauth-client-provider.d.ts +1 -1
  31. package/dist/mcp/do-oauth-client-provider.js +25 -12
  32. package/dist/mcp/do-oauth-client-provider.js.map +1 -1
  33. package/dist/mcp/index.d.ts +48 -34
  34. package/dist/mcp/index.js +95 -156
  35. package/dist/mcp/index.js.map +1 -1
  36. package/dist/mcp/server.d.ts +17 -0
  37. package/dist/mcp/server.js +2 -0
  38. package/dist/mcp/x402.d.ts +21 -9
  39. package/dist/mcp/x402.js +8 -7
  40. package/dist/mcp/x402.js.map +1 -1
  41. package/dist/observability/ai/index.d.ts +9 -1
  42. package/dist/observability/ai/index.js +188 -63
  43. package/dist/observability/ai/index.js.map +1 -1
  44. package/dist/react.d.ts +1 -1
  45. package/dist/serializable.d.ts +1 -1
  46. package/dist/sub-routing.d.ts +6 -6
  47. package/dist/workflows.d.ts +1 -1
  48. package/docs/human-in-the-loop.md +63 -82
  49. package/docs/mcp-client.md +31 -7
  50. package/docs/mcp-servers.md +125 -88
  51. package/docs/observability.md +2 -1
  52. package/docs/securing-mcp-servers.md +9 -6
  53. package/package.json +28 -7
  54. package/dist/client-CcjiFpTf.js.map +0 -1
  55. package/dist/cloudflare-BldFV0Pa.js +0 -117
  56. package/dist/cloudflare-BldFV0Pa.js.map +0 -1
  57. package/dist/connector-CdldGF3h.js.map +0 -1
package/dist/index.js CHANGED
@@ -4,12 +4,12 @@ import { MessageType } from "./types.js";
4
4
  import { camelCaseToKebabCase, isInternalJsStubProp } from "./utils.js";
5
5
  import { createHeaderBasedEmailResolver, signAgentHeaders } from "./email.js";
6
6
  import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldSet2, t as _classPrivateFieldGet2 } from "./classPrivateFieldGet2-DZBYAB34.js";
7
+ import { n as withInvocationScope, r as writeSpanAttributes, t as tracer } from "./cloudflare-BduZwmYK.js";
7
8
  import { SUB_PREFIX, getSubAgentByName, parseSubAgentPath, routeSubAgentRequest } from "./sub-routing.js";
8
9
  import { isDurableObjectCodeUpdateReset, isDurableObjectMemoryLimitReset, isDurableObjectStorageReset, isErrorRetryable, isPlatformTransientError, tryN, validateRetryOptions } from "./retries.js";
9
- 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-CcjiFpTf.js";
10
+ 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-zqKcsyFa.js";
10
11
  import { DurableObjectOAuthClientProvider } from "./mcp/do-oauth-client-provider.js";
11
12
  import { genericObservability } from "./observability/index.js";
12
- import { n as writeSpanAttributes, t as tracer } from "./cloudflare-BldFV0Pa.js";
13
13
  import { AsyncLocalStorage } from "node:async_hooks";
14
14
  import { parseCronExpression } from "cron-schedule";
15
15
  import { nanoid } from "nanoid";
@@ -18,6 +18,15 @@ import { RpcTarget, exports } from "cloudflare:workers";
18
18
  import { Server, getServerByName, routePartykitRequest } from "partyserver";
19
19
  //#region src/index.ts
20
20
  let _Symbol$dispose;
21
+ /**
22
+ * Enters an agent invocation: the context every handler reads, plus the span
23
+ * scope that stops invocation-bounded spans from outliving it. Scopes do not
24
+ * nest, so the outermost live entry point owns the boundary — pass
25
+ * `detached` for work that deliberately runs on past its caller.
26
+ */
27
+ function runInInvocation(store, body, options) {
28
+ return __DO_NOT_USE_WILL_BREAK__agentContext.run(store, () => withInvocationScope(body, options));
29
+ }
21
30
  function isClosedWebSocketSendError(error) {
22
31
  return error instanceof TypeError && error.message.includes("WebSocket send() after close");
23
32
  }
@@ -380,7 +389,7 @@ function withAgentContext(method) {
380
389
  return function(...args) {
381
390
  const { agent } = getCurrentAgent();
382
391
  if (agent === this) return method.apply(this, args);
383
- return __DO_NOT_USE_WILL_BREAK__agentContext.run({
392
+ return runInInvocation({
384
393
  agent: this,
385
394
  connection: void 0,
386
395
  request: void 0,
@@ -497,7 +506,7 @@ var Agent = class Agent extends Server {
497
506
  "cloudflare.agents.storage.system": "durable_object",
498
507
  "cloudflare.agents.storage.phase": storagePhase,
499
508
  ...attributes
500
- }, (span) => run((finishAttributes) => writeSpanAttributes(span, finishAttributes)));
509
+ }, (span) => run((finishAttributes) => writeSpanAttributes(span, finishAttributes)), __DO_NOT_USE_WILL_BREAK__agentContext.getStore()?.connection === void 0 ? void 0 : { boundToInvocation: true });
501
510
  }
502
511
  /**
503
512
  * Execute SQL queries against the Agent's database
@@ -824,7 +833,7 @@ var Agent = class Agent extends Server {
824
833
  }
825
834
  const _onRequest = this.onRequest.bind(this);
826
835
  this.onRequest = (request) => {
827
- return __DO_NOT_USE_WILL_BREAK__agentContext.run({
836
+ return runInInvocation({
828
837
  agent: this,
829
838
  connection: void 0,
830
839
  request,
@@ -839,7 +848,7 @@ var Agent = class Agent extends Server {
839
848
  this.onMessage = async (connection, message) => {
840
849
  if (await this._cf_forwardSubAgentWebSocketMessage(connection, message)) return;
841
850
  this._ensureConnectionWrapped(connection);
842
- return __DO_NOT_USE_WILL_BREAK__agentContext.run({
851
+ return runInInvocation({
843
852
  agent: this,
844
853
  connection,
845
854
  request: void 0,
@@ -932,7 +941,7 @@ var Agent = class Agent extends Server {
932
941
  const subAgentOuterUrl = ctx.request.headers.get(SUB_AGENT_OUTER_URL_HEADER);
933
942
  if (subAgentOuterUrl) this._unsafe_setConnectionFlag(connection, CF_SUB_AGENT_OUTER_URL_KEY, subAgentOuterUrl);
934
943
  if (await this._cf_forwardSubAgentWebSocketConnect(connection, ctx.request, { gate: false })) return;
935
- return __DO_NOT_USE_WILL_BREAK__agentContext.run({
944
+ return runInInvocation({
936
945
  agent: this,
937
946
  connection,
938
947
  request: ctx.request,
@@ -979,7 +988,7 @@ var Agent = class Agent extends Server {
979
988
  const _onClose = this.onClose.bind(this);
980
989
  this.onClose = async (connection, code, reason, wasClean) => {
981
990
  if (await this._cf_forwardSubAgentWebSocketClose(connection, code, reason, wasClean)) return;
982
- return __DO_NOT_USE_WILL_BREAK__agentContext.run({
991
+ return runInInvocation({
983
992
  agent: this,
984
993
  connection,
985
994
  request: void 0,
@@ -995,7 +1004,7 @@ var Agent = class Agent extends Server {
995
1004
  };
996
1005
  const _onStart = this.onStart.bind(this);
997
1006
  const startAgent = async (props, update) => {
998
- return __DO_NOT_USE_WILL_BREAK__agentContext.run({
1007
+ return runInInvocation({
999
1008
  agent: this,
1000
1009
  connection: void 0,
1001
1010
  request: void 0,
@@ -1098,7 +1107,7 @@ var Agent = class Agent extends Server {
1098
1107
  const { connection, request, email } = __DO_NOT_USE_WILL_BREAK__agentContext.getStore() || {};
1099
1108
  this.ctx.waitUntil((async () => {
1100
1109
  try {
1101
- await __DO_NOT_USE_WILL_BREAK__agentContext.run({
1110
+ await runInInvocation({
1102
1111
  agent: this,
1103
1112
  connection,
1104
1113
  request,
@@ -1106,7 +1115,7 @@ var Agent = class Agent extends Server {
1106
1115
  }, async () => {
1107
1116
  this._emit("state:update");
1108
1117
  await this._callStatePersistenceHook(nextState, source);
1109
- });
1118
+ }, { detached: true });
1110
1119
  } catch (e) {
1111
1120
  try {
1112
1121
  await this.onError(e);
@@ -1371,7 +1380,7 @@ var Agent = class Agent extends Server {
1371
1380
  forward: (rcptTo, headers) => payload._bridge.forward(rcptTo, headers),
1372
1381
  reply: (options) => payload._bridge.reply(options)
1373
1382
  };
1374
- return __DO_NOT_USE_WILL_BREAK__agentContext.run({
1383
+ return runInInvocation({
1375
1384
  agent: this,
1376
1385
  connection: void 0,
1377
1386
  request: void 0,
@@ -1620,7 +1629,7 @@ var Agent = class Agent extends Server {
1620
1629
  continue;
1621
1630
  }
1622
1631
  const { connection, request, email } = __DO_NOT_USE_WILL_BREAK__agentContext.getStore() || {};
1623
- await __DO_NOT_USE_WILL_BREAK__agentContext.run({
1632
+ await runInInvocation({
1624
1633
  agent: this,
1625
1634
  connection,
1626
1635
  request,
@@ -1655,7 +1664,7 @@ var Agent = class Agent extends Server {
1655
1664
  } finally {
1656
1665
  this.dequeue(row.id);
1657
1666
  }
1658
- });
1667
+ }, { detached: true });
1659
1668
  }
1660
1669
  }
1661
1670
  } finally {
@@ -3295,7 +3304,7 @@ var Agent = class Agent extends Server {
3295
3304
  console.error(`callback ${row.callback} not found`);
3296
3305
  return;
3297
3306
  }
3298
- await __DO_NOT_USE_WILL_BREAK__agentContext.run({
3307
+ await runInInvocation({
3299
3308
  agent: this,
3300
3309
  connection: void 0,
3301
3310
  request: void 0,
@@ -4766,12 +4775,12 @@ var Agent = class Agent extends Server {
4766
4775
  await invoke();
4767
4776
  return;
4768
4777
  }
4769
- await __DO_NOT_USE_WILL_BREAK__agentContext.run({
4778
+ await runInInvocation({
4770
4779
  agent: this,
4771
4780
  connection: void 0,
4772
4781
  request: void 0,
4773
4782
  email: void 0
4774
- }, invoke);
4783
+ }, invoke, { detached: true });
4775
4784
  }
4776
4785
  /**
4777
4786
  * Arm the self-scheduling detached reconcile backbone. Existing schedules are
@@ -5727,7 +5736,7 @@ var Agent = class Agent extends Server {
5727
5736
  }));
5728
5737
  this._recordSubAgent(className, name, identity);
5729
5738
  try {
5730
- await __DO_NOT_USE_WILL_BREAK__agentContext.run({
5739
+ await runInInvocation({
5731
5740
  agent: this,
5732
5741
  connection: void 0,
5733
5742
  request: void 0,
@@ -6895,7 +6904,8 @@ var Agent = class Agent extends Server {
6895
6904
  transport: {
6896
6905
  ...headerTransportOpts,
6897
6906
  authProvider,
6898
- type: transportType
6907
+ type: transportType,
6908
+ skipIssuerMetadataValidation: resolvedOptions?.transport?.skipIssuerMetadataValidation
6899
6909
  },
6900
6910
  retry: resolvedOptions?.retry
6901
6911
  });
@@ -7222,6 +7232,6 @@ var StreamingResponse = class {
7222
7232
  }
7223
7233
  };
7224
7234
  //#endregion
7225
- export { AGENT_TOOL_MILESTONE_PART, AGENT_TOOL_PROGRESS_PART, 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, isDurableObjectMemoryLimitReset, isDurableObjectStorageReset, isPlatformTransientError, normalizeServerId, parseSubAgentPath, routeAgentEmail, routeAgentRequest, routeSubAgentRequest, unstable_callable };
7235
+ export { AGENT_TOOL_MILESTONE_PART, AGENT_TOOL_PROGRESS_PART, Agent, DEFAULT_AGENT_STATIC_OPTIONS, DurableObjectOAuthClientProvider, MCP_SERVER_ID_MAX_LENGTH, MessageType, SUB_PREFIX, SqlError, StreamingResponse, __DO_NOT_USE_WILL_BREAK__agentContext, withInvocationScope as __DO_NOT_USE_WILL_BREAK__withInvocationScope, callable, camelCaseToKebabCase, createHeaderBasedEmailResolver, getAgentByName, getCurrentAgent, getSubAgentByName, isDurableObjectCodeUpdateReset, isDurableObjectMemoryLimitReset, isDurableObjectStorageReset, isPlatformTransientError, normalizeServerId, parseSubAgentPath, routeAgentEmail, routeAgentRequest, routeSubAgentRequest, unstable_callable };
7226
7236
 
7227
7237
  //# sourceMappingURL=index.js.map