The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(chat): Chat Tools reach messages in every language (GH #224, C51)
purple7381b54f9d85
diff --git a/src/hooks/useChat.ts b/src/hooks/useChat.tsindex 0454b4c9..1578cba2 100644--- a/src/hooks/useChat.ts+++ b/src/hooks/useChat.ts@@ -1106,6 +1106,8 @@ export function useChat() {const media = m.role === 'assistant' ? lastMediaFromBlocks(m) : nullreturn { role: m.role, content: m.content, mediaKind: media?.kind, mediaArgs: media?.args }})+ // A message in a language the detector cannot read comes back as an+ // `open` route: the tools ride along and the model decides (GH #224).const route = resolveChatToolRoute(content, !!images?.length, recent)// Cloud mode has no local ComfyUI pipeline: media intents stay on the// plain-chat path (cloud renders live in the Create tab) instead ofdiff --git a/src/lib/__tests__/chat-tools-every-language.test.ts b/src/lib/__tests__/chat-tools-every-language.test.tsnew file mode 100644index 00000000..be323c72--- /dev/null+++ b/src/lib/__tests__/chat-tools-every-language.test.ts@@ -0,0 +1,65 @@+/**+ * GH #224 (C51): Chat Tools in the plain chat only reached a model when an+ * English or German pattern matched. A user writing Japanese got no tool on+ * any turn. A message the detector cannot read now carries the tools, and the+ * model decides; English and German stay as they were.+ *+ * Run: npx vitest run src/lib/__tests__/chat-tools-every-language.test.ts+ */+import { describe, it, expect } from 'vitest'+import { detectorReads, resolveChatToolRoute } from '../chat-tool-intent'++const OTHER_LANGUAGES = [+ '猫の画像を作ってください', // Japanese: make a picture of a cat+ '最新的Python版本是什么?', // Chinese: what is the latest Python version+ 'найди в интернете погоду в Берлине', // Russian: find the weather in Berlin online+ 'ابحث عن أخبار اليوم', // Arabic: search today's news+ 'dibuja un gato en la luna', // Spanish+ 'dessine un chat sur la lune', // French+ 'cerca su internet il meteo di Roma', // Italian+ 'wygeneruj obraz kota w kosmosie', // Polish+]++describe('GH #224: a message the detector cannot read carries the tools', () => {+ for (const text of OTHER_LANGUAGES) {+ it(`"${text}" goes to the tools, the model decides`, () => {+ expect(detectorReads(text)).toBe(false)+ expect(resolveChatToolRoute(text, false, [])).toEqual({ capability: 'open' })+ })+ }++ it('an open route carries no media hint: the model picks the tool, nothing is forced', () => {+ expect(resolveChatToolRoute('猫の画像を作って', false, [])?.mediaHint).toBeUndefined()+ })+})++describe('English and German stay as before', () => {+ for (const text of [+ 'how are you today?',+ 'explain recursion to me',+ 'what is the capital of France',+ 'wie geht es dir?',+ 'erklär mir bitte die Photosynthese',+ 'hallo',+ 'hola',+ 'ok',+ 'thanks!',+ '42',+ '🙂👍',+ '',+ ]) {+ it(`"${text}" stays on the plain path`, () => {+ expect(detectorReads(text)).toBe(true)+ expect(resolveChatToolRoute(text, false, [])).toBeNull()+ })+ }++ it('a recognised English or German request still routes by its own capability', () => {+ expect(resolveChatToolRoute('draw me a picture of a red apple', false, [])?.capability).toBe('image')+ expect(resolveChatToolRoute('such im netz nach dem wetter', false, [])?.capability).toBe('web')+ })++ it('a mostly English message with a foreign name in it is still read', () => {+ expect(detectorReads('what does 東京 mean in English')).toBe(true)+ })+})diff --git a/src/lib/chat-tool-intent.ts b/src/lib/chat-tool-intent.tsindex 58d6b066..46230d0e 100644--- a/src/lib/chat-tool-intent.ts+++ b/src/lib/chat-tool-intent.ts@@ -14,7 +14,8 @@* explanation request, or normal Q&A must NOT match (otherwise every message* would route through the tool loop). It errs toward the concrete signals a* user gives when they actually want a web lookup, a file written, or an- * image/video made — in both English and German.+ * image/video made — in both English and German. A message in any other+ * language carries the tools and the model decides (detectorReads, GH #224).*//** The exact tools surfaced in plain chat. Order is irrelevant. */@@ -241,12 +242,56 @@ export interface ChatToolRouteMsg {}export interface ChatToolRoute {- capability: ChatToolCapability+ /** `open`: the message is in a language the detector above cannot read+ * (GH #224), so the tools ride along and the model decides. */+ capability: ChatToolCapability | 'open'/** Present for media routes; `args` carries the prior generation's parameters* (prompt, inputImage, duration…) for a faithful regenerate. */mediaHint?: { kind: 'image' | 'video'; args?: Record<string, unknown> }}+// ── Languages the detector does not read (GH #224, C51) ───────────+//+// Every pattern above is English or German. A Japanese "猫の画像を作って", a+// Spanish "dibuja un gato" or a Russian "найди в интернете" matched none of+// them, and the turn went to the plain path, where no tool exists: Chat Tools+// were, for everyone writing in another language, never on. Keyword lists for+// every language would never be complete. So the detector says when it cannot+// judge a message at all, and such a turn carries the tools; the model, which+// does read the language, decides whether to call one. English and German+// stay exactly as before.++/** Short, frequent words of English and German that the neighbouring+ * languages do not share (no "de", "es", "me", "no", "a", "in"). One of them+ * in a Latin-script message means the patterns above can judge it. */+const EN_DE_WORDS = new Set([+ 'the', 'and', 'is', 'are', 'you', 'your', 'what', 'how', 'why', 'when', 'where', 'who', 'which',+ 'please', 'can', 'could', 'would', 'should', 'this', 'that', 'with', 'for', 'my', 'it', 'of', 'to',+ 'an', 'be', 'do', 'does', 'was', 'were', 'have', 'has', 'will', 'about', 'from', 'write', 'make',+ 'tell', 'hi', 'hello', 'hey', 'thanks', 'thank', 'yes', 'i', 'me',+ 'und', 'der', 'die', 'das', 'ist', 'ich', 'du', 'nicht', 'ein', 'eine', 'einen', 'mit', 'auf',+ 'fuer', 'wie', 'was', 'bitte', 'mir', 'mich', 'kannst', 'kann', 'schreib', 'mach', 'zeig',+ 'hallo', 'danke', 'ja', 'nein', 'sind', 'wer', 'warum', 'wo', 'wann', 'welche', 'welcher',+])++/**+ * Can the patterns above judge this message? False for a message mostly in a+ * non-Latin script (Japanese, Chinese, Russian, Arabic, ...) and for a Latin+ * one of three words or more without a single English or German word+ * (Spanish, French, Italian, Polish, ...). A message without letters, and one+ * or two Latin words ("hola", "ok"), count as read: those stay on the plain+ * path as before. A wrong "read" only keeps the old behaviour.+ */+export function detectorReads(text: string): boolean {+ const letters = (text || '').match(/\p{L}/gu) ?? []+ if (letters.length === 0) return true+ const latin = letters.filter((ch) => /\p{Script=Latin}/u.test(ch)).length+ if (latin / letters.length < 0.7) return false+ const words = lower(text).match(/\p{L}+/gu) ?? []+ if (words.some((w) => EN_DE_WORDS.has(w))) return true+ return words.length <= 2+}+/** How far back to look for the in-progress media task. */const MEDIA_CONTEXT_WINDOW = 12@@ -267,7 +312,7 @@ export function resolveChatToolRoute(? { capability: direct, mediaHint: { kind: direct } }: { capability: direct }}- if (!isMediaContinuation(text)) return null+ if (!isMediaContinuation(text)) return detectorReads(text) ? null : { capability: 'open' }const window = recent.slice(-MEDIA_CONTEXT_WINDOW)for (let i = window.length - 1; i >= 0; i--) {@@ -282,5 +327,5 @@ export function resolveChatToolRoute(if (cap === 'image' || cap === 'video') return { capability: cap, mediaHint: { kind: cap } }}}- return null+ return detectorReads(text) ? null : { capability: 'open' }}