@goodandready/dsh-image-gen 0.10.24 → 0.10.26
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 +14 -0
- package/README.ru.md +14 -0
- package/README.zh.md +14 -0
- package/lib/attachment-helper.js +82 -0
- package/lib/client.js +149 -21
- package/lib/history.js +93 -0
- package/lib/index.js +25 -167
- package/lib/pattern-helpers.js +87 -0
- package/lib/providers/backends/custom.js +93 -0
- package/lib/providers/backends/fal.js +67 -0
- package/lib/providers/backends/gemini.js +37 -0
- package/lib/providers/backends/local.js +136 -0
- package/lib/providers/backends/replicate.js +83 -0
- package/lib/providers/backends/seedream.js +49 -0
- package/lib/providers/backends/subscription.js +58 -0
- package/lib/providers/shared-helpers.js +164 -0
- package/lib/providers.js +46 -553
- package/lib/register-tools.js +8 -0
- package/lib/responsive-helpers.js +94 -0
- package/lib/spritesheet-helpers.js +65 -0
- package/lib/tools/editing.js +2 -0
- package/lib/tools/generation-pack.js +74 -0
- package/lib/tools/generation.js +2 -66
- package/lib/tools/pattern.js +125 -0
- package/lib/tools/processing-advanced.js +7 -1
- package/lib/tools/responsive.js +267 -0
- package/lib/tools/sketch.js +167 -0
- package/lib/tools/spritesheet.js +151 -0
- package/package.json +7 -4
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Pure helpers for generate_responsive_mockups (#173) — no cordis imports.
|
|
2
|
+
|
|
3
|
+
export const DEVICE_ORDER = ['mobile', 'tablet', 'desktop']
|
|
4
|
+
|
|
5
|
+
export const DEVICE_PRESETS = {
|
|
6
|
+
mobile: {
|
|
7
|
+
id: 'mobile',
|
|
8
|
+
label: 'Mobile',
|
|
9
|
+
aspect: '9:16',
|
|
10
|
+
size: 'portrait_16_9',
|
|
11
|
+
fileStem: 'mockup-mobile',
|
|
12
|
+
viewport: 'iPhone-class mobile viewport 375×812, portrait 9:16',
|
|
13
|
+
layoutHint:
|
|
14
|
+
'Single-column mobile UI mockup: compact header, stacked content, thumb-reachable bottom actions. '
|
|
15
|
+
+ 'Preserve the same product, brand colors, typography family and visual language as the desktop and tablet versions.',
|
|
16
|
+
},
|
|
17
|
+
tablet: {
|
|
18
|
+
id: 'tablet',
|
|
19
|
+
label: 'Tablet',
|
|
20
|
+
aspect: '3:4',
|
|
21
|
+
size: 'portrait_4_3',
|
|
22
|
+
fileStem: 'mockup-tablet',
|
|
23
|
+
viewport: 'iPad-class tablet viewport 768×1024, portrait 3:4',
|
|
24
|
+
layoutHint:
|
|
25
|
+
'Tablet UI mockup with two-column or wide single-column layout, roomier spacing than mobile, '
|
|
26
|
+
+ 'same product screens, brand colors, and component language as mobile and desktop versions.',
|
|
27
|
+
},
|
|
28
|
+
desktop: {
|
|
29
|
+
id: 'desktop',
|
|
30
|
+
label: 'Desktop',
|
|
31
|
+
aspect: '16:9',
|
|
32
|
+
size: 'landscape_16_9',
|
|
33
|
+
fileStem: 'mockup-desktop',
|
|
34
|
+
viewport: 'desktop viewport 1440×900 / 1920×1080, landscape 16:10–16:9',
|
|
35
|
+
layoutHint:
|
|
36
|
+
'Desktop UI mockup with multi-column layout, full navigation chrome and wide content area. '
|
|
37
|
+
+ 'Same product, brand palette and component language as mobile and tablet versions.',
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function normalizeDevices(input) {
|
|
42
|
+
if (input == null) return [...DEVICE_ORDER]
|
|
43
|
+
const list = Array.isArray(input) ? input : [input]
|
|
44
|
+
const cleaned = list
|
|
45
|
+
.map((d) => String(d || '').trim().toLowerCase())
|
|
46
|
+
.filter((d) => DEVICE_ORDER.includes(d))
|
|
47
|
+
const unique = []
|
|
48
|
+
for (const d of cleaned) {
|
|
49
|
+
if (!unique.includes(d)) unique.push(d)
|
|
50
|
+
}
|
|
51
|
+
return unique.length ? unique : [...DEVICE_ORDER]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function resolveDevicePreset(device) {
|
|
55
|
+
return DEVICE_PRESETS[String(device || '').toLowerCase()] || DEVICE_PRESETS.mobile
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Build a shared semantic base prompt so the three viewports stay visually coherent.
|
|
60
|
+
* Device-specific lines only restate composition constraints, not the product idea.
|
|
61
|
+
*/
|
|
62
|
+
export function buildResponsivePrompt(basePrompt, { device, stylePreset, paletteColors } = {}) {
|
|
63
|
+
const preset = resolveDevicePreset(device)
|
|
64
|
+
const core = String(basePrompt || '').trim()
|
|
65
|
+
const style = stylePreset ? ` Style preset: ${stylePreset}.` : ''
|
|
66
|
+
const palette = Array.isArray(paletteColors) && paletteColors.length
|
|
67
|
+
? ` Dominant brand colors must remain consistent across all responsive mockups: ${paletteColors.join(', ')}.`
|
|
68
|
+
: ''
|
|
69
|
+
return `Responsive UI product mockup of: ${core}.${style}${palette} `
|
|
70
|
+
+ `Render as a polished ${preset.viewport}. ${preset.layoutHint} `
|
|
71
|
+
+ 'Keep the same information architecture, iconography language, spacing rhythm and color palette across mobile, tablet and desktop variants. '
|
|
72
|
+
+ 'High-fidelity interface design, clean UI, realistic device framing only if needed, no lorem-ipsum walls of unreadable text, no watermark.'
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function mockupFileName(device, { outputName } = {}) {
|
|
76
|
+
const preset = resolveDevicePreset(device)
|
|
77
|
+
const stem = String(outputName || '').trim()
|
|
78
|
+
? String(outputName).trim().replace(/\.(png|jpe?g|webp)$/i, '')
|
|
79
|
+
: preset.fileStem
|
|
80
|
+
// Issue requires mockup-mobile.png style names when default stem is used.
|
|
81
|
+
if (!outputName) return `${preset.fileStem}.png`
|
|
82
|
+
return `${stem}-${preset.id}.png`
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function deviceMeta(device) {
|
|
86
|
+
const preset = resolveDevicePreset(device)
|
|
87
|
+
return {
|
|
88
|
+
device: preset.id,
|
|
89
|
+
label: preset.label,
|
|
90
|
+
aspect: preset.aspect,
|
|
91
|
+
size: preset.size,
|
|
92
|
+
viewport: preset.viewport,
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Pure helpers for generate_spritesheet (#177) — no cordis/dsh-tools imports.
|
|
2
|
+
|
|
3
|
+
export const ANIMATION_PRESETS = {
|
|
4
|
+
idle: ['neutral standing pose', 'subtle breathing chest rise', 'slight weight shift', 'return to neutral'],
|
|
5
|
+
walk: ['contact pose left foot forward', 'down pose', 'passing pose', 'up pose', 'contact pose right foot forward', 'down pose', 'passing pose', 'up pose'],
|
|
6
|
+
attack: ['wind-up anticipation', 'strike extension', 'impact frame', 'recoil follow-through'],
|
|
7
|
+
pulse: ['scale 1.0 rest', 'scale 1.08 glow peak', 'scale 1.0 settle', 'scale 0.96 micro-bounce'],
|
|
8
|
+
hover: ['lift 0px', 'lift -6px', 'lift 0px', 'lift 2px press'],
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function clampFrames(n, animation = 'idle') {
|
|
12
|
+
const v = Number(n)
|
|
13
|
+
const anim = String(animation || 'idle').toLowerCase()
|
|
14
|
+
// walk preset has a natural 8-phase cycle; 12 would stutter at loop point
|
|
15
|
+
if (anim === 'walk') return v === 4 ? 4 : 8
|
|
16
|
+
if (v === 4 || v === 8 || v === 12) return v
|
|
17
|
+
return 8
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function buildSpritesheetCss({ frameCount, frameW, frameH, durationSec, name }) {
|
|
21
|
+
const anim = name || 'play'
|
|
22
|
+
const sheetW = frameW * frameCount
|
|
23
|
+
return `/* dsh-image-gen spritesheet */
|
|
24
|
+
.${anim} {
|
|
25
|
+
width: ${frameW}px;
|
|
26
|
+
height: ${frameH}px;
|
|
27
|
+
background-image: url('./${anim}-sheet.svg');
|
|
28
|
+
background-repeat: no-repeat;
|
|
29
|
+
background-size: ${sheetW}px ${frameH}px;
|
|
30
|
+
animation: ${anim} ${durationSec}s steps(${frameCount}) infinite;
|
|
31
|
+
}
|
|
32
|
+
@keyframes ${anim} {
|
|
33
|
+
from { background-position: 0 0; }
|
|
34
|
+
to { background-position: -${sheetW}px 0; }
|
|
35
|
+
}
|
|
36
|
+
`
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function buildSpritesheetSvg(frames, { frameW, frameH }) {
|
|
40
|
+
const count = frames.length
|
|
41
|
+
const totalW = frameW * count
|
|
42
|
+
const totalH = frameH
|
|
43
|
+
let images = ''
|
|
44
|
+
frames.forEach((src, idx) => {
|
|
45
|
+
const b64 = Buffer.isBuffer(src.bytes) ? src.bytes.toString('base64') : Buffer.from(src.bytes).toString('base64')
|
|
46
|
+
const mime = src.mediaType || 'image/png'
|
|
47
|
+
const x = idx * frameW
|
|
48
|
+
images += `<image href="data:${mime};base64,${b64}" x="${x}" y="0" width="${frameW}" height="${frameH}" preserveAspectRatio="xMidYMid slice"/>`
|
|
49
|
+
})
|
|
50
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
51
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="${totalW}" height="${totalH}" viewBox="0 0 ${totalW} ${totalH}">
|
|
52
|
+
${images}
|
|
53
|
+
</svg>`
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function buildFramePrompts(subject, animation, frameCount) {
|
|
57
|
+
const preset = ANIMATION_PRESETS[animation] || ANIMATION_PRESETS.idle
|
|
58
|
+
const phases = []
|
|
59
|
+
for (let i = 0; i < frameCount; i++) {
|
|
60
|
+
phases.push(preset[i % preset.length])
|
|
61
|
+
}
|
|
62
|
+
return phases.map((phase, i) =>
|
|
63
|
+
`2D game sprite frame ${i + 1} of ${frameCount}: ${subject}. Animation phase: ${phase}. `
|
|
64
|
+
+ 'Transparent or solid flat background, consistent character scale and camera, same character design across frames, clean silhouette, even lighting.')
|
|
65
|
+
}
|
package/lib/tools/editing.js
CHANGED
|
@@ -116,6 +116,7 @@ export function registerEditingTools(ctx, deps) {
|
|
|
116
116
|
},
|
|
117
117
|
async execute(args, exec) {
|
|
118
118
|
try {
|
|
119
|
+
const cfg = live()
|
|
119
120
|
trackAndAssertLoopGuard(exec?.agent?.session?.id || 'default', { limit: cfg.loopGuardLimit })
|
|
120
121
|
const estimatedCostEdit = calculateGenerationCost({
|
|
121
122
|
provider: cfg.provider || 'fal',
|
|
@@ -249,6 +250,7 @@ export function registerEditingTools(ctx, deps) {
|
|
|
249
250
|
},
|
|
250
251
|
async execute(args, exec) {
|
|
251
252
|
try {
|
|
253
|
+
const cfg = live()
|
|
252
254
|
trackAndAssertLoopGuard(exec?.agent?.session?.id || 'default', { limit: cfg.loopGuardLimit })
|
|
253
255
|
const count = normalizeCount(args.count || 1)
|
|
254
256
|
const estimatedCostVary = calculateGenerationCost({
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
2
|
+
import { toLosslessJson } from '../providers.js'
|
|
3
|
+
import { slugify } from '../index.js'
|
|
4
|
+
|
|
5
|
+
export function registerGenerationPackTool(ctx, deps) {
|
|
6
|
+
const { live } = deps
|
|
7
|
+
|
|
8
|
+
ctx.effect(() => {
|
|
9
|
+
ctx.tools.register(
|
|
10
|
+
defineTool({
|
|
11
|
+
name: 'generate_image_pack',
|
|
12
|
+
description: 'Generate a multi-aspect ratio pack of the same image (e.g. 1:1, 16:9, 9:16) for different platforms.',
|
|
13
|
+
parameters: {
|
|
14
|
+
prompt: { type: 'string', required: true, description: 'Text prompt for image generation.' },
|
|
15
|
+
aspect_ratios: { type: 'array', items: { type: 'string' }, description: 'Target ratios (default: ["1:1", "16:9", "9:16"]).' },
|
|
16
|
+
output_name: { type: 'string', description: 'Base file name for the pack.' },
|
|
17
|
+
},
|
|
18
|
+
output: {
|
|
19
|
+
schema: {
|
|
20
|
+
type: 'object',
|
|
21
|
+
additionalProperties: true,
|
|
22
|
+
properties: {
|
|
23
|
+
images: { type: 'array', items: { type: 'object', additionalProperties: true } },
|
|
24
|
+
count: { type: 'number' },
|
|
25
|
+
warnings: { type: 'array', items: { type: 'string' } },
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
async execute(args, exec) {
|
|
30
|
+
const ratios = Array.isArray(args.aspect_ratios) && args.aspect_ratios.length ? args.aspect_ratios : ['1:1', '16:9', '9:16']
|
|
31
|
+
const cfg = live()
|
|
32
|
+
const generateTool = ctx.tools.get('generate_image')
|
|
33
|
+
const results = []
|
|
34
|
+
const warnings = []
|
|
35
|
+
const seedBase = Math.floor(Math.random() * 100000)
|
|
36
|
+
|
|
37
|
+
const packTasks = ratios.map((ratio) => async () => {
|
|
38
|
+
const sizeName = ratio === '16:9' ? 'landscape_16_9' : ratio === '9:16' ? 'portrait_16_9' : ratio === '4:3' ? 'landscape_4_3' : ratio === '3:4' ? 'portrait_4_3' : 'square_hd'
|
|
39
|
+
const name = `${slugify(args.output_name || 'pack')}-${ratio.replace(':', 'x')}`
|
|
40
|
+
try {
|
|
41
|
+
const genResult = await generateTool.execute({
|
|
42
|
+
prompt: args.prompt,
|
|
43
|
+
image_size: sizeName,
|
|
44
|
+
seed: seedBase,
|
|
45
|
+
output_name: name,
|
|
46
|
+
}, exec)
|
|
47
|
+
return { success: true, ratio, genResult }
|
|
48
|
+
} catch (err) {
|
|
49
|
+
return { success: false, ratio, error: err?.message || String(err) }
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
const settledPack = await Promise.all(packTasks.map((t) => t()))
|
|
53
|
+
for (const item of settledPack) {
|
|
54
|
+
if (item.success) {
|
|
55
|
+
results.push({ ratio: item.ratio, ...item.genResult })
|
|
56
|
+
} else {
|
|
57
|
+
warnings.push(`Ratio ${item.ratio} failed: ${item.error}`)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (results.length === 0 && warnings.length > 0) {
|
|
62
|
+
throw new Error(`All aspect ratio generations failed in pack: ${warnings.join('; ')}`)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return toLosslessJson({
|
|
66
|
+
images: results,
|
|
67
|
+
count: results.length,
|
|
68
|
+
...(warnings.length ? { warnings } : {}),
|
|
69
|
+
})
|
|
70
|
+
},
|
|
71
|
+
}),
|
|
72
|
+
)
|
|
73
|
+
}, 'dsh-image-gen: tool generate_image_pack')
|
|
74
|
+
}
|
package/lib/tools/generation.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { polishPrompt } from '../prompt-polisher.js'
|
|
2
|
+
import { registerGenerationPackTool } from './generation-pack.js'
|
|
2
3
|
|
|
3
4
|
/** Run an array of async task functions with a concurrency cap */
|
|
4
5
|
async function asyncPool(tasks, concurrency = 3) {
|
|
@@ -542,70 +543,5 @@ export function registerGenerationTools(ctx, deps) {
|
|
|
542
543
|
}),
|
|
543
544
|
)
|
|
544
545
|
}, 'dsh-image-gen: tool generate_image')
|
|
545
|
-
ctx
|
|
546
|
-
ctx.tools.register(
|
|
547
|
-
defineTool({
|
|
548
|
-
name: 'generate_image_pack',
|
|
549
|
-
description: 'Generate a multi-aspect ratio pack of the same image (e.g. 1:1, 16:9, 9:16) for different platforms.',
|
|
550
|
-
parameters: {
|
|
551
|
-
prompt: { type: 'string', required: true, description: 'Text prompt for image generation.' },
|
|
552
|
-
aspect_ratios: { type: 'array', items: { type: 'string' }, description: 'Target ratios (default: ["1:1", "16:9", "9:16"]).' },
|
|
553
|
-
output_name: { type: 'string', description: 'Base file name for the pack.' },
|
|
554
|
-
},
|
|
555
|
-
output: {
|
|
556
|
-
schema: {
|
|
557
|
-
type: 'object',
|
|
558
|
-
additionalProperties: true,
|
|
559
|
-
properties: {
|
|
560
|
-
images: { type: 'array', items: { type: 'object', additionalProperties: true } },
|
|
561
|
-
count: { type: 'number' },
|
|
562
|
-
warnings: { type: 'array', items: { type: 'string' } },
|
|
563
|
-
},
|
|
564
|
-
},
|
|
565
|
-
},
|
|
566
|
-
async execute(args, exec) {
|
|
567
|
-
const ratios = Array.isArray(args.aspect_ratios) && args.aspect_ratios.length ? args.aspect_ratios : ['1:1', '16:9', '9:16']
|
|
568
|
-
const cfg = live()
|
|
569
|
-
const generateTool = ctx.tools.get('generate_image')
|
|
570
|
-
const results = []
|
|
571
|
-
const warnings = []
|
|
572
|
-
const seedBase = Math.floor(Math.random() * 100000)
|
|
573
|
-
|
|
574
|
-
const packTasks = ratios.map((ratio) => async () => {
|
|
575
|
-
const sizeName = ratio === '16:9' ? 'landscape_16_9' : ratio === '9:16' ? 'portrait_16_9' : ratio === '4:3' ? 'landscape_4_3' : ratio === '3:4' ? 'portrait_4_3' : 'square_hd'
|
|
576
|
-
const name = `${slugify(args.output_name || 'pack')}-${ratio.replace(':', 'x')}`
|
|
577
|
-
try {
|
|
578
|
-
const genResult = await generateTool.execute({
|
|
579
|
-
prompt: args.prompt,
|
|
580
|
-
image_size: sizeName,
|
|
581
|
-
seed: seedBase,
|
|
582
|
-
output_name: name,
|
|
583
|
-
}, exec)
|
|
584
|
-
return { success: true, ratio, genResult }
|
|
585
|
-
} catch (err) {
|
|
586
|
-
return { success: false, ratio, error: err?.message || String(err) }
|
|
587
|
-
}
|
|
588
|
-
})
|
|
589
|
-
const settledPack = await Promise.all(packTasks.map((t) => t()))
|
|
590
|
-
for (const item of settledPack) {
|
|
591
|
-
if (item.success) {
|
|
592
|
-
results.push({ ratio: item.ratio, ...item.genResult })
|
|
593
|
-
} else {
|
|
594
|
-
warnings.push(`Ratio ${item.ratio} failed: ${item.error}`)
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
if (results.length === 0 && warnings.length > 0) {
|
|
599
|
-
throw new Error(`All aspect ratio generations failed in pack: ${warnings.join('; ')}`)
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
return toLosslessJson({
|
|
603
|
-
images: results,
|
|
604
|
-
count: results.length,
|
|
605
|
-
...(warnings.length ? { warnings } : {}),
|
|
606
|
-
})
|
|
607
|
-
},
|
|
608
|
-
}),
|
|
609
|
-
)
|
|
610
|
-
}, 'dsh-image-gen: tool generate_image_pack')
|
|
546
|
+
registerGenerationPackTool(ctx, deps)
|
|
611
547
|
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// pattern — generate_seamless_pattern tool (#178)
|
|
2
|
+
|
|
3
|
+
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import { mkdir, writeFile } from 'node:fs/promises'
|
|
6
|
+
import { makeProviders, toLosslessJson, saveAttachmentSafe, sizeToPixels } from '../providers.js'
|
|
7
|
+
import { trackAndAssertLoopGuard } from '../loop-guard.js'
|
|
8
|
+
import { sanitizeErrorAndLogs } from '../security.js'
|
|
9
|
+
import {
|
|
10
|
+
buildSeamlessPrompt,
|
|
11
|
+
buildPatternCss,
|
|
12
|
+
normalizeDensity,
|
|
13
|
+
} from '../pattern-helpers.js'
|
|
14
|
+
|
|
15
|
+
export function registerPatternTools(ctx, deps) {
|
|
16
|
+
const { live, slugify, resolveApiKey } = deps
|
|
17
|
+
|
|
18
|
+
ctx.effect(() => {
|
|
19
|
+
ctx.tools.register(
|
|
20
|
+
defineTool({
|
|
21
|
+
name: 'generate_seamless_pattern',
|
|
22
|
+
description:
|
|
23
|
+
'Generate a seamless tileable repeating pattern for backgrounds (#178). '
|
|
24
|
+
+ 'Describe the motif and optional style; returns a square pattern image plus CSS background-repeat snippet.',
|
|
25
|
+
parameters: {
|
|
26
|
+
motif: {
|
|
27
|
+
type: 'string',
|
|
28
|
+
required: true,
|
|
29
|
+
description: 'What to repeat (e.g. "terrazzo chips", "sakura blossoms", "circuit traces").',
|
|
30
|
+
},
|
|
31
|
+
style: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
description: 'Visual style (e.g. "watercolor", "flat vector", "isometric").',
|
|
34
|
+
},
|
|
35
|
+
density: {
|
|
36
|
+
type: 'string',
|
|
37
|
+
description: 'Motif density: low, medium, or high (default medium).',
|
|
38
|
+
},
|
|
39
|
+
size: {
|
|
40
|
+
type: 'string',
|
|
41
|
+
description: 'Named image size (default square).',
|
|
42
|
+
},
|
|
43
|
+
output_name: {
|
|
44
|
+
type: 'string',
|
|
45
|
+
description: 'File name stem / CSS class (default seamless-pattern).',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
output: {
|
|
49
|
+
schema: {
|
|
50
|
+
type: 'object',
|
|
51
|
+
additionalProperties: true,
|
|
52
|
+
properties: {
|
|
53
|
+
summary: { type: 'string' },
|
|
54
|
+
path: { type: 'string' },
|
|
55
|
+
url: { type: 'string' },
|
|
56
|
+
css: { type: 'string' },
|
|
57
|
+
cssPath: { type: 'string' },
|
|
58
|
+
format: { type: 'string' },
|
|
59
|
+
attachment: { type: 'object', additionalProperties: true },
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
async execute(args, exec) {
|
|
64
|
+
try {
|
|
65
|
+
const cfg = live()
|
|
66
|
+
trackAndAssertLoopGuard(exec?.agent?.session?.id || 'default', { limit: cfg.loopGuardLimit })
|
|
67
|
+
const density = normalizeDensity(args.density)
|
|
68
|
+
const prompt = buildSeamlessPrompt(args.motif, args.style, density)
|
|
69
|
+
const provider = cfg.provider || 'fal'
|
|
70
|
+
const format = cfg.defaultFormat || 'png'
|
|
71
|
+
const size = args.size || 'square'
|
|
72
|
+
const seed = Math.floor(Math.random() * 100000)
|
|
73
|
+
|
|
74
|
+
const pdeps = {
|
|
75
|
+
fetchImpl: fetch,
|
|
76
|
+
resolveKey: (ref) => resolveApiKey(ctx, ref),
|
|
77
|
+
cfg,
|
|
78
|
+
}
|
|
79
|
+
const job = { prompt, size, format, seed, provider }
|
|
80
|
+
const providers = makeProviders(pdeps, job)
|
|
81
|
+
const fn = providers[provider] || providers.fal || providers.custom
|
|
82
|
+
const gen = await fn(seed, prompt)
|
|
83
|
+
|
|
84
|
+
const stem = slugify(args.output_name || 'seamless-pattern')
|
|
85
|
+
const name = `${stem}.${format}`
|
|
86
|
+
const { attachment, localUrl } = await saveAttachmentSafe(ctx, {
|
|
87
|
+
bytes: gen.bytes,
|
|
88
|
+
mediaType: gen.mediaType || 'image/png',
|
|
89
|
+
name,
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
const sessionCwd = exec?.agent?.session?.header?.cwd
|
|
93
|
+
const outDir = path.resolve(sessionCwd || process.cwd(), cfg.outputDir || 'generated/images')
|
|
94
|
+
await mkdir(outDir, { recursive: true })
|
|
95
|
+
const filePath = path.join(outDir, name)
|
|
96
|
+
await writeFile(filePath, gen.bytes)
|
|
97
|
+
|
|
98
|
+
const [tilePx] = sizeToPixels(size)
|
|
99
|
+
const css = buildPatternCss({ className: stem, sizePx: tilePx, imagePath: `./${name}` })
|
|
100
|
+
const cssPath = path.join(outDir, `${stem}.css`)
|
|
101
|
+
await writeFile(cssPath, css, 'utf8')
|
|
102
|
+
|
|
103
|
+
const summary = `### Seamless pattern (${density})\n`
|
|
104
|
+
+ `- **Motif**: ${args.motif}\n`
|
|
105
|
+
+ `- **File**: \`${filePath}\`\n`
|
|
106
|
+
+ `- **CSS**: \`${cssPath}\`\n\n`
|
|
107
|
+
+ ``
|
|
108
|
+
|
|
109
|
+
return toLosslessJson({
|
|
110
|
+
summary,
|
|
111
|
+
path: filePath,
|
|
112
|
+
url: localUrl,
|
|
113
|
+
css,
|
|
114
|
+
cssPath,
|
|
115
|
+
format,
|
|
116
|
+
attachment,
|
|
117
|
+
})
|
|
118
|
+
} catch (err) {
|
|
119
|
+
throw new Error(sanitizeErrorAndLogs(err.message || err))
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
}),
|
|
123
|
+
)
|
|
124
|
+
}, 'dsh-image-gen: tool generate_seamless_pattern')
|
|
125
|
+
}
|
|
@@ -458,7 +458,13 @@ export function registerProcessingAdvancedTools(ctx, deps) {
|
|
|
458
458
|
const b64 = Buffer.isBuffer(src.bytes) ? src.bytes.toString('base64') : Buffer.from(src.bytes).toString('base64')
|
|
459
459
|
logoDataUri = `data:${src.mediaType || 'image/png'};base64,${b64}`
|
|
460
460
|
}
|
|
461
|
-
} catch (
|
|
461
|
+
} catch (err) {
|
|
462
|
+
// Optional logo embed: brand pack still exports without it.
|
|
463
|
+
const msg = err?.message || String(err)
|
|
464
|
+
if (typeof ctx?.logger?.debug === 'function') {
|
|
465
|
+
ctx.logger.debug(`dsh-image-gen: brand logo embed skipped: ${msg}`)
|
|
466
|
+
}
|
|
467
|
+
}
|
|
462
468
|
}
|
|
463
469
|
|
|
464
470
|
const exportedFiles = []
|