@goodandready/dsh-image-gen 0.10.4 → 0.10.6
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 +7 -0
- package/README.ru.md +4 -0
- package/lib/frontend-assets.js +436 -0
- package/lib/index.js +566 -5
- package/lib/providers.js +73 -2
- package/lib/resolve-image.js +243 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -45,9 +45,113 @@ import {
|
|
|
45
45
|
applyStylePreset,
|
|
46
46
|
resolveStylePreset,
|
|
47
47
|
blendImagesFal,
|
|
48
|
+
toLosslessJson,
|
|
48
49
|
} from './providers.js'
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
import { resolveConversationImage, analyzeImageWithVision, buildDualOutputMarkdown } from './resolve-image.js'
|
|
52
|
+
import {
|
|
53
|
+
extractDesignTokens,
|
|
54
|
+
generateCssGradient,
|
|
55
|
+
checkWcagContrast,
|
|
56
|
+
optimizeSvgContent,
|
|
57
|
+
generatePwaIconSuite,
|
|
58
|
+
extractSampleColorsFromBuffer,
|
|
59
|
+
} from './frontend-assets.js'
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
export { IMAGE_SIZES, OUTPUT_FORMATS, PROVIDER_KEYS, buildSidecar, normalizeMediaType, resolveConversationImage, analyzeImageWithVision }
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Сохраняет сгенерированный ассет в воркспейс, регистрирует в attachments и возвращает Dual-Output (#150).
|
|
67
|
+
*/
|
|
68
|
+
export async function saveAndAttachResult(ctx, exec, cfg, {
|
|
69
|
+
bytes,
|
|
70
|
+
mediaType,
|
|
71
|
+
name,
|
|
72
|
+
stem,
|
|
73
|
+
prompt,
|
|
74
|
+
size,
|
|
75
|
+
format,
|
|
76
|
+
seed,
|
|
77
|
+
provider,
|
|
78
|
+
model,
|
|
79
|
+
cost,
|
|
80
|
+
sourceUrl,
|
|
81
|
+
deliverAs,
|
|
82
|
+
args = {},
|
|
83
|
+
action = 'generated',
|
|
84
|
+
}) {
|
|
85
|
+
const attachment = await ctx.attachments.saveImage({
|
|
86
|
+
data: new Uint8Array(bytes),
|
|
87
|
+
mediaType,
|
|
88
|
+
name,
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
const sessionCwd = exec?.agent?.session?.header?.cwd
|
|
92
|
+
const targetDir = (args.output_dir && String(args.output_dir).trim()) || cfg.outputDir || 'generated/images'
|
|
93
|
+
const outDir = path.resolve(sessionCwd || process.cwd(), targetDir)
|
|
94
|
+
await mkdir(outDir, { recursive: true })
|
|
95
|
+
const filePath = path.join(outDir, name)
|
|
96
|
+
await writeFile(filePath, bytes)
|
|
97
|
+
|
|
98
|
+
const localUrl = '/dsh-image-gen/image?id=' + encodeURIComponent(attachment.attachmentId)
|
|
99
|
+
+ '&mt=' + encodeURIComponent(attachment.mediaType)
|
|
100
|
+
+ '&b=' + encodeURIComponent(String(attachment.bytes))
|
|
101
|
+
+ '&w=' + encodeURIComponent(String(attachment.width))
|
|
102
|
+
+ '&h=' + encodeURIComponent(String(attachment.height))
|
|
103
|
+
|
|
104
|
+
await writeFile(
|
|
105
|
+
path.join(outDir, `${stem}.json`),
|
|
106
|
+
JSON.stringify(buildSidecar({
|
|
107
|
+
prompt,
|
|
108
|
+
size,
|
|
109
|
+
format,
|
|
110
|
+
seed,
|
|
111
|
+
provider,
|
|
112
|
+
deliverAs,
|
|
113
|
+
width: attachment.width,
|
|
114
|
+
height: attachment.height,
|
|
115
|
+
mediaType,
|
|
116
|
+
attachmentId: attachment.attachmentId,
|
|
117
|
+
url: deliverAs === 'image' && sourceUrl ? sourceUrl : localUrl,
|
|
118
|
+
cost,
|
|
119
|
+
}), null, 2),
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
const summary = buildDualOutputMarkdown({
|
|
123
|
+
action,
|
|
124
|
+
filePath,
|
|
125
|
+
width: attachment.width,
|
|
126
|
+
height: attachment.height,
|
|
127
|
+
mediaType,
|
|
128
|
+
seed,
|
|
129
|
+
provider,
|
|
130
|
+
model: model || cfg.model || cfg.customModel || 'default',
|
|
131
|
+
cost,
|
|
132
|
+
attachmentId: attachment.attachmentId,
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
return toLosslessJson({
|
|
136
|
+
summary,
|
|
137
|
+
path: filePath,
|
|
138
|
+
url: deliverAs === 'image' && sourceUrl ? sourceUrl : localUrl,
|
|
139
|
+
width: attachment.width,
|
|
140
|
+
height: attachment.height,
|
|
141
|
+
seed,
|
|
142
|
+
prompt,
|
|
143
|
+
cost,
|
|
144
|
+
format: mediaType.replace('image/', ''),
|
|
145
|
+
attachment: {
|
|
146
|
+
attachmentId: attachment.attachmentId,
|
|
147
|
+
mediaType: attachment.mediaType,
|
|
148
|
+
bytes: attachment.bytes,
|
|
149
|
+
width: attachment.width,
|
|
150
|
+
height: attachment.height,
|
|
151
|
+
name: attachment.name,
|
|
152
|
+
},
|
|
153
|
+
})
|
|
154
|
+
}
|
|
51
155
|
|
|
52
156
|
export const name = 'dsh-image-gen'
|
|
53
157
|
|
|
@@ -813,7 +917,7 @@ export function apply(ctx, config) {
|
|
|
813
917
|
height: gen.height || attachment.height,
|
|
814
918
|
seed: gen.seed,
|
|
815
919
|
prompt: promptArg,
|
|
816
|
-
|
|
920
|
+
...(enhanced.enhanced ? { originalPrompt: args.prompt } : {}),
|
|
817
921
|
cost: gen.cost,
|
|
818
922
|
format: mediaType.replace('image/', ''),
|
|
819
923
|
attachment: {
|
|
@@ -873,7 +977,19 @@ export function apply(ctx, config) {
|
|
|
873
977
|
}
|
|
874
978
|
}
|
|
875
979
|
const first = images[0]
|
|
876
|
-
|
|
980
|
+
const dualOutputSummary = buildDualOutputMarkdown({
|
|
981
|
+
action: 'generated',
|
|
982
|
+
filePath: first.path,
|
|
983
|
+
width: first.width,
|
|
984
|
+
height: first.height,
|
|
985
|
+
mediaType: first.mediaType || ('image/' + (first.format || 'png')),
|
|
986
|
+
seed: first.seed,
|
|
987
|
+
provider,
|
|
988
|
+
model: cfg.model || cfg.customModel || 'default',
|
|
989
|
+
cost: first.cost,
|
|
990
|
+
attachmentId: first.attachment?.attachmentId || 'N/A',
|
|
991
|
+
})
|
|
992
|
+
return toLosslessJson({ summary: dualOutputSummary, channel: provider, provider, model: cfg.model || cfg.customModel, ...first, images })
|
|
877
993
|
},
|
|
878
994
|
}),
|
|
879
995
|
)
|
|
@@ -1173,11 +1289,257 @@ export function apply(ctx, config) {
|
|
|
1173
1289
|
throw new Error(`All aspect ratio generations failed in pack: ${warnings.join('; ')}`)
|
|
1174
1290
|
}
|
|
1175
1291
|
|
|
1176
|
-
return {
|
|
1292
|
+
return toLosslessJson({
|
|
1177
1293
|
images: results,
|
|
1178
1294
|
count: results.length,
|
|
1179
|
-
warnings
|
|
1295
|
+
...(warnings.length ? { warnings } : {}),
|
|
1296
|
+
})
|
|
1297
|
+
},
|
|
1298
|
+
}),
|
|
1299
|
+
)
|
|
1300
|
+
|
|
1301
|
+
// Редактирование существующего изображения (Inpainting / Edits) (#142, #144, #145, #150).
|
|
1302
|
+
ctx.tools.register(
|
|
1303
|
+
defineTool({
|
|
1304
|
+
name: 'edit_image',
|
|
1305
|
+
description:
|
|
1306
|
+
'Edit an existing image using inpainting, targeted modification, or object replacement. '
|
|
1307
|
+
+ 'Describe the desired changes in prompt. '
|
|
1308
|
+
+ 'If image is omitted or "latest", automatically resolves the most recent image from the conversation session (#144). '
|
|
1309
|
+
+ 'Leverages @goodandready/dsh-vision-bridge for pre-edit composition analysis (#145). '
|
|
1310
|
+
+ 'Optionally accepts mask (path or attachment id) and strength (0.1-1.0). Returns safe dual-output (#150).',
|
|
1311
|
+
parameters: {
|
|
1312
|
+
prompt: {
|
|
1313
|
+
type: 'string',
|
|
1314
|
+
required: true,
|
|
1315
|
+
description: 'Detailed description of the modification or edit to perform on the image.',
|
|
1316
|
+
},
|
|
1317
|
+
image: {
|
|
1318
|
+
type: 'string',
|
|
1319
|
+
description: 'Path or attachment id of the source image. Defaults to "latest" to auto-resolve from session history.',
|
|
1320
|
+
},
|
|
1321
|
+
mask: {
|
|
1322
|
+
type: 'string',
|
|
1323
|
+
description: 'Optional path or attachment id of the inpaint mask image.',
|
|
1324
|
+
},
|
|
1325
|
+
strength: {
|
|
1326
|
+
type: 'number',
|
|
1327
|
+
description: 'Denoising / edit strength between 0.1 and 1.0 (default 0.75 for edits, 0.9 for mask inpainting).',
|
|
1328
|
+
},
|
|
1329
|
+
output_name: {
|
|
1330
|
+
type: 'string',
|
|
1331
|
+
description: 'Optional file name stem for the saved edited image.',
|
|
1332
|
+
},
|
|
1333
|
+
output_dir: {
|
|
1334
|
+
type: 'string',
|
|
1335
|
+
description: 'Optional custom directory to write edited image into.',
|
|
1336
|
+
},
|
|
1337
|
+
},
|
|
1338
|
+
output: {
|
|
1339
|
+
schema: {
|
|
1340
|
+
type: 'object',
|
|
1341
|
+
additionalProperties: true,
|
|
1342
|
+
properties: {
|
|
1343
|
+
summary: { type: 'string' },
|
|
1344
|
+
path: { type: 'string' },
|
|
1345
|
+
url: { type: 'string' },
|
|
1346
|
+
width: { type: 'number' },
|
|
1347
|
+
height: { type: 'number' },
|
|
1348
|
+
seed: { type: 'number' },
|
|
1349
|
+
provider: { type: 'string' },
|
|
1350
|
+
cost: { type: 'number' },
|
|
1351
|
+
format: { type: 'string' },
|
|
1352
|
+
attachment: { type: 'object', additionalProperties: true },
|
|
1353
|
+
visionAnalysis: { type: 'string' },
|
|
1354
|
+
},
|
|
1355
|
+
},
|
|
1356
|
+
},
|
|
1357
|
+
async execute(args, exec) {
|
|
1358
|
+
const source = await resolveConversationImage(ctx, exec, args.image)
|
|
1359
|
+
const mask = args.mask ? await resolveSource(ctx, exec, args.mask) : undefined
|
|
1360
|
+
const vision = await analyzeImageWithVision(ctx, exec, source)
|
|
1361
|
+
|
|
1362
|
+
let effectivePrompt = args.prompt
|
|
1363
|
+
if (vision.available && vision.summary) {
|
|
1364
|
+
effectivePrompt = `${args.prompt} (Context: modifying ${vision.summary})`
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
const provider = cfg.provider || 'fal'
|
|
1368
|
+
const deps = {
|
|
1369
|
+
fetchImpl: ctx.http ? (url, opt) => ctx.http(url, opt) : fetch,
|
|
1370
|
+
resolveKey: (ref) => resolveApiKey(ctx, ref),
|
|
1371
|
+
cfg,
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
const seed = Math.floor(Math.random() * 100000)
|
|
1375
|
+
const strength = args.strength ?? (mask ? 0.85 : 0.65)
|
|
1376
|
+
const format = cfg.defaultFormat || 'png'
|
|
1377
|
+
const size = cfg.defaultSize || 'square_hd'
|
|
1378
|
+
|
|
1379
|
+
const job = {
|
|
1380
|
+
prompt: effectivePrompt,
|
|
1381
|
+
size,
|
|
1382
|
+
format,
|
|
1383
|
+
seed,
|
|
1384
|
+
source,
|
|
1385
|
+
mask,
|
|
1386
|
+
strength,
|
|
1387
|
+
provider,
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
const providers = makeProviders(deps, job)
|
|
1391
|
+
const fn = providers[provider] || providers.fal || providers.custom
|
|
1392
|
+
const gen = await fn(seed, effectivePrompt)
|
|
1393
|
+
|
|
1394
|
+
const stem = args.output_name ? slugify(args.output_name) : `${source.name}-edit-${seed}`
|
|
1395
|
+
const name = `${stem}.${format}`
|
|
1396
|
+
|
|
1397
|
+
const result = await saveAndAttachResult(ctx, exec, cfg, {
|
|
1398
|
+
bytes: gen.bytes,
|
|
1399
|
+
mediaType: gen.mediaType || 'image/png',
|
|
1400
|
+
name,
|
|
1401
|
+
stem,
|
|
1402
|
+
prompt: args.prompt,
|
|
1403
|
+
size,
|
|
1404
|
+
format,
|
|
1405
|
+
seed: gen.seed ?? seed,
|
|
1406
|
+
provider,
|
|
1407
|
+
model: cfg.model,
|
|
1408
|
+
cost: gen.cost,
|
|
1409
|
+
sourceUrl: gen.sourceUrl,
|
|
1410
|
+
deliverAs: cfg.deliverAs || 'both',
|
|
1411
|
+
args,
|
|
1412
|
+
action: 'edited',
|
|
1413
|
+
})
|
|
1414
|
+
|
|
1415
|
+
if (vision.summary) {
|
|
1416
|
+
result.visionAnalysis = vision.summary
|
|
1180
1417
|
}
|
|
1418
|
+
return toLosslessJson(result)
|
|
1419
|
+
},
|
|
1420
|
+
}),
|
|
1421
|
+
)
|
|
1422
|
+
|
|
1423
|
+
// Генерация вариаций существующего изображения (#143, #144, #145, #150).
|
|
1424
|
+
ctx.tools.register(
|
|
1425
|
+
defineTool({
|
|
1426
|
+
name: 'vary_image',
|
|
1427
|
+
description:
|
|
1428
|
+
'Generate subtle or creative variations of an existing image while preserving overall composition and structure. '
|
|
1429
|
+
+ 'Pass variation_strength between 0.1 (subtle difference) and 0.9 (strong reinterpretation, default 0.35). '
|
|
1430
|
+
+ 'If image is omitted or "latest", automatically resolves the most recent image from the conversation session (#144). '
|
|
1431
|
+
+ 'Returns safe dual-output for text-only LLMs (#150).',
|
|
1432
|
+
parameters: {
|
|
1433
|
+
image: {
|
|
1434
|
+
type: 'string',
|
|
1435
|
+
description: 'Path or attachment id of the source image. Defaults to "latest" to auto-resolve from session history.',
|
|
1436
|
+
},
|
|
1437
|
+
prompt: {
|
|
1438
|
+
type: 'string',
|
|
1439
|
+
description: 'Optional prompt to steer the variation towards a specific mood, lighting, or style.',
|
|
1440
|
+
},
|
|
1441
|
+
variation_strength: {
|
|
1442
|
+
type: 'number',
|
|
1443
|
+
description: 'Strength of variation between 0.1 and 0.9. Default: 0.35.',
|
|
1444
|
+
},
|
|
1445
|
+
count: {
|
|
1446
|
+
type: 'integer',
|
|
1447
|
+
description: 'Number of variations to produce (1-4, default 1).',
|
|
1448
|
+
},
|
|
1449
|
+
output_name: {
|
|
1450
|
+
type: 'string',
|
|
1451
|
+
description: 'Optional file name stem for the saved variations.',
|
|
1452
|
+
},
|
|
1453
|
+
output_dir: {
|
|
1454
|
+
type: 'string',
|
|
1455
|
+
description: 'Optional custom directory to write variations into.',
|
|
1456
|
+
},
|
|
1457
|
+
},
|
|
1458
|
+
output: {
|
|
1459
|
+
schema: {
|
|
1460
|
+
type: 'object',
|
|
1461
|
+
additionalProperties: true,
|
|
1462
|
+
properties: {
|
|
1463
|
+
summary: { type: 'string' },
|
|
1464
|
+
path: { type: 'string' },
|
|
1465
|
+
url: { type: 'string' },
|
|
1466
|
+
width: { type: 'number' },
|
|
1467
|
+
height: { type: 'number' },
|
|
1468
|
+
seed: { type: 'number' },
|
|
1469
|
+
provider: { type: 'string' },
|
|
1470
|
+
cost: { type: 'number' },
|
|
1471
|
+
format: { type: 'string' },
|
|
1472
|
+
attachment: { type: 'object', additionalProperties: true },
|
|
1473
|
+
variations: { type: 'array', items: { type: 'object', additionalProperties: true } },
|
|
1474
|
+
},
|
|
1475
|
+
},
|
|
1476
|
+
},
|
|
1477
|
+
async execute(args, exec) {
|
|
1478
|
+
const source = await resolveConversationImage(ctx, exec, args.image)
|
|
1479
|
+
const vision = await analyzeImageWithVision(ctx, exec, source)
|
|
1480
|
+
|
|
1481
|
+
const provider = cfg.provider || 'fal'
|
|
1482
|
+
const deps = {
|
|
1483
|
+
fetchImpl: ctx.http ? (url, opt) => ctx.http(url, opt) : fetch,
|
|
1484
|
+
resolveKey: (ref) => resolveApiKey(ctx, ref),
|
|
1485
|
+
cfg,
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
const count = normalizeCount(args.count || 1)
|
|
1489
|
+
const variationStrength = Math.max(0.05, Math.min(0.95, args.variation_strength ?? 0.35))
|
|
1490
|
+
const baseSeed = Math.floor(Math.random() * 100000)
|
|
1491
|
+
const format = cfg.defaultFormat || 'png'
|
|
1492
|
+
const size = cfg.defaultSize || 'square_hd'
|
|
1493
|
+
|
|
1494
|
+
const promptText = args.prompt || (vision.available ? `variation of ${vision.summary}` : 'high fidelity variation preserving composition')
|
|
1495
|
+
|
|
1496
|
+
const results = []
|
|
1497
|
+
for (let i = 0; i < count; i++) {
|
|
1498
|
+
const currentSeed = baseSeed + i
|
|
1499
|
+
const job = {
|
|
1500
|
+
prompt: promptText,
|
|
1501
|
+
size,
|
|
1502
|
+
format,
|
|
1503
|
+
seed: currentSeed,
|
|
1504
|
+
source,
|
|
1505
|
+
strength: variationStrength,
|
|
1506
|
+
provider,
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
const providers = makeProviders(deps, job)
|
|
1510
|
+
const fn = providers[provider] || providers.fal || providers.custom
|
|
1511
|
+
const gen = await fn(currentSeed, promptText)
|
|
1512
|
+
|
|
1513
|
+
const stem = args.output_name
|
|
1514
|
+
? `${slugify(args.output_name)}-var-${i + 1}`
|
|
1515
|
+
: `${source.name}-var-${currentSeed}`
|
|
1516
|
+
const name = `${stem}.${format}`
|
|
1517
|
+
|
|
1518
|
+
const item = await saveAndAttachResult(ctx, exec, cfg, {
|
|
1519
|
+
bytes: gen.bytes,
|
|
1520
|
+
mediaType: gen.mediaType || 'image/png',
|
|
1521
|
+
name,
|
|
1522
|
+
stem,
|
|
1523
|
+
prompt: promptText,
|
|
1524
|
+
size,
|
|
1525
|
+
format,
|
|
1526
|
+
seed: gen.seed ?? currentSeed,
|
|
1527
|
+
provider,
|
|
1528
|
+
model: cfg.model,
|
|
1529
|
+
cost: gen.cost,
|
|
1530
|
+
sourceUrl: gen.sourceUrl,
|
|
1531
|
+
deliverAs: cfg.deliverAs || 'both',
|
|
1532
|
+
args,
|
|
1533
|
+
action: `variation (${variationStrength})`,
|
|
1534
|
+
})
|
|
1535
|
+
results.push(item)
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
const first = results[0]
|
|
1539
|
+
return toLosslessJson({
|
|
1540
|
+
...first,
|
|
1541
|
+
variations: results.map((r) => ({ path: r.path, attachmentId: r.attachment?.attachmentId, seed: r.seed })),
|
|
1542
|
+
})
|
|
1181
1543
|
},
|
|
1182
1544
|
}),
|
|
1183
1545
|
)
|
|
@@ -1215,6 +1577,205 @@ export function apply(ctx, config) {
|
|
|
1215
1577
|
},
|
|
1216
1578
|
}),
|
|
1217
1579
|
)
|
|
1580
|
+
|
|
1581
|
+
// #172: Генератор дизайн-токенов и CSS/Tailwind палитры по концепту
|
|
1582
|
+
ctx.tools.register(
|
|
1583
|
+
defineTool({
|
|
1584
|
+
name: 'extract_design_tokens',
|
|
1585
|
+
description: 'Extract design tokens (CSS variables, Tailwind colors config, W3C tokens JSON) from an image or palette.',
|
|
1586
|
+
parameters: {
|
|
1587
|
+
image: { type: 'string', description: 'Path or attachment ID of the image to extract colors from.' },
|
|
1588
|
+
colors: { type: 'array', items: { type: 'string' }, description: 'Optional list of hex colors if already known.' },
|
|
1589
|
+
prefix: { type: 'string', description: 'Token naming prefix (default: color).' },
|
|
1590
|
+
},
|
|
1591
|
+
output: {
|
|
1592
|
+
schema: {
|
|
1593
|
+
type: 'object',
|
|
1594
|
+
additionalProperties: true,
|
|
1595
|
+
properties: {
|
|
1596
|
+
tokens: { type: 'object', additionalProperties: true },
|
|
1597
|
+
cssVariables: { type: 'string' },
|
|
1598
|
+
tailwindSnippet: { type: 'string' },
|
|
1599
|
+
w3cTokens: { type: 'object', additionalProperties: true },
|
|
1600
|
+
},
|
|
1601
|
+
},
|
|
1602
|
+
},
|
|
1603
|
+
async execute(args, exec) {
|
|
1604
|
+
let colors = args.colors
|
|
1605
|
+
if (!colors || colors.length === 0) {
|
|
1606
|
+
if (args.image) {
|
|
1607
|
+
const source = await resolveSource(ctx, exec, args.image)
|
|
1608
|
+
if (source && source.bytes) {
|
|
1609
|
+
colors = extractSampleColorsFromBuffer(source.bytes)
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
return extractDesignTokens(colors, { prefix: args.prefix })
|
|
1614
|
+
},
|
|
1615
|
+
}),
|
|
1616
|
+
)
|
|
1617
|
+
|
|
1618
|
+
// #174: Конвертер фоновых изображений в легковесные CSS Mesh Gradients
|
|
1619
|
+
ctx.tools.register(
|
|
1620
|
+
defineTool({
|
|
1621
|
+
name: 'image_to_css_gradient',
|
|
1622
|
+
description: 'Convert an image background or color palette into a lightweight pure CSS gradient (< 1KB).',
|
|
1623
|
+
parameters: {
|
|
1624
|
+
image: { type: 'string', description: 'Path or attachment ID of the image.' },
|
|
1625
|
+
colors: { type: 'array', items: { type: 'string' }, description: 'Optional explicit hex colors for the gradient.' },
|
|
1626
|
+
type: { type: 'string', enum: ['mesh', 'linear', 'radial'], description: 'Gradient type: mesh, linear, or radial (default: mesh).' },
|
|
1627
|
+
},
|
|
1628
|
+
output: {
|
|
1629
|
+
schema: {
|
|
1630
|
+
type: 'object',
|
|
1631
|
+
additionalProperties: true,
|
|
1632
|
+
properties: {
|
|
1633
|
+
type: { type: 'string' },
|
|
1634
|
+
fallbackColor: { type: 'string' },
|
|
1635
|
+
gradientCss: { type: 'string' },
|
|
1636
|
+
completeStyle: { type: 'string' },
|
|
1637
|
+
byteSize: { type: 'number' },
|
|
1638
|
+
},
|
|
1639
|
+
},
|
|
1640
|
+
},
|
|
1641
|
+
async execute(args, exec) {
|
|
1642
|
+
let colors = args.colors
|
|
1643
|
+
if (!colors || colors.length === 0) {
|
|
1644
|
+
if (args.image) {
|
|
1645
|
+
const source = await resolveSource(ctx, exec, args.image)
|
|
1646
|
+
if (source && source.bytes) {
|
|
1647
|
+
colors = extractSampleColorsFromBuffer(source.bytes)
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
return generateCssGradient(colors, args.type || 'mesh')
|
|
1652
|
+
},
|
|
1653
|
+
}),
|
|
1654
|
+
)
|
|
1655
|
+
|
|
1656
|
+
// #175: Проверка контрастности фона под текст по WCAG 2.1
|
|
1657
|
+
ctx.tools.register(
|
|
1658
|
+
defineTool({
|
|
1659
|
+
name: 'check_image_contrast',
|
|
1660
|
+
description: 'Check image background contrast ratio against text color according to WCAG 2.1 AA/AAA standards and suggest scrim.',
|
|
1661
|
+
parameters: {
|
|
1662
|
+
image: { type: 'string', description: 'Path or attachment ID of the image.' },
|
|
1663
|
+
colors: { type: 'array', items: { type: 'string' }, description: 'Optional list of background hex colors.' },
|
|
1664
|
+
text_color: { type: 'string', description: 'Text hex color to test against (default: #ffffff).' },
|
|
1665
|
+
},
|
|
1666
|
+
output: {
|
|
1667
|
+
schema: {
|
|
1668
|
+
type: 'object',
|
|
1669
|
+
additionalProperties: true,
|
|
1670
|
+
properties: {
|
|
1671
|
+
textHex: { type: 'string' },
|
|
1672
|
+
minContrastRatio: { type: 'number' },
|
|
1673
|
+
passedAA: { type: 'boolean' },
|
|
1674
|
+
passedAALarge: { type: 'boolean' },
|
|
1675
|
+
passedAAA: { type: 'boolean' },
|
|
1676
|
+
recommendation: { type: 'string' },
|
|
1677
|
+
suggestedScrimCss: { type: 'string' },
|
|
1678
|
+
details: { type: 'array', items: { type: 'object', additionalProperties: true } },
|
|
1679
|
+
},
|
|
1680
|
+
},
|
|
1681
|
+
},
|
|
1682
|
+
async execute(args, exec) {
|
|
1683
|
+
let colors = args.colors
|
|
1684
|
+
if (!colors || colors.length === 0) {
|
|
1685
|
+
if (args.image) {
|
|
1686
|
+
const source = await resolveSource(ctx, exec, args.image)
|
|
1687
|
+
if (source && source.bytes) {
|
|
1688
|
+
colors = extractSampleColorsFromBuffer(source.bytes)
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
return checkWcagContrast(colors, args.text_color || '#ffffff')
|
|
1693
|
+
},
|
|
1694
|
+
}),
|
|
1695
|
+
)
|
|
1696
|
+
|
|
1697
|
+
// #176: Интеллектуальная постобработка, очистка и оптимизация SVG
|
|
1698
|
+
ctx.tools.register(
|
|
1699
|
+
defineTool({
|
|
1700
|
+
name: 'optimize_vector_svg',
|
|
1701
|
+
description: 'Clean, sanitize, and minify SVG content, normalize viewBox, and export React TSX component.',
|
|
1702
|
+
parameters: {
|
|
1703
|
+
svg_content: { type: 'string', description: 'Raw SVG markup string to optimize.' },
|
|
1704
|
+
image: { type: 'string', description: 'Path or attachment ID of an SVG file if not passing raw string.' },
|
|
1705
|
+
component_name: { type: 'string', description: 'React component name for TSX export (default: VectorIcon).' },
|
|
1706
|
+
},
|
|
1707
|
+
output: {
|
|
1708
|
+
schema: {
|
|
1709
|
+
type: 'object',
|
|
1710
|
+
additionalProperties: true,
|
|
1711
|
+
properties: {
|
|
1712
|
+
svg: { type: 'string' },
|
|
1713
|
+
viewBox: { type: 'string' },
|
|
1714
|
+
originalSize: { type: 'number' },
|
|
1715
|
+
optimizedSize: { type: 'number' },
|
|
1716
|
+
savedBytes: { type: 'number' },
|
|
1717
|
+
reductionPercent: { type: 'number' },
|
|
1718
|
+
reactTsx: { type: 'string' },
|
|
1719
|
+
},
|
|
1720
|
+
},
|
|
1721
|
+
},
|
|
1722
|
+
async execute(args, exec) {
|
|
1723
|
+
let svgStr = args.svg_content
|
|
1724
|
+
if (!svgStr && args.image) {
|
|
1725
|
+
const source = await resolveSource(ctx, exec, args.image)
|
|
1726
|
+
if (source && source.bytes) {
|
|
1727
|
+
svgStr = source.bytes.toString('utf8')
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
if (!svgStr) {
|
|
1731
|
+
throw new Error('Either svg_content or image must be provided')
|
|
1732
|
+
}
|
|
1733
|
+
return optimizeSvgContent(svgStr, { componentName: args.component_name })
|
|
1734
|
+
},
|
|
1735
|
+
}),
|
|
1736
|
+
)
|
|
1737
|
+
|
|
1738
|
+
// #190: Генератор полного комплекта фавиконок, иконок приложений и PWA-манифеста
|
|
1739
|
+
ctx.tools.register(
|
|
1740
|
+
defineTool({
|
|
1741
|
+
name: 'generate_pwa_icon_suite',
|
|
1742
|
+
description: 'Generate standard PWA icons specification, HTML meta tags, and web app manifest.json.',
|
|
1743
|
+
parameters: {
|
|
1744
|
+
image: { type: 'string', description: 'Source icon image path or attachment ID.' },
|
|
1745
|
+
name: { type: 'string', description: 'App name (e.g. My Application).' },
|
|
1746
|
+
short_name: { type: 'string', description: 'App short name (e.g. MyApp).' },
|
|
1747
|
+
theme_color: { type: 'string', description: 'Theme color hex (e.g. #0f172a).' },
|
|
1748
|
+
background_color: { type: 'string', description: 'Background color hex (e.g. #ffffff).' },
|
|
1749
|
+
icons_dir: { type: 'string', description: 'Directory for icons relative to webroot (default: icons).' },
|
|
1750
|
+
},
|
|
1751
|
+
output: {
|
|
1752
|
+
schema: {
|
|
1753
|
+
type: 'object',
|
|
1754
|
+
additionalProperties: true,
|
|
1755
|
+
properties: {
|
|
1756
|
+
name: { type: 'string' },
|
|
1757
|
+
shortName: { type: 'string' },
|
|
1758
|
+
themeColor: { type: 'string' },
|
|
1759
|
+
backgroundColor: { type: 'string' },
|
|
1760
|
+
icons: { type: 'array', items: { type: 'object', additionalProperties: true } },
|
|
1761
|
+
manifestJson: { type: 'string' },
|
|
1762
|
+
htmlHeadSnippet: { type: 'string' },
|
|
1763
|
+
},
|
|
1764
|
+
},
|
|
1765
|
+
},
|
|
1766
|
+
async execute(args, exec) {
|
|
1767
|
+
return generatePwaIconSuite({
|
|
1768
|
+
name: args.name || 'App',
|
|
1769
|
+
shortName: args.short_name || args.name || 'App',
|
|
1770
|
+
themeColor: args.theme_color || '#0f172a',
|
|
1771
|
+
backgroundColor: args.background_color || '#ffffff',
|
|
1772
|
+
iconsDir: args.icons_dir || 'icons',
|
|
1773
|
+
sourcePath: args.image || null,
|
|
1774
|
+
})
|
|
1775
|
+
},
|
|
1776
|
+
}),
|
|
1777
|
+
)
|
|
1778
|
+
|
|
1218
1779
|
})
|
|
1219
1780
|
|
|
1220
1781
|
}
|