From 61df4499e3ffcf8a9117d1a663f23ecb71e4a4cc Mon Sep 17 00:00:00 2001 From: Santino Fuentes Date: Sat, 28 Nov 2026 21:23:01 -0600 Subject: [PATCH 1/2] fix(model): detect English requests with URLs in userLanguage (#111) Signed-off-by: Santino Fuentes --- packages/model/src/prompt.ts | 21 ++++++++++++----- packages/model/test/prompt-language.test.ts | 26 +++++++++++++++++++++ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/packages/model/src/prompt.ts b/packages/model/src/prompt.ts index 1d02f98..9fa9c27 100644 --- a/packages/model/src/prompt.ts +++ b/packages/model/src/prompt.ts @@ -448,14 +448,23 @@ export function longReplyPrompt(ctx: PromptContext, kind: LongFormKind, userText ].join("\n"); } -/** Spanish or English from the user's own words (results and tool text are English and must not decide). */ +const URL_RE = /https?:\/\/\S+|www\.\S+/gi; +const ES_ACCENTS_RE = /[¿¡ñáéíóú]/i; +const ES_WORDS_RE = + /(?= enHits ? "Spanish (Latin America)" : "English"; } /** diff --git a/packages/model/test/prompt-language.test.ts b/packages/model/test/prompt-language.test.ts index 4964b8a..19a4e6f 100644 --- a/packages/model/test/prompt-language.test.ts +++ b/packages/model/test/prompt-language.test.ts @@ -10,3 +10,29 @@ test("short everyday phrases are detected in both languages", () => { } expect(userLanguage("ok")).toBeUndefined(); }); + +test("URLs do not decide language and common English/Spanish requests are detected outside links", () => { + for (const t of [ + "read https://recipes.example/soup and summarize it", + "summarize https://recipes.example/soup for me", + "check www.recipes.example/soup please", + "open https://site.example/hola/café", + "resume my music", + ]) { + expect(userLanguage(t), t).toBe("English"); + } + for (const t of [ + "léeme https://noticias.example/hoy", + "resume esta página: https://recetas.example/sopa", + "resume esta pagina: https://recetas.example/sopa", + "lee https://site.example/read-and-summarize", + ]) { + expect(userLanguage(t), t).toBe("Spanish (Latin America)"); + } + for (const t of [ + "https://recipes.example/soup", + "www.recipes.example/noticias", + ]) { + expect(userLanguage(t), t).toBeUndefined(); + } +}); From 6e22eee3e92c13a5fe36b56c43f104bea1c3b764 Mon Sep 17 00:00:00 2001 From: Santino Fuentes Date: Sat, 28 Nov 2026 21:33:00 -0600 Subject: [PATCH 2/2] docs(model): document standalone 'a' fallback in userLanguage (#111) Signed-off-by: Santino Fuentes --- packages/model/src/prompt.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/model/src/prompt.ts b/packages/model/src/prompt.ts index 9fa9c27..488f480 100644 --- a/packages/model/src/prompt.ts +++ b/packages/model/src/prompt.ts @@ -462,6 +462,7 @@ export function userLanguage(text: string): string | undefined { const esHits = (prose.match(ES_WORDS_RE)?.length ?? 0) + (ES_ACCENTS_RE.test(prose) ? 1 : 0); const enHits = prose.match(EN_WORDS_RE)?.length ?? 0; if (esHits === 0 && enHits === 0) { + // "a" is also a Spanish preposition, so only count it for English when no other word matched. return /(?= enHits ? "Spanish (Latin America)" : "English";