@kuralle-syrinx/pipecat-smart-turn 4.1.0 → 4.3.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 +26 -0
- package/package.json +28 -4
- package/src/eos-plugin.ts +564 -0
- package/src/index.ts +15 -515
- package/src/interaction-policy.ts +278 -0
- package/src/predictor.ts +74 -0
- package/src/semantic-completeness.ts +3 -1
- package/src/smart-turn-types.ts +10 -0
- package/src/index.test.ts +0 -803
- package/src/semantic-completeness.test.ts +0 -164
- package/tsconfig.json +0 -21
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
|
|
3
|
-
import { describe, expect, it } from "vitest";
|
|
4
|
-
import {
|
|
5
|
-
fuseEndpointDecision,
|
|
6
|
-
scoreSemanticCompleteness,
|
|
7
|
-
type SemanticEndpointFusionConfig,
|
|
8
|
-
} from "./semantic-completeness.js";
|
|
9
|
-
import { SEMANTIC_LABELED_UTTERANCES } from "./semantic-fixtures.js";
|
|
10
|
-
|
|
11
|
-
const fusionConfig: SemanticEndpointFusionConfig = {
|
|
12
|
-
enabled: true,
|
|
13
|
-
finalizeDelayMs: 250,
|
|
14
|
-
semanticShortcutDelayMs: 50,
|
|
15
|
-
incompleteFallbackMs: 2000,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
describe("scoreSemanticCompleteness", () => {
|
|
19
|
-
it("labels complete utterances as complete", () => {
|
|
20
|
-
for (const fixture of SEMANTIC_LABELED_UTTERANCES.filter((item) => item.category === "complete")) {
|
|
21
|
-
const score = scoreSemanticCompleteness(fixture.text);
|
|
22
|
-
expect(score.complete, fixture.id).toBe(true);
|
|
23
|
-
expect(score.label).toBe("complete");
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("labels mid-thought pauses as incomplete", () => {
|
|
28
|
-
for (const fixture of SEMANTIC_LABELED_UTTERANCES.filter(
|
|
29
|
-
(item) => item.category === "mid_thought_pause",
|
|
30
|
-
)) {
|
|
31
|
-
const score = scoreSemanticCompleteness(fixture.text);
|
|
32
|
-
expect(score.complete, fixture.id).toBe(false);
|
|
33
|
-
expect(score.label).toBe("incomplete");
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("does not treat word count alone as a complete turn", () => {
|
|
38
|
-
const score = scoreSemanticCompleteness("I was wondering if I can still add biology");
|
|
39
|
-
expect(score.complete).toBe(false);
|
|
40
|
-
expect(score.label).toBe("incomplete");
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("labels backchannels as complete turns", () => {
|
|
44
|
-
for (const fixture of SEMANTIC_LABELED_UTTERANCES.filter((item) => item.category === "backchannel")) {
|
|
45
|
-
const score = scoreSemanticCompleteness(fixture.text);
|
|
46
|
-
expect(score.complete, fixture.id).toBe(true);
|
|
47
|
-
expect(score.label).toBe("backchannel");
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe("fuseEndpointDecision", () => {
|
|
53
|
-
it("releases when Smart Turn and semantics agree on completion", () => {
|
|
54
|
-
const decision = fuseEndpointDecision(
|
|
55
|
-
true,
|
|
56
|
-
scoreSemanticCompleteness("What are your office hours?"),
|
|
57
|
-
fusionConfig,
|
|
58
|
-
);
|
|
59
|
-
expect(decision).toEqual({
|
|
60
|
-
release: true,
|
|
61
|
-
requestFinalize: true,
|
|
62
|
-
finalizeDelayMs: 250,
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("defers when Smart Turn approves but semantics are incomplete", () => {
|
|
67
|
-
const decision = fuseEndpointDecision(
|
|
68
|
-
true,
|
|
69
|
-
scoreSemanticCompleteness("I need to know"),
|
|
70
|
-
fusionConfig,
|
|
71
|
-
);
|
|
72
|
-
expect(decision).toEqual({
|
|
73
|
-
release: false,
|
|
74
|
-
requestFinalize: false,
|
|
75
|
-
finalizeDelayMs: 250,
|
|
76
|
-
deferReason: "semantic_incomplete",
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("shortcuts only high-confidence semantics when Smart Turn is uncertain", () => {
|
|
81
|
-
const decision = fuseEndpointDecision(
|
|
82
|
-
false,
|
|
83
|
-
scoreSemanticCompleteness("What are your office hours?"),
|
|
84
|
-
fusionConfig,
|
|
85
|
-
);
|
|
86
|
-
expect(decision).toEqual({
|
|
87
|
-
release: true,
|
|
88
|
-
requestFinalize: true,
|
|
89
|
-
finalizeDelayMs: 50,
|
|
90
|
-
shortcutReason: "semantic_complete",
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("waits for fallback when semantics are weak and Smart Turn is uncertain", () => {
|
|
95
|
-
const decision = fuseEndpointDecision(
|
|
96
|
-
false,
|
|
97
|
-
scoreSemanticCompleteness("I was wondering if I can still add biology"),
|
|
98
|
-
fusionConfig,
|
|
99
|
-
);
|
|
100
|
-
expect(decision).toEqual({
|
|
101
|
-
release: false,
|
|
102
|
-
requestFinalize: false,
|
|
103
|
-
finalizeDelayMs: 2000,
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("waits when both Smart Turn and semantics are incomplete", () => {
|
|
108
|
-
const decision = fuseEndpointDecision(
|
|
109
|
-
false,
|
|
110
|
-
scoreSemanticCompleteness("I need to know"),
|
|
111
|
-
fusionConfig,
|
|
112
|
-
);
|
|
113
|
-
expect(decision).toEqual({
|
|
114
|
-
release: false,
|
|
115
|
-
requestFinalize: false,
|
|
116
|
-
finalizeDelayMs: 2000,
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("falls back to Smart Turn only when semantic endpointing is disabled", () => {
|
|
121
|
-
const decision = fuseEndpointDecision(
|
|
122
|
-
true,
|
|
123
|
-
scoreSemanticCompleteness("I need to know"),
|
|
124
|
-
{ ...fusionConfig, enabled: false },
|
|
125
|
-
);
|
|
126
|
-
expect(decision).toEqual({
|
|
127
|
-
release: true,
|
|
128
|
-
requestFinalize: true,
|
|
129
|
-
finalizeDelayMs: 250,
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
describe("labeled fusion outcomes vs Smart-Turn-only", () => {
|
|
135
|
-
it("releases complete utterances earlier than Smart-Turn-only when acoustics are uncertain", () => {
|
|
136
|
-
const complete = SEMANTIC_LABELED_UTTERANCES.filter((item) => item.category === "complete");
|
|
137
|
-
for (const fixture of complete) {
|
|
138
|
-
const fused = fuseEndpointDecision(false, scoreSemanticCompleteness(fixture.text), fusionConfig);
|
|
139
|
-
const smartTurnOnly = fuseEndpointDecision(
|
|
140
|
-
false,
|
|
141
|
-
scoreSemanticCompleteness(fixture.text),
|
|
142
|
-
{ ...fusionConfig, enabled: false },
|
|
143
|
-
);
|
|
144
|
-
expect(fused.release, fixture.id).toBe(true);
|
|
145
|
-
expect(smartTurnOnly.release, fixture.id).toBe(false);
|
|
146
|
-
expect(fused.finalizeDelayMs).toBeLessThan(fusionConfig.incompleteFallbackMs);
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it("defers mid-thought pauses when Smart Turn would have released", () => {
|
|
151
|
-
const midThought = SEMANTIC_LABELED_UTTERANCES.filter((item) => item.category === "mid_thought_pause");
|
|
152
|
-
for (const fixture of midThought) {
|
|
153
|
-
const fused = fuseEndpointDecision(true, scoreSemanticCompleteness(fixture.text), fusionConfig);
|
|
154
|
-
const smartTurnOnly = fuseEndpointDecision(
|
|
155
|
-
true,
|
|
156
|
-
scoreSemanticCompleteness(fixture.text),
|
|
157
|
-
{ ...fusionConfig, enabled: false },
|
|
158
|
-
);
|
|
159
|
-
expect(fused.release, fixture.id).toBe(false);
|
|
160
|
-
expect(smartTurnOnly.release, fixture.id).toBe(true);
|
|
161
|
-
expect(fused.deferReason).toBe("semantic_incomplete");
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "NodeNext",
|
|
5
|
-
"moduleResolution": "NodeNext",
|
|
6
|
-
"lib": ["ES2022"],
|
|
7
|
-
"strict": true,
|
|
8
|
-
"noUncheckedIndexedAccess": true,
|
|
9
|
-
"noImplicitReturns": true,
|
|
10
|
-
"declaration": true,
|
|
11
|
-
"declarationMap": true,
|
|
12
|
-
"sourceMap": true,
|
|
13
|
-
"outDir": "./dist",
|
|
14
|
-
"rootDir": "./src",
|
|
15
|
-
"esModuleInterop": true,
|
|
16
|
-
"skipLibCheck": true,
|
|
17
|
-
"forceConsistentCasingInFileNames": true
|
|
18
|
-
},
|
|
19
|
-
"include": ["src/**/*.ts"],
|
|
20
|
-
"exclude": ["node_modules", "dist"]
|
|
21
|
-
}
|