Skip to content

Commit b526451

Browse files
fix(i18n): tighten producer code boundaries
Generated-by: OpenCode
1 parent 3f3c2fa commit b526451

12 files changed

Lines changed: 28 additions & 62 deletions

File tree

apps/desktop/src/main/__tests__/oauth-result-copy.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ import test from "node:test";
2323
// `node --test "dist/main/**/*.test.js"`, and settings-provider-copy is a pure
2424
// copy module (no react), so it is safe to exercise from node. Same precedent
2525
// as permission-center-copy.test.ts.
26-
import { subscriptionResultMessage } from "../../renderer/features/connection-settings/index.js";
26+
import {
27+
connectionTestFailureMessage,
28+
subscriptionResultMessage,
29+
} from "../../renderer/features/connection-settings/index.js";
2730

2831
test("renders a coded Copilot import failure per locale, ignoring its machine message", () => {
2932
const result = { code: "copilot_subscription_unavailable", message: "copilot_subscription_unavailable" };
@@ -42,3 +45,16 @@ test("falls back to catalog copy for an unknown code instead of the raw message"
4245
assert.equal(subscriptionResultMessage(result, "fallback", "en"), "fallback");
4346
assert.equal(subscriptionResultMessage(result, "fallback", "zh"), "fallback");
4447
});
48+
49+
test("renders provider rate limits consistently from the stable status code", () => {
50+
const result = { ok: false, statusCode: 429, errorClass: "provider_unavailable" } as const;
51+
const troubleshooting = { auth: "auth", recheck: "recheck" };
52+
assert.equal(
53+
connectionTestFailureMessage(result, troubleshooting, "zh"),
54+
"当前账号或模型服务触发速率限制,请稍后重试。",
55+
);
56+
assert.equal(
57+
connectionTestFailureMessage(result, troubleshooting, "en"),
58+
"This account or model service is rate-limited. Try again later.",
59+
);
60+
});

apps/desktop/src/main/__tests__/settings-test-result-copy.test.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,3 @@ test("missing proxy credentials have actionable bilingual copy", () => {
3737
"Proxy authentication is enabled. Enter a proxy password before testing.",
3838
);
3939
});
40-
41-
test("renders the disabled-direct proxy code per locale", () => {
42-
const result = { ok: true, code: "proxy_disabled_direct", message: "direct" } as never;
43-
assert.equal(settingsTestResultMessage(result, "zh"), "代理未启用,当前会直接连接。");
44-
assert.equal(
45-
settingsTestResultMessage(result, "en"),
46-
"The proxy is disabled; connections go direct.",
47-
);
48-
});
49-

apps/desktop/src/main/capability-snapshot.ts

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import { Notification, systemPreferences } from 'electron';
2121
import { BOT_PROVIDERS, type BotProvider } from '@maka/core/bot-chat-settings';
22-
import { redactSecrets } from '@maka/core/redaction';
2322
import {
2423
deriveCapabilityReadiness,
2524
runtimeProbeFromBotReadiness,
@@ -140,7 +139,7 @@ function computerUseCapability(
140139
feature: {
141140
state: artifactAvailable ? 'enabled' : 'not_available',
142141
source: 'runtime',
143-
reason: computerUseCapabilityReason(input),
142+
reason: input === undefined || input.backendId === 'none' ? 'cu_artifact_missing' : 'cu_backend_status',
144143
},
145144
requiredPermissions: [
146145
{ id: 'accessibility', required: true, status: permissions.accessibility.status },
@@ -160,22 +159,6 @@ function computerUseCapability(
160159
});
161160
}
162161

163-
// The presenter composes the full 'cu_backend_status' sentence from data the
164-
// same snapshot already carries (required-permission statuses and the runtime
165-
// probe state), so the reason stays a bare code. The backend name is not
166-
// threaded through: CU_BACKEND_IDS is ['maka-cu'] today.
167-
function computerUseCapabilityReason(
168-
input: {
169-
backendId: CuBackendId | 'none';
170-
health: ReturnType<typeof computerUseServiceHealth>;
171-
} | undefined,
172-
): string {
173-
if (input === undefined || input.backendId === 'none') {
174-
return 'cu_artifact_missing';
175-
}
176-
return 'cu_backend_status';
177-
}
178-
179162
function staticCapability(input: {
180163
id: CapabilitySnapshot['id'];
181164
label: string;
@@ -268,8 +251,8 @@ function accessibilitySnapshot(now: number, platform: NodeJS.Platform): OsPermis
268251
canOpenSettings: true,
269252
canRequest: false,
270253
};
271-
} catch (error) {
272-
return unknownPermission('accessibility', now, error, true);
254+
} catch {
255+
return unknownPermission('accessibility', now, true);
273256
}
274257
}
275258

@@ -292,8 +275,8 @@ function mediaPermissionSnapshot(
292275
checkedAt: now,
293276
...actions,
294277
};
295-
} catch (error) {
296-
return unknownPermission(id, now, error, platform === 'darwin');
278+
} catch {
279+
return unknownPermission(id, now, platform === 'darwin');
297280
}
298281
}
299282

@@ -349,7 +332,6 @@ function unsupportedPermission(
349332
function unknownPermission(
350333
id: OsPermissionId,
351334
now: number,
352-
error: unknown,
353335
canOpenSettings: boolean,
354336
): OsPermissionSnapshot {
355337
return {
@@ -358,10 +340,6 @@ function unknownPermission(
358340
source: 'electron',
359341
checkedAt: now,
360342
reason: 'permission_probe_failed',
361-
// Raw probe error text passes through as diagnostic detail, redacted at
362-
// the producer so every presenter can render it verbatim beside the
363-
// localized 'permission_probe_failed' copy.
364-
...(error instanceof Error && error.message ? { detail: redactSecrets(error.message) } : {}),
365343
canOpenSettings,
366344
canRequest: false,
367345
};

apps/desktop/src/main/computer-use-host.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
selectComputerUseBackend,
3535
type SelectedComputerUseBackend,
3636
} from '@maka/computer-use';
37+
import type { CapabilityReasonCode } from '@maka/core/capabilities';
3738
import type { CuOverlayHook } from '@maka/runtime/computer-use-types';
3839

3940
export interface ComputerUseHostState {
@@ -147,7 +148,7 @@ export function computerUseServiceHealth(
147148
state: MakaCuServiceSnapshot | undefined,
148149
): {
149150
state: 'not_available' | 'not_run' | 'healthy' | 'degraded';
150-
reason: string;
151+
reason: CapabilityReasonCode;
151152
} {
152153
if (backendId === 'none' || !state) {
153154
return { state: 'not_available', reason: 'cu_executor_undistributable' };

apps/desktop/src/renderer/features/connection-settings/provider-panel-shared.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ export function connectionTestFailureFallback(
6969
locale: UiLocale,
7070
): string {
7171
const shared = getProviderSettingsCopy(locale).shared;
72-
if (result.errorCode === 'oauth_rate_limited') return shared.oauthRateLimit;
7372
if (result.statusCode === 429) return shared.rateLimit;
7473
if (result.errorClass === 'timeout') return shared.timeout;
7574
if (result.errorClass === 'auth' || result.statusCode === 401 || result.statusCode === 403) {
@@ -88,9 +87,7 @@ export function connectionTestFailureMessage(
8887
locale: UiLocale,
8988
): string {
9089
const fallback = connectionTestFailureFallback(result, copy, locale);
91-
// A coded result already resolved to specific per-locale copy above; the
92-
// errorMessage is only its machine-readable twin.
93-
if (result.errorCode || !result.errorMessage) return fallback;
90+
if (!result.errorMessage) return fallback;
9491
return locale === 'zh'
9592
? generalizedErrorMessageChinese(new Error(result.errorMessage), fallback)
9693
: generalizedErrorMessage(new Error(result.errorMessage), fallback);

apps/desktop/src/renderer/features/connection-settings/settings-provider-copy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ const zhCopy = {
158158
modelKeyAria: (name: string) => `${name} 模型密钥`,
159159
},
160160
shared: {
161-
actionFallback: '模型连接服务暂时不可用,请稍后重试。', rateLimit: '当前账号或模型服务触发速率限制,请稍后重试。', oauthRateLimit: 'OAuth 已登录,但当前账号或 provider 正在 rate limit。请稍后重试,或先切换到其它可用模型。',
161+
actionFallback: '模型连接服务暂时不可用,请稍后重试。', rateLimit: '当前账号或模型服务触发速率限制,请稍后重试。',
162162
timeout: '请求超时,请检查网络或代理后重试。', unavailable: '模型服务暂时不可用,请稍后重试。',
163163
network: '网络错误,请检查服务地址或代理设置后重试。', statusUnavailable: '连接测试状态暂时无法显示,请重新测试。',
164164
categories: { oauth: 'OAuth', domestic: '国内', overseas: '海外', local: '本地', custom: 'Custom' },
@@ -332,7 +332,7 @@ const enCopy: ProviderSettingsCopy = {
332332
modelKeyAria: (name: string) => `${name} model key`,
333333
},
334334
shared: {
335-
actionFallback: 'The model connection service is temporarily unavailable. Try again later.', rateLimit: 'This account or model service is rate-limited. Try again later.', oauthRateLimit: 'Signed in, but the account or provider is currently rate limited. Retry later or switch to another available model.',
335+
actionFallback: 'The model connection service is temporarily unavailable. Try again later.', rateLimit: 'This account or model service is rate-limited. Try again later.',
336336
timeout: 'The request timed out. Check the network or proxy and try again.', unavailable: 'The model service is temporarily unavailable. Try again later.',
337337
network: 'Network error. Check the service URL or proxy settings and try again.', statusUnavailable: 'The connection test status is temporarily unavailable. Test again.',
338338
categories: { oauth: 'OAuth', domestic: 'China', overseas: 'Global', local: 'Local', custom: 'Custom' },

apps/desktop/src/renderer/locales/settings-test-result-copy.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ type SettingsTestResultCopy = {
2828
location: string | undefined,
2929
) => string;
3030
disabled: string;
31-
disabledDirect: string;
3231
configurationMissing: string;
3332
credentialMissing: string;
3433
timeout: string;
@@ -50,7 +49,6 @@ const COPY = {
5049
reachable: (endpoint, location) =>
5150
["代理配置有效", endpoint, location].filter(Boolean).join(" · "),
5251
disabled: "请先启用代理服务器,再进行测试。",
53-
disabledDirect: "代理未启用,当前会直接连接。",
5452
configurationMissing: "请填写代理服务器地址和端口后再测试。",
5553
credentialMissing: "代理认证已开启,请输入代理密码后再测试。",
5654
timeout: "代理测试超时,请检查代理服务是否可达。",
@@ -78,7 +76,6 @@ const COPY = {
7876
.filter(Boolean)
7977
.join(" · "),
8078
disabled: "Enable the proxy server before testing it.",
81-
disabledDirect: "The proxy is disabled; connections go direct.",
8279
configurationMissing: "Enter a proxy host and port before testing it.",
8380
credentialMissing:
8481
"Proxy authentication is enabled. Enter a proxy password before testing.",
@@ -120,8 +117,6 @@ export function settingsTestResultMessage(
120117
);
121118
case "proxy_disabled":
122119
return copy.proxy.disabled;
123-
case "proxy_disabled_direct":
124-
return copy.proxy.disabledDirect;
125120
case "proxy_configuration_missing":
126121
return copy.proxy.configurationMissing;
127122
case "proxy_credential_missing":

apps/desktop/src/renderer/settings/permission-center-page.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -744,10 +744,7 @@ function osPermissionReasonText(
744744
? copy.reasons[snapshot.reason]
745745
: copy.reasonFallback
746746
: undefined;
747-
// `detail` is redacted probe diagnostics from the producer and renders
748-
// verbatim beside the copy.
749-
if (!text) return snapshot.detail;
750-
return snapshot.detail ? `${text} · ${snapshot.detail}` : text;
747+
return text;
751748
}
752749

753750
function featureTone(state: CapabilitySnapshot['feature']['state']): StatusSemantic {

packages/core/src/capabilities.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ export interface OsPermissionSnapshot {
150150
source: 'electron' | 'platform' | 'static';
151151
checkedAt: number;
152152
reason?: string;
153-
/** Raw diagnostic pass-through (external error text), rendered verbatim. */
154-
detail?: string;
155153
canOpenSettings: boolean;
156154
canRequest: boolean;
157155
}

packages/core/src/llm-connections.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,6 @@ export interface ConnectionTestResult {
531531
errorMessage?: string;
532532
statusCode?: number;
533533
errorClass?: ConnectionTestErrorClass;
534-
/** Stable machine code the presenter maps to per-locale copy. */
535-
errorCode?: 'oauth_rate_limited';
536534
}
537535

538536
/**

0 commit comments

Comments
 (0)