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