import { type Config } from "../config.js"; import { type DeliveryLog } from "../delivery-log.js"; import type { Secrets } from "../env.js"; import type { Events } from "../events.js"; import type { HealthCache } from "../health.js"; import type { JobStore } from "../jobs.js"; import type { Logger } from "../logger.js"; import type { Paths } from "../paths.js"; import type { ReadinessCache } from "../readiness.js"; import type { SkillRegistry } from "../registry.js"; import type { ScheduleStatus } from "../scheduler.js"; import { type ServerState } from "../server.js"; import { type CloudPolicy } from "./config.js"; import type { CommandLedger } from "./outbox.js"; import { type Command, type CommandErrorCode, type CommandResult, type CommandType, type Sealed, type Snapshot } from "./protocol.js"; export declare class CommandError extends Error { readonly code: CommandErrorCode; readonly hint?: string | undefined; constructor(code: CommandErrorCode, message: string, hint?: string | undefined); } export interface CommandDeps { paths: Paths; config: Config; secrets: () => Secrets; fileSecrets: () => Secrets; registry: SkillRegistry; store: JobStore; deliveryLog?: DeliveryLog; schedules?: () => ScheduleStatus[]; health?: HealthCache; readiness?: ReadinessCache; /** Where `accounts.get` says what a usage probe taught (`account.updated`). */ events?: Events; serverState?: () => ServerState | undefined; logger: Logger; policy: () => CloudPolicy; ledger: CommandLedger; snapshot: () => Snapshot; /** Whether payload bodies may leave the machine (`cloud.upload_payloads` and the cloud's hint). */ uploadPayloads: () => boolean; uploadArtifacts: () => boolean; /** Whether the text of skills may leave the machine (`cloud.upload_definitions`; default true). */ uploadDefinitions?: () => boolean; /** Control handlers (skill.run, job.answer, config.patch, …): `createControlHandlers` in control.ts. */ control?: Partial>; /** Runs `fn` once the cloud acknowledged the command's result (a restart must not swallow its own answer). */ afterAck?: (commandId: string, fn: () => void) => void; /** Uploads an artifact in chunks (`PUT /api/agent/artifacts//`), for ones too large to inline. */ upload?: (jobId: string, name: string, data: Buffer) => Promise<{ bytes: number; sha256: string; chunks: number; }>; /** Streams a running job's output as `job.output` events. */ watch?: { start(jobId: string, stream: "stdout" | "stderr", ttlSeconds: number): { watching: number; }; stop(jobId: string): boolean; }; } export type CommandHandler = (args: never, command: Command, deps: CommandDeps) => Promise | CommandOutcome; export interface CommandOutcome { result: unknown; /** Never cached; never scrubbed or stored in the clear by the cloud. */ sensitive?: boolean; /** A value only the requester can open (a generated secret). */ sealed?: Sealed; /** Runs after the cloud has the result (see `CommandDeps.afterAck`). */ after?: () => void; } export interface CommandDispatcher { /** Runs (or refuses) one command and records the result in the ledger. A command seen before returns its cached result. */ run(command: Command): Promise; } export declare function createCommandDispatcher(deps: CommandDeps): CommandDispatcher;