{"record":{"id":"4bf5cb704d879f99","repo":"siyuan-note/siyuan","slug":"failed-to-serialize-inputschema-v","errorCode":null,"errorMessage":"failed to serialize inputSchema: %v","messagePattern":"failed to serialize inputSchema: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/api_agent.go","lineNumber":263,"sourceCode":"\t\t\tlogging.LogErrorf(\"[plugin:%s] siyuan.agent.unregisterCapability worker run: %v\", p.Name, runErr)\n\t\t\tif rejectErr := reject(rt.NewGoError(runErr)); rejectErr != nil {\n\t\t\t\tlogging.LogErrorf(\"[plugin:%s] siyuan.agent.unregisterCapability reject on run error: %v\", p.Name, rejectErr)\n\t\t\t}\n\t\t}\n\n\t\treturn rt.ToValue(promise)\n\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","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/plugin/api_agent.go#L245-L281","documentation":"jsCapabilitySchemaToGoSchema converts a JavaScript tool capability's inputSchema object into a Go tools.ToolSchema. The first step serializes the JS object to JSON via goja's MarshalJSON; if that serialization fails, the function wraps and returns the error. This indicates the JS-side value could not be represented as JSON at all, typically because it is not a plain object or contains unserializable content.","triggerScenarios":"A plugin registers a tool capability whose inputSchema argument to the capability API is not a plain JSON-serializable object (e.g. a function, a Symbol-containing object, a circular structure, or a Proxy with throwing traps passed as the schema).","commonSituations":"Plugin authors pass a getter-only object, a class instance with circular references, or accidentally pass undefined/a function where a schema object is expected; goja's MarshalJSON rejects the value.","solutions":["Pass a plain object literal as inputSchema (JSON Schema shape: {type:'object', properties:{...}, required:[...]})","Remove functions, Symbols, circular references, and getters that throw from the schema object","If the schema is computed at runtime, JSON.parse(JSON.stringify(schema)) it in JS before passing it in","Check the wrapped marshalErr message to identify the exact unserializable value"],"exampleFix":"// before\nregisterTool({ name: \"myTool\", inputSchema: makeSchema }) // function passed\n\n// after\nregisterTool({ name: \"myTool\", inputSchema: { type: \"object\", properties: { q: { type: \"string\" } } } })","handlingStrategy":"validation","validationCode":"function isPlainJsonSchema(v) {\n  return v !== null && typeof v === \"object\" && !Array.isArray(v) &&\n    JSON.parse(JSON.stringify(v)) !== undefined;\n}\nif (!isPlainJsonSchema(schema)) throw new Error(\"inputSchema must be a plain JSON object\");","typeGuard":"const isPlainObject = (v) => typeof v === \"object\" && v !== null && !Array.isArray(v) && Object.getPrototypeOf(v) === Object.prototype;","tryCatchPattern":null,"preventionTips":["Always define inputSchema as a literal JSON Schema object","Never embed functions or class instances in schemas","Deep-clone computed schemas with structuredClone before registering"],"tags":["plugin","goja","json","schema"],"backgroundTag":"json-marshal-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"}