@duckcodeailabs/dql-cli 1.12.8 → 1.12.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/dql-notebook/assets/{AgentAnswerCard-D1VcQOTJ.js → AgentAnswerCard-Dp4odOLE.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AgentLogPage-DKvtW4Fq.js → AgentLogPage-uvVs284-.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildDialog-apJ4HoK3.js → AiBuildDialog-DEUS19WF.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildResult-CvNitmsw.js → AiBuildResult-B9KmBRsh.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiSidePanel-B2cqbPJr.js → AiSidePanel-C7BZVSkM.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AnalyticsHome-D5I-Okbz.js → AnalyticsHome-4TgtH6SB.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AppsView-DLtjogVz.js → AppsView-CnfNtk5W.js} +3 -3
- package/dist/assets/dql-notebook/assets/{BlockStudio-BmNsIfNK.js → BlockStudio-DUXN3MKz.js} +1 -1
- package/dist/assets/dql-notebook/assets/{BusinessArtifactView-Bvn5X8uW.js → BusinessArtifactView-D8FIgrkF.js} +1 -1
- package/dist/assets/dql-notebook/assets/{DbtFirstModelingPage-DnpVGZJv.js → DbtFirstModelingPage-DR8hTZ95.js} +1 -1
- package/dist/assets/dql-notebook/assets/{GitPage-C_5u2aCj.js → GitPage-BS2sm9zh.js} +1 -1
- package/dist/assets/dql-notebook/assets/{GlobalAiRail-ZOHo4H6j.js → GlobalAiRail-B_MZsB0z.js} +1 -1
- package/dist/assets/dql-notebook/assets/{GovernedContextPage-CUaYIqfd.js → GovernedContextPage-CNM5UCAH.js} +1 -1
- package/dist/assets/dql-notebook/assets/{HelpDocsPage-6SmmBvJh.js → HelpDocsPage-Bc5pLakt.js} +1 -1
- package/dist/assets/dql-notebook/assets/{HomePage-LDu8z_nW.js → HomePage-DQSo-K4y.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDAG-VFSCvevO.js → LineageDAG-RdpWmGmR.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDetailView-CuGG_JDv.js → LineageDetailView-CZEx2r1H.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDrawer-B2SVsEw1.js → LineageDrawer-P7ZdOW8-.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineagePathBreadcrumb-qWhGM3bh.js → LineagePathBreadcrumb-DTUMFkJ8.js} +1 -1
- package/dist/assets/dql-notebook/assets/{MiniLineageGraph-BHxUFWDi.js → MiniLineageGraph-Ctp_yFh8.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewBlockModal-oo3fU5OW.js → NewBlockModal-BLtjuWGy.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewNotebookModal-Bl78Nnjz.js → NewNotebookModal-xgaKB2kI.js} +1 -1
- package/dist/assets/dql-notebook/assets/NotebookEditor-D6RgLQw-.js +202 -0
- package/dist/assets/dql-notebook/assets/{ReadinessPage-CL2EJLKo.js → ReadinessPage-C8hATaT_.js} +1 -1
- package/dist/assets/dql-notebook/assets/{SetupOnboarding-Cqw2NuAn.js → SetupOnboarding-DX2f53J2.js} +1 -1
- package/dist/assets/dql-notebook/assets/{TrustBadge-C4jIUuEE.js → TrustBadge-DPnKzRSY.js} +1 -1
- package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-CwxQ4T19.js +83 -0
- package/dist/assets/dql-notebook/assets/{answer-to-notebook-mhY-MBsX.js → answer-to-notebook-Bm9oByWA.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-left-CwMW-Dnz.js → arrow-left-D2FbLWqh.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-right-CJ_6d0z7.js → arrow-right-OYItAZ-s.js} +1 -1
- package/dist/assets/dql-notebook/assets/{book-open-text-B2q44mou.js → book-open-text-BnnirfAc.js} +1 -1
- package/dist/assets/dql-notebook/assets/{bot-CbsSLtXR.js → bot-BJNxPYFm.js} +1 -1
- package/dist/assets/dql-notebook/assets/{chevron-up-DSMkEFrK.js → chevron-up-DM5LX-26.js} +1 -1
- package/dist/assets/dql-notebook/assets/{circle-x-C5hi2hCq.js → circle-x-Dic_-4tF.js} +1 -1
- package/dist/assets/dql-notebook/assets/{dagre.esm-BT65gOyC.js → dagre.esm-C9zxjHHX.js} +1 -1
- package/dist/assets/dql-notebook/assets/{external-link-sDmXu1pG.js → external-link-DHxAcoCE.js} +1 -1
- package/dist/assets/dql-notebook/assets/{grip-vertical-Ca_E_fRZ.js → grip-vertical-02I-EOjL.js} +1 -1
- package/dist/assets/dql-notebook/assets/{index-CcZ8Dw84.js → index-Ca3UeUWI.js} +3 -3
- package/dist/assets/dql-notebook/assets/{link-2-DaVaJfdX.js → link-2-Delh-lai.js} +1 -1
- package/dist/assets/dql-notebook/assets/{list-tree-DMGqPCsV.js → list-tree-BrIZg6l6.js} +1 -1
- package/dist/assets/dql-notebook/assets/{maximize-2-CVJP65sF.js → maximize-2-CQOA-bbN.js} +1 -1
- package/dist/assets/dql-notebook/assets/{minimize-2-BnsbPUr5.js → minimize-2-CUDBPkwe.js} +1 -1
- package/dist/assets/dql-notebook/assets/{panel-right-open-BTTos1w4.js → panel-right-open-CwhZfkKJ.js} +1 -1
- package/dist/assets/dql-notebook/assets/{pencil-BDR0kEX-.js → pencil-Cf6-MgpT.js} +1 -1
- package/dist/assets/dql-notebook/assets/{rotate-ccw-DrQw5ZrW.js → rotate-ccw-DndbJAiz.js} +1 -1
- package/dist/assets/dql-notebook/assets/{semantic-fields-CgqeBot0.js → semantic-fields-DwKPY_mU.js} +1 -1
- package/dist/assets/dql-notebook/assets/{star-DBVkbHOE.js → star-DvcMC9wZ.js} +1 -1
- package/dist/assets/dql-notebook/assets/{triangle-alert-_FtKJhjm.js → triangle-alert-DUf4Ook0.js} +1 -1
- package/dist/assets/dql-notebook/assets/{usePersistedAgentThreadId-BG1TZXp_.js → usePersistedAgentThreadId-DbdBi0oH.js} +1 -1
- package/dist/assets/dql-notebook/assets/{user-round-DkUToep7.js → user-round-DSt0xU3K.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wand-sparkles-TgacCrJg.js → wand-sparkles-ro8Cq0ro.js} +1 -1
- package/dist/assets/dql-notebook/assets/{workflow-z-B8gUF9.js → workflow-DVJXehjU.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wrench-CgXGBYJ-.js → wrench-DxUnoHtz.js} +1 -1
- package/dist/assets/dql-notebook/assets/{x-FQc3jbQ8.js → x-9Gtb3EAd.js} +1 -1
- package/dist/assets/dql-notebook/index.html +1 -1
- package/dist/local-runtime.d.ts +71 -1
- package/dist/local-runtime.d.ts.map +1 -1
- package/dist/local-runtime.js +558 -54
- package/dist/local-runtime.js.map +1 -1
- package/dist/package.json +10 -10
- package/package.json +10 -10
- package/dist/assets/dql-notebook/assets/NotebookEditor-BWMX6Xfi.js +0 -202
- package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-CZjUHLl5.js +0 -83
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import{g as Re,r as p,a as ne,j as t,b as At,f as Je,h as he,aI as $r,e as Xe,L as Pe,aA as Lr,aK as Vn,B as rt,d as Gn,u as qt,t as Kn,aL as Ze,z as Mr,A as Er,aM as Wr,q as Fr,S as De,ax as Un,c as zt,aJ as Ge,P as Ye,D as Pr,G as Yn,aH as Kt,Y as Et}from"./index-Ca3UeUWI.js";import{S as mt,R as rn,d as Dr}from"./AgentAnswerCard-Dp4odOLE.js";import{S as Nr,F as et,d as sn,e as Hr,A as Or,u as Qr}from"./usePersistedAgentThreadId-DbdBi0oH.js";import{C as Vr}from"./AiBuildResult-B9KmBRsh.js";import{T as Wt}from"./triangle-alert-DUf4Ook0.js";import{U as Gr}from"./user-round-DSt0xU3K.js";import{X as bt}from"./x-9Gtb3EAd.js";import{P as Kr}from"./pencil-Cf6-MgpT.js";import{L as tt}from"./list-tree-BrIZg6l6.js";import{W as Rt}from"./wrench-DxUnoHtz.js";import{A as Ur}from"./arrow-right-OYItAZ-s.js";import{C as Jn}from"./chevron-up-DM5LX-26.js";/**
|
|
2
|
+
* @license lucide-react v0.563.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const Yr=[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]],Jr=Re("archive",Yr);/**
|
|
7
|
+
* @license lucide-react v0.563.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const Xr=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],Zr=Re("circle",Xr);/**
|
|
12
|
+
* @license lucide-react v0.563.0 - ISC
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the ISC license.
|
|
15
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
+
*/const ei=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],Xn=Re("copy",ei);/**
|
|
17
|
+
* @license lucide-react v0.563.0 - ISC
|
|
18
|
+
*
|
|
19
|
+
* This source code is licensed under the ISC license.
|
|
20
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
+
*/const ti=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],ni=Re("ellipsis",ti);/**
|
|
22
|
+
* @license lucide-react v0.563.0 - ISC
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the ISC license.
|
|
25
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/const ri=[["path",{d:"M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5",key:"1gvzjb"}],["path",{d:"M9 18h6",key:"x1upvd"}],["path",{d:"M10 22h4",key:"ceow96"}]],vt=Re("lightbulb",ri);/**
|
|
27
|
+
* @license lucide-react v0.563.0 - ISC
|
|
28
|
+
*
|
|
29
|
+
* This source code is licensed under the ISC license.
|
|
30
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
31
|
+
*/const ii=[["circle",{cx:"6",cy:"19",r:"3",key:"1kj8tv"}],["path",{d:"M9 19h8.5a3.5 3.5 0 0 0 0-7h-11a3.5 3.5 0 0 1 0-7H15",key:"1d8sl"}],["circle",{cx:"18",cy:"5",r:"3",key:"gq8acd"}]],Ut=Re("route",ii);/**
|
|
32
|
+
* @license lucide-react v0.563.0 - ISC
|
|
33
|
+
*
|
|
34
|
+
* This source code is licensed under the ISC license.
|
|
35
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
36
|
+
*/const si=[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]],on=Re("save",si);/**
|
|
37
|
+
* @license lucide-react v0.563.0 - ISC
|
|
38
|
+
*
|
|
39
|
+
* This source code is licensed under the ISC license.
|
|
40
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
41
|
+
*/const oi=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],Sn=Re("square",oi);/**
|
|
42
|
+
* @license lucide-react v0.563.0 - ISC
|
|
43
|
+
*
|
|
44
|
+
* This source code is licensed under the ISC license.
|
|
45
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
46
|
+
*/const li=[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]],ai=Re("zap",li),Ft=[{mode:"auto",label:"Auto",hint:"Adapts per question — fast for lookups, thorough for hard ones"},{mode:"low",label:"Low · fast",hint:"Fewer thinking tokens, skips extra verification"},{mode:"medium",label:"Medium · balanced",hint:"More thinking, still skips the heavy verification"},{mode:"high",label:"High · thorough",hint:"Most thinking, cross-checks the number — slower"}];function wn({t:e,value:n,onChange:r}){const[i,s]=p.useState(null),[o,a]=p.useState(!1),u=p.useRef(null);p.useEffect(()=>{let f=!1;return ne.getProviderSettings().then(({providers:l})=>{f||s(l.find(c=>c.active)??null)}).catch(()=>{}),()=>{f=!0}},[]),p.useEffect(()=>{if(!o)return;const f=l=>{u.current&&!u.current.contains(l.target)&&a(!1)};return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[o]);const d=Ft.find(f=>f.mode===n)??Ft[0],m=i?[i.label,i.model].filter(Boolean).join(" · "):null;return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[m?t.jsxs("span",{title:"Connected model",style:kn(e),children:[t.jsx(Zr,{size:7,fill:e.success,color:e.success}),t.jsx("span",{style:{color:e.textSecondary},children:m})]}):null,t.jsxs("div",{ref:u,style:{position:"relative"},children:[t.jsxs("button",{type:"button",onClick:()=>a(f=>!f),title:"How hard the model thinks for this thread",style:{...kn(e),cursor:"pointer"},children:[t.jsx(ai,{size:12,color:e.textMuted}),t.jsxs("span",{style:{color:e.textSecondary},children:["Thinking: ",d.label]}),t.jsx(At,{size:12,color:e.textMuted})]}),o?t.jsx("div",{role:"menu",style:ci(e),children:Ft.map(f=>{const l=f.mode===n;return t.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":l,onClick:()=>{r(f.mode),a(!1)},style:di(e,l),children:[t.jsxs("span",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[t.jsx("span",{style:{fontWeight:l?600:500,color:e.textPrimary},children:f.label}),l?t.jsx(Je,{size:13,color:e.accent}):null]}),t.jsx("span",{style:{display:"block",fontSize:11,color:e.textMuted,marginTop:2},children:f.hint})]},f.mode)})}):null]})]})}function kn(e){return{display:"inline-flex",alignItems:"center",gap:6,padding:"4px 9px",borderRadius:8,border:`1px solid ${e.btnBorder}`,background:e.btnBg,fontSize:12,lineHeight:1.2,whiteSpace:"nowrap"}}function ci(e){return{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:30,width:264,background:e.cellBg,border:`1px solid ${e.cellBorder}`,borderRadius:10,padding:4,boxShadow:"0 8px 24px rgba(0,0,0,0.18)"}}function di(e,n){return{display:"block",width:"100%",textAlign:"left",padding:"8px 10px",borderRadius:7,border:"none",background:n?e.pillBg:"transparent",cursor:"pointer"}}const ui={draft:"#8b949e",review:"#d29922",certified:"#3fb950",deprecated:"#f85149",pending_recertification:"#db6d28"},pi={queued:"#8b949e",generating:"#4c8dff",running:"#4c8dff",saving:"#4c8dff",saved:"#2ea043",ready:"#2ea043",blocked:"#f85149",needs_attention:"#d29922"},fi={queued:"Queued",generating:"Generating",running:"Running",saving:"Saving",saved:"Saved",ready:"Ready",blocked:"Blocked",needs_attention:"Needs review",draft:"Draft",review:"In review",certified:"Certified",deprecated:"Deprecated",pending_recertification:"Recertify"},gi={draft:Vn,queued:Lr,generating:Pe,running:Pe,saving:Pe,ready:Xe,saved:Xe,blocked:Wt,needs_attention:Wt,review:$r,certified:he,deprecated:Jr,pending_recertification:Wt},xi=new Set(["generating","running","saving"]);function hi(e){return ui[e]??pi[e]??"#8b949e"}function yi(e){return fi[e]??e.charAt(0).toUpperCase()+e.slice(1).replace(/_/g," ")}function mi({status:e,t:n,label:r}){const i=hi(e),s=gi[e]??Vn,o=r??yi(e);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:10,fontWeight:800,color:i,background:`${i}18`,border:`1px solid ${i}33`,borderRadius:999,padding:"2px 8px",fontFamily:n.font,textTransform:"uppercase",letterSpacing:"0.03em",whiteSpace:"nowrap"},children:[t.jsx(s,{size:11,strokeWidth:2.2,className:xi.has(e)?"spin":void 0}),o]})}function bi(e){const{t:n,name:r,status:i="draft",description:s,dql:o,sqlPreview:a,grain:u,outputs:d=[],dimensions:m=[],entities:f=[],examples:l=[],sourceTables:c=[],evidence:h=[],certifierVerdict:x,owner:b,actions:g}=e,[R,$]=p.useState(!1),[N,V]=p.useState(!1);return t.jsxs("section",{style:{border:`1px solid ${n.cellBorder}`,borderRadius:10,background:n.cellBg,padding:14,display:"grid",gap:10,fontFamily:n.font},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[t.jsx(rt,{size:14,strokeWidth:2,color:n.accent}),t.jsx("div",{style:{fontSize:13,fontWeight:850,color:n.textPrimary,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r}),t.jsx(mi,{status:i,t:n}),u?t.jsxs("span",{style:Yt(n),children:["grain ",u]}):null]}),s?t.jsx("div",{style:{fontSize:12,color:n.textSecondary,lineHeight:1.5},children:s}):null,o?t.jsx(Cn,{open:R,onToggle:()=>$(q=>!q),label:"Governed DQL",t:n,lead:!0,children:t.jsx("pre",{style:An(n),children:o})}):null,a?t.jsx(Cn,{open:N,onToggle:()=>V(q=>!q),label:o?"Compiled SQL preview":"SQL this block will run",t:n,children:t.jsx("pre",{style:An(n),children:a})}):null,t.jsx(Pt,{label:"Outputs",items:d,t:n}),t.jsx(Pt,{label:"Dimensions",items:m,t:n}),t.jsx(Pt,{label:"Entities",items:f,t:n}),l.length>0?t.jsxs("div",{style:{display:"grid",gap:5},children:[t.jsx(Zn,{t:n,children:"Answers questions like"}),t.jsx("ul",{style:{margin:0,padding:"0 0 0 16px",display:"grid",gap:3},children:l.slice(0,3).map(q=>t.jsx("li",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.45},children:q},q))})]}):null,c.length>0||h.length>0?t.jsxs("div",{style:{display:"grid",gap:6,border:`1px solid ${n.headerBorder}`,borderRadius:8,background:n.appBg,padding:10},children:[t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:10.5,fontWeight:800,color:n.textSecondary,textTransform:"uppercase"},children:[t.jsx(he,{size:12,color:n.accent})," Grounded on"]}),c.length>0?t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:c.map(q=>t.jsx("span",{style:Yt(n),children:q},q))}):null,h.slice(0,5).map((q,Q)=>t.jsxs("div",{style:{border:`1px solid ${n.headerBorder}`,borderRadius:7,padding:8,background:n.cellBg},children:[t.jsx("div",{style:{fontSize:11,fontWeight:800,color:n.textSecondary,overflowWrap:"anywhere"},children:q.name}),t.jsxs("div",{style:{fontSize:10,color:n.textMuted,marginTop:3},children:[q.kind,q.reason?` · ${q.reason}`:""]}),q.description?t.jsx("div",{style:{fontSize:11,color:n.textMuted,lineHeight:1.35,marginTop:5},children:q.description}):null]},`${q.objectKey??q.name}-${Q}`))]}):null,t.jsx(Vr,{t:n,verdict:x}),b?t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11,color:n.textMuted},children:[t.jsx(Gr,{size:12,strokeWidth:2})," drafting as ",b]}):null,g?t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:g}):null]})}function Cn({open:e,onToggle:n,label:r,t:i,lead:s,children:o}){return t.jsxs("div",{children:[t.jsxs("button",{type:"button",onClick:n,style:{display:"inline-flex",alignItems:"center",gap:5,border:"none",background:"transparent",cursor:"pointer",color:s?i.accent:i.textSecondary,fontSize:11.5,fontWeight:s?800:700,fontFamily:i.font,padding:0},children:[e?t.jsx(At,{size:13,strokeWidth:2}):t.jsx(Gn,{size:13,strokeWidth:2}),e?`Hide ${r.toLowerCase()}`:r]}),e?t.jsx("div",{style:{marginTop:7},children:o}):null]})}function Pt({label:e,items:n,t:r}){return n.length===0?null:t.jsxs("div",{style:{display:"grid",gap:5},children:[t.jsx(Zn,{t:r,children:e}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:n.map(i=>t.jsx("span",{style:Yt(r),children:i},i))})]})}function Zn({t:e,children:n}){return t.jsx("div",{style:{fontSize:10,fontWeight:800,letterSpacing:"0.05em",textTransform:"uppercase",color:e.textMuted},children:n})}function Yt(e){return{fontSize:10.5,fontWeight:700,color:e.textSecondary,background:e.pillBg,borderRadius:999,padding:"2px 8px",fontFamily:e.fontMono}}function An(e){return{margin:0,fontFamily:e.fontMono,fontSize:11.5,whiteSpace:"pre-wrap",color:e.textSecondary,background:e.appBg,border:`1px solid ${e.headerBorder}`,borderRadius:7,padding:10,maxHeight:240,overflow:"auto"}}function qn(){return t.jsx("span",{style:{color:"#ff7b72",marginLeft:2},children:"*"})}function Dt(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function vi(e){const n=new Set,r=/@(metric|dim)\(([^)]+)\)/gi;let i;for(;i=r.exec(e);)n.add(i[2].trim());return Array.from(n)}function zn({cell:e,onClose:n,onSaved:r,initialContent:i,initialName:s,initialDescription:o,initialTags:a,initialDomain:u,initialOwner:d}){var B;const{state:m,dispatch:f}=qt(),l=Kn[m.themeMode],c=p.useRef(null),[h,x]=p.useState(s||e.name||"new_block"),[b,g]=p.useState(u??""),[R,$]=p.useState(d??""),[N,V]=p.useState(o??m.notebookMetadata.description??""),[q,Q]=p.useState((a??m.notebookMetadata.categories??[]).join(", ")),[F,I]=p.useState(i??e.content),[H,O]=p.useState(""),[_,v]=p.useState(""),[S,G]=p.useState([]),[M,Y]=p.useState(!1),[Z,se]=p.useState(null),P=p.useMemo(()=>vi(F),[F]),D=p.useMemo(()=>q.split(",").map(C=>C.trim()).filter(Boolean),[q]),ae=[{id:"has-name",label:"Block has name",severity:"error",passed:!!h.trim()},{id:"has-owner",label:"Block has owner",severity:"error",passed:!!R.trim()},{id:"has-description",label:"Description",severity:"warning",passed:!!N.trim()},{id:"has-domain",label:"Domain",severity:"warning",passed:!!b.trim()},{id:"has-tags",label:"Has at least one tag",severity:"warning",passed:D.length>0},{id:"has-llm-context",label:"Has LLM context (for agents)",severity:"warning",passed:!!H.trim()}],J=ae.some(C=>C.severity==="error"&&!C.passed);p.useEffect(()=>{var C;(C=c.current)==null||C.focus()},[]),p.useEffect(()=>{const C=A=>{A.key==="Escape"&&n()};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[n]);const K=m.semanticLayer.domains,de=`${b.trim()?`blocks/${Dt(b)}/`:"blocks/"}${Dt(h)||"new-block"}.dql`,k=async()=>{var C,A,U;if(J){se("Enter the block name and owner before saving.");return}if(!F.trim()){se("Block content is required.");return}Y(!0),se(null);try{const ee=_.split(`
|
|
47
|
+
`).map(j=>j.trim()).filter(Boolean),He=S.map(j=>({question:j.question.trim(),sql:j.sql.trim()||void 0})).filter(j=>j.question),ve=await ne.saveAsBlock({cellId:e.id,notebookPath:((C=m.activeFile)==null?void 0:C.path)??null,name:h.trim(),domain:b.trim()||void 0,owner:R.trim()||void 0,content:F,description:N.trim()||void 0,tags:D,metricRefs:P,llmContext:H.trim()||void 0,examples:He.length>0?He:void 0,invariants:ee.length>0?ee:void 0,reviewRequired:!!((A=e.datasetRefs)!=null&&A.length),datasetRefs:e.datasetRefs,lineage:(U=e.dqlArtifact)==null?void 0:U.lineage}),_e={name:`${Dt(h)||"new-block"}.dql`,path:ve.path,type:"block",folder:"blocks"};m.files.some(j=>j.path===ve.path)||f({type:"FILE_ADDED",file:_e});const we=await ne.openBlockStudio(ve.path);f({type:"OPEN_BLOCK_STUDIO",file:_e,payload:we}),r==null||r({...ve,name:h.trim()}),n()}catch(ee){se(ee instanceof Error?ee.message:String(ee))}finally{Y(!1)}},L={width:"100%",background:l.inputBg,border:`1px solid ${Z?l.error:l.inputBorder}`,borderRadius:6,color:l.textPrimary,fontSize:13,fontFamily:l.font,padding:"8px 12px",outline:"none",boxSizing:"border-box"};return t.jsx("div",{onClick:C=>{C.target===C.currentTarget&&n()},style:{position:"fixed",inset:0,background:l.modalOverlay,display:"flex",alignItems:"center",justifyContent:"center",zIndex:1100,backdropFilter:"blur(4px)"},children:t.jsxs("div",{style:{width:760,maxWidth:"calc(100vw - 48px)",maxHeight:"calc(100vh - 48px)",overflow:"auto",background:l.modalBg,border:`1px solid ${l.cellBorder}`,borderRadius:12,boxShadow:"0 20px 60px rgba(0,0,0,0.5)"},children:[t.jsxs("div",{style:{padding:"20px 24px 0",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsx("h2",{style:{margin:0,fontSize:16,fontWeight:600,color:l.textPrimary,fontFamily:l.font},children:"Save as Block"}),t.jsx("button",{onClick:n,style:{background:"transparent",border:"none",color:l.textMuted,cursor:"pointer",fontSize:18},children:"×"})]}),t.jsxs("div",{style:{padding:"20px 24px 24px",display:"flex",flexDirection:"column",gap:16},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsxs("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:["Block Name ",t.jsx(qn,{})]}),t.jsx("input",{ref:c,value:h,onChange:C=>x(C.target.value),style:L})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:"Domain"}),t.jsx("input",{value:b,onChange:C=>g(C.target.value),list:"semantic-domain-options",style:L,placeholder:"finance"}),t.jsx("datalist",{id:"semantic-domain-options",children:K.map(C=>t.jsx("option",{value:C},C))})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsxs("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:["Owner ",t.jsx(qn,{})]}),t.jsx("input",{value:R,onChange:C=>$(C.target.value),style:L,placeholder:"data-platform@company.com"})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:"Tags"}),t.jsx("input",{value:q,onChange:C=>Q(C.target.value),style:L,placeholder:"revenue, dashboard"})]})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:"Description"}),t.jsx("input",{value:N,onChange:C=>V(C.target.value),style:L})]}),t.jsxs("details",{style:{border:`1px solid ${l.cellBorder}`,borderRadius:6,padding:"8px 12px"},children:[t.jsx("summary",{style:{fontSize:12,fontWeight:600,color:l.textSecondary,fontFamily:l.font,cursor:"pointer"},children:"Agent-facing metadata (optional — helps AI tools ground answers on this block)"}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10,paddingTop:10},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:"How should an AI describe this block?"}),t.jsx("textarea",{value:H,onChange:C=>O(C.target.value),rows:3,placeholder:'One paragraph. E.g. "Monthly revenue recognized from closed-won deals, grouped by billing month. Excludes refunds."',style:{...L,fontFamily:l.font,lineHeight:1.5,resize:"vertical"}})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:"Invariants (one per line)"}),t.jsx("textarea",{value:_,onChange:C=>v(C.target.value),rows:2,placeholder:`Revenue is never negative
|
|
48
|
+
Each row is a unique month`,style:{...L,fontFamily:l.fontMono,lineHeight:1.5,resize:"vertical"}})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:"Example questions (grounding for chat cells)"}),S.map((C,A)=>t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr auto",gap:6},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[t.jsx("input",{value:C.question,onChange:U=>{const ee=[...S];ee[A]={...ee[A],question:U.target.value},G(ee)},placeholder:"What was revenue last month?",style:L}),t.jsx("input",{value:C.sql,onChange:U=>{const ee=[...S];ee[A]={...ee[A],sql:U.target.value},G(ee)},placeholder:"Optional SQL snippet",style:{...L,fontFamily:l.fontMono,fontSize:12}})]}),t.jsx("button",{type:"button",onClick:()=>G(S.filter((U,ee)=>ee!==A)),style:{background:"transparent",border:`1px solid ${l.cellBorder}`,borderRadius:6,color:l.textMuted,cursor:"pointer",fontSize:12,padding:"0 10px"},children:"×"})]},A)),t.jsx("button",{type:"button",onClick:()=>G([...S,{question:"",sql:""}]),style:{alignSelf:"flex-start",background:l.btnBg,border:`1px solid ${l.btnBorder}`,borderRadius:6,color:l.textSecondary,cursor:"pointer",fontSize:12,fontFamily:l.font,padding:"4px 10px"},children:"+ Add example"})]})]})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6,padding:"10px 12px",background:l.pillBg,borderRadius:6,border:`1px solid ${l.cellBorder}`},children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:l.textSecondary,fontFamily:l.font,letterSpacing:"0.06em",textTransform:"uppercase"},children:"Governance checks"}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:ae.map(C=>{const A=C.passed?"#3fb950":C.severity==="error"?"#ff7b72":"#e3b341",U=C.passed?"✓":C.severity==="error"?"✕":"!";return t.jsxs("span",{title:C.passed?`${C.label} — passed`:`${C.label} — ${C.severity}`,style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,fontFamily:l.font,color:A,background:`${A}18`,border:`1px solid ${A}55`,borderRadius:999,padding:"2px 10px"},children:[t.jsx("span",{style:{fontWeight:700},children:U}),C.label]},C.id)})})]}),t.jsx("div",{style:{fontSize:12,color:l.textMuted,fontFamily:l.fontMono,padding:"8px 12px",background:l.pillBg,borderRadius:6},children:de}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:"Content Preview"}),t.jsx("textarea",{value:F,onChange:C=>I(C.target.value),style:{...L,minHeight:220,resize:"vertical",fontFamily:l.fontMono,lineHeight:1.5}})]}),P.length>0&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,padding:"10px 12px",background:l.pillBg,borderRadius:6},children:[t.jsx("span",{style:{fontSize:11,color:l.textMuted,fontFamily:l.font},children:"Detected semantic refs:"}),P.map(C=>t.jsx("span",{style:{fontSize:11,color:l.accent,fontFamily:l.fontMono,background:`${l.accent}18`,borderRadius:999,padding:"2px 8px"},children:C},C))]}),Z&&t.jsx("div",{style:{fontSize:12,color:l.error,fontFamily:l.font},children:Z})]}),t.jsxs("div",{style:{padding:"14px 24px",borderTop:`1px solid ${l.cellBorder}`,display:"flex",justifyContent:"flex-end",gap:10},children:[t.jsx("span",{style:{fontSize:11.5,color:l.textMuted,marginRight:"auto",alignSelf:"center"},children:(B=e.datasetRefs)!=null&&B.length?"This analysis uses imported or staged data, so it will be saved as a review-required draft. Certification requires project-controlled, contracted, tested, reproducible sources.":"DQL will certify this block now when its local checks pass; otherwise it is saved as a draft."}),t.jsx("button",{onClick:n,style:{background:l.btnBg,border:`1px solid ${l.btnBorder}`,borderRadius:6,color:l.textSecondary,cursor:"pointer",fontSize:13,fontFamily:l.font,padding:"7px 16px"},children:"Cancel"}),t.jsx("button",{onClick:k,disabled:M||J,title:J?"Fix governance errors to enable Save":void 0,style:{background:l.accent,border:`1px solid ${l.accent}`,borderRadius:6,color:"#fff",cursor:M||J?"not-allowed":"pointer",fontSize:13,fontFamily:l.font,padding:"7px 20px",opacity:M||J?.5:1},children:M?"Saving & checking…":"Save block"})]})]})})}function er(e){return e.policy==="dynamic"||e.policy==="optional"}function ji({parameters:e,values:n,onChange:r,onReset:i,t:s,includeNonRuntime:o=!1,card:a=!1}){const u=e.filter(d=>o||er(d));return u.length===0?null:t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(170px, 1fr))",gap:8},children:u.map(d=>{const m=Object.prototype.hasOwnProperty.call(n,d.name),f=m?n[d.name]:d.default,l=h=>r(d.name,h),c=d.type==="boolean"?t.jsxs("select",{"aria-label":d.name,value:String(f??""),onChange:h=>l(h.target.value),style:Rn(s),children:[t.jsx("option",{value:"",children:"Select…"}),t.jsx("option",{value:"true",children:"True"}),t.jsx("option",{value:"false",children:"False"})]}):t.jsx("input",{"aria-label":d.name,type:d.type==="number"?"number":d.type==="date"?"date":"text",value:Array.isArray(f)?f.join(", "):f==null?"":String(f),placeholder:d.type.endsWith("[]")?"Comma-separated values":d.required?"Required value":"Use default",onChange:h=>l(h.target.value),style:Rn(s)});return t.jsxs("label",{style:{display:"grid",gap:4,minWidth:0,...a?{padding:9,border:`1px solid ${s.cellBorder}`,borderRadius:7,background:s.appBg}:{}},children:[t.jsxs("span",{style:{display:"flex",gap:5,alignItems:"center",fontSize:10.5,fontWeight:750,color:s.textSecondary},children:[Si(d.name),d.required?t.jsx("span",{style:{color:s.error},children:"*"}):null]}),c,t.jsxs("span",{style:{display:"flex",alignItems:"center",gap:5,minHeight:14,fontSize:9.5,color:s.textMuted},children:[t.jsxs("span",{children:[d.type,o?` · ${d.policy}`:""]}),m&&i?t.jsx("button",{type:"button",onClick:()=>i(d.name),style:{marginLeft:"auto",border:0,padding:0,background:"transparent",color:s.accent,fontSize:9.5,cursor:"pointer"},children:"Reset"}):null]})]},d.name)})})}function Si(e){return e.replace(/[_-]+/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function Rn(e){return{width:"100%",minWidth:0,boxSizing:"border-box",background:e.inputBg,border:`1px solid ${e.inputBorder}`,borderRadius:5,color:e.textPrimary,padding:"5px 7px",fontSize:11,fontFamily:e.font}}function wi(e){const n=e.filter(o=>o.kind==="run").map(ki).filter(o=>!!o).slice(-6);if(n.length===0)return;const r=[...n].reverse().find(o=>{var a;return(a=o.result)==null?void 0:a.columns.length})??n[n.length-1],i=r.result,s=tr(_n(r));return Jt({activeSurface:"notebook",conversationStateVersion:1,activeTurnId:r.id,activeTopic:r.question,conversationSummary:_i(n),turns:n,sourceAnswerId:r.id,sourceCertifiedBlock:r.sourceCertifiedBlock,sourceQuestion:r.question,sourceAnswerSummary:r.answerSummary,answerContract:_n(r),dqlArtifact:r.dqlArtifact,cascade:r.cascade,resultColumns:i==null?void 0:i.columns,resultRowsSample:i==null?void 0:i.rowsSample,resultDimensionValues:i==null?void 0:i.dimensionValues,outputColumns:i==null?void 0:i.columns,requestedFilters:r.requestedFilters??Qe(s==null?void 0:s.filters),requestedDimensions:r.requestedDimensions??Qe(s==null?void 0:s.dimensions),priorLimit:r.topN??nr(s),priorMeasures:r.requestedMeasures??(i==null?void 0:i.measureColumns),contextPackId:r.contextPackId,trustLabel:r.trustLabel,reviewStatus:r.reviewStatus,certification:r.certification,route:r.route,sourceSql:r.sourceSql,updatedAt:r.completedAt})}function ki(e){var l,c,h,x;const n=e.run.artifacts.find(b=>b.kind==="answer")??e.run.artifacts.find(b=>b.kind==="research_run")??e.run.artifacts[0],r=pe(n==null?void 0:n.payload),i=Ci(r),s=Ti(i),o=Array.isArray(i==null?void 0:i.rows)?i.rows.filter(b=>!!(b&&typeof b=="object"&&!Array.isArray(b))).slice(0,24):[],a=((l=pe(r==null?void 0:r.contextPack))==null?void 0:l.questionPlan)??(r==null?void 0:r.analysisPlan),u=tr(a),d=$i(s,o),m=Ii(u,s),f=re(r==null?void 0:r.sourceCertifiedBlock)??((n==null?void 0:n.kind)==="answer"?re(n.ref):void 0)??re((c=pe(r==null?void 0:r.block))==null?void 0:c.name);return Jt({id:e.run.id,question:e.run.question,answerSummary:e.run.answer??e.run.summary,completedAt:e.run.completedAt,artifactKind:n==null?void 0:n.kind,sourceCertifiedBlock:f,route:re((h=pe(r==null?void 0:r.route))==null?void 0:h.label)??re((x=pe(r==null?void 0:r.route))==null?void 0:x.tier),trustLabel:re(r==null?void 0:r.trustLabel),reviewStatus:re(r==null?void 0:r.reviewStatus),certification:re(r==null?void 0:r.certification),contextPackId:re(r==null?void 0:r.contextPackId),requestedFilters:Qe(u==null?void 0:u.filters),requestedDimensions:Qe(u==null?void 0:u.dimensions),requestedMeasures:Qe(u==null?void 0:u.measures),answerContract:a,dqlArtifact:zi(r),cascade:Ri(r),topN:nr(u),result:s.length>0||o.length>0?Jt({columns:s,rowsSample:o,dimensionValues:d,measureColumns:m,rowCount:Ai(i)}):void 0,sourceSql:qi(r,i)})}function _n(e){return e.answerContract}function tr(e){const n=pe(e);return pe(n==null?void 0:n.requestedShape)}function Ci(e){const n=pe(e==null?void 0:e.researchRun),r=pe(e==null?void 0:e.result);return[e==null?void 0:e.result,e==null?void 0:e.resultPreview,n==null?void 0:n.resultPreview,n==null?void 0:n.result,r==null?void 0:r.result].map(pe).filter(s=>!!(s&&(Array.isArray(s.rows)||Array.isArray(s.columns)))).sort((s,o)=>In(o)-In(s))[0]}function In(e){const n=Array.isArray(e.rows)?e.rows.length:0,r=typeof e.rowCount=="number"&&Number.isFinite(e.rowCount)?e.rowCount:0;return n*1e5+r}function Ai(e){const n=e==null?void 0:e.rowCount;return typeof n=="number"&&Number.isFinite(n)?n:Array.isArray(e==null?void 0:e.rows)?e.rows.length:void 0}function qi(e,n){var r,i;return re(e==null?void 0:e.proposedSql)??re(e==null?void 0:e.sql)??re(n==null?void 0:n.sql)??re((r=pe(e==null?void 0:e.query))==null?void 0:r.sql)??re((i=pe(e==null?void 0:e.plan))==null?void 0:i.sql)}function zi(e){var r,i;const n=Ze(e==null?void 0:e.dqlArtifact);return n?{...n,source:n.source.slice(0,3e3),filters:(r=n.filters)==null?void 0:r.filter(s=>s.values.length>0).slice(0,12).map(s=>({...s,values:s.values.slice(0,12)})),orderBy:(i=n.orderBy)==null?void 0:i.slice(0,8)}:void 0}function Ri(e){const n=pe(e==null?void 0:e.cascade);if(!n)return;const r=re(n.terminalLane),i=re(n.routeTier);if(!(!r&&!i))return{terminalLane:r,routeTier:i,label:re(n.label),ref:re(n.ref),artifactKind:re(n.artifactKind),refusalCode:re(n.refusalCode),outcome:pe(n.outcome)}}function _i(e){const n=e.slice(-3).map(r=>{var o,a;const i=(o=r.result)==null?void 0:o.columns.slice(0,5).join(", "),s=(a=r.result)!=null&&a.dimensionValues?Object.entries(r.result.dimensionValues).slice(0,3).map(([u,d])=>`${u}: ${d.slice(0,3).join(", ")}`).join("; "):"";return[`Q: ${r.question}`,r.answerSummary?`A: ${r.answerSummary}`:"",i?`Columns: ${i}`:"",s?`Values: ${s}`:""].filter(Boolean).join(" | ")}).filter(Boolean);return n.length>0?n.join(`
|
|
49
|
+
`):void 0}function nr(e){const n=pe(e==null?void 0:e.topN),r=n==null?void 0:n.n;return typeof r=="number"&&Number.isFinite(r)&&r>0?r:void 0}function Ii(e,n){const r=[...Qe(e==null?void 0:e.measures)??[],...n.filter(s=>/\b(revenue|sales|amount|total|count|average|avg|sum|spend|cost|margin|profit|value|points?|score|quantity|units?|rate|volume)\b/i.test(s.replace(/_/g," ")))],i=Array.from(new Set(r.map(s=>s.trim()).filter(Boolean))).slice(0,12);return i.length>0?i:void 0}function pe(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function Ti(e){const r=(Array.isArray(e==null?void 0:e.columns)?e.columns:[]).map(Bi).filter(o=>!!o),i=Array.isArray(e==null?void 0:e.rows)?e.rows.find(o=>o&&typeof o=="object"&&!Array.isArray(o)):void 0,s=i?Object.keys(i):[];return Array.from(new Set([...r,...s])).slice(0,32)}function Qe(e){if(!Array.isArray(e))return;const n=e.map(i=>typeof i=="string"?i.trim():"").filter(Boolean),r=Array.from(new Set(n)).slice(0,24);return r.length>0?r:void 0}function Bi(e){if(typeof e=="string"&&e.trim())return e.trim();if(e&&typeof e=="object"){const n=e;return re(n.name)??re(n.field)??re(n.key)}}function $i(e,n){const r=e.filter(s=>/\b(category|product|customer|account|user|segment|region|channel|type|name)\b/i.test(s.replace(/_/g," "))).slice(0,12),i={};for(const s of r){const o=[];for(const a of n){const u=pe(a),d=u==null?void 0:u[s],m=typeof d=="string"||typeof d=="number"?String(d).trim():"";if(!(!m||o.includes(m))&&(o.push(m),o.length>=24))break}o.length>0&&(i[Li(s)]=o)}return Object.keys(i).length>0?i:void 0}function Li(e){const n=e.toLowerCase();return n.includes("category")?"category":n.includes("product")?n.includes("name")?"product_name":"product":n.includes("customer")?n.includes("name")?"customer_name":"customer":n.includes("segment")?"segment":n.includes("region")?"region":n.includes("channel")?"channel":n.replace(/[^a-z0-9_]+/g,"_")}function re(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function Jt(e){const n={};for(const[r,i]of Object.entries(e))i!=null&&(Array.isArray(i)&&i.length===0||typeof i=="object"&&!Array.isArray(i)&&Object.keys(i).length===0||(n[r]=i));return Object.keys(n).length>0?n:void 0}function Mi(e){return JSON.stringify([e.kind,e.name??null,e.source,e.persistence??null,e.parameters??[],Object.entries(e.parameterValues??{}).sort(([n],[r])=>n.localeCompare(r)),e.executionReceipt??null])}function rr(e,n){if(e.kind==="sql_block"){const s=new Map(n.columns.map(o=>[o.toLowerCase(),o]));return(e.filterableColumns??[]).flatMap(o=>{const a=s.get(o.column.toLowerCase());return a?[{column:a,field:o.predicateTarget,values:Tn(n.rows.map(u=>u[a]))}]:[]})}if(e.kind!=="semantic_block"||e.persistence!=="transient")return[];const r=new Map(n.columns.map(s=>[s.toLowerCase(),s])),i=new Set((e.parameters??[]).flatMap(s=>{var o;return((o=s.binding)==null?void 0:o.kind)==="semantic_filter"?[s.binding.field.toLowerCase()]:[]}));return(e.dimensions??[]).flatMap(s=>{if(i.has(s.toLowerCase()))return[];const o=s.split(".").at(-1)??s,a=r.get(s.toLowerCase())??r.get(o.toLowerCase())??r.get(s.split(".").join("_").toLowerCase());if(!a)return[];const u=Tn(n.rows.map(d=>d[a]));return[{column:a,field:s,values:u}]})}function Ei(e,n,r,i){const s=rr(e,n).find(g=>g.column===r);if(!s)throw new Error(`"${r}" is not an available semantic result filter.`);if(i==null||String(i).trim()==="")throw new Error("Choose a default filter value before adding the input.");const o=new Set((e.parameters??[]).map(g=>g.name)),a=Wi(s.field.split(".").at(-1)??s.column);let u=a,d=2;for(;o.has(u);)u=`${a}_${d++}`;const m=Array.isArray(i)?i.map(String).join(", "):String(i),f=Mr(m,u);let l=Er(e.source,{name:u,type:f,required:!1,defaultText:m,policy:"dynamic"});l=Wr(l,u,s.field);const c=Fr(l).map(g=>{var R,$,N;return{...g,...((R=g.binding)==null?void 0:R.kind)==="semantic_filter"&&g.binding.field?{binding:{kind:"semantic_filter",field:g.binding.field,operator:g.binding.operator??"equals"}}:(($=g.binding)==null?void 0:$.kind)==="limit"?{binding:{kind:"limit"}}:((N=g.binding)==null?void 0:N.kind)==="sql_value"?{binding:{kind:"sql_value"}}:{binding:void 0}}}),{executionReceipt:h,compiledSql:x,...b}=e;return{artifact:{...b,source:l,parameters:c,parameterValues:{...e.parameterValues??{},[u]:i}},parameterName:u}}function Tn(e){const n=new Set,r=[];for(const i of e){if(typeof i!="string"&&typeof i!="number"&&typeof i!="boolean")continue;const s=`${typeof i}:${String(i)}`;if(!n.has(s)&&(n.add(s),r.push(i),r.length>=50))break}return r}function Wi(e){const n=e.trim().toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"");return/^[a-z_][a-z0-9_]*$/.test(n)?n:"result_filter"}function ir(e){var r,i,s;const n=[];for(const o of e){if(o.kind==="user"){n.push({role:"user",text:o.text});continue}if(o.run.status==="blocked"||((r=o.run.artifacts)==null?void 0:r.some(u=>{const d=le(u);return!!(d.executionError||d.warehouseFailure||d.analyticalFailure)}))){((i=n.at(-1))==null?void 0:i.role)==="user"&&n.pop();continue}n.push({role:"assistant",text:((s=o.run.answer)==null?void 0:s.trim())||o.run.summary})}return n.slice(-12)}const ln="dql.agent.active-runs.v1",sr={conversation:"Chat",certified_answer:"Certified answer",semantic_answer:"Governed semantic answer",generated_answer:"Generated answer",research:"Research plan",sql_cell:"SQL cell",dql_block_draft:"DQL block draft",app_build:"App plan",clarify:"Clarify",blocked:"Blocked"};function Fi({themeMode:e,title:n="AI Copilot",scopeHint:r="Auto routes to answer, research, SQL, block, or app",onClearScope:i,examplePrompts:s,emptyHint:o,notebookPath:a,selectedObject:u,workspaceContext:d,initialMode:m="auto",initialInput:f="",initialItems:l,onItemsChange:c,threadId:h,onThreadIdChange:x,audience:b="analyst",autoRun:g,onInsertSql:R,onInsertDql:$,onReplaceDql:N,onArtifactReady:V,onOpenBlock:q,onOpenResearch:Q,onOpenApp:F,onRunningChange:I,answerFirstCards:H=!1,insertDqlActionLabel:O,replaceDqlActionLabel:_,askLayout:v=!1}){const S=Kn[e],G=p.useRef(void 0),[M,Y]=p.useState(f),[Z,se]=p.useState(l??[]),[P,D]=p.useState([]),[ae,J]=p.useState(""),[K,de]=p.useState(!1),[k,L]=p.useState(null),[B,C]=p.useState(null),[A,U]=p.useState(null),[ee,He]=p.useState(()=>Pi()),[ve,_e]=p.useState([]),[we,j]=p.useState(),ce=p.useCallback(y=>{He(y);try{window.localStorage.setItem(or,y)}catch{}},[]),je=p.useRef(null),xn=p.useRef(f),hn=p.useRef(null),Le=p.useRef(null),me=p.useRef(null),Me=p.useRef(null),fe=p.useRef(null),Ie=p.useRef(0),Se=d==null?void 0:d.executionTarget,yn=Se&&typeof Se=="object"&&!Array.isArray(Se)&&Se.target==="connection"&&typeof Se.connectionName=="string"?String(Se.connectionName):void 0,zr=Se&&typeof Se=="object"&&!Array.isArray(Se)&&Se.target==="local";p.useEffect(()=>{let y=!1;return ne.getConnections().then(w=>{if(y)return;const T=Object.keys(w.connections??{}).sort((E,te)=>E.localeCompare(te));_e(T),j(lr(T,w.default,yn))}).catch(()=>{y||(_e([]),j(void 0))}),()=>{y=!0}},[yn]);const mn=p.useCallback(y=>{j(y)},[]),[Te,Bt]=p.useState(null),[ke,Oe]=p.useState(null),[Rr,$t]=p.useState(""),bn=p.useRef(null),ot=p.useRef(null);p.useEffect(()=>{!f||K||f!==xn.current&&(xn.current=f,Y(f))},[f,K]);const _r=p.useMemo(()=>ir(Z),[Z]),lt=p.useRef(c);lt.current=c;const at=p.useRef(V);at.current=V,p.useEffect(()=>{var y;(y=lt.current)==null||y.call(lt,Z)},[Z]);const ge=p.useRef(h),ct=p.useRef(x);ct.current=x;const Lt=p.useCallback((y,w)=>{var T;if(fe.current!==null&&(window.clearTimeout(fe.current),fe.current=null),Nt(y.id),me.current===y.id&&(me.current=null),Me.current=null,L(null),D(y.events.slice(-8)),J(""),se(E=>{if(E.some(ie=>ie.kind==="run"&&ie.run.id===y.id))return E.map(ie=>ie.kind==="run"&&ie.run.id===y.id?{...ie,id:y.id,run:y}:ie);const te=E.some(ie=>ie.kind==="user"&&ie.text===w.question);return[...E,...te?[]:[{kind:"user",id:`${y.id}-question`,text:w.question}],{kind:"run",id:y.id,run:y}]}),y.route!=="certified_answer"){const E=gn(y);E&&((T=at.current)==null||T.call(at,E,y))}},[]),Ue=p.useCallback(y=>{fe.current!==null&&window.clearTimeout(fe.current);const w=++Ie.current;me.current=y.id,Me.current=y,L(y),de(!0),J(""),D([]);const T=async()=>{if(!(w!==Ie.current||me.current!==y.id))try{const E=await ne.getAgentRunState(y.id);if(w!==Ie.current||me.current!==y.id)return;if(E.lifecycleState==="terminal"){Lt(E.run,y),de(!1);return}D(E.progress.events.slice(-8)),fe.current=window.setTimeout(()=>{T()},600)}catch{if(w!==Ie.current||me.current!==y.id)return;fe.current=window.setTimeout(()=>{T()},1200)}};return T(),()=>{w===Ie.current&&(Ie.current+=1),fe.current!==null&&(window.clearTimeout(fe.current),fe.current=null)}},[Lt]),vn=p.useRef(!1);p.useEffect(()=>{if(!h||vn.current)return;vn.current=!0,ge.current??(ge.current=h);let y=!1;return ne.getAgentThread(h).then(({turns:w,runs:T})=>{y||w.length===0||se(E=>{const te=E.filter(oe=>oe.kind==="run").length,ie=ar(w,T);if(w.length>=te)return ie;const ye=new Map(ie.flatMap(oe=>oe.kind==="run"?[[oe.run.id,oe.run]]:[]));return E.map(oe=>oe.kind==="run"&&ye.has(oe.run.id)?{...oe,run:ye.get(oe.run.id)}:oe)})}).catch(()=>{!y&&ge.current===h&&(ge.current=void 0)}),()=>{y=!0}},[h]),p.useEffect(()=>{const y=Mn(h??ge.current);if(!(!y||Le.current))return Ue(y)},[Ue,h]),p.useEffect(()=>{const y=()=>{if(document.visibilityState!=="visible"||Le.current)return;const w=Me.current??Mn(h??ge.current);w&&Ue(w)};return document.addEventListener("visibilitychange",y),()=>document.removeEventListener("visibilitychange",y)},[Ue,h]);const Ce=async(y,w,T)=>{var xt;const E=(y??M).trim();if(!E||K)return;const te=w??G.current??m;G.current=void 0;const ie={kind:"user",id:Dn("user"),text:E};se(ue=>[...ue,ie]),Y(""),U(null),de(!0),D([]),J("");const ye=new AbortController;Le.current=ye;const oe=Dn("run");let xe={id:oe,question:E,threadId:ge.current,startedAt:new Date().toISOString()};me.current=oe,Me.current=xe,L(xe),Ln(xe);let Ee=!1,gt=!1;try{if(!ge.current)try{const Ae=await ne.createAgentThread({surface:v?"ask":typeof(d==null?void 0:d.surface)=="string"?d.surface:a?"notebook":"agent",title:E,...a?{notebookPath:a}:{}});ge.current=Ae.id,(xt=ct.current)==null||xt.call(ct,Ae.id),xe={...xe,threadId:Ae.id},Me.current=xe,L(xe),Ln(xe)}catch{}const ue={question:E,...T?{selectedEvidenceId:T}:{},requestedMode:te,audience:b,selectedObject:u??(a?{kind:"notebook",path:a}:void 0),...zr?{executionTarget:{target:"local"}}:we?{executionTarget:{target:"connection",connectionName:we}}:{},workspaceContext:{...d??{},...a?{notebookPath:a}:{}},conversationContext:wi(Z),history:_r,thinkingMode:ee,runId:oe,...ge.current?{threadId:ge.current}:{}},Br=await ne.createAgentRunStream(ue,Ae=>{Ee=!0,Ae.kind==="event"?D(Mt=>[...Mt,Ae.event].slice(-8)):Ae.kind==="answer-delta"?J(Mt=>Mt+Ae.delta):D(Ae.run.events.slice(-8))},ye.signal);Lt(Br,xe)}catch(ue){ye.signal.aborted||(U(ue instanceof Error?ue.message:String(ue)),Y(E),Ee?(gt=!0,Ue(xe)):(Nt(oe),me.current===oe&&(me.current=null),Me.current=null,L(null)))}finally{Le.current===ye&&(Le.current=null),gt||de(!1)}},dt=()=>{Ce()},jn=()=>{var w;const y=me.current;y&&ne.cancelAgentRun(y).catch(()=>{}),(w=Le.current)==null||w.abort(),Ie.current+=1,fe.current!==null&&window.clearTimeout(fe.current),Nt(y??""),me.current=null,Me.current=null,L(null),J(""),D([]),de(!1),U("Stopped. No answer or draft was saved.")},ut=p.useRef(I);ut.current=I,p.useEffect(()=>{var y;(y=ut.current)==null||y.call(ut,K)},[K]),p.useEffect(()=>{!(g!=null&&g.text)||K||hn.current!==g.nonce&&(hn.current=g.nonce,Ce(g.text,g.mode??m))},[g==null?void 0:g.nonce,g==null?void 0:g.text,g==null?void 0:g.mode,m,K]),p.useEffect(()=>()=>{var y;(y=Le.current)==null||y.abort(),Ie.current+=1,fe.current!==null&&window.clearTimeout(fe.current)},[]);const pt={appId:typeof(d==null?void 0:d.appId)=="string"?d.appId:void 0,dashboardId:typeof(d==null?void 0:d.dashboardId)=="string"?d.dashboardId:void 0},ft=(y,w)=>{var T,E;if(w.id==="save-dql-block"){const te=$e(y),ie=((T=te==null?void 0:te.source)==null?void 0:T.trim())??((E=Be(y))==null?void 0:E.trim());if(!ie){U("This answer does not include a reusable DQL or SQL artifact yet.");return}C({runId:y.id,source:ie,name:(te==null?void 0:te.name)??`${y.question.slice(0,48).trim()||"saved_answer"}`,dqlArtifact:te});return}if(w.id==="research-deeper"){Ce(y.question,"research");return}if(w.id.startsWith("suggest-question")){Ce(w.label,"auto");return}G.current=cs(w.route),Y(ds(y,w.route)),requestAnimationFrame(()=>{var te;return(te=je.current)==null?void 0:te.focus()})},Ir=p.useCallback((y,w,T="trust")=>{Bt({runId:y,artifactId:w,tab:T})},[]),Tr=p.useCallback(y=>{var E,te;const w=y.trim();if(!w)return;const T=(E=ke==null?void 0:ke.text)==null?void 0:E.trim();Oe(null),$t("");try{(te=window.getSelection())==null||te.removeAllRanges()}catch{}Ce(T?`${w}
|
|
50
|
+
|
|
51
|
+
Regarding: "${T}"`:w),requestAnimationFrame(()=>{ot.current&&(ot.current.scrollTop=ot.current.scrollHeight)})},[ke,Ce]);if(p.useEffect(()=>{if(!v)return;const y=T=>{const E=T.target;E&&E.closest("[data-selpop]")||window.setTimeout(()=>{const te=window.getSelection(),ie=te&&te.rangeCount?te.toString().trim():"";if(!ie||ie.length<3){Oe(ue=>ue&&null);return}const ye=te.anchorNode,oe=ye&&(ye.nodeType===1?ye:ye.parentElement),xe=oe==null?void 0:oe.closest("[data-followup]");if(!xe){Oe(ue=>ue&&null);return}const Ee=te.getRangeAt(0).getBoundingClientRect(),gt=Math.max(12,Math.min(Ee.left,window.innerWidth-340)),xt=Ee.bottom+176>window.innerHeight?Math.max(12,Ee.top-176):Ee.bottom+8;Oe({text:ie.slice(0,220),source:xe.getAttribute("data-followup")||"answer",left:gt,top:xt}),$t(""),requestAnimationFrame(()=>{var ue;return(ue=bn.current)==null?void 0:ue.focus()})},0)},w=T=>{T.key==="Escape"&&Oe(null)};return document.addEventListener("mouseup",y),document.addEventListener("keydown",w),()=>{document.removeEventListener("mouseup",y),document.removeEventListener("keydown",w)}},[v]),v){const y=Te?(()=>{const w=Z.find(E=>E.kind==="run"&&E.run.id===Te.runId);if(!w||w.kind!=="run")return null;const T=w.run.artifacts.find(E=>E.id===Te.artifactId);return T?{run:w.run,artifact:T}:null})():null;return t.jsxs("div",{style:{display:"flex",height:"100%",minHeight:0,flex:1,minWidth:0,width:"100%",background:"var(--bg-canvas)"},children:[B?t.jsx(zn,{cell:{id:`agent-${B.runId}`,type:B.dqlArtifact?"dql":"sql",content:B.source,name:B.name,status:"success",...B.dqlArtifact?{dqlArtifact:B.dqlArtifact}:{}},initialContent:B.source,initialName:B.name,onClose:()=>C(null),onSaved:()=>C(null)}):null,t.jsx("style",{children:Ui}),t.jsxs("div",{style:{flex:1,minWidth:360,display:"flex",flexDirection:"column",overflow:"hidden",background:"var(--bg-canvas)"},children:[t.jsxs("div",{style:{height:46,flexShrink:0,borderBottom:"1px solid var(--border-subtle)",display:"flex",alignItems:"center",gap:9,padding:"0 24px"},children:[t.jsx("div",{style:{width:24,height:24,borderRadius:7,background:"var(--accent-dim)",border:"1px solid var(--status-info-border)",color:"var(--accent)",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:t.jsx(De,{size:13})}),t.jsx("span",{style:{fontSize:13.5,fontWeight:650,color:S.textPrimary,whiteSpace:"nowrap"},children:n==="AI Copilot"?"Ask your data":n}),t.jsx("div",{style:{flex:1}}),t.jsx("span",{style:{fontSize:11,color:S.textMuted,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:"Certified first · semantic next · generated SQL last"})]}),t.jsxs("div",{ref:ot,style:{flex:1,minHeight:0,overflowY:"auto",overflowX:"hidden",display:"flex",flexDirection:"column"},children:[t.jsxs("div",{style:{width:"min(720px, 100% - 48px)",margin:"0 auto",padding:"26px 0 12px",display:"flex",flexDirection:"column",gap:26},children:[Z.length===0&&!K?t.jsxs("div",{style:{margin:"auto 0",display:"grid",gap:14,justifyItems:"center",textAlign:"center",color:S.textSecondary,paddingTop:40},children:[t.jsx("div",{style:Nn(S),children:t.jsx(De,{size:20})}),t.jsx("div",{style:{fontSize:13.5,lineHeight:1.5,maxWidth:400,color:S.textSecondary},children:o??Bn}),t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap",justifyContent:"center",maxWidth:520},children:(s??$n).map(w=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>{Y(w.prompt),requestAnimationFrame(()=>{var T;return(T=je.current)==null?void 0:T.focus()})},style:kt(S),children:w.label},w.label))})]}):null,Z.map(w=>w.kind==="user"?t.jsx("div",{style:Yi(S),children:w.text},w.id):t.jsx(Zt,{run:w.run,t:S,themeMode:e,threadId:ge.current,appContext:pt,selectedArtifactId:(Te==null?void 0:Te.runId)===w.run.id?Te.artifactId:void 0,onOpenArtifact:(T,E)=>Ir(w.run.id,T,E),onOpenApp:F,onInsertSql:R,onInsertDql:$,onOpenBlock:q,onOpenResearch:Q,onSelectClarification:T=>{const E=yt(T);Ce(E.question,void 0,E.selectedEvidenceId)},onNextAction:T=>ft(w.run,T)},w.id)),K&&t.jsx(Wn,{events:P,t:S,streamingAnswer:ae,thinkingMode:ee,backgroundRun:k})]}),t.jsxs("div",{style:{width:"min(720px, 100% - 48px)",margin:"auto auto 0",padding:"10px 0 16px",position:"sticky",bottom:0,background:"linear-gradient(to top, var(--bg-canvas) 82%, transparent)"},children:[A?t.jsx("div",{style:{color:S.error,fontSize:12,marginBottom:8},children:A}):null,i?t.jsxs("div",{style:{width:"fit-content",maxWidth:"100%",marginBottom:7,padding:"4px 7px 4px 9px",border:"1px solid var(--border-default)",borderRadius:999,background:"var(--bg-2)",color:S.textMuted,fontSize:10.5,display:"flex",alignItems:"center",gap:5},children:[t.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r}),t.jsx("button",{type:"button",onClick:i,"aria-label":"Clear modeling scope",title:"Clear modeling scope",style:{border:0,background:"transparent",color:S.textMuted,cursor:"pointer",display:"grid",placeItems:"center",padding:1},children:t.jsx(bt,{size:12})})]}):null,t.jsxs("div",{style:{background:"var(--bg-2)",border:"1px solid var(--border-default)",borderRadius:14,boxShadow:"0 1px 2px rgba(26,26,26,0.03), 0 6px 22px rgba(26,26,26,0.05)",display:"flex",flexDirection:"column"},children:[t.jsx("textarea",{ref:je,value:M,onChange:w=>{Y(w.target.value),G.current=void 0},rows:2,placeholder:"Ask anything about your data…",onKeyDown:w=>{w.key==="Enter"&&!w.shiftKey&&(w.preventDefault(),dt())},style:{border:"none",background:"transparent",resize:"none",outline:"none",boxShadow:"none",padding:"13px 15px 4px",fontSize:13.5,lineHeight:1.5,color:S.textPrimary,fontFamily:S.font}}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 10px 10px 12px"},children:[t.jsx(wn,{t:S,value:ee,onChange:ce}),t.jsx(En,{names:ve,value:we,onChange:mn,t:S}),t.jsx("div",{style:{flex:1}}),K?t.jsxs("button",{type:"button",className:"dql-hover",onClick:jn,title:"Stop the active agent run",style:{height:34,padding:"0 12px",borderRadius:10,border:`1px solid ${S.error}`,background:S.btnBg,color:S.error,display:"inline-flex",alignItems:"center",gap:6,cursor:"pointer",fontFamily:S.font,fontSize:12.5,fontWeight:600},children:[t.jsx(Sn,{size:13,fill:"currentColor"})," Stop"]}):null,t.jsx("button",{type:"button",className:"dql-hover dql-lift",title:"Ask",onClick:dt,disabled:!M.trim()||K,style:{width:34,height:34,borderRadius:10,border:"none",background:M.trim()&&!K?"var(--accent)":"var(--bg-4)",color:"#fff",display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:M.trim()&&!K?"pointer":"default",boxShadow:M.trim()&&!K?"0 1px 5px rgba(107,93,211,0.3)":"none"},children:K?t.jsx(Pe,{size:15,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(Un,{size:15})})]})]}),t.jsx("div",{style:{textAlign:"center",fontSize:10.5,color:S.textMuted,marginTop:8},children:"Every answer is grounded in your certified metrics and dbt lineage."})]})]})]}),y?t.jsx(ts,{run:y.run,artifact:y.artifact,tab:Te.tab,t:S,appContext:pt,onOpenApp:F,onChangeTab:w=>Bt(T=>T&&{...T,tab:w}),onClose:()=>Bt(null),onSaveBlock:()=>ft(y.run,{id:"save-dql-block",label:"Save as block",route:"dql_block_draft"}),onInsertSql:R,onInsertDql:$}):null,ke?t.jsx(ns,{t:S,text:ke.text,source:ke.source,left:ke.left,top:ke.top,draft:Rr,inputRef:bn,onDraftChange:$t,onClose:()=>Oe(null),onSend:Tr}):null]})}return t.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0,flex:1,minWidth:0,width:"100%",background:S.cellBg},children:[B?t.jsx(zn,{cell:{id:`agent-${B.runId}`,type:B.dqlArtifact?"dql":"sql",content:B.source,name:B.name,status:"success",...B.dqlArtifact?{dqlArtifact:B.dqlArtifact}:{}},initialContent:B.source,initialName:B.name,onClose:()=>C(null),onSaved:()=>C(null)}):null,t.jsx("style",{children:`
|
|
52
|
+
@keyframes dql-agent-run-spin { to { transform: rotate(360deg); } }
|
|
53
|
+
@keyframes dql-agent-fadein { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
|
|
54
|
+
@keyframes dql-agent-thinking-dot { 0%, 65%, 100% { opacity: .28; transform: translateY(0); } 32% { opacity: 1; transform: translateY(-2px); } }
|
|
55
|
+
@keyframes dql-agent-activity-in { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
|
|
56
|
+
.dql-agent-thinking-dot { animation: dql-agent-thinking-dot 1.05s ease-in-out infinite; }
|
|
57
|
+
.dql-agent-activity { animation: dql-agent-activity-in .22s ease-out; }
|
|
58
|
+
.dql-hover { transition: filter .15s ease, transform .12s ease, box-shadow .15s ease, background .15s ease, color .15s ease, border-color .15s ease; }
|
|
59
|
+
.dql-hover:hover { filter: brightness(1.07); }
|
|
60
|
+
.dql-hover:active { transform: translateY(0.5px); }
|
|
61
|
+
.dql-lift:hover { transform: translateY(-1px); }
|
|
62
|
+
details > summary::-webkit-details-marker { display: none; }
|
|
63
|
+
@media (prefers-reduced-motion: reduce) { .dql-agent-thinking-dot, .dql-agent-activity { animation: none !important; } }
|
|
64
|
+
`}),t.jsxs("div",{style:{flex:1,minHeight:0,overflow:"auto",padding:"14px 16px",display:"flex",flexDirection:"column",gap:12},children:[Z.length===0&&!K?t.jsxs("div",{style:{margin:"auto 0",display:"grid",gap:14,justifyItems:"center",textAlign:"center",color:S.textSecondary},children:[t.jsx("div",{style:Nn(S),children:t.jsx(De,{size:20})}),t.jsx("div",{style:{fontSize:13,lineHeight:1.5,maxWidth:380,color:S.textSecondary},children:o??Bn}),t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap",justifyContent:"center",maxWidth:520},children:(s??$n).map(y=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>{Y(y.prompt),requestAnimationFrame(()=>{var w;return(w=je.current)==null?void 0:w.focus()})},style:kt(S),children:y.label},y.label))})]}):null,Z.map(y=>y.kind==="user"?t.jsx("div",{style:Ss(S),children:y.text},y.id):H?t.jsx(Zt,{run:y.run,t:S,themeMode:e,threadId:ge.current,appContext:pt,onOpenApp:F,onInsertSql:R,onInsertDql:$,onReplaceDql:N,insertDqlActionLabel:O,replaceDqlActionLabel:_,onOpenBlock:q,onOpenResearch:Q,onSelectClarification:w=>{const T=yt(w);Ce(T.question,void 0,T.selectedEvidenceId)},onNextAction:w=>ft(y.run,w)},y.id):t.jsx(Ki,{run:y.run,t:S,themeMode:e,appContext:pt,onOpenApp:F,onInsertSql:R,onInsertDql:$,onOpenBlock:q,onOpenResearch:Q,onSelectClarification:w=>{const T=yt(w);Ce(T.question,void 0,T.selectedEvidenceId)},onNextAction:w=>ft(y.run,w)},y.id)),K&&t.jsx(Wn,{events:P,t:S,streamingAnswer:ae,thinkingMode:ee,backgroundRun:k})]}),A?t.jsx("div",{style:{margin:"0 16px 8px",color:S.error,fontSize:12},children:A}):null,t.jsxs("div",{style:{padding:"10px 16px 14px",borderTop:`1px solid ${S.headerBorder}`,display:"grid",gap:8},children:[t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center",justifyContent:"space-between",flexWrap:"wrap"},children:[t.jsxs("div",{style:{fontSize:11,color:S.textMuted,flex:1,minWidth:180,display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{children:r}),i?t.jsx("button",{type:"button",onClick:i,"aria-label":"Clear modeling scope",title:"Clear modeling scope",style:{border:0,background:"transparent",color:S.textMuted,cursor:"pointer",display:"grid",placeItems:"center",padding:2},children:t.jsx(bt,{size:12})}):null]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(En,{names:ve,value:we,onChange:mn,t:S}),t.jsx(wn,{t:S,value:ee,onChange:ce})]})]}),t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-end"},children:[t.jsx("textarea",{ref:je,value:M,onChange:y=>{Y(y.target.value),G.current=void 0},rows:2,placeholder:"Ask anything about your data…",onKeyDown:y=>{y.key==="Enter"&&!y.shiftKey&&(y.preventDefault(),dt())},style:ms(S)}),t.jsxs("button",{type:"button",className:"dql-hover dql-lift",onClick:dt,disabled:!M.trim()||K,style:Hn(S,!!M.trim()&&!K),children:[K?t.jsx(Pe,{size:15,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(Nr,{size:15}),t.jsx("span",{children:K?"Working":"Ask"})]}),K?t.jsxs("button",{type:"button",className:"dql-hover",onClick:jn,style:{...Hn(S,!0),background:S.btnBg,borderColor:S.error,color:S.error},title:"Stop the active agent run",children:[t.jsx(Sn,{size:13,fill:"currentColor"}),t.jsx("span",{children:"Stop"})]}):null]})]})]})}const Bn="Ask a question — every answer is grounded in your certified metrics and dbt lineage. Use Research deeper on any answer for a slower investigation.",$n=[{label:"What is total revenue?",prompt:"What is total revenue?"},{label:"Why is revenue down by region?",prompt:"Why is revenue down by region?"},{label:"Top customers by revenue this quarter",prompt:"Top customers by revenue this quarter"},{label:"How have orders trended over the last 6 months?",prompt:"How have orders trended over the last 6 months?"}];function an(){try{const e=JSON.parse(window.localStorage.getItem(ln)??"[]");return Array.isArray(e)?e.filter(n=>{if(!n||typeof n!="object")return!1;const r=n;return typeof r.id=="string"&&typeof r.question=="string"&&typeof r.startedAt=="string"&&(r.threadId===void 0||typeof r.threadId=="string")}):[]}catch{return[]}}function Ln(e){try{const n=an().filter(r=>r.id!==e.id);window.localStorage.setItem(ln,JSON.stringify([...n,e].slice(-12)))}catch{}}function Nt(e){try{const n=an().filter(r=>r.id!==e);window.localStorage.setItem(ln,JSON.stringify(n))}catch{}}function Mn(e){const n=an().sort((r,i)=>i.startedAt.localeCompare(r.startedAt));return e?n.find(r=>r.threadId===e):n.find(r=>!r.threadId)}const or="dql.agent.thinkingMode";function lr(e,n,r){return r&&e.includes(r)?r:n&&e.includes(n)?n:e[0]}function En({names:e,value:n,onChange:r,t:i}){return e.length===0||!n?null:t.jsxs("label",{title:"Database connection used for metadata, compilation, and execution in this conversation",style:{height:30,display:"inline-flex",alignItems:"center",gap:5,padding:"0 7px",border:"1px solid var(--border-default)",borderRadius:8,background:"var(--bg-2)",color:i.textMuted,fontSize:11},children:[t.jsx(Pr,{size:12}),t.jsx("select",{"aria-label":"Ask AI database connection",value:n,onChange:s=>r(s.target.value),style:{maxWidth:150,border:0,outline:0,background:"transparent",color:i.textSecondary,font:"inherit",cursor:e.length>1?"pointer":"default"},children:e.map(s=>t.jsx("option",{value:s,children:s},s))})]})}function Pi(){try{const e=window.localStorage.getItem(or);return e==="low"||e==="medium"||e==="high"||e==="auto"?e:"auto"}catch{return"auto"}}const Di=new Set(["conversation","certified_answer","semantic_answer","generated_answer","research","sql_cell","dql_block_draft","app_build","clarify","blocked"]),Ni=new Set(["certified","governed","grounded","review_required","blocked","not_applicable"]),Hi=new Set(["completed","needs_review","needs_clarification","blocked"]),Oi=new Set(["conversational_reply","certified_answer_found","governed_semantic_answer","generated_review_required","artifact_created","needs_clarification","human_review_required","blocked"]);function ar(e,n=[]){const r=new Map(n.map(i=>[i.id,i]));return e.flatMap(i=>{const s=i.agentRunId?r.get(i.agentRunId):void 0;return[{kind:"user",id:`${i.id}-q`,text:i.question},{kind:"run",id:(s==null?void 0:s.id)??i.id,run:s??Qi(i)}]})}function Qi(e){var m,f,l;const n=Di.has(e.route)?e.route:"generated_answer",r=Ni.has(e.trustLabel)?e.trustLabel:e.certification==="certified"?"certified":"not_applicable",i=Hi.has(e.runStatus)?e.runStatus:"completed",s=Oi.has(e.stopReason)?e.stopReason:i==="blocked"?"blocked":i==="needs_clarification"?"needs_clarification":i==="needs_review"?"human_review_required":n==="conversation"?"conversational_reply":r==="certified"?"certified_answer_found":"artifact_created",o=(((m=e.result)==null?void 0:m.columns)??[]).filter(c=>typeof c=="string"),a=(((f=e.result)==null?void 0:f.rowsSample)??[]).filter(c=>Array.isArray(c)).map(c=>Object.fromEntries(o.map((h,x)=>[h,c[x]]))),u=o.length>0?{columns:o,rows:a,rowCount:((l=e.result)==null?void 0:l.rowCount)??a.length}:void 0,d=u||e.sql||e.dqlArtifact||e.sourceCertifiedBlock?{id:`${e.id}-artifact`,kind:"answer",title:e.sourceCertifiedBlock??e.question,trustState:r,ref:e.sourceCertifiedBlock,payload:{...e.sourceCertifiedBlock?{sourceCertifiedBlock:e.sourceCertifiedBlock}:{},...e.certification?{certification:e.certification}:{},...e.contextPackId?{contextPackId:e.contextPackId}:{},...e.sql?{sql:e.sql}:{},...e.dqlArtifact?{dqlArtifact:e.dqlArtifact}:{},...e.cascade?{cascade:e.cascade}:{},...u?{result:u}:{},...e.contract&&Object.keys(e.contract).length>0?{contextPack:{questionPlan:{requestedShape:e.contract}}}:{}}}:void 0;return{id:e.id,question:e.question,requestedMode:"auto",route:n,status:i,trustState:r,stopReason:s,startedAt:e.createdAt,completedAt:e.createdAt,summary:e.answerSummary??e.question,answer:e.answerText??e.answerSummary,answerKind:n==="conversation"?"conversational":void 0,steps:[],artifacts:d?[d]:[],evaluations:[],events:[],nextActions:[],repairAttempts:0}}function Vi(e){switch(e){case"certified_answer":return"Found a compatible certified block";case"semantic_answer":return"Found a compatible semantic metric";case"generated_answer":return"Identified the relevant tables and columns";case"research":return"Identified evidence for deeper analysis";case"app_build":return"Found governed assets for the app";case"sql_cell":return"Identified the query context";case"dql_block_draft":return"Identified reusable governed logic";case"clarify":return"Identified a missing business detail";default:return"Identified the best answer path"}}function Gi(e,n){if(n.some(r=>r.type==="repair.attempted"))return"Refining the query and trying again";if(n.some(r=>r.type==="escalated"))return"Expanding the evidence search";switch(e){case"certified_answer":case"semantic_answer":return"Running the governed query";case"generated_answer":return"Building and running a grounded query";case"research":return"Researching the strongest evidence";case"app_build":return"Assembling the app from governed assets";case"sql_cell":return"Building and checking the SQL";case"dql_block_draft":return"Drafting the governed logic";case"clarify":return"Preparing a focused clarification";default:return"Preparing the answer"}}function Xt(e){for(let n=e.length-1;n>=0;n-=1)if(e[n].route)return e[n].route}function cr(e,n,r=!1){return e<12?null:!n&&e<24&&!r?{title:"Still resolving the governed evidence",detail:"The bounded request is still selecting its answer path. DQL will stop at the normal deadline instead of silently switching to a longer workflow."}:n==="research"?{title:"Deep research is validating the analysis",detail:"This can use several AI and SQL steps. Reusable relationships and semantic metrics make future investigations faster; reviewed repeat answers can be saved as blocks and certified."}:{title:r?"Applying one bounded query repair":"Finishing the bounded query path",detail:"DQL is compiling or running the selected governed path. An ordinary lookup stops at its deadline instead of silently restarting as Research."}}function dr(e,n,r,i){return r==="certified"||e<20&&i===0||n!=="research"&&n!=="generated_answer"?null:{title:n==="research"?"Make future research faster":"Make this question faster next time",detail:"If this analysis is reusable, save it as a block, review it, then certify it. Add repeated joins to Domain Modeling and reusable measures to the semantic layer to reduce future AI work and token usage."}}function ur(e,n=!1){if(e.length===0&&n)return[{id:"background",label:"Continuing this request in the background",state:"active"}];const r=Xt(e);if(r==="conversation")return[];const i=e.some(u=>u.type==="route.decided"),s=e.some(u=>u.type==="executor.started"||u.type==="step.started"||u.type==="repair.attempted"||u.type==="escalated"),o=e.some(u=>u.type==="evaluation.recorded"),a=[{id:"search",label:"Resolving governed evidence and business meaning",state:i?"complete":"active"}];return i&&a.push({id:"match",label:Vi(r),state:s||o?"complete":"active"}),(s||o)&&a.push({id:"execute",label:Gi(r,e),state:o?"complete":"active"}),o&&a.push({id:"verify",label:"Checking the result against governed evidence",state:"active"}),a}function Wn({events:e,t:n,streamingAnswer:r,thinkingMode:i,backgroundRun:s}){var x;const[o,a]=p.useState(()=>Date.now());p.useEffect(()=>{const b=window.setInterval(()=>a(Date.now()),1e3);return()=>window.clearInterval(b)},[]);const u=(s==null?void 0:s.startedAt)??((x=e.find(b=>b.type==="run.started"))==null?void 0:x.at),d=u?Date.parse(u):o,m=Number.isFinite(d)?Math.max(0,Math.floor((o-d)/1e3)):0,f=cr(m,Xt(e),e.some(b=>b.type==="repair.attempted"));if(r)return t.jsx("div",{style:{alignSelf:"stretch",padding:"4px 2px 8px",fontSize:13.5,lineHeight:1.55,color:n.textPrimary,whiteSpace:"pre-wrap",animation:"dql-agent-fadein 0.22s ease-out"},children:r});if(Xt(e)==="conversation")return t.jsxs("div",{role:"status","aria-live":"polite",style:{alignSelf:"stretch",display:"flex",alignItems:"center",gap:9,padding:"5px 2px 9px",color:n.textSecondary,animation:"dql-agent-fadein 0.22s ease-out"},children:[t.jsx(Fn,{}),t.jsx("span",{style:{fontSize:13,lineHeight:1.4},children:"Replying…"})]});const c=ur(e,!!s),h=m>=12?f==null?void 0:f.title:i==="high"?"Thorough mode is cross-checking the result.":null;return t.jsxs("div",{role:"status","aria-live":"polite","aria-label":"Agent activity",style:{alignSelf:"stretch",display:"grid",gap:7,padding:"5px 2px 10px",animation:"dql-agent-fadein 0.22s ease-out"},children:[c.map(b=>t.jsxs("div",{className:"dql-agent-activity",style:{display:"flex",alignItems:"center",gap:9,minHeight:18,color:b.state==="active"?n.textPrimary:n.textMuted},children:[t.jsx("span",{"aria-hidden":"true",style:{width:16,height:16,display:"inline-flex",alignItems:"center",justifyContent:"center",flex:"0 0 auto",color:b.state==="active"?n.accent:n.textMuted},children:b.state==="active"?t.jsx(Fn,{}):t.jsx(Je,{size:13,strokeWidth:2.2})}),t.jsxs("span",{style:{fontSize:12.5,lineHeight:1.4,fontWeight:b.state==="active"?620:450},children:[b.label,b.state==="active"?"…":""]})]},b.id)),h?t.jsx("span",{style:{paddingLeft:25,fontSize:10.5,lineHeight:1.4,color:n.textMuted},children:h}):null]})}function Fn(){return t.jsx("span",{"aria-hidden":"true",style:{width:16,height:10,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:2},children:[0,1,2].map(e=>t.jsx("span",{className:"dql-agent-thinking-dot",style:{width:3,height:3,borderRadius:999,background:"var(--accent)",animationDelay:`${e*120}ms`}},e))})}function Pn({items:e,t:n,renderItem:r,cap:i=4}){const[s,o]=p.useState(!1),a=s?e:e.slice(0,i);return t.jsxs(t.Fragment,{children:[a.map((u,d)=>r(u,d)),e.length>i?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>o(u=>!u),style:{alignSelf:"flex-start",background:"none",border:"none",cursor:"pointer",color:n.accent,fontSize:11,padding:"2px 0",display:"inline-flex",alignItems:"center",gap:4},children:[s?t.jsx(Jn,{size:11}):t.jsx(At,{size:11}),s?"Show less":`Show all (${e.length})`]}):null]})}function Ki({run:e,t:n,themeMode:r,appContext:i,onOpenApp:s,onInsertSql:o,onInsertDql:a,onOpenBlock:u,onOpenResearch:d,onSelectClarification:m,onNextAction:f}){var _;const{dispatch:l}=qt();if(e.route==="conversation"){const v=e.answerKind==="general_knowledge";return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,animation:"dql-agent-fadein 0.3s ease-out"},children:[t.jsxs("div",{style:ws(n),children:[v?t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:10.5,color:n.textMuted,marginBottom:6,fontWeight:650},children:[t.jsx(vt,{size:11})," General knowledge — not from your data"]}):null,t.jsx("div",{style:{fontSize:13.5,lineHeight:1.55,color:n.textPrimary},children:e.answer?t.jsx(mt,{text:Ve(e.answer),t:n}):e.summary})]}),e.nextActions.length>0?t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:e.nextActions.map(S=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>f(S),style:kt(n),children:S.label},S.id))}):null]})}const c=e.steps??[],h=c.length>1,x=((_=e.plan)==null?void 0:_.source)==="llm",b=fn(e),g=un(e),R=it(e),$=e.route==="certified_answer"||e.route==="generated_answer",N=e.nextActions.some(v=>v.route==="research"),V=$&&R&&!N,q=$e(e),Q=R&&!(q!=null&&q.sourcePath)&&!!((q==null?void 0:q.source)??Be(e)),F=Date.parse(e.startedAt),I=Date.parse(e.completedAt),H=Number.isFinite(F)&&Number.isFinite(I)?Math.max(0,Math.round((I-F)/1e3)):0,O=dr(H,e.route,e.trustState,e.repairAttempts);return t.jsxs("div",{style:ks(n),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(os,{run:e}),t.jsx("div",{style:{minWidth:0,flex:1},children:t.jsx("div",{style:{fontSize:12.5,fontWeight:850,color:n.textPrimary},children:rs(e)})}),t.jsx(ls,{run:e,t:n})]}),g?t.jsxs("div",{style:{display:"flex",gap:6,alignItems:"flex-start",fontSize:11,color:n.textMuted,lineHeight:1.4},children:[e.trustState==="certified"?t.jsx(he,{size:12,color:n.success,style:{flex:"0 0 auto",marginTop:1}}):e.trustState==="governed"||e.trustState==="grounded"?t.jsx(he,{size:12,color:n.accent,style:{flex:"0 0 auto",marginTop:1}}):t.jsx(Ge,{size:12,color:n.warning,style:{flex:"0 0 auto",marginTop:1}}),t.jsx("span",{children:g})]}):null,x||h||e.repairAttempts>0?t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[x?t.jsx(Vt,{t:n,icon:t.jsx(tt,{size:11}),label:"AI plan",tone:"accent"}):null,h?t.jsx(Vt,{t:n,icon:t.jsx(Ut,{size:11}),label:`${c.length} steps`,tone:"muted"}):null,e.repairAttempts>0?t.jsx(Vt,{t:n,icon:t.jsx(Rt,{size:11}),label:`${e.repairAttempts} repair${e.repairAttempts>1?"s":""}`,tone:"warning"}):null]}):null,e.summary&&!(e.answer&&us(ze(e.summary),Ve(e.answer)))?t.jsx("div",{style:{fontSize:12.5,lineHeight:1.45,color:n.textSecondary},children:ze(e.summary)}):null,e.answer?t.jsx("div",{style:Cs(n),children:t.jsx(mt,{text:Ve(e.answer),t:n})}):null,t.jsx(gr,{run:e,t:n,onSelect:m}),b.length>0?t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[t.jsx("span",{style:{fontSize:11,color:n.textMuted},children:"Evidence:"}),b.map(v=>t.jsxs("span",{style:Cr(n,v.certified),children:[v.certified?t.jsx(he,{size:11}):t.jsx(et,{size:11}),t.jsx("span",{children:v.label})]},v.label))]}):null,t.jsx(kr,{run:e,t:n}),e.artifacts.length>0?t.jsx("div",{style:{display:"grid",gap:8,gridTemplateColumns:"minmax(0, 1fr)",minWidth:0},children:e.artifacts.map(v=>t.jsx(br,{artifact:v,t:n,themeMode:r,onInsertSql:o,onInsertDql:a,sourceRunId:e.id,sourceQuestion:e.question,onOpenBlock:u,onOpenResearch:d,onOpenApp:s,onNextAction:f},v.id))}):null,h?t.jsx(jr,{steps:c,t:n}):t.jsx(vr,{evaluations:e.evaluations,t:n}),e.events.length>0?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>l({type:"OPEN_AGENT_LOG",run:e}),style:{display:"inline-flex",alignItems:"center",gap:5,alignSelf:"flex-start",background:"transparent",border:"none",cursor:"pointer",padding:0,color:n.textMuted,fontSize:11.5,fontFamily:n.font},title:"See what the agent did and where the time went",children:[t.jsx(tt,{size:12})," View steps · where the time went"]}):null,O?t.jsxs("div",{style:{display:"grid",gap:3,padding:"8px 9px",border:`1px solid ${n.accent}33`,borderRadius:7,background:`${n.accent}0a`},children:[t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,color:n.textSecondary,fontSize:11,fontWeight:800},children:[t.jsx(vt,{size:11,color:n.accent})," ",O.title]}),t.jsx("span",{style:{fontSize:10.5,color:n.textMuted,lineHeight:1.45},children:O.detail})]}):null,R||V||e.nextActions.length>0?t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[R?t.jsx(dn,{run:e,t:n,appContext:i,onOpenApp:s}):null,Q?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>f({id:"save-dql-block",label:"Save as block",route:"dql_block_draft"}),style:X(n),children:[t.jsx(on,{size:11})," Save as block"]}):null,V?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>f({id:"research-deeper",label:"Research this deeper",route:"research"}),style:X(n),title:"Run a slower, multi-step investigation on this question",children:[t.jsx(et,{size:11}),"Research this deeper"]}):null,e.nextActions.filter(v=>v.id!=="pin-to-app"&&v.id!=="research-deeper"&&v.id!=="confirm-app-build"&&v.id!=="request-certification").map(v=>t.jsx("button",{type:"button",className:"dql-hover",onClick:()=>f(v),style:X(n),children:v.label},v.id))]}):null]})}function pr(e){const n=[];return e.analytical&&n.push({id:"how",label:"How it answered"}),(e.hasDql||e.analytical&&e.blocked)&&n.push({id:"dql",label:"DQL"}),(e.hasSql||e.analytical&&e.blocked)&&n.push({id:"sql",label:"SQL"}),e.hasLineage&&n.push({id:"lineage",label:"Lineage"}),n.push({id:"trust",label:"Trust & steps"}),n}const Ui=`
|
|
65
|
+
@keyframes dql-agent-run-spin { to { transform: rotate(360deg); } }
|
|
66
|
+
@keyframes dql-agent-fadein { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
|
|
67
|
+
@keyframes dql-agent-thinking-dot { 0%, 65%, 100% { opacity: .28; transform: translateY(0); } 32% { opacity: 1; transform: translateY(-2px); } }
|
|
68
|
+
@keyframes dql-agent-activity-in { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
|
|
69
|
+
.dql-agent-thinking-dot { animation: dql-agent-thinking-dot 1.05s ease-in-out infinite; }
|
|
70
|
+
.dql-agent-activity { animation: dql-agent-activity-in .22s ease-out; }
|
|
71
|
+
.dql-hover { transition: filter .15s ease, transform .12s ease, box-shadow .15s ease, background .15s ease, color .15s ease, border-color .15s ease; }
|
|
72
|
+
.dql-hover:hover { filter: brightness(1.03); }
|
|
73
|
+
.dql-hover:active { transform: translateY(0.5px); }
|
|
74
|
+
.dql-lift:hover { transform: translateY(-1px); }
|
|
75
|
+
.dql-ask-ghost:hover { background: var(--bg-0); color: var(--text-primary) !important; }
|
|
76
|
+
.dql-ask-chip:hover { border-color: var(--accent) !important; box-shadow: 0 1px 6px rgba(107,93,211,0.12); }
|
|
77
|
+
details > summary::-webkit-details-marker { display: none; }
|
|
78
|
+
@media (prefers-reduced-motion: reduce) { .dql-agent-thinking-dot, .dql-agent-activity { animation: none !important; } }
|
|
79
|
+
`;function Yi(e){return{alignSelf:"flex-end",maxWidth:"82%",background:"var(--bg-0)",color:e.textPrimary,borderRadius:"16px 16px 4px 16px",padding:"10px 14px",fontSize:13.5,lineHeight:1.5,whiteSpace:"pre-wrap",animation:"dql-agent-fadein 0.25s ease-out"}}function We(e){return zt(e,{variant:"ghost",size:"sm"})}function Ht(e,n){return e.kind==="app_proposal"||e.kind==="dql_block_draft"||e.kind==="research_run"||!!Tt(n)}function _t(e,n){var a,u;const r=[],i=Ne(n),s=e.kind==="answer"?(a=i==null?void 0:i.rows)!=null&&a.length?"Table":"Answer":e.kind==="sql_cell"?"SQL":e.kind==="dql_block_draft"?"DQL block":e.kind==="research_run"?"Research":"Result";r.push(s);const o=(i==null?void 0:i.rowCount)??((u=i==null?void 0:i.rows)==null?void 0:u.length);return typeof o=="number"&&r.push(`${o} row${o===1?"":"s"}`),typeof(i==null?void 0:i.executionTime)=="number"&&r.push(i.executionTime>=1e3?`${(i.executionTime/1e3).toFixed(1)}s`:`${i.executionTime.toFixed(i.executionTime<10?1:0)}ms`),r.push(e.trustState==="certified"?"certified block":e.trustState==="governed"||e.trustState==="grounded"?"governed":"AI-generated"),r.join(" · ")}function jt(e,n){const i=/^(?:certified|governed semantic|review-required|exploratory dbt-grounded) answer$/i.test(n.title.trim())?e.question:n.title,s=ze(i).replace(/[?.!]+$/,"").trim();if(!s)return"Answer result";const o=s.charAt(0).toUpperCase()+s.slice(1);return o.length>88?`${o.slice(0,85).trimEnd()}…`:o}function W(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function fr(e){const n=[],r=new Set,i=(s,o)=>{const a=W(s);if(!a)return;const u=[a.name,a.label,a.relation,a.objectName].find(l=>typeof l=="string"&&l.trim().length>0);if(!u)return;const d=typeof a.kind=="string"?a.kind:o,m=`${d??""}:${u}`;if(r.has(m))return;r.add(m);const f=[a.description,a.provenance,a.sourceTier,a.source].find(l=>typeof l=="string"&&l.trim().length>0);n.push({name:u,kind:d,detail:f})};for(const s of e.artifacts){const o=le(s),a=W(o.evidence);for(const m of["lineage","sourceTables","semanticObjects","selectedAssets"]){const f=a==null?void 0:a[m];Array.isArray(f)&&f.forEach(l=>i(l,m==="sourceTables"?"source":void 0))}const u=W(o.analysisPlan)??W(a==null?void 0:a.analysisPlan),d=u==null?void 0:u.candidateTables;Array.isArray(d)&&d.forEach(m=>i(m,"relation"))}return n.slice(0,24)}function cn(e,n){var i;const r=le(n);return It(r)?"how":(i=$e(e)??st(r))!=null&&i.source?"dql":Be(e)??(typeof r.sql=="string"?r.sql:void 0)?"sql":fr(e).length>0?"lineage":"trust"}function Ji({run:e,artifact:n,selected:r,t:i,themeMode:s,onInspect:o}){const a=le(n),u=Ne(a);if(!u)return null;const d=Sr(a,u),m=cn(e,n),f=$e(e)??st(a),l=n.trustState==="certified"?mr(n,a):void 0;return t.jsxs("section",{"data-followup":"table","aria-label":`${jt(e,n)} result`,style:{border:`1px solid ${r?"var(--accent)":"var(--border-default)"}`,borderRadius:12,background:"var(--bg-2)",overflow:"hidden",boxShadow:r?"0 2px 10px rgba(107,93,211,0.12)":"0 1px 3px rgba(26,26,26,0.04)"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"11px 13px",borderBottom:"1px solid var(--border-subtle)"},children:[t.jsx("span",{style:{width:30,height:30,borderRadius:8,background:n.trustState==="certified"?"var(--status-success-bg)":"var(--accent-dim)",color:n.trustState==="certified"?"var(--status-success)":"var(--accent)",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx(Ke,{kind:n.kind})}),t.jsxs("div",{style:{minWidth:0,flex:1},children:[t.jsx("div",{style:{fontSize:12.5,fontWeight:700,color:i.textPrimary,lineHeight:1.35},children:jt(e,n)}),t.jsx("div",{style:{fontSize:11,color:i.textMuted,marginTop:2},children:_t(n,a)})]}),t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>o(m),style:We(i),children:[t.jsx(tt,{size:12})," Inspect"]})]}),f?t.jsx(yr,{artifact:f,certifiedBlockName:l,initialResult:u,initialChartConfig:d,payload:a,executionTarget:e.executionTarget,t:i,themeMode:s,embedded:!0}):t.jsx(rn,{result:u,themeMode:s,t:i,chartConfig:d,embedded:!0,tabLabels:{table:"Results",chart:"Visualization"}})]})}function Zt(e){const{run:n,t:r,themeMode:i,threadId:s,appContext:o,selectedArtifactId:a,onOpenArtifact:u,onOpenApp:d,onInsertSql:m,onInsertDql:f,onReplaceDql:l,insertDqlActionLabel:c,replaceDqlActionLabel:h,onOpenBlock:x,onOpenResearch:b,onSelectClarification:g,onNextAction:R}=e,{dispatch:$}=qt(),[N,V]=p.useState(!1),[q,Q]=p.useState(null);p.useEffect(()=>Q(null),[n.id]);const F=u??(()=>$({type:"OPEN_AGENT_LOG",run:n}));if(q)return t.jsx(Zt,{...e,run:q});if(n.route==="conversation"){const A=n.answerKind==="general_knowledge";return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,animation:"dql-agent-fadein 0.3s ease-out",maxWidth:"100%"},children:[A?t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:10.5,color:r.textMuted,fontWeight:650},children:[t.jsx(vt,{size:11})," General knowledge — not from your data"]}):null,t.jsx("div",{"data-followup":"answer",style:{fontSize:14.5,lineHeight:1.65,color:r.textPrimary},children:n.answer?t.jsx(mt,{text:Ve(n.answer),t:r}):n.summary}),n.nextActions.length>0?t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:n.nextActions.map(U=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>R(U),style:kt(r),children:U.label},U.id))}):null]})}const I=n.trustState==="certified",H=n.status==="blocked",O=n.status==="needs_clarification",_=H||O?void 0:n.answer,v=H?"Couldn’t run this query":O?"Needs clarification":I?"Certified answer":"AI-generated answer",S=H?qr(n):void 0,G=n.evaluations.filter(A=>A.severity==="info").length,M=fn(n),Y=n.artifacts.filter(A=>{const U=le(A);return!Ht(A,U)&&!!Ne(U)}),Z=new Set(Y.map(A=>A.id)),se=n.artifacts.filter(A=>!Ht(A,le(A))&&!Z.has(A.id)),P=n.artifacts.filter(A=>Ht(A,le(A))),D=Y[0]??se[0]??n.artifacts[0],ae=it(n),J=n.route==="certified_answer"||n.route==="semantic_answer"||n.route==="generated_answer",K=n.nextActions.some(A=>A.route==="research"),de=J&&ae&&!K,k=$e(n),L=ae&&!(k!=null&&k.sourcePath)&&!!((k==null?void 0:k.source)??Be(n)),B=c&&f||h&&l?gn(n):void 0,C=()=>{var U;const A=_?Ve(_):S??n.summary;A&&((U=navigator.clipboard)==null||U.writeText(A).catch(()=>{}),V(!0),window.setTimeout(()=>V(!1),1400))};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10,maxWidth:"100%",animation:"dql-agent-fadein 0.3s ease-out"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,flexWrap:"wrap"},children:[H?t.jsx(Ge,{size:14,color:r.error}):I?t.jsx(he,{size:14,color:r.success}):t.jsx(De,{size:14,color:r.accent}),t.jsx("span",{style:{fontSize:12,fontWeight:650,color:H?r.error:r.textSecondary},children:v}),I&&M[0]?t.jsxs("span",{style:{fontSize:11,color:r.textMuted},children:["from ",t.jsx("span",{style:{color:r.accent,fontWeight:600},children:M[0].label})]}):!H&&D&&G>0?t.jsxs("button",{type:"button",onClick:()=>F(D.id,"trust"),style:{fontSize:11,color:r.textMuted,background:"none",border:"none",cursor:"pointer",padding:0,fontFamily:r.font,display:"inline-flex",alignItems:"center",gap:4},children:[t.jsx(Je,{size:11,color:r.success})," ",G," check",G===1?"":"s"," passed"]}):null]}),_?t.jsx("div",{"data-followup":"answer",style:{fontSize:14.5,lineHeight:1.65,color:r.textPrimary},children:t.jsx(mt,{text:Ve(_),t:r})}):S?t.jsx(qs,{run:n,detail:S,threadId:s,onRepaired:Q,t:r}):n.summary?t.jsx("div",{"data-followup":"answer",style:{fontSize:14,lineHeight:1.6,color:r.textSecondary},children:ze(n.summary)}):null,t.jsx(gr,{run:n,t:r,onSelect:g}),Y.map(A=>t.jsx(Ji,{run:n,artifact:A,selected:A.id===a,t:r,themeMode:i,onInspect:U=>F(A.id,U)},A.id)),se.map(A=>{const U=le(A),ee=A.id===a;return t.jsxs("button",{type:"button",className:"dql-ask-chip",onClick:()=>F(A.id,cn(n,A)),style:{display:"flex",alignItems:"center",gap:10,width:"fit-content",maxWidth:"100%",padding:"9px 12px",borderRadius:10,border:`1px solid ${ee?"var(--accent)":"var(--border-default)"}`,background:"var(--bg-2)",boxShadow:ee?"0 1px 6px rgba(107,93,211,0.12)":"none",cursor:"pointer",textAlign:"left",fontFamily:r.font},children:[t.jsx("span",{style:{width:30,height:30,borderRadius:7,background:A.trustState==="certified"?"var(--status-success-bg)":"var(--accent-dim)",color:A.trustState==="certified"?"var(--status-success)":"var(--accent)",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx(Ke,{kind:A.kind})}),t.jsxs("span",{style:{display:"flex",flexDirection:"column",gap:1,minWidth:0},children:[t.jsx("span",{style:{fontSize:12.5,fontWeight:650,color:r.textPrimary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:ze(A.title)}),t.jsx("span",{style:{fontSize:11,color:r.textMuted},children:_t(A,U)})]}),t.jsx(Gn,{size:14,color:r.textMuted,style:{flexShrink:0,marginLeft:6}})]},A.id)}),P.length>0?t.jsx("div",{style:{display:"grid",gap:8,gridTemplateColumns:"minmax(0, 1fr)",minWidth:0},children:P.map(A=>t.jsx(br,{artifact:A,t:r,themeMode:i,onInsertSql:m,onInsertDql:f,insertDqlActionLabel:c,sourceRunId:n.id,sourceQuestion:n.question,onOpenBlock:x,onOpenResearch:b,onOpenApp:d,onNextAction:R},A.id))}):null,_||S||B||ae||L||de||D?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:2,flexWrap:"wrap",marginTop:-2},children:[B&&f?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>f(B),style:We(r),children:[t.jsx(Ye,{size:12})," ",c]}):null,B&&l&&h?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>l(B),style:We(r),children:[t.jsx(Kr,{size:12})," ",h]}):null,_||S?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:C,style:We(r),children:[N?t.jsx(Je,{size:12}):t.jsx(Xn,{size:12})," ",N?"Copied":"Copy"]}):null,ae?t.jsx(dn,{run:n,t:r,appContext:o,onOpenApp:d}):null,L?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>R({id:"save-dql-block",label:"Save as block",route:"dql_block_draft"}),style:We(r),children:[t.jsx(rt,{size:12})," Save as block"]}):null,de?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>R({id:"research-deeper",label:"Research this deeper",route:"research"}),style:We(r),children:[t.jsx(et,{size:12})," Research deeper"]}):null,D?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>F(D.id,It(le(D))?"how":"trust"),style:We(r),children:[t.jsx(tt,{size:12})," How it was answered"]}):null]}):null]})}function gr({run:e,t:n,onSelect:r}){var i;return e.status!=="needs_clarification"||!((i=e.clarificationOptions)!=null&&i.length)||!r?null:t.jsx("div",{"aria-label":"Choose a governed meaning",style:{display:"grid",gap:7,maxWidth:620},children:e.clarificationOptions.map(s=>t.jsxs("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>r(s),title:`Use governed evidence ${s.id}`,style:{display:"grid",gap:3,width:"100%",padding:"10px 12px",borderRadius:10,border:"1px solid var(--border-default)",background:"var(--bg-2)",color:n.textPrimary,cursor:"pointer",textAlign:"left",fontFamily:n.font},children:[t.jsx("span",{style:{fontSize:12.5,fontWeight:700},children:s.label}),s.description?t.jsx("span",{style:{fontSize:11,lineHeight:1.4,color:n.textMuted},children:s.description}):null]},s.id))})}function xr(e){const n=e.executionError;if(typeof n=="string"&&n.trim())return{stage:"execution",message:n};const r=W(n);if(r)return{stage:"execution",...r};const i=typeof e.refusalCode=="string"?e.refusalCode:void 0;if(i){const s=W(e.refusalDetails),o=typeof(s==null?void 0:s.message)=="string"&&s.message.trim()?s.message:typeof e.answer=="string"&&e.answer.trim()?e.answer:"No answer was accepted for this question.";return{stage:"answer",code:i,message:o}}}function It(e){return!!(W(e.resolvedAnalyticalPlan)||W(e.analyticalExecutionGraph)||W(e.analyticalExecutionReceipt)||W(e.analyticalFailure)||W(e.semanticExecutionTrace)||W(e.diagnosticReceipt)||xr(e))}function hr(e){if(!It(e))return;const n=W(e.diagnosticReceipt),r=W(e.resolvedAnalyticalPlan)??W(n==null?void 0:n.resolvedAnalyticalPlan);return{plan:r,frame:W(r==null?void 0:r.analyticalFrame),graph:W(e.analyticalExecutionGraph),receipt:W(e.analyticalExecutionReceipt),facts:W(e.analyticalFacts),narrative:W(e.analyticalNarrative),freshness:W(e.analyticalFreshnessObservation),failure:W(e.analyticalFailure)??W(n==null?void 0:n.failure)??xr(e),semantic:W(e.semanticExecutionTrace),diagnostic:n}}function Xi(){return["Plan","DQL","Compiled SQL","Lineage","Trust & evidence","Actual steps","Failure & repair"]}function Zi(e){return[e.includes("retry_same_plan")?"Retry same plan":void 0,e.includes("refresh_snapshot")?"Refresh snapshot and prepare retry":void 0,e.includes("request_access")||e.includes("change_authorized_connection")?"Change connection or request access":void 0,e.includes("edit_dql")?"Open DQL to repair":void 0,e.includes("open_sql_notebook")?"Open SQL in Notebook":void 0,e.includes("reapply_semantic_runtime")?"Reapply semantic runtime settings":void 0].filter(n=>!!n)}function es({run:e,contract:n,dqlArtifact:r,sql:i,lineage:s,t:o,onInsertSql:a,onInsertDql:u,onSaveBlock:d}){var ve,_e,we;const{dispatch:m}=qt(),f=n.plan,l=n.frame,c=n.graph,h=n.receipt,x=n.semantic,b=W(x==null?void 0:x.failure),g=n.failure??b,R=W(x==null?void 0:x.authoringRequest),$=W(x==null?void 0:x.runtimeRequest),N=qe(x==null?void 0:x.bindings),V=qe(x==null?void 0:x.steps),q=W(x==null?void 0:x.targetBinding),Q=W(q==null?void 0:q.semanticSnapshot),F=W(q==null?void 0:q.executionTarget),I=W(F==null?void 0:F.redactedContext),H=W(q==null?void 0:q.compileTarget),O=W(x==null?void 0:x.executionReceipt),_=qe(b==null?void 0:b.candidates),v=W(l==null?void 0:l.timeContext),S=W(l==null?void 0:l.comparison),G=W(l==null?void 0:l.ranking),M=qe(l==null?void 0:l.dimensions),Y=qe(l==null?void 0:l.memberBindings),Z=qe(v==null?void 0:v.periods),se=qe(l==null?void 0:l.requestedOutputs),P=qe(c==null?void 0:c.nodes),D=Array.from(new Set([...be(g==null?void 0:g.safeActions),...be(b==null?void 0:b.safeActions)])),ae=qe(g==null?void 0:g.failedBindings),J=W(b==null?void 0:b.sqlExcerpt),K=e.artifacts.map(j=>Ne(le(j))).find(Boolean),de=(r==null?void 0:r.name)??e.question,[k,L]=p.useState(null),B=(j,ce)=>{const je=ce.derivation.trustTransition;return`${j} as immutable derivation ${ce.derivation.derivationId}. Trust: ${je.previous} → ${je.next}${je.requiresReview?" (review required)":""}.`},C=async()=>{if(!(!(r!=null&&r.source)||!u))try{const j=await ne.deriveAnalyticalRepair(e.id,{version:1,action:"edit_dql",dqlSource:r.source});u({sql:i,dqlArtifact:r,result:K,title:de,sourceRunId:e.id,question:e.question}),L(B("Opened DQL in Notebook",j))}catch(j){L(j instanceof Error?j.message:String(j))}},A=async()=>{if(!(!i||!a))try{const j=await ne.deriveAnalyticalRepair(e.id,{version:1,action:"open_sql_notebook",sqlText:i});a(i,`${de} repair`,{question:e.question,sourceRunId:e.id}),L(B("Opened SQL in Notebook",j))}catch(j){L(j instanceof Error?j.message:String(j))}},U=async j=>{try{const ce=await ne.deriveAnalyticalRepair(e.id,{version:1,action:j});L(B(j==="retry_same_plan"?"Prepared the same bounded plan for retry":"Refreshed the governed snapshot and prepared the same plan for retry",ce))}catch(ce){L(ce instanceof Error?ce.message:String(ce))}},ee=async()=>{try{const j=await ne.deriveAnalyticalRepair(e.id,{version:1,action:"request_access"});L(B("Recorded the access/connection repair and opened Database settings",j)),m({type:"SET_SETTINGS_TAB",tab:"database"}),m({type:"SET_MAIN_VIEW",view:"settings"})}catch(j){L(j instanceof Error?j.message:String(j))}},He=()=>{m({type:"SET_SETTINGS_TAB",tab:"project"}),m({type:"SET_MAIN_VIEW",view:"settings"}),L("Opened Project & dbt settings. Test and apply the intended dbt Cloud Semantic Layer environment to refresh its verified metric inventory.")};return t.jsxs("div",{style:{display:"grid",gap:9},"aria-label":"How it answered",children:[t.jsxs("div",{role:"status",style:{display:"flex",gap:8,alignItems:"flex-start",padding:"10px 12px",borderRadius:8,border:`1px solid ${g?"var(--status-error-border)":"var(--status-success-border)"}`,background:g?"var(--status-error-bg)":"var(--status-success-bg)"},children:[g?t.jsx(Ge,{size:13,color:"var(--status-error)",style:{flexShrink:0,marginTop:2}}):t.jsx(he,{size:13,color:"var(--status-success)",style:{flexShrink:0,marginTop:2}}),t.jsxs("div",{style:{fontSize:12,color:o.textSecondary,lineHeight:1.5,minWidth:0},children:[t.jsx("div",{style:{fontWeight:700,color:g?"var(--status-error)":"var(--status-success)"},children:g?"Execution failed":"Answered successfully"}),g?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{marginTop:3,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:o.fontMono,fontSize:11},children:typeof g.message=="string"&&g.message.trim()?g.message:"The engine did not report a message. Open the DQL and SQL tabs to inspect what ran."}),t.jsx("div",{style:{marginTop:4,fontSize:10.5,color:o.textMuted},children:[g.code,g.phase?`during ${g.phase}`:""].filter(Boolean).map(z).join(" · ")})]}):t.jsx("div",{style:{marginTop:2},children:typeof(h==null?void 0:h.rowCount)=="number"?`Returned ${h.rowCount} row${h.rowCount===1?"":"s"}.`:"The query ran and returned a result."})]})]}),t.jsx(ht,{index:1,label:"Plan",t:o,open:!g,children:t.jsx(Ot,{rows:[["Question type",z((l==null?void 0:l.questionType)??(f==null?void 0:f.questionType))],["Selected route",z((c==null?void 0:c.route)??(f==null?void 0:f.recommendedRoute))],["Metric",be(l==null?void 0:l.metricConceptIds).join(", ")],["Entity grain",be(l==null?void 0:l.entityGrainIds).join(", ")],["Dimensions",M.map(j=>`${z(j.dimensionId)} (${z(j.role)})`).join(", ")],["Member filters",Y.map(j=>`${z(j.dimensionId)}: ${Array.isArray(j.canonicalValues)?j.canonicalValues.length:0} bound value(s)`).join(", ")],["Time policy",[v==null?void 0:v.timeRole,v==null?void 0:v.grain,v==null?void 0:v.timezone,v==null?void 0:v.completenessPolicy].map(z).filter(Boolean).join(" · ")],["Periods",Z.map(j=>`${z(j.id)}: ${z(j.start)} → ${z(j.end)}`).join(`
|
|
80
|
+
`)],["Comparison",S?`${z(S.basePeriodId)} vs ${be(S.comparisonPeriodIds).join(", ")} · ${z(S.alignment)}`:l?"Not requested":"Not available — analytical planning did not complete"],["Ranking",G?`${z(G.direction)} · top ${z(G.limit)} · ${z(G.tiePolicy)}`:l?"Not requested":"Not available — analytical planning did not complete"],["Outputs",se.map(j=>`${z(j.id)} (${z(j.kind)})`).join(", ")],["Semantic metrics",be(R==null?void 0:R.metrics).join(", ")],["Semantic dimensions",be(R==null?void 0:R.dimensions).join(", ")]],t:o})}),t.jsx(ht,{index:2,label:"Trust & evidence",t:o,children:t.jsx(Ot,{rows:[["Trust state",e.trustState],["Snapshot",z((f==null?void 0:f.snapshotId)??(c==null?void 0:c.snapshotId))],["Plan fingerprint",z((f==null?void 0:f.fingerprint)??(c==null?void 0:c.planFingerprint))],["Graph fingerprint",z(c==null?void 0:c.fingerprint)],["Receipt",z(h==null?void 0:h.receiptId)],["Result fingerprint",z(h==null?void 0:h.resultFingerprint)],["Freshness observed through",z((ve=n.freshness)==null?void 0:ve.observedThrough)],["Fact set",z((_e=n.facts)==null?void 0:_e.fingerprint)],["Semantic adapter",z(x==null?void 0:x.adapter)],["Semantic compile status",z(x==null?void 0:x.status)],["Target proof",z((we=W(q==null?void 0:q.proof))==null?void 0:we.status)],["Target binding",z(q==null?void 0:q.bindingFingerprint)],["Compile target",z(H==null?void 0:H.kind)],["Local semantic snapshot",z((Q==null?void 0:Q.semanticCatalogFingerprint)??(Q==null?void 0:Q.sourceFingerprint))],["Runtime metric inventory proof",z(H==null?void 0:H.semanticCatalogFingerprint)],["Execution target",[F==null?void 0:F.driver,I==null?void 0:I.account,I==null?void 0:I.database,I==null?void 0:I.schema,I==null?void 0:I.role,I==null?void 0:I.warehouse].map(z).filter(Boolean).join(" · ")],["Semantic receipt",z(O==null?void 0:O.receiptId)],["Warehouse query ID",z(O==null?void 0:O.queryId)],["Executed SQL proof",z(O==null?void 0:O.executedSqlFingerprint)],["Runtime metrics",be($==null?void 0:$.metrics).join(", ")],["Runtime dimensions",be($==null?void 0:$.dimensions).join(", ")],["Member bindings",N.map(j=>`${z(j.authoringReference)} → ${z(j.runtimeReference)}${be(j.entityPath).length?` via ${be(j.entityPath).join(" → ")}`:""} (${z(j.status)})`).join(`
|
|
81
|
+
`)]],t:o,mono:!0})}),t.jsx(ht,{index:3,label:"Actual steps",t:o,children:t.jsxs("div",{style:{display:"grid",gap:6},children:[V.map((j,ce)=>t.jsxs("div",{style:{fontSize:11.5,color:o.textSecondary},children:[t.jsxs("strong",{style:{color:z(j.status)==="failed"?"var(--status-error)":o.textPrimary},children:[ce+1,". ",z(j.label)]})," ","— ",z(j.status)," · ",z(j.detail)]},`semantic:${z(j.id)||ce}`)),e.steps.map(j=>t.jsxs("div",{style:{fontSize:11.5,color:o.textSecondary},children:[t.jsxs("strong",{style:{color:o.textPrimary},children:[j.index+1,". ",j.goal]})," — ",j.status,", ",j.attempts," attempt",j.attempts===1?"":"s"]},j.id)),P.map((j,ce)=>t.jsxs("div",{style:{fontSize:11.5,color:o.textSecondary},children:[t.jsxs("span",{style:{color:o.accent,fontFamily:o.fontMono},children:[ce+1,". ",z(j.kind)]})," ","· ",z(j.id)]},z(j.id)||ce)),V.length===0&&e.steps.length===0&&P.length===0?t.jsx(St,{t:o,children:"No executable steps were recorded."}):null]})}),t.jsx(ht,{index:4,label:"Failure & repair",t:o,open:!!g,children:g?t.jsxs("div",{style:{display:"grid",gap:9},children:[t.jsx(Ot,{rows:[["Failure ID",z(g.failureId)],["Recoverability",z(g.recoverability)],["Failed bindings",ae.map(j=>`${z(j.qualifiedId??j.role)} (${z(j.reasonCode)})`).join(", ")],["Safe actions",D.join(", ")],["DQL fingerprint",z(g.dqlFingerprint)],["SQL fingerprint",z(g.sqlFingerprint)],["Semantic failure code",z(b==null?void 0:b.code)],["Failing identifier",z(b==null?void 0:b.identifier)],["Compiled SQL proof",z(b==null?void 0:b.compiledSqlFingerprint)],["Path candidates",_.map(j=>`${z(j.label)}
|
|
82
|
+
${z(j.runtimeReference)}`).join(`
|
|
83
|
+
`)]],t:o,mono:!0}),z(J==null?void 0:J.text)?t.jsxs("div",{children:[t.jsxs("div",{style:{fontSize:10.5,fontWeight:700,color:o.textSecondary,marginBottom:5},children:["Failing SQL context · lines ",z(J==null?void 0:J.startLine),"–",z(J==null?void 0:J.endLine)]}),t.jsx("pre",{style:nt(o),children:z(J==null?void 0:J.text)})]}):null,t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6},"aria-label":"Safe repair actions",children:[D.includes("edit_dql")&&u?t.jsxs("button",{type:"button",onClick:()=>void C(),style:X(o),children:[t.jsx(Rt,{size:12})," Open DQL to repair"]}):null,D.includes("open_sql_notebook")&&a?t.jsxs("button",{type:"button",onClick:()=>void A(),style:X(o),children:[t.jsx(sn,{size:12})," Open SQL in Notebook"]}):null,D.includes("retry_same_plan")?t.jsxs("button",{type:"button",onClick:()=>void U("retry_same_plan"),style:X(o),children:[t.jsx(Et,{size:12})," Retry same plan"]}):null,D.includes("refresh_snapshot")?t.jsxs("button",{type:"button",onClick:()=>void U("refresh_snapshot"),style:X(o),children:[t.jsx(Et,{size:12})," Refresh snapshot and prepare retry"]}):null,D.includes("request_access")||D.includes("change_authorized_connection")?t.jsxs("button",{type:"button",onClick:()=>void ee(),style:X(o),children:[t.jsx(Ge,{size:12})," Change connection or request access"]}):null,D.includes("reapply_semantic_runtime")?t.jsxs("button",{type:"button",onClick:He,style:X(o),children:[t.jsx(Et,{size:12})," Reapply semantic runtime settings"]}):null]})]}):t.jsxs("div",{style:{display:"grid",gap:8},children:[t.jsx(St,{t:o,children:"No failure was recorded for this run."}),r!=null&&r.sourcePath?null:r!=null&&r.source?t.jsxs("button",{type:"button",onClick:d,style:X(o),children:[t.jsx(on,{size:12})," Save as draft block"]}):null]})}),k?t.jsx("div",{role:"status",style:{fontSize:10.5,color:k.toLowerCase().includes("created")?"var(--status-success)":"var(--status-error)"},children:k}):null]})}function ht({index:e,label:n,t:r,open:i=!1,children:s}){return t.jsxs("details",{open:i,style:{border:"1px solid var(--border-subtle)",borderRadius:8,background:"var(--bg-1)",overflow:"hidden"},children:[t.jsxs("summary",{style:{cursor:"pointer",listStyle:"none",padding:"8px 10px",display:"flex",gap:7,alignItems:"center",fontSize:11.5,fontWeight:700,color:r.textPrimary},children:[t.jsx("span",{style:{width:18,height:18,borderRadius:999,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"var(--accent-dim)",color:"var(--accent)",fontSize:10},children:e}),n]}),t.jsx("div",{style:{display:"grid",gap:8,padding:"0 10px 10px"},children:s})]})}function Ot({rows:e,t:n,mono:r=!1}){return t.jsx("div",{style:{display:"grid",gap:6},children:e.filter(([,i])=>i).map(([i,s])=>t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"112px minmax(0, 1fr)",gap:8,alignItems:"start"},children:[t.jsx("span",{style:{fontSize:10.5,color:n.textMuted},children:i}),t.jsx("span",{style:{fontSize:10.5,color:n.textSecondary,fontFamily:r?n.fontMono:n.font,whiteSpace:"pre-wrap",overflowWrap:"anywhere"},children:s})]},i))})}function St({t:e,children:n}){return t.jsx("div",{style:{fontSize:11,color:e.textMuted},children:n})}function qe(e){return Array.isArray(e)?e.flatMap(n=>W(n)?[W(n)]:[]):[]}function be(e){return Array.isArray(e)?e.filter(n=>typeof n=="string"):[]}function z(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):""}function yt(e){return{question:e.question??e.label,selectedEvidenceId:e.id}}function it(e){return!e.artifacts.some(r=>!!Tt(le(r)))&&e.status!=="blocked"&&e.status!=="needs_clarification"&&e.artifacts.some(r=>r.kind==="answer"||r.kind==="research_run")}function ts({run:e,artifact:n,tab:r,t:i,appContext:s,onOpenApp:o,onChangeTab:a,onClose:u,onSaveBlock:d,onInsertSql:m,onInsertDql:f}){const l=le(n),c=$e(e)??st(l),h=Be(e)??(typeof l.sql=="string"?l.sql:void 0),x=Ne(l),b=jt(e,n),g=fn(e),R=fr(e),$=un(e),N=n.trustState==="certified",V=e.status==="blocked"||n.trustState==="blocked",q=it(e),Q=hr(l),F=pr({analytical:!!Q,blocked:V,hasDql:!!(c!=null&&c.source),hasSql:!!h,hasLineage:R.length>0}),I=F.some(v=>v.id===r)?r:F[0].id,H=V?"Blocked":N?"Certified":n.trustState==="governed"||n.trustState==="grounded"?"Governed":"AI-generated",O=V?"var(--status-error)":N?"var(--status-success)":n.trustState==="governed"||n.trustState==="grounded"?"var(--accent)":"var(--status-warning)",_=V?"var(--status-error-bg)":N?"var(--status-success-bg)":n.trustState==="governed"||n.trustState==="grounded"?"var(--accent-dim)":"var(--status-warning-bg)";return t.jsxs("div",{style:{width:"clamp(300px, 34vw, 440px)",flexShrink:0,background:"var(--bg-2)",borderLeft:"1px solid var(--border-default)",display:"flex",flexDirection:"column",minHeight:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:10,padding:"14px 16px 12px",borderBottom:"1px solid var(--border-subtle)"},children:[t.jsx("span",{style:{width:32,height:32,borderRadius:8,background:_,color:O,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:"1px solid var(--border-subtle)"},children:t.jsx(Ke,{kind:n.kind})}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:13,fontWeight:650,color:i.textPrimary,lineHeight:1.35},children:jt(e,n)}),t.jsx("div",{style:{fontSize:11,color:i.textMuted,marginTop:2},children:_t(n,l)})]}),t.jsx("span",{style:{border:`1px solid ${O}`,color:O,background:_,borderRadius:999,padding:"2px 8px",fontSize:10,fontWeight:700,flexShrink:0,marginTop:2},children:H}),t.jsx("button",{type:"button",onClick:u,title:"Close",className:"dql-ask-ghost",style:{width:24,height:24,borderRadius:6,border:"none",background:"none",color:i.textMuted,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",flexShrink:0},children:t.jsx(bt,{size:14})})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"10px 16px",borderBottom:"1px solid var(--border-subtle)"},children:[q?t.jsx(dn,{run:e,t:i,appContext:s,onOpenApp:o}):null,q?t.jsxs("button",{type:"button",className:"dql-hover",onClick:d,style:{display:"inline-flex",alignItems:"center",gap:6,padding:"7px 13px",borderRadius:8,border:"1px solid var(--border-default)",background:"var(--bg-2)",color:i.textSecondary,fontSize:12,fontWeight:600,cursor:"pointer",fontFamily:i.font},children:[t.jsx(rt,{size:13})," Save as block"]}):null,t.jsx("div",{style:{flex:1}}),t.jsx("button",{type:"button",title:"More",className:"dql-hover",style:{width:28,height:28,borderRadius:7,border:"1px solid var(--border-default)",background:"var(--bg-2)",color:i.textMuted,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer"},children:t.jsx(ni,{size:14})})]}),t.jsx("div",{style:{display:"flex",alignItems:"center",gap:16,padding:"0 16px",borderBottom:"1px solid var(--border-subtle)",flexShrink:0},children:F.map(v=>t.jsx("button",{type:"button",onClick:()=>a(v.id),style:{padding:"10px 1px",fontSize:12,fontWeight:600,cursor:"pointer",border:"none",background:"none",fontFamily:i.font,whiteSpace:"nowrap",color:I===v.id?i.textPrimary:i.textMuted,boxShadow:I===v.id?`inset 0 -2px 0 0 ${i.accent}`:"none"},children:v.label},v.id))}),t.jsxs("div",{style:{flex:1,minHeight:0,overflow:"auto",padding:"14px 16px 20px"},children:[I==="how"&&Q?t.jsx(es,{run:e,contract:Q,dqlArtifact:c,sql:h,lineage:R,t:i,onInsertSql:m,onInsertDql:f,onSaveBlock:d}):null,I==="dql"?c!=null&&c.source?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[t.jsx("span",{style:{fontSize:11,color:i.textMuted},children:"Reusable governed artifact — save it as a block to certify."}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[f?t.jsx("button",{type:"button",onClick:()=>f({sql:h,dqlArtifact:c,result:x,chartConfig:x?Fe(l,x):void 0,title:b,sourceRunId:e.id,question:e.question}),style:X(i),children:"Open DQL in notebook"}):null,t.jsx(wt,{text:c.source,t:i,title:"Copy DQL"})]})]}),t.jsx("pre",{style:nt(i),children:c.source})]}):t.jsx(St,{t:i,children:"The selected plan failed before a DQL source could be materialized. Review the Plan and Failure & repair sections."}):null,I==="sql"?h?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[t.jsx("span",{style:{fontSize:11,color:i.textMuted},children:"Attempted compiled SQL — open it in Notebook to inspect or repair."}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[m?t.jsx("button",{type:"button",onClick:()=>m(h,b,{question:e.question,sourceRunId:e.id}),style:X(i),children:"Open SQL in notebook"}):null,t.jsx(wt,{text:h,t:i,title:"Copy SQL"})]})]}),t.jsx("pre",{style:nt(i),children:h})]}):t.jsx(St,{t:i,children:"Compilation stopped before SQL was produced. The DQL, plan, trust evidence, and failure steps are still retained."}):null,I==="lineage"?t.jsxs("div",{style:{display:"grid",gap:8},children:[t.jsx("div",{style:{fontSize:11,color:i.textMuted,lineHeight:1.5},children:"Governed semantic objects and physical sources used to produce this result."}),R.map(v=>t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:9,padding:"9px 10px",border:"1px solid var(--border-subtle)",borderRadius:8,background:"var(--bg-1)"},children:[t.jsx(Yn,{size:13,color:i.accent,style:{flexShrink:0,marginTop:2}}),t.jsxs("div",{style:{minWidth:0},children:[t.jsx("div",{style:{fontSize:12,fontWeight:650,color:i.textPrimary},children:v.name}),t.jsx("div",{style:{fontSize:10.5,color:i.textMuted,marginTop:2},children:[v.kind,v.detail].filter(Boolean).join(" · ")})]})]},`${v.kind??"asset"}:${v.name}`))]}):null,I==="trust"?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[$?t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-start",padding:"10px 12px",borderRadius:8,background:N?"var(--status-success-bg)":"var(--status-warning-bg)",border:`1px solid ${N?"var(--status-success-border)":"var(--status-warning-border)"}`},children:[N?t.jsx(he,{size:13,color:"var(--status-success)",style:{flexShrink:0,marginTop:1}}):t.jsx(Ge,{size:13,color:"var(--status-warning)",style:{flexShrink:0,marginTop:1}}),t.jsx("span",{style:{fontSize:12,color:i.textSecondary,lineHeight:1.5},children:$})]}):null,g.length>0?t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:i.textMuted,textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:8},children:"Evidence"}),t.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:g.map(v=>t.jsxs("span",{style:Cr(i,v.certified),children:[v.certified?t.jsx(he,{size:11}):t.jsx(et,{size:11}),t.jsx("span",{children:v.label})]},v.label))})]}):null,e.evaluations.length>0?t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:i.textMuted,textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:8},children:"Verification checks"}),t.jsx(vr,{evaluations:e.evaluations,t:i})]}):null,e.steps.length>0?t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:i.textMuted,textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:8},children:"Steps"}),t.jsx(jr,{steps:e.steps,t:i})]}):null,t.jsx(kr,{run:e,t:i})]}):null]})]})}function ns({t:e,text:n,source:r,left:i,top:s,draft:o,inputRef:a,onDraftChange:u,onClose:d,onSend:m}){const f=(l,c)=>t.jsx("button",{type:"button",onClick:()=>m(c),style:{border:"1px solid var(--border-subtle)",background:"var(--bg-1)",color:e.textSecondary,borderRadius:999,padding:"3px 10px",fontSize:11,fontWeight:550,cursor:"pointer",fontFamily:e.font},children:l});return t.jsxs("div",{"data-selpop":"true",style:{position:"fixed",left:i,top:s,zIndex:90,width:324,background:"var(--bg-2)",border:"1px solid var(--border-default)",borderRadius:12,boxShadow:"0 10px 32px rgba(26,26,26,0.16)",padding:10,display:"flex",flexDirection:"column",gap:8,animation:"dql-agent-fadein 0.14s ease-out",fontFamily:e.font},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx(De,{size:12,color:e.accent}),t.jsx("span",{style:{fontSize:11,fontWeight:700,color:e.textSecondary},children:"Follow up on this"}),t.jsx("span",{style:{fontSize:10,color:e.textMuted},children:r==="table"?"from the result":"from the answer"}),t.jsx("div",{style:{flex:1}}),t.jsx("button",{type:"button",onClick:d,style:{width:20,height:20,borderRadius:5,border:"none",background:"none",color:e.textMuted,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0},children:t.jsx(bt,{size:12})})]}),t.jsxs("div",{style:{borderLeft:`2px solid ${e.accent}`,background:"var(--accent-dim)",borderRadius:"0 6px 6px 0",padding:"5px 9px",fontSize:11.5,color:e.textSecondary,lineHeight:1.45,display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:["“",n,"”"]}),t.jsxs("div",{style:{display:"flex",gap:6},children:[t.jsx("input",{ref:a,value:o,onChange:l=>u(l.target.value),onKeyDown:l=>{l.key==="Enter"&&(l.preventDefault(),m(o))},placeholder:"Ask about this…",style:{flex:1,minWidth:0,border:"1px solid var(--border-default)",borderRadius:8,padding:"7px 10px",fontSize:12.5,fontFamily:e.font,color:e.textPrimary,background:"var(--bg-1)",outline:"none"}}),t.jsx("button",{type:"button",onClick:()=>m(o),title:"Send follow-up",style:{width:30,height:30,flexShrink:0,borderRadius:8,border:"none",background:"var(--accent)",color:"#fff",display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer"},children:t.jsx(Un,{size:13})})]}),t.jsxs("div",{style:{display:"flex",gap:5,flexWrap:"wrap"},children:[f("Why is this?","Why is this happening?"),f("Root cause","What is the root cause?"),f("Break it down","Break this down further")]})]})}function Qt(e){const n=e.replace(/^\/\w+\s+/,"").trim().replace(/[?.!]+$/,"");return(n?n.charAt(0).toUpperCase()+n.slice(1):"New app").slice(0,60)}function dn({run:e,t:n,appContext:r,onOpenApp:i}){const[s,o]=p.useState(!1),[a,u]=p.useState(null),[d,m]=p.useState(!1),[f,l]=p.useState("list"),[c,h]=p.useState(""),[x,b]=p.useState(!1),[g,R]=p.useState(null),[$,N]=p.useState(null),V=p.useRef(null),q=async()=>{u(null),m(!1);try{const _=await ne.listAppsStrict();u(_),_.length===0&&l("new")}catch{u([]),m(!0)}},Q=()=>{o(!0),R(null),l("list"),V.current=null,h(Qt(e.question)),q()},F=()=>{x||(o(!1),R(null))},I=async(_,v,S)=>{const G=$e(e);if(!(await ne.createAiPin(_,{dashboardId:v,title:Qt(e.question),answer:e.answer??e.summary,question:e.question,sql:Be(e),certification:e.trustState==="certified"?"certified":"ai_generated",reviewStatus:e.trustState==="certified"?"certified":"needs_review",analysisPlan:G?{dqlArtifact:G}:void 0})).ok)throw new Error("Could not add to app.");N({appId:_,dashboardId:v,name:S}),o(!1)},H=async _=>{var v,S,G;if(!x){b(!0),R(null);try{let M=(r==null?void 0:r.appId)===_.id?r.dashboardId:void 0;if(!M){const Y=await ne.getApp(_.id),Z=(v=Y==null?void 0:Y.app)==null?void 0:v.homepage;if(M=(Z==null?void 0:Z.type)==="dashboard"?Z.id:(G=(S=Y==null?void 0:Y.dashboards)==null?void 0:S[0])==null?void 0:G.id,!M){const se=await ne.createAppDashboard(_.id,{title:"Overview"});if(!se.ok)throw new Error(se.error);M=se.dashboard.id}}await I(_.id,M,_.name)}catch(M){R(M instanceof Error?M.message:"Could not add to app.")}finally{b(!1)}}},O=async()=>{if(x)return;const _=c.trim()||Qt(e.question);b(!0),R(null);try{if(!V.current){const v=await ne.createApp({name:_,domain:"general",dashboardTitle:"Overview",tags:[],owners:[],selectedBlockIds:[]});V.current={appId:v.app.id,dashboardId:v.dashboardId}}await I(V.current.appId,V.current.dashboardId,_),V.current=null}catch(v){R(v instanceof Error?v.message:"Could not create the app.")}finally{b(!1)}};return t.jsxs("div",{style:{position:"relative",display:"inline-flex",alignItems:"center",gap:6},children:[$?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>i==null?void 0:i($.appId,$.dashboardId),style:{...Gt(n),background:`${n.success}1a`,color:n.success,border:`1px solid ${n.success}55`,boxShadow:"none",cursor:i?"pointer":"default"},title:i?"Open the app":void 0,children:[t.jsx(Xe,{size:13}),"Added to ",$.name,i?t.jsx(Ur,{size:13}):null]}):null,t.jsxs("button",{type:"button",className:"dql-hover dql-lift",onClick:Q,style:$?X(n):Gt(n),children:[t.jsx(Kt,{size:13}),$?"Add to another":"Add to app"]}),s?t.jsxs(t.Fragment,{children:[t.jsx("div",{onClick:F,style:{position:"fixed",inset:0,zIndex:40}}),t.jsxs("div",{style:bs(n),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[t.jsx("span",{style:{fontSize:12,fontWeight:700,color:n.textPrimary},children:f==="new"?"Name the new app":"Add to an app"}),t.jsx("button",{type:"button",onClick:F,style:{border:"none",background:"transparent",color:n.textMuted,cursor:"pointer",fontSize:15,lineHeight:1},children:"×"})]}),g?t.jsx("div",{style:{fontSize:11,color:n.error,marginBottom:7,lineHeight:1.4},children:g}):null,f==="new"?t.jsxs("div",{style:{display:"grid",gap:8},children:[t.jsx("input",{autoFocus:!0,value:c,onChange:_=>h(_.target.value),onKeyDown:_=>{_.key==="Enter"&&O()},placeholder:"App name",style:js(n)}),t.jsxs("div",{style:{display:"flex",gap:6},children:[a&&a.length>0?t.jsx("button",{type:"button",className:"dql-hover",onClick:()=>l("list"),style:X(n),children:"Back"}):null,t.jsxs("button",{type:"button",className:"dql-hover",disabled:x||!c.trim(),onClick:()=>void O(),style:{...Gt(n),flex:1,justifyContent:"center"},children:[x?t.jsx(Pe,{size:13,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(Ye,{size:13}),"Create & add"]})]})]}):a===null?t.jsx("div",{style:{fontSize:11.5,color:n.textMuted,padding:"8px 2px"},children:"Loading apps…"}):d?t.jsxs("div",{style:{display:"grid",gap:8},children:[t.jsx("div",{style:{fontSize:11.5,color:n.error,lineHeight:1.4},children:"Couldn't load your apps."}),t.jsxs("div",{style:{display:"flex",gap:6},children:[t.jsx("button",{type:"button",className:"dql-hover",onClick:()=>void q(),style:X(n),children:"Retry"}),t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>l("new"),style:{...On(n),width:"auto",flex:1,marginBottom:0,justifyContent:"center"},children:[t.jsx(Ye,{size:13})," New app…"]})]})]}):t.jsxs("div",{style:{display:"grid",gap:3,maxHeight:244,overflow:"auto"},children:[t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>l("new"),style:On(n),children:[t.jsx(Ye,{size:13})," New app…"]}),a.map(_=>t.jsxs("button",{type:"button",className:"dql-hover",disabled:x,onClick:()=>void H(_),style:vs(n),children:[t.jsx(Kt,{size:13,style:{flex:"0 0 auto",opacity:.7}}),t.jsx("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",textAlign:"left"},children:_.name})]},_.id))]})]})]}):null]})}function un(e){var n;if(e.trustState==="certified")return"Answered from a certified block.";if(e.route==="dql_block_draft")return"Prepared an ownerless review draft. Add it to Block Studio when you are ready to save it.";if(e.trustState==="governed")return"Built from governed metrics and dimensions.";if(e.trustState==="grounded")return"Ran cleanly against your data. Save it as a block when it is reusable.";if(pn(e)){const r=e.artifacts.map(o=>o.payload).filter(o=>!!(o&&typeof o=="object"&&!Array.isArray(o)));if(r.some(o=>{const a=o.result;return!!(a&&typeof a=="object"&&!Array.isArray(a))}))return"Exploratory · DBT-grounded. The query and bounded join probes ran, but no certified relationship path covers it yet.";const s=(n=r.find(o=>typeof o.executionError=="string"))==null?void 0:n.executionError;return typeof s=="string"&&s.trim()?"Exploratory · DBT-grounded. DQL prepared a review-required query, but its bounded execution failed. Inspect the error and DQL artifact before reuse.":"Exploratory · DBT-grounded. DQL prepared a review-required query, but it has not executed yet."}return e.trustState==="review_required"?"AI-generated answer. Save it as a block when you want to keep it.":(e.trustState==="blocked",null)}function pn(e){return e.artifacts.some(n=>{const r=n.payload;return!!(r&&typeof r=="object"&&!Array.isArray(r)&&r.exploratoryCandidate)})}function rs(e){return e.trustState==="certified"?"Certified answer":e.route==="dql_block_draft"?"Draft block":pn(e)?"Exploratory DBT-grounded answer":e.route==="semantic_answer"?"Semantic answer":e.route==="generated_answer"?"AI-generated answer":sr[e.route]}function is({artifact:e,payload:n,t:r,onOpenApp:i}){const s=typeof n.sessionId=="string"?n.sessionId:void 0,o=n.proposal&&typeof n.proposal=="object"?n.proposal:void 0,a=typeof n.proposalHash=="string"?n.proposalHash:void 0,[u,d]=p.useState(()=>o?Hr(o):new Set),[m,f]=p.useState(!1),[l,c]=p.useState(null),[h,x]=p.useState(null);if(!o||!s)return t.jsxs("div",{style:nn(r),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(Ke,{kind:e.kind}),t.jsx("div",{style:{fontSize:12,fontWeight:800,color:r.textPrimary},children:e.title})]}),t.jsx("div",{style:{fontSize:11.5,color:r.textMuted},children:"This proposal is no longer available. Ask again to rebuild it."})]});const b=async()=>{var R,$;f(!0),c(null);const g=await ne.commitAppAiBuild(s,{selectedTileIds:Array.from(u),expectedProposalHash:a});if(f(!1),!g.ok){c(g.error);return}x({appId:((R=g.app)==null?void 0:R.id)??g.session.appId??"",dashboardId:g.dashboardId??void 0,name:(($=g.app)==null?void 0:$.name)??e.title})};return t.jsxs("div",{style:nn(r),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(Ke,{kind:e.kind}),t.jsx("div",{style:{fontSize:12,fontWeight:800,color:r.textPrimary,flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:ze(e.title)})]}),h?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:6,color:r.success,fontSize:12,fontWeight:750},children:[t.jsx(Xe,{size:13})," Created ",h.name]}),h.appId&&i?t.jsx("button",{type:"button",className:"dql-hover",onClick:()=>i(h.appId,h.dashboardId),style:X(r),children:"Open app"}):null]}):t.jsx(Or,{proposal:o,t:r,selected:u,onToggle:g=>{d(R=>{const $=new Set(R);return $.has(g)?$.delete(g):$.add(g),$})},onCreate:()=>void b(),busy:m,error:l,compact:!0})]})}function yr({artifact:e,certifiedBlockName:n,initialResult:r,initialChartConfig:i,payload:s,executionTarget:o,t:a,themeMode:u,embedded:d=!1}){var de;const[m,f]=p.useState(e),[l,c]=p.useState(()=>e.parameters??[]),[h,x]=p.useState(()=>({...e.parameterValues??{},...en(s)})),[b,g]=p.useState(r),[R,$]=p.useState(i),[N,V]=p.useState(!!n),[q,Q]=p.useState(!1),[F,I]=p.useState(null),[H,O]=p.useState(!1),[_,v]=p.useState(""),[S,G]=p.useState(""),M=p.useRef(!1),Y=p.useRef(e);Y.current=e;const Z=Mi(e);p.useEffect(()=>{const k=Y.current;if(f(k),O(!1),!n){c(k.parameters??[]),x({...k.parameterValues??{},...en(s)}),V(!1);return}let L=!1;return V(!0),ne.getCertifiedBlockParameters(n).then(B=>{L||(c(B.parameters),x(C=>({...Object.fromEntries(B.parameters.flatMap(A=>A.default===void 0?[]:[[A.name,A.default]])),...C})))}).catch(B=>{L||I(B instanceof Error?B.message:String(B))}).finally(()=>{L||V(!1)}),()=>{L=!0}},[Z,n]);const se=async()=>{if(!M.current){M.current=!0,Q(!0),I(null);try{const k=await ne.invokeDqlArtifact(m,h,void 0,n,o);g(k.result),f(k.artifact),k.result.chartConfig&&typeof k.result.chartConfig=="object"&&$(k.result.chartConfig),k.parameters.length>0&&c(k.parameters)}catch(k){I(k instanceof Error?k.message:String(k))}finally{M.current=!1,Q(!1)}}},P=p.useMemo(()=>rr(m,b),[m,b]),D=()=>{const k=P[0];k&&(v(k.column),G(k.values[0]==null?"":String(k.values[0])),O(!0),I(null))},ae=async()=>{try{const k=m.kind==="sql_block"?await ne.addDqlArtifactResultFilter(m,b.columns,_,S,o):Ei(m,b,_,S);f(k.artifact),c(k.artifact.parameters??[]),x(L=>({...L,...k.artifact.parameterValues??{}})),O(!1),I(null)}catch(k){I(k instanceof Error?k.message:String(k))}},J=l.some(er),K=Object.entries(h).filter(([,k])=>k!=null&&k!=="");return t.jsxs("div",{style:{display:"grid",gap:9},children:[K.length>0?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap",padding:d?"8px 12px 0":0},children:[t.jsx("span",{style:{fontSize:10.5,fontWeight:750,color:a.textMuted},children:"Applied inputs"}),K.map(([k,L])=>t.jsxs("span",{style:{fontSize:10.5,color:a.textSecondary,border:`1px solid ${a.cellBorder}`,background:a.appBg,borderRadius:999,padding:"2px 7px"},children:[k.replace(/_/g," ")," = ",ss(L)]},k))]}):null,N?t.jsx("div",{style:{fontSize:10.5,color:a.textMuted},children:"Loading reusable inputs…"}):J||P.length>0?t.jsxs("div",{style:{display:"grid",gap:8,padding:9,margin:d?"0 12px":0,border:`1px solid ${a.cellBorder}`,borderRadius:7,background:a.appBg},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:11,fontWeight:800,color:a.textPrimary},children:"Change DQL inputs"}),t.jsx("div",{style:{fontSize:10,color:a.textMuted},children:"Reruns this DQL artifact directly. It does not start another AI search."})]}),P.length>0?t.jsxs("button",{type:"button",onClick:D,style:X(a),children:[t.jsx(Ye,{size:11})," Add result filter"]}):null,t.jsxs("button",{type:"button",disabled:q,onClick:()=>void se(),style:{...X(a),color:a.accent,opacity:q?.65:1},children:[q?t.jsx(Pe,{size:11,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(De,{size:11}),q?"Running…":"Apply"]})]}),H?t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"minmax(150px, 1fr) minmax(150px, 1fr) auto auto",gap:7,alignItems:"end",padding:8,border:`1px solid ${a.cellBorder}`,borderRadius:7,background:a.cellBg},children:[t.jsxs("label",{style:{display:"grid",gap:4,fontSize:10,fontWeight:750,color:a.textSecondary},children:["Result column",t.jsx("select",{"aria-label":"Result column for new DQL input",value:_,onChange:k=>{const L=k.target.value,B=P.find(C=>C.column===L);v(L),G((B==null?void 0:B.values[0])==null?"":String(B.values[0]))},style:Qn(a),children:P.map(k=>t.jsx("option",{value:k.column,children:k.column.split("_").join(" ")},k.column))})]}),t.jsxs("label",{style:{display:"grid",gap:4,fontSize:10,fontWeight:750,color:a.textSecondary},children:["Default value",t.jsx("input",{"aria-label":"Default value for new DQL input",value:S,list:`ask-filter-${_}`,onChange:k=>G(k.target.value),style:Qn(a)}),t.jsx("datalist",{id:`ask-filter-${_}`,children:(((de=P.find(k=>k.column===_))==null?void 0:de.values)??[]).map(k=>t.jsx("option",{value:String(k)},`${typeof k}:${String(k)}`))})]}),t.jsx("button",{type:"button",onClick:()=>{ae()},style:{...X(a),color:a.accent},children:"Add input"}),t.jsx("button",{type:"button",onClick:()=>O(!1),style:X(a),children:"Cancel"})]}):null,l.length>0?t.jsx(ji,{parameters:l,values:h,onChange:(k,L)=>x(B=>({...B,[k]:L})),t:a}):null,P.length>0?t.jsx("div",{style:{fontSize:9.5,color:a.textMuted},children:"Extra filters are available only for semantic dimensions in this result. They stay transient until you explicitly save a block."}):null]}):null,F?t.jsx("div",{style:{fontSize:10.5,color:a.error},children:F}):null,t.jsx(rn,{result:b,themeMode:u,t:a,chartConfig:R,embedded:d,tabLabels:d?{table:"Results",chart:"Visualization"}:void 0})]})}function en(e){const n=e.result&&typeof e.result=="object"&&!Array.isArray(e.result)?e.result:void 0,r=Array.isArray(n==null?void 0:n.parameters)?n.parameters:Array.isArray(e.parameters)?e.parameters:[];return Object.fromEntries(r.flatMap(i=>{if(!i||typeof i!="object")return[];const s=i;return typeof s.name=="string"?[[s.name,s.value]]:[]}))}function ss(e){return Array.isArray(e)?e.map(n=>String(n)).join(", "):typeof e=="boolean"?e?"true":"false":String(e)}function mr(e,n){const r=n.result&&typeof n.result=="object"&&!Array.isArray(n.result)?n.result:void 0,i=n.block&&typeof n.block=="object"&&!Array.isArray(n.block)?n.block:void 0;return[r==null?void 0:r.blockName,n.sourceCertifiedBlock,i==null?void 0:i.name,e.ref].find(o=>typeof o=="string"&&o.trim().length>0)}function br({artifact:e,t:n,themeMode:r,onInsertSql:i,onInsertDql:s,insertDqlActionLabel:o,sourceRunId:a,sourceQuestion:u,onOpenBlock:d,onOpenResearch:m,onOpenApp:f,onNextAction:l}){const c=e.payload&&typeof e.payload=="object"?e.payload:{};if(e.kind==="app_proposal")return t.jsx(is,{artifact:e,payload:c,t:n,onOpenApp:f});const h=Ne(c),x=st(c),b=Tt(c),g=typeof c.sql=="string"?c.sql:typeof c.sqlPreview=="string"?c.sqlPreview:typeof c.proposedSql=="string"?c.proposedSql:void 0,R=typeof c.name=="string"?c.name:e.title,$=typeof c.path=="string"?c.path:e.ref,N=c.draftBlock&&typeof c.draftBlock=="object"&&!Array.isArray(c.draftBlock)?c.draftBlock:void 0,V=typeof(N==null?void 0:N.path)=="string"?N.path:void 0,q=typeof(N==null?void 0:N.name)=="string"?N.name:void 0,Q=(x==null?void 0:x.sourcePath)??V??(e.kind==="dql_block_draft"?$:void 0),F=(x==null?void 0:x.name)??q??R,I=(x==null?void 0:x.kind)==="sql_block"||e.kind==="dql_block_draft"?"Open DQL draft":"Open DQL artifact",H=c.plan&&typeof c.plan=="object"?c.plan:void 0,O=Array.isArray(H==null?void 0:H.steps)?H.steps:[],_=Array.isArray(H==null?void 0:H.gaps)?H.gaps.map(String):[],v=typeof c.researchRunId=="string"?c.researchRunId:e.kind==="research_run"&&typeof e.ref=="string"?e.ref:void 0,S=typeof c.notebookPath=="string"?c.notebookPath:void 0,G=Array.isArray(c.generatedPaths)?c.generatedPaths.filter(P=>typeof P=="string"):[],M=c.narration&&typeof c.narration=="object"?c.narration:void 0,Y=Array.isArray(M==null?void 0:M.keyFindings)?M.keyFindings.filter(P=>typeof P=="string"):[],Z=typeof(M==null?void 0:M.recommendation)=="string"?M.recommendation:void 0,se=e.trustState==="certified"?mr(e,c):void 0;if(e.kind==="dql_block_draft"){const P=ae=>Array.isArray(ae)?ae.filter(J=>typeof J=="string"):void 0,D=c.certifierVerdict&&typeof c.certifierVerdict=="object"?c.certifierVerdict:void 0;return t.jsx(bi,{t:n,name:typeof c.name=="string"?c.name:R,status:"draft",description:typeof c.description=="string"?c.description:void 0,dql:(x==null?void 0:x.source)??(typeof c.dqlSource=="string"?c.dqlSource:void 0),sqlPreview:g,grain:typeof c.grain=="string"?c.grain:void 0,outputs:P(c.outputs),dimensions:P(c.dimensions)??(x==null?void 0:x.dimensions),entities:P(c.entities),certifierVerdict:D?{blocking:P(D.blocking)??[],warnings:P(D.warnings)??[],ready:!!D.ready}:void 0,actions:t.jsxs(t.Fragment,{children:[g&&s?t.jsx("button",{type:"button",onClick:()=>s({sql:g,dqlArtifact:x,result:h,chartConfig:h?Fe(c,h):void 0,title:R,sourceRunId:a,question:u}),style:X(n),children:o??"Insert as DQL cell"}):g&&i?t.jsx("button",{type:"button",onClick:()=>i(g,R,{question:u,sourceRunId:a}),style:X(n),children:"Insert SQL preview"}):null,Q&&d?t.jsx("button",{type:"button",onClick:()=>d(Q,F),style:X(n),children:I}):null]})})}return t.jsxs("div",{style:nn(n),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(Ke,{kind:e.kind}),t.jsx("div",{style:{fontSize:12,fontWeight:800,color:n.textPrimary,flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:ze(e.title)})]}),Y.length>0?t.jsxs("div",{style:{display:"grid",gap:4},children:[t.jsx("div",{style:{fontSize:11,fontWeight:800,color:n.textSecondary},children:"Key findings"}),t.jsx(Pn,{items:Y,t:n,renderItem:(P,D)=>t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.4,display:"flex",gap:6},children:[t.jsx("span",{style:{color:n.accent},children:"•"}),t.jsx("span",{children:P})]},D)})]}):O.length>0?t.jsx("div",{style:{display:"grid",gap:5},children:t.jsx(Pn,{items:O,t:n,renderItem:(P,D)=>t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.35},children:[D+1,". ",String(P.thought??P.expectation??"Research step")]},D)})}):null,Z?t.jsxs("div",{style:{fontSize:11.5,color:n.textPrimary,lineHeight:1.4,display:"flex",gap:6},children:[t.jsx("span",{style:{color:n.accent},children:"→"}),t.jsx("span",{children:Z})]}):null,h?x?t.jsx(yr,{artifact:x,certifiedBlockName:se,initialResult:h,initialChartConfig:Fe(c,h),payload:c,t:n,themeMode:r}):t.jsx(rn,{result:h,themeMode:r,t:n,chartConfig:Fe(c,h)}):null,x?t.jsxs("details",{children:[t.jsxs("summary",{style:{cursor:"pointer",fontSize:11,color:n.textSecondary,listStyle:"none",display:"flex",alignItems:"center",gap:5},children:[t.jsx(rt,{size:12}),t.jsx("span",{children:"View DQL artifact"}),t.jsxs("span",{style:{marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:4},children:[x.source?t.jsx(wt,{text:x.source,t:n,title:"Copy DQL"}):null,!Q&&l?t.jsxs("button",{type:"button",className:"dql-hover",title:"Save this DQL as a reusable block",onClick:P=>{P.preventDefault(),P.stopPropagation(),l({id:"save-dql-block",label:"Save as DQL block",route:"dql_block_draft"})},style:{border:"none",background:"transparent",cursor:"pointer",color:n.accent,display:"inline-flex",alignItems:"center",gap:3,fontSize:10.5,fontWeight:700,padding:"2px 4px"},children:[t.jsx(on,{size:12})," Save as block"]}):null]})]}),x.sourcePath?t.jsx("div",{style:{marginTop:6,fontSize:10.5,color:n.textMuted},children:x.sourcePath}):null,t.jsx("pre",{style:{...nt(n),marginTop:6},children:x.source})]}):null,g?t.jsxs("details",{children:[t.jsxs("summary",{style:{cursor:"pointer",fontSize:11,color:n.textSecondary,listStyle:"none",display:"flex",alignItems:"center",gap:5},children:[t.jsx(sn,{size:12}),t.jsx("span",{children:wr(!!x)}),t.jsx("span",{style:{marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:4},children:t.jsx(wt,{text:g,t:n,title:"Copy SQL"})})]}),t.jsx("pre",{style:{...nt(n),marginTop:6},children:g})]}):null,_.length>0?t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.4},children:["Gaps: ",_.join(", ")]}):null,G.length>0?t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.4},children:["Files: ",G.join(", ")]}):null,t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[v&&m?t.jsx("button",{type:"button",onClick:()=>m(v,S),style:X(n),children:"Open research"}):null,g&&s?t.jsx("button",{type:"button",onClick:()=>s({sql:g,dqlArtifact:x,result:h,chartConfig:h?Fe(c,h):void 0,title:R,mixedSourcePlan:b,sourceRunId:a,question:u}),style:b?{...X(n),background:n.accent,borderColor:n.accent,color:"#fff",fontWeight:850,padding:"7px 11px"}:X(n),children:b?"Add workflow to notebook":x?"Insert as DQL cell":"Add SQL to notebook"}):g&&i?t.jsx("button",{type:"button",onClick:()=>i(g,R,{question:u,sourceRunId:a}),style:X(n),children:"Insert SQL preview"}):null,Q&&d?t.jsx("button",{type:"button",onClick:()=>d(Q,F),style:X(n),children:I}):null]})]})}function os({run:e}){return e.trustState==="certified"?t.jsx(he,{size:16,color:"#16a34a"}):e.trustState==="governed"?t.jsx(he,{size:16,color:"#2563eb"}):e.trustState==="grounded"?t.jsx(he,{size:16,color:"#2563eb"}):e.status==="completed"?t.jsx(Xe,{size:16,color:"#16a34a"}):e.status==="blocked"?t.jsx(Ut,{size:16,color:"#ef4444"}):t.jsx(Ut,{size:16,color:"#d97706"})}function Ke({kind:e}){return e==="sql_cell"?t.jsx(sn,{size:14}):e==="dql_block_draft"?t.jsx(rt,{size:14}):e==="app_draft"||e==="app_proposal"?t.jsx(Kt,{size:14}):e==="research_run"?t.jsx(et,{size:14}):t.jsx(De,{size:14})}function ls({run:e,t:n}){const r=e.trustState==="certified"?n.success:e.trustState==="governed"||e.trustState==="grounded"?n.accent:e.trustState==="blocked"?n.error:e.trustState==="not_applicable"?n.textMuted:n.warning,i=e.trustState==="certified"?"Certified":e.route==="dql_block_draft"?"Draft":pn(e)?"Exploratory":e.trustState==="blocked"?"Needs input":"AI-generated";return t.jsx("span",{style:{border:`1px solid ${r}55`,color:r,background:`${r}12`,borderRadius:999,padding:"3px 7px",fontSize:10,fontWeight:850},children:i})}function vr({evaluations:e,t:n}){if(e.length===0)return null;const r=e.filter(s=>!s.passed),i=e.filter(s=>s.passed);return t.jsxs("div",{style:{display:"grid",gap:6,gridTemplateColumns:"minmax(0, 1fr)",minWidth:0},children:[r.map(s=>t.jsx(tn,{evaluation:s,t:n},s.id)),i.length>0?t.jsxs("details",{children:[t.jsxs("summary",{className:"dql-hover",style:{cursor:"pointer",listStyle:"none",display:"inline-flex",alignItems:"center",gap:6,fontSize:11,fontWeight:700,color:n.textMuted,width:"fit-content"},children:[t.jsx(he,{size:12,color:n.success}),t.jsxs("span",{children:[i.length," check",i.length>1?"s":""," verified"]})]}),t.jsx("div",{style:{display:"grid",gap:5,marginTop:7},children:i.map(s=>t.jsx(tn,{evaluation:s,t:n},s.id))})]}):null]})}function tn({evaluation:e,t:n}){const r=e.passed?n.success:e.severity==="blocking"?n.error:n.warning;return t.jsxs("div",{style:{display:"flex",gap:7,alignItems:"flex-start",fontSize:11.5,color:n.textSecondary,minWidth:0},children:[t.jsx("span",{style:{color:r,lineHeight:"16px",flex:"0 0 auto",fontWeight:800},children:e.passed?"OK":e.severity==="blocking"?"Stop":"Review"}),t.jsxs("span",{style:{lineHeight:1.4,minWidth:0,flex:1,overflowWrap:"anywhere"},children:[e.message,!e.passed&&e.suggestedRepair?t.jsxs("span",{style:{display:"block",color:n.textMuted,marginTop:1},children:["↳ ",e.suggestedRepair]}):null]})]})}function Vt({t:e,icon:n,label:r,tone:i}){const s=i==="accent"?e.accent:i==="warning"?e.warning:e.textMuted;return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,border:`1px solid ${s}44`,color:s,background:`${s}10`,borderRadius:999,padding:"2px 7px",fontSize:10,fontWeight:800},children:[n,t.jsx("span",{children:r})]})}function as(e,n){switch(e){case"passed":return n.success;case"repaired":return n.accent;case"escalated":return n.accent;case"blocked":return n.error;default:return n.warning}}function jr({steps:e,t:n}){return t.jsxs("details",{style:{border:`1px solid ${n.headerBorder}`,background:n.cellBg,borderRadius:8,padding:"6px 9px"},children:[t.jsxs("summary",{style:{cursor:"pointer",fontSize:11.5,fontWeight:800,color:n.textSecondary,listStyle:"none",display:"flex",alignItems:"center",gap:6},children:[t.jsx(tt,{size:13}),t.jsxs("span",{children:["Plan trace · ",e.length," steps"]})]}),t.jsx("div",{style:{display:"grid",gap:10,marginTop:8},children:e.map(r=>{const i=as(r.status,n);return t.jsxs("div",{style:{display:"grid",gap:4,paddingLeft:8,borderLeft:`2px solid ${i}55`},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[t.jsxs("span",{style:{fontSize:11.5,fontWeight:850,color:n.textPrimary},children:[r.index,". ",sr[r.route]]}),t.jsxs("span",{style:{border:`1px solid ${i}55`,color:i,background:`${i}12`,borderRadius:999,padding:"1px 6px",fontSize:9.5,fontWeight:850,display:"inline-flex",alignItems:"center",gap:3},children:[r.status==="escalated"?t.jsx(Yn,{size:10}):r.status==="repaired"?t.jsx(Rt,{size:10}):null,r.status.split("_").join(" ")]}),r.attempts>1?t.jsxs("span",{style:{fontSize:10,color:n.textMuted},children:[r.attempts," attempts"]}):null]}),r.goal?t.jsx("div",{style:{fontSize:11,color:n.textMuted,lineHeight:1.35},children:r.goal}):null,r.evaluations.length>0?t.jsx("div",{style:{display:"grid",gap:4},children:r.evaluations.map(s=>t.jsx(tn,{evaluation:s,t:n},s.id))}):null]},r.id)})})]})}function cs(e){if(e==="research")return"research";if(e==="sql_cell")return"sql";if(e==="dql_block_draft")return"block";if(e==="app_build")return"app";if(e==="certified_answer"||e==="semantic_answer"||e==="generated_answer")return"ask"}function ds(e,n){return n==="sql_cell"?`Create a SQL cell for: ${e.question}`:n==="dql_block_draft"?`Create a DQL block draft for: ${e.question}`:n==="app_build"?`Build an app for: ${e.question}`:n==="research"?`Research deeper: ${e.question}`:e.question}function Dn(e){return`${e}_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function Ve(e){return e.replace(/^\s*Outcome\s*:\s*[^\n]*\n+/i,"").replace(/^\s*Review required:\s*/gim,"").replace(/\breview-required\b/gi,"AI-generated").replace(/\*\*(.+?)\*\*/g,"$1").replace(/`([^`]+)`/g,"$1").replace(/^_(.+?)_$/gm,"$1").trim()}function ze(e){return e.replace(/^\s*Review required:\s*/gim,"").replace(/\breview-required\b/gi,"AI-generated").replace(/\bqueued for review\b/gi,"saved as a draft").trim()}function us(e,n){const r=i=>i.toLowerCase().replace(/[\s.,!?'"()`*_-]+/g," ").trim();return r(e)===r(n)}function Ne(e){var r,i;const n=[e.result,e.resultPreview,(r=e.researchRun)==null?void 0:r.resultPreview,(i=e.result)==null?void 0:i.result];for(const s of n){if(!s||typeof s!="object")continue;const o=s;if(!Array.isArray(o.rows)&&!Array.isArray(o.columns))continue;const a=Array.isArray(o.rows)?o.rows.filter(d=>!!(d&&typeof d=="object")):[],u=Array.isArray(o.columns)&&o.columns.length>0?o.columns.map(d=>typeof d=="string"?d:(d==null?void 0:d.name)??String(d)):a.length>0?Object.keys(a[0]):[];if(!(a.length===0&&u.length===0&&typeof o.rowCount!="number"))return{columns:u,rows:a,rowCount:typeof o.rowCount=="number"?o.rowCount:a.length,...typeof o.executionTime=="number"?{executionTime:o.executionTime}:{}}}}function Fe(e,n){const r=e.result&&typeof e.result=="object"?e.result:void 0,i=r!=null&&r.chartConfig&&typeof r.chartConfig=="object"?r.chartConfig:e.chartConfig&&typeof e.chartConfig=="object"?e.chartConfig:{},s=typeof e.suggestedViz=="string"?e.suggestedViz:typeof(r==null?void 0:r.suggestedViz)=="string"?r.suggestedViz:void 0,o=i.decisionSource==="authored"||i.decisionSource==="agent"||i.decisionSource==="data"||i.decisionSource==="user"?i.decisionSource:void 0,a=typeof i.chart=="string"?i.chart:s,u=a?a.toLowerCase().replace(/_/g,"-")==="single-value"?"kpi":a:void 0,d=n.columns,m=c=>typeof i[c]=="string"&&d.includes(i[c])?i[c]:void 0,f=Array.isArray(i.metrics)?i.metrics.filter(c=>typeof c=="string"&&d.includes(c)):[],l={...u?{chart:u}:{},...u?{decisionSource:o??"agent"}:{},...typeof i.rationale=="string"?{rationale:i.rationale}:{},...m("x")?{x:m("x")}:{},...m("y")?{y:m("y")}:{},...f.length>0?{metrics:f}:{},...m("color")?{color:m("color")}:{},...typeof i.title=="string"?{title:i.title}:{},...typeof i.colorPalette=="string"?{colorPalette:i.colorPalette}:{},...typeof i.maxItems=="number"?{maxItems:i.maxItems}:{}};return Object.keys(l).length>0?l:void 0}function Sr(e,n){var i;const r=Fe(e,n);return(r==null?void 0:r.chart)==="table"&&(((i=r.metrics)==null?void 0:i.length)??0)<=1&&r.decisionSource!=="authored"&&r.decisionSource!=="user"?{...r,chart:void 0}:r}function st(e){const n=Ze(e.dqlArtifact);if(n)return n;const r=e.researchRun&&typeof e.researchRun=="object"&&!Array.isArray(e.researchRun)?e.researchRun:void 0;return Ze(r==null?void 0:r.dqlArtifact)}function wr(e){return e?"View compiled SQL preview":"View SQL preview"}function wt({text:e,t:n,title:r="Copy"}){const[i,s]=p.useState(!1),o=async a=>{a.preventDefault(),a.stopPropagation();try{await navigator.clipboard.writeText(e),s(!0),setTimeout(()=>s(!1),1500)}catch{}};return t.jsxs("button",{type:"button",onClick:o,title:r,className:"dql-hover",style:{border:"none",background:"transparent",cursor:"pointer",color:i?n.success:n.textMuted,display:"inline-flex",alignItems:"center",gap:3,fontSize:10.5,fontWeight:650,padding:"2px 4px"},children:[i?t.jsx(Je,{size:12}):t.jsx(Xn,{size:12}),i?"Copied":null]})}function le(e){return e.payload&&typeof e.payload=="object"&&!Array.isArray(e.payload)?e.payload:{}}function ps(e){var i,s,o;const n=[],r=new Set;for(const a of e.artifacts){const u=le(a),d=Array.isArray(u.memoryContext)?u.memoryContext:[];for(const f of d){if(!f||typeof f!="object")continue;const l=f,c=typeof l.title=="string"?l.title.trim():"";!c||r.has(`m:${c}`)||(r.add(`m:${c}`),n.push({kind:"memory",id:typeof l.id=="string"?l.id:void 0,label:c,detail:typeof l.content=="string"?l.content:void 0}))}const m=Array.isArray(u.appliedHints)?u.appliedHints:[];for(const f of m){if(!f||typeof f!="object")continue;const l=f,c=typeof l.title=="string"?l.title.trim():"";if(!c||r.has(`h:${c}`))continue;r.add(`h:${c}`);const h=typeof((i=l.lesson)==null?void 0:i.rule)=="string"?l.lesson.rule:typeof l.guidance=="string"?l.guidance:void 0,x=[typeof l.scopeReason=="string"?l.scopeReason:void 0,typeof l.graphReason=="string"?l.graphReason:void 0].filter(Boolean).join("; "),b=typeof((s=l.matchSignals)==null?void 0:s.lexicalScore)=="number"?l.matchSignals.lexicalScore:void 0,g=typeof((o=l.matchSignals)==null?void 0:o.graphScore)=="number"?l.matchSignals.graphScore:void 0,R=b!==void 0||g!==void 0?`Signals: lexical ${(b??0).toFixed(2)}, graph ${(g??0).toFixed(2)}`:void 0;n.push({kind:"hint",id:typeof l.hintId=="string"?l.hintId:void 0,label:c,detail:[h,x?`Matched: ${x}`:void 0,R].filter(Boolean).join(" · ")||void 0})}}return n.slice(0,6)}function kr({run:e,t:n}){const[r,i]=p.useState(!1),[s,o]=p.useState(new Set),a=p.useMemo(()=>ps(e).filter(d=>!d.id||!s.has(d.id)),[e,s]);if(a.length===0)return null;const u=async d=>{try{await ne.deleteAgentMemory(d),o(m=>new Set(m).add(d))}catch{}};return t.jsxs("div",{style:{display:"grid",gap:6,gridTemplateColumns:"minmax(0, 1fr)",minWidth:0},children:[t.jsxs("button",{type:"button",onClick:()=>i(d=>!d),style:fs(n),children:[t.jsx(vt,{size:11}),t.jsxs("span",{children:["Applied ",a.length," learning",a.length>1?"s":""]}),r?t.jsx(Jn,{size:11}):t.jsx(At,{size:11})]}),r?t.jsxs("div",{style:gs(n),children:[a.map(d=>t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-start"},children:[t.jsx("span",{style:xs(n,d.kind),children:d.kind==="hint"?"governed lesson":"memory"}),t.jsxs("div",{style:{minWidth:0,flex:1},children:[t.jsx("div",{style:{fontSize:11.5,fontWeight:650,color:n.textPrimary},children:d.label}),d.detail?t.jsx("div",{style:{fontSize:11,color:n.textMuted,lineHeight:1.4,marginTop:1},children:d.detail}):null]}),d.kind==="memory"&&d.id?t.jsx("button",{type:"button",onClick:()=>void u(d.id),style:hs(n),children:"Stop using"}):null]},`${d.kind}:${d.label}`)),t.jsx("div",{style:{fontSize:10.5,color:n.textMuted},children:"Advisory only — learnings never override a certified answer. Manage them under Settings → Agent learning."})]}):null]})}function fn(e){const n=[],r=new Set,i=e.trustState==="certified",s=(o,a)=>{typeof o!="string"||!o.trim()||r.has(o)||(r.add(o),n.push({label:o,certified:a}))};for(const o of e.artifacts){const a=le(o);o.ref&&s(o.ref,i);const u=a.plan&&typeof a.plan=="object"?a.plan:void 0;Array.isArray(u==null?void 0:u.sources)&&u.sources.forEach(d=>s(d,i)),s(a.sourceCertifiedBlock,!0)}return n.slice(0,4)}function Be(e){for(const n of e.artifacts){const r=le(n),i=r.researchRun&&typeof r.researchRun=="object"?r.researchRun:void 0,s=r.proposedSql??r.sql??r.sqlPreview??(i==null?void 0:i.generatedSql)??(i==null?void 0:i.reviewedSql);if(typeof s=="string"&&s.trim())return s}}function $e(e){for(const n of e.artifacts){const r=le(n),i=Ze(r.dqlArtifact);if(i)return i;const s=r.researchRun&&typeof r.researchRun=="object"&&!Array.isArray(r.researchRun)?r.researchRun:void 0,o=Ze(s==null?void 0:s.dqlArtifact);if(o)return o}}function gn(e){const n=e.route==="dql_block_draft"&&e.status!=="blocked"&&e.status!=="needs_clarification";if(e.route==="certified_answer"||!it(e)&&!n)return;const r=$e(e),i=Be(e);if(!((!(r!=null&&r.source)||r.sourcePath)&&!i)){for(const s of e.artifacts){const o=le(s),a=Ne(o),u=Tt(o);if(a)return{sql:i,dqlArtifact:r,result:a,chartConfig:Fe(o,a),title:(r==null?void 0:r.name)??s.title??e.question,mixedSourcePlan:u,sourceRunId:e.id,question:e.question,executionTarget:e.executionTarget};if(u)return{sql:i,dqlArtifact:r,title:(r==null?void 0:r.name)??s.title??e.question,mixedSourcePlan:u,sourceRunId:e.id,question:e.question,executionTarget:e.executionTarget}}return{sql:i,dqlArtifact:r,title:(r==null?void 0:r.name)??e.question,sourceRunId:e.id,question:e.question,executionTarget:e.executionTarget}}}function Tt(e){const n=e.mixedSourcePlan;if(!n||typeof n!="object"||Array.isArray(n))return;const r=n;if(["localDataset","localAlias","localKey","warehouseKey","warehouseExpression","warehouseSql"].every(s=>typeof r[s]=="string"&&String(r[s]).trim()))return{datasetId:typeof r.datasetId=="string"?r.datasetId:void 0,datasetName:typeof r.datasetName=="string"?r.datasetName:void 0,localDataset:String(r.localDataset),localAlias:String(r.localAlias),localKey:String(r.localKey),warehouseKey:String(r.warehouseKey),warehouseExpression:String(r.warehouseExpression),warehouseSql:String(r.warehouseSql),warehouseRelations:Array.isArray(r.warehouseRelations)?r.warehouseRelations.filter(s=>typeof s=="string"):void 0}}function Cr(e,n){return{display:"inline-flex",alignItems:"center",gap:4,fontSize:10.5,padding:"2px 7px",borderRadius:999,background:n?`${e.success}14`:e.cellBg,color:n?e.success:e.textMuted,border:`1px solid ${n?`${e.success}44`:e.headerBorder}`}}function fs(e){return{display:"inline-flex",alignItems:"center",gap:5,alignSelf:"flex-start",fontSize:10.5,fontWeight:600,padding:"2px 8px",borderRadius:999,background:`${e.accent}14`,color:e.accent,border:`1px solid ${e.accent}33`,cursor:"pointer"}}function gs(e){return{display:"grid",gap:8,padding:10,borderRadius:8,background:e.cellBg,border:`1px solid ${e.headerBorder}`}}function xs(e,n){const r=n==="hint";return{flex:"0 0 auto",fontSize:9,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.04em",padding:"2px 6px",borderRadius:4,marginTop:1,background:r?`${e.accent}1f`:`${e.textMuted}1f`,color:r?e.accent:e.textMuted}}function hs(e){return{flex:"0 0 auto",fontSize:10.5,border:`1px solid ${e.headerBorder}`,background:"transparent",color:e.textMuted,borderRadius:6,padding:"2px 7px",cursor:"pointer"}}function ys(e){return{width:30,height:30,borderRadius:8,background:`${e.accent}14`,border:`1px solid ${e.accent}36`,color:e.accent,display:"inline-flex",alignItems:"center",justifyContent:"center",flex:"0 0 auto"}}function Nn(e){return{...ys(e),width:40,height:40}}function kt(e){return{...zt(e,{variant:"secondary",size:"md",pill:!0}),fontWeight:550}}function ms(e){return{flex:1,minHeight:54,maxHeight:140,resize:"none",border:`1px solid ${e.btnBorder}`,background:e.inputBg,color:e.textPrimary,borderRadius:12,padding:"11px 13px",fontSize:13,lineHeight:1.45,fontFamily:e.font,outline:"none",boxShadow:"none"}}function Hn(e,n){return{...zt(e,{variant:n?"primary":"secondary",size:"lg"}),...n?{}:{color:e.textMuted}}}function Gt(e){return{border:"none",background:e.accent,color:"#fff",borderRadius:8,padding:"7px 13px",display:"inline-flex",alignItems:"center",gap:6,fontSize:12,fontWeight:700,fontFamily:e.font,cursor:"pointer",boxShadow:`0 1px 5px ${e.accent}4d`}}function bs(e){return{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:41,width:264,background:e.cellBg,border:`1px solid ${e.headerBorder}`,borderRadius:10,boxShadow:"0 12px 32px rgba(0,0,0,0.2)",padding:10}}function vs(e){return{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"8px 9px",borderRadius:7,border:"none",background:"transparent",color:e.textSecondary,fontSize:12.5,fontWeight:550,fontFamily:e.font,cursor:"pointer"}}function On(e){return{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"8px 9px",borderRadius:7,border:`1px dashed ${e.accent}66`,background:`${e.accent}0d`,color:e.accent,fontSize:12.5,fontWeight:650,fontFamily:e.font,cursor:"pointer",marginBottom:2}}function js(e){return{width:"100%",boxSizing:"border-box",border:`1px solid ${e.btnBorder}`,background:e.inputBg,color:e.textPrimary,borderRadius:8,padding:"8px 10px",fontSize:12.5,fontFamily:e.font,outline:"none"}}function Ss(e){return{alignSelf:"flex-end",maxWidth:"88%",background:`${e.accent}16`,color:e.textPrimary,border:`1px solid ${e.accent}32`,borderRadius:8,padding:"8px 10px",fontSize:12.5,lineHeight:1.45}}function ws(e){return{alignSelf:"flex-start",maxWidth:"92%",color:e.textPrimary,border:`1px solid ${e.cellBorder}`,background:e.appBg,borderRadius:10,padding:"10px 12px"}}function ks(e){return{border:`1px solid ${e.cellBorder}`,background:e.appBg,borderRadius:8,padding:10,display:"grid",gap:10,gridTemplateColumns:"minmax(0, 1fr)",minWidth:0,maxWidth:"100%"}}function nn(e){return{border:`1px solid ${e.headerBorder}`,background:e.cellBg,borderRadius:8,padding:9,display:"grid",gap:8,gridTemplateColumns:"minmax(0, 1fr)",minWidth:0,maxWidth:"100%"}}function Cs(e){return{border:`1px solid ${e.headerBorder}`,background:e.cellBg,borderRadius:8,padding:9,fontSize:12.5,color:e.textPrimary,lineHeight:1.45}}function nt(e){return{margin:0,maxHeight:180,overflow:"auto",border:`1px solid ${e.headerBorder}`,background:e.editorBg,color:e.textPrimary,borderRadius:7,padding:9,fontSize:11,lineHeight:1.45,fontFamily:e.fontMono,whiteSpace:"pre-wrap"}}function Qn(e){return{width:"100%",minWidth:0,boxSizing:"border-box",background:e.inputBg,border:`1px solid ${e.inputBorder}`,borderRadius:5,color:e.textPrimary,padding:"5px 7px",fontSize:11,fontFamily:e.font}}function X(e){return zt(e,{variant:"secondary",size:"sm"})}const Ct={warehouse:{title:"The warehouse rejected the query",hint:"The SQL reached your warehouse and it refused. The message below is the driver’s own."},dql_compilation:{title:"DQL could not build a reusable block",hint:"The query itself is fine — only saving this answer as a block is affected."},governance_gate:{title:"DQL stopped this before running it",hint:"A governance check refused the query, so it never reached the warehouse."},retrieval_gap:{title:"DQL could not confirm this data exists",hint:"The relation was not in the inspected metadata. Refreshing the connection scope usually resolves it."},ambiguity:{title:"One detail is missing",hint:"Answer the question above and DQL will continue."},provider:{title:"The AI provider failed",hint:"Nothing was run. Retry, or check the provider in Settings."},host:{title:"DQL hit an internal error",hint:"This is a defect in DQL. The detail below is what to report."},unknown:{title:"The query could not be completed",hint:"Inspect the details or use the bounded repair when it is available."}};function Ar(e){var n,r,i;for(const s of e.artifacts??[]){const o=le(s),a=(n=o==null?void 0:o.warehouseFailure)==null?void 0:n.origin;if(typeof a=="string"&&a in Ct)return a;if(o!=null&&o.providerFailure||(o==null?void 0:o.refusalCode)==="provider_error")return"provider"}return((i=(r=e.diagnosticReceipt)==null?void 0:r.failure)==null?void 0:i.code)==="AI_PROVIDER_FAILURE"?"provider":"unknown"}function As(e){var n;if(e.status!=="blocked"||!Be(e))return!1;for(const r of e.artifacts??[]){const i=le(r),s=(n=i==null?void 0:i.warehouseFailure)==null?void 0:n.category;if(typeof s=="string"&&["permission","authentication","unsafe","cancelled"].includes(s))return!1}return!0}function qs({run:e,detail:n,threadId:r,onRepaired:i,t:s}){const o=Ar(e),a=Ct[o]??Ct.unknown,[u,d]=p.useState(!1),[m,f]=p.useState(null),l=As(e),c=async()=>{if(!u){d(!0),f(null);try{const h=await ne.repairAgentRunExecution(e.id,r);i(h.run)}catch(h){f(h instanceof Error?h.message:String(h))}finally{d(!1)}}};return t.jsxs("div",{"data-followup":"answer",style:{display:"flex",flexDirection:"column",gap:6,padding:"11px 13px",borderRadius:9,border:`1px solid ${s.error}33`,background:`${s.error}0d`},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7},children:[t.jsx(Ge,{size:13,color:s.error,style:{flexShrink:0}}),t.jsx("span",{style:{fontSize:12.5,fontWeight:700,color:s.textPrimary},children:a.title})]}),t.jsx("div",{style:{fontSize:12.5,lineHeight:1.6,color:s.textSecondary,wordBreak:"break-word"},children:ze(n)}),t.jsx("div",{style:{fontSize:11.5,lineHeight:1.5,color:s.textMuted},children:a.hint}),l?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap",marginTop:2},children:[t.jsxs("button",{type:"button",className:"dql-hover",disabled:u,onClick:()=>void c(),style:{...X(s),opacity:u?.7:1},children:[t.jsx(Rt,{size:12})," ",u?"Fixing and retrying…":"Fix and retry"]}),t.jsx("span",{style:{fontSize:10.5,color:s.textMuted},children:"One bounded repair attempt on the same data target."})]}):null,m?t.jsx("div",{role:"alert",style:{fontSize:11.5,lineHeight:1.45,color:s.error},children:ze(m)}):null]})}function qr(e){var n,r;for(const i of e.artifacts??[]){const s=le(i),o=s==null?void 0:s.warehouseFailure,a=[o==null?void 0:o.redactedMessage,o==null?void 0:o.diagnostic,s==null?void 0:s.executionError].find(u=>typeof u=="string"&&u.trim().length>0);if(a)return a}return e.summary||((r=(n=e.diagnosticReceipt)==null?void 0:n.failure)==null?void 0:r.message)}const Ps=Object.freeze(Object.defineProperty({__proto__:null,ASK_FAILURE_PRESENTATION:Ct,UnifiedAgentRunPanel:Fi,agentRunHistoryFromItems:ir,analyticalInspectorContract:hr,analyticalInspectorSections:Xi,analyticalRepairActionLabels:Zi,artifactReadyPayloadFromRun:gn,artifactSqlDisclosureLabel:wr,askArtifactMeta:_t,askFailureDetail:qr,askFailureOrigin:Ar,askInspectorTabsForState:pr,clarificationSelectionInput:yt,completedRunGuidanceFor:dr,deriveResultChartConfig:Dr,hasAnalyticalInspectorContract:It,inlineAskChartConfig:Sr,isAgentRunPinnable:it,liveAgentActivityFor:ur,longRunGuidanceFor:cr,preferredAskInspectorTab:cn,resolveArtifactDqlView:st,resolvedParameterValues:en,selectAgentExecutionConnection:lr,threadItemsFromTurns:ar,trustExplainer:un,usePersistedAgentThreadId:Qr},Symbol.toStringTag,{value:"Module"}));export{ji as B,ni as E,zn as S,Fi as U,ui as a,mi as b,Ps as c};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{u as x,r as w,a as k,m}from"./index-
|
|
1
|
+
import{u as x,r as w,a as k,m}from"./index-Ca3UeUWI.js";const C="dql:focus-notebook-cell";function h(e){window.setTimeout(()=>{window.dispatchEvent(new CustomEvent(C,{detail:{cellId:e}}))},0)}function S(e){var t,a,c;const i=(t=e.question)==null?void 0:t.trim(),n=(a=e.generatedSql)==null?void 0:a.trim(),s=(c=e.generatedDql)==null?void 0:c.trim();if(!(!i||!n&&!s))return{version:1,source:"agent_run",question:i,...n?{generatedSql:n}:{},...s?{generatedDql:s}:{},...e.sourceRunId?{sourceRunId:e.sourceRunId}:{}}}function g(e){return e.replace(/[^a-zA-Z0-9_ -]+/g," ").replace(/\s+/g,"_").replace(/^_+|_+$/g,"").slice(0,48)||"ai_analysis"}function E(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function I(e,i){var c,o,u,f,l,q;const n=(o=(c=e.dqlArtifact)==null?void 0:c.source)==null?void 0:o.trim(),s=(e.sql??n??"").trim();if(!s&&!n)return[];if(e.mixedSourcePlan){const r=e.mixedSourcePlan,A=m("markdown",[`### ${e.title??"Mixed-source analysis"}`,"",`This analysis combines a bounded warehouse extraction with the local dataset \`${r.localDataset}\`.`,"",...(u=r.warehouseRelations)!=null&&u.length?[`- Warehouse sources: ${r.warehouseRelations.map(b=>`\`${b}\``).join(", ")}`]:[],`- Join: \`${r.warehouseKey}\` = \`${r.localKey}\``,"- Trust: local mixed-source analysis · review required"].join(`
|
|
2
2
|
`));A.name=g("Analysis context");const d=m("sql",s);return d.name=g(e.title??"Warehouse extraction"),d.mixedSourcePlan=r,d.executionTarget=((f=e.executionTarget)==null?void 0:f.target)==="connection"?e.executionTarget:{target:"connection"},d.datasetRefs=[{id:r.datasetId??r.localDataset,alias:r.localDataset,role:"source"}],[A,d]}const t=m(n?"dql":"sql",n||s);t.name=g(e.title??((l=e.dqlArtifact)==null?void 0:l.name)??"AI analysis"),e.result&&(t.result=e.result,t.status="success",t.executionCount=1),e.chartConfig&&(t.chartConfig=e.chartConfig),e.executionTarget&&(t.executionTarget=e.executionTarget),t.correctionProvenance=S({question:e.question,generatedSql:e.sql??((q=e.dqlArtifact)==null?void 0:q.compiledSql),generatedDql:n,sourceRunId:e.sourceRunId}),e.dqlArtifact&&(t.dqlArtifact={source:e.dqlArtifact.source,sql:e.sql,name:e.dqlArtifact.name,sourcePath:e.dqlArtifact.sourcePath,kind:e.dqlArtifact.kind,metrics:e.dqlArtifact.metrics,dimensions:e.dqlArtifact.dimensions,parameters:e.dqlArtifact.parameters,parameterValues:e.dqlArtifact.parameterValues,persistence:e.dqlArtifact.persistence,trustState:e.dqlArtifact.trustState,compiledSql:e.dqlArtifact.compiledSql??e.sql,...e.question?{question:e.question}:{}},t.dqlParameterValues=e.dqlArtifact.parameterValues);const a=i.filter(r=>new RegExp(`\\b${E(r.alias)}\\b`,"i").test(s)).map(r=>({id:r.id,alias:r.alias,role:r.storageMode==="staged"?"staged":"source",fingerprint:r.fileFingerprint}));return a.length>0&&(t.executionTarget={target:"local"},t.datasetRefs=a,t.dqlArtifact&&(t.dqlArtifact.reviewState="review_required")),[t]}function _(e){return(e??"ai analysis").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)||"ai-analysis"}function v(){const{state:e,dispatch:i}=x();return w.useCallback(async(n,s)=>{var f;const t=I(n,(s==null?void 0:s.datasets)??[]);if(t.length===0)return;if(e.activeFile&&e.activeFile.type!=="block"){let l=s==null?void 0:s.afterId;for(const q of t)i({type:"ADD_CELL",cell:q,...l?{afterId:l}:{}}),l=q.id;h(t[t.length-1].id);return}const a=n.title??((f=n.dqlArtifact)==null?void 0:f.name)??"AI analysis",c=_(a);let o=`notebooks/${c}.dqlnb`;try{o=(await k.createNotebook(c,"blank")).path}catch{}const u={name:o.split("/").pop()??`${c}.dqlnb`,path:o,type:"notebook",folder:"notebooks",isNew:!0};i({type:"FILE_ADDED",file:u}),i({type:"OPEN_FILE",file:u,cells:t,title:a}),h(t[t.length-1].id)},[i,e.activeFile])}export{C as N,S as c,h as f,v as u};
|