@duckcodeailabs/dql-cli 1.14.1 → 1.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/dql-notebook/assets/{AgentLogPage-BPz-UWFh.js → AgentLogPage-DKbGpRQS.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildDialog-BEl53WA_.js → AiBuildDialog-DPSu0Mly.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildResult-B4yfGTTZ.js → AiBuildResult-1uaGnpi1.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiSidePanel-CSZAAvuD.js → AiSidePanel-BwMREwa7.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AnalyticsHome-D5P6Ujwi.js → AnalyticsHome-BGfey_ve.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AppsView-DQOwU9Cg.js → AppsView-CM1tPywy.js} +4 -4
- package/dist/assets/dql-notebook/assets/{BlockStudio-B4ap0GdY.js → BlockStudio--S6WFVO4.js} +1 -1
- package/dist/assets/dql-notebook/assets/{BusinessArtifactView-BIfNI-0S.js → BusinessArtifactView-BEAJ-yNW.js} +1 -1
- package/dist/assets/dql-notebook/assets/{DbtFirstModelingPage-D72byb2g.js → DbtFirstModelingPage-CNyU5MBX.js} +1 -1
- package/dist/assets/dql-notebook/assets/{GitPage-lQb1uXH2.js → GitPage-IcydAai3.js} +1 -1
- package/dist/assets/dql-notebook/assets/{GlobalAiRail-CVECf6Xj.js → GlobalAiRail-CSKW-5eD.js} +1 -1
- package/dist/assets/dql-notebook/assets/{GovernedContextPage-trOyMCY6.js → GovernedContextPage-CFen0eFT.js} +1 -1
- package/dist/assets/dql-notebook/assets/{HelpDocsPage-D8hLS5lE.js → HelpDocsPage-D0D9UCIz.js} +1 -1
- package/dist/assets/dql-notebook/assets/{HomePage-eIkfBIep.js → HomePage-CmSxapR3.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDAG-CSqcbDrE.js → LineageDAG-BGUcIt1B.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDetailView-DJZZjZu-.js → LineageDetailView-Dx48Zfzb.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDrawer-BcIipIc3.js → LineageDrawer-zaBfSLZO.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineagePathBreadcrumb-CviIf8PN.js → LineagePathBreadcrumb-CTZJp4_r.js} +1 -1
- package/dist/assets/dql-notebook/assets/{MiniLineageGraph-vH_MY_Ju.js → MiniLineageGraph-CdivNR1S.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewBlockModal-DbCQg-pj.js → NewBlockModal-DMBFB7nE.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewNotebookModal-5Vp6XiuK.js → NewNotebookModal-DsC9CWlW.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NotebookEditor-DjqJS44s.js → NotebookEditor-hs-kw8v9.js} +1 -1
- package/dist/assets/dql-notebook/assets/{ReadinessPage-BHGrC5ho.js → ReadinessPage-DJ83cMik.js} +1 -1
- package/dist/assets/dql-notebook/assets/{SetupOnboarding-BfS9Tdx-.js → SetupOnboarding-B1Pu_Bvv.js} +1 -1
- package/dist/assets/dql-notebook/assets/{SkillsPage-BFH21wSj.js → SkillsPage-BHKDay8n.js} +1 -1
- package/dist/assets/dql-notebook/assets/{TrustBadge-zm6g_SxZ.js → TrustBadge-BkyGgob2.js} +1 -1
- package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-BYdrTaEW.js +89 -0
- package/dist/assets/dql-notebook/assets/{answer-to-notebook-DPhxIEzF.js → answer-to-notebook-DmNiuLQA.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-left-DNEb86Xc.js → arrow-left--1rsrxm8.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-right-DpPWbwaD.js → arrow-right-D5TdqY1G.js} +1 -1
- package/dist/assets/dql-notebook/assets/{book-open-text-D7s5jo4X.js → book-open-text-Bw7nHbzg.js} +1 -1
- package/dist/assets/dql-notebook/assets/{circle-x-Db3dXKg7.js → circle-x-DLe6NNM4.js} +1 -1
- package/dist/assets/dql-notebook/assets/{dagre.esm-C7pppQ1a.js → dagre.esm-CW5QZdBt.js} +1 -1
- package/dist/assets/dql-notebook/assets/{external-link-BxwXitO_.js → external-link-C9Q97sA3.js} +1 -1
- package/dist/assets/dql-notebook/assets/{grip-vertical-Dt4lkWRi.js → grip-vertical-CztvkIgo.js} +1 -1
- package/dist/assets/dql-notebook/assets/{index-DKo-bwNw.js → index-zHHzDn6l.js} +127 -127
- package/dist/assets/dql-notebook/assets/{link-2-Dfo2P6wi.js → link-2-CiKAvumL.js} +1 -1
- package/dist/assets/dql-notebook/assets/{list-tree-DiTmIWAL.js → list-tree-BtnP2nQ5.js} +1 -1
- package/dist/assets/dql-notebook/assets/{minimize-2-CMTAkPzL.js → minimize-2-TSFGxcCP.js} +1 -1
- package/dist/assets/dql-notebook/assets/{panel-right-open-DwYr7FW4.js → panel-right-open-BfXIUWy0.js} +1 -1
- package/dist/assets/dql-notebook/assets/{play-BXhHYQ4x.js → play-DVbSFJHD.js} +1 -1
- package/dist/assets/dql-notebook/assets/{rotate-ccw-BNi6F8pl.js → rotate-ccw-D_cesDcX.js} +1 -1
- package/dist/assets/dql-notebook/assets/{semantic-fields-CNOGysAy.js → semantic-fields-CoVStdYB.js} +1 -1
- package/dist/assets/dql-notebook/assets/{sliders-horizontal-Ec5MUMUW.js → sliders-horizontal-l7xV9K5A.js} +1 -1
- package/dist/assets/dql-notebook/assets/{star-B9leDkp_.js → star-CSBS0H3b.js} +1 -1
- package/dist/assets/dql-notebook/assets/{triangle-alert-BefTYCzx.js → triangle-alert-BTrnyY4q.js} +1 -1
- package/dist/assets/dql-notebook/assets/{upload-SPiOM2tQ.js → upload-sySLq9zb.js} +1 -1
- package/dist/assets/dql-notebook/assets/{usePersistedAgentThreadId-C4foXeiQ.js → usePersistedAgentThreadId-CzwgGdus.js} +1 -1
- package/dist/assets/dql-notebook/assets/{user-round-comGmyw-.js → user-round-ChlgXi9j.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wand-sparkles-BffR4dF8.js → wand-sparkles-CGw0ytyT.js} +1 -1
- package/dist/assets/dql-notebook/assets/{workflow-ChmPTEzH.js → workflow-C_RltiK5.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wrench-DovaG_ze.js → wrench-D-wLfeu0.js} +1 -1
- package/dist/assets/dql-notebook/assets/{x-nRx91AgW.js → x-B28hIJIC.js} +1 -1
- package/dist/assets/dql-notebook/index.html +1 -1
- package/dist/commands/agent-eval-cassette.d.ts +97 -6
- package/dist/commands/agent-eval-cassette.d.ts.map +1 -1
- package/dist/commands/agent-eval-cassette.js +165 -22
- package/dist/commands/agent-eval-cassette.js.map +1 -1
- package/dist/commands/agent-eval-runtime.d.ts +14 -2
- package/dist/commands/agent-eval-runtime.d.ts.map +1 -1
- package/dist/commands/agent-eval-runtime.js +12 -2
- package/dist/commands/agent-eval-runtime.js.map +1 -1
- package/dist/commands/agent.d.ts +9 -3
- package/dist/commands/agent.d.ts.map +1 -1
- package/dist/commands/agent.js +126 -49
- package/dist/commands/agent.js.map +1 -1
- package/dist/commands/compile.d.ts +13 -1
- package/dist/commands/compile.d.ts.map +1 -1
- package/dist/commands/compile.js +36 -4
- package/dist/commands/compile.js.map +1 -1
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +11 -3
- package/dist/commands/sync.js.map +1 -1
- package/dist/llm/providers/dql-agent-provider.d.ts +28 -1
- package/dist/llm/providers/dql-agent-provider.d.ts.map +1 -1
- package/dist/llm/providers/dql-agent-provider.js +272 -22
- package/dist/llm/providers/dql-agent-provider.js.map +1 -1
- package/dist/llm/types.d.ts +29 -1
- package/dist/llm/types.d.ts.map +1 -1
- package/dist/local-runtime.d.ts +16 -1
- package/dist/local-runtime.d.ts.map +1 -1
- package/dist/local-runtime.js +824 -66
- package/dist/local-runtime.js.map +1 -1
- package/dist/package.json +10 -10
- package/package.json +10 -10
- package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel--oxmjlgr.js +0 -88
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import{c as _e,r as g,a as se,j as t,d as Ut,g as bt,l as je,b7 as hi,f as vt,L as Ve,aK as xi,ba as mr,B as wt,e as br,u as Gt,t as vr,a5 as yi,bb as Ge,E as mi,H as bi,bc as vi,w as ji,S as Ue,aH as jr,b as Kt,b9 as tt,P as ht,D as Si,G as Sr,bd as wi,be as ki,b0 as un,a0 as nn,ar as Ci}from"./index-zHHzDn6l.js";import{S as Pt,P as Ai,F as nt,E as Ri,M as qi,R as vn,d as jn,e as Ii,A as _i,g as zi,u as Ti}from"./usePersistedAgentThreadId-CzwgGdus.js";import{C as Mi}from"./AiBuildResult-1uaGnpi1.js";import{T as rn}from"./triangle-alert-BTrnyY4q.js";import{U as Ei}from"./user-round-ChlgXi9j.js";import{X as Ft}from"./x-B28hIJIC.js";import{L as jt}from"./list-tree-BtnP2nQ5.js";import{W as Yt}from"./wrench-D-wLfeu0.js";import{M as $i}from"./minimize-2-TSFGxcCP.js";import{A as Bi}from"./arrow-right-D5TdqY1G.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 Li=[["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"}]],Di=_e("archive",Li);/**
|
|
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 Ni=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],wr=_e("chevron-up",Ni);/**
|
|
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 Pi=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],Fi=_e("circle",Pi);/**
|
|
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 Wi=[["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"}]],kr=_e("copy",Wi);/**
|
|
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 Oi=[["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"}]],Wt=_e("lightbulb",Oi);/**
|
|
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 Hi=[["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",Hi);/**
|
|
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 Qi=[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]],Sn=_e("save",Qi);/**
|
|
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=[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]],Ui=_e("send",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 Gi=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],On=_e("square",Gi);/**
|
|
47
|
+
* @license lucide-react v0.563.0 - ISC
|
|
48
|
+
*
|
|
49
|
+
* This source code is licensed under the ISC license.
|
|
50
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
51
|
+
*/const Ki=[["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"}]],Yi=_e("zap",Ki),sn=[{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 Hn({t:e,value:n,onChange:r}){const[i,s]=g.useState(null),[o,a]=g.useState(!1),c=g.useRef(null);g.useEffect(()=>{let h=!1;return se.getProviderSettings().then(({providers:l})=>{h||s(l.find(u=>u.active)??null)}).catch(()=>{}),()=>{h=!0}},[]),g.useEffect(()=>{if(!o)return;const h=l=>{c.current&&!c.current.contains(l.target)&&a(!1)};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[o]);const d=sn.find(h=>h.mode===n)??sn[0],p=i?[i.label,i.model].filter(Boolean).join(" · "):null;return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[p?t.jsxs("span",{title:"Connected model",style:Qn(e),children:[t.jsx(Fi,{size:7,fill:e.success,color:e.success}),t.jsx("span",{style:{color:e.textSecondary},children:p})]}):null,t.jsxs("div",{ref:c,style:{position:"relative"},children:[t.jsxs("button",{type:"button",onClick:()=>a(h=>!h),title:"How hard the model thinks for this thread",style:{...Qn(e),cursor:"pointer"},children:[t.jsx(Yi,{size:12,color:e.textMuted}),t.jsxs("span",{style:{color:e.textSecondary},children:["Thinking: ",d.label]}),t.jsx(Ut,{size:12,color:e.textMuted})]}),o?t.jsx("div",{role:"menu",style:Xi(e),children:sn.map(h=>{const l=h.mode===n;return t.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":l,onClick:()=>{r(h.mode),a(!1)},style:Ji(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:h.label}),l?t.jsx(bt,{size:13,color:e.accent}):null]}),t.jsx("span",{style:{display:"block",fontSize:11,color:e.textMuted,marginTop:2},children:h.hint})]},h.mode)})}):null]})]})}function Qn(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 Xi(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 Ji(e,n){return{display:"block",width:"100%",textAlign:"left",padding:"8px 10px",borderRadius:7,border:"none",background:n?e.pillBg:"transparent",cursor:"pointer"}}const Zi={draft:"#8b949e",review:"#d29922",certified:"#3fb950",deprecated:"#f85149",pending_recertification:"#db6d28"},es={queued:"#8b949e",generating:"#4c8dff",running:"#4c8dff",saving:"#4c8dff",saved:"#2ea043",ready:"#2ea043",blocked:"#f85149",needs_attention:"#d29922"},ts={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"},ns={draft:mr,queued:xi,generating:Ve,running:Ve,saving:Ve,ready:vt,saved:vt,blocked:rn,needs_attention:rn,review:hi,certified:je,deprecated:Di,pending_recertification:rn},rs=new Set(["generating","running","saving"]);function is(e){return Zi[e]??es[e]??"#8b949e"}function ss(e){return ts[e]??e.charAt(0).toUpperCase()+e.slice(1).replace(/_/g," ")}function os({status:e,t:n,label:r}){const i=is(e),s=ns[e]??mr,o=r??ss(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:rs.has(e)?"spin":void 0}),o]})}function as(e){const{t:n,name:r,status:i="draft",description:s,dql:o,sqlPreview:a,grain:c,outputs:d=[],dimensions:p=[],entities:h=[],examples:l=[],sourceTables:u=[],evidence:f=[],certifierVerdict:x,owner:m,actions:v}=e,[A,H]=g.useState(!1),[D,F]=g.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(wt,{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(os,{status:i,t:n}),c?t.jsxs("span",{style:pn(n),children:["grain ",c]}):null]}),s?t.jsx("div",{style:{fontSize:12,color:n.textSecondary,lineHeight:1.5},children:s}):null,o?t.jsx(Vn,{open:A,onToggle:()=>H(q=>!q),label:"Governed DQL",t:n,lead:!0,children:t.jsx("pre",{style:Un(n),children:o})}):null,a?t.jsx(Vn,{open:D,onToggle:()=>F(q=>!q),label:o?"Compiled SQL preview":"SQL this block will run",t:n,children:t.jsx("pre",{style:Un(n),children:a})}):null,t.jsx(on,{label:"Outputs",items:d,t:n}),t.jsx(on,{label:"Dimensions",items:p,t:n}),t.jsx(on,{label:"Entities",items:h,t:n}),l.length>0?t.jsxs("div",{style:{display:"grid",gap:5},children:[t.jsx(Cr,{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,u.length>0||f.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(je,{size:12,color:n.accent})," Grounded on"]}),u.length>0?t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:u.map(q=>t.jsx("span",{style:pn(n),children:q},q))}):null,f.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(Mi,{t:n,verdict:x}),m?t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11,color:n.textMuted},children:[t.jsx(Ei,{size:12,strokeWidth:2})," drafting as ",m]}):null,v?t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:v}):null]})}function Vn({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(Ut,{size:13,strokeWidth:2}):t.jsx(br,{size:13,strokeWidth:2}),e?`Hide ${r.toLowerCase()}`:r]}),e?t.jsx("div",{style:{marginTop:7},children:o}):null]})}function on({label:e,items:n,t:r}){return n.length===0?null:t.jsxs("div",{style:{display:"grid",gap:5},children:[t.jsx(Cr,{t:r,children:e}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:n.map(i=>t.jsx("span",{style:pn(r),children:i},i))})]})}function Cr({t:e,children:n}){return t.jsx("div",{style:{fontSize:10,fontWeight:800,letterSpacing:"0.05em",textTransform:"uppercase",color:e.textMuted},children:n})}function pn(e){return{fontSize:10.5,fontWeight:700,color:e.textSecondary,background:e.pillBg,borderRadius:999,padding:"2px 8px",fontFamily:e.fontMono}}function Un(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 Gn(){return t.jsx("span",{style:{color:"#ff7b72",marginLeft:2},children:"*"})}function an(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function ls(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 Kn({cell:e,onClose:n,onSaved:r,initialContent:i,initialName:s,initialDescription:o,initialTags:a,initialDomain:c,initialOwner:d}){var te;const{state:p,dispatch:h}=Gt(),l=vr[p.themeMode],u=g.useRef(null),[f,x]=g.useState(s||e.name||"new_block"),[m,v]=g.useState(c??""),[A,H]=g.useState(d??""),[D,F]=g.useState(o??p.notebookMetadata.description??""),[q,N]=g.useState((a??p.notebookMetadata.categories??[]).join(", ")),[V,P]=g.useState(i??e.content),[M,X]=g.useState(""),[J,I]=g.useState(""),[E,_]=g.useState([]),[b,$]=g.useState(!1),[U,K]=g.useState(null),L=g.useMemo(()=>ls(V),[V]),G=g.useMemo(()=>q.split(",").map(w=>w.trim()).filter(Boolean),[q]),re=[{id:"has-name",label:"Block has name",severity:"error",passed:!!f.trim()},{id:"has-owner",label:"Block has owner",severity:"error",passed:!!A.trim()},{id:"has-description",label:"Description",severity:"warning",passed:!!D.trim()},{id:"has-domain",label:"Domain",severity:"warning",passed:!!m.trim()},{id:"has-tags",label:"Has at least one tag",severity:"warning",passed:G.length>0},{id:"has-llm-context",label:"Has LLM context (for agents)",severity:"warning",passed:!!M.trim()}],ee=re.some(w=>w.severity==="error"&&!w.passed);g.useEffect(()=>{var w;(w=u.current)==null||w.focus()},[]),g.useEffect(()=>{const w=B=>{B.key==="Escape"&&n()};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[n]);const pe=yi(m,p.authoredDomains),ce=`${m.trim()?`blocks/${an(m)}/`:"blocks/"}${an(f)||"new-block"}.dql`,Y=async()=>{var w,B,ie;if(ee){K("Enter the block name and owner before saving.");return}if(!V.trim()){K("Block content is required.");return}$(!0),K(null);try{const R=J.split(`
|
|
52
|
+
`).map(Se=>Se.trim()).filter(Boolean),ne=E.map(Se=>({question:Se.question.trim(),sql:Se.sql.trim()||void 0})).filter(Se=>Se.question),xe=await se.saveAsBlock({cellId:e.id,notebookPath:((w=p.activeFile)==null?void 0:w.path)??null,name:f.trim(),domain:m.trim()||void 0,owner:A.trim()||void 0,content:V,description:D.trim()||void 0,tags:G,metricRefs:L,llmContext:M.trim()||void 0,examples:ne.length>0?ne:void 0,invariants:R.length>0?R:void 0,reviewRequired:!!((B=e.datasetRefs)!=null&&B.length),datasetRefs:e.datasetRefs,lineage:(ie=e.dqlArtifact)==null?void 0:ie.lineage}),Ke={name:`${an(f)||"new-block"}.dql`,path:xe.path,type:"block",folder:"blocks"};p.files.some(Se=>Se.path===xe.path)||h({type:"FILE_ADDED",file:Ke});const Re=await se.openBlockStudio(xe.path);h({type:"OPEN_BLOCK_STUDIO",file:Ke,payload:Re}),r==null||r({...xe,name:f.trim()}),n()}catch(R){K(R instanceof Error?R.message:String(R))}finally{$(!1)}},S={width:"100%",background:l.inputBg,border:`1px solid ${U?l.error:l.inputBorder}`,borderRadius:6,color:l.textPrimary,fontSize:13,fontFamily:l.font,padding:"8px 12px",outline:"none",boxSizing:"border-box"};return t.jsx("div",{onClick:w=>{w.target===w.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(Gn,{})]}),t.jsx("input",{ref:u,value:f,onChange:w=>x(w.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:m,onChange:w=>v(w.target.value),style:S,children:[t.jsx("option",{value:"",children:"Global / cross-domain"}),pe.map(w=>t.jsx("option",{value:w.value,disabled:w.disabled,children:w.label},w.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(Gn,{})]}),t.jsx("input",{value:A,onChange:w=>H(w.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:w=>N(w.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:D,onChange:w=>F(w.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:M,onChange:w=>X(w.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:J,onChange:w=>I(w.target.value),rows:2,placeholder:`Revenue is never negative
|
|
53
|
+
Each row is a unique month`,style:{...S,fontFamily:l.fontMono,lineHeight:1.5,resize:"vertical"}})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:"Example questions (grounding for chat cells)"}),E.map((w,B)=>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:w.question,onChange:ie=>{const R=[...E];R[B]={...R[B],question:ie.target.value},_(R)},placeholder:"What was revenue last month?",style:S}),t.jsx("input",{value:w.sql,onChange:ie=>{const R=[...E];R[B]={...R[B],sql:ie.target.value},_(R)},placeholder:"Optional SQL snippet",style:{...S,fontFamily:l.fontMono,fontSize:12}})]}),t.jsx("button",{type:"button",onClick:()=>_(E.filter((ie,R)=>R!==B)),style:{background:"transparent",border:`1px solid ${l.cellBorder}`,borderRadius:6,color:l.textMuted,cursor:"pointer",fontSize:12,padding:"0 10px"},children:"×"})]},B)),t.jsx("button",{type:"button",onClick:()=>_([...E,{question:"",sql:""}]),style:{alignSelf:"flex-start",background:l.btnBg,border:`1px solid ${l.btnBorder}`,borderRadius:6,color:l.textSecondary,cursor:"pointer",fontSize:12,fontFamily:l.font,padding:"4px 10px"},children:"+ Add example"})]})]})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6,padding:"10px 12px",background:l.pillBg,borderRadius:6,border:`1px solid ${l.cellBorder}`},children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:l.textSecondary,fontFamily:l.font,letterSpacing:"0.06em",textTransform:"uppercase"},children:"Governance checks"}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:re.map(w=>{const B=w.passed?"#3fb950":w.severity==="error"?"#ff7b72":"#e3b341",ie=w.passed?"✓":w.severity==="error"?"✕":"!";return t.jsxs("span",{title:w.passed?`${w.label} — passed`:`${w.label} — ${w.severity}`,style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,fontFamily:l.font,color:B,background:`${B}18`,border:`1px solid ${B}55`,borderRadius:999,padding:"2px 10px"},children:[t.jsx("span",{style:{fontWeight:700},children:ie}),w.label]},w.id)})})]}),t.jsx("div",{style:{fontSize:12,color:l.textMuted,fontFamily:l.fontMono,padding:"8px 12px",background:l.pillBg,borderRadius:6},children:ce}),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:V,onChange:w=>P(w.target.value),style:{...S,minHeight:220,resize:"vertical",fontFamily:l.fontMono,lineHeight:1.5}})]}),L.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:"}),L.map(w=>t.jsx("span",{style:{fontSize:11,color:l.accent,fontFamily:l.fontMono,background:`${l.accent}18`,borderRadius:999,padding:"2px 8px"},children:w},w))]}),U&&t.jsx("div",{style:{fontSize:12,color:l.error,fontFamily:l.font},children:U})]}),t.jsxs("div",{style:{padding:"14px 24px",borderTop:`1px solid ${l.cellBorder}`,display:"flex",justifyContent:"flex-end",gap:10},children:[t.jsx("span",{style:{fontSize:11.5,color:l.textMuted,marginRight:"auto",alignSelf:"center"},children:(te=e.datasetRefs)!=null&&te.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:Y,disabled:b||ee,title:ee?"Fix governance errors to enable Save":void 0,style:{background:l.accent,border:`1px solid ${l.accent}`,borderRadius:6,color:"#fff",cursor:b||ee?"not-allowed":"pointer",fontSize:13,fontFamily:l.font,padding:"7px 20px",opacity:b||ee?.5:1},children:b?"Saving & checking…":"Save block"})]})]})})}function Ar(e){return e.policy==="dynamic"||e.policy==="optional"}function cs({parameters:e,values:n,onChange:r,onReset:i,t:s,includeNonRuntime:o=!1,card:a=!1}){const c=e.filter(d=>o||Ar(d));return c.length===0?null:t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(170px, 1fr))",gap:8},children:c.map(d=>{const p=Object.prototype.hasOwnProperty.call(n,d.name),h=p?n[d.name]:d.default,l=f=>r(d.name,f),u=d.type==="boolean"?t.jsxs("select",{"aria-label":d.name,value:String(h??""),onChange:f=>l(f.target.value),style:Yn(s),children:[t.jsx("option",{value:"",children:"Select…"}),t.jsx("option",{value:"true",children:"True"}),t.jsx("option",{value:"false",children:"False"})]}):t.jsx("input",{"aria-label":d.name,type:d.type==="number"?"number":d.type==="date"?"date":"text",value:Array.isArray(h)?h.join(", "):h==null?"":String(h),placeholder:d.type.endsWith("[]")?"Comma-separated values":d.required?"Required value":"Use default",onChange:f=>l(f.target.value),style:Yn(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:[ds(d.name),d.required?t.jsx("span",{style:{color:s.error},children:"*"}):null]}),u,t.jsxs("span",{style:{display:"flex",alignItems:"center",gap:5,minHeight:14,fontSize:9.5,color:s.textMuted},children:[t.jsxs("span",{children:[d.type,o?` · ${d.policy}`:""]}),p&&i?t.jsx("button",{type:"button",onClick:()=>i(d.name),style:{marginLeft:"auto",border:0,padding:0,background:"transparent",color:s.accent,fontSize:9.5,cursor:"pointer"},children:"Reset"}):null]})]},d.name)})})}function ds(e){return e.replace(/[_-]+/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function Yn(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 us(e){const n=e.filter(o=>o.kind==="run").map(ps).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=Rr(Xn(r));return fn({activeSurface:"notebook",conversationStateVersion:1,activeTurnId:r.id,activeTopic:r.question,conversationSummary:ms(n),turns:n,sourceAnswerId:r.id,sourceCertifiedBlock:r.sourceCertifiedBlock,sourceQuestion:r.question,sourceAnswerSummary:r.answerSummary,answerContract:Xn(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??Ze(s==null?void 0:s.filters),requestedDimensions:r.requestedDimensions??Ze(s==null?void 0:s.dimensions),priorLimit:r.topN??qr(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 ps(e){var l,u,f,x;const n=e.run.artifacts.find(m=>m.kind==="answer")??e.run.artifacts.find(m=>m.kind==="research_run")??e.run.artifacts[0],r=he(n==null?void 0:n.payload),i=fs(r),s=vs(i),o=Array.isArray(i==null?void 0:i.rows)?i.rows.filter(m=>!!(m&&typeof m=="object"&&!Array.isArray(m))).slice(0,24):[],a=((l=he(r==null?void 0:r.contextPack))==null?void 0:l.questionPlan)??(r==null?void 0:r.analysisPlan),c=Rr(a),d=Ss(s,o),p=bs(c,s),h=le(r==null?void 0:r.sourceCertifiedBlock)??((n==null?void 0:n.kind)==="answer"?le(n.ref):void 0)??le((u=he(r==null?void 0:r.block))==null?void 0:u.name);return fn({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:h,route:le((f=he(r==null?void 0:r.route))==null?void 0:f.label)??le((x=he(r==null?void 0:r.route))==null?void 0:x.tier),trustLabel:le(r==null?void 0:r.trustLabel),reviewStatus:le(r==null?void 0:r.reviewStatus),certification:le(r==null?void 0:r.certification),contextPackId:le(r==null?void 0:r.contextPackId),requestedFilters:Ze(c==null?void 0:c.filters),requestedDimensions:Ze(c==null?void 0:c.dimensions),requestedMeasures:Ze(c==null?void 0:c.measures),answerContract:a,dqlArtifact:xs(r),cascade:ys(r),topN:qr(c),result:s.length>0||o.length>0?fn({columns:s,rowsSample:o,dimensionValues:d,measureColumns:p,rowCount:gs(i)}):void 0,sourceSql:hs(r,i)})}function Xn(e){return e.answerContract}function Rr(e){const n=he(e);return he(n==null?void 0:n.requestedShape)}function fs(e){const n=he(e==null?void 0:e.researchRun),r=he(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(he).filter(s=>!!(s&&(Array.isArray(s.rows)||Array.isArray(s.columns)))).sort((s,o)=>Jn(o)-Jn(s))[0]}function Jn(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 gs(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 hs(e,n){var r,i;return le(e==null?void 0:e.proposedSql)??le(e==null?void 0:e.sql)??le(n==null?void 0:n.sql)??le((r=he(e==null?void 0:e.query))==null?void 0:r.sql)??le((i=he(e==null?void 0:e.plan))==null?void 0:i.sql)}function xs(e){var r,i;const n=Ge(e==null?void 0:e.dqlArtifact);return n?{...n,source:n.source.slice(0,3e3),filters:(r=n.filters)==null?void 0:r.filter(s=>s.values.length>0).slice(0,12).map(s=>({...s,values:s.values.slice(0,12)})),orderBy:(i=n.orderBy)==null?void 0:i.slice(0,8)}:void 0}function ys(e){const n=he(e==null?void 0:e.cascade);if(!n)return;const r=le(n.terminalLane),i=le(n.routeTier);if(!(!r&&!i))return{terminalLane:r,routeTier:i,label:le(n.label),ref:le(n.ref),artifactKind:le(n.artifactKind),refusalCode:le(n.refusalCode),outcome:he(n.outcome)}}function ms(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(([c,d])=>`${c}: ${d.slice(0,3).join(", ")}`).join("; "):"";return[`Q: ${r.question}`,r.answerSummary?`A: ${r.answerSummary}`:"",i?`Columns: ${i}`:"",s?`Values: ${s}`:""].filter(Boolean).join(" | ")}).filter(Boolean);return n.length>0?n.join(`
|
|
54
|
+
`):void 0}function qr(e){const n=he(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 bs(e,n){const r=[...Ze(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 he(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function vs(e){const r=(Array.isArray(e==null?void 0:e.columns)?e.columns:[]).map(js).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 Ze(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 js(e){if(typeof e=="string"&&e.trim())return e.trim();if(e&&typeof e=="object"){const n=e;return le(n.name)??le(n.field)??le(n.key)}}function Ss(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 c=he(a),d=c==null?void 0:c[s],p=typeof d=="string"||typeof d=="number"?String(d).trim():"";if(!(!p||o.includes(p))&&(o.push(p),o.length>=24))break}o.length>0&&(i[ws(s)]=o)}return Object.keys(i).length>0?i:void 0}function ws(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 le(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function fn(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 ks(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 Ir(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:Zn(n.rows.map(c=>c[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 c=Zn(n.rows.map(d=>d[a]));return[{column:a,field:s,values:c}]})}function Cs(e,n,r,i){const s=Ir(e,n).find(v=>v.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(v=>v.name)),a=As(s.field.split(".").at(-1)??s.column);let c=a,d=2;for(;o.has(c);)c=`${a}_${d++}`;const p=Array.isArray(i)?i.map(String).join(", "):String(i),h=mi(p,c);let l=bi(e.source,{name:c,type:h,required:!1,defaultText:p,policy:"dynamic"});l=vi(l,c,s.field);const u=ji(l).map(v=>{var A,H,D;return{...v,...((A=v.binding)==null?void 0:A.kind)==="semantic_filter"&&v.binding.field?{binding:{kind:"semantic_filter",field:v.binding.field,operator:v.binding.operator??"equals"}}:((H=v.binding)==null?void 0:H.kind)==="limit"?{binding:{kind:"limit"}}:((D=v.binding)==null?void 0:D.kind)==="sql_value"?{binding:{kind:"sql_value"}}:{binding:void 0}}}),{executionReceipt:f,compiledSql:x,...m}=e;return{artifact:{...m,source:l,parameters:u,parameterValues:{...e.parameterValues??{},[c]:i}},parameterName:c}}function Zn(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 As(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 _r(e){return e.modeOverride?e.modeOverride:e.pendingMode?e.pendingMode:e.researchMode?"research":e.initialMode==="research"?"ask":e.initialMode}function zr(e,n,r){return e.map(i=>i.kind==="run"&&i.run.id===n?{kind:"run",id:r.id,run:r}:i)}function Tr(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"||o.run.status==="cancelled"||o.run.stopReason==="cancelled"||((r=o.run.artifacts)==null?void 0:r.some(c=>{const d=oe(c);return!!(d.executionError||d.warehouseFailure||d.analyticalFailure)}))){((i=n.at(-1))==null?void 0:i.role)==="user"&&n.pop();continue}n.push({role:"assistant",text:((s=o.run.answer)==null?void 0:s.trim())||o.run.summary})}return n.slice(-12)}const wn="dql.agent.active-runs.v1",Mr={conversation:"Chat",certified_answer:"Certified answer",semantic_answer:"Governed semantic answer",generated_answer:"Generated answer",research:"Research plan",sql_cell:"SQL cell",dql_block_draft:"DQL block draft",modeling_draft:"Modeling proposal",skill_draft:"Skill proposal",app_build:"App plan",clarify:"Clarify",cancelled:"Stopped by user",blocked:"Blocked"};function Rs({themeMode:e,title:n="AI Copilot",scopeHint:r="Auto routes to answer, research, SQL, block, or app",composerPlaceholder:i="Ask anything about your data…",onClearScope:s,examplePrompts:o,emptyHint:a,notebookPath:c,selectedObject:d,workspaceContext:p,initialMode:h="auto",initialInput:l="",initialItems:u,onItemsChange:f,threadId:x,onThreadIdChange:m,audience:v="analyst",autoRun:A,onInsertSql:H,onInsertDql:D,onReplaceDql:F,onArtifactReady:q,onReviewAuthoringProposal:N,onOpenBlock:V,onOpenResearch:P,onOpenApp:M,onRunningChange:X,answerFirstCards:J=!1,insertDqlActionLabel:I,replaceDqlActionLabel:E,askLayout:_=!1}){const b=vr[e],$=g.useRef(void 0),[U,K]=g.useState(l),[L,G]=g.useState(u??[]),[re,ee]=g.useState([]),[pe,ce]=g.useState(""),[Y,S]=g.useState(!1),[te,w]=g.useState(null),[B,ie]=g.useState(null),[R,ne]=g.useState(null),[xe,Ke]=g.useState(()=>qs()),[Re,Se]=g.useState(h==="research"),[it,We]=g.useState(!1),[st,ot]=g.useState([]),[Oe,Ye]=g.useState(),at=g.useCallback(y=>{Ke(y);try{window.localStorage.setItem(Er,y)}catch{}},[]),lt=g.useCallback(y=>{Se(y),y||We(!1)},[]),k=g.useRef(null),de=g.useRef(l),He=g.useRef(null),Xe=g.useRef(null),ve=g.useRef(null),Me=g.useRef(null),ye=g.useRef(null),Le=g.useRef(0),At=g.useRef(""),De=g.useRef(null),ct=g.useCallback(()=>{At.current="",De.current!==null&&(window.cancelAnimationFrame(De.current),De.current=null),ce("")},[]),li=g.useCallback(y=>{At.current+=y,De.current===null&&(De.current=window.requestAnimationFrame(()=>{De.current=null;const j=At.current;At.current="",j&&ce(T=>T+j)}))},[]);g.useEffect(()=>()=>{De.current!==null&&window.cancelAnimationFrame(De.current)},[]);const qe=p==null?void 0:p.executionTarget,_n=qe&&typeof qe=="object"&&!Array.isArray(qe)&&qe.target==="connection"&&typeof qe.connectionName=="string"?String(qe.connectionName):void 0,ci=qe&&typeof qe=="object"&&!Array.isArray(qe)&&qe.target==="local";g.useEffect(()=>{let y=!1;return se.getConnections().then(j=>{if(y)return;const T=Object.keys(j.connections??{}).sort((W,O)=>W.localeCompare(O));ot(T),Ye(Br(T,j.default,_n))}).catch(()=>{y||(ot([]),Ye(void 0))}),()=>{y=!0}},[_n]);const zn=g.useCallback(y=>{Ye(y)},[]),[Ne,Rt]=g.useState(null),[Ee,Je]=g.useState(null),[di,en]=g.useState(""),Tn=g.useRef(null),qt=g.useRef(null);g.useEffect(()=>{!l||Y||l!==de.current&&(de.current=l,K(l))},[l,Y]);const ui=g.useMemo(()=>Tr(L),[L]),It=g.useRef(f);It.current=f;const Qe=g.useRef(q);Qe.current=q,g.useEffect(()=>{var y;(y=It.current)==null||y.call(It,L)},[L]);const me=g.useRef(x),_t=g.useRef(m);_t.current=m;const tn=g.useCallback((y,j)=>{var T;if(ye.current!==null&&(window.clearTimeout(ye.current),ye.current=null),pt(y.id),ve.current===y.id&&(ve.current=null),Me.current=null,w(null),ee(y.events.slice(-8)),ct(),G(W=>{if(W.some(Q=>Q.kind==="run"&&Q.run.id===y.id))return W.map(Q=>Q.kind==="run"&&Q.run.id===y.id?{...Q,id:y.id,run:y}:Q);const O=W.some(Q=>Q.kind==="user"&&Q.text===j.question);return[...W,...O?[]:[{kind:"user",id:`${y.id}-question`,text:j.question}],{kind:"run",id:y.id,run:y}]}),y.route!=="certified_answer"){const W=Ht(y);W&&((T=Qe.current)==null||T.call(Qe,W,y))}},[ct]),Mn=g.useCallback((y,j)=>{var W;G(O=>zr(O,y,j)),Rt(O=>{if(!O||O.runId!==y)return O;const Q=j.artifacts[0];return Q?{runId:j.id,artifactId:Q.id,tab:O.tab}:null}),ne(null);const T=Ht(j);T&&((W=Qe.current)==null||W.call(Qe,T,j))},[]),dt=g.useCallback(y=>{ye.current!==null&&window.clearTimeout(ye.current);const j=++Le.current;ve.current=y.id,Me.current=y,w(y),S(!0),ct(),ee([]);const T=async()=>{if(!(j!==Le.current||ve.current!==y.id))try{const W=await se.getAgentRunState(y.id);if(j!==Le.current||ve.current!==y.id)return;if(W.lifecycleState==="terminal"){tn(W.run,y),S(!1);return}ee(W.progress.events.slice(-8)),ye.current=window.setTimeout(()=>{T()},600)}catch{if(j!==Le.current||ve.current!==y.id)return;ye.current=window.setTimeout(()=>{T()},1200)}};return T(),()=>{j===Le.current&&(Le.current+=1),ye.current!==null&&(window.clearTimeout(ye.current),ye.current=null)}},[tn]),En=g.useRef(!1);g.useEffect(()=>{if(!x||En.current)return;En.current=!0,me.current??(me.current=x);let y=!1;return se.getAgentThread(x).then(({turns:j,runs:T})=>{y||j.length===0||G(W=>{const O=W.filter(fe=>fe.kind==="run").length,Q=Lr(j,T);if(j.length>=O)return Q;const ge=new Map(Q.flatMap(fe=>fe.kind==="run"?[[fe.run.id,fe.run]]:[]));return W.map(fe=>fe.kind==="run"&&ge.has(fe.run.id)?{...fe,run:ge.get(fe.run.id)}:fe)})}).catch(()=>{!y&&me.current===x&&(me.current=void 0)}),()=>{y=!0}},[x]),g.useEffect(()=>{const y=rr(x??me.current);if(!(!y||Xe.current))return dt(y)},[dt,x]),g.useEffect(()=>{const y=()=>{if(document.visibilityState!=="visible"||Xe.current)return;const j=Me.current??rr(x??me.current);j&&dt(j)};return document.addEventListener("visibilitychange",y),()=>document.removeEventListener("visibilitychange",y)},[dt,x]);const $e=async(y,j,T,W,O)=>{var Nn,Pn,Fn;const Q=(y??U).trim();if(!Q||Y)return;const ge=_r({initialMode:h,researchMode:Re,modeOverride:j,pendingMode:$.current}),fe=ge==="research"&⁢We(!1),$.current=void 0;const $t={kind:"user",id:ur("user"),text:Q};G(we=>[...we,$t]),K(""),ne(null),S(!0),ee([]),ct();const Be=new AbortController;Xe.current=Be;let ae={id:ur("pending"),question:Q,threadId:me.current,startedAt:new Date().toISOString()};ve.current=null,Me.current=ae,w(ae);let ke=!1,Ln=!1,Dn=!1;try{if(!me.current)try{const ue=await se.createAgentThread({surface:_?"ask":typeof(p==null?void 0:p.surface)=="string"?p.surface:c?"notebook":"agent",title:Q,...c?{notebookPath:c}:{}});me.current=ue.id,(Nn=_t.current)==null||Nn.call(_t,ue.id),ae={...ae,threadId:ue.id},Me.current=ae,w(ae)}catch{}const we=ge==="modeling"||ge==="skill"?(Pn=[...L].reverse().find(ue=>ue.kind==="run"&&ue.run.artifacts.some(ut=>ut.kind===(ge==="modeling"?"modeling_change_proposal":"skill_change_proposal"))))==null?void 0:Pn.run:void 0,Wn=we==null?void 0:we.artifacts.find(ue=>ue.kind===(ge==="modeling"?"modeling_change_proposal":"skill_change_proposal")),gi={question:Q,...T?{selectedEvidenceId:T}:{},...W?{clarificationSourceQuestion:W}:{},requestedMode:ge,audience:v,selectedObject:d??(c?{kind:"notebook",path:c}:void 0),...O!=null&&O.executionTarget?{executionTarget:O.executionTarget}:ci?{executionTarget:{target:"local"}}:Oe?{executionTarget:{target:"connection",connectionName:Oe}}:{},workspaceContext:{...p??{},...c?{notebookPath:c}:{},...O?{researchSource:Ur(O)}:{},...we&&Wn?{sourceRunId:we.id,sourceArtifactId:Wn.id,revision:(((Fn=we.derivation)==null?void 0:Fn.revision)??1)+1}:{}},conversationContext:us(L),history:ui,thinkingMode:xe,researchResultRowsOptIn:fe,...me.current?{threadId:me.current}:{}},Bt=await se.createAgentRunStream(gi,ue=>{if(ke=!0,ue.kind==="accepted"){const ut=ae.id;ae={...ae,id:ue.runId},ve.current=ue.runId,Me.current=ae,w(ae),pt(ut),nr(ae),Ln=!0}else ue.kind==="event"?ee(ut=>[...ut,ue.event].slice(-8)):ue.kind==="answer-delta"?li(ue.delta):ee(ue.run.events.slice(-8))},Be.signal);if(ae.id!==Bt.id){const ue=ae.id;ae={...ae,id:Bt.id},ve.current=Bt.id,Me.current=ae,pt(ue),nr(ae)}tn(Bt,ae)}catch(we){Be.signal.aborted||(ne(we instanceof Error?we.message:String(we)),K(Q),ke&&Ln?(Dn=!0,dt(ae)):(pt(ae.id),ve.current===ae.id&&(ve.current=null),Me.current=null,w(null)))}finally{Xe.current===Be&&(Xe.current=null),Dn||S(!1)}},zt=()=>{$e()},$n=()=>{var j;const y=ve.current;y&&se.cancelAgentRun(y).catch(()=>{}),(j=Xe.current)==null||j.abort(),Le.current+=1,ye.current!==null&&window.clearTimeout(ye.current),pt(y??""),ve.current=null,Me.current=null,w(null),ct(),ee([]),S(!1),ne("Stopped. No answer or draft was saved.")},Tt=g.useRef(X);Tt.current=X,g.useEffect(()=>{var y;(y=Tt.current)==null||y.call(Tt,Y)},[Y]),g.useEffect(()=>{!(A!=null&&A.text)||Y||He.current!==A.nonce&&(He.current=A.nonce,$e(A.text,A.mode??h))},[A==null?void 0:A.nonce,A==null?void 0:A.text,A==null?void 0:A.mode,h,Y]),g.useEffect(()=>()=>{Le.current+=1,ye.current!==null&&window.clearTimeout(ye.current)},[]);const Mt={appId:typeof(p==null?void 0:p.appId)=="string"?p.appId:void 0,dashboardId:typeof(p==null?void 0:p.dashboardId)=="string"?p.dashboardId:void 0,dashboardTitle:typeof(p==null?void 0:p.dashboardTitle)=="string"?p.dashboardTitle:void 0},Et=(y,j)=>{var T,W;if(j.id==="review-modeling-proposal"||j.id==="review-skill-proposal"){const O=j.id==="review-modeling-proposal"?"modeling_change_proposal":"skill_change_proposal",Q=y.artifacts.find(ge=>ge.kind===O);if(!Q){ne("This authoring run does not include a reviewable proposal.");return}if(N)N(Q,y);else if(Q.ref){try{window.sessionStorage.setItem("dql-context-proposal-handoff",Q.ref)}catch{}window.dispatchEvent(new CustomEvent("dql:open-context-proposal",{detail:{proposalId:Q.ref,kind:Q.kind}}))}return}if(j.id==="save-dql-block"){const O=Te(y),Q=((T=O==null?void 0:O.source)==null?void 0:T.trim())??((W=Ie(y))==null?void 0:W.trim());if(!Q){ne("This answer does not include a reusable DQL or SQL artifact yet.");return}ie({runId:y.id,source:Q,name:(O==null?void 0:O.name)??`${y.question.slice(0,48).trim()||"saved_answer"}`,dqlArtifact:O});return}if(j.id==="research-deeper"){$e(y.question,"research",void 0,void 0,y);return}if(j.id.startsWith("suggest-question")){$e(j.label,"auto");return}$.current=Js(j.route),K(Zs(y,j.route)),requestAnimationFrame(()=>{var O;return(O=k.current)==null?void 0:O.focus()})},pi=g.useCallback((y,j,T="trust")=>{Rt({runId:y,artifactId:j,tab:T})},[]),fi=g.useCallback(y=>{var W,O;const j=y.trim();if(!j)return;const T=(W=Ee==null?void 0:Ee.text)==null?void 0:W.trim();Je(null),en("");try{(O=window.getSelection())==null||O.removeAllRanges()}catch{}$e(T?`${j}
|
|
55
|
+
|
|
56
|
+
Regarding: "${T}"`:j),requestAnimationFrame(()=>{qt.current&&(qt.current.scrollTop=qt.current.scrollHeight)})},[Ee,$e]);if(g.useEffect(()=>{if(!_)return;const y=T=>{const W=T.target;W&&W.closest("[data-selpop]")||window.setTimeout(()=>{const O=window.getSelection(),Q=O&&O.rangeCount?O.toString().trim():"";if(!Q||Q.length<3){Je(ke=>ke&&null);return}const ge=O.anchorNode,fe=ge&&(ge.nodeType===1?ge:ge.parentElement),$t=fe==null?void 0:fe.closest("[data-followup]");if(!$t){Je(ke=>ke&&null);return}const Be=O.getRangeAt(0).getBoundingClientRect(),Bn=Math.max(12,Math.min(Be.left,window.innerWidth-340)),ae=Be.bottom+176>window.innerHeight?Math.max(12,Be.top-176):Be.bottom+8;Je({text:Q.slice(0,220),source:$t.getAttribute("data-followup")||"answer",left:Bn,top:ae}),en(""),requestAnimationFrame(()=>{var ke;return(ke=Tn.current)==null?void 0:ke.focus()})},0)},j=T=>{T.key==="Escape"&&Je(null)};return document.addEventListener("mouseup",y),document.addEventListener("keydown",j),()=>{document.removeEventListener("mouseup",y),document.removeEventListener("keydown",j)}},[_]),_){const y=Ne?(()=>{const j=L.find(W=>W.kind==="run"&&W.run.id===Ne.runId);if(!j||j.kind!=="run")return null;const T=j.run.artifacts.find(W=>W.id===Ne.artifactId);return T?{run:j.run,artifact:T}:null})():null;return t.jsxs("div",{style:{display:"flex",height:"100%",minHeight:0,flex:1,minWidth:0,width:"100%",background:"var(--bg-canvas)"},children:[B?t.jsx(Kn,{cell:{id:`agent-${B.runId}`,type:B.dqlArtifact?"dql":"sql",content:B.source,name:B.name,status:"success",...B.dqlArtifact?{dqlArtifact:B.dqlArtifact}:{}},initialContent:B.source,initialName:B.name,onClose:()=>ie(null),onSaved:()=>ie(null)}):null,t.jsx("style",{children:Ls}),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(Ue,{size:13})}),t.jsx("span",{style:{fontSize:13.5,fontWeight:650,color:b.textPrimary,whiteSpace:"nowrap"},children:n==="AI Copilot"?"Ask your data":n}),t.jsx("div",{style:{flex:1}}),t.jsx("span",{style:{fontSize:11,color:b.textMuted,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:"Certified first · semantic next · generated SQL last"})]}),t.jsxs("div",{ref:qt,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:[L.length===0&&!Y?t.jsxs("div",{style:{margin:"auto 0",display:"grid",gap:14,justifyItems:"center",textAlign:"center",color:b.textSecondary,paddingTop:40},children:[t.jsx("div",{style:pr(b),children:t.jsx(Ue,{size:20})}),t.jsx("div",{style:{fontSize:13.5,lineHeight:1.5,maxWidth:400,color:b.textSecondary},children:a??er}),t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap",justifyContent:"center",maxWidth:520},children:(o??tr).map(j=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>{K(j.prompt),requestAnimationFrame(()=>{var T;return(T=k.current)==null?void 0:T.focus()})},style:Qt(b),children:j.label},j.label))})]}):null,L.map(j=>j.kind==="user"?t.jsx("div",{style:Ds(b),children:j.text},j.id):t.jsx(dr,{run:j.run,t:b,themeMode:e,threadId:me.current,appContext:Mt,selectedArtifactId:(Ne==null?void 0:Ne.runId)===j.run.id?Ne.artifactId:void 0,onOpenArtifact:(T,W)=>pi(j.run.id,T,W),onOpenApp:M,onInsertSql:H,onInsertDql:D,onOpenBlock:V,onOpenResearch:P,onSelectClarification:T=>{const W=Nt(T,j.run.question);$e(W.question,void 0,W.selectedEvidenceId,j.run.question)},onNextAction:T=>Et(j.run,T),onRepairedRun:Mn},j.id)),Y&&t.jsx(ar,{events:re,t:b,streamingAnswer:pe,thinkingMode:xe,backgroundRun:te})]}),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:[R?t.jsx("div",{style:{color:b.error,fontSize:12,marginBottom:8},children:R}):null,s?t.jsxs("div",{style:{width:"fit-content",maxWidth:"100%",marginBottom:7,padding:"4px 7px 4px 9px",border:"1px solid var(--border-default)",borderRadius:999,background:"var(--bg-2)",color:b.textMuted,fontSize:10.5,display:"flex",alignItems:"center",gap:5},children:[t.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r}),t.jsx("button",{type:"button",onClick:s,"aria-label":"Clear modeling scope",title:"Clear modeling scope",style:{border:0,background:"transparent",color:b.textMuted,cursor:"pointer",display:"grid",placeItems:"center",padding:1},children:t.jsx(Ft,{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:k,value:U,onChange:j=>{K(j.target.value),$.current=void 0},rows:2,placeholder:i,onKeyDown:j=>{j.key==="Enter"&&!j.shiftKey&&(j.preventDefault(),zt())},style:{border:"none",background:"transparent",resize:"none",outline:"none",boxShadow:"none",padding:"13px 15px 4px",fontSize:13.5,lineHeight:1.5,color:b.textPrimary,fontFamily:b.font}}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 10px 10px 12px"},children:[t.jsx(Hn,{t:b,value:xe,onChange:at}),t.jsx(ir,{checked:Re,onChange:lt,t:b}),Re?t.jsx(sr,{checked:it,onChange:We,t:b}):null,t.jsx(or,{names:st,value:Oe,onChange:zn,t:b}),t.jsx("div",{style:{flex:1}}),Y?t.jsxs("button",{type:"button",className:"dql-hover",onClick:$n,title:"Stop the active agent run",style:{height:34,padding:"0 12px",borderRadius:10,border:`1px solid ${b.error}`,background:b.btnBg,color:b.error,display:"inline-flex",alignItems:"center",gap:6,cursor:"pointer",fontFamily:b.font,fontSize:12.5,fontWeight:600},children:[t.jsx(On,{size:13,fill:"currentColor"})," Stop"]}):null,t.jsx("button",{type:"button",className:"dql-hover dql-lift",title:"Ask",onClick:zt,disabled:!U.trim()||Y,style:{width:34,height:34,borderRadius:10,border:"none",background:U.trim()&&!Y?"var(--accent)":"var(--bg-4)",color:"#fff",display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:U.trim()&&!Y?"pointer":"default",boxShadow:U.trim()&&!Y?"0 1px 5px rgba(107,93,211,0.3)":"none"},children:Y?t.jsx(Ve,{size:15,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(jr,{size:15})})]})]}),t.jsx("div",{style:{textAlign:"center",fontSize:10.5,color:b.textMuted,marginTop:8},children:"Every answer is grounded in your certified metrics and dbt lineage."})]})]})]}),y?t.jsx(Hs,{run:y.run,artifact:y.artifact,tab:Ne.tab,t:b,appContext:Mt,onOpenApp:M,onChangeTab:j=>Rt(T=>T&&{...T,tab:j}),onClose:()=>Rt(null),onSaveBlock:()=>Et(y.run,{id:"save-dql-block",label:"Save as block",route:"dql_block_draft"}),onInsertSql:H,onInsertDql:D}):null,Ee?t.jsx(Qs,{t:b,text:Ee.text,source:Ee.source,left:Ee.left,top:Ee.top,draft:di,inputRef:Tn,onDraftChange:en,onClose:()=>Je(null),onSend:fi}):null]})}return t.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0,flex:1,minWidth:0,width:"100%",background:b.cellBg},children:[B?t.jsx(Kn,{cell:{id:`agent-${B.runId}`,type:B.dqlArtifact?"dql":"sql",content:B.source,name:B.name,status:"success",...B.dqlArtifact?{dqlArtifact:B.dqlArtifact}:{}},initialContent:B.source,initialName:B.name,onClose:()=>ie(null),onSaved:()=>ie(null)}):null,t.jsx("style",{children:`
|
|
57
|
+
@keyframes dql-agent-run-spin { to { transform: rotate(360deg); } }
|
|
58
|
+
@keyframes dql-agent-fadein { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
|
|
59
|
+
@keyframes dql-agent-thinking-dot { 0%, 65%, 100% { opacity: .28; transform: translateY(0); } 32% { opacity: 1; transform: translateY(-2px); } }
|
|
60
|
+
@keyframes dql-agent-activity-in { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
|
|
61
|
+
.dql-agent-thinking-dot { animation: dql-agent-thinking-dot 1.05s ease-in-out infinite; }
|
|
62
|
+
.dql-agent-activity { animation: dql-agent-activity-in .22s ease-out; }
|
|
63
|
+
.dql-hover { transition: filter .15s ease, transform .12s ease, box-shadow .15s ease, background .15s ease, color .15s ease, border-color .15s ease; }
|
|
64
|
+
.dql-hover:hover { filter: brightness(1.07); }
|
|
65
|
+
.dql-hover:active { transform: translateY(0.5px); }
|
|
66
|
+
.dql-lift:hover { transform: translateY(-1px); }
|
|
67
|
+
details > summary::-webkit-details-marker { display: none; }
|
|
68
|
+
@media (prefers-reduced-motion: reduce) { .dql-agent-thinking-dot, .dql-agent-activity { animation: none !important; } }
|
|
69
|
+
`}),t.jsxs("div",{style:{flex:1,minHeight:0,overflow:"auto",padding:"14px 16px",display:"flex",flexDirection:"column",gap:12},children:[L.length===0&&!Y?t.jsxs("div",{style:{margin:"auto 0",display:"grid",gap:14,justifyItems:"center",textAlign:"center",color:b.textSecondary},children:[t.jsx("div",{style:pr(b),children:t.jsx(Ue,{size:20})}),t.jsx("div",{style:{fontSize:13,lineHeight:1.5,maxWidth:380,color:b.textSecondary},children:a??er}),t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap",justifyContent:"center",maxWidth:520},children:(o??tr).map(y=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>{K(y.prompt),requestAnimationFrame(()=>{var j;return(j=k.current)==null?void 0:j.focus()})},style:Qt(b),children:y.label},y.label))})]}):null,L.map(y=>y.kind==="user"?t.jsx("div",{style:po(b),children:y.text},y.id):J?t.jsx(dr,{run:y.run,t:b,themeMode:e,threadId:me.current,appContext:Mt,onOpenApp:M,onInsertSql:H,onInsertDql:D,onReplaceDql:F,insertDqlActionLabel:I,replaceDqlActionLabel:E,onOpenBlock:V,onOpenResearch:P,onSelectClarification:j=>{const T=Nt(j,y.run.question);$e(T.question,void 0,T.selectedEvidenceId,y.run.question)},onNextAction:j=>Et(y.run,j),onRepairedRun:Mn},y.id):t.jsx(Bs,{run:y.run,t:b,themeMode:e,appContext:Mt,onOpenApp:M,onInsertSql:H,onInsertDql:D,onOpenBlock:V,onOpenResearch:P,onSelectClarification:j=>{const T=Nt(j,y.run.question);$e(T.question,void 0,T.selectedEvidenceId,y.run.question)},onNextAction:j=>Et(y.run,j)},y.id)),Y&&t.jsx(ar,{events:re,t:b,streamingAnswer:pe,thinkingMode:xe,backgroundRun:te})]}),R?t.jsx("div",{style:{margin:"0 16px 8px",color:b.error,fontSize:12},children:R}):null,t.jsxs("div",{style:{padding:"10px 16px 14px",borderTop:`1px solid ${b.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:b.textMuted,flex:1,minWidth:180,display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{children:r}),s?t.jsx("button",{type:"button",onClick:s,"aria-label":"Clear modeling scope",title:"Clear modeling scope",style:{border:0,background:"transparent",color:b.textMuted,cursor:"pointer",display:"grid",placeItems:"center",padding:2},children:t.jsx(Ft,{size:12})}):null]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(or,{names:st,value:Oe,onChange:zn,t:b}),t.jsx(Hn,{t:b,value:xe,onChange:at}),t.jsx(ir,{checked:Re,onChange:lt,t:b}),Re?t.jsx(sr,{checked:it,onChange:We,t:b}):null]})]}),t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-end"},children:[t.jsx("textarea",{ref:k,value:U,onChange:y=>{K(y.target.value),$.current=void 0},rows:2,placeholder:i,onKeyDown:y=>{y.key==="Enter"&&!y.shiftKey&&(y.preventDefault(),zt())},style:lo(b)}),t.jsxs("button",{type:"button",className:"dql-hover dql-lift",onClick:zt,disabled:!U.trim()||Y,style:fr(b,!!U.trim()&&!Y),children:[Y?t.jsx(Ve,{size:15,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(Ui,{size:15}),t.jsx("span",{children:Y?"Working":"Ask"})]}),Y?t.jsxs("button",{type:"button",className:"dql-hover",onClick:$n,style:{...fr(b,!0),background:b.btnBg,borderColor:b.error,color:b.error},title:"Stop the active agent run",children:[t.jsx(On,{size:13,fill:"currentColor"}),t.jsx("span",{children:"Stop"})]}):null]})]})]})}const er="Ask a question — every answer is grounded in your certified metrics and dbt lineage. Use Research deeper on any answer for a slower investigation.",tr=[{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 kn(){try{const e=JSON.parse(window.localStorage.getItem(wn)??"[]");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 nr(e){try{const n=kn().filter(r=>r.id!==e.id);window.localStorage.setItem(wn,JSON.stringify([...n,e].slice(-12)))}catch{}}function pt(e){try{const n=kn().filter(r=>r.id!==e);window.localStorage.setItem(wn,JSON.stringify(n))}catch{}}function rr(e){const n=kn().sort((r,i)=>i.startedAt.localeCompare(r.startedAt));return e?n.find(r=>r.threadId===e):n.find(r=>!r.threadId)}const Er="dql.agent.thinkingMode",$r="One-run consent: enables up to 200 redacted local-analysis tool rows during explicit Research. Ordinary Ask and Research narration may each use up to 20 redacted rows under their separate bounded narration policy; Ask never sends result rows to tools.";function Br(e,n,r){return r&&e.includes(r)?r:n&&e.includes(n)?n:e[0]}function ir({checked:e,onChange:n,t:r}){return t.jsxs("button",{type:"button","aria-pressed":e,"aria-label":"Research mode",title:"Research mode plans a bounded investigation and synthesizes the surrounding business context. Thinking effort is separate.",onClick:()=>n(!e),style:{minHeight:30,display:"inline-flex",alignItems:"center",gap:5,padding:"0 8px",border:e?"1px solid var(--accent)":"1px solid var(--border-default)",borderRadius:8,background:e?"var(--accent-dim)":"var(--bg-2)",color:e?"var(--accent-fg)":r.textMuted,fontSize:10.5,cursor:"pointer"},children:[t.jsx(nt,{size:13})," Research"]})}function sr({checked:e,onChange:n,t:r}){return t.jsxs("label",{title:$r,style:{minHeight:30,display:"inline-flex",alignItems:"center",gap:5,padding:"0 7px",border:"1px solid var(--border-default)",borderRadius:8,background:"var(--bg-2)",color:r.textMuted,fontSize:10.5,cursor:"pointer"},children:[t.jsx("input",{type:"checkbox","aria-label":"Allow redacted local-analysis tool rows for this Research run",checked:e,onChange:i=>n(i.target.checked)}),"Research tool rows (this run)"]})}function or({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(Si,{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 qs(){try{const e=window.localStorage.getItem(Er);return e==="low"||e==="medium"||e==="high"||e==="auto"?e:"auto"}catch{return"auto"}}const Is=new Set(["conversation","certified_answer","semantic_answer","generated_answer","research","sql_cell","dql_block_draft","modeling_draft","skill_draft","app_build","clarify","cancelled","blocked"]),_s=new Set(["certified","governed","grounded","review_required","blocked","not_applicable"]),zs=new Set(["completed","needs_review","needs_clarification","cancelled","blocked"]),Ts=new Set(["conversational_reply","certified_answer_found","governed_semantic_answer","governed_compound_answer","generated_review_required","artifact_created","needs_clarification","human_review_required","cancelled","blocked"]);function Lr(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??Ms(o)}]})}function Ms(e){var p,h,l;const n=Is.has(e.route)?e.route:"generated_answer",r=_s.has(e.trustLabel)?e.trustLabel:e.certification==="certified"?"certified":"not_applicable",i=zs.has(e.runStatus)?e.runStatus:"completed",s=Ts.has(e.stopReason)?e.stopReason:i==="cancelled"?"cancelled":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=(((p=e.result)==null?void 0:p.columns)??[]).filter(u=>typeof u=="string"),a=(((h=e.result)==null?void 0:h.rowsSample)??[]).filter(u=>Array.isArray(u)).map(u=>Object.fromEntries(o.map((f,x)=>[f,u[x]]))),c=o.length>0?{columns:o,rows:a,rowCount:((l=e.result)==null?void 0:l.rowCount)??a.length}:void 0,d=c||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}:{},...c?{result:c}:{},...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,narrationIntegrityReceipt:e.narrationIntegrityReceipt,steps:[],artifacts:d?[d]:[],evaluations:[],events:[],nextActions:[],repairAttempts:0}}function Es(e){switch(e){case"certified_answer":return"Found a compatible certified block";case"semantic_answer":return"Found a compatible semantic metric";case"generated_answer":return"Identified the relevant tables and columns";case"research":return"Identified evidence for deeper analysis";case"app_build":return"Found governed assets for the app";case"sql_cell":return"Identified the query context";case"dql_block_draft":return"Identified reusable governed logic";case"modeling_draft":return"Resolved current models and relationship evidence";case"skill_draft":return"Resolved current domain guidance and governed references";case"clarify":return"Identified a missing business detail";case"cancelled":return"Stopped by user";default:return"Identified the best answer path"}}function $s(e,n){if(n.some(r=>r.type==="repair.attempted"))return"Refining the query and trying again";if(n.some(r=>r.type==="escalated"))return"Expanding the evidence search";switch(e){case"certified_answer":case"semantic_answer":return"Running the governed query";case"generated_answer":return"Building and running a grounded query";case"research":return"Researching the strongest evidence";case"app_build":return"Assembling the app from governed assets";case"sql_cell":return"Building and checking the SQL";case"dql_block_draft":return"Drafting the governed logic";case"modeling_draft":return"Building a reviewable modeling proposal";case"skill_draft":return"Building a reviewable Skill proposal";case"clarify":return"Preparing a focused clarification";default:return"Preparing the answer"}}function gn(e){for(let n=e.length-1;n>=0;n-=1)if(e[n].route)return e[n].route}function Dr(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 Nr(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 Pr(e,n=!1){if(e.length===0&&n)return[{id:"background",label:"Continuing this request in the background",state:"active"}];const r=gn(e);if(r==="conversation")return[];const i=e.some(c=>c.type==="route.decided"),s=e.some(c=>c.type==="executor.started"||c.type==="step.started"||c.type==="repair.attempted"||c.type==="escalated"),o=e.some(c=>c.type==="evaluation.recorded"),a=[{id:"search",label:"Resolving governed evidence and business meaning",state:i?"complete":"active"}];return i&&a.push({id:"match",label:Es(r),state:s||o?"complete":"active"}),(s||o)&&a.push({id:"execute",label:$s(r,e),state:o?"complete":"active"}),o&&a.push({id:"verify",label:"Checking the result against governed evidence",state:"active"}),a}function ar({events:e,t:n,streamingAnswer:r,thinkingMode:i,backgroundRun:s}){var x;const[o,a]=g.useState(()=>Date.now());g.useEffect(()=>{const m=window.setInterval(()=>a(Date.now()),1e3);return()=>window.clearInterval(m)},[]);const c=(s==null?void 0:s.startedAt)??((x=e.find(m=>m.type==="run.started"))==null?void 0:x.at),d=c?Date.parse(c):o,p=Number.isFinite(d)?Math.max(0,Math.floor((o-d)/1e3)):0,h=Dr(p,gn(e),e.some(m=>m.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(gn(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(lr,{}),t.jsx("span",{style:{fontSize:13,lineHeight:1.4},children:"Replying…"})]});const u=Pr(e,!!s),f=p>=12?h==null?void 0:h.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:[u.map(m=>t.jsxs("div",{className:"dql-agent-activity",style:{display:"flex",alignItems:"center",gap:9,minHeight:18,color:m.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:m.state==="active"?n.accent:n.textMuted},children:m.state==="active"?t.jsx(lr,{}):t.jsx(bt,{size:13,strokeWidth:2.2})}),t.jsxs("span",{style:{fontSize:12.5,lineHeight:1.4,fontWeight:m.state==="active"?620:450},children:[m.label,m.state==="active"?"…":""]})]},m.id)),f?t.jsx("span",{style:{paddingLeft:25,fontSize:10.5,lineHeight:1.4,color:n.textMuted},children:f}):null]})}function lr(){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 cr({items:e,t:n,renderItem:r,cap:i=4}){const[s,o]=g.useState(!1),a=s?e:e.slice(0,i);return t.jsxs(t.Fragment,{children:[a.map((c,d)=>r(c,d)),e.length>i?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>o(c=>!c),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(wr,{size:11}):t.jsx(Ut,{size:11}),s?"Show less":`Show all (${e.length})`]}):null]})}function Bs({run:e,t:n,themeMode:r,appContext:i,onOpenApp:s,onInsertSql:o,onInsertDql:a,onOpenBlock:c,onOpenResearch:d,onSelectClarification:p,onNextAction:h}){var J;const{dispatch:l}=Gt();if(e.route==="conversation"){const I=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:fo(n),children:[I?t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:10.5,color:n.textMuted,marginBottom:6,fontWeight:650},children:[t.jsx(Wt,{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(Pt,{text:et(e.answer),t:n}):e.summary})]}),e.nextActions.length>0?t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:e.nextActions.map(E=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>h(E),style:Qt(n),children:E.label},E.id))}):null]})}const u=e.steps??[],f=u.length>1,x=((J=e.plan)==null?void 0:J.source)==="llm",m=In(e),v=Rn(e),A=kt(e),H=e.route==="certified_answer"||e.route==="generated_answer",D=e.nextActions.some(I=>I.route==="research"),F=H&&A&&!D,q=Te(e),N=A&&!(q!=null&&q.sourcePath)&&!!((q==null?void 0:q.source)??Ie(e)),V=Date.parse(e.startedAt),P=Date.parse(e.completedAt),M=Number.isFinite(V)&&Number.isFinite(P)?Math.max(0,Math.round((P-V)/1e3)):0,X=Nr(M,e.route,e.trustState,e.repairAttempts);return t.jsxs("div",{style:go(n),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(Ks,{run:e}),t.jsx("div",{style:{minWidth:0,flex:1},children:t.jsx("div",{style:{fontSize:12.5,fontWeight:850,color:n.textPrimary},children:Vs(e)})}),t.jsx(Ys,{run:e,t:n})]}),v?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(je,{size:12,color:n.success,style:{flex:"0 0 auto",marginTop:1}}):e.trustState==="governed"||e.trustState==="grounded"?t.jsx(je,{size:12,color:n.accent,style:{flex:"0 0 auto",marginTop:1}}):t.jsx(tt,{size:12,color:n.warning,style:{flex:"0 0 auto",marginTop:1}}),t.jsx("span",{children:v})]}):null,x||f||e.repairAttempts>0?t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[x?t.jsx(cn,{t:n,icon:t.jsx(jt,{size:11}),label:"AI plan",tone:"accent"}):null,f?t.jsx(cn,{t:n,icon:t.jsx(xt,{size:11}),label:`${u.length} steps`,tone:"muted"}):null,e.repairAttempts>0?t.jsx(cn,{t:n,icon:t.jsx(Yt,{size:11}),label:`${e.repairAttempts} repair${e.repairAttempts>1?"s":""}`,tone:"warning"}):null]}):null,e.summary&&!(e.answer&&eo(Ae(e.summary),et(e.answer)))?t.jsx("div",{style:{fontSize:12.5,lineHeight:1.45,color:n.textSecondary},children:Ae(e.summary)}):null,e.answer?t.jsx("div",{style:ho(n),children:t.jsx(Pt,{text:et(e.answer),t:n})}):null,e.analyticalTaskOutcomes&&e.analyticalTaskOutcomes.length>1?t.jsxs("div",{style:{display:"grid",gap:5,padding:"8px 10px",border:`1px solid ${n.cellBorder}`,borderRadius:8,background:n.cellBg},children:[t.jsx("div",{style:{fontSize:10.5,fontWeight:800,color:n.textMuted,textTransform:"uppercase",letterSpacing:.4},children:"Analytical tasks"}),e.analyticalTaskOutcomes.map(I=>{var b;const E=typeof I.status=="string"?I.status:"gap",_=typeof I.summary=="string"?I.summary:typeof((b=I.gap)==null?void 0:b.message)=="string"?String(I.gap.message):"Task outcome recorded.";return t.jsxs("div",{style:{display:"flex",gap:7,alignItems:"flex-start",fontSize:11.5,color:n.textSecondary},children:[t.jsx("span",{style:{color:E==="completed"?n.success:n.warning,fontWeight:800},children:E==="completed"?"✓":"!"}),t.jsxs("span",{children:[t.jsx("strong",{children:String(I.taskId)})," · ",_]})]},String(I.taskId))})]}):null,t.jsx(Or,{run:e,t:n,onSelect:p}),m.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:"}),m.map(I=>t.jsxs("span",{style:ri(n,I.certified),children:[I.certified?t.jsx(je,{size:11}):t.jsx(nt,{size:11}),t.jsx("span",{children:I.label})]},I.label))]}):null,t.jsx(ni,{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(I=>t.jsx(Xr,{artifact:I,t:n,themeMode:r,onInsertSql:o,onInsertDql:a,sourceRunId:e.id,sourceQuestion:e.question,onOpenBlock:c,onOpenResearch:d,onOpenApp:s,onNextAction:h},I.id))}):null,f?t.jsx(Zr,{steps:u,t:n}):t.jsx(Jr,{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(jt,{size:12})," View steps · where the time went"]}):null,X?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(Wt,{size:11,color:n.accent})," ",X.title]}),t.jsx("span",{style:{fontSize:10.5,color:n.textMuted,lineHeight:1.45},children:X.detail})]}):null,A||F||e.nextActions.length>0?t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[A?t.jsx(An,{run:e,t:n,appContext:i,onOpenApp:s}):null,N?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>h({id:"save-dql-block",label:"Save as block",route:"dql_block_draft"}),style:Z(n),children:[t.jsx(Sn,{size:11})," Save as block"]}):null,F?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>h({id:"research-deeper",label:"Research this deeper",route:"research"}),style:Z(n),title:"Run a slower, multi-step investigation on this question",children:[t.jsx(nt,{size:11}),"Research this deeper"]}):null,e.nextActions.filter(I=>I.id!=="pin-to-app"&&I.id!=="research-deeper"&&I.id!=="confirm-app-build"&&I.id!=="request-certification").map(I=>t.jsx("button",{type:"button",className:"dql-hover",onClick:()=>h(I),style:Z(n),children:I.label},I.id))]}):null]})}function Fr(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 Ls=`
|
|
70
|
+
@keyframes dql-agent-run-spin { to { transform: rotate(360deg); } }
|
|
71
|
+
@keyframes dql-agent-fadein { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
|
|
72
|
+
@keyframes dql-agent-thinking-dot { 0%, 65%, 100% { opacity: .28; transform: translateY(0); } 32% { opacity: 1; transform: translateY(-2px); } }
|
|
73
|
+
@keyframes dql-agent-activity-in { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
|
|
74
|
+
.dql-agent-thinking-dot { animation: dql-agent-thinking-dot 1.05s ease-in-out infinite; }
|
|
75
|
+
.dql-agent-activity { animation: dql-agent-activity-in .22s ease-out; }
|
|
76
|
+
.dql-hover { transition: filter .15s ease, transform .12s ease, box-shadow .15s ease, background .15s ease, color .15s ease, border-color .15s ease; }
|
|
77
|
+
.dql-hover:hover { filter: brightness(1.03); }
|
|
78
|
+
.dql-hover:active { transform: translateY(0.5px); }
|
|
79
|
+
.dql-lift:hover { transform: translateY(-1px); }
|
|
80
|
+
.dql-ask-ghost:hover { background: var(--bg-0); color: var(--text-primary) !important; }
|
|
81
|
+
.dql-ask-chip:hover { border-color: var(--accent) !important; box-shadow: 0 1px 6px rgba(107,93,211,0.12); }
|
|
82
|
+
details > summary::-webkit-details-marker { display: none; }
|
|
83
|
+
@media (prefers-reduced-motion: reduce) { .dql-agent-thinking-dot, .dql-agent-activity { animation: none !important; } }
|
|
84
|
+
`;function 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 Pe(e){return Kt(e,{variant:"ghost",size:"sm"})}function ln(e,n){return e.kind==="app_proposal"||e.kind==="dql_block_draft"||e.kind==="research_run"||!!Zt(n)}function Xt(e,n){var a,c;const r=[],i=ze(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)??((c=i==null?void 0:i.rows)==null?void 0:c.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 yt(e,n){const i=/^(?:certified|governed semantic|review-required|exploratory dbt-grounded) answer$/i.test(n.title.trim())?e.question:n.title,s=Ae(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 z(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function Wr(e){const n=[],r=new Set,i=(s,o)=>{const a=z(s);if(!a)return;const c=[a.name,a.label,a.relation,a.objectName].find(l=>typeof l=="string"&&l.trim().length>0);if(!c)return;const d=typeof a.kind=="string"?a.kind:o,p=`${d??""}:${c}`;if(r.has(p))return;r.add(p);const h=[a.description,a.provenance,a.sourceTier,a.source].find(l=>typeof l=="string"&&l.trim().length>0);n.push({name:c,kind:d,detail:h})};for(const s of e.artifacts){const o=oe(s),a=z(o.evidence);for(const p of["lineage","sourceTables","semanticObjects","selectedAssets"]){const h=a==null?void 0:a[p];Array.isArray(h)&&h.forEach(l=>i(l,p==="sourceTables"?"source":void 0))}const c=z(o.analysisPlan)??z(a==null?void 0:a.analysisPlan),d=c==null?void 0:c.candidateTables;Array.isArray(d)&&d.forEach(p=>i(p,"relation"))}return n.slice(0,24)}function Cn(e,n){var i;const r=oe(n);return Jt(r)?"how":(i=Te(e)??Ct(r))!=null&&i.source?"dql":Ie(e)??(typeof r.sql=="string"?r.sql:void 0)?"sql":Wr(e).length>0?"lineage":"trust"}function Ns({run:e,artifact:n,selected:r,t:i,themeMode:s,onInspect:o}){const a=oe(n),c=ze(a),[d,p]=g.useState(!1);if(g.useEffect(()=>{if(!d)return;const m=v=>{v.key==="Escape"&&p(!1)};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[d]),!c)return null;const h=ei(a,c),l=Cn(e,n),u=Te(e)??Ct(a),f=n.trustState==="certified"?Yr(n,a):void 0,x=t.jsxs("section",{"data-followup":"table","aria-label":`${yt(e,n)} result`,style:{border:`1px solid ${r?"var(--accent)":"var(--border-default)"}`,borderRadius:12,background:"var(--bg-2)",overflow:"hidden",boxShadow:d?"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)",...d?{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(rt,{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:yt(e,n)}),t.jsx("div",{style:{fontSize:11,color:i.textMuted,marginTop:2},children:Xt(n,a)})]}),t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>o(l),style:Pe(i),children:[t.jsx(jt,{size:12})," Inspect"]}),t.jsxs("button",{type:"button",className:"dql-ask-ghost","aria-label":d?"Return result to Copilot":"Expand result",title:d?"Return result to Copilot":"Expand this result for wide tables",onClick:()=>p(m=>!m),style:Pe(i),children:[d?t.jsx($i,{size:12}):t.jsx(qi,{size:12}),d?"Restore":"Expand result"]})]}),u?t.jsx(Kr,{artifact:u,certifiedBlockName:f,initialResult:c,initialChartConfig:h,payload:a,executionTarget:e.executionTarget,t:i,themeMode:s,embedded:!0,expanded:d}):t.jsx(vn,{result:c,themeMode:s,t:i,chartConfig:h,embedded:!0,tabLabels:{table:"Results",chart:"Visualization"},contentMaxHeight:d?"calc(100vh - 172px)":void 0,tableMaxHeight:d?"calc(100vh - 250px)":void 0})]});return!d||typeof document>"u"?x: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."}),ki.createPortal(t.jsx("div",{role:"dialog","aria-modal":"true","aria-label":`${yt(e,n)} expanded result`,onClick:()=>p(!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:m=>m.stopPropagation(),style:{minWidth:0,maxWidth:"100%"},children:x})}),document.body)]})}function dr(e){const{run:n,t:r,themeMode:i,threadId:s,appContext:o,selectedArtifactId:a,onOpenArtifact:c,onOpenApp:d,onInsertSql:p,onInsertDql:h,onReplaceDql:l,insertDqlActionLabel:u,replaceDqlActionLabel:f,onOpenBlock:x,onOpenResearch:m,onSelectClarification:v,onNextAction:A,onRepairedRun:H}=e,{dispatch:D}=Gt(),[F,q]=g.useState(!1),N=c??(()=>D({type:"OPEN_AGENT_LOG",run:n}));if(n.route==="conversation"){const R=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:[R?t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:10.5,color:r.textMuted,fontWeight:650},children:[t.jsx(Wt,{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(Pt,{text:et(n.answer),t:r}):n.summary}),n.nextActions.length>0?t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:n.nextActions.map(ne=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>A(ne),style:Qt(r),children:ne.label},ne.id))}):null]})}const V=n.trustState==="certified",P=n.status==="blocked",M=n.status==="cancelled"||n.stopReason==="cancelled"||n.route==="cancelled",X=n.status==="needs_clarification",J=n.answer,I=M?"Stopped by user":P?"Couldn’t run this query":X?"Needs clarification":V?"Certified answer":"AI-generated answer",E=M?n.summary||"Stopped by user.":P?ai(n):void 0,_=si(n),b=n.evaluations.filter(R=>R.severity==="info").length,$=In(n),U=M?[]:n.artifacts,K=U.filter(R=>{const ne=oe(R);return!ln(R,ne)&&!!ze(ne)}),L=new Set(K.map(R=>R.id)),G=U.filter(R=>!ln(R,oe(R))&&!L.has(R.id)),re=U.filter(R=>ln(R,oe(R))),ee=K[0]??G[0]??U[0],pe=kt(n),ce=n.route==="certified_answer"||n.route==="semantic_answer"||n.route==="generated_answer",Y=n.nextActions.some(R=>R.route==="research"),S=ce&&pe&&!Y,te=Te(n),w=pe&&!(te!=null&&te.sourcePath)&&!!((te==null?void 0:te.source)??Ie(n)),B=u&&h||f&&l?Ht(n):void 0,ie=()=>{var ne;const R=J?et(J):E??n.summary;R&&((ne=navigator.clipboard)==null||ne.writeText(R).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:[M?t.jsx(xt,{size:14,color:r.textMuted}):P?t.jsx(tt,{size:14,color:r.error}):V?t.jsx(je,{size:14,color:r.success}):t.jsx(Ue,{size:14,color:r.accent}),t.jsx("span",{style:{fontSize:12,fontWeight:650,color:M?r.textMuted:P?r.error:r.textSecondary},children:I}),V&&$[0]?t.jsxs("span",{style:{fontSize:11,color:r.textMuted},children:["from ",t.jsx("span",{style:{color:r.accent,fontWeight:600},children:$[0].label})]}):!P&&!M&&ee&&b>0?t.jsxs("button",{type:"button",onClick:()=>N(ee.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(bt,{size:11,color:r.success})," ",b," check",b===1?"":"s"," passed"]}):null]}),J?t.jsx("div",{"data-followup":"answer",style:{fontSize:14.5,lineHeight:1.65,color:r.textPrimary},children:t.jsx(Pt,{text:et(J),t:r})}):M?t.jsx("div",{"data-followup":"answer",style:{fontSize:14,lineHeight:1.6,color:r.textMuted},children:Ae(n.summary||"Stopped by user.")}):E?t.jsx(xo,{run:n,detail:E,threadId:s,onRepaired:R=>H(n.id,R),t:r}):n.summary?t.jsx("div",{"data-followup":"answer",style:{fontSize:14,lineHeight:1.6,color:r.textSecondary},children:Ae(n.summary)}):null,_?t.jsxs("div",{role:"status",style:{fontSize:11.5,lineHeight:1.5,color:r.warning,borderLeft:`2px solid ${r.warning}`,paddingLeft:8},children:["Capture warning: ",Ae(_)," The query result is still valid."]}):null,t.jsx(Or,{run:n,t:r,onSelect:v}),K.map(R=>t.jsx(Ns,{run:n,artifact:R,selected:R.id===a,t:r,themeMode:i,onInspect:ne=>N(R.id,ne)},R.id)),G.map(R=>{const ne=oe(R),xe=R.id===a;return t.jsxs("button",{type:"button",className:"dql-ask-chip",onClick:()=>N(R.id,Cn(n,R)),style:{display:"flex",alignItems:"center",gap:10,width:"fit-content",maxWidth:"100%",padding:"9px 12px",borderRadius:10,border:`1px solid ${xe?"var(--accent)":"var(--border-default)"}`,background:"var(--bg-2)",boxShadow:xe?"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:R.trustState==="certified"?"var(--status-success-bg)":"var(--accent-dim)",color:R.trustState==="certified"?"var(--status-success)":"var(--accent)",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx(rt,{kind:R.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:Ae(R.title)}),t.jsx("span",{style:{fontSize:11,color:r.textMuted},children:Xt(R,ne)})]}),t.jsx(br,{size:14,color:r.textMuted,style:{flexShrink:0,marginLeft:6}})]},R.id)}),re.length>0?t.jsx("div",{style:{display:"grid",gap:8,gridTemplateColumns:"minmax(0, 1fr)",minWidth:0},children:re.map(R=>t.jsx(Xr,{artifact:R,t:r,themeMode:i,onInsertSql:p,onInsertDql:h,insertDqlActionLabel:u,sourceRunId:n.id,sourceQuestion:n.question,onOpenBlock:x,onOpenResearch:m,onOpenApp:d,onNextAction:A},R.id))}):null,J||E||B||pe||w||S||ee?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:2,flexWrap:"wrap",marginTop:-2},children:[B&&h?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>h(B),style:Pe(r),children:[t.jsx(ht,{size:12})," ",u]}):null,B&&l&&f?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>l(B),style:Pe(r),children:[t.jsx(Ai,{size:12})," ",f]}):null,J||E?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:ie,style:Pe(r),children:[F?t.jsx(bt,{size:12}):t.jsx(kr,{size:12})," ",F?"Copied":"Copy"]}):null,pe?t.jsx(An,{run:n,t:r,appContext:o,onOpenApp:d}):null,w?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>A({id:"save-dql-block",label:"Save as block",route:"dql_block_draft"}),style:Pe(r),children:[t.jsx(wt,{size:12})," Save as block"]}):null,S?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>A({id:"research-deeper",label:"Research this deeper",route:"research"}),style:Pe(r),children:[t.jsx(nt,{size:12})," Research deeper"]}):null,ee?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>N(ee.id,Jt(oe(ee))?"how":"trust"),style:Pe(r),children:[t.jsx(jt,{size:12})," How it was answered"]}):null]}):null]})}function Or({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 Hr(e){const n=e.executionError;if(typeof n=="string"&&n.trim())return{stage:"execution",message:n};const r=z(n);if(r)return{stage:"execution",...r};const i=typeof e.refusalCode=="string"?e.refusalCode:void 0;if(i){const s=z(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 Jt(e){return!!(z(e.resolvedAnalyticalPlan)||z(e.analyticalExecutionGraph)||z(e.analyticalExecutionReceipt)||z(e.analyticalFailure)||z(e.semanticExecutionTrace)||z(e.diagnosticReceipt)||z(e.diagnosticReceiptV3)||Hr(e))}function Qr(e){if(!Jt(e))return;const n=z(e.diagnosticReceipt),r=z(e.diagnosticReceiptV3),i=r?{...n,...r,failure:r.failure??(n==null?void 0:n.failure)}:n,s=z(e.resolvedAnalyticalPlan)??z(i==null?void 0:i.resolvedAnalyticalPlan);return{plan:s,frame:z(s==null?void 0:s.analyticalFrame),graph:z(e.analyticalExecutionGraph),receipt:z(e.analyticalExecutionReceipt),facts:z(e.analyticalFacts),narrative:z(e.analyticalNarrative),freshness:z(e.analyticalFreshnessObservation),failure:z(e.analyticalFailure)??z(i==null?void 0:i.failure)??Hr(e),semantic:z(e.semanticExecutionTrace),diagnostic:i}}function Ps(){return["Performance & provider egress","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 Vr(e){const n=e.telemetry;if(!n)return;const r=(e.providerEgressReceipts??[]).reduce((d,p)=>d+p.resultRowCount,0),i=n.stageDurationsMs.total,s=n.warehouseDurationMs,o=i===void 0||s===void 0?void 0:Math.max(0,i-s),a=Array.from(new Set((e.artifacts??[]).flatMap(d=>{var u;const p=oe(d),h=z(p.resolvedAnalyticalPlan)??z((u=z(p.diagnosticReceipt))==null?void 0:u.resolvedAnalyticalPlan),l=z(p.analyticalExecutionReceipt);return[h==null?void 0:h.planId,l==null?void 0:l.planId].filter(f=>typeof f=="string"&&f.length>0)}))),c=Array.from(new Set((e.artifacts??[]).map(d=>d.id).filter(d=>typeof d=="string"&&d.length>0)));return[["Total",Dt(n.stageDurationsMs.total)],["Warehouse",n.warehouseDurationMs===void 0?"Not recorded":Dt(n.warehouseDurationMs)],["Orchestration",o===void 0?"Not recorded":Dt(o)],["Stages",Object.entries(n.stageDurationsMs).filter(([d])=>d!=="total").map(([d,p])=>`${d}: ${Dt(p)}`).join(" · ")],["Calls",`${n.providerRoundTrips} provider · ${n.toolCalls} tool · ${n.sqlExecutions} SQL · ${n.repairs} repair`],["Provider rows",r===0?`0 result rows sent to providers (${n.egressReceipts} content-free receipt${n.egressReceipts===1?"":"s"})`:`${r} bounded, redacted Research result row${r===1?"":"s"} sent with explicit run consent`],...e.narrationIntegrityReceipt?[["Narration",Ws(e.narrationIntegrityReceipt)]]:[],["Plan ID",a.length>0?a.join(", "):"Not recorded"],["Artifact IDs",c.length>0?c.join(", "):"None"],["Fallback",n.fallbackReason??"None"]]}function Ws(e){return e.outcome==="skipped"?`Skipped${e.skipReason?` (${e.skipReason.replace(/_/g," ")})`:""}`:e.outcome==="success"?e.mode==="verified_facts"?`Fact-verified (${e.factCount} facts)`:"Preview-grounded":e.outcome==="deterministic_fallback"?`Deterministic fallback${e.validationFailures.length>0?` (${e.validationFailures.join(", ")})`:""}`:"Narration unavailable; the retained answer was not replaced."}function Os({run:e,contract:n,dqlArtifact:r,sql:i,lineage:s,t:o,onInsertSql:a,onInsertDql:c,onSaveBlock:d}){var We,st,ot,Oe,Ye,at,lt;const{dispatch:p}=Gt(),h=n.plan,l=n.frame,u=n.graph,f=n.receipt,x=n.semantic,m=z(x==null?void 0:x.failure),v=n.failure??m,A=z(x==null?void 0:x.authoringRequest),H=z(x==null?void 0:x.runtimeRequest),D=be(x==null?void 0:x.bindings),F=be(x==null?void 0:x.steps),q=z(x==null?void 0:x.targetBinding),N=z(q==null?void 0:q.semanticSnapshot),V=z(q==null?void 0:q.executionTarget),P=z(V==null?void 0:V.redactedContext),M=z(q==null?void 0:q.compileTarget),X=z(x==null?void 0:x.executionReceipt),J=be(m==null?void 0:m.candidates),I=z((We=n.diagnostic)==null?void 0:We.cascade),E=be((st=n.diagnostic)==null?void 0:st.sourceCoverage),_=be(I==null?void 0:I.attempts),b=z((ot=n.diagnostic)==null?void 0:ot.provider),$=z(l==null?void 0:l.timeContext),U=z(l==null?void 0:l.comparison),K=z(l==null?void 0:l.ranking),L=be(l==null?void 0:l.dimensions),G=be(l==null?void 0:l.memberBindings),re=be($==null?void 0:$.periods),ee=be(l==null?void 0:l.requestedOutputs),pe=be(u==null?void 0:u.nodes),ce=Array.from(new Set([...Ce(v==null?void 0:v.safeActions),...Ce(m==null?void 0:m.safeActions)])),Y=be(v==null?void 0:v.failedBindings),S=z(m==null?void 0:m.sqlExcerpt),te=e.artifacts.map(k=>ze(oe(k))).find(Boolean),w=Vr(e),B=(r==null?void 0:r.name)??e.question,[ie,R]=g.useState(null),ne=(k,de)=>{const He=de.derivation.trustTransition;return`${k} as immutable derivation ${de.derivation.derivationId}. Trust: ${He.previous} → ${He.next}${He.requiresReview?" (review required)":""}.`},xe=async()=>{if(!(!(r!=null&&r.source)||!c))try{const k=await se.deriveAnalyticalRepair(e.id,{version:1,action:"edit_dql",dqlSource:r.source});c({sql:i,dqlArtifact:r,result:te,title:B,sourceRunId:e.id,question:e.question}),R(ne("Opened DQL in Notebook",k))}catch(k){R(k instanceof Error?k.message:String(k))}},Ke=async()=>{if(!(!i||!a))try{const k=await se.deriveAnalyticalRepair(e.id,{version:1,action:"open_sql_notebook",sqlText:i});a(i,`${B} repair`,{question:e.question,sourceRunId:e.id}),R(ne("Opened SQL in Notebook",k))}catch(k){R(k instanceof Error?k.message:String(k))}},Re=async k=>{try{const de=await se.deriveAnalyticalRepair(e.id,{version:1,action:k});R(ne(k==="retry_same_plan"?"Prepared the same bounded plan for retry":"Refreshed the governed snapshot and prepared the same plan for retry",de))}catch(de){R(de instanceof Error?de.message:String(de))}},Se=async()=>{try{const k=await se.deriveAnalyticalRepair(e.id,{version:1,action:"request_access"});R(ne("Recorded the access/connection repair and opened Database settings",k)),p({type:"SET_SETTINGS_TAB",tab:"database"}),p({type:"SET_MAIN_VIEW",view:"settings"})}catch(k){R(k instanceof Error?k.message:String(k))}},it=()=>{p({type:"SET_SETTINGS_TAB",tab:"project"}),p({type:"SET_MAIN_VIEW",view:"settings"}),R("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 ${v?"var(--status-error-border)":"var(--status-success-border)"}`,background:v?"var(--status-error-bg)":"var(--status-success-bg)"},children:[v?t.jsx(tt,{size:13,color:"var(--status-error)",style:{flexShrink:0,marginTop:2}}):t.jsx(je,{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:v?"var(--status-error)":"var(--status-success)"},children:v?"Execution failed":"Answered successfully"}),v?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{marginTop:3,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:o.fontMono,fontSize:11},children:typeof v.message=="string"&&v.message.trim()?v.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:[v.code,v.phase?`during ${v.phase}`:""].filter(Boolean).map(C).join(" · ")})]}):t.jsx("div",{style:{marginTop:2},children:typeof(f==null?void 0:f.rowCount)=="number"?`Returned ${f.rowCount} row${f.rowCount===1?"":"s"}.`:"The query ran and returned a result."})]})]}),t.jsx(ft,{index:1,label:"Performance & provider egress",t:o,open:!0,children:w?t.jsx(Lt,{rows:w,t:o}):t.jsx(mt,{t:o,children:"Performance details were not recorded for this legacy run."})}),t.jsx(ft,{index:2,label:"Plan",t:o,open:!v,children:t.jsx(Lt,{rows:[["Question type",C((l==null?void 0:l.questionType)??(h==null?void 0:h.questionType))],["Selected route",C((u==null?void 0:u.route)??(h==null?void 0:h.recommendedRoute))],["Metric",Ce(l==null?void 0:l.metricConceptIds).join(", ")],["Entity grain",Ce(l==null?void 0:l.entityGrainIds).join(", ")],["Dimensions",L.map(k=>`${C(k.dimensionId)} (${C(k.role)})`).join(", ")],["Member filters",G.map(k=>`${C(k.dimensionId)}: ${Array.isArray(k.canonicalValues)?k.canonicalValues.length:0} bound value(s)`).join(", ")],["Time policy",[$==null?void 0:$.timeRole,$==null?void 0:$.grain,$==null?void 0:$.timezone,$==null?void 0:$.completenessPolicy].map(C).filter(Boolean).join(" · ")],["Periods",re.map(k=>`${C(k.id)}: ${C(k.start)} → ${C(k.end)}`).join(`
|
|
85
|
+
`)],["Comparison",U?`${C(U.basePeriodId)} vs ${Ce(U.comparisonPeriodIds).join(", ")} · ${C(U.alignment)}`:l?"Not requested":"Not available — analytical planning did not complete"],["Ranking",K?`${C(K.direction)} · top ${C(K.limit)} · ${C(K.tiePolicy)}`:l?"Not requested":"Not available — analytical planning did not complete"],["Outputs",ee.map(k=>`${C(k.id)} (${C(k.kind)})`).join(", ")],["Semantic metrics",Ce(A==null?void 0:A.metrics).join(", ")],["Semantic dimensions",Ce(A==null?void 0:A.dimensions).join(", ")]],t:o})}),t.jsx(ft,{index:3,label:"Trust & evidence",t:o,children:t.jsx(Lt,{rows:[["Trust state",e.trustState],["Snapshot",C((h==null?void 0:h.snapshotId)??(u==null?void 0:u.snapshotId))],["Plan fingerprint",C((h==null?void 0:h.fingerprint)??(u==null?void 0:u.planFingerprint))],["Graph fingerprint",C(u==null?void 0:u.fingerprint)],["Receipt",C(f==null?void 0:f.receiptId)],["Result fingerprint",C(f==null?void 0:f.resultFingerprint)],["Freshness observed through",C((Oe=n.freshness)==null?void 0:Oe.observedThrough)],["Fact set",C((Ye=n.facts)==null?void 0:Ye.fingerprint)],["Semantic adapter",C(x==null?void 0:x.adapter)],["Semantic compile status",C(x==null?void 0:x.status)],["Target proof",C((at=z(q==null?void 0:q.proof))==null?void 0:at.status)],["Target binding",C(q==null?void 0:q.bindingFingerprint)],["Compile target",C(M==null?void 0:M.kind)],["Local semantic snapshot",C((N==null?void 0:N.semanticCatalogFingerprint)??(N==null?void 0:N.sourceFingerprint))],["Runtime metric inventory proof",C(M==null?void 0:M.semanticCatalogFingerprint)],["Execution target",[V==null?void 0:V.driver,P==null?void 0:P.account,P==null?void 0:P.database,P==null?void 0:P.schema,P==null?void 0:P.role,P==null?void 0:P.warehouse].map(C).filter(Boolean).join(" · ")],["Semantic receipt",C(X==null?void 0:X.receiptId)],["Warehouse query ID",C(X==null?void 0:X.queryId)],["Executed SQL proof",C(X==null?void 0:X.executedSqlFingerprint)],["Runtime metrics",Ce(H==null?void 0:H.metrics).join(", ")],["Runtime dimensions",Ce(H==null?void 0:H.dimensions).join(", ")],["Member bindings",D.map(k=>`${C(k.authoringReference)} → ${C(k.runtimeReference)}${Ce(k.entityPath).length?` via ${Ce(k.entityPath).join(" → ")}`:""} (${C(k.status)})`).join(`
|
|
86
|
+
`)],["Cascade",C(I==null?void 0:I.selectedTier)||C(I==null?void 0:I.stopReason)],["Plan frozen",C((lt=n.diagnostic)==null?void 0:lt.planFrozen)],["Provider phase/cause",[C(b==null?void 0:b.phase),C(b==null?void 0:b.cause)].filter(Boolean).join(" · ")],["Provider recovery",C(b==null?void 0:b.safeAction)],["Source coverage",E.map(k=>`${C(k.source)}: ${C(k.status)}`).join(`
|
|
87
|
+
`)]],t:o,mono:!0})}),t.jsx(ft,{index:4,label:"Actual steps",t:o,children:t.jsxs("div",{style:{display:"grid",gap:6},children:[F.map((k,de)=>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:[de+1,". ",C(k.label)]})," ","— ",C(k.status)," · ",C(k.detail)]},`semantic:${C(k.id)||de}`)),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)),pe.map((k,de)=>t.jsxs("div",{style:{fontSize:11.5,color:o.textSecondary},children:[t.jsxs("span",{style:{color:o.accent,fontFamily:o.fontMono},children:[de+1,". ",C(k.kind)]})," ","· ",C(k.id)]},C(k.id)||de)),_.map((k,de)=>t.jsxs("div",{style:{fontSize:11.5,color:o.textSecondary},children:[t.jsxs("span",{style:{color:o.accent,fontFamily:o.fontMono},children:[de+1,". ",C(k.tier)]})," ","— ",C(k.outcome)," · ",C(k.reason)]},`cascade:${C(k.tier)}:${de}`)),F.length===0&&e.steps.length===0&&pe.length===0&&_.length===0?t.jsx(mt,{t:o,children:"No executable steps were recorded."}):null]})}),t.jsx(ft,{index:5,label:"Failure & repair",t:o,open:!!v,children:v?t.jsxs("div",{style:{display:"grid",gap:9},children:[t.jsx(Lt,{rows:[["Failure ID",C(v.failureId)],["Recoverability",C(v.recoverability)],["Failed bindings",Y.map(k=>`${C(k.qualifiedId??k.role)} (${C(k.reasonCode)})`).join(", ")],["Safe actions",ce.join(", ")],["DQL fingerprint",C(v.dqlFingerprint)],["SQL fingerprint",C(v.sqlFingerprint)],["Semantic failure code",C(m==null?void 0:m.code)],["Failing identifier",C(m==null?void 0:m.identifier)],["Compiled SQL proof",C(m==null?void 0:m.compiledSqlFingerprint)],["Path candidates",J.map(k=>`${C(k.label)}
|
|
88
|
+
${C(k.runtimeReference)}`).join(`
|
|
89
|
+
`)]],t:o,mono:!0}),C(S==null?void 0:S.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(S==null?void 0:S.startLine),"–",C(S==null?void 0:S.endLine)]}),t.jsx("pre",{style:St(o),children:C(S==null?void 0:S.text)})]}):null,t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6},"aria-label":"Safe repair actions",children:[ce.includes("edit_dql")&&c?t.jsxs("button",{type:"button",onClick:()=>void xe(),style:Z(o),children:[t.jsx(Yt,{size:12})," Open DQL to repair"]}):null,ce.includes("open_sql_notebook")&&a?t.jsxs("button",{type:"button",onClick:()=>void Ke(),style:Z(o),children:[t.jsx(jn,{size:12})," Open SQL in Notebook"]}):null,ce.includes("retry_same_plan")?t.jsxs("button",{type:"button",onClick:()=>void Re("retry_same_plan"),style:Z(o),children:[t.jsx(nn,{size:12})," Retry same plan"]}):null,ce.includes("refresh_snapshot")?t.jsxs("button",{type:"button",onClick:()=>void Re("refresh_snapshot"),style:Z(o),children:[t.jsx(nn,{size:12})," Refresh snapshot and prepare retry"]}):null,ce.includes("request_access")||ce.includes("change_authorized_connection")?t.jsxs("button",{type:"button",onClick:()=>void Se(),style:Z(o),children:[t.jsx(tt,{size:12})," Change connection or request access"]}):null,ce.includes("reapply_semantic_runtime")?t.jsxs("button",{type:"button",onClick:it,style:Z(o),children:[t.jsx(nn,{size:12})," Reapply semantic runtime settings"]}):null]})]}):t.jsxs("div",{style:{display:"grid",gap:8},children:[t.jsx(mt,{t:o,children:"No failure was recorded for this run."}),r!=null&&r.sourcePath?null:r!=null&&r.source?t.jsxs("button",{type:"button",onClick:d,style:Z(o),children:[t.jsx(Sn,{size:12})," Save as draft block"]}):null]})}),ie?t.jsx("div",{role:"status",style:{fontSize:10.5,color:ie.toLowerCase().includes("created")?"var(--status-success)":"var(--status-error)"},children:ie}):null]})}function ft({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 Lt({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 mt({t:e,children:n}){return t.jsx("div",{style:{fontSize:11,color:e.textMuted},children:n})}function be(e){return Array.isArray(e)?e.flatMap(n=>z(n)?[z(n)]:[]):[]}function Ce(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 Dt(e){return typeof e!="number"||!Number.isFinite(e)||e<0?"Not recorded":e>=1e3?`${(e/1e3).toFixed(e>=1e4?0:1)}s`:`${Math.round(e)}ms`}function Nt(e,n){var i;const r=n==null?void 0:n.trim();return{question:((i=e.question)==null?void 0:i.trim())||r||e.label,selectedEvidenceId:e.id}}function Ur(e){var i;const n=e.artifacts.map(s=>ze(oe(s))).find(s=>!!s),r=(i=e.artifacts.find(s=>s.ref))==null?void 0:i.ref;return{runId:e.id,question:e.question,trustState:e.trustState,executionTarget:e.executionTarget,sourceCertifiedBlock:r,sql:Ie(e),dqlArtifact:Te(e),...n?{result:{columns:n.columns,rows:n.rows.slice(0,24),rowCount:n.rowCount}}:{}}}function kt(e){return!e.artifacts.some(r=>!!Zt(oe(r)))&&e.status!=="blocked"&&e.status!=="cancelled"&&e.stopReason!=="cancelled"&&e.status!=="needs_clarification"&&(e.artifacts.some(r=>r.kind==="answer"||r.kind==="research_run")||!!(Te(e)??Ie(e)))}function Hs({run:e,artifact:n,tab:r,t:i,appContext:s,onOpenApp:o,onChangeTab:a,onClose:c,onSaveBlock:d,onInsertSql:p,onInsertDql:h}){const l=oe(n),u=Te(e)??Ct(l),f=Ie(e)??(typeof l.sql=="string"?l.sql:void 0),x=ze(l),m=yt(e,n),v=In(e),A=Wr(e),H=Rn(e),D=n.trustState==="certified",F=e.status==="cancelled"||e.stopReason==="cancelled"||e.route==="cancelled",q=!F&&(e.status==="blocked"||n.trustState==="blocked"),N=kt(e),V=Qr(l),P=Fr({analytical:!!V,blocked:q,hasDql:!!(u!=null&&u.source),hasSql:!!f,hasLineage:A.length>0}),M=P.some(E=>E.id===r)?r:P[0].id,X=F?"Cancelled":q?"Blocked":D?"Certified":n.trustState==="governed"||n.trustState==="grounded"?"Governed":"AI-generated",J=F?"var(--text-tertiary)":q?"var(--status-error)":D?"var(--status-success)":n.trustState==="governed"||n.trustState==="grounded"?"var(--accent)":"var(--status-warning)",I=F?"var(--bg-3)":q?"var(--status-error-bg)":D?"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:I,color:J,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:"1px solid var(--border-subtle)"},children:t.jsx(rt,{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:yt(e,n)}),t.jsx("div",{style:{fontSize:11,color:i.textMuted,marginTop:2},children:Xt(n,l)})]}),t.jsx("span",{style:{border:`1px solid ${J}`,color:J,background:I,borderRadius:999,padding:"2px 8px",fontSize:10,fontWeight:700,flexShrink:0,marginTop:2},children:X}),t.jsx("button",{type:"button",onClick:c,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(Ft,{size:14})})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"10px 16px",borderBottom:"1px solid var(--border-subtle)"},children:[N?t.jsx(An,{run:e,t:i,appContext:s,onOpenApp:o}):null,N?t.jsxs("button",{type:"button",className:"dql-hover",onClick:d,style:{display:"inline-flex",alignItems:"center",gap:6,padding:"7px 13px",borderRadius:8,border:"1px solid var(--border-default)",background:"var(--bg-2)",color:i.textSecondary,fontSize:12,fontWeight:600,cursor:"pointer",fontFamily:i.font},children:[t.jsx(wt,{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(Ri,{size:14})})]}),t.jsx("div",{style:{display:"flex",alignItems:"center",gap:16,padding:"0 16px",borderBottom:"1px solid var(--border-subtle)",flexShrink:0},children:P.map(E=>t.jsx("button",{type:"button",onClick:()=>a(E.id),style:{padding:"10px 1px",fontSize:12,fontWeight:600,cursor:"pointer",border:"none",background:"none",fontFamily:i.font,whiteSpace:"nowrap",color:M===E.id?i.textPrimary:i.textMuted,boxShadow:M===E.id?`inset 0 -2px 0 0 ${i.accent}`:"none"},children:E.label},E.id))}),t.jsxs("div",{style:{flex:1,minHeight:0,overflow:"auto",padding:"14px 16px 20px"},children:[M==="how"&&V?t.jsx(Os,{run:e,contract:V,dqlArtifact:u,sql:f,lineage:A,t:i,onInsertSql:p,onInsertDql:h,onSaveBlock:d}):null,M==="dql"?u!=null&&u.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:[h?t.jsx("button",{type:"button",onClick:()=>h({sql:f,dqlArtifact:u,result:x,chartConfig:x?Fe(l,x):void 0,title:m,sourceRunId:e.id,question:e.question}),style:Z(i),children:"Open DQL in notebook"}):null,t.jsx(Ot,{text:u.source,t:i,title:"Copy DQL"})]})]}),t.jsx("pre",{style:St(i),children:u.source})]}):t.jsx(mt,{t:i,children:"The selected plan failed before a DQL source could be materialized. Review the Plan and Failure & repair sections."}):null,M==="sql"?f?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:[p?t.jsx("button",{type:"button",onClick:()=>p(f,m,{question:e.question,sourceRunId:e.id}),style:Z(i),children:"Open SQL in notebook"}):null,t.jsx(Ot,{text:f,t:i,title:"Copy SQL"})]})]}),t.jsx("pre",{style:St(i),children:f})]}):t.jsx(mt,{t:i,children:"Compilation stopped before SQL was produced. The DQL, plan, trust evidence, and failure steps are still retained."}):null,M==="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."}),A.map(E=>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(Sr,{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:E.name}),t.jsx("div",{style:{fontSize:10.5,color:i.textMuted,marginTop:2},children:[E.kind,E.detail].filter(Boolean).join(" · ")})]})]},`${E.kind??"asset"}:${E.name}`))]}):null,M==="trust"?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[H?t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-start",padding:"10px 12px",borderRadius:8,background:D?"var(--status-success-bg)":"var(--status-warning-bg)",border:`1px solid ${D?"var(--status-success-border)":"var(--status-warning-border)"}`},children:[D?t.jsx(je,{size:13,color:"var(--status-success)",style:{flexShrink:0,marginTop:1}}):t.jsx(tt,{size:13,color:"var(--status-warning)",style:{flexShrink:0,marginTop:1}}),t.jsx("span",{style:{fontSize:12,color:i.textSecondary,lineHeight:1.5},children:H})]}):null,v.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:v.map(E=>t.jsxs("span",{style:ri(i,E.certified),children:[E.certified?t.jsx(je,{size:11}):t.jsx(nt,{size:11}),t.jsx("span",{children:E.label})]},E.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(Jr,{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(Zr,{steps:e.steps,t:i})]}):null,t.jsx(ni,{run:e,t:i})]}):null]})]})}function Qs({t:e,text:n,source:r,left:i,top:s,draft:o,inputRef:a,onDraftChange:c,onClose:d,onSend:p}){const h=(l,u)=>t.jsx("button",{type:"button",onClick:()=>p(u),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(Ue,{size:12,color:e.accent}),t.jsx("span",{style:{fontSize:11,fontWeight:700,color:e.textSecondary},children:"Follow up on this"}),t.jsx("span",{style:{fontSize:10,color:e.textMuted},children:r==="table"?"from the result":"from the answer"}),t.jsx("div",{style:{flex:1}}),t.jsx("button",{type:"button",onClick:d,style:{width:20,height:20,borderRadius:5,border:"none",background:"none",color:e.textMuted,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0},children:t.jsx(Ft,{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=>c(l.target.value),onKeyDown:l=>{l.key==="Enter"&&(l.preventDefault(),p(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:()=>p(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(jr,{size:13})})]}),t.jsxs("div",{style:{display:"flex",gap:5,flexWrap:"wrap"},children:[h("Why is this?","Why is this happening?"),h("Root cause","What is the root cause?"),h("Break it down","Break this down further")]})]})}function gt(e){const n=e.replace(/^\/\w+\s+/,"").trim().replace(/[?.!]+$/,"");return(n?n.charAt(0).toUpperCase()+n.slice(1):"New app").slice(0,60)}function hn(e,n){const r=e instanceof Error?e.message.trim():"";return e instanceof Ci&&e.status===405||/method not allowed/i.test(r)?"This Notebook server is older than the App Studio shown in your browser. Restart dql notebook, reload this page, and try again. No Project files were published.":r||n}function xn(e,n){return n!=null&&n.trim()?`${e} › ${n.trim()}`:e}function Gr(e,n){const r=n.filter(s=>s.state!=="project_published"),i=new Set(r.flatMap(s=>{var o;return(o=s.baseApp)!=null&&o.appId?[s.baseApp.appId]:[]}));return[...r.map(s=>{var o,a;return{id:`draft:${s.id}`,kind:"draft",appId:s.appId,name:s.name,draft:s,pageId:(o=s.pages[0])==null?void 0:o.id,pageTitle:(a=s.pages[0])==null?void 0:a.metadata.title}}),...e.filter(s=>!i.has(s.id)).map(s=>{var a,c,d;const o=((a=s.homepage)==null?void 0:a.type)==="dashboard"?s.homepage.id:(c=s.dashboards[0])==null?void 0:c.id;return{id:`project:${s.id}`,kind:"project",appId:s.id,name:s.name,pageId:o,pageTitle:(d=s.dashboards.find(p=>p.id===o))==null?void 0:d.title}})]}function An({run:e,t:n,appContext:r,onOpenApp:i}){const[s,o]=g.useState(!1),[a,c]=g.useState(null),[d,p]=g.useState(!1),[h,l]=g.useState("list"),[u,f]=g.useState(""),[x,m]=g.useState(!1),[v,A]=g.useState(null),[H,D]=g.useState(""),[F,q]=g.useState(null),N=g.useRef(null),V=async()=>{c(null),p(!1);const[_,b]=await Promise.allSettled([se.listAppsStrict(),se.listAppBuilds()]);if(_.status==="rejected"&&b.status==="rejected"){c([]),p(!0);return}const $=Gr(_.status==="fulfilled"?_.value:[],b.status==="fulfilled"?b.value.drafts:[]);c($),$.length===0&&l("new")},P=()=>{o(!0),A(null),l("list"),N.current=null,f(gt(e.question)),D(gt(e.question)),V()},M=()=>{x||(o(!1),A(null))},X=async(_,b,$,U)=>{var ee,pe;const K=H.trim()||gt(e.question),L=Te(e),G=dn(e),re=await se.addAskResultToAppBuild(_.id,{expectedRevision:_.revision,expectedProposalHash:_.proposalHash,pageId:$,title:K,question:e.question,answer:e.answer??e.summary,certifiedBlockId:G,dqlSource:L==null?void 0:L.source,sql:Ie(e),visualization:(ee=no(e))==null?void 0:ee.chart});q({appId:re.draft.appId,draftId:re.draft.id,pageId:re.pageId,name:b,pageTitle:((pe=re.draft.pages.find(ce=>ce.id===re.pageId))==null?void 0:pe.metadata.title)??U,tileTitle:K,kind:re.deduped?"existing":G?"certified":L!=null&&L.source||Ie(e)?"review":"narrative"}),window.dispatchEvent(new CustomEvent("dql-app-build-updated",{detail:{draft:re.draft,pageId:re.pageId,tileId:re.tileId}})),o(!1)},J=async _=>{if(_.draft)return _.draft;const $=(await se.listAppBuilds()).drafts.find(U=>{var K;return U.state!=="project_published"&&((K=U.baseApp)==null?void 0:K.appId)===_.appId});return $||(await se.createAppBuild({baseAppId:_.appId,goal:`Edit ${_.name} with an Ask result`,authoringMode:"ai",sourcePolicy:dn(e)?"governed_only":"include_review_required",template:"blank",entrypoint:"ask"})).draft},I=async _=>{if(!x){m(!0),A(null);try{const b=await J(_),$=(r==null?void 0:r.appId)===_.appId?r.dashboardId:_.pageId;await X(b,_.name,$,_.pageTitle)}catch(b){A(hn(b,"Could not add to app."))}finally{m(!1)}}},E=async()=>{var b,$;if(x)return;const _=u.trim()||gt(e.question);m(!0),A(null);try{N.current||(N.current=(await se.createAppBuild({name:_,goal:e.question,authoringMode:"ai",sourcePolicy:dn(e)?"governed_only":"include_review_required",template:"blank",entrypoint:"ask"})).draft),await X(N.current,_,(b=N.current.pages[0])==null?void 0:b.id,($=N.current.pages[0])==null?void 0:$.metadata.title),N.current=null}catch(U){A(hn(U,"Could not create the app."))}finally{m(!1)}};return t.jsxs("div",{style:{position:"relative",display:"inline-flex",alignItems:"center",gap:6},children:[F?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(vt,{size:15})}),t.jsxs("span",{style:{display:"grid",gap:1,minWidth:0},children:[t.jsx("b",{style:{fontSize:11.5},children:F.kind==="existing"?"Already on this page":F.kind==="certified"?"Saved as a certified tile":F.kind==="review"?"Saved — review required":"Saved as editable narrative"}),t.jsxs("span",{title:xn(F.name,F.pageTitle),style:{fontSize:10.5,color:n.textSecondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[xn(F.name,F.pageTitle)," · editable draft"]}),t.jsxs("span",{title:F.tileTitle,style:{fontSize:10,color:n.textMuted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Tile: ",F.tileTitle]}),F.kind==="review"||F.kind==="narrative"?t.jsx("span",{style:{fontSize:10,color:n.textMuted,lineHeight:1.35},children:"Stays local and cannot publish until reviewed, promoted, or removed."}):null]}),i?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>i(F.appId,F.pageId,F.draftId),style:{...Z(n),color:n.success,whiteSpace:"nowrap"},title:"Open the App page containing this tile",children:["Open App ",t.jsx(Bi,{size:12})]}):null]}):null,t.jsxs("button",{type:"button",className:"dql-hover dql-lift",onClick:P,style:F?Z(n):gr(n),children:[t.jsx(un,{size:13}),F?"Add to another":"Add to app"]}),s?t.jsxs(t.Fragment,{children:[t.jsx("div",{onClick:M,style:{position:"fixed",inset:0,zIndex:40}}),t.jsxs("div",{style:co(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:h==="new"?"Name the new App draft":"Save to an editable App"}),t.jsx("button",{type:"button",onClick:M,style:{border:"none",background:"transparent",color:n.textMuted,cursor:"pointer",fontSize:15,lineHeight:1},children:"×"})]}),v?t.jsx("div",{style:{fontSize:11,color:n.error,marginBottom:7,lineHeight:1.4},children:v}):null,h==="new"?t.jsxs("div",{style:{display:"grid",gap:8},children:[t.jsx("input",{autoFocus:!0,value:u,onChange:_=>f(_.target.value),onKeyDown:_=>{_.key==="Enter"&&E()},placeholder:"App name",style:xr(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:Z(n),children:"Back"}):null,t.jsxs("button",{type:"button",className:"dql-hover",disabled:x||!u.trim(),onClick:()=>void E(),style:{...gr(n),flex:1,justifyContent:"center"},children:[x?t.jsx(Ve,{size:13,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(ht,{size:13}),"Create draft & add"]})]})]}):a===null?t.jsx("div",{style:{fontSize:11.5,color:n.textMuted,padding:"8px 2px"},children:"Loading apps…"}):d?t.jsxs("div",{style:{display:"grid",gap:8},children:[t.jsx("div",{style:{fontSize:11.5,color:n.error,lineHeight:1.4},children:"Couldn't load your apps."}),t.jsxs("div",{style:{display:"flex",gap:6},children:[t.jsx("button",{type:"button",className:"dql-hover",onClick:()=>void V(),style:Z(n),children:"Retry"}),t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>l("new"),style:{...hr(n),width:"auto",flex:1,marginBottom:0,justifyContent:"center"},children:[t.jsx(ht,{size:13})," New app…"]})]})]}):t.jsxs("div",{style:{display:"grid",gap:3,maxHeight:244,overflow:"auto"},children:[t.jsxs("label",{style:{display:"grid",gap:3,marginBottom:5},children:[t.jsx("span",{style:{fontSize:10.5,color:n.textMuted},children:"Tile name"}),t.jsx("input",{value:H,onChange:_=>D(_.target.value),placeholder:gt(e.question),maxLength:120,style:xr(n)})]}),t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>l("new"),style:hr(n),children:[t.jsx(ht,{size:13})," New app…"]}),a.map(_=>t.jsxs("button",{type:"button",className:"dql-hover",disabled:x,onClick:()=>void I(_),style:uo(n),children:[t.jsx(un,{size:13,style:{flex:"0 0 auto",opacity:.7}}),t.jsxs("span",{style:{flex:1,minWidth:0,display:"grid",gap:1,overflow:"hidden",textAlign:"left"},children:[t.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:_.name}),t.jsx("small",{style:{color:n.textMuted},children:_.kind==="draft"?"Local editable draft":"Project App · creates a safe edit draft"})]})]},_.id))]})]})]}):null]})}function Rn(e){var n;if(e.status==="cancelled"||e.stopReason==="cancelled"||e.route==="cancelled")return"Stopped by user. No result was accepted.";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(qn(e)){const r=e.artifacts.map(o=>o.payload).filter(o=>!!(o&&typeof o=="object"&&!Array.isArray(o)));if(r.some(o=>{const a=o.result;return!!(a&&typeof a=="object"&&!Array.isArray(a))}))return"Exploratory · DBT-grounded. The query and bounded join probes ran, but no certified relationship path covers it yet.";const s=(n=r.find(o=>typeof o.executionError=="string"))==null?void 0:n.executionError;return typeof s=="string"&&s.trim()?"Exploratory · DBT-grounded. DQL prepared a review-required query, but its bounded execution failed. Inspect the error and DQL artifact before reuse.":"Exploratory · DBT-grounded. DQL prepared a review-required query, but it has not executed yet."}return e.route==="modeling_draft"?"AI-drafted modeling proposal. Review the exact source diff, then save it as a draft — nothing is written or joinable yet.":e.route==="skill_draft"?"AI-drafted Skill proposal. Review it, then save it as a draft — it will not guide any agent until you activate it.":e.trustState==="review_required"?"AI-generated answer. Save it as a block when you want to keep it.":(e.trustState==="blocked",null)}function qn(e){return e.artifacts.some(n=>{const r=n.payload;return!!(r&&typeof r=="object"&&!Array.isArray(r)&&r.exploratoryCandidate)})}function Vs(e){return e.status==="cancelled"||e.stopReason==="cancelled"||e.route==="cancelled"?"Stopped by user":e.trustState==="certified"?"Certified answer":e.route==="dql_block_draft"?"Draft block":qn(e)?"Exploratory DBT-grounded answer":e.route==="semantic_answer"?"Semantic answer":e.route==="generated_answer"?"AI-generated answer":Mr[e.route]}function Us({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,[c,d]=g.useState(()=>o?Ii(o):new Set),[p,h]=g.useState(!1),[l,u]=g.useState(null),[f,x]=g.useState(null);if(!o||!s)return t.jsxs("div",{style:bn(r),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(rt,{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 m=async v=>{var H,D;h(!0),u(null);const A=await se.commitAppAiBuild(s,{selectedTileIds:Array.from(c),expectedProposalHash:a,...v.appName?{appName:v.appName}:{},...v.pageTitle?{pageTitle:v.pageTitle}:{},...v.audience?{audience:v.audience}:{},...Object.keys(v.tileOverrides).length>0?{tileOverrides:v.tileOverrides}:{}});if(h(!1),!A.ok){u(A.error);return}x({appId:((H=A.app)==null?void 0:H.id)??A.session.appId??"",dashboardId:A.dashboardId??void 0,name:((D=A.app)==null?void 0:D.name)??e.title})};return t.jsxs("div",{style:bn(r),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(rt,{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:Ae(e.title)})]}),f?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(vt,{size:13})," Created ",f.name]}),f.appId&&i?t.jsx("button",{type:"button",className:"dql-hover",onClick:()=>i(f.appId,f.dashboardId),style:Z(r),children:"Open app"}):null]}):t.jsx(_i,{proposal:o,t:r,selected:c,onToggle:v=>{d(A=>{const H=new Set(A);return H.has(v)?H.delete(v):H.add(v),H})},onCreate:v=>void m(v),defaultName:e.title,busy:p,error:l,compact:!0})]})}function Kr({artifact:e,certifiedBlockName:n,initialResult:r,initialChartConfig:i,payload:s,executionTarget:o,t:a,themeMode:c,embedded:d=!1,expanded:p=!1}){var Y;const[h,l]=g.useState(e),[u,f]=g.useState(()=>e.parameters??[]),[x,m]=g.useState(()=>({...e.parameterValues??{},...yn(s)})),[v,A]=g.useState(r),[H,D]=g.useState(i),[F,q]=g.useState(!!n),[N,V]=g.useState(!1),[P,M]=g.useState(null),[X,J]=g.useState(!1),[I,E]=g.useState(""),[_,b]=g.useState(""),$=g.useRef(!1),U=g.useRef(e);U.current=e;const K=ks(e);g.useEffect(()=>{const S=U.current;if(l(S),J(!1),!n){f(S.parameters??[]),m({...S.parameterValues??{},...yn(s)}),q(!1);return}let te=!1;return q(!0),se.getCertifiedBlockParameters(n).then(w=>{te||(f(w.parameters),m(B=>({...Object.fromEntries(w.parameters.flatMap(ie=>ie.default===void 0?[]:[[ie.name,ie.default]])),...B})))}).catch(w=>{te||M(w instanceof Error?w.message:String(w))}).finally(()=>{te||q(!1)}),()=>{te=!0}},[K,n]);const L=async()=>{if(!$.current){$.current=!0,V(!0),M(null);try{const S=await se.invokeDqlArtifact(h,x,void 0,n,o);A(S.result),l(S.artifact),S.result.chartConfig&&typeof S.result.chartConfig=="object"&&D(S.result.chartConfig),S.parameters.length>0&&f(S.parameters)}catch(S){M(S instanceof Error?S.message:String(S))}finally{$.current=!1,V(!1)}}},G=g.useMemo(()=>Ir(h,v),[h,v]),re=()=>{const S=G[0];S&&(E(S.column),b(S.values[0]==null?"":String(S.values[0])),J(!0),M(null))},ee=async()=>{try{const S=h.kind==="sql_block"?await se.addDqlArtifactResultFilter(h,v.columns,I,_,o):Cs(h,v,I,_);l(S.artifact),f(S.artifact.parameters??[]),m(te=>({...te,...S.artifact.parameterValues??{}})),J(!1),M(null)}catch(S){M(S instanceof Error?S.message:String(S))}},pe=u.some(Ar),ce=Object.entries(x).filter(([,S])=>S!=null&&S!=="");return t.jsxs("div",{style:{display:"grid",gap:9},children:[ce.length>0?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap",padding:d?"8px 12px 0":0},children:[t.jsx("span",{style:{fontSize:10.5,fontWeight:750,color:a.textMuted},children:"Applied inputs"}),ce.map(([S,te])=>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," ")," = ",Gs(te)]},S))]}):null,F?t.jsx("div",{style:{fontSize:10.5,color:a.textMuted},children:"Loading reusable inputs…"}):pe||G.length>0?t.jsxs("div",{style:{display:"grid",gap:8,padding:9,margin:d?"0 12px":0,border:`1px solid ${a.cellBorder}`,borderRadius:7,background:a.appBg},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:11,fontWeight:800,color:a.textPrimary},children:"Change DQL inputs"}),t.jsx("div",{style:{fontSize:10,color:a.textMuted},children:"Reruns this DQL artifact directly. It does not start another AI search."})]}),G.length>0?t.jsxs("button",{type:"button",onClick:re,style:Z(a),children:[t.jsx(ht,{size:11})," Add result filter"]}):null,t.jsxs("button",{type:"button",disabled:N,onClick:()=>void L(),style:{...Z(a),color:a.accent,opacity:N?.65:1},children:[N?t.jsx(Ve,{size:11,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(Ue,{size:11}),N?"Running…":"Apply"]})]}),X?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:I,onChange:S=>{const te=S.target.value,w=G.find(B=>B.column===te);E(te),b((w==null?void 0:w.values[0])==null?"":String(w.values[0]))},style:yr(a),children:G.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:_,list:`ask-filter-${I}`,onChange:S=>b(S.target.value),style:yr(a)}),t.jsx("datalist",{id:`ask-filter-${I}`,children:(((Y=G.find(S=>S.column===I))==null?void 0:Y.values)??[]).map(S=>t.jsx("option",{value:String(S)},`${typeof S}:${String(S)}`))})]}),t.jsx("button",{type:"button",onClick:()=>{ee()},style:{...Z(a),color:a.accent},children:"Add input"}),t.jsx("button",{type:"button",onClick:()=>J(!1),style:Z(a),children:"Cancel"})]}):null,u.length>0?t.jsx(cs,{parameters:u,values:x,onChange:(S,te)=>m(w=>({...w,[S]:te})),t:a}):null,G.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,P?t.jsx("div",{style:{fontSize:10.5,color:a.error},children:P}):null,t.jsx(vn,{result:v,themeMode:c,t:a,chartConfig:H,embedded:d,tabLabels:d?{table:"Results",chart:"Visualization"}:void 0,contentMaxHeight:p?"calc(100vh - 172px)":void 0,tableMaxHeight:p?"calc(100vh - 250px)":void 0})]})}function yn(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 Gs(e){return Array.isArray(e)?e.map(n=>String(n)).join(", "):typeof e=="boolean"?e?"true":"false":String(e)}function Yr(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 Xr({artifact:e,t:n,themeMode:r,onInsertSql:i,onInsertDql:s,insertDqlActionLabel:o,sourceRunId:a,sourceQuestion:c,onOpenBlock:d,onOpenResearch:p,onOpenApp:h,onNextAction:l}){const u=e.payload&&typeof e.payload=="object"?e.payload:{};if(e.kind==="app_proposal")return t.jsx(Us,{artifact:e,payload:u,t:n,onOpenApp:h});const f=ze(u),x=Ct(u),m=Zt(u),v=typeof u.sql=="string"?u.sql:typeof u.sqlPreview=="string"?u.sqlPreview:typeof u.proposedSql=="string"?u.proposedSql:void 0,A=typeof u.name=="string"?u.name:e.title,H=typeof u.path=="string"?u.path:e.ref,D=u.draftBlock&&typeof u.draftBlock=="object"&&!Array.isArray(u.draftBlock)?u.draftBlock:void 0,F=typeof(D==null?void 0:D.path)=="string"?D.path:void 0,q=typeof(D==null?void 0:D.name)=="string"?D.name:void 0,N=(x==null?void 0:x.sourcePath)??F??(e.kind==="dql_block_draft"?H:void 0),V=(x==null?void 0:x.name)??q??A,P=(x==null?void 0:x.kind)==="sql_block"||e.kind==="dql_block_draft"?"Open DQL draft":"Open DQL artifact",M=u.plan&&typeof u.plan=="object"?u.plan:void 0,X=Array.isArray(M==null?void 0:M.steps)?M.steps:[],J=Array.isArray(M==null?void 0:M.gaps)?M.gaps.map(String):[],I=typeof u.researchRunId=="string"?u.researchRunId:e.kind==="research_run"&&typeof e.ref=="string"?e.ref:void 0,E=typeof u.notebookPath=="string"?u.notebookPath:void 0,_=Array.isArray(u.generatedPaths)?u.generatedPaths.filter(L=>typeof L=="string"):[],b=u.narration&&typeof u.narration=="object"?u.narration:void 0,$=Array.isArray(b==null?void 0:b.keyFindings)?b.keyFindings.filter(L=>typeof L=="string"):[],U=typeof(b==null?void 0:b.recommendation)=="string"?b.recommendation:void 0,K=e.trustState==="certified"?Yr(e,u):void 0;if(e.kind==="dql_block_draft"){const L=re=>Array.isArray(re)?re.filter(ee=>typeof ee=="string"):void 0,G=u.certifierVerdict&&typeof u.certifierVerdict=="object"?u.certifierVerdict:void 0;return t.jsx(as,{t:n,name:typeof u.name=="string"?u.name:A,status:"draft",description:typeof u.description=="string"?u.description:void 0,dql:(x==null?void 0:x.source)??(typeof u.dqlSource=="string"?u.dqlSource:void 0),sqlPreview:v,grain:typeof u.grain=="string"?u.grain:void 0,outputs:L(u.outputs),dimensions:L(u.dimensions)??(x==null?void 0:x.dimensions),entities:L(u.entities),certifierVerdict:G?{blocking:L(G.blocking)??[],warnings:L(G.warnings)??[],ready:!!G.ready}:void 0,actions:t.jsxs(t.Fragment,{children:[v&&s?t.jsx("button",{type:"button",onClick:()=>s({sql:v,dqlArtifact:x,result:f,chartConfig:f?Fe(u,f):void 0,title:A,sourceRunId:a,question:c}),style:Z(n),children:o??"Insert as DQL cell"}):v&&i?t.jsx("button",{type:"button",onClick:()=>i(v,A,{question:c,sourceRunId:a}),style:Z(n),children:"Insert SQL preview"}):null,N&&d?t.jsx("button",{type:"button",onClick:()=>d(N,V),style:Z(n),children:P}):null]})})}return t.jsxs("div",{style:bn(n),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(rt,{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:Ae(e.title)})]}),$.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(cr,{items:$,t:n,renderItem:(L,G)=>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:L})]},G)})]}):X.length>0?t.jsx("div",{style:{display:"grid",gap:5},children:t.jsx(cr,{items:X,t:n,renderItem:(L,G)=>t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.35},children:[G+1,". ",String(L.thought??L.expectation??"Research step")]},G)})}):null,U?t.jsxs("div",{style:{fontSize:11.5,color:n.textPrimary,lineHeight:1.4,display:"flex",gap:6},children:[t.jsx("span",{style:{color:n.accent},children:"→"}),t.jsx("span",{children:U})]}):null,f?x?t.jsx(Kr,{artifact:x,certifiedBlockName:K,initialResult:f,initialChartConfig:Fe(u,f),payload:u,t:n,themeMode:r}):t.jsx(vn,{result:f,themeMode:r,t:n,chartConfig:Fe(u,f)}):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(wt,{size:12}),t.jsx("span",{children:"View DQL artifact"}),t.jsxs("span",{style:{marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:4},children:[x.source?t.jsx(Ot,{text:x.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:L=>{L.preventDefault(),L.stopPropagation(),l({id:"save-dql-block",label:"Save as DQL block",route:"dql_block_draft"})},style:{border:"none",background:"transparent",cursor:"pointer",color:n.accent,display:"inline-flex",alignItems:"center",gap:3,fontSize:10.5,fontWeight:700,padding:"2px 4px"},children:[t.jsx(Sn,{size:12})," Save as block"]}):null]})]}),x.sourcePath?t.jsx("div",{style:{marginTop:6,fontSize:10.5,color:n.textMuted},children:x.sourcePath}):null,t.jsx("pre",{style:{...St(n),marginTop:6},children:x.source})]}):null,v?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(jn,{size:12}),t.jsx("span",{children:ti(!!x)}),t.jsx("span",{style:{marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:4},children:t.jsx(Ot,{text:v,t:n,title:"Copy SQL"})})]}),t.jsx("pre",{style:{...St(n),marginTop:6},children:v})]}):null,J.length>0?t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.4},children:["Gaps: ",J.join(", ")]}):null,_.length>0?t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.4},children:["Files: ",_.join(", ")]}):null,t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[I&&p?t.jsx("button",{type:"button",onClick:()=>p(I,E),style:Z(n),children:"Open research"}):null,v&&s?t.jsx("button",{type:"button",onClick:()=>s({sql:v,dqlArtifact:x,result:f,chartConfig:f?Fe(u,f):void 0,title:A,mixedSourcePlan:m,sourceRunId:a,question:c}),style:m?{...Z(n),background:n.accent,borderColor:n.accent,color:"#fff",fontWeight:850,padding:"7px 11px"}:Z(n),children:m?"Add workflow to notebook":x?"Insert as DQL cell":"Add SQL to notebook"}):v&&i?t.jsx("button",{type:"button",onClick:()=>i(v,A,{question:c,sourceRunId:a}),style:Z(n),children:"Insert SQL preview"}):null,N&&d?t.jsx("button",{type:"button",onClick:()=>d(N,V),style:Z(n),children:P}):null]})]})}function Ks({run:e}){return e.trustState==="certified"?t.jsx(je,{size:16,color:"#16a34a"}):e.trustState==="governed"?t.jsx(je,{size:16,color:"#2563eb"}):e.trustState==="grounded"?t.jsx(je,{size:16,color:"#2563eb"}):e.status==="completed"?t.jsx(vt,{size:16,color:"#16a34a"}):e.status==="cancelled"||e.stopReason==="cancelled"?t.jsx(xt,{size:16,color:"#737373"}):e.status==="blocked"?t.jsx(xt,{size:16,color:"#ef4444"}):t.jsx(xt,{size:16,color:"#d97706"})}function rt({kind:e}){return e==="sql_cell"?t.jsx(jn,{size:14}):e==="dql_block_draft"?t.jsx(wt,{size:14}):e==="app_draft"||e==="app_proposal"?t.jsx(un,{size:14}):e==="research_run"?t.jsx(nt,{size:14}):t.jsx(Ue,{size:14})}function Ys({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.status==="cancelled"||e.stopReason==="cancelled"?"Cancelled":e.trustState==="certified"?"Certified":e.route==="dql_block_draft"?"Draft":qn(e)?"Exploratory":e.status==="needs_clarification"?"Needs input":e.trustState==="blocked"?"Refused":"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 Jr({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(mn,{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(je,{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(mn,{evaluation:s,t:n},s.id))})]}):null]})}function mn({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 cn({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 Xs(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 Zr({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(jt,{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=Xs(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,". ",Mr[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(Sr,{size:10}):r.status==="repaired"?t.jsx(Yt,{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(mn,{evaluation:s,t:n},s.id))}):null]},r.id)})})]})}function Js(e){if(e==="research")return"research";if(e==="sql_cell")return"sql";if(e==="dql_block_draft")return"block";if(e==="modeling_draft")return"modeling";if(e==="skill_draft")return"skill";if(e==="app_build")return"app";if(e==="certified_answer"||e==="semantic_answer"||e==="generated_answer")return"ask"}function Zs(e,n){return n==="sql_cell"?`Create a SQL cell for: ${e.question}`:n==="dql_block_draft"?`Create a DQL block draft for: ${e.question}`:n==="modeling_draft"?`Revise the modeling proposal for: ${e.question}`:n==="skill_draft"?`Revise the Skill proposal for: ${e.question}`:n==="app_build"?`Build an app for: ${e.question}`:n==="research"?`Research deeper: ${e.question}`:e.question}function ur(e){return`${e}_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function et(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 Ae(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 eo(e,n){const r=i=>i.toLowerCase().replace(/[\s.,!?'"()`*_-]+/g," ").trim();return r(e)===r(n)}function ze(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=wi(o),c=a.rows,d=a.columns;if(!(c.length===0&&d.length===0&&typeof o.rowCount!="number"))return{columns:d,rows:c,rowCount:a.rowCount,...a.resultFingerprint?{resultFingerprint:a.resultFingerprint}:{},...a.executionReceipt?{executionReceipt:a.executionReceipt}:{},...a.trustState?{trustState:a.trustState}:{},...a.answerTier?{answerTier:a.answerTier}:{},...a.executionTime!==void 0?{executionTime:a.executionTime}:{}}}}function Fe(e,n){const r=e.result&&typeof e.result=="object"?e.result:void 0,i=r!=null&&r.chartConfig&&typeof r.chartConfig=="object"?r.chartConfig:e.chartConfig&&typeof e.chartConfig=="object"?e.chartConfig:{},s=typeof e.suggestedViz=="string"?e.suggestedViz:typeof(r==null?void 0:r.suggestedViz)=="string"?r.suggestedViz:void 0,o=i.decisionSource==="authored"||i.decisionSource==="agent"||i.decisionSource==="data"||i.decisionSource==="user"?i.decisionSource:void 0,a=typeof i.chart=="string"?i.chart:s,c=a?a.toLowerCase().replace(/_/g,"-")==="single-value"?"kpi":a:void 0,d=n.columns,p=u=>typeof i[u]=="string"&&d.includes(i[u])?i[u]:void 0,h=Array.isArray(i.metrics)?i.metrics.filter(u=>typeof u=="string"&&d.includes(u)):[],l={...c?{chart:c}:{},...c?{decisionSource:o??"agent"}:{},...typeof i.rationale=="string"?{rationale:i.rationale}:{},...p("x")?{x:p("x")}:{},...p("y")?{y:p("y")}:{},...h.length>0?{metrics:h}:{},...p("color")?{color:p("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 ei(e,n){var i;const r=Fe(e,n);return(r==null?void 0:r.chart)==="table"&&(((i=r.metrics)==null?void 0:i.length)??0)<=1&&r.decisionSource!=="authored"&&r.decisionSource!=="user"?{...r,chart:void 0}:r}function Ct(e){const n=Ge(e.dqlArtifact);if(n)return n;const r=e.researchRun&&typeof e.researchRun=="object"&&!Array.isArray(e.researchRun)?e.researchRun:void 0;return Ge(r==null?void 0:r.dqlArtifact)}function ti(e){return e?"View compiled SQL preview":"View SQL preview"}function Ot({text:e,t:n,title:r="Copy"}){const[i,s]=g.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(bt,{size:12}):t.jsx(kr,{size:12}),i?"Copied":null]})}function oe(e){return e.payload&&typeof e.payload=="object"&&!Array.isArray(e.payload)?e.payload:{}}function to(e){var i,s,o;const n=[],r=new Set;for(const a of e.artifacts){const c=oe(a),d=Array.isArray(c.memoryContext)?c.memoryContext:[];for(const h of d){if(!h||typeof h!="object")continue;const l=h,u=typeof l.title=="string"?l.title.trim():"";!u||r.has(`m:${u}`)||(r.add(`m:${u}`),n.push({kind:"memory",id:typeof l.id=="string"?l.id:void 0,label:u,detail:typeof l.content=="string"?l.content:void 0}))}const p=Array.isArray(c.appliedHints)?c.appliedHints:[];for(const h of p){if(!h||typeof h!="object")continue;const l=h,u=typeof l.title=="string"?l.title.trim():"";if(!u||r.has(`h:${u}`))continue;r.add(`h:${u}`);const f=typeof((i=l.lesson)==null?void 0:i.rule)=="string"?l.lesson.rule:typeof l.guidance=="string"?l.guidance:void 0,x=[typeof l.scopeReason=="string"?l.scopeReason:void 0,typeof l.graphReason=="string"?l.graphReason:void 0].filter(Boolean).join("; "),m=typeof((s=l.matchSignals)==null?void 0:s.lexicalScore)=="number"?l.matchSignals.lexicalScore:void 0,v=typeof((o=l.matchSignals)==null?void 0:o.graphScore)=="number"?l.matchSignals.graphScore:void 0,A=m!==void 0||v!==void 0?`Signals: lexical ${(m??0).toFixed(2)}, graph ${(v??0).toFixed(2)}`:void 0;n.push({kind:"hint",id:typeof l.hintId=="string"?l.hintId:void 0,label:u,detail:[f,x?`Matched: ${x}`:void 0,A].filter(Boolean).join(" · ")||void 0})}}return n.slice(0,6)}function ni({run:e,t:n}){const[r,i]=g.useState(!1),[s,o]=g.useState(new Set),a=g.useMemo(()=>to(e).filter(d=>!d.id||!s.has(d.id)),[e,s]);if(a.length===0)return null;const c=async d=>{try{await se.deleteAgentMemory(d),o(p=>new Set(p).add(d))}catch{}};return t.jsxs("div",{style:{display:"grid",gap:6,gridTemplateColumns:"minmax(0, 1fr)",minWidth:0},children:[t.jsxs("button",{type:"button",onClick:()=>i(d=>!d),style:ro(n),children:[t.jsx(Wt,{size:11}),t.jsxs("span",{children:["Applied ",a.length," learning",a.length>1?"s":""]}),r?t.jsx(wr,{size:11}):t.jsx(Ut,{size:11})]}),r?t.jsxs("div",{style:io(n),children:[a.map(d=>t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-start"},children:[t.jsx("span",{style:so(n,d.kind),children:d.kind==="hint"?"governed lesson":"memory"}),t.jsxs("div",{style:{minWidth:0,flex:1},children:[t.jsx("div",{style:{fontSize:11.5,fontWeight:650,color:n.textPrimary},children:d.label}),d.detail?t.jsx("div",{style:{fontSize:11,color:n.textMuted,lineHeight:1.4,marginTop:1},children:d.detail}):null]}),d.kind==="memory"&&d.id?t.jsx("button",{type:"button",onClick:()=>void c(d.id),style:oo(n),children:"Stop using"}):null]},`${d.kind}:${d.label}`)),t.jsx("div",{style:{fontSize:10.5,color:n.textMuted},children:"Advisory only — learnings never override a certified answer. Manage them under Settings → Agent learning."})]}):null]})}function In(e){const n=[],r=new Set,i=e.trustState==="certified",s=(o,a)=>{typeof o!="string"||!o.trim()||r.has(o)||(r.add(o),n.push({label:o,certified:a}))};for(const o of e.artifacts){const a=oe(o);o.ref&&s(o.ref,i);const c=a.plan&&typeof a.plan=="object"?a.plan:void 0;Array.isArray(c==null?void 0:c.sources)&&c.sources.forEach(d=>s(d,i)),s(a.sourceCertifiedBlock,!0)}return n.slice(0,4)}function Ie(e){for(const n of e.artifacts){const r=oe(n),i=r.researchRun&&typeof r.researchRun=="object"?r.researchRun:void 0,s=r.result&&typeof r.result=="object"&&!Array.isArray(r.result)?r.result:void 0,o=Ge(r.dqlArtifact),a=r.proposedSql??r.sql??r.sqlPreview??(s==null?void 0:s.sql)??(i==null?void 0:i.generatedSql)??(i==null?void 0:i.reviewedSql)??(o==null?void 0:o.compiledSql);if(typeof a=="string"&&a.trim())return a}}function dn(e){var n;if(e.trustState==="certified")for(const r of e.artifacts){const i=oe(r),s=i.blockName??i.blockId??((n=Ge(i.dqlArtifact))==null?void 0:n.name);if(typeof s=="string"&&s.trim())return s.trim()}}function no(e){for(const n of e.artifacts){const r=oe(n),i=ze(r);if(!i)continue;const s=Fe(r,i);if(s)return s}}function Te(e){for(const n of e.artifacts){const r=oe(n),i=Ge(r.dqlArtifact);if(i)return i;const s=r.researchRun&&typeof r.researchRun=="object"&&!Array.isArray(r.researchRun)?r.researchRun:void 0,o=Ge(s==null?void 0:s.dqlArtifact);if(o)return o}}function Ht(e){const n=e.route==="dql_block_draft"&&e.status!=="blocked"&&e.status!=="cancelled"&&e.stopReason!=="cancelled"&&e.status!=="needs_clarification";if(e.route==="certified_answer"||!kt(e)&&!n)return;const r=Te(e),i=Ie(e);if(!((!(r!=null&&r.source)||r.sourcePath)&&!i)){for(const s of e.artifacts){const o=oe(s),a=ze(o),c=Zt(o);if(a)return{sql:i,dqlArtifact:r,result:a,chartConfig:Fe(o,a),title:(r==null?void 0:r.name)??s.title??e.question,mixedSourcePlan:c,sourceRunId:e.id,question:e.question,executionTarget:e.executionTarget};if(c)return{sql:i,dqlArtifact:r,title:(r==null?void 0:r.name)??s.title??e.question,mixedSourcePlan:c,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 Zt(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 ri(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 ro(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 io(e){return{display:"grid",gap:8,padding:10,borderRadius:8,background:e.cellBg,border:`1px solid ${e.headerBorder}`}}function so(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 oo(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 ao(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 pr(e){return{...ao(e),width:40,height:40}}function Qt(e){return{...Kt(e,{variant:"secondary",size:"md",pill:!0}),fontWeight:550}}function lo(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 fr(e,n){return{...Kt(e,{variant:n?"primary":"secondary",size:"lg"}),...n?{}:{color:e.textMuted}}}function gr(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 co(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 uo(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 hr(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 xr(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 po(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 fo(e){return{alignSelf:"flex-start",maxWidth:"92%",color:e.textPrimary,border:`1px solid ${e.cellBorder}`,background:e.appBg,borderRadius:10,padding:"10px 12px"}}function go(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 bn(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 ho(e){return{border:`1px solid ${e.headerBorder}`,background:e.cellBg,borderRadius:8,padding:9,fontSize:12.5,color:e.textPrimary,lineHeight:1.45}}function St(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 yr(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 Z(e){return Kt(e,{variant:"secondary",size:"sm"})}const Vt={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."},orchestration_budget:{title:"Ask could not freeze one executable plan",hint:"Nothing was run. Ask stopped its own planning loop before another provider call; narrow the metric or dimension and retry."},host:{title:"DQL hit an internal error",hint:"This is a defect in DQL. The detail below is what to report."},modeling_gap:{title:"The governed model does not cover this question",hint:"No query ran. Add or review the missing metric, dimension, relationship, or allocation rule."},proof_integrity:{title:"Not executed: exact semantic proof was not established",hint:"DQL could not establish the exact metric, requested grain, join keys, and fanout proof. Warehouse success cannot create that authority."},identity_integrity:{title:"DQL found an internal identity or target-binding defect",hint:"No query ran. This is an orchestration integrity defect, not missing business modeling."},policy:{title:"Policy or permissions blocked this query",hint:"No AI repair was attempted. Use only the server-provided access or connection actions."},result_contract:{title:"The warehouse result did not match the frozen plan",hint:"The query ran, but DQL rejected the returned columns, types, grain, or row bound."},compile:{title:"DQL could not compile the frozen plan",hint:"The query did not reach the warehouse. Review the exact plan binding and compiler diagnostic."},timeout:{title:"This run reached its hard deadline",hint:"DQL stopped the run at its request-owned deadline and did not accept a later result."},cancel:{title:"This run was cancelled",hint:"Cancellation is terminal and no later provider or warehouse result was accepted."},unknown:{title:"The query could not be completed",hint:"Inspect the details or use the bounded repair when it is available."}};function ii(e){var n,r,i,s,o,a,c,d,p,h,l;if(e.status==="cancelled"||e.stopReason==="cancelled"||e.route==="cancelled"||((r=(n=e.diagnosticReceipt)==null?void 0:n.failure)==null?void 0:r.code)==="RUN_CANCELLED")return"cancel";for(const u of e.artifacts??[]){const f=oe(u),x=(i=f==null?void 0:f.warehouseFailure)==null?void 0:i.origin,m=typeof((s=f==null?void 0:f.analyticalFailure)==null?void 0:s.code)=="string"?f.analyticalFailure.code:"";if((f==null?void 0:f.refusalCode)==="modeling_gap")return"modeling_gap";if(((o=f==null?void 0:f.aggregationSafetyProof)==null?void 0:o.status)==="blocked")return"proof_integrity";if(["IDENTIFIER_SCOPE_INVALID","EXECUTION_TARGET_MISMATCH","SEMANTIC_TARGET_BINDING_MISSING","SEMANTIC_SOURCE_DRIFT"].includes(m))return"identity_integrity";if(["POLICY_DENIED","PERMISSION_DENIED"].includes(m))return"policy";if(m==="RESULT_CONTRACT_MISMATCH")return"result_contract";if(["TIMEOUT","SEMANTIC_COMPILATION_TIMEOUT"].includes(m))return"timeout";if(m==="EXECUTION_CANCELLED")return"cancel";if(["COMPILATION_FAILED","DIALECT_ERROR","SEMANTIC_ADAPTER_NOT_READY"].includes(m))return"compile";if(typeof x=="string"&&x in Vt)return x;if(((a=f==null?void 0:f.providerFailure)==null?void 0:a.code)==="orchestration_budget_exhausted"||((c=f==null?void 0:f.providerFailure)==null?void 0:c.code)==="PROVIDER_DISPATCH_BUDGET_EXHAUSTED")return"orchestration_budget";if(f!=null&&f.providerFailure||(f==null?void 0:f.refusalCode)==="provider_error")return"provider";if((f==null?void 0:f.refusalCode)==="ambiguous")return"ambiguity";if((f==null?void 0:f.refusalCode)==="grounding_gap")return"retrieval_gap"}return((p=(d=e.diagnosticReceipt)==null?void 0:d.failure)==null?void 0:p.code)==="orchestration_budget_exhausted"?"orchestration_budget":((l=(h=e.diagnosticReceipt)==null?void 0:h.failure)==null?void 0:l.code)==="AI_PROVIDER_FAILURE"?"provider":"unknown"}function si(e){for(const n of e.artifacts??[]){const r=oe(n),s=(Array.isArray(r.validationWarnings)?r.validationWarnings.filter(o=>typeof o=="string"):[]).find(o=>/captur|reusable DQL block|save as (?:a )?block/i.test(o));if(s)return s}}function oi(e){const n=e.repairCapability;return(n==null?void 0:n.version)===1&&n.automatic.eligible===!0&&n.automatic.action==="repair_embedded_sql"&&n.automatic.correctionCode==="SQL_EXECUTION_REPAIR"&&n.automatic.attemptsRemaining>0&&n.routeLocked===!0&&n.targetLocked===!0&&n.sourceImmutable===!0}function xo({run:e,detail:n,threadId:r,onRepaired:i,t:s}){const o=ii(e),a=Vt[o]??Vt.unknown,[c,d]=g.useState(!1),[p,h]=g.useState(null),l=oi(e),u=async()=>{if(!c){d(!0),h(null);try{const f=await se.repairAgentRunExecution(e.id,r);i(f.run)}catch(f){h(f instanceof Error?f.message:String(f))}finally{d(!1)}}};return t.jsxs("div",{"data-followup":"answer",style:{display:"flex",flexDirection:"column",gap:6,padding:"11px 13px",borderRadius:9,border:`1px solid ${s.error}33`,background:`${s.error}0d`},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7},children:[t.jsx(tt,{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:Ae(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:c,onClick:()=>void u(),style:{...Z(s),opacity:c?.7:1},children:[t.jsx(Yt,{size:12})," ",c?"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,p?t.jsx("div",{role:"alert",style:{fontSize:11.5,lineHeight:1.45,color:s.error},children:Ae(p)}):null]})}function ai(e){var r,i,s;for(const o of e.artifacts??[]){const a=oe(o),c=a==null?void 0:a.warehouseFailure,d=[c==null?void 0:c.redactedMessage,c==null?void 0:c.diagnostic,a==null?void 0:a.executionError,(r=a==null?void 0:a.refusalDetails)==null?void 0:r.message].find(p=>typeof p=="string"&&p.trim().length>0);if(d)return d}const n=yo(e);return n||e.summary||((s=(i=e.diagnosticReceipt)==null?void 0:i.failure)==null?void 0:s.message)}function yo(e){var r;const n=[z((r=z(e.diagnosticReceipt))==null?void 0:r.resolvedAnalyticalPlan),...(e.artifacts??[]).flatMap(i=>{var o;const s=oe(i);return[z(s.resolvedAnalyticalPlan),z((o=z(s.diagnosticReceipt))==null?void 0:o.resolvedAnalyticalPlan)]})].filter(i=>!!i);for(const i of n){const s=z(i.query),a=[...be(s==null?void 0:s.measures).map(p=>({kind:"metric",binding:p})),...be(s==null?void 0:s.dimensions).map(p=>({kind:"dimension",binding:p})),...be(s==null?void 0:s.filters).flatMap(p=>{const h=z(p.binding);return h?[{kind:"filter",binding:h}]:[]})].find(({binding:p})=>p.status==="ambiguous"||p.status==="unresolved");if(!a)continue;const c=C(a.binding.requested)||`requested ${a.kind}`,d=Array.isArray(a.binding.candidateIds)?a.binding.candidateIds.filter(p=>typeof p=="string").map(mo):[];return a.binding.status==="ambiguous"&&d.length>1?`I found more than one governed ${a.kind} for “${c}”: ${d.join(" or ")}. Choose one before I run the query.`:`I couldn’t identify one governed ${a.kind} for “${c}”. Review that model binding before retrying.`}}function mo(e){return(e.split(/[:./]/).filter(Boolean).at(-1)??e).replace(/[_-]+/g," ").replace(/\b\w/g,r=>r.toUpperCase())}const Io=Object.freeze(Object.defineProperty({__proto__:null,ASK_FAILURE_PRESENTATION:Vt,RESEARCH_TOOL_ROWS_CONSENT_TITLE:$r,UnifiedAgentRunPanel:Rs,agentRunHistoryFromItems:Tr,agentRunPerformanceRows:Vr,analyticalInspectorContract:Qr,analyticalInspectorSections:Ps,analyticalRepairActionLabels:Fs,appPinDestinationLabel:xn,artifactReadyPayloadFromRun:Ht,artifactSqlDisclosureLabel:ti,askAppDestinations:Gr,askAppWriteErrorMessage:hn,askArtifactMeta:Xt,askFailureDetail:ai,askFailureOrigin:ii,askInspectorTabsForState:Fr,askRunAllowsExecutionRepair:oi,askRunCaptureWarning:si,clarificationSelectionInput:Nt,completedRunGuidanceFor:Nr,deriveResultChartConfig:zi,extractResult:ze,hasAnalyticalInspectorContract:Jt,inlineAskChartConfig:ei,isAgentRunPinnable:kt,liveAgentActivityFor:Pr,longRunGuidanceFor:Dr,preferredAskInspectorTab:Cn,replacePresentedAgentRun:zr,researchSourceFromRun:Ur,resolveArtifactDqlView:Ct,resolveComposerRequestedMode:_r,resolvedParameterValues:yn,selectAgentExecutionConnection:Br,threadItemsFromTurns:Lr,trustExplainer:Rn,usePersistedAgentThreadId:Ti},Symbol.toStringTag,{value:"Module"}));export{cs as B,wr as C,Kn as S,Rs as U,Zi as a,os as b,Io as c};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{u as x,r as w,a as k,m}from"./index-
|
|
1
|
+
import{u as x,r as w,a as k,m}from"./index-zHHzDn6l.js";const C="dql:focus-notebook-cell";function h(e){window.setTimeout(()=>{window.dispatchEvent(new CustomEvent(C,{detail:{cellId:e}}))},0)}function S(e){var t,a,c;const i=(t=e.question)==null?void 0:t.trim(),n=(a=e.generatedSql)==null?void 0:a.trim(),s=(c=e.generatedDql)==null?void 0:c.trim();if(!(!i||!n&&!s))return{version:1,source:"agent_run",question:i,...n?{generatedSql:n}:{},...s?{generatedDql:s}:{},...e.sourceRunId?{sourceRunId:e.sourceRunId}:{}}}function g(e){return e.replace(/[^a-zA-Z0-9_ -]+/g," ").replace(/\s+/g,"_").replace(/^_+|_+$/g,"").slice(0,48)||"ai_analysis"}function E(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function I(e,i){var c,o,u,f,l,q;const n=(o=(c=e.dqlArtifact)==null?void 0:c.source)==null?void 0:o.trim(),s=(e.sql??n??"").trim();if(!s&&!n)return[];if(e.mixedSourcePlan){const r=e.mixedSourcePlan,A=m("markdown",[`### ${e.title??"Mixed-source analysis"}`,"",`This analysis combines a bounded warehouse extraction with the local dataset \`${r.localDataset}\`.`,"",...(u=r.warehouseRelations)!=null&&u.length?[`- Warehouse sources: ${r.warehouseRelations.map(b=>`\`${b}\``).join(", ")}`]:[],`- Join: \`${r.warehouseKey}\` = \`${r.localKey}\``,"- Trust: local mixed-source analysis · review required"].join(`
|
|
2
2
|
`));A.name=g("Analysis context");const d=m("sql",s);return d.name=g(e.title??"Warehouse extraction"),d.mixedSourcePlan=r,d.executionTarget=((f=e.executionTarget)==null?void 0:f.target)==="connection"?e.executionTarget:{target:"connection"},d.datasetRefs=[{id:r.datasetId??r.localDataset,alias:r.localDataset,role:"source"}],[A,d]}const t=m(n?"dql":"sql",n||s);t.name=g(e.title??((l=e.dqlArtifact)==null?void 0:l.name)??"AI analysis"),e.result&&(t.result=e.result,t.status="success",t.executionCount=1),e.chartConfig&&(t.chartConfig=e.chartConfig),e.executionTarget&&(t.executionTarget=e.executionTarget),t.correctionProvenance=S({question:e.question,generatedSql:e.sql??((q=e.dqlArtifact)==null?void 0:q.compiledSql),generatedDql:n,sourceRunId:e.sourceRunId}),e.dqlArtifact&&(t.dqlArtifact={source:e.dqlArtifact.source,sql:e.sql,name:e.dqlArtifact.name,sourcePath:e.dqlArtifact.sourcePath,kind:e.dqlArtifact.kind,metrics:e.dqlArtifact.metrics,dimensions:e.dqlArtifact.dimensions,parameters:e.dqlArtifact.parameters,parameterValues:e.dqlArtifact.parameterValues,persistence:e.dqlArtifact.persistence,trustState:e.dqlArtifact.trustState,compiledSql:e.dqlArtifact.compiledSql??e.sql,...e.question?{question:e.question}:{}},t.dqlParameterValues=e.dqlArtifact.parameterValues);const a=i.filter(r=>new RegExp(`\\b${E(r.alias)}\\b`,"i").test(s)).map(r=>({id:r.id,alias:r.alias,role:r.storageMode==="staged"?"staged":"source",fingerprint:r.fileFingerprint}));return a.length>0&&(t.executionTarget={target:"local"},t.datasetRefs=a,t.dqlArtifact&&(t.dqlArtifact.reviewState="review_required")),[t]}function _(e){return(e??"ai analysis").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)||"ai-analysis"}function v(){const{state:e,dispatch:i}=x();return w.useCallback(async(n,s)=>{var f;const t=I(n,(s==null?void 0:s.datasets)??[]);if(t.length===0)return;if(e.activeFile&&e.activeFile.type!=="block"){let l=s==null?void 0:s.afterId;for(const q of t)i({type:"ADD_CELL",cell:q,...l?{afterId:l}:{}}),l=q.id;h(t[t.length-1].id);return}const a=n.title??((f=n.dqlArtifact)==null?void 0:f.name)??"AI analysis",c=_(a);let o=`notebooks/${c}.dqlnb`;try{o=(await k.createNotebook(c,"blank")).path}catch{}const u={name:o.split("/").pop()??`${c}.dqlnb`,path:o,type:"notebook",folder:"notebooks",isNew:!0};i({type:"FILE_ADDED",file:u}),i({type:"OPEN_FILE",file:u,cells:t,title:a}),h(t[t.length-1].id)},[i,e.activeFile])}export{C as N,S as c,h as f,v as u};
|