import { ToolSet } from "ai"; //#region src/extensions/types.d.ts /** * Extension system types. * * Extensions are sandboxed Workers loaded on demand via WorkerLoader. * Each extension provides tools that the agent can use, with controlled * access to the host (workspace, network) via permissions. */ /** * Manifest declaring an extension's identity, permissions, and contributions. * Passed to ExtensionManager.load() alongside the extension source. */ interface ExtensionManifest { /** Unique name for this extension (used as namespace prefix for tools and context). */ name: string; /** Semver version string. */ version: string; /** Human-readable description. */ description?: string; /** Permission declarations — controls what the extension can access. */ permissions?: ExtensionPermissions; /** * Context blocks contributed by this extension. * Labels are namespaced as `{extName}_{label}` at registration. * Currently backed by SQLite storage — extensions write via * `host.setContext()`. Direct RPC delegation is planned for Phase 4. */ context?: Array<{ /** Block label (namespaced as {extName}_{label}). */ label: string /** Human-readable description shown in the system prompt header. */; description?: string; /** Block type determines which tools are generated. * Note: not yet enforced — all blocks use SQLite-backed storage * until bridge providers are implemented (Phase 4). */ type: | "readonly" | "writable" | "skill" | "searchable" /** Maximum token budget for this block. */; maxTokens?: number; }>; /** * Lifecycle hooks this extension provides handlers for. * The extension Worker must expose corresponding RPC methods. */ hooks?: Array< | "beforeTurn" | "beforeToolCall" | "afterToolCall" | "onStepFinish" | "onChunk" >; } interface ExtensionPermissions { /** * Allowed network hosts. If empty or undefined, the extension has * no outbound network access (globalOutbound: null). * If set, the extension inherits the parent Worker's network. * * Note: per-host filtering is not yet enforced at the runtime level. * This field serves as a declaration of intent; actual enforcement * is all-or-nothing via globalOutbound. */ network?: string[]; /** * Workspace access level. * - "none" (default): no workspace access * - "read": can read files and list directories * - "read-write": can read, write, and delete files */ workspace?: "read" | "read-write" | "none"; /** * Context block access. * - `read`: which labels the extension can read ("all" or specific list) * - `write`: which labels the extension can write ("own" = only its manifest-declared labels, or specific list) */ context?: { read?: string[] | "all"; write?: string[] | "own"; }; /** * Message history access. * - "none" (default): no access * - "read": can read conversation history */ messages?: "none" | "read"; /** * Session-level capabilities. * - `sendMessage`: can inject user messages (queued when inside inference loop) * - `metadata`: can read session metadata (message count, etc.) */ session?: { sendMessage?: boolean; metadata?: boolean; }; } /** * Tool descriptor returned by the extension's describe() method. * Uses JSON Schema for input validation. */ interface ExtensionToolDescriptor { name: string; description: string; inputSchema: { type: "object"; properties: Record; required?: string[]; }; } /** * Summary of a loaded extension, returned by ExtensionManager.list(). */ interface ExtensionInfo { name: string; version: string; description?: string; /** Names of tools provided by this extension. */ tools: string[]; /** Namespaced context labels contributed by this extension. */ contextLabels: string[]; permissions: ExtensionPermissions; } //#endregion //#region src/extensions/manager.d.ts interface ExtensionEntrypoint { describe(): Promise; manifest(): Promise; execute(toolName: string, argsJson: string): Promise; hook(name: string, ctxProxy: unknown): Promise; } interface ExtensionManagerOptions { /** WorkerLoader binding for creating sandboxed extension Workers. */ loader: WorkerLoader; /** * Durable Object storage for persisting extensions across hibernation. * If provided, loaded extensions survive DO restarts. Call `restore()` * on each turn to rebuild in-memory state from storage. */ storage?: DurableObjectStorage; /** * Factory that creates a loopback Fetcher for workspace access, given * an extension's declared permissions. The returned binding is injected * into the extension worker's `env.host`. * * If not provided, extensions receive no host binding (workspace tools * will get `null` for the host parameter). * * Typically wired up using HostBridgeLoopback via `ctx.exports`: * ```typescript * createHostBinding: (permissions, ownContextLabels) => * ctx.exports.HostBridgeLoopback({ * props: { agentClassName: "ChatSession", agentId: ctx.id.toString(), permissions, ownContextLabels } * }) * ``` */ createHostBinding?: ( permissions: ExtensionPermissions, ownContextLabels: string[] ) => Fetcher; } declare class ExtensionManager { #private; constructor(options: ExtensionManagerOptions); /** * Load an extension from source code. * * The source is a JS object expression defining tools. Each tool has * `description`, `parameters` (JSON Schema properties), optional * `required` array, and an `execute` async function. * * @returns Summary of the loaded extension including discovered tools. */ /** * Restore extensions from DO storage after hibernation. * * Idempotent — skips extensions already in memory. Call this at the * start of each chat turn (e.g. in onChatMessage before getTools). */ restore(): Promise; load(manifest: ExtensionManifest, source: string): Promise; /** * Unload an extension, removing its tools from the agent. * If an onUnload callback is registered, it fires with the * extension's namespaced context labels so the caller can * remove context blocks from the Session. */ unload(name: string): Promise; /** * Register a callback invoked when an extension is unloaded. * Think uses this to remove the extension's context blocks from Session. */ onUnload( cb: (name: string, contextLabels: string[]) => void | Promise ): void; /** * Get the namespaced context labels for all loaded extensions * that declare context blocks in their manifests. */ getContextLabels(): Array<{ extName: string; label: string; }>; /** * Get extension manifest by name. */ getManifest(name: string): ExtensionManifest | null; /** * Get extensions that subscribe to a specific hook, in load order. */ getHookSubscribers(hookName: string): Array<{ name: string; entrypoint: ExtensionEntrypoint; }>; /** * List all loaded extensions. */ list(): ExtensionInfo[]; /** * Get AI SDK tools from all loaded extensions. * * Tool names are prefixed with the sanitized extension name to avoid * collisions: e.g. extension "github" with tool "create_pr" → "github_create_pr". */ getTools(): ToolSet; } //#endregion export { ExtensionPermissions as a, ExtensionManifest as i, ExtensionManagerOptions as n, ExtensionToolDescriptor as o, ExtensionInfo as r, ExtensionManager as t }; //# sourceMappingURL=manager-dOcdCX4u.d.ts.map