@oro-ai/sdk 0.6.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.
- package/README.md +206 -0
- package/dist/index.d.mts +2715 -0
- package/dist/index.d.ts +2715 -0
- package/dist/index.js +737 -0
- package/dist/index.mjs +644 -0
- package/package.json +64 -0
- package/src/generated/index.ts +3 -0
- package/src/generated/sdk.gen.ts +481 -0
- package/src/generated/types.gen.ts +2361 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,737 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
SessionAuthManager: () => SessionAuthManager,
|
|
34
|
+
activateSuite: () => activateSuite,
|
|
35
|
+
banMiner: () => banMiner,
|
|
36
|
+
banValidator: () => banValidator,
|
|
37
|
+
cancelAgentVersion: () => cancelAgentVersion,
|
|
38
|
+
claimWork: () => claimWork,
|
|
39
|
+
classifyError: () => classifyError,
|
|
40
|
+
classifyStatus: () => classifyStatus,
|
|
41
|
+
client: () => client,
|
|
42
|
+
completeRun: () => completeRun,
|
|
43
|
+
computeDelay: () => computeDelay,
|
|
44
|
+
configureBittensorAuth: () => configureBittensorAuth,
|
|
45
|
+
configurePublicClient: () => configurePublicClient,
|
|
46
|
+
configureSessionAuth: () => configureSessionAuth,
|
|
47
|
+
createRetryFetch: () => createRetryFetch,
|
|
48
|
+
createSessionEndpoint: () => createSessionEndpoint,
|
|
49
|
+
createSuite: () => createSuite,
|
|
50
|
+
discardAgentVersion: () => discardAgentVersion,
|
|
51
|
+
generateAuthHeaders: () => generateAuthHeaders,
|
|
52
|
+
getAgentVersion: () => getAgentVersion,
|
|
53
|
+
getAgentVersionProblems: () => getAgentVersionProblems,
|
|
54
|
+
getAgentVersionRuns: () => getAgentVersionRuns,
|
|
55
|
+
getAgentVersionStatus: () => getAgentVersionStatus,
|
|
56
|
+
getArtifactDownloadUrl: () => getArtifactDownloadUrl,
|
|
57
|
+
getAuditEvents: () => getAuditEvents,
|
|
58
|
+
getCurrentSuite: () => getCurrentSuite,
|
|
59
|
+
getErrorCode: () => getErrorCode,
|
|
60
|
+
getErrorDetail: () => getErrorDetail,
|
|
61
|
+
getEvaluationRun: () => getEvaluationRun,
|
|
62
|
+
getLeaderboard: () => getLeaderboard,
|
|
63
|
+
getOwnedAgentVersionStatus: () => getOwnedAgentVersionStatus,
|
|
64
|
+
getPendingEvaluations: () => getPendingEvaluations,
|
|
65
|
+
getReaperStats: () => getReaperStats,
|
|
66
|
+
getRunningEvaluations: () => getRunningEvaluations,
|
|
67
|
+
getSuiteProblems: () => getSuiteProblems,
|
|
68
|
+
getTopAgent: () => getTopAgent,
|
|
69
|
+
getValidators: () => getValidators,
|
|
70
|
+
hasDetail: () => hasDetail,
|
|
71
|
+
hasErrorCode: () => hasErrorCode,
|
|
72
|
+
healthCheck: () => healthCheck,
|
|
73
|
+
heartbeat: () => heartbeat,
|
|
74
|
+
invalidateEvaluationRun: () => invalidateEvaluationRun,
|
|
75
|
+
isTransient: () => isTransient,
|
|
76
|
+
isTransientError: () => isTransientError,
|
|
77
|
+
listAgentVersions: () => listAgentVersions,
|
|
78
|
+
listMinerAgents: () => listMinerAgents,
|
|
79
|
+
logout: () => logout,
|
|
80
|
+
parseRetryAfter: () => parseRetryAfter,
|
|
81
|
+
presignUpload: () => presignUpload,
|
|
82
|
+
reevaluateAgentVersion: () => reevaluateAgentVersion,
|
|
83
|
+
reinstateAgentVersion: () => reinstateAgentVersion,
|
|
84
|
+
requestChallenge: () => requestChallenge,
|
|
85
|
+
setTopAgent: () => setTopAgent,
|
|
86
|
+
submitAgent: () => submitAgent,
|
|
87
|
+
unbanMiner: () => unbanMiner,
|
|
88
|
+
unbanValidator: () => unbanValidator,
|
|
89
|
+
updateProgress: () => updateProgress
|
|
90
|
+
});
|
|
91
|
+
module.exports = __toCommonJS(index_exports);
|
|
92
|
+
|
|
93
|
+
// src/generated/sdk.gen.ts
|
|
94
|
+
var import_client_fetch = require("@hey-api/client-fetch");
|
|
95
|
+
var client = (0, import_client_fetch.createClient)((0, import_client_fetch.createConfig)());
|
|
96
|
+
var healthCheck = (options) => {
|
|
97
|
+
return (options?.client ?? client).get({
|
|
98
|
+
...options,
|
|
99
|
+
url: "/health"
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
var getCurrentSuite = (options) => {
|
|
103
|
+
return (options?.client ?? client).get({
|
|
104
|
+
...options,
|
|
105
|
+
url: "/v1/public/suites/current"
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
var getSuiteProblems = (options) => {
|
|
109
|
+
return (options?.client ?? client).get({
|
|
110
|
+
...options,
|
|
111
|
+
url: "/v1/public/suites/{suite_id}/problems"
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
var getLeaderboard = (options) => {
|
|
115
|
+
return (options?.client ?? client).get({
|
|
116
|
+
...options,
|
|
117
|
+
url: "/v1/public/leaderboard"
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
var getTopAgent = (options) => {
|
|
121
|
+
return (options?.client ?? client).get({
|
|
122
|
+
...options,
|
|
123
|
+
url: "/v1/public/top"
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
var getAgentVersionStatus = (options) => {
|
|
127
|
+
return (options?.client ?? client).get({
|
|
128
|
+
...options,
|
|
129
|
+
url: "/v1/public/agent-versions/{agent_version_id}/status"
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
var getAgentVersionRuns = (options) => {
|
|
133
|
+
return (options?.client ?? client).get({
|
|
134
|
+
...options,
|
|
135
|
+
url: "/v1/public/agent-versions/{agent_version_id}/runs"
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
var getAgentVersionProblems = (options) => {
|
|
139
|
+
return (options?.client ?? client).get({
|
|
140
|
+
...options,
|
|
141
|
+
url: "/v1/public/agent-versions/{agent_version_id}/problems"
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
var getAgentVersion = (options) => {
|
|
145
|
+
return (options?.client ?? client).get({
|
|
146
|
+
...options,
|
|
147
|
+
url: "/v1/public/agent-versions/{agent_version_id}"
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
var getArtifactDownloadUrl = (options) => {
|
|
151
|
+
return (options?.client ?? client).post({
|
|
152
|
+
...options,
|
|
153
|
+
url: "/v1/public/artifacts/download-url"
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
var getEvaluationRun = (options) => {
|
|
157
|
+
return (options?.client ?? client).get({
|
|
158
|
+
...options,
|
|
159
|
+
url: "/v1/public/evaluation-runs/{eval_run_id}"
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
var getValidators = (options) => {
|
|
163
|
+
return (options?.client ?? client).get({
|
|
164
|
+
...options,
|
|
165
|
+
url: "/v1/public/validators"
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
var getRunningEvaluations = (options) => {
|
|
169
|
+
return (options?.client ?? client).get({
|
|
170
|
+
...options,
|
|
171
|
+
url: "/v1/public/evaluations/running"
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
var getPendingEvaluations = (options) => {
|
|
175
|
+
return (options?.client ?? client).get({
|
|
176
|
+
...options,
|
|
177
|
+
url: "/v1/public/evaluations/pending"
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
var requestChallenge = (options) => {
|
|
181
|
+
return (options?.client ?? client).post({
|
|
182
|
+
...options,
|
|
183
|
+
url: "/v1/auth/challenge"
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
var createSessionEndpoint = (options) => {
|
|
187
|
+
return (options?.client ?? client).post({
|
|
188
|
+
...options,
|
|
189
|
+
url: "/v1/auth/session"
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
var logout = (options) => {
|
|
193
|
+
return (options?.client ?? client).post({
|
|
194
|
+
...options,
|
|
195
|
+
url: "/v1/auth/logout"
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
var submitAgent = (options) => {
|
|
199
|
+
return (options?.client ?? client).post({
|
|
200
|
+
...options,
|
|
201
|
+
...import_client_fetch.formDataBodySerializer,
|
|
202
|
+
headers: {
|
|
203
|
+
"Content-Type": null,
|
|
204
|
+
...options?.headers
|
|
205
|
+
},
|
|
206
|
+
url: "/v1/miner/submit"
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
var listMinerAgents = (options) => {
|
|
210
|
+
return (options?.client ?? client).get({
|
|
211
|
+
...options,
|
|
212
|
+
url: "/v1/miner/agents"
|
|
213
|
+
});
|
|
214
|
+
};
|
|
215
|
+
var listAgentVersions = (options) => {
|
|
216
|
+
return (options?.client ?? client).get({
|
|
217
|
+
...options,
|
|
218
|
+
url: "/v1/miner/agents/{agent_id}/versions"
|
|
219
|
+
});
|
|
220
|
+
};
|
|
221
|
+
var getOwnedAgentVersionStatus = (options) => {
|
|
222
|
+
return (options?.client ?? client).get({
|
|
223
|
+
...options,
|
|
224
|
+
url: "/v1/miner/agent-versions/{agent_version_id}"
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
var claimWork = (options) => {
|
|
228
|
+
return (options?.client ?? client).post({
|
|
229
|
+
...options,
|
|
230
|
+
url: "/v1/validator/work/claim"
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
var heartbeat = (options) => {
|
|
234
|
+
return (options?.client ?? client).post({
|
|
235
|
+
...options,
|
|
236
|
+
url: "/v1/validator/evaluation-runs/{eval_run_id}/heartbeat"
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
var updateProgress = (options) => {
|
|
240
|
+
return (options?.client ?? client).post({
|
|
241
|
+
...options,
|
|
242
|
+
url: "/v1/validator/evaluation-runs/{eval_run_id}/progress"
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
var presignUpload = (options) => {
|
|
246
|
+
return (options?.client ?? client).post({
|
|
247
|
+
...options,
|
|
248
|
+
url: "/v1/validator/uploads/presign"
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
var completeRun = (options) => {
|
|
252
|
+
return (options?.client ?? client).post({
|
|
253
|
+
...options,
|
|
254
|
+
url: "/v1/validator/evaluation-runs/{eval_run_id}/complete"
|
|
255
|
+
});
|
|
256
|
+
};
|
|
257
|
+
var banMiner = (options) => {
|
|
258
|
+
return (options?.client ?? client).post({
|
|
259
|
+
...options,
|
|
260
|
+
url: "/v1/admin/miners/{miner_hotkey}/ban"
|
|
261
|
+
});
|
|
262
|
+
};
|
|
263
|
+
var unbanMiner = (options) => {
|
|
264
|
+
return (options?.client ?? client).post({
|
|
265
|
+
...options,
|
|
266
|
+
url: "/v1/admin/miners/{miner_hotkey}/unban"
|
|
267
|
+
});
|
|
268
|
+
};
|
|
269
|
+
var banValidator = (options) => {
|
|
270
|
+
return (options?.client ?? client).post({
|
|
271
|
+
...options,
|
|
272
|
+
url: "/v1/admin/validators/{validator_hotkey}/ban"
|
|
273
|
+
});
|
|
274
|
+
};
|
|
275
|
+
var unbanValidator = (options) => {
|
|
276
|
+
return (options?.client ?? client).post({
|
|
277
|
+
...options,
|
|
278
|
+
url: "/v1/admin/validators/{validator_hotkey}/unban"
|
|
279
|
+
});
|
|
280
|
+
};
|
|
281
|
+
var discardAgentVersion = (options) => {
|
|
282
|
+
return (options?.client ?? client).post({
|
|
283
|
+
...options,
|
|
284
|
+
url: "/v1/admin/agent-versions/{agent_version_id}/discard"
|
|
285
|
+
});
|
|
286
|
+
};
|
|
287
|
+
var reinstateAgentVersion = (options) => {
|
|
288
|
+
return (options?.client ?? client).post({
|
|
289
|
+
...options,
|
|
290
|
+
url: "/v1/admin/agent-versions/{agent_version_id}/reinstate"
|
|
291
|
+
});
|
|
292
|
+
};
|
|
293
|
+
var setTopAgent = (options) => {
|
|
294
|
+
return (options?.client ?? client).post({
|
|
295
|
+
...options,
|
|
296
|
+
url: "/v1/admin/agent-versions/{agent_version_id}/set-top"
|
|
297
|
+
});
|
|
298
|
+
};
|
|
299
|
+
var invalidateEvaluationRun = (options) => {
|
|
300
|
+
return (options?.client ?? client).post({
|
|
301
|
+
...options,
|
|
302
|
+
url: "/v1/admin/evaluation-runs/{eval_run_id}/invalidate"
|
|
303
|
+
});
|
|
304
|
+
};
|
|
305
|
+
var reevaluateAgentVersion = (options) => {
|
|
306
|
+
return (options?.client ?? client).post({
|
|
307
|
+
...options,
|
|
308
|
+
url: "/v1/admin/agent-versions/{agent_version_id}/reevaluate"
|
|
309
|
+
});
|
|
310
|
+
};
|
|
311
|
+
var cancelAgentVersion = (options) => {
|
|
312
|
+
return (options?.client ?? client).post({
|
|
313
|
+
...options,
|
|
314
|
+
url: "/v1/admin/agent-versions/{agent_version_id}/cancel"
|
|
315
|
+
});
|
|
316
|
+
};
|
|
317
|
+
var createSuite = (options) => {
|
|
318
|
+
return (options?.client ?? client).post({
|
|
319
|
+
...options,
|
|
320
|
+
url: "/v1/admin/suites"
|
|
321
|
+
});
|
|
322
|
+
};
|
|
323
|
+
var activateSuite = (options) => {
|
|
324
|
+
return (options?.client ?? client).post({
|
|
325
|
+
...options,
|
|
326
|
+
url: "/v1/admin/suites/{suite_id}/activate"
|
|
327
|
+
});
|
|
328
|
+
};
|
|
329
|
+
var getAuditEvents = (options) => {
|
|
330
|
+
return (options?.client ?? client).get({
|
|
331
|
+
...options,
|
|
332
|
+
url: "/v1/admin/audit-events"
|
|
333
|
+
});
|
|
334
|
+
};
|
|
335
|
+
var getReaperStats = (options) => {
|
|
336
|
+
return (options?.client ?? client).get({
|
|
337
|
+
...options,
|
|
338
|
+
url: "/v1/admin/reaper/stats"
|
|
339
|
+
});
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
// src/errors.ts
|
|
343
|
+
function classifyStatus(status) {
|
|
344
|
+
if (status === void 0 || status === 0) return "NETWORK";
|
|
345
|
+
if (status === 401 || status === 403) return "AUTH";
|
|
346
|
+
if (status === 404) return "NOT_FOUND";
|
|
347
|
+
if (status === 409) return "CONFLICT";
|
|
348
|
+
if (status === 422) return "VALIDATION";
|
|
349
|
+
if (status === 429) return "RATE_LIMITED";
|
|
350
|
+
if (status >= 500 && status < 600) return "SERVER";
|
|
351
|
+
if (status >= 400 && status < 500) return "VALIDATION";
|
|
352
|
+
return "UNKNOWN";
|
|
353
|
+
}
|
|
354
|
+
function classifyError(response) {
|
|
355
|
+
if (!response) return "NETWORK";
|
|
356
|
+
return classifyStatus(response.status);
|
|
357
|
+
}
|
|
358
|
+
function isTransient(status) {
|
|
359
|
+
if (status === void 0 || status === 0) return true;
|
|
360
|
+
if (status === 429) return true;
|
|
361
|
+
if (status >= 500 && status < 600) return true;
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
function isTransientError(response) {
|
|
365
|
+
if (!response) return true;
|
|
366
|
+
return isTransient(response.status);
|
|
367
|
+
}
|
|
368
|
+
function getErrorDetail(error) {
|
|
369
|
+
if (error == null || typeof error !== "object") return void 0;
|
|
370
|
+
const detail = error.detail;
|
|
371
|
+
if (typeof detail === "string") return detail;
|
|
372
|
+
return void 0;
|
|
373
|
+
}
|
|
374
|
+
function getErrorCode(error) {
|
|
375
|
+
if (error == null || typeof error !== "object") return void 0;
|
|
376
|
+
const code = error.error_code;
|
|
377
|
+
if (typeof code === "string") return code;
|
|
378
|
+
return void 0;
|
|
379
|
+
}
|
|
380
|
+
function hasErrorCode(error, code) {
|
|
381
|
+
return getErrorCode(error) === code;
|
|
382
|
+
}
|
|
383
|
+
function hasDetail(error) {
|
|
384
|
+
return getErrorDetail(error) !== void 0;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// src/retry.ts
|
|
388
|
+
var DEFAULT_RETRYABLE_STATUSES = [429, 502, 503, 504];
|
|
389
|
+
var DEFAULT_MAX_RETRIES = 3;
|
|
390
|
+
var DEFAULT_BASE_DELAY_MS = 1e3;
|
|
391
|
+
var DEFAULT_MAX_DELAY_MS = 3e4;
|
|
392
|
+
function parseRetryAfter(response) {
|
|
393
|
+
const header = response.headers.get("retry-after");
|
|
394
|
+
if (!header) {
|
|
395
|
+
return void 0;
|
|
396
|
+
}
|
|
397
|
+
const seconds = Number(header);
|
|
398
|
+
if (!Number.isNaN(seconds) && seconds >= 0) {
|
|
399
|
+
return seconds * 1e3;
|
|
400
|
+
}
|
|
401
|
+
const date = Date.parse(header);
|
|
402
|
+
if (!Number.isNaN(date)) {
|
|
403
|
+
const delayMs = date - Date.now();
|
|
404
|
+
return delayMs > 0 ? delayMs : 0;
|
|
405
|
+
}
|
|
406
|
+
return void 0;
|
|
407
|
+
}
|
|
408
|
+
function computeDelay(attempt, baseDelayMs, maxDelayMs, jitter, retryAfter) {
|
|
409
|
+
if (retryAfter !== void 0) {
|
|
410
|
+
return Math.min(retryAfter, maxDelayMs);
|
|
411
|
+
}
|
|
412
|
+
const exponential = baseDelayMs * Math.pow(2, attempt);
|
|
413
|
+
const capped = Math.min(exponential, maxDelayMs);
|
|
414
|
+
if (jitter) {
|
|
415
|
+
return Math.floor(Math.random() * capped);
|
|
416
|
+
}
|
|
417
|
+
return capped;
|
|
418
|
+
}
|
|
419
|
+
function createRetryFetch(config) {
|
|
420
|
+
const maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
421
|
+
const retryableStatuses = config.retryableStatuses ?? DEFAULT_RETRYABLE_STATUSES;
|
|
422
|
+
const baseDelayMs = config.baseDelayMs ?? DEFAULT_BASE_DELAY_MS;
|
|
423
|
+
const maxDelayMs = config.maxDelayMs ?? DEFAULT_MAX_DELAY_MS;
|
|
424
|
+
const jitter = config.jitter ?? true;
|
|
425
|
+
const onRetry = config.onRetry;
|
|
426
|
+
return async (input, init) => {
|
|
427
|
+
let lastError;
|
|
428
|
+
let lastResponse;
|
|
429
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
430
|
+
try {
|
|
431
|
+
let fetchInput = input;
|
|
432
|
+
let fetchInit = init;
|
|
433
|
+
if (input instanceof Request) {
|
|
434
|
+
fetchInput = input.clone();
|
|
435
|
+
fetchInit = void 0;
|
|
436
|
+
}
|
|
437
|
+
const response = await globalThis.fetch(fetchInput, fetchInit);
|
|
438
|
+
if (attempt < maxRetries && retryableStatuses.includes(response.status)) {
|
|
439
|
+
lastResponse = response;
|
|
440
|
+
const retryAfter = parseRetryAfter(response);
|
|
441
|
+
const delayMs = computeDelay(
|
|
442
|
+
attempt,
|
|
443
|
+
baseDelayMs,
|
|
444
|
+
maxDelayMs,
|
|
445
|
+
jitter,
|
|
446
|
+
retryAfter
|
|
447
|
+
);
|
|
448
|
+
onRetry?.({
|
|
449
|
+
attempt: attempt + 1,
|
|
450
|
+
delayMs,
|
|
451
|
+
status: response.status,
|
|
452
|
+
retryAfter
|
|
453
|
+
});
|
|
454
|
+
await sleep(delayMs);
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
return response;
|
|
458
|
+
} catch (error) {
|
|
459
|
+
lastError = error;
|
|
460
|
+
if (attempt < maxRetries) {
|
|
461
|
+
const delayMs = computeDelay(
|
|
462
|
+
attempt,
|
|
463
|
+
baseDelayMs,
|
|
464
|
+
maxDelayMs,
|
|
465
|
+
jitter
|
|
466
|
+
);
|
|
467
|
+
onRetry?.({
|
|
468
|
+
attempt: attempt + 1,
|
|
469
|
+
delayMs
|
|
470
|
+
});
|
|
471
|
+
await sleep(delayMs);
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (lastResponse) {
|
|
477
|
+
return lastResponse;
|
|
478
|
+
}
|
|
479
|
+
throw lastError;
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
function sleep(ms) {
|
|
483
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// src/auth.ts
|
|
487
|
+
function isPublicEndpoint(url) {
|
|
488
|
+
if (!url) {
|
|
489
|
+
return false;
|
|
490
|
+
}
|
|
491
|
+
let pathname;
|
|
492
|
+
try {
|
|
493
|
+
const parsed = new URL(url, "http://placeholder");
|
|
494
|
+
pathname = parsed.pathname;
|
|
495
|
+
} catch {
|
|
496
|
+
pathname = url;
|
|
497
|
+
}
|
|
498
|
+
return pathname.includes("/v1/public/") || pathname.includes("/v1/auth/") || pathname === "/health" || pathname.endsWith("/health");
|
|
499
|
+
}
|
|
500
|
+
async function generateAuthHeaders(config, nonce) {
|
|
501
|
+
const cryptoModule = typeof globalThis.crypto !== "undefined" ? globalThis.crypto : await import("crypto");
|
|
502
|
+
const actualNonce = nonce ?? cryptoModule.randomUUID();
|
|
503
|
+
const timestamp = Math.floor(Date.now() / 1e3).toString();
|
|
504
|
+
const message = `${config.hotkey}:${timestamp}:${actualNonce}`;
|
|
505
|
+
const signature = await config.sign(message);
|
|
506
|
+
return {
|
|
507
|
+
"X-Hotkey": config.hotkey,
|
|
508
|
+
"X-Signature": signature.startsWith("0x") ? signature : `0x${signature}`,
|
|
509
|
+
"X-Nonce": actualNonce,
|
|
510
|
+
"X-Timestamp": timestamp
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
function configureBittensorAuth(baseUrl, authConfig, retryConfig) {
|
|
514
|
+
client.setConfig({
|
|
515
|
+
baseUrl,
|
|
516
|
+
fetch: createRetryFetch(retryConfig ?? {})
|
|
517
|
+
});
|
|
518
|
+
client.interceptors.request.use(async (request) => {
|
|
519
|
+
if (isPublicEndpoint(request.url)) {
|
|
520
|
+
return request;
|
|
521
|
+
}
|
|
522
|
+
const headers = await generateAuthHeaders(authConfig);
|
|
523
|
+
Object.entries(headers).forEach(([key, value]) => {
|
|
524
|
+
request.headers.set(key, value);
|
|
525
|
+
});
|
|
526
|
+
return request;
|
|
527
|
+
});
|
|
528
|
+
return client;
|
|
529
|
+
}
|
|
530
|
+
function configurePublicClient(baseUrl, retryConfig) {
|
|
531
|
+
client.setConfig({
|
|
532
|
+
baseUrl,
|
|
533
|
+
fetch: createRetryFetch(retryConfig ?? {})
|
|
534
|
+
});
|
|
535
|
+
return client;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// src/session-auth.ts
|
|
539
|
+
var SessionAuthManager = class {
|
|
540
|
+
token = null;
|
|
541
|
+
expiresAt = 0;
|
|
542
|
+
role = "";
|
|
543
|
+
refreshPromise = null;
|
|
544
|
+
hotkey;
|
|
545
|
+
sign;
|
|
546
|
+
refreshBufferSeconds;
|
|
547
|
+
onSessionExpired;
|
|
548
|
+
constructor(config) {
|
|
549
|
+
this.hotkey = config.hotkey;
|
|
550
|
+
this.sign = config.sign;
|
|
551
|
+
this.refreshBufferSeconds = config.refreshBufferSeconds ?? 300;
|
|
552
|
+
this.onSessionExpired = config.onSessionExpired;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Perform challenge/response login flow.
|
|
556
|
+
*
|
|
557
|
+
* 1. Requests a challenge from the server
|
|
558
|
+
* 2. Signs the challenge with the configured sign function
|
|
559
|
+
* 3. Creates a session with the signed challenge
|
|
560
|
+
* 4. Stores the session token internally
|
|
561
|
+
*/
|
|
562
|
+
async login() {
|
|
563
|
+
const { data: challengeData, error: challengeError } = await requestChallenge({
|
|
564
|
+
body: { hotkey: this.hotkey }
|
|
565
|
+
});
|
|
566
|
+
if (challengeError || !challengeData) {
|
|
567
|
+
throw new Error(
|
|
568
|
+
`Failed to request challenge: ${challengeError ? JSON.stringify(challengeError) : "no data returned"}`
|
|
569
|
+
);
|
|
570
|
+
}
|
|
571
|
+
const signature = await this.sign(challengeData.challenge);
|
|
572
|
+
const { data: sessionData, error: sessionError } = await createSessionEndpoint({
|
|
573
|
+
body: {
|
|
574
|
+
hotkey: this.hotkey,
|
|
575
|
+
challenge: challengeData.challenge,
|
|
576
|
+
signature
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
if (sessionError || !sessionData) {
|
|
580
|
+
throw new Error(
|
|
581
|
+
`Failed to create session: ${sessionError ? JSON.stringify(sessionError) : "no data returned"}`
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
this.token = sessionData.session_token;
|
|
585
|
+
this.expiresAt = sessionData.expires_at;
|
|
586
|
+
this.role = sessionData.role;
|
|
587
|
+
return sessionData;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Logout and invalidate the current session.
|
|
591
|
+
* Silently catches errors (session may already be expired).
|
|
592
|
+
*/
|
|
593
|
+
async logout() {
|
|
594
|
+
if (this.token) {
|
|
595
|
+
try {
|
|
596
|
+
await logout({
|
|
597
|
+
headers: { authorization: `Bearer ${this.token}` }
|
|
598
|
+
});
|
|
599
|
+
} catch {
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
this.clearSession();
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Refresh the session by performing a new login flow.
|
|
606
|
+
*/
|
|
607
|
+
async refreshSession() {
|
|
608
|
+
return this.login();
|
|
609
|
+
}
|
|
610
|
+
/** Returns true if a session token exists and hasn't expired. */
|
|
611
|
+
hasActiveSession() {
|
|
612
|
+
return this.token !== null && Date.now() / 1e3 < this.expiresAt;
|
|
613
|
+
}
|
|
614
|
+
/** Returns true if the session is within the refresh buffer of expiry. */
|
|
615
|
+
sessionNeedsRefresh() {
|
|
616
|
+
if (!this.token) return false;
|
|
617
|
+
const now = Date.now() / 1e3;
|
|
618
|
+
return now >= this.expiresAt - this.refreshBufferSeconds && now < this.expiresAt;
|
|
619
|
+
}
|
|
620
|
+
/** Returns current session info, or null if no active session. */
|
|
621
|
+
getSessionInfo() {
|
|
622
|
+
if (!this.token) return null;
|
|
623
|
+
return {
|
|
624
|
+
hotkey: this.hotkey,
|
|
625
|
+
role: this.role,
|
|
626
|
+
expiresAt: this.expiresAt
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Returns authorization headers. Auto-refreshes if the session is
|
|
631
|
+
* within the refresh buffer. Throws if not authenticated or session expired.
|
|
632
|
+
*/
|
|
633
|
+
async getAuthHeaders() {
|
|
634
|
+
if (!this.token) {
|
|
635
|
+
this.onSessionExpired?.();
|
|
636
|
+
throw new Error("No active session");
|
|
637
|
+
}
|
|
638
|
+
const now = Date.now() / 1e3;
|
|
639
|
+
if (now >= this.expiresAt) {
|
|
640
|
+
this.clearSession();
|
|
641
|
+
this.onSessionExpired?.();
|
|
642
|
+
throw new Error("Session expired");
|
|
643
|
+
}
|
|
644
|
+
if (this.sessionNeedsRefresh()) {
|
|
645
|
+
if (!this.refreshPromise) {
|
|
646
|
+
this.refreshPromise = this.refreshSession().catch(() => {
|
|
647
|
+
return null;
|
|
648
|
+
}).finally(() => {
|
|
649
|
+
this.refreshPromise = null;
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
await this.refreshPromise;
|
|
653
|
+
}
|
|
654
|
+
return { Authorization: `Bearer ${this.token}` };
|
|
655
|
+
}
|
|
656
|
+
clearSession() {
|
|
657
|
+
this.token = null;
|
|
658
|
+
this.expiresAt = 0;
|
|
659
|
+
this.role = "";
|
|
660
|
+
this.refreshPromise = null;
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
function configureSessionAuth(baseUrl, config) {
|
|
664
|
+
const manager = new SessionAuthManager(config);
|
|
665
|
+
client.setConfig({ baseUrl });
|
|
666
|
+
client.interceptors.request.use(async (request) => {
|
|
667
|
+
if (isPublicEndpoint(request.url)) {
|
|
668
|
+
return request;
|
|
669
|
+
}
|
|
670
|
+
const headers = await manager.getAuthHeaders();
|
|
671
|
+
Object.entries(headers).forEach(([key, value]) => {
|
|
672
|
+
request.headers.set(key, value);
|
|
673
|
+
});
|
|
674
|
+
return request;
|
|
675
|
+
});
|
|
676
|
+
return manager;
|
|
677
|
+
}
|
|
678
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
679
|
+
0 && (module.exports = {
|
|
680
|
+
SessionAuthManager,
|
|
681
|
+
activateSuite,
|
|
682
|
+
banMiner,
|
|
683
|
+
banValidator,
|
|
684
|
+
cancelAgentVersion,
|
|
685
|
+
claimWork,
|
|
686
|
+
classifyError,
|
|
687
|
+
classifyStatus,
|
|
688
|
+
client,
|
|
689
|
+
completeRun,
|
|
690
|
+
computeDelay,
|
|
691
|
+
configureBittensorAuth,
|
|
692
|
+
configurePublicClient,
|
|
693
|
+
configureSessionAuth,
|
|
694
|
+
createRetryFetch,
|
|
695
|
+
createSessionEndpoint,
|
|
696
|
+
createSuite,
|
|
697
|
+
discardAgentVersion,
|
|
698
|
+
generateAuthHeaders,
|
|
699
|
+
getAgentVersion,
|
|
700
|
+
getAgentVersionProblems,
|
|
701
|
+
getAgentVersionRuns,
|
|
702
|
+
getAgentVersionStatus,
|
|
703
|
+
getArtifactDownloadUrl,
|
|
704
|
+
getAuditEvents,
|
|
705
|
+
getCurrentSuite,
|
|
706
|
+
getErrorCode,
|
|
707
|
+
getErrorDetail,
|
|
708
|
+
getEvaluationRun,
|
|
709
|
+
getLeaderboard,
|
|
710
|
+
getOwnedAgentVersionStatus,
|
|
711
|
+
getPendingEvaluations,
|
|
712
|
+
getReaperStats,
|
|
713
|
+
getRunningEvaluations,
|
|
714
|
+
getSuiteProblems,
|
|
715
|
+
getTopAgent,
|
|
716
|
+
getValidators,
|
|
717
|
+
hasDetail,
|
|
718
|
+
hasErrorCode,
|
|
719
|
+
healthCheck,
|
|
720
|
+
heartbeat,
|
|
721
|
+
invalidateEvaluationRun,
|
|
722
|
+
isTransient,
|
|
723
|
+
isTransientError,
|
|
724
|
+
listAgentVersions,
|
|
725
|
+
listMinerAgents,
|
|
726
|
+
logout,
|
|
727
|
+
parseRetryAfter,
|
|
728
|
+
presignUpload,
|
|
729
|
+
reevaluateAgentVersion,
|
|
730
|
+
reinstateAgentVersion,
|
|
731
|
+
requestChallenge,
|
|
732
|
+
setTopAgent,
|
|
733
|
+
submitAgent,
|
|
734
|
+
unbanMiner,
|
|
735
|
+
unbanValidator,
|
|
736
|
+
updateProgress
|
|
737
|
+
});
|