@chen_hu_hu/pi-qq 1.3.3 → 1.3.5

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.
@@ -2,7 +2,8 @@ import type { QQBot } from "@tencent-connect/qqbot-nodejs";
2
2
  import { AppendStream, type AppendStreamCheckpoint } from "./stream-session";
3
3
  import type { ReplyBudget } from "../quota/reply-quota";
4
4
  import { log } from "../infra/file-logger";
5
- import { THINKING_HEADER, formatToolLine, formatToolResult } from "./stream-block-format";
5
+ import { formatSkillBlock, formatToolLine, formatToolResult, thinkingHeader } from "./stream-block-format";
6
+ import { t } from "../infra/i18n";
6
7
 
7
8
  type BlockKind = "none" | "thinking" | "tool" | "text";
8
9
 
@@ -79,6 +80,14 @@ export class BubbleWriter {
79
80
  this.push(`${prefix}${formatToolLine(name, args)}\n\n`, prefix.length > 0 || newBubble, false, newBubble);
80
81
  }
81
82
 
83
+ pushSkill(name: string): void {
84
+ if (this.streamDead || this.disposed) return;
85
+ this.toolOpen = false;
86
+ const newBubble = true;
87
+ const prefix = this.beginBlock("tool", newBubble);
88
+ this.push(`${prefix}${formatSkillBlock(name)}`, prefix.length > 0 || newBubble, false, newBubble);
89
+ }
90
+
82
91
  pushToolResult(result: unknown, isError: boolean): void {
83
92
  if (this.streamDead || this.disposed) return;
84
93
  const prefix = this.beginBlock("tool");
@@ -236,7 +245,7 @@ export class BubbleWriter {
236
245
  const stream = this.ensureStream();
237
246
  if (!stream) return;
238
247
  this.pushedAny = true;
239
- const outgoing = thinking && (!this.cur || this.bubbleChars === 0) ? `${THINKING_HEADER}${text}` : text;
248
+ const outgoing = thinking && (!this.cur || this.bubbleChars === 0) ? `${thinkingHeader()}${text}` : text;
240
249
  try {
241
250
  await stream.append(outgoing);
242
251
  this.bubbleChars += outgoing.length;
@@ -364,6 +373,6 @@ export class BubbleWriter {
364
373
  this.cur?.dispose();
365
374
  this.cur = null;
366
375
  log.warn("stream", "stream unavailable", { msgId: this.logMsgId(), reason });
367
- this.deps.onWarn(`Stream unavailable; falling back to text (${reason}).`);
376
+ this.deps.onWarn(t("stream.unavailable", { reason }));
368
377
  }
369
378
  }
@@ -2,6 +2,7 @@ import type { QQBot } from "@tencent-connect/qqbot-nodejs";
2
2
  import { BubbleWriter } from "./bubble-writer";
3
3
  import type { ReplyBudget } from "../quota/reply-quota";
4
4
  import { log } from "../infra/file-logger";
5
+ import { detectSkillRead } from "./stream-block-format";
5
6
 
6
7
  export interface RunFeedbackDeps {
7
8
  bot: () => QQBot | undefined;
@@ -15,6 +16,7 @@ interface ToolCall {
15
16
  name: string;
16
17
  args?: unknown;
17
18
  result?: { isError: boolean; result?: unknown };
19
+ skillName?: string;
18
20
  started: boolean;
19
21
  finished: boolean;
20
22
  }
@@ -143,7 +145,7 @@ export class RunFeedback {
143
145
  writer,
144
146
  };
145
147
  this.run = run;
146
- log.debug("run", "started", { msgId: run.msgId?.slice(0, 8) ?? "?" });
148
+ log.debug("run", "run started", { msgId: run.msgId?.slice(0, 8) ?? "?" });
147
149
 
148
150
  const keepTyping = () => {
149
151
  void bot.sendTyping({ scope: "c2c", targetId: run.openid }, 60).catch(() => {});
@@ -157,7 +159,15 @@ export class RunFeedback {
157
159
  if (!run || run.writer.dead) return;
158
160
  const id = toolCallId ?? toolName;
159
161
  if (run.tools.some((tool) => tool.id === id)) return;
160
- run.tools.push({ id, name: toolName, args, started: false, finished: false });
162
+ const skill = detectSkillRead(toolName, args);
163
+ run.tools.push({
164
+ id,
165
+ name: toolName,
166
+ args,
167
+ ...(skill ? { skillName: skill.name } : {}),
168
+ started: false,
169
+ finished: false,
170
+ });
161
171
  this.startNextTool(run);
162
172
  }
163
173
 
@@ -245,7 +255,7 @@ export class RunFeedback {
245
255
  if (run.currentText.trim()) this.lastCompletedText = run.currentText;
246
256
  if (!run.hadError && run.writer.hasPushed) this.recovery = null;
247
257
  this.run = null;
248
- log.debug("run", "ended", {
258
+ log.debug("run", "run ended", {
249
259
  msgId: run.msgId?.slice(0, 8) ?? "?",
250
260
  elapsedMs: Date.now() - run.startedAt,
251
261
  });
@@ -299,14 +309,20 @@ export class RunFeedback {
299
309
  if (!tool) return;
300
310
  tool.started = true;
301
311
  run.activeTool = tool.id;
302
- run.writer.pushTool(tool.name, tool.args);
312
+ if (tool.skillName) {
313
+ run.writer.pushSkill(tool.skillName);
314
+ } else {
315
+ run.writer.pushTool(tool.name, tool.args);
316
+ }
303
317
  if (tool.result) this.finishTool(run, tool);
304
318
  }
305
319
 
306
320
  private finishTool(run: RunState, tool: ToolCall): void {
307
321
  if (!tool.result || tool.finished) return;
308
322
  tool.finished = true;
309
- run.writer.pushToolResult(tool.result.result, tool.result.isError);
323
+ if (!tool.skillName) {
324
+ run.writer.pushToolResult(tool.result.result, tool.result.isError);
325
+ }
310
326
  run.writer.schedule(() => {
311
327
  if (this.run !== run) return;
312
328
  if (run.activeTool !== tool.id) return;
@@ -1,4 +1,8 @@
1
- export const THINKING_HEADER = "**💭 思考**\n\n";
1
+ import { t } from "../infra/i18n";
2
+
3
+ export function thinkingHeader(): string {
4
+ return `**💭 ${t("stream.thinking")}**\n\n`;
5
+ }
2
6
  const ARG_MAX_CHARS = 200;
3
7
  const RESULT_MAX_CHARS = 600;
4
8
  const RESULT_MAX_LINES = 8;
@@ -70,6 +74,30 @@ function primaryArg(args: unknown): string {
70
74
  return normalized.length > ARG_MAX_CHARS ? `${normalized.slice(0, ARG_MAX_CHARS)}…` : normalized;
71
75
  }
72
76
 
77
+ export interface SkillRead {
78
+ name: string;
79
+ }
80
+
81
+ /**
82
+ * Detect a read of a SKILL.md file. pi renders this as "[skill]" in the TUI;
83
+ * QQ should show a dedicated skill block instead of a generic read tool.
84
+ */
85
+ export function detectSkillRead(toolName: string, args: unknown): SkillRead | undefined {
86
+ if (toolName !== "read" || !args || typeof args !== "object") return undefined;
87
+ const record = args as Record<string, unknown>;
88
+ const rawPath =
89
+ typeof record.path === "string" ? record.path : typeof record.file_path === "string" ? record.file_path : undefined;
90
+ if (!rawPath) return undefined;
91
+ const parts = rawPath.split(/[\\/]+/).filter((part) => part.length > 0 && part !== ".");
92
+ if (parts.length < 2 || parts[parts.length - 1] !== "SKILL.md") return undefined;
93
+ const name = parts[parts.length - 2];
94
+ return name ? { name } : undefined;
95
+ }
96
+
97
+ export function formatSkillBlock(name: string): string {
98
+ return `## 🧩 Skill\n\n${inlineCode(name)}\n`;
99
+ }
100
+
73
101
  export function formatToolLine(name: string, args: unknown): string {
74
102
  const primary = primaryArg(args);
75
103
  const label = `${TOOL_ICONS[name.toLowerCase()] ?? "🔧"} ${name}`;
@@ -109,7 +137,7 @@ function resultText(result: unknown): string {
109
137
  export function formatToolResult(result: unknown, isError: boolean): string {
110
138
  let text = resultText(result);
111
139
  text = text.replace(/\r\n/g, "\n").replace(/\s+$/, "");
112
- if (!text) text = "(no output)";
140
+ if (!text) text = t("stream.noOutput");
113
141
  text = truncateText(text, RESULT_MAX_CHARS, RESULT_MAX_LINES);
114
142
  if (isError) text = `❌ ${text}`;
115
143
  const fence = backtickFence(text, 3);
@@ -1,4 +1,5 @@
1
1
  import { getNextMsgSeq, StreamContentType, StreamInputState } from "@tencent-connect/qqbot-nodejs/protocol";
2
+ import { t } from "../infra/i18n";
2
3
  import type {
3
4
  Credentials,
4
5
  MessageApi,
@@ -164,13 +165,11 @@ export class AppendStream {
164
165
  } catch (err) {
165
166
  const reason = err instanceof Error ? err.message : String(err);
166
167
  if (attempt >= MAX_RETRIES || !this.isRateLimitError(err)) {
167
- this.opts.onDebug?.(`frame index=${req.index} failed after ${attempt + 1} attempt(s): ${reason}`);
168
+ this.opts.onDebug?.(t("log.streamFrameFailed", { index: req.index, attempts: attempt + 1, reason }));
168
169
  throw err;
169
170
  }
170
171
  const delay = base * 2 ** attempt;
171
- this.opts.onDebug?.(
172
- `frame index=${req.index} rate limited (attempt ${attempt + 1}), retry in ${delay}ms: ${reason}`,
173
- );
172
+ this.opts.onDebug?.(t("log.streamFrameRateLimited", { index: req.index, attempt: attempt + 1, delay, reason }));
174
173
  await new Promise((r) => setTimeout(r, delay));
175
174
  }
176
175
  }