@duckcodeailabs/dql-cli 1.12.11 → 1.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apps-api.d.ts +151 -3
- package/dist/apps-api.d.ts.map +1 -1
- package/dist/apps-api.js +675 -97
- package/dist/apps-api.js.map +1 -1
- package/dist/args.d.ts +2 -0
- package/dist/args.d.ts.map +1 -1
- package/dist/args.js +3 -0
- package/dist/args.js.map +1 -1
- package/dist/assets/dql-notebook/assets/AgentAnswerCard-c8QUo6NH.js +5 -0
- package/dist/assets/dql-notebook/assets/{AgentLogPage-hzHqpD3-.js → AgentLogPage-D6fgEAEy.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildDialog-BQRWoxp9.js → AiBuildDialog-8miXFPse.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildResult-D9t_4sQl.js → AiBuildResult-DPJ_SI0R.js} +3 -3
- package/dist/assets/dql-notebook/assets/AiSidePanel-NVA6lZnn.js +6 -0
- package/dist/assets/dql-notebook/assets/AnalyticsHome-DgwnRW71.js +6 -0
- package/dist/assets/dql-notebook/assets/AppsView-B6LYUpgm.js +4578 -0
- package/dist/assets/dql-notebook/assets/BlockStudio--jNw9XUI.js +60 -0
- package/dist/assets/dql-notebook/assets/{BusinessArtifactView-CnTbFVGT.js → BusinessArtifactView-DtRMiaF4.js} +1 -1
- package/dist/assets/dql-notebook/assets/DbtFirstModelingPage-DhBsLCYr.js +22 -0
- package/dist/assets/dql-notebook/assets/GitPage-CazC-eTR.js +7 -0
- package/dist/assets/dql-notebook/assets/GlobalAiRail-1Tgweuu2.js +1 -0
- package/dist/assets/dql-notebook/assets/GovernedContextPage-C7qGrH3d.js +16 -0
- package/dist/assets/dql-notebook/assets/{HelpDocsPage-CL0vbSER.js → HelpDocsPage-DMHPsVqP.js} +1 -1
- package/dist/assets/dql-notebook/assets/{HomePage-DzAucwBW.js → HomePage-DcSI4dnU.js} +1 -1
- package/dist/assets/dql-notebook/assets/LineageDAG-BJ6xz06u.js +1 -0
- package/dist/assets/dql-notebook/assets/{LineageDetailView-DdVH-nz6.js → LineageDetailView-8WrQm-MF.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDrawer-BvrVZNKY.js → LineageDrawer-hnqCW_t-.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineagePathBreadcrumb-CSut-zvm.js → LineagePathBreadcrumb-B4LZTUsl.js} +3 -3
- package/dist/assets/dql-notebook/assets/{MiniLineageGraph-zg_1wW3M.js → MiniLineageGraph-CotnRuxa.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewBlockModal-9cDletl-.js → NewBlockModal-DHn-CEEW.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewNotebookModal-V6de8L4d.js → NewNotebookModal-BPGp-8oq.js} +2 -2
- package/dist/assets/dql-notebook/assets/NotebookEditor-B0OTHM6W.js +195 -0
- package/dist/assets/dql-notebook/assets/ReadinessPage-CoOIpxWq.js +1 -0
- package/dist/assets/dql-notebook/assets/{SetupOnboarding-Bg-MjbC9.js → SetupOnboarding-DxK_mFzf.js} +2 -2
- package/dist/assets/dql-notebook/assets/{TrustBadge-DGuHB8kP.js → TrustBadge-ZuD5N5Ww.js} +1 -1
- package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-duFXXNV_.js +88 -0
- package/dist/assets/dql-notebook/assets/{answer-to-notebook-BDzY4MuQ.js → answer-to-notebook-WAVAYjBv.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-left-IjlnAihE.js → arrow-left-L8odLbyN.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-right-BI4cXgOY.js → arrow-right-WIF1V9a9.js} +1 -1
- package/dist/assets/dql-notebook/assets/{book-open-text-i6xhxu_I.js → book-open-text-BpqWMa4m.js} +1 -1
- package/dist/assets/dql-notebook/assets/{bot-C6DE7Q6m.js → bot-CLR1V6dO.js} +1 -1
- package/dist/assets/dql-notebook/assets/{circle-x-BoAorVSm.js → circle-x-CQBOM0b0.js} +1 -1
- package/dist/assets/dql-notebook/assets/{dagre.esm-CycymVj6.js → dagre.esm-DlZi7NR3.js} +1 -1
- package/dist/assets/dql-notebook/assets/{external-link-ZwE5iHsX.js → external-link-DYqdQIGp.js} +1 -1
- package/dist/assets/dql-notebook/assets/{grip-vertical-Dnp2st8l.js → grip-vertical-HmUijbwN.js} +1 -1
- package/dist/assets/dql-notebook/assets/index-Cpx47jCH.js +634 -0
- package/dist/assets/dql-notebook/assets/{list-tree-Ced8e_S1.js → list-tree-DGKqCxmz.js} +1 -1
- package/dist/assets/dql-notebook/assets/{minimize-2-CBIAE0XH.js → minimize-2-C8dvqCxX.js} +1 -1
- package/dist/assets/dql-notebook/assets/{panel-right-open-po3bWSeL.js → panel-right-open-yuVkIo5n.js} +1 -1
- package/dist/assets/dql-notebook/assets/{rotate-ccw-B9v1LTJ0.js → rotate-ccw-Di0kRnrM.js} +1 -1
- package/dist/assets/dql-notebook/assets/{semantic-fields-B6ii0an0.js → semantic-fields-BMQV0li8.js} +1 -1
- package/dist/assets/dql-notebook/assets/sliders-horizontal-alebptlJ.js +6 -0
- package/dist/assets/dql-notebook/assets/{star-CO4tfaDq.js → star-CgCQbnXc.js} +1 -1
- package/dist/assets/dql-notebook/assets/{triangle-alert-BSdIu2El.js → triangle-alert-SyuSZ4ht.js} +1 -1
- package/dist/assets/dql-notebook/assets/upload-BPhfea_E.js +11 -0
- package/dist/assets/dql-notebook/assets/usePersistedAgentThreadId-Bnl9gWhj.js +28 -0
- package/dist/assets/dql-notebook/assets/{user-round-BfrV8U-W.js → user-round-J4PQHxo9.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wand-sparkles-BgTxZNBc.js → wand-sparkles-c4WDXTCk.js} +1 -1
- package/dist/assets/dql-notebook/assets/{workflow--2ycp0yy.js → workflow-NtRLaq7n.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wrench-LMCrpa9_.js → wrench-CS1f1Zv4.js} +1 -1
- package/dist/assets/dql-notebook/assets/{x-CeNgQwGm.js → x-CbKEfe5m.js} +1 -1
- package/dist/assets/dql-notebook/index.html +1 -1
- package/dist/commands/model.d.ts.map +1 -1
- package/dist/commands/model.js +62 -1
- package/dist/commands/model.js.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/llm/providers/dql-agent-provider.d.ts +4 -3
- package/dist/llm/providers/dql-agent-provider.d.ts.map +1 -1
- package/dist/llm/providers/dql-agent-provider.js +13 -10
- package/dist/llm/providers/dql-agent-provider.js.map +1 -1
- package/dist/local-operation-coordinator.d.ts +59 -0
- package/dist/local-operation-coordinator.d.ts.map +1 -0
- package/dist/local-operation-coordinator.js +256 -0
- package/dist/local-operation-coordinator.js.map +1 -0
- package/dist/local-runtime.d.ts +59 -1
- package/dist/local-runtime.d.ts.map +1 -1
- package/dist/local-runtime.js +2653 -342
- package/dist/local-runtime.js.map +1 -1
- package/dist/package.json +12 -11
- package/dist/project-refresh-coordinator.d.ts +19 -0
- package/dist/project-refresh-coordinator.d.ts.map +1 -0
- package/dist/project-refresh-coordinator.js +134 -0
- package/dist/project-refresh-coordinator.js.map +1 -0
- package/dist/project-refresh-worker.d.ts +13 -0
- package/dist/project-refresh-worker.d.ts.map +1 -0
- package/dist/project-refresh-worker.js +58 -0
- package/dist/project-refresh-worker.js.map +1 -0
- package/package.json +13 -11
- package/dist/assets/dql-notebook/assets/AgentAnswerCard-CpL2kDCV.js +0 -5
- package/dist/assets/dql-notebook/assets/AiSidePanel-BCQB9rVF.js +0 -6
- package/dist/assets/dql-notebook/assets/AnalyticsHome-Ba4Ve_Gd.js +0 -6
- package/dist/assets/dql-notebook/assets/AppsView-CdAT9BOq.js +0 -4466
- package/dist/assets/dql-notebook/assets/BlockStudio-Brg4fwn5.js +0 -60
- package/dist/assets/dql-notebook/assets/DbtFirstModelingPage-CQe2FUZq.js +0 -22
- package/dist/assets/dql-notebook/assets/GitPage-DHyDBChc.js +0 -7
- package/dist/assets/dql-notebook/assets/GlobalAiRail-Cys4n_rq.js +0 -1
- package/dist/assets/dql-notebook/assets/GovernedContextPage-DyKoDSZ2.js +0 -7
- package/dist/assets/dql-notebook/assets/LineageDAG-QHqd_AM5.js +0 -1
- package/dist/assets/dql-notebook/assets/NotebookEditor-EZ0pfWVs.js +0 -200
- package/dist/assets/dql-notebook/assets/ReadinessPage-BaGvjyfd.js +0 -1
- package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-BlWAVEwO.js +0 -83
- package/dist/assets/dql-notebook/assets/chevron-up-DSEILnDs.js +0 -6
- package/dist/assets/dql-notebook/assets/index-BTuliKhK.js +0 -634
- package/dist/assets/dql-notebook/assets/link-2-CTKe6Snr.js +0 -6
- package/dist/assets/dql-notebook/assets/maximize-2-Cojc6867.js +0 -6
- package/dist/assets/dql-notebook/assets/pencil-Cb45c6WU.js +0 -6
- package/dist/assets/dql-notebook/assets/usePersistedAgentThreadId-CkVFrrjk.js +0 -18
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import{c as qe,r as f,a as ne,j as t,d as Bt,g as st,l as xe,aZ as Yr,f as ot,L as Qe,aH as Jr,a$ as ir,B as dt,e as sr,u as $t,t as or,a5 as Xr,b0 as Je,E as Zr,H as ei,b1 as ti,w as ni,S as Ve,aE as lr,b as Et,a_ as Xe,P as rt,D as ri,G as ar,b2 as ii,aY as Zt,a0 as Ot}from"./index-Cpx47jCH.js";import{S as At,R as cn,d as si}from"./AgentAnswerCard-c8QUo6NH.js";import{S as oi,P as li,F as lt,M as ai,d as dn,e as ci,A as di,u as ui}from"./usePersistedAgentThreadId-Bnl9gWhj.js";import{C as pi}from"./AiBuildResult-DPJ_SI0R.js";import{T as Ht}from"./triangle-alert-SyuSZ4ht.js";import{U as fi}from"./user-round-J4PQHxo9.js";import{X as qt}from"./x-CbKEfe5m.js";import{L as at}from"./list-tree-DGKqCxmz.js";import{W as Mt}from"./wrench-CS1f1Zv4.js";import{M as gi}from"./minimize-2-C8dvqCxX.js";import{A as hi}from"./arrow-right-WIF1V9a9.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 xi=[["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"}]],yi=qe("archive",xi);/**
|
|
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 mi=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],cr=qe("chevron-up",mi);/**
|
|
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 bi=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],vi=qe("circle",bi);/**
|
|
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 ji=[["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"}]],dr=qe("copy",ji);/**
|
|
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 Si=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],wi=qe("ellipsis",Si);/**
|
|
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 ki=[["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"}]],Ct=qe("lightbulb",ki);/**
|
|
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 Ai=[["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"}]],en=qe("route",Ai);/**
|
|
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 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"}]],un=qe("save",qi);/**
|
|
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 Ci=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],Tn=qe("square",Ci);/**
|
|
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 zi=[["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"}]],Ri=qe("zap",zi),Qt=[{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 Bn({t:e,value:n,onChange:r}){const[i,s]=f.useState(null),[o,a]=f.useState(!1),d=f.useRef(null);f.useEffect(()=>{let g=!1;return ne.getProviderSettings().then(({providers:l})=>{g||s(l.find(c=>c.active)??null)}).catch(()=>{}),()=>{g=!0}},[]),f.useEffect(()=>{if(!o)return;const g=l=>{d.current&&!d.current.contains(l.target)&&a(!1)};return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[o]);const u=Qt.find(g=>g.mode===n)??Qt[0],x=i?[i.label,i.model].filter(Boolean).join(" · "):null;return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[x?t.jsxs("span",{title:"Connected model",style:$n(e),children:[t.jsx(vi,{size:7,fill:e.success,color:e.success}),t.jsx("span",{style:{color:e.textSecondary},children:x})]}):null,t.jsxs("div",{ref:d,style:{position:"relative"},children:[t.jsxs("button",{type:"button",onClick:()=>a(g=>!g),title:"How hard the model thinks for this thread",style:{...$n(e),cursor:"pointer"},children:[t.jsx(Ri,{size:12,color:e.textMuted}),t.jsxs("span",{style:{color:e.textSecondary},children:["Thinking: ",u.label]}),t.jsx(Bt,{size:12,color:e.textMuted})]}),o?t.jsx("div",{role:"menu",style:_i(e),children:Qt.map(g=>{const l=g.mode===n;return t.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":l,onClick:()=>{r(g.mode),a(!1)},style:Ii(e,l),children:[t.jsxs("span",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[t.jsx("span",{style:{fontWeight:l?600:500,color:e.textPrimary},children:g.label}),l?t.jsx(st,{size:13,color:e.accent}):null]}),t.jsx("span",{style:{display:"block",fontSize:11,color:e.textMuted,marginTop:2},children:g.hint})]},g.mode)})}):null]})]})}function $n(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 _i(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 Ii(e,n){return{display:"block",width:"100%",textAlign:"left",padding:"8px 10px",borderRadius:7,border:"none",background:n?e.pillBg:"transparent",cursor:"pointer"}}const Ti={draft:"#8b949e",review:"#d29922",certified:"#3fb950",deprecated:"#f85149",pending_recertification:"#db6d28"},Bi={queued:"#8b949e",generating:"#4c8dff",running:"#4c8dff",saving:"#4c8dff",saved:"#2ea043",ready:"#2ea043",blocked:"#f85149",needs_attention:"#d29922"},$i={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"},Ei={draft:ir,queued:Jr,generating:Qe,running:Qe,saving:Qe,ready:ot,saved:ot,blocked:Ht,needs_attention:Ht,review:Yr,certified:xe,deprecated:yi,pending_recertification:Ht},Mi=new Set(["generating","running","saving"]);function Li(e){return Ti[e]??Bi[e]??"#8b949e"}function Wi(e){return $i[e]??e.charAt(0).toUpperCase()+e.slice(1).replace(/_/g," ")}function Fi({status:e,t:n,label:r}){const i=Li(e),s=Ei[e]??ir,o=r??Wi(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:Mi.has(e)?"spin":void 0}),o]})}function Di(e){const{t:n,name:r,status:i="draft",description:s,dql:o,sqlPreview:a,grain:d,outputs:u=[],dimensions:x=[],entities:g=[],examples:l=[],sourceTables:c=[],evidence:m=[],certifierVerdict:h,owner:b,actions:v}=e,[q,T]=f.useState(!1),[D,U]=f.useState(!1);return t.jsxs("section",{style:{border:`1px solid ${n.cellBorder}`,borderRadius:10,background:n.cellBg,padding:14,display:"grid",gap:10,fontFamily:n.font},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[t.jsx(dt,{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(Fi,{status:i,t:n}),d?t.jsxs("span",{style:tn(n),children:["grain ",d]}):null]}),s?t.jsx("div",{style:{fontSize:12,color:n.textSecondary,lineHeight:1.5},children:s}):null,o?t.jsx(En,{open:q,onToggle:()=>T(C=>!C),label:"Governed DQL",t:n,lead:!0,children:t.jsx("pre",{style:Mn(n),children:o})}):null,a?t.jsx(En,{open:D,onToggle:()=>U(C=>!C),label:o?"Compiled SQL preview":"SQL this block will run",t:n,children:t.jsx("pre",{style:Mn(n),children:a})}):null,t.jsx(Vt,{label:"Outputs",items:u,t:n}),t.jsx(Vt,{label:"Dimensions",items:x,t:n}),t.jsx(Vt,{label:"Entities",items:g,t:n}),l.length>0?t.jsxs("div",{style:{display:"grid",gap:5},children:[t.jsx(ur,{t:n,children:"Answers questions like"}),t.jsx("ul",{style:{margin:0,padding:"0 0 0 16px",display:"grid",gap:3},children:l.slice(0,3).map(C=>t.jsx("li",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.45},children:C},C))})]}):null,c.length>0||m.length>0?t.jsxs("div",{style:{display:"grid",gap:6,border:`1px solid ${n.headerBorder}`,borderRadius:8,background:n.appBg,padding:10},children:[t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:10.5,fontWeight:800,color:n.textSecondary,textTransform:"uppercase"},children:[t.jsx(xe,{size:12,color:n.accent})," Grounded on"]}),c.length>0?t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:c.map(C=>t.jsx("span",{style:tn(n),children:C},C))}):null,m.slice(0,5).map((C,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:C.name}),t.jsxs("div",{style:{fontSize:10,color:n.textMuted,marginTop:3},children:[C.kind,C.reason?` · ${C.reason}`:""]}),C.description?t.jsx("div",{style:{fontSize:11,color:n.textMuted,lineHeight:1.35,marginTop:5},children:C.description}):null]},`${C.objectKey??C.name}-${N}`))]}):null,t.jsx(pi,{t:n,verdict:h}),b?t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11,color:n.textMuted},children:[t.jsx(fi,{size:12,strokeWidth:2})," drafting as ",b]}):null,v?t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:v}):null]})}function En({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(Bt,{size:13,strokeWidth:2}):t.jsx(sr,{size:13,strokeWidth:2}),e?`Hide ${r.toLowerCase()}`:r]}),e?t.jsx("div",{style:{marginTop:7},children:o}):null]})}function Vt({label:e,items:n,t:r}){return n.length===0?null:t.jsxs("div",{style:{display:"grid",gap:5},children:[t.jsx(ur,{t:r,children:e}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:n.map(i=>t.jsx("span",{style:tn(r),children:i},i))})]})}function ur({t:e,children:n}){return t.jsx("div",{style:{fontSize:10,fontWeight:800,letterSpacing:"0.05em",textTransform:"uppercase",color:e.textMuted},children:n})}function tn(e){return{fontSize:10.5,fontWeight:700,color:e.textSecondary,background:e.pillBg,borderRadius:999,padding:"2px 8px",fontFamily:e.fontMono}}function Mn(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 Ln(){return t.jsx("span",{style:{color:"#ff7b72",marginLeft:2},children:"*"})}function Gt(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Pi(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 Wn({cell:e,onClose:n,onSaved:r,initialContent:i,initialName:s,initialDescription:o,initialTags:a,initialDomain:d,initialOwner:u}){var Z;const{state:x,dispatch:g}=$t(),l=or[x.themeMode],c=f.useRef(null),[m,h]=f.useState(s||e.name||"new_block"),[b,v]=f.useState(d??""),[q,T]=f.useState(u??""),[D,U]=f.useState(o??x.notebookMetadata.description??""),[C,N]=f.useState((a??x.notebookMetadata.categories??[]).join(", ")),[Q,B]=f.useState(i??e.content),[W,O]=f.useState(""),[$,j]=f.useState(""),[K,J]=f.useState([]),[A,ee]=f.useState(!1),[P,X]=f.useState(null),R=f.useMemo(()=>Pi(Q),[Q]),E=f.useMemo(()=>C.split(",").map(p=>p.trim()).filter(Boolean),[C]),oe=[{id:"has-name",label:"Block has name",severity:"error",passed:!!m.trim()},{id:"has-owner",label:"Block has owner",severity:"error",passed:!!q.trim()},{id:"has-description",label:"Description",severity:"warning",passed:!!D.trim()},{id:"has-domain",label:"Domain",severity:"warning",passed:!!b.trim()},{id:"has-tags",label:"Has at least one tag",severity:"warning",passed:E.length>0},{id:"has-llm-context",label:"Has LLM context (for agents)",severity:"warning",passed:!!W.trim()}],G=oe.some(p=>p.severity==="error"&&!p.passed);f.useEffect(()=>{var p;(p=c.current)==null||p.focus()},[]),f.useEffect(()=>{const p=_=>{_.key==="Escape"&&n()};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[n]);const be=Xr(b,x.authoredDomains),ae=`${b.trim()?`blocks/${Gt(b)}/`:"blocks/"}${Gt(m)||"new-block"}.dql`,V=async()=>{var p,_,te;if(G){X("Enter the block name and owner before saving.");return}if(!Q.trim()){X("Block content is required.");return}ee(!0),X(null);try{const re=$.split(`
|
|
52
|
+
`).map(k=>k.trim()).filter(Boolean),ve=K.map(k=>({question:k.question.trim(),sql:k.sql.trim()||void 0})).filter(k=>k.question),he=await ne.saveAsBlock({cellId:e.id,notebookPath:((p=x.activeFile)==null?void 0:p.path)??null,name:m.trim(),domain:b.trim()||void 0,owner:q.trim()||void 0,content:Q,description:D.trim()||void 0,tags:E,metricRefs:R,llmContext:W.trim()||void 0,examples:ve.length>0?ve:void 0,invariants:re.length>0?re:void 0,reviewRequired:!!((_=e.datasetRefs)!=null&&_.length),datasetRefs:e.datasetRefs,lineage:(te=e.dqlArtifact)==null?void 0:te.lineage}),Fe={name:`${Gt(m)||"new-block"}.dql`,path:he.path,type:"block",folder:"blocks"};x.files.some(k=>k.path===he.path)||g({type:"FILE_ADDED",file:Fe});const De=await ne.openBlockStudio(he.path);g({type:"OPEN_BLOCK_STUDIO",file:Fe,payload:De}),r==null||r({...he,name:m.trim()}),n()}catch(re){X(re instanceof Error?re.message:String(re))}finally{ee(!1)}},w={width:"100%",background:l.inputBg,border:`1px solid ${P?l.error:l.inputBorder}`,borderRadius:6,color:l.textPrimary,fontSize:13,fontFamily:l.font,padding:"8px 12px",outline:"none",boxSizing:"border-box"};return t.jsx("div",{onClick:p=>{p.target===p.currentTarget&&n()},style:{position:"fixed",inset:0,background:l.modalOverlay,display:"flex",alignItems:"center",justifyContent:"center",zIndex:1100,backdropFilter:"blur(4px)"},children:t.jsxs("div",{style:{width:760,maxWidth:"calc(100vw - 48px)",maxHeight:"calc(100vh - 48px)",overflow:"auto",background:l.modalBg,border:`1px solid ${l.cellBorder}`,borderRadius:12,boxShadow:"0 20px 60px rgba(0,0,0,0.5)"},children:[t.jsxs("div",{style:{padding:"20px 24px 0",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsx("h2",{style:{margin:0,fontSize:16,fontWeight:600,color:l.textPrimary,fontFamily:l.font},children:"Save as Block"}),t.jsx("button",{onClick:n,style:{background:"transparent",border:"none",color:l.textMuted,cursor:"pointer",fontSize:18},children:"×"})]}),t.jsxs("div",{style:{padding:"20px 24px 24px",display:"flex",flexDirection:"column",gap:16},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsxs("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:["Block Name ",t.jsx(Ln,{})]}),t.jsx("input",{ref:c,value:m,onChange:p=>h(p.target.value),style:w})]}),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:b,onChange:p=>v(p.target.value),style:w,children:[t.jsx("option",{value:"",children:"Global / cross-domain"}),be.map(p=>t.jsx("option",{value:p.value,disabled:p.disabled,children:p.label},p.value))]})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsxs("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:["Owner ",t.jsx(Ln,{})]}),t.jsx("input",{value:q,onChange:p=>T(p.target.value),style:w,placeholder:"data-platform@company.com"})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:"Tags"}),t.jsx("input",{value:C,onChange:p=>N(p.target.value),style:w,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:p=>U(p.target.value),style:w})]}),t.jsxs("details",{style:{border:`1px solid ${l.cellBorder}`,borderRadius:6,padding:"8px 12px"},children:[t.jsx("summary",{style:{fontSize:12,fontWeight:600,color:l.textSecondary,fontFamily:l.font,cursor:"pointer"},children:"Agent-facing metadata (optional — helps AI tools ground answers on this block)"}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10,paddingTop:10},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:"How should an AI describe this block?"}),t.jsx("textarea",{value:W,onChange:p=>O(p.target.value),rows:3,placeholder:'One paragraph. E.g. "Monthly revenue recognized from closed-won deals, grouped by billing month. Excludes refunds."',style:{...w,fontFamily:l.font,lineHeight:1.5,resize:"vertical"}})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:"Invariants (one per line)"}),t.jsx("textarea",{value:$,onChange:p=>j(p.target.value),rows:2,placeholder:`Revenue is never negative
|
|
53
|
+
Each row is a unique month`,style:{...w,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)"}),K.map((p,_)=>t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr auto",gap:6},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[t.jsx("input",{value:p.question,onChange:te=>{const re=[...K];re[_]={...re[_],question:te.target.value},J(re)},placeholder:"What was revenue last month?",style:w}),t.jsx("input",{value:p.sql,onChange:te=>{const re=[...K];re[_]={...re[_],sql:te.target.value},J(re)},placeholder:"Optional SQL snippet",style:{...w,fontFamily:l.fontMono,fontSize:12}})]}),t.jsx("button",{type:"button",onClick:()=>J(K.filter((te,re)=>re!==_)),style:{background:"transparent",border:`1px solid ${l.cellBorder}`,borderRadius:6,color:l.textMuted,cursor:"pointer",fontSize:12,padding:"0 10px"},children:"×"})]},_)),t.jsx("button",{type:"button",onClick:()=>J([...K,{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:oe.map(p=>{const _=p.passed?"#3fb950":p.severity==="error"?"#ff7b72":"#e3b341",te=p.passed?"✓":p.severity==="error"?"✕":"!";return t.jsxs("span",{title:p.passed?`${p.label} — passed`:`${p.label} — ${p.severity}`,style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,fontFamily:l.font,color:_,background:`${_}18`,border:`1px solid ${_}55`,borderRadius:999,padding:"2px 10px"},children:[t.jsx("span",{style:{fontWeight:700},children:te}),p.label]},p.id)})})]}),t.jsx("div",{style:{fontSize:12,color:l.textMuted,fontFamily:l.fontMono,padding:"8px 12px",background:l.pillBg,borderRadius:6},children:ae}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:"Content Preview"}),t.jsx("textarea",{value:Q,onChange:p=>B(p.target.value),style:{...w,minHeight:220,resize:"vertical",fontFamily:l.fontMono,lineHeight:1.5}})]}),R.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:"}),R.map(p=>t.jsx("span",{style:{fontSize:11,color:l.accent,fontFamily:l.fontMono,background:`${l.accent}18`,borderRadius:999,padding:"2px 8px"},children:p},p))]}),P&&t.jsx("div",{style:{fontSize:12,color:l.error,fontFamily:l.font},children:P})]}),t.jsxs("div",{style:{padding:"14px 24px",borderTop:`1px solid ${l.cellBorder}`,display:"flex",justifyContent:"flex-end",gap:10},children:[t.jsx("span",{style:{fontSize:11.5,color:l.textMuted,marginRight:"auto",alignSelf:"center"},children:(Z=e.datasetRefs)!=null&&Z.length?"This analysis uses imported or staged data, so it will be saved as a review-required draft. Certification requires project-controlled, contracted, tested, reproducible sources.":"DQL will certify this block now when its local checks pass; otherwise it is saved as a draft."}),t.jsx("button",{onClick:n,style:{background:l.btnBg,border:`1px solid ${l.btnBorder}`,borderRadius:6,color:l.textSecondary,cursor:"pointer",fontSize:13,fontFamily:l.font,padding:"7px 16px"},children:"Cancel"}),t.jsx("button",{onClick:V,disabled:A||G,title:G?"Fix governance errors to enable Save":void 0,style:{background:l.accent,border:`1px solid ${l.accent}`,borderRadius:6,color:"#fff",cursor:A||G?"not-allowed":"pointer",fontSize:13,fontFamily:l.font,padding:"7px 20px",opacity:A||G?.5:1},children:A?"Saving & checking…":"Save block"})]})]})})}function pr(e){return e.policy==="dynamic"||e.policy==="optional"}function Ni({parameters:e,values:n,onChange:r,onReset:i,t:s,includeNonRuntime:o=!1,card:a=!1}){const d=e.filter(u=>o||pr(u));return d.length===0?null:t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(170px, 1fr))",gap:8},children:d.map(u=>{const x=Object.prototype.hasOwnProperty.call(n,u.name),g=x?n[u.name]:u.default,l=m=>r(u.name,m),c=u.type==="boolean"?t.jsxs("select",{"aria-label":u.name,value:String(g??""),onChange:m=>l(m.target.value),style:Fn(s),children:[t.jsx("option",{value:"",children:"Select…"}),t.jsx("option",{value:"true",children:"True"}),t.jsx("option",{value:"false",children:"False"})]}):t.jsx("input",{"aria-label":u.name,type:u.type==="number"?"number":u.type==="date"?"date":"text",value:Array.isArray(g)?g.join(", "):g==null?"":String(g),placeholder:u.type.endsWith("[]")?"Comma-separated values":u.required?"Required value":"Use default",onChange:m=>l(m.target.value),style:Fn(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:[Oi(u.name),u.required?t.jsx("span",{style:{color:s.error},children:"*"}):null]}),c,t.jsxs("span",{style:{display:"flex",alignItems:"center",gap:5,minHeight:14,fontSize:9.5,color:s.textMuted},children:[t.jsxs("span",{children:[u.type,o?` · ${u.policy}`:""]}),x&&i?t.jsx("button",{type:"button",onClick:()=>i(u.name),style:{marginLeft:"auto",border:0,padding:0,background:"transparent",color:s.accent,fontSize:9.5,cursor:"pointer"},children:"Reset"}):null]})]},u.name)})})}function Oi(e){return e.replace(/[_-]+/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function Fn(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 Hi(e){const n=e.filter(o=>o.kind==="run").map(Qi).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=fr(Dn(r));return nn({activeSurface:"notebook",conversationStateVersion:1,activeTurnId:r.id,activeTopic:r.question,conversationSummary:Ji(n),turns:n,sourceAnswerId:r.id,sourceCertifiedBlock:r.sourceCertifiedBlock,sourceQuestion:r.question,sourceAnswerSummary:r.answerSummary,answerContract:Dn(r),dqlArtifact:r.dqlArtifact,cascade:r.cascade,resultColumns:i==null?void 0:i.columns,resultRowsSample:i==null?void 0:i.rowsSample,resultDimensionValues:i==null?void 0:i.dimensionValues,outputColumns:i==null?void 0:i.columns,requestedFilters:r.requestedFilters??Ue(s==null?void 0:s.filters),requestedDimensions:r.requestedDimensions??Ue(s==null?void 0:s.dimensions),priorLimit:r.topN??gr(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 Qi(e){var l,c,m,h;const n=e.run.artifacts.find(b=>b.kind==="answer")??e.run.artifacts.find(b=>b.kind==="research_run")??e.run.artifacts[0],r=de(n==null?void 0:n.payload),i=Vi(r),s=Zi(i),o=Array.isArray(i==null?void 0:i.rows)?i.rows.filter(b=>!!(b&&typeof b=="object"&&!Array.isArray(b))).slice(0,24):[],a=((l=de(r==null?void 0:r.contextPack))==null?void 0:l.questionPlan)??(r==null?void 0:r.analysisPlan),d=fr(a),u=ts(s,o),x=Xi(d,s),g=ie(r==null?void 0:r.sourceCertifiedBlock)??((n==null?void 0:n.kind)==="answer"?ie(n.ref):void 0)??ie((c=de(r==null?void 0:r.block))==null?void 0:c.name);return nn({id:e.run.id,question:e.run.question,answerSummary:e.run.answer??e.run.summary,completedAt:e.run.completedAt,artifactKind:n==null?void 0:n.kind,sourceCertifiedBlock:g,route:ie((m=de(r==null?void 0:r.route))==null?void 0:m.label)??ie((h=de(r==null?void 0:r.route))==null?void 0:h.tier),trustLabel:ie(r==null?void 0:r.trustLabel),reviewStatus:ie(r==null?void 0:r.reviewStatus),certification:ie(r==null?void 0:r.certification),contextPackId:ie(r==null?void 0:r.contextPackId),requestedFilters:Ue(d==null?void 0:d.filters),requestedDimensions:Ue(d==null?void 0:d.dimensions),requestedMeasures:Ue(d==null?void 0:d.measures),answerContract:a,dqlArtifact:Ui(r),cascade:Yi(r),topN:gr(d),result:s.length>0||o.length>0?nn({columns:s,rowsSample:o,dimensionValues:u,measureColumns:x,rowCount:Gi(i)}):void 0,sourceSql:Ki(r,i)})}function Dn(e){return e.answerContract}function fr(e){const n=de(e);return de(n==null?void 0:n.requestedShape)}function Vi(e){const n=de(e==null?void 0:e.researchRun),r=de(e==null?void 0:e.result);return[e==null?void 0:e.result,e==null?void 0:e.resultPreview,n==null?void 0:n.resultPreview,n==null?void 0:n.result,r==null?void 0:r.result].map(de).filter(s=>!!(s&&(Array.isArray(s.rows)||Array.isArray(s.columns)))).sort((s,o)=>Pn(o)-Pn(s))[0]}function Pn(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 Gi(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 Ki(e,n){var r,i;return ie(e==null?void 0:e.proposedSql)??ie(e==null?void 0:e.sql)??ie(n==null?void 0:n.sql)??ie((r=de(e==null?void 0:e.query))==null?void 0:r.sql)??ie((i=de(e==null?void 0:e.plan))==null?void 0:i.sql)}function Ui(e){var r,i;const n=Je(e==null?void 0:e.dqlArtifact);return n?{...n,source:n.source.slice(0,3e3),filters:(r=n.filters)==null?void 0:r.filter(s=>s.values.length>0).slice(0,12).map(s=>({...s,values:s.values.slice(0,12)})),orderBy:(i=n.orderBy)==null?void 0:i.slice(0,8)}:void 0}function Yi(e){const n=de(e==null?void 0:e.cascade);if(!n)return;const r=ie(n.terminalLane),i=ie(n.routeTier);if(!(!r&&!i))return{terminalLane:r,routeTier:i,label:ie(n.label),ref:ie(n.ref),artifactKind:ie(n.artifactKind),refusalCode:ie(n.refusalCode),outcome:de(n.outcome)}}function Ji(e){const n=e.slice(-3).map(r=>{var o,a;const i=(o=r.result)==null?void 0:o.columns.slice(0,5).join(", "),s=(a=r.result)!=null&&a.dimensionValues?Object.entries(r.result.dimensionValues).slice(0,3).map(([d,u])=>`${d}: ${u.slice(0,3).join(", ")}`).join("; "):"";return[`Q: ${r.question}`,r.answerSummary?`A: ${r.answerSummary}`:"",i?`Columns: ${i}`:"",s?`Values: ${s}`:""].filter(Boolean).join(" | ")}).filter(Boolean);return n.length>0?n.join(`
|
|
54
|
+
`):void 0}function gr(e){const n=de(e==null?void 0:e.topN),r=n==null?void 0:n.n;return typeof r=="number"&&Number.isFinite(r)&&r>0?r:void 0}function Xi(e,n){const r=[...Ue(e==null?void 0:e.measures)??[],...n.filter(s=>/\b(revenue|sales|amount|total|count|average|avg|sum|spend|cost|margin|profit|value|points?|score|quantity|units?|rate|volume)\b/i.test(s.replace(/_/g," ")))],i=Array.from(new Set(r.map(s=>s.trim()).filter(Boolean))).slice(0,12);return i.length>0?i:void 0}function de(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function Zi(e){const r=(Array.isArray(e==null?void 0:e.columns)?e.columns:[]).map(es).filter(o=>!!o),i=Array.isArray(e==null?void 0:e.rows)?e.rows.find(o=>o&&typeof o=="object"&&!Array.isArray(o)):void 0,s=i?Object.keys(i):[];return Array.from(new Set([...r,...s])).slice(0,32)}function Ue(e){if(!Array.isArray(e))return;const n=e.map(i=>typeof i=="string"?i.trim():"").filter(Boolean),r=Array.from(new Set(n)).slice(0,24);return r.length>0?r:void 0}function es(e){if(typeof e=="string"&&e.trim())return e.trim();if(e&&typeof e=="object"){const n=e;return ie(n.name)??ie(n.field)??ie(n.key)}}function ts(e,n){const r=e.filter(s=>/\b(category|product|customer|account|user|segment|region|channel|type|name)\b/i.test(s.replace(/_/g," "))).slice(0,12),i={};for(const s of r){const o=[];for(const a of n){const d=de(a),u=d==null?void 0:d[s],x=typeof u=="string"||typeof u=="number"?String(u).trim():"";if(!(!x||o.includes(x))&&(o.push(x),o.length>=24))break}o.length>0&&(i[ns(s)]=o)}return Object.keys(i).length>0?i:void 0}function ns(e){const n=e.toLowerCase();return n.includes("category")?"category":n.includes("product")?n.includes("name")?"product_name":"product":n.includes("customer")?n.includes("name")?"customer_name":"customer":n.includes("segment")?"segment":n.includes("region")?"region":n.includes("channel")?"channel":n.replace(/[^a-z0-9_]+/g,"_")}function ie(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function nn(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 rs(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 hr(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:Nn(n.rows.map(d=>d[a]))}]:[]})}if(e.kind!=="semantic_block"||e.persistence!=="transient")return[];const r=new Map(n.columns.map(s=>[s.toLowerCase(),s])),i=new Set((e.parameters??[]).flatMap(s=>{var o;return((o=s.binding)==null?void 0:o.kind)==="semantic_filter"?[s.binding.field.toLowerCase()]:[]}));return(e.dimensions??[]).flatMap(s=>{if(i.has(s.toLowerCase()))return[];const o=s.split(".").at(-1)??s,a=r.get(s.toLowerCase())??r.get(o.toLowerCase())??r.get(s.split(".").join("_").toLowerCase());if(!a)return[];const d=Nn(n.rows.map(u=>u[a]));return[{column:a,field:s,values:d}]})}function is(e,n,r,i){const s=hr(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=ss(s.field.split(".").at(-1)??s.column);let d=a,u=2;for(;o.has(d);)d=`${a}_${u++}`;const x=Array.isArray(i)?i.map(String).join(", "):String(i),g=Zr(x,d);let l=ei(e.source,{name:d,type:g,required:!1,defaultText:x,policy:"dynamic"});l=ti(l,d,s.field);const c=ni(l).map(v=>{var q,T,D;return{...v,...((q=v.binding)==null?void 0:q.kind)==="semantic_filter"&&v.binding.field?{binding:{kind:"semantic_filter",field:v.binding.field,operator:v.binding.operator??"equals"}}:((T=v.binding)==null?void 0:T.kind)==="limit"?{binding:{kind:"limit"}}:((D=v.binding)==null?void 0:D.kind)==="sql_value"?{binding:{kind:"sql_value"}}:{binding:void 0}}}),{executionReceipt:m,compiledSql:h,...b}=e;return{artifact:{...b,source:l,parameters:c,parameterValues:{...e.parameterValues??{},[d]:i}},parameterName:d}}function Nn(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 ss(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 xr(e,n,r){return e.map(i=>i.kind==="run"&&i.run.id===n?{kind:"run",id:r.id,run:r}:i)}function yr(e){var r,i,s;const n=[];for(const o of e){if(o.kind==="user"){n.push({role:"user",text:o.text});continue}if(o.run.status==="blocked"||((r=o.run.artifacts)==null?void 0:r.some(d=>{const u=se(d);return!!(u.executionError||u.warehouseFailure||u.analyticalFailure)}))){((i=n.at(-1))==null?void 0:i.role)==="user"&&n.pop();continue}n.push({role:"assistant",text:((s=o.run.answer)==null?void 0:s.trim())||o.run.summary})}return n.slice(-12)}const pn="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",blocked:"Blocked"};function os({themeMode:e,title:n="AI Copilot",scopeHint:r="Auto routes to answer, research, SQL, block, or app",composerPlaceholder:i="Ask anything about your data…",onClearScope:s,examplePrompts:o,emptyHint:a,notebookPath:d,selectedObject:u,workspaceContext:x,initialMode:g="auto",initialInput:l="",initialItems:c,onItemsChange:m,threadId:h,onThreadIdChange:b,audience:v="analyst",autoRun:q,onInsertSql:T,onInsertDql:D,onReplaceDql:U,onArtifactReady:C,onReviewAuthoringProposal:N,onOpenBlock:Q,onOpenResearch:B,onOpenApp:W,onRunningChange:O,answerFirstCards:$=!1,insertDqlActionLabel:j,replaceDqlActionLabel:K,askLayout:J=!1}){const A=or[e],ee=f.useRef(void 0),[P,X]=f.useState(l),[R,E]=f.useState(c??[]),[oe,G]=f.useState([]),[be,ae]=f.useState(""),[V,w]=f.useState(!1),[Z,p]=f.useState(null),[_,te]=f.useState(null),[re,ve]=f.useState(null),[he,Fe]=f.useState(()=>ls()),[De,k]=f.useState([]),[le,Be]=f.useState(),bn=f.useCallback(y=>{Fe(y);try{window.localStorage.setItem(br,y)}catch{}},[]),et=f.useRef(null),vn=f.useRef(l),jn=f.useRef(null),Ge=f.useRef(null),je=f.useRef(null),Pe=f.useRef(null),pe=f.useRef(null),$e=f.useRef(0),ft=f.useRef(""),Ee=f.useRef(null),tt=f.useCallback(()=>{ft.current="",Ee.current!==null&&(window.cancelAnimationFrame(Ee.current),Ee.current=null),ae("")},[]),Nr=f.useCallback(y=>{ft.current+=y,Ee.current===null&&(Ee.current=window.requestAnimationFrame(()=>{Ee.current=null;const S=ft.current;ft.current="",S&&ae(I=>I+S)}))},[]);f.useEffect(()=>()=>{Ee.current!==null&&window.cancelAnimationFrame(Ee.current)},[]);const ke=x==null?void 0:x.executionTarget,Sn=ke&&typeof ke=="object"&&!Array.isArray(ke)&&ke.target==="connection"&&typeof ke.connectionName=="string"?String(ke.connectionName):void 0,Or=ke&&typeof ke=="object"&&!Array.isArray(ke)&&ke.target==="local";f.useEffect(()=>{let y=!1;return ne.getConnections().then(S=>{if(y)return;const I=Object.keys(S.connections??{}).sort((M,L)=>M.localeCompare(L));k(I),Be(vr(I,S.default,Sn))}).catch(()=>{y||(k([]),Be(void 0))}),()=>{y=!0}},[Sn]);const wn=f.useCallback(y=>{Be(y)},[]),[Me,gt]=f.useState(null),[ze,Ke]=f.useState(null),[Hr,Dt]=f.useState(""),kn=f.useRef(null),ht=f.useRef(null);f.useEffect(()=>{!l||V||l!==vn.current&&(vn.current=l,X(l))},[l,V]);const Qr=f.useMemo(()=>yr(R),[R]),xt=f.useRef(m);xt.current=m;const Ne=f.useRef(C);Ne.current=C,f.useEffect(()=>{var y;(y=xt.current)==null||y.call(xt,R)},[R]);const fe=f.useRef(h),yt=f.useRef(b);yt.current=b;const Pt=f.useCallback((y,S)=>{var I;if(pe.current!==null&&(window.clearTimeout(pe.current),pe.current=null),Kt(y.id),je.current===y.id&&(je.current=null),Pe.current=null,p(null),G(y.events.slice(-8)),tt(),E(M=>{if(M.some(H=>H.kind==="run"&&H.run.id===y.id))return M.map(H=>H.kind==="run"&&H.run.id===y.id?{...H,id:y.id,run:y}:H);const L=M.some(H=>H.kind==="user"&&H.text===S.question);return[...M,...L?[]:[{kind:"user",id:`${y.id}-question`,text:S.question}],{kind:"run",id:y.id,run:y}]}),y.route!=="certified_answer"){const M=_t(y);M&&((I=Ne.current)==null||I.call(Ne,M,y))}},[tt]),An=f.useCallback((y,S)=>{var M;E(L=>xr(L,y,S)),gt(L=>{if(!L||L.runId!==y)return L;const H=S.artifacts[0];return H?{runId:S.id,artifactId:H.id,tab:L.tab}:null}),ve(null);const I=_t(S);I&&((M=Ne.current)==null||M.call(Ne,I,S))},[]),nt=f.useCallback(y=>{pe.current!==null&&window.clearTimeout(pe.current);const S=++$e.current;je.current=y.id,Pe.current=y,p(y),w(!0),tt(),G([]);const I=async()=>{if(!(S!==$e.current||je.current!==y.id))try{const M=await ne.getAgentRunState(y.id);if(S!==$e.current||je.current!==y.id)return;if(M.lifecycleState==="terminal"){Pt(M.run,y),w(!1);return}G(M.progress.events.slice(-8)),pe.current=window.setTimeout(()=>{I()},600)}catch{if(S!==$e.current||je.current!==y.id)return;pe.current=window.setTimeout(()=>{I()},1200)}};return I(),()=>{S===$e.current&&($e.current+=1),pe.current!==null&&(window.clearTimeout(pe.current),pe.current=null)}},[Pt]),qn=f.useRef(!1);f.useEffect(()=>{if(!h||qn.current)return;qn.current=!0,fe.current??(fe.current=h);let y=!1;return ne.getAgentThread(h).then(({turns:S,runs:I})=>{y||S.length===0||E(M=>{const L=M.filter(ce=>ce.kind==="run").length,H=jr(S,I);if(S.length>=L)return H;const ue=new Map(H.flatMap(ce=>ce.kind==="run"?[[ce.run.id,ce.run]]:[]));return M.map(ce=>ce.kind==="run"&&ue.has(ce.run.id)?{...ce,run:ue.get(ce.run.id)}:ce)})}).catch(()=>{!y&&fe.current===h&&(fe.current=void 0)}),()=>{y=!0}},[h]),f.useEffect(()=>{const y=Vn(h??fe.current);if(!(!y||Ge.current))return nt(y)},[nt,h]),f.useEffect(()=>{const y=()=>{if(document.visibilityState!=="visible"||Ge.current)return;const S=Pe.current??Vn(h??fe.current);S&&nt(S)};return document.addEventListener("visibilitychange",y),()=>document.removeEventListener("visibilitychange",y)},[nt,h]);const Re=async(y,S,I,M,L)=>{var zn,Rn,_n;const H=(y??P).trim();if(!H||V)return;const ue=S??ee.current??g;ee.current=void 0;const ce={kind:"user",id:Xn("user"),text:H};E(me=>[...me,ce]),X(""),ve(null),w(!0),G([]),tt();const Oe=new AbortController;Ge.current=Oe;const Ae=Xn("run");let ye={id:Ae,question:H,threadId:fe.current,startedAt:new Date().toISOString()};je.current=Ae,Pe.current=ye,p(ye),Qn(ye);let St=!1,Se=!1;try{if(!fe.current)try{const ge=await ne.createAgentThread({surface:J?"ask":typeof(x==null?void 0:x.surface)=="string"?x.surface:d?"notebook":"agent",title:H,...d?{notebookPath:d}:{}});fe.current=ge.id,(zn=yt.current)==null||zn.call(yt,ge.id),ye={...ye,threadId:ge.id},Pe.current=ye,p(ye),Qn(ye)}catch{}const me=ue==="modeling"||ue==="skill"?(Rn=[...R].reverse().find(ge=>ge.kind==="run"&&ge.run.artifacts.some(Nt=>Nt.kind===(ue==="modeling"?"modeling_change_proposal":"skill_change_proposal"))))==null?void 0:Rn.run:void 0,In=me==null?void 0:me.artifacts.find(ge=>ge.kind===(ue==="modeling"?"modeling_change_proposal":"skill_change_proposal")),Kr={question:H,...I?{selectedEvidenceId:I}:{},...M?{clarificationSourceQuestion:M}:{},requestedMode:ue,audience:v,selectedObject:u??(d?{kind:"notebook",path:d}:void 0),...L!=null&&L.executionTarget?{executionTarget:L.executionTarget}:Or?{executionTarget:{target:"local"}}:le?{executionTarget:{target:"connection",connectionName:le}}:{},workspaceContext:{...x??{},...d?{notebookPath:d}:{},...L?{researchSource:_r(L)}:{},...me&&In?{sourceRunId:me.id,sourceArtifactId:In.id,revision:(((_n=me.derivation)==null?void 0:_n.revision)??1)+1}:{}},conversationContext:Hi(R),history:Qr,thinkingMode:he,runId:Ae,...fe.current?{threadId:fe.current}:{}},Ur=await ne.createAgentRunStream(Kr,ge=>{St=!0,ge.kind==="event"?G(Nt=>[...Nt,ge.event].slice(-8)):ge.kind==="answer-delta"?Nr(ge.delta):G(ge.run.events.slice(-8))},Oe.signal);Pt(Ur,ye)}catch(me){Oe.signal.aborted||(ve(me instanceof Error?me.message:String(me)),X(H),St?(Se=!0,nt(ye)):(Kt(Ae),je.current===Ae&&(je.current=null),Pe.current=null,p(null)))}finally{Ge.current===Oe&&(Ge.current=null),Se||w(!1)}},mt=()=>{Re()},Cn=()=>{var S;const y=je.current;y&&ne.cancelAgentRun(y).catch(()=>{}),(S=Ge.current)==null||S.abort(),$e.current+=1,pe.current!==null&&window.clearTimeout(pe.current),Kt(y??""),je.current=null,Pe.current=null,p(null),tt(),G([]),w(!1),ve("Stopped. No answer or draft was saved.")},bt=f.useRef(O);bt.current=O,f.useEffect(()=>{var y;(y=bt.current)==null||y.call(bt,V)},[V]),f.useEffect(()=>{!(q!=null&&q.text)||V||jn.current!==q.nonce&&(jn.current=q.nonce,Re(q.text,q.mode??g))},[q==null?void 0:q.nonce,q==null?void 0:q.text,q==null?void 0:q.mode,g,V]),f.useEffect(()=>()=>{$e.current+=1,pe.current!==null&&window.clearTimeout(pe.current)},[]);const vt={appId:typeof(x==null?void 0:x.appId)=="string"?x.appId:void 0,dashboardId:typeof(x==null?void 0:x.dashboardId)=="string"?x.dashboardId:void 0,dashboardTitle:typeof(x==null?void 0:x.dashboardTitle)=="string"?x.dashboardTitle:void 0},jt=(y,S)=>{var I,M;if(S.id==="review-modeling-proposal"||S.id==="review-skill-proposal"){const L=S.id==="review-modeling-proposal"?"modeling_change_proposal":"skill_change_proposal",H=y.artifacts.find(ue=>ue.kind===L);if(!H){ve("This authoring run does not include a reviewable proposal.");return}if(N)N(H,y);else if(H.ref){try{window.sessionStorage.setItem("dql-context-proposal-handoff",H.ref)}catch{}window.dispatchEvent(new CustomEvent("dql:open-context-proposal",{detail:{proposalId:H.ref,kind:H.kind}}))}return}if(S.id==="save-dql-block"){const L=Ce(y),H=((I=L==null?void 0:L.source)==null?void 0:I.trim())??((M=Te(y))==null?void 0:M.trim());if(!H){ve("This answer does not include a reusable DQL or SQL artifact yet.");return}te({runId:y.id,source:H,name:(L==null?void 0:L.name)??`${y.question.slice(0,48).trim()||"saved_answer"}`,dqlArtifact:L});return}if(S.id==="research-deeper"){Re(y.question,"research",void 0,void 0,y);return}if(S.id.startsWith("suggest-question")){Re(S.label,"auto");return}ee.current=_s(S.route),X(Is(y,S.route)),requestAnimationFrame(()=>{var L;return(L=et.current)==null?void 0:L.focus()})},Vr=f.useCallback((y,S,I="trust")=>{gt({runId:y,artifactId:S,tab:I})},[]),Gr=f.useCallback(y=>{var M,L;const S=y.trim();if(!S)return;const I=(M=ze==null?void 0:ze.text)==null?void 0:M.trim();Ke(null),Dt("");try{(L=window.getSelection())==null||L.removeAllRanges()}catch{}Re(I?`${S}
|
|
55
|
+
|
|
56
|
+
Regarding: "${I}"`:S),requestAnimationFrame(()=>{ht.current&&(ht.current.scrollTop=ht.current.scrollHeight)})},[ze,Re]);if(f.useEffect(()=>{if(!J)return;const y=I=>{const M=I.target;M&&M.closest("[data-selpop]")||window.setTimeout(()=>{const L=window.getSelection(),H=L&&L.rangeCount?L.toString().trim():"";if(!H||H.length<3){Ke(Se=>Se&&null);return}const ue=L.anchorNode,ce=ue&&(ue.nodeType===1?ue:ue.parentElement),Oe=ce==null?void 0:ce.closest("[data-followup]");if(!Oe){Ke(Se=>Se&&null);return}const Ae=L.getRangeAt(0).getBoundingClientRect(),ye=Math.max(12,Math.min(Ae.left,window.innerWidth-340)),St=Ae.bottom+176>window.innerHeight?Math.max(12,Ae.top-176):Ae.bottom+8;Ke({text:H.slice(0,220),source:Oe.getAttribute("data-followup")||"answer",left:ye,top:St}),Dt(""),requestAnimationFrame(()=>{var Se;return(Se=kn.current)==null?void 0:Se.focus()})},0)},S=I=>{I.key==="Escape"&&Ke(null)};return document.addEventListener("mouseup",y),document.addEventListener("keydown",S),()=>{document.removeEventListener("mouseup",y),document.removeEventListener("keydown",S)}},[J]),J){const y=Me?(()=>{const S=R.find(M=>M.kind==="run"&&M.run.id===Me.runId);if(!S||S.kind!=="run")return null;const I=S.run.artifacts.find(M=>M.id===Me.artifactId);return I?{run:S.run,artifact:I}:null})():null;return t.jsxs("div",{style:{display:"flex",height:"100%",minHeight:0,flex:1,minWidth:0,width:"100%",background:"var(--bg-canvas)"},children:[_?t.jsx(Wn,{cell:{id:`agent-${_.runId}`,type:_.dqlArtifact?"dql":"sql",content:_.source,name:_.name,status:"success",..._.dqlArtifact?{dqlArtifact:_.dqlArtifact}:{}},initialContent:_.source,initialName:_.name,onClose:()=>te(null),onSaved:()=>te(null)}):null,t.jsx("style",{children:xs}),t.jsxs("div",{style:{flex:1,minWidth:360,display:"flex",flexDirection:"column",overflow:"hidden",background:"var(--bg-canvas)"},children:[t.jsxs("div",{style:{height:46,flexShrink:0,borderBottom:"1px solid var(--border-subtle)",display:"flex",alignItems:"center",gap:9,padding:"0 24px"},children:[t.jsx("div",{style:{width:24,height:24,borderRadius:7,background:"var(--accent-dim)",border:"1px solid var(--status-info-border)",color:"var(--accent)",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:t.jsx(Ve,{size:13})}),t.jsx("span",{style:{fontSize:13.5,fontWeight:650,color:A.textPrimary,whiteSpace:"nowrap"},children:n==="AI Copilot"?"Ask your data":n}),t.jsx("div",{style:{flex:1}}),t.jsx("span",{style:{fontSize:11,color:A.textMuted,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:"Certified first · semantic next · generated SQL last"})]}),t.jsxs("div",{ref:ht,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:[R.length===0&&!V?t.jsxs("div",{style:{margin:"auto 0",display:"grid",gap:14,justifyItems:"center",textAlign:"center",color:A.textSecondary,paddingTop:40},children:[t.jsx("div",{style:Zn(A),children:t.jsx(Ve,{size:20})}),t.jsx("div",{style:{fontSize:13.5,lineHeight:1.5,maxWidth:400,color:A.textSecondary},children:a??On}),t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap",justifyContent:"center",maxWidth:520},children:(o??Hn).map(S=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>{X(S.prompt),requestAnimationFrame(()=>{var I;return(I=et.current)==null?void 0:I.focus()})},style:It(A),children:S.label},S.label))})]}):null,R.map(S=>S.kind==="user"?t.jsx("div",{style:ys(A),children:S.text},S.id):t.jsx(Jn,{run:S.run,t:A,themeMode:e,threadId:fe.current,appContext:vt,selectedArtifactId:(Me==null?void 0:Me.runId)===S.run.id?Me.artifactId:void 0,onOpenArtifact:(I,M)=>Vr(S.run.id,I,M),onOpenApp:W,onInsertSql:T,onInsertDql:D,onOpenBlock:Q,onOpenResearch:B,onSelectClarification:I=>{const M=kt(I);Re(M.question,void 0,M.selectedEvidenceId,S.run.question)},onNextAction:I=>jt(S.run,I),onRepairedRun:An},S.id)),V&&t.jsx(Kn,{events:oe,t:A,streamingAnswer:be,thinkingMode:he,backgroundRun:Z})]}),t.jsxs("div",{style:{width:"min(720px, 100% - 48px)",margin:"auto auto 0",padding:"10px 0 16px",position:"sticky",bottom:0,background:"linear-gradient(to top, var(--bg-canvas) 82%, transparent)"},children:[re?t.jsx("div",{style:{color:A.error,fontSize:12,marginBottom:8},children:re}):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:A.textMuted,fontSize:10.5,display:"flex",alignItems:"center",gap:5},children:[t.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r}),t.jsx("button",{type:"button",onClick:s,"aria-label":"Clear modeling scope",title:"Clear modeling scope",style:{border:0,background:"transparent",color:A.textMuted,cursor:"pointer",display:"grid",placeItems:"center",padding:1},children:t.jsx(qt,{size:12})})]}):null,t.jsxs("div",{style:{background:"var(--bg-2)",border:"1px solid var(--border-default)",borderRadius:14,boxShadow:"0 1px 2px rgba(26,26,26,0.03), 0 6px 22px rgba(26,26,26,0.05)",display:"flex",flexDirection:"column"},children:[t.jsx("textarea",{ref:et,value:P,onChange:S=>{X(S.target.value),ee.current=void 0},rows:2,placeholder:i,onKeyDown:S=>{S.key==="Enter"&&!S.shiftKey&&(S.preventDefault(),mt())},style:{border:"none",background:"transparent",resize:"none",outline:"none",boxShadow:"none",padding:"13px 15px 4px",fontSize:13.5,lineHeight:1.5,color:A.textPrimary,fontFamily:A.font}}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 10px 10px 12px"},children:[t.jsx(Bn,{t:A,value:he,onChange:bn}),t.jsx(Gn,{names:De,value:le,onChange:wn,t:A}),t.jsx("div",{style:{flex:1}}),V?t.jsxs("button",{type:"button",className:"dql-hover",onClick:Cn,title:"Stop the active agent run",style:{height:34,padding:"0 12px",borderRadius:10,border:`1px solid ${A.error}`,background:A.btnBg,color:A.error,display:"inline-flex",alignItems:"center",gap:6,cursor:"pointer",fontFamily:A.font,fontSize:12.5,fontWeight:600},children:[t.jsx(Tn,{size:13,fill:"currentColor"})," Stop"]}):null,t.jsx("button",{type:"button",className:"dql-hover dql-lift",title:"Ask",onClick:mt,disabled:!P.trim()||V,style:{width:34,height:34,borderRadius:10,border:"none",background:P.trim()&&!V?"var(--accent)":"var(--bg-4)",color:"#fff",display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:P.trim()&&!V?"pointer":"default",boxShadow:P.trim()&&!V?"0 1px 5px rgba(107,93,211,0.3)":"none"},children:V?t.jsx(Qe,{size:15,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(lr,{size:15})})]})]}),t.jsx("div",{style:{textAlign:"center",fontSize:10.5,color:A.textMuted,marginTop:8},children:"Every answer is grounded in your certified metrics and dbt lineage."})]})]})]}),y?t.jsx(Ss,{run:y.run,artifact:y.artifact,tab:Me.tab,t:A,appContext:vt,onOpenApp:W,onChangeTab:S=>gt(I=>I&&{...I,tab:S}),onClose:()=>gt(null),onSaveBlock:()=>jt(y.run,{id:"save-dql-block",label:"Save as block",route:"dql_block_draft"}),onInsertSql:T,onInsertDql:D}):null,ze?t.jsx(ws,{t:A,text:ze.text,source:ze.source,left:ze.left,top:ze.top,draft:Hr,inputRef:kn,onDraftChange:Dt,onClose:()=>Ke(null),onSend:Gr}):null]})}return t.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0,flex:1,minWidth:0,width:"100%",background:A.cellBg},children:[_?t.jsx(Wn,{cell:{id:`agent-${_.runId}`,type:_.dqlArtifact?"dql":"sql",content:_.source,name:_.name,status:"success",..._.dqlArtifact?{dqlArtifact:_.dqlArtifact}:{}},initialContent:_.source,initialName:_.name,onClose:()=>te(null),onSaved:()=>te(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:[R.length===0&&!V?t.jsxs("div",{style:{margin:"auto 0",display:"grid",gap:14,justifyItems:"center",textAlign:"center",color:A.textSecondary},children:[t.jsx("div",{style:Zn(A),children:t.jsx(Ve,{size:20})}),t.jsx("div",{style:{fontSize:13,lineHeight:1.5,maxWidth:380,color:A.textSecondary},children:a??On}),t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap",justifyContent:"center",maxWidth:520},children:(o??Hn).map(y=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>{X(y.prompt),requestAnimationFrame(()=>{var S;return(S=et.current)==null?void 0:S.focus()})},style:It(A),children:y.label},y.label))})]}):null,R.map(y=>y.kind==="user"?t.jsx("div",{style:Os(A),children:y.text},y.id):$?t.jsx(Jn,{run:y.run,t:A,themeMode:e,threadId:fe.current,appContext:vt,onOpenApp:W,onInsertSql:T,onInsertDql:D,onReplaceDql:U,insertDqlActionLabel:j,replaceDqlActionLabel:K,onOpenBlock:Q,onOpenResearch:B,onSelectClarification:S=>{const I=kt(S);Re(I.question,void 0,I.selectedEvidenceId,y.run.question)},onNextAction:S=>jt(y.run,S),onRepairedRun:An},y.id):t.jsx(hs,{run:y.run,t:A,themeMode:e,appContext:vt,onOpenApp:W,onInsertSql:T,onInsertDql:D,onOpenBlock:Q,onOpenResearch:B,onSelectClarification:S=>{const I=kt(S);Re(I.question,void 0,I.selectedEvidenceId,y.run.question)},onNextAction:S=>jt(y.run,S)},y.id)),V&&t.jsx(Kn,{events:oe,t:A,streamingAnswer:be,thinkingMode:he,backgroundRun:Z})]}),re?t.jsx("div",{style:{margin:"0 16px 8px",color:A.error,fontSize:12},children:re}):null,t.jsxs("div",{style:{padding:"10px 16px 14px",borderTop:`1px solid ${A.headerBorder}`,display:"grid",gap:8},children:[t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center",justifyContent:"space-between",flexWrap:"wrap"},children:[t.jsxs("div",{style:{fontSize:11,color:A.textMuted,flex:1,minWidth:180,display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{children:r}),s?t.jsx("button",{type:"button",onClick:s,"aria-label":"Clear modeling scope",title:"Clear modeling scope",style:{border:0,background:"transparent",color:A.textMuted,cursor:"pointer",display:"grid",placeItems:"center",padding:2},children:t.jsx(qt,{size:12})}):null]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(Gn,{names:De,value:le,onChange:wn,t:A}),t.jsx(Bn,{t:A,value:he,onChange:bn})]})]}),t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-end"},children:[t.jsx("textarea",{ref:et,value:P,onChange:y=>{X(y.target.value),ee.current=void 0},rows:2,placeholder:i,onKeyDown:y=>{y.key==="Enter"&&!y.shiftKey&&(y.preventDefault(),mt())},style:Fs(A)}),t.jsxs("button",{type:"button",className:"dql-hover dql-lift",onClick:mt,disabled:!P.trim()||V,style:er(A,!!P.trim()&&!V),children:[V?t.jsx(Qe,{size:15,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(oi,{size:15}),t.jsx("span",{children:V?"Working":"Ask"})]}),V?t.jsxs("button",{type:"button",className:"dql-hover",onClick:Cn,style:{...er(A,!0),background:A.btnBg,borderColor:A.error,color:A.error},title:"Stop the active agent run",children:[t.jsx(Tn,{size:13,fill:"currentColor"}),t.jsx("span",{children:"Stop"})]}):null]})]})]})}const On="Ask a question — every answer is grounded in your certified metrics and dbt lineage. Use Research deeper on any answer for a slower investigation.",Hn=[{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 fn(){try{const e=JSON.parse(window.localStorage.getItem(pn)??"[]");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 Qn(e){try{const n=fn().filter(r=>r.id!==e.id);window.localStorage.setItem(pn,JSON.stringify([...n,e].slice(-12)))}catch{}}function Kt(e){try{const n=fn().filter(r=>r.id!==e);window.localStorage.setItem(pn,JSON.stringify(n))}catch{}}function Vn(e){const n=fn().sort((r,i)=>i.startedAt.localeCompare(r.startedAt));return e?n.find(r=>r.threadId===e):n.find(r=>!r.threadId)}const br="dql.agent.thinkingMode";function vr(e,n,r){return r&&e.includes(r)?r:n&&e.includes(n)?n:e[0]}function Gn({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(ri,{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 ls(){try{const e=window.localStorage.getItem(br);return e==="low"||e==="medium"||e==="high"||e==="auto"?e:"auto"}catch{return"auto"}}const as=new Set(["conversation","certified_answer","semantic_answer","generated_answer","research","sql_cell","dql_block_draft","modeling_draft","skill_draft","app_build","clarify","blocked"]),cs=new Set(["certified","governed","grounded","review_required","blocked","not_applicable"]),ds=new Set(["completed","needs_review","needs_clarification","blocked"]),us=new Set(["conversational_reply","certified_answer_found","governed_semantic_answer","generated_review_required","artifact_created","needs_clarification","human_review_required","blocked"]);function jr(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??ps(o)}]})}function ps(e){var x,g,l;const n=as.has(e.route)?e.route:"generated_answer",r=cs.has(e.trustLabel)?e.trustLabel:e.certification==="certified"?"certified":"not_applicable",i=ds.has(e.runStatus)?e.runStatus:"completed",s=us.has(e.stopReason)?e.stopReason:i==="blocked"?"blocked":i==="needs_clarification"?"needs_clarification":i==="needs_review"?"human_review_required":n==="conversation"?"conversational_reply":r==="certified"?"certified_answer_found":"artifact_created",o=(((x=e.result)==null?void 0:x.columns)??[]).filter(c=>typeof c=="string"),a=(((g=e.result)==null?void 0:g.rowsSample)??[]).filter(c=>Array.isArray(c)).map(c=>Object.fromEntries(o.map((m,h)=>[m,c[h]]))),d=o.length>0?{columns:o,rows:a,rowCount:((l=e.result)==null?void 0:l.rowCount)??a.length}:void 0,u=d||e.sql||e.dqlArtifact||e.sourceCertifiedBlock?{id:`${e.id}-artifact`,kind:"answer",title:e.sourceCertifiedBlock??e.question,trustState:r,ref:e.sourceCertifiedBlock,payload:{...e.sourceCertifiedBlock?{sourceCertifiedBlock:e.sourceCertifiedBlock}:{},...e.certification?{certification:e.certification}:{},...e.contextPackId?{contextPackId:e.contextPackId}:{},...e.sql?{sql:e.sql}:{},...e.dqlArtifact?{dqlArtifact:e.dqlArtifact}:{},...e.cascade?{cascade:e.cascade}:{},...d?{result:d}:{},...e.contract&&Object.keys(e.contract).length>0?{contextPack:{questionPlan:{requestedShape:e.contract}}}:{}}}:void 0;return{id:e.id,question:e.question,requestedMode:"auto",route:n,status:i,trustState:r,stopReason:s,startedAt:e.createdAt,completedAt:e.createdAt,summary:e.answerSummary??e.question,answer:e.answerText??e.answerSummary,answerKind:n==="conversation"?"conversational":void 0,steps:[],artifacts:u?[u]:[],evaluations:[],events:[],nextActions:[],repairAttempts:0}}function fs(e){switch(e){case"certified_answer":return"Found a compatible certified block";case"semantic_answer":return"Found a compatible semantic metric";case"generated_answer":return"Identified the relevant tables and columns";case"research":return"Identified evidence for deeper analysis";case"app_build":return"Found governed assets for the app";case"sql_cell":return"Identified the query context";case"dql_block_draft":return"Identified reusable governed logic";case"modeling_draft":return"Resolved current models and relationship evidence";case"skill_draft":return"Resolved current domain guidance and governed references";case"clarify":return"Identified a missing business detail";default:return"Identified the best answer path"}}function gs(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 rn(e){for(let n=e.length-1;n>=0;n-=1)if(e[n].route)return e[n].route}function Sr(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 wr(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 kr(e,n=!1){if(e.length===0&&n)return[{id:"background",label:"Continuing this request in the background",state:"active"}];const r=rn(e);if(r==="conversation")return[];const i=e.some(d=>d.type==="route.decided"),s=e.some(d=>d.type==="executor.started"||d.type==="step.started"||d.type==="repair.attempted"||d.type==="escalated"),o=e.some(d=>d.type==="evaluation.recorded"),a=[{id:"search",label:"Resolving governed evidence and business meaning",state:i?"complete":"active"}];return i&&a.push({id:"match",label:fs(r),state:s||o?"complete":"active"}),(s||o)&&a.push({id:"execute",label:gs(r,e),state:o?"complete":"active"}),o&&a.push({id:"verify",label:"Checking the result against governed evidence",state:"active"}),a}function Kn({events:e,t:n,streamingAnswer:r,thinkingMode:i,backgroundRun:s}){var h;const[o,a]=f.useState(()=>Date.now());f.useEffect(()=>{const b=window.setInterval(()=>a(Date.now()),1e3);return()=>window.clearInterval(b)},[]);const d=(s==null?void 0:s.startedAt)??((h=e.find(b=>b.type==="run.started"))==null?void 0:h.at),u=d?Date.parse(d):o,x=Number.isFinite(u)?Math.max(0,Math.floor((o-u)/1e3)):0,g=Sr(x,rn(e),e.some(b=>b.type==="repair.attempted"));if(r)return t.jsx("div",{style:{alignSelf:"stretch",padding:"4px 2px 8px",fontSize:13.5,lineHeight:1.55,color:n.textPrimary,whiteSpace:"pre-wrap",animation:"dql-agent-fadein 0.22s ease-out"},children:r});if(rn(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(Un,{}),t.jsx("span",{style:{fontSize:13,lineHeight:1.4},children:"Replying…"})]});const c=kr(e,!!s),m=x>=12?g==null?void 0:g.title:i==="high"?"Thorough mode is cross-checking the result.":null;return t.jsxs("div",{role:"status","aria-live":"polite","aria-label":"Agent activity",style:{alignSelf:"stretch",display:"grid",gap:7,padding:"5px 2px 10px",animation:"dql-agent-fadein 0.22s ease-out"},children:[c.map(b=>t.jsxs("div",{className:"dql-agent-activity",style:{display:"flex",alignItems:"center",gap:9,minHeight:18,color:b.state==="active"?n.textPrimary:n.textMuted},children:[t.jsx("span",{"aria-hidden":"true",style:{width:16,height:16,display:"inline-flex",alignItems:"center",justifyContent:"center",flex:"0 0 auto",color:b.state==="active"?n.accent:n.textMuted},children:b.state==="active"?t.jsx(Un,{}):t.jsx(st,{size:13,strokeWidth:2.2})}),t.jsxs("span",{style:{fontSize:12.5,lineHeight:1.4,fontWeight:b.state==="active"?620:450},children:[b.label,b.state==="active"?"…":""]})]},b.id)),m?t.jsx("span",{style:{paddingLeft:25,fontSize:10.5,lineHeight:1.4,color:n.textMuted},children:m}):null]})}function Un(){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 Yn({items:e,t:n,renderItem:r,cap:i=4}){const[s,o]=f.useState(!1),a=s?e:e.slice(0,i);return t.jsxs(t.Fragment,{children:[a.map((d,u)=>r(d,u)),e.length>i?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>o(d=>!d),style:{alignSelf:"flex-start",background:"none",border:"none",cursor:"pointer",color:n.accent,fontSize:11,padding:"2px 0",display:"inline-flex",alignItems:"center",gap:4},children:[s?t.jsx(cr,{size:11}):t.jsx(Bt,{size:11}),s?"Show less":`Show all (${e.length})`]}):null]})}function hs({run:e,t:n,themeMode:r,appContext:i,onOpenApp:s,onInsertSql:o,onInsertDql:a,onOpenBlock:d,onOpenResearch:u,onSelectClarification:x,onNextAction:g}){var $;const{dispatch:l}=$t();if(e.route==="conversation"){const j=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:Hs(n),children:[j?t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:10.5,color:n.textMuted,marginBottom:6,fontWeight:650},children:[t.jsx(Ct,{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(At,{text:Ye(e.answer),t:n}):e.summary})]}),e.nextActions.length>0?t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:e.nextActions.map(K=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>g(K),style:It(n),children:K.label},K.id))}):null]})}const c=e.steps??[],m=c.length>1,h=(($=e.plan)==null?void 0:$.source)==="llm",b=mn(e),v=xn(e),q=ut(e),T=e.route==="certified_answer"||e.route==="generated_answer",D=e.nextActions.some(j=>j.route==="research"),U=T&&q&&!D,C=Ce(e),N=q&&!(C!=null&&C.sourcePath)&&!!((C==null?void 0:C.source)??Te(e)),Q=Date.parse(e.startedAt),B=Date.parse(e.completedAt),W=Number.isFinite(Q)&&Number.isFinite(B)?Math.max(0,Math.round((B-Q)/1e3)):0,O=wr(W,e.route,e.trustState,e.repairAttempts);return t.jsxs("div",{style:Qs(n),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(Cs,{run:e}),t.jsx("div",{style:{minWidth:0,flex:1},children:t.jsx("div",{style:{fontSize:12.5,fontWeight:850,color:n.textPrimary},children:ks(e)})}),t.jsx(zs,{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(xe,{size:12,color:n.success,style:{flex:"0 0 auto",marginTop:1}}):e.trustState==="governed"||e.trustState==="grounded"?t.jsx(xe,{size:12,color:n.accent,style:{flex:"0 0 auto",marginTop:1}}):t.jsx(Xe,{size:12,color:n.warning,style:{flex:"0 0 auto",marginTop:1}}),t.jsx("span",{children:v})]}):null,h||m||e.repairAttempts>0?t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[h?t.jsx(Xt,{t:n,icon:t.jsx(at,{size:11}),label:"AI plan",tone:"accent"}):null,m?t.jsx(Xt,{t:n,icon:t.jsx(en,{size:11}),label:`${c.length} steps`,tone:"muted"}):null,e.repairAttempts>0?t.jsx(Xt,{t:n,icon:t.jsx(Mt,{size:11}),label:`${e.repairAttempts} repair${e.repairAttempts>1?"s":""}`,tone:"warning"}):null]}):null,e.summary&&!(e.answer&&Ts(Ie(e.summary),Ye(e.answer)))?t.jsx("div",{style:{fontSize:12.5,lineHeight:1.45,color:n.textSecondary},children:Ie(e.summary)}):null,e.answer?t.jsx("div",{style:Vs(n),children:t.jsx(At,{text:Ye(e.answer),t:n})}):null,t.jsx(Cr,{run:e,t:n,onSelect:x}),b.length>0?t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[t.jsx("span",{style:{fontSize:11,color:n.textMuted},children:"Evidence:"}),b.map(j=>t.jsxs("span",{style:Fr(n,j.certified),children:[j.certified?t.jsx(xe,{size:11}):t.jsx(lt,{size:11}),t.jsx("span",{children:j.label})]},j.label))]}):null,t.jsx(Wr,{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(j=>t.jsx(Br,{artifact:j,t:n,themeMode:r,onInsertSql:o,onInsertDql:a,sourceRunId:e.id,sourceQuestion:e.question,onOpenBlock:d,onOpenResearch:u,onOpenApp:s,onNextAction:g},j.id))}):null,m?t.jsx(Er,{steps:c,t:n}):t.jsx($r,{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(at,{size:12})," View steps · where the time went"]}):null,O?t.jsxs("div",{style:{display:"grid",gap:3,padding:"8px 9px",border:`1px solid ${n.accent}33`,borderRadius:7,background:`${n.accent}0a`},children:[t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,color:n.textSecondary,fontSize:11,fontWeight:800},children:[t.jsx(Ct,{size:11,color:n.accent})," ",O.title]}),t.jsx("span",{style:{fontSize:10.5,color:n.textMuted,lineHeight:1.45},children:O.detail})]}):null,q||U||e.nextActions.length>0?t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[q?t.jsx(hn,{run:e,t:n,appContext:i,onOpenApp:s}):null,N?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>g({id:"save-dql-block",label:"Save as block",route:"dql_block_draft"}),style:Y(n),children:[t.jsx(un,{size:11})," Save as block"]}):null,U?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>g({id:"research-deeper",label:"Research this deeper",route:"research"}),style:Y(n),title:"Run a slower, multi-step investigation on this question",children:[t.jsx(lt,{size:11}),"Research this deeper"]}):null,e.nextActions.filter(j=>j.id!=="pin-to-app"&&j.id!=="research-deeper"&&j.id!=="confirm-app-build"&&j.id!=="request-certification").map(j=>t.jsx("button",{type:"button",className:"dql-hover",onClick:()=>g(j),style:Y(n),children:j.label},j.id))]}):null]})}function Ar(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 xs=`
|
|
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 ys(e){return{alignSelf:"flex-end",maxWidth:"82%",background:"var(--bg-0)",color:e.textPrimary,borderRadius:"16px 16px 4px 16px",padding:"10px 14px",fontSize:13.5,lineHeight:1.5,whiteSpace:"pre-wrap",animation:"dql-agent-fadein 0.25s ease-out"}}function Le(e){return Et(e,{variant:"ghost",size:"sm"})}function Ut(e,n){return e.kind==="app_proposal"||e.kind==="dql_block_draft"||e.kind==="research_run"||!!Ft(n)}function Lt(e,n){var a,d;const r=[],i=We(n),s=e.kind==="answer"?(a=i==null?void 0:i.rows)!=null&&a.length?"Table":"Answer":e.kind==="sql_cell"?"SQL":e.kind==="dql_block_draft"?"DQL block":e.kind==="research_run"?"Research":"Result";r.push(s);const o=(i==null?void 0:i.rowCount)??((d=i==null?void 0:i.rows)==null?void 0:d.length);return typeof o=="number"&&r.push(`${o} row${o===1?"":"s"}`),typeof(i==null?void 0:i.executionTime)=="number"&&r.push(i.executionTime>=1e3?`${(i.executionTime/1e3).toFixed(1)}s`:`${i.executionTime.toFixed(i.executionTime<10?1:0)}ms`),r.push(e.trustState==="certified"?"certified block":e.trustState==="governed"||e.trustState==="grounded"?"governed":"AI-generated"),r.join(" · ")}function it(e,n){const i=/^(?:certified|governed semantic|review-required|exploratory dbt-grounded) answer$/i.test(n.title.trim())?e.question:n.title,s=Ie(i).replace(/[?.!]+$/,"").trim();if(!s)return"Answer result";const o=s.charAt(0).toUpperCase()+s.slice(1);return o.length>88?`${o.slice(0,85).trimEnd()}…`:o}function F(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function qr(e){const n=[],r=new Set,i=(s,o)=>{const a=F(s);if(!a)return;const d=[a.name,a.label,a.relation,a.objectName].find(l=>typeof l=="string"&&l.trim().length>0);if(!d)return;const u=typeof a.kind=="string"?a.kind:o,x=`${u??""}:${d}`;if(r.has(x))return;r.add(x);const g=[a.description,a.provenance,a.sourceTier,a.source].find(l=>typeof l=="string"&&l.trim().length>0);n.push({name:d,kind:u,detail:g})};for(const s of e.artifacts){const o=se(s),a=F(o.evidence);for(const x of["lineage","sourceTables","semanticObjects","selectedAssets"]){const g=a==null?void 0:a[x];Array.isArray(g)&&g.forEach(l=>i(l,x==="sourceTables"?"source":void 0))}const d=F(o.analysisPlan)??F(a==null?void 0:a.analysisPlan),u=d==null?void 0:d.candidateTables;Array.isArray(u)&&u.forEach(x=>i(x,"relation"))}return n.slice(0,24)}function gn(e,n){var i;const r=se(n);return Wt(r)?"how":(i=Ce(e)??pt(r))!=null&&i.source?"dql":Te(e)??(typeof r.sql=="string"?r.sql:void 0)?"sql":qr(e).length>0?"lineage":"trust"}function ms({run:e,artifact:n,selected:r,t:i,themeMode:s,onInspect:o}){const a=se(n),d=We(a),[u,x]=f.useState(!1);if(f.useEffect(()=>{if(!u)return;const b=v=>{v.key==="Escape"&&x(!1)};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[u]),!d)return null;const g=Mr(a,d),l=gn(e,n),c=Ce(e)??pt(a),m=n.trustState==="certified"?Tr(n,a):void 0,h=t.jsxs("section",{"data-followup":"table","aria-label":`${it(e,n)} result`,style:{border:`1px solid ${r?"var(--accent)":"var(--border-default)"}`,borderRadius:12,background:"var(--bg-2)",overflow:"hidden",boxShadow:u?"0 24px 80px rgba(15,23,42,0.28)":r?"0 2px 10px rgba(107,93,211,0.12)":"0 1px 3px rgba(26,26,26,0.04)",...u?{width:"min(1440px, calc(100vw - 48px))",maxHeight:"calc(100vh - 48px)"}:{}},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"11px 13px",borderBottom:"1px solid var(--border-subtle)"},children:[t.jsx("span",{style:{width:30,height:30,borderRadius:8,background:n.trustState==="certified"?"var(--status-success-bg)":"var(--accent-dim)",color:n.trustState==="certified"?"var(--status-success)":"var(--accent)",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx(Ze,{kind:n.kind})}),t.jsxs("div",{style:{minWidth:0,flex:1},children:[t.jsx("div",{style:{fontSize:12.5,fontWeight:700,color:i.textPrimary,lineHeight:1.35},children:it(e,n)}),t.jsx("div",{style:{fontSize:11,color:i.textMuted,marginTop:2},children:Lt(n,a)})]}),t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>o(l),style:Le(i),children:[t.jsx(at,{size:12})," Inspect"]}),t.jsxs("button",{type:"button",className:"dql-ask-ghost","aria-label":u?"Return result to Copilot":"Expand result",title:u?"Return result to Copilot":"Expand this result for wide tables",onClick:()=>x(b=>!b),style:Le(i),children:[u?t.jsx(gi,{size:12}):t.jsx(ai,{size:12}),u?"Restore":"Expand result"]})]}),c?t.jsx(Ir,{artifact:c,certifiedBlockName:m,initialResult:d,initialChartConfig:g,payload:a,executionTarget:e.executionTarget,t:i,themeMode:s,embedded:!0,expanded:u}):t.jsx(cn,{result:d,themeMode:s,t:i,chartConfig:g,embedded:!0,tabLabels:{table:"Results",chart:"Visualization"},contentMaxHeight:u?"calc(100vh - 172px)":void 0,tableMaxHeight:u?"calc(100vh - 250px)":void 0})]});return!u||typeof document>"u"?h:t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{minHeight:96,border:"1px dashed var(--border-default)",borderRadius:12,display:"grid",placeItems:"center",color:i.textMuted,fontSize:11.5},children:"Result is open in the expanded viewer."}),ii.createPortal(t.jsx("div",{role:"dialog","aria-modal":"true","aria-label":`${it(e,n)} expanded result`,onClick:()=>x(!1),style:{position:"fixed",inset:0,zIndex:120,display:"grid",placeItems:"center",padding:24,background:"rgba(15,23,42,0.48)",backdropFilter:"blur(3px)"},children:t.jsx("div",{onClick:b=>b.stopPropagation(),style:{minWidth:0,maxWidth:"100%"},children:h})}),document.body)]})}function Jn(e){const{run:n,t:r,themeMode:i,threadId:s,appContext:o,selectedArtifactId:a,onOpenArtifact:d,onOpenApp:u,onInsertSql:x,onInsertDql:g,onReplaceDql:l,insertDqlActionLabel:c,replaceDqlActionLabel:m,onOpenBlock:h,onOpenResearch:b,onSelectClarification:v,onNextAction:q,onRepairedRun:T}=e,{dispatch:D}=$t(),[U,C]=f.useState(!1),N=d??(()=>D({type:"OPEN_AGENT_LOG",run:n}));if(n.route==="conversation"){const p=n.answerKind==="general_knowledge";return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,animation:"dql-agent-fadein 0.3s ease-out",maxWidth:"100%"},children:[p?t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:10.5,color:r.textMuted,fontWeight:650},children:[t.jsx(Ct,{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(At,{text:Ye(n.answer),t:r}):n.summary}),n.nextActions.length>0?t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:n.nextActions.map(_=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>q(_),style:It(r),children:_.label},_.id))}):null]})}const Q=n.trustState==="certified",B=n.status==="blocked",W=n.status==="needs_clarification",O=B||W?void 0:n.answer,$=B?"Couldn’t run this query":W?"Needs clarification":Q?"Certified answer":"AI-generated answer",j=B?Pr(n):void 0,K=n.evaluations.filter(p=>p.severity==="info").length,J=mn(n),A=n.artifacts.filter(p=>{const _=se(p);return!Ut(p,_)&&!!We(_)}),ee=new Set(A.map(p=>p.id)),P=n.artifacts.filter(p=>!Ut(p,se(p))&&!ee.has(p.id)),X=n.artifacts.filter(p=>Ut(p,se(p))),R=A[0]??P[0]??n.artifacts[0],E=ut(n),oe=n.route==="certified_answer"||n.route==="semantic_answer"||n.route==="generated_answer",G=n.nextActions.some(p=>p.route==="research"),be=oe&&E&&!G,ae=Ce(n),V=E&&!(ae!=null&&ae.sourcePath)&&!!((ae==null?void 0:ae.source)??Te(n)),w=c&&g||m&&l?_t(n):void 0,Z=()=>{var _;const p=O?Ye(O):j??n.summary;p&&((_=navigator.clipboard)==null||_.writeText(p).catch(()=>{}),C(!0),window.setTimeout(()=>C(!1),1400))};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10,maxWidth:"100%",animation:"dql-agent-fadein 0.3s ease-out"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,flexWrap:"wrap"},children:[B?t.jsx(Xe,{size:14,color:r.error}):Q?t.jsx(xe,{size:14,color:r.success}):t.jsx(Ve,{size:14,color:r.accent}),t.jsx("span",{style:{fontSize:12,fontWeight:650,color:B?r.error:r.textSecondary},children:$}),Q&&J[0]?t.jsxs("span",{style:{fontSize:11,color:r.textMuted},children:["from ",t.jsx("span",{style:{color:r.accent,fontWeight:600},children:J[0].label})]}):!B&&R&&K>0?t.jsxs("button",{type:"button",onClick:()=>N(R.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(st,{size:11,color:r.success})," ",K," check",K===1?"":"s"," passed"]}):null]}),O?t.jsx("div",{"data-followup":"answer",style:{fontSize:14.5,lineHeight:1.65,color:r.textPrimary},children:t.jsx(At,{text:Ye(O),t:r})}):j?t.jsx(Ks,{run:n,detail:j,threadId:s,onRepaired:p=>T(n.id,p),t:r}):n.summary?t.jsx("div",{"data-followup":"answer",style:{fontSize:14,lineHeight:1.6,color:r.textSecondary},children:Ie(n.summary)}):null,t.jsx(Cr,{run:n,t:r,onSelect:v}),A.map(p=>t.jsx(ms,{run:n,artifact:p,selected:p.id===a,t:r,themeMode:i,onInspect:_=>N(p.id,_)},p.id)),P.map(p=>{const _=se(p),te=p.id===a;return t.jsxs("button",{type:"button",className:"dql-ask-chip",onClick:()=>N(p.id,gn(n,p)),style:{display:"flex",alignItems:"center",gap:10,width:"fit-content",maxWidth:"100%",padding:"9px 12px",borderRadius:10,border:`1px solid ${te?"var(--accent)":"var(--border-default)"}`,background:"var(--bg-2)",boxShadow:te?"0 1px 6px rgba(107,93,211,0.12)":"none",cursor:"pointer",textAlign:"left",fontFamily:r.font},children:[t.jsx("span",{style:{width:30,height:30,borderRadius:7,background:p.trustState==="certified"?"var(--status-success-bg)":"var(--accent-dim)",color:p.trustState==="certified"?"var(--status-success)":"var(--accent)",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx(Ze,{kind:p.kind})}),t.jsxs("span",{style:{display:"flex",flexDirection:"column",gap:1,minWidth:0},children:[t.jsx("span",{style:{fontSize:12.5,fontWeight:650,color:r.textPrimary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Ie(p.title)}),t.jsx("span",{style:{fontSize:11,color:r.textMuted},children:Lt(p,_)})]}),t.jsx(sr,{size:14,color:r.textMuted,style:{flexShrink:0,marginLeft:6}})]},p.id)}),X.length>0?t.jsx("div",{style:{display:"grid",gap:8,gridTemplateColumns:"minmax(0, 1fr)",minWidth:0},children:X.map(p=>t.jsx(Br,{artifact:p,t:r,themeMode:i,onInsertSql:x,onInsertDql:g,insertDqlActionLabel:c,sourceRunId:n.id,sourceQuestion:n.question,onOpenBlock:h,onOpenResearch:b,onOpenApp:u,onNextAction:q},p.id))}):null,O||j||w||E||V||be||R?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:2,flexWrap:"wrap",marginTop:-2},children:[w&&g?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>g(w),style:Le(r),children:[t.jsx(rt,{size:12})," ",c]}):null,w&&l&&m?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>l(w),style:Le(r),children:[t.jsx(li,{size:12})," ",m]}):null,O||j?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:Z,style:Le(r),children:[U?t.jsx(st,{size:12}):t.jsx(dr,{size:12})," ",U?"Copied":"Copy"]}):null,E?t.jsx(hn,{run:n,t:r,appContext:o,onOpenApp:u}):null,V?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>q({id:"save-dql-block",label:"Save as block",route:"dql_block_draft"}),style:Le(r),children:[t.jsx(dt,{size:12})," Save as block"]}):null,be?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>q({id:"research-deeper",label:"Research this deeper",route:"research"}),style:Le(r),children:[t.jsx(lt,{size:12})," Research deeper"]}):null,R?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>N(R.id,Wt(se(R))?"how":"trust"),style:Le(r),children:[t.jsx(at,{size:12})," How it was answered"]}):null]}):null]})}function Cr({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 zr(e){const n=e.executionError;if(typeof n=="string"&&n.trim())return{stage:"execution",message:n};const r=F(n);if(r)return{stage:"execution",...r};const i=typeof e.refusalCode=="string"?e.refusalCode:void 0;if(i){const s=F(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 Wt(e){return!!(F(e.resolvedAnalyticalPlan)||F(e.analyticalExecutionGraph)||F(e.analyticalExecutionReceipt)||F(e.analyticalFailure)||F(e.semanticExecutionTrace)||F(e.diagnosticReceipt)||zr(e))}function Rr(e){if(!Wt(e))return;const n=F(e.diagnosticReceipt),r=F(e.resolvedAnalyticalPlan)??F(n==null?void 0:n.resolvedAnalyticalPlan);return{plan:r,frame:F(r==null?void 0:r.analyticalFrame),graph:F(e.analyticalExecutionGraph),receipt:F(e.analyticalExecutionReceipt),facts:F(e.analyticalFacts),narrative:F(e.analyticalNarrative),freshness:F(e.analyticalFreshnessObservation),failure:F(e.analyticalFailure)??F(n==null?void 0:n.failure)??zr(e),semantic:F(e.semanticExecutionTrace),diagnostic:n}}function bs(){return["Plan","DQL","Compiled SQL","Lineage","Trust & evidence","Actual steps","Failure & repair"]}function vs(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 js({run:e,contract:n,dqlArtifact:r,sql:i,lineage:s,t:o,onInsertSql:a,onInsertDql:d,onSaveBlock:u}){var he,Fe,De;const{dispatch:x}=$t(),g=n.plan,l=n.frame,c=n.graph,m=n.receipt,h=n.semantic,b=F(h==null?void 0:h.failure),v=n.failure??b,q=F(h==null?void 0:h.authoringRequest),T=F(h==null?void 0:h.runtimeRequest),D=_e(h==null?void 0:h.bindings),U=_e(h==null?void 0:h.steps),C=F(h==null?void 0:h.targetBinding),N=F(C==null?void 0:C.semanticSnapshot),Q=F(C==null?void 0:C.executionTarget),B=F(Q==null?void 0:Q.redactedContext),W=F(C==null?void 0:C.compileTarget),O=F(h==null?void 0:h.executionReceipt),$=_e(b==null?void 0:b.candidates),j=F(l==null?void 0:l.timeContext),K=F(l==null?void 0:l.comparison),J=F(l==null?void 0:l.ranking),A=_e(l==null?void 0:l.dimensions),ee=_e(l==null?void 0:l.memberBindings),P=_e(j==null?void 0:j.periods),X=_e(l==null?void 0:l.requestedOutputs),R=_e(c==null?void 0:c.nodes),E=Array.from(new Set([...we(v==null?void 0:v.safeActions),...we(b==null?void 0:b.safeActions)])),oe=_e(v==null?void 0:v.failedBindings),G=F(b==null?void 0:b.sqlExcerpt),be=e.artifacts.map(k=>We(se(k))).find(Boolean),ae=(r==null?void 0:r.name)??e.question,[V,w]=f.useState(null),Z=(k,le)=>{const Be=le.derivation.trustTransition;return`${k} as immutable derivation ${le.derivation.derivationId}. Trust: ${Be.previous} → ${Be.next}${Be.requiresReview?" (review required)":""}.`},p=async()=>{if(!(!(r!=null&&r.source)||!d))try{const k=await ne.deriveAnalyticalRepair(e.id,{version:1,action:"edit_dql",dqlSource:r.source});d({sql:i,dqlArtifact:r,result:be,title:ae,sourceRunId:e.id,question:e.question}),w(Z("Opened DQL in Notebook",k))}catch(k){w(k instanceof Error?k.message:String(k))}},_=async()=>{if(!(!i||!a))try{const k=await ne.deriveAnalyticalRepair(e.id,{version:1,action:"open_sql_notebook",sqlText:i});a(i,`${ae} repair`,{question:e.question,sourceRunId:e.id}),w(Z("Opened SQL in Notebook",k))}catch(k){w(k instanceof Error?k.message:String(k))}},te=async k=>{try{const le=await ne.deriveAnalyticalRepair(e.id,{version:1,action:k});w(Z(k==="retry_same_plan"?"Prepared the same bounded plan for retry":"Refreshed the governed snapshot and prepared the same plan for retry",le))}catch(le){w(le instanceof Error?le.message:String(le))}},re=async()=>{try{const k=await ne.deriveAnalyticalRepair(e.id,{version:1,action:"request_access"});w(Z("Recorded the access/connection repair and opened Database settings",k)),x({type:"SET_SETTINGS_TAB",tab:"database"}),x({type:"SET_MAIN_VIEW",view:"settings"})}catch(k){w(k instanceof Error?k.message:String(k))}},ve=()=>{x({type:"SET_SETTINGS_TAB",tab:"project"}),x({type:"SET_MAIN_VIEW",view:"settings"}),w("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(Xe,{size:13,color:"var(--status-error)",style:{flexShrink:0,marginTop:2}}):t.jsx(xe,{size:13,color:"var(--status-success)",style:{flexShrink:0,marginTop:2}}),t.jsxs("div",{style:{fontSize:12,color:o.textSecondary,lineHeight:1.5,minWidth:0},children:[t.jsx("div",{style:{fontWeight:700,color: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(z).join(" · ")})]}):t.jsx("div",{style:{marginTop:2},children:typeof(m==null?void 0:m.rowCount)=="number"?`Returned ${m.rowCount} row${m.rowCount===1?"":"s"}.`:"The query ran and returned a result."})]})]}),t.jsx(wt,{index:1,label:"Plan",t:o,open:!v,children:t.jsx(Yt,{rows:[["Question type",z((l==null?void 0:l.questionType)??(g==null?void 0:g.questionType))],["Selected route",z((c==null?void 0:c.route)??(g==null?void 0:g.recommendedRoute))],["Metric",we(l==null?void 0:l.metricConceptIds).join(", ")],["Entity grain",we(l==null?void 0:l.entityGrainIds).join(", ")],["Dimensions",A.map(k=>`${z(k.dimensionId)} (${z(k.role)})`).join(", ")],["Member filters",ee.map(k=>`${z(k.dimensionId)}: ${Array.isArray(k.canonicalValues)?k.canonicalValues.length:0} bound value(s)`).join(", ")],["Time policy",[j==null?void 0:j.timeRole,j==null?void 0:j.grain,j==null?void 0:j.timezone,j==null?void 0:j.completenessPolicy].map(z).filter(Boolean).join(" · ")],["Periods",P.map(k=>`${z(k.id)}: ${z(k.start)} → ${z(k.end)}`).join(`
|
|
85
|
+
`)],["Comparison",K?`${z(K.basePeriodId)} vs ${we(K.comparisonPeriodIds).join(", ")} · ${z(K.alignment)}`:l?"Not requested":"Not available — analytical planning did not complete"],["Ranking",J?`${z(J.direction)} · top ${z(J.limit)} · ${z(J.tiePolicy)}`:l?"Not requested":"Not available — analytical planning did not complete"],["Outputs",X.map(k=>`${z(k.id)} (${z(k.kind)})`).join(", ")],["Semantic metrics",we(q==null?void 0:q.metrics).join(", ")],["Semantic dimensions",we(q==null?void 0:q.dimensions).join(", ")]],t:o})}),t.jsx(wt,{index:2,label:"Trust & evidence",t:o,children:t.jsx(Yt,{rows:[["Trust state",e.trustState],["Snapshot",z((g==null?void 0:g.snapshotId)??(c==null?void 0:c.snapshotId))],["Plan fingerprint",z((g==null?void 0:g.fingerprint)??(c==null?void 0:c.planFingerprint))],["Graph fingerprint",z(c==null?void 0:c.fingerprint)],["Receipt",z(m==null?void 0:m.receiptId)],["Result fingerprint",z(m==null?void 0:m.resultFingerprint)],["Freshness observed through",z((he=n.freshness)==null?void 0:he.observedThrough)],["Fact set",z((Fe=n.facts)==null?void 0:Fe.fingerprint)],["Semantic adapter",z(h==null?void 0:h.adapter)],["Semantic compile status",z(h==null?void 0:h.status)],["Target proof",z((De=F(C==null?void 0:C.proof))==null?void 0:De.status)],["Target binding",z(C==null?void 0:C.bindingFingerprint)],["Compile target",z(W==null?void 0:W.kind)],["Local semantic snapshot",z((N==null?void 0:N.semanticCatalogFingerprint)??(N==null?void 0:N.sourceFingerprint))],["Runtime metric inventory proof",z(W==null?void 0:W.semanticCatalogFingerprint)],["Execution target",[Q==null?void 0:Q.driver,B==null?void 0:B.account,B==null?void 0:B.database,B==null?void 0:B.schema,B==null?void 0:B.role,B==null?void 0:B.warehouse].map(z).filter(Boolean).join(" · ")],["Semantic receipt",z(O==null?void 0:O.receiptId)],["Warehouse query ID",z(O==null?void 0:O.queryId)],["Executed SQL proof",z(O==null?void 0:O.executedSqlFingerprint)],["Runtime metrics",we(T==null?void 0:T.metrics).join(", ")],["Runtime dimensions",we(T==null?void 0:T.dimensions).join(", ")],["Member bindings",D.map(k=>`${z(k.authoringReference)} → ${z(k.runtimeReference)}${we(k.entityPath).length?` via ${we(k.entityPath).join(" → ")}`:""} (${z(k.status)})`).join(`
|
|
86
|
+
`)]],t:o,mono:!0})}),t.jsx(wt,{index:3,label:"Actual steps",t:o,children:t.jsxs("div",{style:{display:"grid",gap:6},children:[U.map((k,le)=>t.jsxs("div",{style:{fontSize:11.5,color:o.textSecondary},children:[t.jsxs("strong",{style:{color:z(k.status)==="failed"?"var(--status-error)":o.textPrimary},children:[le+1,". ",z(k.label)]})," ","— ",z(k.status)," · ",z(k.detail)]},`semantic:${z(k.id)||le}`)),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)),R.map((k,le)=>t.jsxs("div",{style:{fontSize:11.5,color:o.textSecondary},children:[t.jsxs("span",{style:{color:o.accent,fontFamily:o.fontMono},children:[le+1,". ",z(k.kind)]})," ","· ",z(k.id)]},z(k.id)||le)),U.length===0&&e.steps.length===0&&R.length===0?t.jsx(zt,{t:o,children:"No executable steps were recorded."}):null]})}),t.jsx(wt,{index:4,label:"Failure & repair",t:o,open:!!v,children:v?t.jsxs("div",{style:{display:"grid",gap:9},children:[t.jsx(Yt,{rows:[["Failure ID",z(v.failureId)],["Recoverability",z(v.recoverability)],["Failed bindings",oe.map(k=>`${z(k.qualifiedId??k.role)} (${z(k.reasonCode)})`).join(", ")],["Safe actions",E.join(", ")],["DQL fingerprint",z(v.dqlFingerprint)],["SQL fingerprint",z(v.sqlFingerprint)],["Semantic failure code",z(b==null?void 0:b.code)],["Failing identifier",z(b==null?void 0:b.identifier)],["Compiled SQL proof",z(b==null?void 0:b.compiledSqlFingerprint)],["Path candidates",$.map(k=>`${z(k.label)}
|
|
87
|
+
${z(k.runtimeReference)}`).join(`
|
|
88
|
+
`)]],t:o,mono:!0}),z(G==null?void 0:G.text)?t.jsxs("div",{children:[t.jsxs("div",{style:{fontSize:10.5,fontWeight:700,color:o.textSecondary,marginBottom:5},children:["Failing SQL context · lines ",z(G==null?void 0:G.startLine),"–",z(G==null?void 0:G.endLine)]}),t.jsx("pre",{style:ct(o),children:z(G==null?void 0:G.text)})]}):null,t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6},"aria-label":"Safe repair actions",children:[E.includes("edit_dql")&&d?t.jsxs("button",{type:"button",onClick:()=>void p(),style:Y(o),children:[t.jsx(Mt,{size:12})," Open DQL to repair"]}):null,E.includes("open_sql_notebook")&&a?t.jsxs("button",{type:"button",onClick:()=>void _(),style:Y(o),children:[t.jsx(dn,{size:12})," Open SQL in Notebook"]}):null,E.includes("retry_same_plan")?t.jsxs("button",{type:"button",onClick:()=>void te("retry_same_plan"),style:Y(o),children:[t.jsx(Ot,{size:12})," Retry same plan"]}):null,E.includes("refresh_snapshot")?t.jsxs("button",{type:"button",onClick:()=>void te("refresh_snapshot"),style:Y(o),children:[t.jsx(Ot,{size:12})," Refresh snapshot and prepare retry"]}):null,E.includes("request_access")||E.includes("change_authorized_connection")?t.jsxs("button",{type:"button",onClick:()=>void re(),style:Y(o),children:[t.jsx(Xe,{size:12})," Change connection or request access"]}):null,E.includes("reapply_semantic_runtime")?t.jsxs("button",{type:"button",onClick:ve,style:Y(o),children:[t.jsx(Ot,{size:12})," Reapply semantic runtime settings"]}):null]})]}):t.jsxs("div",{style:{display:"grid",gap:8},children:[t.jsx(zt,{t:o,children:"No failure was recorded for this run."}),r!=null&&r.sourcePath?null:r!=null&&r.source?t.jsxs("button",{type:"button",onClick:u,style:Y(o),children:[t.jsx(un,{size:12})," Save as draft block"]}):null]})}),V?t.jsx("div",{role:"status",style:{fontSize:10.5,color:V.toLowerCase().includes("created")?"var(--status-success)":"var(--status-error)"},children:V}):null]})}function wt({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 Yt({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 zt({t:e,children:n}){return t.jsx("div",{style:{fontSize:11,color:e.textMuted},children:n})}function _e(e){return Array.isArray(e)?e.flatMap(n=>F(n)?[F(n)]:[]):[]}function we(e){return Array.isArray(e)?e.filter(n=>typeof n=="string"):[]}function z(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):""}function kt(e){return{question:e.question??e.label,selectedEvidenceId:e.id}}function _r(e){var i;const n=e.artifacts.map(s=>We(se(s))).find(s=>!!s),r=(i=e.artifacts.find(s=>s.ref))==null?void 0:i.ref;return{runId:e.id,question:e.question,trustState:e.trustState,executionTarget:e.executionTarget,sourceCertifiedBlock:r,sql:Te(e),dqlArtifact:Ce(e),...n?{result:{columns:n.columns,rows:n.rows.slice(0,24),rowCount:n.rowCount}}:{}}}function ut(e){return!e.artifacts.some(r=>!!Ft(se(r)))&&e.status!=="blocked"&&e.status!=="needs_clarification"&&e.artifacts.some(r=>r.kind==="answer"||r.kind==="research_run")}function Ss({run:e,artifact:n,tab:r,t:i,appContext:s,onOpenApp:o,onChangeTab:a,onClose:d,onSaveBlock:u,onInsertSql:x,onInsertDql:g}){const l=se(n),c=Ce(e)??pt(l),m=Te(e)??(typeof l.sql=="string"?l.sql:void 0),h=We(l),b=it(e,n),v=mn(e),q=qr(e),T=xn(e),D=n.trustState==="certified",U=e.status==="blocked"||n.trustState==="blocked",C=ut(e),N=Rr(l),Q=Ar({analytical:!!N,blocked:U,hasDql:!!(c!=null&&c.source),hasSql:!!m,hasLineage:q.length>0}),B=Q.some(j=>j.id===r)?r:Q[0].id,W=U?"Blocked":D?"Certified":n.trustState==="governed"||n.trustState==="grounded"?"Governed":"AI-generated",O=U?"var(--status-error)":D?"var(--status-success)":n.trustState==="governed"||n.trustState==="grounded"?"var(--accent)":"var(--status-warning)",$=U?"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:$,color:O,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:"1px solid var(--border-subtle)"},children:t.jsx(Ze,{kind:n.kind})}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:13,fontWeight:650,color:i.textPrimary,lineHeight:1.35},children:it(e,n)}),t.jsx("div",{style:{fontSize:11,color:i.textMuted,marginTop:2},children:Lt(n,l)})]}),t.jsx("span",{style:{border:`1px solid ${O}`,color:O,background:$,borderRadius:999,padding:"2px 8px",fontSize:10,fontWeight:700,flexShrink:0,marginTop:2},children:W}),t.jsx("button",{type:"button",onClick:d,title:"Close",className:"dql-ask-ghost",style:{width:24,height:24,borderRadius:6,border:"none",background:"none",color:i.textMuted,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",flexShrink:0},children:t.jsx(qt,{size:14})})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"10px 16px",borderBottom:"1px solid var(--border-subtle)"},children:[C?t.jsx(hn,{run:e,t:i,appContext:s,onOpenApp:o}):null,C?t.jsxs("button",{type:"button",className:"dql-hover",onClick:u,style:{display:"inline-flex",alignItems:"center",gap:6,padding:"7px 13px",borderRadius:8,border:"1px solid var(--border-default)",background:"var(--bg-2)",color:i.textSecondary,fontSize:12,fontWeight:600,cursor:"pointer",fontFamily:i.font},children:[t.jsx(dt,{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(wi,{size:14})})]}),t.jsx("div",{style:{display:"flex",alignItems:"center",gap:16,padding:"0 16px",borderBottom:"1px solid var(--border-subtle)",flexShrink:0},children:Q.map(j=>t.jsx("button",{type:"button",onClick:()=>a(j.id),style:{padding:"10px 1px",fontSize:12,fontWeight:600,cursor:"pointer",border:"none",background:"none",fontFamily:i.font,whiteSpace:"nowrap",color:B===j.id?i.textPrimary:i.textMuted,boxShadow:B===j.id?`inset 0 -2px 0 0 ${i.accent}`:"none"},children:j.label},j.id))}),t.jsxs("div",{style:{flex:1,minHeight:0,overflow:"auto",padding:"14px 16px 20px"},children:[B==="how"&&N?t.jsx(js,{run:e,contract:N,dqlArtifact:c,sql:m,lineage:q,t:i,onInsertSql:x,onInsertDql:g,onSaveBlock:u}):null,B==="dql"?c!=null&&c.source?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[t.jsx("span",{style:{fontSize:11,color:i.textMuted},children:"Reusable governed artifact — save it as a block to certify."}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[g?t.jsx("button",{type:"button",onClick:()=>g({sql:m,dqlArtifact:c,result:h,chartConfig:h?He(l,h):void 0,title:b,sourceRunId:e.id,question:e.question}),style:Y(i),children:"Open DQL in notebook"}):null,t.jsx(Rt,{text:c.source,t:i,title:"Copy DQL"})]})]}),t.jsx("pre",{style:ct(i),children:c.source})]}):t.jsx(zt,{t:i,children:"The selected plan failed before a DQL source could be materialized. Review the Plan and Failure & repair sections."}):null,B==="sql"?m?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[t.jsx("span",{style:{fontSize:11,color:i.textMuted},children:"Attempted compiled SQL — open it in Notebook to inspect or repair."}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[x?t.jsx("button",{type:"button",onClick:()=>x(m,b,{question:e.question,sourceRunId:e.id}),style:Y(i),children:"Open SQL in notebook"}):null,t.jsx(Rt,{text:m,t:i,title:"Copy SQL"})]})]}),t.jsx("pre",{style:ct(i),children:m})]}):t.jsx(zt,{t:i,children:"Compilation stopped before SQL was produced. The DQL, plan, trust evidence, and failure steps are still retained."}):null,B==="lineage"?t.jsxs("div",{style:{display:"grid",gap:8},children:[t.jsx("div",{style:{fontSize:11,color:i.textMuted,lineHeight:1.5},children:"Governed semantic objects and physical sources used to produce this result."}),q.map(j=>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(ar,{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:j.name}),t.jsx("div",{style:{fontSize:10.5,color:i.textMuted,marginTop:2},children:[j.kind,j.detail].filter(Boolean).join(" · ")})]})]},`${j.kind??"asset"}:${j.name}`))]}):null,B==="trust"?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[T?t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-start",padding:"10px 12px",borderRadius:8,background: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(xe,{size:13,color:"var(--status-success)",style:{flexShrink:0,marginTop:1}}):t.jsx(Xe,{size:13,color:"var(--status-warning)",style:{flexShrink:0,marginTop:1}}),t.jsx("span",{style:{fontSize:12,color:i.textSecondary,lineHeight:1.5},children:T})]}):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(j=>t.jsxs("span",{style:Fr(i,j.certified),children:[j.certified?t.jsx(xe,{size:11}):t.jsx(lt,{size:11}),t.jsx("span",{children:j.label})]},j.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($r,{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(Er,{steps:e.steps,t:i})]}):null,t.jsx(Wr,{run:e,t:i})]}):null]})]})}function ws({t:e,text:n,source:r,left:i,top:s,draft:o,inputRef:a,onDraftChange:d,onClose:u,onSend:x}){const g=(l,c)=>t.jsx("button",{type:"button",onClick:()=>x(c),style:{border:"1px solid var(--border-subtle)",background:"var(--bg-1)",color:e.textSecondary,borderRadius:999,padding:"3px 10px",fontSize:11,fontWeight:550,cursor:"pointer",fontFamily:e.font},children:l});return t.jsxs("div",{"data-selpop":"true",style:{position:"fixed",left:i,top:s,zIndex:90,width:324,background:"var(--bg-2)",border:"1px solid var(--border-default)",borderRadius:12,boxShadow:"0 10px 32px rgba(26,26,26,0.16)",padding:10,display:"flex",flexDirection:"column",gap:8,animation:"dql-agent-fadein 0.14s ease-out",fontFamily:e.font},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx(Ve,{size:12,color:e.accent}),t.jsx("span",{style:{fontSize:11,fontWeight:700,color:e.textSecondary},children:"Follow up on this"}),t.jsx("span",{style:{fontSize:10,color:e.textMuted},children:r==="table"?"from the result":"from the answer"}),t.jsx("div",{style:{flex:1}}),t.jsx("button",{type:"button",onClick:u,style:{width:20,height:20,borderRadius:5,border:"none",background:"none",color:e.textMuted,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0},children:t.jsx(qt,{size:12})})]}),t.jsxs("div",{style:{borderLeft:`2px solid ${e.accent}`,background:"var(--accent-dim)",borderRadius:"0 6px 6px 0",padding:"5px 9px",fontSize:11.5,color:e.textSecondary,lineHeight:1.45,display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:["“",n,"”"]}),t.jsxs("div",{style:{display:"flex",gap:6},children:[t.jsx("input",{ref:a,value:o,onChange:l=>d(l.target.value),onKeyDown:l=>{l.key==="Enter"&&(l.preventDefault(),x(o))},placeholder:"Ask about this…",style:{flex:1,minWidth:0,border:"1px solid var(--border-default)",borderRadius:8,padding:"7px 10px",fontSize:12.5,fontFamily:e.font,color:e.textPrimary,background:"var(--bg-1)",outline:"none"}}),t.jsx("button",{type:"button",onClick:()=>x(o),title:"Send follow-up",style:{width:30,height:30,flexShrink:0,borderRadius:8,border:"none",background:"var(--accent)",color:"#fff",display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer"},children:t.jsx(lr,{size:13})})]}),t.jsxs("div",{style:{display:"flex",gap:5,flexWrap:"wrap"},children:[g("Why is this?","Why is this happening?"),g("Root cause","What is the root cause?"),g("Break it down","Break this down further")]})]})}function Jt(e){const n=e.replace(/^\/\w+\s+/,"").trim().replace(/[?.!]+$/,"");return(n?n.charAt(0).toUpperCase()+n.slice(1):"New app").slice(0,60)}function sn(e,n){return n!=null&&n.trim()?`${e} › ${n.trim()}`:e}function hn({run:e,t:n,appContext:r,onOpenApp:i}){const[s,o]=f.useState(!1),[a,d]=f.useState(null),[u,x]=f.useState(!1),[g,l]=f.useState("list"),[c,m]=f.useState(""),[h,b]=f.useState(!1),[v,q]=f.useState(null),[T,D]=f.useState(null),U=f.useRef(null),C=async()=>{d(null),x(!1);try{const $=await ne.listAppsStrict();d($),$.length===0&&l("new")}catch{d([]),x(!0)}},N=()=>{o(!0),q(null),l("list"),U.current=null,m(Jt(e.question)),C()},Q=()=>{h||(o(!1),q(null))},B=async($,j,K,J)=>{const A=Jt(e.question),ee=Ce(e),P=await ne.createAiPin($,{dashboardId:j,title:A,answer:e.answer??e.summary,question:e.question,sql:Te(e),certification:e.trustState==="certified"?"certified":"ai_generated",reviewStatus:e.trustState==="certified"?"certified":"needs_review",analysisPlan:ee?{dqlArtifact:ee}:void 0});if(!P.ok)throw new Error("Could not add to app.");D({appId:$,dashboardId:j,name:K,dashboardTitle:J,tileTitle:P.pin.title||A}),window.dispatchEvent(new CustomEvent("dql-app-dashboard-updated",{detail:{appId:$,dashboardId:j,tileId:P.pin.tileId}})),o(!1)},W=async $=>{var j,K,J,A,ee;if(!h){b(!0),q(null);try{let P=(r==null?void 0:r.appId)===$.id?r.dashboardId:void 0,X=(r==null?void 0:r.appId)===$.id?r.dashboardTitle:void 0,R=null;if(!P){R=await ne.getApp($.id);const E=(j=R==null?void 0:R.app)==null?void 0:j.homepage;if(P=(E==null?void 0:E.type)==="dashboard"?E.id:(J=(K=R==null?void 0:R.dashboards)==null?void 0:K[0])==null?void 0:J.id,!P){const oe=await ne.createAppDashboard($.id,{title:"Overview"});if(!oe.ok)throw new Error(oe.error);P=oe.dashboard.id,X=oe.dashboard.metadata.title}}X||(R=R??await ne.getApp($.id),X=(ee=(A=R==null?void 0:R.dashboards)==null?void 0:A.find(E=>E.id===P))==null?void 0:ee.title),await B($.id,P,$.name,X)}catch(P){q(P instanceof Error?P.message:"Could not add to app.")}finally{b(!1)}}},O=async()=>{if(h)return;const $=c.trim()||Jt(e.question);b(!0),q(null);try{if(!U.current){const j=await ne.createApp({name:$,domain:"general",dashboardTitle:"Overview",tags:[],owners:[],selectedBlockIds:[]});U.current={appId:j.app.id,dashboardId:j.dashboardId}}await B(U.current.appId,U.current.dashboardId,$,"Overview"),U.current=null}catch(j){q(j instanceof Error?j.message:"Could not create the app.")}finally{b(!1)}};return t.jsxs("div",{style:{position:"relative",display:"inline-flex",alignItems:"center",gap:6},children:[T?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(ot,{size:15})}),t.jsxs("span",{style:{display:"grid",gap:1,minWidth:0},children:[t.jsx("b",{style:{fontSize:11.5},children:"Added to App"}),t.jsx("span",{title:sn(T.name,T.dashboardTitle),style:{fontSize:10.5,color:n.textSecondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:sn(T.name,T.dashboardTitle)}),t.jsxs("span",{title:T.tileTitle,style:{fontSize:10,color:n.textMuted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Tile: ",T.tileTitle]})]}),i?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>i(T.appId,T.dashboardId),style:{...Y(n),color:n.success,whiteSpace:"nowrap"},title:"Open the App page containing this tile",children:["Open App ",t.jsx(hi,{size:12})]}):null]}):null,t.jsxs("button",{type:"button",className:"dql-hover dql-lift",onClick:N,style:T?Y(n):tr(n),children:[t.jsx(Zt,{size:13}),T?"Add to another":"Add to app"]}),s?t.jsxs(t.Fragment,{children:[t.jsx("div",{onClick:Q,style:{position:"fixed",inset:0,zIndex:40}}),t.jsxs("div",{style:Ds(n),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[t.jsx("span",{style:{fontSize:12,fontWeight:700,color:n.textPrimary},children:g==="new"?"Name the new app":"Add to an app"}),t.jsx("button",{type:"button",onClick:Q,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,g==="new"?t.jsxs("div",{style:{display:"grid",gap:8},children:[t.jsx("input",{autoFocus:!0,value:c,onChange:$=>m($.target.value),onKeyDown:$=>{$.key==="Enter"&&O()},placeholder:"App name",style:Ns(n)}),t.jsxs("div",{style:{display:"flex",gap:6},children:[a&&a.length>0?t.jsx("button",{type:"button",className:"dql-hover",onClick:()=>l("list"),style:Y(n),children:"Back"}):null,t.jsxs("button",{type:"button",className:"dql-hover",disabled:h||!c.trim(),onClick:()=>void O(),style:{...tr(n),flex:1,justifyContent:"center"},children:[h?t.jsx(Qe,{size:13,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(rt,{size:13}),"Create & add"]})]})]}):a===null?t.jsx("div",{style:{fontSize:11.5,color:n.textMuted,padding:"8px 2px"},children:"Loading apps…"}):u?t.jsxs("div",{style:{display:"grid",gap:8},children:[t.jsx("div",{style:{fontSize:11.5,color:n.error,lineHeight:1.4},children:"Couldn't load your apps."}),t.jsxs("div",{style:{display:"flex",gap:6},children:[t.jsx("button",{type:"button",className:"dql-hover",onClick:()=>void C(),style:Y(n),children:"Retry"}),t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>l("new"),style:{...nr(n),width:"auto",flex:1,marginBottom:0,justifyContent:"center"},children:[t.jsx(rt,{size:13})," New app…"]})]})]}):t.jsxs("div",{style:{display:"grid",gap:3,maxHeight:244,overflow:"auto"},children:[t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>l("new"),style:nr(n),children:[t.jsx(rt,{size:13})," New app…"]}),a.map($=>t.jsxs("button",{type:"button",className:"dql-hover",disabled:h,onClick:()=>void W($),style:Ps(n),children:[t.jsx(Zt,{size:13,style:{flex:"0 0 auto",opacity:.7}}),t.jsx("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",textAlign:"left"},children:$.name})]},$.id))]})]})]}):null]})}function xn(e){var n;if(e.trustState==="certified")return"Answered from a certified block.";if(e.route==="dql_block_draft")return"Prepared an ownerless review draft. Add it to Block Studio when you are ready to save it.";if(e.trustState==="governed")return"Built from governed metrics and dimensions.";if(e.trustState==="grounded")return"Ran cleanly against your data. Save it as a block when it is reusable.";if(yn(e)){const r=e.artifacts.map(o=>o.payload).filter(o=>!!(o&&typeof o=="object"&&!Array.isArray(o)));if(r.some(o=>{const a=o.result;return!!(a&&typeof a=="object"&&!Array.isArray(a))}))return"Exploratory · DBT-grounded. The query and bounded join probes ran, but no certified relationship path covers it yet.";const s=(n=r.find(o=>typeof o.executionError=="string"))==null?void 0:n.executionError;return typeof s=="string"&&s.trim()?"Exploratory · DBT-grounded. DQL prepared a review-required query, but its bounded execution failed. Inspect the error and DQL artifact before reuse.":"Exploratory · DBT-grounded. DQL prepared a review-required query, but it has not executed yet."}return e.trustState==="review_required"?"AI-generated answer. Save it as a block when you want to keep it.":(e.trustState==="blocked",null)}function yn(e){return e.artifacts.some(n=>{const r=n.payload;return!!(r&&typeof r=="object"&&!Array.isArray(r)&&r.exploratoryCandidate)})}function ks(e){return e.trustState==="certified"?"Certified answer":e.route==="dql_block_draft"?"Draft block":yn(e)?"Exploratory DBT-grounded answer":e.route==="semantic_answer"?"Semantic answer":e.route==="generated_answer"?"AI-generated answer":mr[e.route]}function As({artifact:e,payload:n,t:r,onOpenApp:i}){const s=typeof n.sessionId=="string"?n.sessionId:void 0,o=n.proposal&&typeof n.proposal=="object"?n.proposal:void 0,a=typeof n.proposalHash=="string"?n.proposalHash:void 0,[d,u]=f.useState(()=>o?ci(o):new Set),[x,g]=f.useState(!1),[l,c]=f.useState(null),[m,h]=f.useState(null);if(!o||!s)return t.jsxs("div",{style:an(r),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(Ze,{kind:e.kind}),t.jsx("div",{style:{fontSize:12,fontWeight:800,color:r.textPrimary},children:e.title})]}),t.jsx("div",{style:{fontSize:11.5,color:r.textMuted},children:"This proposal is no longer available. Ask again to rebuild it."})]});const b=async()=>{var q,T;g(!0),c(null);const v=await ne.commitAppAiBuild(s,{selectedTileIds:Array.from(d),expectedProposalHash:a});if(g(!1),!v.ok){c(v.error);return}h({appId:((q=v.app)==null?void 0:q.id)??v.session.appId??"",dashboardId:v.dashboardId??void 0,name:((T=v.app)==null?void 0:T.name)??e.title})};return t.jsxs("div",{style:an(r),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(Ze,{kind:e.kind}),t.jsx("div",{style:{fontSize:12,fontWeight:800,color:r.textPrimary,flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Ie(e.title)})]}),m?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(ot,{size:13})," Created ",m.name]}),m.appId&&i?t.jsx("button",{type:"button",className:"dql-hover",onClick:()=>i(m.appId,m.dashboardId),style:Y(r),children:"Open app"}):null]}):t.jsx(di,{proposal:o,t:r,selected:d,onToggle:v=>{u(q=>{const T=new Set(q);return T.has(v)?T.delete(v):T.add(v),T})},onCreate:()=>void b(),busy:x,error:l,compact:!0})]})}function Ir({artifact:e,certifiedBlockName:n,initialResult:r,initialChartConfig:i,payload:s,executionTarget:o,t:a,themeMode:d,embedded:u=!1,expanded:x=!1}){var V;const[g,l]=f.useState(e),[c,m]=f.useState(()=>e.parameters??[]),[h,b]=f.useState(()=>({...e.parameterValues??{},...on(s)})),[v,q]=f.useState(r),[T,D]=f.useState(i),[U,C]=f.useState(!!n),[N,Q]=f.useState(!1),[B,W]=f.useState(null),[O,$]=f.useState(!1),[j,K]=f.useState(""),[J,A]=f.useState(""),ee=f.useRef(!1),P=f.useRef(e);P.current=e;const X=rs(e);f.useEffect(()=>{const w=P.current;if(l(w),$(!1),!n){m(w.parameters??[]),b({...w.parameterValues??{},...on(s)}),C(!1);return}let Z=!1;return C(!0),ne.getCertifiedBlockParameters(n).then(p=>{Z||(m(p.parameters),b(_=>({...Object.fromEntries(p.parameters.flatMap(te=>te.default===void 0?[]:[[te.name,te.default]])),..._})))}).catch(p=>{Z||W(p instanceof Error?p.message:String(p))}).finally(()=>{Z||C(!1)}),()=>{Z=!0}},[X,n]);const R=async()=>{if(!ee.current){ee.current=!0,Q(!0),W(null);try{const w=await ne.invokeDqlArtifact(g,h,void 0,n,o);q(w.result),l(w.artifact),w.result.chartConfig&&typeof w.result.chartConfig=="object"&&D(w.result.chartConfig),w.parameters.length>0&&m(w.parameters)}catch(w){W(w instanceof Error?w.message:String(w))}finally{ee.current=!1,Q(!1)}}},E=f.useMemo(()=>hr(g,v),[g,v]),oe=()=>{const w=E[0];w&&(K(w.column),A(w.values[0]==null?"":String(w.values[0])),$(!0),W(null))},G=async()=>{try{const w=g.kind==="sql_block"?await ne.addDqlArtifactResultFilter(g,v.columns,j,J,o):is(g,v,j,J);l(w.artifact),m(w.artifact.parameters??[]),b(Z=>({...Z,...w.artifact.parameterValues??{}})),$(!1),W(null)}catch(w){W(w instanceof Error?w.message:String(w))}},be=c.some(pr),ae=Object.entries(h).filter(([,w])=>w!=null&&w!=="");return t.jsxs("div",{style:{display:"grid",gap:9},children:[ae.length>0?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap",padding:u?"8px 12px 0":0},children:[t.jsx("span",{style:{fontSize:10.5,fontWeight:750,color:a.textMuted},children:"Applied inputs"}),ae.map(([w,Z])=>t.jsxs("span",{style:{fontSize:10.5,color:a.textSecondary,border:`1px solid ${a.cellBorder}`,background:a.appBg,borderRadius:999,padding:"2px 7px"},children:[w.replace(/_/g," ")," = ",qs(Z)]},w))]}):null,U?t.jsx("div",{style:{fontSize:10.5,color:a.textMuted},children:"Loading reusable inputs…"}):be||E.length>0?t.jsxs("div",{style:{display:"grid",gap:8,padding:9,margin:u?"0 12px":0,border:`1px solid ${a.cellBorder}`,borderRadius:7,background:a.appBg},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:11,fontWeight:800,color:a.textPrimary},children:"Change DQL inputs"}),t.jsx("div",{style:{fontSize:10,color:a.textMuted},children:"Reruns this DQL artifact directly. It does not start another AI search."})]}),E.length>0?t.jsxs("button",{type:"button",onClick:oe,style:Y(a),children:[t.jsx(rt,{size:11})," Add result filter"]}):null,t.jsxs("button",{type:"button",disabled:N,onClick:()=>void R(),style:{...Y(a),color:a.accent,opacity:N?.65:1},children:[N?t.jsx(Qe,{size:11,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(Ve,{size:11}),N?"Running…":"Apply"]})]}),O?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:j,onChange:w=>{const Z=w.target.value,p=E.find(_=>_.column===Z);K(Z),A((p==null?void 0:p.values[0])==null?"":String(p.values[0]))},style:rr(a),children:E.map(w=>t.jsx("option",{value:w.column,children:w.column.split("_").join(" ")},w.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:J,list:`ask-filter-${j}`,onChange:w=>A(w.target.value),style:rr(a)}),t.jsx("datalist",{id:`ask-filter-${j}`,children:(((V=E.find(w=>w.column===j))==null?void 0:V.values)??[]).map(w=>t.jsx("option",{value:String(w)},`${typeof w}:${String(w)}`))})]}),t.jsx("button",{type:"button",onClick:()=>{G()},style:{...Y(a),color:a.accent},children:"Add input"}),t.jsx("button",{type:"button",onClick:()=>$(!1),style:Y(a),children:"Cancel"})]}):null,c.length>0?t.jsx(Ni,{parameters:c,values:h,onChange:(w,Z)=>b(p=>({...p,[w]:Z})),t:a}):null,E.length>0?t.jsx("div",{style:{fontSize:9.5,color:a.textMuted},children:"Extra filters are available only for semantic dimensions in this result. They stay transient until you explicitly save a block."}):null]}):null,B?t.jsx("div",{style:{fontSize:10.5,color:a.error},children:B}):null,t.jsx(cn,{result:v,themeMode:d,t:a,chartConfig:T,embedded:u,tabLabels:u?{table:"Results",chart:"Visualization"}:void 0,contentMaxHeight:x?"calc(100vh - 172px)":void 0,tableMaxHeight:x?"calc(100vh - 250px)":void 0})]})}function on(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 qs(e){return Array.isArray(e)?e.map(n=>String(n)).join(", "):typeof e=="boolean"?e?"true":"false":String(e)}function Tr(e,n){const r=n.result&&typeof n.result=="object"&&!Array.isArray(n.result)?n.result:void 0,i=n.block&&typeof n.block=="object"&&!Array.isArray(n.block)?n.block:void 0;return[r==null?void 0:r.blockName,n.sourceCertifiedBlock,i==null?void 0:i.name,e.ref].find(o=>typeof o=="string"&&o.trim().length>0)}function Br({artifact:e,t:n,themeMode:r,onInsertSql:i,onInsertDql:s,insertDqlActionLabel:o,sourceRunId:a,sourceQuestion:d,onOpenBlock:u,onOpenResearch:x,onOpenApp:g,onNextAction:l}){const c=e.payload&&typeof e.payload=="object"?e.payload:{};if(e.kind==="app_proposal")return t.jsx(As,{artifact:e,payload:c,t:n,onOpenApp:g});const m=We(c),h=pt(c),b=Ft(c),v=typeof c.sql=="string"?c.sql:typeof c.sqlPreview=="string"?c.sqlPreview:typeof c.proposedSql=="string"?c.proposedSql:void 0,q=typeof c.name=="string"?c.name:e.title,T=typeof c.path=="string"?c.path:e.ref,D=c.draftBlock&&typeof c.draftBlock=="object"&&!Array.isArray(c.draftBlock)?c.draftBlock:void 0,U=typeof(D==null?void 0:D.path)=="string"?D.path:void 0,C=typeof(D==null?void 0:D.name)=="string"?D.name:void 0,N=(h==null?void 0:h.sourcePath)??U??(e.kind==="dql_block_draft"?T:void 0),Q=(h==null?void 0:h.name)??C??q,B=(h==null?void 0:h.kind)==="sql_block"||e.kind==="dql_block_draft"?"Open DQL draft":"Open DQL artifact",W=c.plan&&typeof c.plan=="object"?c.plan:void 0,O=Array.isArray(W==null?void 0:W.steps)?W.steps:[],$=Array.isArray(W==null?void 0:W.gaps)?W.gaps.map(String):[],j=typeof c.researchRunId=="string"?c.researchRunId:e.kind==="research_run"&&typeof e.ref=="string"?e.ref:void 0,K=typeof c.notebookPath=="string"?c.notebookPath:void 0,J=Array.isArray(c.generatedPaths)?c.generatedPaths.filter(R=>typeof R=="string"):[],A=c.narration&&typeof c.narration=="object"?c.narration:void 0,ee=Array.isArray(A==null?void 0:A.keyFindings)?A.keyFindings.filter(R=>typeof R=="string"):[],P=typeof(A==null?void 0:A.recommendation)=="string"?A.recommendation:void 0,X=e.trustState==="certified"?Tr(e,c):void 0;if(e.kind==="dql_block_draft"){const R=oe=>Array.isArray(oe)?oe.filter(G=>typeof G=="string"):void 0,E=c.certifierVerdict&&typeof c.certifierVerdict=="object"?c.certifierVerdict:void 0;return t.jsx(Di,{t:n,name:typeof c.name=="string"?c.name:q,status:"draft",description:typeof c.description=="string"?c.description:void 0,dql:(h==null?void 0:h.source)??(typeof c.dqlSource=="string"?c.dqlSource:void 0),sqlPreview:v,grain:typeof c.grain=="string"?c.grain:void 0,outputs:R(c.outputs),dimensions:R(c.dimensions)??(h==null?void 0:h.dimensions),entities:R(c.entities),certifierVerdict:E?{blocking:R(E.blocking)??[],warnings:R(E.warnings)??[],ready:!!E.ready}:void 0,actions:t.jsxs(t.Fragment,{children:[v&&s?t.jsx("button",{type:"button",onClick:()=>s({sql:v,dqlArtifact:h,result:m,chartConfig:m?He(c,m):void 0,title:q,sourceRunId:a,question:d}),style:Y(n),children:o??"Insert as DQL cell"}):v&&i?t.jsx("button",{type:"button",onClick:()=>i(v,q,{question:d,sourceRunId:a}),style:Y(n),children:"Insert SQL preview"}):null,N&&u?t.jsx("button",{type:"button",onClick:()=>u(N,Q),style:Y(n),children:B}):null]})})}return t.jsxs("div",{style:an(n),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(Ze,{kind:e.kind}),t.jsx("div",{style:{fontSize:12,fontWeight:800,color:n.textPrimary,flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Ie(e.title)})]}),ee.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(Yn,{items:ee,t:n,renderItem:(R,E)=>t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.4,display:"flex",gap:6},children:[t.jsx("span",{style:{color:n.accent},children:"•"}),t.jsx("span",{children:R})]},E)})]}):O.length>0?t.jsx("div",{style:{display:"grid",gap:5},children:t.jsx(Yn,{items:O,t:n,renderItem:(R,E)=>t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.35},children:[E+1,". ",String(R.thought??R.expectation??"Research step")]},E)})}):null,P?t.jsxs("div",{style:{fontSize:11.5,color:n.textPrimary,lineHeight:1.4,display:"flex",gap:6},children:[t.jsx("span",{style:{color:n.accent},children:"→"}),t.jsx("span",{children:P})]}):null,m?h?t.jsx(Ir,{artifact:h,certifiedBlockName:X,initialResult:m,initialChartConfig:He(c,m),payload:c,t:n,themeMode:r}):t.jsx(cn,{result:m,themeMode:r,t:n,chartConfig:He(c,m)}):null,h?t.jsxs("details",{children:[t.jsxs("summary",{style:{cursor:"pointer",fontSize:11,color:n.textSecondary,listStyle:"none",display:"flex",alignItems:"center",gap:5},children:[t.jsx(dt,{size:12}),t.jsx("span",{children:"View DQL artifact"}),t.jsxs("span",{style:{marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:4},children:[h.source?t.jsx(Rt,{text:h.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:R=>{R.preventDefault(),R.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(un,{size:12})," Save as block"]}):null]})]}),h.sourcePath?t.jsx("div",{style:{marginTop:6,fontSize:10.5,color:n.textMuted},children:h.sourcePath}):null,t.jsx("pre",{style:{...ct(n),marginTop:6},children:h.source})]}):null,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(dn,{size:12}),t.jsx("span",{children:Lr(!!h)}),t.jsx("span",{style:{marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:4},children:t.jsx(Rt,{text:v,t:n,title:"Copy SQL"})})]}),t.jsx("pre",{style:{...ct(n),marginTop:6},children:v})]}):null,$.length>0?t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.4},children:["Gaps: ",$.join(", ")]}):null,J.length>0?t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.4},children:["Files: ",J.join(", ")]}):null,t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[j&&x?t.jsx("button",{type:"button",onClick:()=>x(j,K),style:Y(n),children:"Open research"}):null,v&&s?t.jsx("button",{type:"button",onClick:()=>s({sql:v,dqlArtifact:h,result:m,chartConfig:m?He(c,m):void 0,title:q,mixedSourcePlan:b,sourceRunId:a,question:d}),style:b?{...Y(n),background:n.accent,borderColor:n.accent,color:"#fff",fontWeight:850,padding:"7px 11px"}:Y(n),children:b?"Add workflow to notebook":h?"Insert as DQL cell":"Add SQL to notebook"}):v&&i?t.jsx("button",{type:"button",onClick:()=>i(v,q,{question:d,sourceRunId:a}),style:Y(n),children:"Insert SQL preview"}):null,N&&u?t.jsx("button",{type:"button",onClick:()=>u(N,Q),style:Y(n),children:B}):null]})]})}function Cs({run:e}){return e.trustState==="certified"?t.jsx(xe,{size:16,color:"#16a34a"}):e.trustState==="governed"?t.jsx(xe,{size:16,color:"#2563eb"}):e.trustState==="grounded"?t.jsx(xe,{size:16,color:"#2563eb"}):e.status==="completed"?t.jsx(ot,{size:16,color:"#16a34a"}):e.status==="blocked"?t.jsx(en,{size:16,color:"#ef4444"}):t.jsx(en,{size:16,color:"#d97706"})}function Ze({kind:e}){return e==="sql_cell"?t.jsx(dn,{size:14}):e==="dql_block_draft"?t.jsx(dt,{size:14}):e==="app_draft"||e==="app_proposal"?t.jsx(Zt,{size:14}):e==="research_run"?t.jsx(lt,{size:14}):t.jsx(Ve,{size:14})}function zs({run:e,t:n}){const r=e.trustState==="certified"?n.success:e.trustState==="governed"||e.trustState==="grounded"?n.accent:e.trustState==="blocked"?n.error:e.trustState==="not_applicable"?n.textMuted:n.warning,i=e.trustState==="certified"?"Certified":e.route==="dql_block_draft"?"Draft":yn(e)?"Exploratory":e.trustState==="blocked"?"Needs input":"AI-generated";return t.jsx("span",{style:{border:`1px solid ${r}55`,color:r,background:`${r}12`,borderRadius:999,padding:"3px 7px",fontSize:10,fontWeight:850},children:i})}function $r({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(ln,{evaluation:s,t:n},s.id)),i.length>0?t.jsxs("details",{children:[t.jsxs("summary",{className:"dql-hover",style:{cursor:"pointer",listStyle:"none",display:"inline-flex",alignItems:"center",gap:6,fontSize:11,fontWeight:700,color:n.textMuted,width:"fit-content"},children:[t.jsx(xe,{size:12,color:n.success}),t.jsxs("span",{children:[i.length," check",i.length>1?"s":""," verified"]})]}),t.jsx("div",{style:{display:"grid",gap:5,marginTop:7},children:i.map(s=>t.jsx(ln,{evaluation:s,t:n},s.id))})]}):null]})}function ln({evaluation:e,t:n}){const r=e.passed?n.success:e.severity==="blocking"?n.error:n.warning;return t.jsxs("div",{style:{display:"flex",gap:7,alignItems:"flex-start",fontSize:11.5,color:n.textSecondary,minWidth:0},children:[t.jsx("span",{style:{color:r,lineHeight:"16px",flex:"0 0 auto",fontWeight:800},children:e.passed?"OK":e.severity==="blocking"?"Stop":"Review"}),t.jsxs("span",{style:{lineHeight:1.4,minWidth:0,flex:1,overflowWrap:"anywhere"},children:[e.message,!e.passed&&e.suggestedRepair?t.jsxs("span",{style:{display:"block",color:n.textMuted,marginTop:1},children:["↳ ",e.suggestedRepair]}):null]})]})}function Xt({t:e,icon:n,label:r,tone:i}){const s=i==="accent"?e.accent:i==="warning"?e.warning:e.textMuted;return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,border:`1px solid ${s}44`,color:s,background:`${s}10`,borderRadius:999,padding:"2px 7px",fontSize:10,fontWeight:800},children:[n,t.jsx("span",{children:r})]})}function Rs(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 Er({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(at,{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=Rs(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(ar,{size:10}):r.status==="repaired"?t.jsx(Mt,{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(ln,{evaluation:s,t:n},s.id))}):null]},r.id)})})]})}function _s(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 Is(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 Xn(e){return`${e}_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function Ye(e){return e.replace(/^\s*Outcome\s*:\s*[^\n]*\n+/i,"").replace(/^\s*Review required:\s*/gim,"").replace(/\breview-required\b/gi,"AI-generated").replace(/\*\*(.+?)\*\*/g,"$1").replace(/`([^`]+)`/g,"$1").replace(/^_(.+?)_$/gm,"$1").trim()}function Ie(e){return e.replace(/^\s*Review required:\s*/gim,"").replace(/\breview-required\b/gi,"AI-generated").replace(/\bqueued for review\b/gi,"saved as a draft").trim()}function Ts(e,n){const r=i=>i.toLowerCase().replace(/[\s.,!?'"()`*_-]+/g," ").trim();return r(e)===r(n)}function We(e){var r,i;const n=[e.result,e.resultPreview,(r=e.researchRun)==null?void 0:r.resultPreview,(i=e.result)==null?void 0:i.result];for(const s of n){if(!s||typeof s!="object")continue;const o=s;if(!Array.isArray(o.rows)&&!Array.isArray(o.columns))continue;const a=Array.isArray(o.rows)?o.rows.filter(u=>!!(u&&typeof u=="object")):[],d=Array.isArray(o.columns)&&o.columns.length>0?o.columns.map(u=>typeof u=="string"?u:(u==null?void 0:u.name)??String(u)):a.length>0?Object.keys(a[0]):[];if(!(a.length===0&&d.length===0&&typeof o.rowCount!="number"))return{columns:d,rows:a,rowCount:typeof o.rowCount=="number"?o.rowCount:a.length,...typeof o.executionTime=="number"?{executionTime:o.executionTime}:{}}}}function He(e,n){const r=e.result&&typeof e.result=="object"?e.result:void 0,i=r!=null&&r.chartConfig&&typeof r.chartConfig=="object"?r.chartConfig:e.chartConfig&&typeof e.chartConfig=="object"?e.chartConfig:{},s=typeof e.suggestedViz=="string"?e.suggestedViz:typeof(r==null?void 0:r.suggestedViz)=="string"?r.suggestedViz:void 0,o=i.decisionSource==="authored"||i.decisionSource==="agent"||i.decisionSource==="data"||i.decisionSource==="user"?i.decisionSource:void 0,a=typeof i.chart=="string"?i.chart:s,d=a?a.toLowerCase().replace(/_/g,"-")==="single-value"?"kpi":a:void 0,u=n.columns,x=c=>typeof i[c]=="string"&&u.includes(i[c])?i[c]:void 0,g=Array.isArray(i.metrics)?i.metrics.filter(c=>typeof c=="string"&&u.includes(c)):[],l={...d?{chart:d}:{},...d?{decisionSource:o??"agent"}:{},...typeof i.rationale=="string"?{rationale:i.rationale}:{},...x("x")?{x:x("x")}:{},...x("y")?{y:x("y")}:{},...g.length>0?{metrics:g}:{},...x("color")?{color:x("color")}:{},...typeof i.title=="string"?{title:i.title}:{},...typeof i.colorPalette=="string"?{colorPalette:i.colorPalette}:{},...typeof i.maxItems=="number"?{maxItems:i.maxItems}:{}};return Object.keys(l).length>0?l:void 0}function Mr(e,n){var i;const r=He(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 pt(e){const n=Je(e.dqlArtifact);if(n)return n;const r=e.researchRun&&typeof e.researchRun=="object"&&!Array.isArray(e.researchRun)?e.researchRun:void 0;return Je(r==null?void 0:r.dqlArtifact)}function Lr(e){return e?"View compiled SQL preview":"View SQL preview"}function Rt({text:e,t:n,title:r="Copy"}){const[i,s]=f.useState(!1),o=async a=>{a.preventDefault(),a.stopPropagation();try{await navigator.clipboard.writeText(e),s(!0),setTimeout(()=>s(!1),1500)}catch{}};return t.jsxs("button",{type:"button",onClick:o,title:r,className:"dql-hover",style:{border:"none",background:"transparent",cursor:"pointer",color:i?n.success:n.textMuted,display:"inline-flex",alignItems:"center",gap:3,fontSize:10.5,fontWeight:650,padding:"2px 4px"},children:[i?t.jsx(st,{size:12}):t.jsx(dr,{size:12}),i?"Copied":null]})}function se(e){return e.payload&&typeof e.payload=="object"&&!Array.isArray(e.payload)?e.payload:{}}function Bs(e){var i,s,o;const n=[],r=new Set;for(const a of e.artifacts){const d=se(a),u=Array.isArray(d.memoryContext)?d.memoryContext:[];for(const g of u){if(!g||typeof g!="object")continue;const l=g,c=typeof l.title=="string"?l.title.trim():"";!c||r.has(`m:${c}`)||(r.add(`m:${c}`),n.push({kind:"memory",id:typeof l.id=="string"?l.id:void 0,label:c,detail:typeof l.content=="string"?l.content:void 0}))}const x=Array.isArray(d.appliedHints)?d.appliedHints:[];for(const g of x){if(!g||typeof g!="object")continue;const l=g,c=typeof l.title=="string"?l.title.trim():"";if(!c||r.has(`h:${c}`))continue;r.add(`h:${c}`);const m=typeof((i=l.lesson)==null?void 0:i.rule)=="string"?l.lesson.rule:typeof l.guidance=="string"?l.guidance:void 0,h=[typeof l.scopeReason=="string"?l.scopeReason:void 0,typeof l.graphReason=="string"?l.graphReason:void 0].filter(Boolean).join("; "),b=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,q=b!==void 0||v!==void 0?`Signals: lexical ${(b??0).toFixed(2)}, graph ${(v??0).toFixed(2)}`:void 0;n.push({kind:"hint",id:typeof l.hintId=="string"?l.hintId:void 0,label:c,detail:[m,h?`Matched: ${h}`:void 0,q].filter(Boolean).join(" · ")||void 0})}}return n.slice(0,6)}function Wr({run:e,t:n}){const[r,i]=f.useState(!1),[s,o]=f.useState(new Set),a=f.useMemo(()=>Bs(e).filter(u=>!u.id||!s.has(u.id)),[e,s]);if(a.length===0)return null;const d=async u=>{try{await ne.deleteAgentMemory(u),o(x=>new Set(x).add(u))}catch{}};return t.jsxs("div",{style:{display:"grid",gap:6,gridTemplateColumns:"minmax(0, 1fr)",minWidth:0},children:[t.jsxs("button",{type:"button",onClick:()=>i(u=>!u),style:$s(n),children:[t.jsx(Ct,{size:11}),t.jsxs("span",{children:["Applied ",a.length," learning",a.length>1?"s":""]}),r?t.jsx(cr,{size:11}):t.jsx(Bt,{size:11})]}),r?t.jsxs("div",{style:Es(n),children:[a.map(u=>t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-start"},children:[t.jsx("span",{style:Ms(n,u.kind),children:u.kind==="hint"?"governed lesson":"memory"}),t.jsxs("div",{style:{minWidth:0,flex:1},children:[t.jsx("div",{style:{fontSize:11.5,fontWeight:650,color:n.textPrimary},children:u.label}),u.detail?t.jsx("div",{style:{fontSize:11,color:n.textMuted,lineHeight:1.4,marginTop:1},children:u.detail}):null]}),u.kind==="memory"&&u.id?t.jsx("button",{type:"button",onClick:()=>void d(u.id),style:Ls(n),children:"Stop using"}):null]},`${u.kind}:${u.label}`)),t.jsx("div",{style:{fontSize:10.5,color:n.textMuted},children:"Advisory only — learnings never override a certified answer. Manage them under Settings → Agent learning."})]}):null]})}function mn(e){const n=[],r=new Set,i=e.trustState==="certified",s=(o,a)=>{typeof o!="string"||!o.trim()||r.has(o)||(r.add(o),n.push({label:o,certified:a}))};for(const o of e.artifacts){const a=se(o);o.ref&&s(o.ref,i);const d=a.plan&&typeof a.plan=="object"?a.plan:void 0;Array.isArray(d==null?void 0:d.sources)&&d.sources.forEach(u=>s(u,i)),s(a.sourceCertifiedBlock,!0)}return n.slice(0,4)}function Te(e){for(const n of e.artifacts){const r=se(n),i=r.researchRun&&typeof r.researchRun=="object"?r.researchRun:void 0,s=r.result&&typeof r.result=="object"&&!Array.isArray(r.result)?r.result:void 0,o=Je(r.dqlArtifact),a=r.proposedSql??r.sql??r.sqlPreview??(s==null?void 0:s.sql)??(i==null?void 0:i.generatedSql)??(i==null?void 0:i.reviewedSql)??(o==null?void 0:o.compiledSql);if(typeof a=="string"&&a.trim())return a}}function Ce(e){for(const n of e.artifacts){const r=se(n),i=Je(r.dqlArtifact);if(i)return i;const s=r.researchRun&&typeof r.researchRun=="object"&&!Array.isArray(r.researchRun)?r.researchRun:void 0,o=Je(s==null?void 0:s.dqlArtifact);if(o)return o}}function _t(e){const n=e.route==="dql_block_draft"&&e.status!=="blocked"&&e.status!=="needs_clarification";if(e.route==="certified_answer"||!ut(e)&&!n)return;const r=Ce(e),i=Te(e);if(!((!(r!=null&&r.source)||r.sourcePath)&&!i)){for(const s of e.artifacts){const o=se(s),a=We(o),d=Ft(o);if(a)return{sql:i,dqlArtifact:r,result:a,chartConfig:He(o,a),title:(r==null?void 0:r.name)??s.title??e.question,mixedSourcePlan:d,sourceRunId:e.id,question:e.question,executionTarget:e.executionTarget};if(d)return{sql:i,dqlArtifact:r,title:(r==null?void 0:r.name)??s.title??e.question,mixedSourcePlan:d,sourceRunId:e.id,question:e.question,executionTarget:e.executionTarget}}return{sql:i,dqlArtifact:r,title:(r==null?void 0:r.name)??e.question,sourceRunId:e.id,question:e.question,executionTarget:e.executionTarget}}}function Ft(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 Fr(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 $s(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 Es(e){return{display:"grid",gap:8,padding:10,borderRadius:8,background:e.cellBg,border:`1px solid ${e.headerBorder}`}}function Ms(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 Ls(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 Ws(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 Zn(e){return{...Ws(e),width:40,height:40}}function It(e){return{...Et(e,{variant:"secondary",size:"md",pill:!0}),fontWeight:550}}function Fs(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 er(e,n){return{...Et(e,{variant:n?"primary":"secondary",size:"lg"}),...n?{}:{color:e.textMuted}}}function tr(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 Ds(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 Ps(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 nr(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 Ns(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 Os(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 Hs(e){return{alignSelf:"flex-start",maxWidth:"92%",color:e.textPrimary,border:`1px solid ${e.cellBorder}`,background:e.appBg,borderRadius:10,padding:"10px 12px"}}function Qs(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 an(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 Vs(e){return{border:`1px solid ${e.headerBorder}`,background:e.cellBg,borderRadius:8,padding:9,fontSize:12.5,color:e.textPrimary,lineHeight:1.45}}function ct(e){return{margin:0,maxHeight:180,overflow:"auto",border:`1px solid ${e.headerBorder}`,background:e.editorBg,color:e.textPrimary,borderRadius:7,padding:9,fontSize:11,lineHeight:1.45,fontFamily:e.fontMono,whiteSpace:"pre-wrap"}}function rr(e){return{width:"100%",minWidth:0,boxSizing:"border-box",background:e.inputBg,border:`1px solid ${e.inputBorder}`,borderRadius:5,color:e.textPrimary,padding:"5px 7px",fontSize:11,fontFamily:e.font}}function Y(e){return Et(e,{variant:"secondary",size:"sm"})}const Tt={warehouse:{title:"The warehouse rejected the query",hint:"The SQL reached your warehouse and it refused. The message below is the driver’s own."},dql_compilation:{title:"DQL could not build a reusable block",hint:"The query itself is fine — only saving this answer as a block is affected."},governance_gate:{title:"DQL stopped this before running it",hint:"A governance check refused the query, so it never reached the warehouse."},retrieval_gap:{title:"DQL could not confirm this data exists",hint:"The relation was not in the inspected metadata. Refreshing the connection scope usually resolves it."},ambiguity:{title:"One detail is missing",hint:"Answer the question above and DQL will continue."},provider:{title:"The AI provider failed",hint:"Nothing was run. Retry, or check the provider in Settings."},host:{title:"DQL hit an internal error",hint:"This is a defect in DQL. The detail below is what to report."},unknown:{title:"The query could not be completed",hint:"Inspect the details or use the bounded repair when it is available."}};function Dr(e){var n,r,i;for(const s of e.artifacts??[]){const o=se(s),a=(n=o==null?void 0:o.warehouseFailure)==null?void 0:n.origin;if(typeof a=="string"&&a in Tt)return a;if(o!=null&&o.providerFailure||(o==null?void 0:o.refusalCode)==="provider_error")return"provider"}return((i=(r=e.diagnosticReceipt)==null?void 0:r.failure)==null?void 0:i.code)==="AI_PROVIDER_FAILURE"?"provider":"unknown"}function Gs(e){var n,r;if(e.status!=="blocked"||!Te(e)&&!((n=Ce(e))!=null&&n.source))return!1;for(const i of e.artifacts??[]){const s=se(i),o=(r=s==null?void 0:s.warehouseFailure)==null?void 0:r.category;if(typeof o=="string"&&["permission","authentication","unsafe","cancelled"].includes(o))return!1}return!0}function Ks({run:e,detail:n,threadId:r,onRepaired:i,t:s}){const o=Dr(e),a=Tt[o]??Tt.unknown,[d,u]=f.useState(!1),[x,g]=f.useState(null),l=Gs(e),c=async()=>{if(!d){u(!0),g(null);try{const m=await ne.repairAgentRunExecution(e.id,r);i(m.run)}catch(m){g(m instanceof Error?m.message:String(m))}finally{u(!1)}}};return t.jsxs("div",{"data-followup":"answer",style:{display:"flex",flexDirection:"column",gap:6,padding:"11px 13px",borderRadius:9,border:`1px solid ${s.error}33`,background:`${s.error}0d`},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7},children:[t.jsx(Xe,{size:13,color:s.error,style:{flexShrink:0}}),t.jsx("span",{style:{fontSize:12.5,fontWeight:700,color:s.textPrimary},children:a.title})]}),t.jsx("div",{style:{fontSize:12.5,lineHeight:1.6,color:s.textSecondary,wordBreak:"break-word"},children:Ie(n)}),t.jsx("div",{style:{fontSize:11.5,lineHeight:1.5,color:s.textMuted},children:a.hint}),l?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap",marginTop:2},children:[t.jsxs("button",{type:"button",className:"dql-hover",disabled:d,onClick:()=>void c(),style:{...Y(s),opacity:d?.7:1},children:[t.jsx(Mt,{size:12})," ",d?"Fixing and retrying…":"Fix and retry"]}),t.jsx("span",{style:{fontSize:10.5,color:s.textMuted},children:"One bounded repair attempt on the same data target."})]}):null,x?t.jsx("div",{role:"alert",style:{fontSize:11.5,lineHeight:1.45,color:s.error},children:Ie(x)}):null]})}function Pr(e){var n,r;for(const i of e.artifacts??[]){const s=se(i),o=s==null?void 0:s.warehouseFailure,a=[o==null?void 0:o.redactedMessage,o==null?void 0:o.diagnostic,s==null?void 0:s.executionError].find(d=>typeof d=="string"&&d.trim().length>0);if(a)return a}return e.summary||((r=(n=e.diagnosticReceipt)==null?void 0:n.failure)==null?void 0:r.message)}const oo=Object.freeze(Object.defineProperty({__proto__:null,ASK_FAILURE_PRESENTATION:Tt,UnifiedAgentRunPanel:os,agentRunHistoryFromItems:yr,analyticalInspectorContract:Rr,analyticalInspectorSections:bs,analyticalRepairActionLabels:vs,appPinDestinationLabel:sn,artifactReadyPayloadFromRun:_t,artifactSqlDisclosureLabel:Lr,askArtifactMeta:Lt,askFailureDetail:Pr,askFailureOrigin:Dr,askInspectorTabsForState:Ar,clarificationSelectionInput:kt,completedRunGuidanceFor:wr,deriveResultChartConfig:si,hasAnalyticalInspectorContract:Wt,inlineAskChartConfig:Mr,isAgentRunPinnable:ut,liveAgentActivityFor:kr,longRunGuidanceFor:Sr,preferredAskInspectorTab:gn,replacePresentedAgentRun:xr,researchSourceFromRun:_r,resolveArtifactDqlView:pt,resolvedParameterValues:on,selectAgentExecutionConnection:vr,threadItemsFromTurns:jr,trustExplainer:xn,usePersistedAgentThreadId:ui},Symbol.toStringTag,{value:"Module"}));export{Ni as B,cr as C,wi as E,Wn as S,os as U,Ti as a,Fi as b,oo 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-Cpx47jCH.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};
|