@spzxg/cli-ui 0.4.0 → 0.6.1

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 (44) hide show
  1. package/README.md +84 -10
  2. package/dist/cli-ui-embed-Dk2QGHxn.js +41146 -0
  3. package/dist/cli-ui-index-BFpRZXn4.js +11209 -0
  4. package/dist/cli-ui-jszip.min-B9tqMA-e.js +2324 -0
  5. package/dist/cli-ui-jszip.min-DIavJzUG.js +26 -0
  6. package/dist/cli-ui-xlsx-BKHhqcoa.js +93 -0
  7. package/dist/cli-ui.css +1 -1
  8. package/dist/cli-ui.js +1 -1
  9. package/package.json +3 -1
  10. package/src/board/BrowserPane.tsx +396 -96
  11. package/src/board/ChangesPane.tsx +13 -4
  12. package/src/board/CliBoard.tsx +219 -37
  13. package/src/board/FileViewer.tsx +387 -73
  14. package/src/board/FilesPane.tsx +51 -4
  15. package/src/board/blocks.tsx +3 -2
  16. package/src/board/fileKind.ts +31 -0
  17. package/src/board/fileOps.ts +55 -0
  18. package/src/board/folderDownload.ts +161 -0
  19. package/src/board/frameQuote.ts +50 -0
  20. package/src/board/textLoad.ts +99 -0
  21. package/src/board/workspace.ts +129 -0
  22. package/src/board/zip.ts +85 -0
  23. package/src/chat/CliChat.tsx +122 -23
  24. package/src/chat/Composer.tsx +4 -4
  25. package/src/core/blocks.ts +69 -11
  26. package/src/core/client.ts +285 -41
  27. package/src/core/config.ts +18 -5
  28. package/src/core/conversation.ts +17 -7
  29. package/src/core/store.ts +340 -71
  30. package/src/core/textDecode.ts +24 -0
  31. package/src/core/types.ts +21 -6
  32. package/src/core/xlsx.ts +142 -0
  33. package/src/elements.tsx +106 -11
  34. package/src/index.ts +7 -2
  35. package/src/layout/CliSplit.tsx +53 -0
  36. package/src/layout/split.ts +214 -0
  37. package/src/msglist/CliMsgList.tsx +50 -22
  38. package/src/styles.css +101 -0
  39. package/src/ui/ErrorBoundary.tsx +38 -0
  40. package/src/ui/TextBlock.tsx +1 -1
  41. package/src/ui/Transcript.tsx +10 -5
  42. package/src/ui/transcriptModel.ts +66 -9
  43. package/dist/cli-ui-embed-D7xtcvGG.js +0 -37967
  44. package/dist/cli-ui-index-O0krpZBg.js +0 -13516
package/src/core/types.ts CHANGED
@@ -224,7 +224,8 @@ export type NodeEvent =
224
224
  /** center 实时流 chunk.events 里的一项。 */
225
225
  export type StreamItem =
226
226
  /** remote_task_id:一次性任务的流里才有(大任务里可能同时有几个节点对话)。 */
227
- | { type: "transcript"; remote_task_id?: string; messages: Message[] | null; pending: PendingMessage[] | null; running: boolean | null }
227
+ /** older:快照只有最新一段时,更早还有几条(往上翻时经 history 分页取)。旧版中枢没有 = 全量。 */
228
+ | { type: "transcript"; remote_task_id?: string; messages: Message[] | null; pending: PendingMessage[] | null; running: boolean | null; older?: number }
228
229
  | { type: "node"; remote_task_id?: string; event: NodeEvent }
229
230
  | { type: "turn"; turn: CenterTurn }
230
231
  | { type: "job"; job: { id: string; status: JobStatus; closed_reason?: string | null; node_id: string | null } }
@@ -368,8 +369,8 @@ export interface BoardInfo {
368
369
  remote_task_id?: string;
369
370
  node?: { id: string; health: string };
370
371
  files: boolean;
371
- /** 节点开了浏览器功能。 */
372
- browser: boolean;
372
+ /** 节点开了浏览器功能。null = 这次没探测出来(节点慢 / 暂时连不上),照常显示浏览器页签。 */
373
+ browser: boolean | null;
373
374
  }
374
375
 
375
376
  export interface FileEntry {
@@ -381,10 +382,14 @@ export interface FileEntry {
381
382
  mtime: number;
382
383
  }
383
384
 
384
- export interface DirListing { type: "dir"; path: string; entries: FileEntry[]; truncated: boolean }
385
+ export interface DirListing { type: "dir"; path: string; entries: FileEntry[]; truncated: boolean; /** 目录里的条目总数(新版节点给)。 */ total?: number }
385
386
  export interface FileInfo { type: "file"; path: string; name: string; size: number; mtime: number; contentType: string; inline: boolean }
386
387
 
387
- export interface DiffFile { path: string; status: string; additions: number; deletions: number; binary: boolean; patch: string; truncated?: boolean }
388
+ export interface DiffFile {
389
+ path: string; status: string; additions: number; deletions: number; binary: boolean; patch: string; truncated?: boolean;
390
+ /** 改动太多,这个文件的 diff 没有带上(节点对整个 diff 有总量上限);文件本身照常可以打开。 */
391
+ omitted?: boolean;
392
+ }
388
393
  /** Operator 的 /api/tasks/:id/diff(经 center 原样转发)。 */
389
394
  export interface DiffResult {
390
395
  isolated?: boolean;
@@ -395,6 +400,8 @@ export interface DiffResult {
395
400
  isDirty?: boolean;
396
401
  ahead?: number;
397
402
  alreadyMerged?: boolean;
403
+ /** 因为总量上限没带 diff 的文件数。 */
404
+ patchesOmitted?: number;
398
405
  error?: string;
399
406
  /** 有的节点只给一整段 unified diff。 */
400
407
  diff?: string;
@@ -420,4 +427,12 @@ export interface BrowserStatus {
420
427
  export type BrowserMessage =
421
428
  | { type: "frame"; data: string; metadata?: { deviceWidth: number; deviceHeight: number } }
422
429
  | { type: "page"; url?: string; title?: string }
423
- | { type: "error"; message?: string };
430
+ | { type: "error"; message?: string }
431
+ /** 按了复制 / 剪切:选中的文字(只发给按键的人),写进本机剪贴板。 */
432
+ | { type: "clipboard"; text: string }
433
+ /** 网页弹出了 alert / confirm / prompt(画面里看不到,单独显示)。 */
434
+ | { type: "dialog"; dialogType: "alert" | "confirm" | "prompt" | "beforeunload"; message: string; defaultPrompt?: string }
435
+ | { type: "dialog_closed" };
436
+
437
+ /** 浏览器实时连接(GET /browser/live)的画面连接状况。 */
438
+ export type BrowserFramesState = { state: "idle" | "connecting" | "live" | "retrying"; detail?: string };
@@ -0,0 +1,142 @@
1
+ // Excel(.xlsx / .xlsm)→ 纯文本:每个工作表一段 CSV,发给智能体。
2
+ //
3
+ // .xlsx 是 ZIP 里的一堆 XML:workbook.xml 列出工作表,sharedStrings.xml 是共享字符串,worksheets/sheetN.xml 是单元格。
4
+ // 只取单元格的值(公式取缓存的结果),不要格式、图片、图表;日期按单元格格式认出来写成 2026-08-10(带时间的加上时分),
5
+ // 百分比写成 0.6%(和表格里看到的一致)。
6
+ // 老版 .xls(二进制)读不了,调用方提示另存为 .xlsx。
7
+
8
+ export interface SheetText { name: string; hidden: boolean; rows: string[][] }
9
+
10
+ const NS_MAIN = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
11
+ const NS_REL = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
12
+
13
+ /** 内置的日期 / 时间数字格式编号。 */
14
+ const BUILTIN_DATE_FMTS = new Set([14, 15, 16, 17, 18, 19, 20, 21, 22, 27, 30, 36, 45, 46, 47, 50, 57]);
15
+
16
+ const parseXml = (text: string) => new DOMParser().parseFromString(text, "application/xml");
17
+ const els = (root: Document | Element, tag: string) => Array.from(root.getElementsByTagNameNS(NS_MAIN, tag));
18
+
19
+ /** 「A1」→ 列号(从 0 开始)。 */
20
+ export function columnIndex(ref: string) {
21
+ let n = 0;
22
+ for (const ch of ref) {
23
+ const c = ch.toUpperCase().charCodeAt(0);
24
+ if (c < 65 || c > 90) break;
25
+ n = n * 26 + (c - 64);
26
+ }
27
+ return n - 1;
28
+ }
29
+
30
+ /** 自定义格式里有年月日时(引号里的、[颜色] 不算)就当日期。 */
31
+ function isDateFormat(code: string) {
32
+ const bare = code.replace(/"[^"]*"/g, "").replace(/\[[^\]]*\]/g, "").replace(/\\./g, "");
33
+ return /[ymdhs]/i.test(bare) && !/^[#0.,%E+\-\s]*$/i.test(bare);
34
+ }
35
+
36
+ /** Excel 序列日期 → 2026-08-10 / 2026-08-10 14:30。 */
37
+ export function excelDate(serial: number) {
38
+ const ms = Math.round((serial - 25569) * 86_400_000); // 1970-01-01 = 25569
39
+ const d = new Date(ms);
40
+ if (Number.isNaN(d.getTime())) return String(serial);
41
+ const p = (n: number) => String(n).padStart(2, "0");
42
+ const date = `${d.getUTCFullYear()}-${p(d.getUTCMonth() + 1)}-${p(d.getUTCDate())}`;
43
+ const secs = d.getUTCHours() * 3600 + d.getUTCMinutes() * 60 + d.getUTCSeconds();
44
+ if (!secs) return date;
45
+ const time = `${p(d.getUTCHours())}:${p(d.getUTCMinutes())}${d.getUTCSeconds() ? `:${p(d.getUTCSeconds())}` : ""}`;
46
+ return serial < 1 ? time : `${date} ${time}`;
47
+ }
48
+
49
+ /** 单元格里的文字:<t> 连起来(富文本是多段 <r><t>),不要注音(<rPh>)。 */
50
+ function richText(el: Element) {
51
+ return els(el, "t").filter((t) => t.parentElement?.localName !== "rPh").map((t) => t.textContent ?? "").join("");
52
+ }
53
+
54
+ /** 读出所有工作表(按工作簿里的顺序)。 */
55
+ export async function readXlsx(data: ArrayBuffer): Promise<SheetText[]> {
56
+ // 按需加载(mammoth 也用它,不额外增加体积)。
57
+ const mod = (await import("jszip")) as unknown as { default?: typeof import("jszip") } & typeof import("jszip");
58
+ const JSZip = mod.default ?? mod;
59
+ const zip = await JSZip.loadAsync(data);
60
+ const read = async (path: string) => { const f = zip.file(path); return f ? f.async("string") : null; };
61
+
62
+ const workbook = await read("xl/workbook.xml");
63
+ if (!workbook) throw new Error("不是 Excel 工作簿");
64
+ const rels = new Map<string, string>();
65
+ const relsXml = await read("xl/_rels/workbook.xml.rels");
66
+ if (relsXml) {
67
+ for (const r of Array.from(parseXml(relsXml).getElementsByTagName("Relationship"))) {
68
+ const target = r.getAttribute("Target") ?? "";
69
+ rels.set(r.getAttribute("Id") ?? "", target.startsWith("/") ? target.slice(1) : `xl/${target}`);
70
+ }
71
+ }
72
+ const shared: string[] = [];
73
+ const sharedXml = await read("xl/sharedStrings.xml");
74
+ if (sharedXml) for (const si of els(parseXml(sharedXml), "si")) shared.push(richText(si));
75
+
76
+ // 哪些样式是日期 / 百分比:cellXfs 第 i 个 → numFmtId → 内置格式或自定义格式。
77
+ const dateStyles = new Set<number>();
78
+ const percentStyles = new Set<number>();
79
+ const stylesXml = await read("xl/styles.xml");
80
+ if (stylesXml) {
81
+ const styles = parseXml(stylesXml);
82
+ const custom = new Map(els(styles, "numFmt").map((f) => [Number(f.getAttribute("numFmtId")), f.getAttribute("formatCode") ?? ""]));
83
+ const xfs = els(styles, "cellXfs")[0];
84
+ if (xfs) {
85
+ Array.from(xfs.children).filter((x) => x.localName === "xf").forEach((xf, i) => {
86
+ const id = Number(xf.getAttribute("numFmtId") ?? 0);
87
+ const code = custom.get(id);
88
+ if (BUILTIN_DATE_FMTS.has(id) || (code !== undefined && isDateFormat(code))) dateStyles.add(i);
89
+ else if (id === 9 || id === 10 || (code !== undefined && code.replace(/"[^"]*"/g, "").includes("%"))) percentStyles.add(i);
90
+ });
91
+ }
92
+ }
93
+
94
+ const sheets: SheetText[] = [];
95
+ for (const s of els(parseXml(workbook), "sheet")) {
96
+ const name = s.getAttribute("name") ?? `Sheet${sheets.length + 1}`;
97
+ const path = rels.get(s.getAttributeNS(NS_REL, "id") ?? s.getAttribute("r:id") ?? "") ?? `xl/worksheets/sheet${sheets.length + 1}.xml`;
98
+ const xml = await read(path);
99
+ if (!xml) continue;
100
+ const rows: string[][] = [];
101
+ for (const row of els(parseXml(xml), "row")) {
102
+ const r = Number(row.getAttribute("r")) || rows.length + 1;
103
+ const cells: string[] = [];
104
+ let next = 0;
105
+ for (const c of Array.from(row.children).filter((x) => x.localName === "c")) {
106
+ const ref = c.getAttribute("r");
107
+ const col = ref ? columnIndex(ref) : next;
108
+ next = col + 1;
109
+ const type = c.getAttribute("t");
110
+ const v = els(c, "v")[0]?.textContent ?? "";
111
+ let value: string;
112
+ if (type === "s") value = shared[Number(v)] ?? "";
113
+ else if (type === "inlineStr") value = richText(c);
114
+ else if (type === "b") value = v === "1" ? "TRUE" : v === "0" ? "FALSE" : v;
115
+ else if (type === "str" || type === "e" || !v) value = v;
116
+ else if (dateStyles.has(Number(c.getAttribute("s") ?? -1)) && Number.isFinite(Number(v))) value = excelDate(Number(v));
117
+ else if (percentStyles.has(Number(c.getAttribute("s") ?? -1)) && Number.isFinite(Number(v))) value = `${Number((Number(v) * 100).toPrecision(12))}%`;
118
+ else value = v;
119
+ cells[col] = value;
120
+ }
121
+ rows[r - 1] = Array.from(cells, (x) => x ?? "");
122
+ }
123
+ const dense = Array.from(rows, (x) => x ?? []);
124
+ // 去掉末尾的空行、每行末尾的空格子。
125
+ while (dense.length && dense[dense.length - 1].every((x) => !x)) dense.pop();
126
+ for (const row of dense) while (row.length && !row[row.length - 1]) row.pop();
127
+ sheets.push({ name, hidden: (s.getAttribute("state") ?? "visible") !== "visible", rows: dense });
128
+ }
129
+ return sheets;
130
+ }
131
+
132
+ const csvCell = (v: string) => (/[",\n\r]/.test(v) ? `"${v.replace(/"/g, '""')}"` : v);
133
+
134
+ /** 工作表 → 发给智能体的文字:每个工作表一个标题 + CSV。 */
135
+ export function sheetsToText(sheets: SheetText[]) {
136
+ return sheets
137
+ .map((s) => {
138
+ const head = `## 工作表:${s.name}${s.hidden ? "(隐藏)" : ""}(${s.rows.length} 行)`;
139
+ return s.rows.length ? `${head}\n${s.rows.map((r) => r.map(csvCell).join(",")).join("\n")}` : `${head}\n(空)`;
140
+ })
141
+ .join("\n\n");
142
+ }
package/src/elements.tsx CHANGED
@@ -10,6 +10,8 @@
10
10
  * <cli-board group="a"></cli-board> (右侧看板:文件 / 改动 / 浏览器;对话里点文件会在这里打开)
11
11
  * <cli-file-preview job-id="job_x" path="outputs/报告.md"></cli-file-preview> (单独的文件预览 + 下载)
12
12
  * <cli-browser job-id="job_x"></cli-browser> (单独的浏览器实时画面)
13
+ * <cli-split storage-key="a"> <cli-msglist …/> <cli-chat …/> <cli-board …/> </cli-split>
14
+ * (可拖动分栏:子元素每个是一栏,栏之间左右拖动改宽度;panes='[{"size":300},{},{"size":"42%"}]')
13
15
  *
14
16
  * 同一个 group 的元素共享一个仓库,切换时一起变:列表点哪个,对话和看板就显示哪个;不写 group 各自独立。
15
17
  * 要一起切换,group 里的元素就不要写 job-id(写了的只看自己那个);从外面打开某个对话,给任意一个元素写
@@ -31,9 +33,15 @@ import { CliChat } from "./chat/CliChat.js";
31
33
  import { CliBoard, type BoardTab } from "./board/CliBoard.js";
32
34
  import { CliBrowserView, CliFilePreview } from "./board/blocks.js";
33
35
  import { createCliStore, type CliStore } from "./core/store.js";
36
+ import { convKey } from "./core/conversation.js";
37
+ import type { CliWorkspace } from "./board/workspace.js";
38
+ import { attachSplit, type SplitHandle } from "./layout/split.js";
34
39
 
35
40
  const groups = new Map<string, CliStore>();
36
41
 
42
+ // 服务端渲染(Next.js 等)时没有 HTMLElement:模块照样能导入,defineCliElements() 在服务端什么都不做。
43
+ const Base = (typeof HTMLElement === "undefined" ? class {} : HTMLElement) as typeof HTMLElement;
44
+
37
45
  function storeFor(el: HTMLElement): CliStore | undefined {
38
46
  const group = el.getAttribute("group");
39
47
  if (!group) return undefined;
@@ -47,7 +55,7 @@ function storeFor(el: HTMLElement): CliStore | undefined {
47
55
  return store;
48
56
  }
49
57
 
50
- const ATTRS = ["base-url", "token", "line", "namespace", "group", "selected-id", "job-id", "task-id", "title", "color", "theme", "context", "read-only", "config", "new-conversation", "tabs", "default-tab", "file-open", "path"];
58
+ const ATTRS = ["base-url", "token", "line", "namespace", "group", "selected-id", "job-id", "task-id", "title", "color", "theme", "context", "read-only", "config", "new-conversation", "tabs", "default-tab", "file-open", "path", "no-quote", "hidden"];
51
59
 
52
60
  function jsonAttr(el: HTMLElement, name: string): object | undefined {
53
61
  const raw = el.getAttribute(name);
@@ -65,7 +73,7 @@ function storeOptions(el: HTMLElement) {
65
73
  };
66
74
  }
67
75
 
68
- abstract class CliElement extends HTMLElement {
76
+ abstract class CliElement extends Base {
69
77
  static observedAttributes = ATTRS;
70
78
  private root: Root | null = null;
71
79
  private ownStore: CliStore | undefined;
@@ -80,9 +88,40 @@ abstract class CliElement extends HTMLElement {
80
88
  if (this.root) this.render();
81
89
  }
82
90
 
91
+ /** 这个元素用的仓库(同一个 group 的元素共用一个)。高级用法:store.on(...)、store.select(...)。 */
92
+ get store(): CliStore {
93
+ return storeFor(this) ?? (this.ownStore ??= createCliStore(storeOptions(this)));
94
+ }
95
+ /** 元素自己写的对话(job-id + task-id);没写时 null(跟着这一组的选中走)。 */
96
+ private ownKey(): string | null {
97
+ const job = this.getAttribute("job-id");
98
+ if (!job) return null;
99
+ const task = this.getAttribute("task-id");
100
+ return task ? convKey(job, task) : job;
101
+ }
102
+ /**
103
+ * 工作区文件接口:列文件、读文件、下载、打包、当前打开的文件。不传 jobId = 这个元素看的对话(没写 job-id 时是这一组选中的)。
104
+ * 看板可以隐藏(<cli-board hidden>)或者干脆不放,接口照样能用。
105
+ */
106
+ workspace(jobId?: string): CliWorkspace {
107
+ return this.store.workspace(jobId ?? this.ownKey() ?? undefined);
108
+ }
109
+ /**
110
+ * 追加项目背景:下一条消息发出时一起带给智能体。opts.jobId 不传 = 这个元素看的对话(还没有对话时,随新对话的第一条消息带上)。
111
+ * 返回这条背景的 id(同一个 id 再追加会替换)。
112
+ */
113
+ appendContext(text: string, opts: { title?: string; id?: string; jobId?: string } = {}): string {
114
+ const key = opts.jobId ?? this.ownKey() ?? this.store.getState().selected;
115
+ return this.store.appendContext(key, text, { title: opts.title, id: opts.id });
116
+ }
117
+ /** 去掉还没发出的补充背景(不传 id = 全部)。 */
118
+ removeContext(id?: string, jobId?: string) {
119
+ this.store.removeContext(jobId ?? this.ownKey() ?? this.store.getState().selected, id);
120
+ }
121
+
83
122
  connectedCallback() {
84
- // 缺省撑满父容器;组件自己内部滚动(宿主给定高度即可)。
85
- this.style.display ||= "block";
123
+ // 缺省撑满父容器;组件自己内部滚动(宿主给定高度即可)。hidden:不显示、不连接(接口照样能用)。
124
+ this.syncHidden();
86
125
  this.style.height ||= "100%";
87
126
  this.style.minHeight ||= "0";
88
127
  this.root ??= createRoot(this);
@@ -92,17 +131,23 @@ abstract class CliElement extends HTMLElement {
92
131
  // 移动节点时会先断开再连上:推到下一轮再卸载。
93
132
  queueMicrotask(() => { if (!this.isConnected) { this.root?.unmount(); this.root = null; } });
94
133
  }
95
- attributeChangedCallback() { if (this.root) this.render(); }
134
+ attributeChangedCallback() { this.syncHidden(); if (this.root) this.render(); }
135
+ private syncHidden() {
136
+ if (this.hasAttribute("hidden")) this.style.display = "none";
137
+ else if (!this.style.display || this.style.display === "none") this.style.display = "block";
138
+ }
96
139
 
97
140
  private appliedSelection: string | null = null;
98
- protected common() {
99
- const store = storeFor(this) ?? (this.ownStore ??= createCliStore(storeOptions(this)));
100
- // selected-id:这一组一起看哪个对话。属性变了才切(列表点击换了选中,不会被属性拉回去)。
141
+ /** selected-id:这一组一起看哪个对话。属性变了才切(列表点击换了选中,不会被属性拉回去)。隐藏的元素也生效。 */
142
+ private applySelection() {
101
143
  const selection = this.getAttribute("selected-id");
102
144
  if (selection !== null && selection !== this.appliedSelection) {
103
145
  this.appliedSelection = selection;
104
- store.select(selection || null);
146
+ this.store.select(selection || null);
105
147
  }
148
+ }
149
+ protected common() {
150
+ const store = this.store;
106
151
  return {
107
152
  store,
108
153
  title: this.getAttribute("title") ?? undefined,
@@ -117,7 +162,11 @@ abstract class CliElement extends HTMLElement {
117
162
  };
118
163
  }
119
164
  protected abstract element(): React.ReactNode;
120
- private render() { this.root?.render(this.element()); }
165
+ // 隐藏的元素什么都不渲染:不轮询、不占连接;workspace() / appendContext() 照样能用。
166
+ private render() {
167
+ this.applySelection();
168
+ this.root?.render(this.hasAttribute("hidden") ? null : this.element());
169
+ }
121
170
  }
122
171
 
123
172
  class CliMsgListElement extends CliElement {
@@ -146,7 +195,9 @@ class CliBoardElement extends CliElement {
146
195
  // 结果事件只由 <cli-chat> 发(同上);看板只发 cli-event。
147
196
  const { onTurnEnd: _a, onConversationEnd: _b, onCallback: _c, title: _t, color: _k, config: _g, ...common } = this.common();
148
197
  const taskId = this.getAttribute("task-id");
149
- return <CliBoard {...common} {...(jobId !== null ? { jobId: jobId || null } : {})} {...(taskId ? { taskId } : {})} tabs={tabs?.length ? tabs : undefined} defaultTab={defaultTab} readOnly={this.hasAttribute("read-only")} />;
198
+ return <CliBoard {...common} {...(jobId !== null ? { jobId: jobId || null } : {})} {...(taskId ? { taskId } : {})} tabs={tabs?.length ? tabs : undefined} defaultTab={defaultTab} readOnly={this.hasAttribute("read-only")}
199
+ // 同一个 group 里有对话:看板里「引用到对话」带进那个对话的下一条消息;no-quote 关掉。
200
+ quoteToChat={this.hasAttribute("group") && !this.hasAttribute("no-quote")} />;
150
201
  }
151
202
  }
152
203
 
@@ -166,10 +217,54 @@ class CliBrowserElement extends CliElement {
166
217
  }
167
218
  }
168
219
 
220
+ /** <cli-split>:可拖动分栏(规则见 layout/split.ts)。属性 panes(JSON,每栏 size / min / max)、storage-key(记住宽度)。 */
221
+ class CliSplitElement extends Base {
222
+ static observedAttributes = ["panes", "storage-key"];
223
+ private handle: SplitHandle | null = null;
224
+ private options() {
225
+ let panes: unknown;
226
+ try { panes = JSON.parse(this.getAttribute("panes") ?? "null"); } catch { panes = null; }
227
+ return {
228
+ ...(Array.isArray(panes) ? { panes } : {}),
229
+ storageKey: this.getAttribute("storage-key") ?? undefined,
230
+ onResize: (sizes: (number | null)[]) => this.dispatchEvent(new CustomEvent("cli-resize", { detail: { sizes } })),
231
+ };
232
+ }
233
+ connectedCallback() {
234
+ this.style.height ||= "100%";
235
+ this.handle ??= attachSplit(this, this.options());
236
+ }
237
+ disconnectedCallback() {
238
+ queueMicrotask(() => { if (!this.isConnected) { this.handle?.destroy(); this.handle = null; } });
239
+ }
240
+ attributeChangedCallback() { this.handle?.update(this.options()); }
241
+ }
242
+
169
243
  export function defineCliElements() {
244
+ if (typeof customElements === "undefined") return;
170
245
  if (!customElements.get("cli-msglist")) customElements.define("cli-msglist", CliMsgListElement);
171
246
  if (!customElements.get("cli-chat")) customElements.define("cli-chat", CliChatElement);
172
247
  if (!customElements.get("cli-board")) customElements.define("cli-board", CliBoardElement);
173
248
  if (!customElements.get("cli-file-preview")) customElements.define("cli-file-preview", CliFilePreviewElement);
174
249
  if (!customElements.get("cli-browser")) customElements.define("cli-browser", CliBrowserElement);
250
+ if (!customElements.get("cli-split")) customElements.define("cli-split", CliSplitElement);
251
+ }
252
+
253
+ /** 元素上给业务方用的方法(<cli-msglist> / <cli-chat> / <cli-board> / <cli-file-preview> / <cli-browser> 都有)。 */
254
+ export interface CliElementApi extends HTMLElement {
255
+ readonly store: CliStore;
256
+ config: object | undefined;
257
+ workspace(jobId?: string): CliWorkspace;
258
+ appendContext(text: string, opts?: { title?: string; id?: string; jobId?: string }): string;
259
+ removeContext(id?: string, jobId?: string): void;
260
+ }
261
+
262
+ declare global {
263
+ interface HTMLElementTagNameMap {
264
+ "cli-msglist": CliElementApi;
265
+ "cli-chat": CliElementApi;
266
+ "cli-board": CliElementApi;
267
+ "cli-file-preview": CliElementApi;
268
+ "cli-browser": CliElementApi;
269
+ }
175
270
  }
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  * cli-chat 对话(CliChat)
6
6
  * cli-board 右侧看板:工作区文件(预览 / 下载)、改动、任务浏览器(CliBoard)
7
7
  * 其中两个核心也能单独用:CliFilePreview(文件预览 + 下载)、CliBrowserView(浏览器实时画面)
8
+ * CliSplit 可拖动分栏:把上面几个横着排,栏之间左右拖动改宽度(Web Component:<cli-split>)
8
9
  *
9
10
  * 单独用:
10
11
  * <CliChat baseUrl="/api/center" jobId="job_xxx" />
@@ -20,17 +21,21 @@
20
21
  */
21
22
  export { CliMsgList, type CliMsgListProps } from "./msglist/CliMsgList.js";
22
23
  export { CliChat, type CliChatProps } from "./chat/CliChat.js";
23
- export { CliBoard, type CliBoardProps, type BoardTab } from "./board/CliBoard.js";
24
+ export { CliBoard, type CliBoardProps, type BoardTab, type BoardExtraTab } from "./board/CliBoard.js";
25
+ export { downloadFolder, zipFolder, listFolder, FOLDER_MAX_FILES, FOLDER_MAX_BYTES, type FolderResult, type FolderZip, type FolderProgress } from "./board/folderDownload.js";
26
+ export { createWorkspace, WORKSPACE_TEXT_MAX, WORKSPACE_LIST_MAX, WORKSPACE_FILE_MAX, type CliWorkspace, type BoardView } from "./board/workspace.js";
24
27
  export { CliFilePreview, CliBrowserView, type CliFilePreviewProps, type CliBrowserViewProps } from "./board/blocks.js";
25
28
  export { FileViewer, downloadFile, type FileViewerProps, type FileAction } from "./board/FileViewer.js";
26
29
  export { BrowserPane } from "./board/BrowserPane.js";
30
+ export { CliSplit, type CliSplitProps } from "./layout/CliSplit.js";
31
+ export { attachSplit, type SplitPane, type SplitOptions, type SplitHandle } from "./layout/split.js";
27
32
  export { CliCenterProvider, useCliStore, useCliState, type CliCenterProviderProps, type ResultHandlers } from "./core/provider.js";
28
33
 
29
34
  export {
30
35
  resolveChatConfig, resolveMsgListConfig, DEFAULT_CHAT_CONFIG, DEFAULT_MSGLIST_CONFIG,
31
36
  type CliChatConfig, type CliMsgListConfig, type ResolvedChatConfig, type ResolvedMsgListConfig,
32
37
  } from "./core/config.js";
33
- export { createCliStore, type CliStore, type CliStoreOptions, type CliState, type CliEvent, type JobEntry, type OpenTarget } from "./core/store.js";
38
+ export { createCliStore, CONTEXT_ITEM_MAX, type CliStore, type CliStoreOptions, type CliState, type CliEvent, type JobEntry, type OpenTarget, type BoardRef, type ContextItem } from "./core/store.js";
34
39
  export { createCenterClient, CenterError, boardFileUrl, type CenterClient, type CenterClientOptions, type StreamHandlers, type BoardBackend, type ConversationBackend } from "./core/client.js";
35
40
  export { viewMessages, isRunning, runningTurn, convKey, parseConvKey, NEW_TASK, type ConvState } from "./core/conversation.js";
36
41
  export {
@@ -0,0 +1,53 @@
1
+ /**
2
+ * 可拖动分栏(React 版)。每个子元素是一栏,栏之间可以左右拖动改宽度(规则见 split.ts)。
3
+ *
4
+ * <CliCenterProvider baseUrl="/api/center" namespace="strategy">
5
+ * <CliSplit storageKey="strategy" panes={[{ size: 300, min: 220, max: 480 }, { min: 360 }, { size: "42%", min: 320 }]}>
6
+ * <CliMsgList />
7
+ * <CliChat />
8
+ * <CliBoard />
9
+ * </CliSplit>
10
+ * </CliCenterProvider>
11
+ *
12
+ * 三个组件在同一个 Provider 里照常联动(列表选中 → 对话和看板跟着切;对话里点文件 → 看板打开),分栏只管宽度。
13
+ */
14
+ import { Children, useEffect, useRef, type CSSProperties, type ReactNode } from "react";
15
+ import { attachSplit, type SplitHandle, type SplitPane } from "./split.js";
16
+
17
+ export type CliSplitProps = {
18
+ children: ReactNode;
19
+ /** 每栏的初始宽度 / 最小 / 最大。写了 size 的是定宽栏,没写的占剩余宽度。缺省:第一栏 300px、最后一栏 42%、中间占剩余。 */
20
+ panes?: SplitPane[];
21
+ /** 记住拖好的宽度(localStorage)。 */
22
+ storageKey?: string;
23
+ onResize?: (sizes: (number | null)[]) => void;
24
+ className?: string;
25
+ style?: CSSProperties;
26
+ };
27
+
28
+ const defaultPanes = (n: number): SplitPane[] =>
29
+ n <= 1 ? [{}] : n === 2 ? [{ size: 300, min: 220, max: 520 }, { min: 360 }]
30
+ : Array.from({ length: n }, (_, i) => (i === 0 ? { size: 300, min: 220, max: 520 } : i === n - 1 ? { size: "42%", min: 320 } : { min: 360 }));
31
+
32
+ export function CliSplit({ children, panes, storageKey, onResize, className, style }: CliSplitProps) {
33
+ const ref = useRef<HTMLDivElement>(null);
34
+ const handle = useRef<SplitHandle | null>(null);
35
+ const items = Children.toArray(children).filter(Boolean);
36
+ const onResizeRef = useRef(onResize);
37
+ onResizeRef.current = onResize;
38
+ const options = { panes: panes ?? defaultPanes(items.length), storageKey, onResize: (s: (number | null)[]) => onResizeRef.current?.(s) };
39
+ const sig = JSON.stringify([options.panes, storageKey, items.length]);
40
+
41
+ useEffect(() => {
42
+ if (!ref.current) return;
43
+ handle.current = attachSplit(ref.current, options);
44
+ return () => { handle.current?.destroy(); handle.current = null; };
45
+ }, []); // eslint-disable-line react-hooks/exhaustive-deps
46
+ useEffect(() => { handle.current?.update(options); }, [sig]); // eslint-disable-line react-hooks/exhaustive-deps
47
+
48
+ return (
49
+ <div ref={ref} className={`cli-split ${className ?? ""}`} style={style}>
50
+ {items.map((child, i) => <div key={(child as { key?: string | null }).key ?? i} className="cli-split-pane">{child}</div>)}
51
+ </div>
52
+ );
53
+ }