JianFeeeee
e9df62a565
fix(dsh-mail-bridge): ESM 下 defineTool 静默降级导致工具 schema 非法
现象:dsh 经 llmsproxy AUTO 走到 gozen 时 400:
Invalid schema for function 'connect_to_server':
schema must be a JSON Schema of 'type: "object"', got 'type: null'.
根因:插件 package.json 是 "type": "module"(ESM),而源码用裸
require.resolve / require 载入 @deepseek-ai/dsh-tools。ESM 里 require
是 undefined,require.resolve 抛 ReferenceError,被 catch { return opts; }
**静默吞掉** —— defineTool 恒等返回,工具的 parameters 以**未编译的裸映射**
注册:
{ gateway_url: {type:'string'}, key_token: {type:'string'} } // ❌
而不是合法形态:
{ type:'object', properties:{ gateway_url:…, key_token:… } } // ✅
后果波及全部 11 个 mail-bridge 工具。严格的上游直接 400(实测 OpenCode Go),
宽松的(Claude 系)不校验 —— 所以只在特定 AUTO 档位暴露,表现为「某个模型
突然不能用了」。
修法:
1. 用 createRequire(import.meta.url) 取得合法的 require(ESM 标准做法)。
2. 兜底也必须产出**合法** schema —— 新增 parametersToJsonSchema,在
dsh-tools 不可用时自己编译:required:true 提升到根级 required 数组
(JSON Schema 不允许属性自带 required),type:object 必补。
绝不再静默把裸映射发出去 —— 那比直接报错更难查。
实测 11 个 mail-bridge 工具全部产出合法 schema,包括真机被拒的那个
connect_to_server。测试 test/tool-schema.test.mjs 覆盖:裸映射编译、
required 提升、数组 items、空 spec、被上游拒过的实际工具。
2026-09-11 22:12:01 +08:00
..
2026-09-03 12:09:12 +08:00
2026-09-04 11:14:44 +08:00
2026-09-06 15:18:06 +08:00
2026-09-02 22:47:31 +08:00
2026-09-06 15:18:06 +08:00
2026-09-03 12:09:12 +08:00
2026-09-03 12:09:12 +08:00
2026-09-11 12:03:51 +08:00
2026-09-02 20:05:51 +08:00
2026-09-03 12:09:12 +08:00
2026-09-03 21:10:48 +08:00
2026-09-11 12:04:06 +08:00
2026-09-06 15:16:34 +08:00
2026-09-04 23:52:52 +08:00
2026-09-08 19:16:35 +08:00
2026-09-03 12:09:12 +08:00
2026-09-11 12:03:51 +08:00
2026-09-11 22:12:01 +08:00
2026-09-04 21:39:50 +08:00
2026-09-11 10:44:18 +08:00
2026-09-02 20:28:19 +08:00