import {
  h as ContainerSettings,
  l as ContainerEvent,
  p as ContainerOutcome,
  u as ContainerInput,
  x as JsonValue
} from "./protocol-BEgrJYC5.js";

//#region src/harness/container/daemon-core.d.ts
/** What an adapter is told when its session opens. */
type AdapterContext = {
  /** The harness session id. */ readonly session: string;
  readonly settings: ContainerSettings;
  /**
   * Everything this adapter `persist`ed for the session before, possibly in
   * another container, oldest first. Empty for a new session.
   */
  readonly restore: readonly JsonValue[] /** Report an event. It belongs to the operation that is running, if any. */;
  emit(event: ContainerEvent): void;
  /**
   * Keep resume state. The Durable Object stores the entries and passes all
   * of them back as `restore` when the session opens in a new container.
   */
  persist(
    entries: readonly JsonValue[]
  ): void /** A diagnostic line, reported as a `log` event. */;
  log(level: "info" | "warn" | "error", message: string): void;
};
/** One turn an adapter runs. */
type AdapterTurn = {
  readonly operationId: string;
  readonly input: ContainerInput /** Aborted when the operation is aborted. Wind down promptly. */;
  readonly signal: AbortSignal;
};
/** An open adapter session. Turns are never run concurrently. */
type AdapterSession = {
  /**
   * Run one turn to completion. A rejection settles the operation
   * `unanswered` with the error's message.
   */
  run(turn: AdapterTurn): Promise<ContainerOutcome>;
  /**
   * Fold input into the running turn. Return false to have it queued as a
   * follow-up instead. Absent when the agent cannot be steered.
   */
  steer?(
    input: ContainerInput
  ): boolean | Promise<boolean> /** Apply new settings to the open session. */;
  configure?(
    settings: ContainerSettings
  ): void | Promise<void> /** Release the session's resources. */;
  close(): Promise<void>;
};
/** An agent, as the daemon runs it. */
type ContainerAdapter = {
  /** Reported in `hello`, such as `"claude-code"`. */ readonly id: string;
  readonly version: string /** Free-form capability names, reported in `hello`. */;
  readonly capabilities?: readonly string[] /** Open (or resume) one session. */;
  open(context: AdapterContext): AdapterSession | Promise<AdapterSession>;
};
/** The send side of one connection, supplied by the transport. */
type DaemonSocket = {
  send(text: string): void;
  close(code: number, reason: string): void;
};
/** The receive side of one connection, driven by the transport. */
type DaemonConnection = {
  /** A message arrived. */ receive(
    text: string
  ): void /** The connection closed. */;
  closed(): void;
};
/** `ContainerDaemon`'s options. */
type ContainerDaemonOptions = {
  readonly adapter: ContainerAdapter /** This container's id, from `CONTAINER_ENV.runtimeId`. */;
  readonly runtimeId: string;
  /**
   * Most unacknowledged frames kept per session. Older ones are dropped and
   * the object reconciles from `hello` instead. Default 10_000.
   */
  readonly maxKeptFrames?: number;
};
/**
 * The daemon core. One per container process.
 *
 * @experimental The API may change before it stabilizes.
 */
declare class ContainerDaemon {
  #private;
  /**
   * @param options - The adapter and this container's id.
   */
  constructor(options: ContainerDaemonOptions);
  /**
   * Attach a connection for a session. A newer connection replaces an older
   * one, which is closed with `CLOSE_REPLACED`. The daemon sends `hello`
   * at once.
   *
   * @param session - The harness session id.
   * @param socket - The send side.
   * @returns The receive side, for the transport to drive.
   */
  connect(session: string, socket: DaemonSocket): DaemonConnection;
  /** Close every adapter session, as the container shuts down. */
  close(): Promise<void>;
}
/**
 * A reference adapter that answers `echo: <text>` and needs no model or
 * credentials. Use it for keyless smoke deploys of the whole path and in
 * tests. It persists one entry per turn and counts them back after a
 * restore, so a resumed session visibly remembers its history:
 *
 * - `slow <ms> <text>` waits `ms` before answering, and stops on abort.
 * - `fail <reason>` settles the operation unanswered with `reason`.
 * - anything else is echoed with the turn number: `echo: hi (turn 3)`.
 *
 * @experimental The API may change before it stabilizes.
 */
declare const echoAdapter: ContainerAdapter;
//#endregion
export {
  ContainerDaemon as a,
  DaemonSocket as c,
  ContainerAdapter as i,
  echoAdapter as l,
  AdapterSession as n,
  ContainerDaemonOptions as o,
  AdapterTurn as r,
  DaemonConnection as s,
  AdapterContext as t
};
//# sourceMappingURL=daemon-core-CbohVPAu.d.ts.map
