@jr2/orchestrator 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +23 -0
- package/bin/server.ts +23 -0
- package/console/canvas.ts +843 -0
- package/console/components/app.ts +79 -0
- package/console/components/drawer.ts +131 -0
- package/console/components/fleet.ts +117 -0
- package/console/components/machine-pane.ts +85 -0
- package/console/components/nav.ts +81 -0
- package/console/components/schema-form.ts +137 -0
- package/console/main.ts +383 -0
- package/console/page.html +28 -0
- package/console/store.ts +336 -0
- package/console/style.css +700 -0
- package/console/tsconfig.json +18 -0
- package/package.json +61 -0
- package/src/actor.ts +562 -0
- package/src/agent.ts +124 -0
- package/src/ambient.ts +50 -0
- package/src/config.ts +297 -0
- package/src/customize.ts +348 -0
- package/src/durability.ts +135 -0
- package/src/fingerprint.ts +92 -0
- package/src/gate.ts +76 -0
- package/src/harness-client.ts +503 -0
- package/src/http.ts +753 -0
- package/src/images.ts +303 -0
- package/src/index.ts +40 -0
- package/src/instance.ts +294 -0
- package/src/machine-doc.ts +334 -0
- package/src/names.ts +78 -0
- package/src/open.ts +17 -0
- package/src/parts.ts +500 -0
- package/src/pool.ts +284 -0
- package/src/registration.ts +340 -0
- package/src/repo-fetch.ts +259 -0
- package/src/repo-identity.ts +145 -0
- package/src/repos.ts +330 -0
- package/src/run-host.ts +1095 -0
- package/src/sandbox-kubectl.ts +1136 -0
- package/src/server.ts +220 -0
- package/src/setup.ts +360 -0
- package/src/snapshot-store.ts +150 -0
- package/src/stub-harness.ts +217 -0
- package/src/tokens.ts +126 -0
- package/src/vocabulary.ts +99 -0
- package/src/wire.ts +103 -0
- package/src/workspace.ts +874 -0
- package/tsconfig.instance.json +26 -0
package/src/wire.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// The Harness wire as the CLIENT reads it (ADR-0027): the shapes `harness-client.ts` parses off
|
|
2
|
+
// the durable stream, and the run-narrative echo body `run-host.ts` pushes (ADR-0023).
|
|
3
|
+
//
|
|
4
|
+
// `@jr2/harness` SERVES the wire and owns the serving constants; this module is the Orchestrator's
|
|
5
|
+
// own view of it, and it lives here for one reason: `@jr2/orchestrator` is published to npm and
|
|
6
|
+
// `@jr2/harness` is not (ADR-0009/0043 — the Harness reaches users as a Kit image). The instance's
|
|
7
|
+
// program includes this package's `.ts` sources (zero-build), so an import of `@jr2/harness/wire`
|
|
8
|
+
// from here is a `Cannot find module` in every INSTALLED instance — and since ADR-0050 that is a
|
|
9
|
+
// `jr2 up` refusal, not a warning. The literals below are restated for the same reason a type
|
|
10
|
+
// cannot be: nothing published may reach into a package that was never published.
|
|
11
|
+
//
|
|
12
|
+
// The two views are held in agreement by the compiler, not by care: `test/wire-types.test.ts`
|
|
13
|
+
// asserts each shape here is mutually assignable with `@jr2/harness/wire`'s, and `@jr2/harness`
|
|
14
|
+
// stays a devDependency so that file — and only that file — can see the server's copy.
|
|
15
|
+
|
|
16
|
+
/** How a Submission ends (ADR-0024/0027): `completed` (the prompt resolved), `failed` (the turn
|
|
17
|
+
* threw — provider failure after retries, or the Menu connect/list failed), `aborted` (swept). */
|
|
18
|
+
export type SettlementOutcome = "completed" | "failed" | "aborted";
|
|
19
|
+
|
|
20
|
+
/** The error payload a non-`completed` Settlement carries. */
|
|
21
|
+
export type SettlementError = { type: string; message?: string };
|
|
22
|
+
|
|
23
|
+
/** `SettlementError.type` for a swept Submission (ADR-0024/0025). */
|
|
24
|
+
export const SUBMISSION_ABORTED = "submission_aborted";
|
|
25
|
+
|
|
26
|
+
/** `SettlementError.type` for a Turn the Harness ended as a Runaway (ADR-0035) — no fourth
|
|
27
|
+
* `SettlementOutcome`; the typed error on a `failed` settlement is what lets the Agent actor switch
|
|
28
|
+
* on the class (one fresh-conversation reroll) without parsing prose. */
|
|
29
|
+
export const SUBMISSION_RUNAWAY = "runaway";
|
|
30
|
+
|
|
31
|
+
/** One settled Submission, in the shape `?view=history`'s `settlements` reports. */
|
|
32
|
+
export type Settlement = {
|
|
33
|
+
submissionId: string;
|
|
34
|
+
outcome: SettlementOutcome;
|
|
35
|
+
error?: SettlementError;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** Where a chunk sits on the durable stream. Ordering only (`batch`, then `index`); the Harness
|
|
39
|
+
* appends each chunk as its own batch of one. */
|
|
40
|
+
export type StreamPosition = { batch: number; index: number };
|
|
41
|
+
|
|
42
|
+
/** The envelope every stream chunk carries. */
|
|
43
|
+
type StreamChunk<T extends string> = { type: T; conversationId: string; position: StreamPosition };
|
|
44
|
+
|
|
45
|
+
/** A completed conversation message landing on the stream. */
|
|
46
|
+
export type MessageAppendedEvent = StreamChunk<"message-appended"> & {
|
|
47
|
+
message: { id: string; role: "user" | "assistant"; parts: { type: "text"; text: string; state: "done" }[] };
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/** A Settlement landing on the stream, flat — what `wait` matches by submissionId, and what wakes
|
|
51
|
+
* a parked long-poll. */
|
|
52
|
+
export type SubmissionSettledEvent = StreamChunk<"submission-settled"> & Settlement;
|
|
53
|
+
|
|
54
|
+
/** One event on the durable stream (`GET ?offset=…&view=updates` → 200 JSON array). */
|
|
55
|
+
export type StreamEvent = MessageAppendedEvent | SubmissionSettledEvent;
|
|
56
|
+
|
|
57
|
+
/** Response header: the offset to resume the stream from (every stream read carries it). */
|
|
58
|
+
export const STREAM_NEXT_OFFSET_HEADER = "stream-next-offset";
|
|
59
|
+
|
|
60
|
+
/** `?view=` value the client reads. A read with neither view is `updates`. */
|
|
61
|
+
export const VIEW_UPDATES = "updates";
|
|
62
|
+
|
|
63
|
+
/** `?live=` value: park until a new event or timeout (204 + the same headers). Long-poll is the
|
|
64
|
+
* ONLY wait transport (ADR-0027) — no SSE, no `?wait=result`. */
|
|
65
|
+
export const LIVE_LONG_POLL = "long-poll";
|
|
66
|
+
|
|
67
|
+
// ---- The run-narrative echo (`POST /echo` — ADR-0023) ------------------------------------------
|
|
68
|
+
// "Print these events": the Orchestrator — the observation feed's one subscriber (ADR-0022) — tees
|
|
69
|
+
// the owning run's feed to the enclosing Workspace's Harness, which renders it into its own pod log.
|
|
70
|
+
// The wire payload is the STRUCTURED event, never a preformatted string: the Harness renders, and
|
|
71
|
+
// printing stays ADR-0023's craft.
|
|
72
|
+
|
|
73
|
+
/** One live child MACHINE's place, nested — state keys and spawn ids only, by construction. A
|
|
74
|
+
* root's value alone says almost nothing about where a run is (the work happens in children:
|
|
75
|
+
* a `workspace()` body is one), so the narrative carries the tree. */
|
|
76
|
+
export type EchoStatusChild = { id: string; value: unknown; children?: EchoStatusChild[] };
|
|
77
|
+
|
|
78
|
+
/** The run moved: one status delta, projected to what the narrative needs — the Machine's state
|
|
79
|
+
* value (root + child machines) and the run-lifecycle status. Deliberately not the full run
|
|
80
|
+
* status: context is the workflow's working data, and the log narrates, it does not mirror
|
|
81
|
+
* state. */
|
|
82
|
+
export type EchoStatusEvent = { kind: "status"; status: string; value: unknown; children?: EchoStatusChild[] };
|
|
83
|
+
|
|
84
|
+
/** An author Emit (the sole author API for the narrative — no `log()` primitive exists or will).
|
|
85
|
+
* The PAYLOAD rides here: this endpoint is instance-token-gated wire, so the ADR-0014 open band
|
|
86
|
+
* — which carries Emit types alone — is not widened by it. */
|
|
87
|
+
export type EchoEmitEvent = { kind: "emit"; event: { type: string } & Record<string, unknown> };
|
|
88
|
+
|
|
89
|
+
/** MARKER, not mirror (ADR-0023): a Turn hosted on another Harness (a Menu-only Agent on the
|
|
90
|
+
* Instance Harness — ADR-0031) was admitted — the Agent and its framing. Its transcript prints
|
|
91
|
+
* exactly once, where the Turn ran; the enclosing Workspace's log gets this line and the pick. */
|
|
92
|
+
export type EchoAdmissionEvent = { kind: "admission"; agent: string; prompt: string };
|
|
93
|
+
|
|
94
|
+
/** The second marker: the remotely-hosted Turn's settlement pick — the Menu event (and payload)
|
|
95
|
+
* the Agent ended its turn with. */
|
|
96
|
+
export type EchoPickEvent = { kind: "pick"; agent: string; event: string; payload?: Record<string, unknown> };
|
|
97
|
+
|
|
98
|
+
/** One structured run-narrative event, as the echo body carries it. */
|
|
99
|
+
export type EchoEvent = EchoStatusEvent | EchoEmitEvent | EchoAdmissionEvent | EchoPickEvent;
|
|
100
|
+
|
|
101
|
+
/** What `POST /echo` accepts: feed events in feed order. The answer is `{ printed }` — how many
|
|
102
|
+
* lines landed on stdout (an unrenderable event prints nothing; it never errors the batch). */
|
|
103
|
+
export type EchoRequest = { events: EchoEvent[] };
|