{"record":{"id":"c02e7bae029cd5cb","repo":"siyuan-note/siyuan","slug":"invalid-json-schema-v","errorCode":null,"errorMessage":"invalid json schema: %v","messagePattern":"invalid json schema: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/api_agent.go","lineNumber":270,"sourceCode":"\t})))\n\n\tlo.Must0(ObjectFreeze(rt, agentAPI))\n\tlo.Must0(siyuan.Set(\"agent\", agentAPI))\n\treturn\n}\n\n// jsCapabilitySchemaToGoSchema 将 JavaScript 能力 Schema 转换为 Go ToolSchema。\nfunc jsCapabilitySchemaToGoSchema(rt *goja.Runtime, value goja.Value) (toolSchema *tools.ToolSchema, err error) {\n\tschemaJson, marshalErr := value.ToObject(rt).MarshalJSON()\n\tif marshalErr != nil {\n\t\terr = fmt.Errorf(\"failed to serialize inputSchema: %v\", marshalErr)\n\t\treturn\n\t}\n\n\tschema := &tools.ToolSchema{}\n\tunmarshalErr := json.Unmarshal(schemaJson, schema)\n\tif unmarshalErr != nil {\n\t\terr = fmt.Errorf(\"invalid json schema: %v\", unmarshalErr)\n\t\treturn\n\t}\n\n\ttoolSchema = schema\n\treturn\n}\n\nfunc jsCapabilityEffectsToGoEffects(rt *goja.Runtime, value goja.Value) (*tools.ToolEffects, error) {\n\teffects := &tools.ToolEffects{}\n\tif err := unmarshalCapabilityJSON(rt, value, effects, \"effects\"); err != nil {\n\t\treturn nil, err\n\t}\n\treturn effects, nil\n}\n\nfunc jsCapabilityActionEffectsToGoEffects(rt *goja.Runtime, value goja.Value) (map[string]tools.ToolEffects, error) {\n\tactionEffects := map[string]tools.ToolEffects{}\n\tif err := unmarshalCapabilityJSON(rt, value, &actionEffects, \"actionEffects\"); err != nil {","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/plugin/api_agent.go#L252-L288","documentation":"After the JS inputSchema is serialized to JSON, it is unmarshalled into tools.ToolSchema. If the JSON does not match the Go struct's expected field types (json.Unmarshal fails), this error is returned. It means the schema object exists and serializes, but its contents are not a valid ToolSchema for the agent tool system.","triggerScenarios":"A plugin passes an inputSchema whose fields have wrong types, e.g. inputSchema: \"a string\", inputSchema: [], inputSchema: {type: 123}, or properties values that do not decode into the expected ToolSchema field types.","commonSituations":"Authors copy an OpenAPI-style or vendor-specific schema instead of the expected JSON Schema shape; typos like \"typ\":\"object\" leave wrong-typed fields; passing a top-level array of properties instead of an object.","solutions":["Use a standard JSON Schema object: {type:\"object\", properties:{...}, required:[...]}","Ensure \"type\" and other fields are strings, not numbers or nested objects","Read the wrapped unmarshalErr to see which field failed to decode","Validate the schema with a JSON Schema validator in the plugin before registering"],"exampleFix":"// before\ninputSchema: { type: 1, properties: [] }\n\n// after\ninputSchema: { type: \"object\", properties: { q: { type: \"string\" } }, required: [\"q\"] }","handlingStrategy":"validation","validationCode":"function validateSchema(s) {\n  if (typeof s !== \"object\" || s === null || Array.isArray(s)) return false;\n  if (typeof s.type !== \"string\") return false;\n  if (s.properties && typeof s.properties !== \"object\") return false;\n  if (s.required && !Array.isArray(s.required)) return false;\n  return true;\n}","typeGuard":"const isJsonSchemaObject = (v) => v !== null && typeof v === \"object\" && !Array.isArray(v) && typeof v.type === \"string\";","tryCatchPattern":null,"preventionTips":["Keep \"type\" a string (\"object\", \"string\", \"number\"...)","Validate the schema with ajv or a JSON Schema validator before registering","Compare against the tool registration docs / sample plugin"],"tags":["plugin","goja","json","schema-validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}