@voicethere/agent 0.11.0 → 0.12.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.
Files changed (94) hide show
  1. package/dist/build-bundle.d.ts.map +1 -1
  2. package/dist/build-bundle.js +1 -0
  3. package/dist/build-bundle.js.map +1 -1
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/llm/agent/config.d.ts +376 -0
  9. package/dist/llm/agent/config.d.ts.map +1 -0
  10. package/dist/llm/agent/config.js +679 -0
  11. package/dist/llm/agent/config.js.map +1 -0
  12. package/dist/llm/agent/create-llm-agent.d.ts +22 -0
  13. package/dist/llm/agent/create-llm-agent.d.ts.map +1 -0
  14. package/dist/llm/agent/create-llm-agent.js +720 -0
  15. package/dist/llm/agent/create-llm-agent.js.map +1 -0
  16. package/dist/llm/agent/define-tool.d.ts +8 -0
  17. package/dist/llm/agent/define-tool.d.ts.map +1 -0
  18. package/dist/llm/agent/define-tool.js +9 -0
  19. package/dist/llm/agent/define-tool.js.map +1 -0
  20. package/dist/llm/agent/history.d.ts +35 -0
  21. package/dist/llm/agent/history.d.ts.map +1 -0
  22. package/dist/llm/agent/history.js +79 -0
  23. package/dist/llm/agent/history.js.map +1 -0
  24. package/dist/llm/agent/hooks.d.ts +50 -0
  25. package/dist/llm/agent/hooks.d.ts.map +1 -0
  26. package/dist/llm/agent/hooks.js +2 -0
  27. package/dist/llm/agent/hooks.js.map +1 -0
  28. package/dist/llm/agent/sentence-splitter.d.ts +10 -0
  29. package/dist/llm/agent/sentence-splitter.d.ts.map +1 -0
  30. package/dist/llm/agent/sentence-splitter.js +92 -0
  31. package/dist/llm/agent/sentence-splitter.js.map +1 -0
  32. package/dist/llm/anthropic-provider.d.ts +7 -0
  33. package/dist/llm/anthropic-provider.d.ts.map +1 -0
  34. package/dist/llm/anthropic-provider.js +115 -0
  35. package/dist/llm/anthropic-provider.js.map +1 -0
  36. package/dist/llm/bounded-provider.d.ts +12 -0
  37. package/dist/llm/bounded-provider.d.ts.map +1 -0
  38. package/dist/llm/bounded-provider.js +132 -0
  39. package/dist/llm/bounded-provider.js.map +1 -0
  40. package/dist/llm/catalog.d.ts +9 -0
  41. package/dist/llm/catalog.d.ts.map +1 -0
  42. package/dist/llm/catalog.js +35 -0
  43. package/dist/llm/catalog.js.map +1 -0
  44. package/dist/llm/gemini-provider.d.ts +7 -0
  45. package/dist/llm/gemini-provider.d.ts.map +1 -0
  46. package/dist/llm/gemini-provider.js +120 -0
  47. package/dist/llm/gemini-provider.js.map +1 -0
  48. package/dist/llm/index.d.ts +18 -0
  49. package/dist/llm/index.d.ts.map +1 -0
  50. package/dist/llm/index.js +11 -0
  51. package/dist/llm/index.js.map +1 -0
  52. package/dist/llm/mcp/index.d.ts +5 -0
  53. package/dist/llm/mcp/index.d.ts.map +1 -0
  54. package/dist/llm/mcp/index.js +3 -0
  55. package/dist/llm/mcp/index.js.map +1 -0
  56. package/dist/llm/mcp/mcp-tool-source.d.ts +65 -0
  57. package/dist/llm/mcp/mcp-tool-source.d.ts.map +1 -0
  58. package/dist/llm/mcp/mcp-tool-source.js +328 -0
  59. package/dist/llm/mcp/mcp-tool-source.js.map +1 -0
  60. package/dist/llm/mcp/tool-registry.d.ts +44 -0
  61. package/dist/llm/mcp/tool-registry.d.ts.map +1 -0
  62. package/dist/llm/mcp/tool-registry.js +147 -0
  63. package/dist/llm/mcp/tool-registry.js.map +1 -0
  64. package/dist/llm/openai-provider.d.ts +8 -0
  65. package/dist/llm/openai-provider.d.ts.map +1 -0
  66. package/dist/llm/openai-provider.js +146 -0
  67. package/dist/llm/openai-provider.js.map +1 -0
  68. package/dist/llm/providers.d.ts +10 -0
  69. package/dist/llm/providers.d.ts.map +1 -0
  70. package/dist/llm/providers.js +32 -0
  71. package/dist/llm/providers.js.map +1 -0
  72. package/dist/llm/types.d.ts +70 -0
  73. package/dist/llm/types.d.ts.map +1 -0
  74. package/dist/llm/types.js +11 -0
  75. package/dist/llm/types.js.map +1 -0
  76. package/dist/runtime.d.ts +9 -0
  77. package/dist/runtime.d.ts.map +1 -1
  78. package/dist/runtime.js +24 -0
  79. package/dist/runtime.js.map +1 -1
  80. package/dist/templates/llm-agent/agent.js +121379 -0
  81. package/dist/templates/registry.d.ts +1 -1
  82. package/dist/templates/registry.d.ts.map +1 -1
  83. package/dist/templates/registry.js +24 -0
  84. package/dist/templates/registry.js.map +1 -1
  85. package/eject/llm/loop.ts +913 -0
  86. package/package.json +48 -4
  87. package/schema/voicethere.llm.schema.json +325 -0
  88. package/templates/llm-agent/README.md +24 -0
  89. package/templates/llm-agent/agent.ts +8 -0
  90. package/templates/llm-agent/hooks.ts +21 -0
  91. package/templates/llm-agent/md.d.ts +4 -0
  92. package/templates/llm-agent/prompt.md +11 -0
  93. package/templates/llm-agent/tools.ts +51 -0
  94. package/templates/llm-agent/voicethere.llm.json +21 -0
@@ -0,0 +1,679 @@
1
+ export const LLM_AGENT_CONFIG_DEFAULTS = {
2
+ maxOutputTokens: 512,
3
+ greetingInterruptible: false,
4
+ bargeInMode: "project",
5
+ speechDuringNonInterruptible: "answer_after",
6
+ historyTurns: 20,
7
+ interruptionNote: true,
8
+ toolMaxRounds: 5,
9
+ toolTimeoutMs: 15_000,
10
+ toolMaxResultBytes: 16_384,
11
+ fillerAfterMs: 1_500,
12
+ fillerInterruptible: false,
13
+ servicePath: "/mcp",
14
+ interruptPolicy: "cancel",
15
+ serviceWaitMs: 20_000,
16
+ fallbackText: "Sorry, something went wrong. Please try again.",
17
+ speakChatReplies: true,
18
+ };
19
+ const PROVIDER_IDS = ["openai", "anthropic", "gemini", "openrouter"];
20
+ const ENV_NAME_RE = /^AGENT_[A-Z0-9_]{1,57}$/;
21
+ const ENV_NAME_MESSAGE = "must start with AGENT_ (only AGENT_* project secrets reach the agent)";
22
+ const SOURCE_NAME_RE = /^[a-z0-9-]{1,40}$/;
23
+ const MAX_SOURCES = 8;
24
+ function isRecord(v) {
25
+ return typeof v === "object" && v !== null && !Array.isArray(v);
26
+ }
27
+ function isPrivateIpv4(host) {
28
+ const m = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(host);
29
+ if (!m)
30
+ return false;
31
+ const [a, b] = [Number(m[1]), Number(m[2])];
32
+ return (a === 10 ||
33
+ a === 127 ||
34
+ (a === 172 && b >= 16 && b <= 31) ||
35
+ (a === 192 && b === 168) ||
36
+ (a === 169 && b === 254));
37
+ }
38
+ function isPrivateIpv6(host) {
39
+ const h = host.toLowerCase();
40
+ if (!h.includes(":"))
41
+ return false;
42
+ if (h === "::1" || h === "::")
43
+ return true;
44
+ const first = h.split(":")[0];
45
+ if (first && /^f[cd][0-9a-f]{2}$/.test(first))
46
+ return true;
47
+ // IPv4-mapped ::ffff:a.b.c.d, normalised by URL to ::ffff:hhhh:hhhh
48
+ const mapped = /^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/.exec(h);
49
+ if (mapped) {
50
+ const hi = parseInt(mapped[1], 16);
51
+ const lo = parseInt(mapped[2], 16);
52
+ return isPrivateIpv4(`${hi >> 8}.${hi & 255}.${lo >> 8}.${lo & 255}`);
53
+ }
54
+ return false;
55
+ }
56
+ /** Returns an error message when `host` is a local or private address literal. */
57
+ function privateHostReason(hostname) {
58
+ const host = hostname.startsWith("[") && hostname.endsWith("]")
59
+ ? hostname.slice(1, -1)
60
+ : hostname;
61
+ const lower = host.toLowerCase();
62
+ if (lower === "localhost" || lower.endsWith(".localhost")) {
63
+ return "host must not be localhost";
64
+ }
65
+ if (isPrivateIpv4(lower) || isPrivateIpv6(lower)) {
66
+ return "host must not be a private or loopback address";
67
+ }
68
+ return undefined;
69
+ }
70
+ class Checker {
71
+ errors = [];
72
+ err(path, message) {
73
+ this.errors.push({ path, message });
74
+ }
75
+ unknownKeys(obj, allowed, path) {
76
+ for (const key of Object.keys(obj)) {
77
+ if (!allowed.includes(key)) {
78
+ this.err(path ? `${path}.${key}` : key, "unknown field");
79
+ }
80
+ }
81
+ }
82
+ object(v, path) {
83
+ if (!isRecord(v)) {
84
+ this.err(path, "must be an object");
85
+ return undefined;
86
+ }
87
+ return v;
88
+ }
89
+ string(v, path, opts = {}) {
90
+ if (typeof v !== "string") {
91
+ this.err(path, "must be a string");
92
+ return undefined;
93
+ }
94
+ if (opts.min !== undefined && v.length < opts.min) {
95
+ this.err(path, `must be at least ${opts.min} characters`);
96
+ return undefined;
97
+ }
98
+ if (opts.max !== undefined && v.length > opts.max) {
99
+ this.err(path, `must be at most ${opts.max} characters`);
100
+ return undefined;
101
+ }
102
+ if (opts.re && !opts.re.test(v)) {
103
+ this.err(path, opts.reMessage ?? `must match ${opts.re.source}`);
104
+ return undefined;
105
+ }
106
+ return v;
107
+ }
108
+ number(v, path, min, max, integer) {
109
+ if (typeof v !== "number" || !Number.isFinite(v)) {
110
+ this.err(path, "must be a number");
111
+ return undefined;
112
+ }
113
+ if (integer && !Number.isInteger(v)) {
114
+ this.err(path, "must be an integer");
115
+ return undefined;
116
+ }
117
+ if (v < min || v > max) {
118
+ this.err(path, `must be between ${min} and ${max}`);
119
+ return undefined;
120
+ }
121
+ return v;
122
+ }
123
+ boolean(v, path) {
124
+ if (typeof v !== "boolean") {
125
+ this.err(path, "must be a boolean");
126
+ return undefined;
127
+ }
128
+ return v;
129
+ }
130
+ stringList(v, path) {
131
+ if (!Array.isArray(v)) {
132
+ this.err(path, "must be an array of strings");
133
+ return undefined;
134
+ }
135
+ const out = [];
136
+ v.forEach((item, i) => {
137
+ const s = this.string(item, `${path}[${i}]`, { min: 1, max: 128 });
138
+ if (s !== undefined)
139
+ out.push(s);
140
+ });
141
+ return out;
142
+ }
143
+ }
144
+ function checkAuth(c, v, path) {
145
+ const o = c.object(v, path);
146
+ if (!o)
147
+ return undefined;
148
+ const type = o.type;
149
+ if (type === "none") {
150
+ c.unknownKeys(o, ["type"], path);
151
+ return { type: "none" };
152
+ }
153
+ if (type === "bearer") {
154
+ c.unknownKeys(o, ["type", "secret"], path);
155
+ const secret = c.string(o.secret, `${path}.secret`, {
156
+ re: ENV_NAME_RE,
157
+ reMessage: ENV_NAME_MESSAGE,
158
+ });
159
+ return secret === undefined ? undefined : { type: "bearer", secret };
160
+ }
161
+ if (type === "headers") {
162
+ c.unknownKeys(o, ["type", "headers"], path);
163
+ const h = c.object(o.headers, `${path}.headers`);
164
+ if (!h)
165
+ return undefined;
166
+ const headers = {};
167
+ for (const [name, value] of Object.entries(h)) {
168
+ if (!/^[A-Za-z0-9-]{1,64}$/.test(name)) {
169
+ c.err(`${path}.headers.${name}`, "invalid header name");
170
+ continue;
171
+ }
172
+ const env = c.string(value, `${path}.headers.${name}`, {
173
+ re: ENV_NAME_RE,
174
+ reMessage: ENV_NAME_MESSAGE,
175
+ });
176
+ if (env !== undefined)
177
+ headers[name] = env;
178
+ }
179
+ return { type: "headers", headers };
180
+ }
181
+ c.err(`${path}.type`, 'must be one of "none", "bearer", "headers"');
182
+ return undefined;
183
+ }
184
+ function checkMcpUrl(c, v, path) {
185
+ const s = c.string(v, path, { min: 1, max: 2048 });
186
+ if (s === undefined)
187
+ return undefined;
188
+ let u;
189
+ try {
190
+ u = new URL(s);
191
+ }
192
+ catch {
193
+ c.err(path, "must be a valid URL");
194
+ return undefined;
195
+ }
196
+ if (u.protocol !== "https:") {
197
+ c.err(path, "must use https");
198
+ return undefined;
199
+ }
200
+ const reason = privateHostReason(u.hostname);
201
+ if (reason) {
202
+ c.err(path, reason);
203
+ return undefined;
204
+ }
205
+ return s;
206
+ }
207
+ function checkSources(c, v, path) {
208
+ if (!Array.isArray(v)) {
209
+ c.err(path, "must be an array");
210
+ return undefined;
211
+ }
212
+ if (v.length > MAX_SOURCES) {
213
+ c.err(path, `must have at most ${MAX_SOURCES} entries`);
214
+ }
215
+ const out = [];
216
+ const names = new Set();
217
+ let services = 0;
218
+ v.forEach((item, i) => {
219
+ const p = `${path}[${i}]`;
220
+ const o = c.object(item, p);
221
+ if (!o)
222
+ return;
223
+ if (o.kind === "service") {
224
+ c.unknownKeys(o, ["kind", "path", "allow", "deny"], p);
225
+ services += 1;
226
+ if (services > 1)
227
+ c.err(p, "at most one service source is allowed");
228
+ const src = { kind: "service" };
229
+ if (o.path !== undefined) {
230
+ const sp = c.string(o.path, `${p}.path`, { min: 1, max: 256 });
231
+ if (sp !== undefined) {
232
+ if (!sp.startsWith("/"))
233
+ c.err(`${p}.path`, 'must start with "/"');
234
+ else
235
+ src.path = sp;
236
+ }
237
+ }
238
+ if (o.allow !== undefined)
239
+ src.allow = c.stringList(o.allow, `${p}.allow`);
240
+ if (o.deny !== undefined)
241
+ src.deny = c.stringList(o.deny, `${p}.deny`);
242
+ out.push(src);
243
+ }
244
+ else if (o.kind === "mcp") {
245
+ c.unknownKeys(o, ["kind", "name", "url", "auth", "allow", "deny"], p);
246
+ const name = c.string(o.name, `${p}.name`, {
247
+ re: SOURCE_NAME_RE,
248
+ reMessage: "must match ^[a-z0-9-]{1,40}$",
249
+ });
250
+ if (name !== undefined) {
251
+ if (names.has(name))
252
+ c.err(`${p}.name`, "must be unique");
253
+ names.add(name);
254
+ }
255
+ const url = checkMcpUrl(c, o.url, `${p}.url`);
256
+ const src = {
257
+ kind: "mcp",
258
+ name: name ?? "",
259
+ url: url ?? "",
260
+ };
261
+ if (o.auth !== undefined) {
262
+ const auth = checkAuth(c, o.auth, `${p}.auth`);
263
+ if (auth)
264
+ src.auth = auth;
265
+ }
266
+ if (o.allow !== undefined)
267
+ src.allow = c.stringList(o.allow, `${p}.allow`);
268
+ if (o.deny !== undefined)
269
+ src.deny = c.stringList(o.deny, `${p}.deny`);
270
+ out.push(src);
271
+ }
272
+ else {
273
+ c.err(`${p}.kind`, 'must be "service" or "mcp"');
274
+ }
275
+ });
276
+ return out;
277
+ }
278
+ const TOP_KEYS = [
279
+ "$schema",
280
+ "version",
281
+ "provider",
282
+ "model",
283
+ "apiKeySecret",
284
+ "baseUrl",
285
+ "temperature",
286
+ "maxOutputTokens",
287
+ "greeting",
288
+ "bargeIn",
289
+ "speechDuringNonInterruptible",
290
+ "history",
291
+ "tools",
292
+ "toolSources",
293
+ "interruptPolicy",
294
+ "serviceWaitMs",
295
+ "fallbackText",
296
+ "speakChatReplies",
297
+ ];
298
+ export function validateLlmAgentConfig(input) {
299
+ const c = new Checker();
300
+ const root = c.object(input, "");
301
+ if (!root) {
302
+ return { ok: false, errors: [{ path: "", message: "must be an object" }] };
303
+ }
304
+ c.unknownKeys(root, TOP_KEYS, "");
305
+ if (root.version !== 1)
306
+ c.err("version", "must be 1");
307
+ let provider;
308
+ if (typeof root.provider === "string" &&
309
+ PROVIDER_IDS.includes(root.provider)) {
310
+ provider = root.provider;
311
+ }
312
+ else {
313
+ c.err("provider", `must be one of ${PROVIDER_IDS.join(", ")}`);
314
+ }
315
+ const config = { version: 1 };
316
+ if (provider)
317
+ config.provider = provider;
318
+ if (root.model !== undefined) {
319
+ const m = c.string(root.model, "model", { min: 1, max: 200 });
320
+ if (m !== undefined)
321
+ config.model = m;
322
+ }
323
+ const secret = c.string(root.apiKeySecret, "apiKeySecret", {
324
+ re: ENV_NAME_RE,
325
+ reMessage: ENV_NAME_MESSAGE,
326
+ });
327
+ if (secret !== undefined)
328
+ config.apiKeySecret = secret;
329
+ if (root.baseUrl !== undefined) {
330
+ const b = c.string(root.baseUrl, "baseUrl", { min: 1, max: 2048 });
331
+ if (b !== undefined) {
332
+ if (provider !== undefined && provider !== "openai") {
333
+ c.err("baseUrl", 'is only allowed when provider is "openai"');
334
+ }
335
+ else {
336
+ try {
337
+ const u = new URL(b);
338
+ if (u.protocol !== "http:" && u.protocol !== "https:") {
339
+ c.err("baseUrl", "must use http or https");
340
+ }
341
+ else {
342
+ config.baseUrl = b;
343
+ }
344
+ }
345
+ catch {
346
+ c.err("baseUrl", "must be a valid URL");
347
+ }
348
+ }
349
+ }
350
+ }
351
+ if (root.temperature !== undefined) {
352
+ const t = c.number(root.temperature, "temperature", 0, 2, false);
353
+ if (t !== undefined)
354
+ config.temperature = t;
355
+ }
356
+ if (root.maxOutputTokens !== undefined) {
357
+ const t = c.number(root.maxOutputTokens, "maxOutputTokens", 1, 8192, true);
358
+ if (t !== undefined)
359
+ config.maxOutputTokens = t;
360
+ }
361
+ if (root.greeting !== undefined) {
362
+ const g = c.object(root.greeting, "greeting");
363
+ if (g) {
364
+ c.unknownKeys(g, ["text", "interruptible"], "greeting");
365
+ const text = c.string(g.text, "greeting.text", { min: 1, max: 500 });
366
+ const greeting = {};
367
+ if (text !== undefined)
368
+ greeting.text = text;
369
+ if (g.interruptible !== undefined) {
370
+ const b = c.boolean(g.interruptible, "greeting.interruptible");
371
+ if (b !== undefined)
372
+ greeting.interruptible = b;
373
+ }
374
+ if (text !== undefined)
375
+ config.greeting = greeting;
376
+ }
377
+ }
378
+ if (root.bargeIn !== undefined) {
379
+ const b = c.object(root.bargeIn, "bargeIn");
380
+ if (b) {
381
+ c.unknownKeys(b, ["mode"], "bargeIn");
382
+ if (b.mode === "project" || b.mode === "on" || b.mode === "off") {
383
+ config.bargeIn = { mode: b.mode };
384
+ }
385
+ else {
386
+ c.err("bargeIn.mode", 'must be one of "project", "on", "off"');
387
+ }
388
+ }
389
+ }
390
+ if (root.speechDuringNonInterruptible !== undefined) {
391
+ const v = root.speechDuringNonInterruptible;
392
+ if (v === "answer_after" || v === "discard") {
393
+ config.speechDuringNonInterruptible = v;
394
+ }
395
+ else {
396
+ c.err("speechDuringNonInterruptible", 'must be one of "answer_after", "discard"');
397
+ }
398
+ }
399
+ if (root.history !== undefined) {
400
+ const h = c.object(root.history, "history");
401
+ if (h) {
402
+ c.unknownKeys(h, ["turns", "interruptionNote"], "history");
403
+ const history = {};
404
+ if (h.turns !== undefined) {
405
+ const t = c.number(h.turns, "history.turns", 1, 100, true);
406
+ if (t !== undefined)
407
+ history.turns = t;
408
+ }
409
+ if (h.interruptionNote !== undefined) {
410
+ const b = c.boolean(h.interruptionNote, "history.interruptionNote");
411
+ if (b !== undefined)
412
+ history.interruptionNote = b;
413
+ }
414
+ config.history = history;
415
+ }
416
+ }
417
+ if (root.tools !== undefined) {
418
+ const t = c.object(root.tools, "tools");
419
+ if (t) {
420
+ c.unknownKeys(t, ["maxRounds", "timeoutMs", "maxResultBytes", "filler"], "tools");
421
+ const tools = {};
422
+ if (t.maxRounds !== undefined) {
423
+ const n = c.number(t.maxRounds, "tools.maxRounds", 1, 10, true);
424
+ if (n !== undefined)
425
+ tools.maxRounds = n;
426
+ }
427
+ if (t.timeoutMs !== undefined) {
428
+ const n = c.number(t.timeoutMs, "tools.timeoutMs", 1000, 60000, true);
429
+ if (n !== undefined)
430
+ tools.timeoutMs = n;
431
+ }
432
+ if (t.maxResultBytes !== undefined) {
433
+ const n = c.number(t.maxResultBytes, "tools.maxResultBytes", 1024, 65536, true);
434
+ if (n !== undefined)
435
+ tools.maxResultBytes = n;
436
+ }
437
+ if (t.filler !== undefined) {
438
+ const f = c.object(t.filler, "tools.filler");
439
+ if (f) {
440
+ c.unknownKeys(f, ["text", "afterMs", "interruptible"], "tools.filler");
441
+ const text = c.string(f.text, "tools.filler.text", {
442
+ min: 1,
443
+ max: 500,
444
+ });
445
+ const filler = {};
446
+ if (text !== undefined)
447
+ filler.text = text;
448
+ if (f.afterMs !== undefined) {
449
+ const n = c.number(f.afterMs, "tools.filler.afterMs", 500, 10000, true);
450
+ if (n !== undefined)
451
+ filler.afterMs = n;
452
+ }
453
+ if (f.interruptible !== undefined) {
454
+ const b = c.boolean(f.interruptible, "tools.filler.interruptible");
455
+ if (b !== undefined)
456
+ filler.interruptible = b;
457
+ }
458
+ if (text !== undefined)
459
+ tools.filler = filler;
460
+ }
461
+ }
462
+ config.tools = tools;
463
+ }
464
+ }
465
+ if (root.toolSources !== undefined) {
466
+ const s = checkSources(c, root.toolSources, "toolSources");
467
+ if (s)
468
+ config.toolSources = s;
469
+ }
470
+ if (root.interruptPolicy !== undefined) {
471
+ if (root.interruptPolicy === "cancel" ||
472
+ root.interruptPolicy === "finish") {
473
+ config.interruptPolicy = root.interruptPolicy;
474
+ }
475
+ else {
476
+ c.err("interruptPolicy", 'must be one of "cancel", "finish"');
477
+ }
478
+ }
479
+ if (root.serviceWaitMs !== undefined) {
480
+ const n = c.number(root.serviceWaitMs, "serviceWaitMs", 0, 60000, true);
481
+ if (n !== undefined)
482
+ config.serviceWaitMs = n;
483
+ }
484
+ if (root.fallbackText !== undefined) {
485
+ const s = c.string(root.fallbackText, "fallbackText", { min: 1, max: 500 });
486
+ if (s !== undefined)
487
+ config.fallbackText = s;
488
+ }
489
+ if (root.speakChatReplies !== undefined) {
490
+ const b = c.boolean(root.speakChatReplies, "speakChatReplies");
491
+ if (b !== undefined)
492
+ config.speakChatReplies = b;
493
+ }
494
+ if (c.errors.length > 0)
495
+ return { ok: false, errors: c.errors };
496
+ return { ok: true, config: config };
497
+ }
498
+ const envName = {
499
+ type: "string",
500
+ pattern: "^AGENT_[A-Z0-9_]{1,57}$",
501
+ description: "Name of an AGENT_* environment variable (project secret), never its value.",
502
+ };
503
+ const nameList = {
504
+ type: "array",
505
+ items: { type: "string", minLength: 1, maxLength: 128 },
506
+ };
507
+ export const LLM_AGENT_CONFIG_JSON_SCHEMA = {
508
+ $schema: "https://json-schema.org/draft/2020-12/schema",
509
+ $id: "https://voicethere.io/schema/voicethere.llm.schema.json",
510
+ title: "VoiceThere LLM agent config",
511
+ type: "object",
512
+ additionalProperties: false,
513
+ required: ["version", "provider", "apiKeySecret"],
514
+ properties: {
515
+ $schema: { type: "string" },
516
+ version: { const: 1 },
517
+ provider: { enum: [...PROVIDER_IDS] },
518
+ model: { type: "string", minLength: 1, maxLength: 200 },
519
+ apiKeySecret: envName,
520
+ baseUrl: {
521
+ type: "string",
522
+ format: "uri",
523
+ pattern: "^https?://",
524
+ description: 'Only allowed when provider is "openai".',
525
+ },
526
+ temperature: { type: "number", minimum: 0, maximum: 2 },
527
+ maxOutputTokens: {
528
+ type: "integer",
529
+ minimum: 1,
530
+ maximum: 8192,
531
+ default: 512,
532
+ },
533
+ greeting: {
534
+ type: "object",
535
+ additionalProperties: false,
536
+ required: ["text"],
537
+ properties: {
538
+ text: { type: "string", minLength: 1, maxLength: 500 },
539
+ interruptible: { type: "boolean", default: false },
540
+ },
541
+ },
542
+ bargeIn: {
543
+ type: "object",
544
+ additionalProperties: false,
545
+ required: ["mode"],
546
+ properties: { mode: { enum: ["project", "on", "off"] } },
547
+ default: { mode: "project" },
548
+ },
549
+ speechDuringNonInterruptible: {
550
+ enum: ["answer_after", "discard"],
551
+ default: "answer_after",
552
+ },
553
+ history: {
554
+ type: "object",
555
+ additionalProperties: false,
556
+ properties: {
557
+ turns: { type: "integer", minimum: 1, maximum: 100, default: 20 },
558
+ interruptionNote: { type: "boolean", default: true },
559
+ },
560
+ },
561
+ tools: {
562
+ type: "object",
563
+ additionalProperties: false,
564
+ properties: {
565
+ maxRounds: { type: "integer", minimum: 1, maximum: 10, default: 5 },
566
+ timeoutMs: {
567
+ type: "integer",
568
+ minimum: 1000,
569
+ maximum: 60000,
570
+ default: 15000,
571
+ },
572
+ maxResultBytes: {
573
+ type: "integer",
574
+ minimum: 1024,
575
+ maximum: 65536,
576
+ default: 16384,
577
+ },
578
+ filler: {
579
+ type: "object",
580
+ additionalProperties: false,
581
+ required: ["text"],
582
+ properties: {
583
+ text: { type: "string", minLength: 1, maxLength: 500 },
584
+ afterMs: {
585
+ type: "integer",
586
+ minimum: 500,
587
+ maximum: 10000,
588
+ default: 1500,
589
+ },
590
+ interruptible: { type: "boolean", default: false },
591
+ },
592
+ },
593
+ },
594
+ },
595
+ toolSources: {
596
+ type: "array",
597
+ maxItems: MAX_SOURCES,
598
+ items: {
599
+ oneOf: [
600
+ {
601
+ type: "object",
602
+ additionalProperties: false,
603
+ required: ["kind"],
604
+ properties: {
605
+ kind: { const: "service" },
606
+ path: { type: "string", pattern: "^/", default: "/mcp" },
607
+ allow: nameList,
608
+ deny: nameList,
609
+ },
610
+ },
611
+ {
612
+ type: "object",
613
+ additionalProperties: false,
614
+ required: ["kind", "name", "url"],
615
+ properties: {
616
+ kind: { const: "mcp" },
617
+ name: { type: "string", pattern: "^[a-z0-9-]{1,40}$" },
618
+ url: {
619
+ type: "string",
620
+ format: "uri",
621
+ pattern: "^https://",
622
+ description: "https only; local and private addresses are rejected.",
623
+ },
624
+ auth: {
625
+ oneOf: [
626
+ {
627
+ type: "object",
628
+ additionalProperties: false,
629
+ required: ["type"],
630
+ properties: { type: { const: "none" } },
631
+ },
632
+ {
633
+ type: "object",
634
+ additionalProperties: false,
635
+ required: ["type", "secret"],
636
+ properties: {
637
+ type: { const: "bearer" },
638
+ secret: envName,
639
+ },
640
+ },
641
+ {
642
+ type: "object",
643
+ additionalProperties: false,
644
+ required: ["type", "headers"],
645
+ properties: {
646
+ type: { const: "headers" },
647
+ headers: {
648
+ type: "object",
649
+ propertyNames: { pattern: "^[A-Za-z0-9-]{1,64}$" },
650
+ additionalProperties: envName,
651
+ },
652
+ },
653
+ },
654
+ ],
655
+ },
656
+ allow: nameList,
657
+ deny: nameList,
658
+ },
659
+ },
660
+ ],
661
+ },
662
+ },
663
+ interruptPolicy: { enum: ["cancel", "finish"], default: "cancel" },
664
+ serviceWaitMs: {
665
+ type: "integer",
666
+ minimum: 0,
667
+ maximum: 60000,
668
+ default: 20000,
669
+ },
670
+ fallbackText: {
671
+ type: "string",
672
+ minLength: 1,
673
+ maxLength: 500,
674
+ default: "Sorry, something went wrong. Please try again.",
675
+ },
676
+ speakChatReplies: { type: "boolean", default: true },
677
+ },
678
+ };
679
+ //# sourceMappingURL=config.js.map