@voicethere/agent 0.35.1 → 0.35.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.
@@ -60799,7 +60799,13 @@ function unsupportedNotice(heard, current) {
60799
60799
  return `${text.heard(languageName(heard, lang))} ${text.can(list)}`;
60800
60800
  }
60801
60801
  function withLanguageNote(messages, code) {
60802
- const note = languageNote(code);
60802
+ return withNote(messages, languageNote(code));
60803
+ }
60804
+ var CHAT_NOTE = "Reply in the language this message is written in, even if the earlier conversation used another language.";
60805
+ function withChatNote(messages) {
60806
+ return withNote(messages, CHAT_NOTE);
60807
+ }
60808
+ function withNote(messages, note) {
60803
60809
  for (let i = messages.length - 1; i >= 0; i -= 1) {
60804
60810
  const m = messages[i];
60805
60811
  if (m.role === "user") {
@@ -60820,7 +60826,7 @@ function languageSwitchAgent(create) {
60820
60826
  const sessions = /* @__PURE__ */ new Map();
60821
60827
  const llm = create({
60822
60828
  onBeforeLlmCall(messages, ctx) {
60823
- if (ctx.source === "chat") return;
60829
+ if (ctx.source === "chat") return withChatNote(messages);
60824
60830
  return withLanguageNote(
60825
60831
  messages,
60826
60832
  replyLanguage(sessions.get(ctx.sessionId))
package/eject/llm/loop.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copied from @voicethere/agent 0.35.1. Package updates no longer change this file.
1
+ // Copied from @voicethere/agent 0.35.2. 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.1",
3
+ "version": "0.35.2",
4
4
  "description": "VoiceThere customer agent SDK — IPC types and runtime helpers for sandboxed child bundles",
5
5
  "type": "module",
6
6
  "exports": {
@@ -17,7 +17,7 @@ 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 prompt says so); chat does not change the voice.
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.
21
21
 
22
22
  ## Files
23
23
 
@@ -99,7 +99,19 @@ export function withLanguageNote(
99
99
  messages: LlmMessage[],
100
100
  code: string,
101
101
  ): LlmMessage[] {
102
- const note = languageNote(code);
102
+ return withNote(messages, languageNote(code));
103
+ }
104
+
105
+ /** The one line that tells the LLM to answer a typed message in its own language. */
106
+ export const CHAT_NOTE =
107
+ "Reply in the language this message is written in, even if the earlier conversation used another language.";
108
+
109
+ /** Same as `withLanguageNote`, for a typed chat message. */
110
+ export function withChatNote(messages: LlmMessage[]): LlmMessage[] {
111
+ return withNote(messages, CHAT_NOTE);
112
+ }
113
+
114
+ function withNote(messages: LlmMessage[], note: string): LlmMessage[] {
103
115
  for (let i = messages.length - 1; i >= 0; i -= 1) {
104
116
  const m = messages[i]!;
105
117
  if (m.role === "user") {
@@ -146,8 +158,9 @@ export function languageSwitchAgent(
146
158
 
147
159
  const llm = create({
148
160
  onBeforeLlmCall(messages, ctx) {
149
- // Typed chat is answered in the language it is written in.
150
- if (ctx.source === "chat") return;
161
+ // Typed chat is answered in the language it is written in, not the
162
+ // call's voice language (the history may be in another language).
163
+ if (ctx.source === "chat") return withChatNote(messages);
151
164
  return withLanguageNote(
152
165
  messages,
153
166
  replyLanguage(sessions.get(ctx.sessionId)),