@mcpjam/cli 3.8.0 → 3.10.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/dist/index.js +551 -22
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command, CommanderError } from 'commander';
|
|
3
|
-
import { realpathSync,
|
|
3
|
+
import { realpathSync, mkdirSync, writeFileSync, readFileSync, existsSync, statSync, closeSync, renameSync, openSync } from 'fs';
|
|
4
4
|
import { pathToFileURL, fileURLToPath } from 'url';
|
|
5
5
|
import { probeMcpServer, redactSensitiveValue, runServerDoctor, collectServerSnapshot, serializeStableServerSnapshot, serializeServerSnapshot, buildServerDiffReport, validateToolCallResult, isCallToolResultError, buildToolCallValidationReport, listResources, readResource, listPrompts, getPrompt, MCPAppsConformanceTest, MCPAppsConformanceSuite, runOAuthLogin, OAuthConformanceTest, OAuthConformanceSuite, MCPConformanceTest, MCPConformanceSuite, withEphemeralClient, diffServerSnapshots, ServerSnapshotFormatError, renderStructuredRunJUnitXml, renderStructuredRunJson, toConformanceReport, renderConformanceReportJUnitXml, renderConformanceReportJson, formatOAuthConformanceHuman, formatOAuthConformanceSuiteHuman, fetchOAuthMetadata, executeOAuthProxy, executeDebugOAuthProxy, generateRandomString, generateCodeChallenge, createInteractiveAuthorizationSession, openUrlInBrowser, MCPClientManager, MCP_APPS_CHECK_CATEGORIES, MCP_APPS_CHECK_IDS, OAuthProxyError, MCP_CHECK_CATEGORIES, MCP_CHECK_IDS } from '@mcpjam/sdk';
|
|
6
6
|
import { mkdir, writeFile, readFile, chmod, rename, rm } from 'fs/promises';
|
|
7
|
-
import path2, {
|
|
7
|
+
import path2, { dirname, join, basename } from 'path';
|
|
8
8
|
import { randomUUID } from 'crypto';
|
|
9
9
|
import { spawn } from 'child_process';
|
|
10
10
|
import os, { homedir } from 'os';
|
|
11
|
-
import { createTunnelOperation, DEFAULT_PLATFORM_API_BASE_URL, PlatformApiClient, isPlatformApiError, PlatformApiError, listProjectsOperation, listProjectServersOperation, showServersOperation, createEvalSuiteOperation, listEvalSuitesOperation, runEvalSuiteOperation, getEvalRunOperation } from '@mcpjam/sdk/platform';
|
|
11
|
+
import { listEvalRunIterationsOperation, getEvalIterationTraceOperation, getEvalSuiteOperation, updateEvalSuiteOperation, deleteEvalSuiteOperation, setEvalSuiteScheduleOperation, listEvalCasesOperation, getEvalCaseOperation, createEvalCaseOperation, updateEvalCaseOperation, deleteEvalCaseOperation, generateEvalCasesOperation, createTunnelOperation, DEFAULT_PLATFORM_API_BASE_URL, PlatformApiClient, isPlatformApiError, PlatformApiError, listProjectsOperation, listProjectServersOperation, showServersOperation, createEvalSuiteOperation, listEvalSuitesOperation, runEvalSuiteOperation, getEvalRunOperation } from '@mcpjam/sdk/platform';
|
|
12
12
|
import { StdioServerTransport, McpServer } from '@modelcontextprotocol/server';
|
|
13
13
|
import { z } from 'zod';
|
|
14
14
|
import { PostHog } from 'posthog-node';
|
|
@@ -19,7 +19,7 @@ import { WebSocket } from 'ws';
|
|
|
19
19
|
|
|
20
20
|
// package.json
|
|
21
21
|
var package_default = {
|
|
22
|
-
version: "3.
|
|
22
|
+
version: "3.10.0"};
|
|
23
23
|
|
|
24
24
|
// src/lib/output.ts
|
|
25
25
|
var DEFAULT_OUTPUT_FORMAT = "json";
|
|
@@ -3382,6 +3382,91 @@ function registerAuthCommands(program) {
|
|
|
3382
3382
|
}
|
|
3383
3383
|
});
|
|
3384
3384
|
}
|
|
3385
|
+
|
|
3386
|
+
// src/lib/eval-screenshots.ts
|
|
3387
|
+
function asRecord(value) {
|
|
3388
|
+
return typeof value === "object" && value !== null ? value : null;
|
|
3389
|
+
}
|
|
3390
|
+
function asString(value) {
|
|
3391
|
+
return typeof value === "string" ? value : void 0;
|
|
3392
|
+
}
|
|
3393
|
+
function extractRenderedScreenshots(result) {
|
|
3394
|
+
const root = asRecord(result);
|
|
3395
|
+
if (!root) return [];
|
|
3396
|
+
const trace = asRecord(root.trace) ?? root;
|
|
3397
|
+
const observations = trace.widgetRenderObservations;
|
|
3398
|
+
if (!Array.isArray(observations)) return [];
|
|
3399
|
+
const screenshots = [];
|
|
3400
|
+
for (const entry of observations) {
|
|
3401
|
+
const obs = asRecord(entry);
|
|
3402
|
+
if (!obs) continue;
|
|
3403
|
+
const status = asString(obs.status);
|
|
3404
|
+
const screenshotUrl = asString(obs.screenshotUrl);
|
|
3405
|
+
if (status !== "rendered" || !screenshotUrl) continue;
|
|
3406
|
+
screenshots.push({
|
|
3407
|
+
status,
|
|
3408
|
+
screenshotUrl,
|
|
3409
|
+
toolName: asString(obs.toolName),
|
|
3410
|
+
toolCallId: asString(obs.toolCallId),
|
|
3411
|
+
promptIndex: typeof obs.promptIndex === "number" ? obs.promptIndex : void 0
|
|
3412
|
+
});
|
|
3413
|
+
}
|
|
3414
|
+
return screenshots;
|
|
3415
|
+
}
|
|
3416
|
+
function screenshotFilename(shot, index) {
|
|
3417
|
+
const tool = (shot.toolName ?? "widget").replace(/[^a-zA-Z0-9_-]+/g, "-");
|
|
3418
|
+
const suffix = shot.toolCallId ? shot.toolCallId.replace(/[^a-zA-Z0-9_-]+/g, "-") : String(index + 1);
|
|
3419
|
+
return `${tool}-${suffix}.png`;
|
|
3420
|
+
}
|
|
3421
|
+
|
|
3422
|
+
// src/lib/terminal-image.ts
|
|
3423
|
+
var ESC = "\x1B";
|
|
3424
|
+
var BEL = "\x07";
|
|
3425
|
+
function detectInlineImageProtocol(env = process.env, isTTY = process.stdout.isTTY) {
|
|
3426
|
+
if (!isTTY) return null;
|
|
3427
|
+
const termProgram = env.TERM_PROGRAM ?? "";
|
|
3428
|
+
const term = env.TERM ?? "";
|
|
3429
|
+
if (term === "xterm-kitty" || env.KITTY_WINDOW_ID !== void 0 || termProgram === "ghostty" || env.GHOSTTY_RESOURCES_DIR !== void 0) {
|
|
3430
|
+
return "kitty";
|
|
3431
|
+
}
|
|
3432
|
+
if (termProgram === "iTerm.app" || termProgram === "WezTerm" || termProgram === "WarpTerminal" || env.LC_TERMINAL === "iTerm2") {
|
|
3433
|
+
return "iterm";
|
|
3434
|
+
}
|
|
3435
|
+
return null;
|
|
3436
|
+
}
|
|
3437
|
+
function toBase64(data) {
|
|
3438
|
+
return Buffer.from(data).toString("base64");
|
|
3439
|
+
}
|
|
3440
|
+
function encodeIterm(data) {
|
|
3441
|
+
const payload = toBase64(data);
|
|
3442
|
+
const args = ["inline=1", `size=${data.byteLength}`, "preserveAspectRatio=1"].join(
|
|
3443
|
+
";"
|
|
3444
|
+
);
|
|
3445
|
+
return `${ESC}]1337;File=${args}:${payload}${BEL}
|
|
3446
|
+
`;
|
|
3447
|
+
}
|
|
3448
|
+
function encodeKitty(data) {
|
|
3449
|
+
const payload = toBase64(data);
|
|
3450
|
+
const CHUNK = 4096;
|
|
3451
|
+
const chunks = [];
|
|
3452
|
+
for (let offset = 0; offset < payload.length; offset += CHUNK) {
|
|
3453
|
+
chunks.push(payload.slice(offset, offset + CHUNK));
|
|
3454
|
+
}
|
|
3455
|
+
if (chunks.length === 0) chunks.push("");
|
|
3456
|
+
let out = "";
|
|
3457
|
+
chunks.forEach((chunk, index) => {
|
|
3458
|
+
const more = index < chunks.length - 1 ? 1 : 0;
|
|
3459
|
+
const control = index === 0 ? `a=T,f=100,m=${more}` : `m=${more}`;
|
|
3460
|
+
out += `${ESC}_G${control};${chunk}${ESC}\\`;
|
|
3461
|
+
});
|
|
3462
|
+
return `${out}
|
|
3463
|
+
`;
|
|
3464
|
+
}
|
|
3465
|
+
function encodeInlineImage(data, protocol) {
|
|
3466
|
+
return protocol === "kitty" ? encodeKitty(data) : encodeIterm(data);
|
|
3467
|
+
}
|
|
3468
|
+
|
|
3469
|
+
// src/commands/eval.ts
|
|
3385
3470
|
function addPlatformOptions(command) {
|
|
3386
3471
|
return command.option("--api-key <key>", "MCPJam sk_ API key (overrides MCPJAM_API_KEY)").option(
|
|
3387
3472
|
"--api-url <url>",
|
|
@@ -3392,9 +3477,13 @@ async function runPlatformCommand(options, timeoutMs, execute) {
|
|
|
3392
3477
|
const controller = new AbortController();
|
|
3393
3478
|
const timeoutHandle = setTimeout(() => {
|
|
3394
3479
|
controller.abort(
|
|
3395
|
-
new PlatformApiError(
|
|
3396
|
-
|
|
3397
|
-
|
|
3480
|
+
new PlatformApiError(
|
|
3481
|
+
`Request timed out after ${timeoutMs}ms`,
|
|
3482
|
+
"TIMEOUT",
|
|
3483
|
+
{
|
|
3484
|
+
status: 0
|
|
3485
|
+
}
|
|
3486
|
+
)
|
|
3398
3487
|
);
|
|
3399
3488
|
}, timeoutMs);
|
|
3400
3489
|
timeoutHandle.unref?.();
|
|
@@ -3460,6 +3549,135 @@ function loadSuiteDefinition(options) {
|
|
|
3460
3549
|
}
|
|
3461
3550
|
return parsed.data;
|
|
3462
3551
|
}
|
|
3552
|
+
function loadBodyObject(options) {
|
|
3553
|
+
if (options.file !== void 0 && options.json !== void 0) {
|
|
3554
|
+
throw usageError("Provide either --file or --json, not both.");
|
|
3555
|
+
}
|
|
3556
|
+
let base = {};
|
|
3557
|
+
if (options.file !== void 0) {
|
|
3558
|
+
const text = readFileOrStdin(options.file, "--file");
|
|
3559
|
+
if (text.trim() === "") throw usageError("--file input is empty.");
|
|
3560
|
+
try {
|
|
3561
|
+
base = JSON.parse(text);
|
|
3562
|
+
} catch (error) {
|
|
3563
|
+
throw usageError("--file must contain valid JSON.", {
|
|
3564
|
+
source: error instanceof Error ? error.message : String(error)
|
|
3565
|
+
});
|
|
3566
|
+
}
|
|
3567
|
+
} else if (options.json !== void 0) {
|
|
3568
|
+
base = new JsonInputContext().parseJsonInputRecord(options.json, "--json");
|
|
3569
|
+
}
|
|
3570
|
+
if (base === void 0 || base === null) base = {};
|
|
3571
|
+
if (typeof base !== "object" || Array.isArray(base)) {
|
|
3572
|
+
throw usageError("Body must be a JSON object.");
|
|
3573
|
+
}
|
|
3574
|
+
return base;
|
|
3575
|
+
}
|
|
3576
|
+
function validateOpInput(op, raw) {
|
|
3577
|
+
const parsed = op.inputSchema.safeParse(raw);
|
|
3578
|
+
if (!parsed.success) {
|
|
3579
|
+
const detail = parsed.error.issues.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`).join("; ");
|
|
3580
|
+
throw usageError(`Invalid input: ${detail}`);
|
|
3581
|
+
}
|
|
3582
|
+
return parsed.data;
|
|
3583
|
+
}
|
|
3584
|
+
async function executeOp(op, input, options, command) {
|
|
3585
|
+
const globalOptions = getGlobalOptions(command);
|
|
3586
|
+
const result = await runPlatformCommand(
|
|
3587
|
+
options,
|
|
3588
|
+
globalOptions.timeout,
|
|
3589
|
+
({ client, signal }) => op.execute(input, { client, signal })
|
|
3590
|
+
);
|
|
3591
|
+
writeResult(result, globalOptions.format);
|
|
3592
|
+
}
|
|
3593
|
+
function buildSuiteUpdateInput(options) {
|
|
3594
|
+
const input = { ...loadBodyObject(options) };
|
|
3595
|
+
input.suite = options.suite;
|
|
3596
|
+
if (options.project !== void 0) input.project = options.project;
|
|
3597
|
+
if (options.name !== void 0) input.name = options.name;
|
|
3598
|
+
if (options.description !== void 0)
|
|
3599
|
+
input.description = options.description;
|
|
3600
|
+
if (options.server !== void 0)
|
|
3601
|
+
input.environment = {
|
|
3602
|
+
...input.environment ?? {},
|
|
3603
|
+
servers: options.server
|
|
3604
|
+
};
|
|
3605
|
+
if (options.host !== void 0)
|
|
3606
|
+
input.hosts = options.host.map((host) => ({ host }));
|
|
3607
|
+
const exec = { ...input.executionConfig ?? {} };
|
|
3608
|
+
if (options.model !== void 0) exec.model = options.model;
|
|
3609
|
+
if (options.systemPrompt !== void 0)
|
|
3610
|
+
exec.systemPrompt = options.systemPrompt;
|
|
3611
|
+
if (options.temperature !== void 0)
|
|
3612
|
+
exec.temperature = Number(options.temperature);
|
|
3613
|
+
if (Object.keys(exec).length > 0) input.executionConfig = exec;
|
|
3614
|
+
const settings = { ...input.settings ?? {} };
|
|
3615
|
+
if (options.minAccuracy !== void 0)
|
|
3616
|
+
settings.minimumAccuracy = Number(options.minAccuracy);
|
|
3617
|
+
const mo = { ...settings.matchOptions ?? {} };
|
|
3618
|
+
if (options.toolCallOrder !== void 0)
|
|
3619
|
+
mo.toolCallOrder = options.toolCallOrder;
|
|
3620
|
+
if (options.arguments !== void 0) mo.arguments = options.arguments;
|
|
3621
|
+
if (options.extraToolCalls !== void 0)
|
|
3622
|
+
mo.extraToolCalls = options.extraToolCalls === "unlimited" ? "unlimited" : Number(options.extraToolCalls);
|
|
3623
|
+
if (Object.keys(mo).length > 0) settings.matchOptions = mo;
|
|
3624
|
+
const judge = { ...settings.judge ?? {} };
|
|
3625
|
+
if (options.judge !== void 0) {
|
|
3626
|
+
if (options.judge !== "on" && options.judge !== "off") {
|
|
3627
|
+
throw usageError('--judge must be "on" or "off".');
|
|
3628
|
+
}
|
|
3629
|
+
judge.enabled = options.judge === "on";
|
|
3630
|
+
}
|
|
3631
|
+
if (options.judgeModel !== void 0) judge.model = options.judgeModel;
|
|
3632
|
+
if (Object.keys(judge).length > 0) settings.judge = judge;
|
|
3633
|
+
if (Object.keys(settings).length > 0) input.settings = settings;
|
|
3634
|
+
return input;
|
|
3635
|
+
}
|
|
3636
|
+
function buildCaseInput(options, opts) {
|
|
3637
|
+
const input = { ...loadBodyObject(options) };
|
|
3638
|
+
if (options.project !== void 0) input.project = options.project;
|
|
3639
|
+
input.suite = options.suite;
|
|
3640
|
+
if (opts.requireCase) input.case = options.case;
|
|
3641
|
+
if (options.title !== void 0) input.title = options.title;
|
|
3642
|
+
return input;
|
|
3643
|
+
}
|
|
3644
|
+
async function fetchScreenshotBytes(url, timeoutMs) {
|
|
3645
|
+
const controller = new AbortController();
|
|
3646
|
+
const handle = setTimeout(() => controller.abort(), timeoutMs);
|
|
3647
|
+
handle.unref?.();
|
|
3648
|
+
try {
|
|
3649
|
+
const response = await fetch(url, { signal: controller.signal });
|
|
3650
|
+
if (!response.ok) {
|
|
3651
|
+
throw operationalError(
|
|
3652
|
+
`Failed to download screenshot (HTTP ${response.status}).`,
|
|
3653
|
+
{ url }
|
|
3654
|
+
);
|
|
3655
|
+
}
|
|
3656
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
3657
|
+
} catch (error) {
|
|
3658
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
3659
|
+
throw operationalError(
|
|
3660
|
+
`Timed out downloading screenshot after ${timeoutMs}ms.`,
|
|
3661
|
+
{ url }
|
|
3662
|
+
);
|
|
3663
|
+
}
|
|
3664
|
+
throw error;
|
|
3665
|
+
} finally {
|
|
3666
|
+
clearTimeout(handle);
|
|
3667
|
+
}
|
|
3668
|
+
}
|
|
3669
|
+
function resolveScreenshotPath(out, shot, index, total) {
|
|
3670
|
+
const looksLikeDir = out.endsWith("/") || existsSync(out) && statSync(out).isDirectory();
|
|
3671
|
+
if (looksLikeDir) {
|
|
3672
|
+
return join(out, screenshotFilename(shot, index));
|
|
3673
|
+
}
|
|
3674
|
+
if (total > 1) {
|
|
3675
|
+
throw usageError(
|
|
3676
|
+
"--out must be a directory when the iteration rendered multiple screenshots."
|
|
3677
|
+
);
|
|
3678
|
+
}
|
|
3679
|
+
return out;
|
|
3680
|
+
}
|
|
3463
3681
|
function registerEvalCommands(program) {
|
|
3464
3682
|
const evals = program.command("eval").description("Author and run eval suites in your hosted MCPJam projects");
|
|
3465
3683
|
addPlatformOptions(
|
|
@@ -3474,7 +3692,10 @@ function registerEvalCommands(program) {
|
|
|
3474
3692
|
).option(
|
|
3475
3693
|
"--json <json>",
|
|
3476
3694
|
"Inline suite definition JSON (or @file, or - for stdin)"
|
|
3477
|
-
).option("--name <name>", "Suite name (overrides the file)").option(
|
|
3695
|
+
).option("--name <name>", "Suite name (overrides the file)").option(
|
|
3696
|
+
"--model <model>",
|
|
3697
|
+
"Suite-level default model (overrides the file)"
|
|
3698
|
+
).option(
|
|
3478
3699
|
"--provider <provider>",
|
|
3479
3700
|
"Suite-level default provider (overrides the file; needed for bare/custom model ids)"
|
|
3480
3701
|
).option(
|
|
@@ -3496,20 +3717,18 @@ function registerEvalCommands(program) {
|
|
|
3496
3717
|
"--project <id-or-name>",
|
|
3497
3718
|
"Project name or ID (defaults to the most recently updated project)"
|
|
3498
3719
|
)
|
|
3499
|
-
).action(
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
}
|
|
3512
|
-
);
|
|
3720
|
+
).action(async (options, command) => {
|
|
3721
|
+
const globalOptions = getGlobalOptions(command);
|
|
3722
|
+
const result = await runPlatformCommand(
|
|
3723
|
+
options,
|
|
3724
|
+
globalOptions.timeout,
|
|
3725
|
+
({ client, signal }) => listEvalSuitesOperation.execute(
|
|
3726
|
+
{ project: options.project },
|
|
3727
|
+
{ client, signal }
|
|
3728
|
+
)
|
|
3729
|
+
);
|
|
3730
|
+
writeResult(result, globalOptions.format);
|
|
3731
|
+
});
|
|
3513
3732
|
addPlatformOptions(
|
|
3514
3733
|
evals.command("run").description("Start an eval run of an existing suite (asynchronous)").requiredOption("--suite <id-or-name>", "Eval suite name or ID").option(
|
|
3515
3734
|
"--project <id-or-name>",
|
|
@@ -3552,6 +3771,316 @@ function registerEvalCommands(program) {
|
|
|
3552
3771
|
writeResult(result, globalOptions.format);
|
|
3553
3772
|
}
|
|
3554
3773
|
);
|
|
3774
|
+
const PROJECT_OPT = "Project name or ID (defaults to most recently updated)";
|
|
3775
|
+
addPlatformOptions(
|
|
3776
|
+
evals.command("iterations").description(
|
|
3777
|
+
"List per-iteration results for an eval run (pass/fail, tool calls, tokens, latency)"
|
|
3778
|
+
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption(
|
|
3779
|
+
"--project <id-or-name>",
|
|
3780
|
+
"Project the run belongs to (name or ID)"
|
|
3781
|
+
).option("--cursor <cursor>", "Pagination cursor from a previous response").option("--limit <n>", "Max iterations per page (1\u2013200)")
|
|
3782
|
+
).action(
|
|
3783
|
+
async (options, command) => {
|
|
3784
|
+
const input = validateOpInput(listEvalRunIterationsOperation, {
|
|
3785
|
+
project: options.project,
|
|
3786
|
+
runId: options.run,
|
|
3787
|
+
...options.cursor !== void 0 ? { cursor: options.cursor } : {},
|
|
3788
|
+
...options.limit !== void 0 ? { limit: Number(options.limit) } : {}
|
|
3789
|
+
});
|
|
3790
|
+
await executeOp(listEvalRunIterationsOperation, input, options, command);
|
|
3791
|
+
}
|
|
3792
|
+
);
|
|
3793
|
+
addPlatformOptions(
|
|
3794
|
+
evals.command("trace").description(
|
|
3795
|
+
"Fetch the full trace for one eval iteration (large: full message history + spans)"
|
|
3796
|
+
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption(
|
|
3797
|
+
"--iteration <id>",
|
|
3798
|
+
"Iteration ID (from `eval iterations`)"
|
|
3799
|
+
).requiredOption(
|
|
3800
|
+
"--project <id-or-name>",
|
|
3801
|
+
"Project the run belongs to (name or ID)"
|
|
3802
|
+
)
|
|
3803
|
+
).action(
|
|
3804
|
+
async (options, command) => {
|
|
3805
|
+
await executeOp(
|
|
3806
|
+
getEvalIterationTraceOperation,
|
|
3807
|
+
{
|
|
3808
|
+
project: options.project,
|
|
3809
|
+
runId: options.run,
|
|
3810
|
+
iterationId: options.iteration
|
|
3811
|
+
},
|
|
3812
|
+
options,
|
|
3813
|
+
command
|
|
3814
|
+
);
|
|
3815
|
+
}
|
|
3816
|
+
);
|
|
3817
|
+
addPlatformOptions(
|
|
3818
|
+
evals.command("screenshot").description(
|
|
3819
|
+
"Show the widget screenshot(s) an eval iteration rendered \u2014 inline when the terminal supports it, otherwise the image URL"
|
|
3820
|
+
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption(
|
|
3821
|
+
"--iteration <id>",
|
|
3822
|
+
"Iteration ID (from `eval iterations`)"
|
|
3823
|
+
).requiredOption(
|
|
3824
|
+
"--project <id-or-name>",
|
|
3825
|
+
"Project the run belongs to (name or ID)"
|
|
3826
|
+
).option(
|
|
3827
|
+
"--out <path>",
|
|
3828
|
+
"Save the PNG(s) to a file or directory instead of rendering inline"
|
|
3829
|
+
).option("--index <n>", "Show only the Nth screenshot (1-based)")
|
|
3830
|
+
).action(
|
|
3831
|
+
async (options, command) => {
|
|
3832
|
+
const globalOptions = getGlobalOptions(command);
|
|
3833
|
+
const index = options.index !== void 0 ? parsePositiveInteger(options.index, "--index") : void 0;
|
|
3834
|
+
const result = await runPlatformCommand(
|
|
3835
|
+
options,
|
|
3836
|
+
globalOptions.timeout,
|
|
3837
|
+
({ client, signal }) => getEvalIterationTraceOperation.execute(
|
|
3838
|
+
{
|
|
3839
|
+
project: options.project,
|
|
3840
|
+
runId: options.run,
|
|
3841
|
+
iterationId: options.iteration
|
|
3842
|
+
},
|
|
3843
|
+
{ client, signal }
|
|
3844
|
+
)
|
|
3845
|
+
);
|
|
3846
|
+
let shots = extractRenderedScreenshots(result);
|
|
3847
|
+
if (index !== void 0) {
|
|
3848
|
+
if (index > shots.length) {
|
|
3849
|
+
throw usageError(
|
|
3850
|
+
`--index ${index} is out of range; this iteration rendered ${shots.length} screenshot(s).`
|
|
3851
|
+
);
|
|
3852
|
+
}
|
|
3853
|
+
shots = [shots[index - 1]];
|
|
3854
|
+
}
|
|
3855
|
+
const base = {
|
|
3856
|
+
project: result.project,
|
|
3857
|
+
runId: result.runId,
|
|
3858
|
+
iterationId: result.iterationId
|
|
3859
|
+
};
|
|
3860
|
+
const isJson = globalOptions.format === "json";
|
|
3861
|
+
if (options.out !== void 0) {
|
|
3862
|
+
const saved = [];
|
|
3863
|
+
for (let i = 0; i < shots.length; i += 1) {
|
|
3864
|
+
const shot = shots[i];
|
|
3865
|
+
const bytes = await fetchScreenshotBytes(
|
|
3866
|
+
shot.screenshotUrl,
|
|
3867
|
+
globalOptions.timeout
|
|
3868
|
+
);
|
|
3869
|
+
const path6 = resolveScreenshotPath(
|
|
3870
|
+
options.out,
|
|
3871
|
+
shot,
|
|
3872
|
+
i,
|
|
3873
|
+
shots.length
|
|
3874
|
+
);
|
|
3875
|
+
mkdirSync(dirname(path6), { recursive: true });
|
|
3876
|
+
writeFileSync(path6, bytes);
|
|
3877
|
+
saved.push({ ...shot, savedTo: path6 });
|
|
3878
|
+
}
|
|
3879
|
+
if (isJson) {
|
|
3880
|
+
writeResult({ ...base, items: saved });
|
|
3881
|
+
return;
|
|
3882
|
+
}
|
|
3883
|
+
if (saved.length === 0) {
|
|
3884
|
+
process.stdout.write(
|
|
3885
|
+
"No rendered widget screenshots for this iteration.\n"
|
|
3886
|
+
);
|
|
3887
|
+
return;
|
|
3888
|
+
}
|
|
3889
|
+
for (const shot of saved) {
|
|
3890
|
+
process.stdout.write(
|
|
3891
|
+
`Saved ${shot.toolName ?? "widget"} \u2192 ${shot.savedTo}
|
|
3892
|
+
`
|
|
3893
|
+
);
|
|
3894
|
+
}
|
|
3895
|
+
return;
|
|
3896
|
+
}
|
|
3897
|
+
if (isJson) {
|
|
3898
|
+
writeResult({ ...base, items: shots });
|
|
3899
|
+
return;
|
|
3900
|
+
}
|
|
3901
|
+
if (shots.length === 0) {
|
|
3902
|
+
process.stdout.write(
|
|
3903
|
+
"No rendered widget screenshots for this iteration.\n"
|
|
3904
|
+
);
|
|
3905
|
+
return;
|
|
3906
|
+
}
|
|
3907
|
+
const protocol = detectInlineImageProtocol();
|
|
3908
|
+
for (const shot of shots) {
|
|
3909
|
+
const caption = `${shot.toolName ?? "widget"} \xB7 ${shot.status}`;
|
|
3910
|
+
if (protocol) {
|
|
3911
|
+
const bytes = await fetchScreenshotBytes(
|
|
3912
|
+
shot.screenshotUrl,
|
|
3913
|
+
globalOptions.timeout
|
|
3914
|
+
);
|
|
3915
|
+
process.stdout.write(`${caption}
|
|
3916
|
+
`);
|
|
3917
|
+
process.stdout.write(encodeInlineImage(bytes, protocol));
|
|
3918
|
+
} else {
|
|
3919
|
+
process.stdout.write(`${caption} ${shot.screenshotUrl}
|
|
3920
|
+
`);
|
|
3921
|
+
}
|
|
3922
|
+
}
|
|
3923
|
+
}
|
|
3924
|
+
);
|
|
3925
|
+
addPlatformOptions(
|
|
3926
|
+
evals.command("get").description("Show an eval suite's full settings").requiredOption("--suite <id-or-name>", "Eval suite name or ID").option("--project <id-or-name>", PROJECT_OPT)
|
|
3927
|
+
).action(
|
|
3928
|
+
async (options, command) => {
|
|
3929
|
+
await executeOp(
|
|
3930
|
+
getEvalSuiteOperation,
|
|
3931
|
+
{ project: options.project, suite: options.suite },
|
|
3932
|
+
options,
|
|
3933
|
+
command
|
|
3934
|
+
);
|
|
3935
|
+
}
|
|
3936
|
+
);
|
|
3937
|
+
addPlatformOptions(
|
|
3938
|
+
evals.command("update").description(
|
|
3939
|
+
"Edit an eval suite's settings (only the flags you pass change)"
|
|
3940
|
+
).requiredOption("--suite <id-or-name>", "Eval suite name or ID").option("--project <id-or-name>", PROJECT_OPT).option("--file <path>", "Suite-update JSON body (or - for stdin)").option("--json <json>", "Inline suite-update JSON (or @file, or -)").option("--name <name>", "Rename the suite").option("--description <text>", "Suite description").option(
|
|
3941
|
+
"--server <name...>",
|
|
3942
|
+
"Replace the suite's server selection (project server names)"
|
|
3943
|
+
).option("--host <name...>", "Replace host attachments (by name/ID)").option("--model <id>", "Execution model id").option("--system-prompt <text>", "Execution system prompt").option("--temperature <n>", "Execution temperature").option("--min-accuracy <pct>", "Minimum accuracy, 0\u2013100").option("--tool-call-order <any|in-order|exact>", "Tool call order").option("--arguments <ignore|partial|exact>", "Argument matching").option("--extra-tool-calls <unlimited|N>", "Allowed extra tool calls").option("--judge <on|off>", "Enable/disable LLM-as-judge grading").option("--judge-model <id>", "Judge model id")
|
|
3944
|
+
).action(async (options, command) => {
|
|
3945
|
+
const input = validateOpInput(
|
|
3946
|
+
updateEvalSuiteOperation,
|
|
3947
|
+
buildSuiteUpdateInput(options)
|
|
3948
|
+
);
|
|
3949
|
+
await executeOp(updateEvalSuiteOperation, input, options, command);
|
|
3950
|
+
});
|
|
3951
|
+
addPlatformOptions(
|
|
3952
|
+
evals.command("delete").description("Permanently delete an eval suite (and its cases and runs)").requiredOption("--suite <id-or-name>", "Eval suite name or ID").option("--project <id-or-name>", PROJECT_OPT)
|
|
3953
|
+
).action(
|
|
3954
|
+
async (options, command) => {
|
|
3955
|
+
await executeOp(
|
|
3956
|
+
deleteEvalSuiteOperation,
|
|
3957
|
+
{ project: options.project, suite: options.suite },
|
|
3958
|
+
options,
|
|
3959
|
+
command
|
|
3960
|
+
);
|
|
3961
|
+
}
|
|
3962
|
+
);
|
|
3963
|
+
addPlatformOptions(
|
|
3964
|
+
evals.command("schedule").description("Enable or disable scheduled runs for a suite").requiredOption("--suite <id-or-name>", "Eval suite name or ID").option("--project <id-or-name>", PROJECT_OPT).option("--enable", "Enable scheduled runs").option("--disable", "Disable scheduled runs").option("--interval <minutes>", "Run interval in minutes (5\u201310080)")
|
|
3965
|
+
).action(
|
|
3966
|
+
async (options, command) => {
|
|
3967
|
+
if (options.enable && options.disable) {
|
|
3968
|
+
throw usageError("Pass either --enable or --disable, not both.");
|
|
3969
|
+
}
|
|
3970
|
+
if (!options.enable && !options.disable) {
|
|
3971
|
+
throw usageError("Pass --enable or --disable.");
|
|
3972
|
+
}
|
|
3973
|
+
const input = validateOpInput(setEvalSuiteScheduleOperation, {
|
|
3974
|
+
project: options.project,
|
|
3975
|
+
suite: options.suite,
|
|
3976
|
+
enabled: Boolean(options.enable),
|
|
3977
|
+
...options.interval !== void 0 ? { intervalMinutes: Number(options.interval) } : {}
|
|
3978
|
+
});
|
|
3979
|
+
await executeOp(setEvalSuiteScheduleOperation, input, options, command);
|
|
3980
|
+
}
|
|
3981
|
+
);
|
|
3982
|
+
const cases = evals.command("cases").description("List, author, and edit an eval suite's test cases");
|
|
3983
|
+
addPlatformOptions(
|
|
3984
|
+
cases.command("list").description("List a suite's test cases").requiredOption("--suite <id-or-name>", "Eval suite name or ID").option("--project <id-or-name>", PROJECT_OPT)
|
|
3985
|
+
).action(
|
|
3986
|
+
async (options, command) => {
|
|
3987
|
+
await executeOp(
|
|
3988
|
+
listEvalCasesOperation,
|
|
3989
|
+
{ project: options.project, suite: options.suite },
|
|
3990
|
+
options,
|
|
3991
|
+
command
|
|
3992
|
+
);
|
|
3993
|
+
}
|
|
3994
|
+
);
|
|
3995
|
+
addPlatformOptions(
|
|
3996
|
+
cases.command("get").description("Show one test case").requiredOption("--suite <id-or-name>", "Eval suite name or ID").requiredOption("--case <id-or-title>", "Eval case title or ID").option("--project <id-or-name>", PROJECT_OPT)
|
|
3997
|
+
).action(
|
|
3998
|
+
async (options, command) => {
|
|
3999
|
+
await executeOp(
|
|
4000
|
+
getEvalCaseOperation,
|
|
4001
|
+
{ project: options.project, suite: options.suite, case: options.case },
|
|
4002
|
+
options,
|
|
4003
|
+
command
|
|
4004
|
+
);
|
|
4005
|
+
}
|
|
4006
|
+
);
|
|
4007
|
+
addPlatformOptions(
|
|
4008
|
+
cases.command("create").description("Add a test case to a suite (definition via --file/--json)").requiredOption("--suite <id-or-name>", "Eval suite name or ID").option("--project <id-or-name>", PROJECT_OPT).option("--file <path>", "Case JSON body (or - for stdin)").option("--json <json>", "Inline case JSON (or @file, or -)").option("--title <title>", "Case title (overrides the body)")
|
|
4009
|
+
).action(async (options, command) => {
|
|
4010
|
+
const input = validateOpInput(
|
|
4011
|
+
createEvalCaseOperation,
|
|
4012
|
+
buildCaseInput(options, { requireCase: false })
|
|
4013
|
+
);
|
|
4014
|
+
await executeOp(createEvalCaseOperation, input, options, command);
|
|
4015
|
+
});
|
|
4016
|
+
addPlatformOptions(
|
|
4017
|
+
cases.command("update").description("Edit a test case (definition via --file/--json)").requiredOption("--suite <id-or-name>", "Eval suite name or ID").requiredOption("--case <id-or-title>", "Eval case title or ID").option("--project <id-or-name>", PROJECT_OPT).option("--file <path>", "Case JSON body (or - for stdin)").option("--json <json>", "Inline case JSON (or @file, or -)").option("--title <title>", "Rename the case")
|
|
4018
|
+
).action(async (options, command) => {
|
|
4019
|
+
const input = validateOpInput(
|
|
4020
|
+
updateEvalCaseOperation,
|
|
4021
|
+
buildCaseInput(options, { requireCase: true })
|
|
4022
|
+
);
|
|
4023
|
+
await executeOp(updateEvalCaseOperation, input, options, command);
|
|
4024
|
+
});
|
|
4025
|
+
addPlatformOptions(
|
|
4026
|
+
cases.command("delete").description("Permanently delete a test case").requiredOption("--suite <id-or-name>", "Eval suite name or ID").requiredOption("--case <id-or-title>", "Eval case title or ID").option("--project <id-or-name>", PROJECT_OPT)
|
|
4027
|
+
).action(
|
|
4028
|
+
async (options, command) => {
|
|
4029
|
+
await executeOp(
|
|
4030
|
+
deleteEvalCaseOperation,
|
|
4031
|
+
{ project: options.project, suite: options.suite, case: options.case },
|
|
4032
|
+
options,
|
|
4033
|
+
command
|
|
4034
|
+
);
|
|
4035
|
+
}
|
|
4036
|
+
);
|
|
4037
|
+
addPlatformOptions(
|
|
4038
|
+
cases.command("generate").description(
|
|
4039
|
+
"AI-generate test cases from the suite's tools (spends credits)"
|
|
4040
|
+
).requiredOption("--suite <id-or-name>", "Eval suite name or ID").option("--project <id-or-name>", PROJECT_OPT).option("--mode <normal|negative>", "Generation mode (default normal)").option(
|
|
4041
|
+
"--server <name...>",
|
|
4042
|
+
"Servers to discover tools from (default: suite's)"
|
|
4043
|
+
).option(
|
|
4044
|
+
"--case-model <id...>",
|
|
4045
|
+
"Execution model(s) for the generated cases"
|
|
4046
|
+
).option("--simple <n>", "How many easy, single-tool cases").option("--multi-tool <n>", "How many medium, 2+ tool cases").option("--multi-turn <n>", "How many multi-turn follow-up cases").option("--complex <n>", "How many hard / cross-server cases").option("--negative <n>", "How many negative (no-tool) cases").option(
|
|
4047
|
+
"--vary-user-styles",
|
|
4048
|
+
"Vary query phrasing across a realistic range of user styles"
|
|
4049
|
+
)
|
|
4050
|
+
).action(
|
|
4051
|
+
async (options, command) => {
|
|
4052
|
+
const caseMix = {};
|
|
4053
|
+
for (const key of [
|
|
4054
|
+
"simple",
|
|
4055
|
+
"multiTool",
|
|
4056
|
+
"multiTurn",
|
|
4057
|
+
"complex",
|
|
4058
|
+
"negative"
|
|
4059
|
+
]) {
|
|
4060
|
+
const raw = options[key];
|
|
4061
|
+
if (raw !== void 0) {
|
|
4062
|
+
const parsed = Number(raw);
|
|
4063
|
+
if (!Number.isInteger(parsed)) {
|
|
4064
|
+
const flag = key.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
|
|
4065
|
+
throw usageError(
|
|
4066
|
+
`--${flag} requires an integer value, got "${raw}".`
|
|
4067
|
+
);
|
|
4068
|
+
}
|
|
4069
|
+
caseMix[key] = parsed;
|
|
4070
|
+
}
|
|
4071
|
+
}
|
|
4072
|
+
const input = validateOpInput(generateEvalCasesOperation, {
|
|
4073
|
+
project: options.project,
|
|
4074
|
+
suite: options.suite,
|
|
4075
|
+
...options.mode ? { mode: options.mode } : {},
|
|
4076
|
+
...options.server ? { servers: options.server } : {},
|
|
4077
|
+
...options.caseModel ? { caseModels: options.caseModel.map((model) => ({ model })) } : {},
|
|
4078
|
+
...Object.keys(caseMix).length > 0 ? { caseMix } : {},
|
|
4079
|
+
...options.varyUserStyles ? { varyUserStyles: true } : {}
|
|
4080
|
+
});
|
|
4081
|
+
await executeOp(generateEvalCasesOperation, input, options, command);
|
|
4082
|
+
}
|
|
4083
|
+
);
|
|
3555
4084
|
}
|
|
3556
4085
|
|
|
3557
4086
|
// src/lib/server-doctor.ts
|