@ikijs/mcp 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -7
- package/dist/chunk-MDSZNVVK.mjs +1197 -0
- package/dist/chunk-MDSZNVVK.mjs.map +1 -0
- package/dist/cli.js +677 -31
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +240 -1
- package/dist/index.d.ts +240 -1
- package/dist/index.js +683 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -1
- package/package.json +2 -2
- package/dist/chunk-6LRMADRR.mjs +0 -550
- package/dist/chunk-6LRMADRR.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -31,15 +31,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
autoRigFromLayers: () => autoRigFromLayers,
|
|
34
|
+
composeLayersFromParts: () => composeLayersFromParts,
|
|
34
35
|
createIkiMcpServer: () => createIkiMcpServer,
|
|
35
36
|
describeIki: () => describeIki,
|
|
37
|
+
formatMeasureReport: () => formatMeasureReport,
|
|
36
38
|
listStandardParameters: () => listStandardParameters,
|
|
39
|
+
measureLayers: () => measureLayers,
|
|
37
40
|
validateIki: () => validateIki
|
|
38
41
|
});
|
|
39
42
|
module.exports = __toCommonJS(index_exports);
|
|
40
43
|
|
|
41
44
|
// src/tools.ts
|
|
42
|
-
var import_node_fs2 = __toESM(require("fs"));
|
|
43
45
|
var import_node_path2 = __toESM(require("path"));
|
|
44
46
|
var import_format = require("@ikijs/format");
|
|
45
47
|
var import_editor2 = require("@ikijs/editor");
|
|
@@ -64,15 +66,18 @@ var AutoRigInputError = class extends Error {
|
|
|
64
66
|
this.name = "AutoRigInputError";
|
|
65
67
|
}
|
|
66
68
|
};
|
|
67
|
-
function
|
|
69
|
+
function rejectEmptyOrUrl(inputPath, noun, kind) {
|
|
68
70
|
if (typeof inputPath !== "string" || inputPath.trim() === "") {
|
|
69
|
-
throw new AutoRigInputError(
|
|
71
|
+
throw new AutoRigInputError(`${noun} is empty`);
|
|
70
72
|
}
|
|
71
73
|
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(inputPath)) {
|
|
72
74
|
throw new AutoRigInputError(
|
|
73
|
-
|
|
75
|
+
`${noun} must be a ${kind}, not a URL: ${inputPath}`
|
|
74
76
|
);
|
|
75
77
|
}
|
|
78
|
+
}
|
|
79
|
+
function resolveInputPath(inputPath) {
|
|
80
|
+
rejectEmptyOrUrl(inputPath, "layer path", "file path");
|
|
76
81
|
const resolved = import_node_path.default.resolve(process.cwd(), inputPath);
|
|
77
82
|
let stat;
|
|
78
83
|
try {
|
|
@@ -87,6 +92,30 @@ function resolveInputPath(inputPath) {
|
|
|
87
92
|
}
|
|
88
93
|
return resolved;
|
|
89
94
|
}
|
|
95
|
+
function resolveInputDir(dirPath) {
|
|
96
|
+
rejectEmptyOrUrl(dirPath, "layers dir", "directory path");
|
|
97
|
+
const resolved = import_node_path.default.resolve(process.cwd(), dirPath);
|
|
98
|
+
let stat;
|
|
99
|
+
try {
|
|
100
|
+
stat = import_node_fs.default.statSync(resolved);
|
|
101
|
+
} catch {
|
|
102
|
+
throw new AutoRigInputError(`layers dir not found: ${resolved}`);
|
|
103
|
+
}
|
|
104
|
+
if (!stat.isDirectory()) {
|
|
105
|
+
throw new AutoRigInputError(`layers path is not a directory: ${resolved}`);
|
|
106
|
+
}
|
|
107
|
+
return resolved;
|
|
108
|
+
}
|
|
109
|
+
function confineToWorkingDirectory(root, dir, label, original) {
|
|
110
|
+
const realRoot = import_node_fs.default.realpathSync(root);
|
|
111
|
+
const realDir = import_node_fs.default.realpathSync(dir);
|
|
112
|
+
if (realDir !== realRoot && !realDir.startsWith(realRoot + import_node_path.default.sep)) {
|
|
113
|
+
throw new AutoRigInputError(
|
|
114
|
+
`${label} escapes the working directory: ${original}`
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
return realDir;
|
|
118
|
+
}
|
|
90
119
|
function resolveOutputPath(outputPath) {
|
|
91
120
|
if (typeof outputPath !== "string" || outputPath.trim() === "") {
|
|
92
121
|
throw new AutoRigInputError("output path is empty");
|
|
@@ -106,14 +135,49 @@ function resolveOutputPath(outputPath) {
|
|
|
106
135
|
if (!stat.isDirectory()) {
|
|
107
136
|
throw new AutoRigInputError(`output parent is not a directory: ${dir}`);
|
|
108
137
|
}
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
138
|
+
const realDir = confineToWorkingDirectory(
|
|
139
|
+
root,
|
|
140
|
+
dir,
|
|
141
|
+
"output path",
|
|
142
|
+
outputPath
|
|
143
|
+
);
|
|
144
|
+
return import_node_path.default.join(realDir, import_node_path.default.basename(resolved));
|
|
145
|
+
}
|
|
146
|
+
function resolveOutputDir(dirPath) {
|
|
147
|
+
if (typeof dirPath !== "string" || dirPath.trim() === "") {
|
|
148
|
+
throw new AutoRigInputError("output dir is empty");
|
|
149
|
+
}
|
|
150
|
+
const root = process.cwd();
|
|
151
|
+
const resolved = import_node_path.default.resolve(root, dirPath);
|
|
152
|
+
let stat;
|
|
153
|
+
try {
|
|
154
|
+
stat = import_node_fs.default.statSync(resolved);
|
|
155
|
+
} catch {
|
|
156
|
+
throw new AutoRigInputError(`output dir not found: ${resolved}`);
|
|
157
|
+
}
|
|
158
|
+
if (!stat.isDirectory()) {
|
|
159
|
+
throw new AutoRigInputError(`output dir is not a directory: ${resolved}`);
|
|
160
|
+
}
|
|
161
|
+
return confineToWorkingDirectory(root, resolved, "output dir", dirPath);
|
|
162
|
+
}
|
|
163
|
+
function writeFileAtomic(outPath, data) {
|
|
164
|
+
const tmp = `${outPath}.${process.pid}.${Date.now()}.tmp`;
|
|
165
|
+
try {
|
|
166
|
+
import_node_fs.default.writeFileSync(tmp, data);
|
|
167
|
+
try {
|
|
168
|
+
import_node_fs.default.renameSync(tmp, outPath);
|
|
169
|
+
} catch (e) {
|
|
170
|
+
try {
|
|
171
|
+
import_node_fs.default.rmSync(tmp, { force: true });
|
|
172
|
+
} catch {
|
|
173
|
+
}
|
|
174
|
+
throw e;
|
|
175
|
+
}
|
|
176
|
+
} catch (e) {
|
|
112
177
|
throw new AutoRigInputError(
|
|
113
|
-
`
|
|
178
|
+
`write: ${e instanceof Error ? e.message : String(e)}`
|
|
114
179
|
);
|
|
115
180
|
}
|
|
116
|
-
return import_node_path.default.join(realDir, import_node_path.default.basename(resolved));
|
|
117
181
|
}
|
|
118
182
|
|
|
119
183
|
// src/node-images.ts
|
|
@@ -127,7 +191,12 @@ async function decodePng(filePath) {
|
|
|
127
191
|
);
|
|
128
192
|
}
|
|
129
193
|
const { data, info } = await pipeline.ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
130
|
-
return {
|
|
194
|
+
return {
|
|
195
|
+
width: info.width,
|
|
196
|
+
height: info.height,
|
|
197
|
+
rgba: data,
|
|
198
|
+
hasAlpha: metadata.hasAlpha ?? false
|
|
199
|
+
};
|
|
131
200
|
} catch (e) {
|
|
132
201
|
if (e instanceof AutoRigInputError) throw e;
|
|
133
202
|
const msg = e instanceof Error ? e.message : String(e);
|
|
@@ -149,15 +218,15 @@ async function renderAtlasToDataUri(crops, layout, quantizeColors) {
|
|
|
149
218
|
for (const crop of crops) byId.set(crop.id, crop);
|
|
150
219
|
const pad = layout.padding;
|
|
151
220
|
const composites = await Promise.all(
|
|
152
|
-
layout.placements.map(async (
|
|
153
|
-
const crop = byId.get(
|
|
221
|
+
layout.placements.map(async (placement2) => {
|
|
222
|
+
const crop = byId.get(placement2.id);
|
|
154
223
|
if (crop === void 0) {
|
|
155
224
|
throw new AutoRigInputError(
|
|
156
|
-
`no crop for atlas placement "${
|
|
225
|
+
`no crop for atlas placement "${placement2.id}"`
|
|
157
226
|
);
|
|
158
227
|
}
|
|
159
228
|
const input = pad > 0 ? await (0, import_sharp.default)(crop.buffer).extend({ right: pad, bottom: pad, extendWith: "copy" }).png().toBuffer() : crop.buffer;
|
|
160
|
-
return { input, left:
|
|
229
|
+
return { input, left: placement2.x, top: placement2.y };
|
|
161
230
|
})
|
|
162
231
|
);
|
|
163
232
|
const page = await (0, import_sharp.default)({
|
|
@@ -423,13 +492,13 @@ async function autoRigFromLayers(input) {
|
|
|
423
492
|
);
|
|
424
493
|
}
|
|
425
494
|
const partTextureAssignments = crops.map((crop) => {
|
|
426
|
-
const
|
|
427
|
-
if (
|
|
495
|
+
const placement2 = layout.placements.find((p) => p.id === crop.id);
|
|
496
|
+
if (placement2 === void 0) {
|
|
428
497
|
throw new Error(`auto-rig: no atlas placement for "${crop.id}"`);
|
|
429
498
|
}
|
|
430
499
|
return {
|
|
431
500
|
partId: crop.id,
|
|
432
|
-
uv: (0, import_editor2.uvRectFor)(
|
|
501
|
+
uv: (0, import_editor2.uvRectFor)(placement2, {
|
|
433
502
|
width: layout.pageWidth,
|
|
434
503
|
height: layout.pageHeight
|
|
435
504
|
})
|
|
@@ -437,19 +506,7 @@ async function autoRigFromLayers(input) {
|
|
|
437
506
|
});
|
|
438
507
|
doc.applyAtlas({ textures: [{ source: dataUri }], partTextureAssignments });
|
|
439
508
|
const finalModel = (0, import_format.parseIkiModel)(doc.getModel());
|
|
440
|
-
|
|
441
|
-
const tmp = `${outPath}.${process.pid}.${Date.now()}.tmp`;
|
|
442
|
-
import_node_fs2.default.writeFileSync(tmp, JSON.stringify(finalModel));
|
|
443
|
-
try {
|
|
444
|
-
import_node_fs2.default.renameSync(tmp, outPath);
|
|
445
|
-
} catch (e) {
|
|
446
|
-
try {
|
|
447
|
-
import_node_fs2.default.rmSync(tmp, { force: true });
|
|
448
|
-
} catch {
|
|
449
|
-
}
|
|
450
|
-
throw e;
|
|
451
|
-
}
|
|
452
|
-
});
|
|
509
|
+
writeFileAtomic(outPath, JSON.stringify(finalModel));
|
|
453
510
|
return {
|
|
454
511
|
ok: true,
|
|
455
512
|
path: outPath,
|
|
@@ -464,11 +521,533 @@ async function autoRigFromLayers(input) {
|
|
|
464
521
|
}
|
|
465
522
|
}
|
|
466
523
|
|
|
524
|
+
// src/compose.ts
|
|
525
|
+
var import_node_fs3 = __toESM(require("fs"));
|
|
526
|
+
var import_node_path4 = __toESM(require("path"));
|
|
527
|
+
var import_sharp2 = __toESM(require("sharp"));
|
|
528
|
+
|
|
529
|
+
// src/measure.ts
|
|
530
|
+
var import_node_fs2 = __toESM(require("fs"));
|
|
531
|
+
var import_node_path3 = __toESM(require("path"));
|
|
532
|
+
var IRIS_RATIO_MIN = 0.45;
|
|
533
|
+
var IRIS_RATIO_MAX = 0.72;
|
|
534
|
+
var EYE_ASPECT_MIN = 0.5;
|
|
535
|
+
var IRIS_OFFSET_MAX_X = 3;
|
|
536
|
+
var IRIS_OFFSET_MAX_Y = 10;
|
|
537
|
+
var EDGE_SOLID_MAX = 0.5;
|
|
538
|
+
var LASH_CENTRE_TOL_FRAC = 0.03;
|
|
539
|
+
var EDGE_RUN_MIN_PX = 40;
|
|
540
|
+
var FLAT_CUT_MAX_FRAC = 0.1;
|
|
541
|
+
var FLAT_CUT_MIN_PX = 40;
|
|
542
|
+
var FLAT_CUT_ALPHA_ABOVE = 120;
|
|
543
|
+
var FLAT_CUT_ALPHA_BELOW = 140;
|
|
544
|
+
async function layerStats(filePath) {
|
|
545
|
+
const { width: W, height: H, rgba } = await decodePng(filePath);
|
|
546
|
+
const alpha = (x, y) => rgba[(y * W + x) * 4 + 3];
|
|
547
|
+
let minX = W;
|
|
548
|
+
let minY = H;
|
|
549
|
+
let maxX = -1;
|
|
550
|
+
let maxY = -1;
|
|
551
|
+
let sumX = 0;
|
|
552
|
+
let sumY = 0;
|
|
553
|
+
let n = 0;
|
|
554
|
+
for (let y = 0; y < H; y++) {
|
|
555
|
+
for (let x = 0; x < W; x++) {
|
|
556
|
+
if (alpha(x, y) > 8) {
|
|
557
|
+
if (x < minX) minX = x;
|
|
558
|
+
if (x > maxX) maxX = x;
|
|
559
|
+
if (y < minY) minY = y;
|
|
560
|
+
if (y > maxY) maxY = y;
|
|
561
|
+
sumX += x;
|
|
562
|
+
sumY += y;
|
|
563
|
+
n++;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
if (maxX < 0) return null;
|
|
568
|
+
const edge = (pts) => pts.filter((v) => v > 200).length / pts.length;
|
|
569
|
+
const top = [];
|
|
570
|
+
const bottom = [];
|
|
571
|
+
const left = [];
|
|
572
|
+
const right = [];
|
|
573
|
+
for (let x = minX; x <= maxX; x++) {
|
|
574
|
+
top.push(alpha(x, minY));
|
|
575
|
+
bottom.push(alpha(x, maxY));
|
|
576
|
+
}
|
|
577
|
+
for (let y = minY; y <= maxY; y++) {
|
|
578
|
+
left.push(alpha(minX, y));
|
|
579
|
+
right.push(alpha(maxX, y));
|
|
580
|
+
}
|
|
581
|
+
let flatCutRun = 0;
|
|
582
|
+
let flatCutY = -1;
|
|
583
|
+
for (let y = minY + 1; y <= maxY; y++) {
|
|
584
|
+
let run = 0;
|
|
585
|
+
for (let x = minX; x <= maxX; x++) {
|
|
586
|
+
if (alpha(x, y - 1) < FLAT_CUT_ALPHA_ABOVE && alpha(x, y) > FLAT_CUT_ALPHA_BELOW) {
|
|
587
|
+
run++;
|
|
588
|
+
if (run > flatCutRun) {
|
|
589
|
+
flatCutRun = run;
|
|
590
|
+
flatCutY = y;
|
|
591
|
+
}
|
|
592
|
+
} else {
|
|
593
|
+
run = 0;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
return {
|
|
598
|
+
w: maxX - minX + 1,
|
|
599
|
+
h: maxY - minY + 1,
|
|
600
|
+
flatCutRun,
|
|
601
|
+
flatCutY,
|
|
602
|
+
bboxCx: (minX + maxX) / 2,
|
|
603
|
+
bboxCy: (minY + maxY) / 2,
|
|
604
|
+
massCx: sumX / n,
|
|
605
|
+
massCy: sumY / n,
|
|
606
|
+
marginTop: minY,
|
|
607
|
+
marginBottom: H - 1 - maxY,
|
|
608
|
+
marginLeft: minX,
|
|
609
|
+
marginRight: W - 1 - maxX,
|
|
610
|
+
edgeTop: edge(top),
|
|
611
|
+
edgeBottom: edge(bottom),
|
|
612
|
+
edgeLeft: edge(left),
|
|
613
|
+
edgeRight: edge(right),
|
|
614
|
+
canvasW: W,
|
|
615
|
+
canvasH: H
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
var pct = (v) => `${(v * 100).toFixed(0)}%`;
|
|
619
|
+
async function measureDir(absDir) {
|
|
620
|
+
const files = import_node_fs2.default.readdirSync(absDir).filter((f) => f.endsWith(".png") && f !== "preview.png").sort();
|
|
621
|
+
if (files.length === 0) {
|
|
622
|
+
throw new AutoRigInputError(`no role layers in ${absDir}`);
|
|
623
|
+
}
|
|
624
|
+
if (files.length > MAX_LAYERS) {
|
|
625
|
+
throw new AutoRigInputError(
|
|
626
|
+
`too many layers in ${absDir}: ${files.length} > ${MAX_LAYERS}`
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
const layers = {};
|
|
630
|
+
const empty = [];
|
|
631
|
+
for (const f of files) {
|
|
632
|
+
const role = import_node_path3.default.basename(f, ".png");
|
|
633
|
+
const m = await layerStats(import_node_path3.default.join(absDir, f));
|
|
634
|
+
if (!m) {
|
|
635
|
+
empty.push(role);
|
|
636
|
+
continue;
|
|
637
|
+
}
|
|
638
|
+
layers[role] = m;
|
|
639
|
+
}
|
|
640
|
+
const warnings = [];
|
|
641
|
+
for (const [role, m] of Object.entries(layers)) {
|
|
642
|
+
const edges = [
|
|
643
|
+
["top", m.edgeTop, m.w, m.marginTop],
|
|
644
|
+
["left", m.edgeLeft, m.h, m.marginLeft],
|
|
645
|
+
["right", m.edgeRight, m.h, m.marginRight]
|
|
646
|
+
];
|
|
647
|
+
if (role !== "body")
|
|
648
|
+
edges.push(["bottom", m.edgeBottom, m.w, m.marginBottom]);
|
|
649
|
+
for (const [side, v, span, margin] of edges) {
|
|
650
|
+
if (v > EDGE_SOLID_MAX && v * span >= EDGE_RUN_MIN_PX) {
|
|
651
|
+
const remedy = margin === 0 ? (
|
|
652
|
+
// margin 0 is consistent with a clipped placement AND with art
|
|
653
|
+
// already cropped flush that happens to sit on the boundary, and
|
|
654
|
+
// the flattened layer cannot separate them — so name the free
|
|
655
|
+
// move rather than the cause. If moving it inward leaves the
|
|
656
|
+
// edge opaque, the drawing is the one at fault.
|
|
657
|
+
`it sits flush against the canvas ${side}, which a clipped placement and already-cropped art both produce. Move it inward first \u2014 retune layout.${role}.cx/cy/w, free \u2014 and remeasure; regenerate only if the edge is still opaque with margin to spare.`
|
|
658
|
+
) : `its own drawing runs to the frame ${margin} px inside the canvas \u2014 regenerate that part with empty margin on that side. Billed.`;
|
|
659
|
+
warnings.push(
|
|
660
|
+
`${role}: ${pct(v)} of its ${side} edge is opaque \u2014 the art is cut off there, which shows as a straight seam once the head turns. Cause: ${remedy}`
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
for (const [role, m] of Object.entries(layers)) {
|
|
666
|
+
if (role === "body") continue;
|
|
667
|
+
if (m.flatCutRun > FLAT_CUT_MAX_FRAC * m.w && m.flatCutRun >= FLAT_CUT_MIN_PX) {
|
|
668
|
+
warnings.push(
|
|
669
|
+
`${role}: ${m.flatCutRun}px of straight flat edge at y=${m.flatCutY} (${pct(m.flatCutRun / m.w)} of its width) \u2014 the source art is cut through there. It hides while the head faces front and opens into a seam on turn. Regenerate this part with the whole subject inside the frame.`
|
|
670
|
+
);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
for (const side of ["L", "R"]) {
|
|
674
|
+
const eye = layers[`eye_${side}`];
|
|
675
|
+
const iris = layers[`iris_${side}`];
|
|
676
|
+
const lash = layers[`lash_${side}`];
|
|
677
|
+
if (!eye) continue;
|
|
678
|
+
const aspect = eye.h / eye.w;
|
|
679
|
+
if (aspect < EYE_ASPECT_MIN) {
|
|
680
|
+
warnings.push(
|
|
681
|
+
`eye_${side}: sclera aspect h/w=${aspect.toFixed(2)} is flatter than ${EYE_ASPECT_MIN} \u2014 a round iris cannot sit inside it. Free fix first: set layout.eye_${side}.h and layout.lash_${side}.h to ${Math.ceil(eye.w * EYE_ASPECT_MIN)} (both, or the fold tears) \u2014 stretching a flat white lens is invisible. Regenerate the eyewhite taller only if that distorts the lash.`
|
|
682
|
+
);
|
|
683
|
+
}
|
|
684
|
+
if (iris) {
|
|
685
|
+
const ratio = iris.w / eye.w;
|
|
686
|
+
if (ratio < IRIS_RATIO_MIN || ratio > IRIS_RATIO_MAX) {
|
|
687
|
+
warnings.push(
|
|
688
|
+
`iris_${side}: width is ${pct(ratio)} of the sclera (target ${IRIS_RATIO_MIN}-${IRIS_RATIO_MAX}) \u2014 retune layout.iris_${side}.w (keep it a fraction of the eye width), no regeneration needed.`
|
|
689
|
+
);
|
|
690
|
+
}
|
|
691
|
+
const dx = iris.bboxCx - eye.massCx;
|
|
692
|
+
const dy = iris.bboxCy - eye.massCy;
|
|
693
|
+
if (Math.abs(dx) > IRIS_OFFSET_MAX_X || Math.abs(dy) > IRIS_OFFSET_MAX_Y) {
|
|
694
|
+
warnings.push(
|
|
695
|
+
`iris_${side}: sits (${dx.toFixed(1)}, ${dy.toFixed(1)}) px from the white's centre of mass \u2014 retune layout.iris_${side}.cx/cy. The sclera's bbox centre is NOT its visual centre when the lash flick stretches the box.`
|
|
696
|
+
);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
if (lash) {
|
|
700
|
+
const dx = lash.bboxCx - eye.bboxCx;
|
|
701
|
+
const dTop = lash.marginTop - eye.marginTop;
|
|
702
|
+
if (Math.abs(dx) > eye.w * LASH_CENTRE_TOL_FRAC || Math.abs(dTop) > 0.5) {
|
|
703
|
+
warnings.push(
|
|
704
|
+
`lash_${side}: centre is ${dx.toFixed(1)} px and top edge ${dTop.toFixed(1)} px off eye_${side}. They are split from one source and MUST share cx/cy/w in layout, or the blink fold tears. Retune to match.`
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
for (const [role, why] of [
|
|
710
|
+
["body", "without it the character reads as a floating head on head-turn"],
|
|
711
|
+
["hair_back", "without it the silhouette is flat behind the face"]
|
|
712
|
+
]) {
|
|
713
|
+
if (layers[role] === void 0) warnings.push(`${role}: missing \u2014 ${why}.`);
|
|
714
|
+
}
|
|
715
|
+
return { layers, empty, warnings };
|
|
716
|
+
}
|
|
717
|
+
async function measureLayers(input) {
|
|
718
|
+
try {
|
|
719
|
+
const layersDir = resolveInputDir(input.layersDir);
|
|
720
|
+
const report = await measureDir(layersDir);
|
|
721
|
+
return {
|
|
722
|
+
ok: true,
|
|
723
|
+
layersDir,
|
|
724
|
+
...report,
|
|
725
|
+
passed: report.warnings.length === 0
|
|
726
|
+
};
|
|
727
|
+
} catch (err) {
|
|
728
|
+
if (err instanceof AutoRigInputError)
|
|
729
|
+
return { ok: false, error: err.message };
|
|
730
|
+
throw err;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
function formatMeasureReport(result) {
|
|
734
|
+
const lines = [
|
|
735
|
+
`# layers (${result.layersDir})`,
|
|
736
|
+
"",
|
|
737
|
+
"role size bbox-centre mass-centre margins t/b/l/r"
|
|
738
|
+
];
|
|
739
|
+
for (const role of [...Object.keys(result.layers), ...result.empty].sort()) {
|
|
740
|
+
const m = result.layers[role];
|
|
741
|
+
if (m === void 0) {
|
|
742
|
+
lines.push(`${role.padEnd(13)} EMPTY (fully transparent)`);
|
|
743
|
+
continue;
|
|
744
|
+
}
|
|
745
|
+
lines.push(
|
|
746
|
+
`${role.padEnd(13)} ${`${m.w}x${m.h}`.padEnd(11)} ${`${m.bboxCx.toFixed(0)},${m.bboxCy.toFixed(0)}`.padEnd(14)} ${`${m.massCx.toFixed(0)},${m.massCy.toFixed(0)}`.padEnd(13)} ${m.marginTop}/${m.marginBottom}/${m.marginLeft}/${m.marginRight}`
|
|
747
|
+
);
|
|
748
|
+
}
|
|
749
|
+
lines.push("", "# checks", "");
|
|
750
|
+
if (result.warnings.length === 0) {
|
|
751
|
+
lines.push("all geometry checks passed");
|
|
752
|
+
} else {
|
|
753
|
+
for (const w of result.warnings) lines.push(`- ${w}`);
|
|
754
|
+
}
|
|
755
|
+
return lines.join("\n");
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// src/compose.ts
|
|
759
|
+
var CANVAS = 1100;
|
|
760
|
+
var EYE_W = 128;
|
|
761
|
+
var IRIS_W = Math.round(EYE_W * 0.5625);
|
|
762
|
+
var EYEWHITE_SRC = "eyewhite.png";
|
|
763
|
+
var EYE_LASH_LUMA = 120;
|
|
764
|
+
var LASH_KEEP_FRACTION = 0.5;
|
|
765
|
+
var DEFAULT_LAYOUT = {
|
|
766
|
+
// Back hair and body sit behind the face. Both are OPTIONAL: a parts dir
|
|
767
|
+
// without them still composes (head-only character).
|
|
768
|
+
hair_back: { src: "hair_back.png", cx: 550, cy: 523, w: 800, optional: true },
|
|
769
|
+
// The torso, cut off by the canvas bottom. It rides its own `bodyDeformer`: a
|
|
770
|
+
// light share of the head turn and half its breath bob, so the character is
|
|
771
|
+
// not a floating head.
|
|
772
|
+
body: { src: "body.png", cx: 550, cy: 1017, w: 840, optional: true },
|
|
773
|
+
face: { src: "face.png", cx: 550, cy: 475, w: 400 },
|
|
774
|
+
mouth: { src: "mouth.png", cx: 550, cy: 619, w: 68 },
|
|
775
|
+
// Cross-fades with `mouth` on ParamMouthOpenY (opacity, not scaleY) once the
|
|
776
|
+
// auto-rig sees both roles. Same cx/w as `mouth` so the lip width matches;
|
|
777
|
+
// its top edge (not center) lines up with the closed mouth's top edge since
|
|
778
|
+
// the mouth opens downward from a fixed upper lip — hence the +2 cy nudge
|
|
779
|
+
// rather than sharing cy outright. Optional: composes fine without it.
|
|
780
|
+
mouth_open: {
|
|
781
|
+
src: "mouth_open.png",
|
|
782
|
+
cx: 550,
|
|
783
|
+
cy: 621,
|
|
784
|
+
w: 68,
|
|
785
|
+
optional: true
|
|
786
|
+
},
|
|
787
|
+
// eye_* (sclera) and lash_* share the eyewhite's cropped frame via noTrim (so
|
|
788
|
+
// they are NOT re-bboxed independently): the upper lash stays anchored ABOVE
|
|
789
|
+
// the sclera center, so on blink it folds DOWN over the eye like the sample
|
|
790
|
+
// model instead of the whole eye shrinking in place. Same cx/cy/w.
|
|
791
|
+
eye_L: { src: "eyewhite_sclera.png", cx: 657, cy: 475, w: EYE_W, mirror: true, noTrim: true },
|
|
792
|
+
// prettier-ignore
|
|
793
|
+
eye_R: { src: "eyewhite_sclera.png", cx: 443, cy: 475, w: EYE_W, mirror: false, noTrim: true },
|
|
794
|
+
// prettier-ignore
|
|
795
|
+
iris_L: { src: "iris.png", cx: 653, cy: 475, w: IRIS_W, mirror: false },
|
|
796
|
+
iris_R: { src: "iris.png", cx: 447, cy: 475, w: IRIS_W, mirror: false },
|
|
797
|
+
lash_L: {
|
|
798
|
+
src: "eyewhite_lash.png",
|
|
799
|
+
cx: 657,
|
|
800
|
+
cy: 475,
|
|
801
|
+
w: EYE_W,
|
|
802
|
+
mirror: true,
|
|
803
|
+
noTrim: true
|
|
804
|
+
},
|
|
805
|
+
lash_R: { src: "eyewhite_lash.png", cx: 443, cy: 475, w: EYE_W, mirror: false, noTrim: true },
|
|
806
|
+
// prettier-ignore
|
|
807
|
+
brow_L: { src: "brow.png", cx: 645, cy: 405, w: 135, mirror: false },
|
|
808
|
+
brow_R: { src: "brow.png", cx: 455, cy: 405, w: 135, mirror: true },
|
|
809
|
+
hair_front: { src: "hair_front.png", cx: 550, cy: 425, w: 660 }
|
|
810
|
+
};
|
|
811
|
+
var ORDER = [
|
|
812
|
+
"hair_back",
|
|
813
|
+
"body",
|
|
814
|
+
"face",
|
|
815
|
+
"mouth",
|
|
816
|
+
"mouth_open",
|
|
817
|
+
"eye_L",
|
|
818
|
+
"eye_R",
|
|
819
|
+
"iris_L",
|
|
820
|
+
"iris_R",
|
|
821
|
+
"lash_L",
|
|
822
|
+
"lash_R",
|
|
823
|
+
"brow_L",
|
|
824
|
+
"brow_R",
|
|
825
|
+
"hair_front"
|
|
826
|
+
];
|
|
827
|
+
function resolveLayout(overrides) {
|
|
828
|
+
const resolved = { ...DEFAULT_LAYOUT };
|
|
829
|
+
if (overrides === void 0) return resolved;
|
|
830
|
+
for (const [role, override] of Object.entries(overrides)) {
|
|
831
|
+
if (!Object.prototype.hasOwnProperty.call(DEFAULT_LAYOUT, role)) {
|
|
832
|
+
throw new AutoRigInputError(
|
|
833
|
+
`layout.${role}: unknown role \u2014 expected one of ${Object.keys(DEFAULT_LAYOUT).join(", ")}`
|
|
834
|
+
);
|
|
835
|
+
}
|
|
836
|
+
if (override === void 0) continue;
|
|
837
|
+
const next = { ...resolved[role] };
|
|
838
|
+
for (const field of ["cx", "cy"]) {
|
|
839
|
+
const value = override[field];
|
|
840
|
+
if (value === void 0) continue;
|
|
841
|
+
if (!Number.isFinite(value)) {
|
|
842
|
+
throw new AutoRigInputError(
|
|
843
|
+
`layout.${role}.${field} must be a finite number, got ${String(value)}`
|
|
844
|
+
);
|
|
845
|
+
}
|
|
846
|
+
next[field] = value;
|
|
847
|
+
}
|
|
848
|
+
for (const field of ["w", "h"]) {
|
|
849
|
+
const value = override[field];
|
|
850
|
+
if (value === void 0) continue;
|
|
851
|
+
if (!Number.isInteger(value) || value < 1 || value > CANVAS) {
|
|
852
|
+
throw new AutoRigInputError(
|
|
853
|
+
`layout.${role}.${field} must be an integer in 1..${CANVAS}, got ${String(value)}`
|
|
854
|
+
);
|
|
855
|
+
}
|
|
856
|
+
next[field] = value;
|
|
857
|
+
}
|
|
858
|
+
resolved[role] = next;
|
|
859
|
+
}
|
|
860
|
+
return resolved;
|
|
861
|
+
}
|
|
862
|
+
function keyWhiteToAlpha(rgba) {
|
|
863
|
+
const keyed = Buffer.from(rgba);
|
|
864
|
+
for (let i = 0; i < keyed.length; i += 4) {
|
|
865
|
+
if (keyed[i] > 238 && keyed[i + 1] > 238 && keyed[i + 2] > 238) {
|
|
866
|
+
keyed[i + 3] = 0;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
return keyed;
|
|
870
|
+
}
|
|
871
|
+
async function partBuffer(role, cfg, partsDir, inMemory) {
|
|
872
|
+
let img;
|
|
873
|
+
if (inMemory !== void 0) {
|
|
874
|
+
img = (0, import_sharp2.default)(inMemory);
|
|
875
|
+
} else {
|
|
876
|
+
const srcPath = import_node_path4.default.join(partsDir, cfg.src);
|
|
877
|
+
if (!import_node_fs3.default.existsSync(srcPath)) {
|
|
878
|
+
if (cfg.optional) return null;
|
|
879
|
+
throw new AutoRigInputError(
|
|
880
|
+
`missing part source for role "${role}": ${srcPath}`
|
|
881
|
+
);
|
|
882
|
+
}
|
|
883
|
+
const png = await decodePng(srcPath);
|
|
884
|
+
img = (0, import_sharp2.default)(png.hasAlpha ? png.rgba : keyWhiteToAlpha(png.rgba), {
|
|
885
|
+
raw: { width: png.width, height: png.height, channels: 4 }
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
if (!cfg.noTrim) img = img.trim({ threshold: 12 });
|
|
889
|
+
if (cfg.mirror) img = img.flop();
|
|
890
|
+
const trimmed = await img.png().toBuffer({ resolveWithObject: true });
|
|
891
|
+
if (cfg.h === void 0) {
|
|
892
|
+
const scaledH = Math.round(
|
|
893
|
+
trimmed.info.height * cfg.w / trimmed.info.width
|
|
894
|
+
);
|
|
895
|
+
if (scaledH > CANVAS) {
|
|
896
|
+
throw new AutoRigInputError(
|
|
897
|
+
`layout.${role}.w: resized part ${cfg.w}x${scaledH} exceeds the ${CANVAS} canvas`
|
|
898
|
+
);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
const resized = await (0, import_sharp2.default)(trimmed.data).resize(
|
|
902
|
+
cfg.h === void 0 ? { width: cfg.w } : { width: cfg.w, height: cfg.h, fit: "fill" }
|
|
903
|
+
).png().toBuffer({ resolveWithObject: true });
|
|
904
|
+
return {
|
|
905
|
+
buf: resized.data,
|
|
906
|
+
w: resized.info.width,
|
|
907
|
+
h: resized.info.height
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
function placement(role, cfg, w, h) {
|
|
911
|
+
const left = Math.round(cfg.cx - w / 2);
|
|
912
|
+
const top = Math.round(cfg.cy - h / 2);
|
|
913
|
+
if (left + w <= 0 || top + h <= 0 || left >= CANVAS || top >= CANVAS) {
|
|
914
|
+
throw new AutoRigInputError(
|
|
915
|
+
`layout.${role}.cx/cy: the placed part (${w}x${h} at ${left},${top}) falls entirely outside the ${CANVAS} canvas`
|
|
916
|
+
);
|
|
917
|
+
}
|
|
918
|
+
return { left, top };
|
|
919
|
+
}
|
|
920
|
+
function blankCanvas() {
|
|
921
|
+
return (0, import_sharp2.default)({
|
|
922
|
+
create: {
|
|
923
|
+
width: CANVAS,
|
|
924
|
+
height: CANVAS,
|
|
925
|
+
channels: 4,
|
|
926
|
+
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
|
927
|
+
}
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
async function prepEyeSplit(partsDir) {
|
|
931
|
+
const srcPath = import_node_path4.default.join(partsDir, EYEWHITE_SRC);
|
|
932
|
+
if (!import_node_fs3.default.existsSync(srcPath)) {
|
|
933
|
+
throw new AutoRigInputError(`missing eyewhite source: ${srcPath}`);
|
|
934
|
+
}
|
|
935
|
+
const { width: W, height: H, rgba: data } = await decodePng(srcPath);
|
|
936
|
+
let minX = W;
|
|
937
|
+
let minY = H;
|
|
938
|
+
let maxX = -1;
|
|
939
|
+
let maxY = -1;
|
|
940
|
+
for (let y = 0; y < H; y++) {
|
|
941
|
+
for (let x = 0; x < W; x++) {
|
|
942
|
+
if (data[(y * W + x) * 4 + 3] > 8) {
|
|
943
|
+
if (x < minX) minX = x;
|
|
944
|
+
if (x > maxX) maxX = x;
|
|
945
|
+
if (y < minY) minY = y;
|
|
946
|
+
if (y > maxY) maxY = y;
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
if (maxX < 0) {
|
|
951
|
+
throw new AutoRigInputError(`eyewhite is fully transparent: ${srcPath}`);
|
|
952
|
+
}
|
|
953
|
+
const lashCutoffY = minY + LASH_KEEP_FRACTION * (maxY - minY + 1);
|
|
954
|
+
const sclera = Buffer.from(data);
|
|
955
|
+
const lash = Buffer.from(data);
|
|
956
|
+
for (let y = 0; y < H; y++) {
|
|
957
|
+
for (let x = 0; x < W; x++) {
|
|
958
|
+
const i = (y * W + x) * 4;
|
|
959
|
+
const lum = 0.299 * data[i] + 0.587 * data[i + 1] + 0.114 * data[i + 2];
|
|
960
|
+
const isDark = data[i + 3] > 0 && lum < EYE_LASH_LUMA;
|
|
961
|
+
if (isDark) sclera[i] = sclera[i + 1] = sclera[i + 2] = 255;
|
|
962
|
+
if (!(isDark && y <= lashCutoffY)) lash[i + 3] = 0;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
const region = {
|
|
966
|
+
x: minX,
|
|
967
|
+
y: minY,
|
|
968
|
+
w: maxX - minX + 1,
|
|
969
|
+
h: maxY - minY + 1
|
|
970
|
+
};
|
|
971
|
+
return {
|
|
972
|
+
sclera: await cropToBuffer(sclera, W, H, region),
|
|
973
|
+
lash: await cropToBuffer(lash, W, H, region)
|
|
974
|
+
};
|
|
975
|
+
}
|
|
976
|
+
async function composeLayersFromParts(input) {
|
|
977
|
+
try {
|
|
978
|
+
const outDir = resolveOutputDir(input.outDir);
|
|
979
|
+
const partsDir = resolveInputDir(input.partsDir);
|
|
980
|
+
if (import_node_fs3.default.realpathSync(partsDir) === outDir) {
|
|
981
|
+
throw new AutoRigInputError(
|
|
982
|
+
`partsDir and outDir resolve to the same directory (${outDir}): composing would overwrite the source parts`
|
|
983
|
+
);
|
|
984
|
+
}
|
|
985
|
+
const layout = resolveLayout(input.layout);
|
|
986
|
+
const split = await prepEyeSplit(partsDir);
|
|
987
|
+
const splitSources = /* @__PURE__ */ new Map([
|
|
988
|
+
["eyewhite_sclera.png", split.sclera],
|
|
989
|
+
["eyewhite_lash.png", split.lash]
|
|
990
|
+
]);
|
|
991
|
+
const layers = [];
|
|
992
|
+
const skipped = [];
|
|
993
|
+
const preview = [];
|
|
994
|
+
for (const role of ORDER) {
|
|
995
|
+
const cfg = layout[role];
|
|
996
|
+
const part = await partBuffer(
|
|
997
|
+
role,
|
|
998
|
+
cfg,
|
|
999
|
+
partsDir,
|
|
1000
|
+
splitSources.get(cfg.src)
|
|
1001
|
+
);
|
|
1002
|
+
if (part === null) {
|
|
1003
|
+
skipped.push(role);
|
|
1004
|
+
import_node_fs3.default.rmSync(import_node_path4.default.join(outDir, `${role}.png`), { force: true });
|
|
1005
|
+
continue;
|
|
1006
|
+
}
|
|
1007
|
+
const { left, top } = placement(role, cfg, part.w, part.h);
|
|
1008
|
+
const layer = await blankCanvas().composite([{ input: part.buf, left, top }]).png().toBuffer();
|
|
1009
|
+
const outPath = import_node_path4.default.join(outDir, `${role}.png`);
|
|
1010
|
+
writeFileAtomic(outPath, layer);
|
|
1011
|
+
layers.push({
|
|
1012
|
+
role,
|
|
1013
|
+
path: outPath,
|
|
1014
|
+
width: part.w,
|
|
1015
|
+
height: part.h,
|
|
1016
|
+
left,
|
|
1017
|
+
top
|
|
1018
|
+
});
|
|
1019
|
+
preview.push({ input: part.buf, left, top });
|
|
1020
|
+
}
|
|
1021
|
+
const previewPng = await (0, import_sharp2.default)({
|
|
1022
|
+
create: {
|
|
1023
|
+
width: CANVAS,
|
|
1024
|
+
height: CANVAS,
|
|
1025
|
+
channels: 4,
|
|
1026
|
+
background: { r: 245, g: 245, b: 248, alpha: 1 }
|
|
1027
|
+
}
|
|
1028
|
+
}).composite(preview).png().toBuffer();
|
|
1029
|
+
const previewPath = import_node_path4.default.join(outDir, "preview.png");
|
|
1030
|
+
writeFileAtomic(previewPath, previewPng);
|
|
1031
|
+
return {
|
|
1032
|
+
ok: true,
|
|
1033
|
+
outDir,
|
|
1034
|
+
layers,
|
|
1035
|
+
skipped,
|
|
1036
|
+
preview: previewPath,
|
|
1037
|
+
measure: await measureDir(outDir)
|
|
1038
|
+
};
|
|
1039
|
+
} catch (err) {
|
|
1040
|
+
if (err instanceof AutoRigInputError)
|
|
1041
|
+
return { ok: false, error: err.message };
|
|
1042
|
+
throw err;
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
|
|
467
1046
|
// src/server.ts
|
|
468
1047
|
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
469
1048
|
var import_zod = require("zod");
|
|
470
1049
|
function createIkiMcpServer() {
|
|
471
|
-
const server = new import_mcp.McpServer({ name: "iki", version: "0.
|
|
1050
|
+
const server = new import_mcp.McpServer({ name: "iki", version: "0.5.0" });
|
|
472
1051
|
server.registerTool(
|
|
473
1052
|
"validate_iki",
|
|
474
1053
|
{
|
|
@@ -566,14 +1145,87 @@ function createIkiMcpServer() {
|
|
|
566
1145
|
}
|
|
567
1146
|
}
|
|
568
1147
|
);
|
|
1148
|
+
server.registerTool(
|
|
1149
|
+
"compose_layers_from_parts",
|
|
1150
|
+
{
|
|
1151
|
+
description: "Composes AI-generated part PNGs into canvas-aligned, role-named PNG layers on disk, ready for auto_rig_from_layers (the eyewhite split, alpha-trim/white-key, and placement pipeline the character-generation skill needs), with the same geometry report measure_layers returns standalone included inline. face, mouth, eyewhite, iris, brow, hair_front are required; hair_back, body, mouth_open are optional.",
|
|
1152
|
+
inputSchema: {
|
|
1153
|
+
partsDir: import_zod.z.string().describe(
|
|
1154
|
+
"Directory of the source part PNGs (resolved against cwd)."
|
|
1155
|
+
),
|
|
1156
|
+
outDir: import_zod.z.string().describe(
|
|
1157
|
+
"Existing directory to write the role layer PNGs + preview.png into (resolved against cwd; must already exist; confined to the working directory). Reused across runs: a role this run skips has its stale PNG from an earlier run deleted."
|
|
1158
|
+
),
|
|
1159
|
+
layout: import_zod.z.record(
|
|
1160
|
+
import_zod.z.string(),
|
|
1161
|
+
import_zod.z.object({
|
|
1162
|
+
cx: import_zod.z.number(),
|
|
1163
|
+
cy: import_zod.z.number(),
|
|
1164
|
+
w: import_zod.z.number(),
|
|
1165
|
+
h: import_zod.z.number()
|
|
1166
|
+
}).partial()
|
|
1167
|
+
).optional().describe(
|
|
1168
|
+
"Per-role override merged over the built-in defaults, keyed by role \u2014 hair_back, body, face, mouth, mouth_open, eye_L, eye_R, iris_L, iris_R, lash_L, lash_R, brow_L, brow_R, hair_front \u2014 e.g. `{ eye_L: { cx: 660 } }`. `w` and `h` are integers in 1..1100; omit `h` to keep the part's own aspect, set it to stretch (set it on a sclera and its lash together, or the blink fold tears)."
|
|
1169
|
+
)
|
|
1170
|
+
}
|
|
1171
|
+
},
|
|
1172
|
+
async (args) => {
|
|
1173
|
+
try {
|
|
1174
|
+
const r = await composeLayersFromParts(args);
|
|
1175
|
+
const text = r.ok ? [
|
|
1176
|
+
...r.layers.map((l) => l.path),
|
|
1177
|
+
formatMeasureReport({ ...r.measure, layersDir: r.outDir })
|
|
1178
|
+
].join("\n") : `INVALID: ${r.error}`;
|
|
1179
|
+
return { content: [{ type: "text", text }], structuredContent: r };
|
|
1180
|
+
} catch (err) {
|
|
1181
|
+
const error = err instanceof Error ? err.message : String(err);
|
|
1182
|
+
return {
|
|
1183
|
+
content: [{ type: "text", text: `Unexpected error: ${error}` }],
|
|
1184
|
+
structuredContent: { ok: false, error },
|
|
1185
|
+
isError: true
|
|
1186
|
+
};
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
);
|
|
1190
|
+
server.registerTool(
|
|
1191
|
+
"measure_layers",
|
|
1192
|
+
{
|
|
1193
|
+
description: "Reports read-only geometry checks over an already-composed layers directory \u2014 the same checks compose_layers_from_parts returns inline (iris ratio/offset, eye aspect, cropped/cut edges, missing optional roles). Use to re-check a layers dir without recomposing.",
|
|
1194
|
+
inputSchema: {
|
|
1195
|
+
layersDir: import_zod.z.string().describe(
|
|
1196
|
+
"Directory of role-named layer PNGs (resolved against cwd)."
|
|
1197
|
+
)
|
|
1198
|
+
}
|
|
1199
|
+
},
|
|
1200
|
+
async ({ layersDir }) => {
|
|
1201
|
+
try {
|
|
1202
|
+
const r = await measureLayers({ layersDir });
|
|
1203
|
+
const text = r.ok ? formatMeasureReport(r) : `INVALID: ${r.error}`;
|
|
1204
|
+
return {
|
|
1205
|
+
content: [{ type: "text", text }],
|
|
1206
|
+
structuredContent: { ...r }
|
|
1207
|
+
};
|
|
1208
|
+
} catch (err) {
|
|
1209
|
+
const error = err instanceof Error ? err.message : String(err);
|
|
1210
|
+
return {
|
|
1211
|
+
content: [{ type: "text", text: `Unexpected error: ${error}` }],
|
|
1212
|
+
structuredContent: { ok: false, error },
|
|
1213
|
+
isError: true
|
|
1214
|
+
};
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
);
|
|
569
1218
|
return server;
|
|
570
1219
|
}
|
|
571
1220
|
// Annotate the CommonJS export names for ESM import in node:
|
|
572
1221
|
0 && (module.exports = {
|
|
573
1222
|
autoRigFromLayers,
|
|
1223
|
+
composeLayersFromParts,
|
|
574
1224
|
createIkiMcpServer,
|
|
575
1225
|
describeIki,
|
|
1226
|
+
formatMeasureReport,
|
|
576
1227
|
listStandardParameters,
|
|
1228
|
+
measureLayers,
|
|
577
1229
|
validateIki
|
|
578
1230
|
});
|
|
579
1231
|
//# sourceMappingURL=index.js.map
|