agents 0.0.0-d4257c1 → 0.0.0-d6d6d60
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/ai-chat-agent.d.ts +10 -10
- package/dist/ai-chat-agent.js +6 -6
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/{ai-chat-v5-migration-gdyLiTd8.js → ai-chat-v5-migration-DBHGW4Hv.js} +2 -2
- package/dist/{ai-chat-v5-migration-gdyLiTd8.js.map → ai-chat-v5-migration-DBHGW4Hv.js.map} +1 -1
- package/dist/ai-chat-v5-migration.js +1 -1
- package/dist/ai-react.d.ts +9 -9
- package/dist/ai-react.js +17 -11
- package/dist/ai-react.js.map +1 -1
- package/dist/{ai-types-UZlfLOYP.js → ai-types-B3aQaFv3.js} +2 -2
- package/dist/{ai-types-UZlfLOYP.js.map → ai-types-B3aQaFv3.js.map} +1 -1
- package/dist/{ai-types-BWW4umHY.d.ts → ai-types-D5YoPrBZ.d.ts} +2 -2
- package/dist/ai-types.d.ts +4 -4
- 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-DjR-lC16.js → client-BfiZ3HQd.js} +3 -3
- package/dist/{client-DjR-lC16.js.map → client-BfiZ3HQd.js.map} +1 -1
- package/dist/{client-C-nwz-3N.d.ts → client-Bws9q38u.d.ts} +189 -75
- package/dist/{client-CmMi85Sj.d.ts → client-CbWe9FBd.d.ts} +10 -10
- package/dist/{client-CZBVDDoO.js → client-DvK0u9vD.js} +236 -124
- package/dist/client-DvK0u9vD.js.map +1 -0
- package/dist/client.d.ts +8 -8
- package/dist/client.js +2 -2
- package/dist/codemode/ai.js +5 -5
- package/dist/do-oauth-client-provider-CcTno-25.d.ts +142 -0
- package/dist/{do-oauth-client-provider-B2jr6UNq.js → do-oauth-client-provider-D2P1lSft.js} +3 -3
- package/dist/do-oauth-client-provider-D2P1lSft.js.map +1 -0
- package/dist/{index-CkQU40oY.d.ts → index-Bdzb2feZ.d.ts} +53 -39
- package/dist/{index-W4JUkafc.d.ts → index-DhJCaDWd.d.ts} +7 -3
- package/dist/index.d.ts +36 -36
- 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 +127 -9
- package/dist/mcp/index.js +619 -26
- package/dist/mcp/index.js.map +1 -1
- package/dist/{mcp-BEwaCsxO.d.ts → mcp-Dw5vDrY8.d.ts} +2 -2
- package/dist/observability/index.d.ts +2 -2
- package/dist/observability/index.js +5 -5
- package/dist/{react-B4e1rDid.d.ts → react-DFNXTQzy.d.ts} +17 -17
- package/dist/react.d.ts +9 -9
- package/dist/react.js +1 -1
- package/dist/{serializable-gtr9YMhp.d.ts → serializable-CymX8ovI.d.ts} +8 -3
- package/dist/serializable.d.ts +5 -5
- package/dist/{src-COfG--3R.js → src-C1WWpbRo.js} +189 -121
- package/dist/src-C1WWpbRo.js.map +1 -0
- package/package.json +54 -39
- package/dist/client-CZBVDDoO.js.map +0 -1
- package/dist/do-oauth-client-provider-B2jr6UNq.js.map +0 -1
- package/dist/do-oauth-client-provider-CCwGwnrA.d.ts +0 -55
- package/dist/src-COfG--3R.js.map +0 -1
- package/src/index.ts +0 -2031
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import yargs from "yargs";
|
|
4
|
+
import { hideBin } from "yargs/helpers";
|
|
5
|
+
|
|
6
|
+
//#region src/cli.ts
|
|
7
|
+
function createCli(argv = process.argv) {
|
|
8
|
+
return yargs(hideBin(argv)).scriptName("agents").usage("$0 <command> [options]").command(["init", "create"], "Initialize an agents project", (cmd) => cmd, async () => {
|
|
9
|
+
console.log("agents init: not implemented yet");
|
|
10
|
+
process.exit(0);
|
|
11
|
+
}).command("dev", "Start development server", (cmd) => cmd, async () => {
|
|
12
|
+
console.log("agents dev: not implemented yet");
|
|
13
|
+
process.exit(0);
|
|
14
|
+
}).command("deploy", "Deploy agents to Cloudflare", (cmd) => cmd, async () => {
|
|
15
|
+
console.log("agents deploy: not implemented yet");
|
|
16
|
+
process.exit(0);
|
|
17
|
+
}).command("mcp", "The agents mcp server", (cmd) => cmd, async () => {
|
|
18
|
+
console.log("agents mcp: not implemented yet");
|
|
19
|
+
process.exit(0);
|
|
20
|
+
}).demandCommand(1, "Please provide a command").strict().help();
|
|
21
|
+
}
|
|
22
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
23
|
+
if (process.argv[1] && fileURLToPath(new URL(process.argv[1], "file://")) === __filename) createCli().parse();
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { createCli };
|
|
27
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { fileURLToPath } from \"node:url\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\n\nexport function createCli(argv = process.argv) {\n return yargs(hideBin(argv))\n .scriptName(\"agents\")\n .usage(\"$0 <command> [options]\")\n .command(\n [\"init\", \"create\"],\n \"Initialize an agents project\",\n (cmd) => cmd,\n async () => {\n console.log(\"agents init: not implemented yet\");\n process.exit(0);\n }\n )\n .command(\n \"dev\",\n \"Start development server\",\n (cmd) => cmd,\n async () => {\n console.log(\"agents dev: not implemented yet\");\n process.exit(0);\n }\n )\n .command(\n \"deploy\",\n \"Deploy agents to Cloudflare\",\n (cmd) => cmd,\n async () => {\n console.log(\"agents deploy: not implemented yet\");\n process.exit(0);\n }\n )\n .command(\n \"mcp\",\n \"The agents mcp server\",\n (cmd) => cmd,\n async () => {\n console.log(\"agents mcp: not implemented yet\");\n process.exit(0);\n }\n )\n .demandCommand(1, \"Please provide a command\")\n .strict()\n .help();\n}\n\n// Run CLI if this is the main module\nconst __filename = fileURLToPath(import.meta.url);\n\n// Check if this file was run directly (not imported)\nif (\n process.argv[1] &&\n fileURLToPath(new URL(process.argv[1], \"file://\")) === __filename\n) {\n void createCli().parse();\n}\n"],"mappings":";;;;;;AAMA,SAAgB,UAAU,OAAO,QAAQ,MAAM;AAC7C,QAAO,MAAM,QAAQ,KAAK,CAAC,CACxB,WAAW,SAAS,CACpB,MAAM,yBAAyB,CAC/B,QACC,CAAC,QAAQ,SAAS,EAClB,iCACC,QAAQ,KACT,YAAY;AACV,UAAQ,IAAI,mCAAmC;AAC/C,UAAQ,KAAK,EAAE;GAElB,CACA,QACC,OACA,6BACC,QAAQ,KACT,YAAY;AACV,UAAQ,IAAI,kCAAkC;AAC9C,UAAQ,KAAK,EAAE;GAElB,CACA,QACC,UACA,gCACC,QAAQ,KACT,YAAY;AACV,UAAQ,IAAI,qCAAqC;AACjD,UAAQ,KAAK,EAAE;GAElB,CACA,QACC,OACA,0BACC,QAAQ,KACT,YAAY;AACV,UAAQ,IAAI,kCAAkC;AAC9C,UAAQ,KAAK,EAAE;GAElB,CACA,cAAc,GAAG,2BAA2B,CAC5C,QAAQ,CACR,MAAM;;AAIX,MAAM,aAAa,cAAc,OAAO,KAAK,IAAI;AAGjD,IACE,QAAQ,KAAK,MACb,cAAc,IAAI,IAAI,QAAQ,KAAK,IAAI,UAAU,CAAC,KAAK,WAEvD,CAAK,WAAW,CAAC,OAAO"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MessageType } from "./ai-types-
|
|
1
|
+
import { t as MessageType } from "./ai-types-B3aQaFv3.js";
|
|
2
2
|
import { PartySocket } from "partysocket";
|
|
3
3
|
|
|
4
4
|
//#region src/client.ts
|
|
@@ -113,5 +113,5 @@ function agentFetch(opts, init) {
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
//#endregion
|
|
116
|
-
export {
|
|
117
|
-
//# sourceMappingURL=client-
|
|
116
|
+
export { agentFetch as n, camelCaseToKebabCase as r, AgentClient as t };
|
|
117
|
+
//# sourceMappingURL=client-BfiZ3HQd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-
|
|
1
|
+
{"version":3,"file":"client-BfiZ3HQd.js","names":["parsedMessage: Record<string, unknown>","request: RPCRequest"],"sources":["../src/client.ts"],"sourcesContent":["import {\n type PartyFetchOptions,\n PartySocket,\n type PartySocketOptions\n} from \"partysocket\";\nimport type { RPCRequest, RPCResponse } from \"./\";\nimport type {\n SerializableReturnValue,\n SerializableValue\n} from \"./serializable\";\nimport { MessageType } from \"./ai-types\";\n\n/**\n * Options for creating an AgentClient\n */\nexport type AgentClientOptions<State = unknown> = Omit<\n PartySocketOptions,\n \"party\" | \"room\"\n> & {\n /** Name of the agent to connect to */\n agent: string;\n /** Name of the specific Agent instance */\n name?: string;\n /** Called when the Agent's state is updated */\n onStateUpdate?: (state: State, source: \"server\" | \"client\") => void;\n};\n\n/**\n * Options for streaming RPC calls\n */\nexport type StreamOptions = {\n /** Called when a chunk of data is received */\n onChunk?: (chunk: unknown) => void;\n /** Called when the stream ends */\n onDone?: (finalChunk: unknown) => void;\n /** Called when an error occurs */\n onError?: (error: string) => void;\n};\n\n/**\n * Options for the agentFetch function\n */\nexport type AgentClientFetchOptions = Omit<\n PartyFetchOptions,\n \"party\" | \"room\"\n> & {\n /** Name of the agent to connect to */\n agent: string;\n /** Name of the specific Agent instance */\n name?: string;\n};\n\n/**\n * Convert a camelCase string to a kebab-case string\n * @param str The string to convert\n * @returns The kebab-case string\n */\nexport function camelCaseToKebabCase(str: string): string {\n // If string is all uppercase, convert to lowercase\n if (str === str.toUpperCase() && str !== str.toLowerCase()) {\n return str.toLowerCase().replace(/_/g, \"-\");\n }\n\n // Otherwise handle camelCase to kebab-case\n let kebabified = str.replace(\n /[A-Z]/g,\n (letter) => `-${letter.toLowerCase()}`\n );\n kebabified = kebabified.startsWith(\"-\") ? kebabified.slice(1) : kebabified;\n // Convert any remaining underscores to hyphens and remove trailing -'s\n return kebabified.replace(/_/g, \"-\").replace(/-$/, \"\");\n}\n\n/**\n * WebSocket client for connecting to an Agent\n */\nexport class AgentClient<State = unknown> extends PartySocket {\n /**\n * @deprecated Use agentFetch instead\n */\n static fetch(_opts: PartyFetchOptions): Promise<Response> {\n throw new Error(\n \"AgentClient.fetch is not implemented, use agentFetch instead\"\n );\n }\n agent: string;\n name: string;\n private options: AgentClientOptions<State>;\n private _pendingCalls = new Map<\n string,\n {\n resolve: (value: unknown) => void;\n reject: (error: Error) => void;\n stream?: StreamOptions;\n type?: unknown;\n }\n >();\n\n constructor(options: AgentClientOptions<State>) {\n const agentNamespace = camelCaseToKebabCase(options.agent);\n super({\n party: agentNamespace,\n prefix: \"agents\",\n room: options.name || \"default\",\n ...options\n });\n this.agent = agentNamespace;\n this.name = options.name || \"default\";\n this.options = options;\n\n this.addEventListener(\"message\", (event) => {\n if (typeof event.data === \"string\") {\n let parsedMessage: Record<string, unknown>;\n try {\n parsedMessage = JSON.parse(event.data);\n } catch (_error) {\n // silently ignore invalid messages for now\n // TODO: log errors with log levels\n return;\n }\n if (parsedMessage.type === MessageType.CF_AGENT_STATE) {\n this.options.onStateUpdate?.(parsedMessage.state as State, \"server\");\n return;\n }\n if (parsedMessage.type === MessageType.RPC) {\n const response = parsedMessage as RPCResponse;\n const pending = this._pendingCalls.get(response.id);\n if (!pending) return;\n\n if (!response.success) {\n pending.reject(new Error(response.error));\n this._pendingCalls.delete(response.id);\n pending.stream?.onError?.(response.error);\n return;\n }\n\n // Handle streaming responses\n if (\"done\" in response) {\n if (response.done) {\n pending.resolve(response.result);\n this._pendingCalls.delete(response.id);\n pending.stream?.onDone?.(response.result);\n } else {\n pending.stream?.onChunk?.(response.result);\n }\n } else {\n // Non-streaming response\n pending.resolve(response.result);\n this._pendingCalls.delete(response.id);\n }\n }\n }\n });\n }\n\n setState(state: State) {\n this.send(JSON.stringify({ state, type: MessageType.CF_AGENT_STATE }));\n this.options.onStateUpdate?.(state, \"client\");\n }\n\n /**\n * Call a method on the Agent\n * @param method Name of the method to call\n * @param args Arguments to pass to the method\n * @param streamOptions Options for handling streaming responses\n * @returns Promise that resolves with the method's return value\n */\n call<T extends SerializableReturnValue>(\n method: string,\n args?: SerializableValue[],\n streamOptions?: StreamOptions\n ): Promise<T>;\n call<T = unknown>(\n method: string,\n args?: unknown[],\n streamOptions?: StreamOptions\n ): Promise<T>;\n async call<T>(\n method: string,\n args: unknown[] = [],\n streamOptions?: StreamOptions\n ): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n const id = Math.random().toString(36).slice(2);\n this._pendingCalls.set(id, {\n reject,\n resolve: (value: unknown) => resolve(value as T),\n stream: streamOptions,\n type: null as T\n });\n\n const request: RPCRequest = {\n args,\n id,\n method,\n type: MessageType.RPC\n };\n\n this.send(JSON.stringify(request));\n });\n }\n}\n\n/**\n * Make an HTTP request to an Agent\n * @param opts Connection options\n * @param init Request initialization options\n * @returns Promise resolving to a Response\n */\nexport function agentFetch(opts: AgentClientFetchOptions, init?: RequestInit) {\n const agentNamespace = camelCaseToKebabCase(opts.agent);\n\n return PartySocket.fetch(\n {\n party: agentNamespace,\n prefix: \"agents\",\n room: opts.name || \"default\",\n ...opts\n },\n init\n );\n}\n"],"mappings":";;;;;;;;;AAyDA,SAAgB,qBAAqB,KAAqB;AAExD,KAAI,QAAQ,IAAI,aAAa,IAAI,QAAQ,IAAI,aAAa,CACxD,QAAO,IAAI,aAAa,CAAC,QAAQ,MAAM,IAAI;CAI7C,IAAI,aAAa,IAAI,QACnB,WACC,WAAW,IAAI,OAAO,aAAa,GACrC;AACD,cAAa,WAAW,WAAW,IAAI,GAAG,WAAW,MAAM,EAAE,GAAG;AAEhE,QAAO,WAAW,QAAQ,MAAM,IAAI,CAAC,QAAQ,MAAM,GAAG;;;;;AAMxD,IAAa,cAAb,cAAkD,YAAY;;;;CAI5D,OAAO,MAAM,OAA6C;AACxD,QAAM,IAAI,MACR,+DACD;;CAeH,YAAY,SAAoC;EAC9C,MAAM,iBAAiB,qBAAqB,QAAQ,MAAM;AAC1D,QAAM;GACJ,OAAO;GACP,QAAQ;GACR,MAAM,QAAQ,QAAQ;GACtB,GAAG;GACJ,CAAC;uCAjBoB,IAAI,KAQzB;AAUD,OAAK,QAAQ;AACb,OAAK,OAAO,QAAQ,QAAQ;AAC5B,OAAK,UAAU;AAEf,OAAK,iBAAiB,YAAY,UAAU;AAC1C,OAAI,OAAO,MAAM,SAAS,UAAU;IAClC,IAAIA;AACJ,QAAI;AACF,qBAAgB,KAAK,MAAM,MAAM,KAAK;aAC/B,QAAQ;AAGf;;AAEF,QAAI,cAAc,SAAS,YAAY,gBAAgB;AACrD,UAAK,QAAQ,gBAAgB,cAAc,OAAgB,SAAS;AACpE;;AAEF,QAAI,cAAc,SAAS,YAAY,KAAK;KAC1C,MAAM,WAAW;KACjB,MAAM,UAAU,KAAK,cAAc,IAAI,SAAS,GAAG;AACnD,SAAI,CAAC,QAAS;AAEd,SAAI,CAAC,SAAS,SAAS;AACrB,cAAQ,OAAO,IAAI,MAAM,SAAS,MAAM,CAAC;AACzC,WAAK,cAAc,OAAO,SAAS,GAAG;AACtC,cAAQ,QAAQ,UAAU,SAAS,MAAM;AACzC;;AAIF,SAAI,UAAU,SACZ,KAAI,SAAS,MAAM;AACjB,cAAQ,QAAQ,SAAS,OAAO;AAChC,WAAK,cAAc,OAAO,SAAS,GAAG;AACtC,cAAQ,QAAQ,SAAS,SAAS,OAAO;WAEzC,SAAQ,QAAQ,UAAU,SAAS,OAAO;UAEvC;AAEL,cAAQ,QAAQ,SAAS,OAAO;AAChC,WAAK,cAAc,OAAO,SAAS,GAAG;;;;IAI5C;;CAGJ,SAAS,OAAc;AACrB,OAAK,KAAK,KAAK,UAAU;GAAE;GAAO,MAAM,YAAY;GAAgB,CAAC,CAAC;AACtE,OAAK,QAAQ,gBAAgB,OAAO,SAAS;;CAoB/C,MAAM,KACJ,QACA,OAAkB,EAAE,EACpB,eACY;AACZ,SAAO,IAAI,SAAY,SAAS,WAAW;GACzC,MAAM,KAAK,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,MAAM,EAAE;AAC9C,QAAK,cAAc,IAAI,IAAI;IACzB;IACA,UAAU,UAAmB,QAAQ,MAAW;IAChD,QAAQ;IACR,MAAM;IACP,CAAC;GAEF,MAAMC,UAAsB;IAC1B;IACA;IACA;IACA,MAAM,YAAY;IACnB;AAED,QAAK,KAAK,KAAK,UAAU,QAAQ,CAAC;IAClC;;;;;;;;;AAUN,SAAgB,WAAW,MAA+B,MAAoB;CAC5E,MAAM,iBAAiB,qBAAqB,KAAK,MAAM;AAEvD,QAAO,YAAY,MACjB;EACE,OAAO;EACP,QAAQ;EACR,MAAM,KAAK,QAAQ;EACnB,GAAG;EACJ,EACD,KACD"}
|
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
import { MCPObservabilityEvent } from "./mcp-
|
|
2
|
-
import {
|
|
1
|
+
import { t as MCPObservabilityEvent } from "./mcp-Dw5vDrY8.js";
|
|
2
|
+
import {
|
|
3
|
+
i as MCPServerRow,
|
|
4
|
+
r as MCPClientStorage,
|
|
5
|
+
t as AgentsOAuthProvider
|
|
6
|
+
} from "./do-oauth-client-provider-CcTno-25.js";
|
|
3
7
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
8
|
+
import {
|
|
9
|
+
SSEClientTransport,
|
|
10
|
+
SSEClientTransportOptions
|
|
11
|
+
} from "@modelcontextprotocol/sdk/client/sse.js";
|
|
12
|
+
import {
|
|
13
|
+
StreamableHTTPClientTransport,
|
|
14
|
+
StreamableHTTPClientTransportOptions
|
|
15
|
+
} from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
4
16
|
import {
|
|
5
17
|
CallToolRequest,
|
|
6
18
|
CallToolResultSchema,
|
|
@@ -15,14 +27,6 @@ import {
|
|
|
15
27
|
ServerCapabilities,
|
|
16
28
|
Tool
|
|
17
29
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
18
|
-
import {
|
|
19
|
-
SSEClientTransport,
|
|
20
|
-
SSEClientTransportOptions
|
|
21
|
-
} from "@modelcontextprotocol/sdk/client/sse.js";
|
|
22
|
-
import {
|
|
23
|
-
StreamableHTTPClientTransport,
|
|
24
|
-
StreamableHTTPClientTransportOptions
|
|
25
|
-
} from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
26
30
|
import * as ai0 from "ai";
|
|
27
31
|
import { ToolSet } from "ai";
|
|
28
32
|
import * as zod0 from "zod";
|
|
@@ -34,36 +38,6 @@ interface Disposable {
|
|
|
34
38
|
}
|
|
35
39
|
type Event<T> = (listener: (e: T) => void) => Disposable;
|
|
36
40
|
//#endregion
|
|
37
|
-
//#region src/mcp/sse-edge.d.ts
|
|
38
|
-
declare class SSEEdgeClientTransport extends SSEClientTransport {
|
|
39
|
-
private authProvider;
|
|
40
|
-
/**
|
|
41
|
-
* Creates a new EdgeSSEClientTransport, which overrides fetch to be compatible with the CF workers environment
|
|
42
|
-
*/
|
|
43
|
-
constructor(url: URL, options: SSEClientTransportOptions);
|
|
44
|
-
authHeaders(): Promise<
|
|
45
|
-
| {
|
|
46
|
-
Authorization: string;
|
|
47
|
-
}
|
|
48
|
-
| undefined
|
|
49
|
-
>;
|
|
50
|
-
}
|
|
51
|
-
//#endregion
|
|
52
|
-
//#region src/mcp/streamable-http-edge.d.ts
|
|
53
|
-
declare class StreamableHTTPEdgeClientTransport extends StreamableHTTPClientTransport {
|
|
54
|
-
private authProvider;
|
|
55
|
-
/**
|
|
56
|
-
* Creates a new StreamableHTTPEdgeClientTransport, which overrides fetch to be compatible with the CF workers environment
|
|
57
|
-
*/
|
|
58
|
-
constructor(url: URL, options: StreamableHTTPClientTransportOptions);
|
|
59
|
-
authHeaders(): Promise<
|
|
60
|
-
| {
|
|
61
|
-
Authorization: string;
|
|
62
|
-
}
|
|
63
|
-
| undefined
|
|
64
|
-
>;
|
|
65
|
-
}
|
|
66
|
-
//#endregion
|
|
67
41
|
//#region src/mcp/types.d.ts
|
|
68
42
|
type MaybePromise<T> = T | Promise<T>;
|
|
69
43
|
type BaseTransportType = "sse" | "streamable-http";
|
|
@@ -79,17 +53,48 @@ interface ServeOptions {
|
|
|
79
53
|
binding?: string;
|
|
80
54
|
corsOptions?: CORSOptions;
|
|
81
55
|
transport?: BaseTransportType;
|
|
56
|
+
jurisdiction?: DurableObjectJurisdiction;
|
|
82
57
|
}
|
|
83
58
|
//#endregion
|
|
84
59
|
//#region src/mcp/client-connection.d.ts
|
|
85
60
|
/**
|
|
86
|
-
* Connection state for MCP client connections
|
|
61
|
+
* Connection state machine for MCP client connections.
|
|
62
|
+
*
|
|
63
|
+
* State transitions:
|
|
64
|
+
* - Non-OAuth: init() → "connecting" → "discovering" → "ready"
|
|
65
|
+
* - OAuth: init() → "authenticating" → (callback) → "connecting" → "discovering" → "ready"
|
|
66
|
+
* - Any state can transition to "failed" on error
|
|
87
67
|
*/
|
|
88
68
|
type MCPConnectionState =
|
|
69
|
+
/**
|
|
70
|
+
* Waiting for OAuth authorization to complete.
|
|
71
|
+
* Server requires OAuth and user must complete the authorization flow.
|
|
72
|
+
* Next state: "connecting" (after handleCallbackRequest + establishConnection)
|
|
73
|
+
*/
|
|
89
74
|
| "authenticating"
|
|
75
|
+
/**
|
|
76
|
+
* Establishing transport connection to MCP server.
|
|
77
|
+
* OAuth (if required) is complete, now connecting to the actual MCP endpoint.
|
|
78
|
+
* Next state: "discovering" (after transport connected)
|
|
79
|
+
*/
|
|
90
80
|
| "connecting"
|
|
81
|
+
/**
|
|
82
|
+
* Fully connected and ready to use.
|
|
83
|
+
* Tools, resources, and prompts have been discovered and registered.
|
|
84
|
+
* This is the terminal success state.
|
|
85
|
+
*/
|
|
91
86
|
| "ready"
|
|
87
|
+
/**
|
|
88
|
+
* Discovering server capabilities (tools, resources, prompts).
|
|
89
|
+
* Transport is connected, now fetching available capabilities via MCP protocol.
|
|
90
|
+
* Next state: "ready" (after capabilities fetched)
|
|
91
|
+
*/
|
|
92
92
|
| "discovering"
|
|
93
|
+
/**
|
|
94
|
+
* Connection failed at some point.
|
|
95
|
+
* Check observability events for error details.
|
|
96
|
+
* This is a terminal error state.
|
|
97
|
+
*/
|
|
93
98
|
| "failed";
|
|
94
99
|
type MCPTransportOptions = (
|
|
95
100
|
| SSEClientTransportOptions
|
|
@@ -294,12 +299,51 @@ declare class MCPClientConnection {
|
|
|
294
299
|
*/
|
|
295
300
|
getTransport(
|
|
296
301
|
transportType: BaseTransportType
|
|
297
|
-
):
|
|
302
|
+
): SSEClientTransport | StreamableHTTPClientTransport;
|
|
298
303
|
private tryConnect;
|
|
299
304
|
private _capabilityErrorHandler;
|
|
300
305
|
}
|
|
301
306
|
//#endregion
|
|
302
307
|
//#region src/mcp/client.d.ts
|
|
308
|
+
/**
|
|
309
|
+
* Options that can be stored in the server_options column
|
|
310
|
+
* This is what gets JSON.stringify'd and stored in the database
|
|
311
|
+
*/
|
|
312
|
+
type MCPServerOptions = {
|
|
313
|
+
client?: ConstructorParameters<typeof Client>[1];
|
|
314
|
+
transport?: {
|
|
315
|
+
headers?: HeadersInit;
|
|
316
|
+
type?: TransportType;
|
|
317
|
+
};
|
|
318
|
+
};
|
|
319
|
+
/**
|
|
320
|
+
* Options for registering an MCP server
|
|
321
|
+
*/
|
|
322
|
+
type RegisterServerOptions = {
|
|
323
|
+
url: string;
|
|
324
|
+
name: string;
|
|
325
|
+
callbackUrl: string;
|
|
326
|
+
client?: ConstructorParameters<typeof Client>[1];
|
|
327
|
+
transport?: MCPTransportOptions;
|
|
328
|
+
authUrl?: string;
|
|
329
|
+
clientId?: string;
|
|
330
|
+
};
|
|
331
|
+
/**
|
|
332
|
+
* Result of attempting to connect to an MCP server.
|
|
333
|
+
* Returns the current connection state after the operation.
|
|
334
|
+
*
|
|
335
|
+
* - "ready": Connection established and ready to use (non-OAuth)
|
|
336
|
+
* - "authenticating": OAuth required, user must visit authUrl to authorize
|
|
337
|
+
*/
|
|
338
|
+
type MCPConnectionResult =
|
|
339
|
+
| {
|
|
340
|
+
state: "ready";
|
|
341
|
+
}
|
|
342
|
+
| {
|
|
343
|
+
state: "authenticating";
|
|
344
|
+
authUrl: string;
|
|
345
|
+
clientId?: string;
|
|
346
|
+
};
|
|
303
347
|
type MCPClientOAuthCallbackConfig = {
|
|
304
348
|
successRedirect?: string;
|
|
305
349
|
errorRedirect?: string;
|
|
@@ -310,6 +354,9 @@ type MCPClientOAuthResult = {
|
|
|
310
354
|
authSuccess: boolean;
|
|
311
355
|
authError?: string;
|
|
312
356
|
};
|
|
357
|
+
type MCPClientManagerOptions = {
|
|
358
|
+
storage: MCPClientStorage;
|
|
359
|
+
};
|
|
313
360
|
/**
|
|
314
361
|
* Utility class that aggregates multiple MCP clients into one
|
|
315
362
|
*/
|
|
@@ -317,27 +364,51 @@ declare class MCPClientManager {
|
|
|
317
364
|
private _name;
|
|
318
365
|
private _version;
|
|
319
366
|
mcpConnections: Record<string, MCPClientConnection>;
|
|
320
|
-
private _callbackUrls;
|
|
321
367
|
private _didWarnAboutUnstableGetAITools;
|
|
322
368
|
private _oauthCallbackConfig?;
|
|
323
369
|
private _connectionDisposables;
|
|
370
|
+
private _storage;
|
|
371
|
+
private _isRestored;
|
|
324
372
|
private readonly _onObservabilityEvent;
|
|
325
373
|
readonly onObservabilityEvent: Event<MCPObservabilityEvent>;
|
|
326
|
-
private readonly
|
|
327
|
-
|
|
374
|
+
private readonly _onServerStateChanged;
|
|
375
|
+
/**
|
|
376
|
+
* Event that fires whenever any MCP server state changes (registered, connected, removed, etc.)
|
|
377
|
+
* This is useful for broadcasting server state to clients.
|
|
378
|
+
*/
|
|
379
|
+
readonly onServerStateChanged: Event<void>;
|
|
328
380
|
/**
|
|
329
381
|
* @param _name Name of the MCP client
|
|
330
382
|
* @param _version Version of the MCP Client
|
|
331
|
-
* @param
|
|
383
|
+
* @param options Storage adapter for persisting MCP server state
|
|
332
384
|
*/
|
|
333
|
-
constructor(
|
|
385
|
+
constructor(
|
|
386
|
+
_name: string,
|
|
387
|
+
_version: string,
|
|
388
|
+
options: MCPClientManagerOptions
|
|
389
|
+
);
|
|
334
390
|
jsonSchema: typeof ai0.jsonSchema | undefined;
|
|
391
|
+
/**
|
|
392
|
+
* Create an auth provider for a server
|
|
393
|
+
* @internal
|
|
394
|
+
*/
|
|
395
|
+
private createAuthProvider;
|
|
396
|
+
/**
|
|
397
|
+
* Restore MCP server connections from storage
|
|
398
|
+
* This method is called on Agent initialization to restore previously connected servers
|
|
399
|
+
*
|
|
400
|
+
* @param clientName Name to use for OAuth client (typically the agent instance name)
|
|
401
|
+
*/
|
|
402
|
+
restoreConnectionsFromStorage(clientName: string): Promise<void>;
|
|
335
403
|
/**
|
|
336
404
|
* Connect to and register an MCP server
|
|
337
405
|
*
|
|
338
|
-
* @
|
|
339
|
-
*
|
|
340
|
-
*
|
|
406
|
+
* @deprecated This method is maintained for backward compatibility.
|
|
407
|
+
* For new code, use registerServer() and connectToServer() separately.
|
|
408
|
+
*
|
|
409
|
+
* @param url Server URL
|
|
410
|
+
* @param options Connection options
|
|
411
|
+
* @returns Object with server ID, auth URL (if OAuth), and client ID (if OAuth)
|
|
341
412
|
*/
|
|
342
413
|
connect(
|
|
343
414
|
url: string,
|
|
@@ -355,17 +426,47 @@ declare class MCPClientManager {
|
|
|
355
426
|
authUrl?: string;
|
|
356
427
|
clientId?: string;
|
|
357
428
|
}>;
|
|
358
|
-
|
|
429
|
+
/**
|
|
430
|
+
* Create an in-memory connection object and set up observability
|
|
431
|
+
* Does NOT save to storage - use registerServer() for that
|
|
432
|
+
*/
|
|
433
|
+
private createConnection;
|
|
434
|
+
/**
|
|
435
|
+
* Register an MCP server connection without connecting
|
|
436
|
+
* Creates the connection object, sets up observability, and saves to storage
|
|
437
|
+
*
|
|
438
|
+
* @param id Server ID
|
|
439
|
+
* @param options Registration options including URL, name, callback URL, and connection config
|
|
440
|
+
* @returns Server ID
|
|
441
|
+
*/
|
|
442
|
+
registerServer(id: string, options: RegisterServerOptions): Promise<string>;
|
|
443
|
+
/**
|
|
444
|
+
* Connect to an already registered MCP server and initialize the connection.
|
|
445
|
+
*
|
|
446
|
+
* For OAuth servers, this returns `{ state: "authenticating", authUrl, clientId? }`
|
|
447
|
+
* without establishing the connection. The user must complete the OAuth flow via
|
|
448
|
+
* the authUrl, which will trigger a callback handled by `handleCallbackRequest()`.
|
|
449
|
+
*
|
|
450
|
+
* For non-OAuth servers, this establishes the connection immediately and returns
|
|
451
|
+
* `{ state: "ready" }`.
|
|
452
|
+
*
|
|
453
|
+
* Updates storage with auth URL and client ID after connection.
|
|
454
|
+
*
|
|
455
|
+
* @param id Server ID (must be registered first via registerServer())
|
|
456
|
+
* @returns Connection result with current state and OAuth info (if applicable)
|
|
457
|
+
*/
|
|
458
|
+
connectToServer(id: string): Promise<MCPConnectionResult>;
|
|
459
|
+
isCallbackRequest(req: Request): Promise<boolean>;
|
|
359
460
|
handleCallbackRequest(req: Request): Promise<
|
|
360
461
|
| {
|
|
361
462
|
serverId: string;
|
|
362
463
|
authSuccess: boolean;
|
|
363
|
-
authError
|
|
464
|
+
authError: string;
|
|
364
465
|
}
|
|
365
466
|
| {
|
|
366
467
|
serverId: string;
|
|
367
468
|
authSuccess: boolean;
|
|
368
|
-
authError
|
|
469
|
+
authError?: undefined;
|
|
369
470
|
}
|
|
370
471
|
>;
|
|
371
472
|
/**
|
|
@@ -374,16 +475,6 @@ declare class MCPClientManager {
|
|
|
374
475
|
* @param serverId The server ID to establish connection for
|
|
375
476
|
*/
|
|
376
477
|
establishConnection(serverId: string): Promise<void>;
|
|
377
|
-
/**
|
|
378
|
-
* Register a callback URL for OAuth handling
|
|
379
|
-
* @param url The callback URL to register
|
|
380
|
-
*/
|
|
381
|
-
registerCallbackUrl(url: string): void;
|
|
382
|
-
/**
|
|
383
|
-
* Unregister a callback URL
|
|
384
|
-
* @param serverId The server ID whose callback URL should be removed
|
|
385
|
-
*/
|
|
386
|
-
unregisterCallbackUrl(serverId: string): void;
|
|
387
478
|
/**
|
|
388
479
|
* Configure OAuth callback handling
|
|
389
480
|
* @param config OAuth callback configuration
|
|
@@ -398,6 +489,18 @@ declare class MCPClientManager {
|
|
|
398
489
|
* @returns namespaced list of tools
|
|
399
490
|
*/
|
|
400
491
|
listTools(): NamespacedData["tools"];
|
|
492
|
+
/**
|
|
493
|
+
* Lazy-loads the jsonSchema function from the AI SDK.
|
|
494
|
+
*
|
|
495
|
+
* This defers importing the "ai" package until it's actually needed, which helps reduce
|
|
496
|
+
* initial bundle size and startup time. The jsonSchema function is required for converting
|
|
497
|
+
* MCP tools into AI SDK tool definitions via getAITools().
|
|
498
|
+
*
|
|
499
|
+
* @internal This method is for internal use only. It's automatically called before operations
|
|
500
|
+
* that need jsonSchema (like getAITools() or OAuth flows). External consumers should not need
|
|
501
|
+
* to call this directly.
|
|
502
|
+
*/
|
|
503
|
+
ensureJsonSchema(): Promise<void>;
|
|
401
504
|
/**
|
|
402
505
|
* @returns a set of tools that you can use with the AI SDK
|
|
403
506
|
*/
|
|
@@ -416,6 +519,14 @@ declare class MCPClientManager {
|
|
|
416
519
|
* @param id The id of the connection to close
|
|
417
520
|
*/
|
|
418
521
|
closeConnection(id: string): Promise<void>;
|
|
522
|
+
/**
|
|
523
|
+
* Remove an MCP server from storage
|
|
524
|
+
*/
|
|
525
|
+
removeServer(serverId: string): Promise<void>;
|
|
526
|
+
/**
|
|
527
|
+
* List all MCP servers from storage
|
|
528
|
+
*/
|
|
529
|
+
listServers(): Promise<MCPServerRow[]>;
|
|
419
530
|
/**
|
|
420
531
|
* Dispose the manager and all resources.
|
|
421
532
|
*/
|
|
@@ -5298,16 +5409,19 @@ declare function getNamespacedData<T extends keyof NamespacedData>(
|
|
|
5298
5409
|
): NamespacedData[T];
|
|
5299
5410
|
//#endregion
|
|
5300
5411
|
export {
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
|
|
5412
|
+
MCPConnectionResult as a,
|
|
5413
|
+
getNamespacedData as c,
|
|
5414
|
+
CORSOptions as d,
|
|
5415
|
+
MaybePromise as f,
|
|
5416
|
+
MCPClientOAuthResult as i,
|
|
5417
|
+
MCPConnectionState as l,
|
|
5418
|
+
TransportType as m,
|
|
5419
|
+
MCPClientManagerOptions as n,
|
|
5420
|
+
MCPServerOptions as o,
|
|
5421
|
+
ServeOptions as p,
|
|
5422
|
+
MCPClientOAuthCallbackConfig as r,
|
|
5423
|
+
RegisterServerOptions as s,
|
|
5424
|
+
MCPClientManager as t,
|
|
5425
|
+
BaseTransportType as u
|
|
5312
5426
|
};
|
|
5313
|
-
//# sourceMappingURL=client-
|
|
5427
|
+
//# sourceMappingURL=client-Bws9q38u.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./serializable-
|
|
2
|
+
i as SerializableValue,
|
|
3
|
+
r as SerializableReturnValue
|
|
4
|
+
} from "./serializable-CymX8ovI.js";
|
|
5
5
|
import {
|
|
6
6
|
PartyFetchOptions,
|
|
7
7
|
PartySocket,
|
|
@@ -94,11 +94,11 @@ declare function agentFetch(
|
|
|
94
94
|
): Promise<Response>;
|
|
95
95
|
//#endregion
|
|
96
96
|
export {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
agentFetch as a,
|
|
98
|
+
StreamOptions as i,
|
|
99
|
+
AgentClientFetchOptions as n,
|
|
100
|
+
camelCaseToKebabCase as o,
|
|
101
|
+
AgentClientOptions as r,
|
|
102
|
+
AgentClient as t
|
|
103
103
|
};
|
|
104
|
-
//# sourceMappingURL=client-
|
|
104
|
+
//# sourceMappingURL=client-CbWe9FBd.d.ts.map
|