@voicethere/agent 0.23.0 → 0.23.2

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 (56) hide show
  1. package/README.md +2 -0
  2. package/dist/agent.js +29 -1
  3. package/dist/llm/agent/config.d.ts +5 -0
  4. package/dist/llm/agent/config.d.ts.map +1 -1
  5. package/dist/llm/agent/config.js +1 -0
  6. package/dist/llm/agent/config.js.map +1 -1
  7. package/dist/llm/agent/create-llm-agent.d.ts.map +1 -1
  8. package/dist/llm/agent/create-llm-agent.js +37 -0
  9. package/dist/llm/agent/create-llm-agent.js.map +1 -1
  10. package/dist/llm/agent/hooks.d.ts +5 -1
  11. package/dist/llm/agent/hooks.d.ts.map +1 -1
  12. package/dist/llm/anthropic-provider.d.ts.map +1 -1
  13. package/dist/llm/anthropic-provider.js +9 -4
  14. package/dist/llm/anthropic-provider.js.map +1 -1
  15. package/dist/llm/gemini-provider.d.ts.map +1 -1
  16. package/dist/llm/gemini-provider.js +4 -0
  17. package/dist/llm/gemini-provider.js.map +1 -1
  18. package/dist/llm/index.d.ts +1 -1
  19. package/dist/llm/index.d.ts.map +1 -1
  20. package/dist/llm/index.js.map +1 -1
  21. package/dist/llm/openai-provider.d.ts.map +1 -1
  22. package/dist/llm/openai-provider.js +4 -0
  23. package/dist/llm/openai-provider.js.map +1 -1
  24. package/dist/llm/types.d.ts +14 -4
  25. package/dist/llm/types.d.ts.map +1 -1
  26. package/dist/llm/types.js.map +1 -1
  27. package/dist/runtime.d.ts +8 -0
  28. package/dist/runtime.d.ts.map +1 -1
  29. package/dist/runtime.js +40 -3
  30. package/dist/runtime.js.map +1 -1
  31. package/dist/sandbox/loader-entry.js +21 -1
  32. package/dist/templates/echo/agent.js +29 -1
  33. package/dist/templates/echo-dc/agent.js +29 -1
  34. package/dist/templates/game-sync/agent.js +29 -1
  35. package/dist/templates/language-switch/agent.js +29 -1
  36. package/dist/templates/llm-agent/agent.js +60 -4
  37. package/dist/templates/llm-docs-rag/agent.js +60 -4
  38. package/dist/templates/llm-mcp-service/agent.js +60 -4
  39. package/dist/templates/positional-tts/agent.js +29 -1
  40. package/dist/templates/recording-consent/agent.js +29 -1
  41. package/dist/templates/spatial-showcase/agent.js +29 -1
  42. package/dist/templates/voice-showcase/agent.js +29 -1
  43. package/dist/templates/voice-starter/agent.js +29 -1
  44. package/dist/templates/webhooks/agent.js +29 -1
  45. package/dist/templates/webhooks-redis/agent.js +29 -1
  46. package/dist/templates/world-sync/agent.js +29 -1
  47. package/dist/templates/world-sync-binary/agent.js +29 -1
  48. package/eject/llm/loop.ts +48 -1
  49. package/package.json +1 -1
  50. package/schema/voicethere.llm.schema.json +2 -1
  51. package/templates/llm-agent/README.md +4 -0
  52. package/templates/llm-agent/voicethere.llm.json +1 -1
  53. package/templates/llm-docs-rag/README.md +4 -0
  54. package/templates/llm-docs-rag/voicethere.llm.json +1 -1
  55. package/templates/llm-mcp-service/README.md +4 -0
  56. package/templates/llm-mcp-service/voicethere.llm.json +1 -1
@@ -11312,6 +11312,34 @@ function clearPendingConversationHistoryAcksForSession(sessionId, reason) {
11312
11312
  }
11313
11313
  var sessionExecutionContext = new AsyncLocalStorage();
11314
11314
  var agentLogSessionContext = new AsyncLocalStorage();
11315
+ var CURRENT_SESSION_ID_GETTER_KEY = Symbol.for("voicethere.agent.currentSessionId");
11316
+ function currentHandlerSessionId() {
11317
+ const id = sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
11318
+ return id ? id : void 0;
11319
+ }
11320
+ var previousSessionIdGetter;
11321
+ function stringOrUndefined(value) {
11322
+ return typeof value === "string" && value ? value : void 0;
11323
+ }
11324
+ function currentSessionIdGetter() {
11325
+ const own = currentHandlerSessionId();
11326
+ if (own)
11327
+ return own;
11328
+ try {
11329
+ return stringOrUndefined(previousSessionIdGetter?.());
11330
+ } catch {
11331
+ return void 0;
11332
+ }
11333
+ }
11334
+ function installCurrentSessionIdGetter() {
11335
+ const g = globalThis;
11336
+ const previous = g[CURRENT_SESSION_ID_GETTER_KEY];
11337
+ if (previous === currentSessionIdGetter)
11338
+ return;
11339
+ g[CURRENT_SESSION_ID_GETTER_KEY] = currentSessionIdGetter;
11340
+ previousSessionIdGetter = typeof previous === "function" ? previous : void 0;
11341
+ }
11342
+ installCurrentSessionIdGetter();
11315
11343
  var inboundQueueAuthority = null;
11316
11344
  var childUnhandledRejectionGuardInstalled = false;
11317
11345
  function normalizeRejectionReason(reason) {
@@ -11842,7 +11870,7 @@ function sanitizeAgentLogFields(fields) {
11842
11870
  }
11843
11871
  }
11844
11872
  function buildAgentLogPayload(level, message, fields, sessionId) {
11845
- const resolvedSessionId = sessionId ?? sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
11873
+ const resolvedSessionId = sessionId ?? currentHandlerSessionId();
11846
11874
  const sanitizedFields = fields ? sanitizeAgentLogFields(fields) : void 0;
11847
11875
  return {
11848
11876
  type: "log",
@@ -557,6 +557,34 @@ function clearPendingConversationHistoryAcksForSession(sessionId, reason) {
557
557
  }
558
558
  var sessionExecutionContext = new AsyncLocalStorage();
559
559
  var agentLogSessionContext = new AsyncLocalStorage();
560
+ var CURRENT_SESSION_ID_GETTER_KEY = Symbol.for("voicethere.agent.currentSessionId");
561
+ function currentHandlerSessionId() {
562
+ const id = sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
563
+ return id ? id : void 0;
564
+ }
565
+ var previousSessionIdGetter;
566
+ function stringOrUndefined(value) {
567
+ return typeof value === "string" && value ? value : void 0;
568
+ }
569
+ function currentSessionIdGetter() {
570
+ const own = currentHandlerSessionId();
571
+ if (own)
572
+ return own;
573
+ try {
574
+ return stringOrUndefined(previousSessionIdGetter?.());
575
+ } catch {
576
+ return void 0;
577
+ }
578
+ }
579
+ function installCurrentSessionIdGetter() {
580
+ const g = globalThis;
581
+ const previous = g[CURRENT_SESSION_ID_GETTER_KEY];
582
+ if (previous === currentSessionIdGetter)
583
+ return;
584
+ g[CURRENT_SESSION_ID_GETTER_KEY] = currentSessionIdGetter;
585
+ previousSessionIdGetter = typeof previous === "function" ? previous : void 0;
586
+ }
587
+ installCurrentSessionIdGetter();
560
588
  var inboundQueueAuthority = null;
561
589
  var childUnhandledRejectionGuardInstalled = false;
562
590
  function normalizeRejectionReason(reason) {
@@ -1082,7 +1110,7 @@ function sanitizeAgentLogFields(fields) {
1082
1110
  }
1083
1111
  }
1084
1112
  function buildAgentLogPayload(level, message, fields, sessionId) {
1085
- const resolvedSessionId = sessionId ?? sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
1113
+ const resolvedSessionId = sessionId ?? currentHandlerSessionId();
1086
1114
  const sanitizedFields = fields ? sanitizeAgentLogFields(fields) : void 0;
1087
1115
  return {
1088
1116
  type: "log",
@@ -557,6 +557,34 @@ function clearPendingConversationHistoryAcksForSession(sessionId, reason) {
557
557
  }
558
558
  var sessionExecutionContext = new AsyncLocalStorage();
559
559
  var agentLogSessionContext = new AsyncLocalStorage();
560
+ var CURRENT_SESSION_ID_GETTER_KEY = Symbol.for("voicethere.agent.currentSessionId");
561
+ function currentHandlerSessionId() {
562
+ const id = sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
563
+ return id ? id : void 0;
564
+ }
565
+ var previousSessionIdGetter;
566
+ function stringOrUndefined(value) {
567
+ return typeof value === "string" && value ? value : void 0;
568
+ }
569
+ function currentSessionIdGetter() {
570
+ const own = currentHandlerSessionId();
571
+ if (own)
572
+ return own;
573
+ try {
574
+ return stringOrUndefined(previousSessionIdGetter?.());
575
+ } catch {
576
+ return void 0;
577
+ }
578
+ }
579
+ function installCurrentSessionIdGetter() {
580
+ const g = globalThis;
581
+ const previous = g[CURRENT_SESSION_ID_GETTER_KEY];
582
+ if (previous === currentSessionIdGetter)
583
+ return;
584
+ g[CURRENT_SESSION_ID_GETTER_KEY] = currentSessionIdGetter;
585
+ previousSessionIdGetter = typeof previous === "function" ? previous : void 0;
586
+ }
587
+ installCurrentSessionIdGetter();
560
588
  var inboundQueueAuthority = null;
561
589
  var childUnhandledRejectionGuardInstalled = false;
562
590
  function normalizeRejectionReason(reason) {
@@ -1093,7 +1121,7 @@ function sanitizeAgentLogFields(fields) {
1093
1121
  }
1094
1122
  }
1095
1123
  function buildAgentLogPayload(level, message, fields, sessionId) {
1096
- const resolvedSessionId = sessionId ?? sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
1124
+ const resolvedSessionId = sessionId ?? currentHandlerSessionId();
1097
1125
  const sanitizedFields = fields ? sanitizeAgentLogFields(fields) : void 0;
1098
1126
  return {
1099
1127
  type: "log",
package/eject/llm/loop.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copied from @voicethere/agent 0.23.0. Package updates no longer change this file.
1
+ // Copied from @voicethere/agent 0.23.2. Package updates no longer change this file.
2
2
  import { randomUUID } from "node:crypto";
3
3
  import {
4
4
  type AgentHandlers,
@@ -39,6 +39,7 @@ import {
39
39
  type LlmProvider,
40
40
  LlmProviderError,
41
41
  type LlmProviderModule,
42
+ type LlmStopReason,
42
43
  type LlmStreamEvent,
43
44
  type LlmToolResult,
44
45
  McpToolSource,
@@ -110,6 +111,10 @@ interface TurnState {
110
111
  firstTokenMs?: number;
111
112
  inputTokens?: number;
112
113
  outputTokens?: number;
114
+ /** Hidden thinking share of `outputTokens`, when the provider reports it. */
115
+ reasoningTokens?: number;
116
+ /** Stop reason of the last LLM round of this turn. */
117
+ stopReason?: LlmStopReason;
113
118
  errorCode?: string;
114
119
  abortStatus?: "interrupted" | "cancelled";
115
120
  roundOpen: boolean;
@@ -1044,7 +1049,12 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
1044
1049
  if (done.usage.outputTokens !== undefined) {
1045
1050
  t.outputTokens = (t.outputTokens ?? 0) + done.usage.outputTokens;
1046
1051
  }
1052
+ if (done.usage.reasoningTokens !== undefined) {
1053
+ t.reasoningTokens =
1054
+ (t.reasoningTokens ?? 0) + done.usage.reasoningTokens;
1055
+ }
1047
1056
  }
1057
+ t.stopReason = done.stopReason;
1048
1058
  t.roundOpen = false;
1049
1059
  return done;
1050
1060
  }
@@ -1061,6 +1071,10 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
1061
1071
  ...(t.firstTokenMs !== undefined ? { firstTokenMs: t.firstTokenMs } : {}),
1062
1072
  ...(t.inputTokens !== undefined ? { inputTokens: t.inputTokens } : {}),
1063
1073
  ...(t.outputTokens !== undefined ? { outputTokens: t.outputTokens } : {}),
1074
+ ...(t.reasoningTokens !== undefined
1075
+ ? { reasoningTokens: t.reasoningTokens }
1076
+ : {}),
1077
+ ...(t.stopReason !== undefined ? { stopReason: t.stopReason } : {}),
1064
1078
  ...(t.errorCode ? { errorCode: t.errorCode } : {}),
1065
1079
  ...(t.linkUrls.size > 0 ? { linksSent: t.linkUrls.size } : {}),
1066
1080
  ...(t.linksDropped > 0 ? { linksDropped: t.linksDropped } : {}),
@@ -1102,6 +1116,37 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
1102
1116
  for (let round = 0; round < maxRounds; round += 1) {
1103
1117
  const done = await runRound(s, t, ctx);
1104
1118
  const calls = done.toolCalls;
1119
+ if (calls.length === 0 && done.stopReason === "max_tokens") {
1120
+ // The output cap cut the answer (thinking models spend hidden
1121
+ // reasoning tokens against it). Metadata only in the log.
1122
+ // Partial only when THIS answer round delivered text; a preamble
1123
+ // spoken before a tool call does not answer the caller.
1124
+ const partial = t.roundText.trim().length > 0;
1125
+ agentLog(
1126
+ "warn",
1127
+ "llm turn truncated: LLM_OUTPUT_TRUNCATED",
1128
+ {
1129
+ code: "LLM_OUTPUT_TRUNCATED",
1130
+ round: round + 1,
1131
+ outputTokens: done.usage?.outputTokens,
1132
+ ...(done.usage?.reasoningTokens !== undefined
1133
+ ? { reasoningTokens: done.usage.reasoningTokens }
1134
+ : {}),
1135
+ maxOutputTokens: config.maxOutputTokens ?? D.maxOutputTokens,
1136
+ partial,
1137
+ },
1138
+ s.sessionId,
1139
+ );
1140
+ if (!partial) {
1141
+ // Nothing reached the caller: same as any other failed turn.
1142
+ t.errorCode = "LLM_OUTPUT_TRUNCATED";
1143
+ speakFallback(s, t);
1144
+ t.status = "failed";
1145
+ return summarize(t);
1146
+ }
1147
+ // Text already reached the caller: keep it (never re-send) and
1148
+ // finish the turn as completed; the summary carries stopReason.
1149
+ }
1105
1150
  if (calls.length === 0) {
1106
1151
  s.history.addAssistant(
1107
1152
  {
@@ -1287,6 +1332,8 @@ export function createLlmAgent(opts: CreateLlmAgentOptions): AgentHandlers {
1287
1332
  firstTokenMs: summary.firstTokenMs,
1288
1333
  inputTokens: summary.inputTokens,
1289
1334
  outputTokens: summary.outputTokens,
1335
+ reasoningTokens: summary.reasoningTokens,
1336
+ stopReason: summary.stopReason,
1290
1337
  thinkingCharsStripped: t.thinkingCharsStripped,
1291
1338
  linksSent: t.linkUrls.size,
1292
1339
  linksDropped: t.linksDropped,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voicethere/agent",
3
- "version": "0.23.0",
3
+ "version": "0.23.2",
4
4
  "description": "VoiceThere customer agent SDK — IPC types and runtime helpers for sandboxed child bundles",
5
5
  "type": "module",
6
6
  "exports": {
@@ -40,7 +40,8 @@
40
40
  "type": "integer",
41
41
  "minimum": 1,
42
42
  "maximum": 8192,
43
- "default": 512
43
+ "default": 512,
44
+ "description": "Output token cap per LLM call. Thinking models count hidden reasoning against maxOutputTokens; keep spoken replies short in the prompt, not with a small cap. A reply cut off before anything was spoken fails the turn with LLM_OUTPUT_TRUNCATED."
44
45
  },
45
46
  "toolChoice": {
46
47
  "enum": ["auto", "required-first-round"],
@@ -85,6 +85,10 @@ createLlmAgent({
85
85
 
86
86
  It is never added automatically.
87
87
 
88
+ ## Output token cap
89
+
90
+ `maxOutputTokens` is 1024 in `voicethere.llm.json`. Thinking models count hidden reasoning against `maxOutputTokens`, so keep spoken replies short in the prompt, not with a small cap. A reply cut off by the cap before anything was spoken ends the turn with `LLM_OUTPUT_TRUNCATED` and the fallback text.
91
+
88
92
  ## Switch providers
89
93
 
90
94
  Change `provider`, `model` and `apiKeySecret` in `voicethere.llm.json`. To go back to OpenAI, use `provider: "openai"`, `model: "gpt-4o-mini"` and `AGENT_OPENAI_API_KEY`; no import changes. Other options are `anthropic` with `AGENT_ANTHROPIC_API_KEY` and `gemini` with `AGENT_GEMINI_API_KEY`. Create the matching project secret before you deploy.
@@ -4,7 +4,7 @@
4
4
  "provider": "openrouter",
5
5
  "model": "anthropic/claude-haiku-5.5",
6
6
  "apiKeySecret": "AGENT_OPENROUTER_API_KEY",
7
- "maxOutputTokens": 300,
7
+ "maxOutputTokens": 1024,
8
8
  "greeting": {
9
9
  "text": "Hi! How can I help you today?",
10
10
  "interruptible": true
@@ -38,6 +38,10 @@ Redeploy the project. The agent connects to `/mcp` on the service with the proje
38
38
  - `"toolChoice": "required-first-round"` makes every turn start with a docs search, so the answer comes from your docs and not from the model's memory. Remove it if the assistant should also handle small talk without searching.
39
39
  - Set the provider, model and API key as in the `llm-agent` template: the template starts on OpenRouter with `anthropic/claude-haiku-5.5`, key `AGENT_OPENROUTER_API_KEY` (a project secret).
40
40
 
41
+ ## Output token cap
42
+
43
+ `maxOutputTokens` is 1024 in `voicethere.llm.json`. Thinking models count hidden reasoning against `maxOutputTokens`, so keep spoken replies short in the prompt, not with a small cap. A reply cut off by the cap before anything was spoken ends the turn with `LLM_OUTPUT_TRUNCATED` and the fallback text.
44
+
41
45
  ## Files
42
46
 
43
47
  - `agent.ts` wires the pieces together. You rarely need to change it.
@@ -4,7 +4,7 @@
4
4
  "provider": "openrouter",
5
5
  "model": "anthropic/claude-haiku-5.5",
6
6
  "apiKeySecret": "AGENT_OPENROUTER_API_KEY",
7
- "maxOutputTokens": 300,
7
+ "maxOutputTokens": 1024,
8
8
  "greeting": {
9
9
  "text": "Hi! Ask me anything about our documentation.",
10
10
  "interruptible": true
@@ -109,6 +109,10 @@ createLlmAgent({
109
109
 
110
110
  It is never added automatically.
111
111
 
112
+ ## Output token cap
113
+
114
+ `maxOutputTokens` is 1024 in `voicethere.llm.json`. Thinking models count hidden reasoning against `maxOutputTokens`, so keep spoken replies short in the prompt, not with a small cap. A reply cut off by the cap before anything was spoken ends the turn with `LLM_OUTPUT_TRUNCATED` and the fallback text.
115
+
112
116
  ## Switch providers
113
117
 
114
118
  Change `provider`, `model` and `apiKeySecret` in `voicethere.llm.json`. To go back to OpenAI, use `provider: "openai"`, `model: "gpt-4o-mini"` and `AGENT_OPENAI_API_KEY`; no import changes. Other options are `anthropic` with `AGENT_ANTHROPIC_API_KEY` and `gemini` with `AGENT_GEMINI_API_KEY`. Create the matching project secret before you deploy.
@@ -4,7 +4,7 @@
4
4
  "provider": "openrouter",
5
5
  "model": "anthropic/claude-haiku-5.5",
6
6
  "apiKeySecret": "AGENT_OPENROUTER_API_KEY",
7
- "maxOutputTokens": 300,
7
+ "maxOutputTokens": 1024,
8
8
  "greeting": {
9
9
  "text": "Hi! How can I help you today?",
10
10
  "interruptible": true