agents 0.11.3 → 0.11.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/README.md +44 -1
- package/dist/browser/ai.js +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/browser/tanstack-ai.js +1 -1
- package/dist/chat/index.d.ts +73 -1
- package/dist/{classPrivateFieldGet2-BVdP0e3Z.js → classPrivateFieldGet2-DAZNVUKb.js} +5 -5
- package/dist/{client-PEDsNnfY.js → client-BYF13FDD.js} +6 -3
- package/dist/{client-PEDsNnfY.js.map → client-BYF13FDD.js.map} +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +9 -9
- package/dist/client.js.map +1 -1
- package/dist/experimental/memory/session/index.js +3 -3
- package/dist/experimental/memory/session/index.js.map +1 -1
- package/dist/experimental/webmcp.d.ts +212 -0
- package/dist/experimental/webmcp.js +298 -0
- package/dist/experimental/webmcp.js.map +1 -0
- package/dist/{index-D49HdAiY.d.ts → index-DabjI66m.d.ts} +365 -20
- package/dist/index.d.ts +12 -2
- package/dist/index.js +311 -43
- package/dist/index.js.map +1 -1
- package/dist/mcp/client.d.ts +1 -1
- package/dist/mcp/client.js +1 -1
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +5 -5
- package/dist/mcp/index.js.map +1 -1
- package/dist/react.d.ts +53 -5
- package/dist/react.js +55 -15
- package/dist/react.js.map +1 -1
- package/dist/{retries-JlwH9mnV.d.ts → retries-fLD8cGNf.d.ts} +1 -1
- package/dist/retries.d.ts +1 -1
- package/dist/{shared-BtPEbm_U.js → shared-BovR6hRc.js} +3 -3
- package/dist/{shared-BtPEbm_U.js.map → shared-BovR6hRc.js.map} +1 -1
- package/dist/sub-routing.d.ts +14 -0
- package/dist/sub-routing.js +171 -0
- package/dist/sub-routing.js.map +1 -0
- package/dist/utils.d.ts +21 -1
- package/dist/utils.js +36 -1
- package/dist/utils.js.map +1 -1
- package/dist/workflows.d.ts +1 -1
- package/package.json +13 -19
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as AgentEmail } from "./internal_context-BvuGZieY.js";
|
|
2
|
-
import { t as RetryOptions } from "./retries-
|
|
2
|
+
import { t as RetryOptions } from "./retries-fLD8cGNf.js";
|
|
3
3
|
import {
|
|
4
4
|
n as Observability,
|
|
5
5
|
r as ObservabilityEvent,
|
|
@@ -67,6 +67,122 @@ import { Server as Server$1 } from "@modelcontextprotocol/sdk/server/index.js";
|
|
|
67
67
|
import { Client as Client$1 } from "@modelcontextprotocol/sdk/client";
|
|
68
68
|
import { EventStore } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
69
69
|
|
|
70
|
+
//#region src/sub-routing.d.ts
|
|
71
|
+
/**
|
|
72
|
+
* URL segment marking a parent↔child boundary.
|
|
73
|
+
*
|
|
74
|
+
* Exposed as a constant so callers can build URLs symbolically, but
|
|
75
|
+
* not configurable — the routing layer matches on the literal `sub`
|
|
76
|
+
* token everywhere (parent fetch, client, helpers).
|
|
77
|
+
*/
|
|
78
|
+
declare const SUB_PREFIX = "sub";
|
|
79
|
+
interface SubAgentPathMatch {
|
|
80
|
+
/** CamelCase class name of the child, as it appears in `ctx.exports`. */
|
|
81
|
+
childClass: string;
|
|
82
|
+
/** URL-decoded child name. */
|
|
83
|
+
childName: string;
|
|
84
|
+
/**
|
|
85
|
+
* Request path to forward to the child, with the
|
|
86
|
+
* `/sub/{class}/{name}` segment stripped. Always begins with `/`;
|
|
87
|
+
* may itself contain further `/sub/...` markers when a
|
|
88
|
+
* recursively nested sub-agent is being routed.
|
|
89
|
+
*/
|
|
90
|
+
remainingPath: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Parse a URL and extract the first `/sub/{class}/{name}` segment,
|
|
94
|
+
* if any. Recursive nesting is handled naturally: callers parse one
|
|
95
|
+
* level at a time; the child then parses its own URL (which still
|
|
96
|
+
* contains any deeper `/sub/...` markers).
|
|
97
|
+
*
|
|
98
|
+
* Names are URL-decoded. Classes are kebab-to-CamelCase converted
|
|
99
|
+
* via a best-effort match against a provided lookup — pass
|
|
100
|
+
* `ctx.exports` keys to get exact CamelCase; pass `undefined` for
|
|
101
|
+
* a tolerant conversion without validation.
|
|
102
|
+
*
|
|
103
|
+
* Returns `null` when the URL doesn't contain the marker at a
|
|
104
|
+
* recognized position, or when the marker has no following
|
|
105
|
+
* class+name pair.
|
|
106
|
+
*/
|
|
107
|
+
declare function parseSubAgentPath(
|
|
108
|
+
url: string,
|
|
109
|
+
options?: {
|
|
110
|
+
/** CamelCase class names to match against (usually `ctx.exports` keys). */ knownClasses?: readonly string[];
|
|
111
|
+
}
|
|
112
|
+
): SubAgentPathMatch | null;
|
|
113
|
+
/**
|
|
114
|
+
* Route a request into a sub-agent via its parent DO.
|
|
115
|
+
*
|
|
116
|
+
* Use this in a custom fetch handler when your URL shape doesn't
|
|
117
|
+
* match the `/agents/{class}/{name}` default — you identify and
|
|
118
|
+
* fetch the parent yourself, then let this helper parse the
|
|
119
|
+
* `/sub/{child}/...` tail and forward it.
|
|
120
|
+
*
|
|
121
|
+
* Runs `onBeforeSubAgent` on the parent DO (authorization / request
|
|
122
|
+
* mutation / short-circuit response).
|
|
123
|
+
*
|
|
124
|
+
* For the default `/agents/...` URL shape, use `routeAgentRequest`
|
|
125
|
+
* instead — it handles the parent lookup and this dispatch in one
|
|
126
|
+
* call.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* export default {
|
|
131
|
+
* async fetch(req, env) {
|
|
132
|
+
* const { parentName, rest } = myCustomParse(req.url);
|
|
133
|
+
* const parent = await getAgentByName(env.Inbox, parentName);
|
|
134
|
+
* return routeSubAgentRequest(req, parent, { fromPath: rest });
|
|
135
|
+
* }
|
|
136
|
+
* };
|
|
137
|
+
* ```
|
|
138
|
+
*
|
|
139
|
+
* @experimental The API surface may change before stabilizing.
|
|
140
|
+
*/
|
|
141
|
+
declare function routeSubAgentRequest(
|
|
142
|
+
req: Request,
|
|
143
|
+
parent: unknown,
|
|
144
|
+
options?: {
|
|
145
|
+
/**
|
|
146
|
+
* Path to route on. Defaults to `req.url`'s pathname. Useful
|
|
147
|
+
* when your outer URL is custom (e.g. `/api/v1/...`) and you
|
|
148
|
+
* want to route the sub-agent tail without rewriting the
|
|
149
|
+
* Request first.
|
|
150
|
+
*/
|
|
151
|
+
fromPath?: string;
|
|
152
|
+
}
|
|
153
|
+
): Promise<Response>;
|
|
154
|
+
/**
|
|
155
|
+
* Get a typed RPC stub for a sub-agent from outside the parent DO.
|
|
156
|
+
*
|
|
157
|
+
* The returned stub proxies method calls through the parent via a
|
|
158
|
+
* stateless per-call bridge (caller → parent → facet), so each
|
|
159
|
+
* method invocation costs one extra RPC hop. Works across parent
|
|
160
|
+
* hibernation — no cached references to go stale.
|
|
161
|
+
*
|
|
162
|
+
* Limitations:
|
|
163
|
+
* - RPC methods only. `.fetch()` is not supported (will throw).
|
|
164
|
+
* Use `routeSubAgentRequest` for external HTTP/WS.
|
|
165
|
+
* - Arguments and return values must be structured-cloneable,
|
|
166
|
+
* same as any DO RPC call.
|
|
167
|
+
* - Does not run `onBeforeSubAgent` on the parent — analogous to
|
|
168
|
+
* `getAgentByName` not running `onBeforeConnect`. The caller is
|
|
169
|
+
* assumed to have performed whatever access checks are needed.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* const inbox = await getAgentByName(env.MyInbox, userId);
|
|
174
|
+
* const chat = await getSubAgentByName(inbox, MyChat, chatId);
|
|
175
|
+
* await chat.addMessage({ role: "user", content: "hi" });
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* @experimental The API surface may change before stabilizing.
|
|
179
|
+
*/
|
|
180
|
+
declare function getSubAgentByName<T extends Agent>(
|
|
181
|
+
parent: unknown,
|
|
182
|
+
cls: SubAgentClass<T>,
|
|
183
|
+
name: string
|
|
184
|
+
): Promise<SubAgentStub<T>>;
|
|
185
|
+
//#endregion
|
|
70
186
|
//#region src/core/events.d.ts
|
|
71
187
|
interface Disposable {
|
|
72
188
|
dispose(): void;
|
|
@@ -729,7 +845,7 @@ declare class MCPClientConnection {
|
|
|
729
845
|
*/
|
|
730
846
|
getTransport(
|
|
731
847
|
transportType: BaseTransportType
|
|
732
|
-
):
|
|
848
|
+
): RPCClientTransport | SSEClientTransport | StreamableHTTPClientTransport;
|
|
733
849
|
private tryConnect;
|
|
734
850
|
private _capabilityErrorHandler;
|
|
735
851
|
}
|
|
@@ -1796,6 +1912,13 @@ declare class Agent<
|
|
|
1796
1912
|
private _persistenceHookMode;
|
|
1797
1913
|
/** True when this agent runs as a facet (sub-agent) inside a parent. */
|
|
1798
1914
|
private _isFacet;
|
|
1915
|
+
/**
|
|
1916
|
+
* Ancestor chain, root-first. Empty for top-level DOs; populated at
|
|
1917
|
+
* facet init time from the parent's own `selfPath`. Exposed publicly
|
|
1918
|
+
* via the `parentPath` getter.
|
|
1919
|
+
* @internal
|
|
1920
|
+
*/
|
|
1921
|
+
private _parentPath;
|
|
1799
1922
|
/** True while user's onStart() is executing. Used to warn about non-idempotent schedule() calls. */
|
|
1800
1923
|
private _insideOnStart;
|
|
1801
1924
|
/** Tracks callbacks already warned about during this onStart() to avoid log spam. */
|
|
@@ -1903,18 +2026,6 @@ declare class Agent<
|
|
|
1903
2026
|
* @param excludeIds Additional connection IDs to exclude (e.g. the source)
|
|
1904
2027
|
*/
|
|
1905
2028
|
private _broadcastProtocol;
|
|
1906
|
-
/**
|
|
1907
|
-
* When running as a facet, the parent DO owns the WebSocket registry
|
|
1908
|
-
* (`ctx.getWebSockets()`). Iterating from the child isolate throws
|
|
1909
|
-
* "Cannot perform I/O on behalf of a different Durable Object".
|
|
1910
|
-
* Downstream callers (e.g. chat-streaming paths) invoke
|
|
1911
|
-
* `this.broadcast()` directly, bypassing `_broadcastProtocol`'s
|
|
1912
|
-
* guard, so override at the base to catch every path.
|
|
1913
|
-
*/
|
|
1914
|
-
broadcast(
|
|
1915
|
-
msg: string | ArrayBuffer | ArrayBufferView,
|
|
1916
|
-
without?: string[]
|
|
1917
|
-
): void;
|
|
1918
2029
|
private _setStateInternal;
|
|
1919
2030
|
/**
|
|
1920
2031
|
* Update the Agent's state
|
|
@@ -2293,6 +2404,12 @@ declare class Agent<
|
|
|
2293
2404
|
* alarm system, without creating schedule rows or emitting observability
|
|
2294
2405
|
* events. Configure via `static options = { keepAliveIntervalMs: 5000 }`.
|
|
2295
2406
|
*
|
|
2407
|
+
* No-op on facets. Facets share the parent's isolate and don't
|
|
2408
|
+
* need a separate alarm heartbeat — the parent's own activity,
|
|
2409
|
+
* any open WebSocket to the facet, and any in-flight Promise
|
|
2410
|
+
* already keep the shared machine alive for the duration of
|
|
2411
|
+
* real work.
|
|
2412
|
+
*
|
|
2296
2413
|
* @example
|
|
2297
2414
|
* ```ts
|
|
2298
2415
|
* const dispose = await this.keepAlive();
|
|
@@ -2385,6 +2502,90 @@ declare class Agent<
|
|
|
2385
2502
|
* See {@link https://developers.cloudflare.com/agents/api-reference/schedule-tasks/}
|
|
2386
2503
|
*/
|
|
2387
2504
|
alarm(): Promise<void>;
|
|
2505
|
+
/**
|
|
2506
|
+
* Intercept incoming HTTP/WS requests whose URL contains a
|
|
2507
|
+
* `/sub/{child-class}/{child-name}` marker and forward them to
|
|
2508
|
+
* the facet. The `onBeforeSubAgent` hook fires first (authorize,
|
|
2509
|
+
* mutate, or short-circuit). If the hook doesn't return a
|
|
2510
|
+
* Response, the framework resolves the facet and hands the
|
|
2511
|
+
* request off.
|
|
2512
|
+
*
|
|
2513
|
+
* After a WebSocket upgrade completes, subsequent frames route
|
|
2514
|
+
* directly to the child — the parent is only on the path for the
|
|
2515
|
+
* initial request.
|
|
2516
|
+
*
|
|
2517
|
+
* @experimental The API surface may change before stabilizing.
|
|
2518
|
+
*/
|
|
2519
|
+
fetch(request: Request): Promise<Response>;
|
|
2520
|
+
/**
|
|
2521
|
+
* Parent-side middleware hook. Fires before a request is
|
|
2522
|
+
* forwarded into a facet sub-agent. Mirrors `onBeforeConnect` /
|
|
2523
|
+
* `onBeforeRequest`.
|
|
2524
|
+
*
|
|
2525
|
+
* - return `void` (default) → forward the original request
|
|
2526
|
+
* - return `Request` → forward this (modified) request
|
|
2527
|
+
* - return `Response` → return this response to the
|
|
2528
|
+
* client; do not wake the child
|
|
2529
|
+
*
|
|
2530
|
+
* Default implementation: return void (permissive).
|
|
2531
|
+
*
|
|
2532
|
+
* The hook receives the **original** request with its URL intact —
|
|
2533
|
+
* including the `/sub/{class}/{name}` segment. The routing
|
|
2534
|
+
* decision for which facet to wake is fixed at parse time, so if
|
|
2535
|
+
* you return a modified `Request`, its headers, body, method, and
|
|
2536
|
+
* query string flow through to the child, but the **pathname**
|
|
2537
|
+
* the child sees is always the tail after `/sub/{class}/{name}`.
|
|
2538
|
+
* Customize via headers/body rather than URL-rewriting.
|
|
2539
|
+
*
|
|
2540
|
+
* WebSocket upgrade requests flow through this hook the same way as
|
|
2541
|
+
* plain HTTP. If you return a mutated `Request`, make sure it still
|
|
2542
|
+
* carries the original `Upgrade: websocket` and `Sec-WebSocket-*`
|
|
2543
|
+
* headers — the simplest safe recipe is to clone the incoming
|
|
2544
|
+
* request's headers (via `new Headers(req.headers)`) and only add
|
|
2545
|
+
* or replace entries, rather than constructing a fresh `Headers`
|
|
2546
|
+
* object from scratch.
|
|
2547
|
+
*
|
|
2548
|
+
* @experimental The API surface may change before stabilizing.
|
|
2549
|
+
*
|
|
2550
|
+
* @example
|
|
2551
|
+
* ```ts
|
|
2552
|
+
* class Inbox extends Agent {
|
|
2553
|
+
* override async onBeforeSubAgent(req, { className, name }) {
|
|
2554
|
+
* // Strict registry gate
|
|
2555
|
+
* if (!this.hasSubAgent(className, name)) {
|
|
2556
|
+
* return new Response("Not found", { status: 404 });
|
|
2557
|
+
* }
|
|
2558
|
+
* }
|
|
2559
|
+
* }
|
|
2560
|
+
* ```
|
|
2561
|
+
*/
|
|
2562
|
+
onBeforeSubAgent(
|
|
2563
|
+
_request: Request,
|
|
2564
|
+
_child: {
|
|
2565
|
+
className: string;
|
|
2566
|
+
name: string;
|
|
2567
|
+
}
|
|
2568
|
+
): Promise<Request | Response | void>;
|
|
2569
|
+
/**
|
|
2570
|
+
* Resolve the facet Fetcher for the match and forward the
|
|
2571
|
+
* request to it with `/sub/{class}/{name}` stripped.
|
|
2572
|
+
*
|
|
2573
|
+
* @internal
|
|
2574
|
+
*/
|
|
2575
|
+
private _cf_forwardToFacet;
|
|
2576
|
+
/**
|
|
2577
|
+
* Bridge method used by `getSubAgentByName`. Resolves the facet
|
|
2578
|
+
* on each call (idempotent via `subAgent`) and dispatches one
|
|
2579
|
+
* RPC method. Stateless — no cached references.
|
|
2580
|
+
*
|
|
2581
|
+
* @internal
|
|
2582
|
+
*/
|
|
2583
|
+
_cf_invokeSubAgent(
|
|
2584
|
+
className: string,
|
|
2585
|
+
name: string,
|
|
2586
|
+
method: string,
|
|
2587
|
+
args: unknown[]
|
|
2588
|
+
): Promise<unknown>;
|
|
2388
2589
|
/**
|
|
2389
2590
|
* Initialize this agent as a facet in a single RPC.
|
|
2390
2591
|
*
|
|
@@ -2395,14 +2596,95 @@ declare class Agent<
|
|
|
2395
2596
|
* parent and triggered "Cannot perform I/O on behalf of a different
|
|
2396
2597
|
* Durable Object" on the child.
|
|
2397
2598
|
*
|
|
2398
|
-
*
|
|
2399
|
-
*
|
|
2400
|
-
*
|
|
2401
|
-
*
|
|
2599
|
+
* We still set `_isFacet` eagerly (before `__unsafe_ensureInitialized`)
|
|
2600
|
+
* so any code that legitimately branches on it — e.g. skipping
|
|
2601
|
+
* parent-owned alarms in schedule guards — sees the flag during
|
|
2602
|
+
* the first `onStart()` run. Broadcast paths no longer special-case
|
|
2603
|
+
* facets, since facets can be directly addressed via sub-agent
|
|
2604
|
+
* routing and have their own WebSocket connections.
|
|
2402
2605
|
*
|
|
2403
2606
|
* @internal Called by {@link subAgent}.
|
|
2404
2607
|
*/
|
|
2405
|
-
_cf_initAsFacet(
|
|
2608
|
+
_cf_initAsFacet(
|
|
2609
|
+
name: string,
|
|
2610
|
+
parentPath?: ReadonlyArray<{
|
|
2611
|
+
className: string;
|
|
2612
|
+
name: string;
|
|
2613
|
+
}>
|
|
2614
|
+
): Promise<void>;
|
|
2615
|
+
/**
|
|
2616
|
+
* Ancestor chain for this agent, root-first. Empty for top-level
|
|
2617
|
+
* DOs. Populated at facet init time; survives hibernation.
|
|
2618
|
+
*
|
|
2619
|
+
* @example
|
|
2620
|
+
* ```ts
|
|
2621
|
+
* class Chat extends Agent {
|
|
2622
|
+
* onStart() {
|
|
2623
|
+
* console.log("chat started under:", this.parentPath);
|
|
2624
|
+
* // → [{ className: "Tenant", name: "acme" }, { className: "Inbox", name: "alice" }]
|
|
2625
|
+
* }
|
|
2626
|
+
* }
|
|
2627
|
+
* ```
|
|
2628
|
+
*
|
|
2629
|
+
* @experimental The API surface may change before stabilizing.
|
|
2630
|
+
*/
|
|
2631
|
+
get parentPath(): ReadonlyArray<{
|
|
2632
|
+
className: string;
|
|
2633
|
+
name: string;
|
|
2634
|
+
}>;
|
|
2635
|
+
/**
|
|
2636
|
+
* Ancestor chain + self, root-first. Convenient for logging.
|
|
2637
|
+
*
|
|
2638
|
+
* @experimental The API surface may change before stabilizing.
|
|
2639
|
+
*/
|
|
2640
|
+
get selfPath(): ReadonlyArray<{
|
|
2641
|
+
className: string;
|
|
2642
|
+
name: string;
|
|
2643
|
+
}>;
|
|
2644
|
+
/**
|
|
2645
|
+
* Resolve a typed RPC stub for this facet's **immediate** parent
|
|
2646
|
+
* agent.
|
|
2647
|
+
*
|
|
2648
|
+
* Symmetric with `subAgent(Cls, name)`: while `subAgent` opens a
|
|
2649
|
+
* stub from parent to child, `parentAgent` opens one from child
|
|
2650
|
+
* to parent. Pass the direct parent's class reference — the
|
|
2651
|
+
* framework verifies it matches the last entry of
|
|
2652
|
+
* `this.parentPath` at runtime, then looks up `env[Cls.name]` to
|
|
2653
|
+
* find the namespace binding.
|
|
2654
|
+
*
|
|
2655
|
+
* `this.parentPath` is root-first, so the direct parent is the
|
|
2656
|
+
* **last** entry: `this.parentPath.at(-1)`. For grandparents and
|
|
2657
|
+
* further ancestors, iterate `this.parentPath` and use
|
|
2658
|
+
* `getAgentByName(env.X, this.parentPath[i].name)` directly.
|
|
2659
|
+
*
|
|
2660
|
+
* Assumes the standard "binding name matches class name" convention.
|
|
2661
|
+
* If your `wrangler.jsonc` binds the parent under a different name
|
|
2662
|
+
* (e.g. `{ class_name: "Inbox", name: "MY_INBOX" }`), call
|
|
2663
|
+
* `getAgentByName(env.MY_INBOX, this.parentPath.at(-1)!.name)`
|
|
2664
|
+
* directly instead.
|
|
2665
|
+
*
|
|
2666
|
+
* @experimental The API surface may change before stabilizing.
|
|
2667
|
+
*
|
|
2668
|
+
* @throws If this agent is not a facet (no parent).
|
|
2669
|
+
* @throws If `Cls.name` doesn't match the recorded direct-parent
|
|
2670
|
+
* class (guards against accidentally reaching the wrong
|
|
2671
|
+
* DO, especially in nested Root → Mid → Leaf chains).
|
|
2672
|
+
* @throws If no env binding named `Cls.name` is found.
|
|
2673
|
+
*
|
|
2674
|
+
* @example
|
|
2675
|
+
* ```ts
|
|
2676
|
+
* class Chat extends AIChatAgent<Env> {
|
|
2677
|
+
* async onChatMessage(...) {
|
|
2678
|
+
* const inbox = await this.parentAgent(Inbox);
|
|
2679
|
+
* const memory = await inbox.getSharedMemory("facts");
|
|
2680
|
+
* // ...
|
|
2681
|
+
* }
|
|
2682
|
+
* }
|
|
2683
|
+
* ```
|
|
2684
|
+
*/
|
|
2685
|
+
parentAgent<T extends Agent>(
|
|
2686
|
+
cls: SubAgentClass<T>
|
|
2687
|
+
): Promise<DurableObjectStub<T>>;
|
|
2406
2688
|
/**
|
|
2407
2689
|
* Get or create a named sub-agent — a child Durable Object (facet)
|
|
2408
2690
|
* with its own isolated SQLite storage running on the same machine.
|
|
@@ -2427,6 +2709,16 @@ declare class Agent<
|
|
|
2427
2709
|
cls: SubAgentClass<T>,
|
|
2428
2710
|
name: string
|
|
2429
2711
|
): Promise<SubAgentStub<T>>;
|
|
2712
|
+
/**
|
|
2713
|
+
* Shared facet resolution — takes a CamelCase class name string
|
|
2714
|
+
* (matching `ctx.exports`) rather than a class reference. Both
|
|
2715
|
+
* `subAgent(cls, name)` and `_cf_invokeSubAgent(className, ...)`
|
|
2716
|
+
* funnel through here so registry bookkeeping and the
|
|
2717
|
+
* `_cf_initAsFacet` handshake are consistent.
|
|
2718
|
+
*
|
|
2719
|
+
* @internal
|
|
2720
|
+
*/
|
|
2721
|
+
private _cf_resolveSubAgent;
|
|
2430
2722
|
/**
|
|
2431
2723
|
* Forcefully abort a running sub-agent. The child stops executing
|
|
2432
2724
|
* immediately and will be restarted on next {@link subAgent} call.
|
|
@@ -2450,6 +2742,54 @@ declare class Agent<
|
|
|
2450
2742
|
* @param name Name of the child to delete
|
|
2451
2743
|
*/
|
|
2452
2744
|
deleteSubAgent(cls: SubAgentClass, name: string): void;
|
|
2745
|
+
/** @internal */
|
|
2746
|
+
private _subAgentRegistryReady;
|
|
2747
|
+
/** @internal */
|
|
2748
|
+
private _ensureSubAgentRegistry;
|
|
2749
|
+
/** @internal */
|
|
2750
|
+
private _recordSubAgent;
|
|
2751
|
+
/** @internal */
|
|
2752
|
+
private _forgetSubAgent;
|
|
2753
|
+
/**
|
|
2754
|
+
* Whether this agent has previously spawned (and not deleted) a
|
|
2755
|
+
* sub-agent of the given class and name. Backed by an
|
|
2756
|
+
* auto-maintained SQLite registry in the parent's storage.
|
|
2757
|
+
*
|
|
2758
|
+
* Intended for strict-registry access patterns in
|
|
2759
|
+
* `onBeforeSubAgent` or similar gating logic.
|
|
2760
|
+
*
|
|
2761
|
+
* @experimental The API surface may change before stabilizing.
|
|
2762
|
+
*
|
|
2763
|
+
* @example
|
|
2764
|
+
* ```ts
|
|
2765
|
+
* async onBeforeSubAgent(req, { className, name }) {
|
|
2766
|
+
* if (!this.hasSubAgent(className, name)) {
|
|
2767
|
+
* return new Response("Not found", { status: 404 });
|
|
2768
|
+
* }
|
|
2769
|
+
* }
|
|
2770
|
+
* ```
|
|
2771
|
+
*/
|
|
2772
|
+
hasSubAgent<T extends Agent>(cls: SubAgentClass<T>, name: string): boolean;
|
|
2773
|
+
hasSubAgent(className: string, name: string): boolean;
|
|
2774
|
+
/**
|
|
2775
|
+
* List known sub-agents, optionally filtered by class. Reflects
|
|
2776
|
+
* the registry rows written by {@link subAgent} and removed by
|
|
2777
|
+
* {@link deleteSubAgent}.
|
|
2778
|
+
*
|
|
2779
|
+
* @experimental The API surface may change before stabilizing.
|
|
2780
|
+
*/
|
|
2781
|
+
listSubAgents<T extends Agent>(
|
|
2782
|
+
cls: SubAgentClass<T>
|
|
2783
|
+
): Array<{
|
|
2784
|
+
className: string;
|
|
2785
|
+
name: string;
|
|
2786
|
+
createdAt: number;
|
|
2787
|
+
}>;
|
|
2788
|
+
listSubAgents(className?: string): Array<{
|
|
2789
|
+
className: string;
|
|
2790
|
+
name: string;
|
|
2791
|
+
createdAt: number;
|
|
2792
|
+
}>;
|
|
2453
2793
|
/**
|
|
2454
2794
|
* Destroy the Agent, removing all state and scheduled tasks
|
|
2455
2795
|
*/
|
|
@@ -3068,6 +3408,7 @@ export {
|
|
|
3068
3408
|
RPCServerTransport as Y,
|
|
3069
3409
|
RPC_DO_PREFIX as Z,
|
|
3070
3410
|
MCPServerMessage as _,
|
|
3411
|
+
parseSubAgentPath as _t,
|
|
3071
3412
|
AgentNamespace as a,
|
|
3072
3413
|
McpAuthContext as at,
|
|
3073
3414
|
RPCRequest as b,
|
|
@@ -3079,7 +3420,9 @@ export {
|
|
|
3079
3420
|
EmailRoutingOptions as f,
|
|
3080
3421
|
McpClientOptions as ft,
|
|
3081
3422
|
MCPServer as g,
|
|
3423
|
+
getSubAgentByName as gt,
|
|
3082
3424
|
FiberRecoveryContext as h,
|
|
3425
|
+
SubAgentPathMatch as ht,
|
|
3083
3426
|
AgentContext as i,
|
|
3084
3427
|
experimental_createMcpHandler as it,
|
|
3085
3428
|
getAgentByName as j,
|
|
@@ -3087,6 +3430,7 @@ export {
|
|
|
3087
3430
|
Connection$1 as l,
|
|
3088
3431
|
WorkerTransportOptions as lt,
|
|
3089
3432
|
FiberContext as m,
|
|
3433
|
+
SUB_PREFIX as mt,
|
|
3090
3434
|
AddRpcMcpServerOptions as n,
|
|
3091
3435
|
CreateMcpHandlerOptions as nt,
|
|
3092
3436
|
AgentOptions as o,
|
|
@@ -3103,9 +3447,10 @@ export {
|
|
|
3103
3447
|
ConnectionContext$1 as u,
|
|
3104
3448
|
SSEEdgeClientTransport as ut,
|
|
3105
3449
|
MCPServersState as v,
|
|
3450
|
+
routeSubAgentRequest as vt,
|
|
3106
3451
|
SqlError as w,
|
|
3107
3452
|
RPCResponse as x,
|
|
3108
3453
|
QueueItem as y,
|
|
3109
3454
|
MCPClientOAuthResult as z
|
|
3110
3455
|
};
|
|
3111
|
-
//# sourceMappingURL=index-
|
|
3456
|
+
//# sourceMappingURL=index-DabjI66m.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { r as __DO_NOT_USE_WILL_BREAK__agentContext } from "./internal_context-BvuGZieY.js";
|
|
2
|
-
import { t as RetryOptions } from "./retries-JlwH9mnV.js";
|
|
3
2
|
import {
|
|
4
3
|
A as callable,
|
|
5
4
|
C as SendEmailOptions,
|
|
@@ -13,18 +12,22 @@ import {
|
|
|
13
12
|
S as Schedule,
|
|
14
13
|
T as StateUpdateMessage,
|
|
15
14
|
_ as MCPServerMessage,
|
|
15
|
+
_t as parseSubAgentPath,
|
|
16
16
|
a as AgentNamespace,
|
|
17
17
|
b as RPCRequest,
|
|
18
18
|
c as CallableMetadata,
|
|
19
19
|
d as DEFAULT_AGENT_STATIC_OPTIONS,
|
|
20
20
|
f as EmailRoutingOptions,
|
|
21
21
|
g as MCPServer,
|
|
22
|
+
gt as getSubAgentByName,
|
|
22
23
|
h as FiberRecoveryContext,
|
|
24
|
+
ht as SubAgentPathMatch,
|
|
23
25
|
i as AgentContext,
|
|
24
26
|
j as getAgentByName,
|
|
25
27
|
k as WSMessage,
|
|
26
28
|
l as Connection,
|
|
27
29
|
m as FiberContext,
|
|
30
|
+
mt as SUB_PREFIX,
|
|
28
31
|
n as AddRpcMcpServerOptions,
|
|
29
32
|
o as AgentOptions,
|
|
30
33
|
p as EmailSendBinding,
|
|
@@ -34,10 +37,12 @@ import {
|
|
|
34
37
|
t as AddMcpServerOptions,
|
|
35
38
|
u as ConnectionContext,
|
|
36
39
|
v as MCPServersState,
|
|
40
|
+
vt as routeSubAgentRequest,
|
|
37
41
|
w as SqlError,
|
|
38
42
|
x as RPCResponse,
|
|
39
43
|
y as QueueItem
|
|
40
|
-
} from "./index-
|
|
44
|
+
} from "./index-DabjI66m.js";
|
|
45
|
+
import { t as RetryOptions } from "./retries-fLD8cGNf.js";
|
|
41
46
|
import {
|
|
42
47
|
n as AgentsOAuthProvider,
|
|
43
48
|
r as DurableObjectOAuthClientProvider,
|
|
@@ -72,12 +77,14 @@ export {
|
|
|
72
77
|
RPCRequest,
|
|
73
78
|
RPCResponse,
|
|
74
79
|
RetryOptions,
|
|
80
|
+
SUB_PREFIX,
|
|
75
81
|
Schedule,
|
|
76
82
|
SendEmailOptions,
|
|
77
83
|
SqlError,
|
|
78
84
|
StateUpdateMessage,
|
|
79
85
|
StreamingResponse,
|
|
80
86
|
SubAgentClass,
|
|
87
|
+
SubAgentPathMatch,
|
|
81
88
|
SubAgentStub,
|
|
82
89
|
TransportType,
|
|
83
90
|
WSMessage,
|
|
@@ -86,7 +93,10 @@ export {
|
|
|
86
93
|
createHeaderBasedEmailResolver,
|
|
87
94
|
getAgentByName,
|
|
88
95
|
getCurrentAgent,
|
|
96
|
+
getSubAgentByName,
|
|
97
|
+
parseSubAgentPath,
|
|
89
98
|
routeAgentEmail,
|
|
90
99
|
routeAgentRequest,
|
|
100
|
+
routeSubAgentRequest,
|
|
91
101
|
unstable_callable
|
|
92
102
|
};
|