import type { HostContext } from './types.js'; /** 该路由的 pathname(客户端 logic/plugin-sync.ts 需保持一致)。 */ export declare const PLUGIN_SYNC_PATH = "/dsh-zh/api/plugin-sync"; /** * 参考 profile 的候选顺序:始终取**当前 profile 的另一侧**。 * 在 web 里跑即「桌面版 → 网页端」,在桌面版里跑即「网页端 → 桌面版」; * 其它自定义 profile 先试 web、再试 desktop(两者都是常见枢纽)。 */ export declare function sourceCandidates(target: string): string[]; /** 默认参考 profile(候选中的第一个;实际选用见 resolveSource)。 */ export declare function defaultSourceProfile(target: string): string; /** 单个条目要做的动作。 */ export type SyncAction = 'install' | 'enable' | 'upgrade'; /** 一个待同步条目。 */ export interface SyncEntry { name: string; /** 传给 pluginManager.installBundle 的安装 spec;enable 动作下为空串。 */ spec: string; /** 参考 profile 记录的值(版本范围、link: 地址等)。 */ requested: string; /** 当前 profile 记录的值;install 动作为 null。 */ current: string | null; action: SyncAction; /** 参考 profile 是否把该包选为 bundle。 */ bundle: boolean; } /** 因「当前版本不低于参考」而被跳过的条目(只取最高版本,不改动)。 */ export interface SyncSkippedEntry { name: string; /** 参考 profile 记录的值。 */ requested: string; /** 当前 profile 记录的值(更高或等价)。 */ current: string; } /** 差异计划。 */ export interface SyncPlan { source: string; target: string; /** 参考 profile 的 package.json 是否可读。 */ available: boolean; /** 不可用或不需同步时的说明。 */ reason: string | null; entries: SyncEntry[]; /** 两边一致的包名,仅用于界面计数。 */ current: string[]; /** 两边都有但当前版本不低于参考的包(同步只取最高版本,不降级)。 */ skipped: SyncSkippedEntry[]; } interface RouteRequest { method?: string; url?: string; } interface RouteResponse { statusCode: number; writeHead(status: number, headers?: Record): void; end(body?: string | Uint8Array): void; } /** * 计算同步差异:参考 profile 有、当前 profile 没有的包 → install; * 两边都有但**参考版本更高** → upgrade;版本等价但参考选了 bundle、当前未选 → enable。 * 两边都有且**当前版本不低于参考** → 归入 skipped(只取最高版本,绝不降级)。 * @param source 请求指定的参考 profile 名(可空,默认当前 profile 的另一侧)。 * @returns 可序列化的差异计划(不产生任何副作用)。 */ export declare function planPluginSync(source?: unknown): SyncPlan; /** 单条执行结果。 */ interface SyncItemResult { name: string; action: SyncAction; ok: boolean; /** pluginManager 观测到的落点:applied / restart-required / failed 等。 */ application: string | null; code: string | null; message: string | null; /** 该包等待显式允许的构建脚本名。 */ pendingBuilds: string[]; } interface SyncRunResult { ok: boolean; reason: string | null; source: string; target: string; results: SyncItemResult[]; /** 全部条目是否都已落地(failed / restart-required 视为未完成)。 */ complete: boolean; } /** * 执行同步:逐条调用官方 pluginManager(顺序执行——每次操作都会持 profile * 文件锁并触发一次 reload,并行没有收益且会让进度不可读)。 * @param ctx 主机上下文(惰性取 pluginManager)。 * @param plan 已计算的差异计划。 * @param options.only 只执行该包名的条目(界面「重试」用)。 * @param options.approvedBuilds 本次显式允许的构建脚本名(仅对指定包生效)。 * @returns 逐条结果;pluginManager 缺席或条目为空时 ok 为 false。 */ export declare function runPluginSync(ctx: HostContext, plan: SyncPlan, options?: { only?: unknown; approvedBuilds?: unknown; }): Promise; /** * GET /dsh-zh/api/plugin-sync → 差异计划 * POST /dsh-zh/api/plugin-sync → `{ source?, only?, approvedBuilds? }` 执行同步 * @returns 命中该路径并已响应时 true,供 /dsh-zh/api 分发调用。 */ export declare function handlePluginSyncRoute(req: RouteRequest, res: RouteResponse, pathname: string, payload: Record | null, ctx: HostContext): Promise; export {}; //# sourceMappingURL=plugin-sync.d.ts.map