@burdenoff/fe-libs 2026.1030.3 → 2026.1030.4
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/dist/shared/assistant/abortSignal.d.ts +2 -0
- package/dist/shared/assistant/abortSignal.js +9 -0
- package/dist/shared/assistant/history/historyEngine.js +424 -423
- package/dist/shared/assistant/index.d.ts +1 -0
- package/dist/shared/assistant/speech/hostedTtsSpeechEngine.js +137 -136
- package/dist/shared/assistant/workflowApi.js +71 -70
- package/dist/shared-assistant.js +345 -344
- package/package.json +1 -1
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
* any error, which is exactly the kind of quiet loss this file now exists to
|
|
30
30
|
* prevent).
|
|
31
31
|
*/
|
|
32
|
+
export * from './abortSignal';
|
|
32
33
|
export * from './useSandboxAssistantTransport';
|
|
33
34
|
export * from './createSandboxAssistantTransport';
|
|
34
35
|
export * from './runtime';
|
|
@@ -1,40 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { throwIfAborted as e } from "../abortSignal.js";
|
|
2
|
+
import { createAppendSpeechQueue as t } from "./appendSpeechQueue.js";
|
|
3
|
+
import { isPlaybackReferenceAttached as n, tapPlaybackElement as r } from "../voice/handsfree/playbackReference.js";
|
|
4
|
+
import { HOSTED_TTS_TIER as i, HOSTED_VOICES as a, hostedLocaleFor as o } from "./hostedVoiceCatalogue.js";
|
|
5
|
+
import { buildRequest as s, classifyHttpFailure as c, decodeAudioResponse as l, disableDurationMs as u, shouldDisableEngine as d, speakableChunks as f } from "./hostedTtsProtocol.js";
|
|
6
|
+
import { createPieceSink as p, isOutputRefusal as m } from "./pieceSink.js";
|
|
6
7
|
//#region src/shared/assistant/speech/hostedTtsSpeechEngine.ts
|
|
7
|
-
function
|
|
8
|
+
function h(e) {
|
|
8
9
|
let t = Object.entries(e).map(([e, t]) => `${e.toLowerCase()}:${t}`).sort().join("\n"), n = 5381;
|
|
9
10
|
for (let e = 0; e < t.length; e += 1) n = (n << 5) + n + t.charCodeAt(e) | 0;
|
|
10
11
|
return `${t.length}:${n >>> 0}`;
|
|
11
12
|
}
|
|
12
|
-
var
|
|
13
|
+
var g = new Set([
|
|
13
14
|
429,
|
|
14
15
|
502,
|
|
15
16
|
503,
|
|
16
17
|
504
|
|
17
|
-
]),
|
|
18
|
-
function
|
|
18
|
+
]), _ = 3, v = 400, y = 2e3;
|
|
19
|
+
function b(e, t) {
|
|
19
20
|
let n = e === null ? NaN : Number(e);
|
|
20
|
-
return Math.min(Number.isFinite(n) && n >= 0 ? n * 1e3 :
|
|
21
|
+
return Math.min(Number.isFinite(n) && n >= 0 ? n * 1e3 : v * 2 ** (t - 1), y);
|
|
21
22
|
}
|
|
22
|
-
var
|
|
23
|
-
function
|
|
24
|
-
return
|
|
23
|
+
var x = 6e4, S = 2, C = 1e3;
|
|
24
|
+
function w(e) {
|
|
25
|
+
return x + e / C * 2 * 1e3;
|
|
25
26
|
}
|
|
26
|
-
var
|
|
27
|
+
var T = class extends Error {
|
|
27
28
|
reason = "unknown";
|
|
28
29
|
constructor() {
|
|
29
30
|
super("audio output made no progress"), this.name = "OutputStalledError";
|
|
30
31
|
}
|
|
31
32
|
};
|
|
32
|
-
function
|
|
33
|
+
function E(e) {
|
|
33
34
|
let t = 0, n = !1, r = null, i = () => {
|
|
34
35
|
let n = r;
|
|
35
36
|
n !== null && (n.cancel(), n.cancel = e(() => {
|
|
36
|
-
r === n && (r = null, n.fail(new
|
|
37
|
-
},
|
|
37
|
+
r === n && (r = null, n.fail(new T()));
|
|
38
|
+
}, w(t)));
|
|
38
39
|
};
|
|
39
40
|
return {
|
|
40
41
|
handed(e) {
|
|
@@ -65,14 +66,14 @@ function T(e) {
|
|
|
65
66
|
}
|
|
66
67
|
};
|
|
67
68
|
}
|
|
68
|
-
var
|
|
69
|
-
function k() {
|
|
70
|
-
for (let e of [...D]) e();
|
|
71
|
-
}
|
|
69
|
+
var D = "data:audio/wav;base64,UklGRiQAAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YQAAAAA=", O = [], k = 4;
|
|
72
70
|
function A() {
|
|
73
|
-
|
|
71
|
+
for (let e of [...O]) e();
|
|
72
|
+
}
|
|
73
|
+
function j() {
|
|
74
|
+
O.length = 0;
|
|
74
75
|
}
|
|
75
|
-
function
|
|
76
|
+
function M(e, t) {
|
|
76
77
|
return new Promise((n) => {
|
|
77
78
|
if (t.aborted) {
|
|
78
79
|
n();
|
|
@@ -87,238 +88,238 @@ function j(e, t) {
|
|
|
87
88
|
t.addEventListener("abort", i, { once: !0 });
|
|
88
89
|
});
|
|
89
90
|
}
|
|
90
|
-
function
|
|
91
|
-
let
|
|
91
|
+
function N(v) {
|
|
92
|
+
let y = v.fetchImpl ?? ((...e) => fetch(...e)), x = v.now ?? (() => Date.now()), S = v.setTimer ?? ((e, t) => {
|
|
92
93
|
let n = setTimeout(e, t);
|
|
93
94
|
return () => clearTimeout(n);
|
|
94
|
-
}),
|
|
95
|
-
if (!(
|
|
96
|
-
let e =
|
|
97
|
-
if (
|
|
98
|
-
e.muted = !0, e.src =
|
|
99
|
-
|
|
95
|
+
}), C = null, w = null, A = null, j = !1, N = () => {
|
|
96
|
+
if (!(j || typeof Audio != "function")) try {
|
|
97
|
+
let e = A ?? new Audio();
|
|
98
|
+
if (A = e, C === e) return;
|
|
99
|
+
e.muted = !0, e.src = D, Promise.resolve(e.play()).then(() => {
|
|
100
|
+
A === e && C !== e && e.pause();
|
|
100
101
|
}, () => {});
|
|
101
102
|
} catch {}
|
|
102
103
|
};
|
|
103
|
-
|
|
104
|
-
let
|
|
104
|
+
O.push(N), O.length > k && O.shift();
|
|
105
|
+
let P = 0, F = null, I = null, L = null, R = null, z = 0, B = null, V = null, H = () => {
|
|
105
106
|
try {
|
|
106
|
-
return
|
|
107
|
+
return v.getHeaders?.() ?? {};
|
|
107
108
|
} catch {
|
|
108
109
|
return {};
|
|
109
110
|
}
|
|
110
|
-
},
|
|
111
|
-
for (let e of [...
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
},
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
let e =
|
|
111
|
+
}, U = () => x() >= z ? !1 : V === null ? !0 : h(H()) === V, W = /* @__PURE__ */ new Set(), G = () => {
|
|
112
|
+
for (let e of [...W]) e();
|
|
113
|
+
}, K = () => {
|
|
114
|
+
B !== null && clearTimeout(B), B = null;
|
|
115
|
+
}, q = (e) => {
|
|
116
|
+
K(), B = setTimeout(() => {
|
|
117
|
+
B = null;
|
|
118
|
+
let e = z - x();
|
|
118
119
|
if (e > 0) {
|
|
119
|
-
|
|
120
|
+
q(e);
|
|
120
121
|
return;
|
|
121
122
|
}
|
|
122
|
-
|
|
123
|
+
G();
|
|
123
124
|
}, e);
|
|
124
|
-
},
|
|
125
|
-
|
|
126
|
-
}, J = () => {
|
|
127
|
-
C &&= (URL.revokeObjectURL(C), null);
|
|
125
|
+
}, J = (e, t) => {
|
|
126
|
+
z = x() + e, V = t, q(e), G();
|
|
128
127
|
}, Y = () => {
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
w &&= (URL.revokeObjectURL(w), null);
|
|
129
|
+
}, X = () => {
|
|
130
|
+
if (C) {
|
|
131
|
+
C.onended = null, C.onerror = null;
|
|
131
132
|
try {
|
|
132
|
-
|
|
133
|
+
C.pause();
|
|
133
134
|
} catch {}
|
|
134
|
-
|
|
135
|
+
C = null;
|
|
135
136
|
}
|
|
136
|
-
|
|
137
|
+
Y();
|
|
137
138
|
};
|
|
138
|
-
async function
|
|
139
|
-
let
|
|
140
|
-
for (let
|
|
139
|
+
async function Z(t, n, r, a = !1) {
|
|
140
|
+
let u = s(t, o(n.lang) ?? n.lang, i, n.voice?.name ?? null, n.rate), d = v.getHeaders?.() ?? {}, f;
|
|
141
|
+
for (let t = 1; e(r), f = await y(v.endpoint, {
|
|
141
142
|
method: "POST",
|
|
142
|
-
signal:
|
|
143
|
+
signal: r,
|
|
143
144
|
headers: {
|
|
144
145
|
"content-type": "application/json",
|
|
145
|
-
...
|
|
146
|
+
...d
|
|
146
147
|
},
|
|
147
|
-
body: JSON.stringify(
|
|
148
|
-
}), !
|
|
149
|
-
if (!(
|
|
150
|
-
let e = /* @__PURE__ */ Error(`hosted tts ${
|
|
151
|
-
throw e.reason =
|
|
148
|
+
body: JSON.stringify(u)
|
|
149
|
+
}), !f.ok; t += 1) {
|
|
150
|
+
if (!(g.has(f.status) && t < _ && !r.aborted)) {
|
|
151
|
+
let e = /* @__PURE__ */ Error(`hosted tts ${f.status}`);
|
|
152
|
+
throw e.reason = a && f.status === 429 ? "rate-limited" : c(f.status), e.headers = h(d), e;
|
|
152
153
|
}
|
|
153
|
-
await
|
|
154
|
+
await M(b(f.headers.get("retry-after"), t), r);
|
|
154
155
|
}
|
|
155
|
-
let
|
|
156
|
-
if (!
|
|
156
|
+
let p = f.headers.get("content-type"), m = l(p, p?.includes("json") ? await f.json() : await f.arrayBuffer());
|
|
157
|
+
if (!m) {
|
|
157
158
|
let e = /* @__PURE__ */ Error("hosted tts returned no audio");
|
|
158
159
|
throw e.reason = "unknown", e;
|
|
159
160
|
}
|
|
160
|
-
return
|
|
161
|
+
return m;
|
|
161
162
|
}
|
|
162
|
-
function
|
|
163
|
+
function Q(e, t, i) {
|
|
163
164
|
return new Promise((a, o) => {
|
|
164
|
-
if (
|
|
165
|
+
if (t !== P) {
|
|
165
166
|
a();
|
|
166
167
|
return;
|
|
167
168
|
}
|
|
168
169
|
let s = new Blob([e.slice().buffer], { type: "audio/mpeg" });
|
|
169
|
-
|
|
170
|
+
Y(), w = URL.createObjectURL(s);
|
|
170
171
|
let c;
|
|
171
|
-
|
|
172
|
-
|
|
172
|
+
n() ? (c = new Audio(w), r(c)) : (c = A ?? new Audio(), A = c, c.muted = !1, c.src = w), C = c, c.onended = () => {
|
|
173
|
+
t === P && a();
|
|
173
174
|
}, c.onerror = () => {
|
|
174
|
-
if (
|
|
175
|
+
if (t !== P) {
|
|
175
176
|
a();
|
|
176
177
|
return;
|
|
177
178
|
}
|
|
178
179
|
let e = /* @__PURE__ */ Error("audio playback failed");
|
|
179
180
|
e.reason = "unknown", o(e);
|
|
180
181
|
}, c.play().then(() => {
|
|
181
|
-
c ===
|
|
182
|
+
c === A && !c.muted && (j = !0), t === P && i?.();
|
|
182
183
|
}, (e) => {
|
|
183
|
-
if (
|
|
184
|
+
if (t !== P) {
|
|
184
185
|
a();
|
|
185
186
|
return;
|
|
186
187
|
}
|
|
187
|
-
let
|
|
188
|
-
|
|
188
|
+
let n = /* @__PURE__ */ Error("audio play rejected"), r = e?.name === "NotAllowedError";
|
|
189
|
+
n.reason = r ? "not-allowed" : "unknown", n.transient = r, o(n);
|
|
189
190
|
});
|
|
190
191
|
});
|
|
191
192
|
}
|
|
192
|
-
let
|
|
193
|
+
let $ = {
|
|
193
194
|
id: "hosted-tts",
|
|
194
195
|
isSupported() {
|
|
195
|
-
return
|
|
196
|
+
return U() ? !1 : typeof window < "u" && typeof window.Audio == "function" && typeof fetch == "function";
|
|
196
197
|
},
|
|
197
198
|
listVoices() {
|
|
198
|
-
return
|
|
199
|
+
return U() ? [] : [...a];
|
|
199
200
|
},
|
|
200
201
|
subscribeVoices(e) {
|
|
201
|
-
return
|
|
202
|
-
|
|
202
|
+
return W.add(e), () => {
|
|
203
|
+
W.delete(e);
|
|
203
204
|
};
|
|
204
205
|
},
|
|
205
206
|
speak(e, t, n = {}) {
|
|
206
|
-
|
|
207
|
-
let r =
|
|
207
|
+
I?.cancel(), I = null;
|
|
208
|
+
let r = f(e);
|
|
208
209
|
if (r.length === 0) {
|
|
209
210
|
n.onEnd?.();
|
|
210
211
|
return;
|
|
211
212
|
}
|
|
212
|
-
|
|
213
|
-
let i =
|
|
214
|
-
|
|
213
|
+
P += 1;
|
|
214
|
+
let i = P;
|
|
215
|
+
X(), L?.cancel(), R?.stop(), N();
|
|
215
216
|
let a = new AbortController();
|
|
216
|
-
|
|
217
|
+
F = a;
|
|
217
218
|
let o = !1, s = () => {
|
|
218
219
|
o || (o = !0, n.onStart?.());
|
|
219
220
|
}, c = (e) => {
|
|
220
|
-
let n =
|
|
221
|
+
let n = Z(e, t, a.signal);
|
|
221
222
|
return n.catch(() => {}), n;
|
|
222
|
-
},
|
|
223
|
-
play: (e) =>
|
|
224
|
-
isCurrent: () => i ===
|
|
223
|
+
}, l = t.audioOutput ? E(S) : null, h = t.audioOutput ? p(t.audioOutput, {
|
|
224
|
+
play: (e) => Q(e, i, s),
|
|
225
|
+
isCurrent: () => i === P,
|
|
225
226
|
onChunkStart: (e) => {
|
|
226
|
-
|
|
227
|
+
l?.progress(), n.onChunkStart?.(e);
|
|
227
228
|
},
|
|
228
229
|
onStart: s
|
|
229
230
|
}) : null;
|
|
230
|
-
|
|
231
|
-
let g = (e) =>
|
|
232
|
-
h && (
|
|
231
|
+
L = h, R = l;
|
|
232
|
+
let g = (e) => l ? l.guard(e) : e, _ = () => {
|
|
233
|
+
h && (l?.stop(), R === l && (R = null), L === h && (L = null));
|
|
233
234
|
};
|
|
234
235
|
(async () => {
|
|
235
236
|
try {
|
|
236
237
|
let e = c(r[0]);
|
|
237
238
|
for (let t = 0; t < r.length; t += 1) {
|
|
238
|
-
if (i !==
|
|
239
|
+
if (i !== P) return;
|
|
239
240
|
let a = await e;
|
|
240
|
-
if (i !==
|
|
241
|
+
if (i !== P) return;
|
|
241
242
|
let o = r[t + 1];
|
|
242
243
|
if (o !== void 0 && (e = c(o)), h) {
|
|
243
|
-
|
|
244
|
+
l?.handed(a.byteLength), await g(h.write(a));
|
|
244
245
|
continue;
|
|
245
246
|
}
|
|
246
|
-
n.onChunkStart?.(t), await
|
|
247
|
+
n.onChunkStart?.(t), await Q(a, i, s);
|
|
247
248
|
}
|
|
248
249
|
if (h) {
|
|
249
250
|
let e = await g(h.drain());
|
|
250
|
-
if (i !==
|
|
251
|
+
if (i !== P) return;
|
|
251
252
|
if (!e) throw Object.assign(/* @__PURE__ */ Error("audio output did not finish"), { reason: "unknown" });
|
|
252
253
|
}
|
|
253
|
-
i ===
|
|
254
|
+
i === P && (_(), n.onEnd?.());
|
|
254
255
|
} catch (e) {
|
|
255
|
-
if (a.abort(), i !==
|
|
256
|
+
if (a.abort(), i !== P) return;
|
|
256
257
|
let t = null;
|
|
257
258
|
if (h) {
|
|
258
|
-
let n = e instanceof
|
|
259
|
-
if (i !==
|
|
260
|
-
h.cancel(),
|
|
259
|
+
let n = e instanceof T ? null : await g(h.drain()).then(() => null, (e) => e);
|
|
260
|
+
if (i !== P) return;
|
|
261
|
+
h.cancel(), m(e) ? t = e : m(n) && (t = n);
|
|
261
262
|
}
|
|
262
|
-
if (
|
|
263
|
+
if (P += 1, X(), _(), t) {
|
|
263
264
|
n.onError?.("output-not-cleared");
|
|
264
265
|
return;
|
|
265
266
|
}
|
|
266
267
|
let r = e?.reason;
|
|
267
|
-
|
|
268
|
+
d(r, e?.transient === !0) && J(u(r), r === "not-allowed" ? e.headers ?? null : null), n.onError?.(r === "not-allowed" || r === "unsupported" || r === "cancelled" ? r : "unknown");
|
|
268
269
|
}
|
|
269
270
|
})();
|
|
270
271
|
},
|
|
271
|
-
open(
|
|
272
|
-
|
|
273
|
-
let r = ++
|
|
274
|
-
|
|
275
|
-
let i =
|
|
276
|
-
play: (e) =>
|
|
277
|
-
isCurrent: () => r ===
|
|
272
|
+
open(e, n = {}) {
|
|
273
|
+
$.cancel();
|
|
274
|
+
let r = ++P;
|
|
275
|
+
N();
|
|
276
|
+
let i = e.audioOutput ? E(S) : null, a, o = -1, s = -1, c = -1, l = null, f = e.audioOutput ? p(e.audioOutput, {
|
|
277
|
+
play: (e) => Q(e, r, () => a?.()),
|
|
278
|
+
isCurrent: () => r === P,
|
|
278
279
|
onChunkStart: () => {},
|
|
279
280
|
onStart: () => a?.()
|
|
280
281
|
}) : null;
|
|
281
|
-
|
|
282
|
+
L = f, R = i;
|
|
282
283
|
let h = (e) => i ? i.guard(e) : e, g = async () => {
|
|
283
|
-
if (
|
|
284
|
+
if (f && !await h(f.drain())) throw Error("audio output did not finish");
|
|
284
285
|
}, _ = () => {
|
|
285
|
-
i?.stop(),
|
|
286
|
-
}, v =
|
|
287
|
-
prepare: async (
|
|
286
|
+
i?.stop(), R === i && (R = null), L === f && (L = null), I === v && (I = null);
|
|
287
|
+
}, v = t({
|
|
288
|
+
prepare: async (t, n) => {
|
|
288
289
|
try {
|
|
289
|
-
return await
|
|
290
|
+
return await Z(t, e, n, !0);
|
|
290
291
|
} catch (e) {
|
|
291
292
|
if (n.aborted) throw e;
|
|
292
293
|
try {
|
|
293
294
|
await g();
|
|
294
295
|
} catch (e) {
|
|
295
|
-
if (
|
|
296
|
+
if (m(e)) throw e;
|
|
296
297
|
}
|
|
297
298
|
throw e;
|
|
298
299
|
}
|
|
299
300
|
},
|
|
300
301
|
play: async (e, t, n) => {
|
|
301
|
-
if (!
|
|
302
|
+
if (!f) {
|
|
302
303
|
c = t;
|
|
303
304
|
let i = new Promise((e) => {
|
|
304
|
-
|
|
305
|
+
l = e;
|
|
305
306
|
});
|
|
306
|
-
await Promise.race([
|
|
307
|
+
await Promise.race([Q(e, r, n), i]), l = null;
|
|
307
308
|
return;
|
|
308
309
|
}
|
|
309
|
-
a = n, o += 1, s = t, i?.handed(e.byteLength), await h(
|
|
310
|
+
a = n, o += 1, s = t, i?.handed(e.byteLength), await h(f.write(e));
|
|
310
311
|
},
|
|
311
312
|
drain: g,
|
|
312
313
|
retract: (e) => {
|
|
313
|
-
|
|
314
|
+
f && s >= e ? f.retract(o) : !f && c >= e && (X(), l?.());
|
|
314
315
|
},
|
|
315
316
|
cancel: () => {
|
|
316
|
-
|
|
317
|
+
P += 1, X(), l?.(), f?.cancel(), _();
|
|
317
318
|
},
|
|
318
319
|
failed: (e) => {
|
|
319
|
-
if (
|
|
320
|
+
if (m(e)) return "output-not-cleared";
|
|
320
321
|
let t = e, n = t?.reason;
|
|
321
|
-
return
|
|
322
|
+
return d(n, t?.transient === !0) && J(u(n), n === "not-allowed" ? t?.headers ?? null : null), n === "not-allowed" || n === "unsupported" || n === "cancelled" || n === "rate-limited" ? n : "unknown";
|
|
322
323
|
}
|
|
323
324
|
}, {
|
|
324
325
|
...n,
|
|
@@ -326,17 +327,17 @@ function M(_) {
|
|
|
326
327
|
_(), n.onEnd?.();
|
|
327
328
|
}
|
|
328
329
|
});
|
|
329
|
-
return
|
|
330
|
+
return I = v, v;
|
|
330
331
|
},
|
|
331
332
|
headersChanged() {
|
|
332
|
-
|
|
333
|
+
x() >= z || V === null || U() || (z = 0, V = null, K(), G());
|
|
333
334
|
},
|
|
334
335
|
cancel() {
|
|
335
|
-
let e =
|
|
336
|
-
|
|
336
|
+
let e = I;
|
|
337
|
+
I = null, e?.cancel(), P += 1, F?.abort(), F = null, X(), L?.cancel(), L = null, R?.stop(), R = null;
|
|
337
338
|
}
|
|
338
339
|
};
|
|
339
|
-
return
|
|
340
|
+
return $;
|
|
340
341
|
}
|
|
341
342
|
//#endregion
|
|
342
|
-
export {
|
|
343
|
+
export { C as HOSTED_OUTPUT_MIN_AUDIO_BYTES_PER_SECOND, S as HOSTED_OUTPUT_STALL_AUDIO_RATIO, x as HOSTED_OUTPUT_STALL_BASE_MS, D as SILENT_WAV_DATA_URI, N as createHostedTtsEngine, w as hostedOutputStallMs, A as primeHostedPlayback, j as resetHostedPlaybackForTest, b as retryDelayMs };
|