/** * RPC Client for programmatic access to the coding agent. * * Spawns the agent in RPC mode and provides a typed API for all operations. */ import type { AgentEvent, AgentMessage, ThinkingLevel } from "@earendil-works/pi-agent-core"; import type { ImageContent } from "@earendil-works/pi-ai"; import type { SessionStats } from "../../core/agent-session.js"; import type { BashResult } from "../../core/bash-executor.js"; import type { CompactionResult } from "../../core/compaction/index.js"; import type { RpcSessionState, RpcSlashCommand } from "./rpc-types.js"; export interface RpcClientOptions { /** Path to the CLI entry point (default: searches for dist/cli.js) */ cliPath?: string; /** Working directory for the agent */ cwd?: string; /** Environment variables */ env?: Record; /** Provider to use */ provider?: string; /** Model ID to use */ model?: string; /** Additional CLI arguments */ args?: string[]; } export interface ModelInfo { provider: string; id: string; contextWindow: number; reasoning: boolean; } export type RpcEventListener = (event: AgentEvent) => void; export declare class RpcClient { private options; private process; private stopReadingStdout; private eventListeners; private pendingRequests; private requestId; private stderr; constructor(options?: RpcClientOptions); /** * Start the RPC agent process. */ start(): Promise; /** * Stop the RPC agent process. */ stop(): Promise; /** * Subscribe to agent events. */ onEvent(listener: RpcEventListener): () => void; /** * Get collected stderr output (useful for debugging). */ getStderr(): string; /** * Send a prompt to the agent. * Returns immediately after sending; use onEvent() to receive streaming events. * Use waitForIdle() to wait for completion. */ prompt(message: string, images?: ImageContent[]): Promise; /** * Queue a steering message to interrupt the agent mid-run. */ steer(message: string, images?: ImageContent[]): Promise; /** * Queue a follow-up message to be processed after the agent finishes. */ followUp(message: string, images?: ImageContent[]): Promise; /** * Abort current operation. */ abort(): Promise; /** * Start a new session, optionally with parent tracking. * @param parentSession - Optional parent session path for lineage tracking * @returns Object with `cancelled: true` if an extension cancelled the new session */ newSession(parentSession?: string): Promise<{ cancelled: boolean; }>; /** * Get current session state. */ getState(): Promise; /** * Set model by provider and ID. */ setModel(provider: string, modelId: string): Promise<{ provider: string; id: string; }>; /** * Cycle to next model. */ cycleModel(): Promise<{ model: { provider: string; id: string; }; thinkingLevel: ThinkingLevel; isScoped: boolean; } | null>; /** * Get list of available models. */ getAvailableModels(): Promise; /** * Set thinking level. */ setThinkingLevel(level: ThinkingLevel): Promise; /** * Cycle thinking level. */ cycleThinkingLevel(): Promise<{ level: ThinkingLevel; } | null>; /** * Set steering mode. */ setSteeringMode(mode: "all" | "one-at-a-time"): Promise; /** * Set follow-up mode. */ setFollowUpMode(mode: "all" | "one-at-a-time"): Promise; /** * Compact session context. */ compact(customInstructions?: string): Promise; /** * Set auto-compaction enabled/disabled. */ setAutoCompaction(enabled: boolean): Promise; /** * Set auto-retry enabled/disabled. */ setAutoRetry(enabled: boolean): Promise; /** * Abort in-progress retry. */ abortRetry(): Promise; /** * Execute a bash command. */ bash(command: string): Promise; /** * Abort running bash command. */ abortBash(): Promise; /** * Get session statistics. */ getSessionStats(): Promise; /** * Export session to HTML. */ exportHtml(outputPath?: string): Promise<{ path: string; }>; /** * Switch to a different session file. * @returns Object with `cancelled: true` if an extension cancelled the switch */ switchSession(sessionPath: string): Promise<{ cancelled: boolean; }>; /** * Fork from a specific message. * @returns Object with `text` (the message text) and `cancelled` (if extension cancelled) */ fork(entryId: string): Promise<{ text: string; cancelled: boolean; }>; /** * Clone the current active branch into a new session. * @returns Object with `cancelled: true` if an extension cancelled the clone */ clone(): Promise<{ cancelled: boolean; }>; /** * Get messages available for forking. */ getForkMessages(): Promise>; /** * Get text of last assistant message. */ getLastAssistantText(): Promise; /** * Set the session display name. */ setSessionName(name: string): Promise; /** * Get all messages in the session. */ getMessages(): Promise; /** * Get available commands (extension commands, prompt templates, skills). */ getCommands(): Promise; /** * Wait for agent to become idle (no streaming). * Resolves when agent_end event is received. */ waitForIdle(timeout?: number): Promise; /** * Collect events until agent becomes idle. */ collectEvents(timeout?: number): Promise; /** * Send prompt and wait for completion, returning all events. */ promptAndWait(message: string, images?: ImageContent[], timeout?: number): Promise; private handleLine; private send; private getData; } //# sourceMappingURL=rpc-client.d.ts.map