agents 0.0.0-d6a4eda → 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.
Files changed (77) hide show
  1. package/README.md +255 -27
  2. package/dist/ai-chat-agent.d.ts +20 -17
  3. package/dist/ai-chat-agent.js +532 -222
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/ai-chat-v5-migration-DBHGW4Hv.js +155 -0
  6. package/dist/ai-chat-v5-migration-DBHGW4Hv.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 +73 -84
  10. package/dist/ai-react.js +266 -199
  11. package/dist/ai-react.js.map +1 -1
  12. package/dist/ai-types-B3aQaFv3.js +20 -0
  13. package/dist/ai-types-B3aQaFv3.js.map +1 -0
  14. package/dist/ai-types-D5YoPrBZ.d.ts +95 -0
  15. package/dist/ai-types.d.ts +6 -74
  16. package/dist/ai-types.js +3 -1
  17. package/dist/cli.d.ts +8 -0
  18. package/dist/cli.js +27 -0
  19. package/dist/cli.js.map +1 -0
  20. package/dist/client-BfiZ3HQd.js +117 -0
  21. package/dist/client-BfiZ3HQd.js.map +1 -0
  22. package/dist/client-Bws9q38u.d.ts +5427 -0
  23. package/dist/client-CbWe9FBd.d.ts +104 -0
  24. package/dist/client-DvK0u9vD.js +898 -0
  25. package/dist/client-DvK0u9vD.js.map +1 -0
  26. package/dist/client.d.ts +12 -87
  27. package/dist/client.js +4 -11
  28. package/dist/codemode/ai.d.ts +27 -0
  29. package/dist/codemode/ai.js +151 -0
  30. package/dist/codemode/ai.js.map +1 -0
  31. package/dist/do-oauth-client-provider-CcTno-25.d.ts +142 -0
  32. package/dist/do-oauth-client-provider-D2P1lSft.js +93 -0
  33. package/dist/do-oauth-client-provider-D2P1lSft.js.map +1 -0
  34. package/dist/index-Bdzb2feZ.d.ts +572 -0
  35. package/dist/index-DhJCaDWd.d.ts +58 -0
  36. package/dist/index.d.ts +62 -392
  37. package/dist/index.js +7 -22
  38. package/dist/mcp/client.d.ts +4 -783
  39. package/dist/mcp/client.js +4 -9
  40. package/dist/mcp/do-oauth-client-provider.d.ts +2 -41
  41. package/dist/mcp/do-oauth-client-provider.js +3 -7
  42. package/dist/mcp/index.d.ts +190 -81
  43. package/dist/mcp/index.js +1428 -767
  44. package/dist/mcp/index.js.map +1 -1
  45. package/dist/mcp/x402.d.ts +34 -0
  46. package/dist/mcp/x402.js +194 -0
  47. package/dist/mcp/x402.js.map +1 -0
  48. package/dist/mcp-Dw5vDrY8.d.ts +61 -0
  49. package/dist/observability/index.d.ts +3 -0
  50. package/dist/observability/index.js +7 -0
  51. package/dist/react-DFNXTQzy.d.ts +113 -0
  52. package/dist/react.d.ts +10 -53
  53. package/dist/react.js +183 -100
  54. package/dist/react.js.map +1 -1
  55. package/dist/schedule.d.ts +89 -12
  56. package/dist/schedule.js +46 -21
  57. package/dist/schedule.js.map +1 -1
  58. package/dist/serializable-CymX8ovI.d.ts +39 -0
  59. package/dist/serializable.d.ts +7 -0
  60. package/dist/serializable.js +1 -0
  61. package/dist/src-C1WWpbRo.js +1247 -0
  62. package/dist/src-C1WWpbRo.js.map +1 -0
  63. package/package.json +125 -71
  64. package/dist/ai-types.js.map +0 -1
  65. package/dist/chunk-BZXOAZUX.js +0 -106
  66. package/dist/chunk-BZXOAZUX.js.map +0 -1
  67. package/dist/chunk-QSGN3REV.js +0 -123
  68. package/dist/chunk-QSGN3REV.js.map +0 -1
  69. package/dist/chunk-RIYR6FR6.js +0 -777
  70. package/dist/chunk-RIYR6FR6.js.map +0 -1
  71. package/dist/chunk-Y67CHZBI.js +0 -464
  72. package/dist/chunk-Y67CHZBI.js.map +0 -1
  73. package/dist/client.js.map +0 -1
  74. package/dist/index.js.map +0 -1
  75. package/dist/mcp/client.js.map +0 -1
  76. package/dist/mcp/do-oauth-client-provider.js.map +0 -1
  77. package/src/index.ts +0 -1243
@@ -0,0 +1,93 @@
1
+ import { nanoid } from "nanoid";
2
+
3
+ //#region src/mcp/do-oauth-client-provider.ts
4
+ var DurableObjectOAuthClientProvider = class {
5
+ constructor(storage, clientName, baseRedirectUrl) {
6
+ this.storage = storage;
7
+ this.clientName = clientName;
8
+ this.baseRedirectUrl = baseRedirectUrl;
9
+ }
10
+ get clientMetadata() {
11
+ return {
12
+ client_name: this.clientName,
13
+ client_uri: this.clientUri,
14
+ grant_types: ["authorization_code", "refresh_token"],
15
+ redirect_uris: [this.redirectUrl],
16
+ response_types: ["code"],
17
+ token_endpoint_auth_method: "none"
18
+ };
19
+ }
20
+ get clientUri() {
21
+ return new URL(this.redirectUrl).origin;
22
+ }
23
+ get redirectUrl() {
24
+ return `${this.baseRedirectUrl}/${this.serverId}`;
25
+ }
26
+ get clientId() {
27
+ if (!this._clientId_) throw new Error("Trying to access clientId before it was set");
28
+ return this._clientId_;
29
+ }
30
+ set clientId(clientId_) {
31
+ this._clientId_ = clientId_;
32
+ }
33
+ get serverId() {
34
+ if (!this._serverId_) throw new Error("Trying to access serverId before it was set");
35
+ return this._serverId_;
36
+ }
37
+ set serverId(serverId_) {
38
+ this._serverId_ = serverId_;
39
+ }
40
+ keyPrefix(clientId) {
41
+ return `/${this.clientName}/${this.serverId}/${clientId}`;
42
+ }
43
+ clientInfoKey(clientId) {
44
+ return `${this.keyPrefix(clientId)}/client_info/`;
45
+ }
46
+ async clientInformation() {
47
+ if (!this._clientId_) return;
48
+ return await this.storage.get(this.clientInfoKey(this.clientId)) ?? void 0;
49
+ }
50
+ async saveClientInformation(clientInformation) {
51
+ await this.storage.put(this.clientInfoKey(clientInformation.client_id), clientInformation);
52
+ this.clientId = clientInformation.client_id;
53
+ }
54
+ tokenKey(clientId) {
55
+ return `${this.keyPrefix(clientId)}/token`;
56
+ }
57
+ async tokens() {
58
+ if (!this._clientId_) return;
59
+ return await this.storage.get(this.tokenKey(this.clientId)) ?? void 0;
60
+ }
61
+ async saveTokens(tokens) {
62
+ await this.storage.put(this.tokenKey(this.clientId), tokens);
63
+ }
64
+ get authUrl() {
65
+ return this._authUrl_;
66
+ }
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
+ */
71
+ redirectToAuthorization(authUrl) {
72
+ const stateToken = nanoid();
73
+ authUrl.searchParams.set("state", stateToken);
74
+ this._authUrl_ = authUrl.toString();
75
+ }
76
+ codeVerifierKey(clientId) {
77
+ return `${this.keyPrefix(clientId)}/code_verifier`;
78
+ }
79
+ async saveCodeVerifier(verifier) {
80
+ const key = this.codeVerifierKey(this.clientId);
81
+ if (await this.storage.get(key)) return;
82
+ await this.storage.put(key, verifier);
83
+ }
84
+ async codeVerifier() {
85
+ const codeVerifier = await this.storage.get(this.codeVerifierKey(this.clientId));
86
+ if (!codeVerifier) throw new Error("No code verifier found");
87
+ return codeVerifier;
88
+ }
89
+ };
90
+
91
+ //#endregion
92
+ export { DurableObjectOAuthClientProvider as t };
93
+ //# sourceMappingURL=do-oauth-client-provider-D2P1lSft.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"do-oauth-client-provider-D2P1lSft.js","names":["storage: OAuthClientStorage","clientName: string","baseRedirectUrl: 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\";\nimport type { OAuthClientStorage } from \"./client-storage\";\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}\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: OAuthClientStorage,\n public clientName: string,\n public baseRedirectUrl: string\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}/${this.serverId}`;\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() {\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(clientInformation: OAuthClientInformationFull) {\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() {\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) {\n await this.storage.put(this.tokenKey(this.clientId), tokens);\n }\n\n get authUrl() {\n return this._authUrl_;\n }\n\n /**\n * Because this operates on the server side (but we need browser auth), we send this url back to the user\n * and require user interact to initiate the redirect flow\n */\n redirectToAuthorization(authUrl: URL) {\n // Generate secure random token for state parameter\n const stateToken = nanoid();\n authUrl.searchParams.set(\"state\", stateToken);\n this._authUrl_ = authUrl.toString();\n }\n\n codeVerifierKey(clientId: string) {\n return `${this.keyPrefix(clientId)}/code_verifier`;\n }\n\n async saveCodeVerifier(verifier: string) {\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() {\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"],"mappings":";;;AAkBA,IAAa,mCAAb,MAA6E;CAK3E,YACE,AAAOA,SACP,AAAOC,YACP,AAAOC,iBACP;EAHO;EACA;EACA;;CAGT,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;GAC7B;;CAGH,IAAI,YAAY;AACd,SAAO,IAAI,IAAI,KAAK,YAAY,CAAC;;CAGnC,IAAI,cAAc;AAChB,SAAO,GAAG,KAAK,gBAAgB,GAAG,KAAK;;CAGzC,IAAI,WAAW;AACb,MAAI,CAAC,KAAK,WACR,OAAM,IAAI,MAAM,8CAA8C;AAEhE,SAAO,KAAK;;CAGd,IAAI,SAAS,WAAmB;AAC9B,OAAK,aAAa;;CAGpB,IAAI,WAAW;AACb,MAAI,CAAC,KAAK,WACR,OAAM,IAAI,MAAM,8CAA8C;AAEhE,SAAO,KAAK;;CAGd,IAAI,SAAS,WAAmB;AAC9B,OAAK,aAAa;;CAGpB,UAAU,UAAkB;AAC1B,SAAO,IAAI,KAAK,WAAW,GAAG,KAAK,SAAS,GAAG;;CAGjD,cAAc,UAAkB;AAC9B,SAAO,GAAG,KAAK,UAAU,SAAS,CAAC;;CAGrC,MAAM,oBAAoB;AACxB,MAAI,CAAC,KAAK,WACR;AAEF,SACG,MAAM,KAAK,QAAQ,IAClB,KAAK,cAAc,KAAK,SAAS,CAClC,IAAK;;CAIV,MAAM,sBAAsB,mBAA+C;AACzE,QAAM,KAAK,QAAQ,IACjB,KAAK,cAAc,kBAAkB,UAAU,EAC/C,kBACD;AACD,OAAK,WAAW,kBAAkB;;CAGpC,SAAS,UAAkB;AACzB,SAAO,GAAG,KAAK,UAAU,SAAS,CAAC;;CAGrC,MAAM,SAAS;AACb,MAAI,CAAC,KAAK,WACR;AAEF,SACG,MAAM,KAAK,QAAQ,IAAiB,KAAK,SAAS,KAAK,SAAS,CAAC,IAClE;;CAIJ,MAAM,WAAW,QAAqB;AACpC,QAAM,KAAK,QAAQ,IAAI,KAAK,SAAS,KAAK,SAAS,EAAE,OAAO;;CAG9D,IAAI,UAAU;AACZ,SAAO,KAAK;;;;;;CAOd,wBAAwB,SAAc;EAEpC,MAAM,aAAa,QAAQ;AAC3B,UAAQ,aAAa,IAAI,SAAS,WAAW;AAC7C,OAAK,YAAY,QAAQ,UAAU;;CAGrC,gBAAgB,UAAkB;AAChC,SAAO,GAAG,KAAK,UAAU,SAAS,CAAC;;CAGrC,MAAM,iBAAiB,UAAkB;EACvC,MAAM,MAAM,KAAK,gBAAgB,KAAK,SAAS;AAI/C,MADiB,MAAM,KAAK,QAAQ,IAAY,IAAI,CAElD;AAGF,QAAM,KAAK,QAAQ,IAAI,KAAK,SAAS;;CAGvC,MAAM,eAAe;EACnB,MAAM,eAAe,MAAM,KAAK,QAAQ,IACtC,KAAK,gBAAgB,KAAK,SAAS,CACpC;AACD,MAAI,CAAC,aACH,OAAM,IAAI,MAAM,yBAAyB;AAE3C,SAAO"}
@@ -0,0 +1,572 @@
1
+ import {
2
+ l as MCPConnectionState,
3
+ m as TransportType,
4
+ t as MCPClientManager
5
+ } from "./client-Bws9q38u.js";
6
+ import { t as Observability } from "./index-DhJCaDWd.js";
7
+ import { n as MessageType } from "./ai-types-D5YoPrBZ.js";
8
+ import {
9
+ Connection,
10
+ Connection as Connection$1,
11
+ ConnectionContext,
12
+ PartyServerOptions,
13
+ Server,
14
+ WSMessage
15
+ } from "partyserver";
16
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
17
+ import {
18
+ Prompt,
19
+ Resource,
20
+ ServerCapabilities,
21
+ Tool
22
+ } from "@modelcontextprotocol/sdk/types.js";
23
+ import { env } from "cloudflare:workers";
24
+
25
+ //#region src/index.d.ts
26
+
27
+ /**
28
+ * RPC request message from client
29
+ */
30
+ type RPCRequest = {
31
+ type: "rpc";
32
+ id: string;
33
+ method: string;
34
+ args: unknown[];
35
+ };
36
+ /**
37
+ * State update message from client
38
+ */
39
+ type StateUpdateMessage = {
40
+ type: MessageType.CF_AGENT_STATE;
41
+ state: unknown;
42
+ };
43
+ /**
44
+ * RPC response message to client
45
+ */
46
+ type RPCResponse = {
47
+ type: MessageType.RPC;
48
+ id: string;
49
+ } & (
50
+ | {
51
+ success: true;
52
+ result: unknown;
53
+ done?: false;
54
+ }
55
+ | {
56
+ success: true;
57
+ result: unknown;
58
+ done: true;
59
+ }
60
+ | {
61
+ success: false;
62
+ error: string;
63
+ }
64
+ );
65
+ /**
66
+ * Metadata for a callable method
67
+ */
68
+ type CallableMetadata = {
69
+ /** Optional description of what the method does */
70
+ description?: string;
71
+ /** Whether the method supports streaming responses */
72
+ streaming?: boolean;
73
+ };
74
+ /**
75
+ * Decorator that marks a method as callable by clients
76
+ * @param metadata Optional metadata about the callable method
77
+ */
78
+ declare function callable(
79
+ metadata?: CallableMetadata
80
+ ): <This, Args extends unknown[], Return>(
81
+ target: (this: This, ...args: Args) => Return,
82
+ context: ClassMethodDecoratorContext
83
+ ) => (this: This, ...args: Args) => Return;
84
+ /**
85
+ * Decorator that marks a method as callable by clients
86
+ * @deprecated this has been renamed to callable, and unstable_callable will be removed in the next major version
87
+ * @param metadata Optional metadata about the callable method
88
+ */
89
+ declare const unstable_callable: (metadata?: CallableMetadata) => void;
90
+ type QueueItem<T = string> = {
91
+ id: string;
92
+ payload: T;
93
+ callback: keyof Agent<unknown>;
94
+ created_at: number;
95
+ };
96
+ /**
97
+ * Represents a scheduled task within an Agent
98
+ * @template T Type of the payload data
99
+ */
100
+ type Schedule<T = string> = {
101
+ /** Unique identifier for the schedule */
102
+ id: string;
103
+ /** Name of the method to be called */
104
+ callback: string;
105
+ /** Data to be passed to the callback */
106
+ payload: T;
107
+ } & (
108
+ | {
109
+ /** Type of schedule for one-time execution at a specific time */
110
+ type: "scheduled";
111
+ /** Timestamp when the task should execute */
112
+ time: number;
113
+ }
114
+ | {
115
+ /** Type of schedule for delayed execution */
116
+ type: "delayed";
117
+ /** Timestamp when the task should execute */
118
+ time: number;
119
+ /** Number of seconds to delay execution */
120
+ delayInSeconds: number;
121
+ }
122
+ | {
123
+ /** Type of schedule for recurring execution based on cron expression */
124
+ type: "cron";
125
+ /** Timestamp for the next execution */
126
+ time: number;
127
+ /** Cron expression defining the schedule */
128
+ cron: string;
129
+ }
130
+ );
131
+ /**
132
+ * MCP Server state update message from server -> Client
133
+ */
134
+ type MCPServerMessage = {
135
+ type: MessageType.CF_AGENT_MCP_SERVERS;
136
+ mcp: MCPServersState;
137
+ };
138
+ type MCPServersState = {
139
+ servers: {
140
+ [id: string]: MCPServer;
141
+ };
142
+ tools: Tool[];
143
+ prompts: Prompt[];
144
+ resources: Resource[];
145
+ };
146
+ type MCPServer = {
147
+ name: string;
148
+ server_url: string;
149
+ auth_url: string | null;
150
+ state: MCPConnectionState;
151
+ instructions: string | null;
152
+ capabilities: ServerCapabilities | null;
153
+ };
154
+ declare function getCurrentAgent<
155
+ T extends Agent<unknown, unknown> = Agent<unknown, unknown>
156
+ >(): {
157
+ agent: T | undefined;
158
+ connection: Connection | undefined;
159
+ request: Request | undefined;
160
+ email: AgentEmail | undefined;
161
+ };
162
+ /**
163
+ * Base class for creating Agent implementations
164
+ * @template Env Environment type containing bindings
165
+ * @template State State type to store within the Agent
166
+ */
167
+ declare class Agent<
168
+ Env = typeof env,
169
+ State = unknown,
170
+ Props extends Record<string, unknown> = Record<string, unknown>
171
+ > extends Server<Env, Props> {
172
+ private _state;
173
+ private _disposables;
174
+ private _destroyed;
175
+ private _ParentClass;
176
+ readonly mcp: MCPClientManager;
177
+ /**
178
+ * Initial state for the Agent
179
+ * Override to provide default state values
180
+ */
181
+ initialState: State;
182
+ /**
183
+ * Current state of the Agent
184
+ */
185
+ get state(): State;
186
+ /**
187
+ * Agent configuration options
188
+ */
189
+ static options: {
190
+ /** Whether the Agent should hibernate when inactive */
191
+ hibernate: boolean;
192
+ };
193
+ /**
194
+ * The observability implementation to use for the Agent
195
+ */
196
+ observability?: Observability;
197
+ /**
198
+ * Execute SQL queries against the Agent's database
199
+ * @template T Type of the returned rows
200
+ * @param strings SQL query template strings
201
+ * @param values Values to be inserted into the query
202
+ * @returns Array of query results
203
+ */
204
+ sql<T = Record<string, string | number | boolean | null>>(
205
+ strings: TemplateStringsArray,
206
+ ...values: (string | number | boolean | null)[]
207
+ ): T[];
208
+ constructor(ctx: AgentContext, env: Env);
209
+ private _setStateInternal;
210
+ /**
211
+ * Update the Agent's state
212
+ * @param state New state to set
213
+ */
214
+ setState(state: State): void;
215
+ /**
216
+ * Called when the Agent's state is updated
217
+ * @param state Updated state
218
+ * @param source Source of the state update ("server" or a client connection)
219
+ */
220
+ onStateUpdate(state: State | undefined, source: Connection | "server"): void;
221
+ /**
222
+ * Called when the Agent receives an email via routeAgentEmail()
223
+ * Override this method to handle incoming emails
224
+ * @param email Email message to process
225
+ */
226
+ _onEmail(email: AgentEmail): Promise<void>;
227
+ /**
228
+ * Reply to an email
229
+ * @param email The email to reply to
230
+ * @param options Options for the reply
231
+ * @returns void
232
+ */
233
+ replyToEmail(
234
+ email: AgentEmail,
235
+ options: {
236
+ fromName: string;
237
+ subject?: string | undefined;
238
+ body: string;
239
+ contentType?: string;
240
+ headers?: Record<string, string>;
241
+ }
242
+ ): Promise<void>;
243
+ private _tryCatch;
244
+ /**
245
+ * Automatically wrap custom methods with agent context
246
+ * This ensures getCurrentAgent() works in all custom methods without decorators
247
+ */
248
+ private _autoWrapCustomMethods;
249
+ onError(connection: Connection, error: unknown): void | Promise<void>;
250
+ onError(error: unknown): void | Promise<void>;
251
+ /**
252
+ * Render content (not implemented in base class)
253
+ */
254
+ render(): void;
255
+ /**
256
+ * Queue a task to be executed in the future
257
+ * @param payload Payload to pass to the callback
258
+ * @param callback Name of the method to call
259
+ * @returns The ID of the queued task
260
+ */
261
+ queue<T = unknown>(callback: keyof this, payload: T): Promise<string>;
262
+ private _flushingQueue;
263
+ private _flushQueue;
264
+ /**
265
+ * Dequeue a task by ID
266
+ * @param id ID of the task to dequeue
267
+ */
268
+ dequeue(id: string): Promise<void>;
269
+ /**
270
+ * Dequeue all tasks
271
+ */
272
+ dequeueAll(): Promise<void>;
273
+ /**
274
+ * Dequeue all tasks by callback
275
+ * @param callback Name of the callback to dequeue
276
+ */
277
+ dequeueAllByCallback(callback: string): Promise<void>;
278
+ /**
279
+ * Get a queued task by ID
280
+ * @param id ID of the task to get
281
+ * @returns The task or undefined if not found
282
+ */
283
+ getQueue(id: string): Promise<QueueItem<string> | undefined>;
284
+ /**
285
+ * Get all queues by key and value
286
+ * @param key Key to filter by
287
+ * @param value Value to filter by
288
+ * @returns Array of matching QueueItem objects
289
+ */
290
+ getQueues(key: string, value: string): Promise<QueueItem<string>[]>;
291
+ /**
292
+ * Schedule a task to be executed in the future
293
+ * @template T Type of the payload data
294
+ * @param when When to execute the task (Date, seconds delay, or cron expression)
295
+ * @param callback Name of the method to call
296
+ * @param payload Data to pass to the callback
297
+ * @returns Schedule object representing the scheduled task
298
+ */
299
+ schedule<T = string>(
300
+ when: Date | string | number,
301
+ callback: keyof this,
302
+ payload?: T
303
+ ): Promise<Schedule<T>>;
304
+ /**
305
+ * Get a scheduled task by ID
306
+ * @template T Type of the payload data
307
+ * @param id ID of the scheduled task
308
+ * @returns The Schedule object or undefined if not found
309
+ */
310
+ getSchedule<T = string>(id: string): Promise<Schedule<T> | undefined>;
311
+ /**
312
+ * Get scheduled tasks matching the given criteria
313
+ * @template T Type of the payload data
314
+ * @param criteria Criteria to filter schedules
315
+ * @returns Array of matching Schedule objects
316
+ */
317
+ getSchedules<T = string>(criteria?: {
318
+ id?: string;
319
+ type?: "scheduled" | "delayed" | "cron";
320
+ timeRange?: {
321
+ start?: Date;
322
+ end?: Date;
323
+ };
324
+ }): Schedule<T>[];
325
+ /**
326
+ * Cancel a scheduled task
327
+ * @param id ID of the task to cancel
328
+ * @returns true if the task was cancelled, false otherwise
329
+ */
330
+ cancelSchedule(id: string): Promise<boolean>;
331
+ private _scheduleNextAlarm;
332
+ /**
333
+ * Method called when an alarm fires.
334
+ * Executes any scheduled tasks that are due.
335
+ *
336
+ * @remarks
337
+ * To schedule a task, please use the `this.schedule` method instead.
338
+ * See {@link https://developers.cloudflare.com/agents/api-reference/schedule-tasks/}
339
+ */
340
+ readonly alarm: () => Promise<void>;
341
+ /**
342
+ * Destroy the Agent, removing all state and scheduled tasks
343
+ */
344
+ destroy(): Promise<void>;
345
+ /**
346
+ * Get all methods marked as callable on this Agent
347
+ * @returns A map of method names to their metadata
348
+ */
349
+ private _isCallable;
350
+ /**
351
+ * Connect to a new MCP Server
352
+ *
353
+ * @param serverName Name of the MCP server
354
+ * @param url MCP Server SSE URL
355
+ * @param callbackHost Base host for the agent, used for the redirect URI. If not provided, will be derived from the current request.
356
+ * @param agentsPrefix agents routing prefix if not using `agents`
357
+ * @param options MCP client and transport options
358
+ * @returns authUrl
359
+ */
360
+ addMcpServer(
361
+ serverName: string,
362
+ url: string,
363
+ callbackHost?: string,
364
+ agentsPrefix?: string,
365
+ options?: {
366
+ client?: ConstructorParameters<typeof Client>[1];
367
+ transport?: {
368
+ headers?: HeadersInit;
369
+ type?: TransportType;
370
+ };
371
+ }
372
+ ): Promise<{
373
+ id: string;
374
+ authUrl: string | undefined;
375
+ }>;
376
+ removeMcpServer(id: string): Promise<void>;
377
+ getMcpServers(): Promise<MCPServersState>;
378
+ private broadcastMcpServers;
379
+ /**
380
+ * Handle MCP OAuth callback request if it's an OAuth callback.
381
+ *
382
+ * This method encapsulates the entire OAuth callback flow:
383
+ * 1. Checks if the request is an MCP OAuth callback
384
+ * 2. Processes the OAuth code exchange
385
+ * 3. Establishes the connection if successful
386
+ * 4. Broadcasts MCP server state updates
387
+ * 5. Returns the appropriate HTTP response
388
+ *
389
+ * @param request The incoming HTTP request
390
+ * @returns Response if this was an OAuth callback, null otherwise
391
+ */
392
+ private handleMcpOAuthCallback;
393
+ /**
394
+ * Handle OAuth callback response using MCPClientManager configuration
395
+ * @param result OAuth callback result
396
+ * @param request The original request (needed for base URL)
397
+ * @returns Response for the OAuth callback
398
+ */
399
+ private handleOAuthCallbackResponse;
400
+ }
401
+ /**
402
+ * Namespace for creating Agent instances
403
+ * @template Agentic Type of the Agent class
404
+ */
405
+ type AgentNamespace<Agentic extends Agent<unknown>> =
406
+ DurableObjectNamespace<Agentic>;
407
+ /**
408
+ * Agent's durable context
409
+ */
410
+ type AgentContext = DurableObjectState;
411
+ /**
412
+ * Configuration options for Agent routing
413
+ */
414
+ type AgentOptions<Env> = PartyServerOptions<Env> & {
415
+ /**
416
+ * Whether to enable CORS for the Agent
417
+ */
418
+ cors?: boolean | HeadersInit | undefined;
419
+ };
420
+ /**
421
+ * Route a request to the appropriate Agent
422
+ * @param request Request to route
423
+ * @param env Environment containing Agent bindings
424
+ * @param options Routing options
425
+ * @returns Response from the Agent or undefined if no route matched
426
+ */
427
+ declare function routeAgentRequest<Env>(
428
+ request: Request,
429
+ env: Env,
430
+ options?: AgentOptions<Env>
431
+ ): Promise<Response | null>;
432
+ type EmailResolver<Env> = (
433
+ email: ForwardableEmailMessage,
434
+ env: Env
435
+ ) => Promise<{
436
+ agentName: string;
437
+ agentId: string;
438
+ } | null>;
439
+ /**
440
+ * Create a resolver that uses the message-id header to determine the agent to route the email to
441
+ * @returns A function that resolves the agent to route the email to
442
+ */
443
+ declare function createHeaderBasedEmailResolver<Env>(): EmailResolver<Env>;
444
+ /**
445
+ * Create a resolver that uses the email address to determine the agent to route the email to
446
+ * @param defaultAgentName The default agent name to use if the email address does not contain a sub-address
447
+ * @returns A function that resolves the agent to route the email to
448
+ */
449
+ declare function createAddressBasedEmailResolver<Env>(
450
+ defaultAgentName: string
451
+ ): EmailResolver<Env>;
452
+ /**
453
+ * Create a resolver that uses the agentName and agentId to determine the agent to route the email to
454
+ * @param agentName The name of the agent to route the email to
455
+ * @param agentId The id of the agent to route the email to
456
+ * @returns A function that resolves the agent to route the email to
457
+ */
458
+ declare function createCatchAllEmailResolver<Env>(
459
+ agentName: string,
460
+ agentId: string
461
+ ): EmailResolver<Env>;
462
+ type EmailRoutingOptions<Env> = AgentOptions<Env> & {
463
+ resolver: EmailResolver<Env>;
464
+ };
465
+ /**
466
+ * Route an email to the appropriate Agent
467
+ * @param email The email to route
468
+ * @param env The environment containing the Agent bindings
469
+ * @param options The options for routing the email
470
+ * @returns A promise that resolves when the email has been routed
471
+ */
472
+ declare function routeAgentEmail<Env>(
473
+ email: ForwardableEmailMessage,
474
+ env: Env,
475
+ options: EmailRoutingOptions<Env>
476
+ ): Promise<void>;
477
+ type AgentEmail = {
478
+ from: string;
479
+ to: string;
480
+ getRaw: () => Promise<Uint8Array>;
481
+ headers: Headers;
482
+ rawSize: number;
483
+ setReject: (reason: string) => void;
484
+ forward: (rcptTo: string, headers?: Headers) => Promise<void>;
485
+ reply: (options: { from: string; to: string; raw: string }) => Promise<void>;
486
+ };
487
+ type EmailSendOptions = {
488
+ to: string;
489
+ subject: string;
490
+ body: string;
491
+ contentType?: string;
492
+ headers?: Record<string, string>;
493
+ includeRoutingHeaders?: boolean;
494
+ agentName?: string;
495
+ agentId?: string;
496
+ domain?: string;
497
+ };
498
+ /**
499
+ * Get or create an Agent by name
500
+ * @template Env Environment type containing bindings
501
+ * @template T Type of the Agent class
502
+ * @param namespace Agent namespace
503
+ * @param name Name of the Agent instance
504
+ * @param options Options for Agent creation
505
+ * @returns Promise resolving to an Agent instance stub
506
+ */
507
+ declare function getAgentByName<
508
+ Env,
509
+ T extends Agent<Env>,
510
+ Props extends Record<string, unknown> = Record<string, unknown>
511
+ >(
512
+ namespace: AgentNamespace<T>,
513
+ name: string,
514
+ options?: {
515
+ jurisdiction?: DurableObjectJurisdiction;
516
+ locationHint?: DurableObjectLocationHint;
517
+ props?: Props;
518
+ }
519
+ ): Promise<DurableObjectStub<T>>;
520
+ /**
521
+ * A wrapper for streaming responses in callable methods
522
+ */
523
+ declare class StreamingResponse {
524
+ private _connection;
525
+ private _id;
526
+ private _closed;
527
+ constructor(connection: Connection, id: string);
528
+ /**
529
+ * Send a chunk of data to the client
530
+ * @param chunk The data to send
531
+ */
532
+ send(chunk: unknown): void;
533
+ /**
534
+ * End the stream and send the final chunk (if any)
535
+ * @param finalChunk Optional final chunk of data to send
536
+ */
537
+ end(finalChunk?: unknown): void;
538
+ }
539
+ //#endregion
540
+ export {
541
+ unstable_callable as A,
542
+ createAddressBasedEmailResolver as C,
543
+ getCurrentAgent as D,
544
+ getAgentByName as E,
545
+ routeAgentEmail as O,
546
+ callable as S,
547
+ createHeaderBasedEmailResolver as T,
548
+ RPCResponse as _,
549
+ AgentOptions as a,
550
+ StreamingResponse as b,
551
+ ConnectionContext as c,
552
+ EmailSendOptions as d,
553
+ MCPServer as f,
554
+ RPCRequest as g,
555
+ QueueItem as h,
556
+ AgentNamespace as i,
557
+ routeAgentRequest as k,
558
+ EmailResolver as l,
559
+ MCPServersState as m,
560
+ AgentContext as n,
561
+ CallableMetadata as o,
562
+ MCPServerMessage as p,
563
+ AgentEmail as r,
564
+ Connection$1 as s,
565
+ Agent as t,
566
+ EmailRoutingOptions as u,
567
+ Schedule as v,
568
+ createCatchAllEmailResolver as w,
569
+ WSMessage as x,
570
+ StateUpdateMessage as y
571
+ };
572
+ //# sourceMappingURL=index-Bdzb2feZ.d.ts.map