Workspace Runtime API
Workspace Runtime API 提供每個 workspace 內的 AI Chat thread、Agent 執行、檔案操作與即時事件能力。Claude Code、Codex 與 OpenCode 都透過同一套多 Agent runtime 介面運作。
互動式文件
- Swagger UI:
/workspaces/{workspaceId}/runtime/docs - ReDoc:
/workspaces/{workspaceId}/runtime/redoc
每個 Workspace 都有獨立的 Runtime instance 與 revision。先透過 Manager 啟動 Workspace,再從目前 Platform Public Origin 使用 /workspaces/{workspaceId}/runtime/...;瀏覽器不接收 Runtime host 或 port。
Base URL
/workspaces/{workspaceId}/runtime
Runtime access gate
除精確 public health 與 signed internal route 外,Runtime 只接受 Manager 簽發、audience
為 workspace-runtime 的 Workspace Execution Access Grant。Runtime 在本地使用 public JWKS
驗證簽章、固定 60 秒 TTL、token kind、明確 action、workspaceId、runtimeInstanceId 與
runtimeAccessRevision;任一欄位不符都 fail closed。一般 Runtime action 不以 KB mount
revision 作為全域 gate;只有 /knowledge 與掛載管理操作會明確檢查 KB mount 狀態。
| 路徑/方法 | Action |
|---|---|
一般GET/HEAD | runtime_read |
| 一般寫入方法 | runtime_write |
| Claude/Codex/OpenCode raw settings 與 MCP env/headers | workspace_settings |
| Thread REST(讀取與 mutation)及 agent session | agent |
| Thread events WebSocket handshake | runtime_read |
| Automation | automation |
| Client Browser Relay | browser_automation |
每個 action 會映射到中央 Workspace OperationId。Reader 只能進入安全 read projection;runtime_write、workspace_settings、terminal、agent、automation 與 browser_automation 需要 Manager、Owner 或 Platform Admin。完整規則與 403/423 語意請參考 使用者、群組與權限。
Runtime 依封閉的 route × method inventory 分類 action。敏感精確 route 與敏感 wildcard 優先於一般 mutation/read;未知或同時命中多個 family、Manager timeout 或驗證失敗時,Runtime 會在呼叫 upstream 前 fail closed。Runtime URL 只提供定位,不是授權憑證,每次請求都重新驗證。
Frontend 先使用 opaque Manager session 向
POST /api/v1/workspaces/{workspaceId}/execution-grants 申請 Grant;Manager 對每個 action
完成授權後才簽發。Runtime 不接觸 external OIDC token,也不逐 request 回呼 Manager。
Execution Grant 在 TTL 內可重複使用;Manager→Runtime 內部命令與 pairing 則使用不同
token kind、audience、verifier 與 one-time replay state。兩條 interface 都不接受前端傳入
角色作為授權依據。
Direct/group share 變更、群組成員變更、帳號停用、Owner 重新指派、Platform Admin 降權 及 Public KB 改回 Private 時,Manager 會提升 runtime access revision。舊 Grant 因 revision fence 失效;cached Runtime URL 或未過期但 revision 過舊的 Grant 都不能繞過驗證。
主要端點
健康檢查
GET /health
檔案管理
| Method | 路徑 | 說明 |
|---|---|---|
GET | /api/v1/files/tree | 取得目錄樹 |
GET | /api/v1/files/tree/children | 延遲載入子節點 |
GET | /api/v1/files/search | 搜尋檔案 |
GET/PUT | /api/v1/files/content | 讀取/寫入單一檔案內容 |
POST | /api/v1/files/content/batch | 批次寫入多個檔案內容 |
GET | /api/v1/files/download | 下載檔案 |
POST/DELETE | /api/v1/files | 建立/刪除檔案或資料夾 |
POST | /api/v1/files/upload | 上傳檔案 |
POST | /api/v1/files/copy | 複製檔案或資料夾 |
POST | /api/v1/files/move | 搬移或重新命名 |
POST | /api/v1/files/batch-delete | 批次刪除 |
POST/GET | /api/v1/files/archive、/api/v1/files/archive/{operation_id} | 建立壓縮任務並查詢進度 |
GET | /api/v1/files/archive/{operation_id}/download | 下載完成的 ZIP |
POST/GET | /api/v1/files/extract、/api/v1/files/extract/{operation_id} | 建立解壓任務並查詢進度 |
GET | /api/v1/files/history | 檔案異動歷史 |
POST | /api/v1/files/history/{entry_id}/restore | 還原指定歷史版本 |
Agent 與 CLI 設定
這組設定 API 管理 workspace 內的 agent 設定,涵蓋 Claude Code、Codex、OpenCode 的 rules、hooks、MCP、skills、slash commands 與 subagents 等資源。
| Method | 路徑 | 說明 |
|---|---|---|
GET | /api/v1/workspaces/{workspace_id}/claude-code/settings | 取得 Claude Code settings |
PUT | /api/v1/workspaces/{workspace_id}/claude-code/settings | 更新 Claude Code settings |
GET | /api/v1/workspaces/{workspace_id}/codex | 取得 Codex 設定能力 |
GET/PUT | /api/v1/workspaces/{workspace_id}/codex/config | 取得/更新 Codex config |
GET | /api/v1/workspaces/{workspace_id}/{tool}/mcp-servers | 取得 MCP server 設定 |
PUT | /api/v1/workspaces/{workspace_id}/{tool}/mcp-servers/{scope}/{server_name} | 更新 MCP server |
GET | /api/v1/workspaces/{workspace_id}/{tool}/skills/tree | 取得 skills 檔案樹 |
GET | /api/v1/workspaces/{workspace_id}/{tool}/slash-commands | 列出 slash commands |
GET | /api/v1/workspaces/{workspace_id}/cli-settings/{tool}/prompt-invocations | 取得可直接送出的 Commands 與 Skills invocation catalog |
tool 使用 claude-code、codex 或 opencode;各 provider 支援的 scope 與可寫資源
不同,完整 request/response schema 以目前 Runtime OpenAPI 為準。
Prompt invocation catalog 是 AI Chat 與 Automation 共用的唯讀契約。Runtime 會依指定工具
聚合 Commands 與 Skills,並回傳已格式化的 invocation、穩定項目 ID、可用 scope、內容
revision 與來源錯誤。部分來源失敗時回傳 200 與 completeness: degraded;所有來源都
無法讀取時回傳 503。Runtime 每次請求都重新驗證來源,不沿用來源清單快取;Prompt
Invocation Picker 每次開啟都重新載入 catalog,且 Picker 消費端原樣使用 Runtime 回傳的
invocation,不自行拼接命令格式。
Raw settings、MCP environment variables、HTTP headers、API key 與 token 都屬敏感設定,讀寫一律使用 workspace_settings action;一般 runtime_read 或 agent action 不能讀取這些值。
AI Chat Threads
Thread metadata 與 history 分離;history 只使用 Message Item timeline。完整機制請見 AI Chat 前後端架構。
| Method | 路徑 | 說明 |
|---|---|---|
GET | /api/v1/threads | 列出 threads |
POST | /api/v1/threads/draft | 建立 draft thread |
GET | /api/v1/threads/{thread_id} | 取得 thread 詳情 |
PATCH | /api/v1/threads/{thread_id}/draft | 更新 draft |
POST | /api/v1/threads/{thread_id}/submit | 送出 draft 並啟動 agent |
POST | /api/v1/threads/{thread_id}/messages | 追加訊息 |
GET | /api/v1/threads/{thread_id}/timeline | 以 beforeSequence 讀取 Message Item history |
POST | /api/v1/threads/{thread_id}/timeline/items/batch-get | 批次刷新最多 200 個已知 timeline items |
GET | /api/v1/threads/{thread_id}/messages/{message_id}/tool-result | 依需要讀取完整 tool result |
POST | /api/v1/threads/{thread_id}/questions/{message_id}/answer | 回答互動式問題 |
POST | /api/v1/threads/{thread_id}/stop | 停止目前 Turn;有排隊訊息時接續下一則,否則 thread 結束為 canceled |
POST | /api/v1/threads/{thread_id}/retry | 重試 thread |
POST | /api/v1/threads/{thread_id}/archive | 封存 thread |
GET | /api/v1/threads/{thread_id}/attachments | 列出附件 |
POST | /api/v1/threads/{thread_id}/attachments | 上傳附件 |