@toloka-platform/sdk 0.21.0 → 0.21.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.
@@ -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);
@@ -0,0 +1,313 @@
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
+ import { dirname } from "node:path";
3
+
4
+ import type { PotatoClient, Review, ReviewSummary } from "../client";
5
+ import { PotatoApiError } from "../errors";
6
+ import { TolokaCliError } from "./cli-error";
7
+ import { formatTable, type TableIo, writeOutput } from "./table";
8
+
9
+ type ReviewApi = Pick<PotatoClient, "reviews">;
10
+
11
+ export type ReviewListView = "awaiting" | "checking" | "closed";
12
+
13
+ const CUSTOMER_REVIEW_NOT_ENABLED_MESSAGE = "The \"customerReview\" feature is not enabled for this team";
14
+
15
+ const MAX_CRITERIA_SHOWN = 20;
16
+ const MAX_TEXT_CHARS = 1_000;
17
+ const MAX_TASK_CONTENT_CHARS = 8_000;
18
+
19
+ const characters = (count: number): string => `${count.toLocaleString("en-US")} characters`;
20
+
21
+ export const REVIEW_CUT_VIEW_HELP = [
22
+ "",
23
+ "The output is cut:",
24
+ ` at most ${MAX_CRITERIA_SHOWN} quality criteria, and at most ${MAX_CRITERIA_SHOWN} criteria in each decision;`,
25
+ ` at most ${characters(MAX_TEXT_CHARS)} of each text: criterion descriptions, comments, LLM QA check reasons;`,
26
+ ` at most ${characters(MAX_TASK_CONTENT_CHARS)} of task content, which --json prints as JSON text in taskContentJson.`,
27
+ "With --json, truncated is null when nothing was cut, and otherwise has:",
28
+ " taskContentCharacters full length of the task content when it was cut, otherwise null",
29
+ " truncatedQualityCriterionCount how many quality criteria were left out",
30
+ " truncatedVerdictCriteria { field, truncatedCount } for each decision whose criteria were cut",
31
+ " cutTexts { field, characters } for each cut text, with its full length",
32
+ " hint the --out command that saves the full review",
33
+ "review accept and review reject print the review after the decision in the same cut view.",
34
+ ].join("\n");
35
+
36
+ const boundedReview = (review: Review) => {
37
+ const cutTexts: { field: string; characters: number }[] = [];
38
+ const cut = (field: string, text: string): string => {
39
+ if (text.length <= MAX_TEXT_CHARS) return text;
40
+ cutTexts.push({ field, characters: text.length });
41
+ return `${text.slice(0, MAX_TEXT_CHARS)}… (${characters(text.length - MAX_TEXT_CHARS)} more)`;
42
+ };
43
+ const { taskContent, qualityCriteria, verdicts, ...fields } = review;
44
+ const shownCriteria = qualityCriteria.slice(0, MAX_CRITERIA_SHOWN).map((criterion, index) => ({
45
+ ...criterion,
46
+ qualityElement: cut(`qualityCriteria[${index}].qualityElement`, criterion.qualityElement),
47
+ pass: cut(`qualityCriteria[${index}].pass`, criterion.pass),
48
+ fail: cut(`qualityCriteria[${index}].fail`, criterion.fail),
49
+ }));
50
+ const shownVerdicts = verdicts.map((verdict, index) => ({
51
+ ...verdict,
52
+ criteria: verdict.criteria.slice(0, MAX_CRITERIA_SHOWN),
53
+ comment: cut(`verdicts[${index}].comment`, verdict.comment),
54
+ llmQaCheck:
55
+ verdict.llmQaCheck === null
56
+ ? null
57
+ : { ...verdict.llmQaCheck, reason: cut(`verdicts[${index}].llmQaCheck.reason`, verdict.llmQaCheck.reason) },
58
+ }));
59
+ const taskContentJson = JSON.stringify(taskContent, null, 2);
60
+ const taskContentCut = taskContentJson.length > MAX_TASK_CONTENT_CHARS;
61
+ const truncatedQualityCriterionCount = qualityCriteria.length - shownCriteria.length;
62
+ const truncatedVerdictCriteria = verdicts.flatMap(({ criteria }, index) =>
63
+ criteria.length > MAX_CRITERIA_SHOWN
64
+ ? [{ field: `verdicts[${index}].criteria`, truncatedCount: criteria.length - MAX_CRITERIA_SHOWN }]
65
+ : [],
66
+ );
67
+
68
+ return {
69
+ ...fields,
70
+ qualityCriteria: shownCriteria,
71
+ verdicts: shownVerdicts,
72
+ taskContentJson: taskContentCut ? taskContentJson.slice(0, MAX_TASK_CONTENT_CHARS) : taskContentJson,
73
+ truncated:
74
+ taskContentCut || truncatedQualityCriterionCount > 0 || truncatedVerdictCriteria.length > 0 || cutTexts.length > 0
75
+ ? {
76
+ taskContentCharacters: taskContentCut ? taskContentJson.length : null,
77
+ truncatedQualityCriterionCount,
78
+ truncatedVerdictCriteria,
79
+ cutTexts,
80
+ hint: `Run toloka review get ${review.id} --out <file> to save the full review as JSON.`,
81
+ }
82
+ : null,
83
+ };
84
+ };
85
+
86
+ type BoundedReview = ReturnType<typeof boundedReview>;
87
+
88
+ const serverMessage = (error: PotatoApiError): string =>
89
+ typeof error.body === "string" && error.body.length > 0 ? error.body : error.message;
90
+
91
+ const reviewConflictHint = (reviewId: string): string =>
92
+ `Run toloka review get ${reviewId} to see its status and how many checked rejects are left, then decide again.`;
93
+
94
+ const withReviewErrors = async <T>(conflictHint: string | undefined, request: () => Promise<T>): Promise<T> => {
95
+ try {
96
+ return await request();
97
+ } catch (error) {
98
+ if (error instanceof PotatoApiError && error.status === 403 && serverMessage(error).includes(CUSTOMER_REVIEW_NOT_ENABLED_MESSAGE)) {
99
+ throw new TolokaCliError("Customer review is not enabled for this team.", {
100
+ cause: error,
101
+ hint: { description: "Customer review is not available for this team. Choose another QA mode." },
102
+ });
103
+ }
104
+ if (error instanceof PotatoApiError && error.status === 409 && conflictHint !== undefined) {
105
+ throw new TolokaCliError(serverMessage(error), { cause: error, hint: { description: conflictHint } });
106
+ }
107
+ throw error;
108
+ }
109
+ };
110
+
111
+ const summaryRow = (review: ReviewSummary): readonly string[] => [
112
+ review.id,
113
+ review.itemId,
114
+ `${review.nodeName} (${review.nodeId})`,
115
+ review.status,
116
+ review.closedAt ?? review.deadlineAt,
117
+ ];
118
+
119
+ export const listReviews = async (
120
+ client: ReviewApi,
121
+ input: {
122
+ readonly runId: string;
123
+ readonly status: ReviewListView;
124
+ readonly nodeId?: string;
125
+ readonly limit: number;
126
+ readonly offset: number;
127
+ readonly json: boolean;
128
+ },
129
+ io: TableIo,
130
+ ): Promise<void> => {
131
+ const page = await withReviewErrors(undefined, () =>
132
+ client.reviews.listPage({
133
+ runId: input.runId,
134
+ status: input.status,
135
+ limit: input.limit,
136
+ offset: input.offset,
137
+ ...(input.nodeId === undefined ? {} : { nodeId: input.nodeId }),
138
+ }),
139
+ );
140
+ const { total, offset } = page.pagination;
141
+ const footer =
142
+ page.reviews.length === 0
143
+ ? `No ${input.status} reviews (total ${total}).`
144
+ : `Showing ${offset + 1}-${offset + page.reviews.length} of ${total}.`;
145
+
146
+ writeOutput(
147
+ io,
148
+ input.json,
149
+ page,
150
+ page.reviews.length === 0
151
+ ? footer
152
+ : [
153
+ formatTable([
154
+ ["ID", "ITEM", "NODE", "STATUS", input.status === "closed" ? "CLOSED" : "DEADLINE"],
155
+ ...page.reviews.map(summaryRow),
156
+ ]),
157
+ "",
158
+ footer,
159
+ ].join("\n"),
160
+ );
161
+ };
162
+
163
+ const formatReview = (review: BoundedReview): string => {
164
+ const taskContentCharacters = review.truncated?.taskContentCharacters ?? null;
165
+ const omittedVerdictCriteria = new Map(
166
+ (review.truncated?.truncatedVerdictCriteria ?? []).map(({ field, truncatedCount }) => [field, truncatedCount]),
167
+ );
168
+
169
+ return [
170
+ `Review: ${review.id}`,
171
+ `Status: ${review.status}`,
172
+ `Node: ${review.nodeName} (${review.nodeId})`,
173
+ `Item: ${review.itemId}`,
174
+ `Performer: ${review.performer.type}${review.performer.expertId === null ? "" : ` ${review.performer.expertId}`}`,
175
+ `Deadline: ${review.deadlineAt}`,
176
+ ...(review.closedAt === null ? [] : [`Closed: ${review.closedAt}`]),
177
+ `Checked rejects left: ${review.checkedRejectsLeft}`,
178
+ "",
179
+ "Quality criteria:",
180
+ ...review.qualityCriteria.map(
181
+ (criterion) => ` ${criterion.id} ${criterion.qualityElement}: fails when ${criterion.fail}`,
182
+ ),
183
+ ...(review.truncated !== null && review.truncated.truncatedQualityCriterionCount > 0
184
+ ? [` ${review.truncated.truncatedQualityCriterionCount} more quality criteria not shown`]
185
+ : []),
186
+ "",
187
+ "Decisions:",
188
+ ...(review.verdicts.length === 0
189
+ ? [" (none)"]
190
+ : review.verdicts.map((verdict, index) => {
191
+ const omittedCriteria = omittedVerdictCriteria.get(`verdicts[${index}].criteria`);
192
+
193
+ return [
194
+ ` ${verdict.createdAt} ${verdict.decision}${verdict.forced ? " (forced)" : ""} via ${verdict.source}`,
195
+ ...(verdict.decision === "reject"
196
+ ? [
197
+ ` criteria: ${verdict.criteria.join(", ")}${omittedCriteria === undefined ? "" : ` and ${omittedCriteria} more`}`,
198
+ ` comment: ${verdict.comment}`,
199
+ ]
200
+ : []),
201
+ ...(verdict.llmQaCheck === null
202
+ ? []
203
+ : [` LLM QA check: ${verdict.llmQaCheck.verdict}: ${verdict.llmQaCheck.reason}`]),
204
+ ].join("\n");
205
+ })),
206
+ "",
207
+ "Task content:",
208
+ review.taskContentJson,
209
+ ...(taskContentCharacters === null
210
+ ? []
211
+ : [
212
+ `…task content truncated: showing ${MAX_TASK_CONTENT_CHARS.toLocaleString("en-US")} of ${characters(taskContentCharacters)}`,
213
+ ]),
214
+ ...(review.truncated === null ? [] : ["", review.truncated.hint]),
215
+ ].join("\n");
216
+ };
217
+
218
+ export const showReview = async (
219
+ client: ReviewApi,
220
+ input: { readonly reviewId: string; readonly json: boolean; readonly outPath?: string },
221
+ io: TableIo,
222
+ ): Promise<void> => {
223
+ const review = await withReviewErrors(reviewConflictHint(input.reviewId), () => client.reviews.get({ reviewId: input.reviewId }));
224
+
225
+ if (input.outPath === undefined) {
226
+ const bounded = boundedReview(review);
227
+ writeOutput(io, input.json, bounded, formatReview(bounded));
228
+ return;
229
+ }
230
+
231
+ await mkdir(dirname(input.outPath), { recursive: true });
232
+ await writeFile(input.outPath, `${JSON.stringify(review, null, 2)}\n`);
233
+ writeOutput(
234
+ io,
235
+ input.json,
236
+ { reviewId: review.id, path: input.outPath },
237
+ `Wrote review ${review.id} to ${input.outPath}.`,
238
+ );
239
+ };
240
+
241
+ const outcomeLine = (review: Review): string => {
242
+ switch (review.status) {
243
+ case "accepted":
244
+ return `Accepted ${review.id}: the expert is paid and the task is billed.`;
245
+ case "rejected":
246
+ return `Rejected ${review.id}: the item fails at ${review.nodeName} and nothing is billed for the task.`;
247
+ case "checking":
248
+ return `Sent the reject of ${review.id} to the LLM QA check. Run toloka review get ${review.id} later to see its answer.`;
249
+ case "needs_review":
250
+ return `Review ${review.id} still needs a decision.`;
251
+ case "returned":
252
+ return `Review ${review.id} is back for a new decision: the LLM QA check did not confirm the last reject.`;
253
+ case "expired":
254
+ return `Review ${review.id} expired: its deadline passed while it was open, so the task was accepted automatically.`;
255
+ }
256
+ };
257
+
258
+ export const acceptReview = async (
259
+ client: ReviewApi,
260
+ input: { readonly reviewId: string; readonly json: boolean },
261
+ io: TableIo,
262
+ ): Promise<void> => {
263
+ const review = await withReviewErrors(reviewConflictHint(input.reviewId), () => client.reviews.accept({ reviewId: input.reviewId }));
264
+
265
+ writeOutput(io, input.json, boundedReview(review), outcomeLine(review));
266
+ };
267
+
268
+ export const acceptAwaitingReviews = async (
269
+ client: ReviewApi,
270
+ input: { readonly runId: string; readonly nodeId?: string; readonly expectedCount: number; readonly json: boolean },
271
+ io: TableIo,
272
+ ): Promise<void> => {
273
+ const listCommand = `toloka review list --run ${input.runId}${input.nodeId === undefined ? "" : ` --node ${input.nodeId}`}`;
274
+ const queued = await withReviewErrors(
275
+ `Run ${listCommand} to see the reviews that await a decision now, confirm their number with the user, and retry with --expected <number>.`,
276
+ () =>
277
+ client.reviews.acceptAwaiting({
278
+ runId: input.runId,
279
+ expectedCount: input.expectedCount,
280
+ ...(input.nodeId === undefined ? {} : { nodeId: input.nodeId }),
281
+ }),
282
+ );
283
+
284
+ writeOutput(
285
+ io,
286
+ input.json,
287
+ queued,
288
+ `Accepting ${queued.count} ${queued.count === 1 ? "review" : "reviews"} in the background. Run ${listCommand} to follow: accepted reviews leave the awaiting list.`,
289
+ );
290
+ };
291
+
292
+ export const rejectReview = async (
293
+ client: ReviewApi,
294
+ input: {
295
+ readonly reviewId: string;
296
+ readonly criteria: readonly string[];
297
+ readonly comment: string;
298
+ readonly force: boolean;
299
+ readonly json: boolean;
300
+ },
301
+ io: TableIo,
302
+ ): Promise<void> => {
303
+ const review = await withReviewErrors(reviewConflictHint(input.reviewId), () =>
304
+ client.reviews.reject({
305
+ reviewId: input.reviewId,
306
+ criteria: [...input.criteria],
307
+ comment: input.comment,
308
+ ...(input.force ? { force: true } : {}),
309
+ }),
310
+ );
311
+
312
+ writeOutput(io, input.json, boundedReview(review), outcomeLine(review));
313
+ };
package/src/client.ts CHANGED
@@ -2,6 +2,7 @@ import { assert } from "es-toolkit";
2
2
 
3
3
  import * as wire from "../openapi/gen/api";
4
4
  import type {
5
+ AcceptReviewsBody,
5
6
  AddDatasetItemsBody,
6
7
  AddExpertBanListExpertsBody,
7
8
  CreateExpertListBody,
@@ -46,6 +47,7 @@ import type {
46
47
  ListModelVersionsParams,
47
48
  ListDatasetItemsParams,
48
49
  ListPipelineRunItemsParams,
50
+ ListPipelineRunReviewsParams,
49
51
  ListPipelineRunsParams,
50
52
  ListProjectDatasetsParams,
51
53
  ListProjectPipelinesParams,
@@ -75,7 +77,10 @@ import type {
75
77
  Project as GeneratedProject,
76
78
  ProjectFile as GeneratedProjectFile,
77
79
  ProjectSecretName,
80
+ RejectReviewBody,
78
81
  ReplacePipelineGraphBody,
82
+ Review as GeneratedReview,
83
+ ReviewSummary as GeneratedReviewSummary,
79
84
  RunItem as GeneratedRunItem,
80
85
  RunJob as GeneratedRunJob,
81
86
  RunSummary as GeneratedRunSummary,
@@ -88,7 +93,7 @@ import type {
88
93
  UploadJob as GeneratedUploadJob,
89
94
  ValidatePipelineGraphBody,
90
95
  } from "../openapi/gen/api.schemas";
91
- import { listAllPages } from "./pagination";
96
+ import { listAllPages, readAllPagesFirst } from "./pagination";
92
97
  import { createRequestOptions } from "./transport";
93
98
  import type { ClientCredential } from "./transport";
94
99
  import { pollUntilTerminal, type WaitForOptions } from "./wait-for";
@@ -114,6 +119,7 @@ export type TrainingRunId = Branded<string, "TrainingRunId">;
114
119
  export type PipelineId = Branded<string, "PipelineId">;
115
120
  export type ProjectFileId = Branded<string, "ProjectFileId">;
116
121
  export type ProjectId = Branded<string, "ProjectId">;
122
+ export type ReviewId = Branded<string, "ReviewId">;
117
123
  export type RunId = Branded<string, "RunId">;
118
124
  export type RunItemId = Branded<string, "RunItemId">;
119
125
  export type UploadId = Branded<string, "UploadId">;
@@ -142,6 +148,7 @@ type ResourceIdsByProperty = {
142
148
  pipelineId: PipelineId;
143
149
  projectFileId: ProjectFileId;
144
150
  projectId: ProjectId;
151
+ reviewId: ReviewId;
145
152
  runId: RunId;
146
153
  runItemId: RunItemId;
147
154
  sliceId: DatasetSliceId;
@@ -209,6 +216,8 @@ export type BaseModelId = GeneratedBaseModelId;
209
216
  export type Pipeline = BrandedResource<GeneratedPipeline, PipelineId>;
210
217
  export type Project = BrandedResource<GeneratedProject, ProjectId>;
211
218
  export type ProjectFile = BrandedResource<GeneratedProjectFile, ProjectFileId>;
219
+ export type Review = BrandedResource<GeneratedReview, ReviewId>;
220
+ export type ReviewSummary = BrandedResource<GeneratedReviewSummary, ReviewId>;
212
221
  export type RunItem = BrandedResource<GeneratedRunItem, RunItemId>;
213
222
  export type RunJob = BrandedResource<GeneratedRunJob, RunId>;
214
223
  export type RunSummary = BrandedResource<GeneratedRunSummary, RunId>;
@@ -776,6 +785,26 @@ const createClientImplementation = (config: ClientConfig) => {
776
785
  wire.getPipelineRunItem(runId, itemId, requestOptions),
777
786
  };
778
787
 
788
+ const reviews = {
789
+ listPage: ({ runId, ...params }: { runId: RunId } & ListPipelineRunReviewsParams) =>
790
+ wire.listPipelineRunReviews(runId, params, requestOptions),
791
+ listAll: ({ runId, ...params }: { runId: RunId } & ListPipelineRunReviewsParams) =>
792
+ readAllPagesFirst(async (pageOptions) => {
793
+ const page = await wire.listPipelineRunReviews(
794
+ runId,
795
+ { ...params, ...pageOptions },
796
+ requestOptions,
797
+ );
798
+ return { items: page.reviews, pagination: page.pagination };
799
+ }, params),
800
+ get: ({ reviewId }: { reviewId: ReviewId }) => wire.getReview(reviewId, requestOptions),
801
+ accept: ({ reviewId }: { reviewId: ReviewId }) => wire.acceptReview(reviewId, requestOptions),
802
+ acceptAwaiting: ({ runId, ...body }: { runId: RunId } & AcceptReviewsBody) =>
803
+ wire.acceptPipelineRunReviews(runId, body, requestOptions),
804
+ reject: ({ reviewId, ...body }: { reviewId: ReviewId } & RejectReviewBody) =>
805
+ wire.rejectReview(reviewId, body, requestOptions),
806
+ };
807
+
779
808
  const secrets = {
780
809
  list: async ({ projectId }: { projectId: ProjectId }) =>
781
810
  (await wire.listProjectSecrets(projectId, requestOptions)).secrets,
@@ -877,6 +906,7 @@ const createClientImplementation = (config: ClientConfig) => {
877
906
  trainings,
878
907
  batchInference,
879
908
  runs,
909
+ reviews,
880
910
  secrets,
881
911
  files,
882
912
  checks,
@@ -927,6 +957,10 @@ type PublicOutput<T> = IsJsonValue<T> extends true
927
957
  ? ProjectFile
928
958
  : T extends GeneratedRunItem
929
959
  ? RunItem
960
+ : T extends GeneratedReview
961
+ ? Review
962
+ : T extends GeneratedReviewSummary
963
+ ? ReviewSummary
930
964
  : T extends GeneratedRunSummary
931
965
  ? RunSummary
932
966
  : T extends Blob
package/src/index.ts CHANGED
@@ -28,6 +28,9 @@ export type {
28
28
  ProjectFile,
29
29
  ProjectFileId,
30
30
  ProjectId,
31
+ Review,
32
+ ReviewId,
33
+ ReviewSummary,
31
34
  RunId,
32
35
  RunItem,
33
36
  RunItemId,
package/src/pagination.ts CHANGED
@@ -27,3 +27,14 @@ export async function* listAllPages<T>(
27
27
  offset = page.pagination.offset + page.pagination.limit;
28
28
  }
29
29
  }
30
+
31
+ export async function* readAllPagesFirst<T>(
32
+ fetchPage: (options: PaginationOptions) => Promise<Page<T>>,
33
+ options: PaginationOptions = {}
34
+ ): AsyncGenerator<T> {
35
+ const items: T[] = [];
36
+ for await (const item of listAllPages(fetchPage, options)) {
37
+ items.push(item);
38
+ }
39
+ yield* items;
40
+ }
@@ -1520,6 +1520,20 @@
1520
1520
  "qaMode"
1521
1521
  ],
1522
1522
  "additionalProperties": false
1523
+ },
1524
+ {
1525
+ "type": "object",
1526
+ "properties": {
1527
+ "qaMode": {
1528
+ "type": "string",
1529
+ "const": "customer_review",
1530
+ "description": "Review mode: `customer_review` has your team accept or reject every task of the node; an LLM QA check verifies the evidence of each reject. Only for teams with customer review enabled."
1531
+ }
1532
+ },
1533
+ "required": [
1534
+ "qaMode"
1535
+ ],
1536
+ "additionalProperties": false
1523
1537
  }
1524
1538
  ]
1525
1539
  },
@@ -108,12 +108,21 @@ const playwrightSpecifier = (resolveFrom: string | undefined): string => {
108
108
  }
109
109
  };
110
110
 
111
+ export const TASK_UI_IGNORE_CERTIFICATE_ERRORS_ENV = "TOLOKA_TASK_UI_IGNORE_CERTIFICATE_ERRORS";
112
+
113
+ export const taskUiBrowserLaunchOptions = (
114
+ environment: NodeJS.ProcessEnv = process.env,
115
+ ): Parameters<typeof Playwright.chromium.launch>[0] => ({
116
+ headless: true,
117
+ args: environment[TASK_UI_IGNORE_CERTIFICATE_ERRORS_ENV] === "1" ? ["--ignore-certificate-errors"] : [],
118
+ });
119
+
111
120
  export const launchDefaultBrowser = async ({
112
121
  resolveFrom,
113
122
  }: { resolveFrom?: string } = {}): Promise<Browser> => {
114
123
  try {
115
124
  const { chromium }: typeof Playwright = await import(playwrightSpecifier(resolveFrom));
116
- return await chromium.launch({ headless: true });
125
+ return await chromium.launch(taskUiBrowserLaunchOptions());
117
126
  } catch (error) {
118
127
  throw new TaskUiInfrastructureError(
119
128
  "Local Task UI testing requires Playwright and Chromium. Run `bun add --dev playwright vitest` and `bunx playwright install chromium`.",