agents 0.0.0-4dafe91 → 0.0.0-4ebd6e4

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 (36) hide show
  1. package/dist/ai-chat-agent.d.ts +3 -3
  2. package/dist/ai-chat-agent.js +3 -3
  3. package/dist/ai-chat-agent.js.map +1 -1
  4. package/dist/ai-react.d.ts +4 -4
  5. package/dist/ai-react.js +8 -3
  6. package/dist/ai-react.js.map +1 -1
  7. package/dist/cli.d.ts +8 -0
  8. package/dist/cli.js +27 -0
  9. package/dist/cli.js.map +1 -0
  10. package/dist/{client-Csp_m13H.d.ts → client-D4R9pcB-.d.ts} +191 -79
  11. package/dist/{client-9Ld2_lnt.js → client-DvK0u9vD.js} +236 -124
  12. package/dist/client-DvK0u9vD.js.map +1 -0
  13. package/dist/codemode/ai.js +3 -3
  14. package/dist/do-oauth-client-provider-CcTno-25.d.ts +142 -0
  15. package/dist/{do-oauth-client-provider-CswoD5Lu.js → do-oauth-client-provider-D2P1lSft.js} +2 -2
  16. package/dist/do-oauth-client-provider-D2P1lSft.js.map +1 -0
  17. package/dist/{index-DFqsR7mb.d.ts → index-D76wnQcf.d.ts} +30 -18
  18. package/dist/index.d.ts +3 -3
  19. package/dist/index.js +3 -3
  20. package/dist/mcp/client.d.ts +3 -3
  21. package/dist/mcp/client.js +2 -1
  22. package/dist/mcp/do-oauth-client-provider.d.ts +1 -1
  23. package/dist/mcp/do-oauth-client-provider.js +1 -1
  24. package/dist/mcp/index.d.ts +68 -29
  25. package/dist/mcp/index.js +81 -10
  26. package/dist/mcp/index.js.map +1 -1
  27. package/dist/observability/index.js +3 -3
  28. package/dist/{react-NCPvtyCY.d.ts → react-DiQhRddQ.d.ts} +31 -33
  29. package/dist/react.d.ts +4 -4
  30. package/dist/{src-Dz0H9hSU.js → src-C1WWpbRo.js} +185 -138
  31. package/dist/src-C1WWpbRo.js.map +1 -0
  32. package/package.json +52 -37
  33. package/dist/client-9Ld2_lnt.js.map +0 -1
  34. package/dist/do-oauth-client-provider-CswoD5Lu.js.map +0 -1
  35. package/dist/do-oauth-client-provider-DGc5pP0l.d.ts +0 -55
  36. package/dist/src-Dz0H9hSU.js.map +0 -1
package/dist/mcp/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import { t as MessageType } from "../ai-types-B3aQaFv3.js";
2
2
  import "../client-BfiZ3HQd.js";
3
- import { a as SSEEdgeClientTransport, i as StreamableHTTPEdgeClientTransport } from "../client-9Ld2_lnt.js";
4
- import "../do-oauth-client-provider-CswoD5Lu.js";
5
- import { c as getCurrentAgent, s as getAgentByName, t as Agent } from "../src-Dz0H9hSU.js";
3
+ import "../client-DvK0u9vD.js";
4
+ import "../do-oauth-client-provider-D2P1lSft.js";
5
+ import { c as getCurrentAgent, s as getAgentByName, t as Agent } from "../src-C1WWpbRo.js";
6
6
  import { AsyncLocalStorage } from "node:async_hooks";
7
+ import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
8
+ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
7
9
  import { ElicitRequestSchema, InitializeRequestSchema, JSONRPCMessageSchema, isInitializeRequest, isJSONRPCError, isJSONRPCNotification, isJSONRPCRequest, isJSONRPCResponse } from "@modelcontextprotocol/sdk/types.js";
8
10
 
9
11
  //#region src/mcp/utils.ts
@@ -637,6 +639,35 @@ var StreamableHTTPServerTransport = class {
637
639
  }
638
640
  };
639
641
 
642
+ //#endregion
643
+ //#region src/mcp/client-transports.ts
644
+ let didWarnAboutSSEEdgeClientTransport = false;
645
+ /**
646
+ * @deprecated Use SSEClientTransport from @modelcontextprotocol/sdk/client/sse.js instead. This alias will be removed in the next major version.
647
+ */
648
+ var SSEEdgeClientTransport = class extends SSEClientTransport {
649
+ constructor(url, options) {
650
+ super(url, options);
651
+ if (!didWarnAboutSSEEdgeClientTransport) {
652
+ didWarnAboutSSEEdgeClientTransport = true;
653
+ console.warn("SSEEdgeClientTransport is deprecated. Use SSEClientTransport from @modelcontextprotocol/sdk/client/sse.js instead. SSEEdgeClientTransport will be removed in the next major version.");
654
+ }
655
+ }
656
+ };
657
+ let didWarnAboutStreamableHTTPEdgeClientTransport = false;
658
+ /**
659
+ * @deprecated Use StreamableHTTPClientTransport from @modelcontextprotocol/sdk/client/streamableHttp.js instead. This alias will be removed in the next major version.
660
+ */
661
+ var StreamableHTTPEdgeClientTransport = class extends StreamableHTTPClientTransport {
662
+ constructor(url, options) {
663
+ super(url, options);
664
+ if (!didWarnAboutStreamableHTTPEdgeClientTransport) {
665
+ didWarnAboutStreamableHTTPEdgeClientTransport = true;
666
+ console.warn("StreamableHTTPEdgeClientTransport is deprecated. Use StreamableHTTPClientTransport from @modelcontextprotocol/sdk/client/streamableHttp.js instead. StreamableHTTPEdgeClientTransport will be removed in the next major version.");
667
+ }
668
+ }
669
+ };
670
+
640
671
  //#endregion
641
672
  //#region src/mcp/worker-transport.ts
642
673
  const SUPPORTED_PROTOCOL_VERSIONS = ["2025-03-26", "2025-06-18"];
@@ -651,10 +682,38 @@ var WorkerTransport = class {
651
682
  this.streamMapping = /* @__PURE__ */ new Map();
652
683
  this.requestToStreamMapping = /* @__PURE__ */ new Map();
653
684
  this.requestResponseMap = /* @__PURE__ */ new Map();
685
+ this.stateRestored = false;
654
686
  this.sessionIdGenerator = options?.sessionIdGenerator;
655
687
  this.enableJsonResponse = options?.enableJsonResponse ?? false;
656
688
  this.onsessioninitialized = options?.onsessioninitialized;
657
689
  this.corsOptions = options?.corsOptions;
690
+ this.storage = options?.storage;
691
+ }
692
+ /**
693
+ * Restore transport state from persistent storage.
694
+ * This is automatically called on start.
695
+ */
696
+ async restoreState() {
697
+ if (!this.storage || this.stateRestored) return;
698
+ const state = await Promise.resolve(this.storage.get());
699
+ if (state) {
700
+ this.sessionId = state.sessionId;
701
+ this.initialized = state.initialized;
702
+ this.protocolVersion = state.protocolVersion;
703
+ }
704
+ this.stateRestored = true;
705
+ }
706
+ /**
707
+ * Persist current transport state to storage.
708
+ */
709
+ async saveState() {
710
+ if (!this.storage) return;
711
+ const state = {
712
+ sessionId: this.sessionId,
713
+ initialized: this.initialized,
714
+ protocolVersion: this.protocolVersion
715
+ };
716
+ await Promise.resolve(this.storage.set(state));
658
717
  }
659
718
  async start() {
660
719
  if (this.started) throw new Error("Transport already started");
@@ -729,6 +788,7 @@ var WorkerTransport = class {
729
788
  };
730
789
  }
731
790
  async handleRequest(request, parsedBody) {
791
+ await this.restoreState();
732
792
  switch (request.method) {
733
793
  case "OPTIONS": return this.handleOptionsRequest(request);
734
794
  case "GET": return this.handleGetRequest(request);
@@ -868,6 +928,7 @@ var WorkerTransport = class {
868
928
  }
869
929
  });
870
930
  }
931
+ const requestInfo = { headers: Object.fromEntries(request.headers.entries()) };
871
932
  const isInitializationRequest = messages.some(isInitializeRequest);
872
933
  if (isInitializationRequest) {
873
934
  if (this.initialized && this.sessionId !== void 0) return new Response(JSON.stringify({
@@ -906,6 +967,7 @@ var WorkerTransport = class {
906
967
  }
907
968
  this.sessionId = this.sessionIdGenerator?.();
908
969
  this.initialized = true;
970
+ await this.saveState();
909
971
  if (this.sessionId && this.onsessioninitialized) this.onsessioninitialized(this.sessionId);
910
972
  }
911
973
  if (!isInitializationRequest) {
@@ -915,7 +977,7 @@ var WorkerTransport = class {
915
977
  if (versionError) return versionError;
916
978
  }
917
979
  if (!messages.some(isJSONRPCRequest)) {
918
- for (const message of messages) this.onmessage?.(message);
980
+ for (const message of messages) this.onmessage?.(message, { requestInfo });
919
981
  return new Response(null, {
920
982
  status: 202,
921
983
  headers: { ...this.getHeaders() }
@@ -930,7 +992,7 @@ var WorkerTransport = class {
930
992
  }
931
993
  });
932
994
  for (const message of messages) if (isJSONRPCRequest(message)) this.requestToStreamMapping.set(message.id, streamId);
933
- for (const message of messages) this.onmessage?.(message);
995
+ for (const message of messages) this.onmessage?.(message, { requestInfo });
934
996
  });
935
997
  const { readable, writable } = new TransformStream();
936
998
  const writer = writable.getWriter();
@@ -951,7 +1013,7 @@ var WorkerTransport = class {
951
1013
  }
952
1014
  });
953
1015
  for (const message of messages) if (isJSONRPCRequest(message)) this.requestToStreamMapping.set(message.id, streamId);
954
- for (const message of messages) this.onmessage?.(message);
1016
+ for (const message of messages) this.onmessage?.(message, { requestInfo });
955
1017
  return new Response(readable, { headers });
956
1018
  }
957
1019
  async handleDeleteRequest(request) {
@@ -1102,13 +1164,22 @@ function createMcpHandler(server, options = {}) {
1102
1164
  return async (request, _env, ctx) => {
1103
1165
  const url = new URL(request.url);
1104
1166
  if (route && url.pathname !== route) return new Response("Not Found", { status: 404 });
1105
- const oauthCtx = ctx;
1106
- const authContext = oauthCtx.props ? { props: oauthCtx.props } : void 0;
1107
- const transport = new WorkerTransport(options);
1108
- await server.connect(transport);
1167
+ const transport = options.transport ?? new WorkerTransport({
1168
+ sessionIdGenerator: options.sessionIdGenerator,
1169
+ enableJsonResponse: options.enableJsonResponse,
1170
+ onsessioninitialized: options.onsessioninitialized,
1171
+ corsOptions: options.corsOptions,
1172
+ storage: options.storage
1173
+ });
1174
+ const buildAuthContext = () => {
1175
+ if (options.authContext) return options.authContext;
1176
+ if (ctx.props && Object.keys(ctx.props).length > 0) return { props: ctx.props };
1177
+ };
1109
1178
  const handleRequest = async () => {
1110
1179
  return await transport.handleRequest(request);
1111
1180
  };
1181
+ const authContext = buildAuthContext();
1182
+ if (!transport.started) await server.connect(transport);
1112
1183
  try {
1113
1184
  if (authContext) return await runWithAuthContext(authContext, handleRequest);
1114
1185
  else return await handleRequest();