import type { RestartConfig } from "./config.js"; import type { AutoUpdateConfig } from "./core/auto-update.js"; import { runCommand } from "./platform/command.js"; import { launchRestartWorker, type RestartWorkerLaunch } from "./restart-launcher.js"; import { type KeepAwakeStatus } from "./platform/keep-awake.js"; export interface EngineStatus { version: string; environment: string; startedAt: string; uptimeMs: number; runtimePath: string; } export interface EngineUpdateStatus { currentVersion: string; latestVersion: string; updateAvailable: boolean; } export interface EngineRestartRequest { botName: string; chatId?: string; scopeKey?: string; threadId?: string; wakeReplyTo?: string; updateVersion?: string; autoUpdate?: boolean; } export interface EngineRestartResult extends RestartWorkerLaunch { sourceDirectory: string; } /** Pipeline 只依赖这组 Engine 级能力,不接触 npm、配置文件或 restart worker。 */ export interface EngineLifecycle { getStatus(): EngineStatus; checkForUpdate(): Promise; predownloadUpdate(version: string): Promise; getAutoUpdateConfig(): AutoUpdateConfig | undefined; canPersistAutoUpdate(): boolean; setAutoUpdateEnabled(enabled: boolean): void; setTimezone(timezone: string): void; getKeepAwakeStatus(): KeepAwakeStatus; setKeepAwakeEnabled(enabled: boolean, options?: { persist?: boolean; }): Promise; /** 重启后恢复持久化的防休眠状态;无配置或已关闭时保持现状。 */ restoreKeepAwakeFromConfig(): Promise; restart(request: EngineRestartRequest): EngineRestartResult; } interface EngineLifecycleDependencies { runCommand: typeof runCommand; launchRestartWorker: typeof launchRestartWorker; now: () => Date; } export interface EngineLifecycleServiceOptions { version: string; startedAt: string; runtimePath: string; niubotHome: string; restartConfig?: RestartConfig; configPath?: string; initialAutoUpdateConfig?: AutoUpdateConfig; env?: NodeJS.ProcessEnv; onAutoUpdateConfigChanged?: () => void; dependencies?: Partial; } /** 唯一的进程级状态与生命周期动作所有者。 */ export declare class EngineLifecycleService implements EngineLifecycle { private readonly log; private readonly version; private readonly environment; private readonly legacySourceMode; private readonly startedAt; private readonly startedAtMs; private readonly runtimePath; private readonly niubotHome; private readonly restartConfig?; private readonly configPath?; private autoUpdateConfig?; private readonly env; private readonly onAutoUpdateConfigChanged?; private readonly dependencies; private readonly keepAwake; constructor(options: EngineLifecycleServiceOptions); getStatus(): EngineStatus; checkForUpdate(): Promise; predownloadUpdate(version: string): Promise; getAutoUpdateConfig(): AutoUpdateConfig | undefined; canPersistAutoUpdate(): boolean; setTimezone(timezone: string): void; setAutoUpdateEnabled(enabled: boolean): void; getKeepAwakeStatus(): KeepAwakeStatus; setKeepAwakeEnabled(enabled: boolean, options?: { persist?: boolean; }): Promise; /** Engine 启动时调用:读取持久化的 keepAwake 开关,开启则自动恢复。失败不阻断启动。 */ restoreKeepAwakeFromConfig(): Promise; restart(request: EngineRestartRequest): EngineRestartResult; private assertProductionUpdate; } export {};