@duckcodeailabs/dql-cli 1.13.0 → 1.13.1

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.
Files changed (79) hide show
  1. package/dist/args.d.ts +2 -0
  2. package/dist/args.d.ts.map +1 -1
  3. package/dist/args.js +3 -0
  4. package/dist/args.js.map +1 -1
  5. package/dist/assets/dql-notebook/assets/{AgentAnswerCard-Cp0eh6zU.js → AgentAnswerCard-c8QUo6NH.js} +4 -4
  6. package/dist/assets/dql-notebook/assets/{AgentLogPage-CBGEoGmU.js → AgentLogPage-D6fgEAEy.js} +1 -1
  7. package/dist/assets/dql-notebook/assets/{AiBuildDialog-CwAD3tXE.js → AiBuildDialog-8miXFPse.js} +1 -1
  8. package/dist/assets/dql-notebook/assets/{AiBuildResult-CyqTuQe5.js → AiBuildResult-DPJ_SI0R.js} +3 -3
  9. package/dist/assets/dql-notebook/assets/{AiSidePanel-DjB8PWHG.js → AiSidePanel-NVA6lZnn.js} +1 -1
  10. package/dist/assets/dql-notebook/assets/{AnalyticsHome-B7BkvA-R.js → AnalyticsHome-DgwnRW71.js} +2 -2
  11. package/dist/assets/dql-notebook/assets/AppsView-B6LYUpgm.js +4578 -0
  12. package/dist/assets/dql-notebook/assets/BlockStudio--jNw9XUI.js +60 -0
  13. package/dist/assets/dql-notebook/assets/{BusinessArtifactView-C4SZVNW-.js → BusinessArtifactView-DtRMiaF4.js} +1 -1
  14. package/dist/assets/dql-notebook/assets/DbtFirstModelingPage-DhBsLCYr.js +22 -0
  15. package/dist/assets/dql-notebook/assets/{GitPage-BfVD4tVq.js → GitPage-CazC-eTR.js} +1 -1
  16. package/dist/assets/dql-notebook/assets/GlobalAiRail-1Tgweuu2.js +1 -0
  17. package/dist/assets/dql-notebook/assets/GovernedContextPage-C7qGrH3d.js +16 -0
  18. package/dist/assets/dql-notebook/assets/{HelpDocsPage-BDPNVot1.js → HelpDocsPage-DMHPsVqP.js} +1 -1
  19. package/dist/assets/dql-notebook/assets/{HomePage-DiOnRhEG.js → HomePage-DcSI4dnU.js} +1 -1
  20. package/dist/assets/dql-notebook/assets/{LineageDAG-BiUFX2KL.js → LineageDAG-BJ6xz06u.js} +1 -1
  21. package/dist/assets/dql-notebook/assets/{LineageDetailView-CfbSvlPJ.js → LineageDetailView-8WrQm-MF.js} +1 -1
  22. package/dist/assets/dql-notebook/assets/{LineageDrawer-CgTScaGB.js → LineageDrawer-hnqCW_t-.js} +1 -1
  23. package/dist/assets/dql-notebook/assets/{LineagePathBreadcrumb-D7ZA7k68.js → LineagePathBreadcrumb-B4LZTUsl.js} +1 -1
  24. package/dist/assets/dql-notebook/assets/{MiniLineageGraph-GkD4y17x.js → MiniLineageGraph-CotnRuxa.js} +1 -1
  25. package/dist/assets/dql-notebook/assets/{NewBlockModal-B9TfRjt7.js → NewBlockModal-DHn-CEEW.js} +1 -1
  26. package/dist/assets/dql-notebook/assets/{NewNotebookModal-BbO9NKUl.js → NewNotebookModal-BPGp-8oq.js} +1 -1
  27. package/dist/assets/dql-notebook/assets/{NotebookEditor-CuMpvXR9.js → NotebookEditor-B0OTHM6W.js} +26 -31
  28. package/dist/assets/dql-notebook/assets/{ReadinessPage-BROJ9YBM.js → ReadinessPage-CoOIpxWq.js} +1 -1
  29. package/dist/assets/dql-notebook/assets/{SetupOnboarding-BCcZlpuQ.js → SetupOnboarding-DxK_mFzf.js} +1 -1
  30. package/dist/assets/dql-notebook/assets/{TrustBadge-vQQh8d0D.js → TrustBadge-ZuD5N5Ww.js} +1 -1
  31. package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-duFXXNV_.js +88 -0
  32. package/dist/assets/dql-notebook/assets/{answer-to-notebook-DuqCcDDl.js → answer-to-notebook-WAVAYjBv.js} +1 -1
  33. package/dist/assets/dql-notebook/assets/{arrow-left-CMe1kkOL.js → arrow-left-L8odLbyN.js} +1 -1
  34. package/dist/assets/dql-notebook/assets/{arrow-right-DvB_DONr.js → arrow-right-WIF1V9a9.js} +1 -1
  35. package/dist/assets/dql-notebook/assets/{book-open-text-CJ3NAvrs.js → book-open-text-BpqWMa4m.js} +1 -1
  36. package/dist/assets/dql-notebook/assets/{bot-CV8DYRrt.js → bot-CLR1V6dO.js} +1 -1
  37. package/dist/assets/dql-notebook/assets/{circle-x-BCgtha1W.js → circle-x-CQBOM0b0.js} +1 -1
  38. package/dist/assets/dql-notebook/assets/{dagre.esm-GKp7qoUL.js → dagre.esm-DlZi7NR3.js} +1 -1
  39. package/dist/assets/dql-notebook/assets/{external-link-C-PXokWV.js → external-link-DYqdQIGp.js} +1 -1
  40. package/dist/assets/dql-notebook/assets/{grip-vertical-B4EHbGXW.js → grip-vertical-HmUijbwN.js} +1 -1
  41. package/dist/assets/dql-notebook/assets/{index-1mIC_XX4.js → index-Cpx47jCH.js} +43 -43
  42. package/dist/assets/dql-notebook/assets/{list-tree-BRFpEmvV.js → list-tree-DGKqCxmz.js} +1 -1
  43. package/dist/assets/dql-notebook/assets/{minimize-2-CDwSCGlO.js → minimize-2-C8dvqCxX.js} +1 -1
  44. package/dist/assets/dql-notebook/assets/{panel-right-open-CunA1xO7.js → panel-right-open-yuVkIo5n.js} +1 -1
  45. package/dist/assets/dql-notebook/assets/{rotate-ccw-DOrfTZk8.js → rotate-ccw-Di0kRnrM.js} +1 -1
  46. package/dist/assets/dql-notebook/assets/{semantic-fields-AfQvjt5R.js → semantic-fields-BMQV0li8.js} +1 -1
  47. package/dist/assets/dql-notebook/assets/sliders-horizontal-alebptlJ.js +6 -0
  48. package/dist/assets/dql-notebook/assets/{star-DDhv4e8M.js → star-CgCQbnXc.js} +1 -1
  49. package/dist/assets/dql-notebook/assets/{triangle-alert-2ZXx8wAu.js → triangle-alert-SyuSZ4ht.js} +1 -1
  50. package/dist/assets/dql-notebook/assets/upload-BPhfea_E.js +11 -0
  51. package/dist/assets/dql-notebook/assets/usePersistedAgentThreadId-Bnl9gWhj.js +28 -0
  52. package/dist/assets/dql-notebook/assets/{user-round-BA074kiQ.js → user-round-J4PQHxo9.js} +1 -1
  53. package/dist/assets/dql-notebook/assets/{wand-sparkles-CEYHLt9b.js → wand-sparkles-c4WDXTCk.js} +1 -1
  54. package/dist/assets/dql-notebook/assets/{workflow-CZtyrcR-.js → workflow-NtRLaq7n.js} +1 -1
  55. package/dist/assets/dql-notebook/assets/{wrench-Ong23-wu.js → wrench-CS1f1Zv4.js} +1 -1
  56. package/dist/assets/dql-notebook/assets/{x-CSo1M3tu.js → x-CbKEfe5m.js} +1 -1
  57. package/dist/assets/dql-notebook/index.html +1 -1
  58. package/dist/commands/model.d.ts.map +1 -1
  59. package/dist/commands/model.js +62 -1
  60. package/dist/commands/model.js.map +1 -1
  61. package/dist/index.js +3 -0
  62. package/dist/index.js.map +1 -1
  63. package/dist/local-runtime.d.ts +10 -0
  64. package/dist/local-runtime.d.ts.map +1 -1
  65. package/dist/local-runtime.js +1061 -17
  66. package/dist/local-runtime.js.map +1 -1
  67. package/dist/package.json +10 -10
  68. package/package.json +10 -10
  69. package/dist/assets/dql-notebook/assets/AppsView-CUrqtEGC.js +0 -4583
  70. package/dist/assets/dql-notebook/assets/BlockStudio-Bl0aGQJR.js +0 -60
  71. package/dist/assets/dql-notebook/assets/DbtFirstModelingPage-B0uxitnx.js +0 -22
  72. package/dist/assets/dql-notebook/assets/GlobalAiRail-DUwdy3fB.js +0 -1
  73. package/dist/assets/dql-notebook/assets/GovernedContextPage-D9f26ZFb.js +0 -7
  74. package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-Dj4AXAhT.js +0 -83
  75. package/dist/assets/dql-notebook/assets/chevron-up-HxU1l85K.js +0 -6
  76. package/dist/assets/dql-notebook/assets/link-2-BLx-goet.js +0 -6
  77. package/dist/assets/dql-notebook/assets/maximize-2-CCd5uRIZ.js +0 -6
  78. package/dist/assets/dql-notebook/assets/pencil-D_I14Wyk.js +0 -6
  79. package/dist/assets/dql-notebook/assets/usePersistedAgentThreadId-3rzkZrqc.js +0 -18
@@ -1,83 +0,0 @@
1
- import{c as _e,r as f,a as te,j as t,d as Tt,g as it,l as ge,aZ as Hr,f as st,L as He,aH as Qr,a$ as Xn,B as ct,e as Zn,u as Bt,t as er,a5 as Vr,b0 as Je,E as Gr,H as Kr,b1 as Ur,w as Yr,S as Qe,aE as tr,b as $t,a_ as Xe,P as nt,D as Jr,G as nr,b2 as Xr,aY as Jt,a0 as Dt}from"./index-1mIC_XX4.js";import{S as kt,R as ln,d as Zr}from"./AgentAnswerCard-Cp0eh6zU.js";import{S as ei,F as ot,d as an,e as ti,A as ni,u as ri}from"./usePersistedAgentThreadId-3rzkZrqc.js";import{C as ii}from"./AiBuildResult-CyqTuQe5.js";import{T as Nt}from"./triangle-alert-2ZXx8wAu.js";import{U as si}from"./user-round-BA074kiQ.js";import{X as At}from"./x-CSo1M3tu.js";import{P as oi}from"./pencil-D_I14Wyk.js";import{L as lt}from"./list-tree-BRFpEmvV.js";import{W as Et}from"./wrench-Ong23-wu.js";import{M as li}from"./minimize-2-CDwSCGlO.js";import{M as ai}from"./maximize-2-CCd5uRIZ.js";import{A as ci}from"./arrow-right-DvB_DONr.js";import{C as rr}from"./chevron-up-HxU1l85K.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 di=[["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"}]],ui=_e("archive",di);/**
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 pi=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],fi=_e("circle",pi);/**
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 gi=[["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"}]],ir=_e("copy",gi);/**
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 xi=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],hi=_e("ellipsis",xi);/**
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 yi=[["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"}]],qt=_e("lightbulb",yi);/**
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 mi=[["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"}]],Xt=_e("route",mi);/**
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 bi=[["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"}]],cn=_e("save",bi);/**
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 vi=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],qn=_e("square",vi);/**
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 ji=[["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"}]],Si=_e("zap",ji),Ot=[{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 Cn({t:e,value:n,onChange:r}){const[i,s]=f.useState(null),[o,a]=f.useState(!1),u=f.useRef(null);f.useEffect(()=>{let g=!1;return te.getProviderSettings().then(({providers:l})=>{g||s(l.find(d=>d.active)??null)}).catch(()=>{}),()=>{g=!0}},[]),f.useEffect(()=>{if(!o)return;const g=l=>{u.current&&!u.current.contains(l.target)&&a(!1)};return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[o]);const c=Ot.find(g=>g.mode===n)??Ot[0],j=i?[i.label,i.model].filter(Boolean).join(" · "):null;return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[j?t.jsxs("span",{title:"Connected model",style:zn(e),children:[t.jsx(fi,{size:7,fill:e.success,color:e.success}),t.jsx("span",{style:{color:e.textSecondary},children:j})]}):null,t.jsxs("div",{ref:u,style:{position:"relative"},children:[t.jsxs("button",{type:"button",onClick:()=>a(g=>!g),title:"How hard the model thinks for this thread",style:{...zn(e),cursor:"pointer"},children:[t.jsx(Si,{size:12,color:e.textMuted}),t.jsxs("span",{style:{color:e.textSecondary},children:["Thinking: ",c.label]}),t.jsx(Tt,{size:12,color:e.textMuted})]}),o?t.jsx("div",{role:"menu",style:wi(e),children:Ot.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:ki(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(it,{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 zn(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 wi(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 ki(e,n){return{display:"block",width:"100%",textAlign:"left",padding:"8px 10px",borderRadius:7,border:"none",background:n?e.pillBg:"transparent",cursor:"pointer"}}const Ai={draft:"#8b949e",review:"#d29922",certified:"#3fb950",deprecated:"#f85149",pending_recertification:"#db6d28"},qi={queued:"#8b949e",generating:"#4c8dff",running:"#4c8dff",saving:"#4c8dff",saved:"#2ea043",ready:"#2ea043",blocked:"#f85149",needs_attention:"#d29922"},Ci={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"},zi={draft:Xn,queued:Qr,generating:He,running:He,saving:He,ready:st,saved:st,blocked:Nt,needs_attention:Nt,review:Hr,certified:ge,deprecated:ui,pending_recertification:Nt},Ri=new Set(["generating","running","saving"]);function Ii(e){return Ai[e]??qi[e]??"#8b949e"}function _i(e){return Ci[e]??e.charAt(0).toUpperCase()+e.slice(1).replace(/_/g," ")}function Ti({status:e,t:n,label:r}){const i=Ii(e),s=zi[e]??Xn,o=r??_i(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:Ri.has(e)?"spin":void 0}),o]})}function Bi(e){const{t:n,name:r,status:i="draft",description:s,dql:o,sqlPreview:a,grain:u,outputs:c=[],dimensions:j=[],entities:g=[],examples:l=[],sourceTables:d=[],evidence:y=[],certifierVerdict:m,owner:v,actions:x}=e,[z,I]=f.useState(!1),[Q,G]=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(ct,{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(Ti,{status:i,t:n}),u?t.jsxs("span",{style:Zt(n),children:["grain ",u]}):null]}),s?t.jsx("div",{style:{fontSize:12,color:n.textSecondary,lineHeight:1.5},children:s}):null,o?t.jsx(Rn,{open:z,onToggle:()=>I(q=>!q),label:"Governed DQL",t:n,lead:!0,children:t.jsx("pre",{style:In(n),children:o})}):null,a?t.jsx(Rn,{open:Q,onToggle:()=>G(q=>!q),label:o?"Compiled SQL preview":"SQL this block will run",t:n,children:t.jsx("pre",{style:In(n),children:a})}):null,t.jsx(Ht,{label:"Outputs",items:c,t:n}),t.jsx(Ht,{label:"Dimensions",items:j,t:n}),t.jsx(Ht,{label:"Entities",items:g,t:n}),l.length>0?t.jsxs("div",{style:{display:"grid",gap:5},children:[t.jsx(sr,{t:n,children:"Answers questions like"}),t.jsx("ul",{style:{margin:0,padding:"0 0 0 16px",display:"grid",gap:3},children:l.slice(0,3).map(q=>t.jsx("li",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.45},children:q},q))})]}):null,d.length>0||y.length>0?t.jsxs("div",{style:{display:"grid",gap:6,border:`1px solid ${n.headerBorder}`,borderRadius:8,background:n.appBg,padding:10},children:[t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:10.5,fontWeight:800,color:n.textSecondary,textTransform:"uppercase"},children:[t.jsx(ge,{size:12,color:n.accent})," Grounded on"]}),d.length>0?t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:d.map(q=>t.jsx("span",{style:Zt(n),children:q},q))}):null,y.slice(0,5).map((q,N)=>t.jsxs("div",{style:{border:`1px solid ${n.headerBorder}`,borderRadius:7,padding:8,background:n.cellBg},children:[t.jsx("div",{style:{fontSize:11,fontWeight:800,color:n.textSecondary,overflowWrap:"anywhere"},children:q.name}),t.jsxs("div",{style:{fontSize:10,color:n.textMuted,marginTop:3},children:[q.kind,q.reason?` · ${q.reason}`:""]}),q.description?t.jsx("div",{style:{fontSize:11,color:n.textMuted,lineHeight:1.35,marginTop:5},children:q.description}):null]},`${q.objectKey??q.name}-${N}`))]}):null,t.jsx(ii,{t:n,verdict:m}),v?t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11,color:n.textMuted},children:[t.jsx(si,{size:12,strokeWidth:2})," drafting as ",v]}):null,x?t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:x}):null]})}function Rn({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(Tt,{size:13,strokeWidth:2}):t.jsx(Zn,{size:13,strokeWidth:2}),e?`Hide ${r.toLowerCase()}`:r]}),e?t.jsx("div",{style:{marginTop:7},children:o}):null]})}function Ht({label:e,items:n,t:r}){return n.length===0?null:t.jsxs("div",{style:{display:"grid",gap:5},children:[t.jsx(sr,{t:r,children:e}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:n.map(i=>t.jsx("span",{style:Zt(r),children:i},i))})]})}function sr({t:e,children:n}){return t.jsx("div",{style:{fontSize:10,fontWeight:800,letterSpacing:"0.05em",textTransform:"uppercase",color:e.textMuted},children:n})}function Zt(e){return{fontSize:10.5,fontWeight:700,color:e.textSecondary,background:e.pillBg,borderRadius:999,padding:"2px 8px",fontFamily:e.fontMono}}function In(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 _n(){return t.jsx("span",{style:{color:"#ff7b72",marginLeft:2},children:"*"})}function Qt(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function $i(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 Tn({cell:e,onClose:n,onSaved:r,initialContent:i,initialName:s,initialDescription:o,initialTags:a,initialDomain:u,initialOwner:c}){var E;const{state:j,dispatch:g}=Bt(),l=er[j.themeMode],d=f.useRef(null),[y,m]=f.useState(s||e.name||"new_block"),[v,x]=f.useState(u??""),[z,I]=f.useState(c??""),[Q,G]=f.useState(o??j.notebookMetadata.description??""),[q,N]=f.useState((a??j.notebookMetadata.categories??[]).join(", ")),[O,$]=f.useState(i??e.content),[H,V]=f.useState(""),[B,b]=f.useState(""),[A,U]=f.useState([]),[F,X]=f.useState(!1),[P,re]=f.useState(null),_=f.useMemo(()=>$i(O),[O]),T=f.useMemo(()=>q.split(",").map(p=>p.trim()).filter(Boolean),[q]),le=[{id:"has-name",label:"Block has name",severity:"error",passed:!!y.trim()},{id:"has-owner",label:"Block has owner",severity:"error",passed:!!z.trim()},{id:"has-description",label:"Description",severity:"warning",passed:!!Q.trim()},{id:"has-domain",label:"Domain",severity:"warning",passed:!!v.trim()},{id:"has-tags",label:"Has at least one tag",severity:"warning",passed:T.length>0},{id:"has-llm-context",label:"Has LLM context (for agents)",severity:"warning",passed:!!H.trim()}],Z=le.some(p=>p.severity==="error"&&!p.passed);f.useEffect(()=>{var p;(p=d.current)==null||p.focus()},[]),f.useEffect(()=>{const p=L=>{L.key==="Escape"&&n()};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[n]);const K=Vr(v,j.authoredDomains),oe=`${v.trim()?`blocks/${Qt(v)}/`:"blocks/"}${Qt(y)||"new-block"}.dql`,ue=async()=>{var p,L,ee;if(Z){re("Enter the block name and owner before saving.");return}if(!O.trim()){re("Block content is required.");return}X(!0),re(null);try{const ne=B.split(`
47
- `).map(k=>k.trim()).filter(Boolean),Ve=A.map(k=>({question:k.question.trim(),sql:k.sql.trim()||void 0})).filter(k=>k.question),be=await te.saveAsBlock({cellId:e.id,notebookPath:((p=j.activeFile)==null?void 0:p.path)??null,name:y.trim(),domain:v.trim()||void 0,owner:z.trim()||void 0,content:O,description:Q.trim()||void 0,tags:T,metricRefs:_,llmContext:H.trim()||void 0,examples:Ve.length>0?Ve:void 0,invariants:ne.length>0?ne:void 0,reviewRequired:!!((L=e.datasetRefs)!=null&&L.length),datasetRefs:e.datasetRefs,lineage:(ee=e.dqlArtifact)==null?void 0:ee.lineage}),Be={name:`${Qt(y)||"new-block"}.dql`,path:be.path,type:"block",folder:"blocks"};j.files.some(k=>k.path===be.path)||g({type:"FILE_ADDED",file:Be});const ke=await te.openBlockStudio(be.path);g({type:"OPEN_BLOCK_STUDIO",file:Be,payload:ke}),r==null||r({...be,name:y.trim()}),n()}catch(ne){re(ne instanceof Error?ne.message:String(ne))}finally{X(!1)}},S={width:"100%",background:l.inputBg,border:`1px solid ${P?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(_n,{})]}),t.jsx("input",{ref:d,value:y,onChange:p=>m(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=>x(p.target.value),style:S,children:[t.jsx("option",{value:"",children:"Global / cross-domain"}),K.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(_n,{})]}),t.jsx("input",{value:z,onChange:p=>I(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:q,onChange:p=>N(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:Q,onChange:p=>G(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:H,onChange:p=>V(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:B,onChange:p=>b(p.target.value),rows:2,placeholder:`Revenue is never negative
48
- 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)"}),A.map((p,L)=>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 ne=[...A];ne[L]={...ne[L],question:ee.target.value},U(ne)},placeholder:"What was revenue last month?",style:S}),t.jsx("input",{value:p.sql,onChange:ee=>{const ne=[...A];ne[L]={...ne[L],sql:ee.target.value},U(ne)},placeholder:"Optional SQL snippet",style:{...S,fontFamily:l.fontMono,fontSize:12}})]}),t.jsx("button",{type:"button",onClick:()=>U(A.filter((ee,ne)=>ne!==L)),style:{background:"transparent",border:`1px solid ${l.cellBorder}`,borderRadius:6,color:l.textMuted,cursor:"pointer",fontSize:12,padding:"0 10px"},children:"×"})]},L)),t.jsx("button",{type:"button",onClick:()=>U([...A,{question:"",sql:""}]),style:{alignSelf:"flex-start",background:l.btnBg,border:`1px solid ${l.btnBorder}`,borderRadius:6,color:l.textSecondary,cursor:"pointer",fontSize:12,fontFamily:l.font,padding:"4px 10px"},children:"+ Add example"})]})]})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6,padding:"10px 12px",background:l.pillBg,borderRadius:6,border:`1px solid ${l.cellBorder}`},children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:l.textSecondary,fontFamily:l.font,letterSpacing:"0.06em",textTransform:"uppercase"},children:"Governance checks"}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:le.map(p=>{const L=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:L,background:`${L}18`,border:`1px solid ${L}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:oe}),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:O,onChange:p=>$(p.target.value),style:{...S,minHeight:220,resize:"vertical",fontFamily:l.fontMono,lineHeight:1.5}})]}),_.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:"}),_.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))]}),P&&t.jsx("div",{style:{fontSize:12,color:l.error,fontFamily:l.font},children:P})]}),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:(E=e.datasetRefs)!=null&&E.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:ue,disabled:F||Z,title:Z?"Fix governance errors to enable Save":void 0,style:{background:l.accent,border:`1px solid ${l.accent}`,borderRadius:6,color:"#fff",cursor:F||Z?"not-allowed":"pointer",fontSize:13,fontFamily:l.font,padding:"7px 20px",opacity:F||Z?.5:1},children:F?"Saving & checking…":"Save block"})]})]})})}function or(e){return e.policy==="dynamic"||e.policy==="optional"}function Ei({parameters:e,values:n,onChange:r,onReset:i,t:s,includeNonRuntime:o=!1,card:a=!1}){const u=e.filter(c=>o||or(c));return u.length===0?null:t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(170px, 1fr))",gap:8},children:u.map(c=>{const j=Object.prototype.hasOwnProperty.call(n,c.name),g=j?n[c.name]:c.default,l=y=>r(c.name,y),d=c.type==="boolean"?t.jsxs("select",{"aria-label":c.name,value:String(g??""),onChange:y=>l(y.target.value),style:Bn(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":c.name,type:c.type==="number"?"number":c.type==="date"?"date":"text",value:Array.isArray(g)?g.join(", "):g==null?"":String(g),placeholder:c.type.endsWith("[]")?"Comma-separated values":c.required?"Required value":"Use default",onChange:y=>l(y.target.value),style:Bn(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:[Mi(c.name),c.required?t.jsx("span",{style:{color:s.error},children:"*"}):null]}),d,t.jsxs("span",{style:{display:"flex",alignItems:"center",gap:5,minHeight:14,fontSize:9.5,color:s.textMuted},children:[t.jsxs("span",{children:[c.type,o?` · ${c.policy}`:""]}),j&&i?t.jsx("button",{type:"button",onClick:()=>i(c.name),style:{marginLeft:"auto",border:0,padding:0,background:"transparent",color:s.accent,fontSize:9.5,cursor:"pointer"},children:"Reset"}):null]})]},c.name)})})}function Mi(e){return e.replace(/[_-]+/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function Bn(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 Li(e){const n=e.filter(o=>o.kind==="run").map(Wi).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=lr($n(r));return en({activeSurface:"notebook",conversationStateVersion:1,activeTurnId:r.id,activeTopic:r.question,conversationSummary:Hi(n),turns:n,sourceAnswerId:r.id,sourceCertifiedBlock:r.sourceCertifiedBlock,sourceQuestion:r.question,sourceAnswerSummary:r.answerSummary,answerContract:$n(r),dqlArtifact:r.dqlArtifact,cascade:r.cascade,resultColumns:i==null?void 0:i.columns,resultRowsSample:i==null?void 0:i.rowsSample,resultDimensionValues:i==null?void 0:i.dimensionValues,outputColumns:i==null?void 0:i.columns,requestedFilters:r.requestedFilters??Ue(s==null?void 0:s.filters),requestedDimensions:r.requestedDimensions??Ue(s==null?void 0:s.dimensions),priorLimit:r.topN??ar(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 Wi(e){var l,d,y,m;const n=e.run.artifacts.find(v=>v.kind==="answer")??e.run.artifacts.find(v=>v.kind==="research_run")??e.run.artifacts[0],r=de(n==null?void 0:n.payload),i=Fi(r),s=Vi(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=de(r==null?void 0:r.contextPack))==null?void 0:l.questionPlan)??(r==null?void 0:r.analysisPlan),u=lr(a),c=Ki(s,o),j=Qi(u,s),g=ie(r==null?void 0:r.sourceCertifiedBlock)??((n==null?void 0:n.kind)==="answer"?ie(n.ref):void 0)??ie((d=de(r==null?void 0:r.block))==null?void 0:d.name);return en({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:ie((y=de(r==null?void 0:r.route))==null?void 0:y.label)??ie((m=de(r==null?void 0:r.route))==null?void 0:m.tier),trustLabel:ie(r==null?void 0:r.trustLabel),reviewStatus:ie(r==null?void 0:r.reviewStatus),certification:ie(r==null?void 0:r.certification),contextPackId:ie(r==null?void 0:r.contextPackId),requestedFilters:Ue(u==null?void 0:u.filters),requestedDimensions:Ue(u==null?void 0:u.dimensions),requestedMeasures:Ue(u==null?void 0:u.measures),answerContract:a,dqlArtifact:Ni(r),cascade:Oi(r),topN:ar(u),result:s.length>0||o.length>0?en({columns:s,rowsSample:o,dimensionValues:c,measureColumns:j,rowCount:Pi(i)}):void 0,sourceSql:Di(r,i)})}function $n(e){return e.answerContract}function lr(e){const n=de(e);return de(n==null?void 0:n.requestedShape)}function Fi(e){const n=de(e==null?void 0:e.researchRun),r=de(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(de).filter(s=>!!(s&&(Array.isArray(s.rows)||Array.isArray(s.columns)))).sort((s,o)=>En(o)-En(s))[0]}function En(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 Pi(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 Di(e,n){var r,i;return ie(e==null?void 0:e.proposedSql)??ie(e==null?void 0:e.sql)??ie(n==null?void 0:n.sql)??ie((r=de(e==null?void 0:e.query))==null?void 0:r.sql)??ie((i=de(e==null?void 0:e.plan))==null?void 0:i.sql)}function Ni(e){var r,i;const n=Je(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 Oi(e){const n=de(e==null?void 0:e.cascade);if(!n)return;const r=ie(n.terminalLane),i=ie(n.routeTier);if(!(!r&&!i))return{terminalLane:r,routeTier:i,label:ie(n.label),ref:ie(n.ref),artifactKind:ie(n.artifactKind),refusalCode:ie(n.refusalCode),outcome:de(n.outcome)}}function Hi(e){const n=e.slice(-3).map(r=>{var o,a;const i=(o=r.result)==null?void 0:o.columns.slice(0,5).join(", "),s=(a=r.result)!=null&&a.dimensionValues?Object.entries(r.result.dimensionValues).slice(0,3).map(([u,c])=>`${u}: ${c.slice(0,3).join(", ")}`).join("; "):"";return[`Q: ${r.question}`,r.answerSummary?`A: ${r.answerSummary}`:"",i?`Columns: ${i}`:"",s?`Values: ${s}`:""].filter(Boolean).join(" | ")}).filter(Boolean);return n.length>0?n.join(`
49
- `):void 0}function ar(e){const n=de(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 Qi(e,n){const r=[...Ue(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 de(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function Vi(e){const r=(Array.isArray(e==null?void 0:e.columns)?e.columns:[]).map(Gi).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 Ue(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 Gi(e){if(typeof e=="string"&&e.trim())return e.trim();if(e&&typeof e=="object"){const n=e;return ie(n.name)??ie(n.field)??ie(n.key)}}function Ki(e,n){const r=e.filter(s=>/\b(category|product|customer|account|user|segment|region|channel|type|name)\b/i.test(s.replace(/_/g," "))).slice(0,12),i={};for(const s of r){const o=[];for(const a of n){const u=de(a),c=u==null?void 0:u[s],j=typeof c=="string"||typeof c=="number"?String(c).trim():"";if(!(!j||o.includes(j))&&(o.push(j),o.length>=24))break}o.length>0&&(i[Ui(s)]=o)}return Object.keys(i).length>0?i:void 0}function Ui(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 ie(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function en(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 Yi(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 cr(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:Mn(n.rows.map(u=>u[a]))}]:[]})}if(e.kind!=="semantic_block"||e.persistence!=="transient")return[];const r=new Map(n.columns.map(s=>[s.toLowerCase(),s])),i=new Set((e.parameters??[]).flatMap(s=>{var o;return((o=s.binding)==null?void 0:o.kind)==="semantic_filter"?[s.binding.field.toLowerCase()]:[]}));return(e.dimensions??[]).flatMap(s=>{if(i.has(s.toLowerCase()))return[];const o=s.split(".").at(-1)??s,a=r.get(s.toLowerCase())??r.get(o.toLowerCase())??r.get(s.split(".").join("_").toLowerCase());if(!a)return[];const u=Mn(n.rows.map(c=>c[a]));return[{column:a,field:s,values:u}]})}function Ji(e,n,r,i){const s=cr(e,n).find(x=>x.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(x=>x.name)),a=Xi(s.field.split(".").at(-1)??s.column);let u=a,c=2;for(;o.has(u);)u=`${a}_${c++}`;const j=Array.isArray(i)?i.map(String).join(", "):String(i),g=Gr(j,u);let l=Kr(e.source,{name:u,type:g,required:!1,defaultText:j,policy:"dynamic"});l=Ur(l,u,s.field);const d=Yr(l).map(x=>{var z,I,Q;return{...x,...((z=x.binding)==null?void 0:z.kind)==="semantic_filter"&&x.binding.field?{binding:{kind:"semantic_filter",field:x.binding.field,operator:x.binding.operator??"equals"}}:((I=x.binding)==null?void 0:I.kind)==="limit"?{binding:{kind:"limit"}}:((Q=x.binding)==null?void 0:Q.kind)==="sql_value"?{binding:{kind:"sql_value"}}:{binding:void 0}}}),{executionReceipt:y,compiledSql:m,...v}=e;return{artifact:{...v,source:l,parameters:d,parameterValues:{...e.parameterValues??{},[u]:i}},parameterName:u}}function Mn(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 Xi(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 dr(e,n,r){return e.map(i=>i.kind==="run"&&i.run.id===n?{kind:"run",id:r.id,run:r}:i)}function ur(e){var r,i,s;const n=[];for(const o of e){if(o.kind==="user"){n.push({role:"user",text:o.text});continue}if(o.run.status==="blocked"||((r=o.run.artifacts)==null?void 0:r.some(u=>{const c=se(u);return!!(c.executionError||c.warehouseFailure||c.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 dn="dql.agent.active-runs.v1",pr={conversation:"Chat",certified_answer:"Certified answer",semantic_answer:"Governed semantic answer",generated_answer:"Generated answer",research:"Research plan",sql_cell:"SQL cell",dql_block_draft:"DQL block draft",app_build:"App plan",clarify:"Clarify",blocked:"Blocked"};function Zi({themeMode:e,title:n="AI Copilot",scopeHint:r="Auto routes to answer, research, SQL, block, or app",onClearScope:i,examplePrompts:s,emptyHint:o,notebookPath:a,selectedObject:u,workspaceContext:c,initialMode:j="auto",initialInput:g="",initialItems:l,onItemsChange:d,threadId:y,onThreadIdChange:m,audience:v="analyst",autoRun:x,onInsertSql:z,onInsertDql:I,onReplaceDql:Q,onArtifactReady:G,onOpenBlock:q,onOpenResearch:N,onOpenApp:O,onRunningChange:$,answerFirstCards:H=!1,insertDqlActionLabel:V,replaceDqlActionLabel:B,askLayout:b=!1}){const A=er[e],U=f.useRef(void 0),[F,X]=f.useState(g),[P,re]=f.useState(l??[]),[_,T]=f.useState([]),[le,Z]=f.useState(""),[K,oe]=f.useState(!1),[ue,S]=f.useState(null),[E,p]=f.useState(null),[L,ee]=f.useState(null),[ne,Ve]=f.useState(()=>es()),[be,Be]=f.useState([]),[ke,k]=f.useState(),ae=f.useCallback(h=>{Ve(h);try{window.localStorage.setItem(fr,h)}catch{}},[]),ve=f.useRef(null),yn=f.useRef(g),mn=f.useRef(null),Ge=f.useRef(null),he=f.useRef(null),Fe=f.useRef(null),pe=f.useRef(null),$e=f.useRef(0),pt=f.useRef(""),Ee=f.useRef(null),et=f.useCallback(()=>{pt.current="",Ee.current!==null&&(window.cancelAnimationFrame(Ee.current),Ee.current=null),Z("")},[]),Mr=f.useCallback(h=>{pt.current+=h,Ee.current===null&&(Ee.current=window.requestAnimationFrame(()=>{Ee.current=null;const w=pt.current;pt.current="",w&&Z(R=>R+w)}))},[]);f.useEffect(()=>()=>{Ee.current!==null&&window.cancelAnimationFrame(Ee.current)},[]);const je=c==null?void 0:c.executionTarget,bn=je&&typeof je=="object"&&!Array.isArray(je)&&je.target==="connection"&&typeof je.connectionName=="string"?String(je.connectionName):void 0,Lr=je&&typeof je=="object"&&!Array.isArray(je)&&je.target==="local";f.useEffect(()=>{let h=!1;return te.getConnections().then(w=>{if(h)return;const R=Object.keys(w.connections??{}).sort((M,D)=>M.localeCompare(D));Be(R),k(gr(R,w.default,bn))}).catch(()=>{h||(Be([]),k(void 0))}),()=>{h=!0}},[bn]);const vn=f.useCallback(h=>{k(h)},[]),[Me,ft]=f.useState(null),[Ae,Ke]=f.useState(null),[Wr,Ft]=f.useState(""),jn=f.useRef(null),gt=f.useRef(null);f.useEffect(()=>{!g||K||g!==yn.current&&(yn.current=g,X(g))},[g,K]);const Fr=f.useMemo(()=>ur(P),[P]),xt=f.useRef(d);xt.current=d;const Pe=f.useRef(G);Pe.current=G,f.useEffect(()=>{var h;(h=xt.current)==null||h.call(xt,P)},[P]);const fe=f.useRef(y),ht=f.useRef(m);ht.current=m;const Pt=f.useCallback((h,w)=>{var R;if(pe.current!==null&&(window.clearTimeout(pe.current),pe.current=null),Vt(h.id),he.current===h.id&&(he.current=null),Fe.current=null,S(null),T(h.events.slice(-8)),et(),re(M=>{if(M.some(Y=>Y.kind==="run"&&Y.run.id===h.id))return M.map(Y=>Y.kind==="run"&&Y.run.id===h.id?{...Y,id:h.id,run:h}:Y);const D=M.some(Y=>Y.kind==="user"&&Y.text===w.question);return[...M,...D?[]:[{kind:"user",id:`${h.id}-question`,text:w.question}],{kind:"run",id:h.id,run:h}]}),h.route!=="certified_answer"){const M=Rt(h);M&&((R=Pe.current)==null||R.call(Pe,M,h))}},[et]),Sn=f.useCallback((h,w)=>{var M;re(D=>dr(D,h,w)),ft(D=>{if(!D||D.runId!==h)return D;const Y=w.artifacts[0];return Y?{runId:w.id,artifactId:Y.id,tab:D.tab}:null}),ee(null);const R=Rt(w);R&&((M=Pe.current)==null||M.call(Pe,R,w))},[]),tt=f.useCallback(h=>{pe.current!==null&&window.clearTimeout(pe.current);const w=++$e.current;he.current=h.id,Fe.current=h,S(h),oe(!0),et(),T([]);const R=async()=>{if(!(w!==$e.current||he.current!==h.id))try{const M=await te.getAgentRunState(h.id);if(w!==$e.current||he.current!==h.id)return;if(M.lifecycleState==="terminal"){Pt(M.run,h),oe(!1);return}T(M.progress.events.slice(-8)),pe.current=window.setTimeout(()=>{R()},600)}catch{if(w!==$e.current||he.current!==h.id)return;pe.current=window.setTimeout(()=>{R()},1200)}};return R(),()=>{w===$e.current&&($e.current+=1),pe.current!==null&&(window.clearTimeout(pe.current),pe.current=null)}},[Pt]),wn=f.useRef(!1);f.useEffect(()=>{if(!y||wn.current)return;wn.current=!0,fe.current??(fe.current=y);let h=!1;return te.getAgentThread(y).then(({turns:w,runs:R})=>{h||w.length===0||re(M=>{const D=M.filter(ce=>ce.kind==="run").length,Y=xr(w,R);if(w.length>=D)return Y;const Ce=new Map(Y.flatMap(ce=>ce.kind==="run"?[[ce.run.id,ce.run]]:[]));return M.map(ce=>ce.kind==="run"&&Ce.has(ce.run.id)?{...ce,run:Ce.get(ce.run.id)}:ce)})}).catch(()=>{!h&&fe.current===y&&(fe.current=void 0)}),()=>{h=!0}},[y]),f.useEffect(()=>{const h=Pn(y??fe.current);if(!(!h||Ge.current))return tt(h)},[tt,y]),f.useEffect(()=>{const h=()=>{if(document.visibilityState!=="visible"||Ge.current)return;const w=Fe.current??Pn(y??fe.current);w&&tt(w)};return document.addEventListener("visibilitychange",h),()=>document.removeEventListener("visibilitychange",h)},[tt,y]);const qe=async(h,w,R,M,D)=>{var An;const Y=(h??F).trim();if(!Y||K)return;const Ce=w??U.current??j;U.current=void 0;const ce={kind:"user",id:Vn("user"),text:Y};re(Ne=>[...Ne,ce]),X(""),ee(null),oe(!0),T([]),et();const De=new AbortController;Ge.current=De;const Se=Vn("run");let xe={id:Se,question:Y,threadId:fe.current,startedAt:new Date().toISOString()};he.current=Se,Fe.current=xe,S(xe),Fn(xe);let jt=!1,ye=!1;try{if(!fe.current)try{const ze=await te.createAgentThread({surface:b?"ask":typeof(c==null?void 0:c.surface)=="string"?c.surface:a?"notebook":"agent",title:Y,...a?{notebookPath:a}:{}});fe.current=ze.id,(An=ht.current)==null||An.call(ht,ze.id),xe={...xe,threadId:ze.id},Fe.current=xe,S(xe),Fn(xe)}catch{}const Ne={question:Y,...R?{selectedEvidenceId:R}:{},...M?{clarificationSourceQuestion:M}:{},requestedMode:Ce,audience:v,selectedObject:u??(a?{kind:"notebook",path:a}:void 0),...D!=null&&D.executionTarget?{executionTarget:D.executionTarget}:Lr?{executionTarget:{target:"local"}}:ke?{executionTarget:{target:"connection",connectionName:ke}}:{},workspaceContext:{...c??{},...a?{notebookPath:a}:{},...D?{researchSource:kr(D)}:{}},conversationContext:Li(P),history:Fr,thinkingMode:ne,runId:Se,...fe.current?{threadId:fe.current}:{}},Nr=await te.createAgentRunStream(Ne,ze=>{jt=!0,ze.kind==="event"?T(Or=>[...Or,ze.event].slice(-8)):ze.kind==="answer-delta"?Mr(ze.delta):T(ze.run.events.slice(-8))},De.signal);Pt(Nr,xe)}catch(Ne){De.signal.aborted||(ee(Ne instanceof Error?Ne.message:String(Ne)),X(Y),jt?(ye=!0,tt(xe)):(Vt(Se),he.current===Se&&(he.current=null),Fe.current=null,S(null)))}finally{Ge.current===De&&(Ge.current=null),ye||oe(!1)}},yt=()=>{qe()},kn=()=>{var w;const h=he.current;h&&te.cancelAgentRun(h).catch(()=>{}),(w=Ge.current)==null||w.abort(),$e.current+=1,pe.current!==null&&window.clearTimeout(pe.current),Vt(h??""),he.current=null,Fe.current=null,S(null),et(),T([]),oe(!1),ee("Stopped. No answer or draft was saved.")},mt=f.useRef($);mt.current=$,f.useEffect(()=>{var h;(h=mt.current)==null||h.call(mt,K)},[K]),f.useEffect(()=>{!(x!=null&&x.text)||K||mn.current!==x.nonce&&(mn.current=x.nonce,qe(x.text,x.mode??j))},[x==null?void 0:x.nonce,x==null?void 0:x.text,x==null?void 0:x.mode,j,K]),f.useEffect(()=>()=>{$e.current+=1,pe.current!==null&&window.clearTimeout(pe.current)},[]);const bt={appId:typeof(c==null?void 0:c.appId)=="string"?c.appId:void 0,dashboardId:typeof(c==null?void 0:c.dashboardId)=="string"?c.dashboardId:void 0,dashboardTitle:typeof(c==null?void 0:c.dashboardTitle)=="string"?c.dashboardTitle:void 0},vt=(h,w)=>{var R,M;if(w.id==="save-dql-block"){const D=we(h),Y=((R=D==null?void 0:D.source)==null?void 0:R.trim())??((M=Te(h))==null?void 0:M.trim());if(!Y){ee("This answer does not include a reusable DQL or SQL artifact yet.");return}p({runId:h.id,source:Y,name:(D==null?void 0:D.name)??`${h.question.slice(0,48).trim()||"saved_answer"}`,dqlArtifact:D});return}if(w.id==="research-deeper"){qe(h.question,"research",void 0,void 0,h);return}if(w.id.startsWith("suggest-question")){qe(w.label,"auto");return}U.current=ws(w.route),X(ks(h,w.route)),requestAnimationFrame(()=>{var D;return(D=ve.current)==null?void 0:D.focus()})},Pr=f.useCallback((h,w,R="trust")=>{ft({runId:h,artifactId:w,tab:R})},[]),Dr=f.useCallback(h=>{var M,D;const w=h.trim();if(!w)return;const R=(M=Ae==null?void 0:Ae.text)==null?void 0:M.trim();Ke(null),Ft("");try{(D=window.getSelection())==null||D.removeAllRanges()}catch{}qe(R?`${w}
50
-
51
- Regarding: "${R}"`:w),requestAnimationFrame(()=>{gt.current&&(gt.current.scrollTop=gt.current.scrollHeight)})},[Ae,qe]);if(f.useEffect(()=>{if(!b)return;const h=R=>{const M=R.target;M&&M.closest("[data-selpop]")||window.setTimeout(()=>{const D=window.getSelection(),Y=D&&D.rangeCount?D.toString().trim():"";if(!Y||Y.length<3){Ke(ye=>ye&&null);return}const Ce=D.anchorNode,ce=Ce&&(Ce.nodeType===1?Ce:Ce.parentElement),De=ce==null?void 0:ce.closest("[data-followup]");if(!De){Ke(ye=>ye&&null);return}const Se=D.getRangeAt(0).getBoundingClientRect(),xe=Math.max(12,Math.min(Se.left,window.innerWidth-340)),jt=Se.bottom+176>window.innerHeight?Math.max(12,Se.top-176):Se.bottom+8;Ke({text:Y.slice(0,220),source:De.getAttribute("data-followup")||"answer",left:xe,top:jt}),Ft(""),requestAnimationFrame(()=>{var ye;return(ye=jn.current)==null?void 0:ye.focus()})},0)},w=R=>{R.key==="Escape"&&Ke(null)};return document.addEventListener("mouseup",h),document.addEventListener("keydown",w),()=>{document.removeEventListener("mouseup",h),document.removeEventListener("keydown",w)}},[b]),b){const h=Me?(()=>{const w=P.find(M=>M.kind==="run"&&M.run.id===Me.runId);if(!w||w.kind!=="run")return null;const R=w.run.artifacts.find(M=>M.id===Me.artifactId);return R?{run:w.run,artifact:R}:null})():null;return t.jsxs("div",{style:{display:"flex",height:"100%",minHeight:0,flex:1,minWidth:0,width:"100%",background:"var(--bg-canvas)"},children:[E?t.jsx(Tn,{cell:{id:`agent-${E.runId}`,type:E.dqlArtifact?"dql":"sql",content:E.source,name:E.name,status:"success",...E.dqlArtifact?{dqlArtifact:E.dqlArtifact}:{}},initialContent:E.source,initialName:E.name,onClose:()=>p(null),onSaved:()=>p(null)}):null,t.jsx("style",{children:cs}),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(Qe,{size:13})}),t.jsx("span",{style:{fontSize:13.5,fontWeight:650,color:A.textPrimary,whiteSpace:"nowrap"},children:n==="AI Copilot"?"Ask your data":n}),t.jsx("div",{style:{flex:1}}),t.jsx("span",{style:{fontSize:11,color:A.textMuted,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:"Certified first · semantic next · generated SQL last"})]}),t.jsxs("div",{ref:gt,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:[P.length===0&&!K?t.jsxs("div",{style:{margin:"auto 0",display:"grid",gap:14,justifyItems:"center",textAlign:"center",color:A.textSecondary,paddingTop:40},children:[t.jsx("div",{style:Gn(A),children:t.jsx(Qe,{size:20})}),t.jsx("div",{style:{fontSize:13.5,lineHeight:1.5,maxWidth:400,color:A.textSecondary},children:o??Ln}),t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap",justifyContent:"center",maxWidth:520},children:(s??Wn).map(w=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>{X(w.prompt),requestAnimationFrame(()=>{var R;return(R=ve.current)==null?void 0:R.focus()})},style:It(A),children:w.label},w.label))})]}):null,P.map(w=>w.kind==="user"?t.jsx("div",{style:ds(A),children:w.text},w.id):t.jsx(Qn,{run:w.run,t:A,themeMode:e,threadId:fe.current,appContext:bt,selectedArtifactId:(Me==null?void 0:Me.runId)===w.run.id?Me.artifactId:void 0,onOpenArtifact:(R,M)=>Pr(w.run.id,R,M),onOpenApp:O,onInsertSql:z,onInsertDql:I,onOpenBlock:q,onOpenResearch:N,onSelectClarification:R=>{const M=wt(R);qe(M.question,void 0,M.selectedEvidenceId,w.run.question)},onNextAction:R=>vt(w.run,R),onRepairedRun:Sn},w.id)),K&&t.jsx(Nn,{events:_,t:A,streamingAnswer:le,thinkingMode:ne,backgroundRun:ue})]}),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:[L?t.jsx("div",{style:{color:A.error,fontSize:12,marginBottom:8},children:L}):null,i?t.jsxs("div",{style:{width:"fit-content",maxWidth:"100%",marginBottom:7,padding:"4px 7px 4px 9px",border:"1px solid var(--border-default)",borderRadius:999,background:"var(--bg-2)",color:A.textMuted,fontSize:10.5,display:"flex",alignItems:"center",gap:5},children:[t.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r}),t.jsx("button",{type:"button",onClick:i,"aria-label":"Clear modeling scope",title:"Clear modeling scope",style:{border:0,background:"transparent",color:A.textMuted,cursor:"pointer",display:"grid",placeItems:"center",padding:1},children:t.jsx(At,{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:ve,value:F,onChange:w=>{X(w.target.value),U.current=void 0},rows:2,placeholder:"Ask anything about your data…",onKeyDown:w=>{w.key==="Enter"&&!w.shiftKey&&(w.preventDefault(),yt())},style:{border:"none",background:"transparent",resize:"none",outline:"none",boxShadow:"none",padding:"13px 15px 4px",fontSize:13.5,lineHeight:1.5,color:A.textPrimary,fontFamily:A.font}}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 10px 10px 12px"},children:[t.jsx(Cn,{t:A,value:ne,onChange:ae}),t.jsx(Dn,{names:be,value:ke,onChange:vn,t:A}),t.jsx("div",{style:{flex:1}}),K?t.jsxs("button",{type:"button",className:"dql-hover",onClick:kn,title:"Stop the active agent run",style:{height:34,padding:"0 12px",borderRadius:10,border:`1px solid ${A.error}`,background:A.btnBg,color:A.error,display:"inline-flex",alignItems:"center",gap:6,cursor:"pointer",fontFamily:A.font,fontSize:12.5,fontWeight:600},children:[t.jsx(qn,{size:13,fill:"currentColor"})," Stop"]}):null,t.jsx("button",{type:"button",className:"dql-hover dql-lift",title:"Ask",onClick:yt,disabled:!F.trim()||K,style:{width:34,height:34,borderRadius:10,border:"none",background:F.trim()&&!K?"var(--accent)":"var(--bg-4)",color:"#fff",display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:F.trim()&&!K?"pointer":"default",boxShadow:F.trim()&&!K?"0 1px 5px rgba(107,93,211,0.3)":"none"},children:K?t.jsx(He,{size:15,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(tr,{size:15})})]})]}),t.jsx("div",{style:{textAlign:"center",fontSize:10.5,color:A.textMuted,marginTop:8},children:"Every answer is grounded in your certified metrics and dbt lineage."})]})]})]}),h?t.jsx(xs,{run:h.run,artifact:h.artifact,tab:Me.tab,t:A,appContext:bt,onOpenApp:O,onChangeTab:w=>ft(R=>R&&{...R,tab:w}),onClose:()=>ft(null),onSaveBlock:()=>vt(h.run,{id:"save-dql-block",label:"Save as block",route:"dql_block_draft"}),onInsertSql:z,onInsertDql:I}):null,Ae?t.jsx(hs,{t:A,text:Ae.text,source:Ae.source,left:Ae.left,top:Ae.top,draft:Wr,inputRef:jn,onDraftChange:Ft,onClose:()=>Ke(null),onSend:Dr}):null]})}return t.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0,flex:1,minWidth:0,width:"100%",background:A.cellBg},children:[E?t.jsx(Tn,{cell:{id:`agent-${E.runId}`,type:E.dqlArtifact?"dql":"sql",content:E.source,name:E.name,status:"success",...E.dqlArtifact?{dqlArtifact:E.dqlArtifact}:{}},initialContent:E.source,initialName:E.name,onClose:()=>p(null),onSaved:()=>p(null)}):null,t.jsx("style",{children:`
52
- @keyframes dql-agent-run-spin { to { transform: rotate(360deg); } }
53
- @keyframes dql-agent-fadein { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
54
- @keyframes dql-agent-thinking-dot { 0%, 65%, 100% { opacity: .28; transform: translateY(0); } 32% { opacity: 1; transform: translateY(-2px); } }
55
- @keyframes dql-agent-activity-in { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
56
- .dql-agent-thinking-dot { animation: dql-agent-thinking-dot 1.05s ease-in-out infinite; }
57
- .dql-agent-activity { animation: dql-agent-activity-in .22s ease-out; }
58
- .dql-hover { transition: filter .15s ease, transform .12s ease, box-shadow .15s ease, background .15s ease, color .15s ease, border-color .15s ease; }
59
- .dql-hover:hover { filter: brightness(1.07); }
60
- .dql-hover:active { transform: translateY(0.5px); }
61
- .dql-lift:hover { transform: translateY(-1px); }
62
- details > summary::-webkit-details-marker { display: none; }
63
- @media (prefers-reduced-motion: reduce) { .dql-agent-thinking-dot, .dql-agent-activity { animation: none !important; } }
64
- `}),t.jsxs("div",{style:{flex:1,minHeight:0,overflow:"auto",padding:"14px 16px",display:"flex",flexDirection:"column",gap:12},children:[P.length===0&&!K?t.jsxs("div",{style:{margin:"auto 0",display:"grid",gap:14,justifyItems:"center",textAlign:"center",color:A.textSecondary},children:[t.jsx("div",{style:Gn(A),children:t.jsx(Qe,{size:20})}),t.jsx("div",{style:{fontSize:13,lineHeight:1.5,maxWidth:380,color:A.textSecondary},children:o??Ln}),t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap",justifyContent:"center",maxWidth:520},children:(s??Wn).map(h=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>{X(h.prompt),requestAnimationFrame(()=>{var w;return(w=ve.current)==null?void 0:w.focus()})},style:It(A),children:h.label},h.label))})]}):null,P.map(h=>h.kind==="user"?t.jsx("div",{style:Ms(A),children:h.text},h.id):H?t.jsx(Qn,{run:h.run,t:A,themeMode:e,threadId:fe.current,appContext:bt,onOpenApp:O,onInsertSql:z,onInsertDql:I,onReplaceDql:Q,insertDqlActionLabel:V,replaceDqlActionLabel:B,onOpenBlock:q,onOpenResearch:N,onSelectClarification:w=>{const R=wt(w);qe(R.question,void 0,R.selectedEvidenceId,h.run.question)},onNextAction:w=>vt(h.run,w),onRepairedRun:Sn},h.id):t.jsx(as,{run:h.run,t:A,themeMode:e,appContext:bt,onOpenApp:O,onInsertSql:z,onInsertDql:I,onOpenBlock:q,onOpenResearch:N,onSelectClarification:w=>{const R=wt(w);qe(R.question,void 0,R.selectedEvidenceId,h.run.question)},onNextAction:w=>vt(h.run,w)},h.id)),K&&t.jsx(Nn,{events:_,t:A,streamingAnswer:le,thinkingMode:ne,backgroundRun:ue})]}),L?t.jsx("div",{style:{margin:"0 16px 8px",color:A.error,fontSize:12},children:L}):null,t.jsxs("div",{style:{padding:"10px 16px 14px",borderTop:`1px solid ${A.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:A.textMuted,flex:1,minWidth:180,display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{children:r}),i?t.jsx("button",{type:"button",onClick:i,"aria-label":"Clear modeling scope",title:"Clear modeling scope",style:{border:0,background:"transparent",color:A.textMuted,cursor:"pointer",display:"grid",placeItems:"center",padding:2},children:t.jsx(At,{size:12})}):null]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(Dn,{names:be,value:ke,onChange:vn,t:A}),t.jsx(Cn,{t:A,value:ne,onChange:ae})]})]}),t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-end"},children:[t.jsx("textarea",{ref:ve,value:F,onChange:h=>{X(h.target.value),U.current=void 0},rows:2,placeholder:"Ask anything about your data…",onKeyDown:h=>{h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),yt())},style:Ts(A)}),t.jsxs("button",{type:"button",className:"dql-hover dql-lift",onClick:yt,disabled:!F.trim()||K,style:Kn(A,!!F.trim()&&!K),children:[K?t.jsx(He,{size:15,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(ei,{size:15}),t.jsx("span",{children:K?"Working":"Ask"})]}),K?t.jsxs("button",{type:"button",className:"dql-hover",onClick:kn,style:{...Kn(A,!0),background:A.btnBg,borderColor:A.error,color:A.error},title:"Stop the active agent run",children:[t.jsx(qn,{size:13,fill:"currentColor"}),t.jsx("span",{children:"Stop"})]}):null]})]})]})}const Ln="Ask a question — every answer is grounded in your certified metrics and dbt lineage. Use Research deeper on any answer for a slower investigation.",Wn=[{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 un(){try{const e=JSON.parse(window.localStorage.getItem(dn)??"[]");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 Fn(e){try{const n=un().filter(r=>r.id!==e.id);window.localStorage.setItem(dn,JSON.stringify([...n,e].slice(-12)))}catch{}}function Vt(e){try{const n=un().filter(r=>r.id!==e);window.localStorage.setItem(dn,JSON.stringify(n))}catch{}}function Pn(e){const n=un().sort((r,i)=>i.startedAt.localeCompare(r.startedAt));return e?n.find(r=>r.threadId===e):n.find(r=>!r.threadId)}const fr="dql.agent.thinkingMode";function gr(e,n,r){return r&&e.includes(r)?r:n&&e.includes(n)?n:e[0]}function Dn({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(Jr,{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 es(){try{const e=window.localStorage.getItem(fr);return e==="low"||e==="medium"||e==="high"||e==="auto"?e:"auto"}catch{return"auto"}}const ts=new Set(["conversation","certified_answer","semantic_answer","generated_answer","research","sql_cell","dql_block_draft","app_build","clarify","blocked"]),ns=new Set(["certified","governed","grounded","review_required","blocked","not_applicable"]),rs=new Set(["completed","needs_review","needs_clarification","blocked"]),is=new Set(["conversational_reply","certified_answer_found","governed_semantic_answer","generated_review_required","artifact_created","needs_clarification","human_review_required","blocked"]);function xr(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??ss(o)}]})}function ss(e){var j,g,l;const n=ts.has(e.route)?e.route:"generated_answer",r=ns.has(e.trustLabel)?e.trustLabel:e.certification==="certified"?"certified":"not_applicable",i=rs.has(e.runStatus)?e.runStatus:"completed",s=is.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=(((j=e.result)==null?void 0:j.columns)??[]).filter(d=>typeof d=="string"),a=(((g=e.result)==null?void 0:g.rowsSample)??[]).filter(d=>Array.isArray(d)).map(d=>Object.fromEntries(o.map((y,m)=>[y,d[m]]))),u=o.length>0?{columns:o,rows:a,rowCount:((l=e.result)==null?void 0:l.rowCount)??a.length}:void 0,c=u||e.sql||e.dqlArtifact||e.sourceCertifiedBlock?{id:`${e.id}-artifact`,kind:"answer",title:e.sourceCertifiedBlock??e.question,trustState:r,ref:e.sourceCertifiedBlock,payload:{...e.sourceCertifiedBlock?{sourceCertifiedBlock:e.sourceCertifiedBlock}:{},...e.certification?{certification:e.certification}:{},...e.contextPackId?{contextPackId:e.contextPackId}:{},...e.sql?{sql:e.sql}:{},...e.dqlArtifact?{dqlArtifact:e.dqlArtifact}:{},...e.cascade?{cascade:e.cascade}:{},...u?{result:u}:{},...e.contract&&Object.keys(e.contract).length>0?{contextPack:{questionPlan:{requestedShape:e.contract}}}:{}}}:void 0;return{id:e.id,question:e.question,requestedMode:"auto",route:n,status:i,trustState:r,stopReason:s,startedAt:e.createdAt,completedAt:e.createdAt,summary:e.answerSummary??e.question,answer:e.answerText??e.answerSummary,answerKind:n==="conversation"?"conversational":void 0,steps:[],artifacts:c?[c]:[],evaluations:[],events:[],nextActions:[],repairAttempts:0}}function os(e){switch(e){case"certified_answer":return"Found a compatible certified block";case"semantic_answer":return"Found a compatible semantic metric";case"generated_answer":return"Identified the relevant tables and columns";case"research":return"Identified evidence for deeper analysis";case"app_build":return"Found governed assets for the app";case"sql_cell":return"Identified the query context";case"dql_block_draft":return"Identified reusable governed logic";case"clarify":return"Identified a missing business detail";default:return"Identified the best answer path"}}function ls(e,n){if(n.some(r=>r.type==="repair.attempted"))return"Refining the query and trying again";if(n.some(r=>r.type==="escalated"))return"Expanding the evidence search";switch(e){case"certified_answer":case"semantic_answer":return"Running the governed query";case"generated_answer":return"Building and running a grounded query";case"research":return"Researching the strongest evidence";case"app_build":return"Assembling the app from governed assets";case"sql_cell":return"Building and checking the SQL";case"dql_block_draft":return"Drafting the governed logic";case"clarify":return"Preparing a focused clarification";default:return"Preparing the answer"}}function tn(e){for(let n=e.length-1;n>=0;n-=1)if(e[n].route)return e[n].route}function hr(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 yr(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 mr(e,n=!1){if(e.length===0&&n)return[{id:"background",label:"Continuing this request in the background",state:"active"}];const r=tn(e);if(r==="conversation")return[];const i=e.some(u=>u.type==="route.decided"),s=e.some(u=>u.type==="executor.started"||u.type==="step.started"||u.type==="repair.attempted"||u.type==="escalated"),o=e.some(u=>u.type==="evaluation.recorded"),a=[{id:"search",label:"Resolving governed evidence and business meaning",state:i?"complete":"active"}];return i&&a.push({id:"match",label:os(r),state:s||o?"complete":"active"}),(s||o)&&a.push({id:"execute",label:ls(r,e),state:o?"complete":"active"}),o&&a.push({id:"verify",label:"Checking the result against governed evidence",state:"active"}),a}function Nn({events:e,t:n,streamingAnswer:r,thinkingMode:i,backgroundRun:s}){var m;const[o,a]=f.useState(()=>Date.now());f.useEffect(()=>{const v=window.setInterval(()=>a(Date.now()),1e3);return()=>window.clearInterval(v)},[]);const u=(s==null?void 0:s.startedAt)??((m=e.find(v=>v.type==="run.started"))==null?void 0:m.at),c=u?Date.parse(u):o,j=Number.isFinite(c)?Math.max(0,Math.floor((o-c)/1e3)):0,g=hr(j,tn(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(tn(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(On,{}),t.jsx("span",{style:{fontSize:13,lineHeight:1.4},children:"Replying…"})]});const d=mr(e,!!s),y=j>=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:[d.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(On,{}):t.jsx(it,{size:13,strokeWidth:2.2})}),t.jsxs("span",{style:{fontSize:12.5,lineHeight:1.4,fontWeight:v.state==="active"?620:450},children:[v.label,v.state==="active"?"…":""]})]},v.id)),y?t.jsx("span",{style:{paddingLeft:25,fontSize:10.5,lineHeight:1.4,color:n.textMuted},children:y}):null]})}function On(){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 Hn({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((u,c)=>r(u,c)),e.length>i?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>o(u=>!u),style:{alignSelf:"flex-start",background:"none",border:"none",cursor:"pointer",color:n.accent,fontSize:11,padding:"2px 0",display:"inline-flex",alignItems:"center",gap:4},children:[s?t.jsx(rr,{size:11}):t.jsx(Tt,{size:11}),s?"Show less":`Show all (${e.length})`]}):null]})}function as({run:e,t:n,themeMode:r,appContext:i,onOpenApp:s,onInsertSql:o,onInsertDql:a,onOpenBlock:u,onOpenResearch:c,onSelectClarification:j,onNextAction:g}){var B;const{dispatch:l}=Bt();if(e.route==="conversation"){const b=e.answerKind==="general_knowledge";return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,animation:"dql-agent-fadein 0.3s ease-out"},children:[t.jsxs("div",{style:Ls(n),children:[b?t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:10.5,color:n.textMuted,marginBottom:6,fontWeight:650},children:[t.jsx(qt,{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(kt,{text:Ye(e.answer),t:n}):e.summary})]}),e.nextActions.length>0?t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:e.nextActions.map(A=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>g(A),style:It(n),children:A.label},A.id))}):null]})}const d=e.steps??[],y=d.length>1,m=((B=e.plan)==null?void 0:B.source)==="llm",v=hn(e),x=gn(e),z=dt(e),I=e.route==="certified_answer"||e.route==="generated_answer",Q=e.nextActions.some(b=>b.route==="research"),G=I&&z&&!Q,q=we(e),N=z&&!(q!=null&&q.sourcePath)&&!!((q==null?void 0:q.source)??Te(e)),O=Date.parse(e.startedAt),$=Date.parse(e.completedAt),H=Number.isFinite(O)&&Number.isFinite($)?Math.max(0,Math.round(($-O)/1e3)):0,V=yr(H,e.route,e.trustState,e.repairAttempts);return t.jsxs("div",{style:Ws(n),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(vs,{run:e}),t.jsx("div",{style:{minWidth:0,flex:1},children:t.jsx("div",{style:{fontSize:12.5,fontWeight:850,color:n.textPrimary},children:ys(e)})}),t.jsx(js,{run:e,t:n})]}),x?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(ge,{size:12,color:n.success,style:{flex:"0 0 auto",marginTop:1}}):e.trustState==="governed"||e.trustState==="grounded"?t.jsx(ge,{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:x})]}):null,m||y||e.repairAttempts>0?t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[m?t.jsx(Yt,{t:n,icon:t.jsx(lt,{size:11}),label:"AI plan",tone:"accent"}):null,y?t.jsx(Yt,{t:n,icon:t.jsx(Xt,{size:11}),label:`${d.length} steps`,tone:"muted"}):null,e.repairAttempts>0?t.jsx(Yt,{t:n,icon:t.jsx(Et,{size:11}),label:`${e.repairAttempts} repair${e.repairAttempts>1?"s":""}`,tone:"warning"}):null]}):null,e.summary&&!(e.answer&&As(Ie(e.summary),Ye(e.answer)))?t.jsx("div",{style:{fontSize:12.5,lineHeight:1.45,color:n.textSecondary},children:Ie(e.summary)}):null,e.answer?t.jsx("div",{style:Fs(n),children:t.jsx(kt,{text:Ye(e.answer),t:n})}):null,t.jsx(jr,{run:e,t:n,onSelect:j}),v.length>0?t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[t.jsx("span",{style:{fontSize:11,color:n.textMuted},children:"Evidence:"}),v.map(b=>t.jsxs("span",{style:Br(n,b.certified),children:[b.certified?t.jsx(ge,{size:11}):t.jsx(ot,{size:11}),t.jsx("span",{children:b.label})]},b.label))]}):null,t.jsx(Tr,{run:e,t:n}),e.artifacts.length>0?t.jsx("div",{style:{display:"grid",gap:8,gridTemplateColumns:"minmax(0, 1fr)",minWidth:0},children:e.artifacts.map(b=>t.jsx(Cr,{artifact:b,t:n,themeMode:r,onInsertSql:o,onInsertDql:a,sourceRunId:e.id,sourceQuestion:e.question,onOpenBlock:u,onOpenResearch:c,onOpenApp:s,onNextAction:g},b.id))}):null,y?t.jsx(Rr,{steps:d,t:n}):t.jsx(zr,{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(lt,{size:12})," View steps · where the time went"]}):null,V?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(qt,{size:11,color:n.accent})," ",V.title]}),t.jsx("span",{style:{fontSize:10.5,color:n.textMuted,lineHeight:1.45},children:V.detail})]}):null,z||G||e.nextActions.length>0?t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[z?t.jsx(fn,{run:e,t:n,appContext:i,onOpenApp:s}):null,N?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>g({id:"save-dql-block",label:"Save as block",route:"dql_block_draft"}),style:J(n),children:[t.jsx(cn,{size:11})," Save as block"]}):null,G?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>g({id:"research-deeper",label:"Research this deeper",route:"research"}),style:J(n),title:"Run a slower, multi-step investigation on this question",children:[t.jsx(ot,{size:11}),"Research this deeper"]}):null,e.nextActions.filter(b=>b.id!=="pin-to-app"&&b.id!=="research-deeper"&&b.id!=="confirm-app-build"&&b.id!=="request-certification").map(b=>t.jsx("button",{type:"button",className:"dql-hover",onClick:()=>g(b),style:J(n),children:b.label},b.id))]}):null]})}function br(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 cs=`
65
- @keyframes dql-agent-run-spin { to { transform: rotate(360deg); } }
66
- @keyframes dql-agent-fadein { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
67
- @keyframes dql-agent-thinking-dot { 0%, 65%, 100% { opacity: .28; transform: translateY(0); } 32% { opacity: 1; transform: translateY(-2px); } }
68
- @keyframes dql-agent-activity-in { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
69
- .dql-agent-thinking-dot { animation: dql-agent-thinking-dot 1.05s ease-in-out infinite; }
70
- .dql-agent-activity { animation: dql-agent-activity-in .22s ease-out; }
71
- .dql-hover { transition: filter .15s ease, transform .12s ease, box-shadow .15s ease, background .15s ease, color .15s ease, border-color .15s ease; }
72
- .dql-hover:hover { filter: brightness(1.03); }
73
- .dql-hover:active { transform: translateY(0.5px); }
74
- .dql-lift:hover { transform: translateY(-1px); }
75
- .dql-ask-ghost:hover { background: var(--bg-0); color: var(--text-primary) !important; }
76
- .dql-ask-chip:hover { border-color: var(--accent) !important; box-shadow: 0 1px 6px rgba(107,93,211,0.12); }
77
- details > summary::-webkit-details-marker { display: none; }
78
- @media (prefers-reduced-motion: reduce) { .dql-agent-thinking-dot, .dql-agent-activity { animation: none !important; } }
79
- `;function ds(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 Le(e){return $t(e,{variant:"ghost",size:"sm"})}function Gt(e,n){return e.kind==="app_proposal"||e.kind==="dql_block_draft"||e.kind==="research_run"||!!Wt(n)}function Mt(e,n){var a,u;const r=[],i=We(n),s=e.kind==="answer"?(a=i==null?void 0:i.rows)!=null&&a.length?"Table":"Answer":e.kind==="sql_cell"?"SQL":e.kind==="dql_block_draft"?"DQL block":e.kind==="research_run"?"Research":"Result";r.push(s);const o=(i==null?void 0:i.rowCount)??((u=i==null?void 0:i.rows)==null?void 0:u.length);return typeof o=="number"&&r.push(`${o} row${o===1?"":"s"}`),typeof(i==null?void 0:i.executionTime)=="number"&&r.push(i.executionTime>=1e3?`${(i.executionTime/1e3).toFixed(1)}s`:`${i.executionTime.toFixed(i.executionTime<10?1:0)}ms`),r.push(e.trustState==="certified"?"certified block":e.trustState==="governed"||e.trustState==="grounded"?"governed":"AI-generated"),r.join(" · ")}function rt(e,n){const i=/^(?:certified|governed semantic|review-required|exploratory dbt-grounded) answer$/i.test(n.title.trim())?e.question:n.title,s=Ie(i).replace(/[?.!]+$/,"").trim();if(!s)return"Answer result";const o=s.charAt(0).toUpperCase()+s.slice(1);return o.length>88?`${o.slice(0,85).trimEnd()}…`:o}function W(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function vr(e){const n=[],r=new Set,i=(s,o)=>{const a=W(s);if(!a)return;const u=[a.name,a.label,a.relation,a.objectName].find(l=>typeof l=="string"&&l.trim().length>0);if(!u)return;const c=typeof a.kind=="string"?a.kind:o,j=`${c??""}:${u}`;if(r.has(j))return;r.add(j);const g=[a.description,a.provenance,a.sourceTier,a.source].find(l=>typeof l=="string"&&l.trim().length>0);n.push({name:u,kind:c,detail:g})};for(const s of e.artifacts){const o=se(s),a=W(o.evidence);for(const j of["lineage","sourceTables","semanticObjects","selectedAssets"]){const g=a==null?void 0:a[j];Array.isArray(g)&&g.forEach(l=>i(l,j==="sourceTables"?"source":void 0))}const u=W(o.analysisPlan)??W(a==null?void 0:a.analysisPlan),c=u==null?void 0:u.candidateTables;Array.isArray(c)&&c.forEach(j=>i(j,"relation"))}return n.slice(0,24)}function pn(e,n){var i;const r=se(n);return Lt(r)?"how":(i=we(e)??ut(r))!=null&&i.source?"dql":Te(e)??(typeof r.sql=="string"?r.sql:void 0)?"sql":vr(e).length>0?"lineage":"trust"}function us({run:e,artifact:n,selected:r,t:i,themeMode:s,onInspect:o}){const a=se(n),u=We(a),[c,j]=f.useState(!1);if(f.useEffect(()=>{if(!c)return;const v=x=>{x.key==="Escape"&&j(!1)};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[c]),!u)return null;const g=Ir(a,u),l=pn(e,n),d=we(e)??ut(a),y=n.trustState==="certified"?qr(n,a):void 0,m=t.jsxs("section",{"data-followup":"table","aria-label":`${rt(e,n)} result`,style:{border:`1px solid ${r?"var(--accent)":"var(--border-default)"}`,borderRadius:12,background:"var(--bg-2)",overflow:"hidden",boxShadow:c?"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)",...c?{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:rt(e,n)}),t.jsx("div",{style:{fontSize:11,color:i.textMuted,marginTop:2},children:Mt(n,a)})]}),t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>o(l),style:Le(i),children:[t.jsx(lt,{size:12})," Inspect"]}),t.jsxs("button",{type:"button",className:"dql-ask-ghost","aria-label":c?"Return result to Copilot":"Expand result",title:c?"Return result to Copilot":"Expand this result for wide tables",onClick:()=>j(v=>!v),style:Le(i),children:[c?t.jsx(li,{size:12}):t.jsx(ai,{size:12}),c?"Restore":"Expand result"]})]}),d?t.jsx(Ar,{artifact:d,certifiedBlockName:y,initialResult:u,initialChartConfig:g,payload:a,executionTarget:e.executionTarget,t:i,themeMode:s,embedded:!0,expanded:c}):t.jsx(ln,{result:u,themeMode:s,t:i,chartConfig:g,embedded:!0,tabLabels:{table:"Results",chart:"Visualization"},contentMaxHeight:c?"calc(100vh - 172px)":void 0,tableMaxHeight:c?"calc(100vh - 250px)":void 0})]});return!c||typeof document>"u"?m: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."}),Xr.createPortal(t.jsx("div",{role:"dialog","aria-modal":"true","aria-label":`${rt(e,n)} expanded result`,onClick:()=>j(!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:m})}),document.body)]})}function Qn(e){const{run:n,t:r,themeMode:i,threadId:s,appContext:o,selectedArtifactId:a,onOpenArtifact:u,onOpenApp:c,onInsertSql:j,onInsertDql:g,onReplaceDql:l,insertDqlActionLabel:d,replaceDqlActionLabel:y,onOpenBlock:m,onOpenResearch:v,onSelectClarification:x,onNextAction:z,onRepairedRun:I}=e,{dispatch:Q}=Bt(),[G,q]=f.useState(!1),N=u??(()=>Q({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(qt,{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(kt,{text:Ye(n.answer),t:r}):n.summary}),n.nextActions.length>0?t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:n.nextActions.map(L=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>z(L),style:It(r),children:L.label},L.id))}):null]})}const O=n.trustState==="certified",$=n.status==="blocked",H=n.status==="needs_clarification",V=$||H?void 0:n.answer,B=$?"Couldn’t run this query":H?"Needs clarification":O?"Certified answer":"AI-generated answer",b=$?Er(n):void 0,A=n.evaluations.filter(p=>p.severity==="info").length,U=hn(n),F=n.artifacts.filter(p=>{const L=se(p);return!Gt(p,L)&&!!We(L)}),X=new Set(F.map(p=>p.id)),P=n.artifacts.filter(p=>!Gt(p,se(p))&&!X.has(p.id)),re=n.artifacts.filter(p=>Gt(p,se(p))),_=F[0]??P[0]??n.artifacts[0],T=dt(n),le=n.route==="certified_answer"||n.route==="semantic_answer"||n.route==="generated_answer",Z=n.nextActions.some(p=>p.route==="research"),K=le&&T&&!Z,oe=we(n),ue=T&&!(oe!=null&&oe.sourcePath)&&!!((oe==null?void 0:oe.source)??Te(n)),S=d&&g||y&&l?Rt(n):void 0,E=()=>{var L;const p=V?Ye(V):b??n.summary;p&&((L=navigator.clipboard)==null||L.writeText(p).catch(()=>{}),q(!0),window.setTimeout(()=>q(!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:[$?t.jsx(Xe,{size:14,color:r.error}):O?t.jsx(ge,{size:14,color:r.success}):t.jsx(Qe,{size:14,color:r.accent}),t.jsx("span",{style:{fontSize:12,fontWeight:650,color:$?r.error:r.textSecondary},children:B}),O&&U[0]?t.jsxs("span",{style:{fontSize:11,color:r.textMuted},children:["from ",t.jsx("span",{style:{color:r.accent,fontWeight:600},children:U[0].label})]}):!$&&_&&A>0?t.jsxs("button",{type:"button",onClick:()=>N(_.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(it,{size:11,color:r.success})," ",A," check",A===1?"":"s"," passed"]}):null]}),V?t.jsx("div",{"data-followup":"answer",style:{fontSize:14.5,lineHeight:1.65,color:r.textPrimary},children:t.jsx(kt,{text:Ye(V),t:r})}):b?t.jsx(Ds,{run:n,detail:b,threadId:s,onRepaired:p=>I(n.id,p),t:r}):n.summary?t.jsx("div",{"data-followup":"answer",style:{fontSize:14,lineHeight:1.6,color:r.textSecondary},children:Ie(n.summary)}):null,t.jsx(jr,{run:n,t:r,onSelect:x}),F.map(p=>t.jsx(us,{run:n,artifact:p,selected:p.id===a,t:r,themeMode:i,onInspect:L=>N(p.id,L)},p.id)),P.map(p=>{const L=se(p),ee=p.id===a;return t.jsxs("button",{type:"button",className:"dql-ask-chip",onClick:()=>N(p.id,pn(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:Ie(p.title)}),t.jsx("span",{style:{fontSize:11,color:r.textMuted},children:Mt(p,L)})]}),t.jsx(Zn,{size:14,color:r.textMuted,style:{flexShrink:0,marginLeft:6}})]},p.id)}),re.length>0?t.jsx("div",{style:{display:"grid",gap:8,gridTemplateColumns:"minmax(0, 1fr)",minWidth:0},children:re.map(p=>t.jsx(Cr,{artifact:p,t:r,themeMode:i,onInsertSql:j,onInsertDql:g,insertDqlActionLabel:d,sourceRunId:n.id,sourceQuestion:n.question,onOpenBlock:m,onOpenResearch:v,onOpenApp:c,onNextAction:z},p.id))}):null,V||b||S||T||ue||K||_?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:Le(r),children:[t.jsx(nt,{size:12})," ",d]}):null,S&&l&&y?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>l(S),style:Le(r),children:[t.jsx(oi,{size:12})," ",y]}):null,V||b?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:E,style:Le(r),children:[G?t.jsx(it,{size:12}):t.jsx(ir,{size:12})," ",G?"Copied":"Copy"]}):null,T?t.jsx(fn,{run:n,t:r,appContext:o,onOpenApp:c}):null,ue?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>z({id:"save-dql-block",label:"Save as block",route:"dql_block_draft"}),style:Le(r),children:[t.jsx(ct,{size:12})," Save as block"]}):null,K?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>z({id:"research-deeper",label:"Research this deeper",route:"research"}),style:Le(r),children:[t.jsx(ot,{size:12})," Research deeper"]}):null,_?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>N(_.id,Lt(se(_))?"how":"trust"),style:Le(r),children:[t.jsx(lt,{size:12})," How it was answered"]}):null]}):null]})}function jr({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 Sr(e){const n=e.executionError;if(typeof n=="string"&&n.trim())return{stage:"execution",message:n};const r=W(n);if(r)return{stage:"execution",...r};const i=typeof e.refusalCode=="string"?e.refusalCode:void 0;if(i){const s=W(e.refusalDetails),o=typeof(s==null?void 0:s.message)=="string"&&s.message.trim()?s.message:typeof e.answer=="string"&&e.answer.trim()?e.answer:"No answer was accepted for this question.";return{stage:"answer",code:i,message:o}}}function Lt(e){return!!(W(e.resolvedAnalyticalPlan)||W(e.analyticalExecutionGraph)||W(e.analyticalExecutionReceipt)||W(e.analyticalFailure)||W(e.semanticExecutionTrace)||W(e.diagnosticReceipt)||Sr(e))}function wr(e){if(!Lt(e))return;const n=W(e.diagnosticReceipt),r=W(e.resolvedAnalyticalPlan)??W(n==null?void 0:n.resolvedAnalyticalPlan);return{plan:r,frame:W(r==null?void 0:r.analyticalFrame),graph:W(e.analyticalExecutionGraph),receipt:W(e.analyticalExecutionReceipt),facts:W(e.analyticalFacts),narrative:W(e.analyticalNarrative),freshness:W(e.analyticalFreshnessObservation),failure:W(e.analyticalFailure)??W(n==null?void 0:n.failure)??Sr(e),semantic:W(e.semanticExecutionTrace),diagnostic:n}}function ps(){return["Plan","DQL","Compiled SQL","Lineage","Trust & evidence","Actual steps","Failure & repair"]}function fs(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 gs({run:e,contract:n,dqlArtifact:r,sql:i,lineage:s,t:o,onInsertSql:a,onInsertDql:u,onSaveBlock:c}){var be,Be,ke;const{dispatch:j}=Bt(),g=n.plan,l=n.frame,d=n.graph,y=n.receipt,m=n.semantic,v=W(m==null?void 0:m.failure),x=n.failure??v,z=W(m==null?void 0:m.authoringRequest),I=W(m==null?void 0:m.runtimeRequest),Q=Re(m==null?void 0:m.bindings),G=Re(m==null?void 0:m.steps),q=W(m==null?void 0:m.targetBinding),N=W(q==null?void 0:q.semanticSnapshot),O=W(q==null?void 0:q.executionTarget),$=W(O==null?void 0:O.redactedContext),H=W(q==null?void 0:q.compileTarget),V=W(m==null?void 0:m.executionReceipt),B=Re(v==null?void 0:v.candidates),b=W(l==null?void 0:l.timeContext),A=W(l==null?void 0:l.comparison),U=W(l==null?void 0:l.ranking),F=Re(l==null?void 0:l.dimensions),X=Re(l==null?void 0:l.memberBindings),P=Re(b==null?void 0:b.periods),re=Re(l==null?void 0:l.requestedOutputs),_=Re(d==null?void 0:d.nodes),T=Array.from(new Set([...me(x==null?void 0:x.safeActions),...me(v==null?void 0:v.safeActions)])),le=Re(x==null?void 0:x.failedBindings),Z=W(v==null?void 0:v.sqlExcerpt),K=e.artifacts.map(k=>We(se(k))).find(Boolean),oe=(r==null?void 0:r.name)??e.question,[ue,S]=f.useState(null),E=(k,ae)=>{const ve=ae.derivation.trustTransition;return`${k} as immutable derivation ${ae.derivation.derivationId}. Trust: ${ve.previous} → ${ve.next}${ve.requiresReview?" (review required)":""}.`},p=async()=>{if(!(!(r!=null&&r.source)||!u))try{const k=await te.deriveAnalyticalRepair(e.id,{version:1,action:"edit_dql",dqlSource:r.source});u({sql:i,dqlArtifact:r,result:K,title:oe,sourceRunId:e.id,question:e.question}),S(E("Opened DQL in Notebook",k))}catch(k){S(k instanceof Error?k.message:String(k))}},L=async()=>{if(!(!i||!a))try{const k=await te.deriveAnalyticalRepair(e.id,{version:1,action:"open_sql_notebook",sqlText:i});a(i,`${oe} repair`,{question:e.question,sourceRunId:e.id}),S(E("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(E(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))}},ne=async()=>{try{const k=await te.deriveAnalyticalRepair(e.id,{version:1,action:"request_access"});S(E("Recorded the access/connection repair and opened Database settings",k)),j({type:"SET_SETTINGS_TAB",tab:"database"}),j({type:"SET_MAIN_VIEW",view:"settings"})}catch(k){S(k instanceof Error?k.message:String(k))}},Ve=()=>{j({type:"SET_SETTINGS_TAB",tab:"project"}),j({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 ${x?"var(--status-error-border)":"var(--status-success-border)"}`,background:x?"var(--status-error-bg)":"var(--status-success-bg)"},children:[x?t.jsx(Xe,{size:13,color:"var(--status-error)",style:{flexShrink:0,marginTop:2}}):t.jsx(ge,{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:x?"var(--status-error)":"var(--status-success)"},children:x?"Execution failed":"Answered successfully"}),x?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{marginTop:3,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:o.fontMono,fontSize:11},children:typeof x.message=="string"&&x.message.trim()?x.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:[x.code,x.phase?`during ${x.phase}`:""].filter(Boolean).map(C).join(" · ")})]}):t.jsx("div",{style:{marginTop:2},children:typeof(y==null?void 0:y.rowCount)=="number"?`Returned ${y.rowCount} row${y.rowCount===1?"":"s"}.`:"The query ran and returned a result."})]})]}),t.jsx(St,{index:1,label:"Plan",t:o,open:!x,children:t.jsx(Kt,{rows:[["Question type",C((l==null?void 0:l.questionType)??(g==null?void 0:g.questionType))],["Selected route",C((d==null?void 0:d.route)??(g==null?void 0:g.recommendedRoute))],["Metric",me(l==null?void 0:l.metricConceptIds).join(", ")],["Entity grain",me(l==null?void 0:l.entityGrainIds).join(", ")],["Dimensions",F.map(k=>`${C(k.dimensionId)} (${C(k.role)})`).join(", ")],["Member filters",X.map(k=>`${C(k.dimensionId)}: ${Array.isArray(k.canonicalValues)?k.canonicalValues.length:0} bound value(s)`).join(", ")],["Time policy",[b==null?void 0:b.timeRole,b==null?void 0:b.grain,b==null?void 0:b.timezone,b==null?void 0:b.completenessPolicy].map(C).filter(Boolean).join(" · ")],["Periods",P.map(k=>`${C(k.id)}: ${C(k.start)} → ${C(k.end)}`).join(`
80
- `)],["Comparison",A?`${C(A.basePeriodId)} vs ${me(A.comparisonPeriodIds).join(", ")} · ${C(A.alignment)}`:l?"Not requested":"Not available — analytical planning did not complete"],["Ranking",U?`${C(U.direction)} · top ${C(U.limit)} · ${C(U.tiePolicy)}`:l?"Not requested":"Not available — analytical planning did not complete"],["Outputs",re.map(k=>`${C(k.id)} (${C(k.kind)})`).join(", ")],["Semantic metrics",me(z==null?void 0:z.metrics).join(", ")],["Semantic dimensions",me(z==null?void 0:z.dimensions).join(", ")]],t:o})}),t.jsx(St,{index:2,label:"Trust & evidence",t:o,children:t.jsx(Kt,{rows:[["Trust state",e.trustState],["Snapshot",C((g==null?void 0:g.snapshotId)??(d==null?void 0:d.snapshotId))],["Plan fingerprint",C((g==null?void 0:g.fingerprint)??(d==null?void 0:d.planFingerprint))],["Graph fingerprint",C(d==null?void 0:d.fingerprint)],["Receipt",C(y==null?void 0:y.receiptId)],["Result fingerprint",C(y==null?void 0:y.resultFingerprint)],["Freshness observed through",C((be=n.freshness)==null?void 0:be.observedThrough)],["Fact set",C((Be=n.facts)==null?void 0:Be.fingerprint)],["Semantic adapter",C(m==null?void 0:m.adapter)],["Semantic compile status",C(m==null?void 0:m.status)],["Target proof",C((ke=W(q==null?void 0:q.proof))==null?void 0:ke.status)],["Target binding",C(q==null?void 0:q.bindingFingerprint)],["Compile target",C(H==null?void 0:H.kind)],["Local semantic snapshot",C((N==null?void 0:N.semanticCatalogFingerprint)??(N==null?void 0:N.sourceFingerprint))],["Runtime metric inventory proof",C(H==null?void 0:H.semanticCatalogFingerprint)],["Execution target",[O==null?void 0:O.driver,$==null?void 0:$.account,$==null?void 0:$.database,$==null?void 0:$.schema,$==null?void 0:$.role,$==null?void 0:$.warehouse].map(C).filter(Boolean).join(" · ")],["Semantic receipt",C(V==null?void 0:V.receiptId)],["Warehouse query ID",C(V==null?void 0:V.queryId)],["Executed SQL proof",C(V==null?void 0:V.executedSqlFingerprint)],["Runtime metrics",me(I==null?void 0:I.metrics).join(", ")],["Runtime dimensions",me(I==null?void 0:I.dimensions).join(", ")],["Member bindings",Q.map(k=>`${C(k.authoringReference)} → ${C(k.runtimeReference)}${me(k.entityPath).length?` via ${me(k.entityPath).join(" → ")}`:""} (${C(k.status)})`).join(`
81
- `)]],t:o,mono:!0})}),t.jsx(St,{index:3,label:"Actual steps",t:o,children:t.jsxs("div",{style:{display:"grid",gap:6},children:[G.map((k,ae)=>t.jsxs("div",{style:{fontSize:11.5,color:o.textSecondary},children:[t.jsxs("strong",{style:{color:C(k.status)==="failed"?"var(--status-error)":o.textPrimary},children:[ae+1,". ",C(k.label)]})," ","— ",C(k.status)," · ",C(k.detail)]},`semantic:${C(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)),_.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,". ",C(k.kind)]})," ","· ",C(k.id)]},C(k.id)||ae)),G.length===0&&e.steps.length===0&&_.length===0?t.jsx(Ct,{t:o,children:"No executable steps were recorded."}):null]})}),t.jsx(St,{index:4,label:"Failure & repair",t:o,open:!!x,children:x?t.jsxs("div",{style:{display:"grid",gap:9},children:[t.jsx(Kt,{rows:[["Failure ID",C(x.failureId)],["Recoverability",C(x.recoverability)],["Failed bindings",le.map(k=>`${C(k.qualifiedId??k.role)} (${C(k.reasonCode)})`).join(", ")],["Safe actions",T.join(", ")],["DQL fingerprint",C(x.dqlFingerprint)],["SQL fingerprint",C(x.sqlFingerprint)],["Semantic failure code",C(v==null?void 0:v.code)],["Failing identifier",C(v==null?void 0:v.identifier)],["Compiled SQL proof",C(v==null?void 0:v.compiledSqlFingerprint)],["Path candidates",B.map(k=>`${C(k.label)}
82
- ${C(k.runtimeReference)}`).join(`
83
- `)]],t:o,mono:!0}),C(Z==null?void 0:Z.text)?t.jsxs("div",{children:[t.jsxs("div",{style:{fontSize:10.5,fontWeight:700,color:o.textSecondary,marginBottom:5},children:["Failing SQL context · lines ",C(Z==null?void 0:Z.startLine),"–",C(Z==null?void 0:Z.endLine)]}),t.jsx("pre",{style:at(o),children:C(Z==null?void 0:Z.text)})]}):null,t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6},"aria-label":"Safe repair actions",children:[T.includes("edit_dql")&&u?t.jsxs("button",{type:"button",onClick:()=>void p(),style:J(o),children:[t.jsx(Et,{size:12})," Open DQL to repair"]}):null,T.includes("open_sql_notebook")&&a?t.jsxs("button",{type:"button",onClick:()=>void L(),style:J(o),children:[t.jsx(an,{size:12})," Open SQL in Notebook"]}):null,T.includes("retry_same_plan")?t.jsxs("button",{type:"button",onClick:()=>void ee("retry_same_plan"),style:J(o),children:[t.jsx(Dt,{size:12})," Retry same plan"]}):null,T.includes("refresh_snapshot")?t.jsxs("button",{type:"button",onClick:()=>void ee("refresh_snapshot"),style:J(o),children:[t.jsx(Dt,{size:12})," Refresh snapshot and prepare retry"]}):null,T.includes("request_access")||T.includes("change_authorized_connection")?t.jsxs("button",{type:"button",onClick:()=>void ne(),style:J(o),children:[t.jsx(Xe,{size:12})," Change connection or request access"]}):null,T.includes("reapply_semantic_runtime")?t.jsxs("button",{type:"button",onClick:Ve,style:J(o),children:[t.jsx(Dt,{size:12})," Reapply semantic runtime settings"]}):null]})]}):t.jsxs("div",{style:{display:"grid",gap:8},children:[t.jsx(Ct,{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:c,style:J(o),children:[t.jsx(cn,{size:12})," Save as draft block"]}):null]})}),ue?t.jsx("div",{role:"status",style:{fontSize:10.5,color:ue.toLowerCase().includes("created")?"var(--status-success)":"var(--status-error)"},children:ue}):null]})}function St({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 Kt({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 Ct({t:e,children:n}){return t.jsx("div",{style:{fontSize:11,color:e.textMuted},children:n})}function Re(e){return Array.isArray(e)?e.flatMap(n=>W(n)?[W(n)]:[]):[]}function me(e){return Array.isArray(e)?e.filter(n=>typeof n=="string"):[]}function C(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):""}function wt(e){return{question:e.question??e.label,selectedEvidenceId:e.id}}function kr(e){var i;const n=e.artifacts.map(s=>We(se(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:Te(e),dqlArtifact:we(e),...n?{result:{columns:n.columns,rows:n.rows.slice(0,24),rowCount:n.rowCount}}:{}}}function dt(e){return!e.artifacts.some(r=>!!Wt(se(r)))&&e.status!=="blocked"&&e.status!=="needs_clarification"&&e.artifacts.some(r=>r.kind==="answer"||r.kind==="research_run")}function xs({run:e,artifact:n,tab:r,t:i,appContext:s,onOpenApp:o,onChangeTab:a,onClose:u,onSaveBlock:c,onInsertSql:j,onInsertDql:g}){const l=se(n),d=we(e)??ut(l),y=Te(e)??(typeof l.sql=="string"?l.sql:void 0),m=We(l),v=rt(e,n),x=hn(e),z=vr(e),I=gn(e),Q=n.trustState==="certified",G=e.status==="blocked"||n.trustState==="blocked",q=dt(e),N=wr(l),O=br({analytical:!!N,blocked:G,hasDql:!!(d!=null&&d.source),hasSql:!!y,hasLineage:z.length>0}),$=O.some(b=>b.id===r)?r:O[0].id,H=G?"Blocked":Q?"Certified":n.trustState==="governed"||n.trustState==="grounded"?"Governed":"AI-generated",V=G?"var(--status-error)":Q?"var(--status-success)":n.trustState==="governed"||n.trustState==="grounded"?"var(--accent)":"var(--status-warning)",B=G?"var(--status-error-bg)":Q?"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:B,color:V,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:rt(e,n)}),t.jsx("div",{style:{fontSize:11,color:i.textMuted,marginTop:2},children:Mt(n,l)})]}),t.jsx("span",{style:{border:`1px solid ${V}`,color:V,background:B,borderRadius:999,padding:"2px 8px",fontSize:10,fontWeight:700,flexShrink:0,marginTop:2},children:H}),t.jsx("button",{type:"button",onClick:u,title:"Close",className:"dql-ask-ghost",style:{width:24,height:24,borderRadius:6,border:"none",background:"none",color:i.textMuted,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",flexShrink:0},children:t.jsx(At,{size:14})})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"10px 16px",borderBottom:"1px solid var(--border-subtle)"},children:[q?t.jsx(fn,{run:e,t:i,appContext:s,onOpenApp:o}):null,q?t.jsxs("button",{type:"button",className:"dql-hover",onClick:c,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(ct,{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(hi,{size:14})})]}),t.jsx("div",{style:{display:"flex",alignItems:"center",gap:16,padding:"0 16px",borderBottom:"1px solid var(--border-subtle)",flexShrink:0},children:O.map(b=>t.jsx("button",{type:"button",onClick:()=>a(b.id),style:{padding:"10px 1px",fontSize:12,fontWeight:600,cursor:"pointer",border:"none",background:"none",fontFamily:i.font,whiteSpace:"nowrap",color:$===b.id?i.textPrimary:i.textMuted,boxShadow:$===b.id?`inset 0 -2px 0 0 ${i.accent}`:"none"},children:b.label},b.id))}),t.jsxs("div",{style:{flex:1,minHeight:0,overflow:"auto",padding:"14px 16px 20px"},children:[$==="how"&&N?t.jsx(gs,{run:e,contract:N,dqlArtifact:d,sql:y,lineage:z,t:i,onInsertSql:j,onInsertDql:g,onSaveBlock:c}):null,$==="dql"?d!=null&&d.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:y,dqlArtifact:d,result:m,chartConfig:m?Oe(l,m):void 0,title:v,sourceRunId:e.id,question:e.question}),style:J(i),children:"Open DQL in notebook"}):null,t.jsx(zt,{text:d.source,t:i,title:"Copy DQL"})]})]}),t.jsx("pre",{style:at(i),children:d.source})]}):t.jsx(Ct,{t:i,children:"The selected plan failed before a DQL source could be materialized. Review the Plan and Failure & repair sections."}):null,$==="sql"?y?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[t.jsx("span",{style:{fontSize:11,color:i.textMuted},children:"Attempted compiled SQL — open it in Notebook to inspect or repair."}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[j?t.jsx("button",{type:"button",onClick:()=>j(y,v,{question:e.question,sourceRunId:e.id}),style:J(i),children:"Open SQL in notebook"}):null,t.jsx(zt,{text:y,t:i,title:"Copy SQL"})]})]}),t.jsx("pre",{style:at(i),children:y})]}):t.jsx(Ct,{t:i,children:"Compilation stopped before SQL was produced. The DQL, plan, trust evidence, and failure steps are still retained."}):null,$==="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."}),z.map(b=>t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:9,padding:"9px 10px",border:"1px solid var(--border-subtle)",borderRadius:8,background:"var(--bg-1)"},children:[t.jsx(nr,{size:13,color:i.accent,style:{flexShrink:0,marginTop:2}}),t.jsxs("div",{style:{minWidth:0},children:[t.jsx("div",{style:{fontSize:12,fontWeight:650,color:i.textPrimary},children:b.name}),t.jsx("div",{style:{fontSize:10.5,color:i.textMuted,marginTop:2},children:[b.kind,b.detail].filter(Boolean).join(" · ")})]})]},`${b.kind??"asset"}:${b.name}`))]}):null,$==="trust"?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[I?t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-start",padding:"10px 12px",borderRadius:8,background:Q?"var(--status-success-bg)":"var(--status-warning-bg)",border:`1px solid ${Q?"var(--status-success-border)":"var(--status-warning-border)"}`},children:[Q?t.jsx(ge,{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:I})]}):null,x.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:x.map(b=>t.jsxs("span",{style:Br(i,b.certified),children:[b.certified?t.jsx(ge,{size:11}):t.jsx(ot,{size:11}),t.jsx("span",{children:b.label})]},b.label))})]}):null,e.evaluations.length>0?t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:i.textMuted,textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:8},children:"Verification checks"}),t.jsx(zr,{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(Rr,{steps:e.steps,t:i})]}):null,t.jsx(Tr,{run:e,t:i})]}):null]})]})}function hs({t:e,text:n,source:r,left:i,top:s,draft:o,inputRef:a,onDraftChange:u,onClose:c,onSend:j}){const g=(l,d)=>t.jsx("button",{type:"button",onClick:()=>j(d),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(Qe,{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:c,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(At,{size:12})})]}),t.jsxs("div",{style:{borderLeft:`2px solid ${e.accent}`,background:"var(--accent-dim)",borderRadius:"0 6px 6px 0",padding:"5px 9px",fontSize:11.5,color:e.textSecondary,lineHeight:1.45,display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:["“",n,"”"]}),t.jsxs("div",{style:{display:"flex",gap:6},children:[t.jsx("input",{ref:a,value:o,onChange:l=>u(l.target.value),onKeyDown:l=>{l.key==="Enter"&&(l.preventDefault(),j(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:()=>j(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(tr,{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 Ut(e){const n=e.replace(/^\/\w+\s+/,"").trim().replace(/[?.!]+$/,"");return(n?n.charAt(0).toUpperCase()+n.slice(1):"New app").slice(0,60)}function nn(e,n){return n!=null&&n.trim()?`${e} › ${n.trim()}`:e}function fn({run:e,t:n,appContext:r,onOpenApp:i}){const[s,o]=f.useState(!1),[a,u]=f.useState(null),[c,j]=f.useState(!1),[g,l]=f.useState("list"),[d,y]=f.useState(""),[m,v]=f.useState(!1),[x,z]=f.useState(null),[I,Q]=f.useState(null),G=f.useRef(null),q=async()=>{u(null),j(!1);try{const B=await te.listAppsStrict();u(B),B.length===0&&l("new")}catch{u([]),j(!0)}},N=()=>{o(!0),z(null),l("list"),G.current=null,y(Ut(e.question)),q()},O=()=>{m||(o(!1),z(null))},$=async(B,b,A,U)=>{const F=Ut(e.question),X=we(e),P=await te.createAiPin(B,{dashboardId:b,title:F,answer:e.answer??e.summary,question:e.question,sql:Te(e),certification:e.trustState==="certified"?"certified":"ai_generated",reviewStatus:e.trustState==="certified"?"certified":"needs_review",analysisPlan:X?{dqlArtifact:X}:void 0});if(!P.ok)throw new Error("Could not add to app.");Q({appId:B,dashboardId:b,name:A,dashboardTitle:U,tileTitle:P.pin.title||F}),window.dispatchEvent(new CustomEvent("dql-app-dashboard-updated",{detail:{appId:B,dashboardId:b,tileId:P.pin.tileId}})),o(!1)},H=async B=>{var b,A,U,F,X;if(!m){v(!0),z(null);try{let P=(r==null?void 0:r.appId)===B.id?r.dashboardId:void 0,re=(r==null?void 0:r.appId)===B.id?r.dashboardTitle:void 0,_=null;if(!P){_=await te.getApp(B.id);const T=(b=_==null?void 0:_.app)==null?void 0:b.homepage;if(P=(T==null?void 0:T.type)==="dashboard"?T.id:(U=(A=_==null?void 0:_.dashboards)==null?void 0:A[0])==null?void 0:U.id,!P){const le=await te.createAppDashboard(B.id,{title:"Overview"});if(!le.ok)throw new Error(le.error);P=le.dashboard.id,re=le.dashboard.metadata.title}}re||(_=_??await te.getApp(B.id),re=(X=(F=_==null?void 0:_.dashboards)==null?void 0:F.find(T=>T.id===P))==null?void 0:X.title),await $(B.id,P,B.name,re)}catch(P){z(P instanceof Error?P.message:"Could not add to app.")}finally{v(!1)}}},V=async()=>{if(m)return;const B=d.trim()||Ut(e.question);v(!0),z(null);try{if(!G.current){const b=await te.createApp({name:B,domain:"general",dashboardTitle:"Overview",tags:[],owners:[],selectedBlockIds:[]});G.current={appId:b.app.id,dashboardId:b.dashboardId}}await $(G.current.appId,G.current.dashboardId,B,"Overview"),G.current=null}catch(b){z(b instanceof Error?b.message:"Could not create the app.")}finally{v(!1)}};return t.jsxs("div",{style:{position:"relative",display:"inline-flex",alignItems:"center",gap:6},children:[I?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(st,{size:15})}),t.jsxs("span",{style:{display:"grid",gap:1,minWidth:0},children:[t.jsx("b",{style:{fontSize:11.5},children:"Added to App"}),t.jsx("span",{title:nn(I.name,I.dashboardTitle),style:{fontSize:10.5,color:n.textSecondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:nn(I.name,I.dashboardTitle)}),t.jsxs("span",{title:I.tileTitle,style:{fontSize:10,color:n.textMuted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Tile: ",I.tileTitle]})]}),i?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>i(I.appId,I.dashboardId),style:{...J(n),color:n.success,whiteSpace:"nowrap"},title:"Open the App page containing this tile",children:["Open App ",t.jsx(ci,{size:12})]}):null]}):null,t.jsxs("button",{type:"button",className:"dql-hover dql-lift",onClick:N,style:I?J(n):Un(n),children:[t.jsx(Jt,{size:13}),I?"Add to another":"Add to app"]}),s?t.jsxs(t.Fragment,{children:[t.jsx("div",{onClick:O,style:{position:"fixed",inset:0,zIndex:40}}),t.jsxs("div",{style:Bs(n),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[t.jsx("span",{style:{fontSize:12,fontWeight:700,color:n.textPrimary},children:g==="new"?"Name the new app":"Add to an app"}),t.jsx("button",{type:"button",onClick:O,style:{border:"none",background:"transparent",color:n.textMuted,cursor:"pointer",fontSize:15,lineHeight:1},children:"×"})]}),x?t.jsx("div",{style:{fontSize:11,color:n.error,marginBottom:7,lineHeight:1.4},children:x}):null,g==="new"?t.jsxs("div",{style:{display:"grid",gap:8},children:[t.jsx("input",{autoFocus:!0,value:d,onChange:B=>y(B.target.value),onKeyDown:B=>{B.key==="Enter"&&V()},placeholder:"App name",style:Es(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:J(n),children:"Back"}):null,t.jsxs("button",{type:"button",className:"dql-hover",disabled:m||!d.trim(),onClick:()=>void V(),style:{...Un(n),flex:1,justifyContent:"center"},children:[m?t.jsx(He,{size:13,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(nt,{size:13}),"Create & add"]})]})]}):a===null?t.jsx("div",{style:{fontSize:11.5,color:n.textMuted,padding:"8px 2px"},children:"Loading apps…"}):c?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:J(n),children:"Retry"}),t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>l("new"),style:{...Yn(n),width:"auto",flex:1,marginBottom:0,justifyContent:"center"},children:[t.jsx(nt,{size:13})," New app…"]})]})]}):t.jsxs("div",{style:{display:"grid",gap:3,maxHeight:244,overflow:"auto"},children:[t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>l("new"),style:Yn(n),children:[t.jsx(nt,{size:13})," New app…"]}),a.map(B=>t.jsxs("button",{type:"button",className:"dql-hover",disabled:m,onClick:()=>void H(B),style:$s(n),children:[t.jsx(Jt,{size:13,style:{flex:"0 0 auto",opacity:.7}}),t.jsx("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",textAlign:"left"},children:B.name})]},B.id))]})]})]}):null]})}function gn(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(xn(e)){const r=e.artifacts.map(o=>o.payload).filter(o=>!!(o&&typeof o=="object"&&!Array.isArray(o)));if(r.some(o=>{const a=o.result;return!!(a&&typeof a=="object"&&!Array.isArray(a))}))return"Exploratory · DBT-grounded. The query and bounded join probes ran, but no certified relationship path covers it yet.";const s=(n=r.find(o=>typeof o.executionError=="string"))==null?void 0:n.executionError;return typeof s=="string"&&s.trim()?"Exploratory · DBT-grounded. DQL prepared a review-required query, but its bounded execution failed. Inspect the error and DQL artifact before reuse.":"Exploratory · DBT-grounded. DQL prepared a review-required query, but it has not executed yet."}return e.trustState==="review_required"?"AI-generated answer. Save it as a block when you want to keep it.":(e.trustState==="blocked",null)}function xn(e){return e.artifacts.some(n=>{const r=n.payload;return!!(r&&typeof r=="object"&&!Array.isArray(r)&&r.exploratoryCandidate)})}function ys(e){return e.trustState==="certified"?"Certified answer":e.route==="dql_block_draft"?"Draft block":xn(e)?"Exploratory DBT-grounded answer":e.route==="semantic_answer"?"Semantic answer":e.route==="generated_answer"?"AI-generated answer":pr[e.route]}function ms({artifact:e,payload:n,t:r,onOpenApp:i}){const s=typeof n.sessionId=="string"?n.sessionId:void 0,o=n.proposal&&typeof n.proposal=="object"?n.proposal:void 0,a=typeof n.proposalHash=="string"?n.proposalHash:void 0,[u,c]=f.useState(()=>o?ti(o):new Set),[j,g]=f.useState(!1),[l,d]=f.useState(null),[y,m]=f.useState(null);if(!o||!s)return t.jsxs("div",{style:on(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()=>{var z,I;g(!0),d(null);const x=await te.commitAppAiBuild(s,{selectedTileIds:Array.from(u),expectedProposalHash:a});if(g(!1),!x.ok){d(x.error);return}m({appId:((z=x.app)==null?void 0:z.id)??x.session.appId??"",dashboardId:x.dashboardId??void 0,name:((I=x.app)==null?void 0:I.name)??e.title})};return t.jsxs("div",{style:on(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:Ie(e.title)})]}),y?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:6,color:r.success,fontSize:12,fontWeight:750},children:[t.jsx(st,{size:13})," Created ",y.name]}),y.appId&&i?t.jsx("button",{type:"button",className:"dql-hover",onClick:()=>i(y.appId,y.dashboardId),style:J(r),children:"Open app"}):null]}):t.jsx(ni,{proposal:o,t:r,selected:u,onToggle:x=>{c(z=>{const I=new Set(z);return I.has(x)?I.delete(x):I.add(x),I})},onCreate:()=>void v(),busy:j,error:l,compact:!0})]})}function Ar({artifact:e,certifiedBlockName:n,initialResult:r,initialChartConfig:i,payload:s,executionTarget:o,t:a,themeMode:u,embedded:c=!1,expanded:j=!1}){var ue;const[g,l]=f.useState(e),[d,y]=f.useState(()=>e.parameters??[]),[m,v]=f.useState(()=>({...e.parameterValues??{},...rn(s)})),[x,z]=f.useState(r),[I,Q]=f.useState(i),[G,q]=f.useState(!!n),[N,O]=f.useState(!1),[$,H]=f.useState(null),[V,B]=f.useState(!1),[b,A]=f.useState(""),[U,F]=f.useState(""),X=f.useRef(!1),P=f.useRef(e);P.current=e;const re=Yi(e);f.useEffect(()=>{const S=P.current;if(l(S),B(!1),!n){y(S.parameters??[]),v({...S.parameterValues??{},...rn(s)}),q(!1);return}let E=!1;return q(!0),te.getCertifiedBlockParameters(n).then(p=>{E||(y(p.parameters),v(L=>({...Object.fromEntries(p.parameters.flatMap(ee=>ee.default===void 0?[]:[[ee.name,ee.default]])),...L})))}).catch(p=>{E||H(p instanceof Error?p.message:String(p))}).finally(()=>{E||q(!1)}),()=>{E=!0}},[re,n]);const _=async()=>{if(!X.current){X.current=!0,O(!0),H(null);try{const S=await te.invokeDqlArtifact(g,m,void 0,n,o);z(S.result),l(S.artifact),S.result.chartConfig&&typeof S.result.chartConfig=="object"&&Q(S.result.chartConfig),S.parameters.length>0&&y(S.parameters)}catch(S){H(S instanceof Error?S.message:String(S))}finally{X.current=!1,O(!1)}}},T=f.useMemo(()=>cr(g,x),[g,x]),le=()=>{const S=T[0];S&&(A(S.column),F(S.values[0]==null?"":String(S.values[0])),B(!0),H(null))},Z=async()=>{try{const S=g.kind==="sql_block"?await te.addDqlArtifactResultFilter(g,x.columns,b,U,o):Ji(g,x,b,U);l(S.artifact),y(S.artifact.parameters??[]),v(E=>({...E,...S.artifact.parameterValues??{}})),B(!1),H(null)}catch(S){H(S instanceof Error?S.message:String(S))}},K=d.some(or),oe=Object.entries(m).filter(([,S])=>S!=null&&S!=="");return t.jsxs("div",{style:{display:"grid",gap:9},children:[oe.length>0?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap",padding:c?"8px 12px 0":0},children:[t.jsx("span",{style:{fontSize:10.5,fontWeight:750,color:a.textMuted},children:"Applied inputs"}),oe.map(([S,E])=>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," ")," = ",bs(E)]},S))]}):null,G?t.jsx("div",{style:{fontSize:10.5,color:a.textMuted},children:"Loading reusable inputs…"}):K||T.length>0?t.jsxs("div",{style:{display:"grid",gap:8,padding:9,margin:c?"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."})]}),T.length>0?t.jsxs("button",{type:"button",onClick:le,style:J(a),children:[t.jsx(nt,{size:11})," Add result filter"]}):null,t.jsxs("button",{type:"button",disabled:N,onClick:()=>void _(),style:{...J(a),color:a.accent,opacity:N?.65:1},children:[N?t.jsx(He,{size:11,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(Qe,{size:11}),N?"Running…":"Apply"]})]}),V?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:b,onChange:S=>{const E=S.target.value,p=T.find(L=>L.column===E);A(E),F((p==null?void 0:p.values[0])==null?"":String(p.values[0]))},style:Jn(a),children:T.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:U,list:`ask-filter-${b}`,onChange:S=>F(S.target.value),style:Jn(a)}),t.jsx("datalist",{id:`ask-filter-${b}`,children:(((ue=T.find(S=>S.column===b))==null?void 0:ue.values)??[]).map(S=>t.jsx("option",{value:String(S)},`${typeof S}:${String(S)}`))})]}),t.jsx("button",{type:"button",onClick:()=>{Z()},style:{...J(a),color:a.accent},children:"Add input"}),t.jsx("button",{type:"button",onClick:()=>B(!1),style:J(a),children:"Cancel"})]}):null,d.length>0?t.jsx(Ei,{parameters:d,values:m,onChange:(S,E)=>v(p=>({...p,[S]:E})),t:a}):null,T.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,$?t.jsx("div",{style:{fontSize:10.5,color:a.error},children:$}):null,t.jsx(ln,{result:x,themeMode:u,t:a,chartConfig:I,embedded:c,tabLabels:c?{table:"Results",chart:"Visualization"}:void 0,contentMaxHeight:j?"calc(100vh - 172px)":void 0,tableMaxHeight:j?"calc(100vh - 250px)":void 0})]})}function rn(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 bs(e){return Array.isArray(e)?e.map(n=>String(n)).join(", "):typeof e=="boolean"?e?"true":"false":String(e)}function qr(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 Cr({artifact:e,t:n,themeMode:r,onInsertSql:i,onInsertDql:s,insertDqlActionLabel:o,sourceRunId:a,sourceQuestion:u,onOpenBlock:c,onOpenResearch:j,onOpenApp:g,onNextAction:l}){const d=e.payload&&typeof e.payload=="object"?e.payload:{};if(e.kind==="app_proposal")return t.jsx(ms,{artifact:e,payload:d,t:n,onOpenApp:g});const y=We(d),m=ut(d),v=Wt(d),x=typeof d.sql=="string"?d.sql:typeof d.sqlPreview=="string"?d.sqlPreview:typeof d.proposedSql=="string"?d.proposedSql:void 0,z=typeof d.name=="string"?d.name:e.title,I=typeof d.path=="string"?d.path:e.ref,Q=d.draftBlock&&typeof d.draftBlock=="object"&&!Array.isArray(d.draftBlock)?d.draftBlock:void 0,G=typeof(Q==null?void 0:Q.path)=="string"?Q.path:void 0,q=typeof(Q==null?void 0:Q.name)=="string"?Q.name:void 0,N=(m==null?void 0:m.sourcePath)??G??(e.kind==="dql_block_draft"?I:void 0),O=(m==null?void 0:m.name)??q??z,$=(m==null?void 0:m.kind)==="sql_block"||e.kind==="dql_block_draft"?"Open DQL draft":"Open DQL artifact",H=d.plan&&typeof d.plan=="object"?d.plan:void 0,V=Array.isArray(H==null?void 0:H.steps)?H.steps:[],B=Array.isArray(H==null?void 0:H.gaps)?H.gaps.map(String):[],b=typeof d.researchRunId=="string"?d.researchRunId:e.kind==="research_run"&&typeof e.ref=="string"?e.ref:void 0,A=typeof d.notebookPath=="string"?d.notebookPath:void 0,U=Array.isArray(d.generatedPaths)?d.generatedPaths.filter(_=>typeof _=="string"):[],F=d.narration&&typeof d.narration=="object"?d.narration:void 0,X=Array.isArray(F==null?void 0:F.keyFindings)?F.keyFindings.filter(_=>typeof _=="string"):[],P=typeof(F==null?void 0:F.recommendation)=="string"?F.recommendation:void 0,re=e.trustState==="certified"?qr(e,d):void 0;if(e.kind==="dql_block_draft"){const _=le=>Array.isArray(le)?le.filter(Z=>typeof Z=="string"):void 0,T=d.certifierVerdict&&typeof d.certifierVerdict=="object"?d.certifierVerdict:void 0;return t.jsx(Bi,{t:n,name:typeof d.name=="string"?d.name:z,status:"draft",description:typeof d.description=="string"?d.description:void 0,dql:(m==null?void 0:m.source)??(typeof d.dqlSource=="string"?d.dqlSource:void 0),sqlPreview:x,grain:typeof d.grain=="string"?d.grain:void 0,outputs:_(d.outputs),dimensions:_(d.dimensions)??(m==null?void 0:m.dimensions),entities:_(d.entities),certifierVerdict:T?{blocking:_(T.blocking)??[],warnings:_(T.warnings)??[],ready:!!T.ready}:void 0,actions:t.jsxs(t.Fragment,{children:[x&&s?t.jsx("button",{type:"button",onClick:()=>s({sql:x,dqlArtifact:m,result:y,chartConfig:y?Oe(d,y):void 0,title:z,sourceRunId:a,question:u}),style:J(n),children:o??"Insert as DQL cell"}):x&&i?t.jsx("button",{type:"button",onClick:()=>i(x,z,{question:u,sourceRunId:a}),style:J(n),children:"Insert SQL preview"}):null,N&&c?t.jsx("button",{type:"button",onClick:()=>c(N,O),style:J(n),children:$}):null]})})}return t.jsxs("div",{style:on(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:Ie(e.title)})]}),X.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(Hn,{items:X,t:n,renderItem:(_,T)=>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)})]}):V.length>0?t.jsx("div",{style:{display:"grid",gap:5},children:t.jsx(Hn,{items:V,t:n,renderItem:(_,T)=>t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.35},children:[T+1,". ",String(_.thought??_.expectation??"Research step")]},T)})}):null,P?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:P})]}):null,y?m?t.jsx(Ar,{artifact:m,certifiedBlockName:re,initialResult:y,initialChartConfig:Oe(d,y),payload:d,t:n,themeMode:r}):t.jsx(ln,{result:y,themeMode:r,t:n,chartConfig:Oe(d,y)}):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(ct,{size:12}),t.jsx("span",{children:"View DQL artifact"}),t.jsxs("span",{style:{marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:4},children:[m.source?t.jsx(zt,{text:m.source,t:n,title:"Copy DQL"}):null,!N&&l?t.jsxs("button",{type:"button",className:"dql-hover",title:"Save this DQL as a reusable block",onClick:_=>{_.preventDefault(),_.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(cn,{size:12})," Save as block"]}):null]})]}),m.sourcePath?t.jsx("div",{style:{marginTop:6,fontSize:10.5,color:n.textMuted},children:m.sourcePath}):null,t.jsx("pre",{style:{...at(n),marginTop:6},children:m.source})]}):null,x?t.jsxs("details",{children:[t.jsxs("summary",{style:{cursor:"pointer",fontSize:11,color:n.textSecondary,listStyle:"none",display:"flex",alignItems:"center",gap:5},children:[t.jsx(an,{size:12}),t.jsx("span",{children:_r(!!m)}),t.jsx("span",{style:{marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:4},children:t.jsx(zt,{text:x,t:n,title:"Copy SQL"})})]}),t.jsx("pre",{style:{...at(n),marginTop:6},children:x})]}):null,B.length>0?t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.4},children:["Gaps: ",B.join(", ")]}):null,U.length>0?t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.4},children:["Files: ",U.join(", ")]}):null,t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[b&&j?t.jsx("button",{type:"button",onClick:()=>j(b,A),style:J(n),children:"Open research"}):null,x&&s?t.jsx("button",{type:"button",onClick:()=>s({sql:x,dqlArtifact:m,result:y,chartConfig:y?Oe(d,y):void 0,title:z,mixedSourcePlan:v,sourceRunId:a,question:u}),style:v?{...J(n),background:n.accent,borderColor:n.accent,color:"#fff",fontWeight:850,padding:"7px 11px"}:J(n),children:v?"Add workflow to notebook":m?"Insert as DQL cell":"Add SQL to notebook"}):x&&i?t.jsx("button",{type:"button",onClick:()=>i(x,z,{question:u,sourceRunId:a}),style:J(n),children:"Insert SQL preview"}):null,N&&c?t.jsx("button",{type:"button",onClick:()=>c(N,O),style:J(n),children:$}):null]})]})}function vs({run:e}){return e.trustState==="certified"?t.jsx(ge,{size:16,color:"#16a34a"}):e.trustState==="governed"?t.jsx(ge,{size:16,color:"#2563eb"}):e.trustState==="grounded"?t.jsx(ge,{size:16,color:"#2563eb"}):e.status==="completed"?t.jsx(st,{size:16,color:"#16a34a"}):e.status==="blocked"?t.jsx(Xt,{size:16,color:"#ef4444"}):t.jsx(Xt,{size:16,color:"#d97706"})}function Ze({kind:e}){return e==="sql_cell"?t.jsx(an,{size:14}):e==="dql_block_draft"?t.jsx(ct,{size:14}):e==="app_draft"||e==="app_proposal"?t.jsx(Jt,{size:14}):e==="research_run"?t.jsx(ot,{size:14}):t.jsx(Qe,{size:14})}function js({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":xn(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 zr({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(sn,{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(ge,{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(sn,{evaluation:s,t:n},s.id))})]}):null]})}function sn({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 Yt({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 Ss(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 Rr({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(lt,{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=Ss(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,". ",pr[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(nr,{size:10}):r.status==="repaired"?t.jsx(Et,{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(sn,{evaluation:s,t:n},s.id))}):null]},r.id)})})]})}function ws(e){if(e==="research")return"research";if(e==="sql_cell")return"sql";if(e==="dql_block_draft")return"block";if(e==="app_build")return"app";if(e==="certified_answer"||e==="semantic_answer"||e==="generated_answer")return"ask"}function ks(e,n){return n==="sql_cell"?`Create a SQL cell for: ${e.question}`:n==="dql_block_draft"?`Create a DQL block draft for: ${e.question}`:n==="app_build"?`Build an app for: ${e.question}`:n==="research"?`Research deeper: ${e.question}`:e.question}function Vn(e){return`${e}_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function Ye(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 Ie(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 As(e,n){const r=i=>i.toLowerCase().replace(/[\s.,!?'"()`*_-]+/g," ").trim();return r(e)===r(n)}function We(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(c=>!!(c&&typeof c=="object")):[],u=Array.isArray(o.columns)&&o.columns.length>0?o.columns.map(c=>typeof c=="string"?c:(c==null?void 0:c.name)??String(c)):a.length>0?Object.keys(a[0]):[];if(!(a.length===0&&u.length===0&&typeof o.rowCount!="number"))return{columns:u,rows:a,rowCount:typeof o.rowCount=="number"?o.rowCount:a.length,...typeof o.executionTime=="number"?{executionTime:o.executionTime}:{}}}}function Oe(e,n){const r=e.result&&typeof e.result=="object"?e.result:void 0,i=r!=null&&r.chartConfig&&typeof r.chartConfig=="object"?r.chartConfig:e.chartConfig&&typeof e.chartConfig=="object"?e.chartConfig:{},s=typeof e.suggestedViz=="string"?e.suggestedViz:typeof(r==null?void 0:r.suggestedViz)=="string"?r.suggestedViz:void 0,o=i.decisionSource==="authored"||i.decisionSource==="agent"||i.decisionSource==="data"||i.decisionSource==="user"?i.decisionSource:void 0,a=typeof i.chart=="string"?i.chart:s,u=a?a.toLowerCase().replace(/_/g,"-")==="single-value"?"kpi":a:void 0,c=n.columns,j=d=>typeof i[d]=="string"&&c.includes(i[d])?i[d]:void 0,g=Array.isArray(i.metrics)?i.metrics.filter(d=>typeof d=="string"&&c.includes(d)):[],l={...u?{chart:u}:{},...u?{decisionSource:o??"agent"}:{},...typeof i.rationale=="string"?{rationale:i.rationale}:{},...j("x")?{x:j("x")}:{},...j("y")?{y:j("y")}:{},...g.length>0?{metrics:g}:{},...j("color")?{color:j("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 Ir(e,n){var i;const r=Oe(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 ut(e){const n=Je(e.dqlArtifact);if(n)return n;const r=e.researchRun&&typeof e.researchRun=="object"&&!Array.isArray(e.researchRun)?e.researchRun:void 0;return Je(r==null?void 0:r.dqlArtifact)}function _r(e){return e?"View compiled SQL preview":"View SQL preview"}function zt({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(it,{size:12}):t.jsx(ir,{size:12}),i?"Copied":null]})}function se(e){return e.payload&&typeof e.payload=="object"&&!Array.isArray(e.payload)?e.payload:{}}function qs(e){var i,s,o;const n=[],r=new Set;for(const a of e.artifacts){const u=se(a),c=Array.isArray(u.memoryContext)?u.memoryContext:[];for(const g of c){if(!g||typeof g!="object")continue;const l=g,d=typeof l.title=="string"?l.title.trim():"";!d||r.has(`m:${d}`)||(r.add(`m:${d}`),n.push({kind:"memory",id:typeof l.id=="string"?l.id:void 0,label:d,detail:typeof l.content=="string"?l.content:void 0}))}const j=Array.isArray(u.appliedHints)?u.appliedHints:[];for(const g of j){if(!g||typeof g!="object")continue;const l=g,d=typeof l.title=="string"?l.title.trim():"";if(!d||r.has(`h:${d}`))continue;r.add(`h:${d}`);const y=typeof((i=l.lesson)==null?void 0:i.rule)=="string"?l.lesson.rule:typeof l.guidance=="string"?l.guidance:void 0,m=[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,x=typeof((o=l.matchSignals)==null?void 0:o.graphScore)=="number"?l.matchSignals.graphScore:void 0,z=v!==void 0||x!==void 0?`Signals: lexical ${(v??0).toFixed(2)}, graph ${(x??0).toFixed(2)}`:void 0;n.push({kind:"hint",id:typeof l.hintId=="string"?l.hintId:void 0,label:d,detail:[y,m?`Matched: ${m}`:void 0,z].filter(Boolean).join(" · ")||void 0})}}return n.slice(0,6)}function Tr({run:e,t:n}){const[r,i]=f.useState(!1),[s,o]=f.useState(new Set),a=f.useMemo(()=>qs(e).filter(c=>!c.id||!s.has(c.id)),[e,s]);if(a.length===0)return null;const u=async c=>{try{await te.deleteAgentMemory(c),o(j=>new Set(j).add(c))}catch{}};return t.jsxs("div",{style:{display:"grid",gap:6,gridTemplateColumns:"minmax(0, 1fr)",minWidth:0},children:[t.jsxs("button",{type:"button",onClick:()=>i(c=>!c),style:Cs(n),children:[t.jsx(qt,{size:11}),t.jsxs("span",{children:["Applied ",a.length," learning",a.length>1?"s":""]}),r?t.jsx(rr,{size:11}):t.jsx(Tt,{size:11})]}),r?t.jsxs("div",{style:zs(n),children:[a.map(c=>t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-start"},children:[t.jsx("span",{style:Rs(n,c.kind),children:c.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:c.label}),c.detail?t.jsx("div",{style:{fontSize:11,color:n.textMuted,lineHeight:1.4,marginTop:1},children:c.detail}):null]}),c.kind==="memory"&&c.id?t.jsx("button",{type:"button",onClick:()=>void u(c.id),style:Is(n),children:"Stop using"}):null]},`${c.kind}:${c.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 hn(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=se(o);o.ref&&s(o.ref,i);const u=a.plan&&typeof a.plan=="object"?a.plan:void 0;Array.isArray(u==null?void 0:u.sources)&&u.sources.forEach(c=>s(c,i)),s(a.sourceCertifiedBlock,!0)}return n.slice(0,4)}function Te(e){for(const n of e.artifacts){const r=se(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=Je(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 we(e){for(const n of e.artifacts){const r=se(n),i=Je(r.dqlArtifact);if(i)return i;const s=r.researchRun&&typeof r.researchRun=="object"&&!Array.isArray(r.researchRun)?r.researchRun:void 0,o=Je(s==null?void 0:s.dqlArtifact);if(o)return o}}function Rt(e){const n=e.route==="dql_block_draft"&&e.status!=="blocked"&&e.status!=="needs_clarification";if(e.route==="certified_answer"||!dt(e)&&!n)return;const r=we(e),i=Te(e);if(!((!(r!=null&&r.source)||r.sourcePath)&&!i)){for(const s of e.artifacts){const o=se(s),a=We(o),u=Wt(o);if(a)return{sql:i,dqlArtifact:r,result:a,chartConfig:Oe(o,a),title:(r==null?void 0:r.name)??s.title??e.question,mixedSourcePlan:u,sourceRunId:e.id,question:e.question,executionTarget:e.executionTarget};if(u)return{sql:i,dqlArtifact:r,title:(r==null?void 0:r.name)??s.title??e.question,mixedSourcePlan:u,sourceRunId:e.id,question:e.question,executionTarget:e.executionTarget}}return{sql:i,dqlArtifact:r,title:(r==null?void 0:r.name)??e.question,sourceRunId:e.id,question:e.question,executionTarget:e.executionTarget}}}function Wt(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 Br(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 Cs(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 zs(e){return{display:"grid",gap:8,padding:10,borderRadius:8,background:e.cellBg,border:`1px solid ${e.headerBorder}`}}function Rs(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 Is(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 _s(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 Gn(e){return{..._s(e),width:40,height:40}}function It(e){return{...$t(e,{variant:"secondary",size:"md",pill:!0}),fontWeight:550}}function Ts(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 Kn(e,n){return{...$t(e,{variant:n?"primary":"secondary",size:"lg"}),...n?{}:{color:e.textMuted}}}function Un(e){return{border:"none",background:e.accent,color:"#fff",borderRadius:8,padding:"7px 13px",display:"inline-flex",alignItems:"center",gap:6,fontSize:12,fontWeight:700,fontFamily:e.font,cursor:"pointer",boxShadow:`0 1px 5px ${e.accent}4d`}}function Bs(e){return{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:41,width:264,background:e.cellBg,border:`1px solid ${e.headerBorder}`,borderRadius:10,boxShadow:"0 12px 32px rgba(0,0,0,0.2)",padding:10}}function $s(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 Yn(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 Es(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 Ms(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 Ls(e){return{alignSelf:"flex-start",maxWidth:"92%",color:e.textPrimary,border:`1px solid ${e.cellBorder}`,background:e.appBg,borderRadius:10,padding:"10px 12px"}}function Ws(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 on(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 Fs(e){return{border:`1px solid ${e.headerBorder}`,background:e.cellBg,borderRadius:8,padding:9,fontSize:12.5,color:e.textPrimary,lineHeight:1.45}}function at(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 Jn(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 J(e){return $t(e,{variant:"secondary",size:"sm"})}const _t={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 $r(e){var n,r,i;for(const s of e.artifacts??[]){const o=se(s),a=(n=o==null?void 0:o.warehouseFailure)==null?void 0:n.origin;if(typeof a=="string"&&a in _t)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 Ps(e){var n,r;if(e.status!=="blocked"||!Te(e)&&!((n=we(e))!=null&&n.source))return!1;for(const i of e.artifacts??[]){const s=se(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 Ds({run:e,detail:n,threadId:r,onRepaired:i,t:s}){const o=$r(e),a=_t[o]??_t.unknown,[u,c]=f.useState(!1),[j,g]=f.useState(null),l=Ps(e),d=async()=>{if(!u){c(!0),g(null);try{const y=await te.repairAgentRunExecution(e.id,r);i(y.run)}catch(y){g(y instanceof Error?y.message:String(y))}finally{c(!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:Ie(n)}),t.jsx("div",{style:{fontSize:11.5,lineHeight:1.5,color:s.textMuted},children:a.hint}),l?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap",marginTop:2},children:[t.jsxs("button",{type:"button",className:"dql-hover",disabled:u,onClick:()=>void d(),style:{...J(s),opacity:u?.7:1},children:[t.jsx(Et,{size:12})," ",u?"Fixing and retrying…":"Fix and retry"]}),t.jsx("span",{style:{fontSize:10.5,color:s.textMuted},children:"One bounded repair attempt on the same data target."})]}):null,j?t.jsx("div",{role:"alert",style:{fontSize:11.5,lineHeight:1.45,color:s.error},children:Ie(j)}):null]})}function Er(e){var n,r;for(const i of e.artifacts??[]){const s=se(i),o=s==null?void 0:s.warehouseFailure,a=[o==null?void 0:o.redactedMessage,o==null?void 0:o.diagnostic,s==null?void 0:s.executionError].find(u=>typeof u=="string"&&u.trim().length>0);if(a)return a}return e.summary||((r=(n=e.diagnosticReceipt)==null?void 0:n.failure)==null?void 0:r.message)}const no=Object.freeze(Object.defineProperty({__proto__:null,ASK_FAILURE_PRESENTATION:_t,UnifiedAgentRunPanel:Zi,agentRunHistoryFromItems:ur,analyticalInspectorContract:wr,analyticalInspectorSections:ps,analyticalRepairActionLabels:fs,appPinDestinationLabel:nn,artifactReadyPayloadFromRun:Rt,artifactSqlDisclosureLabel:_r,askArtifactMeta:Mt,askFailureDetail:Er,askFailureOrigin:$r,askInspectorTabsForState:br,clarificationSelectionInput:wt,completedRunGuidanceFor:yr,deriveResultChartConfig:Zr,hasAnalyticalInspectorContract:Lt,inlineAskChartConfig:Ir,isAgentRunPinnable:dt,liveAgentActivityFor:mr,longRunGuidanceFor:hr,preferredAskInspectorTab:pn,replacePresentedAgentRun:dr,researchSourceFromRun:kr,resolveArtifactDqlView:ut,resolvedParameterValues:rn,selectAgentExecutionConnection:gr,threadItemsFromTurns:xr,trustExplainer:gn,usePersistedAgentThreadId:ri},Symbol.toStringTag,{value:"Module"}));export{Ei as B,hi as E,Tn as S,Zi as U,Ai as a,Ti as b,no as c};
@@ -1,6 +0,0 @@
1
- import{c as o}from"./index-1mIC_XX4.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 c=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],n=o("chevron-up",c);export{n as C};
@@ -1,6 +0,0 @@
1
- import{c as e}from"./index-1mIC_XX4.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 o=[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]],n=e("link-2",o);export{n as L};
@@ -1,6 +0,0 @@
1
- import{c as t}from"./index-1mIC_XX4.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 a=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]],i=t("maximize-2",a);export{i as M};
@@ -1,6 +0,0 @@
1
- import{c as a}from"./index-1mIC_XX4.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 c=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]],o=a("pencil",c);export{o as P};