@chen_hu_hu/pi-qq 1.3.2 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -1
- package/README-zh.md +13 -10
- package/README.md +13 -10
- package/doc/bugfix-v4.md +698 -0
- package/doc/enhance-status.md +427 -0
- package/index.ts +40 -31
- package/package.json +1 -1
- package/src/attachments/attachment-download.ts +13 -8
- package/src/attachments/attachment-failure.ts +4 -2
- package/src/attachments/file-attachments.ts +11 -4
- package/src/infra/file-logger.ts +6 -2
- package/src/infra/i18n.ts +525 -0
- package/src/infra/power-status.ts +116 -0
- package/src/infra/settings.ts +28 -8
- package/src/qq/inbound-attachments.ts +2 -1
- package/src/qq/inbound-command.ts +40 -14
- package/src/qq/qq-bot.ts +4 -7
- package/src/qq/qq-diagnostics.ts +28 -21
- package/src/qq/qq-message-handler.ts +26 -3
- package/src/qq/qr-login.ts +9 -8
- package/src/qq/reply-sender.ts +27 -3
- package/src/qq/status-report.ts +112 -0
- package/src/quota/reply-quota-report.ts +36 -8
- package/src/relay/bubble-writer.ts +35 -3
- package/src/relay/run-stream-relay.ts +44 -7
- package/src/relay/stream-block-format.ts +6 -2
- package/src/relay/stream-session.ts +3 -4
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
export type Language = "zh-cn" | "en-us";
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_LANGUAGE: Language = "zh-cn";
|
|
4
|
+
|
|
5
|
+
export function isLanguage(value: unknown): value is Language {
|
|
6
|
+
return value === "zh-cn" || value === "en-us";
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const enUS = {
|
|
10
|
+
"status.title": "pi-qq status",
|
|
11
|
+
"status.separator": ": ",
|
|
12
|
+
"status.detail": " ({detail})",
|
|
13
|
+
"status.login": "Login",
|
|
14
|
+
"status.loginValue": "QR login (AppID {appId})",
|
|
15
|
+
"status.notLoggedIn": "not logged in",
|
|
16
|
+
"status.connection": "Connection",
|
|
17
|
+
"status.state.connected": "connected",
|
|
18
|
+
"status.state.reconnecting": "reconnecting",
|
|
19
|
+
"status.state.stopped": "stopped",
|
|
20
|
+
"status.state.starting": "starting",
|
|
21
|
+
"status.state.blocked": "blocked",
|
|
22
|
+
"status.agent": "Agent",
|
|
23
|
+
"status.agent.runningQQ": "running (QQ)",
|
|
24
|
+
"status.agent.runningLocal": "running (local)",
|
|
25
|
+
"status.agent.completed": "completed",
|
|
26
|
+
"status.model": "Model",
|
|
27
|
+
"status.context": "Context",
|
|
28
|
+
"status.contextValue": "{tokens}/{window} ({percent}%)",
|
|
29
|
+
"status.unknown": "unknown",
|
|
30
|
+
"status.qqUser": "QQ user",
|
|
31
|
+
"status.battery": "Battery",
|
|
32
|
+
"status.batteryCharging": "{percent}% (charging)",
|
|
33
|
+
"status.batteryDischarging": "{percent}% (discharging)",
|
|
34
|
+
"status.batteryAc": "{percent}% (AC)",
|
|
35
|
+
"status.batteryAcNoPercent": "AC",
|
|
36
|
+
"status.batteryChargingNoPercent": "charging",
|
|
37
|
+
"status.batteryDischargingNoPercent": "discharging",
|
|
38
|
+
"status.settings": "Settings",
|
|
39
|
+
"status.none": "none",
|
|
40
|
+
|
|
41
|
+
"commands.descQqLogin": "pi-qq: log in with a QR code and bind the scanning QQ user",
|
|
42
|
+
"commands.descQqStatus": "pi-qq: show login, connection, agent, battery, and bound QQ user",
|
|
43
|
+
"commands.descQqLogout": "pi-qq: log out and clear credentials",
|
|
44
|
+
"commands.descQqNew": "pi-qq: reset the current session (used by QQ /new)",
|
|
45
|
+
"commands.help.title": "pi-qq commands:",
|
|
46
|
+
"commands.help.stop": "• /stop — abort the current task",
|
|
47
|
+
"commands.help.compact": "• /compact — compact the context",
|
|
48
|
+
"commands.help.status": "• /status — show agent, battery, and context status",
|
|
49
|
+
"commands.help.last": "• /last — push the last completed message or restart current output",
|
|
50
|
+
"commands.help.new": "• /new — reset the session",
|
|
51
|
+
"commands.help.help": "• /help — this help",
|
|
52
|
+
"commands.help.other": "Other text is sent to pi.",
|
|
53
|
+
"commands.stop.none": "No task is running.",
|
|
54
|
+
"commands.stop.abort": "Abort requested.",
|
|
55
|
+
"commands.compact.done": "Context compaction triggered.",
|
|
56
|
+
"commands.compact.busy": "Task is running; use /stop before /compact.",
|
|
57
|
+
"commands.last.none": "No completed message yet.",
|
|
58
|
+
"commands.new.busy": "Task is running; use /stop before resetting.",
|
|
59
|
+
"commands.new.resetting": "Resetting the session…",
|
|
60
|
+
"commands.unknown": "Unknown command {cmd}; use /help.",
|
|
61
|
+
|
|
62
|
+
"inbound.unsupported": "Unsupported message type.",
|
|
63
|
+
"inbound.voiceFailed": "Could not transcribe this voice message; please resend or type it.",
|
|
64
|
+
"attachments.failedMany": "⚠️ {failed} attachment(s) failed ({success} succeeded):",
|
|
65
|
+
"attachments.failedNone": "⚠️ Attachment failed:",
|
|
66
|
+
"attachments.tooLarge": "{kind} too large ({size} > {limit})",
|
|
67
|
+
"attachments.tooLargeShort": "{kind} too large (> {limit})",
|
|
68
|
+
"attachments.empty": "empty {kind} content",
|
|
69
|
+
"attachments.invalidUrl": "invalid {kind} URL",
|
|
70
|
+
"attachments.unsupportedProtocol": "unsupported {kind} URL protocol",
|
|
71
|
+
"attachments.httpFailed": "download failed (HTTP {status})",
|
|
72
|
+
"attachments.timeout": "download timed out after {seconds}s",
|
|
73
|
+
"attachments.noUniqueName": "Could not allocate a unique filename",
|
|
74
|
+
"attachments.fileTooLarge": "file too large ({size} > {limit})",
|
|
75
|
+
"attachments.downloadFailed": "Download failed",
|
|
76
|
+
"attachments.kindFile": "file",
|
|
77
|
+
|
|
78
|
+
"bot.fatalClose":
|
|
79
|
+
"Connection closed by the server ({code}, 4914=offline/sandbox, 4915=banned). Check the bot status on the QQ Open Platform, or run /qq-login again.",
|
|
80
|
+
"bot.retryExhausted": "Reconnect budget exhausted: {message}; run /qq-login to retry.",
|
|
81
|
+
"bot.startupFailed": "Startup failed: {message}; check credentials and network.",
|
|
82
|
+
|
|
83
|
+
"login.fetchingQr": "Fetching QR code…",
|
|
84
|
+
"login.scan": "Scan with mobile QQ",
|
|
85
|
+
"login.expired": "QR code expired; refreshing…",
|
|
86
|
+
"login.cancel": "Esc to cancel",
|
|
87
|
+
"login.waiting": "pi-qq: waiting for mobile QQ scan…",
|
|
88
|
+
"login.qrUrl": "pi-qq QR URL: {url}",
|
|
89
|
+
"login.failed": "Error: QR login failed",
|
|
90
|
+
"login.startFailed": "Error: QQ bot start failed",
|
|
91
|
+
"login.fetchingQrShort": "(fetching QR code…)",
|
|
92
|
+
|
|
93
|
+
"notify.connected": "pi-qq connected",
|
|
94
|
+
"notify.connectionBlocked": "connection blocked",
|
|
95
|
+
"notify.loginRequired": "pi-qq: run /qq-login to scan a QR code.",
|
|
96
|
+
"notify.noBoundUser": "pi-qq: no bound QQ user; skipping reply.",
|
|
97
|
+
"notify.loggedOut": "pi-qq logged out.",
|
|
98
|
+
"notify.busyReset": "pi-qq: the agent is busy; run /stop before resetting the session.",
|
|
99
|
+
"notify.resetCancelled": "pi-qq: session reset cancelled.",
|
|
100
|
+
|
|
101
|
+
"errors.model": "⚠️ Model error: {message}",
|
|
102
|
+
|
|
103
|
+
"diagnostics.descBudget": "pi-qq: show passive reply budget, stream bubbles, and last inbound target",
|
|
104
|
+
"diagnostics.descMd": "pi-qq: send a Markdown message to verify QQ C2C Markdown rendering",
|
|
105
|
+
"diagnostics.descStream": "pi-qq: run a streamed timeline diagnostic (thinking/tools/text) or resume probe",
|
|
106
|
+
"diagnostics.doneSucceeded": "DONE succeeded",
|
|
107
|
+
"diagnostics.doneRejected": "DONE rejected: {message}",
|
|
108
|
+
"diagnostics.notConnected": "pi-qq is not connected.",
|
|
109
|
+
"diagnostics.noTarget": "pi-qq: no send target. Send a QQ message first.",
|
|
110
|
+
"diagnostics.mdSent": "Markdown test sent. Check whether QQ renders it as rich text.",
|
|
111
|
+
"diagnostics.mdFailed": "Markdown send failed: {message}",
|
|
112
|
+
"diagnostics.streamNoTarget": "pi-qq: send a QQ message first (streaming needs a msgId).",
|
|
113
|
+
"diagnostics.probeResumeFrame1": "**Resume probe** frame 1\n",
|
|
114
|
+
"diagnostics.probeResumeFrame2": "frame 2 after resume\n",
|
|
115
|
+
"diagnostics.probeThinking": "probe thinking\nsecond line",
|
|
116
|
+
"diagnostics.probeIntermediate": "**Intermediate message**: first-turn reply.",
|
|
117
|
+
"diagnostics.probeFinal": "**Final reply** (streamed append)",
|
|
118
|
+
"diagnostics.probeReadFile": "probe file",
|
|
119
|
+
"diagnostics.probeCode": "probe",
|
|
120
|
+
"diagnostics.resumeNoStream": "Resume probe: frame 1 sent but stream_msg_id is missing; cannot resume.",
|
|
121
|
+
"diagnostics.resumeResult":
|
|
122
|
+
"Resume probe: frame 2 sent with index {index} and stream_msg_id {streamMsgId}. Check whether both frames are in the same bubble.",
|
|
123
|
+
"diagnostics.streamResult": "Stream timeline test: frames sent, {done}. Check the QQ activity timeline.",
|
|
124
|
+
"diagnostics.streamFailed": "Stream timeline test failed: {message}",
|
|
125
|
+
"diagnostics.budget.title": "pi-qq passive reply budget",
|
|
126
|
+
"diagnostics.budget.limit": "Limit: {limit}/msg ({hours}h)",
|
|
127
|
+
"diagnostics.budget.lastInbound": "Last inbound: {openid} / {msgId}, {age}s ago",
|
|
128
|
+
"diagnostics.budget.lastInboundNone": "Last inbound: none",
|
|
129
|
+
"diagnostics.budget.passiveRemainingNone": "Passive remaining: —",
|
|
130
|
+
"diagnostics.budget.estimatedNone": "Estimated remaining: — (diagnostic only)",
|
|
131
|
+
"diagnostics.budget.windowNone": "msgId window: —",
|
|
132
|
+
"diagnostics.budget.none": "none",
|
|
133
|
+
"diagnostics.budget.passiveRemaining": "Passive remaining: {remaining}",
|
|
134
|
+
"diagnostics.budget.streamBubbles": "Stream bubbles: {count} (current msgId)",
|
|
135
|
+
"diagnostics.budget.estimated": "Estimated remaining: {remaining} (diagnostic only)",
|
|
136
|
+
"diagnostics.budget.window": "msgId window: {window}",
|
|
137
|
+
"diagnostics.budget.valid": "valid",
|
|
138
|
+
"diagnostics.budget.expired": "expired",
|
|
139
|
+
"diagnostics.budget.recorded": "Recorded: passive {passive} / stream {stream} / {tracked} msgId(s)",
|
|
140
|
+
|
|
141
|
+
"stream.thinking": "思考",
|
|
142
|
+
"stream.noOutput": "(no output)",
|
|
143
|
+
"stream.unavailable": "Stream unavailable; falling back to text ({reason}).",
|
|
144
|
+
"outbound.passiveFailed": "Passive reply failed; falling back to proactive.",
|
|
145
|
+
"outbound.proactiveFailed": "Proactive send failed: {message}",
|
|
146
|
+
"outbound.sendFailed": "Send failed: {message}",
|
|
147
|
+
|
|
148
|
+
"settings.invalidRoot": "Invalid config file ({path}): expected a JSON object; using defaults.",
|
|
149
|
+
"settings.invalidFields": "Invalid config file ({path}): {errors}; invalid values were ignored.",
|
|
150
|
+
"settings.parseFailed": "Failed to parse config file ({path}): {message}",
|
|
151
|
+
"settings.thinkingRelay": "thinkingRelay must be a boolean",
|
|
152
|
+
"settings.deliverAs": 'deliverAs must be "steer" or "followUp"',
|
|
153
|
+
"settings.fileMaxSize": "fileMaxSize must be a positive finite number",
|
|
154
|
+
"settings.logLevel": 'logLevel must be "silent", "error", "warn", "info", or "debug"',
|
|
155
|
+
"settings.language": 'language must be "zh-cn" or "en-us"',
|
|
156
|
+
"settings.debug": "debug must be a boolean",
|
|
157
|
+
|
|
158
|
+
"log.doneFailed": "DONE failed",
|
|
159
|
+
"log.qqCommand": "QQ command",
|
|
160
|
+
"log.qrCodeDisplayed": "QR code displayed",
|
|
161
|
+
"log.qrCodeExpired": "QR code expired; refreshing",
|
|
162
|
+
"log.qrLoginCommandFailed": "QR login command failed",
|
|
163
|
+
"log.qrLoginNoOpenid": "QR login did not return a user openid",
|
|
164
|
+
"log.qrLoginFailed": "QR login failed",
|
|
165
|
+
"log.qrLoginStarted": "QR login started",
|
|
166
|
+
"log.qrLoginSucceeded": "QR login succeeded",
|
|
167
|
+
"log.assistantMessageEnded": "assistant message ended",
|
|
168
|
+
"log.assistantMessageNoText": "assistant message has no text",
|
|
169
|
+
"log.attachmentFailureSummary": "attachment failure summary",
|
|
170
|
+
"log.attachmentsPending": "attachments pending for instruction",
|
|
171
|
+
"log.bubbleSplit": "bubble split",
|
|
172
|
+
"log.bubbleSplitFailed": "bubble split failed",
|
|
173
|
+
"log.clearedPendingAttachments": "cleared pending attachments for /new",
|
|
174
|
+
"log.toolEnd": "end",
|
|
175
|
+
"log.runEnded": "run ended",
|
|
176
|
+
"log.botErrorEvent": "error event",
|
|
177
|
+
"log.uploadIndexWriteFailed": "failed to write upload index",
|
|
178
|
+
"log.inboundMessage": "inbound message",
|
|
179
|
+
"log.botHandlerRejected": "message handler rejected",
|
|
180
|
+
"log.noBoundUser": "no bound user; reply skipped",
|
|
181
|
+
"log.noInjectableContent": "no injectable content after attachment handling",
|
|
182
|
+
"log.passiveSendFailed": "passive send failed; retrying proactively",
|
|
183
|
+
"log.proactiveRetryFailed": "proactive retry failed",
|
|
184
|
+
"log.runStarted": "run started",
|
|
185
|
+
"log.savingAttachments": "saving attachments",
|
|
186
|
+
"log.sendingReply": "sending reply",
|
|
187
|
+
"log.sendingTextChunk": "sending text chunk",
|
|
188
|
+
"log.sentToPi": "sent to pi",
|
|
189
|
+
"log.shuttingDown": "shutting down",
|
|
190
|
+
"log.skippedSender": "skipped non-allowlisted sender",
|
|
191
|
+
"log.skippedNonC2c": "skipped non-c2c message",
|
|
192
|
+
"log.toolStart": "start",
|
|
193
|
+
"log.sessionStarted": "started",
|
|
194
|
+
"log.botStarting": "starting",
|
|
195
|
+
"log.sessionStartingBot": "starting bot",
|
|
196
|
+
"log.startBotAfterLoginFailed": "starting bot after login failed",
|
|
197
|
+
"log.streamError": "stream error",
|
|
198
|
+
"log.streamReplyFallback": "stream reply failed; falling back to text",
|
|
199
|
+
"log.streamTakeoverDecision": "stream takeover decision",
|
|
200
|
+
"log.streamUnavailable": "stream unavailable",
|
|
201
|
+
"log.textChunkFailed": "text chunk failed",
|
|
202
|
+
"log.textChunkSent": "text chunk sent",
|
|
203
|
+
"log.unsupportedMessage": "unsupported message: no text and no attachments",
|
|
204
|
+
"log.voiceNoText": "voice ASR returned no text",
|
|
205
|
+
"log.voiceNoTextUseContent": "voice ASR returned no text; using text content",
|
|
206
|
+
"log.voiceMessage": "voice message",
|
|
207
|
+
"log.voiceTranscript": "voice transcript",
|
|
208
|
+
"log.streamFrameFailed": "frame index={index} failed after {attempts} attempt(s): {reason}",
|
|
209
|
+
"log.streamFrameRateLimited": "frame index={index} rate limited (attempt {attempt}), retry in {delay}ms: {reason}",
|
|
210
|
+
"log.botConnected": "connected",
|
|
211
|
+
"log.botReconnecting": "reconnecting",
|
|
212
|
+
"log.botStopped": "stopped",
|
|
213
|
+
"log.botBlocked": "blocked",
|
|
214
|
+
"log.messageReceived": "message received",
|
|
215
|
+
"log.ended": "ended",
|
|
216
|
+
"log.starting": "starting",
|
|
217
|
+
} as const;
|
|
218
|
+
|
|
219
|
+
export type TranslationKey = keyof typeof enUS;
|
|
220
|
+
|
|
221
|
+
const zhCN: Record<TranslationKey, string> = {
|
|
222
|
+
"status.title": "pi-qq 状态",
|
|
223
|
+
"status.separator": ":",
|
|
224
|
+
"status.detail": "({detail})",
|
|
225
|
+
"status.login": "登录",
|
|
226
|
+
"status.loginValue": "扫码登录(AppID {appId})",
|
|
227
|
+
"status.notLoggedIn": "未登录",
|
|
228
|
+
"status.connection": "连接",
|
|
229
|
+
"status.state.connected": "已连接",
|
|
230
|
+
"status.state.reconnecting": "重连中",
|
|
231
|
+
"status.state.stopped": "已停止",
|
|
232
|
+
"status.state.starting": "启动中",
|
|
233
|
+
"status.state.blocked": "已阻止",
|
|
234
|
+
"status.agent": "执行",
|
|
235
|
+
"status.agent.runningQQ": "执行中(QQ)",
|
|
236
|
+
"status.agent.runningLocal": "执行中(本地)",
|
|
237
|
+
"status.agent.completed": "已完成",
|
|
238
|
+
"status.model": "模型",
|
|
239
|
+
"status.context": "上下文",
|
|
240
|
+
"status.contextValue": "{tokens}/{window}({percent}%)",
|
|
241
|
+
"status.unknown": "未知",
|
|
242
|
+
"status.qqUser": "QQ 用户",
|
|
243
|
+
"status.battery": "电量",
|
|
244
|
+
"status.batteryCharging": "{percent}%(充电中)",
|
|
245
|
+
"status.batteryDischarging": "{percent}%(放电中)",
|
|
246
|
+
"status.batteryAc": "{percent}%(已接通电源)",
|
|
247
|
+
"status.batteryAcNoPercent": "已接通电源",
|
|
248
|
+
"status.batteryChargingNoPercent": "充电中",
|
|
249
|
+
"status.batteryDischargingNoPercent": "放电中",
|
|
250
|
+
"status.settings": "设置",
|
|
251
|
+
"status.none": "无",
|
|
252
|
+
|
|
253
|
+
"commands.descQqLogin": "pi-qq:扫码登录并绑定扫码的 QQ 用户",
|
|
254
|
+
"commands.descQqStatus": "pi-qq:显示登录、连接、执行状态、电量和绑定用户",
|
|
255
|
+
"commands.descQqLogout": "pi-qq:退出登录并清除凭据",
|
|
256
|
+
"commands.descQqNew": "pi-qq:重置当前会话(由 QQ 侧 /new 调用)",
|
|
257
|
+
"commands.help.title": "pi-qq 命令:",
|
|
258
|
+
"commands.help.stop": "• /stop — 中止当前任务",
|
|
259
|
+
"commands.help.compact": "• /compact — 压缩上下文",
|
|
260
|
+
"commands.help.status": "• /status — 显示执行状态、电量和上下文",
|
|
261
|
+
"commands.help.last": "• /last — 推送最近完成的消息,或重新推送当前输出",
|
|
262
|
+
"commands.help.new": "• /new — 重置会话",
|
|
263
|
+
"commands.help.help": "• /help — 显示帮助",
|
|
264
|
+
"commands.help.other": "其他文本会发送给 pi。",
|
|
265
|
+
"commands.stop.none": "当前没有正在运行的任务。",
|
|
266
|
+
"commands.stop.abort": "已请求中止。",
|
|
267
|
+
"commands.compact.done": "已触发上下文压缩。",
|
|
268
|
+
"commands.compact.busy": "任务正在运行;请先使用 /stop 再执行 /compact。",
|
|
269
|
+
"commands.last.none": "还没有已完成的消息。",
|
|
270
|
+
"commands.new.busy": "任务正在运行;请先使用 /stop 再重置会话。",
|
|
271
|
+
"commands.new.resetting": "正在重置会话…",
|
|
272
|
+
"commands.unknown": "未知命令 {cmd};请使用 /help。",
|
|
273
|
+
|
|
274
|
+
"inbound.unsupported": "不支持的消息类型。",
|
|
275
|
+
"inbound.voiceFailed": "无法转写这条语音消息,请重发或改用文字。",
|
|
276
|
+
"attachments.failedMany": "⚠️ {failed} 个附件失败(成功 {success} 个):",
|
|
277
|
+
"attachments.failedNone": "⚠️ 附件处理失败:",
|
|
278
|
+
"attachments.tooLarge": "{kind}过大({size} > {limit})",
|
|
279
|
+
"attachments.tooLargeShort": "{kind}过大(> {limit})",
|
|
280
|
+
"attachments.empty": "{kind}内容为空",
|
|
281
|
+
"attachments.invalidUrl": "{kind} URL 无效",
|
|
282
|
+
"attachments.unsupportedProtocol": "不支持 {kind} URL 协议",
|
|
283
|
+
"attachments.httpFailed": "下载失败(HTTP {status})",
|
|
284
|
+
"attachments.timeout": "下载超时({seconds} 秒)",
|
|
285
|
+
"attachments.noUniqueName": "无法分配唯一文件名",
|
|
286
|
+
"attachments.fileTooLarge": "文件过大({size} > {limit})",
|
|
287
|
+
"attachments.downloadFailed": "下载失败",
|
|
288
|
+
"attachments.kindFile": "文件",
|
|
289
|
+
|
|
290
|
+
"bot.fatalClose":
|
|
291
|
+
"服务器关闭了连接({code},4914=下线/仅沙箱,4915=被封禁)。请检查 QQ 开放平台中的机器人状态,或重新执行 /qq-login。",
|
|
292
|
+
"bot.retryExhausted": "重连次数已耗尽:{message};请执行 /qq-login 重试。",
|
|
293
|
+
"bot.startupFailed": "启动失败:{message};请检查凭据和网络。",
|
|
294
|
+
|
|
295
|
+
"login.fetchingQr": "正在获取二维码…",
|
|
296
|
+
"login.scan": "请用手机 QQ 扫码",
|
|
297
|
+
"login.expired": "二维码已过期,正在刷新…",
|
|
298
|
+
"login.cancel": "按 Esc 取消",
|
|
299
|
+
"login.waiting": "pi-qq:等待手机 QQ 扫码…",
|
|
300
|
+
"login.qrUrl": "pi-qq 二维码地址:{url}",
|
|
301
|
+
"login.failed": "错误:扫码登录失败",
|
|
302
|
+
"login.startFailed": "错误:QQ 机器人启动失败",
|
|
303
|
+
"login.fetchingQrShort": "(正在获取二维码…)",
|
|
304
|
+
|
|
305
|
+
"notify.connected": "pi-qq 已连接",
|
|
306
|
+
"notify.connectionBlocked": "连接被阻止",
|
|
307
|
+
"notify.loginRequired": "pi-qq:请执行 /qq-login 扫码登录。",
|
|
308
|
+
"notify.noBoundUser": "pi-qq:没有绑定的 QQ 用户,跳过回复。",
|
|
309
|
+
"notify.loggedOut": "pi-qq 已退出登录。",
|
|
310
|
+
"notify.busyReset": "pi-qq:agent 正在运行;请先使用 /stop 再重置会话。",
|
|
311
|
+
"notify.resetCancelled": "pi-qq:会话重置已取消。",
|
|
312
|
+
|
|
313
|
+
"errors.model": "⚠️ 模型错误:{message}",
|
|
314
|
+
|
|
315
|
+
"diagnostics.descBudget": "pi-qq:显示被动回复额度、流式气泡和最近入站目标",
|
|
316
|
+
"diagnostics.descMd": "pi-qq:发送 Markdown 消息,验证 QQ C2C Markdown 渲染",
|
|
317
|
+
"diagnostics.descStream": "pi-qq:运行流式时间线诊断(思考/工具/文本)或续写探测",
|
|
318
|
+
"diagnostics.doneSucceeded": "DONE 成功",
|
|
319
|
+
"diagnostics.doneRejected": "DONE 被拒绝:{message}",
|
|
320
|
+
"diagnostics.notConnected": "pi-qq 未连接。",
|
|
321
|
+
"diagnostics.noTarget": "pi-qq:没有发送目标。请先发送一条 QQ 消息。",
|
|
322
|
+
"diagnostics.mdSent": "Markdown 测试已发送,请检查 QQ 是否渲染为富文本。",
|
|
323
|
+
"diagnostics.mdFailed": "Markdown 发送失败:{message}",
|
|
324
|
+
"diagnostics.streamNoTarget": "pi-qq:请先发送一条 QQ 消息(流式消息需要 msgId)。",
|
|
325
|
+
"diagnostics.probeResumeFrame1": "**续写探测** 第 1 帧\n",
|
|
326
|
+
"diagnostics.probeResumeFrame2": "续写后的第 2 帧\n",
|
|
327
|
+
"diagnostics.probeThinking": "探测思考\n第二行",
|
|
328
|
+
"diagnostics.probeIntermediate": "**中间消息**:第一轮回复。",
|
|
329
|
+
"diagnostics.probeFinal": "**最终回复**(流式追加)",
|
|
330
|
+
"diagnostics.probeReadFile": "探测文件",
|
|
331
|
+
"diagnostics.probeCode": "探测",
|
|
332
|
+
"diagnostics.resumeNoStream": "续写探测:第 1 帧已发送,但缺少 stream_msg_id,无法续写。",
|
|
333
|
+
"diagnostics.resumeResult":
|
|
334
|
+
"续写探测:第 2 帧已发送,index 为 {index},stream_msg_id 为 {streamMsgId}。请检查两帧是否在同一个气泡中。",
|
|
335
|
+
"diagnostics.streamResult": "流式时间线测试:帧已发送,{done}。请检查 QQ 中的时间线。",
|
|
336
|
+
"diagnostics.streamFailed": "流式时间线测试失败:{message}",
|
|
337
|
+
"diagnostics.budget.title": "pi-qq 被动回复额度",
|
|
338
|
+
"diagnostics.budget.limit": "额度:{limit}/消息({hours} 小时)",
|
|
339
|
+
"diagnostics.budget.lastInbound": "最近入站:{openid} / {msgId},{age} 秒前",
|
|
340
|
+
"diagnostics.budget.lastInboundNone": "最近入站:无",
|
|
341
|
+
"diagnostics.budget.passiveRemainingNone": "被动剩余:—",
|
|
342
|
+
"diagnostics.budget.estimatedNone": "预计剩余:—(仅诊断)",
|
|
343
|
+
"diagnostics.budget.windowNone": "msgId 窗口:—",
|
|
344
|
+
"diagnostics.budget.none": "无",
|
|
345
|
+
"diagnostics.budget.passiveRemaining": "被动剩余:{remaining}",
|
|
346
|
+
"diagnostics.budget.streamBubbles": "流式气泡:{count}(当前 msgId)",
|
|
347
|
+
"diagnostics.budget.estimated": "预计剩余:{remaining}(仅诊断)",
|
|
348
|
+
"diagnostics.budget.window": "msgId 窗口:{window}",
|
|
349
|
+
"diagnostics.budget.valid": "有效",
|
|
350
|
+
"diagnostics.budget.expired": "已过期",
|
|
351
|
+
"diagnostics.budget.recorded": "已记录:被动 {passive} / 流式 {stream} / {tracked} 个 msgId",
|
|
352
|
+
|
|
353
|
+
"stream.thinking": "思考",
|
|
354
|
+
"stream.noOutput": "(无输出)",
|
|
355
|
+
"stream.unavailable": "流式不可用,回退为文本({reason})。",
|
|
356
|
+
"outbound.passiveFailed": "被动回复失败,改用主动消息。",
|
|
357
|
+
"outbound.proactiveFailed": "主动消息发送失败:{message}",
|
|
358
|
+
"outbound.sendFailed": "发送失败:{message}",
|
|
359
|
+
|
|
360
|
+
"settings.invalidRoot": "配置文件无效({path}):应为 JSON 对象;使用默认值。",
|
|
361
|
+
"settings.invalidFields": "配置文件无效({path}):{errors};无效值已忽略。",
|
|
362
|
+
"settings.parseFailed": "解析配置文件失败({path}):{message}",
|
|
363
|
+
"settings.thinkingRelay": "thinkingRelay 必须是布尔值",
|
|
364
|
+
"settings.deliverAs": 'deliverAs 必须是 "steer" 或 "followUp"',
|
|
365
|
+
"settings.fileMaxSize": "fileMaxSize 必须是正有限数",
|
|
366
|
+
"settings.logLevel": 'logLevel 必须是 "silent"、"error"、"warn"、"info" 或 "debug"',
|
|
367
|
+
"settings.language": 'language 必须是 "zh-cn" 或 "en-us"',
|
|
368
|
+
"settings.debug": "debug 必须是布尔值",
|
|
369
|
+
|
|
370
|
+
"log.doneFailed": "DONE 失败",
|
|
371
|
+
"log.qqCommand": "QQ 命令",
|
|
372
|
+
"log.qrCodeDisplayed": "二维码已显示",
|
|
373
|
+
"log.qrCodeExpired": "二维码已过期,正在刷新",
|
|
374
|
+
"log.qrLoginCommandFailed": "扫码登录命令失败",
|
|
375
|
+
"log.qrLoginNoOpenid": "扫码登录未返回用户 openid",
|
|
376
|
+
"log.qrLoginFailed": "扫码登录失败",
|
|
377
|
+
"log.qrLoginStarted": "开始扫码登录",
|
|
378
|
+
"log.qrLoginSucceeded": "扫码登录成功",
|
|
379
|
+
"log.assistantMessageEnded": "assistant 消息结束",
|
|
380
|
+
"log.assistantMessageNoText": "assistant 消息没有文本",
|
|
381
|
+
"log.attachmentFailureSummary": "附件失败汇总",
|
|
382
|
+
"log.attachmentsPending": "附件等待指令",
|
|
383
|
+
"log.bubbleSplit": "气泡切分",
|
|
384
|
+
"log.bubbleSplitFailed": "气泡切分失败",
|
|
385
|
+
"log.clearedPendingAttachments": "已清除 /new 的待处理附件",
|
|
386
|
+
"log.toolEnd": "工具结束",
|
|
387
|
+
"log.runEnded": "运行结束",
|
|
388
|
+
"log.botErrorEvent": "错误事件",
|
|
389
|
+
"log.uploadIndexWriteFailed": "写入上传索引失败",
|
|
390
|
+
"log.inboundMessage": "收到消息",
|
|
391
|
+
"log.botHandlerRejected": "消息处理器异常",
|
|
392
|
+
"log.noBoundUser": "未绑定用户,跳过回复",
|
|
393
|
+
"log.noInjectableContent": "附件处理后没有可注入内容",
|
|
394
|
+
"log.passiveSendFailed": "被动回复失败,正在尝试主动消息",
|
|
395
|
+
"log.proactiveRetryFailed": "主动消息重试失败",
|
|
396
|
+
"log.runStarted": "运行开始",
|
|
397
|
+
"log.savingAttachments": "正在保存附件",
|
|
398
|
+
"log.sendingReply": "发送回复",
|
|
399
|
+
"log.sendingTextChunk": "发送文本分片",
|
|
400
|
+
"log.sentToPi": "已发送给 pi",
|
|
401
|
+
"log.shuttingDown": "正在关闭",
|
|
402
|
+
"log.skippedSender": "跳过非白名单发送者",
|
|
403
|
+
"log.skippedNonC2c": "跳过非 C2C 消息",
|
|
404
|
+
"log.toolStart": "工具开始",
|
|
405
|
+
"log.sessionStarted": "会话开始",
|
|
406
|
+
"log.botStarting": "机器人启动中",
|
|
407
|
+
"log.sessionStartingBot": "正在启动机器人",
|
|
408
|
+
"log.startBotAfterLoginFailed": "登录后启动机器人失败",
|
|
409
|
+
"log.streamError": "流式错误",
|
|
410
|
+
"log.streamReplyFallback": "流式回复失败,回退为文本",
|
|
411
|
+
"log.streamTakeoverDecision": "流式接管决策",
|
|
412
|
+
"log.streamUnavailable": "流式不可用",
|
|
413
|
+
"log.textChunkFailed": "文本分片发送失败",
|
|
414
|
+
"log.textChunkSent": "文本分片已发送",
|
|
415
|
+
"log.unsupportedMessage": "不支持的消息:没有文本和附件",
|
|
416
|
+
"log.voiceNoText": "语音 ASR 没有返回文本",
|
|
417
|
+
"log.voiceNoTextUseContent": "语音 ASR 没有返回文本,使用文本内容",
|
|
418
|
+
"log.voiceMessage": "语音消息",
|
|
419
|
+
"log.voiceTranscript": "语音转写",
|
|
420
|
+
"log.streamFrameFailed": "帧 index={index} 在 {attempts} 次尝试后失败:{reason}",
|
|
421
|
+
"log.streamFrameRateLimited": "帧 index={index} 被限流(第 {attempt} 次尝试),{delay}ms 后重试:{reason}",
|
|
422
|
+
"log.botConnected": "已连接",
|
|
423
|
+
"log.botReconnecting": "正在重连",
|
|
424
|
+
"log.botStopped": "已停止",
|
|
425
|
+
"log.botBlocked": "连接被阻止",
|
|
426
|
+
"log.messageReceived": "收到消息",
|
|
427
|
+
"log.ended": "已结束",
|
|
428
|
+
"log.starting": "启动中",
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
const dictionaries: Record<Language, Record<TranslationKey, string>> = {
|
|
432
|
+
"en-us": enUS,
|
|
433
|
+
"zh-cn": zhCN,
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
let activeLanguage: Language = DEFAULT_LANGUAGE;
|
|
437
|
+
|
|
438
|
+
export function configureI18n(language: Language): void {
|
|
439
|
+
activeLanguage = isLanguage(language) ? language : DEFAULT_LANGUAGE;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
export function getLanguage(): Language {
|
|
443
|
+
return activeLanguage;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
export function translate(
|
|
447
|
+
language: Language,
|
|
448
|
+
key: TranslationKey,
|
|
449
|
+
params?: Record<string, string | number | undefined>,
|
|
450
|
+
): string {
|
|
451
|
+
const template = dictionaries[language][key] ?? enUS[key] ?? key;
|
|
452
|
+
if (!params) return template;
|
|
453
|
+
return template.replace(/\{(\w+)\}/g, (match, name: string) => {
|
|
454
|
+
const value = params[name];
|
|
455
|
+
return value === undefined ? match : String(value);
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
export function t(key: TranslationKey, params?: Record<string, string | number | undefined>): string {
|
|
460
|
+
return translate(activeLanguage, key, params);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
const LOG_MESSAGE_KEYS: Record<string, TranslationKey> = {
|
|
464
|
+
"DONE failed": "log.doneFailed",
|
|
465
|
+
"QQ command": "log.qqCommand",
|
|
466
|
+
"QR code displayed": "log.qrCodeDisplayed",
|
|
467
|
+
"QR code expired; refreshing": "log.qrCodeExpired",
|
|
468
|
+
"QR login command failed": "log.qrLoginCommandFailed",
|
|
469
|
+
"QR login did not return a user openid": "log.qrLoginNoOpenid",
|
|
470
|
+
"QR login failed": "log.qrLoginFailed",
|
|
471
|
+
"QR login started": "log.qrLoginStarted",
|
|
472
|
+
"QR login succeeded": "log.qrLoginSucceeded",
|
|
473
|
+
"assistant message ended": "log.assistantMessageEnded",
|
|
474
|
+
"assistant message has no text": "log.assistantMessageNoText",
|
|
475
|
+
"attachment failure summary": "log.attachmentFailureSummary",
|
|
476
|
+
"attachments pending for instruction": "log.attachmentsPending",
|
|
477
|
+
"bubble split": "log.bubbleSplit",
|
|
478
|
+
"bubble split failed": "log.bubbleSplitFailed",
|
|
479
|
+
"cleared pending attachments for /new": "log.clearedPendingAttachments",
|
|
480
|
+
end: "log.toolEnd",
|
|
481
|
+
ended: "log.ended",
|
|
482
|
+
"error event": "log.botErrorEvent",
|
|
483
|
+
"failed to write upload index": "log.uploadIndexWriteFailed",
|
|
484
|
+
"inbound message": "log.inboundMessage",
|
|
485
|
+
"message handler rejected": "log.botHandlerRejected",
|
|
486
|
+
"message received": "log.messageReceived",
|
|
487
|
+
"no bound user; reply skipped": "log.noBoundUser",
|
|
488
|
+
"no injectable content after attachment handling": "log.noInjectableContent",
|
|
489
|
+
"passive send failed; retrying proactively": "log.passiveSendFailed",
|
|
490
|
+
"proactive retry failed": "log.proactiveRetryFailed",
|
|
491
|
+
"run ended": "log.runEnded",
|
|
492
|
+
"run started": "log.runStarted",
|
|
493
|
+
"saving attachments": "log.savingAttachments",
|
|
494
|
+
"sending reply": "log.sendingReply",
|
|
495
|
+
"sending text chunk": "log.sendingTextChunk",
|
|
496
|
+
"sent to pi": "log.sentToPi",
|
|
497
|
+
"shutting down": "log.shuttingDown",
|
|
498
|
+
"skipped non-allowlisted sender": "log.skippedSender",
|
|
499
|
+
"skipped non-c2c message": "log.skippedNonC2c",
|
|
500
|
+
start: "log.toolStart",
|
|
501
|
+
started: "log.sessionStarted",
|
|
502
|
+
starting: "log.botStarting",
|
|
503
|
+
"starting bot": "log.sessionStartingBot",
|
|
504
|
+
"starting bot after login failed": "log.startBotAfterLoginFailed",
|
|
505
|
+
"stream error": "log.streamError",
|
|
506
|
+
"stream reply failed; falling back to text": "log.streamReplyFallback",
|
|
507
|
+
"stream takeover decision": "log.streamTakeoverDecision",
|
|
508
|
+
"stream unavailable": "log.streamUnavailable",
|
|
509
|
+
"text chunk failed": "log.textChunkFailed",
|
|
510
|
+
"text chunk sent": "log.textChunkSent",
|
|
511
|
+
"unsupported message: no text and no attachments": "log.unsupportedMessage",
|
|
512
|
+
"voice ASR returned no text": "log.voiceNoText",
|
|
513
|
+
"voice ASR returned no text; using text content": "log.voiceNoTextUseContent",
|
|
514
|
+
"voice message": "log.voiceMessage",
|
|
515
|
+
"voice transcript": "log.voiceTranscript",
|
|
516
|
+
connected: "log.botConnected",
|
|
517
|
+
reconnecting: "log.botReconnecting",
|
|
518
|
+
stopped: "log.botStopped",
|
|
519
|
+
blocked: "log.botBlocked",
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
export function localizeLogMessage(message: string): { msg: string; msgKey?: TranslationKey } {
|
|
523
|
+
const key = LOG_MESSAGE_KEYS[message];
|
|
524
|
+
return key ? { msg: t(key), msgKey: key } : { msg: message };
|
|
525
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
export interface PowerStatus {
|
|
6
|
+
percent?: number;
|
|
7
|
+
state: "charging" | "discharging" | "ac";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const CACHE_MS = 30_000;
|
|
11
|
+
let cache: { at: number; value: PowerStatus | undefined } | undefined;
|
|
12
|
+
|
|
13
|
+
function clampPercent(value: number): number | undefined {
|
|
14
|
+
if (!Number.isFinite(value)) return undefined;
|
|
15
|
+
return Math.max(0, Math.min(100, Math.round(value)));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function parsePmsetOutput(output: string): PowerStatus | undefined {
|
|
19
|
+
if (!/InternalBattery|Battery/i.test(output)) return undefined;
|
|
20
|
+
const percentMatch = output.match(/(\d+)%/);
|
|
21
|
+
const percent = percentMatch ? clampPercent(Number(percentMatch[1])) : undefined;
|
|
22
|
+
const state = /discharging/i.test(output) ? "discharging" : /charging/i.test(output) ? "charging" : "ac";
|
|
23
|
+
return { percent, state };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface WindowsBattery {
|
|
27
|
+
EstimatedChargeRemaining?: number | string;
|
|
28
|
+
BatteryStatus?: number | string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function parseWindowsBattery(output: string): PowerStatus | undefined {
|
|
32
|
+
let parsed: WindowsBattery | WindowsBattery[] | null;
|
|
33
|
+
try {
|
|
34
|
+
parsed = JSON.parse(output) as WindowsBattery | WindowsBattery[] | null;
|
|
35
|
+
} catch {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const battery = Array.isArray(parsed) ? parsed[0] : parsed;
|
|
39
|
+
if (!battery) return undefined;
|
|
40
|
+
|
|
41
|
+
const percent = clampPercent(Number(battery.EstimatedChargeRemaining));
|
|
42
|
+
const status = Number(battery.BatteryStatus);
|
|
43
|
+
const state =
|
|
44
|
+
status === 1 || status === 4 || status === 5
|
|
45
|
+
? "discharging"
|
|
46
|
+
: status >= 6 && status <= 9
|
|
47
|
+
? "charging"
|
|
48
|
+
: status === 2 || status === 3
|
|
49
|
+
? "ac"
|
|
50
|
+
: "ac";
|
|
51
|
+
return { percent, state };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function readLinuxBattery(root = "/sys/class/power_supply"): PowerStatus | undefined {
|
|
55
|
+
let entries: string[];
|
|
56
|
+
try {
|
|
57
|
+
entries = readdirSync(root).filter((name) => name.startsWith("BAT"));
|
|
58
|
+
} catch {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
if (entries.length === 0) return undefined;
|
|
62
|
+
|
|
63
|
+
for (const entry of entries) {
|
|
64
|
+
try {
|
|
65
|
+
const dir = join(root, entry);
|
|
66
|
+
const rawPercent = readFileSync(join(dir, "capacity"), "utf8").trim();
|
|
67
|
+
const percent = clampPercent(Number(rawPercent));
|
|
68
|
+
const rawStatus = readFileSync(join(dir, "status"), "utf8").trim().toLowerCase();
|
|
69
|
+
const state = rawStatus === "charging" ? "charging" : rawStatus === "discharging" ? "discharging" : "ac";
|
|
70
|
+
return { percent, state };
|
|
71
|
+
} catch {
|
|
72
|
+
// Try the next battery.
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function readPowerStatus(): PowerStatus | undefined {
|
|
79
|
+
try {
|
|
80
|
+
if (process.platform === "linux") return readLinuxBattery();
|
|
81
|
+
if (process.platform === "darwin") {
|
|
82
|
+
const output = execFileSync("pmset", ["-g", "batt"], {
|
|
83
|
+
encoding: "utf8",
|
|
84
|
+
timeout: 500,
|
|
85
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
86
|
+
});
|
|
87
|
+
return parsePmsetOutput(output);
|
|
88
|
+
}
|
|
89
|
+
if (process.platform === "win32") {
|
|
90
|
+
const output = execFileSync(
|
|
91
|
+
"powershell",
|
|
92
|
+
[
|
|
93
|
+
"-NoProfile",
|
|
94
|
+
"-Command",
|
|
95
|
+
"Get-CimInstance Win32_Battery | Select-Object -First 1 EstimatedChargeRemaining,BatteryStatus | ConvertTo-Json -Compress",
|
|
96
|
+
],
|
|
97
|
+
{ encoding: "utf8", timeout: 500, stdio: ["ignore", "pipe", "ignore"] },
|
|
98
|
+
);
|
|
99
|
+
return parseWindowsBattery(output);
|
|
100
|
+
}
|
|
101
|
+
} catch {
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function getPowerStatus(now = Date.now()): PowerStatus | undefined {
|
|
108
|
+
if (cache && now - cache.at < CACHE_MS) return cache.value;
|
|
109
|
+
const value = readPowerStatus();
|
|
110
|
+
cache = { at: now, value };
|
|
111
|
+
return value;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function resetPowerStatusCache(): void {
|
|
115
|
+
cache = undefined;
|
|
116
|
+
}
|