pi-web-ui 0.109.0 → 0.111.0

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 (96) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +21 -1
  3. package/README.zh-CN.md +21 -1
  4. package/README.zh-TW.md +201 -677
  5. package/bin/frp-manager.mjs +85 -7
  6. package/dist/server/agent-formatters.js +10 -6
  7. package/dist/server/agent-service-daemon.js +29 -11
  8. package/dist/server/agent-service.js +160 -54
  9. package/dist/server/attachments.js +140 -37
  10. package/dist/server/canvas/canvas-agent-tool.js +587 -0
  11. package/dist/server/canvas/canvas-cards.js +144 -0
  12. package/dist/server/canvas/canvas-dispatch.js +155 -0
  13. package/dist/server/canvas/canvas-orchestrator.js +1027 -0
  14. package/dist/server/canvas/canvas-store.js +260 -0
  15. package/dist/server/client-id-utils.js +2 -2
  16. package/dist/server/client-state.js +24 -0
  17. package/dist/server/context-budget.js +6 -3
  18. package/dist/server/dispatch-domain-handlers.js +2 -0
  19. package/dist/server/dispatch-plugin-handlers.js +1 -0
  20. package/dist/server/dsh/dsh-agent-service.js +115 -9
  21. package/dist/server/dsh/dsh-client.js +10 -1
  22. package/dist/server/dsh/runtime/goal-rpc.mjs +128 -3
  23. package/dist/server/dsh/runtime/launcher.mjs +59 -5
  24. package/dist/server/dsh/runtime/runtime-root.mjs +353 -40
  25. package/dist/server/durable/durable-agent-service.js +3 -0
  26. package/dist/server/durable/durable-driver.js +1 -1
  27. package/dist/server/durable/durable-tools.js +4 -1
  28. package/dist/server/file-transfer-routes.js +8 -2
  29. package/dist/server/files-service.js +33 -6
  30. package/dist/server/goal-service.js +12 -3
  31. package/dist/server/index.js +175 -13
  32. package/dist/server/locales.js +33 -0
  33. package/dist/server/marker-service.js +10 -14
  34. package/dist/server/markers/builtins/action.js +5 -6
  35. package/dist/server/markers/builtins/notify.js +2 -2
  36. package/dist/server/markers/builtins/rename.js +2 -2
  37. package/dist/server/markers/marker.js +45 -4
  38. package/dist/server/markers/registry.js +36 -1
  39. package/dist/server/message-window.js +193 -0
  40. package/dist/server/model-admin.js +0 -4
  41. package/dist/server/office-parse.js +394 -7
  42. package/dist/server/plugin-api-catalog.js +6 -0
  43. package/dist/server/plugin-catalog-sync.js +10 -2
  44. package/dist/server/plugin-catalog.js +63 -10
  45. package/dist/server/plugins.js +144 -26
  46. package/dist/server/preset-fields.js +35 -1
  47. package/dist/server/preset-share.js +5 -3
  48. package/dist/server/process-utils.js +58 -24
  49. package/dist/server/prompt-assembler.js +7 -1
  50. package/dist/server/prompt-composer.js +66 -36
  51. package/dist/server/protocol-version.js +1 -1
  52. package/dist/server/remote-ssh-service.js +16 -4
  53. package/dist/server/settings-service.js +24 -3
  54. package/dist/server/slash-commands.js +16 -4
  55. package/dist/server/text-sniff.js +10 -7
  56. package/dist/server/themes.js +36 -1
  57. package/dist/server/tool-manager.js +30 -0
  58. package/dist/server/univer-service.js +448 -0
  59. package/dist/server/universal/drivers/claude-code.js +19 -2
  60. package/dist/server/universal/drivers/dsh-driver.js +1 -1
  61. package/dist/server/universal/universal-attachments.js +5 -0
  62. package/dist/server/universal/universal-service.js +5 -0
  63. package/dist/server/universal/universal-session.js +38 -15
  64. package/dist/server/update-check.js +90 -5
  65. package/dist/server/workspace-snapshot.js +33 -2
  66. package/dist/server/worktree-service.js +1 -1
  67. package/docs/dsh-engine.md +497 -0
  68. package/package.json +11 -5
  69. package/plugin-sdk/index.d.ts +37 -0
  70. package/plugin-sdk/index.mjs +19 -0
  71. package/plugins/catalog.json +44 -2
  72. package/themes/aetheris.css +263 -118
  73. package/themes/bases/flow-base.css +1363 -0
  74. package/themes/bases/obsidian-base.css +895 -0
  75. package/themes/bases/zhujian-base.css +687 -0
  76. package/themes/bases/zhupi-base.css +659 -0
  77. package/themes/flow-light.css +2 -925
  78. package/themes/flow.css +1 -936
  79. package/themes/md-preview.css +113 -0
  80. package/themes/wallpaper-flow.css +251 -1029
  81. package/themes/wallpaper-obsidian.css +1 -673
  82. package/themes/zhujian-dark.css +1 -605
  83. package/themes/zhujian.css +1 -654
  84. package/themes/zhupi-dark.css +1 -576
  85. package/themes/zhupi.css +1 -626
  86. package/web/dist/assets/{TerminalPanel-BD3a9o-a.js → TerminalPanel-BiUNySMA.js} +2 -2
  87. package/web/dist/assets/index-B0ajS__T.js +697 -0
  88. package/web/dist/assets/index-BHik5WGG.css +1 -0
  89. package/web/dist/assets/{markdown-DXwnfD9T.js → markdown-BJZlfvdP.js} +24 -24
  90. package/web/dist/assets/markdown-DSNUiDzp.css +1 -0
  91. package/web/dist/index.html +4 -4
  92. package/web/dist/sw.js +1 -1
  93. package/web/dist/assets/es-DIDZppIF.js +0 -2
  94. package/web/dist/assets/index-AccytlpP.css +0 -1
  95. package/web/dist/assets/index-B3dar1BK.js +0 -690
  96. package/web/dist/assets/markdown-CCeVCbci.css +0 -1
@@ -4,6 +4,7 @@ import { saveUpload, uploadsRoot } from "./uploads.js";
4
4
  import { isAbsoluteWirePath, wireToAbs } from "./files-service.js";
5
5
  import { buildVisionBridgePrompt, findVisionModels, transcribeImages } from "./vision-bridge.js";
6
6
  import { saveAttachment } from "./attachment-store.js";
7
+ import { getGlobalRemoteSshService, isRemoteWorkspaceUri, parseRemoteWorkspaceUri, resolveRemoteWorkspacePath, } from "./remote-ssh-service.js";
7
8
  /** 跨快照的视觉转写缓存:批次 hash(名称 + base64 头 + 提示词)→ 转写文本。
8
9
  * 编辑重问重发相同图片不再重复耗视觉 token。进程级共享即可。
9
10
  * 长驻进程下无界 Map 会随图片种类缓慢吃内存(单条转写可达数十 KB),
@@ -36,8 +37,38 @@ export async function buildAttachmentMessages(ctx, attachments) {
36
37
  if (!attachments || attachments.length === 0)
37
38
  return [];
38
39
  const fs = await import("node:fs/promises");
39
- const { resolve, sep, relative, extname, basename } = await import("node:path");
40
- const root = resolve(ctx.cwd);
40
+ const { resolve, sep, relative, extname, basename, posix } = await import("node:path");
41
+ const isRemote = isRemoteWorkspaceUri(ctx.cwd);
42
+ const remoteParsed = isRemote ? parseRemoteWorkspaceUri(ctx.cwd) : null;
43
+ const remoteRoot = remoteParsed ? remoteParsed.remotePath : "/";
44
+ const sshSvc = isRemote ? getGlobalRemoteSshService() : null;
45
+ const root = isRemote ? "" : resolve(ctx.cwd);
46
+ const resolveTarget = (attPath) => {
47
+ if (isRemote) {
48
+ let clean = attPath.trim();
49
+ if (isRemoteWorkspaceUri(clean)) {
50
+ const p = parseRemoteWorkspaceUri(clean);
51
+ if (p)
52
+ clean = p.remotePath;
53
+ }
54
+ if (clean.startsWith("/")) {
55
+ const abs = posix.normalize(clean);
56
+ const rawRel = posix.relative(remoteRoot, abs);
57
+ const isOutside = rawRel.startsWith("..") || rawRel.includes("/..");
58
+ return { abs, rel: isOutside ? abs : rawRel || ".", isOutside: false };
59
+ }
60
+ const w = resolveRemoteWorkspacePath(remoteRoot, clean);
61
+ if (!w)
62
+ return null;
63
+ return { abs: w.abs, rel: w.rel || ".", isOutside: false };
64
+ }
65
+ const absPath = isAbsoluteWirePath(attPath);
66
+ const abs = absPath ? wireToAbs(attPath) : resolve(root, attPath);
67
+ const rawRel = absPath ? null : relative(root, abs);
68
+ const isOutside = !absPath && (rawRel.startsWith("..") || rawRel.includes(`${sep}..`));
69
+ const rel = absPath ? abs.split(sep).join("/") : rawRel.split(sep).join("/");
70
+ return { abs, rel, isOutside };
71
+ };
41
72
  const MAX_ATTACHMENT_BYTES = 200 * 1024;
42
73
  const IMAGE_EXT = new Set([".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".svg"]);
43
74
  const MIME = {
@@ -111,23 +142,42 @@ export async function buildAttachmentMessages(ctx, attachments) {
111
142
  const ext = extname(att.path).toLowerCase();
112
143
  if (!IMAGE_EXT.has(ext) || ext === ".svg")
113
144
  continue;
114
- // 机器浏览的绝对路径(盘符 / posix "/")允许在工作区之外。
115
- const absPath = isAbsoluteWirePath(att.path);
116
- const abs = absPath ? wireToAbs(att.path) : resolve(root, att.path);
117
- const rawRel = absPath ? null : relative(root, abs);
118
- if (!absPath && (rawRel.startsWith("..") || rawRel.includes(`${sep}..`)))
145
+ const target = resolveTarget(att.path);
146
+ if (!target || target.isOutside)
119
147
  continue;
120
148
  let st;
121
- try {
122
- st = await fs.stat(abs);
149
+ if (isRemote) {
150
+ if (!sshSvc)
151
+ continue;
152
+ try {
153
+ const s = await sshSvc.sftpStat(ctx.cwd, target.abs);
154
+ st = { size: s.size, isFile: s.isFile };
155
+ }
156
+ catch {
157
+ continue;
158
+ }
123
159
  }
124
- catch {
160
+ else {
161
+ try {
162
+ const s = await fs.stat(target.abs);
163
+ st = { size: s.size, isFile: s.isFile() };
164
+ }
165
+ catch {
166
+ continue;
167
+ }
168
+ }
169
+ if (!st.isFile || st.size === 0 || st.size > MAX_PATH_IMAGE_BYTES) {
125
170
  continue;
126
171
  }
127
- if (!st.isFile() || st.size === 0 || st.size > MAX_PATH_IMAGE_BYTES) {
172
+ let buf;
173
+ try {
174
+ buf = isRemote
175
+ ? (await sshSvc.sftpReadFile(ctx.cwd, target.abs, MAX_PATH_IMAGE_BYTES)).data
176
+ : await fs.readFile(target.abs);
177
+ }
178
+ catch {
128
179
  continue;
129
180
  }
130
- const buf = await fs.readFile(abs);
131
181
  const mime = sniffImageMime(buf, ext);
132
182
  if (!mime)
133
183
  continue;
@@ -508,10 +558,8 @@ export async function buildAttachmentMessages(ctx, attachments) {
508
558
  pushUploadAside(att.name ?? basename(abs), abs.split(sep).join("/"), buf);
509
559
  continue;
510
560
  }
511
- const absPath = isAbsoluteWirePath(att.path);
512
- const abs = absPath ? wireToAbs(att.path) : resolve(root, att.path);
513
- const rawRel = absPath ? null : relative(root, abs);
514
- if (!absPath && (rawRel.startsWith("..") || rawRel.includes(`${sep}..`))) {
561
+ const target = resolveTarget(att.path);
562
+ if (!target || target.isOutside) {
515
563
  ctx.emit({
516
564
  type: "notice",
517
565
  level: "warning",
@@ -520,22 +568,49 @@ export async function buildAttachmentMessages(ctx, attachments) {
520
568
  });
521
569
  continue;
522
570
  }
523
- // Normalize to forward slashes (relative() returns "\\" on Windows);
524
- // <file path> and details.path must use the wire format. 机器浏览的绝对
525
- // 路径直接按绝对路径引用(SDK 读文件工具接受绝对路径,与上传文件一致)。
526
- const rel = absPath ? abs.split(sep).join("/") : rawRel.split(sep).join("/");
571
+ const { abs, rel } = target;
527
572
  let stat;
528
- try {
529
- stat = await fs.stat(abs);
573
+ if (isRemote) {
574
+ if (!sshSvc) {
575
+ ctx.emit({
576
+ type: "notice",
577
+ level: "error",
578
+ text: `远程 SSH 服务不可用:${att.path}`,
579
+ textEn: `Remote SSH service not available: ${att.path}`,
580
+ });
581
+ continue;
582
+ }
583
+ try {
584
+ const s = await sshSvc.sftpStat(ctx.cwd, abs);
585
+ stat = {
586
+ size: s.size,
587
+ isFile: () => s.isFile,
588
+ isDirectory: () => s.isDirectory,
589
+ };
590
+ }
591
+ catch {
592
+ ctx.emit({
593
+ type: "notice",
594
+ level: "error",
595
+ text: `附件不存在:${att.path}`,
596
+ textEn: `Attachment does not exist: ${att.path}`,
597
+ });
598
+ continue;
599
+ }
530
600
  }
531
- catch {
532
- ctx.emit({
533
- type: "notice",
534
- level: "error",
535
- text: `附件不存在:${att.path}`,
536
- textEn: `Attachment does not exist: ${att.path}`,
537
- });
538
- continue;
601
+ else {
602
+ try {
603
+ stat = await fs.stat(abs);
604
+ }
605
+ catch {
606
+ ctx.emit({
607
+ type: "notice",
608
+ level: "error",
609
+ text: `附件不存在:${att.path}`,
610
+ textEn: `Attachment does not exist: ${att.path}`,
611
+ });
612
+ continue;
613
+ }
539
614
  }
540
615
  const name = att.path.split(/[\\/]/).pop() ?? att.path;
541
616
  // Folders can't be inlined — always a path reference the model browses
@@ -634,7 +709,15 @@ ${transcript}
634
709
  });
635
710
  continue;
636
711
  }
637
- const data = await fs.readFile(abs, "base64");
712
+ let data;
713
+ try {
714
+ data = isRemote
715
+ ? (await sshSvc.sftpReadFile(ctx.cwd, abs, MAX_ATTACHMENT_BYTES)).data.toString("base64")
716
+ : await fs.readFile(abs, "base64");
717
+ }
718
+ catch {
719
+ continue;
720
+ }
638
721
  out.push({
639
722
  message: {
640
723
  customType: "file",
@@ -726,7 +809,29 @@ export function isUserMessageEntry(entry) {
726
809
  return (e.type === "message" && e.message?.role === "user") || e.type === "user" || e.role === "user";
727
810
  }
728
811
  /**
729
- * 从给定的 entry 节点开始,向上追溯属于该轮提问的前置附件 aside 节点(customType === "file" 等),
812
+ * 判断一个 entry 是否为上一轮对话结束时的有效业务节点
813
+ * (例如助手回复、工具返回、bash 执行、分支或压缩摘要,或者更早一轮的用户提问)。
814
+ */
815
+ export function isConversationTurnEntry(entry) {
816
+ if (!entry || typeof entry !== "object")
817
+ return false;
818
+ const e = entry;
819
+ if (e.type === "compaction" || e.type === "branch_summary")
820
+ return true;
821
+ if (e.type === "message" && e.message) {
822
+ const role = e.message.role;
823
+ return (role === "assistant" ||
824
+ role === "toolResult" ||
825
+ role === "bashExecution" ||
826
+ role === "branchSummary" ||
827
+ role === "compactionSummary" ||
828
+ role === "user");
829
+ }
830
+ return false;
831
+ }
832
+ /**
833
+ * 从给定的 entry 节点开始,向上追溯跳过属于该轮提问的前置附件 aside 节点(customType === "file" 等)、
834
+ * SDK 注入的系统截面(role === "system")以及配置变更节点,
730
835
  * 返回该轮提问之前的基准 entry id(作为 fork/分支截断点)。
731
836
  * 如果追溯到会话根(即该提问是会话第一轮提问),返回 null。
732
837
  */
@@ -734,7 +839,7 @@ export function findTurnBaseEntryId(sm, entryId) {
734
839
  const target = sm.getEntry(entryId);
735
840
  if (!target)
736
841
  return null;
737
- // 只有针对用户消息,才需要向上跳过属于该提问的前置附件 aside 卡片
842
+ // 只有针对用户消息,才需要向上跳过属于该提问的前置附件 aside 卡片和系统截面
738
843
  if (!isUserMessageEntry(target)) {
739
844
  const parentId = target.parentId;
740
845
  return parentId ?? null;
@@ -750,12 +855,10 @@ export function findTurnBaseEntryId(sm, entryId) {
750
855
  const parentEntry = sm.getEntry(parentId);
751
856
  if (!parentEntry)
752
857
  return null;
753
- if (isPromptAsideEntry(parentEntry)) {
754
- currentId = parentId;
755
- }
756
- else {
858
+ if (isConversationTurnEntry(parentEntry)) {
757
859
  return parentId;
758
860
  }
861
+ currentId = parentId;
759
862
  }
760
863
  return null;
761
864
  }