tako-sdk 0.1.5 → 1.0.2

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.js CHANGED
@@ -1,224 +1,3192 @@
1
- // src/types/types.ts
2
- var SourceIndex = /* @__PURE__ */ ((SourceIndex2) => {
3
- SourceIndex2["TAKO"] = "tako";
4
- SourceIndex2["WEB"] = "web";
5
- return SourceIndex2;
6
- })(SourceIndex || {});
7
- var TakoException = class extends Error {
8
- constructor(status, message, details) {
9
- super(message);
10
- this.status = status;
11
- this.details = details;
12
- this.name = "TakoException";
1
+ // src/generated/runtime.ts
2
+ var BASE_PATH = "https://tako.com/api".replace(/\/+$/, "");
3
+ var Configuration = class {
4
+ constructor(configuration = {}) {
5
+ this.configuration = configuration;
6
+ }
7
+ set config(configuration) {
8
+ this.configuration = configuration;
9
+ }
10
+ get basePath() {
11
+ return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH;
12
+ }
13
+ get fetchApi() {
14
+ return this.configuration.fetchApi;
15
+ }
16
+ get middleware() {
17
+ return this.configuration.middleware || [];
18
+ }
19
+ get queryParamsStringify() {
20
+ return this.configuration.queryParamsStringify || querystring;
21
+ }
22
+ get username() {
23
+ return this.configuration.username;
24
+ }
25
+ get password() {
26
+ return this.configuration.password;
27
+ }
28
+ get apiKey() {
29
+ const apiKey = this.configuration.apiKey;
30
+ if (apiKey) {
31
+ return typeof apiKey === "function" ? apiKey : () => apiKey;
32
+ }
33
+ return void 0;
34
+ }
35
+ get accessToken() {
36
+ const accessToken = this.configuration.accessToken;
37
+ if (accessToken) {
38
+ return typeof accessToken === "function" ? accessToken : async () => accessToken;
39
+ }
40
+ return void 0;
41
+ }
42
+ get headers() {
43
+ return this.configuration.headers;
44
+ }
45
+ get credentials() {
46
+ return this.configuration.credentials;
13
47
  }
14
48
  };
15
- var TakoUnauthorizedException = class extends TakoException {
16
- constructor(message = "Unauthorized", details) {
17
- super(401, message, details);
18
- this.name = "TakoUnauthorizedException";
49
+ var DefaultConfig = new Configuration();
50
+ var _BaseAPI = class _BaseAPI {
51
+ constructor(configuration = DefaultConfig) {
52
+ this.configuration = configuration;
53
+ this.fetchApi = async (url, init) => {
54
+ let fetchParams = { url, init };
55
+ for (const middleware of this.middleware) {
56
+ if (middleware.pre) {
57
+ fetchParams = await middleware.pre({
58
+ fetch: this.fetchApi,
59
+ ...fetchParams
60
+ }) || fetchParams;
61
+ }
62
+ }
63
+ let response = void 0;
64
+ try {
65
+ response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init);
66
+ } catch (e) {
67
+ for (const middleware of this.middleware) {
68
+ if (middleware.onError) {
69
+ response = await middleware.onError({
70
+ fetch: this.fetchApi,
71
+ url: fetchParams.url,
72
+ init: fetchParams.init,
73
+ error: e,
74
+ response: response ? response.clone() : void 0
75
+ }) || response;
76
+ }
77
+ }
78
+ if (response === void 0) {
79
+ if (e instanceof Error) {
80
+ throw new FetchError(e, "The request failed and the interceptors did not return an alternative response");
81
+ } else {
82
+ throw e;
83
+ }
84
+ }
85
+ }
86
+ for (const middleware of this.middleware) {
87
+ if (middleware.post) {
88
+ response = await middleware.post({
89
+ fetch: this.fetchApi,
90
+ url: fetchParams.url,
91
+ init: fetchParams.init,
92
+ response: response.clone()
93
+ }) || response;
94
+ }
95
+ }
96
+ return response;
97
+ };
98
+ this.middleware = configuration.middleware;
99
+ }
100
+ withMiddleware(...middlewares) {
101
+ const next = this.clone();
102
+ next.middleware = next.middleware.concat(...middlewares);
103
+ return next;
104
+ }
105
+ withPreMiddleware(...preMiddlewares) {
106
+ const middlewares = preMiddlewares.map((pre) => ({ pre }));
107
+ return this.withMiddleware(...middlewares);
108
+ }
109
+ withPostMiddleware(...postMiddlewares) {
110
+ const middlewares = postMiddlewares.map((post) => ({ post }));
111
+ return this.withMiddleware(...middlewares);
112
+ }
113
+ /**
114
+ * Check if the given MIME is a JSON MIME.
115
+ * JSON MIME examples:
116
+ * application/json
117
+ * application/json; charset=UTF8
118
+ * APPLICATION/JSON
119
+ * application/vnd.company+json
120
+ * @param mime - MIME (Multipurpose Internet Mail Extensions)
121
+ * @return True if the given MIME is JSON, false otherwise.
122
+ */
123
+ isJsonMime(mime) {
124
+ if (!mime) {
125
+ return false;
126
+ }
127
+ return _BaseAPI.jsonRegex.test(mime);
128
+ }
129
+ async request(context, initOverrides) {
130
+ const { url, init } = await this.createFetchParams(context, initOverrides);
131
+ const response = await this.fetchApi(url, init);
132
+ if (response && (response.status >= 200 && response.status < 300)) {
133
+ return response;
134
+ }
135
+ throw new ResponseError(response, "Response returned an error code");
136
+ }
137
+ async createFetchParams(context, initOverrides) {
138
+ let url = this.configuration.basePath + context.path;
139
+ if (context.query !== void 0 && Object.keys(context.query).length !== 0) {
140
+ url += "?" + this.configuration.queryParamsStringify(context.query);
141
+ }
142
+ const headers = Object.assign({}, this.configuration.headers, context.headers);
143
+ Object.keys(headers).forEach((key) => headers[key] === void 0 ? delete headers[key] : {});
144
+ const initOverrideFn = typeof initOverrides === "function" ? initOverrides : async () => initOverrides;
145
+ const initParams = {
146
+ method: context.method,
147
+ headers,
148
+ body: context.body,
149
+ credentials: this.configuration.credentials
150
+ };
151
+ const overriddenInit = {
152
+ ...initParams,
153
+ ...await initOverrideFn({
154
+ init: initParams,
155
+ context
156
+ })
157
+ };
158
+ let body;
159
+ if (isFormData(overriddenInit.body) || overriddenInit.body instanceof URLSearchParams || isBlob(overriddenInit.body)) {
160
+ body = overriddenInit.body;
161
+ } else if (this.isJsonMime(headers["Content-Type"])) {
162
+ body = JSON.stringify(overriddenInit.body);
163
+ } else {
164
+ body = overriddenInit.body;
165
+ }
166
+ const init = {
167
+ ...overriddenInit,
168
+ body
169
+ };
170
+ return { url, init };
171
+ }
172
+ /**
173
+ * Create a shallow clone of `this` by constructing a new instance
174
+ * and then shallow cloning data members.
175
+ */
176
+ clone() {
177
+ const constructor = this.constructor;
178
+ const next = new constructor(this.configuration);
179
+ next.middleware = this.middleware.slice();
180
+ return next;
181
+ }
182
+ };
183
+ _BaseAPI.jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i;
184
+ var BaseAPI = _BaseAPI;
185
+ function isBlob(value) {
186
+ return typeof Blob !== "undefined" && value instanceof Blob;
187
+ }
188
+ function isFormData(value) {
189
+ return typeof FormData !== "undefined" && value instanceof FormData;
190
+ }
191
+ var ResponseError = class extends Error {
192
+ constructor(response, msg) {
193
+ super(msg);
194
+ this.response = response;
195
+ this.name = "ResponseError";
196
+ const actualProto = new.target.prototype;
197
+ if (Object.setPrototypeOf) {
198
+ Object.setPrototypeOf(this, actualProto);
199
+ }
200
+ }
201
+ };
202
+ var FetchError = class extends Error {
203
+ constructor(cause, msg) {
204
+ super(msg);
205
+ this.cause = cause;
206
+ this.name = "FetchError";
207
+ const actualProto = new.target.prototype;
208
+ if (Object.setPrototypeOf) {
209
+ Object.setPrototypeOf(this, actualProto);
210
+ }
211
+ }
212
+ };
213
+ var RequiredError = class extends Error {
214
+ constructor(field, msg) {
215
+ super(msg);
216
+ this.field = field;
217
+ this.name = "RequiredError";
218
+ const actualProto = new.target.prototype;
219
+ if (Object.setPrototypeOf) {
220
+ Object.setPrototypeOf(this, actualProto);
221
+ }
222
+ }
223
+ };
224
+ var COLLECTION_FORMATS = {
225
+ csv: ",",
226
+ ssv: " ",
227
+ tsv: " ",
228
+ pipes: "|"
229
+ };
230
+ function querystring(params, prefix = "") {
231
+ return Object.keys(params).map((key) => querystringSingleKey(key, params[key], prefix)).filter((part) => part.length > 0).join("&");
232
+ }
233
+ function querystringSingleKey(key, value, keyPrefix = "") {
234
+ const fullKey = keyPrefix + (keyPrefix.length ? `[${key}]` : key);
235
+ if (value instanceof Array) {
236
+ const multiValue = value.map((singleValue) => encodeURIComponent(String(singleValue))).join(`&${encodeURIComponent(fullKey)}=`);
237
+ return `${encodeURIComponent(fullKey)}=${multiValue}`;
238
+ }
239
+ if (value instanceof Set) {
240
+ const valueAsArray = Array.from(value);
241
+ return querystringSingleKey(key, valueAsArray, keyPrefix);
242
+ }
243
+ if (value instanceof Date) {
244
+ return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`;
245
+ }
246
+ if (value instanceof Object) {
247
+ return querystring(value, fullKey);
248
+ }
249
+ return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
250
+ }
251
+ function exists(json, key) {
252
+ const value = json[key];
253
+ return value !== null && value !== void 0;
254
+ }
255
+ function mapValues(data, fn) {
256
+ const result = {};
257
+ for (const key of Object.keys(data)) {
258
+ result[key] = fn(data[key]);
259
+ }
260
+ return result;
261
+ }
262
+ function canConsumeForm(consumes) {
263
+ for (const consume of consumes) {
264
+ if ("multipart/form-data" === consume.contentType) {
265
+ return true;
266
+ }
267
+ }
268
+ return false;
269
+ }
270
+ var JSONApiResponse = class {
271
+ constructor(raw, transformer = (jsonValue) => jsonValue) {
272
+ this.raw = raw;
273
+ this.transformer = transformer;
274
+ }
275
+ async value() {
276
+ return this.transformer(await this.raw.json());
277
+ }
278
+ };
279
+ var VoidApiResponse = class {
280
+ constructor(raw) {
281
+ this.raw = raw;
282
+ }
283
+ async value() {
284
+ return void 0;
285
+ }
286
+ };
287
+ var BlobApiResponse = class {
288
+ constructor(raw) {
289
+ this.raw = raw;
290
+ }
291
+ async value() {
292
+ return await this.raw.blob();
293
+ }
294
+ };
295
+ var TextApiResponse = class {
296
+ constructor(raw) {
297
+ this.raw = raw;
298
+ }
299
+ async value() {
300
+ return await this.raw.text();
301
+ }
302
+ };
303
+
304
+ // src/generated/models/KnowledgeCardMethodology.ts
305
+ function instanceOfKnowledgeCardMethodology(value) {
306
+ if (!("methodology_name" in value) || value["methodology_name"] === void 0) return false;
307
+ if (!("methodology_description" in value) || value["methodology_description"] === void 0) return false;
308
+ return true;
309
+ }
310
+ function KnowledgeCardMethodologyFromJSON(json) {
311
+ return KnowledgeCardMethodologyFromJSONTyped(json, false);
312
+ }
313
+ function KnowledgeCardMethodologyFromJSONTyped(json, ignoreDiscriminator) {
314
+ if (json == null) {
315
+ return json;
316
+ }
317
+ return {
318
+ "methodology_name": json["methodology_name"],
319
+ "methodology_description": json["methodology_description"]
320
+ };
321
+ }
322
+ function KnowledgeCardMethodologyToJSON(json) {
323
+ return KnowledgeCardMethodologyToJSONTyped(json, false);
324
+ }
325
+ function KnowledgeCardMethodologyToJSONTyped(value, ignoreDiscriminator = false) {
326
+ if (value == null) {
327
+ return value;
328
+ }
329
+ return {
330
+ "methodology_name": value["methodology_name"],
331
+ "methodology_description": value["methodology_description"]
332
+ };
333
+ }
334
+
335
+ // src/generated/models/CardSourceIndex.ts
336
+ var CardSourceIndex = {
337
+ Tako: "tako",
338
+ Web: "web",
339
+ ConnectedData: "connected_data",
340
+ TakoDeepV2: "tako_deep_v2"
341
+ };
342
+ function instanceOfCardSourceIndex(value) {
343
+ for (const key in CardSourceIndex) {
344
+ if (Object.prototype.hasOwnProperty.call(CardSourceIndex, key)) {
345
+ if (CardSourceIndex[key] === value) {
346
+ return true;
347
+ }
348
+ }
349
+ }
350
+ return false;
351
+ }
352
+ function CardSourceIndexFromJSON(json) {
353
+ return CardSourceIndexFromJSONTyped(json, false);
354
+ }
355
+ function CardSourceIndexFromJSONTyped(json, ignoreDiscriminator) {
356
+ return json;
357
+ }
358
+ function CardSourceIndexToJSON(value) {
359
+ return value;
360
+ }
361
+ function CardSourceIndexToJSONTyped(value, ignoreDiscriminator) {
362
+ return value;
363
+ }
364
+
365
+ // src/generated/models/KnowledgeCardSourceIndexesInner.ts
366
+ function instanceOfKnowledgeCardSourceIndexesInner(value) {
367
+ if (!("index_type" in value) || value["index_type"] === void 0) return false;
368
+ if (!("segment_id" in value) || value["segment_id"] === void 0) return false;
369
+ return true;
370
+ }
371
+ function KnowledgeCardSourceIndexesInnerFromJSON(json) {
372
+ return KnowledgeCardSourceIndexesInnerFromJSONTyped(json, false);
373
+ }
374
+ function KnowledgeCardSourceIndexesInnerFromJSONTyped(json, ignoreDiscriminator) {
375
+ if (json == null) {
376
+ return json;
377
+ }
378
+ return {
379
+ "index_type": CardSourceIndexFromJSON(json["index_type"]),
380
+ "segment_id": json["segment_id"]
381
+ };
382
+ }
383
+ function KnowledgeCardSourceIndexesInnerToJSON(json) {
384
+ return KnowledgeCardSourceIndexesInnerToJSONTyped(json, false);
385
+ }
386
+ function KnowledgeCardSourceIndexesInnerToJSONTyped(value, ignoreDiscriminator = false) {
387
+ if (value == null) {
388
+ return value;
389
+ }
390
+ return {
391
+ "index_type": CardSourceIndexToJSON(value["index_type"]),
392
+ "segment_id": value["segment_id"]
393
+ };
394
+ }
395
+
396
+ // src/generated/models/SourceIndex.ts
397
+ function instanceOfSourceIndex(value) {
398
+ if (!("index_type" in value) || value["index_type"] === void 0) return false;
399
+ if (!("segment_id" in value) || value["segment_id"] === void 0) return false;
400
+ if (!("private_index_id" in value) || value["private_index_id"] === void 0) return false;
401
+ return true;
402
+ }
403
+ function SourceIndexFromJSON(json) {
404
+ return SourceIndexFromJSONTyped(json, false);
405
+ }
406
+ function SourceIndexFromJSONTyped(json, ignoreDiscriminator) {
407
+ if (json == null) {
408
+ return json;
409
+ }
410
+ return {
411
+ "index_type": CardSourceIndexFromJSON(json["index_type"]),
412
+ "segment_id": json["segment_id"],
413
+ "private_index_id": json["private_index_id"]
414
+ };
415
+ }
416
+ function SourceIndexToJSON(json) {
417
+ return SourceIndexToJSONTyped(json, false);
418
+ }
419
+ function SourceIndexToJSONTyped(value, ignoreDiscriminator = false) {
420
+ if (value == null) {
421
+ return value;
422
+ }
423
+ return {
424
+ "index_type": CardSourceIndexToJSON(value["index_type"]),
425
+ "segment_id": value["segment_id"],
426
+ "private_index_id": value["private_index_id"]
427
+ };
428
+ }
429
+
430
+ // src/generated/models/KnowledgeCardSource.ts
431
+ function instanceOfKnowledgeCardSource(value) {
432
+ if (!("source_name" in value) || value["source_name"] === void 0) return false;
433
+ if (!("source_description" in value) || value["source_description"] === void 0) return false;
434
+ if (!("source_index" in value) || value["source_index"] === void 0) return false;
435
+ if (!("url" in value) || value["url"] === void 0) return false;
436
+ return true;
437
+ }
438
+ function KnowledgeCardSourceFromJSON(json) {
439
+ return KnowledgeCardSourceFromJSONTyped(json, false);
440
+ }
441
+ function KnowledgeCardSourceFromJSONTyped(json, ignoreDiscriminator) {
442
+ if (json == null) {
443
+ return json;
444
+ }
445
+ return {
446
+ "source_name": json["source_name"],
447
+ "source_description": json["source_description"],
448
+ "source_index": SourceIndexFromJSON(json["source_index"]),
449
+ "url": json["url"],
450
+ "source_text": json["source_text"] == null ? void 0 : json["source_text"]
451
+ };
452
+ }
453
+ function KnowledgeCardSourceToJSON(json) {
454
+ return KnowledgeCardSourceToJSONTyped(json, false);
455
+ }
456
+ function KnowledgeCardSourceToJSONTyped(value, ignoreDiscriminator = false) {
457
+ if (value == null) {
458
+ return value;
459
+ }
460
+ return {
461
+ "source_name": value["source_name"],
462
+ "source_description": value["source_description"],
463
+ "source_index": SourceIndexToJSON(value["source_index"]),
464
+ "url": value["url"],
465
+ "source_text": value["source_text"]
466
+ };
467
+ }
468
+
469
+ // src/generated/models/ContentFormat.ts
470
+ var ContentFormat = {
471
+ Csv: "csv",
472
+ Text: "text"
473
+ };
474
+ function instanceOfContentFormat(value) {
475
+ for (const key in ContentFormat) {
476
+ if (Object.prototype.hasOwnProperty.call(ContentFormat, key)) {
477
+ if (ContentFormat[key] === value) {
478
+ return true;
479
+ }
480
+ }
481
+ }
482
+ return false;
483
+ }
484
+ function ContentFormatFromJSON(json) {
485
+ return ContentFormatFromJSONTyped(json, false);
486
+ }
487
+ function ContentFormatFromJSONTyped(json, ignoreDiscriminator) {
488
+ return json;
489
+ }
490
+ function ContentFormatToJSON(value) {
491
+ return value;
492
+ }
493
+ function ContentFormatToJSONTyped(value, ignoreDiscriminator) {
494
+ return value;
495
+ }
496
+
497
+ // src/generated/models/ResultContent.ts
498
+ function instanceOfResultContent(value) {
499
+ if (!("format" in value) || value["format"] === void 0) return false;
500
+ return true;
501
+ }
502
+ function ResultContentFromJSON(json) {
503
+ return ResultContentFromJSONTyped(json, false);
504
+ }
505
+ function ResultContentFromJSONTyped(json, ignoreDiscriminator) {
506
+ if (json == null) {
507
+ return json;
508
+ }
509
+ return {
510
+ "format": ContentFormatFromJSON(json["format"]),
511
+ "cost": json["cost"] == null ? void 0 : json["cost"],
512
+ "data": json["data"] == null ? void 0 : json["data"],
513
+ "total_rows": json["total_rows"] == null ? void 0 : json["total_rows"],
514
+ "truncated": json["truncated"] == null ? void 0 : json["truncated"]
515
+ };
516
+ }
517
+ function ResultContentToJSON(json) {
518
+ return ResultContentToJSONTyped(json, false);
519
+ }
520
+ function ResultContentToJSONTyped(value, ignoreDiscriminator = false) {
521
+ if (value == null) {
522
+ return value;
523
+ }
524
+ return {
525
+ "format": ContentFormatToJSON(value["format"]),
526
+ "cost": value["cost"],
527
+ "data": value["data"],
528
+ "total_rows": value["total_rows"],
529
+ "truncated": value["truncated"]
530
+ };
531
+ }
532
+
533
+ // src/generated/models/KnowledgeCardRelevance.ts
534
+ var KnowledgeCardRelevance = {
535
+ High: "High",
536
+ Medium: "Medium",
537
+ Low: "Low"
538
+ };
539
+ function instanceOfKnowledgeCardRelevance(value) {
540
+ for (const key in KnowledgeCardRelevance) {
541
+ if (Object.prototype.hasOwnProperty.call(KnowledgeCardRelevance, key)) {
542
+ if (KnowledgeCardRelevance[key] === value) {
543
+ return true;
544
+ }
545
+ }
546
+ }
547
+ return false;
548
+ }
549
+ function KnowledgeCardRelevanceFromJSON(json) {
550
+ return KnowledgeCardRelevanceFromJSONTyped(json, false);
551
+ }
552
+ function KnowledgeCardRelevanceFromJSONTyped(json, ignoreDiscriminator) {
553
+ return json;
554
+ }
555
+ function KnowledgeCardRelevanceToJSON(value) {
556
+ return value;
557
+ }
558
+ function KnowledgeCardRelevanceToJSONTyped(value, ignoreDiscriminator) {
559
+ return value;
560
+ }
561
+
562
+ // src/generated/models/TakoCard.ts
563
+ function instanceOfTakoCard(value) {
564
+ return true;
565
+ }
566
+ function TakoCardFromJSON(json) {
567
+ return TakoCardFromJSONTyped(json, false);
568
+ }
569
+ function TakoCardFromJSONTyped(json, ignoreDiscriminator) {
570
+ if (json == null) {
571
+ return json;
572
+ }
573
+ return {
574
+ "card_id": json["card_id"] == null ? void 0 : json["card_id"],
575
+ "title": json["title"] == null ? void 0 : json["title"],
576
+ "description": json["description"] == null ? void 0 : json["description"],
577
+ "semantic_description": json["semantic_description"] == null ? void 0 : json["semantic_description"],
578
+ "webpage_url": json["webpage_url"] == null ? void 0 : json["webpage_url"],
579
+ "image_url": json["image_url"] == null ? void 0 : json["image_url"],
580
+ "embed_url": json["embed_url"] == null ? void 0 : json["embed_url"],
581
+ "sources": json["sources"] == null ? void 0 : json["sources"].map(KnowledgeCardSourceFromJSON),
582
+ "methodologies": json["methodologies"] == null ? void 0 : json["methodologies"].map(KnowledgeCardMethodologyFromJSON),
583
+ "source_indexes": json["source_indexes"] == null ? void 0 : json["source_indexes"].map(KnowledgeCardSourceIndexesInnerFromJSON),
584
+ "card_type": json["card_type"] == null ? void 0 : json["card_type"],
585
+ "relevance": json["relevance"] == null ? void 0 : KnowledgeCardRelevanceFromJSON(json["relevance"]),
586
+ "content": json["content"] == null ? void 0 : ResultContentFromJSON(json["content"]),
587
+ "relevance_score": json["relevance_score"] == null ? void 0 : json["relevance_score"]
588
+ };
589
+ }
590
+ function TakoCardToJSON(json) {
591
+ return TakoCardToJSONTyped(json, false);
592
+ }
593
+ function TakoCardToJSONTyped(value, ignoreDiscriminator = false) {
594
+ if (value == null) {
595
+ return value;
596
+ }
597
+ return {
598
+ "card_id": value["card_id"],
599
+ "title": value["title"],
600
+ "description": value["description"],
601
+ "semantic_description": value["semantic_description"],
602
+ "webpage_url": value["webpage_url"],
603
+ "image_url": value["image_url"],
604
+ "embed_url": value["embed_url"],
605
+ "sources": value["sources"] == null ? void 0 : value["sources"].map(KnowledgeCardSourceToJSON),
606
+ "methodologies": value["methodologies"] == null ? void 0 : value["methodologies"].map(KnowledgeCardMethodologyToJSON),
607
+ "source_indexes": value["source_indexes"] == null ? void 0 : value["source_indexes"].map(KnowledgeCardSourceIndexesInnerToJSON),
608
+ "card_type": value["card_type"],
609
+ "relevance": KnowledgeCardRelevanceToJSON(value["relevance"]),
610
+ "content": ResultContentToJSON(value["content"]),
611
+ "relevance_score": value["relevance_score"]
612
+ };
613
+ }
614
+
615
+ // src/generated/models/WebResult.ts
616
+ function instanceOfWebResult(value) {
617
+ if (!("title" in value) || value["title"] === void 0) return false;
618
+ if (!("url" in value) || value["url"] === void 0) return false;
619
+ return true;
620
+ }
621
+ function WebResultFromJSON(json) {
622
+ return WebResultFromJSONTyped(json, false);
623
+ }
624
+ function WebResultFromJSONTyped(json, ignoreDiscriminator) {
625
+ if (json == null) {
626
+ return json;
627
+ }
628
+ return {
629
+ "title": json["title"],
630
+ "url": json["url"],
631
+ "snippet": json["snippet"] == null ? void 0 : json["snippet"],
632
+ "source_name": json["source_name"] == null ? void 0 : json["source_name"],
633
+ "publish_date": json["publish_date"] == null ? void 0 : json["publish_date"],
634
+ "content": json["content"] == null ? void 0 : ResultContentFromJSON(json["content"]),
635
+ "citation_number": json["citation_number"] == null ? void 0 : json["citation_number"]
636
+ };
637
+ }
638
+ function WebResultToJSON(json) {
639
+ return WebResultToJSONTyped(json, false);
640
+ }
641
+ function WebResultToJSONTyped(value, ignoreDiscriminator = false) {
642
+ if (value == null) {
643
+ return value;
644
+ }
645
+ return {
646
+ "title": value["title"],
647
+ "url": value["url"],
648
+ "snippet": value["snippet"],
649
+ "source_name": value["source_name"],
650
+ "publish_date": value["publish_date"],
651
+ "content": ResultContentToJSON(value["content"]),
652
+ "citation_number": value["citation_number"]
653
+ };
654
+ }
655
+
656
+ // src/generated/models/AgentResult.ts
657
+ function instanceOfAgentResult(value) {
658
+ return true;
659
+ }
660
+ function AgentResultFromJSON(json) {
661
+ return AgentResultFromJSONTyped(json, false);
662
+ }
663
+ function AgentResultFromJSONTyped(json, ignoreDiscriminator) {
664
+ if (json == null) {
665
+ return json;
666
+ }
667
+ return {
668
+ "answer": json["answer"] == null ? void 0 : json["answer"],
669
+ "cards": json["cards"] == null ? void 0 : json["cards"].map(TakoCardFromJSON),
670
+ "web_results": json["web_results"] == null ? void 0 : json["web_results"].map(WebResultFromJSON),
671
+ "request_id": json["request_id"] == null ? void 0 : json["request_id"]
672
+ };
673
+ }
674
+ function AgentResultToJSON(json) {
675
+ return AgentResultToJSONTyped(json, false);
676
+ }
677
+ function AgentResultToJSONTyped(value, ignoreDiscriminator = false) {
678
+ if (value == null) {
679
+ return value;
680
+ }
681
+ return {
682
+ "answer": value["answer"],
683
+ "cards": value["cards"] == null ? void 0 : value["cards"].map(TakoCardToJSON),
684
+ "web_results": value["web_results"] == null ? void 0 : value["web_results"].map(WebResultToJSON),
685
+ "request_id": value["request_id"]
686
+ };
687
+ }
688
+
689
+ // src/generated/models/AgentRunStatus.ts
690
+ var AgentRunStatus = {
691
+ Queued: "queued",
692
+ Running: "running",
693
+ Completed: "completed",
694
+ Failed: "failed"
695
+ };
696
+ function instanceOfAgentRunStatus(value) {
697
+ for (const key in AgentRunStatus) {
698
+ if (Object.prototype.hasOwnProperty.call(AgentRunStatus, key)) {
699
+ if (AgentRunStatus[key] === value) {
700
+ return true;
701
+ }
702
+ }
703
+ }
704
+ return false;
705
+ }
706
+ function AgentRunStatusFromJSON(json) {
707
+ return AgentRunStatusFromJSONTyped(json, false);
708
+ }
709
+ function AgentRunStatusFromJSONTyped(json, ignoreDiscriminator) {
710
+ return json;
711
+ }
712
+ function AgentRunStatusToJSON(value) {
713
+ return value;
714
+ }
715
+ function AgentRunStatusToJSONTyped(value, ignoreDiscriminator) {
716
+ return value;
717
+ }
718
+
719
+ // src/generated/models/ErrorObject.ts
720
+ function instanceOfErrorObject(value) {
721
+ if (!("code" in value) || value["code"] === void 0) return false;
722
+ if (!("message" in value) || value["message"] === void 0) return false;
723
+ return true;
724
+ }
725
+ function ErrorObjectFromJSON(json) {
726
+ return ErrorObjectFromJSONTyped(json, false);
727
+ }
728
+ function ErrorObjectFromJSONTyped(json, ignoreDiscriminator) {
729
+ if (json == null) {
730
+ return json;
731
+ }
732
+ return {
733
+ "code": json["code"],
734
+ "message": json["message"]
735
+ };
736
+ }
737
+ function ErrorObjectToJSON(json) {
738
+ return ErrorObjectToJSONTyped(json, false);
739
+ }
740
+ function ErrorObjectToJSONTyped(value, ignoreDiscriminator = false) {
741
+ if (value == null) {
742
+ return value;
743
+ }
744
+ return {
745
+ "code": value["code"],
746
+ "message": value["message"]
747
+ };
748
+ }
749
+
750
+ // src/generated/models/AgentRun.ts
751
+ var AgentRunObjectEnum = {
752
+ AgentRun: "agent.run"
753
+ };
754
+ function instanceOfAgentRun(value) {
755
+ if (!("run_id" in value) || value["run_id"] === void 0) return false;
756
+ if (!("status" in value) || value["status"] === void 0) return false;
757
+ if (!("created_at" in value) || value["created_at"] === void 0) return false;
758
+ return true;
759
+ }
760
+ function AgentRunFromJSON(json) {
761
+ return AgentRunFromJSONTyped(json, false);
762
+ }
763
+ function AgentRunFromJSONTyped(json, ignoreDiscriminator) {
764
+ if (json == null) {
765
+ return json;
766
+ }
767
+ return {
768
+ "run_id": json["run_id"],
769
+ "object": json["object"] == null ? void 0 : json["object"],
770
+ "thread_id": json["thread_id"] == null ? void 0 : json["thread_id"],
771
+ "status": AgentRunStatusFromJSON(json["status"]),
772
+ "created_at": json["created_at"],
773
+ "completed_at": json["completed_at"] == null ? void 0 : json["completed_at"],
774
+ "result": json["result"] == null ? void 0 : AgentResultFromJSON(json["result"]),
775
+ "error": json["error"] == null ? void 0 : ErrorObjectFromJSON(json["error"])
776
+ };
777
+ }
778
+ function AgentRunToJSON(json) {
779
+ return AgentRunToJSONTyped(json, false);
780
+ }
781
+ function AgentRunToJSONTyped(value, ignoreDiscriminator = false) {
782
+ if (value == null) {
783
+ return value;
784
+ }
785
+ return {
786
+ "run_id": value["run_id"],
787
+ "object": value["object"],
788
+ "thread_id": value["thread_id"],
789
+ "status": AgentRunStatusToJSON(value["status"]),
790
+ "created_at": value["created_at"],
791
+ "completed_at": value["completed_at"],
792
+ "result": AgentResultToJSON(value["result"]),
793
+ "error": ErrorObjectToJSON(value["error"])
794
+ };
795
+ }
796
+
797
+ // src/generated/models/AgentEffortLevel.ts
798
+ var AgentEffortLevel = {
799
+ Medium: "medium"
800
+ };
801
+ function instanceOfAgentEffortLevel(value) {
802
+ for (const key in AgentEffortLevel) {
803
+ if (Object.prototype.hasOwnProperty.call(AgentEffortLevel, key)) {
804
+ if (AgentEffortLevel[key] === value) {
805
+ return true;
806
+ }
807
+ }
808
+ }
809
+ return false;
810
+ }
811
+ function AgentEffortLevelFromJSON(json) {
812
+ return AgentEffortLevelFromJSONTyped(json, false);
813
+ }
814
+ function AgentEffortLevelFromJSONTyped(json, ignoreDiscriminator) {
815
+ return json;
816
+ }
817
+ function AgentEffortLevelToJSON(value) {
818
+ return value;
819
+ }
820
+ function AgentEffortLevelToJSONTyped(value, ignoreDiscriminator) {
821
+ return value;
822
+ }
823
+
824
+ // src/generated/models/AgentOutputSettings.ts
825
+ function instanceOfAgentOutputSettings(value) {
826
+ return true;
827
+ }
828
+ function AgentOutputSettingsFromJSON(json) {
829
+ return AgentOutputSettingsFromJSONTyped(json, false);
830
+ }
831
+ function AgentOutputSettingsFromJSONTyped(json, ignoreDiscriminator) {
832
+ if (json == null) {
833
+ return json;
834
+ }
835
+ return {
836
+ "image_dark_mode": json["image_dark_mode"] == null ? void 0 : json["image_dark_mode"]
837
+ };
838
+ }
839
+ function AgentOutputSettingsToJSON(json) {
840
+ return AgentOutputSettingsToJSONTyped(json, false);
841
+ }
842
+ function AgentOutputSettingsToJSONTyped(value, ignoreDiscriminator = false) {
843
+ if (value == null) {
844
+ return value;
845
+ }
846
+ return {
847
+ "image_dark_mode": value["image_dark_mode"]
848
+ };
849
+ }
850
+
851
+ // src/generated/models/AgentRunRequest.ts
852
+ var AgentRunRequestSourceIndexesEnum = {
853
+ Data: "data",
854
+ Web: "web"
855
+ };
856
+ function instanceOfAgentRunRequest(value) {
857
+ if (!("query" in value) || value["query"] === void 0) return false;
858
+ return true;
859
+ }
860
+ function AgentRunRequestFromJSON(json) {
861
+ return AgentRunRequestFromJSONTyped(json, false);
862
+ }
863
+ function AgentRunRequestFromJSONTyped(json, ignoreDiscriminator) {
864
+ if (json == null) {
865
+ return json;
866
+ }
867
+ return {
868
+ "query": json["query"],
869
+ "thread_id": json["thread_id"] == null ? void 0 : json["thread_id"],
870
+ "effort": json["effort"] == null ? void 0 : AgentEffortLevelFromJSON(json["effort"]),
871
+ "source_indexes": json["source_indexes"] == null ? void 0 : json["source_indexes"],
872
+ "locale": json["locale"] == null ? void 0 : json["locale"],
873
+ "timezone": json["timezone"] == null ? void 0 : json["timezone"],
874
+ "output_settings": json["output_settings"] == null ? void 0 : AgentOutputSettingsFromJSON(json["output_settings"])
875
+ };
876
+ }
877
+ function AgentRunRequestToJSON(json) {
878
+ return AgentRunRequestToJSONTyped(json, false);
879
+ }
880
+ function AgentRunRequestToJSONTyped(value, ignoreDiscriminator = false) {
881
+ if (value == null) {
882
+ return value;
883
+ }
884
+ return {
885
+ "query": value["query"],
886
+ "thread_id": value["thread_id"],
887
+ "effort": AgentEffortLevelToJSON(value["effort"]),
888
+ "source_indexes": value["source_indexes"],
889
+ "locale": value["locale"],
890
+ "timezone": value["timezone"],
891
+ "output_settings": AgentOutputSettingsToJSON(value["output_settings"])
892
+ };
893
+ }
894
+
895
+ // src/generated/apis/AgentApi.ts
896
+ var AgentApi = class extends BaseAPI {
897
+ /**
898
+ * Creates request options for createAgentRun without sending the request
899
+ */
900
+ async createAgentRunRequestOpts(requestParameters) {
901
+ const queryParameters = {};
902
+ const headerParameters = {};
903
+ headerParameters["Content-Type"] = "application/json";
904
+ if (this.configuration && this.configuration.apiKey) {
905
+ headerParameters["X-API-Key"] = await this.configuration.apiKey("X-API-Key");
906
+ }
907
+ let urlPath = `/v1/agent/runs`;
908
+ return {
909
+ path: urlPath,
910
+ method: "POST",
911
+ headers: headerParameters,
912
+ query: queryParameters,
913
+ body: AgentRunRequestToJSON(requestParameters["agentRunRequest"])
914
+ };
915
+ }
916
+ /**
917
+ * Dispatch a deep-research agent run. Returns 202 with an AgentRun object; poll GET /v1/agent/runs/{run_id} until status is \'completed\' or \'failed\'.
918
+ * Dispatch an agent run
919
+ */
920
+ async createAgentRunRaw(requestParameters, initOverrides) {
921
+ const requestOptions = await this.createAgentRunRequestOpts(requestParameters);
922
+ const response = await this.request(requestOptions, initOverrides);
923
+ return new JSONApiResponse(response, (jsonValue) => AgentRunFromJSON(jsonValue));
924
+ }
925
+ /**
926
+ * Dispatch a deep-research agent run. Returns 202 with an AgentRun object; poll GET /v1/agent/runs/{run_id} until status is \'completed\' or \'failed\'.
927
+ * Dispatch an agent run
928
+ */
929
+ async createAgentRun(requestParameters = {}, initOverrides) {
930
+ const response = await this.createAgentRunRaw(requestParameters, initOverrides);
931
+ return await response.value();
932
+ }
933
+ /**
934
+ * Creates request options for getAgentRun without sending the request
935
+ */
936
+ async getAgentRunRequestOpts(requestParameters) {
937
+ if (requestParameters["runId"] == null) {
938
+ throw new RequiredError(
939
+ "runId",
940
+ 'Required parameter "runId" was null or undefined when calling getAgentRun().'
941
+ );
942
+ }
943
+ const queryParameters = {};
944
+ if (requestParameters["startingAfter"] != null) {
945
+ queryParameters["starting_after"] = requestParameters["startingAfter"];
946
+ }
947
+ const headerParameters = {};
948
+ if (this.configuration && this.configuration.apiKey) {
949
+ headerParameters["X-API-Key"] = await this.configuration.apiKey("X-API-Key");
950
+ }
951
+ let urlPath = `/v1/agent/runs/{run_id}`;
952
+ urlPath = urlPath.replace("{run_id}", encodeURIComponent(String(requestParameters["runId"])));
953
+ return {
954
+ path: urlPath,
955
+ method: "GET",
956
+ headers: headerParameters,
957
+ query: queryParameters
958
+ };
959
+ }
960
+ /**
961
+ * Retrieve the current state of an agent run. Poll until status is \'completed\' or \'failed\'. result is populated when status is \'completed\'.
962
+ * Poll an agent run
963
+ */
964
+ async getAgentRunRaw(requestParameters, initOverrides) {
965
+ const requestOptions = await this.getAgentRunRequestOpts(requestParameters);
966
+ const response = await this.request(requestOptions, initOverrides);
967
+ return new JSONApiResponse(response, (jsonValue) => AgentRunFromJSON(jsonValue));
968
+ }
969
+ /**
970
+ * Retrieve the current state of an agent run. Poll until status is \'completed\' or \'failed\'. result is populated when status is \'completed\'.
971
+ * Poll an agent run
972
+ */
973
+ async getAgentRun(requestParameters, initOverrides) {
974
+ const response = await this.getAgentRunRaw(requestParameters, initOverrides);
975
+ return await response.value();
976
+ }
977
+ };
978
+
979
+ // src/generated/models/AnswerResponse.ts
980
+ function instanceOfAnswerResponse(value) {
981
+ if (!("answer" in value) || value["answer"] === void 0) return false;
982
+ if (!("request_id" in value) || value["request_id"] === void 0) return false;
983
+ return true;
984
+ }
985
+ function AnswerResponseFromJSON(json) {
986
+ return AnswerResponseFromJSONTyped(json, false);
987
+ }
988
+ function AnswerResponseFromJSONTyped(json, ignoreDiscriminator) {
989
+ if (json == null) {
990
+ return json;
991
+ }
992
+ return {
993
+ "answer": json["answer"],
994
+ "cards": json["cards"] == null ? void 0 : json["cards"].map(TakoCardFromJSON),
995
+ "web_results": json["web_results"] == null ? void 0 : json["web_results"].map(WebResultFromJSON),
996
+ "contents_total_cost": json["contents_total_cost"] == null ? void 0 : json["contents_total_cost"],
997
+ "request_id": json["request_id"]
998
+ };
999
+ }
1000
+ function AnswerResponseToJSON(json) {
1001
+ return AnswerResponseToJSONTyped(json, false);
1002
+ }
1003
+ function AnswerResponseToJSONTyped(value, ignoreDiscriminator = false) {
1004
+ if (value == null) {
1005
+ return value;
1006
+ }
1007
+ return {
1008
+ "answer": value["answer"],
1009
+ "cards": value["cards"] == null ? void 0 : value["cards"].map(TakoCardToJSON),
1010
+ "web_results": value["web_results"] == null ? void 0 : value["web_results"].map(WebResultToJSON),
1011
+ "contents_total_cost": value["contents_total_cost"],
1012
+ "request_id": value["request_id"]
1013
+ };
1014
+ }
1015
+
1016
+ // src/generated/models/ClassifyRequest.ts
1017
+ function instanceOfClassifyRequest(value) {
1018
+ if (!("queries" in value) || value["queries"] === void 0) return false;
1019
+ return true;
1020
+ }
1021
+ function ClassifyRequestFromJSON(json) {
1022
+ return ClassifyRequestFromJSONTyped(json, false);
1023
+ }
1024
+ function ClassifyRequestFromJSONTyped(json, ignoreDiscriminator) {
1025
+ if (json == null) {
1026
+ return json;
1027
+ }
1028
+ return {
1029
+ "queries": json["queries"]
1030
+ };
1031
+ }
1032
+ function ClassifyRequestToJSON(json) {
1033
+ return ClassifyRequestToJSONTyped(json, false);
1034
+ }
1035
+ function ClassifyRequestToJSONTyped(value, ignoreDiscriminator = false) {
1036
+ if (value == null) {
1037
+ return value;
1038
+ }
1039
+ return {
1040
+ "queries": value["queries"]
1041
+ };
1042
+ }
1043
+
1044
+ // src/generated/models/QueryClassification.ts
1045
+ function instanceOfQueryClassification(value) {
1046
+ if (!("query" in value) || value["query"] === void 0) return false;
1047
+ if (!("score" in value) || value["score"] === void 0) return false;
1048
+ if (!("keep" in value) || value["keep"] === void 0) return false;
1049
+ return true;
1050
+ }
1051
+ function QueryClassificationFromJSON(json) {
1052
+ return QueryClassificationFromJSONTyped(json, false);
1053
+ }
1054
+ function QueryClassificationFromJSONTyped(json, ignoreDiscriminator) {
1055
+ if (json == null) {
1056
+ return json;
1057
+ }
1058
+ return {
1059
+ "query": json["query"],
1060
+ "score": json["score"],
1061
+ "keep": json["keep"]
1062
+ };
1063
+ }
1064
+ function QueryClassificationToJSON(json) {
1065
+ return QueryClassificationToJSONTyped(json, false);
1066
+ }
1067
+ function QueryClassificationToJSONTyped(value, ignoreDiscriminator = false) {
1068
+ if (value == null) {
1069
+ return value;
1070
+ }
1071
+ return {
1072
+ "query": value["query"],
1073
+ "score": value["score"],
1074
+ "keep": value["keep"]
1075
+ };
1076
+ }
1077
+
1078
+ // src/generated/models/ClassifyResponse.ts
1079
+ function instanceOfClassifyResponse(value) {
1080
+ return true;
1081
+ }
1082
+ function ClassifyResponseFromJSON(json) {
1083
+ return ClassifyResponseFromJSONTyped(json, false);
1084
+ }
1085
+ function ClassifyResponseFromJSONTyped(json, ignoreDiscriminator) {
1086
+ if (json == null) {
1087
+ return json;
1088
+ }
1089
+ return {
1090
+ "results": json["results"] == null ? void 0 : json["results"].map(QueryClassificationFromJSON)
1091
+ };
1092
+ }
1093
+ function ClassifyResponseToJSON(json) {
1094
+ return ClassifyResponseToJSONTyped(json, false);
1095
+ }
1096
+ function ClassifyResponseToJSONTyped(value, ignoreDiscriminator = false) {
1097
+ if (value == null) {
1098
+ return value;
1099
+ }
1100
+ return {
1101
+ "results": value["results"] == null ? void 0 : value["results"].map(QueryClassificationToJSON)
1102
+ };
1103
+ }
1104
+
1105
+ // src/generated/models/ContentsDeliveryMode.ts
1106
+ var ContentsDeliveryMode = {
1107
+ Url: "url",
1108
+ Inline: "inline"
1109
+ };
1110
+ function instanceOfContentsDeliveryMode(value) {
1111
+ for (const key in ContentsDeliveryMode) {
1112
+ if (Object.prototype.hasOwnProperty.call(ContentsDeliveryMode, key)) {
1113
+ if (ContentsDeliveryMode[key] === value) {
1114
+ return true;
1115
+ }
1116
+ }
1117
+ }
1118
+ return false;
1119
+ }
1120
+ function ContentsDeliveryModeFromJSON(json) {
1121
+ return ContentsDeliveryModeFromJSONTyped(json, false);
1122
+ }
1123
+ function ContentsDeliveryModeFromJSONTyped(json, ignoreDiscriminator) {
1124
+ return json;
1125
+ }
1126
+ function ContentsDeliveryModeToJSON(value) {
1127
+ return value;
1128
+ }
1129
+ function ContentsDeliveryModeToJSONTyped(value, ignoreDiscriminator) {
1130
+ return value;
1131
+ }
1132
+
1133
+ // src/generated/models/ContentsRequest.ts
1134
+ function instanceOfContentsRequest(value) {
1135
+ if (!("url" in value) || value["url"] === void 0) return false;
1136
+ return true;
1137
+ }
1138
+ function ContentsRequestFromJSON(json) {
1139
+ return ContentsRequestFromJSONTyped(json, false);
1140
+ }
1141
+ function ContentsRequestFromJSONTyped(json, ignoreDiscriminator) {
1142
+ if (json == null) {
1143
+ return json;
1144
+ }
1145
+ return {
1146
+ "url": json["url"],
1147
+ "mode": json["mode"] == null ? void 0 : ContentsDeliveryModeFromJSON(json["mode"])
1148
+ };
1149
+ }
1150
+ function ContentsRequestToJSON(json) {
1151
+ return ContentsRequestToJSONTyped(json, false);
1152
+ }
1153
+ function ContentsRequestToJSONTyped(value, ignoreDiscriminator = false) {
1154
+ if (value == null) {
1155
+ return value;
1156
+ }
1157
+ return {
1158
+ "url": value["url"],
1159
+ "mode": ContentsDeliveryModeToJSON(value["mode"])
1160
+ };
1161
+ }
1162
+
1163
+ // src/generated/models/ContentItem.ts
1164
+ function instanceOfContentItem(value) {
1165
+ if (!("format" in value) || value["format"] === void 0) return false;
1166
+ if (!("source_url" in value) || value["source_url"] === void 0) return false;
1167
+ return true;
1168
+ }
1169
+ function ContentItemFromJSON(json) {
1170
+ return ContentItemFromJSONTyped(json, false);
1171
+ }
1172
+ function ContentItemFromJSONTyped(json, ignoreDiscriminator) {
1173
+ if (json == null) {
1174
+ return json;
1175
+ }
1176
+ return {
1177
+ "format": ContentFormatFromJSON(json["format"]),
1178
+ "cost": json["cost"] == null ? void 0 : json["cost"],
1179
+ "data": json["data"] == null ? void 0 : json["data"],
1180
+ "total_rows": json["total_rows"] == null ? void 0 : json["total_rows"],
1181
+ "truncated": json["truncated"] == null ? void 0 : json["truncated"],
1182
+ "source_url": json["source_url"],
1183
+ "url": json["url"] == null ? void 0 : json["url"],
1184
+ "expires_at": json["expires_at"] == null ? void 0 : json["expires_at"]
1185
+ };
1186
+ }
1187
+ function ContentItemToJSON(json) {
1188
+ return ContentItemToJSONTyped(json, false);
1189
+ }
1190
+ function ContentItemToJSONTyped(value, ignoreDiscriminator = false) {
1191
+ if (value == null) {
1192
+ return value;
1193
+ }
1194
+ return {
1195
+ "format": ContentFormatToJSON(value["format"]),
1196
+ "cost": value["cost"],
1197
+ "data": value["data"],
1198
+ "total_rows": value["total_rows"],
1199
+ "truncated": value["truncated"],
1200
+ "source_url": value["source_url"],
1201
+ "url": value["url"],
1202
+ "expires_at": value["expires_at"]
1203
+ };
1204
+ }
1205
+
1206
+ // src/generated/models/ContentsResponse.ts
1207
+ function instanceOfContentsResponse(value) {
1208
+ if (!("request_id" in value) || value["request_id"] === void 0) return false;
1209
+ return true;
1210
+ }
1211
+ function ContentsResponseFromJSON(json) {
1212
+ return ContentsResponseFromJSONTyped(json, false);
1213
+ }
1214
+ function ContentsResponseFromJSONTyped(json, ignoreDiscriminator) {
1215
+ if (json == null) {
1216
+ return json;
1217
+ }
1218
+ return {
1219
+ "contents": json["contents"] == null ? void 0 : json["contents"].map(ContentItemFromJSON),
1220
+ "request_id": json["request_id"]
1221
+ };
1222
+ }
1223
+ function ContentsResponseToJSON(json) {
1224
+ return ContentsResponseToJSONTyped(json, false);
1225
+ }
1226
+ function ContentsResponseToJSONTyped(value, ignoreDiscriminator = false) {
1227
+ if (value == null) {
1228
+ return value;
1229
+ }
1230
+ return {
1231
+ "contents": value["contents"] == null ? void 0 : value["contents"].map(ContentItemToJSON),
1232
+ "request_id": value["request_id"]
1233
+ };
1234
+ }
1235
+
1236
+ // src/generated/models/ComponentTypeEnum.ts
1237
+ var ComponentTypeEnum = {
1238
+ CategoricalBar: "categorical_bar",
1239
+ Choropleth: "choropleth",
1240
+ DataTableChart: "data_table_chart",
1241
+ FinancialBoxes: "financial_boxes",
1242
+ GenericTimeseries: "generic_timeseries",
1243
+ Header: "header",
1244
+ Heatmap: "heatmap",
1245
+ Histogram: "histogram",
1246
+ Marimekko: "marimekko",
1247
+ Pie: "pie",
1248
+ Scatter: "scatter",
1249
+ Table: "table",
1250
+ Boxplot: "boxplot",
1251
+ Treemap: "treemap",
1252
+ Waterfall: "waterfall",
1253
+ Sankey: "sankey",
1254
+ Bubble: "bubble",
1255
+ PersonCard: "person_card",
1256
+ Timeline: "timeline",
1257
+ TopLevelMetric: "top_level_metric"
1258
+ };
1259
+ function instanceOfComponentTypeEnum(value) {
1260
+ for (const key in ComponentTypeEnum) {
1261
+ if (Object.prototype.hasOwnProperty.call(ComponentTypeEnum, key)) {
1262
+ if (ComponentTypeEnum[key] === value) {
1263
+ return true;
1264
+ }
1265
+ }
1266
+ }
1267
+ return false;
1268
+ }
1269
+ function ComponentTypeEnumFromJSON(json) {
1270
+ return ComponentTypeEnumFromJSONTyped(json, false);
1271
+ }
1272
+ function ComponentTypeEnumFromJSONTyped(json, ignoreDiscriminator) {
1273
+ return json;
1274
+ }
1275
+ function ComponentTypeEnumToJSON(value) {
1276
+ return value;
1277
+ }
1278
+ function ComponentTypeEnumToJSONTyped(value, ignoreDiscriminator) {
1279
+ return value;
1280
+ }
1281
+
1282
+ // src/generated/models/ComponentConfig.ts
1283
+ function instanceOfComponentConfig(value) {
1284
+ if (!("component_type" in value) || value["component_type"] === void 0) return false;
1285
+ if (!("config" in value) || value["config"] === void 0) return false;
1286
+ return true;
1287
+ }
1288
+ function ComponentConfigFromJSON(json) {
1289
+ return ComponentConfigFromJSONTyped(json, false);
1290
+ }
1291
+ function ComponentConfigFromJSONTyped(json, ignoreDiscriminator) {
1292
+ if (json == null) {
1293
+ return json;
1294
+ }
1295
+ return {
1296
+ "component_type": ComponentTypeEnumFromJSON(json["component_type"]),
1297
+ "component_variant": json["component_variant"] == null ? void 0 : json["component_variant"],
1298
+ "config": json["config"]
1299
+ };
1300
+ }
1301
+ function ComponentConfigToJSON(json) {
1302
+ return ComponentConfigToJSONTyped(json, false);
1303
+ }
1304
+ function ComponentConfigToJSONTyped(value, ignoreDiscriminator = false) {
1305
+ if (value == null) {
1306
+ return value;
1307
+ }
1308
+ return {
1309
+ "component_type": ComponentTypeEnumToJSON(value["component_type"]),
1310
+ "component_variant": value["component_variant"],
1311
+ "config": value["config"]
1312
+ };
1313
+ }
1314
+
1315
+ // src/generated/models/CreateCardRequest.ts
1316
+ function instanceOfCreateCardRequest(value) {
1317
+ if (!("components" in value) || value["components"] === void 0) return false;
1318
+ return true;
1319
+ }
1320
+ function CreateCardRequestFromJSON(json) {
1321
+ return CreateCardRequestFromJSONTyped(json, false);
1322
+ }
1323
+ function CreateCardRequestFromJSONTyped(json, ignoreDiscriminator) {
1324
+ if (json == null) {
1325
+ return json;
1326
+ }
1327
+ return {
1328
+ "components": json["components"].map(ComponentConfigFromJSON),
1329
+ "title": json["title"] == null ? void 0 : json["title"],
1330
+ "description": json["description"] == null ? void 0 : json["description"],
1331
+ "source": json["source"] == null ? void 0 : json["source"],
1332
+ "height": json["height"] == null ? void 0 : json["height"],
1333
+ "postmessage_embed": json["postmessage_embed"] == null ? void 0 : json["postmessage_embed"],
1334
+ "normalize_currencies": json["normalize_currencies"] == null ? void 0 : json["normalize_currencies"],
1335
+ "image_ttl_minutes": json["image_ttl_minutes"] == null ? void 0 : json["image_ttl_minutes"]
1336
+ };
1337
+ }
1338
+ function CreateCardRequestToJSON(json) {
1339
+ return CreateCardRequestToJSONTyped(json, false);
1340
+ }
1341
+ function CreateCardRequestToJSONTyped(value, ignoreDiscriminator = false) {
1342
+ if (value == null) {
1343
+ return value;
1344
+ }
1345
+ return {
1346
+ "components": value["components"].map(ComponentConfigToJSON),
1347
+ "title": value["title"],
1348
+ "description": value["description"],
1349
+ "source": value["source"],
1350
+ "height": value["height"],
1351
+ "postmessage_embed": value["postmessage_embed"],
1352
+ "normalize_currencies": value["normalize_currencies"],
1353
+ "image_ttl_minutes": value["image_ttl_minutes"]
1354
+ };
1355
+ }
1356
+
1357
+ // src/generated/models/IdealVizDecision.ts
1358
+ function instanceOfIdealVizDecision(value) {
1359
+ if (!("property_path" in value) || value["property_path"] === void 0) return false;
1360
+ if (!("reason" in value) || value["reason"] === void 0) return false;
1361
+ return true;
1362
+ }
1363
+ function IdealVizDecisionFromJSON(json) {
1364
+ return IdealVizDecisionFromJSONTyped(json, false);
1365
+ }
1366
+ function IdealVizDecisionFromJSONTyped(json, ignoreDiscriminator) {
1367
+ if (json == null) {
1368
+ return json;
1369
+ }
1370
+ return {
1371
+ "property_path": json["property_path"],
1372
+ "property_path_display_name": json["property_path_display_name"] == null ? void 0 : json["property_path_display_name"],
1373
+ "reason": json["reason"]
1374
+ };
1375
+ }
1376
+ function IdealVizDecisionToJSON(json) {
1377
+ return IdealVizDecisionToJSONTyped(json, false);
1378
+ }
1379
+ function IdealVizDecisionToJSONTyped(value, ignoreDiscriminator = false) {
1380
+ if (value == null) {
1381
+ return value;
1382
+ }
1383
+ return {
1384
+ "property_path": value["property_path"],
1385
+ "property_path_display_name": value["property_path_display_name"],
1386
+ "reason": value["reason"]
1387
+ };
1388
+ }
1389
+
1390
+ // src/generated/models/KnowledgeCard.ts
1391
+ function instanceOfKnowledgeCard(value) {
1392
+ if (!("card_id" in value) || value["card_id"] === void 0) return false;
1393
+ if (!("title" in value) || value["title"] === void 0) return false;
1394
+ if (!("description" in value) || value["description"] === void 0) return false;
1395
+ if (!("webpage_url" in value) || value["webpage_url"] === void 0) return false;
1396
+ if (!("image_url" in value) || value["image_url"] === void 0) return false;
1397
+ if (!("embed_url" in value) || value["embed_url"] === void 0) return false;
1398
+ if (!("sources" in value) || value["sources"] === void 0) return false;
1399
+ if (!("methodologies" in value) || value["methodologies"] === void 0) return false;
1400
+ if (!("source_indexes" in value) || value["source_indexes"] === void 0) return false;
1401
+ if (!("card_type" in value) || value["card_type"] === void 0) return false;
1402
+ if (!("data_url" in value) || value["data_url"] === void 0) return false;
1403
+ if (!("relevance" in value) || value["relevance"] === void 0) return false;
1404
+ if (!("visualization_data" in value) || value["visualization_data"] === void 0) return false;
1405
+ return true;
1406
+ }
1407
+ function KnowledgeCardFromJSON(json) {
1408
+ return KnowledgeCardFromJSONTyped(json, false);
1409
+ }
1410
+ function KnowledgeCardFromJSONTyped(json, ignoreDiscriminator) {
1411
+ if (json == null) {
1412
+ return json;
1413
+ }
1414
+ return {
1415
+ "card_id": json["card_id"],
1416
+ "title": json["title"],
1417
+ "description": json["description"],
1418
+ "semantic_description": json["semantic_description"] == null ? void 0 : json["semantic_description"],
1419
+ "webpage_url": json["webpage_url"],
1420
+ "image_url": json["image_url"],
1421
+ "embed_url": json["embed_url"],
1422
+ "sources": json["sources"] == null ? null : json["sources"].map(KnowledgeCardSourceFromJSON),
1423
+ "methodologies": json["methodologies"] == null ? null : json["methodologies"].map(KnowledgeCardMethodologyFromJSON),
1424
+ "source_indexes": json["source_indexes"] == null ? null : json["source_indexes"].map(KnowledgeCardSourceIndexesInnerFromJSON),
1425
+ "card_type": json["card_type"],
1426
+ "data_url": json["data_url"],
1427
+ "relevance": KnowledgeCardRelevanceFromJSON(json["relevance"]),
1428
+ "visualization_data": json["visualization_data"],
1429
+ "ideal_viz_decisions": json["ideal_viz_decisions"] == null ? void 0 : json["ideal_viz_decisions"].map(IdealVizDecisionFromJSON)
1430
+ };
1431
+ }
1432
+ function KnowledgeCardToJSON(json) {
1433
+ return KnowledgeCardToJSONTyped(json, false);
1434
+ }
1435
+ function KnowledgeCardToJSONTyped(value, ignoreDiscriminator = false) {
1436
+ if (value == null) {
1437
+ return value;
1438
+ }
1439
+ return {
1440
+ "card_id": value["card_id"],
1441
+ "title": value["title"],
1442
+ "description": value["description"],
1443
+ "semantic_description": value["semantic_description"],
1444
+ "webpage_url": value["webpage_url"],
1445
+ "image_url": value["image_url"],
1446
+ "embed_url": value["embed_url"],
1447
+ "sources": value["sources"] == null ? null : value["sources"].map(KnowledgeCardSourceToJSON),
1448
+ "methodologies": value["methodologies"] == null ? null : value["methodologies"].map(KnowledgeCardMethodologyToJSON),
1449
+ "source_indexes": value["source_indexes"] == null ? null : value["source_indexes"].map(KnowledgeCardSourceIndexesInnerToJSON),
1450
+ "card_type": value["card_type"],
1451
+ "data_url": value["data_url"],
1452
+ "relevance": KnowledgeCardRelevanceToJSON(value["relevance"]),
1453
+ "visualization_data": value["visualization_data"],
1454
+ "ideal_viz_decisions": value["ideal_viz_decisions"] == null ? void 0 : value["ideal_viz_decisions"].map(IdealVizDecisionToJSON)
1455
+ };
1456
+ }
1457
+
1458
+ // src/generated/models/SearchEffortLevel.ts
1459
+ var SearchEffortLevel = {
1460
+ Fast: "fast",
1461
+ Instant: "instant",
1462
+ Deep: "deep"
1463
+ };
1464
+ function instanceOfSearchEffortLevel(value) {
1465
+ for (const key in SearchEffortLevel) {
1466
+ if (Object.prototype.hasOwnProperty.call(SearchEffortLevel, key)) {
1467
+ if (SearchEffortLevel[key] === value) {
1468
+ return true;
1469
+ }
1470
+ }
1471
+ }
1472
+ return false;
1473
+ }
1474
+ function SearchEffortLevelFromJSON(json) {
1475
+ return SearchEffortLevelFromJSONTyped(json, false);
1476
+ }
1477
+ function SearchEffortLevelFromJSONTyped(json, ignoreDiscriminator) {
1478
+ return json;
1479
+ }
1480
+ function SearchEffortLevelToJSON(value) {
1481
+ return value;
1482
+ }
1483
+ function SearchEffortLevelToJSONTyped(value, ignoreDiscriminator) {
1484
+ return value;
1485
+ }
1486
+
1487
+ // src/generated/models/OutputSettings.ts
1488
+ function instanceOfOutputSettings(value) {
1489
+ return true;
1490
+ }
1491
+ function OutputSettingsFromJSON(json) {
1492
+ return OutputSettingsFromJSONTyped(json, false);
1493
+ }
1494
+ function OutputSettingsFromJSONTyped(json, ignoreDiscriminator) {
1495
+ if (json == null) {
1496
+ return json;
1497
+ }
1498
+ return {
1499
+ "image_dark_mode": json["image_dark_mode"] == null ? void 0 : json["image_dark_mode"],
1500
+ "force_refresh": json["force_refresh"] == null ? void 0 : json["force_refresh"]
1501
+ };
1502
+ }
1503
+ function OutputSettingsToJSON(json) {
1504
+ return OutputSettingsToJSONTyped(json, false);
1505
+ }
1506
+ function OutputSettingsToJSONTyped(value, ignoreDiscriminator = false) {
1507
+ if (value == null) {
1508
+ return value;
1509
+ }
1510
+ return {
1511
+ "image_dark_mode": value["image_dark_mode"],
1512
+ "force_refresh": value["force_refresh"]
1513
+ };
1514
+ }
1515
+
1516
+ // src/generated/models/TakoSourceSettings.ts
1517
+ function instanceOfTakoSourceSettings(value) {
1518
+ return true;
1519
+ }
1520
+ function TakoSourceSettingsFromJSON(json) {
1521
+ return TakoSourceSettingsFromJSONTyped(json, false);
1522
+ }
1523
+ function TakoSourceSettingsFromJSONTyped(json, ignoreDiscriminator) {
1524
+ if (json == null) {
1525
+ return json;
1526
+ }
1527
+ return {
1528
+ "count": json["count"] == null ? void 0 : json["count"],
1529
+ "include_contents": json["include_contents"] == null ? void 0 : json["include_contents"],
1530
+ "defer_data_retrieval": json["defer_data_retrieval"] == null ? void 0 : json["defer_data_retrieval"]
1531
+ };
1532
+ }
1533
+ function TakoSourceSettingsToJSON(json) {
1534
+ return TakoSourceSettingsToJSONTyped(json, false);
1535
+ }
1536
+ function TakoSourceSettingsToJSONTyped(value, ignoreDiscriminator = false) {
1537
+ if (value == null) {
1538
+ return value;
1539
+ }
1540
+ return {
1541
+ "count": value["count"],
1542
+ "include_contents": value["include_contents"],
1543
+ "defer_data_retrieval": value["defer_data_retrieval"]
1544
+ };
1545
+ }
1546
+
1547
+ // src/generated/models/SourceSettings.ts
1548
+ function instanceOfSourceSettings(value) {
1549
+ return true;
1550
+ }
1551
+ function SourceSettingsFromJSON(json) {
1552
+ return SourceSettingsFromJSONTyped(json, false);
1553
+ }
1554
+ function SourceSettingsFromJSONTyped(json, ignoreDiscriminator) {
1555
+ if (json == null) {
1556
+ return json;
1557
+ }
1558
+ return {
1559
+ "count": json["count"] == null ? void 0 : json["count"],
1560
+ "include_contents": json["include_contents"] == null ? void 0 : json["include_contents"]
1561
+ };
1562
+ }
1563
+ function SourceSettingsToJSON(json) {
1564
+ return SourceSettingsToJSONTyped(json, false);
1565
+ }
1566
+ function SourceSettingsToJSONTyped(value, ignoreDiscriminator = false) {
1567
+ if (value == null) {
1568
+ return value;
1569
+ }
1570
+ return {
1571
+ "count": value["count"],
1572
+ "include_contents": value["include_contents"]
1573
+ };
1574
+ }
1575
+
1576
+ // src/generated/models/Sources.ts
1577
+ function instanceOfSources(value) {
1578
+ return true;
1579
+ }
1580
+ function SourcesFromJSON(json) {
1581
+ return SourcesFromJSONTyped(json, false);
1582
+ }
1583
+ function SourcesFromJSONTyped(json, ignoreDiscriminator) {
1584
+ if (json == null) {
1585
+ return json;
1586
+ }
1587
+ return {
1588
+ "data": json["data"] == null ? void 0 : TakoSourceSettingsFromJSON(json["data"]),
1589
+ "web": json["web"] == null ? void 0 : SourceSettingsFromJSON(json["web"])
1590
+ };
1591
+ }
1592
+ function SourcesToJSON(json) {
1593
+ return SourcesToJSONTyped(json, false);
1594
+ }
1595
+ function SourcesToJSONTyped(value, ignoreDiscriminator = false) {
1596
+ if (value == null) {
1597
+ return value;
1598
+ }
1599
+ return {
1600
+ "data": TakoSourceSettingsToJSON(value["data"]),
1601
+ "web": SourceSettingsToJSON(value["web"])
1602
+ };
1603
+ }
1604
+
1605
+ // src/generated/models/SearchRequest.ts
1606
+ function instanceOfSearchRequest(value) {
1607
+ if (!("query" in value) || value["query"] === void 0) return false;
1608
+ return true;
1609
+ }
1610
+ function SearchRequestFromJSON(json) {
1611
+ return SearchRequestFromJSONTyped(json, false);
1612
+ }
1613
+ function SearchRequestFromJSONTyped(json, ignoreDiscriminator) {
1614
+ if (json == null) {
1615
+ return json;
1616
+ }
1617
+ return {
1618
+ "query": json["query"],
1619
+ "effort": json["effort"] == null ? void 0 : SearchEffortLevelFromJSON(json["effort"]),
1620
+ "sources": json["sources"] == null ? void 0 : SourcesFromJSON(json["sources"]),
1621
+ "country_code": json["country_code"] == null ? void 0 : json["country_code"],
1622
+ "locale": json["locale"] == null ? void 0 : json["locale"],
1623
+ "timezone": json["timezone"] == null ? void 0 : json["timezone"],
1624
+ "output_settings": json["output_settings"] == null ? void 0 : OutputSettingsFromJSON(json["output_settings"])
1625
+ };
1626
+ }
1627
+ function SearchRequestToJSON(json) {
1628
+ return SearchRequestToJSONTyped(json, false);
1629
+ }
1630
+ function SearchRequestToJSONTyped(value, ignoreDiscriminator = false) {
1631
+ if (value == null) {
1632
+ return value;
1633
+ }
1634
+ return {
1635
+ "query": value["query"],
1636
+ "effort": SearchEffortLevelToJSON(value["effort"]),
1637
+ "sources": SourcesToJSON(value["sources"]),
1638
+ "country_code": value["country_code"],
1639
+ "locale": value["locale"],
1640
+ "timezone": value["timezone"],
1641
+ "output_settings": OutputSettingsToJSON(value["output_settings"])
1642
+ };
1643
+ }
1644
+
1645
+ // src/generated/models/SearchResponse.ts
1646
+ function instanceOfSearchResponse(value) {
1647
+ if (!("request_id" in value) || value["request_id"] === void 0) return false;
1648
+ return true;
1649
+ }
1650
+ function SearchResponseFromJSON(json) {
1651
+ return SearchResponseFromJSONTyped(json, false);
1652
+ }
1653
+ function SearchResponseFromJSONTyped(json, ignoreDiscriminator) {
1654
+ if (json == null) {
1655
+ return json;
1656
+ }
1657
+ return {
1658
+ "cards": json["cards"] == null ? void 0 : json["cards"].map(TakoCardFromJSON),
1659
+ "web_results": json["web_results"] == null ? void 0 : json["web_results"].map(WebResultFromJSON),
1660
+ "contents_total_cost": json["contents_total_cost"] == null ? void 0 : json["contents_total_cost"],
1661
+ "request_id": json["request_id"]
1662
+ };
1663
+ }
1664
+ function SearchResponseToJSON(json) {
1665
+ return SearchResponseToJSONTyped(json, false);
1666
+ }
1667
+ function SearchResponseToJSONTyped(value, ignoreDiscriminator = false) {
1668
+ if (value == null) {
1669
+ return value;
1670
+ }
1671
+ return {
1672
+ "cards": value["cards"] == null ? void 0 : value["cards"].map(TakoCardToJSON),
1673
+ "web_results": value["web_results"] == null ? void 0 : value["web_results"].map(WebResultToJSON),
1674
+ "contents_total_cost": value["contents_total_cost"],
1675
+ "request_id": value["request_id"]
1676
+ };
1677
+ }
1678
+
1679
+ // src/generated/apis/TakoApi.ts
1680
+ var TakoApi = class extends BaseAPI {
1681
+ /**
1682
+ * Creates request options for answer without sending the request
1683
+ */
1684
+ async answerRequestOpts(requestParameters) {
1685
+ const queryParameters = {};
1686
+ const headerParameters = {};
1687
+ headerParameters["Content-Type"] = "application/json";
1688
+ if (this.configuration && this.configuration.apiKey) {
1689
+ headerParameters["X-API-Key"] = await this.configuration.apiKey("X-API-Key");
1690
+ }
1691
+ let urlPath = `/v1/answer`;
1692
+ return {
1693
+ path: urlPath,
1694
+ method: "POST",
1695
+ headers: headerParameters,
1696
+ query: queryParameters,
1697
+ body: SearchRequestToJSON(requestParameters["searchRequest"])
1698
+ };
1699
+ }
1700
+ /**
1701
+ * Fast-pipeline retrieval plus an LLM-synthesized answer with confidence. Replaces the grounding endpoint.
1702
+ * Answer
1703
+ */
1704
+ async answerRaw(requestParameters, initOverrides) {
1705
+ const requestOptions = await this.answerRequestOpts(requestParameters);
1706
+ const response = await this.request(requestOptions, initOverrides);
1707
+ return new JSONApiResponse(response, (jsonValue) => AnswerResponseFromJSON(jsonValue));
1708
+ }
1709
+ /**
1710
+ * Fast-pipeline retrieval plus an LLM-synthesized answer with confidence. Replaces the grounding endpoint.
1711
+ * Answer
1712
+ */
1713
+ async answer(requestParameters = {}, initOverrides) {
1714
+ const response = await this.answerRaw(requestParameters, initOverrides);
1715
+ return await response.value();
1716
+ }
1717
+ /**
1718
+ * Creates request options for classify without sending the request
1719
+ */
1720
+ async classifyRequestOpts(requestParameters) {
1721
+ const queryParameters = {};
1722
+ const headerParameters = {};
1723
+ headerParameters["Content-Type"] = "application/json";
1724
+ if (this.configuration && this.configuration.apiKey) {
1725
+ headerParameters["X-API-Key"] = await this.configuration.apiKey("X-API-Key");
1726
+ }
1727
+ let urlPath = `/v1/classify`;
1728
+ return {
1729
+ path: urlPath,
1730
+ method: "POST",
1731
+ headers: headerParameters,
1732
+ query: queryParameters,
1733
+ body: ClassifyRequestToJSON(requestParameters["classifyRequest"])
1734
+ };
19
1735
  }
20
- };
21
- var TakoRateLimitException = class extends TakoException {
22
- constructor(message = "Rate limit exceeded", details) {
23
- super(429, message, details);
24
- this.name = "TakoRateLimitException";
1736
+ /**
1737
+ * Score a batch of queries for whether Tako search will return a result. Returns a probability and a recall-skewed keep flag per query. Free; intended for pre-filtering before /v3/search.
1738
+ * Classify queries
1739
+ */
1740
+ async classifyRaw(requestParameters, initOverrides) {
1741
+ const requestOptions = await this.classifyRequestOpts(requestParameters);
1742
+ const response = await this.request(requestOptions, initOverrides);
1743
+ return new JSONApiResponse(response, (jsonValue) => ClassifyResponseFromJSON(jsonValue));
25
1744
  }
26
- };
27
-
28
- // src/client.ts
29
- var TakoClient = class {
30
1745
  /**
31
- * Create a new Tako API client
32
- * @param config Configuration for the Tako API client
1746
+ * Score a batch of queries for whether Tako search will return a result. Returns a probability and a recall-skewed keep flag per query. Free; intended for pre-filtering before /v3/search.
1747
+ * Classify queries
33
1748
  */
34
- constructor(config) {
35
- if (!config.apiKey?.trim()) {
36
- throw new Error("API key is required");
37
- }
38
- this.apiKey = config.apiKey;
39
- this.baseUrl = config.baseUrl || "https://trytako.com";
40
- this.pathPrefix = config.pathPrefix || "/api/v1";
1749
+ async classify(requestParameters = {}, initOverrides) {
1750
+ const response = await this.classifyRaw(requestParameters, initOverrides);
1751
+ return await response.value();
41
1752
  }
42
1753
  /**
43
- * Make a request to the Tako API
44
- * @param path API endpoint path
45
- * @param method HTTP method
46
- * @param body Request body
47
- * @returns Response data
1754
+ * Creates request options for contents without sending the request
48
1755
  */
49
- async request(path, method, body) {
50
- const url = `${this.baseUrl}${this.pathPrefix}${path}`;
51
- const headers = {
52
- "X-API-Key": this.apiKey,
53
- "Content-Type": "application/json"
54
- };
55
- const options = {
56
- method,
57
- headers,
58
- body: body ? JSON.stringify(body) : void 0
59
- };
60
- const response = await fetch(url, options);
61
- if (!response.ok) {
62
- const errorData = await response.json();
63
- const message = errorData.message || response.statusText;
64
- switch (response.status) {
65
- case 401:
66
- throw new TakoUnauthorizedException(message, errorData);
67
- case 429:
68
- throw new TakoRateLimitException(message, errorData);
69
- case 404:
70
- return null;
71
- default:
72
- throw new TakoException(response.status, message, errorData);
73
- }
1756
+ async contentsRequestOpts(requestParameters) {
1757
+ const queryParameters = {};
1758
+ const headerParameters = {};
1759
+ headerParameters["Content-Type"] = "application/json";
1760
+ if (this.configuration && this.configuration.apiKey) {
1761
+ headerParameters["X-API-Key"] = await this.configuration.apiKey("X-API-Key");
74
1762
  }
75
- return await response.json();
1763
+ let urlPath = `/v1/contents`;
1764
+ return {
1765
+ path: urlPath,
1766
+ method: "POST",
1767
+ headers: headerParameters,
1768
+ query: queryParameters,
1769
+ body: ContentsRequestToJSON(requestParameters["contentsRequest"])
1770
+ };
76
1771
  }
77
1772
  /**
78
- * Search Tako Knowledge using natural language
79
- * @param text The natural language query text
80
- * @param sourceIndexes Optional array of source indexes to search within
81
- * @returns Knowledge search results
1773
+ * Download the content behind a search result: a CSV of a Tako card\'s underlying data, or the full text of a web page. Returns a short-lived presigned download URL. Protected-source cards (data export not available) return 403.
1774
+ * Download content
82
1775
  */
83
- async knowledgeSearch(text, sourceIndexes) {
84
- if (!text?.trim()) {
85
- throw new Error("Search text is required");
1776
+ async contentsRaw(requestParameters, initOverrides) {
1777
+ const requestOptions = await this.contentsRequestOpts(requestParameters);
1778
+ const response = await this.request(requestOptions, initOverrides);
1779
+ return new JSONApiResponse(response, (jsonValue) => ContentsResponseFromJSON(jsonValue));
1780
+ }
1781
+ /**
1782
+ * Download the content behind a search result: a CSV of a Tako card\'s underlying data, or the full text of a web page. Returns a short-lived presigned download URL. Protected-source cards (data export not available) return 403.
1783
+ * Download content
1784
+ */
1785
+ async contents(requestParameters = {}, initOverrides) {
1786
+ const response = await this.contentsRaw(requestParameters, initOverrides);
1787
+ return await response.value();
1788
+ }
1789
+ /**
1790
+ * Creates request options for createCard without sending the request
1791
+ */
1792
+ async createCardRequestOpts(requestParameters) {
1793
+ const queryParameters = {};
1794
+ const headerParameters = {};
1795
+ headerParameters["Content-Type"] = "application/json";
1796
+ if (this.configuration && this.configuration.apiKey) {
1797
+ headerParameters["X-API-Key"] = await this.configuration.apiKey("X-API-Key");
86
1798
  }
87
- const requestBody = {
88
- inputs: {
89
- text
90
- },
91
- ...sourceIndexes && sourceIndexes.length > 0 ? { source_indexes: sourceIndexes } : { source_indexes: ["tako" /* TAKO */] }
1799
+ let urlPath = `/v1/thin_viz/create/`;
1800
+ return {
1801
+ path: urlPath,
1802
+ method: "POST",
1803
+ headers: headerParameters,
1804
+ query: queryParameters,
1805
+ body: CreateCardRequestToJSON(requestParameters["createCardRequest"])
92
1806
  };
93
- const response = await this.request("/knowledge_search", "POST", requestBody);
94
- return response || { outputs: { knowledge_cards: [] } };
95
1807
  }
96
1808
  /**
97
- * Get an image for a knowledge card
98
- * @param cardId The ID of the knowledge card
99
- * @returns bytes of the image
1809
+ * Create a visualization card directly from component configurations. Supported component types: header, generic_timeseries, categorical_bar, stock_boxes, financial_boxes, table.
100
1810
  */
101
- async getImage(cardId) {
102
- const response = await this.request(`/image/${cardId}`, "GET");
103
- return response?.image ? Uint8Array.from(atob(response.image), (c) => c.charCodeAt(0)) : new Uint8Array();
1811
+ async createCardRaw(requestParameters, initOverrides) {
1812
+ const requestOptions = await this.createCardRequestOpts(requestParameters);
1813
+ const response = await this.request(requestOptions, initOverrides);
1814
+ return new JSONApiResponse(response, (jsonValue) => KnowledgeCardFromJSON(jsonValue));
104
1815
  }
105
1816
  /**
106
- * Beta visualize a file or a dataset (beta endpoint)
107
- * @param takoFormattedDataset Tako formatted dataset to visualize
108
- * @param fileId The ID of the file to visualize
109
- * @param query The query to visualize the dataset
110
- * @returns Knowledge search results
1817
+ * Create a visualization card directly from component configurations. Supported component types: header, generic_timeseries, categorical_bar, stock_boxes, financial_boxes, table.
111
1818
  */
112
- async betaVisualize(takoFormattedDataset, fileId, query) {
113
- if (takoFormattedDataset == null && fileId == null) {
114
- throw new Error("Either takoFormattedDataset or fileId must be provided");
115
- }
116
- if (takoFormattedDataset != null && fileId != null) {
117
- throw new Error("Only one of takoFormattedDataset or fileId must be provided");
1819
+ async createCard(requestParameters = {}, initOverrides) {
1820
+ const response = await this.createCardRaw(requestParameters, initOverrides);
1821
+ return await response.value();
1822
+ }
1823
+ /**
1824
+ * Creates request options for search without sending the request
1825
+ */
1826
+ async searchRequestOpts(requestParameters) {
1827
+ const queryParameters = {};
1828
+ const headerParameters = {};
1829
+ headerParameters["Content-Type"] = "application/json";
1830
+ if (this.configuration && this.configuration.apiKey) {
1831
+ headerParameters["X-API-Key"] = await this.configuration.apiKey("X-API-Key");
118
1832
  }
119
- const visualizeRequest = {
120
- tako_formatted_dataset: takoFormattedDataset,
121
- file_id: fileId,
122
- query
1833
+ let urlPath = `/v3/search`;
1834
+ return {
1835
+ path: urlPath,
1836
+ method: "POST",
1837
+ headers: headerParameters,
1838
+ query: queryParameters,
1839
+ body: SearchRequestToJSON(requestParameters["searchRequest"])
123
1840
  };
124
- const response = await this.request("/beta/visualize", "POST", visualizeRequest);
125
- return response || { outputs: { knowledge_cards: [] } };
126
1841
  }
127
1842
  /**
128
- * Upload a file to Tako using presigned URL (supports .csv, .xls, .xlsx, .parquet up to 5MB)
129
- * @param file The file to upload
130
- * @returns The ID of the uploaded file
1843
+ * Fast-pipeline knowledge search. Returns Tako cards (and web results when requested) with no LLM synthesis.
1844
+ * Search
131
1845
  */
132
- async betaUploadFile(file) {
133
- const maxSize = 5 * 1024 * 1024;
134
- if (file.size > maxSize) {
135
- throw new Error("File size exceeds 5MB limit");
136
- }
137
- const supportedFormats = [".csv", ".xls", ".xlsx", ".parquet"];
138
- const fileExtension = file.name.toLowerCase().substring(file.name.lastIndexOf("."));
139
- if (!supportedFormats.includes(fileExtension)) {
140
- throw new Error(`Unsupported file format. Supported formats: ${supportedFormats.join(", ")}`);
141
- }
142
- const uploadUrlResponse = await this.getFileUploadUrl(file.name);
143
- return await this.uploadFileToAws(file, uploadUrlResponse);
1846
+ async searchRaw(requestParameters, initOverrides) {
1847
+ const requestOptions = await this.searchRequestOpts(requestParameters);
1848
+ const response = await this.request(requestOptions, initOverrides);
1849
+ return new JSONApiResponse(response, (jsonValue) => SearchResponseFromJSON(jsonValue));
144
1850
  }
145
1851
  /**
146
- * Get a presigned URL for file upload (private method)
147
- * @param fileName Name of the file to upload
148
- * @returns Presigned URL response with upload details
1852
+ * Fast-pipeline knowledge search. Returns Tako cards (and web results when requested) with no LLM synthesis.
1853
+ * Search
149
1854
  */
150
- async getFileUploadUrl(fileName) {
151
- const url = `${this.baseUrl}${this.pathPrefix}/beta/file_upload_url?file_name=${encodeURIComponent(fileName)}`;
1855
+ async search(requestParameters = {}, initOverrides) {
1856
+ const response = await this.searchRaw(requestParameters, initOverrides);
1857
+ return await response.value();
1858
+ }
1859
+ };
1860
+
1861
+ // src/generated/models/APIErrorType.ts
1862
+ var APIErrorType = {
1863
+ BadRequest: "BAD_REQUEST",
1864
+ AuthenticationError: "AUTHENTICATION_ERROR",
1865
+ InternalServerError: "INTERNAL_SERVER_ERROR",
1866
+ RelevantResultsNotFound: "RELEVANT_RESULTS_NOT_FOUND",
1867
+ RateLimitExceeded: "RATE_LIMIT_EXCEEDED",
1868
+ PaymentRequired: "PAYMENT_REQUIRED",
1869
+ RequestTimeout: "REQUEST_TIMEOUT",
1870
+ Forbidden: "FORBIDDEN",
1871
+ NotFound: "NOT_FOUND"
1872
+ };
1873
+ function instanceOfAPIErrorType(value) {
1874
+ for (const key in APIErrorType) {
1875
+ if (Object.prototype.hasOwnProperty.call(APIErrorType, key)) {
1876
+ if (APIErrorType[key] === value) {
1877
+ return true;
1878
+ }
1879
+ }
1880
+ }
1881
+ return false;
1882
+ }
1883
+ function APIErrorTypeFromJSON(json) {
1884
+ return APIErrorTypeFromJSONTyped(json, false);
1885
+ }
1886
+ function APIErrorTypeFromJSONTyped(json, ignoreDiscriminator) {
1887
+ return json;
1888
+ }
1889
+ function APIErrorTypeToJSON(value) {
1890
+ return value;
1891
+ }
1892
+ function APIErrorTypeToJSONTyped(value, ignoreDiscriminator) {
1893
+ return value;
1894
+ }
1895
+
1896
+ // src/generated/models/AgentResultEvent.ts
1897
+ var AgentResultEventKindEnum = {
1898
+ AgentResult: "agent_result"
1899
+ };
1900
+ function instanceOfAgentResultEvent(value) {
1901
+ if (!("id" in value) || value["id"] === void 0) return false;
1902
+ if (!("data" in value) || value["data"] === void 0) return false;
1903
+ return true;
1904
+ }
1905
+ function AgentResultEventFromJSON(json) {
1906
+ return AgentResultEventFromJSONTyped(json, false);
1907
+ }
1908
+ function AgentResultEventFromJSONTyped(json, ignoreDiscriminator) {
1909
+ if (json == null) {
1910
+ return json;
1911
+ }
1912
+ return {
1913
+ "kind": json["kind"] == null ? void 0 : json["kind"],
1914
+ "id": json["id"],
1915
+ "data": AgentResultFromJSON(json["data"])
1916
+ };
1917
+ }
1918
+ function AgentResultEventToJSON(json) {
1919
+ return AgentResultEventToJSONTyped(json, false);
1920
+ }
1921
+ function AgentResultEventToJSONTyped(value, ignoreDiscriminator = false) {
1922
+ if (value == null) {
1923
+ return value;
1924
+ }
1925
+ return {
1926
+ "kind": value["kind"],
1927
+ "id": value["id"],
1928
+ "data": AgentResultToJSON(value["data"])
1929
+ };
1930
+ }
1931
+
1932
+ // src/generated/models/DataPipelineAnswerEvent.ts
1933
+ var DataPipelineAnswerEventKindEnum = {
1934
+ DataPipelineAnswer: "data_pipeline_answer"
1935
+ };
1936
+ function instanceOfDataPipelineAnswerEvent(value) {
1937
+ if (!("id" in value) || value["id"] === void 0) return false;
1938
+ return true;
1939
+ }
1940
+ function DataPipelineAnswerEventFromJSON(json) {
1941
+ return DataPipelineAnswerEventFromJSONTyped(json, false);
1942
+ }
1943
+ function DataPipelineAnswerEventFromJSONTyped(json, ignoreDiscriminator) {
1944
+ if (json == null) {
1945
+ return json;
1946
+ }
1947
+ return {
1948
+ "kind": json["kind"] == null ? void 0 : json["kind"],
1949
+ "id": json["id"],
1950
+ "chart_refs": json["chart_refs"] == null ? void 0 : json["chart_refs"]
1951
+ };
1952
+ }
1953
+ function DataPipelineAnswerEventToJSON(json) {
1954
+ return DataPipelineAnswerEventToJSONTyped(json, false);
1955
+ }
1956
+ function DataPipelineAnswerEventToJSONTyped(value, ignoreDiscriminator = false) {
1957
+ if (value == null) {
1958
+ return value;
1959
+ }
1960
+ return {
1961
+ "kind": value["kind"],
1962
+ "id": value["id"],
1963
+ "chart_refs": value["chart_refs"]
1964
+ };
1965
+ }
1966
+
1967
+ // src/generated/models/HeartbeatEvent.ts
1968
+ var HeartbeatEventKindEnum = {
1969
+ Heartbeat: "heartbeat"
1970
+ };
1971
+ function instanceOfHeartbeatEvent(value) {
1972
+ return true;
1973
+ }
1974
+ function HeartbeatEventFromJSON(json) {
1975
+ return HeartbeatEventFromJSONTyped(json, false);
1976
+ }
1977
+ function HeartbeatEventFromJSONTyped(json, ignoreDiscriminator) {
1978
+ if (json == null) {
1979
+ return json;
1980
+ }
1981
+ return {
1982
+ "kind": json["kind"] == null ? void 0 : json["kind"]
1983
+ };
1984
+ }
1985
+ function HeartbeatEventToJSON(json) {
1986
+ return HeartbeatEventToJSONTyped(json, false);
1987
+ }
1988
+ function HeartbeatEventToJSONTyped(value, ignoreDiscriminator = false) {
1989
+ if (value == null) {
1990
+ return value;
1991
+ }
1992
+ return {
1993
+ "kind": value["kind"]
1994
+ };
1995
+ }
1996
+
1997
+ // src/generated/models/ReasoningEvent.ts
1998
+ var ReasoningEventKindEnum = {
1999
+ Reasoning: "reasoning"
2000
+ };
2001
+ function instanceOfReasoningEvent(value) {
2002
+ if (!("id" in value) || value["id"] === void 0) return false;
2003
+ if (!("delta" in value) || value["delta"] === void 0) return false;
2004
+ return true;
2005
+ }
2006
+ function ReasoningEventFromJSON(json) {
2007
+ return ReasoningEventFromJSONTyped(json, false);
2008
+ }
2009
+ function ReasoningEventFromJSONTyped(json, ignoreDiscriminator) {
2010
+ if (json == null) {
2011
+ return json;
2012
+ }
2013
+ return {
2014
+ "kind": json["kind"] == null ? void 0 : json["kind"],
2015
+ "id": json["id"],
2016
+ "delta": json["delta"],
2017
+ "done": json["done"] == null ? void 0 : json["done"]
2018
+ };
2019
+ }
2020
+ function ReasoningEventToJSON(json) {
2021
+ return ReasoningEventToJSONTyped(json, false);
2022
+ }
2023
+ function ReasoningEventToJSONTyped(value, ignoreDiscriminator = false) {
2024
+ if (value == null) {
2025
+ return value;
2026
+ }
2027
+ return {
2028
+ "kind": value["kind"],
2029
+ "id": value["id"],
2030
+ "delta": value["delta"],
2031
+ "done": value["done"]
2032
+ };
2033
+ }
2034
+
2035
+ // src/generated/models/StatusEvent.ts
2036
+ var StatusEventKindEnum = {
2037
+ Status: "status"
2038
+ };
2039
+ function instanceOfStatusEvent(value) {
2040
+ if (!("message" in value) || value["message"] === void 0) return false;
2041
+ return true;
2042
+ }
2043
+ function StatusEventFromJSON(json) {
2044
+ return StatusEventFromJSONTyped(json, false);
2045
+ }
2046
+ function StatusEventFromJSONTyped(json, ignoreDiscriminator) {
2047
+ if (json == null) {
2048
+ return json;
2049
+ }
2050
+ return {
2051
+ "kind": json["kind"] == null ? void 0 : json["kind"],
2052
+ "message": json["message"],
2053
+ "parent_id": json["parent_id"] == null ? void 0 : json["parent_id"]
2054
+ };
2055
+ }
2056
+ function StatusEventToJSON(json) {
2057
+ return StatusEventToJSONTyped(json, false);
2058
+ }
2059
+ function StatusEventToJSONTyped(value, ignoreDiscriminator = false) {
2060
+ if (value == null) {
2061
+ return value;
2062
+ }
2063
+ return {
2064
+ "kind": value["kind"],
2065
+ "message": value["message"],
2066
+ "parent_id": value["parent_id"]
2067
+ };
2068
+ }
2069
+
2070
+ // src/generated/models/StreamDoneEvent.ts
2071
+ var StreamDoneEventKindEnum = {
2072
+ StreamDone: "stream_done"
2073
+ };
2074
+ function instanceOfStreamDoneEvent(value) {
2075
+ return true;
2076
+ }
2077
+ function StreamDoneEventFromJSON(json) {
2078
+ return StreamDoneEventFromJSONTyped(json, false);
2079
+ }
2080
+ function StreamDoneEventFromJSONTyped(json, ignoreDiscriminator) {
2081
+ if (json == null) {
2082
+ return json;
2083
+ }
2084
+ return {
2085
+ "kind": json["kind"] == null ? void 0 : json["kind"]
2086
+ };
2087
+ }
2088
+ function StreamDoneEventToJSON(json) {
2089
+ return StreamDoneEventToJSONTyped(json, false);
2090
+ }
2091
+ function StreamDoneEventToJSONTyped(value, ignoreDiscriminator = false) {
2092
+ if (value == null) {
2093
+ return value;
2094
+ }
2095
+ return {
2096
+ "kind": value["kind"]
2097
+ };
2098
+ }
2099
+
2100
+ // src/generated/models/StreamResetEvent.ts
2101
+ var StreamResetEventKindEnum = {
2102
+ StreamReset: "stream_reset"
2103
+ };
2104
+ function instanceOfStreamResetEvent(value) {
2105
+ return true;
2106
+ }
2107
+ function StreamResetEventFromJSON(json) {
2108
+ return StreamResetEventFromJSONTyped(json, false);
2109
+ }
2110
+ function StreamResetEventFromJSONTyped(json, ignoreDiscriminator) {
2111
+ if (json == null) {
2112
+ return json;
2113
+ }
2114
+ return {
2115
+ "kind": json["kind"] == null ? void 0 : json["kind"]
2116
+ };
2117
+ }
2118
+ function StreamResetEventToJSON(json) {
2119
+ return StreamResetEventToJSONTyped(json, false);
2120
+ }
2121
+ function StreamResetEventToJSONTyped(value, ignoreDiscriminator = false) {
2122
+ if (value == null) {
2123
+ return value;
2124
+ }
2125
+ return {
2126
+ "kind": value["kind"]
2127
+ };
2128
+ }
2129
+
2130
+ // src/generated/models/SubagentEvent.ts
2131
+ var SubagentEventKindEnum = {
2132
+ Subagent: "subagent"
2133
+ };
2134
+ var SubagentEventEventEnum = {
2135
+ Dispatch: "dispatch",
2136
+ Complete: "complete"
2137
+ };
2138
+ function instanceOfSubagentEvent(value) {
2139
+ if (!("agent_id" in value) || value["agent_id"] === void 0) return false;
2140
+ if (!("subagent_type" in value) || value["subagent_type"] === void 0) return false;
2141
+ if (!("event" in value) || value["event"] === void 0) return false;
2142
+ return true;
2143
+ }
2144
+ function SubagentEventFromJSON(json) {
2145
+ return SubagentEventFromJSONTyped(json, false);
2146
+ }
2147
+ function SubagentEventFromJSONTyped(json, ignoreDiscriminator) {
2148
+ if (json == null) {
2149
+ return json;
2150
+ }
2151
+ return {
2152
+ "kind": json["kind"] == null ? void 0 : json["kind"],
2153
+ "agent_id": json["agent_id"],
2154
+ "subagent_type": json["subagent_type"],
2155
+ "parent_id": json["parent_id"] == null ? void 0 : json["parent_id"],
2156
+ "event": json["event"]
2157
+ };
2158
+ }
2159
+ function SubagentEventToJSON(json) {
2160
+ return SubagentEventToJSONTyped(json, false);
2161
+ }
2162
+ function SubagentEventToJSONTyped(value, ignoreDiscriminator = false) {
2163
+ if (value == null) {
2164
+ return value;
2165
+ }
2166
+ return {
2167
+ "kind": value["kind"],
2168
+ "agent_id": value["agent_id"],
2169
+ "subagent_type": value["subagent_type"],
2170
+ "parent_id": value["parent_id"],
2171
+ "event": value["event"]
2172
+ };
2173
+ }
2174
+
2175
+ // src/generated/models/TextEvent.ts
2176
+ var TextEventKindEnum = {
2177
+ Text: "text"
2178
+ };
2179
+ function instanceOfTextEvent(value) {
2180
+ if (!("id" in value) || value["id"] === void 0) return false;
2181
+ if (!("delta" in value) || value["delta"] === void 0) return false;
2182
+ return true;
2183
+ }
2184
+ function TextEventFromJSON(json) {
2185
+ return TextEventFromJSONTyped(json, false);
2186
+ }
2187
+ function TextEventFromJSONTyped(json, ignoreDiscriminator) {
2188
+ if (json == null) {
2189
+ return json;
2190
+ }
2191
+ return {
2192
+ "kind": json["kind"] == null ? void 0 : json["kind"],
2193
+ "id": json["id"],
2194
+ "delta": json["delta"],
2195
+ "done": json["done"] == null ? void 0 : json["done"]
2196
+ };
2197
+ }
2198
+ function TextEventToJSON(json) {
2199
+ return TextEventToJSONTyped(json, false);
2200
+ }
2201
+ function TextEventToJSONTyped(value, ignoreDiscriminator = false) {
2202
+ if (value == null) {
2203
+ return value;
2204
+ }
2205
+ return {
2206
+ "kind": value["kind"],
2207
+ "id": value["id"],
2208
+ "delta": value["delta"],
2209
+ "done": value["done"]
2210
+ };
2211
+ }
2212
+
2213
+ // src/generated/models/ToolCallEvent.ts
2214
+ var ToolCallEventKindEnum = {
2215
+ ToolCall: "tool_call"
2216
+ };
2217
+ function instanceOfToolCallEvent(value) {
2218
+ if (!("id" in value) || value["id"] === void 0) return false;
2219
+ if (!("tool" in value) || value["tool"] === void 0) return false;
2220
+ return true;
2221
+ }
2222
+ function ToolCallEventFromJSON(json) {
2223
+ return ToolCallEventFromJSONTyped(json, false);
2224
+ }
2225
+ function ToolCallEventFromJSONTyped(json, ignoreDiscriminator) {
2226
+ if (json == null) {
2227
+ return json;
2228
+ }
2229
+ return {
2230
+ "kind": json["kind"] == null ? void 0 : json["kind"],
2231
+ "id": json["id"],
2232
+ "tool": json["tool"],
2233
+ "status_message": json["status_message"] == null ? void 0 : json["status_message"],
2234
+ "parent_id": json["parent_id"] == null ? void 0 : json["parent_id"],
2235
+ "done": json["done"] == null ? void 0 : json["done"]
2236
+ };
2237
+ }
2238
+ function ToolCallEventToJSON(json) {
2239
+ return ToolCallEventToJSONTyped(json, false);
2240
+ }
2241
+ function ToolCallEventToJSONTyped(value, ignoreDiscriminator = false) {
2242
+ if (value == null) {
2243
+ return value;
2244
+ }
2245
+ return {
2246
+ "kind": value["kind"],
2247
+ "id": value["id"],
2248
+ "tool": value["tool"],
2249
+ "status_message": value["status_message"],
2250
+ "parent_id": value["parent_id"],
2251
+ "done": value["done"]
2252
+ };
2253
+ }
2254
+
2255
+ // src/generated/models/ToolErrorEvent.ts
2256
+ var ToolErrorEventKindEnum = {
2257
+ ToolError: "tool_error"
2258
+ };
2259
+ function instanceOfToolErrorEvent(value) {
2260
+ if (!("id" in value) || value["id"] === void 0) return false;
2261
+ if (!("tool" in value) || value["tool"] === void 0) return false;
2262
+ if (!("error" in value) || value["error"] === void 0) return false;
2263
+ return true;
2264
+ }
2265
+ function ToolErrorEventFromJSON(json) {
2266
+ return ToolErrorEventFromJSONTyped(json, false);
2267
+ }
2268
+ function ToolErrorEventFromJSONTyped(json, ignoreDiscriminator) {
2269
+ if (json == null) {
2270
+ return json;
2271
+ }
2272
+ return {
2273
+ "kind": json["kind"] == null ? void 0 : json["kind"],
2274
+ "id": json["id"],
2275
+ "tool": json["tool"],
2276
+ "error": json["error"],
2277
+ "parent_id": json["parent_id"] == null ? void 0 : json["parent_id"]
2278
+ };
2279
+ }
2280
+ function ToolErrorEventToJSON(json) {
2281
+ return ToolErrorEventToJSONTyped(json, false);
2282
+ }
2283
+ function ToolErrorEventToJSONTyped(value, ignoreDiscriminator = false) {
2284
+ if (value == null) {
2285
+ return value;
2286
+ }
2287
+ return {
2288
+ "kind": value["kind"],
2289
+ "id": value["id"],
2290
+ "tool": value["tool"],
2291
+ "error": value["error"],
2292
+ "parent_id": value["parent_id"]
2293
+ };
2294
+ }
2295
+
2296
+ // src/generated/models/ToolResultEvent.ts
2297
+ var ToolResultEventKindEnum = {
2298
+ ToolResult: "tool_result"
2299
+ };
2300
+ function instanceOfToolResultEvent(value) {
2301
+ if (!("id" in value) || value["id"] === void 0) return false;
2302
+ if (!("tool" in value) || value["tool"] === void 0) return false;
2303
+ return true;
2304
+ }
2305
+ function ToolResultEventFromJSON(json) {
2306
+ return ToolResultEventFromJSONTyped(json, false);
2307
+ }
2308
+ function ToolResultEventFromJSONTyped(json, ignoreDiscriminator) {
2309
+ if (json == null) {
2310
+ return json;
2311
+ }
2312
+ return {
2313
+ "kind": json["kind"] == null ? void 0 : json["kind"],
2314
+ "id": json["id"],
2315
+ "tool": json["tool"],
2316
+ "elapsed_ms": json["elapsed_ms"] == null ? void 0 : json["elapsed_ms"],
2317
+ "link": json["link"] == null ? void 0 : json["link"],
2318
+ "parent_id": json["parent_id"] == null ? void 0 : json["parent_id"]
2319
+ };
2320
+ }
2321
+ function ToolResultEventToJSON(json) {
2322
+ return ToolResultEventToJSONTyped(json, false);
2323
+ }
2324
+ function ToolResultEventToJSONTyped(value, ignoreDiscriminator = false) {
2325
+ if (value == null) {
2326
+ return value;
2327
+ }
2328
+ return {
2329
+ "kind": value["kind"],
2330
+ "id": value["id"],
2331
+ "tool": value["tool"],
2332
+ "elapsed_ms": value["elapsed_ms"],
2333
+ "link": value["link"],
2334
+ "parent_id": value["parent_id"]
2335
+ };
2336
+ }
2337
+
2338
+ // src/generated/models/ToolRetryEvent.ts
2339
+ var ToolRetryEventKindEnum = {
2340
+ ToolRetry: "tool_retry"
2341
+ };
2342
+ function instanceOfToolRetryEvent(value) {
2343
+ if (!("id" in value) || value["id"] === void 0) return false;
2344
+ if (!("tool" in value) || value["tool"] === void 0) return false;
2345
+ if (!("error" in value) || value["error"] === void 0) return false;
2346
+ return true;
2347
+ }
2348
+ function ToolRetryEventFromJSON(json) {
2349
+ return ToolRetryEventFromJSONTyped(json, false);
2350
+ }
2351
+ function ToolRetryEventFromJSONTyped(json, ignoreDiscriminator) {
2352
+ if (json == null) {
2353
+ return json;
2354
+ }
2355
+ return {
2356
+ "kind": json["kind"] == null ? void 0 : json["kind"],
2357
+ "id": json["id"],
2358
+ "tool": json["tool"],
2359
+ "error": json["error"],
2360
+ "elapsed_ms": json["elapsed_ms"] == null ? void 0 : json["elapsed_ms"],
2361
+ "parent_id": json["parent_id"] == null ? void 0 : json["parent_id"]
2362
+ };
2363
+ }
2364
+ function ToolRetryEventToJSON(json) {
2365
+ return ToolRetryEventToJSONTyped(json, false);
2366
+ }
2367
+ function ToolRetryEventToJSONTyped(value, ignoreDiscriminator = false) {
2368
+ if (value == null) {
2369
+ return value;
2370
+ }
2371
+ return {
2372
+ "kind": value["kind"],
2373
+ "id": value["id"],
2374
+ "tool": value["tool"],
2375
+ "error": value["error"],
2376
+ "elapsed_ms": value["elapsed_ms"],
2377
+ "parent_id": value["parent_id"]
2378
+ };
2379
+ }
2380
+
2381
+ // src/generated/models/Block.ts
2382
+ function BlockFromJSON(json) {
2383
+ return BlockFromJSONTyped(json, false);
2384
+ }
2385
+ function BlockFromJSONTyped(json, ignoreDiscriminator) {
2386
+ if (json == null) {
2387
+ return json;
2388
+ }
2389
+ switch (json["kind"]) {
2390
+ case "agent_result":
2391
+ return Object.assign({}, AgentResultEventFromJSONTyped(json, true), { kind: "agent_result" });
2392
+ case "data_pipeline_answer":
2393
+ return Object.assign({}, DataPipelineAnswerEventFromJSONTyped(json, true), { kind: "data_pipeline_answer" });
2394
+ case "heartbeat":
2395
+ return Object.assign({}, HeartbeatEventFromJSONTyped(json, true), { kind: "heartbeat" });
2396
+ case "reasoning":
2397
+ return Object.assign({}, ReasoningEventFromJSONTyped(json, true), { kind: "reasoning" });
2398
+ case "status":
2399
+ return Object.assign({}, StatusEventFromJSONTyped(json, true), { kind: "status" });
2400
+ case "stream_done":
2401
+ return Object.assign({}, StreamDoneEventFromJSONTyped(json, true), { kind: "stream_done" });
2402
+ case "stream_reset":
2403
+ return Object.assign({}, StreamResetEventFromJSONTyped(json, true), { kind: "stream_reset" });
2404
+ case "subagent":
2405
+ return Object.assign({}, SubagentEventFromJSONTyped(json, true), { kind: "subagent" });
2406
+ case "text":
2407
+ return Object.assign({}, TextEventFromJSONTyped(json, true), { kind: "text" });
2408
+ case "tool_call":
2409
+ return Object.assign({}, ToolCallEventFromJSONTyped(json, true), { kind: "tool_call" });
2410
+ case "tool_error":
2411
+ return Object.assign({}, ToolErrorEventFromJSONTyped(json, true), { kind: "tool_error" });
2412
+ case "tool_result":
2413
+ return Object.assign({}, ToolResultEventFromJSONTyped(json, true), { kind: "tool_result" });
2414
+ case "tool_retry":
2415
+ return Object.assign({}, ToolRetryEventFromJSONTyped(json, true), { kind: "tool_retry" });
2416
+ default:
2417
+ return json;
2418
+ }
2419
+ }
2420
+ function BlockToJSON(json) {
2421
+ return BlockToJSONTyped(json, false);
2422
+ }
2423
+ function BlockToJSONTyped(value, ignoreDiscriminator = false) {
2424
+ if (value == null) {
2425
+ return value;
2426
+ }
2427
+ switch (value["kind"]) {
2428
+ case "agent_result":
2429
+ return Object.assign({}, AgentResultEventToJSON(value), { "kind": "agent_result" });
2430
+ case "data_pipeline_answer":
2431
+ return Object.assign({}, DataPipelineAnswerEventToJSON(value), { "kind": "data_pipeline_answer" });
2432
+ case "heartbeat":
2433
+ return Object.assign({}, HeartbeatEventToJSON(value), { "kind": "heartbeat" });
2434
+ case "reasoning":
2435
+ return Object.assign({}, ReasoningEventToJSON(value), { "kind": "reasoning" });
2436
+ case "status":
2437
+ return Object.assign({}, StatusEventToJSON(value), { "kind": "status" });
2438
+ case "stream_done":
2439
+ return Object.assign({}, StreamDoneEventToJSON(value), { "kind": "stream_done" });
2440
+ case "stream_reset":
2441
+ return Object.assign({}, StreamResetEventToJSON(value), { "kind": "stream_reset" });
2442
+ case "subagent":
2443
+ return Object.assign({}, SubagentEventToJSON(value), { "kind": "subagent" });
2444
+ case "text":
2445
+ return Object.assign({}, TextEventToJSON(value), { "kind": "text" });
2446
+ case "tool_call":
2447
+ return Object.assign({}, ToolCallEventToJSON(value), { "kind": "tool_call" });
2448
+ case "tool_error":
2449
+ return Object.assign({}, ToolErrorEventToJSON(value), { "kind": "tool_error" });
2450
+ case "tool_result":
2451
+ return Object.assign({}, ToolResultEventToJSON(value), { "kind": "tool_result" });
2452
+ case "tool_retry":
2453
+ return Object.assign({}, ToolRetryEventToJSON(value), { "kind": "tool_retry" });
2454
+ default:
2455
+ return value;
2456
+ }
2457
+ }
2458
+
2459
+ // src/generated/models/StreamCategory.ts
2460
+ var StreamCategory = {
2461
+ Content: "content",
2462
+ Activity: "activity",
2463
+ Control: "control"
2464
+ };
2465
+ function instanceOfStreamCategory(value) {
2466
+ for (const key in StreamCategory) {
2467
+ if (Object.prototype.hasOwnProperty.call(StreamCategory, key)) {
2468
+ if (StreamCategory[key] === value) {
2469
+ return true;
2470
+ }
2471
+ }
2472
+ }
2473
+ return false;
2474
+ }
2475
+ function StreamCategoryFromJSON(json) {
2476
+ return StreamCategoryFromJSONTyped(json, false);
2477
+ }
2478
+ function StreamCategoryFromJSONTyped(json, ignoreDiscriminator) {
2479
+ return json;
2480
+ }
2481
+ function StreamCategoryToJSON(value) {
2482
+ return value;
2483
+ }
2484
+ function StreamCategoryToJSONTyped(value, ignoreDiscriminator) {
2485
+ return value;
2486
+ }
2487
+
2488
+ // src/generated/models/AgentStreamEnvelope.ts
2489
+ function instanceOfAgentStreamEnvelope(value) {
2490
+ if (!("seq" in value) || value["seq"] === void 0) return false;
2491
+ if (!("run_id" in value) || value["run_id"] === void 0) return false;
2492
+ if (!("category" in value) || value["category"] === void 0) return false;
2493
+ if (!("block" in value) || value["block"] === void 0) return false;
2494
+ return true;
2495
+ }
2496
+ function AgentStreamEnvelopeFromJSON(json) {
2497
+ return AgentStreamEnvelopeFromJSONTyped(json, false);
2498
+ }
2499
+ function AgentStreamEnvelopeFromJSONTyped(json, ignoreDiscriminator) {
2500
+ if (json == null) {
2501
+ return json;
2502
+ }
2503
+ return {
2504
+ "seq": json["seq"],
2505
+ "run_id": json["run_id"],
2506
+ "thread_id": json["thread_id"] == null ? void 0 : json["thread_id"],
2507
+ "category": StreamCategoryFromJSON(json["category"]),
2508
+ "block": BlockFromJSON(json["block"])
2509
+ };
2510
+ }
2511
+ function AgentStreamEnvelopeToJSON(json) {
2512
+ return AgentStreamEnvelopeToJSONTyped(json, false);
2513
+ }
2514
+ function AgentStreamEnvelopeToJSONTyped(value, ignoreDiscriminator = false) {
2515
+ if (value == null) {
2516
+ return value;
2517
+ }
2518
+ return {
2519
+ "seq": value["seq"],
2520
+ "run_id": value["run_id"],
2521
+ "thread_id": value["thread_id"],
2522
+ "category": StreamCategoryToJSON(value["category"]),
2523
+ "block": BlockToJSON(value["block"])
2524
+ };
2525
+ }
2526
+
2527
+ // src/generated/models/BaseAPIError.ts
2528
+ function instanceOfBaseAPIError(value) {
2529
+ if (!("error_message" in value) || value["error_message"] === void 0) return false;
2530
+ if (!("error_type" in value) || value["error_type"] === void 0) return false;
2531
+ return true;
2532
+ }
2533
+ function BaseAPIErrorFromJSON(json) {
2534
+ return BaseAPIErrorFromJSONTyped(json, false);
2535
+ }
2536
+ function BaseAPIErrorFromJSONTyped(json, ignoreDiscriminator) {
2537
+ if (json == null) {
2538
+ return json;
2539
+ }
2540
+ return {
2541
+ "error_message": json["error_message"],
2542
+ "error_type": APIErrorTypeFromJSON(json["error_type"])
2543
+ };
2544
+ }
2545
+ function BaseAPIErrorToJSON(json) {
2546
+ return BaseAPIErrorToJSONTyped(json, false);
2547
+ }
2548
+ function BaseAPIErrorToJSONTyped(value, ignoreDiscriminator = false) {
2549
+ if (value == null) {
2550
+ return value;
2551
+ }
2552
+ return {
2553
+ "error_message": value["error_message"],
2554
+ "error_type": APIErrorTypeToJSON(value["error_type"])
2555
+ };
2556
+ }
2557
+
2558
+ // src/generated/models/CardSourceIndexSegment.ts
2559
+ function instanceOfCardSourceIndexSegment(value) {
2560
+ if (!("index_type" in value) || value["index_type"] === void 0) return false;
2561
+ if (!("segment_id" in value) || value["segment_id"] === void 0) return false;
2562
+ return true;
2563
+ }
2564
+ function CardSourceIndexSegmentFromJSON(json) {
2565
+ return CardSourceIndexSegmentFromJSONTyped(json, false);
2566
+ }
2567
+ function CardSourceIndexSegmentFromJSONTyped(json, ignoreDiscriminator) {
2568
+ if (json == null) {
2569
+ return json;
2570
+ }
2571
+ return {
2572
+ "index_type": CardSourceIndexFromJSON(json["index_type"]),
2573
+ "segment_id": json["segment_id"]
2574
+ };
2575
+ }
2576
+ function CardSourceIndexSegmentToJSON(json) {
2577
+ return CardSourceIndexSegmentToJSONTyped(json, false);
2578
+ }
2579
+ function CardSourceIndexSegmentToJSONTyped(value, ignoreDiscriminator = false) {
2580
+ if (value == null) {
2581
+ return value;
2582
+ }
2583
+ return {
2584
+ "index_type": CardSourceIndexToJSON(value["index_type"]),
2585
+ "segment_id": value["segment_id"]
2586
+ };
2587
+ }
2588
+
2589
+ // src/generated/models/CardSourcePrivateIndex.ts
2590
+ function instanceOfCardSourcePrivateIndex(value) {
2591
+ if (!("index_type" in value) || value["index_type"] === void 0) return false;
2592
+ if (!("private_index_id" in value) || value["private_index_id"] === void 0) return false;
2593
+ return true;
2594
+ }
2595
+ function CardSourcePrivateIndexFromJSON(json) {
2596
+ return CardSourcePrivateIndexFromJSONTyped(json, false);
2597
+ }
2598
+ function CardSourcePrivateIndexFromJSONTyped(json, ignoreDiscriminator) {
2599
+ if (json == null) {
2600
+ return json;
2601
+ }
2602
+ return {
2603
+ "index_type": CardSourceIndexFromJSON(json["index_type"]),
2604
+ "segment_id": json["segment_id"] == null ? void 0 : json["segment_id"],
2605
+ "private_index_id": json["private_index_id"]
2606
+ };
2607
+ }
2608
+ function CardSourcePrivateIndexToJSON(json) {
2609
+ return CardSourcePrivateIndexToJSONTyped(json, false);
2610
+ }
2611
+ function CardSourcePrivateIndexToJSONTyped(value, ignoreDiscriminator = false) {
2612
+ if (value == null) {
2613
+ return value;
2614
+ }
2615
+ return {
2616
+ "index_type": CardSourceIndexToJSON(value["index_type"]),
2617
+ "segment_id": value["segment_id"],
2618
+ "private_index_id": value["private_index_id"]
2619
+ };
2620
+ }
2621
+
2622
+ // src/generated/models/CreateCard400Response.ts
2623
+ function instanceOfCreateCard400Response(value) {
2624
+ if (!("error" in value) || value["error"] === void 0) return false;
2625
+ return true;
2626
+ }
2627
+ function CreateCard400ResponseFromJSON(json) {
2628
+ return CreateCard400ResponseFromJSONTyped(json, false);
2629
+ }
2630
+ function CreateCard400ResponseFromJSONTyped(json, ignoreDiscriminator) {
2631
+ if (json == null) {
2632
+ return json;
2633
+ }
2634
+ return {
2635
+ "error": json["error"]
2636
+ };
2637
+ }
2638
+ function CreateCard400ResponseToJSON(json) {
2639
+ return CreateCard400ResponseToJSONTyped(json, false);
2640
+ }
2641
+ function CreateCard400ResponseToJSONTyped(value, ignoreDiscriminator = false) {
2642
+ if (value == null) {
2643
+ return value;
2644
+ }
2645
+ return {
2646
+ "error": value["error"]
2647
+ };
2648
+ }
2649
+
2650
+ // src/lib/streaming.ts
2651
+ var RUNS_PATH = "/v1/agent/runs";
2652
+ var TERMINAL_KIND = "stream_done";
2653
+ function backoffMs(attempt) {
2654
+ return Math.min(500 * 2 ** (attempt - 1), 1e4);
2655
+ }
2656
+ function sleep(ms) {
2657
+ return new Promise((resolve) => setTimeout(resolve, ms));
2658
+ }
2659
+ var AgentStream = class {
2660
+ constructor(config, request, options = {}) {
2661
+ this.run_id = null;
2662
+ this.last_seq = -1;
2663
+ this.result = null;
2664
+ this.controller = null;
2665
+ this.reader = null;
2666
+ this.buffer = "";
2667
+ this.closed = false;
2668
+ this.decoder = new TextDecoder();
2669
+ this.base = config.basePath.replace(/\/+$/, "");
2670
+ this.apiKeyFn = config.apiKey;
2671
+ this.request = request;
2672
+ this.maxRetries = options.maxRetries ?? 5;
2673
+ this.readTimeoutMs = options.readTimeoutMs ?? 12e4;
2674
+ }
2675
+ async headers(extra = {}) {
152
2676
  const headers = {
153
- "X-API-Key": this.apiKey
2677
+ Accept: "text/event-stream",
2678
+ "Cache-Control": "no-store",
2679
+ ...extra
154
2680
  };
2681
+ if (this.apiKeyFn) headers["X-API-Key"] = await this.apiKeyFn("X-API-Key");
2682
+ return headers;
2683
+ }
2684
+ async open(method, url, body) {
2685
+ this.controller = new AbortController();
2686
+ const extra = body !== void 0 ? { "Content-Type": "application/json" } : {};
155
2687
  const response = await fetch(url, {
156
- method: "GET",
157
- headers
2688
+ method,
2689
+ headers: await this.headers(extra),
2690
+ body,
2691
+ signal: this.controller.signal
158
2692
  });
159
- if (!response.ok) {
160
- const errorData = await response.json();
161
- const message = errorData.message || response.statusText;
162
- switch (response.status) {
163
- case 401:
164
- throw new TakoUnauthorizedException(message, errorData);
165
- case 429:
166
- throw new TakoRateLimitException(message, errorData);
167
- default:
168
- throw new TakoException(response.status, message, errorData);
2693
+ if (!response.ok || response.body == null) {
2694
+ const detail = await response.text().catch(() => "");
2695
+ throw new ResponseError(response, `Agent stream error: ${response.status} ${detail}`);
2696
+ }
2697
+ this.reader = response.body.getReader();
2698
+ this.buffer = "";
2699
+ this.decoder = new TextDecoder();
2700
+ }
2701
+ async dispatch() {
2702
+ await this.open(
2703
+ "POST",
2704
+ `${this.base}${RUNS_PATH}`,
2705
+ JSON.stringify(AgentRunRequestToJSON(this.request))
2706
+ );
2707
+ }
2708
+ async reconnect() {
2709
+ await this.closeConnection();
2710
+ const query = this.last_seq >= 0 ? `?starting_after=${this.last_seq}` : "";
2711
+ await this.open("GET", `${this.base}${RUNS_PATH}/${this.run_id}${query}`);
2712
+ }
2713
+ async closeConnection() {
2714
+ if (this.controller) {
2715
+ this.controller.abort();
2716
+ this.controller = null;
2717
+ }
2718
+ if (this.reader) {
2719
+ try {
2720
+ await this.reader.cancel();
2721
+ } catch {
169
2722
  }
2723
+ this.reader = null;
170
2724
  }
171
- return await response.json();
172
2725
  }
173
- /**
174
- * Upload file to AWS S3 using presigned URL (private method)
175
- * @param file The file to upload
176
- * @param uploadUrlResponse The presigned URL response
177
- * @returns The file ID from the presigned URL response
178
- */
179
- async uploadFileToAws(file, uploadUrlResponse) {
180
- const formData = new FormData();
181
- Object.entries(uploadUrlResponse.fields).forEach(([key, value]) => {
182
- formData.append(key, value);
2726
+ /** Read one chunk, racing an idle-timeout abort. Returns null at end of stream. */
2727
+ async readChunk() {
2728
+ if (!this.reader) throw new Error("stream not open");
2729
+ const reader = this.reader;
2730
+ let timer;
2731
+ const timeout = new Promise((_, reject) => {
2732
+ timer = setTimeout(() => {
2733
+ this.controller?.abort();
2734
+ reject(new Error("read timeout"));
2735
+ }, this.readTimeoutMs);
183
2736
  });
184
- formData.append("file", file);
185
- const response = await fetch(uploadUrlResponse.url, {
186
- method: "POST",
187
- body: formData
2737
+ const readPromise = reader.read();
2738
+ readPromise.catch(() => {
188
2739
  });
189
- if (!response.ok) {
190
- const errorText = await response.text();
191
- throw new Error(`Failed to upload file to AWS S3: ${response.status} ${response.statusText}. ${errorText}`);
2740
+ try {
2741
+ const { value, done } = await Promise.race([readPromise, timeout]);
2742
+ return done ? null : value ?? null;
2743
+ } finally {
2744
+ if (timer) clearTimeout(timer);
192
2745
  }
193
- return uploadUrlResponse.file_id;
194
2746
  }
195
- /**
196
- * Connect a file to Tako for visualization and analysis (beta endpoint)
197
- * @param fileUrl URL of the file to connect to
198
- * @param fileId Optional ID of the file to connect to. If not provided, a new file ID will be generated
199
- * @returns Object containing 'message' and 'id' fields
200
- */
201
- async betaFileConnector(fileUrl, fileId) {
202
- if (!fileUrl?.trim()) {
203
- throw new Error("File URL is required");
2747
+ /** Pull the next complete SSE frame's data payload from the buffer, or null if none yet. */
2748
+ nextFrameData() {
2749
+ const normalized = this.buffer.replace(/\r\n/g, "\n");
2750
+ const sep = normalized.indexOf("\n\n");
2751
+ if (sep === -1) return null;
2752
+ const frame = normalized.slice(0, sep);
2753
+ this.buffer = normalized.slice(sep + 2);
2754
+ const data = frame.split("\n").filter((line) => line.startsWith("data:")).map((line) => line.slice(line.startsWith("data: ") ? 6 : 5)).join("\n");
2755
+ return data;
2756
+ }
2757
+ async *[Symbol.asyncIterator]() {
2758
+ let retries = 0;
2759
+ let started = false;
2760
+ try {
2761
+ while (true) {
2762
+ try {
2763
+ if (!started) {
2764
+ await this.dispatch();
2765
+ started = true;
2766
+ }
2767
+ while (true) {
2768
+ const chunk = await this.readChunk();
2769
+ if (chunk === null) return;
2770
+ this.buffer += this.decoder.decode(chunk, { stream: true });
2771
+ let data = this.nextFrameData();
2772
+ while (data !== null) {
2773
+ if (data.trim().length > 0) {
2774
+ const envelope = AgentStreamEnvelopeFromJSON(JSON.parse(data));
2775
+ this.run_id = envelope.run_id;
2776
+ this.last_seq = envelope.seq;
2777
+ retries = 0;
2778
+ if (envelope.block.kind === "agent_result") {
2779
+ this.result = envelope.block.data;
2780
+ }
2781
+ yield envelope;
2782
+ if (envelope.block.kind === TERMINAL_KIND) return;
2783
+ }
2784
+ data = this.nextFrameData();
2785
+ }
2786
+ }
2787
+ } catch (error) {
2788
+ if (this.closed) return;
2789
+ if (error instanceof ResponseError || error instanceof SyntaxError) throw error;
2790
+ if (this.run_id === null || retries >= this.maxRetries) throw error;
2791
+ retries += 1;
2792
+ await sleep(backoffMs(retries));
2793
+ await this.reconnect();
2794
+ }
2795
+ }
2796
+ } finally {
2797
+ if (!this.closed) await this.closeConnection();
204
2798
  }
205
- const requestBody = {
206
- file_url: fileUrl,
207
- ...fileId ? { file_id: fileId } : {}
208
- };
209
- const response = await this.request("/beta/file_connector", "POST", requestBody);
210
- return response || { message: "", id: "" };
2799
+ }
2800
+ /** Close the underlying connection. Always call this (or use try/finally). */
2801
+ async close() {
2802
+ this.closed = true;
2803
+ await this.closeConnection();
211
2804
  }
212
2805
  };
213
2806
 
214
- // src/index.ts
215
- function createTakoClient(apiKey, baseUrl) {
216
- return new TakoClient({ apiKey, baseUrl });
217
- }
2807
+ // src/lib/agent.ts
2808
+ var AgentResource = class {
2809
+ constructor(config) {
2810
+ this.config = config;
2811
+ this.api = new AgentApi(config);
2812
+ }
2813
+ /** Dispatch a new agent run (202). Returns the AgentRun handle. */
2814
+ run(request) {
2815
+ return this.api.createAgentRun({ agentRunRequest: request });
2816
+ }
2817
+ /** Poll a run's status. `startingAfter` replays events after that seq (JSON mode). */
2818
+ async get(runId, startingAfter) {
2819
+ if (!runId) {
2820
+ throw new Error(
2821
+ "run_id is required to poll a run; the stream produced no events to resume from"
2822
+ );
2823
+ }
2824
+ return this.api.getAgentRun({ runId, startingAfter });
2825
+ }
2826
+ /** Open a live SSE stream over a new agent run. */
2827
+ stream(request, options) {
2828
+ return new AgentStream(this.config, request, options);
2829
+ }
2830
+ };
2831
+
2832
+ // src/lib/facade.ts
2833
+ var Tako = class {
2834
+ constructor(options) {
2835
+ if (!options.apiKey?.trim()) {
2836
+ throw new Error("apiKey is required");
2837
+ }
2838
+ this.config = new Configuration({ apiKey: options.apiKey, basePath: options.basePath });
2839
+ this.api = new TakoApi(this.config);
2840
+ this.agent = new AgentResource(this.config);
2841
+ }
2842
+ search(request) {
2843
+ return this.api.search({ searchRequest: request });
2844
+ }
2845
+ answer(request) {
2846
+ return this.api.answer({ searchRequest: request });
2847
+ }
2848
+ contents(request) {
2849
+ return this.api.contents({ contentsRequest: request });
2850
+ }
2851
+ createCard(request) {
2852
+ return this.api.createCard({ createCardRequest: request });
2853
+ }
2854
+ };
218
2855
  export {
219
- SourceIndex,
220
- TakoException,
221
- TakoRateLimitException,
222
- TakoUnauthorizedException,
223
- createTakoClient
2856
+ APIErrorType,
2857
+ APIErrorTypeFromJSON,
2858
+ APIErrorTypeFromJSONTyped,
2859
+ APIErrorTypeToJSON,
2860
+ APIErrorTypeToJSONTyped,
2861
+ AgentApi,
2862
+ AgentEffortLevel,
2863
+ AgentEffortLevelFromJSON,
2864
+ AgentEffortLevelFromJSONTyped,
2865
+ AgentEffortLevelToJSON,
2866
+ AgentEffortLevelToJSONTyped,
2867
+ AgentOutputSettingsFromJSON,
2868
+ AgentOutputSettingsFromJSONTyped,
2869
+ AgentOutputSettingsToJSON,
2870
+ AgentOutputSettingsToJSONTyped,
2871
+ AgentResource,
2872
+ AgentResultEventFromJSON,
2873
+ AgentResultEventFromJSONTyped,
2874
+ AgentResultEventKindEnum,
2875
+ AgentResultEventToJSON,
2876
+ AgentResultEventToJSONTyped,
2877
+ AgentResultFromJSON,
2878
+ AgentResultFromJSONTyped,
2879
+ AgentResultToJSON,
2880
+ AgentResultToJSONTyped,
2881
+ AgentRunFromJSON,
2882
+ AgentRunFromJSONTyped,
2883
+ AgentRunObjectEnum,
2884
+ AgentRunRequestFromJSON,
2885
+ AgentRunRequestFromJSONTyped,
2886
+ AgentRunRequestSourceIndexesEnum,
2887
+ AgentRunRequestToJSON,
2888
+ AgentRunRequestToJSONTyped,
2889
+ AgentRunStatus,
2890
+ AgentRunStatusFromJSON,
2891
+ AgentRunStatusFromJSONTyped,
2892
+ AgentRunStatusToJSON,
2893
+ AgentRunStatusToJSONTyped,
2894
+ AgentRunToJSON,
2895
+ AgentRunToJSONTyped,
2896
+ AgentStream,
2897
+ AgentStreamEnvelopeFromJSON,
2898
+ AgentStreamEnvelopeFromJSONTyped,
2899
+ AgentStreamEnvelopeToJSON,
2900
+ AgentStreamEnvelopeToJSONTyped,
2901
+ AnswerResponseFromJSON,
2902
+ AnswerResponseFromJSONTyped,
2903
+ AnswerResponseToJSON,
2904
+ AnswerResponseToJSONTyped,
2905
+ BASE_PATH,
2906
+ BaseAPI,
2907
+ BaseAPIErrorFromJSON,
2908
+ BaseAPIErrorFromJSONTyped,
2909
+ BaseAPIErrorToJSON,
2910
+ BaseAPIErrorToJSONTyped,
2911
+ BlobApiResponse,
2912
+ BlockFromJSON,
2913
+ BlockFromJSONTyped,
2914
+ BlockToJSON,
2915
+ BlockToJSONTyped,
2916
+ COLLECTION_FORMATS,
2917
+ CardSourceIndex,
2918
+ CardSourceIndexFromJSON,
2919
+ CardSourceIndexFromJSONTyped,
2920
+ CardSourceIndexSegmentFromJSON,
2921
+ CardSourceIndexSegmentFromJSONTyped,
2922
+ CardSourceIndexSegmentToJSON,
2923
+ CardSourceIndexSegmentToJSONTyped,
2924
+ CardSourceIndexToJSON,
2925
+ CardSourceIndexToJSONTyped,
2926
+ CardSourcePrivateIndexFromJSON,
2927
+ CardSourcePrivateIndexFromJSONTyped,
2928
+ CardSourcePrivateIndexToJSON,
2929
+ CardSourcePrivateIndexToJSONTyped,
2930
+ ClassifyRequestFromJSON,
2931
+ ClassifyRequestFromJSONTyped,
2932
+ ClassifyRequestToJSON,
2933
+ ClassifyRequestToJSONTyped,
2934
+ ClassifyResponseFromJSON,
2935
+ ClassifyResponseFromJSONTyped,
2936
+ ClassifyResponseToJSON,
2937
+ ClassifyResponseToJSONTyped,
2938
+ ComponentConfigFromJSON,
2939
+ ComponentConfigFromJSONTyped,
2940
+ ComponentConfigToJSON,
2941
+ ComponentConfigToJSONTyped,
2942
+ ComponentTypeEnum,
2943
+ ComponentTypeEnumFromJSON,
2944
+ ComponentTypeEnumFromJSONTyped,
2945
+ ComponentTypeEnumToJSON,
2946
+ ComponentTypeEnumToJSONTyped,
2947
+ Configuration,
2948
+ ContentFormat,
2949
+ ContentFormatFromJSON,
2950
+ ContentFormatFromJSONTyped,
2951
+ ContentFormatToJSON,
2952
+ ContentFormatToJSONTyped,
2953
+ ContentItemFromJSON,
2954
+ ContentItemFromJSONTyped,
2955
+ ContentItemToJSON,
2956
+ ContentItemToJSONTyped,
2957
+ ContentsDeliveryMode,
2958
+ ContentsDeliveryModeFromJSON,
2959
+ ContentsDeliveryModeFromJSONTyped,
2960
+ ContentsDeliveryModeToJSON,
2961
+ ContentsDeliveryModeToJSONTyped,
2962
+ ContentsRequestFromJSON,
2963
+ ContentsRequestFromJSONTyped,
2964
+ ContentsRequestToJSON,
2965
+ ContentsRequestToJSONTyped,
2966
+ ContentsResponseFromJSON,
2967
+ ContentsResponseFromJSONTyped,
2968
+ ContentsResponseToJSON,
2969
+ ContentsResponseToJSONTyped,
2970
+ CreateCard400ResponseFromJSON,
2971
+ CreateCard400ResponseFromJSONTyped,
2972
+ CreateCard400ResponseToJSON,
2973
+ CreateCard400ResponseToJSONTyped,
2974
+ CreateCardRequestFromJSON,
2975
+ CreateCardRequestFromJSONTyped,
2976
+ CreateCardRequestToJSON,
2977
+ CreateCardRequestToJSONTyped,
2978
+ DataPipelineAnswerEventFromJSON,
2979
+ DataPipelineAnswerEventFromJSONTyped,
2980
+ DataPipelineAnswerEventKindEnum,
2981
+ DataPipelineAnswerEventToJSON,
2982
+ DataPipelineAnswerEventToJSONTyped,
2983
+ DefaultConfig,
2984
+ ErrorObjectFromJSON,
2985
+ ErrorObjectFromJSONTyped,
2986
+ ErrorObjectToJSON,
2987
+ ErrorObjectToJSONTyped,
2988
+ FetchError,
2989
+ HeartbeatEventFromJSON,
2990
+ HeartbeatEventFromJSONTyped,
2991
+ HeartbeatEventKindEnum,
2992
+ HeartbeatEventToJSON,
2993
+ HeartbeatEventToJSONTyped,
2994
+ IdealVizDecisionFromJSON,
2995
+ IdealVizDecisionFromJSONTyped,
2996
+ IdealVizDecisionToJSON,
2997
+ IdealVizDecisionToJSONTyped,
2998
+ JSONApiResponse,
2999
+ KnowledgeCardFromJSON,
3000
+ KnowledgeCardFromJSONTyped,
3001
+ KnowledgeCardMethodologyFromJSON,
3002
+ KnowledgeCardMethodologyFromJSONTyped,
3003
+ KnowledgeCardMethodologyToJSON,
3004
+ KnowledgeCardMethodologyToJSONTyped,
3005
+ KnowledgeCardRelevance,
3006
+ KnowledgeCardRelevanceFromJSON,
3007
+ KnowledgeCardRelevanceFromJSONTyped,
3008
+ KnowledgeCardRelevanceToJSON,
3009
+ KnowledgeCardRelevanceToJSONTyped,
3010
+ KnowledgeCardSourceFromJSON,
3011
+ KnowledgeCardSourceFromJSONTyped,
3012
+ KnowledgeCardSourceIndexesInnerFromJSON,
3013
+ KnowledgeCardSourceIndexesInnerFromJSONTyped,
3014
+ KnowledgeCardSourceIndexesInnerToJSON,
3015
+ KnowledgeCardSourceIndexesInnerToJSONTyped,
3016
+ KnowledgeCardSourceToJSON,
3017
+ KnowledgeCardSourceToJSONTyped,
3018
+ KnowledgeCardToJSON,
3019
+ KnowledgeCardToJSONTyped,
3020
+ OutputSettingsFromJSON,
3021
+ OutputSettingsFromJSONTyped,
3022
+ OutputSettingsToJSON,
3023
+ OutputSettingsToJSONTyped,
3024
+ QueryClassificationFromJSON,
3025
+ QueryClassificationFromJSONTyped,
3026
+ QueryClassificationToJSON,
3027
+ QueryClassificationToJSONTyped,
3028
+ ReasoningEventFromJSON,
3029
+ ReasoningEventFromJSONTyped,
3030
+ ReasoningEventKindEnum,
3031
+ ReasoningEventToJSON,
3032
+ ReasoningEventToJSONTyped,
3033
+ RequiredError,
3034
+ ResponseError,
3035
+ ResultContentFromJSON,
3036
+ ResultContentFromJSONTyped,
3037
+ ResultContentToJSON,
3038
+ ResultContentToJSONTyped,
3039
+ SearchEffortLevel,
3040
+ SearchEffortLevelFromJSON,
3041
+ SearchEffortLevelFromJSONTyped,
3042
+ SearchEffortLevelToJSON,
3043
+ SearchEffortLevelToJSONTyped,
3044
+ SearchRequestFromJSON,
3045
+ SearchRequestFromJSONTyped,
3046
+ SearchRequestToJSON,
3047
+ SearchRequestToJSONTyped,
3048
+ SearchResponseFromJSON,
3049
+ SearchResponseFromJSONTyped,
3050
+ SearchResponseToJSON,
3051
+ SearchResponseToJSONTyped,
3052
+ SourceIndexFromJSON,
3053
+ SourceIndexFromJSONTyped,
3054
+ SourceIndexToJSON,
3055
+ SourceIndexToJSONTyped,
3056
+ SourceSettingsFromJSON,
3057
+ SourceSettingsFromJSONTyped,
3058
+ SourceSettingsToJSON,
3059
+ SourceSettingsToJSONTyped,
3060
+ SourcesFromJSON,
3061
+ SourcesFromJSONTyped,
3062
+ SourcesToJSON,
3063
+ SourcesToJSONTyped,
3064
+ StatusEventFromJSON,
3065
+ StatusEventFromJSONTyped,
3066
+ StatusEventKindEnum,
3067
+ StatusEventToJSON,
3068
+ StatusEventToJSONTyped,
3069
+ StreamCategory,
3070
+ StreamCategoryFromJSON,
3071
+ StreamCategoryFromJSONTyped,
3072
+ StreamCategoryToJSON,
3073
+ StreamCategoryToJSONTyped,
3074
+ StreamDoneEventFromJSON,
3075
+ StreamDoneEventFromJSONTyped,
3076
+ StreamDoneEventKindEnum,
3077
+ StreamDoneEventToJSON,
3078
+ StreamDoneEventToJSONTyped,
3079
+ StreamResetEventFromJSON,
3080
+ StreamResetEventFromJSONTyped,
3081
+ StreamResetEventKindEnum,
3082
+ StreamResetEventToJSON,
3083
+ StreamResetEventToJSONTyped,
3084
+ SubagentEventEventEnum,
3085
+ SubagentEventFromJSON,
3086
+ SubagentEventFromJSONTyped,
3087
+ SubagentEventKindEnum,
3088
+ SubagentEventToJSON,
3089
+ SubagentEventToJSONTyped,
3090
+ Tako,
3091
+ TakoApi,
3092
+ TakoCardFromJSON,
3093
+ TakoCardFromJSONTyped,
3094
+ TakoCardToJSON,
3095
+ TakoCardToJSONTyped,
3096
+ TakoSourceSettingsFromJSON,
3097
+ TakoSourceSettingsFromJSONTyped,
3098
+ TakoSourceSettingsToJSON,
3099
+ TakoSourceSettingsToJSONTyped,
3100
+ TextApiResponse,
3101
+ TextEventFromJSON,
3102
+ TextEventFromJSONTyped,
3103
+ TextEventKindEnum,
3104
+ TextEventToJSON,
3105
+ TextEventToJSONTyped,
3106
+ ToolCallEventFromJSON,
3107
+ ToolCallEventFromJSONTyped,
3108
+ ToolCallEventKindEnum,
3109
+ ToolCallEventToJSON,
3110
+ ToolCallEventToJSONTyped,
3111
+ ToolErrorEventFromJSON,
3112
+ ToolErrorEventFromJSONTyped,
3113
+ ToolErrorEventKindEnum,
3114
+ ToolErrorEventToJSON,
3115
+ ToolErrorEventToJSONTyped,
3116
+ ToolResultEventFromJSON,
3117
+ ToolResultEventFromJSONTyped,
3118
+ ToolResultEventKindEnum,
3119
+ ToolResultEventToJSON,
3120
+ ToolResultEventToJSONTyped,
3121
+ ToolRetryEventFromJSON,
3122
+ ToolRetryEventFromJSONTyped,
3123
+ ToolRetryEventKindEnum,
3124
+ ToolRetryEventToJSON,
3125
+ ToolRetryEventToJSONTyped,
3126
+ VoidApiResponse,
3127
+ WebResultFromJSON,
3128
+ WebResultFromJSONTyped,
3129
+ WebResultToJSON,
3130
+ WebResultToJSONTyped,
3131
+ canConsumeForm,
3132
+ exists,
3133
+ instanceOfAPIErrorType,
3134
+ instanceOfAgentEffortLevel,
3135
+ instanceOfAgentOutputSettings,
3136
+ instanceOfAgentResult,
3137
+ instanceOfAgentResultEvent,
3138
+ instanceOfAgentRun,
3139
+ instanceOfAgentRunRequest,
3140
+ instanceOfAgentRunStatus,
3141
+ instanceOfAgentStreamEnvelope,
3142
+ instanceOfAnswerResponse,
3143
+ instanceOfBaseAPIError,
3144
+ instanceOfCardSourceIndex,
3145
+ instanceOfCardSourceIndexSegment,
3146
+ instanceOfCardSourcePrivateIndex,
3147
+ instanceOfClassifyRequest,
3148
+ instanceOfClassifyResponse,
3149
+ instanceOfComponentConfig,
3150
+ instanceOfComponentTypeEnum,
3151
+ instanceOfContentFormat,
3152
+ instanceOfContentItem,
3153
+ instanceOfContentsDeliveryMode,
3154
+ instanceOfContentsRequest,
3155
+ instanceOfContentsResponse,
3156
+ instanceOfCreateCard400Response,
3157
+ instanceOfCreateCardRequest,
3158
+ instanceOfDataPipelineAnswerEvent,
3159
+ instanceOfErrorObject,
3160
+ instanceOfHeartbeatEvent,
3161
+ instanceOfIdealVizDecision,
3162
+ instanceOfKnowledgeCard,
3163
+ instanceOfKnowledgeCardMethodology,
3164
+ instanceOfKnowledgeCardRelevance,
3165
+ instanceOfKnowledgeCardSource,
3166
+ instanceOfKnowledgeCardSourceIndexesInner,
3167
+ instanceOfOutputSettings,
3168
+ instanceOfQueryClassification,
3169
+ instanceOfReasoningEvent,
3170
+ instanceOfResultContent,
3171
+ instanceOfSearchEffortLevel,
3172
+ instanceOfSearchRequest,
3173
+ instanceOfSearchResponse,
3174
+ instanceOfSourceIndex,
3175
+ instanceOfSourceSettings,
3176
+ instanceOfSources,
3177
+ instanceOfStatusEvent,
3178
+ instanceOfStreamCategory,
3179
+ instanceOfStreamDoneEvent,
3180
+ instanceOfStreamResetEvent,
3181
+ instanceOfSubagentEvent,
3182
+ instanceOfTakoCard,
3183
+ instanceOfTakoSourceSettings,
3184
+ instanceOfTextEvent,
3185
+ instanceOfToolCallEvent,
3186
+ instanceOfToolErrorEvent,
3187
+ instanceOfToolResultEvent,
3188
+ instanceOfToolRetryEvent,
3189
+ instanceOfWebResult,
3190
+ mapValues,
3191
+ querystring
224
3192
  };