@vellumai/assistant 0.11.3-dev.202608132015.f8ab72f → 0.11.3-dev.202608140033.273a3d8
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
CHANGED
|
@@ -21,6 +21,7 @@ import type { TrustContext } from "../daemon/trust-context-types.js";
|
|
|
21
21
|
import { DAEMON_INTERNAL_ASSISTANT_ID } from "../runtime/assistant-scope.js";
|
|
22
22
|
import { computeToolApprovalDigest } from "../security/tool-approval-digest.js";
|
|
23
23
|
import { getCatalogProvider } from "../tts/provider-catalog.js";
|
|
24
|
+
import { createReasoningTagFilter } from "../tts/reasoning-tag-filter.js";
|
|
24
25
|
import { extractSpeakableSegments } from "../tts/speakable-segments.js";
|
|
25
26
|
import {
|
|
26
27
|
type AudioStoreSink,
|
|
@@ -728,6 +729,10 @@ export class CallController {
|
|
|
728
729
|
// could be the start of a control marker.
|
|
729
730
|
let ttsBuffer = "";
|
|
730
731
|
let fullResponseText = "";
|
|
732
|
+
// Reasoning models can inline <think> spans in the content stream when a
|
|
733
|
+
// profile has not opted into parseThinkTags; the spoken path must never
|
|
734
|
+
// read them aloud. fullResponseText keeps the raw stream.
|
|
735
|
+
const reasoningFilter = createReasoningTagFilter();
|
|
731
736
|
|
|
732
737
|
// Synthesized path: text is split at speakable boundaries as it streams
|
|
733
738
|
// and each segment is synthesized while the LLM keeps generating. The
|
|
@@ -931,7 +936,7 @@ export class CallController {
|
|
|
931
936
|
return;
|
|
932
937
|
}
|
|
933
938
|
fullResponseText += text;
|
|
934
|
-
ttsBuffer += text;
|
|
939
|
+
ttsBuffer += reasoningFilter.push(text);
|
|
935
940
|
ttsBuffer = stripInternalSpeechMarkers(ttsBuffer);
|
|
936
941
|
flushSafeText();
|
|
937
942
|
};
|
|
@@ -1010,7 +1015,9 @@ export class CallController {
|
|
|
1010
1015
|
return fullResponseText;
|
|
1011
1016
|
}
|
|
1012
1017
|
|
|
1013
|
-
// Final sweep:
|
|
1018
|
+
// Final sweep: release any held-back partial tag, then strip any
|
|
1019
|
+
// remaining control markers from the buffer.
|
|
1020
|
+
ttsBuffer += reasoningFilter.flush();
|
|
1014
1021
|
ttsBuffer = stripInternalSpeechMarkers(ttsBuffer);
|
|
1015
1022
|
if (ttsBuffer.length > 0) {
|
|
1016
1023
|
emitSafeChunk(ttsBuffer);
|
|
@@ -73,6 +73,10 @@ import type {
|
|
|
73
73
|
import { getSubagentManager } from "../subagent/index.js";
|
|
74
74
|
import { liveVoiceEndScreen } from "../telemetry/live-voice-funnel.js";
|
|
75
75
|
import { getToolOwner } from "../tools/registry.js";
|
|
76
|
+
import {
|
|
77
|
+
createReasoningTagFilter,
|
|
78
|
+
type ReasoningTagFilter,
|
|
79
|
+
} from "../tts/reasoning-tag-filter.js";
|
|
76
80
|
import { extractSpeakableSegments } from "../tts/speakable-segments.js";
|
|
77
81
|
import { createAbortReason } from "../util/abort-reasons.js";
|
|
78
82
|
import { hasLocalizedEntry } from "../util/language-subtag.js";
|
|
@@ -717,6 +721,10 @@ interface ActiveAssistantTurn {
|
|
|
717
721
|
// the hand-off idempotent.
|
|
718
722
|
escalationHandedOff: boolean;
|
|
719
723
|
ttsBuffer: string;
|
|
724
|
+
// Strips inline <think> reasoning spans from the spoken stream. Stateful
|
|
725
|
+
// per turn because spans and tags cross delta boundaries; display frames
|
|
726
|
+
// keep the raw text.
|
|
727
|
+
ttsReasoningFilter: ReasoningTagFilter;
|
|
720
728
|
// A non-empty speakable segment reached the TTS queue — gates the eager
|
|
721
729
|
// first-segment flush that trades clause quality for speech onset.
|
|
722
730
|
ttsSegmentEnqueued: boolean;
|
|
@@ -4503,6 +4511,7 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
4503
4511
|
deltaEpoch: 0,
|
|
4504
4512
|
escalationHandedOff: false,
|
|
4505
4513
|
ttsBuffer: "",
|
|
4514
|
+
ttsReasoningFilter: createReasoningTagFilter(),
|
|
4506
4515
|
ttsSegmentEnqueued: false,
|
|
4507
4516
|
ttsJobs: [],
|
|
4508
4517
|
ttsQueue: Promise.resolve(),
|
|
@@ -5492,7 +5501,7 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
5492
5501
|
return;
|
|
5493
5502
|
}
|
|
5494
5503
|
|
|
5495
|
-
activeTurn.ttsBuffer += text;
|
|
5504
|
+
activeTurn.ttsBuffer += activeTurn.ttsReasoningFilter.push(text);
|
|
5496
5505
|
this.flushTtsBuffer(token, false);
|
|
5497
5506
|
}
|
|
5498
5507
|
|
|
@@ -5503,6 +5512,7 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
5503
5512
|
}
|
|
5504
5513
|
|
|
5505
5514
|
this.clearFillerTimers(activeTurn);
|
|
5515
|
+
activeTurn.ttsBuffer += activeTurn.ttsReasoningFilter.flush();
|
|
5506
5516
|
this.flushTtsBuffer(token, true);
|
|
5507
5517
|
activeTurn.ttsQueue = activeTurn.ttsQueue
|
|
5508
5518
|
.catch(() => {})
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import { createReasoningTagFilter } from "../reasoning-tag-filter.js";
|
|
4
|
+
|
|
5
|
+
function run(chunks: string[]): string {
|
|
6
|
+
const filter = createReasoningTagFilter();
|
|
7
|
+
let out = "";
|
|
8
|
+
for (const chunk of chunks) {
|
|
9
|
+
out += filter.push(chunk);
|
|
10
|
+
}
|
|
11
|
+
out += filter.flush();
|
|
12
|
+
return out;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe("ReasoningTagFilter", () => {
|
|
16
|
+
test("passes plain text through unchanged", () => {
|
|
17
|
+
expect(run(["Hello ", "there."])).toBe("Hello there.");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("drops a complete think span within one delta", () => {
|
|
21
|
+
expect(run(["<think>hm, let me reason</think>Answer."])).toBe("Answer.");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("drops a reasoning span crossing many deltas", () => {
|
|
25
|
+
expect(
|
|
26
|
+
run(["<thi", "nk>step one", " step two", "</th", "ink>Spoken reply"]),
|
|
27
|
+
).toBe("Spoken reply");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("drops thinking-tag variant and is case-insensitive", () => {
|
|
31
|
+
expect(run(["<Thinking>inner</Thinking>ok"])).toBe("ok");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("keeps text before and after the span", () => {
|
|
35
|
+
expect(run(["Sure. <think>secret</think> Done."])).toBe("Sure. Done.");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("handles multiple spans in one turn", () => {
|
|
39
|
+
expect(run(["a<think>x</think>b", "<think>y", "z</think>c"])).toBe("abc");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("an unclosed span at end of stream stays dropped", () => {
|
|
43
|
+
expect(run(["ok<think>never closes"])).toBe("ok");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("a dangling partial open tag is released as literal text at flush", () => {
|
|
47
|
+
expect(run(["price <th"])).toBe("price <th");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("a false partial that disambiguates to text is released", () => {
|
|
51
|
+
expect(run(["a <th", "ree-step plan"])).toBe("a <three-step plan");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("does not touch angle brackets that are not think tags", () => {
|
|
55
|
+
expect(run(["use <b>bold</b> and x < y"])).toBe(
|
|
56
|
+
"use <b>bold</b> and x < y",
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("holds back nothing across an empty stream", () => {
|
|
61
|
+
expect(run([""])).toBe("");
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streaming reasoning-tag filter for the TTS pipelines.
|
|
3
|
+
*
|
|
4
|
+
* Some OpenAI-compatible reasoning models emit their chain of thought inline
|
|
5
|
+
* in the content stream as `<think>...</think>` (or `<thinking>...</thinking>`)
|
|
6
|
+
* spans. When a profile has not opted into the chat-completions provider's
|
|
7
|
+
* `parseThinkTags` (which re-routes those spans to `thinking_delta`), the raw
|
|
8
|
+
* reasoning rides `text_delta`, and anything downstream that speaks text
|
|
9
|
+
* deltas would read the model's inner monologue aloud and delay real speech
|
|
10
|
+
* by the full length of the reasoning.
|
|
11
|
+
*
|
|
12
|
+
* This filter is the TTS-boundary guard: voice output must never speak
|
|
13
|
+
* reasoning regardless of profile configuration. It is stateful because a
|
|
14
|
+
* tag or a reasoning span routinely crosses delta boundaries; feed every
|
|
15
|
+
* delta through {@link ReasoningTagFilter.push} and call
|
|
16
|
+
* {@link ReasoningTagFilter.flush} when the turn's stream ends.
|
|
17
|
+
*
|
|
18
|
+
* Display paths are deliberately untouched: `assistant_text_delta` frames
|
|
19
|
+
* keep the raw text, exactly like the markdown handling in
|
|
20
|
+
* `calls/tts-text-sanitizer.ts`.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const OPEN_TAGS = ["<think>", "<thinking>"] as const;
|
|
24
|
+
const CLOSE_TAGS = ["</think>", "</thinking>"] as const;
|
|
25
|
+
|
|
26
|
+
/** Longest suffix of `text` that is a proper prefix of any listed tag. */
|
|
27
|
+
function partialTagSuffix(text: string, tags: readonly string[]): number {
|
|
28
|
+
const max = Math.max(...tags.map((tag) => tag.length)) - 1;
|
|
29
|
+
const window = Math.min(max, text.length);
|
|
30
|
+
for (let len = window; len > 0; len -= 1) {
|
|
31
|
+
const suffix = text.slice(text.length - len).toLowerCase();
|
|
32
|
+
if (tags.some((tag) => tag.startsWith(suffix))) {
|
|
33
|
+
return len;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function indexOfAny(
|
|
40
|
+
haystack: string,
|
|
41
|
+
tags: readonly string[],
|
|
42
|
+
): { index: number; tag: string } | null {
|
|
43
|
+
const lower = haystack.toLowerCase();
|
|
44
|
+
let best: { index: number; tag: string } | null = null;
|
|
45
|
+
for (const tag of tags) {
|
|
46
|
+
const index = lower.indexOf(tag);
|
|
47
|
+
if (index >= 0 && (best === null || index < best.index)) {
|
|
48
|
+
best = { index, tag };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return best;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export class ReasoningTagFilter {
|
|
55
|
+
private insideReasoning = false;
|
|
56
|
+
private pending = "";
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Feed one streamed delta; returns the speakable text it releases.
|
|
60
|
+
* Reasoning spans are dropped; a partial tag at the end of the buffer is
|
|
61
|
+
* held back until the next delta disambiguates it.
|
|
62
|
+
*/
|
|
63
|
+
push(text: string): string {
|
|
64
|
+
this.pending += text;
|
|
65
|
+
let out = "";
|
|
66
|
+
for (;;) {
|
|
67
|
+
if (this.insideReasoning) {
|
|
68
|
+
const close = indexOfAny(this.pending, CLOSE_TAGS);
|
|
69
|
+
if (close) {
|
|
70
|
+
this.pending = this.pending.slice(close.index + close.tag.length);
|
|
71
|
+
this.insideReasoning = false;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
// Everything buffered is reasoning except a possible partial close
|
|
75
|
+
// tag at the end; drop the reasoning, keep the partial.
|
|
76
|
+
const partial = partialTagSuffix(this.pending, CLOSE_TAGS);
|
|
77
|
+
this.pending = partial > 0 ? this.pending.slice(-partial) : "";
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
const open = indexOfAny(this.pending, OPEN_TAGS);
|
|
81
|
+
if (open) {
|
|
82
|
+
out += this.pending.slice(0, open.index);
|
|
83
|
+
this.pending = this.pending.slice(open.index + open.tag.length);
|
|
84
|
+
this.insideReasoning = true;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const partial = partialTagSuffix(this.pending, OPEN_TAGS);
|
|
88
|
+
const safeLength = this.pending.length - partial;
|
|
89
|
+
out += this.pending.slice(0, safeLength);
|
|
90
|
+
this.pending = partial > 0 ? this.pending.slice(safeLength) : "";
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* End of stream: release any held-back partial. Outside a reasoning span a
|
|
97
|
+
* dangling "<thin" was ordinary text after all; inside one, the span never
|
|
98
|
+
* closed and its content stays dropped.
|
|
99
|
+
*/
|
|
100
|
+
flush(): string {
|
|
101
|
+
const rest = this.insideReasoning ? "" : this.pending;
|
|
102
|
+
this.pending = "";
|
|
103
|
+
this.insideReasoning = false;
|
|
104
|
+
return rest;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function createReasoningTagFilter(): ReasoningTagFilter {
|
|
109
|
+
return new ReasoningTagFilter();
|
|
110
|
+
}
|