agents 0.0.46 → 0.0.48
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 +23 -28
- package/dist/ai-react.d.ts +44 -72
- package/dist/ai-types.d.ts +40 -60
- package/dist/client.d.ts +37 -57
- package/dist/index.d.ts +174 -224
- package/dist/mcp/client.d.ts +675 -0
- package/dist/mcp/index.d.ts +45 -0
- package/dist/react.d.ts +15 -24
- package/dist/schedule.d.ts +20 -30
- package/package.json +11 -6
- package/src/index.ts +0 -6
- package/dist/ai-chat-agent.js +0 -167
- package/dist/ai-chat-agent.js.map +0 -1
- package/dist/ai-react.js +0 -189
- package/dist/ai-react.js.map +0 -1
- package/dist/ai-types.js +0 -1
- package/dist/ai-types.js.map +0 -1
- package/dist/chunk-HMLY7DHA.js +0 -16
- package/dist/chunk-HMLY7DHA.js.map +0 -1
- package/dist/chunk-KRBQHBPA.js +0 -599
- package/dist/chunk-KRBQHBPA.js.map +0 -1
- package/dist/client.js +0 -138
- package/dist/client.js.map +0 -1
- package/dist/index.js +0 -22
- package/dist/index.js.map +0 -1
- package/dist/mcp.d.ts +0 -58
- package/dist/mcp.js +0 -945
- package/dist/mcp.js.map +0 -1
- package/dist/react.js +0 -97
- package/dist/react.js.map +0 -1
- package/dist/schedule.js +0 -73
- package/dist/schedule.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,108 +1,96 @@
|
|
|
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
|
-
|
|
40
|
-
success: false;
|
|
41
|
-
error: string;
|
|
42
|
-
}
|
|
43
|
-
);
|
|
26
|
+
type: "rpc";
|
|
27
|
+
id: string;
|
|
28
|
+
} & ({
|
|
29
|
+
success: true;
|
|
30
|
+
result: unknown;
|
|
31
|
+
done?: false;
|
|
32
|
+
} | {
|
|
33
|
+
success: true;
|
|
34
|
+
result: unknown;
|
|
35
|
+
done: true;
|
|
36
|
+
} | {
|
|
37
|
+
success: false;
|
|
38
|
+
error: string;
|
|
39
|
+
});
|
|
44
40
|
/**
|
|
45
41
|
* Metadata for a callable method
|
|
46
42
|
*/
|
|
47
43
|
type CallableMetadata = {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
/** Optional description of what the method does */
|
|
45
|
+
description?: string;
|
|
46
|
+
/** Whether the method supports streaming responses */
|
|
47
|
+
streaming?: boolean;
|
|
52
48
|
};
|
|
53
49
|
/**
|
|
54
50
|
* Decorator that marks a method as callable by clients
|
|
55
51
|
* @param metadata Optional metadata about the callable method
|
|
56
52
|
*/
|
|
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;
|
|
53
|
+
declare function unstable_callable(metadata?: CallableMetadata): <This, Args extends unknown[], Return>(target: (this: This, ...args: Args) => Return, context: ClassMethodDecoratorContext) => (this: This, ...args: Args) => Return;
|
|
63
54
|
/**
|
|
64
55
|
* A class for creating workflow entry points that can be used with Cloudflare Workers
|
|
65
56
|
*/
|
|
66
|
-
declare class WorkflowEntrypoint extends WorkflowEntrypoint$1 {
|
|
57
|
+
declare class WorkflowEntrypoint extends WorkflowEntrypoint$1 {
|
|
58
|
+
}
|
|
67
59
|
/**
|
|
68
60
|
* Represents a scheduled task within an Agent
|
|
69
61
|
* @template T Type of the payload data
|
|
70
62
|
*/
|
|
71
63
|
type Schedule<T = string> = {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
} & (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
/** Cron expression defining the schedule */
|
|
99
|
-
cron: string;
|
|
100
|
-
}
|
|
101
|
-
);
|
|
64
|
+
/** Unique identifier for the schedule */
|
|
65
|
+
id: string;
|
|
66
|
+
/** Name of the method to be called */
|
|
67
|
+
callback: string;
|
|
68
|
+
/** Data to be passed to the callback */
|
|
69
|
+
payload: T;
|
|
70
|
+
} & ({
|
|
71
|
+
/** Type of schedule for one-time execution at a specific time */
|
|
72
|
+
type: "scheduled";
|
|
73
|
+
/** Timestamp when the task should execute */
|
|
74
|
+
time: number;
|
|
75
|
+
} | {
|
|
76
|
+
/** Type of schedule for delayed execution */
|
|
77
|
+
type: "delayed";
|
|
78
|
+
/** Timestamp when the task should execute */
|
|
79
|
+
time: number;
|
|
80
|
+
/** Number of seconds to delay execution */
|
|
81
|
+
delayInSeconds: number;
|
|
82
|
+
} | {
|
|
83
|
+
/** Type of schedule for recurring execution based on cron expression */
|
|
84
|
+
type: "cron";
|
|
85
|
+
/** Timestamp for the next execution */
|
|
86
|
+
time: number;
|
|
87
|
+
/** Cron expression defining the schedule */
|
|
88
|
+
cron: string;
|
|
89
|
+
});
|
|
102
90
|
declare const unstable_context: AsyncLocalStorage<{
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
91
|
+
agent: Agent<unknown>;
|
|
92
|
+
connection: Connection | undefined;
|
|
93
|
+
request: Request | undefined;
|
|
106
94
|
}>;
|
|
107
95
|
/**
|
|
108
96
|
* Base class for creating Agent implementations
|
|
@@ -110,114 +98,105 @@ declare const unstable_context: AsyncLocalStorage<{
|
|
|
110
98
|
* @template State State type to store within the Agent
|
|
111
99
|
*/
|
|
112
100
|
declare class Agent<Env, State = unknown> extends Server<Env> {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
description?: string;
|
|
192
|
-
id?: string;
|
|
193
|
-
type?: "scheduled" | "delayed" | "cron";
|
|
194
|
-
timeRange?: {
|
|
195
|
-
start?: Date;
|
|
196
|
-
end?: Date;
|
|
101
|
+
#private;
|
|
102
|
+
/**
|
|
103
|
+
* Initial state for the Agent
|
|
104
|
+
* Override to provide default state values
|
|
105
|
+
*/
|
|
106
|
+
initialState: State;
|
|
107
|
+
/**
|
|
108
|
+
* Current state of the Agent
|
|
109
|
+
*/
|
|
110
|
+
get state(): State;
|
|
111
|
+
/**
|
|
112
|
+
* Agent configuration options
|
|
113
|
+
*/
|
|
114
|
+
static options: {
|
|
115
|
+
/** Whether the Agent should hibernate when inactive */
|
|
116
|
+
hibernate: boolean;
|
|
197
117
|
};
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Execute SQL queries against the Agent's database
|
|
120
|
+
* @template T Type of the returned rows
|
|
121
|
+
* @param strings SQL query template strings
|
|
122
|
+
* @param values Values to be inserted into the query
|
|
123
|
+
* @returns Array of query results
|
|
124
|
+
*/
|
|
125
|
+
sql<T = Record<string, string | number | boolean | null>>(strings: TemplateStringsArray, ...values: (string | number | boolean | null)[]): T[];
|
|
126
|
+
constructor(ctx: AgentContext, env: Env);
|
|
127
|
+
/**
|
|
128
|
+
* Update the Agent's state
|
|
129
|
+
* @param state New state to set
|
|
130
|
+
*/
|
|
131
|
+
setState(state: State): void;
|
|
132
|
+
/**
|
|
133
|
+
* Called when the Agent's state is updated
|
|
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>;
|
|
214
194
|
}
|
|
215
195
|
/**
|
|
216
196
|
* Namespace for creating Agent instances
|
|
217
197
|
* @template Agentic Type of the Agent class
|
|
218
198
|
*/
|
|
219
|
-
type AgentNamespace<Agentic extends Agent<unknown>> =
|
|
220
|
-
DurableObjectNamespace<Agentic>;
|
|
199
|
+
type AgentNamespace<Agentic extends Agent<unknown>> = DurableObjectNamespace<Agentic>;
|
|
221
200
|
/**
|
|
222
201
|
* Agent's durable context
|
|
223
202
|
*/
|
|
@@ -226,10 +205,10 @@ type AgentContext = DurableObjectState;
|
|
|
226
205
|
* Configuration options for Agent routing
|
|
227
206
|
*/
|
|
228
207
|
type AgentOptions<Env> = PartyServerOptions<Env> & {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
208
|
+
/**
|
|
209
|
+
* Whether to enable CORS for the Agent
|
|
210
|
+
*/
|
|
211
|
+
cors?: boolean | HeadersInit | undefined;
|
|
233
212
|
};
|
|
234
213
|
/**
|
|
235
214
|
* Route a request to the appropriate Agent
|
|
@@ -238,22 +217,14 @@ type AgentOptions<Env> = PartyServerOptions<Env> & {
|
|
|
238
217
|
* @param options Routing options
|
|
239
218
|
* @returns Response from the Agent or undefined if no route matched
|
|
240
219
|
*/
|
|
241
|
-
declare function routeAgentRequest<Env>(
|
|
242
|
-
request: Request,
|
|
243
|
-
env: Env,
|
|
244
|
-
options?: AgentOptions<Env>
|
|
245
|
-
): Promise<Response | null>;
|
|
220
|
+
declare function routeAgentRequest<Env>(request: Request, env: Env, options?: AgentOptions<Env>): Promise<Response | null>;
|
|
246
221
|
/**
|
|
247
222
|
* Route an email to the appropriate Agent
|
|
248
223
|
* @param email Email message to route
|
|
249
224
|
* @param env Environment containing Agent bindings
|
|
250
225
|
* @param options Routing options
|
|
251
226
|
*/
|
|
252
|
-
declare function routeAgentEmail<Env>(
|
|
253
|
-
email: ForwardableEmailMessage,
|
|
254
|
-
env: Env,
|
|
255
|
-
options?: AgentOptions<Env>
|
|
256
|
-
): Promise<void>;
|
|
227
|
+
declare function routeAgentEmail<Env>(email: ForwardableEmailMessage, env: Env, options?: AgentOptions<Env>): Promise<void>;
|
|
257
228
|
/**
|
|
258
229
|
* Get or create an Agent by name
|
|
259
230
|
* @template Env Environment type containing bindings
|
|
@@ -263,47 +234,26 @@ declare function routeAgentEmail<Env>(
|
|
|
263
234
|
* @param options Options for Agent creation
|
|
264
235
|
* @returns Promise resolving to an Agent instance stub
|
|
265
236
|
*/
|
|
266
|
-
declare function getAgentByName<Env, T extends Agent<Env>>(
|
|
267
|
-
namespace: AgentNamespace<T>,
|
|
268
|
-
name: string,
|
|
269
|
-
options?: {
|
|
237
|
+
declare function getAgentByName<Env, T extends Agent<Env>>(namespace: AgentNamespace<T>, name: string, options?: {
|
|
270
238
|
jurisdiction?: DurableObjectJurisdiction;
|
|
271
239
|
locationHint?: DurableObjectLocationHint;
|
|
272
|
-
|
|
273
|
-
): Promise<DurableObjectStub<T>>;
|
|
240
|
+
}): Promise<DurableObjectStub<T>>;
|
|
274
241
|
/**
|
|
275
242
|
* A wrapper for streaming responses in callable methods
|
|
276
243
|
*/
|
|
277
244
|
declare class StreamingResponse {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
245
|
+
#private;
|
|
246
|
+
constructor(connection: Connection, id: string);
|
|
247
|
+
/**
|
|
248
|
+
* Send a chunk of data to the client
|
|
249
|
+
* @param chunk The data to send
|
|
250
|
+
*/
|
|
251
|
+
send(chunk: unknown): void;
|
|
252
|
+
/**
|
|
253
|
+
* End the stream and send the final chunk (if any)
|
|
254
|
+
* @param finalChunk Optional final chunk of data to send
|
|
255
|
+
*/
|
|
256
|
+
end(finalChunk?: unknown): void;
|
|
290
257
|
}
|
|
291
258
|
|
|
292
|
-
export {
|
|
293
|
-
Agent,
|
|
294
|
-
type AgentContext,
|
|
295
|
-
type AgentNamespace,
|
|
296
|
-
type AgentOptions,
|
|
297
|
-
type CallableMetadata,
|
|
298
|
-
type RPCRequest,
|
|
299
|
-
type RPCResponse,
|
|
300
|
-
type Schedule,
|
|
301
|
-
type StateUpdateMessage,
|
|
302
|
-
StreamingResponse,
|
|
303
|
-
WorkflowEntrypoint,
|
|
304
|
-
getAgentByName,
|
|
305
|
-
routeAgentEmail,
|
|
306
|
-
routeAgentRequest,
|
|
307
|
-
unstable_callable,
|
|
308
|
-
unstable_context,
|
|
309
|
-
};
|
|
259
|
+
export { Agent, type AgentContext, type AgentNamespace, type AgentOptions, type CallableMetadata, type RPCRequest, type RPCResponse, type Schedule, type StateUpdateMessage, StreamingResponse, WorkflowEntrypoint, getAgentByName, routeAgentEmail, routeAgentRequest, unstable_callable, unstable_context };
|