@omnara/sdk 0.1.42 → 0.1.44

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,1604 @@
1
+ import {
2
+ zError
3
+ } from "./chunk-BUM22BVJ.js";
4
+
5
+ // src/json-body.ts
6
+ import * as z from "zod";
7
+ var zJsonBody = z.json();
8
+ var zJsonText = z.string().transform((text, ctx) => {
9
+ try {
10
+ const value = JSON.parse(text);
11
+ return value;
12
+ } catch (error) {
13
+ ctx.addIssue({ code: "custom", message: String(error), input: text, params: { cause: error } });
14
+ return z.NEVER;
15
+ }
16
+ });
17
+
18
+ // src/errors.ts
19
+ import * as z3 from "zod";
20
+
21
+ // src/validate-response.ts
22
+ import * as z2 from "zod";
23
+ var zStringInput = z2.string();
24
+ function isStringInput(issue) {
25
+ return zStringInput.safeParse(issue.input).success;
26
+ }
27
+ function hasStringDiscriminator(issue) {
28
+ if (issue.discriminator === void 0) return isStringInput(issue);
29
+ return z2.object({ [issue.discriminator]: zStringInput }).safeParse(issue.input).success;
30
+ }
31
+ function samePath(a, b) {
32
+ return a.length === b.length && a.every((segment, index) => segment === b[index]);
33
+ }
34
+ function isUnknownEnumIssue(issue) {
35
+ if (issue.code === "invalid_value") return isStringInput(issue);
36
+ if (issue.code !== "invalid_union") return false;
37
+ if (issue.errors.length === 0) return hasStringDiscriminator(issue);
38
+ if (issue.errors.some((arm) => arm.every(isUnknownEnumIssue))) {
39
+ return true;
40
+ }
41
+ const [first, ...rest] = issue.errors;
42
+ return (first ?? []).some(
43
+ (candidate) => candidate.code === "invalid_value" && isStringInput(candidate) && rest.every(
44
+ (arm) => arm.some((other) => other.code === "invalid_value" && samePath(other.path, candidate.path))
45
+ )
46
+ );
47
+ }
48
+ function isUnknownEnumError(error) {
49
+ return error.issues.every(isUnknownEnumIssue);
50
+ }
51
+ function relaxedSchema(schema) {
52
+ return z2.custom().superRefine((value, ctx) => {
53
+ const result = schema.safeParse(value, { reportInput: true });
54
+ if (result.success || isUnknownEnumError(result.error)) return;
55
+ for (const issue of result.error.issues) ctx.addIssue({ ...issue });
56
+ });
57
+ }
58
+ function relaxedResponseValidator(schema) {
59
+ return async (data) => {
60
+ const result = await schema.safeParseAsync(data, { reportInput: true });
61
+ if (result.success || isUnknownEnumError(result.error)) return;
62
+ throw result.error;
63
+ };
64
+ }
65
+
66
+ // src/errors.ts
67
+ var zErrorBody = zJsonText.pipe(zJsonBody);
68
+ var zErrorResponse = relaxedSchema(
69
+ zError.partial({ code: true }).extend({ error_description: z3.string().optional() })
70
+ );
71
+ var ApiError = class _ApiError extends Error {
72
+ status;
73
+ code;
74
+ body;
75
+ issues;
76
+ currentDigest;
77
+ retryAfterMs;
78
+ constructor(status, message, code, body, retryAfterMs) {
79
+ super(message);
80
+ this.name = "ApiError";
81
+ this.status = status;
82
+ this.code = code;
83
+ this.body = body;
84
+ const parsed = zErrorResponse.safeParse(body);
85
+ this.issues = parsed.data?.issues ?? [];
86
+ this.currentDigest = parsed.data?.current_digest;
87
+ this.retryAfterMs = retryAfterMs;
88
+ }
89
+ static async fromResponse(response) {
90
+ const body = zErrorBody.safeParse(await response.clone().text());
91
+ return _ApiError.fromBody(
92
+ response.status,
93
+ body.success ? body.data : void 0,
94
+ parseRetryAfter(response.headers.get("Retry-After"))
95
+ );
96
+ }
97
+ static fromBody(status, body, retryAfterMs) {
98
+ const parsed = zErrorResponse.safeParse(body);
99
+ const message = parsed.data?.error_description ?? parsed.data?.error ?? `request failed with status ${status}`;
100
+ return new _ApiError(status, message, parsed.data?.code, body, retryAfterMs);
101
+ }
102
+ };
103
+ function parseRetryAfter(value) {
104
+ if (value == null) return void 0;
105
+ const trimmed = value.trim();
106
+ if (/^\d+$/.test(trimmed)) return Number.parseInt(trimmed, 10) * 1e3;
107
+ const at = Date.parse(trimmed);
108
+ if (Number.isNaN(at)) return void 0;
109
+ return Math.max(at - Date.now(), 0);
110
+ }
111
+
112
+ // src/client.ts
113
+ import * as z4 from "zod";
114
+
115
+ // src/generated/core/bodySerializer.gen.ts
116
+ var serializeFormDataPair = (data, key, value) => {
117
+ if (typeof value === "string" || value instanceof Blob) {
118
+ data.append(key, value);
119
+ } else if (value instanceof Date) {
120
+ data.append(key, value.toISOString());
121
+ } else {
122
+ data.append(key, JSON.stringify(value));
123
+ }
124
+ };
125
+ var formDataBodySerializer = {
126
+ bodySerializer: (body) => {
127
+ const data = new FormData();
128
+ Object.entries(body).forEach(([key, value]) => {
129
+ if (value === void 0 || value === null) {
130
+ return;
131
+ }
132
+ if (Array.isArray(value)) {
133
+ value.forEach((v) => serializeFormDataPair(data, key, v));
134
+ } else {
135
+ serializeFormDataPair(data, key, value);
136
+ }
137
+ });
138
+ return data;
139
+ }
140
+ };
141
+ var jsonBodySerializer = {
142
+ bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
143
+ };
144
+
145
+ // src/generated/core/params.gen.ts
146
+ var extraPrefixesMap = {
147
+ $body_: "body",
148
+ $headers_: "headers",
149
+ $path_: "path",
150
+ $query_: "query"
151
+ };
152
+ var extraPrefixes = Object.entries(extraPrefixesMap);
153
+
154
+ // src/generated/core/serverSentEvents.gen.ts
155
+ function createSseClient({
156
+ onRequest,
157
+ onSseError,
158
+ onSseEvent,
159
+ responseTransformer,
160
+ responseValidator,
161
+ sseDefaultRetryDelay,
162
+ sseMaxRetryAttempts,
163
+ sseMaxRetryDelay,
164
+ sseSleepFn,
165
+ url,
166
+ ...options
167
+ }) {
168
+ let lastEventId;
169
+ const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
170
+ const createStream = async function* () {
171
+ let retryDelay2 = sseDefaultRetryDelay ?? 3e3;
172
+ let attempt = 0;
173
+ const signal = options.signal ?? new AbortController().signal;
174
+ while (true) {
175
+ if (signal.aborted) break;
176
+ attempt++;
177
+ const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
178
+ if (lastEventId !== void 0) {
179
+ headers.set("Last-Event-ID", lastEventId);
180
+ }
181
+ try {
182
+ const requestInit = {
183
+ redirect: "follow",
184
+ ...options,
185
+ body: options.serializedBody,
186
+ headers,
187
+ signal
188
+ };
189
+ let request = new Request(url, requestInit);
190
+ if (onRequest) {
191
+ request = await onRequest(url, requestInit);
192
+ }
193
+ const _fetch = options.fetch ?? globalThis.fetch;
194
+ const response = await _fetch(request);
195
+ if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
196
+ if (!response.body) throw new Error("No body in SSE response");
197
+ const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
198
+ let buffer = "";
199
+ const abortHandler = () => {
200
+ try {
201
+ reader.cancel();
202
+ } catch {
203
+ }
204
+ };
205
+ signal.addEventListener("abort", abortHandler);
206
+ try {
207
+ while (true) {
208
+ const { done, value } = await reader.read();
209
+ if (done) break;
210
+ buffer += value;
211
+ buffer = buffer.replace(/\r\n?/g, "\n");
212
+ const chunks = buffer.split("\n\n");
213
+ buffer = chunks.pop() ?? "";
214
+ for (const chunk of chunks) {
215
+ const lines = chunk.split("\n");
216
+ const dataLines = [];
217
+ let eventName;
218
+ for (const line of lines) {
219
+ if (line.startsWith("data:")) {
220
+ dataLines.push(line.replace(/^data:\s*/, ""));
221
+ } else if (line.startsWith("event:")) {
222
+ eventName = line.replace(/^event:\s*/, "");
223
+ } else if (line.startsWith("id:")) {
224
+ lastEventId = line.replace(/^id:\s*/, "");
225
+ } else if (line.startsWith("retry:")) {
226
+ const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
227
+ if (!Number.isNaN(parsed)) {
228
+ retryDelay2 = parsed;
229
+ }
230
+ }
231
+ }
232
+ let data;
233
+ let parsedJson = false;
234
+ if (dataLines.length) {
235
+ const rawData = dataLines.join("\n");
236
+ try {
237
+ data = JSON.parse(rawData);
238
+ parsedJson = true;
239
+ } catch {
240
+ data = rawData;
241
+ }
242
+ }
243
+ if (parsedJson) {
244
+ if (responseValidator) {
245
+ await responseValidator(data);
246
+ }
247
+ if (responseTransformer) {
248
+ data = await responseTransformer(data);
249
+ }
250
+ }
251
+ onSseEvent?.({
252
+ data,
253
+ event: eventName,
254
+ id: lastEventId,
255
+ retry: retryDelay2
256
+ });
257
+ if (dataLines.length) {
258
+ yield data;
259
+ }
260
+ }
261
+ }
262
+ } finally {
263
+ signal.removeEventListener("abort", abortHandler);
264
+ reader.releaseLock();
265
+ }
266
+ break;
267
+ } catch (error) {
268
+ onSseError?.(error);
269
+ if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
270
+ break;
271
+ }
272
+ const backoff = Math.min(retryDelay2 * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
273
+ await sleep(backoff);
274
+ }
275
+ }
276
+ };
277
+ const stream = createStream();
278
+ return { stream };
279
+ }
280
+
281
+ // src/generated/core/pathSerializer.gen.ts
282
+ var separatorArrayExplode = (style) => {
283
+ switch (style) {
284
+ case "label":
285
+ return ".";
286
+ case "matrix":
287
+ return ";";
288
+ case "simple":
289
+ return ",";
290
+ default:
291
+ return "&";
292
+ }
293
+ };
294
+ var separatorArrayNoExplode = (style) => {
295
+ switch (style) {
296
+ case "form":
297
+ return ",";
298
+ case "pipeDelimited":
299
+ return "|";
300
+ case "spaceDelimited":
301
+ return "%20";
302
+ default:
303
+ return ",";
304
+ }
305
+ };
306
+ var separatorObjectExplode = (style) => {
307
+ switch (style) {
308
+ case "label":
309
+ return ".";
310
+ case "matrix":
311
+ return ";";
312
+ case "simple":
313
+ return ",";
314
+ default:
315
+ return "&";
316
+ }
317
+ };
318
+ var serializeArrayParam = ({
319
+ allowReserved,
320
+ explode,
321
+ name,
322
+ style,
323
+ value
324
+ }) => {
325
+ if (!explode) {
326
+ const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
327
+ switch (style) {
328
+ case "label":
329
+ return `.${joinedValues2}`;
330
+ case "matrix":
331
+ return `;${name}=${joinedValues2}`;
332
+ case "simple":
333
+ return joinedValues2;
334
+ default:
335
+ return `${name}=${joinedValues2}`;
336
+ }
337
+ }
338
+ const separator = separatorArrayExplode(style);
339
+ const joinedValues = value.map((v) => {
340
+ if (style === "label" || style === "simple") {
341
+ return allowReserved ? v : encodeURIComponent(v);
342
+ }
343
+ return serializePrimitiveParam({
344
+ allowReserved,
345
+ name,
346
+ value: v
347
+ });
348
+ }).join(separator);
349
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
350
+ };
351
+ var serializePrimitiveParam = ({
352
+ allowReserved,
353
+ name,
354
+ value
355
+ }) => {
356
+ if (value === void 0 || value === null) {
357
+ return "";
358
+ }
359
+ if (typeof value === "object") {
360
+ throw new Error(
361
+ "Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
362
+ );
363
+ }
364
+ return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
365
+ };
366
+ var serializeObjectParam = ({
367
+ allowReserved,
368
+ explode,
369
+ name,
370
+ style,
371
+ value,
372
+ valueOnly
373
+ }) => {
374
+ if (value instanceof Date) {
375
+ return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
376
+ }
377
+ if (style !== "deepObject" && !explode) {
378
+ let values = [];
379
+ Object.entries(value).forEach(([key, v]) => {
380
+ values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
381
+ });
382
+ const joinedValues2 = values.join(",");
383
+ switch (style) {
384
+ case "form":
385
+ return `${name}=${joinedValues2}`;
386
+ case "label":
387
+ return `.${joinedValues2}`;
388
+ case "matrix":
389
+ return `;${name}=${joinedValues2}`;
390
+ default:
391
+ return joinedValues2;
392
+ }
393
+ }
394
+ const separator = separatorObjectExplode(style);
395
+ const joinedValues = Object.entries(value).map(
396
+ ([key, v]) => serializePrimitiveParam({
397
+ allowReserved,
398
+ name: style === "deepObject" ? `${name}[${key}]` : key,
399
+ value: v
400
+ })
401
+ ).join(separator);
402
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
403
+ };
404
+
405
+ // src/generated/core/utils.gen.ts
406
+ var PATH_PARAM_RE = /\{[^{}]+\}/g;
407
+ var defaultPathSerializer = ({ path, url: _url }) => {
408
+ let url = _url;
409
+ const matches = _url.match(PATH_PARAM_RE);
410
+ if (matches) {
411
+ for (const match of matches) {
412
+ let explode = false;
413
+ let name = match.substring(1, match.length - 1);
414
+ let style = "simple";
415
+ if (name.endsWith("*")) {
416
+ explode = true;
417
+ name = name.substring(0, name.length - 1);
418
+ }
419
+ if (name.startsWith(".")) {
420
+ name = name.substring(1);
421
+ style = "label";
422
+ } else if (name.startsWith(";")) {
423
+ name = name.substring(1);
424
+ style = "matrix";
425
+ }
426
+ const value = path[name];
427
+ if (value === void 0 || value === null) {
428
+ continue;
429
+ }
430
+ if (Array.isArray(value)) {
431
+ url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
432
+ continue;
433
+ }
434
+ if (typeof value === "object") {
435
+ url = url.replace(
436
+ match,
437
+ serializeObjectParam({
438
+ explode,
439
+ name,
440
+ style,
441
+ value,
442
+ valueOnly: true
443
+ })
444
+ );
445
+ continue;
446
+ }
447
+ if (style === "matrix") {
448
+ url = url.replace(
449
+ match,
450
+ `;${serializePrimitiveParam({
451
+ name,
452
+ value
453
+ })}`
454
+ );
455
+ continue;
456
+ }
457
+ const replaceValue = encodeURIComponent(
458
+ style === "label" ? `.${value}` : value
459
+ );
460
+ url = url.replace(match, replaceValue);
461
+ }
462
+ }
463
+ return url;
464
+ };
465
+ var getUrl = ({
466
+ baseUrl,
467
+ path,
468
+ query,
469
+ querySerializer,
470
+ url: _url
471
+ }) => {
472
+ const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
473
+ let url = (baseUrl ?? "") + pathUrl;
474
+ if (path) {
475
+ url = defaultPathSerializer({ path, url });
476
+ }
477
+ let search = query ? querySerializer(query) : "";
478
+ if (search.startsWith("?")) {
479
+ search = search.substring(1);
480
+ }
481
+ if (search) {
482
+ url += `?${search}`;
483
+ }
484
+ return url;
485
+ };
486
+ function getValidRequestBody(options) {
487
+ const hasBody = options.body !== void 0;
488
+ const isSerializedBody = hasBody && options.bodySerializer;
489
+ if (isSerializedBody) {
490
+ if ("serializedBody" in options) {
491
+ const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
492
+ return hasSerializedBody ? options.serializedBody : null;
493
+ }
494
+ return options.body !== "" ? options.body : null;
495
+ }
496
+ if (hasBody) {
497
+ return options.body;
498
+ }
499
+ return void 0;
500
+ }
501
+
502
+ // src/generated/core/auth.gen.ts
503
+ var getAuthToken = async (auth, callback) => {
504
+ const token = typeof callback === "function" ? await callback(auth) : callback;
505
+ if (!token) {
506
+ return;
507
+ }
508
+ if (auth.scheme === "bearer") {
509
+ return `Bearer ${token}`;
510
+ }
511
+ if (auth.scheme === "basic") {
512
+ return `Basic ${btoa(token)}`;
513
+ }
514
+ return token;
515
+ };
516
+
517
+ // src/generated/client/utils.gen.ts
518
+ var createQuerySerializer = ({
519
+ parameters = {},
520
+ ...args
521
+ } = {}) => {
522
+ const querySerializer = (queryParams) => {
523
+ const search = [];
524
+ if (queryParams && typeof queryParams === "object") {
525
+ for (const name in queryParams) {
526
+ const value = queryParams[name];
527
+ if (value === void 0 || value === null) {
528
+ continue;
529
+ }
530
+ const options = parameters[name] || args;
531
+ if (Array.isArray(value)) {
532
+ const serializedArray = serializeArrayParam({
533
+ allowReserved: options.allowReserved,
534
+ explode: true,
535
+ name,
536
+ style: "form",
537
+ value,
538
+ ...options.array
539
+ });
540
+ if (serializedArray) search.push(serializedArray);
541
+ } else if (typeof value === "object") {
542
+ const serializedObject = serializeObjectParam({
543
+ allowReserved: options.allowReserved,
544
+ explode: true,
545
+ name,
546
+ style: "deepObject",
547
+ value,
548
+ ...options.object
549
+ });
550
+ if (serializedObject) search.push(serializedObject);
551
+ } else {
552
+ const serializedPrimitive = serializePrimitiveParam({
553
+ allowReserved: options.allowReserved,
554
+ name,
555
+ value
556
+ });
557
+ if (serializedPrimitive) search.push(serializedPrimitive);
558
+ }
559
+ }
560
+ }
561
+ return search.join("&");
562
+ };
563
+ return querySerializer;
564
+ };
565
+ var getParseAs = (contentType) => {
566
+ if (!contentType) {
567
+ return "stream";
568
+ }
569
+ const cleanContent = contentType.split(";")[0]?.trim();
570
+ if (!cleanContent) {
571
+ return;
572
+ }
573
+ if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
574
+ return "json";
575
+ }
576
+ if (cleanContent === "multipart/form-data") {
577
+ return "formData";
578
+ }
579
+ if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
580
+ return "blob";
581
+ }
582
+ if (cleanContent.startsWith("text/")) {
583
+ return "text";
584
+ }
585
+ return;
586
+ };
587
+ var checkForExistence = (options, name) => {
588
+ if (!name) {
589
+ return false;
590
+ }
591
+ if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
592
+ return true;
593
+ }
594
+ return false;
595
+ };
596
+ async function setAuthParams(options) {
597
+ for (const auth of options.security ?? []) {
598
+ if (checkForExistence(options, auth.name)) {
599
+ continue;
600
+ }
601
+ const token = await getAuthToken(auth, options.auth);
602
+ if (!token) {
603
+ continue;
604
+ }
605
+ const name = auth.name ?? "Authorization";
606
+ switch (auth.in) {
607
+ case "query":
608
+ if (!options.query) {
609
+ options.query = {};
610
+ }
611
+ options.query[name] = token;
612
+ break;
613
+ case "cookie":
614
+ options.headers.append("Cookie", `${name}=${token}`);
615
+ break;
616
+ case "header":
617
+ default:
618
+ options.headers.set(name, token);
619
+ break;
620
+ }
621
+ }
622
+ }
623
+ var buildUrl = (options) => getUrl({
624
+ baseUrl: options.baseUrl,
625
+ path: options.path,
626
+ query: options.query,
627
+ querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
628
+ url: options.url
629
+ });
630
+ var mergeConfigs = (a, b) => {
631
+ const config = { ...a, ...b };
632
+ if (config.baseUrl?.endsWith("/")) {
633
+ config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
634
+ }
635
+ config.headers = mergeHeaders(a.headers, b.headers);
636
+ return config;
637
+ };
638
+ var headersEntries = (headers) => {
639
+ const entries = [];
640
+ headers.forEach((value, key) => {
641
+ entries.push([key, value]);
642
+ });
643
+ return entries;
644
+ };
645
+ var mergeHeaders = (...headers) => {
646
+ const mergedHeaders = new Headers();
647
+ for (const header of headers) {
648
+ if (!header) {
649
+ continue;
650
+ }
651
+ const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
652
+ for (const [key, value] of iterator) {
653
+ if (value === null) {
654
+ mergedHeaders.delete(key);
655
+ } else if (Array.isArray(value)) {
656
+ for (const v of value) {
657
+ mergedHeaders.append(key, v);
658
+ }
659
+ } else if (value !== void 0) {
660
+ mergedHeaders.set(
661
+ key,
662
+ typeof value === "object" ? JSON.stringify(value) : value
663
+ );
664
+ }
665
+ }
666
+ }
667
+ return mergedHeaders;
668
+ };
669
+ var Interceptors = class {
670
+ fns = [];
671
+ clear() {
672
+ this.fns = [];
673
+ }
674
+ eject(id) {
675
+ const index = this.getInterceptorIndex(id);
676
+ if (this.fns[index]) {
677
+ this.fns[index] = null;
678
+ }
679
+ }
680
+ exists(id) {
681
+ const index = this.getInterceptorIndex(id);
682
+ return Boolean(this.fns[index]);
683
+ }
684
+ getInterceptorIndex(id) {
685
+ if (typeof id === "number") {
686
+ return this.fns[id] ? id : -1;
687
+ }
688
+ return this.fns.indexOf(id);
689
+ }
690
+ update(id, fn) {
691
+ const index = this.getInterceptorIndex(id);
692
+ if (this.fns[index]) {
693
+ this.fns[index] = fn;
694
+ return id;
695
+ }
696
+ return false;
697
+ }
698
+ use(fn) {
699
+ this.fns.push(fn);
700
+ return this.fns.length - 1;
701
+ }
702
+ };
703
+ var createInterceptors = () => ({
704
+ error: new Interceptors(),
705
+ request: new Interceptors(),
706
+ response: new Interceptors()
707
+ });
708
+ var defaultQuerySerializer = createQuerySerializer({
709
+ allowReserved: false,
710
+ array: {
711
+ explode: true,
712
+ style: "form"
713
+ },
714
+ object: {
715
+ explode: true,
716
+ style: "deepObject"
717
+ }
718
+ });
719
+ var defaultHeaders = {
720
+ "Content-Type": "application/json"
721
+ };
722
+ var createConfig = (override = {}) => ({
723
+ ...jsonBodySerializer,
724
+ headers: defaultHeaders,
725
+ parseAs: "auto",
726
+ querySerializer: defaultQuerySerializer,
727
+ ...override
728
+ });
729
+
730
+ // src/generated/client/client.gen.ts
731
+ var createClient = (config = {}) => {
732
+ let _config = mergeConfigs(createConfig(), config);
733
+ const getConfig = () => ({ ..._config });
734
+ const setConfig = (config2) => {
735
+ _config = mergeConfigs(_config, config2);
736
+ return getConfig();
737
+ };
738
+ const interceptors = createInterceptors();
739
+ const beforeRequest = async (options) => {
740
+ const opts = {
741
+ ..._config,
742
+ ...options,
743
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
744
+ headers: mergeHeaders(_config.headers, options.headers),
745
+ serializedBody: void 0
746
+ };
747
+ if (opts.security) {
748
+ await setAuthParams(opts);
749
+ }
750
+ if (opts.requestValidator) {
751
+ await opts.requestValidator(opts);
752
+ }
753
+ if (opts.body !== void 0 && opts.bodySerializer) {
754
+ opts.serializedBody = opts.bodySerializer(opts.body);
755
+ }
756
+ if (opts.body === void 0 || opts.serializedBody === "") {
757
+ opts.headers.delete("Content-Type");
758
+ }
759
+ const resolvedOpts = opts;
760
+ const url = buildUrl(resolvedOpts);
761
+ return { opts: resolvedOpts, url };
762
+ };
763
+ const request = async (options) => {
764
+ const throwOnError = options.throwOnError ?? _config.throwOnError;
765
+ const responseStyle = options.responseStyle ?? _config.responseStyle;
766
+ let request2;
767
+ let response;
768
+ try {
769
+ const { opts, url } = await beforeRequest(options);
770
+ const requestInit = {
771
+ redirect: "follow",
772
+ ...opts,
773
+ body: getValidRequestBody(opts)
774
+ };
775
+ request2 = new Request(url, requestInit);
776
+ for (const fn of interceptors.request.fns) {
777
+ if (fn) {
778
+ request2 = await fn(request2, opts);
779
+ }
780
+ }
781
+ const _fetch = opts.fetch;
782
+ response = await _fetch(request2);
783
+ for (const fn of interceptors.response.fns) {
784
+ if (fn) {
785
+ response = await fn(response, request2, opts);
786
+ }
787
+ }
788
+ const result = {
789
+ request: request2,
790
+ response
791
+ };
792
+ if (response.ok) {
793
+ const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
794
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
795
+ let emptyData;
796
+ switch (parseAs) {
797
+ case "arrayBuffer":
798
+ case "blob":
799
+ case "text":
800
+ emptyData = await response[parseAs]();
801
+ break;
802
+ case "formData":
803
+ emptyData = new FormData();
804
+ break;
805
+ case "stream":
806
+ emptyData = response.body;
807
+ break;
808
+ case "json":
809
+ default:
810
+ emptyData = {};
811
+ break;
812
+ }
813
+ return opts.responseStyle === "data" ? emptyData : {
814
+ data: emptyData,
815
+ ...result
816
+ };
817
+ }
818
+ let data;
819
+ switch (parseAs) {
820
+ case "arrayBuffer":
821
+ case "blob":
822
+ case "formData":
823
+ case "text":
824
+ data = await response[parseAs]();
825
+ break;
826
+ case "json": {
827
+ const text = await response.text();
828
+ data = text ? JSON.parse(text) : {};
829
+ break;
830
+ }
831
+ case "stream":
832
+ return opts.responseStyle === "data" ? response.body : {
833
+ data: response.body,
834
+ ...result
835
+ };
836
+ }
837
+ if (parseAs === "json") {
838
+ if (opts.responseValidator) {
839
+ await opts.responseValidator(data);
840
+ }
841
+ if (opts.responseTransformer) {
842
+ data = await opts.responseTransformer(data);
843
+ }
844
+ }
845
+ return opts.responseStyle === "data" ? data : {
846
+ data,
847
+ ...result
848
+ };
849
+ }
850
+ const textError = await response.text();
851
+ let jsonError;
852
+ try {
853
+ jsonError = JSON.parse(textError);
854
+ } catch {
855
+ }
856
+ throw jsonError ?? textError;
857
+ } catch (error) {
858
+ let finalError = error;
859
+ for (const fn of interceptors.error.fns) {
860
+ if (fn) {
861
+ finalError = await fn(finalError, response, request2, options);
862
+ }
863
+ }
864
+ finalError = finalError || {};
865
+ if (throwOnError) {
866
+ throw finalError;
867
+ }
868
+ return responseStyle === "data" ? void 0 : {
869
+ error: finalError,
870
+ request: request2,
871
+ response
872
+ };
873
+ }
874
+ };
875
+ const makeMethodFn = (method) => (options) => request({ ...options, method });
876
+ const makeSseFn = (method) => async (options) => {
877
+ const { opts, url } = await beforeRequest(options);
878
+ return createSseClient({
879
+ ...opts,
880
+ body: opts.body,
881
+ method,
882
+ onRequest: async (url2, init) => {
883
+ let request2 = new Request(url2, init);
884
+ for (const fn of interceptors.request.fns) {
885
+ if (fn) {
886
+ request2 = await fn(request2, opts);
887
+ }
888
+ }
889
+ return request2;
890
+ },
891
+ serializedBody: getValidRequestBody(opts),
892
+ url
893
+ });
894
+ };
895
+ const _buildUrl = (options) => buildUrl({ ..._config, ...options });
896
+ return {
897
+ buildUrl: _buildUrl,
898
+ connect: makeMethodFn("CONNECT"),
899
+ delete: makeMethodFn("DELETE"),
900
+ get: makeMethodFn("GET"),
901
+ getConfig,
902
+ head: makeMethodFn("HEAD"),
903
+ interceptors,
904
+ options: makeMethodFn("OPTIONS"),
905
+ patch: makeMethodFn("PATCH"),
906
+ post: makeMethodFn("POST"),
907
+ put: makeMethodFn("PUT"),
908
+ request,
909
+ setConfig,
910
+ sse: {
911
+ connect: makeSseFn("CONNECT"),
912
+ delete: makeSseFn("DELETE"),
913
+ get: makeSseFn("GET"),
914
+ head: makeSseFn("HEAD"),
915
+ options: makeSseFn("OPTIONS"),
916
+ patch: makeSseFn("PATCH"),
917
+ post: makeSseFn("POST"),
918
+ put: makeSseFn("PUT"),
919
+ trace: makeSseFn("TRACE")
920
+ },
921
+ trace: makeMethodFn("TRACE")
922
+ };
923
+ };
924
+
925
+ // src/generated/client.gen.ts
926
+ var client = createClient(createConfig({ baseUrl: "https://api.omnara.com/v1", throwOnError: true }));
927
+
928
+ // src/abort.ts
929
+ function forwardAbort(source, target) {
930
+ let attached = false;
931
+ function dispose() {
932
+ if (!attached) return;
933
+ attached = false;
934
+ source?.removeEventListener("abort", abort);
935
+ }
936
+ function abort() {
937
+ dispose();
938
+ target.abort(source?.reason);
939
+ }
940
+ if (source?.aborted) abort();
941
+ else if (source) {
942
+ attached = true;
943
+ source.addEventListener("abort", abort, { once: true });
944
+ }
945
+ return dispose;
946
+ }
947
+ function untilAborted(request, signal) {
948
+ return new Promise((resolve, reject) => {
949
+ const abort = () => {
950
+ signal.removeEventListener("abort", abort);
951
+ reject(signal.reason);
952
+ };
953
+ if (signal.aborted) {
954
+ abort();
955
+ return;
956
+ }
957
+ signal.addEventListener("abort", abort, { once: true });
958
+ Promise.resolve().then(() => {
959
+ signal.throwIfAborted();
960
+ return request();
961
+ }).then(resolve, reject).finally(() => {
962
+ signal.removeEventListener("abort", abort);
963
+ });
964
+ });
965
+ }
966
+
967
+ // src/generated/replay-contracts.gen.ts
968
+ var knownOperations = /* @__PURE__ */ new Set([
969
+ "DELETE /me",
970
+ "DELETE /orgs/{orgID}",
971
+ "DELETE /orgs/{orgID}/api-keys/{keyID}/projects/{projectID}",
972
+ "DELETE /orgs/{orgID}/invitations/{invitationID}",
973
+ "DELETE /orgs/{orgID}/machine-pools/{poolID}",
974
+ "DELETE /orgs/{orgID}/machines/{machineID}",
975
+ "DELETE /orgs/{orgID}/members/{userID}",
976
+ "DELETE /orgs/{orgID}/members/{userID}/projects/{projectID}",
977
+ "DELETE /orgs/{orgID}/model-provider-configs/{modelProviderConfigID}",
978
+ "DELETE /orgs/{orgID}/model-provider-configs/{modelProviderConfigID}/models/{configuredModelID}",
979
+ "DELETE /orgs/{orgID}/projects/{projectID}",
980
+ "DELETE /orgs/{orgID}/projects/{projectID}/agent-profiles/{agentProfileID}",
981
+ "DELETE /orgs/{orgID}/projects/{projectID}/cron-triggers/{cronTriggerID}",
982
+ "DELETE /orgs/{orgID}/projects/{projectID}/event-webhooks/{webhookID}",
983
+ "DELETE /orgs/{orgID}/projects/{projectID}/integrations/{integrationID}",
984
+ "DELETE /orgs/{orgID}/projects/{projectID}/integrations/{integrationID}/subscriptions/{subscriptionID}",
985
+ "DELETE /orgs/{orgID}/projects/{projectID}/machine-grants/{grantID}",
986
+ "DELETE /orgs/{orgID}/projects/{projectID}/machine-pool-grants/{poolGrantID}",
987
+ "DELETE /orgs/{orgID}/projects/{projectID}/memory-stores/{memoryStoreID}",
988
+ "DELETE /orgs/{orgID}/projects/{projectID}/memory-stores/{memoryStoreID}/file",
989
+ "DELETE /orgs/{orgID}/projects/{projectID}/model-grants/{modelGrantID}",
990
+ "DELETE /orgs/{orgID}/secrets/{secretID}",
991
+ "DELETE /orgs/{orgID}/secrets/{secretID}/grants/{grantID}",
992
+ "DELETE /orgs/{orgID}/skills/{skillID}",
993
+ "DELETE /orgs/{orgID}/skills/{skillID}/grants/{grantID}",
994
+ "GET /daemon/processes/{processID}/file",
995
+ "GET /daemon/runtimes/{runtimeID}/socket",
996
+ "GET /daemon/skills/{skillID}/archive",
997
+ "GET /invitations",
998
+ "GET /mcp-servers",
999
+ "GET /me",
1000
+ "GET /orgs",
1001
+ "GET /orgs/{orgID}/agent-profiles",
1002
+ "GET /orgs/{orgID}/agents",
1003
+ "GET /orgs/{orgID}/api-keys",
1004
+ "GET /orgs/{orgID}/api-keys/{keyID}",
1005
+ "GET /orgs/{orgID}/api-keys/{keyID}/projects",
1006
+ "GET /orgs/{orgID}/integrations",
1007
+ "GET /orgs/{orgID}/invitations",
1008
+ "GET /orgs/{orgID}/machine-pools",
1009
+ "GET /orgs/{orgID}/machine-pools/{poolID}",
1010
+ "GET /orgs/{orgID}/machines",
1011
+ "GET /orgs/{orgID}/machines/{machineID}",
1012
+ "GET /orgs/{orgID}/machines/{machineID}/daemon-tokens",
1013
+ "GET /orgs/{orgID}/members",
1014
+ "GET /orgs/{orgID}/members/{userID}/projects",
1015
+ "GET /orgs/{orgID}/memory-stores",
1016
+ "GET /orgs/{orgID}/model-provider-configs",
1017
+ "GET /orgs/{orgID}/model-provider-configs/{modelProviderConfigID}",
1018
+ "GET /orgs/{orgID}/model-provider-configs/{modelProviderConfigID}/model-catalog",
1019
+ "GET /orgs/{orgID}/model-provider-configs/{modelProviderConfigID}/models",
1020
+ "GET /orgs/{orgID}/model-provider-configs/{modelProviderConfigID}/models/{configuredModelID}",
1021
+ "GET /orgs/{orgID}/overview",
1022
+ "GET /orgs/{orgID}/projects",
1023
+ "GET /orgs/{orgID}/projects/{projectID}",
1024
+ "GET /orgs/{orgID}/projects/{projectID}/actors",
1025
+ "GET /orgs/{orgID}/projects/{projectID}/actors/{actorID}",
1026
+ "GET /orgs/{orgID}/projects/{projectID}/agent-configs/{agentConfigID}",
1027
+ "GET /orgs/{orgID}/projects/{projectID}/agent-configs/{agentConfigID}/generated-source",
1028
+ "GET /orgs/{orgID}/projects/{projectID}/agent-profiles",
1029
+ "GET /orgs/{orgID}/projects/{projectID}/agent-profiles/{agentProfileID}",
1030
+ "GET /orgs/{orgID}/projects/{projectID}/agent-profiles/{agentProfileID}/usage",
1031
+ "GET /orgs/{orgID}/projects/{projectID}/agents",
1032
+ "GET /orgs/{orgID}/projects/{projectID}/agents/{agentID}",
1033
+ "GET /orgs/{orgID}/projects/{projectID}/agents/{agentID}/artifacts/{artifactID}",
1034
+ "GET /orgs/{orgID}/projects/{projectID}/agents/{agentID}/artifacts/{artifactID}/content",
1035
+ "GET /orgs/{orgID}/projects/{projectID}/agents/{agentID}/events",
1036
+ "GET /orgs/{orgID}/projects/{projectID}/agents/{agentID}/events/stream",
1037
+ "GET /orgs/{orgID}/projects/{projectID}/agents/{agentID}/inputs/backlog",
1038
+ "GET /orgs/{orgID}/projects/{projectID}/agents/{agentID}/interactions",
1039
+ "GET /orgs/{orgID}/projects/{projectID}/agents/{agentID}/tool-calls",
1040
+ "GET /orgs/{orgID}/projects/{projectID}/agents/{agentID}/tool-calls/{toolCallID}",
1041
+ "GET /orgs/{orgID}/projects/{projectID}/agents/{agentID}/turns",
1042
+ "GET /orgs/{orgID}/projects/{projectID}/agents/{agentID}/turns/{turnID}/events",
1043
+ "GET /orgs/{orgID}/projects/{projectID}/agents/{agentID}/usage",
1044
+ "GET /orgs/{orgID}/projects/{projectID}/cron-triggers",
1045
+ "GET /orgs/{orgID}/projects/{projectID}/cron-triggers/{cronTriggerID}",
1046
+ "GET /orgs/{orgID}/projects/{projectID}/event-webhooks",
1047
+ "GET /orgs/{orgID}/projects/{projectID}/event-webhooks/{webhookID}",
1048
+ "GET /orgs/{orgID}/projects/{projectID}/integration-definitions",
1049
+ "GET /orgs/{orgID}/projects/{projectID}/integrations",
1050
+ "GET /orgs/{orgID}/projects/{projectID}/integrations/{integrationID}",
1051
+ "GET /orgs/{orgID}/projects/{projectID}/integrations/{integrationID}/github-repositories",
1052
+ "GET /orgs/{orgID}/projects/{projectID}/integrations/{integrationID}/subscriptions",
1053
+ "GET /orgs/{orgID}/projects/{projectID}/integrations/{integrationID}/subscriptions/{subscriptionID}",
1054
+ "GET /orgs/{orgID}/projects/{projectID}/interactions",
1055
+ "GET /orgs/{orgID}/projects/{projectID}/machine-grants",
1056
+ "GET /orgs/{orgID}/projects/{projectID}/machine-grants/{grantID}",
1057
+ "GET /orgs/{orgID}/projects/{projectID}/machine-pool-grants",
1058
+ "GET /orgs/{orgID}/projects/{projectID}/machine-pool-grants/{poolGrantID}",
1059
+ "GET /orgs/{orgID}/projects/{projectID}/machines",
1060
+ "GET /orgs/{orgID}/projects/{projectID}/memory-stores",
1061
+ "GET /orgs/{orgID}/projects/{projectID}/memory-stores/{memoryStoreID}",
1062
+ "GET /orgs/{orgID}/projects/{projectID}/memory-stores/{memoryStoreID}/file",
1063
+ "GET /orgs/{orgID}/projects/{projectID}/memory-stores/{memoryStoreID}/files",
1064
+ "GET /orgs/{orgID}/projects/{projectID}/model-grants",
1065
+ "GET /orgs/{orgID}/projects/{projectID}/model-grants/{modelGrantID}",
1066
+ "GET /orgs/{orgID}/projects/{projectID}/secrets",
1067
+ "GET /orgs/{orgID}/projects/{projectID}/secrets/{secretID}",
1068
+ "GET /orgs/{orgID}/projects/{projectID}/skills",
1069
+ "GET /orgs/{orgID}/projects/{projectID}/tool-calls",
1070
+ "GET /orgs/{orgID}/projects/{projectID}/usage",
1071
+ "GET /orgs/{orgID}/secrets",
1072
+ "GET /orgs/{orgID}/secrets/{secretID}",
1073
+ "GET /orgs/{orgID}/secrets/{secretID}/grants",
1074
+ "GET /orgs/{orgID}/secrets/{secretID}/grants/{grantID}",
1075
+ "GET /orgs/{orgID}/skills",
1076
+ "GET /orgs/{orgID}/skills/{skillID}",
1077
+ "GET /orgs/{orgID}/skills/{skillID}/grants",
1078
+ "GET /orgs/{orgID}/skills/{skillID}/grants/{grantID}",
1079
+ "GET /orgs/{orgID}/usage",
1080
+ "GET /orgs/{orgID}/usage/timeseries",
1081
+ "GET /personal-access-tokens",
1082
+ "GET /tool-catalog",
1083
+ "PATCH /orgs/{orgID}/api-keys/{keyID}",
1084
+ "PATCH /orgs/{orgID}/machines/{machineID}",
1085
+ "PATCH /orgs/{orgID}/members/{userID}",
1086
+ "PATCH /orgs/{orgID}/projects/{projectID}",
1087
+ "PATCH /orgs/{orgID}/projects/{projectID}/agent-profiles/{agentProfileID}",
1088
+ "PATCH /orgs/{orgID}/projects/{projectID}/cron-triggers/{cronTriggerID}",
1089
+ "PATCH /orgs/{orgID}/projects/{projectID}/event-webhooks/{webhookID}",
1090
+ "PATCH /orgs/{orgID}/projects/{projectID}/machine-pool-grants/{poolGrantID}",
1091
+ "PATCH /orgs/{orgID}/projects/{projectID}/memory-stores/{memoryStoreID}",
1092
+ "PATCH /orgs/{orgID}/projects/{projectID}/model-grants/{modelGrantID}",
1093
+ "PATCH /orgs/{orgID}/secrets/{secretID}",
1094
+ "POST /daemon/bootstrap",
1095
+ "POST /daemon/failures",
1096
+ "POST /daemon/processes/{processID}/file",
1097
+ "POST /daemon/processes/{processID}/git-credentials",
1098
+ "POST /daemon/runtimes",
1099
+ "POST /daemon/runtimes/{runtimeID}/end",
1100
+ "POST /daemon/runtimes/{runtimeID}/sleep",
1101
+ "POST /invitations/{invitationID}/accept",
1102
+ "POST /invitations/{invitationID}/decline",
1103
+ "POST /orgs",
1104
+ "POST /orgs/{orgID}/api-keys",
1105
+ "POST /orgs/{orgID}/api-keys/{keyID}/revoke",
1106
+ "POST /orgs/{orgID}/invitations",
1107
+ "POST /orgs/{orgID}/machine-pools",
1108
+ "POST /orgs/{orgID}/machine-pools/check-connection",
1109
+ "POST /orgs/{orgID}/machines",
1110
+ "POST /orgs/{orgID}/machines/connect",
1111
+ "POST /orgs/{orgID}/machines/{machineID}/daemon-tokens",
1112
+ "POST /orgs/{orgID}/machines/{machineID}/daemon-tokens/{tokenID}/revoke",
1113
+ "POST /orgs/{orgID}/model-provider-configs",
1114
+ "POST /orgs/{orgID}/model-provider-configs/{modelProviderConfigID}/models",
1115
+ "POST /orgs/{orgID}/projects",
1116
+ "POST /orgs/{orgID}/projects/{projectID}/agent-configs",
1117
+ "POST /orgs/{orgID}/projects/{projectID}/agent-configs/tools",
1118
+ "POST /orgs/{orgID}/projects/{projectID}/agent-profiles",
1119
+ "POST /orgs/{orgID}/projects/{projectID}/agent-profiles/{agentProfileID}/config",
1120
+ "POST /orgs/{orgID}/projects/{projectID}/agents",
1121
+ "POST /orgs/{orgID}/projects/{projectID}/agents/{agentID}/archive",
1122
+ "POST /orgs/{orgID}/projects/{projectID}/agents/{agentID}/cancel",
1123
+ "POST /orgs/{orgID}/projects/{projectID}/agents/{agentID}/config",
1124
+ "POST /orgs/{orgID}/projects/{projectID}/agents/{agentID}/inputs",
1125
+ "POST /orgs/{orgID}/projects/{projectID}/agents/{agentID}/inputs/{inputID}/cancel",
1126
+ "POST /orgs/{orgID}/projects/{projectID}/agents/{agentID}/inputs/{inputID}/demote_to_queued",
1127
+ "POST /orgs/{orgID}/projects/{projectID}/agents/{agentID}/inputs/{inputID}/move",
1128
+ "POST /orgs/{orgID}/projects/{projectID}/agents/{agentID}/inputs/{inputID}/promote_to_steering",
1129
+ "POST /orgs/{orgID}/projects/{projectID}/agents/{agentID}/interactions/{interactionID}/resolve",
1130
+ "POST /orgs/{orgID}/projects/{projectID}/agents/{agentID}/tool-calls/{toolCallID}/result",
1131
+ "POST /orgs/{orgID}/projects/{projectID}/cron-triggers",
1132
+ "POST /orgs/{orgID}/projects/{projectID}/event-webhooks",
1133
+ "POST /orgs/{orgID}/projects/{projectID}/integrations",
1134
+ "POST /orgs/{orgID}/projects/{projectID}/integrations/{integrationID}/disconnect",
1135
+ "POST /orgs/{orgID}/projects/{projectID}/integrations/{integrationID}/github-setup",
1136
+ "POST /orgs/{orgID}/projects/{projectID}/integrations/{integrationID}/github-setup/installations",
1137
+ "POST /orgs/{orgID}/projects/{projectID}/integrations/{integrationID}/oauth/setup",
1138
+ "POST /orgs/{orgID}/projects/{projectID}/integrations/{integrationID}/setup",
1139
+ "POST /orgs/{orgID}/projects/{projectID}/integrations/{integrationID}/slack-setup",
1140
+ "POST /orgs/{orgID}/projects/{projectID}/integrations/{integrationID}/subscriptions",
1141
+ "POST /orgs/{orgID}/projects/{projectID}/machine-grants",
1142
+ "POST /orgs/{orgID}/projects/{projectID}/machine-pool-grants",
1143
+ "POST /orgs/{orgID}/projects/{projectID}/mcp-servers/tools",
1144
+ "POST /orgs/{orgID}/projects/{projectID}/memory-stores",
1145
+ "POST /orgs/{orgID}/projects/{projectID}/model-grants",
1146
+ "POST /orgs/{orgID}/secrets",
1147
+ "POST /orgs/{orgID}/secrets/mcp-oauth",
1148
+ "POST /orgs/{orgID}/secrets/{secretID}/grants",
1149
+ "POST /orgs/{orgID}/secrets/{secretID}/versions",
1150
+ "POST /orgs/{orgID}/skills",
1151
+ "POST /orgs/{orgID}/skills/{skillID}",
1152
+ "POST /orgs/{orgID}/skills/{skillID}/grants",
1153
+ "POST /personal-access-tokens",
1154
+ "POST /personal-access-tokens/{tokenID}/revoke",
1155
+ "PUT /orgs/{orgID}/api-keys/{keyID}/projects/{projectID}",
1156
+ "PUT /orgs/{orgID}/machine-pools/{poolID}",
1157
+ "PUT /orgs/{orgID}/members/{userID}/projects/{projectID}",
1158
+ "PUT /orgs/{orgID}/model-provider-configs/{modelProviderConfigID}",
1159
+ "PUT /orgs/{orgID}/model-provider-configs/{modelProviderConfigID}/models/{configuredModelID}",
1160
+ "PUT /orgs/{orgID}/projects/{projectID}/actors",
1161
+ "PUT /orgs/{orgID}/projects/{projectID}/integrations/{integrationID}",
1162
+ "PUT /orgs/{orgID}/projects/{projectID}/memory-stores/{memoryStoreID}/file"
1163
+ ]);
1164
+ var keyedOperations = /* @__PURE__ */ new Set([
1165
+ "POST /orgs",
1166
+ "POST /orgs/{orgID}/machines",
1167
+ "POST /orgs/{orgID}/projects",
1168
+ "POST /orgs/{orgID}/projects/{projectID}/agent-profiles",
1169
+ "POST /orgs/{orgID}/projects/{projectID}/agent-profiles/{agentProfileID}/config",
1170
+ "POST /orgs/{orgID}/projects/{projectID}/agents",
1171
+ "POST /orgs/{orgID}/projects/{projectID}/agents/{agentID}/config",
1172
+ "POST /orgs/{orgID}/projects/{projectID}/agents/{agentID}/inputs",
1173
+ "POST /orgs/{orgID}/projects/{projectID}/cron-triggers",
1174
+ "POST /orgs/{orgID}/projects/{projectID}/machine-grants",
1175
+ "POST /orgs/{orgID}/projects/{projectID}/machine-pool-grants"
1176
+ ]);
1177
+ var idempotentOperations = /* @__PURE__ */ new Set([
1178
+ "POST /orgs/{orgID}/projects/{projectID}/agents/{agentID}/archive",
1179
+ "POST /orgs/{orgID}/projects/{projectID}/agents/{agentID}/tool-calls/{toolCallID}/result",
1180
+ "PUT /orgs/{orgID}/projects/{projectID}/memory-stores/{memoryStoreID}/file"
1181
+ ]);
1182
+
1183
+ // src/observer.ts
1184
+ function notifyObserver(observer, observation) {
1185
+ if (observer === void 0) return;
1186
+ try {
1187
+ void Promise.resolve(observer(observation)).catch(() => void 0);
1188
+ } catch {
1189
+ }
1190
+ }
1191
+
1192
+ // src/response-stream.ts
1193
+ function responseWithStreamLifetime(response, signal, dispose) {
1194
+ if (response.body === null) return response;
1195
+ const wrapped = new Response(streamWithLifetime(response.body, signal, dispose), response);
1196
+ return copyResponseMetadata(wrapped, response);
1197
+ }
1198
+ function copyResponseMetadata(target, source) {
1199
+ Object.defineProperties(target, {
1200
+ url: { value: source.url },
1201
+ redirected: { value: source.redirected },
1202
+ type: { value: source.type },
1203
+ clone: {
1204
+ configurable: true,
1205
+ writable: true,
1206
+ value: function clone() {
1207
+ return copyResponseMetadata(Response.prototype.clone.call(this), this);
1208
+ }
1209
+ }
1210
+ });
1211
+ return target;
1212
+ }
1213
+ function streamWithLifetime(source, signal, dispose) {
1214
+ const reader = source.getReader();
1215
+ let finished = false;
1216
+ let disposed = false;
1217
+ let output;
1218
+ function release() {
1219
+ if (disposed) return;
1220
+ disposed = true;
1221
+ signal.removeEventListener("abort", abort);
1222
+ dispose();
1223
+ }
1224
+ function fail(reason) {
1225
+ if (finished) return;
1226
+ finished = true;
1227
+ output.error(reason);
1228
+ release();
1229
+ void reader.cancel(reason).catch(() => void 0).finally(() => {
1230
+ reader.releaseLock();
1231
+ });
1232
+ }
1233
+ function abort() {
1234
+ fail(signal.reason);
1235
+ }
1236
+ return new ReadableStream(
1237
+ {
1238
+ start(controller) {
1239
+ output = controller;
1240
+ if (signal.aborted) abort();
1241
+ else signal.addEventListener("abort", abort, { once: true });
1242
+ void reader.closed.then(release, fail);
1243
+ },
1244
+ async pull(controller) {
1245
+ try {
1246
+ const chunk = await reader.read();
1247
+ if (finished) return;
1248
+ if (chunk.done) {
1249
+ finished = true;
1250
+ controller.close();
1251
+ release();
1252
+ reader.releaseLock();
1253
+ } else controller.enqueue(chunk.value);
1254
+ } catch (error) {
1255
+ fail(error);
1256
+ }
1257
+ },
1258
+ // oxlint-disable-next-line anti-slop/no-unknown-parameters
1259
+ async cancel(reason) {
1260
+ finished = true;
1261
+ release();
1262
+ try {
1263
+ await reader.cancel(reason);
1264
+ } finally {
1265
+ reader.releaseLock();
1266
+ }
1267
+ }
1268
+ },
1269
+ { highWaterMark: 0 }
1270
+ );
1271
+ }
1272
+
1273
+ // src/retry.ts
1274
+ var retryBaseDelayMs = 1e3;
1275
+ var retryMaximumDelayMs = 3e4;
1276
+ var retryAfterMaximumDelayMs = 6e4;
1277
+ function retryDelay(attempt) {
1278
+ const maximum = Math.min(retryBaseDelayMs * 2 ** Math.max(attempt - 1, 0), retryMaximumDelayMs);
1279
+ return Math.floor(Math.random() * maximum);
1280
+ }
1281
+ function abortableDelay(ms, signal) {
1282
+ if (signal?.aborted === true) return Promise.resolve(false);
1283
+ return new Promise((resolve) => {
1284
+ const onAbort = () => {
1285
+ finish(false);
1286
+ };
1287
+ const timeout = globalThis.setTimeout(() => {
1288
+ finish(true);
1289
+ }, ms);
1290
+ function finish(completed) {
1291
+ globalThis.clearTimeout(timeout);
1292
+ signal?.removeEventListener("abort", onAbort);
1293
+ resolve(completed);
1294
+ }
1295
+ signal?.addEventListener("abort", onAbort, { once: true });
1296
+ });
1297
+ }
1298
+
1299
+ // src/request-policy.ts
1300
+ function validateRequestPolicy(options) {
1301
+ for (const name of ["maxRetries", "timeoutMs"]) {
1302
+ const value = options[name];
1303
+ if (value !== void 0 && (!Number.isSafeInteger(value) || value < 0)) {
1304
+ throw new RangeError(`${name} must be a non-negative safe integer`);
1305
+ }
1306
+ }
1307
+ if (options.timeoutMs !== void 0 && options.timeoutMs > 2147483647) {
1308
+ throw new RangeError("timeoutMs must fit a 32-bit timer (at most 2147483647 ms)");
1309
+ }
1310
+ }
1311
+ function normalizeHeaders(headers) {
1312
+ return Array.isArray(headers) ? new Headers(headers) : headers;
1313
+ }
1314
+ function validateClientRequestPolicy(options) {
1315
+ validateRequestPolicy(options);
1316
+ if (mergeHeaders(normalizeHeaders(options.headers)).has("Idempotency-Key")) {
1317
+ throw new TypeError(
1318
+ "Idempotency-Key cannot be set in client-wide headers; set it on each request instead."
1319
+ );
1320
+ }
1321
+ }
1322
+ function oneShotBody(body) {
1323
+ return body instanceof ReadableStream || body !== null && typeof body === "object" && Symbol.asyncIterator in body;
1324
+ }
1325
+ var retryableStatuses = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
1326
+ var originalRequests = /* @__PURE__ */ new WeakMap();
1327
+ function captureRequestDestination(request, options) {
1328
+ if (options.fetch !== void 0 && originalRequests.has(options.fetch)) {
1329
+ originalRequests.set(options.fetch, {
1330
+ method: request.method,
1331
+ url: request.url,
1332
+ baseUrl: options.baseUrl,
1333
+ operation: `${(options.method ?? "GET").toUpperCase()} ${options.url}`
1334
+ });
1335
+ }
1336
+ return request;
1337
+ }
1338
+ async function requestWithPolicy(config, options, dispatch) {
1339
+ const maxRetries = options.maxRetries ?? config.maxRetries ?? 2;
1340
+ const timeoutMs = options.timeoutMs ?? config.timeoutMs ?? 0;
1341
+ validateRequestPolicy({ maxRetries, timeoutMs });
1342
+ const startedAt = Date.now();
1343
+ const observer = options.onRequestComplete ?? config.onRequestComplete;
1344
+ const method = (options.method ?? "GET").toUpperCase();
1345
+ const operation = `${method} ${options.url}`;
1346
+ const baseUrl = "baseUrl" in options ? options.baseUrl : config.baseUrl;
1347
+ const keyed = keyedOperations.has(operation);
1348
+ let headers = normalizeHeaders(options.headers);
1349
+ const mergedHeaders = mergeHeaders(normalizeHeaders(config.headers), headers);
1350
+ if (keyed && !mergedHeaders.has("Idempotency-Key")) {
1351
+ headers = {
1352
+ ...headers instanceof Headers ? Object.fromEntries(headers) : headers,
1353
+ "Idempotency-Key": crypto.randomUUID()
1354
+ };
1355
+ }
1356
+ const callerSignal = options.signal !== void 0 ? options.signal : config.signal;
1357
+ const controller = new AbortController();
1358
+ const disposeCaller = forwardAbort(callerSignal, controller);
1359
+ const { signal } = controller;
1360
+ const timeoutReason = timeoutMs > 0 ? new DOMException("SDK request timed out", "TimeoutError") : void 0;
1361
+ const expiresAt = timeoutMs > 0 ? Date.now() + timeoutMs : Infinity;
1362
+ const timer = timeoutMs > 0 ? setTimeout(() => {
1363
+ if (signal.aborted) return;
1364
+ controller.abort(timeoutReason);
1365
+ }, timeoutMs) : void 0;
1366
+ const fetch = options.fetch ?? config.fetch ?? globalThis.fetch;
1367
+ const parseAs = options.parseAs ?? config.parseAs;
1368
+ let replayable = !oneShotBody(options.body);
1369
+ const serializer = options.bodySerializer !== void 0 ? options.bodySerializer : config.bodySerializer;
1370
+ const bodySerializer = serializer ? (body) => {
1371
+ const serialized = serializer(body);
1372
+ replayable &&= !oneShotBody(serialized);
1373
+ return serialized;
1374
+ } : serializer;
1375
+ let lastRequest;
1376
+ let lastResponse;
1377
+ let handoff = "none";
1378
+ let attempts = 0;
1379
+ const backoff = { elapsedMs: 0 };
1380
+ let status;
1381
+ let observationOperation = knownOperations.has(operation) ? operation : "unknown";
1382
+ let outcome = "returned";
1383
+ async function wait(delayMs) {
1384
+ const waitingAt = Date.now();
1385
+ backoff.startedAt = waitingAt;
1386
+ try {
1387
+ await abortableDelay(delayMs, signal);
1388
+ } finally {
1389
+ backoff.elapsedMs += Math.max(0, Date.now() - waitingAt);
1390
+ backoff.startedAt = void 0;
1391
+ }
1392
+ }
1393
+ function exposeResponse(response) {
1394
+ if (parseAs === "stream" && response.ok) clearTimeout(timer);
1395
+ return response;
1396
+ }
1397
+ const retryingFetch = async (input, init) => {
1398
+ signal.throwIfAborted();
1399
+ const template = input instanceof Request && init === void 0 ? input : new Request(input, init);
1400
+ const original = originalRequests.get(retryingFetch);
1401
+ const sameDestination = original?.operation === operation && original.baseUrl === baseUrl && template.method === method && original.method === template.method && original.url === template.url;
1402
+ if (!sameDestination) observationOperation = "unknown";
1403
+ const safe = sameDestination && replayable && parseAs !== "stream" && (template.method === "GET" || template.method === "HEAD" || idempotentOperations.has(operation) || keyed && Boolean(template.headers.get("Idempotency-Key")?.trim()));
1404
+ const retries = safe ? maxRetries : 0;
1405
+ try {
1406
+ for (let attempt = 0; ; attempt++) {
1407
+ signal.throwIfAborted();
1408
+ lastRequest = retries > 0 ? template.clone() : template;
1409
+ lastResponse = void 0;
1410
+ status = void 0;
1411
+ let response;
1412
+ try {
1413
+ attempts++;
1414
+ response = await fetch(lastRequest);
1415
+ } catch (error) {
1416
+ signal.throwIfAborted();
1417
+ const delay2 = retryDelay(attempt + 1);
1418
+ if (!(error instanceof TypeError) || attempt >= retries || Date.now() + delay2 >= expiresAt)
1419
+ throw error;
1420
+ await wait(delay2);
1421
+ continue;
1422
+ }
1423
+ if (signal.aborted) {
1424
+ void response.body?.cancel().catch(() => void 0);
1425
+ signal.throwIfAborted();
1426
+ }
1427
+ lastResponse = response;
1428
+ status = response.status;
1429
+ if (!retryableStatuses.has(response.status) || attempt >= retries)
1430
+ return exposeResponse(response);
1431
+ const retryAfterMs = parseRetryAfter(response.headers.get("Retry-After")) ?? 0;
1432
+ const delay = Math.max(retryDelay(attempt + 1), retryAfterMs);
1433
+ if (retryAfterMs > retryAfterMaximumDelayMs || Date.now() + delay >= expiresAt)
1434
+ return exposeResponse(response);
1435
+ void response.body?.cancel().catch(() => void 0);
1436
+ lastResponse = void 0;
1437
+ await wait(delay);
1438
+ }
1439
+ } finally {
1440
+ if (retries > 0) void template.body?.cancel().catch(() => void 0);
1441
+ }
1442
+ };
1443
+ originalRequests.set(retryingFetch, void 0);
1444
+ try {
1445
+ const result = await untilAborted(
1446
+ () => dispatch({ fetch: retryingFetch, signal, headers, bodySerializer }),
1447
+ signal
1448
+ );
1449
+ if (result instanceof ReadableStream) {
1450
+ clearTimeout(timer);
1451
+ const stream = callerSignal ? streamWithLifetime(result, signal, disposeCaller) : result;
1452
+ handoff = "stream";
1453
+ return stream;
1454
+ }
1455
+ if (result !== null && // oxlint-disable-next-line anti-slop/no-runtime-typeof
1456
+ typeof result === "object" && "response" in result && result.response instanceof Response) {
1457
+ handoff = result.response === lastResponse ? "response" : "none";
1458
+ if (result.response.body !== null && "data" in result && result.data === result.response.body) {
1459
+ clearTimeout(timer);
1460
+ const response = callerSignal ? responseWithStreamLifetime(result.response, signal, disposeCaller) : result.response;
1461
+ handoff = "stream";
1462
+ return { ...result, data: response.body, response };
1463
+ }
1464
+ }
1465
+ return result;
1466
+ } catch (error) {
1467
+ if (options.throwOnError ?? config.throwOnError) {
1468
+ outcome = "threw";
1469
+ throw error;
1470
+ }
1471
+ const dataOnly = (options.responseStyle ?? config.responseStyle) === "data";
1472
+ handoff = !dataOnly && lastResponse !== void 0 ? "response" : "none";
1473
+ return dataOnly ? void 0 : { error, request: lastRequest, response: lastResponse };
1474
+ } finally {
1475
+ originalRequests.delete(retryingFetch);
1476
+ clearTimeout(timer);
1477
+ if (handoff !== "stream") {
1478
+ disposeCaller();
1479
+ if (parseAs === "stream" && (handoff === "none" || signal.aborted))
1480
+ void lastResponse?.body?.cancel().catch(() => void 0);
1481
+ }
1482
+ if (observer !== void 0) {
1483
+ notifyObserver(observer, {
1484
+ operation: observationOperation,
1485
+ durationMs: Math.max(0, Date.now() - startedAt),
1486
+ attempts,
1487
+ backoffMs: backoff.elapsedMs + (backoff.startedAt === void 0 ? 0 : Math.max(0, Date.now() - backoff.startedAt)),
1488
+ status,
1489
+ outcome: signal.aborted ? signal.reason === timeoutReason ? "timeout" : "canceled" : outcome
1490
+ });
1491
+ }
1492
+ }
1493
+ }
1494
+
1495
+ // src/client.ts
1496
+ var httpMethods = [
1497
+ "connect",
1498
+ "delete",
1499
+ "get",
1500
+ "head",
1501
+ "options",
1502
+ "patch",
1503
+ "post",
1504
+ "put",
1505
+ "trace"
1506
+ ];
1507
+ var zMultipartPart = z4.union([
1508
+ z4.string(),
1509
+ z4.instanceof(Blob),
1510
+ z4.date().transform((date2) => date2.toISOString()),
1511
+ z4.union([z4.number(), z4.boolean(), z4.bigint()]).transform(String),
1512
+ z4.json().transform((value) => new Blob([JSON.stringify(value)], { type: "application/json" }))
1513
+ ]);
1514
+ var zMultipartBody = z4.record(
1515
+ z4.string(),
1516
+ z4.union([z4.array(zMultipartPart), zMultipartPart]).nullish()
1517
+ );
1518
+ var serializeMultipartBody = ((body) => {
1519
+ const form = new FormData();
1520
+ for (const [key, value] of Object.entries(zMultipartBody.parse(body))) {
1521
+ if (value === null || value === void 0) continue;
1522
+ for (const part of Array.isArray(value) ? value : [value]) form.append(key, part);
1523
+ }
1524
+ return form;
1525
+ });
1526
+ function normalizeRequestOptions(options) {
1527
+ const normalized = { ...options };
1528
+ Reflect.deleteProperty(normalized, "client");
1529
+ if (normalized.bodySerializer === formDataBodySerializer.bodySerializer) {
1530
+ normalized.bodySerializer = serializeMultipartBody;
1531
+ }
1532
+ return normalized;
1533
+ }
1534
+ function configureRequests(client2) {
1535
+ client2.interceptors.request.use(captureRequestDestination);
1536
+ const { setConfig } = client2;
1537
+ client2.setConfig = (config) => {
1538
+ validateClientRequestPolicy(config);
1539
+ return setConfig({ ...config, headers: normalizeHeaders(config.headers) });
1540
+ };
1541
+ const { request } = client2;
1542
+ client2.request = (options) => requestWithPolicy(
1543
+ client2.getConfig(),
1544
+ normalizeRequestOptions(options),
1545
+ (overrides) => request(normalizeRequestOptions({ ...options, ...overrides }))
1546
+ );
1547
+ for (const method of httpMethods) {
1548
+ const requestMethod = method.toUpperCase();
1549
+ client2[method] = (options) => client2.request({ ...options, method: requestMethod });
1550
+ const sseDispatch = client2.sse[method];
1551
+ client2.sse[method] = (options) => sseDispatch(normalizeRequestOptions(options));
1552
+ }
1553
+ }
1554
+ client.setConfig({ maxRetries: 0, timeoutMs: 0 });
1555
+ configureRequests(client);
1556
+ function createOmnaraClient(options = {}) {
1557
+ const client2 = createClient(
1558
+ createConfig({
1559
+ throwOnError: true
1560
+ })
1561
+ );
1562
+ configureRequests(client2);
1563
+ client2.setConfig({
1564
+ baseUrl: options.baseUrl ?? client.getConfig().baseUrl,
1565
+ credentials: options.credentials,
1566
+ headers: options.headers,
1567
+ fetch: options.fetch,
1568
+ maxRetries: options.maxRetries,
1569
+ timeoutMs: options.timeoutMs,
1570
+ onRequestComplete: options.onRequestComplete
1571
+ });
1572
+ const { auth } = options;
1573
+ if (auth) {
1574
+ client2.interceptors.request.use(async (request) => {
1575
+ await auth.authenticate(request);
1576
+ return request;
1577
+ });
1578
+ }
1579
+ client2.interceptors.response.use(async (response) => {
1580
+ if (!response.ok) throw await ApiError.fromResponse(response);
1581
+ return response;
1582
+ });
1583
+ return client2;
1584
+ }
1585
+
1586
+ export {
1587
+ forwardAbort,
1588
+ untilAborted,
1589
+ zJsonText,
1590
+ relaxedSchema,
1591
+ relaxedResponseValidator,
1592
+ zErrorResponse,
1593
+ ApiError,
1594
+ parseRetryAfter,
1595
+ retryAfterMaximumDelayMs,
1596
+ retryDelay,
1597
+ abortableDelay,
1598
+ formDataBodySerializer,
1599
+ jsonBodySerializer,
1600
+ client,
1601
+ notifyObserver,
1602
+ createOmnaraClient
1603
+ };
1604
+ //# sourceMappingURL=chunk-HFFDN2XF.js.map