@yinan_chen/pi-claude-code-ui 0.8.7 → 0.8.8

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/generic-card.ts +34 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yinan_chen/pi-claude-code-ui",
3
- "version": "0.8.7",
3
+ "version": "0.8.8",
4
4
  "description": "Claude Code-style UI for Pi: transcript view, rich diffs, subagent panels and working-message status.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -40,22 +40,42 @@ function firstMeaningfulLine(lines: readonly string[]): string {
40
40
  }
41
41
 
42
42
  /** JSON 内容的智能首行:query/title 等字段优先,数组给条数,否则紧凑化。 */
43
+ /** 无语义键:预览跳过(id/时间戳等对读者无信息量)。 */
44
+ const JSON_PREVIEW_SKIP_KEYS = new Set(["id", "responseId", "requestId", "ts", "timestamp", "createdAt", "updatedAt"]);
45
+
46
+ /** 已 parse 的 JSON 摘要:query/queries/provider 等语义字段优先,数组给条数,否则紧凑化。 */
47
+ function summarizeJson(parsed: unknown): string | undefined {
48
+ if (Array.isArray(parsed)) return `${parsed.length} item${parsed.length === 1 ? "" : "s"}`;
49
+ if (parsed && typeof parsed === "object") {
50
+ const record = parsed as Record<string, unknown>;
51
+ const queries = record.queries;
52
+ if (Array.isArray(queries) && queries.length) return `queries: ${queries.map(String).join("; ")}`;
53
+ for (const key of ["query", "q", "title", "summary", "text", "message", "provider", "providers"]) {
54
+ const value = record[key];
55
+ if (typeof value === "string" && value.trim()) return value;
56
+ if (Array.isArray(value) && value.length && value.every((v) => typeof v === "string")) return value.join("; ");
57
+ }
58
+ const firstString = Object.entries(record).find(([k, v]) => typeof v === "string" && String(v).trim() && !JSON_PREVIEW_SKIP_KEYS.has(k));
59
+ if (firstString !== undefined) return String(firstString[1]);
60
+ return JSON.stringify(record).replace(/\s+/g, " ").slice(0, 200);
61
+ }
62
+ return undefined;
63
+ }
64
+
65
+ /** JSON 智能预览:允许 JSON 外裹文本(markdown 等)——从首个 {/[ 开头行逐行累积 parse,成功即摘要。 */
43
66
  function jsonPreview(text: string): string | undefined {
44
- const trimmed = text.trim();
45
- if (!trimmed.startsWith("{") && !trimmed.startsWith("[")) return undefined;
46
- try {
47
- const parsed = JSON.parse(trimmed);
48
- if (Array.isArray(parsed)) return `${parsed.length} item${parsed.length === 1 ? "" : "s"}`;
49
- if (parsed && typeof parsed === "object") {
50
- for (const key of ["query", "q", "title", "summary", "text", "message"]) {
51
- const value = (parsed as Record<string, unknown>)[key];
52
- if (typeof value === "string" && value.trim()) return value;
53
- }
54
- const firstString = Object.values(parsed).find((v) => typeof v === "string" && String(v).trim());
55
- if (firstString !== undefined) return String(firstString);
56
- return trimmed.replace(/\s+/g, " ").slice(0, 200);
67
+ const lines = text.trim().split("\n");
68
+ for (let i = 0; i < lines.length; i++) {
69
+ const head = lines[i].trim();
70
+ if (!head.startsWith("{") && !head.startsWith("[")) continue;
71
+ let buffer = "";
72
+ for (let j = i; j < lines.length && j - i < 200; j++) {
73
+ buffer += `${lines[j]}\n`;
74
+ try {
75
+ return summarizeJson(JSON.parse(buffer));
76
+ } catch { /* 继续累积 */ }
57
77
  }
58
- } catch { /* 非 JSON 或超长,回退原文 */ }
78
+ }
59
79
  return undefined;
60
80
  }
61
81