@vellumai/assistant 0.12.0-dev.202609111458.db63c16 → 0.12.0-dev.202609111517.cc35b41

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.12.0-dev.202609111458.db63c16",
3
+ "version": "0.12.0-dev.202609111517.cc35b41",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -211,7 +211,7 @@
211
211
  "scope": "client",
212
212
  "key": "internal-thread-actions",
213
213
  "label": "Internal Thread Actions",
214
- "description": "Show the internal thread affordances: 'Fork from here', 'Summarize up to here', and 'Read aloud' on messages, 'Fork Conversation', 'Analyze Conversation', and 'Copy conversation ID' in the thread menu, plus the LLM inspector surfaces. The flag is the sole gate: any session that enables it gets the affordances, including local sessions with no platform identity.",
214
+ "description": "Show the internal thread affordances: 'Fork from here' and 'Summarize up to here' on messages, 'Fork Conversation', 'Analyze Conversation', and 'Copy conversation ID' in the thread menu, plus the LLM inspector surfaces. The flag is the sole gate: any session that enables it gets the affordances, including local sessions with no platform identity.",
215
215
  "defaultEnabled": false
216
216
  },
217
217
  {
@@ -0,0 +1,107 @@
1
+ /**
2
+ * The dictation cleanup pass rewrites what the user actually said, so a
3
+ * rewrite the provider cut off at the token cap must never become the
4
+ * payload: the raw transcript is sent instead.
5
+ */
6
+
7
+ import { describe, expect, test } from "bun:test";
8
+
9
+ import {
10
+ computeMaxTokens,
11
+ resolveCleanedDictation,
12
+ } from "../diagnostics-routes.js";
13
+
14
+ const SPOKEN =
15
+ "Hello Quill can you generate a list of 20 open HR coordinator or HR " +
16
+ "related roles that are remote and pay about 50 to 60 K per year";
17
+
18
+ describe("resolveCleanedDictation", () => {
19
+ test("accepts an ordinary cleanup", () => {
20
+ const cleaned =
21
+ "Hello Quill, can you generate a list of 20 open HR coordinator or HR " +
22
+ "related roles that are remote and pay about 50 to 60K per year?";
23
+ expect(resolveCleanedDictation(SPOKEN, cleaned, "end_turn")).toEqual({
24
+ text: cleaned,
25
+ rejected: null,
26
+ });
27
+ });
28
+
29
+ test("trims surrounding whitespace off an accepted cleanup", () => {
30
+ const { text } = resolveCleanedDictation(
31
+ "so um I think we should ship the thing on Tuesday you know",
32
+ " I think we should ship the thing on Tuesday. ",
33
+ "end_turn",
34
+ );
35
+ expect(text).toBe("I think we should ship the thing on Tuesday.");
36
+ });
37
+
38
+ test("rejects a rewrite cut off by max_tokens and keeps the raw words", () => {
39
+ expect(
40
+ resolveCleanedDictation(
41
+ SPOKEN,
42
+ "Hello Quill, can you create a list",
43
+ "max_tokens",
44
+ ),
45
+ ).toEqual({ text: SPOKEN, rejected: "truncated" });
46
+ });
47
+
48
+ test("rejects a max_tokens rewrite even when it kept most of the words", () => {
49
+ const nearlyComplete = SPOKEN.slice(0, SPOKEN.length - 4);
50
+ const { rejected } = resolveCleanedDictation(
51
+ SPOKEN,
52
+ nearlyComplete,
53
+ "max_tokens",
54
+ );
55
+ expect(rejected).toBe("truncated");
56
+ });
57
+
58
+ test("rejects the token-cap stop under every provider's name for it", () => {
59
+ for (const stopReason of ["length", "max_output_tokens", "MAX_TOKENS "]) {
60
+ expect(
61
+ resolveCleanedDictation(SPOKEN, "Hello Quill, can you", stopReason)
62
+ .rejected,
63
+ ).toBe("truncated");
64
+ }
65
+ });
66
+
67
+ test("a missing stop reason is not treated as a truncation", () => {
68
+ const cleaned = "Hello Quill, can you generate a list?";
69
+ expect(resolveCleanedDictation(SPOKEN, cleaned, undefined)).toEqual({
70
+ text: cleaned,
71
+ rejected: null,
72
+ });
73
+ });
74
+
75
+ test("a much shorter rewrite is the model's call, not a rejection", () => {
76
+ // The prompt asks for fillers and vague phrasing to go, so a concise
77
+ // rewrite of a rambling utterance is a correct cleanup.
78
+ const spoken =
79
+ "um you know I just kind of wanted to say like thank you so much you know";
80
+ expect(
81
+ resolveCleanedDictation(spoken, "Thank you so much.", "end_turn"),
82
+ ).toEqual({ text: "Thank you so much.", rejected: null });
83
+ });
84
+
85
+ test("an empty rewrite falls back to raw without flagging a rejection", () => {
86
+ // The model returned nothing usable; there is no rewrite to distrust.
87
+ expect(resolveCleanedDictation(SPOKEN, " ", "end_turn")).toEqual({
88
+ text: SPOKEN,
89
+ rejected: null,
90
+ });
91
+ });
92
+ });
93
+
94
+ describe("computeMaxTokens", () => {
95
+ test("budgets room for the transcript, reasoning, and JSON scaffolding", () => {
96
+ // The tool call carries the whole transcript back in `text`, so the
97
+ // budget has to clear the input's own token count with room to spare.
98
+ const estimatedInputTokens = Math.ceil(SPOKEN.length / 3);
99
+ expect(computeMaxTokens(SPOKEN.length)).toBeGreaterThan(
100
+ estimatedInputTokens * 2,
101
+ );
102
+ });
103
+
104
+ test("holds a floor for very short transcripts", () => {
105
+ expect(computeMaxTokens(5)).toBe(512);
106
+ });
107
+ });
@@ -22,6 +22,7 @@ import {
22
22
  getConfiguredProvider,
23
23
  userMessage,
24
24
  } from "../../providers/provider-send-message.js";
25
+ import { isMaxTokensStopReason } from "../../providers/stop-reasons.js";
25
26
  import { getLogger } from "../../util/logger.js";
26
27
  import { ACTOR_PRINCIPALS } from "../auth/route-policy.js";
27
28
  import { BadRequestError } from "./errors.js";
@@ -176,9 +177,44 @@ function buildCommandPrompt(body: DictationBody, stylePrompt?: string): string {
176
177
  return sections.join("\n");
177
178
  }
178
179
 
179
- function computeMaxTokens(inputLength: number): number {
180
+ export function computeMaxTokens(inputLength: number): number {
180
181
  const estimatedInputTokens = Math.ceil(inputLength / 3);
181
- return Math.max(256, estimatedInputTokens + 128);
182
+ // The cleanup tool call carries the whole transcript back in its `text`
183
+ // argument, plus a `reasoning` string and the JSON scaffolding around both,
184
+ // so the budget has to cover well more than the input alone. `max_tokens` is
185
+ // a ceiling rather than a target: a call that stops short of it costs no
186
+ // extra latency.
187
+ return Math.max(512, estimatedInputTokens * 2 + 256);
188
+ }
189
+
190
+ export type CleanupRejection = "truncated";
191
+
192
+ /**
193
+ * Decide whether the cleanup model's rewrite is safe to use as the payload.
194
+ *
195
+ * The rewrite replaces what the user actually said. A token-cap stop means the
196
+ * tool JSON was cut mid-argument, so however complete the `text` argument
197
+ * happens to look, it is a fragment; the raw transcript is the safer payload
198
+ * then. Unpolished beats wrong.
199
+ *
200
+ * Whether a shorter rewrite still preserved the meaning is the model's call
201
+ * (the prompt asks it to drop fillers and tighten phrasing), so there is no
202
+ * length check here: a deterministic ratio cannot tell a concise cleanup from
203
+ * a summary.
204
+ */
205
+ export function resolveCleanedDictation(
206
+ raw: string,
207
+ cleaned: string,
208
+ stopReason: string | null | undefined,
209
+ ): { text: string; rejected: CleanupRejection | null } {
210
+ const trimmed = cleaned.trim();
211
+ if (!trimmed) {
212
+ return { text: raw, rejected: null };
213
+ }
214
+ if (isMaxTokensStopReason(stopReason)) {
215
+ return { text: raw, rejected: "truncated" };
216
+ }
217
+ return { text: trimmed, rejected: null };
182
218
  }
183
219
 
184
220
  interface DictationResult {
@@ -329,7 +365,23 @@ async function handleDictation(body: DictationBody): Promise<DictationResult> {
329
365
  ...profileMeta,
330
366
  };
331
367
  }
332
- const cleanedText = input.text?.trim() || transcription;
368
+ const { text: cleanedText, rejected } = resolveCleanedDictation(
369
+ transcription,
370
+ input.text ?? "",
371
+ response.stopReason,
372
+ );
373
+ if (rejected) {
374
+ // Lengths only -- transcript content must never be logged.
375
+ log.warn(
376
+ {
377
+ rejected,
378
+ stopReason: response.stopReason,
379
+ rawChars: transcription.length,
380
+ cleanedChars: input.text?.trim().length ?? 0,
381
+ },
382
+ "Dictation cleanup rejected, using raw transcription",
383
+ );
384
+ }
333
385
  const normalizedText = applyDictionary(cleanedText, profile.dictionary);
334
386
  return {
335
387
  text: normalizedText,