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
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { camelCaseToKebabCase, isInternalJsStubProp } from "./utils.js";
|
|
2
|
+
//#region src/sub-routing.ts
|
|
3
|
+
/**
|
|
4
|
+
* Sub-agent routing primitives — external addressability for facets.
|
|
5
|
+
*
|
|
6
|
+
* The public surface:
|
|
7
|
+
* - `routeSubAgentRequest(req, parent, options?)` — the sub-agent
|
|
8
|
+
* analog of `routeAgentRequest`. Use in custom fetch handlers.
|
|
9
|
+
* - `getSubAgentByName(parent, Cls, name)` — the sub-agent analog
|
|
10
|
+
* of `getAgentByName`. Returns a typed RPC stub that proxies
|
|
11
|
+
* method calls through the parent. No `.fetch()` support —
|
|
12
|
+
* external HTTP/WS routing goes through `routeSubAgentRequest`.
|
|
13
|
+
*
|
|
14
|
+
* Internal:
|
|
15
|
+
* - `parseSubAgentPath(url)` — URL → `{ childClass, childName, remainingPath }`.
|
|
16
|
+
* - `forwardToFacet(req, parent, match)` — resolves `ctx.facets.get(...)`
|
|
17
|
+
* on the parent and returns `facetStub.fetch(rewrittenReq)`.
|
|
18
|
+
*
|
|
19
|
+
* @experimental The API surface may change before stabilizing.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* URL segment marking a parent↔child boundary.
|
|
23
|
+
*
|
|
24
|
+
* Exposed as a constant so callers can build URLs symbolically, but
|
|
25
|
+
* not configurable — the routing layer matches on the literal `sub`
|
|
26
|
+
* token everywhere (parent fetch, client, helpers).
|
|
27
|
+
*/
|
|
28
|
+
const SUB_PREFIX = "sub";
|
|
29
|
+
/**
|
|
30
|
+
* Parse a URL and extract the first `/sub/{class}/{name}` segment,
|
|
31
|
+
* if any. Recursive nesting is handled naturally: callers parse one
|
|
32
|
+
* level at a time; the child then parses its own URL (which still
|
|
33
|
+
* contains any deeper `/sub/...` markers).
|
|
34
|
+
*
|
|
35
|
+
* Names are URL-decoded. Classes are kebab-to-CamelCase converted
|
|
36
|
+
* via a best-effort match against a provided lookup — pass
|
|
37
|
+
* `ctx.exports` keys to get exact CamelCase; pass `undefined` for
|
|
38
|
+
* a tolerant conversion without validation.
|
|
39
|
+
*
|
|
40
|
+
* Returns `null` when the URL doesn't contain the marker at a
|
|
41
|
+
* recognized position, or when the marker has no following
|
|
42
|
+
* class+name pair.
|
|
43
|
+
*/
|
|
44
|
+
function parseSubAgentPath(url, options) {
|
|
45
|
+
const parts = new URL(url).pathname.split("/").filter(Boolean);
|
|
46
|
+
for (let i = 0; i < parts.length; i++) {
|
|
47
|
+
if (parts[i] !== "sub") continue;
|
|
48
|
+
if (i + 2 >= parts.length) continue;
|
|
49
|
+
const classSegment = parts[i + 1];
|
|
50
|
+
const nameSegment = parts[i + 2];
|
|
51
|
+
const childClass = resolveClassName(classSegment, options?.knownClasses);
|
|
52
|
+
if (!childClass) continue;
|
|
53
|
+
let childName;
|
|
54
|
+
try {
|
|
55
|
+
childName = decodeURIComponent(nameSegment);
|
|
56
|
+
} catch {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const remainingParts = parts.slice(i + 3);
|
|
60
|
+
const remainingPath = remainingParts.length > 0 ? "/" + remainingParts.join("/") : "/";
|
|
61
|
+
return {
|
|
62
|
+
childClass,
|
|
63
|
+
childName,
|
|
64
|
+
remainingPath
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Best-effort kebab-to-CamelCase match. If `knownClasses` is
|
|
71
|
+
* provided, returns the matching CamelCase entry (or null if no
|
|
72
|
+
* match). If not, performs a naive kebab→CamelCase conversion.
|
|
73
|
+
*/
|
|
74
|
+
function resolveClassName(segment, knownClasses) {
|
|
75
|
+
if (knownClasses) return knownClasses.find((name) => camelCaseToKebabCase(name) === segment) ?? null;
|
|
76
|
+
return segment.split("-").map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join("");
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Route a request into a sub-agent via its parent DO.
|
|
80
|
+
*
|
|
81
|
+
* Use this in a custom fetch handler when your URL shape doesn't
|
|
82
|
+
* match the `/agents/{class}/{name}` default — you identify and
|
|
83
|
+
* fetch the parent yourself, then let this helper parse the
|
|
84
|
+
* `/sub/{child}/...` tail and forward it.
|
|
85
|
+
*
|
|
86
|
+
* Runs `onBeforeSubAgent` on the parent DO (authorization / request
|
|
87
|
+
* mutation / short-circuit response).
|
|
88
|
+
*
|
|
89
|
+
* For the default `/agents/...` URL shape, use `routeAgentRequest`
|
|
90
|
+
* instead — it handles the parent lookup and this dispatch in one
|
|
91
|
+
* call.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* export default {
|
|
96
|
+
* async fetch(req, env) {
|
|
97
|
+
* const { parentName, rest } = myCustomParse(req.url);
|
|
98
|
+
* const parent = await getAgentByName(env.Inbox, parentName);
|
|
99
|
+
* return routeSubAgentRequest(req, parent, { fromPath: rest });
|
|
100
|
+
* }
|
|
101
|
+
* };
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @experimental The API surface may change before stabilizing.
|
|
105
|
+
*/
|
|
106
|
+
async function routeSubAgentRequest(req, parent, options) {
|
|
107
|
+
if (!parseSubAgentPath(options?.fromPath ? `http://placeholder${options.fromPath.startsWith("/") ? "" : "/"}${options.fromPath}` : req.url)) return new Response("Sub-agent path not found in request URL", { status: 400 });
|
|
108
|
+
const forwardReq = options?.fromPath !== void 0 ? new Request(rewritePathname(req.url, options.fromPath), req) : req;
|
|
109
|
+
return parent.fetch(forwardReq);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Replace a URL's pathname (and optionally its search) while
|
|
113
|
+
* preserving every other component. Matches how `_cf_forwardToFacet`
|
|
114
|
+
* forwards requests — pathname is the only thing that changes by
|
|
115
|
+
* default; if the replacement path carries its own query string,
|
|
116
|
+
* that wins.
|
|
117
|
+
*/
|
|
118
|
+
function rewritePathname(url, fromPath) {
|
|
119
|
+
const normalized = fromPath.startsWith("/") ? fromPath : `/${fromPath}`;
|
|
120
|
+
const queryIdx = normalized.indexOf("?");
|
|
121
|
+
const pathOnly = queryIdx >= 0 ? normalized.slice(0, queryIdx) : normalized;
|
|
122
|
+
const querySuffix = queryIdx >= 0 ? normalized.slice(queryIdx) : "";
|
|
123
|
+
const rewritten = new URL(url);
|
|
124
|
+
rewritten.pathname = pathOnly;
|
|
125
|
+
if (querySuffix) rewritten.search = querySuffix;
|
|
126
|
+
return rewritten.toString();
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get a typed RPC stub for a sub-agent from outside the parent DO.
|
|
130
|
+
*
|
|
131
|
+
* The returned stub proxies method calls through the parent via a
|
|
132
|
+
* stateless per-call bridge (caller → parent → facet), so each
|
|
133
|
+
* method invocation costs one extra RPC hop. Works across parent
|
|
134
|
+
* hibernation — no cached references to go stale.
|
|
135
|
+
*
|
|
136
|
+
* Limitations:
|
|
137
|
+
* - RPC methods only. `.fetch()` is not supported (will throw).
|
|
138
|
+
* Use `routeSubAgentRequest` for external HTTP/WS.
|
|
139
|
+
* - Arguments and return values must be structured-cloneable,
|
|
140
|
+
* same as any DO RPC call.
|
|
141
|
+
* - Does not run `onBeforeSubAgent` on the parent — analogous to
|
|
142
|
+
* `getAgentByName` not running `onBeforeConnect`. The caller is
|
|
143
|
+
* assumed to have performed whatever access checks are needed.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* const inbox = await getAgentByName(env.MyInbox, userId);
|
|
148
|
+
* const chat = await getSubAgentByName(inbox, MyChat, chatId);
|
|
149
|
+
* await chat.addMessage({ role: "user", content: "hi" });
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
152
|
+
* @experimental The API surface may change before stabilizing.
|
|
153
|
+
*/
|
|
154
|
+
async function getSubAgentByName(parent, cls, name) {
|
|
155
|
+
if (name.includes("\0")) throw new Error(`Sub-agent name contains null character (\\0), which is reserved.`);
|
|
156
|
+
const bridge = parent;
|
|
157
|
+
const className = cls?.name;
|
|
158
|
+
if (!className) throw new Error(`getSubAgentByName: could not determine class name from ${cls}. Ensure you are passing the class constructor (e.g. getSubAgentByName(parent, MyChat, name)), not a string or undefined.`);
|
|
159
|
+
return new Proxy({}, { get(_target, prop) {
|
|
160
|
+
if (isInternalJsStubProp(prop)) return void 0;
|
|
161
|
+
if (typeof prop !== "string") return void 0;
|
|
162
|
+
if (prop === "fetch") return () => {
|
|
163
|
+
throw new Error("getSubAgentByName returns an RPC-only stub — .fetch() is not supported. Use routeSubAgentRequest() or the /agents/{parent}/{name}/sub/{child}/{name} URL for external HTTP/WS routing.");
|
|
164
|
+
};
|
|
165
|
+
return async (...args) => bridge._cf_invokeSubAgent(className, name, prop, args);
|
|
166
|
+
} });
|
|
167
|
+
}
|
|
168
|
+
//#endregion
|
|
169
|
+
export { SUB_PREFIX, getSubAgentByName, parseSubAgentPath, routeSubAgentRequest };
|
|
170
|
+
|
|
171
|
+
//# sourceMappingURL=sub-routing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sub-routing.js","names":[],"sources":["../src/sub-routing.ts"],"sourcesContent":["/**\n * Sub-agent routing primitives — external addressability for facets.\n *\n * The public surface:\n * - `routeSubAgentRequest(req, parent, options?)` — the sub-agent\n * analog of `routeAgentRequest`. Use in custom fetch handlers.\n * - `getSubAgentByName(parent, Cls, name)` — the sub-agent analog\n * of `getAgentByName`. Returns a typed RPC stub that proxies\n * method calls through the parent. No `.fetch()` support —\n * external HTTP/WS routing goes through `routeSubAgentRequest`.\n *\n * Internal:\n * - `parseSubAgentPath(url)` — URL → `{ childClass, childName, remainingPath }`.\n * - `forwardToFacet(req, parent, match)` — resolves `ctx.facets.get(...)`\n * on the parent and returns `facetStub.fetch(rewrittenReq)`.\n *\n * @experimental The API surface may change before stabilizing.\n */\n\nimport { camelCaseToKebabCase, isInternalJsStubProp } from \"./utils\";\nimport type { Agent, SubAgentClass, SubAgentStub } from \"./index\";\n\n/**\n * URL segment marking a parent↔child boundary.\n *\n * Exposed as a constant so callers can build URLs symbolically, but\n * not configurable — the routing layer matches on the literal `sub`\n * token everywhere (parent fetch, client, helpers).\n */\nexport const SUB_PREFIX = \"sub\";\n\nexport interface SubAgentPathMatch {\n /** CamelCase class name of the child, as it appears in `ctx.exports`. */\n childClass: string;\n /** URL-decoded child name. */\n childName: string;\n /**\n * Request path to forward to the child, with the\n * `/sub/{class}/{name}` segment stripped. Always begins with `/`;\n * may itself contain further `/sub/...` markers when a\n * recursively nested sub-agent is being routed.\n */\n remainingPath: string;\n}\n\n/**\n * Parse a URL and extract the first `/sub/{class}/{name}` segment,\n * if any. Recursive nesting is handled naturally: callers parse one\n * level at a time; the child then parses its own URL (which still\n * contains any deeper `/sub/...` markers).\n *\n * Names are URL-decoded. Classes are kebab-to-CamelCase converted\n * via a best-effort match against a provided lookup — pass\n * `ctx.exports` keys to get exact CamelCase; pass `undefined` for\n * a tolerant conversion without validation.\n *\n * Returns `null` when the URL doesn't contain the marker at a\n * recognized position, or when the marker has no following\n * class+name pair.\n */\nexport function parseSubAgentPath(\n url: string,\n options?: {\n /** CamelCase class names to match against (usually `ctx.exports` keys). */\n knownClasses?: readonly string[];\n }\n): SubAgentPathMatch | null {\n const pathname = new URL(url).pathname;\n const parts = pathname.split(\"/\").filter(Boolean);\n\n // Walk every occurrence of the `sub` segment — a plain\n // `indexOf(SUB_PREFIX)` would mis-match when the literal token\n // appears earlier in the URL (parent instance name == \"sub\", a\n // `basePath` segment that happens to be \"sub\", etc). We return\n // the first position where `parts[i+1]` resolves to a valid\n // class, which pins the real parent↔child boundary.\n for (let i = 0; i < parts.length; i++) {\n if (parts[i] !== SUB_PREFIX) continue;\n if (i + 2 >= parts.length) continue;\n\n const classSegment = parts[i + 1];\n const nameSegment = parts[i + 2];\n\n const childClass = resolveClassName(classSegment, options?.knownClasses);\n if (!childClass) continue;\n\n let childName: string;\n try {\n childName = decodeURIComponent(nameSegment);\n } catch {\n continue;\n }\n\n const remainingParts = parts.slice(i + 3);\n const remainingPath =\n remainingParts.length > 0 ? \"/\" + remainingParts.join(\"/\") : \"/\";\n\n return { childClass, childName, remainingPath };\n }\n\n return null;\n}\n\n/**\n * Best-effort kebab-to-CamelCase match. If `knownClasses` is\n * provided, returns the matching CamelCase entry (or null if no\n * match). If not, performs a naive kebab→CamelCase conversion.\n */\nfunction resolveClassName(\n segment: string,\n knownClasses?: readonly string[]\n): string | null {\n if (knownClasses) {\n const match = knownClasses.find(\n (name) => camelCaseToKebabCase(name) === segment\n );\n return match ?? null;\n }\n return segment\n .split(\"-\")\n .map((s) => s.charAt(0).toUpperCase() + s.slice(1))\n .join(\"\");\n}\n\n// ── routeSubAgentRequest ───────────────────────────────────────────\n\n/**\n * Minimal parent-side shape that `routeSubAgentRequest` relies on:\n * something fetchable (a DO stub, a sub-agent stub, etc.).\n *\n * @internal\n */\ninterface FetchableParent {\n fetch(req: Request): Promise<Response>;\n}\n\n/**\n * Route a request into a sub-agent via its parent DO.\n *\n * Use this in a custom fetch handler when your URL shape doesn't\n * match the `/agents/{class}/{name}` default — you identify and\n * fetch the parent yourself, then let this helper parse the\n * `/sub/{child}/...` tail and forward it.\n *\n * Runs `onBeforeSubAgent` on the parent DO (authorization / request\n * mutation / short-circuit response).\n *\n * For the default `/agents/...` URL shape, use `routeAgentRequest`\n * instead — it handles the parent lookup and this dispatch in one\n * call.\n *\n * @example\n * ```ts\n * export default {\n * async fetch(req, env) {\n * const { parentName, rest } = myCustomParse(req.url);\n * const parent = await getAgentByName(env.Inbox, parentName);\n * return routeSubAgentRequest(req, parent, { fromPath: rest });\n * }\n * };\n * ```\n *\n * @experimental The API surface may change before stabilizing.\n */\nexport async function routeSubAgentRequest(\n req: Request,\n parent: unknown,\n options?: {\n /**\n * Path to route on. Defaults to `req.url`'s pathname. Useful\n * when your outer URL is custom (e.g. `/api/v1/...`) and you\n * want to route the sub-agent tail without rewriting the\n * Request first.\n */\n fromPath?: string;\n }\n): Promise<Response> {\n // We don't know the parent's ctx.exports from here, so parse with\n // a permissive resolver. If the class doesn't exist, the parent's\n // bridge will 404. This lets us keep the helper self-contained.\n const pathForParsing = options?.fromPath\n ? `http://placeholder${options.fromPath.startsWith(\"/\") ? \"\" : \"/\"}${options.fromPath}`\n : req.url;\n\n const match = parseSubAgentPath(pathForParsing);\n if (!match) {\n return new Response(\"Sub-agent path not found in request URL\", {\n status: 400\n });\n }\n\n // Hand the request to the parent so `onBeforeSubAgent` fires in\n // the parent's isolate. The parent's `fetch` handler recognizes\n // the marker internally — we preserve the original request URL\n // (possibly rewritten by `fromPath`) so the parent's parse sees\n // the same match.\n //\n // Key subtlety: when rewriting the pathname via `fromPath`, we\n // mutate the *original* URL's pathname instead of constructing a\n // new URL from scratch. `new URL(\"/path\", baseWithQuery)` discards\n // the base's search; we want the caller's query params (e.g. auth\n // tokens, PartySocket's `_pk=...` handshake key) to survive.\n // Mirrors how `_cf_forwardToFacet` rewrites only pathname when\n // handing off to the child facet. If `fromPath` itself contains a\n // `?query` segment, that overrides the original.\n const forwardReq =\n options?.fromPath !== undefined\n ? new Request(rewritePathname(req.url, options.fromPath), req)\n : req;\n\n return (parent as FetchableParent).fetch(forwardReq);\n}\n\n/**\n * Replace a URL's pathname (and optionally its search) while\n * preserving every other component. Matches how `_cf_forwardToFacet`\n * forwards requests — pathname is the only thing that changes by\n * default; if the replacement path carries its own query string,\n * that wins.\n */\nfunction rewritePathname(url: string, fromPath: string): string {\n const normalized = fromPath.startsWith(\"/\") ? fromPath : `/${fromPath}`;\n const queryIdx = normalized.indexOf(\"?\");\n const pathOnly = queryIdx >= 0 ? normalized.slice(0, queryIdx) : normalized;\n const querySuffix = queryIdx >= 0 ? normalized.slice(queryIdx) : \"\";\n\n const rewritten = new URL(url);\n rewritten.pathname = pathOnly;\n if (querySuffix) {\n rewritten.search = querySuffix; // URL setter keeps the `?` prefix\n }\n return rewritten.toString();\n}\n\n// ── getSubAgentByName ──────────────────────────────────────────────\n\n/**\n * Parent-side RPC bridge shape that `getSubAgentByName` relies on.\n *\n * @internal\n */\ninterface SubAgentInvokeEndpoint {\n _cf_invokeSubAgent(\n className: string,\n name: string,\n method: string,\n args: unknown[]\n ): Promise<unknown>;\n}\n\n/**\n * Get a typed RPC stub for a sub-agent from outside the parent DO.\n *\n * The returned stub proxies method calls through the parent via a\n * stateless per-call bridge (caller → parent → facet), so each\n * method invocation costs one extra RPC hop. Works across parent\n * hibernation — no cached references to go stale.\n *\n * Limitations:\n * - RPC methods only. `.fetch()` is not supported (will throw).\n * Use `routeSubAgentRequest` for external HTTP/WS.\n * - Arguments and return values must be structured-cloneable,\n * same as any DO RPC call.\n * - Does not run `onBeforeSubAgent` on the parent — analogous to\n * `getAgentByName` not running `onBeforeConnect`. The caller is\n * assumed to have performed whatever access checks are needed.\n *\n * @example\n * ```ts\n * const inbox = await getAgentByName(env.MyInbox, userId);\n * const chat = await getSubAgentByName(inbox, MyChat, chatId);\n * await chat.addMessage({ role: \"user\", content: \"hi\" });\n * ```\n *\n * @experimental The API surface may change before stabilizing.\n */\nexport async function getSubAgentByName<T extends Agent>(\n parent: unknown,\n cls: SubAgentClass<T>,\n name: string\n): Promise<SubAgentStub<T>> {\n if (name.includes(\"\\0\")) {\n throw new Error(\n `Sub-agent name contains null character (\\\\0), which is reserved.`\n );\n }\n\n const bridge = parent as SubAgentInvokeEndpoint;\n const className = cls?.name;\n if (!className) {\n throw new Error(\n `getSubAgentByName: could not determine class name from ${cls}. ` +\n `Ensure you are passing the class constructor (e.g. getSubAgentByName(parent, MyChat, name)), not a string or undefined.`\n );\n }\n\n return new Proxy(\n {},\n {\n get(_target, prop) {\n // JS / runtime / test-framework probes (thenable check,\n // serialization, inspection, matcher duck-typing) must NOT\n // dispatch an RPC — returning `undefined` is the contract\n // the inner `createStubProxy` uses for `useAgent` stubs.\n // Without this guard, `JSON.stringify(stub)`, `console.log`,\n // Vitest matchers, and `await stub` would all trigger bogus\n // `_cf_invokeSubAgent` calls that fail with \"Method not found\".\n if (isInternalJsStubProp(prop)) return undefined;\n if (typeof prop !== \"string\") return undefined;\n // `.fetch` gets a dedicated error so users who try to use\n // the stub for HTTP/WS get a helpful pointer.\n if (prop === \"fetch\") {\n return () => {\n throw new Error(\n `getSubAgentByName returns an RPC-only stub — .fetch() is ` +\n `not supported. Use routeSubAgentRequest() or the ` +\n `/agents/{parent}/{name}/sub/{child}/{name} URL for ` +\n `external HTTP/WS routing.`\n );\n };\n }\n return async (...args: unknown[]) =>\n bridge._cf_invokeSubAgent(className, name, prop, args);\n }\n }\n ) as SubAgentStub<T>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAa,aAAa;;;;;;;;;;;;;;;;AA+B1B,SAAgB,kBACd,KACA,SAI0B;CAE1B,MAAM,QADW,IAAI,IAAI,IAAI,CAAC,SACP,MAAM,IAAI,CAAC,OAAO,QAAQ;AAQjD,MAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,MAAI,MAAM,OAAA,MAAmB;AAC7B,MAAI,IAAI,KAAK,MAAM,OAAQ;EAE3B,MAAM,eAAe,MAAM,IAAI;EAC/B,MAAM,cAAc,MAAM,IAAI;EAE9B,MAAM,aAAa,iBAAiB,cAAc,SAAS,aAAa;AACxE,MAAI,CAAC,WAAY;EAEjB,IAAI;AACJ,MAAI;AACF,eAAY,mBAAmB,YAAY;UACrC;AACN;;EAGF,MAAM,iBAAiB,MAAM,MAAM,IAAI,EAAE;EACzC,MAAM,gBACJ,eAAe,SAAS,IAAI,MAAM,eAAe,KAAK,IAAI,GAAG;AAE/D,SAAO;GAAE;GAAY;GAAW;GAAe;;AAGjD,QAAO;;;;;;;AAQT,SAAS,iBACP,SACA,cACe;AACf,KAAI,aAIF,QAHc,aAAa,MACxB,SAAS,qBAAqB,KAAK,KAAK,QAC1C,IACe;AAElB,QAAO,QACJ,MAAM,IAAI,CACV,KAAK,MAAM,EAAE,OAAO,EAAE,CAAC,aAAa,GAAG,EAAE,MAAM,EAAE,CAAC,CAClD,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2Cb,eAAsB,qBACpB,KACA,QACA,SASmB;AASnB,KAAI,CADU,kBAJS,SAAS,WAC5B,qBAAqB,QAAQ,SAAS,WAAW,IAAI,GAAG,KAAK,MAAM,QAAQ,aAC3E,IAAI,IAEuC,CAE7C,QAAO,IAAI,SAAS,2CAA2C,EAC7D,QAAQ,KACT,CAAC;CAiBJ,MAAM,aACJ,SAAS,aAAa,KAAA,IAClB,IAAI,QAAQ,gBAAgB,IAAI,KAAK,QAAQ,SAAS,EAAE,IAAI,GAC5D;AAEN,QAAQ,OAA2B,MAAM,WAAW;;;;;;;;;AAUtD,SAAS,gBAAgB,KAAa,UAA0B;CAC9D,MAAM,aAAa,SAAS,WAAW,IAAI,GAAG,WAAW,IAAI;CAC7D,MAAM,WAAW,WAAW,QAAQ,IAAI;CACxC,MAAM,WAAW,YAAY,IAAI,WAAW,MAAM,GAAG,SAAS,GAAG;CACjE,MAAM,cAAc,YAAY,IAAI,WAAW,MAAM,SAAS,GAAG;CAEjE,MAAM,YAAY,IAAI,IAAI,IAAI;AAC9B,WAAU,WAAW;AACrB,KAAI,YACF,WAAU,SAAS;AAErB,QAAO,UAAU,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6C7B,eAAsB,kBACpB,QACA,KACA,MAC0B;AAC1B,KAAI,KAAK,SAAS,KAAK,CACrB,OAAM,IAAI,MACR,mEACD;CAGH,MAAM,SAAS;CACf,MAAM,YAAY,KAAK;AACvB,KAAI,CAAC,UACH,OAAM,IAAI,MACR,0DAA0D,IAAI,2HAE/D;AAGH,QAAO,IAAI,MACT,EAAE,EACF,EACE,IAAI,SAAS,MAAM;AAQjB,MAAI,qBAAqB,KAAK,CAAE,QAAO,KAAA;AACvC,MAAI,OAAO,SAAS,SAAU,QAAO,KAAA;AAGrC,MAAI,SAAS,QACX,cAAa;AACX,SAAM,IAAI,MACR,yLAID;;AAGL,SAAO,OAAO,GAAG,SACf,OAAO,mBAAmB,WAAW,MAAM,MAAM,KAAK;IAE3D,CACF"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
//#region src/utils.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Property keys that JavaScript runtimes and test frameworks probe
|
|
4
|
+
* on arbitrary objects (serialization, thenable check, inspection,
|
|
5
|
+
* matcher duck-typing). When an RPC-stub Proxy is accessed by
|
|
6
|
+
* `JSON.stringify`, `console.log`, `await`, Vitest matchers, etc.,
|
|
7
|
+
* it hits one of these — we must return `undefined` instead of a
|
|
8
|
+
* call-wrapper to avoid firing a bogus RPC for a method the child
|
|
9
|
+
* doesn't implement.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
declare const INTERNAL_JS_STUB_PROPS: ReadonlySet<string>;
|
|
14
|
+
/**
|
|
15
|
+
* True when the property access is a JS-internal probe that must
|
|
16
|
+
* NOT dispatch an RPC call. Catches all symbol keys plus the named
|
|
17
|
+
* set above.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
declare function isInternalJsStubProp(prop: string | symbol): boolean;
|
|
2
22
|
/**
|
|
3
23
|
* Convert a camelCase string to a kebab-case string
|
|
4
24
|
* @param str The string to convert
|
|
@@ -6,5 +26,5 @@
|
|
|
6
26
|
*/
|
|
7
27
|
declare function camelCaseToKebabCase(str: string): string;
|
|
8
28
|
//#endregion
|
|
9
|
-
export { camelCaseToKebabCase };
|
|
29
|
+
export { INTERNAL_JS_STUB_PROPS, camelCaseToKebabCase, isInternalJsStubProp };
|
|
10
30
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.js
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
//#region src/utils.ts
|
|
2
2
|
/**
|
|
3
|
+
* Property keys that JavaScript runtimes and test frameworks probe
|
|
4
|
+
* on arbitrary objects (serialization, thenable check, inspection,
|
|
5
|
+
* matcher duck-typing). When an RPC-stub Proxy is accessed by
|
|
6
|
+
* `JSON.stringify`, `console.log`, `await`, Vitest matchers, etc.,
|
|
7
|
+
* it hits one of these — we must return `undefined` instead of a
|
|
8
|
+
* call-wrapper to avoid firing a bogus RPC for a method the child
|
|
9
|
+
* doesn't implement.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
const INTERNAL_JS_STUB_PROPS = new Set([
|
|
14
|
+
"toJSON",
|
|
15
|
+
"then",
|
|
16
|
+
"catch",
|
|
17
|
+
"finally",
|
|
18
|
+
"valueOf",
|
|
19
|
+
"toString",
|
|
20
|
+
"constructor",
|
|
21
|
+
"prototype",
|
|
22
|
+
"$$typeof",
|
|
23
|
+
"@@toStringTag",
|
|
24
|
+
"asymmetricMatch",
|
|
25
|
+
"nodeType"
|
|
26
|
+
]);
|
|
27
|
+
/**
|
|
28
|
+
* True when the property access is a JS-internal probe that must
|
|
29
|
+
* NOT dispatch an RPC call. Catches all symbol keys plus the named
|
|
30
|
+
* set above.
|
|
31
|
+
*
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
function isInternalJsStubProp(prop) {
|
|
35
|
+
return typeof prop === "symbol" || INTERNAL_JS_STUB_PROPS.has(prop);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
3
38
|
* Convert a camelCase string to a kebab-case string
|
|
4
39
|
* @param str The string to convert
|
|
5
40
|
* @returns The kebab-case string
|
|
@@ -11,6 +46,6 @@ function camelCaseToKebabCase(str) {
|
|
|
11
46
|
return kebabified.replace(/_/g, "-").replace(/-$/, "");
|
|
12
47
|
}
|
|
13
48
|
//#endregion
|
|
14
|
-
export { camelCaseToKebabCase };
|
|
49
|
+
export { INTERNAL_JS_STUB_PROPS, camelCaseToKebabCase, isInternalJsStubProp };
|
|
15
50
|
|
|
16
51
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../src/utils.ts"],"sourcesContent":["/**\n * Convert a camelCase string to a kebab-case string\n * @param str The string to convert\n * @returns The kebab-case string\n */\nexport function camelCaseToKebabCase(str: string): string {\n // If string is all uppercase, convert to lowercase\n if (str === str.toUpperCase() && str !== str.toLowerCase()) {\n return str.toLowerCase().replace(/_/g, \"-\");\n }\n\n // Otherwise handle camelCase to kebab-case\n let kebabified = str.replace(\n /[A-Z]/g,\n (letter) => `-${letter.toLowerCase()}`\n );\n kebabified = kebabified.startsWith(\"-\") ? kebabified.slice(1) : kebabified;\n // Convert any remaining underscores to hyphens and remove trailing -'s\n return kebabified.replace(/_/g, \"-\").replace(/-$/, \"\");\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../src/utils.ts"],"sourcesContent":["/**\n * Property keys that JavaScript runtimes and test frameworks probe\n * on arbitrary objects (serialization, thenable check, inspection,\n * matcher duck-typing). When an RPC-stub Proxy is accessed by\n * `JSON.stringify`, `console.log`, `await`, Vitest matchers, etc.,\n * it hits one of these — we must return `undefined` instead of a\n * call-wrapper to avoid firing a bogus RPC for a method the child\n * doesn't implement.\n *\n * @internal\n */\nexport const INTERNAL_JS_STUB_PROPS: ReadonlySet<string> = new Set([\n \"toJSON\",\n \"then\",\n \"catch\",\n \"finally\",\n \"valueOf\",\n \"toString\",\n \"constructor\",\n \"prototype\",\n \"$$typeof\",\n \"@@toStringTag\",\n \"asymmetricMatch\",\n \"nodeType\"\n]);\n\n/**\n * True when the property access is a JS-internal probe that must\n * NOT dispatch an RPC call. Catches all symbol keys plus the named\n * set above.\n *\n * @internal\n */\nexport function isInternalJsStubProp(prop: string | symbol): boolean {\n return typeof prop === \"symbol\" || INTERNAL_JS_STUB_PROPS.has(prop);\n}\n\n/**\n * Convert a camelCase string to a kebab-case string\n * @param str The string to convert\n * @returns The kebab-case string\n */\nexport function camelCaseToKebabCase(str: string): string {\n // If string is all uppercase, convert to lowercase\n if (str === str.toUpperCase() && str !== str.toLowerCase()) {\n return str.toLowerCase().replace(/_/g, \"-\");\n }\n\n // Otherwise handle camelCase to kebab-case\n let kebabified = str.replace(\n /[A-Z]/g,\n (letter) => `-${letter.toLowerCase()}`\n );\n kebabified = kebabified.startsWith(\"-\") ? kebabified.slice(1) : kebabified;\n // Convert any remaining underscores to hyphens and remove trailing -'s\n return kebabified.replace(/_/g, \"-\").replace(/-$/, \"\");\n}\n"],"mappings":";;;;;;;;;;;;AAWA,MAAa,yBAA8C,IAAI,IAAI;CACjE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;;;;AASF,SAAgB,qBAAqB,MAAgC;AACnE,QAAO,OAAO,SAAS,YAAY,uBAAuB,IAAI,KAAK;;;;;;;AAQrE,SAAgB,qBAAqB,KAAqB;AAExD,KAAI,QAAQ,IAAI,aAAa,IAAI,QAAQ,IAAI,aAAa,CACxD,QAAO,IAAI,aAAa,CAAC,QAAQ,MAAM,IAAI;CAI7C,IAAI,aAAa,IAAI,QACnB,WACC,WAAW,IAAI,OAAO,aAAa,GACrC;AACD,cAAa,WAAW,WAAW,IAAI,GAAG,WAAW,MAAM,EAAE,GAAG;AAEhE,QAAO,WAAW,QAAQ,MAAM,IAAI,CAAC,QAAQ,MAAM,GAAG"}
|
package/dist/workflows.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"durable objects"
|
|
10
10
|
],
|
|
11
11
|
"type": "module",
|
|
12
|
-
"version": "0.11.
|
|
12
|
+
"version": "0.11.5",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"repository": {
|
|
15
15
|
"directory": "packages/agents",
|
|
@@ -29,46 +29,37 @@
|
|
|
29
29
|
"@modelcontextprotocol/sdk": "1.29.0",
|
|
30
30
|
"@rolldown/plugin-babel": "^0.2.3",
|
|
31
31
|
"cron-schedule": "^6.0.0",
|
|
32
|
-
"json-schema": "^0.4.0",
|
|
33
|
-
"json-schema-to-typescript": "^15.0.4",
|
|
34
32
|
"mimetext": "^3.0.28",
|
|
35
33
|
"nanoid": "^5.1.9",
|
|
36
34
|
"partyserver": "^0.4.1",
|
|
37
|
-
"partysocket": "1.1.
|
|
38
|
-
"picomatch": "^4.0.4",
|
|
35
|
+
"partysocket": "1.1.18",
|
|
39
36
|
"yargs": "^18.0.0"
|
|
40
37
|
},
|
|
41
38
|
"devDependencies": {
|
|
42
|
-
"@ai-sdk/
|
|
43
|
-
"@ai
|
|
44
|
-
"@cloudflare/workers-oauth-provider": "^0.4.0",
|
|
45
|
-
"@tanstack/ai": "^0.10.2",
|
|
39
|
+
"@ai-sdk/react": "^3.0.170",
|
|
40
|
+
"@tanstack/ai": "^0.11.0",
|
|
46
41
|
"@types/react": "^19.2.14",
|
|
47
42
|
"@types/yargs": "^17.0.35",
|
|
43
|
+
"@vitest/browser-playwright": "^4.1.4",
|
|
48
44
|
"@x402/core": "^2.10.0",
|
|
49
45
|
"@x402/evm": "^2.10.0",
|
|
50
|
-
"ai": "^6.0.
|
|
46
|
+
"ai": "^6.0.168",
|
|
51
47
|
"react": "^19.2.5",
|
|
52
48
|
"vitest-browser-react": "^2.2.0",
|
|
53
49
|
"zod": "^4.3.6"
|
|
54
50
|
},
|
|
55
51
|
"peerDependencies": {
|
|
56
|
-
"@ai-sdk/react": "^3.0.0",
|
|
57
52
|
"@cloudflare/ai-chat": ">=0.0.8 <1.0.0",
|
|
58
53
|
"@cloudflare/codemode": ">=0.0.7 <1.0.0",
|
|
59
|
-
"@tanstack/ai": "
|
|
54
|
+
"@tanstack/ai": ">=0.10.2 <1.0.0",
|
|
60
55
|
"@x402/core": "^2.0.0",
|
|
61
56
|
"@x402/evm": "^2.0.0",
|
|
62
57
|
"ai": "^6.0.0",
|
|
63
58
|
"react": "^19.0.0",
|
|
64
|
-
"viem": ">=2.0.0",
|
|
65
59
|
"vite": ">=6.0.0 <9.0.0",
|
|
66
60
|
"zod": "^4.0.0"
|
|
67
61
|
},
|
|
68
62
|
"peerDependenciesMeta": {
|
|
69
|
-
"@ai-sdk/react": {
|
|
70
|
-
"optional": true
|
|
71
|
-
},
|
|
72
63
|
"@cloudflare/ai-chat": {
|
|
73
64
|
"optional": true
|
|
74
65
|
},
|
|
@@ -84,9 +75,6 @@
|
|
|
84
75
|
"@x402/evm": {
|
|
85
76
|
"optional": true
|
|
86
77
|
},
|
|
87
|
-
"viem": {
|
|
88
|
-
"optional": true
|
|
89
|
-
},
|
|
90
78
|
"vite": {
|
|
91
79
|
"optional": true
|
|
92
80
|
}
|
|
@@ -158,6 +146,11 @@
|
|
|
158
146
|
"import": "./dist/experimental/memory/utils/index.js",
|
|
159
147
|
"require": "./dist/experimental/memory/utils/index.js"
|
|
160
148
|
},
|
|
149
|
+
"./experimental/webmcp": {
|
|
150
|
+
"types": "./dist/experimental/webmcp.d.ts",
|
|
151
|
+
"import": "./dist/experimental/webmcp.js",
|
|
152
|
+
"require": "./dist/experimental/webmcp.js"
|
|
153
|
+
},
|
|
161
154
|
"./x402": {
|
|
162
155
|
"types": "./dist/mcp/x402.d.ts",
|
|
163
156
|
"import": "./dist/mcp/x402.js",
|
|
@@ -238,6 +231,7 @@
|
|
|
238
231
|
"test:browser": "vitest run --config src/browser-tests/vitest.config.ts",
|
|
239
232
|
"test:workers": "vitest --project workers",
|
|
240
233
|
"test:chat": "vitest --project chat",
|
|
234
|
+
"test:webmcp": "vitest --project webmcp",
|
|
241
235
|
"test:x402": "vitest --project x402",
|
|
242
236
|
"test:e2e": "vitest --run -c src/e2e-tests/vitest.config.ts"
|
|
243
237
|
}
|