/**
 * Generated by scripts/gen-cordis-api.ts — do not edit by hand; run
 * `pnpm run gen-cordis-api` to regenerate (freshness-gated by
 * `pnpm run verify-cordis-api` in doc-sync).
 *
 * The machine-readable cordis API catalog `cordis_inspect` serves to the
 * model: harness services (summary + structured public method contracts),
 * harness events (mode + structured listener contracts), and the inherited `ctx` API. Produced by
 * the same AST walk as docs/cordis-catalog, so this data and the rendered
 * docs cannot diverge.
 *
 * @module @deepseek-ai/dsh-cordis-client-runner/client/api-catalog
 */

/* jscpd:ignore-start */
/** One named parameter in a Service method or Event listener. */
export interface ApiParameter {
  /** Parameter name from the exact signature. */
  name: string
  /** Source-owned parameter contract. */
  description: string
}

/** One public service member and its source-owned contract. */
export interface ServiceApiMethod {
  /** Public method signature with its body stripped. */
  signature: string
  /** Method purpose and behavior. */
  description: string
  /** Named parameters in signature order. */
  parameters: readonly ApiParameter[]
  /** Non-void result contract when documented. */
  returns?: string
  /** Documented failure conditions. */
  throws?: readonly string[]
}

/** One harness `ctx.<key>` service and its public methods. */
export interface ServiceApiEntry {
  /** The `ctx.<key>` name, e.g. `tools`. */
  key: string
  /** First sentence of the service class JSDoc. */
  summary: string
  /** Complete service description. */
  description: string
  /** Public methods, bodies stripped, in source order. */
  methods: readonly ServiceApiMethod[]
}

/** One harness event: its dispatch mode, exact signature, and listener contract. */
export interface EventApiEntry {
  /** The scoped event name, e.g. `agent/status`. */
  name: string
  /** The dispatch mode from the declaration's `@mode` tag. */
  mode: string
  /** The exact listener signature, whitespace-normalized. */
  signature: string
  /** First sentence of the event JSDoc. */
  summary: string
  /** Complete event description. */
  description: string
  /** Named listener parameters in signature order. */
  parameters: readonly ApiParameter[]
}

/** One inherited (cordis core + loader/hmr/timer) `ctx` member group with its summary. */
export interface InheritedApiEntry {
  /** The `ctx` member name(s), e.g. `ctx.on / ctx.once`. */
  name: string
  /** One-line summary of what the member does. */
  summary: string
}

/** One named type declaration referenced by a Service or Event signature. */
export interface TypeApiEntry {
  /** The exported type/interface name, e.g. `ShellRunResult`. */
  name: string
  /** The full declaration text, comments stripped. */
  declaration: string
}

/** Every harness `ctx.<key>` service, sorted by key. */
export const SERVICE_API: readonly ServiceApiEntry[] = [
  {
    key: 'layout',
    summary: 'The outward layout face (`ctx.layout`): the panel transitions other plugins may trigger — and exactly what a test fake must supply.',
    description: 'The outward layout face (`ctx.layout`): the panel transitions other plugins may trigger — and exactly what a test fake must supply. The attachPanels wiring hook stays on the concrete class (root-entry assembly only).',
    methods: [
      {
        signature: 'toggleSidebar(): void',
        description: 'Toggle the sidebar panel (closed ⟷ contract default width).',
        parameters: [],
      },
      {
        signature: 'openDetails(): void',
        description: 'Open the details panel (no-op when already open).',
        parameters: [],
      },
      {
        signature: 'closeDetails(): void',
        description: 'Close the details panel.',
        parameters: [],
      },
    ],
  },
  {
    key: 'locale',
    summary: 'Dictionary registry plus locale preference.',
    description: 'Dictionary registry plus locale preference. Lookup chain per key: the entry\'s namespace in the active locale -> that namespace\'s zh fallback -> the shared common namespace (active, then zh) -> the key itself (missing text stays visible, fail loud in the UI rather than blank). Reads go through getLocale; writes only through setLocale; continuous sync through the `locale/change` event, or through the LocaleFace getSnapshot/subscribe pair the render machinery consumes (installed via `ctx.slots.installLocale`).',
    methods: [
      {
        signature: 'getLocale(): LocaleSnapshot',
        description: 'Read the current immutable locale snapshot.',
        parameters: [],
        returns: 'the current snapshot (stable reference until the next change).',
      },
      {
        signature: 'getSnapshot(): LocaleSnapshot',
        description: 'LocaleFace getSnapshot: the current snapshot (carries `revision`; stable reference between changes, uSES-safe).',
        parameters: [],
        returns: 'the current snapshot.',
      },
      {
        signature: 'subscribe(fn: () => void): () => void',
        description: 'LocaleFace subscribe: notified on every snapshot change (locale switch or dictionary registration — registrations bump the revision so already rendered outlets pick up late-arriving dictionaries).',
        parameters: [{ name: 'fn', description: 'change callback.' }],
        returns: 'unsubscribe.',
      },
      {
        signature: 'setLocale(id: string): void',
        description: 'Switch the active locale — the only user preference write entry.',
        parameters: [{ name: 'id', description: 'a registered locale id; unknown ids throw.' }],
      },
      {
        signature: 'register<N extends keyof LocaleNamespaceMap & string>(ns: N, dicts: Record<LocaleId, LocaleDictOf<N>>): () => void',
        description: 'Register a declared namespace\'s dictionaries, all locales in one call — the typed form: each dictionary is checked against the namespace\'s LocaleNamespaceMap key union (a missing or extra key is a compile error), and every shipped locale is required (bilingual balance enforced at registration). Duplicate (ns, locale) throws (single occupant; a namespace\'s texts have one owner). Registration bumps the revision so mounted outlets pick up late-arriving dictionaries.',
        parameters: [{ name: 'ns', description: 'a namespace merged into LocaleNamespaceMap.' }, { name: 'dicts', description: 'complete dictionaries keyed by locale id.' }],
        returns: 'disposer removing every locale registered by this call (idempotent).',
      },
      {
        signature: 'register(ns: string, locale: string, dict: LocaleDict): () => void',
        description: 'Single-locale untyped form for namespaces outside the merge table (dynamic composition, tests).',
        parameters: [{ name: 'ns', description: 'namespace.' }, { name: 'locale', description: 'locale tag.' }, { name: 'dict', description: 'dictionary.' }],
        returns: 'disposer (idempotent).',
      },
      {
        signature: 'bind<N extends keyof LocaleNamespaceMap & string>(ns: N): TranslateNS<N>',
        description: 'Bind a declared namespace to a translate function typed to its dictionary key union (plus the shared common vocabulary) — the same key domain the framework-injected `t` seat carries. The returned reference is stable per namespace (repeat binds return the same function), so it can ride inject surfaces without breaking memoization.',
        parameters: [{ name: 'ns', description: 'a namespace merged into LocaleNamespaceMap.' }],
        returns: 'the typed translate function (reads the active locale at call time).',
      },
      {
        signature: 'bind(ns: string): Translate',
        description: 'Untyped form for namespaces outside the merge table (dynamic composition, tests).',
        parameters: [{ name: 'ns', description: 'namespace.' }],
        returns: 'the translate function.',
      },
    ],
  },
  {
    key: 'sessions',
    summary: 'The sessions-service face injected as `ctx.sessions`.',
    description: 'The sessions-service face injected as `ctx.sessions`.',
    methods: [
      {
        signature: 'open(id: SessionId): void',
        description: 'Select a session as current.',
        parameters: [{ name: 'id', description: 'session id (must exist in the list; unknown ids fail loud).' }],
      },
      {
        signature: 'openSubagent(address: SubagentAddress): void',
        description: 'Open a healthy catalog child through its exact direct-parent address.',
        parameters: [{ name: 'address', description: 'catalog-derived parent and child ids.' }],
      },
      {
        signature: 'setSubagentCatalogOpen(parentSessionId: SessionId, open: boolean): void',
        description: 'Mark whether a catalog menu is consuming live membership updates.',
        parameters: [{ name: 'parentSessionId', description: 'catalog owner.' }, { name: 'open', description: 'current menu state.' }],
      },
      {
        signature: 'refreshSubagents(parentSessionId: SessionId): Promise<void>',
        description: 'Refresh one direct-child catalog.',
        parameters: [{ name: 'parentSessionId', description: 'catalog owner.' }],
        returns: 'completion of the current or newly started refresh.',
      },
      {
        signature: 'search( query: string, signal: AbortSignal, ): Promise<RpcResult<{ items: SessionSearchResultItem[]; hasMore: boolean }>>',
        description: 'Search the Host\'s visible message-content index. Results stay request-local; the list snapshot remains the metadata authority.',
        parameters: [{ name: 'query', description: 'non-blank literal phrase.' }, { name: 'signal', description: 'cancellation for a superseded search.' }],
        returns: 'bounded results, or a business/transport error.',
      },
      {
        signature: 'fork(opts: { sessionId: SessionId; atSeq?: number; increaseTitle?: boolean }): Promise<SessionId>',
        description: 'Fork a session from a completed-turn prefix of the source; on resolution the child is in the list store and `open()` can target it.',
        parameters: [{ name: 'opts', description: 'source session id, the optional event seq anchoring the cut (the boundary is the first turn/end at or after it; an in-log anchor in an open turn is unavailable rather than clipped backward), and whether to increment an inherited durable title before resolving.' }],
        returns: 'the child session id.',
        throws: ['when the fork fails, or when a requested child-title rename fails after creation.'],
      },
      {
        signature: 'scope(id: SessionId): AgentContext | undefined',
        description: 'Resolve an Agent-scoped context view (use-and-discard).',
        parameters: [{ name: 'id', description: 'session id.' }],
        returns: 'scoped ctx, or undefined for a session neither listed nor already scoped.',
      },
      {
        signature: 'binding(id: SessionId): SessionBinding | undefined',
        description: 'Resolve the stable session binding (scope-addressed assembly feed).',
        parameters: [{ name: 'id', description: 'session id.' }],
        returns: 'binding, or undefined for a session neither listed nor already scoped.',
      },
    ],
  },
  {
    key: 'slots',
    summary: 'cordis Service layer of the slot system; see the module doc for the split with SlotCore.',
    description: 'cordis Service layer of the slot system; see the module doc for the split with SlotCore.',
    methods: [
      {
        signature: 'declare readonly register: SlotCore[\'register\']',
        description: 'The single registration API. The typed face IS the core\'s register (both overloads reused verbatim — one authority, no structural copy; see SlotCore.register for children declaration, store seat, inject face, load-time validation, and the unload cascade). This layer adds: disposal through the caller\'s ctx.effect (fiber unload = cascade), exclusive-factory minting (`store: createXxxStore` becomes a per-entry handle), the registrant diagnostics stamp, and store-instance lifecycle on the entry axis.\n\nDeclared here, implemented by prototype assignment below the class: it MUST stay a prototype method (never an instance arrow) — the cordis service proxy binds `this.ctx` to the CALLER\'s context at call time, which is what routes the effect (and the unload cascade) into the caller\'s fiber. An arrow property would freeze `this` to the service\'s own root ctx and silently break per-plugin disposal.',
        parameters: [],
      },
      {
        signature: 'inject(key: keyof SlotMap & string, callback: () => SlotInjectionEffect): () => void',
        description: 'Install an effect for each declaration lifetime of a slot. The callback runs synchronously when the declaration already exists; otherwise it runs inside the declaring `register()` call after the declaration is committed. Collapse disposes the effect and a later declaration runs it again. Callback effects are synchronous disposers; iterable effects install transactionally and dispose in reverse order. The controller belongs to the caller\'s fiber, so plugin unload cancels a pending wait and removes any active contribution.',
        parameters: [{ name: 'key', description: 'declared SlotMap key to depend on.' }, { name: 'callback', description: 'creates one disposer or an iterable of disposers.' }],
        returns: 'idempotent disposer for the wait and active effect.',
        throws: ['callback setup failures synchronously when the slot is already declared.'],
      },
    ],
  },
  {
    key: 'theme',
    summary: 'Theme registry and preference owner.',
    description: 'Theme registry and preference owner. `light`/`dark` are built in (the base stylesheets carry both palettes); third-party themes register alias-layer overrides. Reads go through getTheme; preference writes only through setTheme; continuous sync only through the `theme/change` event. overrideTokens stacks partial token layers over the active theme without touching the registry. The service holds the `prefers-color-scheme` media query (environment sensing, not presentation) and re-emits when the OS scheme flips while the preference is `system`.',
    methods: [
      {
        signature: 'getTheme(): ThemeSnapshot',
        description: 'Read the current immutable theme snapshot.',
        parameters: [],
        returns: 'the current snapshot (stable reference until the next change).',
      },
      {
        signature: 'setTheme(id: string): void',
        description: 'Switch the theme preference — the only user preference write entry. Built-in preferences are written through the settings scope and every accepted value emits `theme/change`.',
        parameters: [{ name: 'id', description: 'a registered theme id or `system`; unknown ids throw.' }],
      },
      {
        signature: 'register(definition: ThemeDefinition): () => void',
        description: 'Register a theme. Duplicate id throws (single occupant per id; the built-in pair counts; `system` is a preference, not a registrable id).',
        parameters: [{ name: 'definition', description: 'theme id, colorScheme, and alias-token overrides.' }],
        returns: 'disposer. Disposing the theme backing the active preference resets the preference to the default so the UI never keeps tokens of an unregistered theme.',
      },
      {
        signature: 'overrideTokens(source: string, tokens: ThemeTokenOverrides): () => void',
        description: 'Stack a token override layer on top of the active theme — the token-level analogue of slot shading: the base theme stays untouched, layers compose in seq order with later layers winning per-token, and removing a layer restores whatever it covered. Calling again with the same source replaces that source\'s whole layer and restacks it on top (effect re-registration semantics). Emits `theme/change` with the recomposed snapshot.',
        parameters: [{ name: 'source', description: 'layer identity; one layer per source (dynamic packages pass their package id — the façade pins it, so it also names the layer\'s origin for inspection).' }, { name: 'tokens', description: 'token-name → `{ light, dark }` value pairs. Validated at runtime (model-authored callers reach this boundary with untyped JS); a bare string value throws a teaching error.' }],
        returns: 'disposer removing exactly the layer this call created; a no-op once the source has re-overridden (the newer layer is not torn down).',
      },
    ],
  },
  {
    key: 'timer',
    summary: 'Disposable timer helpers mixed into Cordis contexts.',
    description: 'Disposable timer helpers mixed into Cordis contexts.',
    methods: [
      {
        signature: 'timeout(callback: () => void, delay: number): () => void',
        description: 'Run a callback once and return its disposer.',
        parameters: [],
      },
      {
        signature: 'timeout(delay: number): Promise<void>',
        description: 'Resolve after a delay; disposal rejects the pending promise.',
        parameters: [],
      },
      {
        signature: 'interval(callback: () => void, delay: number): () => void',
        description: 'Run a callback repeatedly and return its disposer.',
        parameters: [],
      },
      {
        signature: 'interval<R = any>(delay: number): AsyncIterableIterator<void, R, void>',
        description: 'Return an async iterator of timer ticks.',
        parameters: [],
      },
      {
        signature: 'throttle<F extends (...args: any[]) => void>(callback: F, delay: number, noTrailing?: boolean): F & { dispose: () => void }',
        description: 'Return a throttled function whose timer is disposed with the current fiber.',
        parameters: [],
      },
      {
        signature: 'debounce<F extends (...args: any[]) => void>(callback: F, delay: number): F & { dispose: () => void }',
        description: 'Return a debounced function whose timer is disposed with the current fiber.',
        parameters: [],
      },
    ],
  },
  {
    key: 'workspaces',
    summary: 'The workspaces-service face injected as `ctx.workspaces`.',
    description: 'The workspaces-service face injected as `ctx.workspaces`.',
    methods: [
      {
        signature: 'connectWorkspace(workspaceId: WorkspaceId): Promise<SessionId>',
        description: 'Connect a Workspace to its reusable or freshly created blank session.',
        parameters: [{ name: 'workspaceId', description: 'target workspace.' }],
        returns: 'the connected session id.',
      },
      {
        signature: 'startSession(workspaceId?: WorkspaceId): void',
        description: 'The New Session flow: connect the explicit, current-Session, or recent Workspace and open the resulting session; failures surface on the session list state.',
        parameters: [{ name: 'workspaceId', description: 'explicit target; omitted inherits the current Session\'s Workspace before falling back to the recency projection.' }],
      },
      {
        signature: 'create(input: { path: string }): Promise<WorkspaceView>',
        description: 'Register an existing path as a Workspace.',
        parameters: [{ name: 'input', description: 'the Host create payload.' }],
        returns: 'the created or idempotently resolved Workspace.',
      },
      {
        signature: 'pickDirectory(): Promise<string | null>',
        description: 'Open the Host\'s native directory picker.',
        parameters: [],
        returns: 'the selected path, or null when the user cancelled.',
      },
      {
        signature: 'listDirectory(path?: string, signal?: AbortSignal): Promise<DirectoryListing>',
        description: 'List one directory level through the Host\'s `browse` capability.',
        parameters: [{ name: 'path', description: 'absolute directory to list; absent lists the Host home directory.' }, { name: 'signal', description: 'aborts the wire request (and the Host\'s scan) when the caller supersedes it.' }],
        returns: 'the level\'s listing with breadcrumb ancestry.',
      },
      {
        signature: 'createDirectory(path: string, name: string): Promise<string>',
        description: 'Create one child directory through the Host\'s `browse` capability.',
        parameters: [{ name: 'path', description: 'absolute existing parent directory.' }, { name: 'name', description: 'single non-blank path segment.' }],
        returns: 'the created directory\'s absolute path.',
      },
      {
        signature: 'openPath(path: string): Promise<void>',
        description: 'Open a filesystem path with the Host operating system\'s default application.',
        parameters: [{ name: 'path', description: 'absolute or host-resolvable path.' }],
      },
      {
        signature: 'rename(workspaceId: WorkspaceId, title: string): Promise<WorkspaceView>',
        description: 'Rename a Workspace.',
        parameters: [{ name: 'workspaceId', description: 'target workspace.' }, { name: 'title', description: 'the new display title.' }],
        returns: 'the updated Workspace view.',
      },
      {
        signature: 'delete(workspaceId: WorkspaceId): Promise<void>',
        description: 'Delete a Workspace (its sessions fall back to the unaccounted group).',
        parameters: [{ name: 'workspaceId', description: 'target workspace.' }],
      },
      {
        signature: 'insertSessionBefore(workspaceId: WorkspaceId, sessionId: SessionId, beforeSessionId?: SessionId): Promise<WorkspaceView>',
        description: 'Move an accounted session within/into a Workspace\'s ordered list.',
        parameters: [{ name: 'workspaceId', description: 'target workspace.' }, { name: 'sessionId', description: 'accounted session to move.' }, { name: 'beforeSessionId', description: 'accounted anchor to insert before; omitted appends.' }],
        returns: 'the updated Workspace view.',
      },
      {
        signature: 'archiveSession(sessionId: SessionId): Promise<void>',
        description: 'Archive a session into the registry-global set (hidden from grouping surfaces; session log and accounting slot remain). Archiving the current session clears the selection into the New Session view state.',
        parameters: [{ name: 'sessionId', description: 'session to archive.' }],
      },
    ],
  },
]

/** Every harness event, sorted by name. */
export const EVENT_API: readonly EventApiEntry[] = [
  {
    name: 'connection/reset',
    mode: 'emit',
    signature: '\'connection/reset\'(): void',
    summary: 'A connection generation was (re-)established.',
    description: 'A connection generation was (re-)established. Wire-derived caches must treat their state as stale and repull (commands directory; the queue mirrors reset themselves through the session resync path).',
    parameters: [],
  },
  {
    name: 'locale/change',
    mode: 'emit',
    signature: '\'locale/change\'(snapshot: LocaleSnapshot): void',
    summary: 'The active locale switched.',
    description: 'The active locale switched. Dictionary registrations do NOT emit this event (listeners may re-register slots in response, and boot registers one namespace per package); continuous render refresh rides the LocaleFace revision instead.',
    parameters: [{ name: 'snapshot', description: 'Current immutable locale snapshot.' }],
  },
  {
    name: 'slots/changed',
    mode: 'emit',
    signature: '\'slots/changed\'(key: string): void',
    summary: 'A slot\'s definition or registration set changed.',
    description: 'A slot\'s definition or registration set changed.',
    parameters: [{ name: 'key', description: 'the mutated SlotMap key.' }],
  },
  {
    name: 'theme/change',
    mode: 'emit',
    signature: '\'theme/change\'(snapshot: ThemeSnapshot): void',
    summary: 'Theme state changed (preference switched, registry updated, or the OS color scheme changed while the preference is `system`).',
    description: 'Theme state changed (preference switched, registry updated, or the OS color scheme changed while the preference is `system`).',
    parameters: [{ name: 'snapshot', description: 'Current immutable theme snapshot.' }],
  },
]

/** Shapes of every exported type the Service and Event signatures reference (transitively), sorted by name. */
export const TYPE_API: readonly TypeApiEntry[] = [
  {
    name: 'ActionsDecl',
    declaration: 'export type ActionsDecl<T> = Record<string, (draft: T, ...params: any[]) => void>;',
  },
  {
    name: 'AgentContext',
    declaration: 'export type AgentContext = Omit<Context, \'remote\'> & {\n    readonly remote: TypertClientRemote & TypertRemoteScopeApi<\'agent\'>;\n};',
  },
  {
    name: 'AssistantBlock',
    declaration: 'export type AssistantBlock = {\n    kind: \'text\';\n    text: string;\n} | {\n    kind: \'reasoning\';\n    text: string;\n} | {\n    kind: \'image\';\n    attachment: ImageAttachmentRef;\n} | {\n    kind: \'tool-call\';\n    callId: string;\n    name: string;\n    argsRaw: string;\n} | {\n    kind: \'other\';\n    block: unknown;\n};',
  },
  {
    name: 'AssistantMessageNode',
    declaration: 'export interface AssistantMessageNode {\n    kind: \'assistant\';\n    seq: number;\n    messageId?: MessageId;\n    time: number;\n    turn: number;\n    step: number;\n    blocks: readonly AssistantBlock[];\n    usage?: unknown;\n    provenance?: AssistantProvenanceView;\n    requestConfig?: AssistantRequestConfig;\n    timing?: AssistantTiming;\n    interrupted?: true;\n}',
  },
  {
    name: 'AssistantProvenanceView',
    declaration: 'export interface AssistantProvenanceView {\n    provider: string;\n    model: string;\n}',
  },
  {
    name: 'AssistantRequestConfig',
    declaration: 'export interface AssistantRequestConfig {\n    provider: string;\n    model: string;\n    purpose?: string;\n    thinking?: string;\n    reasoningEffort?: string;\n    temperature?: number;\n    maxTokens?: number;\n    stop?: readonly string[];\n}',
  },
  {
    name: 'AssistantTiming',
    declaration: 'export interface AssistantTiming {\n    stepStartTime: number | null;\n    firstTokenTime: number | null;\n    completedTime: number;\n}',
  },
  {
    name: 'BakedActions',
    declaration: 'export type BakedActions<T, A extends ActionsDecl<T>> = {\n    [K in keyof A]: A[K] extends (draft: T, ...params: infer P) => void ? (...params: P) => void : never;\n};',
  },
  {
    name: 'BoundActions',
    declaration: 'export type BoundActions<H> = H extends StoreHandle<infer T, infer A> ? BakedActions<T, A> : never;',
  },
  {
    name: 'ChainKeysOf',
    declaration: 'export type ChainKeysOf<S extends keyof SlotMap & string> = S extends unknown ? (SlotMap[S][\'kind\'] extends \'chain\' ? S : never) : never;',
  },
  {
    name: 'ChainRenderOpts',
    declaration: 'export interface ChainRenderOpts {\n    fallback?: ReactNode;\n    overlay?: boolean;\n}',
  },
  {
    name: 'ChatConversationViewNode',
    declaration: 'export interface ChatConversationViewNode extends ConversationViewNode {\n    readonly target: \'chat\';\n    readonly anchorSeq: number;\n    readonly location: ConversationLocation;\n    readonly visibility: \'visible\' | \'hidden\';\n}',
  },
  {
    name: 'ChatLocationNodeIndex',
    declaration: 'export interface ChatLocationNodeIndex {\n    getTurn(turn: number): readonly string[];\n    getStep(turn: number, step: number): readonly string[];\n}',
  },
  {
    name: 'ChatNodeStore',
    declaration: 'export interface ChatNodeStore {\n    get(key: string): ChatConversationViewNode | undefined;\n    values(): readonly ChatConversationViewNode[];\n}',
  },
  {
    name: 'ChatSnapshot',
    declaration: 'export interface ChatSnapshot {\n    readonly order: readonly string[];\n    readonly nodes: ChatNodeStore;\n    readonly locations: ChatLocationNodeIndex;\n    readonly timeline: ConversationTimelineSnapshot;\n    readonly legacy: LegacyConversationSlice;\n}',
  },
  {
    name: 'ChildrenDecl',
    declaration: 'export type ChildrenDecl = {\n    [P in keyof SlotMap & string]?: SlotSpec<SlotMap[P]>;\n};',
  },
  {
    name: 'CommandNode',
    declaration: 'export interface CommandNode {\n    kind: \'command\';\n    seq: number;\n    time: number;\n    commandId: CommandId;\n    name: string | null;\n    args: string | null;\n    outcome: {\n        kind: \'success\' | \'error\';\n        text?: string;\n        sourceEventSeq?: number;\n    } | null;\n}',
  },
  {
    name: 'CommonKeyOf',
    declaration: 'export type CommonKeyOf = LocaleNamespaceMap extends {\n    common: infer C;\n} ? C & string : never;',
  },
  {
    name: 'CompactionSummaryNode',
    declaration: 'export interface CompactionSummaryNode {\n    kind: \'compaction\';\n    seq: number;\n    time: number;\n    summary: string | null;\n    summaryEventSeq: number | null;\n    shadowedItemCount: number | null;\n    shadowedTokenCount: number | null;\n}',
  },
  {
    name: 'ComposedProps',
    declaration: 'export type ComposedProps<K extends keyof SlotMap & string, EntryKey extends EntryKeyOf<K>, S extends keyof SlotMap & string, H, I extends object, M = never, N = undefined> = PropsRuntime<K, EntryKey> & PropsRenderSlots<S> & PropsStore<H> & InjectFace<I> & MatchedShare<SlotMap[K], M> & PropsLocale<N>;',
  },
  {
    name: 'ComposerPhase',
    declaration: 'export type ComposerPhase = \'blank\' | \'engaging\' | \'active\';',
  },
  {
    name: 'ContextMessageNode',
    declaration: 'export interface ContextMessageNode {\n    kind: \'context\';\n    seq: number;\n    time: number;\n    content: readonly ContentBlock[];\n    source: unknown;\n    provenance: ContextProvenanceView;\n    form: KnownContextForm | null;\n}',
  },
  {
    name: 'ContextProvenanceView',
    declaration: 'export interface ContextProvenanceView {\n    role: ContextRole;\n    label: string | null;\n}',
  },
  {
    name: 'ContextRole',
    declaration: 'export type ContextRole = \'inject\' | \'recall\';',
  },
  {
    name: 'ConversationLocation',
    declaration: 'export type ConversationLocation = {\n    readonly kind: \'session\';\n} | {\n    readonly kind: \'turn\';\n    readonly turn: TurnLocation;\n} | {\n    readonly kind: \'step\';\n    readonly turn: TurnLocation;\n    readonly step: StepLocation;\n} | {\n    readonly kind: \'unresolved\';\n};',
  },
  {
    name: 'ConversationLocationDataStore',
    declaration: 'export interface ConversationLocationDataStore<DataMap extends object> {\n    get<Key extends keyof DataMap & string>(key: Key): Readonly<DataMap[Key]> | undefined;\n}',
  },
  {
    name: 'ConversationNode',
    declaration: 'export type ConversationNode = UserMessageNode | AssistantMessageNode | SteeringMessageNode | ContextMessageNode | ModelRetryNode | TurnErrorNode | TurnMaxTokensNode | ToolResultNode | CommandNode | CompactionSummaryNode | UnknownSurfaceNode;',
  },
  {
    name: 'ConversationSnapshot',
    declaration: 'export interface ConversationSnapshot {\n    sessionId: SessionId;\n    views: ConversationViewSnapshotStore;\n    chat: ChatSnapshot;\n    nodes: readonly ConversationNode[];\n    turnTimings: ReadonlyMap<number, {\n        readonly startTime: number;\n        readonly endTime?: number;\n    }>;\n    turnEnds: ReadonlyMap<number, number>;\n    partial: PartialAssistant | null;\n    runningCalls: readonly RunningToolCall[];\n    pending: readonly PendingInteraction[];\n    queue: readonly QueuedMessage[];\n    running: boolean;\n    subagent: {\n        address: SubagentAddress;\n        parentAvailable: boolean;\n    } | null;\n    composerPhase: ComposerPhase;\n    removed: boolean;\n    openState: OpenState;\n    openError: RpcError | null;\n    hasMore: boolean;\n    loadingOlder: boolean;\n    promptError: PromptError | null;\n    blank: boolean;\n    lastAgentError: string | null;\n}',
  },
  {
    name: 'ConversationStepDataMap',
    declaration: 'export interface ConversationStepDataMap {\n}',
  },
  {
    name: 'ConversationTimelineSnapshot',
    declaration: 'export interface ConversationTimelineSnapshot {\n    readonly turnOrder: readonly number[];\n    readonly turns: ReadonlyMap<number, TurnLocation>;\n}',
  },
  {
    name: 'ConversationTurnDataMap',
    declaration: 'export interface ConversationTurnDataMap {\n}',
  },
  {
    name: 'ConversationViewNode',
    declaration: 'export interface ConversationViewNode {\n    readonly key: string;\n    readonly kind: string;\n    readonly id: string;\n    readonly target: string;\n    readonly data: unknown;\n}',
  },
  {
    name: 'ConversationViewSnapshotMap',
    declaration: 'export interface ConversationViewSnapshotMap {\n}',
  },
  {
    name: 'ConversationViewSnapshotStore',
    declaration: 'export interface ConversationViewSnapshotStore {\n    get<Target extends Extract<keyof ConversationViewSnapshotMap, string>>(target: Target): ConversationViewSnapshotMap[Target] | undefined;\n}',
  },
  {
    name: 'EntryKeyOf',
    declaration: 'export type EntryKeyOf<K extends keyof SlotMap & string> = SlotMap[K] extends {\n    kind: \'keyed\';\n    keyProps: infer P extends object;\n} ? keyof P & string : string;',
  },
  {
    name: 'GlobalStandardProps',
    declaration: 'export interface GlobalStandardProps {\n}',
  },
  {
    name: 'HandleOf',
    declaration: 'export type HandleOf<H> = H extends () => infer R ? R : H;',
  },
  {
    name: 'HooksSources',
    declaration: 'export type HooksSources = Record<string, HostObservable<unknown>>;',
  },
  {
    name: 'HostObservable',
    declaration: 'export interface HostObservable<T> {\n    getSnapshot(): T;\n    subscribe(fn: () => void): () => void;\n}',
  },
  {
    name: 'InjectFace',
    declaration: 'export type InjectFace<I extends object> = I extends {\n    hooks: infer HS extends HooksSources;\n} ? Omit<I, \'hooks\'> & PropsHooks<HS> : I;',
  },
  {
    name: 'InjectParams',
    declaration: 'export type InjectParams<K extends keyof SlotMap & string, H> = ScopeOf<K> extends \'session\' ? ([\n    H\n] extends [\n    StoreDecl\n] ? [\n    sessionId: SessionIdOf,\n    actions: BoundActions<HandleOf<H>>\n] : [\n    sessionId: SessionIdOf\n]) : ScopeOf<K> extends \'session-maybe\' ? ([\n    H\n] extends [\n    StoreDecl\n] ? [\n    sessionId: SessionIdOf | undefined,\n    actions: BoundActions<HandleOf<H>> | undefined\n] : [\n    sessionId: SessionIdOf | undefined\n]) : ([\n    H\n] extends [\n    StoreDecl\n] ? [\n    actions: BoundActions<HandleOf<H>>\n] : [\n]);',
  },
  {
    name: 'ISession',
    declaration: 'export interface ISession {\n    readonly sessionId: SessionId;\n    readonly projections: ProjectionsFace;\n    prompt(content: PromptContentPart[], mode: \'queue\' | \'steer\'): Promise<RpcResult<{\n        accepted: true;\n    }>>;\n    readAttachment(attachmentId: AttachmentIdType): Promise<RpcResult<{\n        attachment: ImageAttachmentRef;\n        data: Uint8Array;\n    }>>;\n    updateQueue(itemId: MessageId, action: QueueAction): Promise<RpcResult<{\n        accepted: true;\n    }>>;\n    cancel(): Promise<RpcResult<{\n        accepted: true;\n    }>>;\n    rename(title: string): Promise<RpcResult<{\n        title: string;\n        seq: number;\n    }>>;\n    loadOlder(): Promise<void>;\n    command(line: string): Promise<RemoteResult<{\n        matched: boolean;\n    }>>;\n}',
  },
  {
    name: 'KeyPropsOf',
    declaration: 'export type KeyPropsOf<K extends keyof SlotMap & string, EntryKey extends EntryKeyOf<K>> = SlotMap[K] extends {\n    kind: \'keyed\';\n    keyProps: infer P extends object;\n} ? EntryKey extends keyof P ? P[EntryKey] extends object ? P[EntryKey] : never : never : object;',
  },
  {
    name: 'KnownContextForm',
    declaration: 'export type KnownContextForm = typeof KNOWN_FORMS[number];',
  },
  {
    name: 'LegacyConversationSlice',
    declaration: 'export interface LegacyConversationSlice {\n    readonly nodes: readonly ConversationNode[];\n    readonly turnTimings: ReadonlyMap<number, {\n        readonly startTime: number;\n        readonly endTime?: number;\n    }>;\n    readonly turnEnds: ReadonlyMap<number, number>;\n    readonly partial: PartialAssistant | null;\n    readonly runningCalls: readonly RunningToolCall[];\n}',
  },
  {
    name: 'LocaleDefinition',
    declaration: 'export interface LocaleDefinition {\n    id: LocaleId;\n    label: string;\n}',
  },
  {
    name: 'LocaleDict',
    declaration: 'export type LocaleDict = Record<string, string>;',
  },
  {
    name: 'LocaleDictOf',
    declaration: 'export type LocaleDictOf<N extends keyof LocaleNamespaceMap & string> = Record<LocaleNamespaceMap[N] & string, string>;',
  },
  {
    name: 'LocaleId',
    declaration: 'export type LocaleId = typeof LOCALE_IDS[number];',
  },
  {
    name: 'LocaleKeysOf',
    declaration: 'export type LocaleKeysOf<N extends keyof LocaleNamespaceMap & string> = (LocaleNamespaceMap[N] & string) | CommonKeyOf;',
  },
  {
    name: 'LocaleNamespaceMap',
    declaration: 'export interface LocaleNamespaceMap {\n}',
  },
  {
    name: 'LocaleSnapshot',
    declaration: 'export interface LocaleSnapshot {\n    active: LocaleId;\n    locales: readonly LocaleDefinition[];\n    revision: number;\n}',
  },
  {
    name: 'MatchedShare',
    declaration: 'export type MatchedShare<E extends SlotEntryDef, M> = E[\'kind\'] extends \'chain\' ? {\n    matched: M;\n} : object;',
  },
  {
    name: 'ModelRetryNode',
    declaration: 'export type ModelRetryNode = LlmRetryEventData & {\n    kind: \'model-retry\';\n    seq: number;\n    time: number;\n    retryState: \'scheduled\' | \'started\' | \'cancelled\';\n};',
  },
  {
    name: 'ObservableSnapshot',
    declaration: 'export interface ObservableSnapshot<T> {\n    getSnapshot(): T;\n    subscribe(fn: () => void): () => void;\n}',
  },
  {
    name: 'OpenState',
    declaration: 'export type OpenState = \'cold\' | \'loading\' | \'open\' | \'error\';',
  },
  {
    name: 'OwnerOf',
    declaration: 'export type OwnerOf<K extends keyof SlotMap & string> = SlotMap[K] extends {\n    owner: infer O extends object;\n} ? O : object;',
  },
  {
    name: 'PartialAssistant',
    declaration: 'export interface PartialAssistant {\n    turn: number;\n    step: number;\n    blocks: readonly AssistantBlock[];\n}',
  },
  {
    name: 'PendingInteraction',
    declaration: 'export type PendingInteraction = {\n    [K in PendingKind]: PendingWait<K>;\n}[PendingKind];',
  },
  {
    name: 'PendingKind',
    declaration: 'export type PendingKind = keyof PendingPayloads;',
  },
  {
    name: 'PendingPayloads',
    declaration: 'export interface PendingPayloads {\n    approval: Omit<Extract<MuxFrame, {\n        type: \'approval/requested\';\n    }>, \'type\' | \'sessionId\'>;\n    question: Omit<Extract<MuxFrame, {\n        type: \'question/requested\';\n    }>, \'type\' | \'sessionId\'>;\n}',
  },
  {
    name: 'PendingWait',
    declaration: 'export class PendingWait<K extends PendingKind = PendingKind> {\n    readonly kind: K;\n    readonly key: string;\n    readonly sessionId: SessionId;\n    readonly payload: PendingPayloads[K];\n    constructor(kind: K, rpcId: RpcId, sessionId: SessionId, payload: PendingPayloads[K], respond: (message: ClientResponse) => Promise<RpcReceipt>);\n    respond(result: ClientResponse[\'result\']): Promise<RpcReceipt>;\n    markSettled(): void;\n}',
  },
  {
    name: 'ProjectionsFace',
    declaration: 'export interface ProjectionsFace {\n    faceOf(key: string): ObservableSnapshot<unknown>;\n}',
  },
  {
    name: 'PromptError',
    declaration: 'export interface PromptError {\n    op: \'send\' | \'stop\';\n    error: RpcError;\n}',
  },
  {
    name: 'PropsHooks',
    declaration: 'export type PropsHooks<HS extends HooksSources> = {\n    [N in keyof HS & string as `use${Capitalize<N>}`]: SnapshotSelectorHook<HS[N] extends HostObservable<infer T> ? T : never>;\n};',
  },
  {
    name: 'PropsLocale',
    declaration: 'export type PropsLocale<N> = N extends keyof LocaleNamespaceMap & string ? {\n    t: TranslateNS<N>;\n} : object;',
  },
  {
    name: 'PropsRenderSlots',
    declaration: 'export type PropsRenderSlots<S extends keyof SlotMap & string> = {\n    renderSlot: RenderSlotFn<Exclude<S, ChainKeysOf<S>>>;\n    readonly __renders?: ((key: S) => void) | undefined;\n} & ([\n    ChainKeysOf<S>\n] extends [\n    never\n] ? object : {\n    renderSlotChain: <K extends ChainKeysOf<S>>(key: K, owner: OwnerOf<K>, opts?: ChainRenderOpts) => ReactNode;\n}) & (\'session\' extends ScopeOf<S> ? {\n    SessionProvider: SessionProviderComponent;\n} : object);',
  },
  {
    name: 'PropsRuntime',
    declaration: 'export type PropsRuntime<K extends keyof SlotMap & string, EntryKey extends EntryKeyOf<K> = EntryKeyOf<K>> = OwnerOf<K> & KeyPropsOf<K, EntryKey> & SlotInjectFace<SlotInjectOf<K>> & (ScopeOf<K> extends \'session\' ? SessionStandardProps : ScopeOf<K> extends \'session-maybe\' ? SessionMaybeStandardProps : object) & GlobalStandardProps;',
  },
  {
    name: 'PropsSlotHooks',
    declaration: 'export type PropsSlotHooks<HS extends object> = {\n    [N in keyof HS & string as `use${Capitalize<N>}`]: BoundHookOf<HS[N]>;\n};',
  },
  {
    name: 'PropsStore',
    declaration: 'export type PropsStore<H> = H extends StoreHandle<infer T, infer A> ? {\n    useStore: SnapshotSelectorHook<T>;\n    actions: BakedActions<T, A>;\n} : object;',
  },
  {
    name: 'QueueAction',
    declaration: 'export type QueueAction = Parameters<SessionFace[\'updateQueue\']>[1];',
  },
  {
    name: 'RunningToolCall',
    declaration: 'export interface RunningToolCall {\n    callId: string;\n    name: string;\n    argsRaw: string;\n    turn: number;\n    step: number;\n    time: number;\n    callView: ToolCallView | null;\n    subCalls: readonly ToolCallBlock[];\n}',
  },
  {
    name: 'ScopeOf',
    declaration: 'export type ScopeOf<K extends keyof SlotMap & string> = SlotMap[K][\'scope\'];',
  },
  {
    name: 'SessionAreaProps',
    declaration: 'export interface SessionAreaProps {\n    empty?: (() => ReactNode) | undefined;\n    children: (sessionId: SessionIdOf) => ReactNode;\n}',
  },
  {
    name: 'SessionBinding',
    declaration: 'export interface SessionBinding {\n    readonly sessionId: SessionId;\n    readonly session: SessionFace;\n    readonly ctx: AgentContext;\n}',
  },
  {
    name: 'SessionFace',
    declaration: 'export type SessionFace = ISession & ObservableSnapshot<ConversationSnapshot>;',
  },
  {
    name: 'SessionIdOf',
    declaration: 'export type SessionIdOf = SessionStandardProps extends {\n    sessionId: infer S;\n} ? S : string;',
  },
  {
    name: 'SessionMaybeStandardProps',
    declaration: 'export interface SessionMaybeStandardProps {\n}',
  },
  {
    name: 'SessionProviderComponent',
    declaration: 'export type SessionProviderComponent = (props: SessionAreaProps) => ReactNode;',
  },
  {
    name: 'SessionSearchResultItem',
    declaration: 'export interface SessionSearchResultItem {\n    sessionId: SessionId;\n    snippet: string;\n}',
  },
  {
    name: 'SessionStandardProps',
    declaration: 'export interface SessionStandardProps {\n}',
  },
  {
    name: 'SlotComponent',
    declaration: 'export type SlotComponent<P> = (props: P) => ReactNode;',
  },
  {
    name: 'SlotCore',
    declaration: 'export class SlotCore {\n    constructor();\n    register<K extends keyof SlotMap & string, const EntryKey extends EntryKeyOf<K> = EntryKeyOf<K>, const D extends ChildrenDecl = Record<never, never>, H extends StoreDecl | undefined = undefined, M = never, N extends (keyof LocaleNamespaceMap & string) | undefined = undefined, C extends SlotComponent<never> = SlotComponent<never>>(options: BaseOptions<K, EntryKey, D, H, M, N> & {\n        inject?: undefined;\n    }, component: C & SlotComponent<ComposedProps<K, NoInfer<EntryKey>, keyof NoInfer<D> & keyof SlotMap & string, HandleOf<NoInfer<H>>, object, NoInfer<M>, NoInfer<N>>> & RendersCheck<C, D>): () => void;\n    register<K extends keyof SlotMap & string, I extends object, const EntryKey extends EntryKeyOf<K> = EntryKeyOf<K>, const D extends ChildrenDecl = Record<never, never>, H extends StoreDecl | undefined = undefined, M = never, N extends (keyof LocaleNamespaceMap & string) | undefined = undefined, C extends SlotComponent<never> = SlotComponent<never>>(options: BaseOptions<K, EntryKey, D, H, M, N> & {\n        inject: (...args: InjectParams<K, H>) => I;\n    }, component: C & SlotComponent<ComposedProps<K, NoInfer<EntryKey>, keyof NoInfer<D> & keyof SlotMap & string, HandleOf<NoInfer<H>>, I, NoInfer<M>, NoInfer<N>>> & RendersCheck<C, D>): () => void;\n    register(options: ErasedOptions, component: unknown): () => void;\n    isLive(entry: StoredEntry): boolean;\n    entries(key: string): readonly StoredEntry[];\n    entriesOfSlot(key /* …truncated — full shape in source */',
  },
  {
    name: 'SlotEntryDef',
    declaration: 'export interface SlotEntryDef {\n    kind: SlotKind;\n    scope: SlotScope;\n    owner?: object;\n    keyProps?: Record<string, object>;\n    hookContext?: unknown;\n    inject?: object;\n}',
  },
  {
    name: 'SlotInjectFace',
    declaration: 'export type SlotInjectFace<I extends object> = I extends {\n    hooks: infer HS extends object;\n} ? Omit<I, \'hooks\'> & PropsSlotHooks<HS> : I;',
  },
  {
    name: 'SlotInjectOf',
    declaration: 'export type SlotInjectOf<K extends keyof SlotMap & string> = SlotMap[K] extends {\n    inject: infer Injected extends object;\n} ? Injected : object;',
  },
  {
    name: 'SlotKind',
    declaration: 'export type SlotKind = \'single\' | \'list\' | \'keyed\' | \'chain\';',
  },
  {
    name: 'SlotLabel',
    declaration: 'export type SlotLabel = string | (() => string);',
  },
  {
    name: 'SlotMap',
    declaration: 'export interface SlotMap {\n}',
  },
  {
    name: 'SlotScope',
    declaration: 'export type SlotScope = \'root\' | \'session-maybe\' | \'session\';',
  },
  {
    name: 'SlotSpec',
    declaration: 'export type SlotSpec<E extends SlotEntryDef> = {\n    kind: E[\'kind\'];\n    scope: E[\'scope\'];\n} & (\'inject\' extends keyof E ? E extends {\n    inject: infer Injected extends object;\n} ? {\n    inject: Injected;\n} : {\n    inject?: object;\n} : {\n    inject?: never;\n});',
  },
  {
    name: 'SnapshotSelectorHook',
    declaration: 'export type SnapshotSelectorHook<T> = <S>(sel: (s: T) => S, eq?: (a: S, b: S) => boolean) => S;',
  },
  {
    name: 'SteeringMessageNode',
    declaration: 'export interface SteeringMessageNode {\n    kind: \'steering\';\n    messageId: MessageId;\n    seq: number;\n    time: number;\n    content: readonly ContentBlock[];\n    source: unknown;\n}',
  },
  {
    name: 'StepLocation',
    declaration: 'export interface StepLocation {\n    readonly turn: number;\n    readonly step: number;\n    readonly start: SessionEvent<\'step/start\'> | undefined;\n    readonly end: SessionEvent<\'step/end\'> | undefined;\n    readonly status: \'open\' | \'closed\' | \'unknown\';\n    readonly data: ConversationLocationDataStore<ConversationStepDataMap>;\n}',
  },
  {
    name: 'StoreDecl',
    declaration: 'export type StoreDecl = StoreHandle<any, any> | StoreFactory;',
  },
  {
    name: 'StoredEntry',
    declaration: 'export interface StoredEntry {\n    component: unknown;\n    options: {\n        key?: string;\n        id?: string;\n        order?: number;\n        label?: SlotLabel;\n        priority?: number;\n    };\n    select?: ((owner: never) => unknown) | undefined;\n    inject?: ((...args: never[]) => Record<string, unknown>) | undefined;\n    children?: Readonly<Record<string, SlotSpec<SlotEntryDef>>> | undefined;\n    store?: StoreDecl | undefined;\n    locale?: string | undefined;\n    registrant?: string | undefined;\n}',
  },
  {
    name: 'StoreFactory',
    declaration: 'export type StoreFactory = () => StoreHandle<any, any>;',
  },
  {
    name: 'StoreHandle',
    declaration: 'export interface StoreHandle<T, A extends ActionsDecl<T>> {\n    readonly spec: StoreSpec<T, A>;\n    create(scopeKey?: string): StoreInstance<T, A>;\n}',
  },
  {
    name: 'StoreInstance',
    declaration: 'export interface StoreInstance<T, A extends ActionsDecl<T>> {\n    readonly actions: BakedActions<T, A>;\n    getSnapshot(): T;\n    subscribe(fn: () => void): () => void;\n    clearPersisted(): void;\n}',
  },
  {
    name: 'StoreSpec',
    declaration: 'export interface StoreSpec<T, A extends ActionsDecl<T>> {\n    init: () => T;\n    persist?: string;\n    actions: A;\n}',
  },
  {
    name: 'ThemeDefinition',
    declaration: 'export interface ThemeDefinition {\n    id: string;\n    colorScheme: \'light\' | \'dark\';\n    tokens: ThemeTokens;\n}',
  },
  {
    name: 'ThemePreference',
    declaration: 'export type ThemePreference = typeof THEME_PREFERENCES[number];',
  },
  {
    name: 'ThemeSnapshot',
    declaration: 'export interface ThemeSnapshot {\n    preference: ThemePreference;\n    active: ThemeDefinition;\n    themes: readonly ThemeDefinition[];\n    revision: number;\n}',
  },
  {
    name: 'ThemeTokenModes',
    declaration: 'export interface ThemeTokenModes {\n    light: string;\n    dark: string;\n}',
  },
  {
    name: 'ThemeTokenOverrides',
    declaration: 'export type ThemeTokenOverrides = Record<string, ThemeTokenModes>;',
  },
  {
    name: 'ThemeTokens',
    declaration: 'export type ThemeTokens = Record<string, string>;',
  },
  {
    name: 'ToolCallBlock',
    declaration: 'export type ToolCallBlock = RunningToolCall | ToolResultNode;',
  },
  {
    name: 'ToolResultNode',
    declaration: 'export interface ToolResultNode {\n    kind: \'tool-result\';\n    seq: number;\n    time: number;\n    callId: string;\n    call: {\n        name: string;\n        argsRaw: string;\n    } | null;\n    callTime: number | null;\n    content: readonly ContentBlock[];\n    isError: boolean;\n    error?: {\n        name: string;\n        code: string;\n    };\n    meta?: unknown;\n    callView: ToolCallView | null;\n    resultView: ToolResultView | null;\n    subCalls: readonly ToolCallBlock[];\n}',
  },
  {
    name: 'Translate',
    declaration: 'export type Translate<K extends string = string> = (key: K, params?: Record<string, unknown>) => string;',
  },
  {
    name: 'TranslateNS',
    declaration: 'export type TranslateNS<N extends keyof LocaleNamespaceMap & string> = Translate<LocaleKeysOf<N>>;',
  },
  {
    name: 'TurnErrorNode',
    declaration: 'export interface TurnErrorNode {\n    kind: \'turn-error\';\n    seq: number;\n    time: number;\n    turn: number;\n    step: number;\n    message: string;\n    code?: string;\n}',
  },
  {
    name: 'TurnLocation',
    declaration: 'export interface TurnLocation {\n    readonly turn: number;\n    readonly start: SessionEvent<\'turn/start\'> | undefined;\n    readonly end: SessionEvent<\'turn/end\'> | undefined;\n    readonly status: \'open\' | \'closed\' | \'unknown\';\n    readonly steps: readonly StepLocation[];\n    readonly data: ConversationLocationDataStore<ConversationTurnDataMap>;\n}',
  },
  {
    name: 'TurnMaxTokensNode',
    declaration: 'export interface TurnMaxTokensNode {\n    kind: \'turn-max-tokens\';\n    seq: number;\n    time: number;\n    turn: number;\n    step: number;\n}',
  },
  {
    name: 'UnknownSurfaceNode',
    declaration: 'export interface UnknownSurfaceNode {\n    kind: \'unknown\';\n    seq: number;\n    time: number;\n    type: string;\n    data: unknown;\n}',
  },
  {
    name: 'UserMessageNode',
    declaration: 'export interface UserMessageNode {\n    kind: \'user\';\n    seq: number;\n    time: number;\n    content: readonly ContentBlock[];\n    source: unknown;\n}',
  },
]

/** The inherited `ctx` API (cordis core + loader/hmr/timer), in curated order. */
export const INHERITED_CTX_API: readonly InheritedApiEntry[] = [
  { name: 'ctx.on / ctx.once', summary: 'Register an event listener (disposable).' },
  { name: 'ctx.emit / ctx.parallel / ctx.serial / ctx.bail / ctx.waterfall', summary: 'Dispatch an event (sync / awaited / first-bail / short-circuit chain).' },
  { name: 'ctx.plugin / ctx.inject', summary: 'Load a plugin / declare required services.' },
  { name: 'ctx.effect', summary: 'Register a disposable side effect tied to the fiber.' },
  { name: 'ctx.get / ctx.set / ctx.provide / ctx.accessor / ctx.mixin', summary: 'Low-level service-store access and binding.' },
  { name: 'ctx.extend / ctx.isolate / ctx.intercept', summary: 'Derive a child context (scoped services / isolation / interception).' },
  { name: 'ctx.root / ctx.scope / ctx.fiber / ctx.registry / ctx.reflect / ctx.events / ctx.logger', summary: 'Ambient handles onto the running context graph.' },
  { name: 'ctx.timer (+ interval / timeout / throttle / debounce)', summary: 'Disposable timer helpers. The `timer` key is provided at runtime; the four supported helpers are mixed onto ctx directly (declared via Pick).' },
  { name: 'ctx.loader', summary: 'The config Loader that booted the app (present under the loader).' },
  { name: 'ctx.hmr', summary: 'The hot-module-reload watcher (present under the hmr plugin).' },
]

function referencedTypeClosure(seeds: readonly string[]): TypeApiEntry[] {
  const included = new Set<string>()
  let frontier = [...seeds]
  while (frontier.length > 0) {
    const next: string[] = []
    for (const entry of TYPE_API) {
      if (included.has(entry.name)) continue
      const pattern = new RegExp(`\b${entry.name}\b`)
      if (!frontier.some(text => pattern.test(text))) continue
      included.add(entry.name)
      next.push(entry.declaration)
    }
    frontier = next
  }
  return TYPE_API.filter(entry => included.has(entry.name))
}

function contextProperty(key: string): string {
  return /^[A-Za-z_$][\w$]*$/.test(key) ? `ctx.${key}` : `ctx[${JSON.stringify(key)}]`
}

/**
 * Project the Service Catalog as a compact directory or one exact coding contract.
 * @param key - exact Service key; omit it to list all Services and method signatures.
 * @param services - platform-specific visible Service entries.
 * @returns compact navigation data or one detailed Service with its referenced type closure.
 */
export function queryServiceApi(key?: string, services: readonly ServiceApiEntry[] = SERVICE_API): object {
  if (key === undefined) {
    return {
      mode: 'catalog',
      services: services.map(service => ({
        key: service.key,
        description: service.summary,
        methods: service.methods.map(method => ({ signature: method.signature })),
      })),
    }
  }
  const service = services.find(candidate => candidate.key === key)
  if (service === undefined) throw new Error(`no catalogued Service named "${key}"`)
  return {
    mode: 'service',
    service: {
      key: service.key,
      description: service.description,
      access: {
        optional: { expression: `ctx.get(${JSON.stringify(service.key)})`, requiresUndefinedCheck: true },
        hardDependency: { inject: [service.key], expression: contextProperty(service.key) },
      },
      methods: service.methods,
    },
    referencedTypes: referencedTypeClosure(service.methods.map(method => method.signature)),
  }
}

/**
 * Project the Event Catalog as a compact directory or one exact listener contract.
 * @param name - exact Event name; omit it to list all Events and listener signatures.
 * @param events - platform-specific visible Event entries.
 * @returns compact navigation data or one detailed Event with its referenced type closure.
 */
export function queryEventApi(name?: string, events: readonly EventApiEntry[] = EVENT_API): object {
  if (name === undefined) {
    return {
      mode: 'catalog',
      events: events.map(event => ({
        name: event.name,
        description: event.summary,
        mode: event.mode,
        signature: event.signature,
      })),
    }
  }
  const event = events.find(candidate => candidate.name === name)
  if (event === undefined) throw new Error(`no catalogued Event named "${name}"`)
  return {
    mode: 'event',
    event: {
      name: event.name,
      description: event.description,
      mode: event.mode,
      signature: event.signature,
      parameters: event.parameters,
    },
    referencedTypes: referencedTypeClosure([event.signature]),
  }
}
/* jscpd:ignore-end */
