pi-web-ui 0.110.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/bin/frp-manager.mjs +85 -7
- package/dist/server/agent-formatters.js +10 -6
- package/dist/server/agent-service-daemon.js +27 -9
- package/dist/server/agent-service.js +140 -24
- package/dist/server/attachments.js +114 -31
- 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/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/file-transfer-routes.js +8 -2
- package/dist/server/files-service.js +10 -2
- package/dist/server/index.js +137 -4
- package/dist/server/marker-service.js +3 -1
- package/dist/server/markers/marker.js +45 -4
- package/dist/server/markers/registry.js +31 -0
- package/dist/server/message-window.js +6 -3
- package/dist/server/office-parse.js +394 -7
- package/dist/server/plugin-api-catalog.js +6 -0
- package/dist/server/plugins.js +97 -20
- package/dist/server/preset-fields.js +35 -1
- package/dist/server/preset-share.js +3 -0
- 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 +19 -3
- 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/universal-attachments.js +5 -0
- package/dist/server/universal/universal-service.js +5 -0
- package/dist/server/universal/universal-session.js +28 -12
- package/dist/server/update-check.js +90 -5
- package/dist/server/workspace-snapshot.js +33 -2
- package/docs/dsh-engine.md +497 -0
- package/package.json +5 -4
- package/plugin-sdk/index.d.ts +17 -0
- package/plugin-sdk/index.mjs +5 -0
- package/plugins/catalog.json +22 -0
- package/themes/aetheris.css +114 -0
- package/themes/bases/obsidian-base.css +216 -0
- package/themes/md-preview.css +113 -0
- package/themes/wallpaper-flow.css +182 -0
- package/web/dist/assets/{TerminalPanel-BHjM6pzY.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-DwInT7-a.css +0 -1
- package/web/dist/assets/index-GfVFIgIL.js +0 -693
- 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",
|
package/dist/server/plugins.js
CHANGED
|
@@ -1,21 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* pi-web-ui 插件管理器 —— 可选界面组件的加载与桥接。
|
|
3
|
-
*
|
|
4
|
-
* 一个插件 = <dataDir>/plugins/<id>/ 目录:
|
|
5
|
-
* manifest.json 元数据 { id?, name, version?, description? }(id 缺省取目录名)
|
|
6
|
-
* index.mjs 服务端入口(可选):export default { activate(host) → deactivate? }
|
|
7
|
-
* client/ 前端资源(可选),经 /plugins/<id>/client/* 以静态文件暴露;
|
|
8
|
-
* entry.mjs 视图入口:export default { mount(el, ctx) → cleanup? }
|
|
9
|
-
*
|
|
10
|
-
* 设计要点:
|
|
11
|
-
* - 不装即不存在:目录不在就没有任何协议/UI 痕迹;每次客户端 attach 时重扫目录,
|
|
12
|
-
* 新丢进来的插件无需重启服务即可出现在顶栏(import 只做一次并缓存)。
|
|
13
|
-
* - id 必须匹配 ID_RE,防路径穿越;client 静态服务同样逐段校验。
|
|
14
|
-
* - host 窄接口:broadcast(pluginId, payload) 广播 plugin_data、onMessage 注册
|
|
15
|
-
* 客户端上行处理、dataDir/cwd/log 环境。发送通道由 index.ts 注入(每个 socket
|
|
16
|
-
* 的 send 函数),插件本身不接触 ws。
|
|
17
|
-
* - activate 抛错只标记 error 字段并记日志,绝不影响主进程。
|
|
18
|
-
*/
|
|
1
|
+
import { registerMarker, unregisterMarker, isBuiltinMarker } from "./markers/index.js";
|
|
19
2
|
import { mkdir, readdir, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
20
3
|
import { cpSync, existsSync, lstatSync, readFileSync, readdirSync, renameSync, watch as fsWatch, writeFileSync, } from "node:fs";
|
|
21
4
|
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
@@ -996,6 +979,10 @@ export class PluginManager {
|
|
|
996
979
|
pluginBgTasks = new Map();
|
|
997
980
|
/** 任务集合变化回调(index.ts 接到 AgentService,重推 bg_servers)。 */
|
|
998
981
|
onBgTasksChanged = undefined;
|
|
982
|
+
/** 插件注册的内联标记:pluginId → (name → 定义)。 */
|
|
983
|
+
pluginMarkers = new Map();
|
|
984
|
+
/** 标记工具集合变化回调(index.ts 接到 AgentService,刷新各客户端 markers)。 */
|
|
985
|
+
onMarkersChanged = undefined;
|
|
999
986
|
/** P3:左栏插件运行条目(见 left-panel-running.ts)。 */
|
|
1000
987
|
panelRunning = new LeftPanelRunningStore();
|
|
1001
988
|
panelPushTimer = null;
|
|
@@ -1852,6 +1839,82 @@ export class PluginManager {
|
|
|
1852
1839
|
}
|
|
1853
1840
|
};
|
|
1854
1841
|
}
|
|
1842
|
+
/** 注册内联标记(Inline Marker):跨插件重名拒绝,系统内置标记冲突拒绝。 */
|
|
1843
|
+
registerMarker(pluginId, marker) {
|
|
1844
|
+
if (!marker || typeof marker !== "object") {
|
|
1845
|
+
console.error(`[plugin:${pluginId}] registerMarker: 缺少 marker 参数,忽略`);
|
|
1846
|
+
this.pushRuntimeDiag(pluginId, "registerMarker: missing marker parameter, ignored");
|
|
1847
|
+
return () => { };
|
|
1848
|
+
}
|
|
1849
|
+
const name = String(marker.name ?? "").trim();
|
|
1850
|
+
if (!/^[A-Za-z][A-Za-z0-9_-]*$/.test(name)) {
|
|
1851
|
+
console.error(`[plugin:${pluginId}] registerMarker: 非法名称「${marker.name}」(需英文字母开头,只允许字母数字_-),忽略`);
|
|
1852
|
+
this.pushRuntimeDiag(pluginId, `registerMarker: invalid name "${String(marker.name ?? "").slice(0, 32)}", ignored`);
|
|
1853
|
+
return () => { };
|
|
1854
|
+
}
|
|
1855
|
+
if (isBuiltinMarker(name)) {
|
|
1856
|
+
console.error(`[plugin:${pluginId}] registerMarker: 名称「${name}」为系统内置标记保留名称,忽略冲突注册`);
|
|
1857
|
+
this.pushRuntimeDiag(pluginId, `registerMarker: "${name}" conflicts with built-in marker, ignored`);
|
|
1858
|
+
return () => { };
|
|
1859
|
+
}
|
|
1860
|
+
if (typeof marker.apply !== "function") {
|
|
1861
|
+
console.error(`[plugin:${pluginId}] registerMarker: ${name} 缺少 apply 函数,忽略`);
|
|
1862
|
+
this.pushRuntimeDiag(pluginId, `marker "${name}": missing apply function, ignored`);
|
|
1863
|
+
return () => { };
|
|
1864
|
+
}
|
|
1865
|
+
if (!Array.isArray(marker.guidance) || marker.guidance.length === 0) {
|
|
1866
|
+
console.error(`[plugin:${pluginId}] registerMarker: ${name} 缺少 guidance 引导说明,忽略`);
|
|
1867
|
+
this.pushRuntimeDiag(pluginId, `marker "${name}": missing guidance, ignored`);
|
|
1868
|
+
return () => { };
|
|
1869
|
+
}
|
|
1870
|
+
for (const [pid, other] of this.pluginMarkers) {
|
|
1871
|
+
if (pid !== pluginId && other.has(name)) {
|
|
1872
|
+
console.error(`[plugin:${pluginId}] 标记 "${name}" 已被插件 ${pid} 注册,忽略重复`);
|
|
1873
|
+
this.pushRuntimeDiag(pluginId, `marker "${name}": already registered by plugin ${pid}, ignored`);
|
|
1874
|
+
return () => { };
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
let table = this.pluginMarkers.get(pluginId);
|
|
1878
|
+
if (!table)
|
|
1879
|
+
this.pluginMarkers.set(pluginId, (table = new Map()));
|
|
1880
|
+
if (table.has(name)) {
|
|
1881
|
+
console.error(`[plugin:${pluginId}] 标记 "${name}" 重复注册,忽略`);
|
|
1882
|
+
this.pushRuntimeDiag(pluginId, `marker "${name}": duplicate registration, ignored`);
|
|
1883
|
+
return () => { };
|
|
1884
|
+
}
|
|
1885
|
+
const markerTool = {
|
|
1886
|
+
name,
|
|
1887
|
+
label: marker.label ? String(marker.label).slice(0, 80) : undefined,
|
|
1888
|
+
pluginId,
|
|
1889
|
+
guidance: [...marker.guidance],
|
|
1890
|
+
getGuidance: marker.getGuidance,
|
|
1891
|
+
apply: marker.apply,
|
|
1892
|
+
overlay: marker.overlay,
|
|
1893
|
+
init: marker.init,
|
|
1894
|
+
};
|
|
1895
|
+
table.set(name, markerTool);
|
|
1896
|
+
registerMarker(markerTool);
|
|
1897
|
+
console.log(`[plugin:${pluginId}] registered inline marker: ${name}`);
|
|
1898
|
+
try {
|
|
1899
|
+
this.onMarkersChanged?.();
|
|
1900
|
+
}
|
|
1901
|
+
catch (err) {
|
|
1902
|
+
console.error("[plugins] onMarkersChanged failed:", err);
|
|
1903
|
+
}
|
|
1904
|
+
return () => {
|
|
1905
|
+
if (table.delete(name)) {
|
|
1906
|
+
if (table.size === 0)
|
|
1907
|
+
this.pluginMarkers.delete(pluginId);
|
|
1908
|
+
unregisterMarker(name);
|
|
1909
|
+
try {
|
|
1910
|
+
this.onMarkersChanged?.();
|
|
1911
|
+
}
|
|
1912
|
+
catch {
|
|
1913
|
+
/* shutting down */
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
};
|
|
1917
|
+
}
|
|
1855
1918
|
/** 注册斜杠命令:跨插件重名拒绝(先注册者胜出),onCommandsChanged 通知目录刷新。 */
|
|
1856
1919
|
registerCommand(pluginId, cmd) {
|
|
1857
1920
|
const name = String(cmd?.name ?? "").replace(/^\/+/, ""); // 容忍误带的前导 /
|
|
@@ -2203,6 +2266,7 @@ export class PluginManager {
|
|
|
2203
2266
|
this.panelSweepTimer = null;
|
|
2204
2267
|
}
|
|
2205
2268
|
this.agentTools.clear();
|
|
2269
|
+
this.pluginMarkers.clear();
|
|
2206
2270
|
this.pluginCommands.clear();
|
|
2207
2271
|
this.uiRuntime.clear();
|
|
2208
2272
|
this.uiBase.clear();
|
|
@@ -2296,8 +2360,15 @@ export class PluginManager {
|
|
|
2296
2360
|
continue;
|
|
2297
2361
|
const dir = join(this.pluginsDir, name);
|
|
2298
2362
|
try {
|
|
2299
|
-
|
|
2363
|
+
const st = await stat(dir);
|
|
2364
|
+
if (!st.isDirectory())
|
|
2300
2365
|
continue;
|
|
2366
|
+
}
|
|
2367
|
+
catch {
|
|
2368
|
+
// 目录不存在(如失效的软链接)或非目录/不可访问,跳过
|
|
2369
|
+
continue;
|
|
2370
|
+
}
|
|
2371
|
+
try {
|
|
2301
2372
|
const raw = await readFile(join(dir, "manifest.json"), "utf8");
|
|
2302
2373
|
// wantsDom 快照供静态门禁用(manifest 坏了 → JSON.parse 抛 → catch 跳过,旧快照残留无害:门禁只拦「快照里要且没授权」的)。
|
|
2303
2374
|
const m = JSON.parse(raw);
|
|
@@ -3230,7 +3301,7 @@ export class PluginManager {
|
|
|
3230
3301
|
if (!can("http"))
|
|
3231
3302
|
return () => { };
|
|
3232
3303
|
const m = String(method ?? "GET").toUpperCase();
|
|
3233
|
-
if (!["GET", "POST", "PUT", "DELETE"].includes(m) ||
|
|
3304
|
+
if (!["GET", "POST", "PUT", "DELETE", "OPTIONS"].includes(m) ||
|
|
3234
3305
|
typeof path !== "string" ||
|
|
3235
3306
|
!path.startsWith("/") ||
|
|
3236
3307
|
typeof handler !== "function") {
|
|
@@ -3262,6 +3333,12 @@ export class PluginManager {
|
|
|
3262
3333
|
const off = this.registerAgentTool(info.id, tool);
|
|
3263
3334
|
return effects.add(`agentTool:${String(tool?.name ?? "?")}`, off);
|
|
3264
3335
|
},
|
|
3336
|
+
registerMarker: (marker) => {
|
|
3337
|
+
if (!can("tools"))
|
|
3338
|
+
return () => { };
|
|
3339
|
+
const off = this.registerMarker(info.id, marker);
|
|
3340
|
+
return effects.add(`marker:${String(marker?.name ?? "?")}`, off);
|
|
3341
|
+
},
|
|
3265
3342
|
registerTool: (tool) => {
|
|
3266
3343
|
if (!can("tools"))
|
|
3267
3344
|
return () => { };
|
|
@@ -51,7 +51,14 @@ export const PRESET_FIELD_GROUPS = {
|
|
|
51
51
|
// 终端接管
|
|
52
52
|
terminal: ["terminalBash", "terminalBashIdleMs", "terminalBashMaxForegroundMs"],
|
|
53
53
|
// 技能与扩展
|
|
54
|
-
skills: [
|
|
54
|
+
skills: [
|
|
55
|
+
"disabledSkills",
|
|
56
|
+
"disabledExtensions",
|
|
57
|
+
"skillsFullText",
|
|
58
|
+
"skillsCatalogMaxDesc",
|
|
59
|
+
"skillsCatalogShowLocation",
|
|
60
|
+
"skillsCatalogBudget",
|
|
61
|
+
],
|
|
55
62
|
// 模型侧行为与各专用提示词
|
|
56
63
|
ai: [
|
|
57
64
|
"retryMaxAttempts",
|
|
@@ -283,6 +290,24 @@ export const PRESET_FIELD_META = {
|
|
|
283
290
|
hintZh: "将指定技能的完整正文直接注入上下文,跳过 skill 工具按需载入",
|
|
284
291
|
hintEn: "Inject full text of selected skills directly into context",
|
|
285
292
|
},
|
|
293
|
+
skillsCatalogMaxDesc: {
|
|
294
|
+
labelZh: "技能描述截断字符数",
|
|
295
|
+
labelEn: "Skill Description Cap",
|
|
296
|
+
hintZh: "名录中单条技能描述最大字符数(默认 250,0 为不截断)",
|
|
297
|
+
hintEn: "Max characters per skill description in catalog (default 250, 0 to disable)",
|
|
298
|
+
},
|
|
299
|
+
skillsCatalogShowLocation: {
|
|
300
|
+
labelZh: "名录显示物理路径",
|
|
301
|
+
labelEn: "Show Skill Location",
|
|
302
|
+
hintZh: "是否在技能名录中输出 location 文件绝对路径(默认关,避免浪费 token 和泄露路径)",
|
|
303
|
+
hintEn: "Whether to output file path in skill catalog (default off to save tokens and prevent path leak)",
|
|
304
|
+
},
|
|
305
|
+
skillsCatalogBudget: {
|
|
306
|
+
labelZh: "技能名录总字符预算",
|
|
307
|
+
labelEn: "Skill Catalog Budget",
|
|
308
|
+
hintZh: "技能名录字符上限(默认 20000),超限自动降级为紧凑名称索引",
|
|
309
|
+
hintEn: "Total catalog character limit (default 20000), falls back to compact name index when exceeded",
|
|
310
|
+
},
|
|
286
311
|
// ai
|
|
287
312
|
retryMaxAttempts: {
|
|
288
313
|
labelZh: "网络重试上限",
|
|
@@ -602,6 +627,15 @@ export function formatPresetFieldValue(field, value, lang = "zh") {
|
|
|
602
627
|
detail: list.map((item) => `- ${item}`).join("\n"),
|
|
603
628
|
};
|
|
604
629
|
}
|
|
630
|
+
if (field === "skillsCatalogMaxDesc" || field === "skillsCatalogBudget") {
|
|
631
|
+
const n = Number(value);
|
|
632
|
+
const zeroText = isZh ? "不限" : "No limit";
|
|
633
|
+
const valText = n === 0 ? zeroText : isZh ? `${n} 字符` : `${n} chars`;
|
|
634
|
+
return { summary: valText };
|
|
635
|
+
}
|
|
636
|
+
if (field === "skillsCatalogShowLocation") {
|
|
637
|
+
return { summary: value ? (isZh ? "开启" : "Enabled") : isZh ? "关闭" : "Disabled" };
|
|
638
|
+
}
|
|
605
639
|
// 6. 提示词文本
|
|
606
640
|
if (field === "customSystemPrompt" ||
|
|
607
641
|
field === "promptTemplate" ||
|