@2kw/ai 6.0.0-dev.4 → 6.1.0-dev.10

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.
@@ -0,0 +1,244 @@
1
+ import { Command } from "commander";
2
+ import chalk from "chalk";
3
+ import { getClient, runAction } from "../lib/client.js";
4
+ import { isJsonOutput } from "../lib/config.js";
5
+ import { formatList, formatDetail, formatSuccess } from "../lib/output.js";
6
+ /**
7
+ * Annotation queues let a human reviewer work through a curated list of
8
+ * subjects (run results, traces, spans, dataset items). This command group
9
+ * covers the queue itself plus the items inside it: creating a queue,
10
+ * bulk-adding subjects, claiming the next eligible item, and recording the
11
+ * outcome — the full loop an agent or a human reviewer needs to run review
12
+ * end to end from the CLI.
13
+ */
14
+ export function makeQueuesCommand() {
15
+ const cmd = new Command("queues").description("Manage annotation queues for human review");
16
+ // ── list ──────────────────────────────────────────────────────
17
+ cmd
18
+ .command("list")
19
+ .description("List annotation queues")
20
+ .option("--archived", "List archived queues instead of active ones", false)
21
+ .action(async (opts, command) => {
22
+ await runAction(command, async () => {
23
+ const client = getClient(command);
24
+ const { data } = await client.GET("/v1/annotation-queues", {
25
+ params: { query: { archived: opts.archived } },
26
+ });
27
+ formatList(data, command, [
28
+ "id",
29
+ "name",
30
+ "description",
31
+ "archivedAt",
32
+ "createdAt",
33
+ ]);
34
+ });
35
+ });
36
+ // ── get ───────────────────────────────────────────────────────
37
+ cmd
38
+ .command("get")
39
+ .description("Get an annotation queue by ID")
40
+ .argument("<id>", "Queue ID")
41
+ .action(async (id, _opts, command) => {
42
+ await runAction(command, async () => {
43
+ const client = getClient(command);
44
+ const { data } = await client.GET("/v1/annotation-queues/{id}", {
45
+ params: { path: { id } },
46
+ });
47
+ formatDetail(data, command);
48
+ });
49
+ });
50
+ // ── create ────────────────────────────────────────────────────
51
+ cmd
52
+ .command("create")
53
+ .description("Create a new annotation queue")
54
+ .requiredOption("-n, --name <name>", "Queue name")
55
+ .option("-d, --description <text>", "Queue description")
56
+ .action(async (opts, command) => {
57
+ await runAction(command, async () => {
58
+ const client = getClient(command);
59
+ const { data } = await client.POST("/v1/annotation-queues", {
60
+ body: { name: opts.name, description: opts.description },
61
+ });
62
+ formatDetail(data, command);
63
+ });
64
+ });
65
+ // ── update ────────────────────────────────────────────────────
66
+ cmd
67
+ .command("update")
68
+ .description("Update a queue's name or description")
69
+ .argument("<id>", "Queue ID")
70
+ .option("-n, --name <name>", "New name")
71
+ .option("-d, --description <text>", "New description")
72
+ .action(async (id, opts, command) => {
73
+ await runAction(command, async () => {
74
+ const client = getClient(command);
75
+ const body = {};
76
+ if (opts.name !== undefined)
77
+ body.name = opts.name;
78
+ if (opts.description !== undefined)
79
+ body.description = opts.description;
80
+ const { data } = await client.PATCH("/v1/annotation-queues/{id}", {
81
+ params: { path: { id } },
82
+ body: body,
83
+ });
84
+ formatDetail(data, command);
85
+ });
86
+ });
87
+ // ── archive ───────────────────────────────────────────────────
88
+ cmd
89
+ .command("archive")
90
+ .description("Archive a queue (idempotent)")
91
+ .argument("<id>", "Queue ID")
92
+ .action(async (id, _opts, command) => {
93
+ await runAction(command, async () => {
94
+ const client = getClient(command);
95
+ await client.POST("/v1/annotation-queues/{id}/archive", {
96
+ params: { path: { id } },
97
+ });
98
+ formatSuccess(`Queue ${id} archived.`, command);
99
+ });
100
+ });
101
+ // ── by-subject ────────────────────────────────────────────────
102
+ cmd
103
+ .command("by-subject")
104
+ .description("Find queue items referencing a subject, across every queue")
105
+ .requiredOption("--subject-type <type>", "RUN_RESULT | TRACE | SPAN | DATASET_ITEM")
106
+ .requiredOption("--subject-id <id>", "Subject ID")
107
+ .action(async (opts, command) => {
108
+ await runAction(command, async () => {
109
+ const client = getClient(command);
110
+ const { data } = await client.GET("/v1/annotation-queues/by-subject", {
111
+ params: {
112
+ query: { subjectType: opts.subjectType, subjectId: opts.subjectId },
113
+ },
114
+ });
115
+ formatList(data, command, [
116
+ "id",
117
+ "queueId",
118
+ "subjectType",
119
+ "subjectId",
120
+ "status",
121
+ "assignedTo",
122
+ ]);
123
+ });
124
+ });
125
+ // ── next ──────────────────────────────────────────────────────
126
+ cmd
127
+ .command("next")
128
+ .description("Claim the next eligible item in a queue for the caller")
129
+ .argument("<id>", "Queue ID")
130
+ .action(async (id, _opts, command) => {
131
+ await runAction(command, async () => {
132
+ const client = getClient(command);
133
+ const { data } = await client.GET("/v1/annotation-queues/{id}/items/next", {
134
+ params: { path: { id } },
135
+ });
136
+ if (!data) {
137
+ // 204 No Content: the queue has nothing left for this caller. A
138
+ // normal end state, not an error — printed plainly either way.
139
+ if (isJsonOutput(command)) {
140
+ console.log(JSON.stringify(null));
141
+ }
142
+ else {
143
+ console.log(chalk.dim("No items available to claim — the queue is empty for you."));
144
+ }
145
+ return;
146
+ }
147
+ formatDetail(data, command);
148
+ });
149
+ });
150
+ // ── items ─────────────────────────────────────────────────────
151
+ const items = new Command("items").description("Manage items within an annotation queue");
152
+ items
153
+ .command("list")
154
+ .description("List items in a queue")
155
+ .requiredOption("--queue <id>", "Queue ID")
156
+ .option("--status <status>", "PENDING | IN_PROGRESS | DONE | SKIPPED")
157
+ .option("--assigned-to <userId>", "Filter by assignee")
158
+ .option("-p, --page <number>", "Page number (0-indexed)", "0")
159
+ .option("--size <number>", "Page size", "50")
160
+ .action(async (opts, command) => {
161
+ await runAction(command, async () => {
162
+ const client = getClient(command);
163
+ const { data } = await client.GET("/v1/annotation-queues/{id}/items", {
164
+ params: {
165
+ path: { id: opts.queue },
166
+ query: {
167
+ status: opts.status,
168
+ assignedTo: opts.assignedTo,
169
+ page: opts.page !== undefined ? parseInt(opts.page, 10) : undefined,
170
+ size: opts.size !== undefined ? parseInt(opts.size, 10) : undefined,
171
+ },
172
+ },
173
+ });
174
+ formatList(data, command, [
175
+ "id",
176
+ "subjectType",
177
+ "subjectId",
178
+ "status",
179
+ "assignedTo",
180
+ "createdAt",
181
+ ]);
182
+ });
183
+ });
184
+ items
185
+ .command("add")
186
+ .description("Bulk-add subjects to a queue (duplicates skipped)")
187
+ .requiredOption("--queue <id>", "Queue ID")
188
+ .requiredOption("--items <json>", 'JSON array of {"subjectType","subjectId"} objects')
189
+ .action(async (opts, command) => {
190
+ await runAction(command, async () => {
191
+ const client = getClient(command);
192
+ const parsedItems = JSON.parse(opts.items);
193
+ const { data } = await client.POST("/v1/annotation-queues/{id}/items", {
194
+ params: { path: { id: opts.queue } },
195
+ body: { items: parsedItems },
196
+ });
197
+ formatList(data, command, [
198
+ "id",
199
+ "subjectType",
200
+ "subjectId",
201
+ "status",
202
+ ]);
203
+ });
204
+ });
205
+ items
206
+ .command("get")
207
+ .description("Get a single queue item")
208
+ .argument("<itemId>", "Item ID")
209
+ .requiredOption("--queue <id>", "Queue ID")
210
+ .action(async (itemId, opts, command) => {
211
+ await runAction(command, async () => {
212
+ const client = getClient(command);
213
+ const { data } = await client.GET("/v1/annotation-queues/{id}/items/{itemId}", {
214
+ params: { path: { id: opts.queue, itemId } },
215
+ });
216
+ formatDetail(data, command);
217
+ });
218
+ });
219
+ items
220
+ .command("update")
221
+ .description("Update a queue item's status or assignee — the outcome of a review")
222
+ .argument("<itemId>", "Item ID")
223
+ .requiredOption("--queue <id>", "Queue ID")
224
+ .option("--status <status>", "PENDING | IN_PROGRESS | DONE | SKIPPED")
225
+ .option("--assigned-to <userId>", "New assignee")
226
+ .action(async (itemId, opts, command) => {
227
+ await runAction(command, async () => {
228
+ const client = getClient(command);
229
+ const body = {};
230
+ if (opts.status !== undefined)
231
+ body.status = opts.status;
232
+ if (opts.assignedTo !== undefined)
233
+ body.assignedTo = opts.assignedTo;
234
+ const { data } = await client.PATCH("/v1/annotation-queues/{id}/items/{itemId}", {
235
+ params: { path: { id: opts.queue, itemId } },
236
+ body: body,
237
+ });
238
+ formatDetail(data, command);
239
+ });
240
+ });
241
+ cmd.addCommand(items);
242
+ return cmd;
243
+ }
244
+ //# sourceMappingURL=queues.js.map
@@ -1,6 +1,6 @@
1
1
  import { Command } from "commander";
2
2
  import { getClient, runAction } from "../lib/client.js";
3
- import { formatPage, formatDetail } from "../lib/output.js";
3
+ import { formatPage, formatDetail, formatSuccess } from "../lib/output.js";
4
4
  import { addPaginationOptions, paginationParams } from "../lib/pagination.js";
5
5
  export function makeSchemaVersionsCommand() {
6
6
  const cmd = new Command("versions").description("Manage schema versions");
@@ -32,6 +32,29 @@ export function makeSchemaVersionsCommand() {
32
32
  formatDetail(data, command);
33
33
  });
34
34
  });
35
+ cmd
36
+ .command("latest")
37
+ .description("Get the latest active version of a schema")
38
+ .requiredOption("--schema <id>", "Schema ID")
39
+ .action(async (opts, command) => {
40
+ await runAction(command, async () => {
41
+ const client = getClient(command);
42
+ const { data } = await client.GET("/v1/schemas/{schemaId}/versions/latest", { params: { path: { schemaId: opts.schema } } });
43
+ formatDetail(data, command);
44
+ });
45
+ });
46
+ cmd
47
+ .command("delete")
48
+ .description("Delete (deactivate) a schema version")
49
+ .argument("<versionId>", "Version ID")
50
+ .requiredOption("--schema <id>", "Schema ID")
51
+ .action(async (versionId, opts, command) => {
52
+ await runAction(command, async () => {
53
+ const client = getClient(command);
54
+ await client.DELETE("/v1/schemas/{schemaId}/versions/{versionId}", { params: { path: { schemaId: opts.schema, versionId } } });
55
+ formatSuccess(`Schema version ${versionId} deleted.`, command);
56
+ });
57
+ });
35
58
  cmd
36
59
  .command("create")
37
60
  .description("Create a new schema version")
@@ -1,14 +1,18 @@
1
1
  import { Command } from "commander";
2
2
  import { getClient, runAction } from "../lib/client.js";
3
- import { formatDetail } from "../lib/output.js";
3
+ import { formatDetail, formatList } from "../lib/output.js";
4
4
  export function makeScoresCommand() {
5
- const cmd = new Command("scores").description("Record evaluation scores on experiment run results");
5
+ const cmd = new Command("scores").description("Record and review evaluation scores on experiment run results and other subjects");
6
6
  cmd
7
7
  .command("human")
8
- .description("Record a human score for a run result. Upserts by (runResultId, evaluatorId, annotatorId).")
9
- .requiredOption("--run-result <id>", "Run result ID")
8
+ .description("Record a human score. Upserts by (subject, evaluatorId, annotatorId) — pass either " +
9
+ "--run-result, or --subject-type/--subject-id for a trace, span, or dataset item.")
10
+ .option("--run-result <id>", "Run result ID (legacy shape)")
11
+ .option("--subject-type <type>", "RUN_RESULT | TRACE | SPAN | DATASET_ITEM")
12
+ .option("--subject-id <id>", "Subject ID")
13
+ .option("--queue-item <id>", "Annotation queue item ID this score resolves")
10
14
  .requiredOption("--evaluator <id>", "Evaluator identifier (e.g. 'helpfulness' or a template id)")
11
- .requiredOption("--score <number>", "Score between 0.0 and 1.0", parseFloat)
15
+ .option("--score <number>", "Score between 0.0 and 1.0", parseFloat)
12
16
  .option("--label <text>", "Short label (e.g. 'pass', 'fail', 'good')")
13
17
  .option("--comment <text>", "Optional reviewer note")
14
18
  .action(async (opts, command) => {
@@ -17,6 +21,9 @@ export function makeScoresCommand() {
17
21
  const { data } = await client.POST("/v1/evaluation-scores/human", {
18
22
  body: {
19
23
  runResultId: opts.runResult,
24
+ subjectType: opts.subjectType,
25
+ subjectId: opts.subjectId,
26
+ annotationQueueItemId: opts.queueItem,
20
27
  evaluatorId: opts.evaluator,
21
28
  score: opts.score,
22
29
  label: opts.label,
@@ -26,6 +33,37 @@ export function makeScoresCommand() {
26
33
  formatDetail(data, command);
27
34
  });
28
35
  });
36
+ cmd
37
+ .command("list")
38
+ .description("List human scores filed against a subject. Defaults to the caller's own scores — " +
39
+ "pass --annotator to see another reviewer's.")
40
+ .requiredOption("--subject-type <type>", "RUN_RESULT | TRACE | SPAN | DATASET_ITEM")
41
+ .requiredOption("--subject-id <id>", "Subject ID")
42
+ .option("--annotator <id>", "Annotator ID (defaults to the caller)")
43
+ .action(async (opts, command) => {
44
+ await runAction(command, async () => {
45
+ const client = getClient(command);
46
+ const { data } = await client.GET("/v1/evaluation-scores/human", {
47
+ params: {
48
+ query: {
49
+ subjectType: opts.subjectType,
50
+ subjectId: opts.subjectId,
51
+ annotatorId: opts.annotator,
52
+ },
53
+ },
54
+ });
55
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
+ formatList(data, command, [
57
+ "id",
58
+ "evaluatorId",
59
+ "score",
60
+ "label",
61
+ "annotatorId",
62
+ "comment",
63
+ "createdAt",
64
+ ]);
65
+ });
66
+ });
29
67
  return cmd;
30
68
  }
31
69
  //# sourceMappingURL=scores.js.map
@@ -80,6 +80,46 @@ export function makeTracingCommand() {
80
80
  });
81
81
  });
82
82
  cmd.addCommand(get);
83
+ // ── sessions ──────────────────────────────────────────────────
84
+ const sessions = new Command("sessions").description("Session-level trace views (spans grouped by exporter-stamped session id)");
85
+ const sessionsList = new Command("list").description("List trace sessions");
86
+ sessionsList.option("--search <query>", "Free-text search across session id and name");
87
+ sessionsList.option("--from <iso>", "Start of time range (ISO-8601)");
88
+ sessionsList.option("--to <iso>", "End of time range (ISO-8601)");
89
+ sessionsList.option("--page <n>", "Page index (0-based)", "0");
90
+ sessionsList.option("--size <n>", "Page size", "20");
91
+ sessionsList.action(async (opts, command) => {
92
+ await runAction(command, async () => {
93
+ const client = getClient(command);
94
+ const { data } = await client.GET("/v1/traces/sessions", {
95
+ params: {
96
+ query: {
97
+ search: opts.search,
98
+ from: opts.from,
99
+ to: opts.to,
100
+ page: parseInt(opts.page, 10),
101
+ size: parseInt(opts.size, 10),
102
+ },
103
+ },
104
+ });
105
+ const page = data;
106
+ formatList((page?.content ?? []), command, ["sessionId", "name", "startTime", "durationMs", "turnCount", "errorCount", "costUsd"]);
107
+ });
108
+ });
109
+ sessions.addCommand(sessionsList);
110
+ const sessionsGet = new Command("get").description("Get all spans of a session by id, sorted chronologically");
111
+ sessionsGet.argument("<sessionId>", "Session id");
112
+ sessionsGet.action(async (sessionId, _opts, command) => {
113
+ await runAction(command, async () => {
114
+ const client = getClient(command);
115
+ const { data } = await client.GET("/v1/traces/sessions/{sessionId}", {
116
+ params: { path: { sessionId } },
117
+ });
118
+ formatDetail(data, command);
119
+ });
120
+ });
121
+ sessions.addCommand(sessionsGet);
122
+ cmd.addCommand(sessions);
83
123
  return cmd;
84
124
  }
85
125
  //# sourceMappingURL=tracing.js.map
package/dist/index.js CHANGED
@@ -21,6 +21,12 @@ import { makeExperimentsCommand } from "./commands/experiments.js";
21
21
  import { makeTracingCommand } from "./commands/tracing.js";
22
22
  import { makeEvaluatorsCommand } from "./commands/evaluators.js";
23
23
  import { makeScoresCommand } from "./commands/scores.js";
24
+ import { makeQueuesCommand } from "./commands/queues.js";
25
+ import { makeAgentsCommand } from "./commands/agents.js";
26
+ import { makeConversationsCommand } from "./commands/conversations.js";
27
+ import { makeKnowledgeCommand } from "./commands/knowledge.js";
28
+ import { makeFilesCommand } from "./commands/files.js";
29
+ import { makeInstallationsCommand } from "./commands/installations.js";
24
30
  import { checkForUpdates } from "./lib/update-notifier.js";
25
31
  const updater = checkForUpdates(pkg.version);
26
32
  const program = new Command();
@@ -48,7 +54,13 @@ program.addCommand(makeDatasetsCommand());
48
54
  program.addCommand(makeExperimentsCommand());
49
55
  program.addCommand(makeEvaluatorsCommand());
50
56
  program.addCommand(makeScoresCommand());
57
+ program.addCommand(makeQueuesCommand());
51
58
  program.addCommand(makeTracingCommand());
59
+ program.addCommand(makeAgentsCommand());
60
+ program.addCommand(makeConversationsCommand());
61
+ program.addCommand(makeKnowledgeCommand());
62
+ program.addCommand(makeFilesCommand());
63
+ program.addCommand(makeInstallationsCommand());
52
64
  program.addCommand(makeDocsCommand());
53
65
  program.parseAsync().then(() => updater.notify());
54
66
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@2kw/ai",
3
- "version": "6.0.0-dev.4",
3
+ "version": "6.1.0-dev.10",
4
4
  "description": "CLI for 2kw.ai — schema-driven document extraction, an OpenAI-compatible EU LLM gateway, transcription, prompts, datasets, and experiments from your terminal or agentic workflows. Ships as 2kw, backbone, and bb.",
5
5
  "keywords": [
6
6
  "cli",
@@ -37,6 +37,7 @@
37
37
  "check:spec": "tsx --env-file=.env openapi/scripts/check-drift.ts",
38
38
  "check:generated": "tsx openapi/scripts/check-generated.ts",
39
39
  "fix:generated": "tsx openapi/scripts/check-generated.ts --write",
40
+ "check:coverage": "tsx openapi/scripts/check-coverage.ts",
40
41
  "typecheck": "tsc --noEmit",
41
42
  "test": "vitest",
42
43
  "test:run": "vitest run",