dsh-ppt 0.12.1 → 0.14.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 +16 -0
- package/README.en.md +3 -0
- package/README.md +4 -0
- package/docs/COACHING.md +44 -0
- package/docs/VALIDATION.md +2 -0
- package/docs/validation-0.14.0.md +24 -0
- package/lib/client.js +274 -12
- package/lib/coaching-model.d.ts +12 -0
- package/lib/coaching-model.js +93 -0
- package/lib/coaching.d.ts +196 -0
- package/lib/coaching.js +317 -0
- package/lib/execution.d.ts +2 -0
- package/lib/index.js +8 -1
- package/lib/workbench-language.js +2 -0
- package/lib/workbench.d.ts +4 -0
- package/lib/workbench.js +51 -7
- package/package.json +2 -2
- package/skills/dsh-ppt/SKILL.md +2 -0
- package/skills/dsh-ppt/scripts/deck-advanced.mjs +11 -4
package/lib/workbench.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type PptExecution } from './execution.js';
|
|
2
2
|
import type { DeckEngine } from './types.js';
|
|
3
|
+
import { PptCoaching } from './coaching.js';
|
|
4
|
+
import type { CoachingModel } from './coaching-model.js';
|
|
3
5
|
export declare const PPT_WORKBENCH_ROUTE = "/api/dsh-ppt/workbench";
|
|
4
6
|
export declare const PPT_DOWNLOAD_ROUTE = "/api/dsh-ppt/download";
|
|
5
7
|
type WorkbenchEngine = DeckEngine & {
|
|
@@ -11,9 +13,11 @@ type WorkbenchEngine = DeckEngine & {
|
|
|
11
13
|
type Options = {
|
|
12
14
|
catalogPath?: string;
|
|
13
15
|
loadEngine?: () => Promise<WorkbenchEngine>;
|
|
16
|
+
coachingModel?: CoachingModel;
|
|
14
17
|
};
|
|
15
18
|
export declare class PptWorkbench {
|
|
16
19
|
readonly catalogPath: string;
|
|
20
|
+
readonly coaching: PptCoaching;
|
|
17
21
|
private readonly loadEngine;
|
|
18
22
|
private readonly renders;
|
|
19
23
|
constructor(options?: Options);
|
package/lib/workbench.js
CHANGED
|
@@ -6,6 +6,7 @@ import { basename, dirname, join, resolve } from 'node:path';
|
|
|
6
6
|
import { getEngine } from './execution.js';
|
|
7
7
|
import { bilingualQuality, englishWorkbenchMessage } from './workbench-language.js';
|
|
8
8
|
import { zipSync, strToU8 } from 'fflate';
|
|
9
|
+
import { PptCoaching } from './coaching.js';
|
|
9
10
|
export const PPT_WORKBENCH_ROUTE = '/api/dsh-ppt/workbench';
|
|
10
11
|
export const PPT_DOWNLOAD_ROUTE = '/api/dsh-ppt/download';
|
|
11
12
|
const REQUEST_LIMIT = 12 * 1024 * 1024;
|
|
@@ -32,7 +33,10 @@ function speakerNotes(manifest) {
|
|
|
32
33
|
function json(status, value) {
|
|
33
34
|
return new Response(JSON.stringify(value), { status, headers: { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' } });
|
|
34
35
|
}
|
|
35
|
-
function fail(status, message) {
|
|
36
|
+
function fail(status, message) {
|
|
37
|
+
const display = /[\u3400-\u9fff]/.test(message) && message.includes(' / ') ? message.slice(0, message.indexOf(' / ')) : message;
|
|
38
|
+
return json(status, { ok: false, message: display, messageEn: englishWorkbenchMessage(message) });
|
|
39
|
+
}
|
|
36
40
|
function originVerdict(request) {
|
|
37
41
|
const site = request.headers.get('sec-fetch-site'), origin = request.headers.get('origin');
|
|
38
42
|
if (site && !['same-origin', 'none'].includes(site))
|
|
@@ -49,11 +53,13 @@ function originVerdict(request) {
|
|
|
49
53
|
}
|
|
50
54
|
export class PptWorkbench {
|
|
51
55
|
catalogPath;
|
|
56
|
+
coaching;
|
|
52
57
|
loadEngine;
|
|
53
58
|
renders = new Map();
|
|
54
59
|
constructor(options = {}) {
|
|
55
60
|
this.catalogPath = options.catalogPath ?? join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'plugins', 'dsh-ppt', 'projects.jsonl');
|
|
56
61
|
this.loadEngine = options.loadEngine ?? getEngine;
|
|
62
|
+
this.coaching = new PptCoaching(join(dirname(this.catalogPath), 'rehearsals'), options.coachingModel);
|
|
57
63
|
}
|
|
58
64
|
catalog() {
|
|
59
65
|
if (!existsSync(this.catalogPath))
|
|
@@ -86,7 +92,11 @@ export class PptWorkbench {
|
|
|
86
92
|
// Versioned generator projects only; arbitrary JSON and externally edited PPTX cannot enter.
|
|
87
93
|
if (manifest.schemaVersion !== 1 || typeof manifest.deckId !== 'string' || manifest.slides.some((s) => typeof s.id !== 'string'))
|
|
88
94
|
return;
|
|
89
|
-
|
|
95
|
+
let route = exec?.agent?.session.requestContext?.();
|
|
96
|
+
if (!route?.provider || !route?.model)
|
|
97
|
+
route = exec?.agent?.session.requestHeader?.()?.config;
|
|
98
|
+
const modelRoute = typeof route?.provider === 'string' && typeof route?.model === 'string' ? { provider: route.provider, model: route.model } : this.catalog().find(p => p.path === path)?.modelRoute;
|
|
99
|
+
const row = { id: digest(path), path, title: manifest.title, updatedAt: new Date().toISOString(), ...(modelRoute ? { modelRoute } : {}) };
|
|
90
100
|
mkdirSync(dirname(this.catalogPath), { recursive: true });
|
|
91
101
|
if (existsSync(this.catalogPath) && lstatSync(this.catalogPath).size >= 8 * 1024 * 1024)
|
|
92
102
|
throw new Error('项目索引已满,请备份后整理 projects.jsonl');
|
|
@@ -160,6 +170,19 @@ export class PptWorkbench {
|
|
|
160
170
|
return this.view(body.id);
|
|
161
171
|
const { entry, engine, manifest, files } = await this.project(body.id);
|
|
162
172
|
signal?.throwIfAborted();
|
|
173
|
+
const context = { id: entry.id, manifest };
|
|
174
|
+
if (body.operation === 'coach-options')
|
|
175
|
+
return { ok: true, ...await this.coaching.options(signal) };
|
|
176
|
+
if (body.operation === 'coach-list')
|
|
177
|
+
return { ok: true, runs: this.coaching.list(context) };
|
|
178
|
+
if (body.operation === 'coach-get')
|
|
179
|
+
return { ok: true, run: this.coaching.get(context, body.runId) };
|
|
180
|
+
if (body.operation === 'coach-stop')
|
|
181
|
+
return { ok: true, run: this.coaching.stop(context, body.runId) };
|
|
182
|
+
if (body.operation === 'coach-finish')
|
|
183
|
+
return { ok: true, run: this.coaching.finish(context, body.runId) };
|
|
184
|
+
if (body.operation === 'coach-delete')
|
|
185
|
+
return { ok: true, ...this.coaching.remove(context, body.runId) };
|
|
163
186
|
if (body.operation === 'download') {
|
|
164
187
|
if (!['html', 'pptx', 'json'].includes(String(body.kind)))
|
|
165
188
|
throw new Error('不支持此文件类型');
|
|
@@ -178,6 +201,23 @@ export class PptWorkbench {
|
|
|
178
201
|
return { ok: true, data: 'data:image/png;base64,' + bytes.toString('base64') };
|
|
179
202
|
}
|
|
180
203
|
this.revision(body, manifest);
|
|
204
|
+
if (body.operation === 'coach-create')
|
|
205
|
+
return { ok: true, run: await this.coaching.create(context, body, signal) };
|
|
206
|
+
if (body.operation === 'coach-step') {
|
|
207
|
+
await this.coaching.step(context, body.runId, body, signal);
|
|
208
|
+
const current = await this.project(entry.id);
|
|
209
|
+
return { ok: true, run: this.coaching.get({ id: entry.id, manifest: current.manifest }, body.runId) };
|
|
210
|
+
}
|
|
211
|
+
if (body.operation === 'coach-apply') {
|
|
212
|
+
if (body.confirmed !== true)
|
|
213
|
+
throw new Error('请确认采纳所选建议 / Confirm selected suggestions');
|
|
214
|
+
const { edits, append } = this.coaching.application(context, body.runId, body.selected, body.backup);
|
|
215
|
+
const args = { deckPath: entry.path, expectedRevision: manifest.revision, signal, saveAs: true, preserveUndo: true,
|
|
216
|
+
...(edits.length ? { edits } : {}), ...(append.length ? { append } : {}) };
|
|
217
|
+
const result = await engine.editDeck(args);
|
|
218
|
+
await this.remember(result, args);
|
|
219
|
+
return { ...await this.view(digest(result.jsonPath)), originalId: entry.id };
|
|
220
|
+
}
|
|
181
221
|
if (body.operation === 'render') {
|
|
182
222
|
const result = await engine.renderDeck({ pptxPath: files.pptx, format: 'png', signal });
|
|
183
223
|
if (result.ok)
|
|
@@ -226,14 +266,18 @@ export class PptWorkbench {
|
|
|
226
266
|
return denied;
|
|
227
267
|
try {
|
|
228
268
|
const params = new URL(request.url).searchParams, kind = params.get('kind');
|
|
229
|
-
if (!['html', 'pptx', 'json', 'bundle', 'notes'].includes(String(kind)))
|
|
269
|
+
if (!['html', 'pptx', 'json', 'bundle', 'notes', 'coaching'].includes(String(kind)))
|
|
230
270
|
return fail(400, '不支持此文件类型');
|
|
231
271
|
const { entry, manifest, files } = await this.project(params.get('id'));
|
|
232
272
|
if (String(manifest.revision) !== params.get('revision'))
|
|
233
273
|
return fail(409, '项目已被修改,请重新打开后下载');
|
|
234
274
|
request.signal.throwIfAborted();
|
|
235
275
|
let name, bytes;
|
|
236
|
-
if (kind === '
|
|
276
|
+
if (kind === 'coaching') {
|
|
277
|
+
bytes = strToU8(this.coaching.markdown({ id: entry.id, manifest }, params.get('run')));
|
|
278
|
+
name = basename(entry.path, '.json') + '-rehearsal.md';
|
|
279
|
+
}
|
|
280
|
+
else if (kind === 'notes') {
|
|
237
281
|
bytes = strToU8(speakerNotes(manifest));
|
|
238
282
|
name = basename(entry.path, '.json') + '-speaker-notes.md';
|
|
239
283
|
}
|
|
@@ -265,10 +309,10 @@ export class PptWorkbench {
|
|
|
265
309
|
request.signal.throwIfAborted();
|
|
266
310
|
if ((await this.project(entry.id)).manifest.revision !== manifest.revision)
|
|
267
311
|
return fail(409, '项目已被修改,请重新打开后下载');
|
|
268
|
-
const type = kind === 'notes' ? 'text/markdown; charset=utf-8' : kind === 'bundle' ? 'application/zip' : kind === 'pptx' ? 'application/vnd.openxmlformats-officedocument.presentationml.presentation' : kind === 'html' ? 'text/html; charset=utf-8' : 'application/json; charset=utf-8';
|
|
312
|
+
const type = kind === 'notes' || kind === 'coaching' ? 'text/markdown; charset=utf-8' : kind === 'bundle' ? 'application/zip' : kind === 'pptx' ? 'application/vnd.openxmlformats-officedocument.presentationml.presentation' : kind === 'html' ? 'text/html; charset=utf-8' : 'application/json; charset=utf-8';
|
|
269
313
|
return new Response(new Uint8Array(bytes), { headers: {
|
|
270
314
|
'content-type': type, 'cache-control': 'no-store', 'x-content-type-options': 'nosniff',
|
|
271
|
-
'content-disposition': `attachment; filename="presentation.${kind === 'bundle' ? 'zip' : kind === 'notes' ? 'md' : kind}"; filename*=UTF-8''${encodeURIComponent(name)}`,
|
|
315
|
+
'content-disposition': `attachment; filename="presentation.${kind === 'bundle' ? 'zip' : kind === 'notes' || kind === 'coaching' ? 'md' : kind}"; filename*=UTF-8''${encodeURIComponent(name)}`,
|
|
272
316
|
} });
|
|
273
317
|
}
|
|
274
318
|
catch (error) {
|
|
@@ -312,7 +356,7 @@ export class PptWorkbench {
|
|
|
312
356
|
}
|
|
313
357
|
catch (error) {
|
|
314
358
|
const message = error instanceof Error ? error.message : String(error);
|
|
315
|
-
return fail(
|
|
359
|
+
return fail(/修订号冲突|已被修改|工程已被修改|正在被另一次|其他操作修改/.test(message) ? 409 : 400, message);
|
|
316
360
|
}
|
|
317
361
|
}
|
|
318
362
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-ppt",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "DSH 演示文稿插件:生成 HTML、可编辑 PPTX
|
|
3
|
+
"version": "0.14.0",
|
|
4
|
+
"description": "DSH 演示文稿插件:生成 HTML、可编辑 PPTX 和工程文件,支持轻量编辑、可选 AI 预审与模拟答辩。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|
package/skills/dsh-ppt/SKILL.md
CHANGED
|
@@ -15,6 +15,8 @@ allowed-tools: "Bash, Read, Write, Edit"
|
|
|
15
15
|
|
|
16
16
|
## 执行纪律(每次都要遵守)
|
|
17
17
|
|
|
18
|
+
- 默认直接交付成品,不自动触发 AI 预审或答辩。用户可在设置页成品下载区主动开启两个可选模式;选择模型、范围与调用上限后再发送材料。AI 演练不等于事实核验,不编造实验、数据或引用;采纳建议另存副本,原件保留。
|
|
19
|
+
|
|
18
20
|
- 修改工程先 `ppt_check`。外部编辑过的 HTML/PPTX、缺少成品校验记录的旧工程不可覆盖;告知用户 `saveAs:true` 只从 JSON 另存新副本,原件保留,Office 手工修改不会导入。不得绕过校验或自行篡改校验值。
|
|
19
21
|
|
|
20
22
|
- 一页一个观点;标题是判断句,不是名词短语。
|
|
@@ -411,10 +411,10 @@ export function readDeckProject(options = {}) {
|
|
|
411
411
|
function expected(manifest, revision) {
|
|
412
412
|
if (revision !== undefined && (!Number.isInteger(revision) || revision !== manifest.revision)) fail(`修订号冲突:当前 revision=${manifest.revision},请重新读取工程后修改`)
|
|
413
413
|
}
|
|
414
|
-
async function saveRevision(state, next, signal, saveAs = false) {
|
|
414
|
+
async function saveRevision(state, next, signal, saveAs = false, preserveUndo = false) {
|
|
415
415
|
if (!saveAs) { const problem = artifactProblem(state.manifest, pathsFor(state.path)); if (problem) fail(problem) }
|
|
416
416
|
next.version = DECK_VERSION; next.schemaVersion = 1; next.revision = state.manifest.revision + 1
|
|
417
|
-
if (saveAs) { next.deckId = randomUUID(); next.revision = 0; next.history = [] }
|
|
417
|
+
if (saveAs) { next.deckId = randomUUID(); next.revision = 0; next.history = preserveUndo ? [snapshot(state.manifest)] : [] }
|
|
418
418
|
const data = await generate(next, signal)
|
|
419
419
|
let paths = pathsFor(state.path)
|
|
420
420
|
withLock(state.path, () => {
|
|
@@ -437,7 +437,7 @@ export async function editDeck(options = {}) {
|
|
|
437
437
|
expected(current, options.expectedRevision)
|
|
438
438
|
const next = clone(current)
|
|
439
439
|
if (!Array.isArray(options.edits) || !options.edits.length) {
|
|
440
|
-
if (options.brand === undefined && options.order === undefined && options.duplicate === undefined && options.remove === undefined && options.saveAs !== true) fail('请提供 edits、order、duplicate、remove 或 brand')
|
|
440
|
+
if (options.brand === undefined && options.order === undefined && options.duplicate === undefined && options.remove === undefined && options.append === undefined && options.saveAs !== true) fail('请提供 edits、order、duplicate、remove、append 或 brand')
|
|
441
441
|
}
|
|
442
442
|
const used = new Set(), allowed = new Set(['layout', 'title', 'subtitle', 'kicker', 'text', 'bullets', 'rows', 'notes', 'image', 'chart'])
|
|
443
443
|
for (const edit of options.edits ?? []) {
|
|
@@ -484,11 +484,18 @@ export async function editDeck(options = {}) {
|
|
|
484
484
|
if (count > 120) fail('工程页数超过 120')
|
|
485
485
|
if (duplicate.size || remove.size) next.slides = next.slides.flatMap(slide => remove.has(slide.id) ? [] :
|
|
486
486
|
duplicate.has(slide.id) ? [slide, { ...clone(slide), id: randomUUID() }] : [slide])
|
|
487
|
+
if (options.append !== undefined) {
|
|
488
|
+
if (!Array.isArray(options.append) || options.append.length < 1 || options.append.length > 5) fail('append 需为 1-5 页')
|
|
489
|
+
validateRawSlides(options.append)
|
|
490
|
+
const added = normalizeSlides(options.append, 120, next.language)
|
|
491
|
+
if (next.slides.length + added.length > 120) fail('工程页数超过 120')
|
|
492
|
+
next.slides.push(...embedSlides(added, next.assets, resolve(options.cwd || '.')).map(slide => ({ ...slide, id: randomUUID() })))
|
|
493
|
+
}
|
|
487
494
|
if (options.brand !== undefined) next.brand = normalizeBrand(options.brand === null ? null : { ...next.brand, ...options.brand,
|
|
488
495
|
...(options.brand?.logo === null ? { logo: undefined, logoAssetId: undefined } : {}) }, next.assets, resolve(options.cwd || '.'))
|
|
489
496
|
if (options.saveAs !== true && JSON.stringify(snapshot(next)) === JSON.stringify(snapshot(current))) return { ...result(current, pathsFor(state.path)), changed: false }
|
|
490
497
|
next.history = [...next.history, snapshot(current)].slice(-MAX_HISTORY)
|
|
491
|
-
return { ...await saveRevision(state, next, options.signal, options.saveAs === true), changed: true }
|
|
498
|
+
return { ...await saveRevision(state, next, options.signal, options.saveAs === true, options.preserveUndo === true), changed: true }
|
|
492
499
|
}
|
|
493
500
|
|
|
494
501
|
export async function undoDeck(options = {}) {
|