@aivue/tabular-intelligence 1.1.0 → 1.2.0

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,306 +1,306 @@
1
- import { ref as C, defineComponent as F, createElementBlock as d, openBlock as p, createElementVNode as m, createCommentVNode as T, withDirectives as Y, withKeys as j, withModifiers as L, vModelText as W, toDisplayString as v, normalizeClass as X, createTextVNode as Z, Fragment as O, renderList as Q, computed as ee } from "vue";
2
- function I(l, n) {
3
- if (l.length === 0)
4
- return { columns: [], rowCount: 0, name: n };
5
- const a = l[0];
1
+ import { ref as E, defineComponent as z, createElementBlock as h, openBlock as f, createElementVNode as m, createCommentVNode as S, withDirectives as Z, withKeys as V, withModifiers as R, vModelText as ee, toDisplayString as A, normalizeClass as te, createTextVNode as ne, Fragment as O, renderList as Q, computed as se } from "vue";
2
+ function N(c, e) {
3
+ if (c.length === 0)
4
+ return { columns: [], rowCount: 0, name: e };
5
+ const t = c[0];
6
6
  return {
7
- columns: Object.keys(a).map((t) => {
8
- const s = B(l, t);
7
+ columns: Object.keys(t).map((s) => {
8
+ const a = L(c, s);
9
9
  return {
10
- name: t,
11
- type: s,
12
- nullable: l.some((r) => r[t] == null)
10
+ name: s,
11
+ type: a,
12
+ nullable: c.some((o) => o[s] == null)
13
13
  };
14
14
  }),
15
- rowCount: l.length,
16
- name: n
15
+ rowCount: c.length,
16
+ name: e
17
17
  };
18
18
  }
19
- function B(l, n) {
20
- const a = l.map((t) => t[n]).filter((t) => t != null);
21
- if (a.length === 0) return "string";
22
- if (a.every((t) => typeof t == "number" || !isNaN(Number(t))))
19
+ function L(c, e) {
20
+ const t = c.map((s) => s[e]).filter((s) => s != null);
21
+ if (t.length === 0) return "string";
22
+ if (t.every((s) => typeof s == "number" || !isNaN(Number(s))))
23
23
  return "number";
24
- if (a.every((t) => typeof t == "boolean" || t === "true" || t === "false"))
24
+ if (t.every((s) => typeof s == "boolean" || s === "true" || s === "false"))
25
25
  return "boolean";
26
- if (a.every((t) => !isNaN(Date.parse(t))))
26
+ if (t.every((s) => !isNaN(Date.parse(s))))
27
27
  return "date";
28
- const e = new Set(a);
29
- return e.size < a.length * 0.5 && e.size < 20 ? "categorical" : "string";
28
+ const n = new Set(t);
29
+ return n.size < t.length * 0.5 && n.size < 20 ? "categorical" : "string";
30
30
  }
31
- function H(l, n, a) {
32
- const e = l.map((o) => o[n]).filter((o) => o != null), t = e.length, s = l.length - t, r = {
33
- column: n,
34
- count: t,
35
- nullCount: s
31
+ function B(c, e, t) {
32
+ const n = c.map((r) => r[e]).filter((r) => r != null), s = n.length, a = c.length - s, o = {
33
+ column: e,
34
+ count: s,
35
+ nullCount: a
36
36
  };
37
- if (a === "number") {
38
- const o = e.map(Number).filter((i) => !isNaN(i));
39
- if (o.length > 0) {
40
- const i = [...o].sort((h, w) => h - w), u = o.reduce((h, w) => h + w, 0);
41
- r.mean = u / o.length, r.median = i[Math.floor(i.length / 2)], r.min = i[0], r.max = i[i.length - 1];
42
- const g = o.reduce((h, w) => h + Math.pow(w - r.mean, 2), 0) / o.length;
43
- r.std = Math.sqrt(g), r.percentiles = {
37
+ if (t === "number") {
38
+ const r = n.map(Number).filter((i) => !isNaN(i));
39
+ if (r.length > 0) {
40
+ const i = [...r].sort((p, d) => p - d), l = r.reduce((p, d) => p + 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 g = r.reduce((p, d) => p + Math.pow(d - o.mean, 2), 0) / r.length;
43
+ o.std = Math.sqrt(g), o.percentiles = {
44
44
  25: i[Math.floor(i.length * 0.25)],
45
- 50: r.median,
45
+ 50: o.median,
46
46
  75: i[Math.floor(i.length * 0.75)],
47
47
  90: i[Math.floor(i.length * 0.9)]
48
48
  };
49
49
  }
50
50
  } else {
51
- const o = new Set(e);
52
- r.uniqueValues = o.size;
51
+ const r = new Set(n);
52
+ o.uniqueValues = r.size;
53
53
  const i = {};
54
- e.forEach((g) => {
55
- const h = String(g);
56
- i[h] = (i[h] || 0) + 1;
54
+ n.forEach((g) => {
55
+ const p = String(g);
56
+ i[p] = (i[p] || 0) + 1;
57
57
  });
58
- const u = Math.max(...Object.values(i));
59
- r.mode = Object.keys(i).find((g) => i[g] === u);
58
+ const l = Math.max(...Object.values(i));
59
+ o.mode = Object.keys(i).find((g) => i[g] === l);
60
60
  }
61
- return r;
61
+ return o;
62
62
  }
63
- function te(l, n, a = 0.5) {
64
- const e = [], t = 1.5 + (1 - a) * 1.5;
65
- return n.forEach((s) => {
66
- const r = l.map((A, b) => ({ value: Number(A[s]), idx: b })).filter((A) => !isNaN(A.value));
67
- if (r.length === 0) return;
68
- const o = [...r].sort((A, b) => A.value - b.value), i = o[Math.floor(o.length * 0.25)].value, u = o[Math.floor(o.length * 0.75)].value, g = u - i, h = i - t * g, w = u + t * g;
69
- r.forEach(({ value: A, idx: b }) => {
70
- if (A < h || A > w) {
71
- const _ = e.find((x) => x.rowIndex === b), k = A < h ? `${s}: ${A.toFixed(2)} < ${h.toFixed(2)}` : `${s}: ${A.toFixed(2)} > ${w.toFixed(2)}`;
72
- _ ? (_.reasons.push(k), _.affectedColumns.push(s), _.score = Math.min(1, _.score + 0.2)) : e.push({
73
- rowIndex: b,
74
- row: l[b],
63
+ function ae(c, e, t = 0.5) {
64
+ const n = [], s = 1.5 + (1 - t) * 1.5;
65
+ return e.forEach((a) => {
66
+ const o = c.map((y, v) => ({ value: Number(y[a]), idx: v })).filter((y) => !isNaN(y.value));
67
+ if (o.length === 0) return;
68
+ const r = [...o].sort((y, v) => y.value - v.value), i = r[Math.floor(r.length * 0.25)].value, l = r[Math.floor(r.length * 0.75)].value, g = l - i, p = i - s * g, d = l + s * g;
69
+ o.forEach(({ value: y, idx: v }) => {
70
+ if (y < p || y > d) {
71
+ const $ = n.find((D) => D.rowIndex === v), C = y < p ? `${a}: ${y.toFixed(2)} < ${p.toFixed(2)}` : `${a}: ${y.toFixed(2)} > ${d.toFixed(2)}`;
72
+ $ ? ($.reasons.push(C), $.affectedColumns.push(a), $.score = Math.min(1, $.score + 0.2)) : n.push({
73
+ rowIndex: v,
74
+ row: c[v],
75
75
  score: 0.7,
76
- reasons: [k],
77
- affectedColumns: [s]
76
+ reasons: [C],
77
+ affectedColumns: [a]
78
78
  });
79
79
  }
80
80
  });
81
- }), e.sort((s, r) => r.score - s.score);
81
+ }), n.sort((a, o) => o.score - a.score);
82
82
  }
83
- class P {
84
- constructor(n) {
83
+ class H {
84
+ constructor(e) {
85
85
  this.config = {
86
86
  maxTokens: 1e3,
87
87
  temperature: 0.3,
88
- ...n
88
+ ...e
89
89
  };
90
90
  }
91
91
  /**
92
92
  * Answer a question about the table data
93
93
  */
94
- async answerQuestion(n) {
95
- const a = Date.now();
94
+ async answerQuestion(e) {
95
+ const t = Date.now();
96
96
  try {
97
- const { question: e, schema: t, data: s = [], sampleSize: r = 100, includeAggregates: o = !0 } = n, i = s.length > r ? this.sampleData(s, r) : s, u = o ? this.calculateAggregates(s, t) : void 0, g = this.buildPrompt(e, t, i, u, s.length), h = await this.callLLM(g);
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, g = this.buildPrompt(n, s, i, l, a.length), p = await this.callLLM(g);
98
98
  return {
99
- answer: this.parseResponse(h, e, s.length > r),
100
- processingTime: Date.now() - a
99
+ answer: this.parseResponse(p, n, a.length > o),
100
+ processingTime: Date.now() - t
101
101
  };
102
- } catch (e) {
103
- return console.error("Q&A error:", e), {
102
+ } catch (n) {
103
+ return console.error("Q&A error:", n), {
104
104
  answer: {
105
105
  questionId: this.generateId(),
106
106
  text: "I encountered an error while processing your question. Please try again.",
107
107
  timestamp: /* @__PURE__ */ new Date(),
108
108
  confidence: 0,
109
109
  cannotAnswer: !0,
110
- reason: e instanceof Error ? e.message : "Unknown error"
110
+ reason: n instanceof Error ? n.message : "Unknown error"
111
111
  },
112
- processingTime: Date.now() - a
112
+ processingTime: Date.now() - t
113
113
  };
114
114
  }
115
115
  }
116
116
  /**
117
117
  * Sample data for large datasets
118
118
  */
119
- sampleData(n, a) {
120
- if (n.length <= a)
121
- return n;
122
- const e = Math.floor(n.length / a), t = [];
123
- for (let s = 0; s < n.length && t.length < a; s += e)
124
- t.push(n[s]);
125
- return t;
119
+ sampleData(e, t) {
120
+ if (e.length <= t)
121
+ return e;
122
+ 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]);
125
+ return s;
126
126
  }
127
127
  /**
128
128
  * Calculate aggregates for numeric columns
129
129
  */
130
- calculateAggregates(n, a) {
131
- const e = {};
132
- for (const t of a.columns)
133
- if (t.type === "number" && n.length > 0)
130
+ calculateAggregates(e, t) {
131
+ const n = {};
132
+ for (const s of t.columns)
133
+ if (s.type === "number" && e.length > 0)
134
134
  try {
135
- const s = H(n, t.name, "number");
136
- e[t.name] = {
137
- mean: s.mean,
138
- median: s.median,
139
- min: s.min,
140
- max: s.max,
141
- count: s.count
135
+ const a = B(e, s.name, "number");
136
+ n[s.name] = {
137
+ mean: a.mean,
138
+ median: a.median,
139
+ min: a.min,
140
+ max: a.max,
141
+ count: a.count
142
142
  };
143
143
  } catch {
144
144
  }
145
- else if (t.type === "categorical" || t.type === "string") {
146
- const s = n.map((o) => o[t.name]).filter((o) => o != null), r = new Set(s);
147
- e[t.name] = {
148
- uniqueCount: r.size,
149
- totalCount: s.length,
150
- topValues: this.getTopValues(s, 5)
145
+ 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);
147
+ n[s.name] = {
148
+ uniqueCount: o.size,
149
+ totalCount: a.length,
150
+ topValues: this.getTopValues(a, 5)
151
151
  };
152
152
  }
153
- return e;
153
+ return n;
154
154
  }
155
155
  /**
156
156
  * Get top N most frequent values
157
157
  */
158
- getTopValues(n, a) {
159
- const e = /* @__PURE__ */ new Map();
160
- for (const t of n)
161
- e.set(t, (e.get(t) || 0) + 1);
162
- return Array.from(e.entries()).map(([t, s]) => ({ value: t, count: s })).sort((t, s) => s.count - t.count).slice(0, a);
158
+ getTopValues(e, t) {
159
+ const n = /* @__PURE__ */ new Map();
160
+ for (const s of e)
161
+ 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);
163
163
  }
164
164
  /**
165
165
  * Build prompt for LLM
166
166
  */
167
- buildPrompt(n, a, e, t, s) {
168
- const r = s && s > e.length;
169
- let o = `You are a data analyst assistant. Answer the following question about a table dataset.
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.
170
170
 
171
171
  `;
172
- o += `**Table Schema:**
173
- `, o += `Table: ${a.name}
174
- `, o += `Columns:
172
+ r += `**Table Schema:**
173
+ `, r += `Table: ${t.name}
174
+ `, r += `Columns:
175
175
  `;
176
- for (const i of a.columns)
177
- o += `- ${i.name} (${i.type})
176
+ for (const i of t.columns)
177
+ r += `- ${i.name} (${i.type})
178
178
  `;
179
- return o += `
180
- `, t && Object.keys(t).length > 0 && (o += `**Summary Statistics:**
181
- `, o += JSON.stringify(t, null, 2), o += `
179
+ return r += `
180
+ `, s && Object.keys(s).length > 0 && (r += `**Summary Statistics:**
181
+ `, r += JSON.stringify(s, null, 2), r += `
182
182
 
183
- `), o += `**Sample Data** (${e.length} rows${r ? ` out of ${s} total` : ""}):
184
- `, o += JSON.stringify(e.slice(0, 10), null, 2), o += `
183
+ `), r += `**Sample Data** (${n.length} rows${o ? ` out of ${a} total` : ""}):
184
+ `, r += JSON.stringify(n.slice(0, 10), null, 2), r += `
185
185
 
186
- `, o += `**Question:** ${n}
186
+ `, r += `**Question:** ${e}
187
187
 
188
- `, o += `**Instructions:**
189
- `, o += `1. Answer ONLY based on the data provided above.
190
- `, o += `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
- `, o += `3. Provide a clear, concise answer.
192
- `, o += `4. Include specific numbers or examples from the data when relevant.
193
- `, o += `5. If the answer is based on sampled data, mention that it's an approximation.
194
- `, o += `6. Format your response as JSON with the following structure:
195
- `, o += `{
196
- `, o += ` "answer": "Your answer text here",
197
- `, o += ` "confidence": 0.0-1.0,
198
- `, o += ` "cannotAnswer": false,
199
- `, o += ` "isApproximate": ${r},
200
- `, o += ` "supportingData": { "key": "value" } // optional
201
- `, o += `}
202
- `, o;
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;
203
203
  }
204
204
  /**
205
205
  * Call LLM API
206
206
  */
207
- async callLLM(n) {
208
- const { provider: a, apiKey: e, baseUrl: t, model: s, maxTokens: r, temperature: o } = this.config;
209
- if (a === "openai")
210
- return this.callOpenAI(n, e, s || "gpt-4-turbo-preview", r, o);
211
- if (a === "anthropic")
212
- return this.callAnthropic(n, e, s || "claude-3-5-sonnet-20241022", r, o);
213
- if (a === "custom" && t)
214
- return this.callCustomAPI(n, t, e);
215
- throw new Error(`Unsupported provider: ${a}`);
207
+ async callLLM(e) {
208
+ const { provider: t, apiKey: n, baseUrl: s, model: a, maxTokens: o, temperature: r } = this.config;
209
+ if (t === "openai")
210
+ return this.callOpenAI(e, n, a || "gpt-4-turbo-preview", o, r);
211
+ if (t === "anthropic")
212
+ return this.callAnthropic(e, n, a || "claude-3-5-sonnet-20241022", o, r);
213
+ if (t === "custom" && s)
214
+ return this.callCustomAPI(e, s, n);
215
+ throw new Error(`Unsupported provider: ${t}`);
216
216
  }
217
217
  /**
218
218
  * Call OpenAI API
219
219
  */
220
- async callOpenAI(n, a, e, t, s) {
221
- var i, u;
222
- const r = await fetch("https://api.openai.com/v1/chat/completions", {
220
+ async callOpenAI(e, t, n, s, a) {
221
+ var i, l;
222
+ const o = await fetch("https://api.openai.com/v1/chat/completions", {
223
223
  method: "POST",
224
224
  headers: {
225
225
  "Content-Type": "application/json",
226
- Authorization: `Bearer ${a}`
226
+ Authorization: `Bearer ${t}`
227
227
  },
228
228
  body: JSON.stringify({
229
- model: e,
230
- messages: [{ role: "user", content: n }],
231
- max_tokens: t,
232
- temperature: s,
229
+ model: n,
230
+ messages: [{ role: "user", content: e }],
231
+ max_tokens: s,
232
+ temperature: a,
233
233
  response_format: { type: "json_object" }
234
234
  })
235
235
  });
236
- if (!r.ok)
237
- throw new Error(`OpenAI API error: ${r.statusText}`);
238
- return ((u = (i = (await r.json()).choices[0]) == null ? void 0 : i.message) == null ? void 0 : u.content) || "";
236
+ if (!o.ok)
237
+ 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) || "";
239
239
  }
240
240
  /**
241
241
  * Call Anthropic API
242
242
  */
243
- async callAnthropic(n, a, e, t, s) {
243
+ async callAnthropic(e, t, n, s, a) {
244
244
  var i;
245
- const r = await fetch("https://api.anthropic.com/v1/messages", {
245
+ const o = await fetch("https://api.anthropic.com/v1/messages", {
246
246
  method: "POST",
247
247
  headers: {
248
248
  "Content-Type": "application/json",
249
- "x-api-key": a,
249
+ "x-api-key": t,
250
250
  "anthropic-version": "2023-06-01"
251
251
  },
252
252
  body: JSON.stringify({
253
- model: e,
254
- max_tokens: t,
255
- temperature: s,
256
- messages: [{ role: "user", content: n }]
253
+ model: n,
254
+ max_tokens: s,
255
+ temperature: a,
256
+ messages: [{ role: "user", content: e }]
257
257
  })
258
258
  });
259
- if (!r.ok)
260
- throw new Error(`Anthropic API error: ${r.statusText}`);
261
- return ((i = (await r.json()).content[0]) == null ? void 0 : i.text) || "";
259
+ if (!o.ok)
260
+ throw new Error(`Anthropic API error: ${o.statusText}`);
261
+ return ((i = (await o.json()).content[0]) == null ? void 0 : i.text) || "";
262
262
  }
263
263
  /**
264
264
  * Call custom API
265
265
  */
266
- async callCustomAPI(n, a, e) {
267
- const t = {
266
+ async callCustomAPI(e, t, n) {
267
+ const s = {
268
268
  "Content-Type": "application/json"
269
269
  };
270
- e && (t.Authorization = `Bearer ${e}`);
271
- const s = await fetch(a, {
270
+ n && (s.Authorization = `Bearer ${n}`);
271
+ const a = await fetch(t, {
272
272
  method: "POST",
273
- headers: t,
274
- body: JSON.stringify({ prompt: n })
273
+ headers: s,
274
+ body: JSON.stringify({ prompt: e })
275
275
  });
276
- if (!s.ok)
277
- throw new Error(`Custom API error: ${s.statusText}`);
278
- const r = await s.json();
279
- return r.response || r.answer || JSON.stringify(r);
276
+ if (!a.ok)
277
+ throw new Error(`Custom API error: ${a.statusText}`);
278
+ const o = await a.json();
279
+ return o.response || o.answer || JSON.stringify(o);
280
280
  }
281
281
  /**
282
282
  * Parse LLM response
283
283
  */
284
- parseResponse(n, a, e) {
284
+ parseResponse(e, t, n) {
285
285
  try {
286
- const t = JSON.parse(n);
286
+ const s = JSON.parse(e);
287
287
  return {
288
288
  questionId: this.generateId(),
289
- text: t.answer || t.text || n,
289
+ text: s.answer || s.text || e,
290
290
  timestamp: /* @__PURE__ */ new Date(),
291
- confidence: t.confidence || 0.8,
292
- cannotAnswer: t.cannotAnswer || !1,
293
- isApproximate: t.isApproximate !== void 0 ? t.isApproximate : e,
294
- supportingData: t.supportingData,
295
- reason: t.reason
291
+ confidence: s.confidence || 0.8,
292
+ cannotAnswer: s.cannotAnswer || !1,
293
+ isApproximate: s.isApproximate !== void 0 ? s.isApproximate : n,
294
+ supportingData: s.supportingData,
295
+ reason: s.reason
296
296
  };
297
297
  } catch {
298
298
  return {
299
299
  questionId: this.generateId(),
300
- text: n,
300
+ text: e,
301
301
  timestamp: /* @__PURE__ */ new Date(),
302
302
  confidence: 0.7,
303
- isApproximate: e
303
+ isApproximate: n
304
304
  };
305
305
  }
306
306
  }
@@ -311,115 +311,237 @@ class P {
311
311
  return `qa_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
312
312
  }
313
313
  }
314
- function ne(l = {}) {
314
+ function re(c = {}) {
315
315
  const {
316
- selector: n = "table",
317
- includeHeaders: a = !0,
318
- maxRows: e,
319
- inferTypes: t = !0,
320
- skipEmptyRows: s = !0
321
- } = l, r = document.querySelector(n);
322
- if (!r || r.tagName !== "TABLE")
323
- return console.warn(`No table found with selector: ${n}`), null;
324
- const i = Array.from(r.rows);
316
+ selector: e = "table",
317
+ includeHeaders: t = !0,
318
+ maxRows: n,
319
+ inferTypes: s = !0,
320
+ skipEmptyRows: a = !0
321
+ } = c, o = document.querySelector(e);
322
+ if (!o || o.tagName !== "TABLE")
323
+ return console.warn(`No table found with selector: ${e}`), null;
324
+ const i = Array.from(o.rows);
325
325
  if (i.length === 0)
326
326
  return null;
327
- let u = [], g = 0;
328
- if (a && i[0]) {
329
- const b = i[0];
330
- u = Array.from(b.cells).map((_, k) => {
331
- var S;
332
- return ((S = _.textContent) == null ? void 0 : S.trim()) || "" || `Column${k + 1}`;
327
+ let l = [], g = 0;
328
+ if (t && i[0]) {
329
+ const v = i[0];
330
+ l = Array.from(v.cells).map(($, C) => {
331
+ var _;
332
+ return ((_ = $.textContent) == null ? void 0 : _.trim()) || "" || `Column${C + 1}`;
333
333
  }), g = 1;
334
334
  } else {
335
- const b = i[0];
336
- u = Array.from(b.cells).map((_, k) => `Column${k + 1}`);
337
- }
338
- const h = [], w = e ? i.slice(g, g + e) : i.slice(g);
339
- for (const b of w) {
340
- const _ = Array.from(b.cells);
341
- if (s && _.every((x) => {
342
- var S;
343
- return !((S = x.textContent) != null && S.trim());
335
+ const v = i[0];
336
+ l = Array.from(v.cells).map(($, C) => `Column${C + 1}`);
337
+ }
338
+ const p = [], d = n ? i.slice(g, g + n) : i.slice(g);
339
+ for (const v of d) {
340
+ const $ = Array.from(v.cells);
341
+ if (a && $.every((D) => {
342
+ var _;
343
+ return !((_ = D.textContent) != null && _.trim());
344
344
  }))
345
345
  continue;
346
- const k = {};
347
- _.forEach((x, S) => {
346
+ const C = {};
347
+ $.forEach((D, _) => {
348
348
  var M;
349
- const z = u[S] || `Column${S + 1}`;
350
- let q = ((M = x.textContent) == null ? void 0 : M.trim()) || "";
351
- if (t && q) {
352
- const N = parseFloat(q);
353
- !isNaN(N) && q === N.toString() && (q = N);
349
+ const j = l[_] || `Column${_ + 1}`;
350
+ let T = ((M = D.textContent) == null ? void 0 : M.trim()) || "";
351
+ if (s && T) {
352
+ const P = parseFloat(T);
353
+ !isNaN(P) && T === P.toString() && (T = P);
354
354
  }
355
- k[z] = q;
356
- }), h.push(k);
355
+ C[j] = T;
356
+ }), p.push(C);
357
357
  }
358
358
  return {
359
- schema: t && h.length > 0 ? I(h, "Extracted Table") : ae(u, h.length),
360
- data: h,
359
+ schema: s && p.length > 0 ? N(p, "Extracted Table") : ie(l, p.length),
360
+ data: p,
361
361
  source: "dom",
362
362
  metadata: {
363
- selector: n,
364
- rowCount: h.length,
365
- columnCount: u.length,
363
+ selector: e,
364
+ rowCount: p.length,
365
+ columnCount: l.length,
366
366
  extractedAt: /* @__PURE__ */ new Date()
367
367
  }
368
368
  };
369
369
  }
370
- function se(l, n, a = {}) {
371
- const { maxRows: e, inferTypes: t = !0 } = a, s = e ? l.slice(0, e) : l;
372
- let r;
373
- return n && n.length > 0 ? r = {
370
+ function oe(c, e, t = {}) {
371
+ const { maxRows: n, inferTypes: s = !0 } = t, a = n ? c.slice(0, n) : c;
372
+ let o;
373
+ return e && e.length > 0 ? o = {
374
374
  name: "Vue Data Grid",
375
- columns: n.map((o) => ({
376
- name: o.field,
377
- type: t && s.length > 0 ? B(s, o.field) : "string",
375
+ columns: e.map((r) => ({
376
+ name: r.field,
377
+ type: s && a.length > 0 ? L(a, r.field) : "string",
378
378
  nullable: !0
379
379
  })),
380
- rowCount: s.length
381
- } : s.length > 0 ? r = I(s, "Vue Data Grid") : r = { name: "Vue Data Grid", columns: [], rowCount: 0 }, {
382
- schema: r,
383
- data: s,
380
+ rowCount: a.length
381
+ } : a.length > 0 ? o = N(a, "Vue Data Grid") : o = { name: "Vue Data Grid", columns: [], rowCount: 0 }, {
382
+ schema: o,
383
+ data: a,
384
384
  source: "vue",
385
385
  metadata: {
386
- rowCount: s.length,
387
- columnCount: r.columns.length,
386
+ rowCount: a.length,
387
+ columnCount: o.columns.length,
388
388
  extractedAt: /* @__PURE__ */ new Date()
389
389
  }
390
390
  };
391
391
  }
392
- function ae(l, n = 0) {
392
+ function ie(c, e = 0) {
393
393
  return {
394
394
  name: "Extracted Table",
395
- columns: l.map((a) => ({
396
- name: a,
395
+ columns: c.map((t) => ({
396
+ name: t,
397
397
  type: "string",
398
398
  nullable: !0
399
399
  })),
400
- rowCount: n
400
+ rowCount: e
401
+ };
402
+ }
403
+ function ce(c) {
404
+ const e = {};
405
+ c.variable && c.variable.forEach((a) => {
406
+ e[a.key] = a.value;
407
+ });
408
+ const t = c.auth ? J(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(le(r, t));
412
+ });
413
+ }
414
+ return s(c.item), {
415
+ name: c.info.name,
416
+ description: c.info.description,
417
+ endpoints: n,
418
+ variables: e,
419
+ auth: t
420
+ };
421
+ }
422
+ function le(c, e) {
423
+ const t = c.request, n = {};
424
+ t.header && t.header.forEach((o) => {
425
+ n[o.key] = o.value;
426
+ });
427
+ const s = {};
428
+ t.url.query && t.url.query.forEach((o) => {
429
+ s[o.key] = o.value;
430
+ });
431
+ const a = t.auth ? J(t.auth) : e;
432
+ return {
433
+ name: c.name,
434
+ method: t.method,
435
+ url: t.url.raw,
436
+ description: t.description,
437
+ headers: n,
438
+ queryParams: s,
439
+ auth: a
440
+ };
441
+ }
442
+ function J(c) {
443
+ const e = {};
444
+ return c.apikey ? c.apikey.forEach((t) => {
445
+ e[t.key] = t.value;
446
+ }) : c.bearer ? c.bearer.forEach((t) => {
447
+ e[t.key] = t.value;
448
+ }) : c.basic && c.basic.forEach((t) => {
449
+ e[t.key] = t.value;
450
+ }), {
451
+ type: c.type,
452
+ credentials: e
401
453
  };
402
454
  }
403
- class oe {
404
- constructor(n, a) {
455
+ function I(c, e) {
456
+ let t = c;
457
+ return Object.keys(e).forEach((n) => {
458
+ const s = new RegExp(`{{${n}}}`, "g");
459
+ t = t.replace(s, e[n]);
460
+ }), t;
461
+ }
462
+ async function U(c) {
463
+ const { endpoint: e, variables: t = {}, additionalHeaders: n = {}, additionalParams: s = {} } = c;
464
+ try {
465
+ let a = I(e.url, t);
466
+ const o = { ...e.queryParams, ...s }, r = Object.keys(o).map((d) => `${encodeURIComponent(d)}=${encodeURIComponent(I(o[d], t))}`).join("&");
467
+ r && (a = a.includes("?") ? `${a}&${r}` : `${a}?${r}`);
468
+ const i = {
469
+ "Content-Type": "application/json",
470
+ ...e.headers,
471
+ ...n
472
+ };
473
+ if (Object.keys(i).forEach((d) => {
474
+ i[d] = I(i[d], t);
475
+ }), e.auth) {
476
+ if (e.auth.type === "apikey") {
477
+ const d = e.auth.credentials.key || "access_key", y = I(e.auth.credentials.value || "", t);
478
+ e.auth.credentials.in === "header" && (i[d] = y);
479
+ } else if (e.auth.type === "bearer") {
480
+ const d = I(e.auth.credentials.token || "", t);
481
+ i.Authorization = `Bearer ${d}`;
482
+ } else if (e.auth.type === "basic") {
483
+ const d = I(e.auth.credentials.username || "", t), y = I(e.auth.credentials.password || "", t), v = btoa(`${d}:${y}`);
484
+ i.Authorization = `Basic ${v}`;
485
+ }
486
+ }
487
+ const l = await fetch(a, {
488
+ method: e.method,
489
+ headers: i
490
+ }), g = {};
491
+ return l.headers.forEach((d, y) => {
492
+ g[y] = d;
493
+ }), l.ok ? {
494
+ success: !0,
495
+ data: await l.json(),
496
+ statusCode: l.status,
497
+ headers: g
498
+ } : {
499
+ success: !1,
500
+ error: `HTTP ${l.status}: ${l.statusText}`,
501
+ statusCode: l.status,
502
+ headers: g
503
+ };
504
+ } catch (a) {
505
+ return {
506
+ success: !1,
507
+ error: a.message || "Unknown error occurred"
508
+ };
509
+ }
510
+ }
511
+ async function Ge(c, e = {}) {
512
+ const t = [];
513
+ for (const n of c) {
514
+ const s = await U({ endpoint: n, variables: e });
515
+ t.push(s);
516
+ }
517
+ return t;
518
+ }
519
+ function ue(c) {
520
+ if (!c.success || !c.data)
521
+ return [];
522
+ const e = c.data;
523
+ 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
+ }
525
+ class de {
526
+ constructor(e, t) {
405
527
  this.config = {
406
528
  timeout: 3e4,
407
- ...n
408
- }, a && (this.qaEngine = new P(a));
529
+ ...e
530
+ }, t && (this.qaEngine = new H(t));
409
531
  }
410
532
  /**
411
533
  * Initialize or update Q&A engine
412
534
  */
413
- initializeQA(n) {
414
- this.qaEngine = new P(n);
535
+ initializeQA(e) {
536
+ this.qaEngine = new H(e);
415
537
  }
416
538
  /**
417
539
  * Generic API call to TFM endpoint
418
540
  */
419
- async callTFM(n) {
420
- const a = Date.now();
541
+ async callTFM(e) {
542
+ const t = Date.now();
421
543
  try {
422
- const e = await fetch(this.config.baseUrl, {
544
+ const n = await fetch(this.config.baseUrl, {
423
545
  method: "POST",
424
546
  headers: {
425
547
  "Content-Type": "application/json",
@@ -427,31 +549,31 @@ class oe {
427
549
  ...this.config.headers
428
550
  },
429
551
  body: JSON.stringify({
430
- ...n,
552
+ ...e,
431
553
  model: this.config.model
432
554
  }),
433
555
  signal: AbortSignal.timeout(this.config.timeout || 3e4)
434
556
  });
435
- if (!e.ok) {
436
- const r = await e.text();
437
- throw new Error(`TFM API error: ${e.status} - ${r}`);
557
+ if (!n.ok) {
558
+ const o = await n.text();
559
+ throw new Error(`TFM API error: ${n.status} - ${o}`);
438
560
  }
439
- const t = await e.json(), s = Date.now() - a;
561
+ const s = await n.json(), a = Date.now() - t;
440
562
  return {
441
563
  success: !0,
442
- result: t.result || t,
564
+ result: s.result || s,
443
565
  metadata: {
444
- processingTime: s,
566
+ processingTime: a,
445
567
  model: this.config.model || "unknown",
446
- version: t.version
568
+ version: s.version
447
569
  }
448
570
  };
449
- } catch (e) {
571
+ } catch (n) {
450
572
  return {
451
573
  success: !1,
452
- error: e instanceof Error ? e.message : "Unknown error",
574
+ error: n instanceof Error ? n.message : "Unknown error",
453
575
  metadata: {
454
- processingTime: Date.now() - a,
576
+ processingTime: Date.now() - t,
455
577
  model: this.config.model || "unknown"
456
578
  }
457
579
  };
@@ -460,278 +582,349 @@ class oe {
460
582
  /**
461
583
  * Perform analysis on tabular data
462
584
  */
463
- async analyze(n) {
464
- const a = {
465
- operation: n.type,
466
- data: n.data,
467
- schema: n.schema,
468
- parameters: n.options
469
- }, e = await this.callTFM(a);
470
- if (!e.success)
471
- throw new Error(e.error || "Analysis failed");
472
- return this.parseAnalysisResult(n.type, e.result, e.metadata);
585
+ async analyze(e) {
586
+ const t = {
587
+ operation: e.type,
588
+ data: e.data,
589
+ schema: e.schema,
590
+ parameters: e.options
591
+ }, n = await this.callTFM(t);
592
+ if (!n.success)
593
+ throw new Error(n.error || "Analysis failed");
594
+ return this.parseAnalysisResult(e.type, n.result, n.metadata);
473
595
  }
474
596
  /**
475
597
  * Parse TFM response into structured AnalysisResult
476
598
  */
477
- parseAnalysisResult(n, a, e) {
478
- const t = {
479
- type: n,
599
+ parseAnalysisResult(e, t, n) {
600
+ const s = {
601
+ type: e,
480
602
  timestamp: /* @__PURE__ */ new Date(),
481
- summary: a.summary || "",
482
- insights: a.insights || [],
483
- recommendations: a.recommendations,
484
- confidence: a.confidence || 0.8,
485
- processingTime: e == null ? void 0 : e.processingTime
603
+ summary: t.summary || "",
604
+ insights: t.insights || [],
605
+ recommendations: t.recommendations,
606
+ confidence: t.confidence || 0.8,
607
+ processingTime: n == null ? void 0 : n.processingTime
486
608
  };
487
- switch (n) {
609
+ switch (e) {
488
610
  case "descriptive_stats":
489
611
  return {
490
- ...t,
491
- descriptiveStats: a.stats || a.descriptiveStats
612
+ ...s,
613
+ descriptiveStats: t.stats || t.descriptiveStats
492
614
  };
493
615
  case "anomaly_detection":
494
616
  return {
495
- ...t,
496
- anomalies: a.anomalies || []
617
+ ...s,
618
+ anomalies: t.anomalies || []
497
619
  };
498
620
  case "segmentation":
499
621
  case "clustering":
500
622
  return {
501
- ...t,
502
- clusters: a.clusters || []
623
+ ...s,
624
+ clusters: t.clusters || []
503
625
  };
504
626
  case "prediction":
505
627
  return {
506
- ...t,
507
- predictions: a.predictions || a
628
+ ...s,
629
+ predictions: t.predictions || t
508
630
  };
509
631
  case "correlation":
510
632
  return {
511
- ...t,
512
- correlations: a.correlations || a
633
+ ...s,
634
+ correlations: t.correlations || t
513
635
  };
514
636
  case "summary":
515
637
  return {
516
- ...t,
517
- aiSummary: a.summary || a
638
+ ...s,
639
+ aiSummary: t.summary || t
518
640
  };
519
641
  case "qa":
520
642
  return {
521
- ...t,
522
- qaAnswer: a.answer || a
643
+ ...s,
644
+ qaAnswer: t.answer || t
523
645
  };
524
646
  default:
525
- return t;
647
+ return s;
526
648
  }
527
649
  }
528
650
  /**
529
651
  * Ask a question about the data (Q&A)
530
652
  */
531
- async askQuestion(n) {
653
+ async askQuestion(e) {
532
654
  if (!this.qaEngine)
533
655
  throw new Error("Q&A engine not initialized. Call initializeQA() first.");
534
- return this.qaEngine.answerQuestion(n);
656
+ return this.qaEngine.answerQuestion(e);
535
657
  }
536
658
  /**
537
659
  * Generate AI summary of table data
538
660
  */
539
- async generateSummary(n, a) {
540
- const e = {
661
+ async generateSummary(e, t) {
662
+ const n = {
541
663
  type: "summary",
542
- data: n,
543
- schema: a
544
- }, t = await this.analyze(e);
545
- if (!t.aiSummary)
664
+ data: e,
665
+ schema: t
666
+ }, s = await this.analyze(n);
667
+ if (!s.aiSummary)
546
668
  throw new Error("Failed to generate summary");
547
- return t.aiSummary;
669
+ return s.aiSummary;
548
670
  }
549
671
  /**
550
672
  * Extract table from DOM
551
673
  */
552
- extractFromDOM(n) {
553
- return ne(n);
674
+ extractFromDOM(e) {
675
+ return re(e);
554
676
  }
555
677
  /**
556
678
  * Normalize Vue data grid data
557
679
  */
558
- normalizeVueData(n, a, e) {
559
- return se(n, a, e);
680
+ normalizeVueData(e, t, n) {
681
+ return oe(e, t, n);
560
682
  }
561
683
  /**
562
684
  * Update configuration
563
685
  */
564
- updateConfig(n) {
565
- this.config = { ...this.config, ...n };
686
+ updateConfig(e) {
687
+ this.config = { ...this.config, ...e };
566
688
  }
567
689
  /**
568
690
  * Get current configuration (without sensitive data)
569
691
  */
570
692
  getConfig() {
571
- const { apiKey: n, ...a } = this.config;
572
- return a;
693
+ const { apiKey: e, ...t } = this.config;
694
+ return t;
695
+ }
696
+ // ============================================================================
697
+ // API Integration Methods
698
+ // ============================================================================
699
+ /**
700
+ * Load Postman collection
701
+ */
702
+ loadPostmanCollection(e) {
703
+ return this.parsedCollection = ce(e), this.parsedCollection;
704
+ }
705
+ /**
706
+ * Get loaded collection
707
+ */
708
+ getCollection() {
709
+ return this.parsedCollection;
710
+ }
711
+ /**
712
+ * Get endpoints from loaded collection
713
+ */
714
+ getEndpoints() {
715
+ var e;
716
+ return ((e = this.parsedCollection) == null ? void 0 : e.endpoints) || [];
717
+ }
718
+ /**
719
+ * Execute API request and get data
720
+ */
721
+ async fetchDataFromAPI(e, t) {
722
+ if (!this.parsedCollection)
723
+ throw new Error("No Postman collection loaded. Call loadPostmanCollection() first.");
724
+ const n = this.parsedCollection.endpoints.find((i) => i.name === e);
725
+ if (!n)
726
+ throw new Error(`Endpoint "${e}" not found in collection.`);
727
+ const s = {
728
+ ...this.parsedCollection.variables,
729
+ ...t
730
+ }, a = await U({ endpoint: n, variables: s });
731
+ if (!a.success)
732
+ throw new Error(`API request failed: ${a.error}`);
733
+ const o = ue(a), r = N(o);
734
+ return { data: o, schema: r };
735
+ }
736
+ /**
737
+ * Query API data with natural language
738
+ */
739
+ async queryAPI(e) {
740
+ if (!this.qaEngine)
741
+ throw new Error("Q&A engine not initialized. Provide qaConfig in constructor or call initializeQA().");
742
+ const t = Date.now(), { data: n, schema: s } = await this.fetchDataFromAPI(
743
+ e.dataSource.endpoint || "",
744
+ e.variables
745
+ ), a = {
746
+ question: e.question,
747
+ schema: s,
748
+ data: n
749
+ }, o = await this.qaEngine.answerQuestion(a), r = Date.now() - t;
750
+ return {
751
+ answer: o.answer,
752
+ apiResponse: n,
753
+ endpoint: e.dataSource.endpoint,
754
+ executionTime: r
755
+ };
756
+ }
757
+ /**
758
+ * List available endpoints from loaded collection
759
+ */
760
+ listEndpoints() {
761
+ return this.parsedCollection ? this.parsedCollection.endpoints.map((e) => ({
762
+ name: e.name,
763
+ method: e.method,
764
+ description: e.description
765
+ })) : [];
573
766
  }
574
767
  }
575
- function Be(l) {
576
- const n = new oe(l.config, l.qaConfig), a = C(!1), e = C(null), t = C(null), s = l.data || C([]), r = l.schema || C(null), o = C([]), i = C([]), u = C(null), g = l.maxQuestionHistory || 50, h = l.useLocalFallback !== !1;
577
- async function w(c, f) {
578
- a.value = !0, e.value = null;
768
+ function Ye(c) {
769
+ const e = new de(c.config, c.qaConfig), t = E(!1), n = E(null), s = E(null), a = c.data || E([]), o = c.schema || E(null), r = E([]), i = E([]), l = E(null), g = c.maxQuestionHistory || 50, p = c.useLocalFallback !== !1;
770
+ async function d(u, w) {
771
+ t.value = !0, n.value = null;
579
772
  try {
580
- const y = {
581
- type: c,
582
- data: s.value,
583
- schema: r.value || void 0,
584
- options: f
585
- }, $ = await n.analyze(y);
586
- return t.value = $, $;
587
- } catch (y) {
588
- if (e.value = y instanceof Error ? y : new Error("Analysis failed"), h)
589
- return A(c, f);
590
- throw e.value;
773
+ const b = {
774
+ type: u,
775
+ data: a.value,
776
+ schema: o.value || void 0,
777
+ options: w
778
+ }, k = await e.analyze(b);
779
+ return s.value = k, k;
780
+ } catch (b) {
781
+ if (n.value = b instanceof Error ? b : new Error("Analysis failed"), p)
782
+ return y(u, w);
783
+ throw n.value;
591
784
  } finally {
592
- a.value = !1;
785
+ t.value = !1;
593
786
  }
594
787
  }
595
- function A(c, f) {
596
- const y = r.value || I(s.value);
597
- switch (c) {
788
+ function y(u, w) {
789
+ const b = o.value || N(a.value);
790
+ switch (u) {
598
791
  case "descriptive_stats": {
599
- const $ = y.columns.map(
600
- (E) => H(s.value, E.name, E.type)
792
+ const k = b.columns.map(
793
+ (x) => B(a.value, x.name, x.type)
601
794
  );
602
795
  return {
603
- type: c,
796
+ type: u,
604
797
  timestamp: /* @__PURE__ */ new Date(),
605
- descriptiveStats: $,
606
- summary: `Calculated statistics for ${$.length} columns`,
798
+ descriptiveStats: k,
799
+ summary: `Calculated statistics for ${k.length} columns`,
607
800
  insights: [],
608
801
  confidence: 0.9
609
802
  };
610
803
  }
611
804
  case "anomaly_detection": {
612
- const $ = y.columns.filter((D) => D.type === "number").map((D) => D.name), E = te(
613
- s.value,
614
- $,
615
- f == null ? void 0 : f.sensitivity
805
+ const k = b.columns.filter((q) => q.type === "number").map((q) => q.name), x = ae(
806
+ a.value,
807
+ k,
808
+ w == null ? void 0 : w.sensitivity
616
809
  );
617
810
  return {
618
- type: c,
811
+ type: u,
619
812
  timestamp: /* @__PURE__ */ new Date(),
620
- anomalies: E,
621
- summary: `Found ${E.length} anomalies`,
622
- insights: E.slice(0, 3).map((D) => D.reasons[0]),
813
+ anomalies: x,
814
+ summary: `Found ${x.length} anomalies`,
815
+ insights: x.slice(0, 3).map((q) => q.reasons[0]),
623
816
  confidence: 0.8
624
817
  };
625
818
  }
626
819
  default:
627
- throw new Error(`Local analysis not supported for type: ${c}`);
820
+ throw new Error(`Local analysis not supported for type: ${u}`);
628
821
  }
629
822
  }
630
- async function b() {
631
- return (await w("descriptive_stats")).descriptiveStats || [];
823
+ async function v() {
824
+ return (await d("descriptive_stats")).descriptiveStats || [];
632
825
  }
633
- async function _(c, f) {
634
- return (await w("anomaly_detection", { sensitivity: f, features: c })).anomalies || [];
826
+ async function $(u, w) {
827
+ return (await d("anomaly_detection", { sensitivity: w, features: u })).anomalies || [];
635
828
  }
636
- async function k(c, f = 3) {
637
- return w("clustering", { features: c, numClusters: f });
829
+ async function C(u, w = 3) {
830
+ return d("clustering", { features: u, numClusters: w });
638
831
  }
639
- async function x(c, f) {
640
- return w("prediction", { targetColumn: c, ...f });
832
+ async function D(u, w) {
833
+ return d("prediction", { targetColumn: u, ...w });
641
834
  }
642
- function S(c) {
643
- n.updateConfig(c);
835
+ function _(u) {
836
+ e.updateConfig(u);
644
837
  }
645
- function z(c, f = !0) {
646
- s.value = c, f && (r.value = I(c));
838
+ function j(u, w = !0) {
839
+ a.value = u, w && (o.value = N(u));
647
840
  }
648
- function q() {
649
- a.value = !1, e.value = null, t.value = null, o.value = [], i.value = [], u.value = null;
841
+ function T() {
842
+ t.value = !1, n.value = null, s.value = null, r.value = [], i.value = [], l.value = null;
650
843
  }
651
- async function M(c, f) {
652
- a.value = !0, e.value = null;
844
+ async function M(u, w) {
845
+ t.value = !0, n.value = null;
653
846
  try {
654
- const y = r.value || I(s.value), $ = {
655
- question: c,
656
- schema: y,
657
- data: s.value,
847
+ const b = o.value || N(a.value), k = {
848
+ question: u,
849
+ schema: b,
850
+ data: a.value,
658
851
  sampleSize: 100,
659
852
  includeAggregates: !0,
660
- ...f
661
- }, D = (await n.askQuestion($)).answer, G = {
662
- id: D.questionId,
663
- text: c,
853
+ ...w
854
+ }, q = (await e.askQuestion(k)).answer, X = {
855
+ id: q.questionId,
856
+ text: u,
664
857
  timestamp: /* @__PURE__ */ new Date(),
665
858
  context: {
666
- tableSchema: y,
667
- rowCount: s.value.length
859
+ tableSchema: b,
860
+ rowCount: a.value.length
668
861
  }
669
862
  };
670
- return o.value.push(G), i.value.push(D), u.value = D, o.value.length > g && (o.value.shift(), i.value.shift()), D;
671
- } catch (y) {
672
- throw e.value = y instanceof Error ? y : new Error("Q&A failed"), e.value;
863
+ return r.value.push(X), i.value.push(q), l.value = q, r.value.length > g && (r.value.shift(), i.value.shift()), q;
864
+ } catch (b) {
865
+ throw n.value = b instanceof Error ? b : new Error("Q&A failed"), n.value;
673
866
  } finally {
674
- a.value = !1;
867
+ t.value = !1;
675
868
  }
676
869
  }
677
- async function N() {
678
- a.value = !0, e.value = null;
870
+ async function P() {
871
+ t.value = !0, n.value = null;
679
872
  try {
680
- const c = r.value || I(s.value);
681
- return await n.generateSummary(s.value, c);
682
- } catch (c) {
683
- throw e.value = c instanceof Error ? c : new Error("Summary generation failed"), e.value;
873
+ const u = o.value || N(a.value);
874
+ return await e.generateSummary(a.value, u);
875
+ } catch (u) {
876
+ throw n.value = u instanceof Error ? u : new Error("Summary generation failed"), n.value;
684
877
  } finally {
685
- a.value = !1;
878
+ t.value = !1;
686
879
  }
687
880
  }
688
- function R() {
689
- o.value = [], i.value = [], u.value = null;
881
+ function K() {
882
+ r.value = [], i.value = [], l.value = null;
690
883
  }
691
- function J(c) {
692
- const f = n.extractFromDOM(c);
693
- return f && (s.value = f.data, r.value = f.schema), f;
884
+ function G(u) {
885
+ const w = e.extractFromDOM(u);
886
+ return w && (a.value = w.data, o.value = w.schema), w;
694
887
  }
695
- function K(c, f, y) {
696
- const $ = n.normalizeVueData(c, f, y);
697
- s.value = $.data, r.value = $.schema;
888
+ function Y(u, w, b) {
889
+ const k = e.normalizeVueData(u, w, b);
890
+ a.value = k.data, o.value = k.schema;
698
891
  }
699
- function U(c) {
700
- n.initializeQA(c);
892
+ function W(u) {
893
+ e.initializeQA(u);
701
894
  }
702
895
  return {
703
- client: n,
704
- loading: a,
705
- error: e,
706
- lastResult: t,
707
- data: s,
708
- schema: r,
709
- questionHistory: o,
896
+ client: e,
897
+ loading: t,
898
+ error: n,
899
+ lastResult: s,
900
+ data: a,
901
+ schema: o,
902
+ questionHistory: r,
710
903
  answerHistory: i,
711
- lastAnswer: u,
712
- analyze: w,
713
- getDescriptiveStats: b,
714
- detectAnomalies: _,
715
- performClustering: k,
716
- predict: x,
904
+ lastAnswer: l,
905
+ analyze: d,
906
+ getDescriptiveStats: v,
907
+ detectAnomalies: $,
908
+ performClustering: C,
909
+ predict: D,
717
910
  askQuestion: M,
718
- generateSummary: N,
719
- clearHistory: R,
720
- extractFromDOM: J,
721
- loadFromVueGrid: K,
722
- updateConfig: S,
723
- initializeQA: U,
724
- setData: z,
725
- reset: q
911
+ generateSummary: P,
912
+ clearHistory: K,
913
+ extractFromDOM: G,
914
+ loadFromVueGrid: Y,
915
+ updateConfig: _,
916
+ initializeQA: W,
917
+ setData: j,
918
+ reset: T
726
919
  };
727
920
  }
728
- const re = { class: "ti-question-input" }, ie = { class: "ti-input-wrapper" }, le = ["placeholder", "disabled", "onKeydown"], ce = ["disabled"], ue = { key: 0 }, me = {
921
+ const me = { class: "ti-question-input" }, pe = { class: "ti-input-wrapper" }, he = ["placeholder", "disabled", "onKeydown"], fe = ["disabled"], ge = { key: 0 }, we = {
729
922
  key: 1,
730
923
  class: "ti-loading"
731
- }, de = {
924
+ }, ye = {
732
925
  key: 0,
733
926
  class: "ti-hint"
734
- }, pe = /* @__PURE__ */ F({
927
+ }, ve = /* @__PURE__ */ z({
735
928
  __name: "QuestionInput",
736
929
  props: {
737
930
  placeholder: { default: "Ask a question about this data..." },
@@ -743,184 +936,189 @@ const re = { class: "ti-question-input" }, ie = { class: "ti-input-wrapper" }, l
743
936
  loading: { type: Boolean, default: !1 }
744
937
  },
745
938
  emits: ["submit"],
746
- setup(l, { emit: n }) {
747
- const a = l, e = n, t = C("");
748
- function s() {
749
- t.value.trim() && !a.disabled && !a.loading && (e("submit", t.value.trim()), t.value = "");
939
+ setup(c, { emit: e }) {
940
+ const t = c, n = e, s = E("");
941
+ function a() {
942
+ s.value.trim() && !t.disabled && !t.loading && (n("submit", s.value.trim()), s.value = "");
750
943
  }
751
- function r(o) {
944
+ function o(r) {
752
945
  }
753
- return (o, i) => (p(), d("div", re, [
754
- m("div", ie, [
755
- Y(m("textarea", {
756
- "onUpdate:modelValue": i[0] || (i[0] = (u) => t.value = u),
757
- placeholder: o.placeholder,
758
- disabled: o.disabled,
946
+ return (r, i) => (f(), h("div", me, [
947
+ m("div", pe, [
948
+ Z(m("textarea", {
949
+ "onUpdate:modelValue": i[0] || (i[0] = (l) => s.value = l),
950
+ placeholder: r.placeholder,
951
+ disabled: r.disabled,
759
952
  class: "ti-textarea",
760
953
  rows: "2",
761
954
  onKeydown: [
762
- j(L(s, ["exact", "prevent"]), ["enter"]),
763
- j(L(r, ["shift"]), ["enter"])
955
+ V(R(a, ["exact", "prevent"]), ["enter"]),
956
+ V(R(o, ["shift"]), ["enter"])
764
957
  ]
765
- }, null, 40, le), [
766
- [W, t.value]
958
+ }, null, 40, he), [
959
+ [ee, s.value]
767
960
  ]),
768
961
  m("button", {
769
- disabled: o.disabled || !t.value.trim(),
962
+ disabled: r.disabled || !s.value.trim(),
770
963
  class: "ti-submit-btn",
771
- onClick: s
964
+ onClick: a
772
965
  }, [
773
- o.loading ? (p(), d("span", me, v(o.loadingLabel), 1)) : (p(), d("span", ue, v(o.submitLabel), 1))
774
- ], 8, ce)
966
+ r.loading ? (f(), h("span", we, A(r.loadingLabel), 1)) : (f(), h("span", ge, A(r.submitLabel), 1))
967
+ ], 8, fe)
775
968
  ]),
776
- o.showHint ? (p(), d("div", de, v(o.hint), 1)) : T("", !0)
969
+ r.showHint ? (f(), h("div", ye, A(r.hint), 1)) : S("", !0)
777
970
  ]));
778
971
  }
779
- }), V = (l, n) => {
780
- const a = l.__vccOpts || l;
781
- for (const [e, t] of n)
782
- a[e] = t;
783
- return a;
784
- }, He = /* @__PURE__ */ V(pe, [["__scopeId", "data-v-90db5921"]]), he = { class: "ti-answer-header" }, fe = { class: "ti-answer-icon" }, ge = { key: 0 }, we = { key: 1 }, ye = { class: "ti-answer-meta" }, ve = { class: "ti-confidence" }, be = { class: "ti-timestamp" }, Ae = { class: "ti-answer-text" }, _e = {
972
+ }), F = (c, e) => {
973
+ const t = c.__vccOpts || c;
974
+ for (const [n, s] of e)
975
+ t[n] = s;
976
+ return t;
977
+ }, We = /* @__PURE__ */ F(ve, [["__scopeId", "data-v-90db5921"]]), be = { class: "ti-answer-header" }, Ae = { class: "ti-answer-icon" }, $e = { key: 0 }, ke = { key: 1 }, Ce = { class: "ti-answer-meta" }, _e = { class: "ti-confidence" }, qe = { class: "ti-timestamp" }, Ee = { class: "ti-answer-text" }, Se = {
785
978
  key: 0,
786
979
  class: "ti-approximate-notice"
787
- }, $e = {
980
+ }, De = {
788
981
  key: 1,
789
982
  class: "ti-reason"
790
- }, ke = {
983
+ }, Te = {
791
984
  key: 2,
792
985
  class: "ti-supporting-data"
793
- }, Se = {
986
+ }, xe = {
794
987
  key: 0,
795
988
  class: "ti-supporting-content"
796
- }, De = {
989
+ }, Ie = {
797
990
  key: 0,
798
991
  class: "ti-aggregates"
799
- }, Ce = {
992
+ }, Ne = {
800
993
  key: 1,
801
994
  class: "ti-rows"
802
- }, Te = { class: "ti-table-wrapper" }, xe = { class: "ti-table" }, qe = /* @__PURE__ */ F({
995
+ }, Pe = { class: "ti-table-wrapper" }, Me = { class: "ti-table" }, Oe = /* @__PURE__ */ z({
803
996
  __name: "AnswerDisplay",
804
997
  props: {
805
998
  answer: {}
806
999
  },
807
- setup(l) {
808
- const n = C(!1);
809
- function a(e) {
810
- return new Date(e).toLocaleTimeString();
1000
+ setup(c) {
1001
+ const e = E(!1);
1002
+ function t(n) {
1003
+ return new Date(n).toLocaleTimeString();
811
1004
  }
812
- return (e, t) => (p(), d("div", {
813
- class: X(["ti-answer-display", { "ti-cannot-answer": e.answer.cannotAnswer }])
1005
+ return (n, s) => (f(), h("div", {
1006
+ class: te(["ti-answer-display", { "ti-cannot-answer": n.answer.cannotAnswer }])
814
1007
  }, [
815
- m("div", he, [
816
- m("div", fe, [
817
- e.answer.cannotAnswer ? (p(), d("span", we, "⚠️")) : (p(), d("span", ge, "💡"))
1008
+ m("div", be, [
1009
+ m("div", Ae, [
1010
+ n.answer.cannotAnswer ? (f(), h("span", ke, "⚠️")) : (f(), h("span", $e, "💡"))
818
1011
  ]),
819
- m("div", ye, [
820
- m("div", ve, " Confidence: " + v(Math.round(e.answer.confidence * 100)) + "% ", 1),
821
- m("div", be, v(a(e.answer.timestamp)), 1)
1012
+ m("div", Ce, [
1013
+ m("div", _e, " Confidence: " + A(Math.round(n.answer.confidence * 100)) + "% ", 1),
1014
+ m("div", qe, A(t(n.answer.timestamp)), 1)
822
1015
  ])
823
1016
  ]),
824
- m("div", Ae, v(e.answer.text), 1),
825
- e.answer.isApproximate ? (p(), d("div", _e, " ℹ️ This answer is based on sampled data and may be approximate. ")) : T("", !0),
826
- e.answer.reason && e.answer.cannotAnswer ? (p(), d("div", $e, [
827
- t[1] || (t[1] = m("strong", null, "Reason:", -1)),
828
- Z(" " + v(e.answer.reason), 1)
829
- ])) : T("", !0),
830
- e.answer.supportingData ? (p(), d("div", ke, [
1017
+ m("div", Ee, A(n.answer.text), 1),
1018
+ n.answer.isApproximate ? (f(), h("div", Se, " ℹ️ This answer is based on sampled data and may be approximate. ")) : S("", !0),
1019
+ n.answer.reason && n.answer.cannotAnswer ? (f(), h("div", De, [
1020
+ s[1] || (s[1] = m("strong", null, "Reason:", -1)),
1021
+ ne(" " + A(n.answer.reason), 1)
1022
+ ])) : S("", !0),
1023
+ n.answer.supportingData ? (f(), h("div", Te, [
831
1024
  m("button", {
832
1025
  class: "ti-toggle-btn",
833
- onClick: t[0] || (t[0] = (s) => n.value = !n.value)
834
- }, v(n.value ? "▼" : "▶") + " Supporting Data ", 1),
835
- n.value ? (p(), d("div", Se, [
836
- e.answer.supportingData.aggregates ? (p(), d("div", De, [
837
- t[2] || (t[2] = m("h4", null, "Aggregates:", -1)),
838
- m("pre", null, v(JSON.stringify(e.answer.supportingData.aggregates, null, 2)), 1)
839
- ])) : T("", !0),
840
- e.answer.supportingData.rows && e.answer.supportingData.rows.length > 0 ? (p(), d("div", Ce, [
841
- m("h4", null, "Sample Rows (" + v(e.answer.supportingData.rows.length) + "):", 1),
842
- m("div", Te, [
843
- m("table", xe, [
1026
+ onClick: s[0] || (s[0] = (a) => e.value = !e.value)
1027
+ }, A(e.value ? "▼" : "▶") + " Supporting Data ", 1),
1028
+ e.value ? (f(), h("div", xe, [
1029
+ n.answer.supportingData.aggregates ? (f(), h("div", Ie, [
1030
+ s[2] || (s[2] = m("h4", null, "Aggregates:", -1)),
1031
+ m("pre", null, A(JSON.stringify(n.answer.supportingData.aggregates, null, 2)), 1)
1032
+ ])) : S("", !0),
1033
+ n.answer.supportingData.rows && n.answer.supportingData.rows.length > 0 ? (f(), h("div", Ne, [
1034
+ m("h4", null, "Sample Rows (" + A(n.answer.supportingData.rows.length) + "):", 1),
1035
+ m("div", Pe, [
1036
+ m("table", Me, [
844
1037
  m("thead", null, [
845
1038
  m("tr", null, [
846
- (p(!0), d(O, null, Q(Object.keys(e.answer.supportingData.rows[0]), (s, r) => (p(), d("th", { key: r }, v(s), 1))), 128))
1039
+ (f(!0), h(O, null, Q(Object.keys(n.answer.supportingData.rows[0]), (a, o) => (f(), h("th", { key: o }, A(a), 1))), 128))
847
1040
  ])
848
1041
  ]),
849
1042
  m("tbody", null, [
850
- (p(!0), d(O, null, Q(e.answer.supportingData.rows.slice(0, 5), (s, r) => (p(), d("tr", { key: r }, [
851
- (p(!0), d(O, null, Q(Object.keys(s), (o, i) => (p(), d("td", { key: i }, v(s[o]), 1))), 128))
1043
+ (f(!0), h(O, null, Q(n.answer.supportingData.rows.slice(0, 5), (a, o) => (f(), h("tr", { key: o }, [
1044
+ (f(!0), h(O, null, Q(Object.keys(a), (r, i) => (f(), h("td", { key: i }, A(a[r]), 1))), 128))
852
1045
  ]))), 128))
853
1046
  ])
854
1047
  ])
855
1048
  ])
856
- ])) : T("", !0)
857
- ])) : T("", !0)
858
- ])) : T("", !0)
1049
+ ])) : S("", !0)
1050
+ ])) : S("", !0)
1051
+ ])) : S("", !0)
859
1052
  ], 2));
860
1053
  }
861
- }), Re = /* @__PURE__ */ V(qe, [["__scopeId", "data-v-d1aaae1d"]]), Ee = { class: "ti-question-history" }, Ie = { class: "ti-history-header" }, Ne = {
1054
+ }), Xe = /* @__PURE__ */ F(Oe, [["__scopeId", "data-v-d1aaae1d"]]), Qe = { class: "ti-question-history" }, je = { class: "ti-history-header" }, ze = {
862
1055
  key: 0,
863
1056
  class: "ti-empty-state"
864
- }, Me = {
1057
+ }, Fe = {
865
1058
  key: 1,
866
1059
  class: "ti-history-list"
867
- }, Oe = ["onClick"], Qe = { class: "ti-question-header" }, ze = { class: "ti-question-number" }, Fe = { class: "ti-question-time" }, Ve = { class: "ti-question-text" }, je = {
1060
+ }, Ve = ["onClick"], Re = { class: "ti-question-header" }, He = { class: "ti-question-number" }, Le = { class: "ti-question-time" }, Be = { class: "ti-question-text" }, Je = {
868
1061
  key: 0,
869
1062
  class: "ti-question-context"
870
- }, Le = /* @__PURE__ */ F({
1063
+ }, Ue = /* @__PURE__ */ z({
871
1064
  __name: "QuestionHistory",
872
1065
  props: {
873
1066
  questions: {}
874
1067
  },
875
1068
  emits: ["clear", "select"],
876
- setup(l, { emit: n }) {
877
- const a = l, e = ee(() => [...a.questions].reverse());
878
- function t(s) {
879
- const r = new Date(s), i = (/* @__PURE__ */ new Date()).getTime() - r.getTime(), u = Math.floor(i / 6e4), g = Math.floor(i / 36e5), h = Math.floor(i / 864e5);
880
- return u < 1 ? "Just now" : u < 60 ? `${u}m ago` : g < 24 ? `${g}h ago` : `${h}d ago`;
1069
+ setup(c, { emit: e }) {
1070
+ const t = c, n = se(() => [...t.questions].reverse());
1071
+ function s(a) {
1072
+ const o = new Date(a), i = (/* @__PURE__ */ new Date()).getTime() - o.getTime(), l = Math.floor(i / 6e4), g = Math.floor(i / 36e5), p = Math.floor(i / 864e5);
1073
+ return l < 1 ? "Just now" : l < 60 ? `${l}m ago` : g < 24 ? `${g}h ago` : `${p}d ago`;
881
1074
  }
882
- return (s, r) => (p(), d("div", Ee, [
883
- m("div", Ie, [
884
- r[1] || (r[1] = m("h3", null, "Question History", -1)),
885
- s.questions.length > 0 ? (p(), d("button", {
1075
+ return (a, o) => (f(), h("div", Qe, [
1076
+ m("div", je, [
1077
+ o[1] || (o[1] = m("h3", null, "Question History", -1)),
1078
+ a.questions.length > 0 ? (f(), h("button", {
886
1079
  key: 0,
887
1080
  class: "ti-clear-btn",
888
- onClick: r[0] || (r[0] = (o) => s.$emit("clear"))
889
- }, " Clear History ")) : T("", !0)
1081
+ onClick: o[0] || (o[0] = (r) => a.$emit("clear"))
1082
+ }, " Clear History ")) : S("", !0)
890
1083
  ]),
891
- s.questions.length === 0 ? (p(), d("div", Ne, r[2] || (r[2] = [
1084
+ a.questions.length === 0 ? (f(), h("div", ze, o[2] || (o[2] = [
892
1085
  m("div", { class: "ti-empty-icon" }, "💬", -1),
893
1086
  m("p", null, "No questions asked yet", -1),
894
1087
  m("p", { class: "ti-empty-hint" }, "Ask a question about your data to get started", -1)
895
- ]))) : (p(), d("div", Me, [
896
- (p(!0), d(O, null, Q(e.value, (o, i) => (p(), d("div", {
897
- key: o.id,
1088
+ ]))) : (f(), h("div", Fe, [
1089
+ (f(!0), h(O, null, Q(n.value, (r, i) => (f(), h("div", {
1090
+ key: r.id,
898
1091
  class: "ti-history-item",
899
- onClick: (u) => s.$emit("select", o)
1092
+ onClick: (l) => a.$emit("select", r)
900
1093
  }, [
901
- m("div", Qe, [
902
- m("span", ze, "#" + v(s.questions.length - i), 1),
903
- m("span", Fe, v(t(o.timestamp)), 1)
1094
+ m("div", Re, [
1095
+ m("span", He, "#" + A(a.questions.length - i), 1),
1096
+ m("span", Le, A(s(r.timestamp)), 1)
904
1097
  ]),
905
- m("div", Ve, v(o.text), 1),
906
- o.context ? (p(), d("div", je, v(o.context.rowCount) + " rows ", 1)) : T("", !0)
907
- ], 8, Oe))), 128))
1098
+ m("div", Be, A(r.text), 1),
1099
+ r.context ? (f(), h("div", Je, A(r.context.rowCount) + " rows ", 1)) : S("", !0)
1100
+ ], 8, Ve))), 128))
908
1101
  ]))
909
1102
  ]));
910
1103
  }
911
- }), Je = /* @__PURE__ */ V(Le, [["__scopeId", "data-v-c66393d9"]]);
1104
+ }), Ze = /* @__PURE__ */ F(Ue, [["__scopeId", "data-v-c66393d9"]]);
912
1105
  export {
913
- Re as AnswerDisplay,
914
- P as QAEngine,
915
- Je as QuestionHistory,
916
- He as QuestionInput,
917
- oe as TabularIntelligence,
918
- H as calculateStats,
919
- te as detectAnomalies,
920
- ne as extractFromDOM,
921
- B as inferColumnType,
922
- I as inferSchema,
923
- se as normalizeVueData,
924
- Be as useTabularIntelligence
1106
+ Xe as AnswerDisplay,
1107
+ H as QAEngine,
1108
+ Ze as QuestionHistory,
1109
+ We as QuestionInput,
1110
+ de as TabularIntelligence,
1111
+ B as calculateStats,
1112
+ ue as convertToTabular,
1113
+ ae as detectAnomalies,
1114
+ U as executeAPIRequest,
1115
+ Ge as executeMultipleRequests,
1116
+ re as extractFromDOM,
1117
+ L as inferColumnType,
1118
+ N as inferSchema,
1119
+ oe as normalizeVueData,
1120
+ ce as parsePostmanCollection,
1121
+ I as replaceVariables,
1122
+ Ye as useTabularIntelligence
925
1123
  };
926
1124
  //# sourceMappingURL=index.mjs.map