{"record":{"id":"ab43c454dc19fb87","repo":"siyuan-note/siyuan","slug":"registercapability-requires-3-arguments-name-con","errorCode":null,"errorMessage":"registerCapability requires 3 arguments: name, config, handler","messagePattern":"registerCapability requires 3 arguments: name, config, handler","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/api_agent.go","lineNumber":70,"sourceCode":"\n\tagentAPI := rt.NewObject()\n\n\t// siyuan.agent.registerCapability(name, config, handler) 返回 Promise<IRegisteredCapability>。\n\tlo.Must0(agentAPI.Set(\"registerCapability\", rt.ToValue(func(call goja.FunctionCall, rt *goja.Runtime) goja.Value {\n\t\tpromise, resolve, reject := rt.NewPromise()\n\n\t\tvar name string\n\t\tvar title string\n\t\tvar description string\n\t\tvar effects *tools.ToolEffects\n\t\tvar actionEffects map[string]tools.ToolEffects\n\t\tvar inputSchema *tools.ToolSchema\n\t\tvar outputSchema *tools.ToolSchema\n\t\tvar handler goja.Callable\n\n\t\targErr := func() (err error) {\n\t\t\tif len(call.Arguments) < 3 {\n\t\t\t\terr = fmt.Errorf(\"registerCapability requires 3 arguments: name, config, handler\")\n\t\t\t\treturn\n\t\t\t} else {\n\t\t\t\tif s := call.Argument(0); goja.IsString(s) {\n\t\t\t\t\tname = strings.TrimSpace(s.String())\n\t\t\t\t\tif name == \"\" {\n\t\t\t\t\t\terr = fmt.Errorf(\"capability name must not be empty\")\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\terr = fmt.Errorf(\"first argument must be a tool name string\")\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tif c := call.Argument(1); isJsValueNotNull(c) {\n\t\t\t\t\tconfigObj := c.ToObject(rt)\n\t\t\t\t\tif configObj != nil {\n\t\t\t\t\t\tif titleValue := configObj.Get(\"title\"); goja.IsString(titleValue) {\n\t\t\t\t\t\t\ttitle = titleValue.String()","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/plugin/api_agent.go#L52-L88","documentation":"Thrown by the siyuan.agent.registerCapability JS API exposed to plugins when fewer than 3 arguments are passed. The API contract requires exactly three arguments: a capability name string, a config object, and a handler function. goja reports call.Arguments as a sparse array padded with undefined, so len(call.Arguments) < 3 means the JS caller omitted at least one argument.","triggerScenarios":"A plugin calls siyuan.agent.registerCapability('myTool', config) — omitting the handler. Or siyuan.agent.registerCapability(config, handler) — omitting the name. Any call with fewer than three positional arguments triggers this.","commonSituations":"Plugin developer forgets the handler argument; destructures or passes arguments dynamically and one is missing; copy-paste from an older API version that had fewer required arguments.","solutions":["Provide all three arguments: name (string), config (object with description and inputSchema), handler (function)","Check the plugin's registerCapability call site against the current API signature in api_agent.go"],"exampleFix":"// before\nawait siyuan.agent.registerCapability('myTool', {\n  description: 'Does something',\n  inputSchema: { type: 'object', properties: {} }\n});\n\n// after\nawait siyuan.agent.registerCapability('myTool', {\n  description: 'Does something',\n  inputSchema: { type: 'object', properties: {} }\n}, (args) => {\n  return { result: 'done' };\n});","handlingStrategy":"try-catch","validationCode":"if (arguments.length < 3) {\n  throw new Error('registerCapability needs (name, config, handler)');\n}\nawait siyuan.agent.registerCapability(name, config, handler);","typeGuard":"function isValidCapabilityCall(name, config, handler) {\n  return typeof name === 'string' && name.trim() !== ''\n    && config !== null && config !== undefined\n    && typeof handler === 'function';\n}","tryCatchPattern":"try {\n  await siyuan.agent.registerCapability(name, config, handler);\n} catch (e) {\n  console.error('registerCapability failed:', e.message);\n}","preventionTips":["Always pass exactly three arguments to registerCapability: name, config, handler","Use TypeScript or JSDoc to enforce the argument count at development time","Unit-test plugin capability registration with valid arguments before deployment"],"tags":["plugin","agent","capability","javascript","validation"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}