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