@agentshouse/kit 0.2.1-alpha.8 → 0.2.1-c02dacffca87c
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/README.md +49 -24
- package/dist/abort.js +9 -0
- package/dist/acp.js +102 -88
- package/dist/agents.js +356 -52
- package/dist/api.js +40 -4
- package/dist/app-git.js +48 -0
- package/dist/authority-main.js +2 -2
- package/dist/bridge.js +93 -78
- package/dist/building.js +50 -0
- package/dist/calls.js +71 -0
- package/dist/chatgpt.js +32 -0
- package/dist/chunks.js +49 -0
- package/dist/clis.js +224 -88
- package/dist/codex-main.js +58 -0
- package/dist/configure-main.js +6 -0
- package/dist/connection.js +105 -0
- package/dist/conversations.js +749 -268
- package/dist/copies.js +475 -260
- package/dist/end.js +33 -0
- package/dist/enrol-main.js +7 -1
- package/dist/events.js +546 -0
- package/dist/files.js +140 -17
- package/dist/git-main.js +2 -2
- package/dist/git.js +62 -22
- package/dist/home.js +134 -10
- package/dist/house-cli.js +299 -0
- package/dist/house-main.js +5 -102
- package/dist/instructions.js +17 -18
- package/dist/kit-cli.js +68 -0
- package/dist/kit-main.js +8 -16
- package/dist/login.js +130 -95
- package/dist/logout.js +19 -0
- package/dist/mcp.js +43 -0
- package/dist/operation.js +7 -4
- package/dist/parts.js +82 -0
- package/dist/placement.js +31 -0
- package/dist/refusals.js +53 -0
- package/dist/relay.js +41 -0
- package/dist/resident.js +145 -51
- package/dist/scope.js +214 -0
- package/dist/scripts.js +255 -0
- package/dist/secret-input.js +7 -2
- package/dist/service-main.js +9 -0
- package/dist/service.js +55 -0
- package/dist/shell.js +3 -0
- package/dist/sign-in.js +52 -32
- package/dist/silence.js +28 -0
- package/dist/skills.js +92 -0
- package/dist/transcription.js +210 -0
- package/dist/translate.js +2 -8
- package/dist/update.js +127 -0
- package/dist/wire.js +40 -0
- package/dist/work.js +346 -0
- package/package.json +20 -21
- package/dist/blocks.js +0 -51
- package/dist/bootstrap.json +0 -28
- package/dist/stream.js +0 -47
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { chmod, mkdir, mkdtemp, readdir, readFile, rename, rm, stat } from 'node:fs/promises';
|
|
2
|
+
import { availableParallelism, tmpdir } from 'node:os';
|
|
3
|
+
import { basename, join } from 'node:path';
|
|
4
|
+
import { unlessAborted } from './abort.js';
|
|
5
|
+
import { downloadServed } from './building.js';
|
|
6
|
+
import { failureOf, run } from './clis.js';
|
|
7
|
+
import { downloaded, fetched } from './files.js';
|
|
8
|
+
import { kitHome } from './home.js';
|
|
9
|
+
const RELEASE = 'https://github.com/agentshouse/kit/releases/download/engine-2';
|
|
10
|
+
export const MODEL = {
|
|
11
|
+
name: 'ggml-parakeet-tdt-0.6b-v3-q4_k.bin',
|
|
12
|
+
from: 'https://huggingface.co/ggml-org/parakeet-GGUF/resolve/35156454d1a39de06863303dd209fd2bed6ee079/ggml-parakeet-tdt-0.6b-v3-q4_k.bin',
|
|
13
|
+
sha256: '8b205b8b39c6535e153de6fb11c51db46125d45c4f16ba496fe41a0fe71b885e',
|
|
14
|
+
bytes: 415_611_879,
|
|
15
|
+
executable: false,
|
|
16
|
+
};
|
|
17
|
+
export const ENGINES = {
|
|
18
|
+
'linux-x64': {
|
|
19
|
+
decoder: { name: 'ffmpeg-linux-x86_64', from: `${RELEASE}/ffmpeg-linux-x86_64`, sha256: '1f8235d206428305afb89c6e8ab99d100425a0ba61e22bb4c7aff017db8c8de5', bytes: 5_175_832, executable: true },
|
|
20
|
+
engine: { name: 'parakeet-cli-linux-x86_64', from: `${RELEASE}/parakeet-cli-linux-x86_64`, sha256: 'bb2585695992fe1927a33960002cdf51b8a90a96ad65593c3d0a9f1fbc0865c2', bytes: 3_801_616, executable: true },
|
|
21
|
+
},
|
|
22
|
+
'linux-arm64': {
|
|
23
|
+
decoder: { name: 'ffmpeg-linux-aarch64', from: `${RELEASE}/ffmpeg-linux-aarch64`, sha256: 'a7e08a0fae0179d1078312f6bb13d2a9aa4d4c71a1d82a022953f25dee452f5e', bytes: 4_590_208, executable: true },
|
|
24
|
+
engine: { name: 'parakeet-cli-linux-aarch64', from: `${RELEASE}/parakeet-cli-linux-aarch64`, sha256: 'cbc0bedc8daae97f1ef9dcee4200c06226218e300e0fd62ead1306d22742b7ed', bytes: 3_477_624, executable: true },
|
|
25
|
+
},
|
|
26
|
+
'darwin-arm64': {
|
|
27
|
+
decoder: { name: 'ffmpeg-darwin-arm64', from: `${RELEASE}/ffmpeg-darwin-arm64`, sha256: '7abe154aaed3d6b49f5167ca7221bb66bed51388925d99a7e4261a41fe52fba6', bytes: 3_696_768, executable: true },
|
|
28
|
+
engine: { name: 'parakeet-cli-darwin-arm64', from: `${RELEASE}/parakeet-cli-darwin-arm64`, sha256: '9a2aafc0922ad7c0b6db6eff1641e96572ba32ac40bf995a1df242ed2febf297', bytes: 1_939_728, executable: true },
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
const CHUNK_SECONDS = 20;
|
|
32
|
+
const OFF = "transcription is off on the Agent's Environment, so this message's audio has no text; turn it on or write instead";
|
|
33
|
+
const NOT_INSTALLED = "the speech engine is not installed on the Agent's Environment, so this message's audio has no text";
|
|
34
|
+
const NOT_DOWNLOADED = 'an audio file this message links could not be downloaded; send the message again';
|
|
35
|
+
const UNDECODABLE = 'an audio file this message links could not be decoded';
|
|
36
|
+
const UNTRANSCRIBED = 'an audio file this message links could not be transcribed';
|
|
37
|
+
let held = Promise.resolve();
|
|
38
|
+
let holding = Promise.resolve();
|
|
39
|
+
let setting = null;
|
|
40
|
+
let downloading = null;
|
|
41
|
+
let readiness = { installed: false, failure: null };
|
|
42
|
+
function directory() {
|
|
43
|
+
return join(kitHome(), 'transcription');
|
|
44
|
+
}
|
|
45
|
+
function installed(artifact) {
|
|
46
|
+
return join(directory(), artifact.sha256);
|
|
47
|
+
}
|
|
48
|
+
async function executed(command, args, signal) {
|
|
49
|
+
// A decode or a transcription runs as long as its audio needs; the setting turning off or the turn's interrupt or end aborts it instead.
|
|
50
|
+
const ran = await run(command, args, 0, false, signal);
|
|
51
|
+
if (ran.status !== 0)
|
|
52
|
+
throw new Error(failureOf(ran, basename(command)));
|
|
53
|
+
return ran.stdout;
|
|
54
|
+
}
|
|
55
|
+
function present(path) {
|
|
56
|
+
return stat(path).then(() => true, () => false);
|
|
57
|
+
}
|
|
58
|
+
async function threads() {
|
|
59
|
+
const [quota, period] = (await readFile('/sys/fs/cgroup/cpu.max', 'utf8').catch(() => 'max')).split(' ');
|
|
60
|
+
const allowed = quota === 'max' ? Infinity : Math.ceil(Number(quota) / Number(period));
|
|
61
|
+
return Math.max(1, Math.floor(Math.min(availableParallelism(), allowed) / 2));
|
|
62
|
+
}
|
|
63
|
+
function causeOf(error) {
|
|
64
|
+
return error instanceof Error ? error.message : String(error);
|
|
65
|
+
}
|
|
66
|
+
async function failing(reason, work) {
|
|
67
|
+
try {
|
|
68
|
+
return await work;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
throw new Error(reason, { cause: error });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function ready() {
|
|
75
|
+
if (setting !== true)
|
|
76
|
+
throw new Error(OFF);
|
|
77
|
+
if (!readiness.installed)
|
|
78
|
+
throw new Error(NOT_INSTALLED);
|
|
79
|
+
}
|
|
80
|
+
function pinnedHere() {
|
|
81
|
+
return ENGINES[`${process.platform}-${process.arch}`];
|
|
82
|
+
}
|
|
83
|
+
const DOWNLOADS = 3;
|
|
84
|
+
async function downloadedAgain(artifact, signal) {
|
|
85
|
+
// An artifact arrives at a hundred kilobytes a second or its download ends, so a stalled Building cannot hold the install open.
|
|
86
|
+
const deadlineMs = Math.ceil(artifact.bytes / 100);
|
|
87
|
+
const deadline = AbortSignal.timeout(deadlineMs);
|
|
88
|
+
for (let attempt = 1;; attempt++) {
|
|
89
|
+
try {
|
|
90
|
+
return await downloadServed(artifact.name, artifact.sha256, `${installed(artifact)}.part`, AbortSignal.any([signal, deadline]), artifact.bytes);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
if (signal.aborted)
|
|
94
|
+
throw error;
|
|
95
|
+
if (deadline.aborted)
|
|
96
|
+
throw new Error(`${artifact.name} did not arrive within ${Math.ceil(deadlineMs / 1000)} seconds`);
|
|
97
|
+
if (attempt === DOWNLOADS)
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async function install(artifacts, signal) {
|
|
103
|
+
await mkdir(directory(), { recursive: true });
|
|
104
|
+
const pinned = new Set(artifacts.map((artifact) => artifact.sha256));
|
|
105
|
+
for (const name of await readdir(directory())) {
|
|
106
|
+
if (!pinned.has(name))
|
|
107
|
+
await rm(join(directory(), name), { recursive: true, force: true });
|
|
108
|
+
}
|
|
109
|
+
const missing = [];
|
|
110
|
+
for (const artifact of artifacts)
|
|
111
|
+
if (!(await present(installed(artifact))))
|
|
112
|
+
missing.push(artifact);
|
|
113
|
+
try {
|
|
114
|
+
for (const artifact of missing)
|
|
115
|
+
await downloadedAgain(artifact, signal);
|
|
116
|
+
for (const artifact of missing) {
|
|
117
|
+
if (artifact.executable)
|
|
118
|
+
await chmod(`${installed(artifact)}.part`, 0o755);
|
|
119
|
+
await rename(`${installed(artifact)}.part`, installed(artifact));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
for (const artifact of missing)
|
|
124
|
+
await rm(`${installed(artifact)}.part`, { force: true });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function reported(next) {
|
|
128
|
+
const changed = next.installed !== readiness.installed || next.failure !== readiness.failure;
|
|
129
|
+
readiness = next;
|
|
130
|
+
return changed;
|
|
131
|
+
}
|
|
132
|
+
async function settle(transcribe) {
|
|
133
|
+
if (transcribe === setting)
|
|
134
|
+
return false;
|
|
135
|
+
setting = transcribe;
|
|
136
|
+
if (!transcribe) {
|
|
137
|
+
await rm(directory(), { recursive: true, force: true });
|
|
138
|
+
return reported({ installed: false, failure: null });
|
|
139
|
+
}
|
|
140
|
+
const download = new AbortController();
|
|
141
|
+
downloading = download;
|
|
142
|
+
try {
|
|
143
|
+
const pinned = pinnedHere();
|
|
144
|
+
await install([pinned.decoder, pinned.engine, MODEL], download.signal);
|
|
145
|
+
return reported({ installed: true, failure: null });
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
await rm(directory(), { recursive: true, force: true });
|
|
149
|
+
return reported({ installed: false, failure: download.signal.aborted ? null : causeOf(error) });
|
|
150
|
+
}
|
|
151
|
+
finally {
|
|
152
|
+
downloading = null;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
export function holdTranscription(transcribe) {
|
|
156
|
+
if (!transcribe)
|
|
157
|
+
downloading?.abort();
|
|
158
|
+
const settled = holding.then(() => settle(transcribe));
|
|
159
|
+
holding = settled.catch(() => undefined);
|
|
160
|
+
return settled;
|
|
161
|
+
}
|
|
162
|
+
export function transcriptionReport() {
|
|
163
|
+
return readiness;
|
|
164
|
+
}
|
|
165
|
+
async function transcribed(audio, parts, signal) {
|
|
166
|
+
const pinned = pinnedHere();
|
|
167
|
+
await mkdir(parts);
|
|
168
|
+
await failing(UNDECODABLE, executed(installed(pinned.decoder), ['-nostdin', '-hide_banner', '-loglevel', 'error', '-i', audio, '-ar', '16000', '-ac', '1', '-c:a', 'pcm_s16le',
|
|
169
|
+
'-f', 'segment', '-segment_time', String(CHUNK_SECONDS), join(parts, '%05d.wav')], signal));
|
|
170
|
+
const segments = (await readdir(parts)).sort().flatMap((part) => ['-f', join(parts, part)]);
|
|
171
|
+
const said = await failing(UNTRANSCRIBED, executed(installed(pinned.engine), ['-t', String(await threads()), '-np', '-m', installed(MODEL), ...segments], signal));
|
|
172
|
+
const text = said
|
|
173
|
+
.split('\n')
|
|
174
|
+
.map((line) => line.trim())
|
|
175
|
+
.filter((line) => line !== '')
|
|
176
|
+
.join(' ');
|
|
177
|
+
if (text === '')
|
|
178
|
+
throw new Error(UNTRANSCRIBED);
|
|
179
|
+
return text;
|
|
180
|
+
}
|
|
181
|
+
async function alone(work, signal) {
|
|
182
|
+
const before = held;
|
|
183
|
+
let release;
|
|
184
|
+
const mine = new Promise((resolve) => {
|
|
185
|
+
release = resolve;
|
|
186
|
+
});
|
|
187
|
+
held = Promise.all([before, mine]);
|
|
188
|
+
try {
|
|
189
|
+
await unlessAborted(before, signal);
|
|
190
|
+
return await work();
|
|
191
|
+
}
|
|
192
|
+
finally {
|
|
193
|
+
release();
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
export async function transcribe(address, signal) {
|
|
197
|
+
ready();
|
|
198
|
+
const work = await mkdtemp(join(tmpdir(), 'kit-transcription-'));
|
|
199
|
+
try {
|
|
200
|
+
const audio = join(work, 'audio');
|
|
201
|
+
await failing(NOT_DOWNLOADED, downloaded(address, (url) => fetched(url, signal), audio, 'audio'));
|
|
202
|
+
return await alone(() => {
|
|
203
|
+
ready();
|
|
204
|
+
return transcribed(audio, join(work, 'parts'), signal);
|
|
205
|
+
}, signal);
|
|
206
|
+
}
|
|
207
|
+
finally {
|
|
208
|
+
await rm(work, { recursive: true, force: true });
|
|
209
|
+
}
|
|
210
|
+
}
|
package/dist/translate.js
CHANGED
|
@@ -3,14 +3,8 @@ function same(left, right) {
|
|
|
3
3
|
return JSON.stringify(left) === JSON.stringify(right);
|
|
4
4
|
}
|
|
5
5
|
function applied(document, changes) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const result = apply(current, change);
|
|
9
|
-
if (result.outcome !== 'applied')
|
|
10
|
-
return null;
|
|
11
|
-
current = result.document;
|
|
12
|
-
}
|
|
13
|
-
return serialize(current);
|
|
6
|
+
const result = apply(document, changes);
|
|
7
|
+
return result.outcome === 'applied' ? serialize(result.document) : null;
|
|
14
8
|
}
|
|
15
9
|
function components(path, before, after, text) {
|
|
16
10
|
const edits = [];
|
package/dist/update.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { mkdir } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { downloadServed, servedRelease } from './building.js';
|
|
5
|
+
import { KIT_RELEASE } from './clis.js';
|
|
6
|
+
import { restart, updateLine } from './end.js';
|
|
7
|
+
import { kitHome, readEnrolment } from './home.js';
|
|
8
|
+
import { placedPrefix } from './placement.js';
|
|
9
|
+
import { childEnvironment, relayOrigin } from './relay.js';
|
|
10
|
+
const INSTALLER_BYTES = 1_000_000;
|
|
11
|
+
// A release's Node.js, Kit package and adapters are about a hundred megabytes, so an hour carries them at thirty kilobytes a second, and a placement still running then has hung.
|
|
12
|
+
const PLACEMENT_MS = 60 * 60_000;
|
|
13
|
+
// A refused Kit is offline until its placement succeeds, so it tries again within five minutes of its Building or this computer recovering, while a placement that fails only after its hundred-megabyte download runs at most twelve times an hour.
|
|
14
|
+
export const PLACEMENT_RETRY_MS = 5 * 60_000;
|
|
15
|
+
const REFUSED = 'kit_bootstrap_refused: ';
|
|
16
|
+
const OUTPUT_CHARACTERS = 4000;
|
|
17
|
+
function causeOf(error) {
|
|
18
|
+
if (error instanceof TypeError && error.cause instanceof Error)
|
|
19
|
+
return `the Building did not answer: ${error.cause.message}`;
|
|
20
|
+
return error instanceof Error ? error.message : String(error);
|
|
21
|
+
}
|
|
22
|
+
function placing(installer, house, prefix, signal) {
|
|
23
|
+
return new Promise((resolve) => {
|
|
24
|
+
const relay = relayOrigin();
|
|
25
|
+
const child = spawn('bash', [installer, '--house', house, '--place', prefix], {
|
|
26
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
27
|
+
env: { ...childEnvironment(), ...(relay === undefined ? {} : { HOUSE_KIT_RELAY: relay }) },
|
|
28
|
+
detached: true,
|
|
29
|
+
});
|
|
30
|
+
const stop = () => {
|
|
31
|
+
try {
|
|
32
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
33
|
+
}
|
|
34
|
+
catch { }
|
|
35
|
+
};
|
|
36
|
+
signal.addEventListener('abort', stop, { once: true });
|
|
37
|
+
if (signal.aborted)
|
|
38
|
+
stop();
|
|
39
|
+
let output = '';
|
|
40
|
+
for (const stream of [child.stdout, child.stderr]) {
|
|
41
|
+
stream.setEncoding('utf8').on('data', (chunk) => {
|
|
42
|
+
output = (output + chunk).slice(-OUTPUT_CHARACTERS);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const ended = (failure) => {
|
|
46
|
+
signal.removeEventListener('abort', stop);
|
|
47
|
+
resolve(failure);
|
|
48
|
+
};
|
|
49
|
+
child.on('error', (error) => ended(error.message));
|
|
50
|
+
child.on('close', (status) => {
|
|
51
|
+
if (status === 0)
|
|
52
|
+
return ended(null);
|
|
53
|
+
if (signal.aborted)
|
|
54
|
+
return ended(`the placement did not end within ${PLACEMENT_MS / 1000} seconds`);
|
|
55
|
+
const lines = output.split('\n').filter((line) => line.trim() !== '');
|
|
56
|
+
const refused = lines.findLast((line) => line.startsWith(REFUSED));
|
|
57
|
+
ended(refused?.slice(REFUSED.length) ?? lines.at(-1) ?? `the placement ended with status ${status ?? 'a signal'}`);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
export class KitUpdate {
|
|
62
|
+
calls;
|
|
63
|
+
queue = Promise.resolve();
|
|
64
|
+
placed = null;
|
|
65
|
+
constructor(calls) {
|
|
66
|
+
this.calls = calls;
|
|
67
|
+
}
|
|
68
|
+
take(call) {
|
|
69
|
+
void this.calls.carry(call.input_id, async () => ({ result: await this.queued(() => this.update(call.release)) }));
|
|
70
|
+
}
|
|
71
|
+
async takeRefused(release) {
|
|
72
|
+
for (;;) {
|
|
73
|
+
const failure = await this.queued(async () => (this.placed === null ? this.place(release, 'served') : null));
|
|
74
|
+
if (failure === null)
|
|
75
|
+
restart(`Kit ${this.placed} is placed; its supervisor starts it`);
|
|
76
|
+
process.stderr.write(`kit: ${updateLine(`Kit ${KIT_RELEASE} stays offline and tries again in ${PLACEMENT_RETRY_MS / 60_000} minutes`)}\n`);
|
|
77
|
+
await new Promise((resolve) => setTimeout(resolve, PLACEMENT_RETRY_MS));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
placedRelease() {
|
|
81
|
+
return this.placed;
|
|
82
|
+
}
|
|
83
|
+
queued(work) {
|
|
84
|
+
const taken = this.queue.then(work);
|
|
85
|
+
this.queue = taken.catch(() => undefined);
|
|
86
|
+
return taken;
|
|
87
|
+
}
|
|
88
|
+
async update(release) {
|
|
89
|
+
if (release === (this.placed ?? KIT_RELEASE))
|
|
90
|
+
return {};
|
|
91
|
+
if (this.placed !== null)
|
|
92
|
+
return { refused: `Kit ${this.placed} is placed and starts first, once no turn is open` };
|
|
93
|
+
const failure = await this.place(release, 'named');
|
|
94
|
+
if (failure !== null)
|
|
95
|
+
return { refused: failure };
|
|
96
|
+
process.stderr.write(`kit: Kit ${release} is placed; it starts once no turn is open\n`);
|
|
97
|
+
return {};
|
|
98
|
+
}
|
|
99
|
+
async place(release, which) {
|
|
100
|
+
const signal = AbortSignal.timeout(PLACEMENT_MS);
|
|
101
|
+
let version = release;
|
|
102
|
+
let failure;
|
|
103
|
+
try {
|
|
104
|
+
const prefix = placedPrefix();
|
|
105
|
+
const served = await servedRelease(signal);
|
|
106
|
+
if (which === 'named' && served.version !== release)
|
|
107
|
+
throw new Error(`the Building serves Kit ${served.version}, not Kit ${release}`);
|
|
108
|
+
version = served.version;
|
|
109
|
+
if (version === KIT_RELEASE)
|
|
110
|
+
throw new Error(`the Building serves Kit ${KIT_RELEASE}, which this Kit runs`);
|
|
111
|
+
await mkdir(join(kitHome(), 'update'), { recursive: true, mode: 0o700 });
|
|
112
|
+
const installer = join(kitHome(), 'update', served.installer);
|
|
113
|
+
await downloadServed(served.installer, served.sha256, installer, signal, INSTALLER_BYTES);
|
|
114
|
+
failure = await placing(installer, (await readEnrolment()).house, prefix, signal);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
failure = signal.aborted ? `the placement did not end within ${PLACEMENT_MS / 1000} seconds` : causeOf(error);
|
|
118
|
+
}
|
|
119
|
+
if (failure !== null) {
|
|
120
|
+
const refused = `Kit ${version} could not be placed: ${failure}`;
|
|
121
|
+
process.stderr.write(`kit: ${refused}\n`);
|
|
122
|
+
return refused;
|
|
123
|
+
}
|
|
124
|
+
this.placed = version;
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
}
|
package/dist/wire.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { newerThanHouse, updateRequired } from './end.js';
|
|
2
|
+
import { machine } from './placement.js';
|
|
3
|
+
import { refusalOf } from './refusals.js';
|
|
4
|
+
export const KIT_WIRE = 4;
|
|
5
|
+
export const KIT_WIRE_HEADER = 'x-house-kit-wire';
|
|
6
|
+
let take = null;
|
|
7
|
+
let taken = false;
|
|
8
|
+
function unservedBy(text) {
|
|
9
|
+
let body;
|
|
10
|
+
try {
|
|
11
|
+
body = JSON.parse(text);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const error = body?.error;
|
|
17
|
+
if (error?.code !== 'kit_update_required' && error?.code !== 'kit_newer_than_house')
|
|
18
|
+
return null;
|
|
19
|
+
return typeof error.release === 'string' ? error : null;
|
|
20
|
+
}
|
|
21
|
+
export function takeUnservedRelease(taking) {
|
|
22
|
+
take = taking;
|
|
23
|
+
}
|
|
24
|
+
export function unserved() {
|
|
25
|
+
return taken;
|
|
26
|
+
}
|
|
27
|
+
export function endUnserved(text) {
|
|
28
|
+
const refused = unservedBy(text);
|
|
29
|
+
if (refused !== null && take !== null) {
|
|
30
|
+
if (!taken) {
|
|
31
|
+
taken = true;
|
|
32
|
+
take(refused.release);
|
|
33
|
+
}
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (refusalOf(text)?.code === 'kit_update_required')
|
|
37
|
+
updateRequired();
|
|
38
|
+
if (refused?.code === 'kit_newer_than_house')
|
|
39
|
+
newerThanHouse(refused.release, refused.commands[machine()]);
|
|
40
|
+
}
|