返回 CodeWhale
docs-runtime-api.ts
根目录 / web / lib / i18n / dictionaries / en / docs-runtime-api.ts
1 import type { DocsRuntimeApiDict } from "../types";
2
3 /**
4 * English reference dictionary for `app/[locale]/docs/runtime-api/page.tsx`
5 * ("Automate with the Runtime API"). Checked against docs/RUNTIME_API.md
6 * (entrypoints, defaults, auth, endpoints) and the handlers in
7 * crates/app-server/src/runtime_api.rs (`POST /v1/threads` → 201 ThreadRecord).
8 */
9 export const docsRuntimeApi: DocsRuntimeApiDict = {
10 metaTitle: "Automate with the Runtime API · Codewhale Docs",
11 metaDescription:
12 "Drive Codewhale from your own scripts and apps: run one-shot prompts in CI, or start the local HTTP API and send turns, stream events, and answer approvals.",
13 bodyClassName: "text-ink-soft leading-relaxed",
14 title: "Automate with the Runtime API",
15 lede:
16 "Use `codewhale exec` for a one-shot job, or follow this tutorial to create a thread and stream a turn through the local Runtime API. The [complete reference](/docs/runtime-reference), generated from the repository's main branch, covers routes, request fields, events and compatibility limits.",
17 sections: [
18 {
19 id: "exec",
20 title: "Run one job from a script",
21 blocks: [
22 {
23 code: `codewhale exec --no-tools "Reply with exactly: pong"
24 codewhale exec --auto --sandbox workspace-write "fix the failing test and run it again"
25 codewhale exec --auto --sandbox workspace-write --output-format stream-json "update the changelog"`,
26 lang: "Terminal",
27 },
28 {
29 p: "Plain `exec` runs the agent with the normal tool surface under your configured sandbox and approval settings; `--no-tools` answers once without tools. By default, `--auto` enables Full Access: tools run without asking, shell commands have no Codewhale sandbox, and trust mode lets file tools write outside the workspace. Any `--sandbox` other than `danger-full-access` (or the equivalent `sandbox_mode` in config) keeps trust mode off. Add `--sandbox workspace-write` for the [shell sandbox, where available](/docs/sandbox), and file-tool workspace restrictions; `external-sandbox` relies on your own isolation. Put flags before the prompt, and use `--` before prompt text that starts with `-` or contains literal exec flags. Runs that offer tools are saved in every output format. `--output-format stream-json` prints one JSON event per line and also saves answer-only runs so `--continue` can pick them up. `--max-turns` and `--allowed-tools` put limits on a run.",
30 },
31 ],
32 },
33 {
34 id: "start",
35 title: "Start the Runtime API",
36 blocks: [
37 { p: "Use bash or zsh with `curl`, `jq` and `openssl`, and a Codewhale build that supports `app-server --http`. Run all steps in the same terminal so the token, server process id and thread id remain available." },
38 { note: "The commands on this page exist in the published release; check `codewhale --version` before comparing behavior. Connecting a provider is required for the turn below, and that request uses your provider's normal billing; starting the server and checking `/health` do not send a model request." },
39 {
40 code: `export CODEWHALE_RUNTIME_TOKEN="$(openssl rand -hex 32)"
41 codewhale app-server --http &
42 CODEWHALE_RUNTIME_PID=$!
43 curl --fail --silent --show-error --retry 10 --retry-connrefused \ --retry-delay 1 http://127.0.0.1:7878/health`,
44 lang: "Terminal",
45 },
46 {
47 p: "The health command must return successfully before you continue; inspect the server output if it fails or the port is occupied. Keep the generated token private and send it as `Authorization: Bearer <token>` on every `/v1/*` request.",
48 },
49 ],
50 },
51 {
52 id: "turn",
53 title: "Send a turn and watch it",
54 blocks: [
55 {
56 code: `API=http://127.0.0.1:7878
57 auth() { printf 'Authorization: Bearer %s\\n' "$CODEWHALE_RUNTIME_TOKEN"; }
58
59 THREAD=$(curl -fsS -X POST "$API/v1/threads" -H @<(auth) \\
60 -H "Content-Type: application/json" -d '{}' | jq -er .id)
61
62 curl -fsS -X POST "$API/v1/threads/$THREAD/turns" -H @<(auth) \\
63 -H "Content-Type: application/json" -d '{"prompt": "Summarize README.md"}'
64
65 curl -fN "$API/v1/threads/$THREAD/events?since_seq=0" -H @<(auth)`,
66 lang: "Terminal",
67 },
68 {
69 p: "Check that thread creation returns a nonempty id and the turn request returns an accepted turn; the events stream should then show the turn and its recorded result. Keep the last accepted `seq` for reconnects, handle the terminal `stream.end` frame, and follow the [replay contract](/docs/runtime-reference#ending-and-resuming-a-thread-stream) instead of assuming every disconnect is recoverable. The header reaches curl through a file descriptor so the token stays out of the process list; that form needs bash or zsh and curl 7.55 or newer.",
70 },
71 {
72 rows: [
73 ["Stop a turn", "`POST /v1/threads/{id}/turns/{turn_id}/interrupt`"],
74 ["Answer an approval", "`POST /v1/approvals/{approval_id}`"],
75 ["Steer a running turn", "`POST /v1/threads/{id}/turns/{turn_id}/steer`"],
76 ["List saved sessions", "`GET /v1/sessions`"],
77 ],
78 },
79 {
80 p: "The [Runtime API reference](/docs/runtime-reference) renders the contract from the repository's main branch, including endpoint tables, request fields, event envelopes and version limits.",
81 },
82 ],
83 },
84 {
85 id: "stop",
86 title: "Stop the tutorial server",
87 blocks: [
88 { p: "Press Ctrl+C to close the event stream, then stop the server you started in this terminal. Closing the stream alone does not stop the server or interrupt an active model turn; use the interrupt endpoint above if needed." },
89 { code: 'kill "$CODEWHALE_RUNTIME_PID"\nunset CODEWHALE_RUNTIME_TOKEN CODEWHALE_RUNTIME_PID', lang: "Terminal" },
90 ],
91 },
92 {
93 id: "other",
94 title: "Pick another connection",
95 blocks: [
96 {
97 rows: [
98 ["codewhale app-server --stdio", "JSON-RPC over standard input and output, with no network listener. Good for an SDK or a local probe."],
99 ["codewhale serve --acp", "Agent Client Protocol for editors such as Zed."],
100 ["codewhale serve --mcp", "Offer Codewhale's tools to another MCP client. See [Connect tools with MCP](/docs/mcp)."],
101 ["codewhale web", "The built-in [browser client](/docs/web), on the same API."],
102 ["codewhale doctor --json", "Health and capabilities as JSON, with no secrets."],
103 ],
104 codeTerms: true,
105 },
106 ],
107 },
108 {
109 id: "security",
110 title: "Keep it private",
111 blocks: [
112 {
113 list: [
114 "The server listens on `127.0.0.1` by default. The token is a local guard, not a replacement for TLS or a VPN; do not expose the port to a network.",
115 "`--insecure-no-auth` is accepted only on a loopback address.",
116 "The API never returns your provider keys. Health and capability reports carry only metadata — no secrets, file contents, or messages.",
117 ],
118 },
119 ],
120 },
121 ],
122 next: [
123 { href: "/docs/runtime-reference", label: "Read the Runtime API reference", note: "Find exact routes, fields, event schemas and compatibility behavior." },
124 {
125 href: "/docs/web",
126 label: "Open the browser client",
127 note: "A ready-made client for the same API.",
128 },
129 {
130 href: "/docs/hooks",
131 label: "Run commands on events",
132 note: "React to session events without writing a client.",
133 },
134 {
135 href: "/docs/fleet",
136 label: "Run a workflow",
137 note: "Durable, multi-step runs you can check from any terminal.",
138 },
139 ],
140 sourceNote: "Source document: docs/RUNTIME_API.md · Update docs-map.ts when changing.",
141 };
142
142 lines TYPESCRIPT