@aivue/tabular-intelligence 1.3.6 → 1.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,23 +1,23 @@
1
- import { ref as D, defineComponent as U, createElementBlock as p, openBlock as g, createElementVNode as h, createCommentVNode as q, withDirectives as ee, withKeys as L, withModifiers as H, vModelText as te, toDisplayString as k, normalizeClass as ne, createTextVNode as se, Fragment as Q, renderList as j, computed as ae } from "vue";
2
- function N(c, e) {
3
- if (c.length === 0)
1
+ import { ref as D, defineComponent as U, createElementBlock as p, openBlock as g, createElementVNode as h, createCommentVNode as q, withDirectives as ee, withKeys as L, withModifiers as H, vModelText as te, toDisplayString as k, normalizeClass as ne, createTextVNode as se, Fragment as Q, renderList as j, computed as re } from "vue";
2
+ function N(l, e) {
3
+ if (l.length === 0)
4
4
  return { columns: [], rowCount: 0, name: e };
5
- const t = c[0];
5
+ const t = l[0];
6
6
  return {
7
7
  columns: Object.keys(t).map((s) => {
8
- const a = O(c, s);
8
+ const r = O(l, s);
9
9
  return {
10
10
  name: s,
11
- type: a,
12
- nullable: c.some((o) => o[s] == null)
11
+ type: r,
12
+ nullable: l.some((o) => o[s] == null)
13
13
  };
14
14
  }),
15
- rowCount: c.length,
15
+ rowCount: l.length,
16
16
  name: e
17
17
  };
18
18
  }
19
- function O(c, e) {
20
- const t = c.map((s) => s[e]).filter((s) => s != null);
19
+ function O(l, e) {
20
+ const t = l.map((s) => s[e]).filter((s) => s != null);
21
21
  if (t.length === 0) return "string";
22
22
  if (t.every((s) => typeof s == "number" || !isNaN(Number(s))))
23
23
  return "number";
@@ -28,18 +28,18 @@ function O(c, e) {
28
28
  const n = new Set(t);
29
29
  return n.size < t.length * 0.5 && n.size < 20 ? "categorical" : "string";
30
30
  }
31
- function J(c, e, t) {
32
- const n = c.map((r) => r[e]).filter((r) => r != null), s = n.length, a = c.length - s, o = {
31
+ function J(l, e, t) {
32
+ const n = l.map((a) => a[e]).filter((a) => a != null), s = n.length, r = l.length - s, o = {
33
33
  column: e,
34
34
  count: s,
35
- nullCount: a
35
+ nullCount: r
36
36
  };
37
37
  if (t === "number") {
38
- const r = n.map(Number).filter((i) => !isNaN(i));
39
- if (r.length > 0) {
40
- const i = [...r].sort((f, d) => f - d), l = r.reduce((f, d) => f + d, 0);
41
- o.mean = l / r.length, o.median = i[Math.floor(i.length / 2)], o.min = i[0], o.max = i[i.length - 1];
42
- const w = r.reduce((f, d) => f + Math.pow(d - o.mean, 2), 0) / r.length;
38
+ const a = n.map(Number).filter((i) => !isNaN(i));
39
+ if (a.length > 0) {
40
+ const i = [...a].sort((f, d) => f - d), c = a.reduce((f, d) => f + d, 0);
41
+ o.mean = c / a.length, o.median = i[Math.floor(i.length / 2)], o.min = i[0], o.max = i[i.length - 1];
42
+ const w = a.reduce((f, d) => f + Math.pow(d - o.mean, 2), 0) / a.length;
43
43
  o.std = Math.sqrt(w), o.percentiles = {
44
44
  25: i[Math.floor(i.length * 0.25)],
45
45
  50: o.median,
@@ -48,37 +48,37 @@ function J(c, e, t) {
48
48
  };
49
49
  }
50
50
  } else {
51
- const r = new Set(n);
52
- o.uniqueValues = r.size;
51
+ const a = new Set(n);
52
+ o.uniqueValues = a.size;
53
53
  const i = {};
54
54
  n.forEach((w) => {
55
55
  const f = String(w);
56
56
  i[f] = (i[f] || 0) + 1;
57
57
  });
58
- const l = Math.max(...Object.values(i));
59
- o.mode = Object.keys(i).find((w) => i[w] === l);
58
+ const c = Math.max(...Object.values(i));
59
+ o.mode = Object.keys(i).find((w) => i[w] === c);
60
60
  }
61
61
  return o;
62
62
  }
63
- function re(c, e, t = 0.5) {
63
+ function ae(l, e, t = 0.5) {
64
64
  const n = [], s = 1.5 + (1 - t) * 1.5;
65
- return e.forEach((a) => {
66
- const o = c.map((y, A) => ({ value: Number(y[a]), idx: A })).filter((y) => !isNaN(y.value));
65
+ return e.forEach((r) => {
66
+ const o = l.map((y, A) => ({ value: Number(y[r]), idx: A })).filter((y) => !isNaN(y.value));
67
67
  if (o.length === 0) return;
68
- const r = [...o].sort((y, A) => y.value - A.value), i = r[Math.floor(r.length * 0.25)].value, l = r[Math.floor(r.length * 0.75)].value, w = l - i, f = i - s * w, d = l + s * w;
68
+ const a = [...o].sort((y, A) => y.value - A.value), i = a[Math.floor(a.length * 0.25)].value, c = a[Math.floor(a.length * 0.75)].value, w = c - i, f = i - s * w, d = c + s * w;
69
69
  o.forEach(({ value: y, idx: A }) => {
70
70
  if (y < f || y > d) {
71
- const _ = n.find((T) => T.rowIndex === A), x = y < f ? `${a}: ${y.toFixed(2)} < ${f.toFixed(2)}` : `${a}: ${y.toFixed(2)} > ${d.toFixed(2)}`;
72
- _ ? (_.reasons.push(x), _.affectedColumns.push(a), _.score = Math.min(1, _.score + 0.2)) : n.push({
71
+ const _ = n.find((T) => T.rowIndex === A), x = y < f ? `${r}: ${y.toFixed(2)} < ${f.toFixed(2)}` : `${r}: ${y.toFixed(2)} > ${d.toFixed(2)}`;
72
+ _ ? (_.reasons.push(x), _.affectedColumns.push(r), _.score = Math.min(1, _.score + 0.2)) : n.push({
73
73
  rowIndex: A,
74
- row: c[A],
74
+ row: l[A],
75
75
  score: 0.7,
76
76
  reasons: [x],
77
- affectedColumns: [a]
77
+ affectedColumns: [r]
78
78
  });
79
79
  }
80
80
  });
81
- }), n.sort((a, o) => o.score - a.score);
81
+ }), n.sort((r, o) => o.score - r.score);
82
82
  }
83
83
  class B {
84
84
  constructor(e) {
@@ -94,9 +94,12 @@ class B {
94
94
  async answerQuestion(e) {
95
95
  const t = Date.now();
96
96
  try {
97
- const { question: n, schema: s, data: a = [], sampleSize: o = 100, includeAggregates: r = !0 } = e, i = a.length > o ? this.sampleData(a, o) : a, l = r ? this.calculateAggregates(a, s) : void 0, w = this.buildPrompt(n, s, i, l, a.length), f = await this.callLLM(w);
97
+ const { question: n, schema: s, data: r, sampleSize: o = 100, includeAggregates: a = !0 } = e;
98
+ if (!r || !Array.isArray(r) || r.length === 0)
99
+ throw new Error("No data available. Please load data first.");
100
+ const i = r.length > o ? this.sampleData(r, o) : r, c = a ? this.calculateAggregates(r, s) : void 0, w = this.buildPrompt(n, s, i, c, r.length), f = await this.callLLM(w);
98
101
  return {
99
- answer: this.parseResponse(f, n, a.length > o),
102
+ answer: this.parseResponse(f, n, r.length > o),
100
103
  processingTime: Date.now() - t
101
104
  };
102
105
  } catch (n) {
@@ -117,11 +120,13 @@ class B {
117
120
  * Sample data for large datasets
118
121
  */
119
122
  sampleData(e, t) {
123
+ if (!e || !Array.isArray(e) || e.length === 0)
124
+ return [];
120
125
  if (e.length <= t)
121
126
  return e;
122
127
  const n = Math.floor(e.length / t), s = [];
123
- for (let a = 0; a < e.length && s.length < t; a += n)
124
- s.push(e[a]);
128
+ for (let r = 0; r < e.length && s.length < t; r += n)
129
+ s.push(e[r]);
125
130
  return s;
126
131
  }
127
132
  /**
@@ -129,25 +134,27 @@ class B {
129
134
  */
130
135
  calculateAggregates(e, t) {
131
136
  const n = {};
137
+ if (!e || !Array.isArray(e) || e.length === 0 || !t || !t.columns || !Array.isArray(t.columns))
138
+ return n;
132
139
  for (const s of t.columns)
133
140
  if (s.type === "number" && e.length > 0)
134
141
  try {
135
- const a = J(e, s.name, "number");
142
+ const r = J(e, s.name, "number");
136
143
  n[s.name] = {
137
- mean: a.mean,
138
- median: a.median,
139
- min: a.min,
140
- max: a.max,
141
- count: a.count
144
+ mean: r.mean,
145
+ median: r.median,
146
+ min: r.min,
147
+ max: r.max,
148
+ count: r.count
142
149
  };
143
150
  } catch {
144
151
  }
145
152
  else if (s.type === "categorical" || s.type === "string") {
146
- const a = e.map((r) => r[s.name]).filter((r) => r != null), o = new Set(a);
153
+ const r = e.map((a) => a[s.name]).filter((a) => a != null), o = new Set(r);
147
154
  n[s.name] = {
148
155
  uniqueCount: o.size,
149
- totalCount: a.length,
150
- topValues: this.getTopValues(a, 5)
156
+ totalCount: r.length,
157
+ topValues: this.getTopValues(r, 5)
151
158
  };
152
159
  }
153
160
  return n;
@@ -159,57 +166,57 @@ class B {
159
166
  const n = /* @__PURE__ */ new Map();
160
167
  for (const s of e)
161
168
  n.set(s, (n.get(s) || 0) + 1);
162
- return Array.from(n.entries()).map(([s, a]) => ({ value: s, count: a })).sort((s, a) => a.count - s.count).slice(0, t);
169
+ return Array.from(n.entries()).map(([s, r]) => ({ value: s, count: r })).sort((s, r) => r.count - s.count).slice(0, t);
163
170
  }
164
171
  /**
165
172
  * Build prompt for LLM
166
173
  */
167
- buildPrompt(e, t, n, s, a) {
168
- const o = a && a > n.length;
169
- let r = `You are a data analyst assistant. Answer the following question about a table dataset.
174
+ buildPrompt(e, t, n, s, r) {
175
+ const o = r && r > n.length;
176
+ let a = `You are a data analyst assistant. Answer the following question about a table dataset.
170
177
 
171
178
  `;
172
- r += `**Table Schema:**
173
- `, r += `Table: ${t.name}
174
- `, r += `Columns:
179
+ a += `**Table Schema:**
180
+ `, a += `Table: ${t.name}
181
+ `, a += `Columns:
175
182
  `;
176
183
  for (const i of t.columns)
177
- r += `- ${i.name} (${i.type})
184
+ a += `- ${i.name} (${i.type})
178
185
  `;
179
- return r += `
180
- `, s && Object.keys(s).length > 0 && (r += `**Summary Statistics:**
181
- `, r += JSON.stringify(s, null, 2), r += `
186
+ return a += `
187
+ `, s && Object.keys(s).length > 0 && (a += `**Summary Statistics:**
188
+ `, a += JSON.stringify(s, null, 2), a += `
182
189
 
183
- `), r += `**Sample Data** (${n.length} rows${o ? ` out of ${a} total` : ""}):
184
- `, r += JSON.stringify(n.slice(0, 10), null, 2), r += `
190
+ `), a += `**Sample Data** (${n.length} rows${o ? ` out of ${r} total` : ""}):
191
+ `, a += JSON.stringify(n.slice(0, 10), null, 2), a += `
185
192
 
186
- `, r += `**Question:** ${e}
193
+ `, a += `**Question:** ${e}
187
194
 
188
- `, r += `**Instructions:**
189
- `, r += `1. Answer ONLY based on the data provided above.
190
- `, r += `2. If the question cannot be answered from the available data, clearly state "I cannot answer this question from the available data" and explain why.
191
- `, r += `3. Provide a clear, concise answer.
192
- `, r += `4. Include specific numbers or examples from the data when relevant.
193
- `, r += `5. If the answer is based on sampled data, mention that it's an approximation.
194
- `, r += `6. Format your response as JSON with the following structure:
195
- `, r += `{
196
- `, r += ` "answer": "Your answer text here",
197
- `, r += ` "confidence": 0.0-1.0,
198
- `, r += ` "cannotAnswer": false,
199
- `, r += ` "isApproximate": ${o},
200
- `, r += ` "supportingData": { "key": "value" } // optional
201
- `, r += `}
202
- `, r;
195
+ `, a += `**Instructions:**
196
+ `, a += `1. Answer ONLY based on the data provided above.
197
+ `, a += `2. If the question cannot be answered from the available data, clearly state "I cannot answer this question from the available data" and explain why.
198
+ `, a += `3. Provide a clear, concise answer.
199
+ `, a += `4. Include specific numbers or examples from the data when relevant.
200
+ `, a += `5. If the answer is based on sampled data, mention that it's an approximation.
201
+ `, a += `6. Format your response as JSON with the following structure:
202
+ `, a += `{
203
+ `, a += ` "answer": "Your answer text here",
204
+ `, a += ` "confidence": 0.0-1.0,
205
+ `, a += ` "cannotAnswer": false,
206
+ `, a += ` "isApproximate": ${o},
207
+ `, a += ` "supportingData": { "key": "value" } // optional
208
+ `, a += `}
209
+ `, a;
203
210
  }
204
211
  /**
205
212
  * Call LLM API
206
213
  */
207
214
  async callLLM(e) {
208
- const { provider: t, apiKey: n, baseUrl: s, model: a, maxTokens: o, temperature: r } = this.config;
215
+ const { provider: t, apiKey: n, baseUrl: s, model: r, maxTokens: o, temperature: a } = this.config;
209
216
  if (t === "openai")
210
- return this.callOpenAI(e, n, a || "gpt-4-turbo-preview", o, r);
217
+ return this.callOpenAI(e, n, r || "gpt-4-turbo-preview", o, a);
211
218
  if (t === "anthropic")
212
- return this.callAnthropic(e, n, a || "claude-3-5-sonnet-20241022", o, r);
219
+ return this.callAnthropic(e, n, r || "claude-3-5-sonnet-20241022", o, a);
213
220
  if (t === "custom" && s)
214
221
  return this.callCustomAPI(e, s, n);
215
222
  throw new Error(`Unsupported provider: ${t}`);
@@ -217,8 +224,8 @@ class B {
217
224
  /**
218
225
  * Call OpenAI API
219
226
  */
220
- async callOpenAI(e, t, n, s, a) {
221
- var i, l;
227
+ async callOpenAI(e, t, n, s, r) {
228
+ var i, c;
222
229
  const o = await fetch("https://api.openai.com/v1/chat/completions", {
223
230
  method: "POST",
224
231
  headers: {
@@ -229,18 +236,18 @@ class B {
229
236
  model: n,
230
237
  messages: [{ role: "user", content: e }],
231
238
  max_tokens: s,
232
- temperature: a,
239
+ temperature: r,
233
240
  response_format: { type: "json_object" }
234
241
  })
235
242
  });
236
243
  if (!o.ok)
237
244
  throw new Error(`OpenAI API error: ${o.statusText}`);
238
- return ((l = (i = (await o.json()).choices[0]) == null ? void 0 : i.message) == null ? void 0 : l.content) || "";
245
+ return ((c = (i = (await o.json()).choices[0]) == null ? void 0 : i.message) == null ? void 0 : c.content) || "";
239
246
  }
240
247
  /**
241
248
  * Call Anthropic API
242
249
  */
243
- async callAnthropic(e, t, n, s, a) {
250
+ async callAnthropic(e, t, n, s, r) {
244
251
  var i;
245
252
  const o = await fetch("https://api.anthropic.com/v1/messages", {
246
253
  method: "POST",
@@ -252,7 +259,7 @@ class B {
252
259
  body: JSON.stringify({
253
260
  model: n,
254
261
  max_tokens: s,
255
- temperature: a,
262
+ temperature: r,
256
263
  messages: [{ role: "user", content: e }]
257
264
  })
258
265
  });
@@ -268,14 +275,14 @@ class B {
268
275
  "Content-Type": "application/json"
269
276
  };
270
277
  n && (s.Authorization = `Bearer ${n}`);
271
- const a = await fetch(t, {
278
+ const r = await fetch(t, {
272
279
  method: "POST",
273
280
  headers: s,
274
281
  body: JSON.stringify({ prompt: e })
275
282
  });
276
- if (!a.ok)
277
- throw new Error(`Custom API error: ${a.statusText}`);
278
- const o = await a.json();
283
+ if (!r.ok)
284
+ throw new Error(`Custom API error: ${r.statusText}`);
285
+ const o = await r.json();
279
286
  return o.response || o.answer || JSON.stringify(o);
280
287
  }
281
288
  /**
@@ -311,34 +318,34 @@ class B {
311
318
  return `qa_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
312
319
  }
313
320
  }
314
- function oe(c = {}) {
321
+ function oe(l = {}) {
315
322
  const {
316
323
  selector: e = "table",
317
324
  includeHeaders: t = !0,
318
325
  maxRows: n,
319
326
  inferTypes: s = !0,
320
- skipEmptyRows: a = !0
321
- } = c, o = document.querySelector(e);
327
+ skipEmptyRows: r = !0
328
+ } = l, o = document.querySelector(e);
322
329
  if (!o || o.tagName !== "TABLE")
323
330
  return console.warn(`No table found with selector: ${e}`), null;
324
331
  const i = Array.from(o.rows);
325
332
  if (i.length === 0)
326
333
  return null;
327
- let l = [], w = 0;
334
+ let c = [], w = 0;
328
335
  if (t && i[0]) {
329
336
  const A = i[0];
330
- l = Array.from(A.cells).map((_, x) => {
337
+ c = Array.from(A.cells).map((_, x) => {
331
338
  var E;
332
339
  return ((E = _.textContent) == null ? void 0 : E.trim()) || "" || `Column${x + 1}`;
333
340
  }), w = 1;
334
341
  } else {
335
342
  const A = i[0];
336
- l = Array.from(A.cells).map((_, x) => `Column${x + 1}`);
343
+ c = Array.from(A.cells).map((_, x) => `Column${x + 1}`);
337
344
  }
338
345
  const f = [], d = n ? i.slice(w, w + n) : i.slice(w);
339
346
  for (const A of d) {
340
347
  const _ = Array.from(A.cells);
341
- if (a && _.every((T) => {
348
+ if (r && _.every((T) => {
342
349
  var E;
343
350
  return !((E = T.textContent) != null && E.trim());
344
351
  }))
@@ -346,7 +353,7 @@ function oe(c = {}) {
346
353
  const x = {};
347
354
  _.forEach((T, E) => {
348
355
  var z;
349
- const F = l[E] || `Column${E + 1}`;
356
+ const F = c[E] || `Column${E + 1}`;
350
357
  let I = ((z = T.textContent) == null ? void 0 : z.trim()) || "";
351
358
  if (s && I) {
352
359
  const M = parseFloat(I);
@@ -356,43 +363,43 @@ function oe(c = {}) {
356
363
  }), f.push(x);
357
364
  }
358
365
  return {
359
- schema: s && f.length > 0 ? N(f, "Extracted Table") : ce(l, f.length),
366
+ schema: s && f.length > 0 ? N(f, "Extracted Table") : le(c, f.length),
360
367
  data: f,
361
368
  source: "dom",
362
369
  metadata: {
363
370
  selector: e,
364
371
  rowCount: f.length,
365
- columnCount: l.length,
372
+ columnCount: c.length,
366
373
  extractedAt: /* @__PURE__ */ new Date()
367
374
  }
368
375
  };
369
376
  }
370
- function ie(c, e, t = {}) {
371
- const { maxRows: n, inferTypes: s = !0 } = t, a = n ? c.slice(0, n) : c;
377
+ function ie(l, e, t = {}) {
378
+ const { maxRows: n, inferTypes: s = !0 } = t, r = n ? l.slice(0, n) : l;
372
379
  let o;
373
380
  return e && e.length > 0 ? o = {
374
381
  name: "Vue Data Grid",
375
- columns: e.map((r) => ({
376
- name: r.field,
377
- type: s && a.length > 0 ? O(a, r.field) : "string",
382
+ columns: e.map((a) => ({
383
+ name: a.field,
384
+ type: s && r.length > 0 ? O(r, a.field) : "string",
378
385
  nullable: !0
379
386
  })),
380
- rowCount: a.length
381
- } : a.length > 0 ? o = N(a, "Vue Data Grid") : o = { name: "Vue Data Grid", columns: [], rowCount: 0 }, {
387
+ rowCount: r.length
388
+ } : r.length > 0 ? o = N(r, "Vue Data Grid") : o = { name: "Vue Data Grid", columns: [], rowCount: 0 }, {
382
389
  schema: o,
383
- data: a,
390
+ data: r,
384
391
  source: "vue",
385
392
  metadata: {
386
- rowCount: a.length,
393
+ rowCount: r.length,
387
394
  columnCount: o.columns.length,
388
395
  extractedAt: /* @__PURE__ */ new Date()
389
396
  }
390
397
  };
391
398
  }
392
- function ce(c, e = 0) {
399
+ function le(l, e = 0) {
393
400
  return {
394
401
  name: "Extracted Table",
395
- columns: c.map((t) => ({
402
+ columns: l.map((t) => ({
396
403
  name: t,
397
404
  type: "string",
398
405
  nullable: !0
@@ -400,27 +407,27 @@ function ce(c, e = 0) {
400
407
  rowCount: e
401
408
  };
402
409
  }
403
- function le(c) {
410
+ function ce(l) {
404
411
  const e = {};
405
- c.variable && c.variable.forEach((a) => {
406
- e[a.key] = a.value;
412
+ l.variable && l.variable.forEach((r) => {
413
+ e[r.key] = r.value;
407
414
  });
408
- const t = c.auth ? K(c.auth) : void 0, n = [];
409
- function s(a, o = "") {
410
- a.forEach((r) => {
411
- r.item ? s(r.item, o ? `${o}/${r.name}` : r.name) : r.request && n.push(ue(r, t));
415
+ const t = l.auth ? K(l.auth) : void 0, n = [];
416
+ function s(r, o = "") {
417
+ r.forEach((a) => {
418
+ a.item ? s(a.item, o ? `${o}/${a.name}` : a.name) : a.request && n.push(ue(a, t));
412
419
  });
413
420
  }
414
- return s(c.item), {
415
- name: c.info.name,
416
- description: c.info.description,
421
+ return s(l.item), {
422
+ name: l.info.name,
423
+ description: l.info.description,
417
424
  endpoints: n,
418
425
  variables: e,
419
426
  auth: t
420
427
  };
421
428
  }
422
- function ue(c, e) {
423
- const t = c.request, n = {};
429
+ function ue(l, e) {
430
+ const t = l.request, n = {};
424
431
  t.header && t.header.forEach((o) => {
425
432
  n[o.key] = o.value;
426
433
  });
@@ -428,43 +435,43 @@ function ue(c, e) {
428
435
  t.url.query && t.url.query.forEach((o) => {
429
436
  s[o.key] = o.value;
430
437
  });
431
- const a = t.auth ? K(t.auth) : e;
438
+ const r = t.auth ? K(t.auth) : e;
432
439
  return {
433
- name: c.name,
440
+ name: l.name,
434
441
  method: t.method,
435
442
  url: t.url.raw,
436
443
  description: t.description,
437
444
  headers: n,
438
445
  queryParams: s,
439
- auth: a
446
+ auth: r
440
447
  };
441
448
  }
442
- function K(c) {
449
+ function K(l) {
443
450
  const e = {};
444
- return c.apikey ? c.apikey.forEach((t) => {
451
+ return l.apikey ? l.apikey.forEach((t) => {
445
452
  e[t.key] = t.value;
446
- }) : c.bearer ? c.bearer.forEach((t) => {
453
+ }) : l.bearer ? l.bearer.forEach((t) => {
447
454
  e[t.key] = t.value;
448
- }) : c.basic && c.basic.forEach((t) => {
455
+ }) : l.basic && l.basic.forEach((t) => {
449
456
  e[t.key] = t.value;
450
457
  }), {
451
- type: c.type,
458
+ type: l.type,
452
459
  credentials: e
453
460
  };
454
461
  }
455
- function P(c, e) {
456
- let t = c;
462
+ function P(l, e) {
463
+ let t = l;
457
464
  return Object.keys(e).forEach((n) => {
458
465
  const s = new RegExp(`{{${n}}}`, "g");
459
466
  t = t.replace(s, e[n]);
460
467
  }), t;
461
468
  }
462
- async function G(c) {
463
- const { endpoint: e, variables: t = {}, additionalHeaders: n = {}, additionalParams: s = {} } = c;
469
+ async function G(l) {
470
+ const { endpoint: e, variables: t = {}, additionalHeaders: n = {}, additionalParams: s = {} } = l;
464
471
  try {
465
- let a = P(e.url, t);
466
- const o = { ...e.queryParams, ...t, ...s }, r = Object.keys(o).filter((d) => o[d] !== void 0 && o[d] !== "").map((d) => `${encodeURIComponent(d)}=${encodeURIComponent(P(String(o[d]), t))}`).join("&");
467
- r && (a = a.includes("?") ? `${a}&${r}` : `${a}?${r}`);
472
+ let r = P(e.url, t);
473
+ const o = { ...e.queryParams, ...t, ...s }, a = Object.keys(o).filter((d) => o[d] !== void 0 && o[d] !== "").map((d) => `${encodeURIComponent(d)}=${encodeURIComponent(P(String(o[d]), t))}`).join("&");
474
+ a && (r = r.includes("?") ? `${r}&${a}` : `${r}?${a}`);
468
475
  const i = {
469
476
  "Content-Type": "application/json",
470
477
  ...e.headers,
@@ -484,42 +491,42 @@ async function G(c) {
484
491
  i.Authorization = `Basic ${A}`;
485
492
  }
486
493
  }
487
- const l = await fetch(a, {
494
+ const c = await fetch(r, {
488
495
  method: e.method,
489
496
  headers: i
490
497
  }), w = {};
491
- return l.headers.forEach((d, y) => {
498
+ return c.headers.forEach((d, y) => {
492
499
  w[y] = d;
493
- }), l.ok ? {
500
+ }), c.ok ? {
494
501
  success: !0,
495
- data: await l.json(),
496
- statusCode: l.status,
502
+ data: await c.json(),
503
+ statusCode: c.status,
497
504
  headers: w
498
505
  } : {
499
506
  success: !1,
500
- error: `HTTP ${l.status}: ${l.statusText}`,
501
- statusCode: l.status,
507
+ error: `HTTP ${c.status}: ${c.statusText}`,
508
+ statusCode: c.status,
502
509
  headers: w
503
510
  };
504
- } catch (a) {
511
+ } catch (r) {
505
512
  return {
506
513
  success: !1,
507
- error: a.message || "Unknown error occurred"
514
+ error: r.message || "Unknown error occurred"
508
515
  };
509
516
  }
510
517
  }
511
- async function Ye(c, e = {}) {
518
+ async function Ye(l, e = {}) {
512
519
  const t = [];
513
- for (const n of c) {
520
+ for (const n of l) {
514
521
  const s = await G({ endpoint: n, variables: e });
515
522
  t.push(s);
516
523
  }
517
524
  return t;
518
525
  }
519
- function de(c) {
520
- if (!c.success || !c.data)
526
+ function de(l) {
527
+ if (!l.success || !l.data)
521
528
  return [];
522
- const e = c.data;
529
+ const e = l.data;
523
530
  return Array.isArray(e) ? e : e.data && Array.isArray(e.data) ? e.data : e.results && Array.isArray(e.results) ? e.results : e.items && Array.isArray(e.items) ? e.items : typeof e == "object" ? [e] : [];
524
531
  }
525
532
  class me {
@@ -557,17 +564,17 @@ class me {
557
564
  signal: AbortSignal.timeout(this.config.timeout || 3e4)
558
565
  });
559
566
  if (!s.ok) {
560
- const r = await s.text();
561
- throw new Error(`TFM API error: ${s.status} - ${r}`);
567
+ const a = await s.text();
568
+ throw new Error(`TFM API error: ${s.status} - ${a}`);
562
569
  }
563
- const a = await s.json(), o = Date.now() - t;
570
+ const r = await s.json(), o = Date.now() - t;
564
571
  return {
565
572
  success: !0,
566
- result: a.result || a,
573
+ result: r.result || r,
567
574
  metadata: {
568
575
  processingTime: o,
569
576
  model: this.config.model || "unknown",
570
- version: a.version
577
+ version: r.version
571
578
  }
572
579
  };
573
580
  } catch (n) {
@@ -702,7 +709,7 @@ class me {
702
709
  * Load Postman collection
703
710
  */
704
711
  loadPostmanCollection(e) {
705
- return this.parsedCollection = le(e), this.parsedCollection;
712
+ return this.parsedCollection = ce(e), this.parsedCollection;
706
713
  }
707
714
  /**
708
715
  * Get loaded collection
@@ -729,11 +736,11 @@ class me {
729
736
  const s = {
730
737
  ...this.parsedCollection.variables,
731
738
  ...t
732
- }, a = await G({ endpoint: n, variables: s });
733
- if (!a.success)
734
- throw new Error(`API request failed: ${a.error}`);
735
- const o = de(a), r = N(o);
736
- return { data: o, schema: r };
739
+ }, r = await G({ endpoint: n, variables: s });
740
+ if (!r.success)
741
+ throw new Error(`API request failed: ${r.error}`);
742
+ const o = de(r), a = N(o);
743
+ return { data: o, schema: a };
737
744
  }
738
745
  /**
739
746
  * Query API data with natural language
@@ -744,16 +751,16 @@ class me {
744
751
  const t = Date.now(), { data: n, schema: s } = await this.fetchDataFromAPI(
745
752
  e.dataSource.endpoint || "",
746
753
  e.variables
747
- ), a = {
754
+ ), r = {
748
755
  question: e.question,
749
756
  schema: s,
750
757
  data: n
751
- }, o = await this.qaEngine.answerQuestion(a), r = Date.now() - t;
758
+ }, o = await this.qaEngine.answerQuestion(r), a = Date.now() - t;
752
759
  return {
753
760
  answer: o.answer,
754
761
  apiResponse: n,
755
762
  endpoint: e.dataSource.endpoint,
756
- executionTime: r
763
+ executionTime: a
757
764
  };
758
765
  }
759
766
  /**
@@ -767,19 +774,19 @@ class me {
767
774
  })) : [];
768
775
  }
769
776
  }
770
- function We(c) {
771
- const e = new me(c.config, c.qaConfig), t = D(!1), n = D(null), s = D(null), a = c.data || D([]), o = c.schema || D(null), r = D([]), i = D([]), l = D(null), w = c.maxQuestionHistory || 50, f = c.useLocalFallback !== !1;
777
+ function We(l) {
778
+ const e = new me(l.config, l.qaConfig), t = D(!1), n = D(null), s = D(null), r = l.data || D([]), o = l.schema || D(null), a = D([]), i = D([]), c = D(null), w = l.maxQuestionHistory || 50, f = l.useLocalFallback !== !1;
772
779
  async function d(u, m) {
773
780
  t.value = !0, n.value = null;
774
781
  try {
775
- if (c.config.provider === "local" || f) {
782
+ if (l.config.provider === "local" || f) {
776
783
  console.log("🔧 Using local analysis (no API call)");
777
784
  const b = y(u, m);
778
785
  return s.value = b, b;
779
786
  }
780
787
  const $ = {
781
788
  type: u,
782
- data: a.value,
789
+ data: r.value,
783
790
  schema: o.value || void 0,
784
791
  options: m
785
792
  }, C = await e.analyze($);
@@ -793,11 +800,11 @@ function We(c) {
793
800
  }
794
801
  }
795
802
  function y(u, m) {
796
- const $ = o.value || N(a.value);
803
+ const $ = o.value || N(r.value);
797
804
  switch (u) {
798
805
  case "descriptive_stats": {
799
806
  const C = $.columns.map(
800
- (b) => J(a.value, b.name, b.type)
807
+ (b) => J(r.value, b.name, b.type)
801
808
  );
802
809
  return {
803
810
  type: u,
@@ -809,8 +816,8 @@ function We(c) {
809
816
  };
810
817
  }
811
818
  case "anomaly_detection": {
812
- const C = $.columns.filter((v) => v.type === "number").map((v) => v.name), b = re(
813
- a.value,
819
+ const C = $.columns.filter((v) => v.type === "number").map((v) => v.name), b = ae(
820
+ r.value,
814
821
  C,
815
822
  m == null ? void 0 : m.sensitivity
816
823
  );
@@ -829,7 +836,7 @@ function We(c) {
829
836
  id: R,
830
837
  label: `Cluster ${R + 1}`,
831
838
  centroid: {},
832
- size: Math.floor(a.value.length / b),
839
+ size: Math.floor(r.value.length / b),
833
840
  characteristics: [`Group ${R + 1} characteristics`]
834
841
  }));
835
842
  return {
@@ -876,20 +883,20 @@ function We(c) {
876
883
  e.updateConfig(u);
877
884
  }
878
885
  function F(u, m = !0) {
879
- a.value = u, m && (o.value = N(u));
886
+ r.value = u, m && (o.value = N(u));
880
887
  }
881
888
  function I() {
882
- t.value = !1, n.value = null, s.value = null, r.value = [], i.value = [], l.value = null;
889
+ t.value = !1, n.value = null, s.value = null, a.value = [], i.value = [], c.value = null;
883
890
  }
884
891
  async function z(u, m) {
885
892
  t.value = !0, n.value = null;
886
893
  try {
887
- if (!a.value || !Array.isArray(a.value) || a.value.length === 0)
894
+ if (!r.value || !Array.isArray(r.value) || r.value.length === 0)
888
895
  throw new Error("No data available. Please load data first.");
889
- const $ = o.value || N(a.value), C = {
896
+ const $ = o.value || N(r.value), C = {
890
897
  question: u,
891
898
  schema: $,
892
- data: a.value,
899
+ data: r.value,
893
900
  sampleSize: 100,
894
901
  includeAggregates: !0,
895
902
  ...m
@@ -899,10 +906,10 @@ function We(c) {
899
906
  timestamp: /* @__PURE__ */ new Date(),
900
907
  context: {
901
908
  tableSchema: $,
902
- rowCount: a.value.length
909
+ rowCount: r.value.length
903
910
  }
904
911
  };
905
- return r.value || (r.value = []), i.value || (i.value = []), r.value.push(S), i.value.push(v), l.value = v, r.value.length > w && (r.value.shift(), i.value.shift()), v;
912
+ return a.value || (a.value = []), i.value || (i.value = []), a.value.push(S), i.value.push(v), c.value = v, a.value.length > w && (a.value.shift(), i.value.shift()), v;
906
913
  } catch ($) {
907
914
  throw n.value = $ instanceof Error ? $ : new Error("Q&A failed"), n.value;
908
915
  } finally {
@@ -912,8 +919,8 @@ function We(c) {
912
919
  async function M() {
913
920
  t.value = !0, n.value = null;
914
921
  try {
915
- const u = o.value || N(a.value);
916
- return await e.generateSummary(a.value, u);
922
+ const u = o.value || N(r.value);
923
+ return await e.generateSummary(r.value, u);
917
924
  } catch (u) {
918
925
  throw n.value = u instanceof Error ? u : new Error("Summary generation failed"), n.value;
919
926
  } finally {
@@ -921,15 +928,15 @@ function We(c) {
921
928
  }
922
929
  }
923
930
  function Y() {
924
- r.value = [], i.value = [], l.value = null;
931
+ a.value = [], i.value = [], c.value = null;
925
932
  }
926
933
  function W(u) {
927
934
  const m = e.extractFromDOM(u);
928
- return m && (a.value = m.data, o.value = m.schema), m;
935
+ return m && (r.value = m.data, o.value = m.schema), m;
929
936
  }
930
937
  function X(u, m, $) {
931
938
  const C = e.normalizeVueData(u, m, $);
932
- a.value = C.data, o.value = C.schema;
939
+ r.value = C.data, o.value = C.schema;
933
940
  }
934
941
  function Z(u) {
935
942
  e.initializeQA(u);
@@ -939,11 +946,11 @@ function We(c) {
939
946
  loading: t,
940
947
  error: n,
941
948
  lastResult: s,
942
- data: a,
949
+ data: r,
943
950
  schema: o,
944
- questionHistory: r,
951
+ questionHistory: a,
945
952
  answerHistory: i,
946
- lastAnswer: l,
953
+ lastAnswer: c,
947
954
  analyze: d,
948
955
  getDescriptiveStats: A,
949
956
  detectAnomalies: _,
@@ -978,41 +985,41 @@ const he = { class: "ti-question-input" }, fe = { class: "ti-input-wrapper" }, p
978
985
  loading: { type: Boolean, default: !1 }
979
986
  },
980
987
  emits: ["submit"],
981
- setup(c, { emit: e }) {
982
- const t = c, n = e, s = D("");
983
- function a() {
988
+ setup(l, { emit: e }) {
989
+ const t = l, n = e, s = D("");
990
+ function r() {
984
991
  s.value.trim() && !t.disabled && !t.loading && (n("submit", s.value.trim()), s.value = "");
985
992
  }
986
- function o(r) {
993
+ function o(a) {
987
994
  }
988
- return (r, i) => (g(), p("div", he, [
995
+ return (a, i) => (g(), p("div", he, [
989
996
  h("div", fe, [
990
997
  ee(h("textarea", {
991
- "onUpdate:modelValue": i[0] || (i[0] = (l) => s.value = l),
992
- placeholder: r.placeholder,
993
- disabled: r.disabled,
998
+ "onUpdate:modelValue": i[0] || (i[0] = (c) => s.value = c),
999
+ placeholder: a.placeholder,
1000
+ disabled: a.disabled,
994
1001
  class: "ti-textarea",
995
1002
  rows: "1",
996
1003
  onKeydown: [
997
- L(H(a, ["exact", "prevent"]), ["enter"]),
1004
+ L(H(r, ["exact", "prevent"]), ["enter"]),
998
1005
  L(H(o, ["shift"]), ["enter"])
999
1006
  ]
1000
1007
  }, null, 40, pe), [
1001
1008
  [te, s.value]
1002
1009
  ]),
1003
1010
  h("button", {
1004
- disabled: r.disabled || !s.value.trim(),
1011
+ disabled: a.disabled || !s.value.trim(),
1005
1012
  class: "ti-submit-btn",
1006
- onClick: a
1013
+ onClick: r
1007
1014
  }, [
1008
- r.loading ? (g(), p("span", ye, k(r.loadingLabel), 1)) : (g(), p("span", we, k(r.submitLabel), 1))
1015
+ a.loading ? (g(), p("span", ye, k(a.loadingLabel), 1)) : (g(), p("span", we, k(a.submitLabel), 1))
1009
1016
  ], 8, ge)
1010
1017
  ]),
1011
- r.showHint ? (g(), p("div", ve, k(r.hint), 1)) : q("", !0)
1018
+ a.showHint ? (g(), p("div", ve, k(a.hint), 1)) : q("", !0)
1012
1019
  ]));
1013
1020
  }
1014
- }), V = (c, e) => {
1015
- const t = c.__vccOpts || c;
1021
+ }), V = (l, e) => {
1022
+ const t = l.__vccOpts || l;
1016
1023
  for (const [n, s] of e)
1017
1024
  t[n] = s;
1018
1025
  return t;
@@ -1039,7 +1046,7 @@ const he = { class: "ti-question-input" }, fe = { class: "ti-input-wrapper" }, p
1039
1046
  props: {
1040
1047
  answer: {}
1041
1048
  },
1042
- setup(c) {
1049
+ setup(l) {
1043
1050
  const e = D(!1);
1044
1051
  function t(n) {
1045
1052
  return new Date(n).toLocaleTimeString();
@@ -1065,7 +1072,7 @@ const he = { class: "ti-question-input" }, fe = { class: "ti-input-wrapper" }, p
1065
1072
  n.answer.supportingData ? (g(), p("div", Te, [
1066
1073
  h("button", {
1067
1074
  class: "ti-toggle-btn",
1068
- onClick: s[0] || (s[0] = (a) => e.value = !e.value)
1075
+ onClick: s[0] || (s[0] = (r) => e.value = !e.value)
1069
1076
  }, k(e.value ? "▼" : "▶") + " Supporting Data ", 1),
1070
1077
  e.value ? (g(), p("div", Ie, [
1071
1078
  n.answer.supportingData.aggregates ? (g(), p("div", Pe, [
@@ -1078,12 +1085,12 @@ const he = { class: "ti-question-input" }, fe = { class: "ti-input-wrapper" }, p
1078
1085
  h("table", ze, [
1079
1086
  h("thead", null, [
1080
1087
  h("tr", null, [
1081
- (g(!0), p(Q, null, j(Object.keys(n.answer.supportingData.rows[0]), (a, o) => (g(), p("th", { key: o }, k(a), 1))), 128))
1088
+ (g(!0), p(Q, null, j(Object.keys(n.answer.supportingData.rows[0]), (r, o) => (g(), p("th", { key: o }, k(r), 1))), 128))
1082
1089
  ])
1083
1090
  ]),
1084
1091
  h("tbody", null, [
1085
- (g(!0), p(Q, null, j(n.answer.supportingData.rows.slice(0, 5), (a, o) => (g(), p("tr", { key: o }, [
1086
- (g(!0), p(Q, null, j(Object.keys(a), (r, i) => (g(), p("td", { key: i }, k(a[r]), 1))), 128))
1092
+ (g(!0), p(Q, null, j(n.answer.supportingData.rows.slice(0, 5), (r, o) => (g(), p("tr", { key: o }, [
1093
+ (g(!0), p(Q, null, j(Object.keys(r), (a, i) => (g(), p("td", { key: i }, k(r[a]), 1))), 128))
1087
1094
  ]))), 128))
1088
1095
  ])
1089
1096
  ])
@@ -1108,37 +1115,37 @@ const he = { class: "ti-question-input" }, fe = { class: "ti-input-wrapper" }, p
1108
1115
  questions: {}
1109
1116
  },
1110
1117
  emits: ["clear", "select"],
1111
- setup(c, { emit: e }) {
1112
- const t = c, n = ae(() => [...t.questions].reverse());
1113
- function s(a) {
1114
- const o = new Date(a), i = (/* @__PURE__ */ new Date()).getTime() - o.getTime(), l = Math.floor(i / 6e4), w = Math.floor(i / 36e5), f = Math.floor(i / 864e5);
1115
- return l < 1 ? "Just now" : l < 60 ? `${l}m ago` : w < 24 ? `${w}h ago` : `${f}d ago`;
1118
+ setup(l, { emit: e }) {
1119
+ const t = l, n = re(() => [...t.questions].reverse());
1120
+ function s(r) {
1121
+ const o = new Date(r), i = (/* @__PURE__ */ new Date()).getTime() - o.getTime(), c = Math.floor(i / 6e4), w = Math.floor(i / 36e5), f = Math.floor(i / 864e5);
1122
+ return c < 1 ? "Just now" : c < 60 ? `${c}m ago` : w < 24 ? `${w}h ago` : `${f}d ago`;
1116
1123
  }
1117
- return (a, o) => (g(), p("div", je, [
1124
+ return (r, o) => (g(), p("div", je, [
1118
1125
  h("div", Fe, [
1119
1126
  o[1] || (o[1] = h("h3", null, "Question History", -1)),
1120
- a.questions.length > 0 ? (g(), p("button", {
1127
+ r.questions.length > 0 ? (g(), p("button", {
1121
1128
  key: 0,
1122
1129
  class: "ti-clear-btn",
1123
- onClick: o[0] || (o[0] = (r) => a.$emit("clear"))
1130
+ onClick: o[0] || (o[0] = (a) => r.$emit("clear"))
1124
1131
  }, " Clear History ")) : q("", !0)
1125
1132
  ]),
1126
- a.questions.length === 0 ? (g(), p("div", Re, o[2] || (o[2] = [
1133
+ r.questions.length === 0 ? (g(), p("div", Re, o[2] || (o[2] = [
1127
1134
  h("div", { class: "ti-empty-icon" }, "💬", -1),
1128
1135
  h("p", null, "No questions asked yet", -1),
1129
1136
  h("p", { class: "ti-empty-hint" }, "Ask a question about your data to get started", -1)
1130
1137
  ]))) : (g(), p("div", Ue, [
1131
- (g(!0), p(Q, null, j(n.value, (r, i) => (g(), p("div", {
1132
- key: r.id,
1138
+ (g(!0), p(Q, null, j(n.value, (a, i) => (g(), p("div", {
1139
+ key: a.id,
1133
1140
  class: "ti-history-item",
1134
- onClick: (l) => a.$emit("select", r)
1141
+ onClick: (c) => r.$emit("select", a)
1135
1142
  }, [
1136
1143
  h("div", Le, [
1137
- h("span", He, "#" + k(a.questions.length - i), 1),
1138
- h("span", Be, k(s(r.timestamp)), 1)
1144
+ h("span", He, "#" + k(r.questions.length - i), 1),
1145
+ h("span", Be, k(s(a.timestamp)), 1)
1139
1146
  ]),
1140
- h("div", Oe, k(r.text), 1),
1141
- r.context ? (g(), p("div", Je, k(r.context.rowCount) + " rows ", 1)) : q("", !0)
1147
+ h("div", Oe, k(a.text), 1),
1148
+ a.context ? (g(), p("div", Je, k(a.context.rowCount) + " rows ", 1)) : q("", !0)
1142
1149
  ], 8, Ve))), 128))
1143
1150
  ]))
1144
1151
  ]));
@@ -1152,14 +1159,14 @@ export {
1152
1159
  me as TabularIntelligence,
1153
1160
  J as calculateStats,
1154
1161
  de as convertToTabular,
1155
- re as detectAnomalies,
1162
+ ae as detectAnomalies,
1156
1163
  G as executeAPIRequest,
1157
1164
  Ye as executeMultipleRequests,
1158
1165
  oe as extractFromDOM,
1159
1166
  O as inferColumnType,
1160
1167
  N as inferSchema,
1161
1168
  ie as normalizeVueData,
1162
- le as parsePostmanCollection,
1169
+ ce as parsePostmanCollection,
1163
1170
  P as replaceVariables,
1164
1171
  We as useTabularIntelligence
1165
1172
  };