@naturali/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,1780 @@
1
+ //#region src/generated/core/bodySerializer.gen.ts
2
+ const jsonBodySerializer = { bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value) };
3
+ //#endregion
4
+ //#region src/generated/core/serverSentEvents.gen.ts
5
+ function createSseClient({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) {
6
+ let lastEventId;
7
+ const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
8
+ const createStream = async function* () {
9
+ let retryDelay = sseDefaultRetryDelay ?? 3e3;
10
+ let attempt = 0;
11
+ const signal = options.signal ?? new AbortController().signal;
12
+ while (true) {
13
+ if (signal.aborted) break;
14
+ attempt++;
15
+ const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
16
+ if (lastEventId !== void 0) headers.set("Last-Event-ID", lastEventId);
17
+ try {
18
+ const requestInit = {
19
+ redirect: "follow",
20
+ ...options,
21
+ body: options.serializedBody,
22
+ headers,
23
+ signal
24
+ };
25
+ let request = new Request(url, requestInit);
26
+ if (onRequest) request = await onRequest(url, requestInit);
27
+ const response = await (options.fetch ?? globalThis.fetch)(request);
28
+ if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
29
+ if (!response.body) throw new Error("No body in SSE response");
30
+ const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
31
+ let buffer = "";
32
+ const abortHandler = () => {
33
+ try {
34
+ reader.cancel();
35
+ } catch {}
36
+ };
37
+ signal.addEventListener("abort", abortHandler);
38
+ try {
39
+ while (true) {
40
+ const { done, value } = await reader.read();
41
+ if (done) break;
42
+ buffer += value;
43
+ buffer = buffer.replace(/\r\n?/g, "\n");
44
+ const chunks = buffer.split("\n\n");
45
+ buffer = chunks.pop() ?? "";
46
+ for (const chunk of chunks) {
47
+ const lines = chunk.split("\n");
48
+ const dataLines = [];
49
+ let eventName;
50
+ for (const line of lines) if (line.startsWith("data:")) dataLines.push(line.replace(/^data:\s*/, ""));
51
+ else if (line.startsWith("event:")) eventName = line.replace(/^event:\s*/, "");
52
+ else if (line.startsWith("id:")) lastEventId = line.replace(/^id:\s*/, "");
53
+ else if (line.startsWith("retry:")) {
54
+ const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
55
+ if (!Number.isNaN(parsed)) retryDelay = parsed;
56
+ }
57
+ let data;
58
+ let parsedJson = false;
59
+ if (dataLines.length) {
60
+ const rawData = dataLines.join("\n");
61
+ try {
62
+ data = JSON.parse(rawData);
63
+ parsedJson = true;
64
+ } catch {
65
+ data = rawData;
66
+ }
67
+ }
68
+ if (parsedJson) {
69
+ if (responseValidator) await responseValidator(data);
70
+ if (responseTransformer) data = await responseTransformer(data);
71
+ }
72
+ onSseEvent?.({
73
+ data,
74
+ event: eventName,
75
+ id: lastEventId,
76
+ retry: retryDelay
77
+ });
78
+ if (dataLines.length) yield data;
79
+ }
80
+ }
81
+ } finally {
82
+ signal.removeEventListener("abort", abortHandler);
83
+ reader.releaseLock();
84
+ }
85
+ break;
86
+ } catch (error) {
87
+ onSseError?.(error);
88
+ if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) break;
89
+ const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
90
+ await sleep(backoff);
91
+ }
92
+ }
93
+ };
94
+ return { stream: createStream() };
95
+ }
96
+ //#endregion
97
+ //#region src/generated/core/pathSerializer.gen.ts
98
+ const separatorArrayExplode = (style) => {
99
+ switch (style) {
100
+ case "label": return ".";
101
+ case "matrix": return ";";
102
+ case "simple": return ",";
103
+ default: return "&";
104
+ }
105
+ };
106
+ const separatorArrayNoExplode = (style) => {
107
+ switch (style) {
108
+ case "form": return ",";
109
+ case "pipeDelimited": return "|";
110
+ case "spaceDelimited": return "%20";
111
+ default: return ",";
112
+ }
113
+ };
114
+ const separatorObjectExplode = (style) => {
115
+ switch (style) {
116
+ case "label": return ".";
117
+ case "matrix": return ";";
118
+ case "simple": return ",";
119
+ default: return "&";
120
+ }
121
+ };
122
+ const serializeArrayParam = ({ allowReserved, explode, name, style, value }) => {
123
+ if (!explode) {
124
+ const joinedValues = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
125
+ switch (style) {
126
+ case "label": return `.${joinedValues}`;
127
+ case "matrix": return `;${name}=${joinedValues}`;
128
+ case "simple": return joinedValues;
129
+ default: return `${name}=${joinedValues}`;
130
+ }
131
+ }
132
+ const separator = separatorArrayExplode(style);
133
+ const joinedValues = value.map((v) => {
134
+ if (style === "label" || style === "simple") return allowReserved ? v : encodeURIComponent(v);
135
+ return serializePrimitiveParam({
136
+ allowReserved,
137
+ name,
138
+ value: v
139
+ });
140
+ }).join(separator);
141
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
142
+ };
143
+ const serializePrimitiveParam = ({ allowReserved, name, value }) => {
144
+ if (value === void 0 || value === null) return "";
145
+ if (typeof value === "object") throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");
146
+ return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
147
+ };
148
+ const serializeObjectParam = ({ allowReserved, explode, name, style, value, valueOnly }) => {
149
+ if (value instanceof Date) return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
150
+ if (style !== "deepObject" && !explode) {
151
+ let values = [];
152
+ Object.entries(value).forEach(([key, v]) => {
153
+ values = [
154
+ ...values,
155
+ key,
156
+ allowReserved ? v : encodeURIComponent(v)
157
+ ];
158
+ });
159
+ const joinedValues = values.join(",");
160
+ switch (style) {
161
+ case "form": return `${name}=${joinedValues}`;
162
+ case "label": return `.${joinedValues}`;
163
+ case "matrix": return `;${name}=${joinedValues}`;
164
+ default: return joinedValues;
165
+ }
166
+ }
167
+ const separator = separatorObjectExplode(style);
168
+ const joinedValues = Object.entries(value).map(([key, v]) => serializePrimitiveParam({
169
+ allowReserved,
170
+ name: style === "deepObject" ? `${name}[${key}]` : key,
171
+ value: v
172
+ })).join(separator);
173
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
174
+ };
175
+ //#endregion
176
+ //#region src/generated/core/utils.gen.ts
177
+ const PATH_PARAM_RE = /\{[^{}]+\}/g;
178
+ const defaultPathSerializer = ({ path, url: _url }) => {
179
+ let url = _url;
180
+ const matches = _url.match(PATH_PARAM_RE);
181
+ if (matches) for (const match of matches) {
182
+ let explode = false;
183
+ let name = match.substring(1, match.length - 1);
184
+ let style = "simple";
185
+ if (name.endsWith("*")) {
186
+ explode = true;
187
+ name = name.substring(0, name.length - 1);
188
+ }
189
+ if (name.startsWith(".")) {
190
+ name = name.substring(1);
191
+ style = "label";
192
+ } else if (name.startsWith(";")) {
193
+ name = name.substring(1);
194
+ style = "matrix";
195
+ }
196
+ const value = path[name];
197
+ if (value === void 0 || value === null) continue;
198
+ if (Array.isArray(value)) {
199
+ url = url.replace(match, serializeArrayParam({
200
+ explode,
201
+ name,
202
+ style,
203
+ value
204
+ }));
205
+ continue;
206
+ }
207
+ if (typeof value === "object") {
208
+ url = url.replace(match, serializeObjectParam({
209
+ explode,
210
+ name,
211
+ style,
212
+ value,
213
+ valueOnly: true
214
+ }));
215
+ continue;
216
+ }
217
+ if (style === "matrix") {
218
+ url = url.replace(match, `;${serializePrimitiveParam({
219
+ name,
220
+ value
221
+ })}`);
222
+ continue;
223
+ }
224
+ const replaceValue = encodeURIComponent(style === "label" ? `.${value}` : value);
225
+ url = url.replace(match, replaceValue);
226
+ }
227
+ return url;
228
+ };
229
+ const getUrl = ({ baseUrl, path, query, querySerializer, url: _url }) => {
230
+ const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
231
+ let url = (baseUrl ?? "") + pathUrl;
232
+ if (path) url = defaultPathSerializer({
233
+ path,
234
+ url
235
+ });
236
+ let search = query ? querySerializer(query) : "";
237
+ if (search.startsWith("?")) search = search.substring(1);
238
+ if (search) url += `?${search}`;
239
+ return url;
240
+ };
241
+ function getValidRequestBody(options) {
242
+ const hasBody = options.body !== void 0;
243
+ if (hasBody && options.bodySerializer) {
244
+ if ("serializedBody" in options) return options.serializedBody !== void 0 && options.serializedBody !== "" ? options.serializedBody : null;
245
+ return options.body !== "" ? options.body : null;
246
+ }
247
+ if (hasBody) return options.body;
248
+ }
249
+ //#endregion
250
+ //#region src/generated/core/auth.gen.ts
251
+ const getAuthToken = async (auth, callback) => {
252
+ const token = typeof callback === "function" ? await callback(auth) : callback;
253
+ if (!token) return;
254
+ if (auth.scheme === "bearer") return `Bearer ${token}`;
255
+ if (auth.scheme === "basic") return `Basic ${btoa(token)}`;
256
+ return token;
257
+ };
258
+ //#endregion
259
+ //#region src/generated/client/utils.gen.ts
260
+ const createQuerySerializer = ({ parameters = {}, ...args } = {}) => {
261
+ const querySerializer = (queryParams) => {
262
+ const search = [];
263
+ if (queryParams && typeof queryParams === "object") for (const name in queryParams) {
264
+ const value = queryParams[name];
265
+ if (value === void 0 || value === null) continue;
266
+ const options = parameters[name] || args;
267
+ if (Array.isArray(value)) {
268
+ const serializedArray = serializeArrayParam({
269
+ allowReserved: options.allowReserved,
270
+ explode: true,
271
+ name,
272
+ style: "form",
273
+ value,
274
+ ...options.array
275
+ });
276
+ if (serializedArray) search.push(serializedArray);
277
+ } else if (typeof value === "object") {
278
+ const serializedObject = serializeObjectParam({
279
+ allowReserved: options.allowReserved,
280
+ explode: true,
281
+ name,
282
+ style: "deepObject",
283
+ value,
284
+ ...options.object
285
+ });
286
+ if (serializedObject) search.push(serializedObject);
287
+ } else {
288
+ const serializedPrimitive = serializePrimitiveParam({
289
+ allowReserved: options.allowReserved,
290
+ name,
291
+ value
292
+ });
293
+ if (serializedPrimitive) search.push(serializedPrimitive);
294
+ }
295
+ }
296
+ return search.join("&");
297
+ };
298
+ return querySerializer;
299
+ };
300
+ /**
301
+ * Infers parseAs value from provided Content-Type header.
302
+ */
303
+ const getParseAs = (contentType) => {
304
+ if (!contentType) return "stream";
305
+ const cleanContent = contentType.split(";")[0]?.trim();
306
+ if (!cleanContent) return;
307
+ if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) return "json";
308
+ if (cleanContent === "multipart/form-data") return "formData";
309
+ if ([
310
+ "application/",
311
+ "audio/",
312
+ "image/",
313
+ "video/"
314
+ ].some((type) => cleanContent.startsWith(type))) return "blob";
315
+ if (cleanContent.startsWith("text/")) return "text";
316
+ };
317
+ const checkForExistence = (options, name) => {
318
+ if (!name) return false;
319
+ if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) return true;
320
+ return false;
321
+ };
322
+ async function setAuthParams(options) {
323
+ for (const auth of options.security ?? []) {
324
+ if (checkForExistence(options, auth.name)) continue;
325
+ const token = await getAuthToken(auth, options.auth);
326
+ if (!token) continue;
327
+ const name = auth.name ?? "Authorization";
328
+ switch (auth.in) {
329
+ case "query":
330
+ if (!options.query) options.query = {};
331
+ options.query[name] = token;
332
+ break;
333
+ case "cookie":
334
+ options.headers.append("Cookie", `${name}=${token}`);
335
+ break;
336
+ default:
337
+ options.headers.set(name, token);
338
+ break;
339
+ }
340
+ }
341
+ }
342
+ const buildUrl = (options) => getUrl({
343
+ baseUrl: options.baseUrl,
344
+ path: options.path,
345
+ query: options.query,
346
+ querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
347
+ url: options.url
348
+ });
349
+ const mergeConfigs = (a, b) => {
350
+ const config = {
351
+ ...a,
352
+ ...b
353
+ };
354
+ if (config.baseUrl?.endsWith("/")) config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
355
+ config.headers = mergeHeaders(a.headers, b.headers);
356
+ return config;
357
+ };
358
+ const headersEntries = (headers) => {
359
+ const entries = [];
360
+ headers.forEach((value, key) => {
361
+ entries.push([key, value]);
362
+ });
363
+ return entries;
364
+ };
365
+ const mergeHeaders = (...headers) => {
366
+ const mergedHeaders = new Headers();
367
+ for (const header of headers) {
368
+ if (!header) continue;
369
+ const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
370
+ for (const [key, value] of iterator) if (value === null) mergedHeaders.delete(key);
371
+ else if (Array.isArray(value)) for (const v of value) mergedHeaders.append(key, v);
372
+ else if (value !== void 0) mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
373
+ }
374
+ return mergedHeaders;
375
+ };
376
+ var Interceptors = class {
377
+ fns = [];
378
+ clear() {
379
+ this.fns = [];
380
+ }
381
+ eject(id) {
382
+ const index = this.getInterceptorIndex(id);
383
+ if (this.fns[index]) this.fns[index] = null;
384
+ }
385
+ exists(id) {
386
+ const index = this.getInterceptorIndex(id);
387
+ return Boolean(this.fns[index]);
388
+ }
389
+ getInterceptorIndex(id) {
390
+ if (typeof id === "number") return this.fns[id] ? id : -1;
391
+ return this.fns.indexOf(id);
392
+ }
393
+ update(id, fn) {
394
+ const index = this.getInterceptorIndex(id);
395
+ if (this.fns[index]) {
396
+ this.fns[index] = fn;
397
+ return id;
398
+ }
399
+ return false;
400
+ }
401
+ use(fn) {
402
+ this.fns.push(fn);
403
+ return this.fns.length - 1;
404
+ }
405
+ };
406
+ const createInterceptors = () => ({
407
+ error: new Interceptors(),
408
+ request: new Interceptors(),
409
+ response: new Interceptors()
410
+ });
411
+ const defaultQuerySerializer = createQuerySerializer({
412
+ allowReserved: false,
413
+ array: {
414
+ explode: true,
415
+ style: "form"
416
+ },
417
+ object: {
418
+ explode: true,
419
+ style: "deepObject"
420
+ }
421
+ });
422
+ const defaultHeaders = { "Content-Type": "application/json" };
423
+ const createConfig = (override = {}) => ({
424
+ ...jsonBodySerializer,
425
+ headers: defaultHeaders,
426
+ parseAs: "auto",
427
+ querySerializer: defaultQuerySerializer,
428
+ ...override
429
+ });
430
+ //#endregion
431
+ //#region src/generated/client/client.gen.ts
432
+ const createClient = (config = {}) => {
433
+ let _config = mergeConfigs(createConfig(), config);
434
+ const getConfig = () => ({ ..._config });
435
+ const setConfig = (config) => {
436
+ _config = mergeConfigs(_config, config);
437
+ return getConfig();
438
+ };
439
+ const interceptors = createInterceptors();
440
+ const beforeRequest = async (options) => {
441
+ const opts = {
442
+ ..._config,
443
+ ...options,
444
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
445
+ headers: mergeHeaders(_config.headers, options.headers),
446
+ serializedBody: void 0
447
+ };
448
+ if (opts.security) await setAuthParams(opts);
449
+ if (opts.requestValidator) await opts.requestValidator(opts);
450
+ if (opts.body !== void 0 && opts.bodySerializer) opts.serializedBody = opts.bodySerializer(opts.body);
451
+ if (opts.body === void 0 || opts.serializedBody === "") opts.headers.delete("Content-Type");
452
+ const resolvedOpts = opts;
453
+ return {
454
+ opts: resolvedOpts,
455
+ url: buildUrl(resolvedOpts)
456
+ };
457
+ };
458
+ const request = async (options) => {
459
+ const throwOnError = options.throwOnError ?? _config.throwOnError;
460
+ const responseStyle = options.responseStyle ?? _config.responseStyle;
461
+ let request;
462
+ let response;
463
+ try {
464
+ const { opts, url } = await beforeRequest(options);
465
+ const requestInit = {
466
+ redirect: "follow",
467
+ ...opts,
468
+ body: getValidRequestBody(opts)
469
+ };
470
+ request = new Request(url, requestInit);
471
+ for (const fn of interceptors.request.fns) if (fn) request = await fn(request, opts);
472
+ const _fetch = opts.fetch;
473
+ response = await _fetch(request);
474
+ for (const fn of interceptors.response.fns) if (fn) response = await fn(response, request, opts);
475
+ const result = {
476
+ request,
477
+ response
478
+ };
479
+ if (response.ok) {
480
+ const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
481
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
482
+ let emptyData;
483
+ switch (parseAs) {
484
+ case "arrayBuffer":
485
+ case "blob":
486
+ case "text":
487
+ emptyData = await response[parseAs]();
488
+ break;
489
+ case "formData":
490
+ emptyData = new FormData();
491
+ break;
492
+ case "stream":
493
+ emptyData = response.body;
494
+ break;
495
+ default:
496
+ emptyData = {};
497
+ break;
498
+ }
499
+ return opts.responseStyle === "data" ? emptyData : {
500
+ data: emptyData,
501
+ ...result
502
+ };
503
+ }
504
+ let data;
505
+ switch (parseAs) {
506
+ case "arrayBuffer":
507
+ case "blob":
508
+ case "formData":
509
+ case "text":
510
+ data = await response[parseAs]();
511
+ break;
512
+ case "json": {
513
+ const text = await response.text();
514
+ data = text ? JSON.parse(text) : {};
515
+ break;
516
+ }
517
+ case "stream": return opts.responseStyle === "data" ? response.body : {
518
+ data: response.body,
519
+ ...result
520
+ };
521
+ }
522
+ if (parseAs === "json") {
523
+ if (opts.responseValidator) await opts.responseValidator(data);
524
+ if (opts.responseTransformer) data = await opts.responseTransformer(data);
525
+ }
526
+ return opts.responseStyle === "data" ? data : {
527
+ data,
528
+ ...result
529
+ };
530
+ }
531
+ const textError = await response.text();
532
+ let jsonError;
533
+ try {
534
+ jsonError = JSON.parse(textError);
535
+ } catch {}
536
+ throw jsonError ?? textError;
537
+ } catch (error) {
538
+ let finalError = error;
539
+ for (const fn of interceptors.error.fns) if (fn) finalError = await fn(finalError, response, request, options);
540
+ finalError = finalError || {};
541
+ if (throwOnError) throw finalError;
542
+ return responseStyle === "data" ? void 0 : {
543
+ error: finalError,
544
+ request,
545
+ response
546
+ };
547
+ }
548
+ };
549
+ const makeMethodFn = (method) => (options) => request({
550
+ ...options,
551
+ method
552
+ });
553
+ const makeSseFn = (method) => async (options) => {
554
+ const { opts, url } = await beforeRequest(options);
555
+ return createSseClient({
556
+ ...opts,
557
+ body: opts.body,
558
+ method,
559
+ onRequest: async (url, init) => {
560
+ let request = new Request(url, init);
561
+ for (const fn of interceptors.request.fns) if (fn) request = await fn(request, opts);
562
+ return request;
563
+ },
564
+ serializedBody: getValidRequestBody(opts),
565
+ url
566
+ });
567
+ };
568
+ const _buildUrl = (options) => buildUrl({
569
+ ..._config,
570
+ ...options
571
+ });
572
+ return {
573
+ buildUrl: _buildUrl,
574
+ connect: makeMethodFn("CONNECT"),
575
+ delete: makeMethodFn("DELETE"),
576
+ get: makeMethodFn("GET"),
577
+ getConfig,
578
+ head: makeMethodFn("HEAD"),
579
+ interceptors,
580
+ options: makeMethodFn("OPTIONS"),
581
+ patch: makeMethodFn("PATCH"),
582
+ post: makeMethodFn("POST"),
583
+ put: makeMethodFn("PUT"),
584
+ request,
585
+ setConfig,
586
+ sse: {
587
+ connect: makeSseFn("CONNECT"),
588
+ delete: makeSseFn("DELETE"),
589
+ get: makeSseFn("GET"),
590
+ head: makeSseFn("HEAD"),
591
+ options: makeSseFn("OPTIONS"),
592
+ patch: makeSseFn("PATCH"),
593
+ post: makeSseFn("POST"),
594
+ put: makeSseFn("PUT"),
595
+ trace: makeSseFn("TRACE")
596
+ },
597
+ trace: makeMethodFn("TRACE")
598
+ };
599
+ };
600
+ //#endregion
601
+ //#region src/generated/client.gen.ts
602
+ const client = createClient(createConfig());
603
+ //#endregion
604
+ //#region src/generated/sdk.gen.ts
605
+ var Agents = class {
606
+ /**
607
+ * List agents
608
+ *
609
+ * Lists the agents in the project.
610
+ */
611
+ static listAgents(options) {
612
+ return (options.client ?? client).get({
613
+ url: "/v1/projects/{project_id}/agents",
614
+ ...options
615
+ });
616
+ }
617
+ /**
618
+ * Create an agent
619
+ *
620
+ * Create an agent bound to one of the project's providers (provider_id), optionally attaching tools (tool_ids). See AgentCreate for the runtime config fields.
621
+ *
622
+ */
623
+ static createAgent(options) {
624
+ return (options.client ?? client).post({
625
+ url: "/v1/projects/{project_id}/agents",
626
+ ...options,
627
+ headers: {
628
+ "Content-Type": "application/json",
629
+ ...options.headers
630
+ }
631
+ });
632
+ }
633
+ /**
634
+ * Delete an agent
635
+ *
636
+ * Deletes the backing SOAT agent. Returns 409 if the agent still has dependent generations or traces — pass `force=true` to delete those along with the agent (destructive and irreversible).
637
+ *
638
+ */
639
+ static deleteAgent(options) {
640
+ return (options.client ?? client).delete({
641
+ url: "/v1/projects/{project_id}/agents/{agent_id}",
642
+ ...options
643
+ });
644
+ }
645
+ /**
646
+ * Get an agent
647
+ */
648
+ static getAgent(options) {
649
+ return (options.client ?? client).get({
650
+ url: "/v1/projects/{project_id}/agents/{agent_id}",
651
+ ...options
652
+ });
653
+ }
654
+ /**
655
+ * Update an agent
656
+ *
657
+ * Change the bound provider, name, model, instructions, sampling/step config, attached tools (tool_ids/tool_choice), or the naturali-side status. At least one field is required.
658
+ *
659
+ */
660
+ static updateAgent(options) {
661
+ return (options.client ?? client).patch({
662
+ url: "/v1/projects/{project_id}/agents/{agent_id}",
663
+ ...options,
664
+ headers: {
665
+ "Content-Type": "application/json",
666
+ ...options.headers
667
+ }
668
+ });
669
+ }
670
+ };
671
+ var ApiKeys = class {
672
+ /**
673
+ * List API keys
674
+ *
675
+ * Lists API keys accessible to the caller. A project-scoped credential sees only keys in its project; an account-scoped credential sees all keys in the account. Raw secrets are never returned.
676
+ *
677
+ */
678
+ static listApiKeys(options) {
679
+ return (options?.client ?? client).get({
680
+ url: "/v1/api-keys",
681
+ ...options
682
+ });
683
+ }
684
+ /**
685
+ * Create an API key
686
+ *
687
+ * Creates an API key. When `project_id` is set the key is scoped to that project (the default and recommended stance); omit it for an account-scoped key. `capabilities` narrows what the key may do; when omitted the key inherits the creator's capabilities. The raw `key` (nat_sk_…) is returned only in this response.
688
+ *
689
+ */
690
+ static createApiKey(options) {
691
+ return (options.client ?? client).post({
692
+ url: "/v1/api-keys",
693
+ ...options,
694
+ headers: {
695
+ "Content-Type": "application/json",
696
+ ...options.headers
697
+ }
698
+ });
699
+ }
700
+ /**
701
+ * Revoke an API key
702
+ *
703
+ * Revokes an API key immediately. Subsequent use returns 401.
704
+ */
705
+ static deleteApiKey(options) {
706
+ return (options.client ?? client).delete({
707
+ url: "/v1/api-keys/{api_key_id}",
708
+ ...options
709
+ });
710
+ }
711
+ /**
712
+ * Get an API key
713
+ *
714
+ * Returns metadata for an API key. The raw secret is never returned after creation.
715
+ */
716
+ static getApiKey(options) {
717
+ return (options.client ?? client).get({
718
+ url: "/v1/api-keys/{api_key_id}",
719
+ ...options
720
+ });
721
+ }
722
+ /**
723
+ * Update an API key
724
+ *
725
+ * Rename an API key or replace its capability set. The scope (project vs account) is immutable.
726
+ */
727
+ static updateApiKey(options) {
728
+ return (options.client ?? client).patch({
729
+ url: "/v1/api-keys/{api_key_id}",
730
+ ...options,
731
+ headers: {
732
+ "Content-Type": "application/json",
733
+ ...options.headers
734
+ }
735
+ });
736
+ }
737
+ /**
738
+ * Rotate an API key
739
+ *
740
+ * Issues a new secret for the same key record (same id, scope and capabilities) and invalidates the previous secret. The new raw `key` is returned only in this response.
741
+ *
742
+ */
743
+ static rotateApiKey(options) {
744
+ return (options.client ?? client).post({
745
+ url: "/v1/api-keys/{api_key_id}:rotate",
746
+ ...options
747
+ });
748
+ }
749
+ };
750
+ var Auth = class {
751
+ /**
752
+ * Create an account
753
+ *
754
+ * Creates a user and opens a session. A verification email is sent separately; unverified accounts may be limited until verified.
755
+ *
756
+ */
757
+ static signup(options) {
758
+ return (options.client ?? client).post({
759
+ url: "/v1/auth/signup",
760
+ ...options,
761
+ headers: {
762
+ "Content-Type": "application/json",
763
+ ...options.headers
764
+ }
765
+ });
766
+ }
767
+ /**
768
+ * Log in
769
+ *
770
+ * Exchanges email + password for an access JWT and a refresh token.
771
+ */
772
+ static login(options) {
773
+ return (options.client ?? client).post({
774
+ url: "/v1/auth/login",
775
+ ...options,
776
+ headers: {
777
+ "Content-Type": "application/json",
778
+ ...options.headers
779
+ }
780
+ });
781
+ }
782
+ /**
783
+ * Refresh a session
784
+ *
785
+ * Exchanges a valid refresh token for a new access JWT and a rotated refresh token. Refresh tokens are single-use; presenting a previously-rotated token is treated as reuse and revokes the whole session family (createRefreshRotation reuse detection).
786
+ *
787
+ */
788
+ static refreshSession(options) {
789
+ return (options.client ?? client).post({
790
+ url: "/v1/auth/refresh",
791
+ ...options,
792
+ headers: {
793
+ "Content-Type": "application/json",
794
+ ...options.headers
795
+ }
796
+ });
797
+ }
798
+ /**
799
+ * Log out
800
+ *
801
+ * Revokes the current refresh token (and its rotation family). Pass `all: true` to revoke every active session for the user.
802
+ *
803
+ */
804
+ static logout(options) {
805
+ return (options?.client ?? client).post({
806
+ url: "/v1/auth/logout",
807
+ ...options,
808
+ headers: {
809
+ "Content-Type": "application/json",
810
+ ...options?.headers
811
+ }
812
+ });
813
+ }
814
+ /**
815
+ * Request a password reset
816
+ *
817
+ * Sends a password-reset email if the address has an account. Always responds 202 so account existence is never leaked.
818
+ *
819
+ */
820
+ static requestPasswordReset(options) {
821
+ return (options.client ?? client).post({
822
+ url: "/v1/auth/password/reset-request",
823
+ ...options,
824
+ headers: {
825
+ "Content-Type": "application/json",
826
+ ...options.headers
827
+ }
828
+ });
829
+ }
830
+ /**
831
+ * Complete a password reset
832
+ *
833
+ * Sets a new password using a valid one-time reset token, then revokes existing sessions.
834
+ */
835
+ static confirmPasswordReset(options) {
836
+ return (options.client ?? client).post({
837
+ url: "/v1/auth/password/reset",
838
+ ...options,
839
+ headers: {
840
+ "Content-Type": "application/json",
841
+ ...options.headers
842
+ }
843
+ });
844
+ }
845
+ /**
846
+ * Verify an email address
847
+ *
848
+ * Confirms an email address using a one-time verification token.
849
+ */
850
+ static verifyEmail(options) {
851
+ return (options.client ?? client).post({
852
+ url: "/v1/auth/verify-email",
853
+ ...options,
854
+ headers: {
855
+ "Content-Type": "application/json",
856
+ ...options.headers
857
+ }
858
+ });
859
+ }
860
+ /**
861
+ * Get the current identity
862
+ *
863
+ * Returns the user behind the presented access token.
864
+ */
865
+ static getCurrentUser(options) {
866
+ return (options?.client ?? client).get({
867
+ url: "/v1/auth/me",
868
+ ...options
869
+ });
870
+ }
871
+ };
872
+ var Channels = class {
873
+ /**
874
+ * List channels
875
+ *
876
+ * Lists the channels connected in the project.
877
+ */
878
+ static listChannels(options) {
879
+ return (options.client ?? client).get({
880
+ url: "/v1/projects/{project_id}/channels",
881
+ ...options
882
+ });
883
+ }
884
+ /**
885
+ * Connect a channel
886
+ *
887
+ * Connect a channel. The required fields depend on `channel`; no credential is ever returned.
888
+ * **Discord** (`channel: discord`) — supply `application_id` and `bot_token`, plus the `modes` selecting which Gateway flows to serve (direct messages, and/or @mention-opens-a-thread). Returns `501` when the deployment has no `CHANNEL_TOKEN_KEY` configured.
889
+ * **WhatsApp** (default) — one of two credential paths, both filling the same write-only secret:
890
+ * * **BYOT** (`credential_source: byot`, default) — supply
891
+ * `phone_number_id` and `access_token` from your own Meta app.
892
+ *
893
+ * * **Embedded signup** (`credential_source: embedded_signup`) — supply
894
+ * `code` and `waba_id` (and optionally `pin`) from the Meta popup;
895
+ * naturali exchanges the `code` for the token and subscribes its app to
896
+ * the WABA, so the customer never hands over a token. Returns `501` on
897
+ * deployments where Meta App credentials are not configured.
898
+ *
899
+ */
900
+ static createChannel(options) {
901
+ return (options.client ?? client).post({
902
+ url: "/v1/projects/{project_id}/channels",
903
+ ...options,
904
+ headers: {
905
+ "Content-Type": "application/json",
906
+ ...options.headers
907
+ }
908
+ });
909
+ }
910
+ /**
911
+ * Delete a channel
912
+ *
913
+ * Deletes the channel and whatever it provisioned — the WhatsApp send tool and write-only credential secret, or the Discord channel's sealed bot token (dropped with the row, closing its gateway connection).
914
+ *
915
+ */
916
+ static deleteChannel(options) {
917
+ return (options.client ?? client).delete({
918
+ url: "/v1/projects/{project_id}/channels/{channel_id}",
919
+ ...options
920
+ });
921
+ }
922
+ /**
923
+ * Get a channel
924
+ */
925
+ static getChannel(options) {
926
+ return (options.client ?? client).get({
927
+ url: "/v1/projects/{project_id}/channels/{channel_id}",
928
+ ...options
929
+ });
930
+ }
931
+ /**
932
+ * Update a channel
933
+ *
934
+ * Rotate the credential, update the kind's config (`waba_id` / `credential_source` for WhatsApp, `modes` for Discord), or flip the naturali-side status. At least one field is required. Rotating a WhatsApp token stores a new write-only secret, repoints the send tool and deletes the old secret; rotating a Discord bot token reseals it and the gateway worker reconnects with it.
935
+ *
936
+ */
937
+ static updateChannel(options) {
938
+ return (options.client ?? client).patch({
939
+ url: "/v1/projects/{project_id}/channels/{channel_id}",
940
+ ...options,
941
+ headers: {
942
+ "Content-Type": "application/json",
943
+ ...options.headers
944
+ }
945
+ });
946
+ }
947
+ /**
948
+ * Unbind the channel
949
+ */
950
+ static deleteChannelBinding(options) {
951
+ return (options.client ?? client).delete({
952
+ url: "/v1/projects/{project_id}/channels/{channel_id}/binding",
953
+ ...options
954
+ });
955
+ }
956
+ /**
957
+ * Get the channel's binding
958
+ */
959
+ static getChannelBinding(options) {
960
+ return (options.client ?? client).get({
961
+ url: "/v1/projects/{project_id}/channels/{channel_id}/binding",
962
+ ...options
963
+ });
964
+ }
965
+ /**
966
+ * Set the channel's binding
967
+ *
968
+ * Create or replace the channel's agent binding (a channel has one binding in v1). `agent_id` is required and must be an agent owned in the project; `language` / `config` / `status` default to null / null / active when absent (full replace).
969
+ *
970
+ */
971
+ static setChannelBinding(options) {
972
+ return (options.client ?? client).put({
973
+ url: "/v1/projects/{project_id}/channels/{channel_id}/binding",
974
+ ...options,
975
+ headers: {
976
+ "Content-Type": "application/json",
977
+ ...options.headers
978
+ }
979
+ });
980
+ }
981
+ /**
982
+ * List the channel's conversations
983
+ *
984
+ * A cursor page of the channel's conversations, newest first. A conversation is one contact's dialogue on the channel — the continuity anchor that resumes the same SOAT session instead of starting fresh per message — so this is the read path for who has talked to the channel and which actor/session their dialogue resolved to.
985
+ * Conversations are created by the inbound path (the WhatsApp webhook, the Discord gateway worker) when a real message arrives; there is no way to create one directly.
986
+ *
987
+ */
988
+ static listChannelConversations(options) {
989
+ return (options.client ?? client).get({
990
+ url: "/v1/projects/{project_id}/channels/{channel_id}/conversations",
991
+ ...options
992
+ });
993
+ }
994
+ /**
995
+ * Get a conversation
996
+ */
997
+ static getChannelConversation(options) {
998
+ return (options.client ?? client).get({
999
+ url: "/v1/projects/{project_id}/channels/{channel_id}/conversations/{conversation_id}",
1000
+ ...options
1001
+ });
1002
+ }
1003
+ /**
1004
+ * Read a conversation's transcript
1005
+ *
1006
+ * The conversation's messages, oldest first. naturali stores no message bodies — the dialogue lives in the SOAT session the conversation maps to, so this reads through to SOAT. Pagination is `limit`/`offset` rather than an opaque cursor because the upstream is offset-based over a stable `position` ordering.
1007
+ *
1008
+ */
1009
+ static listChannelConversationMessages(options) {
1010
+ return (options.client ?? client).get({
1011
+ url: "/v1/projects/{project_id}/channels/{channel_id}/conversations/{conversation_id}/messages",
1012
+ ...options
1013
+ });
1014
+ }
1015
+ };
1016
+ var Contacts = class {
1017
+ /**
1018
+ * List contacts
1019
+ *
1020
+ * A cursor page of the project's contacts, newest first.
1021
+ * `channel` + `identifier` (supplied together) is the identity lookup — "who is this phone number?" — and returns at most one contact, following the merge pointer to whoever holds the identifier today. `external_id` asks the same question from the customer's side of the mapping. Contacts merged away are omitted unless `include_merged` asks for them.
1022
+ *
1023
+ */
1024
+ static listContacts(options) {
1025
+ return (options.client ?? client).get({
1026
+ url: "/v1/projects/{project_id}/contacts",
1027
+ ...options
1028
+ });
1029
+ }
1030
+ /**
1031
+ * Create a contact
1032
+ *
1033
+ * Record a contact the customer already knows about, optionally with the identifiers it is expected to arrive at.
1034
+ * Optional by design — the inbound path creates contacts on its own. This is for the embedder who has a user in their own system and wants naturali to agree about who that is before the first message, which is what makes `external_id` (and, through it, a session's `tool_context`) useful. No SOAT actor is created here; the contact gets one on first need.
1035
+ *
1036
+ */
1037
+ static createContact(options) {
1038
+ return (options.client ?? client).post({
1039
+ url: "/v1/projects/{project_id}/contacts",
1040
+ ...options,
1041
+ headers: {
1042
+ "Content-Type": "application/json",
1043
+ ...options.headers
1044
+ }
1045
+ });
1046
+ }
1047
+ /**
1048
+ * Erase a contact
1049
+ *
1050
+ * **Erasure (C4/LGPD).** Not a soft delete and not reversible: the contact's sessions — with their messages and media — its SOAT actor, its memory container and every identifier it was reachable at are removed, along with the merge records that reference it.
1051
+ * The upstream deletes happen first, so a failure there aborts before the local pointers are dropped and a retry can still find what is left. A contact that was merged into another cannot be erased directly: its data lives with the survivor, so erase that one.
1052
+ *
1053
+ */
1054
+ static deleteContact(options) {
1055
+ return (options.client ?? client).delete({
1056
+ url: "/v1/projects/{project_id}/contacts/{contact_id}",
1057
+ ...options
1058
+ });
1059
+ }
1060
+ /**
1061
+ * Get a contact
1062
+ */
1063
+ static getContact(options) {
1064
+ return (options.client ?? client).get({
1065
+ url: "/v1/projects/{project_id}/contacts/{contact_id}",
1066
+ ...options
1067
+ });
1068
+ }
1069
+ /**
1070
+ * Update a contact
1071
+ *
1072
+ * Retune the customer-owned fields. At least one is required. Identities are attached and detached through their own sub-resource, because each one is a claim about reachability rather than a property of the record.
1073
+ *
1074
+ */
1075
+ static updateContact(options) {
1076
+ return (options.client ?? client).patch({
1077
+ url: "/v1/projects/{project_id}/contacts/{contact_id}",
1078
+ ...options,
1079
+ headers: {
1080
+ "Content-Type": "application/json",
1081
+ ...options.headers
1082
+ }
1083
+ });
1084
+ }
1085
+ /**
1086
+ * Attach an identity
1087
+ *
1088
+ * Attach a `(channel, identifier)` pair — the manual half of what the inbound path does automatically, and the way a customer tells naturali that a number it has never seen belongs to a user it already knows. The identifier must be free (C3).
1089
+ *
1090
+ */
1091
+ static createContactIdentity(options) {
1092
+ return (options.client ?? client).post({
1093
+ url: "/v1/projects/{project_id}/contacts/{contact_id}/identities",
1094
+ ...options,
1095
+ headers: {
1096
+ "Content-Type": "application/json",
1097
+ ...options.headers
1098
+ }
1099
+ });
1100
+ }
1101
+ /**
1102
+ * Detach an identity
1103
+ *
1104
+ * Detach an identifier attached in error. Refused with `identity_in_use` once a dialogue hangs off it: dropping an identifier with history is erasure wearing a smaller name, and erasure has its own route that actually removes the messages instead of orphaning them.
1105
+ *
1106
+ */
1107
+ static deleteContactIdentity(options) {
1108
+ return (options.client ?? client).delete({
1109
+ url: "/v1/projects/{project_id}/contacts/{contact_id}/identities/{identity_id}",
1110
+ ...options
1111
+ });
1112
+ }
1113
+ /**
1114
+ * List the contact's conversations
1115
+ *
1116
+ * Every dialogue the contact has, across channels, newest first. The channel-scoped list answers "who has talked to this number?"; this one answers "where has this human talked to us?" — the read that makes a merge visible, since both channels' rows then appear under one contact.
1117
+ *
1118
+ */
1119
+ static listContactConversations(options) {
1120
+ return (options.client ?? client).get({
1121
+ url: "/v1/projects/{project_id}/contacts/{contact_id}/conversations",
1122
+ ...options
1123
+ });
1124
+ }
1125
+ /**
1126
+ * Merge another contact into this one
1127
+ *
1128
+ * Fold `source_contact_id` into this contact — "same human, two identifiers" (C4).
1129
+ * What moves: every identity and every conversation, so the survivor's history is the union of both. What is *shared* rather than moved: agent memory — SOAT hangs it off the actor, so the source's actor is re-pointed at the survivor's memory container and both keep answering with one recollection. Existing sessions keep working, which is the point of not rewriting them.
1130
+ * The source is not deleted: it stays as a tombstone pointing at the survivor, and the returned merge record lists exactly what moved, so the merge can be audited and reverted.
1131
+ *
1132
+ */
1133
+ static mergeContact(options) {
1134
+ return (options.client ?? client).post({
1135
+ url: "/v1/projects/{project_id}/contacts/{contact_id}:merge",
1136
+ ...options,
1137
+ headers: {
1138
+ "Content-Type": "application/json",
1139
+ ...options.headers
1140
+ }
1141
+ });
1142
+ }
1143
+ /**
1144
+ * List the contact's merges
1145
+ *
1146
+ * The contact's merge history, newest first, from both sides: the merges it absorbed and the one that absorbed it. The audit half of C4.
1147
+ *
1148
+ */
1149
+ static listContactMerges(options) {
1150
+ return (options.client ?? client).get({
1151
+ url: "/v1/projects/{project_id}/contacts/{contact_id}/merges",
1152
+ ...options
1153
+ });
1154
+ }
1155
+ /**
1156
+ * Revert a merge
1157
+ *
1158
+ * Undo a merge (C4). Replays the record backwards: the identities and conversations it lists go back to the source, the source's actor is re-pointed at the memory it had before, and the tombstone becomes a contact again. Anything that arrived *after* the merge stays with the survivor — it was never the source's.
1159
+ * Only the merge still in force can be reverted; a source that has since been merged somewhere else has to be unwound from the top (`merge_superseded`).
1160
+ *
1161
+ */
1162
+ static revertContactMerge(options) {
1163
+ return (options.client ?? client).post({
1164
+ url: "/v1/projects/{project_id}/contacts/{contact_id}/merges/{merge_id}:revert",
1165
+ ...options
1166
+ });
1167
+ }
1168
+ };
1169
+ var Generations = class {
1170
+ /**
1171
+ * List an agent's generations
1172
+ *
1173
+ * Lists the generation records the agent has produced, newest first. Filter by lifecycle `status` to find the failures without paging everything the agent has ever run.
1174
+ *
1175
+ */
1176
+ static listAgentGenerations(options) {
1177
+ return (options.client ?? client).get({
1178
+ url: "/v1/projects/{project_id}/agents/{agent_id}/generations",
1179
+ ...options
1180
+ });
1181
+ }
1182
+ /**
1183
+ * Run an agent generation
1184
+ *
1185
+ * Sends messages to the agent, resolves its tools, and runs the model loop. Returns the final text when `status` is `completed` (plus `object` when the agent has an output schema), or the pending `tool_calls` when `status` is `requires_action`. With `stream: true` the response is a Server-Sent Events stream (Content-Type text/event-stream) proxied from SOAT instead of a single JSON body.
1186
+ *
1187
+ */
1188
+ static createGeneration(options) {
1189
+ return (options.client ?? client).post({
1190
+ url: "/v1/projects/{project_id}/agents/{agent_id}/generations",
1191
+ ...options,
1192
+ headers: {
1193
+ "Content-Type": "application/json",
1194
+ ...options.headers
1195
+ }
1196
+ });
1197
+ }
1198
+ /**
1199
+ * Get a generation
1200
+ *
1201
+ * Returns one generation record. Flat rather than nested under the agent, because the ids that need resolving arrive on their own — a session reply carries a `generation_id` with no agent in hand.
1202
+ * A generation belonging to another project responds `404`, not `403` — the API never confirms that an id exists elsewhere.
1203
+ *
1204
+ */
1205
+ static getGeneration(options) {
1206
+ return (options.client ?? client).get({
1207
+ url: "/v1/projects/{project_id}/generations/{generation_id}",
1208
+ ...options
1209
+ });
1210
+ }
1211
+ };
1212
+ var Knowledge = class {
1213
+ /**
1214
+ * List collections
1215
+ *
1216
+ * Lists the knowledge collections in the project.
1217
+ */
1218
+ static listKnowledgeCollections(options) {
1219
+ return (options.client ?? client).get({
1220
+ url: "/v1/projects/{project_id}/knowledge/collections",
1221
+ ...options
1222
+ });
1223
+ }
1224
+ /**
1225
+ * Create a collection
1226
+ *
1227
+ * Create a knowledge collection. The name is the key manifests reference (an agent's `knowledge:` block) and must be unique within the project.
1228
+ *
1229
+ */
1230
+ static createKnowledgeCollection(options) {
1231
+ return (options.client ?? client).post({
1232
+ url: "/v1/projects/{project_id}/knowledge/collections",
1233
+ ...options,
1234
+ headers: {
1235
+ "Content-Type": "application/json",
1236
+ ...options.headers
1237
+ }
1238
+ });
1239
+ }
1240
+ /**
1241
+ * Delete a collection
1242
+ *
1243
+ * Deletes an empty collection. Returns 409 if the collection still has documents (delete them first).
1244
+ *
1245
+ */
1246
+ static deleteKnowledgeCollection(options) {
1247
+ return (options.client ?? client).delete({
1248
+ url: "/v1/projects/{project_id}/knowledge/collections/{collection_id}",
1249
+ ...options
1250
+ });
1251
+ }
1252
+ /**
1253
+ * Get a collection
1254
+ */
1255
+ static getKnowledgeCollection(options) {
1256
+ return (options.client ?? client).get({
1257
+ url: "/v1/projects/{project_id}/knowledge/collections/{collection_id}",
1258
+ ...options
1259
+ });
1260
+ }
1261
+ /**
1262
+ * Update a collection
1263
+ *
1264
+ * Rename the collection or edit its description. At least one field is required.
1265
+ */
1266
+ static updateKnowledgeCollection(options) {
1267
+ return (options.client ?? client).patch({
1268
+ url: "/v1/projects/{project_id}/knowledge/collections/{collection_id}",
1269
+ ...options,
1270
+ headers: {
1271
+ "Content-Type": "application/json",
1272
+ ...options.headers
1273
+ }
1274
+ });
1275
+ }
1276
+ /**
1277
+ * Query a collection (retrieval preview)
1278
+ *
1279
+ * Retrieval preview (API.md §4, K5): returns the chunks the collection would surface for a question — debuggable standalone, before any agent is bound to it. This is the `…:query` action; the path segment is `{collection_id}:query`.
1280
+ *
1281
+ */
1282
+ static queryKnowledgeCollection(options) {
1283
+ return (options.client ?? client).post({
1284
+ url: "/v1/projects/{project_id}/knowledge/collections/{collection_id}",
1285
+ ...options,
1286
+ headers: {
1287
+ "Content-Type": "application/json",
1288
+ ...options.headers
1289
+ }
1290
+ });
1291
+ }
1292
+ /**
1293
+ * List documents
1294
+ *
1295
+ * Lists the documents in the collection, with their ingestion status.
1296
+ */
1297
+ static listKnowledgeDocuments(options) {
1298
+ return (options.client ?? client).get({
1299
+ url: "/v1/projects/{project_id}/knowledge/collections/{collection_id}/documents",
1300
+ ...options
1301
+ });
1302
+ }
1303
+ /**
1304
+ * Create a document
1305
+ *
1306
+ * Add an inline-text document to the collection. The platform ingests the content (chunk + embed) and records the document's ingestion status. File upload (PDF/binary) is a deliberate follow-up.
1307
+ *
1308
+ */
1309
+ static createKnowledgeDocument(options) {
1310
+ return (options.client ?? client).post({
1311
+ url: "/v1/projects/{project_id}/knowledge/collections/{collection_id}/documents",
1312
+ ...options,
1313
+ headers: {
1314
+ "Content-Type": "application/json",
1315
+ ...options.headers
1316
+ }
1317
+ });
1318
+ }
1319
+ /**
1320
+ * Delete a document
1321
+ */
1322
+ static deleteKnowledgeDocument(options) {
1323
+ return (options.client ?? client).delete({
1324
+ url: "/v1/projects/{project_id}/knowledge/collections/{collection_id}/documents/{document_id}",
1325
+ ...options
1326
+ });
1327
+ }
1328
+ /**
1329
+ * Get a document
1330
+ *
1331
+ * Returns the document, including its text content when ingestion is complete.
1332
+ */
1333
+ static getKnowledgeDocument(options) {
1334
+ return (options.client ?? client).get({
1335
+ url: "/v1/projects/{project_id}/knowledge/collections/{collection_id}/documents/{document_id}",
1336
+ ...options
1337
+ });
1338
+ }
1339
+ /**
1340
+ * Re-ingest a document
1341
+ *
1342
+ * Re-run ingestion for a document against its stored source, resetting it to `pending` before re-processing — the recovery path for a `failed` ingest (API.md §4, K1). This is the `…:reingest` action; the path segment is `{document_id}:reingest`.
1343
+ *
1344
+ */
1345
+ static reingestKnowledgeDocument(options) {
1346
+ return (options.client ?? client).post({
1347
+ url: "/v1/projects/{project_id}/knowledge/collections/{collection_id}/documents/{document_id}",
1348
+ ...options
1349
+ });
1350
+ }
1351
+ };
1352
+ var Models = class {
1353
+ /**
1354
+ * List models
1355
+ *
1356
+ * Lists catalog models, newest sources merged and sorted by id. Filter by vendor, provider, output/input modality or status.
1357
+ *
1358
+ */
1359
+ static listModels(options) {
1360
+ return (options?.client ?? client).get({
1361
+ url: "/v1/models",
1362
+ ...options
1363
+ });
1364
+ }
1365
+ /**
1366
+ * Get a model
1367
+ */
1368
+ static getModel(options) {
1369
+ return (options.client ?? client).get({
1370
+ url: "/v1/models/{model_id}",
1371
+ ...options
1372
+ });
1373
+ }
1374
+ };
1375
+ var Projects = class {
1376
+ /**
1377
+ * List projects
1378
+ *
1379
+ * Lists projects accessible to the caller.
1380
+ */
1381
+ static listProjects(options) {
1382
+ return (options?.client ?? client).get({
1383
+ url: "/v1/projects",
1384
+ ...options
1385
+ });
1386
+ }
1387
+ /**
1388
+ * Create a project
1389
+ *
1390
+ * Creates a project (one per client or per environment).
1391
+ */
1392
+ static createProject(options) {
1393
+ return (options.client ?? client).post({
1394
+ url: "/v1/projects",
1395
+ ...options,
1396
+ headers: {
1397
+ "Content-Type": "application/json",
1398
+ ...options.headers
1399
+ }
1400
+ });
1401
+ }
1402
+ /**
1403
+ * Delete a project
1404
+ *
1405
+ * Permanently deletes the project and its backing SOAT project. Fails with 409 if the SOAT project still has dependent resources — remove them first, or pass `force=true` to delete the project and all its dependents (agents, providers, tools, sessions, generations, traces). Forcing is destructive and irreversible.
1406
+ *
1407
+ */
1408
+ static deleteProject(options) {
1409
+ return (options.client ?? client).delete({
1410
+ url: "/v1/projects/{project_id}",
1411
+ ...options
1412
+ });
1413
+ }
1414
+ /**
1415
+ * Get a project
1416
+ */
1417
+ static getProject(options) {
1418
+ return (options.client ?? client).get({
1419
+ url: "/v1/projects/{project_id}",
1420
+ ...options
1421
+ });
1422
+ }
1423
+ /**
1424
+ * Update a project
1425
+ *
1426
+ * Rename or archive a project. Archiving is reversible; resources are retained.
1427
+ */
1428
+ static updateProject(options) {
1429
+ return (options.client ?? client).patch({
1430
+ url: "/v1/projects/{project_id}",
1431
+ ...options,
1432
+ headers: {
1433
+ "Content-Type": "application/json",
1434
+ ...options.headers
1435
+ }
1436
+ });
1437
+ }
1438
+ /**
1439
+ * Get per-project usage
1440
+ *
1441
+ * The per-project meter — the re-billing view (A11/C12/P3). Aggregates the project's usage over an optional [from, to] window, bucketed by a single dimension. Costs are the billing-grade cost_usd SOAT freezes at write time; null means nothing in the bucket was priced (never that it was free). Only managed providers are priced (on SOAT), so cost reflects managed usage; BYOK usage carries no LLM cost.
1442
+ *
1443
+ */
1444
+ static getProjectUsage(options) {
1445
+ return (options.client ?? client).get({
1446
+ url: "/v1/projects/{project_id}/usage",
1447
+ ...options
1448
+ });
1449
+ }
1450
+ };
1451
+ var Providers = class {
1452
+ /**
1453
+ * List providers
1454
+ *
1455
+ * Lists the AI providers registered in the project.
1456
+ */
1457
+ static listProviders(options) {
1458
+ return (options.client ?? client).get({
1459
+ url: "/v1/projects/{project_id}/providers",
1460
+ ...options
1461
+ });
1462
+ }
1463
+ /**
1464
+ * Register a provider (managed or BYOK)
1465
+ *
1466
+ * Register a managed provider (naturali-keyed, priced on SOAT) or a BYOK provider (your credentials, stored write-only and never priced). See ProviderCreate for the fields each mode takes.
1467
+ *
1468
+ */
1469
+ static createProvider(options) {
1470
+ return (options.client ?? client).post({
1471
+ url: "/v1/projects/{project_id}/providers",
1472
+ ...options,
1473
+ headers: {
1474
+ "Content-Type": "application/json",
1475
+ ...options.headers
1476
+ }
1477
+ });
1478
+ }
1479
+ /**
1480
+ * Delete a provider
1481
+ *
1482
+ * Deletes the backing SOAT ai_provider and its secret. Returns 409 if the provider is still referenced by live resources (agents) — detach those first. `force=true` clears only soft dependents (price overrides, usage history); live references always block deletion.
1483
+ *
1484
+ */
1485
+ static deleteProvider(options) {
1486
+ return (options.client ?? client).delete({
1487
+ url: "/v1/projects/{project_id}/providers/{provider_id}",
1488
+ ...options
1489
+ });
1490
+ }
1491
+ /**
1492
+ * Get a provider
1493
+ */
1494
+ static getProvider(options) {
1495
+ return (options.client ?? client).get({
1496
+ url: "/v1/projects/{project_id}/providers/{provider_id}",
1497
+ ...options
1498
+ });
1499
+ }
1500
+ /**
1501
+ * Update a provider
1502
+ *
1503
+ * Change the model, name or base URL, rotate the credentials (api_key), or set the naturali-side status. At least one field is required.
1504
+ *
1505
+ */
1506
+ static updateProvider(options) {
1507
+ return (options.client ?? client).patch({
1508
+ url: "/v1/projects/{project_id}/providers/{provider_id}",
1509
+ ...options,
1510
+ headers: {
1511
+ "Content-Type": "application/json",
1512
+ ...options.headers
1513
+ }
1514
+ });
1515
+ }
1516
+ };
1517
+ var Sessions = class {
1518
+ /**
1519
+ * Open a session
1520
+ *
1521
+ * Opens a durable session against the agent. The session accumulates messages and is resumable by id; its lifecycle (open / closed / expired) and configuration live in the backing SOAT session.
1522
+ *
1523
+ */
1524
+ static createSession(options) {
1525
+ return (options.client ?? client).post({
1526
+ url: "/v1/projects/{project_id}/agents/{agent_id}/sessions",
1527
+ ...options,
1528
+ headers: {
1529
+ "Content-Type": "application/json",
1530
+ ...options.headers
1531
+ }
1532
+ });
1533
+ }
1534
+ /**
1535
+ * Get a session
1536
+ *
1537
+ * Returns the session's current state — status, activity timestamps and configuration — read live from the backing SOAT session, so a resumed session reflects everything that has happened since it was opened.
1538
+ *
1539
+ */
1540
+ static getSession(options) {
1541
+ return (options.client ?? client).get({
1542
+ url: "/v1/projects/{project_id}/agents/{agent_id}/sessions/{session_id}",
1543
+ ...options
1544
+ });
1545
+ }
1546
+ /**
1547
+ * Add a message
1548
+ *
1549
+ * Appends a user message to the session — plain `message` text or a `document_id`, exactly one of the two. `idempotency_key` makes the append safe to retry: a repeat with the same key returns the original message (HTTP 200) and triggers no new work. When the session has `auto_generate` on, the response is the agent's reply (a Generation shape) instead of the saved message.
1550
+ *
1551
+ */
1552
+ static addSessionMessage(options) {
1553
+ return (options.client ?? client).post({
1554
+ url: "/v1/projects/{project_id}/agents/{agent_id}/sessions/{session_id}/messages",
1555
+ ...options,
1556
+ headers: {
1557
+ "Content-Type": "application/json",
1558
+ ...options.headers
1559
+ }
1560
+ });
1561
+ }
1562
+ /**
1563
+ * Generate a response
1564
+ *
1565
+ * Runs the agent over the session's accumulated messages and returns its reply. `status` is `completed` with the assistant `message`, or `requires_action` with the pending `required_action` tool calls. `model` overrides the agent's default model for this turn only.
1566
+ *
1567
+ */
1568
+ static generateSessionResponse(options) {
1569
+ return (options.client ?? client).post({
1570
+ url: "/v1/projects/{project_id}/agents/{agent_id}/sessions/{session_id}/generate",
1571
+ ...options,
1572
+ headers: {
1573
+ "Content-Type": "application/json",
1574
+ ...options.headers
1575
+ }
1576
+ });
1577
+ }
1578
+ };
1579
+ var Tools = class {
1580
+ /**
1581
+ * List tools
1582
+ *
1583
+ * Lists the tools registered in the project.
1584
+ */
1585
+ static listTools(options) {
1586
+ return (options.client ?? client).get({
1587
+ url: "/v1/projects/{project_id}/tools",
1588
+ ...options
1589
+ });
1590
+ }
1591
+ /**
1592
+ * Create a tool
1593
+ *
1594
+ * Create an http or mcp tool in the project. See ToolCreate for the fields each type takes. Any auth headers are stored write-only and never returned.
1595
+ *
1596
+ */
1597
+ static createTool(options) {
1598
+ return (options.client ?? client).post({
1599
+ url: "/v1/projects/{project_id}/tools",
1600
+ ...options,
1601
+ headers: {
1602
+ "Content-Type": "application/json",
1603
+ ...options.headers
1604
+ }
1605
+ });
1606
+ }
1607
+ /**
1608
+ * Delete a tool
1609
+ *
1610
+ * Deletes the backing SOAT tool. Returns 409 if the tool is still attached to an agent (detach it first).
1611
+ *
1612
+ */
1613
+ static deleteTool(options) {
1614
+ return (options.client ?? client).delete({
1615
+ url: "/v1/projects/{project_id}/tools/{tool_id}",
1616
+ ...options
1617
+ });
1618
+ }
1619
+ /**
1620
+ * Get a tool
1621
+ */
1622
+ static getTool(options) {
1623
+ return (options.client ?? client).get({
1624
+ url: "/v1/projects/{project_id}/tools/{tool_id}",
1625
+ ...options
1626
+ });
1627
+ }
1628
+ /**
1629
+ * Update a tool
1630
+ *
1631
+ * Change the name, description, parameters, type-specific config (incl. rotating auth headers), or the naturali-side status. The tool `type` is immutable. At least one field is required.
1632
+ *
1633
+ */
1634
+ static updateTool(options) {
1635
+ return (options.client ?? client).patch({
1636
+ url: "/v1/projects/{project_id}/tools/{tool_id}",
1637
+ ...options,
1638
+ headers: {
1639
+ "Content-Type": "application/json",
1640
+ ...options.headers
1641
+ }
1642
+ });
1643
+ }
1644
+ };
1645
+ var Traces = class {
1646
+ /**
1647
+ * List traces
1648
+ *
1649
+ * Lists the project's execution traces, newest first.
1650
+ */
1651
+ static listTraces(options) {
1652
+ return (options.client ?? client).get({
1653
+ url: "/v1/projects/{project_id}/traces",
1654
+ ...options
1655
+ });
1656
+ }
1657
+ /**
1658
+ * Get a trace
1659
+ *
1660
+ * Returns one trace. A trace belonging to another project responds `404`, not `403` — the API never confirms that an id exists elsewhere.
1661
+ *
1662
+ */
1663
+ static getTrace(options) {
1664
+ return (options.client ?? client).get({
1665
+ url: "/v1/projects/{project_id}/traces/{trace_id}",
1666
+ ...options
1667
+ });
1668
+ }
1669
+ /**
1670
+ * Get a trace tree
1671
+ *
1672
+ * Returns the whole execution tree. Each node is one agent's execution; `children` are the traces its sub-agent tool calls started.
1673
+ * Asking for a child returns the tree from its root, so the response is the full execution either way — pass `include=generations` and one call is enough to render a finished run.
1674
+ *
1675
+ */
1676
+ static getTraceTree(options) {
1677
+ return (options.client ?? client).get({
1678
+ url: "/v1/projects/{project_id}/traces/{trace_id}/tree",
1679
+ ...options
1680
+ });
1681
+ }
1682
+ /**
1683
+ * List a trace's generations
1684
+ *
1685
+ * Lists the generations recorded under this trace — the model loops the execution ran, including sub-agent generations linked by `initiator_generation_id`.
1686
+ *
1687
+ */
1688
+ static listTraceGenerations(options) {
1689
+ return (options.client ?? client).get({
1690
+ url: "/v1/projects/{project_id}/traces/{trace_id}/generations",
1691
+ ...options
1692
+ });
1693
+ }
1694
+ };
1695
+ //#endregion
1696
+ //#region src/naturaliClient.ts
1697
+ /**
1698
+ * Wraps a generated static SDK class so every method is callable without
1699
+ * passing `client` — the configured client is injected into each call.
1700
+ *
1701
+ * The return type stays `T` (= `typeof <StaticClass>`), so callers keep full
1702
+ * auto-complete and type checking on arguments and results.
1703
+ */
1704
+ const bindResource = (SdkClass, client) => {
1705
+ return new Proxy(SdkClass, { get: (target, prop) => {
1706
+ const value = target[prop];
1707
+ if (typeof value === "function") return (options) => {
1708
+ return value({
1709
+ ...options,
1710
+ client
1711
+ });
1712
+ };
1713
+ return value;
1714
+ } });
1715
+ };
1716
+ /**
1717
+ * The naturali.ai API client.
1718
+ *
1719
+ * Create one and reuse it; each property is a resource whose methods mirror
1720
+ * the generated SDK exactly, with the configured HTTP client already bound.
1721
+ *
1722
+ * ```ts
1723
+ * import { NaturaliClient } from '@naturali/sdk';
1724
+ *
1725
+ * const naturali = new NaturaliClient({
1726
+ * baseUrl: 'https://api.naturali.ai',
1727
+ * token: process.env.NATURALI_TOKEN,
1728
+ * });
1729
+ *
1730
+ * const { data, error } = await naturali.sessions.addSessionMessage({
1731
+ * path: { project_id: PROJECT_ID, agent_id: AGENT_ID, session_id: SESSION_ID },
1732
+ * body: { role: 'user', content: 'What is the capital of France?' },
1733
+ * });
1734
+ * ```
1735
+ *
1736
+ * Every method resolves to `{ data, error }` rather than throwing on a non-2xx
1737
+ * response, so the platform's error envelope (`{ error: { code, message } }`)
1738
+ * is available as typed data.
1739
+ */
1740
+ var NaturaliClient = class {
1741
+ agents;
1742
+ apiKeys;
1743
+ auth;
1744
+ channels;
1745
+ contacts;
1746
+ generations;
1747
+ knowledge;
1748
+ models;
1749
+ projects;
1750
+ providers;
1751
+ sessions;
1752
+ tools;
1753
+ traces;
1754
+ /** The underlying HTTP client, for interceptors or one-off requests. */
1755
+ http;
1756
+ constructor({ baseUrl, token, headers } = {}) {
1757
+ this.http = createClient(createConfig({
1758
+ baseUrl: baseUrl ?? "",
1759
+ headers: {
1760
+ ...token ? { Authorization: `Bearer ${token}` } : {},
1761
+ ...headers
1762
+ }
1763
+ }));
1764
+ this.agents = bindResource(Agents, this.http);
1765
+ this.apiKeys = bindResource(ApiKeys, this.http);
1766
+ this.auth = bindResource(Auth, this.http);
1767
+ this.channels = bindResource(Channels, this.http);
1768
+ this.contacts = bindResource(Contacts, this.http);
1769
+ this.generations = bindResource(Generations, this.http);
1770
+ this.knowledge = bindResource(Knowledge, this.http);
1771
+ this.models = bindResource(Models, this.http);
1772
+ this.projects = bindResource(Projects, this.http);
1773
+ this.providers = bindResource(Providers, this.http);
1774
+ this.sessions = bindResource(Sessions, this.http);
1775
+ this.tools = bindResource(Tools, this.http);
1776
+ this.traces = bindResource(Traces, this.http);
1777
+ }
1778
+ };
1779
+ //#endregion
1780
+ export { Agents, ApiKeys, Auth, Channels, Contacts, Generations, Knowledge, Models, NaturaliClient, Projects, Providers, Sessions, Tools, Traces, createClient, createConfig };