Repository navigation
Expand file tree
/
Copy pathaccountDisplay.ts
More file actions
126 lines (122 loc) · 4.69 KB
/
Copy pathaccountDisplay.ts
File metadata and controls
126 lines (122 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import * as uiMessages from "./messages";
import type { Translate } from "./types";
export function accountError(code: string | null | undefined, t: Translate) {
if (!code) return "";
const labels: Record<string, [string, string]> = {
login_required: ["请重新登录此账号。", "Sign in to this account again."],
auth_expired: [
"登录已失效,请重新登录。",
"Sign-in expired. Sign in again.",
],
rate_limited: [
"请求已达限额,请等待额度恢复或选择其他账号。",
"The request limit was reached. Wait for it to reset or choose another account.",
],
quota_exhausted: [
"当前额度已用完,请等待恢复或选择其他账号。",
"Quota is exhausted. Wait for it to reset or choose another account.",
],
account_unavailable: [
"此账号暂不可用,请检查登录或选择其他账号。",
"This account is unavailable. Check its sign-in or choose another account.",
],
login_start_failed: [
"无法启动登录,请检查所选设备的连接和 CLI 安装。",
"Could not start sign-in. Check the device connection and CLI installation.",
],
login_worker_stopped: [
"登录进程已结束,请重新发起登录。",
"The sign-in process stopped. Start sign-in again.",
],
login_timeout: [
"登录等待已超时,请重新发起登录。",
"Sign-in timed out. Start sign-in again.",
],
login_not_confirmed: [
"未确认登录成功,请完成浏览器授权后重试。",
"Sign-in was not confirmed. Complete browser authorization and retry.",
],
native_login_failed: [
"CLI 登录未成功,请重新登录。",
"CLI sign-in failed. Sign in again.",
],
quota_unavailable: [
"当前无法读取订阅额度。",
"Subscription quota is currently unavailable.",
],
network_unavailable: [
"无法通过现有网络配置读取额度,请检查代理连接。",
"Cannot read quota through the existing network configuration. Check the proxy connection.",
],
network_configuration_unavailable: [
"无法确认 CLI 的网络配置,额度查询已停止;现有 CLI 不受影响。",
"Could not establish the CLI network configuration. Quota queries are stopped; the existing CLI is unaffected.",
],
};
const label = labels[code];
return label
? t(label[0], label[1])
: t(
...uiMessages.accountdisplay_the_account_action_did_not_complete_check_the_ec74ad,
);
}
export function resetCountdown(value: string, now: number, t: Translate) {
const timestamp = Date.parse(value);
if (!Number.isFinite(timestamp))
return t(...uiMessages.accountdisplay_reset_time_unknown_c6be26);
const minutes = Math.ceil((timestamp - now) / 60_000);
if (minutes <= 0)
return t(
...uiMessages.accountdisplay_reset_time_reached_refresh_to_check_262c14,
);
const days = Math.floor(minutes / 1440);
const hours = Math.floor((minutes % 1440) / 60);
const rest = minutes % 60;
const duration = [
days ? t(`${days} 天`, `${days}d`) : "",
hours ? t(`${hours} 小时`, `${hours}h`) : "",
rest ? t(`${rest} 分钟`, `${rest}m`) : "",
]
.filter(Boolean)
.join(" ");
return t(`${duration}后恢复`, `Resets in ${duration}`);
}
export function quotaWindow(
window: { name?: string; label?: string; duration_minutes?: number },
t: Translate,
) {
if (window.name === "weekly_sonnet")
return t(...uiMessages.accountdisplay_sonnet_7_day_limit_bc45b0);
if (window.name === "weekly_opus")
return t(...uiMessages.accountdisplay_opus_7_day_limit_42d58b);
const minutes = window.duration_minutes;
if (minutes && minutes > 0) {
if (minutes % 1440 === 0)
return t(`${minutes / 1440} 天额度`, `${minutes / 1440}-day limit`);
if (minutes % 60 === 0)
return t(`${minutes / 60} 小时额度`, `${minutes / 60}-hour limit`);
return t(`${minutes} 分钟额度`, `${minutes}-minute limit`);
}
return (
window.label ??
(
{
session: t(...uiMessages.accountdisplay_5_hour_limit_bf2ba5),
weekly: t(...uiMessages.accountdisplay_7_day_limit_679107),
daily: t(...uiMessages.accountdisplay_daily_limit_464b47),
} as Record<string, string>
)[window.name ?? ""] ??
t(...uiMessages.accountdisplay_usage_limit_e26f7d)
);
}
export function quotaSource(
source: string | undefined,
sampledAt: string | undefined,
t: Translate,
) {
if (source === "legacy_snapshot" || source === "claude-desktop-snapshot")
return t(...uiMessages.quota_source_legacy);
return sampledAt
? t(...uiMessages.quota_source_last_run)
: t(...uiMessages.quota_source_waiting);
}