@agentshouse/kit 0.2.1-c3e4a20bb3183 → 0.2.1-cb0bd1cadcfed
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 +20 -20
- package/dist/agents.js +49 -21
- package/dist/api.js +32 -3
- package/dist/bootstrap.json +10 -17
- package/dist/bridge.js +29 -19
- package/dist/clis.js +21 -4
- package/dist/conversations.js +12 -8
- package/dist/copies.js +34 -41
- package/dist/end.js +8 -0
- package/dist/files.js +2 -1
- package/dist/home.js +15 -2
- package/dist/house-main.js +11 -12
- package/dist/instructions.js +2 -2
- package/dist/kit-main.js +4 -1
- package/dist/login.js +2 -2
- package/dist/logout.js +18 -0
- package/dist/mcp.js +2 -1
- package/dist/refusals.js +12 -0
- package/dist/relay.js +10 -0
- package/dist/resident.js +25 -6
- package/dist/secret-input.js +4 -1
- package/dist/sign-in.js +2 -1
- package/dist/skills.js +1 -1
- package/dist/stream.js +31 -5
- package/dist/transcription.js +54 -6
- package/dist/update.js +2 -0
- package/package.json +1 -1
package/dist/transcription.js
CHANGED
|
@@ -29,6 +29,10 @@ export const ENGINES = {
|
|
|
29
29
|
};
|
|
30
30
|
const CHUNK_SECONDS = 20;
|
|
31
31
|
let held = Promise.resolve();
|
|
32
|
+
let holding = Promise.resolve();
|
|
33
|
+
let setting = null;
|
|
34
|
+
let downloading = null;
|
|
35
|
+
let readiness = { installed: false, failure: null };
|
|
32
36
|
function directory() {
|
|
33
37
|
return join(kitHome(), 'transcription');
|
|
34
38
|
}
|
|
@@ -36,6 +40,7 @@ function installed(artifact) {
|
|
|
36
40
|
return join(directory(), artifact.sha256);
|
|
37
41
|
}
|
|
38
42
|
async function executed(command, args, signal) {
|
|
43
|
+
// A download or a transcription runs as long as its size needs; the setting turning off or the turn's interrupt or end aborts it instead.
|
|
39
44
|
const ran = await run(command, args, 0, false, signal);
|
|
40
45
|
if (ran.status !== 0)
|
|
41
46
|
throw new Error(failureOf(ran, basename(command)));
|
|
@@ -54,6 +59,12 @@ async function sha256(path) {
|
|
|
54
59
|
await pipeline(createReadStream(path), hash);
|
|
55
60
|
return hash.digest('hex');
|
|
56
61
|
}
|
|
62
|
+
function causeOf(error) {
|
|
63
|
+
return error instanceof Error ? error.message : String(error);
|
|
64
|
+
}
|
|
65
|
+
function pinnedHere() {
|
|
66
|
+
return ENGINES[`${process.platform}-${process.arch}`];
|
|
67
|
+
}
|
|
57
68
|
async function install(artifacts, signal) {
|
|
58
69
|
await mkdir(directory(), { recursive: true });
|
|
59
70
|
const pinned = new Set(artifacts.map((artifact) => artifact.sha256));
|
|
@@ -68,6 +79,7 @@ async function install(artifacts, signal) {
|
|
|
68
79
|
try {
|
|
69
80
|
for (const artifact of missing) {
|
|
70
81
|
const part = `${installed(artifact)}.part`;
|
|
82
|
+
// Three retries carry a large download past a dropped connection before the download fails.
|
|
71
83
|
await executed('curl', ['-fsSL', '--retry', '3', '-o', part, artifact.url], signal);
|
|
72
84
|
if ((await sha256(part)) !== artifact.sha256)
|
|
73
85
|
throw new Error(`${artifact.url} does not match its sha256`);
|
|
@@ -83,12 +95,46 @@ async function install(artifacts, signal) {
|
|
|
83
95
|
await rm(`${installed(artifact)}.part`, { force: true });
|
|
84
96
|
}
|
|
85
97
|
}
|
|
98
|
+
function reported(next) {
|
|
99
|
+
const changed = next.installed !== readiness.installed || next.failure !== readiness.failure;
|
|
100
|
+
readiness = next;
|
|
101
|
+
return changed;
|
|
102
|
+
}
|
|
103
|
+
async function settle(transcribe) {
|
|
104
|
+
if (transcribe === setting)
|
|
105
|
+
return false;
|
|
106
|
+
setting = transcribe;
|
|
107
|
+
if (!transcribe) {
|
|
108
|
+
await rm(directory(), { recursive: true, force: true });
|
|
109
|
+
return reported({ installed: false, failure: null });
|
|
110
|
+
}
|
|
111
|
+
const download = new AbortController();
|
|
112
|
+
downloading = download;
|
|
113
|
+
try {
|
|
114
|
+
const pinned = pinnedHere();
|
|
115
|
+
await install([pinned.decoder, pinned.engine, MODEL], download.signal);
|
|
116
|
+
return reported({ installed: true, failure: null });
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
await rm(directory(), { recursive: true, force: true });
|
|
120
|
+
return reported({ installed: false, failure: download.signal.aborted ? null : causeOf(error) });
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
downloading = null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
export function holdTranscription(transcribe) {
|
|
127
|
+
if (!transcribe)
|
|
128
|
+
downloading?.abort();
|
|
129
|
+
const settled = holding.then(() => settle(transcribe));
|
|
130
|
+
holding = settled.catch(() => undefined);
|
|
131
|
+
return settled;
|
|
132
|
+
}
|
|
133
|
+
export function transcriptionReport() {
|
|
134
|
+
return readiness;
|
|
135
|
+
}
|
|
86
136
|
async function transcribed(path, signal) {
|
|
87
|
-
const
|
|
88
|
-
const pinned = ENGINES[platform];
|
|
89
|
-
if (pinned === undefined)
|
|
90
|
-
throw new Error(`no transcription engine is pinned for ${platform}`);
|
|
91
|
-
await install([pinned.decoder, pinned.engine, MODEL], signal);
|
|
137
|
+
const pinned = pinnedHere();
|
|
92
138
|
const work = await mkdtemp(join(tmpdir(), 'kit-transcription-'));
|
|
93
139
|
try {
|
|
94
140
|
await executed(installed(pinned.decoder), ['-nostdin', '-hide_banner', '-loglevel', 'error', '-i', path, '-ar', '16000', '-ac', '1', '-c:a', 'pcm_s16le',
|
|
@@ -106,6 +152,8 @@ async function transcribed(path, signal) {
|
|
|
106
152
|
}
|
|
107
153
|
}
|
|
108
154
|
export async function transcribe(path, signal) {
|
|
155
|
+
if (!readiness.installed)
|
|
156
|
+
return null;
|
|
109
157
|
const before = held;
|
|
110
158
|
let release;
|
|
111
159
|
const mine = new Promise((resolve) => {
|
|
@@ -114,7 +162,7 @@ export async function transcribe(path, signal) {
|
|
|
114
162
|
held = Promise.all([before, mine]);
|
|
115
163
|
try {
|
|
116
164
|
await unlessAborted(before, signal);
|
|
117
|
-
return await transcribed(path, signal);
|
|
165
|
+
return readiness.installed ? await transcribed(path, signal) : null;
|
|
118
166
|
}
|
|
119
167
|
finally {
|
|
120
168
|
release();
|
package/dist/update.js
CHANGED
|
@@ -40,9 +40,11 @@ async function finished(inputId) {
|
|
|
40
40
|
const ack = await recorded();
|
|
41
41
|
if (ack !== null)
|
|
42
42
|
return ack;
|
|
43
|
+
// systemctl answers at once, so ten seconds only bounds a stuck service manager.
|
|
43
44
|
if ((await run('systemctl', ['is-active', '--quiet', unit(inputId)], 10_000)).status !== 0) {
|
|
44
45
|
return (await recorded()) ?? { refused: 'the Kit bootstrap did not finish' };
|
|
45
46
|
}
|
|
47
|
+
// The bootstrap runs for minutes, so checking each second sees its outcome within a second at little cost.
|
|
46
48
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
47
49
|
}
|
|
48
50
|
}
|