@chen_hu_hu/pi-qq 1.6.0 → 1.6.2

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +36 -4
  2. package/README-zh.md +21 -44
  3. package/README.md +29 -52
  4. package/doc/archive/{delivery-v1.md → delivery.1.0.0.md} +1 -1
  5. package/doc/archive/{delivery-v2.md → delivery.1.2.0.md} +1 -1
  6. package/doc/archive/{delivery-v3.md → delivery.1.3.0.md} +1 -1
  7. package/doc/archive/{delivery-v4.md → delivery.1.4.0.md} +1 -1
  8. package/doc/archive/{delivery-v5.md → delivery.1.5.0.md} +2 -2
  9. package/doc/archive/{delivery-v6.md → delivery.1.6.0.md} +3 -3
  10. package/doc/archive/delivery.1.6.1.md +150 -0
  11. package/doc/archive/delivery.1.6.2.md +196 -0
  12. package/doc/todo.md +2 -2
  13. package/index.ts +30 -32
  14. package/package.json +1 -1
  15. package/src/attachments/attachment-download.ts +2 -1
  16. package/src/attachments/file-attachments.ts +4 -5
  17. package/src/infra/file-logger.ts +6 -6
  18. package/src/infra/i18n.ts +4 -198
  19. package/src/infra/log-message-keys.ts +66 -0
  20. package/src/infra/power-status.ts +1 -11
  21. package/src/infra/reply-type.ts +1 -1
  22. package/src/infra/settings.ts +0 -6
  23. package/src/qq/inbound-attachments.ts +2 -2
  24. package/src/qq/inbound-command.ts +8 -7
  25. package/src/qq/media-tool.ts +36 -60
  26. package/src/qq/qq-bot.ts +1 -1
  27. package/src/qq/qq-diagnostics.ts +1 -1
  28. package/src/qq/qq-message-handler.ts +7 -6
  29. package/src/qq/status-report.ts +1 -13
  30. package/src/quota/reply-quota.ts +2 -2
  31. package/src/relay/bubble-writer.ts +84 -38
  32. package/src/relay/reply-policy.ts +0 -13
  33. package/src/relay/run-stream-relay.ts +129 -203
  34. package/src/relay/run-timeline.ts +127 -0
  35. package/src/relay/stream-block-format.ts +1 -1
  36. package/src/relay/stream-session.ts +25 -8
package/src/infra/i18n.ts CHANGED
@@ -56,7 +56,7 @@ const enUS = {
56
56
  "commands.compact.done": "Context compaction triggered.",
57
57
  "commands.compact.busy": "Task is running; use /stop before /compact.",
58
58
  "commands.last.none": "No completed message yet.",
59
- "commands.last.running": "The task is still running; the final reply will be sent when it finishes.",
59
+ "commands.last.empty": "Nothing to repush yet; the task is still running.",
60
60
  "commands.new.busy": "Task is running; use /stop before resetting.",
61
61
  "commands.new.resetting": "Resetting the session…",
62
62
  "commands.unknown": "Unknown command {cmd}; use /help.",
@@ -131,7 +131,6 @@ const enUS = {
131
131
  "diagnostics.budget.passiveRemainingNone": "Passive remaining: —",
132
132
  "diagnostics.budget.estimatedNone": "Estimated remaining: — (diagnostic only)",
133
133
  "diagnostics.budget.windowNone": "msgId window: —",
134
- "diagnostics.budget.none": "none",
135
134
  "diagnostics.budget.passiveRemaining": "Passive remaining: {remaining}",
136
135
  "diagnostics.budget.streamBubbles": "Stream bubbles: {count} (current msgId)",
137
136
  "diagnostics.budget.estimated": "Estimated remaining: {remaining} (diagnostic only)",
@@ -166,75 +165,12 @@ const enUS = {
166
165
  "settings.invalidRoot": "Invalid config file ({path}): expected a JSON object; using defaults.",
167
166
  "settings.invalidFields": "Invalid config file ({path}): {errors}; invalid values were ignored.",
168
167
  "settings.parseFailed": "Failed to parse config file ({path}): {message}",
169
- "settings.thinkingRelay": "thinkingRelay must be a boolean",
170
168
  "settings.deliverAs": 'deliverAs must be "steer" or "followUp"',
171
- "settings.replyType": 'replyType must be "full", "simple", or "last"',
169
+ "settings.replyType": 'replyType must be "full" or "simple"',
172
170
  "settings.fileMaxSize": "fileMaxSize must be a positive finite number",
173
171
  "settings.logLevel": 'logLevel must be "silent", "error", "warn", "info", or "debug"',
174
172
  "settings.language": 'language must be "zh-cn" or "en-us"',
175
173
  "settings.debug": "debug must be a boolean",
176
-
177
- "log.doneFailed": "DONE failed",
178
- "log.qqCommand": "QQ command",
179
- "log.qrCodeDisplayed": "QR code displayed",
180
- "log.qrCodeExpired": "QR code expired; refreshing",
181
- "log.qrLoginCommandFailed": "QR login command failed",
182
- "log.qrLoginNoOpenid": "QR login did not return a user openid",
183
- "log.qrLoginFailed": "QR login failed",
184
- "log.qrLoginStarted": "QR login started",
185
- "log.qrLoginSucceeded": "QR login succeeded",
186
- "log.assistantMessageEnded": "assistant message ended",
187
- "log.assistantMessageNoText": "assistant message has no text",
188
- "log.attachmentFailureSummary": "attachment failure summary",
189
- "log.attachmentsPending": "attachments pending for instruction",
190
- "log.bubbleSplit": "bubble split",
191
- "log.bubbleSplitFailed": "bubble split failed",
192
- "log.clearedPendingAttachments": "cleared pending attachments for /new",
193
- "log.toolEnd": "end",
194
- "log.runEnded": "run ended",
195
- "log.botErrorEvent": "error event",
196
- "log.uploadIndexWriteFailed": "failed to write upload index",
197
- "log.inboundMessage": "inbound message",
198
- "log.botHandlerRejected": "message handler rejected",
199
- "log.noBoundUser": "no bound user; reply skipped",
200
- "log.noInjectableContent": "no injectable content after attachment handling",
201
- "log.passiveSendFailed": "passive send failed; retrying proactively",
202
- "log.proactiveRetryFailed": "proactive retry failed",
203
- "log.runStarted": "run started",
204
- "log.savingAttachments": "saving attachments",
205
- "log.sendingReply": "sending reply",
206
- "log.sendingTextChunk": "sending text chunk",
207
- "log.sentToPi": "sent to pi",
208
- "log.shuttingDown": "shutting down",
209
- "log.skippedSender": "skipped non-allowlisted sender",
210
- "log.skippedNonC2c": "skipped non-c2c message",
211
- "log.toolStart": "start",
212
- "log.sessionStarted": "started",
213
- "log.botStarting": "starting",
214
- "log.sessionStartingBot": "starting bot",
215
- "log.startBotAfterLoginFailed": "starting bot after login failed",
216
- "log.streamError": "stream error",
217
- "log.streamReplyFallback": "stream reply failed; falling back to text",
218
- "log.streamTakeoverDecision": "stream takeover decision",
219
- "log.streamUnavailable": "stream unavailable",
220
- "log.textChunkFailed": "text chunk failed",
221
- "log.textChunkSent": "text chunk sent",
222
- "log.unsupportedMessage": "unsupported message: no text and no attachments",
223
- "log.voiceNoText": "voice ASR returned no text",
224
- "log.voiceNoTextUseContent": "voice ASR returned no text; using text content",
225
- "log.voiceMessage": "voice message",
226
- "log.voiceTranscript": "voice transcript",
227
- "log.streamFrameFailed": "frame index={index} failed after {attempts} attempt(s): {reason}",
228
- "log.streamFrameRateLimited": "frame index={index} rate limited (attempt {attempt}), retry in {delay}ms: {reason}",
229
- "log.botConnected": "connected",
230
- "log.botReconnecting": "reconnecting",
231
- "log.botStopped": "stopped",
232
- "log.botBlocked": "blocked",
233
- "log.messageReceived": "message received",
234
- "log.ended": "ended",
235
- "log.starting": "starting",
236
- "log.streamTiming": "stream timing",
237
- "log.eventLoopDelay": "event loop delay",
238
174
  } as const;
239
175
 
240
176
  export type TranslationKey = keyof typeof enUS;
@@ -289,7 +225,7 @@ const zhCN: Record<TranslationKey, string> = {
289
225
  "commands.compact.done": "已触发上下文压缩。",
290
226
  "commands.compact.busy": "任务正在运行;请先使用 /stop 再执行 /compact。",
291
227
  "commands.last.none": "还没有已完成的消息。",
292
- "commands.last.running": "任务仍在进行中,完成后会自动推送最终回复。",
228
+ "commands.last.empty": "当前没有可重推的内容,任务仍在执行中。",
293
229
  "commands.new.busy": "任务正在运行;请先使用 /stop 再重置会话。",
294
230
  "commands.new.resetting": "正在重置会话…",
295
231
  "commands.unknown": "未知命令 {cmd};请使用 /help。",
@@ -364,7 +300,6 @@ const zhCN: Record<TranslationKey, string> = {
364
300
  "diagnostics.budget.passiveRemainingNone": "被动剩余:—",
365
301
  "diagnostics.budget.estimatedNone": "预计剩余:—(仅诊断)",
366
302
  "diagnostics.budget.windowNone": "msgId 窗口:—",
367
- "diagnostics.budget.none": "无",
368
303
  "diagnostics.budget.passiveRemaining": "被动剩余:{remaining}",
369
304
  "diagnostics.budget.streamBubbles": "流式气泡:{count}(当前 msgId)",
370
305
  "diagnostics.budget.estimated": "预计剩余:{remaining}(仅诊断)",
@@ -399,75 +334,12 @@ const zhCN: Record<TranslationKey, string> = {
399
334
  "settings.invalidRoot": "配置文件无效({path}):应为 JSON 对象;使用默认值。",
400
335
  "settings.invalidFields": "配置文件无效({path}):{errors};无效值已忽略。",
401
336
  "settings.parseFailed": "解析配置文件失败({path}):{message}",
402
- "settings.thinkingRelay": "thinkingRelay 必须是布尔值",
403
337
  "settings.deliverAs": 'deliverAs 必须是 "steer" 或 "followUp"',
404
- "settings.replyType": 'replyType 必须是 "full"、"simple" 或 "last"',
338
+ "settings.replyType": 'replyType 必须是 "full" 或 "simple"',
405
339
  "settings.fileMaxSize": "fileMaxSize 必须是正有限数",
406
340
  "settings.logLevel": 'logLevel 必须是 "silent"、"error"、"warn"、"info" 或 "debug"',
407
341
  "settings.language": 'language 必须是 "zh-cn" 或 "en-us"',
408
342
  "settings.debug": "debug 必须是布尔值",
409
-
410
- "log.doneFailed": "DONE 失败",
411
- "log.qqCommand": "QQ 命令",
412
- "log.qrCodeDisplayed": "二维码已显示",
413
- "log.qrCodeExpired": "二维码已过期,正在刷新",
414
- "log.qrLoginCommandFailed": "扫码登录命令失败",
415
- "log.qrLoginNoOpenid": "扫码登录未返回用户 openid",
416
- "log.qrLoginFailed": "扫码登录失败",
417
- "log.qrLoginStarted": "开始扫码登录",
418
- "log.qrLoginSucceeded": "扫码登录成功",
419
- "log.assistantMessageEnded": "assistant 消息结束",
420
- "log.assistantMessageNoText": "assistant 消息没有文本",
421
- "log.attachmentFailureSummary": "附件失败汇总",
422
- "log.attachmentsPending": "附件等待指令",
423
- "log.bubbleSplit": "气泡切分",
424
- "log.bubbleSplitFailed": "气泡切分失败",
425
- "log.clearedPendingAttachments": "已清除 /new 的待处理附件",
426
- "log.toolEnd": "工具结束",
427
- "log.runEnded": "运行结束",
428
- "log.botErrorEvent": "错误事件",
429
- "log.uploadIndexWriteFailed": "写入上传索引失败",
430
- "log.inboundMessage": "收到消息",
431
- "log.botHandlerRejected": "消息处理器异常",
432
- "log.noBoundUser": "未绑定用户,跳过回复",
433
- "log.noInjectableContent": "附件处理后没有可注入内容",
434
- "log.passiveSendFailed": "被动回复失败,正在尝试主动消息",
435
- "log.proactiveRetryFailed": "主动消息重试失败",
436
- "log.runStarted": "运行开始",
437
- "log.savingAttachments": "正在保存附件",
438
- "log.sendingReply": "发送回复",
439
- "log.sendingTextChunk": "发送文本分片",
440
- "log.sentToPi": "已发送给 pi",
441
- "log.shuttingDown": "正在关闭",
442
- "log.skippedSender": "跳过非白名单发送者",
443
- "log.skippedNonC2c": "跳过非 C2C 消息",
444
- "log.toolStart": "工具开始",
445
- "log.sessionStarted": "会话开始",
446
- "log.botStarting": "机器人启动中",
447
- "log.sessionStartingBot": "正在启动机器人",
448
- "log.startBotAfterLoginFailed": "登录后启动机器人失败",
449
- "log.streamError": "流式错误",
450
- "log.streamReplyFallback": "流式回复失败,回退为文本",
451
- "log.streamTakeoverDecision": "流式接管决策",
452
- "log.streamUnavailable": "流式不可用",
453
- "log.textChunkFailed": "文本分片发送失败",
454
- "log.textChunkSent": "文本分片已发送",
455
- "log.unsupportedMessage": "不支持的消息:没有文本和附件",
456
- "log.voiceNoText": "语音 ASR 没有返回文本",
457
- "log.voiceNoTextUseContent": "语音 ASR 没有返回文本,使用文本内容",
458
- "log.voiceMessage": "语音消息",
459
- "log.voiceTranscript": "语音转写",
460
- "log.streamFrameFailed": "帧 index={index} 在 {attempts} 次尝试后失败:{reason}",
461
- "log.streamFrameRateLimited": "帧 index={index} 被限流(第 {attempt} 次尝试),{delay}ms 后重试:{reason}",
462
- "log.botConnected": "已连接",
463
- "log.botReconnecting": "正在重连",
464
- "log.botStopped": "已停止",
465
- "log.botBlocked": "连接被阻止",
466
- "log.messageReceived": "收到消息",
467
- "log.ended": "已结束",
468
- "log.starting": "启动中",
469
- "log.streamTiming": "流式时序",
470
- "log.eventLoopDelay": "事件循环延迟",
471
343
  };
472
344
 
473
345
  const dictionaries: Record<Language, Record<TranslationKey, string>> = {
@@ -501,69 +373,3 @@ export function translate(
501
373
  export function t(key: TranslationKey, params?: Record<string, string | number | undefined>): string {
502
374
  return translate(activeLanguage, key, params);
503
375
  }
504
-
505
- const LOG_MESSAGE_KEYS: Record<string, TranslationKey> = {
506
- "DONE failed": "log.doneFailed",
507
- "QQ command": "log.qqCommand",
508
- "QR code displayed": "log.qrCodeDisplayed",
509
- "QR code expired; refreshing": "log.qrCodeExpired",
510
- "QR login command failed": "log.qrLoginCommandFailed",
511
- "QR login did not return a user openid": "log.qrLoginNoOpenid",
512
- "QR login failed": "log.qrLoginFailed",
513
- "QR login started": "log.qrLoginStarted",
514
- "QR login succeeded": "log.qrLoginSucceeded",
515
- "assistant message ended": "log.assistantMessageEnded",
516
- "assistant message has no text": "log.assistantMessageNoText",
517
- "attachment failure summary": "log.attachmentFailureSummary",
518
- "attachments pending for instruction": "log.attachmentsPending",
519
- "bubble split": "log.bubbleSplit",
520
- "bubble split failed": "log.bubbleSplitFailed",
521
- "cleared pending attachments for /new": "log.clearedPendingAttachments",
522
- end: "log.toolEnd",
523
- ended: "log.ended",
524
- "error event": "log.botErrorEvent",
525
- "failed to write upload index": "log.uploadIndexWriteFailed",
526
- "inbound message": "log.inboundMessage",
527
- "message handler rejected": "log.botHandlerRejected",
528
- "message received": "log.messageReceived",
529
- "no bound user; reply skipped": "log.noBoundUser",
530
- "no injectable content after attachment handling": "log.noInjectableContent",
531
- "passive send failed; retrying proactively": "log.passiveSendFailed",
532
- "proactive retry failed": "log.proactiveRetryFailed",
533
- "run ended": "log.runEnded",
534
- "run started": "log.runStarted",
535
- "saving attachments": "log.savingAttachments",
536
- "sending reply": "log.sendingReply",
537
- "sending text chunk": "log.sendingTextChunk",
538
- "sent to pi": "log.sentToPi",
539
- "shutting down": "log.shuttingDown",
540
- "skipped non-allowlisted sender": "log.skippedSender",
541
- "skipped non-c2c message": "log.skippedNonC2c",
542
- start: "log.toolStart",
543
- started: "log.sessionStarted",
544
- starting: "log.botStarting",
545
- "stream timing": "log.streamTiming",
546
- "event loop delay": "log.eventLoopDelay",
547
- "starting bot": "log.sessionStartingBot",
548
- "starting bot after login failed": "log.startBotAfterLoginFailed",
549
- "stream error": "log.streamError",
550
- "stream reply failed; falling back to text": "log.streamReplyFallback",
551
- "stream takeover decision": "log.streamTakeoverDecision",
552
- "stream unavailable": "log.streamUnavailable",
553
- "text chunk failed": "log.textChunkFailed",
554
- "text chunk sent": "log.textChunkSent",
555
- "unsupported message: no text and no attachments": "log.unsupportedMessage",
556
- "voice ASR returned no text": "log.voiceNoText",
557
- "voice ASR returned no text; using text content": "log.voiceNoTextUseContent",
558
- "voice message": "log.voiceMessage",
559
- "voice transcript": "log.voiceTranscript",
560
- connected: "log.botConnected",
561
- reconnecting: "log.botReconnecting",
562
- stopped: "log.botStopped",
563
- blocked: "log.botBlocked",
564
- };
565
-
566
- export function localizeLogMessage(message: string): { msg: string; msgKey?: TranslationKey } {
567
- const key = LOG_MESSAGE_KEYS[message];
568
- return key ? { msg: t(key), msgKey: key } : { msg: message };
569
- }
@@ -0,0 +1,66 @@
1
+ const LOG_MESSAGE_KEYS = {
2
+ "DONE failed": "log.doneFailed",
3
+ "QQ command": "log.qqCommand",
4
+ "QR code displayed": "log.qrCodeDisplayed",
5
+ "QR code expired; refreshing": "log.qrCodeExpired",
6
+ "QR login command failed": "log.qrLoginCommandFailed",
7
+ "QR login did not return a user openid": "log.qrLoginNoOpenid",
8
+ "QR login failed": "log.qrLoginFailed",
9
+ "QR login started": "log.qrLoginStarted",
10
+ "QR login succeeded": "log.qrLoginSucceeded",
11
+ "assistant message ended": "log.assistantMessageEnded",
12
+ "assistant message has no text": "log.assistantMessageNoText",
13
+ "attachment failure summary": "log.attachmentFailureSummary",
14
+ "attachments pending for instruction": "log.attachmentsPending",
15
+ "bubble split": "log.bubbleSplit",
16
+ "bubble split failed": "log.bubbleSplitFailed",
17
+ "cleared pending attachments for /new": "log.clearedPendingAttachments",
18
+ end: "log.toolEnd",
19
+ ended: "log.ended",
20
+ "error event": "log.botErrorEvent",
21
+ "failed to write upload index": "log.uploadIndexWriteFailed",
22
+ "inbound message": "log.inboundMessage",
23
+ "message handler rejected": "log.botHandlerRejected",
24
+ "message received": "log.messageReceived",
25
+ "no bound user; reply skipped": "log.noBoundUser",
26
+ "no injectable content after attachment handling": "log.noInjectableContent",
27
+ "passive send failed; retrying proactively": "log.passiveSendFailed",
28
+ "proactive retry failed": "log.proactiveRetryFailed",
29
+ "run ended": "log.runEnded",
30
+ "run started": "log.runStarted",
31
+ "saving attachments": "log.savingAttachments",
32
+ "sending reply": "log.sendingReply",
33
+ "sending text chunk": "log.sendingTextChunk",
34
+ "sent to pi": "log.sentToPi",
35
+ "shutting down": "log.shuttingDown",
36
+ "skipped non-allowlisted sender": "log.skippedSender",
37
+ "skipped non-c2c message": "log.skippedNonC2c",
38
+ start: "log.toolStart",
39
+ started: "log.sessionStarted",
40
+ starting: "log.botStarting",
41
+ "stream timing": "log.streamTiming",
42
+ "event loop delay": "log.eventLoopDelay",
43
+ "starting bot": "log.sessionStartingBot",
44
+ "starting bot after login failed": "log.startBotAfterLoginFailed",
45
+ "stream error": "log.streamError",
46
+ "stream reply failed; falling back to text": "log.streamReplyFallback",
47
+ "stream takeover decision": "log.streamTakeoverDecision",
48
+ "stream unavailable": "log.streamUnavailable",
49
+ "text chunk failed": "log.textChunkFailed",
50
+ "text chunk sent": "log.textChunkSent",
51
+ "unsupported message: no text and no attachments": "log.unsupportedMessage",
52
+ "voice ASR returned no text": "log.voiceNoText",
53
+ "voice ASR returned no text; using text content": "log.voiceNoTextUseContent",
54
+ "voice message": "log.voiceMessage",
55
+ "voice transcript": "log.voiceTranscript",
56
+ connected: "log.botConnected",
57
+ reconnecting: "log.botReconnecting",
58
+ stopped: "log.botStopped",
59
+ blocked: "log.botBlocked",
60
+ } as const;
61
+
62
+ export type LogMessageKey = (typeof LOG_MESSAGE_KEYS)[keyof typeof LOG_MESSAGE_KEYS];
63
+
64
+ export function logMessageKey(message: string): LogMessageKey | undefined {
65
+ return (LOG_MESSAGE_KEYS as Record<string, LogMessageKey>)[message];
66
+ }
@@ -41,13 +41,7 @@ export function parseWindowsBattery(output: string): PowerStatus | undefined {
41
41
  const percent = clampPercent(Number(battery.EstimatedChargeRemaining));
42
42
  const status = Number(battery.BatteryStatus);
43
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";
44
+ status === 1 || status === 4 || status === 5 ? "discharging" : status >= 6 && status <= 9 ? "charging" : "ac";
51
45
  return { percent, state };
52
46
  }
53
47
 
@@ -108,7 +102,3 @@ export function getPowerStatus(now = Date.now()): PowerStatus | undefined {
108
102
  cache = { at: now, value };
109
103
  return value;
110
104
  }
111
-
112
- export function resetPowerStatusCache(): void {
113
- cache = undefined;
114
- }
@@ -1,4 +1,4 @@
1
- export const REPLY_TYPES = ["full", "simple", "last"] as const;
1
+ const REPLY_TYPES = ["full", "simple"] as const;
2
2
 
3
3
  export type ReplyType = (typeof REPLY_TYPES)[number];
4
4
 
@@ -6,7 +6,6 @@ import { DEFAULT_LANGUAGE, getLanguage, isLanguage, translate, type Language } f
6
6
  import { DEFAULT_REPLY_TYPE, isReplyType, type ReplyType } from "./reply-type";
7
7
 
8
8
  export interface PiQQSettings {
9
- thinkingRelay?: boolean;
10
9
  deliverAs?: "steer" | "followUp";
11
10
  replyType?: ReplyType;
12
11
  fileMaxSize?: number;
@@ -55,10 +54,6 @@ export function parseConfig(raw: unknown): ReadConfigResult {
55
54
  if (isLanguage(raw.language)) config.language = raw.language;
56
55
  else errors.push(translate(language, "settings.language"));
57
56
  }
58
- if (raw.thinkingRelay !== undefined) {
59
- if (typeof raw.thinkingRelay === "boolean") config.thinkingRelay = raw.thinkingRelay;
60
- else errors.push(translate(language, "settings.thinkingRelay"));
61
- }
62
57
  if (raw.deliverAs !== undefined) {
63
58
  if (raw.deliverAs === "steer" || raw.deliverAs === "followUp") config.deliverAs = raw.deliverAs;
64
59
  else errors.push(translate(language, "settings.deliverAs"));
@@ -116,7 +111,6 @@ export type ResolvedSettings = Required<Omit<PiQQSettings, "debug">>;
116
111
  export function getSettings(config: PiQQSettings): ResolvedSettings {
117
112
  const logLevel = normalizeLogLevel(config.logLevel ?? (config.debug ? "debug" : undefined));
118
113
  return {
119
- thinkingRelay: config.thinkingRelay ?? true,
120
114
  deliverAs: config.deliverAs ?? "steer",
121
115
  replyType: config.replyType ?? DEFAULT_REPLY_TYPE,
122
116
  fileMaxSize: config.fileMaxSize ?? 50 * 1024 * 1024,
@@ -5,14 +5,14 @@ import { log } from "../infra/file-logger";
5
5
  import { t } from "../infra/i18n";
6
6
  import { isVoiceAttachment, resolveVoiceTranscript } from "../attachments/voice-transcript";
7
7
 
8
- export interface ResolveInboundOptions {
8
+ interface ResolveInboundOptions {
9
9
  contentText: string;
10
10
  maxSize: number;
11
11
  uploadDir: string;
12
12
  saveFiles: typeof saveInboundFiles;
13
13
  }
14
14
 
15
- export type ResolvedInbound =
15
+ type ResolvedInbound =
16
16
  | { status: "rejected"; reply: string }
17
17
  | {
18
18
  status: "resolved";
@@ -1,5 +1,4 @@
1
1
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
- import type { ReplyType } from "../infra/reply-type";
3
2
  import { log } from "../infra/file-logger";
4
3
  import { t } from "../infra/i18n";
5
4
 
@@ -18,14 +17,17 @@ export interface InboundCommandDeps {
18
17
  ctx: InboundContext;
19
18
  getStatusLines: () => string[];
20
19
  getLastMessage?: () => string | undefined;
21
- getReplyType?: () => ReplyType;
22
20
  onStop?: () => void;
23
21
  waitForEnd?: () => Promise<void>;
24
22
  }
25
23
 
24
+ export interface InboundPushResult {
25
+ ok: boolean;
26
+ }
27
+
26
28
  export interface InboundCommandExtras {
27
29
  streamReply?: (text: string) => Promise<void>;
28
- restartPush?: () => void;
30
+ restartPush?: () => InboundPushResult;
29
31
  }
30
32
 
31
33
  export async function handleInboundCommand(
@@ -79,11 +81,10 @@ export async function handleInboundCommand(
79
81
  break;
80
82
  case "/last": {
81
83
  if (!deps.ctx.isIdle()) {
82
- if (deps.getReplyType?.() === "last") {
83
- await reply(t("commands.last.running"));
84
- break;
84
+ const result = extras.restartPush?.();
85
+ if (result && !result.ok) {
86
+ await reply(t("commands.last.empty"));
85
87
  }
86
- extras.restartPush?.();
87
88
  } else {
88
89
  const text = deps.getLastMessage?.();
89
90
  if (text) {
@@ -48,7 +48,7 @@ export interface MediaToolDetails {
48
48
  total?: number;
49
49
  }
50
50
 
51
- export interface PreparedMedia {
51
+ interface PreparedMedia {
52
52
  path: string;
53
53
  fileType: MediaFileType;
54
54
  size: number;
@@ -56,7 +56,7 @@ export interface PreparedMedia {
56
56
  details: MediaToolDetails;
57
57
  }
58
58
 
59
- export interface MediaToolLogin {
59
+ interface MediaToolLogin {
60
60
  allowedOpenid: string;
61
61
  }
62
62
 
@@ -70,7 +70,6 @@ export interface MediaToolDeps {
70
70
  export interface MediaToolController {
71
71
  activate(): void;
72
72
  deactivate(): void;
73
- isActive(): boolean;
74
73
  }
75
74
 
76
75
  function mediaErrorMessage(err: unknown): Error {
@@ -298,14 +297,41 @@ function createTool(deps: MediaToolDeps): ToolDefinition<typeof mediaParams, Med
298
297
  captionLength: caption?.length ?? 0,
299
298
  });
300
299
 
301
- try {
302
- const message = await bot.mediaApi.sendMediaMessage("c2c", targetId, upload.file_info, bot.getCredentials(), {
303
- msgId,
300
+ const sendMedia = (target: string, passiveMsgId?: string) =>
301
+ bot.mediaApi.sendMediaMessage("c2c", target, upload.file_info, bot.getCredentials(), {
302
+ ...(passiveMsgId ? { msgId: passiveMsgId } : {}),
304
303
  content: caption,
305
304
  });
305
+ const buildResult = (
306
+ messageId: string,
307
+ mode: "passive" | "proactive",
308
+ elapsedMs: number,
309
+ ): { content: Array<{ type: "text"; text: string }>; details: MediaToolDetails } => ({
310
+ content: [
311
+ {
312
+ type: "text",
313
+ text: t("mediaTool.sent", {
314
+ kind: mediaKindLabel(prepared.fileType),
315
+ name: prepared.displayName,
316
+ mode: t(mode === "passive" ? "mediaTool.modePassive" : "mediaTool.modeProactive"),
317
+ }),
318
+ },
319
+ ],
320
+ details: {
321
+ ...prepared.details,
322
+ phase: "sent",
323
+ mode,
324
+ messageId,
325
+ fileUuid: upload.file_uuid,
326
+ ttlSec: upload.ttl,
327
+ elapsedMs,
328
+ },
329
+ });
330
+
331
+ try {
332
+ const message = await sendMedia(targetId, msgId);
306
333
  if (msgId) deps.budget.commitPassive(msgId);
307
334
  const elapsedMs = Date.now() - sendStartedAt;
308
- const mode = reply.mode === "passive" ? t("mediaTool.modePassive") : t("mediaTool.modeProactive");
309
335
  log.debug("media", "media tool", {
310
336
  phase: "send.done",
311
337
  toolCallId,
@@ -320,27 +346,7 @@ function createTool(deps: MediaToolDeps): ToolDefinition<typeof mediaParams, Med
320
346
  mode: reply.mode,
321
347
  messageId: message.id,
322
348
  });
323
- return {
324
- content: [
325
- {
326
- type: "text",
327
- text: t("mediaTool.sent", {
328
- kind: mediaKindLabel(prepared.fileType),
329
- name: prepared.displayName,
330
- mode,
331
- }),
332
- },
333
- ],
334
- details: {
335
- ...prepared.details,
336
- phase: "sent",
337
- mode: reply.mode,
338
- messageId: message.id,
339
- fileUuid: upload.file_uuid,
340
- ttlSec: upload.ttl,
341
- elapsedMs: Date.now() - startedAt,
342
- },
343
- };
349
+ return buildResult(message.id, reply.mode, Date.now() - startedAt);
344
350
  } catch (err) {
345
351
  if (!msgId) {
346
352
  log.warn("media", "media tool", { phase: "call.error", toolCallId, stage: "send", err });
@@ -360,16 +366,9 @@ function createTool(deps: MediaToolDeps): ToolDefinition<typeof mediaParams, Med
360
366
  });
361
367
 
362
368
  try {
363
- const message = await bot.mediaApi.sendMediaMessage(
364
- "c2c",
365
- login.allowedOpenid,
366
- upload.file_info,
367
- bot.getCredentials(),
368
- { content: caption },
369
- );
369
+ const message = await sendMedia(login.allowedOpenid);
370
370
  deps.onWarn(t("outbound.passiveFailed"));
371
371
  const elapsedMs = Date.now() - sendStartedAt;
372
- const mode = t("mediaTool.modeProactive");
373
372
  log.debug("media", "media tool", {
374
373
  phase: "send.done",
375
374
  toolCallId,
@@ -384,27 +383,7 @@ function createTool(deps: MediaToolDeps): ToolDefinition<typeof mediaParams, Med
384
383
  mode: "proactive",
385
384
  messageId: message.id,
386
385
  });
387
- return {
388
- content: [
389
- {
390
- type: "text",
391
- text: t("mediaTool.sent", {
392
- kind: mediaKindLabel(prepared.fileType),
393
- name: prepared.displayName,
394
- mode,
395
- }),
396
- },
397
- ],
398
- details: {
399
- ...prepared.details,
400
- phase: "sent",
401
- mode: "proactive",
402
- messageId: message.id,
403
- fileUuid: upload.file_uuid,
404
- ttlSec: upload.ttl,
405
- elapsedMs: Date.now() - startedAt,
406
- },
407
- };
386
+ return buildResult(message.id, "proactive", Date.now() - startedAt);
408
387
  } catch (retryErr) {
409
388
  log.warn("media", "media tool", {
410
389
  phase: "call.error",
@@ -451,8 +430,5 @@ export function registerMediaTool(pi: ExtensionAPI, deps: MediaToolDeps): MediaT
451
430
  activeCount: pi.getActiveTools().length,
452
431
  });
453
432
  },
454
- isActive() {
455
- return pi.getActiveTools().includes(MEDIA_TOOL_NAME);
456
- },
457
433
  };
458
434
  }
package/src/qq/qq-bot.ts CHANGED
@@ -13,7 +13,7 @@ import { t } from "../infra/i18n";
13
13
 
14
14
  export type BotState = "stopped" | "starting" | "connected" | "reconnecting" | "blocked";
15
15
 
16
- export interface StartBotOptions {
16
+ interface StartBotOptions {
17
17
  credentials: Credentials;
18
18
  allowedOpenid: string;
19
19
  onMessage?: (bot: QQBot, msg: QQBotInboundMessage) => void | Promise<void>;
@@ -6,7 +6,7 @@ import type { RunningBot } from "./qq-bot";
6
6
  import { t } from "../infra/i18n";
7
7
  import { thinkingHeader } from "../relay/stream-block-format";
8
8
 
9
- export interface QQDiagnosticsDeps {
9
+ interface QQDiagnosticsDeps {
10
10
  getRunning: () => RunningBot | undefined;
11
11
  budget: ReplyBudget;
12
12
  getBoundOpenid: () => string | undefined;