agents 0.0.0-19a3a25 → 0.0.0-1a3d226

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 (71) hide show
  1. package/README.md +126 -3
  2. package/dist/ai-chat-agent.d.ts +229 -22
  3. package/dist/ai-chat-agent.js +692 -106
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/ai-chat-v5-migration.js +154 -2
  6. package/dist/ai-chat-v5-migration.js.map +1 -0
  7. package/dist/ai-react.d.ts +141 -16
  8. package/dist/ai-react.js +381 -68
  9. package/dist/ai-react.js.map +1 -1
  10. package/dist/{ai-types-D5YoPrBZ.d.ts → ai-types-0OnT3FHg.d.ts} +40 -8
  11. package/dist/{ai-types-B3aQaFv3.js → ai-types-DEtF_8Km.js} +9 -1
  12. package/dist/ai-types-DEtF_8Km.js.map +1 -0
  13. package/dist/ai-types.d.ts +1 -1
  14. package/dist/ai-types.js +1 -1
  15. package/dist/cli/index.d.ts +1 -0
  16. package/dist/{cli.js → cli/index.js} +7 -6
  17. package/dist/cli/index.js.map +1 -0
  18. package/dist/client-BINtT7y-.d.ts +834 -0
  19. package/dist/{client-CbWe9FBd.d.ts → client-CdM5I962.d.ts} +2 -2
  20. package/dist/{client-BfiZ3HQd.js → client-DjTPRM8-.js} +2 -2
  21. package/dist/{client-BfiZ3HQd.js.map → client-DjTPRM8-.js.map} +1 -1
  22. package/dist/client-QZa2Rq0l.js +1105 -0
  23. package/dist/client-QZa2Rq0l.js.map +1 -0
  24. package/dist/client.d.ts +1 -2
  25. package/dist/client.js +1 -2
  26. package/dist/codemode/ai.js +6 -6
  27. package/dist/codemode/ai.js.map +1 -1
  28. package/dist/context-BkKbAa1R.js +8 -0
  29. package/dist/context-BkKbAa1R.js.map +1 -0
  30. package/dist/context-DcbQ8o7k.d.ts +24 -0
  31. package/dist/context.d.ts +6 -0
  32. package/dist/context.js +3 -0
  33. package/dist/{do-oauth-client-provider-DGc5pP0l.d.ts → do-oauth-client-provider--To1Tsjj.d.ts} +20 -5
  34. package/dist/{do-oauth-client-provider-CswoD5Lu.js → do-oauth-client-provider-B1fVIshX.js} +70 -8
  35. package/dist/do-oauth-client-provider-B1fVIshX.js.map +1 -0
  36. package/dist/{index-CuqiHyhT.d.ts → index-CfZ2mfMI.d.ts} +80 -64
  37. package/dist/{index-DhJCaDWd.d.ts → index-DLuxm_9W.d.ts} +2 -2
  38. package/dist/index.d.ts +31 -34
  39. package/dist/index.js +5 -5
  40. package/dist/mcp/client.d.ts +2 -4
  41. package/dist/mcp/client.js +2 -1
  42. package/dist/mcp/do-oauth-client-provider.d.ts +1 -1
  43. package/dist/mcp/do-oauth-client-provider.js +1 -1
  44. package/dist/mcp/index.d.ts +23 -16
  45. package/dist/mcp/index.js +71 -69
  46. package/dist/mcp/index.js.map +1 -1
  47. package/dist/mcp/x402.js +10 -6
  48. package/dist/mcp/x402.js.map +1 -1
  49. package/dist/{mcp-Dw5vDrY8.d.ts → mcp-CPSfGUgd.d.ts} +1 -1
  50. package/dist/observability/index.d.ts +1 -2
  51. package/dist/observability/index.js +5 -5
  52. package/dist/react.d.ts +134 -10
  53. package/dist/react.js +57 -57
  54. package/dist/react.js.map +1 -1
  55. package/dist/schedule.d.ts +18 -72
  56. package/dist/{serializable-CymX8ovI.d.ts → serializable-Crsj26mx.d.ts} +1 -1
  57. package/dist/serializable.d.ts +1 -1
  58. package/dist/{src-CwIW7tU2.js → src-BZDh910Z.js} +104 -139
  59. package/dist/src-BZDh910Z.js.map +1 -0
  60. package/package.json +31 -16
  61. package/dist/ai-chat-v5-migration-DBHGW4Hv.js +0 -155
  62. package/dist/ai-chat-v5-migration-DBHGW4Hv.js.map +0 -1
  63. package/dist/ai-types-B3aQaFv3.js.map +0 -1
  64. package/dist/cli.d.ts +0 -8
  65. package/dist/cli.js.map +0 -1
  66. package/dist/client-BnO9jNtu.d.ts +0 -5283
  67. package/dist/client-DZhjV_XA.js +0 -719
  68. package/dist/client-DZhjV_XA.js.map +0 -1
  69. package/dist/do-oauth-client-provider-CswoD5Lu.js.map +0 -1
  70. package/dist/react-Cx9uE2Jd.d.ts +0 -113
  71. package/dist/src-CwIW7tU2.js.map +0 -1
package/dist/mcp/index.js CHANGED
@@ -1,12 +1,13 @@
1
- import { t as MessageType } from "../ai-types-B3aQaFv3.js";
2
- import "../client-BfiZ3HQd.js";
3
- import "../client-DZhjV_XA.js";
4
- import "../do-oauth-client-provider-CswoD5Lu.js";
5
- import { c as getCurrentAgent, s as getAgentByName, t as Agent } from "../src-CwIW7tU2.js";
1
+ import "../context-BkKbAa1R.js";
2
+ import { t as MessageType } from "../ai-types-DEtF_8Km.js";
3
+ import "../client-DjTPRM8-.js";
4
+ import "../client-QZa2Rq0l.js";
5
+ import "../do-oauth-client-provider-B1fVIshX.js";
6
+ import { c as getCurrentAgent, s as getAgentByName, t as Agent } from "../src-BZDh910Z.js";
6
7
  import { AsyncLocalStorage } from "node:async_hooks";
7
8
  import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
8
9
  import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
9
- import { ElicitRequestSchema, InitializeRequestSchema, JSONRPCMessageSchema, isInitializeRequest, isJSONRPCError, isJSONRPCNotification, isJSONRPCRequest, isJSONRPCResponse } from "@modelcontextprotocol/sdk/types.js";
10
+ import { ElicitRequestSchema, InitializeRequestSchema, JSONRPCMessageSchema, SUPPORTED_PROTOCOL_VERSIONS, isInitializeRequest, isJSONRPCError, isJSONRPCNotification, isJSONRPCRequest, isJSONRPCResponse } from "@modelcontextprotocol/sdk/types.js";
10
11
 
11
12
  //#region src/mcp/utils.ts
12
13
  /**
@@ -434,7 +435,8 @@ const createLegacySseHandler = (basePath, namespace, options = {}) => {
434
435
  jurisdiction: options.jurisdiction
435
436
  });
436
437
  const messageBody = await request.json();
437
- const error = await agent.onSSEMcpMessage(sessionId, messageBody);
438
+ const extraInfo = { requestInfo: { headers: Object.fromEntries(request.headers.entries()) } };
439
+ const error = await agent.onSSEMcpMessage(sessionId, messageBody, extraInfo);
438
440
  if (error) return new Response(error.message, {
439
441
  headers: {
440
442
  "Cache-Control": "no-cache",
@@ -478,9 +480,12 @@ function isDurableObjectNamespace(namespace) {
478
480
  //#endregion
479
481
  //#region src/mcp/transport.ts
480
482
  var McpSSETransport = class {
481
- constructor(getWebSocket) {
483
+ constructor() {
482
484
  this._started = false;
483
- this._getWebSocket = getWebSocket;
485
+ const { agent } = getCurrentAgent();
486
+ if (!agent) throw new Error("McpAgent was not found in Transport constructor");
487
+ this.sessionId = agent.getSessionId();
488
+ this._getWebSocket = () => agent.getWebSocket();
484
489
  }
485
490
  async start() {
486
491
  if (this._started) throw new Error("Transport already started");
@@ -588,19 +593,35 @@ var StreamableHTTPServerTransport = class {
588
593
  if (Array.isArray(rawMessage)) messages = rawMessage.map((msg) => JSONRPCMessageSchema.parse(msg));
589
594
  else messages = [JSONRPCMessageSchema.parse(rawMessage)];
590
595
  const hasRequests = messages.some(isJSONRPCRequest);
591
- if (!hasRequests) for (const message of messages) this.onmessage?.(message, {
592
- authInfo,
593
- requestInfo
594
- });
596
+ if (!hasRequests) for (const message of messages) {
597
+ if (this.messageInterceptor) {
598
+ if (await this.messageInterceptor(message, {
599
+ authInfo,
600
+ requestInfo
601
+ })) continue;
602
+ }
603
+ this.onmessage?.(message, {
604
+ authInfo,
605
+ requestInfo
606
+ });
607
+ }
595
608
  else if (hasRequests) {
596
609
  const { connection } = getCurrentAgent();
597
610
  if (!connection) throw new Error("Connection was not found in handlePostRequest");
598
611
  const requestIds = messages.filter(isJSONRPCRequest).map((message) => message.id);
599
612
  connection.setState({ requestIds });
600
- for (const message of messages) this.onmessage?.(message, {
601
- authInfo,
602
- requestInfo
603
- });
613
+ for (const message of messages) {
614
+ if (this.messageInterceptor) {
615
+ if (await this.messageInterceptor(message, {
616
+ authInfo,
617
+ requestInfo
618
+ })) continue;
619
+ }
620
+ this.onmessage?.(message, {
621
+ authInfo,
622
+ requestInfo
623
+ });
624
+ }
604
625
  }
605
626
  }
606
627
  async close() {
@@ -641,6 +662,9 @@ var StreamableHTTPServerTransport = class {
641
662
 
642
663
  //#endregion
643
664
  //#region src/mcp/client-transports.ts
665
+ /**
666
+ * Deprecated transport wrappers
667
+ */
644
668
  let didWarnAboutSSEEdgeClientTransport = false;
645
669
  /**
646
670
  * @deprecated Use SSEClientTransport from @modelcontextprotocol/sdk/client/sse.js instead. This alias will be removed in the next major version.
@@ -670,8 +694,6 @@ var StreamableHTTPEdgeClientTransport = class extends StreamableHTTPClientTransp
670
694
 
671
695
  //#endregion
672
696
  //#region src/mcp/worker-transport.ts
673
- const SUPPORTED_PROTOCOL_VERSIONS = ["2025-03-26", "2025-06-18"];
674
- const DEFAULT_PROTOCOL_VERSION = "2025-03-26";
675
697
  const MCP_PROTOCOL_VERSION_HEADER = "MCP-Protocol-Version";
676
698
  var WorkerTransport = class {
677
699
  constructor(options) {
@@ -699,7 +721,6 @@ var WorkerTransport = class {
699
721
  if (state) {
700
722
  this.sessionId = state.sessionId;
701
723
  this.initialized = state.initialized;
702
- this.protocolVersion = state.protocolVersion;
703
724
  }
704
725
  this.stateRestored = true;
705
726
  }
@@ -710,8 +731,7 @@ var WorkerTransport = class {
710
731
  if (!this.storage) return;
711
732
  const state = {
712
733
  sessionId: this.sessionId,
713
- initialized: this.initialized,
714
- protocolVersion: this.protocolVersion
734
+ initialized: this.initialized
715
735
  };
716
736
  await Promise.resolve(this.storage.set(state));
717
737
  }
@@ -719,44 +739,26 @@ var WorkerTransport = class {
719
739
  if (this.started) throw new Error("Transport already started");
720
740
  this.started = true;
721
741
  }
742
+ /**
743
+ * Validates the MCP-Protocol-Version header on incoming requests.
744
+ *
745
+ * This performs a simple check: if a version header is present, it must be
746
+ * in the SUPPORTED_PROTOCOL_VERSIONS list. We do not track the negotiated
747
+ * version or enforce version consistency across requests - the SDK handles
748
+ * version negotiation during initialization, and we simply reject any
749
+ * explicitly unsupported versions.
750
+ *
751
+ * - Header present and supported: Accept
752
+ * - Header present and unsupported: 400 Bad Request
753
+ * - Header missing: Accept (version validation is optional)
754
+ */
722
755
  validateProtocolVersion(request) {
723
- const versionHeader = request.headers.get(MCP_PROTOCOL_VERSION_HEADER);
724
- if (!versionHeader) {
725
- if (!this.protocolVersion || this.protocolVersion === DEFAULT_PROTOCOL_VERSION) return;
726
- return new Response(JSON.stringify({
727
- jsonrpc: "2.0",
728
- error: {
729
- code: -32e3,
730
- message: `Bad Request: ${MCP_PROTOCOL_VERSION_HEADER} header is required`
731
- },
732
- id: null
733
- }), {
734
- status: 400,
735
- headers: {
736
- "Content-Type": "application/json",
737
- ...this.getHeaders()
738
- }
739
- });
740
- }
741
- if (!SUPPORTED_PROTOCOL_VERSIONS.includes(versionHeader)) return new Response(JSON.stringify({
742
- jsonrpc: "2.0",
743
- error: {
744
- code: -32e3,
745
- message: `Bad Request: Unsupported ${MCP_PROTOCOL_VERSION_HEADER}: ${versionHeader}. Supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")}`
746
- },
747
- id: null
748
- }), {
749
- status: 400,
750
- headers: {
751
- "Content-Type": "application/json",
752
- ...this.getHeaders()
753
- }
754
- });
755
- if (this.protocolVersion && versionHeader !== this.protocolVersion) return new Response(JSON.stringify({
756
+ const protocolVersion = request.headers.get(MCP_PROTOCOL_VERSION_HEADER);
757
+ if (protocolVersion !== null && !SUPPORTED_PROTOCOL_VERSIONS.includes(protocolVersion)) return new Response(JSON.stringify({
756
758
  jsonrpc: "2.0",
757
759
  error: {
758
760
  code: -32e3,
759
- message: `Bad Request: ${MCP_PROTOCOL_VERSION_HEADER} mismatch. Expected: ${this.protocolVersion}, Got: ${versionHeader}`
761
+ message: `Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`
760
762
  },
761
763
  id: null
762
764
  }), {
@@ -861,7 +863,7 @@ var WorkerTransport = class {
861
863
  }
862
864
  async handlePostRequest(request, parsedBody) {
863
865
  const acceptHeader = request.headers.get("Accept");
864
- if (!acceptHeader?.includes("application/json") || !acceptHeader.includes("text/event-stream")) return new Response(JSON.stringify({
866
+ if (!acceptHeader?.includes("application/json") || !acceptHeader?.includes("text/event-stream")) return new Response(JSON.stringify({
865
867
  jsonrpc: "2.0",
866
868
  error: {
867
869
  code: -32e3,
@@ -959,12 +961,6 @@ var WorkerTransport = class {
959
961
  ...this.getHeaders()
960
962
  }
961
963
  });
962
- const initRequest = messages.find(isInitializeRequest);
963
- if (initRequest?.params) {
964
- const version = initRequest.params.protocolVersion;
965
- if (version && SUPPORTED_PROTOCOL_VERSIONS.includes(version)) this.protocolVersion = version;
966
- else this.protocolVersion = DEFAULT_PROTOCOL_VERSION;
967
- }
968
964
  this.sessionId = this.sessionIdGenerator?.();
969
965
  this.initialized = true;
970
966
  await this.saveState();
@@ -1101,8 +1097,8 @@ var WorkerTransport = class {
1101
1097
  this.requestResponseMap.clear();
1102
1098
  this.onclose?.();
1103
1099
  }
1104
- async send(message) {
1105
- let requestId;
1100
+ async send(message, options) {
1101
+ let requestId = options?.relatedRequestId;
1106
1102
  if (isJSONRPCResponse(message) || isJSONRPCError(message)) requestId = message.id;
1107
1103
  if (requestId === void 0) {
1108
1104
  if (isJSONRPCResponse(message) || isJSONRPCError(message)) throw new Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");
@@ -1250,8 +1246,14 @@ var McpAgent = class McpAgent extends Agent {
1250
1246
  /** Returns a new transport matching the type of the Agent. */
1251
1247
  initTransport() {
1252
1248
  switch (this.getTransportType()) {
1253
- case "sse": return new McpSSETransport(() => this.getWebSocket());
1254
- case "streamable-http": return new StreamableHTTPServerTransport({});
1249
+ case "sse": return new McpSSETransport();
1250
+ case "streamable-http": {
1251
+ const transport = new StreamableHTTPServerTransport({});
1252
+ transport.messageInterceptor = async (message) => {
1253
+ return this._handleElicitationResponse(message);
1254
+ };
1255
+ return transport;
1256
+ }
1255
1257
  }
1256
1258
  }
1257
1259
  /** Update and store the props */
@@ -1303,7 +1305,7 @@ var McpAgent = class McpAgent extends Agent {
1303
1305
  }
1304
1306
  }
1305
1307
  /** Handles MCP Messages for the legacy SSE transport. */
1306
- async onSSEMcpMessage(_sessionId, messageBody) {
1308
+ async onSSEMcpMessage(_sessionId, messageBody, extraInfo) {
1307
1309
  if (this.getTransportType() !== "sse") return /* @__PURE__ */ new Error("Internal Server Error: Expected SSE transport");
1308
1310
  try {
1309
1311
  let parsedMessage;
@@ -1314,7 +1316,7 @@ var McpAgent = class McpAgent extends Agent {
1314
1316
  throw error;
1315
1317
  }
1316
1318
  if (await this._handleElicitationResponse(parsedMessage)) return null;
1317
- this._transport?.onmessage?.(parsedMessage);
1319
+ this._transport?.onmessage?.(parsedMessage, extraInfo);
1318
1320
  return null;
1319
1321
  } catch (error) {
1320
1322
  console.error("Error forwarding message to SSE:", error);