@voicethere/agent 0.35.2 → 0.35.4

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.
@@ -60592,6 +60592,34 @@ function parseArgs(raw) {
60592
60592
  return { _raw: raw };
60593
60593
  }
60594
60594
  }
60595
+ function buildChatCompletionParams(req, providerId) {
60596
+ const tools2 = req.tools.map((t) => ({
60597
+ type: "function",
60598
+ function: {
60599
+ name: t.name,
60600
+ description: t.description,
60601
+ parameters: t.inputSchema
60602
+ }
60603
+ }));
60604
+ const params = {
60605
+ ...req.vendorConfig ?? {},
60606
+ model: req.model,
60607
+ messages: toMessages(req.system, req.messages),
60608
+ stream: true,
60609
+ stream_options: { include_usage: true },
60610
+ ...tools2.length > 0 ? { tools: tools2 } : {},
60611
+ ...tools2.length > 0 && req.toolChoice === "required" ? { tool_choice: "required" } : {},
60612
+ ...tools2.length > 0 && typeof req.toolChoice === "object" && req.toolChoice !== null ? {
60613
+ tool_choice: {
60614
+ type: "function",
60615
+ function: { name: req.toolChoice.name }
60616
+ }
60617
+ } : {},
60618
+ ...req.temperature !== void 0 ? { temperature: req.temperature } : {},
60619
+ ...req.maxOutputTokens !== void 0 ? providerId === "openai" ? { max_completion_tokens: req.maxOutputTokens } : { max_tokens: req.maxOutputTokens } : {}
60620
+ };
60621
+ return params;
60622
+ }
60595
60623
  function createOpenAiCompatibleProvider(config2) {
60596
60624
  const client = new OpenAI({
60597
60625
  apiKey: config2.apiKey,
@@ -60601,31 +60629,7 @@ function createOpenAiCompatibleProvider(config2) {
60601
60629
  return {
60602
60630
  id: config2.id,
60603
60631
  async *stream(req) {
60604
- const tools2 = req.tools.map((t) => ({
60605
- type: "function",
60606
- function: {
60607
- name: t.name,
60608
- description: t.description,
60609
- parameters: t.inputSchema
60610
- }
60611
- }));
60612
- const params = {
60613
- ...req.vendorConfig ?? {},
60614
- model: req.model,
60615
- messages: toMessages(req.system, req.messages),
60616
- stream: true,
60617
- stream_options: { include_usage: true },
60618
- ...tools2.length > 0 ? { tools: tools2 } : {},
60619
- ...tools2.length > 0 && req.toolChoice === "required" ? { tool_choice: "required" } : {},
60620
- ...tools2.length > 0 && typeof req.toolChoice === "object" && req.toolChoice !== null ? {
60621
- tool_choice: {
60622
- type: "function",
60623
- function: { name: req.toolChoice.name }
60624
- }
60625
- } : {},
60626
- ...req.temperature !== void 0 ? { temperature: req.temperature } : {},
60627
- ...req.maxOutputTokens !== void 0 ? config2.id === "openai" ? { max_completion_tokens: req.maxOutputTokens } : { max_tokens: req.maxOutputTokens } : {}
60628
- };
60632
+ const params = buildChatCompletionParams(req, config2.id);
60629
60633
  const stream = await client.chat.completions.create(params, {
60630
60634
  signal: req.signal
60631
60635
  });
@@ -60596,6 +60596,34 @@ function parseArgs(raw) {
60596
60596
  return { _raw: raw };
60597
60597
  }
60598
60598
  }
60599
+ function buildChatCompletionParams(req, providerId) {
60600
+ const tools = req.tools.map((t) => ({
60601
+ type: "function",
60602
+ function: {
60603
+ name: t.name,
60604
+ description: t.description,
60605
+ parameters: t.inputSchema
60606
+ }
60607
+ }));
60608
+ const params = {
60609
+ ...req.vendorConfig ?? {},
60610
+ model: req.model,
60611
+ messages: toMessages(req.system, req.messages),
60612
+ stream: true,
60613
+ stream_options: { include_usage: true },
60614
+ ...tools.length > 0 ? { tools } : {},
60615
+ ...tools.length > 0 && req.toolChoice === "required" ? { tool_choice: "required" } : {},
60616
+ ...tools.length > 0 && typeof req.toolChoice === "object" && req.toolChoice !== null ? {
60617
+ tool_choice: {
60618
+ type: "function",
60619
+ function: { name: req.toolChoice.name }
60620
+ }
60621
+ } : {},
60622
+ ...req.temperature !== void 0 ? { temperature: req.temperature } : {},
60623
+ ...req.maxOutputTokens !== void 0 ? providerId === "openai" ? { max_completion_tokens: req.maxOutputTokens } : { max_tokens: req.maxOutputTokens } : {}
60624
+ };
60625
+ return params;
60626
+ }
60599
60627
  function createOpenAiCompatibleProvider(config2) {
60600
60628
  const client = new OpenAI({
60601
60629
  apiKey: config2.apiKey,
@@ -60605,31 +60633,7 @@ function createOpenAiCompatibleProvider(config2) {
60605
60633
  return {
60606
60634
  id: config2.id,
60607
60635
  async *stream(req) {
60608
- const tools = req.tools.map((t) => ({
60609
- type: "function",
60610
- function: {
60611
- name: t.name,
60612
- description: t.description,
60613
- parameters: t.inputSchema
60614
- }
60615
- }));
60616
- const params = {
60617
- ...req.vendorConfig ?? {},
60618
- model: req.model,
60619
- messages: toMessages(req.system, req.messages),
60620
- stream: true,
60621
- stream_options: { include_usage: true },
60622
- ...tools.length > 0 ? { tools } : {},
60623
- ...tools.length > 0 && req.toolChoice === "required" ? { tool_choice: "required" } : {},
60624
- ...tools.length > 0 && typeof req.toolChoice === "object" && req.toolChoice !== null ? {
60625
- tool_choice: {
60626
- type: "function",
60627
- function: { name: req.toolChoice.name }
60628
- }
60629
- } : {},
60630
- ...req.temperature !== void 0 ? { temperature: req.temperature } : {},
60631
- ...req.maxOutputTokens !== void 0 ? config2.id === "openai" ? { max_completion_tokens: req.maxOutputTokens } : { max_tokens: req.maxOutputTokens } : {}
60632
- };
60636
+ const params = buildChatCompletionParams(req, config2.id);
60633
60637
  const stream = await client.chat.completions.create(params, {
60634
60638
  signal: req.signal
60635
60639
  });
@@ -60725,7 +60729,7 @@ var voicethere_llm_default = {
60725
60729
  $schema: "./node_modules/@voicethere/agent/schema/voicethere.llm.schema.json",
60726
60730
  version: 1,
60727
60731
  provider: "openrouter",
60728
- model: "amazon/nova-micro-v1",
60732
+ model: "anthropic/claude-haiku-5.5",
60729
60733
  apiKeySecret: "AGENT_OPENROUTER_API_KEY",
60730
60734
  maxOutputTokens: 256,
60731
60735
  greeting: {
@@ -60802,8 +60806,52 @@ function withLanguageNote(messages, code) {
60802
60806
  return withNote(messages, languageNote(code));
60803
60807
  }
60804
60808
  var CHAT_NOTE = "Reply in the language this message is written in, even if the earlier conversation used another language.";
60809
+ var STOPWORDS = {
60810
+ en: "the is are what where how can you your i my to of and for with from this that it do does please".split(
60811
+ " "
60812
+ ),
60813
+ de: "der die das ist sind wo wie kann ich du sie ein eine und nicht mit von zu bitte wann welche auf nach".split(
60814
+ " "
60815
+ ),
60816
+ es: "el los las es son d\xF3nde donde c\xF3mo como puedo puede yo t\xFA un una y no con por para hola desde al qu\xE9 que cu\xE1l".split(
60817
+ " "
60818
+ ),
60819
+ fr: "le les est sont o\xF9 ou comment puis je tu vous un une et pas avec pour bonjour depuis au quel quelle que qu'est-ce".split(
60820
+ " "
60821
+ )
60822
+ };
60823
+ var MARKS = {
60824
+ es: "\xBF\xA1\xF1",
60825
+ de: "\xDF\xE4\xF6\xFC",
60826
+ fr: "\xE7\xE0\xE8\xF9\xEA\xEE\xF4\xFB"
60827
+ };
60828
+ function guessChatLanguage(text) {
60829
+ const words = text.toLowerCase().match(/[\p{L}'-]+/gu) ?? [];
60830
+ const scores = SUPPORTED_LANGUAGES.map((code) => {
60831
+ const stop = new Set(STOPWORDS[code] ?? []);
60832
+ let hits = words.filter((w) => stop.has(w)).length;
60833
+ for (const mark of MARKS[code] ?? "") {
60834
+ if (text.toLowerCase().includes(mark)) hits += 1;
60835
+ }
60836
+ return { code, hits };
60837
+ }).sort((a, b) => b.hits - a.hits);
60838
+ const best = scores[0];
60839
+ const next = scores[1];
60840
+ if (!best || best.hits < 2 || best.hits - (next?.hits ?? 0) < 2) {
60841
+ return void 0;
60842
+ }
60843
+ return best.code;
60844
+ }
60845
+ function chatLanguageNote(code) {
60846
+ const name = languageName(code, "en");
60847
+ return `The caller typed this message in ${name} (${code}). Reply only in ${name}.`;
60848
+ }
60849
+ var INTERRUPTION_NOTE = /^\(The caller interrupted your previous reply after: [\s\S]*?\.\)\n/;
60805
60850
  function withChatNote(messages) {
60806
- return withNote(messages, CHAT_NOTE);
60851
+ const last = [...messages].reverse().find((m) => m.role === "user");
60852
+ const typed = last?.text.replace(INTERRUPTION_NOTE, "");
60853
+ const code = typed ? guessChatLanguage(typed) : void 0;
60854
+ return withNote(messages, code ? chatLanguageNote(code) : CHAT_NOTE);
60807
60855
  }
60808
60856
  function withNote(messages, note) {
60809
60857
  for (let i = messages.length - 1; i >= 0; i -= 1) {
@@ -60592,6 +60592,34 @@ function parseArgs(raw) {
60592
60592
  return { _raw: raw };
60593
60593
  }
60594
60594
  }
60595
+ function buildChatCompletionParams(req, providerId) {
60596
+ const tools = req.tools.map((t) => ({
60597
+ type: "function",
60598
+ function: {
60599
+ name: t.name,
60600
+ description: t.description,
60601
+ parameters: t.inputSchema
60602
+ }
60603
+ }));
60604
+ const params = {
60605
+ ...req.vendorConfig ?? {},
60606
+ model: req.model,
60607
+ messages: toMessages(req.system, req.messages),
60608
+ stream: true,
60609
+ stream_options: { include_usage: true },
60610
+ ...tools.length > 0 ? { tools } : {},
60611
+ ...tools.length > 0 && req.toolChoice === "required" ? { tool_choice: "required" } : {},
60612
+ ...tools.length > 0 && typeof req.toolChoice === "object" && req.toolChoice !== null ? {
60613
+ tool_choice: {
60614
+ type: "function",
60615
+ function: { name: req.toolChoice.name }
60616
+ }
60617
+ } : {},
60618
+ ...req.temperature !== void 0 ? { temperature: req.temperature } : {},
60619
+ ...req.maxOutputTokens !== void 0 ? providerId === "openai" ? { max_completion_tokens: req.maxOutputTokens } : { max_tokens: req.maxOutputTokens } : {}
60620
+ };
60621
+ return params;
60622
+ }
60595
60623
  function createOpenAiCompatibleProvider(config2) {
60596
60624
  const client = new OpenAI({
60597
60625
  apiKey: config2.apiKey,
@@ -60601,31 +60629,7 @@ function createOpenAiCompatibleProvider(config2) {
60601
60629
  return {
60602
60630
  id: config2.id,
60603
60631
  async *stream(req) {
60604
- const tools = req.tools.map((t) => ({
60605
- type: "function",
60606
- function: {
60607
- name: t.name,
60608
- description: t.description,
60609
- parameters: t.inputSchema
60610
- }
60611
- }));
60612
- const params = {
60613
- ...req.vendorConfig ?? {},
60614
- model: req.model,
60615
- messages: toMessages(req.system, req.messages),
60616
- stream: true,
60617
- stream_options: { include_usage: true },
60618
- ...tools.length > 0 ? { tools } : {},
60619
- ...tools.length > 0 && req.toolChoice === "required" ? { tool_choice: "required" } : {},
60620
- ...tools.length > 0 && typeof req.toolChoice === "object" && req.toolChoice !== null ? {
60621
- tool_choice: {
60622
- type: "function",
60623
- function: { name: req.toolChoice.name }
60624
- }
60625
- } : {},
60626
- ...req.temperature !== void 0 ? { temperature: req.temperature } : {},
60627
- ...req.maxOutputTokens !== void 0 ? config2.id === "openai" ? { max_completion_tokens: req.maxOutputTokens } : { max_tokens: req.maxOutputTokens } : {}
60628
- };
60632
+ const params = buildChatCompletionParams(req, config2.id);
60629
60633
  const stream = await client.chat.completions.create(params, {
60630
60634
  signal: req.signal
60631
60635
  });
@@ -60758,7 +60762,7 @@ var voicethere_llm_default = {
60758
60762
  };
60759
60763
 
60760
60764
  // templates/llm-language-tutor/prompt.md
60761
- var prompt_default = "You are an English conversation tutor for learners at levels A2 to B2. People talk to you by voice, so everything you say is read aloud.\n\nSpeak English only, even if the learner switches to another language. Keep replies to one to three short sentences, in plain words. Do not use markdown, lists, emoji or special characters.\n\nCorrect at most one mistake per turn. Say the learner's sentence again the correct way, then give the reason in a few words. If there is no mistake, say something encouraging in a few words instead. Then ask one follow-up question that keeps the conversation going.\n\nWhen the learner asks about a phrase, an idiom or a lesson topic, call search_knowledge first and answer from what it returns. Call it before you say anything on such a question: do not give a meaning, a guess or a filler sentence first. Never make up the meaning of an idiom that the search did not return. If the search has nothing, say you are not sure and offer a different phrase to practice.\n\nBe patient and friendly. Let the learner finish their thought before you correct anything.\n";
60765
+ var prompt_default = "You are an English conversation tutor for learners at levels A2 to B2. People talk to you by voice, so everything you say is read aloud.\n\nSpeak English only, even if the learner switches to another language. Keep replies to one to three short sentences, in plain words. Do not use markdown, lists, emoji or special characters.\n\nCorrect at most one mistake per turn. Say the learner's sentence again the correct way, then give the reason in a few words. If there is no mistake, say something encouraging in a few words instead. Then ask one follow-up question that keeps the conversation going.\n\nWhen the learner asks about a phrase, an idiom or a lesson topic, call search_knowledge first and answer from what it returns. Call it before you say anything on such a question: do not give a meaning, a guess or a filler sentence first. Never make up the meaning of an idiom that the search did not return. If the search has nothing, say you are not sure and suggest one lesson topic to practice instead. Do not explain any phrase or idiom that the search did not return.\n\nBe patient and friendly. Let the learner finish their thought before you correct anything.\n";
60762
60766
 
60763
60767
  // templates/llm-language-tutor/knowledge/lessons.md
60764
60768
  var lessons_default = `# English practice lessons
@@ -60592,6 +60592,34 @@ function parseArgs(raw) {
60592
60592
  return { _raw: raw };
60593
60593
  }
60594
60594
  }
60595
+ function buildChatCompletionParams(req, providerId) {
60596
+ const tools2 = req.tools.map((t) => ({
60597
+ type: "function",
60598
+ function: {
60599
+ name: t.name,
60600
+ description: t.description,
60601
+ parameters: t.inputSchema
60602
+ }
60603
+ }));
60604
+ const params = {
60605
+ ...req.vendorConfig ?? {},
60606
+ model: req.model,
60607
+ messages: toMessages(req.system, req.messages),
60608
+ stream: true,
60609
+ stream_options: { include_usage: true },
60610
+ ...tools2.length > 0 ? { tools: tools2 } : {},
60611
+ ...tools2.length > 0 && req.toolChoice === "required" ? { tool_choice: "required" } : {},
60612
+ ...tools2.length > 0 && typeof req.toolChoice === "object" && req.toolChoice !== null ? {
60613
+ tool_choice: {
60614
+ type: "function",
60615
+ function: { name: req.toolChoice.name }
60616
+ }
60617
+ } : {},
60618
+ ...req.temperature !== void 0 ? { temperature: req.temperature } : {},
60619
+ ...req.maxOutputTokens !== void 0 ? providerId === "openai" ? { max_completion_tokens: req.maxOutputTokens } : { max_tokens: req.maxOutputTokens } : {}
60620
+ };
60621
+ return params;
60622
+ }
60595
60623
  function createOpenAiCompatibleProvider(config2) {
60596
60624
  const client = new OpenAI({
60597
60625
  apiKey: config2.apiKey,
@@ -60601,31 +60629,7 @@ function createOpenAiCompatibleProvider(config2) {
60601
60629
  return {
60602
60630
  id: config2.id,
60603
60631
  async *stream(req) {
60604
- const tools2 = req.tools.map((t) => ({
60605
- type: "function",
60606
- function: {
60607
- name: t.name,
60608
- description: t.description,
60609
- parameters: t.inputSchema
60610
- }
60611
- }));
60612
- const params = {
60613
- ...req.vendorConfig ?? {},
60614
- model: req.model,
60615
- messages: toMessages(req.system, req.messages),
60616
- stream: true,
60617
- stream_options: { include_usage: true },
60618
- ...tools2.length > 0 ? { tools: tools2 } : {},
60619
- ...tools2.length > 0 && req.toolChoice === "required" ? { tool_choice: "required" } : {},
60620
- ...tools2.length > 0 && typeof req.toolChoice === "object" && req.toolChoice !== null ? {
60621
- tool_choice: {
60622
- type: "function",
60623
- function: { name: req.toolChoice.name }
60624
- }
60625
- } : {},
60626
- ...req.temperature !== void 0 ? { temperature: req.temperature } : {},
60627
- ...req.maxOutputTokens !== void 0 ? config2.id === "openai" ? { max_completion_tokens: req.maxOutputTokens } : { max_tokens: req.maxOutputTokens } : {}
60628
- };
60632
+ const params = buildChatCompletionParams(req, config2.id);
60629
60633
  const stream = await client.chat.completions.create(params, {
60630
60634
  signal: req.signal
60631
60635
  });
@@ -60592,6 +60592,34 @@ function parseArgs(raw) {
60592
60592
  return { _raw: raw };
60593
60593
  }
60594
60594
  }
60595
+ function buildChatCompletionParams(req, providerId) {
60596
+ const tools = req.tools.map((t) => ({
60597
+ type: "function",
60598
+ function: {
60599
+ name: t.name,
60600
+ description: t.description,
60601
+ parameters: t.inputSchema
60602
+ }
60603
+ }));
60604
+ const params = {
60605
+ ...req.vendorConfig ?? {},
60606
+ model: req.model,
60607
+ messages: toMessages(req.system, req.messages),
60608
+ stream: true,
60609
+ stream_options: { include_usage: true },
60610
+ ...tools.length > 0 ? { tools } : {},
60611
+ ...tools.length > 0 && req.toolChoice === "required" ? { tool_choice: "required" } : {},
60612
+ ...tools.length > 0 && typeof req.toolChoice === "object" && req.toolChoice !== null ? {
60613
+ tool_choice: {
60614
+ type: "function",
60615
+ function: { name: req.toolChoice.name }
60616
+ }
60617
+ } : {},
60618
+ ...req.temperature !== void 0 ? { temperature: req.temperature } : {},
60619
+ ...req.maxOutputTokens !== void 0 ? providerId === "openai" ? { max_completion_tokens: req.maxOutputTokens } : { max_tokens: req.maxOutputTokens } : {}
60620
+ };
60621
+ return params;
60622
+ }
60595
60623
  function createOpenAiCompatibleProvider(config2) {
60596
60624
  const client = new OpenAI({
60597
60625
  apiKey: config2.apiKey,
@@ -60601,31 +60629,7 @@ function createOpenAiCompatibleProvider(config2) {
60601
60629
  return {
60602
60630
  id: config2.id,
60603
60631
  async *stream(req) {
60604
- const tools = req.tools.map((t) => ({
60605
- type: "function",
60606
- function: {
60607
- name: t.name,
60608
- description: t.description,
60609
- parameters: t.inputSchema
60610
- }
60611
- }));
60612
- const params = {
60613
- ...req.vendorConfig ?? {},
60614
- model: req.model,
60615
- messages: toMessages(req.system, req.messages),
60616
- stream: true,
60617
- stream_options: { include_usage: true },
60618
- ...tools.length > 0 ? { tools } : {},
60619
- ...tools.length > 0 && req.toolChoice === "required" ? { tool_choice: "required" } : {},
60620
- ...tools.length > 0 && typeof req.toolChoice === "object" && req.toolChoice !== null ? {
60621
- tool_choice: {
60622
- type: "function",
60623
- function: { name: req.toolChoice.name }
60624
- }
60625
- } : {},
60626
- ...req.temperature !== void 0 ? { temperature: req.temperature } : {},
60627
- ...req.maxOutputTokens !== void 0 ? config2.id === "openai" ? { max_completion_tokens: req.maxOutputTokens } : { max_tokens: req.maxOutputTokens } : {}
60628
- };
60632
+ const params = buildChatCompletionParams(req, config2.id);
60629
60633
  const stream = await client.chat.completions.create(params, {
60630
60634
  signal: req.signal
60631
60635
  });
@@ -60769,7 +60773,7 @@ var voicethere_llm_default = {
60769
60773
  };
60770
60774
 
60771
60775
  // templates/llm-store-support/prompt.md
60772
- var prompt_default = 'You are the phone support assistant for Kestrel Outdoor, an online store for camping and hiking gear. Customers talk to you by voice, so everything you say is read aloud.\n\nKeep replies to one to three short sentences, in plain words. Do not use markdown, lists, emoji or special characters. Say prices as words, for example "one hundred and twenty-nine dollars".\n\nAnswer questions about shipping, returns, warranty, sizing, store hours, contact details and what the store sells from search_knowledge. Search before you answer such a question: do not give a guess or a filler sentence first. If the search has nothing, say you are not sure and offer to connect the customer with the support team at the address or number in the store information.\n\nFor any price, call get_product_price with the product name or id. If the customer asks what the store sells and you need exact names, call list_products. Never state a price that did not come from get_product_price, never estimate one and never work out a total from memory. If the tool says it does not know the product, say so and offer to look up a similar one.\n\nBe friendly and patient. Ask one question at a time.\n';
60776
+ var prompt_default = 'You are the phone support assistant for Kestrel Outdoor, an online store for camping and hiking gear. Customers talk to you by voice, so everything you say is read aloud.\n\nKeep replies to one to three short sentences, in plain words. Do not use markdown, lists, emoji or special characters. Say prices as words, for example "one hundred and twenty-nine dollars".\n\nAnswer questions about shipping, returns, warranty, sizing, store hours, contact details and what the store sells from search_knowledge. Search before you answer such a question: do not give a guess or a filler sentence first. If the search has nothing, say you are not sure and offer to connect the customer with the support team at the address or number in the store information.\n\nFor any price, call get_product_price with the product name or id. Say exactly the priceUsd that get_product_price returned, in words, and no other amount. If the customer asks what the store sells and you need exact names, call list_products. Never state a price that did not come from get_product_price, never estimate one and never work out a total from memory. If the tool says it does not know the product, say so and offer to look up a similar one.\n\nBe friendly and patient. Ask one question at a time.\n';
60773
60777
 
60774
60778
  // templates/llm-store-support/knowledge/shipping.md
60775
60779
  var shipping_default = "# Shipping at Kestrel Outdoor\n\n## Delivery times and carriers\n\nOrders placed before 2 pm on a business day leave our warehouse the same day. Standard shipping takes three to five business days within the continental United States. Express shipping takes one to two business days. Orders to Alaska, Hawaii and US territories take up to ten business days.\n\n## Shipping costs\n\nLarger orders ship standard for free. The free-shipping threshold and the flat rates for smaller orders and for express are shown at checkout.\n\n## Tracking and delivery problems\n\nEvery order gets a tracking link by email when it ships. If a package shows as delivered but did not arrive, wait one business day and check with neighbors, then contact support. We open a carrier claim and send a replacement once the claim is filed.\n\n## International orders\n\nWe ship to Canada. Duties and import taxes are charged by the carrier on delivery. We do not ship to other countries yet.\n";
@@ -60592,6 +60592,34 @@ function parseArgs(raw) {
60592
60592
  return { _raw: raw };
60593
60593
  }
60594
60594
  }
60595
+ function buildChatCompletionParams(req, providerId) {
60596
+ const tools2 = req.tools.map((t) => ({
60597
+ type: "function",
60598
+ function: {
60599
+ name: t.name,
60600
+ description: t.description,
60601
+ parameters: t.inputSchema
60602
+ }
60603
+ }));
60604
+ const params = {
60605
+ ...req.vendorConfig ?? {},
60606
+ model: req.model,
60607
+ messages: toMessages(req.system, req.messages),
60608
+ stream: true,
60609
+ stream_options: { include_usage: true },
60610
+ ...tools2.length > 0 ? { tools: tools2 } : {},
60611
+ ...tools2.length > 0 && req.toolChoice === "required" ? { tool_choice: "required" } : {},
60612
+ ...tools2.length > 0 && typeof req.toolChoice === "object" && req.toolChoice !== null ? {
60613
+ tool_choice: {
60614
+ type: "function",
60615
+ function: { name: req.toolChoice.name }
60616
+ }
60617
+ } : {},
60618
+ ...req.temperature !== void 0 ? { temperature: req.temperature } : {},
60619
+ ...req.maxOutputTokens !== void 0 ? providerId === "openai" ? { max_completion_tokens: req.maxOutputTokens } : { max_tokens: req.maxOutputTokens } : {}
60620
+ };
60621
+ return params;
60622
+ }
60595
60623
  function createOpenAiCompatibleProvider(config2) {
60596
60624
  const client = new OpenAI({
60597
60625
  apiKey: config2.apiKey,
@@ -60601,31 +60629,7 @@ function createOpenAiCompatibleProvider(config2) {
60601
60629
  return {
60602
60630
  id: config2.id,
60603
60631
  async *stream(req) {
60604
- const tools2 = req.tools.map((t) => ({
60605
- type: "function",
60606
- function: {
60607
- name: t.name,
60608
- description: t.description,
60609
- parameters: t.inputSchema
60610
- }
60611
- }));
60612
- const params = {
60613
- ...req.vendorConfig ?? {},
60614
- model: req.model,
60615
- messages: toMessages(req.system, req.messages),
60616
- stream: true,
60617
- stream_options: { include_usage: true },
60618
- ...tools2.length > 0 ? { tools: tools2 } : {},
60619
- ...tools2.length > 0 && req.toolChoice === "required" ? { tool_choice: "required" } : {},
60620
- ...tools2.length > 0 && typeof req.toolChoice === "object" && req.toolChoice !== null ? {
60621
- tool_choice: {
60622
- type: "function",
60623
- function: { name: req.toolChoice.name }
60624
- }
60625
- } : {},
60626
- ...req.temperature !== void 0 ? { temperature: req.temperature } : {},
60627
- ...req.maxOutputTokens !== void 0 ? config2.id === "openai" ? { max_completion_tokens: req.maxOutputTokens } : { max_tokens: req.maxOutputTokens } : {}
60628
- };
60632
+ const params = buildChatCompletionParams(req, config2.id);
60629
60633
  const stream = await client.chat.completions.create(params, {
60630
60634
  signal: req.signal
60631
60635
  });
package/eject/llm/loop.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copied from @voicethere/agent 0.35.2. Package updates no longer change this file.
1
+ // Copied from @voicethere/agent 0.35.4. Package updates no longer change this file.
2
2
  import { randomUUID } from "node:crypto";
3
3
  import {
4
4
  type AgentHandlers,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voicethere/agent",
3
- "version": "0.35.2",
3
+ "version": "0.35.4",
4
4
  "description": "VoiceThere customer agent SDK — IPC types and runtime helpers for sandboxed child bundles",
5
5
  "type": "module",
6
6
  "exports": {
@@ -17,13 +17,13 @@ The runner owns the switch. The agent never calls `setVoiceLanguage`.
17
17
  - `onVoiceLanguageChanged` records the committed language and sends `{ "type": "language", "language": "de" }` to the client. The runner sends it after it has replayed the switching utterance, so the replayed final (`replay: true`) is answered in the language detected for it; every other final is answered in the committed language. The agent appends one line ("The caller now speaks German (de). Reply only in German.") to a copy of the last caller message on every LLM call, so it never piles up in the history.
18
18
  - `onUserLanguage` only reports what was heard: `{ "type": "language_detected", "language": "it", "supported": false }`. The runner may still reject a detection, so a detection alone does not change the LLM note: only the replay that follows a switch uses it.
19
19
  - When the detected language is not in `SUPPORTED_LANGUAGES`, the runner does not switch and the transcript comes from the wrong language's speech model. The agent skips the LLM for that utterance and says, in the current language, "I heard Italian. I can talk with you in English, German, Spanish or French." That notice is not added to the LLM history.
20
- - Typed chat messages are answered in the language they are written in (the agent adds a one-line note to the chat message, not stored in the history, so the reply does not follow the voice language); chat does not change the voice.
20
+ - Typed chat messages are answered in the language they are written in (the agent guesses the language from common words and characters, limited to the supported languages, and adds a one-line note naming it to the chat message, for example "The caller typed this message in Spanish (es). Reply only in Spanish."; when the text is short or mixed it adds a general "reply in the language of this message" note instead. The note is not stored in the history, so the reply does not follow the voice language); chat does not change the voice.
21
21
 
22
22
  ## Files
23
23
 
24
24
  - `agent.ts` wires `createLlmAgent` into `languageSwitchAgent`.
25
25
  - `language.ts` holds `SUPPORTED_LANGUAGES`, the language note and the unsupported-language notice. Keep `SUPPORTED_LANGUAGES` equal to the project's `voice.allowedLanguages`.
26
- - `voicethere.llm.json` holds the model, greeting and limits.
26
+ - `voicethere.llm.json` holds the model (`anthropic/claude-haiku-5.5` on OpenRouter), greeting and limits.
27
27
  - `prompt.md` is the system prompt.
28
28
  - `md.d.ts` lets TypeScript accept `import x from "./x.md"`.
29
29
 
@@ -102,13 +102,78 @@ export function withLanguageNote(
102
102
  return withNote(messages, languageNote(code));
103
103
  }
104
104
 
105
- /** The one line that tells the LLM to answer a typed message in its own language. */
105
+ /** The fallback line when the language of a typed message is not clear. */
106
106
  export const CHAT_NOTE =
107
107
  "Reply in the language this message is written in, even if the earlier conversation used another language.";
108
108
 
109
- /** Same as `withLanguageNote`, for a typed chat message. */
109
+ /** Common words per language; ambiguous ones (`de`, `la`, `en`, `a`) are left out. */
110
+ const STOPWORDS: Record<string, readonly string[]> = {
111
+ en: "the is are what where how can you your i my to of and for with from this that it do does please".split(
112
+ " ",
113
+ ),
114
+ de: "der die das ist sind wo wie kann ich du sie ein eine und nicht mit von zu bitte wann welche auf nach".split(
115
+ " ",
116
+ ),
117
+ es: "el los las es son dónde donde cómo como puedo puede yo tú un una y no con por para hola desde al qué que cuál".split(
118
+ " ",
119
+ ),
120
+ fr: "le les est sont où ou comment puis je tu vous un une et pas avec pour bonjour depuis au quel quelle que qu'est-ce".split(
121
+ " ",
122
+ ),
123
+ };
124
+
125
+ /** Characters that mark one language among the supported ones. */
126
+ const MARKS: Record<string, string> = {
127
+ es: "¿¡ñ",
128
+ de: "ßäöü",
129
+ fr: "çàèùêîôû",
130
+ };
131
+
132
+ /**
133
+ * Guesses the language of a typed message from stopwords and marks, limited
134
+ * to `SUPPORTED_LANGUAGES`. Returns a code only when the best language has at
135
+ * least 2 hits and leads the next one by at least 2; short, mixed or unknown
136
+ * text returns undefined. A guess only words the chat note: it never changes
137
+ * the session language or the voice.
138
+ */
139
+ export function guessChatLanguage(text: string): string | undefined {
140
+ const words = text.toLowerCase().match(/[\p{L}'-]+/gu) ?? [];
141
+ const scores = SUPPORTED_LANGUAGES.map((code) => {
142
+ const stop = new Set(STOPWORDS[code] ?? []);
143
+ let hits = words.filter((w) => stop.has(w)).length;
144
+ for (const mark of MARKS[code] ?? "") {
145
+ if (text.toLowerCase().includes(mark)) hits += 1;
146
+ }
147
+ return { code, hits };
148
+ }).sort((a, b) => b.hits - a.hits);
149
+ const best = scores[0];
150
+ const next = scores[1];
151
+ if (!best || best.hits < 2 || best.hits - (next?.hits ?? 0) < 2) {
152
+ return undefined;
153
+ }
154
+ return best.code;
155
+ }
156
+
157
+ /** The chat note naming the language of a typed message. */
158
+ export function chatLanguageNote(code: string): string {
159
+ const name = languageName(code, "en");
160
+ return `The caller typed this message in ${name} (${code}). Reply only in ${name}.`;
161
+ }
162
+
163
+ const INTERRUPTION_NOTE =
164
+ /^\(The caller interrupted your previous reply after: [\s\S]*?\.\)\n/;
165
+
166
+ /**
167
+ * Same as `withLanguageNote`, for a typed chat message: names the guessed
168
+ * language, or falls back to `CHAT_NOTE` when the guess is not clear.
169
+ */
110
170
  export function withChatNote(messages: LlmMessage[]): LlmMessage[] {
111
- return withNote(messages, CHAT_NOTE);
171
+ const last = [...messages].reverse().find((m) => m.role === "user");
172
+ // The runtime may put its English interruption note before the message;
173
+ // it is not the caller's text and must not count towards the guess.
174
+ const typed = last?.text.replace(INTERRUPTION_NOTE, "");
175
+ const code = typed ? guessChatLanguage(typed) : undefined;
176
+ return withNote(messages, code ? chatLanguageNote(code) : CHAT_NOTE);
112
177
  }
113
178
 
114
179
  function withNote(messages: LlmMessage[], note: string): LlmMessage[] {
@@ -2,7 +2,7 @@
2
2
  "$schema": "./node_modules/@voicethere/agent/schema/voicethere.llm.schema.json",
3
3
  "version": 1,
4
4
  "provider": "openrouter",
5
- "model": "amazon/nova-micro-v1",
5
+ "model": "anthropic/claude-haiku-5.5",
6
6
  "apiKeySecret": "AGENT_OPENROUTER_API_KEY",
7
7
  "maxOutputTokens": 256,
8
8
  "greeting": {
@@ -4,6 +4,6 @@ Speak English only, even if the learner switches to another language. Keep repli
4
4
 
5
5
  Correct at most one mistake per turn. Say the learner's sentence again the correct way, then give the reason in a few words. If there is no mistake, say something encouraging in a few words instead. Then ask one follow-up question that keeps the conversation going.
6
6
 
7
- When the learner asks about a phrase, an idiom or a lesson topic, call search_knowledge first and answer from what it returns. Call it before you say anything on such a question: do not give a meaning, a guess or a filler sentence first. Never make up the meaning of an idiom that the search did not return. If the search has nothing, say you are not sure and offer a different phrase to practice.
7
+ When the learner asks about a phrase, an idiom or a lesson topic, call search_knowledge first and answer from what it returns. Call it before you say anything on such a question: do not give a meaning, a guess or a filler sentence first. Never make up the meaning of an idiom that the search did not return. If the search has nothing, say you are not sure and suggest one lesson topic to practice instead. Do not explain any phrase or idiom that the search did not return.
8
8
 
9
9
  Be patient and friendly. Let the learner finish their thought before you correct anything.
@@ -4,6 +4,6 @@ Keep replies to one to three short sentences, in plain words. Do not use markdow
4
4
 
5
5
  Answer questions about shipping, returns, warranty, sizing, store hours, contact details and what the store sells from search_knowledge. Search before you answer such a question: do not give a guess or a filler sentence first. If the search has nothing, say you are not sure and offer to connect the customer with the support team at the address or number in the store information.
6
6
 
7
- For any price, call get_product_price with the product name or id. If the customer asks what the store sells and you need exact names, call list_products. Never state a price that did not come from get_product_price, never estimate one and never work out a total from memory. If the tool says it does not know the product, say so and offer to look up a similar one.
7
+ For any price, call get_product_price with the product name or id. Say exactly the priceUsd that get_product_price returned, in words, and no other amount. If the customer asks what the store sells and you need exact names, call list_products. Never state a price that did not come from get_product_price, never estimate one and never work out a total from memory. If the tool says it does not know the product, say so and offer to look up a similar one.
8
8
 
9
9
  Be friendly and patient. Ask one question at a time.