agents 0.0.0-2b6cba4 → 0.0.0-2c1427d

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.
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-JMskg2fw.js";
3
+ import "../client-DZhjV_XA.js";
4
4
  import "../do-oauth-client-provider-CswoD5Lu.js";
5
- import { c as getCurrentAgent, s as getAgentByName, t as Agent } from "../src-nFNV3Ttx.js";
5
+ import { c as getCurrentAgent, s as getAgentByName, t as Agent } from "../src-CwIW7tU2.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);
@@ -907,6 +967,7 @@ var WorkerTransport = class {
907
967
  }
908
968
  this.sessionId = this.sessionIdGenerator?.();
909
969
  this.initialized = true;
970
+ await this.saveState();
910
971
  if (this.sessionId && this.onsessioninitialized) this.onsessioninitialized(this.sessionId);
911
972
  }
912
973
  if (!isInitializationRequest) {
@@ -1103,13 +1164,22 @@ function createMcpHandler(server, options = {}) {
1103
1164
  return async (request, _env, ctx) => {
1104
1165
  const url = new URL(request.url);
1105
1166
  if (route && url.pathname !== route) return new Response("Not Found", { status: 404 });
1106
- const oauthCtx = ctx;
1107
- const authContext = oauthCtx.props ? { props: oauthCtx.props } : void 0;
1108
- const transport = new WorkerTransport(options);
1109
- 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
+ };
1110
1178
  const handleRequest = async () => {
1111
1179
  return await transport.handleRequest(request);
1112
1180
  };
1181
+ const authContext = buildAuthContext();
1182
+ if (!transport.started) await server.connect(transport);
1113
1183
  try {
1114
1184
  if (authContext) return await runWithAuthContext(authContext, handleRequest);
1115
1185
  else return await handleRequest();