import type { RuntimeActivity, RuntimeMetadata } from "../runtime-activity.js"; import { type CourseRuntime, type RuntimeCompletionReason, type RuntimeFailureSummary, type RuntimeProgressDispositions, type RuntimeUsage, type RunStartPayload } from "../types.js"; import type { Logger } from "../log.js"; import type { ProgressReport } from "../mcp/report-progress.js"; import type { PreparedRuntimeSkillProvider, RuntimeSkillEvent } from "../runtime-skills.js"; /** * 内部引擎契约:CLI/ACP 基类实现的是 pull-style options + 回调, * 由 wrapEngineAdapter 折叠成对外的 CourseRuntime(sink 语义)。 */ export interface ContentStreamBlock { activity?: RuntimeActivity; raw: unknown; kind: "assistant_text" | "tool_use" | "tool_result" | "system" | "thinking" | "other" | "error"; seq: number; /** Assistant-visible text only. Provider raw payloads must never be used as browser text. */ text?: string; /** Safe provider-normalized tool identifier; arguments and results remain private. */ name?: string; status?: "completed" | "error"; } /** provider 已严格校验的进度块;禁止携带原始 tool envelope。 */ export interface ProgressStreamBlock { kind: "progress"; seq: number; progress: ProgressReport; } /** 底层 CLI 逐事件归一化出的块。seq 为本轮 1-based 单调递增。 */ export type StreamBlock = ContentStreamBlock | ProgressStreamBlock; export type RuntimeStatusEvent = { kind: "typing"; phase: "started" | "stopped"; } | { kind: "thinking"; phase: "started" | "updated" | "stopped"; label?: string; raw?: unknown; }; export interface EngineRunOptions { text: string; /** Learner input locale. Runtime adapters may select a matching versioned base prompt. */ locale?: string; /** Full durable conversation bootstrap, used only if a resumed native thread is missing. */ recoveryText?: string; /** runtime 原生会话 id(resume 用);null 表示新会话。 */ sessionId: string | null; cwd: string; /** Daemon-owned state directory for runtime metadata that the model must not mutate. */ runtimeStateDir?: string; signal: AbortSignal; extraArgs?: string[]; modelContract?: RunStartPayload["runtime"]["model_contract"]; systemContext?: string; /** Final backend-owned prompt for managed execution; applied verbatim. */ systemPrompt?: string; onBlock?: (block: StreamBlock) => void; onRuntimeMetadata?: (metadata: RuntimeMetadata) => Promise; onStatus?: (event: RuntimeStatusEvent) => void; env?: NodeJS.ProcessEnv; /** Control-side binding. Runtime adapters must not copy its credential into child env. */ skillProvider?: PreparedRuntimeSkillProvider; onSkillEvent?: (event: RuntimeSkillEvent) => Promise; } export interface EngineRunResult { text: string; newSessionId: string; /** Model identity returned by the runtime API for this turn. */ model?: string; costUsd?: number; usage?: RuntimeUsage; /** adapter 自身在 emit 前丢弃的进度计数;不包含 accepted,避免 dispatcher 重复计数。 */ progressDispositions?: RuntimeProgressDispositions; /** 非空表示硬失败;由包装层折叠为 RuntimeExecutionError。 */ error?: string; runtimeFailure?: Partial; /** Semantic successful handoff understood by Course, independent of provider tool names. */ completionReason?: RuntimeCompletionReason; } export interface EngineAdapter { readonly id: string; run(opts: EngineRunOptions): Promise; } export interface WrapEngineOptions { /** run.start.runtime.model → CLI 参数。缺省 (m) => ["--model", m]。 */ modelArgs?: (model: string) => string[]; } /** runtime 层默认 logger:stderr 文本行,debug 由 BOTLEARN_DAEMON_DEBUG 开门。 */ export declare const consoleLogger: Logger; /** 把内部 EngineAdapter 包装成对外 CourseRuntime。 */ export declare function wrapEngineAdapter(id: string, engine: EngineAdapter, opts?: WrapEngineOptions): CourseRuntime;