@thready-web/dsh-bot-plugin 0.1.0-beta.10 → 0.1.0-beta.11
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/dist/canvas-http.js +248 -0
- package/dist/canvas-skills.js +56 -0
- package/dist/canvas-store.js +794 -0
- package/dist/canvas-tools.js +211 -0
- package/dist/context.js +1 -0
- package/dist/http.js +19 -0
- package/dist/index.js +11 -0
- package/dist/work-http.js +19 -0
- package/dist/work-worker.js +5 -0
- package/package.json +2 -1
- package/public/assets/{SourceEditor-BEQaScgR.js → SourceEditor-uu0G7jsM.js} +3 -3
- package/public/assets/{cssMode-gpcjCFFS.js → cssMode-C5DAFF5H.js} +1 -1
- package/public/assets/{freemarker2-C1qemGIt.js → freemarker2-DExNwSiZ.js} +1 -1
- package/public/assets/{handlebars-sZqIfAlP.js → handlebars-BK7YAvpQ.js} +1 -1
- package/public/assets/{html-Bn1WXB8L.js → html-CdDm_zae.js} +1 -1
- package/public/assets/{htmlMode-CvQyXnaW.js → htmlMode-CLdn9oa1.js} +1 -1
- package/public/assets/index-BB-QDSf2.css +1 -0
- package/public/assets/index-CsX-_qbo.js +62 -0
- package/public/assets/{javascript-Ox4Jg12j.js → javascript-mLl83_3W.js} +1 -1
- package/public/assets/{jsonMode-DMR7R2dQ.js → jsonMode-B1-bihFd.js} +1 -1
- package/public/assets/{liquid-B6HxtpBd.js → liquid-Cv8m0HUb.js} +1 -1
- package/public/assets/{mdx--jDhmrXq.js → mdx-Q12b91rL.js} +1 -1
- package/public/assets/{python-YjG50skX.js → python-Kda811W0.js} +1 -1
- package/public/assets/{razor-CEcFE3UK.js → razor-CRuCpdOW.js} +1 -1
- package/public/assets/{tsMode-g4kTQl09.js → tsMode-BGHcz-M3.js} +1 -1
- package/public/assets/{typescript-CnHeFmPW.js → typescript-Db1e0DCT.js} +1 -1
- package/public/assets/{xml-BFXMY9nb.js → xml-H3zzFmnd.js} +1 -1
- package/public/assets/{yaml-DNm87nSf.js → yaml-BQrKvmTF.js} +1 -1
- package/public/index.html +2 -2
- package/skills/ui/baseline-ui/SKILL.md +85 -0
- package/skills/ui/bencium-innovative-ux-designer/SKILL.md +227 -0
- package/skills/ui/better-ui/SKILL.md +133 -0
- package/skills/ui/design-lab/SKILL.md +920 -0
- package/skills/ui/frontend-design/SKILL.md +71 -0
- package/skills/ui/impeccable/SKILL.md +93 -0
- package/skills/ui/interface-design/SKILL.md +320 -0
- package/skills/ui/sources.json +66 -0
- package/skills/ui/ui-design/SKILL.md +35 -0
- package/skills/ui/ui-skills-root/SKILL.md +59 -0
- package/skills/ui/visual-design-foundations/SKILL.md +318 -0
- package/skills/ui/web-design-guidelines/SKILL.md +39 -0
- package/public/assets/index-DRNkUrer.css +0 -1
- package/public/assets/index-DhL5Kdlz.js +0 -63
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { asStoreFailure, toolError } from "./errors.js";
|
|
2
|
+
import { CANVAS_MAX_JSON_BYTES, normalizeCanvasPath } from "./canvas-store.js";
|
|
3
|
+
const API = '/session-foundations/api/canvas';
|
|
4
|
+
const MEDIA = '/dsh-bot/canvas-media/';
|
|
5
|
+
const CANVAS_ID = /^cnv_[A-Za-z0-9_-]{16}$/;
|
|
6
|
+
/**
|
|
7
|
+
* Manual and test publish routes. They require the existing login gate.
|
|
8
|
+
* Model tools do not call them. Media routes are dispatched before that gate
|
|
9
|
+
* and accept only the capability token.
|
|
10
|
+
*/
|
|
11
|
+
export async function handleCanvasApi(req, path, url, canvas) {
|
|
12
|
+
try {
|
|
13
|
+
const method = req.method ?? 'GET';
|
|
14
|
+
if (method === 'POST' && path === API) {
|
|
15
|
+
const body = await readBody(req);
|
|
16
|
+
return outcome(canvas.create({ sessionId: body.sessionId, title: body.title, ticketId: body.ticketId, createdBy: 'user' }));
|
|
17
|
+
}
|
|
18
|
+
if (method === 'GET' && path === API)
|
|
19
|
+
return outcome(canvas.list(url.searchParams.get('sessionId') ?? ''));
|
|
20
|
+
const parts = path.slice(API.length + 1).split('/');
|
|
21
|
+
const id = parts[0] ?? '';
|
|
22
|
+
if (!CANVAS_ID.test(id))
|
|
23
|
+
return { status: 404, body: toolError('NOT_FOUND', 'No such canvas.') };
|
|
24
|
+
if (method === 'GET' && parts.length === 1)
|
|
25
|
+
return outcome(canvas.get(id));
|
|
26
|
+
if (method === 'GET' && parts[1] === 'revisions' && parts.length === 3) {
|
|
27
|
+
const revision = Number(parts[2]);
|
|
28
|
+
if (!/^[1-9]\d{0,8}$/.test(parts[2] ?? ''))
|
|
29
|
+
return { status: 404, body: toolError('NOT_FOUND', 'No such revision.') };
|
|
30
|
+
return outcome(canvas.manifest(id, revision));
|
|
31
|
+
}
|
|
32
|
+
if (method !== 'POST' || parts.length !== 2)
|
|
33
|
+
return { status: 404, body: toolError('NOT_FOUND', 'No such canvas route.') };
|
|
34
|
+
const body = await readBody(req);
|
|
35
|
+
if (parts[1] === 'snapshot' || parts[1] === 'delta') {
|
|
36
|
+
const files = decodeFiles(body.files);
|
|
37
|
+
if (!Array.isArray(files))
|
|
38
|
+
return { status: 400, body: files };
|
|
39
|
+
return outcome(await canvas.publish({
|
|
40
|
+
canvasId: id,
|
|
41
|
+
kind: parts[1],
|
|
42
|
+
baseRevision: typeof body.baseRevision === 'number' ? body.baseRevision : null,
|
|
43
|
+
entry: typeof body.entry === 'string' ? body.entry : '',
|
|
44
|
+
expectedFence: typeof body.expectedFence === 'number' ? body.expectedFence : -1,
|
|
45
|
+
files,
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
if (parts[1] === 'token') {
|
|
49
|
+
const revision = typeof body.revision === 'number' ? body.revision : null;
|
|
50
|
+
const minRevision = typeof body.minRevision === 'number' ? body.minRevision : revision;
|
|
51
|
+
const maxRevision = typeof body.maxRevision === 'number' ? body.maxRevision : revision;
|
|
52
|
+
if (minRevision == null || maxRevision == null)
|
|
53
|
+
return { status: 400, body: toolError('VALIDATION', 'revision is required.') };
|
|
54
|
+
return outcome(canvas.mint({ canvasId: id, minRevision, maxRevision }));
|
|
55
|
+
}
|
|
56
|
+
if (parts[1] === 'adopt')
|
|
57
|
+
return outcome(await canvas.adopt({ canvasId: id, revision: typeof body.revision === 'number' ? body.revision : 0 }));
|
|
58
|
+
if (parts[1] === 'revoke')
|
|
59
|
+
return outcome(canvas.revoke({ canvasId: id, tokenId: typeof body.tokenId === 'string' ? body.tokenId : '' }));
|
|
60
|
+
if (parts[1] === 'fail') {
|
|
61
|
+
return outcome(await canvas.fail({
|
|
62
|
+
canvasId: id,
|
|
63
|
+
expectedFence: typeof body.expectedFence === 'number' ? body.expectedFence : -1,
|
|
64
|
+
message: typeof body.message === 'string' ? body.message : '',
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
return { status: 404, body: toolError('NOT_FOUND', 'No such canvas route.') };
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
const code = error && typeof error === 'object' && 'code' in error ? String(error.code) : '';
|
|
71
|
+
if (code === 'VALIDATION')
|
|
72
|
+
return {
|
|
73
|
+
status: 400,
|
|
74
|
+
body: toolError('VALIDATION', error instanceof Error ? error.message : 'invalid canvas request'),
|
|
75
|
+
};
|
|
76
|
+
return { status: 500, body: asStoreFailure(error) };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Token-only media. A login cookie or Authorization header does not grant access.
|
|
81
|
+
* @param {string} requestUrl raw request target, before URL normalization
|
|
82
|
+
*/
|
|
83
|
+
export function serveCanvasMedia(req, res, requestUrl, canvas) {
|
|
84
|
+
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
85
|
+
json(res, 405, toolError('VALIDATION', 'canvas media is read-only.'));
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const parsed = parseCanvasMedia(requestUrl);
|
|
89
|
+
if (!parsed) {
|
|
90
|
+
json(res, 400, toolError('VALIDATION', 'canvas media path is not allowed.'));
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (!canvas) {
|
|
94
|
+
json(res, 404, toolError('NOT_FOUND', 'No such canvas file.'));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const found = canvas.readMedia(parsed);
|
|
98
|
+
if (found.ok === false) {
|
|
99
|
+
json(res, found.code === 'NOT_FOUND' ? 404 : found.code === 'VALIDATION' ? 400 : 401, found);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const origin = requestOrigin(req);
|
|
103
|
+
if (origin === '') {
|
|
104
|
+
json(res, 400, toolError('VALIDATION', 'canvas media needs a host.'));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const headers = {
|
|
108
|
+
'content-type': found.type === 'text/html' || found.type === 'text/css' ? `${found.type}; charset=utf-8` : found.type,
|
|
109
|
+
'content-length': String(found.bytes.length),
|
|
110
|
+
'cache-control': 'private, no-store',
|
|
111
|
+
'x-content-type-options': 'nosniff',
|
|
112
|
+
'referrer-policy': 'no-referrer',
|
|
113
|
+
'content-security-policy': mediaPolicy(found.type, origin, parsed),
|
|
114
|
+
};
|
|
115
|
+
res.writeHead(200, headers);
|
|
116
|
+
res.end(req.method === 'HEAD' ? undefined : found.bytes);
|
|
117
|
+
}
|
|
118
|
+
/** Raw media target. Dot segments and any percent-encoding are rejected before resolution. */
|
|
119
|
+
export function parseCanvasMedia(requestUrl) {
|
|
120
|
+
const pathname = (requestUrl.split('?')[0] ?? '').replace(/\/+$/, '');
|
|
121
|
+
if (!pathname.startsWith(MEDIA))
|
|
122
|
+
return null;
|
|
123
|
+
if (pathname.includes('\\') || pathname.includes('%') || pathname.includes('\0'))
|
|
124
|
+
return null;
|
|
125
|
+
if (pathname.split('/').includes('..') || pathname.split('/').includes('.'))
|
|
126
|
+
return null;
|
|
127
|
+
const parts = pathname.slice(MEDIA.length).split('/');
|
|
128
|
+
if (parts.length < 3)
|
|
129
|
+
return null;
|
|
130
|
+
const [token, revision, ...rest] = parts;
|
|
131
|
+
if (!token || !/^[A-Za-z0-9_-]{20,128}$/.test(token))
|
|
132
|
+
return null;
|
|
133
|
+
if (!revision || !/^[1-9]\d{0,8}$/.test(revision))
|
|
134
|
+
return null;
|
|
135
|
+
const path = normalizeCanvasPath(rest.join('/'));
|
|
136
|
+
if (!path)
|
|
137
|
+
return null;
|
|
138
|
+
return { token, revision: Number(revision), path };
|
|
139
|
+
}
|
|
140
|
+
function mediaPolicy(type, origin, parsed) {
|
|
141
|
+
const sandbox = "sandbox; base-uri 'none'; form-action 'none'";
|
|
142
|
+
if (type !== 'text/html')
|
|
143
|
+
return `default-src 'none'; ${sandbox}`;
|
|
144
|
+
const prefix = `${origin}${MEDIA}${parsed.token}/${parsed.revision}/`;
|
|
145
|
+
// A design draft usually keeps CSS in a <style> block. External sheets still have to come from this prefix.
|
|
146
|
+
return [
|
|
147
|
+
"default-src 'none'",
|
|
148
|
+
`img-src ${prefix}`,
|
|
149
|
+
`style-src ${prefix} 'unsafe-inline'`,
|
|
150
|
+
`font-src ${prefix}`,
|
|
151
|
+
`frame-ancestors ${origin}`,
|
|
152
|
+
sandbox,
|
|
153
|
+
].join('; ');
|
|
154
|
+
}
|
|
155
|
+
function requestOrigin(req) {
|
|
156
|
+
const host = header(req, 'host');
|
|
157
|
+
if (!host || /[\s/\\]/.test(host))
|
|
158
|
+
return '';
|
|
159
|
+
const forwarded = header(req, 'x-forwarded-proto');
|
|
160
|
+
const proto = forwarded === 'https' || forwarded === 'http' ? forwarded : 'http';
|
|
161
|
+
return `${proto}://${host}`;
|
|
162
|
+
}
|
|
163
|
+
function header(req, name) {
|
|
164
|
+
const value = req.headers[name];
|
|
165
|
+
return Array.isArray(value) ? (value[0] ?? '') : (value ?? '');
|
|
166
|
+
}
|
|
167
|
+
function outcome(result) {
|
|
168
|
+
if (result.ok !== false)
|
|
169
|
+
return { status: 200, body: result };
|
|
170
|
+
const status = result.code === 'NOT_FOUND' ? 404 : result.code === 'CAS_CONFLICT' ? 409 : result.code === 'FORBIDDEN' ? 401 : 400;
|
|
171
|
+
return { status, body: result };
|
|
172
|
+
}
|
|
173
|
+
function decodeFiles(value) {
|
|
174
|
+
if (!Array.isArray(value))
|
|
175
|
+
return toolError('VALIDATION', 'files are required.');
|
|
176
|
+
const files = [];
|
|
177
|
+
for (const item of value) {
|
|
178
|
+
if (!item || typeof item !== 'object')
|
|
179
|
+
return toolError('VALIDATION', 'files are required.');
|
|
180
|
+
const record = item;
|
|
181
|
+
if (typeof record.path !== 'string' || typeof record.type !== 'string' || typeof record.body !== 'string')
|
|
182
|
+
return toolError('VALIDATION', 'each file needs path, type, and body.');
|
|
183
|
+
if (record.body.length > CANVAS_MAX_JSON_BYTES)
|
|
184
|
+
return toolError('VALIDATION', 'A canvas file is too large.');
|
|
185
|
+
const bytes = decodeBase64(record.body);
|
|
186
|
+
if (!bytes)
|
|
187
|
+
return toolError('VALIDATION', `body for ${record.path} is not base64.`);
|
|
188
|
+
files.push({ path: record.path, type: record.type, bytes });
|
|
189
|
+
}
|
|
190
|
+
return files;
|
|
191
|
+
}
|
|
192
|
+
function decodeBase64(value) {
|
|
193
|
+
if (value.length % 4 === 1 || /[^A-Za-z0-9+/=]/.test(value))
|
|
194
|
+
return null;
|
|
195
|
+
const bytes = Buffer.from(value, 'base64');
|
|
196
|
+
const canonical = bytes.toString('base64').replace(/=+$/u, '');
|
|
197
|
+
if (canonical !== value.replace(/=+$/u, ''))
|
|
198
|
+
return null;
|
|
199
|
+
return bytes;
|
|
200
|
+
}
|
|
201
|
+
function readBody(req) {
|
|
202
|
+
return new Promise((resolve, reject) => {
|
|
203
|
+
const chunks = [];
|
|
204
|
+
let total = 0;
|
|
205
|
+
let failed = false;
|
|
206
|
+
const fail = (error) => {
|
|
207
|
+
if (failed)
|
|
208
|
+
return;
|
|
209
|
+
failed = true;
|
|
210
|
+
reject(error);
|
|
211
|
+
};
|
|
212
|
+
req.on('data', (chunk) => {
|
|
213
|
+
total += chunk.length;
|
|
214
|
+
if (total > CANVAS_MAX_JSON_BYTES) {
|
|
215
|
+
fail(Object.assign(new Error('Canvas package is too large.'), { code: 'VALIDATION' }));
|
|
216
|
+
req.destroy();
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
chunks.push(chunk);
|
|
220
|
+
});
|
|
221
|
+
req.on('end', () => {
|
|
222
|
+
if (failed)
|
|
223
|
+
return;
|
|
224
|
+
try {
|
|
225
|
+
const text = Buffer.concat(chunks).toString('utf8');
|
|
226
|
+
const parsed = text === '' ? {} : JSON.parse(text);
|
|
227
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
228
|
+
fail(Object.assign(new Error('canvas body must be an object.'), { code: 'VALIDATION' }));
|
|
229
|
+
else
|
|
230
|
+
resolve(parsed);
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
fail(Object.assign(new Error('invalid json'), { code: 'VALIDATION', cause: error }));
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
req.on('error', fail);
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
function json(res, status, body) {
|
|
240
|
+
const text = JSON.stringify(body);
|
|
241
|
+
res.writeHead(status, {
|
|
242
|
+
'content-type': 'application/json; charset=utf-8',
|
|
243
|
+
'content-length': Buffer.byteLength(text),
|
|
244
|
+
'cache-control': 'no-store',
|
|
245
|
+
'x-content-type-options': 'nosniff',
|
|
246
|
+
});
|
|
247
|
+
res.end(text);
|
|
248
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { readdirSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
const SKILL_ID = /^[a-z0-9][a-z0-9-]{0,64}$/;
|
|
5
|
+
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..', 'skills', 'ui');
|
|
6
|
+
/**
|
|
7
|
+
* Bundled canvas skills. `ui-design` is this plugin's contract.
|
|
8
|
+
* The other directories are a starter catalog from ui-skills.com.
|
|
9
|
+
*/
|
|
10
|
+
export function canvasSkillFiles() {
|
|
11
|
+
const entries = readdirSync(ROOT, { withFileTypes: true });
|
|
12
|
+
const skills = [];
|
|
13
|
+
for (const entry of entries) {
|
|
14
|
+
if (!entry.isDirectory() || !SKILL_ID.test(entry.name))
|
|
15
|
+
continue;
|
|
16
|
+
const bytes = readFileSync(join(ROOT, entry.name, 'SKILL.md'));
|
|
17
|
+
const summary = skillSummary(bytes.toString('utf8'), entry.name);
|
|
18
|
+
skills.push({
|
|
19
|
+
id: entry.name,
|
|
20
|
+
version: entry.name === 'ui-design' ? '1' : 'catalog',
|
|
21
|
+
summary,
|
|
22
|
+
bytes,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
skills.sort((left, right) => (left.id < right.id ? -1 : left.id > right.id ? 1 : 0));
|
|
26
|
+
return skills;
|
|
27
|
+
}
|
|
28
|
+
export function bindCanvasSkills(engine, sessionId) {
|
|
29
|
+
const bound = [];
|
|
30
|
+
const skipped = [];
|
|
31
|
+
for (const skill of canvasSkillFiles()) {
|
|
32
|
+
try {
|
|
33
|
+
engine.registerSkill(sessionId, 'public', skill.id, skill.version, skill.summary, skill.bytes);
|
|
34
|
+
bound.push(skill.id);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
skipped.push(skill.id);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return { bound, skipped };
|
|
41
|
+
}
|
|
42
|
+
function skillSummary(text, fallback) {
|
|
43
|
+
const fence = text.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
44
|
+
const block = fence?.[1] ?? '';
|
|
45
|
+
const line = block.match(/^description:\s*(.*)$/m)?.[1]?.trim() ?? '';
|
|
46
|
+
const description = unquote(line).replace(/\s+/g, ' ').trim();
|
|
47
|
+
const summary = description || fallback;
|
|
48
|
+
return summary.slice(0, fallback === 'ui-design' ? 180 : 100);
|
|
49
|
+
}
|
|
50
|
+
function unquote(value) {
|
|
51
|
+
if ((value.startsWith('"') && value.endsWith('"') && value.length >= 2) ||
|
|
52
|
+
(value.startsWith("'") && value.endsWith("'") && value.length >= 2)) {
|
|
53
|
+
return value.slice(1, -1);
|
|
54
|
+
}
|
|
55
|
+
return value;
|
|
56
|
+
}
|