@cloudflare/think 0.23.0 → 0.25.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.
Files changed (49) hide show
  1. package/README.md +30 -40
  2. package/dist/{chat-sdk-BEjKXjCm.js → chat-sdk-4Nu96eDX.js} +375 -256
  3. package/dist/chat-sdk-4Nu96eDX.js.map +1 -0
  4. package/dist/extensions/index.d.ts +30 -72
  5. package/dist/extensions/index.js +45 -47
  6. package/dist/extensions/index.js.map +1 -1
  7. package/dist/{fetch-DO3uQ9py.js → fetch-BbYxtlff.js} +10 -2
  8. package/dist/fetch-BbYxtlff.js.map +1 -0
  9. package/dist/manager-B3rcb_6p.js +493 -0
  10. package/dist/manager-B3rcb_6p.js.map +1 -0
  11. package/dist/manager-CWGumyKi.d.ts +3391 -0
  12. package/dist/messengers/index.d.ts +54 -66
  13. package/dist/messengers/index.js +2 -2
  14. package/dist/messengers/telegram.d.ts +4 -4
  15. package/dist/messengers/telegram.js +1 -1
  16. package/dist/think.d.ts +2 -2
  17. package/dist/think.js +8493 -10725
  18. package/dist/think.js.map +1 -1
  19. package/dist/tools/browser.d.ts +1 -1
  20. package/dist/tools/browser.js +1 -1
  21. package/dist/tools/browser.js.map +1 -1
  22. package/dist/tools/execute.d.ts +2 -2
  23. package/dist/tools/execute.js +2 -2
  24. package/dist/tools/execute.js.map +1 -1
  25. package/dist/tools/extensions.d.ts +1 -1
  26. package/dist/tools/extensions.js +1 -1
  27. package/dist/tools/fetch.js +1 -1
  28. package/dist/workflows.d.ts +5 -2
  29. package/docs/actions.md +12 -0
  30. package/docs/channels.md +10 -4
  31. package/docs/client-tools.md +57 -27
  32. package/docs/context.md +92 -0
  33. package/docs/getting-started.md +4 -4
  34. package/docs/index.md +112 -52
  35. package/docs/lifecycle-hooks.md +10 -21
  36. package/docs/multi-chat.md +6 -6
  37. package/docs/programmatic-submissions.md +28 -10
  38. package/docs/sub-agents.md +45 -51
  39. package/docs/tools.md +41 -15
  40. package/docs/workflows.md +5 -4
  41. package/package.json +15 -10
  42. package/dist/chat-sdk-BEjKXjCm.js.map +0 -1
  43. package/dist/fetch-DO3uQ9py.js.map +0 -1
  44. package/dist/hook-proxy-DY2sBNa0.js +0 -117
  45. package/dist/hook-proxy-DY2sBNa0.js.map +0 -1
  46. package/dist/index-DDnny6kt.d.ts +0 -5847
  47. package/dist/manager-BubfmA3q.js +0 -313
  48. package/dist/manager-BubfmA3q.js.map +0 -1
  49. package/dist/manager-rze95KCk.d.ts +0 -235
@@ -1,313 +0,0 @@
1
- import { a as _checkPrivateRedeclaration, i as _classPrivateFieldInitSpec, n as _classPrivateFieldGet2, r as _assertClassBrand, t as _classPrivateFieldSet2 } from "./classPrivateFieldSet2-DwGJfC3w.js";
2
- import { jsonSchema, tool } from "ai";
3
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/classPrivateMethodInitSpec.js
4
- function _classPrivateMethodInitSpec(e, a) {
5
- _checkPrivateRedeclaration(e, a), a.add(e);
6
- }
7
- //#endregion
8
- //#region src/extensions/manager.ts
9
- /**
10
- * ExtensionManager — loads, manages, and exposes tools from extension Workers.
11
- *
12
- * Extensions are sandboxed Workers created via WorkerLoader. Each extension
13
- * declares tools (with JSON Schema inputs) and permissions. The manager:
14
- *
15
- * 1. Wraps extension source in a Worker module with describe/execute RPC
16
- * 2. Loads it via WorkerLoader with permission-gated bindings
17
- * 3. Discovers tools via describe() RPC call
18
- * 4. Exposes them as AI SDK tools via getTools()
19
- *
20
- * Extension source format — a JS object expression defining tools:
21
- *
22
- * ```js
23
- * ({
24
- * greet: {
25
- * description: "Greet someone",
26
- * parameters: { name: { type: "string" } },
27
- * required: ["name"],
28
- * execute: async (args, host) => `Hello, ${args.name}!`
29
- * }
30
- * })
31
- * ```
32
- *
33
- * The `host` parameter in execute is provided via `env.host` — a loopback
34
- * binding that resolves the parent agent and delegates workspace operations
35
- * (gated by permissions). See HostBridgeLoopback.
36
- */
37
- /**
38
- * Sanitize a name for use as a tool name prefix.
39
- * Replaces any non-alphanumeric characters with underscores and
40
- * collapses consecutive underscores.
41
- */
42
- function sanitizeName(name) {
43
- if (!name || name.trim().length === 0) throw new Error("Extension name must not be empty");
44
- return name.replace(/[^a-zA-Z0-9]/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "");
45
- }
46
- const STORAGE_PREFIX = "ext:";
47
- var _loader = /* @__PURE__ */ new WeakMap();
48
- var _storage = /* @__PURE__ */ new WeakMap();
49
- var _createHostBinding = /* @__PURE__ */ new WeakMap();
50
- var _extensions = /* @__PURE__ */ new WeakMap();
51
- var _restored = /* @__PURE__ */ new WeakMap();
52
- var _onUnload = /* @__PURE__ */ new WeakMap();
53
- var _ExtensionManager_brand = /* @__PURE__ */ new WeakSet();
54
- var ExtensionManager = class {
55
- constructor(options) {
56
- _classPrivateMethodInitSpec(this, _ExtensionManager_brand);
57
- _classPrivateFieldInitSpec(this, _loader, void 0);
58
- _classPrivateFieldInitSpec(this, _storage, void 0);
59
- _classPrivateFieldInitSpec(this, _createHostBinding, void 0);
60
- _classPrivateFieldInitSpec(this, _extensions, /* @__PURE__ */ new Map());
61
- _classPrivateFieldInitSpec(this, _restored, false);
62
- _classPrivateFieldInitSpec(this, _onUnload, null);
63
- _classPrivateFieldSet2(_loader, this, options.loader);
64
- _classPrivateFieldSet2(_storage, this, options.storage ?? null);
65
- _classPrivateFieldSet2(_createHostBinding, this, options.createHostBinding ?? null);
66
- }
67
- /**
68
- * Load an extension from source code.
69
- *
70
- * The source is a JS object expression defining tools. Each tool has
71
- * `description`, `parameters` (JSON Schema properties), optional
72
- * `required` array, and an `execute` async function.
73
- *
74
- * @returns Summary of the loaded extension including discovered tools.
75
- */
76
- /**
77
- * Restore extensions from DO storage after hibernation.
78
- *
79
- * Idempotent — skips extensions already in memory. Call this at the
80
- * start of each chat turn (e.g. in onChatMessage before getTools).
81
- */
82
- async restore() {
83
- if (_classPrivateFieldGet2(_restored, this) || !_classPrivateFieldGet2(_storage, this)) return;
84
- _classPrivateFieldSet2(_restored, this, true);
85
- const entries = await _classPrivateFieldGet2(_storage, this).list({ prefix: STORAGE_PREFIX });
86
- for (const persisted of entries.values()) {
87
- if (_classPrivateFieldGet2(_extensions, this).has(persisted.manifest.name)) continue;
88
- await _assertClassBrand(_ExtensionManager_brand, this, _loadInternal).call(this, persisted.manifest, persisted.source);
89
- }
90
- }
91
- async load(manifest, source) {
92
- if (_classPrivateFieldGet2(_extensions, this).has(manifest.name)) throw new Error(`Extension "${manifest.name}" is already loaded. Unload it first.`);
93
- const info = await _assertClassBrand(_ExtensionManager_brand, this, _loadInternal).call(this, manifest, source);
94
- if (_classPrivateFieldGet2(_storage, this)) await _classPrivateFieldGet2(_storage, this).put(`${STORAGE_PREFIX}${manifest.name}`, {
95
- manifest,
96
- source
97
- });
98
- return info;
99
- }
100
- /**
101
- * Unload an extension, removing its tools from the agent.
102
- * If an onUnload callback is registered, it fires with the
103
- * extension's namespaced context labels so the caller can
104
- * remove context blocks from the Session.
105
- */
106
- async unload(name) {
107
- const ext = _classPrivateFieldGet2(_extensions, this).get(name);
108
- if (!ext) return false;
109
- const removed = _classPrivateFieldGet2(_extensions, this).delete(name);
110
- if (removed && _classPrivateFieldGet2(_storage, this)) await _classPrivateFieldGet2(_storage, this).delete(`${STORAGE_PREFIX}${name}`);
111
- if (removed && _classPrivateFieldGet2(_onUnload, this)) {
112
- const prefix = sanitizeName(name);
113
- const contextLabels = (ext.manifest.context ?? []).map((c) => `${prefix}_${c.label}`);
114
- await _classPrivateFieldGet2(_onUnload, this).call(this, name, contextLabels);
115
- }
116
- return removed;
117
- }
118
- /**
119
- * Register a callback invoked when an extension is unloaded.
120
- * Think uses this to remove the extension's context blocks from Session.
121
- */
122
- onUnload(cb) {
123
- _classPrivateFieldSet2(_onUnload, this, cb);
124
- }
125
- /**
126
- * Get the namespaced context labels for all loaded extensions
127
- * that declare context blocks in their manifests.
128
- */
129
- getContextLabels() {
130
- const result = [];
131
- for (const ext of _classPrivateFieldGet2(_extensions, this).values()) {
132
- if (!ext.manifest.context) continue;
133
- const prefix = sanitizeName(ext.manifest.name);
134
- for (const ctx of ext.manifest.context) result.push({
135
- extName: ext.manifest.name,
136
- label: `${prefix}_${ctx.label}`
137
- });
138
- }
139
- return result;
140
- }
141
- /**
142
- * Get extension manifest by name.
143
- */
144
- getManifest(name) {
145
- return _classPrivateFieldGet2(_extensions, this).get(name)?.manifest ?? null;
146
- }
147
- /**
148
- * Get extensions that subscribe to a specific hook, in load order.
149
- */
150
- getHookSubscribers(hookName) {
151
- const result = [];
152
- for (const ext of _classPrivateFieldGet2(_extensions, this).values()) if (ext.hooks.includes(hookName)) result.push({
153
- name: ext.manifest.name,
154
- entrypoint: ext.entrypoint
155
- });
156
- return result;
157
- }
158
- /**
159
- * List all loaded extensions.
160
- */
161
- list() {
162
- return [..._classPrivateFieldGet2(_extensions, this).values()].map((ext) => toExtensionInfo(ext.manifest, ext.tools));
163
- }
164
- /**
165
- * Get AI SDK tools from all loaded extensions.
166
- *
167
- * Tool names are prefixed with the sanitized extension name to avoid
168
- * collisions: e.g. extension "github" with tool "create_pr" → "github_create_pr".
169
- */
170
- getTools() {
171
- const tools = {};
172
- for (const ext of _classPrivateFieldGet2(_extensions, this).values()) {
173
- const prefix = sanitizeName(ext.manifest.name);
174
- for (const descriptor of ext.tools) {
175
- const toolName = `${prefix}_${descriptor.name}`;
176
- tools[toolName] = tool({
177
- description: `[${ext.manifest.name}] ${descriptor.description}`,
178
- inputSchema: jsonSchema(descriptor.inputSchema),
179
- execute: async (args) => {
180
- if (!_classPrivateFieldGet2(_extensions, this).has(ext.manifest.name)) throw new Error(`Extension "${ext.manifest.name}" has been unloaded. Tool "${toolName}" is no longer available.`);
181
- const resultJson = await ext.entrypoint.execute(descriptor.name, JSON.stringify(args));
182
- const parsed = JSON.parse(resultJson);
183
- if (parsed.error) throw new Error(parsed.error);
184
- return parsed.result;
185
- }
186
- });
187
- }
188
- }
189
- return tools;
190
- }
191
- };
192
- async function _loadInternal(manifest, source) {
193
- const workerModule = wrapExtensionSource(source);
194
- const permissions = manifest.permissions ?? {};
195
- const workerEnv = {};
196
- const needsHost = (permissions.workspace ?? "none") !== "none" || permissions.context?.read !== void 0 || permissions.context?.write !== void 0 || (permissions.messages ?? "none") !== "none" || permissions.session?.sendMessage || permissions.session?.metadata;
197
- if (_classPrivateFieldGet2(_createHostBinding, this) && needsHost) {
198
- const prefix = sanitizeName(manifest.name);
199
- const ownLabels = (manifest.context ?? []).map((c) => `${prefix}_${c.label}`);
200
- workerEnv.host = _classPrivateFieldGet2(_createHostBinding, this).call(this, permissions, ownLabels);
201
- }
202
- const entrypoint = _classPrivateFieldGet2(_loader, this).get(`ext-${manifest.name}-${manifest.version}-${Date.now()}`, () => ({
203
- compatibilityDate: "2025-06-01",
204
- compatibilityFlags: ["nodejs_compat"],
205
- mainModule: "extension.js",
206
- modules: { "extension.js": workerModule },
207
- globalOutbound: permissions.network?.length ? void 0 : null,
208
- ...Object.keys(workerEnv).length > 0 ? { env: workerEnv } : {}
209
- })).getEntrypoint();
210
- const descriptorsJson = await entrypoint.describe();
211
- const tools = JSON.parse(descriptorsJson);
212
- let hooks = [];
213
- try {
214
- const manifestJson = await entrypoint.manifest();
215
- hooks = JSON.parse(manifestJson).hooks ?? [];
216
- } catch {}
217
- _classPrivateFieldGet2(_extensions, this).set(manifest.name, {
218
- manifest,
219
- tools,
220
- hooks,
221
- entrypoint
222
- });
223
- return toExtensionInfo(manifest, tools);
224
- }
225
- function toExtensionInfo(manifest, tools) {
226
- const prefix = sanitizeName(manifest.name);
227
- return {
228
- name: manifest.name,
229
- version: manifest.version,
230
- description: manifest.description,
231
- tools: tools.map((t) => `${prefix}_${t.name}`),
232
- contextLabels: (manifest.context ?? []).map((c) => `${prefix}_${c.label}`),
233
- permissions: manifest.permissions ?? {}
234
- };
235
- }
236
- /**
237
- * Wrap an extension source in a Worker module that exposes
238
- * describe(), execute(), manifest(), and hook RPC methods.
239
- *
240
- * Source format: `({ tools: {...}, hooks: {...} })`
241
- * Both `tools` and `hooks` are optional.
242
- */
243
- function wrapExtensionSource(source) {
244
- return `import { WorkerEntrypoint } from "cloudflare:workers";
245
-
246
- const __ext = (${source});
247
- if (__ext && typeof __ext === "object" && !("tools" in __ext) && !("hooks" in __ext)) {
248
- throw new Error(
249
- "Invalid extension source format. Expected { tools: {...}, hooks: {...} } " +
250
- "but got a flat object. Wrap your tools in a 'tools' key."
251
- );
252
- }
253
- const __tools = __ext.tools || {};
254
- const __hooks = __ext.hooks || {};
255
-
256
- export default class Extension extends WorkerEntrypoint {
257
- describe() {
258
- const descriptors = [];
259
- for (const [name, def] of Object.entries(__tools)) {
260
- descriptors.push({
261
- name,
262
- description: def.description || name,
263
- inputSchema: {
264
- type: "object",
265
- properties: def.parameters || {},
266
- required: def.required || []
267
- }
268
- });
269
- }
270
- return JSON.stringify(descriptors);
271
- }
272
-
273
- manifest() {
274
- return JSON.stringify({
275
- hooks: Object.keys(__hooks)
276
- });
277
- }
278
-
279
- async execute(toolName, argsJson) {
280
- const def = __tools[toolName];
281
- if (!def || !def.execute) {
282
- return JSON.stringify({ error: "Unknown tool: " + toolName });
283
- }
284
- try {
285
- const args = JSON.parse(argsJson);
286
- const result = await def.execute(args, this.env.host ?? null);
287
- return JSON.stringify({ result });
288
- } catch (err) {
289
- return JSON.stringify({ error: err.message || String(err) });
290
- }
291
- }
292
-
293
- async hook(name, ctxSnapshot) {
294
- const fn = __hooks[name];
295
- if (!fn) return JSON.stringify({ skipped: true });
296
- try {
297
- // Hook handlers receive (ctxSnapshot, host) — symmetric with tool
298
- // executes. \`host\` is null when the extension was loaded without
299
- // host-requiring permissions or when the worker entry point doesn't
300
- // re-export HostBridgeLoopback.
301
- const result = await fn(ctxSnapshot, this.env.host ?? null);
302
- return JSON.stringify({ result: result ?? {} });
303
- } catch (err) {
304
- return JSON.stringify({ error: err.message || String(err) });
305
- }
306
- }
307
- }
308
- `;
309
- }
310
- //#endregion
311
- export { sanitizeName as n, _classPrivateMethodInitSpec as r, ExtensionManager as t };
312
-
313
- //# sourceMappingURL=manager-BubfmA3q.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"manager-BubfmA3q.js","names":[],"sources":["../src/extensions/manager.ts"],"sourcesContent":["/**\n * ExtensionManager — loads, manages, and exposes tools from extension Workers.\n *\n * Extensions are sandboxed Workers created via WorkerLoader. Each extension\n * declares tools (with JSON Schema inputs) and permissions. The manager:\n *\n * 1. Wraps extension source in a Worker module with describe/execute RPC\n * 2. Loads it via WorkerLoader with permission-gated bindings\n * 3. Discovers tools via describe() RPC call\n * 4. Exposes them as AI SDK tools via getTools()\n *\n * Extension source format — a JS object expression defining tools:\n *\n * ```js\n * ({\n * greet: {\n * description: \"Greet someone\",\n * parameters: { name: { type: \"string\" } },\n * required: [\"name\"],\n * execute: async (args, host) => `Hello, ${args.name}!`\n * }\n * })\n * ```\n *\n * The `host` parameter in execute is provided via `env.host` — a loopback\n * binding that resolves the parent agent and delegates workspace operations\n * (gated by permissions). See HostBridgeLoopback.\n */\n\nimport { tool, jsonSchema } from \"ai\";\nimport type { ToolSet } from \"ai\";\nimport type {\n ExtensionManifest,\n ExtensionPermissions,\n ExtensionInfo,\n ExtensionToolDescriptor\n} from \"./types\";\n\n/**\n * Sanitize a name for use as a tool name prefix.\n * Replaces any non-alphanumeric characters with underscores and\n * collapses consecutive underscores.\n */\nexport function sanitizeName(name: string): string {\n if (!name || name.trim().length === 0) {\n throw new Error(\"Extension name must not be empty\");\n }\n return name\n .replace(/[^a-zA-Z0-9]/g, \"_\")\n .replace(/_+/g, \"_\")\n .replace(/^_|_$/g, \"\");\n}\n\ninterface ExtensionEntrypoint {\n describe(): Promise<string>;\n manifest(): Promise<string>;\n execute(toolName: string, argsJson: string): Promise<string>;\n hook(name: string, ctxProxy: unknown): Promise<string>;\n}\n\ninterface LoadedExtension {\n manifest: ExtensionManifest;\n tools: ExtensionToolDescriptor[];\n hooks: string[];\n entrypoint: ExtensionEntrypoint;\n}\n\n/** Shape persisted to DO storage for each extension. */\ninterface PersistedExtension {\n manifest: ExtensionManifest;\n source: string;\n}\n\nconst STORAGE_PREFIX = \"ext:\";\n\nexport interface ExtensionManagerOptions {\n /** WorkerLoader binding for creating sandboxed extension Workers. */\n loader: WorkerLoader;\n /**\n * Durable Object storage for persisting extensions across hibernation.\n * If provided, loaded extensions survive DO restarts. Call `restore()`\n * on each turn to rebuild in-memory state from storage.\n */\n storage?: DurableObjectStorage;\n /**\n * Factory that creates a loopback Fetcher for workspace access, given\n * an extension's declared permissions. The returned binding is injected\n * into the extension worker's `env.host`.\n *\n * If not provided, extensions receive no host binding (workspace tools\n * will get `null` for the host parameter).\n *\n * Typically wired up using HostBridgeLoopback via `ctx.exports`:\n * ```typescript\n * createHostBinding: (permissions, ownContextLabels) =>\n * ctx.exports.HostBridgeLoopback({\n * props: { agentClassName: \"ChatSession\", agentId: ctx.id.toString(), permissions, ownContextLabels }\n * })\n * ```\n */\n createHostBinding?: (\n permissions: ExtensionPermissions,\n ownContextLabels: string[]\n ) => Fetcher;\n}\n\nexport class ExtensionManager {\n #loader: WorkerLoader;\n #storage: DurableObjectStorage | null;\n #createHostBinding:\n | ((\n permissions: ExtensionPermissions,\n ownContextLabels: string[]\n ) => Fetcher)\n | null;\n #extensions = new Map<string, LoadedExtension>();\n #restored = false;\n #onUnload:\n | ((name: string, contextLabels: string[]) => void | Promise<void>)\n | null = null;\n\n constructor(options: ExtensionManagerOptions) {\n this.#loader = options.loader;\n this.#storage = options.storage ?? null;\n this.#createHostBinding = options.createHostBinding ?? null;\n }\n\n /**\n * Load an extension from source code.\n *\n * The source is a JS object expression defining tools. Each tool has\n * `description`, `parameters` (JSON Schema properties), optional\n * `required` array, and an `execute` async function.\n *\n * @returns Summary of the loaded extension including discovered tools.\n */\n /**\n * Restore extensions from DO storage after hibernation.\n *\n * Idempotent — skips extensions already in memory. Call this at the\n * start of each chat turn (e.g. in onChatMessage before getTools).\n */\n async restore(): Promise<void> {\n if (this.#restored || !this.#storage) return;\n this.#restored = true;\n\n const entries = await this.#storage.list<PersistedExtension>({\n prefix: STORAGE_PREFIX\n });\n\n for (const persisted of entries.values()) {\n if (this.#extensions.has(persisted.manifest.name)) continue;\n await this.#loadInternal(persisted.manifest, persisted.source);\n }\n }\n\n async load(\n manifest: ExtensionManifest,\n source: string\n ): Promise<ExtensionInfo> {\n if (this.#extensions.has(manifest.name)) {\n throw new Error(\n `Extension \"${manifest.name}\" is already loaded. Unload it first.`\n );\n }\n\n const info = await this.#loadInternal(manifest, source);\n\n // Persist to storage so it survives hibernation\n if (this.#storage) {\n await this.#storage.put<PersistedExtension>(\n `${STORAGE_PREFIX}${manifest.name}`,\n { manifest, source }\n );\n }\n\n return info;\n }\n\n async #loadInternal(\n manifest: ExtensionManifest,\n source: string\n ): Promise<ExtensionInfo> {\n const workerModule = wrapExtensionSource(source);\n const permissions = manifest.permissions ?? {};\n\n // Build env bindings for the dynamic worker. Inject a loopback\n // Fetcher as env.host when the extension declares ANY permission\n // that requires host access (workspace, context, messages, session).\n const workerEnv: Record<string, Fetcher> = {};\n const needsHost =\n (permissions.workspace ?? \"none\") !== \"none\" ||\n permissions.context?.read !== undefined ||\n permissions.context?.write !== undefined ||\n (permissions.messages ?? \"none\") !== \"none\" ||\n permissions.session?.sendMessage ||\n permissions.session?.metadata;\n if (this.#createHostBinding && needsHost) {\n const prefix = sanitizeName(manifest.name);\n const ownLabels = (manifest.context ?? []).map(\n (c) => `${prefix}_${c.label}`\n );\n workerEnv.host = this.#createHostBinding(permissions, ownLabels);\n }\n\n const worker = this.#loader.get(\n `ext-${manifest.name}-${manifest.version}-${Date.now()}`,\n () => ({\n compatibilityDate: \"2025-06-01\",\n compatibilityFlags: [\"nodejs_compat\"],\n mainModule: \"extension.js\",\n modules: { \"extension.js\": workerModule },\n globalOutbound: permissions.network?.length ? undefined : null,\n ...(Object.keys(workerEnv).length > 0 ? { env: workerEnv } : {})\n })\n );\n\n const entrypoint = worker.getEntrypoint() as unknown as ExtensionEntrypoint;\n\n // Discover tools and hooks via RPC\n const descriptorsJson = await entrypoint.describe();\n const tools = JSON.parse(descriptorsJson) as ExtensionToolDescriptor[];\n\n let hooks: string[] = [];\n try {\n const manifestJson = await entrypoint.manifest();\n const runtimeManifest = JSON.parse(manifestJson) as {\n hooks?: string[];\n };\n hooks = runtimeManifest.hooks ?? [];\n } catch {\n // Legacy extensions may not have manifest() — treat as no hooks\n }\n\n this.#extensions.set(manifest.name, {\n manifest,\n tools,\n hooks,\n entrypoint\n });\n\n return toExtensionInfo(manifest, tools);\n }\n\n /**\n * Unload an extension, removing its tools from the agent.\n * If an onUnload callback is registered, it fires with the\n * extension's namespaced context labels so the caller can\n * remove context blocks from the Session.\n */\n async unload(name: string): Promise<boolean> {\n const ext = this.#extensions.get(name);\n if (!ext) return false;\n\n const removed = this.#extensions.delete(name);\n if (removed && this.#storage) {\n await this.#storage.delete(`${STORAGE_PREFIX}${name}`);\n }\n\n if (removed && this.#onUnload) {\n const prefix = sanitizeName(name);\n const contextLabels = (ext.manifest.context ?? []).map(\n (c) => `${prefix}_${c.label}`\n );\n await this.#onUnload(name, contextLabels);\n }\n\n return removed;\n }\n\n /**\n * Register a callback invoked when an extension is unloaded.\n * Think uses this to remove the extension's context blocks from Session.\n */\n onUnload(\n cb: (name: string, contextLabels: string[]) => void | Promise<void>\n ): void {\n this.#onUnload = cb;\n }\n\n /**\n * Get the namespaced context labels for all loaded extensions\n * that declare context blocks in their manifests.\n */\n getContextLabels(): Array<{ extName: string; label: string }> {\n const result: Array<{ extName: string; label: string }> = [];\n for (const ext of this.#extensions.values()) {\n if (!ext.manifest.context) continue;\n const prefix = sanitizeName(ext.manifest.name);\n for (const ctx of ext.manifest.context) {\n result.push({\n extName: ext.manifest.name,\n label: `${prefix}_${ctx.label}`\n });\n }\n }\n return result;\n }\n\n /**\n * Get extension manifest by name.\n */\n getManifest(name: string): ExtensionManifest | null {\n return this.#extensions.get(name)?.manifest ?? null;\n }\n\n /**\n * Get extensions that subscribe to a specific hook, in load order.\n */\n getHookSubscribers(\n hookName: string\n ): Array<{ name: string; entrypoint: ExtensionEntrypoint }> {\n const result: Array<{ name: string; entrypoint: ExtensionEntrypoint }> = [];\n for (const ext of this.#extensions.values()) {\n if (ext.hooks.includes(hookName)) {\n result.push({ name: ext.manifest.name, entrypoint: ext.entrypoint });\n }\n }\n return result;\n }\n\n /**\n * List all loaded extensions.\n */\n list(): ExtensionInfo[] {\n return [...this.#extensions.values()].map((ext) =>\n toExtensionInfo(ext.manifest, ext.tools)\n );\n }\n\n /**\n * Get AI SDK tools from all loaded extensions.\n *\n * Tool names are prefixed with the sanitized extension name to avoid\n * collisions: e.g. extension \"github\" with tool \"create_pr\" → \"github_create_pr\".\n */\n getTools(): ToolSet {\n const tools: ToolSet = {};\n\n for (const ext of this.#extensions.values()) {\n const prefix = sanitizeName(ext.manifest.name);\n\n for (const descriptor of ext.tools) {\n const toolName = `${prefix}_${descriptor.name}`;\n\n tools[toolName] = tool({\n description: `[${ext.manifest.name}] ${descriptor.description}`,\n inputSchema: jsonSchema(\n descriptor.inputSchema as Record<string, unknown>\n ),\n execute: async (args: Record<string, unknown>) => {\n if (!this.#extensions.has(ext.manifest.name)) {\n throw new Error(\n `Extension \"${ext.manifest.name}\" has been unloaded. Tool \"${toolName}\" is no longer available.`\n );\n }\n const resultJson = await ext.entrypoint.execute(\n descriptor.name,\n JSON.stringify(args)\n );\n const parsed = JSON.parse(resultJson) as {\n result?: unknown;\n error?: string;\n };\n if (parsed.error) throw new Error(parsed.error);\n return parsed.result;\n }\n });\n }\n }\n\n return tools;\n }\n}\n\nfunction toExtensionInfo(\n manifest: ExtensionManifest,\n tools: ExtensionToolDescriptor[]\n): ExtensionInfo {\n const prefix = sanitizeName(manifest.name);\n return {\n name: manifest.name,\n version: manifest.version,\n description: manifest.description,\n tools: tools.map((t) => `${prefix}_${t.name}`),\n contextLabels: (manifest.context ?? []).map((c) => `${prefix}_${c.label}`),\n permissions: manifest.permissions ?? {}\n };\n}\n\n/**\n * Wrap an extension source in a Worker module that exposes\n * describe(), execute(), manifest(), and hook RPC methods.\n *\n * Source format: `({ tools: {...}, hooks: {...} })`\n * Both `tools` and `hooks` are optional.\n */\nfunction wrapExtensionSource(source: string): string {\n return `import { WorkerEntrypoint } from \"cloudflare:workers\";\n\nconst __ext = (${source});\nif (__ext && typeof __ext === \"object\" && !(\"tools\" in __ext) && !(\"hooks\" in __ext)) {\n throw new Error(\n \"Invalid extension source format. Expected { tools: {...}, hooks: {...} } \" +\n \"but got a flat object. Wrap your tools in a 'tools' key.\"\n );\n}\nconst __tools = __ext.tools || {};\nconst __hooks = __ext.hooks || {};\n\nexport default class Extension extends WorkerEntrypoint {\n describe() {\n const descriptors = [];\n for (const [name, def] of Object.entries(__tools)) {\n descriptors.push({\n name,\n description: def.description || name,\n inputSchema: {\n type: \"object\",\n properties: def.parameters || {},\n required: def.required || []\n }\n });\n }\n return JSON.stringify(descriptors);\n }\n\n manifest() {\n return JSON.stringify({\n hooks: Object.keys(__hooks)\n });\n }\n\n async execute(toolName, argsJson) {\n const def = __tools[toolName];\n if (!def || !def.execute) {\n return JSON.stringify({ error: \"Unknown tool: \" + toolName });\n }\n try {\n const args = JSON.parse(argsJson);\n const result = await def.execute(args, this.env.host ?? null);\n return JSON.stringify({ result });\n } catch (err) {\n return JSON.stringify({ error: err.message || String(err) });\n }\n }\n\n async hook(name, ctxSnapshot) {\n const fn = __hooks[name];\n if (!fn) return JSON.stringify({ skipped: true });\n try {\n // Hook handlers receive (ctxSnapshot, host) — symmetric with tool\n // executes. \\`host\\` is null when the extension was loaded without\n // host-requiring permissions or when the worker entry point doesn't\n // re-export HostBridgeLoopback.\n const result = await fn(ctxSnapshot, this.env.host ?? null);\n return JSON.stringify({ result: result ?? {} });\n } catch (err) {\n return JSON.stringify({ error: err.message || String(err) });\n }\n }\n}\n`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2C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K,MAAM,GAAG,OAAO,GAAG,EAAE,MAAM;EAC7C,gBAAgB,SAAS,WAAW,CAAC,EAAA,CAAG,KAAK,MAAM,GAAG,OAAO,GAAG,EAAE,OAAO;EACzE,aAAa,SAAS,eAAe,CAAC;CACxC;AACF;;;;;;;;AASA,SAAS,oBAAoB,QAAwB;CACnD,OAAO;;iBAEQ,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DxB"}
@@ -1,235 +0,0 @@
1
- import { ToolSet } from "ai";
2
-
3
- //#region src/extensions/types.d.ts
4
- /**
5
- * Extension system types.
6
- *
7
- * Extensions are sandboxed Workers loaded on demand via WorkerLoader.
8
- * Each extension provides tools that the agent can use, with controlled
9
- * access to the host (workspace, network) via permissions.
10
- */
11
- /**
12
- * Manifest declaring an extension's identity, permissions, and contributions.
13
- * Passed to ExtensionManager.load() alongside the extension source.
14
- */
15
- interface ExtensionManifest {
16
- /** Unique name for this extension (used as namespace prefix for tools and context). */
17
- name: string;
18
- /** Semver version string. */
19
- version: string;
20
- /** Human-readable description. */
21
- description?: string;
22
- /** Permission declarations — controls what the extension can access. */
23
- permissions?: ExtensionPermissions;
24
- /**
25
- * Context blocks contributed by this extension.
26
- * Labels are namespaced as `{extName}_{label}` at registration.
27
- * Currently backed by SQLite storage — extensions write via
28
- * `host.setContext()`. Direct RPC delegation is planned for Phase 4.
29
- */
30
- context?: Array<{
31
- /** Block label (namespaced as {extName}_{label}). */ label: string /** Human-readable description shown in the system prompt header. */;
32
- description?: string;
33
- /** Block type determines which tools are generated.
34
- * Note: not yet enforced — all blocks use SQLite-backed storage
35
- * until bridge providers are implemented (Phase 4). */
36
- type:
37
- | "readonly"
38
- | "writable"
39
- | "searchable" /** Maximum token budget for this block. */;
40
- maxTokens?: number;
41
- }>;
42
- /**
43
- * Lifecycle hooks this extension provides handlers for.
44
- * The extension Worker must expose corresponding RPC methods.
45
- */
46
- hooks?: Array<
47
- | "beforeTurn"
48
- | "beforeToolCall"
49
- | "afterToolCall"
50
- | "onStepFinish"
51
- | "onChunk"
52
- >;
53
- }
54
- interface ExtensionPermissions {
55
- /**
56
- * Allowed network hosts. If empty or undefined, the extension has
57
- * no outbound network access (globalOutbound: null).
58
- * If set, the extension inherits the parent Worker's network.
59
- *
60
- * Note: per-host filtering is not yet enforced at the runtime level.
61
- * This field serves as a declaration of intent; actual enforcement
62
- * is all-or-nothing via globalOutbound.
63
- */
64
- network?: string[];
65
- /**
66
- * Workspace access level.
67
- * - "none" (default): no workspace access
68
- * - "read": can read files and list directories
69
- * - "read-write": can read, write, and delete files
70
- */
71
- workspace?: "read" | "read-write" | "none";
72
- /**
73
- * Context block access.
74
- * - `read`: which labels the extension can read ("all" or specific list)
75
- * - `write`: which labels the extension can write ("own" = only its manifest-declared labels, or specific list)
76
- */
77
- context?: {
78
- read?: string[] | "all";
79
- write?: string[] | "own";
80
- };
81
- /**
82
- * Message history access.
83
- * - "none" (default): no access
84
- * - "read": can read conversation history
85
- */
86
- messages?: "none" | "read";
87
- /**
88
- * Session-level capabilities.
89
- * - `sendMessage`: can inject user messages (queued when inside inference loop)
90
- * - `metadata`: can read session metadata (message count, etc.)
91
- */
92
- session?: {
93
- sendMessage?: boolean;
94
- metadata?: boolean;
95
- };
96
- }
97
- /**
98
- * Tool descriptor returned by the extension's describe() method.
99
- * Uses JSON Schema for input validation.
100
- */
101
- interface ExtensionToolDescriptor {
102
- name: string;
103
- description: string;
104
- inputSchema: {
105
- type: "object";
106
- properties: Record<string, unknown>;
107
- required?: string[];
108
- };
109
- }
110
- /**
111
- * Summary of a loaded extension, returned by ExtensionManager.list().
112
- */
113
- interface ExtensionInfo {
114
- name: string;
115
- version: string;
116
- description?: string;
117
- /** Names of tools provided by this extension. */
118
- tools: string[];
119
- /** Namespaced context labels contributed by this extension. */
120
- contextLabels: string[];
121
- permissions: ExtensionPermissions;
122
- }
123
- //#endregion
124
- //#region src/extensions/manager.d.ts
125
- interface ExtensionEntrypoint {
126
- describe(): Promise<string>;
127
- manifest(): Promise<string>;
128
- execute(toolName: string, argsJson: string): Promise<string>;
129
- hook(name: string, ctxProxy: unknown): Promise<string>;
130
- }
131
- interface ExtensionManagerOptions {
132
- /** WorkerLoader binding for creating sandboxed extension Workers. */
133
- loader: WorkerLoader;
134
- /**
135
- * Durable Object storage for persisting extensions across hibernation.
136
- * If provided, loaded extensions survive DO restarts. Call `restore()`
137
- * on each turn to rebuild in-memory state from storage.
138
- */
139
- storage?: DurableObjectStorage;
140
- /**
141
- * Factory that creates a loopback Fetcher for workspace access, given
142
- * an extension's declared permissions. The returned binding is injected
143
- * into the extension worker's `env.host`.
144
- *
145
- * If not provided, extensions receive no host binding (workspace tools
146
- * will get `null` for the host parameter).
147
- *
148
- * Typically wired up using HostBridgeLoopback via `ctx.exports`:
149
- * ```typescript
150
- * createHostBinding: (permissions, ownContextLabels) =>
151
- * ctx.exports.HostBridgeLoopback({
152
- * props: { agentClassName: "ChatSession", agentId: ctx.id.toString(), permissions, ownContextLabels }
153
- * })
154
- * ```
155
- */
156
- createHostBinding?: (
157
- permissions: ExtensionPermissions,
158
- ownContextLabels: string[]
159
- ) => Fetcher;
160
- }
161
- declare class ExtensionManager {
162
- #private;
163
- constructor(options: ExtensionManagerOptions);
164
- /**
165
- * Load an extension from source code.
166
- *
167
- * The source is a JS object expression defining tools. Each tool has
168
- * `description`, `parameters` (JSON Schema properties), optional
169
- * `required` array, and an `execute` async function.
170
- *
171
- * @returns Summary of the loaded extension including discovered tools.
172
- */
173
- /**
174
- * Restore extensions from DO storage after hibernation.
175
- *
176
- * Idempotent — skips extensions already in memory. Call this at the
177
- * start of each chat turn (e.g. in onChatMessage before getTools).
178
- */
179
- restore(): Promise<void>;
180
- load(manifest: ExtensionManifest, source: string): Promise<ExtensionInfo>;
181
- /**
182
- * Unload an extension, removing its tools from the agent.
183
- * If an onUnload callback is registered, it fires with the
184
- * extension's namespaced context labels so the caller can
185
- * remove context blocks from the Session.
186
- */
187
- unload(name: string): Promise<boolean>;
188
- /**
189
- * Register a callback invoked when an extension is unloaded.
190
- * Think uses this to remove the extension's context blocks from Session.
191
- */
192
- onUnload(
193
- cb: (name: string, contextLabels: string[]) => void | Promise<void>
194
- ): void;
195
- /**
196
- * Get the namespaced context labels for all loaded extensions
197
- * that declare context blocks in their manifests.
198
- */
199
- getContextLabels(): Array<{
200
- extName: string;
201
- label: string;
202
- }>;
203
- /**
204
- * Get extension manifest by name.
205
- */
206
- getManifest(name: string): ExtensionManifest | null;
207
- /**
208
- * Get extensions that subscribe to a specific hook, in load order.
209
- */
210
- getHookSubscribers(hookName: string): Array<{
211
- name: string;
212
- entrypoint: ExtensionEntrypoint;
213
- }>;
214
- /**
215
- * List all loaded extensions.
216
- */
217
- list(): ExtensionInfo[];
218
- /**
219
- * Get AI SDK tools from all loaded extensions.
220
- *
221
- * Tool names are prefixed with the sanitized extension name to avoid
222
- * collisions: e.g. extension "github" with tool "create_pr" → "github_create_pr".
223
- */
224
- getTools(): ToolSet;
225
- }
226
- //#endregion
227
- export {
228
- ExtensionPermissions as a,
229
- ExtensionManifest as i,
230
- ExtensionManagerOptions as n,
231
- ExtensionToolDescriptor as o,
232
- ExtensionInfo as r,
233
- ExtensionManager as t
234
- };
235
- //# sourceMappingURL=manager-rze95KCk.d.ts.map