@root-signals/scorable-cli 0.12.0 → 0.14.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 +60 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -0
- package/dist/commands/auth/index.d.ts.map +1 -1
- package/dist/commands/auth/index.js +68 -1
- package/dist/commands/evaluator/create.d.ts.map +1 -1
- package/dist/commands/evaluator/create.js +11 -5
- package/dist/commands/evaluator/duplicate.d.ts.map +1 -1
- package/dist/commands/evaluator/duplicate.js +5 -2
- package/dist/commands/evaluator/execute-by-name.d.ts +2 -0
- package/dist/commands/evaluator/execute-by-name.d.ts.map +1 -1
- package/dist/commands/evaluator/execute-by-name.js +27 -2
- package/dist/commands/evaluator/execute.d.ts +2 -0
- package/dist/commands/evaluator/execute.d.ts.map +1 -1
- package/dist/commands/evaluator/execute.js +27 -2
- package/dist/commands/evaluator/export-yaml.d.ts.map +1 -1
- package/dist/commands/evaluator/export-yaml.js +10 -1
- package/dist/commands/evaluator/import-yaml.d.ts.map +1 -1
- package/dist/commands/evaluator/import-yaml.js +10 -1
- package/dist/commands/evaluator/list.d.ts.map +1 -1
- package/dist/commands/evaluator/list.js +5 -0
- package/dist/commands/evaluator/update.d.ts.map +1 -1
- package/dist/commands/evaluator/update.js +11 -5
- package/dist/commands/execution-log/list.d.ts.map +1 -1
- package/dist/commands/execution-log/list.js +5 -0
- package/dist/commands/judge/create.d.ts.map +1 -1
- package/dist/commands/judge/create.js +12 -5
- package/dist/commands/judge/duplicate.d.ts.map +1 -1
- package/dist/commands/judge/duplicate.js +5 -2
- package/dist/commands/judge/exec-openai-generic.d.ts.map +1 -1
- package/dist/commands/judge/exec-openai-generic.js +21 -11
- package/dist/commands/judge/exec-openai.d.ts.map +1 -1
- package/dist/commands/judge/exec-openai.js +21 -11
- package/dist/commands/judge/execute-by-name.d.ts +2 -0
- package/dist/commands/judge/execute-by-name.d.ts.map +1 -1
- package/dist/commands/judge/execute-by-name.js +27 -2
- package/dist/commands/judge/execute.d.ts +2 -0
- package/dist/commands/judge/execute.d.ts.map +1 -1
- package/dist/commands/judge/execute.js +27 -2
- package/dist/commands/judge/generate.d.ts.map +1 -1
- package/dist/commands/judge/generate.js +9 -4
- package/dist/commands/judge/list.d.ts.map +1 -1
- package/dist/commands/judge/list.js +5 -0
- package/dist/commands/judge/update.d.ts.map +1 -1
- package/dist/commands/judge/update.js +12 -5
- package/dist/commands/otel-filter/create.d.ts.map +1 -1
- package/dist/commands/otel-filter/create.js +6 -6
- package/dist/commands/project/create.d.ts +3 -0
- package/dist/commands/project/create.d.ts.map +1 -0
- package/dist/commands/project/create.js +31 -0
- package/dist/commands/project/delete.d.ts +3 -0
- package/dist/commands/project/delete.d.ts.map +1 -0
- package/dist/commands/project/delete.js +37 -0
- package/dist/commands/project/get.d.ts +3 -0
- package/dist/commands/project/get.d.ts.map +1 -0
- package/dist/commands/project/get.js +23 -0
- package/dist/commands/project/index.d.ts +3 -0
- package/dist/commands/project/index.d.ts.map +1 -0
- package/dist/commands/project/index.js +17 -0
- package/dist/commands/project/list.d.ts +3 -0
- package/dist/commands/project/list.d.ts.map +1 -0
- package/dist/commands/project/list.js +39 -0
- package/dist/commands/project/set-default.d.ts +3 -0
- package/dist/commands/project/set-default.d.ts.map +1 -0
- package/dist/commands/project/set-default.js +23 -0
- package/dist/commands/project/update.d.ts +3 -0
- package/dist/commands/project/update.d.ts.map +1 -0
- package/dist/commands/project/update.js +37 -0
- package/dist/commands/prompt-test/init.d.ts.map +1 -1
- package/dist/commands/prompt-test/init.js +9 -2
- package/dist/commands/prompt-test/run.d.ts +1 -1
- package/dist/commands/prompt-test/run.d.ts.map +1 -1
- package/dist/commands/prompt-test/run.js +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/lib/filter-yaml.d.ts +8 -0
- package/dist/lib/filter-yaml.d.ts.map +1 -1
- package/dist/lib/filter-yaml.js +1 -1
- package/dist/lib/project-id.d.ts +9 -0
- package/dist/lib/project-id.d.ts.map +1 -0
- package/dist/lib/project-id.js +23 -0
- package/dist/output.d.ts +2 -1
- package/dist/output.d.ts.map +1 -1
- package/dist/output.js +71 -12
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +9 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +27 -7
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get.d.ts","sourceRoot":"","sources":["../../../src/commands/project/get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAkBzD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import ora from "ora";
|
|
2
|
+
import { requireApiKey, getSdkClient } from "../../auth.js";
|
|
3
|
+
import { printSuccess, printJson, handleSdkError } from "../../output.js";
|
|
4
|
+
export function registerGetCommand(project) {
|
|
5
|
+
project
|
|
6
|
+
.command("get <projectId>")
|
|
7
|
+
.description("Get a specific project by its ID")
|
|
8
|
+
.action(async (projectId) => {
|
|
9
|
+
const apiKey = await requireApiKey();
|
|
10
|
+
const spinner = ora("Fetching...").start();
|
|
11
|
+
try {
|
|
12
|
+
const client = getSdkClient(apiKey);
|
|
13
|
+
const result = await client.projects.retrieve(projectId);
|
|
14
|
+
spinner.stop();
|
|
15
|
+
printSuccess(`Project '${result.name}' details:`);
|
|
16
|
+
printJson(result);
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
spinner.stop();
|
|
20
|
+
handleSdkError(e);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/project/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAW9D"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { registerListCommand } from "./list.js";
|
|
3
|
+
import { registerGetCommand } from "./get.js";
|
|
4
|
+
import { registerCreateCommand } from "./create.js";
|
|
5
|
+
import { registerUpdateCommand } from "./update.js";
|
|
6
|
+
import { registerDeleteCommand } from "./delete.js";
|
|
7
|
+
import { registerSetDefaultCommand } from "./set-default.js";
|
|
8
|
+
export function registerProjectCommands(program) {
|
|
9
|
+
const project = new Command("project").description("Project management commands");
|
|
10
|
+
registerListCommand(project);
|
|
11
|
+
registerGetCommand(project);
|
|
12
|
+
registerCreateCommand(project);
|
|
13
|
+
registerUpdateCommand(project);
|
|
14
|
+
registerDeleteCommand(project);
|
|
15
|
+
registerSetDefaultCommand(project);
|
|
16
|
+
program.addCommand(project);
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/commands/project/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAoC1D"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import ora from "ora";
|
|
2
|
+
import { requireApiKey, getSdkClient } from "../../auth.js";
|
|
3
|
+
import { printMessage, printProjectTable, handleSdkError } from "../../output.js";
|
|
4
|
+
export function registerListCommand(project) {
|
|
5
|
+
project
|
|
6
|
+
.command("list")
|
|
7
|
+
.description("List projects in your organization")
|
|
8
|
+
.option("--page-size <number>", "Number of results to return per page", (v) => parseInt(v, 10))
|
|
9
|
+
.option("--cursor <cursor>", "The pagination cursor value")
|
|
10
|
+
.option("--search <term>", "A search term to filter by")
|
|
11
|
+
.option("--ordering <field>", "Which field to use for ordering the results")
|
|
12
|
+
.action(async (opts) => {
|
|
13
|
+
const apiKey = await requireApiKey();
|
|
14
|
+
const params = {};
|
|
15
|
+
if (opts.pageSize !== undefined)
|
|
16
|
+
params.page_size = opts.pageSize;
|
|
17
|
+
if (opts.cursor !== undefined)
|
|
18
|
+
params.cursor = opts.cursor;
|
|
19
|
+
if (opts.search !== undefined)
|
|
20
|
+
params.search = opts.search;
|
|
21
|
+
if (opts.ordering !== undefined)
|
|
22
|
+
params.ordering = opts.ordering;
|
|
23
|
+
const spinner = ora("Fetching...").start();
|
|
24
|
+
try {
|
|
25
|
+
const client = getSdkClient(apiKey);
|
|
26
|
+
const response = await client.projects.list(params);
|
|
27
|
+
spinner.stop();
|
|
28
|
+
if (!response.results.length) {
|
|
29
|
+
printMessage("No projects found.");
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
printProjectTable(response.results, response.next);
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
spinner.stop();
|
|
36
|
+
handleSdkError(e);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-default.d.ts","sourceRoot":"","sources":["../../../src/commands/project/set-default.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAkBhE"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import ora from "ora";
|
|
2
|
+
import { requireApiKey, getSdkClient } from "../../auth.js";
|
|
3
|
+
import { printSuccess, printJson, handleSdkError } from "../../output.js";
|
|
4
|
+
export function registerSetDefaultCommand(project) {
|
|
5
|
+
project
|
|
6
|
+
.command("set-default <projectId>")
|
|
7
|
+
.description("Promote a project to the org default. Atomically clears the previous default.")
|
|
8
|
+
.action(async (projectId) => {
|
|
9
|
+
const apiKey = await requireApiKey();
|
|
10
|
+
const spinner = ora("Updating default project...").start();
|
|
11
|
+
try {
|
|
12
|
+
const client = getSdkClient(apiKey);
|
|
13
|
+
const result = await client.projects.update(projectId, { is_default: true });
|
|
14
|
+
spinner.stop();
|
|
15
|
+
printSuccess(`Project ${projectId} is now the org default.`);
|
|
16
|
+
printJson(result);
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
spinner.stop();
|
|
20
|
+
handleSdkError(e);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../src/commands/project/update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAyC5D"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import ora from "ora";
|
|
2
|
+
import { requireApiKey, getSdkClient } from "../../auth.js";
|
|
3
|
+
import { printSuccess, printInfo, printJson, handleSdkError } from "../../output.js";
|
|
4
|
+
export function registerUpdateCommand(project) {
|
|
5
|
+
project
|
|
6
|
+
.command("update <projectId>")
|
|
7
|
+
.description("Update an existing project (PATCH)")
|
|
8
|
+
.option("--name <name>", "New project name")
|
|
9
|
+
.option("--description <text>", "New project description")
|
|
10
|
+
.option("--is-default", "Promote this project to org default. Atomically clears the previous default. Clearing the default directly is not supported by the backend; promote another project instead.", false)
|
|
11
|
+
.action(async (projectId, opts) => {
|
|
12
|
+
const apiKey = await requireApiKey();
|
|
13
|
+
const payload = {};
|
|
14
|
+
if (opts.name !== undefined)
|
|
15
|
+
payload.name = opts.name;
|
|
16
|
+
if (opts.description !== undefined)
|
|
17
|
+
payload.description = opts.description;
|
|
18
|
+
if (opts.isDefault)
|
|
19
|
+
payload.is_default = true;
|
|
20
|
+
if (Object.keys(payload).length === 0) {
|
|
21
|
+
printInfo("No update parameters provided. Aborting.");
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const spinner = ora("Updating...").start();
|
|
25
|
+
try {
|
|
26
|
+
const client = getSdkClient(apiKey);
|
|
27
|
+
const result = await client.projects.update(projectId, payload);
|
|
28
|
+
spinner.stop();
|
|
29
|
+
printSuccess(`Project ${projectId} updated successfully!`);
|
|
30
|
+
printJson(result);
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
spinner.stop();
|
|
34
|
+
handleSdkError(e);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/commands/prompt-test/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/commands/prompt-test/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA4DpC,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,OAAO,GAAG,IAAI,CA8BrD"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { writeFileSync, existsSync } from "node:fs";
|
|
2
2
|
import { printWarning, printSuccess, printInfo, printError } from "../../output.js";
|
|
3
|
+
import { PROJECT_ID_FLAG_DESC } from "../../lib/project-id.js";
|
|
3
4
|
const TEMPLATE = `# Prompt Testing Configuration
|
|
4
5
|
# This file defines a test suite of prompt and model combinations, with optional evaluators.
|
|
5
6
|
|
|
@@ -48,10 +49,16 @@ evaluators:
|
|
|
48
49
|
# description: "The username of the user. Must start with @"
|
|
49
50
|
# additionalProperties: false
|
|
50
51
|
`;
|
|
52
|
+
function buildTemplate(projectId) {
|
|
53
|
+
if (!projectId)
|
|
54
|
+
return TEMPLATE;
|
|
55
|
+
return `${TEMPLATE}\n# Project to assign prompt-test runs to. Override per-run with \`--project-id\`.\nproject_id: "${projectId}"\n`;
|
|
56
|
+
}
|
|
51
57
|
export function registerInitCommand(pt) {
|
|
52
58
|
pt.command("init")
|
|
53
59
|
.description("Initializes a new prompt-tests.yaml file in the current directory")
|
|
54
|
-
.
|
|
60
|
+
.option("--project-id <uuid>", PROJECT_ID_FLAG_DESC)
|
|
61
|
+
.action(async (opts) => {
|
|
55
62
|
const configPath = "prompt-tests.yaml";
|
|
56
63
|
if (existsSync(configPath)) {
|
|
57
64
|
printWarning(`'${configPath}' already exists in the current directory.`);
|
|
@@ -66,7 +73,7 @@ export function registerInitCommand(pt) {
|
|
|
66
73
|
}
|
|
67
74
|
}
|
|
68
75
|
try {
|
|
69
|
-
writeFileSync(configPath,
|
|
76
|
+
writeFileSync(configPath, buildTemplate(opts.projectId));
|
|
70
77
|
printSuccess(`'${configPath}' created successfully.`);
|
|
71
78
|
printInfo("Update the file with your prompt test details and run `pt run`.");
|
|
72
79
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
-
export declare function runPromptTests(outputFile: string | undefined, configPath: string, sleep?: (ms: number) => Promise<void
|
|
2
|
+
export declare function runPromptTests(outputFile: string | undefined, configPath: string, sleep?: (ms: number) => Promise<void>, projectIdOverride?: string): Promise<void>;
|
|
3
3
|
export declare function registerRunCommand(pt: Command): void;
|
|
4
4
|
//# sourceMappingURL=run.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/commands/prompt-test/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/commands/prompt-test/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA8GpC,wBAAsB,cAAc,CAClC,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,UAAU,EAAE,MAAM,EAClB,KAAK,GAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAiD,EACpF,iBAAiB,CAAC,EAAE,MAAM,GACzB,OAAO,CAAC,IAAI,CAAC,CA2Hf;AAED,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,OAAO,GAAG,IAAI,CAapD"}
|
|
@@ -23,6 +23,7 @@ const UNICODE_CHARS = {
|
|
|
23
23
|
middle: "│",
|
|
24
24
|
};
|
|
25
25
|
import { CliError } from "../../types.js";
|
|
26
|
+
import { resolveProjectIdValue, PROJECT_ID_FLAG_DESC } from "../../lib/project-id.js";
|
|
26
27
|
function isPromptTestComplete(exp) {
|
|
27
28
|
if (!exp.tasks.length)
|
|
28
29
|
return false;
|
|
@@ -93,7 +94,7 @@ function displayAggregatedResults(experiments) {
|
|
|
93
94
|
}
|
|
94
95
|
console.log(table.toString());
|
|
95
96
|
}
|
|
96
|
-
export async function runPromptTests(outputFile, configPath, sleep = (ms) => new Promise((r) => setTimeout(r, ms))) {
|
|
97
|
+
export async function runPromptTests(outputFile, configPath, sleep = (ms) => new Promise((r) => setTimeout(r, ms)), projectIdOverride) {
|
|
97
98
|
let rawConfig;
|
|
98
99
|
try {
|
|
99
100
|
rawConfig = yaml.load(readFileSync(configPath, "utf8"));
|
|
@@ -118,6 +119,9 @@ export async function runPromptTests(outputFile, configPath, sleep = (ms) => new
|
|
|
118
119
|
}
|
|
119
120
|
const apiKey = await requireApiKey();
|
|
120
121
|
printInfo("Starting prompt tests");
|
|
122
|
+
const resolvedProjectId = projectIdOverride !== undefined
|
|
123
|
+
? resolveProjectIdValue(projectIdOverride)
|
|
124
|
+
: (config.project_id ?? resolveProjectIdValue(undefined));
|
|
121
125
|
const experiments = {};
|
|
122
126
|
for (const prompt of config.prompts) {
|
|
123
127
|
for (const model of config.models) {
|
|
@@ -141,6 +145,8 @@ export async function runPromptTests(outputFile, configPath, sleep = (ms) => new
|
|
|
141
145
|
payload["response_schema"] = config.response_schema;
|
|
142
146
|
if (config.dataset_id)
|
|
143
147
|
payload["dataset_id"] = config.dataset_id;
|
|
148
|
+
if (resolvedProjectId !== undefined)
|
|
149
|
+
payload["project_id"] = resolvedProjectId;
|
|
144
150
|
const result = (await apiRequest("POST", "prompt-tests", {
|
|
145
151
|
payload,
|
|
146
152
|
apiKey,
|
|
@@ -200,9 +206,10 @@ export function registerRunCommand(pt) {
|
|
|
200
206
|
.description("Runs prompt tests from the prompt-tests.yaml file")
|
|
201
207
|
.option("-o, --output <path>", "Output file path to save prompt test results as JSON")
|
|
202
208
|
.option("-c, --config <path>", "Path to prompt testing configuration file", "prompt-tests.yaml")
|
|
209
|
+
.option("--project-id <uuid>", PROJECT_ID_FLAG_DESC + " Overrides project_id from config file.")
|
|
203
210
|
.action(async (opts) => {
|
|
204
211
|
try {
|
|
205
|
-
await runPromptTests(opts.output, opts.config);
|
|
212
|
+
await runPromptTests(opts.output, opts.config, undefined, opts.projectId);
|
|
206
213
|
}
|
|
207
214
|
catch (e) {
|
|
208
215
|
handleSdkError(e);
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAqDpC,wBAAgB,SAAS,IAAI,OAAO,CAgCnC"}
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ import { registerFileCommands } from "./commands/file/index.js";
|
|
|
14
14
|
import { registerOtelFilterCommands } from "./commands/otel-filter/index.js";
|
|
15
15
|
import { registerOtelTraceCommands } from "./commands/otel-trace/index.js";
|
|
16
16
|
import { registerModelCommands } from "./commands/model/index.js";
|
|
17
|
+
import { registerProjectCommands } from "./commands/project/index.js";
|
|
17
18
|
const { version } = createRequire(import.meta.url)("../package.json");
|
|
18
19
|
function buildBanner(ver) {
|
|
19
20
|
const logo = chalk.hex("#4D9FFF");
|
|
@@ -76,6 +77,7 @@ export function createCli() {
|
|
|
76
77
|
registerOtelFilterCommands(program);
|
|
77
78
|
registerOtelTraceCommands(program);
|
|
78
79
|
registerModelCommands(program);
|
|
80
|
+
registerProjectCommands(program);
|
|
79
81
|
return program;
|
|
80
82
|
}
|
|
81
83
|
if (realpathSync(fileURLToPath(import.meta.url)) === realpathSync(process.argv[1])) {
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
export declare const Match: z.ZodObject<{
|
|
3
|
+
conditions: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
4
|
+
column: z.ZodString;
|
|
5
|
+
operator: z.ZodString;
|
|
6
|
+
value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
7
|
+
key: z.ZodOptional<z.ZodString>;
|
|
8
|
+
}, z.core.$strict>>>;
|
|
9
|
+
}, z.core.$strict>;
|
|
2
10
|
export declare const FilterYamlSchema: z.ZodObject<{
|
|
3
11
|
name: z.ZodString;
|
|
4
12
|
evaluator_id: z.ZodOptional<z.ZodString>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter-yaml.d.ts","sourceRoot":"","sources":["../../src/lib/filter-yaml.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"filter-yaml.d.ts","sourceRoot":"","sources":["../../src/lib/filter-yaml.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAYxB,eAAO,MAAM,KAAK;;;;;;;kBAIP,CAAC;AAyEZ,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAczB,CAAC;AAEL,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAczD"}
|
package/dist/lib/filter-yaml.js
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type ProjectIdSource = "flag" | "env" | "settings" | "none";
|
|
2
|
+
export interface ResolvedProjectId {
|
|
3
|
+
value: string | undefined;
|
|
4
|
+
source: ProjectIdSource;
|
|
5
|
+
}
|
|
6
|
+
export declare function resolveProjectId(flagValue?: string): ResolvedProjectId;
|
|
7
|
+
export declare function resolveProjectIdValue(flagValue?: string): string | undefined;
|
|
8
|
+
export declare const PROJECT_ID_FLAG_DESC = "Project UUID to scope this operation. Pass \"\" to opt out of inherited defaults from SCORABLE_PROJECT_ID or ~/.scorable/settings.json.";
|
|
9
|
+
//# sourceMappingURL=project-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-id.d.ts","sourceRoot":"","sources":["../../src/lib/project-id.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,KAAK,GAAG,UAAU,GAAG,MAAM,CAAC;AAEnE,MAAM,WAAW,iBAAiB;IAKhC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,MAAM,EAAE,eAAe,CAAC;CACzB;AAYD,wBAAgB,gBAAgB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAqBtE;AAKD,wBAAgB,qBAAqB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE5E;AAKD,eAAO,MAAM,oBAAoB,4IACwG,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { loadSettings } from "../auth.js";
|
|
2
|
+
export function resolveProjectId(flagValue) {
|
|
3
|
+
if (flagValue !== undefined) {
|
|
4
|
+
if (flagValue === "") {
|
|
5
|
+
return { value: undefined, source: "flag" };
|
|
6
|
+
}
|
|
7
|
+
return { value: flagValue, source: "flag" };
|
|
8
|
+
}
|
|
9
|
+
const fromEnv = process.env["SCORABLE_PROJECT_ID"];
|
|
10
|
+
if (fromEnv !== undefined && fromEnv !== "") {
|
|
11
|
+
return { value: fromEnv, source: "env" };
|
|
12
|
+
}
|
|
13
|
+
const settings = loadSettings();
|
|
14
|
+
const fromSettings = settings["project_id"];
|
|
15
|
+
if (typeof fromSettings === "string" && fromSettings !== "") {
|
|
16
|
+
return { value: fromSettings, source: "settings" };
|
|
17
|
+
}
|
|
18
|
+
return { value: undefined, source: "none" };
|
|
19
|
+
}
|
|
20
|
+
export function resolveProjectIdValue(flagValue) {
|
|
21
|
+
return resolveProjectId(flagValue).value;
|
|
22
|
+
}
|
|
23
|
+
export const PROJECT_ID_FLAG_DESC = 'Project UUID to scope this operation. Pass "" to opt out of inherited defaults from SCORABLE_PROJECT_ID or ~/.scorable/settings.json.';
|
package/dist/output.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Judge, EvaluatorListItem, ExecutionLogList, ModelList } from "@root-signals/scorable";
|
|
1
|
+
import type { Judge, EvaluatorListItem, ExecutionLogList, ModelList, Project } from "@root-signals/scorable";
|
|
2
2
|
export declare function printJson(data: unknown): void;
|
|
3
3
|
export declare function printError(msg: string): void;
|
|
4
4
|
export declare function handleSdkError(e: unknown): never;
|
|
@@ -8,6 +8,7 @@ export declare function printWarning(msg: string): void;
|
|
|
8
8
|
export declare function printMessage(msg: string): void;
|
|
9
9
|
export declare function printJudgeTable(judges: Judge[], nextCursor?: string): void;
|
|
10
10
|
export declare function printEvaluatorTable(evaluators: EvaluatorListItem[], nextCursor?: string): void;
|
|
11
|
+
export declare function printProjectTable(projects: Project[], nextCursor?: string): void;
|
|
11
12
|
export declare function printModelTable(models: ModelList[], nextCursor?: string): void;
|
|
12
13
|
export declare function printExecutionLogTable(logs: ExecutionLogList[], nextCursor?: string): void;
|
|
13
14
|
//# sourceMappingURL=output.d.ts.map
|
package/dist/output.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,KAAK,EACL,iBAAiB,EACjB,gBAAgB,EAChB,SAAS,EACT,OAAO,EACR,MAAM,wBAAwB,CAAC;AAoBhC,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAE7C;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAE5C;AAmBD,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,KAAK,CAgBhD;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAE9C;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAE3C;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAE9C;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAE9C;AAUD,wBAAgB,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAmB1E;AAED,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,iBAAiB,EAAE,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAmB9F;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAoBhF;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAmB9E;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,gBAAgB,EAAE,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CA6B1F"}
|
package/dist/output.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import Table from "cli-table3";
|
|
3
|
+
import { ScorableError } from "@root-signals/scorable";
|
|
3
4
|
import { CliError } from "./types.js";
|
|
4
5
|
const UNICODE_CHARS = {
|
|
5
6
|
top: "─",
|
|
@@ -24,12 +25,42 @@ export function printJson(data) {
|
|
|
24
25
|
export function printError(msg) {
|
|
25
26
|
console.error(chalk.red("✖") + " " + msg);
|
|
26
27
|
}
|
|
28
|
+
function extractBackendMessage(details) {
|
|
29
|
+
if (!details || typeof details !== "object")
|
|
30
|
+
return undefined;
|
|
31
|
+
const d = details;
|
|
32
|
+
if (typeof d["detail"] === "string")
|
|
33
|
+
return d["detail"];
|
|
34
|
+
if (typeof d["title"] === "string")
|
|
35
|
+
return d["title"];
|
|
36
|
+
if (typeof d["error"] === "string")
|
|
37
|
+
return d["error"];
|
|
38
|
+
if (typeof d["message"] === "string")
|
|
39
|
+
return d["message"];
|
|
40
|
+
for (const v of Object.values(d)) {
|
|
41
|
+
if (Array.isArray(v) && v.length && typeof v[0] === "string") {
|
|
42
|
+
return v[0];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
27
47
|
export function handleSdkError(e) {
|
|
28
48
|
if (e instanceof CliError)
|
|
29
49
|
throw e;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
50
|
+
let message;
|
|
51
|
+
if (e instanceof ScorableError) {
|
|
52
|
+
const detail = extractBackendMessage(e.details);
|
|
53
|
+
message = detail ?? e.detail ?? e.title ?? e.message ?? `API Error ${e.status}: ${e.code}`;
|
|
54
|
+
}
|
|
55
|
+
else if (e instanceof Error) {
|
|
56
|
+
message = e.message || String(e);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
message = String(e);
|
|
60
|
+
}
|
|
61
|
+
const oneLine = message.replace(/\s*\n\s*/g, " ").trim();
|
|
62
|
+
printError(oneLine);
|
|
63
|
+
throw new CliError(1, oneLine);
|
|
33
64
|
}
|
|
34
65
|
export function printSuccess(msg) {
|
|
35
66
|
console.log(chalk.green("✔") + " " + msg);
|
|
@@ -46,16 +77,19 @@ export function printMessage(msg) {
|
|
|
46
77
|
function truncate(s, max) {
|
|
47
78
|
return s.length > max ? s.slice(0, max - 1) + "…" : s;
|
|
48
79
|
}
|
|
80
|
+
function projectIdCell(value) {
|
|
81
|
+
return value ?? "";
|
|
82
|
+
}
|
|
49
83
|
export function printJudgeTable(judges, nextCursor) {
|
|
50
84
|
const table = new Table({
|
|
51
|
-
head: ["ID", "Name", "Intent", "Created At"].map((h) => chalk.bold.cyan(h)),
|
|
85
|
+
head: ["ID", "Name", "Intent", "Project ID", "Created At"].map((h) => chalk.bold.cyan(h)),
|
|
52
86
|
chars: UNICODE_CHARS,
|
|
53
|
-
colWidths: [38,
|
|
87
|
+
colWidths: [38, 24, 40, 38, 12],
|
|
54
88
|
wordWrap: true,
|
|
55
89
|
});
|
|
56
90
|
for (const j of judges) {
|
|
57
91
|
const date = (j.created_at ?? "").slice(0, 10);
|
|
58
|
-
table.push([j.id, j.name, truncate(j.intent ?? "",
|
|
92
|
+
table.push([j.id, j.name, truncate(j.intent ?? "", 38), projectIdCell(j.project_id), date]);
|
|
59
93
|
}
|
|
60
94
|
console.log(table.toString());
|
|
61
95
|
if (nextCursor) {
|
|
@@ -65,14 +99,32 @@ export function printJudgeTable(judges, nextCursor) {
|
|
|
65
99
|
}
|
|
66
100
|
export function printEvaluatorTable(evaluators, nextCursor) {
|
|
67
101
|
const table = new Table({
|
|
68
|
-
head: ["ID", "Name", "Created At"].map((h) => chalk.bold.cyan(h)),
|
|
102
|
+
head: ["ID", "Name", "Project ID", "Created At"].map((h) => chalk.bold.cyan(h)),
|
|
69
103
|
chars: UNICODE_CHARS,
|
|
70
|
-
colWidths: [38, 30, 12],
|
|
104
|
+
colWidths: [38, 30, 38, 12],
|
|
71
105
|
wordWrap: true,
|
|
72
106
|
});
|
|
73
107
|
for (const e of evaluators) {
|
|
74
108
|
const date = (e.created_at ?? "").slice(0, 10);
|
|
75
|
-
table.push([e.id, e.name, date]);
|
|
109
|
+
table.push([e.id, e.name, projectIdCell(e.project_id), date]);
|
|
110
|
+
}
|
|
111
|
+
console.log(table.toString());
|
|
112
|
+
if (nextCursor) {
|
|
113
|
+
const cursor = nextCursor.split("cursor=")[1] ?? nextCursor;
|
|
114
|
+
printInfo(`Next page available. Use --cursor "${cursor}"`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
export function printProjectTable(projects, nextCursor) {
|
|
118
|
+
const table = new Table({
|
|
119
|
+
head: ["ID", "Name", "Description", "Created At"].map((h) => chalk.bold.cyan(h)),
|
|
120
|
+
chars: UNICODE_CHARS,
|
|
121
|
+
colWidths: [38, 30, 40, 12],
|
|
122
|
+
wordWrap: true,
|
|
123
|
+
});
|
|
124
|
+
for (const p of projects) {
|
|
125
|
+
const date = (p.created_at ?? "").slice(0, 10);
|
|
126
|
+
const name = p.is_default ? `${p.name} (default)` : p.name;
|
|
127
|
+
table.push([p.id, name, truncate(p.description ?? "", 38), date]);
|
|
76
128
|
}
|
|
77
129
|
console.log(table.toString());
|
|
78
130
|
if (nextCursor) {
|
|
@@ -99,15 +151,22 @@ export function printModelTable(models, nextCursor) {
|
|
|
99
151
|
}
|
|
100
152
|
export function printExecutionLogTable(logs, nextCursor) {
|
|
101
153
|
const table = new Table({
|
|
102
|
-
head: ["ID", "Item Name", "Type", "Score", "Created At"].map((h) => chalk.bold.cyan(h)),
|
|
154
|
+
head: ["ID", "Item Name", "Type", "Score", "Project ID", "Created At"].map((h) => chalk.bold.cyan(h)),
|
|
103
155
|
chars: UNICODE_CHARS,
|
|
104
|
-
colWidths: [38,
|
|
156
|
+
colWidths: [38, 24, 15, 8, 38, 12],
|
|
105
157
|
wordWrap: true,
|
|
106
158
|
});
|
|
107
159
|
for (const l of logs) {
|
|
108
160
|
const date = (l.created_at ?? "").slice(0, 10);
|
|
109
161
|
const score = l.score != null ? String(l.score) : "";
|
|
110
|
-
table.push([
|
|
162
|
+
table.push([
|
|
163
|
+
l.id,
|
|
164
|
+
truncate(l.executed_item_name, 22),
|
|
165
|
+
l.execution_type,
|
|
166
|
+
score,
|
|
167
|
+
projectIdCell(l.project_id),
|
|
168
|
+
date,
|
|
169
|
+
]);
|
|
111
170
|
}
|
|
112
171
|
console.log(table.toString());
|
|
113
172
|
if (nextCursor) {
|
package/dist/types.d.ts
CHANGED
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,kBAAkB,EAAE,KAAK,CAAC;QACxB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;KAC9B,CAAC,CAAC;IACH,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,UAAU,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACjD;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,QAAS,SAAQ,KAAK;aAEf,QAAQ,EAAE,MAAM;gBAAhB,QAAQ,EAAE,MAAM,EAChC,OAAO,EAAE,MAAM;CAKlB"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,kBAAkB,EAAE,KAAK,CAAC;QACxB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;KAC9B,CAAC,CAAC;IACH,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,UAAU,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACjD;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,QAAS,SAAQ,KAAK;aAEf,QAAQ,EAAE,MAAM;gBAAhB,QAAQ,EAAE,MAAM,EAChC,OAAO,EAAE,MAAM;CAKlB"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
import { type ZodType } from "zod";
|
|
1
2
|
import type { Turn } from "@root-signals/scorable";
|
|
2
3
|
export declare function isTurnArray(v: unknown): v is Turn[];
|
|
4
|
+
export declare function isToolCatalog(v: unknown): v is Record<string, unknown>[];
|
|
3
5
|
export declare function isStringArray(v: unknown): v is string[];
|
|
4
6
|
export declare function isStringRecord(v: unknown): v is Record<string, string>;
|
|
7
|
+
export type JsonArgResult<T> = {
|
|
8
|
+
ok: true;
|
|
9
|
+
value: T;
|
|
10
|
+
} | {
|
|
11
|
+
ok: false;
|
|
12
|
+
};
|
|
13
|
+
export declare function parseJsonArg<T>(raw: string, schema: ZodType<T>): JsonArgResult<T>;
|
|
5
14
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAanD,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,IAAI,EAAE,CAEnD;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAExE;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,EAAE,CAEvD;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOtE;AAID,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAA;CAAE,CAAC;AAEtE,wBAAgB,YAAY,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAUjF"}
|
package/dist/utils.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const TurnSchema = z.object({
|
|
3
|
+
role: z.enum(["user", "assistant", "tool"]),
|
|
4
|
+
content: z.string().nullable().optional(),
|
|
5
|
+
contexts: z.array(z.string()).nullable().optional(),
|
|
6
|
+
tool_calls: z.array(z.record(z.string(), z.unknown())).nullable().optional(),
|
|
7
|
+
tool_call_id: z.string().nullable().optional(),
|
|
8
|
+
});
|
|
9
|
+
const TurnArraySchema = z.array(TurnSchema);
|
|
10
|
+
const ToolCatalogSchema = z.array(z.record(z.string(), z.unknown()));
|
|
1
11
|
export function isTurnArray(v) {
|
|
2
|
-
return
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
typeof t.role === "string" &&
|
|
7
|
-
"content" in t &&
|
|
8
|
-
typeof t.content === "string"));
|
|
12
|
+
return TurnArraySchema.safeParse(v).success;
|
|
13
|
+
}
|
|
14
|
+
export function isToolCatalog(v) {
|
|
15
|
+
return ToolCatalogSchema.safeParse(v).success;
|
|
9
16
|
}
|
|
10
17
|
export function isStringArray(v) {
|
|
11
18
|
return Array.isArray(v) && v.every((s) => typeof s === "string");
|
|
@@ -16,3 +23,16 @@ export function isStringRecord(v) {
|
|
|
16
23
|
!Array.isArray(v) &&
|
|
17
24
|
Object.values(v).every((val) => typeof val === "string"));
|
|
18
25
|
}
|
|
26
|
+
export function parseJsonArg(raw, schema) {
|
|
27
|
+
let parsed;
|
|
28
|
+
try {
|
|
29
|
+
parsed = JSON.parse(raw);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return { ok: false };
|
|
33
|
+
}
|
|
34
|
+
const result = schema.safeParse(parsed);
|
|
35
|
+
if (!result.success)
|
|
36
|
+
return { ok: false };
|
|
37
|
+
return { ok: true, value: result.data };
|
|
38
|
+
}
|