agents 0.0.0-72b6c49 → 0.0.0-7360c51
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/README.md +5 -3
- package/dist/ai-chat-agent.d.ts +94 -13
- package/dist/ai-chat-agent.js +346 -74
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/{ai-chat-v5-migration-DBHGW4Hv.js → ai-chat-v5-migration-BSiGZmYU.js} +1 -1
- package/dist/{ai-chat-v5-migration-DBHGW4Hv.js.map → ai-chat-v5-migration-BSiGZmYU.js.map} +1 -1
- package/dist/ai-chat-v5-migration.js +1 -1
- package/dist/ai-react.d.ts +14 -9
- package/dist/ai-react.js +179 -29
- package/dist/ai-react.js.map +1 -1
- package/dist/{ai-types-D5YoPrBZ.d.ts → ai-types-81H_-Uxh.d.ts} +15 -7
- package/dist/{ai-types-B3aQaFv3.js → ai-types-CrMqkwc_.js} +5 -1
- package/dist/ai-types-CrMqkwc_.js.map +1 -0
- package/dist/ai-types.d.ts +1 -1
- package/dist/ai-types.js +1 -1
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +28 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/{client-BfiZ3HQd.js → client-B3SR12TQ.js} +2 -2
- package/dist/{client-BfiZ3HQd.js.map → client-B3SR12TQ.js.map} +1 -1
- package/dist/{client-CbWe9FBd.d.ts → client-BAQA84dr.d.ts} +2 -2
- package/dist/client-CFhjXCiO.js +1093 -0
- package/dist/client-CFhjXCiO.js.map +1 -0
- package/dist/client-z9RQJDtK.d.ts +833 -0
- package/dist/client.d.ts +2 -2
- package/dist/client.js +2 -2
- package/dist/codemode/ai.js +5 -5
- package/dist/{do-oauth-client-provider-DGc5pP0l.d.ts → do-oauth-client-provider-C2CHH5x-.d.ts} +1 -1
- package/dist/{do-oauth-client-provider-CswoD5Lu.js → do-oauth-client-provider-CwqK5SXm.js} +2 -1
- package/dist/do-oauth-client-provider-CwqK5SXm.js.map +1 -0
- package/dist/{index-DhJCaDWd.d.ts → index-BUle9RiP.d.ts} +2 -2
- package/dist/{index-_D8rpSTJ.d.ts → index-D3s0zwxa.d.ts} +54 -27
- package/dist/index.d.ts +6 -6
- package/dist/index.js +5 -5
- package/dist/mcp/client.d.ts +4 -4
- package/dist/mcp/client.js +2 -1
- package/dist/mcp/do-oauth-client-provider.d.ts +1 -1
- package/dist/mcp/do-oauth-client-provider.js +1 -1
- package/dist/mcp/index.d.ts +73 -34
- package/dist/mcp/index.js +96 -22
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/x402.js +10 -6
- package/dist/mcp/x402.js.map +1 -1
- package/dist/{mcp-Dw5vDrY8.d.ts → mcp-BwPscEiF.d.ts} +1 -1
- package/dist/observability/index.d.ts +2 -2
- package/dist/observability/index.js +5 -5
- package/dist/{react-D4uebgIu.d.ts → react-D9Ou_tyQ.d.ts} +33 -35
- package/dist/react.d.ts +9 -9
- package/dist/react.js +2 -2
- package/dist/react.js.map +1 -1
- package/dist/{serializable-CymX8ovI.d.ts → serializable-faDkMCai.d.ts} +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/{src-Dz0H9hSU.js → src-CNAXL7wY.js} +127 -145
- package/dist/src-CNAXL7wY.js.map +1 -0
- package/package.json +53 -38
- package/dist/ai-types-B3aQaFv3.js.map +0 -1
- package/dist/client-9Ld2_lnt.js +0 -786
- package/dist/client-9Ld2_lnt.js.map +0 -1
- package/dist/client-mxNP7zR3.d.ts +0 -5315
- package/dist/do-oauth-client-provider-CswoD5Lu.js.map +0 -1
- package/dist/src-Dz0H9hSU.js.map +0 -1
package/dist/mcp/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { t as MessageType } from "../ai-types-
|
|
2
|
-
import "../client-
|
|
3
|
-
import
|
|
4
|
-
import "../do-oauth-client-provider-
|
|
5
|
-
import { c as getCurrentAgent, s as getAgentByName, t as Agent } from "../src-
|
|
1
|
+
import { t as MessageType } from "../ai-types-CrMqkwc_.js";
|
|
2
|
+
import "../client-B3SR12TQ.js";
|
|
3
|
+
import "../client-CFhjXCiO.js";
|
|
4
|
+
import "../do-oauth-client-provider-CwqK5SXm.js";
|
|
5
|
+
import { c as getCurrentAgent, s as getAgentByName, t as Agent } from "../src-CNAXL7wY.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
|
|
@@ -432,7 +434,8 @@ const createLegacySseHandler = (basePath, namespace, options = {}) => {
|
|
|
432
434
|
jurisdiction: options.jurisdiction
|
|
433
435
|
});
|
|
434
436
|
const messageBody = await request.json();
|
|
435
|
-
const
|
|
437
|
+
const extraInfo = { requestInfo: { headers: Object.fromEntries(request.headers.entries()) } };
|
|
438
|
+
const error = await agent.onSSEMcpMessage(sessionId, messageBody, extraInfo);
|
|
436
439
|
if (error) return new Response(error.message, {
|
|
437
440
|
headers: {
|
|
438
441
|
"Cache-Control": "no-cache",
|
|
@@ -476,9 +479,12 @@ function isDurableObjectNamespace(namespace) {
|
|
|
476
479
|
//#endregion
|
|
477
480
|
//#region src/mcp/transport.ts
|
|
478
481
|
var McpSSETransport = class {
|
|
479
|
-
constructor(
|
|
482
|
+
constructor() {
|
|
480
483
|
this._started = false;
|
|
481
|
-
|
|
484
|
+
const { agent } = getCurrentAgent();
|
|
485
|
+
if (!agent) throw new Error("McpAgent was not found in Transport constructor");
|
|
486
|
+
this.sessionId = agent.getSessionId();
|
|
487
|
+
this._getWebSocket = () => agent.getWebSocket();
|
|
482
488
|
}
|
|
483
489
|
async start() {
|
|
484
490
|
if (this._started) throw new Error("Transport already started");
|
|
@@ -637,6 +643,38 @@ var StreamableHTTPServerTransport = class {
|
|
|
637
643
|
}
|
|
638
644
|
};
|
|
639
645
|
|
|
646
|
+
//#endregion
|
|
647
|
+
//#region src/mcp/client-transports.ts
|
|
648
|
+
/**
|
|
649
|
+
* Deprecated transport wrappers
|
|
650
|
+
*/
|
|
651
|
+
let didWarnAboutSSEEdgeClientTransport = false;
|
|
652
|
+
/**
|
|
653
|
+
* @deprecated Use SSEClientTransport from @modelcontextprotocol/sdk/client/sse.js instead. This alias will be removed in the next major version.
|
|
654
|
+
*/
|
|
655
|
+
var SSEEdgeClientTransport = class extends SSEClientTransport {
|
|
656
|
+
constructor(url, options) {
|
|
657
|
+
super(url, options);
|
|
658
|
+
if (!didWarnAboutSSEEdgeClientTransport) {
|
|
659
|
+
didWarnAboutSSEEdgeClientTransport = true;
|
|
660
|
+
console.warn("SSEEdgeClientTransport is deprecated. Use SSEClientTransport from @modelcontextprotocol/sdk/client/sse.js instead. SSEEdgeClientTransport will be removed in the next major version.");
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
let didWarnAboutStreamableHTTPEdgeClientTransport = false;
|
|
665
|
+
/**
|
|
666
|
+
* @deprecated Use StreamableHTTPClientTransport from @modelcontextprotocol/sdk/client/streamableHttp.js instead. This alias will be removed in the next major version.
|
|
667
|
+
*/
|
|
668
|
+
var StreamableHTTPEdgeClientTransport = class extends StreamableHTTPClientTransport {
|
|
669
|
+
constructor(url, options) {
|
|
670
|
+
super(url, options);
|
|
671
|
+
if (!didWarnAboutStreamableHTTPEdgeClientTransport) {
|
|
672
|
+
didWarnAboutStreamableHTTPEdgeClientTransport = true;
|
|
673
|
+
console.warn("StreamableHTTPEdgeClientTransport is deprecated. Use StreamableHTTPClientTransport from @modelcontextprotocol/sdk/client/streamableHttp.js instead. StreamableHTTPEdgeClientTransport will be removed in the next major version.");
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
|
|
640
678
|
//#endregion
|
|
641
679
|
//#region src/mcp/worker-transport.ts
|
|
642
680
|
const SUPPORTED_PROTOCOL_VERSIONS = ["2025-03-26", "2025-06-18"];
|
|
@@ -651,10 +689,38 @@ var WorkerTransport = class {
|
|
|
651
689
|
this.streamMapping = /* @__PURE__ */ new Map();
|
|
652
690
|
this.requestToStreamMapping = /* @__PURE__ */ new Map();
|
|
653
691
|
this.requestResponseMap = /* @__PURE__ */ new Map();
|
|
692
|
+
this.stateRestored = false;
|
|
654
693
|
this.sessionIdGenerator = options?.sessionIdGenerator;
|
|
655
694
|
this.enableJsonResponse = options?.enableJsonResponse ?? false;
|
|
656
695
|
this.onsessioninitialized = options?.onsessioninitialized;
|
|
657
696
|
this.corsOptions = options?.corsOptions;
|
|
697
|
+
this.storage = options?.storage;
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Restore transport state from persistent storage.
|
|
701
|
+
* This is automatically called on start.
|
|
702
|
+
*/
|
|
703
|
+
async restoreState() {
|
|
704
|
+
if (!this.storage || this.stateRestored) return;
|
|
705
|
+
const state = await Promise.resolve(this.storage.get());
|
|
706
|
+
if (state) {
|
|
707
|
+
this.sessionId = state.sessionId;
|
|
708
|
+
this.initialized = state.initialized;
|
|
709
|
+
this.protocolVersion = state.protocolVersion;
|
|
710
|
+
}
|
|
711
|
+
this.stateRestored = true;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Persist current transport state to storage.
|
|
715
|
+
*/
|
|
716
|
+
async saveState() {
|
|
717
|
+
if (!this.storage) return;
|
|
718
|
+
const state = {
|
|
719
|
+
sessionId: this.sessionId,
|
|
720
|
+
initialized: this.initialized,
|
|
721
|
+
protocolVersion: this.protocolVersion
|
|
722
|
+
};
|
|
723
|
+
await Promise.resolve(this.storage.set(state));
|
|
658
724
|
}
|
|
659
725
|
async start() {
|
|
660
726
|
if (this.started) throw new Error("Transport already started");
|
|
@@ -729,6 +795,7 @@ var WorkerTransport = class {
|
|
|
729
795
|
};
|
|
730
796
|
}
|
|
731
797
|
async handleRequest(request, parsedBody) {
|
|
798
|
+
await this.restoreState();
|
|
732
799
|
switch (request.method) {
|
|
733
800
|
case "OPTIONS": return this.handleOptionsRequest(request);
|
|
734
801
|
case "GET": return this.handleGetRequest(request);
|
|
@@ -801,7 +868,7 @@ var WorkerTransport = class {
|
|
|
801
868
|
}
|
|
802
869
|
async handlePostRequest(request, parsedBody) {
|
|
803
870
|
const acceptHeader = request.headers.get("Accept");
|
|
804
|
-
if (!acceptHeader?.includes("application/json") || !acceptHeader
|
|
871
|
+
if (!acceptHeader?.includes("application/json") || !acceptHeader?.includes("text/event-stream")) return new Response(JSON.stringify({
|
|
805
872
|
jsonrpc: "2.0",
|
|
806
873
|
error: {
|
|
807
874
|
code: -32e3,
|
|
@@ -868,10 +935,7 @@ var WorkerTransport = class {
|
|
|
868
935
|
}
|
|
869
936
|
});
|
|
870
937
|
}
|
|
871
|
-
const requestInfo = {
|
|
872
|
-
headers: Object.fromEntries(request.headers.entries()),
|
|
873
|
-
url: request.url
|
|
874
|
-
};
|
|
938
|
+
const requestInfo = { headers: Object.fromEntries(request.headers.entries()) };
|
|
875
939
|
const isInitializationRequest = messages.some(isInitializeRequest);
|
|
876
940
|
if (isInitializationRequest) {
|
|
877
941
|
if (this.initialized && this.sessionId !== void 0) return new Response(JSON.stringify({
|
|
@@ -910,6 +974,7 @@ var WorkerTransport = class {
|
|
|
910
974
|
}
|
|
911
975
|
this.sessionId = this.sessionIdGenerator?.();
|
|
912
976
|
this.initialized = true;
|
|
977
|
+
await this.saveState();
|
|
913
978
|
if (this.sessionId && this.onsessioninitialized) this.onsessioninitialized(this.sessionId);
|
|
914
979
|
}
|
|
915
980
|
if (!isInitializationRequest) {
|
|
@@ -1043,8 +1108,8 @@ var WorkerTransport = class {
|
|
|
1043
1108
|
this.requestResponseMap.clear();
|
|
1044
1109
|
this.onclose?.();
|
|
1045
1110
|
}
|
|
1046
|
-
async send(message) {
|
|
1047
|
-
let requestId;
|
|
1111
|
+
async send(message, options) {
|
|
1112
|
+
let requestId = options?.relatedRequestId;
|
|
1048
1113
|
if (isJSONRPCResponse(message) || isJSONRPCError(message)) requestId = message.id;
|
|
1049
1114
|
if (requestId === void 0) {
|
|
1050
1115
|
if (isJSONRPCResponse(message) || isJSONRPCError(message)) throw new Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");
|
|
@@ -1106,13 +1171,22 @@ function createMcpHandler(server, options = {}) {
|
|
|
1106
1171
|
return async (request, _env, ctx) => {
|
|
1107
1172
|
const url = new URL(request.url);
|
|
1108
1173
|
if (route && url.pathname !== route) return new Response("Not Found", { status: 404 });
|
|
1109
|
-
const
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1174
|
+
const transport = options.transport ?? new WorkerTransport({
|
|
1175
|
+
sessionIdGenerator: options.sessionIdGenerator,
|
|
1176
|
+
enableJsonResponse: options.enableJsonResponse,
|
|
1177
|
+
onsessioninitialized: options.onsessioninitialized,
|
|
1178
|
+
corsOptions: options.corsOptions,
|
|
1179
|
+
storage: options.storage
|
|
1180
|
+
});
|
|
1181
|
+
const buildAuthContext = () => {
|
|
1182
|
+
if (options.authContext) return options.authContext;
|
|
1183
|
+
if (ctx.props && Object.keys(ctx.props).length > 0) return { props: ctx.props };
|
|
1184
|
+
};
|
|
1113
1185
|
const handleRequest = async () => {
|
|
1114
1186
|
return await transport.handleRequest(request);
|
|
1115
1187
|
};
|
|
1188
|
+
const authContext = buildAuthContext();
|
|
1189
|
+
if (!transport.started) await server.connect(transport);
|
|
1116
1190
|
try {
|
|
1117
1191
|
if (authContext) return await runWithAuthContext(authContext, handleRequest);
|
|
1118
1192
|
else return await handleRequest();
|
|
@@ -1183,7 +1257,7 @@ var McpAgent = class McpAgent extends Agent {
|
|
|
1183
1257
|
/** Returns a new transport matching the type of the Agent. */
|
|
1184
1258
|
initTransport() {
|
|
1185
1259
|
switch (this.getTransportType()) {
|
|
1186
|
-
case "sse": return new McpSSETransport(
|
|
1260
|
+
case "sse": return new McpSSETransport();
|
|
1187
1261
|
case "streamable-http": return new StreamableHTTPServerTransport({});
|
|
1188
1262
|
}
|
|
1189
1263
|
}
|
|
@@ -1236,7 +1310,7 @@ var McpAgent = class McpAgent extends Agent {
|
|
|
1236
1310
|
}
|
|
1237
1311
|
}
|
|
1238
1312
|
/** Handles MCP Messages for the legacy SSE transport. */
|
|
1239
|
-
async onSSEMcpMessage(_sessionId, messageBody) {
|
|
1313
|
+
async onSSEMcpMessage(_sessionId, messageBody, extraInfo) {
|
|
1240
1314
|
if (this.getTransportType() !== "sse") return /* @__PURE__ */ new Error("Internal Server Error: Expected SSE transport");
|
|
1241
1315
|
try {
|
|
1242
1316
|
let parsedMessage;
|
|
@@ -1247,7 +1321,7 @@ var McpAgent = class McpAgent extends Agent {
|
|
|
1247
1321
|
throw error;
|
|
1248
1322
|
}
|
|
1249
1323
|
if (await this._handleElicitationResponse(parsedMessage)) return null;
|
|
1250
|
-
this._transport?.onmessage?.(parsedMessage);
|
|
1324
|
+
this._transport?.onmessage?.(parsedMessage, extraInfo);
|
|
1251
1325
|
return null;
|
|
1252
1326
|
} catch (error) {
|
|
1253
1327
|
console.error("Error forwarding message to SSE:", error);
|