agents 0.0.0-e934f53 → 0.0.0-eaeb1b3

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 (85) hide show
  1. package/README.md +255 -10
  2. package/dist/ai-chat-agent.d.ts +236 -27
  3. package/dist/ai-chat-agent.js +1118 -260
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/ai-chat-v5-migration-DguhuLKF.js +155 -0
  6. package/dist/ai-chat-v5-migration-DguhuLKF.js.map +1 -0
  7. package/dist/ai-chat-v5-migration.d.ts +155 -0
  8. package/dist/ai-chat-v5-migration.js +3 -0
  9. package/dist/ai-react.d.ts +202 -87
  10. package/dist/ai-react.js +574 -199
  11. package/dist/ai-react.js.map +1 -1
  12. package/dist/ai-types-DEtF_8Km.js +28 -0
  13. package/dist/ai-types-DEtF_8Km.js.map +1 -0
  14. package/dist/ai-types-U8lYA0o8.d.ts +127 -0
  15. package/dist/ai-types.d.ts +6 -74
  16. package/dist/ai-types.js +3 -1
  17. package/dist/cli/index.d.ts +1 -0
  18. package/dist/cli/index.js +28 -0
  19. package/dist/cli/index.js.map +1 -0
  20. package/dist/client-Cfw92Wb_.d.ts +834 -0
  21. package/dist/client-ClORm6f0.d.ts +104 -0
  22. package/dist/client-DjTPRM8-.js +117 -0
  23. package/dist/client-DjTPRM8-.js.map +1 -0
  24. package/dist/client-QZa2Rq0l.js +1105 -0
  25. package/dist/client-QZa2Rq0l.js.map +1 -0
  26. package/dist/client.d.ts +11 -92
  27. package/dist/client.js +4 -11
  28. package/dist/codemode/ai.d.ts +27 -0
  29. package/dist/codemode/ai.js +152 -0
  30. package/dist/codemode/ai.js.map +1 -0
  31. package/dist/context-BkKbAa1R.js +8 -0
  32. package/dist/context-BkKbAa1R.js.map +1 -0
  33. package/dist/context-_sPQqJWv.d.ts +24 -0
  34. package/dist/context.d.ts +6 -0
  35. package/dist/context.js +3 -0
  36. package/dist/do-oauth-client-provider-B-ryFIPr.d.ts +70 -0
  37. package/dist/do-oauth-client-provider-B1fVIshX.js +155 -0
  38. package/dist/do-oauth-client-provider-B1fVIshX.js.map +1 -0
  39. package/dist/index-CyDpAVHZ.d.ts +58 -0
  40. package/dist/{index-BCJclX6q.d.ts → index-DAogLZyb.d.ts} +128 -166
  41. package/dist/index.d.ts +69 -40
  42. package/dist/index.js +8 -28
  43. package/dist/mcp/client.d.ts +4 -11
  44. package/dist/mcp/client.js +4 -9
  45. package/dist/mcp/do-oauth-client-provider.d.ts +2 -41
  46. package/dist/mcp/do-oauth-client-provider.js +3 -7
  47. package/dist/mcp/index.d.ts +200 -109
  48. package/dist/mcp/index.js +1429 -942
  49. package/dist/mcp/index.js.map +1 -1
  50. package/dist/mcp/x402.d.ts +34 -0
  51. package/dist/mcp/x402.js +198 -0
  52. package/dist/mcp/x402.js.map +1 -0
  53. package/dist/mcp-CzbSsLfc.d.ts +61 -0
  54. package/dist/observability/index.d.ts +3 -14
  55. package/dist/observability/index.js +8 -10
  56. package/dist/react-6RGGGKJb.d.ts +131 -0
  57. package/dist/react.d.ts +15 -121
  58. package/dist/react.js +183 -110
  59. package/dist/react.js.map +1 -1
  60. package/dist/schedule.d.ts +87 -10
  61. package/dist/schedule.js +46 -21
  62. package/dist/schedule.js.map +1 -1
  63. package/dist/serializable-C4GLimgv.d.ts +39 -0
  64. package/dist/serializable.d.ts +7 -32
  65. package/dist/serializable.js +1 -1
  66. package/dist/src-BZDh910Z.js +1181 -0
  67. package/dist/src-BZDh910Z.js.map +1 -0
  68. package/package.json +77 -31
  69. package/dist/ai-types.js.map +0 -1
  70. package/dist/chunk-HY7ZLHJB.js +0 -598
  71. package/dist/chunk-HY7ZLHJB.js.map +0 -1
  72. package/dist/chunk-JXN5WZFQ.js +0 -1287
  73. package/dist/chunk-JXN5WZFQ.js.map +0 -1
  74. package/dist/chunk-KUH345EY.js +0 -116
  75. package/dist/chunk-KUH345EY.js.map +0 -1
  76. package/dist/chunk-PVQZBKN7.js +0 -106
  77. package/dist/chunk-PVQZBKN7.js.map +0 -1
  78. package/dist/client-DgyzBU_8.d.ts +0 -4601
  79. package/dist/client.js.map +0 -1
  80. package/dist/index.js.map +0 -1
  81. package/dist/mcp/client.js.map +0 -1
  82. package/dist/mcp/do-oauth-client-provider.js.map +0 -1
  83. package/dist/observability/index.js.map +0 -1
  84. package/dist/serializable.js.map +0 -1
  85. package/src/index.ts +0 -1917
@@ -0,0 +1,155 @@
1
+ import { nanoid } from "nanoid";
2
+
3
+ //#region src/mcp/do-oauth-client-provider.ts
4
+ const STATE_EXPIRATION_MS = 600 * 1e3;
5
+ var DurableObjectOAuthClientProvider = class {
6
+ constructor(storage, clientName, baseRedirectUrl) {
7
+ this.storage = storage;
8
+ this.clientName = clientName;
9
+ this.baseRedirectUrl = baseRedirectUrl;
10
+ if (!storage) throw new Error("DurableObjectOAuthClientProvider requires a valid DurableObjectStorage instance");
11
+ }
12
+ get clientMetadata() {
13
+ return {
14
+ client_name: this.clientName,
15
+ client_uri: this.clientUri,
16
+ grant_types: ["authorization_code", "refresh_token"],
17
+ redirect_uris: [this.redirectUrl],
18
+ response_types: ["code"],
19
+ token_endpoint_auth_method: "none"
20
+ };
21
+ }
22
+ get clientUri() {
23
+ return new URL(this.redirectUrl).origin;
24
+ }
25
+ get redirectUrl() {
26
+ return this.baseRedirectUrl;
27
+ }
28
+ get clientId() {
29
+ if (!this._clientId_) throw new Error("Trying to access clientId before it was set");
30
+ return this._clientId_;
31
+ }
32
+ set clientId(clientId_) {
33
+ this._clientId_ = clientId_;
34
+ }
35
+ get serverId() {
36
+ if (!this._serverId_) throw new Error("Trying to access serverId before it was set");
37
+ return this._serverId_;
38
+ }
39
+ set serverId(serverId_) {
40
+ this._serverId_ = serverId_;
41
+ }
42
+ keyPrefix(clientId) {
43
+ return `/${this.clientName}/${this.serverId}/${clientId}`;
44
+ }
45
+ clientInfoKey(clientId) {
46
+ return `${this.keyPrefix(clientId)}/client_info/`;
47
+ }
48
+ async clientInformation() {
49
+ if (!this._clientId_) return;
50
+ return await this.storage.get(this.clientInfoKey(this.clientId)) ?? void 0;
51
+ }
52
+ async saveClientInformation(clientInformation) {
53
+ await this.storage.put(this.clientInfoKey(clientInformation.client_id), clientInformation);
54
+ this.clientId = clientInformation.client_id;
55
+ }
56
+ tokenKey(clientId) {
57
+ return `${this.keyPrefix(clientId)}/token`;
58
+ }
59
+ async tokens() {
60
+ if (!this._clientId_) return;
61
+ return await this.storage.get(this.tokenKey(this.clientId)) ?? void 0;
62
+ }
63
+ async saveTokens(tokens) {
64
+ await this.storage.put(this.tokenKey(this.clientId), tokens);
65
+ }
66
+ get authUrl() {
67
+ return this._authUrl_;
68
+ }
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
+ }
124
+ async redirectToAuthorization(authUrl) {
125
+ this._authUrl_ = authUrl.toString();
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
+ }
135
+ codeVerifierKey(clientId) {
136
+ return `${this.keyPrefix(clientId)}/code_verifier`;
137
+ }
138
+ async saveCodeVerifier(verifier) {
139
+ const key = this.codeVerifierKey(this.clientId);
140
+ if (await this.storage.get(key)) return;
141
+ await this.storage.put(key, verifier);
142
+ }
143
+ async codeVerifier() {
144
+ const codeVerifier = await this.storage.get(this.codeVerifierKey(this.clientId));
145
+ if (!codeVerifier) throw new Error("No code verifier found");
146
+ return codeVerifier;
147
+ }
148
+ async deleteCodeVerifier() {
149
+ await this.storage.delete(this.codeVerifierKey(this.clientId));
150
+ }
151
+ };
152
+
153
+ //#endregion
154
+ export { DurableObjectOAuthClientProvider as t };
155
+ //# sourceMappingURL=do-oauth-client-provider-B1fVIshX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"do-oauth-client-provider-B1fVIshX.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,gB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uB,EAAE;AAE/B,MAAI,UAAU,SAAS,UAAU,SAC/B,YAAW,KAAK,KAAK,cAAc,KAAK,SAAS,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"}
@@ -0,0 +1,58 @@
1
+ import { n as BaseEvent, t as MCPObservabilityEvent } from "./mcp-CzbSsLfc.js";
2
+
3
+ //#region src/observability/agent.d.ts
4
+
5
+ /**
6
+ * Agent-specific observability events
7
+ * These track the lifecycle and operations of an Agent
8
+ */
9
+ type AgentObservabilityEvent =
10
+ | BaseEvent<"state:update", {}>
11
+ | BaseEvent<
12
+ "rpc",
13
+ {
14
+ method: string;
15
+ streaming?: boolean;
16
+ }
17
+ >
18
+ | BaseEvent<"message:request" | "message:response", {}>
19
+ | BaseEvent<"message:clear">
20
+ | BaseEvent<
21
+ "schedule:create" | "schedule:execute" | "schedule:cancel",
22
+ {
23
+ callback: string;
24
+ id: string;
25
+ }
26
+ >
27
+ | BaseEvent<"destroy">
28
+ | BaseEvent<
29
+ "connect",
30
+ {
31
+ connectionId: string;
32
+ }
33
+ >;
34
+ //#endregion
35
+ //#region src/observability/index.d.ts
36
+ /**
37
+ * Union of all observability event types from different domains
38
+ */
39
+ type ObservabilityEvent = AgentObservabilityEvent | MCPObservabilityEvent;
40
+ interface Observability {
41
+ /**
42
+ * Emit an event for the Agent's observability implementation to handle.
43
+ * @param event - The event to emit
44
+ * @param ctx - The execution context of the invocation (optional)
45
+ */
46
+ emit(event: ObservabilityEvent, ctx?: DurableObjectState): void;
47
+ }
48
+ /**
49
+ * A generic observability implementation that logs events to the console.
50
+ */
51
+ declare const genericObservability: Observability;
52
+ //#endregion
53
+ export {
54
+ ObservabilityEvent as n,
55
+ genericObservability as r,
56
+ Observability as t
57
+ };
58
+ //# sourceMappingURL=index-CyDpAVHZ.d.ts.map
@@ -1,88 +1,29 @@
1
- import { env } from "cloudflare:workers";
1
+ import { n as AgentEmail } from "./context-_sPQqJWv.js";
2
+ import {
3
+ h as TransportType,
4
+ t as MCPClientManager,
5
+ u as MCPConnectionState
6
+ } from "./client-Cfw92Wb_.js";
7
+ import { t as Observability } from "./index-CyDpAVHZ.js";
8
+ import { n as MessageType } from "./ai-types-U8lYA0o8.js";
9
+ import {
10
+ Connection,
11
+ Connection as Connection$1,
12
+ ConnectionContext,
13
+ PartyServerOptions,
14
+ Server,
15
+ WSMessage
16
+ } from "partyserver";
2
17
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
3
18
  import {
4
- ServerCapabilities,
5
- Tool,
6
19
  Prompt,
7
- Resource
20
+ Resource,
21
+ ServerCapabilities,
22
+ Tool
8
23
  } from "@modelcontextprotocol/sdk/types.js";
9
- import { Server, Connection, PartyServerOptions } from "partyserver";
10
- import { M as MCPClientManager } from "./client-DgyzBU_8.js";
11
- import { Message } from "ai";
24
+ import { env } from "cloudflare:workers";
12
25
 
13
- type BaseEvent<
14
- T extends string,
15
- Payload extends Record<string, unknown> = {}
16
- > = {
17
- type: T;
18
- /**
19
- * The unique identifier for the event
20
- */
21
- id: string;
22
- /**
23
- * The message to display in the logs for this event, should the implementation choose to display
24
- * a human-readable message.
25
- */
26
- displayMessage: string;
27
- /**
28
- * The payload of the event
29
- */
30
- payload: Payload;
31
- /**
32
- * The timestamp of the event in milliseconds since epoch
33
- */
34
- timestamp: number;
35
- };
36
- /**
37
- * The type of events that can be emitted by an Agent
38
- */
39
- type ObservabilityEvent =
40
- | BaseEvent<
41
- "state:update",
42
- {
43
- state: unknown;
44
- previousState: unknown;
45
- }
46
- >
47
- | BaseEvent<
48
- "rpc",
49
- {
50
- method: string;
51
- args: unknown[];
52
- streaming?: boolean;
53
- success: boolean;
54
- }
55
- >
56
- | BaseEvent<
57
- "message:request" | "message:response",
58
- {
59
- message: Message[];
60
- }
61
- >
62
- | BaseEvent<"message:clear">
63
- | BaseEvent<
64
- "schedule:create" | "schedule:execute" | "schedule:cancel",
65
- Schedule<unknown>
66
- >
67
- | BaseEvent<"destroy">
68
- | BaseEvent<
69
- "connect",
70
- {
71
- connectionId: string;
72
- }
73
- >;
74
- interface Observability {
75
- /**
76
- * Emit an event for the Agent's observability implementation to handle.
77
- * @param event - The event to emit
78
- * @param ctx - The execution context of the invocation
79
- */
80
- emit(event: ObservabilityEvent, ctx: DurableObjectState): void;
81
- }
82
- /**
83
- * A generic observability implementation that logs events to the console.
84
- */
85
- declare const genericObservability: Observability;
26
+ //#region src/index.d.ts
86
27
 
87
28
  /**
88
29
  * RPC request message from client
@@ -97,14 +38,14 @@ type RPCRequest = {
97
38
  * State update message from client
98
39
  */
99
40
  type StateUpdateMessage = {
100
- type: "cf_agent_state";
41
+ type: MessageType.CF_AGENT_STATE;
101
42
  state: unknown;
102
43
  };
103
44
  /**
104
45
  * RPC response message to client
105
46
  */
106
47
  type RPCResponse = {
107
- type: "rpc";
48
+ type: MessageType.RPC;
108
49
  id: string;
109
50
  } & (
110
51
  | {
@@ -135,12 +76,18 @@ type CallableMetadata = {
135
76
  * Decorator that marks a method as callable by clients
136
77
  * @param metadata Optional metadata about the callable method
137
78
  */
138
- declare function unstable_callable(
79
+ declare function callable(
139
80
  metadata?: CallableMetadata
140
81
  ): <This, Args extends unknown[], Return>(
141
82
  target: (this: This, ...args: Args) => Return,
142
83
  context: ClassMethodDecoratorContext
143
84
  ) => (this: This, ...args: Args) => Return;
85
+ /**
86
+ * Decorator that marks a method as callable by clients
87
+ * @deprecated this has been renamed to callable, and unstable_callable will be removed in the next major version
88
+ * @param metadata Optional metadata about the callable method
89
+ */
90
+ declare const unstable_callable: (metadata?: CallableMetadata) => void;
144
91
  type QueueItem<T = string> = {
145
92
  id: string;
146
93
  payload: T;
@@ -186,22 +133,28 @@ type Schedule<T = string> = {
186
133
  * MCP Server state update message from server -> Client
187
134
  */
188
135
  type MCPServerMessage = {
189
- type: "cf_agent_mcp_servers";
136
+ type: MessageType.CF_AGENT_MCP_SERVERS;
190
137
  mcp: MCPServersState;
191
138
  };
192
139
  type MCPServersState = {
193
140
  servers: {
194
141
  [id: string]: MCPServer;
195
142
  };
196
- tools: Tool[];
197
- prompts: Prompt[];
198
- resources: Resource[];
143
+ tools: (Tool & {
144
+ serverId: string;
145
+ })[];
146
+ prompts: (Prompt & {
147
+ serverId: string;
148
+ })[];
149
+ resources: (Resource & {
150
+ serverId: string;
151
+ })[];
199
152
  };
200
153
  type MCPServer = {
201
154
  name: string;
202
155
  server_url: string;
203
156
  auth_url: string | null;
204
- state: "authenticating" | "connecting" | "ready" | "discovering" | "failed";
157
+ state: MCPConnectionState;
205
158
  instructions: string | null;
206
159
  capabilities: ServerCapabilities | null;
207
160
  };
@@ -218,10 +171,16 @@ declare function getCurrentAgent<
218
171
  * @template Env Environment type containing bindings
219
172
  * @template State State type to store within the Agent
220
173
  */
221
- declare class Agent<Env = typeof env, State = unknown> extends Server<Env> {
174
+ declare class Agent<
175
+ Env = typeof env,
176
+ State = unknown,
177
+ Props extends Record<string, unknown> = Record<string, unknown>
178
+ > extends Server<Env, Props> {
222
179
  private _state;
180
+ private _disposables;
181
+ private _destroyed;
223
182
  private _ParentClass;
224
- mcp: MCPClientManager;
183
+ readonly mcp: MCPClientManager;
225
184
  /**
226
185
  * Initial state for the Agent
227
186
  * Override to provide default state values
@@ -373,7 +332,7 @@ declare class Agent<Env = typeof env, State = unknown> extends Server<Env> {
373
332
  /**
374
333
  * Cancel a scheduled task
375
334
  * @param id ID of the task to cancel
376
- * @returns true if the task was cancelled, false otherwise
335
+ * @returns true if the task was cancelled, false if the task was not found
377
336
  */
378
337
  cancelSchedule(id: string): Promise<boolean>;
379
338
  private _scheduleNextAlarm;
@@ -398,55 +357,62 @@ declare class Agent<Env = typeof env, State = unknown> extends Server<Env> {
398
357
  /**
399
358
  * Connect to a new MCP Server
400
359
  *
360
+ * @param serverName Name of the MCP server
401
361
  * @param url MCP Server SSE URL
402
- * @param callbackHost Base host for the agent, used for the redirect URI.
362
+ * @param callbackHost Base host for the agent, used for the redirect URI. If not provided, will be derived from the current request.
403
363
  * @param agentsPrefix agents routing prefix if not using `agents`
404
- * @param options MCP client and transport (header) options
405
- * @returns authUrl
364
+ * @param options MCP client and transport options
365
+ * @returns Server id and state - either "authenticating" with authUrl, or "ready"
366
+ * @throws If connection or discovery fails
406
367
  */
407
368
  addMcpServer(
408
369
  serverName: string,
409
370
  url: string,
410
- callbackHost: string,
371
+ callbackHost?: string,
411
372
  agentsPrefix?: string,
412
373
  options?: {
413
374
  client?: ConstructorParameters<typeof Client>[1];
414
- transport?: {
415
- headers: HeadersInit;
416
- };
417
- }
418
- ): Promise<{
419
- id: string;
420
- authUrl: string | undefined;
421
- }>;
422
- _connectToMcpServerInternal(
423
- _serverName: string,
424
- url: string,
425
- callbackUrl: string,
426
- options?: {
427
- client?: ConstructorParameters<typeof Client>[1];
428
- /**
429
- * We don't expose the normal set of transport options because:
430
- * 1) we can't serialize things like the auth provider or a fetch function into the DB for reconnection purposes
431
- * 2) We probably want these options to be agnostic to the transport type (SSE vs Streamable)
432
- *
433
- * This has the limitation that you can't override fetch, but I think headers should handle nearly all cases needed (i.e. non-standard bearer auth).
434
- */
435
375
  transport?: {
436
376
  headers?: HeadersInit;
377
+ type?: TransportType;
437
378
  };
438
- },
439
- reconnect?: {
440
- id: string;
441
- oauthClientId?: string;
442
379
  }
443
- ): Promise<{
444
- id: string;
445
- authUrl: string | undefined;
446
- clientId: string | undefined;
447
- }>;
380
+ ): Promise<
381
+ | {
382
+ id: string;
383
+ state: typeof MCPConnectionState.AUTHENTICATING;
384
+ authUrl: string;
385
+ }
386
+ | {
387
+ id: string;
388
+ state: typeof MCPConnectionState.READY;
389
+ authUrl?: undefined;
390
+ }
391
+ >;
448
392
  removeMcpServer(id: string): Promise<void>;
449
393
  getMcpServers(): MCPServersState;
394
+ private broadcastMcpServers;
395
+ /**
396
+ * Handle MCP OAuth callback request if it's an OAuth callback.
397
+ *
398
+ * This method encapsulates the entire OAuth callback flow:
399
+ * 1. Checks if the request is an MCP OAuth callback
400
+ * 2. Processes the OAuth code exchange
401
+ * 3. Establishes the connection if successful
402
+ * 4. Broadcasts MCP server state updates
403
+ * 5. Returns the appropriate HTTP response
404
+ *
405
+ * @param request The incoming HTTP request
406
+ * @returns Response if this was an OAuth callback, null otherwise
407
+ */
408
+ private handleMcpOAuthCallback;
409
+ /**
410
+ * Handle OAuth callback response using MCPClientManager configuration
411
+ * @param result OAuth callback result
412
+ * @param request The original request (needed for base URL)
413
+ * @returns Response for the OAuth callback
414
+ */
415
+ private handleOAuthCallbackResponse;
450
416
  }
451
417
  /**
452
418
  * Namespace for creating Agent instances
@@ -524,16 +490,6 @@ declare function routeAgentEmail<Env>(
524
490
  env: Env,
525
491
  options: EmailRoutingOptions<Env>
526
492
  ): Promise<void>;
527
- type AgentEmail = {
528
- from: string;
529
- to: string;
530
- getRaw: () => Promise<Uint8Array>;
531
- headers: Headers;
532
- rawSize: number;
533
- setReject: (reason: string) => void;
534
- forward: (rcptTo: string, headers?: Headers) => Promise<void>;
535
- reply: (options: { from: string; to: string; raw: string }) => Promise<void>;
536
- };
537
493
  type EmailSendOptions = {
538
494
  to: string;
539
495
  subject: string;
@@ -554,12 +510,17 @@ type EmailSendOptions = {
554
510
  * @param options Options for Agent creation
555
511
  * @returns Promise resolving to an Agent instance stub
556
512
  */
557
- declare function getAgentByName<Env, T extends Agent<Env>>(
513
+ declare function getAgentByName<
514
+ Env,
515
+ T extends Agent<Env>,
516
+ Props extends Record<string, unknown> = Record<string, unknown>
517
+ >(
558
518
  namespace: AgentNamespace<T>,
559
519
  name: string,
560
520
  options?: {
561
521
  jurisdiction?: DurableObjectJurisdiction;
562
522
  locationHint?: DurableObjectLocationHint;
523
+ props?: Props;
563
524
  }
564
525
  ): Promise<DurableObjectStub<T>>;
565
526
  /**
@@ -581,35 +542,36 @@ declare class StreamingResponse {
581
542
  */
582
543
  end(finalChunk?: unknown): void;
583
544
  }
584
-
545
+ //#endregion
585
546
  export {
586
- Agent as A,
587
- type CallableMetadata as C,
588
- type EmailResolver as E,
589
- type MCPServersState as M,
590
- type ObservabilityEvent as O,
591
- type QueueItem as Q,
592
- type RPCRequest as R,
593
- type StateUpdateMessage as S,
594
- type AgentContext as a,
595
- type Observability as b,
596
- type RPCResponse as c,
597
- type Schedule as d,
598
- type MCPServerMessage as e,
599
- type MCPServer as f,
600
- genericObservability as g,
601
- getCurrentAgent as h,
602
- type AgentNamespace as i,
603
- type AgentOptions as j,
604
- createHeaderBasedEmailResolver as k,
605
- createAddressBasedEmailResolver as l,
606
- createCatchAllEmailResolver as m,
607
- type EmailRoutingOptions as n,
608
- routeAgentEmail as o,
609
- type AgentEmail as p,
610
- type EmailSendOptions as q,
611
- routeAgentRequest as r,
612
- getAgentByName as s,
613
- StreamingResponse as t,
614
- unstable_callable as u
547
+ createCatchAllEmailResolver as C,
548
+ routeAgentEmail as D,
549
+ getCurrentAgent as E,
550
+ routeAgentRequest as O,
551
+ createAddressBasedEmailResolver as S,
552
+ getAgentByName as T,
553
+ Schedule as _,
554
+ CallableMetadata as a,
555
+ WSMessage as b,
556
+ EmailResolver as c,
557
+ MCPServer as d,
558
+ MCPServerMessage as f,
559
+ RPCResponse as g,
560
+ RPCRequest as h,
561
+ AgentOptions as i,
562
+ unstable_callable as k,
563
+ EmailRoutingOptions as l,
564
+ QueueItem as m,
565
+ AgentContext as n,
566
+ Connection$1 as o,
567
+ MCPServersState as p,
568
+ AgentNamespace as r,
569
+ ConnectionContext as s,
570
+ Agent as t,
571
+ EmailSendOptions as u,
572
+ StateUpdateMessage as v,
573
+ createHeaderBasedEmailResolver as w,
574
+ callable as x,
575
+ StreamingResponse as y
615
576
  };
577
+ //# sourceMappingURL=index-DAogLZyb.d.ts.map