import type { ServerResponse } from 'node:http'; export interface CaptureMeta { /** 适配器名称(仅适配器请求) */ adapterName?: string; /** 上游供应商名称,如 "deepseek" */ upstreamProvider?: string; /** 上游供应商协议,如 "openai" */ upstreamProtocol?: string; /** 上游供应商模型 ID,如 "deepseek-chat" */ upstreamModel?: string; } export interface CaptureEntry extends CaptureMeta { id: number; timestamp: number; /** 从创建抓包记录到响应完整写回客户端的耗时(毫秒) */ durationMs: number | null; /** 来源:proxy(代理入口)或适配器名称 */ source: string; /** 代理端协议 */ protocol: string; /** 代理端模型 */ model: string; pairId: number; /** 客户端→代理(原始请求) */ requestIn: string | null; /** 代理→上游(转换后请求) */ requestOut: string | null; /** 上游→代理(原始响应) */ responseIn: string | null; /** 代理→客户端(转换后响应) */ responseOut: string | null; } export declare class CaptureBuffer { private buffer; private nextId; private nextPairId; private maxSize; /** * 抓包 SSE 订阅者集合。 * 使用 Map 跟踪每个订阅者的最近活跃时间, * 以便后续 pruneStaleSubscribers() 主动剔除长时间无活动的死连接。 */ private subscribers; /** 订阅者空闲超时(毫秒)——超过此时长无活动则从集合中移除 */ private subscriberIdleTimeoutMs; /** 定期清理周期(毫秒) */ private subscriberPruneIntervalMs; private pruneTimer; /** pairId → CaptureEntry 的快速索引 */ private entryMap; private _enabled; constructor(maxSize?: number); isEnabled(): boolean; enable(): void; disable(): void; /** 更新缓冲区上限,并立即淘汰超出的旧记录。 */ setMaxSize(maxSize: number): void; clear(): void; /** 创建一条新请求的抓包记录,返回 pairId */ startRequest(source: string, protocol: string, model: string, meta?: CaptureMeta): number; /** 更新已有记录某个阶段的数据 */ updateRequest(pairId: number, field: 'requestIn' | 'requestOut' | 'responseIn' | 'responseOut', data: string): void; getAll(): CaptureEntry[]; subscribe(res: ServerResponse): void; /** 主动清理已死亡/被销毁的 subscriber,防止句柄 + 内部 buffer 泄漏 */ private pruneDeadSubscribers; /** * 清理长时间无活动的 subscriber。 * close 事件不可靠,部分场景(如反代超时中断、NAT 重建)下永远不会触发。 * 定期清理可保证即使完全静默断开也能被回收,避免句柄和缓冲区累积泄漏。 */ private pruneStaleSubscribers; private isSubDead; private notifySubscribers; /** 释放定时器等资源(测试用) */ destroy(): void; } //# sourceMappingURL=capture.d.ts.map