[Ideas / 文档] 插件开发的工具 schema 两个隐藏校验:object 节点必须显式声明 additionalProperties;type 不支持联合数组 #1040
truelove-dreamer
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
摘要
用
harness.defineTool(动态插件)或ctx.tools.register(外部插件)注册模型工具时,工具参数的 JSON Schema 校验有两个硬性限制,违反即注册失败:additionalProperties(true或false都行),省略报unsupported JSON schema: schema.additionalProperties must be explicitly true or false;type不支持联合数组(如["string","null"]),报schema.properties.xxx.type must be string/number/integer/boolean/null/array/object/json, or use oneOf。两个限制都不在官方文档/类型定义里明确写出,只有运行时错误。本文给出最小复现、绕过方式,并建议把这两条写进
docs/cookbook/adding-a-package.md(或放宽校验)。复现
坑 1:object 节点省略 additionalProperties
报错:
注意:嵌套的每个 object 节点(如
properties.result里再套 object)也要各自显式声明,不是只补顶层。坑 2:type 联合数组
报错:
绕过方式
additionalProperties: false(推荐,报告/参数结构更严格)或true。ref: { type: "string" }),用"字段缺失"表达 null,不要用联合数组;需要真正的多类型时改用oneOf。建议(供讨论)
additionalProperties缺省时按true处理、type数组在运行时做值校验即可——当前报错信息对新手不友好("unsupported JSON schema" 没指出是哪个节点、怎么改);附注
All reactions