@toloka-platform/sdk 0.2.0 → 0.3.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.
Files changed (62) hide show
  1. package/README.md +12 -6
  2. package/dist/cli/toloka.js +269 -142
  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 +2 -0
  7. package/docs/cli.md +86 -23
  8. package/docs/getting-started.md +11 -9
  9. package/docs/limitations.md +6 -0
  10. package/docs/testing-examples.md +2 -2
  11. package/docs/testing.md +10 -2
  12. package/docs/troubleshooting.md +16 -4
  13. package/openapi/gen/api.ts +30 -0
  14. package/openapi/gen/models/gistingTrainingConfigurationGistTokens.ts +1 -1
  15. package/openapi/gen/models/gistingTrainingConfigurationInputGistTokens.ts +1 -1
  16. package/openapi/gen/models/index.ts +3 -0
  17. package/openapi/gen/models/listAudienceSpecializations200.ts +7 -0
  18. package/openapi/gen/models/listAudienceSpecializationsParams.ts +5 -0
  19. package/openapi/gen/models/specialization.ts +6 -0
  20. package/openapi/gen/models/trainingCostEstimateOneOfTwoseven.ts +0 -2
  21. package/openapi/gen/models/trainingRunQuote.ts +0 -2
  22. package/package.json +1 -1
  23. package/skills/catalog.json +10 -10
  24. package/skills/toloka-build/SKILL.md +8 -5
  25. package/skills/toloka-build/references/node-semantics.md +2 -2
  26. package/skills/toloka-build/references/workflow-and-cli.md +50 -25
  27. package/skills/toloka-fine-tuning/SKILL.md +3 -2
  28. package/skills/toloka-get-started/SKILL.md +4 -3
  29. package/skills/toloka-gisting/SKILL.md +4 -3
  30. package/skills/toloka-report-issue/references/report-template.md +1 -1
  31. package/src/checks/task-ui-typecheck.ts +4 -1
  32. package/src/cli/analytics.ts +1 -0
  33. package/src/cli/audience.ts +31 -0
  34. package/src/cli/auth.ts +382 -81
  35. package/src/cli/auto-update.ts +363 -24
  36. package/src/cli/browser-login.ts +265 -0
  37. package/src/cli/browser-session.ts +244 -0
  38. package/src/cli/check.ts +51 -52
  39. package/src/cli/cli-entry.ts +31 -0
  40. package/src/cli/commands/audience.ts +22 -0
  41. package/src/cli/commands/auth.ts +22 -15
  42. package/src/cli/commands/project.ts +3 -3
  43. package/src/cli/commands/training.ts +10 -2
  44. package/src/cli/config.ts +41 -14
  45. package/src/cli/context.ts +45 -9
  46. package/src/cli/credentials.ts +13 -13
  47. package/src/cli/init.ts +7 -2
  48. package/src/cli/keycloak.ts +189 -0
  49. package/src/cli/models.ts +1 -21
  50. package/src/cli/native-runtime.ts +7 -0
  51. package/src/cli/program.ts +5 -0
  52. package/src/cli/sign-in-page.ts +153 -0
  53. package/src/cli/skill.ts +34 -26
  54. package/src/cli/style.ts +37 -0
  55. package/src/cli/table.ts +21 -0
  56. package/src/cli/terminal-io.ts +9 -2
  57. package/src/cli/trainings.ts +1 -22
  58. package/src/cli/version.ts +12 -1
  59. package/src/client.ts +20 -3
  60. package/src/index.ts +1 -0
  61. package/src/pipeline-graph-v1.contract.json +47 -24
  62. package/src/transport.ts +19 -11
@@ -4,10 +4,13 @@ import { dirname, join, resolve, sep } from "node:path";
4
4
 
5
5
  import { SDK_VERSION } from "./sdk-version";
6
6
  import { assertCli, REPORT_HINT } from "./cli-error";
7
+ import { isNativeCli } from "./native-runtime";
7
8
 
8
- export type CliInstallChannel = "global-registry" | "linked" | "project-local";
9
+ export type CliInstallChannel = "native" | "global-registry" | "linked" | "project-local";
9
10
 
10
11
  type VersionInfoOptions = {
12
+ readonly native?: boolean;
13
+ readonly executablePath?: string;
11
14
  readonly globalBinDirectory?: string;
12
15
  readonly globalPackageDirectory?: string;
13
16
  };
@@ -36,6 +39,14 @@ const classifyInstallChannel = (
36
39
  };
37
40
 
38
41
  export const cliVersionInfo = (entryPath = process.argv[1], options: VersionInfoOptions = {}) => {
42
+ if (options.native ?? isNativeCli()) {
43
+ return {
44
+ version: SDK_VERSION,
45
+ commit: process.env.TOLOKA_BUILD_COMMIT ?? null,
46
+ channel: "native",
47
+ path: realpathOrSelf(options.executablePath ?? process.execPath),
48
+ };
49
+ }
39
50
  assertCli(entryPath, "CLI entry path is unavailable", { hint: REPORT_HINT });
40
51
  const globalBinDirectory =
41
52
  options.globalBinDirectory ??
package/src/client.ts CHANGED
@@ -33,6 +33,7 @@ import type {
33
33
  ListPipelineRunsParams,
34
34
  ListProjectDatasetsParams,
35
35
  ListProjectPipelinesParams,
36
+ ListAudienceSpecializationsParams,
36
37
  ListProjectModelsParams,
37
38
  ListProjectsParams,
38
39
  ListTrainingRunsParams,
@@ -69,6 +70,7 @@ import type {
69
70
  } from "../openapi/gen/models";
70
71
  import { listAllPages } from "./pagination";
71
72
  import { createRequestOptions } from "./transport";
73
+ import type { ClientCredential } from "./transport";
72
74
  import { pollUntilTerminal, type WaitForOptions } from "./wait-for";
73
75
 
74
76
  declare const __brand: unique symbol;
@@ -195,9 +197,8 @@ export type TerminalJob<T extends { status: string }> = Omit<T, "status"> & {
195
197
 
196
198
  export type ClientConfig = {
197
199
  readonly baseUrl: string;
198
- readonly apiKey: string;
199
200
  readonly fetch?: typeof globalThis.fetch;
200
- };
201
+ } & ClientCredential;
201
202
 
202
203
  export type DatasetUploadWaitTarget = {
203
204
  readonly type: "datasetUpload";
@@ -226,7 +227,7 @@ export type WaitForTarget =
226
227
  | PipelineRunWaitTarget;
227
228
 
228
229
  const createClientImplementation = (config: ClientConfig) => {
229
- const requestOptions = createRequestOptions(config.baseUrl, config.apiKey, config.fetch);
230
+ const requestOptions = createRequestOptions(config.baseUrl, config, config.fetch);
230
231
 
231
232
  function waitFor(
232
233
  target: DatasetUploadWaitTarget,
@@ -635,8 +636,24 @@ const createClientImplementation = (config: ClientConfig) => {
635
636
  list: async () => (await wire.listDeliveryOrders(requestOptions)).deliveryOrders,
636
637
  };
637
638
 
639
+ const audience = {
640
+ specializations: {
641
+ listPage: (params: ListAudienceSpecializationsParams = {}) =>
642
+ wire.listAudienceSpecializations(params, requestOptions),
643
+ listAll: (params: ListAudienceSpecializationsParams = {}) =>
644
+ listAllPages(async (pageOptions) => {
645
+ const page = await wire.listAudienceSpecializations(
646
+ { ...params, ...pageOptions },
647
+ requestOptions,
648
+ );
649
+ return { items: page.specializations, pagination: page.pagination };
650
+ }, params),
651
+ },
652
+ };
653
+
638
654
  return {
639
655
  me: () => wire.getCurrentUser(requestOptions),
656
+ audience,
640
657
  projects,
641
658
  pipelines,
642
659
  datasets,
package/src/index.ts CHANGED
@@ -61,6 +61,7 @@ export type {
61
61
  RootNode,
62
62
  RootNodeSettings,
63
63
  RunStats,
64
+ Specialization,
64
65
  } from "../openapi/gen/models";
65
66
  export { PipelineGraphValidationError } from "./errors";
66
67
  export type { PipelineGraphValidationIssue } from "./errors";
@@ -614,7 +614,20 @@
614
614
  "type": "string"
615
615
  },
616
616
  "input": {
617
- "type": "string"
617
+ "anyOf": [
618
+ {
619
+ "type": "string"
620
+ },
621
+ {
622
+ "type": "object",
623
+ "propertyNames": {
624
+ "type": "string"
625
+ },
626
+ "additionalProperties": {
627
+ "type": "string"
628
+ }
629
+ }
630
+ ]
618
631
  }
619
632
  },
620
633
  "required": [
@@ -623,10 +636,7 @@
623
636
  "input"
624
637
  ]
625
638
  }
626
- },
627
- "required": [
628
- "code"
629
- ]
639
+ }
630
640
  }
631
641
  },
632
642
  "required": [
@@ -2331,6 +2341,7 @@
2331
2341
  "enum": [
2332
2342
  "ui",
2333
2343
  "llmqa",
2344
+ "annotation_qa",
2334
2345
  "qc_lint",
2335
2346
  "ui_types_lint",
2336
2347
  "exam_dataset",
@@ -2349,7 +2360,20 @@
2349
2360
  "type": "string"
2350
2361
  },
2351
2362
  "input": {
2352
- "type": "string"
2363
+ "anyOf": [
2364
+ {
2365
+ "type": "string"
2366
+ },
2367
+ {
2368
+ "type": "object",
2369
+ "propertyNames": {
2370
+ "type": "string"
2371
+ },
2372
+ "additionalProperties": {
2373
+ "type": "string"
2374
+ }
2375
+ }
2376
+ ]
2353
2377
  }
2354
2378
  },
2355
2379
  "required": [
@@ -2358,15 +2382,7 @@
2358
2382
  "input"
2359
2383
  ]
2360
2384
  }
2361
- },
2362
- "required": [
2363
- "ui",
2364
- "llmqa",
2365
- "qc_lint",
2366
- "ui_types_lint",
2367
- "exam_dataset",
2368
- "synthgen"
2369
- ]
2385
+ }
2370
2386
  }
2371
2387
  },
2372
2388
  "required": [
@@ -4158,6 +4174,7 @@
4158
4174
  "enum": [
4159
4175
  "ui",
4160
4176
  "llmqa",
4177
+ "annotation_qa",
4161
4178
  "qc_lint",
4162
4179
  "ui_types_lint",
4163
4180
  "exam_dataset"
@@ -4175,7 +4192,20 @@
4175
4192
  "type": "string"
4176
4193
  },
4177
4194
  "input": {
4178
- "type": "string"
4195
+ "anyOf": [
4196
+ {
4197
+ "type": "string"
4198
+ },
4199
+ {
4200
+ "type": "object",
4201
+ "propertyNames": {
4202
+ "type": "string"
4203
+ },
4204
+ "additionalProperties": {
4205
+ "type": "string"
4206
+ }
4207
+ }
4208
+ ]
4179
4209
  }
4180
4210
  },
4181
4211
  "required": [
@@ -4184,14 +4214,7 @@
4184
4214
  "input"
4185
4215
  ]
4186
4216
  }
4187
- },
4188
- "required": [
4189
- "ui",
4190
- "llmqa",
4191
- "qc_lint",
4192
- "ui_types_lint",
4193
- "exam_dataset"
4194
- ]
4217
+ }
4195
4218
  }
4196
4219
  },
4197
4220
  "required": [
package/src/transport.ts CHANGED
@@ -3,26 +3,33 @@ import { PotatoApiError } from "./errors";
3
3
 
4
4
  const BASE_URL_HEADER = "x-potato-sdk-base-url";
5
5
 
6
+ export type ClientCredential =
7
+ | { readonly apiKey: string; readonly accessToken?: undefined }
8
+ | { readonly accessToken: () => Promise<string>; readonly apiKey?: undefined };
9
+
6
10
  type TransportRequestInit = RequestInit & {
7
11
  readonly fetch?: typeof globalThis.fetch;
12
+ readonly authorization?: () => Promise<string>;
8
13
  };
9
14
 
10
15
  export const createRequestOptions = (
11
16
  baseUrl: string,
12
- apiKey: string,
17
+ credential: ClientCredential,
13
18
  fetch?: typeof globalThis.fetch,
14
19
  ): TransportRequestInit => {
15
20
  assert(baseUrl.length > 0, "The SDK base URL cannot be empty");
16
- assert(apiKey.length > 0, "The SDK API key cannot be empty");
17
-
18
- return {
19
- headers: {
20
- Accept: "application/json",
21
- Authorization: `ApiKey ${apiKey}`,
22
- [BASE_URL_HEADER]: new URL(baseUrl).toString(),
23
- },
24
- fetch,
21
+ const headers = {
22
+ Accept: "application/json",
23
+ [BASE_URL_HEADER]: new URL(baseUrl).toString(),
25
24
  };
25
+
26
+ if (credential.accessToken !== undefined) {
27
+ const accessToken = credential.accessToken;
28
+ return { headers, fetch, authorization: async () => `Bearer ${await accessToken()}` };
29
+ }
30
+
31
+ assert(credential.apiKey.length > 0, "The SDK API key cannot be empty");
32
+ return { headers: { ...headers, Authorization: `ApiKey ${credential.apiKey}` }, fetch };
26
33
  };
27
34
 
28
35
  const prepareRequestInit = (requestOptions: RequestInit, headers: Headers): RequestInit => {
@@ -36,11 +43,12 @@ const prepareRequestInit = (requestOptions: RequestInit, headers: Headers): Requ
36
43
 
37
44
  export function potatoFetch<T>(url: string, options: TransportRequestInit): Promise<T>;
38
45
  export async function potatoFetch(url: string, options: TransportRequestInit): Promise<unknown> {
39
- const { fetch: fetchImplementation = globalThis.fetch, ...requestOptions } = options;
46
+ const { fetch: fetchImplementation = globalThis.fetch, authorization, ...requestOptions } = options;
40
47
  const headers = new Headers(requestOptions.headers);
41
48
  const baseUrl = headers.get(BASE_URL_HEADER);
42
49
  assert(baseUrl, "The SDK base URL is missing");
43
50
  headers.delete(BASE_URL_HEADER);
51
+ if (authorization !== undefined) headers.set("Authorization", await authorization());
44
52
 
45
53
  const response = await fetchImplementation(
46
54
  new URL(url, baseUrl),