agents 0.0.0-881f11e → 0.0.0-885b3db

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 (47) hide show
  1. package/README.md +127 -22
  2. package/dist/ai-chat-agent.d.ts +33 -5
  3. package/dist/ai-chat-agent.js +149 -115
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/ai-react.d.ts +18 -5
  6. package/dist/ai-react.js +27 -29
  7. package/dist/ai-react.js.map +1 -1
  8. package/dist/chunk-KUH345EY.js +116 -0
  9. package/dist/chunk-KUH345EY.js.map +1 -0
  10. package/dist/chunk-PVQZBKN7.js +106 -0
  11. package/dist/chunk-PVQZBKN7.js.map +1 -0
  12. package/dist/{chunk-7VFQNJFK.js → chunk-UNG3FXYX.js} +99 -36
  13. package/dist/chunk-UNG3FXYX.js.map +1 -0
  14. package/dist/chunk-Z2OUUKK4.js +1270 -0
  15. package/dist/chunk-Z2OUUKK4.js.map +1 -0
  16. package/dist/client.d.ts +16 -2
  17. package/dist/client.js +6 -126
  18. package/dist/client.js.map +1 -1
  19. package/dist/index-BIJvkfYt.d.ts +614 -0
  20. package/dist/index.d.ts +34 -312
  21. package/dist/index.js +10 -3
  22. package/dist/mcp/client.d.ts +302 -33
  23. package/dist/mcp/client.js +1 -2
  24. package/dist/mcp/do-oauth-client-provider.d.ts +3 -3
  25. package/dist/mcp/do-oauth-client-provider.js +3 -103
  26. package/dist/mcp/do-oauth-client-provider.js.map +1 -1
  27. package/dist/mcp/index.d.ts +44 -12
  28. package/dist/mcp/index.js +141 -169
  29. package/dist/mcp/index.js.map +1 -1
  30. package/dist/observability/index.d.ts +13 -0
  31. package/dist/observability/index.js +10 -0
  32. package/dist/react.d.ts +86 -5
  33. package/dist/react.js +20 -8
  34. package/dist/react.js.map +1 -1
  35. package/dist/schedule.d.ts +6 -6
  36. package/dist/schedule.js +4 -6
  37. package/dist/schedule.js.map +1 -1
  38. package/dist/serializable.d.ts +32 -0
  39. package/dist/serializable.js +1 -0
  40. package/dist/serializable.js.map +1 -0
  41. package/package.json +76 -71
  42. package/src/index.ts +1073 -135
  43. package/dist/chunk-7VFQNJFK.js.map +0 -1
  44. package/dist/chunk-HMLY7DHA.js +0 -16
  45. package/dist/chunk-JR3NW4A7.js +0 -621
  46. package/dist/chunk-JR3NW4A7.js.map +0 -1
  47. /package/dist/{chunk-HMLY7DHA.js.map → observability/index.js.map} +0 -0
package/dist/index.d.ts CHANGED
@@ -1,318 +1,40 @@
1
- import { Server, Connection, PartyServerOptions } from "partyserver";
1
+ import "@modelcontextprotocol/sdk/client/index.js";
2
+ import "@modelcontextprotocol/sdk/types.js";
2
3
  export { Connection, ConnectionContext, WSMessage } from "partyserver";
3
- import { MCPClientManager } from "./mcp/client.js";
4
+ import "./mcp/client.js";
5
+ export {
6
+ A as Agent,
7
+ a as AgentContext,
8
+ p as AgentEmail,
9
+ i as AgentNamespace,
10
+ j as AgentOptions,
11
+ C as CallableMetadata,
12
+ E as EmailResolver,
13
+ n as EmailRoutingOptions,
14
+ q as EmailSendOptions,
15
+ f as MCPServer,
16
+ e as MCPServerMessage,
17
+ M as MCPServersState,
18
+ Q as QueueItem,
19
+ R as RPCRequest,
20
+ c as RPCResponse,
21
+ d as Schedule,
22
+ S as StateUpdateMessage,
23
+ t as StreamingResponse,
24
+ l as createAddressBasedEmailResolver,
25
+ m as createCatchAllEmailResolver,
26
+ k as createHeaderBasedEmailResolver,
27
+ s as getAgentByName,
28
+ h as getCurrentAgent,
29
+ o as routeAgentEmail,
30
+ r as routeAgentRequest,
31
+ u as unstable_callable
32
+ } from "./index-BIJvkfYt.js";
4
33
  import "zod";
5
- import "@modelcontextprotocol/sdk/types.js";
6
- import "@modelcontextprotocol/sdk/client/index.js";
34
+ import "@modelcontextprotocol/sdk/shared/protocol.js";
35
+ import "ai";
7
36
  import "@modelcontextprotocol/sdk/client/sse.js";
37
+ import "@modelcontextprotocol/sdk/client/streamableHttp.js";
8
38
  import "./mcp/do-oauth-client-provider.js";
9
39
  import "@modelcontextprotocol/sdk/client/auth.js";
10
40
  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
- declare function getCurrentAgent<
107
- T extends Agent<unknown, unknown> = Agent<unknown, unknown>,
108
- >(): {
109
- agent: T | undefined;
110
- connection: Connection | undefined;
111
- request: Request<unknown, CfProperties<unknown>> | undefined;
112
- };
113
- /**
114
- * Base class for creating Agent implementations
115
- * @template Env Environment type containing bindings
116
- * @template State State type to store within the Agent
117
- */
118
- declare class Agent<Env, State = unknown> extends Server<Env> {
119
- #private;
120
- mcp: MCPClientManager;
121
- /**
122
- * Initial state for the Agent
123
- * Override to provide default state values
124
- */
125
- initialState: State;
126
- /**
127
- * Current state of the Agent
128
- */
129
- get state(): State;
130
- /**
131
- * Agent configuration options
132
- */
133
- static options: {
134
- /** Whether the Agent should hibernate when inactive */
135
- hibernate: boolean;
136
- };
137
- /**
138
- * Execute SQL queries against the Agent's database
139
- * @template T Type of the returned rows
140
- * @param strings SQL query template strings
141
- * @param values Values to be inserted into the query
142
- * @returns Array of query results
143
- */
144
- sql<T = Record<string, string | number | boolean | null>>(
145
- strings: TemplateStringsArray,
146
- ...values: (string | number | boolean | null)[]
147
- ): T[];
148
- constructor(ctx: AgentContext, env: Env);
149
- /**
150
- * Update the Agent's state
151
- * @param state New state to set
152
- */
153
- setState(state: State): void;
154
- /**
155
- * Called when the Agent's state is updated
156
- * @param state Updated state
157
- * @param source Source of the state update ("server" or a client connection)
158
- */
159
- onStateUpdate(state: State | undefined, source: Connection | "server"): void;
160
- /**
161
- * Called when the Agent receives an email
162
- * @param email Email message to process
163
- */
164
- onEmail(email: ForwardableEmailMessage): Promise<void>;
165
- onError(connection: Connection, error: unknown): void | Promise<void>;
166
- onError(error: unknown): void | Promise<void>;
167
- /**
168
- * Render content (not implemented in base class)
169
- */
170
- render(): void;
171
- /**
172
- * Schedule a task to be executed in the future
173
- * @template T Type of the payload data
174
- * @param when When to execute the task (Date, seconds delay, or cron expression)
175
- * @param callback Name of the method to call
176
- * @param payload Data to pass to the callback
177
- * @returns Schedule object representing the scheduled task
178
- */
179
- schedule<T = string>(
180
- when: Date | string | number,
181
- callback: keyof this,
182
- payload?: T
183
- ): Promise<Schedule<T>>;
184
- /**
185
- * Get a scheduled task by ID
186
- * @template T Type of the payload data
187
- * @param id ID of the scheduled task
188
- * @returns The Schedule object or undefined if not found
189
- */
190
- getSchedule<T = string>(id: string): Promise<Schedule<T> | undefined>;
191
- /**
192
- * Get scheduled tasks matching the given criteria
193
- * @template T Type of the payload data
194
- * @param criteria Criteria to filter schedules
195
- * @returns Array of matching Schedule objects
196
- */
197
- getSchedules<T = string>(criteria?: {
198
- id?: string;
199
- type?: "scheduled" | "delayed" | "cron";
200
- timeRange?: {
201
- start?: Date;
202
- end?: Date;
203
- };
204
- }): Schedule<T>[];
205
- /**
206
- * Cancel a scheduled task
207
- * @param id ID of the task to cancel
208
- * @returns true if the task was cancelled, false otherwise
209
- */
210
- cancelSchedule(id: string): Promise<boolean>;
211
- /**
212
- * Method called when an alarm fires.
213
- * Executes any scheduled tasks that are due.
214
- *
215
- * @remarks
216
- * To schedule a task, please use the `this.schedule` method instead.
217
- * See {@link https://developers.cloudflare.com/agents/api-reference/schedule-tasks/}
218
- */
219
- readonly alarm: () => Promise<void>;
220
- /**
221
- * Destroy the Agent, removing all state and scheduled tasks
222
- */
223
- destroy(): Promise<void>;
224
- }
225
- /**
226
- * Namespace for creating Agent instances
227
- * @template Agentic Type of the Agent class
228
- */
229
- type AgentNamespace<Agentic extends Agent<unknown>> =
230
- DurableObjectNamespace<Agentic>;
231
- /**
232
- * Agent's durable context
233
- */
234
- type AgentContext = DurableObjectState;
235
- /**
236
- * Configuration options for Agent routing
237
- */
238
- type AgentOptions<Env> = PartyServerOptions<Env> & {
239
- /**
240
- * Whether to enable CORS for the Agent
241
- */
242
- cors?: boolean | HeadersInit | undefined;
243
- };
244
- /**
245
- * Route a request to the appropriate Agent
246
- * @param request Request to route
247
- * @param env Environment containing Agent bindings
248
- * @param options Routing options
249
- * @returns Response from the Agent or undefined if no route matched
250
- */
251
- declare function routeAgentRequest<Env>(
252
- request: Request,
253
- env: Env,
254
- options?: AgentOptions<Env>
255
- ): Promise<Response | null>;
256
- /**
257
- * Route an email to the appropriate Agent
258
- * @param email Email message to route
259
- * @param env Environment containing Agent bindings
260
- * @param options Routing options
261
- */
262
- declare function routeAgentEmail<Env>(
263
- email: ForwardableEmailMessage,
264
- env: Env,
265
- options?: AgentOptions<Env>
266
- ): Promise<void>;
267
- /**
268
- * Get or create an Agent by name
269
- * @template Env Environment type containing bindings
270
- * @template T Type of the Agent class
271
- * @param namespace Agent namespace
272
- * @param name Name of the Agent instance
273
- * @param options Options for Agent creation
274
- * @returns Promise resolving to an Agent instance stub
275
- */
276
- declare function getAgentByName<Env, T extends Agent<Env>>(
277
- namespace: AgentNamespace<T>,
278
- name: string,
279
- options?: {
280
- jurisdiction?: DurableObjectJurisdiction;
281
- locationHint?: DurableObjectLocationHint;
282
- }
283
- ): Promise<DurableObjectStub<T>>;
284
- /**
285
- * A wrapper for streaming responses in callable methods
286
- */
287
- declare class StreamingResponse {
288
- #private;
289
- constructor(connection: Connection, id: string);
290
- /**
291
- * Send a chunk of data to the client
292
- * @param chunk The data to send
293
- */
294
- send(chunk: unknown): void;
295
- /**
296
- * End the stream and send the final chunk (if any)
297
- * @param finalChunk Optional final chunk of data to send
298
- */
299
- end(finalChunk?: unknown): void;
300
- }
301
-
302
- export {
303
- Agent,
304
- type AgentContext,
305
- type AgentNamespace,
306
- type AgentOptions,
307
- type CallableMetadata,
308
- type RPCRequest,
309
- type RPCResponse,
310
- type Schedule,
311
- type StateUpdateMessage,
312
- StreamingResponse,
313
- getAgentByName,
314
- getCurrentAgent,
315
- routeAgentEmail,
316
- routeAgentRequest,
317
- unstable_callable,
318
- };
package/dist/index.js CHANGED
@@ -1,17 +1,24 @@
1
1
  import {
2
2
  Agent,
3
3
  StreamingResponse,
4
+ createAddressBasedEmailResolver,
5
+ createCatchAllEmailResolver,
6
+ createHeaderBasedEmailResolver,
4
7
  getAgentByName,
5
8
  getCurrentAgent,
6
9
  routeAgentEmail,
7
10
  routeAgentRequest,
8
11
  unstable_callable
9
- } from "./chunk-JR3NW4A7.js";
10
- import "./chunk-7VFQNJFK.js";
11
- import "./chunk-HMLY7DHA.js";
12
+ } from "./chunk-Z2OUUKK4.js";
13
+ import "./chunk-UNG3FXYX.js";
14
+ import "./chunk-PVQZBKN7.js";
15
+ import "./chunk-KUH345EY.js";
12
16
  export {
13
17
  Agent,
14
18
  StreamingResponse,
19
+ createAddressBasedEmailResolver,
20
+ createCatchAllEmailResolver,
21
+ createHeaderBasedEmailResolver,
15
22
  getAgentByName,
16
23
  getCurrentAgent,
17
24
  routeAgentEmail,