@toloka-platform/sdk 0.19.0 → 0.20.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.
@@ -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
+ };
@@ -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";
@@ -55,10 +57,10 @@ export function createProgram(context: ProgramContext): CreatedProgram {
55
57
  .version(SDK_VERSION, "-v, --version", "output the current version")
56
58
  .option(
57
59
  "--source-root <directory>",
58
- "project root; discovered from the working directory when omitted",
60
+ "project root; otherwise search the working directory and parents; init and report use only the working directory",
59
61
  )
60
- .option("--api-key <key>", "API key for this command only")
61
- .option("--base-url <url>", "platform base URL for this command only")
62
+ .option("--api-key <key>", "API key override; login stores the key it verifies")
63
+ .option("--base-url <url>", "platform base URL override; login saves the selected URL")
62
64
  .option("--project-id <id>", "target project; overrides toloka.json")
63
65
  .addHelpText("after", `\n${CREDENTIAL_PRECEDENCE}`)
64
66
  .configureOutput({
@@ -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);
@@ -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(authoredNodes, liveNodes, matchesAuthored, (node, action) => ({
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,
@@ -796,6 +804,39 @@ const createClientImplementation = (config: ClientConfig) => {
796
804
  wire.runPipelineLints(pipelineId, requestOptions),
797
805
  };
798
806
 
807
+ const expertLists = {
808
+ list: async ({ projectId }: { projectId: ProjectId }) =>
809
+ (await wire.listExpertLists(projectId, requestOptions)).expertLists,
810
+ create: ({ projectId, ...body }: { projectId: ProjectId } & CreateExpertListBody) =>
811
+ wire.createExpertList(projectId, body, requestOptions),
812
+ get: ({ expertListId }: { expertListId: string }) =>
813
+ wire.getExpertList(expertListId, requestOptions),
814
+ update: ({ expertListId, ...body }: { expertListId: string } & UpdateExpertListBody) =>
815
+ wire.updateExpertList(expertListId, body, requestOptions),
816
+ listExpertsPage: ({
817
+ expertListId,
818
+ ...params
819
+ }: { expertListId: string } & ListExpertListExpertsParams) =>
820
+ wire.listExpertListExperts(expertListId, params, requestOptions),
821
+ addExperts: ({ expertListId, ...body }: { expertListId: string } & AddExpertListExpertsBody) =>
822
+ wire.addExpertListExperts(expertListId, body, requestOptions),
823
+ removeExperts: ({
824
+ expertListId,
825
+ ...body
826
+ }: { expertListId: string } & RemoveExpertListExpertsBody) =>
827
+ wire.removeExpertListExperts(expertListId, body, requestOptions),
828
+ };
829
+
830
+ const expertBanList = {
831
+ get: ({ projectId }: { projectId: ProjectId }) => wire.getExpertBanList(projectId, requestOptions),
832
+ listExpertsPage: ({ projectId, ...params }: { projectId: ProjectId } & ListExpertBanListExpertsParams) =>
833
+ wire.listExpertBanListExperts(projectId, params, requestOptions),
834
+ addExperts: ({ projectId, ...body }: { projectId: ProjectId } & AddExpertBanListExpertsBody) =>
835
+ wire.addExpertBanListExperts(projectId, body, requestOptions),
836
+ removeExperts: ({ projectId, ...body }: { projectId: ProjectId } & RemoveExpertBanListExpertsBody) =>
837
+ wire.removeExpertBanListExperts(projectId, body, requestOptions),
838
+ };
839
+
799
840
  const deliveryOrders = {
800
841
  list: async () => (await wire.listDeliveryOrders(requestOptions)).deliveryOrders,
801
842
  };
@@ -835,6 +876,8 @@ const createClientImplementation = (config: ClientConfig) => {
835
876
  files,
836
877
  checks,
837
878
  deliveryOrders,
879
+ expertLists,
880
+ expertBanList,
838
881
  waitFor,
839
882
  };
840
883
  };
@@ -1428,10 +1428,6 @@
1428
1428
  ]
1429
1429
  },
1430
1430
  "qualityAssurance": {
1431
- "default": {
1432
- "qaMode": "llm_only",
1433
- "llmQaModelId": "gpt-5.6-terra"
1434
- },
1435
1431
  "oneOf": [
1436
1432
  {
1437
1433
  "type": "object",
@@ -1474,6 +1470,18 @@
1474
1470
  "humanQaTimeForTask": {
1475
1471
  "type": "number",
1476
1472
  "exclusiveMinimum": 0
1473
+ },
1474
+ "expertListId": {
1475
+ "description": "Expert list the experts come from, with prefix `exl.`. Requires `audienceMode: service`. `null` detaches the list. Omitted when no list is attached.",
1476
+ "anyOf": [
1477
+ {
1478
+ "type": "string",
1479
+ "pattern": "^exl\\.[0-9a-f]{8}-[0-9a-f]{4}-[7][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
1480
+ },
1481
+ {
1482
+ "type": "null"
1483
+ }
1484
+ ]
1477
1485
  }
1478
1486
  },
1479
1487
  "required": [
@@ -1498,6 +1506,18 @@
1498
1506
  "type": "number",
1499
1507
  "exclusiveMinimum": 0
1500
1508
  },
1509
+ "expertListId": {
1510
+ "description": "Expert list the experts come from, with prefix `exl.`. Requires `audienceMode: service`. `null` detaches the list. Omitted when no list is attached.",
1511
+ "anyOf": [
1512
+ {
1513
+ "type": "string",
1514
+ "pattern": "^exl\\.[0-9a-f]{8}-[0-9a-f]{4}-[7][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
1515
+ },
1516
+ {
1517
+ "type": "null"
1518
+ }
1519
+ ]
1520
+ },
1501
1521
  "llmQaModelId": {
1502
1522
  "default": "gpt-5.6-terra",
1503
1523
  "type": "string",
@@ -1520,28 +1540,6 @@
1520
1540
  ]
1521
1541
  },
1522
1542
  "audienceAndPricing": {
1523
- "default": {
1524
- "audienceType": "human",
1525
- "verifiedExperts": true,
1526
- "audience": {
1527
- "languages": {
1528
- "type": "and",
1529
- "values": []
1530
- },
1531
- "specializations": {
1532
- "type": "and",
1533
- "values": []
1534
- },
1535
- "countries": {
1536
- "type": "or",
1537
- "values": []
1538
- }
1539
- },
1540
- "pricePerTask": 6,
1541
- "timeForTask": 1800,
1542
- "perExpertCapEnabled": false,
1543
- "perExpertCapValue": 1
1544
- },
1545
1543
  "oneOf": [
1546
1544
  {
1547
1545
  "type": "object",
@@ -1665,6 +1663,18 @@
1665
1663
  "exclusiveMinimum": 0,
1666
1664
  "maximum": 50
1667
1665
  },
1666
+ "expertListId": {
1667
+ "description": "Expert list the experts come from, with prefix `exl.`. Requires `audienceMode: service`. `null` detaches the list. Omitted when no list is attached.",
1668
+ "anyOf": [
1669
+ {
1670
+ "type": "string",
1671
+ "pattern": "^exl\\.[0-9a-f]{8}-[0-9a-f]{4}-[7][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
1672
+ },
1673
+ {
1674
+ "type": "null"
1675
+ }
1676
+ ]
1677
+ },
1668
1678
  "audienceType": {
1669
1679
  "type": "string",
1670
1680
  "const": "human"
@@ -2325,6 +2335,14 @@
2325
2335
  }
2326
2336
  ]
2327
2337
  },
2338
+ "audienceMode": {
2339
+ "description": "How the node finds experts. `legacy`: audience filters and smart search. `service`: the audience service, which can also take experts from an expert list. Only teams with the audience service enabled can use `service`. Omitted when `legacy`.",
2340
+ "type": "string",
2341
+ "enum": [
2342
+ "legacy",
2343
+ "service"
2344
+ ]
2345
+ },
2328
2346
  "smartSearch": {
2329
2347
  "default": null,
2330
2348
  "anyOf": [
@@ -2648,28 +2666,6 @@
2648
2666
  "type": "string"
2649
2667
  },
2650
2668
  "audienceAndPricing": {
2651
- "default": {
2652
- "audienceType": "human",
2653
- "verifiedExperts": true,
2654
- "audience": {
2655
- "languages": {
2656
- "type": "and",
2657
- "values": []
2658
- },
2659
- "specializations": {
2660
- "type": "and",
2661
- "values": []
2662
- },
2663
- "countries": {
2664
- "type": "or",
2665
- "values": []
2666
- }
2667
- },
2668
- "pricePerTask": 6,
2669
- "timeForTask": 1800,
2670
- "perExpertCapEnabled": false,
2671
- "perExpertCapValue": 1
2672
- },
2673
2669
  "type": "object",
2674
2670
  "properties": {
2675
2671
  "verifiedExperts": {
@@ -2791,6 +2787,18 @@
2791
2787
  "exclusiveMinimum": 0,
2792
2788
  "maximum": 50
2793
2789
  },
2790
+ "expertListId": {
2791
+ "description": "Expert list the experts come from, with prefix `exl.`. Requires `audienceMode: service`. `null` detaches the list. Omitted when no list is attached.",
2792
+ "anyOf": [
2793
+ {
2794
+ "type": "string",
2795
+ "pattern": "^exl\\.[0-9a-f]{8}-[0-9a-f]{4}-[7][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
2796
+ },
2797
+ {
2798
+ "type": "null"
2799
+ }
2800
+ ]
2801
+ },
2794
2802
  "audienceType": {
2795
2803
  "type": "string",
2796
2804
  "const": "human"
@@ -4151,6 +4159,14 @@
4151
4159
  }
4152
4160
  ]
4153
4161
  },
4162
+ "audienceMode": {
4163
+ "description": "How the node finds experts. `legacy`: audience filters and smart search. `service`: the audience service, which can also take experts from an expert list. Only teams with the audience service enabled can use `service`. Omitted when `legacy`.",
4164
+ "type": "string",
4165
+ "enum": [
4166
+ "legacy",
4167
+ "service"
4168
+ ]
4169
+ },
4154
4170
  "smartSearch": {
4155
4171
  "default": null,
4156
4172
  "anyOf": [
package/src/transport.ts CHANGED
@@ -19,6 +19,8 @@ const TUNNEL_UNAVAILABLE = "tunnel-unavailable";
19
19
  export const TUNNEL_RETRY_DELAYS_MS: readonly number[] = [
20
20
  1_000, 2_000, 4_000, 8_000, 15_000, 15_000, 15_000, 15_000, 15_000,
21
21
  ];
22
+ const RATE_LIMIT_RETRIES = 3;
23
+ const MAX_RATE_LIMIT_DELAY_MS = 60_000;
22
24
 
23
25
  type TransportRequestInit = RequestInit & {
24
26
  readonly fetch?: typeof globalThis.fetch;
@@ -26,6 +28,13 @@ type TransportRequestInit = RequestInit & {
26
28
  readonly tunnelRetryDelaysMs?: readonly number[];
27
29
  };
28
30
 
31
+ const rateLimitDelayMs = (response: Response): number | undefined => {
32
+ const retryAfter = response.headers.get("retry-after");
33
+ if (response.status !== 429 || retryAfter === null || retryAfter.trim() === "") return undefined;
34
+ const seconds = Number(retryAfter);
35
+ return Number.isFinite(seconds) && seconds >= 0 ? Math.min(seconds * 1_000, MAX_RATE_LIMIT_DELAY_MS) : undefined;
36
+ };
37
+
29
38
  export const createRequestOptions = (
30
39
  baseUrl: string,
31
40
  credential: ClientCredential,
@@ -109,6 +118,15 @@ export async function potatoFetch(url: string, options: TransportRequestInit): P
109
118
  response = await send();
110
119
  }
111
120
 
121
+ for (let retry = 0; replayableBody && retry < RATE_LIMIT_RETRIES; retry += 1) {
122
+ const delayMs = rateLimitDelayMs(response);
123
+ if (delayMs === undefined) break;
124
+
125
+ await response.body?.cancel();
126
+ await delay(delayMs, { signal: requestOptions.signal ?? undefined });
127
+ response = await send();
128
+ }
129
+
112
130
  const text = await response.text();
113
131
 
114
132
  if (!response.ok) {