import { type ScanLimits, type WorkspaceScanMeasurement } from "./file-candidates.js"; import { type InputAttachmentGrant } from "./input-attachments.js"; import { type Logger } from "./log.js"; import type { PreparedRuntimeSkillProvider } from "./runtime-skills.js"; import { type CourseRuntime, type RunEvent, type RunEventReceipt, type RunStartPayload } from "./types.js"; export interface RunDispatcherOptions { log?: Logger; scanLimits?: ScanLimits; now?: () => number; persistentSession?: PersistentSessionExecution; } export interface PreparedPersistentTurn { workspaceDir: string; transcriptFile: string; runtimeStateDir?: string; nativeSessionId: string | null; contextRevision: number; runtimeEnv?: NodeJS.ProcessEnv; inputAttachmentGrant?: InputAttachmentGrant; skillProvider?: PreparedRuntimeSkillProvider; } export interface PersistentSessionExecution { prepareTurn(payload: RunStartPayload): PreparedPersistentTurn; persistNativeSession(sessionId: string): void; finishTurn(payload: RunStartPayload): Promise; } export interface RunReportingClient { postEvent(agentRunId: string, event: RunEvent): Promise; postFiles(agentRunId: string, files: import("./types.js").RunFileCandidate[], truncated?: boolean, signal?: AbortSignal): Promise; recordWorkspaceScanMeasurement?(agentRunId: string, measurement: WorkspaceScanMeasurement): Promise | void; } /** * Run dispatcher:把 Course Service 下发的 run.start 交给 runtime, * 并把 runtime 输出归一化成 run.block / run.message / run.completed 回报 Course Service。 * * - 串行:同一 agent_instance 经 RunQueue 排队。 * - 取消:AbortController;runtime 抛错归一化为 run.failed。 * - daemon 不推进进度,只汇报事实。 */ export declare class RunDispatcher { private readonly client; private readonly runtimes; private readonly queue; private readonly inflight; private readonly scheduledRunIds; private readonly pendingCancellations; private readonly log; private readonly scanLimits?; private readonly now; private readonly persistentSession?; constructor(client: RunReportingClient, runtimes: Map, opts?: RunDispatcherOptions); /** 排队执行一个 run。返回的 Promise 不 reject(失败已归一化回报为 run.failed)。 */ dispatch(payload: RunStartPayload): Promise; cancel(agentRunId: string): boolean; cancelAll(): void; get activeCount(): number; /** Wait until the selected runs have left both the active and queued sets. */ waitForRuns(agentRunIds: Iterable, timeoutMs: number): Promise; /** 等待所有 run(含排队中的)结束;超时返回 false。 */ drain(timeoutMs: number): Promise; private execute; }