docs: 补 15-17 号踩坑(defineTool 必须转换参数 schema、具名导出被 default 吞、上下文窗口来自 request/context)

This commit is contained in:
2026-09-27 16:09:30 +08:00
parent 60474fceea
commit 5f258e8308
+5
View File
@@ -113,6 +113,11 @@ shell\run-float.cmd -Action pin # 给正在运行的实例
12. **会话事件载荷在 `event.data` 下**,不在顶层:`user/message` → `data.content[{type:'text',text}]`、`assistant/chunk` → `data.chunk{type,text,reason}`、`session/title` → `data.title`、`tool/call` → `data.name/args`。另外要过滤 `data.source.kind === 'plugin'` 的消息(系统提示快照),否则镜像里会混入一大段内部注入文本。
13. **宿主 RPC 的信封是 `{ rpcId, payload }`**(0.1.0 的 `ctx.apiProxy.sessions.*`):把字段平铺在顶层会得到 `Cannot read properties of undefined (reading 'sessionId')`。
14. **0.1.7 起宿主面换成了 `ctx.sessionController`**(`ctx.apiProxy` 不再存在),并且 Remote 签名是 `(request, signal)`——**漏了 signal 会报 `Cannot read properties of undefined (reading 'throwIfAborted')`**;`create` 还必须带一个合法的 `agentPreset`(否则 `Unknown agent preset: xxx`)。插件对两套 API 都自动适配(见 `hostCall`)。
15. **手工拼工具定义会打断每一轮对话**(真机事故):0.1.7 的 `ctx.tools.register()` 要求模型侧看到的就是 JSON Schema,参数必须经 `defineTool()`(内部 `parameterSchemaSpecToJsonSchema`)转换。直接塞 DSL 对象会让 provider 收到 `parameters.type = null`,于是**每次请求都被拒**:
`Invalid schema for function 'float_window': schema must be a JSON Schema of 'type: "object"', got 'type: null'`。
现在的三层防护:解析不到 `defineTool` 就**根本不注册**;注册前自检 `parameters.type === 'object'`;配置项 `tool: false` 可一键关掉。
16. **link: 安装时优先返回 `default` 会吞掉具名导出**:`@deepseek-ai/dsh-tools` 的 `default` 是 `ToolRuntime` 类,`defineTool` 是具名导出——宿主模块加载器必须返回模块命名空间本身。
17. **上下文窗口不在 model 配置里**,而在会话事件 **`request/context.contextWindow`**(实测 `deepseek-flash` = 1000000),用它算上下文用量百分比最可靠;状态文件里的 `toolSchemas` 是从真实 `request/header` 抓下来的"模型视角工具 schema",用来一眼确认 schema 合法。
## 版本支持