@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
|
-
|
|
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
package/package.json
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
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)),
|