SuperAPI AI 工具集

OpenCode SDK Development

编程与开发

查看项目

更新于 10-15 22:13

技能介绍

用途:指导开发者基于 OpenCode SDK 创建自定义工具与插件,扩展 OpenCode 能力。

主要能力:SDK 提供两个包——@opencode-ai/sdk 用于与 OpenCode 服务器交互(会话、消息、文件),@opencode-ai/plugin 提供带 schema 校验的插件系统。自定义工具为 TypeScript/JavaScript 文件,从项目目录 .opencode/tool/ 或全局 ~/.config/opencode/tool/ 自动发现,文件名即工具名,多导出生成 filename_exportname。工具用 tool() 定义 description、args 与 execute,args 使用 tool.schema(Zod)做校验,支持 string、number、enum、boolean、optional、default 等。execute 接收 context,含 sessionID、messageID、agent、abort。插件通过 Plugin 类型定义,可注册工具,并提供 event、config、auth、chat.message、chat.params、permission.ask、tool.execute.before/after 等钩子。SDK 客户端用 createOpencode 或 createOpencodeClient 初始化,涵盖 session、project、file、find、tool、event、mcp、tui 等 API,支持 SSE 事件流订阅。

使用方式:安装 npm install @opencode-ai/sdk 与 npm install @opencode-ai/plugin,要求 TypeScript >= 4.9。

适用场景:为 OpenCode 添加文件搜索、跨语言脚本调用等自定义工具,或编写带事件与消息钩子的完整插件。

限制:资料未提供收费、价格与平台支持信息;工具未出现时需检查路径、导出并重启 OpenCode。