@vectorize-io/hindsight-client 0.4.18 → 0.4.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/dist/{generated/types.gen.d.ts → index.d.mts} +1426 -362
  2. package/dist/index.d.ts +5384 -0
  3. package/dist/index.js +1597 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.mjs +1572 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/generated/client/client.gen.ts +3 -1
  8. package/generated/sdk.gen.ts +17 -0
  9. package/generated/types.gen.ts +63 -1
  10. package/package.json +15 -5
  11. package/src/index.ts +2 -0
  12. package/dist/generated/client/client.gen.d.ts +0 -3
  13. package/dist/generated/client/client.gen.d.ts.map +0 -1
  14. package/dist/generated/client/client.gen.js +0 -233
  15. package/dist/generated/client/client.gen.js.map +0 -1
  16. package/dist/generated/client/index.d.ts +0 -9
  17. package/dist/generated/client/index.d.ts.map +0 -1
  18. package/dist/generated/client/index.js +0 -18
  19. package/dist/generated/client/index.js.map +0 -1
  20. package/dist/generated/client/types.gen.d.ts +0 -118
  21. package/dist/generated/client/types.gen.d.ts.map +0 -1
  22. package/dist/generated/client/types.gen.js +0 -4
  23. package/dist/generated/client/types.gen.js.map +0 -1
  24. package/dist/generated/client/utils.gen.d.ts +0 -34
  25. package/dist/generated/client/utils.gen.d.ts.map +0 -1
  26. package/dist/generated/client/utils.gen.js +0 -245
  27. package/dist/generated/client/utils.gen.js.map +0 -1
  28. package/dist/generated/client.gen.d.ts +0 -13
  29. package/dist/generated/client.gen.d.ts.map +0 -1
  30. package/dist/generated/client.gen.js +0 -7
  31. package/dist/generated/client.gen.js.map +0 -1
  32. package/dist/generated/core/auth.gen.d.ts +0 -19
  33. package/dist/generated/core/auth.gen.d.ts.map +0 -1
  34. package/dist/generated/core/auth.gen.js +0 -19
  35. package/dist/generated/core/auth.gen.js.map +0 -1
  36. package/dist/generated/core/bodySerializer.gen.d.ts +0 -26
  37. package/dist/generated/core/bodySerializer.gen.d.ts.map +0 -1
  38. package/dist/generated/core/bodySerializer.gen.js +0 -61
  39. package/dist/generated/core/bodySerializer.gen.js.map +0 -1
  40. package/dist/generated/core/params.gen.d.ts +0 -44
  41. package/dist/generated/core/params.gen.d.ts.map +0 -1
  42. package/dist/generated/core/params.gen.js +0 -105
  43. package/dist/generated/core/params.gen.js.map +0 -1
  44. package/dist/generated/core/pathSerializer.gen.d.ts +0 -34
  45. package/dist/generated/core/pathSerializer.gen.d.ts.map +0 -1
  46. package/dist/generated/core/pathSerializer.gen.js +0 -124
  47. package/dist/generated/core/pathSerializer.gen.js.map +0 -1
  48. package/dist/generated/core/queryKeySerializer.gen.d.ts +0 -19
  49. package/dist/generated/core/queryKeySerializer.gen.d.ts.map +0 -1
  50. package/dist/generated/core/queryKeySerializer.gen.js +0 -106
  51. package/dist/generated/core/queryKeySerializer.gen.js.map +0 -1
  52. package/dist/generated/core/serverSentEvents.gen.d.ts +0 -72
  53. package/dist/generated/core/serverSentEvents.gen.d.ts.map +0 -1
  54. package/dist/generated/core/serverSentEvents.gen.js +0 -140
  55. package/dist/generated/core/serverSentEvents.gen.js.map +0 -1
  56. package/dist/generated/core/types.gen.d.ts +0 -79
  57. package/dist/generated/core/types.gen.d.ts.map +0 -1
  58. package/dist/generated/core/types.gen.js +0 -4
  59. package/dist/generated/core/types.gen.js.map +0 -1
  60. package/dist/generated/core/utils.gen.d.ts +0 -20
  61. package/dist/generated/core/utils.gen.d.ts.map +0 -1
  62. package/dist/generated/core/utils.gen.js +0 -94
  63. package/dist/generated/core/utils.gen.js.map +0 -1
  64. package/dist/generated/index.d.ts +0 -3
  65. package/dist/generated/index.d.ts.map +0 -1
  66. package/dist/generated/index.js +0 -19
  67. package/dist/generated/index.js.map +0 -1
  68. package/dist/generated/sdk.gen.d.ts +0 -433
  69. package/dist/generated/sdk.gen.d.ts.map +0 -1
  70. package/dist/generated/sdk.gen.js +0 -636
  71. package/dist/generated/sdk.gen.js.map +0 -1
  72. package/dist/generated/types.gen.d.ts.map +0 -1
  73. package/dist/generated/types.gen.js +0 -4
  74. package/dist/generated/types.gen.js.map +0 -1
  75. package/dist/src/index.d.ts +0 -310
  76. package/dist/src/index.d.ts.map +0 -1
  77. package/dist/src/index.js +0 -518
  78. package/dist/src/index.js.map +0 -1
package/dist/index.mjs ADDED
@@ -0,0 +1,1572 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // generated/core/bodySerializer.gen.ts
8
+ var serializeFormDataPair = (data, key, value) => {
9
+ if (typeof value === "string" || value instanceof Blob) {
10
+ data.append(key, value);
11
+ } else if (value instanceof Date) {
12
+ data.append(key, value.toISOString());
13
+ } else {
14
+ data.append(key, JSON.stringify(value));
15
+ }
16
+ };
17
+ var formDataBodySerializer = {
18
+ bodySerializer: (body) => {
19
+ const data = new FormData();
20
+ Object.entries(body).forEach(([key, value]) => {
21
+ if (value === void 0 || value === null) {
22
+ return;
23
+ }
24
+ if (Array.isArray(value)) {
25
+ value.forEach((v) => serializeFormDataPair(data, key, v));
26
+ } else {
27
+ serializeFormDataPair(data, key, value);
28
+ }
29
+ });
30
+ return data;
31
+ }
32
+ };
33
+ var jsonBodySerializer = {
34
+ bodySerializer: (body) => JSON.stringify(
35
+ body,
36
+ (_key, value) => typeof value === "bigint" ? value.toString() : value
37
+ )
38
+ };
39
+
40
+ // generated/core/params.gen.ts
41
+ var extraPrefixesMap = {
42
+ $body_: "body",
43
+ $headers_: "headers",
44
+ $path_: "path",
45
+ $query_: "query"
46
+ };
47
+ var extraPrefixes = Object.entries(extraPrefixesMap);
48
+
49
+ // generated/core/serverSentEvents.gen.ts
50
+ var createSseClient = ({
51
+ onRequest,
52
+ onSseError,
53
+ onSseEvent,
54
+ responseTransformer,
55
+ responseValidator,
56
+ sseDefaultRetryDelay,
57
+ sseMaxRetryAttempts,
58
+ sseMaxRetryDelay,
59
+ sseSleepFn,
60
+ url,
61
+ ...options
62
+ }) => {
63
+ let lastEventId;
64
+ const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
65
+ const createStream = async function* () {
66
+ let retryDelay = sseDefaultRetryDelay ?? 3e3;
67
+ let attempt = 0;
68
+ const signal = options.signal ?? new AbortController().signal;
69
+ while (true) {
70
+ if (signal.aborted) break;
71
+ attempt++;
72
+ const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
73
+ if (lastEventId !== void 0) {
74
+ headers.set("Last-Event-ID", lastEventId);
75
+ }
76
+ try {
77
+ const requestInit = {
78
+ redirect: "follow",
79
+ ...options,
80
+ body: options.serializedBody,
81
+ headers,
82
+ signal
83
+ };
84
+ let request = new Request(url, requestInit);
85
+ if (onRequest) {
86
+ request = await onRequest(url, requestInit);
87
+ }
88
+ const _fetch = options.fetch ?? globalThis.fetch;
89
+ const response = await _fetch(request);
90
+ if (!response.ok)
91
+ throw new Error(
92
+ `SSE failed: ${response.status} ${response.statusText}`
93
+ );
94
+ if (!response.body) throw new Error("No body in SSE response");
95
+ const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
96
+ let buffer = "";
97
+ const abortHandler = () => {
98
+ try {
99
+ reader.cancel();
100
+ } catch {
101
+ }
102
+ };
103
+ signal.addEventListener("abort", abortHandler);
104
+ try {
105
+ while (true) {
106
+ const { done, value } = await reader.read();
107
+ if (done) break;
108
+ buffer += value;
109
+ const chunks = buffer.split("\n\n");
110
+ buffer = chunks.pop() ?? "";
111
+ for (const chunk of chunks) {
112
+ const lines = chunk.split("\n");
113
+ const dataLines = [];
114
+ let eventName;
115
+ for (const line of lines) {
116
+ if (line.startsWith("data:")) {
117
+ dataLines.push(line.replace(/^data:\s*/, ""));
118
+ } else if (line.startsWith("event:")) {
119
+ eventName = line.replace(/^event:\s*/, "");
120
+ } else if (line.startsWith("id:")) {
121
+ lastEventId = line.replace(/^id:\s*/, "");
122
+ } else if (line.startsWith("retry:")) {
123
+ const parsed = Number.parseInt(
124
+ line.replace(/^retry:\s*/, ""),
125
+ 10
126
+ );
127
+ if (!Number.isNaN(parsed)) {
128
+ retryDelay = parsed;
129
+ }
130
+ }
131
+ }
132
+ let data;
133
+ let parsedJson = false;
134
+ if (dataLines.length) {
135
+ const rawData = dataLines.join("\n");
136
+ try {
137
+ data = JSON.parse(rawData);
138
+ parsedJson = true;
139
+ } catch {
140
+ data = rawData;
141
+ }
142
+ }
143
+ if (parsedJson) {
144
+ if (responseValidator) {
145
+ await responseValidator(data);
146
+ }
147
+ if (responseTransformer) {
148
+ data = await responseTransformer(data);
149
+ }
150
+ }
151
+ onSseEvent?.({
152
+ data,
153
+ event: eventName,
154
+ id: lastEventId,
155
+ retry: retryDelay
156
+ });
157
+ if (dataLines.length) {
158
+ yield data;
159
+ }
160
+ }
161
+ }
162
+ } finally {
163
+ signal.removeEventListener("abort", abortHandler);
164
+ reader.releaseLock();
165
+ }
166
+ break;
167
+ } catch (error) {
168
+ onSseError?.(error);
169
+ if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
170
+ break;
171
+ }
172
+ const backoff = Math.min(
173
+ retryDelay * 2 ** (attempt - 1),
174
+ sseMaxRetryDelay ?? 3e4
175
+ );
176
+ await sleep(backoff);
177
+ }
178
+ }
179
+ };
180
+ const stream = createStream();
181
+ return { stream };
182
+ };
183
+
184
+ // generated/core/pathSerializer.gen.ts
185
+ var separatorArrayExplode = (style) => {
186
+ switch (style) {
187
+ case "label":
188
+ return ".";
189
+ case "matrix":
190
+ return ";";
191
+ case "simple":
192
+ return ",";
193
+ default:
194
+ return "&";
195
+ }
196
+ };
197
+ var separatorArrayNoExplode = (style) => {
198
+ switch (style) {
199
+ case "form":
200
+ return ",";
201
+ case "pipeDelimited":
202
+ return "|";
203
+ case "spaceDelimited":
204
+ return "%20";
205
+ default:
206
+ return ",";
207
+ }
208
+ };
209
+ var separatorObjectExplode = (style) => {
210
+ switch (style) {
211
+ case "label":
212
+ return ".";
213
+ case "matrix":
214
+ return ";";
215
+ case "simple":
216
+ return ",";
217
+ default:
218
+ return "&";
219
+ }
220
+ };
221
+ var serializeArrayParam = ({
222
+ allowReserved,
223
+ explode,
224
+ name,
225
+ style,
226
+ value
227
+ }) => {
228
+ if (!explode) {
229
+ const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
230
+ switch (style) {
231
+ case "label":
232
+ return `.${joinedValues2}`;
233
+ case "matrix":
234
+ return `;${name}=${joinedValues2}`;
235
+ case "simple":
236
+ return joinedValues2;
237
+ default:
238
+ return `${name}=${joinedValues2}`;
239
+ }
240
+ }
241
+ const separator = separatorArrayExplode(style);
242
+ const joinedValues = value.map((v) => {
243
+ if (style === "label" || style === "simple") {
244
+ return allowReserved ? v : encodeURIComponent(v);
245
+ }
246
+ return serializePrimitiveParam({
247
+ allowReserved,
248
+ name,
249
+ value: v
250
+ });
251
+ }).join(separator);
252
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
253
+ };
254
+ var serializePrimitiveParam = ({
255
+ allowReserved,
256
+ name,
257
+ value
258
+ }) => {
259
+ if (value === void 0 || value === null) {
260
+ return "";
261
+ }
262
+ if (typeof value === "object") {
263
+ throw new Error(
264
+ "Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
265
+ );
266
+ }
267
+ return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
268
+ };
269
+ var serializeObjectParam = ({
270
+ allowReserved,
271
+ explode,
272
+ name,
273
+ style,
274
+ value,
275
+ valueOnly
276
+ }) => {
277
+ if (value instanceof Date) {
278
+ return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
279
+ }
280
+ if (style !== "deepObject" && !explode) {
281
+ let values = [];
282
+ Object.entries(value).forEach(([key, v]) => {
283
+ values = [
284
+ ...values,
285
+ key,
286
+ allowReserved ? v : encodeURIComponent(v)
287
+ ];
288
+ });
289
+ const joinedValues2 = values.join(",");
290
+ switch (style) {
291
+ case "form":
292
+ return `${name}=${joinedValues2}`;
293
+ case "label":
294
+ return `.${joinedValues2}`;
295
+ case "matrix":
296
+ return `;${name}=${joinedValues2}`;
297
+ default:
298
+ return joinedValues2;
299
+ }
300
+ }
301
+ const separator = separatorObjectExplode(style);
302
+ const joinedValues = Object.entries(value).map(
303
+ ([key, v]) => serializePrimitiveParam({
304
+ allowReserved,
305
+ name: style === "deepObject" ? `${name}[${key}]` : key,
306
+ value: v
307
+ })
308
+ ).join(separator);
309
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
310
+ };
311
+
312
+ // generated/core/utils.gen.ts
313
+ var PATH_PARAM_RE = /\{[^{}]+\}/g;
314
+ var defaultPathSerializer = ({ path, url: _url }) => {
315
+ let url = _url;
316
+ const matches = _url.match(PATH_PARAM_RE);
317
+ if (matches) {
318
+ for (const match of matches) {
319
+ let explode = false;
320
+ let name = match.substring(1, match.length - 1);
321
+ let style = "simple";
322
+ if (name.endsWith("*")) {
323
+ explode = true;
324
+ name = name.substring(0, name.length - 1);
325
+ }
326
+ if (name.startsWith(".")) {
327
+ name = name.substring(1);
328
+ style = "label";
329
+ } else if (name.startsWith(";")) {
330
+ name = name.substring(1);
331
+ style = "matrix";
332
+ }
333
+ const value = path[name];
334
+ if (value === void 0 || value === null) {
335
+ continue;
336
+ }
337
+ if (Array.isArray(value)) {
338
+ url = url.replace(
339
+ match,
340
+ serializeArrayParam({ explode, name, style, value })
341
+ );
342
+ continue;
343
+ }
344
+ if (typeof value === "object") {
345
+ url = url.replace(
346
+ match,
347
+ serializeObjectParam({
348
+ explode,
349
+ name,
350
+ style,
351
+ value,
352
+ valueOnly: true
353
+ })
354
+ );
355
+ continue;
356
+ }
357
+ if (style === "matrix") {
358
+ url = url.replace(
359
+ match,
360
+ `;${serializePrimitiveParam({
361
+ name,
362
+ value
363
+ })}`
364
+ );
365
+ continue;
366
+ }
367
+ const replaceValue = encodeURIComponent(
368
+ style === "label" ? `.${value}` : value
369
+ );
370
+ url = url.replace(match, replaceValue);
371
+ }
372
+ }
373
+ return url;
374
+ };
375
+ var getUrl = ({
376
+ baseUrl,
377
+ path,
378
+ query,
379
+ querySerializer,
380
+ url: _url
381
+ }) => {
382
+ const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
383
+ let url = (baseUrl ?? "") + pathUrl;
384
+ if (path) {
385
+ url = defaultPathSerializer({ path, url });
386
+ }
387
+ let search = query ? querySerializer(query) : "";
388
+ if (search.startsWith("?")) {
389
+ search = search.substring(1);
390
+ }
391
+ if (search) {
392
+ url += `?${search}`;
393
+ }
394
+ return url;
395
+ };
396
+ function getValidRequestBody(options) {
397
+ const hasBody = options.body !== void 0;
398
+ const isSerializedBody = hasBody && options.bodySerializer;
399
+ if (isSerializedBody) {
400
+ if ("serializedBody" in options) {
401
+ const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
402
+ return hasSerializedBody ? options.serializedBody : null;
403
+ }
404
+ return options.body !== "" ? options.body : null;
405
+ }
406
+ if (hasBody) {
407
+ return options.body;
408
+ }
409
+ return void 0;
410
+ }
411
+
412
+ // generated/core/auth.gen.ts
413
+ var getAuthToken = async (auth, callback) => {
414
+ const token = typeof callback === "function" ? await callback(auth) : callback;
415
+ if (!token) {
416
+ return;
417
+ }
418
+ if (auth.scheme === "bearer") {
419
+ return `Bearer ${token}`;
420
+ }
421
+ if (auth.scheme === "basic") {
422
+ return `Basic ${btoa(token)}`;
423
+ }
424
+ return token;
425
+ };
426
+
427
+ // generated/client/utils.gen.ts
428
+ var createQuerySerializer = ({
429
+ parameters = {},
430
+ ...args
431
+ } = {}) => {
432
+ const querySerializer = (queryParams) => {
433
+ const search = [];
434
+ if (queryParams && typeof queryParams === "object") {
435
+ for (const name in queryParams) {
436
+ const value = queryParams[name];
437
+ if (value === void 0 || value === null) {
438
+ continue;
439
+ }
440
+ const options = parameters[name] || args;
441
+ if (Array.isArray(value)) {
442
+ const serializedArray = serializeArrayParam({
443
+ allowReserved: options.allowReserved,
444
+ explode: true,
445
+ name,
446
+ style: "form",
447
+ value,
448
+ ...options.array
449
+ });
450
+ if (serializedArray) search.push(serializedArray);
451
+ } else if (typeof value === "object") {
452
+ const serializedObject = serializeObjectParam({
453
+ allowReserved: options.allowReserved,
454
+ explode: true,
455
+ name,
456
+ style: "deepObject",
457
+ value,
458
+ ...options.object
459
+ });
460
+ if (serializedObject) search.push(serializedObject);
461
+ } else {
462
+ const serializedPrimitive = serializePrimitiveParam({
463
+ allowReserved: options.allowReserved,
464
+ name,
465
+ value
466
+ });
467
+ if (serializedPrimitive) search.push(serializedPrimitive);
468
+ }
469
+ }
470
+ }
471
+ return search.join("&");
472
+ };
473
+ return querySerializer;
474
+ };
475
+ var getParseAs = (contentType) => {
476
+ if (!contentType) {
477
+ return "stream";
478
+ }
479
+ const cleanContent = contentType.split(";")[0]?.trim();
480
+ if (!cleanContent) {
481
+ return;
482
+ }
483
+ if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
484
+ return "json";
485
+ }
486
+ if (cleanContent === "multipart/form-data") {
487
+ return "formData";
488
+ }
489
+ if (["application/", "audio/", "image/", "video/"].some(
490
+ (type) => cleanContent.startsWith(type)
491
+ )) {
492
+ return "blob";
493
+ }
494
+ if (cleanContent.startsWith("text/")) {
495
+ return "text";
496
+ }
497
+ return;
498
+ };
499
+ var checkForExistence = (options, name) => {
500
+ if (!name) {
501
+ return false;
502
+ }
503
+ if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
504
+ return true;
505
+ }
506
+ return false;
507
+ };
508
+ var setAuthParams = async ({
509
+ security,
510
+ ...options
511
+ }) => {
512
+ for (const auth of security) {
513
+ if (checkForExistence(options, auth.name)) {
514
+ continue;
515
+ }
516
+ const token = await getAuthToken(auth, options.auth);
517
+ if (!token) {
518
+ continue;
519
+ }
520
+ const name = auth.name ?? "Authorization";
521
+ switch (auth.in) {
522
+ case "query":
523
+ if (!options.query) {
524
+ options.query = {};
525
+ }
526
+ options.query[name] = token;
527
+ break;
528
+ case "cookie":
529
+ options.headers.append("Cookie", `${name}=${token}`);
530
+ break;
531
+ case "header":
532
+ default:
533
+ options.headers.set(name, token);
534
+ break;
535
+ }
536
+ }
537
+ };
538
+ var buildUrl = (options) => getUrl({
539
+ baseUrl: options.baseUrl,
540
+ path: options.path,
541
+ query: options.query,
542
+ querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
543
+ url: options.url
544
+ });
545
+ var mergeConfigs = (a, b) => {
546
+ const config = { ...a, ...b };
547
+ if (config.baseUrl?.endsWith("/")) {
548
+ config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
549
+ }
550
+ config.headers = mergeHeaders(a.headers, b.headers);
551
+ return config;
552
+ };
553
+ var headersEntries = (headers) => {
554
+ const entries = [];
555
+ headers.forEach((value, key) => {
556
+ entries.push([key, value]);
557
+ });
558
+ return entries;
559
+ };
560
+ var mergeHeaders = (...headers) => {
561
+ const mergedHeaders = new Headers();
562
+ for (const header of headers) {
563
+ if (!header) {
564
+ continue;
565
+ }
566
+ const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
567
+ for (const [key, value] of iterator) {
568
+ if (value === null) {
569
+ mergedHeaders.delete(key);
570
+ } else if (Array.isArray(value)) {
571
+ for (const v of value) {
572
+ mergedHeaders.append(key, v);
573
+ }
574
+ } else if (value !== void 0) {
575
+ mergedHeaders.set(
576
+ key,
577
+ typeof value === "object" ? JSON.stringify(value) : value
578
+ );
579
+ }
580
+ }
581
+ }
582
+ return mergedHeaders;
583
+ };
584
+ var Interceptors = class {
585
+ constructor() {
586
+ this.fns = [];
587
+ }
588
+ clear() {
589
+ this.fns = [];
590
+ }
591
+ eject(id) {
592
+ const index = this.getInterceptorIndex(id);
593
+ if (this.fns[index]) {
594
+ this.fns[index] = null;
595
+ }
596
+ }
597
+ exists(id) {
598
+ const index = this.getInterceptorIndex(id);
599
+ return Boolean(this.fns[index]);
600
+ }
601
+ getInterceptorIndex(id) {
602
+ if (typeof id === "number") {
603
+ return this.fns[id] ? id : -1;
604
+ }
605
+ return this.fns.indexOf(id);
606
+ }
607
+ update(id, fn) {
608
+ const index = this.getInterceptorIndex(id);
609
+ if (this.fns[index]) {
610
+ this.fns[index] = fn;
611
+ return id;
612
+ }
613
+ return false;
614
+ }
615
+ use(fn) {
616
+ this.fns.push(fn);
617
+ return this.fns.length - 1;
618
+ }
619
+ };
620
+ var createInterceptors = () => ({
621
+ error: new Interceptors(),
622
+ request: new Interceptors(),
623
+ response: new Interceptors()
624
+ });
625
+ var defaultQuerySerializer = createQuerySerializer({
626
+ allowReserved: false,
627
+ array: {
628
+ explode: true,
629
+ style: "form"
630
+ },
631
+ object: {
632
+ explode: true,
633
+ style: "deepObject"
634
+ }
635
+ });
636
+ var defaultHeaders = {
637
+ "Content-Type": "application/json"
638
+ };
639
+ var createConfig = (override = {}) => ({
640
+ ...jsonBodySerializer,
641
+ headers: defaultHeaders,
642
+ parseAs: "auto",
643
+ querySerializer: defaultQuerySerializer,
644
+ ...override
645
+ });
646
+
647
+ // generated/client/client.gen.ts
648
+ var createClient = (config = {}) => {
649
+ let _config = mergeConfigs(createConfig(), config);
650
+ const getConfig = () => ({ ..._config });
651
+ const setConfig = (config2) => {
652
+ _config = mergeConfigs(_config, config2);
653
+ return getConfig();
654
+ };
655
+ const interceptors = createInterceptors();
656
+ const beforeRequest = async (options) => {
657
+ const opts = {
658
+ ..._config,
659
+ ...options,
660
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
661
+ headers: mergeHeaders(_config.headers, options.headers),
662
+ serializedBody: void 0
663
+ };
664
+ if (opts.security) {
665
+ await setAuthParams({
666
+ ...opts,
667
+ security: opts.security
668
+ });
669
+ }
670
+ if (opts.requestValidator) {
671
+ await opts.requestValidator(opts);
672
+ }
673
+ if (opts.body !== void 0 && opts.bodySerializer) {
674
+ opts.serializedBody = opts.bodySerializer(opts.body);
675
+ }
676
+ if (opts.body === void 0 || opts.serializedBody === "") {
677
+ opts.headers.delete("Content-Type");
678
+ }
679
+ const url = buildUrl(opts);
680
+ return { opts, url };
681
+ };
682
+ const request = async (options) => {
683
+ const { opts, url } = await beforeRequest(options);
684
+ const { client: _client, ...optsForRequest } = opts;
685
+ const requestInit = {
686
+ redirect: "follow",
687
+ ...optsForRequest,
688
+ body: getValidRequestBody(opts)
689
+ };
690
+ let request2 = new Request(url, requestInit);
691
+ for (const fn of interceptors.request.fns) {
692
+ if (fn) {
693
+ request2 = await fn(request2, opts);
694
+ }
695
+ }
696
+ const _fetch = opts.fetch;
697
+ let response;
698
+ try {
699
+ response = await _fetch(request2);
700
+ } catch (error2) {
701
+ let finalError2 = error2;
702
+ for (const fn of interceptors.error.fns) {
703
+ if (fn) {
704
+ finalError2 = await fn(
705
+ error2,
706
+ void 0,
707
+ request2,
708
+ opts
709
+ );
710
+ }
711
+ }
712
+ finalError2 = finalError2 || {};
713
+ if (opts.throwOnError) {
714
+ throw finalError2;
715
+ }
716
+ return opts.responseStyle === "data" ? void 0 : {
717
+ error: finalError2,
718
+ request: request2,
719
+ response: void 0
720
+ };
721
+ }
722
+ for (const fn of interceptors.response.fns) {
723
+ if (fn) {
724
+ response = await fn(response, request2, opts);
725
+ }
726
+ }
727
+ const result = {
728
+ request: request2,
729
+ response
730
+ };
731
+ if (response.ok) {
732
+ const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
733
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
734
+ let emptyData;
735
+ switch (parseAs) {
736
+ case "arrayBuffer":
737
+ case "blob":
738
+ case "text":
739
+ emptyData = await response[parseAs]();
740
+ break;
741
+ case "formData":
742
+ emptyData = new FormData();
743
+ break;
744
+ case "stream":
745
+ emptyData = response.body;
746
+ break;
747
+ case "json":
748
+ default:
749
+ emptyData = {};
750
+ break;
751
+ }
752
+ return opts.responseStyle === "data" ? emptyData : {
753
+ data: emptyData,
754
+ ...result
755
+ };
756
+ }
757
+ let data;
758
+ switch (parseAs) {
759
+ case "arrayBuffer":
760
+ case "blob":
761
+ case "formData":
762
+ case "json":
763
+ case "text":
764
+ data = await response[parseAs]();
765
+ break;
766
+ case "stream":
767
+ return opts.responseStyle === "data" ? response.body : {
768
+ data: response.body,
769
+ ...result
770
+ };
771
+ }
772
+ if (parseAs === "json") {
773
+ if (opts.responseValidator) {
774
+ await opts.responseValidator(data);
775
+ }
776
+ if (opts.responseTransformer) {
777
+ data = await opts.responseTransformer(data);
778
+ }
779
+ }
780
+ return opts.responseStyle === "data" ? data : {
781
+ data,
782
+ ...result
783
+ };
784
+ }
785
+ const textError = await response.text();
786
+ let jsonError;
787
+ try {
788
+ jsonError = JSON.parse(textError);
789
+ } catch {
790
+ }
791
+ const error = jsonError ?? textError;
792
+ let finalError = error;
793
+ for (const fn of interceptors.error.fns) {
794
+ if (fn) {
795
+ finalError = await fn(error, response, request2, opts);
796
+ }
797
+ }
798
+ finalError = finalError || {};
799
+ if (opts.throwOnError) {
800
+ throw finalError;
801
+ }
802
+ return opts.responseStyle === "data" ? void 0 : {
803
+ error: finalError,
804
+ ...result
805
+ };
806
+ };
807
+ const makeMethodFn = (method) => (options) => request({ ...options, method });
808
+ const makeSseFn = (method) => async (options) => {
809
+ const { opts, url } = await beforeRequest(options);
810
+ return createSseClient({
811
+ ...opts,
812
+ body: opts.body,
813
+ headers: opts.headers,
814
+ method,
815
+ onRequest: async (url2, init) => {
816
+ let request2 = new Request(url2, init);
817
+ for (const fn of interceptors.request.fns) {
818
+ if (fn) {
819
+ request2 = await fn(request2, opts);
820
+ }
821
+ }
822
+ return request2;
823
+ },
824
+ url
825
+ });
826
+ };
827
+ return {
828
+ buildUrl,
829
+ connect: makeMethodFn("CONNECT"),
830
+ delete: makeMethodFn("DELETE"),
831
+ get: makeMethodFn("GET"),
832
+ getConfig,
833
+ head: makeMethodFn("HEAD"),
834
+ interceptors,
835
+ options: makeMethodFn("OPTIONS"),
836
+ patch: makeMethodFn("PATCH"),
837
+ post: makeMethodFn("POST"),
838
+ put: makeMethodFn("PUT"),
839
+ request,
840
+ setConfig,
841
+ sse: {
842
+ connect: makeSseFn("CONNECT"),
843
+ delete: makeSseFn("DELETE"),
844
+ get: makeSseFn("GET"),
845
+ head: makeSseFn("HEAD"),
846
+ options: makeSseFn("OPTIONS"),
847
+ patch: makeSseFn("PATCH"),
848
+ post: makeSseFn("POST"),
849
+ put: makeSseFn("PUT"),
850
+ trace: makeSseFn("TRACE")
851
+ },
852
+ trace: makeMethodFn("TRACE")
853
+ };
854
+ };
855
+
856
+ // generated/sdk.gen.ts
857
+ var sdk_gen_exports = {};
858
+ __export(sdk_gen_exports, {
859
+ addBankBackground: () => addBankBackground,
860
+ cancelOperation: () => cancelOperation,
861
+ clearBankMemories: () => clearBankMemories,
862
+ clearMemoryObservations: () => clearMemoryObservations,
863
+ clearObservations: () => clearObservations,
864
+ createDirective: () => createDirective,
865
+ createMentalModel: () => createMentalModel,
866
+ createOrUpdateBank: () => createOrUpdateBank,
867
+ createWebhook: () => createWebhook,
868
+ deleteBank: () => deleteBank,
869
+ deleteDirective: () => deleteDirective,
870
+ deleteDocument: () => deleteDocument,
871
+ deleteMentalModel: () => deleteMentalModel,
872
+ deleteWebhook: () => deleteWebhook,
873
+ fileRetain: () => fileRetain,
874
+ getAgentStats: () => getAgentStats,
875
+ getBankConfig: () => getBankConfig,
876
+ getBankProfile: () => getBankProfile,
877
+ getChunk: () => getChunk,
878
+ getDirective: () => getDirective,
879
+ getDocument: () => getDocument,
880
+ getEntity: () => getEntity,
881
+ getGraph: () => getGraph,
882
+ getMemory: () => getMemory,
883
+ getMentalModel: () => getMentalModel,
884
+ getMentalModelHistory: () => getMentalModelHistory,
885
+ getObservationHistory: () => getObservationHistory,
886
+ getOperationStatus: () => getOperationStatus,
887
+ getVersion: () => getVersion,
888
+ healthEndpointHealthGet: () => healthEndpointHealthGet,
889
+ listBanks: () => listBanks,
890
+ listDirectives: () => listDirectives,
891
+ listDocuments: () => listDocuments,
892
+ listEntities: () => listEntities,
893
+ listMemories: () => listMemories,
894
+ listMentalModels: () => listMentalModels,
895
+ listOperations: () => listOperations,
896
+ listTags: () => listTags,
897
+ listWebhookDeliveries: () => listWebhookDeliveries,
898
+ listWebhooks: () => listWebhooks,
899
+ metricsEndpointMetricsGet: () => metricsEndpointMetricsGet,
900
+ recallMemories: () => recallMemories,
901
+ recoverConsolidation: () => recoverConsolidation,
902
+ reflect: () => reflect,
903
+ refreshMentalModel: () => refreshMentalModel,
904
+ regenerateEntityObservations: () => regenerateEntityObservations,
905
+ resetBankConfig: () => resetBankConfig,
906
+ retainMemories: () => retainMemories,
907
+ retryOperation: () => retryOperation,
908
+ triggerConsolidation: () => triggerConsolidation,
909
+ updateBank: () => updateBank,
910
+ updateBankConfig: () => updateBankConfig,
911
+ updateBankDisposition: () => updateBankDisposition,
912
+ updateDirective: () => updateDirective,
913
+ updateDocument: () => updateDocument,
914
+ updateMentalModel: () => updateMentalModel,
915
+ updateWebhook: () => updateWebhook
916
+ });
917
+
918
+ // generated/client.gen.ts
919
+ var client = createClient(createConfig());
920
+
921
+ // generated/sdk.gen.ts
922
+ var healthEndpointHealthGet = (options) => (options?.client ?? client).get({ url: "/health", ...options });
923
+ var getVersion = (options) => (options?.client ?? client).get({
924
+ url: "/version",
925
+ ...options
926
+ });
927
+ var metricsEndpointMetricsGet = (options) => (options?.client ?? client).get({ url: "/metrics", ...options });
928
+ var getGraph = (options) => (options.client ?? client).get({ url: "/v1/default/banks/{bank_id}/graph", ...options });
929
+ var listMemories = (options) => (options.client ?? client).get({ url: "/v1/default/banks/{bank_id}/memories/list", ...options });
930
+ var getMemory = (options) => (options.client ?? client).get({ url: "/v1/default/banks/{bank_id}/memories/{memory_id}", ...options });
931
+ var getObservationHistory = (options) => (options.client ?? client).get({
932
+ url: "/v1/default/banks/{bank_id}/memories/{memory_id}/history",
933
+ ...options
934
+ });
935
+ var recallMemories = (options) => (options.client ?? client).post({
936
+ url: "/v1/default/banks/{bank_id}/memories/recall",
937
+ ...options,
938
+ headers: {
939
+ "Content-Type": "application/json",
940
+ ...options.headers
941
+ }
942
+ });
943
+ var reflect = (options) => (options.client ?? client).post({
944
+ url: "/v1/default/banks/{bank_id}/reflect",
945
+ ...options,
946
+ headers: {
947
+ "Content-Type": "application/json",
948
+ ...options.headers
949
+ }
950
+ });
951
+ var listBanks = (options) => (options?.client ?? client).get({ url: "/v1/default/banks", ...options });
952
+ var getAgentStats = (options) => (options.client ?? client).get({ url: "/v1/default/banks/{bank_id}/stats", ...options });
953
+ var listEntities = (options) => (options.client ?? client).get({ url: "/v1/default/banks/{bank_id}/entities", ...options });
954
+ var getEntity = (options) => (options.client ?? client).get({ url: "/v1/default/banks/{bank_id}/entities/{entity_id}", ...options });
955
+ var regenerateEntityObservations = (options) => (options.client ?? client).post({
956
+ url: "/v1/default/banks/{bank_id}/entities/{entity_id}/regenerate",
957
+ ...options
958
+ });
959
+ var listMentalModels = (options) => (options.client ?? client).get({ url: "/v1/default/banks/{bank_id}/mental-models", ...options });
960
+ var createMentalModel = (options) => (options.client ?? client).post({
961
+ url: "/v1/default/banks/{bank_id}/mental-models",
962
+ ...options,
963
+ headers: {
964
+ "Content-Type": "application/json",
965
+ ...options.headers
966
+ }
967
+ });
968
+ var deleteMentalModel = (options) => (options.client ?? client).delete({
969
+ url: "/v1/default/banks/{bank_id}/mental-models/{mental_model_id}",
970
+ ...options
971
+ });
972
+ var getMentalModel = (options) => (options.client ?? client).get({
973
+ url: "/v1/default/banks/{bank_id}/mental-models/{mental_model_id}",
974
+ ...options
975
+ });
976
+ var updateMentalModel = (options) => (options.client ?? client).patch({
977
+ url: "/v1/default/banks/{bank_id}/mental-models/{mental_model_id}",
978
+ ...options,
979
+ headers: {
980
+ "Content-Type": "application/json",
981
+ ...options.headers
982
+ }
983
+ });
984
+ var getMentalModelHistory = (options) => (options.client ?? client).get({
985
+ url: "/v1/default/banks/{bank_id}/mental-models/{mental_model_id}/history",
986
+ ...options
987
+ });
988
+ var refreshMentalModel = (options) => (options.client ?? client).post({
989
+ url: "/v1/default/banks/{bank_id}/mental-models/{mental_model_id}/refresh",
990
+ ...options
991
+ });
992
+ var listDirectives = (options) => (options.client ?? client).get({ url: "/v1/default/banks/{bank_id}/directives", ...options });
993
+ var createDirective = (options) => (options.client ?? client).post({
994
+ url: "/v1/default/banks/{bank_id}/directives",
995
+ ...options,
996
+ headers: {
997
+ "Content-Type": "application/json",
998
+ ...options.headers
999
+ }
1000
+ });
1001
+ var deleteDirective = (options) => (options.client ?? client).delete({
1002
+ url: "/v1/default/banks/{bank_id}/directives/{directive_id}",
1003
+ ...options
1004
+ });
1005
+ var getDirective = (options) => (options.client ?? client).get({
1006
+ url: "/v1/default/banks/{bank_id}/directives/{directive_id}",
1007
+ ...options
1008
+ });
1009
+ var updateDirective = (options) => (options.client ?? client).patch({
1010
+ url: "/v1/default/banks/{bank_id}/directives/{directive_id}",
1011
+ ...options,
1012
+ headers: {
1013
+ "Content-Type": "application/json",
1014
+ ...options.headers
1015
+ }
1016
+ });
1017
+ var listDocuments = (options) => (options.client ?? client).get({ url: "/v1/default/banks/{bank_id}/documents", ...options });
1018
+ var deleteDocument = (options) => (options.client ?? client).delete({ url: "/v1/default/banks/{bank_id}/documents/{document_id}", ...options });
1019
+ var getDocument = (options) => (options.client ?? client).get({ url: "/v1/default/banks/{bank_id}/documents/{document_id}", ...options });
1020
+ var updateDocument = (options) => (options.client ?? client).patch({
1021
+ url: "/v1/default/banks/{bank_id}/documents/{document_id}",
1022
+ ...options,
1023
+ headers: {
1024
+ "Content-Type": "application/json",
1025
+ ...options.headers
1026
+ }
1027
+ });
1028
+ var listTags = (options) => (options.client ?? client).get({ url: "/v1/default/banks/{bank_id}/tags", ...options });
1029
+ var getChunk = (options) => (options.client ?? client).get({ url: "/v1/default/chunks/{chunk_id}", ...options });
1030
+ var listOperations = (options) => (options.client ?? client).get({ url: "/v1/default/banks/{bank_id}/operations", ...options });
1031
+ var cancelOperation = (options) => (options.client ?? client).delete({
1032
+ url: "/v1/default/banks/{bank_id}/operations/{operation_id}",
1033
+ ...options
1034
+ });
1035
+ var getOperationStatus = (options) => (options.client ?? client).get({
1036
+ url: "/v1/default/banks/{bank_id}/operations/{operation_id}",
1037
+ ...options
1038
+ });
1039
+ var retryOperation = (options) => (options.client ?? client).post({
1040
+ url: "/v1/default/banks/{bank_id}/operations/{operation_id}/retry",
1041
+ ...options
1042
+ });
1043
+ var getBankProfile = (options) => (options.client ?? client).get({ url: "/v1/default/banks/{bank_id}/profile", ...options });
1044
+ var updateBankDisposition = (options) => (options.client ?? client).put({
1045
+ url: "/v1/default/banks/{bank_id}/profile",
1046
+ ...options,
1047
+ headers: {
1048
+ "Content-Type": "application/json",
1049
+ ...options.headers
1050
+ }
1051
+ });
1052
+ var addBankBackground = (options) => (options.client ?? client).post({
1053
+ url: "/v1/default/banks/{bank_id}/background",
1054
+ ...options,
1055
+ headers: {
1056
+ "Content-Type": "application/json",
1057
+ ...options.headers
1058
+ }
1059
+ });
1060
+ var deleteBank = (options) => (options.client ?? client).delete({ url: "/v1/default/banks/{bank_id}", ...options });
1061
+ var updateBank = (options) => (options.client ?? client).patch({
1062
+ url: "/v1/default/banks/{bank_id}",
1063
+ ...options,
1064
+ headers: {
1065
+ "Content-Type": "application/json",
1066
+ ...options.headers
1067
+ }
1068
+ });
1069
+ var createOrUpdateBank = (options) => (options.client ?? client).put({
1070
+ url: "/v1/default/banks/{bank_id}",
1071
+ ...options,
1072
+ headers: {
1073
+ "Content-Type": "application/json",
1074
+ ...options.headers
1075
+ }
1076
+ });
1077
+ var clearObservations = (options) => (options.client ?? client).delete({ url: "/v1/default/banks/{bank_id}/observations", ...options });
1078
+ var recoverConsolidation = (options) => (options.client ?? client).post({ url: "/v1/default/banks/{bank_id}/consolidation/recover", ...options });
1079
+ var clearMemoryObservations = (options) => (options.client ?? client).delete({
1080
+ url: "/v1/default/banks/{bank_id}/memories/{memory_id}/observations",
1081
+ ...options
1082
+ });
1083
+ var resetBankConfig = (options) => (options.client ?? client).delete({ url: "/v1/default/banks/{bank_id}/config", ...options });
1084
+ var getBankConfig = (options) => (options.client ?? client).get({ url: "/v1/default/banks/{bank_id}/config", ...options });
1085
+ var updateBankConfig = (options) => (options.client ?? client).patch({
1086
+ url: "/v1/default/banks/{bank_id}/config",
1087
+ ...options,
1088
+ headers: {
1089
+ "Content-Type": "application/json",
1090
+ ...options.headers
1091
+ }
1092
+ });
1093
+ var triggerConsolidation = (options) => (options.client ?? client).post({ url: "/v1/default/banks/{bank_id}/consolidate", ...options });
1094
+ var listWebhooks = (options) => (options.client ?? client).get({ url: "/v1/default/banks/{bank_id}/webhooks", ...options });
1095
+ var createWebhook = (options) => (options.client ?? client).post({
1096
+ url: "/v1/default/banks/{bank_id}/webhooks",
1097
+ ...options,
1098
+ headers: {
1099
+ "Content-Type": "application/json",
1100
+ ...options.headers
1101
+ }
1102
+ });
1103
+ var deleteWebhook = (options) => (options.client ?? client).delete({ url: "/v1/default/banks/{bank_id}/webhooks/{webhook_id}", ...options });
1104
+ var updateWebhook = (options) => (options.client ?? client).patch({
1105
+ url: "/v1/default/banks/{bank_id}/webhooks/{webhook_id}",
1106
+ ...options,
1107
+ headers: {
1108
+ "Content-Type": "application/json",
1109
+ ...options.headers
1110
+ }
1111
+ });
1112
+ var listWebhookDeliveries = (options) => (options.client ?? client).get({
1113
+ url: "/v1/default/banks/{bank_id}/webhooks/{webhook_id}/deliveries",
1114
+ ...options
1115
+ });
1116
+ var clearBankMemories = (options) => (options.client ?? client).delete({ url: "/v1/default/banks/{bank_id}/memories", ...options });
1117
+ var retainMemories = (options) => (options.client ?? client).post({
1118
+ url: "/v1/default/banks/{bank_id}/memories",
1119
+ ...options,
1120
+ headers: {
1121
+ "Content-Type": "application/json",
1122
+ ...options.headers
1123
+ }
1124
+ });
1125
+ var fileRetain = (options) => (options.client ?? client).post({
1126
+ ...formDataBodySerializer,
1127
+ url: "/v1/default/banks/{bank_id}/files/retain",
1128
+ ...options,
1129
+ headers: {
1130
+ "Content-Type": null,
1131
+ ...options.headers
1132
+ }
1133
+ });
1134
+
1135
+ // src/index.ts
1136
+ var HindsightError = class extends Error {
1137
+ constructor(message, statusCode, details) {
1138
+ super(message);
1139
+ this.name = "HindsightError";
1140
+ this.statusCode = statusCode;
1141
+ this.details = details;
1142
+ }
1143
+ };
1144
+ var HindsightClient = class {
1145
+ constructor(options) {
1146
+ this.client = createClient(
1147
+ createConfig({
1148
+ baseUrl: options.baseUrl,
1149
+ headers: options.apiKey ? { Authorization: `Bearer ${options.apiKey}` } : void 0
1150
+ })
1151
+ );
1152
+ }
1153
+ /**
1154
+ * Validates the API response and throws an error if the request failed.
1155
+ */
1156
+ validateResponse(response, operation) {
1157
+ if (!response.data) {
1158
+ const error = response.error;
1159
+ const httpResponse = response.response;
1160
+ const statusCode = httpResponse?.status;
1161
+ const details = error?.detail || error?.message || error;
1162
+ throw new HindsightError(
1163
+ `${operation} failed: ${JSON.stringify(details)}`,
1164
+ statusCode,
1165
+ details
1166
+ );
1167
+ }
1168
+ return response.data;
1169
+ }
1170
+ /**
1171
+ * Retain a single memory for a bank.
1172
+ */
1173
+ async retain(bankId, content, options) {
1174
+ const item = { content };
1175
+ if (options?.timestamp) {
1176
+ item.timestamp = options.timestamp instanceof Date ? options.timestamp.toISOString() : options.timestamp;
1177
+ }
1178
+ if (options?.context) {
1179
+ item.context = options.context;
1180
+ }
1181
+ if (options?.metadata) {
1182
+ item.metadata = options.metadata;
1183
+ }
1184
+ if (options?.documentId) {
1185
+ item.document_id = options.documentId;
1186
+ }
1187
+ if (options?.entities) {
1188
+ item.entities = options.entities;
1189
+ }
1190
+ if (options?.tags) {
1191
+ item.tags = options.tags;
1192
+ }
1193
+ const response = await retainMemories({
1194
+ client: this.client,
1195
+ path: { bank_id: bankId },
1196
+ body: { items: [item], async: options?.async }
1197
+ });
1198
+ return this.validateResponse(response, "retain");
1199
+ }
1200
+ /**
1201
+ * Retain multiple memories in batch.
1202
+ */
1203
+ async retainBatch(bankId, items, options) {
1204
+ const processedItems = items.map((item) => ({
1205
+ content: item.content,
1206
+ context: item.context,
1207
+ metadata: item.metadata,
1208
+ document_id: item.document_id,
1209
+ entities: item.entities,
1210
+ tags: item.tags,
1211
+ observation_scopes: item.observation_scopes,
1212
+ strategy: item.strategy,
1213
+ timestamp: item.timestamp instanceof Date ? item.timestamp.toISOString() : item.timestamp
1214
+ }));
1215
+ const itemsWithDocId = processedItems.map((item) => ({
1216
+ ...item,
1217
+ document_id: item.document_id || options?.documentId
1218
+ }));
1219
+ const response = await retainMemories({
1220
+ client: this.client,
1221
+ path: { bank_id: bankId },
1222
+ body: {
1223
+ items: itemsWithDocId,
1224
+ document_tags: options?.documentTags,
1225
+ async: options?.async
1226
+ }
1227
+ });
1228
+ return this.validateResponse(response, "retainBatch");
1229
+ }
1230
+ /**
1231
+ * Upload files and retain their contents as memories.
1232
+ *
1233
+ * Files are automatically converted to text (PDF, DOCX, images via OCR, audio via
1234
+ * transcription, and more) and ingested as memories. Processing is always asynchronous —
1235
+ * use the returned operation IDs to track progress via the operations endpoint.
1236
+ *
1237
+ * @param bankId - The memory bank ID
1238
+ * @param files - Array of File or Blob objects to upload
1239
+ * @param options - Optional settings: context, documentTags, filesMetadata
1240
+ */
1241
+ async retainFiles(bankId, files, options) {
1242
+ const meta = options?.filesMetadata ?? files.map(() => options?.context ? { context: options.context } : {});
1243
+ const requestBody = JSON.stringify({
1244
+ files_metadata: meta
1245
+ });
1246
+ const response = await fileRetain({
1247
+ client: this.client,
1248
+ path: { bank_id: bankId },
1249
+ body: { files, request: requestBody }
1250
+ });
1251
+ return this.validateResponse(response, "retainFiles");
1252
+ }
1253
+ /**
1254
+ * Recall memories with a natural language query.
1255
+ */
1256
+ async recall(bankId, query, options) {
1257
+ const response = await recallMemories({
1258
+ client: this.client,
1259
+ path: { bank_id: bankId },
1260
+ body: {
1261
+ query,
1262
+ types: options?.types,
1263
+ max_tokens: options?.maxTokens,
1264
+ budget: options?.budget || "mid",
1265
+ trace: options?.trace,
1266
+ query_timestamp: options?.queryTimestamp,
1267
+ include: {
1268
+ entities: options?.includeEntities === false ? null : options?.includeEntities ? { max_tokens: options?.maxEntityTokens ?? 500 } : void 0,
1269
+ chunks: options?.includeChunks ? { max_tokens: options?.maxChunkTokens ?? 8192 } : void 0,
1270
+ source_facts: options?.includeSourceFacts ? { max_tokens: options?.maxSourceFactsTokens ?? 4096 } : void 0
1271
+ },
1272
+ tags: options?.tags,
1273
+ tags_match: options?.tagsMatch
1274
+ }
1275
+ });
1276
+ return this.validateResponse(response, "recall");
1277
+ }
1278
+ /**
1279
+ * Reflect and generate a contextual answer using the bank's identity and memories.
1280
+ */
1281
+ async reflect(bankId, query, options) {
1282
+ const response = await reflect({
1283
+ client: this.client,
1284
+ path: { bank_id: bankId },
1285
+ body: {
1286
+ query,
1287
+ context: options?.context,
1288
+ budget: options?.budget || "low",
1289
+ tags: options?.tags,
1290
+ tags_match: options?.tagsMatch
1291
+ }
1292
+ });
1293
+ return this.validateResponse(response, "reflect");
1294
+ }
1295
+ /**
1296
+ * List memories with pagination.
1297
+ */
1298
+ async listMemories(bankId, options) {
1299
+ const response = await listMemories({
1300
+ client: this.client,
1301
+ path: { bank_id: bankId },
1302
+ query: {
1303
+ limit: options?.limit,
1304
+ offset: options?.offset,
1305
+ type: options?.type,
1306
+ q: options?.q
1307
+ }
1308
+ });
1309
+ return this.validateResponse(response, "listMemories");
1310
+ }
1311
+ /**
1312
+ * Create or update a bank with disposition, missions, and operational configuration.
1313
+ */
1314
+ async createBank(bankId, options = {}) {
1315
+ const response = await createOrUpdateBank({
1316
+ client: this.client,
1317
+ path: { bank_id: bankId },
1318
+ body: {
1319
+ name: options.name,
1320
+ mission: options.mission,
1321
+ reflect_mission: options.reflectMission,
1322
+ background: options.background,
1323
+ disposition: options.disposition,
1324
+ disposition_skepticism: options.dispositionSkepticism,
1325
+ disposition_literalism: options.dispositionLiteralism,
1326
+ disposition_empathy: options.dispositionEmpathy,
1327
+ retain_mission: options.retainMission,
1328
+ retain_extraction_mode: options.retainExtractionMode,
1329
+ retain_custom_instructions: options.retainCustomInstructions,
1330
+ retain_chunk_size: options.retainChunkSize,
1331
+ enable_observations: options.enableObservations,
1332
+ observations_mission: options.observationsMission
1333
+ }
1334
+ });
1335
+ return this.validateResponse(response, "createBank");
1336
+ }
1337
+ /**
1338
+ * Set or update the reflect mission for a memory bank.
1339
+ * @deprecated Use createBank({ reflectMission: '...' }) instead.
1340
+ */
1341
+ async setMission(bankId, mission) {
1342
+ return this.createBank(bankId, { reflectMission: mission });
1343
+ }
1344
+ /**
1345
+ * Get a bank's profile.
1346
+ */
1347
+ async getBankProfile(bankId) {
1348
+ const response = await getBankProfile({
1349
+ client: this.client,
1350
+ path: { bank_id: bankId }
1351
+ });
1352
+ return this.validateResponse(response, "getBankProfile");
1353
+ }
1354
+ /**
1355
+ * Get the resolved configuration for a bank, including any bank-level overrides.
1356
+ *
1357
+ * Can be disabled on the server by setting `HINDSIGHT_API_ENABLE_BANK_CONFIG_API=false`.
1358
+ */
1359
+ async getBankConfig(bankId) {
1360
+ const response = await getBankConfig({
1361
+ client: this.client,
1362
+ path: { bank_id: bankId }
1363
+ });
1364
+ return this.validateResponse(response, "getBankConfig");
1365
+ }
1366
+ /**
1367
+ * Update configuration overrides for a bank.
1368
+ *
1369
+ * Can be disabled on the server by setting `HINDSIGHT_API_ENABLE_BANK_CONFIG_API=false`.
1370
+ *
1371
+ * @param bankId - The memory bank ID
1372
+ * @param options - Fields to override
1373
+ */
1374
+ async updateBankConfig(bankId, options) {
1375
+ const updates = {};
1376
+ if (options.reflectMission !== void 0) updates.reflect_mission = options.reflectMission;
1377
+ if (options.retainMission !== void 0) updates.retain_mission = options.retainMission;
1378
+ if (options.retainExtractionMode !== void 0) updates.retain_extraction_mode = options.retainExtractionMode;
1379
+ if (options.retainCustomInstructions !== void 0)
1380
+ updates.retain_custom_instructions = options.retainCustomInstructions;
1381
+ if (options.retainChunkSize !== void 0) updates.retain_chunk_size = options.retainChunkSize;
1382
+ if (options.enableObservations !== void 0) updates.enable_observations = options.enableObservations;
1383
+ if (options.observationsMission !== void 0) updates.observations_mission = options.observationsMission;
1384
+ if (options.dispositionSkepticism !== void 0) updates.disposition_skepticism = options.dispositionSkepticism;
1385
+ if (options.dispositionLiteralism !== void 0) updates.disposition_literalism = options.dispositionLiteralism;
1386
+ if (options.dispositionEmpathy !== void 0) updates.disposition_empathy = options.dispositionEmpathy;
1387
+ const response = await updateBankConfig({
1388
+ client: this.client,
1389
+ path: { bank_id: bankId },
1390
+ body: { updates }
1391
+ });
1392
+ return this.validateResponse(response, "updateBankConfig");
1393
+ }
1394
+ /**
1395
+ * Reset all bank-level configuration overrides, reverting to server defaults.
1396
+ *
1397
+ * Can be disabled on the server by setting `HINDSIGHT_API_ENABLE_BANK_CONFIG_API=false`.
1398
+ */
1399
+ async resetBankConfig(bankId) {
1400
+ const response = await resetBankConfig({
1401
+ client: this.client,
1402
+ path: { bank_id: bankId }
1403
+ });
1404
+ return this.validateResponse(response, "resetBankConfig");
1405
+ }
1406
+ /**
1407
+ * Delete a bank.
1408
+ */
1409
+ async deleteBank(bankId) {
1410
+ const response = await deleteBank({
1411
+ client: this.client,
1412
+ path: { bank_id: bankId }
1413
+ });
1414
+ if (response.error) {
1415
+ throw new Error(`deleteBank failed: ${JSON.stringify(response.error)}`);
1416
+ }
1417
+ }
1418
+ // Directive methods
1419
+ /**
1420
+ * Create a directive (hard rule for reflect).
1421
+ */
1422
+ async createDirective(bankId, name, content, options) {
1423
+ const response = await createDirective({
1424
+ client: this.client,
1425
+ path: { bank_id: bankId },
1426
+ body: {
1427
+ name,
1428
+ content,
1429
+ priority: options?.priority ?? 0,
1430
+ is_active: options?.isActive ?? true,
1431
+ tags: options?.tags
1432
+ }
1433
+ });
1434
+ return this.validateResponse(response, "createDirective");
1435
+ }
1436
+ /**
1437
+ * List all directives in a bank.
1438
+ */
1439
+ async listDirectives(bankId, options) {
1440
+ const response = await listDirectives({
1441
+ client: this.client,
1442
+ path: { bank_id: bankId },
1443
+ query: { tags: options?.tags }
1444
+ });
1445
+ return this.validateResponse(response, "listDirectives");
1446
+ }
1447
+ /**
1448
+ * Get a specific directive.
1449
+ */
1450
+ async getDirective(bankId, directiveId) {
1451
+ const response = await getDirective({
1452
+ client: this.client,
1453
+ path: { bank_id: bankId, directive_id: directiveId }
1454
+ });
1455
+ return this.validateResponse(response, "getDirective");
1456
+ }
1457
+ /**
1458
+ * Update a directive.
1459
+ */
1460
+ async updateDirective(bankId, directiveId, options) {
1461
+ const response = await updateDirective({
1462
+ client: this.client,
1463
+ path: { bank_id: bankId, directive_id: directiveId },
1464
+ body: {
1465
+ name: options.name,
1466
+ content: options.content,
1467
+ priority: options.priority,
1468
+ is_active: options.isActive,
1469
+ tags: options.tags
1470
+ }
1471
+ });
1472
+ return this.validateResponse(response, "updateDirective");
1473
+ }
1474
+ /**
1475
+ * Delete a directive.
1476
+ */
1477
+ async deleteDirective(bankId, directiveId) {
1478
+ const response = await deleteDirective({
1479
+ client: this.client,
1480
+ path: { bank_id: bankId, directive_id: directiveId }
1481
+ });
1482
+ if (response.error) {
1483
+ throw new Error(`deleteDirective failed: ${JSON.stringify(response.error)}`);
1484
+ }
1485
+ }
1486
+ // Mental Model methods
1487
+ /**
1488
+ * Create a mental model (runs reflect in background).
1489
+ */
1490
+ async createMentalModel(bankId, name, sourceQuery, options) {
1491
+ const response = await createMentalModel({
1492
+ client: this.client,
1493
+ path: { bank_id: bankId },
1494
+ body: {
1495
+ name,
1496
+ source_query: sourceQuery,
1497
+ tags: options?.tags,
1498
+ max_tokens: options?.maxTokens,
1499
+ trigger: options?.trigger ? { refresh_after_consolidation: options.trigger.refreshAfterConsolidation } : void 0
1500
+ }
1501
+ });
1502
+ return this.validateResponse(response, "createMentalModel");
1503
+ }
1504
+ /**
1505
+ * List all mental models in a bank.
1506
+ */
1507
+ async listMentalModels(bankId, options) {
1508
+ const response = await listMentalModels({
1509
+ client: this.client,
1510
+ path: { bank_id: bankId },
1511
+ query: { tags: options?.tags }
1512
+ });
1513
+ return this.validateResponse(response, "listMentalModels");
1514
+ }
1515
+ /**
1516
+ * Get a specific mental model.
1517
+ */
1518
+ async getMentalModel(bankId, mentalModelId) {
1519
+ const response = await getMentalModel({
1520
+ client: this.client,
1521
+ path: { bank_id: bankId, mental_model_id: mentalModelId }
1522
+ });
1523
+ return this.validateResponse(response, "getMentalModel");
1524
+ }
1525
+ /**
1526
+ * Refresh a mental model to update with current knowledge.
1527
+ */
1528
+ async refreshMentalModel(bankId, mentalModelId) {
1529
+ const response = await refreshMentalModel({
1530
+ client: this.client,
1531
+ path: { bank_id: bankId, mental_model_id: mentalModelId }
1532
+ });
1533
+ return this.validateResponse(response, "refreshMentalModel");
1534
+ }
1535
+ /**
1536
+ * Update a mental model's metadata.
1537
+ */
1538
+ async updateMentalModel(bankId, mentalModelId, options) {
1539
+ const response = await updateMentalModel({
1540
+ client: this.client,
1541
+ path: { bank_id: bankId, mental_model_id: mentalModelId },
1542
+ body: {
1543
+ name: options.name,
1544
+ source_query: options.sourceQuery,
1545
+ tags: options.tags,
1546
+ max_tokens: options.maxTokens,
1547
+ trigger: options.trigger ? { refresh_after_consolidation: options.trigger.refreshAfterConsolidation } : void 0
1548
+ }
1549
+ });
1550
+ return this.validateResponse(response, "updateMentalModel");
1551
+ }
1552
+ /**
1553
+ * Delete a mental model.
1554
+ */
1555
+ async deleteMentalModel(bankId, mentalModelId) {
1556
+ const response = await deleteMentalModel({
1557
+ client: this.client,
1558
+ path: { bank_id: bankId, mental_model_id: mentalModelId }
1559
+ });
1560
+ if (response.error) {
1561
+ throw new Error(`deleteMentalModel failed: ${JSON.stringify(response.error)}`);
1562
+ }
1563
+ }
1564
+ };
1565
+ export {
1566
+ HindsightClient,
1567
+ HindsightError,
1568
+ createClient,
1569
+ createConfig,
1570
+ sdk_gen_exports as sdk
1571
+ };
1572
+ //# sourceMappingURL=index.mjs.map