agents 0.7.4 → 0.7.5
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.js +3 -4
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-chat-v5-migration.js +3 -4
- package/dist/ai-chat-v5-migration.js.map +1 -1
- package/dist/ai-react.js +3 -4
- package/dist/ai-react.js.map +1 -1
- package/dist/ai-types.js +1 -2
- package/dist/ai-types.js.map +1 -1
- package/dist/cli/index.js +2 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/client-CgXIwdcc.js +1442 -0
- package/dist/client-CgXIwdcc.js.map +1 -0
- package/dist/client.js +1 -2
- package/dist/client.js.map +1 -1
- package/dist/codemode/ai.js +2 -2
- package/dist/do-oauth-client-provider-C2jurFjW.d.ts +78 -0
- package/dist/email-U_MG7UET.d.ts +157 -0
- package/dist/email.d.ts +16 -146
- package/dist/email.js +2 -2
- package/dist/email.js.map +1 -1
- package/dist/experimental/forever.d.ts +26 -71
- package/dist/experimental/forever.js +1 -2
- package/dist/experimental/forever.js.map +1 -1
- package/dist/experimental/memory/session/index.js +3 -12
- package/dist/experimental/memory/session/index.js.map +1 -1
- package/dist/experimental/sub-agent.js +1 -2
- package/dist/experimental/sub-agent.js.map +1 -1
- package/dist/experimental/workspace.d.ts +273 -0
- package/dist/experimental/workspace.js +1263 -0
- package/dist/experimental/workspace.js.map +1 -0
- package/dist/index-BS_jL8MI.d.ts +492 -0
- package/dist/index-p1XLNvwQ.d.ts +2719 -0
- package/dist/index.d.ts +45 -1320
- package/dist/index.js +3 -5
- package/dist/index.js.map +1 -1
- package/dist/internal_context-DgcmHqS1.d.ts +37 -0
- package/dist/internal_context.d.ts +5 -32
- package/dist/internal_context.js +1 -2
- package/dist/internal_context.js.map +1 -1
- package/dist/mcp/client.d.ts +2 -575
- package/dist/mcp/client.js +1 -847
- package/dist/mcp/do-oauth-client-provider.d.ts +2 -61
- package/dist/mcp/do-oauth-client-provider.js +1 -2
- package/dist/mcp/do-oauth-client-provider.js.map +1 -1
- package/dist/mcp/index.d.ts +2 -95
- package/dist/mcp/index.js +2 -9
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/x402.js +1 -2
- package/dist/mcp/x402.js.map +1 -1
- package/dist/observability/index.d.ts +2 -93
- package/dist/observability/index.js +4 -3
- package/dist/observability/index.js.map +1 -1
- package/dist/react.d.ts +1 -2
- package/dist/react.js +1 -2
- package/dist/react.js.map +1 -1
- package/dist/retries-DXMQGhG3.d.ts +79 -0
- package/dist/retries.d.ts +7 -72
- package/dist/retries.js +1 -1
- package/dist/retries.js.map +1 -1
- package/dist/schedule.js +1 -2
- package/dist/schedule.js.map +1 -1
- package/dist/serializable.js +1 -1
- package/dist/types-BB1plA51.d.ts +15 -0
- package/dist/types.d.ts +1 -14
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/workflow-types-CZNXKj_D.d.ts +260 -0
- package/dist/workflow-types.d.ts +23 -235
- package/dist/workflow-types.js +1 -1
- package/dist/workflow-types.js.map +1 -1
- package/dist/workflows.d.ts +22 -23
- package/dist/workflows.js +5 -6
- package/dist/workflows.js.map +1 -1
- package/package.json +15 -5
- package/dist/agent-eZnMHidZ.d.ts +0 -273
- package/dist/client-connection-D3Wcd6Q6.js +0 -603
- package/dist/client-connection-D3Wcd6Q6.js.map +0 -1
- package/dist/client-storage-BPjfP_is.d.ts +0 -604
- package/dist/mcp/client.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,1330 +1,56 @@
|
|
|
1
|
+
import { r as __DO_NOT_USE_WILL_BREAK__agentContext } from "./internal_context-DgcmHqS1.js";
|
|
2
|
+
import { l as createHeaderBasedEmailResolver } from "./email-U_MG7UET.js";
|
|
3
|
+
import { t as RetryOptions } from "./retries-DXMQGhG3.js";
|
|
1
4
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
C as WSMessage,
|
|
6
|
+
D as routeAgentEmail,
|
|
7
|
+
E as getCurrentAgent,
|
|
8
|
+
O as routeAgentRequest,
|
|
9
|
+
S as StreamingResponse,
|
|
10
|
+
T as getAgentByName,
|
|
11
|
+
_ as RPCRequest,
|
|
12
|
+
a as AgentNamespace,
|
|
13
|
+
b as SqlError,
|
|
14
|
+
c as CallableMetadata,
|
|
15
|
+
d as DEFAULT_AGENT_STATIC_OPTIONS,
|
|
16
|
+
f as EmailRoutingOptions,
|
|
17
|
+
g as QueueItem,
|
|
18
|
+
h as MCPServersState,
|
|
19
|
+
i as AgentContext,
|
|
20
|
+
k as unstable_callable,
|
|
21
|
+
l as Connection,
|
|
22
|
+
m as MCPServerMessage,
|
|
23
|
+
n as AddRpcMcpServerOptions,
|
|
24
|
+
o as AgentOptions,
|
|
25
|
+
ot as TransportType,
|
|
26
|
+
p as MCPServer,
|
|
27
|
+
r as Agent,
|
|
28
|
+
s as AgentStaticOptions,
|
|
29
|
+
t as AddMcpServerOptions,
|
|
30
|
+
u as ConnectionContext,
|
|
31
|
+
v as RPCResponse,
|
|
32
|
+
w as callable,
|
|
33
|
+
x as StateUpdateMessage,
|
|
34
|
+
y as Schedule
|
|
35
|
+
} from "./index-p1XLNvwQ.js";
|
|
7
36
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
AgentMcpOAuthProvider,
|
|
13
|
-
AgentsOAuthProvider,
|
|
14
|
-
DurableObjectOAuthClientProvider
|
|
15
|
-
} from "./mcp/do-oauth-client-provider.js";
|
|
16
|
-
import { McpAgent } from "./mcp/index.js";
|
|
17
|
-
import { MCPClientManager } from "./mcp/client.js";
|
|
18
|
-
import {
|
|
19
|
-
RunWorkflowOptions,
|
|
20
|
-
WorkflowCallback,
|
|
21
|
-
WorkflowEventPayload,
|
|
22
|
-
WorkflowInfo,
|
|
23
|
-
WorkflowPage,
|
|
24
|
-
WorkflowQueryCriteria
|
|
25
|
-
} from "./workflow-types.js";
|
|
26
|
-
import { Observability, ObservabilityEvent } from "./observability/index.js";
|
|
27
|
-
import { MessageType } from "./types.js";
|
|
28
|
-
import {
|
|
29
|
-
Connection,
|
|
30
|
-
Connection as Connection$1,
|
|
31
|
-
ConnectionContext,
|
|
32
|
-
ConnectionContext as ConnectionContext$1,
|
|
33
|
-
PartyServerOptions,
|
|
34
|
-
Server,
|
|
35
|
-
WSMessage
|
|
36
|
-
} from "partyserver";
|
|
37
|
-
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
38
|
-
import {
|
|
39
|
-
Prompt,
|
|
40
|
-
Resource,
|
|
41
|
-
ServerCapabilities,
|
|
42
|
-
Tool
|
|
43
|
-
} from "@modelcontextprotocol/sdk/types.js";
|
|
44
|
-
|
|
45
|
-
//#region src/index.d.ts
|
|
46
|
-
/**
|
|
47
|
-
* RPC request message from client
|
|
48
|
-
*/
|
|
49
|
-
type RPCRequest = {
|
|
50
|
-
type: "rpc";
|
|
51
|
-
id: string;
|
|
52
|
-
method: string;
|
|
53
|
-
args: unknown[];
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
* State update message from client
|
|
57
|
-
*/
|
|
58
|
-
type StateUpdateMessage = {
|
|
59
|
-
type: MessageType.CF_AGENT_STATE;
|
|
60
|
-
state: unknown;
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* RPC response message to client
|
|
64
|
-
*/
|
|
65
|
-
type RPCResponse = {
|
|
66
|
-
type: MessageType.RPC;
|
|
67
|
-
id: string;
|
|
68
|
-
} & (
|
|
69
|
-
| {
|
|
70
|
-
success: true;
|
|
71
|
-
result: unknown;
|
|
72
|
-
done?: false;
|
|
73
|
-
}
|
|
74
|
-
| {
|
|
75
|
-
success: true;
|
|
76
|
-
result: unknown;
|
|
77
|
-
done: true;
|
|
78
|
-
}
|
|
79
|
-
| {
|
|
80
|
-
success: false;
|
|
81
|
-
error: string;
|
|
82
|
-
}
|
|
83
|
-
);
|
|
84
|
-
/**
|
|
85
|
-
* Metadata for a callable method
|
|
86
|
-
*/
|
|
87
|
-
type CallableMetadata = {
|
|
88
|
-
/** Optional description of what the method does */ description?: string /** Whether the method supports streaming responses */;
|
|
89
|
-
streaming?: boolean;
|
|
90
|
-
};
|
|
91
|
-
/**
|
|
92
|
-
* Error class for SQL execution failures, containing the query that failed
|
|
93
|
-
*/
|
|
94
|
-
declare class SqlError extends Error {
|
|
95
|
-
/** The SQL query that failed */
|
|
96
|
-
readonly query: string;
|
|
97
|
-
constructor(query: string, cause: unknown);
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Decorator that marks a method as callable by clients
|
|
101
|
-
* @param metadata Optional metadata about the callable method
|
|
102
|
-
*/
|
|
103
|
-
declare function callable(
|
|
104
|
-
metadata?: CallableMetadata
|
|
105
|
-
): <This, Args extends unknown[], Return>(
|
|
106
|
-
target: (this: This, ...args: Args) => Return,
|
|
107
|
-
_context: ClassMethodDecoratorContext
|
|
108
|
-
) => (this: This, ...args: Args) => Return;
|
|
109
|
-
/**
|
|
110
|
-
* Decorator that marks a method as callable by clients
|
|
111
|
-
* @deprecated this has been renamed to callable, and unstable_callable will be removed in the next major version
|
|
112
|
-
* @param metadata Optional metadata about the callable method
|
|
113
|
-
*/
|
|
114
|
-
declare const unstable_callable: (
|
|
115
|
-
metadata?: CallableMetadata
|
|
116
|
-
) => <This, Args extends unknown[], Return>(
|
|
117
|
-
target: (this: This, ...args: Args) => Return,
|
|
118
|
-
_context: ClassMethodDecoratorContext
|
|
119
|
-
) => (this: This, ...args: Args) => Return;
|
|
120
|
-
type QueueItem<T = string> = {
|
|
121
|
-
id: string;
|
|
122
|
-
payload: T;
|
|
123
|
-
callback: keyof Agent<Cloudflare.Env>;
|
|
124
|
-
created_at: number;
|
|
125
|
-
retry?: RetryOptions;
|
|
126
|
-
};
|
|
127
|
-
/**
|
|
128
|
-
* Represents a scheduled task within an Agent
|
|
129
|
-
* @template T Type of the payload data
|
|
130
|
-
*/
|
|
131
|
-
type Schedule<T = string> = {
|
|
132
|
-
/** Unique identifier for the schedule */ id: string /** Name of the method to be called */;
|
|
133
|
-
callback: string /** Data to be passed to the callback */;
|
|
134
|
-
payload: T /** Retry options for callback execution */;
|
|
135
|
-
retry?: RetryOptions;
|
|
136
|
-
} & (
|
|
137
|
-
| {
|
|
138
|
-
/** Type of schedule for one-time execution at a specific time */ type: "scheduled" /** Timestamp when the task should execute */;
|
|
139
|
-
time: number;
|
|
140
|
-
}
|
|
141
|
-
| {
|
|
142
|
-
/** Type of schedule for delayed execution */ type: "delayed" /** Timestamp when the task should execute */;
|
|
143
|
-
time: number /** Number of seconds to delay execution */;
|
|
144
|
-
delayInSeconds: number;
|
|
145
|
-
}
|
|
146
|
-
| {
|
|
147
|
-
/** Type of schedule for recurring execution based on cron expression */ type: "cron" /** Timestamp for the next execution */;
|
|
148
|
-
time: number /** Cron expression defining the schedule */;
|
|
149
|
-
cron: string;
|
|
150
|
-
}
|
|
151
|
-
| {
|
|
152
|
-
/** Type of schedule for recurring execution at fixed intervals */ type: "interval" /** Timestamp for the next execution */;
|
|
153
|
-
time: number /** Number of seconds between executions */;
|
|
154
|
-
intervalSeconds: number;
|
|
155
|
-
}
|
|
156
|
-
);
|
|
157
|
-
/**
|
|
158
|
-
* MCP Server state update message from server -> Client
|
|
159
|
-
*/
|
|
160
|
-
type MCPServerMessage = {
|
|
161
|
-
type: MessageType.CF_AGENT_MCP_SERVERS;
|
|
162
|
-
mcp: MCPServersState;
|
|
163
|
-
};
|
|
164
|
-
type MCPServersState = {
|
|
165
|
-
servers: {
|
|
166
|
-
[id: string]: MCPServer;
|
|
167
|
-
};
|
|
168
|
-
tools: (Tool & {
|
|
169
|
-
serverId: string;
|
|
170
|
-
})[];
|
|
171
|
-
prompts: (Prompt & {
|
|
172
|
-
serverId: string;
|
|
173
|
-
})[];
|
|
174
|
-
resources: (Resource & {
|
|
175
|
-
serverId: string;
|
|
176
|
-
})[];
|
|
177
|
-
};
|
|
178
|
-
type MCPServer = {
|
|
179
|
-
name: string;
|
|
180
|
-
server_url: string;
|
|
181
|
-
auth_url: string | null;
|
|
182
|
-
state: MCPConnectionState /** May contain untrusted content from external OAuth providers. Escape appropriately for your output context. */;
|
|
183
|
-
error: string | null;
|
|
184
|
-
instructions: string | null;
|
|
185
|
-
capabilities: ServerCapabilities | null;
|
|
186
|
-
};
|
|
187
|
-
/**
|
|
188
|
-
* Options for adding an MCP server
|
|
189
|
-
*/
|
|
190
|
-
type AddMcpServerOptions = {
|
|
191
|
-
/** OAuth callback host (auto-derived from request if omitted) */ callbackHost?: string;
|
|
192
|
-
/**
|
|
193
|
-
* Custom callback URL path — bypasses the default `/agents/{class}/{name}/callback` construction.
|
|
194
|
-
* Required when `sendIdentityOnConnect` is `false` to prevent leaking the instance name.
|
|
195
|
-
* When set, the callback URL becomes `{callbackHost}/{callbackPath}`.
|
|
196
|
-
* The developer must route this path to the agent instance via `getAgentByName`.
|
|
197
|
-
* Should be a plain path (e.g., `/mcp-callback`) — do not include query strings or fragments.
|
|
198
|
-
*/
|
|
199
|
-
callbackPath?: string /** Agents routing prefix (default: "agents") */;
|
|
200
|
-
agentsPrefix?: string /** MCP client options */;
|
|
201
|
-
client?: ConstructorParameters<typeof Client>[1] /** Transport options */;
|
|
202
|
-
transport?: {
|
|
203
|
-
/** Custom headers for authentication (e.g., bearer tokens, CF Access) */ headers?: HeadersInit /** Transport type: "sse", "streamable-http", or "auto" (default) */;
|
|
204
|
-
type?: TransportType;
|
|
205
|
-
} /** Retry options for connection and reconnection attempts */;
|
|
206
|
-
retry?: RetryOptions;
|
|
207
|
-
};
|
|
208
|
-
/**
|
|
209
|
-
* Options for adding an MCP server via RPC (Durable Object binding)
|
|
210
|
-
*/
|
|
211
|
-
type AddRpcMcpServerOptions = {
|
|
212
|
-
/** Props to pass to the McpAgent instance */ props?: Record<string, unknown>;
|
|
213
|
-
};
|
|
214
|
-
/**
|
|
215
|
-
* Default options for Agent configuration.
|
|
216
|
-
* Child classes can override specific options without spreading.
|
|
217
|
-
*/
|
|
218
|
-
declare const DEFAULT_AGENT_STATIC_OPTIONS: {
|
|
219
|
-
/** Whether the Agent should hibernate when inactive */ hibernate: boolean /** Whether to send identity (name, agent) to clients on connect */;
|
|
220
|
-
sendIdentityOnConnect: boolean;
|
|
221
|
-
/**
|
|
222
|
-
* Timeout in seconds before a running interval schedule is considered "hung"
|
|
223
|
-
* and force-reset. Increase this if you have callbacks that legitimately
|
|
224
|
-
* take longer than 30 seconds.
|
|
225
|
-
*/
|
|
226
|
-
hungScheduleTimeoutSeconds: number /** Default retry options for schedule(), queue(), and this.retry() */;
|
|
227
|
-
retry: {
|
|
228
|
-
maxAttempts: number;
|
|
229
|
-
baseDelayMs: number;
|
|
230
|
-
maxDelayMs: number;
|
|
231
|
-
};
|
|
232
|
-
};
|
|
233
|
-
/**
|
|
234
|
-
* Configuration options for the Agent.
|
|
235
|
-
* Override in subclasses via `static options`.
|
|
236
|
-
* All fields are optional - defaults are applied at runtime.
|
|
237
|
-
* Note: `hibernate` defaults to `true` if not specified.
|
|
238
|
-
*/
|
|
239
|
-
interface AgentStaticOptions {
|
|
240
|
-
hibernate?: boolean;
|
|
241
|
-
sendIdentityOnConnect?: boolean;
|
|
242
|
-
hungScheduleTimeoutSeconds?: number;
|
|
243
|
-
/** Default retry options for schedule(), queue(), and this.retry(). */
|
|
244
|
-
retry?: RetryOptions;
|
|
245
|
-
}
|
|
246
|
-
declare function getCurrentAgent<
|
|
247
|
-
T extends Agent<Cloudflare.Env> = Agent<Cloudflare.Env>
|
|
248
|
-
>(): {
|
|
249
|
-
agent: T | undefined;
|
|
250
|
-
connection: Connection$1 | undefined;
|
|
251
|
-
request: Request | undefined;
|
|
252
|
-
email: AgentEmail | undefined;
|
|
253
|
-
};
|
|
254
|
-
/**
|
|
255
|
-
* Extract string keys from Env where the value is a Workflow binding.
|
|
256
|
-
*/
|
|
257
|
-
type WorkflowBinding<E> = {
|
|
258
|
-
[K in keyof E & string]: E[K] extends Workflow ? K : never;
|
|
259
|
-
}[keyof E & string];
|
|
260
|
-
/**
|
|
261
|
-
* Type for workflow name parameter.
|
|
262
|
-
* When Env has typed Workflow bindings, provides autocomplete for those keys.
|
|
263
|
-
* Also accepts any string for dynamic use cases and compatibility.
|
|
264
|
-
* The `string & {}` trick preserves autocomplete while allowing any string.
|
|
265
|
-
*/
|
|
266
|
-
type WorkflowName<E> = WorkflowBinding<E> | (string & {});
|
|
267
|
-
/**
|
|
268
|
-
* Base class for creating Agent implementations
|
|
269
|
-
* @template Env Environment type containing bindings
|
|
270
|
-
* @template State State type to store within the Agent
|
|
271
|
-
*/
|
|
272
|
-
declare class Agent<
|
|
273
|
-
Env extends Cloudflare.Env = Cloudflare.Env,
|
|
274
|
-
State = unknown,
|
|
275
|
-
Props extends Record<string, unknown> = Record<string, unknown>
|
|
276
|
-
> extends Server<Env, Props> {
|
|
277
|
-
private _state;
|
|
278
|
-
private _disposables;
|
|
279
|
-
private _destroyed;
|
|
280
|
-
/**
|
|
281
|
-
* Stores raw state accessors for wrapped connections.
|
|
282
|
-
* Used by internal flag methods (readonly, no-protocol) to read/write
|
|
283
|
-
* _cf_-prefixed keys without going through the user-facing state/setState.
|
|
284
|
-
*/
|
|
285
|
-
private _rawStateAccessors;
|
|
286
|
-
/**
|
|
287
|
-
* Cached persistence-hook dispatch mode, computed once in the constructor.
|
|
288
|
-
* - "new" → call onStateChanged
|
|
289
|
-
* - "old" → call onStateUpdate (deprecated)
|
|
290
|
-
* - "none" → neither hook is overridden, skip entirely
|
|
291
|
-
*/
|
|
292
|
-
private _persistenceHookMode;
|
|
293
|
-
private _ParentClass;
|
|
294
|
-
readonly mcp: MCPClientManager;
|
|
295
|
-
/**
|
|
296
|
-
* Initial state for the Agent
|
|
297
|
-
* Override to provide default state values
|
|
298
|
-
*/
|
|
299
|
-
initialState: State;
|
|
300
|
-
/**
|
|
301
|
-
* Current state of the Agent
|
|
302
|
-
*/
|
|
303
|
-
get state(): State;
|
|
304
|
-
/**
|
|
305
|
-
* Agent configuration options.
|
|
306
|
-
* Override in subclasses - only specify what you want to change.
|
|
307
|
-
* @example
|
|
308
|
-
* class SecureAgent extends Agent {
|
|
309
|
-
* static options = { sendIdentityOnConnect: false };
|
|
310
|
-
* }
|
|
311
|
-
*/
|
|
312
|
-
static options: AgentStaticOptions;
|
|
313
|
-
/**
|
|
314
|
-
* Resolved options (merges defaults with subclass overrides).
|
|
315
|
-
* Cached after first access — static options never change during the
|
|
316
|
-
* lifetime of a Durable Object instance.
|
|
317
|
-
*/
|
|
318
|
-
private _cachedOptions?;
|
|
319
|
-
private get _resolvedOptions();
|
|
320
|
-
/**
|
|
321
|
-
* The observability implementation to use for the Agent
|
|
322
|
-
*/
|
|
323
|
-
observability?: Observability;
|
|
324
|
-
/**
|
|
325
|
-
* Emit an observability event with auto-generated timestamp.
|
|
326
|
-
* @internal
|
|
327
|
-
*/
|
|
328
|
-
protected _emit(
|
|
329
|
-
type: ObservabilityEvent["type"],
|
|
330
|
-
payload?: Record<string, unknown>
|
|
331
|
-
): void;
|
|
332
|
-
/**
|
|
333
|
-
* Execute SQL queries against the Agent's database
|
|
334
|
-
* @template T Type of the returned rows
|
|
335
|
-
* @param strings SQL query template strings
|
|
336
|
-
* @param values Values to be inserted into the query
|
|
337
|
-
* @returns Array of query results
|
|
338
|
-
*/
|
|
339
|
-
sql<T = Record<string, string | number | boolean | null>>(
|
|
340
|
-
strings: TemplateStringsArray,
|
|
341
|
-
...values: (string | number | boolean | null)[]
|
|
342
|
-
): T[];
|
|
343
|
-
constructor(ctx: AgentContext, env: Env);
|
|
344
|
-
/**
|
|
345
|
-
* Check for workflows referencing unknown bindings and warn with migration suggestion.
|
|
346
|
-
*/
|
|
347
|
-
private _checkOrphanedWorkflows;
|
|
348
|
-
/**
|
|
349
|
-
* Broadcast a protocol message only to connections that have protocol
|
|
350
|
-
* messages enabled. Connections where shouldSendProtocolMessages returned
|
|
351
|
-
* false are excluded automatically.
|
|
352
|
-
* @param msg The JSON-encoded protocol message
|
|
353
|
-
* @param excludeIds Additional connection IDs to exclude (e.g. the source)
|
|
354
|
-
*/
|
|
355
|
-
private _broadcastProtocol;
|
|
356
|
-
private _setStateInternal;
|
|
357
|
-
/**
|
|
358
|
-
* Update the Agent's state
|
|
359
|
-
* @param state New state to set
|
|
360
|
-
* @throws Error if called from a readonly connection context
|
|
361
|
-
*/
|
|
362
|
-
setState(state: State): void;
|
|
363
|
-
/**
|
|
364
|
-
* Wraps connection.state and connection.setState so that internal
|
|
365
|
-
* _cf_-prefixed flags (readonly, no-protocol) are hidden from user code
|
|
366
|
-
* and cannot be accidentally overwritten.
|
|
367
|
-
*
|
|
368
|
-
* Idempotent — safe to call multiple times on the same connection.
|
|
369
|
-
* After hibernation, the _rawStateAccessors WeakMap is empty but the
|
|
370
|
-
* connection's state getter still reads from the persisted WebSocket
|
|
371
|
-
* attachment. Calling this method re-captures the raw getter so that
|
|
372
|
-
* predicate methods (isConnectionReadonly, isConnectionProtocolEnabled)
|
|
373
|
-
* work correctly post-hibernation.
|
|
374
|
-
*/
|
|
375
|
-
private _ensureConnectionWrapped;
|
|
376
|
-
/**
|
|
377
|
-
* Mark a connection as readonly or readwrite
|
|
378
|
-
* @param connection The connection to mark
|
|
379
|
-
* @param readonly Whether the connection should be readonly (default: true)
|
|
380
|
-
*/
|
|
381
|
-
setConnectionReadonly(connection: Connection$1, readonly?: boolean): void;
|
|
382
|
-
/**
|
|
383
|
-
* Check if a connection is marked as readonly.
|
|
384
|
-
*
|
|
385
|
-
* Safe to call after hibernation — re-wraps the connection if the
|
|
386
|
-
* in-memory accessor cache was cleared.
|
|
387
|
-
* @param connection The connection to check
|
|
388
|
-
* @returns True if the connection is readonly
|
|
389
|
-
*/
|
|
390
|
-
isConnectionReadonly(connection: Connection$1): boolean;
|
|
391
|
-
/**
|
|
392
|
-
* Override this method to determine if a connection should be readonly on connect
|
|
393
|
-
* @param _connection The connection that is being established
|
|
394
|
-
* @param _ctx Connection context
|
|
395
|
-
* @returns True if the connection should be readonly
|
|
396
|
-
*/
|
|
397
|
-
shouldConnectionBeReadonly(
|
|
398
|
-
_connection: Connection$1,
|
|
399
|
-
_ctx: ConnectionContext$1
|
|
400
|
-
): boolean;
|
|
401
|
-
/**
|
|
402
|
-
* Override this method to control whether protocol messages are sent to a
|
|
403
|
-
* connection. Protocol messages include identity (CF_AGENT_IDENTITY), state
|
|
404
|
-
* sync (CF_AGENT_STATE), and MCP server lists (CF_AGENT_MCP_SERVERS).
|
|
405
|
-
*
|
|
406
|
-
* When this returns `false` for a connection, that connection will not
|
|
407
|
-
* receive any protocol text frames — neither on connect nor via broadcasts.
|
|
408
|
-
* This is useful for binary-only clients (e.g. MQTT devices) that cannot
|
|
409
|
-
* handle JSON text frames.
|
|
410
|
-
*
|
|
411
|
-
* The connection can still send and receive regular messages, use RPC, and
|
|
412
|
-
* participate in all non-protocol communication.
|
|
413
|
-
*
|
|
414
|
-
* @param _connection The connection that is being established
|
|
415
|
-
* @param _ctx Connection context (includes the upgrade request)
|
|
416
|
-
* @returns True if protocol messages should be sent (default), false to suppress them
|
|
417
|
-
*/
|
|
418
|
-
shouldSendProtocolMessages(
|
|
419
|
-
_connection: Connection$1,
|
|
420
|
-
_ctx: ConnectionContext$1
|
|
421
|
-
): boolean;
|
|
422
|
-
/**
|
|
423
|
-
* Check if a connection has protocol messages enabled.
|
|
424
|
-
* Protocol messages include identity, state sync, and MCP server lists.
|
|
425
|
-
*
|
|
426
|
-
* Safe to call after hibernation — re-wraps the connection if the
|
|
427
|
-
* in-memory accessor cache was cleared.
|
|
428
|
-
* @param connection The connection to check
|
|
429
|
-
* @returns True if the connection receives protocol messages
|
|
430
|
-
*/
|
|
431
|
-
isConnectionProtocolEnabled(connection: Connection$1): boolean;
|
|
432
|
-
/**
|
|
433
|
-
* Mark a connection as having protocol messages disabled.
|
|
434
|
-
* Called internally when shouldSendProtocolMessages returns false.
|
|
435
|
-
*/
|
|
436
|
-
private _setConnectionNoProtocol;
|
|
437
|
-
/**
|
|
438
|
-
* Called before the Agent's state is persisted and broadcast.
|
|
439
|
-
* Override to validate or reject an update by throwing an error.
|
|
440
|
-
*
|
|
441
|
-
* IMPORTANT: This hook must be synchronous.
|
|
442
|
-
*/
|
|
443
|
-
validateStateChange(nextState: State, source: Connection$1 | "server"): void;
|
|
444
|
-
/**
|
|
445
|
-
* Called after the Agent's state has been persisted and broadcast to all clients.
|
|
446
|
-
* This is a notification hook — errors here are routed to onError and do not
|
|
447
|
-
* affect state persistence or client broadcasts.
|
|
448
|
-
*
|
|
449
|
-
* @param state Updated state
|
|
450
|
-
* @param source Source of the state update ("server" or a client connection)
|
|
451
|
-
*/
|
|
452
|
-
onStateChanged(
|
|
453
|
-
state: State | undefined,
|
|
454
|
-
source: Connection$1 | "server"
|
|
455
|
-
): void;
|
|
456
|
-
/**
|
|
457
|
-
* @deprecated Renamed to `onStateChanged` — the behavior is identical.
|
|
458
|
-
* `onStateUpdate` will be removed in the next major version.
|
|
459
|
-
*
|
|
460
|
-
* Called after the Agent's state has been persisted and broadcast to all clients.
|
|
461
|
-
* This is a server-side notification hook. For the client-side state callback,
|
|
462
|
-
* see the `onStateUpdate` option in `useAgent` / `AgentClient`.
|
|
463
|
-
*
|
|
464
|
-
* @param state Updated state
|
|
465
|
-
* @param source Source of the state update ("server" or a client connection)
|
|
466
|
-
*/
|
|
467
|
-
onStateUpdate(
|
|
468
|
-
state: State | undefined,
|
|
469
|
-
source: Connection$1 | "server"
|
|
470
|
-
): void;
|
|
471
|
-
/**
|
|
472
|
-
* Dispatch to the appropriate persistence hook based on the mode
|
|
473
|
-
* cached in the constructor. No prototype walks at call time.
|
|
474
|
-
*/
|
|
475
|
-
private _callStatePersistenceHook;
|
|
476
|
-
/**
|
|
477
|
-
* Called when the Agent receives an email via routeAgentEmail()
|
|
478
|
-
* Override this method to handle incoming emails
|
|
479
|
-
* @param email Email message to process
|
|
480
|
-
*/
|
|
481
|
-
_onEmail(email: AgentEmail): Promise<void>;
|
|
482
|
-
/**
|
|
483
|
-
* Reply to an email
|
|
484
|
-
* @param email The email to reply to
|
|
485
|
-
* @param options Options for the reply
|
|
486
|
-
* @param options.secret Secret for signing agent headers (enables secure reply routing).
|
|
487
|
-
* Required if the email was routed via createSecureReplyEmailResolver.
|
|
488
|
-
* Pass explicit `null` to opt-out of signing (not recommended for secure routing).
|
|
489
|
-
* @returns void
|
|
490
|
-
*/
|
|
491
|
-
replyToEmail(
|
|
492
|
-
email: AgentEmail,
|
|
493
|
-
options: {
|
|
494
|
-
fromName: string;
|
|
495
|
-
subject?: string | undefined;
|
|
496
|
-
body: string;
|
|
497
|
-
contentType?: string;
|
|
498
|
-
headers?: Record<string, string>;
|
|
499
|
-
secret?: string | null;
|
|
500
|
-
}
|
|
501
|
-
): Promise<void>;
|
|
502
|
-
private _tryCatch;
|
|
503
|
-
/**
|
|
504
|
-
* Automatically wrap custom methods with agent context
|
|
505
|
-
* This ensures getCurrentAgent() works in all custom methods without decorators
|
|
506
|
-
*/
|
|
507
|
-
private _autoWrapCustomMethods;
|
|
508
|
-
onError(connection: Connection$1, error: unknown): void | Promise<void>;
|
|
509
|
-
onError(error: unknown): void | Promise<void>;
|
|
510
|
-
/**
|
|
511
|
-
* Render content (not implemented in base class)
|
|
512
|
-
*/
|
|
513
|
-
render(): void;
|
|
514
|
-
/**
|
|
515
|
-
* Retry an async operation with exponential backoff and jitter.
|
|
516
|
-
* Retries on all errors by default. Use `shouldRetry` to bail early on non-retryable errors.
|
|
517
|
-
*
|
|
518
|
-
* @param fn The async function to retry. Receives the current attempt number (1-indexed).
|
|
519
|
-
* @param options Retry configuration.
|
|
520
|
-
* @param options.maxAttempts Maximum number of attempts (including the first). Falls back to static options, then 3.
|
|
521
|
-
* @param options.baseDelayMs Base delay in ms for exponential backoff. Falls back to static options, then 100.
|
|
522
|
-
* @param options.maxDelayMs Maximum delay cap in ms. Falls back to static options, then 3000.
|
|
523
|
-
* @param options.shouldRetry Predicate called with the error and next attempt number. Return false to stop retrying immediately. Default: retry all errors.
|
|
524
|
-
* @returns The result of fn on success.
|
|
525
|
-
* @throws The last error if all attempts fail or shouldRetry returns false.
|
|
526
|
-
*/
|
|
527
|
-
retry<T>(
|
|
528
|
-
fn: (attempt: number) => Promise<T>,
|
|
529
|
-
options?: RetryOptions & {
|
|
530
|
-
/** Return false to stop retrying a specific error. Receives the error and the next attempt number. Default: retry all errors. */ shouldRetry?: (
|
|
531
|
-
err: unknown,
|
|
532
|
-
nextAttempt: number
|
|
533
|
-
) => boolean;
|
|
534
|
-
}
|
|
535
|
-
): Promise<T>;
|
|
536
|
-
/**
|
|
537
|
-
* Queue a task to be executed in the future
|
|
538
|
-
* @param callback Name of the method to call
|
|
539
|
-
* @param payload Payload to pass to the callback
|
|
540
|
-
* @param options Options for the queued task
|
|
541
|
-
* @param options.retry Retry options for the callback execution
|
|
542
|
-
* @returns The ID of the queued task
|
|
543
|
-
*/
|
|
544
|
-
queue<T = unknown>(
|
|
545
|
-
callback: keyof this,
|
|
546
|
-
payload: T,
|
|
547
|
-
options?: {
|
|
548
|
-
retry?: RetryOptions;
|
|
549
|
-
}
|
|
550
|
-
): Promise<string>;
|
|
551
|
-
private _flushingQueue;
|
|
552
|
-
private _flushQueue;
|
|
553
|
-
/**
|
|
554
|
-
* Dequeue a task by ID
|
|
555
|
-
* @param id ID of the task to dequeue
|
|
556
|
-
*/
|
|
557
|
-
dequeue(id: string): void;
|
|
558
|
-
/**
|
|
559
|
-
* Dequeue all tasks
|
|
560
|
-
*/
|
|
561
|
-
dequeueAll(): void;
|
|
562
|
-
/**
|
|
563
|
-
* Dequeue all tasks by callback
|
|
564
|
-
* @param callback Name of the callback to dequeue
|
|
565
|
-
*/
|
|
566
|
-
dequeueAllByCallback(callback: string): void;
|
|
567
|
-
/**
|
|
568
|
-
* Get a queued task by ID
|
|
569
|
-
* @param id ID of the task to get
|
|
570
|
-
* @returns The task or undefined if not found
|
|
571
|
-
*/
|
|
572
|
-
getQueue(id: string): QueueItem<string> | undefined;
|
|
573
|
-
/**
|
|
574
|
-
* Get all queues by key and value
|
|
575
|
-
* @param key Key to filter by
|
|
576
|
-
* @param value Value to filter by
|
|
577
|
-
* @returns Array of matching QueueItem objects
|
|
578
|
-
*/
|
|
579
|
-
getQueues(key: string, value: string): QueueItem<string>[];
|
|
580
|
-
/**
|
|
581
|
-
* Schedule a task to be executed in the future
|
|
582
|
-
* @template T Type of the payload data
|
|
583
|
-
* @param when When to execute the task (Date, seconds delay, or cron expression)
|
|
584
|
-
* @param callback Name of the method to call
|
|
585
|
-
* @param payload Data to pass to the callback
|
|
586
|
-
* @param options Options for the scheduled task
|
|
587
|
-
* @param options.retry Retry options for the callback execution
|
|
588
|
-
* @returns Schedule object representing the scheduled task
|
|
589
|
-
*/
|
|
590
|
-
schedule<T = string>(
|
|
591
|
-
when: Date | string | number,
|
|
592
|
-
callback: keyof this,
|
|
593
|
-
payload?: T,
|
|
594
|
-
options?: {
|
|
595
|
-
retry?: RetryOptions;
|
|
596
|
-
}
|
|
597
|
-
): Promise<Schedule<T>>;
|
|
598
|
-
/**
|
|
599
|
-
* Schedule a task to run repeatedly at a fixed interval.
|
|
600
|
-
*
|
|
601
|
-
* This method is **idempotent** — calling it multiple times with the same
|
|
602
|
-
* `callback`, `intervalSeconds`, and `payload` returns the existing schedule
|
|
603
|
-
* instead of creating a duplicate. A different interval or payload is
|
|
604
|
-
* treated as a distinct schedule and creates a new row.
|
|
605
|
-
*
|
|
606
|
-
* This makes it safe to call in `onStart()`, which runs on every Durable
|
|
607
|
-
* Object wake:
|
|
608
|
-
*
|
|
609
|
-
* ```ts
|
|
610
|
-
* async onStart() {
|
|
611
|
-
* // Only one schedule is created, no matter how many times the DO wakes
|
|
612
|
-
* await this.scheduleEvery(30, "tick");
|
|
613
|
-
* }
|
|
614
|
-
* ```
|
|
615
|
-
*
|
|
616
|
-
* @template T Type of the payload data
|
|
617
|
-
* @param intervalSeconds Number of seconds between executions
|
|
618
|
-
* @param callback Name of the method to call
|
|
619
|
-
* @param payload Data to pass to the callback
|
|
620
|
-
* @param options Options for the scheduled task
|
|
621
|
-
* @param options.retry Retry options for the callback execution
|
|
622
|
-
* @returns Schedule object representing the scheduled task
|
|
623
|
-
*/
|
|
624
|
-
scheduleEvery<T = string>(
|
|
625
|
-
intervalSeconds: number,
|
|
626
|
-
callback: keyof this,
|
|
627
|
-
payload?: T,
|
|
628
|
-
options?: {
|
|
629
|
-
retry?: RetryOptions;
|
|
630
|
-
_idempotent?: boolean;
|
|
631
|
-
}
|
|
632
|
-
): Promise<Schedule<T>>;
|
|
633
|
-
/**
|
|
634
|
-
* Get a scheduled task by ID
|
|
635
|
-
* @template T Type of the payload data
|
|
636
|
-
* @param id ID of the scheduled task
|
|
637
|
-
* @returns The Schedule object or undefined if not found
|
|
638
|
-
*/
|
|
639
|
-
getSchedule<T = string>(id: string): Schedule<T> | undefined;
|
|
640
|
-
/**
|
|
641
|
-
* Get scheduled tasks matching the given criteria
|
|
642
|
-
* @template T Type of the payload data
|
|
643
|
-
* @param criteria Criteria to filter schedules
|
|
644
|
-
* @returns Array of matching Schedule objects
|
|
645
|
-
*/
|
|
646
|
-
getSchedules<T = string>(criteria?: {
|
|
647
|
-
id?: string;
|
|
648
|
-
type?: "scheduled" | "delayed" | "cron" | "interval";
|
|
649
|
-
timeRange?: {
|
|
650
|
-
start?: Date;
|
|
651
|
-
end?: Date;
|
|
652
|
-
};
|
|
653
|
-
}): Schedule<T>[];
|
|
654
|
-
/**
|
|
655
|
-
* Cancel a scheduled task
|
|
656
|
-
* @param id ID of the task to cancel
|
|
657
|
-
* @returns true if the task was cancelled, false if the task was not found
|
|
658
|
-
*/
|
|
659
|
-
cancelSchedule(id: string): Promise<boolean>;
|
|
660
|
-
/**
|
|
661
|
-
* Keep the Durable Object alive via alarm heartbeats.
|
|
662
|
-
* Returns a disposer function that stops the heartbeat when called.
|
|
663
|
-
*
|
|
664
|
-
* Use this when you have long-running work and need to prevent the
|
|
665
|
-
* DO from going idle (eviction after ~70-140s of inactivity).
|
|
666
|
-
* The heartbeat fires every 30 seconds via the scheduling system.
|
|
667
|
-
*
|
|
668
|
-
* @experimental This API may change between releases.
|
|
669
|
-
*
|
|
670
|
-
* @example
|
|
671
|
-
* ```ts
|
|
672
|
-
* const dispose = await this.keepAlive();
|
|
673
|
-
* try {
|
|
674
|
-
* // ... long-running work ...
|
|
675
|
-
* } finally {
|
|
676
|
-
* dispose();
|
|
677
|
-
* }
|
|
678
|
-
* ```
|
|
679
|
-
*/
|
|
680
|
-
keepAlive(): Promise<() => void>;
|
|
681
|
-
/**
|
|
682
|
-
* Run an async function while keeping the Durable Object alive.
|
|
683
|
-
* The heartbeat is automatically stopped when the function completes
|
|
684
|
-
* (whether it succeeds or throws).
|
|
685
|
-
*
|
|
686
|
-
* This is the recommended way to use keepAlive — it guarantees cleanup
|
|
687
|
-
* so you cannot forget to dispose the heartbeat.
|
|
688
|
-
*
|
|
689
|
-
* @experimental This API may change between releases.
|
|
690
|
-
*
|
|
691
|
-
* @example
|
|
692
|
-
* ```ts
|
|
693
|
-
* const result = await this.keepAliveWhile(async () => {
|
|
694
|
-
* const data = await longRunningComputation();
|
|
695
|
-
* return data;
|
|
696
|
-
* });
|
|
697
|
-
* ```
|
|
698
|
-
*/
|
|
699
|
-
keepAliveWhile<T>(fn: () => Promise<T>): Promise<T>;
|
|
700
|
-
/**
|
|
701
|
-
* Internal no-op callback invoked by the keepAlive heartbeat schedule.
|
|
702
|
-
* Its only purpose is to keep the DO alive — the alarm machinery
|
|
703
|
-
* handles the rest.
|
|
704
|
-
* @internal
|
|
705
|
-
*/
|
|
706
|
-
_cf_keepAliveHeartbeat(): Promise<void>;
|
|
707
|
-
private _scheduleNextAlarm;
|
|
708
|
-
/**
|
|
709
|
-
* Override PartyServer's onAlarm hook as a no-op.
|
|
710
|
-
* Agent handles alarm logic directly in the alarm() method override,
|
|
711
|
-
* but super.alarm() calls onAlarm() after #ensureInitialized(),
|
|
712
|
-
* so we suppress the default "Implement onAlarm" warning.
|
|
713
|
-
*/
|
|
714
|
-
onAlarm(): void;
|
|
715
|
-
/**
|
|
716
|
-
* Method called when an alarm fires.
|
|
717
|
-
* Executes any scheduled tasks that are due.
|
|
718
|
-
*
|
|
719
|
-
* Calls super.alarm() first to ensure PartyServer's #ensureInitialized()
|
|
720
|
-
* runs, which hydrates this.name from storage and calls onStart() if needed.
|
|
721
|
-
*
|
|
722
|
-
* @remarks
|
|
723
|
-
* To schedule a task, please use the `this.schedule` method instead.
|
|
724
|
-
* See {@link https://developers.cloudflare.com/agents/api-reference/schedule-tasks/}
|
|
725
|
-
*/
|
|
726
|
-
alarm(): Promise<void>;
|
|
727
|
-
/**
|
|
728
|
-
* Destroy the Agent, removing all state and scheduled tasks
|
|
729
|
-
*/
|
|
730
|
-
destroy(): Promise<void>;
|
|
731
|
-
/**
|
|
732
|
-
* Check if a method is callable
|
|
733
|
-
* @param method The method name to check
|
|
734
|
-
* @returns True if the method is marked as callable
|
|
735
|
-
*/
|
|
736
|
-
private _isCallable;
|
|
737
|
-
/**
|
|
738
|
-
* Get all methods marked as callable on this Agent
|
|
739
|
-
* @returns A map of method names to their metadata
|
|
740
|
-
*/
|
|
741
|
-
getCallableMethods(): Map<string, CallableMetadata>;
|
|
742
|
-
/**
|
|
743
|
-
* Start a workflow and track it in this Agent's database.
|
|
744
|
-
* Automatically injects agent identity into the workflow params.
|
|
745
|
-
*
|
|
746
|
-
* @template P - Type of params to pass to the workflow
|
|
747
|
-
* @param workflowName - Name of the workflow binding in env (e.g., 'MY_WORKFLOW')
|
|
748
|
-
* @param params - Params to pass to the workflow
|
|
749
|
-
* @param options - Optional workflow options
|
|
750
|
-
* @returns The workflow instance ID
|
|
751
|
-
*
|
|
752
|
-
* @example
|
|
753
|
-
* ```typescript
|
|
754
|
-
* const workflowId = await this.runWorkflow(
|
|
755
|
-
* 'MY_WORKFLOW',
|
|
756
|
-
* { taskId: '123', data: 'process this' }
|
|
757
|
-
* );
|
|
758
|
-
* ```
|
|
759
|
-
*/
|
|
760
|
-
runWorkflow<P = unknown>(
|
|
761
|
-
workflowName: WorkflowName<Env>,
|
|
762
|
-
params: P,
|
|
763
|
-
options?: RunWorkflowOptions
|
|
764
|
-
): Promise<string>;
|
|
765
|
-
/**
|
|
766
|
-
* Send an event to a running workflow.
|
|
767
|
-
* The workflow can wait for this event using step.waitForEvent().
|
|
768
|
-
*
|
|
769
|
-
* @param workflowName - Name of the workflow binding in env (e.g., 'MY_WORKFLOW')
|
|
770
|
-
* @param workflowId - ID of the workflow instance
|
|
771
|
-
* @param event - Event to send
|
|
772
|
-
*
|
|
773
|
-
* @example
|
|
774
|
-
* ```typescript
|
|
775
|
-
* await this.sendWorkflowEvent(
|
|
776
|
-
* 'MY_WORKFLOW',
|
|
777
|
-
* workflowId,
|
|
778
|
-
* { type: 'approval', payload: { approved: true } }
|
|
779
|
-
* );
|
|
780
|
-
* ```
|
|
781
|
-
*/
|
|
782
|
-
sendWorkflowEvent(
|
|
783
|
-
workflowName: WorkflowName<Env>,
|
|
784
|
-
workflowId: string,
|
|
785
|
-
event: WorkflowEventPayload
|
|
786
|
-
): Promise<void>;
|
|
787
|
-
/**
|
|
788
|
-
* Approve a waiting workflow.
|
|
789
|
-
* Sends an approval event to the workflow that can be received by waitForApproval().
|
|
790
|
-
*
|
|
791
|
-
* @param workflowId - ID of the workflow to approve
|
|
792
|
-
* @param data - Optional approval data (reason, metadata)
|
|
793
|
-
*
|
|
794
|
-
* @example
|
|
795
|
-
* ```typescript
|
|
796
|
-
* await this.approveWorkflow(workflowId, {
|
|
797
|
-
* reason: 'Approved by admin',
|
|
798
|
-
* metadata: { approvedBy: userId }
|
|
799
|
-
* });
|
|
800
|
-
* ```
|
|
801
|
-
*/
|
|
802
|
-
approveWorkflow(
|
|
803
|
-
workflowId: string,
|
|
804
|
-
data?: {
|
|
805
|
-
reason?: string;
|
|
806
|
-
metadata?: Record<string, unknown>;
|
|
807
|
-
}
|
|
808
|
-
): Promise<void>;
|
|
809
|
-
/**
|
|
810
|
-
* Reject a waiting workflow.
|
|
811
|
-
* Sends a rejection event to the workflow that will cause waitForApproval() to throw.
|
|
812
|
-
*
|
|
813
|
-
* @param workflowId - ID of the workflow to reject
|
|
814
|
-
* @param data - Optional rejection data (reason)
|
|
815
|
-
*
|
|
816
|
-
* @example
|
|
817
|
-
* ```typescript
|
|
818
|
-
* await this.rejectWorkflow(workflowId, {
|
|
819
|
-
* reason: 'Request denied by admin'
|
|
820
|
-
* });
|
|
821
|
-
* ```
|
|
822
|
-
*/
|
|
823
|
-
rejectWorkflow(
|
|
824
|
-
workflowId: string,
|
|
825
|
-
data?: {
|
|
826
|
-
reason?: string;
|
|
827
|
-
}
|
|
828
|
-
): Promise<void>;
|
|
829
|
-
/**
|
|
830
|
-
* Terminate a running workflow.
|
|
831
|
-
* This immediately stops the workflow and sets its status to "terminated".
|
|
832
|
-
*
|
|
833
|
-
* @param workflowId - ID of the workflow to terminate (must be tracked via runWorkflow)
|
|
834
|
-
* @throws Error if workflow not found in tracking table
|
|
835
|
-
* @throws Error if workflow binding not found in environment
|
|
836
|
-
* @throws Error if workflow is already completed/errored/terminated (from Cloudflare)
|
|
837
|
-
*
|
|
838
|
-
* @note `terminate()` is not yet supported in local development (wrangler dev).
|
|
839
|
-
* It will throw an error locally but works when deployed to Cloudflare.
|
|
840
|
-
*
|
|
841
|
-
* @example
|
|
842
|
-
* ```typescript
|
|
843
|
-
* await this.terminateWorkflow(workflowId);
|
|
844
|
-
* ```
|
|
845
|
-
*/
|
|
846
|
-
terminateWorkflow(workflowId: string): Promise<void>;
|
|
847
|
-
/**
|
|
848
|
-
* Pause a running workflow.
|
|
849
|
-
* The workflow can be resumed later with resumeWorkflow().
|
|
850
|
-
*
|
|
851
|
-
* @param workflowId - ID of the workflow to pause (must be tracked via runWorkflow)
|
|
852
|
-
* @throws Error if workflow not found in tracking table
|
|
853
|
-
* @throws Error if workflow binding not found in environment
|
|
854
|
-
* @throws Error if workflow is not running (from Cloudflare)
|
|
855
|
-
*
|
|
856
|
-
* @note `pause()` is not yet supported in local development (wrangler dev).
|
|
857
|
-
* It will throw an error locally but works when deployed to Cloudflare.
|
|
858
|
-
*
|
|
859
|
-
* @example
|
|
860
|
-
* ```typescript
|
|
861
|
-
* await this.pauseWorkflow(workflowId);
|
|
862
|
-
* ```
|
|
863
|
-
*/
|
|
864
|
-
pauseWorkflow(workflowId: string): Promise<void>;
|
|
865
|
-
/**
|
|
866
|
-
* Resume a paused workflow.
|
|
867
|
-
*
|
|
868
|
-
* @param workflowId - ID of the workflow to resume (must be tracked via runWorkflow)
|
|
869
|
-
* @throws Error if workflow not found in tracking table
|
|
870
|
-
* @throws Error if workflow binding not found in environment
|
|
871
|
-
* @throws Error if workflow is not paused (from Cloudflare)
|
|
872
|
-
*
|
|
873
|
-
* @note `resume()` is not yet supported in local development (wrangler dev).
|
|
874
|
-
* It will throw an error locally but works when deployed to Cloudflare.
|
|
875
|
-
*
|
|
876
|
-
* @example
|
|
877
|
-
* ```typescript
|
|
878
|
-
* await this.resumeWorkflow(workflowId);
|
|
879
|
-
* ```
|
|
880
|
-
*/
|
|
881
|
-
resumeWorkflow(workflowId: string): Promise<void>;
|
|
882
|
-
/**
|
|
883
|
-
* Restart a workflow instance.
|
|
884
|
-
* This re-runs the workflow from the beginning with the same ID.
|
|
885
|
-
*
|
|
886
|
-
* @param workflowId - ID of the workflow to restart (must be tracked via runWorkflow)
|
|
887
|
-
* @param options - Optional settings
|
|
888
|
-
* @param options.resetTracking - If true (default), resets created_at and clears error fields.
|
|
889
|
-
* If false, preserves original timestamps.
|
|
890
|
-
* @throws Error if workflow not found in tracking table
|
|
891
|
-
* @throws Error if workflow binding not found in environment
|
|
892
|
-
*
|
|
893
|
-
* @note `restart()` is not yet supported in local development (wrangler dev).
|
|
894
|
-
* It will throw an error locally but works when deployed to Cloudflare.
|
|
895
|
-
*
|
|
896
|
-
* @example
|
|
897
|
-
* ```typescript
|
|
898
|
-
* // Reset tracking (default)
|
|
899
|
-
* await this.restartWorkflow(workflowId);
|
|
900
|
-
*
|
|
901
|
-
* // Preserve original timestamps
|
|
902
|
-
* await this.restartWorkflow(workflowId, { resetTracking: false });
|
|
903
|
-
* ```
|
|
904
|
-
*/
|
|
905
|
-
restartWorkflow(
|
|
906
|
-
workflowId: string,
|
|
907
|
-
options?: {
|
|
908
|
-
resetTracking?: boolean;
|
|
909
|
-
}
|
|
910
|
-
): Promise<void>;
|
|
911
|
-
/**
|
|
912
|
-
* Find a workflow binding by its name.
|
|
913
|
-
*/
|
|
914
|
-
private _findWorkflowBindingByName;
|
|
915
|
-
/**
|
|
916
|
-
* Get all workflow binding names from the environment.
|
|
917
|
-
*/
|
|
918
|
-
private _getWorkflowBindingNames;
|
|
919
|
-
/**
|
|
920
|
-
* Get the status of a workflow and update the tracking record.
|
|
921
|
-
*
|
|
922
|
-
* @param workflowName - Name of the workflow binding in env (e.g., 'MY_WORKFLOW')
|
|
923
|
-
* @param workflowId - ID of the workflow instance
|
|
924
|
-
* @returns The workflow status
|
|
925
|
-
*/
|
|
926
|
-
getWorkflowStatus(
|
|
927
|
-
workflowName: WorkflowName<Env>,
|
|
928
|
-
workflowId: string
|
|
929
|
-
): Promise<InstanceStatus>;
|
|
930
|
-
/**
|
|
931
|
-
* Get a tracked workflow by ID.
|
|
932
|
-
*
|
|
933
|
-
* @param workflowId - Workflow instance ID
|
|
934
|
-
* @returns Workflow info or undefined if not found
|
|
935
|
-
*/
|
|
936
|
-
getWorkflow(workflowId: string): WorkflowInfo | undefined;
|
|
937
|
-
/**
|
|
938
|
-
* Query tracked workflows with cursor-based pagination.
|
|
939
|
-
*
|
|
940
|
-
* @param criteria - Query criteria including optional cursor for pagination
|
|
941
|
-
* @returns WorkflowPage with workflows, total count, and next cursor
|
|
942
|
-
*
|
|
943
|
-
* @example
|
|
944
|
-
* ```typescript
|
|
945
|
-
* // First page
|
|
946
|
-
* const page1 = this.getWorkflows({ status: 'running', limit: 20 });
|
|
947
|
-
*
|
|
948
|
-
* // Next page
|
|
949
|
-
* if (page1.nextCursor) {
|
|
950
|
-
* const page2 = this.getWorkflows({
|
|
951
|
-
* status: 'running',
|
|
952
|
-
* limit: 20,
|
|
953
|
-
* cursor: page1.nextCursor
|
|
954
|
-
* });
|
|
955
|
-
* }
|
|
956
|
-
* ```
|
|
957
|
-
*/
|
|
958
|
-
getWorkflows(criteria?: WorkflowQueryCriteria): WorkflowPage;
|
|
959
|
-
/**
|
|
960
|
-
* Count workflows matching criteria (for pagination total).
|
|
961
|
-
*/
|
|
962
|
-
private _countWorkflows;
|
|
963
|
-
/**
|
|
964
|
-
* Encode a cursor from workflow info for pagination.
|
|
965
|
-
* Stores createdAt as Unix timestamp in seconds (matching DB storage).
|
|
966
|
-
*/
|
|
967
|
-
private _encodeCursor;
|
|
968
|
-
/**
|
|
969
|
-
* Decode a pagination cursor.
|
|
970
|
-
* Returns createdAt as Unix timestamp in seconds (matching DB storage).
|
|
971
|
-
*/
|
|
972
|
-
private _decodeCursor;
|
|
973
|
-
/**
|
|
974
|
-
* Delete a workflow tracking record.
|
|
975
|
-
*
|
|
976
|
-
* @param workflowId - ID of the workflow to delete
|
|
977
|
-
* @returns true if a record was deleted, false if not found
|
|
978
|
-
*/
|
|
979
|
-
deleteWorkflow(workflowId: string): boolean;
|
|
980
|
-
/**
|
|
981
|
-
* Delete workflow tracking records matching criteria.
|
|
982
|
-
* Useful for cleaning up old completed/errored workflows.
|
|
983
|
-
*
|
|
984
|
-
* @param criteria - Criteria for which workflows to delete
|
|
985
|
-
* @returns Number of records matching criteria (expected deleted count)
|
|
986
|
-
*
|
|
987
|
-
* @example
|
|
988
|
-
* ```typescript
|
|
989
|
-
* // Delete all completed workflows created more than 7 days ago
|
|
990
|
-
* const deleted = this.deleteWorkflows({
|
|
991
|
-
* status: 'complete',
|
|
992
|
-
* createdBefore: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000)
|
|
993
|
-
* });
|
|
994
|
-
*
|
|
995
|
-
* // Delete all errored and terminated workflows
|
|
996
|
-
* const deleted = this.deleteWorkflows({
|
|
997
|
-
* status: ['errored', 'terminated']
|
|
998
|
-
* });
|
|
999
|
-
* ```
|
|
1000
|
-
*/
|
|
1001
|
-
deleteWorkflows(
|
|
1002
|
-
criteria?: Omit<WorkflowQueryCriteria, "limit" | "orderBy"> & {
|
|
1003
|
-
createdBefore?: Date;
|
|
1004
|
-
}
|
|
1005
|
-
): number;
|
|
1006
|
-
/**
|
|
1007
|
-
* Migrate workflow tracking records from an old binding name to a new one.
|
|
1008
|
-
* Use this after renaming a workflow binding in wrangler.toml.
|
|
1009
|
-
*
|
|
1010
|
-
* @param oldName - Previous workflow binding name
|
|
1011
|
-
* @param newName - New workflow binding name
|
|
1012
|
-
* @returns Number of records migrated
|
|
1013
|
-
*
|
|
1014
|
-
* @example
|
|
1015
|
-
* ```typescript
|
|
1016
|
-
* // After renaming OLD_WORKFLOW to NEW_WORKFLOW in wrangler.toml
|
|
1017
|
-
* async onStart() {
|
|
1018
|
-
* const migrated = this.migrateWorkflowBinding('OLD_WORKFLOW', 'NEW_WORKFLOW');
|
|
1019
|
-
* }
|
|
1020
|
-
* ```
|
|
1021
|
-
*/
|
|
1022
|
-
migrateWorkflowBinding(oldName: string, newName: string): number;
|
|
1023
|
-
/**
|
|
1024
|
-
* Update workflow tracking record from InstanceStatus
|
|
1025
|
-
*/
|
|
1026
|
-
private _updateWorkflowTracking;
|
|
1027
|
-
/**
|
|
1028
|
-
* Convert a database row to WorkflowInfo
|
|
1029
|
-
*/
|
|
1030
|
-
private _rowToWorkflowInfo;
|
|
1031
|
-
/**
|
|
1032
|
-
* Find the binding name for this Agent's namespace by matching class name.
|
|
1033
|
-
* Returns undefined if no match found - use options.agentBinding as fallback.
|
|
1034
|
-
*/
|
|
1035
|
-
private _findAgentBindingName;
|
|
1036
|
-
private _findBindingNameForNamespace;
|
|
1037
|
-
private _restoreRpcMcpServers;
|
|
1038
|
-
/**
|
|
1039
|
-
* Handle a callback from a workflow.
|
|
1040
|
-
* Called when the Agent receives a callback at /_workflow/callback.
|
|
1041
|
-
* Override this to handle all callback types in one place.
|
|
1042
|
-
*
|
|
1043
|
-
* @param callback - The callback payload
|
|
1044
|
-
*/
|
|
1045
|
-
onWorkflowCallback(callback: WorkflowCallback): Promise<void>;
|
|
1046
|
-
/**
|
|
1047
|
-
* Called when a workflow reports progress.
|
|
1048
|
-
* Override to handle progress updates.
|
|
1049
|
-
*
|
|
1050
|
-
* @param workflowName - Workflow binding name
|
|
1051
|
-
* @param workflowId - ID of the workflow
|
|
1052
|
-
* @param progress - Typed progress data (default: DefaultProgress)
|
|
1053
|
-
*/
|
|
1054
|
-
onWorkflowProgress(
|
|
1055
|
-
_workflowName: string,
|
|
1056
|
-
_workflowId: string,
|
|
1057
|
-
_progress: unknown
|
|
1058
|
-
): Promise<void>;
|
|
1059
|
-
/**
|
|
1060
|
-
* Called when a workflow completes successfully.
|
|
1061
|
-
* Override to handle completion.
|
|
1062
|
-
*
|
|
1063
|
-
* @param workflowName - Workflow binding name
|
|
1064
|
-
* @param workflowId - ID of the workflow
|
|
1065
|
-
* @param result - Optional result data
|
|
1066
|
-
*/
|
|
1067
|
-
onWorkflowComplete(
|
|
1068
|
-
_workflowName: string,
|
|
1069
|
-
_workflowId: string,
|
|
1070
|
-
_result?: unknown
|
|
1071
|
-
): Promise<void>;
|
|
1072
|
-
/**
|
|
1073
|
-
* Called when a workflow encounters an error.
|
|
1074
|
-
* Override to handle errors.
|
|
1075
|
-
*
|
|
1076
|
-
* @param workflowName - Workflow binding name
|
|
1077
|
-
* @param workflowId - ID of the workflow
|
|
1078
|
-
* @param error - Error message
|
|
1079
|
-
*/
|
|
1080
|
-
onWorkflowError(
|
|
1081
|
-
_workflowName: string,
|
|
1082
|
-
_workflowId: string,
|
|
1083
|
-
_error: string
|
|
1084
|
-
): Promise<void>;
|
|
1085
|
-
/**
|
|
1086
|
-
* Called when a workflow sends a custom event.
|
|
1087
|
-
* Override to handle custom events.
|
|
1088
|
-
*
|
|
1089
|
-
* @param workflowName - Workflow binding name
|
|
1090
|
-
* @param workflowId - ID of the workflow
|
|
1091
|
-
* @param event - Custom event payload
|
|
1092
|
-
*/
|
|
1093
|
-
onWorkflowEvent(
|
|
1094
|
-
_workflowName: string,
|
|
1095
|
-
_workflowId: string,
|
|
1096
|
-
_event: unknown
|
|
1097
|
-
): Promise<void>;
|
|
1098
|
-
/**
|
|
1099
|
-
* Handle a workflow callback via RPC.
|
|
1100
|
-
* @internal - Called by AgentWorkflow, do not call directly
|
|
1101
|
-
*/
|
|
1102
|
-
_workflow_handleCallback(callback: WorkflowCallback): Promise<void>;
|
|
1103
|
-
/**
|
|
1104
|
-
* Broadcast a message to all connected clients via RPC.
|
|
1105
|
-
* @internal - Called by AgentWorkflow, do not call directly
|
|
1106
|
-
*/
|
|
1107
|
-
_workflow_broadcast(message: unknown): Promise<void>;
|
|
1108
|
-
/**
|
|
1109
|
-
* Update agent state via RPC.
|
|
1110
|
-
* @internal - Called by AgentWorkflow, do not call directly
|
|
1111
|
-
*/
|
|
1112
|
-
_workflow_updateState(
|
|
1113
|
-
action: "set" | "merge" | "reset",
|
|
1114
|
-
state?: unknown
|
|
1115
|
-
): Promise<void>;
|
|
1116
|
-
/**
|
|
1117
|
-
* Connect to a new MCP Server via RPC (Durable Object binding)
|
|
1118
|
-
*
|
|
1119
|
-
* The binding name and props are persisted to storage so the connection
|
|
1120
|
-
* is automatically restored after Durable Object hibernation.
|
|
1121
|
-
*
|
|
1122
|
-
* @example
|
|
1123
|
-
* await this.addMcpServer("counter", env.MY_MCP);
|
|
1124
|
-
* await this.addMcpServer("counter", env.MY_MCP, { props: { userId: "123" } });
|
|
1125
|
-
*/
|
|
1126
|
-
addMcpServer<T extends McpAgent>(
|
|
1127
|
-
serverName: string,
|
|
1128
|
-
binding: DurableObjectNamespace<T>,
|
|
1129
|
-
options?: AddRpcMcpServerOptions
|
|
1130
|
-
): Promise<{
|
|
1131
|
-
id: string;
|
|
1132
|
-
state: typeof MCPConnectionState.READY;
|
|
1133
|
-
}>;
|
|
1134
|
-
/**
|
|
1135
|
-
* Connect to a new MCP Server via HTTP (SSE or Streamable HTTP)
|
|
1136
|
-
*
|
|
1137
|
-
* @example
|
|
1138
|
-
* await this.addMcpServer("github", "https://mcp.github.com");
|
|
1139
|
-
* await this.addMcpServer("github", "https://mcp.github.com", { transport: { type: "sse" } });
|
|
1140
|
-
* await this.addMcpServer("github", url, callbackHost, agentsPrefix, options); // legacy
|
|
1141
|
-
*/
|
|
1142
|
-
addMcpServer(
|
|
1143
|
-
serverName: string,
|
|
1144
|
-
url: string,
|
|
1145
|
-
callbackHostOrOptions?: string | AddMcpServerOptions,
|
|
1146
|
-
agentsPrefix?: string,
|
|
1147
|
-
options?: {
|
|
1148
|
-
client?: ConstructorParameters<typeof Client>[1];
|
|
1149
|
-
transport?: {
|
|
1150
|
-
headers?: HeadersInit;
|
|
1151
|
-
type?: TransportType;
|
|
1152
|
-
};
|
|
1153
|
-
}
|
|
1154
|
-
): Promise<
|
|
1155
|
-
| {
|
|
1156
|
-
id: string;
|
|
1157
|
-
state: typeof MCPConnectionState.AUTHENTICATING;
|
|
1158
|
-
authUrl: string;
|
|
1159
|
-
}
|
|
1160
|
-
| {
|
|
1161
|
-
id: string;
|
|
1162
|
-
state: typeof MCPConnectionState.READY;
|
|
1163
|
-
}
|
|
1164
|
-
>;
|
|
1165
|
-
removeMcpServer(id: string): Promise<void>;
|
|
1166
|
-
getMcpServers(): MCPServersState;
|
|
1167
|
-
/**
|
|
1168
|
-
* Create the OAuth provider used when connecting to MCP servers that require authentication.
|
|
1169
|
-
*
|
|
1170
|
-
* Override this method in a subclass to supply a custom OAuth provider implementation,
|
|
1171
|
-
* for example to use pre-registered client credentials, mTLS-based authentication,
|
|
1172
|
-
* or any other OAuth flow beyond dynamic client registration.
|
|
1173
|
-
*
|
|
1174
|
-
* @example
|
|
1175
|
-
* // Custom OAuth provider
|
|
1176
|
-
* class MyAgent extends Agent {
|
|
1177
|
-
* createMcpOAuthProvider(callbackUrl: string): AgentMcpOAuthProvider {
|
|
1178
|
-
* return new MyCustomOAuthProvider(
|
|
1179
|
-
* this.ctx.storage,
|
|
1180
|
-
* this.name,
|
|
1181
|
-
* callbackUrl
|
|
1182
|
-
* );
|
|
1183
|
-
* }
|
|
1184
|
-
* }
|
|
1185
|
-
*
|
|
1186
|
-
* @param callbackUrl The OAuth callback URL for the authorization flow
|
|
1187
|
-
* @returns An {@link AgentMcpOAuthProvider} instance used by {@link addMcpServer}
|
|
1188
|
-
*/
|
|
1189
|
-
createMcpOAuthProvider(callbackUrl: string): AgentMcpOAuthProvider;
|
|
1190
|
-
private broadcastMcpServers;
|
|
1191
|
-
/**
|
|
1192
|
-
* Handle MCP OAuth callback request if it's an OAuth callback.
|
|
1193
|
-
*
|
|
1194
|
-
* This method encapsulates the entire OAuth callback flow:
|
|
1195
|
-
* 1. Checks if the request is an MCP OAuth callback
|
|
1196
|
-
* 2. Processes the OAuth code exchange
|
|
1197
|
-
* 3. Establishes the connection if successful
|
|
1198
|
-
* 4. Broadcasts MCP server state updates
|
|
1199
|
-
* 5. Returns the appropriate HTTP response
|
|
1200
|
-
*
|
|
1201
|
-
* @param request The incoming HTTP request
|
|
1202
|
-
* @returns Response if this was an OAuth callback, null otherwise
|
|
1203
|
-
*/
|
|
1204
|
-
private handleMcpOAuthCallback;
|
|
1205
|
-
/**
|
|
1206
|
-
* Handle OAuth callback response using MCPClientManager configuration
|
|
1207
|
-
* @param result OAuth callback result
|
|
1208
|
-
* @param request The original request (needed for base URL)
|
|
1209
|
-
* @returns Response for the OAuth callback
|
|
1210
|
-
*/
|
|
1211
|
-
private handleOAuthCallbackResponse;
|
|
1212
|
-
}
|
|
1213
|
-
/**
|
|
1214
|
-
* Namespace for creating Agent instances
|
|
1215
|
-
* @template Agentic Type of the Agent class
|
|
1216
|
-
* @deprecated Use DurableObjectNamespace instead
|
|
1217
|
-
*/
|
|
1218
|
-
type AgentNamespace<Agentic extends Agent<Cloudflare.Env>> =
|
|
1219
|
-
DurableObjectNamespace<Agentic>;
|
|
1220
|
-
/**
|
|
1221
|
-
* Agent's durable context
|
|
1222
|
-
*/
|
|
1223
|
-
type AgentContext = DurableObjectState;
|
|
1224
|
-
/**
|
|
1225
|
-
* Configuration options for Agent routing
|
|
1226
|
-
*/
|
|
1227
|
-
type AgentOptions<Env> = PartyServerOptions<Env>;
|
|
1228
|
-
/**
|
|
1229
|
-
* Route a request to the appropriate Agent
|
|
1230
|
-
* @param request Request to route
|
|
1231
|
-
* @param env Environment containing Agent bindings
|
|
1232
|
-
* @param options Routing options
|
|
1233
|
-
* @returns Response from the Agent or undefined if no route matched
|
|
1234
|
-
*/
|
|
1235
|
-
declare function routeAgentRequest<Env>(
|
|
1236
|
-
request: Request,
|
|
1237
|
-
env: Env,
|
|
1238
|
-
options?: AgentOptions<Env>
|
|
1239
|
-
): Promise<Response | null>;
|
|
1240
|
-
type EmailRoutingOptions<Env> = AgentOptions<Env> & {
|
|
1241
|
-
resolver: EmailResolver<Env>;
|
|
1242
|
-
/**
|
|
1243
|
-
* Callback invoked when no routing information is found for an email.
|
|
1244
|
-
* Use this to reject the email or perform custom handling.
|
|
1245
|
-
* If not provided, a warning is logged and the email is dropped.
|
|
1246
|
-
*/
|
|
1247
|
-
onNoRoute?: (email: ForwardableEmailMessage) => void | Promise<void>;
|
|
1248
|
-
};
|
|
1249
|
-
/**
|
|
1250
|
-
* Route an email to the appropriate Agent
|
|
1251
|
-
* @param email The email to route
|
|
1252
|
-
* @param env The environment containing the Agent bindings
|
|
1253
|
-
* @param options The options for routing the email
|
|
1254
|
-
* @returns A promise that resolves when the email has been routed
|
|
1255
|
-
*/
|
|
1256
|
-
declare function routeAgentEmail<Env extends Cloudflare.Env = Cloudflare.Env>(
|
|
1257
|
-
email: ForwardableEmailMessage,
|
|
1258
|
-
env: Env,
|
|
1259
|
-
options: EmailRoutingOptions<Env>
|
|
1260
|
-
): Promise<void>;
|
|
1261
|
-
/**
|
|
1262
|
-
* Get or create an Agent by name
|
|
1263
|
-
* @template Env Environment type containing bindings
|
|
1264
|
-
* @template T Type of the Agent class
|
|
1265
|
-
* @param namespace Agent namespace
|
|
1266
|
-
* @param name Name of the Agent instance
|
|
1267
|
-
* @param options Options for Agent creation
|
|
1268
|
-
* @returns Promise resolving to an Agent instance stub
|
|
1269
|
-
*/
|
|
1270
|
-
declare function getAgentByName<
|
|
1271
|
-
Env extends Cloudflare.Env = Cloudflare.Env,
|
|
1272
|
-
T extends Agent<Env> = Agent<Env>,
|
|
1273
|
-
Props extends Record<string, unknown> = Record<string, unknown>
|
|
1274
|
-
>(
|
|
1275
|
-
namespace: DurableObjectNamespace<T>,
|
|
1276
|
-
name: string,
|
|
1277
|
-
options?: {
|
|
1278
|
-
jurisdiction?: DurableObjectJurisdiction;
|
|
1279
|
-
locationHint?: DurableObjectLocationHint;
|
|
1280
|
-
props?: Props;
|
|
1281
|
-
}
|
|
1282
|
-
): Promise<DurableObjectStub<T>>;
|
|
1283
|
-
/**
|
|
1284
|
-
* A wrapper for streaming responses in callable methods
|
|
1285
|
-
*/
|
|
1286
|
-
declare class StreamingResponse {
|
|
1287
|
-
private _connection;
|
|
1288
|
-
private _id;
|
|
1289
|
-
private _closed;
|
|
1290
|
-
constructor(connection: Connection$1, id: string);
|
|
1291
|
-
/**
|
|
1292
|
-
* Whether the stream has been closed (via end() or error())
|
|
1293
|
-
*/
|
|
1294
|
-
get isClosed(): boolean;
|
|
1295
|
-
/**
|
|
1296
|
-
* Send a chunk of data to the client
|
|
1297
|
-
* @param chunk The data to send
|
|
1298
|
-
* @returns false if stream is already closed (no-op), true if sent
|
|
1299
|
-
*/
|
|
1300
|
-
send(chunk: unknown): boolean;
|
|
1301
|
-
/**
|
|
1302
|
-
* End the stream and send the final chunk (if any)
|
|
1303
|
-
* @param finalChunk Optional final chunk of data to send
|
|
1304
|
-
* @returns false if stream is already closed (no-op), true if sent
|
|
1305
|
-
*/
|
|
1306
|
-
end(finalChunk?: unknown): boolean;
|
|
1307
|
-
/**
|
|
1308
|
-
* Send an error to the client and close the stream
|
|
1309
|
-
* @param message Error message to send
|
|
1310
|
-
* @returns false if stream is already closed (no-op), true if sent
|
|
1311
|
-
*/
|
|
1312
|
-
error(message: string): boolean;
|
|
1313
|
-
}
|
|
1314
|
-
//#endregion
|
|
37
|
+
n as AgentsOAuthProvider,
|
|
38
|
+
r as DurableObjectOAuthClientProvider,
|
|
39
|
+
t as AgentMcpOAuthProvider
|
|
40
|
+
} from "./do-oauth-client-provider-C2jurFjW.js";
|
|
1315
41
|
export {
|
|
1316
42
|
AddMcpServerOptions,
|
|
1317
43
|
AddRpcMcpServerOptions,
|
|
1318
44
|
Agent,
|
|
1319
45
|
AgentContext,
|
|
1320
|
-
|
|
46
|
+
AgentMcpOAuthProvider,
|
|
1321
47
|
AgentNamespace,
|
|
1322
48
|
AgentOptions,
|
|
1323
49
|
AgentStaticOptions,
|
|
1324
|
-
|
|
50
|
+
AgentsOAuthProvider,
|
|
1325
51
|
CallableMetadata,
|
|
1326
|
-
|
|
1327
|
-
|
|
52
|
+
Connection,
|
|
53
|
+
ConnectionContext,
|
|
1328
54
|
DEFAULT_AGENT_STATIC_OPTIONS,
|
|
1329
55
|
DurableObjectOAuthClientProvider,
|
|
1330
56
|
EmailRoutingOptions,
|
|
@@ -1334,13 +60,13 @@ export {
|
|
|
1334
60
|
QueueItem,
|
|
1335
61
|
RPCRequest,
|
|
1336
62
|
RPCResponse,
|
|
1337
|
-
|
|
63
|
+
RetryOptions,
|
|
1338
64
|
Schedule,
|
|
1339
65
|
SqlError,
|
|
1340
66
|
StateUpdateMessage,
|
|
1341
67
|
StreamingResponse,
|
|
1342
|
-
|
|
1343
|
-
|
|
68
|
+
TransportType,
|
|
69
|
+
WSMessage,
|
|
1344
70
|
__DO_NOT_USE_WILL_BREAK__agentContext,
|
|
1345
71
|
callable,
|
|
1346
72
|
createHeaderBasedEmailResolver,
|
|
@@ -1350,4 +76,3 @@ export {
|
|
|
1350
76
|
routeAgentRequest,
|
|
1351
77
|
unstable_callable
|
|
1352
78
|
};
|
|
1353
|
-
//# sourceMappingURL=index.d.ts.map
|