Skip to content

feat: make adapters protocol agnostic - #212

Merged
maplezzk merged 1 commit into
mainfrom
codex/adapter-protocol-agnostic
Aug 1, 2026
Merged

maplezzk merged 1 commit into
mainfrom
codex/adapter-protocol-agnostic

Conversation

@maplezzk

@maplezzk maplezzk commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Summary\n\n- remove the adapter-level protocol field while keeping legacy YAML readable\n- make adapters accept OpenAI Chat, OpenAI Responses, and Anthropic requests\n- add model dropdown and protocol selection to adapter test panels in the React admin UI and macOS app\n- update adapter test routing, API contracts, documentation, and regression coverage\n\n## Verification\n\n-

@maplezzk/llm-proxy@0.28.3 test
node --import tsx --test test/**/*.test.ts

▶ adapter/handlers
✔ 通过适配器端点转发请求成功 (38.777583ms)
✔ 适配器名称不存在返回 404 (2.784708ms)
✔ 模型映射不存在返回 404 (1.416458ms)
✔ 非 JSON 请求体返回 400 (1.251041ms)
✔ Anthropic 格式适配器端点 (3.2895ms)
✔ 按实际请求协议选择多协议供应商的同协议上游 (8.913208ms)
✔ 请求体缺少 model 字段返回 400 (1.788542ms)
✔ 映射的 Provider 不存在返回 502 (1.382167ms)
✔ adapter/handlers (67.937875ms)
▶ adapter/router
✔ 同协议映射到 Anthropic Provider (0.71125ms)
✔ 无协议绑定时按目标 Provider 协议作为默认入站协议 (0.107625ms)
✔ 实际请求协议优先于适配器默认协议 (0.086917ms)
✔ 适配器名称不存在时抛错 (0.215666ms)
✔ 工具模型名在适配器映射中不存在时抛错 (0.06475ms)
✔ 映射的 Provider 不存在时抛错 (0.067125ms)
✔ 映射的 Model 在 Provider 中不存在时抛错 (0.076458ms)
✔ 传递 target model 的 input 模态到 route(用于外挂识图判断) (0.8445ms)
✔ adapter/router (2.88675ms)
▶ admin UI handoff bootstrap
✔ removes the code before exchange and stores the returned credential (1.220333ms)
✔ falls back to manual entry after an exchange failure (0.247ms)
✔ ignores normal tab fragments (0.072708ms)
✔ admin UI handoff bootstrap (2.159958ms)
▶ admin UI client settings
✔ resolves root and reverse-proxy management paths (0.775875ms)
✔ isolates credentials for services mounted below different paths (0.098083ms)
✔ migrates the legacy origin-wide credential to the current path (0.094875ms)
✔ treats an available but empty persistent store as persistent (0.072625ms)
✔ falls back to session memory when persistent storage is unavailable (0.064709ms)
✔ accepts only high-entropy handoff fragments (0.828417ms)
✔ admin UI client settings (2.6755ms)
(node:61903) ExperimentalWarning: SQLite is an experimental feature and might change at any time
(Use node --trace-warnings ... to show where the warning was created)
▶ admin API authentication
✔ rejects missing or invalid admin credentials (14.154292ms)
✔ accepts Bearer and x-api-key admin credentials (1.947375ms)
✔ serves the admin UI shell without credentials so a browser can enter its key (12.302334ms)
✔ does not apply admin authentication to proxy routes or CORS preflight (1.130667ms)
✔ issues an authenticated one-time handoff and exchanges it without putting the key in the URL (22.247292ms)
✔ expires handoff codes and invalidates them after key rotation (0.230917ms)
✔ admin API authentication (64.129833ms)
▶ api/handlers
✔ GET /admin/config 返回脱敏配置 (0.635709ms)
✔ POST /admin/providers 支持创建多协议供应商 (6.299083ms)
✔ 保存多协议供应商时清除旧版 type 和 api_base (1.930958ms)
✔ POST /admin/adapters 不需要协议字段且保存时不写入协议 (1.538875ms)
✔ GET /admin/health 返回 ok (0.118292ms)
✔ POST /admin/config/reload 失败时返回错误 (0.2405ms)
✔ GET /admin/status/providers 返回结构 (0.129333ms)
✔ GET /admin/locale 返回默认 locale en (0.063791ms)
✔ GET /admin/locale 返回配置中的 locale (0.082709ms)
✔ PUT /admin/locale 设置 locale 为 zh (1.114709ms)
✔ PUT /admin/proxy-key 热更新运行时配置且保留其他配置 (2.051125ms)
✔ PUT /admin/locale 无效参数返回 400 (0.520875ms)
✔ api/handlers (16.083667ms)
(node:61905) ExperimentalWarning: SQLite is an experimental feature and might change at any time
(Use node --trace-warnings ... to show where the warning was created)
▶ config hot reload
✔ 修改端口后服务自动重绑定,无需重启进程 (74.294875ms)
✔ 重载配置后同步日志级别、语言和抓包容量 (10.713583ms)
Configuration reloaded (version: 1)
Configuration reloaded (version: 2)
✔ CLI reload 可使用当前密钥轮换并删除 admin_key (13.319875ms)
✔ config hot reload (99.24775ms)
▶ integration
✔ OpenAI 格式 → 非流式 → 同协议转发 (53.368583ms)
✔ OpenAI 格式 → 流式 → 同协议 (4.5295ms)
✔ 多协议模型:OpenAI 入站优先直通 OpenAI 上游 (5.395792ms)
✔ 多协议模型:Anthropic 入站优先直通 Anthropic 上游 (6.908417ms)
✔ Anthropic 格式 → 非流式 → 跨协议响应转换 (2.8615ms)
✔ Anthropic 格式 → 流式 → 跨协议 SSE 转换 (1.96325ms)
✔ 管理 API: GET /admin/health (0.974125ms)
✔ 管理 API: GET /admin/config 返回原始 Key (1.174208ms)
✔ 不存在的 model name 返回 404 (8.947125ms)
✔ 适配器端点同协议转发成功 (2.252875ms)
✔ 适配器名称不存在返回 404 (0.958875ms)
✔ 管理 API: GET /admin/adapters 返回适配器列表 (0.862542ms)
✔ 管理 API: 适配器测试可选择入站协议 (9.861834ms)
✔ POST /v1/responses → 非流式 → 同协议返回 Responses 格式 (3.724292ms)
✔ POST /v1/responses → 流式 → 同协议 SSE 穿透 (2.277125ms)
✔ POST /v1/responses → 跨协议 → Anthropic 格式返回 (1.946458ms)
✔ POST /v1/responses → 跨协议 → 流式 SSE 转换 (2.178625ms)
✔ /v1/responses 不存在的 model 返回 404 (0.785709ms)
✔ /v1/responses 缺少 model 返回 400 (0.601875ms)
✔ 适配器端点 /my-tool/v1/responses 转发成功 (1.285375ms)
✔ Mock 上游收到正确的 Responses/Chat/Messages 请求 (0.116917ms)
✔ integration (122.177958ms)
(node:61907) ExperimentalWarning: SQLite is an experimental feature and might change at any time
(Use node --trace-warnings ... to show where the warning was created)
▶ api/server 超时配置(防止 socket 累积)
✔ createProxyServer 设置了 keepAliveTimeout / headersTimeout / requestTimeout / timeout (6.432791ms)
✔ server.timeout = 0 允许流式响应持续数分钟不被 kill (1.773833ms)
✔ api/server 超时配置(防止 socket 累积) (8.810584ms)
cli.start.sigterm
cli.start.sigterm
cli.start.sigterm
cli.start.sigterm
▶ cli/commands
✔ 模块可正常加载且导出命令函数 (0.950125ms)
✔ cmdReload 参数接口正确 (0.127625ms)
✔ cmdStart 参数接口正确 (0.094375ms)
▶ installShutdownHandlers
✔ SIGTERM 触发后即使 visionCache.flushSync 抛错,仍调用 process.exit(0) (1.146917ms)
✔ SIGINT 触发后即使 server.close 抛错,仍调用 process.exit(0) (0.284917ms)
✔ 正常路径:所有清理步骤依次执行 (0.300125ms)
✔ 旧进程退出时不应删除新实例的 PID 文件 (1.169541ms)
✔ installShutdownHandlers (3.081833ms)
✔ cli/commands (4.944917ms)
▶ config/parser
✔ 解析有效 YAML 配置 (4.359333ms)
✔ 环境变量插值正确替换 (1.198083ms)
✔ 解析并序列化独立的管理 API 密钥 (2.344875ms)
✔ 未定义环境变量抛错 (1.767125ms)
✔ YAML 语法错误抛错 (9.524542ms)
✔ 缺失必要字段正常解析(校验交由 validator 处理) (4.943667ms)
✔ 解析 Anthropic thinking 配置 (0.482375ms)
✔ 解析 OpenAI reasoning_effort 配置 (0.359834ms)
✔ 解析适配器 thinking 配置 (1.558875ms)
✔ 解析 thinking.type 配置(MiniMax adaptive) (0.769334ms)
✔ 解析多协议供应商及模型协议 (0.805709ms)
✔ 序列化多协议供应商时保留协议和模型绑定 (0.351208ms)
✔ config/parser (34.11325ms)
▶ config/store
✔ 创建 Store 并获取初始配置 (0.518458ms)
✔ reload 失败不影响运行时配置 (0.212958ms)
✔ 初始版本号为 0 (0.056583ms)
✔ config/store (1.431042ms)
▶ config/validator
✔ 有效配置通过校验 (0.970083ms)
✔ 重复 Provider name 报错 (0.144584ms)
✔ 重复 Model name 报错 (0.084417ms)
✔ 空 API Key 报错 (0.069292ms)
✔ 无效 Provider type 报错 (0.068166ms)
✔ 同时多个错误返回所有错误 (0.053708ms)
✔ Provider name 非法字符报错 (0.048083ms)
✔ Model name 含冒号(微调模型)应通过 (0.0445ms)
✔ 空 providers 数组应报错 (0.060583ms)
✔ providers 非数组应报错 (0.084666ms)
✔ Model 对象缺失 id 字段应报错 (0.061917ms)
✔ Anthropic 模型 valid thinking 配置通过 (0.052041ms)
✔ Anthropic 模型 budget_tokens 为 0 报错 (0.055ms)
✔ Anthropic 模型仅 type 配置通过 (0.050542ms)
✔ Anthropic 模型无效 type 报错 (0.054875ms)
✔ Anthropic 模型设置 reasoning_effort 通过 (0.040625ms)
✔ OpenAI 模型 valid reasoning_effort 通过 (0.037375ms)
✔ reasoning_effort 支持 xhigh 和 max (0.052917ms)
✔ OpenAI 模型无效 reasoning_effort 报错 (0.062583ms)
✔ OpenAI 模型不能设置 budget_tokens (0.042125ms)
✔ 多协议供应商校验模型支持的协议 (15.080291ms)
✔ config/validator (19.164917ms)
▶ sanitizeApiBase
✔ 去除末尾的 /v1 (0.742333ms)
✔ 去除末尾的 /v1/(带斜杠) (0.128959ms)
✔ 大小写不敏感 — /V1 (0.048625ms)
✔ 不含 /v1 时不变 (0.042042ms)
✔ 仅去末尾斜杠 (0.042416ms)
✔ v1 不在末尾时不触发 — /v1/models (0.051417ms)
✔ v1 在中间时不触发 — /v1/extra (0.037917ms)
✔ 空字符串 (0.04775ms)
✔ 仅 /v1 (0.072375ms)
✔ sanitizeApiBase (1.8685ms)
▶ log/logger
✔ 记录系统事件日志 (6.34175ms)
✔ 默认 level 为 info (0.150792ms)
✔ 设置为 debug 级别时记录所有日志 (0.078958ms)
✔ 设置为 warn 级别时不记录 info 和 debug (0.069458ms)
✔ 设置为 error 级别时只记录 error (0.111625ms)
✔ getLogs 支持 level 过滤 (0.150083ms)
✔ 记录请求日志 (0.058375ms)
✔ getLogs 返回最新的日志在前 (5.54325ms)
✔ 超过 maxEntries 自动裁剪 (0.114791ms)
✔ before 参数过滤 (0.13725ms)
✔ getStats 返回统计 (0.066459ms)
✔ 从文件回读日志(新格式含级别) (1.889583ms)
✔ getLogs 按日期筛选 (6.758458ms)
✔ getLogs 日期查询:内存满了之后从文件补 (1.118458ms)
✔ getLogs 日期查询:内存有数据但当日日志文件不存在 (0.929833ms)
✔ 从文件回读日志(旧格式无级别,默认 info) (0.956292ms)
✔ log/logger (25.383916ms)
▶ proxy/capture
✔ startRequest 创建一条记录,返回 pairId (0.811458ms)
✔ updateRequest 更新指定阶段的数据 (0.123417ms)
✔ updateRequest 不存在的 pairId 静默忽略 (0.054916ms)
✔ startRequest 携带 meta 信息 (0.071666ms)
✔ getAll 返回副本,不受后续修改影响 (0.056959ms)
▶ enabled 开关
✔ 默认 enabled = false (0.074541ms)
✔ disable 后 isEnabled 返回 false (0.062666ms)
✔ enable 后恢复 true (0.0555ms)
✔ enable/disable 不影响正常记录功能 (0.069041ms)
✔ enabled 开关 (0.388125ms)
▶ clear
✔ 清空所有记录 (0.117959ms)
✔ clear 后 updateRequest 无效(pairId 已不存在) (0.072583ms)
✔ clear (0.267792ms)
▶ maxSize
✔ setMaxSize 热更新上限并立即淘汰旧记录 (0.771833ms)
✔ 超过 maxSize 时淘汰旧记录 (0.067041ms)
✔ 淘汰后旧 pairId 无法再 updateRequest (0.047875ms)
✔ maxSize (0.94075ms)
▶ subscribe / 通知
✔ subscribe 后新记录会推送给订阅者 (0.188584ms)
✔ 订阅者 close 后自动移除 (0.059667ms)
✔ 多个订阅者同时接收通知 (0.067458ms)
✔ subscribe / 通知 (0.363167ms)
▶ 内存泄漏防护(死 subscriber 清理)
✔ destroyed=true 的 subscriber 在下次 notify 时被清理 (0.095084ms)
✔ writableEnded=true 的 subscriber 在下次 notify 时被清理 (0.041209ms)
✔ writable=false 的 subscriber 在下次 notify 时被清理 (0.070667ms)
✔ 混合健康/死亡 subscriber:只推送给健康的 (0.088375ms)
✔ write 抛错的 subscriber 在下次 notify 时被清理 (0.065625ms)
✔ 反压时(write 返回 false)跳过本次写入但不清理 subscriber (0.053125ms)
✔ 内存泄漏防护(死 subscriber 清理) (0.480458ms)
▶ 长时间空闲 subscriber 防护
✔ 超过空闲阈值的 subscriber 在 pruneStaleSubscribers 时被清理 (0.084959ms)
✔ 活跃的 subscriber(lastSeen 在阈值内)不被清理 (0.030875ms)
✔ 同时清除死亡 + 空闲 subscriber (0.050083ms)
✔ notifySubscribers 后更新 lastSeen 防止误清理 (0.041041ms)
✔ 构造函数启动 pruneTimer(unref 不阻止进程退出) (0.077292ms)
✔ 长时间空闲 subscriber 防护 (0.344417ms)
✔ proxy/capture (4.672792ms)
▶ proxy/responses-protocol — Anthropic → OpenAI Responses (inbound)
✔ user 字符串消息 → input.message.input_text (3.173875ms)
✔ user 数组 content (text 块) → message with input_text(必须是 input_text,不是 text) (0.6805ms)
✔ user 数组 content (image 块 + text 块) → input_image + input_text (6.716625ms)
✔ user 数组 content (image base64) → input_image with data URL (0.105334ms)
✔ assistant 字符串消息 → message (string content,Responses 接受) (0.36575ms)
✔ assistant 数组 content (text + tool_use) → output_text + function_call(必须 output_text) (14.496959ms)
✔ assistant 数组 content (thinking + text) → reasoning + message (output_text) (2.071416ms)
✔ Anthropic → Responses:Responses response 反向 → Anthropic thinking.signature 是上游 encrypted_content (5.040084ms)
✔ tool_result 纯字符串 → function_call_output with string output (0.223875ms)
✔ tool_result 含 image → computer_call_output (0.177417ms)
✔ system 字符串 → instructions (0.078917ms)
✔ max_tokens → max_output_tokens (0.059042ms)
✔ Responses 协议专有字段透传:store / include / metadata / parallel_tool_calls / previous_response_id (0.075542ms)
✔ Chat → Responses:parallel_tool_calls 透传 (0.098375ms)
✔ Chat → Responses:metadata 透传 (0.06225ms)
✔ tool_choice any → required (0.207917ms)
✔ tool_choice auto → auto (0.065375ms)
✔ tool_choice tool 指定 → {type:"function",name} (0.044292ms)
✔ Anthropic function tool → Responses 扁平 function format (0.052667ms)
✔ reasoning effort 通过 thinking → reasoning.effort 映射 (0.062167ms)
✔ proxy/responses-protocol — Anthropic → OpenAI Responses (inbound) (38.279625ms)
▶ proxy/responses-protocol — OpenAI Chat → OpenAI Responses (inbound)
✔ 字符串 user 消息 → message with string content (0.071584ms)
✔ 字符串 assistant 消息 → message with string content (0.037708ms)
✔ Chat image_url 块 → Responses input_image (string url) (0.060084ms)
✔ Chat image_url with object form → input_image (string url extracted) (0.038375ms)
✔ Chat tool message → function_call_output (0.054791ms)
✔ Chat tool_calls → function_call item (arguments 保持 JSON 字符串) (0.041792ms)
✔ Chat reasoning_content → 顶层 reasoning.effort 不变(应通过 reasoning 字段传递) (0.040125ms)
✔ proxy/responses-protocol — OpenAI Chat → OpenAI Responses (inbound) (0.41775ms)
▶ proxy/responses-protocol — OpenAI Responses → Anthropic (inbound)
✔ 单字符串 input → user message with string content (0.280375ms)
✔ input 数组 message (string content) → user message (0.142917ms)
✔ input 数组 message (input_text 块) → Anthropic text (0.082333ms)
✔ input 数组 input_image (string url) → Anthropic image block (0.065459ms)
✔ input 数组 input_image (file_id) → 占位文本 (0.092ms)
✔ input 数组 function_call → assistant message with tool_use (0.091334ms)
✔ input 数组 function_call_output (string) → tool message (0.065ms)
✔ input 数组 parallel function_call_output → 单 user 消息含多个 tool_result (0.060166ms)
✔ input 数组 reasoning item → skip(不产生消息) (0.037916ms)
✔ input 数组 message 混合 string + array content 都被规范化 (0.040292ms)
✔ input 数组含 system message → 不出现在 messages(应映射到 system 字段) (0.044417ms)
✔ instructions → Anthropic system (0.051167ms)
✔ unknown item type → pass through(不应崩) (0.037167ms)
✔ input 数组 message content 是 object(不规范)→ 不崩 (0.0345ms)
✔ input 是空数组 → 跨协议路由到 Chat 上游时不发空 messages(占位 user message) (0.172041ms)
✔ input 是空数组 → 路由到 Responses 上游时透传 input=[] (0.041625ms)
✔ proxy/responses-protocol — OpenAI Responses → Anthropic (inbound) (1.502917ms)
▶ proxy/responses-protocol — OpenAI Responses → OpenAI Chat (inbound)
✔ input 字符串 → messages[0].content 字符串 (0.067125ms)
✔ input 数组 message (input_text) → user message with text content (0.035333ms)
✔ input 数组 input_image (string) → Chat image_url block (0.096041ms)
✔ input 数组 function_call → Chat tool_calls (0.084542ms)
✔ input 数组 function_call_output → Chat tool message (0.070292ms)
✔ input 数组含 reasoning item → 不出现 reasoning_content(除非有显式字段) (0.050708ms)
✔ proxy/responses-protocol — OpenAI Responses → OpenAI Chat (inbound) (0.546458ms)
▶ proxy/responses-protocol — OpenAI Responses → OpenAI Responses (same)
✔ 完整 body 保真转发 + 替换 model (0.071708ms)
✔ 保留 input array 中的 input_text 块(同协议) (0.034125ms)
✔ proxy/responses-protocol — OpenAI Responses → OpenAI Responses (same) (0.142167ms)
▶ proxy/responses-protocol — OpenAI Chat → OpenAI Chat (same)
✔ 字符串 content 保真 (0.046042ms)
✔ 不应规范化 Chat 风格请求中的 input_text(用户错误契约) (0.026875ms)
✔ proxy/responses-protocol — OpenAI Chat → OpenAI Chat (same) (0.103834ms)
▶ proxy/responses-protocol — Responses response conversion
▶ Responses body → Anthropic body
✔ message output_text → text block (0.224ms)
✔ function_call → tool_use (arguments 解析为 object) (0.06625ms)
✔ 空 arguments 字符串 → 空 object (0.03675ms)
✔ 顶层 reasoning.summary → thinking block(作为首个 content block) (0.051334ms)
✔ refusal content → text block (0.038666ms)
✔ status=incomplete + reason=max_output_tokens → stop_reason=max_tokens (0.035167ms)
✔ status=failed → 应传播为错误(当前实现:宽容映射为 end_turn) (0.031125ms)
✔ Responses body → Anthropic body (0.548334ms)
▶ Responses body → Chat body
✔ output_text → content string (0.156125ms)
✔ function_call → tool_calls (0.072917ms)
✔ 顶层 reasoning.summary → reasoning_content (0.0445ms)
✔ usage: cached_tokens → prompt_tokens 包含缓存 + details (0.055333ms)
✔ Responses body → Chat body (0.390458ms)
▶ Anthropic body → Responses body
✔ text → output_text;thinking → 顶层 reasoning.summary (0.0885ms)
✔ tool_use → function_call item(canonical JSON 字符串 arguments) (0.068291ms)
✔ tool_use input 已是 string 时不重复 stringify(避免双重转义) (0.04825ms)
✔ computer tool_use → computer_call output item (0.078667ms)
✔ stop_reason=max_tokens → status=incomplete (12.125625ms)
✔ usage 透传 + cache_read/cache_create 归一化 (0.078166ms)
✔ Anthropic body → Responses body (12.586542ms)
▶ Chat body → Responses body
✔ content string + tool_calls → message(output_text) + function_call items (0.204166ms)
✔ reasoning_content → 顶层 reasoning.summary (0.049416ms)
✔ Chat body → Responses body (0.301875ms)
▶ Anthropic body → Chat body(已有覆盖,补充 Responses 关联)
✔ thinking + text + tool_use → reasoning_content + content + tool_calls (1.129125ms)
✔ Anthropic body → Chat body(已有覆盖,补充 Responses 关联) (1.178208ms)
✔ proxy/responses-protocol — Responses response conversion (15.117042ms)
▶ proxy/responses-protocol — Responses SSE → Anthropic SSE
✔ 完整生命周期:created → output_item.added → output_text.delta → output_text.done → completed (6.173125ms)
✔ reasoning_text.delta → thinking_delta(固定 index=0) (0.336ms)
✔ response.function_call_arguments.delta → input_json_delta (0.17475ms)
✔ computer_call.output_item.added → tool_use(name=computer) with action mapping (0.156667ms)
✔ refusal content → text block (0.112292ms)
✔ response.failed → error event (0.074084ms)
✔ response.incomplete + reason=max_output_tokens → stop_reason=max_tokens (0.098583ms)
✔ usage 缓存 token 透传到 Anthropic usage (0.094875ms)
✔ 上游 response.reasoning.encrypted_content 作为 thinking signature(多轮 reasoning) (0.142167ms)
✔ output_item.added reasoning → 开启 thinking block(不丢 reasoning) (0.111ms)
✔ proxy/responses-protocol — Responses SSE → Anthropic SSE (7.577333ms)
▶ proxy/responses-protocol — Anthropic SSE → Responses SSE
✔ message_start → response.created + response.in_progress + response.output_item.added (0.491625ms)
✔ thinking_delta → response.reasoning_text.delta + 顶层 reasoning.summary in completed (0.426166ms)
✔ tool_use → function_call + arguments delta (0.341291ms)
✔ computer tool_use → computer_call output item (0.1915ms)
✔ namespace 工具 mcp__xxx__yyy → 解码为 function_call with namespace field (0.234417ms)
✔ proxy/responses-protocol — Anthropic SSE → Responses SSE (1.802083ms)
▶ proxy/responses-protocol — Chat SSE → Responses SSE
✔ role delta → response.created + output_item.added (0.488417ms)
✔ reasoning_content delta → response.reasoning_text.delta (0.200542ms)
✔ tool_calls delta → response.function_call_arguments.delta (0.266417ms)
✔ proxy/responses-protocol — Chat SSE → Responses SSE (1.018542ms)
▶ proxy/responses-protocol — Responses SSE → Chat SSE
✔ output_text.delta → content delta + finish_reason=stop (0.473125ms)
✔ reasoning_text.delta → reasoning_content delta (0.316084ms)
✔ function_call → tool_calls + finish_reason=tool_calls (0.180084ms)
✔ cache_read_input_tokens 计入 prompt_tokens + details (0.126167ms)
✔ cache_creation_input_tokens 透传到 Responses → Chat 流式 usage (0.098833ms)
✔ proxy/responses-protocol — Responses SSE → Chat SSE (1.263333ms)
▶ proxy/router
✔ 通过 model name 匹配到 Anthropic Provider (0.599084ms)
✔ 通过 model name 匹配到 OpenAI Provider (0.1855ms)
✔ 使用自定义 apiBase (0.06375ms)
✔ 不存在的 model name 抛错 (0.604666ms)
✔ 模型包含 thinking 配置时正确传递 (0.081083ms)
✔ 模型无 thinking 配置时返回 undefined (0.053958ms)
✔ 同一供应商的不同模型可路由到不同协议和 apiBase (0.143708ms)
✔ proxy/router (2.388042ms)
▶ proxy/stream-converter
▶ Anthropic SSE → OpenAI SSE (convertAnthropicStreamToOpenAI)
✔ text_delta → delta.content (3.958833ms)
✔ input_json_delta → tool_calls arguments (0.241041ms)
✔ message_delta stop_reason 映射 (0.346375ms)
✔ cache_read_input_tokens / cache_creation_input_tokens 透传到 prompt_tokens_details (0.382125ms)
✔ ping 事件被忽略 (0.161125ms)
✔ thinking_delta → reasoning_content (0.306167ms)
✔ Anthropic SSE → OpenAI SSE (convertAnthropicStreamToOpenAI) (5.832ms)
▶ OpenAI SSE → Anthropic SSE (convertOpenAIStreamToAnthropic)
✔ role + content 事件 → content_block_start + text_delta (1.131834ms)
✔ tool_calls → input_json_delta (0.31225ms)
✔ reasoning + text + tool_use:text 块必须在 tool_use 前补发 content_block_stop (1.298084ms)
✔ reasoning_content → thinking_delta (content_block_start/stop 配对) (2.522291ms)
✔ 供应商不发送 [DONE] 时也能正确发送 message_stop(如 MiniMax) (0.165125ms)
✔ usage-only chunk (choices=[]) 补发 usage 时应正确转发(finish_reason chunk usage 为 0) (0.213125ms)
✔ finish_reason chunk 不带 usage,usage-only chunk 补发 (0.17525ms)
✔ cached_tokens=0 时 message_delta 不应包含 cache_read_input_tokens 字段 (0.118459ms)
✔ usage 嵌在 choices[0] 内(如 Kimi k3)时也能正确提取 (0.572041ms)
✔ OpenAI SSE → Anthropic SSE (convertOpenAIStreamToAnthropic) (6.802084ms)
▶ OpenAI Responses SSE → Anthropic SSE
✔ output_text.delta → text_delta (0.731042ms)
✔ 每个内容块只关闭一次,缺失 *.done 时在 completed 补齐 (0.369083ms)
✔ function_call_arguments.delta → input_json_delta (0.19325ms)
✔ reasoning_text.delta → thinking_delta (带 content_block_start) (0.296ms)
✔ computer_call → tool_use (computer) with action conversion (0.270375ms)
✔ OpenAI Responses SSE → Anthropic SSE (1.957083ms)
▶ OpenAI Responses SSE → OpenAI Chat SSE
✔ Responses 缓存命中计入 Chat prompt_tokens,并保留 details (0.367292ms)
✔ OpenAI Responses SSE → OpenAI Chat SSE (0.407459ms)
▶ Anthropic SSE → OpenAI Responses SSE
✔ text_delta → output_text.delta (0.611166ms)
✔ thinking_delta → reasoning_text.delta (with top-level reasoning.summary) (0.251625ms)
✔ tool_use (computer) → computer_call output_item (0.313334ms)
✔ Anthropic SSE → OpenAI Responses SSE (1.252042ms)
▶ 客户端断连防护(AbortSignal)
✔ signal 已 abort 时,convertAnthropicStreamToOpenAI 立即返回且 cancel reader (0.202542ms)
✔ signal 在中途 abort 时,convertOpenAIStreamToAnthropic 提前退出 (41.628042ms)
✔ signal abort 防止处理剩余 chunk(不写 [DONE]) (43.050625ms)
✔ 客户端断连防护(AbortSignal) (85.029417ms)
✔ proxy/stream-converter (101.800541ms)
▶ proxy/translation
▶ 同协议转发
✔ Anthropic → Anthropic 保真传递 + 替换 model (0.699666ms)
✔ OpenAI → OpenAI 保真传递 + 替换 model (0.138792ms)
✔ Anthropic → Anthropic 同协议:built-in tools 透传 (0.118334ms)
✔ 同协议转发 (1.301417ms)
▶ 跨协议翻译 — OpenAI → Anthropic
✔ 基础参数映射 (0.8445ms)
✔ System message → Anthropic system 参数 (0.093166ms)
✔ Tool 格式转换 (0.180209ms)
✔ 跨协议翻译 — OpenAI → Anthropic (1.222583ms)
▶ 跨协议翻译 — OpenAI Responses → Anthropic
✔ input 字符串 → messages + instructions → system + max_output_tokens → max_tokens (0.375542ms)
✔ input 数组(消息列表)转换为 Anthropic messages (0.185208ms)
✔ tools 转换为 Anthropic tool 格式 (0.263291ms)
✔ built-in tool: computer_use_preview → Anthropic computer_20251124 (0.114ms)
✔ built-in tool: web_search_preview / code_interpreter / file_search → 被过滤(无 Anthropic 等效工具) (0.267459ms)
✔ built-in tool: 混合 function + computer_use_preview (0.110709ms)
✔ computer_call_output input → Anthropic tool_result with image (0.155ms)
✔ 跨协议翻译 — OpenAI Responses → Anthropic (1.650833ms)
▶ 同协议转发 — OpenAI Responses → OpenAI Responses
✔ Responses → Responses 保真传递 + 替换 model (0.074833ms)
✔ Responses → Responses 同协议:built-in tools 透传 (0.054459ms)
✔ 同协议转发 — OpenAI Responses → OpenAI Responses (0.162ms)
▶ 跨协议翻译 — Anthropic → OpenAI Responses
✔ user message 带 tool_result(含 image)→ computer_call_output (0.266917ms)
✔ Anthropic function tool 和 tool_choice → Responses 扁平格式 (0.180333ms)
✔ OpenAI Chat function tool → Responses 扁平格式 (0.068834ms)
✔ 跨协议翻译 — Anthropic → OpenAI Responses (0.565792ms)
▶ 跨协议翻译 — Anthropic → OpenAI
✔ 基础参数映射 (0.259208ms)
✔ System 参数 → messages 首条 system message (0.057792ms)
✔ Tool 格式转换 (0.062875ms)
✔ built-in tool: computer_20251124 → OpenAI computer_use_preview (0.048083ms)
✔ built-in tool: bash + text_editor → 被过滤(无 OpenAI 等效工具) (0.054875ms)
✔ Anthropic assistant thinking + text 内容块 → OpenAI reasoning_content + content 字符串 (0.089208ms)
✔ Anthropic thinking + tool_use 共存时 reasoning_content 不丢失 (0.089ms)
✔ 助手消息 tool_calls → content 中 tool_use 块(有 reasoning) (0.145041ms)
✔ 助手消息 tool_calls → content 中 tool_use 块(无 reasoning) (0.066458ms)
✔ 并行 tool_calls 转为多个 tool_use 块,连续 tool 消息合并为单个 user 消息 (0.087209ms)
✔ 单 tool_result 不合并——前后有非 tool 消息 (0.065417ms)
✔ Anthropic user message 含 base64 image → OpenAI image_url 拼 data URI 前缀 (0.087625ms)
✔ Anthropic user message 含 URL image → OpenAI image_url 保留原 URL (0.0415ms)
✔ Anthropic tool message 含 base64 image → OpenAI tool message 含 image_url 块(不再降级文本) (0.094667ms)
✔ OpenAI Chat tool message 含 image_url 块 → Anthropic tool_result 用 image 块(不再原样转发) (0.094916ms)
✔ OpenAI Chat user message 含 image_url 块 → Anthropic user image 块 (0.053167ms)
✔ OpenAI Chat user message 含 image_url → Responses input_image(image_url 变 string) (0.095542ms)
✔ Responses input_image with file_id → Anthropic [image:file_id=xxx] 占位文本 (0.064291ms)
✔ Responses input_image with image_url object { url, detail } → Anthropic image URL (0.04975ms)
✔ 跨协议翻译 — Anthropic → OpenAI (1.770708ms)
✔ proxy/translation (7.201416ms)
▶ proxy/response-conversion
✔ OpenAI 响应 → Anthropic 格式 (1.744917ms)
✔ Anthropic 响应 → OpenAI 格式 (0.26675ms)
✔ OpenAI tool_calls → Anthropic tool_use (0.08875ms)
✔ Anthropic tool_use → OpenAI tool_calls (0.067375ms)
✔ 并行 tool_use → 并行 tool_calls (0.051792ms)
✔ OpenAI Responses 响应 → Anthropic 格式 (0.156375ms)
✔ OpenAI Responses function_call → Anthropic tool_use (0.042042ms)
✔ OpenAI Responses computer_call → Anthropic tool_use (computer) (0.16825ms)
✔ OpenAI Responses click action → Anthropic coordinate (0.123458ms)
✔ OpenAI Responses keypress → Anthropic key + text (0.064625ms)
✔ Anthropic 响应 → OpenAI Responses 格式 (0.141125ms)
✔ Anthropic tool_use (computer) → OpenAI Responses computer_call (0.073459ms)
✔ Anthropic tool_use (computer) click → computer_call with action (0.037458ms)
✔ Anthropic tool_use (bash) → 转为 function_call (0.049125ms)
✔ OpenAI Responses computer_call → Chat tool_calls (lossy) (0.119542ms)
✔ OpenAI Responses function_call → Chat tool_calls finish_reason 与缓存用量 (0.041209ms)
✔ 跨协议 usage 保持计费输入与缓存字段独立 (0.123459ms)
✔ OpenAI reasoning_content → Anthropic thinking 块 (0.035541ms)
✔ Anthropic thinking + text → OpenAI reasoning_content + content (0.119542ms)
▶ thinking 配置注入
✔ 同协议 Anthropic 注入 thinking.budget_tokens (0.137125ms)
✔ 同协议 Anthropic 自动调整 max_tokens < budget_tokens (0.036042ms)
✔ 同协议 Anthropic max_tokens 未设置时自动设为 budget_tokens (0.033542ms)
✔ 同协议 OpenAI 注入 reasoning_effort (0.030334ms)
✔ 跨协议 OpenAI → Anthropic 注入 thinking (0.036959ms)
✔ 跨协议 OpenAI → Anthropic: 客户端 max_tokens < budget 时被覆盖 (0.032875ms)
✔ 跨协议 Anthropic + reasoning_effort 查表转 budget_tokens (0.029042ms)
✔ 跨协议: 客户端传 reasoning_effort 上游是 Anthropic 时也查表转 budget_tokens (0.028834ms)
✔ 跨协议: 客户端 max_tokens < reasoning_effort 映射的 budget 时被覆盖 (0.029083ms)
✔ 同协议 Anthropic reasoning_effort 查表转 budget_tokens (0.026833ms)
✔ 跨协议 Anthropic → OpenAI 注入 reasoning_effort (0.03125ms)
✔ 无 thinking 配置时不注入任何参数 (0.024792ms)
✔ 对话中已有 thinking 时,工具调用 assistant 自动补占位 thinking (0.075ms)
✔ 已有 thinking 块时,后续无 reasoning 的 tool_calls 也补占位 (0.064041ms)
✔ thinking 模式未启用时不补占位 thinking (0.044375ms)
✔ 无 thinking 配置但对话中已有 reasoning_content 时自动补占位 thinking (0.067958ms)
✔ thinking 签名:上游有 reasoning_signature 时优先使用 (0.038417ms)
✔ thinking 签名:上游无 reasoning_signature 时自动 SHA-256 生成 (0.04775ms)
✔ 用户配置优先:Anthropic budget_tokens 覆盖客户端 thinking (0.031041ms)
✔ 用户配置优先:Anthropic type 覆盖客户端 thinking (0.030833ms)
✔ 用户配置优先:thinking.type 覆盖客户端 reasoning_effort(OpenAI) (0.02925ms)
✔ 用户配置优先:reasoning_effort 覆盖客户端(OpenAI) (0.023625ms)
✔ 用户配置优先:reasoning_effort 覆盖客户端 reasoning(OpenAI Responses) (0.030167ms)
✔ thinking 配置注入 (1.136459ms)
▶ stream 默认值 fallback
✔ 同协议 Anthropic→Anthropic: 未传 stream → 设为 true (0.065583ms)
✔ 同协议 Anthropic→Anthropic: stream: true → 保持 true (1.200292ms)
✔ 同协议 Anthropic→Anthropic: stream: false → 保持 false (0.072667ms)
✔ 跨协议 OpenAI Chat→Anthropic: 未传 stream → 设为 true (0.059ms)
✔ 跨协议 OpenAI Chat→Anthropic: stream: true → 保持 true (0.038458ms)
✔ 跨协议 Anthropic→OpenAI: 未传 stream → 设为 true (0.031667ms)
✔ 跨协议 Anthropic→OpenAI: stream: true → 保持 true (0.032459ms)
✔ route.stream=false: 同协议未传 stream → 采用路由默认 false (0.03ms)
✔ route.stream=false: 跨协议未传 stream → 采用路由默认 false (0.03875ms)
✔ route.stream=false: 客户端显式 stream=true 优先于路由默认 (0.026458ms)
✔ route.stream=true: 同协议未传 stream → 采用路由默认 true (0.033625ms)
✔ route.stream=null(跟随): 同协议未传 stream → 不注入,保持 undefined (0.025125ms)
✔ route.stream=null(跟随): 跨协议未传 stream → 不注入,保持 undefined (0.032416ms)
✔ route.stream=null(跟随): 客户端显式 stream=true 仍保留 (0.024709ms)
✔ stream 默认值 fallback (1.862667ms)
▶ Namespace 工具后处理 (CCX 兼容)
✔ buildNamespaceToolContext: 从 namespace 工具构建查找表 (0.127875ms)
✔ buildNamespaceToolContext: namespace 以 __ 结尾时不加额外分隔符 (0.036ms)
✔ remapNamespaceFunctionCalls: 匹配时加回 namespace (0.066833ms)
✔ remapNamespaceFunctionCalls: 不匹配的工具名不受影响 (0.042875ms)
✔ remapNamespaceFunctionCalls: 空上下文不修改输出 (0.031416ms)
✔ remapNamespaceFunctionCalls: computer_call 类型不受影响 (0.0345ms)
✔ Anthropic → Responses: function_call 经后处理加回 namespace (0.08025ms)
✔ Namespace 工具后处理 (CCX 兼容) (0.488458ms)
✔ proxy/response-conversion (7.785625ms)
(node:61919) ExperimentalWarning: SQLite is an experimental feature and might change at any time
(Use node --trace-warnings ... to show where the warning was created)
▶ proxy/forwardRequest → UsageStore 集成
✔ 非流式响应:Anthropic 协议 usage 被归一化后写入 UsageStore (25.657416ms)
✔ 非流式响应:OpenAI 协议 usage 直接写入 (3.690916ms)
✔ 非流式响应:OpenAI Responses 标准缓存字段写入 UsageStore (5.329375ms)
✔ adapter 请求:adapterName 被正确持久化 (3.239417ms)
✔ 直接代理 vs 适配器:两条请求分别记录 (3.461125ms)
✔ 持久化:关闭后重开数据仍在 (6.362625ms)
✔ proxy/forwardRequest → UsageStore 集成 (48.509917ms)
▶ proxy/vision-cache
▶ computeImageKey
✔ data URI 使用 md5 前缀(包含 mediaType + data) (0.613209ms)
✔ http(s) URL 使用 url: 前缀且不做哈希 (0.070791ms)
✔ http URL 同样处理 (0.060625ms)
✔ data URI 缺少逗号时仍能生成键 (0.069ms)
✔ computeImageKey (1.180375ms)
▶ 基本读写
✔ 未命中返回 null 并累加 misses (0.445625ms)
✔ 写入后读取命中 (0.394125ms)
✔ 同 key 多次 set 取最后一次 (0.225875ms)
✔ 基本读写 (1.310041ms)
▶ LRU 淘汰
✔ 超过 maxEntries 时淘汰 lastUsedAt 最早的 (18.320042ms)
[vision-cache] load failed (/var/folders/13/rt1cgm5j5w36_34_wzmff_rm0000gn/T/vision-cache-test-1785574430374-2qy9b33q26k.json): Expected property name or '}' in JSON at position 1 (line 1 column 2)
✔ 命中会更新 lastUsedAt,避免被淘汰 (22.111291ms)
✔ 已有 key 的更新不触发淘汰 (0.216458ms)
✔ LRU 淘汰 (40.859ms)
▶ 磁盘持久化
✔ load 从 JSON 读回已有 entries (0.814625ms)
✔ 文件不存在时 load 静默成功(空缓存) (0.129625ms)
✔ JSON 损坏时 load 静默成功(空缓存) (0.649125ms)
✔ version 不匹配时视为空缓存 (0.3795ms)
✔ flushSync 写入磁盘 (1.214958ms)
✔ flushSync 在没有 dirty 时不写盘(不抛错) (0.109209ms)
✔ 自动创建父目录 (0.543541ms)
✔ 磁盘持久化 (3.961458ms)
▶ clear
✔ 清空内存 + 计数 + 磁盘文件 (0.382625ms)
✔ clear (0.404541ms)
▶ getStats 字段
✔ 初始 hits=0, misses=0, size=0, hitRate=0 (0.049292ms)
✔ hitRate 正确计算 (0.035167ms)
✔ getStats 字段 (0.104792ms)
✔ proxy/vision-cache (48.357417ms)
▶ proxy/vision
▶ modelSupportsImage
✔ input 含 image 时返回 true (0.4675ms)
✔ input 不含 image 时返回 false (0.086458ms)
✔ input 未配置时返回 false(向后兼容,视为仅文本) (0.044458ms)
✔ modelSupportsImage (0.945084ms)
▶ processVisionFallback 触发条件
✔ 未配置 vision 时不触发(返回 false) (0.365958ms)
✔ 目标模型已支持图片时不触发(返回 false) (0.086292ms)
✔ 请求中无图片时不触发(返回 false) (0.157666ms)
✔ processVisionFallback 触发条件 (0.708458ms)
▶ 图片块扫描覆盖三种协议
✔ 识别 OpenAI Chat image_url 块 (0.560291ms)
✔ 识别 Anthropic image 块(base64) (0.128542ms)
✔ 识别 Anthropic image 块(url) (0.087708ms)
✔ 识别 OpenAI Responses input_image 块 (0.113833ms)
✔ content 为纯字符串时不触发(无图片块) (0.058125ms)
✔ 图片块扫描覆盖三种协议 (1.078ms)
▶ 图片块替换为 <image_description>(fetch mock)
✔ 单张图片被替换为 <image_description> 文本块 (23.043ms)
✔ 同一条消息多张图片各自独立识图 (0.488ms)
✔ 缓存命中时不再调用识图模型 (0.200125ms)
✔ 部分命中:已缓存的图跳过识图 (0.321125ms)
✔ tool_result 嵌套图片(Anthropic 协议)被正确识别并替换 (0.246208ms)
✔ 多条消息的图片分别识图 (0.270416ms)
✔ 识图模型返回错误时抛出异常 (0.258584ms)
✔ 多消息多图:所有图片各自独立识别并替换,无残留图片块 (0.346542ms)
✔ 图片块替换为 <image_description>(fetch mock) (25.314792ms)
✔ proxy/vision (28.459083ms)
▶ status/tracker
✔ 无请求数据时返回默认状态 (0.518583ms)
✔ 记录请求后返回正确统计 (0.112458ms)
✔ 失败请求正确影响 errorRate (0.055042ms)
✔ 滑动窗口过期后数据清除 (61.128125ms)
✔ getAllStatuses 返回所有 Provider (0.205ms)
✔ status/tracker (62.723917ms)
(node:61923) ExperimentalWarning: SQLite is an experimental feature and might change at any time
(Use node --trace-warnings ... to show where the warning was created)
▶ status/usage-store
▶ record + getStats
✔ 初始无数据时返回全 0 (4.573208ms)
✔ record 后 today 累加 (2.478542ms)
✔ byProvider 按 provider 分组 (2.339125ms)
✔ 多次 record 累加 (2.508708ms)
✔ record + getStats (12.252375ms)
▶ adapter 维度
✔ adapter 不为 null 时正确记录 (2.562292ms)
✔ adapter 为 null 时显示为 (direct proxy) (2.155791ms)
✔ 同一 provider 下不同 adapter 分别记录 (2.319625ms)
✔ getBreakdown by model 正确分组 (2.521125ms)
✔ getBreakdown by model 按供应商/上游真实模型分组 (2.166334ms)
✔ getBreakdown by adapterModel 按适配器/虚拟模型分组 (2.38725ms)
✔ adapter 维度 (14.340917ms)
▶ 持久化(重启保留)
✔ close 后重新打开数据仍在 (2.612542ms)
✔ db 文件确实被创建 (1.862666ms)
✔ 持久化(重启保留) (4.585125ms)
▶ getTimeline
✔ 无历史数据时返回 N 天全 0 (1.942458ms)
✔ 请求数据正确反映在 timeline (1.988084ms)
✔ days=1 只返回今天 (1.955792ms)
✔ 默认参数等价于 days=30 (2.172042ms)
✔ 自定义 startDate/endDate 返回 [start, end] 范围内连续日期(含两端) (2.396416ms)
✔ startDate === endDate 只返回那一天 (2.02675ms)
✔ getTimeline (12.617792ms)
▶ getBreakdown 自定义日期范围
✔ startDate/endDate 与 days 互不影响 (2.301667ms)
✔ startDate/endDate 合并多天同维度数据 (2.00975ms)
✔ getBreakdown 自定义日期范围 (4.35775ms)
▶ cleanup
✔ 清理 90 天前的数据 (2.656042ms)
✔ clearAll 清空全部数据(含今日内存缓存) (2.089959ms)
✔ cleanup (4.798875ms)
▶ stats
✔ 返回条目数与文件大小 (2.135666ms)
✔ stats (2.169209ms)
▶ 并发安全
✔ 连续 record 无数据丢失 (40.189917ms)
✔ 并发安全 (40.231041ms)
✔ status/usage-store (95.861833ms)
ℹ tests 469
ℹ suites 81
ℹ pass 469
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 5419.082334 — 469 passed\n-

@maplezzk/llm-proxy@0.28.3 prebuild
npm run generate:i18n-types

@maplezzk/llm-proxy@0.28.3 generate:i18n-types
tsx scripts/generate-i18n-types.ts

Generated 360 translation keys → /Users/zzk/CliProject/llm-proxy/src/types/i18n.generated.ts
zh: 360 keys
en: 360 keys

@maplezzk/llm-proxy@0.28.3 build
tsc && npm run build:admin && cp admin-ui/dist/admin-ui.html dist/api/admin-ui.html

@maplezzk/llm-proxy@0.28.3 build:admin
vite build admin-ui

vite v6.4.3 building for production...
transforming...
✓ 6404 modules transformed.
rendering chunks...
[plugin vite:singlefile]

[plugin vite:singlefile] Inlining: index-DKvd8BbW.js
[plugin vite:singlefile] Inlining: style-DA0B_Q88.css
computing gzip size...
dist/index.html 1,319.08 kB │ gzip: 367.66 kB
✓ built in 2.28s — passed\n- — 186 passed\n- — passed

@maplezzk
maplezzk merged commit 25bda44 into main Aug 1, 2026
1 check passed
@maplezzk
maplezzk deleted the codex/adapter-protocol-agnostic branch August 1, 2026 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant