@wirecat/cli-core 0.663.0 → 0.665.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/CHANGELOG.md +141 -0
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/calendar/index.d.ts +1 -1
- package/dist/calendar/index.js +1 -1
- package/dist/calendar/prepare.d.ts +2 -2
- package/dist/calendar/reads.d.ts +5 -5
- package/dist/calendar/writes.d.ts +4 -4
- package/dist/cli/chat-sending-command.d.ts +14 -0
- package/dist/cli/chat-sending-command.js +64 -0
- package/dist/cli/context.d.ts +7 -0
- package/dist/cli/context.js +12 -4
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +2 -0
- package/dist/cli/meeting-meaning-command.d.ts +47 -0
- package/dist/cli/meeting-meaning-command.js +136 -0
- package/dist/cli/meeting-preparation-answer.d.ts +6 -0
- package/dist/cli/meeting-preparation-projects.d.ts +6 -0
- package/dist/cli/meeting-preparation-read.d.ts +6 -0
- package/dist/cli/meeting-tags-command.d.ts +18 -0
- package/dist/cli/meeting-tags-command.js +74 -0
- package/dist/cli/messenger/conversation-answers.d.ts +1 -1
- package/dist/cli/messenger/conversation-answers.js +1 -0
- package/dist/cli/messenger/conversations-command.js +38 -12
- package/dist/cli/messenger/models-command.js +7 -0
- package/dist/cli/messenger/records-command.d.ts +4 -1
- package/dist/cli/messenger/records-command.js +6 -1
- package/dist/cli/model-catalogue-command.js +2 -0
- package/dist/cli/profile-token.d.ts +15 -1
- package/dist/cli/profile-token.js +103 -7
- package/dist/cli/program.js +2 -2
- package/dist/domain/links.d.ts +11 -0
- package/dist/domain/links.js +4 -0
- package/dist/entities/chat-sending.d.ts +10 -0
- package/dist/entities/chat-sending.js +11 -0
- package/dist/entities/index.d.ts +43 -1
- package/dist/entities/index.js +6 -2
- package/dist/entities/listings.d.ts +60 -0
- package/dist/entities/listings.js +15 -0
- package/dist/entities/meeting-preparation.d.ts +6 -0
- package/dist/entities/meeting.d.ts +1 -1
- package/dist/entities/meeting.js +1 -1
- package/dist/errors/reasons.js +25 -1
- package/dist/mcp/meeting-preparation.d.ts +6 -0
- package/dist/meetings/answers.d.ts +7 -0
- package/dist/meetings/answers.js +4 -0
- package/dist/meetings/event-store.d.ts +2 -1
- package/dist/meetings/event-store.js +6 -0
- package/dist/meetings/index.d.ts +2 -1
- package/dist/meetings/index.js +2 -1
- package/dist/meetings/mcp/search.d.ts +6 -0
- package/dist/meetings/project-evidence-answer.d.ts +6 -0
- package/dist/meetings/tag-answers.d.ts +43 -0
- package/dist/meetings/tag-answers.js +41 -0
- package/dist/models/chat-sending.d.ts +24 -0
- package/dist/models/chat-sending.js +40 -0
- package/dist/runs/events.d.ts +1 -1
- package/dist/search/question-plan.d.ts +5 -0
- package/dist/search/question-plan.js +5 -0
- package/dist/search/task-similarity.d.ts +1 -0
- package/dist/search/task-similarity.js +1 -1
- package/dist/services/embeddings-search.js +19 -5
- package/dist/services/embeddings.d.ts +4 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.js +2 -0
- package/dist/services/listings.js +17 -2
- package/dist/services/meeting-meaning.d.ts +47 -0
- package/dist/services/meeting-meaning.js +158 -0
- package/dist/services/meeting-tags.d.ts +27 -0
- package/dist/services/meeting-tags.js +81 -0
- package/dist/services/messages-discovery.js +2 -2
- package/dist/sftp/index.d.ts +1 -1
- package/dist/sftp/index.js +1 -1
- package/dist/sftp/session.d.ts +30 -4
- package/dist/sftp/session.js +195 -11
- package/dist/sftp/ssh2.d.ts +19 -4
- package/dist/sftp/ssh2.js +144 -17
- package/dist/speech/cloud.d.ts +47 -0
- package/dist/speech/cloud.js +73 -0
- package/dist/speech/decode.d.ts +36 -9
- package/dist/speech/decode.js +208 -61
- package/dist/speech/index.d.ts +2 -1
- package/dist/speech/index.js +2 -1
- package/dist/speech/openai.d.ts +4 -0
- package/dist/speech/openai.js +13 -12
- package/dist/sql/index.d.ts +1 -0
- package/dist/sql/index.js +1 -0
- package/dist/sql/reader.d.ts +95 -0
- package/dist/sql/reader.js +214 -0
- package/dist/store/sqlite/drizzle/bun.js +4 -4
- package/dist/store/sqlite/drizzle/bun.js.map +1 -1
- package/dist/store/sqlite/drizzle/core.js +5 -5
- package/dist/store/sqlite/drizzle/core.js.map +1 -1
- package/dist/store/sqlite/drizzle/node.js +4 -4
- package/dist/store/sqlite/drizzle/node.js.map +1 -1
- package/dist/store/sqlite/drizzle/{shared-55XJMTPA.js → shared-5XR7K42U.js} +58 -58
- package/dist/store/sqlite/drizzle/{shared-55XJMTPA.js.map → shared-5XR7K42U.js.map} +1 -1
- package/dist/store/sqlite/knowledge.d.ts +1 -1
- package/dist/store/sqlite/knowledge.js +8 -4
- package/dist/store/sqlite/labelled.d.ts +5 -0
- package/dist/store/sqlite/labelled.js +6 -0
- package/dist/store/sqlite/link-row.d.ts +1 -0
- package/dist/store/sqlite/link-row.js +2 -0
- package/dist/store/sqlite/meeting-listing.d.ts +12 -0
- package/dist/store/sqlite/meeting-listing.js +20 -5
- package/dist/store/sqlite/notes.d.ts +1 -1
- package/dist/store/sqlite/notes.js +1 -1
- package/package.json +18 -3
- package/parity.json +20 -1
- package/skills/link-conversations/SKILL.md +1 -1
package/dist/sftp/ssh2.js
CHANGED
|
@@ -39,7 +39,7 @@ const CONNECTION_LOST = 7;
|
|
|
39
39
|
/** SSH disconnect reasons (RFC 4253, section 11.1) a busy or restarting server sends: service not available, connection
|
|
40
40
|
* lost, too many connections. */
|
|
41
41
|
const DISCONNECTS_TO_RETRY = new Set([7, 10, 12]);
|
|
42
|
-
const lost = () => new CliError("network_error",
|
|
42
|
+
const lost = (server = "SFTP server") => new CliError("network_error", `the connection to the ${server} broke`, {
|
|
43
43
|
reason: "network.failed",
|
|
44
44
|
retryable: true,
|
|
45
45
|
});
|
|
@@ -47,16 +47,16 @@ const lost = () => new CliError("network_error", "the connection to the SFTP ser
|
|
|
47
47
|
* The vendor's error as a CliError with fixed wording: an SFTP server's message and the path asked can name a caller's
|
|
48
48
|
* phone number, and a key error can quote the key (WC-SECR-6).
|
|
49
49
|
*/
|
|
50
|
-
const failureOf = (error, from = "sftp") => {
|
|
50
|
+
const failureOf = (error, from = "sftp", server = "SFTP server") => {
|
|
51
51
|
if (isCliError(error))
|
|
52
52
|
return error;
|
|
53
53
|
const { code, level, message } = (error ?? {});
|
|
54
54
|
if (level === "client-authentication")
|
|
55
|
-
return new CliError("authentication_error",
|
|
55
|
+
return new CliError("authentication_error", `the ${server} refused the user name and password or key`, {
|
|
56
56
|
reason: "auth.failed",
|
|
57
57
|
});
|
|
58
58
|
if (from === "ssh" && typeof code === "number")
|
|
59
|
-
return new CliError(DISCONNECTS_TO_RETRY.has(code) ? "provider_unavailable" : "provider_error", `the
|
|
59
|
+
return new CliError(DISCONNECTS_TO_RETRY.has(code) ? "provider_unavailable" : "provider_error", `the ${server} ended the connection (SSH disconnect reason ${code})`, {
|
|
60
60
|
reason: DISCONNECTS_TO_RETRY.has(code) ? "provider.unavailable" : "provider.refused",
|
|
61
61
|
...(DISCONNECTS_TO_RETRY.has(code) ? { retryable: true } : {}),
|
|
62
62
|
});
|
|
@@ -67,7 +67,7 @@ const failureOf = (error, from = "sftp") => {
|
|
|
67
67
|
if (code === NO_CONNECTION || code === CONNECTION_LOST || message === "No response from server")
|
|
68
68
|
return lost();
|
|
69
69
|
if (level === "client-dns" || code === "ENOTFOUND")
|
|
70
|
-
return new CliError("network_error",
|
|
70
|
+
return new CliError("network_error", `the ${server}'s host name was not found`, { reason: "network.failed" });
|
|
71
71
|
if ((typeof code === "string" && TRANSIENT_CODES.has(code)) ||
|
|
72
72
|
level === "client-socket" ||
|
|
73
73
|
level === "client-timeout" ||
|
|
@@ -159,6 +159,44 @@ const readAll = async (sftp, path, maxBytes, progress) => {
|
|
|
159
159
|
sftp.close(handle, () => { });
|
|
160
160
|
}
|
|
161
161
|
};
|
|
162
|
+
const openFile = async (sftp, path, guarded) => {
|
|
163
|
+
const call = (work) => new Promise((resolve, reject) => work((error, value) => (error ? reject(failureOf(error)) : resolve(value))));
|
|
164
|
+
const handle = await call((done) => sftp.open(path, "r", (error, value) => done(error, value)));
|
|
165
|
+
const close = () => sftp.close(handle, () => { });
|
|
166
|
+
try {
|
|
167
|
+
const stats = await call((done) => sftp.fstat(handle, (error, value) => done(error, value)));
|
|
168
|
+
if (kindOf(stats.mode) !== "file")
|
|
169
|
+
throw new CliError("validation_error", "the path names a folder or another thing that is not a file", {
|
|
170
|
+
reason: "file.not-a-file",
|
|
171
|
+
});
|
|
172
|
+
const readAt = (position, length) => call((done) => {
|
|
173
|
+
const into = Buffer.alloc(length);
|
|
174
|
+
sftp.read(handle, into, 0, length, position, (error, bytes) => done(error, into.subarray(0, bytes)));
|
|
175
|
+
});
|
|
176
|
+
return {
|
|
177
|
+
size: Number(stats.size),
|
|
178
|
+
mtime: stats.mtime,
|
|
179
|
+
// A server may answer a read with fewer bytes than asked; only an empty answer is the end of the file.
|
|
180
|
+
read: (position, length) => guarded(async () => {
|
|
181
|
+
const parts = [];
|
|
182
|
+
let got = 0;
|
|
183
|
+
while (got < length) {
|
|
184
|
+
const part = await readAt(position + got, length - got);
|
|
185
|
+
if (part.length === 0)
|
|
186
|
+
break;
|
|
187
|
+
parts.push(part);
|
|
188
|
+
got += part.length;
|
|
189
|
+
}
|
|
190
|
+
return Buffer.concat(parts, got);
|
|
191
|
+
}),
|
|
192
|
+
close,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
close();
|
|
197
|
+
throw error;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
162
200
|
const validKey = (library, options) => {
|
|
163
201
|
if (options.privateKey === undefined)
|
|
164
202
|
return;
|
|
@@ -189,10 +227,10 @@ const configOf = async (options, verify) => ({
|
|
|
189
227
|
hostVerifier: verify,
|
|
190
228
|
});
|
|
191
229
|
/**
|
|
192
|
-
* Connects, checks the host key with `accept` before any credential is sent, and
|
|
193
|
-
*
|
|
230
|
+
* Connects, checks the host key with `accept` before any credential is sent, and signs in. `signal` ends the attempt
|
|
231
|
+
* and destroys the connection.
|
|
194
232
|
*/
|
|
195
|
-
|
|
233
|
+
const connectClient = async (options, accept, signal, server) => {
|
|
196
234
|
const library = await ssh2();
|
|
197
235
|
validKey(library, options);
|
|
198
236
|
signal.throwIfAborted();
|
|
@@ -207,7 +245,7 @@ export const openWire = async (options, accept, signal) => {
|
|
|
207
245
|
};
|
|
208
246
|
const config = await configOf(options, verify);
|
|
209
247
|
signal.throwIfAborted();
|
|
210
|
-
|
|
248
|
+
return new Promise((resolve, reject) => {
|
|
211
249
|
const stop = () => {
|
|
212
250
|
client.destroy();
|
|
213
251
|
reject(signal.reason);
|
|
@@ -217,24 +255,112 @@ export const openWire = async (options, accept, signal) => {
|
|
|
217
255
|
signal.removeEventListener("abort", stop);
|
|
218
256
|
client.destroy();
|
|
219
257
|
reject(refused
|
|
220
|
-
? new CliError("authentication_error", `the
|
|
258
|
+
? new CliError("authentication_error", `the ${server}'s host key (${refused.algorithm} ${refused.fingerprint}) is not the pinned one; ` +
|
|
221
259
|
"check it with the server's owner before pinning it again", { reason: "sftp.host-key-mismatch" })
|
|
222
|
-
: failureOf(error, "ssh"));
|
|
260
|
+
: failureOf(error, "ssh", server));
|
|
223
261
|
};
|
|
262
|
+
const closed = () => fail(lost(server));
|
|
224
263
|
client.once("error", fail);
|
|
225
|
-
client.once("close",
|
|
226
|
-
client.once("ready", () =>
|
|
227
|
-
if (error)
|
|
228
|
-
return fail(error);
|
|
264
|
+
client.once("close", closed);
|
|
265
|
+
client.once("ready", () => {
|
|
229
266
|
signal.removeEventListener("abort", stop);
|
|
230
267
|
client.removeListener("error", fail);
|
|
268
|
+
client.removeListener("close", closed);
|
|
231
269
|
client.on("error", () => { });
|
|
232
|
-
resolve(
|
|
233
|
-
})
|
|
270
|
+
resolve(client);
|
|
271
|
+
});
|
|
234
272
|
client.connect(config);
|
|
235
273
|
});
|
|
274
|
+
};
|
|
275
|
+
/** Signs in as `connectClient` does and opens the SFTP channel. */
|
|
276
|
+
export const openWire = async (options, accept, signal) => {
|
|
277
|
+
const client = await connectClient(options, accept, signal, "SFTP server");
|
|
278
|
+
const sftp = await new Promise((resolve, reject) => {
|
|
279
|
+
const stop = () => {
|
|
280
|
+
client.destroy();
|
|
281
|
+
reject(signal.reason);
|
|
282
|
+
};
|
|
283
|
+
signal.addEventListener("abort", stop, { once: true });
|
|
284
|
+
client.once("close", () => reject(lost()));
|
|
285
|
+
client.sftp((error, channel) => {
|
|
286
|
+
signal.removeEventListener("abort", stop);
|
|
287
|
+
if (!error)
|
|
288
|
+
return resolve(channel);
|
|
289
|
+
client.destroy();
|
|
290
|
+
reject(failureOf(error, "ssh"));
|
|
291
|
+
});
|
|
292
|
+
});
|
|
236
293
|
return wireOf(client, sftp);
|
|
237
294
|
};
|
|
295
|
+
/** SSH channel-open failure reasons (RFC 4254, section 5.1). */
|
|
296
|
+
const PROHIBITED = 1;
|
|
297
|
+
const CONNECT_FAILED = 2;
|
|
298
|
+
const forwardFailure = (error) => {
|
|
299
|
+
const reason = error?.reason;
|
|
300
|
+
if (reason === PROHIBITED)
|
|
301
|
+
return new CliError("permission_error", "the SSH server does not allow forwarding to that address", {
|
|
302
|
+
reason: "ssh.forward-refused",
|
|
303
|
+
});
|
|
304
|
+
if (reason === CONNECT_FAILED)
|
|
305
|
+
return new CliError("network_error", "the SSH server could not reach the address behind it", {
|
|
306
|
+
reason: "ssh.forward-failed",
|
|
307
|
+
retryable: true,
|
|
308
|
+
});
|
|
309
|
+
return failureOf(error, "ssh", "SSH server");
|
|
310
|
+
};
|
|
311
|
+
/**
|
|
312
|
+
* What a database driver expects of a socket, on a forwarded channel: `pg` calls `connect` and waits for its
|
|
313
|
+
* `connect` event, and both drivers set keep-alive and Nagle options that mean nothing inside an SSH channel.
|
|
314
|
+
*/
|
|
315
|
+
const socketLike = (channel) => {
|
|
316
|
+
const same = () => channel;
|
|
317
|
+
return Object.assign(channel, {
|
|
318
|
+
connect: () => {
|
|
319
|
+
setImmediate(() => channel.emit("connect"));
|
|
320
|
+
return channel;
|
|
321
|
+
},
|
|
322
|
+
setNoDelay: same,
|
|
323
|
+
setKeepAlive: same,
|
|
324
|
+
setTimeout: same,
|
|
325
|
+
ref: same,
|
|
326
|
+
unref: same,
|
|
327
|
+
});
|
|
328
|
+
};
|
|
329
|
+
/** Signs in as `connectClient` does, for forwarding only: no shell, no command, no SFTP. */
|
|
330
|
+
export const openForwarder = async (options, accept, signal) => {
|
|
331
|
+
const client = await connectClient(options, accept, signal, "SSH server");
|
|
332
|
+
let closed = false;
|
|
333
|
+
const channels = new Set();
|
|
334
|
+
const close = () => {
|
|
335
|
+
if (closed)
|
|
336
|
+
return;
|
|
337
|
+
closed = true;
|
|
338
|
+
for (const channel of channels)
|
|
339
|
+
channel.destroy();
|
|
340
|
+
client.destroy();
|
|
341
|
+
};
|
|
342
|
+
client.once("close", close);
|
|
343
|
+
return {
|
|
344
|
+
get closed() {
|
|
345
|
+
return closed;
|
|
346
|
+
},
|
|
347
|
+
forward: (host, port) => new Promise((resolve, reject) => {
|
|
348
|
+
if (closed)
|
|
349
|
+
return reject(lost("SSH server"));
|
|
350
|
+
const gone = () => reject(lost("SSH server"));
|
|
351
|
+
client.once("close", gone);
|
|
352
|
+
client.forwardOut("127.0.0.1", 0, host, port, (error, channel) => {
|
|
353
|
+
client.removeListener("close", gone);
|
|
354
|
+
if (error)
|
|
355
|
+
return reject(forwardFailure(error));
|
|
356
|
+
channels.add(channel);
|
|
357
|
+
channel.once("close", () => channels.delete(channel));
|
|
358
|
+
resolve(socketLike(channel));
|
|
359
|
+
});
|
|
360
|
+
}),
|
|
361
|
+
close,
|
|
362
|
+
};
|
|
363
|
+
};
|
|
238
364
|
const wireOf = (client, sftp) => {
|
|
239
365
|
const pending = new Set();
|
|
240
366
|
let closed = false;
|
|
@@ -271,6 +397,7 @@ const wireOf = (client, sftp) => {
|
|
|
271
397
|
.map((one) => entryOf(one.filename, one.attrs)))))),
|
|
272
398
|
stat: (path) => guarded(() => new Promise((resolve, reject) => sftp.stat(path, (error, attrs) => (error ? reject(error) : resolve(entryOf(basename(path), attrs)))))),
|
|
273
399
|
read: (path, maxBytes, progress) => guarded(() => readAll(sftp, path, maxBytes, progress)),
|
|
400
|
+
open: (path) => guarded(() => openFile(sftp, path, guarded)),
|
|
274
401
|
close,
|
|
275
402
|
};
|
|
276
403
|
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type KeyringStore } from "@wirecat/cli-base";
|
|
2
|
+
import type { Settings } from "../cli/settings.js";
|
|
3
|
+
import { type Fetch } from "../embeddings/remote.js";
|
|
4
|
+
import { type AppIdentity } from "../ports/app.js";
|
|
5
|
+
import type { Pcm } from "./decode.js";
|
|
6
|
+
import type { TimedText } from "./recognize.js";
|
|
7
|
+
export interface CloudSpeechDeps {
|
|
8
|
+
app: AppIdentity;
|
|
9
|
+
env: NodeJS.ProcessEnv;
|
|
10
|
+
keyring?: KeyringStore | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* The profile's settings. Only the profile's own `transcribeWith: "openai"` turns cloud speech on, never the shared
|
|
13
|
+
* defaults: sending a business's calls away is decided for one profile at a time.
|
|
14
|
+
*/
|
|
15
|
+
settings: Pick<Settings, "configured">;
|
|
16
|
+
/** Called once, before the first audio leaves the computer, with the line the run shows on stderr. */
|
|
17
|
+
notify: (line: string) => void;
|
|
18
|
+
fetch?: Fetch;
|
|
19
|
+
signal?: AbortSignal | undefined;
|
|
20
|
+
/** The voice detector model that cuts the speech into pieces; the shared models directory's when not given. */
|
|
21
|
+
vadModel?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface CloudSpeech {
|
|
24
|
+
/**
|
|
25
|
+
* One channel's speech as timed pieces. Each stretch of speech is sent alone, at most ten minutes, under the
|
|
26
|
+
* provider's 25 MB per request; `bundle` sends fewer, longer pieces when the turns do not matter.
|
|
27
|
+
*/
|
|
28
|
+
recognize(audio: Pcm, options?: {
|
|
29
|
+
bundle?: boolean;
|
|
30
|
+
}): Promise<TimedText[]>;
|
|
31
|
+
/** What a host keeps with the transcript: `openai`, or the host name of a compatible service, and the model. */
|
|
32
|
+
recognition: {
|
|
33
|
+
engine: string;
|
|
34
|
+
model: string;
|
|
35
|
+
};
|
|
36
|
+
/** The address the audio goes to, `https://api.openai.com/v1` or the shared AI model's `--base-url`. */
|
|
37
|
+
baseUrl: string;
|
|
38
|
+
/** False only for a compatible service on this computer. */
|
|
39
|
+
leavesComputer: boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Speech to text by an OpenAI-compatible `/audio/transcriptions`, for a host that transcribes recordings (calls,
|
|
43
|
+
* meetings). `null` unless the profile set `transcribeWith` to `openai`: the default is a local model and nothing
|
|
44
|
+
* leaves the computer. Refuses, before any audio is read, in a read-only process, with local only on for an address
|
|
45
|
+
* off this computer, and without a key for the address.
|
|
46
|
+
*/
|
|
47
|
+
export declare const cloudSpeech: (deps: CloudSpeechDeps) => CloudSpeech | null;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { OPENAI_URL } from "../embeddings/remote.js";
|
|
3
|
+
import { aiKeys, aiOrigin, aiSettingPath, readAiSetting } from "../models/ai.js";
|
|
4
|
+
import { onThisComputer } from "../models/endpoint.js";
|
|
5
|
+
import { localOnly, localOnlyRefusal } from "../models/local-only.js";
|
|
6
|
+
import { readOnlyLockOf, readOnlyRefusal } from "../ports/app.js";
|
|
7
|
+
import { typedCommand } from "../runs/scope.js";
|
|
8
|
+
import { OPENAI_TRANSCRIBE_MODEL } from "./models.js";
|
|
9
|
+
/**
|
|
10
|
+
* Where the audio goes: the shared AI model's address when it is OpenAI or compatible (`models ai set openai
|
|
11
|
+
* --base-url …`), else OpenAI's own. The key is the one kept for that address, never another's.
|
|
12
|
+
*/
|
|
13
|
+
const addressOf = (env) => {
|
|
14
|
+
const setting = readAiSetting(aiSettingPath(env));
|
|
15
|
+
return setting?.provider === "openai" && setting.base_url ? setting.base_url : OPENAI_URL;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Speech to text by an OpenAI-compatible `/audio/transcriptions`, for a host that transcribes recordings (calls,
|
|
19
|
+
* meetings). `null` unless the profile set `transcribeWith` to `openai`: the default is a local model and nothing
|
|
20
|
+
* leaves the computer. Refuses, before any audio is read, in a read-only process, with local only on for an address
|
|
21
|
+
* off this computer, and without a key for the address.
|
|
22
|
+
*/
|
|
23
|
+
export const cloudSpeech = (deps) => {
|
|
24
|
+
if (deps.settings.configured.transcribeWith !== "openai")
|
|
25
|
+
return null;
|
|
26
|
+
const baseUrl = addressOf(deps.env);
|
|
27
|
+
const origin = aiOrigin({ provider: "openai", base_url: baseUrl });
|
|
28
|
+
const host = new URL(origin).host;
|
|
29
|
+
const official = origin === "https://api.openai.com";
|
|
30
|
+
const leavesComputer = !onThisComputer(baseUrl);
|
|
31
|
+
const lock = readOnlyLockOf(deps.app, deps.env);
|
|
32
|
+
if (lock && leavesComputer)
|
|
33
|
+
throw readOnlyRefusal(lock, `send audio to ${host}`);
|
|
34
|
+
if (leavesComputer && localOnly(deps.env))
|
|
35
|
+
throw localOnlyRefusal("the recordings", host);
|
|
36
|
+
const apiKey = aiKeys(deps.app, deps.env, deps.keyring).read(origin)?.key;
|
|
37
|
+
const setKey = typedCommand(deps.app.command, official
|
|
38
|
+
? "models ai set openai --model <model> --secret-stdin"
|
|
39
|
+
: `models ai set openai --base-url ${baseUrl} --secret-stdin`);
|
|
40
|
+
if (!apiKey && leavesComputer)
|
|
41
|
+
throw new CliError("authentication_error", `no key for ${host} — \`${setKey}\`${official ? ", or OPENAI_API_KEY" : ""}`, {
|
|
42
|
+
reason: "transcription.no-key",
|
|
43
|
+
});
|
|
44
|
+
const configuredModel = deps.settings.configured.transcribeModel;
|
|
45
|
+
const model = typeof configuredModel === "string" && configuredModel.trim() ? configuredModel.trim() : OPENAI_TRANSCRIBE_MODEL;
|
|
46
|
+
let told = false;
|
|
47
|
+
return {
|
|
48
|
+
baseUrl,
|
|
49
|
+
leavesComputer,
|
|
50
|
+
recognition: { engine: official ? "openai" : host, model },
|
|
51
|
+
recognize: async (audio, options = {}) => {
|
|
52
|
+
if (!told) {
|
|
53
|
+
told = true;
|
|
54
|
+
deps.notify(leavesComputer
|
|
55
|
+
? `the recordings' audio leaves this computer: it goes to ${host} (${model}) to be transcribed`
|
|
56
|
+
: `the recordings' audio goes to ${host} on this computer (${model}) to be transcribed`);
|
|
57
|
+
}
|
|
58
|
+
const { transcribeOpenAI } = await import("./openai.js");
|
|
59
|
+
return transcribeOpenAI(audio, {
|
|
60
|
+
apiKey: apiKey ?? "",
|
|
61
|
+
model,
|
|
62
|
+
baseUrl,
|
|
63
|
+
label: official ? "OpenAI" : host,
|
|
64
|
+
keyHint: setKey,
|
|
65
|
+
env: deps.env,
|
|
66
|
+
...(options.bundle ? { bundle: true } : {}),
|
|
67
|
+
...(deps.vadModel ? { vadModel: deps.vadModel } : {}),
|
|
68
|
+
...(deps.fetch ? { fetch: deps.fetch } : {}),
|
|
69
|
+
...(deps.signal ? { signal: deps.signal } : {}),
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
};
|
package/dist/speech/decode.d.ts
CHANGED
|
@@ -4,28 +4,55 @@ export interface Pcm {
|
|
|
4
4
|
}
|
|
5
5
|
/** An hour of speech; a longer "voice message" is a podcast or a song, and its samples would not fit in memory. */
|
|
6
6
|
export declare const LONGEST_AUDIO_SECONDS = 3600;
|
|
7
|
-
|
|
7
|
+
/** One `Pcm` per channel; a decoder written before channels were kept may still answer one mixed `Pcm`. */
|
|
8
|
+
export type Ffmpeg = (bytes: Uint8Array) => Promise<Pcm | Pcm[]>;
|
|
8
9
|
type Format = "opus" | "vorbis" | "flac" | "mp3" | "other";
|
|
9
10
|
/** From the bytes, never the MIME type: WhatsApp calls an iPhone recording `audio/mp4` and a voice note `audio/ogg`. */
|
|
10
11
|
export declare const formatOf: (bytes: Uint8Array) => Format;
|
|
11
12
|
/**
|
|
12
|
-
* The
|
|
13
|
-
* the
|
|
13
|
+
* The 32-bit float WAV ffmpeg writes to a pipe, read as it arrives: each channel's samples go to their own array at
|
|
14
|
+
* once, so the interleaved bytes are never held whole. ffmpeg cannot seek back on a pipe, so the sizes in the header
|
|
15
|
+
* are placeholders and the samples run to the end of the stream. `push` answers false once a channel passes `most`
|
|
16
|
+
* samples.
|
|
14
17
|
*/
|
|
15
|
-
export declare const
|
|
18
|
+
export declare const wavStream: (most: number) => {
|
|
19
|
+
push: (chunk: Buffer) => boolean;
|
|
20
|
+
end: () => Pcm[];
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The owner's own ffmpeg on a file, for what no bundled decoder reads — AAC above all, which every small decoder does
|
|
24
|
+
* under the GPL; Asterisk's WAV and GSM too. A mono file stays one channel and a stereo call two, one speaker each; a
|
|
25
|
+
* file of more channels is mixed down to two. From a file rather than a pipe: an MP4 whose index sits at the end
|
|
26
|
+
* cannot be read from a pipe. Stops past an hour of audio, so a channel holds at most an hour of 16 kHz samples.
|
|
27
|
+
*/
|
|
28
|
+
export declare const runFfmpegFile: (path: string) => Promise<Pcm[]>;
|
|
29
|
+
/** `runFfmpegFile` on bytes already in memory, through a private temporary file. */
|
|
30
|
+
export declare const runFfmpeg: (bytes: Uint8Array) => Promise<Pcm[]>;
|
|
16
31
|
export interface DecodedChannels {
|
|
17
32
|
channels: Pcm[];
|
|
18
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* True when the channels arrived mixed into one, so one speaker per channel is lost: only when a caller's own
|
|
35
|
+
* `Ffmpeg` answers a single `Pcm`. The bundled decoders and `runFfmpeg` keep a stereo file's channels apart.
|
|
36
|
+
*/
|
|
19
37
|
mixed: boolean;
|
|
20
38
|
}
|
|
21
39
|
/**
|
|
22
|
-
* Every channel the file has, one `Pcm` each: a phone call recorded in stereo keeps one speaker per channel.
|
|
23
|
-
*
|
|
40
|
+
* Every channel the file has, one `Pcm` each: a phone call recorded in stereo keeps one speaker per channel. Opus,
|
|
41
|
+
* Vorbis, FLAC and MP3 by the bundled decoders; anything else, or what one of them could not read, by ffmpeg when the
|
|
42
|
+
* machine has it. The bundled decoder's error wins: it names the file's own problem.
|
|
24
43
|
*/
|
|
25
44
|
export declare const decodeChannels: (bytes: Uint8Array, ffmpeg?: Ffmpeg) => Promise<DecodedChannels>;
|
|
26
45
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
46
|
+
* The channels of a file on disk, for a recording too large to read into memory first: what ffmpeg reads (WAV, GSM,
|
|
47
|
+
* AAC…) goes to it by path, and only the samples are held. A format a bundled decoder reads is read whole, at most
|
|
48
|
+
* `maxBytes` (64 MB when not given): those decoders take bytes, and a compressed file decodes to many times its size.
|
|
29
49
|
*/
|
|
50
|
+
export declare const decodeChannelsFile: (path: string, { maxBytes, ffmpegFile, }?: {
|
|
51
|
+
maxBytes?: number;
|
|
52
|
+
ffmpegFile?: (path: string) => Promise<Pcm[]>;
|
|
53
|
+
}) => Promise<DecodedChannels>;
|
|
54
|
+
/** Every channel averaged into one, so a caller that wants one text keeps both sides of a stereo recording. */
|
|
55
|
+
export declare const mixDown: (channels: readonly Pcm[]) => Pcm;
|
|
56
|
+
/** One voice for a caller that wants the text and not the turns, a voice message: the channels mixed into one. */
|
|
30
57
|
export declare const decodeAudio: (bytes: Uint8Array, ffmpeg?: Ffmpeg) => Promise<Pcm>;
|
|
31
58
|
export {};
|