@toloka-platform/sdk 0.26.1 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/toloka.js +157 -157
- package/dist/cli/toloka.js.jsc +0 -0
- package/dist/cli/toloka.js.jsc.sha256 +1 -1
- package/dist/cli/toloka.js.sha256 +1 -1
- package/openapi/gen/api.schemas.ts +3 -0
- package/package.json +2 -2
- package/skills/catalog.json +6 -6
- package/skills/toloka-build/SKILL.md +1 -1
- package/skills/toloka-build/references/human-work.md +28 -2
- package/src/authoring/index.ts +34 -3
- package/src/cli/poll.ts +26 -0
- package/src/cli/project.ts +16 -23
- package/src/cli/runs.ts +13 -14
- package/src/importer.ts +78 -6
- package/src/index.ts +2 -0
- package/src/pipeline-graph-v1.contract.json +27 -0
package/dist/cli/toloka.js.jsc
CHANGED
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
734ec9fa7066d2eabcd71039e8e4992d3786713c4c613559be072ec1a14fad79 toloka.js.jsc
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
5d0fd338ab431959995d7bed9e136d670fc8745b8468a7061b5c05fb0da37d2f toloka.js
|
|
@@ -1533,6 +1533,8 @@ export interface GenerationNodeSettings {
|
|
|
1533
1533
|
exam?: QualificationExam;
|
|
1534
1534
|
reuseAudienceWithNodeId?: GenerationNodeSettingsReuseAudienceWithNodeId;
|
|
1535
1535
|
smartSearch?: SmartSearch | null;
|
|
1536
|
+
allowedExperts?: string[];
|
|
1537
|
+
excludedExperts?: string[];
|
|
1536
1538
|
checks?: Partial<Record<'ui' | 'llmqa' | 'annotation_qa' | 'qc_lint' | 'ui_types_lint' | 'exam_dataset' | 'synthgen', CheckTestCases>>;
|
|
1537
1539
|
}
|
|
1538
1540
|
|
|
@@ -1613,6 +1615,7 @@ export interface QuorumNodeSettings {
|
|
|
1613
1615
|
exam?: QualificationExam;
|
|
1614
1616
|
reuseAudienceWithNodeId?: QuorumNodeSettingsReuseAudienceWithNodeId;
|
|
1615
1617
|
smartSearch?: SmartSearch | null;
|
|
1618
|
+
excludedExperts?: string[];
|
|
1616
1619
|
checks?: Partial<Record<'ui' | 'llmqa' | 'annotation_qa' | 'qc_lint' | 'ui_types_lint' | 'exam_dataset', CheckTestCases>>;
|
|
1617
1620
|
}
|
|
1618
1621
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toloka-platform/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
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",
|
|
@@ -78,6 +78,6 @@
|
|
|
78
78
|
"bun": ">=1.4.0"
|
|
79
79
|
},
|
|
80
80
|
"tolokaBuild": {
|
|
81
|
-
"commit": "
|
|
81
|
+
"commit": "e61620bbaa3d8ffaf14b60352d2026ab7fcd8df0"
|
|
82
82
|
}
|
|
83
83
|
}
|
package/skills/catalog.json
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"testing",
|
|
12
12
|
"checks"
|
|
13
13
|
],
|
|
14
|
-
"version": "0.
|
|
15
|
-
"digest": "
|
|
14
|
+
"version": "0.27.0",
|
|
15
|
+
"digest": "0820713c190feda349a949a0146124508165410b3073f2d02d11eb6613690c18",
|
|
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.
|
|
36
|
+
"version": "0.27.0",
|
|
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.
|
|
53
|
+
"version": "0.27.0",
|
|
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.
|
|
70
|
+
"version": "0.27.0",
|
|
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.
|
|
87
|
+
"version": "0.27.0",
|
|
88
88
|
"digest": "be8bce8d9cf7241ccb60d2b2a9b7cc07d7755a76e8ff8ec1b0847c49efbb3469",
|
|
89
89
|
"files": [
|
|
90
90
|
"SKILL.md"
|
|
@@ -90,7 +90,7 @@ Let constructors mint IDs for new declarations. Preserve `id` options generated
|
|
|
90
90
|
| `checks-running` | Only with `--wait`: a lint was still running when the wait ended. |
|
|
91
91
|
| `skipped` | The pipeline or its dataset is not on the platform yet; `toloka apply` creates it. |
|
|
92
92
|
|
|
93
|
-
The platform's lints, such as the Task UI interface lint and the quality-criteria lint, start by themselves a few seconds after every apply and take about a minute. Until they finish, plain `toloka validate` lists each as a `running_node_check` warning and can still print `valid` with exit 0, so it does not prove the lints passed. After applying a change, run `toloka validate --wait`: it validates again
|
|
93
|
+
The platform's lints, such as the Task UI interface lint and the quality-criteria lint, start by themselves a few seconds after every apply and take about a minute. Until they finish, plain `toloka validate` lists each as a `running_node_check` warning and can still print `valid` with exit 0, so it does not prove the lints passed. After applying a change, run `toloka validate --wait`: it validates again after 1 second, then at growing intervals of up to 5 seconds, for up to 5 minutes, until no lint is running, and does not wait for a pipeline whose source has unapplied changes. Report the pipeline as valid only after that. A lint does not restart by itself when dataset items or their values change, or after it fails or times out (after 5 minutes running or 15 minutes waiting to start): run `toloka pipeline lint <name> --wait`, which starts every lint without a current result and waits for it, then validate again. `validate` names this case: `Check "<name>" ran before the dataset changed`. When a reviewed plan adds a dataset field already bound by an existing live pipeline, pre-apply validation can report that exact field as missing; apply only the reviewed additive plan, then require post-apply validation to clear source/spec errors. Never rewrite valid source because a stored test case on the Checks tab has not run.
|
|
94
94
|
|
|
95
95
|
Register every code-node behavior with `test.code(pipeline, node, name, callback)`; its callback receives a bound `run(inputs, options?)` helper with the node's Python execution contract, and the test counts only after `run` executes, an assertion runs, and the callback passes. Register required human-work behavior with `test.ui(pipeline, node, name, callback)`; its callback receives a bound `render(options?)`, and the test counts only after a successful `submit`, at least one assertion, and a passing callback. Add at least one `test.pipeline(pipeline, name, callback)` scenario: treat the fixture as `root.started` item state, execute connected nodes in order with the callback's bound `runCode` and `renderUi` helpers, merge only each node's declared outputs, and assert the final `root.completed` fields. Cover meaningful match branches, optional paths, and failures as well as the happy path.
|
|
96
96
|
|
|
@@ -25,6 +25,7 @@ Use `about.projectType: 'data_collection'` only when experts upload or record me
|
|
|
25
25
|
- `audienceAndPricing`: either a human audience or synthetic generation.
|
|
26
26
|
- `onboarding`: built-in Training stage.
|
|
27
27
|
- `exam`: optional built-in qualification gate.
|
|
28
|
+
- `allowedExperts` and `excludedExperts`: experts allowed or kept off per item, for some teams only (see [Per-item expert settings](#per-item-expert-settings)).
|
|
28
29
|
- `checks`: stored test cases (see [node checks](node-checks.md)). `reuseAudienceWithNodeId` and `smartSearch` are still accepted but deploy ignores them.
|
|
29
30
|
|
|
30
31
|
This file says when and why to use each setting. For its exact shape (fields, optionality, allowed values, defaults and bounds), run `toloka schema generation` or `toloka schema quorum`, or the type name such as `Onboarding` or `GenerationExam`, before writing a setting the example you borrow from does not show.
|
|
@@ -165,6 +166,31 @@ Expert lists and expert bans are enabled for a team together: `toloka expert-lis
|
|
|
165
166
|
- Don't use the same list for labeling and human QA: experts would review their own work, and validation warns about it. To keep them apart while the lists overlap, exclude the labeling lists from the QA condition with `list_nin`.
|
|
166
167
|
- Ban experts from the project with `toloka expert-ban-list add <expertIds...> --reason <text>` (or `--file`), lift bans with `toloka expert-ban-list remove`, and see them with `toloka expert-ban-list show` and `toloka expert-ban-list experts`. Banned experts can't be invited and are removed from the work they are in, so confirm the expert IDs with the user before banning. Team-wide bans are managed in the platform UI only.
|
|
167
168
|
|
|
169
|
+
#### Per-item expert settings
|
|
170
|
+
|
|
171
|
+
Only some teams have per-item expert settings. Add them only when your instructions say per-item expert settings are enabled for the team, and use `allowedExperts` only when they name it too. For a team without them, validation rejects the node with `Per-item expert settings are not enabled for this team` (or `Allowed experts per item require expert lists` for `allowedExperts`): tell the user the setting is not available for their team and remove it.
|
|
172
|
+
|
|
173
|
+
They decide, item by item, which experts may take the item's task, from the item's own fields. Use them only when that depends on the item. A fixed set of experts belongs in an expert-list condition, a fixed exclusion in `list_nin` or an expert ban (see [Expert lists and bans](#expert-lists-and-bans)). Typical uses: the reviewer must not be the expert who wrote the answer; a fix-up task goes back to the expert named in a dataset field; a dataset field lists experts to keep off that item.
|
|
174
|
+
|
|
175
|
+
Both settings are lists of up to 20 field references. A reference is a declared `field(...)` whose schema is `{ type: "string" }` (one expert ID) or `{ type: "array", items: { type: "string" } }` (a list of IDs), or an expert ID field of another node in the pipeline: a `generation` node's `writer.annotatorId` and `writer.qaAnnotatorId` (the latter only with `human_only` or `hybrid` QA), a `quorum` node's `reviewer.annotatorIds`. Never declare those implicit fields with `field()`; import the node's binding from its `node.ts`. The field must reach the node: a dataset field the pipeline starts with, or the expert ID field of a node upstream of it.
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
const assignedExpert = field("assigned_expert", { type: "string" });
|
|
179
|
+
const blockedExperts = field("blocked_experts", { type: "array", items: { type: "string" } });
|
|
180
|
+
const writer = generation("writer", { /* … */ });
|
|
181
|
+
const reviewer = quorum("reviewer", { /* … */, excludedExperts: [writer.annotatorId, blockedExperts] });
|
|
182
|
+
const fixer = generation("fixer", {
|
|
183
|
+
audienceAndPricing: { audienceType: "human", expertListCondition: { operator: "list_in", expertListId: "exl.…" }, /* … */ },
|
|
184
|
+
allowedExperts: [assignedExpert],
|
|
185
|
+
excludedExperts: [writer.annotatorId, reviewer.annotatorIds],
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
- `excludedExperts` (`generation` and `quorum`): the experts the fields name for an item can't take its task, on top of the experts the platform already keeps off it. An expert ID is 1 to 128 characters of letters, digits, `_`, `.`, `:` and `-`. A value that is not a valid expert ID (an empty string, other characters, more than 128 characters) is skipped, and the item's trace records a warning; more than 100 IDs across the fields fail the item.
|
|
190
|
+
- `allowedExperts` (`generation` only; `quorum` has none): only the experts the fields name for an item can take its task. The node's `audienceAndPricing` must use an `expertListCondition`, and experts outside those lists are left out with a trace warning. The item fails when its fields are all empty, when a field holds a value that is not a valid expert ID, when they name more than 100 experts, or when no allowed expert is left in the lists and not excluded. A field can't be in both settings.
|
|
191
|
+
- The platform applies them every time it puts the item's task up for experts: the first upload and every new upload after a rejection or expiry on `generation`, and the quorum's tasks. Synthetic generation rejects both settings.
|
|
192
|
+
- The item's trace records them on `task_uploaded`: `allowed_experts`, `excluded_experts` and `expert_warnings` (one message per field with values that are not expert IDs or allowed experts outside the lists); a failed item has the reason `per_item_experts_error`.
|
|
193
|
+
|
|
168
194
|
#### Customer review
|
|
169
195
|
|
|
170
196
|
Customer review is a QA mode of `generation` nodes, not `quorum`, in which the user's own team accepts or rejects every task. Only some teams have it, and nothing shows in advance which. For a team without it, validation, deploy, and the API answer `403 The "customerReview" feature is not enabled for this team`, and `toloka review` prints `Customer review is not enabled for this team.`: tell the user customer review is not available for their team, do not offer it again, and offer another QA mode. Keep `customer_review` on a node that already has it.
|
|
@@ -238,7 +264,7 @@ Deploy ignores `reuseAudienceWithNodeId` and `smartSearch`: every deploy sources
|
|
|
238
264
|
|
|
239
265
|
`quorum(name, settings)` accepts `QuorumAuthoringSettings`, derived from `QuorumNodeSettings`:
|
|
240
266
|
|
|
241
|
-
- `about`, `publicName`, `entities`, `qualityCriteria`, `instruction`, `expectedExpertBehavior`, `ui`, `audienceAndPricing`, `onboarding`, `exam`, `reuseAudienceWithNodeId`, `smartSearch`, and `checks` follow the human-node rules above. A quorum task can be as complex as a generation task, so settle its expected expert behavior the same way.
|
|
267
|
+
- `about`, `publicName`, `entities`, `qualityCriteria`, `instruction`, `expectedExpertBehavior`, `ui`, `audienceAndPricing`, `onboarding`, `exam`, `reuseAudienceWithNodeId`, `smartSearch`, `excludedExperts`, and `checks` follow the human-node rules above. A quorum task can be as complex as a generation task, so settle its expected expert behavior the same way. Quorum has no `allowedExperts`.
|
|
242
268
|
- `overlap` is the fixed number of independent labelers per item: 1–100, though below 2 validation warns that one annotation per item calls for a `generation` node instead. Default to 3 when the user does not specify it; 3 gives a majority, 5 gives stronger consensus, and cost grows linearly.
|
|
243
269
|
- `qualityAssurance` is either `llm_only` or `none`.
|
|
244
270
|
- `offboardingRules` supports majority-vote agreement rules in No-QA mode.
|
|
@@ -298,4 +324,4 @@ When a requirement depends on one of these capabilities, state the gap instead o
|
|
|
298
324
|
- Exam golden-dataset discovery, creation by symbolic dataset name, dataset lint execution, and generated-golden confirmation flow have no high-level SDK authoring path. `exam.goldenDatasetId` requires a real ID.
|
|
299
325
|
- Generation's platform-controlled redo cap, appeal behavior, payment retry, and exact terminal handling are intentionally not configurable SDK settings.
|
|
300
326
|
- Dynamic quorum and per-item overlap are unsupported by both surfaces; this is a platform limitation, not missing TypeScript syntax.
|
|
301
|
-
- Server-owned outputs (`<node>_annotator_id`, `<node>_qa_annotator_id`, and `<node>_annotator_ids`, `*_evaluation_result`, `<node>_qa_metadata`, `<node>_evaluation_summary`) have no authoring path. Source cannot declare them or wire them into a downstream node; read them from the dataset instead.
|
|
327
|
+
- Server-owned outputs (`<node>_annotator_id`, `<node>_qa_annotator_id`, and `<node>_annotator_ids`, `*_evaluation_result`, `<node>_qa_metadata`, `<node>_evaluation_summary`) have no authoring path. Source cannot declare them or wire them into a downstream node; read them from the dataset instead. The one exception is per-item expert settings, which take the expert ID fields as `annotatorId`, `qaAnnotatorId` and `annotatorIds` of the node (see [Per-item expert settings](#per-item-expert-settings)).
|
package/src/authoring/index.ts
CHANGED
|
@@ -19,6 +19,7 @@ const FIELD_DEFINITION = Symbol("fieldDefinition");
|
|
|
19
19
|
const PIPELINE_DEFINITION = Symbol.for("@toloka-platform/sdk/pipeline-definition");
|
|
20
20
|
const PORT_DEFINITION = Symbol("portDefinition");
|
|
21
21
|
const NODE_FIELD_REFERENCES = Symbol("nodeFieldReferences");
|
|
22
|
+
const IMPLICIT_FIELD = Symbol("implicitField");
|
|
22
23
|
|
|
23
24
|
export interface Field<Name extends string = string> {
|
|
24
25
|
readonly id: string;
|
|
@@ -27,6 +28,14 @@ export interface Field<Name extends string = string> {
|
|
|
27
28
|
readonly [FIELD_DEFINITION]: true;
|
|
28
29
|
}
|
|
29
30
|
|
|
31
|
+
export interface ImplicitField {
|
|
32
|
+
readonly id: string;
|
|
33
|
+
readonly node: string;
|
|
34
|
+
readonly [IMPLICIT_FIELD]: true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type FieldRef = Field | ImplicitField;
|
|
38
|
+
|
|
30
39
|
export type AuthoringIdOptions = {
|
|
31
40
|
readonly id?: string;
|
|
32
41
|
};
|
|
@@ -156,6 +165,8 @@ export type GenerationAuthoringSettings = Omit<
|
|
|
156
165
|
| "ui"
|
|
157
166
|
| "onboarding"
|
|
158
167
|
| "exam"
|
|
168
|
+
| "allowedExperts"
|
|
169
|
+
| "excludedExperts"
|
|
159
170
|
> & {
|
|
160
171
|
readonly about?: Omit<GenerationNodeSettings["about"], "name"> & { readonly name?: string };
|
|
161
172
|
readonly entities: {
|
|
@@ -168,6 +179,8 @@ export type GenerationAuthoringSettings = Omit<
|
|
|
168
179
|
readonly ui?: GenerationNodeSettings["ui"];
|
|
169
180
|
readonly onboarding?: GenerationNodeSettings["onboarding"];
|
|
170
181
|
readonly exam?: GenerationExam;
|
|
182
|
+
readonly allowedExperts?: ReadonlyArray<FieldRef>;
|
|
183
|
+
readonly excludedExperts?: ReadonlyArray<FieldRef>;
|
|
171
184
|
};
|
|
172
185
|
|
|
173
186
|
export type MatchAuthoringSettings = Pick<MatchNodeSettings, "about"> & {
|
|
@@ -181,7 +194,7 @@ export type MatchAuthoringSettings = Pick<MatchNodeSettings, "about"> & {
|
|
|
181
194
|
|
|
182
195
|
export type QuorumAuthoringSettings = Omit<
|
|
183
196
|
QuorumNodeSettings,
|
|
184
|
-
"entities" | "qualityCriteria" | "expectedExpertBehavior" | "exam"
|
|
197
|
+
"entities" | "qualityCriteria" | "expectedExpertBehavior" | "exam" | "excludedExperts"
|
|
185
198
|
> & {
|
|
186
199
|
readonly entities: {
|
|
187
200
|
readonly input: ReadonlyArray<QuorumInputEntity>;
|
|
@@ -190,6 +203,7 @@ export type QuorumAuthoringSettings = Omit<
|
|
|
190
203
|
readonly qualityCriteria: ReadonlyArray<QuorumQualityCriterion>;
|
|
191
204
|
readonly expectedExpertBehavior?: string;
|
|
192
205
|
readonly exam?: QuorumExam;
|
|
206
|
+
readonly excludedExperts?: ReadonlyArray<FieldRef>;
|
|
193
207
|
};
|
|
194
208
|
|
|
195
209
|
type WireNode = PipelineGraphV1["nodes"][number];
|
|
@@ -217,6 +231,8 @@ export interface AuthoredCodeNode extends AuthoredNode<CodeNode> {
|
|
|
217
231
|
export interface AuthoredGenerationNode extends AuthoredNode<GenerationNode> {
|
|
218
232
|
readonly input: InputPort;
|
|
219
233
|
readonly output: OutputPort;
|
|
234
|
+
readonly annotatorId: ImplicitField;
|
|
235
|
+
readonly qaAnnotatorId: ImplicitField;
|
|
220
236
|
}
|
|
221
237
|
|
|
222
238
|
export interface AuthoredMatchNode extends AuthoredNode<MatchNode> {
|
|
@@ -228,6 +244,7 @@ export interface AuthoredMatchNode extends AuthoredNode<MatchNode> {
|
|
|
228
244
|
export interface AuthoredQuorumNode extends AuthoredNode<QuorumNode> {
|
|
229
245
|
readonly input: InputPort;
|
|
230
246
|
readonly output: OutputPort;
|
|
247
|
+
readonly annotatorIds: ImplicitField;
|
|
231
248
|
}
|
|
232
249
|
|
|
233
250
|
export type PipelineNode =
|
|
@@ -299,6 +316,10 @@ function outputPort(node: string, handle: string): OutputPort {
|
|
|
299
316
|
return { node, handle, direction: "output", [PORT_DEFINITION]: "output" };
|
|
300
317
|
}
|
|
301
318
|
|
|
319
|
+
function implicitField(node: string, id: string): ImplicitField {
|
|
320
|
+
return { id, node, [IMPLICIT_FIELD]: true };
|
|
321
|
+
}
|
|
322
|
+
|
|
302
323
|
function isField(value: unknown): value is Field {
|
|
303
324
|
return typeof value === "object" && value !== null && FIELD_DEFINITION in value;
|
|
304
325
|
}
|
|
@@ -388,9 +409,13 @@ function compileGenerationSettings(
|
|
|
388
409
|
name: string,
|
|
389
410
|
settings: GenerationAuthoringSettings,
|
|
390
411
|
): GenerationNodeSettings {
|
|
391
|
-
const { exam, ...settingsWithoutExam } = settings;
|
|
412
|
+
const { exam, allowedExperts, excludedExperts, ...settingsWithoutExam } = settings;
|
|
392
413
|
return {
|
|
393
414
|
...settingsWithoutExam,
|
|
415
|
+
...(allowedExperts === undefined ? {} : { allowedExperts: allowedExperts.map(({ id }) => id) }),
|
|
416
|
+
...(excludedExperts === undefined
|
|
417
|
+
? {}
|
|
418
|
+
: { excludedExperts: excludedExperts.map(({ id }) => id) }),
|
|
394
419
|
about: { ...settings.about, name: settings.about?.name ?? name },
|
|
395
420
|
entities: {
|
|
396
421
|
input: settings.entities.input.map(compileGenerationInputEntity),
|
|
@@ -537,6 +562,8 @@ export function generation(
|
|
|
537
562
|
settings: compileGenerationSettings(name, settings),
|
|
538
563
|
input: inputPort(id, "input"),
|
|
539
564
|
output: outputPort(id, "output"),
|
|
565
|
+
annotatorId: implicitField(id, `generation_sft_${id}_annotator_id`),
|
|
566
|
+
qaAnnotatorId: implicitField(id, `generation_sft_${id}_qa_annotator_id`),
|
|
540
567
|
[NODE_FIELD_REFERENCES]: referencedFields(settings),
|
|
541
568
|
};
|
|
542
569
|
}
|
|
@@ -590,12 +617,15 @@ export function quorum(
|
|
|
590
617
|
options: AuthoringIdOptions = {},
|
|
591
618
|
): AuthoredQuorumNode {
|
|
592
619
|
const id = options.id ?? mintedId("quorum", name);
|
|
593
|
-
const { exam, ...settingsWithoutExam } = settings;
|
|
620
|
+
const { exam, excludedExperts, ...settingsWithoutExam } = settings;
|
|
594
621
|
return {
|
|
595
622
|
id,
|
|
596
623
|
type: "quorum",
|
|
597
624
|
settings: {
|
|
598
625
|
...settingsWithoutExam,
|
|
626
|
+
...(excludedExperts === undefined
|
|
627
|
+
? {}
|
|
628
|
+
: { excludedExperts: excludedExperts.map(({ id }) => id) }),
|
|
599
629
|
entities: {
|
|
600
630
|
input: settings.entities.input.map(compileGenerationInputEntity),
|
|
601
631
|
output: settings.entities.output.map(compileGenerationInputEntity),
|
|
@@ -619,6 +649,7 @@ export function quorum(
|
|
|
619
649
|
},
|
|
620
650
|
input: inputPort(id, "input"),
|
|
621
651
|
output: outputPort(id, "output"),
|
|
652
|
+
annotatorIds: implicitField(id, `quorum_sft_${id}_annotator_ids`),
|
|
622
653
|
[NODE_FIELD_REFERENCES]: referencedFields(settings),
|
|
623
654
|
};
|
|
624
655
|
}
|
package/src/cli/poll.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const FIRST_POLL_INTERVAL_MS = 1_000;
|
|
2
|
+
|
|
3
|
+
export const pollUntil = async <T>({
|
|
4
|
+
initial,
|
|
5
|
+
settled,
|
|
6
|
+
poll,
|
|
7
|
+
deadline,
|
|
8
|
+
maxIntervalMs,
|
|
9
|
+
}: {
|
|
10
|
+
readonly initial: T;
|
|
11
|
+
readonly settled: (state: T) => boolean;
|
|
12
|
+
readonly poll: (state: T) => Promise<T>;
|
|
13
|
+
readonly deadline: number;
|
|
14
|
+
readonly maxIntervalMs: number;
|
|
15
|
+
}): Promise<T> => {
|
|
16
|
+
let state = initial;
|
|
17
|
+
let intervalMs = Math.min(FIRST_POLL_INTERVAL_MS, maxIntervalMs);
|
|
18
|
+
while (!settled(state) && Date.now() < deadline) {
|
|
19
|
+
await new Promise<void>((resolve) => {
|
|
20
|
+
setTimeout(resolve, Math.min(intervalMs, deadline - Date.now()));
|
|
21
|
+
});
|
|
22
|
+
state = await poll(state);
|
|
23
|
+
intervalMs = Math.min(intervalMs * 2, maxIntervalMs);
|
|
24
|
+
}
|
|
25
|
+
return state;
|
|
26
|
+
};
|
package/src/cli/project.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { listPipelineSourceDirectories, loadProjectSource } from "./source";
|
|
|
18
18
|
import type { ProjectPipelineSource, ProjectSource } from "./source";
|
|
19
19
|
import { pipelineDirectoryName, resolvePipelineDirectories } from "./pipeline-selector";
|
|
20
20
|
import { assertCli, REPORT_HINT } from "./cli-error";
|
|
21
|
+
import { pollUntil } from "./poll";
|
|
21
22
|
|
|
22
23
|
export type PipelinePlanChange = {
|
|
23
24
|
readonly kind: "node" | "connection" | "field" | "layout";
|
|
@@ -1258,11 +1259,6 @@ type RunningValidation = {
|
|
|
1258
1259
|
readonly failure?: string;
|
|
1259
1260
|
};
|
|
1260
1261
|
|
|
1261
|
-
const sleep = (ms: number) =>
|
|
1262
|
-
new Promise<void>((resolve) => {
|
|
1263
|
-
setTimeout(resolve, ms);
|
|
1264
|
-
});
|
|
1265
|
-
|
|
1266
1262
|
const pollValidationEntry = async (
|
|
1267
1263
|
results: PipelineValidationResult[],
|
|
1268
1264
|
entry: RunningValidation,
|
|
@@ -1282,17 +1278,16 @@ const waitForRunningChecks = async (
|
|
|
1282
1278
|
wait: NonNullable<ValidateProjectOptions["wait"]>,
|
|
1283
1279
|
startedAt: number,
|
|
1284
1280
|
) => {
|
|
1285
|
-
const
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
}
|
|
1281
|
+
const pending = await pollUntil({
|
|
1282
|
+
initial: running,
|
|
1283
|
+
settled: (entries) => entries.length === 0,
|
|
1284
|
+
poll: async (entries) =>
|
|
1285
|
+
(await Promise.all(entries.map((entry) => pollValidationEntry(results, entry)))).filter(
|
|
1286
|
+
(entry): entry is RunningValidation => entry !== undefined,
|
|
1287
|
+
),
|
|
1288
|
+
deadline: startedAt + wait.timeoutMs,
|
|
1289
|
+
maxIntervalMs: wait.pollIntervalMs,
|
|
1290
|
+
});
|
|
1296
1291
|
const waitedSeconds = Math.round((Date.now() - startedAt) / 1000);
|
|
1297
1292
|
for (const entry of pending) {
|
|
1298
1293
|
const result = results[entry.index]!;
|
|
@@ -1379,13 +1374,11 @@ export async function validateProject(
|
|
|
1379
1374
|
const startedAt = Date.now();
|
|
1380
1375
|
const inspection = await inspectProject(client, options);
|
|
1381
1376
|
const { wait } = options;
|
|
1382
|
-
const
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
if (poll !== undefined) running.push({ index: results.length - 1, validate: poll });
|
|
1388
|
-
}
|
|
1377
|
+
const entries = await Promise.all(
|
|
1378
|
+
inspection.pipelines.map((pipeline) => validatePipelineEntry(client, inspection, pipeline, wait)),
|
|
1379
|
+
);
|
|
1380
|
+
const results = entries.map(({ result }) => result);
|
|
1381
|
+
const running = entries.flatMap(({ poll }, index) => (poll === undefined ? [] : [{ index, validate: poll }]));
|
|
1389
1382
|
if (wait !== undefined) await waitForRunningChecks(results, running, wait, startedAt);
|
|
1390
1383
|
const valid = results.every(
|
|
1391
1384
|
(result) => result.status !== "invalid" && result.status !== "checks_running",
|
package/src/cli/runs.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { RunItem, RunJob } from "../index";
|
|
|
6
6
|
import { assertCli } from "./cli-error";
|
|
7
7
|
import { apiErrorDetails } from "./format-error";
|
|
8
8
|
import { matchesNormalizedPipelineName } from "./pipeline-selector";
|
|
9
|
+
import { pollUntil } from "./poll";
|
|
9
10
|
|
|
10
11
|
export type PipelineRef = {
|
|
11
12
|
readonly pipelineId: string;
|
|
@@ -266,24 +267,22 @@ type LintJob = Awaited<ReturnType<PotatoClient["checks"]["runLints"]>>["checks"]
|
|
|
266
267
|
|
|
267
268
|
const isLintFinished = (job: LintJob) => job.status === "succeeded" || job.status === "failed";
|
|
268
269
|
|
|
269
|
-
const waitForLints =
|
|
270
|
+
const waitForLints = (
|
|
270
271
|
client: PotatoClient,
|
|
271
272
|
jobs: readonly LintJob[],
|
|
272
273
|
timeoutMs: number,
|
|
273
274
|
intervalMs: number,
|
|
274
|
-
): Promise<readonly LintJob[]> =>
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
return current;
|
|
286
|
-
};
|
|
275
|
+
): Promise<readonly LintJob[]> =>
|
|
276
|
+
pollUntil({
|
|
277
|
+
initial: jobs,
|
|
278
|
+
settled: (current) => current.every(isLintFinished),
|
|
279
|
+
poll: (current) =>
|
|
280
|
+
Promise.all(
|
|
281
|
+
current.map(async (job) => (isLintFinished(job) ? job : client.checks.get({ checkRunId: job.id }))),
|
|
282
|
+
),
|
|
283
|
+
deadline: Date.now() + timeoutMs,
|
|
284
|
+
maxIntervalMs: intervalMs,
|
|
285
|
+
});
|
|
287
286
|
|
|
288
287
|
const runLints = async (
|
|
289
288
|
client: PotatoClient,
|
package/src/importer.ts
CHANGED
|
@@ -28,6 +28,12 @@ type NodeEmission = {
|
|
|
28
28
|
readonly source: string;
|
|
29
29
|
};
|
|
30
30
|
type FieldReference = (id: string) => SourceReference;
|
|
31
|
+
type ImplicitFieldSource = {
|
|
32
|
+
readonly node: string;
|
|
33
|
+
readonly binding: string;
|
|
34
|
+
readonly directory: string;
|
|
35
|
+
readonly property: "annotatorId" | "qaAnnotatorId" | "annotatorIds";
|
|
36
|
+
};
|
|
31
37
|
|
|
32
38
|
const SOURCE_REFERENCE = Symbol("sourceReference");
|
|
33
39
|
const BLOCKED_BINDINGS: Record<string, true> = {
|
|
@@ -311,7 +317,21 @@ const withoutEmptyChecks = (
|
|
|
311
317
|
return kept.length === 0 ? undefined : Object.fromEntries(kept);
|
|
312
318
|
};
|
|
313
319
|
|
|
314
|
-
function
|
|
320
|
+
function expertFieldsSetting(
|
|
321
|
+
settingName: "allowedExperts" | "excludedExperts",
|
|
322
|
+
fieldIds: ReadonlyArray<string> | undefined,
|
|
323
|
+
expertFieldReference: FieldReference,
|
|
324
|
+
): Record<string, unknown> {
|
|
325
|
+
return fieldIds === undefined || fieldIds.length === 0
|
|
326
|
+
? {}
|
|
327
|
+
: { [settingName]: fieldIds.map(expertFieldReference) };
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function authoringSettings(
|
|
331
|
+
node: GraphNode,
|
|
332
|
+
fieldReference: FieldReference,
|
|
333
|
+
expertFieldReference: FieldReference,
|
|
334
|
+
): unknown {
|
|
315
335
|
switch (node.type) {
|
|
316
336
|
case "root": {
|
|
317
337
|
const {
|
|
@@ -346,11 +366,21 @@ function authoringSettings(node: GraphNode, fieldReference: FieldReference): unk
|
|
|
346
366
|
};
|
|
347
367
|
}
|
|
348
368
|
case "generation": {
|
|
349
|
-
const {
|
|
369
|
+
const {
|
|
370
|
+
entities,
|
|
371
|
+
qualityCriteria,
|
|
372
|
+
exam,
|
|
373
|
+
checks,
|
|
374
|
+
allowedExperts,
|
|
375
|
+
excludedExperts,
|
|
376
|
+
...settings
|
|
377
|
+
} = node.settings;
|
|
350
378
|
const authoredChecks = withoutEmptyChecks(checks);
|
|
351
379
|
return {
|
|
352
380
|
...settings,
|
|
353
381
|
...(authoredChecks === undefined ? {} : { checks: authoredChecks }),
|
|
382
|
+
...expertFieldsSetting("allowedExperts", allowedExperts, expertFieldReference),
|
|
383
|
+
...expertFieldsSetting("excludedExperts", excludedExperts, expertFieldReference),
|
|
354
384
|
entities: {
|
|
355
385
|
input: entities.input.map((entity) => transformEntity(entity, fieldReference)),
|
|
356
386
|
output: entities.output.map((entity) => transformEntity(entity, fieldReference)),
|
|
@@ -378,11 +408,13 @@ function authoringSettings(node: GraphNode, fieldReference: FieldReference): unk
|
|
|
378
408
|
};
|
|
379
409
|
}
|
|
380
410
|
case "quorum": {
|
|
381
|
-
const { entities, qualityCriteria, exam, checks, ...settings } =
|
|
411
|
+
const { entities, qualityCriteria, exam, checks, excludedExperts, ...settings } =
|
|
412
|
+
node.settings;
|
|
382
413
|
const authoredChecks = withoutEmptyChecks(checks);
|
|
383
414
|
return {
|
|
384
415
|
...settings,
|
|
385
416
|
...(authoredChecks === undefined ? {} : { checks: authoredChecks }),
|
|
417
|
+
...expertFieldsSetting("excludedExperts", excludedExperts, expertFieldReference),
|
|
386
418
|
entities: {
|
|
387
419
|
input: entities.input.map((entity) => transformEntity(entity, fieldReference)),
|
|
388
420
|
output: entities.output.map((entity) => transformEntity(entity, fieldReference)),
|
|
@@ -401,6 +433,7 @@ function nodeSource(
|
|
|
401
433
|
binding: string,
|
|
402
434
|
path: string,
|
|
403
435
|
fieldBindings: ReadonlyMap<string, string>,
|
|
436
|
+
implicitFields: ReadonlyMap<string, ImplicitFieldSource>,
|
|
404
437
|
): NodeEmission {
|
|
405
438
|
const referencedFields = new Set<string>();
|
|
406
439
|
const fieldReference = (id: string): SourceReference => {
|
|
@@ -409,13 +442,30 @@ function nodeSource(
|
|
|
409
442
|
referencedFields.add(referencedBinding);
|
|
410
443
|
return { name: referencedBinding, [SOURCE_REFERENCE]: true };
|
|
411
444
|
};
|
|
412
|
-
const
|
|
445
|
+
const referencedNodes = new Map<string, string>();
|
|
446
|
+
const expertFieldReference = (id: string): SourceReference => {
|
|
447
|
+
if (fieldBindings.has(id)) return fieldReference(id);
|
|
448
|
+
const source = implicitFields.get(id);
|
|
449
|
+
assert(source, `Node "${node.id}" takes experts from unknown field "${id}"`);
|
|
450
|
+
assert(source.node !== node.id, `Node "${node.id}" takes experts from its own field "${id}"`);
|
|
451
|
+
referencedNodes.set(source.binding, source.directory);
|
|
452
|
+
return { name: `${source.binding}.${source.property}`, [SOURCE_REFERENCE]: true };
|
|
453
|
+
};
|
|
454
|
+
const settings = authoringSettings(node, fieldReference, expertFieldReference);
|
|
413
455
|
const fieldImport = [...referencedFields].toSorted(compareText);
|
|
456
|
+
const nodeImports = [...referencedNodes]
|
|
457
|
+
.toSorted(([left], [right]) => compareText(left, right))
|
|
458
|
+
.map(
|
|
459
|
+
([referencedBinding, referencedDirectory]) =>
|
|
460
|
+
`import { ${referencedBinding} } from '../${referencedDirectory}/node';`,
|
|
461
|
+
);
|
|
414
462
|
const imports = [
|
|
415
463
|
`import { ${node.type} } from '@toloka-platform/sdk';`,
|
|
464
|
+
...(fieldImport.length === 0 && nodeImports.length === 0 ? [] : [""]),
|
|
416
465
|
...(fieldImport.length === 0
|
|
417
466
|
? []
|
|
418
|
-
: [
|
|
467
|
+
: [`import { ${fieldImport.join(", ")} } from '../../fields';`]),
|
|
468
|
+
...nodeImports,
|
|
419
469
|
];
|
|
420
470
|
const argumentsSource =
|
|
421
471
|
node.type === "root"
|
|
@@ -656,11 +706,33 @@ export function generatePipelineSourceTree(
|
|
|
656
706
|
return [node.id, binding];
|
|
657
707
|
}),
|
|
658
708
|
);
|
|
709
|
+
const implicitFields = new Map(
|
|
710
|
+
graph.nodes.flatMap((node): Array<[string, ImplicitFieldSource]> => {
|
|
711
|
+
const binding = nodeBindings.get(node.id);
|
|
712
|
+
const directory = directories.get(`node:${node.id}`);
|
|
713
|
+
assert(binding && directory, `Node "${node.id}" has no allocated source name`);
|
|
714
|
+
const source = (property: ImplicitFieldSource["property"]) => ({
|
|
715
|
+
node: node.id,
|
|
716
|
+
binding,
|
|
717
|
+
directory,
|
|
718
|
+
property,
|
|
719
|
+
});
|
|
720
|
+
if (node.type === "generation") {
|
|
721
|
+
return [
|
|
722
|
+
[`generation_sft_${node.id}_annotator_id`, source("annotatorId")],
|
|
723
|
+
[`generation_sft_${node.id}_qa_annotator_id`, source("qaAnnotatorId")],
|
|
724
|
+
];
|
|
725
|
+
}
|
|
726
|
+
return node.type === "quorum"
|
|
727
|
+
? [[`quorum_sft_${node.id}_annotator_ids`, source("annotatorIds")]]
|
|
728
|
+
: [];
|
|
729
|
+
}),
|
|
730
|
+
);
|
|
659
731
|
const nodeEmissions = graph.nodes.map((node) => {
|
|
660
732
|
const binding = nodeBindings.get(node.id);
|
|
661
733
|
const directory = directories.get(`node:${node.id}`);
|
|
662
734
|
assert(binding && directory, `Node "${node.id}" has no allocated source name`);
|
|
663
|
-
return nodeSource(node, binding, `nodes/${directory}/node.ts`, fieldBindings);
|
|
735
|
+
return nodeSource(node, binding, `nodes/${directory}/node.ts`, fieldBindings, implicitFields);
|
|
664
736
|
});
|
|
665
737
|
const entries = [
|
|
666
738
|
{
|
package/src/index.ts
CHANGED
|
@@ -102,12 +102,14 @@ export type {
|
|
|
102
102
|
CodeAuthoringSettings,
|
|
103
103
|
Connection,
|
|
104
104
|
Field,
|
|
105
|
+
FieldRef,
|
|
105
106
|
GenerationAuthoringSettings,
|
|
106
107
|
InvalidJsonSchemaSource,
|
|
107
108
|
InputPort,
|
|
108
109
|
MatchAuthoringSettings,
|
|
109
110
|
OutputPort,
|
|
110
111
|
OptionalFieldBinding,
|
|
112
|
+
ImplicitField,
|
|
111
113
|
PipelineDefinition,
|
|
112
114
|
PipelineDefinitionBindings,
|
|
113
115
|
PipelineDefinitionInput,
|
|
@@ -2476,6 +2476,24 @@
|
|
|
2476
2476
|
}
|
|
2477
2477
|
]
|
|
2478
2478
|
},
|
|
2479
|
+
"allowedExperts": {
|
|
2480
|
+
"default": [],
|
|
2481
|
+
"description": "Ids of up to 20 fields at the node's input, each holding an expert id (string) or a list of expert ids (array of strings). Before each upload of an item's task, only the experts these fields name for the item can take it, and only those in the node's expert-list audience. An expert id is 1 to 128 letters, digits, `_`, `.`, `:` or `-`; a value that is not one fails the item, as does an item whose fields name no such expert or more than 100 of them. Experts outside the node's expert lists are skipped with a warning in the item trace. Requires per-item expert settings and expert lists for the team and an expert-list audience. `[]` lets any expert of the audience take the task.",
|
|
2482
|
+
"maxItems": 20,
|
|
2483
|
+
"type": "array",
|
|
2484
|
+
"items": {
|
|
2485
|
+
"type": "string"
|
|
2486
|
+
}
|
|
2487
|
+
},
|
|
2488
|
+
"excludedExperts": {
|
|
2489
|
+
"default": [],
|
|
2490
|
+
"description": "Ids of up to 20 fields at the node's input, each holding an expert id or a list of expert ids: a dataset field, or an upstream node's `generation_sft_<nodeId>_annotator_id`, `generation_sft_<nodeId>_qa_annotator_id` or `quorum_sft_<nodeId>_annotator_ids`. The experts they name for an item can't take its task, on top of the experts the platform already excludes. An expert id is 1 to 128 letters, digits, `_`, `.`, `:` or `-`; other values are skipped with a warning in the item trace; more than 100 ids fail the item. Requires per-item expert settings for the team. `[]` adds no exclusions.",
|
|
2491
|
+
"maxItems": 20,
|
|
2492
|
+
"type": "array",
|
|
2493
|
+
"items": {
|
|
2494
|
+
"type": "string"
|
|
2495
|
+
}
|
|
2496
|
+
},
|
|
2479
2497
|
"checks": {
|
|
2480
2498
|
"type": "object",
|
|
2481
2499
|
"propertyNames": {
|
|
@@ -4302,6 +4320,15 @@
|
|
|
4302
4320
|
}
|
|
4303
4321
|
]
|
|
4304
4322
|
},
|
|
4323
|
+
"excludedExperts": {
|
|
4324
|
+
"default": [],
|
|
4325
|
+
"description": "Ids of up to 20 fields at the node's input, each holding an expert id or a list of expert ids: a dataset field, or an upstream node's `generation_sft_<nodeId>_annotator_id`, `generation_sft_<nodeId>_qa_annotator_id` or `quorum_sft_<nodeId>_annotator_ids`. The experts they name for an item can't take its quorum tasks, on top of the experts the platform already excludes. An expert id is 1 to 128 letters, digits, `_`, `.`, `:` or `-`; other values are skipped with a warning in the item trace; more than 100 ids fail the item. Requires per-item expert settings for the team. `[]` adds no exclusions.",
|
|
4326
|
+
"maxItems": 20,
|
|
4327
|
+
"type": "array",
|
|
4328
|
+
"items": {
|
|
4329
|
+
"type": "string"
|
|
4330
|
+
}
|
|
4331
|
+
},
|
|
4305
4332
|
"checks": {
|
|
4306
4333
|
"type": "object",
|
|
4307
4334
|
"propertyNames": {
|