@aivue/tabular-intelligence 1.3.7 → 1.3.9

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