dsh-artifact-studio 0.3.1 → 0.7.1
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/README.md +6 -4
- package/THIRD_PARTY_NOTICES.md +296 -0
- package/assets/canvas.engine.js +6601 -0
- package/assets/canvaskit.wasm +0 -0
- package/assets/fonts/Inter-Bold.ttf +0 -0
- package/assets/fonts/Inter-ExtraBold.ttf +0 -0
- package/assets/fonts/Inter-Medium.ttf +0 -0
- package/assets/fonts/Inter-Regular.ttf +0 -0
- package/assets/fonts/Inter-SemiBold.ttf +0 -0
- package/assets/fonts/NotoNaskhArabic-Regular.ttf +0 -0
- package/assets/fonts/Roboto-Bold.woff2 +0 -0
- package/assets/fonts/Roboto-Medium.woff2 +0 -0
- package/assets/fonts/Roboto-Regular.woff2 +0 -0
- package/assets/icons.json +42204 -0
- package/client.canvas.js +11 -0
- package/client.js +154 -17
- package/dist/contract.js +22 -2
- package/dist/host/index.js +2 -0
- package/dist/host/lib/assets.js +88 -0
- package/dist/host/lib/design-render.js +254 -0
- package/dist/host/lib/editor-leases.js +63 -0
- package/dist/host/lib/export.js +21 -3
- package/dist/host/lib/fsutil.js +4 -1
- package/dist/host/lib/rpc.js +14 -0
- package/dist/host/lib/service.js +291 -11
- package/dist/host/lib/skill.js +32 -3
- package/dist/host/lib/store.js +57 -0
- package/dist/host/lib/tools.js +63 -18
- package/dist/host/worker/design-worker.js +215 -0
- package/dist/host/worker/protocol.js +1 -0
- package/dist/icon-set.js +81 -0
- package/package.json +12 -3
package/dist/host/lib/tools.js
CHANGED
|
@@ -8,10 +8,11 @@ const SCOPE_PARAM = {
|
|
|
8
8
|
description: 'workspace (default) stores it under the Harness home for this workspace. library stores it in the user profile, shared by every project; use it only when the user asks for something reusable across projects.',
|
|
9
9
|
};
|
|
10
10
|
const PAGE_GUIDE = [
|
|
11
|
-
'Load the artifact-design skill first if
|
|
12
|
-
'A page is one self-contained HTML document in a sandbox with no network or browser storage: inline all CSS and JavaScript, draw charts with inline SVG or canvas, and use data: URIs for images.
|
|
13
|
-
'Style pages with the injected variables: --artifact-color-primary, -accent, -surface, -text, -muted; --artifact-font-family, -display, -mono;
|
|
14
|
-
'A doc is Markdown: headings, lists, task lists,
|
|
11
|
+
'Load the artifact-design skill first if not loaded yet. Precedence: the user\'s request, then the design system, then your own choices.',
|
|
12
|
+
'A page is one self-contained HTML document in a sandbox with no network or browser storage: inline all CSS and JavaScript, draw charts with inline SVG or canvas, and use data: URIs for images. Keep the layout fluid for a 380 to 700 px panel.',
|
|
13
|
+
'Style pages with the injected variables: --artifact-color-primary, -accent, -surface, -text, -muted; --artifact-font-family, -display, -mono; and the size, space, and radius scales in the skill.',
|
|
14
|
+
'A doc is Markdown: headings, lists, task lists, tables, quotes, and fenced code.',
|
|
15
|
+
'Each save is a version the user sees. Check before saving and batch fixes into one update.',
|
|
15
16
|
].join('\n');
|
|
16
17
|
/**
|
|
17
18
|
* Warnings for the version an update wrote. Full content is checked directly.
|
|
@@ -114,7 +115,7 @@ function writeText(value, verb) {
|
|
|
114
115
|
const warnings = record(value).warnings;
|
|
115
116
|
const list = Array.isArray(warnings) ? warnings.map(String) : [];
|
|
116
117
|
const head = `${line(value, verb)} The user sees a card with an Open action.`;
|
|
117
|
-
return list.length === 0 ? head : `${head}\nWarnings:\n${list.map((item) => `- ${item}`).join('\n')}`;
|
|
118
|
+
return list.length === 0 ? head : `${head}\nWarnings, fix all of them in one update:\n${list.map((item) => `- ${item}`).join('\n')}`;
|
|
118
119
|
}
|
|
119
120
|
const SUMMARY_SCHEMA = {
|
|
120
121
|
type: 'object',
|
|
@@ -123,7 +124,7 @@ const SUMMARY_SCHEMA = {
|
|
|
123
124
|
properties: {
|
|
124
125
|
id: { type: 'string' },
|
|
125
126
|
scope: { type: 'string', enum: ['workspace', 'library'] },
|
|
126
|
-
type: { type: 'string', enum: ['page', 'doc'] },
|
|
127
|
+
type: { type: 'string', enum: ['page', 'doc', 'design'] },
|
|
127
128
|
title: { type: 'string' },
|
|
128
129
|
version: { type: 'integer' },
|
|
129
130
|
updatedAt: { type: 'string' },
|
|
@@ -166,9 +167,9 @@ export function createTools(host) {
|
|
|
166
167
|
additionalProperties: false,
|
|
167
168
|
required: ['type', 'title', 'content'],
|
|
168
169
|
properties: {
|
|
169
|
-
type: { type: 'string', enum: ['page', 'doc'], description: 'page for HTML, doc for Markdown.' },
|
|
170
|
+
type: { type: 'string', enum: ['page', 'doc', 'design'], description: 'page for HTML, doc for Markdown, design for OpenPencil Design JSX. For a design, load the artifact-design skill first: no imports, no HTML.' },
|
|
170
171
|
title: { type: 'string', description: 'Short title, 1 to 120 characters.' },
|
|
171
|
-
content: { type: 'string', description: 'The full HTML document
|
|
172
|
+
content: { type: 'string', description: 'The full HTML document, Markdown text, or Design JSX source, up to 2 MiB.' },
|
|
172
173
|
scope: SCOPE_PARAM,
|
|
173
174
|
},
|
|
174
175
|
},
|
|
@@ -188,7 +189,10 @@ export function createTools(host) {
|
|
|
188
189
|
content,
|
|
189
190
|
source: { origin: 'agent', action: 'create', ...(exec.agent === undefined ? {} : { sessionId: exec.agent.id }) },
|
|
190
191
|
});
|
|
191
|
-
|
|
192
|
+
const warnings = type === 'design'
|
|
193
|
+
? (await service.read(target, manifest.id)).designInfo?.warnings ?? []
|
|
194
|
+
: warningsFor(type, content);
|
|
195
|
+
return { ...summary(manifest, target), warnings };
|
|
192
196
|
},
|
|
193
197
|
};
|
|
194
198
|
const read = {
|
|
@@ -208,15 +212,28 @@ export function createTools(host) {
|
|
|
208
212
|
type: 'object',
|
|
209
213
|
additionalProperties: false,
|
|
210
214
|
required: ['artifact', 'readVersion', 'content'],
|
|
211
|
-
properties: {
|
|
215
|
+
properties: {
|
|
216
|
+
artifact: SUMMARY_SCHEMA,
|
|
217
|
+
readVersion: { type: 'integer' },
|
|
218
|
+
content: { type: 'string' },
|
|
219
|
+
designInfo: {
|
|
220
|
+
type: 'object',
|
|
221
|
+
description: 'The compiled summary of a design: pages, nodes, type counts, fonts, and warnings.',
|
|
222
|
+
},
|
|
223
|
+
},
|
|
212
224
|
},
|
|
213
225
|
render: (_args, value) => {
|
|
214
226
|
const fields = record(value);
|
|
215
227
|
const artifact = record(fields.artifact ?? null);
|
|
228
|
+
const info = record(fields.designInfo ?? null);
|
|
229
|
+
const summaryLine = info.nodes === undefined
|
|
230
|
+
? ''
|
|
231
|
+
: `\n\nDesign: ${String(info.nodes)} nodes, ${String(info.pages)} page(s), fonts ${Array.isArray(info.fonts) && info.fonts.length > 0 ? info.fonts.map(String).join(', ') : 'none'}.`
|
|
232
|
+
+ (Array.isArray(info.warnings) && info.warnings.length > 0 ? `\nWarnings:\n${info.warnings.map((item) => `- ${String(item)}`).join('\n')}` : '');
|
|
216
233
|
return [
|
|
217
234
|
{
|
|
218
235
|
type: 'text',
|
|
219
|
-
text: `${line(artifact, 'Artifact')} Showing version ${String(fields.readVersion)}
|
|
236
|
+
text: `${line(artifact, 'Artifact')} Showing version ${String(fields.readVersion)}.${summaryLine}\n\n${String(fields.content)}`,
|
|
220
237
|
},
|
|
221
238
|
];
|
|
222
239
|
},
|
|
@@ -226,7 +243,15 @@ export function createTools(host) {
|
|
|
226
243
|
const id = requiredString(fields, 'id');
|
|
227
244
|
const target = await targetFor(host, exec, id.startsWith('art_lib_') ? 'library' : undefined);
|
|
228
245
|
const result = await service.read(target, id, optionalInteger(fields, 'version'));
|
|
229
|
-
|
|
246
|
+
const info = result.designInfo;
|
|
247
|
+
return {
|
|
248
|
+
artifact: summary(result.manifest, target),
|
|
249
|
+
readVersion: result.version,
|
|
250
|
+
content: result.content,
|
|
251
|
+
...(info === undefined
|
|
252
|
+
? {}
|
|
253
|
+
: { designInfo: { pages: info.pages, nodes: info.nodes, types: info.types, fonts: info.fonts, warnings: info.warnings } }),
|
|
254
|
+
};
|
|
230
255
|
},
|
|
231
256
|
};
|
|
232
257
|
const update = {
|
|
@@ -235,6 +260,8 @@ export function createTools(host) {
|
|
|
235
260
|
'Save a new version of an artifact. For a few local changes send edits; send complete content only when you rewrite most of it. Each edit oldText must occur exactly once.',
|
|
236
261
|
'The update is refused when baseVersion is not the current version, for example after the user edited it; read it again and reapply your change. Never discard the user\'s edits.',
|
|
237
262
|
'A layout or styling change follows the artifact-design skill and the same precedence: the user\'s request, then the design system, then your own choices.',
|
|
263
|
+
'For a design, send the complete Design JSX source as content and read it first if you did not write it; edits are applied and validated too, but a design rewrite is usually smaller as one content value.',
|
|
264
|
+
'Each call writes a version the user sees. Put every fix for one request, including all returned warnings, into one update; never send one update per finding.',
|
|
238
265
|
].join('\n'),
|
|
239
266
|
parameters: {
|
|
240
267
|
type: 'object',
|
|
@@ -243,7 +270,7 @@ export function createTools(host) {
|
|
|
243
270
|
properties: {
|
|
244
271
|
id: { type: 'string' },
|
|
245
272
|
baseVersion: { type: 'integer', description: 'The version your change is based on.' },
|
|
246
|
-
content: { type: 'string', description: 'Complete replacement content. Use this or edits.' },
|
|
273
|
+
content: { type: 'string', description: 'Complete replacement content. Use this or edits. For a design, send the complete Design JSX source.' },
|
|
247
274
|
edits: {
|
|
248
275
|
type: 'array',
|
|
249
276
|
description: 'Replace-once edits applied in order. Each oldText must occur exactly once.',
|
|
@@ -279,7 +306,25 @@ export function createTools(host) {
|
|
|
279
306
|
title,
|
|
280
307
|
source: { origin: 'agent', action: 'update', ...(exec.agent === undefined ? {} : { sessionId: exec.agent.id }) },
|
|
281
308
|
});
|
|
282
|
-
|
|
309
|
+
const warnings = manifest.type === 'design'
|
|
310
|
+
? (await service.read(target, id, manifest.version)).designInfo?.warnings ?? []
|
|
311
|
+
: await writtenWarnings(manifest.type, content, edits === undefined ? undefined : () => service.read(target, id, manifest.version));
|
|
312
|
+
return { ...summary(manifest, target), warnings };
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
const move = {
|
|
316
|
+
name: 'artifact_move',
|
|
317
|
+
description: 'Move a saved workspace artifact to another registered workspace. Ask the user first. Close all editors for the artifact before moving it.',
|
|
318
|
+
parameters: { type: 'object', additionalProperties: false, required: ['id', 'destinationWorkspaceId', 'baseVersion'], properties: {
|
|
319
|
+
id: { type: 'string' }, destinationWorkspaceId: { type: 'string' }, baseVersion: { type: 'integer' },
|
|
320
|
+
} },
|
|
321
|
+
output: { schema: SUMMARY_SCHEMA, render: (_args, value) => [{ type: 'text', text: 'Moved artifact: ' + String(record(value).id) + ' to workspace ' + String(record(value).workspaceId) }] },
|
|
322
|
+
async execute(args, exec) {
|
|
323
|
+
const fields = fieldsOf(args);
|
|
324
|
+
const target = await targetFor(host, exec, undefined);
|
|
325
|
+
const destinationWorkspaceId = requiredString(fields, 'destinationWorkspaceId');
|
|
326
|
+
const manifest = await service.move(target, requiredString(fields, 'id'), destinationWorkspaceId, requiredInteger(fields, 'baseVersion'));
|
|
327
|
+
return summary(manifest, { scope: 'workspace', workspaceId: destinationWorkspaceId });
|
|
283
328
|
},
|
|
284
329
|
};
|
|
285
330
|
const list = {
|
|
@@ -290,7 +335,7 @@ export function createTools(host) {
|
|
|
290
335
|
additionalProperties: false,
|
|
291
336
|
properties: {
|
|
292
337
|
scope: { type: 'string', enum: ['workspace', 'library'], description: 'Defaults to workspace.' },
|
|
293
|
-
type: { type: 'string', enum: ['page', 'doc'] },
|
|
338
|
+
type: { type: 'string', enum: ['page', 'doc', 'design'] },
|
|
294
339
|
query: { type: 'string', description: 'Title substring, case-insensitive.' },
|
|
295
340
|
offset: { type: 'integer' },
|
|
296
341
|
},
|
|
@@ -347,12 +392,12 @@ export function createTools(host) {
|
|
|
347
392
|
};
|
|
348
393
|
const exportTool = {
|
|
349
394
|
name: 'artifact_export',
|
|
350
|
-
description: 'Write an artifact to a standalone file and return its path. A page exports as html; a doc exports as md, docx, or printable html.',
|
|
395
|
+
description: 'Write an artifact to a standalone file and return its path. A page exports as html; a doc exports as md, docx, or printable html; a design exports as png, svg, or .fig.',
|
|
351
396
|
parameters: {
|
|
352
397
|
type: 'object',
|
|
353
398
|
additionalProperties: false,
|
|
354
399
|
required: ['id', 'format'],
|
|
355
|
-
properties: { id: { type: 'string' }, format: { type: 'string', enum: ['html', 'md', 'docx'] },
|
|
400
|
+
properties: { id: { type: 'string' }, format: { type: 'string', enum: ['html', 'md', 'docx', 'png', 'svg', 'fig'] },
|
|
356
401
|
version: { type: 'integer', minimum: 1, description: 'Saved version to export. Omit for the current version.' } },
|
|
357
402
|
},
|
|
358
403
|
output: {
|
|
@@ -415,5 +460,5 @@ export function createTools(host) {
|
|
|
415
460
|
return { scope: saved.scope, tokens: JSON.stringify(saved.tokens, null, 2) };
|
|
416
461
|
},
|
|
417
462
|
};
|
|
418
|
-
return [create, read, update, list, remove, exportTool, designRead, designUpdate];
|
|
463
|
+
return [create, read, update, move, list, remove, exportTool, designRead, designUpdate];
|
|
419
464
|
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import { SceneGraph } from '@open-pencil/scene-graph';
|
|
4
|
+
import { designJSXRenderer } from '@open-pencil/core/design-jsx';
|
|
5
|
+
import { fontManager } from '@open-pencil/core/text';
|
|
6
|
+
import { computeContentBounds, headlessRenderNodes } from '@open-pencil/core/io/formats/raster';
|
|
7
|
+
import { renderNodesToSVG } from '@open-pencil/core/io/formats/svg';
|
|
8
|
+
import { exportFigFile } from '@open-pencil/core/io/formats/fig';
|
|
9
|
+
import { bundledIconProvider } from '../../icon-set.js';
|
|
10
|
+
/** Fonts that ship with the package; any other family is substituted. */
|
|
11
|
+
const BUNDLED_FONTS = new Set(['Inter', 'Noto Naskh Arabic', 'Roboto']);
|
|
12
|
+
/** The Roboto faces the package ships, by style. */
|
|
13
|
+
const EXTRA_FONTS = [
|
|
14
|
+
['Regular', 'Roboto-Regular.woff2'],
|
|
15
|
+
['Medium', 'Roboto-Medium.woff2'],
|
|
16
|
+
['Bold', 'Roboto-Bold.woff2'],
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* Load the extra bundled faces into the font manager before anything compiles.
|
|
20
|
+
* The engine's own manifest only knows Inter and Noto, so a family is added here.
|
|
21
|
+
*/
|
|
22
|
+
async function loadExtraFonts() {
|
|
23
|
+
for (const [style, file] of EXTRA_FONTS) {
|
|
24
|
+
const bytes = await fs.readFile(new URL('../../../assets/fonts/' + file, import.meta.url));
|
|
25
|
+
const copy = new Uint8Array(bytes.byteLength);
|
|
26
|
+
copy.set(bytes);
|
|
27
|
+
fontManager.markLoaded('Roboto', style, copy.buffer);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** The bundled Material Design Icons set, read on the first icon. */
|
|
31
|
+
const { renderJSX } = designJSXRenderer(bundledIconProvider(async () => JSON.parse(await fs.readFile(new URL('../../../assets/icons.json', import.meta.url), 'utf8'))));
|
|
32
|
+
/**
|
|
33
|
+
* The message of a thrown value.
|
|
34
|
+
* @param error the value.
|
|
35
|
+
* @returns its message.
|
|
36
|
+
*/
|
|
37
|
+
function messageOf(error) {
|
|
38
|
+
return error instanceof Error ? error.message : String(error);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Compile a source into a graph whose first page holds the top-level elements.
|
|
42
|
+
* @param source the Design JSX source.
|
|
43
|
+
* @returns the graph and page.
|
|
44
|
+
*/
|
|
45
|
+
async function compile(source) {
|
|
46
|
+
const graph = new SceneGraph();
|
|
47
|
+
await renderJSX(graph, source);
|
|
48
|
+
const page = graph.getPages()[0];
|
|
49
|
+
if (page === undefined)
|
|
50
|
+
throw new Error('The design has no page.');
|
|
51
|
+
return { graph, page };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Every node below a page, depth first.
|
|
55
|
+
* @param graph the graph.
|
|
56
|
+
* @param page the page node.
|
|
57
|
+
* @returns the nodes.
|
|
58
|
+
*/
|
|
59
|
+
function descendants(graph, page) {
|
|
60
|
+
const out = [];
|
|
61
|
+
const visit = (id) => {
|
|
62
|
+
const node = graph.getNode(id);
|
|
63
|
+
if (node === undefined)
|
|
64
|
+
return;
|
|
65
|
+
out.push(node);
|
|
66
|
+
for (const child of node.childIds)
|
|
67
|
+
visit(child);
|
|
68
|
+
};
|
|
69
|
+
for (const id of page.childIds)
|
|
70
|
+
visit(id);
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Count the design's nodes, record its types and fonts, and warn about
|
|
75
|
+
* families the engine cannot load.
|
|
76
|
+
* @param graph the graph.
|
|
77
|
+
* @param page the page node.
|
|
78
|
+
* @returns the summary.
|
|
79
|
+
*/
|
|
80
|
+
function summarize(graph, page) {
|
|
81
|
+
const nodes = descendants(graph, page);
|
|
82
|
+
const types = {};
|
|
83
|
+
const fonts = new Set();
|
|
84
|
+
for (const node of nodes) {
|
|
85
|
+
const type = String(node.type);
|
|
86
|
+
types[type] = (types[type] ?? 0) + 1;
|
|
87
|
+
if (typeof node.fontFamily === 'string' && node.fontFamily.trim() !== '')
|
|
88
|
+
fonts.add(node.fontFamily.trim());
|
|
89
|
+
}
|
|
90
|
+
const sorted = [...fonts].sort();
|
|
91
|
+
const warnings = sorted
|
|
92
|
+
.filter((family) => !BUNDLED_FONTS.has(family))
|
|
93
|
+
.map((family) => `Font "${family}" is not bundled. The preview substitutes a default face.`);
|
|
94
|
+
return { pages: graph.getPages().length, nodes: nodes.length, types, fonts: sorted, warnings };
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Read a PNG's pixel size from its IHDR chunk.
|
|
98
|
+
* @param bytes the PNG file.
|
|
99
|
+
* @returns the size.
|
|
100
|
+
*/
|
|
101
|
+
function pngSize(bytes) {
|
|
102
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
103
|
+
return { width: view.getUint32(16), height: view.getUint32(20) };
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Rasterize the page, scaled down when it is wider or taller than the cap.
|
|
107
|
+
* @param compiled the graph.
|
|
108
|
+
* @param maxSide the longest side, or zero for the design's own size.
|
|
109
|
+
* @returns the PNG bytes, or null for an empty design.
|
|
110
|
+
*/
|
|
111
|
+
async function renderPng(compiled, maxSide) {
|
|
112
|
+
const bounds = computeContentBounds(compiled.graph, compiled.page.childIds);
|
|
113
|
+
if (bounds === null)
|
|
114
|
+
return null;
|
|
115
|
+
const width = bounds.maxX - bounds.minX;
|
|
116
|
+
const height = bounds.maxY - bounds.minY;
|
|
117
|
+
const longest = Math.max(width, height);
|
|
118
|
+
const scale = maxSide > 0 && longest > maxSide ? maxSide / longest : 1;
|
|
119
|
+
return headlessRenderNodes(compiled.graph, compiled.page.id, compiled.page.childIds, {
|
|
120
|
+
scale,
|
|
121
|
+
format: 'PNG',
|
|
122
|
+
trimTransparent: true,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Answer one request.
|
|
127
|
+
* @param source the Design JSX source.
|
|
128
|
+
* @param request the request.
|
|
129
|
+
* @returns the response.
|
|
130
|
+
*/
|
|
131
|
+
async function handle(source, request) {
|
|
132
|
+
let compiled;
|
|
133
|
+
try {
|
|
134
|
+
compiled = await compile(source);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
const message = messageOf(error);
|
|
138
|
+
const missing = /^Icon "([^"]+)" not found$/.exec(message);
|
|
139
|
+
if (missing !== null) {
|
|
140
|
+
return { ok: false, code: 'artifact/design-icon-not-found', message: 'The bundled mdi set has no "' + (missing[1] ?? '') + '". Use a name from the mdi set.' };
|
|
141
|
+
}
|
|
142
|
+
if (/^Icon set "[^"]+" is not bundled\./.test(message)) {
|
|
143
|
+
return { ok: false, code: 'artifact/design-icon-not-found', message };
|
|
144
|
+
}
|
|
145
|
+
return { ok: false, code: 'artifact/design-invalid', message };
|
|
146
|
+
}
|
|
147
|
+
const info = summarize(compiled.graph, compiled.page);
|
|
148
|
+
if (info.nodes === 0) {
|
|
149
|
+
return {
|
|
150
|
+
ok: false,
|
|
151
|
+
code: 'artifact/design-invalid',
|
|
152
|
+
message: 'The design has no top-level elements. Wrap the layout in a <Frame>.',
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
if (request.action === 'inspect')
|
|
156
|
+
return { ok: true, info };
|
|
157
|
+
try {
|
|
158
|
+
if (request.action === 'preview') {
|
|
159
|
+
const png = await renderPng(compiled, request.maxSide ?? 1600);
|
|
160
|
+
if (png === null)
|
|
161
|
+
return { ok: false, code: 'artifact/design-render-failed', message: 'The design produced no image.' };
|
|
162
|
+
const size = pngSize(png);
|
|
163
|
+
return { ok: true, info, mediaType: 'image/png', data: Buffer.from(png).toString('base64'), width: size.width, height: size.height };
|
|
164
|
+
}
|
|
165
|
+
if (request.format === 'fig') {
|
|
166
|
+
const bytes = await exportFigFile(compiled.graph);
|
|
167
|
+
return { ok: true, info, mediaType: 'application/octet-stream', data: Buffer.from(bytes).toString('base64') };
|
|
168
|
+
}
|
|
169
|
+
if (request.format === 'svg') {
|
|
170
|
+
const svg = renderNodesToSVG(compiled.graph, compiled.page.id, compiled.page.childIds, { xmlDeclaration: true });
|
|
171
|
+
if (svg === null)
|
|
172
|
+
return { ok: false, code: 'artifact/design-render-failed', message: 'The design produced no SVG.' };
|
|
173
|
+
return { ok: true, info, mediaType: 'image/svg+xml', data: Buffer.from(svg, 'utf8').toString('base64') };
|
|
174
|
+
}
|
|
175
|
+
const png = await renderPng(compiled, 0);
|
|
176
|
+
if (png === null)
|
|
177
|
+
return { ok: false, code: 'artifact/design-render-failed', message: 'The design produced no image.' };
|
|
178
|
+
const size = pngSize(png);
|
|
179
|
+
return { ok: true, info, mediaType: 'image/png', data: Buffer.from(png).toString('base64'), width: size.width, height: size.height };
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
return { ok: false, code: 'artifact/design-render-failed', message: messageOf(error) };
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Read the one JSON request from stdin.
|
|
187
|
+
* @returns the request.
|
|
188
|
+
*/
|
|
189
|
+
async function readRequest() {
|
|
190
|
+
const chunks = [];
|
|
191
|
+
for await (const chunk of process.stdin)
|
|
192
|
+
chunks.push(Buffer.from(chunk));
|
|
193
|
+
const parsed = JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
194
|
+
if (parsed === null || typeof parsed !== 'object')
|
|
195
|
+
throw new Error('The design request is not an object.');
|
|
196
|
+
const fields = { ...parsed };
|
|
197
|
+
if (typeof fields.nonce !== 'string' || fields.nonce === '')
|
|
198
|
+
throw new Error('The design request has no nonce.');
|
|
199
|
+
if (typeof fields.source !== 'string')
|
|
200
|
+
throw new Error('The design request has no source.');
|
|
201
|
+
if (fields.action !== 'inspect' && fields.action !== 'preview' && fields.action !== 'export') {
|
|
202
|
+
throw new Error('The design request has an unknown action.');
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
nonce: fields.nonce,
|
|
206
|
+
action: fields.action,
|
|
207
|
+
source: fields.source,
|
|
208
|
+
...(typeof fields.maxSide === 'number' ? { maxSide: fields.maxSide } : {}),
|
|
209
|
+
...(fields.format === 'png' || fields.format === 'svg' || fields.format === 'fig' ? { format: fields.format } : {}),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
await loadExtraFonts();
|
|
213
|
+
const request = await readRequest();
|
|
214
|
+
const response = await handle(request.source, request);
|
|
215
|
+
process.stdout.write(request.nonce + JSON.stringify(response) + '\n', () => process.exit(0));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/icon-set.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { createIconifyProvider } from '@open-pencil/core/icons';
|
|
2
|
+
/**
|
|
3
|
+
* Tell a bundled icon file from an unknown value.
|
|
4
|
+
* @param value the parsed JSON.
|
|
5
|
+
* @returns whether it has the shape the provider needs.
|
|
6
|
+
*/
|
|
7
|
+
function isIconSet(value) {
|
|
8
|
+
if (value === null || typeof value !== 'object')
|
|
9
|
+
return false;
|
|
10
|
+
const fields = { ...value };
|
|
11
|
+
if (typeof fields['prefix'] !== 'string' || fields['prefix'] === '')
|
|
12
|
+
return false;
|
|
13
|
+
if (fields['icons'] === null || typeof fields['icons'] !== 'object')
|
|
14
|
+
return false;
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Tell one icon body from an unknown value.
|
|
19
|
+
* @param value the entry.
|
|
20
|
+
* @returns whether it has a body.
|
|
21
|
+
*/
|
|
22
|
+
function isBody(value) {
|
|
23
|
+
if (value === null || typeof value !== 'object')
|
|
24
|
+
return false;
|
|
25
|
+
return typeof value['body'] === 'string';
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* An icon provider over one bundled Iconify set. The file is loaded on the first
|
|
29
|
+
* icon, so a design without icons never reads it. Unknown sets and names fail
|
|
30
|
+
* with a message rather than falling back to the network.
|
|
31
|
+
* @param load reads and parses the bundled JSON.
|
|
32
|
+
* @returns the provider.
|
|
33
|
+
*/
|
|
34
|
+
export function bundledIconProvider(load) {
|
|
35
|
+
let set = null;
|
|
36
|
+
const file = () => {
|
|
37
|
+
set ??= load().then((value) => {
|
|
38
|
+
if (!isIconSet(value))
|
|
39
|
+
throw new Error('The bundled icon set is malformed.');
|
|
40
|
+
return value;
|
|
41
|
+
});
|
|
42
|
+
set.catch(() => {
|
|
43
|
+
set = null;
|
|
44
|
+
});
|
|
45
|
+
return set;
|
|
46
|
+
};
|
|
47
|
+
const name = async () => (await file()).prefix;
|
|
48
|
+
return createIconifyProvider({
|
|
49
|
+
async fetchCollection(prefix, iconNames) {
|
|
50
|
+
const data = await file();
|
|
51
|
+
if (prefix !== data.prefix)
|
|
52
|
+
throw new Error('Icon set "' + prefix + '" is not bundled. Use ' + data.prefix + ':<name>.');
|
|
53
|
+
const icons = {};
|
|
54
|
+
for (const iconName of iconNames) {
|
|
55
|
+
const entry = data.icons[iconName];
|
|
56
|
+
if (isBody(entry))
|
|
57
|
+
icons[iconName] = { body: entry.body, width: entry.width, height: entry.height };
|
|
58
|
+
}
|
|
59
|
+
return { prefix, width: data.width, height: data.height, icons, aliases: data.aliases };
|
|
60
|
+
},
|
|
61
|
+
async collections() {
|
|
62
|
+
const data = await file();
|
|
63
|
+
return [{ prefix: data.prefix, name: 'Material Design Icons', total: Object.keys(data.icons).length, category: 'General', license: 'Apache-2.0', multicolor: false }];
|
|
64
|
+
},
|
|
65
|
+
async collectionIcons() {
|
|
66
|
+
const data = await file();
|
|
67
|
+
return Object.keys(data.icons).map((iconName) => data.prefix + ':' + iconName);
|
|
68
|
+
},
|
|
69
|
+
async search(query, options) {
|
|
70
|
+
const data = await file();
|
|
71
|
+
const prefix = await name();
|
|
72
|
+
const limit = options?.limit ?? 20;
|
|
73
|
+
const needle = query.toLowerCase();
|
|
74
|
+
const icons = Object.keys(data.icons)
|
|
75
|
+
.filter((iconName) => iconName.toLowerCase().includes(needle))
|
|
76
|
+
.slice(0, limit)
|
|
77
|
+
.map((iconName) => prefix + ':' + iconName);
|
|
78
|
+
return { icons, total: icons.length, collections: { [prefix]: { name: 'Material Design Icons', total: Object.keys(data.icons).length, category: 'General' } } };
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-artifact-studio",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Local-first artifacts for DeepSeek Harness: the agent creates pages and documents as versioned files, and you open, edit, restore, and export them beside the chat.",
|
|
6
6
|
"keywords": [
|
|
@@ -27,11 +27,14 @@
|
|
|
27
27
|
"dist",
|
|
28
28
|
"client.js",
|
|
29
29
|
"client.doc.js",
|
|
30
|
+
"client.canvas.js",
|
|
31
|
+
"assets",
|
|
30
32
|
"cordis.patch.yml",
|
|
31
33
|
"locale/*.json",
|
|
32
34
|
"icon.svg",
|
|
33
35
|
"LICENSE",
|
|
34
|
-
"README.md"
|
|
36
|
+
"README.md",
|
|
37
|
+
"THIRD_PARTY_NOTICES.md"
|
|
35
38
|
],
|
|
36
39
|
"dsh": {
|
|
37
40
|
"bundle": {
|
|
@@ -59,10 +62,13 @@
|
|
|
59
62
|
"prepack": "node scripts/check-icon.mjs"
|
|
60
63
|
},
|
|
61
64
|
"dependencies": {
|
|
65
|
+
"@open-pencil/core": "0.16.0",
|
|
62
66
|
"docx": "9.15.3",
|
|
63
67
|
"marked": "^17.0.1"
|
|
64
68
|
},
|
|
65
69
|
"devDependencies": {
|
|
70
|
+
"@iconify-json/mdi": "1.2.3",
|
|
71
|
+
"@open-pencil/vue": "0.16.0",
|
|
66
72
|
"@tiptap/core": "3.33.1",
|
|
67
73
|
"@tiptap/extension-list": "^3.33.1",
|
|
68
74
|
"@tiptap/extension-table": "^3.33.1",
|
|
@@ -72,10 +78,13 @@
|
|
|
72
78
|
"@types/node": "^22.20.5",
|
|
73
79
|
"@types/react": "^18.3.31",
|
|
74
80
|
"@types/react-dom": "^18.3.7",
|
|
81
|
+
"canvaskit-wasm": "0.41.1",
|
|
75
82
|
"esbuild": "^0.25.0",
|
|
76
83
|
"jsdom": "^25.0.1",
|
|
77
84
|
"react": "18.3.1",
|
|
78
85
|
"react-dom": "18.3.1",
|
|
79
|
-
"
|
|
86
|
+
"roboto-fontface": "0.10.0",
|
|
87
|
+
"typescript": "^5.9.3",
|
|
88
|
+
"vue": "3.5.41"
|
|
80
89
|
}
|
|
81
90
|
}
|