687
Oc
orc-code / files
orc-code / packages / types / src / index.ts
2.0 KB
1import type { Subprocess } from "bun"; 2 3// ── Agent Events ────────────────────────────────────────────── 4 5export type AgentEvent = 6 | { type: "text"; content: string } 7 | { type: "tool_use"; tool: string; args?: unknown } 8 | { type: "tool_result"; output: string; error?: boolean } 9 | { type: "error"; message: string } 10 | { type: "done"; sessionId: string } 11 | { type: "usage"; tokens: TokenUsage }; 12 13export interface TokenUsage { 14 inputTokens?: number; 15 outputTokens?: number; 16 cacheReadTokens?: number; 17 cacheWriteTokens?: number; 18} 19 20// ── Agent Process ───────────────────────────────────────────── 21 22export interface AgentProcess { 23 /** Raw subprocess handle for lifecycle management */ 24 child: Subprocess; 25 /** Normalized event stream */ 26 events: AsyncIterable<AgentEvent>; 27 /** Resolves when the process exits */ 28 result: Promise<AgentResult>; 29} 30 31export interface AgentResult { 32 sessionId: string | null; 33 exitCode: number; 34} 35 36// ── Agent Plugin ────────────────────────────────────────────── 37 38export interface AgentSessionOpts { 39 cwd?: string; 40} 41 42export interface AgentPlugin { 43 /** Identifier used in /agent command and the DB */ 44 name: string; 45 /** Binary name to look for in $PATH */ 46 command: string; 47 /** Default flags for all invocations */ 48 opts: string[]; 49 /** Checks if the binary exists in $PATH */ 50 isAvailable(): Promise<boolean>; 51 /** Spawns a new agent session */ 52 createSession(prompt: string, opts?: AgentSessionOpts): AgentProcess; 53 /** Sends a follow-up prompt to an existing session */ 54 resumeSession(sessionId: string, prompt: string, opts?: AgentSessionOpts): AgentProcess; 55} 56 57export { checkCommand, spawnAgentProcess } from "./helpers.js"; 58export type { LineParseFn, SessionIdExtractFn } from "./helpers.js";