realtime-avatar 0.36.0 → 0.38.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.
@@ -845,9 +845,109 @@ var schema47 = z.strictObject({
845
845
  var schema56 = z.string().regex(new RegExp("^(vce|voice)_"));
846
846
  var schema64 = z.number().min(0);
847
847
  var schema74 = z.int().min(1);
848
+ var schema84 = z.enum(["normal", "balanced", "low"]);
849
+ var schema94 = z.int().min(100).max(300);
850
+ var schema104 = z.strictObject({
851
+ "text": z.string().trim().pipe(schema08),
852
+ "speed": schema212.optional(),
853
+ "language": schema37.optional(),
854
+ "latency": schema84.optional(),
855
+ "chunkLength": schema94.optional()
856
+ });
857
+ var schema118 = z.string().max(4096);
858
+ var schema124 = z.number().min(0).max(180);
859
+ var schema134 = z.strictObject({
860
+ "text": schema118,
861
+ "start": schema124,
862
+ "end": schema124
863
+ });
864
+ var speechAlignedTextSchema = schema134.refine((segment) => segment.end >= segment.start);
865
+ var schema154 = z.uuid().regex(new RegExp("^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"));
866
+ var schema163 = z.literal("started");
867
+ var schema173 = z.literal("pcm_s16le");
868
+ var schema183 = z.literal(24e3);
869
+ var schema193 = z.literal(1);
870
+ var schema202 = z.strictObject({
871
+ "requestId": schema154,
872
+ "type": schema163,
873
+ "encoding": schema173,
874
+ "sampleRate": schema183,
875
+ "channels": schema193
876
+ });
877
+ var schema213 = z.literal("audio");
878
+ var schema222 = z.int().min(0).max(9007199254740991);
879
+ var schema232 = z.int().min(0).max(432e4);
880
+ var schema242 = z.base64().regex(new RegExp("^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$")).min(4).max(21848);
881
+ var schema252 = z.strictObject({
882
+ "requestId": schema154,
883
+ "type": schema213,
884
+ "sequence": schema222,
885
+ "sampleOffset": schema232,
886
+ "audioBase64": schema242
887
+ });
888
+ var schema262 = z.literal("alignment");
889
+ var schema272 = z.int().min(0).max(127);
890
+ var schema282 = z.array(speechAlignedTextSchema).max(2048);
891
+ var schema292 = z.strictObject({
892
+ "requestId": schema154,
893
+ "type": schema262,
894
+ "chunkSeq": schema272,
895
+ "segments": schema282
896
+ });
897
+ var schema30 = z.literal("completed");
898
+ var schema31 = z.int().max(432e4).gt(0);
899
+ var schema322 = z.int().max(9007199254740991).gt(0);
900
+ var schema332 = z.strictObject({
901
+ "requestId": schema154,
902
+ "type": schema30,
903
+ "totalSamples": schema31,
904
+ "billedCredits": schema64,
905
+ "billedBytes": schema322
906
+ });
907
+ var schema342 = z.literal("failed");
908
+ var schema352 = z.string();
909
+ var schema362 = z.int().min(-9007199254740991).max(9007199254740991);
910
+ var schema372 = z.string();
911
+ var schema38 = z.url();
912
+ var schema39 = z.boolean();
913
+ var schema40 = z.uuid().regex(new RegExp("^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"));
914
+ var schema41 = z.enum(["*", "api_keys:write", "credits:read", "avatars:read", "avatars:write", "realtime:write", "usage:read", "recordings:read", "usage:write", "speech:write", "renders:read", "renders:write"]);
915
+ var schema422 = z.enum(["*", "api_keys:write", "credits:read", "avatars:read", "avatars:write", "realtime:write", "usage:read", "recordings:read", "usage:write", "speech:write", "renders:read", "renders:write"]);
916
+ var schema432 = z.array(schema422);
917
+ var schema442 = z.string();
918
+ var schema452 = z.int().max(9007199254740991).gt(0);
919
+ var schema462 = z.int().min(0).max(9007199254740991);
920
+ var schema472 = z.int().min(0).max(9007199254740991);
921
+ var schema48 = z.int().min(0).max(9007199254740991);
922
+ var schema49 = z.int().min(0).max(9007199254740991);
923
+ var schema50 = z.looseObject({
924
+ "error": schema352,
925
+ "status": schema362,
926
+ "code": schema372,
927
+ "documentation": schema38,
928
+ "retryable": schema39.optional(),
929
+ "requestId": schema40.optional(),
930
+ "requiredScope": schema41.optional(),
931
+ "grantedScopes": schema432.optional(),
932
+ "billingUrl": schema442.optional(),
933
+ "maxConcurrentSessions": schema452.optional(),
934
+ "liveSessions": schema462.optional(),
935
+ "activeSessions": schema472.optional(),
936
+ "connectingSessions": schema48.optional(),
937
+ "pendingSessions": schema49.optional()
938
+ });
939
+ var schema51 = z.strictObject({
940
+ "requestId": schema154,
941
+ "type": schema342,
942
+ "error": schema50
943
+ });
944
+ var schema522 = z.union([schema202, schema252, schema292, schema332, schema51]);
848
945
  var createSpeechRequestSchema = schema47.extend({
849
946
  format: schema47.shape.format.unwrap().default("mp3")
850
947
  });
948
+ var createSpeechStreamRequestSchema = schema104;
949
+ var speechStreamEventSchema = schema522;
950
+ var SPEECH_STREAM_CONTRACT = { "maxAudioEventBytes": 16384, "maxSamples": 432e4};
851
951
  var speechVoiceIdSchema = schema56;
852
952
  var speechContentTypeSchema = z.enum(["audio/mpeg", "audio/wav"]);
853
953
  var speechResponseHeadersSchema = z.strictObject({
@@ -897,116 +997,439 @@ function isTransient(cause) {
897
997
  return name === "TimeoutError" || name === "TypeError" || name === "FetchError";
898
998
  }
899
999
  var schema09 = z.string().min(1).max(160);
900
- var schema118 = z.custom((value) => typeof value === "object" && value !== null && !Array.isArray(value));
901
- var schema213 = z.enum(["cartesia", "fish"]);
902
- var schema38 = z.string().min(1).max(240);
903
- var schema48 = z.string().min(1).max(120);
1000
+ var schema119 = z.custom((value) => typeof value === "object" && value !== null && !Array.isArray(value));
1001
+ var schema214 = z.enum(["cartesia", "fish"]);
1002
+ var schema310 = z.string().min(1).max(240);
1003
+ var schema410 = z.string().min(1).max(120);
904
1004
  var schema57 = z.number().min(0.5).max(2);
905
1005
  var schema65 = z.null();
906
1006
  var schema75 = z.union([schema57, schema65]);
907
- var schema84 = z.string().min(1).max(80);
908
- var schema94 = z.union([schema84, schema65]);
909
- var schema104 = z.string().min(2).max(16);
910
- var schema119 = z.union([schema104, schema65]);
911
- var schema124 = z.strictObject({
912
- "provider": schema213,
913
- "voice_id": schema38,
914
- "model": schema48.optional(),
1007
+ var schema85 = z.string().min(1).max(80);
1008
+ var schema95 = z.union([schema85, schema65]);
1009
+ var schema105 = z.string().min(2).max(16);
1010
+ var schema1110 = z.union([schema105, schema65]);
1011
+ var schema125 = z.strictObject({
1012
+ "provider": schema214,
1013
+ "voice_id": schema310,
1014
+ "model": schema410.optional(),
915
1015
  "speed": schema75.optional(),
916
- "emotion": schema94.optional(),
917
- "language": schema119.optional()
1016
+ "emotion": schema95.optional(),
1017
+ "language": schema1110.optional()
918
1018
  });
919
- var schema134 = z.string().min(8).max(80);
1019
+ var schema135 = z.string().min(8).max(80);
920
1020
  var schema144 = z.string();
921
- var schema154 = z.enum(["video", "live2d"]);
922
- var schema163 = z.enum(["image", "video"]);
923
- var schema173 = z.enum(["realtime-avatar-live-v1", "realtime-avatar-video-v1"]);
924
- var schema183 = z.union([schema134, schema65]);
925
- var schema193 = z.enum(["draft", "preprocessing", "ready", "failed", "disabled", "deleted"]);
926
- var schema202 = z.union([schema144, schema65]);
927
- var schema214 = z.enum(["none", "queued", "generating", "ready", "failed"]);
928
- var schema222 = z.enum(["local", "gemini", "openai"]);
929
- var schema232 = z.string().max(200);
930
- var schema242 = z.union([schema232, schema65]);
931
- var schema252 = z.strictObject({
932
- "provider": schema222,
933
- "model": schema242.optional()
1021
+ var schema155 = z.enum(["video", "anima"]);
1022
+ var schema164 = z.enum(["image", "video"]);
1023
+ var schema174 = z.enum(["realtime-avatar-live-v1", "realtime-avatar-video-v1"]);
1024
+ var schema184 = z.union([schema135, schema65]);
1025
+ var schema194 = z.enum(["draft", "preprocessing", "ready", "failed", "disabled", "deleted"]);
1026
+ var schema203 = z.union([schema144, schema65]);
1027
+ var schema215 = z.enum(["none", "queued", "generating", "ready", "failed"]);
1028
+ var schema223 = z.enum(["local", "gemini", "openai"]);
1029
+ var schema233 = z.string().max(200);
1030
+ var schema243 = z.union([schema233, schema65]);
1031
+ var schema253 = z.strictObject({
1032
+ "provider": schema223,
1033
+ "model": schema243.optional()
934
1034
  });
935
- var schema262 = z.union([schema252, schema65]);
936
- var schema272 = z.strictObject({
937
- "id": schema134,
938
- "tenantId": schema134,
1035
+ var schema263 = z.union([schema253, schema65]);
1036
+ var schema273 = z.strictObject({
1037
+ "id": schema135,
1038
+ "tenantId": schema135,
939
1039
  "displayName": schema144,
940
- "renderer": schema154,
941
- "sourceKind": schema163,
942
- "modelId": schema173,
943
- "sourceAssetId": schema183,
944
- "status": schema193,
945
- "error": schema202,
946
- "idleVideoStatus": schema214,
947
- "defaultVoiceId": schema202,
948
- "llm": schema262,
1040
+ "renderer": schema155,
1041
+ "sourceKind": schema164,
1042
+ "modelId": schema174,
1043
+ "sourceAssetId": schema184,
1044
+ "status": schema194,
1045
+ "error": schema203,
1046
+ "idleVideoStatus": schema215,
1047
+ "defaultVoiceId": schema203,
1048
+ "llm": schema263,
949
1049
  "createdAt": schema144,
950
1050
  "updatedAt": schema144
951
1051
  });
952
- var createLive2dAvatarInputSchema = z.strictObject({
1052
+ var createAnimaAvatarInputSchema = z.strictObject({
953
1053
  displayName: schema09,
954
- settings: schema118.optional(),
955
- metadata: schema118.optional(),
956
- voice: schema124
1054
+ settings: schema119.optional(),
1055
+ metadata: schema119.optional(),
1056
+ voice: schema125
957
1057
  });
958
- var avatarResponseSchema = schema272;
1058
+ var avatarResponseSchema = schema273;
1059
+
1060
+ // ../../node_modules/eventsource-parser/dist/index.js
1061
+ var ParseError = class extends Error {
1062
+ constructor(message, options) {
1063
+ super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
1064
+ }
1065
+ };
1066
+ var LF = 10;
1067
+ var CR = 13;
1068
+ var SPACE = 32;
1069
+ function noop(_arg) {
1070
+ }
1071
+ function createParser(config) {
1072
+ if (typeof config == "function")
1073
+ throw new TypeError(
1074
+ "`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?"
1075
+ );
1076
+ const { onEvent = noop, onError = noop, onRetry = noop, onComment, maxBufferSize } = config, pendingFragments = [];
1077
+ let pendingFragmentsLength = 0, isFirstChunk = true, id, data = "", dataLines = 0, eventType, terminated = false;
1078
+ function feed(chunk) {
1079
+ if (terminated)
1080
+ throw new Error(
1081
+ "Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing."
1082
+ );
1083
+ if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
1084
+ const trailing2 = processLines(chunk);
1085
+ trailing2 !== "" && (pendingFragments.push(trailing2), pendingFragmentsLength = trailing2.length), checkBufferSize();
1086
+ return;
1087
+ }
1088
+ if (chunk.indexOf(`
1089
+ `) === -1 && chunk.indexOf("\r") === -1) {
1090
+ pendingFragments.push(chunk), pendingFragmentsLength += chunk.length, checkBufferSize();
1091
+ return;
1092
+ }
1093
+ pendingFragments.push(chunk);
1094
+ const input = pendingFragments.join("");
1095
+ pendingFragments.length = 0, pendingFragmentsLength = 0;
1096
+ const trailing = processLines(input);
1097
+ trailing !== "" && (pendingFragments.push(trailing), pendingFragmentsLength = trailing.length), checkBufferSize();
1098
+ }
1099
+ function checkBufferSize() {
1100
+ maxBufferSize !== void 0 && (pendingFragmentsLength + data.length <= maxBufferSize || (terminated = true, pendingFragments.length = 0, pendingFragmentsLength = 0, id = void 0, data = "", dataLines = 0, eventType = void 0, onError(
1101
+ new ParseError(`Buffered data exceeded max buffer size of ${maxBufferSize} characters`, {
1102
+ type: "max-buffer-size-exceeded"
1103
+ })
1104
+ )));
1105
+ }
1106
+ function processLines(chunk) {
1107
+ let searchIndex = 0;
1108
+ if (chunk.indexOf("\r") === -1) {
1109
+ let lfIndex = chunk.indexOf(`
1110
+ `, searchIndex);
1111
+ for (; lfIndex !== -1; ) {
1112
+ if (searchIndex === lfIndex) {
1113
+ dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
1114
+ `, searchIndex);
1115
+ continue;
1116
+ }
1117
+ const firstCharCode = chunk.charCodeAt(searchIndex);
1118
+ if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
1119
+ const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
1120
+ if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
1121
+ onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
1122
+ `, searchIndex);
1123
+ continue;
1124
+ }
1125
+ data = dataLines === 0 ? value : `${data}
1126
+ ${value}`, dataLines++;
1127
+ } else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
1128
+ chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
1129
+ lfIndex
1130
+ ) || void 0 : parseLine(chunk, searchIndex, lfIndex);
1131
+ searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
1132
+ `, searchIndex);
1133
+ }
1134
+ return chunk.slice(searchIndex);
1135
+ }
1136
+ for (; searchIndex < chunk.length; ) {
1137
+ const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
1138
+ `, searchIndex);
1139
+ let lineEnd = -1;
1140
+ if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = crIndex < lfIndex ? crIndex : lfIndex : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1)
1141
+ break;
1142
+ parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
1143
+ }
1144
+ return chunk.slice(searchIndex);
1145
+ }
1146
+ function parseLine(chunk, start, end) {
1147
+ if (start === end) {
1148
+ dispatchEvent();
1149
+ return;
1150
+ }
1151
+ const firstCharCode = chunk.charCodeAt(start);
1152
+ if (isDataPrefix(chunk, start, firstCharCode)) {
1153
+ const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
1154
+ data = dataLines === 0 ? value2 : `${data}
1155
+ ${value2}`, dataLines++;
1156
+ return;
1157
+ }
1158
+ if (isEventPrefix(chunk, start, firstCharCode)) {
1159
+ eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
1160
+ return;
1161
+ }
1162
+ if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
1163
+ const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
1164
+ value2.includes("\0") || (id = value2);
1165
+ return;
1166
+ }
1167
+ if (firstCharCode === 58) {
1168
+ if (onComment) {
1169
+ const line2 = chunk.slice(start, end);
1170
+ onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
1171
+ }
1172
+ return;
1173
+ }
1174
+ const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
1175
+ if (fieldSeparatorIndex === -1) {
1176
+ processField(line, "", line);
1177
+ return;
1178
+ }
1179
+ const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
1180
+ processField(field, value, line);
1181
+ }
1182
+ function processField(field, value, line) {
1183
+ switch (field) {
1184
+ case "event":
1185
+ eventType = value || void 0;
1186
+ break;
1187
+ case "data":
1188
+ data = dataLines === 0 ? value : `${data}
1189
+ ${value}`, dataLines++;
1190
+ break;
1191
+ case "id":
1192
+ value.includes("\0") || (id = value);
1193
+ break;
1194
+ case "retry":
1195
+ /^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(
1196
+ new ParseError(`Invalid \`retry\` value: "${value}"`, {
1197
+ type: "invalid-retry",
1198
+ value,
1199
+ line
1200
+ })
1201
+ );
1202
+ break;
1203
+ default:
1204
+ onError(
1205
+ new ParseError(
1206
+ `Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`,
1207
+ { type: "unknown-field", field, value, line }
1208
+ )
1209
+ );
1210
+ break;
1211
+ }
1212
+ }
1213
+ function dispatchEvent() {
1214
+ dataLines > 0 && onEvent({
1215
+ id,
1216
+ event: eventType,
1217
+ data
1218
+ }), id = void 0, data = "", dataLines = 0, eventType = void 0;
1219
+ }
1220
+ function reset(options = {}) {
1221
+ if (options.consume && pendingFragments.length > 0) {
1222
+ const incompleteLine = pendingFragments.join("");
1223
+ parseLine(incompleteLine, 0, incompleteLine.length);
1224
+ }
1225
+ isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0, pendingFragmentsLength = 0, terminated = false;
1226
+ }
1227
+ return { feed, reset };
1228
+ }
1229
+ function isDataPrefix(chunk, i, firstCharCode) {
1230
+ return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
1231
+ }
1232
+ function isEventPrefix(chunk, i, firstCharCode) {
1233
+ return firstCharCode === 101 && chunk.charCodeAt(i + 1) === 118 && chunk.charCodeAt(i + 2) === 101 && chunk.charCodeAt(i + 3) === 110 && chunk.charCodeAt(i + 4) === 116 && chunk.charCodeAt(i + 5) === 58;
1234
+ }
1235
+
1236
+ // ../http-client/src/speech-stream.ts
1237
+ var MISMATCH = "Speech stream response did not match the SDK contract";
1238
+ var MAX_WIRE_BYTES = 24 * 1024 * 1024;
1239
+ var MAX_EVENT_BYTES = 256 * 1024;
1240
+ var MAX_ERROR_BYTES = 64 * 1024;
1241
+ var FEED_BYTES = 4096;
1242
+ function speechStreamIterator(open, timeoutMs, callerSignal) {
1243
+ const controller = new AbortController();
1244
+ async function* iterate() {
1245
+ const timeout = AbortSignal.timeout(timeoutMs);
1246
+ const signal = AbortSignal.any([controller.signal, timeout, ...callerSignal ? [callerSignal] : []]);
1247
+ try {
1248
+ signal.throwIfAborted();
1249
+ const response = await open(signal);
1250
+ if (response.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase() !== "text/event-stream") {
1251
+ await response.body?.cancel().catch(() => {
1252
+ });
1253
+ throw new RealtimeAvatarError(MISMATCH);
1254
+ }
1255
+ yield* parseEvents(response, signal);
1256
+ } finally {
1257
+ controller.abort();
1258
+ }
1259
+ }
1260
+ const iterator = iterate();
1261
+ return {
1262
+ next: (value) => iterator.next(value),
1263
+ return: (value) => {
1264
+ controller.abort();
1265
+ return iterator.return(value);
1266
+ },
1267
+ throw: (error) => {
1268
+ controller.abort();
1269
+ return iterator.throw(error);
1270
+ },
1271
+ [Symbol.asyncIterator]() {
1272
+ return this;
1273
+ }
1274
+ };
1275
+ }
1276
+ async function* bodyChunks(response, signal, limit) {
1277
+ if (!response.body) throw new RealtimeAvatarError(MISMATCH);
1278
+ const reader = response.body.getReader();
1279
+ const cancel = () => {
1280
+ void reader.cancel().catch(() => {
1281
+ });
1282
+ };
1283
+ signal.addEventListener("abort", cancel, { once: true });
1284
+ let size = 0;
1285
+ try {
1286
+ signal.throwIfAborted();
1287
+ for (; ; ) {
1288
+ const { value, done } = await reader.read();
1289
+ signal.throwIfAborted();
1290
+ if (done) return;
1291
+ size += value.byteLength;
1292
+ if (size > limit) throw new RealtimeAvatarError(MISMATCH);
1293
+ yield value;
1294
+ }
1295
+ } catch (error) {
1296
+ signal.throwIfAborted();
1297
+ if (error instanceof RealtimeAvatarError) throw error;
1298
+ throw new RealtimeAvatarError(MISMATCH);
1299
+ } finally {
1300
+ signal.removeEventListener("abort", cancel);
1301
+ await reader.cancel().catch(() => {
1302
+ });
1303
+ reader.releaseLock();
1304
+ }
1305
+ }
1306
+ async function boundedSpeechErrorResponse(response, signal) {
1307
+ if (!response.body) return response;
1308
+ const chunks = [];
1309
+ for await (const chunk of bodyChunks(response, signal, MAX_ERROR_BYTES)) chunks.push(new Uint8Array(chunk));
1310
+ return new Response(new Blob(chunks), { status: response.status, headers: response.headers });
1311
+ }
1312
+ async function* parseEvents(response, signal) {
1313
+ let requestId;
1314
+ let sequence = 0;
1315
+ let samples = 0;
1316
+ let terminal = false;
1317
+ const queue = [];
1318
+ const decoder = new TextDecoder("utf-8", { fatal: true });
1319
+ const encoder = new TextEncoder();
1320
+ let endsWithCR = false;
1321
+ const parser = createParser({
1322
+ maxBufferSize: MAX_EVENT_BYTES,
1323
+ onError() {
1324
+ throw new RealtimeAvatarError(MISMATCH);
1325
+ },
1326
+ onEvent(message) {
1327
+ if (terminal || encoder.encode(message.data).byteLength > MAX_EVENT_BYTES) throw new RealtimeAvatarError(MISMATCH);
1328
+ const raw = JSON.parse(message.data);
1329
+ const event = speechStreamEventSchema.parse(raw);
1330
+ if (message.event !== void 0 && message.event !== event.type) throw new RealtimeAvatarError(MISMATCH);
1331
+ if (requestId === void 0) {
1332
+ if (event.type !== "started") throw new RealtimeAvatarError(MISMATCH);
1333
+ requestId = event.requestId;
1334
+ } else {
1335
+ if (event.type === "started" || event.requestId !== requestId) throw new RealtimeAvatarError(MISMATCH);
1336
+ }
1337
+ if (event.type === "audio") {
1338
+ const bytes = atob(event.audioBase64).length;
1339
+ if (event.sequence !== sequence || event.sampleOffset !== samples || bytes === 0 || bytes % 2 !== 0 || bytes > SPEECH_STREAM_CONTRACT.maxAudioEventBytes) throw new RealtimeAvatarError(MISMATCH);
1340
+ samples += bytes / 2;
1341
+ sequence++;
1342
+ if (samples > SPEECH_STREAM_CONTRACT.maxSamples) throw new RealtimeAvatarError(MISMATCH);
1343
+ } else if (event.type === "completed") {
1344
+ if (samples <= 0 || event.totalSamples !== samples) throw new RealtimeAvatarError(MISMATCH);
1345
+ terminal = true;
1346
+ } else if (event.type === "failed") {
1347
+ terminal = true;
1348
+ }
1349
+ queue.push(event);
1350
+ }
1351
+ });
1352
+ try {
1353
+ for await (const bytes of bodyChunks(response, signal, MAX_WIRE_BYTES)) {
1354
+ for (let offset = 0; offset < bytes.byteLength; offset += FEED_BYTES) {
1355
+ signal.throwIfAborted();
1356
+ const text = decoder.decode(bytes.subarray(offset, offset + FEED_BYTES), { stream: true });
1357
+ if (text.length) endsWithCR = text.endsWith("\r");
1358
+ parser.feed(text);
1359
+ while (queue.length) {
1360
+ signal.throwIfAborted();
1361
+ const event = queue.shift();
1362
+ if (event) yield event;
1363
+ }
1364
+ }
1365
+ }
1366
+ const remainder = decoder.decode();
1367
+ if (remainder.length) endsWithCR = remainder.endsWith("\r");
1368
+ parser.feed(remainder);
1369
+ if (endsWithCR) parser.feed("\n");
1370
+ while (queue.length) {
1371
+ const event = queue.shift();
1372
+ if (event) yield event;
1373
+ }
1374
+ if (!terminal) throw new RealtimeAvatarError(MISMATCH);
1375
+ parser.feed("\n\n");
1376
+ parser.reset();
1377
+ } catch {
1378
+ signal.throwIfAborted();
1379
+ throw new RealtimeAvatarError(MISMATCH);
1380
+ }
1381
+ }
959
1382
  var schema010 = z.url().regex(new RegExp("^https:\\/\\/")).max(500);
960
1383
  var schema120 = z.string().min(16).max(200);
961
- var schema215 = z.string().min(1).max(200);
962
- var schema39 = z.string().min(2).max(35);
963
- var schema49 = z.literal([8e3, 16e3, 22050, 24e3, 44100, 48e3]);
1384
+ var schema216 = z.string().min(1).max(200);
1385
+ var schema311 = z.string().min(2).max(35);
1386
+ var schema411 = z.literal([8e3, 16e3, 22050, 24e3, 44100, 48e3]);
964
1387
  var schema58 = z.int().min(1e3).max(15e3);
965
1388
  var schema66 = z.strictObject({
966
1389
  "url": schema010,
967
1390
  "secret": schema120,
968
- "voice_id": schema215.optional(),
969
- "language": schema39.optional(),
970
- "sample_rate": schema49.optional(),
1391
+ "voice_id": schema216.optional(),
1392
+ "language": schema311.optional(),
1393
+ "sample_rate": schema411.optional(),
971
1394
  "timeout_ms": schema58.optional()
972
1395
  });
973
1396
  var schema76 = z.literal("voice.synthesize");
974
- var schema85 = z.literal(1);
975
- var schema95 = z.string().min(1).max(200);
976
- var schema105 = z.string().min(1).max(200);
977
- var schema1110 = z.object({
978
- "generation_id": schema95,
979
- "utterance_id": schema105
980
- });
981
- var schema125 = z.string().min(1).max(200);
982
- var schema135 = z.string();
1397
+ var schema86 = z.literal(1);
1398
+ var schema96 = z.string().min(1).max(200);
1399
+ var schema106 = z.string().min(1).max(200);
1400
+ var schema1111 = z.object({
1401
+ "generation_id": schema96,
1402
+ "utterance_id": schema106
1403
+ });
1404
+ var schema126 = z.string().min(1).max(200);
1405
+ var schema136 = z.string();
983
1406
  var schema145 = z.string().min(1).max(5e3);
984
- var schema155 = z.string();
985
- var schema164 = z.null();
986
- var schema174 = z.union([schema155, schema164]);
987
- var schema184 = z.string();
988
- var schema194 = z.union([schema184, schema164]);
989
- var schema203 = z.literal("pcm_s16le");
990
- var schema216 = z.literal([8e3, 16e3, 22050, 24e3, 44100, 48e3]);
991
- var schema223 = z.object({
992
- "encoding": schema203,
993
- "sample_rate": schema216,
994
- "channels": schema85
995
- });
996
- var schema233 = z.string().min(1).max(64);
997
- var schema243 = z.string().max(200);
998
- var schema253 = z.record(schema233, schema243).refine((value) => Object.keys(value).length <= 16, { message: "Too many keys: at most 16" });
999
- var schema263 = z.object({
1407
+ var schema156 = z.string();
1408
+ var schema165 = z.null();
1409
+ var schema175 = z.union([schema156, schema165]);
1410
+ var schema185 = z.string();
1411
+ var schema195 = z.union([schema185, schema165]);
1412
+ var schema204 = z.literal("pcm_s16le");
1413
+ var schema217 = z.literal([8e3, 16e3, 22050, 24e3, 44100, 48e3]);
1414
+ var schema224 = z.object({
1415
+ "encoding": schema204,
1416
+ "sample_rate": schema217,
1417
+ "channels": schema86
1418
+ });
1419
+ var schema234 = z.string().min(1).max(64);
1420
+ var schema244 = z.string().max(200);
1421
+ var schema254 = z.record(schema234, schema244).refine((value) => Object.keys(value).length <= 16, { message: "Too many keys: at most 16" });
1422
+ var schema264 = z.object({
1000
1423
  "type": schema76,
1001
- "version": schema85,
1002
- "performance": schema1110.optional(),
1003
- "request_id": schema125,
1004
- "session_id": schema135,
1424
+ "version": schema86,
1425
+ "performance": schema1111.optional(),
1426
+ "request_id": schema126,
1427
+ "session_id": schema136,
1005
1428
  "text": schema145,
1006
- "voice_id": schema174,
1007
- "language": schema194,
1008
- "output": schema223,
1009
- "client_metadata": schema253
1429
+ "voice_id": schema175,
1430
+ "language": schema195,
1431
+ "output": schema224,
1432
+ "client_metadata": schema254
1010
1433
  });
1011
1434
  var voiceWebhookWireSchema = schema66;
1012
1435
  var voiceWebhookOptionsSchema = z.strictObject({
@@ -1028,49 +1451,49 @@ function voiceWebhookToWire(input) {
1028
1451
  ...options.timeoutMs !== void 0 ? { timeout_ms: options.timeoutMs } : {}
1029
1452
  };
1030
1453
  }
1031
- var voiceWebhookRequestSchema = schema263;
1454
+ var voiceWebhookRequestSchema = schema264;
1032
1455
  var schema011 = z.url().regex(new RegExp("^\\s*[Hh][Tt][Tt][Pp][Ss]:\\/\\/")).max(500);
1033
1456
  var schema121 = z.string().min(16).max(4096);
1034
- var schema217 = z.boolean();
1035
- var schema310 = z.literal("external");
1036
- var schema410 = z.strictObject({
1037
- "renderer": schema310
1457
+ var schema218 = z.boolean();
1458
+ var schema312 = z.literal("external");
1459
+ var schema412 = z.strictObject({
1460
+ "renderer": schema312
1038
1461
  });
1039
1462
  var schema59 = z.literal("v1");
1040
1463
  var schema67 = z.literal("correlated_pcm_v1");
1041
1464
  var schema77 = z.literal("speech_segments_v1");
1042
- var schema86 = z.literal("v1");
1043
- var schema96 = z.literal(true);
1044
- var schema106 = z.object({
1045
- "performance": schema86,
1046
- "fail_closed": schema96
1047
- });
1048
- var schema1111 = z.literal("correlated_pcm_v1");
1049
- var schema126 = z.object({
1050
- "performance": schema86,
1051
- "fail_closed": schema96,
1052
- "audio_output": schema1111
1053
- });
1054
- var schema136 = z.strictObject({
1465
+ var schema87 = z.literal("v1");
1466
+ var schema97 = z.literal(true);
1467
+ var schema107 = z.object({
1468
+ "performance": schema87,
1469
+ "fail_closed": schema97
1470
+ });
1471
+ var schema1112 = z.literal("correlated_pcm_v1");
1472
+ var schema127 = z.object({
1473
+ "performance": schema87,
1474
+ "fail_closed": schema97,
1475
+ "audio_output": schema1112
1476
+ });
1477
+ var schema137 = z.strictObject({
1055
1478
  "base_url": schema011,
1056
1479
  "token": schema121,
1057
- "fail_closed": schema217.optional(),
1058
- "visible_character": schema410.optional(),
1480
+ "fail_closed": schema218.optional(),
1481
+ "visible_character": schema412.optional(),
1059
1482
  "performance": schema59.optional(),
1060
1483
  "audio_output": schema67.optional(),
1061
1484
  "text_output": schema77.optional()
1062
1485
  }).superRefine((value, ctx) => {
1063
1486
  if (value["audio_output"] !== void 0) {
1064
- const result = schema106.safeParse(value);
1487
+ const result = schema107.safeParse(value);
1065
1488
  if (!result.success) for (const issue of result.error.issues) ctx.addIssue({ code: "custom", message: issue.message, path: issue.path });
1066
1489
  }
1067
1490
  }).superRefine((value, ctx) => {
1068
1491
  if (value["text_output"] !== void 0) {
1069
- const result = schema126.safeParse(value);
1492
+ const result = schema127.safeParse(value);
1070
1493
  if (!result.success) for (const issue of result.error.issues) ctx.addIssue({ code: "custom", message: issue.message, path: issue.path });
1071
1494
  }
1072
1495
  });
1073
- var externalLlmWireSchema = schema136;
1496
+ var externalLlmWireSchema = schema137;
1074
1497
  var externalLlmOptionsSchema = z.strictObject({
1075
1498
  baseUrl: externalLlmWireSchema.shape.base_url,
1076
1499
  token: externalLlmWireSchema.shape.token,
@@ -1093,94 +1516,94 @@ function externalLlmToWire(input) {
1093
1516
  });
1094
1517
  }
1095
1518
  var schema012 = z.string().min(8).max(80);
1096
- var schema127 = z.enum(["eou", "llm", "tts", "decision", "hold", "e2e"]);
1097
- var schema218 = z.literal("interrupt_stop");
1098
- var schema311 = z.union([schema127, schema218]);
1099
- var schema411 = z.int().max(9007199254740991).gt(0);
1519
+ var schema128 = z.enum(["eou", "llm", "tts", "decision", "hold", "e2e"]);
1520
+ var schema219 = z.literal("interrupt_stop");
1521
+ var schema313 = z.union([schema128, schema219]);
1522
+ var schema413 = z.int().max(9007199254740991).gt(0);
1100
1523
  var schema510 = z.number().min(0);
1101
1524
  var schema68 = z.strictObject({
1102
- "count": schema411,
1525
+ "count": schema413,
1103
1526
  "max": schema510,
1104
1527
  "p50": schema510,
1105
1528
  "p90": schema510
1106
1529
  });
1107
- var schema78 = z.partialRecord(schema311, schema68);
1108
- var schema87 = z.literal("available");
1109
- var schema97 = z.literal("dialogue");
1110
- var schema107 = 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+)?)?)$"));
1111
- var schema1112 = z.null();
1112
- var schema128 = z.union([schema107, schema1112]);
1113
- var schema137 = z.int().min(0).max(9007199254740991);
1530
+ var schema78 = z.partialRecord(schema313, schema68);
1531
+ var schema88 = z.literal("available");
1532
+ var schema98 = z.literal("dialogue");
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+)?)?)$"));
1534
+ var schema1113 = z.null();
1535
+ var schema129 = z.union([schema108, schema1113]);
1536
+ var schema138 = z.int().min(0).max(9007199254740991);
1114
1537
  var schema146 = z.strictObject({
1115
- "first_at": schema128,
1116
- "last_at": schema128,
1117
- "lines": schema137
1538
+ "first_at": schema129,
1539
+ "last_at": schema129,
1540
+ "lines": schema138
1118
1541
  });
1119
- var schema156 = z.strictObject({
1542
+ var schema157 = z.strictObject({
1120
1543
  "latency_ms": schema78,
1121
- "status": schema87,
1122
- "sourceRole": schema97,
1544
+ "status": schema88,
1545
+ "sourceRole": schema98,
1123
1546
  "coverage": schema146
1124
1547
  });
1125
- var schema165 = z.literal("unavailable");
1126
- var schema175 = z.enum(["not_closed", "unconfigured", "missing", "invalid", "oversized", "unscorable", "no_measured_latency", "timeout", "aborted", "storage_unavailable"]);
1127
- var schema185 = z.strictObject({
1128
- "status": schema165,
1129
- "reason": schema175
1130
- });
1131
- var schema195 = z.union([schema156, schema185]);
1132
- var schema204 = z.string().min(1).max(200);
1133
- var schema219 = z.union([schema204, schema1112]);
1134
- var schema224 = z.string().regex(new RegExp("^[0-9a-f]{40}$"));
1135
- var schema234 = z.union([schema224, schema1112]);
1136
- var schema244 = z.literal("cloudflare-worker-version");
1137
- var schema254 = z.literal("authenticated-worker-heartbeat");
1138
- var schema264 = z.union([schema254, schema1112]);
1139
- var schema273 = z.string().min(1).max(160);
1140
- var schema282 = z.union([schema273, schema1112]);
1141
- var schema292 = z.union([schema137, schema1112]);
1142
- var schema30 = z.iso.datetime({ offset: true }).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)))$"));
1143
- var schema31 = z.union([schema30, schema1112]);
1144
- var schema322 = z.strictObject({
1145
- "deploymentSource": schema244,
1146
- "workerSource": schema264,
1147
- "workerId": schema282,
1148
- "podStartedAtMs": schema292,
1149
- "workerObservedAt": schema31
1548
+ var schema166 = z.literal("unavailable");
1549
+ var schema176 = z.enum(["not_closed", "unconfigured", "missing", "invalid", "oversized", "unscorable", "no_measured_latency", "timeout", "aborted", "storage_unavailable"]);
1550
+ var schema186 = z.strictObject({
1551
+ "status": schema166,
1552
+ "reason": schema176
1150
1553
  });
1151
- var schema332 = z.strictObject({
1152
- "deploymentId": schema219,
1153
- "workerRevision": schema234,
1154
- "provenance": schema322
1155
- });
1156
- var schema342 = z.string();
1157
- var schema352 = z.union([schema342, schema1112]);
1158
- var schema362 = z.enum(["reserved", "started", "released", "failed"]);
1159
- var schema372 = z.union([schema510, schema1112]);
1554
+ var schema196 = z.union([schema157, schema186]);
1555
+ var schema205 = z.string().min(1).max(200);
1556
+ var schema2110 = z.union([schema205, schema1113]);
1557
+ var schema225 = z.string().regex(new RegExp("^[0-9a-f]{40}$"));
1558
+ var schema235 = z.union([schema225, schema1113]);
1559
+ var schema245 = z.literal("cloudflare-worker-version");
1560
+ var schema255 = z.literal("authenticated-worker-heartbeat");
1561
+ var schema265 = z.union([schema255, schema1113]);
1562
+ var schema274 = z.string().min(1).max(160);
1563
+ var schema283 = z.union([schema274, schema1113]);
1564
+ var schema293 = z.union([schema138, schema1113]);
1565
+ var schema302 = z.iso.datetime({ offset: true }).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)))$"));
1566
+ var schema314 = z.union([schema302, schema1113]);
1567
+ var schema323 = z.strictObject({
1568
+ "deploymentSource": schema245,
1569
+ "workerSource": schema265,
1570
+ "workerId": schema283,
1571
+ "podStartedAtMs": schema293,
1572
+ "workerObservedAt": schema314
1573
+ });
1574
+ var schema333 = z.strictObject({
1575
+ "deploymentId": schema2110,
1576
+ "workerRevision": schema235,
1577
+ "provenance": schema323
1578
+ });
1579
+ var schema343 = z.string();
1580
+ var schema353 = z.union([schema343, schema1113]);
1581
+ var schema363 = z.enum(["reserved", "started", "released", "failed"]);
1582
+ var schema373 = z.union([schema510, schema1113]);
1160
1583
  var schema382 = z.custom((value) => typeof value === "object" && value !== null && !Array.isArray(value));
1161
1584
  var schema392 = z.strictObject({
1162
1585
  "sessionId": schema012,
1163
- "speechDiagnostics": schema195.optional(),
1164
- "releaseIdentity": schema332.optional(),
1165
- "avatarId": schema352,
1166
- "avatarName": schema352,
1167
- "status": schema362,
1168
- "startedAt": schema352,
1169
- "endedAt": schema352,
1170
- "activeSeconds": schema372,
1171
- "billedCreditMicros": schema292,
1586
+ "speechDiagnostics": schema196.optional(),
1587
+ "releaseIdentity": schema333.optional(),
1588
+ "avatarId": schema353,
1589
+ "avatarName": schema353,
1590
+ "status": schema363,
1591
+ "startedAt": schema353,
1592
+ "endedAt": schema353,
1593
+ "activeSeconds": schema373,
1594
+ "billedCreditMicros": schema293,
1172
1595
  "metadata": schema382,
1173
- "createdAt": schema342
1596
+ "createdAt": schema343
1174
1597
  });
1175
- var schema40 = z.array(schema392);
1176
- var schema41 = z.iso.datetime({ offset: true }).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))$"));
1177
- var schema422 = z.strictObject({
1178
- "data": schema40,
1179
- "nextCursor": schema352,
1180
- "from": schema41,
1181
- "to": schema41
1598
+ var schema402 = z.array(schema392);
1599
+ var schema414 = z.iso.datetime({ offset: true }).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))$"));
1600
+ var schema423 = z.strictObject({
1601
+ "data": schema402,
1602
+ "nextCursor": schema353,
1603
+ "from": schema414,
1604
+ "to": schema414
1182
1605
  });
1183
- var listUsageSessionsResponseSchema = schema422;
1606
+ var listUsageSessionsResponseSchema = schema423;
1184
1607
  function toSessionsPage(page) {
1185
1608
  const { data, ...pagination } = page;
1186
1609
  return { ...pagination, sessions: data };
@@ -1191,7 +1614,7 @@ var DEFAULT_BASE_URL = "https://realtimeavatar.ai/api/v1";
1191
1614
  var RENDER_MISMATCH = "Render response did not match the SDK contract";
1192
1615
  var SPEECH_MISMATCH = "Speech response did not match the SDK contract";
1193
1616
  var MAX_SPEECH_RESPONSE_BYTES = 24 * 1024 * 1024;
1194
- var SDK_VERSION = "0.36.0";
1617
+ var SDK_VERSION = "0.38.0";
1195
1618
  var RealtimeAvatar = class {
1196
1619
  #apiKey;
1197
1620
  #baseUrl;
@@ -1394,14 +1817,15 @@ var RealtimeAvatar = class {
1394
1817
  });
1395
1818
  }
1396
1819
  /**
1397
- * Register an app-owned Live2D rig for voice sessions. No assets, motion generation or
1820
+ * Register an Anima avatar for voice sessions: your application owns the rig and the rendering,
1821
+ * the platform owns identity, voice and sessions. No assets, motion generation or
1398
1822
  * automatic voice casting: supply an explicit provider and voice_id, then mint with mode voice.
1399
1823
  */
1400
- async createLive2dAvatar(input) {
1401
- const { voice, ...identity } = createLive2dAvatarInputSchema.parse(input);
1824
+ async createAnimaAvatar(input) {
1825
+ const { voice, ...identity } = createAnimaAvatarInputSchema.parse(input);
1402
1826
  const body = {
1403
1827
  ...identity,
1404
- renderer: "live2d",
1828
+ renderer: "anima",
1405
1829
  sourceKind: "image",
1406
1830
  voice: { voice }
1407
1831
  };
@@ -1792,6 +2216,26 @@ var RealtimeAvatar = class {
1792
2216
  const bytes = await readSpeechBytes(response, signal, metadata.contentType);
1793
2217
  return { bytes, ...metadata };
1794
2218
  }
2219
+ /**
2220
+ * Incremental mono PCM and absolute alignment, without a call or LiveKit. The first next()
2221
+ * starts the paid request; break/return or signal abort cancels it. Never retried. A failed
2222
+ * terminal is yielded, not thrown; malformed/truncated transport throws RealtimeAvatarError.
2223
+ */
2224
+ createSpeechStream(voiceId, input, options = {}) {
2225
+ return speechStreamIterator(async (signal) => {
2226
+ const id = speechVoiceIdSchema.parse(voiceId);
2227
+ const json = createSpeechStreamRequestSchema.parse(input);
2228
+ const response = await this.#request("POST", `/voices/${encodeURIComponent(id)}/speech/stream`, {
2229
+ json,
2230
+ signal,
2231
+ maxRetries: 0
2232
+ });
2233
+ if (!response.ok) {
2234
+ await this.#json(await boundedSpeechErrorResponse(response, signal));
2235
+ }
2236
+ return response;
2237
+ }, Math.max(0, Math.min(this.#timeoutMs, this.#totalTimeoutMs ?? Infinity)), options.signal);
2238
+ }
1795
2239
  // ── internals ────────────────────────────────────────────────────────────
1796
2240
  async #request(method, path, init = {}) {
1797
2241
  const headers = {
@@ -2045,4 +2489,4 @@ var proxyEndRequestSchema = z.object({
2045
2489
  message: "session_id or queue_ticket_id is required"
2046
2490
  });
2047
2491
 
2048
- export { DEFAULT_FISH_TTS_MODEL, FISH_DELIVERY_MODELS, ROUTE_TIMEOUT_MS, RealtimeAvatar, RealtimeAvatarError, RealtimeAvatarHttpError, RealtimeAvatarWebhookError, capacityBusyResponseSchema, clipLibraryDeclarationSchema, createSpeechRequestSchema, externalSpeechSegmentSchema, externalTurnContextSchema, externalUtteranceSchema, fishTtsModelSchema, isQueued, listRecordingsResponseSchema, listRendersResponseSchema, liveKitSessionGrantSchema, proxyConnectRequestSchema, proxyEndRequestSchema, recordingAccessResponseSchema, recordingArtifactSchema, recordingModeSchema, renderAccessResponseSchema, renderSchema, 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 };