agents 0.0.0-9688c15 → 0.0.0-96add46

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 (76) hide show
  1. package/README.md +255 -27
  2. package/dist/ai-chat-agent.d.ts +47 -18
  3. package/dist/ai-chat-agent.js +532 -228
  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 +261 -201
  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/client-9Ld2_lnt.js +786 -0
  18. package/dist/client-9Ld2_lnt.js.map +1 -0
  19. package/dist/client-BfiZ3HQd.js +117 -0
  20. package/dist/client-BfiZ3HQd.js.map +1 -0
  21. package/dist/client-C1R7IU9g.d.ts +5313 -0
  22. package/dist/client-CbWe9FBd.d.ts +104 -0
  23. package/dist/client.d.ts +12 -86
  24. package/dist/client.js +4 -12
  25. package/dist/codemode/ai.d.ts +27 -0
  26. package/dist/codemode/ai.js +151 -0
  27. package/dist/codemode/ai.js.map +1 -0
  28. package/dist/do-oauth-client-provider-CswoD5Lu.js +93 -0
  29. package/dist/do-oauth-client-provider-CswoD5Lu.js.map +1 -0
  30. package/dist/do-oauth-client-provider-DGc5pP0l.d.ts +55 -0
  31. package/dist/index-DhJCaDWd.d.ts +58 -0
  32. package/dist/index-ZB3447pb.d.ts +560 -0
  33. package/dist/index.d.ts +62 -359
  34. package/dist/index.js +7 -23
  35. package/dist/mcp/client.d.ts +4 -783
  36. package/dist/mcp/client.js +3 -10
  37. package/dist/mcp/do-oauth-client-provider.d.ts +2 -41
  38. package/dist/mcp/do-oauth-client-provider.js +3 -8
  39. package/dist/mcp/index.d.ts +126 -72
  40. package/dist/mcp/index.js +1223 -806
  41. package/dist/mcp/index.js.map +1 -1
  42. package/dist/mcp/x402.d.ts +34 -0
  43. package/dist/mcp/x402.js +194 -0
  44. package/dist/mcp/x402.js.map +1 -0
  45. package/dist/mcp-Dw5vDrY8.d.ts +61 -0
  46. package/dist/observability/index.d.ts +3 -0
  47. package/dist/observability/index.js +7 -0
  48. package/dist/react-CLI3oFqf.d.ts +115 -0
  49. package/dist/react.d.ts +10 -53
  50. package/dist/react.js +183 -102
  51. package/dist/react.js.map +1 -1
  52. package/dist/schedule.d.ts +89 -12
  53. package/dist/schedule.js +46 -23
  54. package/dist/schedule.js.map +1 -1
  55. package/dist/serializable-CymX8ovI.d.ts +39 -0
  56. package/dist/serializable.d.ts +7 -0
  57. package/dist/serializable.js +1 -0
  58. package/dist/src-Dz0H9hSU.js +1200 -0
  59. package/dist/src-Dz0H9hSU.js.map +1 -0
  60. package/package.json +109 -70
  61. package/dist/ai-types.js.map +0 -1
  62. package/dist/chunk-25YDMV4H.js +0 -464
  63. package/dist/chunk-25YDMV4H.js.map +0 -1
  64. package/dist/chunk-D6UOOELW.js +0 -106
  65. package/dist/chunk-D6UOOELW.js.map +0 -1
  66. package/dist/chunk-HMLY7DHA.js +0 -16
  67. package/dist/chunk-HMLY7DHA.js.map +0 -1
  68. package/dist/chunk-RN4SNE73.js +0 -133
  69. package/dist/chunk-RN4SNE73.js.map +0 -1
  70. package/dist/chunk-YFPCCSZO.js +0 -787
  71. package/dist/chunk-YFPCCSZO.js.map +0 -1
  72. package/dist/client.js.map +0 -1
  73. package/dist/index.js.map +0 -1
  74. package/dist/mcp/client.js.map +0 -1
  75. package/dist/mcp/do-oauth-client-provider.js.map +0 -1
  76. package/src/index.ts +0 -1244
package/dist/index.d.ts CHANGED
@@ -1,367 +1,70 @@
1
- import { Server, Connection, PartyServerOptions } from "partyserver";
2
- export { Connection, ConnectionContext, WSMessage } from "partyserver";
3
- import { MCPClientManager } from "./mcp/client.js";
4
- import { Tool, Prompt, Resource } from "@modelcontextprotocol/sdk/types.js";
5
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
6
- import "zod";
7
- import "@modelcontextprotocol/sdk/client/sse.js";
8
- import "./mcp/do-oauth-client-provider.js";
9
- import "@modelcontextprotocol/sdk/client/auth.js";
10
- import "@modelcontextprotocol/sdk/shared/auth.js";
11
- import "@modelcontextprotocol/sdk/shared/protocol.js";
12
- import "ai";
13
-
14
- /**
15
- * RPC request message from client
16
- */
17
- type RPCRequest = {
18
- type: "rpc";
19
- id: string;
20
- method: string;
21
- args: unknown[];
22
- };
23
- /**
24
- * State update message from client
25
- */
26
- type StateUpdateMessage = {
27
- type: "cf_agent_state";
28
- state: unknown;
29
- };
30
- /**
31
- * RPC response message to client
32
- */
33
- type RPCResponse = {
34
- type: "rpc";
35
- id: string;
36
- } & (
37
- | {
38
- success: true;
39
- result: unknown;
40
- done?: false;
41
- }
42
- | {
43
- success: true;
44
- result: unknown;
45
- done: true;
46
- }
47
- | {
48
- success: false;
49
- error: string;
50
- }
51
- );
52
- /**
53
- * Metadata for a callable method
54
- */
55
- type CallableMetadata = {
56
- /** Optional description of what the method does */
57
- description?: string;
58
- /** Whether the method supports streaming responses */
59
- streaming?: boolean;
60
- };
61
- /**
62
- * Decorator that marks a method as callable by clients
63
- * @param metadata Optional metadata about the callable method
64
- */
65
- declare function unstable_callable(
66
- metadata?: CallableMetadata
67
- ): <This, Args extends unknown[], Return>(
68
- target: (this: This, ...args: Args) => Return,
69
- context: ClassMethodDecoratorContext
70
- ) => (this: This, ...args: Args) => Return;
71
- /**
72
- * Represents a scheduled task within an Agent
73
- * @template T Type of the payload data
74
- */
75
- type Schedule<T = string> = {
76
- /** Unique identifier for the schedule */
77
- id: string;
78
- /** Name of the method to be called */
79
- callback: string;
80
- /** Data to be passed to the callback */
81
- payload: T;
82
- } & (
83
- | {
84
- /** Type of schedule for one-time execution at a specific time */
85
- type: "scheduled";
86
- /** Timestamp when the task should execute */
87
- time: number;
88
- }
89
- | {
90
- /** Type of schedule for delayed execution */
91
- type: "delayed";
92
- /** Timestamp when the task should execute */
93
- time: number;
94
- /** Number of seconds to delay execution */
95
- delayInSeconds: number;
96
- }
97
- | {
98
- /** Type of schedule for recurring execution based on cron expression */
99
- type: "cron";
100
- /** Timestamp for the next execution */
101
- time: number;
102
- /** Cron expression defining the schedule */
103
- cron: string;
104
- }
105
- );
106
- /**
107
- * MCP Server state update message from server -> Client
108
- */
109
- type MCPServerMessage = {
110
- type: "cf_agent_mcp_servers";
111
- mcp: MCPServersState;
112
- };
113
- type MCPServersState = {
114
- servers: {
115
- [id: string]: MCPServer;
116
- };
117
- tools: Tool[];
118
- prompts: Prompt[];
119
- resources: Resource[];
120
- };
121
- type MCPServer = {
122
- name: string;
123
- server_url: string;
124
- auth_url: string | null;
125
- state: "authenticating" | "connecting" | "ready" | "discovering" | "failed";
126
- };
127
- declare function getCurrentAgent<
128
- T extends Agent<unknown, unknown> = Agent<unknown, unknown>,
129
- >(): {
130
- agent: T | undefined;
131
- connection: Connection | undefined;
132
- request: Request<unknown, CfProperties<unknown>> | undefined;
133
- };
134
- /**
135
- * Base class for creating Agent implementations
136
- * @template Env Environment type containing bindings
137
- * @template State State type to store within the Agent
138
- */
139
- declare class Agent<Env, State = unknown> extends Server<Env> {
140
- #private;
141
- mcp: MCPClientManager;
142
- /**
143
- * Initial state for the Agent
144
- * Override to provide default state values
145
- */
146
- initialState: State;
147
- /**
148
- * Current state of the Agent
149
- */
150
- get state(): State;
151
- /**
152
- * Agent configuration options
153
- */
154
- static options: {
155
- /** Whether the Agent should hibernate when inactive */
156
- hibernate: boolean;
157
- };
158
- /**
159
- * Execute SQL queries against the Agent's database
160
- * @template T Type of the returned rows
161
- * @param strings SQL query template strings
162
- * @param values Values to be inserted into the query
163
- * @returns Array of query results
164
- */
165
- sql<T = Record<string, string | number | boolean | null>>(
166
- strings: TemplateStringsArray,
167
- ...values: (string | number | boolean | null)[]
168
- ): T[];
169
- constructor(ctx: AgentContext, env: Env);
170
- /**
171
- * Update the Agent's state
172
- * @param state New state to set
173
- */
174
- setState(state: State): void;
175
- /**
176
- * Called when the Agent's state is updated
177
- * @param state Updated state
178
- * @param source Source of the state update ("server" or a client connection)
179
- */
180
- onStateUpdate(state: State | undefined, source: Connection | "server"): void;
181
- /**
182
- * Called when the Agent receives an email
183
- * @param email Email message to process
184
- */
185
- onEmail(email: ForwardableEmailMessage): Promise<void>;
186
- onError(connection: Connection, error: unknown): void | Promise<void>;
187
- onError(error: unknown): void | Promise<void>;
188
- /**
189
- * Render content (not implemented in base class)
190
- */
191
- render(): void;
192
- /**
193
- * Schedule a task to be executed in the future
194
- * @template T Type of the payload data
195
- * @param when When to execute the task (Date, seconds delay, or cron expression)
196
- * @param callback Name of the method to call
197
- * @param payload Data to pass to the callback
198
- * @returns Schedule object representing the scheduled task
199
- */
200
- schedule<T = string>(
201
- when: Date | string | number,
202
- callback: keyof this,
203
- payload?: T
204
- ): Promise<Schedule<T>>;
205
- /**
206
- * Get a scheduled task by ID
207
- * @template T Type of the payload data
208
- * @param id ID of the scheduled task
209
- * @returns The Schedule object or undefined if not found
210
- */
211
- getSchedule<T = string>(id: string): Promise<Schedule<T> | undefined>;
212
- /**
213
- * Get scheduled tasks matching the given criteria
214
- * @template T Type of the payload data
215
- * @param criteria Criteria to filter schedules
216
- * @returns Array of matching Schedule objects
217
- */
218
- getSchedules<T = string>(criteria?: {
219
- id?: string;
220
- type?: "scheduled" | "delayed" | "cron";
221
- timeRange?: {
222
- start?: Date;
223
- end?: Date;
224
- };
225
- }): Schedule<T>[];
226
- /**
227
- * Cancel a scheduled task
228
- * @param id ID of the task to cancel
229
- * @returns true if the task was cancelled, false otherwise
230
- */
231
- cancelSchedule(id: string): Promise<boolean>;
232
- /**
233
- * Method called when an alarm fires.
234
- * Executes any scheduled tasks that are due.
235
- *
236
- * @remarks
237
- * To schedule a task, please use the `this.schedule` method instead.
238
- * See {@link https://developers.cloudflare.com/agents/api-reference/schedule-tasks/}
239
- */
240
- readonly alarm: () => Promise<void>;
241
- /**
242
- * Destroy the Agent, removing all state and scheduled tasks
243
- */
244
- destroy(): Promise<void>;
245
- /**
246
- * Connect to a new MCP Server
247
- *
248
- * @param url MCP Server SSE URL
249
- * @param callbackHost Base host for the agent, used for the redirect URI.
250
- * @param agentsPrefix agents routing prefix if not using `agents`
251
- * @param options MCP client and transport (header) options
252
- * @returns authUrl
253
- */
254
- addMcpServer(
255
- serverName: string,
256
- url: string,
257
- callbackHost: string,
258
- agentsPrefix?: string,
259
- options?: {
260
- client?: ConstructorParameters<typeof Client>[1];
261
- transport?: {
262
- headers: HeadersInit;
263
- };
264
- }
265
- ): Promise<{
266
- id: string;
267
- authUrl: string | undefined;
268
- }>;
269
- removeMcpServer(id: string): Promise<void>;
270
- }
271
- /**
272
- * Namespace for creating Agent instances
273
- * @template Agentic Type of the Agent class
274
- */
275
- type AgentNamespace<Agentic extends Agent<unknown>> =
276
- DurableObjectNamespace<Agentic>;
277
- /**
278
- * Agent's durable context
279
- */
280
- type AgentContext = DurableObjectState;
281
- /**
282
- * Configuration options for Agent routing
283
- */
284
- type AgentOptions<Env> = PartyServerOptions<Env> & {
285
- /**
286
- * Whether to enable CORS for the Agent
287
- */
288
- cors?: boolean | HeadersInit | undefined;
289
- };
290
- /**
291
- * Route a request to the appropriate Agent
292
- * @param request Request to route
293
- * @param env Environment containing Agent bindings
294
- * @param options Routing options
295
- * @returns Response from the Agent or undefined if no route matched
296
- */
297
- declare function routeAgentRequest<Env>(
298
- request: Request,
299
- env: Env,
300
- options?: AgentOptions<Env>
301
- ): Promise<Response | null>;
302
- /**
303
- * Route an email to the appropriate Agent
304
- * @param email Email message to route
305
- * @param env Environment containing Agent bindings
306
- * @param options Routing options
307
- */
308
- declare function routeAgentEmail<Env>(
309
- email: ForwardableEmailMessage,
310
- env: Env,
311
- options?: AgentOptions<Env>
312
- ): Promise<void>;
313
- /**
314
- * Get or create an Agent by name
315
- * @template Env Environment type containing bindings
316
- * @template T Type of the Agent class
317
- * @param namespace Agent namespace
318
- * @param name Name of the Agent instance
319
- * @param options Options for Agent creation
320
- * @returns Promise resolving to an Agent instance stub
321
- */
322
- declare function getAgentByName<Env, T extends Agent<Env>>(
323
- namespace: AgentNamespace<T>,
324
- name: string,
325
- options?: {
326
- jurisdiction?: DurableObjectJurisdiction;
327
- locationHint?: DurableObjectLocationHint;
328
- }
329
- ): Promise<DurableObjectStub<T>>;
330
- /**
331
- * A wrapper for streaming responses in callable methods
332
- */
333
- declare class StreamingResponse {
334
- #private;
335
- constructor(connection: Connection, id: string);
336
- /**
337
- * Send a chunk of data to the client
338
- * @param chunk The data to send
339
- */
340
- send(chunk: unknown): void;
341
- /**
342
- * End the stream and send the final chunk (if any)
343
- * @param finalChunk Optional final chunk of data to send
344
- */
345
- end(finalChunk?: unknown): void;
346
- }
347
-
1
+ import { l as TransportType } from "./client-C1R7IU9g.js";
2
+ import "./mcp-Dw5vDrY8.js";
3
+ import "./do-oauth-client-provider-DGc5pP0l.js";
4
+ import "./index-DhJCaDWd.js";
5
+ import "./ai-types-D5YoPrBZ.js";
6
+ import {
7
+ A as unstable_callable,
8
+ C as createAddressBasedEmailResolver,
9
+ D as getCurrentAgent,
10
+ E as getAgentByName,
11
+ O as routeAgentEmail,
12
+ S as callable,
13
+ T as createHeaderBasedEmailResolver,
14
+ _ as RPCResponse,
15
+ a as AgentOptions,
16
+ b as StreamingResponse,
17
+ c as ConnectionContext,
18
+ d as EmailSendOptions,
19
+ f as MCPServer,
20
+ g as RPCRequest,
21
+ h as QueueItem,
22
+ i as AgentNamespace,
23
+ k as routeAgentRequest,
24
+ l as EmailResolver,
25
+ m as MCPServersState,
26
+ n as AgentContext,
27
+ o as CallableMetadata,
28
+ p as MCPServerMessage,
29
+ r as AgentEmail,
30
+ s as Connection,
31
+ t as Agent,
32
+ u as EmailRoutingOptions,
33
+ v as Schedule,
34
+ w as createCatchAllEmailResolver,
35
+ x as WSMessage,
36
+ y as StateUpdateMessage
37
+ } from "./index-ZB3447pb.js";
348
38
  export {
349
39
  Agent,
350
- type AgentContext,
351
- type AgentNamespace,
352
- type AgentOptions,
353
- type CallableMetadata,
354
- type MCPServer,
355
- type MCPServerMessage,
356
- type MCPServersState,
357
- type RPCRequest,
358
- type RPCResponse,
359
- type Schedule,
360
- type StateUpdateMessage,
40
+ AgentContext,
41
+ AgentEmail,
42
+ AgentNamespace,
43
+ AgentOptions,
44
+ CallableMetadata,
45
+ Connection,
46
+ ConnectionContext,
47
+ EmailResolver,
48
+ EmailRoutingOptions,
49
+ EmailSendOptions,
50
+ MCPServer,
51
+ MCPServerMessage,
52
+ MCPServersState,
53
+ QueueItem,
54
+ RPCRequest,
55
+ RPCResponse,
56
+ Schedule,
57
+ StateUpdateMessage,
361
58
  StreamingResponse,
59
+ TransportType,
60
+ WSMessage,
61
+ callable,
62
+ createAddressBasedEmailResolver,
63
+ createCatchAllEmailResolver,
64
+ createHeaderBasedEmailResolver,
362
65
  getAgentByName,
363
66
  getCurrentAgent,
364
67
  routeAgentEmail,
365
68
  routeAgentRequest,
366
- unstable_callable,
69
+ unstable_callable
367
70
  };
package/dist/index.js CHANGED
@@ -1,23 +1,7 @@
1
- import {
2
- Agent,
3
- StreamingResponse,
4
- getAgentByName,
5
- getCurrentAgent,
6
- routeAgentEmail,
7
- routeAgentRequest,
8
- unstable_callable
9
- } from "./chunk-YFPCCSZO.js";
10
- import "./chunk-D6UOOELW.js";
11
- import "./chunk-RN4SNE73.js";
12
- import "./chunk-25YDMV4H.js";
13
- import "./chunk-HMLY7DHA.js";
14
- export {
15
- Agent,
16
- StreamingResponse,
17
- getAgentByName,
18
- getCurrentAgent,
19
- routeAgentEmail,
20
- routeAgentRequest,
21
- unstable_callable
22
- };
23
- //# sourceMappingURL=index.js.map
1
+ import "./ai-types-B3aQaFv3.js";
2
+ import "./client-BfiZ3HQd.js";
3
+ import "./client-9Ld2_lnt.js";
4
+ import "./do-oauth-client-provider-CswoD5Lu.js";
5
+ import { a as createCatchAllEmailResolver, c as getCurrentAgent, d as unstable_callable, i as createAddressBasedEmailResolver, l as routeAgentEmail, n as StreamingResponse, o as createHeaderBasedEmailResolver, r as callable, s as getAgentByName, t as Agent, u as routeAgentRequest } from "./src-Dz0H9hSU.js";
6
+
7
+ export { Agent, StreamingResponse, callable, createAddressBasedEmailResolver, createCatchAllEmailResolver, createHeaderBasedEmailResolver, getAgentByName, getCurrentAgent, routeAgentEmail, routeAgentRequest, unstable_callable };