agents 0.0.0-ac0e999 → 0.0.0-ac74811

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 (45) hide show
  1. package/dist/ai-chat-agent.d.ts +13 -12
  2. package/dist/ai-chat-agent.js +94 -57
  3. package/dist/ai-chat-agent.js.map +1 -1
  4. package/dist/ai-react.d.ts +9 -8
  5. package/dist/ai-react.js +27 -29
  6. package/dist/ai-react.js.map +1 -1
  7. package/dist/{chunk-D6UOOELW.js → chunk-767EASBA.js} +15 -15
  8. package/dist/chunk-767EASBA.js.map +1 -0
  9. package/dist/{chunk-25YDMV4H.js → chunk-E3LCYPCB.js} +34 -29
  10. package/dist/chunk-E3LCYPCB.js.map +1 -0
  11. package/dist/{chunk-DMJ7L3FI.js → chunk-JFRK72K3.js} +305 -168
  12. package/dist/chunk-JFRK72K3.js.map +1 -0
  13. package/dist/{chunk-ZKIVUOTQ.js → chunk-NKZZ66QY.js} +14 -21
  14. package/dist/chunk-NKZZ66QY.js.map +1 -0
  15. package/dist/client.d.ts +7 -1
  16. package/dist/client.js +1 -2
  17. package/dist/index-CITGJflw.d.ts +486 -0
  18. package/dist/index.d.ts +25 -369
  19. package/dist/index.js +4 -5
  20. package/dist/mcp/client.d.ts +287 -15
  21. package/dist/mcp/client.js +1 -2
  22. package/dist/mcp/do-oauth-client-provider.d.ts +3 -3
  23. package/dist/mcp/do-oauth-client-provider.js +1 -2
  24. package/dist/mcp/index.d.ts +12 -12
  25. package/dist/mcp/index.js +124 -121
  26. package/dist/mcp/index.js.map +1 -1
  27. package/dist/observability/index.d.ts +12 -0
  28. package/dist/observability/index.js +10 -0
  29. package/dist/react.d.ts +76 -10
  30. package/dist/react.js +16 -8
  31. package/dist/react.js.map +1 -1
  32. package/dist/schedule.d.ts +6 -6
  33. package/dist/schedule.js +4 -6
  34. package/dist/schedule.js.map +1 -1
  35. package/dist/serializable.d.ts +32 -0
  36. package/dist/serializable.js +1 -0
  37. package/dist/serializable.js.map +1 -0
  38. package/package.json +75 -71
  39. package/src/index.ts +253 -131
  40. package/dist/chunk-25YDMV4H.js.map +0 -1
  41. package/dist/chunk-D6UOOELW.js.map +0 -1
  42. package/dist/chunk-DMJ7L3FI.js.map +0 -1
  43. package/dist/chunk-NOUFNU2O.js +0 -12
  44. package/dist/chunk-ZKIVUOTQ.js.map +0 -1
  45. /package/dist/{chunk-NOUFNU2O.js.map → observability/index.js.map} +0 -0
package/dist/index.d.ts CHANGED
@@ -1,375 +1,31 @@
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 { Tool, Prompt, Resource } from "@modelcontextprotocol/sdk/types.js";
5
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
4
+ import "./mcp/client.js";
5
+ export {
6
+ A as Agent,
7
+ a as AgentContext,
8
+ i as AgentNamespace,
9
+ j as AgentOptions,
10
+ C as CallableMetadata,
11
+ f as MCPServer,
12
+ e as MCPServerMessage,
13
+ M as MCPServersState,
14
+ R as RPCRequest,
15
+ c as RPCResponse,
16
+ d as Schedule,
17
+ S as StateUpdateMessage,
18
+ m as StreamingResponse,
19
+ l as getAgentByName,
20
+ h as getCurrentAgent,
21
+ k as routeAgentEmail,
22
+ r as routeAgentRequest,
23
+ u as unstable_callable,
24
+ } from "./index-CITGJflw.js";
6
25
  import "zod";
7
26
  import "@modelcontextprotocol/sdk/client/sse.js";
27
+ import "@modelcontextprotocol/sdk/shared/protocol.js";
28
+ import "ai";
8
29
  import "./mcp/do-oauth-client-provider.js";
9
30
  import "@modelcontextprotocol/sdk/client/auth.js";
10
31
  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
- private _state;
142
- private ParentClass;
143
- mcp: MCPClientManager;
144
- /**
145
- * Initial state for the Agent
146
- * Override to provide default state values
147
- */
148
- initialState: State;
149
- /**
150
- * Current state of the Agent
151
- */
152
- get state(): State;
153
- /**
154
- * Agent configuration options
155
- */
156
- static options: {
157
- /** Whether the Agent should hibernate when inactive */
158
- hibernate: boolean;
159
- };
160
- /**
161
- * Execute SQL queries against the Agent's database
162
- * @template T Type of the returned rows
163
- * @param strings SQL query template strings
164
- * @param values Values to be inserted into the query
165
- * @returns Array of query results
166
- */
167
- sql<T = Record<string, string | number | boolean | null>>(
168
- strings: TemplateStringsArray,
169
- ...values: (string | number | boolean | null)[]
170
- ): T[];
171
- constructor(ctx: AgentContext, env: Env);
172
- private setStateInternal;
173
- /**
174
- * Update the Agent's state
175
- * @param state New state to set
176
- */
177
- setState(state: State): void;
178
- /**
179
- * Called when the Agent's state is updated
180
- * @param state Updated state
181
- * @param source Source of the state update ("server" or a client connection)
182
- */
183
- onStateUpdate(state: State | undefined, source: Connection | "server"): void;
184
- /**
185
- * Called when the Agent receives an email
186
- * @param email Email message to process
187
- */
188
- onEmail(email: ForwardableEmailMessage): Promise<void>;
189
- private tryCatch;
190
- onError(connection: Connection, error: unknown): void | Promise<void>;
191
- onError(error: unknown): void | Promise<void>;
192
- /**
193
- * Render content (not implemented in base class)
194
- */
195
- render(): void;
196
- /**
197
- * Schedule a task to be executed in the future
198
- * @template T Type of the payload data
199
- * @param when When to execute the task (Date, seconds delay, or cron expression)
200
- * @param callback Name of the method to call
201
- * @param payload Data to pass to the callback
202
- * @returns Schedule object representing the scheduled task
203
- */
204
- schedule<T = string>(
205
- when: Date | string | number,
206
- callback: keyof this,
207
- payload?: T
208
- ): Promise<Schedule<T>>;
209
- /**
210
- * Get a scheduled task by ID
211
- * @template T Type of the payload data
212
- * @param id ID of the scheduled task
213
- * @returns The Schedule object or undefined if not found
214
- */
215
- getSchedule<T = string>(id: string): Promise<Schedule<T> | undefined>;
216
- /**
217
- * Get scheduled tasks matching the given criteria
218
- * @template T Type of the payload data
219
- * @param criteria Criteria to filter schedules
220
- * @returns Array of matching Schedule objects
221
- */
222
- getSchedules<T = string>(criteria?: {
223
- id?: string;
224
- type?: "scheduled" | "delayed" | "cron";
225
- timeRange?: {
226
- start?: Date;
227
- end?: Date;
228
- };
229
- }): Schedule<T>[];
230
- /**
231
- * Cancel a scheduled task
232
- * @param id ID of the task to cancel
233
- * @returns true if the task was cancelled, false otherwise
234
- */
235
- cancelSchedule(id: string): Promise<boolean>;
236
- private scheduleNextAlarm;
237
- /**
238
- * Method called when an alarm fires.
239
- * Executes any scheduled tasks that are due.
240
- *
241
- * @remarks
242
- * To schedule a task, please use the `this.schedule` method instead.
243
- * See {@link https://developers.cloudflare.com/agents/api-reference/schedule-tasks/}
244
- */
245
- readonly alarm: () => Promise<void>;
246
- /**
247
- * Destroy the Agent, removing all state and scheduled tasks
248
- */
249
- destroy(): Promise<void>;
250
- private isCallable;
251
- /**
252
- * Connect to a new MCP Server
253
- *
254
- * @param url MCP Server SSE URL
255
- * @param callbackHost Base host for the agent, used for the redirect URI.
256
- * @param agentsPrefix agents routing prefix if not using `agents`
257
- * @param options MCP client and transport (header) options
258
- * @returns authUrl
259
- */
260
- addMcpServer(
261
- serverName: string,
262
- url: string,
263
- callbackHost: string,
264
- agentsPrefix?: string,
265
- options?: {
266
- client?: ConstructorParameters<typeof Client>[1];
267
- transport?: {
268
- headers: HeadersInit;
269
- };
270
- }
271
- ): Promise<{
272
- id: string;
273
- authUrl: string | undefined;
274
- }>;
275
- removeMcpServer(id: string): Promise<void>;
276
- }
277
- /**
278
- * Namespace for creating Agent instances
279
- * @template Agentic Type of the Agent class
280
- */
281
- type AgentNamespace<Agentic extends Agent<unknown>> =
282
- DurableObjectNamespace<Agentic>;
283
- /**
284
- * Agent's durable context
285
- */
286
- type AgentContext = DurableObjectState;
287
- /**
288
- * Configuration options for Agent routing
289
- */
290
- type AgentOptions<Env> = PartyServerOptions<Env> & {
291
- /**
292
- * Whether to enable CORS for the Agent
293
- */
294
- cors?: boolean | HeadersInit | undefined;
295
- };
296
- /**
297
- * Route a request to the appropriate Agent
298
- * @param request Request to route
299
- * @param env Environment containing Agent bindings
300
- * @param options Routing options
301
- * @returns Response from the Agent or undefined if no route matched
302
- */
303
- declare function routeAgentRequest<Env>(
304
- request: Request,
305
- env: Env,
306
- options?: AgentOptions<Env>
307
- ): Promise<Response | null>;
308
- /**
309
- * Route an email to the appropriate Agent
310
- * @param email Email message to route
311
- * @param env Environment containing Agent bindings
312
- * @param options Routing options
313
- */
314
- declare function routeAgentEmail<Env>(
315
- email: ForwardableEmailMessage,
316
- env: Env,
317
- options?: AgentOptions<Env>
318
- ): Promise<void>;
319
- /**
320
- * Get or create an Agent by name
321
- * @template Env Environment type containing bindings
322
- * @template T Type of the Agent class
323
- * @param namespace Agent namespace
324
- * @param name Name of the Agent instance
325
- * @param options Options for Agent creation
326
- * @returns Promise resolving to an Agent instance stub
327
- */
328
- declare function getAgentByName<Env, T extends Agent<Env>>(
329
- namespace: AgentNamespace<T>,
330
- name: string,
331
- options?: {
332
- jurisdiction?: DurableObjectJurisdiction;
333
- locationHint?: DurableObjectLocationHint;
334
- }
335
- ): Promise<DurableObjectStub<T>>;
336
- /**
337
- * A wrapper for streaming responses in callable methods
338
- */
339
- declare class StreamingResponse {
340
- private connection;
341
- private id;
342
- private closed;
343
- constructor(connection: Connection, id: string);
344
- /**
345
- * Send a chunk of data to the client
346
- * @param chunk The data to send
347
- */
348
- send(chunk: unknown): void;
349
- /**
350
- * End the stream and send the final chunk (if any)
351
- * @param finalChunk Optional final chunk of data to send
352
- */
353
- end(finalChunk?: unknown): void;
354
- }
355
-
356
- export {
357
- Agent,
358
- type AgentContext,
359
- type AgentNamespace,
360
- type AgentOptions,
361
- type CallableMetadata,
362
- type MCPServer,
363
- type MCPServerMessage,
364
- type MCPServersState,
365
- type RPCRequest,
366
- type RPCResponse,
367
- type Schedule,
368
- type StateUpdateMessage,
369
- StreamingResponse,
370
- getAgentByName,
371
- getCurrentAgent,
372
- routeAgentEmail,
373
- routeAgentRequest,
374
- unstable_callable,
375
- };
package/dist/index.js CHANGED
@@ -6,11 +6,10 @@ import {
6
6
  routeAgentEmail,
7
7
  routeAgentRequest,
8
8
  unstable_callable
9
- } from "./chunk-DMJ7L3FI.js";
10
- import "./chunk-D6UOOELW.js";
11
- import "./chunk-ZKIVUOTQ.js";
12
- import "./chunk-25YDMV4H.js";
13
- import "./chunk-NOUFNU2O.js";
9
+ } from "./chunk-JFRK72K3.js";
10
+ import "./chunk-E3LCYPCB.js";
11
+ import "./chunk-767EASBA.js";
12
+ import "./chunk-NKZZ66QY.js";
14
13
  export {
15
14
  Agent,
16
15
  StreamingResponse,