@toloka-platform/sdk 0.20.0 → 0.21.1

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.
@@ -1,4 +1,6 @@
1
1
  import type {
2
+ AcceptReviewsBody,
3
+ AcceptReviewsResult,
2
4
  AddDatasetItems200,
3
5
  AddDatasetItemsBody,
4
6
  AddExpertBanListExpertsBody,
@@ -71,6 +73,8 @@ import type {
71
73
  ListPipelineChecks200,
72
74
  ListPipelineRunItems200,
73
75
  ListPipelineRunItemsParams,
76
+ ListPipelineRunReviews200,
77
+ ListPipelineRunReviewsParams,
74
78
  ListPipelineRuns200,
75
79
  ListPipelineRunsParams,
76
80
  ListProjectDatasets200,
@@ -107,10 +111,13 @@ import type {
107
111
  ProjectId,
108
112
  ProjectSecret,
109
113
  ProjectSecretName,
114
+ RejectReviewBody,
110
115
  RemoveExpertBanListExpertsBody,
111
116
  RemoveExpertListExpertsBody,
112
117
  ReplacePipelineGraphBody,
113
118
  ReplaceTrainingConfigurationBody,
119
+ Review,
120
+ ReviewId,
114
121
  RevokedScopedTokens,
115
122
  RunCost,
116
123
  RunId,
@@ -1203,6 +1210,150 @@ export const listGenerationModels = async ( options?: Parameters<typeof potatoFe
1203
1210
 
1204
1211
 
1205
1212
 
1213
+ export const getListPipelineRunReviewsUrl = (runId: RunId,
1214
+ params?: ListPipelineRunReviewsParams,) => {
1215
+ const normalizedParams = new URLSearchParams();
1216
+
1217
+ Object.entries(params || {}).forEach(([key, value]) => {
1218
+
1219
+ if (value !== undefined) {
1220
+ normalizedParams.append(key, value === null ? 'null' : String(value))
1221
+ }
1222
+ });
1223
+
1224
+ const stringifiedParams = normalizedParams.toString();
1225
+
1226
+ return stringifiedParams.length > 0 ? `/api/v2-beta/runs/${runId}/reviews?${stringifiedParams}` : `/api/v2-beta/runs/${runId}/reviews`
1227
+ }
1228
+
1229
+ export const listPipelineRunReviews = async (runId: RunId,
1230
+ params?: ListPipelineRunReviewsParams, options?: Parameters<typeof potatoFetch>[1]): Promise<ListPipelineRunReviews200> => {
1231
+
1232
+ return potatoFetch<ListPipelineRunReviews200>(getListPipelineRunReviewsUrl(runId,params),
1233
+ {
1234
+ ...options,
1235
+ method: 'GET'
1236
+
1237
+
1238
+ }
1239
+ );}
1240
+
1241
+
1242
+
1243
+ export const getAcceptPipelineRunReviewsUrl = (runId: RunId,) => {
1244
+
1245
+
1246
+
1247
+
1248
+ return `/api/v2-beta/runs/${runId}/reviews/accept`
1249
+ }
1250
+
1251
+ export const acceptPipelineRunReviews = async (runId: RunId,
1252
+ acceptReviewsBody: AcceptReviewsBody, options?: Parameters<typeof potatoFetch>[1]): Promise<AcceptReviewsResult> => {
1253
+
1254
+ const getHeaders = (h?: NonNullable<RequestInit['headers']>): Record<string, string | readonly string[]> => {
1255
+ if (!h) return {};
1256
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
1257
+ if (Symbol.iterator in h) {
1258
+ return Object.fromEntries(
1259
+ Array.from(h as Iterable<Iterable<string>>, (entry) => Array.from(entry) as [string, string]),
1260
+ );
1261
+ }
1262
+ const headers: Record<string, string | readonly string[]> = {};
1263
+ for (const [name, value] of Object.entries<string | readonly string[] | undefined>(h)) {
1264
+ if (value !== undefined) headers[name] = value;
1265
+ }
1266
+ return headers;
1267
+ };
1268
+ return potatoFetch<AcceptReviewsResult>(getAcceptPipelineRunReviewsUrl(runId),
1269
+ {
1270
+ ...options,
1271
+ method: 'POST',
1272
+ headers: { 'Content-Type': 'application/json', ...getHeaders(options?.headers) },
1273
+ body: JSON.stringify(acceptReviewsBody)
1274
+ }
1275
+ );}
1276
+
1277
+
1278
+
1279
+ export const getGetReviewUrl = (reviewId: ReviewId,) => {
1280
+
1281
+
1282
+
1283
+
1284
+ return `/api/v2-beta/reviews/${reviewId}`
1285
+ }
1286
+
1287
+ export const getReview = async (reviewId: ReviewId, options?: Parameters<typeof potatoFetch>[1]): Promise<Review> => {
1288
+
1289
+ return potatoFetch<Review>(getGetReviewUrl(reviewId),
1290
+ {
1291
+ ...options,
1292
+ method: 'GET'
1293
+
1294
+
1295
+ }
1296
+ );}
1297
+
1298
+
1299
+
1300
+ export const getAcceptReviewUrl = (reviewId: ReviewId,) => {
1301
+
1302
+
1303
+
1304
+
1305
+ return `/api/v2-beta/reviews/${reviewId}/accept`
1306
+ }
1307
+
1308
+ export const acceptReview = async (reviewId: ReviewId, options?: Parameters<typeof potatoFetch>[1]): Promise<Review> => {
1309
+
1310
+ return potatoFetch<Review>(getAcceptReviewUrl(reviewId),
1311
+ {
1312
+ ...options,
1313
+ method: 'POST'
1314
+
1315
+
1316
+ }
1317
+ );}
1318
+
1319
+
1320
+
1321
+ export const getRejectReviewUrl = (reviewId: ReviewId,) => {
1322
+
1323
+
1324
+
1325
+
1326
+ return `/api/v2-beta/reviews/${reviewId}/reject`
1327
+ }
1328
+
1329
+ export const rejectReview = async (reviewId: ReviewId,
1330
+ rejectReviewBody: RejectReviewBody, options?: Parameters<typeof potatoFetch>[1]): Promise<Review> => {
1331
+
1332
+ const getHeaders = (h?: NonNullable<RequestInit['headers']>): Record<string, string | readonly string[]> => {
1333
+ if (!h) return {};
1334
+ if (h instanceof Headers) return Object.fromEntries(h.entries());
1335
+ if (Symbol.iterator in h) {
1336
+ return Object.fromEntries(
1337
+ Array.from(h as Iterable<Iterable<string>>, (entry) => Array.from(entry) as [string, string]),
1338
+ );
1339
+ }
1340
+ const headers: Record<string, string | readonly string[]> = {};
1341
+ for (const [name, value] of Object.entries<string | readonly string[] | undefined>(h)) {
1342
+ if (value !== undefined) headers[name] = value;
1343
+ }
1344
+ return headers;
1345
+ };
1346
+ return potatoFetch<Review>(getRejectReviewUrl(reviewId),
1347
+ {
1348
+ ...options,
1349
+ method: 'POST',
1350
+ headers: { 'Content-Type': 'application/json', ...getHeaders(options?.headers) },
1351
+ body: JSON.stringify(rejectReviewBody)
1352
+ }
1353
+ );}
1354
+
1355
+
1356
+
1206
1357
  export const getGetCurrentUserUrl = () => {
1207
1358
 
1208
1359
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toloka-platform/sdk",
3
- "version": "0.20.0",
3
+ "version": "0.21.1",
4
4
  "private": false,
5
5
  "description": "Build, inspect, and operate Toloka pipeline projects as TypeScript source. The public API may change between minor versions before 1.0.",
6
6
  "license": "Apache-2.0",
@@ -40,7 +40,7 @@
40
40
  "sync-task-ui-declarations": "bun ./scripts/sync-task-ui-declarations.ts",
41
41
  "test": "vitest run",
42
42
  "test:browser": "vitest run --config vitest.browser.config.ts",
43
- "typecheck": "tsc --noEmit"
43
+ "typecheck": "tsrs --noEmit"
44
44
  },
45
45
  "dependencies": {
46
46
  "@inquirer/select": "5.2.1",
@@ -59,12 +59,12 @@
59
59
  "orval": "8.40.0",
60
60
  "playwright": "1.63.0",
61
61
  "typescript": "7.1.0-beta",
62
- "vitest": "4.1.0",
62
+ "vitest": "5.0.5",
63
63
  "yaml": "2.9.0"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "playwright": ">=1.63.0 <2",
67
- "vitest": ">=4.1.0 <5"
67
+ "vitest": ">=4.1.0 <6"
68
68
  },
69
69
  "peerDependenciesMeta": {
70
70
  "playwright": {
@@ -78,6 +78,6 @@
78
78
  "bun": ">=1.4.0"
79
79
  },
80
80
  "tolokaBuild": {
81
- "commit": "f0d62dc526a8897f20a7b3082b966ac1955897a5"
81
+ "commit": "af4c9a203ea792720b3169b95816b6fe44137cf7"
82
82
  }
83
83
  }
@@ -11,8 +11,8 @@
11
11
  "testing",
12
12
  "checks"
13
13
  ],
14
- "version": "0.20.0",
15
- "digest": "f7d62bb54636b2653b9ee3afc4cad5c83440ebce712cf7296df314f27be2fbf3",
14
+ "version": "0.21.1",
15
+ "digest": "6e2a18f123c3559953e2ce21bf7a154a0793c6663150fde0e7a531bd89c34ff8",
16
16
  "files": [
17
17
  "SKILL.md",
18
18
  "references/human-work.md",
@@ -33,7 +33,7 @@
33
33
  "bug",
34
34
  "report"
35
35
  ],
36
- "version": "0.20.0",
36
+ "version": "0.21.1",
37
37
  "digest": "70f0bd2c80b32f87896aeb27c363b8a2d37f40e22424f57fe1aad142e125ad67",
38
38
  "files": [
39
39
  "SKILL.md",
@@ -50,7 +50,7 @@
50
50
  "getting-started",
51
51
  "agent"
52
52
  ],
53
- "version": "0.20.0",
53
+ "version": "0.21.1",
54
54
  "digest": "2278adeb46a792356579395fcf73c42322cb23bcd0c61e20856ccabdad6762d1",
55
55
  "files": [
56
56
  "SKILL.md"
@@ -67,7 +67,7 @@
67
67
  "sft",
68
68
  "models"
69
69
  ],
70
- "version": "0.20.0",
70
+ "version": "0.21.1",
71
71
  "digest": "3ce10dee5d3c283d8b5fdea15134a58fc738c7af2c1bb19eb5a0bf70ea0bca13",
72
72
  "files": [
73
73
  "SKILL.md"
@@ -84,7 +84,7 @@
84
84
  "prompt",
85
85
  "models"
86
86
  ],
87
- "version": "0.20.0",
87
+ "version": "0.21.1",
88
88
  "digest": "be8bce8d9cf7241ccb60d2b2a9b7cc07d7755a76e8ff8ec1b0847c49efbb3469",
89
89
  "files": [
90
90
  "SKILL.md"
@@ -20,7 +20,7 @@ Use `about.projectType: 'data_collection'` only when experts upload or record me
20
20
  - `qualityCriteria`: semantic pass/fail rubrics targeting output `Field` objects.
21
21
  - `instruction`: English labeler guidance reflecting the actual entities, UI, and criteria.
22
22
  - `ui`: `{ code, data, preprocess, postprocess?, constants }` for the task interface.
23
- - `qualityAssurance`: `llm_only`, `hybrid`, or `human_only`.
23
+ - `qualityAssurance`: `llm_only`, `hybrid`, or `human_only`; some teams can also use `customer_review`, where their own team accepts or rejects every task. For a team without it, validation answers `The "customerReview" feature is not enabled for this team`: then the mode is not available, so offer another one. Keep `customer_review` when a node already has it, and read the toloka-customer-review skill before setting it or touching its reviews.
24
24
  - `audienceAndPricing`: either a human audience or synthetic generation.
25
25
  - `onboarding`: built-in Training stage.
26
26
  - `exam`: optional built-in qualification gate.
@@ -65,7 +65,7 @@ Use `audienceType: 'synthetic'` only when the user explicitly asks for model-gen
65
65
 
66
66
  #### Expert lists and bans
67
67
 
68
- Expert lists, expert bans, and the audience service are enabled for a team separately: `toloka expert-list` works only for teams with expert lists enabled, `toloka expert-ban-list` only for teams with expert bans enabled, and apply rejects `audienceMode: 'service'` unless the team also has the audience service enabled. Use them only when the user asks for a fixed set of experts or a ban.
68
+ Expert lists and expert bans are enabled for a team together, and only on top of the audience service: `toloka expert-list` and `toloka expert-ban-list` work only for teams with expert lists enabled, and apply rejects `audienceMode: 'service'` unless the team has the audience service enabled. Use them only when the user asks for a fixed set of experts or a ban.
69
69
 
70
70
  - `audienceMode: 'service'` on a `generation` or `quorum` node switches it to the audience service; `'legacy'` (or omitting it on a new node) keeps audience filters and smart search. With the service, `audienceAndPricing.expertListId` takes the labeling experts from an expert list, and on `generation` `qualityAssurance.expertListId` does the same for human QA (`human_only` or `hybrid`). The audience filters then stop deciding who gets tasks; `pricePerTask`, `timeForTask`, and the per-expert cap still apply.
71
71
  - Keep the settings `toloka import` wrote. Leaving a field out never detaches a list: plan shows no change for it, but apply rejects the whole graph while any node leaves out a setting the platform has, even when you only changed another node. Run `toloka import` to bring the settings into the source. To remove them, set `audienceMode: 'legacy'` and `expertListId: null` explicitly.
@@ -131,6 +131,6 @@ Create a second live project with `toloka project create <alias>` or register an
131
131
 
132
132
  ## Hand out a project-scoped token
133
133
 
134
- `toloka project token` mints a token that acts as the signed-in user inside the selected project only (`--projects` adds more projects of the same team), with the permissions of `--preset` (default `write`) or an explicit `--permissions` list, for at most six hours. It is printed once and never stored; pass it to another agent or script as `TOLOKA_SCOPED_TOKEN`, as the command says. `toloka project tokens` lists the live tokens of the project; `toloka project revoke-token <tokenId>` ends one and `toloka project revoke-tokens` ends every live token of the project at once, for example when a run finished or a token leaked. One user may hold at most 1000 live tokens per project; when `token` fails with `429 … revoke unused tokens first`, run `revoke-tokens`.
134
+ `toloka project token` mints a token that acts as the signed-in user inside the selected project only (`--projects` adds more projects of the same team), with the permissions of `--preset` (default `write`) or an explicit `--permissions` list, for at most six hours. Only the `deploy` and `labeling-deploy` presets can spend money: they launch runs. Every preset except `read` and `labeling-read` can decide customer reviews (`review:write`). It is printed once and never stored; pass it to another agent or script as `TOLOKA_SCOPED_TOKEN`, as the command says. `toloka project tokens` lists the live tokens of the project; `toloka project revoke-token <tokenId>` ends one and `toloka project revoke-tokens` ends every live token of the project at once, for example when a run finished or a token leaked. One user may hold at most 1000 live tokens per project; when `token` fails with `429 … revoke unused tokens first`, run `revoke-tokens`.
135
135
 
136
136
  A scoped token downloads project files in two steps: a request to `ProjectFile.url` with the token answers `200 {"url": "<storage URL>"}` instead of the redirect a human credential gets. Fetch that `url` as a plain request without the `X-Scoped-Token` header; HTTP clients replay custom headers across redirects, and the token must never reach the storage host.
@@ -35,6 +35,7 @@ Run `toloka --help` and `toloka <command> --help` for the exact commands and opt
35
35
  - source reconciliation: `init`, `import`, `check`, `validate`, `plan`, `apply`, `status`, `secret set`;
36
36
  - catalogs: `audience specialization list`, `generation-model list`, `ui components`;
37
37
  - data and runs: `dataset` (`list`, `create`, `fields`, `fields add`, `columns`, `load`, `upload`, `split`, `slice`), `pipeline` (`list`, `run`, `status`, `runs`, `cost`, `results`, `cancel`);
38
+ - customer review, only for teams that have it (other teams get a 403): `review` (`list`, `get`, `accept`, `reject`), described in the toloka-customer-review skill;
38
39
  - models and training: `base-model`, `model` (including `model version download`), `training`, `batch-inference` (`run`, `list`, `status`, `confirm`, `resume`, `cancel`);
39
40
  - skills and reports: `skill` (`list`, `search`, `install`), `report`.
40
41
 
@@ -0,0 +1,95 @@
1
+ ---
2
+ name: toloka-customer-review
3
+ description: Set up customer review on Toloka generation nodes and work through the review queue of a run with the toloka CLI, accepting or rejecting tasks with evidence. Only for teams with customer review enabled. Use when the user wants their own team to approve each generation result, asks which tasks wait for their decision, or asks to accept or reject reviewed tasks.
4
+ ---
5
+
6
+ # Customer review
7
+
8
+ Customer review is a quality assurance mode of generation nodes for teams that have it enabled: the customer's own team accepts or rejects every task the node produces.
9
+
10
+ Customer review is available only to some teams, and nothing shows in advance whether a team has it. For a team without it, validation, deploy, and every review command answer `403 The "customerReview" feature is not enabled for this team`. Treat that answer as "customer review is not available for this team": stop, tell the user, do not offer the mode again, and if a node of theirs already has it, offer another QA mode.
11
+
12
+ ## What the mode does
13
+
14
+ - It is set on a generation node as `qualityAssurance: { qaMode: 'customer_review' }`, with no other settings. Quorum nodes do not support it.
15
+ - Each item gets one task, nothing is redone, and the team's decision on that task is final for the item.
16
+ - Automatic grading is off on such a node: no LLM QA grades its tasks, and no Human QA reviews them. The one automated step left is the **LLM QA check**: every reject that is not forced goes to an LLM, which reads the task, the quality criteria the reject names, and its comment, and answers whether that evidence holds.
17
+ - It works with every workforce a generation node supports, including synthetic generation, and with Training and Exam.
18
+ - Quality criteria are still required: a reject names the criteria the task fails, and the LLM QA check reads them.
19
+
20
+ ## When to suggest it
21
+
22
+ Suggest it only when the user wants their own team to approve each result, for example a sign-off, acceptance against their own standard, or a contract that requires it. Never suggest it by default, and never infer it from the quality criteria.
23
+
24
+ Before switching a node to it, explain the trade-offs:
25
+
26
+ - someone on the team has to decide every task before its deadline, or the task is accepted automatically and billed;
27
+ - throughput follows the team's review speed;
28
+ - items wait at the node, and the run finishes only after its last review closes.
29
+
30
+ ## How a review goes
31
+
32
+ - When a task is submitted, its review opens with a deadline for a decision (`deadlineAt`).
33
+ - **Accept** is final at once: the expert is paid, the task is billed, and the item moves on to the next node.
34
+ - **Reject** names at least one of the review's quality criteria (the IDs that `toloka review get` prints) and explains in a non-empty comment what is wrong. The review then waits for the LLM QA check (`checking`) and refuses decisions until the check answers:
35
+ - `agree`: the reject is final. The item fails at this node and is not redone; nothing is billed for the task, and the expert is not paid.
36
+ - `disagree`: the evidence does not hold. The review returns (`returned`) with the check's reason; accept the task, or reject again with better evidence.
37
+ - `inconclusive`: the check could not decide, for example because its run failed repeatedly or gave no readable answer. The review also returns.
38
+ - Each review allows a limited number of checked rejects (`checkedRejectsLeft`). When none are left, accept the task or send a forced reject: the check has returned a reject by then, so the forced reject is allowed.
39
+ - **Forced reject** (`--force`) works only through the API and the CLI, never in the UI, and only after the LLM QA check has returned a reject of the same review. A forced reject on a review that has no returned check is a conflict: reject without `--force` first. It still needs criteria and a comment, skips the LLM QA check, is final at once, and does not use up a checked reject.
40
+ - Canceling a run does not close its open reviews: they keep waiting for the team's decision and expire at their deadline as usual.
41
+
42
+ ## Deadline and expiry
43
+
44
+ - From `deadlineAt` on, the review takes no more decisions.
45
+ - A review that waits for a decision at its deadline (`needs_review` or `returned`) expires: the task is accepted automatically, the expert is paid, the task is billed, and the item moves on.
46
+ - A review that is `checking` at its deadline stays open until the LLM QA check answers. If the check agrees, the reject is final. Otherwise the review expires as above, and nobody can decide it again.
47
+ - So `deadlineAt` is when decisions stop, not the exact moment the review closes: an expiry takes effect shortly after the deadline, and a review that is checking closes when the check answers.
48
+
49
+ ## Statuses
50
+
51
+ - `needs_review`: waits for the first decision.
52
+ - `returned`: the LLM QA check did not confirm the last reject (`disagree` or `inconclusive`), so the review waits for a new decision.
53
+ - `checking`: the LLM QA check is checking a reject; decisions are refused until it answers.
54
+ - `accepted`: the team accepted the task.
55
+ - `rejected`: the reject is final, either forced or confirmed by the LLM QA check, and the item failed at this node.
56
+ - `expired`: the deadline passed while the review was open, whether it waited for a first decision, was returned, or was checking a reject that the check then did not confirm. The task was accepted automatically.
57
+
58
+ ## Billing
59
+
60
+ - An accepted task, whether the team accepted it or its review expired, bills the node's per-task price, plus the Training and Exam bonuses when it is the expert's first accepted task. For synthetic generation, it bills that task's generation tokens.
61
+ - A finally rejected task bills nothing.
62
+ - The LLM QA check is not billed. The cost forecast has no QA line for the node, and its maximum assumes every task is accepted.
63
+
64
+ ## Work through the queue
65
+
66
+ The team decides in the platform UI (the run's Items tab: open an item, then Review), through the API, or with these commands:
67
+
68
+ 1. `toloka review list --run <run-id>` lists the reviews that still take a decision (`needs_review` and `returned` before their deadline), soonest deadline first. `--status checking` and `--status closed` show the other views, `--node <node-id>` keeps one node, and `--json` prints JSON.
69
+ 2. `toloka review get <review-id>` shows the review's status and deadline, the quality criteria with their IDs, the decisions so far with the answers of the LLM QA check, and the task content. Project files in the task content appear as file proxy URLs. The output is cut to at most 20 quality criteria, 20 criteria in each decision, 1,000 characters of each text, and 8,000 characters of task content, and it says what it cut. `--out <file>` saves the whole review as JSON; read that file in parts. `--json` prints the same cut view, with the task content as JSON text in `taskContentJson` and a `truncated` summary that is `null` when nothing was cut and otherwise has:
70
+ - `taskContentCharacters`: the full length of the task content when it was cut, otherwise `null`;
71
+ - `truncatedQualityCriterionCount`: how many quality criteria were left out;
72
+ - `truncatedVerdictCriteria`: each decision whose criteria were cut (`field`), with how many were left out (`truncatedCount`);
73
+ - `cutTexts`: each cut text (`field`), with its full length (`characters`);
74
+ - `hint`: the command that saves the full review.
75
+ 3. Decide with `toloka review accept <review-id>`, or `toloka review reject <review-id> --criterion <criterion-id> --comment "<what is wrong>"`. Repeat `--criterion` for each failed criterion. With `--json`, both print the review after the decision in the same cut view as `toloka review get --json`.
76
+ 4. A decision moves the review out of the awaiting list, so list again from the start instead of paging forward with `--offset`.
77
+
78
+ To accept every review that awaits a decision in a run, or in one node, send one bulk accept instead of a command per review: `toloka review accept --run <run-id> [--node <node-id>] --expected <n>`, where `<n>` is the number of awaiting reviews the user confirmed (the total that `toloka review list` prints). When a different number awaits a decision now, it accepts nothing and says the current number; confirm again with the user. The accepts run in the background, each like a single accept. A review that is decided, rejected, or past its deadline before its turn is skipped, and reviews that open later are not included. Follow the progress with `toloka review list`: accepted reviews leave the awaiting list. There is no bulk reject: reject one review at a time, each with its own evidence.
79
+
80
+ When a command fails:
81
+
82
+ - `The "customerReview" feature is not enabled for this team`: the team does not have customer review. Stop and tell the user.
83
+ - `Scoped token does not allow review:write`: the token can read reviews but not decide them. Every preset except `read` and `labeling-read` includes `review:write`. Tell the user instead of looking for another way to decide.
84
+ - A conflict (HTTP 409): the review cannot take the decision now, because the LLM QA check is still checking, the checked rejects are used up, a forced reject came before any returned check, or the review is closed or past its deadline. Run `toloka review get <review-id>` and act on its status.
85
+
86
+ ## Decide only when asked
87
+
88
+ - Accept or reject only on the user's explicit instruction that names the reviews, or an exact filter such as "the awaiting reviews of node X in run Y". Accepting pays the expert and bills the task at once, and a final reject fails the item; neither can be undone.
89
+ - Before a bulk accept or more than one decision, tell the user how many reviews you are about to decide and how, show at most 5 of them as a sample with the decision for each, and get their confirmation. Send a confirmed accept of all of them as one bulk accept with that number as `--expected`.
90
+ - Send a forced reject only when the user explicitly asks for one.
91
+ - Never decide reviews just to let a run finish.
92
+
93
+ ## In pipeline source
94
+
95
+ A generation node with customer review has `qualityAssurance: { qaMode: 'customer_review' }`. Keep it as imported unless the user asks to change it.
@@ -0,0 +1,160 @@
1
+ import { resolve } from "node:path";
2
+ import { Option, type Command } from "commander";
3
+
4
+ import { collectValues, nonNegativeInteger, positiveInteger, resolveContext, type CommandHost } from "../context";
5
+ import { assertCli } from "../cli-error";
6
+ import {
7
+ acceptAwaitingReviews,
8
+ acceptReview,
9
+ listReviews,
10
+ rejectReview,
11
+ REVIEW_CUT_VIEW_HELP,
12
+ type ReviewListView,
13
+ showReview,
14
+ } from "../reviews";
15
+
16
+ const REVIEW_VIEWS: readonly ReviewListView[] = ["awaiting", "checking", "closed"];
17
+
18
+ export const registerReviewCommands = (program: Command, host: CommandHost): void => {
19
+ const { context, globals } = host;
20
+ const review = program
21
+ .command("review")
22
+ .description("decide customer reviews of generation tasks; teams with customer review only");
23
+
24
+ review
25
+ .command("list")
26
+ .requiredOption("--run <run-id>", "pipeline run ID")
27
+ .addOption(
28
+ new Option("--status <status>", "awaiting needs a decision, checking waits for the LLM QA check, closed is done")
29
+ .choices(REVIEW_VIEWS)
30
+ .default("awaiting"),
31
+ )
32
+ .option("--node <node-id>", "only the reviews of this generation node")
33
+ .option("--limit <n>", "reviews per page, at most 100", positiveInteger, 20)
34
+ .option("--offset <n>", "reviews to skip", nonNegativeInteger, 0)
35
+ .option("--json", "print JSON", false)
36
+ .description(
37
+ "list the reviews of a run; a decision moves a review out of awaiting, so decide the first page and list again",
38
+ )
39
+ .action(
40
+ async (options: {
41
+ run: string;
42
+ status: ReviewListView;
43
+ node?: string;
44
+ limit: number;
45
+ offset: number;
46
+ json: boolean;
47
+ }) => {
48
+ const { client } = await resolveContext(globals(), context);
49
+ await listReviews(
50
+ client,
51
+ {
52
+ runId: options.run,
53
+ status: options.status,
54
+ ...(options.node === undefined ? {} : { nodeId: options.node }),
55
+ limit: options.limit,
56
+ offset: options.offset,
57
+ json: options.json,
58
+ },
59
+ context.io,
60
+ );
61
+ },
62
+ );
63
+
64
+ review
65
+ .command("get")
66
+ .argument("<review-id>", "review ID")
67
+ .option("--out <file>", "save the full review as JSON to this file instead of printing it")
68
+ .option("--json", "print the same cut view as JSON, with a truncated summary of what was cut", false)
69
+ .description(
70
+ "show a review with its task content, quality criteria, and decisions; long content is cut, --out saves all of it",
71
+ )
72
+ .addHelpText("after", REVIEW_CUT_VIEW_HELP)
73
+ .action(async (reviewId: string, options: { out?: string; json: boolean }) => {
74
+ const { client } = await resolveContext(globals(), context);
75
+ await showReview(
76
+ client,
77
+ { reviewId, json: options.json, ...(options.out === undefined ? {} : { outPath: resolve(options.out) }) },
78
+ context.io,
79
+ );
80
+ });
81
+
82
+ review
83
+ .command("accept")
84
+ .argument("[review-id]", "review ID")
85
+ .option("--run <run-id>", "accept every review of this run that awaits a decision, instead of one review")
86
+ .option("--node <node-id>", "with --run, only the reviews of this generation node")
87
+ .option(
88
+ "--expected <n>",
89
+ "with --run, the number of awaiting reviews the user confirmed; nothing is accepted when it differs",
90
+ positiveInteger,
91
+ )
92
+ .option("--json", "print the review after the decision in the same cut view as review get --json", false)
93
+ .description(
94
+ "accept a task, or with --run every awaiting review of a run; an accept is final: the expert is paid and the task is billed",
95
+ )
96
+ .action(
97
+ async (
98
+ reviewId: string | undefined,
99
+ options: { run?: string; node?: string; expected?: number; json: boolean },
100
+ ) => {
101
+ if (options.run === undefined) {
102
+ assertCli(reviewId !== undefined, "Pass the review ID, or --run to accept the awaiting reviews of a run.", {
103
+ hint: { description: "Run toloka review list --run <run-id> to see the reviews that await a decision." },
104
+ });
105
+ assertCli(options.node === undefined && options.expected === undefined, "--node and --expected go with --run.", {
106
+ hint: { description: "Run toloka review accept --run <run-id> --expected <n> to accept the awaiting reviews of a run." },
107
+ });
108
+ const { client } = await resolveContext(globals(), context);
109
+ await acceptReview(client, { reviewId, json: options.json }, context.io);
110
+ return;
111
+ }
112
+
113
+ assertCli(reviewId === undefined, "Pass either a review ID or --run, not both.", {
114
+ hint: { description: "A review ID accepts one review; --run accepts every review of the run that awaits a decision." },
115
+ });
116
+ assertCli(options.expected !== undefined, "Pass --expected with the number of awaiting reviews the user confirmed.", {
117
+ hint: { description: `Run toloka review list --run ${options.run} to count them, and confirm the number with the user.` },
118
+ });
119
+ const { client } = await resolveContext(globals(), context);
120
+ await acceptAwaitingReviews(
121
+ client,
122
+ {
123
+ runId: options.run,
124
+ expectedCount: options.expected,
125
+ json: options.json,
126
+ ...(options.node === undefined ? {} : { nodeId: options.node }),
127
+ },
128
+ context.io,
129
+ );
130
+ },
131
+ );
132
+
133
+ review
134
+ .command("reject")
135
+ .argument("<review-id>", "review ID")
136
+ .option("--criterion <criterion-id>", "a quality criterion the task fails; repeat for each", collectValues, [])
137
+ .requiredOption("--comment <text>", "what is wrong with the task")
138
+ .option("--force", "skip the LLM QA check and reject at once, only after the check returned a reject of this review; use only when asked to", false)
139
+ .option("--json", "print the review after the decision in the same cut view as review get --json", false)
140
+ .description("reject the task with evidence; the LLM QA check then checks the reject unless --force")
141
+ .action(
142
+ async (
143
+ reviewId: string,
144
+ options: { criterion: string[]; comment: string; force: boolean; json: boolean },
145
+ ) => {
146
+ const { client } = await resolveContext(globals(), context);
147
+ await rejectReview(
148
+ client,
149
+ {
150
+ reviewId,
151
+ criteria: options.criterion,
152
+ comment: options.comment,
153
+ force: options.force,
154
+ json: options.json,
155
+ },
156
+ context.io,
157
+ );
158
+ },
159
+ );
160
+ };
@@ -19,6 +19,7 @@ import { registerProjectCommands } from "./commands/project";
19
19
  import { registerReportCommand } from "./commands/report";
20
20
  import { registerExpertBanListCommands } from "./commands/expert-ban-list";
21
21
  import { registerExpertListCommands } from "./commands/expert-list";
22
+ import { registerReviewCommands } from "./commands/review";
22
23
  import { registerSecretCommands } from "./commands/secret";
23
24
  import { registerSkillCommands } from "./commands/skill";
24
25
  import { registerSourceCommands } from "./commands/source";
@@ -110,6 +111,7 @@ export function createProgram(context: ProgramContext): CreatedProgram {
110
111
  registerBatchInferenceCommands(program, host);
111
112
  registerDatasetCommands(program, host);
112
113
  registerPipelineCommands(program, host);
114
+ registerReviewCommands(program, host);
113
115
  registerStatusCommand(program, host);
114
116
  registerReportCommand(program, host);
115
117
  registerSkillCommands(program, host);