agents 0.0.0-ee727ca → 0.0.0-eeb70e2

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 (43) hide show
  1. package/README.md +2 -6
  2. package/dist/ai-chat-agent.d.ts +49 -3
  3. package/dist/ai-chat-agent.js +129 -66
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/ai-react.d.ts +13 -0
  6. package/dist/ai-react.js +38 -24
  7. package/dist/ai-react.js.map +1 -1
  8. package/dist/ai-types.d.ts +5 -0
  9. package/dist/chunk-BZXOAZUX.js +106 -0
  10. package/dist/chunk-BZXOAZUX.js.map +1 -0
  11. package/dist/chunk-OYJXQRRH.js +465 -0
  12. package/dist/chunk-OYJXQRRH.js.map +1 -0
  13. package/dist/chunk-P3RZJ72N.js +783 -0
  14. package/dist/chunk-P3RZJ72N.js.map +1 -0
  15. package/dist/chunk-VCSB47AK.js +116 -0
  16. package/dist/chunk-VCSB47AK.js.map +1 -0
  17. package/dist/client.d.ts +15 -1
  18. package/dist/client.js +6 -133
  19. package/dist/client.js.map +1 -1
  20. package/dist/index.d.ts +122 -13
  21. package/dist/index.js +6 -4
  22. package/dist/mcp/client.d.ts +783 -0
  23. package/dist/mcp/client.js +9 -0
  24. package/dist/mcp/do-oauth-client-provider.d.ts +41 -0
  25. package/dist/mcp/do-oauth-client-provider.js +7 -0
  26. package/dist/mcp/do-oauth-client-provider.js.map +1 -0
  27. package/dist/mcp/index.d.ts +84 -0
  28. package/dist/mcp/index.js +782 -0
  29. package/dist/mcp/index.js.map +1 -0
  30. package/dist/react.d.ts +85 -5
  31. package/dist/react.js +48 -29
  32. package/dist/react.js.map +1 -1
  33. package/dist/schedule.js +0 -2
  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 +41 -5
  39. package/src/index.ts +490 -126
  40. package/dist/chunk-HMLY7DHA.js +0 -16
  41. package/dist/chunk-X6BBKLSC.js +0 -568
  42. package/dist/chunk-X6BBKLSC.js.map +0 -1
  43. /package/dist/{chunk-HMLY7DHA.js.map → mcp/client.js.map} +0 -0
package/dist/index.d.ts CHANGED
@@ -1,6 +1,20 @@
1
1
  import { Server, Connection, PartyServerOptions } from "partyserver";
2
2
  export { Connection, ConnectionContext, WSMessage } from "partyserver";
3
- import { WorkflowEntrypoint as WorkflowEntrypoint$1 } from "cloudflare:workers";
3
+ import {
4
+ ServerCapabilities,
5
+ Tool,
6
+ Prompt,
7
+ Resource,
8
+ } from "@modelcontextprotocol/sdk/types.js";
9
+ import { MCPClientManager } from "./mcp/client.js";
10
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
11
+ import "zod";
12
+ import "@modelcontextprotocol/sdk/client/sse.js";
13
+ import "./mcp/do-oauth-client-provider.js";
14
+ import "@modelcontextprotocol/sdk/client/auth.js";
15
+ import "@modelcontextprotocol/sdk/shared/auth.js";
16
+ import "@modelcontextprotocol/sdk/shared/protocol.js";
17
+ import "ai";
4
18
 
5
19
  /**
6
20
  * RPC request message from client
@@ -59,10 +73,6 @@ declare function unstable_callable(
59
73
  target: (this: This, ...args: Args) => Return,
60
74
  context: ClassMethodDecoratorContext
61
75
  ) => (this: This, ...args: Args) => Return;
62
- /**
63
- * A class for creating workflow entry points that can be used with Cloudflare Workers
64
- */
65
- declare class WorkflowEntrypoint extends WorkflowEntrypoint$1 {}
66
76
  /**
67
77
  * Represents a scheduled task within an Agent
68
78
  * @template T Type of the payload data
@@ -98,13 +108,45 @@ type Schedule<T = string> = {
98
108
  cron: string;
99
109
  }
100
110
  );
111
+ /**
112
+ * MCP Server state update message from server -> Client
113
+ */
114
+ type MCPServerMessage = {
115
+ type: "cf_agent_mcp_servers";
116
+ mcp: MCPServersState;
117
+ };
118
+ type MCPServersState = {
119
+ servers: {
120
+ [id: string]: MCPServer;
121
+ };
122
+ tools: Tool[];
123
+ prompts: Prompt[];
124
+ resources: Resource[];
125
+ };
126
+ type MCPServer = {
127
+ name: string;
128
+ server_url: string;
129
+ auth_url: string | null;
130
+ state: "authenticating" | "connecting" | "ready" | "discovering" | "failed";
131
+ instructions: string | null;
132
+ capabilities: ServerCapabilities | null;
133
+ };
134
+ declare function getCurrentAgent<
135
+ T extends Agent<unknown, unknown> = Agent<unknown, unknown>,
136
+ >(): {
137
+ agent: T | undefined;
138
+ connection: Connection | undefined;
139
+ request: Request<unknown, CfProperties<unknown>> | undefined;
140
+ };
101
141
  /**
102
142
  * Base class for creating Agent implementations
103
143
  * @template Env Environment type containing bindings
104
144
  * @template State State type to store within the Agent
105
145
  */
106
146
  declare class Agent<Env, State = unknown> extends Server<Env> {
107
- #private;
147
+ private _state;
148
+ private _ParentClass;
149
+ mcp: MCPClientManager;
108
150
  /**
109
151
  * Initial state for the Agent
110
152
  * Override to provide default state values
@@ -133,6 +175,7 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
133
175
  ...values: (string | number | boolean | null)[]
134
176
  ): T[];
135
177
  constructor(ctx: AgentContext, env: Env);
178
+ private _setStateInternal;
136
179
  /**
137
180
  * Update the Agent's state
138
181
  * @param state New state to set
@@ -148,7 +191,8 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
148
191
  * Called when the Agent receives an email
149
192
  * @param email Email message to process
150
193
  */
151
- onEmail(email: ForwardableEmailMessage): void;
194
+ onEmail(email: ForwardableEmailMessage): Promise<void>;
195
+ private _tryCatch;
152
196
  onError(connection: Connection, error: unknown): void | Promise<void>;
153
197
  onError(error: unknown): void | Promise<void>;
154
198
  /**
@@ -182,7 +226,6 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
182
226
  * @returns Array of matching Schedule objects
183
227
  */
184
228
  getSchedules<T = string>(criteria?: {
185
- description?: string;
186
229
  id?: string;
187
230
  type?: "scheduled" | "delayed" | "cron";
188
231
  timeRange?: {
@@ -196,15 +239,76 @@ declare class Agent<Env, State = unknown> extends Server<Env> {
196
239
  * @returns true if the task was cancelled, false otherwise
197
240
  */
198
241
  cancelSchedule(id: string): Promise<boolean>;
242
+ private _scheduleNextAlarm;
199
243
  /**
200
- * Method called when an alarm fires
201
- * Executes any scheduled tasks that are due
244
+ * Method called when an alarm fires.
245
+ * Executes any scheduled tasks that are due.
246
+ *
247
+ * @remarks
248
+ * To schedule a task, please use the `this.schedule` method instead.
249
+ * See {@link https://developers.cloudflare.com/agents/api-reference/schedule-tasks/}
202
250
  */
203
- alarm(): Promise<void>;
251
+ readonly alarm: () => Promise<void>;
204
252
  /**
205
253
  * Destroy the Agent, removing all state and scheduled tasks
206
254
  */
207
255
  destroy(): Promise<void>;
256
+ /**
257
+ * Get all methods marked as callable on this Agent
258
+ * @returns A map of method names to their metadata
259
+ */
260
+ private _isCallable;
261
+ /**
262
+ * Connect to a new MCP Server
263
+ *
264
+ * @param url MCP Server SSE URL
265
+ * @param callbackHost Base host for the agent, used for the redirect URI.
266
+ * @param agentsPrefix agents routing prefix if not using `agents`
267
+ * @param options MCP client and transport (header) options
268
+ * @returns authUrl
269
+ */
270
+ addMcpServer(
271
+ serverName: string,
272
+ url: string,
273
+ callbackHost: string,
274
+ agentsPrefix?: string,
275
+ options?: {
276
+ client?: ConstructorParameters<typeof Client>[1];
277
+ transport?: {
278
+ headers: HeadersInit;
279
+ };
280
+ }
281
+ ): Promise<{
282
+ id: string;
283
+ authUrl: string | undefined;
284
+ }>;
285
+ _connectToMcpServerInternal(
286
+ serverName: string,
287
+ url: string,
288
+ callbackUrl: string,
289
+ options?: {
290
+ client?: ConstructorParameters<typeof Client>[1];
291
+ /**
292
+ * We don't expose the normal set of transport options because:
293
+ * 1) we can't serialize things like the auth provider or a fetch function into the DB for reconnection purposes
294
+ * 2) We probably want these options to be agnostic to the transport type (SSE vs Streamable)
295
+ *
296
+ * This has the limitation that you can't override fetch, but I think headers should handle nearly all cases needed (i.e. non-standard bearer auth).
297
+ */
298
+ transport?: {
299
+ headers?: HeadersInit;
300
+ };
301
+ },
302
+ reconnect?: {
303
+ id: string;
304
+ oauthClientId?: string;
305
+ }
306
+ ): Promise<{
307
+ id: string;
308
+ authUrl: string | undefined;
309
+ }>;
310
+ removeMcpServer(id: string): Promise<void>;
311
+ getMcpServers(): MCPServersState;
208
312
  }
209
313
  /**
210
314
  * Namespace for creating Agent instances
@@ -269,7 +373,9 @@ declare function getAgentByName<Env, T extends Agent<Env>>(
269
373
  * A wrapper for streaming responses in callable methods
270
374
  */
271
375
  declare class StreamingResponse {
272
- #private;
376
+ private _connection;
377
+ private _id;
378
+ private _closed;
273
379
  constructor(connection: Connection, id: string);
274
380
  /**
275
381
  * Send a chunk of data to the client
@@ -289,13 +395,16 @@ export {
289
395
  type AgentNamespace,
290
396
  type AgentOptions,
291
397
  type CallableMetadata,
398
+ type MCPServer,
399
+ type MCPServerMessage,
400
+ type MCPServersState,
292
401
  type RPCRequest,
293
402
  type RPCResponse,
294
403
  type Schedule,
295
404
  type StateUpdateMessage,
296
405
  StreamingResponse,
297
- WorkflowEntrypoint,
298
406
  getAgentByName,
407
+ getCurrentAgent,
299
408
  routeAgentEmail,
300
409
  routeAgentRequest,
301
410
  unstable_callable,
package/dist/index.js CHANGED
@@ -1,18 +1,20 @@
1
1
  import {
2
2
  Agent,
3
3
  StreamingResponse,
4
- WorkflowEntrypoint,
5
4
  getAgentByName,
5
+ getCurrentAgent,
6
6
  routeAgentEmail,
7
7
  routeAgentRequest,
8
8
  unstable_callable
9
- } from "./chunk-X6BBKLSC.js";
10
- import "./chunk-HMLY7DHA.js";
9
+ } from "./chunk-P3RZJ72N.js";
10
+ import "./chunk-OYJXQRRH.js";
11
+ import "./chunk-BZXOAZUX.js";
12
+ import "./chunk-VCSB47AK.js";
11
13
  export {
12
14
  Agent,
13
15
  StreamingResponse,
14
- WorkflowEntrypoint,
15
16
  getAgentByName,
17
+ getCurrentAgent,
16
18
  routeAgentEmail,
17
19
  routeAgentRequest,
18
20
  unstable_callable