SuperAPI AI 工具集

add-ai-chat-tool

通用与其它

查看项目

更新于 10-16 08:39

技能介绍

用途:在 ryOS 中新增或修改 AI 聊天工具(“Ask Ryo”能力)。ryOS 聊天工具遵循 Vercel AI SDK 的 tool-loop 模式:工具在服务端定义(名称 + 描述 + Zod inputSchema),分为服务端执行(带 execute,运行于 api/chat/tools/,需要 Redis、密钥、服务端 fetch)与客户端执行(无 execute,模型发出工具调用后由浏览器在 src/apps/chats/tools/ 中运行处理器,再通过 addToolOutput 回传结果)。部分工具两种方式都支持(如 stickiesControl、calendarControl、contactsControl),此时需同时提供 handler 与 executor。

主要步骤:一、在 api/chat/tools/schemas.ts 用 Zod 定义 schema,动作型工具用 enum action 加可选参数,跨字段规则用 .superRefine;共享枚举放 types.ts。二、在 api/chat/tools/index.ts 的 TOOL_DESCRIPTIONS 写清行为、参数与不适用场景,并在 createChatTools 的 allTools 中注册;如需 Telegram/记忆 profile 可用,还要加入对应分支。三、若为服务端执行,在 src/shared/tools/serverExecuted.ts 的 TOOL_EXECUTION_METADATA 标记 execution: "server"。四、客户端工具需在 src/apps/chats/tools/ 新建 handler,读写 Zustand store 并通过 context.addToolOutput 返回结果,每次调用只发一次输出,用户可见文案用 i18n.t(...),必要时先 context.launchApp 打开应用,list→mutate 流程可用 createShortIdMap / resolveId 降低 token。五、在 dispatchToolCall.ts 的 switch 中显式添加 case,否则会落到默认分支报 “Unhandled tool”;handler 自行输出时 result 设为空字符串。六、服务端执行器写入 executors.ts 或 app-state-executors.ts,返回可 JSON 序列化结果;返回图像的工具需加 toModelOutput。

测试与限制:schema 可加 tests/unit 下的 safeParse 单测,服务端执行器走 test:ai 套件,客户端处理器在 Chats 应用中端到端验证。资料未提供具体版本、依赖安装命令或收费信息。