agents 0.22.0 → 0.24.0
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/README.md +20 -1
- package/dist/{agent-routing-CnkaHb-v.d.ts → agent-routing-B2XLNMxq.d.ts} +1094 -443
- package/dist/agent-routing.d.ts +1 -1
- package/dist/agent-tool-types.d.ts +26 -26
- package/dist/{agent-tools-C0XJqWzB.d.ts → agent-tools-Dj5Mzlw7.d.ts} +7 -7
- package/dist/agent-tools.d.ts +21 -21
- package/dist/browser/ai.js +4 -1
- package/dist/browser/ai.js.map +1 -1
- package/dist/browser/tanstack-ai.js.map +1 -1
- package/dist/callable-decorator-DP__HhBA.d.ts +72 -0
- package/dist/callable-decorator.d.ts +18 -0
- package/dist/callable-decorator.js +71 -0
- package/dist/callable-decorator.js.map +1 -0
- package/dist/{capability-BjSKYpzg.js → capability-B4WbF81e.js} +2 -1
- package/dist/capability-B4WbF81e.js.map +1 -0
- package/dist/capability-runner-BUBa6Ake.d.ts +484 -0
- package/dist/channel-Bnm4S7T2.d.ts +491 -0
- package/dist/channels/ai-sdk.d.ts +46 -0
- package/dist/channels/ai-sdk.js +120 -0
- package/dist/channels/ai-sdk.js.map +1 -0
- package/dist/channels/email.d.ts +95 -0
- package/dist/channels/email.js +323 -0
- package/dist/channels/email.js.map +1 -0
- package/dist/channels/index.d.ts +233 -0
- package/dist/channels/index.js +608 -0
- package/dist/channels/index.js.map +1 -0
- package/dist/channels/slack.d.ts +140 -0
- package/dist/channels/slack.js +614 -0
- package/dist/channels/slack.js.map +1 -0
- package/dist/channels/tanstack-ai.d.ts +39 -0
- package/dist/channels/tanstack-ai.js +17 -0
- package/dist/channels/tanstack-ai.js.map +1 -0
- package/dist/channels/telegram.d.ts +106 -0
- package/dist/channels/telegram.js +427 -0
- package/dist/channels/telegram.js.map +1 -0
- package/dist/channels/voice.d.ts +45 -0
- package/dist/channels/voice.js +122 -0
- package/dist/channels/voice.js.map +1 -0
- package/dist/chat/index.d.ts +2319 -2010
- package/dist/chat/index.js +892 -518
- package/dist/chat/index.js.map +1 -1
- package/dist/chat-sdk/index.d.ts +7 -7
- package/dist/chat-sdk/index.js +1 -1
- package/dist/client-BxdkCuVy.d.ts +411 -0
- package/dist/client-C9DAjZIY.js +518 -0
- package/dist/client-C9DAjZIY.js.map +1 -0
- package/dist/{client-jagG8a9_.js → client-fyQrLGkD.js} +2 -2
- package/dist/{client-jagG8a9_.js.map → client-fyQrLGkD.js.map} +1 -1
- package/dist/client.d.ts +27 -283
- package/dist/client.js +2 -274
- package/dist/context/index.d.ts +216 -0
- package/dist/context/index.js +454 -0
- package/dist/context/index.js.map +1 -0
- package/dist/current-agent-C4w86kcN.d.ts +93 -0
- package/dist/current-agent-DhoDkSnH.js.map +1 -1
- package/dist/{diagnostics-CaBjfz4J.js → diagnostics-BzvaX2UT.js} +5 -1
- package/dist/diagnostics-BzvaX2UT.js.map +1 -0
- package/dist/diagnostics-C4jcz3VK.js +360 -0
- package/dist/diagnostics-C4jcz3VK.js.map +1 -0
- package/dist/durable-object-lifecycle-ei7M7lqB.d.ts +157 -0
- package/dist/index-BB0kqhIz.d.ts +101 -0
- package/dist/index-BVVgDSdq.d.ts +1 -0
- package/dist/index-Dlgtd3Mj.d.ts +78 -0
- package/dist/index-XDkuQ7zm.d.ts +89 -0
- package/dist/{index-DcSAZKsB.d.ts → index-YSKgfgg9.d.ts} +3 -1
- package/dist/index.d.ts +92 -83
- package/dist/index.js +4 -3
- package/dist/ingress-BfetZbMO.js +83 -0
- package/dist/ingress-BfetZbMO.js.map +1 -0
- package/dist/internal-CYlgHl1l.js +59 -0
- package/dist/internal-CYlgHl1l.js.map +1 -0
- package/dist/internal_context.d.ts +1 -1
- package/dist/lifecycle/index.d.ts +39 -19
- package/dist/lifecycle/index.js +2 -2
- package/dist/lifecycle-Mm_jQh7r.js +1314 -0
- package/dist/lifecycle-Mm_jQh7r.js.map +1 -0
- package/dist/mcp/client/index.d.ts +20 -20
- package/dist/mcp/client/index.js +1 -1
- package/dist/mcp/index.d.ts +35 -35
- package/dist/mcp/index.js +2 -2
- package/dist/observability/index.d.ts +1 -1
- package/dist/observability/index.js +1 -1
- package/dist/queue/index.d.ts +123 -0
- package/dist/queue/index.js +2 -0
- package/dist/queue-BC9F5cUo.js +406 -0
- package/dist/queue-BC9F5cUo.js.map +1 -0
- package/dist/react.d.ts +34 -16
- package/dist/react.js +31 -8
- package/dist/react.js.map +1 -1
- package/dist/{retries-CAvxtG9d.d.ts → retries-D9B2UCq3.d.ts} +23 -6
- package/dist/retries.d.ts +10 -6
- package/dist/retries.js +21 -1
- package/dist/retries.js.map +1 -1
- package/dist/routing/index.d.ts +137 -0
- package/dist/routing/index.js +244 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/sanitize-D9TujEK8.js +79 -0
- package/dist/sanitize-D9TujEK8.js.map +1 -0
- package/dist/{scheduler-DQoTGoAW.d.ts → scheduler-BGq6M5Kd.d.ts} +20 -21
- package/dist/scheduler-D_KHqxBa.js +658 -0
- package/dist/scheduler-D_KHqxBa.js.map +1 -0
- package/dist/schedules/index.d.ts +1 -1
- package/dist/schedules/index.js +1 -1
- package/dist/sentence-chunker-BAidJ4DA.d.ts +68 -0
- package/dist/serializable.d.ts +1 -1
- package/dist/sessions/index.d.ts +441 -0
- package/dist/sessions/index.js +2063 -0
- package/dist/sessions/index.js.map +1 -0
- package/dist/skills/index.d.ts +99 -0
- package/dist/skills/index.js +254 -5
- package/dist/skills/index.js.map +1 -1
- package/dist/{src-5W6JNKVb.js → src-BNU3ZiJM.js} +1524 -1441
- package/dist/src-BNU3ZiJM.js.map +1 -0
- package/dist/state/index.d.ts +6 -0
- package/dist/state/index.js +137 -0
- package/dist/state/index.js.map +1 -0
- package/dist/streams/index.d.ts +120 -0
- package/dist/streams/index.js +107 -0
- package/dist/streams/index.js.map +1 -0
- package/dist/streams-BcE8JP2X.d.ts +370 -0
- package/dist/streams-CCPRV6dt.js +709 -0
- package/dist/streams-CCPRV6dt.js.map +1 -0
- package/dist/sub-routing.d.ts +12 -12
- package/dist/surface-bZZJqBka.js +17 -0
- package/dist/surface-bZZJqBka.js.map +1 -0
- package/dist/tasks/index.d.ts +64 -0
- package/dist/tasks/index.js +2 -0
- package/dist/tasks-D4nLqVSI.js +1656 -0
- package/dist/tasks-D4nLqVSI.js.map +1 -0
- package/dist/tasks-V2lCT8ZV.d.ts +517 -0
- package/dist/text-segment-joiner-BtAFQSA_.js +57 -0
- package/dist/text-segment-joiner-BtAFQSA_.js.map +1 -0
- package/dist/text-stream-CpdiKrJB.js +272 -0
- package/dist/text-stream-CpdiKrJB.js.map +1 -0
- package/dist/tokens-nHAKcN6M.js +52 -0
- package/dist/tokens-nHAKcN6M.js.map +1 -0
- package/dist/tool-schema-CBjGPrsQ.js +31 -0
- package/dist/tool-schema-CBjGPrsQ.js.map +1 -0
- package/dist/transport-protocol-BxyngQ_R.js +25 -0
- package/dist/transport-protocol-BxyngQ_R.js.map +1 -0
- package/dist/transport-protocol-ZTew5Wso.d.ts +27 -0
- package/dist/types-B7LojTe4.d.ts +202 -0
- package/dist/types-DCD6BNZH.d.ts +70 -0
- package/dist/types-_Faxb570.d.ts +439 -0
- package/dist/voice/client.d.ts +226 -0
- package/dist/voice/client.js +932 -0
- package/dist/voice/client.js.map +1 -0
- package/dist/voice/errors.d.ts +43 -0
- package/dist/voice/errors.js +41 -0
- package/dist/voice/errors.js.map +1 -0
- package/dist/voice/index.d.ts +271 -0
- package/dist/voice/index.js +1812 -0
- package/dist/voice/index.js.map +1 -0
- package/dist/voice/react.d.ts +167 -0
- package/dist/voice/react.js +234 -0
- package/dist/voice/react.js.map +1 -0
- package/dist/voice/sfu.d.ts +71 -0
- package/dist/voice/sfu.js +157 -0
- package/dist/voice/sfu.js.map +1 -0
- package/dist/voice/text.d.ts +6 -0
- package/dist/voice/text.js +2 -0
- package/dist/voice/types.d.ts +58 -0
- package/dist/voice/types.js +18 -0
- package/dist/voice/types.js.map +1 -0
- package/dist/voice/workers-ai.d.ts +136 -0
- package/dist/voice/workers-ai.js +568 -0
- package/dist/voice/workers-ai.js.map +1 -0
- package/dist/websockets/index.d.ts +301 -0
- package/dist/websockets/index.js +3 -0
- package/dist/websockets-D7IzWbZb.js +1005 -0
- package/dist/websockets-D7IzWbZb.js.map +1 -0
- package/dist/workflow-types.d.ts +25 -25
- package/dist/workflows.d.ts +21 -21
- package/dist/workflows.js +1 -1
- package/docs/agent-class.md +4 -4
- package/docs/agent-tools.md +2 -1
- package/docs/channels.md +323 -0
- package/docs/chat-agents.md +6 -13
- package/docs/client-sdk.md +30 -0
- package/docs/context.md +131 -0
- package/docs/index.md +16 -13
- package/docs/lifecycle.md +179 -57
- package/docs/long-running-agents.md +2 -2
- package/docs/mcp-servers.md +5 -1
- package/docs/queue.md +135 -241
- package/docs/resumable-streaming.md +1 -1
- package/docs/retries.md +1 -1
- package/docs/routing.md +105 -0
- package/docs/sessions.md +237 -871
- package/docs/streams.md +213 -0
- package/docs/sub-agents.md +184 -124
- package/docs/tasks.md +246 -0
- package/docs/voice.md +745 -0
- package/package.json +126 -14
- package/dist/capability-BjSKYpzg.js.map +0 -1
- package/dist/capability-runner-CvHGZqUu.d.ts +0 -150
- package/dist/client.js.map +0 -1
- package/dist/compaction-helpers-iiKMr2TQ.js +0 -340
- package/dist/compaction-helpers-iiKMr2TQ.js.map +0 -1
- package/dist/compaction-helpers-wUz6M3us.d.ts +0 -621
- package/dist/current-agent-CuMErtly.d.ts +0 -283
- package/dist/diagnostics-CaBjfz4J.js.map +0 -1
- package/dist/durable-object-lifecycle-D6nNQJJd.js +0 -862
- package/dist/durable-object-lifecycle-D6nNQJJd.js.map +0 -1
- package/dist/experimental/memory/session/index.d.ts +0 -671
- package/dist/experimental/memory/session/index.js +0 -2379
- package/dist/experimental/memory/session/index.js.map +0 -1
- package/dist/experimental/memory/utils/index.d.ts +0 -96
- package/dist/experimental/memory/utils/index.js +0 -79
- package/dist/experimental/memory/utils/index.js.map +0 -1
- package/dist/scheduler-CR9RHGos.js +0 -857
- package/dist/scheduler-CR9RHGos.js.map +0 -1
- package/dist/src-5W6JNKVb.js.map +0 -1
- package/dist/tool-output-truncation-CNnnGZQ3.js +0 -98
- package/dist/tool-output-truncation-CNnnGZQ3.js.map +0 -1
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
S as ConnectionContext,
|
|
3
|
+
T as WSMessage,
|
|
4
|
+
_ as LifecycleJobContext,
|
|
5
|
+
o as MemoryLimitContext,
|
|
4
6
|
s as LifecycleCapability,
|
|
5
|
-
t as
|
|
6
|
-
|
|
7
|
+
t as CapabilityRequestContext,
|
|
8
|
+
u as LifecycleRouteAddress,
|
|
9
|
+
v as LifecycleJobOutcome,
|
|
10
|
+
x as Connection
|
|
11
|
+
} from "./capability-runner-BUBa6Ake.js";
|
|
12
|
+
import { t as RetryOptions } from "./retries-D9B2UCq3.js";
|
|
7
13
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
s as LifecycleRouteEnvelope,
|
|
13
|
-
u as ConnectionContext
|
|
14
|
-
} from "./current-agent-CuMErtly.js";
|
|
14
|
+
r as LifecycleRouteEnvelope,
|
|
15
|
+
t as Lifecycle
|
|
16
|
+
} from "./durable-object-lifecycle-ei7M7lqB.js";
|
|
17
|
+
import { n as CurrentAgentContext } from "./current-agent-C4w86kcN.js";
|
|
15
18
|
import { t as AgentEmail } from "./internal_context-BlxFEWfn.js";
|
|
16
19
|
import { r as EmailResolver, s as SendEmailOptions } from "./email-7TatiTnl.js";
|
|
17
|
-
import { t as RetryOptions } from "./retries-CAvxtG9d.js";
|
|
18
20
|
import {
|
|
19
21
|
n as Observability,
|
|
20
22
|
r as ObservabilityEvent,
|
|
21
23
|
s as MCPObservabilityEvent
|
|
22
|
-
} from "./index-
|
|
24
|
+
} from "./index-YSKgfgg9.js";
|
|
23
25
|
import { t as AgentMcpOAuthProvider } from "./do-oauth-client-provider-Tmf1vgKz.js";
|
|
24
26
|
import {
|
|
25
27
|
a as McpAuthContext,
|
|
@@ -37,8 +39,14 @@ import { t as MessageType } from "./types-6Zo2zfoO.js";
|
|
|
37
39
|
import {
|
|
38
40
|
a as ScheduleCriteria,
|
|
39
41
|
i as Schedule,
|
|
42
|
+
o as ScheduleOptions,
|
|
40
43
|
t as Scheduler
|
|
41
|
-
} from "./scheduler-
|
|
44
|
+
} from "./scheduler-BGq6M5Kd.js";
|
|
45
|
+
import { i as QueueItem } from "./types-DCD6BNZH.js";
|
|
46
|
+
import { l as TaskHandlers, r as Tasks } from "./tasks-V2lCT8ZV.js";
|
|
47
|
+
import { t as State } from "./index-Dlgtd3Mj.js";
|
|
48
|
+
import { t as CallableMetadata } from "./callable-decorator-DP__HhBA.js";
|
|
49
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
42
50
|
import {
|
|
43
51
|
DurableObject,
|
|
44
52
|
RpcTarget,
|
|
@@ -286,9 +294,726 @@ declare function routeSubAgentRequest(
|
|
|
286
294
|
*/
|
|
287
295
|
declare function getSubAgentByName<T extends Agent>(
|
|
288
296
|
parent: unknown,
|
|
289
|
-
cls:
|
|
297
|
+
cls: DynamicAgentClass<T>,
|
|
290
298
|
name: string
|
|
291
|
-
): Promise<
|
|
299
|
+
): Promise<DynamicAgentStub<T>>;
|
|
300
|
+
//#endregion
|
|
301
|
+
//#region src/dynamic-agents/types.d.ts
|
|
302
|
+
type DynamicAgentConnectionMeta = {
|
|
303
|
+
id: string;
|
|
304
|
+
uri: string | null;
|
|
305
|
+
tags: string[];
|
|
306
|
+
state: unknown;
|
|
307
|
+
requestHeaders?: [string, string][];
|
|
308
|
+
};
|
|
309
|
+
type DynamicAgentConnectionBridgeLike = {
|
|
310
|
+
send(message: string | ArrayBuffer | ArrayBufferView): void | Promise<void>;
|
|
311
|
+
close(code?: number, reason?: string): void | Promise<void>;
|
|
312
|
+
setState(state: unknown): unknown | Promise<unknown>;
|
|
313
|
+
broadcast(
|
|
314
|
+
ownerPath: ReadonlyArray<{
|
|
315
|
+
className: string;
|
|
316
|
+
name: string;
|
|
317
|
+
}>,
|
|
318
|
+
message: string | ArrayBuffer | ArrayBufferView,
|
|
319
|
+
without?: string[]
|
|
320
|
+
): void | Promise<void>;
|
|
321
|
+
};
|
|
322
|
+
type DynamicAgentConnectionOperationName = "send" | "setState" | "close";
|
|
323
|
+
/**
|
|
324
|
+
* Constructor type for a dynamic agent (facet-backed child) class.
|
|
325
|
+
* Used by {@link Agent.dynamicAgents} to reference the child class
|
|
326
|
+
* via `ctx.exports`.
|
|
327
|
+
*
|
|
328
|
+
* The class name (`cls.name`) must match the export name in the
|
|
329
|
+
* worker entry point — re-exports under a different name
|
|
330
|
+
* (e.g. `export { Foo as Bar }`) are not supported.
|
|
331
|
+
*/
|
|
332
|
+
type DynamicAgentClass<T extends Agent = Agent> = {
|
|
333
|
+
new (ctx: DurableObjectState, env: never): T;
|
|
334
|
+
};
|
|
335
|
+
/**
|
|
336
|
+
* Wraps `T` in a `Promise` unless it already is one.
|
|
337
|
+
*/
|
|
338
|
+
type Promisify<T> = T extends Promise<unknown> ? T : Promise<T>;
|
|
339
|
+
/**
|
|
340
|
+
* A typed RPC stub for a dynamic agent. Exposes all public instance
|
|
341
|
+
* methods as callable RPC methods with Promise-wrapped return types.
|
|
342
|
+
*
|
|
343
|
+
* Methods owned by `Agent`, its lifecycle, or `DurableObject` internals
|
|
344
|
+
* are excluded — only user-defined methods on the subclass are exposed.
|
|
345
|
+
*/
|
|
346
|
+
type DynamicAgentStub<T extends Agent> = {
|
|
347
|
+
[K in keyof T as K extends keyof Agent
|
|
348
|
+
? never
|
|
349
|
+
: T[K] extends (...args: never[]) => unknown
|
|
350
|
+
? K
|
|
351
|
+
: never]: T[K] extends (...args: infer A) => infer R
|
|
352
|
+
? (...args: A) => Promisify<R>
|
|
353
|
+
: never;
|
|
354
|
+
};
|
|
355
|
+
type FacetRunStorageRow = {
|
|
356
|
+
owner_path: string;
|
|
357
|
+
owner_path_key: string;
|
|
358
|
+
run_id: string;
|
|
359
|
+
created_at: number;
|
|
360
|
+
};
|
|
361
|
+
/**
|
|
362
|
+
* Internal RPC surface exposed by the root agent for facets to
|
|
363
|
+
* delegate alarm-owning operations (schedules + facet teardown).
|
|
364
|
+
* @internal
|
|
365
|
+
*/
|
|
366
|
+
type RootFacetRpcSurface = {
|
|
367
|
+
_cf_routeLifecycle(
|
|
368
|
+
target: LifecycleRouteAddress | undefined,
|
|
369
|
+
envelope: LifecycleRouteEnvelope
|
|
370
|
+
): Promise<unknown>;
|
|
371
|
+
_cf_cleanupFacetPrefix(
|
|
372
|
+
ownerPath: ReadonlyArray<AgentPathStep>
|
|
373
|
+
): Promise<void>;
|
|
374
|
+
_cf_destroyDescendantFacet(
|
|
375
|
+
targetPath: ReadonlyArray<AgentPathStep>
|
|
376
|
+
): Promise<void>;
|
|
377
|
+
_cf_acquireFacetKeepAlive(
|
|
378
|
+
ownerPath: ReadonlyArray<AgentPathStep>
|
|
379
|
+
): Promise<string>;
|
|
380
|
+
_cf_releaseFacetKeepAlive(token: string): Promise<void>;
|
|
381
|
+
_cf_registerFacetRun(
|
|
382
|
+
ownerPath: ReadonlyArray<AgentPathStep>,
|
|
383
|
+
runId: string
|
|
384
|
+
): Promise<void>;
|
|
385
|
+
_cf_unregisterFacetRun(
|
|
386
|
+
ownerPath: ReadonlyArray<AgentPathStep>,
|
|
387
|
+
runId: string
|
|
388
|
+
): Promise<void>;
|
|
389
|
+
_cf_broadcastToSubAgent(
|
|
390
|
+
ownerPath: ReadonlyArray<AgentPathStep>,
|
|
391
|
+
message: string | ArrayBuffer | ArrayBufferView,
|
|
392
|
+
without?: string[]
|
|
393
|
+
): Promise<void>;
|
|
394
|
+
_cf_subAgentConnectionMetas(
|
|
395
|
+
ownerPath: ReadonlyArray<AgentPathStep>
|
|
396
|
+
): Promise<DynamicAgentConnectionMeta[]>;
|
|
397
|
+
_cf_sendToSubAgentConnection(
|
|
398
|
+
connectionId: string,
|
|
399
|
+
message: string | ArrayBuffer | ArrayBufferView
|
|
400
|
+
): Promise<void>;
|
|
401
|
+
_cf_closeSubAgentConnection(
|
|
402
|
+
connectionId: string,
|
|
403
|
+
code?: number,
|
|
404
|
+
reason?: string
|
|
405
|
+
): Promise<void>;
|
|
406
|
+
_cf_setSubAgentConnectionState(
|
|
407
|
+
connectionId: string,
|
|
408
|
+
state: unknown
|
|
409
|
+
): Promise<unknown>;
|
|
410
|
+
};
|
|
411
|
+
//#endregion
|
|
412
|
+
//#region src/dynamic-agents/bridges.d.ts
|
|
413
|
+
/**
|
|
414
|
+
* Parent-side bridge handed to a facet over RPC: wraps a live root-owned
|
|
415
|
+
* `Connection` so the facet can send/close/setState on it, and carries
|
|
416
|
+
* the root's broadcast entry point for facet-scoped broadcasts.
|
|
417
|
+
*/
|
|
418
|
+
declare class DynamicAgentConnectionBridge
|
|
419
|
+
extends RpcTarget
|
|
420
|
+
implements DynamicAgentConnectionBridgeLike
|
|
421
|
+
{
|
|
422
|
+
#private;
|
|
423
|
+
constructor(
|
|
424
|
+
connection: Connection,
|
|
425
|
+
broadcast?: (
|
|
426
|
+
ownerPath: ReadonlyArray<{
|
|
427
|
+
className: string;
|
|
428
|
+
name: string;
|
|
429
|
+
}>,
|
|
430
|
+
message: string | ArrayBuffer | ArrayBufferView,
|
|
431
|
+
without?: string[]
|
|
432
|
+
) => void | Promise<void>
|
|
433
|
+
);
|
|
434
|
+
send(message: string | ArrayBuffer | ArrayBufferView): void;
|
|
435
|
+
close(code?: number, reason?: string): void;
|
|
436
|
+
setState(state: unknown): unknown;
|
|
437
|
+
broadcast(
|
|
438
|
+
ownerPath: ReadonlyArray<{
|
|
439
|
+
className: string;
|
|
440
|
+
name: string;
|
|
441
|
+
}>,
|
|
442
|
+
message: string | ArrayBuffer | ArrayBufferView,
|
|
443
|
+
without?: string[]
|
|
444
|
+
): void | Promise<void>;
|
|
445
|
+
}
|
|
446
|
+
//#endregion
|
|
447
|
+
//#region src/dynamic-agents/identity.d.ts
|
|
448
|
+
declare const SUB_AGENT_IDENTITY_VERSION_LEGACY = "legacy";
|
|
449
|
+
declare const SUB_AGENT_IDENTITY_VERSION_PATH_V2 = "path-v2";
|
|
450
|
+
type SubAgentIdentityVersion =
|
|
451
|
+
| typeof SUB_AGENT_IDENTITY_VERSION_LEGACY
|
|
452
|
+
| typeof SUB_AGENT_IDENTITY_VERSION_PATH_V2;
|
|
453
|
+
//#endregion
|
|
454
|
+
//#region src/dynamic-agents/registry.d.ts
|
|
455
|
+
/**
|
|
456
|
+
* SQL access the registry needs from its owning Agent: the tagged
|
|
457
|
+
* template helper plus raw DDL execution (for additive column
|
|
458
|
+
* migrations whose errors must be inspected).
|
|
459
|
+
*/
|
|
460
|
+
type DynamicAgentRegistrySqlHost = {
|
|
461
|
+
sql<T = Record<string, string | number | boolean | null>>(
|
|
462
|
+
strings: TemplateStringsArray,
|
|
463
|
+
...values: (string | number | boolean | null)[]
|
|
464
|
+
): T[];
|
|
465
|
+
execRawSql(sql: string): void;
|
|
466
|
+
};
|
|
467
|
+
/**
|
|
468
|
+
* The parent-side registry of spawned dynamic agents (facets), stored
|
|
469
|
+
* in the parent's own SQLite. Backs `hasSubAgent` / `listSubAgents`
|
|
470
|
+
* and the identity-versioning decision (legacy bare-name facets vs
|
|
471
|
+
* path-scoped v2 identities).
|
|
472
|
+
*
|
|
473
|
+
* Table and column names are storage-frozen — never rename them.
|
|
474
|
+
*/
|
|
475
|
+
declare class DynamicAgentRegistry {
|
|
476
|
+
#private;
|
|
477
|
+
constructor(host: DynamicAgentRegistrySqlHost);
|
|
478
|
+
ensure(): void;
|
|
479
|
+
record(
|
|
480
|
+
className: string,
|
|
481
|
+
name: string,
|
|
482
|
+
identity: {
|
|
483
|
+
version: SubAgentIdentityVersion;
|
|
484
|
+
name: string;
|
|
485
|
+
}
|
|
486
|
+
): void;
|
|
487
|
+
row(
|
|
488
|
+
className: string,
|
|
489
|
+
name: string
|
|
490
|
+
): {
|
|
491
|
+
identity_version: string | null;
|
|
492
|
+
identity_name: string | null;
|
|
493
|
+
} | null;
|
|
494
|
+
identity(
|
|
495
|
+
className: string,
|
|
496
|
+
name: string,
|
|
497
|
+
childPath: ReadonlyArray<AgentPathStep>
|
|
498
|
+
): Promise<{
|
|
499
|
+
version: SubAgentIdentityVersion;
|
|
500
|
+
name: string;
|
|
501
|
+
existing: boolean;
|
|
502
|
+
}>;
|
|
503
|
+
forget(className: string, name: string): void;
|
|
504
|
+
has(className: string, name: string): boolean;
|
|
505
|
+
list(className?: string): Array<{
|
|
506
|
+
className: string;
|
|
507
|
+
name: string;
|
|
508
|
+
createdAt: number;
|
|
509
|
+
}>;
|
|
510
|
+
}
|
|
511
|
+
//#endregion
|
|
512
|
+
//#region src/dynamic-agents/host.d.ts
|
|
513
|
+
/**
|
|
514
|
+
* The Agent internals the dynamic-agents (facet) machinery reaches
|
|
515
|
+
* into. Agent implements this structurally and passes itself at
|
|
516
|
+
* construction — the interface exists to make the coupling explicit
|
|
517
|
+
* and reviewable, and is the seam a later capability refactor would
|
|
518
|
+
* shrink.
|
|
519
|
+
*
|
|
520
|
+
* Members named `_cf_*` are cross-facet RPC entry points that must
|
|
521
|
+
* stay on the Agent prototype; the module calls back into them when
|
|
522
|
+
* traversal continues on another agent instance.
|
|
523
|
+
*
|
|
524
|
+
* @internal
|
|
525
|
+
*/
|
|
526
|
+
interface DynamicAgentHostPort {
|
|
527
|
+
readonly ctx: DurableObjectState;
|
|
528
|
+
readonly lifecycle: {
|
|
529
|
+
route(envelope: LifecycleRouteEnvelope): Promise<unknown>;
|
|
530
|
+
readonly name: string;
|
|
531
|
+
};
|
|
532
|
+
sql<T = Record<string, string | number | boolean | null>>(
|
|
533
|
+
strings: TemplateStringsArray,
|
|
534
|
+
...values: (string | number | boolean | null)[]
|
|
535
|
+
): T[];
|
|
536
|
+
/** Facet identity — written by `initAsFacet` and startup restore. */
|
|
537
|
+
_isFacet: boolean;
|
|
538
|
+
_facetName?: string;
|
|
539
|
+
_parentPath: ReadonlyArray<AgentPathStep>;
|
|
540
|
+
readonly name: string;
|
|
541
|
+
readonly _ParentClass: {
|
|
542
|
+
readonly name: string;
|
|
543
|
+
};
|
|
544
|
+
readonly selfPath: AgentPathStep[];
|
|
545
|
+
_keepAliveRefs: number;
|
|
546
|
+
_isSameAgentPathPrefix(
|
|
547
|
+
prefix: ReadonlyArray<AgentPathStep>,
|
|
548
|
+
path: ReadonlyArray<AgentPathStep>
|
|
549
|
+
): boolean;
|
|
550
|
+
hasSubAgent(className: string, name: string): boolean;
|
|
551
|
+
_cf_resolveSubAgent(className: string, name: string): Promise<unknown>;
|
|
552
|
+
_cf_cleanupFacetPrefix(
|
|
553
|
+
ownerPath: ReadonlyArray<AgentPathStep>
|
|
554
|
+
): Promise<void>;
|
|
555
|
+
_cf_routeLifecycle(
|
|
556
|
+
target: LifecycleRouteAddress | undefined,
|
|
557
|
+
envelope: LifecycleRouteEnvelope
|
|
558
|
+
): Promise<unknown>;
|
|
559
|
+
_syncHostJobs(): Promise<void>;
|
|
560
|
+
readonly scheduler: {
|
|
561
|
+
__DO_NOT_USE_WILL_BREAK__cleanupRoutePrefix(prefix: string): Promise<void>;
|
|
562
|
+
};
|
|
563
|
+
readonly tasks: {
|
|
564
|
+
__DO_NOT_USE_WILL_BREAK__cleanupRoutePrefix(prefix: string): Promise<void>;
|
|
565
|
+
};
|
|
566
|
+
readonly _queue: {
|
|
567
|
+
__DO_NOT_USE_WILL_BREAK__cleanupRoutePrefix(prefix: string): Promise<void>;
|
|
568
|
+
};
|
|
569
|
+
/** Local (non-facet-index) durable fiber recovery pass. */
|
|
570
|
+
_checkRunFibers(): Promise<void>;
|
|
571
|
+
/** Overridable RPC entry points — call via the host so subclass overrides intercept. */
|
|
572
|
+
_cf_broadcastToSubAgent(
|
|
573
|
+
ownerPath: ReadonlyArray<AgentPathStep>,
|
|
574
|
+
message: string | ArrayBuffer | ArrayBufferView,
|
|
575
|
+
without?: string[]
|
|
576
|
+
): Promise<void>;
|
|
577
|
+
_cf_checkRunFibersForFacet(
|
|
578
|
+
ownerPath: ReadonlyArray<AgentPathStep>
|
|
579
|
+
): Promise<number>;
|
|
580
|
+
/** Ensure constructor-time async initialization has completed. */
|
|
581
|
+
__unsafe_ensureInitialized(): Promise<void>;
|
|
582
|
+
/**
|
|
583
|
+
* Run `body` in a fresh invocation scope with no native request/
|
|
584
|
+
* connection context attached, so a child-facet RPC never sees
|
|
585
|
+
* parent-owned I/O handles.
|
|
586
|
+
*/
|
|
587
|
+
_runFacetInitInvocation<T>(body: () => Promise<T>): Promise<T>;
|
|
588
|
+
readonly _webSockets: {
|
|
589
|
+
getConnection<TState = unknown>(id: string): Connection<TState> | undefined;
|
|
590
|
+
getConnections<TState = unknown>(
|
|
591
|
+
tag?: string
|
|
592
|
+
): Iterable<Connection<TState>>;
|
|
593
|
+
};
|
|
594
|
+
_unsafe_getConnectionFlag(connection: Connection, key: string): unknown;
|
|
595
|
+
_unsafe_setConnectionFlag(
|
|
596
|
+
connection: Connection,
|
|
597
|
+
key: string,
|
|
598
|
+
value: unknown
|
|
599
|
+
): void;
|
|
600
|
+
shouldConnectionBeReadonly(
|
|
601
|
+
connection: Connection,
|
|
602
|
+
context: {
|
|
603
|
+
request: Request;
|
|
604
|
+
}
|
|
605
|
+
): boolean;
|
|
606
|
+
setConnectionReadonly(connection: Connection, readonly: boolean): void;
|
|
607
|
+
shouldSendProtocolMessages(
|
|
608
|
+
connection: Connection,
|
|
609
|
+
context: {
|
|
610
|
+
request: Request;
|
|
611
|
+
}
|
|
612
|
+
): boolean;
|
|
613
|
+
getConnectionTags(
|
|
614
|
+
connection: Connection,
|
|
615
|
+
context: {
|
|
616
|
+
request: Request;
|
|
617
|
+
}
|
|
618
|
+
): Promise<string[]> | string[];
|
|
619
|
+
onConnect(
|
|
620
|
+
connection: Connection,
|
|
621
|
+
context: {
|
|
622
|
+
request: Request;
|
|
623
|
+
}
|
|
624
|
+
): unknown | Promise<unknown>;
|
|
625
|
+
onMessage(
|
|
626
|
+
connection: Connection,
|
|
627
|
+
message: WSMessage
|
|
628
|
+
): unknown | Promise<unknown>;
|
|
629
|
+
onClose(
|
|
630
|
+
connection: Connection,
|
|
631
|
+
code: number,
|
|
632
|
+
reason: string,
|
|
633
|
+
wasClean: boolean
|
|
634
|
+
): unknown | Promise<unknown>;
|
|
635
|
+
onBeforeSubAgent(
|
|
636
|
+
request: Request,
|
|
637
|
+
child: {
|
|
638
|
+
className: string;
|
|
639
|
+
name: string;
|
|
640
|
+
}
|
|
641
|
+
): Promise<Request | Response | void>;
|
|
642
|
+
}
|
|
643
|
+
//#endregion
|
|
644
|
+
//#region src/dynamic-agents/dynamic-agents.d.ts
|
|
645
|
+
/**
|
|
646
|
+
* The facet-backed dynamic-agent machinery, extracted from the Agent
|
|
647
|
+
* class. One instance per Agent, installed as a Lifecycle capability
|
|
648
|
+
* (`capabilityId: "dynamic-agents"`); the host port documents exactly
|
|
649
|
+
* which Agent internals it touches.
|
|
650
|
+
*
|
|
651
|
+
* The capability claims no runner hooks — four integration points are
|
|
652
|
+
* deliberately wired directly through the Agent composition root
|
|
653
|
+
* instead, because the runner's dispatch contract cannot express them:
|
|
654
|
+
* the `/sub/` upgrade path rewrites the request and *continues* into
|
|
655
|
+
* `lifecycle.fetch` (onRequest can only claim), forwarded WS frames run
|
|
656
|
+
* inside the host's onMessage wrapper *after* the WebSockets capability
|
|
657
|
+
* has claimed the wake, this module *implements* the lifecycle route
|
|
658
|
+
* transport rather than consuming it, and facet-context restore has
|
|
659
|
+
* load-bearing startup ordering inside the host's startup span.
|
|
660
|
+
*
|
|
661
|
+
* Nothing here renames any wire- or storage-visible identifier: the
|
|
662
|
+
* `cf_agents_facet_runs` table, `_cf_*` RPC method names, and route
|
|
663
|
+
* key formats are frozen.
|
|
664
|
+
*
|
|
665
|
+
* @internal
|
|
666
|
+
*/
|
|
667
|
+
declare class DynamicAgentsInternal extends LifecycleCapability {
|
|
668
|
+
#private;
|
|
669
|
+
/** The parent-side registry of spawned dynamic agents. */
|
|
670
|
+
readonly registry: DynamicAgentRegistry;
|
|
671
|
+
constructor(host: DynamicAgentHostPort);
|
|
672
|
+
runRowsForPrefix(
|
|
673
|
+
ownerPath: ReadonlyArray<AgentPathStep>
|
|
674
|
+
): FacetRunStorageRow[];
|
|
675
|
+
deleteRunRowsForPrefix(ownerPath: ReadonlyArray<AgentPathStep>): void;
|
|
676
|
+
lifecycleRouteAddress(): LifecycleRouteAddress | undefined;
|
|
677
|
+
routeLifecycleToRoot(envelope: LifecycleRouteEnvelope): Promise<unknown>;
|
|
678
|
+
routeLifecycleToTarget(
|
|
679
|
+
target: LifecycleRouteAddress,
|
|
680
|
+
envelope: LifecycleRouteEnvelope
|
|
681
|
+
): Promise<unknown>;
|
|
682
|
+
/** Body of the single native-RPC aperture for routed Lifecycle capabilities. */
|
|
683
|
+
routeLifecycle(
|
|
684
|
+
target: LifecycleRouteAddress | undefined,
|
|
685
|
+
envelope: LifecycleRouteEnvelope
|
|
686
|
+
): Promise<unknown>;
|
|
687
|
+
rootAlarmOwner(): Promise<RootFacetRpcSurface>;
|
|
688
|
+
rootResolvesToSelf(): boolean;
|
|
689
|
+
/**
|
|
690
|
+
* Clean root-owned bookkeeping for a sub-tree of facets: bulk-cancel
|
|
691
|
+
* schedules, queue items, and routed Task wake mirrors under the
|
|
692
|
+
* owner-path prefix, and delete root-side facet fiber recovery leases for
|
|
693
|
+
* the same sub-tree.
|
|
694
|
+
*/
|
|
695
|
+
cleanupPrefix(ownerPath: ReadonlyArray<AgentPathStep>): Promise<void>;
|
|
696
|
+
/**
|
|
697
|
+
* Acquire a root-owned keepAlive ref on behalf of a descendant facet.
|
|
698
|
+
*/
|
|
699
|
+
acquireKeepAlive(ownerPath: ReadonlyArray<AgentPathStep>): Promise<string>;
|
|
700
|
+
/**
|
|
701
|
+
* Release a root-owned keepAlive ref previously acquired for a facet.
|
|
702
|
+
* Idempotent so disposer calls can safely race or run twice.
|
|
703
|
+
*/
|
|
704
|
+
releaseKeepAlive(token: string): Promise<void>;
|
|
705
|
+
/**
|
|
706
|
+
* Register a facet's durable run row in the root-side index so root
|
|
707
|
+
* alarm housekeeping can dispatch recovery checks into idle facets.
|
|
708
|
+
*/
|
|
709
|
+
registerRun(
|
|
710
|
+
ownerPath: ReadonlyArray<AgentPathStep>,
|
|
711
|
+
runId: string
|
|
712
|
+
): Promise<void>;
|
|
713
|
+
/**
|
|
714
|
+
* Root-side scan for durable fibers owned by descendant facets.
|
|
715
|
+
* `cf_agents_facet_runs` is only an index; actual snapshots and
|
|
716
|
+
* recovery hooks live in each facet's own `cf_agents_runs` table.
|
|
717
|
+
*/
|
|
718
|
+
checkRunFibers(): Promise<void>;
|
|
719
|
+
/**
|
|
720
|
+
* Dispatch a runFiber recovery check into the facet identified by
|
|
721
|
+
* `ownerPath`. Returns the number of remaining local `cf_agents_runs`
|
|
722
|
+
* rows on the target facet after recovery.
|
|
723
|
+
*/
|
|
724
|
+
checkRunFibersAtPath(
|
|
725
|
+
ownerPath: ReadonlyArray<AgentPathStep>
|
|
726
|
+
): Promise<number>;
|
|
727
|
+
/**
|
|
728
|
+
* Invoke an RPC method on the host Agent or a descendant facet
|
|
729
|
+
* identified by a root-first path. Used by AgentWorkflow to route
|
|
730
|
+
* callbacks and `this.agent` calls back to the exact sub-agent that
|
|
731
|
+
* started a workflow.
|
|
732
|
+
*/
|
|
733
|
+
invokeAgentPath(
|
|
734
|
+
targetPath: ReadonlyArray<AgentPathStep>,
|
|
735
|
+
method: string,
|
|
736
|
+
args: unknown[]
|
|
737
|
+
): Promise<unknown>;
|
|
738
|
+
/**
|
|
739
|
+
* Recursively destroy a descendant facet identified by `targetPath`.
|
|
740
|
+
* Walks down from `selfPath` until reaching the target's immediate
|
|
741
|
+
* parent, where it cancels the target's parent-owned schedules (and
|
|
742
|
+
* any descendants), removes the target from the registry, and calls
|
|
743
|
+
* `ctx.facets.delete` to wipe the target's storage.
|
|
744
|
+
*/
|
|
745
|
+
destroyDescendant(targetPath: ReadonlyArray<AgentPathStep>): Promise<void>;
|
|
746
|
+
/**
|
|
747
|
+
* Shared facet resolution — takes a CamelCase class name string
|
|
748
|
+
* (matching `ctx.exports`) rather than a class reference. Both
|
|
749
|
+
* `subAgent(cls, name)` and `_cf_invokeSubAgent(className, ...)`
|
|
750
|
+
* funnel through here so registry bookkeeping and the
|
|
751
|
+
* `_cf_initAsFacet` handshake are consistent.
|
|
752
|
+
*/
|
|
753
|
+
resolve(className: string, name: string): Promise<unknown>;
|
|
754
|
+
/**
|
|
755
|
+
* Forcefully abort a running facet. Transitively aborts the child's
|
|
756
|
+
* own children; storage is preserved.
|
|
757
|
+
*/
|
|
758
|
+
abort(className: string, name: string, reason?: unknown): void;
|
|
759
|
+
/**
|
|
760
|
+
* Delete a facet: abort it if running, then permanently wipe its
|
|
761
|
+
* storage. Transitively deletes the child's own children.
|
|
762
|
+
*/
|
|
763
|
+
delete(className: string, name: string): Promise<void>;
|
|
764
|
+
/** Drop all facet-side virtual connections (test/rehydration hook). */
|
|
765
|
+
clearVirtualConnections(): void;
|
|
766
|
+
/** Facet-side lookup of a virtual connection by id. */
|
|
767
|
+
getVirtualConnection(id: string): Connection | undefined;
|
|
768
|
+
/** Facet-side iteration over virtual connections, optionally by tag. */
|
|
769
|
+
getVirtualConnections(tag?: string): Iterable<Connection>;
|
|
770
|
+
activeBridge(
|
|
771
|
+
connectionId?: string
|
|
772
|
+
): DynamicAgentConnectionBridgeLike | undefined;
|
|
773
|
+
/**
|
|
774
|
+
* Route a virtual sub-agent connection operation through its live frame
|
|
775
|
+
* bridge, or through the durable root Agent after that frame completes.
|
|
776
|
+
* All operations share one per-connection queue. Facet broadcasts wait for
|
|
777
|
+
* older queued operations; failures do not block later work.
|
|
778
|
+
*/
|
|
779
|
+
routeConnectionOperation(
|
|
780
|
+
connectionId: string,
|
|
781
|
+
operationName: DynamicAgentConnectionOperationName,
|
|
782
|
+
operation: (bridge: DynamicAgentConnectionBridgeLike) => unknown
|
|
783
|
+
): void;
|
|
784
|
+
/**
|
|
785
|
+
* Route a facet broadcast after every older connection operation.
|
|
786
|
+
*
|
|
787
|
+
* This barrier is intentionally one-way: facet startup can broadcast before
|
|
788
|
+
* a child connection has finished initializing its tags and protocol flags.
|
|
789
|
+
* Making those later connection operations wait would let the next frame
|
|
790
|
+
* observe stale root-owned metadata.
|
|
791
|
+
*/
|
|
792
|
+
routeBroadcast(
|
|
793
|
+
ownerPath: ReadonlyArray<AgentPathStep>,
|
|
794
|
+
message: string | ArrayBuffer | ArrayBufferView,
|
|
795
|
+
without?: string[],
|
|
796
|
+
upstreamBridge?: DynamicAgentConnectionBridgeLike
|
|
797
|
+
): Promise<void>;
|
|
798
|
+
broadcastToParent(
|
|
799
|
+
message: string | ArrayBuffer | ArrayBufferView,
|
|
800
|
+
without?: string[]
|
|
801
|
+
): Promise<void>;
|
|
802
|
+
broadcastToPath(
|
|
803
|
+
ownerPath: ReadonlyArray<AgentPathStep>,
|
|
804
|
+
message: string | ArrayBuffer | ArrayBufferView,
|
|
805
|
+
without?: string[]
|
|
806
|
+
): Promise<void>;
|
|
807
|
+
connectionMetas(
|
|
808
|
+
ownerPath: ReadonlyArray<AgentPathStep>
|
|
809
|
+
): Promise<DynamicAgentConnectionMeta[]>;
|
|
810
|
+
sendToConnection(
|
|
811
|
+
connectionId: string,
|
|
812
|
+
message: string | ArrayBuffer | ArrayBufferView
|
|
813
|
+
): Promise<void>;
|
|
814
|
+
closeConnection(
|
|
815
|
+
connectionId: string,
|
|
816
|
+
code?: number,
|
|
817
|
+
reason?: string
|
|
818
|
+
): Promise<void>;
|
|
819
|
+
setConnectionState(connectionId: string, state: unknown): Promise<unknown>;
|
|
820
|
+
connectionTargetPath(
|
|
821
|
+
connection: Connection
|
|
822
|
+
): ReadonlyArray<AgentPathStep> | null;
|
|
823
|
+
isSameAgentPath(
|
|
824
|
+
a: ReadonlyArray<AgentPathStep>,
|
|
825
|
+
b: ReadonlyArray<AgentPathStep>
|
|
826
|
+
): boolean;
|
|
827
|
+
connectionHasChildTarget(connection: Connection): boolean;
|
|
828
|
+
connectionTargetsChild(connection: Connection): boolean;
|
|
829
|
+
requestTargetsChild(request: Request): boolean;
|
|
830
|
+
forwardWebSocketConnect(
|
|
831
|
+
connection: Connection,
|
|
832
|
+
request: Request,
|
|
833
|
+
options: {
|
|
834
|
+
gate: boolean;
|
|
835
|
+
}
|
|
836
|
+
): Promise<boolean>;
|
|
837
|
+
forwardWebSocketMessage(
|
|
838
|
+
connection: Connection,
|
|
839
|
+
message: WSMessage,
|
|
840
|
+
replyBridge?: DynamicAgentConnectionBridge
|
|
841
|
+
): Promise<boolean>;
|
|
842
|
+
forwardWebSocketClose(
|
|
843
|
+
connection: Connection,
|
|
844
|
+
code: number,
|
|
845
|
+
reason: string,
|
|
846
|
+
wasClean: boolean
|
|
847
|
+
): Promise<boolean>;
|
|
848
|
+
handleWebSocketConnect(
|
|
849
|
+
bridge: DynamicAgentConnectionBridge,
|
|
850
|
+
meta: DynamicAgentConnectionMeta
|
|
851
|
+
): Promise<void>;
|
|
852
|
+
handleWebSocketMessage(
|
|
853
|
+
message: WSMessage,
|
|
854
|
+
bridge: DynamicAgentConnectionBridge,
|
|
855
|
+
meta: DynamicAgentConnectionMeta,
|
|
856
|
+
replyBridge?: DynamicAgentConnectionBridge
|
|
857
|
+
): Promise<void>;
|
|
858
|
+
handleWebSocketClose(
|
|
859
|
+
code: number,
|
|
860
|
+
reason: string,
|
|
861
|
+
wasClean: boolean,
|
|
862
|
+
bridge: DynamicAgentConnectionBridge,
|
|
863
|
+
meta: DynamicAgentConnectionMeta
|
|
864
|
+
): Promise<void>;
|
|
865
|
+
runWithBridge<T>(
|
|
866
|
+
bridge: DynamicAgentConnectionBridgeLike,
|
|
867
|
+
connectionId: string,
|
|
868
|
+
fn: () => Promise<T> | T
|
|
869
|
+
): Promise<T>;
|
|
870
|
+
createBridgeConnection(meta: DynamicAgentConnectionMeta): Connection;
|
|
871
|
+
storeVirtualConnection(connection: Connection): void;
|
|
872
|
+
/**
|
|
873
|
+
* Restore the facet identity persisted by `init` (wake after
|
|
874
|
+
* hibernation), then best-effort hydrate the virtual connections
|
|
875
|
+
* from the root's WebSocket state.
|
|
876
|
+
*/
|
|
877
|
+
restoreFacetContext(): Promise<void>;
|
|
878
|
+
hydrateConnectionsFromRoot(): Promise<void>;
|
|
879
|
+
getRawConnectionState(connection: Connection): unknown;
|
|
880
|
+
getForwardedState(connection: Connection): unknown;
|
|
881
|
+
/**
|
|
882
|
+
* Resolve the facet Fetcher for the match and forward the request to
|
|
883
|
+
* it with `/sub/{class}/{name}` stripped.
|
|
884
|
+
*/
|
|
885
|
+
forward(
|
|
886
|
+
req: Request,
|
|
887
|
+
match: {
|
|
888
|
+
childClass: string;
|
|
889
|
+
childName: string;
|
|
890
|
+
remainingPath: string;
|
|
891
|
+
}
|
|
892
|
+
): Promise<Response>;
|
|
893
|
+
/**
|
|
894
|
+
* Bridge used by `getSubAgentByName`: resolve the facet and dispatch
|
|
895
|
+
* one RPC method. Stateless — no cached references.
|
|
896
|
+
*/
|
|
897
|
+
invoke(
|
|
898
|
+
className: string,
|
|
899
|
+
name: string,
|
|
900
|
+
method: string,
|
|
901
|
+
args: unknown[]
|
|
902
|
+
): Promise<unknown>;
|
|
903
|
+
/**
|
|
904
|
+
* Bridge used by `parentAgent()` when the requested parent is itself
|
|
905
|
+
* a facet (and therefore has no top-level env namespace). The root
|
|
906
|
+
* receives the full root-first target path, then each hop delegates
|
|
907
|
+
* to the next facet using that facet's own `ctx.facets`.
|
|
908
|
+
*/
|
|
909
|
+
invokePath(
|
|
910
|
+
path: ReadonlyArray<{
|
|
911
|
+
className: string;
|
|
912
|
+
name: string;
|
|
913
|
+
}>,
|
|
914
|
+
method: string,
|
|
915
|
+
args: unknown[]
|
|
916
|
+
): Promise<unknown>;
|
|
917
|
+
invokeStubMethod(
|
|
918
|
+
stub: unknown,
|
|
919
|
+
className: string,
|
|
920
|
+
method: string,
|
|
921
|
+
args: unknown[]
|
|
922
|
+
): Promise<unknown>;
|
|
923
|
+
/**
|
|
924
|
+
* Initialize the host agent as a facet in a single RPC. Runs entirely
|
|
925
|
+
* inside the child's isolate, so every storage write and `onStart()`
|
|
926
|
+
* I/O is owned by the child DO.
|
|
927
|
+
*/
|
|
928
|
+
init(
|
|
929
|
+
name: string,
|
|
930
|
+
parentPath?: ReadonlyArray<{
|
|
931
|
+
className: string;
|
|
932
|
+
name: string;
|
|
933
|
+
}>,
|
|
934
|
+
identityName?: string
|
|
935
|
+
): Promise<void>;
|
|
936
|
+
/** Remove a completed facet fiber from the root-side index. */
|
|
937
|
+
unregisterRun(
|
|
938
|
+
ownerPath: ReadonlyArray<AgentPathStep>,
|
|
939
|
+
runId: string
|
|
940
|
+
): Promise<void>;
|
|
941
|
+
}
|
|
942
|
+
//#endregion
|
|
943
|
+
//#region src/dynamic-agents/api.d.ts
|
|
944
|
+
/**
|
|
945
|
+
* The public dynamic-agents capability surface, reached via
|
|
946
|
+
* `this.dynamicAgents` on an Agent.
|
|
947
|
+
*
|
|
948
|
+
* A dynamic agent is a facet-backed child: it runs in its own isolate
|
|
949
|
+
* with its own SQLite database, colocated with — and supervised by —
|
|
950
|
+
* its parent Agent. Use dynamic agents for code whose class or
|
|
951
|
+
* lifecycle the parent owns (dynamically-loaded/generated code,
|
|
952
|
+
* per-run tool agents, sandboxed components). For independent peers
|
|
953
|
+
* such as one-DO-per-chat, use `getAgentByName` instead.
|
|
954
|
+
*
|
|
955
|
+
* @experimental The API surface may change before stabilizing.
|
|
956
|
+
*/
|
|
957
|
+
declare class DynamicAgents {
|
|
958
|
+
#private;
|
|
959
|
+
/** @internal Constructed by Agent; do not instantiate directly. */
|
|
960
|
+
constructor(internal: DynamicAgentsInternal);
|
|
961
|
+
/**
|
|
962
|
+
* Get (creating or waking if needed) the dynamic agent of the given
|
|
963
|
+
* class and name, as a typed RPC stub. Idempotent — repeated calls
|
|
964
|
+
* with the same class and name return the same child.
|
|
965
|
+
*
|
|
966
|
+
* @experimental
|
|
967
|
+
*/
|
|
968
|
+
get<T extends Agent>(
|
|
969
|
+
cls: DynamicAgentClass<T>,
|
|
970
|
+
name: string
|
|
971
|
+
): Promise<DynamicAgentStub<T>>;
|
|
972
|
+
/**
|
|
973
|
+
* Forcefully abort a running dynamic agent. The child stops
|
|
974
|
+
* executing immediately and restarts on the next {@link get} call;
|
|
975
|
+
* its storage is preserved. Transitively aborts the child's own
|
|
976
|
+
* children. Pending RPC calls receive the reason as an error.
|
|
977
|
+
*
|
|
978
|
+
* @experimental
|
|
979
|
+
*/
|
|
980
|
+
abort(cls: DynamicAgentClass, name: string, reason?: unknown): void;
|
|
981
|
+
/**
|
|
982
|
+
* Delete a dynamic agent: abort it if running, then permanently wipe
|
|
983
|
+
* its storage. Transitively deletes the child's own children.
|
|
984
|
+
*
|
|
985
|
+
* @experimental
|
|
986
|
+
*/
|
|
987
|
+
delete(cls: DynamicAgentClass, name: string): Promise<void>;
|
|
988
|
+
/**
|
|
989
|
+
* Whether this agent has previously spawned (and not deleted) a
|
|
990
|
+
* dynamic agent of the given class and name. Backed by an
|
|
991
|
+
* auto-maintained SQLite registry in the parent's storage.
|
|
992
|
+
*
|
|
993
|
+
* @experimental
|
|
994
|
+
*/
|
|
995
|
+
has<T extends Agent>(cls: DynamicAgentClass<T>, name: string): boolean;
|
|
996
|
+
has(className: string, name: string): boolean;
|
|
997
|
+
/**
|
|
998
|
+
* List known dynamic agents, optionally filtered by class. Reflects
|
|
999
|
+
* the registry rows written by {@link get} and removed by
|
|
1000
|
+
* {@link delete}.
|
|
1001
|
+
*
|
|
1002
|
+
* @experimental
|
|
1003
|
+
*/
|
|
1004
|
+
list<T extends Agent>(
|
|
1005
|
+
cls: DynamicAgentClass<T>
|
|
1006
|
+
): Array<{
|
|
1007
|
+
className: string;
|
|
1008
|
+
name: string;
|
|
1009
|
+
createdAt: number;
|
|
1010
|
+
}>;
|
|
1011
|
+
list(className?: string): Array<{
|
|
1012
|
+
className: string;
|
|
1013
|
+
name: string;
|
|
1014
|
+
createdAt: number;
|
|
1015
|
+
}>;
|
|
1016
|
+
}
|
|
292
1017
|
//#endregion
|
|
293
1018
|
//#region src/core/events.d.ts
|
|
294
1019
|
interface Disposable {
|
|
@@ -3162,7 +3887,7 @@ type RunAgentToolResult<Output = unknown> = {
|
|
|
3162
3887
|
*/
|
|
3163
3888
|
childStillRunning?: boolean;
|
|
3164
3889
|
};
|
|
3165
|
-
type ChatCapableAgentClass<T extends Agent = Agent> =
|
|
3890
|
+
type ChatCapableAgentClass<T extends Agent = Agent> = DynamicAgentClass<T>;
|
|
3166
3891
|
type AgentToolRunInspection<Output = unknown> = {
|
|
3167
3892
|
runId: string;
|
|
3168
3893
|
status: Exclude<AgentToolRunStatus, "interrupted">;
|
|
@@ -3355,121 +4080,6 @@ type RPCResponse = {
|
|
|
3355
4080
|
error: string;
|
|
3356
4081
|
}
|
|
3357
4082
|
);
|
|
3358
|
-
/**
|
|
3359
|
-
* Metadata for a callable method
|
|
3360
|
-
*/
|
|
3361
|
-
type CallableMetadata = {
|
|
3362
|
-
/** Optional description of what the method does */ description?: string /** Whether the method supports streaming responses */;
|
|
3363
|
-
streaming?: boolean;
|
|
3364
|
-
};
|
|
3365
|
-
type SubAgentConnectionMeta = {
|
|
3366
|
-
id: string;
|
|
3367
|
-
uri: string | null;
|
|
3368
|
-
tags: string[];
|
|
3369
|
-
state: unknown;
|
|
3370
|
-
requestHeaders?: [string, string][];
|
|
3371
|
-
};
|
|
3372
|
-
type SubAgentConnectionBridgeLike = {
|
|
3373
|
-
send(message: string | ArrayBuffer | ArrayBufferView): void | Promise<void>;
|
|
3374
|
-
close(code?: number, reason?: string): void | Promise<void>;
|
|
3375
|
-
setState(state: unknown): unknown | Promise<unknown>;
|
|
3376
|
-
broadcast(
|
|
3377
|
-
ownerPath: ReadonlyArray<{
|
|
3378
|
-
className: string;
|
|
3379
|
-
name: string;
|
|
3380
|
-
}>,
|
|
3381
|
-
message: string | ArrayBuffer | ArrayBufferView,
|
|
3382
|
-
without?: string[]
|
|
3383
|
-
): void | Promise<void>;
|
|
3384
|
-
};
|
|
3385
|
-
declare class SubAgentConnectionBridge
|
|
3386
|
-
extends RpcTarget
|
|
3387
|
-
implements SubAgentConnectionBridgeLike
|
|
3388
|
-
{
|
|
3389
|
-
#private;
|
|
3390
|
-
constructor(
|
|
3391
|
-
connection: Connection,
|
|
3392
|
-
broadcast?: (
|
|
3393
|
-
ownerPath: ReadonlyArray<{
|
|
3394
|
-
className: string;
|
|
3395
|
-
name: string;
|
|
3396
|
-
}>,
|
|
3397
|
-
message: string | ArrayBuffer | ArrayBufferView,
|
|
3398
|
-
without?: string[]
|
|
3399
|
-
) => void | Promise<void>
|
|
3400
|
-
);
|
|
3401
|
-
send(message: string | ArrayBuffer | ArrayBufferView): void;
|
|
3402
|
-
close(code?: number, reason?: string): void;
|
|
3403
|
-
setState(state: unknown): unknown;
|
|
3404
|
-
broadcast(
|
|
3405
|
-
ownerPath: ReadonlyArray<{
|
|
3406
|
-
className: string;
|
|
3407
|
-
name: string;
|
|
3408
|
-
}>,
|
|
3409
|
-
message: string | ArrayBuffer | ArrayBufferView,
|
|
3410
|
-
without?: string[]
|
|
3411
|
-
): void | Promise<void>;
|
|
3412
|
-
}
|
|
3413
|
-
/**
|
|
3414
|
-
* Constructor type for a sub-agent class.
|
|
3415
|
-
* Used by {@link Agent.subAgent} to reference the child class
|
|
3416
|
-
* via `ctx.exports`.
|
|
3417
|
-
*
|
|
3418
|
-
* The class name (`cls.name`) must match the export name in the
|
|
3419
|
-
* worker entry point — re-exports under a different name
|
|
3420
|
-
* (e.g. `export { Foo as Bar }`) are not supported.
|
|
3421
|
-
*/
|
|
3422
|
-
type SubAgentClass<T extends Agent = Agent> = {
|
|
3423
|
-
new (ctx: DurableObjectState, env: never): T;
|
|
3424
|
-
};
|
|
3425
|
-
/**
|
|
3426
|
-
* Wraps `T` in a `Promise` unless it already is one.
|
|
3427
|
-
*/
|
|
3428
|
-
type Promisify<T> = T extends Promise<unknown> ? T : Promise<T>;
|
|
3429
|
-
/**
|
|
3430
|
-
* A typed RPC stub for a sub-agent. Exposes all public instance methods
|
|
3431
|
-
* as callable RPC methods with Promise-wrapped return types.
|
|
3432
|
-
*
|
|
3433
|
-
* Methods owned by `Agent`, its lifecycle, or `DurableObject` internals
|
|
3434
|
-
* are excluded — only user-defined methods on the subclass are exposed.
|
|
3435
|
-
*/
|
|
3436
|
-
type SubAgentStub<T extends Agent> = {
|
|
3437
|
-
[K in keyof T as K extends keyof Agent
|
|
3438
|
-
? never
|
|
3439
|
-
: T[K] extends (...args: never[]) => unknown
|
|
3440
|
-
? K
|
|
3441
|
-
: never]: T[K] extends (...args: infer A) => infer R
|
|
3442
|
-
? (...args: A) => Promisify<R>
|
|
3443
|
-
: never;
|
|
3444
|
-
};
|
|
3445
|
-
/**
|
|
3446
|
-
* Decorator that marks a method as callable by clients
|
|
3447
|
-
* @param metadata Optional metadata about the callable method
|
|
3448
|
-
*/
|
|
3449
|
-
declare function callable(
|
|
3450
|
-
metadata?: CallableMetadata
|
|
3451
|
-
): <This, Args extends unknown[], Return>(
|
|
3452
|
-
target: (this: This, ...args: Args) => Return,
|
|
3453
|
-
_context: ClassMethodDecoratorContext
|
|
3454
|
-
) => (this: This, ...args: Args) => Return;
|
|
3455
|
-
/**
|
|
3456
|
-
* Decorator that marks a method as callable by clients
|
|
3457
|
-
* @deprecated this has been renamed to callable, and unstable_callable will be removed in the next major version
|
|
3458
|
-
* @param metadata Optional metadata about the callable method
|
|
3459
|
-
*/
|
|
3460
|
-
declare const unstable_callable: (
|
|
3461
|
-
metadata?: CallableMetadata
|
|
3462
|
-
) => <This, Args extends unknown[], Return>(
|
|
3463
|
-
target: (this: This, ...args: Args) => Return,
|
|
3464
|
-
_context: ClassMethodDecoratorContext
|
|
3465
|
-
) => (this: This, ...args: Args) => Return;
|
|
3466
|
-
type QueueItem<T = string> = {
|
|
3467
|
-
id: string;
|
|
3468
|
-
payload: T;
|
|
3469
|
-
callback: keyof Agent<Cloudflare.Env>;
|
|
3470
|
-
created_at: number;
|
|
3471
|
-
retry?: RetryOptions;
|
|
3472
|
-
};
|
|
3473
4083
|
type DetachedReconcilePayload = {
|
|
3474
4084
|
cadenceIndex?: number;
|
|
3475
4085
|
};
|
|
@@ -3846,11 +4456,11 @@ type WorkflowName<E> = WorkflowBinding<E> | (string & {});
|
|
|
3846
4456
|
/**
|
|
3847
4457
|
* Base class for creating Agent implementations
|
|
3848
4458
|
* @template Env Environment type containing bindings
|
|
3849
|
-
* @template
|
|
4459
|
+
* @template TState State type to store within the Agent
|
|
3850
4460
|
*/
|
|
3851
4461
|
declare class Agent<
|
|
3852
4462
|
Env extends Cloudflare.Env = Cloudflare.Env,
|
|
3853
|
-
|
|
4463
|
+
TState = unknown,
|
|
3854
4464
|
Props extends Record<string, unknown> = Record<string, unknown>
|
|
3855
4465
|
> extends DurableObject<Env> {
|
|
3856
4466
|
/**
|
|
@@ -3859,6 +4469,27 @@ declare class Agent<
|
|
|
3859
4469
|
* @experimental The API surface may change before stabilizing.
|
|
3860
4470
|
*/
|
|
3861
4471
|
readonly lifecycle: Lifecycle<Env, Props>;
|
|
4472
|
+
/**
|
|
4473
|
+
* WebSocket connection subsystem. Constructed as a field initializer
|
|
4474
|
+
* so it exists before the constructor installs it; the handler arrows
|
|
4475
|
+
* defer to `this.*`, so they always hit the framework-wrapped hooks.
|
|
4476
|
+
* Those wrappers still open their own invocation scope even though
|
|
4477
|
+
* the capability's dispatch already entered one via the host invoker
|
|
4478
|
+
* — the inner wrap is kept because the wrapped hooks are also invoked
|
|
4479
|
+
* from paths that do not pass through the capability (facet bridging,
|
|
4480
|
+
* direct calls).
|
|
4481
|
+
*/
|
|
4482
|
+
/**
|
|
4483
|
+
* Durable state: the `cf_agents_state` row, lazy load, validated persistence.
|
|
4484
|
+
* `initialState` stays on Agent (a subclass field, initialized after this
|
|
4485
|
+
* one) and is seeded by the `state` getter. Typed `<unknown>` rather than
|
|
4486
|
+
* `<TState>` because `TState` appears in both `get()` and `set()` positions,
|
|
4487
|
+
* which would make `Agent`'s own `TState` parameter invariant and break
|
|
4488
|
+
* `Subclass -> Agent<Env, unknown>` assignability; the typed boundary is
|
|
4489
|
+
* re-established in `state` / `setState`.
|
|
4490
|
+
*/
|
|
4491
|
+
readonly _state: State<unknown>;
|
|
4492
|
+
private readonly _webSockets;
|
|
3862
4493
|
/** Run user initialization after lifecycle components have started. */
|
|
3863
4494
|
onStart(_props?: Props): void | Promise<void>;
|
|
3864
4495
|
/** Handle an HTTP request not claimed by a lifecycle component. */
|
|
@@ -3884,7 +4515,6 @@ declare class Agent<
|
|
|
3884
4515
|
): string[] | Promise<string[]>;
|
|
3885
4516
|
/** @internal Ensure lifecycle startup before a native RPC implementation. */
|
|
3886
4517
|
__unsafe_ensureInitialized(props?: Props): Promise<void>;
|
|
3887
|
-
private _state;
|
|
3888
4518
|
private _disposables;
|
|
3889
4519
|
private _destroyed;
|
|
3890
4520
|
/**
|
|
@@ -3892,7 +4522,6 @@ declare class Agent<
|
|
|
3892
4522
|
* Used by internal flag methods (readonly, no-protocol) to read/write
|
|
3893
4523
|
* _cf_-prefixed keys without going through the user-facing state/setState.
|
|
3894
4524
|
*/
|
|
3895
|
-
private _rawStateAccessors;
|
|
3896
4525
|
/**
|
|
3897
4526
|
* Cached persistence-hook dispatch mode, computed once in the constructor.
|
|
3898
4527
|
* - "new" → call onStateChanged
|
|
@@ -3903,10 +4532,6 @@ declare class Agent<
|
|
|
3903
4532
|
/** True when this agent runs as a facet (sub-agent) inside a parent. */
|
|
3904
4533
|
private _isFacet;
|
|
3905
4534
|
private _protocolBroadcastExcludeIds;
|
|
3906
|
-
private _cf_subAgentBridgeContext;
|
|
3907
|
-
private _cf_virtualSubAgentConnections;
|
|
3908
|
-
private _cf_subAgentConnectionOperationTails;
|
|
3909
|
-
private _cf_subAgentBroadcastOperationTail?;
|
|
3910
4535
|
/**
|
|
3911
4536
|
* User-facing facet name. For legacy facets this is the same as
|
|
3912
4537
|
* `ctx.id.name`; path-scoped facets use an internal routing id and
|
|
@@ -3924,20 +4549,39 @@ declare class Agent<
|
|
|
3924
4549
|
/** Warn-once guard: `chatRecovery` reassigned during onStart() (too late for wake recovery). */
|
|
3925
4550
|
private _warnedChatRecoveryInOnStart;
|
|
3926
4551
|
/**
|
|
3927
|
-
* Number of active keepAlive() callers. When > 0, `
|
|
4552
|
+
* Number of active keepAlive() callers. When > 0, `_syncHostJobs()`
|
|
3928
4553
|
* caps the next alarm at `keepAliveIntervalMs` so the DO stays alive.
|
|
3929
4554
|
* Purely in-memory — lost on eviction, which is correct because the
|
|
3930
4555
|
* in-memory work keepAlive was protecting is also lost.
|
|
3931
4556
|
* @internal
|
|
3932
4557
|
*/
|
|
3933
4558
|
_keepAliveRefs: number;
|
|
4559
|
+
/** @internal The extracted dynamic-agent (facet) machinery. */
|
|
4560
|
+
private _dynamicAgentsInstance;
|
|
4561
|
+
/** @internal */
|
|
4562
|
+
private get _dynamicAgents();
|
|
4563
|
+
/** @internal */
|
|
4564
|
+
private _dynamicAgentsApi;
|
|
3934
4565
|
/**
|
|
3935
|
-
*
|
|
3936
|
-
*
|
|
3937
|
-
*
|
|
3938
|
-
*
|
|
4566
|
+
* The dynamic-agents capability: facet-backed child agents that run
|
|
4567
|
+
* in their own isolate with their own SQLite database, colocated
|
|
4568
|
+
* with — and supervised by — this agent.
|
|
4569
|
+
*
|
|
4570
|
+
* Use dynamic agents for code whose class or lifecycle this agent
|
|
4571
|
+
* owns: dynamically-loaded or AI-generated code, per-run tool
|
|
4572
|
+
* agents, sandboxed components. For independent peers (for example
|
|
4573
|
+
* one Durable Object per chat), use `getAgentByName` instead.
|
|
4574
|
+
*
|
|
4575
|
+
* ```ts
|
|
4576
|
+
* const child = await this.dynamicAgents.get(Researcher, id);
|
|
4577
|
+
* await child.doWork();
|
|
4578
|
+
* this.dynamicAgents.abort(Researcher, id, reason);
|
|
4579
|
+
* await this.dynamicAgents.delete(Researcher, id);
|
|
4580
|
+
* ```
|
|
4581
|
+
*
|
|
4582
|
+
* @experimental The API surface may change before stabilizing.
|
|
3939
4583
|
*/
|
|
3940
|
-
|
|
4584
|
+
get dynamicAgents(): DynamicAgents;
|
|
3941
4585
|
/** @internal In-memory set of fiber IDs running in this process. */
|
|
3942
4586
|
private _runFiberActiveFibers;
|
|
3943
4587
|
/** @internal In-memory abort controllers for managed running fibers. */
|
|
@@ -3970,12 +4614,44 @@ declare class Agent<
|
|
|
3970
4614
|
* cancelSchedule() methods are the stable surface.
|
|
3971
4615
|
*/
|
|
3972
4616
|
readonly scheduler: Scheduler;
|
|
4617
|
+
/**
|
|
4618
|
+
* Durable background-work capability installed into this Agent's
|
|
4619
|
+
* Lifecycle. Agent's queue()/dequeue()/dequeueAll()/dequeueAllByCallback()/
|
|
4620
|
+
* getQueue()/getQueues() methods are its surface.
|
|
4621
|
+
*/
|
|
4622
|
+
private readonly _queue;
|
|
4623
|
+
/**
|
|
4624
|
+
* Durable replayable execution capability installed into this Agent's
|
|
4625
|
+
* Lifecycle. Declare definitions on the overridable
|
|
4626
|
+
* {@link taskDefinitions} property and start runs with
|
|
4627
|
+
* `this.tasks.run(name, input, options)`.
|
|
4628
|
+
*
|
|
4629
|
+
* @experimental The API surface may change before stabilizing.
|
|
4630
|
+
*/
|
|
4631
|
+
readonly tasks: Tasks;
|
|
4632
|
+
/**
|
|
4633
|
+
* Named Task definitions for this Agent, resolved lazily on every
|
|
4634
|
+
* dispatch. Declare as a field so the map is rebuilt on every Durable
|
|
4635
|
+
* Object wake — that is what lets in-flight runs resolve their persisted
|
|
4636
|
+
* definition names after a restart:
|
|
4637
|
+
*
|
|
4638
|
+
* ```ts
|
|
4639
|
+
* readonly taskDefinitions = {
|
|
4640
|
+
* "build-report@v1": async (input: ReportInput, step: TaskStep) => {
|
|
4641
|
+
* // ...
|
|
4642
|
+
* }
|
|
4643
|
+
* } satisfies TaskHandlers;
|
|
4644
|
+
* ```
|
|
4645
|
+
*
|
|
4646
|
+
* @experimental The API surface may change before stabilizing.
|
|
4647
|
+
*/
|
|
4648
|
+
readonly taskDefinitions?: TaskHandlers;
|
|
3973
4649
|
readonly mcp: MCPClientManager;
|
|
3974
4650
|
/**
|
|
3975
4651
|
* Initial state for the Agent
|
|
3976
4652
|
* Override to provide default state values
|
|
3977
4653
|
*/
|
|
3978
|
-
initialState:
|
|
4654
|
+
initialState: TState;
|
|
3979
4655
|
/**
|
|
3980
4656
|
* Stable key for Workers AI session affinity (prefix-cache optimization).
|
|
3981
4657
|
*
|
|
@@ -3995,9 +4671,12 @@ declare class Agent<
|
|
|
3995
4671
|
*/
|
|
3996
4672
|
get sessionAffinity(): string;
|
|
3997
4673
|
/**
|
|
3998
|
-
* Current state of the Agent
|
|
4674
|
+
* Current state of the Agent.
|
|
4675
|
+
*
|
|
4676
|
+
* Delegates to the State capability, which owns lazy load and the
|
|
4677
|
+
* in-memory cache; Agent seeds `initialState` on first access.
|
|
3999
4678
|
*/
|
|
4000
|
-
get state():
|
|
4679
|
+
get state(): TState;
|
|
4001
4680
|
/**
|
|
4002
4681
|
* Agent configuration options.
|
|
4003
4682
|
* Override in subclasses - only specify what you want to change.
|
|
@@ -4050,6 +4729,14 @@ declare class Agent<
|
|
|
4050
4729
|
* local dev and the constructor only runs once per DO instance).
|
|
4051
4730
|
*/
|
|
4052
4731
|
protected _ensureSchema(): void;
|
|
4732
|
+
/**
|
|
4733
|
+
* Read the Agent's schema version from its KV key. A DO created before the
|
|
4734
|
+
* State capability owned `cf_agents_state` has the version as a row in that
|
|
4735
|
+
* table instead: read it once, move it to the key, and delete the row so the
|
|
4736
|
+
* table is left with a single owner. Synchronous (`storage.kv`) because the
|
|
4737
|
+
* constructor gates DDL on it.
|
|
4738
|
+
*/
|
|
4739
|
+
private _readSchemaVersion;
|
|
4053
4740
|
constructor(ctx: AgentContext, env: Env);
|
|
4054
4741
|
private _restoreAgentFacetContext;
|
|
4055
4742
|
/**
|
|
@@ -4064,26 +4751,20 @@ declare class Agent<
|
|
|
4064
4751
|
* @param excludeIds Additional connection IDs to exclude (e.g. the source)
|
|
4065
4752
|
*/
|
|
4066
4753
|
private _broadcastProtocol;
|
|
4067
|
-
|
|
4754
|
+
/**
|
|
4755
|
+
* React to a persisted state change from the State capability.
|
|
4756
|
+
*
|
|
4757
|
+
* Reproduces the pre-migration steps 3-4: broadcast the new state to
|
|
4758
|
+
* protocol-enabled connections (excluding the originating connection) and
|
|
4759
|
+
* run the notification hook off the invocation tail.
|
|
4760
|
+
*/
|
|
4761
|
+
private _handleStateChanged;
|
|
4068
4762
|
/**
|
|
4069
4763
|
* Update the Agent's state
|
|
4070
4764
|
* @param state New state to set
|
|
4071
4765
|
* @throws Error if called from a readonly connection context
|
|
4072
4766
|
*/
|
|
4073
|
-
setState(state:
|
|
4074
|
-
/**
|
|
4075
|
-
* Wraps connection.state and connection.setState so that internal
|
|
4076
|
-
* _cf_-prefixed flags (readonly, no-protocol) are hidden from user code
|
|
4077
|
-
* and cannot be accidentally overwritten.
|
|
4078
|
-
*
|
|
4079
|
-
* Idempotent — safe to call multiple times on the same connection.
|
|
4080
|
-
* After hibernation, the _rawStateAccessors WeakMap is empty but the
|
|
4081
|
-
* connection's state getter still reads from the persisted WebSocket
|
|
4082
|
-
* attachment. Calling this method re-captures the raw getter so that
|
|
4083
|
-
* predicate methods (isConnectionReadonly, isConnectionProtocolEnabled)
|
|
4084
|
-
* work correctly post-hibernation.
|
|
4085
|
-
*/
|
|
4086
|
-
private _ensureConnectionWrapped;
|
|
4767
|
+
setState(state: TState): void;
|
|
4087
4768
|
/**
|
|
4088
4769
|
* Mark a connection as readonly or readwrite
|
|
4089
4770
|
* @param connection The connection to mark
|
|
@@ -4117,8 +4798,8 @@ declare class Agent<
|
|
|
4117
4798
|
*
|
|
4118
4799
|
* Write an internal `_cf_`-prefixed flag to the raw connection state,
|
|
4119
4800
|
* bypassing the user-facing state wrapper. The key must be registered
|
|
4120
|
-
*
|
|
4121
|
-
* and hidden from `connection.state`.
|
|
4801
|
+
* with `registerInternalConnectionKeys` so it is preserved across user
|
|
4802
|
+
* `setState` calls and hidden from `connection.state`.
|
|
4122
4803
|
*
|
|
4123
4804
|
* @internal
|
|
4124
4805
|
*/
|
|
@@ -4168,18 +4849,13 @@ declare class Agent<
|
|
|
4168
4849
|
* @returns True if the connection receives protocol messages
|
|
4169
4850
|
*/
|
|
4170
4851
|
isConnectionProtocolEnabled(connection: Connection): boolean;
|
|
4171
|
-
/**
|
|
4172
|
-
* Mark a connection as having protocol messages disabled.
|
|
4173
|
-
* Called internally when shouldSendProtocolMessages returns false.
|
|
4174
|
-
*/
|
|
4175
|
-
private _setConnectionNoProtocol;
|
|
4176
4852
|
/**
|
|
4177
4853
|
* Called before the Agent's state is persisted and broadcast.
|
|
4178
4854
|
* Override to validate or reject an update by throwing an error.
|
|
4179
4855
|
*
|
|
4180
4856
|
* IMPORTANT: This hook must be synchronous.
|
|
4181
4857
|
*/
|
|
4182
|
-
validateStateChange(_nextState:
|
|
4858
|
+
validateStateChange(_nextState: TState, _source: Connection | "server"): void;
|
|
4183
4859
|
/**
|
|
4184
4860
|
* Called after the Agent's state has been persisted and broadcast to all clients.
|
|
4185
4861
|
* This is a notification hook — errors here are routed to onError and do not
|
|
@@ -4189,7 +4865,7 @@ declare class Agent<
|
|
|
4189
4865
|
* @param source Source of the state update ("server" or a client connection)
|
|
4190
4866
|
*/
|
|
4191
4867
|
onStateChanged(
|
|
4192
|
-
_state:
|
|
4868
|
+
_state: TState | undefined,
|
|
4193
4869
|
_source: Connection | "server"
|
|
4194
4870
|
): void;
|
|
4195
4871
|
/**
|
|
@@ -4204,7 +4880,7 @@ declare class Agent<
|
|
|
4204
4880
|
* @param source Source of the state update ("server" or a client connection)
|
|
4205
4881
|
*/
|
|
4206
4882
|
onStateUpdate(
|
|
4207
|
-
_state:
|
|
4883
|
+
_state: TState | undefined,
|
|
4208
4884
|
_source: Connection | "server"
|
|
4209
4885
|
): void;
|
|
4210
4886
|
/**
|
|
@@ -4302,11 +4978,16 @@ declare class Agent<
|
|
|
4302
4978
|
}
|
|
4303
4979
|
): Promise<T>;
|
|
4304
4980
|
/**
|
|
4305
|
-
* Queue a task to
|
|
4981
|
+
* Queue a task to run in the background.
|
|
4982
|
+
*
|
|
4983
|
+
* The item is durable: it runs from the Lifecycle alarm event loop after
|
|
4984
|
+
* this call returns, in push order, one at a time, with retries per
|
|
4985
|
+
* `options.retry`, and survives the Durable Object leaving memory.
|
|
4306
4986
|
* @param callback Name of the method to call
|
|
4307
4987
|
* @param payload Payload to pass to the callback
|
|
4308
4988
|
* @param options Options for the queued task
|
|
4309
4989
|
* @param options.retry Retry options for the callback execution
|
|
4990
|
+
* @param options.id Stable id; a push with an existing id replaces that item
|
|
4310
4991
|
* @returns The ID of the queued task
|
|
4311
4992
|
*/
|
|
4312
4993
|
queue<T = unknown>(
|
|
@@ -4314,39 +4995,36 @@ declare class Agent<
|
|
|
4314
4995
|
payload: T,
|
|
4315
4996
|
options?: {
|
|
4316
4997
|
retry?: RetryOptions;
|
|
4998
|
+
id?: string;
|
|
4317
4999
|
}
|
|
4318
5000
|
): Promise<string>;
|
|
4319
|
-
private _flushingQueue;
|
|
4320
|
-
private _flushQueue;
|
|
4321
5001
|
/**
|
|
4322
5002
|
* Dequeue a task by ID
|
|
4323
5003
|
* @param id ID of the task to dequeue
|
|
4324
5004
|
*/
|
|
4325
|
-
dequeue(id: string):
|
|
5005
|
+
dequeue(id: string): Promise<boolean>;
|
|
4326
5006
|
/**
|
|
4327
5007
|
* Dequeue all tasks
|
|
4328
5008
|
*/
|
|
4329
|
-
dequeueAll():
|
|
5009
|
+
dequeueAll(): Promise<number>;
|
|
4330
5010
|
/**
|
|
4331
5011
|
* Dequeue all tasks by callback
|
|
4332
5012
|
* @param callback Name of the callback to dequeue
|
|
4333
5013
|
*/
|
|
4334
|
-
dequeueAllByCallback(callback: string):
|
|
5014
|
+
dequeueAllByCallback(callback: string): Promise<number>;
|
|
4335
5015
|
/**
|
|
4336
5016
|
* Get a queued task by ID
|
|
4337
5017
|
* @param id ID of the task to get
|
|
4338
5018
|
* @returns The task or undefined if not found
|
|
4339
5019
|
*/
|
|
4340
|
-
getQueue(id: string): QueueItem<
|
|
5020
|
+
getQueue<T = unknown>(id: string): Promise<QueueItem<T> | undefined>;
|
|
4341
5021
|
/**
|
|
4342
|
-
* Get all
|
|
5022
|
+
* Get all queued tasks whose payload has `key` equal to `value`
|
|
4343
5023
|
* @param key Key to filter by
|
|
4344
5024
|
* @param value Value to filter by
|
|
4345
5025
|
* @returns Array of matching QueueItem objects
|
|
4346
5026
|
*/
|
|
4347
|
-
getQueues(key: string, value: string): QueueItem<
|
|
4348
|
-
private _facetRunRowsForPrefix;
|
|
4349
|
-
private _deleteFacetRunRowsForPrefix;
|
|
5027
|
+
getQueues<T = unknown>(key: string, value: string): Promise<QueueItem<T>[]>;
|
|
4350
5028
|
private _lifecycleRouteAddress;
|
|
4351
5029
|
private _routeLifecycleToRoot;
|
|
4352
5030
|
private _routeLifecycleToTarget;
|
|
@@ -4356,7 +5034,6 @@ declare class Agent<
|
|
|
4356
5034
|
envelope: LifecycleRouteEnvelope
|
|
4357
5035
|
): Promise<unknown>;
|
|
4358
5036
|
private _rootAlarmOwner;
|
|
4359
|
-
private _cf_rootResolvesToSelf;
|
|
4360
5037
|
/**
|
|
4361
5038
|
* Clean root-owned bookkeeping for a sub-tree of facets. This
|
|
4362
5039
|
* bulk-cancels schedules whose `owner_path` starts with the given
|
|
@@ -4372,8 +5049,8 @@ declare class Agent<
|
|
|
4372
5049
|
): Promise<void>;
|
|
4373
5050
|
/**
|
|
4374
5051
|
* Acquire a root-owned keepAlive ref on behalf of a descendant facet.
|
|
4375
|
-
* Facets
|
|
4376
|
-
* alarm, so this lets facet work use the root alarm heartbeat.
|
|
5052
|
+
* Facets run in separate colocated isolates but cannot set their own
|
|
5053
|
+
* physical alarm, so this lets facet work use the root alarm heartbeat.
|
|
4377
5054
|
* @internal
|
|
4378
5055
|
*/
|
|
4379
5056
|
_cf_acquireFacetKeepAlive(
|
|
@@ -4429,10 +5106,7 @@ declare class Agent<
|
|
|
4429
5106
|
when: Date | string | number,
|
|
4430
5107
|
callback: keyof this,
|
|
4431
5108
|
payload?: T,
|
|
4432
|
-
options?:
|
|
4433
|
-
retry?: RetryOptions;
|
|
4434
|
-
idempotent?: boolean;
|
|
4435
|
-
}
|
|
5109
|
+
options?: ScheduleOptions
|
|
4436
5110
|
): Promise<Schedule<T>>;
|
|
4437
5111
|
/**
|
|
4438
5112
|
* Schedule a task to run repeatedly at a fixed interval.
|
|
@@ -4636,6 +5310,20 @@ declare class Agent<
|
|
|
4636
5310
|
* Throws if called outside a `runFiber` callback.
|
|
4637
5311
|
*/
|
|
4638
5312
|
stash(data: unknown): void;
|
|
5313
|
+
/**
|
|
5314
|
+
* Run `fn` inside the fiber stash context so `this.stash()` keeps working
|
|
5315
|
+
* for turns executing on the `tasks` capability exactly as it does inside
|
|
5316
|
+
* legacy `runFiber()` closures.
|
|
5317
|
+
* @internal
|
|
5318
|
+
*/
|
|
5319
|
+
protected _withFiberStash<T>(
|
|
5320
|
+
context: {
|
|
5321
|
+
id: string;
|
|
5322
|
+
signal: AbortSignal;
|
|
5323
|
+
stash: (data: unknown) => void;
|
|
5324
|
+
},
|
|
5325
|
+
fn: () => Promise<T>
|
|
5326
|
+
): Promise<T>;
|
|
4639
5327
|
/**
|
|
4640
5328
|
* Called when an interrupted fiber is detected after restart.
|
|
4641
5329
|
* Override to implement recovery (re-invoke work, notify clients, etc.).
|
|
@@ -4710,80 +5398,71 @@ declare class Agent<
|
|
|
4710
5398
|
* executing in memory, which already hold a keepAlive ref) or managed
|
|
4711
5399
|
* ledger fibers stuck in a non-terminal state with no live run row.
|
|
4712
5400
|
*
|
|
4713
|
-
* Used by `
|
|
5401
|
+
* Used by `_syncHostJobs` to arm a follow-up alarm so multi-pass
|
|
4714
5402
|
* recovery (e.g. after a scan-deadline yield, or while retrying a throwing
|
|
4715
5403
|
* recovery hook) resumes instead of starving.
|
|
4716
5404
|
* @internal
|
|
4717
5405
|
*/
|
|
4718
5406
|
private _hasPendingFiberRecovery;
|
|
4719
|
-
private _rearmAlarm;
|
|
4720
|
-
/**
|
|
4721
|
-
* Contribute Agent-owned alarm work that has not yet been extracted into its
|
|
4722
|
-
* own capability. Scheduler contributes independently.
|
|
4723
|
-
* @internal
|
|
4724
|
-
*/
|
|
4725
|
-
getNextAlarm(): Promise<AlarmContribution>;
|
|
4726
|
-
/** @internal Transitional alarm contribution for Agent subclasses. */
|
|
4727
|
-
protected _getExtensionAlarm(): number | null | Promise<number | null>;
|
|
4728
|
-
/** Lifecycle alarm callback; Agent housekeeping runs after user alarm work. */
|
|
4729
|
-
onAlarm(): void;
|
|
4730
5407
|
/**
|
|
4731
|
-
*
|
|
5408
|
+
* Synchronize Agent-owned host jobs with current durable state.
|
|
4732
5409
|
*
|
|
4733
|
-
*
|
|
4734
|
-
*
|
|
5410
|
+
* Replaces the old pull-based `getNextAlarm()` contribution: keep-alive
|
|
5411
|
+
* refs hold a `cf:keep-alive` job, and fiber-recovery / facet-run state
|
|
5412
|
+
* holds a `cf:housekeeping` job. Every state change that used to trigger
|
|
5413
|
+
* an alarm recalculation now re-pushes or cancels these jobs; queue
|
|
5414
|
+
* mutations re-arm the physical alarm automatically.
|
|
5415
|
+
* @internal
|
|
4735
5416
|
*/
|
|
4736
|
-
|
|
4737
|
-
/** Run the Lifecycle alarm phase inside Agent's OOM circuit breaker. */
|
|
4738
|
-
private _cf_runAlarmBody;
|
|
5417
|
+
private _syncHostJobs;
|
|
4739
5418
|
/**
|
|
4740
|
-
*
|
|
5419
|
+
* The next wake fiber-recovery or facet-run housekeeping needs, or `null`
|
|
5420
|
+
* when neither has pending durable state.
|
|
4741
5421
|
*/
|
|
4742
|
-
private
|
|
5422
|
+
private _nextHousekeepingWakeMs;
|
|
5423
|
+
/** Lifecycle alarm callback; Agent housekeeping runs after user alarm work. */
|
|
5424
|
+
onAlarm(): void;
|
|
4743
5425
|
/**
|
|
4744
|
-
*
|
|
4745
|
-
*
|
|
4746
|
-
*
|
|
4747
|
-
* so the circuit breaker can surgically back them off / purge them WITHOUT
|
|
4748
|
-
* disturbing unrelated scheduled tasks. See {@link _cf_handleAlarmMemoryLimitReset}.
|
|
5426
|
+
* Drive one Agent-owned host job from the Lifecycle queue.
|
|
5427
|
+
* @internal Dispatched by Lifecycle's alarm event loop; extensions add
|
|
5428
|
+
* job fns through {@link _onHostJob}.
|
|
4749
5429
|
*/
|
|
4750
|
-
|
|
5430
|
+
onJob(
|
|
5431
|
+
context: LifecycleJobContext
|
|
5432
|
+
): LifecycleJobOutcome | void | Promise<LifecycleJobOutcome | void>;
|
|
4751
5433
|
/**
|
|
4752
|
-
*
|
|
4753
|
-
*
|
|
4754
|
-
* budget (#1825). Runs at the outermost alarm frame (post-unwind, so writes
|
|
4755
|
-
* can land). Default: no-op. Chat hosts override to fire `onExhausted` + the
|
|
4756
|
-
* terminal banner and persist the sealed incident.
|
|
5434
|
+
* @internal Dispatch one host job fn. Agent extensions (Think) override
|
|
5435
|
+
* this to add fns and delegate unknown ones to `super`.
|
|
4757
5436
|
*/
|
|
4758
|
-
protected
|
|
5437
|
+
protected _onHostJob(
|
|
5438
|
+
fn: string,
|
|
5439
|
+
_context: LifecycleJobContext
|
|
5440
|
+
): LifecycleJobOutcome | void | Promise<LifecycleJobOutcome | void>;
|
|
4759
5441
|
/**
|
|
4760
|
-
*
|
|
4761
|
-
*
|
|
4762
|
-
*
|
|
4763
|
-
*
|
|
4764
|
-
*
|
|
5442
|
+
* Apply host policy after the alarm memory-limit breaker records a strike.
|
|
5443
|
+
*
|
|
5444
|
+
* New chat hosts override this hook directly. The sealed-only fallback keeps
|
|
5445
|
+
* `agents` 0.23 compatible with already-published chat packages whose peer
|
|
5446
|
+
* ranges accept it but which implement only the former
|
|
5447
|
+
* `_cf_sealMemoryLimitedRecovery` template method. Queue membership remains
|
|
5448
|
+
* job-row policy; this invokes terminalization only and can be removed once
|
|
5449
|
+
* old chat releases no longer accept the current `agents` range.
|
|
5450
|
+
*
|
|
5451
|
+
* @internal
|
|
4765
5452
|
*/
|
|
4766
|
-
|
|
5453
|
+
protected onAlarmMemoryLimit(context: MemoryLimitContext): Promise<void>;
|
|
4767
5454
|
/**
|
|
4768
|
-
*
|
|
4769
|
-
* (#1825). The in-DO recovery budgets (`chatRecovery.maxOomRetries` /
|
|
4770
|
-
* `maxRecoveryWork`) only engage if their code runs AND its writes land; a
|
|
4771
|
-
* severe OOM can defeat both — thrown before the budget runs (boot hydration),
|
|
4772
|
-
* or its own small writes also OOM under memory pressure. In that case the
|
|
4773
|
-
* error reaches {@link alarm} and, unhandled, the platform auto-retries the
|
|
4774
|
-
* alarm indefinitely (re-running the doomed, billable turn each cycle).
|
|
5455
|
+
* Run Lifecycle's alarm event loop after the pending-destroy preamble.
|
|
4775
5456
|
*
|
|
4776
|
-
*
|
|
4777
|
-
*
|
|
4778
|
-
*
|
|
4779
|
-
*
|
|
4780
|
-
*
|
|
4781
|
-
*
|
|
4782
|
-
*
|
|
4783
|
-
* swallowing (not re-throwing) still halts the platform's auto-retry, and a
|
|
4784
|
-
* later wake re-arms legitimate schedules.
|
|
5457
|
+
* The alarm memory-limit circuit breaker (#1825) lives inside
|
|
5458
|
+
* `Lifecycle.alarm()`; capabilities and hosts opt into extra domain
|
|
5459
|
+
* policy via their `onMemoryLimit` / `onAlarmMemoryLimit` hooks and the
|
|
5460
|
+
* `recoveryLoop` schedule option.
|
|
5461
|
+
*
|
|
5462
|
+
* @remarks Use `this.schedule()` for named Agent callbacks. Reusable durable
|
|
5463
|
+
* work belongs in a capability that pushes jobs and implements `onJob()`.
|
|
4785
5464
|
*/
|
|
4786
|
-
|
|
5465
|
+
alarm(): Promise<void>;
|
|
4787
5466
|
/**
|
|
4788
5467
|
* Intercept incoming HTTP/WS requests whose URL contains a
|
|
4789
5468
|
* `/sub/{child-class}/{child-name}` marker and forward them to
|
|
@@ -4792,9 +5471,9 @@ declare class Agent<
|
|
|
4792
5471
|
* Response, the framework resolves the facet and hands the
|
|
4793
5472
|
* request off.
|
|
4794
5473
|
*
|
|
4795
|
-
*
|
|
4796
|
-
*
|
|
4797
|
-
*
|
|
5474
|
+
* The parent owns an upgraded WebSocket for its lifetime. Subsequent
|
|
5475
|
+
* frames wake the root parent, which forwards them to the child over
|
|
5476
|
+
* RPC and routes replies back to the native socket.
|
|
4798
5477
|
*
|
|
4799
5478
|
* @experimental The API surface may change before stabilizing.
|
|
4800
5479
|
*/
|
|
@@ -4805,25 +5484,6 @@ declare class Agent<
|
|
|
4805
5484
|
): void;
|
|
4806
5485
|
getConnection<TState = unknown>(id: string): Connection<TState> | undefined;
|
|
4807
5486
|
getConnections<TState = unknown>(tag?: string): Iterable<Connection<TState>>;
|
|
4808
|
-
private _cf_activeSubAgentBridge;
|
|
4809
|
-
/**
|
|
4810
|
-
* Route a virtual sub-agent connection operation through its live frame
|
|
4811
|
-
* bridge, or through the durable root Agent after that frame completes.
|
|
4812
|
-
* All operations share one per-connection queue. Facet broadcasts wait for
|
|
4813
|
-
* older queued operations; failures do not block later work.
|
|
4814
|
-
*/
|
|
4815
|
-
private _cf_routeSubAgentConnectionOperation;
|
|
4816
|
-
/**
|
|
4817
|
-
* Route a facet broadcast after every older connection operation.
|
|
4818
|
-
*
|
|
4819
|
-
* This barrier is intentionally one-way: facet startup can broadcast before
|
|
4820
|
-
* a child connection has finished initializing its tags and protocol flags.
|
|
4821
|
-
* Making those later connection operations wait would let the next frame
|
|
4822
|
-
* observe stale root-owned metadata.
|
|
4823
|
-
*/
|
|
4824
|
-
private _cf_routeSubAgentBroadcast;
|
|
4825
|
-
private _cf_reportSubAgentConnectionOperationFailure;
|
|
4826
|
-
private _cf_broadcastToParentSubAgent;
|
|
4827
5487
|
_cf_broadcastToSubAgent(
|
|
4828
5488
|
ownerPath: ReadonlyArray<AgentPathStep>,
|
|
4829
5489
|
message: string | ArrayBuffer | ArrayBufferView,
|
|
@@ -4831,7 +5491,7 @@ declare class Agent<
|
|
|
4831
5491
|
): Promise<void>;
|
|
4832
5492
|
_cf_subAgentConnectionMetas(
|
|
4833
5493
|
ownerPath: ReadonlyArray<AgentPathStep>
|
|
4834
|
-
): Promise<
|
|
5494
|
+
): Promise<DynamicAgentConnectionMeta[]>;
|
|
4835
5495
|
_cf_sendToSubAgentConnection(
|
|
4836
5496
|
connectionId: string,
|
|
4837
5497
|
message: string | ArrayBuffer | ArrayBufferView
|
|
@@ -4845,11 +5505,6 @@ declare class Agent<
|
|
|
4845
5505
|
connectionId: string,
|
|
4846
5506
|
state: unknown
|
|
4847
5507
|
): Promise<unknown>;
|
|
4848
|
-
private _cf_subAgentConnectionMetaForPath;
|
|
4849
|
-
private _cf_subAgentTargetPath;
|
|
4850
|
-
private _cf_subAgentPathFromOuterUri;
|
|
4851
|
-
private _isSameAgentPath;
|
|
4852
|
-
private _cf_connectionHasSubAgentTarget;
|
|
4853
5508
|
protected _cf_connectionTargetsSubAgent(connection: Connection): boolean;
|
|
4854
5509
|
/**
|
|
4855
5510
|
* Returns true when the current request is addressed to a child facet of
|
|
@@ -4861,33 +5516,26 @@ declare class Agent<
|
|
|
4861
5516
|
*/
|
|
4862
5517
|
protected _cf_requestTargetsSubAgent(request: Request): boolean;
|
|
4863
5518
|
private _cf_forwardSubAgentWebSocketConnect;
|
|
4864
|
-
private _cf_createSubAgentConnectionBridge;
|
|
4865
5519
|
private _cf_forwardSubAgentWebSocketMessage;
|
|
4866
5520
|
private _cf_forwardSubAgentWebSocketClose;
|
|
4867
|
-
private _cf_resolveSubAgentConnection;
|
|
4868
5521
|
_cf_handleSubAgentWebSocketConnect(
|
|
4869
|
-
bridge:
|
|
4870
|
-
meta:
|
|
5522
|
+
bridge: DynamicAgentConnectionBridge,
|
|
5523
|
+
meta: DynamicAgentConnectionMeta
|
|
4871
5524
|
): Promise<void>;
|
|
4872
5525
|
_cf_handleSubAgentWebSocketMessage(
|
|
4873
5526
|
message: WSMessage,
|
|
4874
|
-
bridge:
|
|
4875
|
-
meta:
|
|
4876
|
-
replyBridge?:
|
|
5527
|
+
bridge: DynamicAgentConnectionBridge,
|
|
5528
|
+
meta: DynamicAgentConnectionMeta,
|
|
5529
|
+
replyBridge?: DynamicAgentConnectionBridge
|
|
4877
5530
|
): Promise<void>;
|
|
4878
5531
|
_cf_handleSubAgentWebSocketClose(
|
|
4879
5532
|
code: number,
|
|
4880
5533
|
reason: string,
|
|
4881
5534
|
wasClean: boolean,
|
|
4882
|
-
bridge:
|
|
4883
|
-
meta:
|
|
5535
|
+
bridge: DynamicAgentConnectionBridge,
|
|
5536
|
+
meta: DynamicAgentConnectionMeta
|
|
4884
5537
|
): Promise<void>;
|
|
4885
|
-
private _cf_runWithSubAgentBridge;
|
|
4886
|
-
private _cf_createSubAgentBridgeConnection;
|
|
4887
|
-
private _cf_storeVirtualSubAgentConnection;
|
|
4888
5538
|
protected _cf_hydrateSubAgentConnectionsFromRoot(): Promise<void>;
|
|
4889
|
-
private _cf_getRawConnectionState;
|
|
4890
|
-
private _cf_getForwardedSubAgentState;
|
|
4891
5539
|
/**
|
|
4892
5540
|
* Parent-side middleware hook. Fires before a request is
|
|
4893
5541
|
* forwarded into a facet sub-agent. Mirrors `onBeforeConnect` /
|
|
@@ -4923,7 +5571,7 @@ declare class Agent<
|
|
|
4923
5571
|
* class Inbox extends Agent {
|
|
4924
5572
|
* override async onBeforeSubAgent(req, { className, name }) {
|
|
4925
5573
|
* // Strict registry gate
|
|
4926
|
-
* if (!this.
|
|
5574
|
+
* if (!this.dynamicAgents.has(className, name)) {
|
|
4927
5575
|
* return new Response("Not found", { status: 404 });
|
|
4928
5576
|
* }
|
|
4929
5577
|
* }
|
|
@@ -4973,7 +5621,6 @@ declare class Agent<
|
|
|
4973
5621
|
method: string,
|
|
4974
5622
|
args: unknown[]
|
|
4975
5623
|
): Promise<unknown>;
|
|
4976
|
-
private _cf_invokeStubMethod;
|
|
4977
5624
|
/**
|
|
4978
5625
|
* Initialize this agent as a facet in a single RPC.
|
|
4979
5626
|
*
|
|
@@ -5080,7 +5727,7 @@ declare class Agent<
|
|
|
5080
5727
|
* ```
|
|
5081
5728
|
*/
|
|
5082
5729
|
parentAgent<T extends Agent>(
|
|
5083
|
-
cls:
|
|
5730
|
+
cls: DynamicAgentClass<T>
|
|
5084
5731
|
): Promise<DurableObjectStub<T>>;
|
|
5085
5732
|
private _cf_getTopLevelNamespaceByClassName;
|
|
5086
5733
|
private _cf_asDurableObjectNamespace;
|
|
@@ -5105,11 +5752,13 @@ declare class Agent<
|
|
|
5105
5752
|
* const searcher = await this.subAgent(SearchAgent, "main-search");
|
|
5106
5753
|
* const results = await searcher.search("cloudflare agents");
|
|
5107
5754
|
* ```
|
|
5755
|
+
*
|
|
5756
|
+
* @deprecated Use {@link Agent.dynamicAgents | this.dynamicAgents.get()} instead.
|
|
5108
5757
|
*/
|
|
5109
5758
|
subAgent<T extends Agent>(
|
|
5110
|
-
cls:
|
|
5759
|
+
cls: DynamicAgentClass<T>,
|
|
5111
5760
|
name: string
|
|
5112
|
-
): Promise<
|
|
5761
|
+
): Promise<DynamicAgentStub<T>>;
|
|
5113
5762
|
/** Maximum number of non-terminal agent-tool runs this parent may own at once. */
|
|
5114
5763
|
maxConcurrentAgentTools: number;
|
|
5115
5764
|
onAgentToolStart(_run: AgentToolRunInfo): Promise<void>;
|
|
@@ -5244,7 +5893,7 @@ declare class Agent<
|
|
|
5244
5893
|
*/
|
|
5245
5894
|
_cfDetachedReconcileTick(payload?: DetachedReconcilePayload): Promise<void>;
|
|
5246
5895
|
hasAgentToolRun<T extends Agent>(
|
|
5247
|
-
cls:
|
|
5896
|
+
cls: DynamicAgentClass<T>,
|
|
5248
5897
|
runId: string
|
|
5249
5898
|
): boolean;
|
|
5250
5899
|
hasAgentToolRun(agentType: string, runId: string): boolean;
|
|
@@ -5398,6 +6047,13 @@ declare class Agent<
|
|
|
5398
6047
|
* @internal
|
|
5399
6048
|
*/
|
|
5400
6049
|
private _cf_resolveSubAgent;
|
|
6050
|
+
/**
|
|
6051
|
+
* Run `body` in a fresh invocation scope with no native request/
|
|
6052
|
+
* connection context attached, so a child-facet RPC never sees
|
|
6053
|
+
* parent-owned I/O handles.
|
|
6054
|
+
* @internal
|
|
6055
|
+
*/
|
|
6056
|
+
private _runFacetInitInvocation;
|
|
5401
6057
|
/**
|
|
5402
6058
|
* Forcefully abort a running sub-agent. The child stops executing
|
|
5403
6059
|
* immediately and will be restarted on next {@link subAgent} call.
|
|
@@ -5409,8 +6065,10 @@ declare class Agent<
|
|
|
5409
6065
|
* @param cls The Agent subclass used when creating the child
|
|
5410
6066
|
* @param name Name of the child to abort
|
|
5411
6067
|
* @param reason Error thrown to pending/future RPC callers
|
|
6068
|
+
*
|
|
6069
|
+
* @deprecated Use {@link Agent.dynamicAgents | this.dynamicAgents.abort()} instead.
|
|
5412
6070
|
*/
|
|
5413
|
-
abortSubAgent(cls:
|
|
6071
|
+
abortSubAgent(cls: DynamicAgentClass, name: string, reason?: unknown): void;
|
|
5414
6072
|
/**
|
|
5415
6073
|
* Delete a sub-agent: abort it if running, then permanently wipe its
|
|
5416
6074
|
* storage. Transitively deletes the child's own children.
|
|
@@ -5419,20 +6077,10 @@ declare class Agent<
|
|
|
5419
6077
|
*
|
|
5420
6078
|
* @param cls The Agent subclass used when creating the child
|
|
5421
6079
|
* @param name Name of the child to delete
|
|
6080
|
+
*
|
|
6081
|
+
* @deprecated Use {@link Agent.dynamicAgents | this.dynamicAgents.delete()} instead.
|
|
5422
6082
|
*/
|
|
5423
|
-
deleteSubAgent(cls:
|
|
5424
|
-
/** @internal */
|
|
5425
|
-
private _subAgentRegistryReady;
|
|
5426
|
-
private _addColumnIfNotExists;
|
|
5427
|
-
/** @internal */
|
|
5428
|
-
private _ensureSubAgentRegistry;
|
|
5429
|
-
/** @internal */
|
|
5430
|
-
private _recordSubAgent;
|
|
5431
|
-
/** @internal */
|
|
5432
|
-
private _subAgentRegistryRow;
|
|
5433
|
-
private _cf_subAgentIdentity;
|
|
5434
|
-
/** @internal */
|
|
5435
|
-
private _forgetSubAgent;
|
|
6083
|
+
deleteSubAgent(cls: DynamicAgentClass, name: string): Promise<void>;
|
|
5436
6084
|
/**
|
|
5437
6085
|
* Whether this agent has previously spawned (and not deleted) a
|
|
5438
6086
|
* sub-agent of the given class and name. Backed by an
|
|
@@ -5451,8 +6099,13 @@ declare class Agent<
|
|
|
5451
6099
|
* }
|
|
5452
6100
|
* }
|
|
5453
6101
|
* ```
|
|
6102
|
+
*
|
|
6103
|
+
* @deprecated Use {@link Agent.dynamicAgents | this.dynamicAgents.has()} instead.
|
|
5454
6104
|
*/
|
|
5455
|
-
hasSubAgent<T extends Agent>(
|
|
6105
|
+
hasSubAgent<T extends Agent>(
|
|
6106
|
+
cls: DynamicAgentClass<T>,
|
|
6107
|
+
name: string
|
|
6108
|
+
): boolean;
|
|
5456
6109
|
hasSubAgent(className: string, name: string): boolean;
|
|
5457
6110
|
/**
|
|
5458
6111
|
* List known sub-agents, optionally filtered by class. Reflects
|
|
@@ -5460,9 +6113,11 @@ declare class Agent<
|
|
|
5460
6113
|
* {@link deleteSubAgent}.
|
|
5461
6114
|
*
|
|
5462
6115
|
* @experimental The API surface may change before stabilizing.
|
|
6116
|
+
*
|
|
6117
|
+
* @deprecated Use {@link Agent.dynamicAgents | this.dynamicAgents.list()} instead.
|
|
5463
6118
|
*/
|
|
5464
6119
|
listSubAgents<T extends Agent>(
|
|
5465
|
-
cls:
|
|
6120
|
+
cls: DynamicAgentClass<T>
|
|
5466
6121
|
): Array<{
|
|
5467
6122
|
className: string;
|
|
5468
6123
|
name: string;
|
|
@@ -6168,147 +6823,143 @@ declare function getAgentByName<
|
|
|
6168
6823
|
): Promise<DurableObjectStub<T>>;
|
|
6169
6824
|
//#endregion
|
|
6170
6825
|
export {
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
|
|
6201
|
-
|
|
6202
|
-
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
|
|
6207
|
-
|
|
6208
|
-
|
|
6209
|
-
|
|
6210
|
-
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
|
|
6218
|
-
|
|
6219
|
-
|
|
6220
|
-
|
|
6221
|
-
|
|
6222
|
-
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
|
|
6230
|
-
|
|
6231
|
-
|
|
6232
|
-
|
|
6233
|
-
|
|
6234
|
-
|
|
6235
|
-
FiberInspection as _,
|
|
6236
|
-
MCPStorageApi as _n,
|
|
6237
|
-
RunWorkflowOptions as _t,
|
|
6826
|
+
DetachedAgentToolConfig as $,
|
|
6827
|
+
ElicitRequest$2 as $t,
|
|
6828
|
+
getCurrentAgent as A,
|
|
6829
|
+
withInvocationScope as An,
|
|
6830
|
+
MCPAIToolSet as At,
|
|
6831
|
+
AgentToolInterruptedReason as B,
|
|
6832
|
+
MCPServerFilter as Bt,
|
|
6833
|
+
MCPServersState as C,
|
|
6834
|
+
buildAgentPath as Cn,
|
|
6835
|
+
WorkflowQueryCriteria as Ct,
|
|
6836
|
+
StartFiberResult as D,
|
|
6837
|
+
getSubAgentByName as Dn,
|
|
6838
|
+
ElicitRequest$1 as Dt,
|
|
6839
|
+
StartFiberOptions as E,
|
|
6840
|
+
buildSubAgentPathUnchecked as En,
|
|
6841
|
+
WorkflowTrackingRow as Et,
|
|
6842
|
+
AgentToolDisplayMetadata as F,
|
|
6843
|
+
MCPClientOAuthCallbackConfig as Ft,
|
|
6844
|
+
AgentToolRunInfo as G,
|
|
6845
|
+
normalizeServerId as Gt,
|
|
6846
|
+
AgentToolMilestone as H,
|
|
6847
|
+
MCP_SERVER_ID_MAX_LENGTH as Ht,
|
|
6848
|
+
AgentToolEvent as I,
|
|
6849
|
+
MCPClientOAuthResult as It,
|
|
6850
|
+
AgentToolRunState as J,
|
|
6851
|
+
RPCClientTransport as Jt,
|
|
6852
|
+
AgentToolRunInspection as K,
|
|
6853
|
+
MCPElicitationHandler as Kt,
|
|
6854
|
+
AgentToolEventMessage as L,
|
|
6855
|
+
MCPConnectionResult as Lt,
|
|
6856
|
+
AGENT_TOOL_MILESTONE_PART as M,
|
|
6857
|
+
MCPClientElicitationHandlers as Mt,
|
|
6858
|
+
AGENT_TOOL_PROGRESS_PART as N,
|
|
6859
|
+
MCPClientManager as Nt,
|
|
6860
|
+
StateUpdateMessage as O,
|
|
6861
|
+
parseSubAgentPath as On,
|
|
6862
|
+
ElicitResult$2 as Ot,
|
|
6863
|
+
AgentToolChildAdapter as P,
|
|
6864
|
+
MCPClientManagerOptions as Pt,
|
|
6865
|
+
ChatCapableAgentClass as Q,
|
|
6866
|
+
RPC_DO_PREFIX as Qt,
|
|
6867
|
+
AgentToolEventState as R,
|
|
6868
|
+
MCPDiscoverResult as Rt,
|
|
6869
|
+
MCPServerMessage as S,
|
|
6870
|
+
SubAgentPathMatch as Sn,
|
|
6871
|
+
WorkflowProgressCallback as St,
|
|
6872
|
+
RPCResponse as T,
|
|
6873
|
+
buildSubAgentPath as Tn,
|
|
6874
|
+
WorkflowStatus as Tt,
|
|
6875
|
+
AgentToolProgress as U,
|
|
6876
|
+
RegisterServerOptions as Ut,
|
|
6877
|
+
AgentToolLifecycleResult as V,
|
|
6878
|
+
MCPServerOptions as Vt,
|
|
6879
|
+
AgentToolProgressSnapshot as W,
|
|
6880
|
+
getNamespacedData as Wt,
|
|
6881
|
+
AgentToolStoredChunk as X,
|
|
6882
|
+
RPCServerTransport as Xt,
|
|
6883
|
+
AgentToolRunStatus as Y,
|
|
6884
|
+
RPCClientTransportOptions as Yt,
|
|
6885
|
+
AgentToolTerminalStatus as Z,
|
|
6886
|
+
RPCServerTransportOptions as Zt,
|
|
6887
|
+
FiberRecoveryContext as _,
|
|
6888
|
+
DynamicAgentClass as _n,
|
|
6889
|
+
WorkflowErrorCallback as _t,
|
|
6238
6890
|
routeAgentRequest as a,
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6891
|
+
createMcpHandler$1 as an,
|
|
6892
|
+
AgentWorkflowOrigin as at,
|
|
6893
|
+
ListFibersOptions as b,
|
|
6894
|
+
BuildAgentPathOptions as bn,
|
|
6895
|
+
WorkflowInfo as bt,
|
|
6244
6896
|
Agent as c,
|
|
6245
|
-
|
|
6246
|
-
|
|
6897
|
+
CreateMcpHandlerOptions$1 as cn,
|
|
6898
|
+
AgentWorkflowStep as ct,
|
|
6247
6899
|
AgentStaticOptions as d,
|
|
6248
|
-
|
|
6249
|
-
|
|
6250
|
-
|
|
6251
|
-
|
|
6252
|
-
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
|
|
6256
|
-
|
|
6257
|
-
|
|
6258
|
-
|
|
6259
|
-
|
|
6260
|
-
|
|
6900
|
+
MCPStorageApi as dn,
|
|
6901
|
+
RunWorkflowOptions as dt,
|
|
6902
|
+
ElicitRequestSchema as en,
|
|
6903
|
+
DetachedRunAgentToolResult as et,
|
|
6904
|
+
DEFAULT_AGENT_STATIC_OPTIONS as f,
|
|
6905
|
+
TransportState as fn,
|
|
6906
|
+
WaitForApprovalOptions as ft,
|
|
6907
|
+
FiberInspection as g,
|
|
6908
|
+
StreamableHTTPEdgeClientTransport as gn,
|
|
6909
|
+
WorkflowCompleteCallback as gt,
|
|
6910
|
+
FiberContext as h,
|
|
6911
|
+
SSEEdgeClientTransport as hn,
|
|
6912
|
+
WorkflowCallbackType as ht,
|
|
6261
6913
|
getAgentByName as i,
|
|
6262
|
-
|
|
6263
|
-
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
|
|
6267
|
-
|
|
6268
|
-
|
|
6269
|
-
WorkflowQueryCriteria as kt,
|
|
6914
|
+
DurableObjectEventStore as in,
|
|
6915
|
+
AgentWorkflowInternalParams as it,
|
|
6916
|
+
routeAgentEmail as j,
|
|
6917
|
+
MCPClientElicitationHandler as jt,
|
|
6918
|
+
StreamingResponse as k,
|
|
6919
|
+
routeSubAgentRequest as kn,
|
|
6920
|
+
MCPAITool as kt,
|
|
6270
6921
|
AgentContext as l,
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6922
|
+
LegacyMcpHandler as ln,
|
|
6923
|
+
ApprovalEventPayload as lt,
|
|
6924
|
+
EmailRoutingOptions as m,
|
|
6925
|
+
WorkerTransportOptions as mn,
|
|
6926
|
+
WorkflowCallbackBase as mt,
|
|
6276
6927
|
AgentOptions as n,
|
|
6277
|
-
|
|
6278
|
-
|
|
6928
|
+
McpAgent as nn,
|
|
6929
|
+
RunAgentToolResult as nt,
|
|
6279
6930
|
AddMcpServerOptions as o,
|
|
6280
|
-
|
|
6281
|
-
|
|
6282
|
-
|
|
6283
|
-
|
|
6284
|
-
|
|
6285
|
-
|
|
6286
|
-
|
|
6931
|
+
experimental_createMcpHandler as on,
|
|
6932
|
+
AgentWorkflowParams as ot,
|
|
6933
|
+
DeleteFibersOptions as p,
|
|
6934
|
+
WorkerTransport as pn,
|
|
6935
|
+
WorkflowCallback as pt,
|
|
6936
|
+
AgentToolRunPart as q,
|
|
6937
|
+
MCPElicitationHandlers as qt,
|
|
6287
6938
|
RoutingRetryOptions as r,
|
|
6288
|
-
|
|
6289
|
-
|
|
6939
|
+
ClearableEventStore as rn,
|
|
6940
|
+
AgentWorkflowEvent as rt,
|
|
6290
6941
|
AddRpcMcpServerOptions as s,
|
|
6291
|
-
|
|
6292
|
-
|
|
6942
|
+
CreateLegacyMcpHandlerOptions as sn,
|
|
6943
|
+
AgentWorkflowPathStep as st,
|
|
6293
6944
|
AgentGetOptions as t,
|
|
6294
|
-
|
|
6295
|
-
|
|
6945
|
+
ElicitResult$3 as tn,
|
|
6946
|
+
RunAgentToolOptions as tt,
|
|
6296
6947
|
AgentNamespace as u,
|
|
6297
|
-
|
|
6298
|
-
|
|
6299
|
-
|
|
6300
|
-
|
|
6301
|
-
|
|
6302
|
-
|
|
6303
|
-
|
|
6304
|
-
|
|
6305
|
-
|
|
6306
|
-
|
|
6307
|
-
|
|
6308
|
-
|
|
6309
|
-
|
|
6310
|
-
|
|
6311
|
-
|
|
6312
|
-
|
|
6948
|
+
createLegacyMcpHandler as un,
|
|
6949
|
+
DefaultProgress as ut,
|
|
6950
|
+
FiberRecoveryResult as v,
|
|
6951
|
+
DynamicAgentStub as vn,
|
|
6952
|
+
WorkflowEventCallback as vt,
|
|
6953
|
+
RPCRequest as w,
|
|
6954
|
+
buildAgentUrl as wn,
|
|
6955
|
+
WorkflowRejectedError as wt,
|
|
6956
|
+
MCPServer as x,
|
|
6957
|
+
SUB_PREFIX as xn,
|
|
6958
|
+
WorkflowPage as xt,
|
|
6959
|
+
FiberStatus as y,
|
|
6960
|
+
AgentPathStep as yn,
|
|
6961
|
+
WorkflowEventPayload as yt,
|
|
6962
|
+
AgentToolFailure as z,
|
|
6963
|
+
MCPOAuthCallbackResult as zt
|
|
6313
6964
|
};
|
|
6314
|
-
//# sourceMappingURL=agent-routing-
|
|
6965
|
+
//# sourceMappingURL=agent-routing-B2XLNMxq.d.ts.map
|