dsh-ppt 0.14.0 → 0.16.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 +2 -0
- package/docs/DATA.md +43 -0
- package/docs/USAGE.en.md +1 -1
- package/docs/USAGE.md +3 -1
- package/docs/VALIDATION.md +4 -0
- package/docs/VISUAL.md +54 -0
- package/docs/validation-0.15.0.md +25 -0
- package/docs/validation-0.16.0.md +30 -0
- package/lib/client.js +207 -24
- package/lib/coaching.d.ts +1 -0
- package/lib/coaching.js +1 -1
- package/lib/execution.d.ts +1 -0
- package/lib/execution.js +11 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +6 -1
- package/lib/tools.js +27 -0
- package/lib/types.d.ts +51 -0
- package/lib/visual-model.d.ts +13 -0
- package/lib/visual-model.js +104 -0
- package/lib/visual.d.ts +197 -0
- package/lib/visual.js +382 -0
- package/lib/workbench.d.ts +4 -0
- package/lib/workbench.js +55 -8
- package/package.json +5 -3
- package/skills/dsh-ppt/SKILL.md +4 -1
- package/skills/dsh-ppt/package.json +3 -3
- package/skills/dsh-ppt/references/data.md +67 -0
- package/skills/dsh-ppt/scripts/build-deck.mjs +3 -0
- package/skills/dsh-ppt/scripts/deck-advanced.mjs +56 -10
- package/skills/dsh-ppt/scripts/deck-core.mjs +19 -4
- package/skills/dsh-ppt/scripts/deck-data-math.mjs +76 -0
- package/skills/dsh-ppt/scripts/deck-data-view.mjs +113 -0
- package/skills/dsh-ppt/scripts/deck-data.mjs +190 -0
- package/skills/dsh-ppt/scripts/deck-visual.mjs +79 -0
package/lib/types.d.ts
CHANGED
|
@@ -94,6 +94,43 @@ export interface PptProjectArgs {
|
|
|
94
94
|
deckPath: string;
|
|
95
95
|
expectedRevision?: number;
|
|
96
96
|
}
|
|
97
|
+
export interface PptDataSource {
|
|
98
|
+
id: string;
|
|
99
|
+
name?: string;
|
|
100
|
+
format?: 'csv' | 'tsv' | 'text';
|
|
101
|
+
path?: string;
|
|
102
|
+
content?: string;
|
|
103
|
+
kind?: 'table' | 'text';
|
|
104
|
+
rows?: Array<Array<string | number>>;
|
|
105
|
+
text?: string;
|
|
106
|
+
}
|
|
107
|
+
export interface PptDataMetric {
|
|
108
|
+
id: string;
|
|
109
|
+
label?: string;
|
|
110
|
+
kind: 'source' | 'input' | 'formula';
|
|
111
|
+
source?: {
|
|
112
|
+
sourceId: string;
|
|
113
|
+
cell?: string;
|
|
114
|
+
line?: number;
|
|
115
|
+
numberIndex?: number;
|
|
116
|
+
};
|
|
117
|
+
value?: number;
|
|
118
|
+
min?: number;
|
|
119
|
+
max?: number;
|
|
120
|
+
step?: number;
|
|
121
|
+
note?: string;
|
|
122
|
+
formula?: string;
|
|
123
|
+
format?: {
|
|
124
|
+
style?: 'number' | 'percent';
|
|
125
|
+
digits?: number;
|
|
126
|
+
unit?: string;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
export interface PptDataModel {
|
|
130
|
+
schemaVersion?: 1;
|
|
131
|
+
sources: PptDataSource[];
|
|
132
|
+
metrics: PptDataMetric[];
|
|
133
|
+
}
|
|
97
134
|
export interface PptSlideSpec {
|
|
98
135
|
id?: string;
|
|
99
136
|
layout?: PptSlideLayout;
|
|
@@ -108,6 +145,12 @@ export interface PptSlideSpec {
|
|
|
108
145
|
notes?: string;
|
|
109
146
|
image?: PptImageSpec | string | null;
|
|
110
147
|
chart?: PptChartSpec | null;
|
|
148
|
+
/** Optional bounded native font sizes, in points. */
|
|
149
|
+
visual?: {
|
|
150
|
+
titleSize?: number;
|
|
151
|
+
bodySize?: number;
|
|
152
|
+
chartLabelSize?: number;
|
|
153
|
+
};
|
|
111
154
|
}
|
|
112
155
|
export interface PptConfig {
|
|
113
156
|
/** 默认输出目录;调用 ppt_create 时可用 outputDir 覆盖。相对路径按会话工作目录解析。 */
|
|
@@ -135,6 +178,8 @@ export interface PptCreateArgs {
|
|
|
135
178
|
overwrite?: boolean;
|
|
136
179
|
template?: PptTemplateId;
|
|
137
180
|
brand?: PptBrand;
|
|
181
|
+
/** Optional explicit source facts, assumptions and safe arithmetic; bind slides with {{metricId}}. */
|
|
182
|
+
dataModel?: PptDataModel;
|
|
138
183
|
}
|
|
139
184
|
export interface PptThemeInfo {
|
|
140
185
|
id: string;
|
|
@@ -186,6 +231,12 @@ export interface PptCreateResult {
|
|
|
186
231
|
}
|
|
187
232
|
/** Shared generator and optional renderer exposed to the plugin. */
|
|
188
233
|
export interface DeckEngine {
|
|
234
|
+
repairDeckVisual(options: Record<string, unknown>): Promise<PptCreateResult>;
|
|
235
|
+
readRenderReceipt(pptxPath: string, receiptPath: string): PptRenderResult;
|
|
236
|
+
previewDeckData(options: Record<string, unknown>): Record<string, any>;
|
|
237
|
+
updateDeckData(options: Record<string, unknown>): Promise<PptCreateResult>;
|
|
238
|
+
dataReport(manifest: any): string;
|
|
239
|
+
dataNotes(manifest: any, slide: any): string;
|
|
189
240
|
buildDeckAsync?(options: Record<string, unknown>): Promise<PptCreateResult>;
|
|
190
241
|
listTemplates(lang?: string): unknown[];
|
|
191
242
|
editDeck(options: Record<string, unknown>): Promise<PptCreateResult>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Native image calls use durable DSH attachments and the exact prepared route. */
|
|
2
|
+
import type { ModelRoute } from './coaching-model.js';
|
|
3
|
+
export interface VisualImage {
|
|
4
|
+
data: Uint8Array;
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
7
|
+
export interface VisualModel {
|
|
8
|
+
routes(signal?: AbortSignal): Promise<Array<ModelRoute & {
|
|
9
|
+
label: string;
|
|
10
|
+
}>>;
|
|
11
|
+
inspect(route: ModelRoute, system: string, input: string, images: VisualImage[], signal: AbortSignal): Promise<string>;
|
|
12
|
+
}
|
|
13
|
+
export declare function nativeVisualModel(llm: any, attachments: any): VisualModel;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
class VisualCallError extends Error {
|
|
2
|
+
}
|
|
3
|
+
async function abortable(work, signal) {
|
|
4
|
+
signal.throwIfAborted();
|
|
5
|
+
let stop;
|
|
6
|
+
const aborted = new Promise((_, reject) => { stop = () => reject(new Error('视觉模型调用已停止 / Visual model call stopped')); signal.addEventListener('abort', stop, { once: true }); });
|
|
7
|
+
try {
|
|
8
|
+
return await Promise.race([work, aborted]);
|
|
9
|
+
}
|
|
10
|
+
finally {
|
|
11
|
+
signal.removeEventListener('abort', stop);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function nativeVisualModel(llm, attachments) {
|
|
15
|
+
return {
|
|
16
|
+
async routes(signal) {
|
|
17
|
+
const active = AbortSignal.any([...(signal ? [signal] : []), AbortSignal.timeout(15_000)]);
|
|
18
|
+
const groups = await Promise.all(llm.listProviders().slice(0, 20).map(async (provider) => {
|
|
19
|
+
try {
|
|
20
|
+
const models = await abortable(llm.listModels(provider.id), active);
|
|
21
|
+
return models.slice(0, 100).filter(m => m.inputModalities?.includes('image') && m.inputModalities?.includes('text'))
|
|
22
|
+
.map(m => ({ provider: provider.id, model: m.id, label: (provider.name || provider.id) + ' / ' + (m.name || m.id) }));
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
active.throwIfAborted();
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
}));
|
|
29
|
+
return groups.flat();
|
|
30
|
+
},
|
|
31
|
+
async inspect(route, system, input, images, signal) {
|
|
32
|
+
if (!images.length || images.length > 2 || images.some(i => i.data.byteLength > 4 * 1024 * 1024))
|
|
33
|
+
throw new Error('每次视觉检查需 1–2 张、每张不超过 4 MiB / Image request limit');
|
|
34
|
+
if (!llm.listProviders().some((p) => p.id === route.provider))
|
|
35
|
+
throw new Error('模型服务已停用 / Model provider is unavailable');
|
|
36
|
+
const active = AbortSignal.any([signal, AbortSignal.timeout(120_000)]);
|
|
37
|
+
let stream;
|
|
38
|
+
try {
|
|
39
|
+
const info = await abortable(llm.resolveModelInfo(route.provider, route.model, active), active);
|
|
40
|
+
const prepared = await abortable(llm.prepareCall({ ...route, maxTokens: 6000,
|
|
41
|
+
...(info?.reasoning?.efforts?.some((v) => v.id === 'off') ? { reasoningEffort: 'off' } : {}) }, active), active);
|
|
42
|
+
if (!prepared.inputModalities?.includes('image') || !prepared.inputModalities?.includes('text'))
|
|
43
|
+
throw new VisualCallError('所选模型不能读取图片,请选择视觉模型 / Choose a model with image input');
|
|
44
|
+
const refs = await abortable(attachments.saveImages(images.map(i => ({ data: i.data, mediaType: 'image/png', name: i.name }))), active);
|
|
45
|
+
if (!Array.isArray(refs) || refs.length !== images.length)
|
|
46
|
+
throw new VisualCallError('图片存储未完成 / Image admission failed');
|
|
47
|
+
active.throwIfAborted();
|
|
48
|
+
stream = prepared.stream({ ...prepared.config, system, tools: [], signal: active,
|
|
49
|
+
messages: [{ role: 'user', content: [{ type: 'text', text: input }, ...refs.map(attachment => ({ type: 'image', attachment }))] }],
|
|
50
|
+
})[Symbol.asyncIterator]();
|
|
51
|
+
const blocks = new Map();
|
|
52
|
+
let complete = false;
|
|
53
|
+
for (;;) {
|
|
54
|
+
const part = await abortable(stream.next(), active);
|
|
55
|
+
if (part.done)
|
|
56
|
+
break;
|
|
57
|
+
const chunk = part.value;
|
|
58
|
+
if (chunk.type === 'tool-call-delta' || chunk.type === 'block-end' && chunk.block?.type === 'tool-call')
|
|
59
|
+
throw new VisualCallError('视觉检查不允许工具调用 / Unexpected tool call');
|
|
60
|
+
if (chunk.type === 'text-delta')
|
|
61
|
+
blocks.set(chunk.index, (blocks.get(chunk.index) || '') + String(chunk.text || ''));
|
|
62
|
+
if (chunk.type === 'block-end' && chunk.block?.type === 'text')
|
|
63
|
+
blocks.set(chunk.index, String(chunk.block.text || ''));
|
|
64
|
+
if ([...blocks.values()].reduce((n, t) => n + t.length, 0) > 30_000)
|
|
65
|
+
throw new VisualCallError('视觉结果过长 / Visual output limit');
|
|
66
|
+
if (chunk.type === 'finish') {
|
|
67
|
+
if (chunk.reason?.kind === 'max-tokens')
|
|
68
|
+
throw new VisualCallError('视觉模型达到输出上限,未采纳截断结果;请缩小检查范围或选择更快的模型 / Vision output limit reached; truncated results were not adopted. Review fewer slides or choose a faster model');
|
|
69
|
+
if (chunk.reason?.failure?.code === 'AUTH')
|
|
70
|
+
throw new VisualCallError('视觉模型认证失败,请检查 DSH 中的凭据 / Vision model authentication failed; check the DSH credential');
|
|
71
|
+
if (chunk.reason?.failure?.code === 'RATE_LIMIT')
|
|
72
|
+
throw new VisualCallError('视觉模型服务限流,未自动重试 / Vision model rate limited; no automatic retry');
|
|
73
|
+
if (chunk.reason?.kind !== 'stop')
|
|
74
|
+
throw new VisualCallError('视觉模型未完整返回结果,未自动重试;请检查模型服务 / Vision model did not complete; no automatic retry. Check the model service');
|
|
75
|
+
complete = true;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const output = [...blocks].sort(([a], [b]) => a - b).map(([, t]) => t).join('');
|
|
80
|
+
if (!complete || !output.trim())
|
|
81
|
+
throw new VisualCallError('未收到完整视觉结果 / No complete visual result');
|
|
82
|
+
return output;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
if (active.aborted)
|
|
86
|
+
throw new VisualCallError('视觉模型调用已停止 / Visual model call stopped');
|
|
87
|
+
if (error instanceof VisualCallError)
|
|
88
|
+
throw error;
|
|
89
|
+
// Provider error bodies can echo credentials or request payloads. Keep
|
|
90
|
+
// only stable failure categories in UI and persistent review records.
|
|
91
|
+
const code = error?.failure?.code || error?.code;
|
|
92
|
+
if (code === 'AUTH')
|
|
93
|
+
throw new VisualCallError('视觉模型认证失败,请检查 DSH 中的凭据 / Vision model authentication failed; check the DSH credential');
|
|
94
|
+
if (code === 'RATE_LIMIT')
|
|
95
|
+
throw new VisualCallError('视觉模型服务限流,未自动重试 / Vision model rate limited; no automatic retry');
|
|
96
|
+
throw new VisualCallError('视觉模型请求失败,请检查模型、凭据与图片输入配置;未自动重试 / Vision model request failed; check model, credential and image input settings; no automatic retry');
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
if (stream?.return)
|
|
100
|
+
void Promise.resolve(stream.return()).catch(() => { });
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
package/lib/visual.d.ts
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import type { DeckEngine } from './types.js';
|
|
2
|
+
import type { ModelRoute } from './coaching-model.js';
|
|
3
|
+
import type { VisualModel } from './visual-model.js';
|
|
4
|
+
export type VisualContext = {
|
|
5
|
+
id: string;
|
|
6
|
+
path: string;
|
|
7
|
+
manifest: any;
|
|
8
|
+
engine: DeckEngine & {
|
|
9
|
+
readDeckProject(options: any): {
|
|
10
|
+
manifest: any;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
type Action = {
|
|
15
|
+
slideId: string;
|
|
16
|
+
type: string;
|
|
17
|
+
value?: number;
|
|
18
|
+
};
|
|
19
|
+
type Finding = {
|
|
20
|
+
slideId: string;
|
|
21
|
+
kind: string;
|
|
22
|
+
region: string;
|
|
23
|
+
issue: string;
|
|
24
|
+
box: number[];
|
|
25
|
+
action?: Action;
|
|
26
|
+
};
|
|
27
|
+
export declare class PptVisual {
|
|
28
|
+
readonly directory: string;
|
|
29
|
+
private model?;
|
|
30
|
+
private active;
|
|
31
|
+
constructor(directory: string, model?: VisualModel);
|
|
32
|
+
setModel(model?: VisualModel): void;
|
|
33
|
+
dispose(): void;
|
|
34
|
+
options(signal?: AbortSignal): Promise<{
|
|
35
|
+
available: boolean;
|
|
36
|
+
routes: (ModelRoute & {
|
|
37
|
+
label: string;
|
|
38
|
+
})[];
|
|
39
|
+
}>;
|
|
40
|
+
private path;
|
|
41
|
+
private read;
|
|
42
|
+
private locked;
|
|
43
|
+
private write;
|
|
44
|
+
private bound;
|
|
45
|
+
private unchanged;
|
|
46
|
+
private roundPath;
|
|
47
|
+
private state;
|
|
48
|
+
private render;
|
|
49
|
+
list(context: VisualContext): {
|
|
50
|
+
id: string;
|
|
51
|
+
status: "ready" | "busy" | "paused" | "complete";
|
|
52
|
+
revision: number;
|
|
53
|
+
createdAt: string;
|
|
54
|
+
}[];
|
|
55
|
+
get(context: VisualContext, id: unknown): {
|
|
56
|
+
stale: boolean;
|
|
57
|
+
canAdopt: boolean;
|
|
58
|
+
rounds: {
|
|
59
|
+
deckId: string;
|
|
60
|
+
revision: number;
|
|
61
|
+
ids: string[];
|
|
62
|
+
cursor: number;
|
|
63
|
+
findings: Finding[];
|
|
64
|
+
applied: Action[];
|
|
65
|
+
missingFonts: string[];
|
|
66
|
+
rendered: boolean;
|
|
67
|
+
pptxHash: string;
|
|
68
|
+
}[];
|
|
69
|
+
version: 1;
|
|
70
|
+
id: string;
|
|
71
|
+
projectId: string;
|
|
72
|
+
deckId: string;
|
|
73
|
+
revision: number;
|
|
74
|
+
title: string;
|
|
75
|
+
language: "zh" | "en";
|
|
76
|
+
route: ModelRoute;
|
|
77
|
+
repairs: number;
|
|
78
|
+
maxCalls: number;
|
|
79
|
+
usedCalls: number;
|
|
80
|
+
status: "ready" | "busy" | "paused" | "complete";
|
|
81
|
+
phase: "render" | "inspect" | "repair" | "done";
|
|
82
|
+
createdAt: string;
|
|
83
|
+
updatedAt: string;
|
|
84
|
+
reason?: string;
|
|
85
|
+
error?: string;
|
|
86
|
+
};
|
|
87
|
+
create(context: VisualContext, body: Record<string, unknown>, signal?: AbortSignal): Promise<{
|
|
88
|
+
stale: boolean;
|
|
89
|
+
canAdopt: boolean;
|
|
90
|
+
rounds: {
|
|
91
|
+
deckId: string;
|
|
92
|
+
revision: number;
|
|
93
|
+
ids: string[];
|
|
94
|
+
cursor: number;
|
|
95
|
+
findings: Finding[];
|
|
96
|
+
applied: Action[];
|
|
97
|
+
missingFonts: string[];
|
|
98
|
+
rendered: boolean;
|
|
99
|
+
pptxHash: string;
|
|
100
|
+
}[];
|
|
101
|
+
version: 1;
|
|
102
|
+
id: string;
|
|
103
|
+
projectId: string;
|
|
104
|
+
deckId: string;
|
|
105
|
+
revision: number;
|
|
106
|
+
title: string;
|
|
107
|
+
language: "zh" | "en";
|
|
108
|
+
route: ModelRoute;
|
|
109
|
+
repairs: number;
|
|
110
|
+
maxCalls: number;
|
|
111
|
+
usedCalls: number;
|
|
112
|
+
status: "ready" | "busy" | "paused" | "complete";
|
|
113
|
+
phase: "render" | "inspect" | "repair" | "done";
|
|
114
|
+
createdAt: string;
|
|
115
|
+
updatedAt: string;
|
|
116
|
+
reason?: string;
|
|
117
|
+
error?: string;
|
|
118
|
+
}>;
|
|
119
|
+
private findings;
|
|
120
|
+
step(context: VisualContext, id: unknown, body: Record<string, unknown>, signal?: AbortSignal): Promise<{
|
|
121
|
+
stale: boolean;
|
|
122
|
+
canAdopt: boolean;
|
|
123
|
+
rounds: {
|
|
124
|
+
deckId: string;
|
|
125
|
+
revision: number;
|
|
126
|
+
ids: string[];
|
|
127
|
+
cursor: number;
|
|
128
|
+
findings: Finding[];
|
|
129
|
+
applied: Action[];
|
|
130
|
+
missingFonts: string[];
|
|
131
|
+
rendered: boolean;
|
|
132
|
+
pptxHash: string;
|
|
133
|
+
}[];
|
|
134
|
+
version: 1;
|
|
135
|
+
id: string;
|
|
136
|
+
projectId: string;
|
|
137
|
+
deckId: string;
|
|
138
|
+
revision: number;
|
|
139
|
+
title: string;
|
|
140
|
+
language: "zh" | "en";
|
|
141
|
+
route: ModelRoute;
|
|
142
|
+
repairs: number;
|
|
143
|
+
maxCalls: number;
|
|
144
|
+
usedCalls: number;
|
|
145
|
+
status: "ready" | "busy" | "paused" | "complete";
|
|
146
|
+
phase: "render" | "inspect" | "repair" | "done";
|
|
147
|
+
createdAt: string;
|
|
148
|
+
updatedAt: string;
|
|
149
|
+
reason?: string;
|
|
150
|
+
error?: string;
|
|
151
|
+
}>;
|
|
152
|
+
stop(context: VisualContext, id: unknown): {
|
|
153
|
+
stale: boolean;
|
|
154
|
+
canAdopt: boolean;
|
|
155
|
+
rounds: {
|
|
156
|
+
deckId: string;
|
|
157
|
+
revision: number;
|
|
158
|
+
ids: string[];
|
|
159
|
+
cursor: number;
|
|
160
|
+
findings: Finding[];
|
|
161
|
+
applied: Action[];
|
|
162
|
+
missingFonts: string[];
|
|
163
|
+
rendered: boolean;
|
|
164
|
+
pptxHash: string;
|
|
165
|
+
}[];
|
|
166
|
+
version: 1;
|
|
167
|
+
id: string;
|
|
168
|
+
projectId: string;
|
|
169
|
+
deckId: string;
|
|
170
|
+
revision: number;
|
|
171
|
+
title: string;
|
|
172
|
+
language: "zh" | "en";
|
|
173
|
+
route: ModelRoute;
|
|
174
|
+
repairs: number;
|
|
175
|
+
maxCalls: number;
|
|
176
|
+
usedCalls: number;
|
|
177
|
+
status: "ready" | "busy" | "paused" | "complete";
|
|
178
|
+
phase: "render" | "inspect" | "repair" | "done";
|
|
179
|
+
createdAt: string;
|
|
180
|
+
updatedAt: string;
|
|
181
|
+
reason?: string;
|
|
182
|
+
error?: string;
|
|
183
|
+
};
|
|
184
|
+
page(context: VisualContext, id: unknown, roundIndex: unknown, slideId: unknown): {
|
|
185
|
+
ok: boolean;
|
|
186
|
+
data: string;
|
|
187
|
+
};
|
|
188
|
+
adoption(context: VisualContext, id: unknown): {
|
|
189
|
+
path: string;
|
|
190
|
+
render: import("./types.js").PptRenderResult;
|
|
191
|
+
};
|
|
192
|
+
remove(context: VisualContext, id: unknown): {
|
|
193
|
+
removed: boolean;
|
|
194
|
+
};
|
|
195
|
+
markdown(context: VisualContext, id: unknown): string;
|
|
196
|
+
}
|
|
197
|
+
export {};
|