agents
Version:
A home for your AI agents
145 lines (143 loc) • 5.04 kB
TypeScript
import {
h as ContainerSettings,
l as ContainerEvent,
p as ContainerOutcome
} from "../../../protocol-BEgrJYC5.js";
import { i as ContainerAdapter } from "../../../daemon-core-CbohVPAu.js";
//#region src/harness/container/runtime/server.d.ts
/** `serve`'s options. */
type ServeOptions = {
readonly adapter: ContainerAdapter /** This container's id, from `CF_HARNESS_RUNTIME_ID`. */;
readonly runtimeId: string /** The shared secret, from `CF_HARNESS_TOKEN`. */;
readonly token: string /** Port to listen on; 0 picks one. */;
readonly port: number /** Interface to bind. Default all interfaces. */;
readonly host?: string;
};
/** A running daemon. */
type DaemonServer = {
/** The port it listens on. */ readonly port: number /** Stop accepting connections and close every adapter session. */;
close(): Promise<void>;
};
/**
* Start the daemon.
*
* @param options - The adapter, identity, secret, and port.
* @returns The running server, once it listens.
*
* @experimental The API may change before it stabilizes.
*/
declare function serve(options: ServeOptions): Promise<DaemonServer>;
/**
* Start the daemon with the identity, secret, and port the Durable Object
* started the container with, and stop it on SIGTERM. The entrypoint of an
* image: `serveFromEnv(cliAdapter({ ... }))`.
*
* @param adapter - The agent to run.
* @param env - The environment. Default `process.env`.
* @returns The running server.
*
* @experimental The API may change before it stabilizes.
*/
declare function serveFromEnv(
adapter: ContainerAdapter,
env?: NodeJS.ProcessEnv
): Promise<DaemonServer>;
//#endregion
//#region src/harness/container/runtime/cli-adapter.d.ts
/** String values a CLI reported in earlier turns, such as its session id. */
type CliState = {
readonly [key: string]: string;
};
/** What a command and a parser are given for one turn. */
type CliTurn = {
readonly operationId: string /** The prompt's text. Image parts are not passed to CLIs. */;
readonly prompt: string;
readonly settings: ContainerSettings;
readonly state: CliState;
};
/** How to start one turn. */
type CliCommand = {
readonly argv: readonly string[] /** Written to the process's stdin, which is then closed. */;
readonly stdin?: string /** Added to the environment. */;
readonly env?: {
readonly [name: string]: string;
};
};
/** What one stdout line meant. */
type CliUpdate = {
readonly events?: readonly ContainerEvent[] /** Merged into the session's state and persisted. */;
readonly state?: CliState /** The turn's outcome, when the line reports it. */;
readonly outcome?: ContainerOutcome;
};
/** Reads one turn's output. */
type CliParser = {
line(
text: string
): CliUpdate /** The outcome when no line reported one, from how the process exited. */;
end(exit: {
readonly code: number | null;
readonly stderr: string;
}): ContainerOutcome;
};
/** `cliAdapter`'s options. */
type CliAdapterOptions = {
/** Reported in `hello`, such as `"codex"`. */ readonly id: string;
readonly version?: string;
readonly command: (turn: CliTurn) => CliCommand;
readonly parser: (
turn: CliTurn
) => CliParser /** Directories under `$HOME` where the CLI keeps its sessions. */;
readonly stateDirs?: readonly string[] /** Working directory. Default `/workspace`. */;
readonly cwd?: string /** Where session homes are created. Default `~/.harness/sessions`. */;
readonly homes?: string /** How often a running turn's state is persisted. Default 5 seconds. */;
readonly syncIntervalMs?: number;
/**
* A home to start every session home from: whatever setup installed
* there (plugins, mods, settings, skills) is in each session's home. The
* session files under `stateDirs` are then restored on top. Default: none.
*/
readonly skeleton?: string;
/**
* Run the CLI as this user, and give it its home. For a daemon running
* as root: Claude Code, for one, refuses to skip permission prompts as
* root. Default: the daemon's own user.
*/
readonly user?: {
readonly uid: number;
readonly gid: number;
};
};
/**
* An adapter for an agent CLI.
*
* @param options - The CLI's command, parser, and state directories.
* @returns The adapter.
*
* @experimental The API may change before it stabilizes.
*/
declare function cliAdapter(options: CliAdapterOptions): ContainerAdapter;
//#endregion
//#region src/harness/container/runtime/presets/claude-code.d.ts
/** The Claude Code preset's description, for `cliAdapter`. */
declare const claudeCodeCli: CliAdapterOptions;
//#endregion
//#region src/harness/container/runtime/presets/codex.d.ts
/** The Codex preset's description, for `cliAdapter`. */
declare const codexCli: CliAdapterOptions;
//#endregion
export {
type CliAdapterOptions,
type CliCommand,
type CliParser,
type CliState,
type CliTurn,
type CliUpdate,
type DaemonServer,
type ServeOptions,
claudeCodeCli,
cliAdapter,
codexCli,
serve,
serveFromEnv
};
//# sourceMappingURL=index.d.ts.map