@toloka-platform/sdk 0.2.1 → 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.
- package/README.md +12 -6
- package/dist/cli/toloka.js +242 -134
- 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/docs/cli.md +73 -20
- package/docs/getting-started.md +11 -9
- package/docs/limitations.md +6 -0
- package/docs/testing-examples.md +2 -2
- package/docs/testing.md +10 -2
- package/docs/troubleshooting.md +16 -4
- package/package.json +1 -1
- package/skills/catalog.json +10 -10
- package/skills/toloka-build/SKILL.md +8 -5
- package/skills/toloka-build/references/workflow-and-cli.md +44 -22
- package/skills/toloka-fine-tuning/SKILL.md +1 -2
- package/skills/toloka-get-started/SKILL.md +4 -3
- package/skills/toloka-gisting/SKILL.md +1 -2
- package/skills/toloka-report-issue/references/report-template.md +1 -1
- package/src/cli/auth.ts +382 -81
- package/src/cli/browser-login.ts +265 -0
- package/src/cli/browser-session.ts +244 -0
- package/src/cli/commands/auth.ts +22 -15
- package/src/cli/commands/project.ts +3 -3
- package/src/cli/config.ts +41 -14
- package/src/cli/context.ts +38 -7
- package/src/cli/credentials.ts +13 -13
- package/src/cli/keycloak.ts +189 -0
- package/src/cli/program.ts +3 -0
- package/src/cli/sign-in-page.ts +153 -0
- package/src/cli/style.ts +37 -0
- package/src/cli/terminal-io.ts +9 -2
- package/src/client.ts +3 -3
- package/src/pipeline-graph-v1.contract.json +47 -24
- package/src/transport.ts +19 -11
package/src/cli/terminal-io.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import select from "@inquirer/select";
|
|
1
2
|
import { createInterface } from "node:readline/promises";
|
|
2
|
-
import type { AuthPrompt } from "./auth";
|
|
3
|
+
import type { AuthChoose, AuthPrompt } from "./auth";
|
|
3
4
|
import type { CliIo } from "./context";
|
|
4
5
|
import { pickPipeline } from "./runs";
|
|
5
6
|
import { TolokaCliError } from "./cli-error";
|
|
7
|
+
import { styleFor } from "./style";
|
|
6
8
|
|
|
7
9
|
const stdinClosedError = () =>
|
|
8
10
|
new TolokaCliError("Standard input closed before an API key was entered.", {
|
|
@@ -102,9 +104,14 @@ const promptFromTerminal: AuthPrompt = async (question, options = {}) => {
|
|
|
102
104
|
}
|
|
103
105
|
};
|
|
104
106
|
|
|
107
|
+
const chooseFromTerminal: AuthChoose = (message, choices) => select({ message, choices });
|
|
108
|
+
|
|
105
109
|
export const terminalIo = (): CliIo => ({
|
|
106
110
|
stdout: (text) => console.log(text),
|
|
107
111
|
stderr: (text) => console.error(text),
|
|
108
112
|
readStdin: readStandardInput,
|
|
109
|
-
|
|
113
|
+
style: styleFor(process.env, process.stdout.isTTY),
|
|
114
|
+
...(process.stdin.isTTY
|
|
115
|
+
? { prompt: promptFromTerminal, choose: chooseFromTerminal, select: pickPipeline }
|
|
116
|
+
: {}),
|
|
110
117
|
});
|
package/src/client.ts
CHANGED
|
@@ -70,6 +70,7 @@ import type {
|
|
|
70
70
|
} from "../openapi/gen/models";
|
|
71
71
|
import { listAllPages } from "./pagination";
|
|
72
72
|
import { createRequestOptions } from "./transport";
|
|
73
|
+
import type { ClientCredential } from "./transport";
|
|
73
74
|
import { pollUntilTerminal, type WaitForOptions } from "./wait-for";
|
|
74
75
|
|
|
75
76
|
declare const __brand: unique symbol;
|
|
@@ -196,9 +197,8 @@ export type TerminalJob<T extends { status: string }> = Omit<T, "status"> & {
|
|
|
196
197
|
|
|
197
198
|
export type ClientConfig = {
|
|
198
199
|
readonly baseUrl: string;
|
|
199
|
-
readonly apiKey: string;
|
|
200
200
|
readonly fetch?: typeof globalThis.fetch;
|
|
201
|
-
};
|
|
201
|
+
} & ClientCredential;
|
|
202
202
|
|
|
203
203
|
export type DatasetUploadWaitTarget = {
|
|
204
204
|
readonly type: "datasetUpload";
|
|
@@ -227,7 +227,7 @@ export type WaitForTarget =
|
|
|
227
227
|
| PipelineRunWaitTarget;
|
|
228
228
|
|
|
229
229
|
const createClientImplementation = (config: ClientConfig) => {
|
|
230
|
-
const requestOptions = createRequestOptions(config.baseUrl, config
|
|
230
|
+
const requestOptions = createRequestOptions(config.baseUrl, config, config.fetch);
|
|
231
231
|
|
|
232
232
|
function waitFor(
|
|
233
233
|
target: DatasetUploadWaitTarget,
|
|
@@ -614,7 +614,20 @@
|
|
|
614
614
|
"type": "string"
|
|
615
615
|
},
|
|
616
616
|
"input": {
|
|
617
|
-
"
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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),
|