import type { AgentEvent, CommandDefinition, ContextProvider, Extension, ExtensionEvent, ExtensionLifecycleEventName, InstructionInjector, Skill, StopHook, ToolDefinition } from "./contracts.js"; import { type ContributionRegistries } from "./contributions.js"; import { type MiddlewareRegistry } from "./middleware.js"; import { type PermissionPolicy } from "./security.js"; export type ExtensionEventHandler = (event: ExtensionEvent) => void | Promise; export type ExtensionErrorPolicy = "event" | "throw"; export interface ExtensionLoadPolicy { /** When set, only listed extension names may load. */ readonly allowList?: readonly string[]; /** * Host signature / attestation check. Return false or throw to deny. * Unsigned extensions fail closed when this callback is provided. */ readonly verifySignature?: (extension: Extension) => boolean | Promise; } export interface ExtensionKernelOptions { readonly registries?: ContributionRegistries; readonly middleware?: MiddlewareRegistry; readonly errorPolicy?: ExtensionErrorPolicy; readonly secrets?: readonly (string | undefined)[]; readonly permission?: PermissionPolicy; /** Optional allow-list / signature policy evaluated before `setup`. */ readonly loadPolicy?: ExtensionLoadPolicy; } export interface ExtensionEventBus { on(type: ExtensionLifecycleEventName | string, handler: ExtensionEventHandler): () => void; emit(event: ExtensionEvent): Promise; } export interface LoadedExtension { readonly name: string; /** Remove this extension's registry contributions and middleware/event subscriptions. * Best-effort and idempotent; side effects outside the registries are NOT unwound. */ dispose(): void; } export interface ExtensionKernel { readonly registries: ContributionRegistries; readonly middleware: MiddlewareRegistry; readonly events: ExtensionEventBus; load(extensions: readonly Extension[]): Promise; } export declare function createExtensionEventBus(options?: Pick): ExtensionEventBus; export declare function createExtensionKernel(options?: ExtensionKernelOptions): ExtensionKernel; export interface AgentEventBridgeOptions { /** Bridge-side failure (a source error, or a bus listener that throws under `errorPolicy: "throw"`). * Never rethrown — the bridge must not fail the run it is observing. */ readonly onError?: (error: unknown) => void; } /** * Forward an `AgentEvent` iterable onto the extension bus, one mapped lifecycle event at a time * (plan 106 R2). Handlers run in event order and never in the run's path, so a slow or throwing * listener cannot stall or fail the observed run. Returns an unsubscribe that stops forwarding and * releases the source iterator. */ export declare function forwardAgentEvents(source: AsyncIterable, events: Pick, options?: AgentEventBridgeOptions): () => void; /** Host-owned activation: copy contributed entries into the `createAgent()` * fields that accept plain arrays. Contributions stay inert until the host * passes the returned fields into runtime config. Array slots only — * single-slot builders (`inputBuilder`/`promptBuilder`), `compaction`, * `retry`, provider/model selection, and skill activation remain host-owned * decisions; `commands` are for host RPC surfaces, not an `AgentConfig` field. */ export interface ActivatedKernelConfig { readonly tools: readonly ToolDefinition[]; readonly skills: readonly Skill[]; readonly instructionInjectors: readonly InstructionInjector[]; readonly context: readonly ContextProvider[]; /** Run-end stop hooks (plan 106 R1); pass to `createAgent({ stopHooks })`. */ readonly stopHooks: readonly StopHook[]; /** For host command surfaces (CLI/RPC/UI); not part of `AgentConfig`. */ readonly commands: readonly CommandDefinition[]; /** The kernel middleware registry itself; runs only when passed to runtime config. */ readonly middleware: MiddlewareRegistry; } export declare function activateKernel(kernel: ExtensionKernel): ActivatedKernelConfig;