/** * Persistent PI RPC driver and PI-owned session history operations. * * PI is intentionally integrated through its public JSONL RPC protocol and * session file format. No PI runtime package is imported by AgentLink. */ import { type ChildProcess } from 'child_process'; import type { SendFn } from './claude.js'; import type { GlobalSessionInfo, SessionInfo } from './history.js'; import type { HistoryMessage } from './history-message-transform.js'; import { piCapabilities, type UsageInfo } from './backends/types.js'; import { type ProviderCommand, type ProviderCommandDiscoveryResult } from './provider-command-types.js'; export type PiThinkingLevel = 'off' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max'; export interface PiOptions { /** PI provider/model identifier, for example "anthropic/claude-sonnet-4". */ model?: string; thinking?: PiThinkingLevel; } interface PiChatFile { name: string; mimeType: string; data: string; } interface PendingRpc { command: string; resolve: (response: Record) => void; reject: (error: Error) => void; timer: ReturnType; } export interface PiConversationState { conversationId: string; child: ChildProcess | null; childProviderId: string | null; piSessionId: string | null; lastPiSessionId: string | null; sessionFile: string | null; workDir: string; providerId: string; turnActive: boolean; turnId: string | null; stateVersion: number; heartbeatTimer: ReturnType | null; model: string | null; thinking: PiThinkingLevel | null; availableModels: string[]; commands: ProviderCommand[]; commandCatalogGeneration: number; sessionNotified: boolean; cancelRequested: boolean; protocolFailed: boolean; stderrBuffer: string; pendingRpc: Map; attachmentPaths: Set; turnAttachmentPaths: Map>; lastUsage?: UsageInfo; launching: Promise | null; setupPromise: Promise | null; } interface PiSessionPage { sessions: SessionInfo[]; hasMore: boolean; nextCursor?: string; } interface PiGlobalSessionPage { sessions: GlobalSessionInfo[]; hasMore: boolean; nextCursor?: string; indexState: 'ready'; } export declare function addPiSendFn(fn: SendFn): () => void; export declare function getPiConversation(conversationId: string): PiConversationState | undefined; export declare function getPiConversations(): Map; export declare function createPiPlaceholder(conversationId: string, options?: { providerId?: string; workDir?: string; }): void; export declare function rebindPiConversation(piSessionId: string, newConversationId: string, providerId?: string, workDir?: string): boolean; export declare function discoverPiCommands(conversationId: string, workDir: string, providerId?: string): Promise; export declare function getPiAvailableModels(providerId?: string): string[]; export interface PiChatOptions { resumeSessionId?: string; providerId?: string; piOptions?: PiOptions; } export declare function handlePiChat(conversationId: string, text: string, workDir: string, options?: PiChatOptions, files?: PiChatFile[]): void; export declare function cancelPiExecution(conversationId: string): void; export declare function cleanupAllPiConversations(): void; export declare function restartPiConversation(conversationId: string, options?: { providerId?: string; }): { wasTurnActive: boolean; piSessionId: string | null; }; export declare function evictByPiSessionId(piSessionId: string, providerId?: string, workDir?: string): boolean; export declare function _resetResolvedPiPathForTests(): void; export declare function listPiSessions(workDir: string, providerId?: string): SessionInfo[]; export declare function listPiSessionsPage(workDir: string, options?: { limit?: number; cursor?: string; providerId?: string; }): PiSessionPage; export declare function listAllPiSessions(limit?: number, providerId?: string): GlobalSessionInfo[]; export declare function listAllPiSessionsPage(options?: { limit?: number; cursor?: string; providerId?: string; }): PiGlobalSessionPage; export declare function getPiSessionWorkDir(sessionId: string, providerId?: string, workDir?: string): string | undefined; export declare function readPiSessionMessages(workDir: string, sessionId: string, providerId?: string): HistoryMessage[]; export declare function renamePiSession(workDir: string, sessionId: string, newTitle: string, providerId?: string): boolean; export declare function deletePiSession(workDir: string, sessionId: string, providerId?: string): boolean; export declare function movePiSession(fromWorkDir: string, toWorkDir: string, sessionId: string, providerId?: string): boolean; export { piCapabilities };