JianFeeeee
741edfea98
feat(lua): 适配器共享前导 —— 消除 12680 字节的逐字重复
问题(实测证据,按钩子做字节级哈希分组):
transform_response github/groq/mistral 三份完全相同(2207B × 3)
transform_stream_chunk github/groq/kimicode/mistral 四份相同(2211B × 4)
transform_error deepseek/github/groq/kimicode 四份相同(293B × 4)
合计 12680 字节完全重复。openai.lua 自己的注释就写着
「(anthropic.lua carries the same helper; Lua adapters have no shared
prelude.)」—— safe_tool_id 在 openai.lua 与 anthropic.lua 各复制了一份。
参考插件有 src/openai-compat.ts(1196 行,12 个 adapter 里 8 个 import),
我们没有对应物。本提交补上这一层。
做法:**编译期把一份中性助手库拼在适配器脚本前面**,注入点在
LoadAdapterSource —— 适配器有三个编译点(worker boot / HasFn 探针 /
inspectScript),全部源自这里存进 pool 的 script 文本,拼一处即全覆盖;
且不像运行时 SetGlobal 那样会在热重载/池重建时丢失。
助手只做**协议层面的中立清理与组装**,不含任何厂商名(守住内核零厂商名
纪律):decode_body / strip_control(剥内核私有控制字段 —— 那是网关内部
约定,v2 改一次就要改 12 个文件)/ unified_skeleton / finish_reason /
usage(含 cache 细分,属协议族已知变体)/ choices / tool_id(路由器性质:
坏 id 会被回放到每个 Claude 上游,一票否决整条 AUTO 链)/ derive_key。
判据两条:
- TestAdapterPreludeInjectedAndCorrect:不只断言存在,抽查**语义值**
(end_turn→stop、tool_use→tool_calls、合法 id 原样透传、非法 id 带摘要
改写、cache_hit 从 prompt_cache_hit_tokens 取)
- TestAdapterPreludeDoesNotChangeExistingAdapters:旧适配器(自己实现全部
钩子、不引用前导)输出逐字节不变
回归:internal/lua + internal/provider 全绿(16 个适配器行为不变)。
2026-10-13 22:34:13 +08:00
..
2026-10-12 16:32:30 +08:00
2026-10-13 17:02:58 +08:00
2026-10-13 22:34:13 +08:00
2026-10-13 22:34:13 +08:00
2026-10-06 15:02:42 +08:00
2026-10-12 16:37:23 +08:00
2026-10-11 09:23:34 +08:00
2026-10-11 09:23:34 +08:00
2026-10-02 12:41:35 +08:00
2026-10-13 13:42:57 +08:00
2026-10-13 13:42:57 +08:00
2026-10-12 12:32:10 +08:00
2026-10-13 13:42:57 +08:00
2026-10-02 10:45:20 +08:00
2026-10-13 13:42:57 +08:00
2026-10-02 14:07:44 +08:00
2026-10-13 06:57:28 +08:00
2026-10-13 06:57:28 +08:00
2026-10-13 13:42:57 +08:00
2026-10-04 14:50:46 +08:00
2026-10-11 09:35:32 +08:00
2026-10-05 08:17:57 +08:00
2026-10-05 08:17:57 +08:00
2026-10-11 13:25:11 +08:00
2026-10-11 10:03:43 +08:00
2026-10-12 12:32:10 +08:00
2026-10-13 22:28:34 +08:00
2026-10-11 16:24:55 +08:00
2026-10-05 08:17:57 +08:00
2026-10-05 08:17:57 +08:00
2026-10-05 08:17:57 +08:00
2026-10-11 09:35:32 +08:00
2026-10-11 09:35:32 +08:00
2026-10-13 09:18:15 +08:00
2026-10-13 06:57:28 +08:00
2026-10-13 06:57:28 +08:00
2026-10-13 06:57:28 +08:00
2026-10-11 12:59:36 +08:00
2026-10-11 12:59:36 +08:00
2026-10-11 20:50:52 +08:00
2026-10-07 17:37:22 +08:00
2026-10-05 08:17:57 +08:00
2026-10-11 13:25:11 +08:00
2026-10-13 13:42:57 +08:00
2026-10-11 09:35:32 +08:00
2026-10-04 14:50:46 +08:00
2026-10-13 13:42:57 +08:00
2026-10-12 19:07:09 +08:00
2026-10-07 17:37:22 +08:00
2026-10-11 09:35:32 +08:00
2026-10-12 12:32:10 +08:00
2026-10-13 13:42:57 +08:00
2026-10-12 16:32:30 +08:00
2026-10-11 08:17:56 +08:00
2026-10-11 09:35:32 +08:00
2026-10-12 19:07:09 +08:00
2026-10-13 22:34:13 +08:00