react-semaphor 0.0.690 → 0.0.691

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.
@@ -1,5 +1,5 @@
1
1
  import { jsxs as a, jsx as e, Fragment as W } from "react/jsx-runtime";
2
- import { c as oe, a1 as fs, u as H, a2 as kt, a3 as Dt, B as _, a4 as Tt, a5 as Ke, a6 as gs, _ as pt, a7 as Je, a8 as nt, a9 as Ql, aa as $e, ab as st, ac as lt, ad as rt, ae as ft, af as U, ag as Oe, ah as Mt, I as ye, ai as vs, aj as ia, ak as $i, al as Cl, am as xs, f as Y, an as ys, ao as Yi, ap as Zl, aq as qi, ar as Ki, as as ba, at as me, w as wl, au as Wi, av as Ji, aw as oa, ax as je, ay as de, az as De, aA as wt, aB as Ve, aC as Aa, aD as ua, aE as Ea, aF as Hi, aG as ma, aH as It, aI as Qe, aJ as Ze, aK as qa, aL as tt, aM as Ee, aN as He, aO as Ns, aP as pn, aQ as Ca, aR as Ht, aS as ha, aT as bs, aU as Cs, aV as Qi, aW as Ka, aX as ws, aY as Ss, aZ as ks, a_ as Ds, R as Lt, a$ as Xl, b0 as Zi, b1 as Ts, b2 as Wa, b3 as Ms, b4 as Is, b5 as Oa, b6 as Ra, b7 as Fa, b8 as As, b9 as Dn, ba as Es, bb as er, bc as tr, bd as Os, be as fe, bf as ge, bg as ve, bh as xe, bi as ae, bj as ar, bk as nr, bl as Xi, bm as eo, bn as _t, bo as to, bp as ao, bq as Vt, br as Bt, bs as ze, bt as dt, bu as bt, $ as O, bv as At, bw as Tn, bx as Mn, by as Rs, bz as no, bA as mt, bB as Ba, bC as Qt, bD as fn, bE as sr, bF as lr, bG as so, bH as Fs, bI as Ps, bJ as Ls, bK as zs, bL as _s, bM as Vs, bN as Bs, bO as Us, bP as cn, bQ as In, bR as Ja, a0 as le, bS as lo, bT as St, bU as ro, o as pa, bV as rr, bW as We, bX as io, bY as js, bZ as gn, b_ as Gs, b$ as dn, c0 as Ha, c1 as $s, c2 as oo, c3 as co, c4 as uo, c5 as mo, c6 as ho, v as po, c7 as vn, c8 as ir, c9 as fo, ca as go, cb as as, cc as vo, cd as un, ce as mn, cf as na, cg as xo, x as or, W as Zt, ch as Ua, ci as Yt, cj as yo, A as wa, z as qt, G as Kt, ck as ns, y as Ot, cl as An, Q as Sl, K as cr, J as dr, T as No, cm as kl, cn as Pa, co as La, cp as Qa, cq as ot, cr as Za, cs as bo, ct as xn, cu as Jt, cv as ur, cw as En, cx as Ys, cy as ht, cz as Te, cA as Me, cB as Ie, cC as Sa, cD as qs, cE as Ks, cF as Xa, g as Xt, cG as Dl, cH as Co, cI as ss, cJ as mr, cK as Ws, cL as hr, cM as ja, cN as Tl, cO as wo, cP as So, cQ as ko, cR as pr, cS as Do, cT as To, cU as fr, cV as Mo, cW as On, cX as Io, cY as Ao, cZ as ls, c_ as Rt, c$ as qe, d0 as Ft, d1 as Eo, d2 as Oo, d3 as Rn, d4 as Ro, d5 as Js, d6 as Fo, d7 as gr, d8 as Hs, d9 as Po, da as vr, db as hn, dc as xr, dd as Lo, de as zo, df as _o, dg as Qs, dh as Vo, di as Bo, dj as Ml, dk as Uo, E as en, b as Zs, dl as jo, dm as Go, dn as $o, dp as Xs, dq as Yo, dr as qo, ds as Ko, dt as yr, du as el, dv as Nr, dw as br, dx as Cr, dy as wr, dz as Sr, dA as tl, dB as al, dC as kr, dD as Dr, dE as Tr, dF as nl, dG as Fn, dH as Pn, dI as Wo, P as Ut, e as jt, dJ as Jo, dK as aa, dL as Ho, dM as Qo, dN as Zo, dO as Xo, dP as ec, dQ as tc, dR as Mr, dS as ut, dT as Ga, dU as yn, dV as Wt, h as ea, dW as ac, dX as nc, dY as sc, dZ as lc, d_ as rc, d$ as Ir, e0 as ic, i as Ln, j as zn, k as _n, l as Vn, m as ya, n as tn, e1 as oc, e2 as ct, e3 as nn, e4 as Il, e5 as cc, e6 as Al, e7 as dc, e8 as uc, e9 as mc, ea as hc, eb as sl, ec as ll, ed as zt, ee as pc, ef as Bn, eg as Ar, eh as fc, ei as gc, ej as El, ek as vc, el as xc, em as yc, en as Nc, eo as bc, O as Ol, ep as Rl, eq as Cc, er as wc, es as Er, et as Sc, eu as Or, ev as kc, ew as Dc, ex as Tc, ey as Mc, ez as Ic, eA as Ac, eB as Ec, eC as Oc, eD as Rc, eE as Fc, eF as Pc, eG as Lc, eH as zc, eI as _c, eJ as Vc, eK as Bc, eL as Rr, eM as qn, eN as rl, eO as Uc, eP as jc, eQ as Gc, eR as ka, eS as $c, eT as Fr, eU as rs, eV as Yc, eW as qc, eX as Kc, eY as is, eZ as os, e_ as Nn, e$ as Pr, f0 as ca, f1 as Da, f2 as Wc, f3 as Jc, f4 as Hc, f5 as Qc, f6 as Zc, f7 as Xc, f8 as ed, f9 as td, fa as ad, fb as Kn, fc as nd, fd as sd, fe as ld, F as Lr, ff as rd, fg as id, fh as od, fi as zr, fj as _r, fk as cd, fl as Vr, fm as dd, fn as ud, fo as md, fp as hd, fq as pd, S as fd, fr as gd, U as vd, fs as xd, C as yd } from "./index--nYl92ic.js";
2
+ import { c as oe, a1 as fs, u as H, a2 as kt, a3 as Dt, B as _, a4 as Tt, a5 as Ke, a6 as gs, _ as pt, a7 as Je, a8 as nt, a9 as Ql, aa as $e, ab as st, ac as lt, ad as rt, ae as ft, af as U, ag as Oe, ah as Mt, I as ye, ai as vs, aj as ia, ak as $i, al as Cl, am as xs, f as Y, an as ys, ao as Yi, ap as Zl, aq as qi, ar as Ki, as as ba, at as me, w as wl, au as Wi, av as Ji, aw as oa, ax as je, ay as de, az as De, aA as wt, aB as Ve, aC as Aa, aD as ua, aE as Ea, aF as Hi, aG as ma, aH as It, aI as Qe, aJ as Ze, aK as qa, aL as tt, aM as Ee, aN as He, aO as Ns, aP as pn, aQ as Ca, aR as Ht, aS as ha, aT as bs, aU as Cs, aV as Qi, aW as Ka, aX as ws, aY as Ss, aZ as ks, a_ as Ds, R as Lt, a$ as Xl, b0 as Zi, b1 as Ts, b2 as Wa, b3 as Ms, b4 as Is, b5 as Oa, b6 as Ra, b7 as Fa, b8 as As, b9 as Dn, ba as Es, bb as er, bc as tr, bd as Os, be as fe, bf as ge, bg as ve, bh as xe, bi as ae, bj as ar, bk as nr, bl as Xi, bm as eo, bn as _t, bo as to, bp as ao, bq as Vt, br as Bt, bs as ze, bt as dt, bu as bt, $ as O, bv as At, bw as Tn, bx as Mn, by as Rs, bz as no, bA as mt, bB as Ba, bC as Qt, bD as fn, bE as sr, bF as lr, bG as so, bH as Fs, bI as Ps, bJ as Ls, bK as zs, bL as _s, bM as Vs, bN as Bs, bO as Us, bP as cn, bQ as In, bR as Ja, a0 as le, bS as lo, bT as St, bU as ro, o as pa, bV as rr, bW as We, bX as io, bY as js, bZ as gn, b_ as Gs, b$ as dn, c0 as Ha, c1 as $s, c2 as oo, c3 as co, c4 as uo, c5 as mo, c6 as ho, v as po, c7 as vn, c8 as ir, c9 as fo, ca as go, cb as as, cc as vo, cd as un, ce as mn, cf as na, cg as xo, x as or, W as Zt, ch as Ua, ci as Yt, cj as yo, A as wa, z as qt, G as Kt, ck as ns, y as Ot, cl as An, Q as Sl, K as cr, J as dr, T as No, cm as kl, cn as Pa, co as La, cp as Qa, cq as ot, cr as Za, cs as bo, ct as xn, cu as Jt, cv as ur, cw as En, cx as Ys, cy as ht, cz as Te, cA as Me, cB as Ie, cC as Sa, cD as qs, cE as Ks, cF as Xa, g as Xt, cG as Dl, cH as Co, cI as ss, cJ as mr, cK as Ws, cL as hr, cM as ja, cN as Tl, cO as wo, cP as So, cQ as ko, cR as pr, cS as Do, cT as To, cU as fr, cV as Mo, cW as On, cX as Io, cY as Ao, cZ as ls, c_ as Rt, c$ as qe, d0 as Ft, d1 as Eo, d2 as Oo, d3 as Rn, d4 as Ro, d5 as Js, d6 as Fo, d7 as gr, d8 as Hs, d9 as Po, da as vr, db as hn, dc as xr, dd as Lo, de as zo, df as _o, dg as Qs, dh as Vo, di as Bo, dj as Ml, dk as Uo, E as en, b as Zs, dl as jo, dm as Go, dn as $o, dp as Xs, dq as Yo, dr as qo, ds as Ko, dt as yr, du as el, dv as Nr, dw as br, dx as Cr, dy as wr, dz as Sr, dA as tl, dB as al, dC as kr, dD as Dr, dE as Tr, dF as nl, dG as Fn, dH as Pn, dI as Wo, P as Ut, e as jt, dJ as Jo, dK as aa, dL as Ho, dM as Qo, dN as Zo, dO as Xo, dP as ec, dQ as tc, dR as Mr, dS as ut, dT as Ga, dU as yn, dV as Wt, h as ea, dW as ac, dX as nc, dY as sc, dZ as lc, d_ as rc, d$ as Ir, e0 as ic, i as Ln, j as zn, k as _n, l as Vn, m as ya, n as tn, e1 as oc, e2 as ct, e3 as nn, e4 as Il, e5 as cc, e6 as Al, e7 as dc, e8 as uc, e9 as mc, ea as hc, eb as sl, ec as ll, ed as zt, ee as pc, ef as Bn, eg as Ar, eh as fc, ei as gc, ej as El, ek as vc, el as xc, em as yc, en as Nc, eo as bc, O as Ol, ep as Rl, eq as Cc, er as wc, es as Er, et as Sc, eu as Or, ev as kc, ew as Dc, ex as Tc, ey as Mc, ez as Ic, eA as Ac, eB as Ec, eC as Oc, eD as Rc, eE as Fc, eF as Pc, eG as Lc, eH as zc, eI as _c, eJ as Vc, eK as Bc, eL as Rr, eM as qn, eN as rl, eO as Uc, eP as jc, eQ as Gc, eR as ka, eS as $c, eT as Fr, eU as rs, eV as Yc, eW as qc, eX as Kc, eY as is, eZ as os, e_ as Nn, e$ as Pr, f0 as ca, f1 as Da, f2 as Wc, f3 as Jc, f4 as Hc, f5 as Qc, f6 as Zc, f7 as Xc, f8 as ed, f9 as td, fa as ad, fb as Kn, fc as nd, fd as sd, fe as ld, F as Lr, ff as rd, fg as id, fh as od, fi as zr, fj as _r, fk as cd, fl as Vr, fm as dd, fn as ud, fo as md, fp as hd, fq as pd, S as fd, fr as gd, U as vd, fs as xd, C as yd } from "./index-BH94YTiC.js";
3
3
  import * as cs from "react";
4
4
  import Ge, { useState as V, useRef as xt, useEffect as be, useMemo as _e, useCallback as we, useContext as il, Suspense as Br } from "react";
5
5
  import { createPortal as Nd } from "react-dom";
@@ -8775,7 +8775,7 @@ function hi({
8775
8775
  onClick: () => l(!0),
8776
8776
  children: [
8777
8777
  /* @__PURE__ */ e(Jt, { className: "mr-2 h-3.5 w-3.5" }),
8778
- "Add Data"
8778
+ "Choose Dataset"
8779
8779
  ]
8780
8780
  }
8781
8781
  ) }),
@@ -1,4 +1,4 @@
1
- "use strict";const e=require("react/jsx-runtime"),s=require("./index-W0Unjlcm.js"),I=require("react"),ia=require("react-dom");function ca(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(n,a,r.get?r:{enumerable:!0,get:()=>t[a]})}}return n.default=t,Object.freeze(n)}const js=ca(I);/**
1
+ "use strict";const e=require("react/jsx-runtime"),s=require("./index-DRvSuKSw.js"),I=require("react"),ia=require("react-dom");function ca(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(n,a,r.get?r:{enumerable:!0,get:()=>t[a]})}}return n.default=t,Object.freeze(n)}const js=ca(I);/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -294,7 +294,7 @@ ${y.joinType} JOIN ${O.name}
294
294
  ON ${F}`}),N},isValidConfiguration:()=>!(!a.baseEntity.name||a.joins.some(y=>!y.source.name||!y.target.name)||a.joins.some(y=>y.joinKeyGroups.some(O=>O.keys.length===0))||a.joins.some(y=>y.joinKeyGroups.some(O=>O.keys.some(w=>!w.source.name||!w.target.name||!w.operator))))}}function Zn({joinPlan:t,availableDataSources:n,onSave:a,onRemove:r,onCancel:l}){const{setCardConfig:o}=s.useEditorActions();s.useEditorStore(w=>w.card.config);const{columnGroups:i}=s.useColumns(),{joinPlan:c,expandedJoins:d,setJoinPlan:u,addJoin:m,removeJoin:h,updateJoin:x,moveJoinUp:g,moveJoinDown:b,toggleJoinExpansion:p,getAvailableSourceEntities:v,getAvailableTargetEntities:j,addJoinKeyGroup:S,updateGroupOperator:M,removeJoinKeyGroup:E,addJoinKey:C,updateJoinKey:D,removeJoinKey:f,generateSQLPreview:N,isValidConfiguration:y}=Xn({initialJoinPlan:t,availableDataSources:n}),O=w=>{const F=i.find(k=>k.entityName===w);return(F==null?void 0:F.columns)||[]};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Base Entity (FROM clause)"}),e.jsxs(s.Select,{value:c.baseEntity.name,onValueChange:w=>{const F=n.find(k=>k.name===w);u({...c,baseEntity:{connectionId:(F==null?void 0:F.connectionId)||"",connectionType:(F==null?void 0:F.connectionType)||"none",type:(F==null?void 0:F.type)||"table",name:w,database:F==null?void 0:F.database,schema:F==null?void 0:F.schema}})},children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select base entity..."})}),e.jsx(s.SelectContent,{children:n.map(w=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:w.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:w.type}),w.name,e.jsx(s.Badge,{variant:"outline",className:"text-xs text-green-600",children:"BASE"})]})},w.name))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This entity will be used as the base table in the FROM clause of the SQL query."})]}),e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"Join SQL Preview"}),e.jsx("code",{className:"block whitespace-pre-wrap break-all text-xs",children:N()})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(s.Label,{children:["Joins Configuration (",c.joins.length,")"]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:m,children:[e.jsx(s.Plus,{className:"mr-1 h-4 w-4"}),"Add Join"]})})]}),c.joins.length===0?e.jsx("div",{className:"rounded-lg border border-dashed py-8 text-center text-muted-foreground",children:e.jsx("p",{children:"No joins configured. Add a join to connect multiple data sources."})}):e.jsx("div",{className:"max-h-[300px] space-y-4 overflow-y-auto",children:c.joins.map(w=>{const F=n.find(A=>A.name===w.source.name),k=n.find(A=>A.name===w.target.name),T=d.has(w.id);return e.jsxs(s.Card,{className:"border",children:[e.jsx(s.CardHeader,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{children:w.sequence}),e.jsxs(s.CardTitle,{className:"text-sm",children:["Join ",w.sequence,F&&k&&e.jsxs("span",{className:"ml-2 font-normal text-gray-600",children:["(",F.name," → ",k.name,")"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>g(w.id),disabled:w.sequence===1,children:e.jsx(s.ArrowUp,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>b(w.id),disabled:w.sequence===c.joins.length,children:e.jsx(s.ArrowDown,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>p(w.id),children:T?e.jsx(s.ChevronUp,{className:"h-4 w-4"}):e.jsx(s.ChevronDown,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>h(w.id),children:e.jsx(s.X,{className:"h-4 w-4"})})]})]})}),T&&e.jsxs(s.CardContent,{className:"space-y-4 pb-6",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Source"}),e.jsxs(s.Select,{value:w.source.name,onValueChange:A=>{const R=n.find(L=>L.name===A);x(w.id,{source:{connectionId:(R==null?void 0:R.connectionId)||"",connectionType:(R==null?void 0:R.connectionType)||"none",type:(R==null?void 0:R.type)||"table",name:A,database:R==null?void 0:R.database,schema:R==null?void 0:R.schema}})},children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select source..."})}),e.jsx(s.SelectContent,{children:v(w.id).map(A=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:A.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:A.type}),A.name]})},A.name))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Join Type"}),e.jsxs(s.Select,{value:w.joinType,onValueChange:A=>x(w.id,{joinType:A}),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"INNER",children:"INNER JOIN"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"LEFT",children:"LEFT JOIN"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"RIGHT",children:"RIGHT JOIN"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"FULL",children:"FULL JOIN"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Target"}),e.jsxs(s.Select,{value:w.target.name,onValueChange:A=>{const R=n.find(L=>L.name===A);x(w.id,{target:{connectionId:(R==null?void 0:R.connectionId)||"",connectionType:(R==null?void 0:R.connectionType)||"none",type:(R==null?void 0:R.type)||"table",name:A,database:R==null?void 0:R.database,schema:R==null?void 0:R.schema}})},disabled:!w.source.name,children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select target..."})}),e.jsx(s.SelectContent,{children:w.source.name?j(w.source.name).map(A=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:A.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:A.type}),A.name,A.name===w.source.name&&e.jsx(s.Badge,{variant:"outline",className:"text-xs text-yellow-600",children:"(Self-join)"})]})},A.name)):[]})]})]})]}),w.source.name&&w.target.name&&F&&k&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{children:"Join Conditions"}),e.jsxs(s.Button,{type:"button",variant:"outline",size:"sm",onClick:()=>S(w.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Condition Group"]})]}),w.joinKeyGroups.length===0?e.jsx("div",{className:"rounded-md border p-3 text-center text-sm text-gray-500",children:"No join conditions defined. Add condition groups to specify how data sources should be joined."}):e.jsx("div",{className:"space-y-4",children:w.joinKeyGroups.map((A,R)=>e.jsxs("div",{className:"space-y-3 rounded-md border p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Label,{children:["Group ",R+1]}),R>0&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-gray-100 px-2 py-1",children:[e.jsx(s.Label,{className:"text-xs font-normal",children:"Join with:"}),e.jsx("span",{className:"text-sm font-medium",children:"OR"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Select,{value:A.operator,onValueChange:L=>M(w.id,R,L),children:[e.jsx(s.SelectTrigger,{className:"w-[100px]",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"AND",children:"AND"}),e.jsx(s.SelectItem,{value:"OR",children:"OR"})]})]}),e.jsx(s.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>E(w.id,R),children:e.jsx(s.Trash2,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[A.keys.length===0?e.jsx("div",{className:"rounded-md border border-dashed p-3 text-center text-sm text-gray-500",children:"No conditions in this group. Add conditions to specify join criteria."}):e.jsx("div",{className:"space-y-2",children:A.keys.map((L,B)=>e.jsxs("div",{className:"flex flex-col items-start gap-2 rounded-md border p-2 sm:flex-row sm:items-center",children:[B>0&&e.jsx("div",{className:"self-center rounded-md bg-gray-100 px-2 py-1 text-xs font-medium",children:A.operator}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:flex-1",children:e.jsxs(s.Select,{value:L.source.name,onValueChange:P=>D(w.id,R,B,"sourceColumnName",P),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Source column"})}),e.jsx(s.SelectContent,{children:O(w.source.name).map(P=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:P.name,children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("span",{children:P.name}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 text-xs",children:P.dataType})]})},P.name))})]})}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:w-20",children:e.jsxs(s.Select,{value:L.operator,onValueChange:P=>D(w.id,R,B,"operator",P),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"=",children:"="}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"<",children:"<"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:">",children:">"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"<=",children:"<="}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:">=",children:">="})]})]})}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:flex-1",children:e.jsxs(s.Select,{value:L.target.name,onValueChange:P=>D(w.id,R,B,"targetColumnName",P),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Target column"})}),e.jsx(s.SelectContent,{children:O(w.target.name).map(P=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:P.name,children:e.jsxs("div",{className:"flex w-full items-center justify-between hover:bg-muted",children:[e.jsx("span",{children:P.name}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 text-xs",children:P.dataType})]})},P.name))})]})}),e.jsx(s.Button,{type:"button",variant:"ghost",size:"sm",className:"self-center",onClick:()=>f(w.id,R,B),children:e.jsx(s.X,{className:"size-3.5"})})]},L.id||B))}),e.jsxs(s.Button,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:()=>C(w.id,R),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Condition"]})]})]},A.id))})]})]})]},w.id)})})]}),e.jsxs("div",{className:"flex justify-end gap-2 border-t pt-4",children:[e.jsx(s.Button,{variant:"outline",onClick:()=>{r(),l()},children:"Remove All"}),e.jsx(s.Button,{variant:"outline",onClick:l,children:"Cancel"}),e.jsx(s.Button,{onClick:()=>a(c),disabled:!y(),children:"Save"})]})]})}function Gs({children:t,open:n,onOpenChange:a,joinPlan:r,availableDataSources:l,onRemove:o,onSave:i,onCancel:c}){return e.jsxs(s.Dialog,{open:n,onOpenChange:a,children:[e.jsxs(s.DialogContent,{className:"max-w-4xl",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Join Configuration"}),e.jsx(s.DialogDescription,{children:"Configure the join between the two entities to combine the fields."})]}),e.jsx(Zn,{joinPlan:r,availableDataSources:l,onSave:i,onCancel:c,onRemove:o})]}),t]})}function er({joins:t,baseEntityId:n,availableDataSources:a,generateSQLPreview:r}){return e.jsxs("div",{className:"divide-y divide-border",children:[t.length>0&&e.jsxs("div",{className:"p-4",children:[e.jsx("h3",{className:"mb-3 text-left font-semibold",children:"Join Chain"}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:(()=>{const l=[...t].sort((i,c)=>i.sequence-c.sequence),o=a.find(i=>i.name===n);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1 rounded-md border bg-muted px-2 py-1",children:[e.jsx(s.Badge,{variant:"secondary",className:"text-xs",children:o==null?void 0:o.type}),e.jsx("span",{className:"text-xs font-medium",children:o==null?void 0:o.name}),e.jsx(s.Badge,{variant:"outline",className:"text-xs text-green-600",children:"BASE"})]}),l.map(i=>{const c=a.find(d=>d.name===i.target.name);return e.jsxs("div",{className:"flex items-center",children:[e.jsxs("div",{className:"mx-1 flex items-center gap-1",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:i.joinType}),e.jsx("span",{className:"text-muted-foreground",children:"→"})]}),e.jsxs("div",{className:"flex items-center gap-1 rounded-md border bg-muted px-2 py-1",children:[e.jsx(s.Badge,{variant:"secondary",className:"text-xs",children:c==null?void 0:c.type}),e.jsx("span",{className:"text-xs font-medium",children:c==null?void 0:c.name})]})]},i.id)})]})})()})]}),e.jsxs("div",{className:"p-4",children:[e.jsxs("h3",{className:"mb-3 text-left text-sm font-medium",children:["Configured Joins (",t.length,")"]}),e.jsx("div",{className:"space-y-2",children:[...t].sort((l,o)=>l.sequence-o.sequence).map((l,o)=>{const i=a.find(d=>d.name===l.source.name),c=a.find(d=>d.name===l.target.name);return e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-muted p-2 text-left",children:[e.jsx(s.Badge,{variant:"secondary",className:"shrink-0 text-xs",children:o+1}),e.jsx(s.Badge,{variant:"outline",className:"shrink-0 text-xs",children:l.joinType}),e.jsxs("span",{className:"text-xs font-medium",children:[i==null?void 0:i.name," → ",c==null?void 0:c.name]}),e.jsxs(s.Badge,{variant:"outline",className:"ml-auto text-xs",children:[l.joinKeyGroups.reduce((d,u)=>d+u.keys.length,0)," ","condition",l.joinKeyGroups.reduce((d,u)=>d+u.keys.length,0)>1?"s":""]})]},l.id)})})]}),e.jsxs("div",{className:"p-4",children:[e.jsx("h3",{className:"mb-3 text-left text-sm font-medium",children:"SQL Query"}),e.jsx("div",{className:"overflow-x-auto rounded-md border bg-muted p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap break-all text-left font-mono text-xs text-muted-foreground",children:r()})})]})]})}function sr(){var m,h;const t=s.useEditorStore(x=>x.card),n=s.useEditorStore(x=>x.actions.updateCardConfig),a=((m=t==null?void 0:t.config)==null?void 0:m.joinPlan)||{baseEntity:{type:"table",name:"",database:"",schema:"",connectionId:"",connectionType:"none",dialect:"none"},joins:[]},[r,l]=I.useState(!1),o=((h=t==null?void 0:t.dataSource)==null?void 0:h.selectedEntities)||[],i=x=>{n(t.id,{...t==null?void 0:t.config,joinPlan:x}),l(!1)},c=()=>{n(t.id,{...t==null?void 0:t.config,joinPlan:void 0})},d=()=>{l(!1)},u=()=>{const x=[...a.joins].sort((p,v)=>p.sequence-v.sequence),g=a.baseEntity;if(!g.name)return"SELECT * FROM table -- Please select a base entity";let b=`SELECT *
295
295
  FROM ${g.name}`;return x.forEach(p=>{const v=o.find(M=>M.name===p.target.name);if(!v)return;const j=p.joinKeyGroups.filter(M=>M.keys&&M.keys.length>0).map(M=>{const E=M.keys.filter(C=>{var D,f,N,y;return((D=C.source)==null?void 0:D.name)&&((f=C.target)==null?void 0:f.name)&&((N=C.source)==null?void 0:N.entityName)&&((y=C.target)==null?void 0:y.entityName)}).map(C=>`${C.source.entityName}.${C.source.name} ${C.operator} ${C.target.entityName}.${C.target.name}`);return E.length>1?`(${E.join(` ${M.operator} `)})`:E[0]}).filter(Boolean),S=j.length>1?j.join(" OR "):j[0]||"condition_here";b+=`
296
296
  ${p.joinType} JOIN ${v.name}
297
- ON ${S}`}),b};return o.length<2?null:e.jsx(e.Fragment,{children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[a.joins.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-6 text-xs font-semibold",onClick:()=>l(!0),children:[e.jsx(s.Link,{className:s.cn("mr-1 h-3 w-3",{"text-blue-500":a.joins.length>0,"text-gray-500":a.joins.length===0})}),"Join",a.joins.length>1?"s":""," (",a.joins.length,")"]})}),e.jsx(s.TooltipContent,{side:"right",className:"max-w-md overflow-hidden p-0",children:e.jsx(er,{joins:a.joins,baseEntityId:a.baseEntity.name,availableDataSources:o,generateSQLPreview:u})})]})}),e.jsx(Gs,{open:r,onOpenChange:l,joinPlan:a,availableDataSources:o,onSave:i,onCancel:d,onRemove:c,children:e.jsx("div",{})})]}),a.joins.length===0&&e.jsx(Gs,{open:r,onOpenChange:l,joinPlan:a,availableDataSources:o,onSave:i,onCancel:d,onRemove:c,children:e.jsxs(s.Button,{onClick:()=>l(!0),variant:"outline",size:"sm",className:"w-full",children:[e.jsx(s.Link,{className:"mr-3 size-4"}),"Configure Joins"]})})]})})})}function tr({open:t,onOpenChange:n}){const[a,r]=I.useState([]),{updateDataSource:l}=s.useEditorActions(),o=s.useDashboardStore(p=>p.dashboard.aiContext),i=(o==null?void 0:o.selectedEntities)||[];I.useEffect(()=>{t&&r([])},[t]);const c=p=>{r(v=>v.some(S=>S.name===p.name&&S.type===p.type)?v.filter(S=>!(S.name===p.name&&S.type===p.type)):[...v,p])},d=()=>{r([...i])},u=()=>{r([])},m=()=>{if(a.length===0)return;const p=a[0],v=p.connectionId||"",j=p.connectionType||"",M=a.some(C=>C.type==="dataset")?"semanticDomain":"database";l({connectionId:v,connectionType:j,mode:M,selectedEntities:a}),n(!1)},h=p=>{switch(p.type){case"table":return e.jsx(s.Table,{className:"h-4 w-4"});case"view":return e.jsx(Wa,{className:"h-4 w-4"});case"model":return e.jsx(ya,{className:"h-4 w-4"});case"dataset":return e.jsx(s.Database,{className:"h-4 w-4"});case"file":case"url":case"upload":return e.jsx(s.FileText,{className:"h-4 w-4"});default:return e.jsx(s.Database,{className:"h-4 w-4"})}},x=p=>"label"in p&&p.label?p.label:p.name,g=p=>{if("description"in p&&p.description)return p.description;const v=[];return p.database&&v.push(p.database),p.schema&&v.push(p.schema),p.name&&v.push(p.name),v.join(".")},b=p=>a.some(v=>v.name===p.name&&v.type===p.type);return i.length===0?e.jsx(s.Dialog,{open:t,onOpenChange:n,children:e.jsxs(s.DialogContent,{className:"max-w-md",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"No Data Available"}),e.jsx(s.DialogDescription,{children:"No entities are currently available in the AI context. Please add some data sources to the dashboard first."})]}),e.jsx(s.DialogFooter,{children:e.jsx(s.Button,{onClick:()=>n(!1),children:"Close"})})]})}):e.jsx(s.Dialog,{open:t,onOpenChange:n,children:e.jsxs(s.DialogContent,{className:"flex max-w-2xl flex-col",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Select Data to Analyze"}),e.jsx(s.DialogDescription,{children:"Choose entities from the dashboard's context"})]}),e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"outline",size:"sm",onClick:d,disabled:a.length===i.length,children:"Select All"}),e.jsx(s.Button,{variant:"outline",size:"sm",onClick:u,disabled:a.length===0,children:"Clear All"})]}),e.jsxs(s.Badge,{variant:"secondary",children:[a.length," of ",i.length," selected"]})]}),e.jsx(s.Separator,{}),e.jsx(s.ScrollArea,{className:"h-64",children:e.jsx("div",{className:"space-y-2",children:i.map((p,v)=>e.jsxs("div",{className:s.cn("flex items-center gap-3 rounded-lg border p-3 transition-colors hover:bg-muted/50",b(p)&&"border-primary bg-primary/5"),children:[e.jsx(s.Checkbox,{checked:b(p),onCheckedChange:()=>c(p)}),e.jsx("div",{className:"flex items-center gap-2 text-muted-foreground",children:h(p)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-medium",children:x(p)}),e.jsx("div",{className:"truncate text-sm text-muted-foreground",children:g(p)})]}),e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:p.type})]},`${p.type}-${p.name}-${v}`))})})]}),e.jsx(s.DialogFooter,{children:e.jsx("div",{className:"flex w-full justify-between",children:e.jsxs("div",{className:"flex grow justify-end gap-2",children:[e.jsx(s.Button,{variant:"outline",onClick:()=>n(!1),children:"Cancel"}),e.jsxs(s.Button,{onClick:m,disabled:a.length===0,children:["Select"," ",a.length>0?`(${a.length})`:""]})]})})})]})})}function ar({entity:t,title:n,maxDetails:a=10}){const l=s.getEntityDetails(t).slice(0,a),o=l.find(c=>c.label==="Description"),i=l.filter(c=>c.label==="Description"?!1:!["Connection","Database","Schema"].includes(c.label));return e.jsx(s.TooltipContent,{side:"top",className:"ml-5 max-w-xs",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:n||s.getDisplayName(t)}),o&&e.jsxs("div",{className:"border-t border-border pt-2",children:[e.jsx("div",{className:"mb-1 text-xs text-muted-foreground",children:"Description:"}),e.jsx("div",{className:"text-xs leading-relaxed",children:o.value})]}),i.length>0&&e.jsx("div",{className:"space-y-0.5",children:i.map((c,d)=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsxs("span",{className:"mr-2 text-muted-foreground",children:[c.label,":"]}),e.jsx("span",{className:"font-mono",children:c.value})]},d))})]})})}function nr({entities:t}){return e.jsx(s.TooltipContent,{side:"top",className:"ml-5 max-w-xs",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-sm font-medium",children:[t.length," more entities"]}),e.jsx("div",{className:"space-y-1",children:t.map((n,a)=>{const r=s.getEntityDetails(n),l=r.find(i=>i.label==="Description"),o=r.filter(i=>i.label==="Description"?!1:!["Connection","Database","Schema"].includes(i.label)).slice(0,3);return e.jsxs("div",{className:"border-b border-border pb-1 last:border-b-0",children:[e.jsx("div",{className:"text-xs font-medium",children:s.getDisplayName(n)}),l&&e.jsxs("div",{className:"mb-1 mt-1",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Description:"}),e.jsx("div",{className:"text-xs leading-relaxed",children:l.value})]}),o.length>0&&e.jsx("div",{className:"mt-1 space-y-0.5",children:o.map((i,c)=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsxs("span",{className:"mr-2 text-muted-foreground",children:[i.label,":"]}),e.jsx("span",{className:"font-mono",children:i.value})]},c))})]},`remaining-${n.type}-${n.name}-${a}`)})})]})})}function Et(){const t=s.useEditorStore(i=>i.card.dataSource),{setSelectedConnectionId:n,setSelectedDatabaseName:a,setSelectedSchemaName:r,setSelectedTableName:l,setSelectedDatamodelId:o}=s.useEditorActions();I.useEffect(()=>{var g;if(!t)return;const{tableName:i,schemaName:c,databaseName:d,connectionId:u}=Ts(t),m=(g=t.selectedEntities)==null?void 0:g[0],x=(m==null?void 0:m.type)==="model"&&"id"in m?m.id:"";n(u||""),a(d||""),r(c||""),l(i||""),o(x)},[t,n,a,r,l,o])}function It({isVisible:t}){const n=s.useEditorStore(x=>x.isDevMode);Et();const[a,r]=I.useState(!1),[l,o]=I.useState(!1),[i,c]=I.useState(!0),d=s.useEditorStore(x=>x.card.dataSource);s.useCurrentUserInfo();const{updateDataSource:u}=s.useEditorActions(),m={connectionId:"",connectionType:"",mode:"database",selectedEntities:[]},h={...m,...d,selectedEntities:(d==null?void 0:d.selectedEntities)||[]};return e.jsxs("div",{className:s.cn("flex flex-col overflow-hidden bg-background transition-all duration-300 ease-in-out",{"w-[325px]":t,"w-0":!t}),children:[e.jsxs("div",{children:[e.jsx("div",{className:"p-4 px-6 pb-2",children:e.jsxs(s.Button,{className:"w-full bg-muted/50",variant:"outline",onClick:()=>r(!0),children:[e.jsx(s.Database,{className:"mr-2 h-3.5 w-3.5"}),"Add Data"]})}),e.jsxs("div",{className:"relative px-6",children:[e.jsx("div",{className:"absolute inset-0 flex items-center px-6",children:e.jsx("div",{className:"w-full border-t border-border"})}),e.jsx("div",{className:"relative flex justify-center",children:e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>c(!i),className:"size-6 bg-background p-1 py-1 hover:bg-accent",children:i?e.jsx(s.ChevronUp,{className:"h-3.5 w-3.5"}):e.jsx(s.ChevronDown,{className:"h-3.5 w-3.5"})})})]}),e.jsxs("div",{className:`overflow-hidden px-6 ${i?"max-h-96 space-y-4":"max-h-0 py-0 opacity-0"}`,children:[h.selectedEntities.length>0&&e.jsx(s.TooltipProvider,{children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[h.selectedEntities.slice(0,3).map((x,g)=>e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Badge,{variant:"secondary",className:"group relative cursor-pointer pr-6 text-xs transition-colors hover:border-red-200 hover:bg-red-50 dark:hover:border-red-800 dark:hover:bg-red-950",children:[s.getDisplayName(x),e.jsx("button",{onClick:b=>{b.stopPropagation();const p=h.selectedEntities.filter(v=>!(v.name===x.name&&v.type===x.type));u({...m,...d,selectedEntities:p})},className:"absolute right-1 top-1/2 -translate-y-1/2 rounded-full p-0.5 hover:bg-red-100",children:e.jsx(s.X,{className:"h-2.5 w-2.5 group-hover:text-red-500"})})]})}),e.jsx(ar,{entity:x})]},`${x.type}-${x.name}-${g}`)),h.selectedEntities.length>3&&e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Badge,{variant:"outline",className:"text-xs",children:["+",h.selectedEntities.length-3," more"]})}),e.jsx(nr,{entities:h.selectedEntities.slice(3)})]})]})}),!n&&e.jsx(sr,{})]})]}),e.jsx(kt,{}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(d==null?void 0:d.selectedEntities)||[],dialogMode:"dataSource",open:a,onOpenChange:r,dataSource:h}),e.jsx(tr,{open:l,onOpenChange:o})]})}function At({error:t,errorSql:n,onSendFeedback:a,className:r,showFeedbackButton:l=!0}){const[o,i]=I.useState(!1);return e.jsx("div",{className:s.cn("rounded-lg border border-destructive/30 bg-destructive/5 p-4",r),children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(s.CircleAlert,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-destructive"}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-destructive",children:"Query Error"}),e.jsxs("div",{className:"relative rounded-md bg-background/60 p-3",children:[e.jsx(s.CopyButton,{text:t,className:"absolute right-2 top-2 h-6 w-6 z-10"}),e.jsx("div",{className:"max-h-40 overflow-auto pr-10",children:e.jsx("p",{className:"font-mono text-xs text-foreground/80 break-all",children:t})})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[n&&e.jsx(s.Collapsible,{open:o,onOpenChange:i,children:e.jsx(s.CollapsibleTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"outline",size:"sm",className:"h-8",children:o?e.jsxs(e.Fragment,{children:[e.jsx(s.ChevronUp,{className:"mr-1.5 h-3.5 w-3.5"}),"Hide Details"]}):e.jsxs(e.Fragment,{children:[e.jsx(s.ChevronDown,{className:"mr-1.5 h-3.5 w-3.5"}),"Show Details"]})})})}),l&&a&&e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-8",onClick:a,children:[e.jsx(s.MessageSquareWarning,{className:"mr-1.5 h-3.5 w-3.5"}),"Send Feedback"]})]}),n&&e.jsx(s.Collapsible,{open:o,onOpenChange:i,children:e.jsx(s.CollapsibleContent,{className:"space-y-2",children:e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Error SQL Query"}),e.jsx(s.CopyButton,{text:n,className:"h-6 w-6"})]}),e.jsx("div",{className:"rounded-md bg-background/60 p-2 max-h-80 overflow-auto",children:e.jsx(s.CodeHighlighter,{code:n,language:"sql"})})]})})})]})]})})}function Mt({sql:t,error:n,errorSql:a,onDebugWithAssistant:r}){const l=s.useEditorStore(u=>u.isDevMode),{setIsDevMode:o,setCardSql:i,setRunSql:c}=s.useEditorActions();function d(){o(!l),i(t),setTimeout(()=>{c(!0)},100)}return e.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxs("div",{className:"flex grow flex-col space-y-3",children:[e.jsxs(s.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll text-xs leading-relaxed text-foreground/80",children:[n&&e.jsx(At,{error:n,errorSql:a,showFeedbackButton:!1}),!n&&t&&e.jsx("div",{className:"flex flex-col space-y-1.5",children:e.jsx("div",{className:"",children:e.jsx(s.CodeHighlighter,{code:t,language:"sql"})})})]}),!l&&t&&!n&&e.jsxs(s.Button,{onClick:d,variant:"secondary",size:"sm",children:[e.jsx(Ca,{className:"mr-2 h-4 w-4"}),"View in SQL Editor"]}),n&&r&&e.jsxs(s.Button,{onClick:r,size:"sm",variant:"outline",children:[e.jsx(Ea,{className:"mr-2 h-4 w-4"}),"Debug with Assistant"]})]})})}function Lt({sql:t,error:n,errorSql:a,onDebugWithAssistant:r}){return e.jsxs(s.HoverCard,{openDelay:n?0:500,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"link",className:"h-5 p-0",children:n?e.jsx(ja,{className:"h-4 w-4 text-red-500"}):e.jsx(s.Info,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsx(s.HoverCardContent,{align:"start",className:"flex w-[700px]",children:e.jsx(Mt,{errorSql:a,sql:t,error:n,onDebugWithAssistant:r})})]})}function rr(t){return s.GenIcon({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"},child:[]}]})(t)}function Rt(t){const{theme:n}=s.useTheme(),a=s.useDashboardStore(p=>p.theme),r=s.useEditorStore(p=>p.frame),l=s.useEditorStore(p=>p.card),o=s.useEditorStore(p=>p.activeTabCardId),i=s.Le(),{refetch:c}=s.useDashboardCardQuery(l),{updateCardTab:d,setRunSql:u}=s.useEditorActions(),m=I.useRef(),h=I.useRef({}),x=r.cards.find(p=>p.id===o),g=I.useCallback(()=>{let p="";return t==="python"&&(p=(x==null?void 0:x.python)||s.PYTHON_DEFAULT_CODE),t==="sql"&&(p=(x==null?void 0:x.sql)||""),p},[t,x]);I.useEffect(()=>{if(o&&l.id&&l.id!==o){if(m.current&&i){const p=m.current.getModel();p&&(h.current[l.id]=p);let v=h.current[o];if(!v){const j=g();v=i.editor.createModel(j,t),h.current[o]=v}m.current.setModel(v)}d(o,l),u(!0)}},[o,l,d,i,u,t,g]),I.useEffect(()=>{if(!i)return;const p=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",v=a==="system"?p:a;i.editor.defineTheme("default",{base:v==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":v==="light"?"#ffffff":s.hslStringToHex("240 10% 10%")}}),i.editor.setTheme("default")},[n,a,i]),I.useEffect(()=>{const p=m.current;p&&i&&l&&p.addCommand(i.KeyMod.Shift|i.KeyCode.Enter,function(){return c(),!1})},[i,c,l]);function b(p,v){if(m.current=p,!h.current[l.id]){const j=p.getModel(),S=g();h.current[l.id]=j||(v==null?void 0:v.editor.createModel(S,t))||p.getModel()}p.setModel(h.current[l.id])}return{handleEditorDidMount:b}}function lr(){const t=s.useEditorStore(i=>i.card.sql),n=s.useEditorStore(i=>i.sqlGen),{setCardSql:a,setSqlGen:r}=s.useEditorActions(),{handleEditorDidMount:l}=Rt("sql");function o(i){a(i),s.isObjectEmpty(n)||r({})}return e.jsxs("div",{className:"relative h-full w-full",children:[!t&&e.jsx("div",{className:"pointer-events-none absolute left-[65px] top-3 z-10 font-mono text-sm text-muted-foreground",children:"Write your SQL here"}),e.jsx(s.Ft,{theme:"default",className:"pt-3",onChange:o,value:t||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:l})]})}function or(){const t=s.useEditorStore(l=>l.card.python),{setCardPython:n}=s.useEditorActions(),{handleEditorDidMount:a}=Rt("python");function r(l){n(l)}return e.jsx(s.Ft,{className:"pt-3",theme:"default",onChange:r,value:t||s.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"python",onMount:a})}function ir({jsonString:t}){return e.jsx(s.Ft,{theme:"default",defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:t,options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})}function cr(){const t=s.useQueryClient(),{isConsoleMode:n}=s.useDashboardPreferences(),[a,r]=I.useState(!1),[l,o]=I.useState(!1);s.useEditorStore(V=>V.frame);const i=s.useEditorStore(V=>V.card);s.useEditorStore(V=>V.isShowingVisual),s.useEditorStore(V=>V.selectedConnectionId),s.useEditorStore(V=>V.tempQueryData),s.useEditorStore(V=>V.selectedDatabaseName),s.useEditorStore(V=>V.selectedDatamodelId),s.useEditorStore(V=>V.selectedSchemaName);const c=s.useEditorStore(V=>V.showAIDialog);s.useEditorStore(V=>V.selectedTableName);const d=s.useEditorStore(V=>{var J;return(J=V==null?void 0:V.card)==null?void 0:J.sql}),u=s.useEditorStore(V=>{var J;return(J=V==null?void 0:V.card)==null?void 0:J.python}),{cardFilterValues:m}=s.useCardFilterValues((i==null?void 0:i.id)??""),{setCardCustomCfg:h,setQueryResultColumns:x,setCardSql:g,setTempQueryData:b,setPythonStdOut:p,setCardPreferences:v,setCardType:j,setCardPython:S,runAssistant:M,setShowAIDialog:E}=s.useEditorActions();s.useEditorStore(V=>V.onSave),s.useEditorStore(V=>V.onClose),s.useEditorStore(V=>V.actions.setSqlGen);const C=s.useEditorStore(V=>V.runSql),D=s.useEditorStore(V=>V.actions.setRunSql),f=s.useEditorStore(V=>V.actions.setIsSqlRunning),{data:N,isLoading:y,isFetching:O,isSuccess:w,isError:F,error:k,errorSql:T,queryKey:A,refetch:R,errorMessage:L}=s.useDashboardCardQuery(i);I.useEffect(()=>{if(N&&(N.rowLimitExceeded&&s.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),p((N==null?void 0:N.output)||""),N.records.length>0)){const{dimensionKeys:V}=s.getKeys(N.records);x(V)}},[N,x,p]),I.useEffect(()=>{(y||O)&&f(!0),(F||w)&&f(!1),F&&(x([]),p(""))},[y,O,N,p,F,w,f,x,k]),I.useEffect(()=>{C&&(t.getQueryData(A)||R(),D(!1))},[C,R,D,A,t]);async function B(){const V=`Can you help me debug this query?
297
+ ON ${S}`}),b};return o.length<2?null:e.jsx(e.Fragment,{children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[a.joins.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-6 text-xs font-semibold",onClick:()=>l(!0),children:[e.jsx(s.Link,{className:s.cn("mr-1 h-3 w-3",{"text-blue-500":a.joins.length>0,"text-gray-500":a.joins.length===0})}),"Join",a.joins.length>1?"s":""," (",a.joins.length,")"]})}),e.jsx(s.TooltipContent,{side:"right",className:"max-w-md overflow-hidden p-0",children:e.jsx(er,{joins:a.joins,baseEntityId:a.baseEntity.name,availableDataSources:o,generateSQLPreview:u})})]})}),e.jsx(Gs,{open:r,onOpenChange:l,joinPlan:a,availableDataSources:o,onSave:i,onCancel:d,onRemove:c,children:e.jsx("div",{})})]}),a.joins.length===0&&e.jsx(Gs,{open:r,onOpenChange:l,joinPlan:a,availableDataSources:o,onSave:i,onCancel:d,onRemove:c,children:e.jsxs(s.Button,{onClick:()=>l(!0),variant:"outline",size:"sm",className:"w-full",children:[e.jsx(s.Link,{className:"mr-3 size-4"}),"Configure Joins"]})})]})})})}function tr({open:t,onOpenChange:n}){const[a,r]=I.useState([]),{updateDataSource:l}=s.useEditorActions(),o=s.useDashboardStore(p=>p.dashboard.aiContext),i=(o==null?void 0:o.selectedEntities)||[];I.useEffect(()=>{t&&r([])},[t]);const c=p=>{r(v=>v.some(S=>S.name===p.name&&S.type===p.type)?v.filter(S=>!(S.name===p.name&&S.type===p.type)):[...v,p])},d=()=>{r([...i])},u=()=>{r([])},m=()=>{if(a.length===0)return;const p=a[0],v=p.connectionId||"",j=p.connectionType||"",M=a.some(C=>C.type==="dataset")?"semanticDomain":"database";l({connectionId:v,connectionType:j,mode:M,selectedEntities:a}),n(!1)},h=p=>{switch(p.type){case"table":return e.jsx(s.Table,{className:"h-4 w-4"});case"view":return e.jsx(Wa,{className:"h-4 w-4"});case"model":return e.jsx(ya,{className:"h-4 w-4"});case"dataset":return e.jsx(s.Database,{className:"h-4 w-4"});case"file":case"url":case"upload":return e.jsx(s.FileText,{className:"h-4 w-4"});default:return e.jsx(s.Database,{className:"h-4 w-4"})}},x=p=>"label"in p&&p.label?p.label:p.name,g=p=>{if("description"in p&&p.description)return p.description;const v=[];return p.database&&v.push(p.database),p.schema&&v.push(p.schema),p.name&&v.push(p.name),v.join(".")},b=p=>a.some(v=>v.name===p.name&&v.type===p.type);return i.length===0?e.jsx(s.Dialog,{open:t,onOpenChange:n,children:e.jsxs(s.DialogContent,{className:"max-w-md",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"No Data Available"}),e.jsx(s.DialogDescription,{children:"No entities are currently available in the AI context. Please add some data sources to the dashboard first."})]}),e.jsx(s.DialogFooter,{children:e.jsx(s.Button,{onClick:()=>n(!1),children:"Close"})})]})}):e.jsx(s.Dialog,{open:t,onOpenChange:n,children:e.jsxs(s.DialogContent,{className:"flex max-w-2xl flex-col",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Select Data to Analyze"}),e.jsx(s.DialogDescription,{children:"Choose entities from the dashboard's context"})]}),e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"outline",size:"sm",onClick:d,disabled:a.length===i.length,children:"Select All"}),e.jsx(s.Button,{variant:"outline",size:"sm",onClick:u,disabled:a.length===0,children:"Clear All"})]}),e.jsxs(s.Badge,{variant:"secondary",children:[a.length," of ",i.length," selected"]})]}),e.jsx(s.Separator,{}),e.jsx(s.ScrollArea,{className:"h-64",children:e.jsx("div",{className:"space-y-2",children:i.map((p,v)=>e.jsxs("div",{className:s.cn("flex items-center gap-3 rounded-lg border p-3 transition-colors hover:bg-muted/50",b(p)&&"border-primary bg-primary/5"),children:[e.jsx(s.Checkbox,{checked:b(p),onCheckedChange:()=>c(p)}),e.jsx("div",{className:"flex items-center gap-2 text-muted-foreground",children:h(p)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-medium",children:x(p)}),e.jsx("div",{className:"truncate text-sm text-muted-foreground",children:g(p)})]}),e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:p.type})]},`${p.type}-${p.name}-${v}`))})})]}),e.jsx(s.DialogFooter,{children:e.jsx("div",{className:"flex w-full justify-between",children:e.jsxs("div",{className:"flex grow justify-end gap-2",children:[e.jsx(s.Button,{variant:"outline",onClick:()=>n(!1),children:"Cancel"}),e.jsxs(s.Button,{onClick:m,disabled:a.length===0,children:["Select"," ",a.length>0?`(${a.length})`:""]})]})})})]})})}function ar({entity:t,title:n,maxDetails:a=10}){const l=s.getEntityDetails(t).slice(0,a),o=l.find(c=>c.label==="Description"),i=l.filter(c=>c.label==="Description"?!1:!["Connection","Database","Schema"].includes(c.label));return e.jsx(s.TooltipContent,{side:"top",className:"ml-5 max-w-xs",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:n||s.getDisplayName(t)}),o&&e.jsxs("div",{className:"border-t border-border pt-2",children:[e.jsx("div",{className:"mb-1 text-xs text-muted-foreground",children:"Description:"}),e.jsx("div",{className:"text-xs leading-relaxed",children:o.value})]}),i.length>0&&e.jsx("div",{className:"space-y-0.5",children:i.map((c,d)=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsxs("span",{className:"mr-2 text-muted-foreground",children:[c.label,":"]}),e.jsx("span",{className:"font-mono",children:c.value})]},d))})]})})}function nr({entities:t}){return e.jsx(s.TooltipContent,{side:"top",className:"ml-5 max-w-xs",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-sm font-medium",children:[t.length," more entities"]}),e.jsx("div",{className:"space-y-1",children:t.map((n,a)=>{const r=s.getEntityDetails(n),l=r.find(i=>i.label==="Description"),o=r.filter(i=>i.label==="Description"?!1:!["Connection","Database","Schema"].includes(i.label)).slice(0,3);return e.jsxs("div",{className:"border-b border-border pb-1 last:border-b-0",children:[e.jsx("div",{className:"text-xs font-medium",children:s.getDisplayName(n)}),l&&e.jsxs("div",{className:"mb-1 mt-1",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Description:"}),e.jsx("div",{className:"text-xs leading-relaxed",children:l.value})]}),o.length>0&&e.jsx("div",{className:"mt-1 space-y-0.5",children:o.map((i,c)=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsxs("span",{className:"mr-2 text-muted-foreground",children:[i.label,":"]}),e.jsx("span",{className:"font-mono",children:i.value})]},c))})]},`remaining-${n.type}-${n.name}-${a}`)})})]})})}function Et(){const t=s.useEditorStore(i=>i.card.dataSource),{setSelectedConnectionId:n,setSelectedDatabaseName:a,setSelectedSchemaName:r,setSelectedTableName:l,setSelectedDatamodelId:o}=s.useEditorActions();I.useEffect(()=>{var g;if(!t)return;const{tableName:i,schemaName:c,databaseName:d,connectionId:u}=Ts(t),m=(g=t.selectedEntities)==null?void 0:g[0],x=(m==null?void 0:m.type)==="model"&&"id"in m?m.id:"";n(u||""),a(d||""),r(c||""),l(i||""),o(x)},[t,n,a,r,l,o])}function It({isVisible:t}){const n=s.useEditorStore(x=>x.isDevMode);Et();const[a,r]=I.useState(!1),[l,o]=I.useState(!1),[i,c]=I.useState(!0),d=s.useEditorStore(x=>x.card.dataSource);s.useCurrentUserInfo();const{updateDataSource:u}=s.useEditorActions(),m={connectionId:"",connectionType:"",mode:"database",selectedEntities:[]},h={...m,...d,selectedEntities:(d==null?void 0:d.selectedEntities)||[]};return e.jsxs("div",{className:s.cn("flex flex-col overflow-hidden bg-background transition-all duration-300 ease-in-out",{"w-[325px]":t,"w-0":!t}),children:[e.jsxs("div",{children:[e.jsx("div",{className:"p-4 px-6 pb-2",children:e.jsxs(s.Button,{className:"w-full bg-muted/50",variant:"outline",onClick:()=>r(!0),children:[e.jsx(s.Database,{className:"mr-2 h-3.5 w-3.5"}),"Choose Dataset"]})}),e.jsxs("div",{className:"relative px-6",children:[e.jsx("div",{className:"absolute inset-0 flex items-center px-6",children:e.jsx("div",{className:"w-full border-t border-border"})}),e.jsx("div",{className:"relative flex justify-center",children:e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>c(!i),className:"size-6 bg-background p-1 py-1 hover:bg-accent",children:i?e.jsx(s.ChevronUp,{className:"h-3.5 w-3.5"}):e.jsx(s.ChevronDown,{className:"h-3.5 w-3.5"})})})]}),e.jsxs("div",{className:`overflow-hidden px-6 ${i?"max-h-96 space-y-4":"max-h-0 py-0 opacity-0"}`,children:[h.selectedEntities.length>0&&e.jsx(s.TooltipProvider,{children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[h.selectedEntities.slice(0,3).map((x,g)=>e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Badge,{variant:"secondary",className:"group relative cursor-pointer pr-6 text-xs transition-colors hover:border-red-200 hover:bg-red-50 dark:hover:border-red-800 dark:hover:bg-red-950",children:[s.getDisplayName(x),e.jsx("button",{onClick:b=>{b.stopPropagation();const p=h.selectedEntities.filter(v=>!(v.name===x.name&&v.type===x.type));u({...m,...d,selectedEntities:p})},className:"absolute right-1 top-1/2 -translate-y-1/2 rounded-full p-0.5 hover:bg-red-100",children:e.jsx(s.X,{className:"h-2.5 w-2.5 group-hover:text-red-500"})})]})}),e.jsx(ar,{entity:x})]},`${x.type}-${x.name}-${g}`)),h.selectedEntities.length>3&&e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Badge,{variant:"outline",className:"text-xs",children:["+",h.selectedEntities.length-3," more"]})}),e.jsx(nr,{entities:h.selectedEntities.slice(3)})]})]})}),!n&&e.jsx(sr,{})]})]}),e.jsx(kt,{}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(d==null?void 0:d.selectedEntities)||[],dialogMode:"dataSource",open:a,onOpenChange:r,dataSource:h}),e.jsx(tr,{open:l,onOpenChange:o})]})}function At({error:t,errorSql:n,onSendFeedback:a,className:r,showFeedbackButton:l=!0}){const[o,i]=I.useState(!1);return e.jsx("div",{className:s.cn("rounded-lg border border-destructive/30 bg-destructive/5 p-4",r),children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(s.CircleAlert,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-destructive"}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-destructive",children:"Query Error"}),e.jsxs("div",{className:"relative rounded-md bg-background/60 p-3",children:[e.jsx(s.CopyButton,{text:t,className:"absolute right-2 top-2 h-6 w-6 z-10"}),e.jsx("div",{className:"max-h-40 overflow-auto pr-10",children:e.jsx("p",{className:"font-mono text-xs text-foreground/80 break-all",children:t})})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[n&&e.jsx(s.Collapsible,{open:o,onOpenChange:i,children:e.jsx(s.CollapsibleTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"outline",size:"sm",className:"h-8",children:o?e.jsxs(e.Fragment,{children:[e.jsx(s.ChevronUp,{className:"mr-1.5 h-3.5 w-3.5"}),"Hide Details"]}):e.jsxs(e.Fragment,{children:[e.jsx(s.ChevronDown,{className:"mr-1.5 h-3.5 w-3.5"}),"Show Details"]})})})}),l&&a&&e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-8",onClick:a,children:[e.jsx(s.MessageSquareWarning,{className:"mr-1.5 h-3.5 w-3.5"}),"Send Feedback"]})]}),n&&e.jsx(s.Collapsible,{open:o,onOpenChange:i,children:e.jsx(s.CollapsibleContent,{className:"space-y-2",children:e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Error SQL Query"}),e.jsx(s.CopyButton,{text:n,className:"h-6 w-6"})]}),e.jsx("div",{className:"rounded-md bg-background/60 p-2 max-h-80 overflow-auto",children:e.jsx(s.CodeHighlighter,{code:n,language:"sql"})})]})})})]})]})})}function Mt({sql:t,error:n,errorSql:a,onDebugWithAssistant:r}){const l=s.useEditorStore(u=>u.isDevMode),{setIsDevMode:o,setCardSql:i,setRunSql:c}=s.useEditorActions();function d(){o(!l),i(t),setTimeout(()=>{c(!0)},100)}return e.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxs("div",{className:"flex grow flex-col space-y-3",children:[e.jsxs(s.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll text-xs leading-relaxed text-foreground/80",children:[n&&e.jsx(At,{error:n,errorSql:a,showFeedbackButton:!1}),!n&&t&&e.jsx("div",{className:"flex flex-col space-y-1.5",children:e.jsx("div",{className:"",children:e.jsx(s.CodeHighlighter,{code:t,language:"sql"})})})]}),!l&&t&&!n&&e.jsxs(s.Button,{onClick:d,variant:"secondary",size:"sm",children:[e.jsx(Ca,{className:"mr-2 h-4 w-4"}),"View in SQL Editor"]}),n&&r&&e.jsxs(s.Button,{onClick:r,size:"sm",variant:"outline",children:[e.jsx(Ea,{className:"mr-2 h-4 w-4"}),"Debug with Assistant"]})]})})}function Lt({sql:t,error:n,errorSql:a,onDebugWithAssistant:r}){return e.jsxs(s.HoverCard,{openDelay:n?0:500,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"link",className:"h-5 p-0",children:n?e.jsx(ja,{className:"h-4 w-4 text-red-500"}):e.jsx(s.Info,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsx(s.HoverCardContent,{align:"start",className:"flex w-[700px]",children:e.jsx(Mt,{errorSql:a,sql:t,error:n,onDebugWithAssistant:r})})]})}function rr(t){return s.GenIcon({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"},child:[]}]})(t)}function Rt(t){const{theme:n}=s.useTheme(),a=s.useDashboardStore(p=>p.theme),r=s.useEditorStore(p=>p.frame),l=s.useEditorStore(p=>p.card),o=s.useEditorStore(p=>p.activeTabCardId),i=s.Le(),{refetch:c}=s.useDashboardCardQuery(l),{updateCardTab:d,setRunSql:u}=s.useEditorActions(),m=I.useRef(),h=I.useRef({}),x=r.cards.find(p=>p.id===o),g=I.useCallback(()=>{let p="";return t==="python"&&(p=(x==null?void 0:x.python)||s.PYTHON_DEFAULT_CODE),t==="sql"&&(p=(x==null?void 0:x.sql)||""),p},[t,x]);I.useEffect(()=>{if(o&&l.id&&l.id!==o){if(m.current&&i){const p=m.current.getModel();p&&(h.current[l.id]=p);let v=h.current[o];if(!v){const j=g();v=i.editor.createModel(j,t),h.current[o]=v}m.current.setModel(v)}d(o,l),u(!0)}},[o,l,d,i,u,t,g]),I.useEffect(()=>{if(!i)return;const p=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",v=a==="system"?p:a;i.editor.defineTheme("default",{base:v==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":v==="light"?"#ffffff":s.hslStringToHex("240 10% 10%")}}),i.editor.setTheme("default")},[n,a,i]),I.useEffect(()=>{const p=m.current;p&&i&&l&&p.addCommand(i.KeyMod.Shift|i.KeyCode.Enter,function(){return c(),!1})},[i,c,l]);function b(p,v){if(m.current=p,!h.current[l.id]){const j=p.getModel(),S=g();h.current[l.id]=j||(v==null?void 0:v.editor.createModel(S,t))||p.getModel()}p.setModel(h.current[l.id])}return{handleEditorDidMount:b}}function lr(){const t=s.useEditorStore(i=>i.card.sql),n=s.useEditorStore(i=>i.sqlGen),{setCardSql:a,setSqlGen:r}=s.useEditorActions(),{handleEditorDidMount:l}=Rt("sql");function o(i){a(i),s.isObjectEmpty(n)||r({})}return e.jsxs("div",{className:"relative h-full w-full",children:[!t&&e.jsx("div",{className:"pointer-events-none absolute left-[65px] top-3 z-10 font-mono text-sm text-muted-foreground",children:"Write your SQL here"}),e.jsx(s.Ft,{theme:"default",className:"pt-3",onChange:o,value:t||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:l})]})}function or(){const t=s.useEditorStore(l=>l.card.python),{setCardPython:n}=s.useEditorActions(),{handleEditorDidMount:a}=Rt("python");function r(l){n(l)}return e.jsx(s.Ft,{className:"pt-3",theme:"default",onChange:r,value:t||s.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"python",onMount:a})}function ir({jsonString:t}){return e.jsx(s.Ft,{theme:"default",defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:t,options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})}function cr(){const t=s.useQueryClient(),{isConsoleMode:n}=s.useDashboardPreferences(),[a,r]=I.useState(!1),[l,o]=I.useState(!1);s.useEditorStore(V=>V.frame);const i=s.useEditorStore(V=>V.card);s.useEditorStore(V=>V.isShowingVisual),s.useEditorStore(V=>V.selectedConnectionId),s.useEditorStore(V=>V.tempQueryData),s.useEditorStore(V=>V.selectedDatabaseName),s.useEditorStore(V=>V.selectedDatamodelId),s.useEditorStore(V=>V.selectedSchemaName);const c=s.useEditorStore(V=>V.showAIDialog);s.useEditorStore(V=>V.selectedTableName);const d=s.useEditorStore(V=>{var J;return(J=V==null?void 0:V.card)==null?void 0:J.sql}),u=s.useEditorStore(V=>{var J;return(J=V==null?void 0:V.card)==null?void 0:J.python}),{cardFilterValues:m}=s.useCardFilterValues((i==null?void 0:i.id)??""),{setCardCustomCfg:h,setQueryResultColumns:x,setCardSql:g,setTempQueryData:b,setPythonStdOut:p,setCardPreferences:v,setCardType:j,setCardPython:S,runAssistant:M,setShowAIDialog:E}=s.useEditorActions();s.useEditorStore(V=>V.onSave),s.useEditorStore(V=>V.onClose),s.useEditorStore(V=>V.actions.setSqlGen);const C=s.useEditorStore(V=>V.runSql),D=s.useEditorStore(V=>V.actions.setRunSql),f=s.useEditorStore(V=>V.actions.setIsSqlRunning),{data:N,isLoading:y,isFetching:O,isSuccess:w,isError:F,error:k,errorSql:T,queryKey:A,refetch:R,errorMessage:L}=s.useDashboardCardQuery(i);I.useEffect(()=>{if(N&&(N.rowLimitExceeded&&s.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),p((N==null?void 0:N.output)||""),N.records.length>0)){const{dimensionKeys:V}=s.getKeys(N.records);x(V)}},[N,x,p]),I.useEffect(()=>{(y||O)&&f(!0),(F||w)&&f(!1),F&&(x([]),p(""))},[y,O,N,p,F,w,f,x,k]),I.useEffect(()=>{C&&(t.getQueryData(A)||R(),D(!1))},[C,R,D,A,t]);async function B(){const V=`Can you help me debug this query?
298
298
 
299
299
  Error:
300
300
 
@@ -90601,7 +90601,7 @@ function hVe({
90601
90601
  accentText: "text-yellow-900 dark:text-yellow-200"
90602
90602
  }, ie = () => G ? Z ? "Configuration validation failed. Retrying..." : "Configuration validation failed" : T === "group_by_error" ? Z ? "SQL grouping error. Retrying..." : "SQL grouping error" : T === "syntax_error" ? Z ? "SQL syntax error. Retrying..." : "SQL syntax error" : T === "type_mismatch" ? Z ? "Data type mismatch. Retrying..." : "Data type mismatch" : Z ? "Retrying..." : "Couldn't generate this visual";
90603
90603
  if (!r) {
90604
- const ee = Z ? "Trying a different approach..." : "I'm ready with a revised plan.", fe = H || (q && q !== o.error ? q : "");
90604
+ const ee = Z ? "Let me try that a different way..." : "I'm ready with a revised plan.", fe = H || (q && q !== o.error ? q : "");
90605
90605
  return /* @__PURE__ */ p("div", { className: "mt-2 rounded-md border border-border/40 bg-muted/30 p-3 text-xs", children: /* @__PURE__ */ k("div", { className: "flex items-start gap-2", children: [
90606
90606
  /* @__PURE__ */ p(
90607
90607
  wL,
@@ -91089,7 +91089,7 @@ function SVe({
91089
91089
  status: e,
91090
91090
  errorMessage: t
91091
91091
  }) {
91092
- return e === "submitted" ? /* @__PURE__ */ p("div", { className: "mt-2 animate-pulse text-sm text-muted-foreground", children: "Thinking..." }) : e === "streaming" ? /* @__PURE__ */ p("div", { className: "mt-1 animate-pulse text-sm text-muted-foreground", children: "Streaming..." }) : e === "error" ? /* @__PURE__ */ p("div", { className: "mt-2 text-xs text-muted-foreground", children: /* @__PURE__ */ p(hT, { errorMessage: t }) }) : null;
91092
+ return e === "submitted" ? /* @__PURE__ */ p("div", { className: "mt-2 animate-pulse text-sm text-muted-foreground", children: "Thinking..." }) : e === "streaming" ? /* @__PURE__ */ p("div", { className: "animate-pulse text-sm text-muted-foreground", children: "Streaming..." }) : e === "error" ? /* @__PURE__ */ p("div", { className: "mt-2 text-xs text-muted-foreground", children: /* @__PURE__ */ p(hT, { errorMessage: t }) }) : null;
91093
91093
  }
91094
91094
  function CVe({
91095
91095
  messages: e,
@@ -922,10 +922,10 @@ prismjs/prism.js:
922
922
  `))+1))}const i="#".repeat(o),a=n.enter("headingAtx"),l=n.enter("phrasing");s.move(i+" ");let c=n.containerPhrasing(e,{before:"# ",after:`
923
923
  `,...s.current()});return/^[\t ]/.test(c)&&(c=fg(c.charCodeAt(0))+c.slice(1)),c=c?i+" "+c:i,n.options.closeAtx&&(c+=" "+i),l(),a(),c}IK.peek=I7e;function IK(e){return e.value||""}function I7e(){return"<"}OK.peek=O7e;function OK(e,t,n,r){const o=RD(n),s=o==='"'?"Quote":"Apostrophe",i=n.enter("image");let a=n.enter("label");const l=n.createTracker(r);let c=l.move("![");return c+=l.move(n.safe(e.alt,{before:c,after:"]",...l.current()})),c+=l.move("]("),a(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(a=n.enter("destinationLiteral"),c+=l.move("<"),c+=l.move(n.safe(e.url,{before:c,after:">",...l.current()})),c+=l.move(">")):(a=n.enter("destinationRaw"),c+=l.move(n.safe(e.url,{before:c,after:e.title?" ":")",...l.current()}))),a(),e.title&&(a=n.enter(`title${s}`),c+=l.move(" "+o),c+=l.move(n.safe(e.title,{before:c,after:o,...l.current()})),c+=l.move(o),a()),c+=l.move(")"),i(),c}function O7e(){return"!"}FK.peek=F7e;function FK(e,t,n,r){const o=e.referenceType,s=n.enter("imageReference");let i=n.enter("label");const a=n.createTracker(r);let l=a.move("![");const c=n.safe(e.alt,{before:l,after:"]",...a.current()});l+=a.move(c+"]["),i();const d=n.stack;n.stack=[],i=n.enter("reference");const f=n.safe(n.associationId(e),{before:l,after:"]",...a.current()});return i(),n.stack=d,s(),o==="full"||!c||c!==f?l+=a.move(f+"]"):o==="shortcut"?l=l.slice(0,-1):l+=a.move("]"),l}function F7e(){return"!"}$K.peek=$7e;function $K(e,t,n){let r=e.value||"",o="`",s=-1;for(;new RegExp("(^|[^`])"+o+"([^`]|$)").test(r);)o+="`";for(/[^ \r\n]/.test(r)&&(/^[ \r\n]/.test(r)&&/[ \r\n]$/.test(r)||/^`|`$/.test(r))&&(r=" "+r+" ");++s<n.unsafe.length;){const i=n.unsafe[s],a=n.compilePattern(i);let l;if(i.atBreak)for(;l=a.exec(r);){let c=l.index;r.charCodeAt(c)===10&&r.charCodeAt(c-1)===13&&c--,r=r.slice(0,c)+" "+r.slice(l.index+1)}}return o+r+o}function $7e(){return"`"}function LK(e,t){const n=xD(e);return!!(!t.options.resourceLink&&e.url&&!e.title&&e.children&&e.children.length===1&&e.children[0].type==="text"&&(n===e.url||"mailto:"+n===e.url)&&/^[a-z][a-z+.-]+:/i.test(e.url)&&!/[\0- <>\u007F]/.test(e.url))}zK.peek=L7e;function zK(e,t,n,r){const o=RD(n),s=o==='"'?"Quote":"Apostrophe",i=n.createTracker(r);let a,l;if(LK(e,n)){const d=n.stack;n.stack=[],a=n.enter("autolink");let f=i.move("<");return f+=i.move(n.containerPhrasing(e,{before:f,after:">",...i.current()})),f+=i.move(">"),a(),n.stack=d,f}a=n.enter("link"),l=n.enter("label");let c=i.move("[");return c+=i.move(n.containerPhrasing(e,{before:c,after:"](",...i.current()})),c+=i.move("]("),l(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(l=n.enter("destinationLiteral"),c+=i.move("<"),c+=i.move(n.safe(e.url,{before:c,after:">",...i.current()})),c+=i.move(">")):(l=n.enter("destinationRaw"),c+=i.move(n.safe(e.url,{before:c,after:e.title?" ":")",...i.current()}))),l(),e.title&&(l=n.enter(`title${s}`),c+=i.move(" "+o),c+=i.move(n.safe(e.title,{before:c,after:o,...i.current()})),c+=i.move(o),l()),c+=i.move(")"),a(),c}function L7e(e,t,n){return LK(e,n)?"<":"["}BK.peek=z7e;function BK(e,t,n,r){const o=e.referenceType,s=n.enter("linkReference");let i=n.enter("label");const a=n.createTracker(r);let l=a.move("[");const c=n.containerPhrasing(e,{before:l,after:"]",...a.current()});l+=a.move(c+"]["),i();const d=n.stack;n.stack=[],i=n.enter("reference");const f=n.safe(n.associationId(e),{before:l,after:"]",...a.current()});return i(),n.stack=d,s(),o==="full"||!c||c!==f?l+=a.move(f+"]"):o==="shortcut"?l=l.slice(0,-1):l+=a.move("]"),l}function z7e(){return"["}function MD(e){const t=e.options.bullet||"*";if(t!=="*"&&t!=="+"&&t!=="-")throw new Error("Cannot serialize items with `"+t+"` for `options.bullet`, expected `*`, `+`, or `-`");return t}function B7e(e){const t=MD(e),n=e.options.bulletOther;if(!n)return t==="*"?"-":"*";if(n!=="*"&&n!=="+"&&n!=="-")throw new Error("Cannot serialize items with `"+n+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(n===t)throw new Error("Expected `bullet` (`"+t+"`) and `bulletOther` (`"+n+"`) to be different");return n}function V7e(e){const t=e.options.bulletOrdered||".";if(t!=="."&&t!==")")throw new Error("Cannot serialize items with `"+t+"` for `options.bulletOrdered`, expected `.` or `)`");return t}function VK(e){const t=e.options.rule||"*";if(t!=="*"&&t!=="-"&&t!=="_")throw new Error("Cannot serialize rules with `"+t+"` for `options.rule`, expected `*`, `-`, or `_`");return t}function H7e(e,t,n,r){const o=n.enter("list"),s=n.bulletCurrent;let i=e.ordered?V7e(n):MD(n);const a=e.ordered?i==="."?")":".":B7e(n);let l=t&&n.bulletLastUsed?i===n.bulletLastUsed:!1;if(!e.ordered){const d=e.children?e.children[0]:void 0;if((i==="*"||i==="-")&&d&&(!d.children||!d.children[0])&&n.stack[n.stack.length-1]==="list"&&n.stack[n.stack.length-2]==="listItem"&&n.stack[n.stack.length-3]==="list"&&n.stack[n.stack.length-4]==="listItem"&&n.indexStack[n.indexStack.length-1]===0&&n.indexStack[n.indexStack.length-2]===0&&n.indexStack[n.indexStack.length-3]===0&&(l=!0),VK(n)===i&&d){let f=-1;for(;++f<e.children.length;){const h=e.children[f];if(h&&h.type==="listItem"&&h.children&&h.children[0]&&h.children[0].type==="thematicBreak"){l=!0;break}}}}l&&(i=a),n.bulletCurrent=i;const c=n.containerFlow(e,r);return n.bulletLastUsed=i,n.bulletCurrent=s,o(),c}function U7e(e){const t=e.options.listItemIndent||"one";if(t!=="tab"&&t!=="one"&&t!=="mixed")throw new Error("Cannot serialize items with `"+t+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return t}function W7e(e,t,n,r){const o=U7e(n);let s=n.bulletCurrent||MD(n);t&&t.type==="list"&&t.ordered&&(s=(typeof t.start=="number"&&t.start>-1?t.start:1)+(n.options.incrementListMarker===!1?0:t.children.indexOf(e))+s);let i=s.length+1;(o==="tab"||o==="mixed"&&(t&&t.type==="list"&&t.spread||e.spread))&&(i=Math.ceil(i/4)*4);const a=n.createTracker(r);a.move(s+" ".repeat(i-s.length)),a.shift(i);const l=n.enter("listItem"),c=n.indentLines(n.containerFlow(e,a.current()),d);return l(),c;function d(f,h,p){return h?(p?"":" ".repeat(i))+f:(p?s:s+" ".repeat(i-s.length))+f}}function q7e(e,t,n,r){const o=n.enter("paragraph"),s=n.enter("phrasing"),i=n.containerPhrasing(e,r);return s(),o(),i}const G7e=L1(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function Y7e(e,t,n,r){return(e.children.some(function(i){return G7e(i)})?n.containerPhrasing:n.containerFlow).call(n,e,r)}function Z7e(e){const t=e.options.strong||"*";if(t!=="*"&&t!=="_")throw new Error("Cannot serialize strong with `"+t+"` for `options.strong`, expected `*`, or `_`");return t}HK.peek=K7e;function HK(e,t,n,r){const o=Z7e(n),s=n.enter("strong"),i=n.createTracker(r),a=i.move(o+o);let l=i.move(n.containerPhrasing(e,{after:o,before:a,...i.current()}));const c=l.charCodeAt(0),d=bv(r.before.charCodeAt(r.before.length-1),c,o);d.inside&&(l=fg(c)+l.slice(1));const f=l.charCodeAt(l.length-1),h=bv(r.after.charCodeAt(0),f,o);h.inside&&(l=l.slice(0,-1)+fg(f));const p=i.move(o+o);return s(),n.attentionEncodeSurroundingInfo={after:h.outside,before:d.outside},a+l+p}function K7e(e,t,n){return n.options.strong||"*"}function X7e(e,t,n,r){return n.safe(e.value,r)}function Q7e(e){const t=e.options.ruleRepetition||3;if(t<3)throw new Error("Cannot serialize rules with repetition `"+t+"` for `options.ruleRepetition`, expected `3` or more");return t}function J7e(e,t,n){const r=(VK(n)+(n.options.ruleSpaces?" ":"")).repeat(Q7e(n));return n.options.ruleSpaces?r.slice(0,-1):r}const UK={blockquote:S7e,break:D4,code:j7e,definition:M7e,emphasis:AK,hardBreak:D4,heading:A7e,html:IK,image:OK,imageReference:FK,inlineCode:$K,link:zK,linkReference:BK,list:H7e,listItem:W7e,paragraph:q7e,root:Y7e,strong:HK,text:X7e,thematicBreak:J7e};function eBe(){return{enter:{table:tBe,tableData:P4,tableHeader:P4,tableRow:rBe},exit:{codeText:oBe,table:nBe,tableData:jE,tableHeader:jE,tableRow:jE}}}function tBe(e){const t=e._align;this.enter({type:"table",align:t.map(function(n){return n==="none"?null:n}),children:[]},e),this.data.inTable=!0}function nBe(e){this.exit(e),this.data.inTable=void 0}function rBe(e){this.enter({type:"tableRow",children:[]},e)}function jE(e){this.exit(e)}function P4(e){this.enter({type:"tableCell",children:[]},e)}function oBe(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,sBe));const n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function sBe(e,t){return t==="|"?t:e}function iBe(e){const t=e||{},n=t.tableCellPadding,r=t.tablePipeAlign,o=t.stringLength,s=n?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:`
924
924
  `,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:h,table:i,tableCell:l,tableRow:a}};function i(p,m,g,y){return c(d(p,g,y),p.align)}function a(p,m,g,y){const b=f(p,g,y),x=c([b]);return x.slice(0,x.indexOf(`
925
- `))}function l(p,m,g,y){const b=g.enter("tableCell"),x=g.enter("phrasing"),v=g.containerPhrasing(p,{...y,before:s,after:s});return x(),b(),v}function c(p,m){return v7e(p,{align:m,alignDelimiters:r,padding:n,stringLength:o})}function d(p,m,g){const y=p.children;let b=-1;const x=[],v=m.enter("table");for(;++b<y.length;)x[b]=f(y[b],m,g);return v(),x}function f(p,m,g){const y=p.children;let b=-1;const x=[],v=m.enter("tableRow");for(;++b<y.length;)x[b]=l(y[b],p,m,g);return v(),x}function h(p,m,g){let y=UK.inlineCode(p,m,g);return g.stack.includes("tableCell")&&(y=y.replace(/\|/g,"\\$&")),y}}function aBe(){return{exit:{taskListCheckValueChecked:T4,taskListCheckValueUnchecked:T4,paragraph:cBe}}}function lBe(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:uBe}}}function T4(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function cBe(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const r=n.children[0];if(r&&r.type==="text"){const o=t.children;let s=-1,i;for(;++s<o.length;){const a=o[s];if(a.type==="paragraph"){i=a;break}}i===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(e)}function uBe(e,t,n,r){const o=e.children[0],s=typeof e.checked=="boolean"&&o&&o.type==="paragraph",i="["+(e.checked?"x":" ")+"] ",a=n.createTracker(r);s&&a.move(i);let l=UK.listItem(e,t,n,{...r,...a.current()});return s&&(l=l.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,c)),l;function c(d){return d+i}}function dBe(){return[H9e(),u7e(),p7e(),eBe(),aBe()]}function fBe(e){return{extensions:[U9e(),d7e(e),m7e(),iBe(e),lBe()]}}const hBe={tokenize:xBe,partial:!0},WK={tokenize:vBe,partial:!0},qK={tokenize:wBe,partial:!0},GK={tokenize:SBe,partial:!0},pBe={tokenize:CBe,partial:!0},YK={name:"wwwAutolink",tokenize:bBe,previous:KK},ZK={name:"protocolAutolink",tokenize:yBe,previous:XK},rl={name:"emailAutolink",tokenize:gBe,previous:QK},ua={};function mBe(){return{text:ua}}let Cc=48;for(;Cc<123;)ua[Cc]=rl,Cc++,Cc===58?Cc=65:Cc===91&&(Cc=97);ua[43]=rl;ua[45]=rl;ua[46]=rl;ua[95]=rl;ua[72]=[rl,ZK];ua[104]=[rl,ZK];ua[87]=[rl,YK];ua[119]=[rl,YK];function gBe(e,t,n){const r=this;let o,s;return i;function i(f){return!Fk(f)||!QK.call(r,r.previous)||DD(r.events)?n(f):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),a(f))}function a(f){return Fk(f)?(e.consume(f),a):f===64?(e.consume(f),l):n(f)}function l(f){return f===46?e.check(pBe,d,c)(f):f===45||f===95||Ur(f)?(s=!0,e.consume(f),l):d(f)}function c(f){return e.consume(f),o=!0,l}function d(f){return s&&o&&oo(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(f)):n(f)}}function bBe(e,t,n){const r=this;return o;function o(i){return i!==87&&i!==119||!KK.call(r,r.previous)||DD(r.events)?n(i):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(hBe,e.attempt(WK,e.attempt(qK,s),n),n)(i))}function s(i){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(i)}}function yBe(e,t,n){const r=this;let o="",s=!1;return i;function i(f){return(f===72||f===104)&&XK.call(r,r.previous)&&!DD(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),o+=String.fromCodePoint(f),e.consume(f),a):n(f)}function a(f){if(oo(f)&&o.length<5)return o+=String.fromCodePoint(f),e.consume(f),a;if(f===58){const h=o.toLowerCase();if(h==="http"||h==="https")return e.consume(f),l}return n(f)}function l(f){return f===47?(e.consume(f),s?c:(s=!0,l)):n(f)}function c(f){return f===null||hv(f)||mn(f)||Lu(f)||O1(f)?n(f):e.attempt(WK,e.attempt(qK,d),n)(f)}function d(f){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(f)}}function xBe(e,t,n){let r=0;return o;function o(i){return(i===87||i===119)&&r<3?(r++,e.consume(i),o):i===46&&r===3?(e.consume(i),s):n(i)}function s(i){return i===null?n(i):t(i)}}function vBe(e,t,n){let r,o,s;return i;function i(c){return c===46||c===95?e.check(GK,l,a)(c):c===null||mn(c)||Lu(c)||c!==45&&O1(c)?l(c):(s=!0,e.consume(c),i)}function a(c){return c===95?r=!0:(o=r,r=void 0),e.consume(c),i}function l(c){return o||r||!s?n(c):t(c)}}function wBe(e,t){let n=0,r=0;return o;function o(i){return i===40?(n++,e.consume(i),o):i===41&&r<n?s(i):i===33||i===34||i===38||i===39||i===41||i===42||i===44||i===46||i===58||i===59||i===60||i===63||i===93||i===95||i===126?e.check(GK,t,s)(i):i===null||mn(i)||Lu(i)?t(i):(e.consume(i),o)}function s(i){return i===41&&r++,e.consume(i),o}}function SBe(e,t,n){return r;function r(a){return a===33||a===34||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===63||a===95||a===126?(e.consume(a),r):a===38?(e.consume(a),s):a===93?(e.consume(a),o):a===60||a===null||mn(a)||Lu(a)?t(a):n(a)}function o(a){return a===null||a===40||a===91||mn(a)||Lu(a)?t(a):r(a)}function s(a){return oo(a)?i(a):n(a)}function i(a){return a===59?(e.consume(a),r):oo(a)?(e.consume(a),i):n(a)}}function CBe(e,t,n){return r;function r(s){return e.consume(s),o}function o(s){return Ur(s)?n(s):t(s)}}function KK(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||mn(e)}function XK(e){return!oo(e)}function QK(e){return!(e===47||Fk(e))}function Fk(e){return e===43||e===45||e===46||e===95||Ur(e)}function DD(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const EBe={tokenize:PBe,partial:!0};function NBe(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:RBe,continuation:{tokenize:MBe},exit:DBe}},text:{91:{name:"gfmFootnoteCall",tokenize:jBe},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:kBe,resolveTo:_Be}}}}function kBe(e,t,n){const r=this;let o=r.events.length;const s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let i;for(;o--;){const l=r.events[o][1];if(l.type==="labelImage"){i=l;break}if(l.type==="gfmFootnoteCall"||l.type==="labelLink"||l.type==="label"||l.type==="image"||l.type==="link")break}return a;function a(l){if(!i||!i._balanced)return n(l);const c=Qs(r.sliceSerialize({start:i.end,end:r.now()}));return c.codePointAt(0)!==94||!s.includes(c.slice(1))?n(l):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(l),e.exit("gfmFootnoteCallLabelMarker"),t(l))}}function _Be(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},o={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};o.end.column++,o.end.offset++,o.end._bufferIndex++;const s={type:"gfmFootnoteCallString",start:Object.assign({},o.end),end:Object.assign({},e[e.length-1][1].start)},i={type:"chunkString",contentType:"string",start:Object.assign({},s.start),end:Object.assign({},s.end)},a=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",o,t],["exit",o,t],["enter",s,t],["enter",i,t],["exit",i,t],["exit",s,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...a),e}function jBe(e,t,n){const r=this,o=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s=0,i;return a;function a(f){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),l}function l(f){return f!==94?n(f):(e.enter("gfmFootnoteCallMarker"),e.consume(f),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",c)}function c(f){if(s>999||f===93&&!i||f===null||f===91||mn(f))return n(f);if(f===93){e.exit("chunkString");const h=e.exit("gfmFootnoteCallString");return o.includes(Qs(r.sliceSerialize(h)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(f)}return mn(f)||(i=!0),s++,e.consume(f),f===92?d:c}function d(f){return f===91||f===92||f===93?(e.consume(f),s++,c):c(f)}}function RBe(e,t,n){const r=this,o=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s,i=0,a;return l;function l(m){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionLabelMarker"),c}function c(m){return m===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",d):n(m)}function d(m){if(i>999||m===93&&!a||m===null||m===91||mn(m))return n(m);if(m===93){e.exit("chunkString");const g=e.exit("gfmFootnoteDefinitionLabelString");return s=Qs(r.sliceSerialize(g)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),h}return mn(m)||(a=!0),i++,e.consume(m),m===92?f:d}function f(m){return m===91||m===92||m===93?(e.consume(m),i++,d):d(m)}function h(m){return m===58?(e.enter("definitionMarker"),e.consume(m),e.exit("definitionMarker"),o.includes(s)||o.push(s),Lt(e,p,"gfmFootnoteDefinitionWhitespace")):n(m)}function p(m){return t(m)}}function MBe(e,t,n){return e.check(jb,t,e.attempt(EBe,t,n))}function DBe(e){e.exit("gfmFootnoteDefinition")}function PBe(e,t,n){const r=this;return Lt(e,o,"gfmFootnoteDefinitionIndent",5);function o(s){const i=r.events[r.events.length-1];return i&&i[1].type==="gfmFootnoteDefinitionIndent"&&i[2].sliceSerialize(i[1],!0).length===4?t(s):n(s)}}function TBe(e){let n=(e||{}).singleTilde;const r={name:"strikethrough",tokenize:s,resolveAll:o};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function o(i,a){let l=-1;for(;++l<i.length;)if(i[l][0]==="enter"&&i[l][1].type==="strikethroughSequenceTemporary"&&i[l][1]._close){let c=l;for(;c--;)if(i[c][0]==="exit"&&i[c][1].type==="strikethroughSequenceTemporary"&&i[c][1]._open&&i[l][1].end.offset-i[l][1].start.offset===i[c][1].end.offset-i[c][1].start.offset){i[l][1].type="strikethroughSequence",i[c][1].type="strikethroughSequence";const d={type:"strikethrough",start:Object.assign({},i[c][1].start),end:Object.assign({},i[l][1].end)},f={type:"strikethroughText",start:Object.assign({},i[c][1].end),end:Object.assign({},i[l][1].start)},h=[["enter",d,a],["enter",i[c][1],a],["exit",i[c][1],a],["enter",f,a]],p=a.parser.constructs.insideSpan.null;p&&Go(h,h.length,0,F1(p,i.slice(c+1,l),a)),Go(h,h.length,0,[["exit",f,a],["enter",i[l][1],a],["exit",i[l][1],a],["exit",d,a]]),Go(i,c-1,l-c+3,h),l=c+h.length-2;break}}for(l=-1;++l<i.length;)i[l][1].type==="strikethroughSequenceTemporary"&&(i[l][1].type="data");return i}function s(i,a,l){const c=this.previous,d=this.events;let f=0;return h;function h(m){return c===126&&d[d.length-1][1].type!=="characterEscape"?l(m):(i.enter("strikethroughSequenceTemporary"),p(m))}function p(m){const g=rh(c);if(m===126)return f>1?l(m):(i.consume(m),f++,p);if(f<2&&!n)return l(m);const y=i.exit("strikethroughSequenceTemporary"),b=rh(m);return y._open=!b||b===2&&!!g,y._close=!g||g===2&&!!b,a(m)}}}class ABe{constructor(){this.map=[]}add(t,n,r){IBe(this,t,n,r)}consume(t){if(this.map.sort(function(s,i){return s[0]-i[0]}),this.map.length===0)return;let n=this.map.length;const r=[];for(;n>0;)n-=1,r.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];r.push(t.slice()),t.length=0;let o=r.pop();for(;o;){for(const s of o)t.push(s);o=r.pop()}this.map.length=0}}function IBe(e,t,n,r){let o=0;if(!(n===0&&r.length===0)){for(;o<e.map.length;){if(e.map[o][0]===t){e.map[o][1]+=n,e.map[o][2].push(...r);return}o+=1}e.map.push([t,n,r])}}function OBe(e,t){let n=!1;const r=[];for(;t<e.length;){const o=e[t];if(n){if(o[0]==="enter")o[1].type==="tableContent"&&r.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(o[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const s=r.length-1;r[s]=r[s]==="left"?"center":"right"}}else if(o[1].type==="tableDelimiterRow")break}else o[0]==="enter"&&o[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return r}function FBe(){return{flow:{null:{name:"table",tokenize:$Be,resolveAll:LBe}}}}function $Be(e,t,n){const r=this;let o=0,s=0,i;return a;function a(R){let P=r.events.length-1;for(;P>-1;){const I=r.events[P][1].type;if(I==="lineEnding"||I==="linePrefix")P--;else break}const M=P>-1?r.events[P][1].type:null,F=M==="tableHead"||M==="tableRow"?E:l;return F===E&&r.parser.lazy[r.now().line]?n(R):F(R)}function l(R){return e.enter("tableHead"),e.enter("tableRow"),c(R)}function c(R){return R===124||(i=!0,s+=1),d(R)}function d(R){return R===null?n(R):Ge(R)?s>1?(s=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(R),e.exit("lineEnding"),p):n(R):Nt(R)?Lt(e,d,"whitespace")(R):(s+=1,i&&(i=!1,o+=1),R===124?(e.enter("tableCellDivider"),e.consume(R),e.exit("tableCellDivider"),i=!0,d):(e.enter("data"),f(R)))}function f(R){return R===null||R===124||mn(R)?(e.exit("data"),d(R)):(e.consume(R),R===92?h:f)}function h(R){return R===92||R===124?(e.consume(R),f):f(R)}function p(R){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(R):(e.enter("tableDelimiterRow"),i=!1,Nt(R)?Lt(e,m,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(R):m(R))}function m(R){return R===45||R===58?y(R):R===124?(i=!0,e.enter("tableCellDivider"),e.consume(R),e.exit("tableCellDivider"),g):S(R)}function g(R){return Nt(R)?Lt(e,y,"whitespace")(R):y(R)}function y(R){return R===58?(s+=1,i=!0,e.enter("tableDelimiterMarker"),e.consume(R),e.exit("tableDelimiterMarker"),b):R===45?(s+=1,b(R)):R===null||Ge(R)?w(R):S(R)}function b(R){return R===45?(e.enter("tableDelimiterFiller"),x(R)):S(R)}function x(R){return R===45?(e.consume(R),x):R===58?(i=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(R),e.exit("tableDelimiterMarker"),v):(e.exit("tableDelimiterFiller"),v(R))}function v(R){return Nt(R)?Lt(e,w,"whitespace")(R):w(R)}function w(R){return R===124?m(R):R===null||Ge(R)?!i||o!==s?S(R):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(R)):S(R)}function S(R){return n(R)}function E(R){return e.enter("tableRow"),C(R)}function C(R){return R===124?(e.enter("tableCellDivider"),e.consume(R),e.exit("tableCellDivider"),C):R===null||Ge(R)?(e.exit("tableRow"),t(R)):Nt(R)?Lt(e,C,"whitespace")(R):(e.enter("data"),_(R))}function _(R){return R===null||R===124||mn(R)?(e.exit("data"),C(R)):(e.consume(R),R===92?j:_)}function j(R){return R===92||R===124?(e.consume(R),_):_(R)}}function LBe(e,t){let n=-1,r=!0,o=0,s=[0,0,0,0],i=[0,0,0,0],a=!1,l=0,c,d,f;const h=new ABe;for(;++n<e.length;){const p=e[n],m=p[1];p[0]==="enter"?m.type==="tableHead"?(a=!1,l!==0&&(A4(h,t,l,c,d),d=void 0,l=0),c={type:"table",start:Object.assign({},m.start),end:Object.assign({},m.end)},h.add(n,0,[["enter",c,t]])):m.type==="tableRow"||m.type==="tableDelimiterRow"?(r=!0,f=void 0,s=[0,0,0,0],i=[0,n+1,0,0],a&&(a=!1,d={type:"tableBody",start:Object.assign({},m.start),end:Object.assign({},m.end)},h.add(n,0,[["enter",d,t]])),o=m.type==="tableDelimiterRow"?2:d?3:1):o&&(m.type==="data"||m.type==="tableDelimiterMarker"||m.type==="tableDelimiterFiller")?(r=!1,i[2]===0&&(s[1]!==0&&(i[0]=i[1],f=n0(h,t,s,o,void 0,f),s=[0,0,0,0]),i[2]=n)):m.type==="tableCellDivider"&&(r?r=!1:(s[1]!==0&&(i[0]=i[1],f=n0(h,t,s,o,void 0,f)),s=i,i=[s[1],n,0,0])):m.type==="tableHead"?(a=!0,l=n):m.type==="tableRow"||m.type==="tableDelimiterRow"?(l=n,s[1]!==0?(i[0]=i[1],f=n0(h,t,s,o,n,f)):i[1]!==0&&(f=n0(h,t,i,o,n,f)),o=0):o&&(m.type==="data"||m.type==="tableDelimiterMarker"||m.type==="tableDelimiterFiller")&&(i[3]=n)}for(l!==0&&A4(h,t,l,c,d),h.consume(t.events),n=-1;++n<t.events.length;){const p=t.events[n];p[0]==="enter"&&p[1].type==="table"&&(p[1]._align=OBe(t.events,n))}return e}function n0(e,t,n,r,o,s){const i=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",a="tableContent";n[0]!==0&&(s.end=Object.assign({},Ad(t.events,n[0])),e.add(n[0],0,[["exit",s,t]]));const l=Ad(t.events,n[1]);if(s={type:i,start:Object.assign({},l),end:Object.assign({},l)},e.add(n[1],0,[["enter",s,t]]),n[2]!==0){const c=Ad(t.events,n[2]),d=Ad(t.events,n[3]),f={type:a,start:Object.assign({},c),end:Object.assign({},d)};if(e.add(n[2],0,[["enter",f,t]]),r!==2){const h=t.events[n[2]],p=t.events[n[3]];if(h[1].end=Object.assign({},p[1].end),h[1].type="chunkText",h[1].contentType="text",n[3]>n[2]+1){const m=n[2]+1,g=n[3]-n[2]-1;e.add(m,g,[])}}e.add(n[3]+1,0,[["exit",f,t]])}return o!==void 0&&(s.end=Object.assign({},Ad(t.events,o)),e.add(o,0,[["exit",s,t]]),s=void 0),s}function A4(e,t,n,r,o){const s=[],i=Ad(t.events,n);o&&(o.end=Object.assign({},i),s.push(["exit",o,t])),r.end=Object.assign({},i),s.push(["exit",r,t]),e.add(n+1,0,s)}function Ad(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const zBe={name:"tasklistCheck",tokenize:VBe};function BBe(){return{text:{91:zBe}}}function VBe(e,t,n){const r=this;return o;function o(l){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(l):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(l),e.exit("taskListCheckMarker"),s)}function s(l){return mn(l)?(e.enter("taskListCheckValueUnchecked"),e.consume(l),e.exit("taskListCheckValueUnchecked"),i):l===88||l===120?(e.enter("taskListCheckValueChecked"),e.consume(l),e.exit("taskListCheckValueChecked"),i):n(l)}function i(l){return l===93?(e.enter("taskListCheckMarker"),e.consume(l),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),a):n(l)}function a(l){return Ge(l)?t(l):Nt(l)?e.check({tokenize:HBe},t,n)(l):n(l)}}function HBe(e,t,n){return Lt(e,r,"whitespace");function r(o){return o===null?n(o):t(o)}}function UBe(e){return oK([mBe(),NBe(),TBe(e),FBe(),BBe()])}const WBe={};function qBe(e){const t=this,n=e||WBe,r=t.data(),o=r.micromarkExtensions||(r.micromarkExtensions=[]),s=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),i=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);o.push(UBe(n)),s.push(dBe()),i.push(fBe(n))}function I4({text:e,handleRun:t,className:n}){const r=ee(s=>s.themeStyle),o={p:({node:s,...i})=>u.jsx("p",{className:Z("text-sm leading-relaxed mb-4 text-foreground/90",n),...i}),code:({node:s,...i})=>{var l,c;const a=(c=(l=s==null?void 0:s.children)==null?void 0:l[0])==null?void 0:c.value;return a&&/^#([0-9a-fA-F]{6})$/.test(a)?u.jsx("code",{className:Z("rounded-lg bg-muted px-2.5 py-1.5 text-sm font-mono",n),style:{backgroundColor:a},...i}):u.jsx("code",{className:Z("rounded-lg bg-muted/50 border border-border/50 px-2 py-1 text-sm font-mono text-foreground/80 transition-colors hover:bg-muted/70",n),...i})},pre:s=>u.jsx(F9e,{...s,handleRun:t}),ul:({node:s,...i})=>u.jsx("ul",{className:Z("mb-4 ml-6 list-disc space-y-2 text-sm marker:text-muted-foreground",n),...i}),ol:({node:s,...i})=>u.jsx("ol",{className:Z("mb-4 ml-6 list-decimal space-y-2 text-sm marker:text-muted-foreground",n),...i}),li:({node:s,...i})=>u.jsx("li",{className:Z("pl-2 leading-relaxed text-foreground/90",n),...i}),a:({node:s,...i})=>u.jsx("a",{target:"_blank",rel:"noopener noreferrer",className:Z("text-blue-600 underline underline-offset-2 decoration-1 transition-all hover:text-blue-700 hover:decoration-2",n),...i}),h1:({node:s,...i})=>u.jsx("h1",{className:Z("text-2xl font-semibold tracking-tight mb-4 mt-6 text-foreground",n),...i}),h2:({node:s,...i})=>u.jsx("h2",{className:Z("text-xl font-semibold tracking-tight mb-3 mt-5 text-foreground",n),...i}),h3:({node:s,...i})=>u.jsx("h3",{className:Z("text-lg font-medium mb-2 mt-4 text-foreground",n),...i}),h4:({node:s,...i})=>u.jsx("h4",{className:Z("text-base font-medium mb-2 mt-3 text-foreground/90",n),...i}),strong:({node:s,...i})=>u.jsx("strong",{className:Z("font-semibold text-foreground",n),...i}),blockquote:({node:s,...i})=>u.jsx("blockquote",{className:Z("my-4 border-l-4 border-muted-foreground/30 bg-muted/20 pl-4 pr-4 py-3 italic text-foreground/80 rounded-r-md",n),...i}),table:({node:s,...i})=>u.jsx("div",{className:"my-6 overflow-x-auto rounded-lg border border-border/50 shadow-sm",children:u.jsx("table",{className:Z("w-full table-auto border-collapse text-sm",n),...i})}),thead:({node:s,...i})=>{var a,l,c,d,f,h;return u.jsx("thead",{style:{backgroundColor:(c=(l=(a=r==null?void 0:r.chart)==null?void 0:a.dataset)==null?void 0:l.backgroundColor)==null?void 0:c[0],color:Fa((h=(f=(d=r==null?void 0:r.chart)==null?void 0:d.dataset)==null?void 0:f.backgroundColor)==null?void 0:h[0])},className:"sticky top-0",...i})},tr:({node:s,...i})=>u.jsx("tr",{className:Z("border-b border-border/30 transition-colors hover:bg-muted/30 last:border-0",n),...i}),th:({node:s,...i})=>u.jsx("th",{className:Z("px-4 py-3 text-left font-medium text-sm tracking-wide",n),...i}),td:({node:s,...i})=>u.jsx("td",{className:Z("px-4 py-3 align-top text-foreground/90",n),...i})};return u.jsx(j8e,{components:o,remarkPlugins:[qBe],children:e})}const zu=["image/png","image/jpeg","image/jpg","image/gif","image/webp"],GBe=["application/pdf","text/plain","text/markdown"],YBe=["text/csv","application/json","text/xml","application/xml"],ZBe=["text/javascript","application/javascript","text/typescript","application/x-typescript","text/x-python","application/x-python-code","text/x-sql","application/sql"],KBe=[...zu,...GBe,...YBe,...ZBe],JK=10*1024*1024,wa=5,eX={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".pdf":"application/pdf",".txt":"text/plain",".md":"text/markdown",".csv":"text/csv",".json":"application/json",".xml":"text/xml",".js":"text/javascript",".jsx":"text/javascript",".ts":"text/typescript",".tsx":"text/typescript",".py":"text/x-python",".sql":"text/x-sql"};function XBe(e){if(KBe.includes(e.type))return!0;const t=PD(e.name);return t?Object.prototype.hasOwnProperty.call(eX,t):!1}function PD(e){const t=e.lastIndexOf(".");return t===-1?"":e.substring(t).toLowerCase()}function tX(e){if(e.type)return e.type;const t=PD(e.name);return eX[t]||"application/octet-stream"}function QBe(e){return e.size<=JK}function hg(e){if(e===0)return"0 Bytes";const t=1024,n=["Bytes","KB","MB","GB"],r=Math.floor(Math.log(e)/Math.log(t));return Math.round(e/Math.pow(t,r)*100)/100+" "+n[r]}function O4(e){return new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{const s=r.result.split(",")[1];t(s)},r.onerror=n,r.readAsDataURL(e)})}function JBe(e){return new Promise((t,n)=>{if(!zu.includes(tX(e))){n(new Error("Not an image file"));return}const r=new FileReader;r.onload=()=>t(r.result),r.onerror=n,r.readAsDataURL(e)})}async function TD(e){const t=tX(e),n=zu.includes(t),r={id:crypto.randomUUID(),name:e.name,size:e.size,type:t};if(n)try{r.preview=await JBe(e),r.data=r.preview.split(",")[1]}catch(o){console.error("Failed to create image preview:",o),r.data=await O4(e)}else r.data=await O4(e);return r}function nX(e){const t=[],n=[];for(const r of e)XBe(r)?QBe(r)?t.push(r):n.push({file:r,error:`File too large: ${hg(r.size)} (max ${hg(JK)})`}):n.push({file:r,error:`File type not supported: ${r.type||PD(r.name)}`});return{valid:t,errors:n}}function eVe(e){var r;const t=(r=e.clipboardData)==null?void 0:r.items;if(!t)return[];const n=[];for(let o=0;o<t.length;o++){const s=t[o];if(s.kind==="file"){const i=s.getAsFile();i&&zu.includes(i.type)&&n.push(i)}}return n}function tVe({files:e,onRemove:t,showRemove:n=!0,className:r=""}){if(e.length===0)return null;const o=s=>zu.includes(s)?Ine:s.includes("pdf")||s.includes("text")?Ko:s.includes("javascript")||s.includes("typescript")||s.includes("python")||s.includes("sql")?Ane:J3;return u.jsx("div",{className:`flex flex-wrap gap-2 ${r}`,children:e.map(s=>{const i=o(s.type),a=zu.includes(s.type);return u.jsxs("div",{className:"group relative flex items-center gap-2 rounded-lg border border-border bg-muted/50 p-2 transition-colors hover:bg-muted",children:[a&&s.preview?u.jsx("div",{className:"relative h-12 w-12 overflow-hidden rounded",children:u.jsx("img",{src:s.preview,alt:s.name,className:"h-full w-full object-cover"})}):u.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded bg-background",children:u.jsx(i,{className:"h-6 w-6 text-muted-foreground"})}),u.jsxs("div",{className:"flex flex-col",children:[u.jsx("span",{className:"max-w-[150px] truncate text-xs font-medium",children:s.name}),u.jsx("span",{className:"text-xs text-muted-foreground",children:hg(s.size)}),s.uploadProgress!==void 0&&s.uploadProgress<100&&u.jsx(TM,{value:s.uploadProgress,className:"mt-1 h-1 w-full"})]}),n&&t&&u.jsx(ae,{variant:"ghost",size:"icon",className:"absolute -right-2 -top-2 h-5 w-5 rounded-full bg-background opacity-0 shadow-sm transition-opacity group-hover:opacity-100",onClick:()=>t(s.id),children:u.jsx(Xt,{className:"h-3 w-3"})})]},s.id)})})}function nVe({file:e,className:t=""}){return zu.includes(e.type)&&e.preview?u.jsxs("div",{className:`inline-block ${t}`,children:[u.jsx("img",{src:e.preview,alt:e.name,className:"max-h-64 max-w-full rounded-lg border border-border"}),u.jsxs("div",{className:"mt-1 text-xs text-muted-foreground",children:[e.name," • ",hg(e.size)]})]}):u.jsxs("div",{className:`inline-flex items-center gap-2 rounded-lg border border-border bg-muted/50 px-3 py-2 ${t}`,children:[u.jsx(Ko,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm",children:e.name}),u.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",hg(e.size),")"]})]})}const F4={"tool-getTableColumns":{"input-streaming":"Fetching table columns...","input-available":"Reading column definitions..."},"tool-getChartDataFromSqlAndPython":{"input-streaming":"Planning...","input-available":"Fetching data..."},"tool-getChartDataFromCardConfig":{"input-streaming":"Planning...","input-available":"Fetching data..."},"tool-getForecastDataFromSqlAndPython":{"input-streaming":"Planning...","input-available":"Fetching data..."},"tool-getChartSQLSyntax":{"input-streaming":"Generating SQL syntax...","input-available":"SQL syntax generated"},"tool-validateCardConfigFormat":{"input-streaming":"Validating card config format...","input-available":"Card config format validated"},"tool-generateQueryConfig":{"input-streaming":"Generating query config...","input-available":"Sending query config..."},"tool-askForMoreInfo":{"input-streaming":"Asking for more information...","input-available":"More information requested"},"tool-createChartFromSql":{"input-streaming":"Creating chart...","input-available":"Chart created"},"tool-getUserSql":{"input-streaming":"Getting SQL...","input-available":"SQL retrieved"},"tool-inspectTableData":{"input-streaming":"Inspecting table data...","input-available":"Analyzing data..."}};function rX(e,t){var r;if((r=F4[e])!=null&&r[t])return F4[e][t];const n=e.replace("tool-","").replace(/([A-Z])/g," $1").toLowerCase().trim();return t==="input-streaming"?`Processing ${n}...`:`Preparing ${n} response...`}var AD="Collapsible",[rVe,oX]=mr(AD),[oVe,ID]=rVe(AD),sX=k.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[l=!1,c]=Rr({prop:r,defaultProp:o,onChange:i});return u.jsx(oVe,{scope:n,disabled:s,contentId:Yn(),open:l,onOpenToggle:k.useCallback(()=>c(d=>!d),[c]),children:u.jsx(Te.div,{"data-state":LD(l),"data-disabled":s?"":void 0,...a,ref:t})})});sX.displayName=AD;var iX="CollapsibleTrigger",OD=k.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=ID(iX,n);return u.jsx(Te.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":LD(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:we(e.onClick,o.onOpenToggle)})});OD.displayName=iX;var FD="CollapsibleContent",$D=k.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ID(FD,e.__scopeCollapsible);return u.jsx(Zn,{present:n||o.open,children:({present:s})=>u.jsx(sVe,{...r,ref:t,present:s})})});$D.displayName=FD;var sVe=k.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=ID(FD,n),[a,l]=k.useState(r),c=k.useRef(null),d=ot(t,c),f=k.useRef(0),h=f.current,p=k.useRef(0),m=p.current,g=i.open||a,y=k.useRef(g),b=k.useRef(void 0);return k.useEffect(()=>{const x=requestAnimationFrame(()=>y.current=!1);return()=>cancelAnimationFrame(x)},[]),jr(()=>{const x=c.current;if(x){b.current=b.current||{transitionDuration:x.style.transitionDuration,animationName:x.style.animationName},x.style.transitionDuration="0s",x.style.animationName="none";const v=x.getBoundingClientRect();f.current=v.height,p.current=v.width,y.current||(x.style.transitionDuration=b.current.transitionDuration,x.style.animationName=b.current.animationName),l(r)}},[i.open,r]),u.jsx(Te.div,{"data-state":LD(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!g,...s,ref:d,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":m?`${m}px`:void 0,...e.style},children:g&&o})});function LD(e){return e?"open":"closed"}var aX=sX,iVe=OD,aVe=$D;const oh=aX,sh=OD,ih=$D;function lVe({part:e,showTools:t}){if(!t)return null;const{input:n,output:r,...o}=e;return e.type,u.jsx("div",{className:"space-y-3",children:t&&u.jsxs(oh,{children:[u.jsxs("div",{className:"inline-flex items-center gap-2",children:[u.jsxs(sh,{className:"rounded-md border border-foreground/20 p-1 px-2 font-mono text-xs text-foreground/80 hover:bg-foreground/5",children:[u.jsx("span",{className:"font-bold",children:"Tool:"})," ",e.type.split("-")[1]]}),Iv]}),u.jsx(ih,{className:"mt-2 font-mono text-xs",children:u.jsxs("div",{className:"space-y-2 px-2",children:[u.jsxs("div",{className:"space-y-1",children:[u.jsx("span",{children:"Args:"}),u.jsx(zl,{language:"json",code:JSON.stringify(o,null,2)})]}),u.jsxs("div",{className:"space-y-1",children:[u.jsx("span",{children:"Input:"}),u.jsx(zl,{language:"json",code:JSON.stringify(n,null,2)})]}),u.jsxs("div",{className:"space-y-1",children:[u.jsx("span",{children:"Output:"}),u.jsx(zl,{language:"json",code:JSON.stringify(r,null,2)})]})]})})]})})}function cVe(){const{authToken:e,tokenProps:t}=qe(),{currentUser:n}=ea(),r=Ji({mutationFn:async o=>{if(!(e!=null&&e.accessToken))throw new Error("No authentication token available");const i=`${t.apiServiceUrl||""}/v1/feedback`,a={...o,user:n,tokenContext:t},l=await nc(i,e.accessToken,a,"POST");if(!l||!l.success)throw new Error((l==null?void 0:l.error)||"Failed to send feedback");return l},onSuccess:o=>{Ue.success(`Feedback sent successfully! Issue: ${o.issueNumber}`,{duration:5e3})},onError:o=>{console.error("Feedback submission error:",o),Ue.error("Failed to send feedback. Please try again later.",{duration:5e3})}});return{sendFeedback:r.mutate,sendFeedbackAsync:r.mutateAsync,isLoading:r.isPending,isSuccess:r.isSuccess,isError:r.isError,error:r.error,data:r.data,reset:r.reset}}function zD(e,t,n){return{category:e,userMessage:n,systemState:t,metadata:{url:window.location.href,userAgent:navigator.userAgent,timestamp:new Date().toISOString(),viewport:`${window.innerWidth}x${window.innerHeight}`}}}function yv({open:e,onOpenChange:t,feedbackData:n}){var g,y,b,x,v,w,S,E,C,_,j,R,P;const[r,o]=N.useState(""),[s,i]=N.useState(!1),{sendFeedback:a,isLoading:l,isSuccess:c,data:d,reset:f}=cVe(),h=()=>{const M={...n,userMessage:r.trim()||void 0};a(M)},p=()=>{o(""),i(!1),f(),t(!1)},m={category:n.category,error:{message:(g=n.systemState)==null?void 0:g.errorMessage,sql:(y=n.systemState)==null?void 0:y.generatedSql,errorSql:(b=n.systemState)==null?void 0:b.errorSql},assistantType:(x=n.systemState)==null?void 0:x.assistantType,toolType:(v=n.systemState)==null?void 0:v.toolType,userQuery:(w=n.systemState)==null?void 0:w.userQuery,messages:(S=n.systemState)==null?void 0:S.messages,aiContext:(E=n.systemState)==null?void 0:E.aiContext,toolInput:(C=n.systemState)==null?void 0:C.toolInput,toolOutput:(_=n.systemState)==null?void 0:_.toolOutput,cardConfig:(j=n.systemState)==null?void 0:j.cardConfig,dataSource:(R=n.systemState)==null?void 0:R.dataSource,filters:(P=n.systemState)==null?void 0:P.dashboardFilters,metadata:n.metadata};return u.jsx(_s,{open:e,onOpenChange:p,children:u.jsxs(ns,{className:"max-w-2xl",children:[u.jsxs(rs,{children:[u.jsx(os,{children:c?"Feedback Sent Successfully":n.category==="dashboard-assistant"?"Report Dashboard Assistant Issue":n.category==="editor-assistant"?"Report Editor Assistant Issue":"Report Query Generation Issue"}),u.jsx(ci,{children:c?`Your feedback has been submitted with issue number: ${d==null?void 0:d.issueNumber}`:n.category==="dashboard-assistant"||n.category==="editor-assistant"?"Help us improve by reporting this AI assistant issue. Your feedback will be sent to our support team.":"Help us improve by reporting this query generation issue. Your feedback will be sent to our support team."})]}),!c&&u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(de,{htmlFor:"message",children:"Additional Information (Optional)"}),u.jsx(ph,{id:"message",placeholder:"Please describe what you were trying to do when this error occurred...",value:r,onChange:M=>o(M.target.value),className:"min-h-[100px] resize-none ring-inset focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0",disabled:l})]}),u.jsxs(oh,{open:s,onOpenChange:i,children:[u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsx(sh,{asChild:!0,children:u.jsxs(ae,{variant:"ghost",size:"sm",className:"flex flex-1 items-center justify-between p-2 hover:bg-muted",children:[u.jsx("span",{className:"text-sm font-medium",children:"View data to be sent"}),s?u.jsx(No,{className:"h-4 w-4"}):u.jsx(Js,{className:"h-4 w-4"})]})}),u.jsx(Fu,{text:JSON.stringify(m,null,2),className:"h-8 w-8 shrink-0"})]}),u.jsx(ih,{className:"mt-2",children:u.jsx(Yi,{className:"h-[300px] w-full rounded-md border bg-muted/50 p-4",children:u.jsx("div",{className:"text-xs overflow-auto break-all whitespace-pre-wrap",children:u.jsx(zl,{code:JSON.stringify(m,null,2),language:"json"})})})})]})]}),u.jsxs(js,{children:[u.jsx(ae,{variant:"outline",onClick:p,disabled:l,children:"Cancel"}),u.jsx(ae,{onClick:h,disabled:l,className:"min-w-[100px]",children:l?u.jsxs(u.Fragment,{children:[u.jsx(Cs,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):"Send Feedback"})]})]}),c&&u.jsxs("div",{className:"flex flex-col items-center space-y-4 py-6",children:[u.jsx(Dne,{className:"h-12 w-12 text-green-600"}),u.jsxs("div",{className:"text-center",children:[u.jsx("p",{className:"text-lg font-medium",children:"Thank you for your feedback!"}),u.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:["Issue Number:"," ",u.jsx("span",{className:"font-mono font-medium",children:d==null?void 0:d.issueNumber})]}),u.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Our support team will review your feedback and take appropriate action."})]}),u.jsx(ae,{onClick:p,className:"mt-4",children:"Close"})]})]})})}var ah=(e=>(e.QUERY_GENERATION="query-generation",e.DASHBOARD_ASSISTANT="dashboard-assistant",e.EDITOR_ASSISTANT="editor-assistant",e))(ah||{});function uVe({part:e,messages:t}){const[n,r]=N.useState(!1),[o,s]=N.useState(null),i=x6(),a=Pg(),{tokenProps:l}=N.useContext(Rg);ea();const c=()=>{var g;const d=t==null?void 0:t.filter(y=>y.role==="user").pop(),f=(g=d==null?void 0:d.parts)==null?void 0:g.find(y=>y.type==="text"),h=(f==null?void 0:f.text)||"",p=i==="dashboard"?ah.DASHBOARD_ASSISTANT:ah.EDITOR_ASSISTANT,m=zD(p,{errorMessage:e.errorText||"Tool invocation error occurred",toolType:e.type,toolInput:e.input,toolOutput:null,assistantType:i,userQuery:h,messages:t,aiContext:a});s(m),r(!0)};return u.jsxs(u.Fragment,{children:[u.jsxs(oh,{children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(sh,{className:"",children:u.jsxs(de,{className:"flex cursor-pointer items-center hover:text-foreground",children:[u.jsx(j_,{className:"mr-2 size-4 text-yellow-500"}),"Recovering from Error"]})}),u.jsxs(ae,{variant:"ghost",size:"sm",className:"gap-1 text-[11px]",onClick:c,"aria-label":"Send feedback",children:[u.jsx(S_,{className:"h-3 w-3"}),"Send Feedback"]})]}),u.jsx(ih,{className:"mt-2 text-xs",children:u.jsxs("div",{className:"relative space-y-2 rounded-md border border-yellow-500 bg-yellow-50 p-4 text-black/80 dark:border-yellow-500/80 dark:bg-yellow-500/10 dark:text-white/80",children:[u.jsxs(de,{className:"text-xs",children:["Tool Invocation Error (",e.type.split("-")[1],")"]}),u.jsx("p",{children:e.errorText})]})})]}),o&&u.jsx(yv,{open:n,onOpenChange:d=>{r(d),d||s(null)},feedbackData:o})]})}const H1={connectionId:"",connectionType:"none",mode:"semanticDomain",selectedEntities:[]},$4=N.memo(({cfg:e,onDatapointClick:t})=>u.jsx(l1,{cfg:e,onDatapointClick:t}),(e,t)=>JSON.stringify(e.cfg)===JSON.stringify(t.cfg)&&e.onDatapointClick===t.onDatapointClick);function dVe({part:e,onAddToDashboard:t,messages:n,showTools:r=!1}){var z,L;const o=e.output,s=e.input,[i,a]=N.useState(!1),[l,c]=N.useState(!1),[d,f]=N.useState("visual"),[h,p]=N.useState(!1),[m,g]=N.useState(null),y=N.useMemo(()=>(e==null?void 0:e.toolCallId)??br(),[e]),{queueMessage:b}=mh(),x=x6(),v=Pg(),{tokenProps:w}=N.useContext(Rg);ea();const S=()=>{const D=e.toolCallId;T().label;const H=`Can you explain how this visual was calculated? [ref: ${D}]`;b("dashboard",H)},E=()=>{var B;console.log("Send Feedback clicked",{activeAssistantType:x,messages:n,output:o,input:s,part:e});const D=n==null?void 0:n.filter(G=>G.role==="user").pop(),H=(B=D==null?void 0:D.parts)==null?void 0:B.find(G=>G.type==="text"),q=(H==null?void 0:H.text)||"",Y=x==="dashboard"?ah.DASHBOARD_ASSISTANT:ah.EDITOR_ASSISTANT;console.log("Feedback category:",Y);const V=zD(Y,{errorMessage:(o==null?void 0:o.error)||"An error occurred while generating the visualization",toolType:e.type,toolInput:s,toolOutput:o,assistantType:x,userQuery:q,messages:n,aiContext:v,cardConfig:s==null?void 0:s.cardConfig,dataSource:o==null?void 0:o.dataSource,generatedSql:s==null?void 0:s.sql});console.log("Feedback payload prepared:",V),g(V),p(!0)},C=s==null?void 0:s.chartType,_=s==null?void 0:s.connectionId,j=s==null?void 0:s.cardConfig,R=s==null?void 0:s.chartTitle,P=s==null?void 0:s.sql,M=(z=o==null?void 0:o.data)==null?void 0:z.userSql,F=s==null?void 0:s.python,I=(L=o==null?void 0:o.data)==null?void 0:L.records,A=o==null?void 0:o.dataSource,O=N.useMemo(()=>C?{id:y,config:j,type:C,dataSource:A,preferences:{tablePrefs:{pageSize:10}}}:null,[y,j,C,A]),U=N.useMemo(()=>!O||C==="pivotTable"?null:OR({card:O,cardType:C,data:I||[],queryConfig:{}}),[O,C,I]),W=N.useMemo(()=>{var V,B,G,X;if(C!=="pivotTable"||!o)return null;const D=((V=o.data)==null?void 0:V.pivotSchema)||[],H=((B=o.data)==null?void 0:B.subtotalColumns)||[],q=(G=o.data)==null?void 0:G.columnSubtotalMeta,Y=(X=o.data)==null?void 0:X.groupByColumns;return{records:I||[],pivotSchema:D,subtotalColumns:H,columnSubtotalMeta:q,groupByColumns:Y}},[C,o,I]),$=ob(O,W),T=()=>{const D=O?nv(O):!1,H=u1.find(Y=>Y.id===C),q=H==null?void 0:H.icon;return F?{type:"advanced",label:"Advanced Analysis",icons:[nu,KP]}:D&&q?{type:"standard",label:"Standard Analysis",icons:[q]}:{type:"sql",label:"SQL Analysis",icons:[nu]}};if(!o)return null;if(o.error){const D=o.errorType||"unknown",H=o.hint||"",q=o.rootCause||o.error,Y=o.shouldRetry!==!1,V=o.validationErrors||[],B=o.suggestions||[],G=V.length>0,X=G?{border:"border-purple-500/60 dark:border-purple-500/50",bg:"bg-purple-50 dark:bg-purple-500/10",text:"text-purple-800 dark:text-purple-300",iconColor:"text-purple-600 dark:text-purple-500",accentBg:"bg-purple-100 dark:bg-purple-900/30",accentText:"text-purple-900 dark:text-purple-200"}:{border:"border-yellow-500/60 dark:border-yellow-500/50",bg:"bg-yellow-50 dark:bg-yellow-500/10",text:"text-yellow-800 dark:text-yellow-300",iconColor:"text-yellow-600 dark:text-yellow-500",accentBg:"bg-yellow-100 dark:bg-yellow-900/30",accentText:"text-yellow-900 dark:text-yellow-200"},re=()=>G?Y?"Configuration validation failed. Retrying...":"Configuration validation failed":D==="group_by_error"?Y?"SQL grouping error. Retrying...":"SQL grouping error":D==="syntax_error"?Y?"SQL syntax error. Retrying...":"SQL syntax error":D==="type_mismatch"?Y?"Data type mismatch. Retrying...":"Data type mismatch":Y?"Retrying...":"Couldn't generate this visual";if(!r){const J=Y?"Trying a different approach...":"I'm ready with a revised plan.",ue=H||(q&&q!==o.error?q:"");return u.jsx("div",{className:"mt-2 rounded-md border border-border/40 bg-muted/30 p-3 text-xs",children:u.jsxs("div",{className:"flex items-start gap-2",children:[u.jsx(k_,{className:"size-4 shrink-0 text-primary","aria-hidden":"true"}),u.jsxs("div",{className:"space-y-1 text-foreground/80",children:[u.jsx("div",{className:"font-medium text-foreground",children:J}),ue&&u.jsx("div",{className:"text-[11px] text-muted-foreground",children:ue})]})]})})}return u.jsxs(u.Fragment,{children:[u.jsx(oh,{open:l,onOpenChange:c,children:u.jsxs("div",{className:`relative space-y-2 rounded-md border ${X.border} ${X.bg} p-3 text-xs`,children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(j_,{className:`size-4 shrink-0 ${X.iconColor}`,"aria-hidden":"true"}),u.jsx("span",{className:`font-medium ${X.text}`,children:re()})]}),G&&u.jsx("div",{className:`text-[10px] ${X.text} opacity-80`,children:"Self-healing defense: Config validated before execution"}),q&&q!==o.error&&u.jsxs("div",{className:"text-foreground/80",children:[u.jsx("span",{className:"font-semibold",children:"Issue:"})," ",q]}),H&&u.jsxs("div",{className:`rounded-md ${X.accentBg} p-2 ${X.accentText}`,children:[u.jsx("span",{className:"font-semibold",children:"Fix:"})," ",H]}),V.length>0&&u.jsxs("div",{className:"space-y-1",children:[u.jsx("div",{className:`font-semibold ${X.text}`,children:"Configuration issues found:"}),u.jsxs("ul",{className:"ml-4 list-disc space-y-0.5",children:[V.slice(0,3).map((J,ue)=>u.jsx("li",{className:"text-foreground/70 dark:text-foreground/60",children:J},ue)),V.length>3&&u.jsxs("li",{className:"text-muted-foreground",children:["...and ",V.length-3," more"]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-1",children:[u.jsx(sh,{asChild:!0,children:u.jsxs(ae,{variant:"ghost",size:"sm",className:`gap-1 text-[11px] ${X.text}`,children:[l?"Hide":"View"," technical details",u.jsx(No,{className:`h-3 w-3 transition-transform ${l?"rotate-180":""}`})]})}),u.jsxs(ae,{variant:"ghost",size:"sm",className:`gap-1 text-[11px] ${X.text}`,onClick:E,children:[u.jsx(S_,{className:"h-3 w-3"}),"Report Issue"]})]}),u.jsxs(ih,{className:"mt-2 space-y-2",children:[B.length>0&&u.jsxs("div",{className:"rounded-md border border-blue-500/40 bg-background/60 p-2 dark:bg-background/40",children:[u.jsx("div",{className:"mb-1 text-[11px] font-semibold text-blue-900 dark:text-blue-200",children:"Suggested fixes:"}),u.jsx("ul",{className:"ml-3 list-disc space-y-1",children:B.map((J,ue)=>u.jsx("li",{className:"text-[11px] leading-relaxed text-foreground/80",children:J},ue))})]}),u.jsxs("div",{className:`rounded-md border ${X.border} bg-background/60 p-2 dark:bg-background/40`,children:[u.jsx("div",{className:`mb-1 text-[11px] font-semibold ${X.text}`,children:"Raw error:"}),u.jsx("pre",{className:"max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-[11px] leading-relaxed text-foreground/80",children:o.error})]})]})]})}),m&&u.jsx(yv,{open:h,onOpenChange:J=>{p(J),J||g(null)},feedbackData:m})]})}return u.jsxs(u.Fragment,{children:[u.jsxs(Li,{className:"grid w-full max-w-full grid-cols-1 border border-muted bg-background shadow-sm",children:[u.jsx(zi,{className:"pb-3",children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"space-y-1",children:u.jsx("h3",{className:"text-base font-semibold text-foreground",children:R||"Untitled Chart"})}),u.jsxs("div",{className:"flex items-center gap-2",children:[C!=="table"&&C!=="pivotTable"&&u.jsx(di,{value:d,onValueChange:f,children:u.jsxs(Rs,{className:"h-8",children:[u.jsx(Ln,{value:"visual",className:"h-7 w-7 p-0","aria-label":"View as chart",children:u.jsx(Mg,{className:"h-3.5 w-3.5"})}),u.jsx(Ln,{value:"table",className:"h-7 w-7 p-0","aria-label":"View as table",children:u.jsx(Uv,{className:"h-3.5 w-3.5"})})]})}),u.jsx(ae,{variant:"outline",size:"sm",className:"h-8 w-8 p-0",onClick:()=>{t==null||t({sql:P||"",data:I||[],dataSource:A||H1,cardConfig:j,cardTitle:R||"Untitled Chart",connectionId:_||"",cardType:C||"bar",python:F||""})},"aria-label":"Add visual to dashboard",children:u.jsx(Xo,{className:"h-4 w-4"})})]})]})}),u.jsxs(Wa,{className:"space-y-4",children:[u.jsx("div",{className:Z("isolate flex w-full grow flex-col",C!=="table"&&C!=="pivotTable"&&"min-h-[360px]"),children:u.jsx("div",{className:"flex grow flex-col",children:C==="table"&&O?u.jsx("div",{className:"min-w-0",children:u.jsx(Zm,{card:O,data:I||[],isLoading:!1})}):C==="pivotTable"&&$&&O?u.jsx(c1,{data:$.data,card:O,options:$.options}):U&&C!=="table"&&C!=="pivotTable"?d==="table"?u.jsx("div",{className:"min-w-0 pb-6",children:u.jsx(Zm,{card:O,data:I||[],isLoading:!1})}):u.jsx($4,{cfg:U}):U&&u.jsx($4,{cfg:U})})}),(P||F||O&&nv(O))&&u.jsxs(oh,{open:i,onOpenChange:a,children:[u.jsxs("div",{className:"flex items-center justify-between border-t border-muted/40 pb-2 pt-2",children:[u.jsx("div",{className:"flex items-center gap-2",children:(()=>{const D=T();return u.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[D.icons.map((H,q)=>u.jsx(H,{className:"h-3 w-3"},q)),u.jsx("span",{children:D.label}),u.jsx(ae,{variant:"ghost",size:"sm",className:"h-4 w-4 p-0 hover:text-foreground",onClick:S,title:"Ask for explanation",children:u.jsx(uh,{className:"h-3 w-3"})})]})})()}),u.jsx(sh,{asChild:!0,children:u.jsxs(ae,{variant:"ghost",size:"sm",className:"gap-1 text-xs",children:[i?"Hide Details":"Show Details",u.jsx(No,{className:`h-3 w-3 transition-transform ${i?"rotate-180":""}`})]})})]}),u.jsxs(ih,{className:"space-y-3 pb-6",children:[M&&u.jsxs("div",{className:"space-y-2",children:[u.jsxs("div",{className:"flex items-center justify-between gap-2",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(nu,{className:"h-4 w-4 text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-foreground",children:"SQL Query"})]}),u.jsx(Fu,{text:M,className:"-mr-1"})]}),u.jsx("div",{className:"rounded-md border bg-muted/30",children:u.jsx(zl,{language:"sql",code:M})})]}),F&&u.jsxs("div",{className:"space-y-2",children:[u.jsxs("div",{className:"flex items-center justify-between gap-2",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(KP,{className:"h-4 w-4 text-green-600"}),u.jsx("span",{className:"text-sm font-medium text-foreground",children:"Python"})]}),u.jsx(Fu,{text:F,className:"-mr-1"})]}),u.jsx("div",{className:"rounded-md border bg-muted/30",children:u.jsx(zl,{language:"python",code:F})})]})]})]})]})]}),m&&u.jsx(yv,{open:h,onOpenChange:D=>{p(D),D||g(null)},feedbackData:m})]})}const fVe=["tool-getChartDataFromSqlAndPython","tool-getChartDataFromCardConfig","tool-getForecastDataFromSqlAndPython","tool-generateQueryConfig"];function hVe({part:e,idx:t,showTools:n,onAddToDashboard:r,messages:o}){if(!e.state)return null;if(e.state==="input-streaming"||e.state==="input-available"){const s=rX(e.type,e.state);return u.jsx(pVe,{text:s})}if(e.state==="output-available"){const s=fVe.includes(e.type);return u.jsxs("div",{className:"my-2 space-y-2",children:[n&&u.jsx(lVe,{part:e,showTools:n}),s&&r&&u.jsx(dVe,{part:e,onAddToDashboard:r,messages:o,showTools:n})]},t)}return e.state==="output-error"?n?u.jsx("div",{className:"mt-2",children:u.jsx(uVe,{part:e,messages:o})},t):u.jsx("div",{className:"my-2 rounded-md border border-border/40 bg-muted/30 px-3 py-2 text-sm text-muted-foreground",children:"I hit a snag while working on that and will adjust the approach."},t):u.jsx("div",{},t)}function pVe({text:e}){return u.jsx("div",{className:"mt-2 animate-pulse text-sm text-muted-foreground",children:e})}const L4=/```quickreply\s*([\s\S]*?)```/i;function mVe(e){let t=e,n=null;const r=e.toLowerCase().indexOf("```quickreply");if(r!==-1){const i=e.match(L4);if(i)n=i[1].trim(),t=e.replace(i[0],"").trim();else return{cleanedText:e.slice(0,r).trimEnd(),quickReplies:[]}}else{const i=e.match(L4);i&&(n=i[1].trim(),t=e.replace(i[0],"").trim())}const o=t===e?e.toLowerCase().indexOf("quickreply"):-1;if(!n&&o!==-1){const i=e.indexOf("{",o);if(i!==-1){let a=0,l=-1;for(let c=i;c<e.length;c++){const d=e[c];if(d==="{")a++;else if(d==="}"&&(a--,a===0)){l=c;break}}if(l!==-1)n=e.slice(i,l+1).trim(),t=(e.slice(0,o)+e.slice(l+1)).trim();else return{cleanedText:e.slice(0,o).trimEnd(),quickReplies:[]}}else return{cleanedText:e.slice(0,o).trimEnd(),quickReplies:[]}}let s=[];if(n)try{const i=JSON.parse(n);s=(Array.isArray(i==null?void 0:i.options)?i.options:[]).map(l=>{const c=typeof(l==null?void 0:l.label)=="string"?l.label.trim():"",d=typeof(l==null?void 0:l.value)=="string"?l.value.trim():"";return c&&d?{label:c,value:d}:null}).filter(Boolean)}catch{s=[]}return{cleanedText:t.trim(),quickReplies:s}}function gVe(e){if(e==null)return"Something went wrong.";if(e instanceof Error)return e.message||"Something went wrong.";const t=r=>{if(!r||typeof r!="object")return null;const o=r.error&&typeof r.error=="object"?r.error:r,s=typeof o.code=="string"&&o.code?o.code.trim():"",i=typeof o.docs=="string"&&o.docs?`
925
+ `))}function l(p,m,g,y){const b=g.enter("tableCell"),x=g.enter("phrasing"),v=g.containerPhrasing(p,{...y,before:s,after:s});return x(),b(),v}function c(p,m){return v7e(p,{align:m,alignDelimiters:r,padding:n,stringLength:o})}function d(p,m,g){const y=p.children;let b=-1;const x=[],v=m.enter("table");for(;++b<y.length;)x[b]=f(y[b],m,g);return v(),x}function f(p,m,g){const y=p.children;let b=-1;const x=[],v=m.enter("tableRow");for(;++b<y.length;)x[b]=l(y[b],p,m,g);return v(),x}function h(p,m,g){let y=UK.inlineCode(p,m,g);return g.stack.includes("tableCell")&&(y=y.replace(/\|/g,"\\$&")),y}}function aBe(){return{exit:{taskListCheckValueChecked:T4,taskListCheckValueUnchecked:T4,paragraph:cBe}}}function lBe(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:uBe}}}function T4(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function cBe(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const r=n.children[0];if(r&&r.type==="text"){const o=t.children;let s=-1,i;for(;++s<o.length;){const a=o[s];if(a.type==="paragraph"){i=a;break}}i===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(e)}function uBe(e,t,n,r){const o=e.children[0],s=typeof e.checked=="boolean"&&o&&o.type==="paragraph",i="["+(e.checked?"x":" ")+"] ",a=n.createTracker(r);s&&a.move(i);let l=UK.listItem(e,t,n,{...r,...a.current()});return s&&(l=l.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,c)),l;function c(d){return d+i}}function dBe(){return[H9e(),u7e(),p7e(),eBe(),aBe()]}function fBe(e){return{extensions:[U9e(),d7e(e),m7e(),iBe(e),lBe()]}}const hBe={tokenize:xBe,partial:!0},WK={tokenize:vBe,partial:!0},qK={tokenize:wBe,partial:!0},GK={tokenize:SBe,partial:!0},pBe={tokenize:CBe,partial:!0},YK={name:"wwwAutolink",tokenize:bBe,previous:KK},ZK={name:"protocolAutolink",tokenize:yBe,previous:XK},rl={name:"emailAutolink",tokenize:gBe,previous:QK},ua={};function mBe(){return{text:ua}}let Cc=48;for(;Cc<123;)ua[Cc]=rl,Cc++,Cc===58?Cc=65:Cc===91&&(Cc=97);ua[43]=rl;ua[45]=rl;ua[46]=rl;ua[95]=rl;ua[72]=[rl,ZK];ua[104]=[rl,ZK];ua[87]=[rl,YK];ua[119]=[rl,YK];function gBe(e,t,n){const r=this;let o,s;return i;function i(f){return!Fk(f)||!QK.call(r,r.previous)||DD(r.events)?n(f):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),a(f))}function a(f){return Fk(f)?(e.consume(f),a):f===64?(e.consume(f),l):n(f)}function l(f){return f===46?e.check(pBe,d,c)(f):f===45||f===95||Ur(f)?(s=!0,e.consume(f),l):d(f)}function c(f){return e.consume(f),o=!0,l}function d(f){return s&&o&&oo(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(f)):n(f)}}function bBe(e,t,n){const r=this;return o;function o(i){return i!==87&&i!==119||!KK.call(r,r.previous)||DD(r.events)?n(i):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(hBe,e.attempt(WK,e.attempt(qK,s),n),n)(i))}function s(i){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(i)}}function yBe(e,t,n){const r=this;let o="",s=!1;return i;function i(f){return(f===72||f===104)&&XK.call(r,r.previous)&&!DD(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),o+=String.fromCodePoint(f),e.consume(f),a):n(f)}function a(f){if(oo(f)&&o.length<5)return o+=String.fromCodePoint(f),e.consume(f),a;if(f===58){const h=o.toLowerCase();if(h==="http"||h==="https")return e.consume(f),l}return n(f)}function l(f){return f===47?(e.consume(f),s?c:(s=!0,l)):n(f)}function c(f){return f===null||hv(f)||mn(f)||Lu(f)||O1(f)?n(f):e.attempt(WK,e.attempt(qK,d),n)(f)}function d(f){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(f)}}function xBe(e,t,n){let r=0;return o;function o(i){return(i===87||i===119)&&r<3?(r++,e.consume(i),o):i===46&&r===3?(e.consume(i),s):n(i)}function s(i){return i===null?n(i):t(i)}}function vBe(e,t,n){let r,o,s;return i;function i(c){return c===46||c===95?e.check(GK,l,a)(c):c===null||mn(c)||Lu(c)||c!==45&&O1(c)?l(c):(s=!0,e.consume(c),i)}function a(c){return c===95?r=!0:(o=r,r=void 0),e.consume(c),i}function l(c){return o||r||!s?n(c):t(c)}}function wBe(e,t){let n=0,r=0;return o;function o(i){return i===40?(n++,e.consume(i),o):i===41&&r<n?s(i):i===33||i===34||i===38||i===39||i===41||i===42||i===44||i===46||i===58||i===59||i===60||i===63||i===93||i===95||i===126?e.check(GK,t,s)(i):i===null||mn(i)||Lu(i)?t(i):(e.consume(i),o)}function s(i){return i===41&&r++,e.consume(i),o}}function SBe(e,t,n){return r;function r(a){return a===33||a===34||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===63||a===95||a===126?(e.consume(a),r):a===38?(e.consume(a),s):a===93?(e.consume(a),o):a===60||a===null||mn(a)||Lu(a)?t(a):n(a)}function o(a){return a===null||a===40||a===91||mn(a)||Lu(a)?t(a):r(a)}function s(a){return oo(a)?i(a):n(a)}function i(a){return a===59?(e.consume(a),r):oo(a)?(e.consume(a),i):n(a)}}function CBe(e,t,n){return r;function r(s){return e.consume(s),o}function o(s){return Ur(s)?n(s):t(s)}}function KK(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||mn(e)}function XK(e){return!oo(e)}function QK(e){return!(e===47||Fk(e))}function Fk(e){return e===43||e===45||e===46||e===95||Ur(e)}function DD(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const EBe={tokenize:PBe,partial:!0};function NBe(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:RBe,continuation:{tokenize:MBe},exit:DBe}},text:{91:{name:"gfmFootnoteCall",tokenize:jBe},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:kBe,resolveTo:_Be}}}}function kBe(e,t,n){const r=this;let o=r.events.length;const s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let i;for(;o--;){const l=r.events[o][1];if(l.type==="labelImage"){i=l;break}if(l.type==="gfmFootnoteCall"||l.type==="labelLink"||l.type==="label"||l.type==="image"||l.type==="link")break}return a;function a(l){if(!i||!i._balanced)return n(l);const c=Qs(r.sliceSerialize({start:i.end,end:r.now()}));return c.codePointAt(0)!==94||!s.includes(c.slice(1))?n(l):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(l),e.exit("gfmFootnoteCallLabelMarker"),t(l))}}function _Be(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},o={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};o.end.column++,o.end.offset++,o.end._bufferIndex++;const s={type:"gfmFootnoteCallString",start:Object.assign({},o.end),end:Object.assign({},e[e.length-1][1].start)},i={type:"chunkString",contentType:"string",start:Object.assign({},s.start),end:Object.assign({},s.end)},a=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",o,t],["exit",o,t],["enter",s,t],["enter",i,t],["exit",i,t],["exit",s,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...a),e}function jBe(e,t,n){const r=this,o=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s=0,i;return a;function a(f){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),l}function l(f){return f!==94?n(f):(e.enter("gfmFootnoteCallMarker"),e.consume(f),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",c)}function c(f){if(s>999||f===93&&!i||f===null||f===91||mn(f))return n(f);if(f===93){e.exit("chunkString");const h=e.exit("gfmFootnoteCallString");return o.includes(Qs(r.sliceSerialize(h)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(f)}return mn(f)||(i=!0),s++,e.consume(f),f===92?d:c}function d(f){return f===91||f===92||f===93?(e.consume(f),s++,c):c(f)}}function RBe(e,t,n){const r=this,o=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s,i=0,a;return l;function l(m){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionLabelMarker"),c}function c(m){return m===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",d):n(m)}function d(m){if(i>999||m===93&&!a||m===null||m===91||mn(m))return n(m);if(m===93){e.exit("chunkString");const g=e.exit("gfmFootnoteDefinitionLabelString");return s=Qs(r.sliceSerialize(g)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),h}return mn(m)||(a=!0),i++,e.consume(m),m===92?f:d}function f(m){return m===91||m===92||m===93?(e.consume(m),i++,d):d(m)}function h(m){return m===58?(e.enter("definitionMarker"),e.consume(m),e.exit("definitionMarker"),o.includes(s)||o.push(s),Lt(e,p,"gfmFootnoteDefinitionWhitespace")):n(m)}function p(m){return t(m)}}function MBe(e,t,n){return e.check(jb,t,e.attempt(EBe,t,n))}function DBe(e){e.exit("gfmFootnoteDefinition")}function PBe(e,t,n){const r=this;return Lt(e,o,"gfmFootnoteDefinitionIndent",5);function o(s){const i=r.events[r.events.length-1];return i&&i[1].type==="gfmFootnoteDefinitionIndent"&&i[2].sliceSerialize(i[1],!0).length===4?t(s):n(s)}}function TBe(e){let n=(e||{}).singleTilde;const r={name:"strikethrough",tokenize:s,resolveAll:o};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function o(i,a){let l=-1;for(;++l<i.length;)if(i[l][0]==="enter"&&i[l][1].type==="strikethroughSequenceTemporary"&&i[l][1]._close){let c=l;for(;c--;)if(i[c][0]==="exit"&&i[c][1].type==="strikethroughSequenceTemporary"&&i[c][1]._open&&i[l][1].end.offset-i[l][1].start.offset===i[c][1].end.offset-i[c][1].start.offset){i[l][1].type="strikethroughSequence",i[c][1].type="strikethroughSequence";const d={type:"strikethrough",start:Object.assign({},i[c][1].start),end:Object.assign({},i[l][1].end)},f={type:"strikethroughText",start:Object.assign({},i[c][1].end),end:Object.assign({},i[l][1].start)},h=[["enter",d,a],["enter",i[c][1],a],["exit",i[c][1],a],["enter",f,a]],p=a.parser.constructs.insideSpan.null;p&&Go(h,h.length,0,F1(p,i.slice(c+1,l),a)),Go(h,h.length,0,[["exit",f,a],["enter",i[l][1],a],["exit",i[l][1],a],["exit",d,a]]),Go(i,c-1,l-c+3,h),l=c+h.length-2;break}}for(l=-1;++l<i.length;)i[l][1].type==="strikethroughSequenceTemporary"&&(i[l][1].type="data");return i}function s(i,a,l){const c=this.previous,d=this.events;let f=0;return h;function h(m){return c===126&&d[d.length-1][1].type!=="characterEscape"?l(m):(i.enter("strikethroughSequenceTemporary"),p(m))}function p(m){const g=rh(c);if(m===126)return f>1?l(m):(i.consume(m),f++,p);if(f<2&&!n)return l(m);const y=i.exit("strikethroughSequenceTemporary"),b=rh(m);return y._open=!b||b===2&&!!g,y._close=!g||g===2&&!!b,a(m)}}}class ABe{constructor(){this.map=[]}add(t,n,r){IBe(this,t,n,r)}consume(t){if(this.map.sort(function(s,i){return s[0]-i[0]}),this.map.length===0)return;let n=this.map.length;const r=[];for(;n>0;)n-=1,r.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];r.push(t.slice()),t.length=0;let o=r.pop();for(;o;){for(const s of o)t.push(s);o=r.pop()}this.map.length=0}}function IBe(e,t,n,r){let o=0;if(!(n===0&&r.length===0)){for(;o<e.map.length;){if(e.map[o][0]===t){e.map[o][1]+=n,e.map[o][2].push(...r);return}o+=1}e.map.push([t,n,r])}}function OBe(e,t){let n=!1;const r=[];for(;t<e.length;){const o=e[t];if(n){if(o[0]==="enter")o[1].type==="tableContent"&&r.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(o[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const s=r.length-1;r[s]=r[s]==="left"?"center":"right"}}else if(o[1].type==="tableDelimiterRow")break}else o[0]==="enter"&&o[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return r}function FBe(){return{flow:{null:{name:"table",tokenize:$Be,resolveAll:LBe}}}}function $Be(e,t,n){const r=this;let o=0,s=0,i;return a;function a(R){let P=r.events.length-1;for(;P>-1;){const I=r.events[P][1].type;if(I==="lineEnding"||I==="linePrefix")P--;else break}const M=P>-1?r.events[P][1].type:null,F=M==="tableHead"||M==="tableRow"?E:l;return F===E&&r.parser.lazy[r.now().line]?n(R):F(R)}function l(R){return e.enter("tableHead"),e.enter("tableRow"),c(R)}function c(R){return R===124||(i=!0,s+=1),d(R)}function d(R){return R===null?n(R):Ge(R)?s>1?(s=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(R),e.exit("lineEnding"),p):n(R):Nt(R)?Lt(e,d,"whitespace")(R):(s+=1,i&&(i=!1,o+=1),R===124?(e.enter("tableCellDivider"),e.consume(R),e.exit("tableCellDivider"),i=!0,d):(e.enter("data"),f(R)))}function f(R){return R===null||R===124||mn(R)?(e.exit("data"),d(R)):(e.consume(R),R===92?h:f)}function h(R){return R===92||R===124?(e.consume(R),f):f(R)}function p(R){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(R):(e.enter("tableDelimiterRow"),i=!1,Nt(R)?Lt(e,m,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(R):m(R))}function m(R){return R===45||R===58?y(R):R===124?(i=!0,e.enter("tableCellDivider"),e.consume(R),e.exit("tableCellDivider"),g):S(R)}function g(R){return Nt(R)?Lt(e,y,"whitespace")(R):y(R)}function y(R){return R===58?(s+=1,i=!0,e.enter("tableDelimiterMarker"),e.consume(R),e.exit("tableDelimiterMarker"),b):R===45?(s+=1,b(R)):R===null||Ge(R)?w(R):S(R)}function b(R){return R===45?(e.enter("tableDelimiterFiller"),x(R)):S(R)}function x(R){return R===45?(e.consume(R),x):R===58?(i=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(R),e.exit("tableDelimiterMarker"),v):(e.exit("tableDelimiterFiller"),v(R))}function v(R){return Nt(R)?Lt(e,w,"whitespace")(R):w(R)}function w(R){return R===124?m(R):R===null||Ge(R)?!i||o!==s?S(R):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(R)):S(R)}function S(R){return n(R)}function E(R){return e.enter("tableRow"),C(R)}function C(R){return R===124?(e.enter("tableCellDivider"),e.consume(R),e.exit("tableCellDivider"),C):R===null||Ge(R)?(e.exit("tableRow"),t(R)):Nt(R)?Lt(e,C,"whitespace")(R):(e.enter("data"),_(R))}function _(R){return R===null||R===124||mn(R)?(e.exit("data"),C(R)):(e.consume(R),R===92?j:_)}function j(R){return R===92||R===124?(e.consume(R),_):_(R)}}function LBe(e,t){let n=-1,r=!0,o=0,s=[0,0,0,0],i=[0,0,0,0],a=!1,l=0,c,d,f;const h=new ABe;for(;++n<e.length;){const p=e[n],m=p[1];p[0]==="enter"?m.type==="tableHead"?(a=!1,l!==0&&(A4(h,t,l,c,d),d=void 0,l=0),c={type:"table",start:Object.assign({},m.start),end:Object.assign({},m.end)},h.add(n,0,[["enter",c,t]])):m.type==="tableRow"||m.type==="tableDelimiterRow"?(r=!0,f=void 0,s=[0,0,0,0],i=[0,n+1,0,0],a&&(a=!1,d={type:"tableBody",start:Object.assign({},m.start),end:Object.assign({},m.end)},h.add(n,0,[["enter",d,t]])),o=m.type==="tableDelimiterRow"?2:d?3:1):o&&(m.type==="data"||m.type==="tableDelimiterMarker"||m.type==="tableDelimiterFiller")?(r=!1,i[2]===0&&(s[1]!==0&&(i[0]=i[1],f=n0(h,t,s,o,void 0,f),s=[0,0,0,0]),i[2]=n)):m.type==="tableCellDivider"&&(r?r=!1:(s[1]!==0&&(i[0]=i[1],f=n0(h,t,s,o,void 0,f)),s=i,i=[s[1],n,0,0])):m.type==="tableHead"?(a=!0,l=n):m.type==="tableRow"||m.type==="tableDelimiterRow"?(l=n,s[1]!==0?(i[0]=i[1],f=n0(h,t,s,o,n,f)):i[1]!==0&&(f=n0(h,t,i,o,n,f)),o=0):o&&(m.type==="data"||m.type==="tableDelimiterMarker"||m.type==="tableDelimiterFiller")&&(i[3]=n)}for(l!==0&&A4(h,t,l,c,d),h.consume(t.events),n=-1;++n<t.events.length;){const p=t.events[n];p[0]==="enter"&&p[1].type==="table"&&(p[1]._align=OBe(t.events,n))}return e}function n0(e,t,n,r,o,s){const i=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",a="tableContent";n[0]!==0&&(s.end=Object.assign({},Ad(t.events,n[0])),e.add(n[0],0,[["exit",s,t]]));const l=Ad(t.events,n[1]);if(s={type:i,start:Object.assign({},l),end:Object.assign({},l)},e.add(n[1],0,[["enter",s,t]]),n[2]!==0){const c=Ad(t.events,n[2]),d=Ad(t.events,n[3]),f={type:a,start:Object.assign({},c),end:Object.assign({},d)};if(e.add(n[2],0,[["enter",f,t]]),r!==2){const h=t.events[n[2]],p=t.events[n[3]];if(h[1].end=Object.assign({},p[1].end),h[1].type="chunkText",h[1].contentType="text",n[3]>n[2]+1){const m=n[2]+1,g=n[3]-n[2]-1;e.add(m,g,[])}}e.add(n[3]+1,0,[["exit",f,t]])}return o!==void 0&&(s.end=Object.assign({},Ad(t.events,o)),e.add(o,0,[["exit",s,t]]),s=void 0),s}function A4(e,t,n,r,o){const s=[],i=Ad(t.events,n);o&&(o.end=Object.assign({},i),s.push(["exit",o,t])),r.end=Object.assign({},i),s.push(["exit",r,t]),e.add(n+1,0,s)}function Ad(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const zBe={name:"tasklistCheck",tokenize:VBe};function BBe(){return{text:{91:zBe}}}function VBe(e,t,n){const r=this;return o;function o(l){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(l):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(l),e.exit("taskListCheckMarker"),s)}function s(l){return mn(l)?(e.enter("taskListCheckValueUnchecked"),e.consume(l),e.exit("taskListCheckValueUnchecked"),i):l===88||l===120?(e.enter("taskListCheckValueChecked"),e.consume(l),e.exit("taskListCheckValueChecked"),i):n(l)}function i(l){return l===93?(e.enter("taskListCheckMarker"),e.consume(l),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),a):n(l)}function a(l){return Ge(l)?t(l):Nt(l)?e.check({tokenize:HBe},t,n)(l):n(l)}}function HBe(e,t,n){return Lt(e,r,"whitespace");function r(o){return o===null?n(o):t(o)}}function UBe(e){return oK([mBe(),NBe(),TBe(e),FBe(),BBe()])}const WBe={};function qBe(e){const t=this,n=e||WBe,r=t.data(),o=r.micromarkExtensions||(r.micromarkExtensions=[]),s=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),i=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);o.push(UBe(n)),s.push(dBe()),i.push(fBe(n))}function I4({text:e,handleRun:t,className:n}){const r=ee(s=>s.themeStyle),o={p:({node:s,...i})=>u.jsx("p",{className:Z("text-sm leading-relaxed mb-4 text-foreground/90",n),...i}),code:({node:s,...i})=>{var l,c;const a=(c=(l=s==null?void 0:s.children)==null?void 0:l[0])==null?void 0:c.value;return a&&/^#([0-9a-fA-F]{6})$/.test(a)?u.jsx("code",{className:Z("rounded-lg bg-muted px-2.5 py-1.5 text-sm font-mono",n),style:{backgroundColor:a},...i}):u.jsx("code",{className:Z("rounded-lg bg-muted/50 border border-border/50 px-2 py-1 text-sm font-mono text-foreground/80 transition-colors hover:bg-muted/70",n),...i})},pre:s=>u.jsx(F9e,{...s,handleRun:t}),ul:({node:s,...i})=>u.jsx("ul",{className:Z("mb-4 ml-6 list-disc space-y-2 text-sm marker:text-muted-foreground",n),...i}),ol:({node:s,...i})=>u.jsx("ol",{className:Z("mb-4 ml-6 list-decimal space-y-2 text-sm marker:text-muted-foreground",n),...i}),li:({node:s,...i})=>u.jsx("li",{className:Z("pl-2 leading-relaxed text-foreground/90",n),...i}),a:({node:s,...i})=>u.jsx("a",{target:"_blank",rel:"noopener noreferrer",className:Z("text-blue-600 underline underline-offset-2 decoration-1 transition-all hover:text-blue-700 hover:decoration-2",n),...i}),h1:({node:s,...i})=>u.jsx("h1",{className:Z("text-2xl font-semibold tracking-tight mb-4 mt-6 text-foreground",n),...i}),h2:({node:s,...i})=>u.jsx("h2",{className:Z("text-xl font-semibold tracking-tight mb-3 mt-5 text-foreground",n),...i}),h3:({node:s,...i})=>u.jsx("h3",{className:Z("text-lg font-medium mb-2 mt-4 text-foreground",n),...i}),h4:({node:s,...i})=>u.jsx("h4",{className:Z("text-base font-medium mb-2 mt-3 text-foreground/90",n),...i}),strong:({node:s,...i})=>u.jsx("strong",{className:Z("font-semibold text-foreground",n),...i}),blockquote:({node:s,...i})=>u.jsx("blockquote",{className:Z("my-4 border-l-4 border-muted-foreground/30 bg-muted/20 pl-4 pr-4 py-3 italic text-foreground/80 rounded-r-md",n),...i}),table:({node:s,...i})=>u.jsx("div",{className:"my-6 overflow-x-auto rounded-lg border border-border/50 shadow-sm",children:u.jsx("table",{className:Z("w-full table-auto border-collapse text-sm",n),...i})}),thead:({node:s,...i})=>{var a,l,c,d,f,h;return u.jsx("thead",{style:{backgroundColor:(c=(l=(a=r==null?void 0:r.chart)==null?void 0:a.dataset)==null?void 0:l.backgroundColor)==null?void 0:c[0],color:Fa((h=(f=(d=r==null?void 0:r.chart)==null?void 0:d.dataset)==null?void 0:f.backgroundColor)==null?void 0:h[0])},className:"sticky top-0",...i})},tr:({node:s,...i})=>u.jsx("tr",{className:Z("border-b border-border/30 transition-colors hover:bg-muted/30 last:border-0",n),...i}),th:({node:s,...i})=>u.jsx("th",{className:Z("px-4 py-3 text-left font-medium text-sm tracking-wide",n),...i}),td:({node:s,...i})=>u.jsx("td",{className:Z("px-4 py-3 align-top text-foreground/90",n),...i})};return u.jsx(j8e,{components:o,remarkPlugins:[qBe],children:e})}const zu=["image/png","image/jpeg","image/jpg","image/gif","image/webp"],GBe=["application/pdf","text/plain","text/markdown"],YBe=["text/csv","application/json","text/xml","application/xml"],ZBe=["text/javascript","application/javascript","text/typescript","application/x-typescript","text/x-python","application/x-python-code","text/x-sql","application/sql"],KBe=[...zu,...GBe,...YBe,...ZBe],JK=10*1024*1024,wa=5,eX={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".pdf":"application/pdf",".txt":"text/plain",".md":"text/markdown",".csv":"text/csv",".json":"application/json",".xml":"text/xml",".js":"text/javascript",".jsx":"text/javascript",".ts":"text/typescript",".tsx":"text/typescript",".py":"text/x-python",".sql":"text/x-sql"};function XBe(e){if(KBe.includes(e.type))return!0;const t=PD(e.name);return t?Object.prototype.hasOwnProperty.call(eX,t):!1}function PD(e){const t=e.lastIndexOf(".");return t===-1?"":e.substring(t).toLowerCase()}function tX(e){if(e.type)return e.type;const t=PD(e.name);return eX[t]||"application/octet-stream"}function QBe(e){return e.size<=JK}function hg(e){if(e===0)return"0 Bytes";const t=1024,n=["Bytes","KB","MB","GB"],r=Math.floor(Math.log(e)/Math.log(t));return Math.round(e/Math.pow(t,r)*100)/100+" "+n[r]}function O4(e){return new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{const s=r.result.split(",")[1];t(s)},r.onerror=n,r.readAsDataURL(e)})}function JBe(e){return new Promise((t,n)=>{if(!zu.includes(tX(e))){n(new Error("Not an image file"));return}const r=new FileReader;r.onload=()=>t(r.result),r.onerror=n,r.readAsDataURL(e)})}async function TD(e){const t=tX(e),n=zu.includes(t),r={id:crypto.randomUUID(),name:e.name,size:e.size,type:t};if(n)try{r.preview=await JBe(e),r.data=r.preview.split(",")[1]}catch(o){console.error("Failed to create image preview:",o),r.data=await O4(e)}else r.data=await O4(e);return r}function nX(e){const t=[],n=[];for(const r of e)XBe(r)?QBe(r)?t.push(r):n.push({file:r,error:`File too large: ${hg(r.size)} (max ${hg(JK)})`}):n.push({file:r,error:`File type not supported: ${r.type||PD(r.name)}`});return{valid:t,errors:n}}function eVe(e){var r;const t=(r=e.clipboardData)==null?void 0:r.items;if(!t)return[];const n=[];for(let o=0;o<t.length;o++){const s=t[o];if(s.kind==="file"){const i=s.getAsFile();i&&zu.includes(i.type)&&n.push(i)}}return n}function tVe({files:e,onRemove:t,showRemove:n=!0,className:r=""}){if(e.length===0)return null;const o=s=>zu.includes(s)?Ine:s.includes("pdf")||s.includes("text")?Ko:s.includes("javascript")||s.includes("typescript")||s.includes("python")||s.includes("sql")?Ane:J3;return u.jsx("div",{className:`flex flex-wrap gap-2 ${r}`,children:e.map(s=>{const i=o(s.type),a=zu.includes(s.type);return u.jsxs("div",{className:"group relative flex items-center gap-2 rounded-lg border border-border bg-muted/50 p-2 transition-colors hover:bg-muted",children:[a&&s.preview?u.jsx("div",{className:"relative h-12 w-12 overflow-hidden rounded",children:u.jsx("img",{src:s.preview,alt:s.name,className:"h-full w-full object-cover"})}):u.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded bg-background",children:u.jsx(i,{className:"h-6 w-6 text-muted-foreground"})}),u.jsxs("div",{className:"flex flex-col",children:[u.jsx("span",{className:"max-w-[150px] truncate text-xs font-medium",children:s.name}),u.jsx("span",{className:"text-xs text-muted-foreground",children:hg(s.size)}),s.uploadProgress!==void 0&&s.uploadProgress<100&&u.jsx(TM,{value:s.uploadProgress,className:"mt-1 h-1 w-full"})]}),n&&t&&u.jsx(ae,{variant:"ghost",size:"icon",className:"absolute -right-2 -top-2 h-5 w-5 rounded-full bg-background opacity-0 shadow-sm transition-opacity group-hover:opacity-100",onClick:()=>t(s.id),children:u.jsx(Xt,{className:"h-3 w-3"})})]},s.id)})})}function nVe({file:e,className:t=""}){return zu.includes(e.type)&&e.preview?u.jsxs("div",{className:`inline-block ${t}`,children:[u.jsx("img",{src:e.preview,alt:e.name,className:"max-h-64 max-w-full rounded-lg border border-border"}),u.jsxs("div",{className:"mt-1 text-xs text-muted-foreground",children:[e.name," • ",hg(e.size)]})]}):u.jsxs("div",{className:`inline-flex items-center gap-2 rounded-lg border border-border bg-muted/50 px-3 py-2 ${t}`,children:[u.jsx(Ko,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm",children:e.name}),u.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",hg(e.size),")"]})]})}const F4={"tool-getTableColumns":{"input-streaming":"Fetching table columns...","input-available":"Reading column definitions..."},"tool-getChartDataFromSqlAndPython":{"input-streaming":"Planning...","input-available":"Fetching data..."},"tool-getChartDataFromCardConfig":{"input-streaming":"Planning...","input-available":"Fetching data..."},"tool-getForecastDataFromSqlAndPython":{"input-streaming":"Planning...","input-available":"Fetching data..."},"tool-getChartSQLSyntax":{"input-streaming":"Generating SQL syntax...","input-available":"SQL syntax generated"},"tool-validateCardConfigFormat":{"input-streaming":"Validating card config format...","input-available":"Card config format validated"},"tool-generateQueryConfig":{"input-streaming":"Generating query config...","input-available":"Sending query config..."},"tool-askForMoreInfo":{"input-streaming":"Asking for more information...","input-available":"More information requested"},"tool-createChartFromSql":{"input-streaming":"Creating chart...","input-available":"Chart created"},"tool-getUserSql":{"input-streaming":"Getting SQL...","input-available":"SQL retrieved"},"tool-inspectTableData":{"input-streaming":"Inspecting table data...","input-available":"Analyzing data..."}};function rX(e,t){var r;if((r=F4[e])!=null&&r[t])return F4[e][t];const n=e.replace("tool-","").replace(/([A-Z])/g," $1").toLowerCase().trim();return t==="input-streaming"?`Processing ${n}...`:`Preparing ${n} response...`}var AD="Collapsible",[rVe,oX]=mr(AD),[oVe,ID]=rVe(AD),sX=k.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[l=!1,c]=Rr({prop:r,defaultProp:o,onChange:i});return u.jsx(oVe,{scope:n,disabled:s,contentId:Yn(),open:l,onOpenToggle:k.useCallback(()=>c(d=>!d),[c]),children:u.jsx(Te.div,{"data-state":LD(l),"data-disabled":s?"":void 0,...a,ref:t})})});sX.displayName=AD;var iX="CollapsibleTrigger",OD=k.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=ID(iX,n);return u.jsx(Te.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":LD(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:we(e.onClick,o.onOpenToggle)})});OD.displayName=iX;var FD="CollapsibleContent",$D=k.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ID(FD,e.__scopeCollapsible);return u.jsx(Zn,{present:n||o.open,children:({present:s})=>u.jsx(sVe,{...r,ref:t,present:s})})});$D.displayName=FD;var sVe=k.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=ID(FD,n),[a,l]=k.useState(r),c=k.useRef(null),d=ot(t,c),f=k.useRef(0),h=f.current,p=k.useRef(0),m=p.current,g=i.open||a,y=k.useRef(g),b=k.useRef(void 0);return k.useEffect(()=>{const x=requestAnimationFrame(()=>y.current=!1);return()=>cancelAnimationFrame(x)},[]),jr(()=>{const x=c.current;if(x){b.current=b.current||{transitionDuration:x.style.transitionDuration,animationName:x.style.animationName},x.style.transitionDuration="0s",x.style.animationName="none";const v=x.getBoundingClientRect();f.current=v.height,p.current=v.width,y.current||(x.style.transitionDuration=b.current.transitionDuration,x.style.animationName=b.current.animationName),l(r)}},[i.open,r]),u.jsx(Te.div,{"data-state":LD(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!g,...s,ref:d,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":m?`${m}px`:void 0,...e.style},children:g&&o})});function LD(e){return e?"open":"closed"}var aX=sX,iVe=OD,aVe=$D;const oh=aX,sh=OD,ih=$D;function lVe({part:e,showTools:t}){if(!t)return null;const{input:n,output:r,...o}=e;return e.type,u.jsx("div",{className:"space-y-3",children:t&&u.jsxs(oh,{children:[u.jsxs("div",{className:"inline-flex items-center gap-2",children:[u.jsxs(sh,{className:"rounded-md border border-foreground/20 p-1 px-2 font-mono text-xs text-foreground/80 hover:bg-foreground/5",children:[u.jsx("span",{className:"font-bold",children:"Tool:"})," ",e.type.split("-")[1]]}),Iv]}),u.jsx(ih,{className:"mt-2 font-mono text-xs",children:u.jsxs("div",{className:"space-y-2 px-2",children:[u.jsxs("div",{className:"space-y-1",children:[u.jsx("span",{children:"Args:"}),u.jsx(zl,{language:"json",code:JSON.stringify(o,null,2)})]}),u.jsxs("div",{className:"space-y-1",children:[u.jsx("span",{children:"Input:"}),u.jsx(zl,{language:"json",code:JSON.stringify(n,null,2)})]}),u.jsxs("div",{className:"space-y-1",children:[u.jsx("span",{children:"Output:"}),u.jsx(zl,{language:"json",code:JSON.stringify(r,null,2)})]})]})})]})})}function cVe(){const{authToken:e,tokenProps:t}=qe(),{currentUser:n}=ea(),r=Ji({mutationFn:async o=>{if(!(e!=null&&e.accessToken))throw new Error("No authentication token available");const i=`${t.apiServiceUrl||""}/v1/feedback`,a={...o,user:n,tokenContext:t},l=await nc(i,e.accessToken,a,"POST");if(!l||!l.success)throw new Error((l==null?void 0:l.error)||"Failed to send feedback");return l},onSuccess:o=>{Ue.success(`Feedback sent successfully! Issue: ${o.issueNumber}`,{duration:5e3})},onError:o=>{console.error("Feedback submission error:",o),Ue.error("Failed to send feedback. Please try again later.",{duration:5e3})}});return{sendFeedback:r.mutate,sendFeedbackAsync:r.mutateAsync,isLoading:r.isPending,isSuccess:r.isSuccess,isError:r.isError,error:r.error,data:r.data,reset:r.reset}}function zD(e,t,n){return{category:e,userMessage:n,systemState:t,metadata:{url:window.location.href,userAgent:navigator.userAgent,timestamp:new Date().toISOString(),viewport:`${window.innerWidth}x${window.innerHeight}`}}}function yv({open:e,onOpenChange:t,feedbackData:n}){var g,y,b,x,v,w,S,E,C,_,j,R,P;const[r,o]=N.useState(""),[s,i]=N.useState(!1),{sendFeedback:a,isLoading:l,isSuccess:c,data:d,reset:f}=cVe(),h=()=>{const M={...n,userMessage:r.trim()||void 0};a(M)},p=()=>{o(""),i(!1),f(),t(!1)},m={category:n.category,error:{message:(g=n.systemState)==null?void 0:g.errorMessage,sql:(y=n.systemState)==null?void 0:y.generatedSql,errorSql:(b=n.systemState)==null?void 0:b.errorSql},assistantType:(x=n.systemState)==null?void 0:x.assistantType,toolType:(v=n.systemState)==null?void 0:v.toolType,userQuery:(w=n.systemState)==null?void 0:w.userQuery,messages:(S=n.systemState)==null?void 0:S.messages,aiContext:(E=n.systemState)==null?void 0:E.aiContext,toolInput:(C=n.systemState)==null?void 0:C.toolInput,toolOutput:(_=n.systemState)==null?void 0:_.toolOutput,cardConfig:(j=n.systemState)==null?void 0:j.cardConfig,dataSource:(R=n.systemState)==null?void 0:R.dataSource,filters:(P=n.systemState)==null?void 0:P.dashboardFilters,metadata:n.metadata};return u.jsx(_s,{open:e,onOpenChange:p,children:u.jsxs(ns,{className:"max-w-2xl",children:[u.jsxs(rs,{children:[u.jsx(os,{children:c?"Feedback Sent Successfully":n.category==="dashboard-assistant"?"Report Dashboard Assistant Issue":n.category==="editor-assistant"?"Report Editor Assistant Issue":"Report Query Generation Issue"}),u.jsx(ci,{children:c?`Your feedback has been submitted with issue number: ${d==null?void 0:d.issueNumber}`:n.category==="dashboard-assistant"||n.category==="editor-assistant"?"Help us improve by reporting this AI assistant issue. Your feedback will be sent to our support team.":"Help us improve by reporting this query generation issue. Your feedback will be sent to our support team."})]}),!c&&u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(de,{htmlFor:"message",children:"Additional Information (Optional)"}),u.jsx(ph,{id:"message",placeholder:"Please describe what you were trying to do when this error occurred...",value:r,onChange:M=>o(M.target.value),className:"min-h-[100px] resize-none ring-inset focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0",disabled:l})]}),u.jsxs(oh,{open:s,onOpenChange:i,children:[u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsx(sh,{asChild:!0,children:u.jsxs(ae,{variant:"ghost",size:"sm",className:"flex flex-1 items-center justify-between p-2 hover:bg-muted",children:[u.jsx("span",{className:"text-sm font-medium",children:"View data to be sent"}),s?u.jsx(No,{className:"h-4 w-4"}):u.jsx(Js,{className:"h-4 w-4"})]})}),u.jsx(Fu,{text:JSON.stringify(m,null,2),className:"h-8 w-8 shrink-0"})]}),u.jsx(ih,{className:"mt-2",children:u.jsx(Yi,{className:"h-[300px] w-full rounded-md border bg-muted/50 p-4",children:u.jsx("div",{className:"text-xs overflow-auto break-all whitespace-pre-wrap",children:u.jsx(zl,{code:JSON.stringify(m,null,2),language:"json"})})})})]})]}),u.jsxs(js,{children:[u.jsx(ae,{variant:"outline",onClick:p,disabled:l,children:"Cancel"}),u.jsx(ae,{onClick:h,disabled:l,className:"min-w-[100px]",children:l?u.jsxs(u.Fragment,{children:[u.jsx(Cs,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):"Send Feedback"})]})]}),c&&u.jsxs("div",{className:"flex flex-col items-center space-y-4 py-6",children:[u.jsx(Dne,{className:"h-12 w-12 text-green-600"}),u.jsxs("div",{className:"text-center",children:[u.jsx("p",{className:"text-lg font-medium",children:"Thank you for your feedback!"}),u.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:["Issue Number:"," ",u.jsx("span",{className:"font-mono font-medium",children:d==null?void 0:d.issueNumber})]}),u.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Our support team will review your feedback and take appropriate action."})]}),u.jsx(ae,{onClick:p,className:"mt-4",children:"Close"})]})]})})}var ah=(e=>(e.QUERY_GENERATION="query-generation",e.DASHBOARD_ASSISTANT="dashboard-assistant",e.EDITOR_ASSISTANT="editor-assistant",e))(ah||{});function uVe({part:e,messages:t}){const[n,r]=N.useState(!1),[o,s]=N.useState(null),i=x6(),a=Pg(),{tokenProps:l}=N.useContext(Rg);ea();const c=()=>{var g;const d=t==null?void 0:t.filter(y=>y.role==="user").pop(),f=(g=d==null?void 0:d.parts)==null?void 0:g.find(y=>y.type==="text"),h=(f==null?void 0:f.text)||"",p=i==="dashboard"?ah.DASHBOARD_ASSISTANT:ah.EDITOR_ASSISTANT,m=zD(p,{errorMessage:e.errorText||"Tool invocation error occurred",toolType:e.type,toolInput:e.input,toolOutput:null,assistantType:i,userQuery:h,messages:t,aiContext:a});s(m),r(!0)};return u.jsxs(u.Fragment,{children:[u.jsxs(oh,{children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(sh,{className:"",children:u.jsxs(de,{className:"flex cursor-pointer items-center hover:text-foreground",children:[u.jsx(j_,{className:"mr-2 size-4 text-yellow-500"}),"Recovering from Error"]})}),u.jsxs(ae,{variant:"ghost",size:"sm",className:"gap-1 text-[11px]",onClick:c,"aria-label":"Send feedback",children:[u.jsx(S_,{className:"h-3 w-3"}),"Send Feedback"]})]}),u.jsx(ih,{className:"mt-2 text-xs",children:u.jsxs("div",{className:"relative space-y-2 rounded-md border border-yellow-500 bg-yellow-50 p-4 text-black/80 dark:border-yellow-500/80 dark:bg-yellow-500/10 dark:text-white/80",children:[u.jsxs(de,{className:"text-xs",children:["Tool Invocation Error (",e.type.split("-")[1],")"]}),u.jsx("p",{children:e.errorText})]})})]}),o&&u.jsx(yv,{open:n,onOpenChange:d=>{r(d),d||s(null)},feedbackData:o})]})}const H1={connectionId:"",connectionType:"none",mode:"semanticDomain",selectedEntities:[]},$4=N.memo(({cfg:e,onDatapointClick:t})=>u.jsx(l1,{cfg:e,onDatapointClick:t}),(e,t)=>JSON.stringify(e.cfg)===JSON.stringify(t.cfg)&&e.onDatapointClick===t.onDatapointClick);function dVe({part:e,onAddToDashboard:t,messages:n,showTools:r=!1}){var z,L;const o=e.output,s=e.input,[i,a]=N.useState(!1),[l,c]=N.useState(!1),[d,f]=N.useState("visual"),[h,p]=N.useState(!1),[m,g]=N.useState(null),y=N.useMemo(()=>(e==null?void 0:e.toolCallId)??br(),[e]),{queueMessage:b}=mh(),x=x6(),v=Pg(),{tokenProps:w}=N.useContext(Rg);ea();const S=()=>{const D=e.toolCallId;T().label;const H=`Can you explain how this visual was calculated? [ref: ${D}]`;b("dashboard",H)},E=()=>{var B;console.log("Send Feedback clicked",{activeAssistantType:x,messages:n,output:o,input:s,part:e});const D=n==null?void 0:n.filter(G=>G.role==="user").pop(),H=(B=D==null?void 0:D.parts)==null?void 0:B.find(G=>G.type==="text"),q=(H==null?void 0:H.text)||"",Y=x==="dashboard"?ah.DASHBOARD_ASSISTANT:ah.EDITOR_ASSISTANT;console.log("Feedback category:",Y);const V=zD(Y,{errorMessage:(o==null?void 0:o.error)||"An error occurred while generating the visualization",toolType:e.type,toolInput:s,toolOutput:o,assistantType:x,userQuery:q,messages:n,aiContext:v,cardConfig:s==null?void 0:s.cardConfig,dataSource:o==null?void 0:o.dataSource,generatedSql:s==null?void 0:s.sql});console.log("Feedback payload prepared:",V),g(V),p(!0)},C=s==null?void 0:s.chartType,_=s==null?void 0:s.connectionId,j=s==null?void 0:s.cardConfig,R=s==null?void 0:s.chartTitle,P=s==null?void 0:s.sql,M=(z=o==null?void 0:o.data)==null?void 0:z.userSql,F=s==null?void 0:s.python,I=(L=o==null?void 0:o.data)==null?void 0:L.records,A=o==null?void 0:o.dataSource,O=N.useMemo(()=>C?{id:y,config:j,type:C,dataSource:A,preferences:{tablePrefs:{pageSize:10}}}:null,[y,j,C,A]),U=N.useMemo(()=>!O||C==="pivotTable"?null:OR({card:O,cardType:C,data:I||[],queryConfig:{}}),[O,C,I]),W=N.useMemo(()=>{var V,B,G,X;if(C!=="pivotTable"||!o)return null;const D=((V=o.data)==null?void 0:V.pivotSchema)||[],H=((B=o.data)==null?void 0:B.subtotalColumns)||[],q=(G=o.data)==null?void 0:G.columnSubtotalMeta,Y=(X=o.data)==null?void 0:X.groupByColumns;return{records:I||[],pivotSchema:D,subtotalColumns:H,columnSubtotalMeta:q,groupByColumns:Y}},[C,o,I]),$=ob(O,W),T=()=>{const D=O?nv(O):!1,H=u1.find(Y=>Y.id===C),q=H==null?void 0:H.icon;return F?{type:"advanced",label:"Advanced Analysis",icons:[nu,KP]}:D&&q?{type:"standard",label:"Standard Analysis",icons:[q]}:{type:"sql",label:"SQL Analysis",icons:[nu]}};if(!o)return null;if(o.error){const D=o.errorType||"unknown",H=o.hint||"",q=o.rootCause||o.error,Y=o.shouldRetry!==!1,V=o.validationErrors||[],B=o.suggestions||[],G=V.length>0,X=G?{border:"border-purple-500/60 dark:border-purple-500/50",bg:"bg-purple-50 dark:bg-purple-500/10",text:"text-purple-800 dark:text-purple-300",iconColor:"text-purple-600 dark:text-purple-500",accentBg:"bg-purple-100 dark:bg-purple-900/30",accentText:"text-purple-900 dark:text-purple-200"}:{border:"border-yellow-500/60 dark:border-yellow-500/50",bg:"bg-yellow-50 dark:bg-yellow-500/10",text:"text-yellow-800 dark:text-yellow-300",iconColor:"text-yellow-600 dark:text-yellow-500",accentBg:"bg-yellow-100 dark:bg-yellow-900/30",accentText:"text-yellow-900 dark:text-yellow-200"},re=()=>G?Y?"Configuration validation failed. Retrying...":"Configuration validation failed":D==="group_by_error"?Y?"SQL grouping error. Retrying...":"SQL grouping error":D==="syntax_error"?Y?"SQL syntax error. Retrying...":"SQL syntax error":D==="type_mismatch"?Y?"Data type mismatch. Retrying...":"Data type mismatch":Y?"Retrying...":"Couldn't generate this visual";if(!r){const J=Y?"Let me try that a different way...":"I'm ready with a revised plan.",ue=H||(q&&q!==o.error?q:"");return u.jsx("div",{className:"mt-2 rounded-md border border-border/40 bg-muted/30 p-3 text-xs",children:u.jsxs("div",{className:"flex items-start gap-2",children:[u.jsx(k_,{className:"size-4 shrink-0 text-primary","aria-hidden":"true"}),u.jsxs("div",{className:"space-y-1 text-foreground/80",children:[u.jsx("div",{className:"font-medium text-foreground",children:J}),ue&&u.jsx("div",{className:"text-[11px] text-muted-foreground",children:ue})]})]})})}return u.jsxs(u.Fragment,{children:[u.jsx(oh,{open:l,onOpenChange:c,children:u.jsxs("div",{className:`relative space-y-2 rounded-md border ${X.border} ${X.bg} p-3 text-xs`,children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(j_,{className:`size-4 shrink-0 ${X.iconColor}`,"aria-hidden":"true"}),u.jsx("span",{className:`font-medium ${X.text}`,children:re()})]}),G&&u.jsx("div",{className:`text-[10px] ${X.text} opacity-80`,children:"Self-healing defense: Config validated before execution"}),q&&q!==o.error&&u.jsxs("div",{className:"text-foreground/80",children:[u.jsx("span",{className:"font-semibold",children:"Issue:"})," ",q]}),H&&u.jsxs("div",{className:`rounded-md ${X.accentBg} p-2 ${X.accentText}`,children:[u.jsx("span",{className:"font-semibold",children:"Fix:"})," ",H]}),V.length>0&&u.jsxs("div",{className:"space-y-1",children:[u.jsx("div",{className:`font-semibold ${X.text}`,children:"Configuration issues found:"}),u.jsxs("ul",{className:"ml-4 list-disc space-y-0.5",children:[V.slice(0,3).map((J,ue)=>u.jsx("li",{className:"text-foreground/70 dark:text-foreground/60",children:J},ue)),V.length>3&&u.jsxs("li",{className:"text-muted-foreground",children:["...and ",V.length-3," more"]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-1",children:[u.jsx(sh,{asChild:!0,children:u.jsxs(ae,{variant:"ghost",size:"sm",className:`gap-1 text-[11px] ${X.text}`,children:[l?"Hide":"View"," technical details",u.jsx(No,{className:`h-3 w-3 transition-transform ${l?"rotate-180":""}`})]})}),u.jsxs(ae,{variant:"ghost",size:"sm",className:`gap-1 text-[11px] ${X.text}`,onClick:E,children:[u.jsx(S_,{className:"h-3 w-3"}),"Report Issue"]})]}),u.jsxs(ih,{className:"mt-2 space-y-2",children:[B.length>0&&u.jsxs("div",{className:"rounded-md border border-blue-500/40 bg-background/60 p-2 dark:bg-background/40",children:[u.jsx("div",{className:"mb-1 text-[11px] font-semibold text-blue-900 dark:text-blue-200",children:"Suggested fixes:"}),u.jsx("ul",{className:"ml-3 list-disc space-y-1",children:B.map((J,ue)=>u.jsx("li",{className:"text-[11px] leading-relaxed text-foreground/80",children:J},ue))})]}),u.jsxs("div",{className:`rounded-md border ${X.border} bg-background/60 p-2 dark:bg-background/40`,children:[u.jsx("div",{className:`mb-1 text-[11px] font-semibold ${X.text}`,children:"Raw error:"}),u.jsx("pre",{className:"max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-[11px] leading-relaxed text-foreground/80",children:o.error})]})]})]})}),m&&u.jsx(yv,{open:h,onOpenChange:J=>{p(J),J||g(null)},feedbackData:m})]})}return u.jsxs(u.Fragment,{children:[u.jsxs(Li,{className:"grid w-full max-w-full grid-cols-1 border border-muted bg-background shadow-sm",children:[u.jsx(zi,{className:"pb-3",children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"space-y-1",children:u.jsx("h3",{className:"text-base font-semibold text-foreground",children:R||"Untitled Chart"})}),u.jsxs("div",{className:"flex items-center gap-2",children:[C!=="table"&&C!=="pivotTable"&&u.jsx(di,{value:d,onValueChange:f,children:u.jsxs(Rs,{className:"h-8",children:[u.jsx(Ln,{value:"visual",className:"h-7 w-7 p-0","aria-label":"View as chart",children:u.jsx(Mg,{className:"h-3.5 w-3.5"})}),u.jsx(Ln,{value:"table",className:"h-7 w-7 p-0","aria-label":"View as table",children:u.jsx(Uv,{className:"h-3.5 w-3.5"})})]})}),u.jsx(ae,{variant:"outline",size:"sm",className:"h-8 w-8 p-0",onClick:()=>{t==null||t({sql:P||"",data:I||[],dataSource:A||H1,cardConfig:j,cardTitle:R||"Untitled Chart",connectionId:_||"",cardType:C||"bar",python:F||""})},"aria-label":"Add visual to dashboard",children:u.jsx(Xo,{className:"h-4 w-4"})})]})]})}),u.jsxs(Wa,{className:"space-y-4",children:[u.jsx("div",{className:Z("isolate flex w-full grow flex-col",C!=="table"&&C!=="pivotTable"&&"min-h-[360px]"),children:u.jsx("div",{className:"flex grow flex-col",children:C==="table"&&O?u.jsx("div",{className:"min-w-0",children:u.jsx(Zm,{card:O,data:I||[],isLoading:!1})}):C==="pivotTable"&&$&&O?u.jsx(c1,{data:$.data,card:O,options:$.options}):U&&C!=="table"&&C!=="pivotTable"?d==="table"?u.jsx("div",{className:"min-w-0 pb-6",children:u.jsx(Zm,{card:O,data:I||[],isLoading:!1})}):u.jsx($4,{cfg:U}):U&&u.jsx($4,{cfg:U})})}),(P||F||O&&nv(O))&&u.jsxs(oh,{open:i,onOpenChange:a,children:[u.jsxs("div",{className:"flex items-center justify-between border-t border-muted/40 pb-2 pt-2",children:[u.jsx("div",{className:"flex items-center gap-2",children:(()=>{const D=T();return u.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[D.icons.map((H,q)=>u.jsx(H,{className:"h-3 w-3"},q)),u.jsx("span",{children:D.label}),u.jsx(ae,{variant:"ghost",size:"sm",className:"h-4 w-4 p-0 hover:text-foreground",onClick:S,title:"Ask for explanation",children:u.jsx(uh,{className:"h-3 w-3"})})]})})()}),u.jsx(sh,{asChild:!0,children:u.jsxs(ae,{variant:"ghost",size:"sm",className:"gap-1 text-xs",children:[i?"Hide Details":"Show Details",u.jsx(No,{className:`h-3 w-3 transition-transform ${i?"rotate-180":""}`})]})})]}),u.jsxs(ih,{className:"space-y-3 pb-6",children:[M&&u.jsxs("div",{className:"space-y-2",children:[u.jsxs("div",{className:"flex items-center justify-between gap-2",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(nu,{className:"h-4 w-4 text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-foreground",children:"SQL Query"})]}),u.jsx(Fu,{text:M,className:"-mr-1"})]}),u.jsx("div",{className:"rounded-md border bg-muted/30",children:u.jsx(zl,{language:"sql",code:M})})]}),F&&u.jsxs("div",{className:"space-y-2",children:[u.jsxs("div",{className:"flex items-center justify-between gap-2",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(KP,{className:"h-4 w-4 text-green-600"}),u.jsx("span",{className:"text-sm font-medium text-foreground",children:"Python"})]}),u.jsx(Fu,{text:F,className:"-mr-1"})]}),u.jsx("div",{className:"rounded-md border bg-muted/30",children:u.jsx(zl,{language:"python",code:F})})]})]})]})]})]}),m&&u.jsx(yv,{open:h,onOpenChange:D=>{p(D),D||g(null)},feedbackData:m})]})}const fVe=["tool-getChartDataFromSqlAndPython","tool-getChartDataFromCardConfig","tool-getForecastDataFromSqlAndPython","tool-generateQueryConfig"];function hVe({part:e,idx:t,showTools:n,onAddToDashboard:r,messages:o}){if(!e.state)return null;if(e.state==="input-streaming"||e.state==="input-available"){const s=rX(e.type,e.state);return u.jsx(pVe,{text:s})}if(e.state==="output-available"){const s=fVe.includes(e.type);return u.jsxs("div",{className:"my-2 space-y-2",children:[n&&u.jsx(lVe,{part:e,showTools:n}),s&&r&&u.jsx(dVe,{part:e,onAddToDashboard:r,messages:o,showTools:n})]},t)}return e.state==="output-error"?n?u.jsx("div",{className:"mt-2",children:u.jsx(uVe,{part:e,messages:o})},t):u.jsx("div",{className:"my-2 rounded-md border border-border/40 bg-muted/30 px-3 py-2 text-sm text-muted-foreground",children:"I hit a snag while working on that and will adjust the approach."},t):u.jsx("div",{},t)}function pVe({text:e}){return u.jsx("div",{className:"mt-2 animate-pulse text-sm text-muted-foreground",children:e})}const L4=/```quickreply\s*([\s\S]*?)```/i;function mVe(e){let t=e,n=null;const r=e.toLowerCase().indexOf("```quickreply");if(r!==-1){const i=e.match(L4);if(i)n=i[1].trim(),t=e.replace(i[0],"").trim();else return{cleanedText:e.slice(0,r).trimEnd(),quickReplies:[]}}else{const i=e.match(L4);i&&(n=i[1].trim(),t=e.replace(i[0],"").trim())}const o=t===e?e.toLowerCase().indexOf("quickreply"):-1;if(!n&&o!==-1){const i=e.indexOf("{",o);if(i!==-1){let a=0,l=-1;for(let c=i;c<e.length;c++){const d=e[c];if(d==="{")a++;else if(d==="}"&&(a--,a===0)){l=c;break}}if(l!==-1)n=e.slice(i,l+1).trim(),t=(e.slice(0,o)+e.slice(l+1)).trim();else return{cleanedText:e.slice(0,o).trimEnd(),quickReplies:[]}}else return{cleanedText:e.slice(0,o).trimEnd(),quickReplies:[]}}let s=[];if(n)try{const i=JSON.parse(n);s=(Array.isArray(i==null?void 0:i.options)?i.options:[]).map(l=>{const c=typeof(l==null?void 0:l.label)=="string"?l.label.trim():"",d=typeof(l==null?void 0:l.value)=="string"?l.value.trim():"";return c&&d?{label:c,value:d}:null}).filter(Boolean)}catch{s=[]}return{cleanedText:t.trim(),quickReplies:s}}function gVe(e){if(e==null)return"Something went wrong.";if(e instanceof Error)return e.message||"Something went wrong.";const t=r=>{if(!r||typeof r!="object")return null;const o=r.error&&typeof r.error=="object"?r.error:r,s=typeof o.code=="string"&&o.code?o.code.trim():"",i=typeof o.docs=="string"&&o.docs?`
926
926
  More info: ${o.docs}`:"",a=typeof o.message=="string"&&o.message.trim()?o.message.trim():typeof o.error=="string"&&o.error.trim()?o.error.trim():null;if(a){const l=s?` (code: ${s})`:"",c=s==="insufficient_quota"||a.toLowerCase().includes("quota")?`
927
927
 
928
- Semaphor supports bring-your-own OpenAI API keys. Add yours in Settings or drop a note to support@semaphor.cloud and we’ll help you get set up.`:"";return`${a}${l}${i}${c}`}return null};if(typeof e=="string"){const r=e.trim();if(!r)return"Something went wrong.";try{const o=JSON.parse(r),s=t(o);if(s)return s}catch{}return r}const n=t(e);if(n)return n;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function BD({errorMessage:e}){return u.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-red-500/10 p-2 text-sm text-red-500 backdrop-blur-sm",children:[u.jsx(j_,{className:"mt-0.5 h-4 w-4 shrink-0"}),u.jsx("span",{className:"whitespace-pre-wrap break-words",children:gVe(e)})]})}function bVe({error:e,resetErrorBoundary:t}){return u.jsxs("div",{className:"my-4 space-y-2 rounded-md border border-border/50 bg-muted/20 p-3",children:[u.jsx(BD,{errorMessage:e==null?void 0:e.message}),u.jsx("button",{type:"button",className:"text-xs font-medium text-muted-foreground underline hover:text-foreground",onClick:t,children:"Try again"})]})}function yVe({text:e,files:t}){return u.jsxs("div",{className:"group relative rounded-md border border-border/50 bg-muted/50 p-3 text-sm",children:[u.jsx(Vne,{className:"float-left mr-2 mt-0.5 size-3.5"}),u.jsxs("div",{className:"space-y-2",children:[e&&u.jsx("div",{className:"whitespace-pre-line",children:e}),t&&t.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:t.map(n=>u.jsx(nVe,{file:n},n.id))})]}),e&&u.jsx("div",{className:"absolute right-1 top-1 opacity-0 transition-opacity group-hover:opacity-100",children:u.jsx(Fu,{text:e,className:"h-6"})})]})}function xVe({text:e}){const t=e.split("|"),n=t[0],r=t[1]||"{}",o=JSON.parse(r);return u.jsxs("div",{className:"space-y-1 text-xs",children:[u.jsxs("div",{children:[u.jsx("span",{className:"font-bold",children:"System Message:"})," ",n]}),u.jsxs("div",{className:"space-y-1",children:[u.jsx("span",{className:"font-mono text-xs",children:"Scope:"}),u.jsx(X$e,{children:JSON.stringify(o,null,2)})]})]})}function lX({status:e,errorMessage:t}){return e==="submitted"?u.jsx("div",{className:"mt-2 animate-pulse text-sm text-muted-foreground",children:"Thinking..."}):e==="streaming"?u.jsx("div",{className:"mt-1 animate-pulse text-sm text-muted-foreground",children:"Streaming..."}):e==="error"?u.jsx("div",{className:"mt-2 text-xs text-muted-foreground",children:u.jsx(BD,{errorMessage:t})}):null}function cX({messages:e,showTools:t=!1,onAddToDashboard:n,showSystemMessage:r=!1,handleRun:o,onQuickReply:s,disableQuickReplies:i=!1}){return u.jsx("div",{children:e==null?void 0:e.map((a,l)=>{var c,d,f;if(a.role==="user"){const h=((c=a.parts)==null?void 0:c.filter(y=>y.type==="text"))||[],p=((d=a.parts)==null?void 0:d.filter(y=>y.type==="file"))||[],m=h.map(y=>y.text).join(`
928
+ Semaphor supports bring-your-own OpenAI API keys. Add yours in Settings or drop a note to support@semaphor.cloud and we’ll help you get set up.`:"";return`${a}${l}${i}${c}`}return null};if(typeof e=="string"){const r=e.trim();if(!r)return"Something went wrong.";try{const o=JSON.parse(r),s=t(o);if(s)return s}catch{}return r}const n=t(e);if(n)return n;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function BD({errorMessage:e}){return u.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-red-500/10 p-2 text-sm text-red-500 backdrop-blur-sm",children:[u.jsx(j_,{className:"mt-0.5 h-4 w-4 shrink-0"}),u.jsx("span",{className:"whitespace-pre-wrap break-words",children:gVe(e)})]})}function bVe({error:e,resetErrorBoundary:t}){return u.jsxs("div",{className:"my-4 space-y-2 rounded-md border border-border/50 bg-muted/20 p-3",children:[u.jsx(BD,{errorMessage:e==null?void 0:e.message}),u.jsx("button",{type:"button",className:"text-xs font-medium text-muted-foreground underline hover:text-foreground",onClick:t,children:"Try again"})]})}function yVe({text:e,files:t}){return u.jsxs("div",{className:"group relative rounded-md border border-border/50 bg-muted/50 p-3 text-sm",children:[u.jsx(Vne,{className:"float-left mr-2 mt-0.5 size-3.5"}),u.jsxs("div",{className:"space-y-2",children:[e&&u.jsx("div",{className:"whitespace-pre-line",children:e}),t&&t.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:t.map(n=>u.jsx(nVe,{file:n},n.id))})]}),e&&u.jsx("div",{className:"absolute right-1 top-1 opacity-0 transition-opacity group-hover:opacity-100",children:u.jsx(Fu,{text:e,className:"h-6"})})]})}function xVe({text:e}){const t=e.split("|"),n=t[0],r=t[1]||"{}",o=JSON.parse(r);return u.jsxs("div",{className:"space-y-1 text-xs",children:[u.jsxs("div",{children:[u.jsx("span",{className:"font-bold",children:"System Message:"})," ",n]}),u.jsxs("div",{className:"space-y-1",children:[u.jsx("span",{className:"font-mono text-xs",children:"Scope:"}),u.jsx(X$e,{children:JSON.stringify(o,null,2)})]})]})}function lX({status:e,errorMessage:t}){return e==="submitted"?u.jsx("div",{className:"mt-2 animate-pulse text-sm text-muted-foreground",children:"Thinking..."}):e==="streaming"?u.jsx("div",{className:"animate-pulse text-sm text-muted-foreground",children:"Streaming..."}):e==="error"?u.jsx("div",{className:"mt-2 text-xs text-muted-foreground",children:u.jsx(BD,{errorMessage:t})}):null}function cX({messages:e,showTools:t=!1,onAddToDashboard:n,showSystemMessage:r=!1,handleRun:o,onQuickReply:s,disableQuickReplies:i=!1}){return u.jsx("div",{children:e==null?void 0:e.map((a,l)=>{var c,d,f;if(a.role==="user"){const h=((c=a.parts)==null?void 0:c.filter(y=>y.type==="text"))||[],p=((d=a.parts)==null?void 0:d.filter(y=>y.type==="file"))||[],m=h.map(y=>y.text).join(`
929
929
  `).trim(),g=p.map((y,b)=>{var w,S;let x="",v;if((w=y.url)!=null&&w.startsWith("data:")){const E=y.url.match(/data:[^;]+;base64,(.+)/);E&&(x=E[1],(S=y.mediaType)!=null&&S.startsWith("image/")&&(v=y.url))}return{id:`${a.id||l}-file-${b}`,name:y.filename||`File ${b+1}`,size:0,type:y.mediaType||"application/octet-stream",data:x,preview:v}});return u.jsx(yVe,{text:m||void 0,files:g.length>0?g:void 0},a.id||l)}return(f=a.parts)==null?void 0:f.map((h,p)=>{var g;const m=`${a.id||l}-${p}`;switch(h.type){case"text":{const y=typeof h.text=="string"?h.text:JSON.stringify(h.text??"",null,2);if(a.role==="assistant"){const{cleanedText:b,quickReplies:x}=mVe(y),v=b.trim().length>0;return u.jsxs("div",{className:"my-4 space-y-2",children:[v&&u.jsx(I4,{text:b,handleRun:o,onAddToDashboard:n}),x.length>0&&s&&u.jsx("div",{className:"mt-3 flex flex-wrap justify-center gap-2",children:x.map(({label:w,value:S},E)=>u.jsxs(oi,{children:[u.jsx(si,{asChild:!0,children:u.jsx(ae,{size:"sm",variant:"outline",disabled:i,onClick:()=>s(S),children:w})}),u.jsx(Zi,{side:"top",align:"center",children:u.jsx("p",{className:"max-w-xs text-xs",children:S})})]},`${m}-qr-${E}`))})]},m)}return a.role==="system"&&r?u.jsx(xVe,{text:y},m):null}case"error":{const y=h,b=y.errorText??y.error??y.message;return u.jsx("div",{className:"my-4",children:u.jsx(BD,{errorMessage:b})},m)}case"reasoning":return h.state==="streaming"?u.jsx("div",{className:"mt-2 animate-pulse",children:h.text?u.jsx(I4,{className:"text-xs text-muted-foreground",text:h.text}):u.jsx("div",{className:"text-sm text-muted-foreground",children:"Reasoning..."})},m):null;default:return(g=h.type)!=null&&g.startsWith("tool-")||h.type==="dynamic-tool"?u.jsx(nd,{FallbackComponent:({error:y,resetErrorBoundary:b})=>u.jsx(bVe,{error:y,resetErrorBoundary:b}),children:u.jsx(hVe,{part:h,idx:m,showTools:t,onAddToDashboard:n,messages:e})},m):null}})})})}function uX({placeholders:e,onClick:t}){return u.jsx("div",{className:"grid grid-cols-2 gap-2 text-foreground/80",children:e==null?void 0:e.map(n=>u.jsxs("div",{onClick:()=>t(n),className:"cursor-pointer rounded-md border border-border p-4 hover:bg-muted/50",children:[u.jsx("p",{className:"text-sm font-semibold",children:n.title}),u.jsx("p",{className:"text-sm text-muted-foreground/70 dark:text-muted-foreground/50",children:n.subtitle})]},n.title))})}var dX="vercel.ai.error",vVe=Symbol.for(dX),fX,wVe=class hX extends Error{constructor({name:t,message:n,cause:r}){super(n),this[fX]=!0,this.name=t,this.cause=r}static isInstance(t){return hX.hasMarker(t,dX)}static hasMarker(t,n){const r=Symbol.for(n);return t!=null&&typeof t=="object"&&r in t&&typeof t[r]=="boolean"&&t[r]===!0}};fX=vVe;var Jl=wVe;function pX(e){return e==null?"unknown error":typeof e=="string"?e:e instanceof Error?e.message:JSON.stringify(e)}var mX="AI_InvalidArgumentError",gX=`vercel.ai.error.${mX}`,SVe=Symbol.for(gX),bX,CVe=class extends Jl{constructor({message:e,cause:t,argument:n}){super({name:mX,message:e,cause:t}),this[bX]=!0,this.argument=n}static isInstance(e){return Jl.hasMarker(e,gX)}};bX=SVe;var yX="AI_JSONParseError",xX=`vercel.ai.error.${yX}`,EVe=Symbol.for(xX),vX,z4=class extends Jl{constructor({text:e,cause:t}){super({name:yX,message:`JSON parsing failed: Text: ${e}.
930
930
  Error message: ${pX(t)}`,cause:t}),this[vX]=!0,this.text=e}static isInstance(e){return Jl.hasMarker(e,xX)}};vX=EVe;var wX="AI_TypeValidationError",SX=`vercel.ai.error.${wX}`,NVe=Symbol.for(SX),CX,kVe=class $k extends Jl{constructor({value:t,cause:n}){super({name:wX,message:`Type validation failed: Value: ${JSON.stringify(t)}.
931
931
  Error message: ${pX(n)}`,cause:n}),this[CX]=!0,this.value=t}static isInstance(t){return Jl.hasMarker(t,SX)}static wrap({value:t,cause:n}){return $k.isInstance(n)&&n.value===t?n:new $k({value:t,cause:n})}};CX=NVe;var xv=kVe;class B4 extends Error{constructor(t,n){super(t),this.name="ParseError",this.type=n.type,this.field=n.field,this.value=n.value,this.line=n.line}}function RE(e){}function _Ve(e){if(typeof e=="function")throw new TypeError("`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?");const{onEvent:t=RE,onError:n=RE,onRetry:r=RE,onComment:o}=e;let s="",i=!0,a,l="",c="";function d(g){const y=i?g.replace(/^\xEF\xBB\xBF/,""):g,[b,x]=jVe(`${s}${y}`);for(const v of b)f(v);s=x,i=!1}function f(g){if(g===""){p();return}if(g.startsWith(":")){o&&o(g.slice(g.startsWith(": ")?2:1));return}const y=g.indexOf(":");if(y!==-1){const b=g.slice(0,y),x=g[y+1]===" "?2:1,v=g.slice(y+x);h(b,v,g);return}h(g,"",g)}function h(g,y,b){switch(g){case"event":c=y;break;case"data":l=`${l}${y}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/index-W0Unjlcm.js"),r=require("../types/index.cjs");exports.Dashboard=e.Dashboard;exports.EMPTY_SELECTION=r.EMPTY_SELECTION;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/index-DRvSuKSw.js"),r=require("../types/index.cjs");exports.Dashboard=e.Dashboard;exports.EMPTY_SELECTION=r.EMPTY_SELECTION;
@@ -1,4 +1,4 @@
1
- import { D as a } from "../chunks/index--nYl92ic.js";
1
+ import { D as a } from "../chunks/index-BH94YTiC.js";
2
2
  import { EMPTY_SELECTION as e } from "../types/index.js";
3
3
  export {
4
4
  a as Dashboard,
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chunks/index-W0Unjlcm.js"),v=require("./types/index.cjs"),u=require("./chunks/dashboard-plus-BS6U2aw8.js"),a=require("react/jsx-runtime"),x=require("react");require("react-dom");function j(r){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const s in r)if(s!=="default"){const i=Object.getOwnPropertyDescriptor(r,s);Object.defineProperty(t,s,i.get?i:{enumerable:!0,get:()=>r[s]})}}return t.default=r,Object.freeze(t)}const p=j(x);/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chunks/index-DRvSuKSw.js"),v=require("./types/index.cjs"),u=require("./chunks/dashboard-plus-DUGBQtC2.js"),a=require("react/jsx-runtime"),x=require("react");require("react-dom");function j(r){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const s in r)if(s!=="default"){const i=Object.getOwnPropertyDescriptor(r,s);Object.defineProperty(t,s,i.get?i:{enumerable:!0,get:()=>r[s]})}}return t.default=r,Object.freeze(t)}const p=j(x);/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { c as x, E as b, F as N, S as w, U as A, a as L, C as _, u as P, b as v, d as E, P as k, e as W, B as F, f as m, g as R, h as V, i as B, j as O, I as Q, k as I, l as j, m as q, n as U, o as z } from "./chunks/index--nYl92ic.js";
2
- import { D as ne, t as ie, R as de, r as le, r as ce, K as Ye, w as ue, y as he, M as fe, L as pe, Q as Me, T as me, J as De, v as Ce, H as ve, N as be, G as ge, A as ye, z as Te, V as Se, O as xe, s as Ne, X as we, Z as Ae, Y as Le, _ as _e, x as Pe, p as Ee, a0 as ke, W as We, $ as Fe, q as Re } from "./chunks/index--nYl92ic.js";
1
+ import { c as x, E as b, F as N, S as w, U as A, a as L, C as _, u as P, b as v, d as E, P as k, e as W, B as F, f as m, g as R, h as V, i as B, j as O, I as Q, k as I, l as j, m as q, n as U, o as z } from "./chunks/index-BH94YTiC.js";
2
+ import { D as ne, t as ie, R as de, r as le, r as ce, K as Ye, w as ue, y as he, M as fe, L as pe, Q as Me, T as me, J as De, v as Ce, H as ve, N as be, G as ge, A as ye, z as Te, V as Se, O as xe, s as Ne, X as we, Z as Ae, Y as Le, _ as _e, x as Pe, p as Ee, a0 as ke, W as We, $ as Fe, q as Re } from "./chunks/index-BH94YTiC.js";
3
3
  import { EMPTY_SELECTION as Be } from "./types/index.js";
4
- import { A as Qe, R as Ie, b as je, S as qe, D as Ue, a as ze, V as Ge, c as He, g as $e } from "./chunks/dashboard-plus-CbCN1k1x.js";
4
+ import { A as Qe, R as Ie, b as je, S as qe, D as Ue, a as ze, V as Ge, c as He, g as $e } from "./chunks/dashboard-plus-CmctxWlG.js";
5
5
  import { jsx as e, jsxs as d } from "react/jsx-runtime";
6
6
  import * as h from "react";
7
7
  import { useMemo as G } from "react";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/dashboard-plus-BS6U2aw8.js"),r=require("../types/index.cjs");exports.Surfboard=e.DashboardPlus;exports.EMPTY_SELECTION=r.EMPTY_SELECTION;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/dashboard-plus-DUGBQtC2.js"),r=require("../types/index.cjs");exports.Surfboard=e.DashboardPlus;exports.EMPTY_SELECTION=r.EMPTY_SELECTION;
@@ -1,4 +1,4 @@
1
- import { D as f } from "../chunks/dashboard-plus-CbCN1k1x.js";
1
+ import { D as f } from "../chunks/dashboard-plus-CmctxWlG.js";
2
2
  import { EMPTY_SELECTION as a } from "../types/index.js";
3
3
  export {
4
4
  a as EMPTY_SELECTION,
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "email": "support@semaphor.cloud"
6
6
  },
7
7
  "license": "MIT",
8
- "version": "0.0.690",
8
+ "version": "0.0.691",
9
9
  "description": "Fully interactive and customizable dashboards for your apps.",
10
10
  "keywords": [
11
11
  "react",