@kuralle-syrinx/tts-core 3.1.0 → 4.0.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/package.json +3 -3
- package/src/engine.ts +13 -1
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kuralle-syrinx/tts-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "./src/index.ts",
|
|
8
8
|
"types": "./src/index.ts",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@kuralle-syrinx/core": "
|
|
11
|
-
"@kuralle-syrinx/ws": "
|
|
10
|
+
"@kuralle-syrinx/core": "4.0.0",
|
|
11
|
+
"@kuralle-syrinx/ws": "4.0.0"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"typescript": "^5.7.0",
|
package/src/engine.ts
CHANGED
|
@@ -23,6 +23,18 @@ import type { SocketData } from "@kuralle-syrinx/ws";
|
|
|
23
23
|
import type { AttributionKey, PacketSink, TimerHandle, TimerPort, Transport, WireEvent, WireProtocol } from "./types.js";
|
|
24
24
|
|
|
25
25
|
const EMPTY = new Uint8Array(0);
|
|
26
|
+
// Cancelled-context guard is per-turn (telephony rotates contextIds), so it must
|
|
27
|
+
// stay bounded to a recent-turns window instead of growing for the whole call.
|
|
28
|
+
const MAX_CANCELLED_CONTEXTS = 256;
|
|
29
|
+
|
|
30
|
+
function boundedAdd(set: Set<string>, value: string, cap: number): void {
|
|
31
|
+
set.add(value);
|
|
32
|
+
while (set.size > cap) {
|
|
33
|
+
const oldest = set.values().next().value;
|
|
34
|
+
if (oldest === undefined) break;
|
|
35
|
+
set.delete(oldest);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
26
38
|
|
|
27
39
|
const defaultTimer: TimerPort = {
|
|
28
40
|
set: (ms, fn) => setTimeout(fn, ms),
|
|
@@ -295,7 +307,7 @@ class TtsEngineImpl implements TtsEngine {
|
|
|
295
307
|
}
|
|
296
308
|
|
|
297
309
|
private async cancelContext(contextId: string): Promise<void> {
|
|
298
|
-
this.cancelledContexts
|
|
310
|
+
boundedAdd(this.cancelledContexts, contextId, MAX_CANCELLED_CONTEXTS);
|
|
299
311
|
this.pendingEnd.delete(contextId);
|
|
300
312
|
this.clearFinishTimeout(contextId);
|
|
301
313
|
for (const key of [...(this.contextKeys.get(contextId) ?? [])]) {
|