realtime-avatar 0.39.0 → 0.40.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 CHANGED
@@ -259,24 +259,6 @@ and fetch, including a pending `next()`. The smaller of `timeoutMs` and `totalTi
259
259
  covers the entire request/body, including pauses between iterations. **Never automatically
260
260
  retry** an ambiguous paid request. Cancellation does not prove that billing stopped.
261
261
 
262
- ### Live speech session
263
-
264
- `openSpeechSession(voiceId, { maxTextBytes, latency?, chunkLength?, language? }, { signal? })`
265
- opens `GET /voices/{voiceId}/speech/live` as a WebSocket and resolves once the platform admitted
266
- the session, so every refusal rejects the promise. Send `text(utterance, text)` (utterance 0 first,
267
- at most `chunkLength` characters each), `flush(utterance)` to speak it and open the next, `end()`
268
- and `cancel()`. Iterate it once for `started`, per-utterance `audio` (`sampleOffset` from the
269
- utterance's start), `alignment` (replaces that utterance's snapshot, may arrive late) and
270
- `utterance-end`, then one `completed` or `failed`. Frames are validated by the generated
271
- `speechLiveClientMessageSchema` and `speechLiveServerMessageSchema` in both directions;
272
- non-contiguous audio or a skipped utterance fails the session.
273
-
274
- Billing is for the UTF-8 bytes sent: cancel, disconnect, `break` and abort still bill them, and a
275
- provider failure refunds. Never retried. In Workers the upgrade is a `fetch` with the
276
- `Authorization` header and a refusal is a `RealtimeAvatarHttpError`; in Node 22 it is the global
277
- `WebSocket`, which reports no status, so a refusal is a `RealtimeAvatarError`. `timeoutMs` bounds
278
- opening and `totalTimeoutMs`, if set, the whole session.
279
-
280
262
  ## Custom voice (webhook)
281
263
 
282
264
  Speak a call in your own voice. Each sentence she is about to say is POSTed, signed, to an
@@ -500,8 +482,6 @@ rta.getConnectionHistory(sessionId) // bounded LiveKit observations; requires
500
482
  rta.createSpeech(voiceId, { text, format?, speed?, language? }, { signal? })
501
483
  // unreleased streaming candidate; generated SSE events, never retried
502
484
  rta.createSpeechStream(voiceId, { text, speed?, language? }, { signal? })
503
- // live session: text in while it is written, PCM + alignment per utterance; WebSocket, never retried
504
- rta.openSpeechSession(voiceId, { maxTextBytes, latency?, chunkLength?, language? }, { signal? })
505
485
 
506
486
  // pre-rendered video (MP4, no live call); server only, requires renders:write / renders:read
507
487
  rta.createRender({ avatarId, voiceId? | voice?, lipGain?, shots }) // 202 queued; one Idempotency-Key across retries
@@ -942,74 +942,12 @@ var schema51 = z.strictObject({
942
942
  "error": schema50
943
943
  });
944
944
  var schema522 = z.union([schema202, schema252, schema292, schema332, schema51]);
945
- var schema532 = z.int().min(100).max(300);
946
- var schema542 = z.int().min(1).max(6e3);
947
- var schema552 = z.literal("text");
948
- var schema562 = z.int().min(0).max(127);
949
- var schema57 = z.string().min(1).max(300);
950
- var schema58 = z.strictObject({
951
- "type": schema552,
952
- "utterance": schema562,
953
- "text": schema57
954
- });
955
- var schema59 = z.literal("flush");
956
- var schema60 = z.strictObject({
957
- "type": schema59,
958
- "utterance": schema272
959
- });
960
- var schema61 = z.literal("end");
961
- var schema622 = z.strictObject({
962
- "type": schema61
963
- });
964
- var schema632 = z.literal("cancel");
965
- var schema642 = z.strictObject({
966
- "type": schema632
967
- });
968
- var schema65 = z.union([schema58, schema60, schema622, schema642]);
969
- var schema66 = z.int().min(0).max(432e4);
970
- var schema67 = z.strictObject({
971
- "requestId": schema154,
972
- "type": schema213,
973
- "utterance": schema272,
974
- "sampleOffset": schema66,
975
- "audioBase64": schema242
976
- });
977
- var schema68 = z.array(speechAlignedTextSchema).max(2048);
978
- var schema69 = z.strictObject({
979
- "requestId": schema154,
980
- "type": schema262,
981
- "utterance": schema272,
982
- "segments": schema68
983
- });
984
- var schema70 = z.literal("utterance-end");
985
- var schema71 = z.strictObject({
986
- "requestId": schema154,
987
- "type": schema70,
988
- "utterance": schema272,
989
- "samples": schema31
990
- });
991
- var schema722 = z.int().min(0).max(6e3);
992
- var schema732 = z.strictObject({
993
- "requestId": schema154,
994
- "type": schema30,
995
- "billedBytes": schema722,
996
- "billedCredits": schema64
997
- });
998
- var schema742 = z.union([schema202, schema67, schema69, schema71, schema732, schema51]);
999
945
  var createSpeechRequestSchema = schema47.extend({
1000
946
  format: schema47.shape.format.unwrap().default("mp3")
1001
947
  });
1002
948
  var createSpeechStreamRequestSchema = schema104;
1003
949
  var speechStreamEventSchema = schema522;
1004
950
  var SPEECH_STREAM_CONTRACT = { "maxAudioEventBytes": 16384, "maxSamples": 432e4};
1005
- var speechLiveOpenSchema = z.strictObject({
1006
- "language": schema37.optional(),
1007
- "latency": schema84.optional(),
1008
- "chunkLength": schema532.optional(),
1009
- "maxTextBytes": schema542
1010
- });
1011
- var speechLiveClientMessageSchema = schema65;
1012
- var speechLiveServerMessageSchema = schema742;
1013
951
  var speechVoiceIdSchema = schema56;
1014
952
  var speechContentTypeSchema = z.enum(["audio/mpeg", "audio/wav"]);
1015
953
  var speechResponseHeadersSchema = z.strictObject({
@@ -1063,13 +1001,13 @@ var schema119 = z.custom((value) => typeof value === "object" && value !== null
1063
1001
  var schema214 = z.enum(["cartesia", "fish"]);
1064
1002
  var schema310 = z.string().min(1).max(240);
1065
1003
  var schema410 = z.string().min(1).max(120);
1066
- var schema510 = z.number().min(0.5).max(2);
1067
- var schema610 = z.null();
1068
- var schema75 = z.union([schema510, schema610]);
1004
+ var schema57 = z.number().min(0.5).max(2);
1005
+ var schema65 = z.null();
1006
+ var schema75 = z.union([schema57, schema65]);
1069
1007
  var schema85 = z.string().min(1).max(80);
1070
- var schema95 = z.union([schema85, schema610]);
1008
+ var schema95 = z.union([schema85, schema65]);
1071
1009
  var schema105 = z.string().min(2).max(16);
1072
- var schema1110 = z.union([schema105, schema610]);
1010
+ var schema1110 = z.union([schema105, schema65]);
1073
1011
  var schema125 = z.strictObject({
1074
1012
  "provider": schema214,
1075
1013
  "voice_id": schema310,
@@ -1083,18 +1021,18 @@ var schema144 = z.string();
1083
1021
  var schema155 = z.enum(["video", "anima"]);
1084
1022
  var schema164 = z.enum(["image", "video"]);
1085
1023
  var schema174 = z.enum(["realtime-avatar-live-v1", "realtime-avatar-video-v1"]);
1086
- var schema184 = z.union([schema135, schema610]);
1024
+ var schema184 = z.union([schema135, schema65]);
1087
1025
  var schema194 = z.enum(["draft", "preprocessing", "ready", "failed", "disabled", "deleted"]);
1088
- var schema203 = z.union([schema144, schema610]);
1026
+ var schema203 = z.union([schema144, schema65]);
1089
1027
  var schema215 = z.enum(["none", "queued", "generating", "ready", "failed"]);
1090
1028
  var schema223 = z.enum(["local", "gemini", "openai"]);
1091
1029
  var schema233 = z.string().max(200);
1092
- var schema243 = z.union([schema233, schema610]);
1030
+ var schema243 = z.union([schema233, schema65]);
1093
1031
  var schema253 = z.strictObject({
1094
1032
  "provider": schema223,
1095
1033
  "model": schema243.optional()
1096
1034
  });
1097
- var schema263 = z.union([schema253, schema610]);
1035
+ var schema263 = z.union([schema253, schema65]);
1098
1036
  var schema273 = z.strictObject({
1099
1037
  "id": schema135,
1100
1038
  "tenantId": schema135,
@@ -1441,243 +1379,19 @@ async function* parseEvents(response, signal) {
1441
1379
  throw new RealtimeAvatarError(MISMATCH);
1442
1380
  }
1443
1381
  }
1444
-
1445
- // ../http-client/src/speech-session.ts
1446
- var MISMATCH2 = "Speech session message did not match the SDK contract";
1447
- var CLOSED = "Speech session is closed";
1448
- var UNOPENED = "Speech session could not be opened";
1449
- function isUpgradedSocket(value) {
1450
- return typeof value === "object" && value !== null && "accept" in value && typeof value.accept === "function" && "send" in value && typeof value.send === "function" && "close" in value && typeof value.close === "function" && "addEventListener" in value && typeof value.addEventListener === "function";
1451
- }
1452
- function connectStandardSocket(url, headers) {
1453
- if (typeof WebSocket === "undefined") {
1454
- throw new RealtimeAvatarError("openSpeechSession needs a global WebSocket (Node 22 or later) or Cloudflare Workers");
1455
- }
1456
- const target = new URL(url);
1457
- target.protocol = target.protocol === "http:" ? "ws:" : "wss:";
1458
- const socket = Reflect.construct(WebSocket, [target.href, { headers }]);
1459
- if (!(socket instanceof WebSocket)) throw new RealtimeAvatarError(UNOPENED);
1460
- const ready = new Promise((resolve, reject) => {
1461
- socket.addEventListener("open", () => resolve(), { once: true });
1462
- socket.addEventListener("error", () => reject(new RealtimeAvatarError(UNOPENED)), { once: true });
1463
- socket.addEventListener("close", () => reject(new RealtimeAvatarError(UNOPENED)), { once: true });
1464
- });
1465
- return { socket, ready };
1466
- }
1467
- async function openSpeechSocketSession(connect, timing, callerSignal) {
1468
- callerSignal?.throwIfAborted();
1469
- const handshake = new AbortController();
1470
- const timer = setTimeout(() => handshake.abort(new DOMException("The operation timed out.", "TimeoutError")), timing.handshakeMs);
1471
- const forward = () => handshake.abort(callerSignal?.reason);
1472
- callerSignal?.addEventListener("abort", forward, { once: true });
1473
- let connection;
1474
- try {
1475
- connection = await connect(handshake.signal);
1476
- const session = new LiveSession(connection.socket);
1477
- connection.socket.accept?.();
1478
- const opened = connection.ready;
1479
- opened.catch(() => {
1480
- });
1481
- await new Promise((resolve, reject) => {
1482
- const abort = () => reject(handshake.signal.reason);
1483
- if (handshake.signal.aborted) {
1484
- abort();
1485
- return;
1486
- }
1487
- handshake.signal.addEventListener("abort", abort, { once: true });
1488
- opened.then(resolve, reject).finally(() => handshake.signal.removeEventListener("abort", abort));
1489
- });
1490
- session.start(callerSignal, timing.sessionMs);
1491
- return session;
1492
- } catch (error) {
1493
- if (connection) closeQuietly(connection.socket);
1494
- callerSignal?.throwIfAborted();
1495
- throw error;
1496
- } finally {
1497
- clearTimeout(timer);
1498
- callerSignal?.removeEventListener("abort", forward);
1499
- }
1500
- }
1501
- function closeQuietly(socket) {
1502
- try {
1503
- socket.close(1e3);
1504
- } catch {
1505
- }
1506
- }
1507
- function messageText(event) {
1508
- if (typeof event !== "object" || event === null || !("data" in event)) return void 0;
1509
- return typeof event.data === "string" ? event.data : void 0;
1510
- }
1511
- var LiveSession = class {
1512
- #socket;
1513
- #queue = [];
1514
- #waiting;
1515
- #failure;
1516
- #over = false;
1517
- #iterated = false;
1518
- #stop;
1519
- // What has been received, checked against the order the platform promises.
1520
- #received = 0;
1521
- #requestId;
1522
- #terminal = false;
1523
- #ended = 0;
1524
- #open;
1525
- #samples = 0;
1526
- constructor(socket) {
1527
- this.#socket = socket;
1528
- socket.addEventListener("message", (event) => this.#receive(event));
1529
- socket.addEventListener("close", () => this.#closed());
1530
- socket.addEventListener("error", () => this.#closed());
1531
- }
1532
- start(signal, sessionMs) {
1533
- const stops = [];
1534
- if (signal) {
1535
- const abort = () => this.#fail(signal.reason);
1536
- signal.addEventListener("abort", abort, { once: true });
1537
- stops.push(() => signal.removeEventListener("abort", abort));
1538
- }
1539
- if (sessionMs !== void 0) {
1540
- const timer = setTimeout(() => this.#fail(new DOMException("The operation timed out.", "TimeoutError")), sessionMs);
1541
- stops.push(() => clearTimeout(timer));
1542
- }
1543
- this.#stop = () => {
1544
- for (const stop of stops) stop();
1545
- };
1546
- }
1547
- text(utterance, text) {
1548
- this.#send({ type: "text", utterance, text });
1549
- }
1550
- flush(utterance) {
1551
- this.#send({ type: "flush", utterance });
1552
- }
1553
- end() {
1554
- if (!this.#over) this.#send({ type: "end" });
1555
- }
1556
- cancel() {
1557
- if (!this.#over) this.#send({ type: "cancel" });
1558
- }
1559
- [Symbol.asyncIterator]() {
1560
- if (this.#iterated) throw new RealtimeAvatarError("A speech session can be iterated only once");
1561
- this.#iterated = true;
1562
- return {
1563
- next: () => this.#next(),
1564
- return: async () => {
1565
- if (!this.#over) {
1566
- this.cancel();
1567
- this.#finish();
1568
- }
1569
- this.#queue.length = 0;
1570
- return { value: void 0, done: true };
1571
- }
1572
- };
1573
- }
1574
- #send(message) {
1575
- const parsed = speechLiveClientMessageSchema.parse(message);
1576
- if (this.#over) throw new RealtimeAvatarError(CLOSED);
1577
- this.#socket.send(JSON.stringify(parsed));
1578
- }
1579
- #next() {
1580
- const message = this.#queue.shift();
1581
- if (message) return Promise.resolve({ value: message, done: false });
1582
- if (this.#failure) return Promise.reject(this.#failure.error);
1583
- if (this.#over) return Promise.resolve({ value: void 0, done: true });
1584
- return new Promise((resolve, reject) => {
1585
- this.#waiting = { resolve, reject };
1586
- });
1587
- }
1588
- #deliver(message) {
1589
- const waiting = this.#waiting;
1590
- this.#waiting = void 0;
1591
- if (waiting) waiting.resolve({ value: message, done: false });
1592
- else this.#queue.push(message);
1593
- }
1594
- /** Ends the session: no more messages are accepted and the socket is closed. */
1595
- #finish() {
1596
- if (this.#over) return;
1597
- this.#over = true;
1598
- this.#stop?.();
1599
- closeQuietly(this.#socket);
1600
- const waiting = this.#waiting;
1601
- this.#waiting = void 0;
1602
- if (!waiting) return;
1603
- if (this.#failure) waiting.reject(this.#failure.error);
1604
- else waiting.resolve({ value: void 0, done: true });
1605
- }
1606
- #fail(error) {
1607
- if (this.#over) return;
1608
- this.#failure = { error };
1609
- this.#queue.length = 0;
1610
- this.#finish();
1611
- }
1612
- #closed() {
1613
- if (!this.#terminal) this.#fail(new RealtimeAvatarError("Speech session closed before it completed"));
1614
- this.#finish();
1615
- }
1616
- #receive(event) {
1617
- if (this.#over) return;
1618
- try {
1619
- const data = messageText(event);
1620
- if (data === void 0 || this.#terminal || data.length > MAX_EVENT_BYTES) throw new RealtimeAvatarError(MISMATCH2);
1621
- this.#received += data.length;
1622
- if (this.#received > MAX_WIRE_BYTES) throw new RealtimeAvatarError(MISMATCH2);
1623
- const raw = JSON.parse(data);
1624
- const message = speechLiveServerMessageSchema.parse(raw);
1625
- this.#check(message);
1626
- this.#deliver(message);
1627
- if (this.#terminal) this.#finish();
1628
- } catch {
1629
- this.#fail(new RealtimeAvatarError(MISMATCH2));
1630
- }
1631
- }
1632
- #check(message) {
1633
- if (this.#requestId === void 0) {
1634
- if (message.type !== "started") throw new RealtimeAvatarError(MISMATCH2);
1635
- this.#requestId = message.requestId;
1636
- return;
1637
- }
1638
- if (message.type === "started" || message.requestId !== this.#requestId) throw new RealtimeAvatarError(MISMATCH2);
1639
- switch (message.type) {
1640
- case "audio": {
1641
- const bytes = atob(message.audioBase64).length;
1642
- if (bytes === 0 || bytes % 2 !== 0) throw new RealtimeAvatarError(MISMATCH2);
1643
- if (this.#open === void 0) {
1644
- if (message.utterance !== this.#ended || message.sampleOffset !== 0) throw new RealtimeAvatarError(MISMATCH2);
1645
- this.#open = message.utterance;
1646
- this.#samples = 0;
1647
- } else if (message.utterance !== this.#open || message.sampleOffset !== this.#samples) {
1648
- throw new RealtimeAvatarError(MISMATCH2);
1649
- }
1650
- this.#samples += bytes / 2;
1651
- return;
1652
- }
1653
- case "utterance-end":
1654
- if (message.utterance !== this.#open || message.samples !== this.#samples) throw new RealtimeAvatarError(MISMATCH2);
1655
- this.#open = void 0;
1656
- this.#ended++;
1657
- return;
1658
- case "alignment":
1659
- if (message.utterance > this.#ended) throw new RealtimeAvatarError(MISMATCH2);
1660
- return;
1661
- case "completed":
1662
- case "failed":
1663
- this.#terminal = true;
1664
- return;
1665
- }
1666
- }
1667
- };
1668
1382
  var schema010 = z.url().regex(new RegExp("^https:\\/\\/")).max(500);
1669
1383
  var schema120 = z.string().min(16).max(200);
1670
1384
  var schema216 = z.string().min(1).max(200);
1671
1385
  var schema311 = z.string().min(2).max(35);
1672
1386
  var schema411 = z.literal([8e3, 16e3, 22050, 24e3, 44100, 48e3]);
1673
- var schema511 = z.int().min(1e3).max(15e3);
1674
- var schema611 = z.strictObject({
1387
+ var schema58 = z.int().min(1e3).max(15e3);
1388
+ var schema66 = z.strictObject({
1675
1389
  "url": schema010,
1676
1390
  "secret": schema120,
1677
1391
  "voice_id": schema216.optional(),
1678
1392
  "language": schema311.optional(),
1679
1393
  "sample_rate": schema411.optional(),
1680
- "timeout_ms": schema511.optional()
1394
+ "timeout_ms": schema58.optional()
1681
1395
  });
1682
1396
  var schema76 = z.literal("voice.synthesize");
1683
1397
  var schema86 = z.literal(1);
@@ -1717,7 +1431,7 @@ var schema264 = z.object({
1717
1431
  "output": schema224,
1718
1432
  "client_metadata": schema254
1719
1433
  });
1720
- var voiceWebhookWireSchema = schema611;
1434
+ var voiceWebhookWireSchema = schema66;
1721
1435
  var voiceWebhookOptionsSchema = z.strictObject({
1722
1436
  url: voiceWebhookWireSchema.shape.url,
1723
1437
  secret: voiceWebhookWireSchema.shape.secret,
@@ -1745,8 +1459,8 @@ var schema312 = z.literal("external");
1745
1459
  var schema412 = z.strictObject({
1746
1460
  "renderer": schema312
1747
1461
  });
1748
- var schema512 = z.literal("v1");
1749
- var schema612 = z.literal("correlated_pcm_v1");
1462
+ var schema59 = z.literal("v1");
1463
+ var schema67 = z.literal("correlated_pcm_v1");
1750
1464
  var schema77 = z.literal("speech_segments_v1");
1751
1465
  var schema87 = z.literal("v1");
1752
1466
  var schema97 = z.literal(true);
@@ -1765,8 +1479,8 @@ var schema137 = z.strictObject({
1765
1479
  "token": schema121,
1766
1480
  "fail_closed": schema218.optional(),
1767
1481
  "visible_character": schema412.optional(),
1768
- "performance": schema512.optional(),
1769
- "audio_output": schema612.optional(),
1482
+ "performance": schema59.optional(),
1483
+ "audio_output": schema67.optional(),
1770
1484
  "text_output": schema77.optional()
1771
1485
  }).superRefine((value, ctx) => {
1772
1486
  if (value["audio_output"] !== void 0) {
@@ -1806,14 +1520,14 @@ var schema128 = z.enum(["eou", "llm", "tts", "decision", "hold", "e2e"]);
1806
1520
  var schema219 = z.literal("interrupt_stop");
1807
1521
  var schema313 = z.union([schema128, schema219]);
1808
1522
  var schema413 = z.int().max(9007199254740991).gt(0);
1809
- var schema513 = z.number().min(0);
1810
- var schema613 = z.strictObject({
1523
+ var schema510 = z.number().min(0);
1524
+ var schema68 = z.strictObject({
1811
1525
  "count": schema413,
1812
- "max": schema513,
1813
- "p50": schema513,
1814
- "p90": schema513
1526
+ "max": schema510,
1527
+ "p50": schema510,
1528
+ "p90": schema510
1815
1529
  });
1816
- var schema78 = z.partialRecord(schema313, schema613);
1530
+ var schema78 = z.partialRecord(schema313, schema68);
1817
1531
  var schema88 = z.literal("available");
1818
1532
  var schema98 = z.literal("dialogue");
1819
1533
  var schema108 = z.string().regex(new RegExp("^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d))|(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?)$"));
@@ -1865,7 +1579,7 @@ var schema333 = z.strictObject({
1865
1579
  var schema343 = z.string();
1866
1580
  var schema353 = z.union([schema343, schema1113]);
1867
1581
  var schema363 = z.enum(["reserved", "started", "released", "failed"]);
1868
- var schema373 = z.union([schema513, schema1113]);
1582
+ var schema373 = z.union([schema510, schema1113]);
1869
1583
  var schema382 = z.custom((value) => typeof value === "object" && value !== null && !Array.isArray(value));
1870
1584
  var schema392 = z.strictObject({
1871
1585
  "sessionId": schema012,
@@ -1900,7 +1614,7 @@ var DEFAULT_BASE_URL = "https://realtimeavatar.ai/api/v1";
1900
1614
  var RENDER_MISMATCH = "Render response did not match the SDK contract";
1901
1615
  var SPEECH_MISMATCH = "Speech response did not match the SDK contract";
1902
1616
  var MAX_SPEECH_RESPONSE_BYTES = 24 * 1024 * 1024;
1903
- var SDK_VERSION = "0.39.0";
1617
+ var SDK_VERSION = "0.40.0";
1904
1618
  var RealtimeAvatar = class {
1905
1619
  #apiKey;
1906
1620
  #baseUrl;
@@ -2522,43 +2236,12 @@ var RealtimeAvatar = class {
2522
2236
  return response;
2523
2237
  }, Math.max(0, Math.min(this.#timeoutMs, this.#totalTimeoutMs ?? Infinity)), options.signal);
2524
2238
  }
2525
- /**
2526
- * A live speech session: text in while it is written, PCM and alignment out per utterance.
2527
- * Resolves once the platform admitted the session (voice, slot, credit hold, provider socket),
2528
- * so every refusal before that rejects here. In Workers the upgrade is a fetch and a refusal is
2529
- * a RealtimeAvatarHttpError; Node's standard WebSocket reports no status, so there it is a
2530
- * RealtimeAvatarError. Never retried. `timeoutMs` bounds opening, `totalTimeoutMs` (if set) the
2531
- * whole session; abort or `break` closes it, which bills what was already sent.
2532
- */
2533
- async openSpeechSession(voiceId, input, options = {}) {
2534
- const id = speechVoiceIdSchema.parse(voiceId);
2535
- const open = speechLiveOpenSchema.parse(input);
2536
- const query = new URLSearchParams();
2537
- for (const [name, value] of Object.entries(open)) if (value !== void 0) query.set(name, String(value));
2538
- const url = `${this.#baseUrl}/voices/${encodeURIComponent(id)}/speech/live?${query}`;
2539
- const headers = this.#identityHeaders();
2540
- return openSpeechSocketSession(
2541
- isWorkerd() ? (signal) => this.#upgrade(url, headers, signal) : async () => connectStandardSocket(url, headers),
2542
- { handshakeMs: Math.max(0, Math.min(this.#timeoutMs, this.#totalTimeoutMs ?? Infinity)), sessionMs: this.#totalTimeoutMs },
2543
- options.signal
2544
- );
2545
- }
2546
- /** Workers open an outbound WebSocket with a fetch upgrade; it is the only way to send headers there. */
2547
- async #upgrade(url, headers, signal) {
2548
- const response = await this.#fetch(url, { headers: { ...headers, upgrade: "websocket" }, signal });
2549
- const socket = "webSocket" in response ? response.webSocket : null;
2550
- if (response.status === 101 && isUpgradedSocket(socket)) return { socket, ready: Promise.resolve() };
2551
- if (!response.ok) await this.#json(await boundedSpeechErrorResponse(response, signal));
2552
- await response.body?.cancel().catch(() => {
2553
- });
2554
- throw new RealtimeAvatarError("Speech session upgrade did not match the SDK contract");
2555
- }
2556
2239
  // ── internals ────────────────────────────────────────────────────────────
2557
- #identityHeaders() {
2558
- return { authorization: `Bearer ${this.#apiKey}`, "user-agent": this.#userAgent };
2559
- }
2560
2240
  async #request(method, path, init = {}) {
2561
- const headers = this.#identityHeaders();
2241
+ const headers = {
2242
+ authorization: `Bearer ${this.#apiKey}`,
2243
+ "user-agent": this.#userAgent
2244
+ };
2562
2245
  if (init.headers?.["X-RTA-Speech-Diagnostics"] === "1") {
2563
2246
  headers["X-RTA-Speech-Diagnostics"] = "1";
2564
2247
  }
@@ -2724,15 +2407,11 @@ function toAsset(raw) {
2724
2407
  sizeBytes: typeof a.sizeBytes === "number" ? a.sizeBytes : null
2725
2408
  };
2726
2409
  }
2727
- function isWorkerd() {
2728
- const g = globalThis;
2729
- return "navigator" in g && typeof navigator?.userAgent === "string" && navigator.userAgent.includes("Cloudflare-Workers");
2730
- }
2731
2410
  function runtimeTag() {
2732
2411
  const g = globalThis;
2733
2412
  if ("Deno" in g) return "deno";
2734
2413
  if ("Bun" in g) return "bun";
2735
- if (isWorkerd()) return "workerd";
2414
+ if ("navigator" in g && typeof navigator?.userAgent === "string" && navigator.userAgent.includes("Cloudflare-Workers")) return "workerd";
2736
2415
  if ("process" in g && typeof process?.versions?.node === "string") return `node/${process.versions.node}`;
2737
2416
  return "unknown";
2738
2417
  }
@@ -2810,4 +2489,4 @@ var proxyEndRequestSchema = z.object({
2810
2489
  message: "session_id or queue_ticket_id is required"
2811
2490
  });
2812
2491
 
2813
- export { DEFAULT_FISH_TTS_MODEL, FISH_DELIVERY_MODELS, ROUTE_TIMEOUT_MS, RealtimeAvatar, RealtimeAvatarError, RealtimeAvatarHttpError, RealtimeAvatarWebhookError, capacityBusyResponseSchema, clipLibraryDeclarationSchema, createSpeechRequestSchema, createSpeechStreamRequestSchema, externalSpeechSegmentSchema, externalTurnContextSchema, externalUtteranceSchema, fishTtsModelSchema, isQueued, listRecordingsResponseSchema, listRendersResponseSchema, liveKitSessionGrantSchema, proxyConnectRequestSchema, proxyEndRequestSchema, recordingAccessResponseSchema, recordingArtifactSchema, recordingModeSchema, renderAccessResponseSchema, renderSchema, speechAlignedTextSchema, speechLiveClientMessageSchema, speechLiveOpenSchema, speechLiveServerMessageSchema, speechStreamEventSchema, verifyTranscript, verifyVoiceWebhook };
2492
+ export { DEFAULT_FISH_TTS_MODEL, FISH_DELIVERY_MODELS, ROUTE_TIMEOUT_MS, RealtimeAvatar, RealtimeAvatarError, RealtimeAvatarHttpError, RealtimeAvatarWebhookError, capacityBusyResponseSchema, clipLibraryDeclarationSchema, createSpeechRequestSchema, createSpeechStreamRequestSchema, externalSpeechSegmentSchema, externalTurnContextSchema, externalUtteranceSchema, fishTtsModelSchema, isQueued, listRecordingsResponseSchema, listRendersResponseSchema, liveKitSessionGrantSchema, proxyConnectRequestSchema, proxyEndRequestSchema, recordingAccessResponseSchema, recordingArtifactSchema, recordingModeSchema, renderAccessResponseSchema, renderSchema, speechAlignedTextSchema, speechStreamEventSchema, verifyTranscript, verifyVoiceWebhook };
@@ -1,4 +1,4 @@
1
- import { RealtimeAvatar, ROUTE_TIMEOUT_MS, proxyEndRequestSchema, proxyConnectRequestSchema, isQueued, RealtimeAvatarHttpError, RealtimeAvatarError } from './chunk-YBKE7SDI.js';
1
+ import { RealtimeAvatar, ROUTE_TIMEOUT_MS, proxyEndRequestSchema, proxyConnectRequestSchema, isQueued, RealtimeAvatarHttpError, RealtimeAvatarError } from './chunk-A6EY5MI3.js';
2
2
 
3
3
  // ../http-client/src/generated/error-semantics.ts
4
4
  var ERROR_SEMANTICS = {
package/dist/express.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as ProxyConfig } from './types-CpfJZaxo.js';
2
- import './types-B8MMMQ_V.js';
1
+ import { P as ProxyConfig } from './types-CYti2_bv.js';
2
+ import './types-niYtoW5A.js';
3
3
  import 'zod';
4
4
 
5
5
  type Expressish = {
package/dist/express.js CHANGED
@@ -1,5 +1,5 @@
1
- import { createProxyHandler } from './chunk-PZNCGKOB.js';
2
- import './chunk-YBKE7SDI.js';
1
+ import { createProxyHandler } from './chunk-K2DC73LC.js';
2
+ import './chunk-A6EY5MI3.js';
3
3
  import './chunk-MCIXU6XP.js';
4
4
 
5
5
  // ../proxy/src/express.ts
package/dist/hono.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as ProxyConfig } from './types-CpfJZaxo.js';
2
- import './types-B8MMMQ_V.js';
1
+ import { P as ProxyConfig } from './types-CYti2_bv.js';
2
+ import './types-niYtoW5A.js';
3
3
  import 'zod';
4
4
 
5
5
  /**
package/dist/hono.js CHANGED
@@ -1,5 +1,5 @@
1
- import { createProxyHandler } from './chunk-PZNCGKOB.js';
2
- import './chunk-YBKE7SDI.js';
1
+ import { createProxyHandler } from './chunk-K2DC73LC.js';
2
+ import './chunk-A6EY5MI3.js';
3
3
  import './chunk-MCIXU6XP.js';
4
4
 
5
5
  // ../proxy/src/hono.ts
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as SpeechLiveServerMessage, b as SpeechLiveClientMessage, a as CallPolicy, C as CallMode, c as StartCallResult, E as EndCallOptions, A as Avatar, d as CreateAnimaAvatarInput, R as RegisteredAvatar, e as AvatarUpdate, f as AvatarSourceSwap, g as ClipLibraryDeclaration, h as ClipLibraryUpdate, L as LoopRedirect, i as ClipLibrary, j as AssetKind, k as Asset, l as ListSessionsOptions, U as UsageSessionPage, m as UsageSession, n as ListRecordingsQuery, o as ListRecordingsResponse, p as RecordingArtifact, q as RecordingAccessResponse, r as CreateRenderInput, s as CreditBalance, t as operations, u as CreateSpeechInput, v as SpeechResult, w as CreateSpeechStreamRequest, x as SpeechStreamEvent, y as SpeechLiveOpen, T as TranscriptPayload, V as VoiceWebhookRequest } from './types-B8MMMQ_V.js';
2
- export { z as AvatarClip, B as CallConnection, D as CallQueued, F as ClipDeclaration, G as ClipLibraryPlan, H as ClipSource, I as ContextMessage, J as EndCallReason, K as ExternalLlm, M as RecordingArtifactStatus, N as RecordingMode, O as RenderShot, P as SpeechAlignedText, Q as VideoPolicy, W as VoiceWebhook, X as VoiceWebhookErrorCode, Y as createSpeechRequestSchema, Z as createSpeechStreamRequestSchema, _ as isQueued, $ as listRecordingsResponseSchema, a0 as recordingAccessResponseSchema, a1 as recordingArtifactSchema, a2 as recordingModeSchema, a3 as speechAlignedTextSchema, a4 as speechLiveClientMessageSchema, a5 as speechLiveOpenSchema, a6 as speechLiveServerMessageSchema, a7 as speechStreamEventSchema } from './types-B8MMMQ_V.js';
1
+ import { a as CallPolicy, C as CallMode, S as StartCallResult, E as EndCallOptions, A as Avatar, b as CreateAnimaAvatarInput, R as RegisteredAvatar, c as AvatarUpdate, d as AvatarSourceSwap, e as ClipLibraryDeclaration, f as ClipLibraryUpdate, L as LoopRedirect, g as ClipLibrary, h as AssetKind, i as Asset, j as ListSessionsOptions, U as UsageSessionPage, k as UsageSession, l as ListRecordingsQuery, m as ListRecordingsResponse, n as RecordingArtifact, o as RecordingAccessResponse, p as CreateRenderInput, q as CreditBalance, r as operations, s as CreateSpeechInput, t as SpeechResult, u as CreateSpeechStreamRequest, v as SpeechStreamEvent, T as TranscriptPayload, V as VoiceWebhookRequest } from './types-niYtoW5A.js';
2
+ export { w as AvatarClip, x as CallConnection, y as CallQueued, z as ClipDeclaration, B as ClipLibraryPlan, D as ClipSource, F as ContextMessage, G as EndCallReason, H as ExternalLlm, I as RecordingArtifactStatus, J as RecordingMode, K as RenderShot, M as SpeechAlignedText, N as VideoPolicy, O as VoiceWebhook, P as VoiceWebhookErrorCode, Q as createSpeechRequestSchema, W as createSpeechStreamRequestSchema, X as isQueued, Y as listRecordingsResponseSchema, Z as recordingAccessResponseSchema, _ as recordingArtifactSchema, $ as recordingModeSchema, a0 as speechAlignedTextSchema, a1 as speechStreamEventSchema } from './types-niYtoW5A.js';
3
3
  import { ConnectionHistoryResponse } from './connection-history.js';
4
4
  import { z } from 'zod';
5
5
 
@@ -9,29 +9,6 @@ type PollOptions = {
9
9
  pollMs?: number;
10
10
  };
11
11
 
12
- type TextMessage = Extract<SpeechLiveClientMessage, {
13
- type: "text";
14
- }>;
15
- /**
16
- * One live speech session: send text while it is written, read PCM and alignment per utterance.
17
- *
18
- * Iterate it once. Every message is validated against the generated `SpeechLiveServerMessage`
19
- * schema and the session's ordering before it is yielded; a terminal `completed` or `failed` ends
20
- * the iteration. `break`/`return()` and the caller's signal close the socket, which the platform
21
- * bills like `cancel`: the bytes already sent are paid for.
22
- */
23
- interface SpeechSession extends AsyncIterable<SpeechLiveServerMessage> {
24
- /** Append text to the open utterance: 0 first, then one more after each flush. */
25
- text(utterance: TextMessage["utterance"], text: TextMessage["text"]): void;
26
- /** Speak the open utterance now and open the next. */
27
- flush(utterance: TextMessage["utterance"]): void;
28
- /** No more text: the platform speaks what is buffered, then completes. A no-op once the session is over. */
29
- end(): void;
30
- /** Stop now. Bytes already sent are billed. A no-op once the session is over. */
31
- cancel(): void;
32
- [Symbol.asyncIterator](): AsyncIterator<SpeechLiveServerMessage, void, undefined>;
33
- }
34
-
35
12
  declare const renderStatusSchema: z.ZodEnum<{
36
13
  ready: "ready";
37
14
  failed: "failed";
@@ -506,17 +483,6 @@ declare class RealtimeAvatar {
506
483
  createSpeechStream(voiceId: operations["createSpeechStream"]["parameters"]["path"]["voiceId"], input: CreateSpeechStreamRequest, options?: {
507
484
  signal?: AbortSignal;
508
485
  }): AsyncGenerator<SpeechStreamEvent, void, unknown>;
509
- /**
510
- * A live speech session: text in while it is written, PCM and alignment out per utterance.
511
- * Resolves once the platform admitted the session (voice, slot, credit hold, provider socket),
512
- * so every refusal before that rejects here. In Workers the upgrade is a fetch and a refusal is
513
- * a RealtimeAvatarHttpError; Node's standard WebSocket reports no status, so there it is a
514
- * RealtimeAvatarError. Never retried. `timeoutMs` bounds opening, `totalTimeoutMs` (if set) the
515
- * whole session; abort or `break` closes it, which bills what was already sent.
516
- */
517
- openSpeechSession(voiceId: operations["openSpeechLive"]["parameters"]["path"]["voiceId"], input: SpeechLiveOpen, options?: {
518
- signal?: AbortSignal;
519
- }): Promise<SpeechSession>;
520
486
  }
521
487
 
522
488
  /** Base for everything this SDK throws, so `catch (e) { if (e instanceof RealtimeAvatarError) }` works. */
@@ -996,4 +962,4 @@ declare const proxyEndRequestSchema: z.ZodObject<{
996
962
  }>>>;
997
963
  }, z.core.$strict>;
998
964
 
999
- export { Asset, AssetKind, Avatar, AvatarSourceSwap, AvatarUpdate, CallMode, CallPolicy, ClipLibrary, ClipLibraryDeclaration, ClipLibraryUpdate, CreateAnimaAvatarInput, CreateRenderInput, CreateSpeechInput, CreateSpeechStreamRequest, CreditBalance, DEFAULT_FISH_TTS_MODEL, EndCallOptions, type ExternalSpeechSegment, type ExternalTurnContext, type ExternalUtterance, FISH_DELIVERY_MODELS, type FishDelivery, type FishTtsModel, ListRecordingsQuery, ListRecordingsResponse, type ListRendersQuery, type ListRendersResponse, ListSessionsOptions, LoopRedirect, RealtimeAvatar, RealtimeAvatarError, RealtimeAvatarHttpError, type RealtimeAvatarOptions, RealtimeAvatarWebhookError, RecordingAccessResponse, RecordingArtifact, RegisteredAvatar, type Render, type RenderAccessResponse, type RenderFailureCode, type RenderPlayback, type RenderStatus, type ShotTiming, SpeechLiveClientMessage, SpeechLiveOpen, SpeechLiveServerMessage, SpeechResult, type SpeechSession, SpeechStreamEvent, type StartCallOptions, StartCallResult, TranscriptPayload, UsageSession, UsageSessionPage, VoiceWebhookRequest, type WebhookVerificationErrorCode, capacityBusyResponseSchema, clipLibraryDeclarationSchema, externalSpeechSegmentSchema, externalTurnContextSchema, externalUtteranceSchema, fishTtsModelSchema, listRendersResponseSchema, liveKitSessionGrantSchema, proxyConnectRequestSchema, proxyEndRequestSchema, renderAccessResponseSchema, renderSchema, verifyTranscript, verifyVoiceWebhook };
965
+ export { Asset, AssetKind, Avatar, AvatarSourceSwap, AvatarUpdate, CallMode, CallPolicy, ClipLibrary, ClipLibraryDeclaration, ClipLibraryUpdate, CreateAnimaAvatarInput, CreateRenderInput, CreateSpeechInput, CreateSpeechStreamRequest, CreditBalance, DEFAULT_FISH_TTS_MODEL, EndCallOptions, type ExternalSpeechSegment, type ExternalTurnContext, type ExternalUtterance, FISH_DELIVERY_MODELS, type FishDelivery, type FishTtsModel, ListRecordingsQuery, ListRecordingsResponse, type ListRendersQuery, type ListRendersResponse, ListSessionsOptions, LoopRedirect, RealtimeAvatar, RealtimeAvatarError, RealtimeAvatarHttpError, type RealtimeAvatarOptions, RealtimeAvatarWebhookError, RecordingAccessResponse, RecordingArtifact, RegisteredAvatar, type Render, type RenderAccessResponse, type RenderFailureCode, type RenderPlayback, type RenderStatus, type ShotTiming, SpeechResult, SpeechStreamEvent, type StartCallOptions, StartCallResult, TranscriptPayload, UsageSession, UsageSessionPage, VoiceWebhookRequest, type WebhookVerificationErrorCode, capacityBusyResponseSchema, clipLibraryDeclarationSchema, externalSpeechSegmentSchema, externalTurnContextSchema, externalUtteranceSchema, fishTtsModelSchema, listRendersResponseSchema, liveKitSessionGrantSchema, proxyConnectRequestSchema, proxyEndRequestSchema, renderAccessResponseSchema, renderSchema, verifyTranscript, verifyVoiceWebhook };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import './chunk-6KQS7CTR.js';
2
- export { DEFAULT_FISH_TTS_MODEL, FISH_DELIVERY_MODELS, RealtimeAvatar, RealtimeAvatarError, RealtimeAvatarHttpError, RealtimeAvatarWebhookError, capacityBusyResponseSchema, clipLibraryDeclarationSchema, createSpeechRequestSchema, createSpeechStreamRequestSchema, externalSpeechSegmentSchema, externalTurnContextSchema, externalUtteranceSchema, fishTtsModelSchema, isQueued, listRecordingsResponseSchema, listRendersResponseSchema, liveKitSessionGrantSchema, proxyConnectRequestSchema, proxyEndRequestSchema, recordingAccessResponseSchema, recordingArtifactSchema, recordingModeSchema, renderAccessResponseSchema, renderSchema, speechAlignedTextSchema, speechLiveClientMessageSchema, speechLiveOpenSchema, speechLiveServerMessageSchema, speechStreamEventSchema, verifyTranscript, verifyVoiceWebhook } from './chunk-YBKE7SDI.js';
2
+ export { DEFAULT_FISH_TTS_MODEL, FISH_DELIVERY_MODELS, RealtimeAvatar, RealtimeAvatarError, RealtimeAvatarHttpError, RealtimeAvatarWebhookError, capacityBusyResponseSchema, clipLibraryDeclarationSchema, createSpeechRequestSchema, createSpeechStreamRequestSchema, externalSpeechSegmentSchema, externalTurnContextSchema, externalUtteranceSchema, fishTtsModelSchema, isQueued, listRecordingsResponseSchema, listRendersResponseSchema, liveKitSessionGrantSchema, proxyConnectRequestSchema, proxyEndRequestSchema, recordingAccessResponseSchema, recordingArtifactSchema, recordingModeSchema, renderAccessResponseSchema, renderSchema, speechAlignedTextSchema, speechStreamEventSchema, verifyTranscript, verifyVoiceWebhook } from './chunk-A6EY5MI3.js';
3
3
  import './chunk-MCIXU6XP.js';