@2kw/ai 4.0.0-dev.2
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/LICENSE +19 -0
- package/README.md +91 -0
- package/dist/commands/ai.d.ts +3 -0
- package/dist/commands/ai.js +72 -0
- package/dist/commands/analytics.d.ts +3 -0
- package/dist/commands/analytics.js +161 -0
- package/dist/commands/auth.d.ts +3 -0
- package/dist/commands/auth.js +134 -0
- package/dist/commands/billing.d.ts +3 -0
- package/dist/commands/billing.js +102 -0
- package/dist/commands/config.d.ts +3 -0
- package/dist/commands/config.js +90 -0
- package/dist/commands/context.d.ts +3 -0
- package/dist/commands/context.js +149 -0
- package/dist/commands/convert.d.ts +3 -0
- package/dist/commands/convert.js +291 -0
- package/dist/commands/dataset-versions.d.ts +3 -0
- package/dist/commands/dataset-versions.js +90 -0
- package/dist/commands/datasets.d.ts +3 -0
- package/dist/commands/datasets.js +150 -0
- package/dist/commands/docs.d.ts +3 -0
- package/dist/commands/docs.js +166 -0
- package/dist/commands/evaluators.d.ts +3 -0
- package/dist/commands/evaluators.js +124 -0
- package/dist/commands/experiments.d.ts +3 -0
- package/dist/commands/experiments.js +255 -0
- package/dist/commands/extractions.d.ts +3 -0
- package/dist/commands/extractions.js +134 -0
- package/dist/commands/prompt-labels.d.ts +3 -0
- package/dist/commands/prompt-labels.js +67 -0
- package/dist/commands/prompt-versions.d.ts +3 -0
- package/dist/commands/prompt-versions.js +65 -0
- package/dist/commands/prompts.d.ts +3 -0
- package/dist/commands/prompts.js +159 -0
- package/dist/commands/providers.d.ts +3 -0
- package/dist/commands/providers.js +115 -0
- package/dist/commands/schema-labels.d.ts +3 -0
- package/dist/commands/schema-labels.js +67 -0
- package/dist/commands/schema-versions.d.ts +3 -0
- package/dist/commands/schema-versions.js +66 -0
- package/dist/commands/schemas.d.ts +3 -0
- package/dist/commands/schemas.js +178 -0
- package/dist/commands/scores.d.ts +3 -0
- package/dist/commands/scores.js +31 -0
- package/dist/commands/tracing.d.ts +3 -0
- package/dist/commands/tracing.js +85 -0
- package/dist/commands/transcribe.d.ts +3 -0
- package/dist/commands/transcribe.js +65 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +54 -0
- package/dist/lib/client.d.ts +12 -0
- package/dist/lib/client.js +52 -0
- package/dist/lib/config.d.ts +44 -0
- package/dist/lib/config.js +217 -0
- package/dist/lib/datasets.d.ts +6 -0
- package/dist/lib/datasets.js +10 -0
- package/dist/lib/errors.d.ts +14 -0
- package/dist/lib/errors.js +54 -0
- package/dist/lib/multipart.d.ts +10 -0
- package/dist/lib/multipart.js +59 -0
- package/dist/lib/output.d.ts +29 -0
- package/dist/lib/output.js +107 -0
- package/dist/lib/pagination.d.ts +21 -0
- package/dist/lib/pagination.js +21 -0
- package/dist/lib/schema-compat.d.ts +11 -0
- package/dist/lib/schema-compat.js +51 -0
- package/dist/lib/update-notifier.d.ts +9 -0
- package/dist/lib/update-notifier.js +96 -0
- package/package.json +49 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import ora from "ora";
|
|
4
|
+
import { getClient, runAction } from "../lib/client.js";
|
|
5
|
+
import { formatPage, formatDetail, formatList, formatSuccess, withSpinner } from "../lib/output.js";
|
|
6
|
+
import { addPaginationOptions, paginationParams } from "../lib/pagination.js";
|
|
7
|
+
import { isJsonOutput } from "../lib/config.js";
|
|
8
|
+
const TERMINAL_STATUSES = new Set(["COMPLETED", "FAILED"]);
|
|
9
|
+
export function makeExperimentsCommand() {
|
|
10
|
+
const cmd = new Command("experiments").description("Manage experiments");
|
|
11
|
+
// ── list ──────────────────────────────────────────────────────
|
|
12
|
+
const list = new Command("list").description("List experiments");
|
|
13
|
+
addPaginationOptions(list);
|
|
14
|
+
list.option("-s, --search <term>", "Filter by name");
|
|
15
|
+
list.option("--status <status>", "Filter by status (DRAFT, RUNNING, COMPLETED, FAILED)");
|
|
16
|
+
list.action(async (opts, command) => {
|
|
17
|
+
await runAction(command, async () => {
|
|
18
|
+
const client = getClient(command);
|
|
19
|
+
const { data } = await client.GET("/v1/experiments", {
|
|
20
|
+
params: {
|
|
21
|
+
query: { search: opts.search, status: opts.status, ...paginationParams(opts) },
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
formatPage(data, command, ["id", "name", "status", "type", "datasetVersionId", "createdAt"]);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
cmd.addCommand(list);
|
|
28
|
+
// ── get ───────────────────────────────────────────────────────
|
|
29
|
+
cmd
|
|
30
|
+
.command("get")
|
|
31
|
+
.description("Get an experiment by ID")
|
|
32
|
+
.argument("<id>", "Experiment ID")
|
|
33
|
+
.action(async (id, _opts, command) => {
|
|
34
|
+
await runAction(command, async () => {
|
|
35
|
+
const client = getClient(command);
|
|
36
|
+
const { data } = await client.GET("/v1/experiments/{id}", {
|
|
37
|
+
params: { path: { id } },
|
|
38
|
+
});
|
|
39
|
+
formatDetail(data, command);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
// ── create ────────────────────────────────────────────────────
|
|
43
|
+
cmd
|
|
44
|
+
.command("create")
|
|
45
|
+
.description("Create a new experiment")
|
|
46
|
+
.requiredOption("-n, --name <name>", "Experiment name")
|
|
47
|
+
.option("-d, --description <text>", "Experiment description")
|
|
48
|
+
.option("-t, --type <type>", "Experiment type")
|
|
49
|
+
.option("--dataset-version <id>", "Dataset version ID to evaluate against")
|
|
50
|
+
.option("--metadata <json>", "Metadata (JSON)")
|
|
51
|
+
.action(async (opts, command) => {
|
|
52
|
+
await runAction(command, async () => {
|
|
53
|
+
const client = getClient(command);
|
|
54
|
+
const body = { name: opts.name };
|
|
55
|
+
if (opts.description !== undefined)
|
|
56
|
+
body.description = opts.description;
|
|
57
|
+
if (opts.type !== undefined)
|
|
58
|
+
body.type = opts.type;
|
|
59
|
+
if (opts.datasetVersion !== undefined)
|
|
60
|
+
body.datasetVersionId = opts.datasetVersion;
|
|
61
|
+
if (opts.metadata)
|
|
62
|
+
body.metadata = JSON.parse(opts.metadata);
|
|
63
|
+
const { data } = await client.POST("/v1/experiments", {
|
|
64
|
+
body: body,
|
|
65
|
+
});
|
|
66
|
+
formatDetail(data, command);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
// ── update ────────────────────────────────────────────────────
|
|
70
|
+
cmd
|
|
71
|
+
.command("update")
|
|
72
|
+
.description("Update an experiment")
|
|
73
|
+
.argument("<id>", "Experiment ID")
|
|
74
|
+
.option("-n, --name <name>", "New name")
|
|
75
|
+
.option("-d, --description <text>", "New description")
|
|
76
|
+
.option("-t, --type <type>", "New type")
|
|
77
|
+
.option("--dataset-version <id>", "Dataset version ID")
|
|
78
|
+
.option("--metadata <json>", "Metadata (JSON)")
|
|
79
|
+
.action(async (id, opts, command) => {
|
|
80
|
+
await runAction(command, async () => {
|
|
81
|
+
const client = getClient(command);
|
|
82
|
+
const body = {};
|
|
83
|
+
if (opts.name)
|
|
84
|
+
body.name = opts.name;
|
|
85
|
+
if (opts.description !== undefined)
|
|
86
|
+
body.description = opts.description;
|
|
87
|
+
if (opts.type !== undefined)
|
|
88
|
+
body.type = opts.type;
|
|
89
|
+
if (opts.datasetVersion !== undefined)
|
|
90
|
+
body.datasetVersionId = opts.datasetVersion;
|
|
91
|
+
if (opts.metadata)
|
|
92
|
+
body.metadata = JSON.parse(opts.metadata);
|
|
93
|
+
const { data } = await client.PUT("/v1/experiments/{id}", {
|
|
94
|
+
params: { path: { id } },
|
|
95
|
+
body: body,
|
|
96
|
+
});
|
|
97
|
+
formatDetail(data, command);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
// ── delete ────────────────────────────────────────────────────
|
|
101
|
+
cmd
|
|
102
|
+
.command("delete")
|
|
103
|
+
.description("Delete an experiment")
|
|
104
|
+
.argument("<id>", "Experiment ID")
|
|
105
|
+
.action(async (id, _opts, command) => {
|
|
106
|
+
await runAction(command, async () => {
|
|
107
|
+
const client = getClient(command);
|
|
108
|
+
await client.DELETE("/v1/experiments/{id}", {
|
|
109
|
+
params: { path: { id } },
|
|
110
|
+
});
|
|
111
|
+
formatSuccess(`Experiment ${id} deleted.`, command);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
// ── add-variant ───────────────────────────────────────────────
|
|
115
|
+
cmd
|
|
116
|
+
.command("add-variant")
|
|
117
|
+
.description("Add a variant to an experiment")
|
|
118
|
+
.requiredOption("--experiment <id>", "Experiment ID")
|
|
119
|
+
.requiredOption("-n, --name <name>", "Variant name")
|
|
120
|
+
.requiredOption("--task-type <type>", "Task type")
|
|
121
|
+
.requiredOption("--config <json>", "Variant configuration (JSON)")
|
|
122
|
+
.option("-d, --description <text>", "Variant description")
|
|
123
|
+
.option("--sort-order <n>", "Sort order", parseInt)
|
|
124
|
+
.action(async (opts, command) => {
|
|
125
|
+
await runAction(command, async () => {
|
|
126
|
+
const client = getClient(command);
|
|
127
|
+
const body = {
|
|
128
|
+
name: opts.name,
|
|
129
|
+
taskType: opts.taskType,
|
|
130
|
+
configuration: JSON.parse(opts.config),
|
|
131
|
+
};
|
|
132
|
+
if (opts.description !== undefined)
|
|
133
|
+
body.description = opts.description;
|
|
134
|
+
if (opts.sortOrder !== undefined)
|
|
135
|
+
body.sortOrder = opts.sortOrder;
|
|
136
|
+
const { data } = await client.POST("/v1/experiments/{id}/variants", {
|
|
137
|
+
params: {
|
|
138
|
+
path: { id: opts.experiment },
|
|
139
|
+
},
|
|
140
|
+
body: body,
|
|
141
|
+
});
|
|
142
|
+
formatDetail(data, command);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
// ── variants ──────────────────────────────────────────────────
|
|
146
|
+
cmd
|
|
147
|
+
.command("variants")
|
|
148
|
+
.description("List variants of an experiment")
|
|
149
|
+
.requiredOption("--experiment <id>", "Experiment ID")
|
|
150
|
+
.action(async (opts, command) => {
|
|
151
|
+
await runAction(command, async () => {
|
|
152
|
+
const client = getClient(command);
|
|
153
|
+
const { data } = await client.GET("/v1/experiments/{id}/variants", {
|
|
154
|
+
params: {
|
|
155
|
+
path: { id: opts.experiment },
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
formatList(data, command, ["id", "name", "taskType", "description", "sortOrder"]);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
// ── run ───────────────────────────────────────────────────────
|
|
162
|
+
cmd
|
|
163
|
+
.command("run")
|
|
164
|
+
.description("Start an experiment run and wait for completion")
|
|
165
|
+
.argument("<id>", "Experiment ID")
|
|
166
|
+
.option("--variant <variantId>", "Run only the given variant instead of the full matrix")
|
|
167
|
+
.option("--no-wait", "Return immediately without polling for completion")
|
|
168
|
+
.option("--poll-interval <seconds>", "Poll interval in seconds", "5")
|
|
169
|
+
.action(async (id, opts, command) => {
|
|
170
|
+
await runAction(command, async () => {
|
|
171
|
+
const client = getClient(command);
|
|
172
|
+
// Start the run
|
|
173
|
+
const { data: run } = await withSpinner("Starting experiment run...", () => client.POST("/v1/experiments/{id}/runs", {
|
|
174
|
+
params: {
|
|
175
|
+
path: { id },
|
|
176
|
+
},
|
|
177
|
+
body: opts.variant ? { variantId: opts.variant } : undefined,
|
|
178
|
+
}));
|
|
179
|
+
const runData = run;
|
|
180
|
+
const runId = runData?.id;
|
|
181
|
+
if (!opts.wait || isJsonOutput(command)) {
|
|
182
|
+
formatDetail(runData, command);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
console.log(chalk.green(`Run ${runId} started (status: ${runData?.status ?? "PENDING"})`));
|
|
186
|
+
// Poll until terminal status
|
|
187
|
+
const interval = parseInt(opts.pollInterval, 10) * 1000;
|
|
188
|
+
const spinner = ora("Running...").start();
|
|
189
|
+
while (true) {
|
|
190
|
+
await new Promise((r) => setTimeout(r, interval));
|
|
191
|
+
const { data: status } = await client.GET("/v1/experiments/{id}/runs/{runId}", {
|
|
192
|
+
params: {
|
|
193
|
+
path: { id, runId },
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
const s = status;
|
|
197
|
+
const progress = s?.itemsTotal
|
|
198
|
+
? `${s.itemsCompleted ?? 0}/${s.itemsTotal}`
|
|
199
|
+
: "...";
|
|
200
|
+
spinner.text = `Running... ${progress} items (${s?.status ?? "UNKNOWN"})`;
|
|
201
|
+
if (s?.status && TERMINAL_STATUSES.has(s.status)) {
|
|
202
|
+
if (s.status === "COMPLETED") {
|
|
203
|
+
spinner.succeed(`Run completed: ${progress} items`);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
spinner.fail(`Run failed: ${s.itemsFailed ?? 0} failures`);
|
|
207
|
+
}
|
|
208
|
+
formatDetail(s, command);
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
// ── runs ──────────────────────────────────────────────────────
|
|
215
|
+
const runs = new Command("runs").description("List experiment runs");
|
|
216
|
+
addPaginationOptions(runs);
|
|
217
|
+
runs.requiredOption("--experiment <id>", "Experiment ID");
|
|
218
|
+
runs.action(async (opts, command) => {
|
|
219
|
+
await runAction(command, async () => {
|
|
220
|
+
const client = getClient(command);
|
|
221
|
+
const { data } = await client.GET("/v1/experiments/{id}/runs", {
|
|
222
|
+
params: {
|
|
223
|
+
path: { id: opts.experiment },
|
|
224
|
+
query: paginationParams(opts),
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
formatPage(data, command, [
|
|
228
|
+
"id", "variantName", "status", "itemsCompleted", "itemsTotal", "itemsFailed", "startedAt", "completedAt",
|
|
229
|
+
]);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
cmd.addCommand(runs);
|
|
233
|
+
// ── results ───────────────────────────────────────────────────
|
|
234
|
+
const results = new Command("results").description("Get experiment run results");
|
|
235
|
+
addPaginationOptions(results);
|
|
236
|
+
results.requiredOption("--experiment <id>", "Experiment ID");
|
|
237
|
+
results.requiredOption("--run <id>", "Run ID");
|
|
238
|
+
results.action(async (opts, command) => {
|
|
239
|
+
await runAction(command, async () => {
|
|
240
|
+
const client = getClient(command);
|
|
241
|
+
const { data } = await client.GET("/v1/experiments/{id}/runs/{runId}/results", {
|
|
242
|
+
params: {
|
|
243
|
+
path: { id: opts.experiment, runId: opts.run },
|
|
244
|
+
query: paginationParams(opts),
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
formatPage(data, command, [
|
|
248
|
+
"datasetItemId", "durationMs", "inputTokens", "outputTokens", "estimatedCost", "error",
|
|
249
|
+
]);
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
cmd.addCommand(results);
|
|
253
|
+
return cmd;
|
|
254
|
+
}
|
|
255
|
+
//# sourceMappingURL=experiments.js.map
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { extname } from "node:path";
|
|
4
|
+
import { getClient, runAction } from "../lib/client.js";
|
|
5
|
+
import { formatPage, formatDetail, withSpinner } from "../lib/output.js";
|
|
6
|
+
import { addPaginationOptions, paginationParams } from "../lib/pagination.js";
|
|
7
|
+
const IMAGE_MIME_TYPES = {
|
|
8
|
+
".png": "image/png",
|
|
9
|
+
".jpg": "image/jpeg",
|
|
10
|
+
".jpeg": "image/jpeg",
|
|
11
|
+
".gif": "image/gif",
|
|
12
|
+
".webp": "image/webp",
|
|
13
|
+
".bmp": "image/bmp",
|
|
14
|
+
".tiff": "image/tiff",
|
|
15
|
+
};
|
|
16
|
+
function readImages(paths) {
|
|
17
|
+
return paths.map((p) => {
|
|
18
|
+
const buffer = readFileSync(p);
|
|
19
|
+
const ext = extname(p).toLowerCase();
|
|
20
|
+
const mimeType = IMAGE_MIME_TYPES[ext] ?? "image/png";
|
|
21
|
+
return { data: buffer.toString("base64"), mimeType };
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export function makeExtractionsCommand() {
|
|
25
|
+
const cmd = new Command("extractions").description("Manage extractions");
|
|
26
|
+
cmd
|
|
27
|
+
.command("create")
|
|
28
|
+
.description("Create a new extraction")
|
|
29
|
+
.requiredOption("--schema <id>", "Schema ID")
|
|
30
|
+
.requiredOption("-m, --model <model>", "Model to use (provider/model)")
|
|
31
|
+
.option("-t, --text <text>", "Input text (use - for stdin)")
|
|
32
|
+
.option("-f, --file <path>", "Read input text from file (use - for stdin)")
|
|
33
|
+
.option("--images <paths...>", "Image file paths")
|
|
34
|
+
.option("--version-id <id>", "Schema version ID")
|
|
35
|
+
.option("-l, --label <name>", "Schema label")
|
|
36
|
+
.option("--async", "Run asynchronously")
|
|
37
|
+
.action(async (opts, command) => {
|
|
38
|
+
await runAction(command, async () => {
|
|
39
|
+
const client = getClient(command);
|
|
40
|
+
let text = opts.text === "-" ? readFileSync(0, "utf-8") : opts.text;
|
|
41
|
+
if (opts.file) {
|
|
42
|
+
text = opts.file === "-" ? readFileSync(0, "utf-8") : readFileSync(opts.file, "utf-8");
|
|
43
|
+
}
|
|
44
|
+
const images = opts.images ? readImages(opts.images) : undefined;
|
|
45
|
+
const body = {
|
|
46
|
+
schemaId: opts.schema,
|
|
47
|
+
schemaVersionId: opts.versionId,
|
|
48
|
+
model: opts.model,
|
|
49
|
+
inputText: text,
|
|
50
|
+
inputImages: images,
|
|
51
|
+
};
|
|
52
|
+
if (opts.async) {
|
|
53
|
+
const { data } = await withSpinner("Extracting...", () => client.POST("/v1/extractions/async", {
|
|
54
|
+
body,
|
|
55
|
+
}));
|
|
56
|
+
formatDetail(data, command);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const { data } = await withSpinner("Extracting...", () => client.POST("/v1/extractions", {
|
|
60
|
+
body,
|
|
61
|
+
}));
|
|
62
|
+
formatDetail(data, command);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
cmd
|
|
67
|
+
.command("get")
|
|
68
|
+
.description("Get an extraction by ID")
|
|
69
|
+
.argument("<id>", "Extraction ID")
|
|
70
|
+
.action(async (id, _opts, command) => {
|
|
71
|
+
await runAction(command, async () => {
|
|
72
|
+
const client = getClient(command);
|
|
73
|
+
const { data } = await client.GET("/v1/extractions/{id}", { params: { path: { id } } });
|
|
74
|
+
formatDetail(data, command);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
const list = new Command("list").description("List extractions");
|
|
78
|
+
addPaginationOptions(list);
|
|
79
|
+
list.option("-s, --search <term>", "Search text");
|
|
80
|
+
list.option("--schema-version <id>", "Filter by schema version ID");
|
|
81
|
+
list.option("--status <status>", "Filter by status (PENDING|PROCESSING|COMPLETED|FAILED)");
|
|
82
|
+
list.action(async (opts, command) => {
|
|
83
|
+
await runAction(command, async () => {
|
|
84
|
+
const client = getClient(command);
|
|
85
|
+
const { data } = await client.GET("/v1/extractions", {
|
|
86
|
+
params: {
|
|
87
|
+
query: {
|
|
88
|
+
search: opts.search,
|
|
89
|
+
schemaVersionId: opts.schemaVersion,
|
|
90
|
+
status: opts.status,
|
|
91
|
+
...paginationParams(opts),
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
formatPage(data, command, ["id", "schemaId", "model", "status", "totalTokens", "createdAt"]);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
cmd.addCommand(list);
|
|
99
|
+
cmd
|
|
100
|
+
.command("estimate")
|
|
101
|
+
.description("Estimate token usage for an extraction")
|
|
102
|
+
.requiredOption("--schema <id>", "Schema ID")
|
|
103
|
+
.requiredOption("-m, --model <model>", "Model to use")
|
|
104
|
+
.option("-t, --text <text>", "Input text")
|
|
105
|
+
.option("--version-id <id>", "Schema version ID")
|
|
106
|
+
.action(async (opts, command) => {
|
|
107
|
+
await runAction(command, async () => {
|
|
108
|
+
const client = getClient(command);
|
|
109
|
+
const { data } = await client.POST("/v1/extractions/estimate", {
|
|
110
|
+
body: {
|
|
111
|
+
schemaId: opts.schema,
|
|
112
|
+
schemaVersionId: opts.versionId,
|
|
113
|
+
inputText: opts.text,
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
formatDetail(data, command);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
cmd
|
|
120
|
+
.command("rerun")
|
|
121
|
+
.description("Re-run an extraction")
|
|
122
|
+
.argument("<id>", "Extraction ID to rerun")
|
|
123
|
+
.action(async (id, _opts, command) => {
|
|
124
|
+
await runAction(command, async () => {
|
|
125
|
+
const client = getClient(command);
|
|
126
|
+
const { data } = await withSpinner("Re-running extraction...", () => client.POST("/v1/extractions/{id}/rerun", {
|
|
127
|
+
params: { path: { id } },
|
|
128
|
+
}));
|
|
129
|
+
formatDetail(data, command);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
return cmd;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=extractions.js.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { getClient, runAction } from "../lib/client.js";
|
|
3
|
+
import { formatList, formatDetail, formatSuccess } from "../lib/output.js";
|
|
4
|
+
export function makePromptLabelsCommand() {
|
|
5
|
+
const cmd = new Command("labels").description("Manage prompt labels");
|
|
6
|
+
cmd
|
|
7
|
+
.command("list")
|
|
8
|
+
.description("List labels for a prompt")
|
|
9
|
+
.requiredOption("--prompt <id>", "Prompt ID")
|
|
10
|
+
.action(async (opts, command) => {
|
|
11
|
+
await runAction(command, async () => {
|
|
12
|
+
const client = getClient(command);
|
|
13
|
+
const { data } = await client.GET("/v1/prompts/{promptId}/labels", { params: { path: { promptId: opts.prompt } } });
|
|
14
|
+
formatList(data, command, [
|
|
15
|
+
"name",
|
|
16
|
+
"promptVersionId",
|
|
17
|
+
"createdAt",
|
|
18
|
+
]);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
cmd
|
|
22
|
+
.command("create")
|
|
23
|
+
.description("Create a label for a prompt version")
|
|
24
|
+
.requiredOption("--prompt <id>", "Prompt ID")
|
|
25
|
+
.requiredOption("-n, --name <name>", "Label name")
|
|
26
|
+
.requiredOption("--version-id <id>", "Prompt version ID to label")
|
|
27
|
+
.action(async (opts, command) => {
|
|
28
|
+
await runAction(command, async () => {
|
|
29
|
+
const client = getClient(command);
|
|
30
|
+
const { data } = await client.POST("/v1/prompts/{promptId}/labels", {
|
|
31
|
+
params: { path: { promptId: opts.prompt } },
|
|
32
|
+
body: { name: opts.name, promptVersionId: opts.versionId },
|
|
33
|
+
});
|
|
34
|
+
formatDetail(data, command);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
cmd
|
|
38
|
+
.command("update")
|
|
39
|
+
.description("Update a label to point to a different version")
|
|
40
|
+
.argument("<labelName>", "Label name")
|
|
41
|
+
.requiredOption("--prompt <id>", "Prompt ID")
|
|
42
|
+
.requiredOption("--version-id <id>", "New prompt version ID")
|
|
43
|
+
.action(async (labelName, opts, command) => {
|
|
44
|
+
await runAction(command, async () => {
|
|
45
|
+
const client = getClient(command);
|
|
46
|
+
const { data } = await client.PUT("/v1/prompts/{promptId}/labels/{labelName}", {
|
|
47
|
+
params: { path: { promptId: opts.prompt, labelName } },
|
|
48
|
+
body: { promptVersionId: opts.versionId },
|
|
49
|
+
});
|
|
50
|
+
formatDetail(data, command);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
cmd
|
|
54
|
+
.command("delete")
|
|
55
|
+
.description("Delete a prompt label")
|
|
56
|
+
.argument("<labelName>", "Label name")
|
|
57
|
+
.requiredOption("--prompt <id>", "Prompt ID")
|
|
58
|
+
.action(async (labelName, opts, command) => {
|
|
59
|
+
await runAction(command, async () => {
|
|
60
|
+
const client = getClient(command);
|
|
61
|
+
await client.DELETE("/v1/prompts/{promptId}/labels/{labelName}", { params: { path: { promptId: opts.prompt, labelName } } });
|
|
62
|
+
formatSuccess(`Label "${labelName}" deleted.`, command);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
return cmd;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=prompt-labels.js.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { getClient, runAction } from "../lib/client.js";
|
|
3
|
+
import { formatPage, formatDetail } from "../lib/output.js";
|
|
4
|
+
import { addPaginationOptions, paginationParams } from "../lib/pagination.js";
|
|
5
|
+
export function makePromptVersionsCommand() {
|
|
6
|
+
const cmd = new Command("versions").description("Manage prompt versions");
|
|
7
|
+
const list = new Command("list").description("List versions of a prompt");
|
|
8
|
+
addPaginationOptions(list);
|
|
9
|
+
list.requiredOption("--prompt <id>", "Prompt ID");
|
|
10
|
+
list.action(async (opts, command) => {
|
|
11
|
+
await runAction(command, async () => {
|
|
12
|
+
const client = getClient(command);
|
|
13
|
+
const { data } = await client.GET("/v1/prompts/{promptId}/versions", {
|
|
14
|
+
params: {
|
|
15
|
+
path: { promptId: opts.prompt },
|
|
16
|
+
query: paginationParams(opts),
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
formatPage(data, command, ["id", "version", "active", "changeDescription", "createdAt"]);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
cmd.addCommand(list);
|
|
23
|
+
cmd
|
|
24
|
+
.command("get")
|
|
25
|
+
.description("Get a specific prompt version")
|
|
26
|
+
.argument("<versionId>", "Version ID")
|
|
27
|
+
.requiredOption("--prompt <id>", "Prompt ID")
|
|
28
|
+
.action(async (versionId, opts, command) => {
|
|
29
|
+
await runAction(command, async () => {
|
|
30
|
+
const client = getClient(command);
|
|
31
|
+
const { data } = await client.GET("/v1/prompts/{promptId}/versions/{versionId}", { params: { path: { promptId: opts.prompt, versionId } } });
|
|
32
|
+
formatDetail(data, command);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
cmd
|
|
36
|
+
.command("create")
|
|
37
|
+
.description("Create a new prompt version")
|
|
38
|
+
.requiredOption("--prompt <id>", "Prompt ID")
|
|
39
|
+
.requiredOption("-c, --content <text>", "Prompt content (template text)")
|
|
40
|
+
.option("-m, --message <text>", "Change description")
|
|
41
|
+
.action(async (opts, command) => {
|
|
42
|
+
await runAction(command, async () => {
|
|
43
|
+
const client = getClient(command);
|
|
44
|
+
const { data } = await client.POST("/v1/prompts/{promptId}/versions", {
|
|
45
|
+
params: { path: { promptId: opts.prompt } },
|
|
46
|
+
body: { content: opts.content, changeDescription: opts.message },
|
|
47
|
+
});
|
|
48
|
+
formatDetail(data, command);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
cmd
|
|
52
|
+
.command("activate")
|
|
53
|
+
.description("Activate a prompt version")
|
|
54
|
+
.argument("<versionId>", "Version ID")
|
|
55
|
+
.requiredOption("--prompt <id>", "Prompt ID")
|
|
56
|
+
.action(async (versionId, opts, command) => {
|
|
57
|
+
await runAction(command, async () => {
|
|
58
|
+
const client = getClient(command);
|
|
59
|
+
const { data } = await client.PUT("/v1/prompts/{promptId}/versions/{versionId}/activate", { params: { path: { promptId: opts.prompt, versionId } } });
|
|
60
|
+
formatDetail(data, command);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
return cmd;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=prompt-versions.js.map
|