pi-web-ui 0.110.0 → 0.112.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 (110) hide show
  1. package/CHANGELOG.md +55 -2
  2. package/bin/frp-manager.mjs +92 -7
  3. package/dist/server/agent-formatters.js +10 -6
  4. package/dist/server/agent-service-daemon.js +27 -9
  5. package/dist/server/agent-service.js +1442 -489
  6. package/dist/server/approval-audit.js +119 -0
  7. package/dist/server/approval-default-rules.js +4 -4
  8. package/dist/server/approval-rules.js +42 -17
  9. package/dist/server/attachment-store.js +8 -8
  10. package/dist/server/attachments.js +114 -31
  11. package/dist/server/canvas/canvas-agent-tool.js +593 -0
  12. package/dist/server/canvas/canvas-cards.js +144 -0
  13. package/dist/server/canvas/canvas-dispatch.js +155 -0
  14. package/dist/server/canvas/canvas-orchestrator.js +1094 -0
  15. package/dist/server/canvas/canvas-store.js +260 -0
  16. package/dist/server/client-id-utils.js +2 -2
  17. package/dist/server/client-state.js +52 -0
  18. package/dist/server/context-budget.js +6 -3
  19. package/dist/server/delegate-mode.js +6 -3
  20. package/dist/server/delegate-task.js +18 -3
  21. package/dist/server/dispatch-domain-handlers.js +3 -0
  22. package/dist/server/dsh/dsh-agent-service.js +357 -20
  23. package/dist/server/dsh/dsh-client.js +10 -1
  24. package/dist/server/dsh/dsh-serialize.js +1 -1
  25. package/dist/server/dsh/runtime/goal-rpc.mjs +128 -3
  26. package/dist/server/dsh/runtime/launcher.mjs +59 -5
  27. package/dist/server/dsh/runtime/runtime-root.mjs +353 -40
  28. package/dist/server/durable/durable-agent-service.js +3 -0
  29. package/dist/server/durable/durable-driver.js +75 -9
  30. package/dist/server/durable/durable-loader.js +1 -14
  31. package/dist/server/durable/durable-models.js +107 -0
  32. package/dist/server/durable/index.js +0 -4
  33. package/dist/server/engine-probe.js +76 -37
  34. package/dist/server/eval-tool.js +28 -3
  35. package/dist/server/file-transfer-routes.js +8 -2
  36. package/dist/server/files-service.js +10 -2
  37. package/dist/server/goal-service.js +7 -0
  38. package/dist/server/index.js +480 -59
  39. package/dist/server/json-utils.js +57 -0
  40. package/dist/server/marker-service.js +11 -1
  41. package/dist/server/markers/marker.js +45 -4
  42. package/dist/server/markers/registry.js +31 -0
  43. package/dist/server/message-window.js +44 -8
  44. package/dist/server/model-admin.js +68 -106
  45. package/dist/server/model-resolver.js +66 -44
  46. package/dist/server/office-parse.js +394 -7
  47. package/dist/server/plan-manager.js +3 -6
  48. package/dist/server/plugin-api-catalog.js +7 -0
  49. package/dist/server/plugin-assets.js +238 -0
  50. package/dist/server/plugin-facilities.js +22 -0
  51. package/dist/server/plugin-ui-slots.js +1 -0
  52. package/dist/server/plugins.js +296 -25
  53. package/dist/server/preset-fields.js +60 -2
  54. package/dist/server/preset-share.js +8 -2
  55. package/dist/server/prompt-assembler.js +9 -2
  56. package/dist/server/prompt-composer.js +84 -44
  57. package/dist/server/protocol-version.js +1 -1
  58. package/dist/server/queue-utils.js +156 -0
  59. package/dist/server/remote-ssh-service.js +16 -4
  60. package/dist/server/sdk-builtin-extensions.js +85 -0
  61. package/dist/server/server-config.js +66 -0
  62. package/dist/server/session-parser.js +49 -13
  63. package/dist/server/session-search.js +4 -3
  64. package/dist/server/settings-service.js +56 -7
  65. package/dist/server/soft-cap.js +8 -6
  66. package/dist/server/subagent-helpers.js +22 -1
  67. package/dist/server/subagent-notify.js +93 -0
  68. package/dist/server/subagent-security-gate.js +282 -0
  69. package/dist/server/subagent-templates.js +8 -0
  70. package/dist/server/subagents.js +144 -17
  71. package/dist/server/terminals.js +196 -8
  72. package/dist/server/text-quote.js +61 -0
  73. package/dist/server/tool-approval.js +63 -4
  74. package/dist/server/tool-guards.js +208 -0
  75. package/dist/server/tool-host-factories.js +46 -10
  76. package/dist/server/tool-manager.js +30 -0
  77. package/dist/server/tool-overrides.js +21 -11
  78. package/dist/server/univer-service.js +448 -0
  79. package/dist/server/universal/driver-base.js +8 -0
  80. package/dist/server/universal/drivers/claude-code.js +39 -5
  81. package/dist/server/universal/drivers/dsh-driver.js +3 -0
  82. package/dist/server/universal/index.js +0 -1
  83. package/dist/server/universal/universal-attachments.js +5 -0
  84. package/dist/server/universal/universal-service.js +5 -0
  85. package/dist/server/universal/universal-session.js +114 -21
  86. package/dist/server/update-check.js +90 -5
  87. package/dist/server/workspace-snapshot.js +33 -2
  88. package/dist/server/worktree-service.js +189 -1
  89. package/docs/dsh-engine.md +493 -0
  90. package/package.json +5 -4
  91. package/plugin-sdk/client-utils.mjs +192 -5
  92. package/plugin-sdk/index.d.ts +80 -1
  93. package/plugin-sdk/index.mjs +99 -0
  94. package/plugin-sdk/package.json +5 -1
  95. package/plugins/catalog.json +33 -0
  96. package/themes/aetheris.css +114 -0
  97. package/themes/bases/obsidian-base.css +216 -0
  98. package/themes/md-preview.css +113 -0
  99. package/themes/wallpaper-flow.css +182 -0
  100. package/web/dist/assets/{TerminalPanel-BHjM6pzY.js → TerminalPanel-Dqr1dK28.js} +2 -2
  101. package/web/dist/assets/index-Dh8BX-lP.js +720 -0
  102. package/web/dist/assets/index-DqrC1I_a.css +1 -0
  103. package/web/dist/assets/{markdown-DXwnfD9T.js → markdown-BJZlfvdP.js} +24 -24
  104. package/web/dist/assets/markdown-DSNUiDzp.css +1 -0
  105. package/web/dist/index.html +13 -4
  106. package/web/dist/sw.js +1 -1
  107. package/web/dist/assets/es-DIDZppIF.js +0 -2
  108. package/web/dist/assets/index-DwInT7-a.css +0 -1
  109. package/web/dist/assets/index-GfVFIgIL.js +0 -693
  110. package/web/dist/assets/markdown-CCeVCbci.css +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-web-ui",
3
- "version": "0.110.0",
3
+ "version": "0.112.0",
4
4
  "description": "Just open your browser to get all your work done — browser cockpit for AI coding agents (chat, code, files, terminal, Git in one tab)",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -28,6 +28,7 @@
28
28
  "extensions/",
29
29
  "plugin-sdk/",
30
30
  "plugins/catalog.json",
31
+ "docs/dsh-engine.md",
31
32
  "CHANGELOG.md",
32
33
  "README.md",
33
34
  "LICENSE"
@@ -96,8 +97,8 @@
96
97
  "audit:diff": "node scripts/theme-diff.mjs .theme-audit/baseline .theme-audit/current"
97
98
  },
98
99
  "dependencies": {
99
- "@deepseek-ai/dsh-sdk-jsonrpc-server": "^0.1.5-rc.3",
100
- "@deepseek-ai/dsh-sdk-protocol": "^0.1.5-rc.3",
100
+ "@deepseek-ai/dsh-sdk-jsonrpc-server": "^0.2.1-rc.2",
101
+ "@deepseek-ai/dsh-sdk-protocol": "^0.2.1-rc.2",
101
102
  "compression": "^1.8.2",
102
103
  "electron-updater": "^6.8.9",
103
104
  "express": "^5.2.1",
@@ -144,7 +145,7 @@
144
145
  "highlight.js": "^11.12.0",
145
146
  "html-to-image": "^1.11.13",
146
147
  "jsdom": "^30.1.0",
147
- "katex": "^0.18.7",
148
+ "katex": "^0.16.47",
148
149
  "mermaid": "^12.0.0",
149
150
  "oxlint": "^1.83.0",
150
151
  "playwright-core": "^1.63.0",
@@ -22,7 +22,7 @@ export function esc(s) {
22
22
  * @returns {any} 宿主 API 对象或 null
23
23
  */
24
24
  export function hostApi() {
25
- return typeof window !== "undefined" ? window.__piWebUiHost ?? null : null;
25
+ return typeof window !== "undefined" ? (window.__piWebUiHost ?? null) : null;
26
26
  }
27
27
 
28
28
  /**
@@ -58,10 +58,7 @@ export function formatBytes(bytes, decimals = 1) {
58
58
  * @returns {Promise<T>}
59
59
  */
60
60
  export function withTimeout(promise, timeoutMs, errorMsg = "Operation timed out") {
61
- return Promise.race([
62
- promise,
63
- new Promise((_, reject) => setTimeout(() => reject(new Error(errorMsg)), timeoutMs)),
64
- ]);
61
+ return Promise.race([promise, new Promise((_, reject) => setTimeout(() => reject(new Error(errorMsg)), timeoutMs))]);
65
62
  }
66
63
 
67
64
  /**
@@ -90,3 +87,193 @@ export function normalizeRel(p) {
90
87
  .replace(/^\.?\/+/, "")
91
88
  .replace(/\/+$/, "");
92
89
  }
90
+
91
+ /**
92
+ * 为容器创建 Shadow DOM 并注入基础主题继承样式。
93
+ * @param {HTMLElement} hostEl 宿主容器元素
94
+ * @param {string} [customCss] 额外注入该组件的隔离样式
95
+ * @returns {ShadowRoot} 创建或已存在的 open 模式 ShadowRoot
96
+ */
97
+ export function attachShadowRoot(hostEl, customCss = "") {
98
+ let shadow = hostEl.shadowRoot;
99
+ if (!shadow) {
100
+ try {
101
+ shadow = hostEl.attachShadow({ mode: "open" });
102
+ } catch {
103
+ shadow = hostEl.shadowRoot;
104
+ }
105
+ }
106
+ if (!shadow) return hostEl;
107
+
108
+ shadow.replaceChildren();
109
+ const style = document.createElement("style");
110
+ style.textContent = `
111
+ :host {
112
+ display: block;
113
+ width: 100%;
114
+ height: 100%;
115
+ box-sizing: border-box;
116
+ color: var(--text, inherit);
117
+ font-family: inherit;
118
+ font-size: var(--text-base, 13.5px);
119
+ line-height: 1.5;
120
+ }
121
+ *, *::before, *::after {
122
+ box-sizing: inherit;
123
+ }
124
+ ${customCss}
125
+ `;
126
+ shadow.appendChild(style);
127
+ return shadow;
128
+ }
129
+
130
+ /**
131
+ * 带有 Shadow DOM 样式隔离的视图挂载辅助器。
132
+ * @param {HTMLElement} container 挂载目标容器
133
+ * @param {(root: HTMLElement) => void | (() => void)} mountFn 实际挂载函数
134
+ * @param {string} [customCss] 隔离样式
135
+ * @returns {() => void} 清理函数
136
+ */
137
+ export function mountIsolated(container, mountFn, customCss = "") {
138
+ const shadow = attachShadowRoot(container, customCss);
139
+ const inner = document.createElement("div");
140
+ inner.className = "plugin-isolated-body";
141
+ inner.style.cssText = "width:100%;height:100%;display:flex;flex-direction:column;";
142
+ shadow.appendChild(inner);
143
+
144
+ const cleanup = mountFn(inner);
145
+ return () => {
146
+ if (typeof cleanup === "function") {
147
+ try {
148
+ cleanup();
149
+ } catch {}
150
+ }
151
+ inner.replaceChildren();
152
+ shadow.replaceChildren();
153
+ };
154
+ }
155
+
156
+ const DEFAULT_CHUNK_LIMIT = 3800;
157
+ const CODE_FENCE_OPEN = /^( {0,3})(`{3,}|~{3,})(.*)$/;
158
+
159
+ /**
160
+ * 计算安全的截断位置,避免割裂 UTF-16 代理对(Surrogate Pair Emoji/特异字符)。
161
+ * @param {string} value
162
+ * @param {number} limit
163
+ * @returns {number}
164
+ */
165
+ export function safeSliceIndex(value, limit) {
166
+ let index = Math.min(limit, value.length);
167
+ if (index <= 0) return 0;
168
+ const before = value.charCodeAt(index - 1);
169
+ const after = value.charCodeAt(index);
170
+ if (before >= 0xd800 && before <= 0xdbff && after >= 0xdc00 && after <= 0xdfff) {
171
+ index -= 1;
172
+ }
173
+ return Math.max(1, index);
174
+ }
175
+
176
+ function openingFence(line) {
177
+ const normalized = line.endsWith("\r") ? line.slice(0, -1) : line;
178
+ const match = CODE_FENCE_OPEN.exec(normalized);
179
+ if (!match) return null;
180
+ if (match[2][0] === "`" && match[3].includes("`")) return null;
181
+ return { delimiter: match[2], info: match[3], indent: match[1].length };
182
+ }
183
+
184
+ function closesFence(line, opening) {
185
+ const match = /^ {0,3}(`{3,}|~{3,})[ \t]*$/.exec(line);
186
+ return Boolean(match && match[1][0] === opening.delimiter[0] && match[1].length >= opening.delimiter.length);
187
+ }
188
+
189
+ function splitRawText(text, limit) {
190
+ if (text.length <= limit) return [text];
191
+ const parts = [];
192
+ let remaining = text;
193
+ while (remaining.length > limit) {
194
+ let index = safeSliceIndex(remaining, limit);
195
+ const newline = remaining.lastIndexOf("\n", index - 1);
196
+ if (newline >= 0 && newline >= Math.floor(limit * 0.4)) {
197
+ index = newline + 1;
198
+ }
199
+ parts.push(remaining.slice(0, index));
200
+ remaining = remaining.slice(index);
201
+ }
202
+ if (remaining || parts.length === 0) parts.push(remaining);
203
+ return parts;
204
+ }
205
+
206
+ /**
207
+ * 结构感知 Markdown 分块工具(专为 IM 机器人、通知卡片与受限文本通道设计)。
208
+ * 跨分块边界保护代码围栏(``` 或 ~~~),自动在上一块末尾闭合并在下一块开头重新打开,
209
+ * 确保代码高亮不破损、超长行不断字。
210
+ *
211
+ * @param {string} text 待分块 Markdown 文本
212
+ * @param {number} [limit=3800] 单块最大字符数(必须 > 20)
213
+ * @returns {string[]} 分块数组
214
+ */
215
+ export function chunkMarkdownText(text, limit = DEFAULT_CHUNK_LIMIT) {
216
+ const raw = String(text ?? "").trim();
217
+ if (!raw) return [];
218
+ const bound = Math.max(50, Number(limit) || DEFAULT_CHUNK_LIMIT);
219
+ if (raw.length <= bound) return [raw];
220
+
221
+ const lines = raw.split("\n");
222
+ const chunks = [];
223
+ let currentLines = [];
224
+ let currentLen = 0;
225
+ let activeFence = null;
226
+
227
+ function flushChunk() {
228
+ if (currentLines.length === 0) return;
229
+ if (activeFence) {
230
+ currentLines.push(activeFence.delimiter);
231
+ chunks.push(currentLines.join("\n"));
232
+ currentLines = [`${activeFence.delimiter}${activeFence.info}`];
233
+ currentLen = currentLines[0].length + 1;
234
+ } else {
235
+ chunks.push(currentLines.join("\n"));
236
+ currentLines = [];
237
+ currentLen = 0;
238
+ }
239
+ }
240
+
241
+ for (let i = 0; i < lines.length; i++) {
242
+ const line = lines[i];
243
+ const lineLen = line.length + 1;
244
+
245
+ if (activeFence) {
246
+ if (closesFence(line, activeFence)) {
247
+ activeFence = null;
248
+ }
249
+ } else {
250
+ const open = openingFence(line);
251
+ if (open) {
252
+ activeFence = open;
253
+ }
254
+ }
255
+
256
+ if (currentLen + lineLen > bound) {
257
+ if (currentLines.length === 0) {
258
+ const parts = splitRawText(line, bound - (activeFence ? 20 : 0));
259
+ for (let p = 0; p < parts.length; p++) {
260
+ currentLines.push(parts[p]);
261
+ if (p < parts.length - 1) flushChunk();
262
+ }
263
+ currentLen = currentLines.join("\n").length + 1;
264
+ continue;
265
+ }
266
+
267
+ flushChunk();
268
+ }
269
+
270
+ currentLines.push(line);
271
+ currentLen += lineLen;
272
+ }
273
+
274
+ if (currentLines.length > 0) {
275
+ chunks.push(currentLines.join("\n"));
276
+ }
277
+
278
+ return chunks;
279
+ }
@@ -38,6 +38,17 @@ export interface UiSelectOption {
38
38
  labelEn?: string;
39
39
  }
40
40
 
41
+ /** 插件注册的内联状态标记(Inline Marker)。 */
42
+ export interface PluginMarkerDef<State = unknown> {
43
+ name: string;
44
+ label?: string;
45
+ guidance: string[];
46
+ getGuidance?: (lang: "zh" | "en") => string[];
47
+ apply: (token: any, ctx: any, state: State, lang?: any) => Promise<any> | any;
48
+ overlay?: (state: State, ctx: any) => any;
49
+ init?: () => State;
50
+ }
51
+
41
52
  export type UiItemKind =
42
53
  "view" | "action" | "badge" | "menu" | "page" | "organizer" | "divider" | "toggle" | "input" | "progress" | "select";
43
54
 
@@ -191,6 +202,8 @@ export interface PluginHost {
191
202
  /** 订阅模型切换成功(回调带 clientId / conversationId / model / isSubagent… 的快照)。 */
192
203
  onClientModelChanged(handler: (snap: unknown) => void): () => void;
193
204
  registerAgentTool(tool: PluginAgentTool): () => void;
205
+ /** 注册一个内联标记(Inline Marker)。 */
206
+ registerMarker<State = unknown>(marker: any): () => void;
194
207
  /** 注册一个供 AI 调用的工具(单参数 execute(args) 兼容接口,内部适配并转调 registerAgentTool)。 */
195
208
  registerTool(tool: {
196
209
  name: string;
@@ -201,6 +214,8 @@ export interface PluginHost {
201
214
  parameters?: Record<string, unknown>;
202
215
  execute(args: Record<string, unknown>): Promise<unknown>;
203
216
  }): () => void;
217
+ /** 注册一个内联标记(Inline Marker),如 [[name:op:body]]。 */
218
+ registerMarker<State = unknown>(marker: PluginMarkerDef<State>): () => void;
204
219
  dir: string;
205
220
  dataDir: string;
206
221
  readonly cwd: string;
@@ -240,8 +255,22 @@ export interface PluginHost {
240
255
  get<T>(key: string, fallback?: T): T | undefined;
241
256
  set(key: string, value: unknown): void;
242
257
  delete(key: string): void;
258
+ has(key: string): boolean;
259
+ keys(): string[];
260
+ clear(preserveSettings?: boolean): void;
243
261
  all(): Record<string, unknown>;
244
262
  };
263
+ /** 插件间服务总线(Service Registry / Bus):跨插件服务发布与获取。 */
264
+ services: {
265
+ provide<T>(name: string, service: T): () => void;
266
+ get<T>(name: string): T | undefined;
267
+ has(name: string): boolean;
268
+ list(): Array<{ name: string; pluginId: string }>;
269
+ on<T>(name: string, handler: (service: T | undefined) => void): () => void;
270
+ };
271
+ provide<T>(name: string, service: T): () => void;
272
+ get<T>(name: string): T | undefined;
273
+ onService<T>(name: string, handler: (service: T | undefined) => void): () => void;
245
274
  secrets: {
246
275
  set(name: string, value: string): void;
247
276
  get(name: string): string | undefined;
@@ -253,6 +282,10 @@ export interface PluginHost {
253
282
  ensureDeps(specs: string[], opts?: { onProgress?: (msg: string) => void }): Promise<boolean>;
254
283
  fs: PluginHostFs;
255
284
  schedule(spec: string | number, fn: () => void, opts?: PluginHostScheduleOptions): () => void;
285
+ assets: {
286
+ ensure(spec: any, opts?: any): Promise<{ ok: boolean; ready?: boolean; error?: string; path?: string }>;
287
+ status(spec: any): { ready: boolean; downloading?: boolean; error?: string };
288
+ };
256
289
  requestPermission(req: PluginPermissionRequest): Promise<boolean>;
257
290
  getSettings(): Record<string, unknown>;
258
291
  onSettingsChanged(handler: (values: Record<string, unknown>) => void): () => void;
@@ -267,6 +300,44 @@ export interface PluginHost {
267
300
  * 走同一个 effect 栈,这里只用于「宿主管不到的那些」—— 挂进来就不怕漏注销
268
301
  * (热重载后定时器叠加、监听器堆积都是这个漏法的症状)。dispose 请写成幂等的。 */
269
302
  effect(label: string, dispose: () => void): () => void;
303
+ /** 安全解析工作区相对/绝对路径:落在工作区或额外根内放行,越界抛带 statusCode=403 的错误。 */
304
+ resolveInWorkspace(relOrAbsPath: string): string;
305
+ /** 带有默认超时(默认 30s)与插件生命周期绑定的安全 fetch。 */
306
+ fetch(input: string | URL | Request, init?: RequestInit & { timeoutMs?: number }): Promise<Response>;
307
+ /** 宿主重资产流水线(Heavy Asset Pipeline)。 */
308
+ assets: {
309
+ ensure(
310
+ spec: {
311
+ id: string;
312
+ targetDir: string;
313
+ urls: string[];
314
+ sha256?: string;
315
+ testFile?: string;
316
+ size?: number;
317
+ description?: string;
318
+ },
319
+ opts?: {
320
+ onProgress?: (progress: { downloaded: number; total: number; percent: number; url: string }) => void;
321
+ timeoutMs?: number;
322
+ },
323
+ ): Promise<{ ok: boolean; targetDir: string; cached?: boolean; sha256?: string; error?: string }>;
324
+ status(spec: {
325
+ id: string;
326
+ targetDir: string;
327
+ urls: string[];
328
+ sha256?: string;
329
+ testFile?: string;
330
+ size?: number;
331
+ description?: string;
332
+ }): {
333
+ ready: boolean;
334
+ downloading: boolean;
335
+ progress: number;
336
+ downloaded: number;
337
+ total: number;
338
+ error: string | null;
339
+ };
340
+ };
270
341
  /** 无头调用:把外部通道文本投给 agent(要 "chat" 能力;宿主未接 chatProvider
271
342
  * 时 reject(由 chatWait 包成 {ok:false},插件侧用 chatWait 更省心)。 */
272
343
  chat(req: { text: string; accountId?: string }): Promise<{
@@ -475,7 +546,7 @@ export interface MockHostLogEntry {
475
546
 
476
547
  /** createMockHost(overrides?):settings/cwd/dir/dataDir 是专用键;命名空间键
477
548
  * (fs/ui/llm/conversations/scm/net/events/models/storage/secrets/project/dialogs/
478
- * shortcuts/searchProviders/composerProviders)传对象 = 按子键合并覆盖;其余键整体
549
+ * shortcuts/searchProviders/composerProviders/assets)传对象 = 按子键合并覆盖;其余键整体
479
550
  * 替换对应方法(仍进 calls 记录)。`calls`/`logs`/`mock`/`reset` 不可覆盖。 */
480
551
  export interface MockHostOverrides {
481
552
  settings?: Record<string, unknown>;
@@ -502,6 +573,8 @@ export interface MockHostControls {
502
573
  emitSettings(next?: Record<string, unknown>): Record<string, unknown>;
503
574
  /** 已注册的 Agent 工具定义(活数组,注销即摘除;工具的 execute 可直接调)。 */
504
575
  agentTools: Array<PluginAgentTool>;
576
+ /** 已注册的内联标记定义(活数组,注销即摘除)。 */
577
+ markers: Array<PluginMarkerDef<unknown>>;
505
578
  /** 已注册的斜杠命令定义(活数组,注销即摘除)。 */
506
579
  commands: Array<PluginCommandDef>;
507
580
  /** 已挂载的路由表(活数组,注销即摘除)。 */
@@ -581,3 +654,9 @@ export declare function uuid(): string;
581
654
 
582
655
  /** 归一化相对路径(反斜杠转斜杠、去除首尾多余斜杠与 "./")。 */
583
656
  export declare function normalizeRel(p: string): string;
657
+
658
+ /** 计算安全的截断位置,避免割裂 UTF-16 代理对。 */
659
+ export declare function safeSliceIndex(value: string, limit: number): number;
660
+
661
+ /** 结构感知 Markdown 分块工具(保护代码围栏不跨块破坏)。 */
662
+ export declare function chunkMarkdownText(text: string, limit?: number): string[];
@@ -38,6 +38,8 @@
38
38
  * 零依赖、纯 ESM,直接拷走就能用(renderer 插件的裸 ESM 约束同样满足)。
39
39
  */
40
40
 
41
+ import { resolve, sep } from "node:path";
42
+
41
43
  /**
42
44
  * SDK 版本(单源:与 plugin-sdk/package.json 的 version 保持一致,
43
45
  * tests/unit/plugin-sdk-mock.test.ts 锁定)。脚手架拷贝 sdk/index.mjs 时连版本号
@@ -266,11 +268,14 @@ export function createMockHost(overrides) {
266
268
  const uiArrangeOps = [];
267
269
  let uiAutoId = 0;
268
270
  const agentToolStore = [];
271
+ const markerStore = [];
269
272
  const commandStore = [];
270
273
  const routeStore = [];
271
274
  const proxyStore = [];
272
275
  const scheduleStore = [];
273
276
  const effectStore = [];
277
+ const serviceMap = new Map();
278
+ const serviceListeners = new Map();
274
279
  // 注册类:存定义体 + 返回只摘除本次注册的注销函数(与宿主同语义)。
275
280
  const remember = (store, entry) => {
276
281
  if (entry !== undefined) store.push(entry);
@@ -311,6 +316,7 @@ export function createMockHost(overrides) {
311
316
  abortRun: async () => okFalse("runAborter(运行中止未接入)"),
312
317
  onConversationChanged: sub("onConversationChanged"),
313
318
  registerAgentTool: (tool) => remember(agentToolStore, tool),
319
+ registerMarker: (marker) => remember(markerStore, marker),
314
320
  dir: typeof overrides.dir === "string" ? overrides.dir : "/mock-workspace/.mock-plugin",
315
321
  dataDir: typeof overrides.dataDir === "string" ? overrides.dataDir : "/mock-data",
316
322
  cwd: typeof overrides.cwd === "string" ? overrides.cwd : "/mock-workspace",
@@ -369,8 +375,61 @@ export function createMockHost(overrides) {
369
375
  delete: (key) => {
370
376
  storeMap.delete(key);
371
377
  },
378
+ has: (key) => storeMap.has(key),
379
+ keys: () => [...storeMap.keys()],
380
+ clear: () => {
381
+ storeMap.clear();
382
+ },
372
383
  all: () => Object.fromEntries(storeMap),
373
384
  },
385
+ services: {
386
+ provide: (name, service) => {
387
+ serviceMap.set(name, service);
388
+ const listeners = serviceListeners.get(name);
389
+ if (listeners) {
390
+ for (const fn of listeners) {
391
+ try {
392
+ fn(service);
393
+ } catch {}
394
+ }
395
+ }
396
+ return () => {
397
+ if (serviceMap.get(name) === service) {
398
+ serviceMap.delete(name);
399
+ const currListeners = serviceListeners.get(name);
400
+ if (currListeners) {
401
+ for (const fn of currListeners) {
402
+ try {
403
+ fn(undefined);
404
+ } catch {}
405
+ }
406
+ }
407
+ }
408
+ };
409
+ },
410
+ get: (name) => serviceMap.get(name),
411
+ has: (name) => serviceMap.has(name),
412
+ list: () => [...serviceMap.keys()].map((k) => ({ name: k, pluginId: "mock" })),
413
+ on: (name, handler) => {
414
+ let listeners = serviceListeners.get(name);
415
+ if (!listeners) {
416
+ listeners = new Set();
417
+ serviceListeners.set(name, listeners);
418
+ }
419
+ listeners.add(handler);
420
+ if (serviceMap.has(name)) {
421
+ try {
422
+ handler(serviceMap.get(name));
423
+ } catch {}
424
+ }
425
+ return () => {
426
+ listeners.delete(handler);
427
+ };
428
+ },
429
+ },
430
+ provide: (name, service) => host.services.provide(name, service),
431
+ get: (name) => host.services.get(name),
432
+ onService: (name, handler) => host.services.on(name, handler),
374
433
  secrets: {
375
434
  set: (name, value) => {
376
435
  secretMap.set(name, value);
@@ -467,6 +526,32 @@ export function createMockHost(overrides) {
467
526
  const entry = { label, dispose };
468
527
  return remember(effectStore, entry);
469
528
  },
529
+ resolveInWorkspace: (relOrAbsPath) => {
530
+ record("resolveInWorkspace", [relOrAbsPath]);
531
+ const cwdValue = typeof overrides.cwd === "string" ? overrides.cwd : "/mock-workspace";
532
+ const target = resolve(cwdValue, String(relOrAbsPath ?? ""));
533
+ const root = resolve(cwdValue);
534
+ if (target !== root && !target.startsWith(root + sep)) {
535
+ const err = new Error("路径超出工作区范围");
536
+ err.statusCode = 403;
537
+ throw err;
538
+ }
539
+ return target;
540
+ },
541
+ fetch: async (input, init) => {
542
+ record("fetch", [input, init]);
543
+ return fetch(input, init);
544
+ },
545
+ assets: {
546
+ ensure: async (spec, opts) => {
547
+ record("assets.ensure", [spec, opts]);
548
+ return { ok: true, targetDir: spec?.targetDir ?? "artifacts", cached: true };
549
+ },
550
+ status: (spec) => {
551
+ record("assets.status", [spec]);
552
+ return { ready: true, downloading: false, progress: 100, downloaded: 0, total: 0, error: null };
553
+ },
554
+ },
470
555
  // 浏览器桥兼容(client 侧逻辑单测也能用同一个 mock):无注入回退语义。
471
556
  dialogs: {
472
557
  select: async () => ({ ok: false }),
@@ -485,6 +570,16 @@ export function createMockHost(overrides) {
485
570
  register: freshOff,
486
571
  list: () => [],
487
572
  },
573
+ assets: {
574
+ ensure: async (spec, opts) => {
575
+ record("assets.ensure", [spec, opts]);
576
+ return { ok: true, ready: true, path: spec?.targetDir || "" };
577
+ },
578
+ status: (spec) => {
579
+ record("assets.status", [spec]);
580
+ return { ready: true, downloading: false };
581
+ },
582
+ },
488
583
  calls,
489
584
  logs,
490
585
  mock: {
@@ -521,6 +616,9 @@ export function createMockHost(overrides) {
521
616
  get agentTools() {
522
617
  return agentToolStore;
523
618
  },
619
+ get markers() {
620
+ return markerStore;
621
+ },
524
622
  get commands() {
525
623
  return commandStore;
526
624
  },
@@ -562,6 +660,7 @@ export function createMockHost(overrides) {
562
660
  "shortcuts",
563
661
  "searchProviders",
564
662
  "composerProviders",
663
+ "assets",
565
664
  ];
566
665
  for (const [key, value] of Object.entries(overrides)) {
567
666
  if (key === "settings" || key === "cwd" || key === "dir" || key === "dataDir") continue;
@@ -5,5 +5,9 @@
5
5
  "type": "module",
6
6
  "description": "Starter helpers + types for pi-web-ui plugins (copy this dir into your plugin, or vendor index.mjs/index.d.ts).",
7
7
  "main": "index.mjs",
8
- "types": "index.d.ts"
8
+ "types": "index.d.ts",
9
+ "exports": {
10
+ ".": "./index.mjs",
11
+ "./client": "./client-utils.mjs"
12
+ }
9
13
  }
@@ -391,5 +391,38 @@
391
391
  "descriptionEn": "Approval gate: centralized pending-decision list from scheduled tasks; click an item to jump into its conversation; red-dot badge on the tab shows pending count. A generic CLI lets any cron job register items.",
392
392
  "source": "xing-shuyin/pi-web-ui/plugins/approval-gate",
393
393
  "homepage": "https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/approval-gate"
394
+ },
395
+ {
396
+ "id": "live2d",
397
+ "name": "Live2D 看板娘",
398
+ "nameEn": "Live2D Companion",
399
+ "icon": "🐾",
400
+ "iconSvg": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm-2-9c.55 0 1-.45 1-1s-.45-1-1-1-1 .45-1 1 .45 1 1 1zm4 0c.55 0 1-.45 1-1s-.45-1-1-1-1 .45-1 1 .45 1 1 1zm-2 5c1.66 0 3-1.34 3-3H9c0 1.66 1.34 3 3 3z\"/></svg>",
401
+ "description": "页面悬浮 Live2D 桌面看板娘宠物:支持 Cubism 2/3/4 模型渲染、鼠标视线跟随、触摸点击反应、气泡对话台词、伴随 AI 思考/回复情绪联动与 AI 动作表情操控工具。",
402
+ "descriptionEn": "Interactive Live2D companion on your screen: Cubism 2/3/4 models, mouse eye-tracking, tap reactions, speech bubbles, AI emotion reactivity, and agent tools.",
403
+ "source": "xing-shuyin/pi-web-ui/plugins/live2d",
404
+ "homepage": "https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/live2d"
405
+ },
406
+ {
407
+ "id": "office",
408
+ "name": "office",
409
+ "nameEn": "office",
410
+ "icon": "📑",
411
+ "iconSvg": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z\"/><polyline points=\"14 2 14 8 20 8\"/><line x1=\"16\" y1=\"13\" x2=\"8\" y2=\"13\"/><line x1=\"16\" y1=\"17\" x2=\"8\" y2=\"17\"/><line x1=\"10\" y1=\"9\" x2=\"8\" y2=\"9\"/></svg>",
412
+ "description": "基于 Univer 引擎的高保真 Office 原生画布预览与编辑:接管工作区 .pptx / .docx / .xlsx 真实渲染,支持 1:1 排版放映与 AI 结构化表格修改写回。",
413
+ "descriptionEn": "High-fidelity Office Canvas preview and editing powered by Univer: 1:1 true layouts for .pptx/.docx/.xlsx with AI structured editing and lossless disk save.",
414
+ "source": "xing-shuyin/pi-web-ui/plugins/office",
415
+ "homepage": "https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/office"
416
+ },
417
+ {
418
+ "id": "bili-scroll",
419
+ "name": "bili-scroll",
420
+ "nameEn": "Bilibili Scroll",
421
+ "icon": "📺",
422
+ "iconSvg": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><rect x=\"2\" y=\"7\" width=\"20\" height=\"15\" rx=\"3\"/><polyline points=\"17 2 12 7 7 2\"/><line x1=\"8\" y1=\"12\" x2=\"8\" y2=\"12.01\"/><line x1=\"16\" y1=\"12\" x2=\"16\" y2=\"12.01\"/></svg>",
423
+ "description": "每天替你刷一轮 B 站:通读原文字幕深度排雷、三档位精选、默认私信投递、支持私信双向对话与分享看片、视频卡片墙与自动收藏。",
424
+ "descriptionEn": "Autonomous Bilibili duty agent: reads raw subtitles to filter fluff, delivers curated video digests directly to private DMs, supports bidirectional DM chat, video card wall, and auto-favorite.",
425
+ "source": "xing-shuyin/pi-web-ui/plugins/bili-scroll",
426
+ "homepage": "https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/bili-scroll"
394
427
  }
395
428
  ]