@tempad-dev/mcp 0.3.8 → 0.3.9
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/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as SOCK_PATH, c as log, i as RUNTIME_DIR, n as LOCK_PATH, o as ensureDir, r as PACKAGE_VERSION } from "./shared-
|
|
2
|
+
import { a as SOCK_PATH, c as log, i as RUNTIME_DIR, n as LOCK_PATH, o as ensureDir, r as PACKAGE_VERSION } from "./shared-Dx5fhN-T.mjs";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
4
|
import { connect } from "node:net";
|
|
5
5
|
import { join } from "node:path";
|
package/dist/hub.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as SOCK_PATH, c as log, i as RUNTIME_DIR, o as ensureDir, r as PACKAGE_VERSION, s as ensureFile, t as ASSET_DIR } from "./shared-
|
|
1
|
+
import { a as SOCK_PATH, c as log, i as RUNTIME_DIR, o as ensureDir, r as PACKAGE_VERSION, s as ensureFile, t as ASSET_DIR } from "./shared-Dx5fhN-T.mjs";
|
|
2
2
|
import { createServer } from "node:net";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { URL as URL$1 } from "node:url";
|
|
@@ -3237,7 +3237,7 @@ const GetCodeParametersSchema = object({
|
|
|
3237
3237
|
resolveTokens: boolean().describe("Inline token values instead of references for quick renders; default false returns token metadata so you can map into your theming system.").optional()
|
|
3238
3238
|
});
|
|
3239
3239
|
const GetTokenDefsParametersSchema = object({
|
|
3240
|
-
names: array(string().regex(/^--[a-zA-Z0-9-_]+$/)).min(1).describe("Canonical token names (CSS variable form) from get_code.usedTokens or your own list to resolve, e.g., --color-primary."),
|
|
3240
|
+
names: array(string().regex(/^--[a-zA-Z0-9-_]+$/)).min(1).describe("Canonical token names (CSS variable form) from Object.keys(get_code.usedTokens) or your own list to resolve, e.g., --color-primary."),
|
|
3241
3241
|
includeAllModes: boolean().describe("Include all token modes (light/dark/etc.) instead of just the active one to mirror responsive tokens; default false.").optional()
|
|
3242
3242
|
});
|
|
3243
3243
|
const GetScreenshotParametersSchema = object({ nodeId: string().describe("Optional node id to screenshot; defaults to the current single selection. Useful when layout/overlap is uncertain (auto-layout none/inferred).").optional() });
|
|
@@ -3314,6 +3314,15 @@ function createAssetHttpServer(store) {
|
|
|
3314
3314
|
return `http://${LOOPBACK_HOST}:${port$1}`;
|
|
3315
3315
|
}
|
|
3316
3316
|
function handleRequest(req, res) {
|
|
3317
|
+
const startedAt = Date.now();
|
|
3318
|
+
res.on("finish", () => {
|
|
3319
|
+
log.info({
|
|
3320
|
+
method: req.method,
|
|
3321
|
+
url: req.url,
|
|
3322
|
+
status: res.statusCode,
|
|
3323
|
+
durationMs: Date.now() - startedAt
|
|
3324
|
+
}, "HTTP asset request completed.");
|
|
3325
|
+
});
|
|
3317
3326
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
3318
3327
|
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
|
3319
3328
|
res.setHeader("Access-Control-Allow-Headers", "Content-Type, X-Asset-Width, X-Asset-Height");
|
|
@@ -3323,14 +3332,12 @@ function createAssetHttpServer(store) {
|
|
|
3323
3332
|
return;
|
|
3324
3333
|
}
|
|
3325
3334
|
if (!req.url) {
|
|
3326
|
-
res
|
|
3327
|
-
res.end("Missing URL");
|
|
3335
|
+
sendError(res, 400, "Missing URL");
|
|
3328
3336
|
return;
|
|
3329
3337
|
}
|
|
3330
3338
|
const segments = new URL$1(req.url, getBaseUrl()).pathname.split("/").filter(Boolean);
|
|
3331
3339
|
if (segments.length !== 2 || segments[0] !== "assets") {
|
|
3332
|
-
res
|
|
3333
|
-
res.end("Not Found");
|
|
3340
|
+
sendError(res, 404, "Not Found");
|
|
3334
3341
|
return;
|
|
3335
3342
|
}
|
|
3336
3343
|
const hash = segments[1];
|
|
@@ -3342,14 +3349,12 @@ function createAssetHttpServer(store) {
|
|
|
3342
3349
|
handleDownload(req, res, hash);
|
|
3343
3350
|
return;
|
|
3344
3351
|
}
|
|
3345
|
-
res
|
|
3346
|
-
res.end("Method Not Allowed");
|
|
3352
|
+
sendError(res, 405, "Method Not Allowed");
|
|
3347
3353
|
}
|
|
3348
3354
|
function handleDownload(req, res, hash) {
|
|
3349
3355
|
const record = store.get(hash);
|
|
3350
3356
|
if (!record) {
|
|
3351
|
-
res
|
|
3352
|
-
res.end("Not Found");
|
|
3357
|
+
sendError(res, 404, "Asset Not Found");
|
|
3353
3358
|
return;
|
|
3354
3359
|
}
|
|
3355
3360
|
let stat;
|
|
@@ -3358,15 +3363,13 @@ function createAssetHttpServer(store) {
|
|
|
3358
3363
|
} catch (error) {
|
|
3359
3364
|
if (error.code === "ENOENT") {
|
|
3360
3365
|
store.remove(hash, { removeFile: false });
|
|
3361
|
-
res
|
|
3362
|
-
res.end("Not Found");
|
|
3366
|
+
sendError(res, 404, "Asset Not Found");
|
|
3363
3367
|
} else {
|
|
3364
3368
|
log.error({
|
|
3365
3369
|
error,
|
|
3366
3370
|
hash
|
|
3367
3371
|
}, "Failed to stat asset file.");
|
|
3368
|
-
res
|
|
3369
|
-
res.end("Internal Server Error");
|
|
3372
|
+
sendError(res, 500, "Internal Server Error");
|
|
3370
3373
|
}
|
|
3371
3374
|
return;
|
|
3372
3375
|
}
|
|
@@ -3381,8 +3384,8 @@ function createAssetHttpServer(store) {
|
|
|
3381
3384
|
error,
|
|
3382
3385
|
hash
|
|
3383
3386
|
}, "Failed to stream asset file.");
|
|
3384
|
-
if (!res.headersSent) res
|
|
3385
|
-
res.end(
|
|
3387
|
+
if (!res.headersSent) sendError(res, 500, "Internal Server Error");
|
|
3388
|
+
else res.end();
|
|
3386
3389
|
});
|
|
3387
3390
|
stream.on("open", () => {
|
|
3388
3391
|
store.touch(hash);
|
|
@@ -3391,8 +3394,7 @@ function createAssetHttpServer(store) {
|
|
|
3391
3394
|
}
|
|
3392
3395
|
function handleUpload(req, res, hash) {
|
|
3393
3396
|
if (!MCP_HASH_PATTERN.test(hash)) {
|
|
3394
|
-
res
|
|
3395
|
-
res.end("Invalid Hash Format");
|
|
3397
|
+
sendError(res, 400, "Invalid Hash Format");
|
|
3396
3398
|
return;
|
|
3397
3399
|
}
|
|
3398
3400
|
const mimeType = req.headers["content-type"] || "application/octet-stream";
|
|
@@ -3417,8 +3419,7 @@ function createAssetHttpServer(store) {
|
|
|
3417
3419
|
}
|
|
3418
3420
|
if (changed) store.upsert(existing);
|
|
3419
3421
|
store.touch(hash);
|
|
3420
|
-
res
|
|
3421
|
-
res.end("OK");
|
|
3422
|
+
sendOk(res, 200, "Asset Already Exists");
|
|
3422
3423
|
return;
|
|
3423
3424
|
}
|
|
3424
3425
|
const tmpPath = `${filePath}.tmp.${nanoid()}`;
|
|
@@ -3446,26 +3447,22 @@ function createAssetHttpServer(store) {
|
|
|
3446
3447
|
} }), writeStream, (err) => {
|
|
3447
3448
|
if (err) {
|
|
3448
3449
|
cleanup();
|
|
3449
|
-
if (err.message === "PayloadTooLarge")
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
else {
|
|
3450
|
+
if (err.message === "PayloadTooLarge") sendError(res, 413, "Payload Too Large");
|
|
3451
|
+
else if (err.code === "ERR_STREAM_PREMATURE_CLOSE") {
|
|
3452
|
+
log.warn({ hash }, "Upload request closed prematurely.");
|
|
3453
|
+
sendError(res, 400, "Upload Incomplete");
|
|
3454
|
+
} else {
|
|
3454
3455
|
log.error({
|
|
3455
3456
|
error: err,
|
|
3456
3457
|
hash
|
|
3457
3458
|
}, "Upload pipeline failed.");
|
|
3458
|
-
if (!res.headersSent)
|
|
3459
|
-
res.writeHead(500);
|
|
3460
|
-
res.end("Internal Server Error");
|
|
3461
|
-
}
|
|
3459
|
+
if (!res.headersSent) sendError(res, 500, "Internal Server Error");
|
|
3462
3460
|
}
|
|
3463
3461
|
return;
|
|
3464
3462
|
}
|
|
3465
|
-
if (hasher.digest("hex") !== hash) {
|
|
3463
|
+
if (hasher.digest("hex").slice(0, MCP_HASH_HEX_LENGTH) !== hash) {
|
|
3466
3464
|
cleanup();
|
|
3467
|
-
res
|
|
3468
|
-
res.end("Hash Mismatch");
|
|
3465
|
+
sendError(res, 400, "Hash Mismatch");
|
|
3469
3466
|
return;
|
|
3470
3467
|
}
|
|
3471
3468
|
try {
|
|
@@ -3476,8 +3473,7 @@ function createAssetHttpServer(store) {
|
|
|
3476
3473
|
hash
|
|
3477
3474
|
}, "Failed to rename temp file to asset.");
|
|
3478
3475
|
cleanup();
|
|
3479
|
-
res
|
|
3480
|
-
res.end("Internal Server Error");
|
|
3476
|
+
sendError(res, 500, "Internal Server Error");
|
|
3481
3477
|
return;
|
|
3482
3478
|
}
|
|
3483
3479
|
store.upsert({
|
|
@@ -3491,10 +3487,26 @@ function createAssetHttpServer(store) {
|
|
|
3491
3487
|
hash,
|
|
3492
3488
|
size
|
|
3493
3489
|
}, "Stored uploaded asset via HTTP.");
|
|
3494
|
-
res
|
|
3495
|
-
|
|
3490
|
+
sendOk(res, 201, "Created", {
|
|
3491
|
+
hash,
|
|
3492
|
+
size
|
|
3493
|
+
});
|
|
3496
3494
|
});
|
|
3497
3495
|
}
|
|
3496
|
+
function sendError(res, status, message, details) {
|
|
3497
|
+
if (!res.headersSent) res.writeHead(status, { "Content-Type": "application/json; charset=utf-8" });
|
|
3498
|
+
res.end(JSON.stringify({
|
|
3499
|
+
error: message,
|
|
3500
|
+
...details
|
|
3501
|
+
}));
|
|
3502
|
+
}
|
|
3503
|
+
function sendOk(res, status, message, data) {
|
|
3504
|
+
if (!res.headersSent) res.writeHead(status, { "Content-Type": "application/json; charset=utf-8" });
|
|
3505
|
+
res.end(JSON.stringify({
|
|
3506
|
+
message,
|
|
3507
|
+
...data
|
|
3508
|
+
}));
|
|
3509
|
+
}
|
|
3498
3510
|
return {
|
|
3499
3511
|
start,
|
|
3500
3512
|
stop,
|
|
@@ -3792,7 +3804,7 @@ function createCodeToolResponse(payload) {
|
|
|
3792
3804
|
summary.push(`Generated \`${payload.lang}\` snippet (${formatBytes$1(codeSize)}).`);
|
|
3793
3805
|
if (payload.message) summary.push(payload.message);
|
|
3794
3806
|
summary.push(payload.assets.length ? `Assets attached: ${payload.assets.length}. Fetch bytes via resources/read using resourceUri.` : "No binary assets were attached to this response.");
|
|
3795
|
-
const tokenCount = payload.usedTokens ? Object.keys(payload.usedTokens
|
|
3807
|
+
const tokenCount = payload.usedTokens ? Object.keys(payload.usedTokens ?? {}).length : 0;
|
|
3796
3808
|
if (tokenCount) summary.push(`Token references included: ${tokenCount}.`);
|
|
3797
3809
|
summary.push("Read structuredContent for the full code string and asset metadata.");
|
|
3798
3810
|
const assetLinks = payload.assets.length > 0 ? payload.assets.map((asset) => createAssetResourceLinkBlock$1(asset)) : [];
|