-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat(daemon): add POST /session/:id/language for runtime language switching #4705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: daemon_mode_b_main
Are you sure you want to change the base?
Changes from all commits
125d49e
d5e5a9d
af375f4
e636b2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -102,6 +102,13 @@ import { | |||||||||||||||
| } from '../utils/acpModelUtils.js'; | ||||||||||||||||
| import { runWithAcpRuntimeOutputDir } from './runtimeOutputDirContext.js'; | ||||||||||||||||
| import { runExitCleanup } from '../utils/cleanup.js'; | ||||||||||||||||
| import { setLanguageAsync, getCurrentLanguage } from '../i18n/index.js'; | ||||||||||||||||
| import { | ||||||||||||||||
| resolveOutputLanguage, | ||||||||||||||||
| updateOutputLanguageFile, | ||||||||||||||||
| isAutoLanguage, | ||||||||||||||||
| OUTPUT_LANGUAGE_AUTO, | ||||||||||||||||
| } from '../utils/languageUtils.js'; | ||||||||||||||||
| import { | ||||||||||||||||
| ACP_PREFLIGHT_KINDS, | ||||||||||||||||
| STATUS_SCHEMA_VERSION, | ||||||||||||||||
|
|
@@ -2516,6 +2523,87 @@ class QwenAgent implements Agent { | |||||||||||||||
| const current = config.getApprovalMode(); | ||||||||||||||||
| return { previous, current }; | ||||||||||||||||
| } | ||||||||||||||||
| case SERVE_CONTROL_EXT_METHODS.sessionLanguage: { | ||||||||||||||||
|
chiga0 marked this conversation as resolved.
|
||||||||||||||||
| const sessionId = params['sessionId']; | ||||||||||||||||
| const language = params['language']; | ||||||||||||||||
| const syncOutputLanguage = params['syncOutputLanguage'] === true; | ||||||||||||||||
|
|
||||||||||||||||
| if (typeof sessionId !== 'string' || sessionId.length === 0) { | ||||||||||||||||
| throw RequestError.invalidParams( | ||||||||||||||||
| undefined, | ||||||||||||||||
| 'Invalid or missing sessionId', | ||||||||||||||||
| ); | ||||||||||||||||
| } | ||||||||||||||||
| if (typeof language !== 'string' || !language) { | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] The language validation here only checks for non-empty string, but does not validate against the allowed Direct extMethod callers (bypassing the HTTP route) can pass arbitrary strings, which
Suggested change
— qwen3.7-max via Qwen Code /review |
||||||||||||||||
| throw RequestError.invalidParams( | ||||||||||||||||
| undefined, | ||||||||||||||||
| 'Invalid or missing language', | ||||||||||||||||
| ); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| this.sessionOrThrow(sessionId); | ||||||||||||||||
|
|
||||||||||||||||
| try { | ||||||||||||||||
| await setLanguageAsync(language); | ||||||||||||||||
| } catch (err) { | ||||||||||||||||
| debugLogger.warn('setLanguageAsync failed:', err); | ||||||||||||||||
| throw new RequestError( | ||||||||||||||||
| -32603, | ||||||||||||||||
| `Failed to switch UI language: ${err instanceof Error ? err.message : String(err)}`, | ||||||||||||||||
| ); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| const resolvedLanguage = getCurrentLanguage(); | ||||||||||||||||
|
|
||||||||||||||||
|
chiga0 marked this conversation as resolved.
|
||||||||||||||||
| try { | ||||||||||||||||
| this.settings.setValue( | ||||||||||||||||
| SettingScope.User, | ||||||||||||||||
| 'general.language', | ||||||||||||||||
| language, | ||||||||||||||||
| ); | ||||||||||||||||
| } catch (err) { | ||||||||||||||||
| debugLogger.warn('Failed to persist UI language setting:', err); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| let outputLanguage: string | null = null; | ||||||||||||||||
| let refreshed = false; | ||||||||||||||||
|
|
||||||||||||||||
| if (syncOutputLanguage) { | ||||||||||||||||
| const resolved = resolveOutputLanguage(language); | ||||||||||||||||
| const settingValue = isAutoLanguage(language) | ||||||||||||||||
| ? OUTPUT_LANGUAGE_AUTO | ||||||||||||||||
| : resolved; | ||||||||||||||||
|
|
||||||||||||||||
| try { | ||||||||||||||||
| updateOutputLanguageFile(settingValue); | ||||||||||||||||
| } catch (err) { | ||||||||||||||||
| debugLogger.warn('Failed to write output-language.md:', err); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| try { | ||||||||||||||||
| this.settings.setValue( | ||||||||||||||||
| SettingScope.User, | ||||||||||||||||
| 'general.outputLanguage', | ||||||||||||||||
| settingValue, | ||||||||||||||||
| ); | ||||||||||||||||
| } catch (err) { | ||||||||||||||||
| debugLogger.warn('Failed to persist output language setting:', err); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| const allSessions = [...this.sessions.values()]; | ||||||||||||||||
| await Promise.allSettled( | ||||||||||||||||
|
chiga0 marked this conversation as resolved.
|
||||||||||||||||
| allSessions.map(async (s) => { | ||||||||||||||||
| const cfg = s.getConfig(); | ||||||||||||||||
| await cfg.refreshHierarchicalMemory(); | ||||||||||||||||
| await cfg.getGeminiClient()?.refreshSystemInstruction(); | ||||||||||||||||
| }), | ||||||||||||||||
| ); | ||||||||||||||||
| refreshed = true; | ||||||||||||||||
|
chiga0 marked this conversation as resolved.
|
||||||||||||||||
| outputLanguage = resolved; | ||||||||||||||||
| } | ||||||||||||||||
|
chiga0 marked this conversation as resolved.
|
||||||||||||||||
|
|
||||||||||||||||
| return { language: resolvedLanguage, outputLanguage, refreshed }; | ||||||||||||||||
| } | ||||||||||||||||
| case SERVE_CONTROL_EXT_METHODS.sessionRecap: { | ||||||||||||||||
| // #4175 follow-up. Generate a one-sentence "where did I leave | ||||||||||||||||
| // off" summary by running `generateSessionRecap` against the | ||||||||||||||||
|
|
||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.