@duckcodeailabs/dql-cli 1.13.4 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/args.d.ts +2 -0
- package/dist/args.d.ts.map +1 -1
- package/dist/args.js +5 -0
- package/dist/args.js.map +1 -1
- package/dist/assets/dql-notebook/assets/{AgentLogPage-DYmHO6_i.js → AgentLogPage-Ch7VK20X.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildDialog-BfhaOd1h.js → AiBuildDialog-DBr5TmyM.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildResult-DLKFAe6R.js → AiBuildResult-jLPzQO7O.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiSidePanel-C6Z3URGr.js → AiSidePanel-CdlGsiVC.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AnalyticsHome-uG3xCP_s.js → AnalyticsHome-C0DXbOwY.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AppsView-DfieNjkh.js → AppsView-CcpwjApv.js} +4 -4
- package/dist/assets/dql-notebook/assets/{BlockStudio-90J_wvWL.js → BlockStudio-CFYxafw-.js} +1 -1
- package/dist/assets/dql-notebook/assets/{BusinessArtifactView-_zSMae5q.js → BusinessArtifactView-C0kLYg2p.js} +1 -1
- package/dist/assets/dql-notebook/assets/{DbtFirstModelingPage-DoXiPssu.js → DbtFirstModelingPage-CMwElXD_.js} +1 -1
- package/dist/assets/dql-notebook/assets/{GitPage-CUfAhS67.js → GitPage-JjhRDeWY.js} +1 -1
- package/dist/assets/dql-notebook/assets/{GlobalAiRail-ovtL7nQu.js → GlobalAiRail-DakE4NdR.js} +1 -1
- package/dist/assets/dql-notebook/assets/{GovernedContextPage-CaMiKAzA.js → GovernedContextPage-BokDqG6a.js} +1 -1
- package/dist/assets/dql-notebook/assets/{HelpDocsPage-CEGUx28b.js → HelpDocsPage-CjOv6_gz.js} +1 -1
- package/dist/assets/dql-notebook/assets/{HomePage-2v3SRf8V.js → HomePage-nGaNcwdw.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDAG-AaqLEiBN.js → LineageDAG-CO6CFJRg.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDetailView-CFc8pm91.js → LineageDetailView-BnGb7OF7.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDrawer-DOkFjPq-.js → LineageDrawer-C5Y0Ht0b.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineagePathBreadcrumb-BrDwCuMs.js → LineagePathBreadcrumb-Cgh3GR3F.js} +1 -1
- package/dist/assets/dql-notebook/assets/{MiniLineageGraph-CiHtQs3y.js → MiniLineageGraph-Kla9PYuj.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewBlockModal-DAgJZbws.js → NewBlockModal-BR2SnmPT.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewNotebookModal-xjG7nZ3O.js → NewNotebookModal-BaCHMYeB.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NotebookEditor-CXZaKfYT.js → NotebookEditor-CBLqY8cE.js} +1 -1
- package/dist/assets/dql-notebook/assets/{ReadinessPage-MuJBFwwg.js → ReadinessPage-CiN0IWSS.js} +1 -1
- package/dist/assets/dql-notebook/assets/{SetupOnboarding-vKFtKtjh.js → SetupOnboarding-BhiCsYF-.js} +1 -1
- package/dist/assets/dql-notebook/assets/{SkillsPage-DCFVOV5f.js → SkillsPage-CCSf8VMm.js} +1 -1
- package/dist/assets/dql-notebook/assets/{TrustBadge-TcwXFFHK.js → TrustBadge-BgQmFe_x.js} +1 -1
- package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-Bw5AXNDB.js +88 -0
- package/dist/assets/dql-notebook/assets/{answer-to-notebook-DCFWlHB7.js → answer-to-notebook-AeDYUDla.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-left-BLnlJAtp.js → arrow-left-C55x2hq_.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-right-BmUAb1aW.js → arrow-right-C1cJrhOm.js} +1 -1
- package/dist/assets/dql-notebook/assets/{book-open-text-bdSChSag.js → book-open-text-CQf_sdv2.js} +1 -1
- package/dist/assets/dql-notebook/assets/{circle-x-Cc6dEaf4.js → circle-x-X8-Z2yLY.js} +1 -1
- package/dist/assets/dql-notebook/assets/{dagre.esm-CPebQKQ9.js → dagre.esm-BjjNYKyY.js} +1 -1
- package/dist/assets/dql-notebook/assets/{external-link-rmXvubf3.js → external-link-C2zrz5DH.js} +1 -1
- package/dist/assets/dql-notebook/assets/{grip-vertical-Sg4zd5-Q.js → grip-vertical-qGV_PYGU.js} +1 -1
- package/dist/assets/dql-notebook/assets/{index-mQd_pC-P.js → index-ByTDPDaH.js} +127 -127
- package/dist/assets/dql-notebook/assets/{link-2-BLaPoFxW.js → link-2-VpyOxQXG.js} +1 -1
- package/dist/assets/dql-notebook/assets/{list-tree-j0s4asFK.js → list-tree-CH2Jhwms.js} +1 -1
- package/dist/assets/dql-notebook/assets/{minimize-2-Cl4pef4s.js → minimize-2-B2TZJ8BT.js} +1 -1
- package/dist/assets/dql-notebook/assets/{panel-right-open-Clz-FtWi.js → panel-right-open-BunF88lt.js} +1 -1
- package/dist/assets/dql-notebook/assets/{play-DFdazMg7.js → play-DAFVF4_G.js} +1 -1
- package/dist/assets/dql-notebook/assets/{rotate-ccw-C3tTaR7s.js → rotate-ccw-DGCrrqtY.js} +1 -1
- package/dist/assets/dql-notebook/assets/{semantic-fields-DIAhTlfy.js → semantic-fields-Ci-9QL9F.js} +1 -1
- package/dist/assets/dql-notebook/assets/{sliders-horizontal-BUiu2tfY.js → sliders-horizontal-BOAlXXbn.js} +1 -1
- package/dist/assets/dql-notebook/assets/{star--Yq77aH4.js → star-CkksZXHt.js} +1 -1
- package/dist/assets/dql-notebook/assets/{triangle-alert-D5Ng-xZO.js → triangle-alert-D3mjyJZE.js} +1 -1
- package/dist/assets/dql-notebook/assets/{upload-L8BKQAxP.js → upload-CTNOAVEO.js} +1 -1
- package/dist/assets/dql-notebook/assets/{usePersistedAgentThreadId-DBu97YaM.js → usePersistedAgentThreadId-DiQjc7x-.js} +4 -4
- package/dist/assets/dql-notebook/assets/{user-round-BK5N1cJW.js → user-round-BWd5tQRg.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wand-sparkles-D8XDQD9z.js → wand-sparkles-CqsAv8P-.js} +1 -1
- package/dist/assets/dql-notebook/assets/{workflow-Bl9zwG0q.js → workflow-CSqsj-sC.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wrench-C-zLCMbW.js → wrench-DWqzqlX8.js} +1 -1
- package/dist/assets/dql-notebook/assets/{x-stiJ-sP7.js → x-65M5rLCE.js} +1 -1
- package/dist/assets/dql-notebook/index.html +1 -1
- package/dist/commands/eval.d.ts +15 -1
- package/dist/commands/eval.d.ts.map +1 -1
- package/dist/commands/eval.js +32 -3
- package/dist/commands/eval.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/llm/answer-loop-tools.d.ts +3 -1
- package/dist/llm/answer-loop-tools.d.ts.map +1 -1
- package/dist/llm/answer-loop-tools.js +31 -23
- package/dist/llm/answer-loop-tools.js.map +1 -1
- package/dist/llm/providers/dql-agent-provider.d.ts +3 -1
- package/dist/llm/providers/dql-agent-provider.d.ts.map +1 -1
- package/dist/llm/providers/dql-agent-provider.js +315 -22
- package/dist/llm/providers/dql-agent-provider.js.map +1 -1
- package/dist/llm/types.d.ts +29 -2
- package/dist/llm/types.d.ts.map +1 -1
- package/dist/local-runtime.d.ts +200 -5
- package/dist/local-runtime.d.ts.map +1 -1
- package/dist/local-runtime.js +2280 -457
- package/dist/local-runtime.js.map +1 -1
- package/dist/package.json +10 -10
- package/dist/providers/oauth/claude-oauth.d.ts +1 -1
- package/dist/providers/oauth/claude-oauth.d.ts.map +1 -1
- package/dist/providers/oauth/claude-oauth.js +18 -11
- package/dist/providers/oauth/claude-oauth.js.map +1 -1
- package/dist/providers/oauth/codex-oauth.d.ts +1 -1
- package/dist/providers/oauth/codex-oauth.d.ts.map +1 -1
- package/dist/providers/oauth/codex-oauth.js +9 -1
- package/dist/providers/oauth/codex-oauth.js.map +1 -1
- package/dist/providers/subscription-cli.d.ts +1 -1
- package/dist/providers/subscription-cli.d.ts.map +1 -1
- package/dist/providers/subscription-cli.js +33 -4
- package/dist/providers/subscription-cli.js.map +1 -1
- package/package.json +10 -10
- package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-Cu-YgIe4.js +0 -88
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import{c as ze,r as f,a as te,j as t,d as $t,g as ot,l as ye,b7 as ei,f as lt,L as Qe,aK as ti,ba as lr,B as ut,e as ar,u as Mt,t as dr,a5 as ni,bb as Ge,E as ri,H as ii,bc as si,w as oi,S as Ve,aH as cr,b as Et,b9 as Xe,P as it,D as li,G as ur,bd as ai,b0 as en,a0 as Ot,ar as di}from"./index-mQd_pC-P.js";import{S as qt,P as ci,F as at,E as ui,M as pi,R as un,d as pn,e as fi,A as gi,g as hi,u as xi}from"./usePersistedAgentThreadId-DBu97YaM.js";import{C as yi}from"./AiBuildResult-DLKFAe6R.js";import{T as Qt}from"./triangle-alert-D5Ng-xZO.js";import{U as mi}from"./user-round-BK5N1cJW.js";import{X as Ct}from"./x-stiJ-sP7.js";import{L as dt}from"./list-tree-j0s4asFK.js";import{W as Lt}from"./wrench-C-zLCMbW.js";import{M as bi}from"./minimize-2-Cl4pef4s.js";import{A as vi}from"./arrow-right-BmUAb1aW.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 ji=[["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"}]],Si=ze("archive",ji);/**
|
|
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 wi=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],pr=ze("chevron-up",wi);/**
|
|
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 ki=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],Ai=ze("circle",ki);/**
|
|
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 qi=[["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"}]],fr=ze("copy",qi);/**
|
|
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 Ci=[["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"}]],zt=ze("lightbulb",Ci);/**
|
|
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 zi=[["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"}]],tn=ze("route",zi);/**
|
|
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 Ri=[["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"}]],fn=ze("save",Ri);/**
|
|
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 Ii=[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]],_i=ze("send",Ii);/**
|
|
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 Ti=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],$n=ze("square",Ti);/**
|
|
47
|
-
* @license lucide-react v0.563.0 - ISC
|
|
48
|
-
*
|
|
49
|
-
* This source code is licensed under the ISC license.
|
|
50
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
51
|
-
*/const Bi=[["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"}]],$i=ze("zap",Bi),Vt=[{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 Mn({t:e,value:n,onChange:r}){const[i,s]=f.useState(null),[o,a]=f.useState(!1),d=f.useRef(null);f.useEffect(()=>{let g=!1;return te.getProviderSettings().then(({providers:l})=>{g||s(l.find(c=>c.active)??null)}).catch(()=>{}),()=>{g=!0}},[]),f.useEffect(()=>{if(!o)return;const g=l=>{d.current&&!d.current.contains(l.target)&&a(!1)};return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[o]);const u=Vt.find(g=>g.mode===n)??Vt[0],x=i?[i.label,i.model].filter(Boolean).join(" · "):null;return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[x?t.jsxs("span",{title:"Connected model",style:En(e),children:[t.jsx(Ai,{size:7,fill:e.success,color:e.success}),t.jsx("span",{style:{color:e.textSecondary},children:x})]}):null,t.jsxs("div",{ref:d,style:{position:"relative"},children:[t.jsxs("button",{type:"button",onClick:()=>a(g=>!g),title:"How hard the model thinks for this thread",style:{...En(e),cursor:"pointer"},children:[t.jsx($i,{size:12,color:e.textMuted}),t.jsxs("span",{style:{color:e.textSecondary},children:["Thinking: ",u.label]}),t.jsx($t,{size:12,color:e.textMuted})]}),o?t.jsx("div",{role:"menu",style:Mi(e),children:Vt.map(g=>{const l=g.mode===n;return t.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":l,onClick:()=>{r(g.mode),a(!1)},style:Ei(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:g.label}),l?t.jsx(ot,{size:13,color:e.accent}):null]}),t.jsx("span",{style:{display:"block",fontSize:11,color:e.textMuted,marginTop:2},children:g.hint})]},g.mode)})}):null]})]})}function En(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 Mi(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 Ei(e,n){return{display:"block",width:"100%",textAlign:"left",padding:"8px 10px",borderRadius:7,border:"none",background:n?e.pillBg:"transparent",cursor:"pointer"}}const Li={draft:"#8b949e",review:"#d29922",certified:"#3fb950",deprecated:"#f85149",pending_recertification:"#db6d28"},Wi={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"},Di={draft:lr,queued:ti,generating:Qe,running:Qe,saving:Qe,ready:lt,saved:lt,blocked:Qt,needs_attention:Qt,review:ei,certified:ye,deprecated:Si,pending_recertification:Qt},Pi=new Set(["generating","running","saving"]);function Ni(e){return Li[e]??Wi[e]??"#8b949e"}function Hi(e){return Fi[e]??e.charAt(0).toUpperCase()+e.slice(1).replace(/_/g," ")}function Oi({status:e,t:n,label:r}){const i=Ni(e),s=Di[e]??lr,o=r??Hi(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:Pi.has(e)?"spin":void 0}),o]})}function Qi(e){const{t:n,name:r,status:i="draft",description:s,dql:o,sqlPreview:a,grain:d,outputs:u=[],dimensions:x=[],entities:g=[],examples:l=[],sourceTables:c=[],evidence:b=[],certifierVerdict:h,owner:v,actions:m}=e,[q,P]=f.useState(!1),[$,L]=f.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(ut,{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(Oi,{status:i,t:n}),d?t.jsxs("span",{style:nn(n),children:["grain ",d]}):null]}),s?t.jsx("div",{style:{fontSize:12,color:n.textSecondary,lineHeight:1.5},children:s}):null,o?t.jsx(Ln,{open:q,onToggle:()=>P(C=>!C),label:"Governed DQL",t:n,lead:!0,children:t.jsx("pre",{style:Wn(n),children:o})}):null,a?t.jsx(Ln,{open:$,onToggle:()=>L(C=>!C),label:o?"Compiled SQL preview":"SQL this block will run",t:n,children:t.jsx("pre",{style:Wn(n),children:a})}):null,t.jsx(Gt,{label:"Outputs",items:u,t:n}),t.jsx(Gt,{label:"Dimensions",items:x,t:n}),t.jsx(Gt,{label:"Entities",items:g,t:n}),l.length>0?t.jsxs("div",{style:{display:"grid",gap:5},children:[t.jsx(gr,{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(C=>t.jsx("li",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.45},children:C},C))})]}):null,c.length>0||b.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(ye,{size:12,color:n.accent})," Grounded on"]}),c.length>0?t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:c.map(C=>t.jsx("span",{style:nn(n),children:C},C))}):null,b.slice(0,5).map((C,M)=>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:C.name}),t.jsxs("div",{style:{fontSize:10,color:n.textMuted,marginTop:3},children:[C.kind,C.reason?` · ${C.reason}`:""]}),C.description?t.jsx("div",{style:{fontSize:11,color:n.textMuted,lineHeight:1.35,marginTop:5},children:C.description}):null]},`${C.objectKey??C.name}-${M}`))]}):null,t.jsx(yi,{t:n,verdict:h}),v?t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11,color:n.textMuted},children:[t.jsx(mi,{size:12,strokeWidth:2})," drafting as ",v]}):null,m?t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:m}):null]})}function Ln({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($t,{size:13,strokeWidth:2}):t.jsx(ar,{size:13,strokeWidth:2}),e?`Hide ${r.toLowerCase()}`:r]}),e?t.jsx("div",{style:{marginTop:7},children:o}):null]})}function Gt({label:e,items:n,t:r}){return n.length===0?null:t.jsxs("div",{style:{display:"grid",gap:5},children:[t.jsx(gr,{t:r,children:e}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:n.map(i=>t.jsx("span",{style:nn(r),children:i},i))})]})}function gr({t:e,children:n}){return t.jsx("div",{style:{fontSize:10,fontWeight:800,letterSpacing:"0.05em",textTransform:"uppercase",color:e.textMuted},children:n})}function nn(e){return{fontSize:10.5,fontWeight:700,color:e.textSecondary,background:e.pillBg,borderRadius:999,padding:"2px 8px",fontFamily:e.fontMono}}function Wn(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 Fn(){return t.jsx("span",{style:{color:"#ff7b72",marginLeft:2},children:"*"})}function Kt(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 Dn({cell:e,onClose:n,onSaved:r,initialContent:i,initialName:s,initialDescription:o,initialTags:a,initialDomain:d,initialOwner:u}){var Z;const{state:x,dispatch:g}=Mt(),l=dr[x.themeMode],c=f.useRef(null),[b,h]=f.useState(s||e.name||"new_block"),[v,m]=f.useState(d??""),[q,P]=f.useState(u??""),[$,L]=f.useState(o??x.notebookMetadata.description??""),[C,M]=f.useState((a??x.notebookMetadata.categories??[]).join(", ")),[Q,B]=f.useState(i??e.content),[W,H]=f.useState(""),[ne,A]=f.useState(""),[J,R]=f.useState([]),[w,K]=f.useState(!1),[U,X]=f.useState(null),T=f.useMemo(()=>Vi(Q),[Q]),E=f.useMemo(()=>C.split(",").map(p=>p.trim()).filter(Boolean),[C]),re=[{id:"has-name",label:"Block has name",severity:"error",passed:!!b.trim()},{id:"has-owner",label:"Block has owner",severity:"error",passed:!!q.trim()},{id:"has-description",label:"Description",severity:"warning",passed:!!$.trim()},{id:"has-domain",label:"Domain",severity:"warning",passed:!!v.trim()},{id:"has-tags",label:"Has at least one tag",severity:"warning",passed:E.length>0},{id:"has-llm-context",label:"Has LLM context (for agents)",severity:"warning",passed:!!W.trim()}],V=re.some(p=>p.severity==="error"&&!p.passed);f.useEffect(()=>{var p;(p=c.current)==null||p.focus()},[]),f.useEffect(()=>{const p=I=>{I.key==="Escape"&&n()};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[n]);const pe=ni(v,x.authoredDomains),le=`${v.trim()?`blocks/${Kt(v)}/`:"blocks/"}${Kt(b)||"new-block"}.dql`,G=async()=>{var p,I,ee;if(V){X("Enter the block name and owner before saving.");return}if(!Q.trim()){X("Block content is required.");return}K(!0),X(null);try{const ie=ne.split(`
|
|
52
|
-
`).map(k=>k.trim()).filter(Boolean),ve=J.map(k=>({question:k.question.trim(),sql:k.sql.trim()||void 0})).filter(k=>k.question),xe=await te.saveAsBlock({cellId:e.id,notebookPath:((p=x.activeFile)==null?void 0:p.path)??null,name:b.trim(),domain:v.trim()||void 0,owner:q.trim()||void 0,content:Q,description:$.trim()||void 0,tags:E,metricRefs:T,llmContext:W.trim()||void 0,examples:ve.length>0?ve:void 0,invariants:ie.length>0?ie:void 0,reviewRequired:!!((I=e.datasetRefs)!=null&&I.length),datasetRefs:e.datasetRefs,lineage:(ee=e.dqlArtifact)==null?void 0:ee.lineage}),De={name:`${Kt(b)||"new-block"}.dql`,path:xe.path,type:"block",folder:"blocks"};x.files.some(k=>k.path===xe.path)||g({type:"FILE_ADDED",file:De});const Pe=await te.openBlockStudio(xe.path);g({type:"OPEN_BLOCK_STUDIO",file:De,payload:Pe}),r==null||r({...xe,name:b.trim()}),n()}catch(ie){X(ie instanceof Error?ie.message:String(ie))}finally{K(!1)}},S={width:"100%",background:l.inputBg,border:`1px solid ${U?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:p=>{p.target===p.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(Fn,{})]}),t.jsx("input",{ref:c,value:b,onChange:p=>h(p.target.value),style:S})]}),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.jsxs("select",{value:v,onChange:p=>m(p.target.value),style:S,children:[t.jsx("option",{value:"",children:"Global / cross-domain"}),pe.map(p=>t.jsx("option",{value:p.value,disabled:p.disabled,children:p.label},p.value))]})]})]}),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(Fn,{})]}),t.jsx("input",{value:q,onChange:p=>P(p.target.value),style:S,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:C,onChange:p=>M(p.target.value),style:S,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:$,onChange:p=>L(p.target.value),style:S})]}),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:W,onChange:p=>H(p.target.value),rows:3,placeholder:'One paragraph. E.g. "Monthly revenue recognized from closed-won deals, grouped by billing month. Excludes refunds."',style:{...S,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:ne,onChange:p=>A(p.target.value),rows:2,placeholder:`Revenue is never negative
|
|
53
|
-
Each row is a unique month`,style:{...S,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)"}),J.map((p,I)=>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:p.question,onChange:ee=>{const ie=[...J];ie[I]={...ie[I],question:ee.target.value},R(ie)},placeholder:"What was revenue last month?",style:S}),t.jsx("input",{value:p.sql,onChange:ee=>{const ie=[...J];ie[I]={...ie[I],sql:ee.target.value},R(ie)},placeholder:"Optional SQL snippet",style:{...S,fontFamily:l.fontMono,fontSize:12}})]}),t.jsx("button",{type:"button",onClick:()=>R(J.filter((ee,ie)=>ie!==I)),style:{background:"transparent",border:`1px solid ${l.cellBorder}`,borderRadius:6,color:l.textMuted,cursor:"pointer",fontSize:12,padding:"0 10px"},children:"×"})]},I)),t.jsx("button",{type:"button",onClick:()=>R([...J,{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:re.map(p=>{const I=p.passed?"#3fb950":p.severity==="error"?"#ff7b72":"#e3b341",ee=p.passed?"✓":p.severity==="error"?"✕":"!";return t.jsxs("span",{title:p.passed?`${p.label} — passed`:`${p.label} — ${p.severity}`,style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,fontFamily:l.font,color:I,background:`${I}18`,border:`1px solid ${I}55`,borderRadius:999,padding:"2px 10px"},children:[t.jsx("span",{style:{fontWeight:700},children:ee}),p.label]},p.id)})})]}),t.jsx("div",{style:{fontSize:12,color:l.textMuted,fontFamily:l.fontMono,padding:"8px 12px",background:l.pillBg,borderRadius:6},children:le}),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:Q,onChange:p=>B(p.target.value),style:{...S,minHeight:220,resize:"vertical",fontFamily:l.fontMono,lineHeight:1.5}})]}),T.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:"}),T.map(p=>t.jsx("span",{style:{fontSize:11,color:l.accent,fontFamily:l.fontMono,background:`${l.accent}18`,borderRadius:999,padding:"2px 8px"},children:p},p))]}),U&&t.jsx("div",{style:{fontSize:12,color:l.error,fontFamily:l.font},children:U})]}),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:(Z=e.datasetRefs)!=null&&Z.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:G,disabled:w||V,title:V?"Fix governance errors to enable Save":void 0,style:{background:l.accent,border:`1px solid ${l.accent}`,borderRadius:6,color:"#fff",cursor:w||V?"not-allowed":"pointer",fontSize:13,fontFamily:l.font,padding:"7px 20px",opacity:w||V?.5:1},children:w?"Saving & checking…":"Save block"})]})]})})}function hr(e){return e.policy==="dynamic"||e.policy==="optional"}function Gi({parameters:e,values:n,onChange:r,onReset:i,t:s,includeNonRuntime:o=!1,card:a=!1}){const d=e.filter(u=>o||hr(u));return d.length===0?null:t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(170px, 1fr))",gap:8},children:d.map(u=>{const x=Object.prototype.hasOwnProperty.call(n,u.name),g=x?n[u.name]:u.default,l=b=>r(u.name,b),c=u.type==="boolean"?t.jsxs("select",{"aria-label":u.name,value:String(g??""),onChange:b=>l(b.target.value),style:Pn(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":u.name,type:u.type==="number"?"number":u.type==="date"?"date":"text",value:Array.isArray(g)?g.join(", "):g==null?"":String(g),placeholder:u.type.endsWith("[]")?"Comma-separated values":u.required?"Required value":"Use default",onChange:b=>l(b.target.value),style:Pn(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:[Ki(u.name),u.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:[u.type,o?` · ${u.policy}`:""]}),x&&i?t.jsx("button",{type:"button",onClick:()=>i(u.name),style:{marginLeft:"auto",border:0,padding:0,background:"transparent",color:s.accent,fontSize:9.5,cursor:"pointer"},children:"Reset"}):null]})]},u.name)})})}function Ki(e){return e.replace(/[_-]+/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function Pn(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 Ui(e){const n=e.filter(o=>o.kind==="run").map(Yi).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=xr(Nn(r));return rn({activeSurface:"notebook",conversationStateVersion:1,activeTurnId:r.id,activeTopic:r.question,conversationSummary:ns(n),turns:n,sourceAnswerId:r.id,sourceCertifiedBlock:r.sourceCertifiedBlock,sourceQuestion:r.question,sourceAnswerSummary:r.answerSummary,answerContract:Nn(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??Ye(s==null?void 0:s.filters),requestedDimensions:r.requestedDimensions??Ye(s==null?void 0:s.dimensions),priorLimit:r.topN??yr(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 Yi(e){var l,c,b,h;const n=e.run.artifacts.find(v=>v.kind==="answer")??e.run.artifacts.find(v=>v.kind==="research_run")??e.run.artifacts[0],r=ce(n==null?void 0:n.payload),i=Ji(r),s=is(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=ce(r==null?void 0:r.contextPack))==null?void 0:l.questionPlan)??(r==null?void 0:r.analysisPlan),d=xr(a),u=os(s,o),x=rs(d,s),g=se(r==null?void 0:r.sourceCertifiedBlock)??((n==null?void 0:n.kind)==="answer"?se(n.ref):void 0)??se((c=ce(r==null?void 0:r.block))==null?void 0:c.name);return rn({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:g,route:se((b=ce(r==null?void 0:r.route))==null?void 0:b.label)??se((h=ce(r==null?void 0:r.route))==null?void 0:h.tier),trustLabel:se(r==null?void 0:r.trustLabel),reviewStatus:se(r==null?void 0:r.reviewStatus),certification:se(r==null?void 0:r.certification),contextPackId:se(r==null?void 0:r.contextPackId),requestedFilters:Ye(d==null?void 0:d.filters),requestedDimensions:Ye(d==null?void 0:d.dimensions),requestedMeasures:Ye(d==null?void 0:d.measures),answerContract:a,dqlArtifact:es(r),cascade:ts(r),topN:yr(d),result:s.length>0||o.length>0?rn({columns:s,rowsSample:o,dimensionValues:u,measureColumns:x,rowCount:Xi(i)}):void 0,sourceSql:Zi(r,i)})}function Nn(e){return e.answerContract}function xr(e){const n=ce(e);return ce(n==null?void 0:n.requestedShape)}function Ji(e){const n=ce(e==null?void 0:e.researchRun),r=ce(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(ce).filter(s=>!!(s&&(Array.isArray(s.rows)||Array.isArray(s.columns)))).sort((s,o)=>Hn(o)-Hn(s))[0]}function Hn(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 Xi(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 Zi(e,n){var r,i;return se(e==null?void 0:e.proposedSql)??se(e==null?void 0:e.sql)??se(n==null?void 0:n.sql)??se((r=ce(e==null?void 0:e.query))==null?void 0:r.sql)??se((i=ce(e==null?void 0:e.plan))==null?void 0:i.sql)}function es(e){var r,i;const n=Ge(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 ts(e){const n=ce(e==null?void 0:e.cascade);if(!n)return;const r=se(n.terminalLane),i=se(n.routeTier);if(!(!r&&!i))return{terminalLane:r,routeTier:i,label:se(n.label),ref:se(n.ref),artifactKind:se(n.artifactKind),refusalCode:se(n.refusalCode),outcome:ce(n.outcome)}}function ns(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(([d,u])=>`${d}: ${u.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(`
|
|
54
|
-
`):void 0}function yr(e){const n=ce(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 rs(e,n){const r=[...Ye(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 ce(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function is(e){const r=(Array.isArray(e==null?void 0:e.columns)?e.columns:[]).map(ss).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 Ye(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 ss(e){if(typeof e=="string"&&e.trim())return e.trim();if(e&&typeof e=="object"){const n=e;return se(n.name)??se(n.field)??se(n.key)}}function os(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 d=ce(a),u=d==null?void 0:d[s],x=typeof u=="string"||typeof u=="number"?String(u).trim():"";if(!(!x||o.includes(x))&&(o.push(x),o.length>=24))break}o.length>0&&(i[ls(s)]=o)}return Object.keys(i).length>0?i:void 0}function ls(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 se(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function rn(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 as(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 mr(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:On(n.rows.map(d=>d[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 d=On(n.rows.map(u=>u[a]));return[{column:a,field:s,values:d}]})}function ds(e,n,r,i){const s=mr(e,n).find(m=>m.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(m=>m.name)),a=cs(s.field.split(".").at(-1)??s.column);let d=a,u=2;for(;o.has(d);)d=`${a}_${u++}`;const x=Array.isArray(i)?i.map(String).join(", "):String(i),g=ri(x,d);let l=ii(e.source,{name:d,type:g,required:!1,defaultText:x,policy:"dynamic"});l=si(l,d,s.field);const c=oi(l).map(m=>{var q,P,$;return{...m,...((q=m.binding)==null?void 0:q.kind)==="semantic_filter"&&m.binding.field?{binding:{kind:"semantic_filter",field:m.binding.field,operator:m.binding.operator??"equals"}}:((P=m.binding)==null?void 0:P.kind)==="limit"?{binding:{kind:"limit"}}:(($=m.binding)==null?void 0:$.kind)==="sql_value"?{binding:{kind:"sql_value"}}:{binding:void 0}}}),{executionReceipt:b,compiledSql:h,...v}=e;return{artifact:{...v,source:l,parameters:c,parameterValues:{...e.parameterValues??{},[d]:i}},parameterName:d}}function On(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 cs(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 br(e,n,r){return e.map(i=>i.kind==="run"&&i.run.id===n?{kind:"run",id:r.id,run:r}:i)}function vr(e){var r,i,s;const n=[];for(const o of e){if(o.kind==="user"){n.push({role:"user",text:o.text});continue}if(o.run.status==="blocked"||((r=o.run.artifacts)==null?void 0:r.some(d=>{const u=oe(d);return!!(u.executionError||u.warehouseFailure||u.analyticalFailure)}))){((i=n.at(-1))==null?void 0:i.role)==="user"&&n.pop();continue}n.push({role:"assistant",text:((s=o.run.answer)==null?void 0:s.trim())||o.run.summary})}return n.slice(-12)}const gn="dql.agent.active-runs.v1",jr={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",modeling_draft:"Modeling proposal",skill_draft:"Skill proposal",app_build:"App plan",clarify:"Clarify",blocked:"Blocked"};function us({themeMode:e,title:n="AI Copilot",scopeHint:r="Auto routes to answer, research, SQL, block, or app",composerPlaceholder:i="Ask anything about your data…",onClearScope:s,examplePrompts:o,emptyHint:a,notebookPath:d,selectedObject:u,workspaceContext:x,initialMode:g="auto",initialInput:l="",initialItems:c,onItemsChange:b,threadId:h,onThreadIdChange:v,audience:m="analyst",autoRun:q,onInsertSql:P,onInsertDql:$,onReplaceDql:L,onArtifactReady:C,onReviewAuthoringProposal:M,onOpenBlock:Q,onOpenResearch:B,onOpenApp:W,onRunningChange:H,answerFirstCards:ne=!1,insertDqlActionLabel:A,replaceDqlActionLabel:J,askLayout:R=!1}){const w=dr[e],K=f.useRef(void 0),[U,X]=f.useState(l),[T,E]=f.useState(c??[]),[re,V]=f.useState([]),[pe,le]=f.useState(""),[G,S]=f.useState(!1),[Z,p]=f.useState(null),[I,ee]=f.useState(null),[ie,ve]=f.useState(null),[xe,De]=f.useState(()=>ps()),[Pe,k]=f.useState([]),[ae,$e]=f.useState(),jn=f.useCallback(y=>{De(y);try{window.localStorage.setItem(Sr,y)}catch{}},[]),et=f.useRef(null),Sn=f.useRef(l),wn=f.useRef(null),Ke=f.useRef(null),je=f.useRef(null),Ne=f.useRef(null),fe=f.useRef(null),Me=f.useRef(0),gt=f.useRef(""),Ee=f.useRef(null),tt=f.useCallback(()=>{gt.current="",Ee.current!==null&&(window.cancelAnimationFrame(Ee.current),Ee.current=null),le("")},[]),Vr=f.useCallback(y=>{gt.current+=y,Ee.current===null&&(Ee.current=window.requestAnimationFrame(()=>{Ee.current=null;const j=gt.current;gt.current="",j&&le(_=>_+j)}))},[]);f.useEffect(()=>()=>{Ee.current!==null&&window.cancelAnimationFrame(Ee.current)},[]);const qe=x==null?void 0:x.executionTarget,kn=qe&&typeof qe=="object"&&!Array.isArray(qe)&&qe.target==="connection"&&typeof qe.connectionName=="string"?String(qe.connectionName):void 0,Gr=qe&&typeof qe=="object"&&!Array.isArray(qe)&&qe.target==="local";f.useEffect(()=>{let y=!1;return te.getConnections().then(j=>{if(y)return;const _=Object.keys(j.connections??{}).sort((F,D)=>F.localeCompare(D));k(_),$e(wr(_,j.default,kn))}).catch(()=>{y||(k([]),$e(void 0))}),()=>{y=!0}},[kn]);const An=f.useCallback(y=>{$e(y)},[]),[Le,ht]=f.useState(null),[Re,Ue]=f.useState(null),[Kr,Pt]=f.useState(""),qn=f.useRef(null),xt=f.useRef(null);f.useEffect(()=>{!l||G||l!==Sn.current&&(Sn.current=l,X(l))},[l,G]);const Ur=f.useMemo(()=>vr(T),[T]),yt=f.useRef(b);yt.current=b;const He=f.useRef(C);He.current=C,f.useEffect(()=>{var y;(y=yt.current)==null||y.call(yt,T)},[T]);const ge=f.useRef(h),mt=f.useRef(v);mt.current=v;const Nt=f.useCallback((y,j)=>{var _;if(fe.current!==null&&(window.clearTimeout(fe.current),fe.current=null),Ut(y.id),je.current===y.id&&(je.current=null),Ne.current=null,p(null),V(y.events.slice(-8)),tt(),E(F=>{if(F.some(O=>O.kind==="run"&&O.run.id===y.id))return F.map(O=>O.kind==="run"&&O.run.id===y.id?{...O,id:y.id,run:y}:O);const D=F.some(O=>O.kind==="user"&&O.text===j.question);return[...F,...D?[]:[{kind:"user",id:`${y.id}-question`,text:j.question}],{kind:"run",id:y.id,run:y}]}),y.route!=="certified_answer"){const F=_t(y);F&&((_=He.current)==null||_.call(He,F,y))}},[tt]),Cn=f.useCallback((y,j)=>{var F;E(D=>br(D,y,j)),ht(D=>{if(!D||D.runId!==y)return D;const O=j.artifacts[0];return O?{runId:j.id,artifactId:O.id,tab:D.tab}:null}),ve(null);const _=_t(j);_&&((F=He.current)==null||F.call(He,_,j))},[]),nt=f.useCallback(y=>{fe.current!==null&&window.clearTimeout(fe.current);const j=++Me.current;je.current=y.id,Ne.current=y,p(y),S(!0),tt(),V([]);const _=async()=>{if(!(j!==Me.current||je.current!==y.id))try{const F=await te.getAgentRunState(y.id);if(j!==Me.current||je.current!==y.id)return;if(F.lifecycleState==="terminal"){Nt(F.run,y),S(!1);return}V(F.progress.events.slice(-8)),fe.current=window.setTimeout(()=>{_()},600)}catch{if(j!==Me.current||je.current!==y.id)return;fe.current=window.setTimeout(()=>{_()},1200)}};return _(),()=>{j===Me.current&&(Me.current+=1),fe.current!==null&&(window.clearTimeout(fe.current),fe.current=null)}},[Nt]),zn=f.useRef(!1);f.useEffect(()=>{if(!h||zn.current)return;zn.current=!0,ge.current??(ge.current=h);let y=!1;return te.getAgentThread(h).then(({turns:j,runs:_})=>{y||j.length===0||E(F=>{const D=F.filter(de=>de.kind==="run").length,O=kr(j,_);if(j.length>=D)return O;const ue=new Map(O.flatMap(de=>de.kind==="run"?[[de.run.id,de.run]]:[]));return F.map(de=>de.kind==="run"&&ue.has(de.run.id)?{...de,run:ue.get(de.run.id)}:de)})}).catch(()=>{!y&&ge.current===h&&(ge.current=void 0)}),()=>{y=!0}},[h]),f.useEffect(()=>{const y=Kn(h??ge.current);if(!(!y||Ke.current))return nt(y)},[nt,h]),f.useEffect(()=>{const y=()=>{if(document.visibilityState!=="visible"||Ke.current)return;const j=Ne.current??Kn(h??ge.current);j&&nt(j)};return document.addEventListener("visibilitychange",y),()=>document.removeEventListener("visibilitychange",y)},[nt,h]);const Ie=async(y,j,_,F,D)=>{var In,_n,Tn;const O=(y??U).trim();if(!O||G)return;const ue=j??K.current??g;K.current=void 0;const de={kind:"user",id:er("user"),text:O};E(be=>[...be,de]),X(""),ve(null),S(!0),V([]),tt();const Oe=new AbortController;Ke.current=Oe;const Ce=er("run");let me={id:Ce,question:O,threadId:ge.current,startedAt:new Date().toISOString()};je.current=Ce,Ne.current=me,p(me),Gn(me);let wt=!1,Se=!1;try{if(!ge.current)try{const he=await te.createAgentThread({surface:R?"ask":typeof(x==null?void 0:x.surface)=="string"?x.surface:d?"notebook":"agent",title:O,...d?{notebookPath:d}:{}});ge.current=he.id,(In=mt.current)==null||In.call(mt,he.id),me={...me,threadId:he.id},Ne.current=me,p(me),Gn(me)}catch{}const be=ue==="modeling"||ue==="skill"?(_n=[...T].reverse().find(he=>he.kind==="run"&&he.run.artifacts.some(Ht=>Ht.kind===(ue==="modeling"?"modeling_change_proposal":"skill_change_proposal"))))==null?void 0:_n.run:void 0,Bn=be==null?void 0:be.artifacts.find(he=>he.kind===(ue==="modeling"?"modeling_change_proposal":"skill_change_proposal")),Xr={question:O,..._?{selectedEvidenceId:_}:{},...F?{clarificationSourceQuestion:F}:{},requestedMode:ue,audience:m,selectedObject:u??(d?{kind:"notebook",path:d}:void 0),...D!=null&&D.executionTarget?{executionTarget:D.executionTarget}:Gr?{executionTarget:{target:"local"}}:ae?{executionTarget:{target:"connection",connectionName:ae}}:{},workspaceContext:{...x??{},...d?{notebookPath:d}:{},...D?{researchSource:Br(D)}:{},...be&&Bn?{sourceRunId:be.id,sourceArtifactId:Bn.id,revision:(((Tn=be.derivation)==null?void 0:Tn.revision)??1)+1}:{}},conversationContext:Ui(T),history:Ur,thinkingMode:xe,runId:Ce,...ge.current?{threadId:ge.current}:{}},Zr=await te.createAgentRunStream(Xr,he=>{wt=!0,he.kind==="event"?V(Ht=>[...Ht,he.event].slice(-8)):he.kind==="answer-delta"?Vr(he.delta):V(he.run.events.slice(-8))},Oe.signal);Nt(Zr,me)}catch(be){Oe.signal.aborted||(ve(be instanceof Error?be.message:String(be)),X(O),wt?(Se=!0,nt(me)):(Ut(Ce),je.current===Ce&&(je.current=null),Ne.current=null,p(null)))}finally{Ke.current===Oe&&(Ke.current=null),Se||S(!1)}},bt=()=>{Ie()},Rn=()=>{var j;const y=je.current;y&&te.cancelAgentRun(y).catch(()=>{}),(j=Ke.current)==null||j.abort(),Me.current+=1,fe.current!==null&&window.clearTimeout(fe.current),Ut(y??""),je.current=null,Ne.current=null,p(null),tt(),V([]),S(!1),ve("Stopped. No answer or draft was saved.")},vt=f.useRef(H);vt.current=H,f.useEffect(()=>{var y;(y=vt.current)==null||y.call(vt,G)},[G]),f.useEffect(()=>{!(q!=null&&q.text)||G||wn.current!==q.nonce&&(wn.current=q.nonce,Ie(q.text,q.mode??g))},[q==null?void 0:q.nonce,q==null?void 0:q.text,q==null?void 0:q.mode,g,G]),f.useEffect(()=>()=>{Me.current+=1,fe.current!==null&&window.clearTimeout(fe.current)},[]);const jt={appId:typeof(x==null?void 0:x.appId)=="string"?x.appId:void 0,dashboardId:typeof(x==null?void 0:x.dashboardId)=="string"?x.dashboardId:void 0,dashboardTitle:typeof(x==null?void 0:x.dashboardTitle)=="string"?x.dashboardTitle:void 0},St=(y,j)=>{var _,F;if(j.id==="review-modeling-proposal"||j.id==="review-skill-proposal"){const D=j.id==="review-modeling-proposal"?"modeling_change_proposal":"skill_change_proposal",O=y.artifacts.find(ue=>ue.kind===D);if(!O){ve("This authoring run does not include a reviewable proposal.");return}if(M)M(O,y);else if(O.ref){try{window.sessionStorage.setItem("dql-context-proposal-handoff",O.ref)}catch{}window.dispatchEvent(new CustomEvent("dql:open-context-proposal",{detail:{proposalId:O.ref,kind:O.kind}}))}return}if(j.id==="save-dql-block"){const D=Ae(y),O=((_=D==null?void 0:D.source)==null?void 0:_.trim())??((F=ke(y))==null?void 0:F.trim());if(!O){ve("This answer does not include a reusable DQL or SQL artifact yet.");return}ee({runId:y.id,source:O,name:(D==null?void 0:D.name)??`${y.question.slice(0,48).trim()||"saved_answer"}`,dqlArtifact:D});return}if(j.id==="research-deeper"){Ie(y.question,"research",void 0,void 0,y);return}if(j.id.startsWith("suggest-question")){Ie(j.label,"auto");return}K.current=Ms(j.route),X(Es(y,j.route)),requestAnimationFrame(()=>{var D;return(D=et.current)==null?void 0:D.focus()})},Yr=f.useCallback((y,j,_="trust")=>{ht({runId:y,artifactId:j,tab:_})},[]),Jr=f.useCallback(y=>{var F,D;const j=y.trim();if(!j)return;const _=(F=Re==null?void 0:Re.text)==null?void 0:F.trim();Ue(null),Pt("");try{(D=window.getSelection())==null||D.removeAllRanges()}catch{}Ie(_?`${j}
|
|
55
|
-
|
|
56
|
-
Regarding: "${_}"`:j),requestAnimationFrame(()=>{xt.current&&(xt.current.scrollTop=xt.current.scrollHeight)})},[Re,Ie]);if(f.useEffect(()=>{if(!R)return;const y=_=>{const F=_.target;F&&F.closest("[data-selpop]")||window.setTimeout(()=>{const D=window.getSelection(),O=D&&D.rangeCount?D.toString().trim():"";if(!O||O.length<3){Ue(Se=>Se&&null);return}const ue=D.anchorNode,de=ue&&(ue.nodeType===1?ue:ue.parentElement),Oe=de==null?void 0:de.closest("[data-followup]");if(!Oe){Ue(Se=>Se&&null);return}const Ce=D.getRangeAt(0).getBoundingClientRect(),me=Math.max(12,Math.min(Ce.left,window.innerWidth-340)),wt=Ce.bottom+176>window.innerHeight?Math.max(12,Ce.top-176):Ce.bottom+8;Ue({text:O.slice(0,220),source:Oe.getAttribute("data-followup")||"answer",left:me,top:wt}),Pt(""),requestAnimationFrame(()=>{var Se;return(Se=qn.current)==null?void 0:Se.focus()})},0)},j=_=>{_.key==="Escape"&&Ue(null)};return document.addEventListener("mouseup",y),document.addEventListener("keydown",j),()=>{document.removeEventListener("mouseup",y),document.removeEventListener("keydown",j)}},[R]),R){const y=Le?(()=>{const j=T.find(F=>F.kind==="run"&&F.run.id===Le.runId);if(!j||j.kind!=="run")return null;const _=j.run.artifacts.find(F=>F.id===Le.artifactId);return _?{run:j.run,artifact:_}:null})():null;return t.jsxs("div",{style:{display:"flex",height:"100%",minHeight:0,flex:1,minWidth:0,width:"100%",background:"var(--bg-canvas)"},children:[I?t.jsx(Dn,{cell:{id:`agent-${I.runId}`,type:I.dqlArtifact?"dql":"sql",content:I.source,name:I.name,status:"success",...I.dqlArtifact?{dqlArtifact:I.dqlArtifact}:{}},initialContent:I.source,initialName:I.name,onClose:()=>ee(null),onSaved:()=>ee(null)}):null,t.jsx("style",{children:js}),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(Ve,{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:xt,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:[T.length===0&&!G?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:tr(w),children:t.jsx(Ve,{size:20})}),t.jsx("div",{style:{fontSize:13.5,lineHeight:1.5,maxWidth:400,color:w.textSecondary},children:a??Qn}),t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap",justifyContent:"center",maxWidth:520},children:(o??Vn).map(j=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>{X(j.prompt),requestAnimationFrame(()=>{var _;return(_=et.current)==null?void 0:_.focus()})},style:Tt(w),children:j.label},j.label))})]}):null,T.map(j=>j.kind==="user"?t.jsx("div",{style:Ss(w),children:j.text},j.id):t.jsx(Zn,{run:j.run,t:w,themeMode:e,threadId:ge.current,appContext:jt,selectedArtifactId:(Le==null?void 0:Le.runId)===j.run.id?Le.artifactId:void 0,onOpenArtifact:(_,F)=>Yr(j.run.id,_,F),onOpenApp:W,onInsertSql:P,onInsertDql:$,onOpenBlock:Q,onOpenResearch:B,onSelectClarification:_=>{const F=At(_);Ie(F.question,void 0,F.selectedEvidenceId,j.run.question)},onNextAction:_=>St(j.run,_),onRepairedRun:Cn},j.id)),G&&t.jsx(Yn,{events:re,t:w,streamingAnswer:pe,thinkingMode:xe,backgroundRun:Z})]}),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,s?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:s,"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(Ct,{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:et,value:U,onChange:j=>{X(j.target.value),K.current=void 0},rows:2,placeholder:i,onKeyDown:j=>{j.key==="Enter"&&!j.shiftKey&&(j.preventDefault(),bt())},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(Mn,{t:w,value:xe,onChange:jn}),t.jsx(Un,{names:Pe,value:ae,onChange:An,t:w}),t.jsx("div",{style:{flex:1}}),G?t.jsxs("button",{type:"button",className:"dql-hover",onClick:Rn,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($n,{size:13,fill:"currentColor"})," Stop"]}):null,t.jsx("button",{type:"button",className:"dql-hover dql-lift",title:"Ask",onClick:bt,disabled:!U.trim()||G,style:{width:34,height:34,borderRadius:10,border:"none",background:U.trim()&&!G?"var(--accent)":"var(--bg-4)",color:"#fff",display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:U.trim()&&!G?"pointer":"default",boxShadow:U.trim()&&!G?"0 1px 5px rgba(107,93,211,0.3)":"none"},children:G?t.jsx(Qe,{size:15,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(cr,{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."})]})]})]}),y?t.jsx(Cs,{run:y.run,artifact:y.artifact,tab:Le.tab,t:w,appContext:jt,onOpenApp:W,onChangeTab:j=>ht(_=>_&&{..._,tab:j}),onClose:()=>ht(null),onSaveBlock:()=>St(y.run,{id:"save-dql-block",label:"Save as block",route:"dql_block_draft"}),onInsertSql:P,onInsertDql:$}):null,Re?t.jsx(zs,{t:w,text:Re.text,source:Re.source,left:Re.left,top:Re.top,draft:Kr,inputRef:qn,onDraftChange:Pt,onClose:()=>Ue(null),onSend:Jr}):null]})}return t.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0,flex:1,minWidth:0,width:"100%",background:w.cellBg},children:[I?t.jsx(Dn,{cell:{id:`agent-${I.runId}`,type:I.dqlArtifact?"dql":"sql",content:I.source,name:I.name,status:"success",...I.dqlArtifact?{dqlArtifact:I.dqlArtifact}:{}},initialContent:I.source,initialName:I.name,onClose:()=>ee(null),onSaved:()=>ee(null)}):null,t.jsx("style",{children:`
|
|
57
|
-
@keyframes dql-agent-run-spin { to { transform: rotate(360deg); } }
|
|
58
|
-
@keyframes dql-agent-fadein { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
|
|
59
|
-
@keyframes dql-agent-thinking-dot { 0%, 65%, 100% { opacity: .28; transform: translateY(0); } 32% { opacity: 1; transform: translateY(-2px); } }
|
|
60
|
-
@keyframes dql-agent-activity-in { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
|
|
61
|
-
.dql-agent-thinking-dot { animation: dql-agent-thinking-dot 1.05s ease-in-out infinite; }
|
|
62
|
-
.dql-agent-activity { animation: dql-agent-activity-in .22s ease-out; }
|
|
63
|
-
.dql-hover { transition: filter .15s ease, transform .12s ease, box-shadow .15s ease, background .15s ease, color .15s ease, border-color .15s ease; }
|
|
64
|
-
.dql-hover:hover { filter: brightness(1.07); }
|
|
65
|
-
.dql-hover:active { transform: translateY(0.5px); }
|
|
66
|
-
.dql-lift:hover { transform: translateY(-1px); }
|
|
67
|
-
details > summary::-webkit-details-marker { display: none; }
|
|
68
|
-
@media (prefers-reduced-motion: reduce) { .dql-agent-thinking-dot, .dql-agent-activity { animation: none !important; } }
|
|
69
|
-
`}),t.jsxs("div",{style:{flex:1,minHeight:0,overflow:"auto",padding:"14px 16px",display:"flex",flexDirection:"column",gap:12},children:[T.length===0&&!G?t.jsxs("div",{style:{margin:"auto 0",display:"grid",gap:14,justifyItems:"center",textAlign:"center",color:w.textSecondary},children:[t.jsx("div",{style:tr(w),children:t.jsx(Ve,{size:20})}),t.jsx("div",{style:{fontSize:13,lineHeight:1.5,maxWidth:380,color:w.textSecondary},children:a??Qn}),t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap",justifyContent:"center",maxWidth:520},children:(o??Vn).map(y=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>{X(y.prompt),requestAnimationFrame(()=>{var j;return(j=et.current)==null?void 0:j.focus()})},style:Tt(w),children:y.label},y.label))})]}):null,T.map(y=>y.kind==="user"?t.jsx("div",{style:Ks(w),children:y.text},y.id):ne?t.jsx(Zn,{run:y.run,t:w,themeMode:e,threadId:ge.current,appContext:jt,onOpenApp:W,onInsertSql:P,onInsertDql:$,onReplaceDql:L,insertDqlActionLabel:A,replaceDqlActionLabel:J,onOpenBlock:Q,onOpenResearch:B,onSelectClarification:j=>{const _=At(j);Ie(_.question,void 0,_.selectedEvidenceId,y.run.question)},onNextAction:j=>St(y.run,j),onRepairedRun:Cn},y.id):t.jsx(vs,{run:y.run,t:w,themeMode:e,appContext:jt,onOpenApp:W,onInsertSql:P,onInsertDql:$,onOpenBlock:Q,onOpenResearch:B,onSelectClarification:j=>{const _=At(j);Ie(_.question,void 0,_.selectedEvidenceId,y.run.question)},onNextAction:j=>St(y.run,j)},y.id)),G&&t.jsx(Yn,{events:re,t:w,streamingAnswer:pe,thinkingMode:xe,backgroundRun:Z})]}),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}),s?t.jsx("button",{type:"button",onClick:s,"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(Ct,{size:12})}):null]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(Un,{names:Pe,value:ae,onChange:An,t:w}),t.jsx(Mn,{t:w,value:xe,onChange:jn})]})]}),t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-end"},children:[t.jsx("textarea",{ref:et,value:U,onChange:y=>{X(y.target.value),K.current=void 0},rows:2,placeholder:i,onKeyDown:y=>{y.key==="Enter"&&!y.shiftKey&&(y.preventDefault(),bt())},style:Qs(w)}),t.jsxs("button",{type:"button",className:"dql-hover dql-lift",onClick:bt,disabled:!U.trim()||G,style:nr(w,!!U.trim()&&!G),children:[G?t.jsx(Qe,{size:15,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(_i,{size:15}),t.jsx("span",{children:G?"Working":"Ask"})]}),G?t.jsxs("button",{type:"button",className:"dql-hover",onClick:Rn,style:{...nr(w,!0),background:w.btnBg,borderColor:w.error,color:w.error},title:"Stop the active agent run",children:[t.jsx($n,{size:13,fill:"currentColor"}),t.jsx("span",{children:"Stop"})]}):null]})]})]})}const Qn="Ask a question — every answer is grounded in your certified metrics and dbt lineage. Use Research deeper on any answer for a slower investigation.",Vn=[{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 hn(){try{const e=JSON.parse(window.localStorage.getItem(gn)??"[]");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 Gn(e){try{const n=hn().filter(r=>r.id!==e.id);window.localStorage.setItem(gn,JSON.stringify([...n,e].slice(-12)))}catch{}}function Ut(e){try{const n=hn().filter(r=>r.id!==e);window.localStorage.setItem(gn,JSON.stringify(n))}catch{}}function Kn(e){const n=hn().sort((r,i)=>i.startedAt.localeCompare(r.startedAt));return e?n.find(r=>r.threadId===e):n.find(r=>!r.threadId)}const Sr="dql.agent.thinkingMode";function wr(e,n,r){return r&&e.includes(r)?r:n&&e.includes(n)?n:e[0]}function Un({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(li,{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 ps(){try{const e=window.localStorage.getItem(Sr);return e==="low"||e==="medium"||e==="high"||e==="auto"?e:"auto"}catch{return"auto"}}const fs=new Set(["conversation","certified_answer","semantic_answer","generated_answer","research","sql_cell","dql_block_draft","modeling_draft","skill_draft","app_build","clarify","blocked"]),gs=new Set(["certified","governed","grounded","review_required","blocked","not_applicable"]),hs=new Set(["completed","needs_review","needs_clarification","blocked"]),xs=new Set(["conversational_reply","certified_answer_found","governed_semantic_answer","generated_review_required","artifact_created","needs_clarification","human_review_required","blocked"]);function kr(e,n=[]){const r=new Map(n.map(o=>[o.id,o])),i=new Set(e.flatMap(o=>o.agentRunId?[o.agentRunId]:[])),s=new Set(n.flatMap(o=>{const a=o.derivation;return(a==null?void 0:a.kind)==="analytical_repair"&&i.has(o.id)&&typeof a.sourceRunId=="string"?[a.sourceRunId]:[]}));return e.filter(o=>!o.agentRunId||!s.has(o.agentRunId)).flatMap(o=>{const a=o.agentRunId?r.get(o.agentRunId):void 0;return[{kind:"user",id:`${o.id}-q`,text:o.question},{kind:"run",id:(a==null?void 0:a.id)??o.id,run:a??ys(o)}]})}function ys(e){var x,g,l;const n=fs.has(e.route)?e.route:"generated_answer",r=gs.has(e.trustLabel)?e.trustLabel:e.certification==="certified"?"certified":"not_applicable",i=hs.has(e.runStatus)?e.runStatus:"completed",s=xs.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=(((x=e.result)==null?void 0:x.columns)??[]).filter(c=>typeof c=="string"),a=(((g=e.result)==null?void 0:g.rowsSample)??[]).filter(c=>Array.isArray(c)).map(c=>Object.fromEntries(o.map((b,h)=>[b,c[h]]))),d=o.length>0?{columns:o,rows:a,rowCount:((l=e.result)==null?void 0:l.rowCount)??a.length}:void 0,u=d||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}:{},...d?{result:d}:{},...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:u?[u]:[],evaluations:[],events:[],nextActions:[],repairAttempts:0}}function ms(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"modeling_draft":return"Resolved current models and relationship evidence";case"skill_draft":return"Resolved current domain guidance and governed references";case"clarify":return"Identified a missing business detail";default:return"Identified the best answer path"}}function bs(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"modeling_draft":return"Building a reviewable modeling proposal";case"skill_draft":return"Building a reviewable Skill proposal";case"clarify":return"Preparing a focused clarification";default:return"Preparing the answer"}}function sn(e){for(let n=e.length-1;n>=0;n-=1)if(e[n].route)return e[n].route}function Ar(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 qr(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 Cr(e,n=!1){if(e.length===0&&n)return[{id:"background",label:"Continuing this request in the background",state:"active"}];const r=sn(e);if(r==="conversation")return[];const i=e.some(d=>d.type==="route.decided"),s=e.some(d=>d.type==="executor.started"||d.type==="step.started"||d.type==="repair.attempted"||d.type==="escalated"),o=e.some(d=>d.type==="evaluation.recorded"),a=[{id:"search",label:"Resolving governed evidence and business meaning",state:i?"complete":"active"}];return i&&a.push({id:"match",label:ms(r),state:s||o?"complete":"active"}),(s||o)&&a.push({id:"execute",label:bs(r,e),state:o?"complete":"active"}),o&&a.push({id:"verify",label:"Checking the result against governed evidence",state:"active"}),a}function Yn({events:e,t:n,streamingAnswer:r,thinkingMode:i,backgroundRun:s}){var h;const[o,a]=f.useState(()=>Date.now());f.useEffect(()=>{const v=window.setInterval(()=>a(Date.now()),1e3);return()=>window.clearInterval(v)},[]);const d=(s==null?void 0:s.startedAt)??((h=e.find(v=>v.type==="run.started"))==null?void 0:h.at),u=d?Date.parse(d):o,x=Number.isFinite(u)?Math.max(0,Math.floor((o-u)/1e3)):0,g=Ar(x,sn(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(sn(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(Jn,{}),t.jsx("span",{style:{fontSize:13,lineHeight:1.4},children:"Replying…"})]});const c=Cr(e,!!s),b=x>=12?g==null?void 0:g.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(Jn,{}):t.jsx(ot,{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)),b?t.jsx("span",{style:{paddingLeft:25,fontSize:10.5,lineHeight:1.4,color:n.textMuted},children:b}):null]})}function Jn(){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 Xn({items:e,t:n,renderItem:r,cap:i=4}){const[s,o]=f.useState(!1),a=s?e:e.slice(0,i);return t.jsxs(t.Fragment,{children:[a.map((d,u)=>r(d,u)),e.length>i?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>o(d=>!d),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(pr,{size:11}):t.jsx($t,{size:11}),s?"Show less":`Show all (${e.length})`]}):null]})}function vs({run:e,t:n,themeMode:r,appContext:i,onOpenApp:s,onInsertSql:o,onInsertDql:a,onOpenBlock:d,onOpenResearch:u,onSelectClarification:x,onNextAction:g}){var ne;const{dispatch:l}=Mt();if(e.route==="conversation"){const A=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:Us(n),children:[A?t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:10.5,color:n.textMuted,marginBottom:6,fontWeight:650},children:[t.jsx(zt,{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(qt,{text:Je(e.answer),t:n}):e.summary})]}),e.nextActions.length>0?t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:e.nextActions.map(J=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>g(J),style:Tt(n),children:J.label},J.id))}):null]})}const c=e.steps??[],b=c.length>1,h=((ne=e.plan)==null?void 0:ne.source)==="llm",v=vn(e),m=mn(e),q=pt(e),P=e.route==="certified_answer"||e.route==="generated_answer",$=e.nextActions.some(A=>A.route==="research"),L=P&&q&&!$,C=Ae(e),M=q&&!(C!=null&&C.sourcePath)&&!!((C==null?void 0:C.source)??ke(e)),Q=Date.parse(e.startedAt),B=Date.parse(e.completedAt),W=Number.isFinite(Q)&&Number.isFinite(B)?Math.max(0,Math.round((B-Q)/1e3)):0,H=qr(W,e.route,e.trustState,e.repairAttempts);return t.jsxs("div",{style:Ys(n),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(Ts,{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(Bs,{run:e,t:n})]}),m?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(ye,{size:12,color:n.success,style:{flex:"0 0 auto",marginTop:1}}):e.trustState==="governed"||e.trustState==="grounded"?t.jsx(ye,{size:12,color:n.accent,style:{flex:"0 0 auto",marginTop:1}}):t.jsx(Xe,{size:12,color:n.warning,style:{flex:"0 0 auto",marginTop:1}}),t.jsx("span",{children:m})]}):null,h||b||e.repairAttempts>0?t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[h?t.jsx(Xt,{t:n,icon:t.jsx(dt,{size:11}),label:"AI plan",tone:"accent"}):null,b?t.jsx(Xt,{t:n,icon:t.jsx(tn,{size:11}),label:`${c.length} steps`,tone:"muted"}):null,e.repairAttempts>0?t.jsx(Xt,{t:n,icon:t.jsx(Lt,{size:11}),label:`${e.repairAttempts} repair${e.repairAttempts>1?"s":""}`,tone:"warning"}):null]}):null,e.summary&&!(e.answer&&Ls(Te(e.summary),Je(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:Js(n),children:t.jsx(qt,{text:Je(e.answer),t:n})}):null,t.jsx(Ir,{run:e,t:n,onSelect:x}),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(A=>t.jsxs("span",{style:Hr(n,A.certified),children:[A.certified?t.jsx(ye,{size:11}):t.jsx(at,{size:11}),t.jsx("span",{children:A.label})]},A.label))]}):null,t.jsx(Nr,{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(A=>t.jsx(Lr,{artifact:A,t:n,themeMode:r,onInsertSql:o,onInsertDql:a,sourceRunId:e.id,sourceQuestion:e.question,onOpenBlock:d,onOpenResearch:u,onOpenApp:s,onNextAction:g},A.id))}):null,b?t.jsx(Fr,{steps:c,t:n}):t.jsx(Wr,{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(dt,{size:12})," View steps · where the time went"]}):null,H?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(zt,{size:11,color:n.accent})," ",H.title]}),t.jsx("span",{style:{fontSize:10.5,color:n.textMuted,lineHeight:1.45},children:H.detail})]}):null,q||L||e.nextActions.length>0?t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[q?t.jsx(yn,{run:e,t:n,appContext:i,onOpenApp:s}):null,M?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>g({id:"save-dql-block",label:"Save as block",route:"dql_block_draft"}),style:Y(n),children:[t.jsx(fn,{size:11})," Save as block"]}):null,L?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>g({id:"research-deeper",label:"Research this deeper",route:"research"}),style:Y(n),title:"Run a slower, multi-step investigation on this question",children:[t.jsx(at,{size:11}),"Research this deeper"]}):null,e.nextActions.filter(A=>A.id!=="pin-to-app"&&A.id!=="research-deeper"&&A.id!=="confirm-app-build"&&A.id!=="request-certification").map(A=>t.jsx("button",{type:"button",className:"dql-hover",onClick:()=>g(A),style:Y(n),children:A.label},A.id))]}):null]})}function zr(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 js=`
|
|
70
|
-
@keyframes dql-agent-run-spin { to { transform: rotate(360deg); } }
|
|
71
|
-
@keyframes dql-agent-fadein { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
|
|
72
|
-
@keyframes dql-agent-thinking-dot { 0%, 65%, 100% { opacity: .28; transform: translateY(0); } 32% { opacity: 1; transform: translateY(-2px); } }
|
|
73
|
-
@keyframes dql-agent-activity-in { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
|
|
74
|
-
.dql-agent-thinking-dot { animation: dql-agent-thinking-dot 1.05s ease-in-out infinite; }
|
|
75
|
-
.dql-agent-activity { animation: dql-agent-activity-in .22s ease-out; }
|
|
76
|
-
.dql-hover { transition: filter .15s ease, transform .12s ease, box-shadow .15s ease, background .15s ease, color .15s ease, border-color .15s ease; }
|
|
77
|
-
.dql-hover:hover { filter: brightness(1.03); }
|
|
78
|
-
.dql-hover:active { transform: translateY(0.5px); }
|
|
79
|
-
.dql-lift:hover { transform: translateY(-1px); }
|
|
80
|
-
.dql-ask-ghost:hover { background: var(--bg-0); color: var(--text-primary) !important; }
|
|
81
|
-
.dql-ask-chip:hover { border-color: var(--accent) !important; box-shadow: 0 1px 6px rgba(107,93,211,0.12); }
|
|
82
|
-
details > summary::-webkit-details-marker { display: none; }
|
|
83
|
-
@media (prefers-reduced-motion: reduce) { .dql-agent-thinking-dot, .dql-agent-activity { animation: none !important; } }
|
|
84
|
-
`;function Ss(e){return{alignSelf:"flex-end",maxWidth:"82%",background:"var(--bg-0)",color:e.textPrimary,borderRadius:"16px 16px 4px 16px",padding:"10px 14px",fontSize:13.5,lineHeight:1.5,whiteSpace:"pre-wrap",animation:"dql-agent-fadein 0.25s ease-out"}}function We(e){return Et(e,{variant:"ghost",size:"sm"})}function Yt(e,n){return e.kind==="app_proposal"||e.kind==="dql_block_draft"||e.kind==="research_run"||!!Dt(n)}function Wt(e,n){var a,d;const r=[],i=Be(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)??((d=i==null?void 0:i.rows)==null?void 0:d.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 st(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 N(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function Rr(e){const n=[],r=new Set,i=(s,o)=>{const a=N(s);if(!a)return;const d=[a.name,a.label,a.relation,a.objectName].find(l=>typeof l=="string"&&l.trim().length>0);if(!d)return;const u=typeof a.kind=="string"?a.kind:o,x=`${u??""}:${d}`;if(r.has(x))return;r.add(x);const g=[a.description,a.provenance,a.sourceTier,a.source].find(l=>typeof l=="string"&&l.trim().length>0);n.push({name:d,kind:u,detail:g})};for(const s of e.artifacts){const o=oe(s),a=N(o.evidence);for(const x of["lineage","sourceTables","semanticObjects","selectedAssets"]){const g=a==null?void 0:a[x];Array.isArray(g)&&g.forEach(l=>i(l,x==="sourceTables"?"source":void 0))}const d=N(o.analysisPlan)??N(a==null?void 0:a.analysisPlan),u=d==null?void 0:d.candidateTables;Array.isArray(u)&&u.forEach(x=>i(x,"relation"))}return n.slice(0,24)}function xn(e,n){var i;const r=oe(n);return Ft(r)?"how":(i=Ae(e)??ft(r))!=null&&i.source?"dql":ke(e)??(typeof r.sql=="string"?r.sql:void 0)?"sql":Rr(e).length>0?"lineage":"trust"}function ws({run:e,artifact:n,selected:r,t:i,themeMode:s,onInspect:o}){const a=oe(n),d=Be(a),[u,x]=f.useState(!1);if(f.useEffect(()=>{if(!u)return;const v=m=>{m.key==="Escape"&&x(!1)};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[u]),!d)return null;const g=Dr(a,d),l=xn(e,n),c=Ae(e)??ft(a),b=n.trustState==="certified"?Er(n,a):void 0,h=t.jsxs("section",{"data-followup":"table","aria-label":`${st(e,n)} result`,style:{border:`1px solid ${r?"var(--accent)":"var(--border-default)"}`,borderRadius:12,background:"var(--bg-2)",overflow:"hidden",boxShadow:u?"0 24px 80px rgba(15,23,42,0.28)":r?"0 2px 10px rgba(107,93,211,0.12)":"0 1px 3px rgba(26,26,26,0.04)",...u?{width:"min(1440px, calc(100vw - 48px))",maxHeight:"calc(100vh - 48px)"}:{}},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(Ze,{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:st(e,n)}),t.jsx("div",{style:{fontSize:11,color:i.textMuted,marginTop:2},children:Wt(n,a)})]}),t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>o(l),style:We(i),children:[t.jsx(dt,{size:12})," Inspect"]}),t.jsxs("button",{type:"button",className:"dql-ask-ghost","aria-label":u?"Return result to Copilot":"Expand result",title:u?"Return result to Copilot":"Expand this result for wide tables",onClick:()=>x(v=>!v),style:We(i),children:[u?t.jsx(bi,{size:12}):t.jsx(pi,{size:12}),u?"Restore":"Expand result"]})]}),c?t.jsx(Mr,{artifact:c,certifiedBlockName:b,initialResult:d,initialChartConfig:g,payload:a,executionTarget:e.executionTarget,t:i,themeMode:s,embedded:!0,expanded:u}):t.jsx(un,{result:d,themeMode:s,t:i,chartConfig:g,embedded:!0,tabLabels:{table:"Results",chart:"Visualization"},contentMaxHeight:u?"calc(100vh - 172px)":void 0,tableMaxHeight:u?"calc(100vh - 250px)":void 0})]});return!u||typeof document>"u"?h:t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{minHeight:96,border:"1px dashed var(--border-default)",borderRadius:12,display:"grid",placeItems:"center",color:i.textMuted,fontSize:11.5},children:"Result is open in the expanded viewer."}),ai.createPortal(t.jsx("div",{role:"dialog","aria-modal":"true","aria-label":`${st(e,n)} expanded result`,onClick:()=>x(!1),style:{position:"fixed",inset:0,zIndex:120,display:"grid",placeItems:"center",padding:24,background:"rgba(15,23,42,0.48)",backdropFilter:"blur(3px)"},children:t.jsx("div",{onClick:v=>v.stopPropagation(),style:{minWidth:0,maxWidth:"100%"},children:h})}),document.body)]})}function Zn(e){const{run:n,t:r,themeMode:i,threadId:s,appContext:o,selectedArtifactId:a,onOpenArtifact:d,onOpenApp:u,onInsertSql:x,onInsertDql:g,onReplaceDql:l,insertDqlActionLabel:c,replaceDqlActionLabel:b,onOpenBlock:h,onOpenResearch:v,onSelectClarification:m,onNextAction:q,onRepairedRun:P}=e,{dispatch:$}=Mt(),[L,C]=f.useState(!1),M=d??(()=>$({type:"OPEN_AGENT_LOG",run:n}));if(n.route==="conversation"){const p=n.answerKind==="general_knowledge";return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,animation:"dql-agent-fadein 0.3s ease-out",maxWidth:"100%"},children:[p?t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:10.5,color:r.textMuted,fontWeight:650},children:[t.jsx(zt,{size:11})," General knowledge — not from your data"]}):null,t.jsx("div",{"data-followup":"answer",style:{fontSize:14.5,lineHeight:1.65,color:r.textPrimary},children:n.answer?t.jsx(qt,{text:Je(n.answer),t:r}):n.summary}),n.nextActions.length>0?t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:n.nextActions.map(I=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>q(I),style:Tt(r),children:I.label},I.id))}):null]})}const Q=n.trustState==="certified",B=n.status==="blocked",W=n.status==="needs_clarification",H=B||W?void 0:n.answer,ne=B?"Couldn’t run this query":W?"Needs clarification":Q?"Certified answer":"AI-generated answer",A=B?Qr(n):void 0,J=n.evaluations.filter(p=>p.severity==="info").length,R=vn(n),w=n.artifacts.filter(p=>{const I=oe(p);return!Yt(p,I)&&!!Be(I)}),K=new Set(w.map(p=>p.id)),U=n.artifacts.filter(p=>!Yt(p,oe(p))&&!K.has(p.id)),X=n.artifacts.filter(p=>Yt(p,oe(p))),T=w[0]??U[0]??n.artifacts[0],E=pt(n),re=n.route==="certified_answer"||n.route==="semantic_answer"||n.route==="generated_answer",V=n.nextActions.some(p=>p.route==="research"),pe=re&&E&&!V,le=Ae(n),G=E&&!(le!=null&&le.sourcePath)&&!!((le==null?void 0:le.source)??ke(n)),S=c&&g||b&&l?_t(n):void 0,Z=()=>{var I;const p=H?Je(H):A??n.summary;p&&((I=navigator.clipboard)==null||I.writeText(p).catch(()=>{}),C(!0),window.setTimeout(()=>C(!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:[B?t.jsx(Xe,{size:14,color:r.error}):Q?t.jsx(ye,{size:14,color:r.success}):t.jsx(Ve,{size:14,color:r.accent}),t.jsx("span",{style:{fontSize:12,fontWeight:650,color:B?r.error:r.textSecondary},children:ne}),Q&&R[0]?t.jsxs("span",{style:{fontSize:11,color:r.textMuted},children:["from ",t.jsx("span",{style:{color:r.accent,fontWeight:600},children:R[0].label})]}):!B&&T&&J>0?t.jsxs("button",{type:"button",onClick:()=>M(T.id,"trust"),style:{fontSize:11,color:r.textMuted,background:"none",border:"none",cursor:"pointer",padding:0,fontFamily:r.font,display:"inline-flex",alignItems:"center",gap:4},children:[t.jsx(ot,{size:11,color:r.success})," ",J," check",J===1?"":"s"," passed"]}):null]}),H?t.jsx("div",{"data-followup":"answer",style:{fontSize:14.5,lineHeight:1.65,color:r.textPrimary},children:t.jsx(qt,{text:Je(H),t:r})}):A?t.jsx(Zs,{run:n,detail:A,threadId:s,onRepaired:p=>P(n.id,p),t:r}):n.summary?t.jsx("div",{"data-followup":"answer",style:{fontSize:14,lineHeight:1.6,color:r.textSecondary},children:Te(n.summary)}):null,t.jsx(Ir,{run:n,t:r,onSelect:m}),w.map(p=>t.jsx(ws,{run:n,artifact:p,selected:p.id===a,t:r,themeMode:i,onInspect:I=>M(p.id,I)},p.id)),U.map(p=>{const I=oe(p),ee=p.id===a;return t.jsxs("button",{type:"button",className:"dql-ask-chip",onClick:()=>M(p.id,xn(n,p)),style:{display:"flex",alignItems:"center",gap:10,width:"fit-content",maxWidth:"100%",padding:"9px 12px",borderRadius:10,border:`1px solid ${ee?"var(--accent)":"var(--border-default)"}`,background:"var(--bg-2)",boxShadow:ee?"0 1px 6px rgba(107,93,211,0.12)":"none",cursor:"pointer",textAlign:"left",fontFamily:r.font},children:[t.jsx("span",{style:{width:30,height:30,borderRadius:7,background:p.trustState==="certified"?"var(--status-success-bg)":"var(--accent-dim)",color:p.trustState==="certified"?"var(--status-success)":"var(--accent)",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx(Ze,{kind:p.kind})}),t.jsxs("span",{style:{display:"flex",flexDirection:"column",gap:1,minWidth:0},children:[t.jsx("span",{style:{fontSize:12.5,fontWeight:650,color:r.textPrimary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Te(p.title)}),t.jsx("span",{style:{fontSize:11,color:r.textMuted},children:Wt(p,I)})]}),t.jsx(ar,{size:14,color:r.textMuted,style:{flexShrink:0,marginLeft:6}})]},p.id)}),X.length>0?t.jsx("div",{style:{display:"grid",gap:8,gridTemplateColumns:"minmax(0, 1fr)",minWidth:0},children:X.map(p=>t.jsx(Lr,{artifact:p,t:r,themeMode:i,onInsertSql:x,onInsertDql:g,insertDqlActionLabel:c,sourceRunId:n.id,sourceQuestion:n.question,onOpenBlock:h,onOpenResearch:v,onOpenApp:u,onNextAction:q},p.id))}):null,H||A||S||E||G||pe||T?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:2,flexWrap:"wrap",marginTop:-2},children:[S&&g?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>g(S),style:We(r),children:[t.jsx(it,{size:12})," ",c]}):null,S&&l&&b?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>l(S),style:We(r),children:[t.jsx(ci,{size:12})," ",b]}):null,H||A?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:Z,style:We(r),children:[L?t.jsx(ot,{size:12}):t.jsx(fr,{size:12})," ",L?"Copied":"Copy"]}):null,E?t.jsx(yn,{run:n,t:r,appContext:o,onOpenApp:u}):null,G?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>q({id:"save-dql-block",label:"Save as block",route:"dql_block_draft"}),style:We(r),children:[t.jsx(ut,{size:12})," Save as block"]}):null,pe?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>q({id:"research-deeper",label:"Research this deeper",route:"research"}),style:We(r),children:[t.jsx(at,{size:12})," Research deeper"]}):null,T?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>M(T.id,Ft(oe(T))?"how":"trust"),style:We(r),children:[t.jsx(dt,{size:12})," How it was answered"]}):null]}):null]})}function Ir({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 _r(e){const n=e.executionError;if(typeof n=="string"&&n.trim())return{stage:"execution",message:n};const r=N(n);if(r)return{stage:"execution",...r};const i=typeof e.refusalCode=="string"?e.refusalCode:void 0;if(i){const s=N(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 Ft(e){return!!(N(e.resolvedAnalyticalPlan)||N(e.analyticalExecutionGraph)||N(e.analyticalExecutionReceipt)||N(e.analyticalFailure)||N(e.semanticExecutionTrace)||N(e.diagnosticReceipt)||_r(e))}function Tr(e){if(!Ft(e))return;const n=N(e.diagnosticReceipt),r=N(e.resolvedAnalyticalPlan)??N(n==null?void 0:n.resolvedAnalyticalPlan);return{plan:r,frame:N(r==null?void 0:r.analyticalFrame),graph:N(e.analyticalExecutionGraph),receipt:N(e.analyticalExecutionReceipt),facts:N(e.analyticalFacts),narrative:N(e.analyticalNarrative),freshness:N(e.analyticalFreshnessObservation),failure:N(e.analyticalFailure)??N(n==null?void 0:n.failure)??_r(e),semantic:N(e.semanticExecutionTrace),diagnostic:n}}function ks(){return["Plan","DQL","Compiled SQL","Lineage","Trust & evidence","Actual steps","Failure & repair"]}function As(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 qs({run:e,contract:n,dqlArtifact:r,sql:i,lineage:s,t:o,onInsertSql:a,onInsertDql:d,onSaveBlock:u}){var xe,De,Pe;const{dispatch:x}=Mt(),g=n.plan,l=n.frame,c=n.graph,b=n.receipt,h=n.semantic,v=N(h==null?void 0:h.failure),m=n.failure??v,q=N(h==null?void 0:h.authoringRequest),P=N(h==null?void 0:h.runtimeRequest),$=_e(h==null?void 0:h.bindings),L=_e(h==null?void 0:h.steps),C=N(h==null?void 0:h.targetBinding),M=N(C==null?void 0:C.semanticSnapshot),Q=N(C==null?void 0:C.executionTarget),B=N(Q==null?void 0:Q.redactedContext),W=N(C==null?void 0:C.compileTarget),H=N(h==null?void 0:h.executionReceipt),ne=_e(v==null?void 0:v.candidates),A=N(l==null?void 0:l.timeContext),J=N(l==null?void 0:l.comparison),R=N(l==null?void 0:l.ranking),w=_e(l==null?void 0:l.dimensions),K=_e(l==null?void 0:l.memberBindings),U=_e(A==null?void 0:A.periods),X=_e(l==null?void 0:l.requestedOutputs),T=_e(c==null?void 0:c.nodes),E=Array.from(new Set([...we(m==null?void 0:m.safeActions),...we(v==null?void 0:v.safeActions)])),re=_e(m==null?void 0:m.failedBindings),V=N(v==null?void 0:v.sqlExcerpt),pe=e.artifacts.map(k=>Be(oe(k))).find(Boolean),le=(r==null?void 0:r.name)??e.question,[G,S]=f.useState(null),Z=(k,ae)=>{const $e=ae.derivation.trustTransition;return`${k} as immutable derivation ${ae.derivation.derivationId}. Trust: ${$e.previous} → ${$e.next}${$e.requiresReview?" (review required)":""}.`},p=async()=>{if(!(!(r!=null&&r.source)||!d))try{const k=await te.deriveAnalyticalRepair(e.id,{version:1,action:"edit_dql",dqlSource:r.source});d({sql:i,dqlArtifact:r,result:pe,title:le,sourceRunId:e.id,question:e.question}),S(Z("Opened DQL in Notebook",k))}catch(k){S(k instanceof Error?k.message:String(k))}},I=async()=>{if(!(!i||!a))try{const k=await te.deriveAnalyticalRepair(e.id,{version:1,action:"open_sql_notebook",sqlText:i});a(i,`${le} repair`,{question:e.question,sourceRunId:e.id}),S(Z("Opened SQL in Notebook",k))}catch(k){S(k instanceof Error?k.message:String(k))}},ee=async k=>{try{const ae=await te.deriveAnalyticalRepair(e.id,{version:1,action:k});S(Z(k==="retry_same_plan"?"Prepared the same bounded plan for retry":"Refreshed the governed snapshot and prepared the same plan for retry",ae))}catch(ae){S(ae instanceof Error?ae.message:String(ae))}},ie=async()=>{try{const k=await te.deriveAnalyticalRepair(e.id,{version:1,action:"request_access"});S(Z("Recorded the access/connection repair and opened Database settings",k)),x({type:"SET_SETTINGS_TAB",tab:"database"}),x({type:"SET_MAIN_VIEW",view:"settings"})}catch(k){S(k instanceof Error?k.message:String(k))}},ve=()=>{x({type:"SET_SETTINGS_TAB",tab:"project"}),x({type:"SET_MAIN_VIEW",view:"settings"}),S("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 ${m?"var(--status-error-border)":"var(--status-success-border)"}`,background:m?"var(--status-error-bg)":"var(--status-success-bg)"},children:[m?t.jsx(Xe,{size:13,color:"var(--status-error)",style:{flexShrink:0,marginTop:2}}):t.jsx(ye,{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:m?"var(--status-error)":"var(--status-success)"},children:m?"Execution failed":"Answered successfully"}),m?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{marginTop:3,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:o.fontMono,fontSize:11},children:typeof m.message=="string"&&m.message.trim()?m.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:[m.code,m.phase?`during ${m.phase}`:""].filter(Boolean).map(z).join(" · ")})]}):t.jsx("div",{style:{marginTop:2},children:typeof(b==null?void 0:b.rowCount)=="number"?`Returned ${b.rowCount} row${b.rowCount===1?"":"s"}.`:"The query ran and returned a result."})]})]}),t.jsx(kt,{index:1,label:"Plan",t:o,open:!m,children:t.jsx(Jt,{rows:[["Question type",z((l==null?void 0:l.questionType)??(g==null?void 0:g.questionType))],["Selected route",z((c==null?void 0:c.route)??(g==null?void 0:g.recommendedRoute))],["Metric",we(l==null?void 0:l.metricConceptIds).join(", ")],["Entity grain",we(l==null?void 0:l.entityGrainIds).join(", ")],["Dimensions",w.map(k=>`${z(k.dimensionId)} (${z(k.role)})`).join(", ")],["Member filters",K.map(k=>`${z(k.dimensionId)}: ${Array.isArray(k.canonicalValues)?k.canonicalValues.length:0} bound value(s)`).join(", ")],["Time policy",[A==null?void 0:A.timeRole,A==null?void 0:A.grain,A==null?void 0:A.timezone,A==null?void 0:A.completenessPolicy].map(z).filter(Boolean).join(" · ")],["Periods",U.map(k=>`${z(k.id)}: ${z(k.start)} → ${z(k.end)}`).join(`
|
|
85
|
-
`)],["Comparison",J?`${z(J.basePeriodId)} vs ${we(J.comparisonPeriodIds).join(", ")} · ${z(J.alignment)}`:l?"Not requested":"Not available — analytical planning did not complete"],["Ranking",R?`${z(R.direction)} · top ${z(R.limit)} · ${z(R.tiePolicy)}`:l?"Not requested":"Not available — analytical planning did not complete"],["Outputs",X.map(k=>`${z(k.id)} (${z(k.kind)})`).join(", ")],["Semantic metrics",we(q==null?void 0:q.metrics).join(", ")],["Semantic dimensions",we(q==null?void 0:q.dimensions).join(", ")]],t:o})}),t.jsx(kt,{index:2,label:"Trust & evidence",t:o,children:t.jsx(Jt,{rows:[["Trust state",e.trustState],["Snapshot",z((g==null?void 0:g.snapshotId)??(c==null?void 0:c.snapshotId))],["Plan fingerprint",z((g==null?void 0:g.fingerprint)??(c==null?void 0:c.planFingerprint))],["Graph fingerprint",z(c==null?void 0:c.fingerprint)],["Receipt",z(b==null?void 0:b.receiptId)],["Result fingerprint",z(b==null?void 0:b.resultFingerprint)],["Freshness observed through",z((xe=n.freshness)==null?void 0:xe.observedThrough)],["Fact set",z((De=n.facts)==null?void 0:De.fingerprint)],["Semantic adapter",z(h==null?void 0:h.adapter)],["Semantic compile status",z(h==null?void 0:h.status)],["Target proof",z((Pe=N(C==null?void 0:C.proof))==null?void 0:Pe.status)],["Target binding",z(C==null?void 0:C.bindingFingerprint)],["Compile target",z(W==null?void 0:W.kind)],["Local semantic snapshot",z((M==null?void 0:M.semanticCatalogFingerprint)??(M==null?void 0:M.sourceFingerprint))],["Runtime metric inventory proof",z(W==null?void 0:W.semanticCatalogFingerprint)],["Execution target",[Q==null?void 0:Q.driver,B==null?void 0:B.account,B==null?void 0:B.database,B==null?void 0:B.schema,B==null?void 0:B.role,B==null?void 0:B.warehouse].map(z).filter(Boolean).join(" · ")],["Semantic receipt",z(H==null?void 0:H.receiptId)],["Warehouse query ID",z(H==null?void 0:H.queryId)],["Executed SQL proof",z(H==null?void 0:H.executedSqlFingerprint)],["Runtime metrics",we(P==null?void 0:P.metrics).join(", ")],["Runtime dimensions",we(P==null?void 0:P.dimensions).join(", ")],["Member bindings",$.map(k=>`${z(k.authoringReference)} → ${z(k.runtimeReference)}${we(k.entityPath).length?` via ${we(k.entityPath).join(" → ")}`:""} (${z(k.status)})`).join(`
|
|
86
|
-
`)]],t:o,mono:!0})}),t.jsx(kt,{index:3,label:"Actual steps",t:o,children:t.jsxs("div",{style:{display:"grid",gap:6},children:[L.map((k,ae)=>t.jsxs("div",{style:{fontSize:11.5,color:o.textSecondary},children:[t.jsxs("strong",{style:{color:z(k.status)==="failed"?"var(--status-error)":o.textPrimary},children:[ae+1,". ",z(k.label)]})," ","— ",z(k.status)," · ",z(k.detail)]},`semantic:${z(k.id)||ae}`)),e.steps.map(k=>t.jsxs("div",{style:{fontSize:11.5,color:o.textSecondary},children:[t.jsxs("strong",{style:{color:o.textPrimary},children:[k.index+1,". ",k.goal]})," — ",k.status,", ",k.attempts," attempt",k.attempts===1?"":"s"]},k.id)),T.map((k,ae)=>t.jsxs("div",{style:{fontSize:11.5,color:o.textSecondary},children:[t.jsxs("span",{style:{color:o.accent,fontFamily:o.fontMono},children:[ae+1,". ",z(k.kind)]})," ","· ",z(k.id)]},z(k.id)||ae)),L.length===0&&e.steps.length===0&&T.length===0?t.jsx(Rt,{t:o,children:"No executable steps were recorded."}):null]})}),t.jsx(kt,{index:4,label:"Failure & repair",t:o,open:!!m,children:m?t.jsxs("div",{style:{display:"grid",gap:9},children:[t.jsx(Jt,{rows:[["Failure ID",z(m.failureId)],["Recoverability",z(m.recoverability)],["Failed bindings",re.map(k=>`${z(k.qualifiedId??k.role)} (${z(k.reasonCode)})`).join(", ")],["Safe actions",E.join(", ")],["DQL fingerprint",z(m.dqlFingerprint)],["SQL fingerprint",z(m.sqlFingerprint)],["Semantic failure code",z(v==null?void 0:v.code)],["Failing identifier",z(v==null?void 0:v.identifier)],["Compiled SQL proof",z(v==null?void 0:v.compiledSqlFingerprint)],["Path candidates",ne.map(k=>`${z(k.label)}
|
|
87
|
-
${z(k.runtimeReference)}`).join(`
|
|
88
|
-
`)]],t:o,mono:!0}),z(V==null?void 0:V.text)?t.jsxs("div",{children:[t.jsxs("div",{style:{fontSize:10.5,fontWeight:700,color:o.textSecondary,marginBottom:5},children:["Failing SQL context · lines ",z(V==null?void 0:V.startLine),"–",z(V==null?void 0:V.endLine)]}),t.jsx("pre",{style:ct(o),children:z(V==null?void 0:V.text)})]}):null,t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6},"aria-label":"Safe repair actions",children:[E.includes("edit_dql")&&d?t.jsxs("button",{type:"button",onClick:()=>void p(),style:Y(o),children:[t.jsx(Lt,{size:12})," Open DQL to repair"]}):null,E.includes("open_sql_notebook")&&a?t.jsxs("button",{type:"button",onClick:()=>void I(),style:Y(o),children:[t.jsx(pn,{size:12})," Open SQL in Notebook"]}):null,E.includes("retry_same_plan")?t.jsxs("button",{type:"button",onClick:()=>void ee("retry_same_plan"),style:Y(o),children:[t.jsx(Ot,{size:12})," Retry same plan"]}):null,E.includes("refresh_snapshot")?t.jsxs("button",{type:"button",onClick:()=>void ee("refresh_snapshot"),style:Y(o),children:[t.jsx(Ot,{size:12})," Refresh snapshot and prepare retry"]}):null,E.includes("request_access")||E.includes("change_authorized_connection")?t.jsxs("button",{type:"button",onClick:()=>void ie(),style:Y(o),children:[t.jsx(Xe,{size:12})," Change connection or request access"]}):null,E.includes("reapply_semantic_runtime")?t.jsxs("button",{type:"button",onClick:ve,style:Y(o),children:[t.jsx(Ot,{size:12})," Reapply semantic runtime settings"]}):null]})]}):t.jsxs("div",{style:{display:"grid",gap:8},children:[t.jsx(Rt,{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:u,style:Y(o),children:[t.jsx(fn,{size:12})," Save as draft block"]}):null]})}),G?t.jsx("div",{role:"status",style:{fontSize:10.5,color:G.toLowerCase().includes("created")?"var(--status-success)":"var(--status-error)"},children:G}):null]})}function kt({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 Jt({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 Rt({t:e,children:n}){return t.jsx("div",{style:{fontSize:11,color:e.textMuted},children:n})}function _e(e){return Array.isArray(e)?e.flatMap(n=>N(n)?[N(n)]:[]):[]}function we(e){return Array.isArray(e)?e.filter(n=>typeof n=="string"):[]}function z(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):""}function At(e){return{question:e.question??e.label,selectedEvidenceId:e.id}}function Br(e){var i;const n=e.artifacts.map(s=>Be(oe(s))).find(s=>!!s),r=(i=e.artifacts.find(s=>s.ref))==null?void 0:i.ref;return{runId:e.id,question:e.question,trustState:e.trustState,executionTarget:e.executionTarget,sourceCertifiedBlock:r,sql:ke(e),dqlArtifact:Ae(e),...n?{result:{columns:n.columns,rows:n.rows.slice(0,24),rowCount:n.rowCount}}:{}}}function pt(e){return!e.artifacts.some(r=>!!Dt(oe(r)))&&e.status!=="blocked"&&e.status!=="needs_clarification"&&(e.artifacts.some(r=>r.kind==="answer"||r.kind==="research_run")||!!(Ae(e)??ke(e)))}function Cs({run:e,artifact:n,tab:r,t:i,appContext:s,onOpenApp:o,onChangeTab:a,onClose:d,onSaveBlock:u,onInsertSql:x,onInsertDql:g}){const l=oe(n),c=Ae(e)??ft(l),b=ke(e)??(typeof l.sql=="string"?l.sql:void 0),h=Be(l),v=st(e,n),m=vn(e),q=Rr(e),P=mn(e),$=n.trustState==="certified",L=e.status==="blocked"||n.trustState==="blocked",C=pt(e),M=Tr(l),Q=zr({analytical:!!M,blocked:L,hasDql:!!(c!=null&&c.source),hasSql:!!b,hasLineage:q.length>0}),B=Q.some(A=>A.id===r)?r:Q[0].id,W=L?"Blocked":$?"Certified":n.trustState==="governed"||n.trustState==="grounded"?"Governed":"AI-generated",H=L?"var(--status-error)":$?"var(--status-success)":n.trustState==="governed"||n.trustState==="grounded"?"var(--accent)":"var(--status-warning)",ne=L?"var(--status-error-bg)":$?"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:ne,color:H,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:"1px solid var(--border-subtle)"},children:t.jsx(Ze,{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:st(e,n)}),t.jsx("div",{style:{fontSize:11,color:i.textMuted,marginTop:2},children:Wt(n,l)})]}),t.jsx("span",{style:{border:`1px solid ${H}`,color:H,background:ne,borderRadius:999,padding:"2px 8px",fontSize:10,fontWeight:700,flexShrink:0,marginTop:2},children:W}),t.jsx("button",{type:"button",onClick:d,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(Ct,{size:14})})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"10px 16px",borderBottom:"1px solid var(--border-subtle)"},children:[C?t.jsx(yn,{run:e,t:i,appContext:s,onOpenApp:o}):null,C?t.jsxs("button",{type:"button",className:"dql-hover",onClick:u,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(ut,{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(ui,{size:14})})]}),t.jsx("div",{style:{display:"flex",alignItems:"center",gap:16,padding:"0 16px",borderBottom:"1px solid var(--border-subtle)",flexShrink:0},children:Q.map(A=>t.jsx("button",{type:"button",onClick:()=>a(A.id),style:{padding:"10px 1px",fontSize:12,fontWeight:600,cursor:"pointer",border:"none",background:"none",fontFamily:i.font,whiteSpace:"nowrap",color:B===A.id?i.textPrimary:i.textMuted,boxShadow:B===A.id?`inset 0 -2px 0 0 ${i.accent}`:"none"},children:A.label},A.id))}),t.jsxs("div",{style:{flex:1,minHeight:0,overflow:"auto",padding:"14px 16px 20px"},children:[B==="how"&&M?t.jsx(qs,{run:e,contract:M,dqlArtifact:c,sql:b,lineage:q,t:i,onInsertSql:x,onInsertDql:g,onSaveBlock:u}):null,B==="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:[g?t.jsx("button",{type:"button",onClick:()=>g({sql:b,dqlArtifact:c,result:h,chartConfig:h?Fe(l,h):void 0,title:v,sourceRunId:e.id,question:e.question}),style:Y(i),children:"Open DQL in notebook"}):null,t.jsx(It,{text:c.source,t:i,title:"Copy DQL"})]})]}),t.jsx("pre",{style:ct(i),children:c.source})]}):t.jsx(Rt,{t:i,children:"The selected plan failed before a DQL source could be materialized. Review the Plan and Failure & repair sections."}):null,B==="sql"?b?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:[x?t.jsx("button",{type:"button",onClick:()=>x(b,v,{question:e.question,sourceRunId:e.id}),style:Y(i),children:"Open SQL in notebook"}):null,t.jsx(It,{text:b,t:i,title:"Copy SQL"})]})]}),t.jsx("pre",{style:ct(i),children:b})]}):t.jsx(Rt,{t:i,children:"Compilation stopped before SQL was produced. The DQL, plan, trust evidence, and failure steps are still retained."}):null,B==="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."}),q.map(A=>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(ur,{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:A.name}),t.jsx("div",{style:{fontSize:10.5,color:i.textMuted,marginTop:2},children:[A.kind,A.detail].filter(Boolean).join(" · ")})]})]},`${A.kind??"asset"}:${A.name}`))]}):null,B==="trust"?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[P?t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-start",padding:"10px 12px",borderRadius:8,background:$?"var(--status-success-bg)":"var(--status-warning-bg)",border:`1px solid ${$?"var(--status-success-border)":"var(--status-warning-border)"}`},children:[$?t.jsx(ye,{size:13,color:"var(--status-success)",style:{flexShrink:0,marginTop:1}}):t.jsx(Xe,{size:13,color:"var(--status-warning)",style:{flexShrink:0,marginTop:1}}),t.jsx("span",{style:{fontSize:12,color:i.textSecondary,lineHeight:1.5},children:P})]}):null,m.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:m.map(A=>t.jsxs("span",{style:Hr(i,A.certified),children:[A.certified?t.jsx(ye,{size:11}):t.jsx(at,{size:11}),t.jsx("span",{children:A.label})]},A.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(Wr,{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(Fr,{steps:e.steps,t:i})]}):null,t.jsx(Nr,{run:e,t:i})]}):null]})]})}function zs({t:e,text:n,source:r,left:i,top:s,draft:o,inputRef:a,onDraftChange:d,onClose:u,onSend:x}){const g=(l,c)=>t.jsx("button",{type:"button",onClick:()=>x(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(Ve,{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:u,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(Ct,{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=>d(l.target.value),onKeyDown:l=>{l.key==="Enter"&&(l.preventDefault(),x(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:()=>x(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(cr,{size:13})})]}),t.jsxs("div",{style:{display:"flex",gap:5,flexWrap:"wrap"},children:[g("Why is this?","Why is this happening?"),g("Root cause","What is the root cause?"),g("Break it down","Break this down further")]})]})}function rt(e){const n=e.replace(/^\/\w+\s+/,"").trim().replace(/[?.!]+$/,"");return(n?n.charAt(0).toUpperCase()+n.slice(1):"New app").slice(0,60)}function on(e,n){const r=e instanceof Error?e.message.trim():"";return e instanceof di&&e.status===405||/method not allowed/i.test(r)?"This Notebook server is older than the App Studio shown in your browser. Restart dql notebook, reload this page, and try again. No Project files were published.":r||n}function ln(e,n){return n!=null&&n.trim()?`${e} › ${n.trim()}`:e}function $r(e,n){const r=n.filter(s=>s.state!=="project_published"),i=new Set(r.flatMap(s=>{var o;return(o=s.baseApp)!=null&&o.appId?[s.baseApp.appId]:[]}));return[...r.map(s=>{var o,a;return{id:`draft:${s.id}`,kind:"draft",appId:s.appId,name:s.name,draft:s,pageId:(o=s.pages[0])==null?void 0:o.id,pageTitle:(a=s.pages[0])==null?void 0:a.metadata.title}}),...e.filter(s=>!i.has(s.id)).map(s=>{var a,d,u;const o=((a=s.homepage)==null?void 0:a.type)==="dashboard"?s.homepage.id:(d=s.dashboards[0])==null?void 0:d.id;return{id:`project:${s.id}`,kind:"project",appId:s.id,name:s.name,pageId:o,pageTitle:(u=s.dashboards.find(x=>x.id===o))==null?void 0:u.title}})]}function yn({run:e,t:n,appContext:r,onOpenApp:i}){const[s,o]=f.useState(!1),[a,d]=f.useState(null),[u,x]=f.useState(!1),[g,l]=f.useState("list"),[c,b]=f.useState(""),[h,v]=f.useState(!1),[m,q]=f.useState(null),[P,$]=f.useState(""),[L,C]=f.useState(null),M=f.useRef(null),Q=async()=>{d(null),x(!1);const[R,w]=await Promise.allSettled([te.listAppsStrict(),te.listAppBuilds()]);if(R.status==="rejected"&&w.status==="rejected"){d([]),x(!0);return}const K=$r(R.status==="fulfilled"?R.value:[],w.status==="fulfilled"?w.value.drafts:[]);d(K),K.length===0&&l("new")},B=()=>{o(!0),q(null),l("list"),M.current=null,b(rt(e.question)),$(rt(e.question)),Q()},W=()=>{h||(o(!1),q(null))},H=async(R,w,K,U)=>{var V,pe;const X=P.trim()||rt(e.question),T=Ae(e),E=Zt(e),re=await te.addAskResultToAppBuild(R.id,{expectedRevision:R.revision,expectedProposalHash:R.proposalHash,pageId:K,title:X,question:e.question,answer:e.answer??e.summary,certifiedBlockId:E,dqlSource:T==null?void 0:T.source,sql:ke(e),visualization:(V=Fs(e))==null?void 0:V.chart});C({appId:re.draft.appId,draftId:re.draft.id,pageId:re.pageId,name:w,pageTitle:((pe=re.draft.pages.find(le=>le.id===re.pageId))==null?void 0:pe.metadata.title)??U,tileTitle:X,kind:re.deduped?"existing":E?"certified":T!=null&&T.source||ke(e)?"review":"narrative"}),window.dispatchEvent(new CustomEvent("dql-app-build-updated",{detail:{draft:re.draft,pageId:re.pageId,tileId:re.tileId}})),o(!1)},ne=async R=>{if(R.draft)return R.draft;const K=(await te.listAppBuilds()).drafts.find(U=>{var X;return U.state!=="project_published"&&((X=U.baseApp)==null?void 0:X.appId)===R.appId});return K||(await te.createAppBuild({baseAppId:R.appId,goal:`Edit ${R.name} with an Ask result`,authoringMode:"ai",sourcePolicy:Zt(e)?"governed_only":"include_review_required",template:"blank",entrypoint:"ask"})).draft},A=async R=>{if(!h){v(!0),q(null);try{const w=await ne(R),K=(r==null?void 0:r.appId)===R.appId?r.dashboardId:R.pageId;await H(w,R.name,K,R.pageTitle)}catch(w){q(on(w,"Could not add to app."))}finally{v(!1)}}},J=async()=>{var w,K;if(h)return;const R=c.trim()||rt(e.question);v(!0),q(null);try{M.current||(M.current=(await te.createAppBuild({name:R,goal:e.question,authoringMode:"ai",sourcePolicy:Zt(e)?"governed_only":"include_review_required",template:"blank",entrypoint:"ask"})).draft),await H(M.current,R,(w=M.current.pages[0])==null?void 0:w.id,(K=M.current.pages[0])==null?void 0:K.metadata.title),M.current=null}catch(U){q(on(U,"Could not create the app."))}finally{v(!1)}};return t.jsxs("div",{style:{position:"relative",display:"inline-flex",alignItems:"center",gap:6},children:[L?t.jsxs("div",{role:"status","aria-live":"polite",style:{display:"grid",gridTemplateColumns:"auto minmax(0, 1fr) auto",alignItems:"center",gap:8,minWidth:260,maxWidth:440,padding:"8px 9px",borderRadius:9,background:`${n.success}12`,color:n.success,border:`1px solid ${n.success}55`},children:[t.jsx("span",{style:{width:26,height:26,borderRadius:999,display:"grid",placeItems:"center",background:`${n.success}20`},children:t.jsx(lt,{size:15})}),t.jsxs("span",{style:{display:"grid",gap:1,minWidth:0},children:[t.jsx("b",{style:{fontSize:11.5},children:L.kind==="existing"?"Already on this page":L.kind==="certified"?"Saved as a certified tile":L.kind==="review"?"Saved — review required":"Saved as editable narrative"}),t.jsxs("span",{title:ln(L.name,L.pageTitle),style:{fontSize:10.5,color:n.textSecondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[ln(L.name,L.pageTitle)," · editable draft"]}),t.jsxs("span",{title:L.tileTitle,style:{fontSize:10,color:n.textMuted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Tile: ",L.tileTitle]}),L.kind==="review"||L.kind==="narrative"?t.jsx("span",{style:{fontSize:10,color:n.textMuted,lineHeight:1.35},children:"Stays local and cannot publish until reviewed, promoted, or removed."}):null]}),i?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>i(L.appId,L.pageId,L.draftId),style:{...Y(n),color:n.success,whiteSpace:"nowrap"},title:"Open the App page containing this tile",children:["Open App ",t.jsx(vi,{size:12})]}):null]}):null,t.jsxs("button",{type:"button",className:"dql-hover dql-lift",onClick:B,style:L?Y(n):rr(n),children:[t.jsx(en,{size:13}),L?"Add to another":"Add to app"]}),s?t.jsxs(t.Fragment,{children:[t.jsx("div",{onClick:W,style:{position:"fixed",inset:0,zIndex:40}}),t.jsxs("div",{style:Vs(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:g==="new"?"Name the new App draft":"Save to an editable App"}),t.jsx("button",{type:"button",onClick:W,style:{border:"none",background:"transparent",color:n.textMuted,cursor:"pointer",fontSize:15,lineHeight:1},children:"×"})]}),m?t.jsx("div",{style:{fontSize:11,color:n.error,marginBottom:7,lineHeight:1.4},children:m}):null,g==="new"?t.jsxs("div",{style:{display:"grid",gap:8},children:[t.jsx("input",{autoFocus:!0,value:c,onChange:R=>b(R.target.value),onKeyDown:R=>{R.key==="Enter"&&J()},placeholder:"App name",style:sr(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:Y(n),children:"Back"}):null,t.jsxs("button",{type:"button",className:"dql-hover",disabled:h||!c.trim(),onClick:()=>void J(),style:{...rr(n),flex:1,justifyContent:"center"},children:[h?t.jsx(Qe,{size:13,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(it,{size:13}),"Create draft & add"]})]})]}):a===null?t.jsx("div",{style:{fontSize:11.5,color:n.textMuted,padding:"8px 2px"},children:"Loading apps…"}):u?t.jsxs("div",{style:{display:"grid",gap:8},children:[t.jsx("div",{style:{fontSize:11.5,color:n.error,lineHeight:1.4},children:"Couldn't load your apps."}),t.jsxs("div",{style:{display:"flex",gap:6},children:[t.jsx("button",{type:"button",className:"dql-hover",onClick:()=>void Q(),style:Y(n),children:"Retry"}),t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>l("new"),style:{...ir(n),width:"auto",flex:1,marginBottom:0,justifyContent:"center"},children:[t.jsx(it,{size:13})," New app…"]})]})]}):t.jsxs("div",{style:{display:"grid",gap:3,maxHeight:244,overflow:"auto"},children:[t.jsxs("label",{style:{display:"grid",gap:3,marginBottom:5},children:[t.jsx("span",{style:{fontSize:10.5,color:n.textMuted},children:"Tile name"}),t.jsx("input",{value:P,onChange:R=>$(R.target.value),placeholder:rt(e.question),maxLength:120,style:sr(n)})]}),t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>l("new"),style:ir(n),children:[t.jsx(it,{size:13})," New app…"]}),a.map(R=>t.jsxs("button",{type:"button",className:"dql-hover",disabled:h,onClick:()=>void A(R),style:Gs(n),children:[t.jsx(en,{size:13,style:{flex:"0 0 auto",opacity:.7}}),t.jsxs("span",{style:{flex:1,minWidth:0,display:"grid",gap:1,overflow:"hidden",textAlign:"left"},children:[t.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:R.name}),t.jsx("small",{style:{color:n.textMuted},children:R.kind==="draft"?"Local editable draft":"Project App · creates a safe edit draft"})]})]},R.id))]})]})]}):null]})}function mn(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(bn(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.route==="modeling_draft"?"AI-drafted modeling proposal. Review the exact source diff, then save it as a draft — nothing is written or joinable yet.":e.route==="skill_draft"?"AI-drafted Skill proposal. Review it, then save it as a draft — it will not guide any agent until you activate it.":e.trustState==="review_required"?"AI-generated answer. Save it as a block when you want to keep it.":(e.trustState==="blocked",null)}function bn(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":bn(e)?"Exploratory DBT-grounded answer":e.route==="semantic_answer"?"Semantic answer":e.route==="generated_answer"?"AI-generated answer":jr[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,[d,u]=f.useState(()=>o?fi(o):new Set),[x,g]=f.useState(!1),[l,c]=f.useState(null),[b,h]=f.useState(null);if(!o||!s)return t.jsxs("div",{style:cn(r),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(Ze,{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 m=>{var P,$;g(!0),c(null);const q=await te.commitAppAiBuild(s,{selectedTileIds:Array.from(d),expectedProposalHash:a,...m.appName?{appName:m.appName}:{},...m.pageTitle?{pageTitle:m.pageTitle}:{},...m.audience?{audience:m.audience}:{},...Object.keys(m.tileOverrides).length>0?{tileOverrides:m.tileOverrides}:{}});if(g(!1),!q.ok){c(q.error);return}h({appId:((P=q.app)==null?void 0:P.id)??q.session.appId??"",dashboardId:q.dashboardId??void 0,name:(($=q.app)==null?void 0:$.name)??e.title})};return t.jsxs("div",{style:cn(r),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(Ze,{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)})]}),b?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(lt,{size:13})," Created ",b.name]}),b.appId&&i?t.jsx("button",{type:"button",className:"dql-hover",onClick:()=>i(b.appId,b.dashboardId),style:Y(r),children:"Open app"}):null]}):t.jsx(gi,{proposal:o,t:r,selected:d,onToggle:m=>{u(q=>{const P=new Set(q);return P.has(m)?P.delete(m):P.add(m),P})},onCreate:m=>void v(m),defaultName:e.title,busy:x,error:l,compact:!0})]})}function Mr({artifact:e,certifiedBlockName:n,initialResult:r,initialChartConfig:i,payload:s,executionTarget:o,t:a,themeMode:d,embedded:u=!1,expanded:x=!1}){var G;const[g,l]=f.useState(e),[c,b]=f.useState(()=>e.parameters??[]),[h,v]=f.useState(()=>({...e.parameterValues??{},...an(s)})),[m,q]=f.useState(r),[P,$]=f.useState(i),[L,C]=f.useState(!!n),[M,Q]=f.useState(!1),[B,W]=f.useState(null),[H,ne]=f.useState(!1),[A,J]=f.useState(""),[R,w]=f.useState(""),K=f.useRef(!1),U=f.useRef(e);U.current=e;const X=as(e);f.useEffect(()=>{const S=U.current;if(l(S),ne(!1),!n){b(S.parameters??[]),v({...S.parameterValues??{},...an(s)}),C(!1);return}let Z=!1;return C(!0),te.getCertifiedBlockParameters(n).then(p=>{Z||(b(p.parameters),v(I=>({...Object.fromEntries(p.parameters.flatMap(ee=>ee.default===void 0?[]:[[ee.name,ee.default]])),...I})))}).catch(p=>{Z||W(p instanceof Error?p.message:String(p))}).finally(()=>{Z||C(!1)}),()=>{Z=!0}},[X,n]);const T=async()=>{if(!K.current){K.current=!0,Q(!0),W(null);try{const S=await te.invokeDqlArtifact(g,h,void 0,n,o);q(S.result),l(S.artifact),S.result.chartConfig&&typeof S.result.chartConfig=="object"&&$(S.result.chartConfig),S.parameters.length>0&&b(S.parameters)}catch(S){W(S instanceof Error?S.message:String(S))}finally{K.current=!1,Q(!1)}}},E=f.useMemo(()=>mr(g,m),[g,m]),re=()=>{const S=E[0];S&&(J(S.column),w(S.values[0]==null?"":String(S.values[0])),ne(!0),W(null))},V=async()=>{try{const S=g.kind==="sql_block"?await te.addDqlArtifactResultFilter(g,m.columns,A,R,o):ds(g,m,A,R);l(S.artifact),b(S.artifact.parameters??[]),v(Z=>({...Z,...S.artifact.parameterValues??{}})),ne(!1),W(null)}catch(S){W(S instanceof Error?S.message:String(S))}},pe=c.some(hr),le=Object.entries(h).filter(([,S])=>S!=null&&S!=="");return t.jsxs("div",{style:{display:"grid",gap:9},children:[le.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:a.textMuted},children:"Applied inputs"}),le.map(([S,Z])=>t.jsxs("span",{style:{fontSize:10.5,color:a.textSecondary,border:`1px solid ${a.cellBorder}`,background:a.appBg,borderRadius:999,padding:"2px 7px"},children:[S.replace(/_/g," ")," = ",_s(Z)]},S))]}):null,L?t.jsx("div",{style:{fontSize:10.5,color:a.textMuted},children:"Loading reusable inputs…"}):pe||E.length>0?t.jsxs("div",{style:{display:"grid",gap:8,padding:9,margin:u?"0 12px":0,border:`1px solid ${a.cellBorder}`,borderRadius:7,background:a.appBg},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:11,fontWeight:800,color:a.textPrimary},children:"Change DQL inputs"}),t.jsx("div",{style:{fontSize:10,color:a.textMuted},children:"Reruns this DQL artifact directly. It does not start another AI search."})]}),E.length>0?t.jsxs("button",{type:"button",onClick:re,style:Y(a),children:[t.jsx(it,{size:11})," Add result filter"]}):null,t.jsxs("button",{type:"button",disabled:M,onClick:()=>void T(),style:{...Y(a),color:a.accent,opacity:M?.65:1},children:[M?t.jsx(Qe,{size:11,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(Ve,{size:11}),M?"Running…":"Apply"]})]}),H?t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"minmax(150px, 1fr) minmax(150px, 1fr) auto auto",gap:7,alignItems:"end",padding:8,border:`1px solid ${a.cellBorder}`,borderRadius:7,background:a.cellBg},children:[t.jsxs("label",{style:{display:"grid",gap:4,fontSize:10,fontWeight:750,color:a.textSecondary},children:["Result column",t.jsx("select",{"aria-label":"Result column for new DQL input",value:A,onChange:S=>{const Z=S.target.value,p=E.find(I=>I.column===Z);J(Z),w((p==null?void 0:p.values[0])==null?"":String(p.values[0]))},style:or(a),children:E.map(S=>t.jsx("option",{value:S.column,children:S.column.split("_").join(" ")},S.column))})]}),t.jsxs("label",{style:{display:"grid",gap:4,fontSize:10,fontWeight:750,color:a.textSecondary},children:["Default value",t.jsx("input",{"aria-label":"Default value for new DQL input",value:R,list:`ask-filter-${A}`,onChange:S=>w(S.target.value),style:or(a)}),t.jsx("datalist",{id:`ask-filter-${A}`,children:(((G=E.find(S=>S.column===A))==null?void 0:G.values)??[]).map(S=>t.jsx("option",{value:String(S)},`${typeof S}:${String(S)}`))})]}),t.jsx("button",{type:"button",onClick:()=>{V()},style:{...Y(a),color:a.accent},children:"Add input"}),t.jsx("button",{type:"button",onClick:()=>ne(!1),style:Y(a),children:"Cancel"})]}):null,c.length>0?t.jsx(Gi,{parameters:c,values:h,onChange:(S,Z)=>v(p=>({...p,[S]:Z})),t:a}):null,E.length>0?t.jsx("div",{style:{fontSize:9.5,color:a.textMuted},children:"Extra filters are available only for semantic dimensions in this result. They stay transient until you explicitly save a block."}):null]}):null,B?t.jsx("div",{style:{fontSize:10.5,color:a.error},children:B}):null,t.jsx(un,{result:m,themeMode:d,t:a,chartConfig:P,embedded:u,tabLabels:u?{table:"Results",chart:"Visualization"}:void 0,contentMaxHeight:x?"calc(100vh - 172px)":void 0,tableMaxHeight:x?"calc(100vh - 250px)":void 0})]})}function an(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 _s(e){return Array.isArray(e)?e.map(n=>String(n)).join(", "):typeof e=="boolean"?e?"true":"false":String(e)}function Er(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 Lr({artifact:e,t:n,themeMode:r,onInsertSql:i,onInsertDql:s,insertDqlActionLabel:o,sourceRunId:a,sourceQuestion:d,onOpenBlock:u,onOpenResearch:x,onOpenApp:g,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:g});const b=Be(c),h=ft(c),v=Dt(c),m=typeof c.sql=="string"?c.sql:typeof c.sqlPreview=="string"?c.sqlPreview:typeof c.proposedSql=="string"?c.proposedSql:void 0,q=typeof c.name=="string"?c.name:e.title,P=typeof c.path=="string"?c.path:e.ref,$=c.draftBlock&&typeof c.draftBlock=="object"&&!Array.isArray(c.draftBlock)?c.draftBlock:void 0,L=typeof($==null?void 0:$.path)=="string"?$.path:void 0,C=typeof($==null?void 0:$.name)=="string"?$.name:void 0,M=(h==null?void 0:h.sourcePath)??L??(e.kind==="dql_block_draft"?P:void 0),Q=(h==null?void 0:h.name)??C??q,B=(h==null?void 0:h.kind)==="sql_block"||e.kind==="dql_block_draft"?"Open DQL draft":"Open DQL artifact",W=c.plan&&typeof c.plan=="object"?c.plan:void 0,H=Array.isArray(W==null?void 0:W.steps)?W.steps:[],ne=Array.isArray(W==null?void 0:W.gaps)?W.gaps.map(String):[],A=typeof c.researchRunId=="string"?c.researchRunId:e.kind==="research_run"&&typeof e.ref=="string"?e.ref:void 0,J=typeof c.notebookPath=="string"?c.notebookPath:void 0,R=Array.isArray(c.generatedPaths)?c.generatedPaths.filter(T=>typeof T=="string"):[],w=c.narration&&typeof c.narration=="object"?c.narration:void 0,K=Array.isArray(w==null?void 0:w.keyFindings)?w.keyFindings.filter(T=>typeof T=="string"):[],U=typeof(w==null?void 0:w.recommendation)=="string"?w.recommendation:void 0,X=e.trustState==="certified"?Er(e,c):void 0;if(e.kind==="dql_block_draft"){const T=re=>Array.isArray(re)?re.filter(V=>typeof V=="string"):void 0,E=c.certifierVerdict&&typeof c.certifierVerdict=="object"?c.certifierVerdict:void 0;return t.jsx(Qi,{t:n,name:typeof c.name=="string"?c.name:q,status:"draft",description:typeof c.description=="string"?c.description:void 0,dql:(h==null?void 0:h.source)??(typeof c.dqlSource=="string"?c.dqlSource:void 0),sqlPreview:m,grain:typeof c.grain=="string"?c.grain:void 0,outputs:T(c.outputs),dimensions:T(c.dimensions)??(h==null?void 0:h.dimensions),entities:T(c.entities),certifierVerdict:E?{blocking:T(E.blocking)??[],warnings:T(E.warnings)??[],ready:!!E.ready}:void 0,actions:t.jsxs(t.Fragment,{children:[m&&s?t.jsx("button",{type:"button",onClick:()=>s({sql:m,dqlArtifact:h,result:b,chartConfig:b?Fe(c,b):void 0,title:q,sourceRunId:a,question:d}),style:Y(n),children:o??"Insert as DQL cell"}):m&&i?t.jsx("button",{type:"button",onClick:()=>i(m,q,{question:d,sourceRunId:a}),style:Y(n),children:"Insert SQL preview"}):null,M&&u?t.jsx("button",{type:"button",onClick:()=>u(M,Q),style:Y(n),children:B}):null]})})}return t.jsxs("div",{style:cn(n),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(Ze,{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)})]}),K.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(Xn,{items:K,t:n,renderItem:(T,E)=>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:T})]},E)})]}):H.length>0?t.jsx("div",{style:{display:"grid",gap:5},children:t.jsx(Xn,{items:H,t:n,renderItem:(T,E)=>t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.35},children:[E+1,". ",String(T.thought??T.expectation??"Research step")]},E)})}):null,U?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:U})]}):null,b?h?t.jsx(Mr,{artifact:h,certifiedBlockName:X,initialResult:b,initialChartConfig:Fe(c,b),payload:c,t:n,themeMode:r}):t.jsx(un,{result:b,themeMode:r,t:n,chartConfig:Fe(c,b)}):null,h?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(ut,{size:12}),t.jsx("span",{children:"View DQL artifact"}),t.jsxs("span",{style:{marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:4},children:[h.source?t.jsx(It,{text:h.source,t:n,title:"Copy DQL"}):null,!M&&l?t.jsxs("button",{type:"button",className:"dql-hover",title:"Save this DQL as a reusable block",onClick:T=>{T.preventDefault(),T.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(fn,{size:12})," Save as block"]}):null]})]}),h.sourcePath?t.jsx("div",{style:{marginTop:6,fontSize:10.5,color:n.textMuted},children:h.sourcePath}):null,t.jsx("pre",{style:{...ct(n),marginTop:6},children:h.source})]}):null,m?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(pn,{size:12}),t.jsx("span",{children:Pr(!!h)}),t.jsx("span",{style:{marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:4},children:t.jsx(It,{text:m,t:n,title:"Copy SQL"})})]}),t.jsx("pre",{style:{...ct(n),marginTop:6},children:m})]}):null,ne.length>0?t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.4},children:["Gaps: ",ne.join(", ")]}):null,R.length>0?t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.4},children:["Files: ",R.join(", ")]}):null,t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[A&&x?t.jsx("button",{type:"button",onClick:()=>x(A,J),style:Y(n),children:"Open research"}):null,m&&s?t.jsx("button",{type:"button",onClick:()=>s({sql:m,dqlArtifact:h,result:b,chartConfig:b?Fe(c,b):void 0,title:q,mixedSourcePlan:v,sourceRunId:a,question:d}),style:v?{...Y(n),background:n.accent,borderColor:n.accent,color:"#fff",fontWeight:850,padding:"7px 11px"}:Y(n),children:v?"Add workflow to notebook":h?"Insert as DQL cell":"Add SQL to notebook"}):m&&i?t.jsx("button",{type:"button",onClick:()=>i(m,q,{question:d,sourceRunId:a}),style:Y(n),children:"Insert SQL preview"}):null,M&&u?t.jsx("button",{type:"button",onClick:()=>u(M,Q),style:Y(n),children:B}):null]})]})}function Ts({run:e}){return e.trustState==="certified"?t.jsx(ye,{size:16,color:"#16a34a"}):e.trustState==="governed"?t.jsx(ye,{size:16,color:"#2563eb"}):e.trustState==="grounded"?t.jsx(ye,{size:16,color:"#2563eb"}):e.status==="completed"?t.jsx(lt,{size:16,color:"#16a34a"}):e.status==="blocked"?t.jsx(tn,{size:16,color:"#ef4444"}):t.jsx(tn,{size:16,color:"#d97706"})}function Ze({kind:e}){return e==="sql_cell"?t.jsx(pn,{size:14}):e==="dql_block_draft"?t.jsx(ut,{size:14}):e==="app_draft"||e==="app_proposal"?t.jsx(en,{size:14}):e==="research_run"?t.jsx(at,{size:14}):t.jsx(Ve,{size:14})}function Bs({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":bn(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 Wr({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(dn,{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(ye,{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(dn,{evaluation:s,t:n},s.id))})]}):null]})}function dn({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 Xt({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 $s(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 Fr({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(dt,{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=$s(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,". ",jr[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(ur,{size:10}):r.status==="repaired"?t.jsx(Lt,{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(dn,{evaluation:s,t:n},s.id))}):null]},r.id)})})]})}function Ms(e){if(e==="research")return"research";if(e==="sql_cell")return"sql";if(e==="dql_block_draft")return"block";if(e==="modeling_draft")return"modeling";if(e==="skill_draft")return"skill";if(e==="app_build")return"app";if(e==="certified_answer"||e==="semantic_answer"||e==="generated_answer")return"ask"}function Es(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==="modeling_draft"?`Revise the modeling proposal for: ${e.question}`:n==="skill_draft"?`Revise the Skill proposal for: ${e.question}`:n==="app_build"?`Build an app for: ${e.question}`:n==="research"?`Research deeper: ${e.question}`:e.question}function er(e){return`${e}_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function Je(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 Ls(e,n){const r=i=>i.toLowerCase().replace(/[\s.,!?'"()`*_-]+/g," ").trim();return r(e)===r(n)}function Be(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(u=>!!(u&&typeof u=="object")):[],d=Array.isArray(o.columns)&&o.columns.length>0?o.columns.map(u=>typeof u=="string"?u:(u==null?void 0:u.name)??String(u)):a.length>0?Object.keys(a[0]):[];if(!(a.length===0&&d.length===0&&typeof o.rowCount!="number"))return{columns:d,rows:a,rowCount:typeof o.rowCount=="number"?o.rowCount:a.length,...typeof o.executionTime=="number"?{executionTime:o.executionTime}:{}}}}function Fe(e,n){const r=e.result&&typeof e.result=="object"?e.result:void 0,i=r!=null&&r.chartConfig&&typeof r.chartConfig=="object"?r.chartConfig:e.chartConfig&&typeof e.chartConfig=="object"?e.chartConfig:{},s=typeof e.suggestedViz=="string"?e.suggestedViz:typeof(r==null?void 0:r.suggestedViz)=="string"?r.suggestedViz:void 0,o=i.decisionSource==="authored"||i.decisionSource==="agent"||i.decisionSource==="data"||i.decisionSource==="user"?i.decisionSource:void 0,a=typeof i.chart=="string"?i.chart:s,d=a?a.toLowerCase().replace(/_/g,"-")==="single-value"?"kpi":a:void 0,u=n.columns,x=c=>typeof i[c]=="string"&&u.includes(i[c])?i[c]:void 0,g=Array.isArray(i.metrics)?i.metrics.filter(c=>typeof c=="string"&&u.includes(c)):[],l={...d?{chart:d}:{},...d?{decisionSource:o??"agent"}:{},...typeof i.rationale=="string"?{rationale:i.rationale}:{},...x("x")?{x:x("x")}:{},...x("y")?{y:x("y")}:{},...g.length>0?{metrics:g}:{},...x("color")?{color:x("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 Dr(e,n){var i;const r=Fe(e,n);return(r==null?void 0:r.chart)==="table"&&(((i=r.metrics)==null?void 0:i.length)??0)<=1&&r.decisionSource!=="authored"&&r.decisionSource!=="user"?{...r,chart:void 0}:r}function ft(e){const n=Ge(e.dqlArtifact);if(n)return n;const r=e.researchRun&&typeof e.researchRun=="object"&&!Array.isArray(e.researchRun)?e.researchRun:void 0;return Ge(r==null?void 0:r.dqlArtifact)}function Pr(e){return e?"View compiled SQL preview":"View SQL preview"}function It({text:e,t:n,title:r="Copy"}){const[i,s]=f.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(ot,{size:12}):t.jsx(fr,{size:12}),i?"Copied":null]})}function oe(e){return e.payload&&typeof e.payload=="object"&&!Array.isArray(e.payload)?e.payload:{}}function Ws(e){var i,s,o;const n=[],r=new Set;for(const a of e.artifacts){const d=oe(a),u=Array.isArray(d.memoryContext)?d.memoryContext:[];for(const g of u){if(!g||typeof g!="object")continue;const l=g,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 x=Array.isArray(d.appliedHints)?d.appliedHints:[];for(const g of x){if(!g||typeof g!="object")continue;const l=g,c=typeof l.title=="string"?l.title.trim():"";if(!c||r.has(`h:${c}`))continue;r.add(`h:${c}`);const b=typeof((i=l.lesson)==null?void 0:i.rule)=="string"?l.lesson.rule:typeof l.guidance=="string"?l.guidance:void 0,h=[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,m=typeof((o=l.matchSignals)==null?void 0:o.graphScore)=="number"?l.matchSignals.graphScore:void 0,q=v!==void 0||m!==void 0?`Signals: lexical ${(v??0).toFixed(2)}, graph ${(m??0).toFixed(2)}`:void 0;n.push({kind:"hint",id:typeof l.hintId=="string"?l.hintId:void 0,label:c,detail:[b,h?`Matched: ${h}`:void 0,q].filter(Boolean).join(" · ")||void 0})}}return n.slice(0,6)}function Nr({run:e,t:n}){const[r,i]=f.useState(!1),[s,o]=f.useState(new Set),a=f.useMemo(()=>Ws(e).filter(u=>!u.id||!s.has(u.id)),[e,s]);if(a.length===0)return null;const d=async u=>{try{await te.deleteAgentMemory(u),o(x=>new Set(x).add(u))}catch{}};return t.jsxs("div",{style:{display:"grid",gap:6,gridTemplateColumns:"minmax(0, 1fr)",minWidth:0},children:[t.jsxs("button",{type:"button",onClick:()=>i(u=>!u),style:Ds(n),children:[t.jsx(zt,{size:11}),t.jsxs("span",{children:["Applied ",a.length," learning",a.length>1?"s":""]}),r?t.jsx(pr,{size:11}):t.jsx($t,{size:11})]}),r?t.jsxs("div",{style:Ps(n),children:[a.map(u=>t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-start"},children:[t.jsx("span",{style:Ns(n,u.kind),children:u.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:u.label}),u.detail?t.jsx("div",{style:{fontSize:11,color:n.textMuted,lineHeight:1.4,marginTop:1},children:u.detail}):null]}),u.kind==="memory"&&u.id?t.jsx("button",{type:"button",onClick:()=>void d(u.id),style:Hs(n),children:"Stop using"}):null]},`${u.kind}:${u.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 vn(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=oe(o);o.ref&&s(o.ref,i);const d=a.plan&&typeof a.plan=="object"?a.plan:void 0;Array.isArray(d==null?void 0:d.sources)&&d.sources.forEach(u=>s(u,i)),s(a.sourceCertifiedBlock,!0)}return n.slice(0,4)}function ke(e){for(const n of e.artifacts){const r=oe(n),i=r.researchRun&&typeof r.researchRun=="object"?r.researchRun:void 0,s=r.result&&typeof r.result=="object"&&!Array.isArray(r.result)?r.result:void 0,o=Ge(r.dqlArtifact),a=r.proposedSql??r.sql??r.sqlPreview??(s==null?void 0:s.sql)??(i==null?void 0:i.generatedSql)??(i==null?void 0:i.reviewedSql)??(o==null?void 0:o.compiledSql);if(typeof a=="string"&&a.trim())return a}}function Zt(e){var n;if(e.trustState==="certified")for(const r of e.artifacts){const i=oe(r),s=i.blockName??i.blockId??((n=Ge(i.dqlArtifact))==null?void 0:n.name);if(typeof s=="string"&&s.trim())return s.trim()}}function Fs(e){for(const n of e.artifacts){const r=oe(n),i=Be(r);if(!i)continue;const s=Fe(r,i);if(s)return s}}function Ae(e){for(const n of e.artifacts){const r=oe(n),i=Ge(r.dqlArtifact);if(i)return i;const s=r.researchRun&&typeof r.researchRun=="object"&&!Array.isArray(r.researchRun)?r.researchRun:void 0,o=Ge(s==null?void 0:s.dqlArtifact);if(o)return o}}function _t(e){const n=e.route==="dql_block_draft"&&e.status!=="blocked"&&e.status!=="needs_clarification";if(e.route==="certified_answer"||!pt(e)&&!n)return;const r=Ae(e),i=ke(e);if(!((!(r!=null&&r.source)||r.sourcePath)&&!i)){for(const s of e.artifacts){const o=oe(s),a=Be(o),d=Dt(o);if(a)return{sql:i,dqlArtifact:r,result:a,chartConfig:Fe(o,a),title:(r==null?void 0:r.name)??s.title??e.question,mixedSourcePlan:d,sourceRunId:e.id,question:e.question,executionTarget:e.executionTarget};if(d)return{sql:i,dqlArtifact:r,title:(r==null?void 0:r.name)??s.title??e.question,mixedSourcePlan:d,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 Dt(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 Hr(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 Ds(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 Ps(e){return{display:"grid",gap:8,padding:10,borderRadius:8,background:e.cellBg,border:`1px solid ${e.headerBorder}`}}function Ns(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 Os(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 tr(e){return{...Os(e),width:40,height:40}}function Tt(e){return{...Et(e,{variant:"secondary",size:"md",pill:!0}),fontWeight:550}}function Qs(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 nr(e,n){return{...Et(e,{variant:n?"primary":"secondary",size:"lg"}),...n?{}:{color:e.textMuted}}}function rr(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 Vs(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 Gs(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 ir(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 sr(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 Ks(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 Us(e){return{alignSelf:"flex-start",maxWidth:"92%",color:e.textPrimary,border:`1px solid ${e.cellBorder}`,background:e.appBg,borderRadius:10,padding:"10px 12px"}}function Ys(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 cn(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 Js(e){return{border:`1px solid ${e.headerBorder}`,background:e.cellBg,borderRadius:8,padding:9,fontSize:12.5,color:e.textPrimary,lineHeight:1.45}}function ct(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 or(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 Y(e){return Et(e,{variant:"secondary",size:"sm"})}const Bt={warehouse:{title:"The warehouse rejected the query",hint:"The SQL reached your warehouse and it refused. The message below is the driver’s own."},dql_compilation:{title:"DQL could not build a reusable block",hint:"The query itself is fine — only saving this answer as a block is affected."},governance_gate:{title:"DQL stopped this before running it",hint:"A governance check refused the query, so it never reached the warehouse."},retrieval_gap:{title:"DQL could not confirm this data exists",hint:"The relation was not in the inspected metadata. Refreshing the connection scope usually resolves it."},ambiguity:{title:"One detail is missing",hint:"Answer the question above and DQL will continue."},provider:{title:"The AI provider failed",hint:"Nothing was run. Retry, or check the provider in Settings."},host:{title:"DQL hit an internal error",hint:"This is a defect in DQL. The detail below is what to report."},unknown:{title:"The query could not be completed",hint:"Inspect the details or use the bounded repair when it is available."}};function Or(e){var n,r,i;for(const s of e.artifacts??[]){const o=oe(s),a=(n=o==null?void 0:o.warehouseFailure)==null?void 0:n.origin;if(typeof a=="string"&&a in Bt)return a;if(o!=null&&o.providerFailure||(o==null?void 0:o.refusalCode)==="provider_error")return"provider"}return((i=(r=e.diagnosticReceipt)==null?void 0:r.failure)==null?void 0:i.code)==="AI_PROVIDER_FAILURE"?"provider":"unknown"}function Xs(e){var n,r;if(e.status!=="blocked"||!ke(e)&&!((n=Ae(e))!=null&&n.source))return!1;for(const i of e.artifacts??[]){const s=oe(i),o=(r=s==null?void 0:s.warehouseFailure)==null?void 0:r.category;if(typeof o=="string"&&["permission","authentication","unsafe","cancelled"].includes(o))return!1}return!0}function Zs({run:e,detail:n,threadId:r,onRepaired:i,t:s}){const o=Or(e),a=Bt[o]??Bt.unknown,[d,u]=f.useState(!1),[x,g]=f.useState(null),l=Xs(e),c=async()=>{if(!d){u(!0),g(null);try{const b=await te.repairAgentRunExecution(e.id,r);i(b.run)}catch(b){g(b instanceof Error?b.message:String(b))}finally{u(!1)}}};return t.jsxs("div",{"data-followup":"answer",style:{display:"flex",flexDirection:"column",gap:6,padding:"11px 13px",borderRadius:9,border:`1px solid ${s.error}33`,background:`${s.error}0d`},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7},children:[t.jsx(Xe,{size:13,color:s.error,style:{flexShrink:0}}),t.jsx("span",{style:{fontSize:12.5,fontWeight:700,color:s.textPrimary},children:a.title})]}),t.jsx("div",{style:{fontSize:12.5,lineHeight:1.6,color:s.textSecondary,wordBreak:"break-word"},children:Te(n)}),t.jsx("div",{style:{fontSize:11.5,lineHeight:1.5,color:s.textMuted},children:a.hint}),l?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap",marginTop:2},children:[t.jsxs("button",{type:"button",className:"dql-hover",disabled:d,onClick:()=>void c(),style:{...Y(s),opacity:d?.7:1},children:[t.jsx(Lt,{size:12})," ",d?"Fixing and retrying…":"Fix and retry"]}),t.jsx("span",{style:{fontSize:10.5,color:s.textMuted},children:"One bounded repair attempt on the same data target."})]}):null,x?t.jsx("div",{role:"alert",style:{fontSize:11.5,lineHeight:1.45,color:s.error},children:Te(x)}):null]})}function Qr(e){var n,r;for(const i of e.artifacts??[]){const s=oe(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(d=>typeof d=="string"&&d.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 uo=Object.freeze(Object.defineProperty({__proto__:null,ASK_FAILURE_PRESENTATION:Bt,UnifiedAgentRunPanel:us,agentRunHistoryFromItems:vr,analyticalInspectorContract:Tr,analyticalInspectorSections:ks,analyticalRepairActionLabels:As,appPinDestinationLabel:ln,artifactReadyPayloadFromRun:_t,artifactSqlDisclosureLabel:Pr,askAppDestinations:$r,askAppWriteErrorMessage:on,askArtifactMeta:Wt,askFailureDetail:Qr,askFailureOrigin:Or,askInspectorTabsForState:zr,clarificationSelectionInput:At,completedRunGuidanceFor:qr,deriveResultChartConfig:hi,hasAnalyticalInspectorContract:Ft,inlineAskChartConfig:Dr,isAgentRunPinnable:pt,liveAgentActivityFor:Cr,longRunGuidanceFor:Ar,preferredAskInspectorTab:xn,replacePresentedAgentRun:br,researchSourceFromRun:Br,resolveArtifactDqlView:ft,resolvedParameterValues:an,selectAgentExecutionConnection:wr,threadItemsFromTurns:kr,trustExplainer:mn,usePersistedAgentThreadId:xi},Symbol.toStringTag,{value:"Module"}));export{Gi as B,pr as C,Dn as S,us as U,Li as a,Oi as b,uo as c};
|