@duckcodeailabs/dql-cli 1.12.7 → 1.12.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/dql-notebook/assets/{AgentAnswerCard-BJAnjaLA.js → AgentAnswerCard-D1VcQOTJ.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AgentLogPage-J72WR6hk.js → AgentLogPage-DKvtW4Fq.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildDialog-CHJZfDmp.js → AiBuildDialog-apJ4HoK3.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildResult-Da7_Cn12.js → AiBuildResult-CvNitmsw.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiSidePanel-BY6W_5aC.js → AiSidePanel-B2cqbPJr.js} +1 -1
- package/dist/assets/dql-notebook/assets/AnalyticsHome-D5I-Okbz.js +6 -0
- package/dist/assets/dql-notebook/assets/{AppsView-3k7ftDpd.js → AppsView-DLtjogVz.js} +13 -18
- package/dist/assets/dql-notebook/assets/{BlockStudio-CLX4EUyO.js → BlockStudio-BmNsIfNK.js} +1 -1
- package/dist/assets/dql-notebook/assets/{BusinessArtifactView-3THMNeyO.js → BusinessArtifactView-Bvn5X8uW.js} +1 -1
- package/dist/assets/dql-notebook/assets/{DbtFirstModelingPage-BwBPwtdA.js → DbtFirstModelingPage-DnpVGZJv.js} +1 -1
- package/dist/assets/dql-notebook/assets/{GitPage-CvEki0pe.js → GitPage-C_5u2aCj.js} +1 -1
- package/dist/assets/dql-notebook/assets/{GlobalAiRail-NXdk9kNy.js → GlobalAiRail-ZOHo4H6j.js} +1 -1
- package/dist/assets/dql-notebook/assets/{GovernedContextPage-DILbw-Vr.js → GovernedContextPage-CUaYIqfd.js} +1 -1
- package/dist/assets/dql-notebook/assets/{HelpDocsPage-DgCu4bvY.js → HelpDocsPage-6SmmBvJh.js} +1 -1
- package/dist/assets/dql-notebook/assets/{HomePage-CK3fXTQo.js → HomePage-LDu8z_nW.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDAG-DW_NO3P2.js → LineageDAG-VFSCvevO.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDetailView-VT7DLJOB.js → LineageDetailView-CuGG_JDv.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDrawer-DSTm8aXw.js → LineageDrawer-B2SVsEw1.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineagePathBreadcrumb-DRlAYasJ.js → LineagePathBreadcrumb-qWhGM3bh.js} +1 -1
- package/dist/assets/dql-notebook/assets/{MiniLineageGraph-CR_nhwhZ.js → MiniLineageGraph-BHxUFWDi.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewBlockModal-CJvjYiBF.js → NewBlockModal-oo3fU5OW.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewNotebookModal-BEpPH93n.js → NewNotebookModal-Bl78Nnjz.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NotebookEditor-C7GDFwhF.js → NotebookEditor-BWMX6Xfi.js} +1 -1
- package/dist/assets/dql-notebook/assets/{ReadinessPage-rZiOp2xr.js → ReadinessPage-CL2EJLKo.js} +1 -1
- package/dist/assets/dql-notebook/assets/{SetupOnboarding-BWjhTjPB.js → SetupOnboarding-Cqw2NuAn.js} +1 -1
- package/dist/assets/dql-notebook/assets/{TrustBadge-RvZ9s6OQ.js → TrustBadge-C4jIUuEE.js} +1 -1
- package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-CZjUHLl5.js +83 -0
- package/dist/assets/dql-notebook/assets/{answer-to-notebook-Di227Cd4.js → answer-to-notebook-mhY-MBsX.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-left-BZHDcWHR.js → arrow-left-CwMW-Dnz.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-right-DlM1pC3_.js → arrow-right-CJ_6d0z7.js} +1 -1
- package/dist/assets/dql-notebook/assets/{book-open-text-DBcXFQAu.js → book-open-text-B2q44mou.js} +1 -1
- package/dist/assets/dql-notebook/assets/{bot-BAywbvPm.js → bot-CbsSLtXR.js} +1 -1
- package/dist/assets/dql-notebook/assets/{chevron-up-B_GfKE_F.js → chevron-up-DSMkEFrK.js} +1 -1
- package/dist/assets/dql-notebook/assets/{circle-x-BcxtZ-ym.js → circle-x-C5hi2hCq.js} +1 -1
- package/dist/assets/dql-notebook/assets/{dagre.esm-Bqs0lsEz.js → dagre.esm-BT65gOyC.js} +1 -1
- package/dist/assets/dql-notebook/assets/{external-link-B24Dk9_t.js → external-link-sDmXu1pG.js} +1 -1
- package/dist/assets/dql-notebook/assets/{grip-vertical-D9g31N3j.js → grip-vertical-Ca_E_fRZ.js} +1 -1
- package/dist/assets/dql-notebook/assets/{index-DU7j3Sqk.js → index-CcZ8Dw84.js} +128 -128
- package/dist/assets/dql-notebook/assets/{link-2-B36oR5Bj.js → link-2-DaVaJfdX.js} +1 -1
- package/dist/assets/dql-notebook/assets/{list-tree-B9ZzGc4U.js → list-tree-DMGqPCsV.js} +1 -1
- package/dist/assets/dql-notebook/assets/{maximize-2-BrvQLPoj.js → maximize-2-CVJP65sF.js} +1 -1
- package/dist/assets/dql-notebook/assets/{minimize-2-BrpFmsxS.js → minimize-2-BnsbPUr5.js} +1 -1
- package/dist/assets/dql-notebook/assets/{panel-right-open-B1g1qhh5.js → panel-right-open-BTTos1w4.js} +1 -1
- package/dist/assets/dql-notebook/assets/{pencil-DwywbTqQ.js → pencil-BDR0kEX-.js} +1 -1
- package/dist/assets/dql-notebook/assets/{rotate-ccw-Db_KVs3J.js → rotate-ccw-DrQw5ZrW.js} +1 -1
- package/dist/assets/dql-notebook/assets/{semantic-fields-BIVuvP2l.js → semantic-fields-CgqeBot0.js} +1 -1
- package/dist/assets/dql-notebook/assets/star-DBVkbHOE.js +6 -0
- package/dist/assets/dql-notebook/assets/{triangle-alert-Cne6C2aG.js → triangle-alert-_FtKJhjm.js} +1 -1
- package/dist/assets/dql-notebook/assets/{usePersistedAgentThreadId-D6mtrJ-_.js → usePersistedAgentThreadId-BG1TZXp_.js} +1 -1
- package/dist/assets/dql-notebook/assets/{user-round-DkzxN1xD.js → user-round-DkUToep7.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wand-sparkles-CJUvFtur.js → wand-sparkles-TgacCrJg.js} +1 -1
- package/dist/assets/dql-notebook/assets/{workflow-BOvVTg7R.js → workflow-z-B8gUF9.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wrench-YeSpzZRt.js → wrench-CgXGBYJ-.js} +1 -1
- package/dist/assets/dql-notebook/assets/{x-C6tsHUR7.js → x-FQc3jbQ8.js} +1 -1
- package/dist/assets/dql-notebook/index.html +1 -1
- package/dist/local-runtime.d.ts +16 -0
- package/dist/local-runtime.d.ts.map +1 -1
- package/dist/local-runtime.js +191 -2
- 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/AnalyticsHome-u-buXgdv.js +0 -6
- package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-CGPcpY1B.js +0 -83
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import{g as Ae,r as p,a as re,j as t,b as zt,f as Je,h as xe,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 Pr,S as Fe,ax as Un,c as At,aJ as Ge,P as Ye,D as Fr,G as Yn,aH as Gt,Y as Mt}from"./index-CcZ8Dw84.js";import{S as mt,R as tn,d as Dr}from"./AgentAnswerCard-D1VcQOTJ.js";import{S as Nr,F as et,d as nn,e as Hr,A as Or,u as Qr}from"./usePersistedAgentThreadId-BG1TZXp_.js";import{C as Vr}from"./AiBuildResult-CvNitmsw.js";import{T as Et}from"./triangle-alert-_FtKJhjm.js";import{U as Gr}from"./user-round-DkUToep7.js";import{X as bt}from"./x-FQc3jbQ8.js";import{P as Kr}from"./pencil-BDR0kEX-.js";import{L as tt}from"./list-tree-DMGqPCsV.js";import{W as rn}from"./wrench-CgXGBYJ-.js";import{A as Ur}from"./arrow-right-CJ_6d0z7.js";import{C as Jn}from"./chevron-up-DSMkEFrK.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=Ae("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=Ae("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=Ae("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=Ae("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=Ae("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"}]],Kt=Ae("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"}]],sn=Ae("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"}]],jn=Ae("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=Ae("zap",li),Wt=[{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 Sn({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 re.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=Wt.find(f=>f.mode===n)??Wt[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:wn(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:{...wn(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(zt,{size:12,color:e.textMuted})]}),o?t.jsx("div",{role:"menu",style:ci(e),children:Wt.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 wn(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:Et,needs_attention:Et,review:$r,certified:xe,deprecated:Jr,pending_recertification:Et},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:y=[],certifierVerdict:x,owner:v,actions:g}=e,[R,T]=p.useState(!1),[M,N]=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:Ut(n),children:["grain ",u]}):null]}),s?t.jsx("div",{style:{fontSize:12,color:n.textSecondary,lineHeight:1.5},children:s}):null,o?t.jsx(kn,{open:R,onToggle:()=>T(k=>!k),label:"Governed DQL",t:n,lead:!0,children:t.jsx("pre",{style:Cn(n),children:o})}):null,a?t.jsx(kn,{open:M,onToggle:()=>N(k=>!k),label:o?"Compiled SQL preview":"SQL this block will run",t:n,children:t.jsx("pre",{style:Cn(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(k=>t.jsx("li",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.45},children:k},k))})]}):null,c.length>0||y.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(xe,{size:12,color:n.accent})," Grounded on"]}),c.length>0?t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:c.map(k=>t.jsx("span",{style:Ut(n),children:k},k))}):null,y.slice(0,5).map((k,O)=>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:k.name}),t.jsxs("div",{style:{fontSize:10,color:n.textMuted,marginTop:3},children:[k.kind,k.reason?` · ${k.reason}`:""]}),k.description?t.jsx("div",{style:{fontSize:11,color:n.textMuted,lineHeight:1.35,marginTop:5},children:k.description}):null]},`${k.objectKey??k.name}-${O}`))]}):null,t.jsx(Vr,{t:n,verdict:x}),v?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 ",v]}):null,g?t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:g}):null]})}function kn({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(zt,{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:Ut(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 Ut(e){return{fontSize:10.5,fontWeight:700,color:e.textSecondary,background:e.pillBg,borderRadius:999,padding:"2px 8px",fontFamily:e.fontMono}}function Cn(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 zn(){return t.jsx("span",{style:{color:"#ff7b72",marginLeft:2},children:"*"})}function Ft(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 qn({cell:e,onClose:n,onSaved:r,initialContent:i,initialName:s,initialDescription:o,initialTags:a,initialDomain:u,initialOwner:d}){var V;const{state:m,dispatch:f}=qt(),l=Kn[m.themeMode],c=p.useRef(null),[y,x]=p.useState(s||e.name||"new_block"),[v,g]=p.useState(u??""),[R,T]=p.useState(d??""),[M,N]=p.useState(o??m.notebookMetadata.description??""),[k,O]=p.useState((a??m.notebookMetadata.categories??[]).join(", ")),[B,E]=p.useState(i??e.content),[F,D]=p.useState(""),[$,b]=p.useState(""),[w,U]=p.useState([]),[W,G]=p.useState(!1),[Y,ee]=p.useState(null),J=p.useMemo(()=>vi(B),[B]),Q=p.useMemo(()=>k.split(",").map(z=>z.trim()).filter(Boolean),[k]),le=[{id:"has-name",label:"Block has name",severity:"error",passed:!!y.trim()},{id:"has-owner",label:"Block has owner",severity:"error",passed:!!R.trim()},{id:"has-description",label:"Description",severity:"warning",passed:!!M.trim()},{id:"has-domain",label:"Domain",severity:"warning",passed:!!v.trim()},{id:"has-tags",label:"Has at least one tag",severity:"warning",passed:Q.length>0},{id:"has-llm-context",label:"Has LLM context (for agents)",severity:"warning",passed:!!F.trim()}],K=le.some(z=>z.severity==="error"&&!z.passed);p.useEffect(()=>{var z;(z=c.current)==null||z.focus()},[]),p.useEffect(()=>{const z=ie=>{ie.key==="Escape"&&n()};return document.addEventListener("keydown",z),()=>document.removeEventListener("keydown",z)},[n]);const H=m.semanticLayer.domains,C=`${v.trim()?`blocks/${Ft(v)}/`:"blocks/"}${Ft(y)||"new-block"}.dql`,q=async()=>{var z,ie,ce;if(K){ee("Enter the block name and owner before saving.");return}if(!B.trim()){ee("Block content is required.");return}G(!0),ee(null);try{const te=$.split(`
|
|
47
|
+
`).map(j=>j.trim()).filter(Boolean),He=w.map(j=>({question:j.question.trim(),sql:j.sql.trim()||void 0})).filter(j=>j.question),ve=await re.saveAsBlock({cellId:e.id,notebookPath:((z=m.activeFile)==null?void 0:z.path)??null,name:y.trim(),domain:v.trim()||void 0,owner:R.trim()||void 0,content:B,description:M.trim()||void 0,tags:Q,metricRefs:J,llmContext:F.trim()||void 0,examples:He.length>0?He:void 0,invariants:te.length>0?te:void 0,reviewRequired:!!((ie=e.datasetRefs)!=null&&ie.length),datasetRefs:e.datasetRefs,lineage:(ce=e.dqlArtifact)==null?void 0:ce.lineage}),Re={name:`${Ft(y)||"new-block"}.dql`,path:ve.path,type:"block",folder:"blocks"};m.files.some(j=>j.path===ve.path)||f({type:"FILE_ADDED",file:Re});const we=await re.openBlockStudio(ve.path);f({type:"OPEN_BLOCK_STUDIO",file:Re,payload:we}),r==null||r({...ve,name:y.trim()}),n()}catch(te){ee(te instanceof Error?te.message:String(te))}finally{G(!1)}},_={width:"100%",background:l.inputBg,border:`1px solid ${Y?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:z=>{z.target===z.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(zn,{})]}),t.jsx("input",{ref:c,value:y,onChange:z=>x(z.target.value),style:_})]}),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:v,onChange:z=>g(z.target.value),list:"semantic-domain-options",style:_,placeholder:"finance"}),t.jsx("datalist",{id:"semantic-domain-options",children:H.map(z=>t.jsx("option",{value:z},z))})]})]}),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(zn,{})]}),t.jsx("input",{value:R,onChange:z=>T(z.target.value),style:_,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:k,onChange:z=>O(z.target.value),style:_,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:M,onChange:z=>N(z.target.value),style:_})]}),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:F,onChange:z=>D(z.target.value),rows:3,placeholder:'One paragraph. E.g. "Monthly revenue recognized from closed-won deals, grouped by billing month. Excludes refunds."',style:{..._,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:z=>b(z.target.value),rows:2,placeholder:`Revenue is never negative
|
|
48
|
+
Each row is a unique month`,style:{..._,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)"}),w.map((z,ie)=>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:z.question,onChange:ce=>{const te=[...w];te[ie]={...te[ie],question:ce.target.value},U(te)},placeholder:"What was revenue last month?",style:_}),t.jsx("input",{value:z.sql,onChange:ce=>{const te=[...w];te[ie]={...te[ie],sql:ce.target.value},U(te)},placeholder:"Optional SQL snippet",style:{..._,fontFamily:l.fontMono,fontSize:12}})]}),t.jsx("button",{type:"button",onClick:()=>U(w.filter((ce,te)=>te!==ie)),style:{background:"transparent",border:`1px solid ${l.cellBorder}`,borderRadius:6,color:l.textMuted,cursor:"pointer",fontSize:12,padding:"0 10px"},children:"×"})]},ie)),t.jsx("button",{type:"button",onClick:()=>U([...w,{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:le.map(z=>{const ie=z.passed?"#3fb950":z.severity==="error"?"#ff7b72":"#e3b341",ce=z.passed?"✓":z.severity==="error"?"✕":"!";return t.jsxs("span",{title:z.passed?`${z.label} — passed`:`${z.label} — ${z.severity}`,style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,fontFamily:l.font,color:ie,background:`${ie}18`,border:`1px solid ${ie}55`,borderRadius:999,padding:"2px 10px"},children:[t.jsx("span",{style:{fontWeight:700},children:ce}),z.label]},z.id)})})]}),t.jsx("div",{style:{fontSize:12,color:l.textMuted,fontFamily:l.fontMono,padding:"8px 12px",background:l.pillBg,borderRadius:6},children:C}),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:B,onChange:z=>E(z.target.value),style:{..._,minHeight:220,resize:"vertical",fontFamily:l.fontMono,lineHeight:1.5}})]}),J.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:"}),J.map(z=>t.jsx("span",{style:{fontSize:11,color:l.accent,fontFamily:l.fontMono,background:`${l.accent}18`,borderRadius:999,padding:"2px 8px"},children:z},z))]}),Y&&t.jsx("div",{style:{fontSize:12,color:l.error,fontFamily:l.font},children:Y})]}),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:(V=e.datasetRefs)!=null&&V.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:q,disabled:W||K,title:K?"Fix governance errors to enable Save":void 0,style:{background:l.accent,border:`1px solid ${l.accent}`,borderRadius:6,color:"#fff",cursor:W||K?"not-allowed":"pointer",fontSize:13,fontFamily:l.font,padding:"7px 20px",opacity:W||K?.5:1},children:W?"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=y=>r(d.name,y),c=d.type==="boolean"?t.jsxs("select",{"aria-label":d.name,value:String(f??""),onChange:y=>l(y.target.value),style:An(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:y=>l(y.target.value),style:An(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 An(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(Rn(r));return Yt({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:Rn(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,y,x;const n=e.run.artifacts.find(v=>v.kind==="answer")??e.run.artifacts.find(v=>v.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(v=>!!(v&&typeof v=="object"&&!Array.isArray(v))).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=ne(r==null?void 0:r.sourceCertifiedBlock)??((n==null?void 0:n.kind)==="answer"?ne(n.ref):void 0)??ne((c=pe(r==null?void 0:r.block))==null?void 0:c.name);return Yt({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:ne((y=pe(r==null?void 0:r.route))==null?void 0:y.label)??ne((x=pe(r==null?void 0:r.route))==null?void 0:x.tier),trustLabel:ne(r==null?void 0:r.trustLabel),reviewStatus:ne(r==null?void 0:r.reviewStatus),certification:ne(r==null?void 0:r.certification),contextPackId:ne(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:Ai(r),cascade:Ri(r),topN:nr(u),result:s.length>0||o.length>0?Yt({columns:s,rowsSample:o,dimensionValues:d,measureColumns:m,rowCount:zi(i)}):void 0,sourceSql:qi(r,i)})}function Rn(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)=>_n(o)-_n(s))[0]}function _n(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 zi(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 ne(e==null?void 0:e.proposedSql)??ne(e==null?void 0:e.sql)??ne(n==null?void 0:n.sql)??ne((r=pe(e==null?void 0:e.query))==null?void 0:r.sql)??ne((i=pe(e==null?void 0:e.plan))==null?void 0:i.sql)}function Ai(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=ne(n.terminalLane),i=ne(n.routeTier);if(!(!r&&!i))return{terminalLane:r,routeTier:i,label:ne(n.label),ref:ne(n.ref),artifactKind:ne(n.artifactKind),refusalCode:ne(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 ne(n.name)??ne(n.field)??ne(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 ne(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function Yt(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:In(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=In(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=Pr(l).map(g=>{var R,T,M;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"}}:((T=g.binding)==null?void 0:T.kind)==="limit"?{binding:{kind:"limit"}}:((M=g.binding)==null?void 0:M.kind)==="sql_value"?{binding:{kind:"sql_value"}}:{binding:void 0}}}),{executionReceipt:y,compiledSql:x,...v}=e;return{artifact:{...v,source:l,parameters:c,parameterValues:{...e.parameterValues??{},[u]:i}},parameterName:u}}function In(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){return e.map(n=>{var r;return n.kind==="user"?{role:"user",text:n.text}:{role:"assistant",text:((r=n.run.answer)==null?void 0:r.trim())||n.run.summary}}).slice(-12)}const on="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 Pi({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:y,onThreadIdChange:x,audience:v="analyst",autoRun:g,onInsertSql:R,onInsertDql:T,onReplaceDql:M,onArtifactReady:N,onOpenBlock:k,onOpenResearch:O,onOpenApp:B,onRunningChange:E,answerFirstCards:F=!1,insertDqlActionLabel:D,replaceDqlActionLabel:$,askLayout:b=!1}){const w=Kn[e],U=p.useRef(void 0),[W,G]=p.useState(f),[Y,ee]=p.useState(l??[]),[J,Q]=p.useState([]),[le,K]=p.useState(""),[H,C]=p.useState(!1),[q,_]=p.useState(null),[V,z]=p.useState(null),[ie,ce]=p.useState(null),[te,He]=p.useState(()=>Fi()),[ve,Re]=p.useState([]),[we,j]=p.useState(),de=p.useCallback(h=>{He(h);try{window.localStorage.setItem(or,h)}catch{}},[]),je=p.useRef(null),gn=p.useRef(f),xn=p.useRef(null),$e=p.useRef(null),me=p.useRef(null),Le=p.useRef(null),fe=p.useRef(null),_e=p.useRef(0),Se=d==null?void 0:d.executionTarget,hn=Se&&typeof Se=="object"&&!Array.isArray(Se)&&Se.target==="connection"&&typeof Se.connectionName=="string"?String(Se.connectionName):void 0,Ar=Se&&typeof Se=="object"&&!Array.isArray(Se)&&Se.target==="local";p.useEffect(()=>{let h=!1;return re.getConnections().then(S=>{if(h)return;const I=Object.keys(S.connections??{}).sort((L,Z)=>L.localeCompare(Z));Re(I),j(lr(I,S.default,hn))}).catch(()=>{h||(Re([]),j(void 0))}),()=>{h=!0}},[hn]);const yn=p.useCallback(h=>{j(h)},[]),[Ie,Tt]=p.useState(null),[ke,Oe]=p.useState(null),[Rr,Bt]=p.useState(""),mn=p.useRef(null),ot=p.useRef(null);p.useEffect(()=>{!f||H||f!==gn.current&&(gn.current=f,G(f))},[f,H]);const _r=p.useMemo(()=>ir(Y),[Y]),lt=p.useRef(c);lt.current=c;const at=p.useRef(N);at.current=N,p.useEffect(()=>{var h;(h=lt.current)==null||h.call(lt,Y)},[Y]);const he=p.useRef(y),ct=p.useRef(x);ct.current=x;const $t=p.useCallback((h,S)=>{var I;if(fe.current!==null&&(window.clearTimeout(fe.current),fe.current=null),Dt(h.id),me.current===h.id&&(me.current=null),Le.current=null,_(null),Q(h.events.slice(-8)),K(""),ee(L=>{if(L.some(se=>se.kind==="run"&&se.run.id===h.id))return L.map(se=>se.kind==="run"&&se.run.id===h.id?{...se,id:h.id,run:h}:se);const Z=L.some(se=>se.kind==="user"&&se.text===S.question);return[...L,...Z?[]:[{kind:"user",id:`${h.id}-question`,text:S.question}],{kind:"run",id:h.id,run:h}]}),h.route!=="certified_answer"){const L=fn(h);L&&((I=at.current)==null||I.call(at,L,h))}},[]),Ue=p.useCallback(h=>{fe.current!==null&&window.clearTimeout(fe.current);const S=++_e.current;me.current=h.id,Le.current=h,_(h),C(!0),K(""),Q([]);const I=async()=>{if(!(S!==_e.current||me.current!==h.id))try{const L=await re.getAgentRunState(h.id);if(S!==_e.current||me.current!==h.id)return;if(L.lifecycleState==="terminal"){$t(L.run,h),C(!1);return}Q(L.progress.events.slice(-8)),fe.current=window.setTimeout(()=>{I()},600)}catch{if(S!==_e.current||me.current!==h.id)return;fe.current=window.setTimeout(()=>{I()},1200)}};return I(),()=>{S===_e.current&&(_e.current+=1),fe.current!==null&&(window.clearTimeout(fe.current),fe.current=null)}},[$t]),bn=p.useRef(!1);p.useEffect(()=>{if(!y||bn.current)return;bn.current=!0,he.current??(he.current=y);let h=!1;return re.getAgentThread(y).then(({turns:S,runs:I})=>{h||S.length===0||ee(L=>{const Z=L.filter(oe=>oe.kind==="run").length,se=ar(S,I);if(S.length>=Z)return se;const ye=new Map(se.flatMap(oe=>oe.kind==="run"?[[oe.run.id,oe.run]]:[]));return L.map(oe=>oe.kind==="run"&&ye.has(oe.run.id)?{...oe,run:ye.get(oe.run.id)}:oe)})}).catch(()=>{!h&&he.current===y&&(he.current=void 0)}),()=>{h=!0}},[y]),p.useEffect(()=>{const h=Ln(y??he.current);if(!(!h||$e.current))return Ue(h)},[Ue,y]),p.useEffect(()=>{const h=()=>{if(document.visibilityState!=="visible"||$e.current)return;const S=Le.current??Ln(y??he.current);S&&Ue(S)};return document.addEventListener("visibilitychange",h),()=>document.removeEventListener("visibilitychange",h)},[Ue,y]);const Ce=async(h,S,I)=>{var xt;const L=(h??W).trim();if(!L||H)return;const Z=S??U.current??m;U.current=void 0;const se={kind:"user",id:Dn("user"),text:L};ee(ue=>[...ue,se]),G(""),ce(null),C(!0),Q([]),K("");const ye=new AbortController;$e.current=ye;const oe=Dn("run");let ge={id:oe,question:L,threadId:he.current,startedAt:new Date().toISOString()};me.current=oe,Le.current=ge,_(ge),$n(ge);let Me=!1,gt=!1;try{if(!he.current)try{const ze=await re.createAgentThread({surface:b?"ask":typeof(d==null?void 0:d.surface)=="string"?d.surface:a?"notebook":"agent",title:L,...a?{notebookPath:a}:{}});he.current=ze.id,(xt=ct.current)==null||xt.call(ct,ze.id),ge={...ge,threadId:ze.id},Le.current=ge,_(ge),$n(ge)}catch{}const ue={question:L,...I?{selectedEvidenceId:I}:{},requestedMode:Z,audience:v,selectedObject:u??(a?{kind:"notebook",path:a}:void 0),...Ar?{executionTarget:{target:"local"}}:we?{executionTarget:{target:"connection",connectionName:we}}:{},workspaceContext:{...d??{},...a?{notebookPath:a}:{}},conversationContext:wi(Y),history:_r,thinkingMode:te,runId:oe,...he.current?{threadId:he.current}:{}},Br=await re.createAgentRunStream(ue,ze=>{Me=!0,ze.kind==="event"?Q(Lt=>[...Lt,ze.event].slice(-8)):ze.kind==="answer-delta"?K(Lt=>Lt+ze.delta):Q(ze.run.events.slice(-8))},ye.signal);$t(Br,ge)}catch(ue){ye.signal.aborted||(ce(ue instanceof Error?ue.message:String(ue)),G(L),Me?(gt=!0,Ue(ge)):(Dt(oe),me.current===oe&&(me.current=null),Le.current=null,_(null)))}finally{$e.current===ye&&($e.current=null),gt||C(!1)}},dt=()=>{Ce()},vn=()=>{var S;const h=me.current;h&&re.cancelAgentRun(h).catch(()=>{}),(S=$e.current)==null||S.abort(),_e.current+=1,fe.current!==null&&window.clearTimeout(fe.current),Dt(h??""),me.current=null,Le.current=null,_(null),K(""),Q([]),C(!1),ce("Stopped. No answer or draft was saved.")},ut=p.useRef(E);ut.current=E,p.useEffect(()=>{var h;(h=ut.current)==null||h.call(ut,H)},[H]),p.useEffect(()=>{!(g!=null&&g.text)||H||xn.current!==g.nonce&&(xn.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,H]),p.useEffect(()=>()=>{var h;(h=$e.current)==null||h.abort(),_e.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=(h,S)=>{var I,L;if(S.id==="save-dql-block"){const Z=Be(h),se=((I=Z==null?void 0:Z.source)==null?void 0:I.trim())??((L=Ne(h))==null?void 0:L.trim());if(!se){ce("This answer does not include a reusable DQL or SQL artifact yet.");return}z({runId:h.id,source:se,name:(Z==null?void 0:Z.name)??`${h.question.slice(0,48).trim()||"saved_answer"}`,dqlArtifact:Z});return}if(S.id==="research-deeper"){Ce(h.question,"research");return}if(S.id.startsWith("suggest-question")){Ce(S.label,"auto");return}U.current=cs(S.route),G(ds(h,S.route)),requestAnimationFrame(()=>{var Z;return(Z=je.current)==null?void 0:Z.focus()})},Ir=p.useCallback((h,S,I="trust")=>{Tt({runId:h,artifactId:S,tab:I})},[]),Tr=p.useCallback(h=>{var L,Z;const S=h.trim();if(!S)return;const I=(L=ke==null?void 0:ke.text)==null?void 0:L.trim();Oe(null),Bt("");try{(Z=window.getSelection())==null||Z.removeAllRanges()}catch{}Ce(I?`${S}
|
|
50
|
+
|
|
51
|
+
Regarding: "${I}"`:S),requestAnimationFrame(()=>{ot.current&&(ot.current.scrollTop=ot.current.scrollHeight)})},[ke,Ce]);if(p.useEffect(()=>{if(!b)return;const h=I=>{const L=I.target;L&&L.closest("[data-selpop]")||window.setTimeout(()=>{const Z=window.getSelection(),se=Z&&Z.rangeCount?Z.toString().trim():"";if(!se||se.length<3){Oe(ue=>ue&&null);return}const ye=Z.anchorNode,oe=ye&&(ye.nodeType===1?ye:ye.parentElement),ge=oe==null?void 0:oe.closest("[data-followup]");if(!ge){Oe(ue=>ue&&null);return}const Me=Z.getRangeAt(0).getBoundingClientRect(),gt=Math.max(12,Math.min(Me.left,window.innerWidth-340)),xt=Me.bottom+176>window.innerHeight?Math.max(12,Me.top-176):Me.bottom+8;Oe({text:se.slice(0,220),source:ge.getAttribute("data-followup")||"answer",left:gt,top:xt}),Bt(""),requestAnimationFrame(()=>{var ue;return(ue=mn.current)==null?void 0:ue.focus()})},0)},S=I=>{I.key==="Escape"&&Oe(null)};return document.addEventListener("mouseup",h),document.addEventListener("keydown",S),()=>{document.removeEventListener("mouseup",h),document.removeEventListener("keydown",S)}},[b]),b){const h=Ie?(()=>{const S=Y.find(L=>L.kind==="run"&&L.run.id===Ie.runId);if(!S||S.kind!=="run")return null;const I=S.run.artifacts.find(L=>L.id===Ie.artifactId);return I?{run:S.run,artifact:I}:null})():null;return t.jsxs("div",{style:{display:"flex",height:"100%",minHeight:0,flex:1,minWidth:0,width:"100%",background:"var(--bg-canvas)"},children:[V?t.jsx(qn,{cell:{id:`agent-${V.runId}`,type:V.dqlArtifact?"dql":"sql",content:V.source,name:V.name,status:"success",...V.dqlArtifact?{dqlArtifact:V.dqlArtifact}:{}},initialContent:V.source,initialName:V.name,onClose:()=>z(null),onSaved:()=>z(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(Fe,{size:13})}),t.jsx("span",{style:{fontSize:13.5,fontWeight:650,color:w.textPrimary,whiteSpace:"nowrap"},children:n==="AI Copilot"?"Ask your data":n}),t.jsx("div",{style:{flex:1}}),t.jsx("span",{style:{fontSize:11,color:w.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:[Y.length===0&&!H?t.jsxs("div",{style:{margin:"auto 0",display:"grid",gap:14,justifyItems:"center",textAlign:"center",color:w.textSecondary,paddingTop:40},children:[t.jsx("div",{style:Nn(w),children:t.jsx(Fe,{size:20})}),t.jsx("div",{style:{fontSize:13.5,lineHeight:1.5,maxWidth:400,color:w.textSecondary},children:o??Tn}),t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap",justifyContent:"center",maxWidth:520},children:(s??Bn).map(S=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>{G(S.prompt),requestAnimationFrame(()=>{var I;return(I=je.current)==null?void 0:I.focus()})},style:kt(w),children:S.label},S.label))})]}):null,Y.map(S=>S.kind==="user"?t.jsx("div",{style:Yi(w),children:S.text},S.id):t.jsx(Fn,{run:S.run,t:w,themeMode:e,appContext:pt,selectedArtifactId:(Ie==null?void 0:Ie.runId)===S.run.id?Ie.artifactId:void 0,onOpenArtifact:(I,L)=>Ir(S.run.id,I,L),onOpenApp:B,onInsertSql:R,onInsertDql:T,onOpenBlock:k,onOpenResearch:O,onSelectClarification:I=>{const L=yt(I);Ce(L.question,void 0,L.selectedEvidenceId)},onNextAction:I=>ft(S.run,I)},S.id)),H&&t.jsx(En,{events:J,t:w,streamingAnswer:le,thinkingMode:te,backgroundRun:q})]}),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:[ie?t.jsx("div",{style:{color:w.error,fontSize:12,marginBottom:8},children:ie}):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:w.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:w.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:W,onChange:S=>{G(S.target.value),U.current=void 0},rows:2,placeholder:"Ask anything about your data…",onKeyDown:S=>{S.key==="Enter"&&!S.shiftKey&&(S.preventDefault(),dt())},style:{border:"none",background:"transparent",resize:"none",outline:"none",boxShadow:"none",padding:"13px 15px 4px",fontSize:13.5,lineHeight:1.5,color:w.textPrimary,fontFamily:w.font}}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 10px 10px 12px"},children:[t.jsx(Sn,{t:w,value:te,onChange:de}),t.jsx(Mn,{names:ve,value:we,onChange:yn,t:w}),t.jsx("div",{style:{flex:1}}),H?t.jsxs("button",{type:"button",className:"dql-hover",onClick:vn,title:"Stop the active agent run",style:{height:34,padding:"0 12px",borderRadius:10,border:`1px solid ${w.error}`,background:w.btnBg,color:w.error,display:"inline-flex",alignItems:"center",gap:6,cursor:"pointer",fontFamily:w.font,fontSize:12.5,fontWeight:600},children:[t.jsx(jn,{size:13,fill:"currentColor"})," Stop"]}):null,t.jsx("button",{type:"button",className:"dql-hover dql-lift",title:"Ask",onClick:dt,disabled:!W.trim()||H,style:{width:34,height:34,borderRadius:10,border:"none",background:W.trim()&&!H?"var(--accent)":"var(--bg-4)",color:"#fff",display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:W.trim()&&!H?"pointer":"default",boxShadow:W.trim()&&!H?"0 1px 5px rgba(107,93,211,0.3)":"none"},children:H?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:w.textMuted,marginTop:8},children:"Every answer is grounded in your certified metrics and dbt lineage."})]})]})]}),h?t.jsx(ts,{run:h.run,artifact:h.artifact,tab:Ie.tab,t:w,appContext:pt,onOpenApp:B,onChangeTab:S=>Tt(I=>I&&{...I,tab:S}),onClose:()=>Tt(null),onSaveBlock:()=>ft(h.run,{id:"save-dql-block",label:"Save as block",route:"dql_block_draft"}),onInsertSql:R,onInsertDql:T}):null,ke?t.jsx(ns,{t:w,text:ke.text,source:ke.source,left:ke.left,top:ke.top,draft:Rr,inputRef:mn,onDraftChange:Bt,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:w.cellBg},children:[V?t.jsx(qn,{cell:{id:`agent-${V.runId}`,type:V.dqlArtifact?"dql":"sql",content:V.source,name:V.name,status:"success",...V.dqlArtifact?{dqlArtifact:V.dqlArtifact}:{}},initialContent:V.source,initialName:V.name,onClose:()=>z(null),onSaved:()=>z(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:[Y.length===0&&!H?t.jsxs("div",{style:{margin:"auto 0",display:"grid",gap:14,justifyItems:"center",textAlign:"center",color:w.textSecondary},children:[t.jsx("div",{style:Nn(w),children:t.jsx(Fe,{size:20})}),t.jsx("div",{style:{fontSize:13,lineHeight:1.5,maxWidth:380,color:w.textSecondary},children:o??Tn}),t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap",justifyContent:"center",maxWidth:520},children:(s??Bn).map(h=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>{G(h.prompt),requestAnimationFrame(()=>{var S;return(S=je.current)==null?void 0:S.focus()})},style:kt(w),children:h.label},h.label))})]}):null,Y.map(h=>h.kind==="user"?t.jsx("div",{style:Ss(w),children:h.text},h.id):F?t.jsx(Fn,{run:h.run,t:w,themeMode:e,appContext:pt,onOpenApp:B,onInsertSql:R,onInsertDql:T,onReplaceDql:M,insertDqlActionLabel:D,replaceDqlActionLabel:$,onOpenBlock:k,onOpenResearch:O,onSelectClarification:S=>{const I=yt(S);Ce(I.question,void 0,I.selectedEvidenceId)},onNextAction:S=>ft(h.run,S)},h.id):t.jsx(Ki,{run:h.run,t:w,themeMode:e,appContext:pt,onOpenApp:B,onInsertSql:R,onInsertDql:T,onOpenBlock:k,onOpenResearch:O,onSelectClarification:S=>{const I=yt(S);Ce(I.question,void 0,I.selectedEvidenceId)},onNextAction:S=>ft(h.run,S)},h.id)),H&&t.jsx(En,{events:J,t:w,streamingAnswer:le,thinkingMode:te,backgroundRun:q})]}),ie?t.jsx("div",{style:{margin:"0 16px 8px",color:w.error,fontSize:12},children:ie}):null,t.jsxs("div",{style:{padding:"10px 16px 14px",borderTop:`1px solid ${w.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:w.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:w.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(Mn,{names:ve,value:we,onChange:yn,t:w}),t.jsx(Sn,{t:w,value:te,onChange:de})]})]}),t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-end"},children:[t.jsx("textarea",{ref:je,value:W,onChange:h=>{G(h.target.value),U.current=void 0},rows:2,placeholder:"Ask anything about your data…",onKeyDown:h=>{h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),dt())},style:ms(w)}),t.jsxs("button",{type:"button",className:"dql-hover dql-lift",onClick:dt,disabled:!W.trim()||H,style:Hn(w,!!W.trim()&&!H),children:[H?t.jsx(Pe,{size:15,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(Nr,{size:15}),t.jsx("span",{children:H?"Working":"Ask"})]}),H?t.jsxs("button",{type:"button",className:"dql-hover",onClick:vn,style:{...Hn(w,!0),background:w.btnBg,borderColor:w.error,color:w.error},title:"Stop the active agent run",children:[t.jsx(jn,{size:13,fill:"currentColor"}),t.jsx("span",{children:"Stop"})]}):null]})]})]})}const Tn="Ask a question — every answer is grounded in your certified metrics and dbt lineage. Use Research deeper on any answer for a slower investigation.",Bn=[{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 ln(){try{const e=JSON.parse(window.localStorage.getItem(on)??"[]");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 $n(e){try{const n=ln().filter(r=>r.id!==e.id);window.localStorage.setItem(on,JSON.stringify([...n,e].slice(-12)))}catch{}}function Dt(e){try{const n=ln().filter(r=>r.id!==e);window.localStorage.setItem(on,JSON.stringify(n))}catch{}}function Ln(e){const n=ln().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 Mn({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(Fr,{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 Fi(){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((y,x)=>[y,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 Jt(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=Jt(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 En({events:e,t:n,streamingAnswer:r,thinkingMode:i,backgroundRun:s}){var x;const[o,a]=p.useState(()=>Date.now());p.useEffect(()=>{const v=window.setInterval(()=>a(Date.now()),1e3);return()=>window.clearInterval(v)},[]);const u=(s==null?void 0:s.startedAt)??((x=e.find(v=>v.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,Jt(e),e.some(v=>v.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(Jt(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(Wn,{}),t.jsx("span",{style:{fontSize:13,lineHeight:1.4},children:"Replying…"})]});const c=ur(e,!!s),y=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(v=>t.jsxs("div",{className:"dql-agent-activity",style:{display:"flex",alignItems:"center",gap:9,minHeight:18,color:v.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:v.state==="active"?n.accent:n.textMuted},children:v.state==="active"?t.jsx(Wn,{}):t.jsx(Je,{size:13,strokeWidth:2.2})}),t.jsxs("span",{style:{fontSize:12.5,lineHeight:1.4,fontWeight:v.state==="active"?620:450},children:[v.label,v.state==="active"?"…":""]})]},v.id)),y?t.jsx("span",{style:{paddingLeft:25,fontSize:10.5,lineHeight:1.4,color:n.textMuted},children:y}):null]})}function Wn(){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(zt,{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 b=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:[b?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(w=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>f(w),style:kt(n),children:w.label},w.id))}):null]})}const c=e.steps??[],y=c.length>1,x=(($=e.plan)==null?void 0:$.source)==="llm",v=pn(e),g=dn(e),R=it(e),T=e.route==="certified_answer"||e.route==="generated_answer",M=e.nextActions.some(b=>b.route==="research"),N=T&&R&&!M,k=Be(e),O=R&&!(k!=null&&k.sourcePath)&&!!((k==null?void 0:k.source)??Ne(e)),B=Date.parse(e.startedAt),E=Date.parse(e.completedAt),F=Number.isFinite(B)&&Number.isFinite(E)?Math.max(0,Math.round((E-B)/1e3)):0,D=dr(F,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(xe,{size:12,color:n.success,style:{flex:"0 0 auto",marginTop:1}}):e.trustState==="governed"||e.trustState==="grounded"?t.jsx(xe,{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||y||e.repairAttempts>0?t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[x?t.jsx(Qt,{t:n,icon:t.jsx(tt,{size:11}),label:"AI plan",tone:"accent"}):null,y?t.jsx(Qt,{t:n,icon:t.jsx(Kt,{size:11}),label:`${c.length} steps`,tone:"muted"}):null,e.repairAttempts>0?t.jsx(Qt,{t:n,icon:t.jsx(rn,{size:11}),label:`${e.repairAttempts} repair${e.repairAttempts>1?"s":""}`,tone:"warning"}):null]}):null,e.summary&&!(e.answer&&us(Te(e.summary),Ve(e.answer)))?t.jsx("div",{style:{fontSize:12.5,lineHeight:1.45,color:n.textSecondary},children:Te(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}),v.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:"}),v.map(b=>t.jsxs("span",{style:Cr(n,b.certified),children:[b.certified?t.jsx(xe,{size:11}):t.jsx(et,{size:11}),t.jsx("span",{children:b.label})]},b.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(b=>t.jsx(br,{artifact:b,t:n,themeMode:r,onInsertSql:o,onInsertDql:a,sourceRunId:e.id,sourceQuestion:e.question,onOpenBlock:u,onOpenResearch:d,onOpenApp:s,onNextAction:f},b.id))}):null,y?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,D?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})," ",D.title]}),t.jsx("span",{style:{fontSize:10.5,color:n.textMuted,lineHeight:1.45},children:D.detail})]}):null,R||N||e.nextActions.length>0?t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[R?t.jsx(cn,{run:e,t:n,appContext:i,onOpenApp:s}):null,O?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(sn,{size:11})," Save as block"]}):null,N?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(b=>b.id!=="pin-to-app"&&b.id!=="research-deeper"&&b.id!=="confirm-app-build"&&b.id!=="request-certification").map(b=>t.jsx("button",{type:"button",className:"dql-hover",onClick:()=>f(b),style:X(n),children:b.label},b.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 Ee(e){return At(e,{variant:"ghost",size:"sm"})}function Nt(e,n){return e.kind==="app_proposal"||e.kind==="dql_block_draft"||e.kind==="research_run"||!!It(n)}function Rt(e,n){var a,u;const r=[],i=De(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=Te(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 P(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=P(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=ae(s),a=P(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=P(o.analysisPlan)??P(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 an(e,n){var i;const r=ae(n);return _t(r)?"how":(i=Be(e)??st(r))!=null&&i.source?"dql":Ne(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=ae(n),u=De(a);if(!u)return null;const d=Sr(a,u),m=an(e,n),f=Be(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:Rt(n,a)})]}),t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>o(m),style:Ee(i),children:[t.jsx(tt,{size:12})," Inspect"]})]}),f?t.jsx(yr,{artifact:f,certifiedBlockName:l,initialResult:u,initialChartConfig:d,payload:a,t:i,themeMode:s,embedded:!0}):t.jsx(tn,{result:u,themeMode:s,t:i,chartConfig:d,embedded:!0,tabLabels:{table:"Results",chart:"Visualization"}})]})}function Fn({run:e,t:n,themeMode:r,appContext:i,selectedArtifactId:s,onOpenArtifact:o,onOpenApp:a,onInsertSql:u,onInsertDql:d,onReplaceDql:m,insertDqlActionLabel:f,replaceDqlActionLabel:l,onOpenBlock:c,onOpenResearch:y,onSelectClarification:x,onNextAction:v}){const{dispatch:g}=qt(),[R,T]=p.useState(!1),M=o??(()=>g({type:"OPEN_AGENT_LOG",run:e}));if(e.route==="conversation"){const q=e.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:[q?t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:10.5,color:n.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: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(_=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>v(_),style:kt(n),children:_.label},_.id))}):null]})}const N=e.trustState==="certified",k=e.status==="blocked",O=e.status==="needs_clarification",B=k||O?void 0:e.answer,E=k?"Blocked — no answer produced":O?"Needs clarification":N?"Certified answer":"AI-generated answer",F=k?qr(e):void 0,D=e.evaluations.filter(q=>q.severity==="info").length,$=pn(e),b=e.artifacts.filter(q=>{const _=ae(q);return!Nt(q,_)&&!!De(_)}),w=new Set(b.map(q=>q.id)),U=e.artifacts.filter(q=>!Nt(q,ae(q))&&!w.has(q.id)),W=e.artifacts.filter(q=>Nt(q,ae(q))),G=b[0]??U[0]??e.artifacts[0],Y=it(e),ee=e.route==="certified_answer"||e.route==="semantic_answer"||e.route==="generated_answer",J=e.nextActions.some(q=>q.route==="research"),Q=ee&&Y&&!J,le=Be(e),K=Y&&!(le!=null&&le.sourcePath)&&!!((le==null?void 0:le.source)??Ne(e)),H=f&&d||l&&m?fn(e):void 0,C=()=>{var _;const q=B?Ve(B):F??e.summary;q&&((_=navigator.clipboard)==null||_.writeText(q).catch(()=>{}),T(!0),window.setTimeout(()=>T(!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:[k?t.jsx(Ge,{size:14,color:n.error}):N?t.jsx(xe,{size:14,color:n.success}):t.jsx(Fe,{size:14,color:n.accent}),t.jsx("span",{style:{fontSize:12,fontWeight:650,color:k?n.error:n.textSecondary},children:E}),N&&$[0]?t.jsxs("span",{style:{fontSize:11,color:n.textMuted},children:["from ",t.jsx("span",{style:{color:n.accent,fontWeight:600},children:$[0].label})]}):!k&&G&&D>0?t.jsxs("button",{type:"button",onClick:()=>M(G.id,"trust"),style:{fontSize:11,color:n.textMuted,background:"none",border:"none",cursor:"pointer",padding:0,fontFamily:n.font,display:"inline-flex",alignItems:"center",gap:4},children:[t.jsx(Je,{size:11,color:n.success})," ",D," check",D===1?"":"s"," passed"]}):null]}),B?t.jsx("div",{"data-followup":"answer",style:{fontSize:14.5,lineHeight:1.65,color:n.textPrimary},children:t.jsx(mt,{text:Ve(B),t:n})}):F?t.jsx(zs,{run:e,detail:F,t:n}):e.summary?t.jsx("div",{"data-followup":"answer",style:{fontSize:14,lineHeight:1.6,color:n.textSecondary},children:Te(e.summary)}):null,t.jsx(gr,{run:e,t:n,onSelect:x}),b.map(q=>t.jsx(Ji,{run:e,artifact:q,selected:q.id===s,t:n,themeMode:r,onInspect:_=>M(q.id,_)},q.id)),U.map(q=>{const _=ae(q),V=q.id===s;return t.jsxs("button",{type:"button",className:"dql-ask-chip",onClick:()=>M(q.id,an(e,q)),style:{display:"flex",alignItems:"center",gap:10,width:"fit-content",maxWidth:"100%",padding:"9px 12px",borderRadius:10,border:`1px solid ${V?"var(--accent)":"var(--border-default)"}`,background:"var(--bg-2)",boxShadow:V?"0 1px 6px rgba(107,93,211,0.12)":"none",cursor:"pointer",textAlign:"left",fontFamily:n.font},children:[t.jsx("span",{style:{width:30,height:30,borderRadius:7,background:q.trustState==="certified"?"var(--status-success-bg)":"var(--accent-dim)",color:q.trustState==="certified"?"var(--status-success)":"var(--accent)",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx(Ke,{kind:q.kind})}),t.jsxs("span",{style:{display:"flex",flexDirection:"column",gap:1,minWidth:0},children:[t.jsx("span",{style:{fontSize:12.5,fontWeight:650,color:n.textPrimary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Te(q.title)}),t.jsx("span",{style:{fontSize:11,color:n.textMuted},children:Rt(q,_)})]}),t.jsx(Gn,{size:14,color:n.textMuted,style:{flexShrink:0,marginLeft:6}})]},q.id)}),W.length>0?t.jsx("div",{style:{display:"grid",gap:8,gridTemplateColumns:"minmax(0, 1fr)",minWidth:0},children:W.map(q=>t.jsx(br,{artifact:q,t:n,themeMode:r,onInsertSql:u,onInsertDql:d,insertDqlActionLabel:f,sourceRunId:e.id,sourceQuestion:e.question,onOpenBlock:c,onOpenResearch:y,onOpenApp:a,onNextAction:v},q.id))}):null,B||F||H||Y||K||Q||G?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:2,flexWrap:"wrap",marginTop:-2},children:[H&&d?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>d(H),style:Ee(n),children:[t.jsx(Ye,{size:12})," ",f]}):null,H&&m&&l?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>m(H),style:Ee(n),children:[t.jsx(Kr,{size:12})," ",l]}):null,B||F?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:C,style:Ee(n),children:[R?t.jsx(Je,{size:12}):t.jsx(Xn,{size:12})," ",R?"Copied":"Copy"]}):null,Y?t.jsx(cn,{run:e,t:n,appContext:i,onOpenApp:a}):null,K?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>v({id:"save-dql-block",label:"Save as block",route:"dql_block_draft"}),style:Ee(n),children:[t.jsx(rt,{size:12})," Save as block"]}):null,Q?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>v({id:"research-deeper",label:"Research this deeper",route:"research"}),style:Ee(n),children:[t.jsx(et,{size:12})," Research deeper"]}):null,G?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>M(G.id,_t(ae(G))?"how":"trust"),style:Ee(n),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=P(n);if(r)return{stage:"execution",...r};const i=typeof e.refusalCode=="string"?e.refusalCode:void 0;if(i){const s=P(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 _t(e){return!!(P(e.resolvedAnalyticalPlan)||P(e.analyticalExecutionGraph)||P(e.analyticalExecutionReceipt)||P(e.analyticalFailure)||P(e.semanticExecutionTrace)||P(e.diagnosticReceipt)||xr(e))}function hr(e){if(!_t(e))return;const n=P(e.diagnosticReceipt),r=P(e.resolvedAnalyticalPlan)??P(n==null?void 0:n.resolvedAnalyticalPlan);return{plan:r,frame:P(r==null?void 0:r.analyticalFrame),graph:P(e.analyticalExecutionGraph),receipt:P(e.analyticalExecutionReceipt),facts:P(e.analyticalFacts),narrative:P(e.analyticalNarrative),freshness:P(e.analyticalFreshnessObservation),failure:P(e.analyticalFailure)??P(n==null?void 0:n.failure)??xr(e),semantic:P(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,Re,we;const{dispatch:m}=qt(),f=n.plan,l=n.frame,c=n.graph,y=n.receipt,x=n.semantic,v=P(x==null?void 0:x.failure),g=n.failure??v,R=P(x==null?void 0:x.authoringRequest),T=P(x==null?void 0:x.runtimeRequest),M=qe(x==null?void 0:x.bindings),N=qe(x==null?void 0:x.steps),k=P(x==null?void 0:x.targetBinding),O=P(k==null?void 0:k.semanticSnapshot),B=P(k==null?void 0:k.executionTarget),E=P(B==null?void 0:B.redactedContext),F=P(k==null?void 0:k.compileTarget),D=P(x==null?void 0:x.executionReceipt),$=qe(v==null?void 0:v.candidates),b=P(l==null?void 0:l.timeContext),w=P(l==null?void 0:l.comparison),U=P(l==null?void 0:l.ranking),W=qe(l==null?void 0:l.dimensions),G=qe(l==null?void 0:l.memberBindings),Y=qe(b==null?void 0:b.periods),ee=qe(l==null?void 0:l.requestedOutputs),J=qe(c==null?void 0:c.nodes),Q=Array.from(new Set([...be(g==null?void 0:g.safeActions),...be(v==null?void 0:v.safeActions)])),le=qe(g==null?void 0:g.failedBindings),K=P(v==null?void 0:v.sqlExcerpt),H=e.artifacts.map(j=>De(ae(j))).find(Boolean),C=(r==null?void 0:r.name)??e.question,[q,_]=p.useState(null),V=(j,de)=>{const je=de.derivation.trustTransition;return`${j} as immutable derivation ${de.derivation.derivationId}. Trust: ${je.previous} → ${je.next}${je.requiresReview?" (review required)":""}.`},z=async()=>{if(!(!(r!=null&&r.source)||!u))try{const j=await re.deriveAnalyticalRepair(e.id,{version:1,action:"edit_dql",dqlSource:r.source});u({sql:i,dqlArtifact:r,result:H,title:C,sourceRunId:e.id,question:e.question}),_(V("Opened DQL in Notebook",j))}catch(j){_(j instanceof Error?j.message:String(j))}},ie=async()=>{if(!(!i||!a))try{const j=await re.deriveAnalyticalRepair(e.id,{version:1,action:"open_sql_notebook",sqlText:i});a(i,`${C} repair`,{question:e.question,sourceRunId:e.id}),_(V("Opened SQL in Notebook",j))}catch(j){_(j instanceof Error?j.message:String(j))}},ce=async j=>{try{const de=await re.deriveAnalyticalRepair(e.id,{version:1,action:j});_(V(j==="retry_same_plan"?"Prepared the same bounded plan for retry":"Refreshed the governed snapshot and prepared the same plan for retry",de))}catch(de){_(de instanceof Error?de.message:String(de))}},te=async()=>{try{const j=await re.deriveAnalyticalRepair(e.id,{version:1,action:"request_access"});_(V("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){_(j instanceof Error?j.message:String(j))}},He=()=>{m({type:"SET_SETTINGS_TAB",tab:"project"}),m({type:"SET_MAIN_VIEW",view:"settings"}),_("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(xe,{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(A).join(" · ")})]}):t.jsx("div",{style:{marginTop:2},children:typeof(y==null?void 0:y.rowCount)=="number"?`Returned ${y.rowCount} row${y.rowCount===1?"":"s"}.`:"The query ran and returned a result."})]})]}),t.jsx(ht,{index:1,label:"Plan",t:o,open:!g,children:t.jsx(Ht,{rows:[["Question type",A((l==null?void 0:l.questionType)??(f==null?void 0:f.questionType))],["Selected route",A((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",W.map(j=>`${A(j.dimensionId)} (${A(j.role)})`).join(", ")],["Member filters",G.map(j=>`${A(j.dimensionId)}: ${Array.isArray(j.canonicalValues)?j.canonicalValues.length:0} bound value(s)`).join(", ")],["Time policy",[b==null?void 0:b.timeRole,b==null?void 0:b.grain,b==null?void 0:b.timezone,b==null?void 0:b.completenessPolicy].map(A).filter(Boolean).join(" · ")],["Periods",Y.map(j=>`${A(j.id)}: ${A(j.start)} → ${A(j.end)}`).join(`
|
|
80
|
+
`)],["Comparison",w?`${A(w.basePeriodId)} vs ${be(w.comparisonPeriodIds).join(", ")} · ${A(w.alignment)}`:l?"Not requested":"Not available — analytical planning did not complete"],["Ranking",U?`${A(U.direction)} · top ${A(U.limit)} · ${A(U.tiePolicy)}`:l?"Not requested":"Not available — analytical planning did not complete"],["Outputs",ee.map(j=>`${A(j.id)} (${A(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(Ht,{rows:[["Trust state",e.trustState],["Snapshot",A((f==null?void 0:f.snapshotId)??(c==null?void 0:c.snapshotId))],["Plan fingerprint",A((f==null?void 0:f.fingerprint)??(c==null?void 0:c.planFingerprint))],["Graph fingerprint",A(c==null?void 0:c.fingerprint)],["Receipt",A(y==null?void 0:y.receiptId)],["Result fingerprint",A(y==null?void 0:y.resultFingerprint)],["Freshness observed through",A((ve=n.freshness)==null?void 0:ve.observedThrough)],["Fact set",A((Re=n.facts)==null?void 0:Re.fingerprint)],["Semantic adapter",A(x==null?void 0:x.adapter)],["Semantic compile status",A(x==null?void 0:x.status)],["Target proof",A((we=P(k==null?void 0:k.proof))==null?void 0:we.status)],["Target binding",A(k==null?void 0:k.bindingFingerprint)],["Compile target",A(F==null?void 0:F.kind)],["Local semantic snapshot",A((O==null?void 0:O.semanticCatalogFingerprint)??(O==null?void 0:O.sourceFingerprint))],["Runtime metric inventory proof",A(F==null?void 0:F.semanticCatalogFingerprint)],["Execution target",[B==null?void 0:B.driver,E==null?void 0:E.account,E==null?void 0:E.database,E==null?void 0:E.schema,E==null?void 0:E.role,E==null?void 0:E.warehouse].map(A).filter(Boolean).join(" · ")],["Semantic receipt",A(D==null?void 0:D.receiptId)],["Warehouse query ID",A(D==null?void 0:D.queryId)],["Executed SQL proof",A(D==null?void 0:D.executedSqlFingerprint)],["Runtime metrics",be(T==null?void 0:T.metrics).join(", ")],["Runtime dimensions",be(T==null?void 0:T.dimensions).join(", ")],["Member bindings",M.map(j=>`${A(j.authoringReference)} → ${A(j.runtimeReference)}${be(j.entityPath).length?` via ${be(j.entityPath).join(" → ")}`:""} (${A(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:[N.map((j,de)=>t.jsxs("div",{style:{fontSize:11.5,color:o.textSecondary},children:[t.jsxs("strong",{style:{color:A(j.status)==="failed"?"var(--status-error)":o.textPrimary},children:[de+1,". ",A(j.label)]})," ","— ",A(j.status)," · ",A(j.detail)]},`semantic:${A(j.id)||de}`)),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)),J.map((j,de)=>t.jsxs("div",{style:{fontSize:11.5,color:o.textSecondary},children:[t.jsxs("span",{style:{color:o.accent,fontFamily:o.fontMono},children:[de+1,". ",A(j.kind)]})," ","· ",A(j.id)]},A(j.id)||de)),N.length===0&&e.steps.length===0&&J.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(Ht,{rows:[["Failure ID",A(g.failureId)],["Recoverability",A(g.recoverability)],["Failed bindings",le.map(j=>`${A(j.qualifiedId??j.role)} (${A(j.reasonCode)})`).join(", ")],["Safe actions",Q.join(", ")],["DQL fingerprint",A(g.dqlFingerprint)],["SQL fingerprint",A(g.sqlFingerprint)],["Semantic failure code",A(v==null?void 0:v.code)],["Failing identifier",A(v==null?void 0:v.identifier)],["Compiled SQL proof",A(v==null?void 0:v.compiledSqlFingerprint)],["Path candidates",$.map(j=>`${A(j.label)}
|
|
82
|
+
${A(j.runtimeReference)}`).join(`
|
|
83
|
+
`)]],t:o,mono:!0}),A(K==null?void 0:K.text)?t.jsxs("div",{children:[t.jsxs("div",{style:{fontSize:10.5,fontWeight:700,color:o.textSecondary,marginBottom:5},children:["Failing SQL context · lines ",A(K==null?void 0:K.startLine),"–",A(K==null?void 0:K.endLine)]}),t.jsx("pre",{style:nt(o),children:A(K==null?void 0:K.text)})]}):null,t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6},"aria-label":"Safe repair actions",children:[Q.includes("edit_dql")&&u?t.jsxs("button",{type:"button",onClick:()=>void z(),style:X(o),children:[t.jsx(rn,{size:12})," Open DQL to repair"]}):null,Q.includes("open_sql_notebook")&&a?t.jsxs("button",{type:"button",onClick:()=>void ie(),style:X(o),children:[t.jsx(nn,{size:12})," Open SQL in Notebook"]}):null,Q.includes("retry_same_plan")?t.jsxs("button",{type:"button",onClick:()=>void ce("retry_same_plan"),style:X(o),children:[t.jsx(Mt,{size:12})," Retry same plan"]}):null,Q.includes("refresh_snapshot")?t.jsxs("button",{type:"button",onClick:()=>void ce("refresh_snapshot"),style:X(o),children:[t.jsx(Mt,{size:12})," Refresh snapshot and prepare retry"]}):null,Q.includes("request_access")||Q.includes("change_authorized_connection")?t.jsxs("button",{type:"button",onClick:()=>void te(),style:X(o),children:[t.jsx(Ge,{size:12})," Change connection or request access"]}):null,Q.includes("reapply_semantic_runtime")?t.jsxs("button",{type:"button",onClick:He,style:X(o),children:[t.jsx(Mt,{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(sn,{size:12})," Save as draft block"]}):null]})}),q?t.jsx("div",{role:"status",style:{fontSize:10.5,color:q.toLowerCase().includes("created")?"var(--status-success)":"var(--status-error)"},children:q}):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 Ht({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=>P(n)?[P(n)]:[]):[]}function be(e){return Array.isArray(e)?e.filter(n=>typeof n=="string"):[]}function A(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=>!!It(ae(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=ae(n),c=Be(e)??st(l),y=Ne(e)??(typeof l.sql=="string"?l.sql:void 0),x=De(l),v=jt(e,n),g=pn(e),R=fr(e),T=dn(e),M=n.trustState==="certified",N=e.status==="blocked"||n.trustState==="blocked",k=it(e),O=hr(l),B=pr({analytical:!!O,blocked:N,hasDql:!!(c!=null&&c.source),hasSql:!!y,hasLineage:R.length>0}),E=B.some(b=>b.id===r)?r:B[0].id,F=N?"Blocked":M?"Certified":n.trustState==="governed"||n.trustState==="grounded"?"Governed":"AI-generated",D=N?"var(--status-error)":M?"var(--status-success)":n.trustState==="governed"||n.trustState==="grounded"?"var(--accent)":"var(--status-warning)",$=N?"var(--status-error-bg)":M?"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:D,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:Rt(n,l)})]}),t.jsx("span",{style:{border:`1px solid ${D}`,color:D,background:$,borderRadius:999,padding:"2px 8px",fontSize:10,fontWeight:700,flexShrink:0,marginTop:2},children:F}),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:[k?t.jsx(cn,{run:e,t:i,appContext:s,onOpenApp:o}):null,k?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:B.map(b=>t.jsx("button",{type:"button",onClick:()=>a(b.id),style:{padding:"10px 1px",fontSize:12,fontWeight:600,cursor:"pointer",border:"none",background:"none",fontFamily:i.font,whiteSpace:"nowrap",color:E===b.id?i.textPrimary:i.textMuted,boxShadow:E===b.id?`inset 0 -2px 0 0 ${i.accent}`:"none"},children:b.label},b.id))}),t.jsxs("div",{style:{flex:1,minHeight:0,overflow:"auto",padding:"14px 16px 20px"},children:[E==="how"&&O?t.jsx(es,{run:e,contract:O,dqlArtifact:c,sql:y,lineage:R,t:i,onInsertSql:m,onInsertDql:f,onSaveBlock:d}):null,E==="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:y,dqlArtifact:c,result:x,chartConfig:x?We(l,x):void 0,title:v,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,E==="sql"?y?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(y,v,{question:e.question,sourceRunId:e.id}),style:X(i),children:"Open SQL in notebook"}):null,t.jsx(wt,{text:y,t:i,title:"Copy SQL"})]})]}),t.jsx("pre",{style:nt(i),children:y})]}):t.jsx(St,{t:i,children:"Compilation stopped before SQL was produced. The DQL, plan, trust evidence, and failure steps are still retained."}):null,E==="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(b=>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:b.name}),t.jsx("div",{style:{fontSize:10.5,color:i.textMuted,marginTop:2},children:[b.kind,b.detail].filter(Boolean).join(" · ")})]})]},`${b.kind??"asset"}:${b.name}`))]}):null,E==="trust"?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[T?t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-start",padding:"10px 12px",borderRadius:8,background:M?"var(--status-success-bg)":"var(--status-warning-bg)",border:`1px solid ${M?"var(--status-success-border)":"var(--status-warning-border)"}`},children:[M?t.jsx(xe,{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:T})]}):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(b=>t.jsxs("span",{style:Cr(i,b.certified),children:[b.certified?t.jsx(xe,{size:11}):t.jsx(et,{size:11}),t.jsx("span",{children:b.label})]},b.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(Fe,{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 Ot(e){const n=e.replace(/^\/\w+\s+/,"").trim().replace(/[?.!]+$/,"");return(n?n.charAt(0).toUpperCase()+n.slice(1):"New app").slice(0,60)}function cn({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,y]=p.useState(""),[x,v]=p.useState(!1),[g,R]=p.useState(null),[T,M]=p.useState(null),N=p.useRef(null),k=async()=>{u(null),m(!1);try{const $=await re.listAppsStrict();u($),$.length===0&&l("new")}catch{u([]),m(!0)}},O=()=>{o(!0),R(null),l("list"),N.current=null,y(Ot(e.question)),k()},B=()=>{x||(o(!1),R(null))},E=async($,b,w)=>{const U=Be(e);if(!(await re.createAiPin($,{dashboardId:b,title:Ot(e.question),answer:e.answer??e.summary,question:e.question,sql:Ne(e),certification:e.trustState==="certified"?"certified":"ai_generated",reviewStatus:e.trustState==="certified"?"certified":"needs_review",analysisPlan:U?{dqlArtifact:U}:void 0})).ok)throw new Error("Could not add to app.");M({appId:$,dashboardId:b,name:w}),o(!1)},F=async $=>{var b,w,U;if(!x){v(!0),R(null);try{let W=(r==null?void 0:r.appId)===$.id?r.dashboardId:void 0;if(!W){const G=await re.getApp($.id),Y=(b=G==null?void 0:G.app)==null?void 0:b.homepage;if(W=(Y==null?void 0:Y.type)==="dashboard"?Y.id:(U=(w=G==null?void 0:G.dashboards)==null?void 0:w[0])==null?void 0:U.id,!W){const ee=await re.createAppDashboard($.id,{title:"Overview"});if(!ee.ok)throw new Error(ee.error);W=ee.dashboard.id}}await E($.id,W,$.name)}catch(W){R(W instanceof Error?W.message:"Could not add to app.")}finally{v(!1)}}},D=async()=>{if(x)return;const $=c.trim()||Ot(e.question);v(!0),R(null);try{if(!N.current){const b=await re.createApp({name:$,domain:"general",dashboardTitle:"Overview",tags:[],owners:[],selectedBlockIds:[]});N.current={appId:b.app.id,dashboardId:b.dashboardId}}await E(N.current.appId,N.current.dashboardId,$),N.current=null}catch(b){R(b instanceof Error?b.message:"Could not create the app.")}finally{v(!1)}};return t.jsxs("div",{style:{position:"relative",display:"inline-flex",alignItems:"center",gap:6},children:[T?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>i==null?void 0:i(T.appId,T.dashboardId),style:{...Vt(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 ",T.name,i?t.jsx(Ur,{size:13}):null]}):null,t.jsxs("button",{type:"button",className:"dql-hover dql-lift",onClick:O,style:T?X(n):Vt(n),children:[t.jsx(Gt,{size:13}),T?"Add to another":"Add to app"]}),s?t.jsxs(t.Fragment,{children:[t.jsx("div",{onClick:B,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:B,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:$=>y($.target.value),onKeyDown:$=>{$.key==="Enter"&&D()},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 D(),style:{...Vt(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 k(),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 F($),style:vs(n),children:[t.jsx(Gt,{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 dn(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(un(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 un(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":un(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),[y,x]=p.useState(null);if(!o||!s)return t.jsxs("div",{style:en(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 v=async()=>{var R,T;f(!0),c(null);const g=await re.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:((T=g.app)==null?void 0:T.name)??e.title})};return t.jsxs("div",{style:en(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:Te(e.title)})]}),y?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 ",y.name]}),y.appId&&i?t.jsx("button",{type:"button",className:"dql-hover",onClick:()=>i(y.appId,y.dashboardId),style:X(r),children:"Open app"}):null]}):t.jsx(Or,{proposal:o,t:r,selected:u,onToggle:g=>{d(R=>{const T=new Set(R);return T.has(g)?T.delete(g):T.add(g),T})},onCreate:()=>void v(),busy:m,error:l,compact:!0})]})}function yr({artifact:e,certifiedBlockName:n,initialResult:r,initialChartConfig:i,payload:s,t:o,themeMode:a,embedded:u=!1}){var H;const[d,m]=p.useState(e),[f,l]=p.useState(()=>e.parameters??[]),[c,y]=p.useState(()=>({...e.parameterValues??{},...Xt(s)})),[x,v]=p.useState(r),[g,R]=p.useState(i),[T,M]=p.useState(!!n),[N,k]=p.useState(!1),[O,B]=p.useState(null),[E,F]=p.useState(!1),[D,$]=p.useState(""),[b,w]=p.useState(""),U=p.useRef(!1),W=p.useRef(e);W.current=e;const G=Mi(e);p.useEffect(()=>{const C=W.current;if(m(C),F(!1),!n){l(C.parameters??[]),y({...C.parameterValues??{},...Xt(s)}),M(!1);return}let q=!1;return M(!0),re.getCertifiedBlockParameters(n).then(_=>{q||(l(_.parameters),y(V=>({...Object.fromEntries(_.parameters.flatMap(z=>z.default===void 0?[]:[[z.name,z.default]])),...V})))}).catch(_=>{q||B(_ instanceof Error?_.message:String(_))}).finally(()=>{q||M(!1)}),()=>{q=!0}},[G,n]);const Y=async()=>{if(!U.current){U.current=!0,k(!0),B(null);try{const C=await re.invokeDqlArtifact(d,c,void 0,n);v(C.result),m(C.artifact),C.result.chartConfig&&typeof C.result.chartConfig=="object"&&R(C.result.chartConfig),C.parameters.length>0&&l(C.parameters)}catch(C){B(C instanceof Error?C.message:String(C))}finally{U.current=!1,k(!1)}}},ee=p.useMemo(()=>rr(d,x),[d,x]),J=()=>{const C=ee[0];C&&($(C.column),w(C.values[0]==null?"":String(C.values[0])),F(!0),B(null))},Q=async()=>{try{const C=d.kind==="sql_block"?await re.addDqlArtifactResultFilter(d,x.columns,D,b):Ei(d,x,D,b);m(C.artifact),l(C.artifact.parameters??[]),y(q=>({...q,...C.artifact.parameterValues??{}})),F(!1),B(null)}catch(C){B(C instanceof Error?C.message:String(C))}},le=f.some(er),K=Object.entries(c).filter(([,C])=>C!=null&&C!=="");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:u?"8px 12px 0":0},children:[t.jsx("span",{style:{fontSize:10.5,fontWeight:750,color:o.textMuted},children:"Applied inputs"}),K.map(([C,q])=>t.jsxs("span",{style:{fontSize:10.5,color:o.textSecondary,border:`1px solid ${o.cellBorder}`,background:o.appBg,borderRadius:999,padding:"2px 7px"},children:[C.replace(/_/g," ")," = ",ss(q)]},C))]}):null,T?t.jsx("div",{style:{fontSize:10.5,color:o.textMuted},children:"Loading reusable inputs…"}):le||ee.length>0?t.jsxs("div",{style:{display:"grid",gap:8,padding:9,margin:u?"0 12px":0,border:`1px solid ${o.cellBorder}`,borderRadius:7,background:o.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:o.textPrimary},children:"Change DQL inputs"}),t.jsx("div",{style:{fontSize:10,color:o.textMuted},children:"Reruns this DQL artifact directly. It does not start another AI search."})]}),ee.length>0?t.jsxs("button",{type:"button",onClick:J,style:X(o),children:[t.jsx(Ye,{size:11})," Add result filter"]}):null,t.jsxs("button",{type:"button",disabled:N,onClick:()=>void Y(),style:{...X(o),color:o.accent,opacity:N?.65:1},children:[N?t.jsx(Pe,{size:11,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(Fe,{size:11}),N?"Running…":"Apply"]})]}),E?t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"minmax(150px, 1fr) minmax(150px, 1fr) auto auto",gap:7,alignItems:"end",padding:8,border:`1px solid ${o.cellBorder}`,borderRadius:7,background:o.cellBg},children:[t.jsxs("label",{style:{display:"grid",gap:4,fontSize:10,fontWeight:750,color:o.textSecondary},children:["Result column",t.jsx("select",{"aria-label":"Result column for new DQL input",value:D,onChange:C=>{const q=C.target.value,_=ee.find(V=>V.column===q);$(q),w((_==null?void 0:_.values[0])==null?"":String(_.values[0]))},style:Qn(o),children:ee.map(C=>t.jsx("option",{value:C.column,children:C.column.split("_").join(" ")},C.column))})]}),t.jsxs("label",{style:{display:"grid",gap:4,fontSize:10,fontWeight:750,color:o.textSecondary},children:["Default value",t.jsx("input",{"aria-label":"Default value for new DQL input",value:b,list:`ask-filter-${D}`,onChange:C=>w(C.target.value),style:Qn(o)}),t.jsx("datalist",{id:`ask-filter-${D}`,children:(((H=ee.find(C=>C.column===D))==null?void 0:H.values)??[]).map(C=>t.jsx("option",{value:String(C)},`${typeof C}:${String(C)}`))})]}),t.jsx("button",{type:"button",onClick:()=>{Q()},style:{...X(o),color:o.accent},children:"Add input"}),t.jsx("button",{type:"button",onClick:()=>F(!1),style:X(o),children:"Cancel"})]}):null,f.length>0?t.jsx(ji,{parameters:f,values:c,onChange:(C,q)=>y(_=>({..._,[C]:q})),t:o}):null,ee.length>0?t.jsx("div",{style:{fontSize:9.5,color:o.textMuted},children:"Extra filters are available only for semantic dimensions in this result. They stay transient until you explicitly save a block."}):null]}):null,O?t.jsx("div",{style:{fontSize:10.5,color:o.error},children:O}):null,t.jsx(tn,{result:x,themeMode:a,t:o,chartConfig:g,embedded:u,tabLabels:u?{table:"Results",chart:"Visualization"}:void 0})]})}function Xt(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 y=De(c),x=st(c),v=It(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,T=typeof c.path=="string"?c.path:e.ref,M=c.draftBlock&&typeof c.draftBlock=="object"&&!Array.isArray(c.draftBlock)?c.draftBlock:void 0,N=typeof(M==null?void 0:M.path)=="string"?M.path:void 0,k=typeof(M==null?void 0:M.name)=="string"?M.name:void 0,O=(x==null?void 0:x.sourcePath)??N??(e.kind==="dql_block_draft"?T:void 0),B=(x==null?void 0:x.name)??k??R,E=(x==null?void 0:x.kind)==="sql_block"||e.kind==="dql_block_draft"?"Open DQL draft":"Open DQL artifact",F=c.plan&&typeof c.plan=="object"?c.plan:void 0,D=Array.isArray(F==null?void 0:F.steps)?F.steps:[],$=Array.isArray(F==null?void 0:F.gaps)?F.gaps.map(String):[],b=typeof c.researchRunId=="string"?c.researchRunId:e.kind==="research_run"&&typeof e.ref=="string"?e.ref:void 0,w=typeof c.notebookPath=="string"?c.notebookPath:void 0,U=Array.isArray(c.generatedPaths)?c.generatedPaths.filter(J=>typeof J=="string"):[],W=c.narration&&typeof c.narration=="object"?c.narration:void 0,G=Array.isArray(W==null?void 0:W.keyFindings)?W.keyFindings.filter(J=>typeof J=="string"):[],Y=typeof(W==null?void 0:W.recommendation)=="string"?W.recommendation:void 0,ee=e.trustState==="certified"?mr(e,c):void 0;if(e.kind==="dql_block_draft"){const J=le=>Array.isArray(le)?le.filter(K=>typeof K=="string"):void 0,Q=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:J(c.outputs),dimensions:J(c.dimensions)??(x==null?void 0:x.dimensions),entities:J(c.entities),certifierVerdict:Q?{blocking:J(Q.blocking)??[],warnings:J(Q.warnings)??[],ready:!!Q.ready}:void 0,actions:t.jsxs(t.Fragment,{children:[g&&s?t.jsx("button",{type:"button",onClick:()=>s({sql:g,dqlArtifact:x,result:y,chartConfig:y?We(c,y):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,O&&d?t.jsx("button",{type:"button",onClick:()=>d(O,B),style:X(n),children:E}):null]})})}return t.jsxs("div",{style:en(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:Te(e.title)})]}),G.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:G,t:n,renderItem:(J,Q)=>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:J})]},Q)})]}):D.length>0?t.jsx("div",{style:{display:"grid",gap:5},children:t.jsx(Pn,{items:D,t:n,renderItem:(J,Q)=>t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.35},children:[Q+1,". ",String(J.thought??J.expectation??"Research step")]},Q)})}):null,Y?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:Y})]}):null,y?x?t.jsx(yr,{artifact:x,certifiedBlockName:ee,initialResult:y,initialChartConfig:We(c,y),payload:c,t:n,themeMode:r}):t.jsx(tn,{result:y,themeMode:r,t:n,chartConfig:We(c,y)}):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,!O&&l?t.jsxs("button",{type:"button",className:"dql-hover",title:"Save this DQL as a reusable block",onClick:J=>{J.preventDefault(),J.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(sn,{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(nn,{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,U.length>0?t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.4},children:["Files: ",U.join(", ")]}):null,t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[b&&m?t.jsx("button",{type:"button",onClick:()=>m(b,w),style:X(n),children:"Open research"}):null,g&&s?t.jsx("button",{type:"button",onClick:()=>s({sql:g,dqlArtifact:x,result:y,chartConfig:y?We(c,y):void 0,title:R,mixedSourcePlan:v,sourceRunId:a,question:u}),style:v?{...X(n),background:n.accent,borderColor:n.accent,color:"#fff",fontWeight:850,padding:"7px 11px"}:X(n),children:v?"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,O&&d?t.jsx("button",{type:"button",onClick:()=>d(O,B),style:X(n),children:E}):null]})]})}function os({run:e}){return e.trustState==="certified"?t.jsx(xe,{size:16,color:"#16a34a"}):e.trustState==="governed"?t.jsx(xe,{size:16,color:"#2563eb"}):e.trustState==="grounded"?t.jsx(xe,{size:16,color:"#2563eb"}):e.status==="completed"?t.jsx(Xe,{size:16,color:"#16a34a"}):e.status==="blocked"?t.jsx(Kt,{size:16,color:"#ef4444"}):t.jsx(Kt,{size:16,color:"#d97706"})}function Ke({kind:e}){return e==="sql_cell"?t.jsx(nn,{size:14}):e==="dql_block_draft"?t.jsx(rt,{size:14}):e==="app_draft"||e==="app_proposal"?t.jsx(Gt,{size:14}):e==="research_run"?t.jsx(et,{size:14}):t.jsx(Fe,{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":un(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(Zt,{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(xe,{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(Zt,{evaluation:s,t:n},s.id))})]}):null]})}function Zt({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 Qt({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(rn,{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(Zt,{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 Te(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 De(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 We(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=We(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 ae(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=ae(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 y=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("; "),v=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=v!==void 0||g!==void 0?`Signals: lexical ${(v??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:[y,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 re.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(zt,{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 pn(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=ae(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 Ne(e){for(const n of e.artifacts){const r=ae(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 Be(e){for(const n of e.artifacts){const r=ae(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 fn(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=Be(e),i=Ne(e);if(!((!(r!=null&&r.source)||r.sourcePath)&&!i)){for(const s of e.artifacts){const o=ae(s),a=De(o),u=It(o);if(a)return{sql:i,dqlArtifact:r,result:a,chartConfig:We(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 It(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{...At(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{...At(e,{variant:n?"primary":"secondary",size:"lg"}),...n?{}:{color:e.textMuted}}}function Vt(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 en(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 At(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."}};function zr(e){var n;for(const r of e.artifacts??[]){const i=ae(r),s=(n=i==null?void 0:i.warehouseFailure)==null?void 0:n.origin;if(typeof s=="string"&&s in Ct)return s}return"warehouse"}function zs({run:e,detail:n,t:r}){const i=zr(e),s=Ct[i]??Ct.warehouse;return t.jsxs("div",{"data-followup":"answer",style:{display:"flex",flexDirection:"column",gap:6,padding:"11px 13px",borderRadius:9,border:`1px solid ${r.error}33`,background:`${r.error}0d`},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7},children:[t.jsx(Ge,{size:13,color:r.error,style:{flexShrink:0}}),t.jsx("span",{style:{fontSize:12.5,fontWeight:700,color:r.textPrimary},children:s.title})]}),t.jsx("div",{style:{fontSize:12.5,lineHeight:1.6,color:r.textSecondary,wordBreak:"break-word"},children:Te(n)}),t.jsx("div",{style:{fontSize:11.5,lineHeight:1.5,color:r.textMuted},children:s.hint})]})}function qr(e){var n,r;for(const i of e.artifacts??[]){const s=ae(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:Pi,agentRunHistoryFromItems:ir,analyticalInspectorContract:hr,analyticalInspectorSections:Xi,analyticalRepairActionLabels:Zi,artifactReadyPayloadFromRun:fn,artifactSqlDisclosureLabel:wr,askArtifactMeta:Rt,askFailureDetail:qr,askFailureOrigin:zr,askInspectorTabsForState:pr,clarificationSelectionInput:yt,completedRunGuidanceFor:dr,deriveResultChartConfig:Dr,hasAnalyticalInspectorContract:_t,inlineAskChartConfig:Sr,isAgentRunPinnable:it,liveAgentActivityFor:ur,longRunGuidanceFor:cr,preferredAskInspectorTab:an,resolveArtifactDqlView:st,resolvedParameterValues:Xt,selectAgentExecutionConnection:lr,threadItemsFromTurns:ar,trustExplainer:dn,usePersistedAgentThreadId:Qr},Symbol.toStringTag,{value:"Module"}));export{ji as B,ni as E,qn as S,Pi 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-CcZ8Dw84.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};
|