Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
630 changes: 1 addition & 629 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt"] }
uuid = { version = "1", features = ["serde", "v4"] }
jsonwebtoken = { version = "9", default-features = false }
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }

[profile.release]
opt-level = "z"
Expand Down
36 changes: 9 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,22 @@ Generated Qoder documentation may exist under `.qoder/`; it is generated output

## Runtime Shape

The default runtime is `embedded`:
All Gateway sessions use the embedded runtime:

1. A client creates a session through the Rust gateway.
2. The session owns a `CodexAppServerBridge`.
3. The bridge starts and manages one `codex app-server` subprocess over stdio.
4. App-server notifications are folded into session state and streamed to the client over SSE.

The optional `devbox` runtime is a remote execution backend:
Brain deployment tasks use the same embedded runtime, but expose a polling-only task API instead of the interactive session API. Gateway does not create or manage Devbox runtimes for deployment requests.

1. The outer gateway creates a Devbox runtime.
2. It waits for the gateway inside Devbox to become ready.
3. It creates a remote session in that inner gateway.
4. The inner gateway uses the `embedded` runtime to run `codex app-server`.

`devbox` is runtime infrastructure, not a product mode.
If deployment work runs in Devbox, an external system is responsible for creating the Devbox and starting this gateway inside it before calling the Brain Deployment API.

## Brain Deployment API

`POST /api/deployments` is a Brain application reserved API. It is not intended to describe a general deployment product surface.
`POST /api/brain/deployments` is a Brain application API. It is not intended to describe a general deployment product surface.

The endpoint creates a Codex task that deploys a repository and reports a machine-readable deployment result. When the active session runtime is Devbox-backed, Gateway bootstraps the Devbox runtime before starting the Brain deployment task.
The endpoint creates a local embedded Codex task that installs the deployment skill if needed, builds the repository image, pushes it to GHCR, generates a Sealos template, and reports a machine-readable deployment result containing both the image reference and template content. It does not expose intermediate Codex output or accept follow-up user turns.

## HTTP API

Expand All @@ -44,8 +39,8 @@ The endpoint creates a Codex task that deploys a repository and reports a machin
- `DELETE /api/sessions/:id`
- `GET /api/threads`
- `GET /api/threads/:threadId`
- `POST /api/deployments`
- `GET /api/deployments/:threadId`
- `POST /api/brain/deployments`
- `GET /api/brain/deployments/:threadId`

Legacy single-session routes such as `/api/state`, `/api/events`, `/api/turn`, and `/api/thread/new` are removed and return `410 Gone`.

Expand Down Expand Up @@ -89,21 +84,8 @@ Gateway-owned settings use the `CODEX_GATEWAY_` prefix.
- `CODEX_GATEWAY_MAX_SESSIONS`: maximum live sessions. Defaults to `12`.
- `CODEX_GATEWAY_SESSION_TTL_MS`: idle session TTL. Defaults to `1800000`.
- `CODEX_GATEWAY_SESSION_SWEEP_INTERVAL_MS`: cleanup sweep interval. Defaults to `60000`.
- `CODEX_GATEWAY_SESSION_RUNTIME`: session runtime backend. Defaults to `embedded`. Supported values are `embedded` and `devbox`.
- `CODEX_GATEWAY_MAX_DEPLOYMENTS`: maximum active Brain deployment tasks. Defaults to `4`.
- `CODEX_GATEWAY_DEPLOYMENT_TIMEOUT_MS`: Brain deployment timeout and session keepalive window. Defaults to `3600000`.

Devbox-related settings are only used when the runtime is `devbox`:

- `CODEX_GATEWAY_DEVBOX_BASE_URL`
- `CODEX_GATEWAY_DEVBOX_TOKEN`
- `CODEX_GATEWAY_DEVBOX_JWT_SIGNING_KEY`
- `CODEX_GATEWAY_DEVBOX_NAMESPACE`
- `CODEX_GATEWAY_DEVBOX_RUNTIME_IMAGE`
- `CODEX_GATEWAY_DEVBOX_ARCHIVE_AFTER_PAUSE_TIME`
- `CODEX_GATEWAY_DEVBOX_WAIT_TIMEOUT_SECONDS`
- `CODEX_GATEWAY_DEVBOX_GATEWAY_READY_TIMEOUT_SECONDS`
- `CODEX_GATEWAY_DEVBOX_BOOTSTRAP_TIMEOUT_SECONDS`

Devbox lifecycle is external to this gateway. If the gateway is running in Devbox, configure the process with the normal gateway settings above.

## Verification

Expand Down
36 changes: 9 additions & 27 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,22 @@ Codex Gateway 是一个 Rust HTTP/SSE 网关,用来通过小型 API 和浏览

## Runtime 形态

默认 runtime 是 `embedded`
所有 Gateway session 都使用 embedded runtime

1. 客户端通过 Rust gateway 创建 session。
2. session 拥有一个 `CodexAppServerBridge`。
3. bridge 通过 stdio 启动并管理一个 `codex app-server` 子进程。
4. app-server 的通知会写入 session state,并通过 SSE 推给客户端。

可选的 `devbox` runtime 是远端执行后端:
Brain deployment task 也使用同一个 embedded runtime,但对外暴露的是 polling-only 的任务 API,而不是可交互 session API。Gateway 收到部署请求时不会创建或管理 Devbox runtime。

1. 外层 gateway 创建 Devbox runtime。
2. 外层 gateway 等待 Devbox 内部的 gateway ready。
3. 外层 gateway 在内部 gateway 里创建远端 session。
4. 内部 gateway 使用 `embedded` runtime 运行 `codex app-server`。

`devbox` 是 runtime 基础设施,不是产品模式。
如果部署工作运行在 Devbox 中,外部系统负责先创建 Devbox,并在 Devbox 内启动这个 gateway,然后再调用 Brain Deployment API。

## Brain Deployment API

`POST /api/deployments` 是为 Brain 应用预留的接口,不是通用部署产品接口。
`POST /api/brain/deployments` Brain 应用接口,不是通用部署产品接口。

这个接口会创建一个 Codex task,用来部署仓库并返回机器可读的部署结果。当当前 session runtime 由 Devbox 承载时,Gateway 会先 bootstrap Devbox runtime,再启动 Brain deployment task
这个接口会创建一个本地 embedded Codex task。该 task 会按需安装 deployment skill,构建仓库镜像,推送到 GHCR,生成 Sealos template,并返回同时包含镜像地址和 template 内容的机器可读部署结果。接口不暴露 Codex 中间输出,也不接受用户继续输入

## HTTP API

Expand All @@ -44,8 +39,8 @@ Codex Gateway 是一个 Rust HTTP/SSE 网关,用来通过小型 API 和浏览
- `DELETE /api/sessions/:id`
- `GET /api/threads`
- `GET /api/threads/:threadId`
- `POST /api/deployments`
- `GET /api/deployments/:threadId`
- `POST /api/brain/deployments`
- `GET /api/brain/deployments/:threadId`

旧的单 session 路由已经移除,例如 `/api/state`、`/api/events`、`/api/turn`、`/api/thread/new`,现在会返回 `410 Gone`。

Expand Down Expand Up @@ -89,21 +84,8 @@ Gateway 自有配置统一使用 `CODEX_GATEWAY_` 前缀。
- `CODEX_GATEWAY_MAX_SESSIONS`:最大在线 session 数,默认 `12`
- `CODEX_GATEWAY_SESSION_TTL_MS`:空闲 session TTL,默认 `1800000`
- `CODEX_GATEWAY_SESSION_SWEEP_INTERVAL_MS`:清理扫描间隔,默认 `60000`
- `CODEX_GATEWAY_SESSION_RUNTIME`:session runtime backend,默认 `embedded`;支持值只有 `embedded` 和 `devbox`
- `CODEX_GATEWAY_MAX_DEPLOYMENTS`:最大并发 Brain deployment task 数,默认 `4`
- `CODEX_GATEWAY_DEPLOYMENT_TIMEOUT_MS`:Brain deployment 超时和 session keepalive 窗口,默认 `3600000`

Devbox 相关配置只在 runtime 为 `devbox` 时使用:

- `CODEX_GATEWAY_DEVBOX_BASE_URL`
- `CODEX_GATEWAY_DEVBOX_TOKEN`
- `CODEX_GATEWAY_DEVBOX_JWT_SIGNING_KEY`
- `CODEX_GATEWAY_DEVBOX_NAMESPACE`
- `CODEX_GATEWAY_DEVBOX_RUNTIME_IMAGE`
- `CODEX_GATEWAY_DEVBOX_ARCHIVE_AFTER_PAUSE_TIME`
- `CODEX_GATEWAY_DEVBOX_WAIT_TIMEOUT_SECONDS`
- `CODEX_GATEWAY_DEVBOX_GATEWAY_READY_TIMEOUT_SECONDS`
- `CODEX_GATEWAY_DEVBOX_BOOTSTRAP_TIMEOUT_SECONDS`

Devbox 生命周期在 gateway 外部管理。如果 gateway 运行在 Devbox 中,仍然只需要配置上面的常规 gateway 设置。

## 验证

Expand Down
Loading
Loading