import type { PlatformAdapter, DownloadedFile } from '../platform/index.js'; import type { AgentResult, ChatNoticeLevel, ContextUsage } from '../core/types/agent-types.js'; import { projectStore } from '../domain/projects/index.js'; import { runningExecutions } from '../core/running-executions.js'; export interface RunConversationOptions { adapter: PlatformAdapter; channel: string; /** The raw user message (without the default agent's directive). */ userMessage: string; /** Stable Cortex tracking id for this session (UI identity, execution-record + publish key). */ trackSessionId: string; /** The project this session is bound to (from the session registry record). Cost + execution * records are attributed to this project verbatim — no message-text re-derivation. */ projectId: string; /** Backend resume target (the backend CLI's own session id), or null for a fresh session where the * backend self-assigns its id. Decoupled from {@link trackSessionId}. */ backendSessionId: string | null; /** Resolved session name for this turn. */ sessionName: string; files: DownloadedFile[]; startTime: number; /** Execution trigger; defaults to 'user'. Scheduled session-target dispatch passes 'scheduled'. */ trigger?: string; scheduleTaskId?: string | null; /** Profile override for `__active__` agents (used by scheduler). */ profileOverride?: string | null; /** Fired once the execution record is created, before the agent starts — lets the caller * attach an execution-scoped Cancel button to the status message. */ onExecutionStarted?: (executionId: string) => void | Promise; /** Fired synchronously after the backend handle is registered for cancellation. */ onExecutionRegistered?: () => void; /** `blockId` identifies prior deltas; `noticeLevel` marks system-authored chat notices. */ onAssistantMessage?: ((text: string, blockId?: string, noticeLevel?: ChatNoticeLevel) => void) | null; /** Incremental chunk of a block still being generated. Web chat only — see delta-coalescer. */ onAssistantDelta?: ((text: string, blockId: string) => void) | null; onProgress?: ((progress: any) => void) | null; onContextUsage?: ((usage: ContextUsage) => void | Promise) | null; onFallback?: ((...args: any[]) => Promise) | null; /** Receives the backend-ready prompt after context and attachment paths are assembled. */ onPromptBuilt?: ((prompt: string) => void) | null; onToolUse?: ((name: string, input: any, toolUseId: string) => void) | null; onToolResult?: ((toolUseId: string, content: string, isError: boolean) => void) | null; onPlanWritten?: ((event: { path: string; content: string; toolUseId: string; }) => void) | null; onAskUserQuestion?: ((event: any) => void) | null; } export interface ConversationResult { result: AgentResult; executionId: string; /** Underlying agent process for the turn. Used by the background-task continuation path to * register a ContinuationSink on the (Claude) session. Opaque to other consumers. */ agentProcess?: unknown; } export declare function registerConversationHandle(registry: Pick, registration: Parameters[0], onRegistered?: () => void): void; /** * Decide whether (and which) project context to inject into the conversation prompt. * Returns the {id, contextDir} pair for buildConversationPrompt, or null to inject nothing. * * Injection is deliberately narrow: only the FIRST turn (fresh backend session — resume keeps it * in history) of a Web UI direct session (`web:` channel — the only path where the user explicitly * binds the session to a project at create time), and only for real user projects (the `general` * umbrella carries no signal). Unknown/deleted project ids inject nothing rather than a dead path. */ export declare function resolveConversationProject(args: { channel: string; projectId: string; isFreshSession: boolean; store?: Pick; }): { id: string; contextDir: string; } | null; /** * Execute a single plain user-conversation turn against the active default agent — no thread, * no workspace, no artifact. Mirrors the legacy default-thread branch of runThread() exactly * (channel session reuse, useCoreMcp:false, isUserInitiated:true, single step) and the * register/complete lifecycle of lifecycle.ts:runRetryAgent. * * Does NOT catch agent errors: the caller's try/catch (agent-runner._executeReal) invokes * handleAgentError, which finalizes the execution record and removes the running-execution * entry via runningExecutions.fail(executionId). On success this function removes the entry via * runningExecutions.complete(executionId); handleAgentSuccess finalizes the execution record. */ export declare function runConversation(opts: RunConversationOptions): Promise;