@lumavox/server 0.62.2 → 0.63.1
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/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.d.ts +4 -3
- package/dist/resources/voices.js +6 -4
- 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/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
|
}
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* `/v1/voices*` — the built-in one, the platform's, and its own, cloned
|
|
4
4
|
* from a recording or designed from a description.
|
|
5
5
|
*
|
|
6
|
-
* - **A
|
|
7
|
-
*
|
|
6
|
+
* - **A clone is a job**: `create` and `upload` answer it `pending`;
|
|
7
|
+
* `wait(id)` reads it until `ready` or `failed`. A design kept with
|
|
8
|
+
* `saveDesign` is `ready` at once, its spoken samples following.
|
|
8
9
|
* - **`upload(recording, fields)`** is the ticket, the `PUT` and the
|
|
9
10
|
* create in one (`upload.ts`); `consent: true` says you may clone it.
|
|
10
11
|
* - **`design(body)` answers previews, not a voice**: keep one with
|
|
@@ -36,6 +37,6 @@ export declare class Voices extends WaitableLibrary<VoiceDetail, VoiceUpdate, Vo
|
|
|
36
37
|
resample(id: string, options?: RequestOptions): Promise<VoiceDetail>;
|
|
37
38
|
/** Previews of a voice made from a description; charged. */
|
|
38
39
|
design(body: VoiceDesignRequest, options?: RequestOptions): Promise<VoiceDesignResult>;
|
|
39
|
-
/** Keeps one preview as a voice: `
|
|
40
|
+
/** Keeps one preview as a voice: `ready` at once, its spoken samples following. */
|
|
40
41
|
saveDesign(body: VoiceDesignSaveRequest, options?: RequestOptions): Promise<VoiceDetail>;
|
|
41
42
|
}
|
package/dist/resources/voices.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* `/v1/voices*` — the built-in one, the platform's, and its own, cloned
|
|
4
4
|
* from a recording or designed from a description.
|
|
5
5
|
*
|
|
6
|
-
* - **A
|
|
7
|
-
*
|
|
6
|
+
* - **A clone is a job**: `create` and `upload` answer it `pending`;
|
|
7
|
+
* `wait(id)` reads it until `ready` or `failed`. A design kept with
|
|
8
|
+
* `saveDesign` is `ready` at once, its spoken samples following.
|
|
8
9
|
* - **`upload(recording, fields)`** is the ticket, the `PUT` and the
|
|
9
10
|
* create in one (`upload.ts`); `consent: true` says you may clone it.
|
|
10
11
|
* - **`design(body)` answers previews, not a voice**: keep one with
|
|
@@ -13,7 +14,7 @@
|
|
|
13
14
|
* voice: done.
|
|
14
15
|
* - **`list()` reads one page**: the route answers every voice in it.
|
|
15
16
|
*/
|
|
16
|
-
import { needType, put, } from "../upload.js";
|
|
17
|
+
import { needType, put, sendable, } from "../upload.js";
|
|
17
18
|
import { keeping } from "../wait.js";
|
|
18
19
|
import { WaitableLibrary } from "./resource.js";
|
|
19
20
|
import { SPEECH_WAIT_MS } from "./speech.js";
|
|
@@ -30,6 +31,7 @@ export class Voices extends WaitableLibrary {
|
|
|
30
31
|
/** Uploads a recording and clones it: `uploadUrl`, the `PUT`, `create`. */
|
|
31
32
|
async upload(recording, fields, options = {}) {
|
|
32
33
|
const { content_type, ...body } = fields;
|
|
34
|
+
sendable(recording, options.size);
|
|
33
35
|
const ticket = await this.uploadUrl({ content_type: needType(recording, content_type) }, options);
|
|
34
36
|
const { upload_id } = ticket;
|
|
35
37
|
const voice = await keeping({ upload_id }, put(this.api, ticket, recording, ticket.content_type, options).then(() => this.create({ ...body, upload_id }, options)));
|
|
@@ -51,7 +53,7 @@ export class Voices extends WaitableLibrary {
|
|
|
51
53
|
}, options)
|
|
52
54
|
.then((answer) => answer.data);
|
|
53
55
|
}
|
|
54
|
-
/** Keeps one preview as a voice: `
|
|
56
|
+
/** Keeps one preview as a voice: `ready` at once, its spoken samples following. */
|
|
55
57
|
saveDesign(body, options) {
|
|
56
58
|
return this.send("POST", "/design/save", options, body);
|
|
57
59
|
}
|
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.1",
|
|
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",
|