@voicethere/agent 0.12.0 → 0.13.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 (45) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/llm/agent/config.d.ts.map +1 -1
  6. package/dist/llm/agent/config.js +7 -6
  7. package/dist/llm/agent/config.js.map +1 -1
  8. package/dist/llm/agent/create-llm-agent.d.ts +3 -1
  9. package/dist/llm/agent/create-llm-agent.d.ts.map +1 -1
  10. package/dist/llm/agent/create-llm-agent.js +11 -4
  11. package/dist/llm/agent/create-llm-agent.js.map +1 -1
  12. package/dist/llm/anthropic.d.ts +6 -0
  13. package/dist/llm/anthropic.d.ts.map +1 -0
  14. package/dist/llm/anthropic.js +8 -0
  15. package/dist/llm/anthropic.js.map +1 -0
  16. package/dist/llm/catalog.js +4 -4
  17. package/dist/llm/catalog.js.map +1 -1
  18. package/dist/llm/gemini.d.ts +6 -0
  19. package/dist/llm/gemini.d.ts.map +1 -0
  20. package/dist/llm/gemini.js +8 -0
  21. package/dist/llm/gemini.js.map +1 -0
  22. package/dist/llm/index.d.ts +1 -1
  23. package/dist/llm/index.d.ts.map +1 -1
  24. package/dist/llm/index.js.map +1 -1
  25. package/dist/llm/openai.d.ts +6 -0
  26. package/dist/llm/openai.d.ts.map +1 -0
  27. package/dist/llm/openai.js +12 -0
  28. package/dist/llm/openai.js.map +1 -0
  29. package/dist/llm/providers.d.ts +4 -2
  30. package/dist/llm/providers.d.ts.map +1 -1
  31. package/dist/llm/providers.js +20 -22
  32. package/dist/llm/providers.js.map +1 -1
  33. package/dist/llm/types.d.ts +10 -0
  34. package/dist/llm/types.d.ts.map +1 -1
  35. package/dist/runtime.d.ts +9 -0
  36. package/dist/runtime.d.ts.map +1 -1
  37. package/dist/runtime.js +24 -0
  38. package/dist/runtime.js.map +1 -1
  39. package/dist/templates/llm-agent/agent.js +25559 -100185
  40. package/eject/llm/loop.ts +27 -9
  41. package/package.json +19 -1
  42. package/schema/voicethere.llm.schema.json +6 -6
  43. package/templates/llm-agent/README.md +12 -2
  44. package/templates/llm-agent/agent.ts +9 -1
  45. package/templates/llm-agent/voicethere.llm.json +1 -1
package/eject/llm/loop.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copied from @voicethere/agent 0.12.0. Package updates no longer change this file.
1
+ // Copied from @voicethere/agent 0.13.0. Package updates no longer change this file.
2
2
  import { randomUUID } from "node:crypto";
3
3
  import {
4
4
  type AgentHandlers,
@@ -23,6 +23,7 @@ import {
23
23
  type LlmMessage,
24
24
  type LlmProvider,
25
25
  LlmProviderError,
26
+ type LlmProviderModule,
26
27
  type LlmStreamEvent,
27
28
  type LlmToolResult,
28
29
  McpToolSource,
@@ -48,6 +49,8 @@ export interface CreateLlmAgentOptions {
48
49
  env?: () => Record<string, string | undefined>;
49
50
  /** Test injection. */
50
51
  provider?: LlmProvider;
52
+ /** Provider SDK modules this agent may use, e.g. `[openai]` from `@voicethere/agent/llm/openai`. Must include the one `config.provider` selects. */
53
+ providers?: readonly LlmProviderModule[];
51
54
  now?: () => number;
52
55
  /** Test injection for MCP tool sources. */
53
56
  sourceFactory?: (opts: McpToolSourceOptions) => McpToolSource;
@@ -132,6 +135,18 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
132
135
  );
133
136
  }
134
137
  const config: LlmAgentConfig = validated.config;
138
+ if (
139
+ !opts.provider &&
140
+ !(opts.providers ?? []).some((m) => m.ids.includes(config.provider))
141
+ ) {
142
+ // Quotes are interpolated so the eject copy's import scan sees no specifier here.
143
+ const sub = config.provider === "openrouter" ? "openai" : config.provider;
144
+ const q = '"';
145
+ throw configError(
146
+ `voicethere.llm.json selects provider ${q}${config.provider}${q}, but agent.ts does not register it. Add: import { ${sub} } from ${q}@voicethere/agent/llm/${sub}${q}; and pass providers: [${sub}]`,
147
+ "LLM_CONFIG_INVALID",
148
+ );
149
+ }
135
150
  const hooks = opts.hooks ?? {};
136
151
  const now = opts.now ?? Date.now;
137
152
  const getEnv = opts.env ?? (() => process.env);
@@ -236,7 +251,7 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
236
251
  const sources: McpToolSource[] = [];
237
252
  for (const src of config.toolSources ?? []) {
238
253
  if (src.kind === "service") {
239
- const base = env.VOICETHERE_SERVICE_URL;
254
+ const base = env.AGENT_SERVICE_URL;
240
255
  if (!nonEmpty(base)) {
241
256
  agentLog(
242
257
  "warn",
@@ -245,11 +260,11 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
245
260
  continue;
246
261
  }
247
262
  const headers: Record<string, string> = {};
248
- const token = env.VOICETHERE_SERVICE_TOKEN;
263
+ const token = env.AGENT_SERVICE_TOKEN;
249
264
  if (nonEmpty(token)) {
250
265
  headers.Authorization = `Bearer ${token}`;
251
266
  } else {
252
- agentLog("warn", "toolSources: VOICETHERE_SERVICE_TOKEN is not set");
267
+ agentLog("warn", "toolSources: AGENT_SERVICE_TOKEN is not set");
253
268
  }
254
269
  const source = makeSource({
255
270
  name: "service",
@@ -822,11 +837,14 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
822
837
  );
823
838
  }
824
839
  if (!provider) {
825
- provider = createLlmProvider({
826
- provider: config.provider,
827
- apiKey,
828
- baseUrl: config.baseUrl,
829
- });
840
+ provider = createLlmProvider(
841
+ {
842
+ provider: config.provider,
843
+ apiKey,
844
+ baseUrl: config.baseUrl,
845
+ },
846
+ opts.providers ?? [],
847
+ );
830
848
  }
831
849
  buildRegistry(env);
832
850
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voicethere/agent",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "VoiceThere customer agent SDK — IPC types and runtime helpers for sandboxed child bundles",
5
5
  "type": "module",
6
6
  "exports": {
@@ -22,6 +22,24 @@
22
22
  "require": "./dist/host/index.js",
23
23
  "default": "./dist/host/index.js"
24
24
  },
25
+ "./llm/openai": {
26
+ "types": "./dist/llm/openai.d.ts",
27
+ "import": "./dist/llm/openai.js",
28
+ "require": "./dist/llm/openai.js",
29
+ "default": "./dist/llm/openai.js"
30
+ },
31
+ "./llm/anthropic": {
32
+ "types": "./dist/llm/anthropic.d.ts",
33
+ "import": "./dist/llm/anthropic.js",
34
+ "require": "./dist/llm/anthropic.js",
35
+ "default": "./dist/llm/anthropic.js"
36
+ },
37
+ "./llm/gemini": {
38
+ "types": "./dist/llm/gemini.d.ts",
39
+ "import": "./dist/llm/gemini.js",
40
+ "require": "./dist/llm/gemini.js",
41
+ "default": "./dist/llm/gemini.js"
42
+ },
25
43
  "./llm": {
26
44
  "types": "./dist/llm/index.d.ts",
27
45
  "import": "./dist/llm/index.js",
@@ -31,8 +31,8 @@
31
31
  },
32
32
  "apiKeySecret": {
33
33
  "type": "string",
34
- "pattern": "^[A-Z][A-Z0-9_]{0,63}$",
35
- "description": "Name of an environment variable (secret), never its value."
34
+ "pattern": "^AGENT_[A-Z0-9_]{1,57}$",
35
+ "description": "Name of an AGENT_* environment variable (project secret), never its value."
36
36
  },
37
37
  "baseUrl": {
38
38
  "type": "string",
@@ -246,8 +246,8 @@
246
246
  },
247
247
  "secret": {
248
248
  "type": "string",
249
- "pattern": "^[A-Z][A-Z0-9_]{0,63}$",
250
- "description": "Name of an environment variable (secret), never its value."
249
+ "pattern": "^AGENT_[A-Z0-9_]{1,57}$",
250
+ "description": "Name of an AGENT_* environment variable (project secret), never its value."
251
251
  }
252
252
  }
253
253
  },
@@ -269,8 +269,8 @@
269
269
  },
270
270
  "additionalProperties": {
271
271
  "type": "string",
272
- "pattern": "^[A-Z][A-Z0-9_]{0,63}$",
273
- "description": "Name of an environment variable (secret), never its value."
272
+ "pattern": "^AGENT_[A-Z0-9_]{1,57}$",
273
+ "description": "Name of an AGENT_* environment variable (project secret), never its value."
274
274
  }
275
275
  }
276
276
  }
@@ -13,11 +13,21 @@ A voice and chat agent powered by an LLM, with custom tools and MCP servers. Sou
13
13
 
14
14
  ## Set the API key
15
15
 
16
- The default provider is OpenAI. Add a project secret named `OPENAI_API_KEY` with your key, then deploy. The key is read by name from `apiKeySecret` in `voicethere.llm.json`; it is never stored in the file.
16
+ The default provider is OpenAI. Add a project secret named `AGENT_OPENAI_API_KEY` with your key, then deploy. The key is read by name from `apiKeySecret` in `voicethere.llm.json`; it is never stored in the file. Only project secrets whose names start with `AGENT_` reach the agent.
17
17
 
18
18
  ## Switch providers
19
19
 
20
- Change `provider`, `model` and `apiKeySecret` in `voicethere.llm.json`. For example, `anthropic` with `ANTHROPIC_API_KEY`, `gemini` with `GEMINI_API_KEY`, or `openrouter` with `OPENROUTER_API_KEY`. Create the matching project secret before you deploy.
20
+ Change `provider`, `model` and `apiKeySecret` in `voicethere.llm.json`. For example, `anthropic` with `AGENT_ANTHROPIC_API_KEY`, `gemini` with `AGENT_GEMINI_API_KEY`, or `openrouter` with `AGENT_OPENROUTER_API_KEY`. Create the matching project secret before you deploy.
21
+
22
+ ## Switching provider
23
+
24
+ Only the provider you import in `agent.ts` is bundled. When you change `provider` in `voicethere.llm.json`, also change the import and the `providers` list:
25
+
26
+ - `anthropic`: `import { anthropic } from "@voicethere/agent/llm/anthropic";` and `providers: [anthropic]`
27
+ - `gemini`: `import { gemini } from "@voicethere/agent/llm/gemini";` and `providers: [gemini]`
28
+ - `openrouter` uses the `openai` module.
29
+
30
+ If they do not match, `createLlmAgent` throws when the bundle loads, and the deploy check reports it.
21
31
 
22
32
  ## Learn more
23
33
 
@@ -1,8 +1,16 @@
1
1
  import { defineAgent } from "@voicethere/agent";
2
2
  import { createLlmAgent } from "@voicethere/agent/llm";
3
+ import { openai } from "@voicethere/agent/llm/openai";
3
4
  import config from "./voicethere.llm.json";
4
5
  import systemPrompt from "./prompt.md";
5
6
  import { tools } from "./tools";
6
7
  import { hooks } from "./hooks";
7
8
 
8
- defineAgent(createLlmAgent({ config, systemPrompt, tools, hooks }));
9
+ // Only the provider you import here is bundled. To switch provider, change
10
+ // "provider" in voicethere.llm.json and import its module instead:
11
+ // anthropic → import { anthropic } from "@voicethere/agent/llm/anthropic";
12
+ // gemini → import { gemini } from "@voicethere/agent/llm/gemini";
13
+ // openrouter uses the openai module.
14
+ defineAgent(
15
+ createLlmAgent({ config, systemPrompt, tools, hooks, providers: [openai] }),
16
+ );
@@ -3,7 +3,7 @@
3
3
  "version": 1,
4
4
  "provider": "openai",
5
5
  "model": "gpt-4o-mini",
6
- "apiKeySecret": "OPENAI_API_KEY",
6
+ "apiKeySecret": "AGENT_OPENAI_API_KEY",
7
7
  "maxOutputTokens": 300,
8
8
  "greeting": {
9
9
  "text": "Hi! How can I help you today?",