返回 CodeWhale
README.md
根目录 / npm / runtime-sdk / README.md
1 # @codewhale/runtime-sdk
2
3 Small JavaScript helpers and TypeScript declarations for Codewhale's local
4 Runtime API. The package is intentionally transport-only: it never bypasses the
5 Rust runtime, sandbox, approvals, provider configuration, or fleet ledger.
6
7 ```js
8 import { createRuntimeClient } from "@codewhale/runtime-sdk";
9
10 const client = createRuntimeClient({
11 baseUrl: "http://127.0.0.1:7878",
12 token: process.env.CODEWHALE_RUNTIME_TOKEN,
13 });
14
15 const created = await client.createFleetRun({
16 target: "this_computer",
17 roles: [{ name: "reviewer" }, { name: "verifier" }],
18 workflow: {
19 id: "release-check",
20 kind: "parallel",
21 tasks: [
22 { id: "review", name: "Review", instructions: "Review locally.", worker: { role: "reviewer" } },
23 { id: "verify", name: "Verify", instructions: "Verify locally.", worker: { role: "verifier" } },
24 ],
25 },
26 });
27
28 // Creation is durable but does not launch work. Launch remains explicit.
29 await client.startFleetRun(created.run.id);
30
31 let cursor;
32 for await (const event of client.fleetEvents(created.run.id, { after: cursor })) {
33 if (event.cursor) cursor = event.cursor; // persist durable cursors only
34 if (event.event === "fleet.replay.cursor_unavailable") {
35 // Reload getFleetRun(created.run.id), then reconnect without the old cursor.
36 }
37 }
38 ```
39
40 ## Fleet Helpers
41
42 - `listFleetRuns()`
43 - `getFleetRun(runId)`
44 - `listFleetWorkers(runId)`
45 - `getFleetWorker(workerId)`
46 - `interruptWorker(workerId)`
47 - `stopWorker(workerId)`
48 - `restartWorker(workerId)`
49 - `stopFleetRun(runId)`
50 - `startFleetRun(runId)`
51 - `replayFleetEvents(runId, { after, limit })`
52 - `fleetEvents(runId, { after, limit })`
53 - `createFleetRun(spec)`
54
55 The v0.9.4 Runtime implements the complete local managed-Fleet path. A creation
56 request must name its roles, define a `parallel` Workflow, and select the
57 explicit `this_computer` target. `another_computer` and `cloud` are contract
58 values but fail closed until those targets are implemented. Event cursors are
59 opaque and durable across Runtime restarts; if ledger compaction removes an old
60 cursor, replay returns a conflict so the client can reload the run projection.
61 Local worker IDs are generated per run; managed creation does not yet accept
62 caller-assigned `worker_specs` because worker controls address IDs globally.
63
64 Older runtimes that do not expose one of these endpoints produce a
65 `RuntimeCapabilityError` with a stable capability string instead of a generic
66 fetch failure.
67
67 lines MARKDOWN