@nouter/platform 0.0.0-stage → 0.2.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 (45) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +23 -0
  3. package/README.md +183 -2
  4. package/dist/agents.d.ts +331 -0
  5. package/dist/agents.js +1 -0
  6. package/dist/deployments.d.ts +35 -0
  7. package/dist/deployments.js +1 -0
  8. package/dist/environments.d.ts +30 -0
  9. package/dist/environments.js +1 -0
  10. package/dist/evals.d.ts +419 -0
  11. package/dist/evals.js +186 -0
  12. package/dist/generated/openapi.d.ts +34866 -0
  13. package/dist/index.d.ts +39 -0
  14. package/dist/index.js +90 -0
  15. package/dist/oma.d.ts +126 -0
  16. package/dist/oma.js +80 -0
  17. package/dist/platform/api-keys.d.ts +54 -0
  18. package/dist/platform/api-keys.js +62 -0
  19. package/dist/platform/audit-events.d.ts +22 -0
  20. package/dist/platform/audit-events.js +29 -0
  21. package/dist/platform/errors.d.ts +30 -0
  22. package/dist/platform/errors.js +66 -0
  23. package/dist/platform/http.d.ts +27 -0
  24. package/dist/platform/http.js +57 -0
  25. package/dist/platform/me.d.ts +15 -0
  26. package/dist/platform/me.js +10 -0
  27. package/dist/platform/model-cards.d.ts +34 -0
  28. package/dist/platform/model-cards.js +40 -0
  29. package/dist/platform/privacy-erasure.d.ts +37 -0
  30. package/dist/platform/privacy-erasure.js +40 -0
  31. package/dist/platform/rate-limits.d.ts +16 -0
  32. package/dist/platform/rate-limits.js +14 -0
  33. package/dist/platform/settings.d.ts +17 -0
  34. package/dist/platform/settings.js +17 -0
  35. package/dist/platform/types.d.ts +6 -0
  36. package/dist/platform/types.js +1 -0
  37. package/dist/platform/usage-limits.d.ts +34 -0
  38. package/dist/platform/usage-limits.js +38 -0
  39. package/dist/platform/usage.d.ts +30 -0
  40. package/dist/platform/usage.js +34 -0
  41. package/dist/platform/user-profiles.d.ts +35 -0
  42. package/dist/platform/user-profiles.js +46 -0
  43. package/dist/trigger-events.d.ts +36 -0
  44. package/dist/trigger-events.js +1 -0
  45. package/package.json +63 -4
@@ -0,0 +1,419 @@
1
+ import Anthropic from "@anthropic-ai/sdk";
2
+ export type EvalBenchmarkKind = "harbor" | "messages";
3
+ /** Where harbor cases come from. */
4
+ export type HarborCaseSource =
5
+ /** Task directories (found by their task.toml) in a git repository:
6
+ * https://github.com/<owner>/<repo> or
7
+ * https://huggingface.co/datasets/<org>/<name>. ref is a branch, tag or
8
+ * commit sha (default HEAD), resolved to a commit at import and at every
9
+ * sync. path limits the import to one directory (a task or a folder of
10
+ * tasks). */
11
+ {
12
+ type: "git";
13
+ url: string;
14
+ ref?: string;
15
+ path?: string;
16
+ }
17
+ /** A dataset from a Harbor registry.json (default: Harbor's public
18
+ * registry). Its tasks are git entries pinned to commits. */
19
+ | {
20
+ type: "registry";
21
+ name: string;
22
+ version?: string;
23
+ registry_url?: string;
24
+ }
25
+ /** A dataset shipped with OMA; see GET /v1/oma/evals/benchmarks/builtin. */
26
+ | {
27
+ type: "builtin";
28
+ name: string;
29
+ }
30
+ /** A .tar or .tar.gz uploaded through the Files API. Task directories are
31
+ * found anywhere in the archive by their task.toml. */
32
+ | {
33
+ type: "upload";
34
+ file_id: string;
35
+ };
36
+ /** A git repository at the commit a revision was read from. */
37
+ export interface EvalSourcePin {
38
+ url: string;
39
+ /** The ref that was resolved (git sources). */
40
+ ref?: string;
41
+ commit: string;
42
+ }
43
+ /** One immutable state of a harbor benchmark's cases. */
44
+ export interface EvalBenchmarkRevision {
45
+ /** 1, 2, ... */
46
+ revision: number;
47
+ /** "sha256:<hex>" over the sorted "<case name>\0<case digest>\n" lines. */
48
+ digest: string;
49
+ source: HarborCaseSource;
50
+ /** Commits read (empty for uploads). */
51
+ pins: EvalSourcePin[];
52
+ /** The case_names filter of the import, reused by sync. */
53
+ case_names?: string[];
54
+ case_count: number;
55
+ created_at: string;
56
+ }
57
+ /** A messages case as written by clients (create, add, replace). */
58
+ export interface MessagesCaseInput {
59
+ /** [A-Za-z0-9][A-Za-z0-9._-]{0,127}; unique in the benchmark. Ignored on
60
+ * replace (the path names the case). */
61
+ name: string;
62
+ /** User messages sent in order, each after the previous turn ends. */
63
+ messages: string[];
64
+ /** eval-core RewardSpec; type must be verifiable | script | reward_model | composite (else 400). */
65
+ reward?: unknown;
66
+ setup_files?: {
67
+ path: string;
68
+ content: string;
69
+ }[];
70
+ /** Bash run in the Session sandbox before the first message. */
71
+ setup_script?: string;
72
+ timeout_ms?: number;
73
+ }
74
+ export type CreateEvalBenchmarkRequest =
75
+ /** Import a harbor benchmark (revision 1). name defaults to the source's
76
+ * name (registry/builtin name, repository/path, upload file name). */
77
+ {
78
+ kind?: "harbor";
79
+ name?: string;
80
+ source: HarborCaseSource;
81
+ case_names?: string[];
82
+ }
83
+ /** A messages benchmark with optional initial cases. */
84
+ | {
85
+ kind: "messages";
86
+ name: string;
87
+ source?: undefined;
88
+ cases?: MessagesCaseInput[];
89
+ };
90
+ export interface UpdateEvalBenchmarkRequest {
91
+ name?: string;
92
+ }
93
+ /** Re-read a harbor benchmark's source. A new revision is made only when the
94
+ * content changed. */
95
+ export interface SyncEvalBenchmarkRequest {
96
+ /** git sources: resolve this ref instead of the source's ref; it becomes
97
+ * the source's ref in the new revision. */
98
+ ref?: string;
99
+ /** upload sources: required, the new archive. */
100
+ file_id?: string;
101
+ }
102
+ export interface SyncEvalBenchmarkResponse {
103
+ /** false: same content digest as the latest revision; nothing was written. */
104
+ changed: boolean;
105
+ benchmark: EvalBenchmark;
106
+ }
107
+ /** messages benchmarks only: one case. */
108
+ export type AddEvalCasesRequest = MessagesCaseInput;
109
+ /** messages benchmarks only: the new case content. */
110
+ export type ReplaceEvalCaseRequest = MessagesCaseInput;
111
+ /** A harbor case as listed in a benchmark revision. */
112
+ export interface HarborEvalCase {
113
+ kind: "harbor";
114
+ name: string;
115
+ /** "sha256:<hex>", Harbor's package hash over the stored files. */
116
+ digest: string;
117
+ /** [environment].docker_image from task.toml. */
118
+ image: string;
119
+ /** SANDBOX_IMAGES alias whose reference equals `image`; null when the
120
+ * operator catalog has none (the case cannot run until one is added). */
121
+ image_alias: string | null;
122
+ /** false when the task uses a Harbor feature OMA does not run yet. */
123
+ supported: boolean;
124
+ unsupported_reason?: string;
125
+ agent_timeout_sec: number | null;
126
+ verifier_timeout_sec: number;
127
+ cpus: number | null;
128
+ memory_mb: number | null;
129
+ has_solution: boolean;
130
+ /** First 2000 characters of instruction.md. */
131
+ instruction_preview: string;
132
+ /** When this content first entered the benchmark's revisions. */
133
+ updated_at: string;
134
+ }
135
+ /** A messages case as listed in a benchmark (its full content). */
136
+ export interface MessagesEvalCase extends Omit<MessagesCaseInput, "reward"> {
137
+ kind: "messages";
138
+ reward?: unknown;
139
+ updated_at: string;
140
+ }
141
+ export type EvalCase = HarborEvalCase | MessagesEvalCase;
142
+ /** GET/PUT of one case: a harbor case adds its full instruction and the
143
+ * stored files (task.toml, instruction.md, tests/, solution/). */
144
+ export type EvalCaseDetail = (HarborEvalCase & {
145
+ revision: number;
146
+ instruction: string;
147
+ files: Array<{
148
+ path: string;
149
+ size: number;
150
+ executable: boolean;
151
+ }>;
152
+ }) | MessagesEvalCase;
153
+ export interface EvalBenchmark {
154
+ id: string;
155
+ name: string;
156
+ kind: EvalBenchmarkKind;
157
+ /** harbor: the latest revision's source. messages: null. */
158
+ source: HarborCaseSource | null;
159
+ /** harbor: latest revision number. messages: null. */
160
+ revision: number | null;
161
+ /** Cases of the latest revision (or of ?revision=N on GET). */
162
+ case_count: number;
163
+ /** harbor: cases supported and with an image alias. messages: case_count. */
164
+ runnable_count: number;
165
+ created_at: string;
166
+ updated_at: string;
167
+ /** present on GET /benchmarks/:id and write responses */
168
+ cases?: EvalCase[];
169
+ /** harbor, on GET /benchmarks/:id and write responses: newest first. */
170
+ revisions?: EvalBenchmarkRevision[];
171
+ /** Revision the listed cases belong to (harbor, with cases). */
172
+ cases_revision?: number;
173
+ }
174
+ export interface BuiltinEvalBenchmark {
175
+ name: string;
176
+ description: string;
177
+ case_count: number;
178
+ }
179
+ /** A branch or tag and the commit it points to (tags: the peeled target). */
180
+ export interface EvalGitRef {
181
+ name: string;
182
+ commit: string;
183
+ }
184
+ /** GET /v1/oma/evals/git-refs?url= : refs to pick a git source's ref from. */
185
+ export interface EvalGitRefList {
186
+ /** The normalized repository URL. */
187
+ url: string;
188
+ /** The branch HEAD points to (what an import without ref reads); null when unknown. */
189
+ default_branch: string | null;
190
+ /** Default branch first, then by name. */
191
+ branches: EvalGitRef[];
192
+ /** Newest-looking first (natural order, descending). */
193
+ tags: EvalGitRef[];
194
+ /** More than 1000 branches or tags: the lists are cut; a ref can still be passed by name. */
195
+ truncated: boolean;
196
+ }
197
+ export type EvalRunStatus = "pending" | "running" | "completed" | "failed" | "cancelled";
198
+ export type CreateEvalRunRequest =
199
+ /** Run a benchmark (all runnable cases, or case_names). The run's kind is
200
+ * the benchmark's kind; a harbor run is bound to the latest revision. */
201
+ {
202
+ benchmark_id: string;
203
+ /** harbor only: "agent" (default) needs agent_id; "oracle" runs
204
+ * solution/solve.sh in a Session owned by a hidden platform agent and
205
+ * rejects agent_id (400). messages benchmarks accept "agent" only. */
206
+ mode?: "agent" | "oracle";
207
+ agent_id?: string;
208
+ /** messages benchmarks: required (the Session environment). harbor:
209
+ * rejected (400); each case's image picks its environment. */
210
+ environment_id?: string;
211
+ /** Subset of the benchmark; default every runnable case. */
212
+ case_names?: string[];
213
+ /** Trials per case, default 1, max 20. */
214
+ trials?: number;
215
+ /** Trials running at once, default 4, max 32. */
216
+ concurrency?: number;
217
+ }
218
+ /** Inline messages tasks (the original API, unchanged). */
219
+ | {
220
+ kind?: "messages";
221
+ agent_id: string;
222
+ environment_id: string;
223
+ tasks: Array<{
224
+ id: string;
225
+ messages: string[];
226
+ setup_files?: {
227
+ path: string;
228
+ content: string;
229
+ }[];
230
+ setup_script?: string;
231
+ timeout_ms?: number;
232
+ trials?: number;
233
+ /** eval-core RewardSpec; type must be verifiable | script | reward_model | composite (else 400). */
234
+ reward?: unknown;
235
+ }>;
236
+ };
237
+ export interface CreateEvalRunResponse {
238
+ run_id: string;
239
+ task_count: number;
240
+ }
241
+ export type EvalTrialPhase = "provisioning" | "agent" | "verifying" | "done";
242
+ export interface EvalTrial {
243
+ trial_index: number;
244
+ status: EvalRunStatus;
245
+ phase?: EvalTrialPhase;
246
+ session_id?: string;
247
+ started_at?: string;
248
+ ended_at?: string;
249
+ /** Final reward (Harbor: rewards.reward; messages: verifier final_reward). */
250
+ reward?: number;
251
+ /** Every key of reward.json (Harbor) or raw verifier rewards. */
252
+ rewards?: Record<string, number>;
253
+ /** The agent hit the task's agent timeout and was interrupted; still graded. */
254
+ agent_timed_out?: boolean;
255
+ test_exit_code?: number;
256
+ /** Last 4000 bytes of /logs/verifier/test-stdout.txt. */
257
+ verifier_output_tail?: string;
258
+ error?: string;
259
+ /** messages kind only. */
260
+ trajectory_id?: string;
261
+ current_message_index?: number;
262
+ }
263
+ export interface EvalRunTask {
264
+ /** Case name (benchmark runs) or inline task id. */
265
+ id: string;
266
+ status: EvalRunStatus;
267
+ trials: EvalTrial[];
268
+ trial_total: number;
269
+ trial_pass_count?: number;
270
+ /** harbor: mean over every finished trial, errored trials counting 0 (Harbor's
271
+ * convention). messages: mean over completed trials. */
272
+ mean_reward?: number;
273
+ error?: string;
274
+ /** harbor kind: image alias used. */
275
+ image_alias?: string;
276
+ /** harbor kind: content digest of the case that ran. */
277
+ digest?: string;
278
+ }
279
+ export interface EvalRun {
280
+ id: string;
281
+ kind: "messages" | "harbor";
282
+ agent_id: string | null;
283
+ environment_id: string | null;
284
+ /** Set when the run executes a benchmark. */
285
+ benchmark_id?: string;
286
+ /** harbor benchmark runs: the revision the run is bound to. */
287
+ benchmark_revision?: number;
288
+ mode?: "agent" | "oracle";
289
+ status: EvalRunStatus;
290
+ created_at: string;
291
+ started_at?: string;
292
+ ended_at?: string;
293
+ task_count: number;
294
+ completed_count: number;
295
+ failed_count: number;
296
+ /** Mean of per-task mean_reward over tasks with at least one graded trial. */
297
+ score?: number;
298
+ concurrency?: number;
299
+ tasks: EvalRunTask[];
300
+ error?: string;
301
+ }
302
+ export interface EvalBenchmarkListResponse {
303
+ data: EvalBenchmark[];
304
+ }
305
+ export interface BuiltinEvalBenchmarkListResponse {
306
+ data: BuiltinEvalBenchmark[];
307
+ }
308
+ export interface EvalBenchmarkDeleted {
309
+ type: "eval_benchmark_deleted";
310
+ id: string;
311
+ }
312
+ export interface EvalCaseDeleted {
313
+ type: "eval_case_deleted";
314
+ benchmark_id: string;
315
+ name: string;
316
+ }
317
+ export interface EvalRunListParams {
318
+ status?: EvalRunStatus;
319
+ agent_id?: string;
320
+ benchmark_id?: string;
321
+ limit?: number;
322
+ }
323
+ export interface EvalRunListResponse {
324
+ data: EvalRun[];
325
+ }
326
+ export interface EvalRunDeleted {
327
+ type: "eval_run_deleted";
328
+ id: string;
329
+ }
330
+ /** A .tar/.tar.gz archive to send through the Files API. */
331
+ export interface EvalArchiveUpload {
332
+ /** A .tar or .tar.gz archive containing Harbor task directories. */
333
+ file: Blob | Uint8Array;
334
+ /** File name sent to the Files API; must end in .tar, .tar.gz or .tgz. */
335
+ filename: string;
336
+ }
337
+ export interface UploadEvalBenchmarkParams extends EvalArchiveUpload {
338
+ /** Benchmark name; the server defaults to the upload file name. */
339
+ name?: string;
340
+ /** Import only these tasks from the archive. */
341
+ case_names?: string[];
342
+ }
343
+ /** Sync an upload benchmark from a new archive. */
344
+ export type SyncUploadEvalBenchmarkParams = EvalArchiveUpload;
345
+ export interface EvalBenchmarkRetrieveParams {
346
+ /** harbor: list the cases of this revision instead of the latest. */
347
+ revision?: number;
348
+ }
349
+ export interface EvalCaseRetrieveParams {
350
+ /** harbor: read the case from this revision instead of the latest. */
351
+ revision?: number;
352
+ }
353
+ export interface WaitForEvalRunOptions {
354
+ /** Delay between polls. Default 5000 ms. */
355
+ intervalMs?: number;
356
+ /** Give up after this long (throws). Default: no timeout. */
357
+ timeoutMs?: number;
358
+ /** Called with every polled run, including the terminal one. */
359
+ onProgress?: (run: EvalRun) => void;
360
+ /** Aborts the wait (rejects with the signal's reason). */
361
+ signal?: AbortSignal;
362
+ requestOptions?: Anthropic.RequestOptions;
363
+ }
364
+ export declare const EVAL_RUN_TERMINAL_STATUSES: readonly EvalRunStatus[];
365
+ /** Cases of one benchmark: /v1/oma/evals/benchmarks/:id/cases. */
366
+ export declare class EvalCasesResource {
367
+ private readonly client;
368
+ constructor(client: Anthropic);
369
+ private path;
370
+ /** One case; harbor benchmarks accept { revision } (default latest). */
371
+ retrieve(benchmarkId: string, name: string, params?: EvalCaseRetrieveParams, options?: Anthropic.RequestOptions): import("@anthropic-ai/sdk").APIPromise<EvalCaseDetail>;
372
+ /** messages benchmarks only (harbor cases are read-only; sync the benchmark instead). */
373
+ add(benchmarkId: string, params: AddEvalCasesRequest, options?: Anthropic.RequestOptions): import("@anthropic-ai/sdk").APIPromise<EvalBenchmark>;
374
+ /** messages benchmarks only. */
375
+ replace(benchmarkId: string, name: string, params: ReplaceEvalCaseRequest, options?: Anthropic.RequestOptions): import("@anthropic-ai/sdk").APIPromise<EvalCaseDetail>;
376
+ /** messages benchmarks only. */
377
+ delete(benchmarkId: string, name: string, options?: Anthropic.RequestOptions): import("@anthropic-ai/sdk").APIPromise<EvalCaseDeleted>;
378
+ }
379
+ export declare class EvalBenchmarksResource {
380
+ private readonly client;
381
+ readonly cases: EvalCasesResource;
382
+ constructor(client: Anthropic);
383
+ list(options?: Anthropic.RequestOptions): import("@anthropic-ai/sdk").APIPromise<EvalBenchmarkListResponse>;
384
+ listBuiltin(options?: Anthropic.RequestOptions): import("@anthropic-ai/sdk").APIPromise<BuiltinEvalBenchmarkListResponse>;
385
+ /** Import a harbor benchmark from a source (revision 1), or create a messages benchmark. */
386
+ create(params: CreateEvalBenchmarkRequest, options?: Anthropic.RequestOptions): import("@anthropic-ai/sdk").APIPromise<EvalBenchmark>;
387
+ /** With cases (of { revision }, default latest) and, for harbor, its revisions. */
388
+ retrieve(id: string, params?: EvalBenchmarkRetrieveParams, options?: Anthropic.RequestOptions): import("@anthropic-ai/sdk").APIPromise<EvalBenchmark>;
389
+ /** harbor: re-read the source; a new revision is made only when content changed.
390
+ * git sources accept { ref }; upload sources need { file_id } (see syncUpload). */
391
+ sync(id: string, params?: SyncEvalBenchmarkRequest, options?: Anthropic.RequestOptions): import("@anthropic-ai/sdk").APIPromise<SyncEvalBenchmarkResponse>;
392
+ /** harbor upload benchmark: upload a new .tar/.tar.gz through the Files API, then sync from it. */
393
+ syncUpload(id: string, params: SyncUploadEvalBenchmarkParams, options?: Anthropic.RequestOptions): Promise<SyncEvalBenchmarkResponse>;
394
+ update(id: string, params: UpdateEvalBenchmarkRequest, options?: Anthropic.RequestOptions): import("@anthropic-ai/sdk").APIPromise<EvalBenchmark>;
395
+ delete(id: string, options?: Anthropic.RequestOptions): import("@anthropic-ai/sdk").APIPromise<EvalBenchmarkDeleted>;
396
+ /** Upload a .tar/.tar.gz through the Files API, then import it as a harbor benchmark. */
397
+ upload(params: UploadEvalBenchmarkParams, options?: Anthropic.RequestOptions): Promise<EvalBenchmark>;
398
+ }
399
+ export declare class EvalRunsResource {
400
+ private readonly client;
401
+ constructor(client: Anthropic);
402
+ create(params: CreateEvalRunRequest, options?: Anthropic.RequestOptions): import("@anthropic-ai/sdk").APIPromise<CreateEvalRunResponse>;
403
+ list(params?: EvalRunListParams, options?: Anthropic.RequestOptions): import("@anthropic-ai/sdk").APIPromise<EvalRunListResponse>;
404
+ retrieve(id: string, options?: Anthropic.RequestOptions): import("@anthropic-ai/sdk").APIPromise<EvalRun>;
405
+ cancel(id: string, options?: Anthropic.RequestOptions): import("@anthropic-ai/sdk").APIPromise<EvalRun>;
406
+ delete(id: string, options?: Anthropic.RequestOptions): import("@anthropic-ai/sdk").APIPromise<EvalRunDeleted>;
407
+ /** Poll until the run is completed, failed or cancelled; resolves with the terminal run. */
408
+ waitForRun(id: string, opts?: WaitForEvalRunOptions): Promise<EvalRun>;
409
+ }
410
+ export declare class EvalsResource {
411
+ private readonly client;
412
+ readonly benchmarks: EvalBenchmarksResource;
413
+ readonly runs: EvalRunsResource;
414
+ constructor(client: Anthropic);
415
+ /** Branches and tags of a github.com / huggingface.co repository, to pick a git source's ref. */
416
+ gitRefs(params: {
417
+ url: string;
418
+ }, options?: Anthropic.RequestOptions): import("@anthropic-ai/sdk").APIPromise<EvalGitRefList>;
419
+ }
package/dist/evals.js ADDED
@@ -0,0 +1,186 @@
1
+ import Anthropic, { toFile } from "@anthropic-ai/sdk";
2
+ import { withRetryPolicy } from "./platform/http.js";
3
+ export const EVAL_RUN_TERMINAL_STATUSES = ["completed", "failed", "cancelled"];
4
+ const MANAGED_AGENTS_BETA = "managed-agents-2026-04-01";
5
+ const ARCHIVE_NAME = /\.(tar|tar\.gz|tgz)$/i;
6
+ /** Add the Managed Agents beta header unless the caller already set one. */
7
+ function withBeta(options) {
8
+ const headers = options?.headers;
9
+ if (headers == null)
10
+ return { ...options, headers: { "anthropic-beta": MANAGED_AGENTS_BETA } };
11
+ if (headers instanceof Headers) {
12
+ const merged = new Headers(headers);
13
+ if (!merged.has("anthropic-beta"))
14
+ merged.set("anthropic-beta", MANAGED_AGENTS_BETA);
15
+ return { ...options, headers: merged };
16
+ }
17
+ if (Array.isArray(headers)) {
18
+ const has = headers.some((h) => String(h[0]).toLowerCase() === "anthropic-beta");
19
+ return { ...options, headers: has ? headers : [["anthropic-beta", MANAGED_AGENTS_BETA], ...headers] };
20
+ }
21
+ const record = headers;
22
+ const has = Object.keys(record).some((k) => k.toLowerCase() === "anthropic-beta");
23
+ return { ...options, headers: has ? headers : { "anthropic-beta": MANAGED_AGENTS_BETA, ...record } };
24
+ }
25
+ function enc(id) {
26
+ if (typeof id !== "string" || id.length === 0)
27
+ throw new TypeError("id must be a non-empty string");
28
+ return encodeURIComponent(id);
29
+ }
30
+ /** GET query for an optional revision; omitted when unset. */
31
+ function revisionQuery(params) {
32
+ return params?.revision === undefined ? {} : { query: { revision: params.revision } };
33
+ }
34
+ function sleep(ms, signal) {
35
+ return new Promise((resolve, reject) => {
36
+ if (signal?.aborted)
37
+ return reject(signal.reason);
38
+ const timer = setTimeout(() => { signal?.removeEventListener("abort", onAbort); resolve(); }, ms);
39
+ const onAbort = () => { clearTimeout(timer); reject(signal.reason); };
40
+ signal?.addEventListener("abort", onAbort, { once: true });
41
+ });
42
+ }
43
+ /** Upload an archive through the Files API and return its file id. */
44
+ async function uploadArchive(client, params, options) {
45
+ if (!params.filename || !ARCHIVE_NAME.test(params.filename)) {
46
+ throw new TypeError("filename must end in .tar, .tar.gz or .tgz");
47
+ }
48
+ const file = await toFile(params.file, params.filename, {
49
+ type: /\.tar$/i.test(params.filename) ? "application/x-tar" : "application/gzip",
50
+ });
51
+ const uploaded = await client.beta.files.upload(
52
+ // The Files API checks its own beta flag in addition to ours.
53
+ { file, betas: [MANAGED_AGENTS_BETA, "files-api-2025-04-14"] }, options);
54
+ return uploaded.id;
55
+ }
56
+ /** Cases of one benchmark: /v1/oma/evals/benchmarks/:id/cases. */
57
+ export class EvalCasesResource {
58
+ client;
59
+ constructor(client) {
60
+ this.client = client;
61
+ }
62
+ path(benchmarkId, name) {
63
+ const base = `/v1/oma/evals/benchmarks/${enc(benchmarkId)}/cases`;
64
+ return name === undefined ? base : `${base}/${enc(name)}`;
65
+ }
66
+ /** One case; harbor benchmarks accept { revision } (default latest). */
67
+ retrieve(benchmarkId, name, params = {}, options) {
68
+ return this.client.get(this.path(benchmarkId, name), { ...revisionQuery(params), ...withBeta(options) });
69
+ }
70
+ /** messages benchmarks only (harbor cases are read-only; sync the benchmark instead). */
71
+ add(benchmarkId, params, options) {
72
+ return this.client.post(this.path(benchmarkId), withRetryPolicy("post", { body: params, ...withBeta(options) }));
73
+ }
74
+ /** messages benchmarks only. */
75
+ replace(benchmarkId, name, params, options) {
76
+ return this.client.put(this.path(benchmarkId, name), { body: params, ...withBeta(options) });
77
+ }
78
+ /** messages benchmarks only. */
79
+ delete(benchmarkId, name, options) {
80
+ return this.client.delete(this.path(benchmarkId, name), withBeta(options));
81
+ }
82
+ }
83
+ export class EvalBenchmarksResource {
84
+ client;
85
+ cases;
86
+ constructor(client) {
87
+ this.client = client;
88
+ this.cases = new EvalCasesResource(client);
89
+ }
90
+ list(options) {
91
+ return this.client.get("/v1/oma/evals/benchmarks", withBeta(options));
92
+ }
93
+ listBuiltin(options) {
94
+ return this.client.get("/v1/oma/evals/benchmarks/builtin", withBeta(options));
95
+ }
96
+ /** Import a harbor benchmark from a source (revision 1), or create a messages benchmark. */
97
+ create(params, options) {
98
+ return this.client.post("/v1/oma/evals/benchmarks", withRetryPolicy("post", { body: params, ...withBeta(options) }));
99
+ }
100
+ /** With cases (of { revision }, default latest) and, for harbor, its revisions. */
101
+ retrieve(id, params = {}, options) {
102
+ return this.client.get(`/v1/oma/evals/benchmarks/${enc(id)}`, { ...revisionQuery(params), ...withBeta(options) });
103
+ }
104
+ /** harbor: re-read the source; a new revision is made only when content changed.
105
+ * git sources accept { ref }; upload sources need { file_id } (see syncUpload). */
106
+ sync(id, params = {}, options) {
107
+ return this.client.post(`/v1/oma/evals/benchmarks/${enc(id)}/sync`, withRetryPolicy("post", { body: params, ...withBeta(options) }));
108
+ }
109
+ /** harbor upload benchmark: upload a new .tar/.tar.gz through the Files API, then sync from it. */
110
+ async syncUpload(id, params, options) {
111
+ enc(id);
112
+ const fileId = await uploadArchive(this.client, params, options);
113
+ return this.sync(id, { file_id: fileId }, options);
114
+ }
115
+ update(id, params, options) {
116
+ return this.client.patch(`/v1/oma/evals/benchmarks/${enc(id)}`, { body: params, ...withBeta(options) });
117
+ }
118
+ delete(id, options) {
119
+ return this.client.delete(`/v1/oma/evals/benchmarks/${enc(id)}`, withBeta(options));
120
+ }
121
+ /** Upload a .tar/.tar.gz through the Files API, then import it as a harbor benchmark. */
122
+ async upload(params, options) {
123
+ const fileId = await uploadArchive(this.client, params, options);
124
+ return this.create({
125
+ ...(params.name ? { name: params.name } : {}),
126
+ source: { type: "upload", file_id: fileId },
127
+ ...(params.case_names?.length ? { case_names: params.case_names } : {}),
128
+ }, options);
129
+ }
130
+ }
131
+ export class EvalRunsResource {
132
+ client;
133
+ constructor(client) {
134
+ this.client = client;
135
+ }
136
+ create(params, options) {
137
+ return this.client.post("/v1/oma/evals/runs", withRetryPolicy("post", { body: params, ...withBeta(options) }));
138
+ }
139
+ list(params = {}, options) {
140
+ return this.client.get("/v1/oma/evals/runs", { query: params, ...withBeta(options) });
141
+ }
142
+ retrieve(id, options) {
143
+ return this.client.get(`/v1/oma/evals/runs/${enc(id)}`, withBeta(options));
144
+ }
145
+ cancel(id, options) {
146
+ return this.client.post(`/v1/oma/evals/runs/${enc(id)}/cancel`, withRetryPolicy("post", withBeta(options)));
147
+ }
148
+ delete(id, options) {
149
+ return this.client.delete(`/v1/oma/evals/runs/${enc(id)}`, withBeta(options));
150
+ }
151
+ /** Poll until the run is completed, failed or cancelled; resolves with the terminal run. */
152
+ async waitForRun(id, opts = {}) {
153
+ const intervalMs = opts.intervalMs ?? 5000;
154
+ if (!(intervalMs >= 0))
155
+ throw new RangeError("intervalMs must be >= 0");
156
+ if (opts.timeoutMs !== undefined && !(opts.timeoutMs > 0))
157
+ throw new RangeError("timeoutMs must be > 0");
158
+ const deadline = opts.timeoutMs !== undefined ? Date.now() + opts.timeoutMs : Infinity;
159
+ for (;;) {
160
+ const signal = opts.signal ?? opts.requestOptions?.signal ?? undefined;
161
+ const run = await this.retrieve(id, { ...opts.requestOptions, ...(signal ? { signal } : {}) });
162
+ opts.onProgress?.(run);
163
+ if (EVAL_RUN_TERMINAL_STATUSES.includes(run.status))
164
+ return run;
165
+ const remaining = deadline - Date.now();
166
+ if (remaining <= 0) {
167
+ throw new Error(`Timed out after ${opts.timeoutMs} ms waiting for eval run ${id} (status: ${run.status})`);
168
+ }
169
+ await sleep(Math.min(intervalMs, remaining), opts.signal);
170
+ }
171
+ }
172
+ }
173
+ export class EvalsResource {
174
+ client;
175
+ benchmarks;
176
+ runs;
177
+ constructor(client) {
178
+ this.client = client;
179
+ this.benchmarks = new EvalBenchmarksResource(client);
180
+ this.runs = new EvalRunsResource(client);
181
+ }
182
+ /** Branches and tags of a github.com / huggingface.co repository, to pick a git source's ref. */
183
+ gitRefs(params, options) {
184
+ return this.client.get("/v1/oma/evals/git-refs", { query: { url: params.url }, ...withBeta(options) });
185
+ }
186
+ }