/** * Command Context Implementation * * Provides the concrete implementation of CommandContext interface, * bridging commands to core services (AgentService, SessionStore, etc.) */ import type { CommandContext, BtwQueryOptions, CommandStreamEvent, ReplyOptions, UIComponent, SessionInfo, ModelInfo, UsageStats, PlatformFeature, MessageSource, CompactSessionResult } from './types.js'; import type { Config } from '../config/schema.js'; import type { AgentMessage } from '@earendil-works/pi-agent-core'; import type { MessageBus } from '../infra/bus/index.js'; import type { SessionStore, SessionConfigStore } from '../session/index.js'; import type { ThinkLevel, ReasoningLevel, VerboseLevel } from '../agent/transcript/thinking-types.js'; import type { CompactionResult } from '../agent/memory/compaction.js'; import type { WorkflowRunServiceLike } from '../workflows/service/workflow-run-service.types.js'; export interface CommandContextDeps { sessionKey: string; source: MessageSource; channelId: string; chatId: string; senderId: string; isGroup: boolean; accountId?: string; threadId?: string; config: Config; bus: MessageBus; sessionStore: SessionStore; sessionConfigStore?: SessionConfigStore; /** After persisting session thinking, sync pi-agent in-memory state */ applySessionThinkingLevel?: (sessionKey: string, level: ThinkLevel) => void; replyHandler: (text: string, options?: ReplyOptions) => Promise; componentHandler?: (component: UIComponent) => Promise; typingHandler?: (typing: boolean) => Promise; supportedFeatures: PlatformFeature[]; /** Called after session files are removed so in-memory agents match disk */ invalidateAgentSession?: (sessionKey: string) => void; /** Reset session in place (archive + new session id); optional — falls back to clearSession */ resetSession?: (sessionKey: string) => Promise; getCurrentModel?: () => string; switchModel?: (modelId: string) => Promise; listModels?: () => Promise; getUsage?: () => Promise; /** Stop current LLM turn and clear channel preview stream (Telegram draft, etc.) */ abortCurrentTurn?: () => Promise; /** Reload skills from disk and refresh active agent prompts. */ reloadSkills?: () => Promise; /** Install a managed skill from an explicit source and refresh active agent prompts. */ installSkillFromSource?: CommandContext['installSkillFromSource']; compactSession?: (sessionKey: string, options?: { instructions?: string; force?: boolean; }) => Promise; btwQuery?: (sessionKey: string, question: string, options?: BtwQueryOptions) => Promise<{ text: string; error?: string; }>; emitEvent?: (event: CommandStreamEvent) => void | Promise; getSessionContextReport?: (sessionKey: string, mode: 'list' | 'detail' | 'json') => Promise; workflowRunService?: WorkflowRunServiceLike; } export declare class CommandContextImpl implements CommandContext { readonly sessionKey: string; readonly source: MessageSource; readonly channelId: string; readonly chatId: string; readonly senderId: string; readonly isGroup: boolean; readonly accountId?: string; readonly threadId?: string; readonly config: Config; readonly abortCurrentTurn?: () => Promise; readonly reloadSkills?: () => Promise; readonly installSkillFromSource?: CommandContext['installSkillFromSource']; readonly workflowRunApis?: CommandContext['workflowRunApis']; private deps; constructor(deps: CommandContextDeps); private outboundMetadata; reply(text: string, options?: ReplyOptions): Promise; replyComponent(component: UIComponent): Promise; setTyping(typing: boolean): Promise; getSession(): Promise; resetSession(): Promise; clearSession(): Promise; archiveSession(): Promise; listSessions(): Promise; switchSession(sessionKey: string): Promise; getCurrentModel(): string; listModels(): Promise; switchModel(modelId: string): Promise; getUsage(): Promise; supports(feature: PlatformFeature): boolean; getConfig(): Config; updateConfig(path: string, value: unknown): Promise; /** * Get the session config store (if available) */ getSessionConfigStore(): SessionConfigStore | undefined; /** * Get current thinking level (session override or default) */ getThinkingLevel(): Promise; /** * Set thinking level for this session */ setThinkingLevel(level: ThinkLevel): Promise; syncAgentThinkingLevel(level: ThinkLevel): void; compactSession(options?: { instructions?: string; force?: boolean; }): Promise; btwQuery(question: string, options?: BtwQueryOptions): Promise<{ text: string; error?: string; }>; emitEvent(event: CommandStreamEvent): void | Promise; exportSessionToWorkspace(format: 'markdown' | 'html' | 'json'): Promise<{ path: string; }>; agentContextReport(mode?: 'list' | 'detail' | 'json'): Promise; /** * Get current reasoning level (session override or default) */ getReasoningLevel(): Promise; /** * Set reasoning level for this session */ setReasoningLevel(level: ReasoningLevel): Promise; /** * Get current verbose level (session override or default) */ getVerboseLevel(): Promise; /** * Set verbose level for this session */ setVerboseLevel(level: VerboseLevel): Promise; private renderComponentAsText; } /** * Create a command context from dependencies */ export declare function createCommandContext(deps: CommandContextDeps): CommandContext;