@lumavox/server 0.62.1 → 0.63.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/README.md +6 -3
- package/dist/gen/types.gen.d.ts +4 -4
- package/dist/resources/assets.js +2 -1
- package/dist/resources/knowledge.js +2 -1
- package/dist/resources/speech.d.ts +6 -0
- package/dist/resources/speech.js +9 -2
- package/dist/resources/voices.js +2 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.js +6 -0
- package/dist/transport.js +33 -6
- package/dist/upload.d.ts +10 -2
- package/dist/upload.js +13 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,8 +31,9 @@ const { key } = await lumavox.ephemeralKeys.create({
|
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
**Server only.** The client holds your API key, which spends your whole
|
|
34
|
-
balance and reads every end user, so it refuses to run in a browser
|
|
35
|
-
React Native app: bundlers resolve it to a
|
|
34
|
+
balance and reads every end user, so it refuses to run in a browser (a page
|
|
35
|
+
or one of its workers) or a React Native app: bundlers resolve it to a
|
|
36
|
+
module that fails the build and
|
|
36
37
|
throws when loaded, and `createClient` checks again. Give the device an
|
|
37
38
|
ephemeral key and use `@lumavox/client` there.
|
|
38
39
|
|
|
@@ -88,7 +89,9 @@ list's page.
|
|
|
88
89
|
sent straight to storage, and the confirm: for an asset, a voice's
|
|
89
90
|
recording and a knowledge file. A `Blob`, an `ArrayBuffer` or a typed
|
|
90
91
|
array; a stream with its `size`.
|
|
91
|
-
- **`tts.create({ …, stream: true })`** answers a `ReadableStream` of PCM
|
|
92
|
+
- **`tts.create({ …, stream: true })`** answers a `ReadableStream` of PCM,
|
|
93
|
+
and every speech answer what its headers say (`sampleRate`, `model`,
|
|
94
|
+
`audioSeconds`, `generationSeconds`, `totalSeconds`, `streamChunking`);
|
|
92
95
|
**`stt.create(audio, { stream: true })`** an async iterator of the
|
|
93
96
|
transcript's events.
|
|
94
97
|
- **A `delete` of something already gone is done**: one thing's answers
|
package/dist/gen/types.gen.d.ts
CHANGED
|
@@ -2975,7 +2975,7 @@ export type AgentCreateRequest = {
|
|
|
2975
2975
|
*/
|
|
2976
2976
|
seed?: number | null;
|
|
2977
2977
|
/**
|
|
2978
|
-
* Where the model stops writing a reply: at the first of these it writes, which is left out. At most 5, of 100 characters each. **One that could end a reply inside its mood line is refused** (422) — a mood opens a reply with `emotion_enabled` on, as `mood: happy 0.6` on a line of its own, so a newline, a space, a digit, `mood` or part of a mood's name would leave no reply. The complete list: `null` or `[]` clears it.
|
|
2978
|
+
* Where the model stops writing a reply: at the first of these it writes, which is left out. At most 5, of 100 characters each. **One that could end a reply inside its mood line is refused** (422) — a mood opens a reply with `emotion_enabled` on, as `mood: happy 0.6` on a line of its own, so a newline, a space, a digit, `mood` or part of a mood's name would leave no reply. So is one that could end it inside the line a reply that steers away from a blocked topic or the age rules begins with (`[steer: 2]`, `[steer: age]`): `[`, `]` or `steer`. The complete list: `null` or `[]` clears it.
|
|
2979
2979
|
*/
|
|
2980
2980
|
stop_sequences?: Array<string> | null;
|
|
2981
2981
|
/**
|
|
@@ -3892,7 +3892,7 @@ export type AgentDefaultsUpdate = {
|
|
|
3892
3892
|
*/
|
|
3893
3893
|
seed?: number | null;
|
|
3894
3894
|
/**
|
|
3895
|
-
* Where the model stops writing a reply: at the first of these it writes, which is left out. At most 5, of 100 characters each. **One that could end a reply inside its mood line is refused** (422) — a mood opens a reply with `emotion_enabled` on, as `mood: happy 0.6` on a line of its own, so a newline, a space, a digit, `mood` or part of a mood's name would leave no reply. The complete list: `null` or `[]` clears it.
|
|
3895
|
+
* Where the model stops writing a reply: at the first of these it writes, which is left out. At most 5, of 100 characters each. **One that could end a reply inside its mood line is refused** (422) — a mood opens a reply with `emotion_enabled` on, as `mood: happy 0.6` on a line of its own, so a newline, a space, a digit, `mood` or part of a mood's name would leave no reply. So is one that could end it inside the line a reply that steers away from a blocked topic or the age rules begins with (`[steer: 2]`, `[steer: age]`): `[`, `]` or `steer`. The complete list: `null` or `[]` clears it.
|
|
3896
3896
|
*/
|
|
3897
3897
|
stop_sequences?: Array<string> | null;
|
|
3898
3898
|
/**
|
|
@@ -4250,7 +4250,7 @@ export type AgentUpdate = {
|
|
|
4250
4250
|
*/
|
|
4251
4251
|
seed?: number | null;
|
|
4252
4252
|
/**
|
|
4253
|
-
* Where the model stops writing a reply: at the first of these it writes, which is left out. At most 5, of 100 characters each. **One that could end a reply inside its mood line is refused** (422) — a mood opens a reply with `emotion_enabled` on, as `mood: happy 0.6` on a line of its own, so a newline, a space, a digit, `mood` or part of a mood's name would leave no reply. The complete list: `null` or `[]` clears it.
|
|
4253
|
+
* Where the model stops writing a reply: at the first of these it writes, which is left out. At most 5, of 100 characters each. **One that could end a reply inside its mood line is refused** (422) — a mood opens a reply with `emotion_enabled` on, as `mood: happy 0.6` on a line of its own, so a newline, a space, a digit, `mood` or part of a mood's name would leave no reply. So is one that could end it inside the line a reply that steers away from a blocked topic or the age rules begins with (`[steer: 2]`, `[steer: age]`): `[`, `]` or `steer`. The complete list: `null` or `[]` clears it.
|
|
4254
4254
|
*/
|
|
4255
4255
|
stop_sequences?: Array<string> | null;
|
|
4256
4256
|
/**
|
|
@@ -4967,7 +4967,7 @@ export type AgentDraftUpdate = {
|
|
|
4967
4967
|
*/
|
|
4968
4968
|
seed?: number | null;
|
|
4969
4969
|
/**
|
|
4970
|
-
* Where the model stops writing a reply: at the first of these it writes, which is left out. At most 5, of 100 characters each. **One that could end a reply inside its mood line is refused** (422) — a mood opens a reply with `emotion_enabled` on, as `mood: happy 0.6` on a line of its own, so a newline, a space, a digit, `mood` or part of a mood's name would leave no reply. The complete list: `null` or `[]` clears it.
|
|
4970
|
+
* Where the model stops writing a reply: at the first of these it writes, which is left out. At most 5, of 100 characters each. **One that could end a reply inside its mood line is refused** (422) — a mood opens a reply with `emotion_enabled` on, as `mood: happy 0.6` on a line of its own, so a newline, a space, a digit, `mood` or part of a mood's name would leave no reply. So is one that could end it inside the line a reply that steers away from a blocked topic or the age rules begins with (`[steer: 2]`, `[steer: age]`): `[`, `]` or `steer`. The complete list: `null` or `[]` clears it.
|
|
4971
4971
|
*/
|
|
4972
4972
|
stop_sequences?: Array<string> | null;
|
|
4973
4973
|
/**
|
package/dist/resources/assets.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* - **`list()` pages by cursor**, 200 a page; a folder's `list()` is one
|
|
16
16
|
* level, which the route answers in one page.
|
|
17
17
|
*/
|
|
18
|
-
import { needType, put, } from "../upload.js";
|
|
18
|
+
import { needType, put, sendable, } from "../upload.js";
|
|
19
19
|
import { keeping } from "../wait.js";
|
|
20
20
|
import { Editable, Waitable } from "./resource.js";
|
|
21
21
|
/** The route's largest page. */
|
|
@@ -71,6 +71,7 @@ export class Assets extends Waitable {
|
|
|
71
71
|
async upload(data, fields = {}, options = {}) {
|
|
72
72
|
const { content_type, ...rest } = fields;
|
|
73
73
|
const type = needType(data, content_type);
|
|
74
|
+
sendable(data, options.size);
|
|
74
75
|
const ticket = await this.uploadUrl({ content_type: type }, options);
|
|
75
76
|
return keeping({ id: ticket.asset_id }, put(this.api, ticket, data, type, options).then(async () => this.settled(await this.confirm({ ...rest, asset_id: ticket.asset_id, content_type: type }, options), options)));
|
|
76
77
|
}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* somebody else's (409); `delete` answers `true`, and `false` for one
|
|
16
16
|
* already gone.
|
|
17
17
|
*/
|
|
18
|
-
import { put, sizeOf, typeOf, } from "../upload.js";
|
|
18
|
+
import { put, sendable, sizeOf, typeOf, } from "../upload.js";
|
|
19
19
|
import { keeping } from "../wait.js";
|
|
20
20
|
import { Waitable } from "./resource.js";
|
|
21
21
|
/** The route's largest page. */
|
|
@@ -52,6 +52,7 @@ export class Knowledge extends Waitable {
|
|
|
52
52
|
/** Uploads a file and reads it: `uploadUrl`, the `PUT`, `fromFile`. */
|
|
53
53
|
async upload(file, fields, options = {}) {
|
|
54
54
|
const { content_type, ...body } = fields;
|
|
55
|
+
sendable(file, options.size);
|
|
55
56
|
const ticket = await this.uploadUrl({
|
|
56
57
|
filename: body.filename,
|
|
57
58
|
size_bytes: sizeOf(file, options.size) ?? null,
|
|
@@ -33,6 +33,12 @@ export interface Speech<Body> {
|
|
|
33
33
|
model: string | null;
|
|
34
34
|
/** Seconds of audio; `null` for a stream, which is not measured up front. */
|
|
35
35
|
audioSeconds: number | null;
|
|
36
|
+
/** Seconds the provider took, the network included; `null` for a stream. */
|
|
37
|
+
generationSeconds: number | null;
|
|
38
|
+
/** Seconds the call took inside the API; `null` for a stream. */
|
|
39
|
+
totalSeconds: number | null;
|
|
40
|
+
/** How a stream was split — `none`, as it came — and `null` for one answer whole. */
|
|
41
|
+
streamChunking: string | null;
|
|
36
42
|
requestId: string;
|
|
37
43
|
}
|
|
38
44
|
/**
|
package/dist/resources/speech.js
CHANGED
|
@@ -46,13 +46,20 @@ export class Tts extends Resource {
|
|
|
46
46
|
...(body.stream ? {} : { waitMs: SPEECH_WAIT_MS.tts }),
|
|
47
47
|
}, options);
|
|
48
48
|
const header = (name) => answer.headers.get(name);
|
|
49
|
-
|
|
49
|
+
// Every header the document names for it: three were read by nobody.
|
|
50
|
+
const seconds = (name) => {
|
|
51
|
+
const value = header(name);
|
|
52
|
+
return value === null ? null : Number(value);
|
|
53
|
+
};
|
|
50
54
|
return {
|
|
51
55
|
body: answer.data,
|
|
52
56
|
contentType: header("content-type") ?? "",
|
|
53
57
|
sampleRate: Number(header("x-sample-rate") ?? body.sample_rate ?? DEFAULT_SAMPLE_RATE),
|
|
54
58
|
model: header("x-model"),
|
|
55
|
-
audioSeconds: seconds
|
|
59
|
+
audioSeconds: seconds("x-audio-seconds"),
|
|
60
|
+
generationSeconds: seconds("x-generation-seconds"),
|
|
61
|
+
totalSeconds: seconds("x-total-seconds"),
|
|
62
|
+
streamChunking: header("x-stream-chunking"),
|
|
56
63
|
requestId: answer.requestId,
|
|
57
64
|
};
|
|
58
65
|
}
|
package/dist/resources/voices.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* voice: done.
|
|
14
14
|
* - **`list()` reads one page**: the route answers every voice in it.
|
|
15
15
|
*/
|
|
16
|
-
import { needType, put, } from "../upload.js";
|
|
16
|
+
import { needType, put, sendable, } from "../upload.js";
|
|
17
17
|
import { keeping } from "../wait.js";
|
|
18
18
|
import { WaitableLibrary } from "./resource.js";
|
|
19
19
|
import { SPEECH_WAIT_MS } from "./speech.js";
|
|
@@ -30,6 +30,7 @@ export class Voices extends WaitableLibrary {
|
|
|
30
30
|
/** Uploads a recording and clones it: `uploadUrl`, the `PUT`, `create`. */
|
|
31
31
|
async upload(recording, fields, options = {}) {
|
|
32
32
|
const { content_type, ...body } = fields;
|
|
33
|
+
sendable(recording, options.size);
|
|
33
34
|
const ticket = await this.uploadUrl({ content_type: needType(recording, content_type) }, options);
|
|
34
35
|
const { upload_id } = ticket;
|
|
35
36
|
const voice = await keeping({ upload_id }, put(this.api, ticket, recording, ticket.content_type, options).then(() => this.create({ ...body, upload_id }, options)));
|
package/dist/runtime.d.ts
CHANGED
package/dist/runtime.js
CHANGED
|
@@ -18,6 +18,12 @@ export const REFUSAL = "@lumavox/server holds your organisation's API key, so it
|
|
|
18
18
|
export function refusedHere(globals = globalThis) {
|
|
19
19
|
if (typeof globals.document !== "undefined")
|
|
20
20
|
return "a browser";
|
|
21
|
+
// A browser's workers — dedicated, shared, a service worker — have no
|
|
22
|
+
// `document`, and every one has `importScripts` (a module worker's too,
|
|
23
|
+
// which throws when called): one let the key through. No server's
|
|
24
|
+
// runtime has it — Workers, Node, Deno, Bun.
|
|
25
|
+
if (typeof globals.importScripts === "function")
|
|
26
|
+
return "a browser's worker";
|
|
21
27
|
if (globals.navigator?.product === "ReactNative")
|
|
22
28
|
return "React Native";
|
|
23
29
|
return null;
|
package/dist/transport.js
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
* `signal`, and it covers reading the body — **except a stream's**,
|
|
11
11
|
* whose timer stops at the headers: a transcript streamed for minutes
|
|
12
12
|
* is not a call that timed out. The caller's abort is theirs: it is
|
|
13
|
-
* thrown as their reason and never retried, and it still ends a stream
|
|
13
|
+
* thrown as their reason and never retried, and it still ends a stream
|
|
14
|
+
* — until the stream ends, and no longer (`following`).
|
|
14
15
|
* - **Not every body is JSON**: speech is bytes or a stream, `/v1/stt`
|
|
15
16
|
* takes the audio raw, and an upload's `PUT` goes to object storage's
|
|
16
17
|
* own URL with no credential (`open`) — the same attempts, retries and
|
|
@@ -144,6 +145,28 @@ export const orNull = (promise) => promise.catch((error) => {
|
|
|
144
145
|
return null;
|
|
145
146
|
throw error;
|
|
146
147
|
});
|
|
148
|
+
/**
|
|
149
|
+
* `body` as the caller reads it, `done` called once it has ended, failed
|
|
150
|
+
* or been cancelled: the caller's signal is listened to while a stream
|
|
151
|
+
* runs, since its abort still ends it, and **not for the signal's life**
|
|
152
|
+
* — a signal kept for a server's whole run held a listener, and through
|
|
153
|
+
* it the answer, for every stream it ever made. The bytes pass through an
|
|
154
|
+
* identity `TransformStream` to be followed; a cancel still reaches the
|
|
155
|
+
* response's own body, so the API still sees its caller hang up. Where
|
|
156
|
+
* there is no `TransformStream` (React Native's Hermes, whose `fetch`
|
|
157
|
+
* streams no body) the body is the response's own and the listener stays.
|
|
158
|
+
*/
|
|
159
|
+
function following(body, done) {
|
|
160
|
+
const { TransformStream: Pass } = globalThis;
|
|
161
|
+
if (!body || !Pass)
|
|
162
|
+
return body;
|
|
163
|
+
const pass = new Pass();
|
|
164
|
+
body.pipeTo(pass.writable).then(done, () => {
|
|
165
|
+
// swallowed: the reader meets the failure on the stream itself.
|
|
166
|
+
done();
|
|
167
|
+
});
|
|
168
|
+
return pass.readable;
|
|
169
|
+
}
|
|
147
170
|
export class Transport {
|
|
148
171
|
constructor(config) {
|
|
149
172
|
numbered("timeoutMs", config.timeoutMs, 1);
|
|
@@ -255,23 +278,26 @@ export class Transport {
|
|
|
255
278
|
async attempt(url, init, read, signal, timeoutMs) {
|
|
256
279
|
// The caller's signal joined to the timer by hand, its reason carried
|
|
257
280
|
// over: `AbortSignal.any` is not React Native's. Left joined for a
|
|
258
|
-
// stream, whose body the caller's abort still ends.
|
|
281
|
+
// stream, whose body the caller's abort still ends, until it ends.
|
|
259
282
|
const timer = new AbortController();
|
|
260
283
|
const stop = () => timer.abort(signal?.reason);
|
|
284
|
+
const release = () => signal?.removeEventListener("abort", stop);
|
|
261
285
|
const clock = setTimeout(stop, timeoutMs);
|
|
262
286
|
signal?.addEventListener("abort", stop);
|
|
263
287
|
// Already aborted: no event will come, and `fetch` sends nothing.
|
|
264
288
|
if (signal?.aborted)
|
|
265
289
|
stop();
|
|
290
|
+
let streaming = false;
|
|
266
291
|
try {
|
|
267
292
|
const response = await this.config.fetch(url, {
|
|
268
293
|
...init,
|
|
269
294
|
signal: timer.signal,
|
|
270
295
|
});
|
|
296
|
+
streaming = response.ok && read === "stream";
|
|
271
297
|
const body = !response.ok
|
|
272
298
|
? await response.text()
|
|
273
|
-
:
|
|
274
|
-
? response.body
|
|
299
|
+
: streaming
|
|
300
|
+
? following(response.body, release)
|
|
275
301
|
: read === "bytes"
|
|
276
302
|
? await response.arrayBuffer()
|
|
277
303
|
: await response.text();
|
|
@@ -287,8 +313,9 @@ export class Transport {
|
|
|
287
313
|
}
|
|
288
314
|
finally {
|
|
289
315
|
clearTimeout(clock);
|
|
290
|
-
|
|
291
|
-
|
|
316
|
+
// A refusal's body, read whole, is no stream to end.
|
|
317
|
+
if (!streaming)
|
|
318
|
+
release();
|
|
292
319
|
}
|
|
293
320
|
}
|
|
294
321
|
}
|
package/dist/upload.d.ts
CHANGED
|
@@ -13,8 +13,9 @@
|
|
|
13
13
|
* machine whose clock runs ahead would otherwise time out at once.
|
|
14
14
|
* - **A Blob, an ArrayBuffer or a typed array; a stream only with its
|
|
15
15
|
* `size`**: a signed `PUT` needs `Content-Length`, which a stream cannot
|
|
16
|
-
* say
|
|
17
|
-
*
|
|
16
|
+
* say — refused before the ticket is asked (`sendable`). On Workers the
|
|
17
|
+
* stream goes through `FixedLengthStream`, which is how a Worker sends a
|
|
18
|
+
* stream with a length. A stream is sent once.
|
|
18
19
|
*/
|
|
19
20
|
import type { RequestOptions, Transport } from "./transport.js";
|
|
20
21
|
/** What an upload can send. */
|
|
@@ -32,6 +33,13 @@ export declare const sizeOf: (data: UploadData, size?: number) => number | undef
|
|
|
32
33
|
export declare const typeOf: (data: UploadData, type?: string | null) => string;
|
|
33
34
|
/** `type`, or a `TypeError` naming what to pass. */
|
|
34
35
|
export declare function needType(data: UploadData, type?: string | null): string;
|
|
36
|
+
/**
|
|
37
|
+
* A stream's `size`, or a `TypeError` naming it: **what every upload asks
|
|
38
|
+
* first**, before its ticket. Refused at the `PUT`, a stream with none
|
|
39
|
+
* had a ticket asked for nothing — for a knowledge file, a pending upload
|
|
40
|
+
* left behind it.
|
|
41
|
+
*/
|
|
42
|
+
export declare function sendable(data: UploadData, size: number | undefined): number | undefined;
|
|
35
43
|
/** The bytes, to a ticket's signed URL, valid until its `expires_at`. */
|
|
36
44
|
export declare function put(api: Transport, ticket: {
|
|
37
45
|
url: string;
|
package/dist/upload.js
CHANGED
|
@@ -14,6 +14,18 @@ export function needType(data, type) {
|
|
|
14
14
|
throw new TypeError("This upload needs its content_type.");
|
|
15
15
|
return found;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* A stream's `size`, or a `TypeError` naming it: **what every upload asks
|
|
19
|
+
* first**, before its ticket. Refused at the `PUT`, a stream with none
|
|
20
|
+
* had a ticket asked for nothing — for a knowledge file, a pending upload
|
|
21
|
+
* left behind it.
|
|
22
|
+
*/
|
|
23
|
+
export function sendable(data, size) {
|
|
24
|
+
if (data instanceof ReadableStream && size === undefined) {
|
|
25
|
+
throw new TypeError("A stream uploads only with its size: { size }.");
|
|
26
|
+
}
|
|
27
|
+
return size;
|
|
28
|
+
}
|
|
17
29
|
/** The least time a `PUT` is given, whatever the ticket's clock says. */
|
|
18
30
|
const MIN_PUT_MS = 60_000;
|
|
19
31
|
/** The bytes, to a ticket's signed URL, valid until its `expires_at`. */
|
|
@@ -21,10 +33,7 @@ export async function put(api, ticket, data, type, options) {
|
|
|
21
33
|
let raw = data;
|
|
22
34
|
const headers = {};
|
|
23
35
|
if (data instanceof ReadableStream) {
|
|
24
|
-
const size = options.size;
|
|
25
|
-
if (size === undefined) {
|
|
26
|
-
throw new TypeError("A stream uploads only with its size: { size }.");
|
|
27
|
-
}
|
|
36
|
+
const size = sendable(data, options.size);
|
|
28
37
|
headers["Content-Length"] = String(size);
|
|
29
38
|
// Workers' own class, read off the global: no other runtime has it,
|
|
30
39
|
// nor do the types a customer compiles against.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lumavox/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.63.0",
|
|
4
4
|
"description": "The Lumavox API from your server: end users, ephemeral keys and the rest, typed from the published OpenAPI document. Zero dependencies.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|