From b1907fae23e43c44d1c0e794bcf849317d80a357 Mon Sep 17 00:00:00 2001 From: Liuxinyu176 <1041316040@qq.com> Date: Sat, 10 Oct 2026 10:26:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(settings):=20=E6=B5=8B=E8=AF=95=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E8=B7=9F=E9=9A=8F=E5=BD=93=E5=89=8D=E9=80=89=E4=B8=AD?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E5=8C=BA=E5=9F=9F=EF=BC=8C=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E5=9B=BA=E5=AE=9A=E5=9B=BD=E5=86=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../token/ui/settings/SettingsViewModel.kt | 62 ++++++++++++------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/rainy/token/ui/settings/SettingsViewModel.kt b/app/src/main/java/com/rainy/token/ui/settings/SettingsViewModel.kt index b8c1357..6241ef4 100644 --- a/app/src/main/java/com/rainy/token/ui/settings/SettingsViewModel.kt +++ b/app/src/main/java/com/rainy/token/ui/settings/SettingsViewModel.kt @@ -132,61 +132,75 @@ class SettingsViewModel @Inject constructor( } } - /** 用 Trae CN 默认账号发一条 stream=true 测试。 */ + /** 用当前选中的 Trae 目标发一条 stream=true 测试(未选 Trae 时兜底 CN)。 */ fun testTraeStream() { + val target = _selectedProxy.value + val region = when (target) { + ProxyTarget.TRAE_CN, ProxyTarget.TRAE_INTL -> target.region() + else -> ProviderRegion.CN + } + val intl = region == ProviderRegion.INTL viewModelScope.launch { - _proxyDebug.value = "正在请求 Trae CN 流..." + _proxyDebug.value = if (intl) "正在请求 Trae INTL 流..." else "正在请求 Trae CN 流..." _proxyDebugRaw.value = null - val model = traeModelProvider.selectedFor(ProviderRegion.CN) + val model = traeModelProvider.selectedFor(region) val body = """{"model":"$model","stream":true,"messages":[{"role":"user","content":"只回复OK两个字"}],"max_tokens":100}""" + val requestLine = if (intl) { + "POST https://core-normal.trae.ai/api/agent/v3/llm_utils_chat" + } else { + "POST https://trae-api-cn.mchost.guru/api/agent/v3/llm_utils_chat" + } try { - val stream = traeChatProxy.openStreamingChat(body, null, ProviderRegion.CN) + val stream = traeChatProxy.openStreamingChat(body, null, region) if (stream == null) { - _proxyDebug.value = "Trae CN 未配置或未登录" + _proxyDebug.value = if (intl) "Trae INTL 未配置或未登录" else "Trae CN 未配置或未登录" return@launch } - val result = readStreamSample( - stream, - "Trae CN", - body, - "POST https://trae-api-cn.mchost.guru/api/agent/v3/llm_utils_chat" - ) + val label = if (intl) "Trae INTL" else "Trae CN" + val result = readStreamSample(stream, label, body, requestLine) _proxyDebug.value = result.summary _proxyDebugRaw.value = result.raw } catch (e: kotlinx.coroutines.CancellationException) { throw e } catch (e: Exception) { - _proxyDebug.value = "Trae CN 异常:" + (e.message ?: "未知错误") + _proxyDebug.value = (if (intl) "Trae INTL" else "Trae CN") + " 异常:" + (e.message ?: "未知错误") _proxyDebugRaw.value = null } } } - /** 用 WorkBuddy CN 默认账号发一条 stream=true 测试。 */ + /** 用当前选中的 WorkBuddy 目标发一条 stream=true 测试(未选 WorkBuddy 时兜底 CN)。 */ fun testWorkBuddyStream() { + val target = _selectedProxy.value + val region = when (target) { + ProxyTarget.WORKBUDDY_CN, ProxyTarget.WORKBUDDY_INTL -> target.region() + else -> ProviderRegion.CN + } + val intl = region == ProviderRegion.INTL viewModelScope.launch { - _proxyDebug.value = "正在请求 WorkBuddy CN 流..." + _proxyDebug.value = if (intl) "正在请求 WorkBuddy INTL 流..." else "正在请求 WorkBuddy CN 流..." _proxyDebugRaw.value = null - val model = workBuddyModelProvider.selectedFor(ProviderRegion.CN) + val model = workBuddyModelProvider.selectedFor(region) val body = """{"model":"$model","stream":true,"messages":[{"role":"user","content":"只回复OK两个字"}],"max_tokens":100}""" + val requestLine = if (intl) { + "POST https://www.workbuddy.ai/console/chat/completions" + } else { + "POST https://copilot.tencent.com/v2/chat/completions" + } try { - val stream = workBuddyChatProxy.openStreamingChat(body, null, ProviderRegion.CN) + val stream = workBuddyChatProxy.openStreamingChat(body, null, region) if (stream == null) { - _proxyDebug.value = "WorkBuddy CN 未配置或未登录" + _proxyDebug.value = if (intl) "WorkBuddy INTL 未配置或未登录" else "WorkBuddy CN 未配置或未登录" return@launch } - val result = readStreamSample( - stream, - "WorkBuddy CN", - body, - "POST https://copilot.tencent.com/v2/chat/completions" - ) + val label = if (intl) "WorkBuddy INTL" else "WorkBuddy CN" + val result = readStreamSample(stream, label, body, requestLine) _proxyDebug.value = result.summary _proxyDebugRaw.value = result.raw } catch (e: kotlinx.coroutines.CancellationException) { throw e } catch (e: Exception) { - _proxyDebug.value = "WorkBuddy CN 异常:" + (e.message ?: "未知错误") + _proxyDebug.value = (if (intl) "WorkBuddy INTL" else "WorkBuddy CN") + " 异常:" + (e.message ?: "未知错误") _proxyDebugRaw.value = null } }