@toloka-platform/sdk 0.25.2 → 0.26.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.
- package/dist/cli/toloka.js +187 -170
- 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/examples/app-crowdtesting/nodes/app-flow-test/node.ts +24 -0
- package/examples/egocentric-video-collection/nodes/record-activity/node.ts +24 -0
- package/examples/face-image-collection/nodes/annotate-faces/node.ts +16 -1
- package/examples/product-moderation/nodes/moderate-product/instruction.ts +4 -0
- package/examples/product-moderation/nodes/moderate-product/node.ts +19 -0
- package/examples/video-pair-rating/nodes/adjudicate/node.ts +18 -1
- package/examples/video-pair-rating/nodes/adjudicate_op/node.ts +18 -1
- package/examples/video-pair-rating/nodes/overall_preference_pick/node.ts +18 -1
- package/examples/video-pair-rating/nodes/rate_pair/node.ts +18 -1
- package/openapi/gen/api.schemas.ts +50 -42
- package/package.json +3 -3
- package/skills/catalog.json +6 -6
- package/skills/toloka-build/SKILL.md +9 -7
- package/skills/toloka-build/references/human-work.md +97 -8
- package/skills/toloka-build/references/workflow-and-cli.md +7 -7
- package/src/authoring/index.ts +13 -2
- package/src/checks/task-ui-typecheck.ts +1 -1
- package/src/cli/analytics.ts +1 -0
- package/src/cli/check.ts +60 -30
- package/src/cli/commands/schema.ts +27 -0
- package/src/cli/commands/source.ts +14 -6
- package/src/cli/pipeline-selector.ts +68 -0
- package/src/cli/program.ts +2 -0
- package/src/cli/project.ts +47 -27
- package/src/cli/runs.ts +9 -0
- package/src/cli/schema.ts +633 -0
- package/src/cli/source.ts +16 -2
- package/src/graph-rules.json +3 -1
- package/src/pipeline-graph-v1.contract.json +12 -4
- package/src/validate.ts +23 -2
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { TolokaState } from "../state";
|
|
2
|
+
import { assertCli } from "./cli-error";
|
|
3
|
+
|
|
4
|
+
export const pipelineDirectoryName = (name: string): string =>
|
|
5
|
+
name
|
|
6
|
+
.toLowerCase()
|
|
7
|
+
.match(/[a-z0-9]+/gu)
|
|
8
|
+
?.join("-") || "pipeline";
|
|
9
|
+
|
|
10
|
+
export const lastDirectorySegment = (directory: string): string =>
|
|
11
|
+
directory.split("/").at(-1) ?? directory;
|
|
12
|
+
|
|
13
|
+
export const matchesNormalizedPipelineName = (
|
|
14
|
+
selector: string,
|
|
15
|
+
{ name, sourceDirectory }: { readonly name?: string; readonly sourceDirectory?: string },
|
|
16
|
+
): boolean => {
|
|
17
|
+
const normalized = pipelineDirectoryName(selector);
|
|
18
|
+
return (
|
|
19
|
+
(sourceDirectory !== undefined && lastDirectorySegment(sourceDirectory) === normalized) ||
|
|
20
|
+
(name !== undefined && pipelineDirectoryName(name) === normalized)
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const resolvePipelineDirectories = ({
|
|
25
|
+
selectors,
|
|
26
|
+
directories,
|
|
27
|
+
state,
|
|
28
|
+
}: {
|
|
29
|
+
readonly selectors: readonly string[];
|
|
30
|
+
readonly directories: readonly string[];
|
|
31
|
+
readonly state: TolokaState | undefined;
|
|
32
|
+
}): readonly string[] => {
|
|
33
|
+
const pipelineIds = new Map(
|
|
34
|
+
Object.entries(state?.pipelines ?? {}).map(([directory, { pipelineId }]) => [directory, pipelineId]),
|
|
35
|
+
);
|
|
36
|
+
const describe = (candidates: readonly string[]) =>
|
|
37
|
+
candidates
|
|
38
|
+
.map((directory) => {
|
|
39
|
+
const pipelineId = pipelineIds.get(directory);
|
|
40
|
+
return pipelineId === undefined ? directory : `${directory} (${pipelineId})`;
|
|
41
|
+
})
|
|
42
|
+
.join(", ");
|
|
43
|
+
const tiers: readonly ((selector: string, directory: string) => boolean)[] = [
|
|
44
|
+
(selector, directory) => directory === selector || pipelineIds.get(directory) === selector,
|
|
45
|
+
(selector, directory) => lastDirectorySegment(directory) === selector,
|
|
46
|
+
(selector, directory) => matchesNormalizedPipelineName(selector, { sourceDirectory: directory }),
|
|
47
|
+
];
|
|
48
|
+
const resolved = selectors.map((selector) => {
|
|
49
|
+
const matches =
|
|
50
|
+
tiers
|
|
51
|
+
.map((tier) => directories.filter((directory) => tier(selector, directory)))
|
|
52
|
+
.find((tierMatches) => tierMatches.length > 0) ?? [];
|
|
53
|
+
assertCli(
|
|
54
|
+
matches.length > 0,
|
|
55
|
+
directories.length === 0
|
|
56
|
+
? `Unknown pipeline ${JSON.stringify(selector)}: this project has no pipeline sources.`
|
|
57
|
+
: `Unknown pipeline ${JSON.stringify(selector)}. This project's pipelines: ${describe(directories)}.`,
|
|
58
|
+
{ hint: { description: "Pass a source directory, its last segment, or a pipeline id." } },
|
|
59
|
+
);
|
|
60
|
+
assertCli(
|
|
61
|
+
matches.length === 1,
|
|
62
|
+
`Pipeline ${JSON.stringify(selector)} is ambiguous: ${describe(matches)}.`,
|
|
63
|
+
{ hint: { description: "Pass the full source directory or the pipeline id." } },
|
|
64
|
+
);
|
|
65
|
+
return matches[0]!;
|
|
66
|
+
});
|
|
67
|
+
return [...new Set(resolved)];
|
|
68
|
+
};
|
package/src/cli/program.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { registerReportCommand } from "./commands/report";
|
|
|
20
20
|
import { registerExpertBanListCommands } from "./commands/expert-ban-list";
|
|
21
21
|
import { registerExpertListCommands } from "./commands/expert-list";
|
|
22
22
|
import { registerReviewCommands } from "./commands/review";
|
|
23
|
+
import { registerSchemaCommand } from "./commands/schema";
|
|
23
24
|
import { registerSecretCommands } from "./commands/secret";
|
|
24
25
|
import { registerSkillCommands } from "./commands/skill";
|
|
25
26
|
import { registerSourceCommands } from "./commands/source";
|
|
@@ -119,6 +120,7 @@ export function createProgram(context: ProgramContext): CreatedProgram {
|
|
|
119
120
|
registerReportCommand(program, host);
|
|
120
121
|
registerSkillCommands(program, host);
|
|
121
122
|
registerUiCommands(program, host);
|
|
123
|
+
registerSchemaCommand(program, host);
|
|
122
124
|
|
|
123
125
|
program
|
|
124
126
|
.command("help")
|
package/src/cli/project.ts
CHANGED
|
@@ -14,8 +14,9 @@ import { platformRuleIssues } from "../validate";
|
|
|
14
14
|
import type { TolokaState } from "../state";
|
|
15
15
|
import { assertProjectSelected } from "./project-context";
|
|
16
16
|
import { collectGraphSecretNames } from "./secrets";
|
|
17
|
-
import { loadProjectSource } from "./source";
|
|
17
|
+
import { listPipelineSourceDirectories, loadProjectSource } from "./source";
|
|
18
18
|
import type { ProjectPipelineSource, ProjectSource } from "./source";
|
|
19
|
+
import { pipelineDirectoryName, resolvePipelineDirectories } from "./pipeline-selector";
|
|
19
20
|
import { assertCli, REPORT_HINT } from "./cli-error";
|
|
20
21
|
|
|
21
22
|
export type PipelinePlanChange = {
|
|
@@ -57,6 +58,7 @@ export type ImportProjectResult = {
|
|
|
57
58
|
export type PlanProjectOptions = {
|
|
58
59
|
readonly sourceRoot: string;
|
|
59
60
|
readonly source?: ProjectSource;
|
|
61
|
+
readonly pipelines?: readonly string[];
|
|
60
62
|
readonly projectId?: string;
|
|
61
63
|
readonly listAllSecrets?: boolean;
|
|
62
64
|
};
|
|
@@ -138,6 +140,7 @@ type PipelineInspection = {
|
|
|
138
140
|
type ProjectInspection = {
|
|
139
141
|
readonly projectId: string;
|
|
140
142
|
readonly source: ProjectSource;
|
|
143
|
+
readonly selected: boolean;
|
|
141
144
|
readonly state: TolokaState | undefined;
|
|
142
145
|
readonly datasets: readonly DatasetInspection[];
|
|
143
146
|
readonly pipelines: readonly PipelineInspection[];
|
|
@@ -701,9 +704,19 @@ const inspectProject = async (
|
|
|
701
704
|
client: PotatoClient,
|
|
702
705
|
options: PlanProjectOptions,
|
|
703
706
|
): Promise<ProjectInspection> => {
|
|
704
|
-
const source = options.source ?? (await loadProjectSource(options.sourceRoot));
|
|
705
|
-
validateSource(source);
|
|
706
707
|
const state = await readTolokaState(options.sourceRoot);
|
|
708
|
+
const sourceDirectories =
|
|
709
|
+
options.pipelines === undefined || options.pipelines.length === 0
|
|
710
|
+
? undefined
|
|
711
|
+
: await listPipelineSourceDirectories(options.sourceRoot);
|
|
712
|
+
const selectedDirectories =
|
|
713
|
+
sourceDirectories === undefined
|
|
714
|
+
? undefined
|
|
715
|
+
: resolvePipelineDirectories({ selectors: options.pipelines ?? [], directories: sourceDirectories, state });
|
|
716
|
+
const source =
|
|
717
|
+
options.source ?? (await loadProjectSource(options.sourceRoot, selectedDirectories));
|
|
718
|
+
validateSource(source);
|
|
719
|
+
const selected = selectedDirectories !== undefined;
|
|
707
720
|
const projectId = options.projectId ?? state?.projectId;
|
|
708
721
|
assertProjectSelected(projectId);
|
|
709
722
|
|
|
@@ -718,14 +731,16 @@ const inspectProject = async (
|
|
|
718
731
|
shouldListSecrets ? client.secrets.list({ projectId }) : Promise.resolve([]),
|
|
719
732
|
]);
|
|
720
733
|
const requiredDatasets = desiredDatasets(source);
|
|
721
|
-
const removedDatasets =
|
|
722
|
-
|
|
723
|
-
.
|
|
734
|
+
const removedDatasets = selected
|
|
735
|
+
? []
|
|
736
|
+
: Object.keys(bindings?.datasets ?? {})
|
|
737
|
+
.filter((name) => !requiredDatasets.some((dataset) => dataset.name === name))
|
|
738
|
+
.toSorted();
|
|
739
|
+
const presentDirectories = new Set(
|
|
740
|
+
sourceDirectories ?? source.pipelines.map((pipeline) => pipeline.sourceDirectory),
|
|
741
|
+
);
|
|
724
742
|
const removedPipelines = Object.keys(bindings?.pipelines ?? {})
|
|
725
|
-
.filter(
|
|
726
|
-
(sourceDirectory) =>
|
|
727
|
-
!source.pipelines.some((pipeline) => pipeline.sourceDirectory === sourceDirectory),
|
|
728
|
-
)
|
|
743
|
+
.filter((sourceDirectory) => !presentDirectories.has(sourceDirectory))
|
|
729
744
|
.toSorted();
|
|
730
745
|
const datasets = await inspectDatasets(client, requiredDatasets, bindings, liveDatasets);
|
|
731
746
|
const pipelines = await inspectPipelines(client, source, bindings, datasets, livePipelines);
|
|
@@ -736,6 +751,7 @@ const inspectProject = async (
|
|
|
736
751
|
return {
|
|
737
752
|
projectId,
|
|
738
753
|
source,
|
|
754
|
+
selected,
|
|
739
755
|
state,
|
|
740
756
|
datasets,
|
|
741
757
|
pipelines,
|
|
@@ -749,12 +765,6 @@ const inspectProject = async (
|
|
|
749
765
|
};
|
|
750
766
|
};
|
|
751
767
|
|
|
752
|
-
const sourceDirectoryBase = (name: string) =>
|
|
753
|
-
name
|
|
754
|
-
.toLowerCase()
|
|
755
|
-
.match(/[a-z0-9]+/gu)
|
|
756
|
-
?.join("-") || "pipeline";
|
|
757
|
-
|
|
758
768
|
const hash = (value: string) => {
|
|
759
769
|
let result = 0x811c9dc5;
|
|
760
770
|
for (let index = 0; index < value.length; index += 1) {
|
|
@@ -765,10 +775,10 @@ const hash = (value: string) => {
|
|
|
765
775
|
};
|
|
766
776
|
|
|
767
777
|
const pipelineSourceDirectories = (pipelines: readonly Pipeline[]) => {
|
|
768
|
-
const groups = Map.groupBy(pipelines, (pipeline) =>
|
|
778
|
+
const groups = Map.groupBy(pipelines, (pipeline) => pipelineDirectoryName(pipeline.name));
|
|
769
779
|
return new Map(
|
|
770
780
|
pipelines.map((pipeline) => {
|
|
771
|
-
const base =
|
|
781
|
+
const base = pipelineDirectoryName(pipeline.name);
|
|
772
782
|
const collision = (groups.get(base)?.length ?? 0) > 1;
|
|
773
783
|
return [pipeline.id, `pipelines/${collision ? `${base}-${hash(pipeline.id)}` : base}`];
|
|
774
784
|
}),
|
|
@@ -1089,9 +1099,15 @@ export async function applyProject(
|
|
|
1089
1099
|
writes += applied.writes;
|
|
1090
1100
|
}
|
|
1091
1101
|
|
|
1102
|
+
const keptBindings =
|
|
1103
|
+
inspection.selected && inspection.state?.projectId === inspection.projectId
|
|
1104
|
+
? inspection.state
|
|
1105
|
+
: undefined;
|
|
1092
1106
|
const nextState: TolokaState = {
|
|
1093
1107
|
projectId: inspection.projectId,
|
|
1094
|
-
pipelines:
|
|
1108
|
+
pipelines: {
|
|
1109
|
+
...keptBindings?.pipelines,
|
|
1110
|
+
...Object.fromEntries(
|
|
1095
1111
|
inspection.source.pipelines.map((pipeline) => {
|
|
1096
1112
|
const pipelineId = pipelineIds.get(pipeline.sourceDirectory);
|
|
1097
1113
|
assertCli(
|
|
@@ -1101,14 +1117,18 @@ export async function applyProject(
|
|
|
1101
1117
|
);
|
|
1102
1118
|
return [pipeline.sourceDirectory, { pipelineId }];
|
|
1103
1119
|
}),
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1120
|
+
),
|
|
1121
|
+
},
|
|
1122
|
+
datasets: {
|
|
1123
|
+
...keptBindings?.datasets,
|
|
1124
|
+
...Object.fromEntries(
|
|
1125
|
+
inspection.datasets.map((dataset) => {
|
|
1126
|
+
const datasetId = datasetIds.get(dataset.name);
|
|
1127
|
+
assertCli(datasetId, `Dataset ${dataset.name} has no resolved ID.`, { hint: REPORT_HINT });
|
|
1128
|
+
return [dataset.name, { datasetId }];
|
|
1129
|
+
}),
|
|
1130
|
+
),
|
|
1131
|
+
},
|
|
1112
1132
|
};
|
|
1113
1133
|
if (valueKey(inspection.state) !== valueKey(nextState))
|
|
1114
1134
|
await writeTolokaState(options.sourceRoot, nextState);
|
package/src/cli/runs.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { TolokaState } from "../state";
|
|
|
5
5
|
import type { RunItem, RunJob } from "../index";
|
|
6
6
|
import { assertCli } from "./cli-error";
|
|
7
7
|
import { apiErrorDetails } from "./format-error";
|
|
8
|
+
import { matchesNormalizedPipelineName } from "./pipeline-selector";
|
|
8
9
|
|
|
9
10
|
export type PipelineRef = {
|
|
10
11
|
readonly pipelineId: string;
|
|
@@ -183,6 +184,14 @@ const resolveToken = (token: string, live: readonly PipelineRef[]): PipelineRef
|
|
|
183
184
|
);
|
|
184
185
|
if (basename !== undefined) return basename;
|
|
185
186
|
|
|
187
|
+
const normalized = live.filter((ref) => matchesNormalizedPipelineName(token, ref));
|
|
188
|
+
const byNormalizedName = uniqueMatch(
|
|
189
|
+
normalized,
|
|
190
|
+
`Multiple pipelines match ${token}: ${normalized.map(formatPipelineChoice).join(", ")}.`,
|
|
191
|
+
unknown,
|
|
192
|
+
);
|
|
193
|
+
if (byNormalizedName !== undefined) return byNormalizedName;
|
|
194
|
+
|
|
186
195
|
assertCli(
|
|
187
196
|
false,
|
|
188
197
|
unknown,
|