import { type ProviderSwitches } from "../../capability/index.js"; import { type Rule } from "../../capability/rule.js"; import { Settings, type SettingsMirrorRefresh, type SettingsMirrorState, type SettingsMirrorWrite } from "../../config/settings.js"; import type { AgentStorageApi } from "../../session/agent-storage.js"; import { type RpcMethod } from "../rpc.js"; import type { ThreadService } from "../services.js"; /** Worker-side receiver of main-instance states; returns `false` once its mirror was collected. */ export type SettingsMirrorListener = (state: SettingsMirrorState) => boolean | Promise; /** What a new worker mirror needs: the main instance's state and, for an overlay, its parent. */ export interface SettingsMirrorSeed { readonly state: SettingsMirrorState; readonly parent: Settings | null; /** The main instance's agent.db handle; crosses as a remote `"agent-storage"` object (see `./runtime`). */ readonly storage: AgentStorageApi | null; } /** Remote-object protocol (kind `"settings"`) a worker mirror speaks to its main-thread instance. */ export type SettingsMirrorProtocol = { /** Subscribe `listener` to state pushes and return the current state, atomically. */ attach: RpcMethod<[listener: SettingsMirrorListener], SettingsMirrorSeed>; /** Replay a mirror write; sync on main. */ write: RpcMethod<[write: SettingsMirrorWrite], SettingsMirrorState>; refresh: RpcMethod<[refresh: SettingsMirrorRefresh], SettingsMirrorState>; cloneForCwd: RpcMethod<[cwd: string], Settings>; }; /** A main-thread snapshot tagged with a sequence number; receivers drop ones not newer than the last. */ export interface Sequenced { readonly seq: number; readonly value: T; } /** Snapshots returned by {@link SettingsThreadGlobals.watch}. */ export interface SettingsWatchSnapshot { readonly switches: Sequenced; readonly rules: Sequenced; } /** Boot globals of {@link settingsThreadService}. */ export interface SettingsThreadGlobals { /** Main's global singleton, or `null` when main never initialized one. */ readonly global: Settings | null; /** Instance driving main's process-wide effects, if any. */ readonly effects: Settings | null; /** Subscribe to provider-switch and active-rule changes; resolves with the current snapshots. */ readonly watch: (onSwitches: (switches: Sequenced) => void, onRules: (rules: Sequenced) => void) => SettingsWatchSnapshot | Promise; } /** * Settings, capability provider switches and active rules for subagent workers; see the module * doc for the mirror protocol and write routing. */ export declare const settingsThreadService: ThreadService;