agents 0.0.0-db5b372 → 0.0.0-dc7a99c

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 (46) hide show
  1. package/dist/ai-chat-agent.d.ts +32 -6
  2. package/dist/ai-chat-agent.js +149 -115
  3. package/dist/ai-chat-agent.js.map +1 -1
  4. package/dist/ai-react.d.ts +17 -4
  5. package/dist/ai-react.js +29 -29
  6. package/dist/ai-react.js.map +1 -1
  7. package/dist/chunk-767EASBA.js +106 -0
  8. package/dist/chunk-767EASBA.js.map +1 -0
  9. package/dist/{chunk-YZNSS675.js → chunk-E3LCYPCB.js} +71 -37
  10. package/dist/chunk-E3LCYPCB.js.map +1 -0
  11. package/dist/chunk-JFRK72K3.js +910 -0
  12. package/dist/chunk-JFRK72K3.js.map +1 -0
  13. package/dist/chunk-NKZZ66QY.js +116 -0
  14. package/dist/chunk-NKZZ66QY.js.map +1 -0
  15. package/dist/client.d.ts +15 -1
  16. package/dist/client.js +6 -126
  17. package/dist/client.js.map +1 -1
  18. package/dist/index-CITGJflw.d.ts +486 -0
  19. package/dist/index.d.ts +25 -307
  20. package/dist/index.js +8 -7
  21. package/dist/mcp/client.d.ts +310 -23
  22. package/dist/mcp/client.js +1 -2
  23. package/dist/mcp/do-oauth-client-provider.d.ts +3 -3
  24. package/dist/mcp/do-oauth-client-provider.js +3 -103
  25. package/dist/mcp/do-oauth-client-provider.js.map +1 -1
  26. package/dist/mcp/index.d.ts +22 -11
  27. package/dist/mcp/index.js +172 -175
  28. package/dist/mcp/index.js.map +1 -1
  29. package/dist/observability/index.d.ts +12 -0
  30. package/dist/observability/index.js +10 -0
  31. package/dist/react.d.ts +85 -5
  32. package/dist/react.js +20 -8
  33. package/dist/react.js.map +1 -1
  34. package/dist/schedule.d.ts +6 -6
  35. package/dist/schedule.js +4 -6
  36. package/dist/schedule.js.map +1 -1
  37. package/dist/serializable.d.ts +32 -0
  38. package/dist/serializable.js +1 -0
  39. package/dist/serializable.js.map +1 -0
  40. package/package.json +75 -68
  41. package/src/index.ts +538 -91
  42. package/dist/chunk-AV3OMRR4.js +0 -597
  43. package/dist/chunk-AV3OMRR4.js.map +0 -1
  44. package/dist/chunk-HMLY7DHA.js +0 -16
  45. package/dist/chunk-YZNSS675.js.map +0 -1
  46. /package/dist/{chunk-HMLY7DHA.js.map → observability/index.js.map} +0 -0
package/dist/index.d.ts CHANGED
@@ -1,313 +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 { AsyncLocalStorage } from "node:async_hooks";
4
- import { MCPClientManager } from "./mcp/client.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";
5
25
  import "zod";
6
- import "@modelcontextprotocol/sdk/types.js";
7
- import "@modelcontextprotocol/sdk/client/index.js";
8
26
  import "@modelcontextprotocol/sdk/client/sse.js";
27
+ import "@modelcontextprotocol/sdk/shared/protocol.js";
28
+ import "ai";
9
29
  import "./mcp/do-oauth-client-provider.js";
10
30
  import "@modelcontextprotocol/sdk/client/auth.js";
11
31
  import "@modelcontextprotocol/sdk/shared/auth.js";
12
- import "@modelcontextprotocol/sdk/shared/protocol.js";
13
- import "ai";
14
-
15
- /**
16
- * RPC request message from client
17
- */
18
- type RPCRequest = {
19
- type: "rpc";
20
- id: string;
21
- method: string;
22
- args: unknown[];
23
- };
24
- /**
25
- * State update message from client
26
- */
27
- type StateUpdateMessage = {
28
- type: "cf_agent_state";
29
- state: unknown;
30
- };
31
- /**
32
- * RPC response message to client
33
- */
34
- type RPCResponse = {
35
- type: "rpc";
36
- id: string;
37
- } & (
38
- | {
39
- success: true;
40
- result: unknown;
41
- done?: false;
42
- }
43
- | {
44
- success: true;
45
- result: unknown;
46
- done: true;
47
- }
48
- | {
49
- success: false;
50
- error: string;
51
- }
52
- );
53
- /**
54
- * Metadata for a callable method
55
- */
56
- type CallableMetadata = {
57
- /** Optional description of what the method does */
58
- description?: string;
59
- /** Whether the method supports streaming responses */
60
- streaming?: boolean;
61
- };
62
- /**
63
- * Decorator that marks a method as callable by clients
64
- * @param metadata Optional metadata about the callable method
65
- */
66
- declare function unstable_callable(
67
- metadata?: CallableMetadata
68
- ): <This, Args extends unknown[], Return>(
69
- target: (this: This, ...args: Args) => Return,
70
- context: ClassMethodDecoratorContext
71
- ) => (this: This, ...args: Args) => Return;
72
- /**
73
- * Represents a scheduled task within an Agent
74
- * @template T Type of the payload data
75
- */
76
- type Schedule<T = string> = {
77
- /** Unique identifier for the schedule */
78
- id: string;
79
- /** Name of the method to be called */
80
- callback: string;
81
- /** Data to be passed to the callback */
82
- payload: T;
83
- } & (
84
- | {
85
- /** Type of schedule for one-time execution at a specific time */
86
- type: "scheduled";
87
- /** Timestamp when the task should execute */
88
- time: number;
89
- }
90
- | {
91
- /** Type of schedule for delayed execution */
92
- type: "delayed";
93
- /** Timestamp when the task should execute */
94
- time: number;
95
- /** Number of seconds to delay execution */
96
- delayInSeconds: number;
97
- }
98
- | {
99
- /** Type of schedule for recurring execution based on cron expression */
100
- type: "cron";
101
- /** Timestamp for the next execution */
102
- time: number;
103
- /** Cron expression defining the schedule */
104
- cron: string;
105
- }
106
- );
107
- declare const unstable_context: AsyncLocalStorage<{
108
- agent: Agent<unknown>;
109
- connection: Connection | undefined;
110
- request: Request | undefined;
111
- }>;
112
- /**
113
- * Base class for creating Agent implementations
114
- * @template Env Environment type containing bindings
115
- * @template State State type to store within the Agent
116
- */
117
- declare class Agent<Env, State = unknown> extends Server<Env> {
118
- #private;
119
- mcp: MCPClientManager;
120
- /**
121
- * Initial state for the Agent
122
- * Override to provide default state values
123
- */
124
- initialState: State;
125
- /**
126
- * Current state of the Agent
127
- */
128
- get state(): State;
129
- /**
130
- * Agent configuration options
131
- */
132
- static options: {
133
- /** Whether the Agent should hibernate when inactive */
134
- hibernate: boolean;
135
- };
136
- /**
137
- * Execute SQL queries against the Agent's database
138
- * @template T Type of the returned rows
139
- * @param strings SQL query template strings
140
- * @param values Values to be inserted into the query
141
- * @returns Array of query results
142
- */
143
- sql<T = Record<string, string | number | boolean | null>>(
144
- strings: TemplateStringsArray,
145
- ...values: (string | number | boolean | null)[]
146
- ): T[];
147
- constructor(ctx: AgentContext, env: Env);
148
- /**
149
- * Update the Agent's state
150
- * @param state New state to set
151
- */
152
- setState(state: State): void;
153
- /**
154
- * Called when the Agent's state is updated
155
- * @param state Updated state
156
- * @param source Source of the state update ("server" or a client connection)
157
- */
158
- onStateUpdate(state: State | undefined, source: Connection | "server"): void;
159
- /**
160
- * Called when the Agent receives an email
161
- * @param email Email message to process
162
- */
163
- onEmail(email: ForwardableEmailMessage): Promise<void>;
164
- onError(connection: Connection, error: unknown): void | Promise<void>;
165
- onError(error: unknown): void | Promise<void>;
166
- /**
167
- * Render content (not implemented in base class)
168
- */
169
- render(): void;
170
- /**
171
- * Schedule a task to be executed in the future
172
- * @template T Type of the payload data
173
- * @param when When to execute the task (Date, seconds delay, or cron expression)
174
- * @param callback Name of the method to call
175
- * @param payload Data to pass to the callback
176
- * @returns Schedule object representing the scheduled task
177
- */
178
- schedule<T = string>(
179
- when: Date | string | number,
180
- callback: keyof this,
181
- payload?: T
182
- ): Promise<Schedule<T>>;
183
- /**
184
- * Get a scheduled task by ID
185
- * @template T Type of the payload data
186
- * @param id ID of the scheduled task
187
- * @returns The Schedule object or undefined if not found
188
- */
189
- getSchedule<T = string>(id: string): Promise<Schedule<T> | undefined>;
190
- /**
191
- * Get scheduled tasks matching the given criteria
192
- * @template T Type of the payload data
193
- * @param criteria Criteria to filter schedules
194
- * @returns Array of matching Schedule objects
195
- */
196
- getSchedules<T = string>(criteria?: {
197
- id?: string;
198
- type?: "scheduled" | "delayed" | "cron";
199
- timeRange?: {
200
- start?: Date;
201
- end?: Date;
202
- };
203
- }): Schedule<T>[];
204
- /**
205
- * Cancel a scheduled task
206
- * @param id ID of the task to cancel
207
- * @returns true if the task was cancelled, false otherwise
208
- */
209
- cancelSchedule(id: string): Promise<boolean>;
210
- /**
211
- * Method called when an alarm fires
212
- * Executes any scheduled tasks that are due
213
- */
214
- alarm(): Promise<void>;
215
- /**
216
- * Destroy the Agent, removing all state and scheduled tasks
217
- */
218
- destroy(): Promise<void>;
219
- }
220
- /**
221
- * Namespace for creating Agent instances
222
- * @template Agentic Type of the Agent class
223
- */
224
- type AgentNamespace<Agentic extends Agent<unknown>> =
225
- DurableObjectNamespace<Agentic>;
226
- /**
227
- * Agent's durable context
228
- */
229
- type AgentContext = DurableObjectState;
230
- /**
231
- * Configuration options for Agent routing
232
- */
233
- type AgentOptions<Env> = PartyServerOptions<Env> & {
234
- /**
235
- * Whether to enable CORS for the Agent
236
- */
237
- cors?: boolean | HeadersInit | undefined;
238
- };
239
- /**
240
- * Route a request to the appropriate Agent
241
- * @param request Request to route
242
- * @param env Environment containing Agent bindings
243
- * @param options Routing options
244
- * @returns Response from the Agent or undefined if no route matched
245
- */
246
- declare function routeAgentRequest<Env>(
247
- request: Request,
248
- env: Env,
249
- options?: AgentOptions<Env>
250
- ): Promise<Response | null>;
251
- /**
252
- * Route an email to the appropriate Agent
253
- * @param email Email message to route
254
- * @param env Environment containing Agent bindings
255
- * @param options Routing options
256
- */
257
- declare function routeAgentEmail<Env>(
258
- email: ForwardableEmailMessage,
259
- env: Env,
260
- options?: AgentOptions<Env>
261
- ): Promise<void>;
262
- /**
263
- * Get or create an Agent by name
264
- * @template Env Environment type containing bindings
265
- * @template T Type of the Agent class
266
- * @param namespace Agent namespace
267
- * @param name Name of the Agent instance
268
- * @param options Options for Agent creation
269
- * @returns Promise resolving to an Agent instance stub
270
- */
271
- declare function getAgentByName<Env, T extends Agent<Env>>(
272
- namespace: AgentNamespace<T>,
273
- name: string,
274
- options?: {
275
- jurisdiction?: DurableObjectJurisdiction;
276
- locationHint?: DurableObjectLocationHint;
277
- }
278
- ): Promise<DurableObjectStub<T>>;
279
- /**
280
- * A wrapper for streaming responses in callable methods
281
- */
282
- declare class StreamingResponse {
283
- #private;
284
- constructor(connection: Connection, id: string);
285
- /**
286
- * Send a chunk of data to the client
287
- * @param chunk The data to send
288
- */
289
- send(chunk: unknown): void;
290
- /**
291
- * End the stream and send the final chunk (if any)
292
- * @param finalChunk Optional final chunk of data to send
293
- */
294
- end(finalChunk?: unknown): void;
295
- }
296
-
297
- export {
298
- Agent,
299
- type AgentContext,
300
- type AgentNamespace,
301
- type AgentOptions,
302
- type CallableMetadata,
303
- type RPCRequest,
304
- type RPCResponse,
305
- type Schedule,
306
- type StateUpdateMessage,
307
- StreamingResponse,
308
- getAgentByName,
309
- routeAgentEmail,
310
- routeAgentRequest,
311
- unstable_callable,
312
- unstable_context,
313
- };
package/dist/index.js CHANGED
@@ -2,20 +2,21 @@ import {
2
2
  Agent,
3
3
  StreamingResponse,
4
4
  getAgentByName,
5
+ getCurrentAgent,
5
6
  routeAgentEmail,
6
7
  routeAgentRequest,
7
- unstable_callable,
8
- unstable_context
9
- } from "./chunk-AV3OMRR4.js";
10
- import "./chunk-YZNSS675.js";
11
- import "./chunk-HMLY7DHA.js";
8
+ unstable_callable
9
+ } from "./chunk-JFRK72K3.js";
10
+ import "./chunk-E3LCYPCB.js";
11
+ import "./chunk-767EASBA.js";
12
+ import "./chunk-NKZZ66QY.js";
12
13
  export {
13
14
  Agent,
14
15
  StreamingResponse,
15
16
  getAgentByName,
17
+ getCurrentAgent,
16
18
  routeAgentEmail,
17
19
  routeAgentRequest,
18
- unstable_callable,
19
- unstable_context
20
+ unstable_callable
20
21
  };
21
22
  //# sourceMappingURL=index.js.map