@vellumai/cli 0.8.12-dev.202606152340.7efde97 → 0.8.12-dev.202606160320.367ef7c
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.
|
@@ -35,6 +35,8 @@ export { runHatch } from "./hatch";
|
|
|
35
35
|
export type { HatchResult } from "./hatch";
|
|
36
36
|
export { runRetire } from "./retire";
|
|
37
37
|
export type { RetireResult } from "./retire";
|
|
38
|
+
export { runSleep } from "./sleep";
|
|
39
|
+
export type { SleepResult } from "./sleep";
|
|
38
40
|
export { runWake } from "./wake";
|
|
39
41
|
export type { WakeOptions, WakeResult } from "./wake";
|
|
40
42
|
export { getLocalAssistantStatus } from "./status";
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
import type { CliInvocation } from "./util";
|
|
4
|
+
|
|
5
|
+
// The CLI's `sleep` command uses a 120s SIGKILL ceiling for the assistant
|
|
6
|
+
// daemon (WAL checkpoint can be slow on large databases) plus 7s for the
|
|
7
|
+
// gateway drain window. The wrapper timeout must sit above that total so a
|
|
8
|
+
// slow-but-succeeding sleep isn't killed and misreported as a timeout.
|
|
9
|
+
const SLEEP_TIMEOUT_MS = 150_000;
|
|
10
|
+
|
|
11
|
+
export type SleepResult =
|
|
12
|
+
| { ok: true }
|
|
13
|
+
| { ok: false; status: number; error: string };
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Stop a local assistant's daemon and gateway via the CLI's `sleep --force`.
|
|
17
|
+
*
|
|
18
|
+
* Uses `--force` to bypass the active-call-lease guard — the restart flow
|
|
19
|
+
* immediately follows with a `wake`, so the brief interruption is expected
|
|
20
|
+
* and user-confirmed at the UI level.
|
|
21
|
+
*
|
|
22
|
+
* Mirrors {@link runRetire}'s never-reject contract so each host wires
|
|
23
|
+
* transport once and surfaces a structured failure rather than a thrown error.
|
|
24
|
+
*/
|
|
25
|
+
export function runSleep(
|
|
26
|
+
invocation: CliInvocation,
|
|
27
|
+
assistantId: string,
|
|
28
|
+
): Promise<SleepResult> {
|
|
29
|
+
return new Promise((resolve) => {
|
|
30
|
+
const child = spawn(
|
|
31
|
+
invocation.command,
|
|
32
|
+
[...invocation.baseArgs, "sleep", assistantId, "--force"],
|
|
33
|
+
{ stdio: ["ignore", "pipe", "pipe"] },
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
let stdout = "";
|
|
37
|
+
let stderr = "";
|
|
38
|
+
let done = false;
|
|
39
|
+
|
|
40
|
+
const finish = (result: SleepResult) => {
|
|
41
|
+
if (done) return;
|
|
42
|
+
done = true;
|
|
43
|
+
clearTimeout(timeout);
|
|
44
|
+
resolve(result);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const timeout = setTimeout(() => {
|
|
48
|
+
child.kill("SIGTERM");
|
|
49
|
+
finish({
|
|
50
|
+
ok: false,
|
|
51
|
+
status: 500,
|
|
52
|
+
error: `Sleep timed out after ${SLEEP_TIMEOUT_MS / 1000} seconds`,
|
|
53
|
+
});
|
|
54
|
+
}, SLEEP_TIMEOUT_MS);
|
|
55
|
+
|
|
56
|
+
child.stdout.on("data", (data: Buffer) => {
|
|
57
|
+
stdout += data.toString();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
child.stderr.on("data", (data: Buffer) => {
|
|
61
|
+
stderr += data.toString();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
child.on("close", (code) => {
|
|
65
|
+
if (code === 0) {
|
|
66
|
+
finish({ ok: true });
|
|
67
|
+
} else {
|
|
68
|
+
finish({ ok: false, status: 500, error: stderr || stdout });
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
child.on("error", (err) => {
|
|
73
|
+
finish({
|
|
74
|
+
ok: false,
|
|
75
|
+
status: 500,
|
|
76
|
+
error: `Failed to spawn CLI: ${err.message}`,
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|