agents 0.0.101 → 0.0.102

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.
package/dist/index.d.ts CHANGED
@@ -1,13 +1,27 @@
1
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
- import {
3
- ServerCapabilities,
4
- Tool,
5
- Prompt,
6
- Resource,
7
- } from "@modelcontextprotocol/sdk/types.js";
8
- import { Server, Connection, PartyServerOptions } from "partyserver";
1
+ import "@modelcontextprotocol/sdk/client/index.js";
2
+ import "@modelcontextprotocol/sdk/types.js";
9
3
  export { Connection, ConnectionContext, WSMessage } from "partyserver";
10
- 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";
11
25
  import "zod";
12
26
  import "@modelcontextprotocol/sdk/client/sse.js";
13
27
  import "@modelcontextprotocol/sdk/shared/protocol.js";
@@ -15,398 +29,3 @@ import "ai";
15
29
  import "./mcp/do-oauth-client-provider.js";
16
30
  import "@modelcontextprotocol/sdk/client/auth.js";
17
31
  import "@modelcontextprotocol/sdk/shared/auth.js";
18
-
19
- /**
20
- * RPC request message from client
21
- */
22
- type RPCRequest = {
23
- type: "rpc";
24
- id: string;
25
- method: string;
26
- args: unknown[];
27
- };
28
- /**
29
- * State update message from client
30
- */
31
- type StateUpdateMessage = {
32
- type: "cf_agent_state";
33
- state: unknown;
34
- };
35
- /**
36
- * RPC response message to client
37
- */
38
- type RPCResponse = {
39
- type: "rpc";
40
- id: string;
41
- } & (
42
- | {
43
- success: true;
44
- result: unknown;
45
- done?: false;
46
- }
47
- | {
48
- success: true;
49
- result: unknown;
50
- done: true;
51
- }
52
- | {
53
- success: false;
54
- error: string;
55
- }
56
- );
57
- /**
58
- * Metadata for a callable method
59
- */
60
- type CallableMetadata = {
61
- /** Optional description of what the method does */
62
- description?: string;
63
- /** Whether the method supports streaming responses */
64
- streaming?: boolean;
65
- };
66
- /**
67
- * Decorator that marks a method as callable by clients
68
- * @param metadata Optional metadata about the callable method
69
- */
70
- declare function unstable_callable(
71
- metadata?: CallableMetadata
72
- ): <This, Args extends unknown[], Return>(
73
- target: (this: This, ...args: Args) => Return,
74
- context: ClassMethodDecoratorContext
75
- ) => (this: This, ...args: Args) => Return;
76
- /**
77
- * Represents a scheduled task within an Agent
78
- * @template T Type of the payload data
79
- */
80
- type Schedule<T = string> = {
81
- /** Unique identifier for the schedule */
82
- id: string;
83
- /** Name of the method to be called */
84
- callback: string;
85
- /** Data to be passed to the callback */
86
- payload: T;
87
- } & (
88
- | {
89
- /** Type of schedule for one-time execution at a specific time */
90
- type: "scheduled";
91
- /** Timestamp when the task should execute */
92
- time: number;
93
- }
94
- | {
95
- /** Type of schedule for delayed execution */
96
- type: "delayed";
97
- /** Timestamp when the task should execute */
98
- time: number;
99
- /** Number of seconds to delay execution */
100
- delayInSeconds: number;
101
- }
102
- | {
103
- /** Type of schedule for recurring execution based on cron expression */
104
- type: "cron";
105
- /** Timestamp for the next execution */
106
- time: number;
107
- /** Cron expression defining the schedule */
108
- cron: string;
109
- }
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
- };
141
- /**
142
- * Base class for creating Agent implementations
143
- * @template Env Environment type containing bindings
144
- * @template State State type to store within the Agent
145
- */
146
- declare class Agent<Env, State = unknown> extends Server<Env> {
147
- private _state;
148
- private _ParentClass;
149
- mcp: MCPClientManager;
150
- /**
151
- * Initial state for the Agent
152
- * Override to provide default state values
153
- */
154
- initialState: State;
155
- /**
156
- * Current state of the Agent
157
- */
158
- get state(): State;
159
- /**
160
- * Agent configuration options
161
- */
162
- static options: {
163
- /** Whether the Agent should hibernate when inactive */
164
- hibernate: boolean;
165
- };
166
- /**
167
- * Execute SQL queries against the Agent's database
168
- * @template T Type of the returned rows
169
- * @param strings SQL query template strings
170
- * @param values Values to be inserted into the query
171
- * @returns Array of query results
172
- */
173
- sql<T = Record<string, string | number | boolean | null>>(
174
- strings: TemplateStringsArray,
175
- ...values: (string | number | boolean | null)[]
176
- ): T[];
177
- constructor(ctx: AgentContext, env: Env);
178
- private _setStateInternal;
179
- /**
180
- * Update the Agent's state
181
- * @param state New state to set
182
- */
183
- setState(state: State): void;
184
- /**
185
- * Called when the Agent's state is updated
186
- * @param state Updated state
187
- * @param source Source of the state update ("server" or a client connection)
188
- */
189
- onStateUpdate(state: State | undefined, source: Connection | "server"): void;
190
- /**
191
- * Called when the Agent receives an email
192
- * @param email Email message to process
193
- */
194
- onEmail(email: ForwardableEmailMessage): Promise<void>;
195
- private _tryCatch;
196
- onError(connection: Connection, error: unknown): void | Promise<void>;
197
- onError(error: unknown): void | Promise<void>;
198
- /**
199
- * Render content (not implemented in base class)
200
- */
201
- render(): void;
202
- /**
203
- * Schedule a task to be executed in the future
204
- * @template T Type of the payload data
205
- * @param when When to execute the task (Date, seconds delay, or cron expression)
206
- * @param callback Name of the method to call
207
- * @param payload Data to pass to the callback
208
- * @returns Schedule object representing the scheduled task
209
- */
210
- schedule<T = string>(
211
- when: Date | string | number,
212
- callback: keyof this,
213
- payload?: T
214
- ): Promise<Schedule<T>>;
215
- /**
216
- * Get a scheduled task by ID
217
- * @template T Type of the payload data
218
- * @param id ID of the scheduled task
219
- * @returns The Schedule object or undefined if not found
220
- */
221
- getSchedule<T = string>(id: string): Promise<Schedule<T> | undefined>;
222
- /**
223
- * Get scheduled tasks matching the given criteria
224
- * @template T Type of the payload data
225
- * @param criteria Criteria to filter schedules
226
- * @returns Array of matching Schedule objects
227
- */
228
- getSchedules<T = string>(criteria?: {
229
- id?: string;
230
- type?: "scheduled" | "delayed" | "cron";
231
- timeRange?: {
232
- start?: Date;
233
- end?: Date;
234
- };
235
- }): Schedule<T>[];
236
- /**
237
- * Cancel a scheduled task
238
- * @param id ID of the task to cancel
239
- * @returns true if the task was cancelled, false otherwise
240
- */
241
- cancelSchedule(id: string): Promise<boolean>;
242
- private _scheduleNextAlarm;
243
- /**
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/}
250
- */
251
- readonly alarm: () => Promise<void>;
252
- /**
253
- * Destroy the Agent, removing all state and scheduled tasks
254
- */
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
- clientId: string | undefined;
310
- }>;
311
- removeMcpServer(id: string): Promise<void>;
312
- getMcpServers(): MCPServersState;
313
- }
314
- /**
315
- * Namespace for creating Agent instances
316
- * @template Agentic Type of the Agent class
317
- */
318
- type AgentNamespace<Agentic extends Agent<unknown>> =
319
- DurableObjectNamespace<Agentic>;
320
- /**
321
- * Agent's durable context
322
- */
323
- type AgentContext = DurableObjectState;
324
- /**
325
- * Configuration options for Agent routing
326
- */
327
- type AgentOptions<Env> = PartyServerOptions<Env> & {
328
- /**
329
- * Whether to enable CORS for the Agent
330
- */
331
- cors?: boolean | HeadersInit | undefined;
332
- };
333
- /**
334
- * Route a request to the appropriate Agent
335
- * @param request Request to route
336
- * @param env Environment containing Agent bindings
337
- * @param options Routing options
338
- * @returns Response from the Agent or undefined if no route matched
339
- */
340
- declare function routeAgentRequest<Env>(
341
- request: Request,
342
- env: Env,
343
- options?: AgentOptions<Env>
344
- ): Promise<Response | null>;
345
- /**
346
- * Route an email to the appropriate Agent
347
- * @param email Email message to route
348
- * @param env Environment containing Agent bindings
349
- * @param options Routing options
350
- */
351
- declare function routeAgentEmail<Env>(
352
- _email: ForwardableEmailMessage,
353
- _env: Env,
354
- _options?: AgentOptions<Env>
355
- ): Promise<void>;
356
- /**
357
- * Get or create an Agent by name
358
- * @template Env Environment type containing bindings
359
- * @template T Type of the Agent class
360
- * @param namespace Agent namespace
361
- * @param name Name of the Agent instance
362
- * @param options Options for Agent creation
363
- * @returns Promise resolving to an Agent instance stub
364
- */
365
- declare function getAgentByName<Env, T extends Agent<Env>>(
366
- namespace: AgentNamespace<T>,
367
- name: string,
368
- options?: {
369
- jurisdiction?: DurableObjectJurisdiction;
370
- locationHint?: DurableObjectLocationHint;
371
- }
372
- ): Promise<DurableObjectStub<T>>;
373
- /**
374
- * A wrapper for streaming responses in callable methods
375
- */
376
- declare class StreamingResponse {
377
- private _connection;
378
- private _id;
379
- private _closed;
380
- constructor(connection: Connection, id: string);
381
- /**
382
- * Send a chunk of data to the client
383
- * @param chunk The data to send
384
- */
385
- send(chunk: unknown): void;
386
- /**
387
- * End the stream and send the final chunk (if any)
388
- * @param finalChunk Optional final chunk of data to send
389
- */
390
- end(finalChunk?: unknown): void;
391
- }
392
-
393
- export {
394
- Agent,
395
- type AgentContext,
396
- type AgentNamespace,
397
- type AgentOptions,
398
- type CallableMetadata,
399
- type MCPServer,
400
- type MCPServerMessage,
401
- type MCPServersState,
402
- type RPCRequest,
403
- type RPCResponse,
404
- type Schedule,
405
- type StateUpdateMessage,
406
- StreamingResponse,
407
- getAgentByName,
408
- getCurrentAgent,
409
- routeAgentEmail,
410
- routeAgentRequest,
411
- unstable_callable,
412
- };
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  routeAgentEmail,
7
7
  routeAgentRequest,
8
8
  unstable_callable
9
- } from "./chunk-4CIGD73X.js";
9
+ } from "./chunk-JFRK72K3.js";
10
10
  import "./chunk-E3LCYPCB.js";
11
11
  import "./chunk-767EASBA.js";
12
12
  import "./chunk-NKZZ66QY.js";
package/dist/mcp/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Agent
3
- } from "../chunk-4CIGD73X.js";
3
+ } from "../chunk-JFRK72K3.js";
4
4
  import "../chunk-E3LCYPCB.js";
5
5
  import "../chunk-767EASBA.js";
6
6
  import "../chunk-NKZZ66QY.js";
@@ -0,0 +1,12 @@
1
+ import 'ai';
2
+ export { b as Observability, O as ObservabilityEvent, g as genericObservability } from '../index-CITGJflw.js';
3
+ import '@modelcontextprotocol/sdk/client/index.js';
4
+ import '@modelcontextprotocol/sdk/types.js';
5
+ import 'partyserver';
6
+ import '../mcp/client.js';
7
+ import 'zod';
8
+ import '@modelcontextprotocol/sdk/client/sse.js';
9
+ import '@modelcontextprotocol/sdk/shared/protocol.js';
10
+ import '../mcp/do-oauth-client-provider.js';
11
+ import '@modelcontextprotocol/sdk/client/auth.js';
12
+ import '@modelcontextprotocol/sdk/shared/auth.js';
@@ -0,0 +1,10 @@
1
+ import {
2
+ genericObservability
3
+ } from "../chunk-JFRK72K3.js";
4
+ import "../chunk-E3LCYPCB.js";
5
+ import "../chunk-767EASBA.js";
6
+ import "../chunk-NKZZ66QY.js";
7
+ export {
8
+ genericObservability
9
+ };
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/react.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { PartySocket } from "partysocket";
2
2
  import { usePartySocket } from "partysocket/react";
3
- import { MCPServersState, Agent } from "./index.js";
3
+ import { M as MCPServersState, A as Agent } from "./index-CITGJflw.js";
4
4
  import { StreamOptions } from "./client.js";
5
5
  import { Method, RPCMethod } from "./serializable.js";
6
6
  import "@modelcontextprotocol/sdk/client/index.js";
@@ -16,14 +16,14 @@ declare const unstable_scheduleSchema: z.ZodObject<
16
16
  z.ZodTypeAny,
17
17
  {
18
18
  type: "scheduled" | "delayed" | "cron" | "no-schedule";
19
- cron?: string | undefined;
20
19
  delayInSeconds?: number | undefined;
20
+ cron?: string | undefined;
21
21
  date?: Date | undefined;
22
22
  },
23
23
  {
24
24
  type: "scheduled" | "delayed" | "cron" | "no-schedule";
25
- cron?: string | undefined;
26
25
  delayInSeconds?: number | undefined;
26
+ cron?: string | undefined;
27
27
  date?: Date | undefined;
28
28
  }
29
29
  >;
@@ -34,8 +34,8 @@ declare const unstable_scheduleSchema: z.ZodObject<
34
34
  description: string;
35
35
  when: {
36
36
  type: "scheduled" | "delayed" | "cron" | "no-schedule";
37
- cron?: string | undefined;
38
37
  delayInSeconds?: number | undefined;
38
+ cron?: string | undefined;
39
39
  date?: Date | undefined;
40
40
  };
41
41
  },
@@ -43,8 +43,8 @@ declare const unstable_scheduleSchema: z.ZodObject<
43
43
  description: string;
44
44
  when: {
45
45
  type: "scheduled" | "delayed" | "cron" | "no-schedule";
46
- cron?: string | undefined;
47
46
  delayInSeconds?: number | undefined;
47
+ cron?: string | undefined;
48
48
  date?: Date | undefined;
49
49
  };
50
50
  }
package/package.json CHANGED
@@ -58,6 +58,11 @@
58
58
  "import": "./dist/mcp/do-oauth-client-provider.js",
59
59
  "require": "./dist/mcp/do-oauth-client-provider.js"
60
60
  },
61
+ "./observability": {
62
+ "import": "./dist/observability/index.js",
63
+ "require": "./dist/observability/index.js",
64
+ "types": "./dist/observability/index.d.ts"
65
+ },
61
66
  "./react": {
62
67
  "types": "./dist/react.d.ts",
63
68
  "import": "./dist/react.js",
@@ -96,5 +101,5 @@
96
101
  },
97
102
  "type": "module",
98
103
  "types": "dist/index.d.ts",
99
- "version": "0.0.101"
104
+ "version": "0.0.102"
100
105
  }