@toloka-platform/sdk 0.1.0-preview.7 → 0.1.0-preview.8

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.
Files changed (37) hide show
  1. package/README.md +3 -4
  2. package/dist/cli/toloka.js +133 -130
  3. package/dist/cli/toloka.js.jsc +0 -0
  4. package/dist/cli/toloka.js.jsc.sha256 +1 -1
  5. package/dist/cli/toloka.js.sha256 +1 -1
  6. package/docs/authoring.md +3 -5
  7. package/docs/cli.md +15 -0
  8. package/docs/limitations.md +1 -1
  9. package/examples/face-image-collection/nodes/order-faces/node.ts +2 -4
  10. package/examples/video-pair-rating/nodes/adjudication_match/node.ts +15 -17
  11. package/examples/video-pair-rating/nodes/assemble/node.ts +25 -27
  12. package/examples/video-pair-rating/nodes/cascade/node.ts +24 -26
  13. package/examples/video-pair-rating/nodes/finalize_overall/node.ts +17 -19
  14. package/examples/video-pair-rating/nodes/merge_adjudication/node.ts +13 -15
  15. package/examples/video-pair-rating/nodes/merge_op_adjudication/node.ts +12 -14
  16. package/examples/video-pair-rating/nodes/op_quorum_resolve/node.ts +13 -15
  17. package/examples/video-pair-rating/nodes/route_adjudication/node.ts +1 -3
  18. package/examples/video-pair-rating/nodes/route_op_adjudication/node.ts +5 -7
  19. package/examples/video-pair-rating/nodes/route_overall/node.ts +1 -3
  20. package/examples/video-pair-rating/nodes/shuffle_ab/node.ts +11 -13
  21. package/openapi/gen/models/datasetItem.ts +0 -2
  22. package/openapi/gen/models/index.ts +0 -1
  23. package/package.json +1 -1
  24. package/skills/catalog.json +4 -4
  25. package/skills/toloka-build/SKILL.md +1 -0
  26. package/skills/toloka-build/references/node-semantics.md +5 -5
  27. package/skills/toloka-build/references/workflow-and-cli.md +6 -1
  28. package/skills/toloka-report-issue/references/report-template.md +1 -1
  29. package/src/authoring/index.ts +27 -26
  30. package/src/cli/analytics.ts +8 -19
  31. package/src/cli/auto-update.ts +367 -0
  32. package/src/cli/boolean-flag.ts +13 -0
  33. package/src/cli/credentials.ts +3 -0
  34. package/src/cli/program.ts +37 -1
  35. package/src/cli/settings.ts +93 -0
  36. package/src/importer.ts +12 -16
  37. package/openapi/gen/models/datasetItemDuplicateOfSubmissionId.ts +0 -2
@@ -0,0 +1,93 @@
1
+ import { chmod, readFile, writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { isFalseyFlag, isTruthyFlag } from "./boolean-flag";
4
+ import type { CliEnvironment } from "./credentials";
5
+ import { configDirectory, preparePrivateFilePath } from "./credentials";
6
+
7
+ export const AUTO_UPDATE_SETTING = "auto-update";
8
+
9
+ export type CliSettings = {
10
+ readonly autoUpdate: boolean;
11
+ };
12
+
13
+ export const DEFAULT_CLI_SETTINGS: CliSettings = {
14
+ autoUpdate: true,
15
+ };
16
+
17
+ export class SettingsError extends Error {
18
+ constructor(message: string, options?: { readonly cause?: unknown }) {
19
+ super(message, options);
20
+ this.name = "SettingsError";
21
+ }
22
+ }
23
+
24
+ export const settingsPath = (environment: CliEnvironment = process.env): string =>
25
+ join(configDirectory(environment), "settings.json");
26
+
27
+ const asSettings = (payload: unknown): CliSettings => {
28
+ const autoUpdate =
29
+ typeof payload === "object" && payload !== null
30
+ ? Reflect.get(payload, "autoUpdate")
31
+ : undefined;
32
+ if (typeof autoUpdate !== "boolean") return DEFAULT_CLI_SETTINGS;
33
+ return { autoUpdate };
34
+ };
35
+
36
+ export async function readCliSettings(
37
+ environment: CliEnvironment = process.env,
38
+ ): Promise<CliSettings> {
39
+ try {
40
+ return asSettings(JSON.parse(await readFile(settingsPath(environment), "utf8")));
41
+ } catch {
42
+ return DEFAULT_CLI_SETTINGS;
43
+ }
44
+ }
45
+
46
+ export async function writeCliSettings(
47
+ settings: CliSettings,
48
+ environment: CliEnvironment = process.env,
49
+ ): Promise<string> {
50
+ const path = settingsPath(environment);
51
+ await preparePrivateFilePath(path);
52
+ await writeFile(path, `${JSON.stringify({ autoUpdate: settings.autoUpdate }, null, 2)}\n`, {
53
+ mode: 0o600,
54
+ });
55
+ await chmod(path, 0o600);
56
+ return path;
57
+ }
58
+
59
+ export const parseBooleanSetting = (value: string): boolean => {
60
+ if (isTruthyFlag(value)) return true;
61
+ if (isFalseyFlag(value)) return false;
62
+ throw new SettingsError(`Expected a boolean (true or false), got ${JSON.stringify(value)}.`);
63
+ };
64
+
65
+ export const formatCliSettings = (settings: CliSettings): string =>
66
+ `${AUTO_UPDATE_SETTING}=${settings.autoUpdate}`;
67
+
68
+ export const getCliSetting = (
69
+ settings: CliSettings,
70
+ name: string | undefined,
71
+ ): { readonly output: string } => {
72
+ if (name === undefined || name.length === 0) return { output: formatCliSettings(settings) };
73
+ if (name !== AUTO_UPDATE_SETTING) {
74
+ throw new SettingsError(`Unknown setting "${name}". Known settings: ${AUTO_UPDATE_SETTING}.`);
75
+ }
76
+ return { output: String(settings.autoUpdate) };
77
+ };
78
+
79
+ export async function setCliSetting(
80
+ environment: CliEnvironment,
81
+ name: string,
82
+ value: string,
83
+ ): Promise<{ readonly output: string; readonly settings: CliSettings }> {
84
+ if (name !== AUTO_UPDATE_SETTING) {
85
+ throw new SettingsError(`Unknown setting "${name}". Known settings: ${AUTO_UPDATE_SETTING}.`);
86
+ }
87
+ const settings = { autoUpdate: parseBooleanSetting(value) };
88
+ await writeCliSettings(settings, environment);
89
+ return {
90
+ settings,
91
+ output: `Set ${AUTO_UPDATE_SETTING} to ${settings.autoUpdate}.`,
92
+ };
93
+ }
package/src/importer.ts CHANGED
@@ -220,7 +220,7 @@ function formatSource(value: unknown, depth = 0): string {
220
220
  return `{\n${properties}\n${indentation(depth)}}`;
221
221
  }
222
222
 
223
- function transformFieldProxy(
223
+ function transformFieldReference(
224
224
  reference: { id: string; optional: boolean },
225
225
  fieldReference: FieldReference,
226
226
  ): unknown {
@@ -276,10 +276,10 @@ function authoringSettings(node: GraphNode, fieldReference: FieldReference): unk
276
276
  return {
277
277
  ...settings,
278
278
  started: startedFieldProxies.output.map((reference) =>
279
- transformFieldProxy(reference, fieldReference),
279
+ transformFieldReference(reference, fieldReference),
280
280
  ),
281
281
  completed: completedFieldProxies.input.map((reference) =>
282
- transformFieldProxy(reference, fieldReference),
282
+ transformFieldReference(reference, fieldReference),
283
283
  ),
284
284
  };
285
285
  }
@@ -287,14 +287,12 @@ function authoringSettings(node: GraphNode, fieldReference: FieldReference): unk
287
287
  const { fieldProxies, ...settings } = node.settings;
288
288
  return {
289
289
  ...settings,
290
- fieldProxies: {
291
- input: fieldProxies.input.map((reference) =>
292
- transformFieldProxy(reference, fieldReference),
293
- ),
294
- output: fieldProxies.output.map((reference) =>
295
- transformFieldProxy(reference, fieldReference),
296
- ),
297
- },
290
+ input: fieldProxies.input.map((reference) =>
291
+ transformFieldReference(reference, fieldReference),
292
+ ),
293
+ output: fieldProxies.output.map((reference) =>
294
+ transformFieldReference(reference, fieldReference),
295
+ ),
298
296
  };
299
297
  }
300
298
  case "generation": {
@@ -322,11 +320,9 @@ function authoringSettings(node: GraphNode, fieldReference: FieldReference): unk
322
320
  field: fieldReference(fieldProxyId),
323
321
  })),
324
322
  })),
325
- fieldProxies: {
326
- input: fieldProxies.input.map((reference) =>
327
- transformFieldProxy(reference, fieldReference),
328
- ),
329
- },
323
+ input: fieldProxies.input.map((reference) =>
324
+ transformFieldReference(reference, fieldReference),
325
+ ),
330
326
  };
331
327
  }
332
328
  case "quorum": {
@@ -1,2 +0,0 @@
1
-
2
- export type DatasetItemDuplicateOfSubmissionId = string | null;