agents 0.0.0-1057c94 → 0.0.0-10d453d

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 (62) hide show
  1. package/README.md +5 -3
  2. package/dist/ai-chat-agent.d.ts +94 -13
  3. package/dist/ai-chat-agent.js +346 -74
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/{ai-chat-v5-migration-gdyLiTd8.js → ai-chat-v5-migration-BSiGZmYU.js} +2 -2
  6. package/dist/{ai-chat-v5-migration-gdyLiTd8.js.map → ai-chat-v5-migration-BSiGZmYU.js.map} +1 -1
  7. package/dist/ai-chat-v5-migration.js +1 -1
  8. package/dist/ai-react.d.ts +14 -9
  9. package/dist/ai-react.js +179 -29
  10. package/dist/ai-react.js.map +1 -1
  11. package/dist/{ai-types-BWW4umHY.d.ts → ai-types-81H_-Uxh.d.ts} +16 -8
  12. package/dist/{ai-types-UZlfLOYP.js → ai-types-CrMqkwc_.js} +6 -2
  13. package/dist/ai-types-CrMqkwc_.js.map +1 -0
  14. package/dist/ai-types.d.ts +4 -4
  15. package/dist/ai-types.js +1 -1
  16. package/dist/cli/index.d.ts +1 -0
  17. package/dist/cli/index.js +28 -0
  18. package/dist/cli/index.js.map +1 -0
  19. package/dist/{client-DjR-lC16.js → client-B3SR12TQ.js} +3 -3
  20. package/dist/{client-DjR-lC16.js.map → client-B3SR12TQ.js.map} +1 -1
  21. package/dist/{client-CmMi85Sj.d.ts → client-BAQA84dr.d.ts} +10 -10
  22. package/dist/client-BqdCHvCQ.js +1105 -0
  23. package/dist/client-BqdCHvCQ.js.map +1 -0
  24. package/dist/client-fv1aMi-q.d.ts +834 -0
  25. package/dist/client.d.ts +8 -8
  26. package/dist/client.js +2 -2
  27. package/dist/codemode/ai.js +5 -5
  28. package/dist/{do-oauth-client-provider-CCwGwnrA.d.ts → do-oauth-client-provider-CJ9YuMVT.d.ts} +21 -6
  29. package/dist/{do-oauth-client-provider-B2jr6UNq.js → do-oauth-client-provider-CnDheVho.js} +71 -9
  30. package/dist/do-oauth-client-provider-CnDheVho.js.map +1 -0
  31. package/dist/{index-CEqvuT_e.d.ts → index-8Iyg9pLA.d.ts} +77 -226
  32. package/dist/{index-W4JUkafc.d.ts → index-BUle9RiP.d.ts} +7 -3
  33. package/dist/index.d.ts +36 -50
  34. package/dist/index.js +6 -6
  35. package/dist/mcp/client.d.ts +4 -4
  36. package/dist/mcp/client.js +2 -1
  37. package/dist/mcp/do-oauth-client-provider.d.ts +1 -1
  38. package/dist/mcp/do-oauth-client-provider.js +1 -1
  39. package/dist/mcp/index.d.ts +193 -7
  40. package/dist/mcp/index.js +1446 -6
  41. package/dist/mcp/index.js.map +1 -0
  42. package/dist/mcp/x402.js +10 -6
  43. package/dist/mcp/x402.js.map +1 -1
  44. package/dist/{mcp-BEwaCsxO.d.ts → mcp-BwPscEiF.d.ts} +2 -2
  45. package/dist/observability/index.d.ts +2 -2
  46. package/dist/observability/index.js +5 -5
  47. package/dist/{react-CesuHpFV.d.ts → react-UBqSl5O8.d.ts} +17 -17
  48. package/dist/react.d.ts +9 -9
  49. package/dist/react.js +2 -2
  50. package/dist/react.js.map +1 -1
  51. package/dist/{serializable-gtr9YMhp.d.ts → serializable-faDkMCai.d.ts} +8 -3
  52. package/dist/serializable.d.ts +5 -5
  53. package/dist/src-DYN-ccro.js +1182 -0
  54. package/dist/src-DYN-ccro.js.map +1 -0
  55. package/package.json +53 -38
  56. package/dist/ai-types-UZlfLOYP.js.map +0 -1
  57. package/dist/client-CZBVDDoO.js +0 -786
  58. package/dist/client-CZBVDDoO.js.map +0 -1
  59. package/dist/client-rqBi9hbh.d.ts +0 -5313
  60. package/dist/do-oauth-client-provider-B2jr6UNq.js.map +0 -1
  61. package/dist/src-tpG9NtHy.js +0 -2457
  62. package/dist/src-tpG9NtHy.js.map +0 -1
package/dist/client.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import "./serializable-gtr9YMhp.js";
1
+ import "./serializable-faDkMCai.js";
2
2
  import {
3
- AgentClient,
4
- AgentClientFetchOptions,
5
- AgentClientOptions,
6
- StreamOptions,
7
- agentFetch,
8
- camelCaseToKebabCase
9
- } from "./client-CmMi85Sj.js";
3
+ a as agentFetch,
4
+ i as StreamOptions,
5
+ n as AgentClientFetchOptions,
6
+ o as camelCaseToKebabCase,
7
+ r as AgentClientOptions,
8
+ t as AgentClient
9
+ } from "./client-BAQA84dr.js";
10
10
  export {
11
11
  AgentClient,
12
12
  AgentClientFetchOptions,
package/dist/client.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./ai-types-UZlfLOYP.js";
2
- import { AgentClient, agentFetch, camelCaseToKebabCase } from "./client-DjR-lC16.js";
1
+ import "./ai-types-CrMqkwc_.js";
2
+ import { n as agentFetch, r as camelCaseToKebabCase, t as AgentClient } from "./client-B3SR12TQ.js";
3
3
 
4
4
  export { AgentClient, agentFetch, camelCaseToKebabCase };
@@ -1,8 +1,8 @@
1
- import "../ai-types-UZlfLOYP.js";
2
- import "../client-DjR-lC16.js";
3
- import "../client-CZBVDDoO.js";
4
- import "../do-oauth-client-provider-B2jr6UNq.js";
5
- import { getAgentByName } from "../src-tpG9NtHy.js";
1
+ import "../ai-types-CrMqkwc_.js";
2
+ import "../client-B3SR12TQ.js";
3
+ import "../client-BqdCHvCQ.js";
4
+ import "../do-oauth-client-provider-CnDheVho.js";
5
+ import { s as getAgentByName } from "../src-DYN-ccro.js";
6
6
  import { generateObject, tool } from "ai";
7
7
  import { openai } from "@ai-sdk/openai";
8
8
  import { z } from "zod/v3";
@@ -11,6 +11,13 @@ interface AgentsOAuthProvider extends OAuthClientProvider {
11
11
  authUrl: string | undefined;
12
12
  clientId: string | undefined;
13
13
  serverId: string | undefined;
14
+ checkState(state: string): Promise<{
15
+ valid: boolean;
16
+ serverId?: string;
17
+ error?: string;
18
+ }>;
19
+ consumeState(state: string): Promise<void>;
20
+ deleteCodeVerifier(): Promise<void>;
14
21
  }
15
22
  declare class DurableObjectOAuthClientProvider implements AgentsOAuthProvider {
16
23
  storage: DurableObjectStorage;
@@ -41,15 +48,23 @@ declare class DurableObjectOAuthClientProvider implements AgentsOAuthProvider {
41
48
  tokens(): Promise<OAuthTokens | undefined>;
42
49
  saveTokens(tokens: OAuthTokens): Promise<void>;
43
50
  get authUrl(): string | undefined;
44
- /**
45
- * Because this operates on the server side (but we need browser auth), we send this url back to the user
46
- * and require user interact to initiate the redirect flow
47
- */
51
+ stateKey(nonce: string): string;
52
+ state(): Promise<string>;
53
+ checkState(state: string): Promise<{
54
+ valid: boolean;
55
+ serverId?: string;
56
+ error?: string;
57
+ }>;
58
+ consumeState(state: string): Promise<void>;
48
59
  redirectToAuthorization(authUrl: URL): Promise<void>;
60
+ invalidateCredentials(
61
+ scope: "all" | "client" | "tokens" | "verifier"
62
+ ): Promise<void>;
49
63
  codeVerifierKey(clientId: string): string;
50
64
  saveCodeVerifier(verifier: string): Promise<void>;
51
65
  codeVerifier(): Promise<string>;
66
+ deleteCodeVerifier(): Promise<void>;
52
67
  }
53
68
  //#endregion
54
- export { AgentsOAuthProvider, DurableObjectOAuthClientProvider };
55
- //# sourceMappingURL=do-oauth-client-provider-CCwGwnrA.d.ts.map
69
+ export { DurableObjectOAuthClientProvider as n, AgentsOAuthProvider as t };
70
+ //# sourceMappingURL=do-oauth-client-provider-CJ9YuMVT.d.ts.map
@@ -1,11 +1,13 @@
1
1
  import { nanoid } from "nanoid";
2
2
 
3
3
  //#region src/mcp/do-oauth-client-provider.ts
4
+ const STATE_EXPIRATION_MS = 600 * 1e3;
4
5
  var DurableObjectOAuthClientProvider = class {
5
6
  constructor(storage, clientName, baseRedirectUrl) {
6
7
  this.storage = storage;
7
8
  this.clientName = clientName;
8
9
  this.baseRedirectUrl = baseRedirectUrl;
10
+ if (!storage) throw new Error("DurableObjectOAuthClientProvider requires a valid DurableObjectStorage instance");
9
11
  }
10
12
  get clientMetadata() {
11
13
  return {
@@ -21,7 +23,7 @@ var DurableObjectOAuthClientProvider = class {
21
23
  return new URL(this.redirectUrl).origin;
22
24
  }
23
25
  get redirectUrl() {
24
- return `${this.baseRedirectUrl}/${this.serverId}`;
26
+ return this.baseRedirectUrl;
25
27
  }
26
28
  get clientId() {
27
29
  if (!this._clientId_) throw new Error("Trying to access clientId before it was set");
@@ -64,15 +66,72 @@ var DurableObjectOAuthClientProvider = class {
64
66
  get authUrl() {
65
67
  return this._authUrl_;
66
68
  }
67
- /**
68
- * Because this operates on the server side (but we need browser auth), we send this url back to the user
69
- * and require user interact to initiate the redirect flow
70
- */
69
+ stateKey(nonce) {
70
+ return `/${this.clientName}/${this.serverId}/state/${nonce}`;
71
+ }
72
+ async state() {
73
+ const nonce = nanoid();
74
+ const state = `${nonce}.${this.serverId}`;
75
+ const storedState = {
76
+ nonce,
77
+ serverId: this.serverId,
78
+ createdAt: Date.now()
79
+ };
80
+ await this.storage.put(this.stateKey(nonce), storedState);
81
+ return state;
82
+ }
83
+ async checkState(state) {
84
+ const parts = state.split(".");
85
+ if (parts.length !== 2) return {
86
+ valid: false,
87
+ error: "Invalid state format"
88
+ };
89
+ const [nonce, serverId] = parts;
90
+ const key = this.stateKey(nonce);
91
+ const storedState = await this.storage.get(key);
92
+ if (!storedState) return {
93
+ valid: false,
94
+ error: "State not found or already used"
95
+ };
96
+ if (storedState.serverId !== serverId) {
97
+ await this.storage.delete(key);
98
+ return {
99
+ valid: false,
100
+ error: "State serverId mismatch"
101
+ };
102
+ }
103
+ if (Date.now() - storedState.createdAt > STATE_EXPIRATION_MS) {
104
+ await this.storage.delete(key);
105
+ return {
106
+ valid: false,
107
+ error: "State expired"
108
+ };
109
+ }
110
+ return {
111
+ valid: true,
112
+ serverId
113
+ };
114
+ }
115
+ async consumeState(state) {
116
+ const parts = state.split(".");
117
+ if (parts.length !== 2) {
118
+ console.warn(`[OAuth] consumeState called with invalid state format: ${state.substring(0, 20)}...`);
119
+ return;
120
+ }
121
+ const [nonce] = parts;
122
+ await this.storage.delete(this.stateKey(nonce));
123
+ }
71
124
  async redirectToAuthorization(authUrl) {
72
- const stateToken = nanoid();
73
- authUrl.searchParams.set("state", stateToken);
74
125
  this._authUrl_ = authUrl.toString();
75
126
  }
127
+ async invalidateCredentials(scope) {
128
+ if (!this._clientId_) return;
129
+ const deleteKeys = [];
130
+ if (scope === "all" || scope === "client") deleteKeys.push(this.clientInfoKey(this.clientId));
131
+ if (scope === "all" || scope === "tokens") deleteKeys.push(this.tokenKey(this.clientId));
132
+ if (scope === "all" || scope === "verifier") deleteKeys.push(this.codeVerifierKey(this.clientId));
133
+ if (deleteKeys.length > 0) await this.storage.delete(deleteKeys);
134
+ }
76
135
  codeVerifierKey(clientId) {
77
136
  return `${this.keyPrefix(clientId)}/code_verifier`;
78
137
  }
@@ -86,8 +145,11 @@ var DurableObjectOAuthClientProvider = class {
86
145
  if (!codeVerifier) throw new Error("No code verifier found");
87
146
  return codeVerifier;
88
147
  }
148
+ async deleteCodeVerifier() {
149
+ await this.storage.delete(this.codeVerifierKey(this.clientId));
150
+ }
89
151
  };
90
152
 
91
153
  //#endregion
92
- export { DurableObjectOAuthClientProvider };
93
- //# sourceMappingURL=do-oauth-client-provider-B2jr6UNq.js.map
154
+ export { DurableObjectOAuthClientProvider as t };
155
+ //# sourceMappingURL=do-oauth-client-provider-CnDheVho.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"do-oauth-client-provider-CnDheVho.js","names":["storage: DurableObjectStorage","clientName: string","baseRedirectUrl: string","storedState: StoredState","deleteKeys: string[]"],"sources":["../src/mcp/do-oauth-client-provider.ts"],"sourcesContent":["import type { OAuthClientProvider } from \"@modelcontextprotocol/sdk/client/auth.js\";\nimport type {\n OAuthClientInformation,\n OAuthClientInformationFull,\n OAuthClientMetadata,\n OAuthTokens\n} from \"@modelcontextprotocol/sdk/shared/auth.js\";\nimport { nanoid } from \"nanoid\";\n\nconst STATE_EXPIRATION_MS = 10 * 60 * 1000; // 10 minutes\n\ninterface StoredState {\n nonce: string;\n serverId: string;\n createdAt: number;\n}\n\n// A slight extension to the standard OAuthClientProvider interface because `redirectToAuthorization` doesn't give us the interface we need\n// This allows us to track authentication for a specific server and associated dynamic client registration\nexport interface AgentsOAuthProvider extends OAuthClientProvider {\n authUrl: string | undefined;\n clientId: string | undefined;\n serverId: string | undefined;\n checkState(\n state: string\n ): Promise<{ valid: boolean; serverId?: string; error?: string }>;\n consumeState(state: string): Promise<void>;\n deleteCodeVerifier(): Promise<void>;\n}\n\nexport class DurableObjectOAuthClientProvider implements AgentsOAuthProvider {\n private _authUrl_: string | undefined;\n private _serverId_: string | undefined;\n private _clientId_: string | undefined;\n\n constructor(\n public storage: DurableObjectStorage,\n public clientName: string,\n public baseRedirectUrl: string\n ) {\n if (!storage) {\n throw new Error(\n \"DurableObjectOAuthClientProvider requires a valid DurableObjectStorage instance\"\n );\n }\n }\n\n get clientMetadata(): OAuthClientMetadata {\n return {\n client_name: this.clientName,\n client_uri: this.clientUri,\n grant_types: [\"authorization_code\", \"refresh_token\"],\n redirect_uris: [this.redirectUrl],\n response_types: [\"code\"],\n token_endpoint_auth_method: \"none\"\n };\n }\n\n get clientUri() {\n return new URL(this.redirectUrl).origin;\n }\n\n get redirectUrl() {\n return this.baseRedirectUrl;\n }\n\n get clientId() {\n if (!this._clientId_) {\n throw new Error(\"Trying to access clientId before it was set\");\n }\n return this._clientId_;\n }\n\n set clientId(clientId_: string) {\n this._clientId_ = clientId_;\n }\n\n get serverId() {\n if (!this._serverId_) {\n throw new Error(\"Trying to access serverId before it was set\");\n }\n return this._serverId_;\n }\n\n set serverId(serverId_: string) {\n this._serverId_ = serverId_;\n }\n\n keyPrefix(clientId: string) {\n return `/${this.clientName}/${this.serverId}/${clientId}`;\n }\n\n clientInfoKey(clientId: string) {\n return `${this.keyPrefix(clientId)}/client_info/`;\n }\n\n async clientInformation(): Promise<OAuthClientInformation | undefined> {\n if (!this._clientId_) {\n return undefined;\n }\n return (\n (await this.storage.get<OAuthClientInformation>(\n this.clientInfoKey(this.clientId)\n )) ?? undefined\n );\n }\n\n async saveClientInformation(\n clientInformation: OAuthClientInformationFull\n ): Promise<void> {\n await this.storage.put(\n this.clientInfoKey(clientInformation.client_id),\n clientInformation\n );\n this.clientId = clientInformation.client_id;\n }\n\n tokenKey(clientId: string) {\n return `${this.keyPrefix(clientId)}/token`;\n }\n\n async tokens(): Promise<OAuthTokens | undefined> {\n if (!this._clientId_) {\n return undefined;\n }\n return (\n (await this.storage.get<OAuthTokens>(this.tokenKey(this.clientId))) ??\n undefined\n );\n }\n\n async saveTokens(tokens: OAuthTokens): Promise<void> {\n await this.storage.put(this.tokenKey(this.clientId), tokens);\n }\n\n get authUrl() {\n return this._authUrl_;\n }\n\n stateKey(nonce: string) {\n return `/${this.clientName}/${this.serverId}/state/${nonce}`;\n }\n\n async state(): Promise<string> {\n const nonce = nanoid();\n const state = `${nonce}.${this.serverId}`;\n const storedState: StoredState = {\n nonce,\n serverId: this.serverId,\n createdAt: Date.now()\n };\n await this.storage.put(this.stateKey(nonce), storedState);\n return state;\n }\n\n async checkState(\n state: string\n ): Promise<{ valid: boolean; serverId?: string; error?: string }> {\n const parts = state.split(\".\");\n if (parts.length !== 2) {\n return { valid: false, error: \"Invalid state format\" };\n }\n\n const [nonce, serverId] = parts;\n const key = this.stateKey(nonce);\n const storedState = await this.storage.get<StoredState>(key);\n\n if (!storedState) {\n return { valid: false, error: \"State not found or already used\" };\n }\n\n if (storedState.serverId !== serverId) {\n await this.storage.delete(key);\n return { valid: false, error: \"State serverId mismatch\" };\n }\n\n const age = Date.now() - storedState.createdAt;\n if (age > STATE_EXPIRATION_MS) {\n await this.storage.delete(key);\n return { valid: false, error: \"State expired\" };\n }\n\n return { valid: true, serverId };\n }\n\n async consumeState(state: string): Promise<void> {\n const parts = state.split(\".\");\n if (parts.length !== 2) {\n // This should never happen since checkState validates format first.\n // Log for debugging but don't throw - state consumption is best-effort.\n console.warn(\n `[OAuth] consumeState called with invalid state format: ${state.substring(0, 20)}...`\n );\n return;\n }\n const [nonce] = parts;\n await this.storage.delete(this.stateKey(nonce));\n }\n\n async redirectToAuthorization(authUrl: URL): Promise<void> {\n this._authUrl_ = authUrl.toString();\n }\n\n async invalidateCredentials(\n scope: \"all\" | \"client\" | \"tokens\" | \"verifier\"\n ): Promise<void> {\n if (!this._clientId_) return;\n\n const deleteKeys: string[] = [];\n\n if (scope === \"all\" || scope === \"client\") {\n deleteKeys.push(this.clientInfoKey(this.clientId));\n }\n if (scope === \"all\" || scope === \"tokens\") {\n deleteKeys.push(this.tokenKey(this.clientId));\n }\n if (scope === \"all\" || scope === \"verifier\") {\n deleteKeys.push(this.codeVerifierKey(this.clientId));\n }\n\n if (deleteKeys.length > 0) {\n await this.storage.delete(deleteKeys);\n }\n }\n\n codeVerifierKey(clientId: string) {\n return `${this.keyPrefix(clientId)}/code_verifier`;\n }\n\n async saveCodeVerifier(verifier: string): Promise<void> {\n const key = this.codeVerifierKey(this.clientId);\n\n // Don't overwrite existing verifier to preserve first PKCE verifier\n const existing = await this.storage.get<string>(key);\n if (existing) {\n return;\n }\n\n await this.storage.put(key, verifier);\n }\n\n async codeVerifier(): Promise<string> {\n const codeVerifier = await this.storage.get<string>(\n this.codeVerifierKey(this.clientId)\n );\n if (!codeVerifier) {\n throw new Error(\"No code verifier found\");\n }\n return codeVerifier;\n }\n\n async deleteCodeVerifier(): Promise<void> {\n await this.storage.delete(this.codeVerifierKey(this.clientId));\n }\n}\n"],"mappings":";;;AASA,MAAM,sBAAsB,MAAU;AAqBtC,IAAa,mCAAb,MAA6E;CAK3E,YACE,AAAOA,SACP,AAAOC,YACP,AAAOC,iBACP;EAHO;EACA;EACA;AAEP,MAAI,CAAC,QACH,OAAM,IAAI,MACR,kFACD;;CAIL,IAAI,iBAAsC;AACxC,SAAO;GACL,aAAa,KAAK;GAClB,YAAY,KAAK;GACjB,aAAa,CAAC,sBAAsB,gBAAgB;GACpD,eAAe,CAAC,KAAK,YAAY;GACjC,gBAAgB,CAAC,OAAO;GACxB,4BAA4B;GAC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AS,CAAC;AAEpD,MAAI,UAAU,SAAS,UAAU,SAC/B,YAAW,KAAK,KAAK,SAAS,KAAK,SAAS,CAAC;AAE/C,MAAI,UAAU,SAAS,UAAU,WAC/B,YAAW,KAAK,KAAK,gBAAgB,KAAK,SAAS,CAAC;AAGtD,MAAI,WAAW,SAAS,EACtB,OAAM,KAAK,QAAQ,OAAO,WAAW;;CAIzC,gBAAgB,UAAkB;AAChC,SAAO,GAAG,KAAK,UAAU,SAAS,CAAC;;CAGrC,MAAM,iBAAiB,UAAiC;EACtD,MAAM,MAAM,KAAK,gBAAgB,KAAK,SAAS;AAI/C,MADiB,MAAM,KAAK,QAAQ,IAAY,IAAI,CAElD;AAGF,QAAM,KAAK,QAAQ,IAAI,KAAK,SAAS;;CAGvC,MAAM,eAAgC;EACpC,MAAM,eAAe,MAAM,KAAK,QAAQ,IACtC,KAAK,gBAAgB,KAAK,SAAS,CACpC;AACD,MAAI,CAAC,aACH,OAAM,IAAI,MAAM,yBAAyB;AAE3C,SAAO;;CAGT,MAAM,qBAAoC;AACxC,QAAM,KAAK,QAAQ,OAAO,KAAK,gBAAgB,KAAK,SAAS,CAAC"}
@@ -1,13 +1,10 @@
1
1
  import {
2
- BaseTransportType,
3
- MCPClientManager,
4
- MCPConnectionState,
5
- MaybePromise,
6
- ServeOptions,
7
- TransportType
8
- } from "./client-rqBi9hbh.js";
9
- import { Observability } from "./index-W4JUkafc.js";
10
- import { MessageType } from "./ai-types-BWW4umHY.js";
2
+ h as TransportType,
3
+ t as MCPClientManager,
4
+ u as MCPConnectionState
5
+ } from "./client-fv1aMi-q.js";
6
+ import { t as Observability } from "./index-BUle9RiP.js";
7
+ import { n as MessageType } from "./ai-types-81H_-Uxh.js";
11
8
  import {
12
9
  Connection,
13
10
  Connection as Connection$1,
@@ -18,169 +15,15 @@ import {
18
15
  } from "partyserver";
19
16
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
20
17
  import {
21
- ElicitRequest as ElicitRequest$1,
22
- ElicitRequestSchema as ElicitRequestSchema$1,
23
- ElicitResult,
24
- ElicitResult as ElicitResult$1,
25
- JSONRPCMessage,
26
18
  Prompt,
27
19
  Resource,
28
20
  ServerCapabilities,
29
21
  Tool
30
22
  } from "@modelcontextprotocol/sdk/types.js";
31
23
  import { env } from "cloudflare:workers";
32
- import { Server as Server$1 } from "@modelcontextprotocol/sdk/server/index.js";
33
- import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
34
- import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
35
24
 
36
- //#region src/mcp/worker-transport.d.ts
37
- interface WorkerTransportOptions {
38
- sessionIdGenerator?: () => string;
39
- enableJsonResponse?: boolean;
40
- onsessioninitialized?: (sessionId: string) => void;
41
- }
42
- declare class WorkerTransport implements Transport {
43
- private started;
44
- private initialized;
45
- private sessionIdGenerator?;
46
- private enableJsonResponse;
47
- private onsessioninitialized?;
48
- private standaloneSseStreamId;
49
- private streamMapping;
50
- private requestToStreamMapping;
51
- private requestResponseMap;
52
- sessionId?: string;
53
- onclose?: () => void;
54
- onerror?: (error: Error) => void;
55
- onmessage?: (message: JSONRPCMessage) => void;
56
- constructor(options?: WorkerTransportOptions);
57
- start(): Promise<void>;
58
- handleRequest(request: Request, parsedBody?: unknown): Promise<Response>;
59
- private handleGetRequest;
60
- private handlePostRequest;
61
- private handleDeleteRequest;
62
- private handleOptionsRequest;
63
- private handleUnsupportedRequest;
64
- private validateSession;
65
- close(): Promise<void>;
66
- send(message: JSONRPCMessage): Promise<void>;
67
- }
68
- //#endregion
69
- //#region src/mcp/handler.d.ts
70
- interface CreateMcpHandlerOptions extends WorkerTransportOptions {
71
- /**
72
- * The route path that this MCP handler should respond to.
73
- * If specified, the handler will only process requests that match this route.
74
- * @default "/mcp"
75
- */
76
- route?: string;
77
- }
78
- type OAuthExecutionContext = ExecutionContext & {
79
- props?: Record<string, unknown>;
80
- };
81
- declare function experimental_createMcpHandler(
82
- server: McpServer | Server$1,
83
- options?: CreateMcpHandlerOptions
84
- ): (request: Request, env: unknown, ctx: ExecutionContext) => Promise<Response>;
85
- //#endregion
86
- //#region src/mcp/auth-context.d.ts
87
- interface McpAuthContext {
88
- props: Record<string, unknown>;
89
- }
90
- declare function getMcpAuthContext(): McpAuthContext | undefined;
91
- //#endregion
92
- //#region src/mcp/index.d.ts
93
- declare abstract class McpAgent<
94
- Env = unknown,
95
- State = unknown,
96
- Props extends Record<string, unknown> = Record<string, unknown>
97
- > extends Agent<Env, State, Props> {
98
- private _transport?;
99
- props?: Props;
100
- abstract server: MaybePromise<McpServer | Server$1>;
101
- abstract init(): Promise<void>;
102
- setInitializeRequest(initializeRequest: JSONRPCMessage): Promise<void>;
103
- getInitializeRequest(): Promise<JSONRPCMessage | undefined>;
104
- /** Read the transport type for this agent.
105
- * This relies on the naming scheme being `sse:${sessionId}`
106
- * or `streamable-http:${sessionId}`.
107
- */
108
- getTransportType(): BaseTransportType;
109
- /** Read the sessionId for this agent.
110
- * This relies on the naming scheme being `sse:${sessionId}`
111
- * or `streamable-http:${sessionId}`.
112
- */
113
- getSessionId(): string;
114
- /** Get the unique WebSocket. SSE transport only. */
115
- private getWebSocket;
116
- /** Returns a new transport matching the type of the Agent. */
117
- private initTransport;
118
- /** Update and store the props */
119
- updateProps(props?: Props): Promise<void>;
120
- reinitializeServer(): Promise<void>;
121
- /** Sets up the MCP transport and server every time the Agent is started.*/
122
- onStart(props?: Props): Promise<void>;
123
- /** Validates new WebSocket connections. */
124
- onConnect(
125
- conn: Connection$1,
126
- { request: req }: ConnectionContext
127
- ): Promise<void>;
128
- /** Handles MCP Messages for the legacy SSE transport. */
129
- onSSEMcpMessage(
130
- _sessionId: string,
131
- messageBody: unknown
132
- ): Promise<Error | null>;
133
- /** Elicit user input with a message and schema */
134
- elicitInput(params: {
135
- message: string;
136
- requestedSchema: unknown;
137
- }): Promise<ElicitResult>;
138
- /** Wait for elicitation response through storage polling */
139
- private _waitForElicitationResponse;
140
- /** Handle elicitation responses */
141
- private _handleElicitationResponse;
142
- /** Return a handler for the given path for this MCP.
143
- * Defaults to Streamable HTTP transport.
144
- */
145
- static serve(
146
- path: string,
147
- { binding, corsOptions, transport }?: ServeOptions
148
- ): {
149
- fetch<Env>(
150
- this: void,
151
- request: Request,
152
- env: Env,
153
- ctx: ExecutionContext
154
- ): Promise<Response>;
155
- };
156
- /**
157
- * Legacy api
158
- **/
159
- static mount(
160
- path: string,
161
- opts?: Omit<ServeOptions, "transport">
162
- ): {
163
- fetch<Env>(
164
- this: void,
165
- request: Request,
166
- env: Env,
167
- ctx: ExecutionContext
168
- ): Promise<Response>;
169
- };
170
- static serveSSE(
171
- path: string,
172
- opts?: Omit<ServeOptions, "transport">
173
- ): {
174
- fetch<Env>(
175
- this: void,
176
- request: Request,
177
- env: Env,
178
- ctx: ExecutionContext
179
- ): Promise<Response>;
180
- };
181
- }
182
- //#endregion
183
25
  //#region src/index.d.ts
26
+
184
27
  /**
185
28
  * RPC request message from client
186
29
  */
@@ -296,9 +139,15 @@ type MCPServersState = {
296
139
  servers: {
297
140
  [id: string]: MCPServer;
298
141
  };
299
- tools: Tool[];
300
- prompts: Prompt[];
301
- resources: Resource[];
142
+ tools: (Tool & {
143
+ serverId: string;
144
+ })[];
145
+ prompts: (Prompt & {
146
+ serverId: string;
147
+ })[];
148
+ resources: (Resource & {
149
+ serverId: string;
150
+ })[];
302
151
  };
303
152
  type MCPServer = {
304
153
  name: string;
@@ -328,6 +177,7 @@ declare class Agent<
328
177
  > extends Server<Env, Props> {
329
178
  private _state;
330
179
  private _disposables;
180
+ private _destroyed;
331
181
  private _ParentClass;
332
182
  readonly mcp: MCPClientManager;
333
183
  /**
@@ -481,7 +331,7 @@ declare class Agent<
481
331
  /**
482
332
  * Cancel a scheduled task
483
333
  * @param id ID of the task to cancel
484
- * @returns true if the task was cancelled, false otherwise
334
+ * @returns true if the task was cancelled, false if the task was not found
485
335
  */
486
336
  cancelSchedule(id: string): Promise<boolean>;
487
337
  private _scheduleNextAlarm;
@@ -511,7 +361,8 @@ declare class Agent<
511
361
  * @param callbackHost Base host for the agent, used for the redirect URI. If not provided, will be derived from the current request.
512
362
  * @param agentsPrefix agents routing prefix if not using `agents`
513
363
  * @param options MCP client and transport options
514
- * @returns authUrl
364
+ * @returns Server id and state - either "authenticating" with authUrl, or "ready"
365
+ * @throws If connection or discovery fails
515
366
  */
516
367
  addMcpServer(
517
368
  serverName: string,
@@ -525,24 +376,35 @@ declare class Agent<
525
376
  type?: TransportType;
526
377
  };
527
378
  }
528
- ): Promise<{
529
- id: string;
530
- authUrl: string | undefined;
531
- }>;
532
- /**
533
- * Handle potential OAuth callback requests after DO hibernation.
534
- * Detects OAuth callbacks, restores state from database, and processes the callback.
535
- * Returns a Response if this was an OAuth callback, otherwise returns undefined.
536
- */
537
- private _handlePotentialOAuthCallback;
538
- /**
539
- * Process an OAuth callback request (assumes state is already restored)
540
- */
541
- private _processOAuthCallback;
542
- private _connectToMcpServerInternal;
379
+ ): Promise<
380
+ | {
381
+ id: string;
382
+ state: typeof MCPConnectionState.AUTHENTICATING;
383
+ authUrl: string;
384
+ }
385
+ | {
386
+ id: string;
387
+ state: typeof MCPConnectionState.READY;
388
+ authUrl?: undefined;
389
+ }
390
+ >;
543
391
  removeMcpServer(id: string): Promise<void>;
544
392
  getMcpServers(): MCPServersState;
545
393
  private broadcastMcpServers;
394
+ /**
395
+ * Handle MCP OAuth callback request if it's an OAuth callback.
396
+ *
397
+ * This method encapsulates the entire OAuth callback flow:
398
+ * 1. Checks if the request is an MCP OAuth callback
399
+ * 2. Processes the OAuth code exchange
400
+ * 3. Establishes the connection if successful
401
+ * 4. Broadcasts MCP server state updates
402
+ * 5. Returns the appropriate HTTP response
403
+ *
404
+ * @param request The incoming HTTP request
405
+ * @returns Response if this was an OAuth callback, null otherwise
406
+ */
407
+ private handleMcpOAuthCallback;
546
408
  /**
547
409
  * Handle OAuth callback response using MCPClientManager configuration
548
410
  * @param result OAuth callback result
@@ -691,46 +553,35 @@ declare class StreamingResponse {
691
553
  }
692
554
  //#endregion
693
555
  export {
694
- Agent,
695
- AgentContext,
696
- AgentEmail,
697
- AgentNamespace,
698
- AgentOptions,
699
- CallableMetadata,
700
- type Connection$1 as Connection,
701
- type ConnectionContext,
702
- type CreateMcpHandlerOptions,
703
- type ElicitRequest$1 as ElicitRequest,
704
- ElicitRequestSchema$1 as ElicitRequestSchema,
705
- type ElicitResult$1 as ElicitResult,
706
- EmailResolver,
707
- EmailRoutingOptions,
708
- EmailSendOptions,
709
- MCPServer,
710
- MCPServerMessage,
711
- MCPServersState,
712
- McpAgent,
713
- type McpAuthContext,
714
- type OAuthExecutionContext,
715
- QueueItem,
716
- RPCRequest,
717
- RPCResponse,
718
- Schedule,
719
- StateUpdateMessage,
720
- StreamingResponse,
721
- type WSMessage,
722
- WorkerTransport,
723
- type WorkerTransportOptions,
724
- callable,
725
- createAddressBasedEmailResolver,
726
- createCatchAllEmailResolver,
727
- createHeaderBasedEmailResolver,
728
- experimental_createMcpHandler,
729
- getAgentByName,
730
- getCurrentAgent,
731
- getMcpAuthContext,
732
- routeAgentEmail,
733
- routeAgentRequest,
734
- unstable_callable
556
+ unstable_callable as A,
557
+ createAddressBasedEmailResolver as C,
558
+ getCurrentAgent as D,
559
+ getAgentByName as E,
560
+ routeAgentEmail as O,
561
+ callable as S,
562
+ createHeaderBasedEmailResolver as T,
563
+ RPCResponse as _,
564
+ AgentOptions as a,
565
+ StreamingResponse as b,
566
+ ConnectionContext as c,
567
+ EmailSendOptions as d,
568
+ MCPServer as f,
569
+ RPCRequest as g,
570
+ QueueItem as h,
571
+ AgentNamespace as i,
572
+ routeAgentRequest as k,
573
+ EmailResolver as l,
574
+ MCPServersState as m,
575
+ AgentContext as n,
576
+ CallableMetadata as o,
577
+ MCPServerMessage as p,
578
+ AgentEmail as r,
579
+ Connection$1 as s,
580
+ Agent as t,
581
+ EmailRoutingOptions as u,
582
+ Schedule as v,
583
+ createCatchAllEmailResolver as w,
584
+ WSMessage as x,
585
+ StateUpdateMessage as y
735
586
  };
736
- //# sourceMappingURL=index-CEqvuT_e.d.ts.map
587
+ //# sourceMappingURL=index-8Iyg9pLA.d.ts.map
@@ -1,4 +1,4 @@
1
- import { BaseEvent, MCPObservabilityEvent } from "./mcp-BEwaCsxO.js";
1
+ import { n as BaseEvent, t as MCPObservabilityEvent } from "./mcp-BwPscEiF.js";
2
2
 
3
3
  //#region src/observability/agent.d.ts
4
4
 
@@ -50,5 +50,9 @@ interface Observability {
50
50
  */
51
51
  declare const genericObservability: Observability;
52
52
  //#endregion
53
- export { Observability, ObservabilityEvent, genericObservability };
54
- //# sourceMappingURL=index-W4JUkafc.d.ts.map
53
+ export {
54
+ ObservabilityEvent as n,
55
+ genericObservability as r,
56
+ Observability as t
57
+ };
58
+ //# sourceMappingURL=index-BUle9RiP.d.ts.map