Skip to content
草案 v0.13 · 早期开发

BOX

唯一真相来源。就这样。

无限可扩展·无限组合·无限可移植

源 → 输出

一处声明,每个消费者。

插件认领你要暴露的表层类型;目标插件生成客户端、服务端与规范。改一处源,所有消费者随之而动。

box
use "@box/http"
import "./schema.box"

http("user-api") {
  basePath = "/v1"

  route("/users") {
    get  = list(): schema.User[]
    post = create(req: schema.CreateUserRequest): schema.User
  }

  route("/users/{id}") {
    get    = get(id: string): schema.User
    delete = delete(id: string): void
  }

  auth {
    type     = bearer
    audience = "admin-tools"
  }
}
box
use "@box/mcp"
import "./schema.box"

mcp("user-tools") {
  tool("get_user") {
    description = "Fetch a user by ID"
    input  = GetUserInput
    output = schema.User
  }

  tool("create_user") {
    description = "Create a new user"
    input  = schema.CreateUserRequest
    output = schema.User
  }

  tool("list_users") {
    description = "List all users"
    input  = EmptyInput
    output = schema.User[]
  }
}
box
use "@box/cli"
use "@box/i18n"
import "./i18n.box"

cli("main") {
  description = t("cli.main.description")

  command("init") {
    description = t("cli.init.description")
    arg("name") {
      description = t("cli.init.arg.name")
      required    = true
    }
  }

  command("build") {
    description = t("cli.build.description")
    flag("watch") {
      description = t("cli.build.flag.watch")
    }
  }
}

生成

  • Rustaxum · reqwest
    客户端服务端
  • PythonFastAPI · httpx
    客户端服务端
  • TypeScriptFastify · fetch
    客户端服务端
  • Gonet/http · chi
    客户端服务端
  • OpenAPI 3.xJSON · YAML
    规范

安装

两条命令。

Box 以 adi cli 插件的形式发布。安装一次,然后通过 adi 命令行驱动。

$adiplugin installadi.box
$adibox

Released under the MIT License.