@lumavox/server 0.46.0 → 0.48.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 +21 -7
- package/dist/gen/types.gen.d.ts +28 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -0
- package/dist/resources/assets.js +2 -2
- package/dist/resources/end-users.d.ts +19 -3
- package/dist/resources/end-users.js +25 -2
- package/dist/resources/generations.js +2 -2
- package/dist/resources/knowledge.js +4 -2
- package/dist/resources/resource.js +2 -2
- package/dist/resources/speech.d.ts +17 -0
- package/dist/resources/speech.js +17 -0
- package/dist/resources/templates.js +2 -2
- package/dist/resources/voices.js +14 -3
- package/dist/transport.d.ts +26 -3
- package/dist/transport.js +70 -12
- package/dist/wait.d.ts +16 -0
- package/dist/wait.js +36 -0
- package/package.json +16 -1
package/README.md
CHANGED
|
@@ -53,6 +53,10 @@ createClient({
|
|
|
53
53
|
Bodies and answers are the API's own JSON, field for field, as the API
|
|
54
54
|
reference shows them; methods are camelCase, and the SDK's options go in a
|
|
55
55
|
last argument on every call: `{ timeoutMs, signal, maxRetries, requestId }`.
|
|
56
|
+
`stt.create`, a whole `tts.create` and `voices.design` wait at least 100,
|
|
57
|
+
70 and 90 seconds by themselves — the API holds them open that long — unless
|
|
58
|
+
the call names its own `timeoutMs`. An id that is empty, `.` or `..` is a
|
|
59
|
+
`TypeError` before anything is sent.
|
|
56
60
|
Credits are integers of micro-credits (`*_micros`; 1 credit is 1,000,000)
|
|
57
61
|
and times ISO strings, as on the wire. Every schema is exported as a type:
|
|
58
62
|
`GenerationInfo`, `AssetDetail`, `EndUserInfo`, … — and `Page<T>`, any
|
|
@@ -60,16 +64,16 @@ list's page.
|
|
|
60
64
|
|
|
61
65
|
| Resource | Methods |
|
|
62
66
|
|---|---|
|
|
63
|
-
| `endUsers` | `create`, `get`, `update`, `delete`, `list`, `page`, `export`, `toolResult`; `facts.list`, `facts.add`, `facts.update`, `facts.delete`; `memories.list`, `memories.page`, `memories.get`, `memories.delete`, `memories.deleteAll`; `personalization.get`, `personalization.update`, `note`; `scheduledMessages.create`, `scheduledMessages.list`, `scheduledMessages.get`, `scheduledMessages.cancel` |
|
|
64
|
-
| `ephemeralKeys` | `limits`, `create`, `revoke`, `inspect`, `list`, `page` |
|
|
67
|
+
| `endUsers` | `create`, `get`, `update`, `delete`, `list`, `page`, `export`, `toolResult`; `facts.list`, `facts.add`, `facts.update`, `facts.delete`; `memories.list`, `memories.page`, `memories.get`, `memories.delete`, `memories.deleteAll`; `personalization.get`, `personalization.update`, `note`; `scheduledMessages.create`, `scheduledMessages.list`, `scheduledMessages.get`, `scheduledMessages.cancel`; `reports.list`, `reports.page`, `reports.get` |
|
|
68
|
+
| `ephemeralKeys` | `limits`, `create`, `get`, `revoke`, `inspect`, `list`, `page` |
|
|
65
69
|
| `images`, `videos`, `audio`, `skybox`, `transcriptions` | `create`, `get`, `wait`, `generate`; `images.draftLayout`, `images.findElements`; `skybox.styles` |
|
|
66
70
|
| `generations` | `get`, `wait`, `list`, `page` |
|
|
67
71
|
| `templates` | `list`, `page`, `get`, `create`, `generate`, `file` |
|
|
68
72
|
| `tts`, `stt` | `create` |
|
|
69
73
|
| `voices` | `list`, `page`, `get`, `create`, `uploadUrl`, `upload`, `update`, `delete`, `resample`, `design`, `saveDesign`, `wait` |
|
|
70
74
|
| `assets` | `list`, `page`, `get`, `uploadUrl`, `confirm`, `upload`, `update`, `delete`, `deleteMany`, `move`, `wait`; `assets.folders.*` |
|
|
71
|
-
| `agents` | `list`, `page`, `get`, `create`, `update`, `delete`; `agents.settings.get/update`; `agents.knowledge.list/set`; `agents.tools.list/set`; `agents.versions.list/get/restore` — every change players see is a version, any kept one put back; `agents.draft.get/update/discard/publish` — changes players get only once published |
|
|
72
|
-
| `tools` | `list`, `page`, `get`, `create` (a webhook's signing secret, shown once), `update`, `delete`, `rotateSecret`, `test` |
|
|
75
|
+
| `agents` | `list`, `page`, `get`, `create`, `update`, `delete`; `agents.testWebhook`; `agents.settings.get/update/rotateWebhookSecret`; `agents.knowledge.list/set`; `agents.tools.list/set`; `agents.versions.list/get/restore` — every change players see is a version, any kept one put back; `agents.draft.get/update/discard/publish` — changes players get only once published |
|
|
76
|
+
| `tools` | `list`, `page`, `get`, `create` (a webhook's signing secret, shown once), `update`, `delete`, `rotateSecret`, `test`, `calls` |
|
|
73
77
|
| `knowledge` | `list`, `page`, `get`, `create`, `bulk`, `fromUrl`, `uploadUrl`, `fromFile`, `upload`, `update`, `delete`, `reindex`, `refresh`, `setAgents`, `search`, `categories`, `insights`, `wait` |
|
|
74
78
|
| `usage` | `get`, `plan` |
|
|
75
79
|
| the client | `health()`, `limits()` (the platform's limits, each by its key) |
|
|
@@ -120,7 +124,10 @@ ours.
|
|
|
120
124
|
Only what cannot happen twice is retried, up to `maxRetries`: a GET, PUT,
|
|
121
125
|
PATCH or DELETE after a failed connection, a timeout, 429, 502, 503 or 504;
|
|
122
126
|
a POST after a 429 only, which is refused before any work — and
|
|
123
|
-
`endUsers.create` with an `external_id`, which is idempotent.
|
|
127
|
+
`endUsers.create` with an `external_id`, which is idempotent. A change
|
|
128
|
+
that names its `expected_version`, and a scheduled message's `cancel`, are
|
|
129
|
+
sent once, but for a 429. When a call fails after it made something — a
|
|
130
|
+
`generate()` whose wait was aborted — `madeBy(error)` answers its `{ id }`. The wait
|
|
124
131
|
doubles from 0.5 s to 8 s with jitter; `Retry-After` wins, up to a minute,
|
|
125
132
|
and a longer one is thrown at once as a `RateLimitError` with its
|
|
126
133
|
`retryAfter`.
|
|
@@ -137,8 +144,15 @@ and a longer one is thrown at once as a `RateLimitError` with its
|
|
|
137
144
|
ones (`settled_at`), reading the key with `get` — pass a `signal` for a
|
|
138
145
|
deadline. **`inspect` shows a key's spend turn by turn**, as the key
|
|
139
146
|
itself reads it.
|
|
140
|
-
- **`endUsers.export(id)`** reads
|
|
141
|
-
|
|
147
|
+
- **`endUsers.export(id)`** reads everything the API holds about a
|
|
148
|
+
person — their record, every conversation, fact and memory (replaced
|
|
149
|
+
facts too, until they are deleted), how each agent stands with them,
|
|
150
|
+
their reports, what you set and scheduled for them — with a
|
|
142
151
|
five-minute key of their own, revoked after — on failure
|
|
143
152
|
too. The key is an ordinary one: at the person's live-key cap the export
|
|
144
153
|
fails as the mint does.
|
|
154
|
+
|
|
155
|
+
## Docs and releases
|
|
156
|
+
|
|
157
|
+
The guide: <https://docs.lumavox.ai/sdks/server>. What changed in each
|
|
158
|
+
release, and what you change: <https://docs.lumavox.ai/sdks/releases>.
|
package/dist/gen/types.gen.d.ts
CHANGED
|
@@ -499,6 +499,10 @@ export type TtsOptions = {
|
|
|
499
499
|
* `POST /v1/tts` says what it produced in the `X-Sample-Rate` header. Queued speech (`POST /v1/audio`) does not take it: each of its formats has its own rate.
|
|
500
500
|
*/
|
|
501
501
|
sample_rate: 8000 | 16000 | 22050 | 24000 | 44100 | null;
|
|
502
|
+
/**
|
|
503
|
+
* The language the voice speaks in: a BCP-47 tag of a language and, optionally, a region — `en`, `fa`, `pt-BR`. It holds the voice to that language, its accent and its reading of numbers, where the provider would otherwise guess it from the text, which a short text can get wrong. Sent to the voice's provider when its model lists the language: `eleven_flash_v2_5` takes 32, `eleven_v3` and Inworld's two many more, and `eleven_multilingual_v2` none. For a language the model does not list, and when unset or null, the language is detected from the text.
|
|
504
|
+
*/
|
|
505
|
+
language: string | null;
|
|
502
506
|
};
|
|
503
507
|
export type ProviderVoiceSettingsInfo = {
|
|
504
508
|
/**
|
|
@@ -834,6 +838,10 @@ export type AudioRequest = {
|
|
|
834
838
|
* `POST /v1/tts` says what it produced in the `X-Sample-Rate` header. Queued speech (`POST /v1/audio`) does not take it: each of its formats has its own rate.
|
|
835
839
|
*/
|
|
836
840
|
sample_rate?: 8000 | 16000 | 22050 | 24000 | 44100 | null;
|
|
841
|
+
/**
|
|
842
|
+
* The language the voice speaks in: a BCP-47 tag of a language and, optionally, a region — `en`, `fa`, `pt-BR`. It holds the voice to that language, its accent and its reading of numbers, where the provider would otherwise guess it from the text, which a short text can get wrong. Sent to the voice's provider when its model lists the language: `eleven_flash_v2_5` takes 32, `eleven_v3` and Inworld's two many more, and `eleven_multilingual_v2` none. For a language the model does not list, and when unset or null, the language is detected from the text.
|
|
843
|
+
*/
|
|
844
|
+
language?: string | null;
|
|
837
845
|
/**
|
|
838
846
|
* What to say.
|
|
839
847
|
*/
|
|
@@ -2283,6 +2291,10 @@ export type AgentVoiceInfo = {
|
|
|
2283
2291
|
* The audio format this voice is configured with. On the WebSocket a reply is always raw 16-bit PCM, at the rate its `audio.start` names.
|
|
2284
2292
|
*/
|
|
2285
2293
|
format: 'wav' | 'pcm' | null;
|
|
2294
|
+
/**
|
|
2295
|
+
* The language the agent's voice speaks in: a BCP-47 tag of a language and, optionally, a region — `en`, `fa`, `pt-BR`. It holds every piece of a reply to one language and accent, where the provider would otherwise guess each from its own text. A conversation whose key names a `language` speaks in that instead. Sent to the voice's provider when its model lists the language — `eleven_flash_v2_5` takes 32, Inworld's two many more, `eleven_multilingual_v2` none; for any other, and when unset or null, the language is detected from the text.
|
|
2296
|
+
*/
|
|
2297
|
+
language: string | null;
|
|
2286
2298
|
/**
|
|
2287
2299
|
* Which model speaks, one the voice lists as `models` in `GET /v1/voices`: for an ElevenLabs voice `eleven_flash_v2_5` or `eleven_multilingual_v2`, for an Inworld voice `inworld-tts-2-flash` or `inworld-tts-2`. Unset is the voice's provider's fastest — `eleven_flash_v2_5` or `inworld-tts-2-flash`.
|
|
2288
2300
|
*/
|
|
@@ -2301,6 +2313,10 @@ export type AgentVoiceInfo = {
|
|
|
2301
2313
|
* An id from `GET /v1/voices` — the built-in voice, a platform voice, or one your organisation uploaded.
|
|
2302
2314
|
*/
|
|
2303
2315
|
voice_id: string | null;
|
|
2316
|
+
/**
|
|
2317
|
+
* Whether a turn the agent is about to speak reaches the model with a note saying its reply will be spoken aloud, so it writes numbers, amounts, dates and times in words and leaves out lists, headings, links, emoji and symbols — which a voice reads out or stumbles on. A reply that will only be typed is never asked this, and the note is not stored in the transcript. Unset or null means on.
|
|
2318
|
+
*/
|
|
2319
|
+
write_for_speech: boolean | null;
|
|
2304
2320
|
};
|
|
2305
2321
|
export type AgentInfo = {
|
|
2306
2322
|
/**
|
|
@@ -2994,6 +3010,10 @@ export type AgentVoice = {
|
|
|
2994
3010
|
* The audio format this voice is configured with. On the WebSocket a reply is always raw 16-bit PCM, at the rate its `audio.start` names.
|
|
2995
3011
|
*/
|
|
2996
3012
|
format?: 'wav' | 'pcm';
|
|
3013
|
+
/**
|
|
3014
|
+
* The language the agent's voice speaks in: a BCP-47 tag of a language and, optionally, a region — `en`, `fa`, `pt-BR`. It holds every piece of a reply to one language and accent, where the provider would otherwise guess each from its own text. A conversation whose key names a `language` speaks in that instead. Sent to the voice's provider when its model lists the language — `eleven_flash_v2_5` takes 32, Inworld's two many more, `eleven_multilingual_v2` none; for any other, and when unset or null, the language is detected from the text.
|
|
3015
|
+
*/
|
|
3016
|
+
language?: string | null;
|
|
2997
3017
|
/**
|
|
2998
3018
|
* Which model speaks, one the voice lists as `models` in `GET /v1/voices`: for an ElevenLabs voice `eleven_flash_v2_5` or `eleven_multilingual_v2`, for an Inworld voice `inworld-tts-2-flash` or `inworld-tts-2`. Unset is the voice's provider's fastest — `eleven_flash_v2_5` or `inworld-tts-2-flash`.
|
|
2999
3019
|
*/
|
|
@@ -3012,6 +3032,10 @@ export type AgentVoice = {
|
|
|
3012
3032
|
* An id from `GET /v1/voices` — the built-in voice, a platform voice, or one your organisation uploaded.
|
|
3013
3033
|
*/
|
|
3014
3034
|
voice_id?: string;
|
|
3035
|
+
/**
|
|
3036
|
+
* Whether a turn the agent is about to speak reaches the model with a note saying its reply will be spoken aloud, so it writes numbers, amounts, dates and times in words and leaves out lists, headings, links, emoji and symbols — which a voice reads out or stumbles on. A reply that will only be typed is never asked this, and the note is not stored in the transcript. Unset or null means on.
|
|
3037
|
+
*/
|
|
3038
|
+
write_for_speech?: boolean | null;
|
|
3015
3039
|
};
|
|
3016
3040
|
export type AgentSettingsInfo = {
|
|
3017
3041
|
/**
|
|
@@ -5495,6 +5519,10 @@ export type TtsRequest = {
|
|
|
5495
5519
|
* `POST /v1/tts` says what it produced in the `X-Sample-Rate` header. Queued speech (`POST /v1/audio`) does not take it: each of its formats has its own rate.
|
|
5496
5520
|
*/
|
|
5497
5521
|
sample_rate?: 8000 | 16000 | 22050 | 24000 | 44100 | null;
|
|
5522
|
+
/**
|
|
5523
|
+
* The language the voice speaks in: a BCP-47 tag of a language and, optionally, a region — `en`, `fa`, `pt-BR`. It holds the voice to that language, its accent and its reading of numbers, where the provider would otherwise guess it from the text, which a short text can get wrong. Sent to the voice's provider when its model lists the language: `eleven_flash_v2_5` takes 32, `eleven_v3` and Inworld's two many more, and `eleven_multilingual_v2` none. For a language the model does not list, and when unset or null, the language is detected from the text.
|
|
5524
|
+
*/
|
|
5525
|
+
language?: string | null;
|
|
5498
5526
|
text: string;
|
|
5499
5527
|
/**
|
|
5500
5528
|
* Stream audio as it is generated. Only the pcm format can stream.
|
package/dist/index.d.ts
CHANGED
|
@@ -8,9 +8,9 @@ export { type Client, type ClientOptions, createClient, DEFAULT_BASE_URL, } from
|
|
|
8
8
|
export { AuthenticationError, ConflictError, ConnectionError, InsufficientCreditsError, NotFoundError, PermissionError, PlatformError, type PlatformErrorCode, type PlatformErrorInit, RateLimitError, ServerError, TimeoutError, ValidationError, } from "./errors.js";
|
|
9
9
|
export type * from "./gen/index.js";
|
|
10
10
|
export type { Page } from "./paging.js";
|
|
11
|
-
export type { AgentKnowledge, AgentSettings, Agents, AgentTools, } from "./resources/agents.js";
|
|
11
|
+
export type { AgentDrafts, AgentKnowledge, AgentSettings, Agents, AgentTools, AgentVersions, } from "./resources/agents.js";
|
|
12
12
|
export type { AssetListParams, Assets, AssetUploadFields, FolderListParams, Folders, } from "./resources/assets.js";
|
|
13
|
-
export type { EndUserCreated, EndUserExport, EndUserListParams, EndUserMemories, EndUserMemoryListParams, EndUserScheduledMessages, EndUsers, } from "./resources/end-users.js";
|
|
13
|
+
export type { EndUserCreated, EndUserExport, EndUserFacts, EndUserListParams, EndUserMemories, EndUserMemoryListParams, EndUserPersonalizations, EndUserReportListParams, EndUserReports, EndUserScheduledMessages, EndUsers, FactAdded, } from "./resources/end-users.js";
|
|
14
14
|
export type { EphemeralKeyCreateOptions, EphemeralKeyListParams, EphemeralKeyRevokeOptions, EphemeralKeys, } from "./resources/ephemeral-keys.js";
|
|
15
15
|
export type { GenerationListParams, Generations, Images, Jobs, Skybox, } from "./resources/generations.js";
|
|
16
16
|
export type { Knowledge, KnowledgeInsightsParams, KnowledgeListParams, KnowledgeUploadFields, } from "./resources/knowledge.js";
|
|
@@ -22,4 +22,4 @@ export type { Usage, UsageParams } from "./resources/usage.js";
|
|
|
22
22
|
export type { Voices, VoiceUploadFields } from "./resources/voices.js";
|
|
23
23
|
export type { Fetch, RequestOptions } from "./transport.js";
|
|
24
24
|
export type { UploadData, UploadOptions } from "./upload.js";
|
|
25
|
-
export type
|
|
25
|
+
export { type Job, type Made, madeBy } from "./wait.js";
|
package/dist/index.js
CHANGED
|
@@ -6,3 +6,4 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export { createClient, DEFAULT_BASE_URL, } from "./client.js";
|
|
8
8
|
export { AuthenticationError, ConflictError, ConnectionError, InsufficientCreditsError, NotFoundError, PermissionError, PlatformError, RateLimitError, ServerError, TimeoutError, ValidationError, } from "./errors.js";
|
|
9
|
+
export { madeBy } from "./wait.js";
|
package/dist/resources/assets.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* level, which the route answers in one page.
|
|
17
17
|
*/
|
|
18
18
|
import { needType, put, } from "../upload.js";
|
|
19
|
+
import { keeping } from "../wait.js";
|
|
19
20
|
import { Editable, Waitable } from "./resource.js";
|
|
20
21
|
/** The route's largest page. */
|
|
21
22
|
const PAGE = 200;
|
|
@@ -71,8 +72,7 @@ export class Assets extends Waitable {
|
|
|
71
72
|
const { content_type, ...rest } = fields;
|
|
72
73
|
const type = needType(data, content_type);
|
|
73
74
|
const ticket = await this.uploadUrl({ content_type: type }, options);
|
|
74
|
-
|
|
75
|
-
return this.settled(await this.confirm({ ...rest, asset_id: ticket.asset_id, content_type: type }, options), options);
|
|
75
|
+
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
76
|
}
|
|
77
77
|
/** Deletes several: how many were. */
|
|
78
78
|
deleteMany(body, options) {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
* read fails with a 401; its one micro-credit is set aside like any key's,
|
|
35
35
|
* so an organisation with no balance cannot export (402).
|
|
36
36
|
*/
|
|
37
|
-
import type { ConversationReport, ConversationReportPage, EndUserCreateRequest, EndUserDeleted, EndUserInfo, EndUserPage, EndUserPersonalization, EndUserPersonalizationUpdate, EndUserUpdateRequest, FactCreateRequest, FactInfo, FactUpdateRequest, ListEndUserMemoriesData, ListEndUserReportsData, ListEndUsersData, MemoriesDeleted, MemoryInfo, MemoryPage, NoteCreateRequest, NoteTaken, ScheduledMessage, ScheduledMessageCreateRequest, SessionDetail, ToolResultRequest, ToolResultTaken } from "../gen/index.js";
|
|
37
|
+
import type { ConversationReport, ConversationReportPage, EndUserCreateRequest, EndUserDeleted, EndUserInfo, EndUserPage, EndUserPersonalization, EndUserPersonalizationUpdate, EndUserUpdateRequest, FactCreateRequest, FactInfo, FactUpdateRequest, ListEndUserMemoriesData, ListEndUserReportsData, ListEndUsersData, MemoriesDeleted, MemoryInfo, MemoryPage, NoteCreateRequest, NoteTaken, RelationInfo, ScheduledMessage, ScheduledMessageCreateRequest, SessionDetail, ToolResultRequest, ToolResultTaken } from "../gen/index.js";
|
|
38
38
|
import { type RequestOptions, type Transport } from "../transport.js";
|
|
39
39
|
import type { EphemeralKeys } from "./ephemeral-keys.js";
|
|
40
40
|
import { Editable } from "./resource.js";
|
|
@@ -50,19 +50,35 @@ export type EndUserCreated = EndUserInfo & {
|
|
|
50
50
|
*/
|
|
51
51
|
created: boolean;
|
|
52
52
|
};
|
|
53
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Everything the API holds about one person. **Everything**: until 0.46.4
|
|
55
|
+
* it was their conversations, facts and memories alone — an answer to a
|
|
56
|
+
* person's request for their data that left out how the agents stand with
|
|
57
|
+
* them, what was written about their conversations, and what your server
|
|
58
|
+
* had set and scheduled for them.
|
|
59
|
+
*/
|
|
54
60
|
export interface EndUserExport {
|
|
55
61
|
/** Their `eu_…` id. */
|
|
56
62
|
end_user_id: string;
|
|
63
|
+
/** Their own record: your id for them, their name, when they were made. */
|
|
64
|
+
end_user: EndUserInfo;
|
|
57
65
|
/**
|
|
58
66
|
* Every conversation, most recent first, each with every message,
|
|
59
67
|
* oldest first, in its one page of `messages` (`next_cursor` `null`).
|
|
60
68
|
*/
|
|
61
69
|
sessions: SessionDetail[];
|
|
62
|
-
/** What is remembered about them,
|
|
70
|
+
/** What is remembered about them, replaced facts too, oldest first. */
|
|
63
71
|
facts: FactInfo[];
|
|
64
72
|
/** Every topic of their life the agents remember, the topic last talked about first. */
|
|
65
73
|
memories: MemoryInfo[];
|
|
74
|
+
/** How each agent they have talked to stands with them. */
|
|
75
|
+
relations: RelationInfo[];
|
|
76
|
+
/** What an agent that writes reports wrote after each of their conversations, newest first. */
|
|
77
|
+
reports: ConversationReport[];
|
|
78
|
+
/** What your server set for them: the instructions every agent follows, an opening line's blanks. */
|
|
79
|
+
personalization: EndUserPersonalization;
|
|
80
|
+
/** The messages an agent was to write to them first, sent or still waiting, newest `send_at` first. */
|
|
81
|
+
scheduled_messages: ScheduledMessage[];
|
|
66
82
|
}
|
|
67
83
|
/** A fact `facts.add` answered, and whether this call made it. */
|
|
68
84
|
export type FactAdded = FactInfo & {
|
|
@@ -105,7 +105,15 @@ export class EndUsers extends Editable {
|
|
|
105
105
|
create: (id, body, options) => this.send("POST", this.at(id, "/scheduled-messages"), options, body),
|
|
106
106
|
list: (id, params = {}, options) => this.each(this.at(id, "/scheduled-messages"), params, options, PAGE),
|
|
107
107
|
get: (id, messageId, options) => this.send("GET", message(id, messageId), options),
|
|
108
|
-
|
|
108
|
+
// Sent once: cancelled, its answer lost, a second send is a 409 —
|
|
109
|
+
// "no longer waiting" — for a message this very call cancelled.
|
|
110
|
+
cancel: (id, messageId, options) => this.api
|
|
111
|
+
.request({
|
|
112
|
+
method: "DELETE",
|
|
113
|
+
path: this.base + message(id, messageId),
|
|
114
|
+
idempotent: false,
|
|
115
|
+
}, options)
|
|
116
|
+
.then((answer) => answer.data),
|
|
109
117
|
};
|
|
110
118
|
}
|
|
111
119
|
/**
|
|
@@ -198,11 +206,26 @@ export class EndUsers extends Editable {
|
|
|
198
206
|
limit: MEMORY_PAGE,
|
|
199
207
|
cursor,
|
|
200
208
|
})));
|
|
209
|
+
const relations = await all(pages((cursor) => read("/v1/agent/relations", { limit: PAGE, cursor })));
|
|
210
|
+
// Their own record, and what your server set, scheduled and was
|
|
211
|
+
// sent about them: the API key's to read, by the id the key named.
|
|
212
|
+
const person = key.end_user_id ?? id;
|
|
213
|
+
const [end_user, personalization, reports, scheduled_messages] = await Promise.all([
|
|
214
|
+
this.get(person, options),
|
|
215
|
+
this.personalization.get(person, options),
|
|
216
|
+
all(this.reports.list(person, {}, options)),
|
|
217
|
+
all(this.scheduledMessages.list(person, {}, options)),
|
|
218
|
+
]);
|
|
201
219
|
return {
|
|
202
|
-
end_user_id:
|
|
220
|
+
end_user_id: person,
|
|
221
|
+
end_user,
|
|
203
222
|
sessions,
|
|
204
223
|
facts,
|
|
205
224
|
memories,
|
|
225
|
+
relations,
|
|
226
|
+
reports,
|
|
227
|
+
personalization,
|
|
228
|
+
scheduled_messages,
|
|
206
229
|
};
|
|
207
230
|
}
|
|
208
231
|
finally {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* - **`images` also drafts a layout and finds an image's elements**
|
|
18
18
|
* (`Images`): answered at once, nothing queued.
|
|
19
19
|
*/
|
|
20
|
-
import { poll } from "../wait.js";
|
|
20
|
+
import { keeping, poll } from "../wait.js";
|
|
21
21
|
import { Polled } from "./resource.js";
|
|
22
22
|
/** The route's largest page. */
|
|
23
23
|
const PAGE = 100;
|
|
@@ -30,7 +30,7 @@ export class Jobs extends Polled {
|
|
|
30
30
|
/** Creates it and waits: the generation once it is final. */
|
|
31
31
|
async generate(body, options) {
|
|
32
32
|
const job = await this.create(body, options);
|
|
33
|
-
return poll(() => this.get(job.id, options), options, job);
|
|
33
|
+
return keeping(job, poll(() => this.get(job.id, options), options, job));
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* already gone.
|
|
17
17
|
*/
|
|
18
18
|
import { put, sizeOf, typeOf, } from "../upload.js";
|
|
19
|
+
import { keeping } from "../wait.js";
|
|
19
20
|
import { Waitable } from "./resource.js";
|
|
20
21
|
/** The route's largest page. */
|
|
21
22
|
const PAGE = 200;
|
|
@@ -56,8 +57,9 @@ export class Knowledge extends Waitable {
|
|
|
56
57
|
size_bytes: sizeOf(file, options.size) ?? null,
|
|
57
58
|
content_type: typeOf(file, content_type) || null,
|
|
58
59
|
}, options);
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
const { upload_id } = ticket;
|
|
61
|
+
const entry = await keeping({ upload_id }, put(this.api, ticket, file, ticket.content_type, options).then(() => this.fromFile({ ...body, upload_id }, options)));
|
|
62
|
+
return this.settled(entry, options);
|
|
61
63
|
}
|
|
62
64
|
/** Indexes the body it has again. */
|
|
63
65
|
reindex(id, options) {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
*/
|
|
26
26
|
import { pages } from "../paging.js";
|
|
27
27
|
import { orNull, segment, } from "../transport.js";
|
|
28
|
-
import { poll } from "../wait.js";
|
|
28
|
+
import { keeping, poll } from "../wait.js";
|
|
29
29
|
export class Resource {
|
|
30
30
|
constructor(api, base) {
|
|
31
31
|
this.api = api;
|
|
@@ -82,7 +82,7 @@ export class Waitable extends Editable {
|
|
|
82
82
|
/** `item` as made, or as it ended when `options.wait` says to wait. */
|
|
83
83
|
async settled(item, options) {
|
|
84
84
|
return options.wait
|
|
85
|
-
? poll(() => this.get(item.id, options), options, item)
|
|
85
|
+
? keeping(item, poll(() => this.get(item.id, options), options, item))
|
|
86
86
|
: item;
|
|
87
87
|
}
|
|
88
88
|
}
|
|
@@ -35,6 +35,19 @@ export interface Speech<Body> {
|
|
|
35
35
|
audioSeconds: number | null;
|
|
36
36
|
requestId: string;
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* The least these calls wait for their answer, in ms. **The API holds each
|
|
40
|
+
* open past the client's 30 s**: a transcript 95 s, speech made whole 65 s,
|
|
41
|
+
* a voice designed 80 s (`apps/api/src/speech/`) — each here with room for
|
|
42
|
+
* the answer to arrive. Hung up on at 30 s, the work went on and was
|
|
43
|
+
* charged, and its answer was lost: a POST is not sent again.
|
|
44
|
+
* `apps/api/test/sdk.test.ts` holds each above the API's own.
|
|
45
|
+
*/
|
|
46
|
+
export declare const SPEECH_WAIT_MS: {
|
|
47
|
+
readonly stt: 100000;
|
|
48
|
+
readonly tts: 70000;
|
|
49
|
+
readonly design: 90000;
|
|
50
|
+
};
|
|
38
51
|
export declare class Tts extends Resource {
|
|
39
52
|
/** The audio as it is made: `pcm` only. */
|
|
40
53
|
create(body: TtsRequest & {
|
|
@@ -44,6 +57,8 @@ export declare class Tts extends Resource {
|
|
|
44
57
|
create(body: TtsRequest & {
|
|
45
58
|
stream?: false;
|
|
46
59
|
}, options?: RequestOptions): Promise<Speech<ArrayBuffer>>;
|
|
60
|
+
/** Either, for a body whose `stream` is not known until it runs. */
|
|
61
|
+
create(body: TtsRequest, options?: RequestOptions): Promise<Speech<ArrayBuffer | ReadableStream<Uint8Array>>>;
|
|
47
62
|
}
|
|
48
63
|
/** The options `/v1/stt` takes, and the audio's type when it is no `Blob`'s. */
|
|
49
64
|
export type SttParams = Omit<TranscribeData["body"], "file"> & {
|
|
@@ -66,4 +81,6 @@ export declare class Stt extends Resource {
|
|
|
66
81
|
create(audio: UploadData, params?: SttParams & {
|
|
67
82
|
stream?: false;
|
|
68
83
|
}, options?: RequestOptions): Promise<Transcript>;
|
|
84
|
+
/** Either, for options whose `stream` is not known until it runs. */
|
|
85
|
+
create(audio: UploadData, params: SttParams, options?: RequestOptions): Promise<Transcript> | AsyncGenerator<SttEvent, void, undefined>;
|
|
69
86
|
}
|
package/dist/resources/speech.js
CHANGED
|
@@ -22,6 +22,19 @@ import { typeOf } from "../upload.js";
|
|
|
22
22
|
import { Resource } from "./resource.js";
|
|
23
23
|
/** The rate a streamed `pcm` is spoken at when the request named none. */
|
|
24
24
|
const DEFAULT_SAMPLE_RATE = 24_000;
|
|
25
|
+
/**
|
|
26
|
+
* The least these calls wait for their answer, in ms. **The API holds each
|
|
27
|
+
* open past the client's 30 s**: a transcript 95 s, speech made whole 65 s,
|
|
28
|
+
* a voice designed 80 s (`apps/api/src/speech/`) — each here with room for
|
|
29
|
+
* the answer to arrive. Hung up on at 30 s, the work went on and was
|
|
30
|
+
* charged, and its answer was lost: a POST is not sent again.
|
|
31
|
+
* `apps/api/test/sdk.test.ts` holds each above the API's own.
|
|
32
|
+
*/
|
|
33
|
+
export const SPEECH_WAIT_MS = {
|
|
34
|
+
stt: 100_000,
|
|
35
|
+
tts: 70_000,
|
|
36
|
+
design: 90_000,
|
|
37
|
+
};
|
|
25
38
|
export class Tts extends Resource {
|
|
26
39
|
async create(body, options) {
|
|
27
40
|
const answer = await this.api.request({
|
|
@@ -29,6 +42,8 @@ export class Tts extends Resource {
|
|
|
29
42
|
path: this.base,
|
|
30
43
|
body,
|
|
31
44
|
read: body.stream ? "stream" : "bytes",
|
|
45
|
+
// A stream's timer ends at its headers, which come at once.
|
|
46
|
+
...(body.stream ? {} : { waitMs: SPEECH_WAIT_MS.tts }),
|
|
32
47
|
}, options);
|
|
33
48
|
const header = (name) => answer.headers.get(name);
|
|
34
49
|
const seconds = header("x-audio-seconds");
|
|
@@ -51,6 +66,8 @@ export class Stt extends Resource {
|
|
|
51
66
|
query: query,
|
|
52
67
|
raw: audio,
|
|
53
68
|
type: typeOf(audio, content_type) || "application/octet-stream",
|
|
69
|
+
// The upload is on this timer too, streamed or whole.
|
|
70
|
+
waitMs: SPEECH_WAIT_MS.stt,
|
|
54
71
|
};
|
|
55
72
|
if (!params.stream) {
|
|
56
73
|
return this.api.request(call, options).then((a) => a.data);
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* URLs already name each file and its `v`, which makes it cacheable.
|
|
13
13
|
*/
|
|
14
14
|
import { segment } from "../transport.js";
|
|
15
|
-
import { poll } from "../wait.js";
|
|
15
|
+
import { keeping, poll } from "../wait.js";
|
|
16
16
|
import { Readable } from "./resource.js";
|
|
17
17
|
/** `get(id)` answers one with its inputs, frozen parameters and price. */
|
|
18
18
|
export class Templates extends Readable {
|
|
@@ -35,7 +35,7 @@ export class Templates extends Readable {
|
|
|
35
35
|
/** Generates from it and waits: the generation once it is final. */
|
|
36
36
|
async generate(id, body = {}, options) {
|
|
37
37
|
const job = await this.create(id, body, options);
|
|
38
|
-
return poll(() => this.generations.get(job.id, options), options, job);
|
|
38
|
+
return keeping(job, poll(() => this.generations.get(job.id, options), options, job));
|
|
39
39
|
}
|
|
40
40
|
/** A template's picture — `example`, or `input-<slot>` — with no key. */
|
|
41
41
|
async file(id, name, params = {}, options) {
|
package/dist/resources/voices.js
CHANGED
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
* - **`list()` reads one page**: the route answers every voice in it.
|
|
15
15
|
*/
|
|
16
16
|
import { needType, put, } from "../upload.js";
|
|
17
|
+
import { keeping } from "../wait.js";
|
|
17
18
|
import { WaitableLibrary } from "./resource.js";
|
|
19
|
+
import { SPEECH_WAIT_MS } from "./speech.js";
|
|
18
20
|
/**
|
|
19
21
|
* `update` renames a voice, or changes its description or defaults;
|
|
20
22
|
* `list()` is every voice this organisation may speak with; `create(body)`
|
|
@@ -29,8 +31,9 @@ export class Voices extends WaitableLibrary {
|
|
|
29
31
|
async upload(recording, fields, options = {}) {
|
|
30
32
|
const { content_type, ...body } = fields;
|
|
31
33
|
const ticket = await this.uploadUrl({ content_type: needType(recording, content_type) }, options);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
const { upload_id } = ticket;
|
|
35
|
+
const voice = await keeping({ upload_id }, put(this.api, ticket, recording, ticket.content_type, options).then(() => this.create({ ...body, upload_id }, options)));
|
|
36
|
+
return this.settled(voice, options);
|
|
34
37
|
}
|
|
35
38
|
/** Speaks its samples again, one per model. */
|
|
36
39
|
resample(id, options) {
|
|
@@ -38,7 +41,15 @@ export class Voices extends WaitableLibrary {
|
|
|
38
41
|
}
|
|
39
42
|
/** Previews of a voice made from a description; charged. */
|
|
40
43
|
design(body, options) {
|
|
41
|
-
|
|
44
|
+
// Tens of seconds of the provider's work, held open by the API.
|
|
45
|
+
return this.api
|
|
46
|
+
.request({
|
|
47
|
+
method: "POST",
|
|
48
|
+
path: `${this.base}/design`,
|
|
49
|
+
body,
|
|
50
|
+
waitMs: SPEECH_WAIT_MS.design,
|
|
51
|
+
}, options)
|
|
52
|
+
.then((answer) => answer.data);
|
|
42
53
|
}
|
|
43
54
|
/** Keeps one preview as a voice: `pending` at once. */
|
|
44
55
|
saveDesign(body, options) {
|
package/dist/transport.d.ts
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
export type Fetch = (url: string, init: RequestInit) => Promise<Response>;
|
|
3
3
|
/** Options any call takes, in its last argument. */
|
|
4
4
|
export interface RequestOptions {
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Per attempt; the client's `timeoutMs` (30 s) by default — longer for
|
|
7
|
+
* the few calls the API itself holds open past that, which say so.
|
|
8
|
+
*/
|
|
6
9
|
timeoutMs?: number;
|
|
7
10
|
/** Aborts the call, its retries and their waits. */
|
|
8
11
|
signal?: AbortSignal;
|
|
@@ -36,10 +39,20 @@ export interface Call {
|
|
|
36
39
|
read?: "bytes" | "stream";
|
|
37
40
|
/** No credential: the open routes, and object storage's signed URLs. */
|
|
38
41
|
open?: boolean;
|
|
39
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* `true`: a POST that may be sent twice with the same effect. `false`: a
|
|
44
|
+
* call of another method that may not — sent again, it answers
|
|
45
|
+
* differently from its first, as a cancel of what is cancelled does.
|
|
46
|
+
*/
|
|
40
47
|
idempotent?: boolean;
|
|
41
48
|
/** Another bearer for this call: an end user's ephemeral key. */
|
|
42
49
|
token?: string;
|
|
50
|
+
/**
|
|
51
|
+
* The least an attempt waits, for a call the API itself holds open
|
|
52
|
+
* longer than the client's `timeoutMs`: the larger of the two, unless
|
|
53
|
+
* the caller gave this call a `timeoutMs` of its own.
|
|
54
|
+
*/
|
|
55
|
+
waitMs?: number;
|
|
43
56
|
}
|
|
44
57
|
export interface Answer<T> {
|
|
45
58
|
data: T;
|
|
@@ -51,6 +64,15 @@ export interface Answer<T> {
|
|
|
51
64
|
export declare const MAX_RETRY_AFTER_S = 60;
|
|
52
65
|
/** A path parameter or a query's value, encoded: an `external_id` may hold `/` or `?`. */
|
|
53
66
|
export declare const segment: (value: string | number | boolean) => string;
|
|
67
|
+
/**
|
|
68
|
+
* `path`, or a `TypeError` when one of its parts is empty, `.` or `..` —
|
|
69
|
+
* an id that came out empty, or as dots, which no encoding can hide.
|
|
70
|
+
* **Such a path names another route**: `fetch` folds `..` away, and an
|
|
71
|
+
* empty last part is a trailing slash, which the API reads as none — so
|
|
72
|
+
* deleting the memory `""` deleted every memory, and the fact `".."` the
|
|
73
|
+
* person. Refused here, before anything is sent.
|
|
74
|
+
*/
|
|
75
|
+
export declare function routed(method: string, path: string): string;
|
|
54
76
|
/**
|
|
55
77
|
* A request id of the API's own shape: 16 hex. From `Math.random`, not
|
|
56
78
|
* `crypto`, which React Native lacks (this file is the client SDK's too):
|
|
@@ -59,7 +81,8 @@ export declare const segment: (value: string | number | boolean) => string;
|
|
|
59
81
|
export declare const newRequestId: () => string;
|
|
60
82
|
/**
|
|
61
83
|
* How long to wait before retry `attempt` (1, 2, …): the doubling backoff
|
|
62
|
-
* less up to a quarter, or `Retry-After`'s seconds
|
|
84
|
+
* less up to a quarter, or `Retry-After`'s seconds, and up to a tenth
|
|
85
|
+
* more, when the API sent one.
|
|
63
86
|
*/
|
|
64
87
|
export declare function retryDelayMs(attempt: number, retryAfter: number | null, random?: () => number): number;
|
|
65
88
|
/** Waits `ms`, or rejects with the signal's reason when it aborts first. */
|
package/dist/transport.js
CHANGED
|
@@ -20,7 +20,10 @@
|
|
|
20
20
|
* 504. A POST: only a 429, which the API answers at admission before any
|
|
21
21
|
* work — unless the method says the POST is idempotent
|
|
22
22
|
* (`POST /v1/end-users` with an `external_id`). Never a 500: whatever
|
|
23
|
-
* failed may have half-happened.
|
|
23
|
+
* failed may have half-happened. **Nor what a second send would answer
|
|
24
|
+
* differently** than its first, whatever its method: a change that
|
|
25
|
+
* names the version it expects (`versioned`), a cancel
|
|
26
|
+
* (`idempotent: false`).
|
|
24
27
|
* - **The wait** doubles from 0.5 s to 8 s, less up to a quarter at random
|
|
25
28
|
* so callers refused together do not return together; `Retry-After`
|
|
26
29
|
* wins, up to a minute. A longer one is thrown at once as a
|
|
@@ -39,6 +42,46 @@ const MAX_DELAY_MS = 8_000;
|
|
|
39
42
|
export const MAX_RETRY_AFTER_S = 60;
|
|
40
43
|
/** A path parameter or a query's value, encoded: an `external_id` may hold `/` or `?`. */
|
|
41
44
|
export const segment = (value) => encodeURIComponent(value);
|
|
45
|
+
/**
|
|
46
|
+
* A count or a time the caller set, or a `TypeError`: a number that is one.
|
|
47
|
+
* `maxRetries: Number(process.env.RETRIES)` with the variable unset is
|
|
48
|
+
* `NaN`, which no attempt is ever past — a refusal that kept coming was
|
|
49
|
+
* retried without end; and a `timeoutMs` that is `NaN`, 0 or `Infinity`
|
|
50
|
+
* is a timer that fires at once.
|
|
51
|
+
*/
|
|
52
|
+
function numbered(name, value, least) {
|
|
53
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < least) {
|
|
54
|
+
throw new TypeError(`${name} must be a number of ${least} or more: it is ${value}.`);
|
|
55
|
+
}
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Whether a body names the version it expects to change. **Such a change
|
|
60
|
+
* is sent once**: applied, its answer lost on the way, a second send
|
|
61
|
+
* finds the version moved by the first and is answered "changed since" —
|
|
62
|
+
* a conflict with itself, read as someone else's edit having won.
|
|
63
|
+
*/
|
|
64
|
+
const versioned = (body) => typeof body === "object" &&
|
|
65
|
+
body !== null &&
|
|
66
|
+
body.expected_version != null;
|
|
67
|
+
/**
|
|
68
|
+
* `path`, or a `TypeError` when one of its parts is empty, `.` or `..` —
|
|
69
|
+
* an id that came out empty, or as dots, which no encoding can hide.
|
|
70
|
+
* **Such a path names another route**: `fetch` folds `..` away, and an
|
|
71
|
+
* empty last part is a trailing slash, which the API reads as none — so
|
|
72
|
+
* deleting the memory `""` deleted every memory, and the fact `".."` the
|
|
73
|
+
* person. Refused here, before anything is sent.
|
|
74
|
+
*/
|
|
75
|
+
export function routed(method, path) {
|
|
76
|
+
if (/^https?:/.test(path))
|
|
77
|
+
return path;
|
|
78
|
+
for (const part of path.split("/").slice(1)) {
|
|
79
|
+
if (part === "" || part === "." || part === "..") {
|
|
80
|
+
throw new TypeError(`An id in this call is empty, "." or "..", so its path would name another route: ${method} ${path}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return path;
|
|
84
|
+
}
|
|
42
85
|
/**
|
|
43
86
|
* A request id of the API's own shape: 16 hex. From `Math.random`, not
|
|
44
87
|
* `crypto`, which React Native lacks (this file is the client SDK's too):
|
|
@@ -47,11 +90,15 @@ export const segment = (value) => encodeURIComponent(value);
|
|
|
47
90
|
export const newRequestId = () => "x".repeat(16).replace(/x/g, () => ((Math.random() * 16) | 0).toString(16));
|
|
48
91
|
/**
|
|
49
92
|
* How long to wait before retry `attempt` (1, 2, …): the doubling backoff
|
|
50
|
-
* less up to a quarter, or `Retry-After`'s seconds
|
|
93
|
+
* less up to a quarter, or `Retry-After`'s seconds, and up to a tenth
|
|
94
|
+
* more, when the API sent one.
|
|
51
95
|
*/
|
|
52
96
|
export function retryDelayMs(attempt, retryAfter, random = Math.random) {
|
|
53
|
-
|
|
54
|
-
|
|
97
|
+
// Up to a tenth more, at random: the API sends `Retry-After` on every
|
|
98
|
+
// 429, so callers refused together slept exactly, and returned together.
|
|
99
|
+
if (retryAfter !== null) {
|
|
100
|
+
return Math.ceil(retryAfter * 1000 * (1 + 0.1 * random()));
|
|
101
|
+
}
|
|
55
102
|
const full = Math.min(MAX_DELAY_MS, BASE_DELAY_MS * 2 ** (attempt - 1));
|
|
56
103
|
return Math.round(full * (1 - 0.25 * random()));
|
|
57
104
|
}
|
|
@@ -99,6 +146,8 @@ export const orNull = (promise) => promise.catch((error) => {
|
|
|
99
146
|
});
|
|
100
147
|
export class Transport {
|
|
101
148
|
constructor(config) {
|
|
149
|
+
numbered("timeoutMs", config.timeoutMs, 1);
|
|
150
|
+
numbered("maxRetries", config.maxRetries, 0);
|
|
102
151
|
this.config = config;
|
|
103
152
|
}
|
|
104
153
|
/** A JSON call's answer: `data` is a GET's query and any other's body. */
|
|
@@ -114,7 +163,14 @@ export class Transport {
|
|
|
114
163
|
const maxRetries = once
|
|
115
164
|
? 0
|
|
116
165
|
: (options.maxRetries ?? this.config.maxRetries);
|
|
117
|
-
|
|
166
|
+
if (options.timeoutMs !== undefined) {
|
|
167
|
+
numbered("timeoutMs", options.timeoutMs, 1);
|
|
168
|
+
}
|
|
169
|
+
if (options.maxRetries !== undefined) {
|
|
170
|
+
numbered("maxRetries", options.maxRetries, 0);
|
|
171
|
+
}
|
|
172
|
+
const retriesAll = call.idempotent ?? (call.method !== "POST" && !versioned(call.body));
|
|
173
|
+
const timeoutMs = options.timeoutMs ?? Math.max(this.config.timeoutMs, call.waitMs ?? 0);
|
|
118
174
|
const url = this.url(call);
|
|
119
175
|
const headers = {
|
|
120
176
|
Accept: call.read ? "*/*" : "application/json",
|
|
@@ -136,7 +192,7 @@ export class Transport {
|
|
|
136
192
|
if (once)
|
|
137
193
|
Object.assign(init, { duplex: "half" });
|
|
138
194
|
for (let attempt = 0;; attempt++) {
|
|
139
|
-
const outcome = await this.attempt(url, init, call.read, options);
|
|
195
|
+
const outcome = await this.attempt(url, init, call.read, options.signal, timeoutMs);
|
|
140
196
|
const last = attempt >= maxRetries;
|
|
141
197
|
if (outcome.kind === "response") {
|
|
142
198
|
const { response, body: read } = outcome;
|
|
@@ -147,7 +203,9 @@ export class Transport {
|
|
|
147
203
|
: parsed(read, response.status, requestId),
|
|
148
204
|
status: response.status,
|
|
149
205
|
headers: response.headers,
|
|
150
|
-
|
|
206
|
+
// The API's own for it: it replaces an id it does not take, and
|
|
207
|
+
// the one sent then names a request in no log.
|
|
208
|
+
requestId: response.headers.get("x-request-id") ?? requestId,
|
|
151
209
|
};
|
|
152
210
|
}
|
|
153
211
|
const error = errorFromResponse(response.status, response.headers, read, requestId);
|
|
@@ -186,21 +244,21 @@ export class Transport {
|
|
|
186
244
|
query += `${query ? "&" : "?"}${key}=${segment(value)}`;
|
|
187
245
|
}
|
|
188
246
|
}
|
|
189
|
-
const
|
|
190
|
-
|
|
247
|
+
const path = routed(call.method, call.path);
|
|
248
|
+
const base = /^https?:/.test(path) ? "" : this.config.baseUrl;
|
|
249
|
+
return base + path + query;
|
|
191
250
|
}
|
|
192
251
|
/**
|
|
193
252
|
* One send and its body read, under this attempt's timer — which stops
|
|
194
253
|
* at the headers of a stream the caller reads (and of nothing else).
|
|
195
254
|
*/
|
|
196
|
-
async attempt(url, init, read,
|
|
255
|
+
async attempt(url, init, read, signal, timeoutMs) {
|
|
197
256
|
// The caller's signal joined to the timer by hand, its reason carried
|
|
198
257
|
// over: `AbortSignal.any` is not React Native's. Left joined for a
|
|
199
258
|
// stream, whose body the caller's abort still ends.
|
|
200
|
-
const { signal } = options;
|
|
201
259
|
const timer = new AbortController();
|
|
202
260
|
const stop = () => timer.abort(signal?.reason);
|
|
203
|
-
const clock = setTimeout(stop,
|
|
261
|
+
const clock = setTimeout(stop, timeoutMs);
|
|
204
262
|
signal?.addEventListener("abort", stop);
|
|
205
263
|
// Already aborted: no event will come, and `fetch` sends nothing.
|
|
206
264
|
if (signal?.aborted)
|
package/dist/wait.d.ts
CHANGED
|
@@ -27,6 +27,22 @@
|
|
|
27
27
|
* DO's trigger in the root `CLAUDE.md`; in their first second, 250 are.
|
|
28
28
|
*/
|
|
29
29
|
import { type RequestOptions } from "./transport.js";
|
|
30
|
+
/** What a call had made when it failed after making it: a job's or a file's `id`, or an upload's. */
|
|
31
|
+
export interface Made {
|
|
32
|
+
id?: string;
|
|
33
|
+
upload_id?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* `work`, and when it fails its error told what was made before it.
|
|
37
|
+
* **A call that makes something and then waits loses nothing by
|
|
38
|
+
* failing**: `generate()` whose wait is aborted, or meets one bad poll,
|
|
39
|
+
* threw an error that named no job — charged, still running, and with an
|
|
40
|
+
* id only a local had; an upload whose last step timed out, a file with
|
|
41
|
+
* no name to confirm again. `madeBy(error)` reads it back.
|
|
42
|
+
*/
|
|
43
|
+
export declare function keeping<T>(made: Made, work: Promise<T>): Promise<T>;
|
|
44
|
+
/** What the call that threw `error` had already made: `{ id }` of a job or a file, `{ upload_id }` of an upload not yet named, or `null`. */
|
|
45
|
+
export declare function madeBy(error: unknown): Made | null;
|
|
30
46
|
/** A job as each kind's read answers it: with its `status`. */
|
|
31
47
|
export interface Job {
|
|
32
48
|
status: string;
|
package/dist/wait.js
CHANGED
|
@@ -36,6 +36,42 @@ const IN_PROGRESS = [
|
|
|
36
36
|
];
|
|
37
37
|
const FIRST_MS = 1_000;
|
|
38
38
|
const MAX_MS = 10_000;
|
|
39
|
+
/**
|
|
40
|
+
* `work`, and when it fails its error told what was made before it.
|
|
41
|
+
* **A call that makes something and then waits loses nothing by
|
|
42
|
+
* failing**: `generate()` whose wait is aborted, or meets one bad poll,
|
|
43
|
+
* threw an error that named no job — charged, still running, and with an
|
|
44
|
+
* id only a local had; an upload whose last step timed out, a file with
|
|
45
|
+
* no name to confirm again. `madeBy(error)` reads it back.
|
|
46
|
+
*/
|
|
47
|
+
export async function keeping(made, work) {
|
|
48
|
+
try {
|
|
49
|
+
return await work;
|
|
50
|
+
}
|
|
51
|
+
catch (failure) {
|
|
52
|
+
throw saying(failure, made);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** `failure` itself, saying what was made, where it can carry it — the caller's own reason is thrown as it is — else an `Error` of it. */
|
|
56
|
+
function saying(failure, made) {
|
|
57
|
+
const told = { value: made, configurable: true };
|
|
58
|
+
if (typeof failure === "object" && failure !== null) {
|
|
59
|
+
try {
|
|
60
|
+
return Object.defineProperty(failure, "made", told);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
// swallowed: a frozen reason of the caller's — wrapped below.
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return Object.defineProperty(new Error(String(failure), { cause: failure }), "made", told);
|
|
67
|
+
}
|
|
68
|
+
/** What the call that threw `error` had already made: `{ id }` of a job or a file, `{ upload_id }` of an upload not yet named, or `null`. */
|
|
69
|
+
export function madeBy(error) {
|
|
70
|
+
return ((typeof error === "object" &&
|
|
71
|
+
error !== null &&
|
|
72
|
+
error.made) ||
|
|
73
|
+
null);
|
|
74
|
+
}
|
|
39
75
|
/**
|
|
40
76
|
* Reads `read` until its status is final — or until `pending` says it no
|
|
41
77
|
* longer is, for what is not a job (a revoked key's settlement) —
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lumavox/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.48.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",
|
|
@@ -13,6 +13,21 @@
|
|
|
13
13
|
"sideEffects": [
|
|
14
14
|
"./dist/refuse.js"
|
|
15
15
|
],
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"homepage": "https://docs.lumavox.ai/sdks/server",
|
|
19
|
+
"keywords": [
|
|
20
|
+
"lumavox",
|
|
21
|
+
"voice",
|
|
22
|
+
"agents",
|
|
23
|
+
"text-to-speech",
|
|
24
|
+
"speech-to-text",
|
|
25
|
+
"sdk"
|
|
26
|
+
],
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public",
|
|
29
|
+
"tag": "next"
|
|
30
|
+
},
|
|
16
31
|
"exports": {
|
|
17
32
|
".": {
|
|
18
33
|
"types": "./dist/index.d.ts",
|