@toloka-platform/sdk 0.19.1 → 0.21.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 +160 -158
- 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 +837 -3441
- package/openapi/gen/api.ts +354 -0
- package/package.json +5 -5
- package/skills/catalog.json +6 -6
- package/skills/toloka-build/references/human-work.md +11 -0
- package/src/cli/commands/expert-ban-list.ts +69 -0
- package/src/cli/commands/expert-list.ts +124 -0
- package/src/cli/experts.ts +293 -0
- package/src/cli/program.ts +4 -0
- package/src/cli/project.ts +30 -1
- package/src/client.ts +52 -2
- package/src/pipeline-graph-v1.contract.json +106 -186
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import { positiveInteger, resolveContext, type CommandHost } from "../context";
|
|
3
|
+
import {
|
|
4
|
+
createExpertList,
|
|
5
|
+
addExpertListExperts,
|
|
6
|
+
listExpertListExperts,
|
|
7
|
+
listExpertLists,
|
|
8
|
+
readExpertIds,
|
|
9
|
+
removeExpertListExperts,
|
|
10
|
+
resolveExpertListId,
|
|
11
|
+
showExpertList,
|
|
12
|
+
updateExpertList,
|
|
13
|
+
} from "../experts";
|
|
14
|
+
import { assertProjectSelected } from "../project-context";
|
|
15
|
+
|
|
16
|
+
export const registerExpertListCommands = (program: Command, host: CommandHost): void => {
|
|
17
|
+
const { context, globals } = host;
|
|
18
|
+
|
|
19
|
+
const resolveList = async (list: string) => {
|
|
20
|
+
const { client, projectId } = await resolveContext(globals(), context);
|
|
21
|
+
assertProjectSelected(projectId);
|
|
22
|
+
|
|
23
|
+
return { client, projectId, expertListId: await resolveExpertListId(client, { projectId, list }) };
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const expertList = program
|
|
27
|
+
.command("expert-list")
|
|
28
|
+
.description("manage the project's expert lists, which nodes with audienceMode service take experts from");
|
|
29
|
+
|
|
30
|
+
expertList
|
|
31
|
+
.command("list")
|
|
32
|
+
.option("--json", "print JSON", false)
|
|
33
|
+
.description("list the project's expert lists")
|
|
34
|
+
.action(async (options: { json: boolean }) => {
|
|
35
|
+
const { client, projectId } = await resolveContext(globals(), context);
|
|
36
|
+
assertProjectSelected(projectId);
|
|
37
|
+
await listExpertLists(client, { projectId, json: options.json }, context.io);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
expertList
|
|
41
|
+
.command("create")
|
|
42
|
+
.argument("<name>", "name of the new list")
|
|
43
|
+
.option("--json", "print JSON", false)
|
|
44
|
+
.description("create an empty expert list")
|
|
45
|
+
.action(async (name: string, options: { json: boolean }) => {
|
|
46
|
+
const { client, projectId } = await resolveContext(globals(), context);
|
|
47
|
+
assertProjectSelected(projectId);
|
|
48
|
+
await createExpertList(client, { projectId, name, json: options.json }, context.io);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
expertList
|
|
52
|
+
.command("show")
|
|
53
|
+
.argument("<list>", "list id (exl.…) or name")
|
|
54
|
+
.option("--json", "print JSON", false)
|
|
55
|
+
.description("show a list and how many of its experts are available")
|
|
56
|
+
.action(async (list: string, options: { json: boolean }) => {
|
|
57
|
+
const { client, expertListId } = await resolveList(list);
|
|
58
|
+
await showExpertList(client, { expertListId, json: options.json }, context.io);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
expertList
|
|
62
|
+
.command("rename")
|
|
63
|
+
.argument("<list>", "list id (exl.…) or name")
|
|
64
|
+
.argument("<name>", "new name")
|
|
65
|
+
.description("rename a list")
|
|
66
|
+
.action(async (list: string, name: string) => {
|
|
67
|
+
const { client, expertListId } = await resolveList(list);
|
|
68
|
+
await updateExpertList(client, { expertListId, name }, context.io);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
expertList
|
|
72
|
+
.command("hide")
|
|
73
|
+
.argument("<list>", "list id (exl.…) or name")
|
|
74
|
+
.description("hide a list: its experts can't be added or removed until it is shown again; nodes that use it keep working")
|
|
75
|
+
.action(async (list: string) => {
|
|
76
|
+
const { client, expertListId } = await resolveList(list);
|
|
77
|
+
await updateExpertList(client, { expertListId, hidden: true }, context.io);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
expertList
|
|
81
|
+
.command("unhide")
|
|
82
|
+
.argument("<list>", "list id (exl.…) or name")
|
|
83
|
+
.description("show a hidden list again")
|
|
84
|
+
.action(async (list: string) => {
|
|
85
|
+
const { client, expertListId } = await resolveList(list);
|
|
86
|
+
await updateExpertList(client, { expertListId, hidden: false }, context.io);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
expertList
|
|
90
|
+
.command("experts")
|
|
91
|
+
.argument("<list>", "list id (exl.…) or name")
|
|
92
|
+
.option("--after <expertId>", "start after this expert id, from the previous page")
|
|
93
|
+
.option("--limit <count>", "experts per page, up to 1000", positiveInteger)
|
|
94
|
+
.option("--json", "print JSON", false)
|
|
95
|
+
.description("list a page of the list's experts with their status")
|
|
96
|
+
.action(async (list: string, options: { after?: string; limit?: number; json: boolean }) => {
|
|
97
|
+
const { client, expertListId } = await resolveList(list);
|
|
98
|
+
await listExpertListExperts(client, { expertListId, ...options }, context.io);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
expertList
|
|
102
|
+
.command("add")
|
|
103
|
+
.argument("<list>", "list id (exl.…) or name")
|
|
104
|
+
.argument("[expertIds...]", "expert ids to add")
|
|
105
|
+
.option("--file <path>", "file with one expert id per line")
|
|
106
|
+
.description("add experts to a list, from arguments or a file")
|
|
107
|
+
.action(async (list: string, expertIds: string[], options: { file?: string }) => {
|
|
108
|
+
const { client, expertListId } = await resolveList(list);
|
|
109
|
+
const ids = await readExpertIds({ expertIds, ...(options.file === undefined ? {} : { file: options.file }) });
|
|
110
|
+
await addExpertListExperts(client, { expertListId, expertIds: ids }, context.io);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
expertList
|
|
114
|
+
.command("remove")
|
|
115
|
+
.argument("<list>", "list id (exl.…) or name")
|
|
116
|
+
.argument("[expertIds...]", "expert ids to remove")
|
|
117
|
+
.option("--file <path>", "file with one expert id per line")
|
|
118
|
+
.description("remove experts from a list")
|
|
119
|
+
.action(async (list: string, expertIds: string[], options: { file?: string }) => {
|
|
120
|
+
const { client, expertListId } = await resolveList(list);
|
|
121
|
+
const ids = await readExpertIds({ expertIds, ...(options.file === undefined ? {} : { file: options.file }) });
|
|
122
|
+
await removeExpertListExperts(client, { expertListId, expertIds: ids }, context.io);
|
|
123
|
+
});
|
|
124
|
+
};
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import type { PotatoClient } from "../client";
|
|
3
|
+
import { PotatoApiError } from "../errors";
|
|
4
|
+
import { TolokaCliError } from "./cli-error";
|
|
5
|
+
import { formatTable, type TableIo, writeOutput } from "./table";
|
|
6
|
+
|
|
7
|
+
type ExpertListApi = Pick<PotatoClient, "expertLists">;
|
|
8
|
+
type ExpertBanListApi = Pick<PotatoClient, "expertBanList">;
|
|
9
|
+
|
|
10
|
+
const MAX_EXPERT_IDS_PER_REQUEST = 10_000;
|
|
11
|
+
|
|
12
|
+
const experts = (count: number) => `${count} expert${count === 1 ? "" : "s"}`;
|
|
13
|
+
|
|
14
|
+
const notAvailable = (error: unknown, feature: string): never => {
|
|
15
|
+
if (error instanceof PotatoApiError && error.status === 404) {
|
|
16
|
+
const reason = typeof error.body === "string" && error.body.length > 0 ? error.body : "Not found";
|
|
17
|
+
throw new TolokaCliError(`${feature}: ${reason}.`, {
|
|
18
|
+
cause: error,
|
|
19
|
+
hint: {
|
|
20
|
+
description:
|
|
21
|
+
"Check the id or name you passed and the selected project (toloka status). If both are right, this feature is not enabled for the team.",
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
throw error;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const explainingNotFound = async <Result>(feature: string, call: () => Promise<Result>): Promise<Result> => {
|
|
29
|
+
try {
|
|
30
|
+
return await call();
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return notAvailable(error, feature);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const listExpertListsOrExplain = (client: ExpertListApi, projectId: string) =>
|
|
37
|
+
explainingNotFound("Expert lists", () => client.expertLists.list({ projectId }));
|
|
38
|
+
|
|
39
|
+
export const resolveExpertListId = async (
|
|
40
|
+
client: ExpertListApi,
|
|
41
|
+
input: { projectId: string; list: string },
|
|
42
|
+
): Promise<string> => {
|
|
43
|
+
if (input.list.startsWith("exl.")) return input.list;
|
|
44
|
+
|
|
45
|
+
const [match, ...others] = (await listExpertListsOrExplain(client, input.projectId)).filter(
|
|
46
|
+
(expertList) => expertList.name === input.list,
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
if (match === undefined || others.length > 0) {
|
|
50
|
+
throw new TolokaCliError(
|
|
51
|
+
match === undefined
|
|
52
|
+
? `No expert list named "${input.list}" in this project.`
|
|
53
|
+
: `Several expert lists are named "${input.list}"; pass the list id (exl.…) instead.`,
|
|
54
|
+
{ hint: { description: "Run toloka expert-list list to see the lists and their ids." } },
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return match.id;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const readExpertIds = async (input: {
|
|
62
|
+
expertIds: readonly string[];
|
|
63
|
+
file?: string;
|
|
64
|
+
}): Promise<string[]> => {
|
|
65
|
+
const fromFile = input.file === undefined ? [] : (await readFile(input.file, "utf8")).split(/\r?\n/u);
|
|
66
|
+
const expertIds = [
|
|
67
|
+
...new Set([...fromFile, ...input.expertIds].map((id) => id.trim()).filter((id) => id.length > 0)),
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
if (expertIds.length === 0) {
|
|
71
|
+
throw new TolokaCliError("No expert IDs given.", {
|
|
72
|
+
hint: { description: "Pass expert IDs as arguments or a file with one ID per line with --file." },
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (expertIds.length > MAX_EXPERT_IDS_PER_REQUEST) {
|
|
77
|
+
throw new TolokaCliError(`Too many expert IDs: ${expertIds.length}, at most ${MAX_EXPERT_IDS_PER_REQUEST}.`, {
|
|
78
|
+
hint: { description: "Split the file and run the command once per part." },
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return expertIds;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const listExpertLists = async (
|
|
86
|
+
client: ExpertListApi,
|
|
87
|
+
input: { projectId: string; json: boolean },
|
|
88
|
+
io: TableIo,
|
|
89
|
+
): Promise<void> => {
|
|
90
|
+
const expertLists = await listExpertListsOrExplain(client, input.projectId);
|
|
91
|
+
|
|
92
|
+
writeOutput(
|
|
93
|
+
io,
|
|
94
|
+
input.json,
|
|
95
|
+
expertLists,
|
|
96
|
+
expertLists.length === 0
|
|
97
|
+
? "No expert lists in this project."
|
|
98
|
+
: formatTable([
|
|
99
|
+
["ID", "NAME", "EXPERTS", "HIDDEN"],
|
|
100
|
+
...expertLists.map((expertList) => [
|
|
101
|
+
expertList.id,
|
|
102
|
+
expertList.name,
|
|
103
|
+
String(expertList.expertCount),
|
|
104
|
+
expertList.hidden ? "yes" : "no",
|
|
105
|
+
]),
|
|
106
|
+
]),
|
|
107
|
+
);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export const createExpertList = async (
|
|
111
|
+
client: ExpertListApi,
|
|
112
|
+
input: { projectId: string; name: string; json: boolean },
|
|
113
|
+
io: TableIo,
|
|
114
|
+
): Promise<void> => {
|
|
115
|
+
const expertList = await explainingNotFound("Expert lists", () =>
|
|
116
|
+
client.expertLists.create({ projectId: input.projectId, name: input.name }),
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
writeOutput(io, input.json, expertList, `Created expert list ${expertList.id} "${expertList.name}".`);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export const showExpertList = async (
|
|
123
|
+
client: ExpertListApi,
|
|
124
|
+
input: { expertListId: string; json: boolean },
|
|
125
|
+
io: TableIo,
|
|
126
|
+
): Promise<void> => {
|
|
127
|
+
const expertList = await explainingNotFound("Expert lists", () => client.expertLists.get({ expertListId: input.expertListId }));
|
|
128
|
+
const { stats } = expertList;
|
|
129
|
+
|
|
130
|
+
writeOutput(
|
|
131
|
+
io,
|
|
132
|
+
input.json,
|
|
133
|
+
expertList,
|
|
134
|
+
formatTable([
|
|
135
|
+
["ID", expertList.id],
|
|
136
|
+
["NAME", expertList.name],
|
|
137
|
+
["HIDDEN", expertList.hidden ? "yes" : "no"],
|
|
138
|
+
["EXPERTS", String(expertList.expertCount)],
|
|
139
|
+
["AVAILABLE", String(stats.available)],
|
|
140
|
+
["PENDING", String(stats.pending)],
|
|
141
|
+
["UNAVAILABLE", String(stats.unavailable)],
|
|
142
|
+
["NOT FOUND", String(stats.notFound)],
|
|
143
|
+
["BANNED", String(stats.banned)],
|
|
144
|
+
]),
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export const updateExpertList = async (
|
|
149
|
+
client: ExpertListApi,
|
|
150
|
+
input: { expertListId: string; name?: string; hidden?: boolean },
|
|
151
|
+
io: TableIo,
|
|
152
|
+
): Promise<void> => {
|
|
153
|
+
const { expertListId, ...body } = input;
|
|
154
|
+
const expertList = await explainingNotFound("Expert lists", () => client.expertLists.update({ expertListId, ...body }));
|
|
155
|
+
|
|
156
|
+
io.stdout(`Updated expert list ${expertList.id} "${expertList.name}"${expertList.hidden ? " (hidden)" : ""}.`);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export const addExpertListExperts = async (
|
|
160
|
+
client: ExpertListApi,
|
|
161
|
+
input: { expertListId: string; expertIds: string[] },
|
|
162
|
+
io: TableIo,
|
|
163
|
+
): Promise<void> => {
|
|
164
|
+
const result = await explainingNotFound("Expert lists", () => client.expertLists.addExperts({
|
|
165
|
+
expertListId: input.expertListId,
|
|
166
|
+
expertIds: input.expertIds,
|
|
167
|
+
}));
|
|
168
|
+
|
|
169
|
+
io.stdout(
|
|
170
|
+
`Added ${experts(result.changedCount)}; experts already in the list were skipped. ` +
|
|
171
|
+
"Availability is checked in the background: run toloka expert-list show to see it.",
|
|
172
|
+
);
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export const removeExpertListExperts = async (
|
|
176
|
+
client: ExpertListApi,
|
|
177
|
+
input: { expertListId: string; expertIds: string[] },
|
|
178
|
+
io: TableIo,
|
|
179
|
+
): Promise<void> => {
|
|
180
|
+
const result = await explainingNotFound("Expert lists", () => client.expertLists.removeExperts({
|
|
181
|
+
expertListId: input.expertListId,
|
|
182
|
+
expertIds: input.expertIds,
|
|
183
|
+
}));
|
|
184
|
+
|
|
185
|
+
io.stdout(`Removed ${experts(result.changedCount)}; experts not in the list were skipped.`);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
export const listExpertListExperts = async (
|
|
189
|
+
client: ExpertListApi,
|
|
190
|
+
input: { expertListId: string; after?: string; limit?: number; json: boolean },
|
|
191
|
+
io: TableIo,
|
|
192
|
+
): Promise<void> => {
|
|
193
|
+
const page = await explainingNotFound("Expert lists", () => client.expertLists.listExpertsPage({
|
|
194
|
+
expertListId: input.expertListId,
|
|
195
|
+
...(input.after === undefined ? {} : { after: input.after }),
|
|
196
|
+
...(input.limit === undefined ? {} : { limit: input.limit }),
|
|
197
|
+
}));
|
|
198
|
+
|
|
199
|
+
writeOutput(
|
|
200
|
+
io,
|
|
201
|
+
input.json,
|
|
202
|
+
page,
|
|
203
|
+
[
|
|
204
|
+
page.experts.length === 0
|
|
205
|
+
? "No experts."
|
|
206
|
+
: formatTable([["EXPERT", "STATUS"], ...page.experts.map((expert) => [expert.expertId, expert.status])]),
|
|
207
|
+
...(page.nextAfter === null ? [] : [`More experts: pass --after ${page.nextAfter}`]),
|
|
208
|
+
].join("\n"),
|
|
209
|
+
);
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
export const showExpertBanList = async (
|
|
213
|
+
client: ExpertBanListApi,
|
|
214
|
+
input: { projectId: string; json: boolean },
|
|
215
|
+
io: TableIo,
|
|
216
|
+
): Promise<void> => {
|
|
217
|
+
const banList = await explainingNotFound("Banned experts", () =>
|
|
218
|
+
client.expertBanList.get({ projectId: input.projectId }),
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
writeOutput(
|
|
222
|
+
io,
|
|
223
|
+
input.json,
|
|
224
|
+
banList,
|
|
225
|
+
formatTable([
|
|
226
|
+
["EXPERTS", String(banList.expertCount)],
|
|
227
|
+
["BANNED", String(banList.stats.banned)],
|
|
228
|
+
["PENDING", String(banList.stats.pending)],
|
|
229
|
+
["UNBANNING", String(banList.stats.unbanning)],
|
|
230
|
+
["NOT FOUND", String(banList.stats.notFound)],
|
|
231
|
+
]),
|
|
232
|
+
);
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
export const listExpertBanListExperts = async (
|
|
236
|
+
client: ExpertBanListApi,
|
|
237
|
+
input: { projectId: string; after?: string; limit?: number; json: boolean },
|
|
238
|
+
io: TableIo,
|
|
239
|
+
): Promise<void> => {
|
|
240
|
+
const page = await explainingNotFound("Banned experts", () =>
|
|
241
|
+
client.expertBanList.listExpertsPage({
|
|
242
|
+
projectId: input.projectId,
|
|
243
|
+
...(input.after === undefined ? {} : { after: input.after }),
|
|
244
|
+
...(input.limit === undefined ? {} : { limit: input.limit }),
|
|
245
|
+
}),
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
writeOutput(
|
|
249
|
+
io,
|
|
250
|
+
input.json,
|
|
251
|
+
page,
|
|
252
|
+
[
|
|
253
|
+
page.experts.length === 0
|
|
254
|
+
? "No banned experts."
|
|
255
|
+
: formatTable([
|
|
256
|
+
["EXPERT", "STATUS", "REASON"],
|
|
257
|
+
...page.experts.map((expert) => [expert.expertId, expert.status, expert.reason]),
|
|
258
|
+
]),
|
|
259
|
+
...(page.nextAfter === null ? [] : [`More experts: pass --after ${page.nextAfter}`]),
|
|
260
|
+
].join("\n"),
|
|
261
|
+
);
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
export const addExpertBanListExperts = async (
|
|
265
|
+
client: ExpertBanListApi,
|
|
266
|
+
input: { projectId: string; expertIds: string[]; reason: string },
|
|
267
|
+
io: TableIo,
|
|
268
|
+
): Promise<void> => {
|
|
269
|
+
const result = await explainingNotFound("Banned experts", () =>
|
|
270
|
+
client.expertBanList.addExperts({
|
|
271
|
+
projectId: input.projectId,
|
|
272
|
+
expertIds: input.expertIds,
|
|
273
|
+
reason: input.reason,
|
|
274
|
+
}),
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
io.stdout(`Banned ${experts(result.changedCount)}.`);
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
export const removeExpertBanListExperts = async (
|
|
281
|
+
client: ExpertBanListApi,
|
|
282
|
+
input: { projectId: string; expertIds: string[] },
|
|
283
|
+
io: TableIo,
|
|
284
|
+
): Promise<void> => {
|
|
285
|
+
const result = await explainingNotFound("Banned experts", () =>
|
|
286
|
+
client.expertBanList.removeExperts({
|
|
287
|
+
projectId: input.projectId,
|
|
288
|
+
expertIds: input.expertIds,
|
|
289
|
+
}),
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
io.stdout(`Unbanned ${experts(result.changedCount)}; experts that were not banned were skipped.`);
|
|
293
|
+
};
|
package/src/cli/program.ts
CHANGED
|
@@ -17,6 +17,8 @@ import { registerModelCommands } from "./commands/models";
|
|
|
17
17
|
import { registerPipelineCommands } from "./commands/pipeline";
|
|
18
18
|
import { registerProjectCommands } from "./commands/project";
|
|
19
19
|
import { registerReportCommand } from "./commands/report";
|
|
20
|
+
import { registerExpertBanListCommands } from "./commands/expert-ban-list";
|
|
21
|
+
import { registerExpertListCommands } from "./commands/expert-list";
|
|
20
22
|
import { registerSecretCommands } from "./commands/secret";
|
|
21
23
|
import { registerSkillCommands } from "./commands/skill";
|
|
22
24
|
import { registerSourceCommands } from "./commands/source";
|
|
@@ -101,6 +103,8 @@ export function createProgram(context: ProgramContext): CreatedProgram {
|
|
|
101
103
|
registerGenerationModelCommands(program, host);
|
|
102
104
|
registerSourceCommands(program, host);
|
|
103
105
|
registerSecretCommands(program, host);
|
|
106
|
+
registerExpertListCommands(program, host);
|
|
107
|
+
registerExpertBanListCommands(program, host);
|
|
104
108
|
registerModelCommands(program, host);
|
|
105
109
|
registerTrainingCommands(program, host);
|
|
106
110
|
registerBatchInferenceCommands(program, host);
|
package/src/cli/project.ts
CHANGED
|
@@ -167,6 +167,31 @@ const projectAuthoredKeys = (authored: unknown, live: unknown): unknown => {
|
|
|
167
167
|
const matchesAuthored = (authored: unknown, live: unknown) =>
|
|
168
168
|
valueKey(authored) === valueKey(projectAuthoredKeys(authored, live));
|
|
169
169
|
|
|
170
|
+
const isHumanQa = (qualityAssurance: unknown): qualityAssurance is Record<string, unknown> =>
|
|
171
|
+
isPlainObject(qualityAssurance) &&
|
|
172
|
+
(qualityAssurance.qaMode === "human_only" || qualityAssurance.qaMode === "hybrid");
|
|
173
|
+
|
|
174
|
+
const withAudienceSourcingDefaults = (node: PipelineGraphV1["nodes"][number]): unknown => {
|
|
175
|
+
if (node.type !== "generation" && node.type !== "quorum") return node;
|
|
176
|
+
|
|
177
|
+
const audienceAndPricing: unknown = node.settings.audienceAndPricing;
|
|
178
|
+
const qualityAssurance: unknown = node.type === "generation" ? node.settings.qualityAssurance : undefined;
|
|
179
|
+
|
|
180
|
+
return {
|
|
181
|
+
...node,
|
|
182
|
+
settings: {
|
|
183
|
+
audienceMode: "legacy",
|
|
184
|
+
...node.settings,
|
|
185
|
+
...(isPlainObject(audienceAndPricing) && audienceAndPricing.audienceType === "human"
|
|
186
|
+
? { audienceAndPricing: { expertListId: null, ...audienceAndPricing } }
|
|
187
|
+
: {}),
|
|
188
|
+
...(isHumanQa(qualityAssurance)
|
|
189
|
+
? { qualityAssurance: { expertListId: null, ...qualityAssurance } }
|
|
190
|
+
: {}),
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
|
|
170
195
|
const collectAsync = async <Value>(values: AsyncIterable<Value>): Promise<Value[]> => {
|
|
171
196
|
const collected: Value[] = [];
|
|
172
197
|
for await (const value of values) collected.push(value);
|
|
@@ -243,7 +268,11 @@ export function diffPipelineGraphs(
|
|
|
243
268
|
id: field.id,
|
|
244
269
|
}),
|
|
245
270
|
),
|
|
246
|
-
...diffKeyed(
|
|
271
|
+
...diffKeyed(
|
|
272
|
+
authoredNodes,
|
|
273
|
+
liveNodes,
|
|
274
|
+
(authored, live) => matchesAuthored(authored, withAudienceSourcingDefaults(live)),
|
|
275
|
+
(node, action) => ({
|
|
247
276
|
kind: "node",
|
|
248
277
|
action,
|
|
249
278
|
label: nodeLabel(node),
|
package/src/client.ts
CHANGED
|
@@ -3,6 +3,14 @@ import { assert } from "es-toolkit";
|
|
|
3
3
|
import * as wire from "../openapi/gen/api";
|
|
4
4
|
import type {
|
|
5
5
|
AddDatasetItemsBody,
|
|
6
|
+
AddExpertBanListExpertsBody,
|
|
7
|
+
CreateExpertListBody,
|
|
8
|
+
AddExpertListExpertsBody,
|
|
9
|
+
ListExpertBanListExpertsParams,
|
|
10
|
+
ListExpertListExpertsParams,
|
|
11
|
+
RemoveExpertListExpertsBody,
|
|
12
|
+
RemoveExpertBanListExpertsBody,
|
|
13
|
+
UpdateExpertListBody,
|
|
6
14
|
AttachPipelineDatasetBody,
|
|
7
15
|
BatchInferenceRun as GeneratedBatchInferenceRun,
|
|
8
16
|
CancelPipelineRunBody,
|
|
@@ -76,6 +84,7 @@ import type {
|
|
|
76
84
|
BaseModelId as GeneratedBaseModelId,
|
|
77
85
|
UpdatePipelineBody,
|
|
78
86
|
UpdateProjectBody,
|
|
87
|
+
JsonValue as GeneratedJsonValue,
|
|
79
88
|
UploadJob as GeneratedUploadJob,
|
|
80
89
|
ValidatePipelineGraphBody,
|
|
81
90
|
} from "../openapi/gen/api.schemas";
|
|
@@ -159,7 +168,11 @@ type BrandedResource<T extends { id: string }, Id extends string> = Omit<
|
|
|
159
168
|
id: Id;
|
|
160
169
|
};
|
|
161
170
|
|
|
162
|
-
type
|
|
171
|
+
type IsJsonValue<T> = [T] extends [GeneratedJsonValue] ? ([GeneratedJsonValue] extends [T] ? true : false) : false;
|
|
172
|
+
|
|
173
|
+
type PublicInput<T> = IsJsonValue<T> extends true
|
|
174
|
+
? T
|
|
175
|
+
: T extends readonly unknown[]
|
|
163
176
|
? { [K in keyof T]: PublicInput<T[K]> }
|
|
164
177
|
: T extends object
|
|
165
178
|
? {
|
|
@@ -796,6 +809,39 @@ const createClientImplementation = (config: ClientConfig) => {
|
|
|
796
809
|
wire.runPipelineLints(pipelineId, requestOptions),
|
|
797
810
|
};
|
|
798
811
|
|
|
812
|
+
const expertLists = {
|
|
813
|
+
list: async ({ projectId }: { projectId: ProjectId }) =>
|
|
814
|
+
(await wire.listExpertLists(projectId, requestOptions)).expertLists,
|
|
815
|
+
create: ({ projectId, ...body }: { projectId: ProjectId } & CreateExpertListBody) =>
|
|
816
|
+
wire.createExpertList(projectId, body, requestOptions),
|
|
817
|
+
get: ({ expertListId }: { expertListId: string }) =>
|
|
818
|
+
wire.getExpertList(expertListId, requestOptions),
|
|
819
|
+
update: ({ expertListId, ...body }: { expertListId: string } & UpdateExpertListBody) =>
|
|
820
|
+
wire.updateExpertList(expertListId, body, requestOptions),
|
|
821
|
+
listExpertsPage: ({
|
|
822
|
+
expertListId,
|
|
823
|
+
...params
|
|
824
|
+
}: { expertListId: string } & ListExpertListExpertsParams) =>
|
|
825
|
+
wire.listExpertListExperts(expertListId, params, requestOptions),
|
|
826
|
+
addExperts: ({ expertListId, ...body }: { expertListId: string } & AddExpertListExpertsBody) =>
|
|
827
|
+
wire.addExpertListExperts(expertListId, body, requestOptions),
|
|
828
|
+
removeExperts: ({
|
|
829
|
+
expertListId,
|
|
830
|
+
...body
|
|
831
|
+
}: { expertListId: string } & RemoveExpertListExpertsBody) =>
|
|
832
|
+
wire.removeExpertListExperts(expertListId, body, requestOptions),
|
|
833
|
+
};
|
|
834
|
+
|
|
835
|
+
const expertBanList = {
|
|
836
|
+
get: ({ projectId }: { projectId: ProjectId }) => wire.getExpertBanList(projectId, requestOptions),
|
|
837
|
+
listExpertsPage: ({ projectId, ...params }: { projectId: ProjectId } & ListExpertBanListExpertsParams) =>
|
|
838
|
+
wire.listExpertBanListExperts(projectId, params, requestOptions),
|
|
839
|
+
addExperts: ({ projectId, ...body }: { projectId: ProjectId } & AddExpertBanListExpertsBody) =>
|
|
840
|
+
wire.addExpertBanListExperts(projectId, body, requestOptions),
|
|
841
|
+
removeExperts: ({ projectId, ...body }: { projectId: ProjectId } & RemoveExpertBanListExpertsBody) =>
|
|
842
|
+
wire.removeExpertBanListExperts(projectId, body, requestOptions),
|
|
843
|
+
};
|
|
844
|
+
|
|
799
845
|
const deliveryOrders = {
|
|
800
846
|
list: async () => (await wire.listDeliveryOrders(requestOptions)).deliveryOrders,
|
|
801
847
|
};
|
|
@@ -835,11 +881,15 @@ const createClientImplementation = (config: ClientConfig) => {
|
|
|
835
881
|
files,
|
|
836
882
|
checks,
|
|
837
883
|
deliveryOrders,
|
|
884
|
+
expertLists,
|
|
885
|
+
expertBanList,
|
|
838
886
|
waitFor,
|
|
839
887
|
};
|
|
840
888
|
};
|
|
841
889
|
|
|
842
|
-
type PublicOutput<T> = T extends
|
|
890
|
+
type PublicOutput<T> = IsJsonValue<T> extends true
|
|
891
|
+
? T
|
|
892
|
+
: T extends GeneratedCheckJob
|
|
843
893
|
? CheckJob
|
|
844
894
|
: T extends GeneratedRunJob
|
|
845
895
|
? RunJob
|