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