SuperAPI AI 工具集

just-bash-executor

智能体与模型

查看项目

更新于 10-16 06:42

技能介绍

用途:@just-bash/executor 把不同来源(OpenAPI 规范、GraphQL 端点、MCP 服务器,或自定义 JS 函数)映射为统一的工具接口:供 js-exec 脚本调用的 tools.* JS API,以及供 bash.exec 使用的 CLI 命令。消费端代码对四类来源都相同,区别只在 createExecutor 的配置。

主要能力:四类来源的接入方式为:OpenAPI 用 sdk.sources.add({kind:"openapi", spec, endpoint, name}),spec 必须是字符串(URL、JSON 文本或 YAML 文本,不能是已解析对象);GraphQL 用 kind:"graphql" 加 endpoint,可选 introspectionJson;MCP 支持 transport "remote"(需 endpoint)或 "stdio"(需 command 与 args),可带 headers、env、cwd;自定义函数直接写在 tools 中。多来源可在一个 setup() 内多次调用 sources.add() 并用不同 name 作为命名空间。

转换规则:OpenAPI 每个 operation 生成一个工具,路径为 <name>.<首段URL>.<operationId>,缺少 operationId 的操作会被跳过;GraphQL 每个顶层 Query/Mutation 字段生成一个工具,路径为 <name>.query.<字段> 或 <name>.mutation.<字段>;MCP 每个 server 工具生成一个,路径为 <name>.<server工具名>;inline 路径即所写 key。参数合并为单一 args 对象。JS 侧用 await tools.ns.name(args),bash 侧支持 key=value、--flag、--json '{"a":1}'、管道 stdin 与 jq 组合,优先级为 flags > --json > stdin。

使用方式:先 createExecutor 配置来源,再 new Bash({ customCommands: executor.commands, javascript: { invokeTool: executor.invokeTool } }),即可在 js-exec 沙箱中调用。onToolApproval 可按来源或工具路径做审批控制,onElicitation 可处理 MCP 交互式请求(默认拒绝需自行实现)。

限制:GraphQL 结果为原始响应封装 { status, data, errors },需自行检查 errors 与读取 data;自动生成的浅层 selection set 对含嵌套对象返回类型的查询会校验失败,需改用内联工具手写查询;订阅尚未暴露为可调用工具。OpenAPI 的 headers 每次调用都会发送,适合静态令牌。插件需按类型安装 @executor-js/plugin-openapi、plugin-graphql、plugin-mcp。命名空间 name 冲突会静默覆盖。