@ikijs/mcp 0.23.2 → 0.24.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 +20 -10
- package/dist/{chunk-SXLILLB6.mjs → chunk-GEXOSC5O.mjs} +528 -6
- package/dist/chunk-GEXOSC5O.mjs.map +1 -0
- package/dist/cli.js +529 -5
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +4 -1
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +70 -1
- package/dist/index.d.ts +70 -1
- package/dist/index.js +528 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -1
- package/dist/render-page.global.js +1250 -0
- package/package.json +3 -2
- package/dist/chunk-SXLILLB6.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -39,10 +39,15 @@ __export(index_exports, {
|
|
|
39
39
|
listStandardParameters: () => listStandardParameters,
|
|
40
40
|
measureLayers: () => measureLayers,
|
|
41
41
|
measureTurnReference: () => measureTurnReference,
|
|
42
|
+
renderPoses: () => renderPoses,
|
|
42
43
|
validateIki: () => validateIki
|
|
43
44
|
});
|
|
44
45
|
module.exports = __toCommonJS(index_exports);
|
|
45
46
|
|
|
47
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_postcss@8.5.15_supports-color@7.2.0_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js
|
|
48
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
49
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
50
|
+
|
|
46
51
|
// src/tools.ts
|
|
47
52
|
var import_node_path2 = __toESM(require("path"));
|
|
48
53
|
var import_format = require("@ikijs/format");
|
|
@@ -78,18 +83,18 @@ function rejectEmptyOrUrl(inputPath, noun, kind) {
|
|
|
78
83
|
);
|
|
79
84
|
}
|
|
80
85
|
}
|
|
81
|
-
function resolveInputPath(inputPath) {
|
|
82
|
-
rejectEmptyOrUrl(inputPath,
|
|
86
|
+
function resolveInputPath(inputPath, what = "layer") {
|
|
87
|
+
rejectEmptyOrUrl(inputPath, `${what} path`, "file path");
|
|
83
88
|
const resolved = import_node_path.default.resolve(process.cwd(), inputPath);
|
|
84
89
|
let stat;
|
|
85
90
|
try {
|
|
86
91
|
stat = import_node_fs.default.statSync(resolved);
|
|
87
92
|
} catch {
|
|
88
|
-
throw new AutoRigInputError(
|
|
93
|
+
throw new AutoRigInputError(`${what} file not found: ${resolved}`);
|
|
89
94
|
}
|
|
90
95
|
if (stat.isDirectory()) {
|
|
91
96
|
throw new AutoRigInputError(
|
|
92
|
-
|
|
97
|
+
`${what} path is a directory, not a file: ${resolved}`
|
|
93
98
|
);
|
|
94
99
|
}
|
|
95
100
|
return resolved;
|
|
@@ -3285,11 +3290,500 @@ async function composeLayersFromParts(input) {
|
|
|
3285
3290
|
}
|
|
3286
3291
|
}
|
|
3287
3292
|
|
|
3293
|
+
// src/render-poses.ts
|
|
3294
|
+
var import_node_fs5 = require("fs");
|
|
3295
|
+
var import_node_path9 = __toESM(require("path"));
|
|
3296
|
+
var import_format2 = require("@ikijs/format");
|
|
3297
|
+
|
|
3298
|
+
// src/render-browser.ts
|
|
3299
|
+
var import_node_child_process = require("child_process");
|
|
3300
|
+
var import_node_fs4 = __toESM(require("fs"));
|
|
3301
|
+
var import_node_os = __toESM(require("os"));
|
|
3302
|
+
var import_node_path8 = __toESM(require("path"));
|
|
3303
|
+
var NO_BROWSER_MESSAGE = "render_poses needs a Chromium-based browser and found none. Install Google Chrome, Microsoft Edge or Chromium, or set CHROME_PATH to its executable.";
|
|
3304
|
+
var DARWIN_CANDIDATES = [
|
|
3305
|
+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
3306
|
+
"/Applications/Chromium.app/Contents/MacOS/Chromium",
|
|
3307
|
+
"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"
|
|
3308
|
+
];
|
|
3309
|
+
var LINUX_CANDIDATES = [
|
|
3310
|
+
"/usr/bin/google-chrome",
|
|
3311
|
+
"/usr/bin/google-chrome-stable",
|
|
3312
|
+
"/usr/bin/chromium",
|
|
3313
|
+
"/usr/bin/chromium-browser",
|
|
3314
|
+
"/usr/bin/microsoft-edge",
|
|
3315
|
+
"/snap/bin/chromium"
|
|
3316
|
+
];
|
|
3317
|
+
var WIN32_ROOTS = ["PROGRAMFILES", "PROGRAMFILES(X86)", "LOCALAPPDATA"];
|
|
3318
|
+
var WIN32_SUFFIXES = [
|
|
3319
|
+
["Google", "Chrome", "Application", "chrome.exe"],
|
|
3320
|
+
["Microsoft", "Edge", "Application", "msedge.exe"]
|
|
3321
|
+
];
|
|
3322
|
+
var CLOSE_GRACE_MS = 2e3;
|
|
3323
|
+
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
3324
|
+
var BROWSER_CLOSE_MS = 1e3;
|
|
3325
|
+
function isExecutableFile(file) {
|
|
3326
|
+
try {
|
|
3327
|
+
if (!import_node_fs4.default.statSync(file).isFile()) return false;
|
|
3328
|
+
import_node_fs4.default.accessSync(file, import_node_fs4.default.constants.X_OK);
|
|
3329
|
+
return true;
|
|
3330
|
+
} catch {
|
|
3331
|
+
return false;
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
3334
|
+
function findBrowser({
|
|
3335
|
+
env = process.env,
|
|
3336
|
+
platform = process.platform,
|
|
3337
|
+
isExecutable = isExecutableFile
|
|
3338
|
+
} = {}) {
|
|
3339
|
+
const override = env.CHROME_PATH;
|
|
3340
|
+
if (override) {
|
|
3341
|
+
if (!isExecutable(override)) {
|
|
3342
|
+
throw new AutoRigInputError(
|
|
3343
|
+
`CHROME_PATH is not an executable file: ${override}`
|
|
3344
|
+
);
|
|
3345
|
+
}
|
|
3346
|
+
return override;
|
|
3347
|
+
}
|
|
3348
|
+
let candidates;
|
|
3349
|
+
if (platform === "darwin") candidates = DARWIN_CANDIDATES;
|
|
3350
|
+
else if (platform === "win32") {
|
|
3351
|
+
candidates = [];
|
|
3352
|
+
for (const suffix of WIN32_SUFFIXES) {
|
|
3353
|
+
for (const root of WIN32_ROOTS) {
|
|
3354
|
+
const base = env[root];
|
|
3355
|
+
if (base) candidates.push(import_node_path8.default.win32.join(base, ...suffix));
|
|
3356
|
+
}
|
|
3357
|
+
}
|
|
3358
|
+
} else candidates = LINUX_CANDIDATES;
|
|
3359
|
+
return candidates.find((file) => isExecutable(file));
|
|
3360
|
+
}
|
|
3361
|
+
function within(promise, ms, what, detail) {
|
|
3362
|
+
let timer;
|
|
3363
|
+
const timeout = new Promise((_, reject) => {
|
|
3364
|
+
timer = setTimeout(
|
|
3365
|
+
() => reject(
|
|
3366
|
+
new Error(
|
|
3367
|
+
`${what} timed out after ${ms} ms${detail ? `: ${detail()}` : ""}`
|
|
3368
|
+
)
|
|
3369
|
+
),
|
|
3370
|
+
ms
|
|
3371
|
+
);
|
|
3372
|
+
});
|
|
3373
|
+
return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
|
|
3374
|
+
}
|
|
3375
|
+
function connectCdp(url, timeoutMs) {
|
|
3376
|
+
const socket = new WebSocket(url);
|
|
3377
|
+
let nextId = 0;
|
|
3378
|
+
let socketClosed = false;
|
|
3379
|
+
const pending = /* @__PURE__ */ new Map();
|
|
3380
|
+
socket.addEventListener("message", (event) => {
|
|
3381
|
+
const message = JSON.parse(String(event.data));
|
|
3382
|
+
const entry = pending.get(message.id);
|
|
3383
|
+
if (!entry) return;
|
|
3384
|
+
pending.delete(message.id);
|
|
3385
|
+
if (message.error) {
|
|
3386
|
+
entry.reject(
|
|
3387
|
+
new Error(`${message.error.message} (${message.error.code})`)
|
|
3388
|
+
);
|
|
3389
|
+
} else entry.resolve(message.result);
|
|
3390
|
+
});
|
|
3391
|
+
socket.addEventListener("close", () => {
|
|
3392
|
+
socketClosed = true;
|
|
3393
|
+
for (const entry of pending.values()) {
|
|
3394
|
+
entry.reject(new Error("DevTools connection closed"));
|
|
3395
|
+
}
|
|
3396
|
+
pending.clear();
|
|
3397
|
+
});
|
|
3398
|
+
const opened = new Promise((resolve, reject) => {
|
|
3399
|
+
socket.addEventListener(
|
|
3400
|
+
"error",
|
|
3401
|
+
() => reject(new Error("DevTools connection failed"))
|
|
3402
|
+
);
|
|
3403
|
+
socket.addEventListener(
|
|
3404
|
+
"open",
|
|
3405
|
+
() => resolve({
|
|
3406
|
+
send(method, callTimeoutMs, params, sessionId) {
|
|
3407
|
+
if (socketClosed) {
|
|
3408
|
+
return Promise.reject(new Error("DevTools connection closed"));
|
|
3409
|
+
}
|
|
3410
|
+
const id = ++nextId;
|
|
3411
|
+
const reply = new Promise((res, rej) => {
|
|
3412
|
+
pending.set(id, {
|
|
3413
|
+
resolve: res,
|
|
3414
|
+
reject: rej
|
|
3415
|
+
});
|
|
3416
|
+
});
|
|
3417
|
+
socket.send(JSON.stringify({ id, method, params, sessionId }));
|
|
3418
|
+
return within(reply, callTimeoutMs, method).finally(
|
|
3419
|
+
() => pending.delete(id)
|
|
3420
|
+
);
|
|
3421
|
+
}
|
|
3422
|
+
})
|
|
3423
|
+
);
|
|
3424
|
+
});
|
|
3425
|
+
return within(opened, timeoutMs, "DevTools connection").catch((error) => {
|
|
3426
|
+
socket.close();
|
|
3427
|
+
throw error;
|
|
3428
|
+
});
|
|
3429
|
+
}
|
|
3430
|
+
function startError(executable, error) {
|
|
3431
|
+
return new Error(
|
|
3432
|
+
`could not start ${executable}: ${error.code ?? error.message}`
|
|
3433
|
+
);
|
|
3434
|
+
}
|
|
3435
|
+
function waitForDevTools(child, closed, getSpawnError, executable, timeoutMs) {
|
|
3436
|
+
let tail = "";
|
|
3437
|
+
return within(
|
|
3438
|
+
new Promise((resolve, reject) => {
|
|
3439
|
+
child.stderr.on("data", (chunk) => {
|
|
3440
|
+
tail = (tail + chunk).slice(-2e3);
|
|
3441
|
+
const match = /DevTools listening on (ws:\/\/\S+)/.exec(tail);
|
|
3442
|
+
if (match) resolve(match[1]);
|
|
3443
|
+
});
|
|
3444
|
+
void closed.then(() => {
|
|
3445
|
+
const spawnError = getSpawnError();
|
|
3446
|
+
reject(
|
|
3447
|
+
spawnError ? startError(executable, spawnError) : new Error(
|
|
3448
|
+
`${executable} exited before DevTools was ready: ${tail.trim()}`
|
|
3449
|
+
)
|
|
3450
|
+
);
|
|
3451
|
+
});
|
|
3452
|
+
}),
|
|
3453
|
+
timeoutMs,
|
|
3454
|
+
"browser startup",
|
|
3455
|
+
() => tail.trim() || "no output"
|
|
3456
|
+
);
|
|
3457
|
+
}
|
|
3458
|
+
async function openPage(cdp, timeoutMs) {
|
|
3459
|
+
const { targetId } = await cdp.send(
|
|
3460
|
+
"Target.createTarget",
|
|
3461
|
+
timeoutMs,
|
|
3462
|
+
{ url: "about:blank" }
|
|
3463
|
+
);
|
|
3464
|
+
const { sessionId } = await cdp.send(
|
|
3465
|
+
"Target.attachToTarget",
|
|
3466
|
+
timeoutMs,
|
|
3467
|
+
{ targetId, flatten: true }
|
|
3468
|
+
);
|
|
3469
|
+
return async (expression, evalTimeoutMs) => {
|
|
3470
|
+
const { result, exceptionDetails } = await cdp.send(
|
|
3471
|
+
"Runtime.evaluate",
|
|
3472
|
+
evalTimeoutMs,
|
|
3473
|
+
{ expression, awaitPromise: true, returnByValue: true },
|
|
3474
|
+
sessionId
|
|
3475
|
+
);
|
|
3476
|
+
if (exceptionDetails) {
|
|
3477
|
+
const thrown = exceptionDetails.exception;
|
|
3478
|
+
throw new Error(
|
|
3479
|
+
thrown?.description ?? (thrown && "value" in thrown ? String(thrown.value) : exceptionDetails.text)
|
|
3480
|
+
);
|
|
3481
|
+
}
|
|
3482
|
+
return result.value;
|
|
3483
|
+
};
|
|
3484
|
+
}
|
|
3485
|
+
function removeProfile(profile) {
|
|
3486
|
+
try {
|
|
3487
|
+
import_node_fs4.default.rmSync(profile, {
|
|
3488
|
+
recursive: true,
|
|
3489
|
+
force: true,
|
|
3490
|
+
maxRetries: 5,
|
|
3491
|
+
retryDelay: 100
|
|
3492
|
+
});
|
|
3493
|
+
} catch (error) {
|
|
3494
|
+
console.error(`could not remove browser profile ${profile}:`, error);
|
|
3495
|
+
}
|
|
3496
|
+
}
|
|
3497
|
+
async function launchBrowser(executable, timeoutMs) {
|
|
3498
|
+
if (typeof globalThis.WebSocket === "undefined") {
|
|
3499
|
+
throw new AutoRigInputError(
|
|
3500
|
+
"render_poses needs Node 22 or newer (the global WebSocket is missing)."
|
|
3501
|
+
);
|
|
3502
|
+
}
|
|
3503
|
+
const profile = import_node_fs4.default.mkdtempSync(import_node_path8.default.join(import_node_os.default.tmpdir(), "iki-render-"));
|
|
3504
|
+
let child;
|
|
3505
|
+
try {
|
|
3506
|
+
child = (0, import_node_child_process.spawn)(
|
|
3507
|
+
executable,
|
|
3508
|
+
[
|
|
3509
|
+
"--headless=new",
|
|
3510
|
+
"--remote-debugging-port=0",
|
|
3511
|
+
`--user-data-dir=${profile}`,
|
|
3512
|
+
"--no-first-run",
|
|
3513
|
+
"--no-default-browser-check",
|
|
3514
|
+
// Output pixel sizes must equal the plan's, whatever the display.
|
|
3515
|
+
"--force-device-scale-factor=1",
|
|
3516
|
+
// WebGL without a GPU; recent Chrome no longer falls back by itself.
|
|
3517
|
+
"--enable-unsafe-swiftshader",
|
|
3518
|
+
"about:blank"
|
|
3519
|
+
],
|
|
3520
|
+
{ stdio: ["ignore", "ignore", "pipe"] }
|
|
3521
|
+
);
|
|
3522
|
+
} catch (error) {
|
|
3523
|
+
import_node_fs4.default.rmSync(profile, { recursive: true, force: true });
|
|
3524
|
+
throw startError(executable, error);
|
|
3525
|
+
}
|
|
3526
|
+
let spawnError;
|
|
3527
|
+
child.on("error", (error) => {
|
|
3528
|
+
spawnError = error;
|
|
3529
|
+
});
|
|
3530
|
+
let exited = false;
|
|
3531
|
+
const closed = new Promise((resolve) => {
|
|
3532
|
+
child.on("close", () => {
|
|
3533
|
+
exited = true;
|
|
3534
|
+
resolve();
|
|
3535
|
+
});
|
|
3536
|
+
});
|
|
3537
|
+
const settle = (ms) => within(closed, ms, "browser close").catch(() => {
|
|
3538
|
+
});
|
|
3539
|
+
const onProcessExit = () => {
|
|
3540
|
+
child.kill("SIGKILL");
|
|
3541
|
+
removeProfile(profile);
|
|
3542
|
+
};
|
|
3543
|
+
process.once("exit", onProcessExit);
|
|
3544
|
+
let shutdownPromise;
|
|
3545
|
+
const shutdown = () => shutdownPromise ??= (async () => {
|
|
3546
|
+
if (!exited) {
|
|
3547
|
+
child.kill();
|
|
3548
|
+
await settle(CLOSE_GRACE_MS);
|
|
3549
|
+
if (!exited) {
|
|
3550
|
+
child.kill("SIGKILL");
|
|
3551
|
+
await settle(CLOSE_GRACE_MS);
|
|
3552
|
+
}
|
|
3553
|
+
}
|
|
3554
|
+
process.removeListener("exit", onProcessExit);
|
|
3555
|
+
removeProfile(profile);
|
|
3556
|
+
})();
|
|
3557
|
+
let cdp;
|
|
3558
|
+
try {
|
|
3559
|
+
const endpoint = await waitForDevTools(
|
|
3560
|
+
child,
|
|
3561
|
+
closed,
|
|
3562
|
+
() => spawnError,
|
|
3563
|
+
executable,
|
|
3564
|
+
timeoutMs
|
|
3565
|
+
);
|
|
3566
|
+
cdp = await connectCdp(endpoint, timeoutMs);
|
|
3567
|
+
} catch (error) {
|
|
3568
|
+
await shutdown();
|
|
3569
|
+
throw error;
|
|
3570
|
+
}
|
|
3571
|
+
return {
|
|
3572
|
+
openPage: () => openPage(cdp, timeoutMs),
|
|
3573
|
+
async close() {
|
|
3574
|
+
if (!exited) {
|
|
3575
|
+
await cdp.send("Browser.close", BROWSER_CLOSE_MS).catch(() => {
|
|
3576
|
+
});
|
|
3577
|
+
}
|
|
3578
|
+
await shutdown();
|
|
3579
|
+
}
|
|
3580
|
+
};
|
|
3581
|
+
}
|
|
3582
|
+
async function withBrowser(executable, fn) {
|
|
3583
|
+
const browser = await launchBrowser(executable, DEFAULT_TIMEOUT_MS);
|
|
3584
|
+
try {
|
|
3585
|
+
return await fn(await browser.openPage());
|
|
3586
|
+
} finally {
|
|
3587
|
+
await browser.close();
|
|
3588
|
+
}
|
|
3589
|
+
}
|
|
3590
|
+
|
|
3591
|
+
// src/render-poses.ts
|
|
3592
|
+
var FULL_BODY_VIEW_WIDTH = 2.5;
|
|
3593
|
+
var BUST_SIZE = 560;
|
|
3594
|
+
function planRenders(model) {
|
|
3595
|
+
const { width: W, height: H } = model.canvas;
|
|
3596
|
+
const fullBody = H > W;
|
|
3597
|
+
const canvas = fullBody ? {
|
|
3598
|
+
width: FULL_BODY_VIEW_WIDTH * BUST_SIZE,
|
|
3599
|
+
height: Math.ceil(BUST_SIZE * H / W)
|
|
3600
|
+
} : { width: BUST_SIZE, height: BUST_SIZE };
|
|
3601
|
+
const view = fullBody ? { x: 0, y: 0, width: FULL_BODY_VIEW_WIDTH * W, height: H } : void 0;
|
|
3602
|
+
const x0 = (canvas.width - BUST_SIZE) / 2;
|
|
3603
|
+
const s = BUST_SIZE / W;
|
|
3604
|
+
const mouthPart = model.parts.find((p) => p.id === "mouth_inner") ?? model.parts.find((p) => p.id === "mouth");
|
|
3605
|
+
const mouth = mouthPart ? { cx: W / 2 + mouthPart.transform.x, cy: H / 2 - mouthPart.transform.y } : void 0;
|
|
3606
|
+
const squareCrop = fullBody ? {
|
|
3607
|
+
sx: x0,
|
|
3608
|
+
sy: 0,
|
|
3609
|
+
sw: BUST_SIZE,
|
|
3610
|
+
sh: BUST_SIZE,
|
|
3611
|
+
dw: BUST_SIZE,
|
|
3612
|
+
dh: BUST_SIZE
|
|
3613
|
+
} : void 0;
|
|
3614
|
+
const square = (name, values = {}) => ({
|
|
3615
|
+
name,
|
|
3616
|
+
values,
|
|
3617
|
+
crop: squareCrop
|
|
3618
|
+
});
|
|
3619
|
+
const whole = (name, values = {}) => ({
|
|
3620
|
+
name,
|
|
3621
|
+
values
|
|
3622
|
+
});
|
|
3623
|
+
const poses = [
|
|
3624
|
+
square("rest"),
|
|
3625
|
+
square("turn-m30", { ParamAngleX: -30 }),
|
|
3626
|
+
square("turn-p30", { ParamAngleX: 30 }),
|
|
3627
|
+
square("turn-15", { ParamAngleX: 15 }),
|
|
3628
|
+
square("nod-15", { ParamAngleY: 15 }),
|
|
3629
|
+
square("blink", { ParamEyeLOpen: 0 }),
|
|
3630
|
+
square("blink-half", { ParamEyeLOpen: 0.5 }),
|
|
3631
|
+
square("gaze", { ParamEyeBallX: 1 }),
|
|
3632
|
+
square("combined", { ParamAngleX: 30, ParamAngleY: 30, ParamAngleZ: 30 })
|
|
3633
|
+
];
|
|
3634
|
+
if (mouth) {
|
|
3635
|
+
const crop = {
|
|
3636
|
+
sx: x0 + (mouth.cx - 90) * s,
|
|
3637
|
+
sy: (mouth.cy - 60) * s,
|
|
3638
|
+
sw: 180 * s,
|
|
3639
|
+
sh: 120 * s,
|
|
3640
|
+
dw: 720,
|
|
3641
|
+
dh: 480
|
|
3642
|
+
};
|
|
3643
|
+
for (const open of [0, 0.3, 0.6, 1]) {
|
|
3644
|
+
for (const [name, form] of [
|
|
3645
|
+
["m1", -1],
|
|
3646
|
+
["0", 0],
|
|
3647
|
+
["p1", 1]
|
|
3648
|
+
]) {
|
|
3649
|
+
poses.push({
|
|
3650
|
+
name: `mouth-open-${open}-form-${name}`,
|
|
3651
|
+
values: { ParamMouthOpenY: open, ParamMouthForm: form },
|
|
3652
|
+
crop
|
|
3653
|
+
});
|
|
3654
|
+
}
|
|
3655
|
+
}
|
|
3656
|
+
poses.push(
|
|
3657
|
+
{
|
|
3658
|
+
name: "mouth-laugh",
|
|
3659
|
+
values: { ParamMouthOpenY: 0.8, ParamMouthForm: 1 },
|
|
3660
|
+
crop
|
|
3661
|
+
},
|
|
3662
|
+
{ name: "mouth-surprised", values: { ParamMouthOpenY: 0.9 }, crop },
|
|
3663
|
+
{
|
|
3664
|
+
name: "mouth-turn-p30-half",
|
|
3665
|
+
values: { ParamAngleX: 30, ParamMouthOpenY: 0.5 },
|
|
3666
|
+
crop
|
|
3667
|
+
}
|
|
3668
|
+
);
|
|
3669
|
+
}
|
|
3670
|
+
if (fullBody) {
|
|
3671
|
+
poses.push(
|
|
3672
|
+
whole("full-rest"),
|
|
3673
|
+
whole("full-turn-p30", { ParamAngleX: 30 }),
|
|
3674
|
+
whole("full-body-x-m10", { ParamBodyAngleX: -10 }),
|
|
3675
|
+
whole("full-body-x-p10", { ParamBodyAngleX: 10 }),
|
|
3676
|
+
whole("full-body-y-m10", { ParamBodyAngleY: -10 }),
|
|
3677
|
+
whole("full-body-y-p10", { ParamBodyAngleY: 10 }),
|
|
3678
|
+
whole("full-body-z-m10", { ParamBodyAngleZ: -10 }),
|
|
3679
|
+
whole("full-body-z-p10", { ParamBodyAngleZ: 10 }),
|
|
3680
|
+
whole("full-arm-l-16", { ParamArmL: 16 }),
|
|
3681
|
+
whole("full-arm-l-32", { ParamArmL: 32 }),
|
|
3682
|
+
whole("full-arm-r-16", { ParamArmR: 16 }),
|
|
3683
|
+
whole("full-arm-r-32", { ParamArmR: 32 }),
|
|
3684
|
+
whole("full-elbow-l-m10", { ParamElbowL: -10 }),
|
|
3685
|
+
whole("full-elbow-l-45", { ParamElbowL: 45 }),
|
|
3686
|
+
whole("full-elbow-l-90", { ParamElbowL: 90 }),
|
|
3687
|
+
whole("full-elbow-r-m10", { ParamElbowR: -10 }),
|
|
3688
|
+
whole("full-elbow-r-45", { ParamElbowR: 45 }),
|
|
3689
|
+
whole("full-elbow-r-90", { ParamElbowR: 90 })
|
|
3690
|
+
);
|
|
3691
|
+
if (model.parameters.some((p) => p.id === import_format2.StandardParameter.ArmPoseRight)) {
|
|
3692
|
+
poses.push(
|
|
3693
|
+
whole("full-pose-l", { ParamArmPoseL: 1 }),
|
|
3694
|
+
whole("full-pose-r", { ParamArmPoseR: 1 }),
|
|
3695
|
+
whole("full-pose-r-angle-m15", {
|
|
3696
|
+
ParamArmPoseR: 1,
|
|
3697
|
+
ParamArmPoseAngleR: -15
|
|
3698
|
+
}),
|
|
3699
|
+
whole("full-pose-r-angle-p15", {
|
|
3700
|
+
ParamArmPoseR: 1,
|
|
3701
|
+
ParamArmPoseAngleR: 15
|
|
3702
|
+
}),
|
|
3703
|
+
whole("full-pose-r-half", { ParamArmPoseR: 0.5 })
|
|
3704
|
+
);
|
|
3705
|
+
}
|
|
3706
|
+
}
|
|
3707
|
+
return { canvas, view, fullBody, mouth, poses };
|
|
3708
|
+
}
|
|
3709
|
+
var PNG_PREFIX = "data:image/png;base64,";
|
|
3710
|
+
var PAGE_SCRIPT_MS = 1e4;
|
|
3711
|
+
var LOAD_MS = 6e4;
|
|
3712
|
+
var CAPTURE_MS = 15e3;
|
|
3713
|
+
function readPageScript() {
|
|
3714
|
+
const url = new URL("../dist/render-page.global.js", importMetaUrl);
|
|
3715
|
+
try {
|
|
3716
|
+
return (0, import_node_fs5.readFileSync)(url, "utf8");
|
|
3717
|
+
} catch (cause) {
|
|
3718
|
+
throw new Error(
|
|
3719
|
+
"could not read the render page script; run `pnpm build` in packages/mcp",
|
|
3720
|
+
{ cause }
|
|
3721
|
+
);
|
|
3722
|
+
}
|
|
3723
|
+
}
|
|
3724
|
+
async function renderPoses(input) {
|
|
3725
|
+
try {
|
|
3726
|
+
const modelFile = confineToWorkingDirectory(
|
|
3727
|
+
process.cwd(),
|
|
3728
|
+
resolveInputPath(input.modelPath, "model"),
|
|
3729
|
+
"model path",
|
|
3730
|
+
input.modelPath
|
|
3731
|
+
);
|
|
3732
|
+
const outDir = resolveOutputDir(input.outDir);
|
|
3733
|
+
const model = (0, import_format2.loadIkiModel)((0, import_node_fs5.readFileSync)(modelFile, "utf8"));
|
|
3734
|
+
const plan = planRenders(model);
|
|
3735
|
+
const browser = findBrowser();
|
|
3736
|
+
if (!browser) return { ok: false, error: NO_BROWSER_MESSAGE };
|
|
3737
|
+
const pageScript = readPageScript();
|
|
3738
|
+
const { failedTextures, poses } = await withBrowser(
|
|
3739
|
+
browser,
|
|
3740
|
+
async (evaluate) => {
|
|
3741
|
+
await evaluate(pageScript, PAGE_SCRIPT_MS);
|
|
3742
|
+
const loaded = await evaluate(
|
|
3743
|
+
`window.__ikiRender.load(${JSON.stringify(model)}, ${JSON.stringify({ canvas: plan.canvas, view: plan.view })})`,
|
|
3744
|
+
LOAD_MS
|
|
3745
|
+
);
|
|
3746
|
+
const written = [];
|
|
3747
|
+
for (const pose of plan.poses) {
|
|
3748
|
+
const url = await evaluate(
|
|
3749
|
+
`window.__ikiRender.capture(${JSON.stringify(pose.values)}, ${JSON.stringify(pose.crop)})`,
|
|
3750
|
+
CAPTURE_MS
|
|
3751
|
+
);
|
|
3752
|
+
if (typeof url !== "string" || !url.startsWith(PNG_PREFIX)) {
|
|
3753
|
+
throw new Error(`pose ${pose.name}: the page returned no PNG`);
|
|
3754
|
+
}
|
|
3755
|
+
const file = import_node_path9.default.join(outDir, `${pose.name}.png`);
|
|
3756
|
+
writeFileAtomic(
|
|
3757
|
+
file,
|
|
3758
|
+
Buffer.from(url.slice(PNG_PREFIX.length), "base64")
|
|
3759
|
+
);
|
|
3760
|
+
written.push({ name: pose.name, path: file });
|
|
3761
|
+
}
|
|
3762
|
+
return { failedTextures: loaded.failedTextures, poses: written };
|
|
3763
|
+
}
|
|
3764
|
+
);
|
|
3765
|
+
return {
|
|
3766
|
+
ok: true,
|
|
3767
|
+
outDir,
|
|
3768
|
+
canvas: plan.canvas,
|
|
3769
|
+
fullBody: plan.fullBody,
|
|
3770
|
+
mouth: plan.mouth,
|
|
3771
|
+
failedTextures,
|
|
3772
|
+
poses
|
|
3773
|
+
};
|
|
3774
|
+
} catch (error) {
|
|
3775
|
+
if (error instanceof AutoRigInputError || error instanceof import_format2.IkiFormatError) {
|
|
3776
|
+
return { ok: false, error: error.message };
|
|
3777
|
+
}
|
|
3778
|
+
throw error;
|
|
3779
|
+
}
|
|
3780
|
+
}
|
|
3781
|
+
|
|
3288
3782
|
// src/server.ts
|
|
3289
3783
|
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
3290
3784
|
var import_zod = require("zod");
|
|
3291
3785
|
function createIkiMcpServer() {
|
|
3292
|
-
const server = new import_mcp.McpServer({ name: "iki", version: "0.
|
|
3786
|
+
const server = new import_mcp.McpServer({ name: "iki", version: "0.24.0" });
|
|
3293
3787
|
server.registerTool(
|
|
3294
3788
|
"validate_iki",
|
|
3295
3789
|
{
|
|
@@ -3519,6 +4013,34 @@ function createIkiMcpServer() {
|
|
|
3519
4013
|
}
|
|
3520
4014
|
}
|
|
3521
4015
|
);
|
|
4016
|
+
server.registerTool(
|
|
4017
|
+
"render_poses",
|
|
4018
|
+
{
|
|
4019
|
+
description: "Renders a rigged .iki into the character loop's pose PNGs with the real engine, through the installed Chrome, Edge or Chromium run headless (set CHROME_PATH to pick one). The model decides the set: a bust gets 560x560 shots (rest, turns, nod, blinks, gaze, combined); a mouth adds 720x480 mouth crops; a full body (taller than wide) adds the full-canvas body, arm and elbow poses on a 1400-wide canvas, and a model with a pose forearm adds the full-pose-* shots. Writes <pose>.png files into outDir, overwriting same-named files in place; returns the written paths one per line. Fails with INVALID when no browser is found or an input is refused; a browser that cannot start is a tool error.",
|
|
4020
|
+
inputSchema: {
|
|
4021
|
+
modelPath: import_zod.z.string().describe(
|
|
4022
|
+
"Rigged .iki file path (resolved against cwd; must sit under the working directory)."
|
|
4023
|
+
),
|
|
4024
|
+
outDir: import_zod.z.string().describe(
|
|
4025
|
+
"Existing directory to write the pose PNGs into (resolved against cwd; must already exist; confined to the working directory)."
|
|
4026
|
+
)
|
|
4027
|
+
}
|
|
4028
|
+
},
|
|
4029
|
+
async (args) => {
|
|
4030
|
+
try {
|
|
4031
|
+
const r = await renderPoses(args);
|
|
4032
|
+
const text = r.ok ? r.poses.map((p) => p.path).join("\n") : `INVALID: ${r.error}`;
|
|
4033
|
+
return { content: [{ type: "text", text }], structuredContent: r };
|
|
4034
|
+
} catch (err) {
|
|
4035
|
+
const error = err instanceof Error ? err.message : String(err);
|
|
4036
|
+
return {
|
|
4037
|
+
content: [{ type: "text", text: `Unexpected error: ${error}` }],
|
|
4038
|
+
structuredContent: { ok: false, error },
|
|
4039
|
+
isError: true
|
|
4040
|
+
};
|
|
4041
|
+
}
|
|
4042
|
+
}
|
|
4043
|
+
);
|
|
3522
4044
|
return server;
|
|
3523
4045
|
}
|
|
3524
4046
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -3532,6 +4054,7 @@ function createIkiMcpServer() {
|
|
|
3532
4054
|
listStandardParameters,
|
|
3533
4055
|
measureLayers,
|
|
3534
4056
|
measureTurnReference,
|
|
4057
|
+
renderPoses,
|
|
3535
4058
|
validateIki
|
|
3536
4059
|
});
|
|
3537
4060
|
//# sourceMappingURL=index.js.map
|