@vellumai/assistant 0.10.6-dev.202607072040.fb971ce → 0.10.6-dev.202607072134.71ed9c4

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.10.6-dev.202607072040.fb971ce",
3
+ "version": "0.10.6-dev.202607072134.71ed9c4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -45,6 +45,6 @@ describe("isDeniedNumber", () => {
45
45
 
46
46
  describe("getEndCallListenWindowMs", () => {
47
47
  test("leaves a brief response window before task-complete hangup", () => {
48
- expect(getEndCallListenWindowMs()).toBe(15_000);
48
+ expect(getEndCallListenWindowMs()).toBe(2_000);
49
49
  });
50
50
  });
@@ -915,6 +915,37 @@ describe("AssistantConfigSchema", () => {
915
915
  expect(result.calls.safety.denyCategories).toEqual(["spam"]);
916
916
  });
917
917
 
918
+ // ── Live voice config ───────────────────────────────────────────────
919
+
920
+ test("applies liveVoice defaults", () => {
921
+ const result = AssistantConfigSchema.parse({});
922
+ expect(result.liveVoice).toEqual({
923
+ mode: "open-mic",
924
+ vad: {
925
+ speechEnergyThreshold: 800,
926
+ silenceThresholdMs: 800,
927
+ maxTurnDurationMs: 30000,
928
+ },
929
+ maxSessionDurationSeconds: 1800,
930
+ });
931
+ });
932
+
933
+ test("accepts valid liveVoice config overrides", () => {
934
+ const result = AssistantConfigSchema.parse({
935
+ liveVoice: {
936
+ mode: "ptt",
937
+ vad: { speechEnergyThreshold: 1500, silenceThresholdMs: 1000 },
938
+ maxSessionDurationSeconds: 900,
939
+ },
940
+ });
941
+ expect(result.liveVoice.mode).toBe("ptt");
942
+ expect(result.liveVoice.vad.speechEnergyThreshold).toBe(1500);
943
+ expect(result.liveVoice.vad.silenceThresholdMs).toBe(1000);
944
+ // Unspecified vad fields still get defaults
945
+ expect(result.liveVoice.vad.maxTurnDurationMs).toBe(30000);
946
+ expect(result.liveVoice.maxSessionDurationSeconds).toBe(900);
947
+ });
948
+
918
949
  test("accepts partial calls config with defaults for missing fields", () => {
919
950
  const result = AssistantConfigSchema.parse({
920
951
  calls: { maxDurationSeconds: 600 },
@@ -70,5 +70,5 @@ export function getSilenceTimeoutMs(): number {
70
70
  }
71
71
 
72
72
  export function getEndCallListenWindowMs(): number {
73
- return 15 * 1000;
73
+ return 2 * 1000;
74
74
  }
@@ -0,0 +1,231 @@
1
+ import {
2
+ existsSync,
3
+ mkdirSync,
4
+ readFileSync,
5
+ rmSync,
6
+ writeFileSync,
7
+ } from "node:fs";
8
+ import { join } from "node:path";
9
+ import {
10
+ afterAll,
11
+ afterEach,
12
+ beforeEach,
13
+ describe,
14
+ expect,
15
+ mock,
16
+ test,
17
+ } from "bun:test";
18
+
19
+ const WORKSPACE_DIR = process.env.VELLUM_WORKSPACE_DIR!;
20
+ const CONFIG_PATH = join(WORKSPACE_DIR, "config.json");
21
+
22
+ function ensureTestDir(): void {
23
+ const dirs = [
24
+ WORKSPACE_DIR,
25
+ join(WORKSPACE_DIR, "data"),
26
+ join(WORKSPACE_DIR, "data", "memory"),
27
+ join(WORKSPACE_DIR, "data", "logs"),
28
+ ];
29
+ for (const dir of dirs) {
30
+ if (!existsSync(dir)) {
31
+ mkdirSync(dir, { recursive: true });
32
+ }
33
+ }
34
+ }
35
+
36
+ function makeLoggerStub(): Record<string, unknown> {
37
+ const stub: Record<string, unknown> = {};
38
+ for (const m of [
39
+ "info",
40
+ "warn",
41
+ "error",
42
+ "debug",
43
+ "trace",
44
+ "fatal",
45
+ "silent",
46
+ "child",
47
+ ]) {
48
+ stub[m] = m === "child" ? () => makeLoggerStub() : () => {};
49
+ }
50
+ return stub;
51
+ }
52
+
53
+ mock.module("../../util/logger.js", () => ({
54
+ getLogger: () => makeLoggerStub(),
55
+ }));
56
+
57
+ afterAll(() => {
58
+ mock.restore();
59
+ });
60
+
61
+ import { invalidateConfigCache } from "../loader.js";
62
+ import { LLMSchema } from "../schemas/llm.js";
63
+ import {
64
+ seedInferenceProfiles,
65
+ type SeedInferenceProfilesOptions,
66
+ } from "../seed-inference-profiles.js";
67
+
68
+ type RawLLM = Record<string, unknown> & {
69
+ defaultProvider?: { provider: string; connectionName?: string };
70
+ };
71
+
72
+ function writeConfig(obj: unknown): void {
73
+ writeFileSync(CONFIG_PATH, JSON.stringify(obj, null, 2) + "\n");
74
+ }
75
+
76
+ function readLLM(): RawLLM {
77
+ return (JSON.parse(readFileSync(CONFIG_PATH, "utf-8")) as { llm: RawLLM })
78
+ .llm;
79
+ }
80
+
81
+ function seed(
82
+ config: Record<string, unknown>,
83
+ options: SeedInferenceProfilesOptions,
84
+ ): RawLLM {
85
+ writeConfig(config);
86
+ invalidateConfigCache();
87
+ seedInferenceProfiles(options);
88
+ invalidateConfigCache();
89
+ return readLLM();
90
+ }
91
+
92
+ describe("seedInferenceProfiles / llm.defaultProvider", () => {
93
+ beforeEach(() => {
94
+ ensureTestDir();
95
+ if (existsSync(CONFIG_PATH)) {
96
+ rmSync(CONFIG_PATH, { force: true });
97
+ }
98
+ delete process.env.IS_PLATFORM;
99
+ invalidateConfigCache();
100
+ });
101
+
102
+ afterEach(() => {
103
+ delete process.env.IS_PLATFORM;
104
+ invalidateConfigCache();
105
+ });
106
+
107
+ test("platform hatch writes vellum", () => {
108
+ process.env.IS_PLATFORM = "true";
109
+ const llm = seed(
110
+ { llm: { default: { provider: "anthropic" } } },
111
+ { isHatch: true },
112
+ );
113
+ expect(llm.defaultProvider).toEqual({ provider: "vellum" });
114
+ });
115
+
116
+ test("BYOK hatch with an anthropic key writes anthropic", () => {
117
+ const llm = seed(
118
+ { llm: { default: { provider: "anthropic" } } },
119
+ { isHatch: true },
120
+ );
121
+ expect(llm.defaultProvider).toEqual({ provider: "anthropic" });
122
+ });
123
+
124
+ test("BYOK hatch with an openai key writes openai", () => {
125
+ const llm = seed(
126
+ { llm: { default: { provider: "openai" } } },
127
+ { isHatch: true },
128
+ );
129
+ expect(llm.defaultProvider).toEqual({ provider: "openai" });
130
+ });
131
+
132
+ test("BYOK hatch with provider ollama falls back to anthropic", () => {
133
+ const llm = seed(
134
+ { llm: { default: { provider: "ollama" } } },
135
+ { isHatch: true },
136
+ );
137
+ expect(llm.defaultProvider).toEqual({ provider: "anthropic" });
138
+ });
139
+
140
+ test("BYOK hatch with no provider entered falls back to anthropic", () => {
141
+ const llm = seed({ llm: {} }, { isHatch: true });
142
+ expect(llm.defaultProvider).toEqual({ provider: "anthropic" });
143
+ });
144
+
145
+ test("BYOK hatch that selected a managed connection writes vellum", () => {
146
+ const llm = seed(
147
+ {
148
+ llm: {
149
+ default: { provider: "anthropic" },
150
+ activeProfile: "balanced",
151
+ },
152
+ },
153
+ { isHatch: true, preserveActiveProfile: true },
154
+ );
155
+ expect(llm.defaultProvider).toEqual({ provider: "vellum" });
156
+ });
157
+
158
+ test("a pre-existing defaultProvider survives a platform hatch untouched", () => {
159
+ process.env.IS_PLATFORM = "true";
160
+ const llm = seed(
161
+ {
162
+ llm: {
163
+ default: { provider: "anthropic" },
164
+ defaultProvider: { provider: "openai" },
165
+ },
166
+ },
167
+ { isHatch: true },
168
+ );
169
+ expect(llm.defaultProvider).toEqual({ provider: "openai" });
170
+ });
171
+
172
+ test("a pre-existing defaultProvider survives a BYOK hatch untouched", () => {
173
+ const llm = seed(
174
+ {
175
+ llm: {
176
+ default: { provider: "anthropic" },
177
+ defaultProvider: { provider: "openai" },
178
+ },
179
+ },
180
+ { isHatch: true },
181
+ );
182
+ expect(llm.defaultProvider).toEqual({ provider: "openai" });
183
+ });
184
+
185
+ test("a pre-existing defaultProvider survives a managed-connection hatch untouched", () => {
186
+ const llm = seed(
187
+ {
188
+ llm: {
189
+ default: { provider: "anthropic" },
190
+ activeProfile: "balanced",
191
+ defaultProvider: { provider: "openai" },
192
+ },
193
+ },
194
+ { isHatch: true, preserveActiveProfile: true },
195
+ );
196
+ expect(llm.defaultProvider).toEqual({ provider: "openai" });
197
+ });
198
+
199
+ test("non-hatch boot writes nothing", () => {
200
+ const llm = seed({ llm: { default: { provider: "anthropic" } } }, {});
201
+ expect(llm.defaultProvider).toBeUndefined();
202
+ });
203
+
204
+ test("seeded config round-trips through LLMSchema.parse with the field intact", () => {
205
+ const llm = seed(
206
+ { llm: { default: { provider: "anthropic" } } },
207
+ { isHatch: true },
208
+ );
209
+ const parsed = LLMSchema.parse(llm);
210
+ expect(parsed.defaultProvider).toEqual({ provider: "anthropic" });
211
+ });
212
+
213
+ test("no connectionName is ever written", () => {
214
+ process.env.IS_PLATFORM = "true";
215
+ const platformLLM = seed(
216
+ { llm: { default: { provider: "anthropic" } } },
217
+ { isHatch: true },
218
+ );
219
+ expect(platformLLM.defaultProvider?.connectionName).toBeUndefined();
220
+
221
+ delete process.env.IS_PLATFORM;
222
+ const byokLLM = seed(
223
+ { llm: { default: { provider: "openai" } } },
224
+ { isHatch: true },
225
+ );
226
+ expect(byokLLM.defaultProvider?.connectionName).toBeUndefined();
227
+
228
+ const fallbackLLM = seed({ llm: {} }, { isHatch: true });
229
+ expect(fallbackLLM.defaultProvider?.connectionName).toBeUndefined();
230
+ });
231
+ });
@@ -34,6 +34,7 @@ import { HeartbeatConfigSchema } from "./schemas/heartbeat.js";
34
34
  import { HostBrowserConfigSchema } from "./schemas/host-browser.js";
35
35
  import { IngressConfigSchema } from "./schemas/ingress.js";
36
36
  import { JournalConfigSchema } from "./schemas/journal.js";
37
+ import { LiveVoiceConfigSchema } from "./schemas/live-voice.js";
37
38
  import { LLMSchema } from "./schemas/llm.js";
38
39
  import { LlmRequestLogsConfigSchema } from "./schemas/llm-request-logs.js";
39
40
  import {
@@ -120,6 +121,7 @@ export const AssistantConfigSchema = z
120
121
  compactionLogs: CompactionLogsConfigSchema,
121
122
  twilio: TwilioConfigSchema.default(TwilioConfigSchema.parse({})),
122
123
  calls: CallsConfigSchema.default(CallsConfigSchema.parse({})),
124
+ liveVoice: LiveVoiceConfigSchema.default(LiveVoiceConfigSchema.parse({})),
123
125
  whatsapp: WhatsAppConfigSchema.default(WhatsAppConfigSchema.parse({})),
124
126
  telegram: TelegramConfigSchema.default(TelegramConfigSchema.parse({})),
125
127
  slack: SlackConfigSchema.default(SlackConfigSchema.parse({})),
@@ -0,0 +1,92 @@
1
+ import { describe, expect, test } from "bun:test";
2
+
3
+ import {
4
+ LiveVoiceConfigSchema,
5
+ LiveVoiceVadConfigSchema,
6
+ VALID_LIVE_VOICE_MODES,
7
+ } from "../live-voice.js";
8
+
9
+ describe("LiveVoiceVadConfigSchema", () => {
10
+ test("empty object parses to defaults", () => {
11
+ const parsed = LiveVoiceVadConfigSchema.parse({});
12
+ expect(parsed).toEqual({
13
+ speechEnergyThreshold: 800,
14
+ silenceThresholdMs: 800,
15
+ maxTurnDurationMs: 30_000,
16
+ });
17
+ });
18
+
19
+ test("accepts overrides", () => {
20
+ const parsed = LiveVoiceVadConfigSchema.parse({
21
+ speechEnergyThreshold: 1200,
22
+ silenceThresholdMs: 500,
23
+ maxTurnDurationMs: 60_000,
24
+ });
25
+ expect(parsed.speechEnergyThreshold).toBe(1200);
26
+ expect(parsed.silenceThresholdMs).toBe(500);
27
+ expect(parsed.maxTurnDurationMs).toBe(60_000);
28
+ });
29
+
30
+ test("rejects non-positive speechEnergyThreshold", () => {
31
+ const result = LiveVoiceVadConfigSchema.safeParse({
32
+ speechEnergyThreshold: 0,
33
+ });
34
+ expect(result.success).toBe(false);
35
+ });
36
+
37
+ test("rejects non-integer silenceThresholdMs", () => {
38
+ const result = LiveVoiceVadConfigSchema.safeParse({
39
+ silenceThresholdMs: 800.5,
40
+ });
41
+ expect(result.success).toBe(false);
42
+ });
43
+ });
44
+
45
+ describe("LiveVoiceConfigSchema", () => {
46
+ test("empty object parses to defaults", () => {
47
+ const parsed = LiveVoiceConfigSchema.parse({});
48
+ expect(parsed).toEqual({
49
+ mode: "open-mic",
50
+ vad: {
51
+ speechEnergyThreshold: 800,
52
+ silenceThresholdMs: 800,
53
+ maxTurnDurationMs: 30_000,
54
+ },
55
+ maxSessionDurationSeconds: 1800,
56
+ });
57
+ });
58
+
59
+ test("accepts overrides", () => {
60
+ const parsed = LiveVoiceConfigSchema.parse({
61
+ mode: "ptt",
62
+ vad: { silenceThresholdMs: 1200 },
63
+ maxSessionDurationSeconds: 600,
64
+ });
65
+ expect(parsed.mode).toBe("ptt");
66
+ expect(parsed.vad.silenceThresholdMs).toBe(1200);
67
+ // Unspecified vad fields still get defaults
68
+ expect(parsed.vad.speechEnergyThreshold).toBe(800);
69
+ expect(parsed.vad.maxTurnDurationMs).toBe(30_000);
70
+ expect(parsed.maxSessionDurationSeconds).toBe(600);
71
+ });
72
+
73
+ test("rejects invalid mode", () => {
74
+ const result = LiveVoiceConfigSchema.safeParse({ mode: "always-on" });
75
+ expect(result.success).toBe(false);
76
+ if (!result.success) {
77
+ const msgs = result.error.issues.map((i) => i.message);
78
+ expect(msgs.some((m) => m.includes("liveVoice.mode"))).toBe(true);
79
+ }
80
+ });
81
+
82
+ test("rejects non-positive maxSessionDurationSeconds", () => {
83
+ const result = LiveVoiceConfigSchema.safeParse({
84
+ maxSessionDurationSeconds: -1,
85
+ });
86
+ expect(result.success).toBe(false);
87
+ });
88
+
89
+ test("VALID_LIVE_VOICE_MODES lists ptt and open-mic", () => {
90
+ expect(VALID_LIVE_VOICE_MODES).toEqual(["ptt", "open-mic"]);
91
+ });
92
+ });
@@ -0,0 +1,67 @@
1
+ import { z } from "zod";
2
+
3
+ export const VALID_LIVE_VOICE_MODES = ["ptt", "open-mic"] as const;
4
+
5
+ export const LiveVoiceVadConfigSchema = z
6
+ .object({
7
+ speechEnergyThreshold: z
8
+ .number({
9
+ error: "liveVoice.vad.speechEnergyThreshold must be a number",
10
+ })
11
+ .int("liveVoice.vad.speechEnergyThreshold must be an integer")
12
+ .positive(
13
+ "liveVoice.vad.speechEnergyThreshold must be a positive integer",
14
+ )
15
+ .default(800)
16
+ .describe(
17
+ "Mean absolute amplitude (16-bit linear scale) above which a frame counts as speech — mirrors DEFAULT_SPEECH_ENERGY_THRESHOLD in stt/speech-energy.ts",
18
+ ),
19
+ silenceThresholdMs: z
20
+ .number({ error: "liveVoice.vad.silenceThresholdMs must be a number" })
21
+ .int("liveVoice.vad.silenceThresholdMs must be an integer")
22
+ .positive("liveVoice.vad.silenceThresholdMs must be a positive integer")
23
+ .default(800)
24
+ .describe(
25
+ "Trailing silence duration (ms) after speech that ends the user's turn",
26
+ ),
27
+ maxTurnDurationMs: z
28
+ .number({ error: "liveVoice.vad.maxTurnDurationMs must be a number" })
29
+ .int("liveVoice.vad.maxTurnDurationMs must be an integer")
30
+ .positive("liveVoice.vad.maxTurnDurationMs must be a positive integer")
31
+ .default(30_000)
32
+ .describe(
33
+ "Maximum duration (ms) of a single user turn before it is force-ended",
34
+ ),
35
+ })
36
+ .describe(
37
+ "Voice-activity-detection tuning for live voice sessions (open-mic turn segmentation)",
38
+ );
39
+
40
+ export const LiveVoiceConfigSchema = z
41
+ .object({
42
+ mode: z
43
+ .enum(VALID_LIVE_VOICE_MODES, {
44
+ error: `liveVoice.mode must be one of: ${VALID_LIVE_VOICE_MODES.join(", ")}`,
45
+ })
46
+ .default("open-mic")
47
+ .describe(
48
+ "Default microphone mode for live voice sessions — hands-free (open-mic) or push-to-talk (ptt)",
49
+ ),
50
+ vad: LiveVoiceVadConfigSchema.default(LiveVoiceVadConfigSchema.parse({})),
51
+ maxSessionDurationSeconds: z
52
+ .number({
53
+ error: "liveVoice.maxSessionDurationSeconds must be a number",
54
+ })
55
+ .int("liveVoice.maxSessionDurationSeconds must be an integer")
56
+ .positive(
57
+ "liveVoice.maxSessionDurationSeconds must be a positive integer",
58
+ )
59
+ .default(1800)
60
+ .describe("Maximum duration of a single live voice session in seconds"),
61
+ })
62
+ .describe(
63
+ "Live voice (in-app duplex audio) configuration — mic mode, VAD tuning, and session limits",
64
+ );
65
+
66
+ export type LiveVoiceConfig = z.infer<typeof LiveVoiceConfigSchema>;
67
+ export type LiveVoiceVadConfig = z.infer<typeof LiveVoiceVadConfigSchema>;
@@ -15,7 +15,10 @@ import {
15
15
  materializeProfile,
16
16
  USER_PROFILE_TEMPLATES,
17
17
  } from "./default-profile-catalog.js";
18
- import { DEFAULT_PROFILE_KEYS } from "./default-profile-names.js";
18
+ import {
19
+ DEFAULT_PROFILE_KEYS,
20
+ DEFAULT_PROFILE_PROVIDERS,
21
+ } from "./default-profile-names.js";
19
22
  import { loadRawConfig, saveRawConfig } from "./loader.js";
20
23
  import { isDispatchableProfile } from "./profile-dispatchability.js";
21
24
  import type { ProfileEntry } from "./schemas/llm.js";
@@ -45,7 +48,7 @@ export type SeedInferenceProfilesOptions = {
45
48
  * Runs on every daemon startup. Default profile CONTENT is code-owned
46
49
  * (`default-profile-catalog.ts`) and resolves through the effective view
47
50
  * whether or not `llm.profiles` carries an entry, so nothing here writes
48
- * default bodies. Two responsibilities remain:
51
+ * default bodies. Three responsibilities remain:
49
52
  *
50
53
  * 1. **BYOK hatch stubs**: a fresh off-platform install cannot use the
51
54
  * platform-auth vellum route, so the default profiles get a thin
@@ -59,6 +62,9 @@ export type SeedInferenceProfilesOptions = {
59
62
  * off-platform installations. Each points at a personal provider
60
63
  * connection backed by the user's API key in CES. Subsequent boots
61
64
  * leave these untouched — the user owns them.
65
+ *
66
+ * 3. **`llm.defaultProvider`**: written once at hatch time, mirroring the
67
+ * platform/managed/BYOK decisions above, and never overwritten afterward.
62
68
  */
63
69
  export function seedInferenceProfiles(
64
70
  options: SeedInferenceProfilesOptions = {},
@@ -119,6 +125,7 @@ export function seedInferenceProfiles(
119
125
 
120
126
  // 2. User profiles — only at hatch time for off-platform installations.
121
127
  let userConnectionName: string | undefined;
128
+ let usableHatchProvider: string | undefined;
122
129
  if (options.isHatch && !isPlatform) {
123
130
  const hatchProvider = readString(readObject(llm.default)?.provider);
124
131
  if (
@@ -126,6 +133,7 @@ export function seedInferenceProfiles(
126
133
  hatchProvider !== "ollama" &&
127
134
  !PROVIDERS_REQUIRING_BASE_URL_AND_MODELS.has(hatchProvider)
128
135
  ) {
136
+ usableHatchProvider = hatchProvider;
129
137
  userConnectionName = `${hatchProvider}-personal`;
130
138
 
131
139
  if (options.db) {
@@ -158,6 +166,19 @@ export function seedInferenceProfiles(
158
166
  }
159
167
  }
160
168
 
169
+ // 3. Default provider — hatch only, never overwritten once set. Always
170
+ // populated — even dangling, so later resolution can prompt the user
171
+ // for a key explainably rather than hitting an unset branch.
172
+ if (options.isHatch && readObject(llm.defaultProvider) === null) {
173
+ llm.defaultProvider = {
174
+ provider: resolveHatchDefaultProvider(
175
+ isPlatform,
176
+ hatchSelectedManagedConnection !== undefined,
177
+ usableHatchProvider,
178
+ ),
179
+ };
180
+ }
181
+
161
182
  pruneNonDispatchableProfiles(llm, profiles);
162
183
 
163
184
  // Profile lookups below go through the effective view: a default profile
@@ -257,6 +278,25 @@ export function readObject(value: unknown): Record<string, unknown> | null {
257
278
  : null;
258
279
  }
259
280
 
281
+ function resolveHatchDefaultProvider(
282
+ isPlatform: boolean,
283
+ selectedManagedConnection: boolean,
284
+ hatchProvider: string | undefined,
285
+ ): string {
286
+ // Platform mode and an explicit managed-connection selection both route
287
+ // through vellum.
288
+ if (isPlatform || selectedManagedConnection) {
289
+ return "vellum";
290
+ }
291
+ if (
292
+ hatchProvider !== undefined &&
293
+ (DEFAULT_PROFILE_PROVIDERS as readonly string[]).includes(hatchProvider)
294
+ ) {
295
+ return hatchProvider;
296
+ }
297
+ return "anthropic";
298
+ }
299
+
260
300
  function pruneNonDispatchableProfiles(
261
301
  llm: Record<string, unknown>,
262
302
  profiles: Record<string, Record<string, unknown>>,