feat(runtime-sdk): add fleet helper client
Refs #3163. Adds the @codewhale/runtime-sdk workspace with typed fleet Runtime API helpers, protocol-shaped TypeScript declarations, JSON/SSE event fixture handling, and typed RuntimeCapabilityError failures for create/event-stream endpoints that the Rust API has not exposed yet. Documents the SDK contract in docs/RUNTIME_API.md and wires npm workspace verification through npm test --workspace @codewhale/runtime-sdk.
This commit is contained in:
@@ -450,6 +450,51 @@ User-supplied origins **stack on top of** the built-in defaults; they do not
|
||||
replace them. Wildcard origins are not supported — the explicit allow-list
|
||||
model is preserved. Added in v0.8.10 (#561).
|
||||
|
||||
## Runtime SDK Fleet Helpers
|
||||
|
||||
The v0.8.60 Runtime SDK fixture lives in `npm/runtime-sdk` and is exposed as
|
||||
the `@codewhale/runtime-sdk` workspace package. It is deliberately thin: every
|
||||
helper calls the local Rust Runtime API and therefore cannot bypass CodeWhale's
|
||||
sandbox, approval prompts, provider configuration, or fleet ledger authority.
|
||||
|
||||
```js
|
||||
import { createRuntimeClient } from "@codewhale/runtime-sdk";
|
||||
|
||||
const client = createRuntimeClient({
|
||||
baseUrl: "http://127.0.0.1:7878",
|
||||
token: process.env.CODEWHALE_RUNTIME_TOKEN,
|
||||
});
|
||||
|
||||
const { runs } = await client.listFleetRuns();
|
||||
const workers = await client.listFleetWorkers(runs[0].id);
|
||||
await client.restartWorker(workers.workers[0].worker_id);
|
||||
```
|
||||
|
||||
Fleet helpers cover the v0.8.60 HTTP surface:
|
||||
|
||||
| Helper | Runtime API route |
|
||||
|---|---|
|
||||
| `listFleetRuns()` | `GET /v1/fleet/runs` |
|
||||
| `getFleetRun(runId)` | `GET /v1/fleet/runs/{run_id}` |
|
||||
| `listFleetWorkers(runId)` | `GET /v1/fleet/runs/{run_id}/workers` |
|
||||
| `getFleetWorker(workerId)` | `GET /v1/fleet/workers/{worker_id}` |
|
||||
| `interruptWorker(workerId)` | `POST /v1/fleet/workers/{worker_id}/interrupt` |
|
||||
| `restartWorker(workerId)` | `POST /v1/fleet/workers/{worker_id}/restart` |
|
||||
| `stopFleetRun(runId)` | `POST /v1/fleet/runs/{run_id}/stop` |
|
||||
|
||||
`createFleetRun(spec)` and `fleetEvents(runId)` are typed ahead of the current
|
||||
Rust routes so editor/web clients can code against the intended SDK contract.
|
||||
Until the Runtime API exposes `POST /v1/fleet/runs` and a fleet event stream,
|
||||
the SDK raises `RuntimeCapabilityError` with stable capability strings
|
||||
(`fleet_run_create`, `fleet_event_stream`) instead of surfacing those gaps as
|
||||
generic fetch failures.
|
||||
|
||||
Verification:
|
||||
|
||||
```bash
|
||||
npm test --workspace @codewhale/runtime-sdk
|
||||
```
|
||||
|
||||
## Session lifecycle (native UI supervision)
|
||||
|
||||
| Operation | Endpoint |
|
||||
|
||||
Reference in New Issue
Block a user