@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
@@ -31205,6 +31205,34 @@ function isVoicethereAgentChild() {
31205
31205
  }
31206
31206
  var sessionExecutionContext = new AsyncLocalStorage();
31207
31207
  var agentLogSessionContext = new AsyncLocalStorage();
31208
+ var CURRENT_SESSION_ID_GETTER_KEY = Symbol.for("voicethere.agent.currentSessionId");
31209
+ function currentHandlerSessionId() {
31210
+ const id = sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
31211
+ return id ? id : void 0;
31212
+ }
31213
+ var previousSessionIdGetter;
31214
+ function stringOrUndefined(value) {
31215
+ return typeof value === "string" && value ? value : void 0;
31216
+ }
31217
+ function currentSessionIdGetter() {
31218
+ const own2 = currentHandlerSessionId();
31219
+ if (own2)
31220
+ return own2;
31221
+ try {
31222
+ return stringOrUndefined(previousSessionIdGetter?.());
31223
+ } catch {
31224
+ return void 0;
31225
+ }
31226
+ }
31227
+ function installCurrentSessionIdGetter() {
31228
+ const g = globalThis;
31229
+ const previous = g[CURRENT_SESSION_ID_GETTER_KEY];
31230
+ if (previous === currentSessionIdGetter)
31231
+ return;
31232
+ g[CURRENT_SESSION_ID_GETTER_KEY] = currentSessionIdGetter;
31233
+ previousSessionIdGetter = typeof previous === "function" ? previous : void 0;
31234
+ }
31235
+ installCurrentSessionIdGetter();
31208
31236
  var inboundQueueAuthority = null;
31209
31237
  var childUnhandledRejectionGuardInstalled = false;
31210
31238
  function normalizeRejectionReason(reason) {
@@ -31858,7 +31886,7 @@ function sanitizeAgentLogFields(fields) {
31858
31886
  }
31859
31887
  }
31860
31888
  function buildAgentLogPayload(level, message, fields, sessionId) {
31861
- const resolvedSessionId = sessionId ?? sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
31889
+ const resolvedSessionId = sessionId ?? currentHandlerSessionId();
31862
31890
  const sanitizedFields = fields ? sanitizeAgentLogFields(fields) : void 0;
31863
31891
  return {
31864
31892
  type: "log",
@@ -34568,7 +34596,8 @@ var LLM_AGENT_CONFIG_JSON_SCHEMA = {
34568
34596
  type: "integer",
34569
34597
  minimum: 1,
34570
34598
  maximum: 8192,
34571
- default: 512
34599
+ default: 512,
34600
+ 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."
34572
34601
  },
34573
34602
  toolChoice: {
34574
34603
  enum: ["auto", "required-first-round"],
@@ -35935,7 +35964,11 @@ ${validated.errors.map((e) => `${e.path || "(root)"}: ${e.message}`).join("\n")}
35935
35964
  if (done.usage.outputTokens !== void 0) {
35936
35965
  t.outputTokens = (t.outputTokens ?? 0) + done.usage.outputTokens;
35937
35966
  }
35967
+ if (done.usage.reasoningTokens !== void 0) {
35968
+ t.reasoningTokens = (t.reasoningTokens ?? 0) + done.usage.reasoningTokens;
35969
+ }
35938
35970
  }
35971
+ t.stopReason = done.stopReason;
35939
35972
  t.roundOpen = false;
35940
35973
  return done;
35941
35974
  }
@@ -35949,6 +35982,8 @@ ${validated.errors.map((e) => `${e.path || "(root)"}: ${e.message}`).join("\n")}
35949
35982
  ...t.firstTokenMs !== void 0 ? { firstTokenMs: t.firstTokenMs } : {},
35950
35983
  ...t.inputTokens !== void 0 ? { inputTokens: t.inputTokens } : {},
35951
35984
  ...t.outputTokens !== void 0 ? { outputTokens: t.outputTokens } : {},
35985
+ ...t.reasoningTokens !== void 0 ? { reasoningTokens: t.reasoningTokens } : {},
35986
+ ...t.stopReason !== void 0 ? { stopReason: t.stopReason } : {},
35952
35987
  ...t.errorCode ? { errorCode: t.errorCode } : {},
35953
35988
  ...t.linkUrls.size > 0 ? { linksSent: t.linkUrls.size } : {},
35954
35989
  ...t.linksDropped > 0 ? { linksDropped: t.linksDropped } : {}
@@ -35988,6 +36023,23 @@ ${validated.errors.map((e) => `${e.path || "(root)"}: ${e.message}`).join("\n")}
35988
36023
  for (let round = 0; round < maxRounds; round += 1) {
35989
36024
  const done = await runRound(s, t, ctx);
35990
36025
  const calls = done.toolCalls;
36026
+ if (calls.length === 0 && done.stopReason === "max_tokens") {
36027
+ const partial2 = t.roundText.trim().length > 0;
36028
+ agentLog("warn", "llm turn truncated: LLM_OUTPUT_TRUNCATED", {
36029
+ code: "LLM_OUTPUT_TRUNCATED",
36030
+ round: round + 1,
36031
+ outputTokens: done.usage?.outputTokens,
36032
+ ...done.usage?.reasoningTokens !== void 0 ? { reasoningTokens: done.usage.reasoningTokens } : {},
36033
+ maxOutputTokens: config2.maxOutputTokens ?? D.maxOutputTokens,
36034
+ partial: partial2
36035
+ }, s.sessionId);
36036
+ if (!partial2) {
36037
+ t.errorCode = "LLM_OUTPUT_TRUNCATED";
36038
+ speakFallback(s, t);
36039
+ t.status = "failed";
36040
+ return summarize(t);
36041
+ }
36042
+ }
35991
36043
  if (calls.length === 0) {
35992
36044
  s.history.addAssistant({
35993
36045
  role: "assistant",
@@ -36128,6 +36180,8 @@ ${t.inputText}` : t.inputText, {
36128
36180
  firstTokenMs: summary.firstTokenMs,
36129
36181
  inputTokens: summary.inputTokens,
36130
36182
  outputTokens: summary.outputTokens,
36183
+ reasoningTokens: summary.reasoningTokens,
36184
+ stopReason: summary.stopReason,
36131
36185
  thinkingCharsStripped: t.thinkingCharsStripped,
36132
36186
  linksSent: t.linkUrls.size,
36133
36187
  linksDropped: t.linksDropped
@@ -59760,9 +59814,11 @@ function createOpenAiCompatibleProvider(config2) {
59760
59814
  const acc = /* @__PURE__ */ new Map();
59761
59815
  for await (const chunk of stream) {
59762
59816
  if (chunk.usage) {
59817
+ const reasoning = chunk.usage.completion_tokens_details?.reasoning_tokens;
59763
59818
  usage = {
59764
59819
  inputTokens: chunk.usage.prompt_tokens,
59765
- outputTokens: chunk.usage.completion_tokens
59820
+ outputTokens: chunk.usage.completion_tokens,
59821
+ ...typeof reasoning === "number" ? { reasoningTokens: reasoning } : {}
59766
59822
  };
59767
59823
  }
59768
59824
  const choice = chunk.choices?.[0];
@@ -59846,7 +59902,7 @@ var voicethere_llm_default = {
59846
59902
  provider: "openrouter",
59847
59903
  model: "anthropic/claude-haiku-5.5",
59848
59904
  apiKeySecret: "AGENT_OPENROUTER_API_KEY",
59849
- maxOutputTokens: 300,
59905
+ maxOutputTokens: 1024,
59850
59906
  greeting: {
59851
59907
  text: "Hi! How can I help you today?",
59852
59908
  interruptible: true
@@ -31205,6 +31205,34 @@ function isVoicethereAgentChild() {
31205
31205
  }
31206
31206
  var sessionExecutionContext = new AsyncLocalStorage();
31207
31207
  var agentLogSessionContext = new AsyncLocalStorage();
31208
+ var CURRENT_SESSION_ID_GETTER_KEY = Symbol.for("voicethere.agent.currentSessionId");
31209
+ function currentHandlerSessionId() {
31210
+ const id = sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
31211
+ return id ? id : void 0;
31212
+ }
31213
+ var previousSessionIdGetter;
31214
+ function stringOrUndefined(value) {
31215
+ return typeof value === "string" && value ? value : void 0;
31216
+ }
31217
+ function currentSessionIdGetter() {
31218
+ const own2 = currentHandlerSessionId();
31219
+ if (own2)
31220
+ return own2;
31221
+ try {
31222
+ return stringOrUndefined(previousSessionIdGetter?.());
31223
+ } catch {
31224
+ return void 0;
31225
+ }
31226
+ }
31227
+ function installCurrentSessionIdGetter() {
31228
+ const g = globalThis;
31229
+ const previous = g[CURRENT_SESSION_ID_GETTER_KEY];
31230
+ if (previous === currentSessionIdGetter)
31231
+ return;
31232
+ g[CURRENT_SESSION_ID_GETTER_KEY] = currentSessionIdGetter;
31233
+ previousSessionIdGetter = typeof previous === "function" ? previous : void 0;
31234
+ }
31235
+ installCurrentSessionIdGetter();
31208
31236
  var inboundQueueAuthority = null;
31209
31237
  var childUnhandledRejectionGuardInstalled = false;
31210
31238
  function normalizeRejectionReason(reason) {
@@ -31858,7 +31886,7 @@ function sanitizeAgentLogFields(fields) {
31858
31886
  }
31859
31887
  }
31860
31888
  function buildAgentLogPayload(level, message, fields, sessionId) {
31861
- const resolvedSessionId = sessionId ?? sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
31889
+ const resolvedSessionId = sessionId ?? currentHandlerSessionId();
31862
31890
  const sanitizedFields = fields ? sanitizeAgentLogFields(fields) : void 0;
31863
31891
  return {
31864
31892
  type: "log",
@@ -34568,7 +34596,8 @@ var LLM_AGENT_CONFIG_JSON_SCHEMA = {
34568
34596
  type: "integer",
34569
34597
  minimum: 1,
34570
34598
  maximum: 8192,
34571
- default: 512
34599
+ default: 512,
34600
+ 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."
34572
34601
  },
34573
34602
  toolChoice: {
34574
34603
  enum: ["auto", "required-first-round"],
@@ -35935,7 +35964,11 @@ ${validated.errors.map((e) => `${e.path || "(root)"}: ${e.message}`).join("\n")}
35935
35964
  if (done.usage.outputTokens !== void 0) {
35936
35965
  t.outputTokens = (t.outputTokens ?? 0) + done.usage.outputTokens;
35937
35966
  }
35967
+ if (done.usage.reasoningTokens !== void 0) {
35968
+ t.reasoningTokens = (t.reasoningTokens ?? 0) + done.usage.reasoningTokens;
35969
+ }
35938
35970
  }
35971
+ t.stopReason = done.stopReason;
35939
35972
  t.roundOpen = false;
35940
35973
  return done;
35941
35974
  }
@@ -35949,6 +35982,8 @@ ${validated.errors.map((e) => `${e.path || "(root)"}: ${e.message}`).join("\n")}
35949
35982
  ...t.firstTokenMs !== void 0 ? { firstTokenMs: t.firstTokenMs } : {},
35950
35983
  ...t.inputTokens !== void 0 ? { inputTokens: t.inputTokens } : {},
35951
35984
  ...t.outputTokens !== void 0 ? { outputTokens: t.outputTokens } : {},
35985
+ ...t.reasoningTokens !== void 0 ? { reasoningTokens: t.reasoningTokens } : {},
35986
+ ...t.stopReason !== void 0 ? { stopReason: t.stopReason } : {},
35952
35987
  ...t.errorCode ? { errorCode: t.errorCode } : {},
35953
35988
  ...t.linkUrls.size > 0 ? { linksSent: t.linkUrls.size } : {},
35954
35989
  ...t.linksDropped > 0 ? { linksDropped: t.linksDropped } : {}
@@ -35988,6 +36023,23 @@ ${validated.errors.map((e) => `${e.path || "(root)"}: ${e.message}`).join("\n")}
35988
36023
  for (let round = 0; round < maxRounds; round += 1) {
35989
36024
  const done = await runRound(s, t, ctx);
35990
36025
  const calls = done.toolCalls;
36026
+ if (calls.length === 0 && done.stopReason === "max_tokens") {
36027
+ const partial2 = t.roundText.trim().length > 0;
36028
+ agentLog("warn", "llm turn truncated: LLM_OUTPUT_TRUNCATED", {
36029
+ code: "LLM_OUTPUT_TRUNCATED",
36030
+ round: round + 1,
36031
+ outputTokens: done.usage?.outputTokens,
36032
+ ...done.usage?.reasoningTokens !== void 0 ? { reasoningTokens: done.usage.reasoningTokens } : {},
36033
+ maxOutputTokens: config2.maxOutputTokens ?? D.maxOutputTokens,
36034
+ partial: partial2
36035
+ }, s.sessionId);
36036
+ if (!partial2) {
36037
+ t.errorCode = "LLM_OUTPUT_TRUNCATED";
36038
+ speakFallback(s, t);
36039
+ t.status = "failed";
36040
+ return summarize(t);
36041
+ }
36042
+ }
35991
36043
  if (calls.length === 0) {
35992
36044
  s.history.addAssistant({
35993
36045
  role: "assistant",
@@ -36128,6 +36180,8 @@ ${t.inputText}` : t.inputText, {
36128
36180
  firstTokenMs: summary.firstTokenMs,
36129
36181
  inputTokens: summary.inputTokens,
36130
36182
  outputTokens: summary.outputTokens,
36183
+ reasoningTokens: summary.reasoningTokens,
36184
+ stopReason: summary.stopReason,
36131
36185
  thinkingCharsStripped: t.thinkingCharsStripped,
36132
36186
  linksSent: t.linkUrls.size,
36133
36187
  linksDropped: t.linksDropped
@@ -59760,9 +59814,11 @@ function createOpenAiCompatibleProvider(config2) {
59760
59814
  const acc = /* @__PURE__ */ new Map();
59761
59815
  for await (const chunk of stream) {
59762
59816
  if (chunk.usage) {
59817
+ const reasoning = chunk.usage.completion_tokens_details?.reasoning_tokens;
59763
59818
  usage = {
59764
59819
  inputTokens: chunk.usage.prompt_tokens,
59765
- outputTokens: chunk.usage.completion_tokens
59820
+ outputTokens: chunk.usage.completion_tokens,
59821
+ ...typeof reasoning === "number" ? { reasoningTokens: reasoning } : {}
59766
59822
  };
59767
59823
  }
59768
59824
  const choice = chunk.choices?.[0];
@@ -59846,7 +59902,7 @@ var voicethere_llm_default = {
59846
59902
  provider: "openrouter",
59847
59903
  model: "anthropic/claude-haiku-5.5",
59848
59904
  apiKeySecret: "AGENT_OPENROUTER_API_KEY",
59849
- maxOutputTokens: 300,
59905
+ maxOutputTokens: 1024,
59850
59906
  greeting: {
59851
59907
  text: "Hi! Ask me anything about our documentation.",
59852
59908
  interruptible: true
@@ -31205,6 +31205,34 @@ function isVoicethereAgentChild() {
31205
31205
  }
31206
31206
  var sessionExecutionContext = new AsyncLocalStorage();
31207
31207
  var agentLogSessionContext = new AsyncLocalStorage();
31208
+ var CURRENT_SESSION_ID_GETTER_KEY = Symbol.for("voicethere.agent.currentSessionId");
31209
+ function currentHandlerSessionId() {
31210
+ const id = sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
31211
+ return id ? id : void 0;
31212
+ }
31213
+ var previousSessionIdGetter;
31214
+ function stringOrUndefined(value) {
31215
+ return typeof value === "string" && value ? value : void 0;
31216
+ }
31217
+ function currentSessionIdGetter() {
31218
+ const own2 = currentHandlerSessionId();
31219
+ if (own2)
31220
+ return own2;
31221
+ try {
31222
+ return stringOrUndefined(previousSessionIdGetter?.());
31223
+ } catch {
31224
+ return void 0;
31225
+ }
31226
+ }
31227
+ function installCurrentSessionIdGetter() {
31228
+ const g = globalThis;
31229
+ const previous = g[CURRENT_SESSION_ID_GETTER_KEY];
31230
+ if (previous === currentSessionIdGetter)
31231
+ return;
31232
+ g[CURRENT_SESSION_ID_GETTER_KEY] = currentSessionIdGetter;
31233
+ previousSessionIdGetter = typeof previous === "function" ? previous : void 0;
31234
+ }
31235
+ installCurrentSessionIdGetter();
31208
31236
  var inboundQueueAuthority = null;
31209
31237
  var childUnhandledRejectionGuardInstalled = false;
31210
31238
  function normalizeRejectionReason(reason) {
@@ -31858,7 +31886,7 @@ function sanitizeAgentLogFields(fields) {
31858
31886
  }
31859
31887
  }
31860
31888
  function buildAgentLogPayload(level, message, fields, sessionId) {
31861
- const resolvedSessionId = sessionId ?? sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
31889
+ const resolvedSessionId = sessionId ?? currentHandlerSessionId();
31862
31890
  const sanitizedFields = fields ? sanitizeAgentLogFields(fields) : void 0;
31863
31891
  return {
31864
31892
  type: "log",
@@ -34568,7 +34596,8 @@ var LLM_AGENT_CONFIG_JSON_SCHEMA = {
34568
34596
  type: "integer",
34569
34597
  minimum: 1,
34570
34598
  maximum: 8192,
34571
- default: 512
34599
+ default: 512,
34600
+ 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."
34572
34601
  },
34573
34602
  toolChoice: {
34574
34603
  enum: ["auto", "required-first-round"],
@@ -35935,7 +35964,11 @@ ${validated.errors.map((e) => `${e.path || "(root)"}: ${e.message}`).join("\n")}
35935
35964
  if (done.usage.outputTokens !== void 0) {
35936
35965
  t.outputTokens = (t.outputTokens ?? 0) + done.usage.outputTokens;
35937
35966
  }
35967
+ if (done.usage.reasoningTokens !== void 0) {
35968
+ t.reasoningTokens = (t.reasoningTokens ?? 0) + done.usage.reasoningTokens;
35969
+ }
35938
35970
  }
35971
+ t.stopReason = done.stopReason;
35939
35972
  t.roundOpen = false;
35940
35973
  return done;
35941
35974
  }
@@ -35949,6 +35982,8 @@ ${validated.errors.map((e) => `${e.path || "(root)"}: ${e.message}`).join("\n")}
35949
35982
  ...t.firstTokenMs !== void 0 ? { firstTokenMs: t.firstTokenMs } : {},
35950
35983
  ...t.inputTokens !== void 0 ? { inputTokens: t.inputTokens } : {},
35951
35984
  ...t.outputTokens !== void 0 ? { outputTokens: t.outputTokens } : {},
35985
+ ...t.reasoningTokens !== void 0 ? { reasoningTokens: t.reasoningTokens } : {},
35986
+ ...t.stopReason !== void 0 ? { stopReason: t.stopReason } : {},
35952
35987
  ...t.errorCode ? { errorCode: t.errorCode } : {},
35953
35988
  ...t.linkUrls.size > 0 ? { linksSent: t.linkUrls.size } : {},
35954
35989
  ...t.linksDropped > 0 ? { linksDropped: t.linksDropped } : {}
@@ -35988,6 +36023,23 @@ ${validated.errors.map((e) => `${e.path || "(root)"}: ${e.message}`).join("\n")}
35988
36023
  for (let round = 0; round < maxRounds; round += 1) {
35989
36024
  const done = await runRound(s, t, ctx);
35990
36025
  const calls = done.toolCalls;
36026
+ if (calls.length === 0 && done.stopReason === "max_tokens") {
36027
+ const partial2 = t.roundText.trim().length > 0;
36028
+ agentLog("warn", "llm turn truncated: LLM_OUTPUT_TRUNCATED", {
36029
+ code: "LLM_OUTPUT_TRUNCATED",
36030
+ round: round + 1,
36031
+ outputTokens: done.usage?.outputTokens,
36032
+ ...done.usage?.reasoningTokens !== void 0 ? { reasoningTokens: done.usage.reasoningTokens } : {},
36033
+ maxOutputTokens: config2.maxOutputTokens ?? D.maxOutputTokens,
36034
+ partial: partial2
36035
+ }, s.sessionId);
36036
+ if (!partial2) {
36037
+ t.errorCode = "LLM_OUTPUT_TRUNCATED";
36038
+ speakFallback(s, t);
36039
+ t.status = "failed";
36040
+ return summarize(t);
36041
+ }
36042
+ }
35991
36043
  if (calls.length === 0) {
35992
36044
  s.history.addAssistant({
35993
36045
  role: "assistant",
@@ -36128,6 +36180,8 @@ ${t.inputText}` : t.inputText, {
36128
36180
  firstTokenMs: summary.firstTokenMs,
36129
36181
  inputTokens: summary.inputTokens,
36130
36182
  outputTokens: summary.outputTokens,
36183
+ reasoningTokens: summary.reasoningTokens,
36184
+ stopReason: summary.stopReason,
36131
36185
  thinkingCharsStripped: t.thinkingCharsStripped,
36132
36186
  linksSent: t.linkUrls.size,
36133
36187
  linksDropped: t.linksDropped
@@ -59760,9 +59814,11 @@ function createOpenAiCompatibleProvider(config2) {
59760
59814
  const acc = /* @__PURE__ */ new Map();
59761
59815
  for await (const chunk of stream) {
59762
59816
  if (chunk.usage) {
59817
+ const reasoning = chunk.usage.completion_tokens_details?.reasoning_tokens;
59763
59818
  usage = {
59764
59819
  inputTokens: chunk.usage.prompt_tokens,
59765
- outputTokens: chunk.usage.completion_tokens
59820
+ outputTokens: chunk.usage.completion_tokens,
59821
+ ...typeof reasoning === "number" ? { reasoningTokens: reasoning } : {}
59766
59822
  };
59767
59823
  }
59768
59824
  const choice = chunk.choices?.[0];
@@ -59846,7 +59902,7 @@ var voicethere_llm_default = {
59846
59902
  provider: "openrouter",
59847
59903
  model: "anthropic/claude-haiku-5.5",
59848
59904
  apiKeySecret: "AGENT_OPENROUTER_API_KEY",
59849
- maxOutputTokens: 300,
59905
+ maxOutputTokens: 1024,
59850
59906
  greeting: {
59851
59907
  text: "Hi! How can I help you today?",
59852
59908
  interruptible: true
@@ -577,6 +577,34 @@ function isVoicethereAgentChild() {
577
577
  }
578
578
  var sessionExecutionContext = new AsyncLocalStorage();
579
579
  var agentLogSessionContext = new AsyncLocalStorage();
580
+ var CURRENT_SESSION_ID_GETTER_KEY = Symbol.for("voicethere.agent.currentSessionId");
581
+ function currentHandlerSessionId() {
582
+ const id = sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
583
+ return id ? id : void 0;
584
+ }
585
+ var previousSessionIdGetter;
586
+ function stringOrUndefined(value) {
587
+ return typeof value === "string" && value ? value : void 0;
588
+ }
589
+ function currentSessionIdGetter() {
590
+ const own = currentHandlerSessionId();
591
+ if (own)
592
+ return own;
593
+ try {
594
+ return stringOrUndefined(previousSessionIdGetter?.());
595
+ } catch {
596
+ return void 0;
597
+ }
598
+ }
599
+ function installCurrentSessionIdGetter() {
600
+ const g = globalThis;
601
+ const previous = g[CURRENT_SESSION_ID_GETTER_KEY];
602
+ if (previous === currentSessionIdGetter)
603
+ return;
604
+ g[CURRENT_SESSION_ID_GETTER_KEY] = currentSessionIdGetter;
605
+ previousSessionIdGetter = typeof previous === "function" ? previous : void 0;
606
+ }
607
+ installCurrentSessionIdGetter();
580
608
  var inboundQueueAuthority = null;
581
609
  var childUnhandledRejectionGuardInstalled = false;
582
610
  function normalizeRejectionReason(reason) {
@@ -1222,7 +1250,7 @@ function sanitizeAgentLogFields(fields) {
1222
1250
  }
1223
1251
  }
1224
1252
  function buildAgentLogPayload(level, message, fields, sessionId) {
1225
- const resolvedSessionId = sessionId ?? sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
1253
+ const resolvedSessionId = sessionId ?? currentHandlerSessionId();
1226
1254
  const sanitizedFields = fields ? sanitizeAgentLogFields(fields) : void 0;
1227
1255
  return {
1228
1256
  type: "log",
@@ -562,6 +562,34 @@ function isVoicethereAgentChild() {
562
562
  }
563
563
  var sessionExecutionContext = new AsyncLocalStorage();
564
564
  var agentLogSessionContext = new AsyncLocalStorage();
565
+ var CURRENT_SESSION_ID_GETTER_KEY = Symbol.for("voicethere.agent.currentSessionId");
566
+ function currentHandlerSessionId() {
567
+ const id = sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
568
+ return id ? id : void 0;
569
+ }
570
+ var previousSessionIdGetter;
571
+ function stringOrUndefined(value) {
572
+ return typeof value === "string" && value ? value : void 0;
573
+ }
574
+ function currentSessionIdGetter() {
575
+ const own = currentHandlerSessionId();
576
+ if (own)
577
+ return own;
578
+ try {
579
+ return stringOrUndefined(previousSessionIdGetter?.());
580
+ } catch {
581
+ return void 0;
582
+ }
583
+ }
584
+ function installCurrentSessionIdGetter() {
585
+ const g = globalThis;
586
+ const previous = g[CURRENT_SESSION_ID_GETTER_KEY];
587
+ if (previous === currentSessionIdGetter)
588
+ return;
589
+ g[CURRENT_SESSION_ID_GETTER_KEY] = currentSessionIdGetter;
590
+ previousSessionIdGetter = typeof previous === "function" ? previous : void 0;
591
+ }
592
+ installCurrentSessionIdGetter();
565
593
  var inboundQueueAuthority = null;
566
594
  var childUnhandledRejectionGuardInstalled = false;
567
595
  function normalizeRejectionReason(reason) {
@@ -1213,7 +1241,7 @@ function sanitizeAgentLogFields(fields) {
1213
1241
  }
1214
1242
  }
1215
1243
  function buildAgentLogPayload(level, message, fields, sessionId) {
1216
- const resolvedSessionId = sessionId ?? sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
1244
+ const resolvedSessionId = sessionId ?? currentHandlerSessionId();
1217
1245
  const sanitizedFields = fields ? sanitizeAgentLogFields(fields) : void 0;
1218
1246
  return {
1219
1247
  type: "log",
@@ -592,6 +592,34 @@ function isVoicethereAgentChild() {
592
592
  }
593
593
  var sessionExecutionContext = new AsyncLocalStorage();
594
594
  var agentLogSessionContext = new AsyncLocalStorage();
595
+ var CURRENT_SESSION_ID_GETTER_KEY = Symbol.for("voicethere.agent.currentSessionId");
596
+ function currentHandlerSessionId() {
597
+ const id = sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
598
+ return id ? id : void 0;
599
+ }
600
+ var previousSessionIdGetter;
601
+ function stringOrUndefined(value) {
602
+ return typeof value === "string" && value ? value : void 0;
603
+ }
604
+ function currentSessionIdGetter() {
605
+ const own = currentHandlerSessionId();
606
+ if (own)
607
+ return own;
608
+ try {
609
+ return stringOrUndefined(previousSessionIdGetter?.());
610
+ } catch {
611
+ return void 0;
612
+ }
613
+ }
614
+ function installCurrentSessionIdGetter() {
615
+ const g = globalThis;
616
+ const previous = g[CURRENT_SESSION_ID_GETTER_KEY];
617
+ if (previous === currentSessionIdGetter)
618
+ return;
619
+ g[CURRENT_SESSION_ID_GETTER_KEY] = currentSessionIdGetter;
620
+ previousSessionIdGetter = typeof previous === "function" ? previous : void 0;
621
+ }
622
+ installCurrentSessionIdGetter();
595
623
  var inboundQueueAuthority = null;
596
624
  var childUnhandledRejectionGuardInstalled = false;
597
625
  function normalizeRejectionReason(reason) {
@@ -1457,7 +1485,7 @@ function sanitizeAgentLogFields(fields) {
1457
1485
  }
1458
1486
  }
1459
1487
  function buildAgentLogPayload(level, message, fields, sessionId) {
1460
- const resolvedSessionId = sessionId ?? sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
1488
+ const resolvedSessionId = sessionId ?? currentHandlerSessionId();
1461
1489
  const sanitizedFields = fields ? sanitizeAgentLogFields(fields) : void 0;
1462
1490
  return {
1463
1491
  type: "log",
@@ -561,6 +561,34 @@ function isVoicethereAgentChild() {
561
561
  }
562
562
  var sessionExecutionContext = new AsyncLocalStorage();
563
563
  var agentLogSessionContext = new AsyncLocalStorage();
564
+ var CURRENT_SESSION_ID_GETTER_KEY = Symbol.for("voicethere.agent.currentSessionId");
565
+ function currentHandlerSessionId() {
566
+ const id = sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
567
+ return id ? id : void 0;
568
+ }
569
+ var previousSessionIdGetter;
570
+ function stringOrUndefined(value) {
571
+ return typeof value === "string" && value ? value : void 0;
572
+ }
573
+ function currentSessionIdGetter() {
574
+ const own = currentHandlerSessionId();
575
+ if (own)
576
+ return own;
577
+ try {
578
+ return stringOrUndefined(previousSessionIdGetter?.());
579
+ } catch {
580
+ return void 0;
581
+ }
582
+ }
583
+ function installCurrentSessionIdGetter() {
584
+ const g = globalThis;
585
+ const previous = g[CURRENT_SESSION_ID_GETTER_KEY];
586
+ if (previous === currentSessionIdGetter)
587
+ return;
588
+ g[CURRENT_SESSION_ID_GETTER_KEY] = currentSessionIdGetter;
589
+ previousSessionIdGetter = typeof previous === "function" ? previous : void 0;
590
+ }
591
+ installCurrentSessionIdGetter();
564
592
  var inboundQueueAuthority = null;
565
593
  var childUnhandledRejectionGuardInstalled = false;
566
594
  function normalizeRejectionReason(reason) {
@@ -1190,7 +1218,7 @@ function sanitizeAgentLogFields(fields) {
1190
1218
  }
1191
1219
  }
1192
1220
  function buildAgentLogPayload(level, message, fields, sessionId) {
1193
- const resolvedSessionId = sessionId ?? sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
1221
+ const resolvedSessionId = sessionId ?? currentHandlerSessionId();
1194
1222
  const sanitizedFields = fields ? sanitizeAgentLogFields(fields) : void 0;
1195
1223
  return {
1196
1224
  type: "log",
@@ -561,6 +561,34 @@ function isVoicethereAgentChild() {
561
561
  }
562
562
  var sessionExecutionContext = new AsyncLocalStorage();
563
563
  var agentLogSessionContext = new AsyncLocalStorage();
564
+ var CURRENT_SESSION_ID_GETTER_KEY = Symbol.for("voicethere.agent.currentSessionId");
565
+ function currentHandlerSessionId() {
566
+ const id = sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
567
+ return id ? id : void 0;
568
+ }
569
+ var previousSessionIdGetter;
570
+ function stringOrUndefined(value) {
571
+ return typeof value === "string" && value ? value : void 0;
572
+ }
573
+ function currentSessionIdGetter() {
574
+ const own = currentHandlerSessionId();
575
+ if (own)
576
+ return own;
577
+ try {
578
+ return stringOrUndefined(previousSessionIdGetter?.());
579
+ } catch {
580
+ return void 0;
581
+ }
582
+ }
583
+ function installCurrentSessionIdGetter() {
584
+ const g = globalThis;
585
+ const previous = g[CURRENT_SESSION_ID_GETTER_KEY];
586
+ if (previous === currentSessionIdGetter)
587
+ return;
588
+ g[CURRENT_SESSION_ID_GETTER_KEY] = currentSessionIdGetter;
589
+ previousSessionIdGetter = typeof previous === "function" ? previous : void 0;
590
+ }
591
+ installCurrentSessionIdGetter();
564
592
  var inboundQueueAuthority = null;
565
593
  var childUnhandledRejectionGuardInstalled = false;
566
594
  function normalizeRejectionReason(reason) {
@@ -1174,7 +1202,7 @@ function sanitizeAgentLogFields(fields) {
1174
1202
  }
1175
1203
  }
1176
1204
  function buildAgentLogPayload(level, message, fields, sessionId) {
1177
- const resolvedSessionId = sessionId ?? sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
1205
+ const resolvedSessionId = sessionId ?? currentHandlerSessionId();
1178
1206
  const sanitizedFields = fields ? sanitizeAgentLogFields(fields) : void 0;
1179
1207
  return {
1180
1208
  type: "log",
@@ -564,6 +564,34 @@ function isVoicethereAgentChild() {
564
564
  }
565
565
  var sessionExecutionContext = new AsyncLocalStorage();
566
566
  var agentLogSessionContext = new AsyncLocalStorage();
567
+ var CURRENT_SESSION_ID_GETTER_KEY = Symbol.for("voicethere.agent.currentSessionId");
568
+ function currentHandlerSessionId() {
569
+ const id = sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
570
+ return id ? id : void 0;
571
+ }
572
+ var previousSessionIdGetter;
573
+ function stringOrUndefined(value) {
574
+ return typeof value === "string" && value ? value : void 0;
575
+ }
576
+ function currentSessionIdGetter() {
577
+ const own = currentHandlerSessionId();
578
+ if (own)
579
+ return own;
580
+ try {
581
+ return stringOrUndefined(previousSessionIdGetter?.());
582
+ } catch {
583
+ return void 0;
584
+ }
585
+ }
586
+ function installCurrentSessionIdGetter() {
587
+ const g = globalThis;
588
+ const previous = g[CURRENT_SESSION_ID_GETTER_KEY];
589
+ if (previous === currentSessionIdGetter)
590
+ return;
591
+ g[CURRENT_SESSION_ID_GETTER_KEY] = currentSessionIdGetter;
592
+ previousSessionIdGetter = typeof previous === "function" ? previous : void 0;
593
+ }
594
+ installCurrentSessionIdGetter();
567
595
  var inboundQueueAuthority = null;
568
596
  var childUnhandledRejectionGuardInstalled = false;
569
597
  function normalizeRejectionReason(reason) {
@@ -1185,7 +1213,7 @@ function sanitizeAgentLogFields(fields) {
1185
1213
  }
1186
1214
  }
1187
1215
  function buildAgentLogPayload(level, message, fields, sessionId) {
1188
- const resolvedSessionId = sessionId ?? sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
1216
+ const resolvedSessionId = sessionId ?? currentHandlerSessionId();
1189
1217
  const sanitizedFields = fields ? sanitizeAgentLogFields(fields) : void 0;
1190
1218
  return {
1191
1219
  type: "log",