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