@fonoster/voice 0.53.0 → 0.54.1
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/Session.d.ts +5 -0
- package/dist/Session.js +49 -5
- package/package.json +5 -5
package/dist/Session.d.ts
CHANGED
|
@@ -72,6 +72,10 @@ export declare class Session {
|
|
|
72
72
|
private frameListeners;
|
|
73
73
|
private gatherState?;
|
|
74
74
|
private buffered;
|
|
75
|
+
/** The caller is mid-turn: a turn.user_started with no turn.ended yet. */
|
|
76
|
+
private midTurn;
|
|
77
|
+
/** A gather gave up on the current turn; its late turn.ended is dropped, not buffered. */
|
|
78
|
+
private turnExpired;
|
|
75
79
|
private lastWarmTransfer?;
|
|
76
80
|
/** A pending completeTransfer(), rejected when AppBridge refuses it. */
|
|
77
81
|
private completing?;
|
|
@@ -148,6 +152,7 @@ export declare class Session {
|
|
|
148
152
|
private input;
|
|
149
153
|
private feedGather;
|
|
150
154
|
private armGatherTimer;
|
|
155
|
+
private armBackstop;
|
|
151
156
|
private endGather;
|
|
152
157
|
private nextId;
|
|
153
158
|
private send;
|
package/dist/Session.js
CHANGED
|
@@ -30,6 +30,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
30
30
|
exports.Session = void 0;
|
|
31
31
|
const errors_1 = require("./errors");
|
|
32
32
|
const DEFAULT_GATHER_TIMEOUT_MS = 4000;
|
|
33
|
+
/**
|
|
34
|
+
* How long past its timeout a gather waits for a turn in progress to end. Mirrors AppBridge's 10 s
|
|
35
|
+
* abandon window, so a turn AppBridge never ends can't hold a gather forever.
|
|
36
|
+
*/
|
|
37
|
+
const GATHER_TURN_BACKSTOP_MS = 10000;
|
|
33
38
|
/** Commands that make AppBridge start listening (speech recognition and turn events). */
|
|
34
39
|
const SPEECH_COMMANDS = new Set([
|
|
35
40
|
"speak",
|
|
@@ -54,6 +59,10 @@ class Session {
|
|
|
54
59
|
this.listeners = new Map();
|
|
55
60
|
this.frameListeners = new Set();
|
|
56
61
|
this.buffered = [];
|
|
62
|
+
/** The caller is mid-turn: a turn.user_started with no turn.ended yet. */
|
|
63
|
+
this.midTurn = false;
|
|
64
|
+
/** A gather gave up on the current turn; its late turn.ended is dropped, not buffered. */
|
|
65
|
+
this.turnExpired = false;
|
|
57
66
|
this.listening = false;
|
|
58
67
|
this.signedFor = signedFor;
|
|
59
68
|
this.sessionRef = start.sessionRef;
|
|
@@ -179,7 +188,11 @@ class Session {
|
|
|
179
188
|
reject
|
|
180
189
|
};
|
|
181
190
|
this.gatherState = g;
|
|
182
|
-
|
|
191
|
+
// A caller already talking gets to finish: wait for the turn, not the normal timer.
|
|
192
|
+
if (g.speech && this.midTurn)
|
|
193
|
+
this.armBackstop(g);
|
|
194
|
+
else
|
|
195
|
+
this.armGatherTimer(g);
|
|
183
196
|
// Inputs that arrived before the gather (type-ahead) count, in order.
|
|
184
197
|
const backlog = this.buffered;
|
|
185
198
|
this.buffered = [];
|
|
@@ -384,6 +397,8 @@ class Session {
|
|
|
384
397
|
return this.input({ type: "turn.user_started" });
|
|
385
398
|
case "turn.likely_ended":
|
|
386
399
|
case "turn.resumed":
|
|
400
|
+
this.emit(type, this.without(msg, "type"));
|
|
401
|
+
return this.input({ type });
|
|
387
402
|
case "turn.backchannel":
|
|
388
403
|
case "transcript.partial":
|
|
389
404
|
case "turn.estimate":
|
|
@@ -425,9 +440,21 @@ class Session {
|
|
|
425
440
|
}
|
|
426
441
|
// ---- gather -----------------------------------------------------------------------
|
|
427
442
|
input(input) {
|
|
443
|
+
if (input.type === "turn.user_started") {
|
|
444
|
+
this.midTurn = true;
|
|
445
|
+
this.turnExpired = false;
|
|
446
|
+
}
|
|
447
|
+
else if (input.type === "turn.ended") {
|
|
448
|
+
const expired = this.turnExpired;
|
|
449
|
+
this.midTurn = false;
|
|
450
|
+
this.turnExpired = false;
|
|
451
|
+
// The late end of a turn a gather already gave up on doesn't answer the next gather.
|
|
452
|
+
if (expired && !this.gatherState)
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
428
455
|
if (this.gatherState)
|
|
429
456
|
return this.feedGather(input);
|
|
430
|
-
if (input.type
|
|
457
|
+
if (input.type !== "turn.ended" && input.type !== "dtmf")
|
|
431
458
|
return;
|
|
432
459
|
this.buffered.push(input);
|
|
433
460
|
if (this.buffered.length > MAX_BUFFERED_INPUTS)
|
|
@@ -435,10 +462,15 @@ class Session {
|
|
|
435
462
|
}
|
|
436
463
|
feedGather(input) {
|
|
437
464
|
const g = this.gatherState;
|
|
438
|
-
if (input.type === "turn.user_started"
|
|
465
|
+
if (input.type === "turn.user_started" ||
|
|
466
|
+
input.type === "turn.likely_ended" ||
|
|
467
|
+
input.type === "turn.resumed") {
|
|
439
468
|
// The caller is talking: wait for the end of the turn instead of timing out mid-sentence.
|
|
440
|
-
|
|
441
|
-
|
|
469
|
+
// Each turn event restarts the backstop.
|
|
470
|
+
if (g.speech &&
|
|
471
|
+
!g.digits &&
|
|
472
|
+
(input.type === "turn.user_started" || g.backstop))
|
|
473
|
+
this.armBackstop(g);
|
|
442
474
|
return;
|
|
443
475
|
}
|
|
444
476
|
if (input.type === "turn.ended") {
|
|
@@ -459,8 +491,20 @@ class Session {
|
|
|
459
491
|
armGatherTimer(g) {
|
|
460
492
|
if (g.timer)
|
|
461
493
|
clearTimeout(g.timer);
|
|
494
|
+
g.backstop = false;
|
|
462
495
|
g.timer = setTimeout(() => this.endGather(g.digits ? { digits: g.digits } : {}), g.timeoutMs);
|
|
463
496
|
}
|
|
497
|
+
armBackstop(g) {
|
|
498
|
+
if (g.timer)
|
|
499
|
+
clearTimeout(g.timer);
|
|
500
|
+
g.backstop = true;
|
|
501
|
+
g.timer = setTimeout(() => {
|
|
502
|
+
// The turn never ended: give up on it, so its late turn.ended can't answer a later gather.
|
|
503
|
+
this.midTurn = false;
|
|
504
|
+
this.turnExpired = true;
|
|
505
|
+
this.endGather({});
|
|
506
|
+
}, g.timeoutMs + GATHER_TURN_BACKSTOP_MS);
|
|
507
|
+
}
|
|
464
508
|
endGather(result) {
|
|
465
509
|
const g = this.gatherState;
|
|
466
510
|
if (!g)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/voice",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.54.1",
|
|
4
4
|
"description": "Session SDK for Fonoster voice applications",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/fonoster#readme",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"generate:readme": "fonoster-readme"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@fonoster/common": "^0.
|
|
21
|
-
"@fonoster/logger": "^0.
|
|
20
|
+
"@fonoster/common": "^0.54.0",
|
|
21
|
+
"@fonoster/logger": "^0.54.0",
|
|
22
22
|
"ws": "^8.18.0"
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"bugs": {
|
|
37
37
|
"url": "https://github.com/fonoster/fonoster/issues"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "493553716161a4e30e3882a926d5708c9ecca63a",
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@fonoster/conformance": "^0.
|
|
41
|
+
"@fonoster/conformance": "^0.54.1"
|
|
42
42
|
}
|
|
43
43
|
}
|