agents 0.0.0-eede2bd → 0.0.0-f31397c

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 +22 -22
  2. package/dist/ai-chat-agent.d.ts +32 -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-MFNGQLFL.js +1260 -0
  11. package/dist/chunk-MFNGQLFL.js.map +1 -0
  12. package/dist/{chunk-Q5ZBHY4Z.js → chunk-MW5BQ2FW.js} +49 -36
  13. package/dist/chunk-MW5BQ2FW.js.map +1 -0
  14. package/dist/chunk-PVQZBKN7.js +106 -0
  15. package/dist/chunk-PVQZBKN7.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 +33 -308
  21. package/dist/index.js +10 -3
  22. package/dist/mcp/client.d.ts +301 -23
  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 +20 -10
  28. package/dist/mcp/index.js +148 -175
  29. package/dist/mcp/index.js.map +1 -1
  30. package/dist/observability/index.d.ts +12 -0
  31. package/dist/observability/index.js +10 -0
  32. package/dist/react.d.ts +85 -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 -69
  42. package/src/index.ts +1059 -137
  43. package/dist/chunk-5W7ZWKOP.js +0 -617
  44. package/dist/chunk-5W7ZWKOP.js.map +0 -1
  45. package/dist/chunk-HMLY7DHA.js +0 -16
  46. package/dist/chunk-Q5ZBHY4Z.js.map +0 -1
  47. /package/dist/{chunk-HMLY7DHA.js.map → observability/index.js.map} +0 -0
package/dist/index.d.ts CHANGED
@@ -1,314 +1,39 @@
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";
7
34
  import "@modelcontextprotocol/sdk/client/sse.js";
35
+ import "@modelcontextprotocol/sdk/shared/protocol.js";
36
+ import "ai";
8
37
  import "./mcp/do-oauth-client-provider.js";
9
38
  import "@modelcontextprotocol/sdk/client/auth.js";
10
39
  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
- alarm(): Promise<void>;
216
- /**
217
- * Destroy the Agent, removing all state and scheduled tasks
218
- */
219
- destroy(): Promise<void>;
220
- }
221
- /**
222
- * Namespace for creating Agent instances
223
- * @template Agentic Type of the Agent class
224
- */
225
- type AgentNamespace<Agentic extends Agent<unknown>> =
226
- DurableObjectNamespace<Agentic>;
227
- /**
228
- * Agent's durable context
229
- */
230
- type AgentContext = DurableObjectState;
231
- /**
232
- * Configuration options for Agent routing
233
- */
234
- type AgentOptions<Env> = PartyServerOptions<Env> & {
235
- /**
236
- * Whether to enable CORS for the Agent
237
- */
238
- cors?: boolean | HeadersInit | undefined;
239
- };
240
- /**
241
- * Route a request to the appropriate Agent
242
- * @param request Request to route
243
- * @param env Environment containing Agent bindings
244
- * @param options Routing options
245
- * @returns Response from the Agent or undefined if no route matched
246
- */
247
- declare function routeAgentRequest<Env>(
248
- request: Request,
249
- env: Env,
250
- options?: AgentOptions<Env>
251
- ): Promise<Response | null>;
252
- /**
253
- * Route an email to the appropriate Agent
254
- * @param email Email message to route
255
- * @param env Environment containing Agent bindings
256
- * @param options Routing options
257
- */
258
- declare function routeAgentEmail<Env>(
259
- email: ForwardableEmailMessage,
260
- env: Env,
261
- options?: AgentOptions<Env>
262
- ): Promise<void>;
263
- /**
264
- * Get or create an Agent by name
265
- * @template Env Environment type containing bindings
266
- * @template T Type of the Agent class
267
- * @param namespace Agent namespace
268
- * @param name Name of the Agent instance
269
- * @param options Options for Agent creation
270
- * @returns Promise resolving to an Agent instance stub
271
- */
272
- declare function getAgentByName<Env, T extends Agent<Env>>(
273
- namespace: AgentNamespace<T>,
274
- name: string,
275
- options?: {
276
- jurisdiction?: DurableObjectJurisdiction;
277
- locationHint?: DurableObjectLocationHint;
278
- }
279
- ): Promise<DurableObjectStub<T>>;
280
- /**
281
- * A wrapper for streaming responses in callable methods
282
- */
283
- declare class StreamingResponse {
284
- #private;
285
- constructor(connection: Connection, id: string);
286
- /**
287
- * Send a chunk of data to the client
288
- * @param chunk The data to send
289
- */
290
- send(chunk: unknown): void;
291
- /**
292
- * End the stream and send the final chunk (if any)
293
- * @param finalChunk Optional final chunk of data to send
294
- */
295
- end(finalChunk?: unknown): void;
296
- }
297
-
298
- export {
299
- Agent,
300
- type AgentContext,
301
- type AgentNamespace,
302
- type AgentOptions,
303
- type CallableMetadata,
304
- type RPCRequest,
305
- type RPCResponse,
306
- type Schedule,
307
- type StateUpdateMessage,
308
- StreamingResponse,
309
- getAgentByName,
310
- getCurrentAgent,
311
- routeAgentEmail,
312
- routeAgentRequest,
313
- unstable_callable,
314
- };
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-5W7ZWKOP.js";
10
- import "./chunk-Q5ZBHY4Z.js";
11
- import "./chunk-HMLY7DHA.js";
12
+ } from "./chunk-MFNGQLFL.js";
13
+ import "./chunk-MW5BQ2FW.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,