mirror of
https://gitcode.com/JianFeeeee/ModelRouter.git
synced 2026-11-07 09:47:23 +00:00
TRAE **不是 OpenAI 兼容**。参考 trae.ts:30 点名:「载荷必须转换:OpenAI 的
{model,messages,tools,tool_choice,stream} 需要映射为 SOLO 格式(function、
config_name 等字段),不能透传」。上一轮我把端点改对了(/api/agent/v3/
llm_utils_chat)但**载荷仍原样直发** —— 上游会回流内 4001,而 HTTP 状态码
仍是 200,属静默失败。
本次补齐 transformToSOLOBody 的 7 条规则(逐条对齐参考):
1. messages.content 字符串 → [{type:"text",text:…}];数组透传
2. stream 强制 true(非流式由服务端聚合)
3. model → config_name + model **双字段**(支持 __dev 后缀消除)
4. function 通道名,缺省 solo_work_lite
5. tool_choice 归一化:none → 删 tool_choice **与** tools;
auto/required 保留;{type:function,function:{name}} → 字符串 name
6. assistant 的 tool_calls: function → function_call,并剔除无 name 的条目
(孤儿 tool_call 会让整条会话被拒)
7. tools[].function.parameters: object → JSON **字符串**(SOLO 要求)
★ 命名为什么是 channels-trae 而不是 trae:内置 trae.lua 服务的是**运维自建
的 trae-local-api 反代**(base_url 127.0.0.1:19900,生产 config.yaml 在用),
与本插件的直连通道是两回事。重名会被内核冲突仲裁挂起(正确的护栏)。
判据里专门断言"内置 trae 未被顶掉"。
★ 踩到的坑:`function` 是 Lua 关键字,写 `body.function = x` 是**语法错误**
('<name>' expected near 'function'),必须 `body["function"]`。它只在 load()
时才暴露 —— 插件脚本本身能编译通过,适配器源码要运行期才报错。
判据(internal/lua/channels_trae_solo_test.go):走**真实路径**
(装插件 → 调已安装的适配器),而不是在插件 VM 里 load 一份副本 ——
副本拿不到内核注入的共享前导,也发现不了"装了但没生效"。逐条断言 7 条规则
+ 三处反向断言(extra_body 必剥离、无 name 的 tool_call 必剔除、
tool_choice=none 时 tools 与 tool_choice 都必须消失)。
回归:internal/{lua,core,provider,gateway} 全绿。