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