From b3c372bdf4eb48c76b8713ef010c47bc565681af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=8E=AE?= <165636612+1jackwang@users.noreply.github.com> Date: Sat, 28 Nov 2026 16:41:24 +0800 Subject: [PATCH] fix: match generated text to the user's language --- CHANGELOG.md | 7 +++ src/qoder/prompt/generated-text-language.ts | 5 ++ src/qoder/prompt/inline-edit.ts | 5 ++ src/qoder/prompt/instruction-refine.ts | 8 ++- src/qoder/prompt/title-generation.ts | 12 +++- .../qoder-title-generation-service.ts | 39 +++--------- tests/unit/qoder/prompt/inline-edit.test.ts | 31 ++++++++-- .../qoder/prompt/instruction-refine.test.ts | 40 ++++++------ .../qoder/prompt/title-generation.test.ts | 61 ++++++++++++++++--- .../qoder-inline-edit-service.test.ts | 35 +++++++++++ .../qoder-instruction-refine-service.test.ts | 30 +++++++++ .../qoder-title-generation-service.test.ts | 31 ++++++++++ 12 files changed, 239 insertions(+), 65 deletions(-) create mode 100644 src/qoder/prompt/generated-text-language.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f9638e..ac48cb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,13 @@ version with its date and start a fresh empty `[Unreleased]` above it. ## [Unreleased] +### Fixed + +- Auto-generated conversation titles, inline edits, and refined instructions + now follow the language of the user's request, falling back to the UI locale + when the language is unclear. Proper nouns, product names, file names, and + code identifiers are preserved. + ## [1.0.20] - 2026-11-26 ### Fixed diff --git a/src/qoder/prompt/generated-text-language.ts b/src/qoder/prompt/generated-text-language.ts new file mode 100644 index 0000000..d28b783 --- /dev/null +++ b/src/qoder/prompt/generated-text-language.ts @@ -0,0 +1,5 @@ +import { getLocale } from '../../i18n/i18n'; + +export function buildGeneratedTextLanguageRule(): string { + return `**Language**: Write the generated text in the same language as the user's request. If the request's language is unclear, use the UI locale (\`${getLocale()}\`). Keep proper nouns, product names, file names, paths, code identifiers, and code snippets unchanged; do not translate or rename them.`; +} diff --git a/src/qoder/prompt/inline-edit.ts b/src/qoder/prompt/inline-edit.ts index ce75577..5b06503 100644 --- a/src/qoder/prompt/inline-edit.ts +++ b/src/qoder/prompt/inline-edit.ts @@ -5,6 +5,7 @@ import type { InlineEditResult, } from '../../core/types/services'; import { appendContextFiles } from './context/prompt-context'; +import { buildGeneratedTextLanguageRule } from './generated-text-language'; export function parseInlineEditResponse(responseText: string): InlineEditResult { const replacementMatch = responseText.match(/([\s\S]*?)<\/replacement>/); @@ -88,6 +89,8 @@ You are **Qoderian**, an expert editor and writing assistant embedded in Obsidia 3. **Silent Execution**: Use tools (Read, WebSearch) silently. Your final output must be ONLY the result. 4. **No Fluff**: No pleasantries, no "Here is the text", no "I have updated...". Just the content. +${buildGeneratedTextLanguageRule()} + ## Input Format User messages have the instruction first, followed by XML context tags: @@ -174,6 +177,8 @@ CORRECT: "This is a guide about..." If the request is ambiguous, ask a clarifying question. Keep questions concise and specific. +The examples below illustrate formatting only. Always follow the language rule above for the generated text. + ## Examples ### Selection Mode diff --git a/src/qoder/prompt/instruction-refine.ts b/src/qoder/prompt/instruction-refine.ts index 1b61c91..fde70e2 100644 --- a/src/qoder/prompt/instruction-refine.ts +++ b/src/qoder/prompt/instruction-refine.ts @@ -1,3 +1,5 @@ +import { buildGeneratedTextLanguageRule } from './generated-text-language'; + export function buildRefineSystemPrompt(existingInstructions: string): string { const existingSection = existingInstructions.trim() ? `\n\nEXISTING INSTRUCTIONS (already in the user's system prompt): @@ -21,7 +23,7 @@ When refining the new instruction: 2. **Check Context**: Does this conflict with existing instructions? - *No Conflict*: Add as new. - *Conflict*: Propose a **merged instruction** that resolves the contradiction (or ask if unsure). -3. **Refine**: Draft a clear, positive instruction (e.g., "Do X" instead of "Don't do Y"). +3. **Refine**: Draft a clear, positive instruction. 4. **Format**: Return *only* the Markdown snippet wrapped in \`\` tags. **Guidelines**: @@ -31,12 +33,16 @@ When refining the new instruction: - **No Header**: Do NOT include a top-level header like \`# Custom Instructions\`. - **Conflict Handling**: If the new rule directly contradicts an existing one, rewrite the *new* one to override specific cases or ask for clarification. +${buildGeneratedTextLanguageRule()} + **Output Format**: - **Success**: \`...markdown content...\` - **Ambiguity**: Plain text question. ${existingSection} +The examples below illustrate formatting only. Always follow the language rule above for the generated text. + **Examples**: Input: "typescript for code" diff --git a/src/qoder/prompt/title-generation.ts b/src/qoder/prompt/title-generation.ts index 2e521f0..8eb3b25 100644 --- a/src/qoder/prompt/title-generation.ts +++ b/src/qoder/prompt/title-generation.ts @@ -1,17 +1,23 @@ +import { buildGeneratedTextLanguageRule } from './generated-text-language'; + const MAX_TITLE_INPUT_LENGTH = 500; const MAX_TITLE_LENGTH = 50; -export const TITLE_GENERATION_SYSTEM_PROMPT = `You are a specialist in summarizing user intent. +export function getTitleGenerationSystemPrompt(): string { + return `You are a specialist in summarizing user intent. **Task**: Generate a **concise, descriptive title** (max 50 chars) summarizing the user's task/request. **Rules**: 1. **Format**: Sentence case. No periods/quotes. -2. **Structure**: Start with a **strong verb** (e.g., Create, Fix, Debug, Explain, Analyze). +2. **Structure**: Start with a **strong verb** appropriate to the output language. 3. **Forbidden**: "Conversation with...", "Help me...", "Question about...", "I need...". -4. **Tech Context**: Detect and include the primary language/framework if code is present (e.g., "Debug Python script", "Refactor React hook"). +4. **Tech Context**: When code is present, include the primary language or framework, preserving product names and code identifiers exactly. + +${buildGeneratedTextLanguageRule()} **Output**: Return ONLY the raw title text.`; +} export function buildTitleGenerationPrompt(userMessage: string): string { const truncated = userMessage.length > MAX_TITLE_INPUT_LENGTH diff --git a/src/qoder/services/qoder-title-generation-service.ts b/src/qoder/services/qoder-title-generation-service.ts index 262082a..2b2cb29 100644 --- a/src/qoder/services/qoder-title-generation-service.ts +++ b/src/qoder/services/qoder-title-generation-service.ts @@ -4,7 +4,11 @@ import type { } from '../../core/types/services'; import { toQoderRuntimeModelId } from '../models/model-selection'; import { qoderModelConfig } from '../models/qoder-model-config'; -import { TITLE_GENERATION_SYSTEM_PROMPT } from '../prompt/title-generation'; +import { + buildTitleGenerationPrompt, + getTitleGenerationSystemPrompt, + parseTitleGenerationResponse, +} from '../prompt/title-generation'; import type { QoderHostContext } from '../qoder-host-context'; import { runColdStartQuery } from '../runtime/qoder-cold-start-query'; @@ -32,13 +36,12 @@ export class QoderTitleGenerationService { const abortController = new AbortController(); this.activeGenerations.set(conversationId, abortController); - const truncatedUser = this.truncateText(userMessage, 500); - const prompt = `User's request:\n"""\n${truncatedUser}\n"""\n\nGenerate a title for this conversation:`; + const prompt = buildTitleGenerationPrompt(userMessage); try { const result = await runColdStartQuery({ plugin: this.plugin, - systemPrompt: TITLE_GENERATION_SYSTEM_PROMPT, + systemPrompt: getTitleGenerationSystemPrompt(), tools: [], model: this.resolveTitleModel(), thinking: { disabled: true }, @@ -46,7 +49,7 @@ export class QoderTitleGenerationService { abortController, }, prompt); - const title = this.parseTitle(result.text); + const title = parseTitleGenerationResponse(result.text); if (title) { await this.safeCallback(callback, conversationId, { success: true, title }); } else { @@ -82,32 +85,6 @@ export class QoderTitleGenerationService { return 'auto'; } - private truncateText(text: string, maxLength: number): string { - if (text.length <= maxLength) return text; - return text.substring(0, maxLength) + '...'; - } - - private parseTitle(responseText: string): string | null { - const trimmed = responseText.trim(); - if (!trimmed) return null; - - let title = trimmed; - if ( - (title.startsWith('"') && title.endsWith('"')) || - (title.startsWith("'") && title.endsWith("'")) - ) { - title = title.slice(1, -1); - } - - title = title.replace(/[.!?:;,]+$/, ''); - - if (title.length > 50) { - title = title.substring(0, 47) + '...'; - } - - return title || null; - } - private async safeCallback( callback: TitleGenerationCallback, conversationId: string, diff --git a/tests/unit/qoder/prompt/inline-edit.test.ts b/tests/unit/qoder/prompt/inline-edit.test.ts index 380d6a8..c0e3d5b 100644 --- a/tests/unit/qoder/prompt/inline-edit.test.ts +++ b/tests/unit/qoder/prompt/inline-edit.test.ts @@ -2,9 +2,21 @@ jest.mock('@/core/time/date', () => ({ getTodayDate: () => 'Mocked Date', })); +import { getLocale, setLocale } from '@/i18n/i18n'; import { getInlineEditSystemPrompt } from '@/qoder/prompt/inline-edit'; describe('getInlineEditSystemPrompt', () => { + let previousLocale: ReturnType; + + beforeEach(() => { + previousLocale = getLocale(); + setLocale('en'); + }); + + afterEach(() => { + setLocale(previousLocale); + }); + it('should include inline edit critical output rules', () => { const prompt = getInlineEditSystemPrompt(); expect(prompt).toContain('ABSOLUTE RULE'); @@ -17,16 +29,25 @@ describe('getInlineEditSystemPrompt', () => { expect(prompt).toContain('read-only'); }); - it('should include example scenarios', () => { + it('should use the shared language rule while preserving formatting examples', () => { const prompt = getInlineEditSystemPrompt(); - expect(prompt).toContain('translate to French'); - expect(prompt).toContain('Bonjour le monde'); - expect(prompt).toContain('asking for clarification'); + + expect(prompt).toContain("same language as the user's request"); + expect(prompt).toContain('UI locale (`en`)'); + expect(prompt).toContain('proper nouns, product names, file names, paths, code identifiers, and code snippets unchanged'); + expect(prompt).toContain('The examples below illustrate formatting only'); + expect(prompt).toContain('Bonjour le monde'); + expect(prompt.indexOf('**Language**')).toBeLessThan(prompt.indexOf('## Examples')); + }); + + it('should fall back to the current UI locale', () => { + setLocale('zh-CN'); + + expect(getInlineEditSystemPrompt()).toContain('UI locale (`zh-CN`)'); }); it('should include date from utils', () => { const prompt = getInlineEditSystemPrompt(); expect(prompt).toContain('Mocked Date'); }); - }); diff --git a/tests/unit/qoder/prompt/instruction-refine.test.ts b/tests/unit/qoder/prompt/instruction-refine.test.ts index 8d341c3..d7534d3 100644 --- a/tests/unit/qoder/prompt/instruction-refine.test.ts +++ b/tests/unit/qoder/prompt/instruction-refine.test.ts @@ -1,6 +1,18 @@ +import { getLocale, setLocale } from '@/i18n/i18n'; import { buildRefineSystemPrompt } from '@/qoder/prompt/instruction-refine'; describe('buildRefineSystemPrompt', () => { + let previousLocale: ReturnType; + + beforeEach(() => { + previousLocale = getLocale(); + setLocale('en'); + }); + + afterEach(() => { + setLocale(previousLocale); + }); + describe('without existing instructions', () => { it('should return base prompt when existing instructions is empty', () => { const result = buildRefineSystemPrompt(''); @@ -10,7 +22,6 @@ describe('buildRefineSystemPrompt', () => { expect(result).toContain('**Process**'); expect(result).toContain('**Guidelines**'); expect(result).toContain('**Output Format**'); - expect(result).toContain('**Examples**'); }); it('should not include existing instructions section when empty', () => { @@ -93,29 +104,22 @@ describe('buildRefineSystemPrompt', () => { expect(result).toContain('**Ambiguity**'); }); - it('should include examples', () => { + it('should use the shared language rule while preserving formatting examples', () => { const result = buildRefineSystemPrompt(''); + expect(result).toContain("same language as the user's request"); + expect(result).toContain('UI locale (`en`)'); + expect(result).toContain('proper nouns, product names, file names, paths, code identifiers, and code snippets unchanged'); + expect(result).toContain('The examples below illustrate formatting only'); expect(result).toContain('Input: "typescript for code"'); - expect(result).toContain('Input: "be concise"'); - expect(result).toContain('Input: "organize coding style rules"'); - expect(result).toContain('Input: "use that thing from before"'); + expect(result).not.toContain('"Do X" instead of "Don\'t do Y"'); + expect(result.indexOf('**Language**')).toBeLessThan(result.indexOf('**Examples**')); }); - it('should show example outputs with proper tag wrapping', () => { - const result = buildRefineSystemPrompt(''); - - expect(result).toContain('Output: '); - expect(result).toContain('**Code Language**'); - expect(result).toContain('**Conciseness**'); - expect(result).toContain('## Coding Standards'); - }); - - it('should include ambiguity handling example', () => { - const result = buildRefineSystemPrompt(''); + it('should fall back to the current UI locale', () => { + setLocale('zh-CN'); - expect(result).toContain('I\'m not sure what you\'re referring to'); - expect(result).toContain('Could you please clarify'); + expect(buildRefineSystemPrompt('')).toContain('UI locale (`zh-CN`)'); }); }); diff --git a/tests/unit/qoder/prompt/title-generation.test.ts b/tests/unit/qoder/prompt/title-generation.test.ts index b8e7d8e..4cca3e0 100644 --- a/tests/unit/qoder/prompt/title-generation.test.ts +++ b/tests/unit/qoder/prompt/title-generation.test.ts @@ -1,20 +1,67 @@ -import { TITLE_GENERATION_SYSTEM_PROMPT } from '@/qoder/prompt/title-generation'; +import { getLocale, setLocale } from '@/i18n/i18n'; +import { + buildTitleGenerationPrompt, + getTitleGenerationSystemPrompt, + parseTitleGenerationResponse, +} from '@/qoder/prompt/title-generation'; describe('titleGeneration', () => { + let previousLocale: ReturnType; + + beforeEach(() => { + previousLocale = getLocale(); + setLocale('en'); + }); + + afterEach(() => { + setLocale(previousLocale); + }); + it('exports a non-empty system prompt string', () => { - expect(typeof TITLE_GENERATION_SYSTEM_PROMPT).toBe('string'); - expect(TITLE_GENERATION_SYSTEM_PROMPT.length).toBeGreaterThan(0); + const prompt = getTitleGenerationSystemPrompt(); + expect(typeof prompt).toBe('string'); + expect(prompt.length).toBeGreaterThan(0); }); it('includes the max character constraint', () => { - expect(TITLE_GENERATION_SYSTEM_PROMPT).toContain('max 50 chars'); + expect(getTitleGenerationSystemPrompt()).toContain('max 50 chars'); }); - it('instructs to start with a strong verb', () => { - expect(TITLE_GENERATION_SYSTEM_PROMPT).toContain('strong verb'); + it('instructs to start with a strong verb in the output language', () => { + expect(getTitleGenerationSystemPrompt()).toContain('strong verb'); + expect(getTitleGenerationSystemPrompt()).toContain('output language'); }); it('instructs to return only the raw title text', () => { - expect(TITLE_GENERATION_SYSTEM_PROMPT).toContain('ONLY the raw title text'); + expect(getTitleGenerationSystemPrompt()).toContain('ONLY the raw title text'); + }); + + it('uses one language rule without English verb or title examples', () => { + const prompt = getTitleGenerationSystemPrompt(); + + expect(prompt).toContain("same language as the user's request"); + expect(prompt).toContain('UI locale (`en`)'); + expect(prompt).toContain('proper nouns, product names, file names, paths, code identifiers, and code snippets unchanged'); + expect(prompt).not.toContain('Create, Fix, Debug, Explain, Analyze'); + expect(prompt).not.toContain('Debug Python script'); + expect(prompt).not.toContain('Refactor React hook'); + }); + + it('falls back to the current UI locale', () => { + setLocale('zh-CN'); + + expect(getTitleGenerationSystemPrompt()).toContain('UI locale (`zh-CN`)'); + }); + + it.each([ + ['Chinese', '请修复 useReducer 的状态更新'], + ['English', 'Fix useReducer state updates'], + ['mixed code identifiers', '请修复 Qoderian 中 notes/demo.md 的 useReducer'], + ])('preserves %s request text and identifiers', (_language, request) => { + expect(buildTitleGenerationPrompt(request)).toContain(request); + }); + + it('preserves a Chinese title and its code identifiers', () => { + expect(parseTitleGenerationResponse('修复 Qoderian 的 useReducer')).toBe('修复 Qoderian 的 useReducer'); }); }); diff --git a/tests/unit/qoder/services/qoder-inline-edit-service.test.ts b/tests/unit/qoder/services/qoder-inline-edit-service.test.ts index c260e8c..c4d4a4a 100644 --- a/tests/unit/qoder/services/qoder-inline-edit-service.test.ts +++ b/tests/unit/qoder/services/qoder-inline-edit-service.test.ts @@ -12,6 +12,7 @@ jest.mock('fs'); // Now import after all mocks are set up import { buildCursorContext } from '@/core/editor/editor-context'; +import { getLocale, setLocale } from '@/i18n/i18n'; import { buildInlineEditPrompt, parseInlineEditResponse } from '@/qoder/prompt/inline-edit'; import type { InlineEditRequest } from '@/qoder/services/qoder-inline-edit-service'; import { @@ -46,14 +47,21 @@ const callHook = async (hook: any, input: any, ...rest: any[]): Promise => describe('QoderInlineEditService', () => { let service: QoderInlineEditService; let mockPlugin: any; + let previousLocale: ReturnType; beforeEach(() => { + previousLocale = getLocale(); + setLocale('en'); jest.clearAllMocks(); resetMockMessages(); mockPlugin = createMockPlugin(); service = new QoderInlineEditService(mockPlugin); }); + afterEach(() => { + setLocale(previousLocale); + }); + describe('buildPrompt', () => { it('should build prompt with correct format', () => { @@ -257,6 +265,33 @@ describe('QoderInlineEditService', () => { (fs.existsSync as jest.Mock).mockReturnValue(true); }); + it.each([ + ['Chinese request under English UI', 'en', '请修正这段说明', 'useReducer 更新状态', 'useReducer 更新状态(已修正)', 'useReducer 更新状态(已修正)'], + ['English request under Chinese UI', 'zh-CN', 'Fix this description', 'useReducer updates state', 'useReducer updates state correctly', 'useReducer updates state correctly'], + ['mixed code identifiers', 'en', '保留 Qoderian、notes/demo.md 和 useReducer', 'Qoderian notes/demo.md useReducer', 'Qoderian:notes/demo.md 中的 useReducer 保持不变', 'Qoderian:notes/demo.md 中的 useReducer 保持不变'], + ] as const)('edits text for %s in the request language', async (_name, locale, instruction, selectedText, response, expected) => { + setLocale(locale); + setMockMessages([ + { type: 'system', subtype: 'init', session_id: 'test-session' }, + { + type: 'assistant', + message: { content: [{ type: 'text', text: response }] }, + }, + { type: 'result' }, + ]); + + const result = await service.editText({ + mode: 'selection', + selectedText, + instruction, + notePath: 'notes/demo.md', + }); + + expect(result).toEqual({ success: true, editedText: expected }); + expect(getLastOptions()?.systemPrompt).toContain("same language as the user's request"); + expect(getLastOptions()?.systemPrompt).toContain(`UI locale (\`${locale}\`)`); + }); + it('should return error when vault path cannot be determined', async () => { mockPlugin.app.vault.adapter.basePath = undefined; service = new QoderInlineEditService(mockPlugin); diff --git a/tests/unit/qoder/services/qoder-instruction-refine-service.test.ts b/tests/unit/qoder/services/qoder-instruction-refine-service.test.ts index 9e8f457..aec488c 100644 --- a/tests/unit/qoder/services/qoder-instruction-refine-service.test.ts +++ b/tests/unit/qoder/services/qoder-instruction-refine-service.test.ts @@ -7,6 +7,7 @@ import { } from '@test/__mocks__/qoder-agent-sdk'; // Import after mocks are set up +import { getLocale, setLocale } from '@/i18n/i18n'; import { QoderInstructionRefineService } from '@/qoder/services/qoder-instruction-refine-service'; function createMockPlugin(settings = {}) { @@ -30,15 +31,44 @@ function createMockPlugin(settings = {}) { describe('QoderInstructionRefineService', () => { let service: QoderInstructionRefineService; let mockPlugin: any; + let previousLocale: ReturnType; beforeEach(() => { + previousLocale = getLocale(); + setLocale('en'); jest.clearAllMocks(); resetMockMessages(); mockPlugin = createMockPlugin(); service = new QoderInstructionRefineService(mockPlugin); }); + afterEach(() => { + setLocale(previousLocale); + }); + describe('refineInstruction', () => { + it.each([ + ['Chinese request under English UI', 'en', '请让回答更简洁', '- **简洁性**:回答简短直接。', '- **简洁性**:回答简短直接。'], + ['English request under Chinese UI', 'zh-CN', 'Keep answers concise', '- **Conciseness**: Keep answers brief and direct.', '- **Conciseness**: Keep answers brief and direct.'], + ['mixed code identifiers', 'en', '保留 Qoderian、notes/demo.md 和 useReducer', '- **命名**:保留 Qoderian、notes/demo.md 和 useReducer。', '- **命名**:保留 Qoderian、notes/demo.md 和 useReducer。'], + ] as const)('refines an instruction for %s in the request language', async (_name, locale, rawInstruction, response, expected) => { + setLocale(locale); + setMockMessages([ + { type: 'system', subtype: 'init', session_id: 'test-session' }, + { + type: 'assistant', + message: { content: [{ type: 'text', text: response }] }, + }, + { type: 'result' }, + ]); + + const result = await service.refineInstruction(rawInstruction, ''); + + expect(result).toEqual({ success: true, refinedInstruction: expected }); + expect(getLastOptions()?.systemPrompt).toContain("same language as the user's request"); + expect(getLastOptions()?.systemPrompt).toContain(`UI locale (\`${locale}\`)`); + }); + it('should use no tools (text-only refinement)', async () => { setMockMessages([ { type: 'system', subtype: 'init', session_id: 'test-session' }, diff --git a/tests/unit/qoder/services/qoder-title-generation-service.test.ts b/tests/unit/qoder/services/qoder-title-generation-service.test.ts index b88d6f8..e732cc5 100644 --- a/tests/unit/qoder/services/qoder-title-generation-service.test.ts +++ b/tests/unit/qoder/services/qoder-title-generation-service.test.ts @@ -6,6 +6,7 @@ import { setMockMessages, } from '@test/__mocks__/qoder-agent-sdk'; +import { getLocale, setLocale } from '@/i18n/i18n'; import { QoderTitleGenerationService,type TitleGenerationResult } from '@/qoder/services/qoder-title-generation-service'; function createMockPlugin(settings = {}) { return { @@ -28,15 +29,45 @@ function createMockPlugin(settings = {}) { describe('QoderTitleGenerationService', () => { let service: QoderTitleGenerationService; let mockPlugin: any; + let previousLocale: ReturnType; beforeEach(() => { + previousLocale = getLocale(); + setLocale('en'); jest.clearAllMocks(); resetMockMessages(); mockPlugin = createMockPlugin(); service = new QoderTitleGenerationService(mockPlugin); }); + afterEach(() => { + setLocale(previousLocale); + }); + describe('generateTitle', () => { + it.each([ + ['Chinese request under English UI', 'en', '请修复 useReducer 的状态更新', '修复 useReducer 状态更新'], + ['English request under Chinese UI', 'zh-CN', 'Fix useReducer state updates', 'Fix useReducer state updates'], + ['mixed code identifiers', 'en', '请修复 Qoderian 中 notes/demo.md 的 useReducer', '修复 Qoderian 的 useReducer'], + ] as const)('generates a title for %s in the request language', async (_name, locale, request, title) => { + setLocale(locale); + setMockMessages([ + { type: 'system', subtype: 'init', session_id: 'test-session' }, + { + type: 'assistant', + message: { content: [{ type: 'text', text: title }] }, + }, + { type: 'result' }, + ]); + + const callback = jest.fn(); + await service.generateTitle('conv-123', request, callback); + + expect(callback).toHaveBeenCalledWith('conv-123', { success: true, title }); + expect(getLastOptions()?.systemPrompt).toContain("same language as the user's request"); + expect(getLastOptions()?.systemPrompt).toContain(`UI locale (\`${locale}\`)`); + }); + it('should generate a title from user message', async () => { setMockMessages([ { type: 'system', subtype: 'init', session_id: 'test-session' },