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.
- package/CHANGELOG.md +31 -0
- package/README.md +21 -1
- package/README.zh-CN.md +21 -1
- package/README.zh-TW.md +201 -677
- package/bin/frp-manager.mjs +85 -7
- package/dist/server/agent-formatters.js +10 -6
- package/dist/server/agent-service-daemon.js +29 -11
- package/dist/server/agent-service.js +160 -54
- package/dist/server/attachments.js +140 -37
- package/dist/server/canvas/canvas-agent-tool.js +587 -0
- package/dist/server/canvas/canvas-cards.js +144 -0
- package/dist/server/canvas/canvas-dispatch.js +155 -0
- package/dist/server/canvas/canvas-orchestrator.js +1027 -0
- package/dist/server/canvas/canvas-store.js +260 -0
- package/dist/server/client-id-utils.js +2 -2
- package/dist/server/client-state.js +24 -0
- package/dist/server/context-budget.js +6 -3
- package/dist/server/dispatch-domain-handlers.js +2 -0
- package/dist/server/dispatch-plugin-handlers.js +1 -0
- package/dist/server/dsh/dsh-agent-service.js +115 -9
- package/dist/server/dsh/dsh-client.js +10 -1
- package/dist/server/dsh/runtime/goal-rpc.mjs +128 -3
- package/dist/server/dsh/runtime/launcher.mjs +59 -5
- package/dist/server/dsh/runtime/runtime-root.mjs +353 -40
- package/dist/server/durable/durable-agent-service.js +3 -0
- package/dist/server/durable/durable-driver.js +1 -1
- package/dist/server/durable/durable-tools.js +4 -1
- package/dist/server/file-transfer-routes.js +8 -2
- package/dist/server/files-service.js +33 -6
- package/dist/server/goal-service.js +12 -3
- package/dist/server/index.js +175 -13
- package/dist/server/locales.js +33 -0
- package/dist/server/marker-service.js +10 -14
- package/dist/server/markers/builtins/action.js +5 -6
- package/dist/server/markers/builtins/notify.js +2 -2
- package/dist/server/markers/builtins/rename.js +2 -2
- package/dist/server/markers/marker.js +45 -4
- package/dist/server/markers/registry.js +36 -1
- package/dist/server/message-window.js +193 -0
- package/dist/server/model-admin.js +0 -4
- package/dist/server/office-parse.js +394 -7
- package/dist/server/plugin-api-catalog.js +6 -0
- package/dist/server/plugin-catalog-sync.js +10 -2
- package/dist/server/plugin-catalog.js +63 -10
- package/dist/server/plugins.js +144 -26
- package/dist/server/preset-fields.js +35 -1
- package/dist/server/preset-share.js +5 -3
- package/dist/server/process-utils.js +58 -24
- package/dist/server/prompt-assembler.js +7 -1
- package/dist/server/prompt-composer.js +66 -36
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/remote-ssh-service.js +16 -4
- package/dist/server/settings-service.js +24 -3
- package/dist/server/slash-commands.js +16 -4
- package/dist/server/text-sniff.js +10 -7
- package/dist/server/themes.js +36 -1
- package/dist/server/tool-manager.js +30 -0
- package/dist/server/univer-service.js +448 -0
- package/dist/server/universal/drivers/claude-code.js +19 -2
- package/dist/server/universal/drivers/dsh-driver.js +1 -1
- package/dist/server/universal/universal-attachments.js +5 -0
- package/dist/server/universal/universal-service.js +5 -0
- package/dist/server/universal/universal-session.js +38 -15
- package/dist/server/update-check.js +90 -5
- package/dist/server/workspace-snapshot.js +33 -2
- package/dist/server/worktree-service.js +1 -1
- package/docs/dsh-engine.md +497 -0
- package/package.json +11 -5
- package/plugin-sdk/index.d.ts +37 -0
- package/plugin-sdk/index.mjs +19 -0
- package/plugins/catalog.json +44 -2
- package/themes/aetheris.css +263 -118
- package/themes/bases/flow-base.css +1363 -0
- package/themes/bases/obsidian-base.css +895 -0
- package/themes/bases/zhujian-base.css +687 -0
- package/themes/bases/zhupi-base.css +659 -0
- package/themes/flow-light.css +2 -925
- package/themes/flow.css +1 -936
- package/themes/md-preview.css +113 -0
- package/themes/wallpaper-flow.css +251 -1029
- package/themes/wallpaper-obsidian.css +1 -673
- package/themes/zhujian-dark.css +1 -605
- package/themes/zhujian.css +1 -654
- package/themes/zhupi-dark.css +1 -576
- package/themes/zhupi.css +1 -626
- package/web/dist/assets/{TerminalPanel-BD3a9o-a.js → TerminalPanel-BiUNySMA.js} +2 -2
- package/web/dist/assets/index-B0ajS__T.js +697 -0
- package/web/dist/assets/index-BHik5WGG.css +1 -0
- package/web/dist/assets/{markdown-DXwnfD9T.js → markdown-BJZlfvdP.js} +24 -24
- package/web/dist/assets/markdown-DSNUiDzp.css +1 -0
- package/web/dist/index.html +4 -4
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/es-DIDZppIF.js +0 -2
- package/web/dist/assets/index-AccytlpP.css +0 -1
- package/web/dist/assets/index-B3dar1BK.js +0 -690
- package/web/dist/assets/markdown-CCeVCbci.css +0 -1
|
@@ -4,15 +4,12 @@
|
|
|
4
4
|
* 给「随处可看」用的:文件预览(files-service readFile)、附件等走 file_content
|
|
5
5
|
* 下发 Markdown 文本,前端 FilePreview 按 Markdown 渲染表格/段落,无需改协议。
|
|
6
6
|
*
|
|
7
|
-
* 零依赖:docx / xlsx 本质是 zip 包,这里用 node:zlib + 手写 zip 中央目录解析
|
|
7
|
+
* 零依赖:docx / xlsx / pptx 本质是 zip 包,这里用 node:zlib + 手写 zip 中央目录解析
|
|
8
8
|
* 做最小解包(只支持 stored / deflate,Office 写出的文件都是这两种)。
|
|
9
|
-
*
|
|
10
|
-
* 注意:plugins/office-preview/index.mjs 里有一份同逻辑的 JS 拷贝(插件必须
|
|
11
|
-
* 自包含、不能 import 服务端 TS,见架构文档插件章)。两边改解析时请同步另一份。
|
|
12
9
|
*/
|
|
13
10
|
import { inflateRawSync } from "node:zlib";
|
|
14
|
-
const OFFICE_EXTS = new Set([".docx", ".xlsx", ".xlsm"]);
|
|
15
|
-
/**
|
|
11
|
+
const OFFICE_EXTS = new Set([".docx", ".xlsx", ".xlsm", ".pptx", ".pptm", ".ppsx", ".potx"]);
|
|
12
|
+
/** 单个文件上限(15MB)。 */
|
|
16
13
|
export const OFFICE_MAX_FILE_BYTES = 15 * 1024 * 1024;
|
|
17
14
|
/** 解包后总量上限(防 zip 炸弹:小包解出巨量内容)。 */
|
|
18
15
|
export const OFFICE_MAX_UNCOMPRESSED_BYTES = 64 * 1024 * 1024;
|
|
@@ -111,6 +108,25 @@ export function unzipFiles(buf, wanted) {
|
|
|
111
108
|
}
|
|
112
109
|
return out;
|
|
113
110
|
}
|
|
111
|
+
/** 列出 zip 中央目录里的全部条目名(不解压内容,快速探测)。 */
|
|
112
|
+
export function listZipEntries(buf) {
|
|
113
|
+
const eocd = findEocd(buf);
|
|
114
|
+
const cdCount = buf.readUInt16LE(eocd + 10);
|
|
115
|
+
const cdOffset = buf.readUInt32LE(eocd + 16);
|
|
116
|
+
const names = [];
|
|
117
|
+
let p = cdOffset;
|
|
118
|
+
for (let i = 0; i < cdCount; i++) {
|
|
119
|
+
if (buf.readUInt32LE(p) !== 0x02014b50)
|
|
120
|
+
throw new Error("zip 中央目录损坏");
|
|
121
|
+
const nameLen = buf.readUInt16LE(p + 28);
|
|
122
|
+
const extraLen = buf.readUInt16LE(p + 30);
|
|
123
|
+
const commentLen = buf.readUInt16LE(p + 32);
|
|
124
|
+
const name = buf.toString("utf8", p + 46, p + 46 + nameLen);
|
|
125
|
+
names.push(name);
|
|
126
|
+
p += 46 + nameLen + extraLen + commentLen;
|
|
127
|
+
}
|
|
128
|
+
return names;
|
|
129
|
+
}
|
|
114
130
|
const NAMED_ENTITIES = { lt: "<", gt: ">", amp: "&", quot: '"', apos: "'" };
|
|
115
131
|
/**
|
|
116
132
|
* 单轮解码命名实体与十/十六进制数字实体(一次扫描同时匹配三类)。
|
|
@@ -324,6 +340,371 @@ function colName(i) {
|
|
|
324
340
|
} while (n >= 0);
|
|
325
341
|
return s;
|
|
326
342
|
}
|
|
343
|
+
/* ---------------- PPTX 幻灯片解析 ---------------- */
|
|
344
|
+
export const PPTX_MAX_SLIDES = 500;
|
|
345
|
+
function extractShapePlainText(spXml) {
|
|
346
|
+
const parts = [];
|
|
347
|
+
for (const m of spXml.matchAll(/<a:(t|tab|br)\b[^>]*\/?>([^<]*)(?:<\/a:t>)?/g)) {
|
|
348
|
+
if (m[1] === "tab")
|
|
349
|
+
parts.push("\t");
|
|
350
|
+
else if (m[1] === "br")
|
|
351
|
+
parts.push(" ");
|
|
352
|
+
else
|
|
353
|
+
parts.push(decodeEntities(m[2]));
|
|
354
|
+
}
|
|
355
|
+
return parts.join("").trim();
|
|
356
|
+
}
|
|
357
|
+
function extractShapeParagraphs(spXml, isBodyPlaceholder = false) {
|
|
358
|
+
const out = [];
|
|
359
|
+
for (const pMatch of spXml.matchAll(/<a:p\b[\s\S]*?<\/a:p>/g)) {
|
|
360
|
+
const pXml = pMatch[0];
|
|
361
|
+
const pPr = /<a:pPr\b([^>]*)>([\s\S]*?)<\/a:pPr>|<a:pPr\b([^>]*)\/>/.exec(pXml);
|
|
362
|
+
let lvl = 0;
|
|
363
|
+
let hasBuNone = false;
|
|
364
|
+
let hasBuChar = false;
|
|
365
|
+
let hasBuAutoNum = false;
|
|
366
|
+
if (pPr) {
|
|
367
|
+
const attrs = pPr[1] ?? pPr[3] ?? "";
|
|
368
|
+
const inner = pPr[2] ?? "";
|
|
369
|
+
const lvlMatch = /\blvl=["'](\d+)["']/.exec(attrs);
|
|
370
|
+
if (lvlMatch)
|
|
371
|
+
lvl = Number(lvlMatch[1]);
|
|
372
|
+
hasBuNone = /<a:buNone\b/.test(inner);
|
|
373
|
+
hasBuChar = /<a:buChar\b/.test(inner);
|
|
374
|
+
hasBuAutoNum = /<a:buAutoNum\b/.test(inner);
|
|
375
|
+
}
|
|
376
|
+
const isBullet = !hasBuNone && (hasBuChar || hasBuAutoNum || lvl > 0 || isBodyPlaceholder);
|
|
377
|
+
let text = "";
|
|
378
|
+
for (const m of pXml.matchAll(/<a:(t|tab|br)\b[^>]*\/?>([^<]*)(?:<\/a:t>)?/g)) {
|
|
379
|
+
if (m[1] === "tab")
|
|
380
|
+
text += "\t";
|
|
381
|
+
else if (m[1] === "br")
|
|
382
|
+
text += "\n";
|
|
383
|
+
else
|
|
384
|
+
text += decodeEntities(m[2]);
|
|
385
|
+
}
|
|
386
|
+
text = text.trim();
|
|
387
|
+
if (text) {
|
|
388
|
+
out.push({ text, lvl, isBullet });
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return out;
|
|
392
|
+
}
|
|
393
|
+
function parseTable(tblXml) {
|
|
394
|
+
const rows = [];
|
|
395
|
+
for (const trMatch of tblXml.matchAll(/<a:tr\b[^>]*>([\s\S]*?)<\/a:tr>/g)) {
|
|
396
|
+
const rowXml = trMatch[1];
|
|
397
|
+
const row = [];
|
|
398
|
+
for (const tcMatch of rowXml.matchAll(/<a:tc\b[^>]*>([\s\S]*?)<\/a:tc>/g)) {
|
|
399
|
+
const cellXml = tcMatch[1];
|
|
400
|
+
const cellText = [];
|
|
401
|
+
for (const m of cellXml.matchAll(/<a:(t|tab|br)\b[^>]*\/?>([^<]*)(?:<\/a:t>)?/g)) {
|
|
402
|
+
if (m[1] === "tab")
|
|
403
|
+
cellText.push("\t");
|
|
404
|
+
else if (m[1] === "br")
|
|
405
|
+
cellText.push(" ");
|
|
406
|
+
else
|
|
407
|
+
cellText.push(decodeEntities(m[2]));
|
|
408
|
+
}
|
|
409
|
+
row.push(cellText.join("").trim());
|
|
410
|
+
}
|
|
411
|
+
if (row.length > 0)
|
|
412
|
+
rows.push(row);
|
|
413
|
+
}
|
|
414
|
+
return rows;
|
|
415
|
+
}
|
|
416
|
+
function tableToMarkdown(rows) {
|
|
417
|
+
if (rows.length === 0)
|
|
418
|
+
return "";
|
|
419
|
+
const colCount = Math.max(...rows.map((r) => r.length));
|
|
420
|
+
if (colCount === 0)
|
|
421
|
+
return "";
|
|
422
|
+
const pad = (r) => {
|
|
423
|
+
const row = r.slice(0, colCount);
|
|
424
|
+
while (row.length < colCount)
|
|
425
|
+
row.push("");
|
|
426
|
+
return row;
|
|
427
|
+
};
|
|
428
|
+
const headerRow = pad(rows[0]);
|
|
429
|
+
const separatorRow = Array(colCount).fill("---");
|
|
430
|
+
const dataRows = rows.slice(1).map(pad);
|
|
431
|
+
const lines = [headerRow, separatorRow, ...dataRows].map((r) => `| ${r.map(mdCell).join(" | ")} |`);
|
|
432
|
+
return lines.join("\n");
|
|
433
|
+
}
|
|
434
|
+
function slideToMarkdown(slide) {
|
|
435
|
+
const titlePart = slide.title ? `:${slide.title}` : "";
|
|
436
|
+
const head = `## 幻灯片 ${slide.index}${titlePart}`;
|
|
437
|
+
const bodyParts = [];
|
|
438
|
+
if (slide.subtitle) {
|
|
439
|
+
bodyParts.push(`*${slide.subtitle}*`);
|
|
440
|
+
}
|
|
441
|
+
if (slide.images && slide.images.length > 0) {
|
|
442
|
+
for (const img of slide.images) {
|
|
443
|
+
bodyParts.push(`🖼️ **图片**:${img.descr || img.media}`);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (slide.paragraphs.length > 0) {
|
|
447
|
+
bodyParts.push(slide.paragraphs.join("\n"));
|
|
448
|
+
}
|
|
449
|
+
if (slide.tables && slide.tables.length > 0) {
|
|
450
|
+
for (const tbl of slide.tables) {
|
|
451
|
+
const mdTbl = tableToMarkdown(tbl);
|
|
452
|
+
if (mdTbl)
|
|
453
|
+
bodyParts.push(mdTbl);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
if (slide.notes) {
|
|
457
|
+
bodyParts.push(`> 💡 **备注**:${slide.notes}`);
|
|
458
|
+
}
|
|
459
|
+
if (bodyParts.length === 0) {
|
|
460
|
+
return `${head}\n\n(空幻灯片)`;
|
|
461
|
+
}
|
|
462
|
+
return `${head}\n\n${bodyParts.join("\n\n")}`;
|
|
463
|
+
}
|
|
464
|
+
/** pptx/pptm/ppsx/potx → 幻灯片数组。 */
|
|
465
|
+
export function parsePptxSlides(buf) {
|
|
466
|
+
const allEntries = new Set(listZipEntries(buf));
|
|
467
|
+
const probeTargets = ["ppt/presentation.xml", "ppt/_rels/presentation.xml.rels"].filter((n) => allEntries.has(n));
|
|
468
|
+
const probe = unzipFiles(buf, probeTargets);
|
|
469
|
+
const presXml = probe.get("ppt/presentation.xml")?.toString("utf8") ?? "";
|
|
470
|
+
const relsXml = probe.get("ppt/_rels/presentation.xml.rels")?.toString("utf8") ?? "";
|
|
471
|
+
const relTarget = new Map();
|
|
472
|
+
for (const m of relsXml.matchAll(/<Relationship\b[^>]*>/gi)) {
|
|
473
|
+
const id = /\bId=["']([^"']+)["']/i.exec(m[0])?.[1];
|
|
474
|
+
const target = /\bTarget=["']([^"']+)["']/i.exec(m[0])?.[1];
|
|
475
|
+
if (id && target) {
|
|
476
|
+
const clean = target
|
|
477
|
+
.replace(/\\/g, "/")
|
|
478
|
+
.replace(/^\/+/, "")
|
|
479
|
+
.replace(/^ppt\//, "");
|
|
480
|
+
relTarget.set(id, clean);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
const slideRids = [];
|
|
484
|
+
for (const m of presXml.matchAll(/<[a-zA-Z0-9:]*sldId\b[^>]*\br:id=["']([^"']+)["']/gi)) {
|
|
485
|
+
slideRids.push(m[1]);
|
|
486
|
+
}
|
|
487
|
+
let slideTargets = slideRids
|
|
488
|
+
.map((rid) => relTarget.get(rid))
|
|
489
|
+
.filter((t) => Boolean(t))
|
|
490
|
+
.map((t) => (t.startsWith("ppt/") ? t : `ppt/${t}`));
|
|
491
|
+
// Fallback 1: presentation.xml.rels 中声明的 slide 关系
|
|
492
|
+
if (slideTargets.length === 0) {
|
|
493
|
+
for (const m of relsXml.matchAll(/<Relationship\b[^>]*>/gi)) {
|
|
494
|
+
const type = /\bType=["']([^"']+)["']/i.exec(m[0])?.[1] ?? "";
|
|
495
|
+
const target = /\bTarget=["']([^"']+)["']/i.exec(m[0])?.[1] ?? "";
|
|
496
|
+
if (type.endsWith("/slide") || target.includes("slides/slide")) {
|
|
497
|
+
const clean = target
|
|
498
|
+
.replace(/\\/g, "/")
|
|
499
|
+
.replace(/^\/+/, "")
|
|
500
|
+
.replace(/^ppt\//, "");
|
|
501
|
+
slideTargets.push(clean.startsWith("ppt/") ? clean : `ppt/${clean}`);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
slideTargets.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }));
|
|
505
|
+
}
|
|
506
|
+
// Fallback 2: 中央目录扫描 ppt/slides/slideN.xml
|
|
507
|
+
if (slideTargets.length === 0) {
|
|
508
|
+
slideTargets = Array.from(allEntries)
|
|
509
|
+
.filter((name) => /^ppt\/slides\/slide\d+\.xml$/i.test(name))
|
|
510
|
+
.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }));
|
|
511
|
+
}
|
|
512
|
+
if (slideTargets.length === 0) {
|
|
513
|
+
throw new Error("PPTX 文件中未找到幻灯片内容");
|
|
514
|
+
}
|
|
515
|
+
const cappedSlideTargets = slideTargets.slice(0, PPTX_MAX_SLIDES);
|
|
516
|
+
// 扫描各幻灯片的 .rels 关系(查找图片与演讲者备注)
|
|
517
|
+
const slideRelsMap = new Map();
|
|
518
|
+
const slideToNotes = new Map();
|
|
519
|
+
const slideRelsToFetch = [];
|
|
520
|
+
for (const st of cappedSlideTargets) {
|
|
521
|
+
const base = st.split("/").pop();
|
|
522
|
+
const relsName = `ppt/slides/_rels/${base}.rels`;
|
|
523
|
+
if (allEntries.has(relsName))
|
|
524
|
+
slideRelsToFetch.push(relsName);
|
|
525
|
+
}
|
|
526
|
+
if (slideRelsToFetch.length > 0) {
|
|
527
|
+
const slideRelsData = unzipFiles(buf, slideRelsToFetch);
|
|
528
|
+
for (const [relsPath, relsBuf] of slideRelsData) {
|
|
529
|
+
const xml = relsBuf.toString("utf8");
|
|
530
|
+
const rMap = new Map();
|
|
531
|
+
const base = relsPath
|
|
532
|
+
.split("/")
|
|
533
|
+
.pop()
|
|
534
|
+
?.replace(/\.rels$/, "");
|
|
535
|
+
const slideTarget = cappedSlideTargets.find((st) => st.endsWith(`/${base}`));
|
|
536
|
+
for (const m of xml.matchAll(/<Relationship\b[^>]*>/gi)) {
|
|
537
|
+
const id = /\bId=["']([^"']+)["']/i.exec(m[0])?.[1];
|
|
538
|
+
const target = /\bTarget=["']([^"']+)["']/i.exec(m[0])?.[1];
|
|
539
|
+
const type = /\bType=["']([^"']+)["']/i.exec(m[0])?.[1] ?? "";
|
|
540
|
+
if (id && target) {
|
|
541
|
+
rMap.set(id, target);
|
|
542
|
+
}
|
|
543
|
+
if ((type.endsWith("/notesSlide") || target?.includes("notesSlide")) && target && slideTarget) {
|
|
544
|
+
const clean = target
|
|
545
|
+
.replace(/\\/g, "/")
|
|
546
|
+
.replace(/^\.\.\//, "")
|
|
547
|
+
.replace(/^ppt\//, "");
|
|
548
|
+
const fullNotesPath = clean.startsWith("ppt/") ? clean : `ppt/${clean}`;
|
|
549
|
+
if (allEntries.has(fullNotesPath)) {
|
|
550
|
+
slideToNotes.set(slideTarget, fullNotesPath);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
if (slideTarget)
|
|
555
|
+
slideRelsMap.set(slideTarget, rMap);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
const filesToUnzip = [...cappedSlideTargets, ...Array.from(new Set(slideToNotes.values()))];
|
|
559
|
+
const unzipped = unzipFiles(buf, filesToUnzip);
|
|
560
|
+
const slides = [];
|
|
561
|
+
for (let i = 0; i < cappedSlideTargets.length; i++) {
|
|
562
|
+
const target = cappedSlideTargets[i];
|
|
563
|
+
const slideXml = unzipped.get(target)?.toString("utf8") ?? "";
|
|
564
|
+
if (!slideXml)
|
|
565
|
+
continue;
|
|
566
|
+
if (slideXml.length > DOCX_MAX_XML_BYTES) {
|
|
567
|
+
throw new Error(`幻灯片内容过大(解压后 ${(slideXml.length / 1048576).toFixed(1)} MB,上限 20 MB),拒绝预览`);
|
|
568
|
+
}
|
|
569
|
+
let title = "";
|
|
570
|
+
let titleShapeXml = null;
|
|
571
|
+
let subtitle;
|
|
572
|
+
// 查找标题与副标题占位符
|
|
573
|
+
for (const spMatch of slideXml.matchAll(/<p:sp\b[\s\S]*?<\/p:sp>/g)) {
|
|
574
|
+
const sp = spMatch[0];
|
|
575
|
+
if (!title && /<p:ph\b[^>]*\btype=["'](?:title|ctrTitle)["']/i.test(sp)) {
|
|
576
|
+
const text = extractShapePlainText(sp);
|
|
577
|
+
if (text) {
|
|
578
|
+
title = text;
|
|
579
|
+
titleShapeXml = sp;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
else if (!subtitle && /<p:ph\b[^>]*\btype=["']subTitle["']/i.test(sp)) {
|
|
583
|
+
const text = extractShapePlainText(sp);
|
|
584
|
+
if (text) {
|
|
585
|
+
subtitle = text;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
if (!title) {
|
|
590
|
+
for (const spMatch of slideXml.matchAll(/<p:sp\b[\s\S]*?<\/p:sp>/g)) {
|
|
591
|
+
const sp = spMatch[0];
|
|
592
|
+
const isTitle = /<p:ph\b(?![^>]*type=)(?:[^>]*idx=["']0["'])?/i.test(sp) ||
|
|
593
|
+
/<p:cNvPr\b[^>]*name=["'][^"']*(?:Title|标题)/i.test(sp);
|
|
594
|
+
if (isTitle) {
|
|
595
|
+
const text = extractShapePlainText(sp);
|
|
596
|
+
if (text && text.length <= 120) {
|
|
597
|
+
title = text;
|
|
598
|
+
titleShapeXml = sp;
|
|
599
|
+
break;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
if (!title) {
|
|
605
|
+
for (const spMatch of slideXml.matchAll(/<p:sp\b[\s\S]*?<\/p:sp>/g)) {
|
|
606
|
+
const sp = spMatch[0];
|
|
607
|
+
if (/<p:ph\b[^>]*type=["'](?:sldNum|dt|ftr)["']/i.test(sp))
|
|
608
|
+
continue;
|
|
609
|
+
const paras = extractShapeParagraphs(sp);
|
|
610
|
+
if (paras.length === 1 && paras[0].text.length <= 60 && !paras[0].isBullet) {
|
|
611
|
+
title = paras[0].text;
|
|
612
|
+
titleShapeXml = sp;
|
|
613
|
+
break;
|
|
614
|
+
}
|
|
615
|
+
if (paras.length > 0)
|
|
616
|
+
break;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
const paragraphs = [];
|
|
620
|
+
const tables = [];
|
|
621
|
+
const images = [];
|
|
622
|
+
const rMap = slideRelsMap.get(target);
|
|
623
|
+
// 提取图片(<p:pic>)
|
|
624
|
+
for (const picMatch of slideXml.matchAll(/<p:pic\b[\s\S]*?<\/p:pic>/gi)) {
|
|
625
|
+
const pic = picMatch[0];
|
|
626
|
+
const rEmbed = /<a:blip\b[^>]*r:embed=["']([^"']+)["']/i.exec(pic)?.[1];
|
|
627
|
+
const imgTarget = rEmbed && rMap ? rMap.get(rEmbed) : null;
|
|
628
|
+
if (imgTarget) {
|
|
629
|
+
const media = imgTarget.replace(/\\/g, "/").split("/").pop() ?? "";
|
|
630
|
+
if (media && /^image\d+\./i.test(media)) {
|
|
631
|
+
const descr = /<p:cNvPr\b[^>]*descr=["']([^"']*)["']/i.exec(pic)?.[1] ||
|
|
632
|
+
/<p:cNvPr\b[^>]*name=["']([^"']*)["']/i.exec(pic)?.[1];
|
|
633
|
+
images.push({ media, descr: descr?.trim() || undefined });
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
// 提取背景色
|
|
638
|
+
let bg;
|
|
639
|
+
const bgPrMatch = /<p:bgPr\b[\s\S]*?<a:srgbClr\b[^>]*val=["']([0-9a-fA-F]{6})["']/i.exec(slideXml);
|
|
640
|
+
if (bgPrMatch) {
|
|
641
|
+
bg = `#${bgPrMatch[1]}`;
|
|
642
|
+
}
|
|
643
|
+
else {
|
|
644
|
+
const fullSp = /<p:sp\b[\s\S]*?<a:ext\b[^>]*cx=["'](?:12\d{6}|9\d{6})["'][\s\S]*?<a:srgbClr\b[^>]*val=["']([0-9a-fA-F]{6})["']/i.exec(slideXml);
|
|
645
|
+
if (fullSp) {
|
|
646
|
+
bg = `#${fullSp[1]}`;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
for (const elemMatch of slideXml.matchAll(/<p:sp\b[\s\S]*?<\/p:sp>|<a:tbl\b[\s\S]*?<\/a:tbl>/g)) {
|
|
650
|
+
const elem = elemMatch[0];
|
|
651
|
+
if (elem.startsWith("<p:sp")) {
|
|
652
|
+
if (elem === titleShapeXml)
|
|
653
|
+
continue;
|
|
654
|
+
if (/<p:ph\b[^>]*type=["'](?:sldNum|dt|ftr)["']/i.test(elem))
|
|
655
|
+
continue;
|
|
656
|
+
const isBodyPlaceholder = /<p:ph\b[^>]*type=["']body["']/i.test(elem);
|
|
657
|
+
const paras = extractShapeParagraphs(elem, isBodyPlaceholder);
|
|
658
|
+
for (const p of paras) {
|
|
659
|
+
if (p.isBullet) {
|
|
660
|
+
const clean = p.text.replace(/^[\s•·\-*]+\s*/, "");
|
|
661
|
+
paragraphs.push(`${" ".repeat(p.lvl)}- ${clean}`);
|
|
662
|
+
}
|
|
663
|
+
else {
|
|
664
|
+
paragraphs.push(p.text);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
else if (elem.startsWith("<a:tbl")) {
|
|
669
|
+
const tbl = parseTable(elem);
|
|
670
|
+
if (tbl.length > 0)
|
|
671
|
+
tables.push(tbl);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
let notes;
|
|
675
|
+
const notesPath = slideToNotes.get(target);
|
|
676
|
+
if (notesPath) {
|
|
677
|
+
const notesXml = unzipped.get(notesPath)?.toString("utf8");
|
|
678
|
+
if (notesXml) {
|
|
679
|
+
for (const spMatch of notesXml.matchAll(/<p:sp\b[\s\S]*?<\/p:sp>/g)) {
|
|
680
|
+
const sp = spMatch[0];
|
|
681
|
+
if (/<p:ph\b[^>]*type=["']body["']/i.test(sp)) {
|
|
682
|
+
const paras = extractShapeParagraphs(sp, false);
|
|
683
|
+
const noteText = paras
|
|
684
|
+
.map((p) => p.text)
|
|
685
|
+
.join("\n")
|
|
686
|
+
.trim();
|
|
687
|
+
if (noteText) {
|
|
688
|
+
notes = noteText;
|
|
689
|
+
break;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
slides.push({
|
|
696
|
+
index: i + 1,
|
|
697
|
+
title,
|
|
698
|
+
subtitle,
|
|
699
|
+
paragraphs,
|
|
700
|
+
tables: tables.length > 0 ? tables : undefined,
|
|
701
|
+
images: images.length > 0 ? images : undefined,
|
|
702
|
+
notes,
|
|
703
|
+
bg,
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
return slides;
|
|
707
|
+
}
|
|
327
708
|
/**
|
|
328
709
|
* 表头固定用 A/B/C…(与 Excel 列标一致),而不拿第一行数据冒充表头——
|
|
329
710
|
* 很多表的第一行是通知/标题文字,染成紫色表头又怪又误导。
|
|
@@ -359,11 +740,17 @@ export function extractOfficeText(filename, buf) {
|
|
|
359
740
|
}
|
|
360
741
|
let text;
|
|
361
742
|
let truncated = false;
|
|
743
|
+
let slides;
|
|
362
744
|
if (ext === ".docx") {
|
|
363
745
|
const paras = parseDocxParagraphs(buf);
|
|
364
746
|
text = paras.join("\n");
|
|
365
747
|
truncated = text.length > OFFICE_MAX_TEXT_CHARS;
|
|
366
748
|
}
|
|
749
|
+
else if (ext === ".pptx" || ext === ".pptm" || ext === ".ppsx" || ext === ".potx") {
|
|
750
|
+
slides = parsePptxSlides(buf);
|
|
751
|
+
text = slides.map(slideToMarkdown).join("\n\n---\n\n");
|
|
752
|
+
truncated = text.length > OFFICE_MAX_TEXT_CHARS || slides.length >= PPTX_MAX_SLIDES;
|
|
753
|
+
}
|
|
367
754
|
else {
|
|
368
755
|
const sheets = parseXlsxSheets(buf);
|
|
369
756
|
text = sheets.map(sheetToMarkdown).join("\n\n");
|
|
@@ -371,5 +758,5 @@ export function extractOfficeText(filename, buf) {
|
|
|
371
758
|
}
|
|
372
759
|
if (text.length > OFFICE_MAX_TEXT_CHARS)
|
|
373
760
|
text = text.slice(0, OFFICE_MAX_TEXT_CHARS);
|
|
374
|
-
return { text, truncated };
|
|
761
|
+
return { text, truncated, slides };
|
|
375
762
|
}
|
|
@@ -92,6 +92,12 @@ export const HOST_METHODS = [
|
|
|
92
92
|
summary: "给 AI 注册工具(插件给模型加能力,与 AI 写插件方向相反)",
|
|
93
93
|
example: `host.registerAgentTool({ name: "mail", description: "…", execute: async () => ({}) })`,
|
|
94
94
|
},
|
|
95
|
+
{
|
|
96
|
+
name: "registerMarker",
|
|
97
|
+
needs: "tools",
|
|
98
|
+
summary: "注册内联状态标记(如 [[name:op:...]];模型直接输出触发副作用,正文自动剥离)",
|
|
99
|
+
example: `host.registerMarker({ name: "flag", guidance: ["[[flag:mark:<id>]] mark item"], apply: (token, ctx) => ({ applied: true }) })`,
|
|
100
|
+
},
|
|
95
101
|
{
|
|
96
102
|
name: "onToolPre",
|
|
97
103
|
needs: "tools",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
import { existsSync, readFileSync } from "node:fs";
|
|
20
20
|
import { join } from "node:path";
|
|
21
21
|
import { pick } from "./i18n.js";
|
|
22
|
-
import { normalizeSyncPayload, writeCustomCatalog } from "./plugin-catalog.js";
|
|
22
|
+
import { normalizeSyncPayload, writeCustomCatalog, writeCommunityCatalog } from "./plugin-catalog.js";
|
|
23
23
|
import { workspacePath } from "./files-service.js";
|
|
24
24
|
/**
|
|
25
25
|
* 读同步文档:`http(s)://` 走网络,其余当本地文件路径 —— **只允许工作区内的路径**
|
|
@@ -110,7 +110,15 @@ export async function syncPluginCatalog(source, opts, deps) {
|
|
|
110
110
|
if ("error" in payload)
|
|
111
111
|
return { ok: false, error: payload.error };
|
|
112
112
|
// 到这里才动磁盘:校验失败的文档绝不覆盖一份有效目录。
|
|
113
|
-
|
|
113
|
+
const isCommunity = opts.target === "community" ||
|
|
114
|
+
(Boolean(deps.communityCatalogPath) &&
|
|
115
|
+
(source.includes("pi-web-ui-plugins/catalog.json") || source.endsWith("/community-catalog.json")));
|
|
116
|
+
if (isCommunity && deps.communityCatalogPath) {
|
|
117
|
+
writeCommunityCatalog(deps.communityCatalogPath, payload.entries);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
writeCustomCatalog(deps.customCatalogPath, payload.entries, opts.replace === true);
|
|
121
|
+
}
|
|
114
122
|
await deps.afterWrite();
|
|
115
123
|
let installed;
|
|
116
124
|
if (opts.install === true && payload.entries.length) {
|
|
@@ -64,7 +64,9 @@ function atomicWrite(path, data) {
|
|
|
64
64
|
writeJsonAtomicSync(path, data);
|
|
65
65
|
}
|
|
66
66
|
/** 把任意对象规范化为合法条目;非法则返回 null。 */
|
|
67
|
-
function toEntry(raw,
|
|
67
|
+
function toEntry(raw, originOrBuiltin) {
|
|
68
|
+
const origin = typeof originOrBuiltin === "boolean" ? (originOrBuiltin ? "builtin" : "custom") : originOrBuiltin;
|
|
69
|
+
const builtin = origin === "builtin";
|
|
68
70
|
const source = typeof raw.source === "string" ? raw.source.trim() : "";
|
|
69
71
|
if (!isValidSource(source))
|
|
70
72
|
return null;
|
|
@@ -83,6 +85,7 @@ function toEntry(raw, builtin) {
|
|
|
83
85
|
name,
|
|
84
86
|
source,
|
|
85
87
|
builtin,
|
|
88
|
+
origin,
|
|
86
89
|
...(nameEn ? { nameEn } : {}),
|
|
87
90
|
...(description ? { description } : {}),
|
|
88
91
|
...(descriptionEn ? { descriptionEn } : {}),
|
|
@@ -91,38 +94,70 @@ function toEntry(raw, builtin) {
|
|
|
91
94
|
...(homepage ? { homepage } : {}),
|
|
92
95
|
};
|
|
93
96
|
}
|
|
94
|
-
/** 读合并后的目录:
|
|
97
|
+
/** 读合并后的目录:
|
|
98
|
+
* 1. builtin : 项目随包内置核心插件(不可移除);
|
|
99
|
+
* 2. community : 官方社区生态清单(pi-web-ui-plugins 自动化审核构建,不可移除);
|
|
100
|
+
* 3. custom : 用户在设置面板手动填写的自定义条目(同 id 可覆盖 builtin/community,支持单独移除)。
|
|
95
101
|
* custom 覆盖 builtin 时强制打 `overridesBuiltin: true` 标记(builtin 同时为
|
|
96
|
-
* false
|
|
97
|
-
|
|
98
|
-
* 不允许伪装成官方来源。 */
|
|
99
|
-
export function readCatalog(builtinPath, customPath) {
|
|
102
|
+
* false):显示字段来自用户可写来源,前端据此把它标识为「自定义覆盖」。 */
|
|
103
|
+
export function readCatalog(builtinPath, customPath, communityPath) {
|
|
100
104
|
const out = [];
|
|
105
|
+
const seenBuiltin = new Set();
|
|
101
106
|
const seen = new Set();
|
|
107
|
+
// 1. 内置核心插件
|
|
102
108
|
if (existsSync(builtinPath)) {
|
|
103
109
|
const raw = readJsonSafe(builtinPath, []);
|
|
104
110
|
if (Array.isArray(raw)) {
|
|
105
111
|
for (const it of raw) {
|
|
106
|
-
const e = it && typeof it === "object" ? toEntry(it,
|
|
112
|
+
const e = it && typeof it === "object" ? toEntry(it, "builtin") : null;
|
|
107
113
|
if (e && !seen.has(e.id)) {
|
|
114
|
+
seenBuiltin.add(e.id);
|
|
108
115
|
seen.add(e.id);
|
|
109
116
|
out.push(e);
|
|
110
117
|
}
|
|
111
118
|
}
|
|
112
119
|
}
|
|
113
120
|
}
|
|
121
|
+
// 2. 官方社区生态插件(若存在)
|
|
122
|
+
if (communityPath && existsSync(communityPath)) {
|
|
123
|
+
const rawCommunity = readJsonSafe(communityPath, []);
|
|
124
|
+
const list = Array.isArray(rawCommunity)
|
|
125
|
+
? rawCommunity
|
|
126
|
+
: rawCommunity &&
|
|
127
|
+
typeof rawCommunity === "object" &&
|
|
128
|
+
Array.isArray(rawCommunity.entries)
|
|
129
|
+
? rawCommunity.entries
|
|
130
|
+
: [];
|
|
131
|
+
for (const it of list) {
|
|
132
|
+
const e = it && typeof it === "object" ? toEntry(it, "community") : null;
|
|
133
|
+
if (!e)
|
|
134
|
+
continue;
|
|
135
|
+
// 内置插件绝对优先,不被社区同名条目替换
|
|
136
|
+
if (seenBuiltin.has(e.id))
|
|
137
|
+
continue;
|
|
138
|
+
const idx = out.findIndex((x) => x.id === e.id);
|
|
139
|
+
if (idx >= 0) {
|
|
140
|
+
out[idx] = e;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
out.push(e);
|
|
144
|
+
}
|
|
145
|
+
seen.add(e.id);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// 3. 用户在设置面板手动添加的自定义条目
|
|
114
149
|
const rawCustom = readJsonSafe(customPath, {});
|
|
115
150
|
const list = rawCustom && typeof rawCustom === "object" && Array.isArray(rawCustom.entries)
|
|
116
151
|
? rawCustom.entries
|
|
117
152
|
: [];
|
|
118
153
|
for (const it of list) {
|
|
119
|
-
const e = it && typeof it === "object" ? toEntry(it,
|
|
154
|
+
const e = it && typeof it === "object" ? toEntry(it, "custom") : null;
|
|
120
155
|
if (!e)
|
|
121
156
|
continue;
|
|
122
157
|
const idx = out.findIndex((x) => x.id === e.id);
|
|
123
158
|
if (idx >= 0) {
|
|
124
|
-
// 覆盖了同名 builtin 条目:强制带标识(不信任 custom 文件里的任何自标字段)。
|
|
125
|
-
out[idx] = { ...e, builtin: false, overridesBuiltin:
|
|
159
|
+
// 覆盖了同名 builtin/community 条目:强制带标识(不信任 custom 文件里的任何自标字段)。
|
|
160
|
+
out[idx] = { ...e, builtin: false, origin: "custom", overridesBuiltin: seenBuiltin.has(e.id) };
|
|
126
161
|
}
|
|
127
162
|
else {
|
|
128
163
|
out.push(e);
|
|
@@ -240,3 +275,21 @@ export function writeCustomCatalog(customPath, incoming, replace) {
|
|
|
240
275
|
atomicWrite(customPath, { entries });
|
|
241
276
|
return entries.length;
|
|
242
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* 原子写入官方社区生态清单(由远端构建的 catalog.json 同步而来,全量替换)。
|
|
280
|
+
*/
|
|
281
|
+
export function writeCommunityCatalog(communityPath, incoming) {
|
|
282
|
+
const entries = incoming.map((e) => ({
|
|
283
|
+
id: e.id,
|
|
284
|
+
source: e.source,
|
|
285
|
+
name: e.name,
|
|
286
|
+
...(e.nameEn ? { nameEn: e.nameEn } : {}),
|
|
287
|
+
...(e.description ? { description: e.description } : {}),
|
|
288
|
+
...(e.descriptionEn ? { descriptionEn: e.descriptionEn } : {}),
|
|
289
|
+
...(e.icon ? { icon: e.icon } : {}),
|
|
290
|
+
...(e.iconSvg ? { iconSvg: e.iconSvg } : {}),
|
|
291
|
+
...(e.homepage ? { homepage: e.homepage } : {}),
|
|
292
|
+
}));
|
|
293
|
+
atomicWrite(communityPath, { entries });
|
|
294
|
+
return entries.length;
|
|
295
|
+
}
|