agents 0.0.0-d7a460e → 0.0.0-da2bb57
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 +86 -13
- package/dist/ai-chat-agent.js +340 -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 +164 -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.d.ts +8 -0
- package/dist/cli.js +27 -0
- package/dist/cli.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-BZq9qau2.js +1093 -0
- package/dist/client-BZq9qau2.js.map +1 -0
- package/dist/client-DJhQNTez.d.ts +1528 -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-DFqsR7mb.d.ts → index-BvEldExU.d.ts} +53 -26
- 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 +75 -36
- package/dist/mcp/index.js +99 -21
- 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-NCPvtyCY.d.ts → react-Ccc1FohP.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-D_KKH_4c.js} +123 -139
- package/dist/src-D_KKH_4c.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-Csp_m13H.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-BZq9qau2.js";
|
|
4
|
+
import "../do-oauth-client-provider-CwqK5SXm.js";
|
|
5
|
+
import { c as getCurrentAgent, s as getAgentByName, t as Agent } from "../src-D_KKH_4c.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,6 +935,7 @@ var WorkerTransport = class {
|
|
|
868
935
|
}
|
|
869
936
|
});
|
|
870
937
|
}
|
|
938
|
+
const requestInfo = { headers: Object.fromEntries(request.headers.entries()) };
|
|
871
939
|
const isInitializationRequest = messages.some(isInitializeRequest);
|
|
872
940
|
if (isInitializationRequest) {
|
|
873
941
|
if (this.initialized && this.sessionId !== void 0) return new Response(JSON.stringify({
|
|
@@ -906,6 +974,7 @@ var WorkerTransport = class {
|
|
|
906
974
|
}
|
|
907
975
|
this.sessionId = this.sessionIdGenerator?.();
|
|
908
976
|
this.initialized = true;
|
|
977
|
+
await this.saveState();
|
|
909
978
|
if (this.sessionId && this.onsessioninitialized) this.onsessioninitialized(this.sessionId);
|
|
910
979
|
}
|
|
911
980
|
if (!isInitializationRequest) {
|
|
@@ -915,7 +984,7 @@ var WorkerTransport = class {
|
|
|
915
984
|
if (versionError) return versionError;
|
|
916
985
|
}
|
|
917
986
|
if (!messages.some(isJSONRPCRequest)) {
|
|
918
|
-
for (const message of messages) this.onmessage?.(message);
|
|
987
|
+
for (const message of messages) this.onmessage?.(message, { requestInfo });
|
|
919
988
|
return new Response(null, {
|
|
920
989
|
status: 202,
|
|
921
990
|
headers: { ...this.getHeaders() }
|
|
@@ -930,7 +999,7 @@ var WorkerTransport = class {
|
|
|
930
999
|
}
|
|
931
1000
|
});
|
|
932
1001
|
for (const message of messages) if (isJSONRPCRequest(message)) this.requestToStreamMapping.set(message.id, streamId);
|
|
933
|
-
for (const message of messages) this.onmessage?.(message);
|
|
1002
|
+
for (const message of messages) this.onmessage?.(message, { requestInfo });
|
|
934
1003
|
});
|
|
935
1004
|
const { readable, writable } = new TransformStream();
|
|
936
1005
|
const writer = writable.getWriter();
|
|
@@ -951,7 +1020,7 @@ var WorkerTransport = class {
|
|
|
951
1020
|
}
|
|
952
1021
|
});
|
|
953
1022
|
for (const message of messages) if (isJSONRPCRequest(message)) this.requestToStreamMapping.set(message.id, streamId);
|
|
954
|
-
for (const message of messages) this.onmessage?.(message);
|
|
1023
|
+
for (const message of messages) this.onmessage?.(message, { requestInfo });
|
|
955
1024
|
return new Response(readable, { headers });
|
|
956
1025
|
}
|
|
957
1026
|
async handleDeleteRequest(request) {
|
|
@@ -1039,8 +1108,8 @@ var WorkerTransport = class {
|
|
|
1039
1108
|
this.requestResponseMap.clear();
|
|
1040
1109
|
this.onclose?.();
|
|
1041
1110
|
}
|
|
1042
|
-
async send(message) {
|
|
1043
|
-
let requestId;
|
|
1111
|
+
async send(message, options) {
|
|
1112
|
+
let requestId = options?.relatedRequestId;
|
|
1044
1113
|
if (isJSONRPCResponse(message) || isJSONRPCError(message)) requestId = message.id;
|
|
1045
1114
|
if (requestId === void 0) {
|
|
1046
1115
|
if (isJSONRPCResponse(message) || isJSONRPCError(message)) throw new Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");
|
|
@@ -1102,13 +1171,22 @@ function createMcpHandler(server, options = {}) {
|
|
|
1102
1171
|
return async (request, _env, ctx) => {
|
|
1103
1172
|
const url = new URL(request.url);
|
|
1104
1173
|
if (route && url.pathname !== route) return new Response("Not Found", { status: 404 });
|
|
1105
|
-
const
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
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
|
+
};
|
|
1109
1185
|
const handleRequest = async () => {
|
|
1110
1186
|
return await transport.handleRequest(request);
|
|
1111
1187
|
};
|
|
1188
|
+
const authContext = buildAuthContext();
|
|
1189
|
+
if (!transport.started) await server.connect(transport);
|
|
1112
1190
|
try {
|
|
1113
1191
|
if (authContext) return await runWithAuthContext(authContext, handleRequest);
|
|
1114
1192
|
else return await handleRequest();
|
|
@@ -1179,7 +1257,7 @@ var McpAgent = class McpAgent extends Agent {
|
|
|
1179
1257
|
/** Returns a new transport matching the type of the Agent. */
|
|
1180
1258
|
initTransport() {
|
|
1181
1259
|
switch (this.getTransportType()) {
|
|
1182
|
-
case "sse": return new McpSSETransport(
|
|
1260
|
+
case "sse": return new McpSSETransport();
|
|
1183
1261
|
case "streamable-http": return new StreamableHTTPServerTransport({});
|
|
1184
1262
|
}
|
|
1185
1263
|
}
|
|
@@ -1232,7 +1310,7 @@ var McpAgent = class McpAgent extends Agent {
|
|
|
1232
1310
|
}
|
|
1233
1311
|
}
|
|
1234
1312
|
/** Handles MCP Messages for the legacy SSE transport. */
|
|
1235
|
-
async onSSEMcpMessage(_sessionId, messageBody) {
|
|
1313
|
+
async onSSEMcpMessage(_sessionId, messageBody, extraInfo) {
|
|
1236
1314
|
if (this.getTransportType() !== "sse") return /* @__PURE__ */ new Error("Internal Server Error: Expected SSE transport");
|
|
1237
1315
|
try {
|
|
1238
1316
|
let parsedMessage;
|
|
@@ -1243,7 +1321,7 @@ var McpAgent = class McpAgent extends Agent {
|
|
|
1243
1321
|
throw error;
|
|
1244
1322
|
}
|
|
1245
1323
|
if (await this._handleElicitationResponse(parsedMessage)) return null;
|
|
1246
|
-
this._transport?.onmessage?.(parsedMessage);
|
|
1324
|
+
this._transport?.onmessage?.(parsedMessage, extraInfo);
|
|
1247
1325
|
return null;
|
|
1248
1326
|
} catch (error) {
|
|
1249
1327
|
console.error("Error forwarding message to SSE:", error);
|