@amd-gaia/gaia 0.1.0 → 0.2.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.
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Process lifecycle for the two binaries this package installs.
3
+ *
4
+ * **Sidecar** — locate the frozen binary, spawn it, poll `GET /health`, check the
5
+ * contract version via `GET /version`, and shut it down killing the whole process
6
+ * tree. Tree-kill matters: a PyInstaller one-file build spawns a child uvicorn
7
+ * process that `child.kill()` on the parent does NOT reap, leaving the port held.
8
+ *
9
+ * **TUI** — exec it with stdio inherited and propagate its exit code, so the
10
+ * terminal UI owns the terminal completely.
11
+ *
12
+ * Note on who spawns the sidecar in the normal `gaia` flow: the GAIA daemon does.
13
+ * The TUI reaches agents through the daemon's relay and deliberately never holds a
14
+ * sidecar bearer token, so `gaia run` stages the *verified* sidecar binary into the
15
+ * daemon's cache and lets the daemon own its process. The helpers below are the
16
+ * direct path — used by `gaia serve` and by programmatic integrators who want the
17
+ * REST surface without a daemon.
18
+ */
19
+ import { type ChildProcess } from "node:child_process";
20
+ import { type BinaryLock } from "./platform.js";
21
+ export declare const DEFAULT_HOST = "127.0.0.1";
22
+ /** Matches `gaia_agent.server.DEFAULT_PORT`. NEVER 4001 (repo-reserved). */
23
+ export declare const DEFAULT_PORT = 8141;
24
+ /** Repo-wide reserved port. Nothing here may ever bind it. */
25
+ export declare const RESERVED_PORT = 4001;
26
+ /** The apiVersion this package is built against (`server.py: API_VERSION`). */
27
+ export declare const API_VERSION = "2.12";
28
+ /** The agent id in the sidecar's route prefix (`/v1/gaia/...`). */
29
+ export declare const AGENT_ID = "gaia";
30
+ /** `GET /health` response. */
31
+ export interface HealthResponse {
32
+ status: string;
33
+ service?: string;
34
+ }
35
+ /** `GET /version` response — the key names are a contract, not a convention. */
36
+ export interface VersionResponse {
37
+ apiVersion: string;
38
+ agentVersion: string;
39
+ }
40
+ /** Basename the sidecar executable is written as (matches the lock). */
41
+ export declare function sidecarExecutableName(platform?: NodeJS.Platform): string;
42
+ /**
43
+ * Basename the TUI executable is written as. Deliberately `gaia-tui`, not
44
+ * `gaia`: npm installs its own `gaia` bin shim, and a same-named executable in a
45
+ * cache dir on PATH would shadow it.
46
+ */
47
+ export declare function tuiExecutableName(platform?: NodeJS.Platform): string;
48
+ export interface ResolveOptions {
49
+ /** Directory the binary was fetched into. */
50
+ resourcesDir: string;
51
+ /** Override the executable basename (defaults per-platform). */
52
+ executable?: string;
53
+ /**
54
+ * Re-verify the file's SHA-256 against `binaries.lock.json` before handing
55
+ * back a path that is about to be spawned. Default `true` — the cache dir is
56
+ * predictable, so anything that can write it could otherwise get code run.
57
+ * Set `false` only for a binary you built yourself, which no lock describes.
58
+ */
59
+ verify?: boolean;
60
+ /** Pre-loaded lock, to avoid re-reading it per call. */
61
+ lock?: BinaryLock;
62
+ }
63
+ export declare function resolveSidecarPath(opts: ResolveOptions): string;
64
+ export declare function resolveTuiPath(opts: ResolveOptions): string;
65
+ export interface SpawnOptions {
66
+ /** Absolute path to the sidecar binary. */
67
+ binaryPath: string;
68
+ /** Bind host. Default 127.0.0.1. */
69
+ host?: string;
70
+ /** Bind port. Default 8141. NEVER 4001. */
71
+ port?: number;
72
+ /** Extra CLI args appended verbatim. */
73
+ extraArgs?: string[];
74
+ /** Extra env vars merged over process.env. */
75
+ env?: NodeJS.ProcessEnv;
76
+ /**
77
+ * Reap this sidecar if the parent exits, crashes, or is interrupted without an
78
+ * explicit `shutdown()`. Default `true` — the frozen binary's detached child
79
+ * must never outlive us holding the port. Set `false` to own the lifecycle.
80
+ */
81
+ autoCleanup?: boolean;
82
+ }
83
+ /** A running sidecar handle. */
84
+ export interface Sidecar {
85
+ child: ChildProcess;
86
+ host: string;
87
+ port: number;
88
+ baseUrl: string;
89
+ }
90
+ /**
91
+ * Spawn the frozen sidecar. Does NOT wait for readiness — call `waitForHealth`
92
+ * (or `startSidecar`, which does both).
93
+ */
94
+ export declare function spawnSidecar(opts: SpawnOptions): Sidecar;
95
+ /** `GET /health` — liveness only; it does not mean a model is loaded. */
96
+ export declare function health(baseUrl: string, timeoutMs?: number, signal?: AbortSignal): Promise<HealthResponse>;
97
+ /** `GET /version` — the contract probe (`{ apiVersion, agentVersion }`). */
98
+ export declare function version(baseUrl: string, timeoutMs?: number): Promise<VersionResponse>;
99
+ export interface WaitForHealthOptions {
100
+ /** Total time to wait before failing loudly. Default 60000ms. */
101
+ timeoutMs?: number;
102
+ /** Poll interval. Default 250ms. */
103
+ intervalMs?: number;
104
+ /** Abort the wait early (e.g. the process being probed died). */
105
+ signal?: AbortSignal;
106
+ }
107
+ /**
108
+ * Poll `GET /health` until the sidecar reports ok, or throw `HealthTimeoutError`.
109
+ * Never silently assumes ready.
110
+ */
111
+ export declare function waitForHealth(baseUrl: string, opts?: WaitForHealthOptions): Promise<void>;
112
+ export interface VersionCheckOptions {
113
+ /** apiVersion this package was built against. Default API_VERSION ("2.12"). */
114
+ expectedApiVersion?: string;
115
+ }
116
+ /**
117
+ * Fetch `/version` and refuse a sidecar whose apiVersion MAJOR differs from what
118
+ * this package expects. A major bump is a breaking contract change; a higher
119
+ * minor (same major) is a backward-compatible addition and is accepted.
120
+ */
121
+ export declare function checkVersion(baseUrl: string, opts?: VersionCheckOptions): Promise<VersionResponse>;
122
+ /**
123
+ * Shut the sidecar down, killing the whole process tree. Resolves once the
124
+ * process has exited (or immediately if it already had).
125
+ */
126
+ export declare function shutdown(sidecar: Sidecar, timeoutMs?: number): Promise<void>;
127
+ export interface StartOptions extends SpawnOptions {
128
+ /** Health-wait timeout. Default 60000ms (a cold frozen binary unpacks first). */
129
+ healthTimeoutMs?: number;
130
+ /** Verify the contract apiVersion after health. Default true. */
131
+ verifyVersion?: boolean;
132
+ /** apiVersion this package expects. Default API_VERSION. */
133
+ expectedApiVersion?: string;
134
+ }
135
+ /**
136
+ * Spawn → wait for health → assert the child is still ours → (optionally)
137
+ * version-check. On any failure the sidecar is shut down before rethrowing, so a
138
+ * failed start never leaks a process.
139
+ *
140
+ * The port is checked BEFORE the spawn. Without that, the frozen sidecar spends
141
+ * seconds unpacking before it even attempts its bind, while an incumbent answers
142
+ * `/health` in milliseconds — so the health wait succeeds, the still-unpacking
143
+ * child looks alive, and we would hand back a handle for a server we do not own.
144
+ * `assertOurs` / `assertNotAForeignServer` stay as backstops for the narrower
145
+ * race where something binds after this check.
146
+ */
147
+ export declare function startSidecar(opts: StartOptions): Promise<Sidecar>;
148
+ export interface RunTuiOptions {
149
+ /** Absolute path to the gaia-tui binary. */
150
+ binaryPath: string;
151
+ /** Args forwarded verbatim to the TUI. */
152
+ args?: string[];
153
+ /** Extra env merged over process.env. */
154
+ env?: NodeJS.ProcessEnv;
155
+ }
156
+ /**
157
+ * Run the TUI in the foreground with stdio inherited and resolve with its exit
158
+ * code. A signal-terminated TUI resolves as 128 + signum, the shell convention,
159
+ * so a Ctrl+C is distinguishable from a clean exit 0.
160
+ */
161
+ export declare function runTui(opts: RunTuiOptions): Promise<number>;
162
+ //# sourceMappingURL=lifecycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAoB,MAAM,oBAAoB,CAAC;AAiBzE,OAAO,EACL,KAAK,UAAU,EAMhB,MAAM,eAAe,CAAC;AAIvB,eAAO,MAAM,YAAY,cAAc,CAAC;AAExC,4EAA4E;AAC5E,eAAO,MAAM,YAAY,OAAO,CAAC;AAEjC,8DAA8D;AAC9D,eAAO,MAAM,aAAa,OAAO,CAAC;AAElC,+EAA+E;AAC/E,eAAO,MAAM,WAAW,SAAS,CAAC;AAElC,mEAAmE;AACnE,eAAO,MAAM,QAAQ,SAAS,CAAC;AAE/B,8BAA8B;AAC9B,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,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