{"record":{"id":"c02e7bae029cd5cb","repo":"siyuan-note/siyuan","slug":"invalid-json-schema-v","errorCode":null,"errorMessage":"invalid json schema: %v","messagePattern":"invalid json schema: (.+?)","errorType":"exception","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/251596fc0de2f9528c00c224252fd073a99973f4/kernel/plugin/api_agent.go#L252-L288","documentation":"Thrown by jsCapabilitySchemaToGoSchema when the JSON-serialized schema fails to unmarshal into the Go tools.ToolSchema struct. The JSON is valid (MarshalJSON succeeded) but its structure does not match the ToolSchema Go type — missing required fields, wrong types, or unknown enum values.","triggerScenarios":"Passing an inputSchema whose JSON structure doesn't match tools.ToolSchema — for example, an array instead of an object, or an object with type: 'invalid' where the Go struct expects a specific set of values.","commonSituations":"Plugin uses an ad-hoc schema format instead of standard JSON Schema; the schema was hand-written with typos; a version change in the ToolSchema struct introduced new required fields.","solutions":["Ensure inputSchema follows standard JSON Schema format with 'type', 'properties', etc.","Validate the schema against the tools.ToolSchema struct definition in kernel/mcp/tools","Use a JSON Schema validator library on the JS side before passing the schema"],"exampleFix":"// before\nawait siyuan.agent.registerCapability('myTool', {\n  description: '...',\n  inputSchema: ['type', 'object']  // array, not object\n}, handler);\n\n// after\nawait siyuan.agent.registerCapability('myTool', {\n  description: '...',\n  inputSchema: {\n    type: 'object',\n    properties: {\n      query: { type: 'string' }\n    }\n  }\n}, handler);","handlingStrategy":"validation","validationCode":"// Validate schema is a plain object with expected JSON Schema structure\nif (typeof inputSchema !== 'object' || Array.isArray(inputSchema)) {\n  throw new Error('inputSchema must be a JSON Schema object');\n}\nif (typeof inputSchema.type !== 'string') {\n  throw new Error('inputSchema.type must be a string (e.g., \"object\")');\n}\nconfig.inputSchema = inputSchema;","typeGuard":"function isValidJsonSchema(v) {\n  return v != null && typeof v === 'object'\n    && !Array.isArray(v)\n    && typeof v.type === 'string';\n}","tryCatchPattern":null,"preventionTips":["Follow standard JSON Schema format for inputSchema and outputSchema","Reference the tools.ToolSchema Go struct to understand expected fields"],"tags":["plugin","agent","capability","schema","validation","javascript"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}