@duckcodeailabs/dql-cli 1.13.0 → 1.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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-Cp0eh6zU.js → AgentAnswerCard-c8QUo6NH.js} +4 -4
- package/dist/assets/dql-notebook/assets/{AgentLogPage-CBGEoGmU.js → AgentLogPage-D6fgEAEy.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildDialog-CwAD3tXE.js → AiBuildDialog-8miXFPse.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildResult-CyqTuQe5.js → AiBuildResult-DPJ_SI0R.js} +3 -3
- package/dist/assets/dql-notebook/assets/{AiSidePanel-DjB8PWHG.js → AiSidePanel-NVA6lZnn.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AnalyticsHome-B7BkvA-R.js → AnalyticsHome-DgwnRW71.js} +2 -2
- 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-C4SZVNW-.js → BusinessArtifactView-DtRMiaF4.js} +1 -1
- package/dist/assets/dql-notebook/assets/DbtFirstModelingPage-DhBsLCYr.js +22 -0
- package/dist/assets/dql-notebook/assets/{GitPage-BfVD4tVq.js → GitPage-CazC-eTR.js} +1 -1
- 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-BDPNVot1.js → HelpDocsPage-DMHPsVqP.js} +1 -1
- package/dist/assets/dql-notebook/assets/{HomePage-DiOnRhEG.js → HomePage-DcSI4dnU.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDAG-BiUFX2KL.js → LineageDAG-BJ6xz06u.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDetailView-CfbSvlPJ.js → LineageDetailView-8WrQm-MF.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDrawer-CgTScaGB.js → LineageDrawer-hnqCW_t-.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineagePathBreadcrumb-D7ZA7k68.js → LineagePathBreadcrumb-B4LZTUsl.js} +1 -1
- package/dist/assets/dql-notebook/assets/{MiniLineageGraph-GkD4y17x.js → MiniLineageGraph-CotnRuxa.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewBlockModal-B9TfRjt7.js → NewBlockModal-DHn-CEEW.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewNotebookModal-BbO9NKUl.js → NewNotebookModal-BPGp-8oq.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NotebookEditor-CuMpvXR9.js → NotebookEditor-B0OTHM6W.js} +26 -31
- package/dist/assets/dql-notebook/assets/{ReadinessPage-BROJ9YBM.js → ReadinessPage-CoOIpxWq.js} +1 -1
- package/dist/assets/dql-notebook/assets/{SetupOnboarding-BCcZlpuQ.js → SetupOnboarding-DxK_mFzf.js} +1 -1
- package/dist/assets/dql-notebook/assets/{TrustBadge-vQQh8d0D.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-DuqCcDDl.js → answer-to-notebook-WAVAYjBv.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-left-CMe1kkOL.js → arrow-left-L8odLbyN.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-right-DvB_DONr.js → arrow-right-WIF1V9a9.js} +1 -1
- package/dist/assets/dql-notebook/assets/{book-open-text-CJ3NAvrs.js → book-open-text-BpqWMa4m.js} +1 -1
- package/dist/assets/dql-notebook/assets/{bot-CV8DYRrt.js → bot-CLR1V6dO.js} +1 -1
- package/dist/assets/dql-notebook/assets/{circle-x-BCgtha1W.js → circle-x-CQBOM0b0.js} +1 -1
- package/dist/assets/dql-notebook/assets/{dagre.esm-GKp7qoUL.js → dagre.esm-DlZi7NR3.js} +1 -1
- package/dist/assets/dql-notebook/assets/{external-link-C-PXokWV.js → external-link-DYqdQIGp.js} +1 -1
- package/dist/assets/dql-notebook/assets/{grip-vertical-B4EHbGXW.js → grip-vertical-HmUijbwN.js} +1 -1
- package/dist/assets/dql-notebook/assets/{index-1mIC_XX4.js → index-Cpx47jCH.js} +43 -43
- package/dist/assets/dql-notebook/assets/{list-tree-BRFpEmvV.js → list-tree-DGKqCxmz.js} +1 -1
- package/dist/assets/dql-notebook/assets/{minimize-2-CDwSCGlO.js → minimize-2-C8dvqCxX.js} +1 -1
- package/dist/assets/dql-notebook/assets/{panel-right-open-CunA1xO7.js → panel-right-open-yuVkIo5n.js} +1 -1
- package/dist/assets/dql-notebook/assets/{rotate-ccw-DOrfTZk8.js → rotate-ccw-Di0kRnrM.js} +1 -1
- package/dist/assets/dql-notebook/assets/{semantic-fields-AfQvjt5R.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-DDhv4e8M.js → star-CgCQbnXc.js} +1 -1
- package/dist/assets/dql-notebook/assets/{triangle-alert-2ZXx8wAu.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-BA074kiQ.js → user-round-J4PQHxo9.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wand-sparkles-CEYHLt9b.js → wand-sparkles-c4WDXTCk.js} +1 -1
- package/dist/assets/dql-notebook/assets/{workflow-CZtyrcR-.js → workflow-NtRLaq7n.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wrench-Ong23-wu.js → wrench-CS1f1Zv4.js} +1 -1
- package/dist/assets/dql-notebook/assets/{x-CSo1M3tu.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/local-runtime.d.ts +10 -0
- package/dist/local-runtime.d.ts.map +1 -1
- package/dist/local-runtime.js +1061 -17
- package/dist/local-runtime.js.map +1 -1
- package/dist/package.json +10 -10
- package/package.json +10 -10
- package/dist/assets/dql-notebook/assets/AppsView-CUrqtEGC.js +0 -4583
- package/dist/assets/dql-notebook/assets/BlockStudio-Bl0aGQJR.js +0 -60
- package/dist/assets/dql-notebook/assets/DbtFirstModelingPage-B0uxitnx.js +0 -22
- package/dist/assets/dql-notebook/assets/GlobalAiRail-DUwdy3fB.js +0 -1
- package/dist/assets/dql-notebook/assets/GovernedContextPage-D9f26ZFb.js +0 -7
- package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-Dj4AXAhT.js +0 -83
- package/dist/assets/dql-notebook/assets/chevron-up-HxU1l85K.js +0 -6
- package/dist/assets/dql-notebook/assets/link-2-BLx-goet.js +0 -6
- package/dist/assets/dql-notebook/assets/maximize-2-CCd5uRIZ.js +0 -6
- package/dist/assets/dql-notebook/assets/pencil-D_I14Wyk.js +0 -6
- package/dist/assets/dql-notebook/assets/usePersistedAgentThreadId-3rzkZrqc.js +0 -18
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import{c as cn,r as c,j as e,a5 as co,h as Dt,i as uo,k as po,a6 as fo,t as zt,a7 as Zt,a as O,a8 as rt,a9 as ho,e as rn,D as sn,T as Nt,P as mo,S as ln,f as Mt,l as go,aa as xo,ab as yo,ac as ae,ad as wt,ae as Ct,af as fi,ag as hi,b as bo,ah as vo,B as Ot,A as mi,L as lt,ai as gi,aj as xi,ak as So,al as ni,am as $e,z as jo,an as yi,Q as bi,ao as ko,ap as wo,w as Co,E as Jt,x as Bo,y as To,H as ii}from"./index-1mIC_XX4.js";import{S as Mo,a as Io,b as oi}from"./LineagePathBreadcrumb-D7ZA7k68.js";import{u as Do,a as zo,T as vi,b as Po,d as Ro,C as Si}from"./usePersistedAgentThreadId-3rzkZrqc.js";import{M as Lo}from"./MiniLineageGraph-GkD4y17x.js";import{b as ji,U as $o,E as Eo,B as Ao}from"./UnifiedAgentRunPanel-Dj4AXAhT.js";import{a as _o,A as Wo}from"./AiSidePanel-DjB8PWHG.js";import{T as Ht}from"./triangle-alert-2ZXx8wAu.js";import{P as Fo}from"./panel-right-open-CunA1xO7.js";import{X as Oo}from"./x-CSo1M3tu.js";import{B as qo}from"./bot-CV8DYRrt.js";import{P as No}from"./pencil-D_I14Wyk.js";import"./react-CRB3T2We.js";import"./codemirror-DXt7RW72.js";import"./wrench-Ong23-wu.js";import"./dagre.esm-GKp7qoUL.js";import"./AgentAnswerCard-Cp0eh6zU.js";import"./TrustBadge-vQQh8d0D.js";import"./AiBuildResult-CyqTuQe5.js";import"./user-round-BA074kiQ.js";import"./rotate-ccw-DOrfTZk8.js";import"./list-tree-BRFpEmvV.js";import"./minimize-2-CDwSCGlO.js";import"./maximize-2-CCd5uRIZ.js";import"./arrow-right-DvB_DONr.js";import"./chevron-up-HxU1l85K.js";/**
|
|
2
|
-
* @license lucide-react v0.563.0 - ISC
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the ISC license.
|
|
5
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const Ho=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],Qo=cn("chevron-left",Ho);/**
|
|
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 Uo=[["path",{d:"M4 11V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-1",key:"1q9hii"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M2 15h10",key:"jfw4w8"}],["path",{d:"m9 18 3-3-3-3",key:"112psh"}]],ki=cn("file-input",Uo);/**
|
|
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 Ko=[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]],wi=cn("play",Ko);function Bt({value:t,onChange:n,multiline:r,placeholder:s,style:i,ariaLabel:d,rows:p}){const[m,x]=c.useState(t),P=c.useRef(!1);c.useEffect(()=>{P.current||x(t)},[t]);const l={value:m,placeholder:s,style:i,"aria-label":d,onFocus:()=>{P.current=!0},onBlur:()=>{P.current=!1,x(t)},onChange:f=>{x(f.target.value),n(f.target.value)}};return r?e.jsx("textarea",{...l,rows:p}):e.jsx("input",{type:"text",...l})}function Go(t,n){return co(t,n)}const Vo={native:"Native (DQL)","metricflow-cli":"Local MetricFlow","dbt-cloud":"dbt Cloud"};function Yo(t){switch(t){case"no_join_path":return"No join path from this metric’s model to this dimension.";case"not_shared_across_metrics":return"Not reachable from every selected metric.";case"metric_unresolved":return"The selected metric could not be resolved.";default:return"Not compatible with the selected metrics."}}const ri=["day","week","month","quarter","year"];function Xo(t,n,r){var d,p;if(!t)return ri;const s=(d=n.get(t))==null?void 0:d.granularities;if(s&&s.length>0)return s;const i=(p=r.find(m=>(m.reference??m.name)===t||m.name===t))==null?void 0:p.granularities;return i&&i.length>0?i:ri}function ys(){var Mn,In,Dn,zn,Pn,Rn,Ln,$n,En,An,_n,Wn,Fn,On,qn,Nn,Hn,Qn,Un,Kn,Gn,Vn,Yn,Xn,Zn,Jn;const t=Dt(uo(o=>({activeBlockPath:o.activeBlockPath,authoredDomains:o.authoredDomains,blockStudioDbtStatus:o.blockStudioDbtStatus,blockStudioDirty:o.blockStudioDirty,blockStudioDraft:o.blockStudioDraft,blockStudioImportOpen:o.blockStudioImportOpen,blockStudioMetadata:o.blockStudioMetadata,blockStudioPreview:o.blockStudioPreview,blockStudioValidation:o.blockStudioValidation,files:o.files,schemaTables:o.schemaTables,semanticLayer:o.semanticLayer,themeMode:o.themeMode}))),n=po(),{operations:r,track:s}=fo(),i=zt[t.themeMode],[d,p]=c.useState(()=>Ar()),m=t.activeBlockPath?`block-studio.block.${encodeURIComponent(t.activeBlockPath)}`:`block-studio.draft.${d}`,x=Do(m),[P,l]=c.useState("blocks"),[f,h]=c.useState("results"),[T,R]=c.useState(()=>_r()),[E,ee]=c.useState([]),[_,k]=c.useState({}),[S,oe]=c.useState(""),[Z,pe]=c.useState(new Set),A=c.useMemo(()=>{const o=t.schemaTables.map(b=>[b.name,b.columns.map(C=>C.name)]),u=Hr(E).map(b=>[b.path,b.columns]),v=new Map;for(const[b,C]of[...u,...o])b&&v.set(b,C);return v.size>0?Object.fromEntries(v):void 0},[t.schemaTables,E]),[U,Y]=c.useState(!1),[M,K]=c.useState(null),[W,X]=c.useState(null),[fe,te]=c.useState(0),[N,ce]=c.useState({}),[I,H]=c.useState(!1),[he,ke]=c.useState(null),we=c.useRef(!1),ye=c.useRef(null),[Ee,G]=c.useState(null),[Ne,Be]=c.useState(!1),[se,Ie]=c.useState(null),[a,L]=c.useState(!1),[J,de]=c.useState(null),[Te,De]=c.useState(0),[le,re]=c.useState(!1),[Ae,_e]=c.useState(!1),Ce=c.useRef(null),We=c.useRef(!1),[dt,He]=c.useState(null),[nt,Ve]=c.useState([]),[Ye,Me]=c.useState(!1),[it,Xe]=c.useState(!1),[Ze,Je]=c.useState(null),[ot,g]=c.useState(null),[B,D]=c.useState(null),[w,q]=c.useState(340),[ne,y]=c.useState(320),[j,z]=c.useState(!1),[F,Se]=c.useState(!1),[Q,Pt]=c.useState(()=>typeof window<"u"?window.innerWidth<900:!1),[ct,ze]=c.useState(()=>t.blockStudioImportOpen?"import":"start"),[ut,ge]=c.useState("visual"),[Qe,Qt]=c.useState(()=>Wr("dql.block-studio.ai.open",!1)),[Rt,Di]=c.useState(()=>Fr("dql.block-studio.ai.width",420,360,520)),[pn,fn]=c.useState(!1),[zi,Pi]=c.useState(!1),[Ri,Li]=c.useState(0),[Pe,Lt]=c.useState(null),[$i,hn]=c.useState([]),[Ei,mn]=c.useState(!1),[pt,Ut]=c.useState(null),[gn,Kt]=c.useState(null),[xn,Ai]=c.useState("ask"),[_i,Wi]=c.useState(""),[Fi,Oi]=c.useState(void 0),[qi,Ni]=c.useState(!1),[yn,$t]=c.useState(null),bn=c.useRef(t.activeBlockPath),Re=Zt({queryKey:["block-studio","catalog","summary"],queryFn:()=>O.getBlockStudioCatalog({includeSemantic:!1}),staleTime:3e4}),ft=Zt({queryKey:["block-studio","dbt-status"],queryFn:()=>O.getBlockStudioDbtStatus(),staleTime:3e4}),ht=Zt({queryKey:["semantic-layer"],queryFn:()=>O.getSemanticLayer(),staleTime:3e4});c.useEffect(()=>{const o=()=>De(u=>u+1);return window.addEventListener("dql:block-library-invalidated",o),()=>window.removeEventListener("dql:block-library-invalidated",o)},[]),c.useEffect(()=>{var u,v,b;if(!he)return;const o=r.find(C=>C.id===he);if(!(!o||o.status==="queued"||o.status==="running")){if(o.status==="succeeded"){const C=o.result;$t({pending:!1,ok:(C==null?void 0:C.outcome)==="certified",checklist:C==null?void 0:C.checklist,blockers:(C==null?void 0:C.blockers)??((u=C==null?void 0:C.checklist)==null?void 0:u.blockers),error:(C==null?void 0:C.outcome)==="draft_saved_with_blockers"?"The draft was saved. Resolve the certification blockers and try again.":void 0}),(C==null?void 0:C.outcome)==="draft_saved_with_blockers"&&G("Draft saved. Certification needs attention; review the checklist below.")}else G(((v=o.error)==null?void 0:v.message)??"Certification did not complete. The draft remains saved."),$t({pending:!1,error:((b=o.error)==null?void 0:b.message)??o.message});ke(null),h("save")}},[he,r]),c.useEffect(()=>{n({type:"SET_BLOCK_STUDIO_CATALOG_LOADING",loading:Re.isLoading}),Re.data?(n({type:"SET_BLOCK_STUDIO_CATALOG",catalog:Re.data}),ee(Re.data.databaseTree),He(null)):Re.isError&&He("Failed to load schema. Check your connection and try refreshing.")},[Re.data,Re.isError,Re.isLoading,n]),c.useEffect(()=>{ft.data?n({type:"SET_BLOCK_STUDIO_DBT_STATUS",status:ft.data}):ft.isError&&n({type:"SET_BLOCK_STUDIO_DBT_STATUS",status:null})},[ft.data,ft.isError,n]),c.useEffect(()=>{n({type:"SET_SEMANTIC_LOADING",loading:ht.isLoading}),ht.data&&n({type:"SET_SEMANTIC_LAYER",layer:ht.data})},[n,ht.data,ht.isLoading]);const Et=c.useCallback(async()=>{mn(!0);try{const o=await O.listBlockStudioImports();hn(o.sessions??[])}catch{hn([])}finally{mn(!1)}},[]);c.useEffect(()=>{Et()},[Et]),c.useEffect(()=>{const o=bn.current,u=t.activeBlockPath;u&&u!==o&&n({type:"CLOSE_BLOCK_IMPORT"}),bn.current=u},[t.activeBlockPath,n]),c.useEffect(()=>{const o=new AbortController,u=window.setTimeout(()=>{t.blockStudioDraft.trim()&&O.validateBlockStudio(t.blockStudioDraft,t.activeBlockPath,o.signal).then(v=>{o.signal.aborted||n({type:"SET_BLOCK_STUDIO_VALIDATION",validation:v})}).catch(()=>{})},250);return()=>{window.clearTimeout(u),o.abort()}},[t.blockStudioDraft,t.activeBlockPath,n]),c.useMemo(()=>qr(E,S),[E,S]);const At=c.useMemo(()=>Nr(E),[E]),vn={metrics:t.semanticLayer.metrics.length,measures:t.semanticLayer.measures.length,dimensions:t.semanticLayer.dimensions.length,timeDimensions:t.semanticLayer.timeDimensions.length,entities:t.semanticLayer.entities.length,hierarchies:t.semanticLayer.hierarchies.length,semanticModels:t.semanticLayer.semanticModels.length,savedQueries:t.semanticLayer.savedQueries.length},Sn=Qr(vn);c.useEffect(()=>{const o=()=>Pt(window.innerWidth<900);return o(),window.addEventListener("resize",o),()=>window.removeEventListener("resize",o)},[]),c.useEffect(()=>{try{window.localStorage.setItem("dql.block-studio.ai.open",Qe?"1":"0")}catch{}},[Qe]),c.useEffect(()=>{try{window.localStorage.setItem("dql.block-studio.ai.width",String(Rt))}catch{}},[Rt]),c.useEffect(()=>{if(T)try{window.localStorage.setItem("dql.block-studio.domain",T)}catch{}},[T]),c.useEffect(()=>{var u,v;const o=(v=(u=t.blockStudioMetadata)==null?void 0:u.domain)==null?void 0:v.trim();o&&o!=="uncategorized"&&R(o)},[t.activeBlockPath,(Mn=t.blockStudioMetadata)==null?void 0:Mn.domain]),c.useEffect(()=>{t.blockStudioImportOpen&&(ze("import"),n({type:"CLOSE_BLOCK_IMPORT"}))},[n,t.blockStudioImportOpen]),c.useEffect(()=>{var o;ze(Or(t)?"manual":"start"),ge(((o=rt(t.blockStudioDraft))==null?void 0:o.blockType)==="semantic"?"visual":"source")},[t.activeBlockPath]);const et=c.useMemo(()=>{var u;const o=rt(t.blockStudioDraft);return t.blockStudioMetadata?{...o,name:(o==null?void 0:o.name)||t.blockStudioMetadata.name,domain:(o==null?void 0:o.domain)||t.blockStudioMetadata.domain,description:(o==null?void 0:o.description)||t.blockStudioMetadata.description,owner:(o==null?void 0:o.owner)||t.blockStudioMetadata.owner,tags:(u=o==null?void 0:o.tags)!=null&&u.length?o.tags:t.blockStudioMetadata.tags,blockType:(o==null?void 0:o.blockType)||"custom",status:(o==null?void 0:o.status)||t.blockStudioMetadata.reviewStatus||"draft"}:o},[t.blockStudioDraft,t.blockStudioMetadata]),me=(et==null?void 0:et.name)??((In=t.blockStudioMetadata)==null?void 0:In.name)??null,Ue=((et==null?void 0:et.blockType)??"custom")==="semantic",Fe=!!(t.blockStudioDraft.trim()||t.blockStudioMetadata||t.activeBlockPath);c.useEffect(()=>{var o;if(t.activeBlockPath){if(ye.current==="builder"){ye.current=null,ge(((o=rt(t.blockStudioDraft))==null?void 0:o.blockType)==="semantic"?"visual":"source");return}t.activeBlockPath&&ge("detail")}},[t.activeBlockPath]);const Gt=c.useCallback(async o=>{const u=`block:${o}`;n({type:"SET_LINEAGE_FOCUS",nodeId:u}),Xe(!0);try{const[v,b,C]=await Promise.all([O.fetchLineageNode(u),O.queryLineage({focus:u,upstreamDepth:3,downstreamDepth:2}),O.fetchLineagePaths(u,{maxDepth:6,maxPaths:6})]);Je(v),g(b.graph??null),D(C)}catch{Je(null),g(null),D(null)}finally{Xe(!1)}},[n]);c.useEffect(()=>{me&&Gt(me)},[me,Gt]);const Le=o=>{K(null),n({type:"SET_BLOCK_STUDIO_DRAFT",draft:o});const u=rt(o),v=t.blockStudioMetadata;if(!u||!v)return;const b={...v,name:u.name||v.name,domain:u.domain||v.domain,description:u.description,owner:u.owner,tags:u.tags,reviewStatus:u.status||v.reviewStatus};(b.name!==v.name||b.domain!==v.domain||b.description!==v.description||b.owner!==v.owner||b.reviewStatus!==v.reviewStatus||b.tags.join("\0")!==v.tags.join("\0"))&&n({type:"SET_BLOCK_STUDIO_METADATA",metadata:b})},Hi=o=>{if(o==="semantic"===Ue)return;const u=t.blockStudioMetadata,v=(u==null?void 0:u.name)||(o==="semantic"?"new_semantic_block":"new_sql_block");let b=o==="semantic"?on(v):Ft(v);b=wt(b,v),o==="custom"&&(b=gi(b,"")),u&&(b=ae(b,"domain",u.domain||"uncategorized"),b=ae(b,"description",u.description??""),b=ae(b,"owner",u.owner??""),b=Ct(b,u.tags??[])),Le(b),ge("visual")},Qi=(o,u)=>{const v=t.blockStudioMetadata;let b=Ue?t.blockStudioDraft:on((v==null?void 0:v.name)||"new_semantic_block");!Ue&&v&&(b=ae(b,"domain",v.domain||"uncategorized"),b=ae(b,"description",v.description??""),b=ae(b,"owner",v.owner??""),b=Ct(b,v.tags??[])),b=fi(b,o),b=hi(b,"dimensions",u),Le(b),Ut(null),Kt(null),ze("manual"),ge("visual")},_t=()=>{n({type:"START_NEW_BLOCK_WORKSPACE"}),p(dn()),Lt(null),ze("start"),ge("visual")},jn=()=>{if(t.blockStudioDirty){_e(!0);return}_t()},kn=()=>{jn()},wn=o=>{const u=o==="semantic"?"new_semantic_block":"new_sql_block",v=T||"uncategorized",b=o==="semantic"?on(u):Ft(u),C=ae(b,"domain",v);n({type:"SET_BLOCK_STUDIO_DRAFT",draft:C}),n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{name:u,path:null,domain:v,folderPath:"",description:"",owner:"",tags:[],reviewStatus:"draft",sourceKind:"manual"}}),n({type:"SET_BLOCK_STUDIO_PREVIEW",preview:null}),n({type:"SET_BLOCK_STUDIO_VALIDATION",validation:null}),ze("manual"),ge("visual")},Wt=async()=>{Y(!0),K(null),X(Date.now()),te(0),n({type:"SET_BLOCK_STUDIO_PREVIEW",preview:null});try{const o=await O.runBlockStudio(t.blockStudioDraft,t.activeBlockPath,N);n({type:"SET_BLOCK_STUDIO_PREVIEW",preview:o}),h("results")}catch(o){const u=o instanceof Error?o.message:String(o);K(u),h(/required parameter|provide required parameter/i.test(u)?"parameters":"results")}finally{Y(!1),X(null)}},Ui=async(o=t.blockStudioDraft)=>{var b,C;if(!t.blockStudioMetadata)throw new Error("Block metadata is required before saving.");const u=await O.saveBlockStudio({path:t.activeBlockPath,source:o,metadata:{name:t.blockStudioMetadata.name,domain:t.blockStudioMetadata.domain,folderPath:t.blockStudioMetadata.folderPath,description:t.blockStudioMetadata.description,owner:t.blockStudioMetadata.owner,tags:t.blockStudioMetadata.tags,sourceKind:t.blockStudioMetadata.sourceKind,sourcePath:t.blockStudioMetadata.sourcePath,importId:t.blockStudioMetadata.importId,candidateId:t.blockStudioMetadata.candidateId,lineage:t.blockStudioMetadata.lineage}});return De(V=>V+1),n({type:"OPEN_BLOCK_STUDIO",file:{name:`${u.metadata.name}.dql`,path:u.path,type:"block",folder:"blocks"},payload:u}),t.files.some(V=>V.path===u.path)||n({type:"FILE_ADDED",file:{name:`${u.metadata.name}.dql`,path:u.path,type:"block",folder:"blocks"}}),((b=u.lineageRefresh)==null?void 0:b.status)==="ready"?Gt(u.metadata.name):((C=u.lineageRefresh)==null?void 0:C.status)==="failed"&&(G(`Block saved, but lineage refresh failed: ${u.lineageRefresh.message??"compile failed"}`),setTimeout(()=>G(null),7e3)),u},Vt=async()=>{var o;if(!((o=t.blockStudioMetadata)!=null&&o.name.trim())||!t.blockStudioMetadata.owner.trim())return Ce.current="save",re(!0),!1;H(!0),G(null);try{const u=t.blockStudioMetadata.reviewStatus==="certified"&&t.blockStudioDirty?ae(t.blockStudioDraft,"status","draft"):t.blockStudioDraft;return await Ui(u),h("save"),!0}catch(u){const v=(u==null?void 0:u.message)??"Save failed";return G(v.includes("409")||v.includes("BLOCK_EXISTS")?"A block with this name already exists. Rename and try again.":v),setTimeout(()=>G(null),5e3),!1}finally{H(!1)}},Yt=(o,u)=>{de(null),Ie({path:o,name:u}),Be(!0)},Ki=async()=>{var u;const o=se==null?void 0:se.path;if(o){L(!0),de(null);try{const v=await O.deleteBlockStudio(o);n({type:"FILE_REMOVED",path:v.path}),t.activeBlockPath===v.path&&(n({type:"START_NEW_BLOCK_WORKSPACE"}),p(dn()),Lt(null),ze("start"),ge("visual")),Be(!1),Ie(null),De(b=>b+1),((u=v.lineageRefresh)==null?void 0:u.status)==="failed"&&He(`Block deleted, but lineage refresh failed: ${v.lineageRefresh.message??"compile failed"}`)}catch(v){de(v instanceof Error?v.message:String(v))}finally{L(!1)}}},Cn=async()=>{var o;if(!((o=t.blockStudioMetadata)!=null&&o.name.trim())||!t.blockStudioMetadata.owner.trim())return Ce.current="certify",re(!0),!1;if(we.current||he)return!1;we.current=!0,H(!0),G(null);try{$t(null);const u=t.blockStudioMetadata.reviewStatus==="certified"&&t.blockStudioDirty?ae(t.blockStudioDraft,"status","draft"):t.blockStudioDraft,v=`${t.blockStudioMetadata.sourceFingerprint??"new"}:${Date.now()}`,b=typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():`block-certification-${v}`,C=await O.requestBlockStudioCertification({source:u,path:t.activeBlockPath,metadata:t.blockStudioMetadata,expectedSourceFingerprint:t.blockStudioMetadata.sourceFingerprint,clientRevision:v,idempotencyKey:b});return s(C.operation),ke(C.operation.id),n({type:"BLOCK_CERTIFICATION_ACCEPTED",source:u}),$t({pending:!0}),h("save"),!0}catch(u){const v=(u==null?void 0:u.message)??"Save failed";return G(v.includes("409")||v.includes("BLOCK_EXISTS")?"A block with this name already exists. Rename and try again.":v),setTimeout(()=>G(null),5e3),!1}finally{we.current=!1,H(!1)}};c.useEffect(()=>{var v;const o=Ce.current;if(!o||!((v=t.blockStudioMetadata)!=null&&v.name.trim())||!t.blockStudioMetadata.owner.trim())return;Ce.current=null,(o==="certify"?Cn():Vt()).then(b=>{b&&We.current&&(We.current=!1,_t())})},[(Dn=t.blockStudioMetadata)==null?void 0:Dn.name,(zn=t.blockStudioMetadata)==null?void 0:zn.owner,t.blockStudioDraft]);const Gi=o=>{var b;const u=o.savedPath??((b=o.draftSave)==null?void 0:b.path)??"",v={path:u,source:o.dqlSource,metadata:{name:o.name,path:u||null,domain:o.domain,description:o.description,owner:o.owner,tags:o.tags,reviewStatus:o.reviewStatus,sourceKind:o.sourceKind,sourcePath:o.sourcePath,importId:Pe==null?void 0:Pe.id,candidateId:o.id,lineage:o.lineage.sourceTables},companionPath:null,validation:o.validation??{valid:!0,diagnostics:[],semanticRefs:{metrics:[],dimensions:[],segments:[]},executableSql:null}};n({type:"OPEN_BLOCK_STUDIO",file:{name:`${o.name}.dql`,path:u,type:"block",folder:"blocks",isNew:!u},payload:v}),n({type:"SET_BLOCK_STUDIO_PREVIEW",preview:o.preview}),h("results"),ze("manual"),ge("visual")},Vi=(o,u)=>{t.files.some(b=>b.path===u.path)||n({type:"FILE_ADDED",file:{name:`${u.metadata.name}.dql`,path:u.path,type:"block",folder:"blocks"}}),Lt(b=>b&&{...b,candidates:b.candidates.map(C=>C.id===o.id?o:C)}),Et()},Yi=(o,u)=>{var V,Oe,gt,xt,yt,bt,vt;const v=t.blockStudioDraft.trim()?t.blockStudioDraft:Ft(((V=u==null?void 0:u.title)==null?void 0:V.trim())||"AI Generated Block"),b=(Oe=u==null?void 0:u.blockSource)!=null&&Oe.trim()?u.blockSource.trim():ui(v,o);Le(b);const C=rt(b);C&&n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{name:C.name||(u==null?void 0:u.title)||"AI Generated Block",path:t.activeBlockPath,domain:C.domain||(u==null?void 0:u.domain)||"analytics",description:C.description||(u==null?void 0:u.description)||`AI generated block for ${(u==null?void 0:u.question)??"analysis"}`,owner:C.owner||(u==null?void 0:u.owner)||"",tags:C.tags.length>0?C.tags:(u==null?void 0:u.tags)??["ai-generated","review-required"],reviewStatus:C.status||"draft",sourceKind:((gt=t.blockStudioMetadata)==null?void 0:gt.sourceKind)??"ai-generated",sourcePath:(xt=t.blockStudioMetadata)==null?void 0:xt.sourcePath,importId:(yt=t.blockStudioMetadata)==null?void 0:yt.importId,candidateId:(bt=t.blockStudioMetadata)==null?void 0:bt.candidateId,lineage:(vt=t.blockStudioMetadata)==null?void 0:vt.lineage}}),n({type:"SET_BLOCK_STUDIO_VALIDATION",validation:{valid:!0,diagnostics:[{severity:"info",code:"ai_sql_draft_inserted",message:C?"AI generated a draft block with metadata, SQL, visualization, and tests. Run preview, review joins and grain, then save.":"AI generated SQL inserted. Run preview, review joins and grain, then save or certify."}],semanticRefs:{metrics:[],dimensions:[],segments:[]},executableSql:o.trim()}}),h("results")},Xi=async o=>{var gt,xt,yt,bt,vt,ei,ti;const u=(xt=(gt=o.dqlArtifact)==null?void 0:gt.source)==null?void 0:xt.trim(),v=(o.sql??"").trim();if(!u&&!v)return;let b;if((yt=o.question)!=null&&yt.trim())try{const be=await O.composeSemanticBlock(o.question.trim());be.ok&&be.source.trim()&&(b=be.source.trim())}catch{}const C=b||u||ui(Ft(((bt=o.title)==null?void 0:bt.trim())||"AI Generated Block"),v),V=rt(C),Oe=(V==null?void 0:V.name)||((vt=o.dqlArtifact)==null?void 0:vt.name)||o.title||"AI Generated Block";H(!0),G(null);try{const be=await O.saveAgentBlockDraft({source:C,name:Oe,domain:(V==null?void 0:V.domain)||((ei=t.blockStudioMetadata)==null?void 0:ei.domain)||"uncategorized",description:(V==null?void 0:V.description)||`AI-generated draft for ${o.title??Oe}`,tags:(ti=V==null?void 0:V.tags)!=null&&ti.length?V.tags:["ai-generated","review-required"],runId:o.sourceRunId});ye.current="builder",n({type:"OPEN_BLOCK_STUDIO",file:{name:`${be.metadata.name}.dql`,path:be.path,type:"block",folder:"blocks",isNew:!1},payload:be}),t.files.some(Xt=>Xt.path===be.path)||n({type:"FILE_ADDED",file:{name:`${be.metadata.name}.dql`,path:be.path,type:"block",folder:"blocks"}}),De(Xt=>Xt+1),ze("manual"),ge("visual"),h("save")}catch(be){G(be instanceof Error?be.message:String(be))}finally{H(!1)}},mt=o=>{const u=(o==null?void 0:o.kind)??"ask";h("results"),Ai(u),Wi((o==null?void 0:o.initialInput)??""),Oi(o!=null&&o.autoRun?{text:o.autoRun,mode:"block",nonce:Date.now()}:void 0),Qt(!0)};c.useCallback(async()=>{try{const o=(await Re.refetch()).data;o!=null&&o.databaseTree&&ee(o.databaseTree),o&&n({type:"SET_BLOCK_STUDIO_CATALOG",catalog:o})}catch{}},[Re,n]),c.useEffect(()=>{if(!U||!W)return;const o=()=>te(Date.now()-W);o();const u=window.setInterval(o,1e3);return()=>window.clearInterval(u)},[U,W]);const Bn=((Pn=t.blockStudioValidation)==null?void 0:Pn.chartConfig)??((Rn=t.blockStudioPreview)==null?void 0:Rn.chartConfig)??{chart:"table"},Zi=t.blockStudioPreview?zo(t.blockStudioPreview.result,t.blockStudioPreview.chartConfig):"table",Ji=o=>{o.preventDefault();const u=o.clientX,v=w,b=V=>{const Oe=Math.min(560,Math.max(300,v+V.clientX-u));q(Oe)},C=()=>{window.removeEventListener("mousemove",b),window.removeEventListener("mouseup",C)};window.addEventListener("mousemove",b),window.addEventListener("mouseup",C)},eo=o=>{o.preventDefault();const u=o.clientY,v=ne,b=V=>{const Oe=Math.min(500,Math.max(180,v-(V.clientY-u)));y(Oe)},C=()=>{window.removeEventListener("mousemove",b),window.removeEventListener("mouseup",C)};window.addEventListener("mousemove",b),window.addEventListener("mouseup",C)},to=o=>{o.preventDefault();const u=o.clientX,v=Rt,b=V=>{Di(Math.min(520,Math.max(360,v-(V.clientX-u))))},C=()=>{window.removeEventListener("mousemove",b),window.removeEventListener("mouseup",C)};window.addEventListener("mousemove",b),window.addEventListener("mouseup",C)},tt=Fe&&!F,no=Q?"minmax(0, 1fr)":`${j?0:w}px ${j?0:6}px minmax(0, 1fr) ${Qe?6:0}px ${Qe?pn?`min(${_o}px, 52vw)`:`${Rt}px`:0}`,io=Q?j?tt?`minmax(0, 1fr) 6px ${ne}px`:"minmax(0, 1fr) 0 0":tt?`minmax(220px, 34vh) minmax(320px, 1fr) 6px ${ne}px`:"minmax(220px, 34vh) minmax(0, 1fr) 0 0":tt?`minmax(0, 1fr) 6px ${ne}px`:"minmax(0, 1fr) 0 0",oo=Q?"1":"3",Tn=Q?j?"1":"2":"1",ro=Q?"1":"3",so=Q?j?"2":"3":"2",lo=Q?"1":"3",ao=Q?j?"3":"4":"3";return e.jsxs("div",{style:{flex:1,position:"relative",display:"grid",gridTemplateColumns:no,gridTemplateRows:io,overflow:"hidden",background:i.appBg},children:[e.jsx("div",{style:{gridColumn:"1",gridRow:Q?"1":"1 / 4",borderRight:j?"none":`1px solid ${i.headerBorder}`,borderBottom:Q&&!j?`1px solid ${i.headerBorder}`:"none",display:j?"none":"flex",flexDirection:"column",overflow:"hidden",background:i.sidebarBg,minWidth:0},children:e.jsx("div",{style:{flex:1,minHeight:0,overflow:"hidden"},children:e.jsx(ho,{tabs:["blocks","semantic","database"],defaultTab:P,blockDomain:T,onBlockDomainChange:R,onInsertText:o=>{if(Ue){Kt("That snippet is SQL. Use a SQL Block for raw SELECT work, or keep this Semantic Block on metrics and dimensions.");return}Le(Er(t.blockStudioDraft,o))},onSemanticCompose:Qi,onNewBlock:kn,onDeleteBlock:o=>Yt(o.path,o.name),blockLibraryRefreshKey:Te,onCollapse:()=>z(!0),footer:t.semanticLayer.loading?`Loading ${(((Ln=t.blockStudioDbtStatus)==null?void 0:Ln.counts.metrics)??0).toLocaleString()} semantic metrics…`:`${t.semanticLayer.provider?`${t.semanticLayer.provider} synced`:"dbt synced"} · ${At.tables} table${At.tables===1?"":"s"} · ${t.semanticLayer.metrics.length.toLocaleString()} metric${t.semanticLayer.metrics.length===1?"":"s"}`,footerStatus:t.semanticLayer.loading?"loading":"ready"})})}),e.jsx("div",{onMouseDown:j?void 0:Ji,style:{gridColumn:"2",gridRow:"1 / 4",display:j||Q?"none":"block",cursor:"col-resize",background:i.headerBorder}}),e.jsxs("div",{style:{display:Q&&Qe?"none":"flex",flexDirection:"column",minWidth:0,overflow:"hidden",gridColumn:oo,gridRow:Tn},children:[e.jsx("style",{children:`
|
|
17
|
-
@keyframes dql-agent-fadein { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
|
|
18
|
-
@keyframes dql-agent-run-spin { to { transform: rotate(360deg); } }
|
|
19
|
-
`}),e.jsxs("div",{style:{height:46,flexShrink:0,display:"flex",alignItems:"center",gap:10,padding:"0 16px",borderBottom:`1px solid ${i.headerBorder}`,background:i.cellBg,overflowX:"auto"},children:[j&&e.jsx("button",{onClick:()=>z(!1),style:{background:"transparent",border:"none",color:i.textMuted,cursor:"pointer",fontSize:14,fontFamily:i.font,padding:0,lineHeight:1},title:"Open explorer",children:"›"}),e.jsxs("button",{type:"button",onClick:jn,title:"Back to Block Studio",className:"dql-hover",style:{display:"inline-flex",alignItems:"center",gap:4,background:"transparent",border:"none",padding:"2px 4px",margin:"0 -4px",borderRadius:6,color:i.textMuted,fontSize:12,fontFamily:i.font,whiteSpace:"nowrap",cursor:"pointer"},children:[e.jsx(Qo,{size:12,strokeWidth:2})," Blocks"]}),e.jsx(rn,{size:11,color:i.textMuted,style:{flexShrink:0}}),e.jsx("span",{style:{fontSize:12.5,fontWeight:600,color:i.textPrimary,fontFamily:i.fontMono,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:220},children:me||(($n=t.blockStudioMetadata)==null?void 0:$n.name)||(Fe?"new_block":Ue?"semantic":"sql")}),((En=t.blockStudioMetadata)==null?void 0:En.reviewStatus)&&e.jsx(ji,{status:t.blockStudioMetadata.reviewStatus,t:i}),Fe&&ct==="manual"&&ut!=="detail"&&e.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:2,padding:2,border:`1px solid ${i.headerBorder}`,borderRadius:7,background:i.appBg,marginLeft:6,flexShrink:0},children:[e.jsx("button",{type:"button",onClick:()=>ge("visual"),style:si(i,ut==="visual"),children:"Visual Builder"}),e.jsx("button",{type:"button",onClick:()=>ge("source"),style:si(i,ut==="source"),children:"DQL Source"})]}),Fe&&e.jsx(Ke,{label:`Context${pi(t.blockStudioDraft)?` (${pi(t.blockStudioDraft)})`:""}`,Icon:sn,onClick:()=>Ni(o=>!o)}),e.jsx("div",{style:{flex:1}}),t.activeBlockPath&&e.jsx(Ke,{label:"Delete",Icon:Nt,variant:"danger",title:"Delete this saved block",onClick:()=>{var o;return Yt(t.activeBlockPath,((o=t.blockStudioMetadata)==null?void 0:o.name)||me||t.activeBlockPath)}}),e.jsx(Ke,{label:"New block",Icon:mo,onClick:kn}),Fe&&e.jsxs(e.Fragment,{children:[e.jsx(Ke,{label:"Ask AI",Icon:ln,onClick:()=>mt({kind:"ask"})}),t.activeBlockPath&&e.jsx(Ke,{label:"Modify with AI",Icon:ln,onClick:()=>mt({kind:"edit",initialInput:`Modify this block${me?` (${me})`:""}: `})}),e.jsx(Ke,{label:"Run",Icon:wi,onClick:()=>void Wt(),busy:U}),e.jsx(Ke,{label:I?"Saving":"Save draft",Icon:Mt,variant:"secondary",busy:I,onClick:()=>void Vt(),title:"Save changes as a review-required draft"}),e.jsx(Ke,{label:((An=t.blockStudioMetadata)==null?void 0:An.reviewStatus)==="certified"?"Re-certify":"Certify",Icon:go,variant:"primary",busy:I||!!he,onClick:()=>void Cn(),title:"Run validation, query, tests, chart, and lineage gates before certification"})]}),Ee&&e.jsx("span",{style:{fontSize:11,color:"var(--status-error)",fontFamily:i.font,padding:"4px 8px",background:"var(--status-error-bg)",borderRadius:6},children:Ee})]}),Fe&&qi&&e.jsx(rr,{source:t.blockStudioDraft,databaseStats:At,semanticCount:Sn,onChange:Le,onOpenExplorer:()=>{z(!1),l("database")},onOpenAi:()=>mt({kind:"edit",initialInput:"Review and improve this block context. Keep only grounded business references, sources, constraints, and caveats: "}),t:i}),e.jsx("div",{style:{flex:1,overflow:"hidden"},children:ct==="import"?e.jsx(br,{session:Pe,sessions:$i,sessionsLoading:Ei,onClose:()=>ze(Fe?"manual":"start"),onSessionChange:Lt,onRefreshSessions:Et,onSelectCandidate:Gi,onSavedCandidate:Vi,defaultDomain:((_n=t.blockStudioMetadata)==null?void 0:_n.domain)??T,defaultOwner:((Wn=t.blockStudioMetadata)==null?void 0:Wn.owner)??"",themeMode:t.themeMode,t:i,inline:!0}):Fe?ut==="detail"?e.jsx(ar,{metadata:t.blockStudioMetadata,source:t.blockStudioDraft,parameters:((Fn=t.blockStudioValidation)==null?void 0:Fn.parameters)??[],preview:t.blockStudioPreview,lineageDetail:Ze,isSemanticBlock:Ue,running:U,onOpenBuilder:()=>ge("visual"),onOpenSource:()=>ge("source"),onDelete:()=>{var o;return t.activeBlockPath&&Yt(t.activeBlockPath,((o=t.blockStudioMetadata)==null?void 0:o.name)||me||t.activeBlockPath)},onRun:()=>void Wt(),onOpenHistory:()=>{h("history"),Se(!1),!Ye&&t.activeBlockPath&&O.getBlockHistory(t.activeBlockPath).then(o=>{Ve(o.entries),Me(!0)})},t:i}):ut==="visual"?e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[e.jsx(cr,{mode:Ue?"semantic":"custom",onModeChange:Hi,t:i}),e.jsx("div",{style:{flex:1,minHeight:0},children:Ue?e.jsx(dr,{source:t.blockStudioDraft,metadata:t.blockStudioMetadata,semanticLayer:t.semanticLayer,dbtStatus:t.blockStudioDbtStatus,domainOptions:t.authoredDomains,chartConfig:Bn,onChange:Le,onMetadataChange:o=>t.blockStudioMetadata&&n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{...t.blockStudioMetadata,...o}}),onOpenAi:()=>mt({kind:"edit",initialInput:"Help resolve the selected semantic metrics and dimensions for this block: "}),onSetupRuntime:()=>{n({type:"SET_SETTINGS_TAB",tab:"project"}),n({type:"SET_MAIN_VIEW",view:"settings"})},t:i},`sem-${t.activeBlockPath??d}`):e.jsx(ur,{source:t.blockStudioDraft,metadata:t.blockStudioMetadata,domainOptions:t.authoredDomains,chartConfig:Bn,onChange:Le,onMetadataChange:o=>t.blockStudioMetadata&&n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{...t.blockStudioMetadata,...o}}),onConvertToDql:()=>ge("source"),t:i},`sql-${t.activeBlockPath??d}`)})]}):e.jsxs("div",{style:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[(pt||gn)&&e.jsx(pr,{semanticChoice:pt,databaseWarning:gn,onDismiss:()=>{Ut(null),Kt(null)},onInsertAdvanced:()=>{if(!pt)return;const o=xo(pt.kind==="metric"?"metric":"dimension",pt.name);Le(yo(t.blockStudioDraft,o)),Ut(null)},onCreateSemantic:()=>n({type:"OPEN_NEW_BLOCK_MODAL",blockType:"semantic"}),t:i}),e.jsxs("div",{style:{height:34,flexShrink:0,display:"flex",alignItems:"center",gap:10,padding:"0 14px",borderBottom:"1px solid var(--border-subtle)",background:i.appBg},children:[e.jsx("span",{style:{fontSize:11,color:i.textMuted,fontFamily:i.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.activeBlockPath??Mi(t.blockStudioMetadata)}),e.jsx("span",{style:{width:6,height:6,borderRadius:999,background:"var(--status-warning)",flexShrink:0},title:"Unsaved changes"}),e.jsx("div",{style:{flex:1}}),(((On=t.blockStudioValidation)==null?void 0:On.diagnostics.filter(o=>o.severity==="error").length)??0)===0?e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11,color:"var(--status-success)",fontWeight:600,whiteSpace:"nowrap",fontFamily:i.font},children:[e.jsx(Mt,{size:12})," Valid"]}):e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11,color:"var(--status-warning)",fontWeight:600,whiteSpace:"nowrap",fontFamily:i.font},children:[e.jsx(Ht,{size:12})," ",t.blockStudioValidation.diagnostics.filter(o=>o.severity==="error").length," problem",t.blockStudioValidation.diagnostics.filter(o=>o.severity==="error").length===1?"":"s"]})]}),e.jsxs("div",{style:{flex:1,minHeight:0,display:"flex",overflow:"hidden"},children:[e.jsx("div",{style:{flex:1,minWidth:0,overflow:"hidden",background:i.cellBg,borderRight:"1px solid var(--border-subtle)"},children:e.jsx(Mo,{value:t.blockStudioDraft,onChange:Le,onRun:()=>void Wt(),themeMode:t.themeMode,autoFocus:!0,wrap:!1,fillHeight:!0,schema:A,dqlMode:!0,errorMessage:(Nn=(qn=t.blockStudioValidation)==null?void 0:qn.diagnostics.find(o=>o.severity==="error"))==null?void 0:Nn.message})}),!Q&&e.jsx(Jo,{source:t.blockStudioDraft,diagnostics:((Hn=t.blockStudioValidation)==null?void 0:Hn.diagnostics)??[],parameterCount:((Un=(Qn=t.blockStudioValidation)==null?void 0:Qn.parameters)==null?void 0:Un.length)??0,t:i})]})]}):e.jsx(ir,{dbtStatus:t.blockStudioDbtStatus,semanticStats:vn,semanticObjectCount:Sn,databaseStats:At,onCreateSql:()=>wn("custom"),onCreateSemantic:()=>wn("semantic"),onImport:()=>ze("import"),onBuildDql:()=>mt({kind:"build",initialInput:"Draft a reusable DQL block that "}),t:i})})]}),e.jsx("div",{onMouseDown:tt?eo:void 0,style:{gridColumn:ro,gridRow:so,display:tt?"block":"none",cursor:"row-resize",background:i.headerBorder}}),e.jsxs("div",{style:{gridColumn:lo,gridRow:ao,borderTop:tt?`1px solid ${i.headerBorder}`:"none",display:tt?"flex":"none",flexDirection:"column",overflow:"hidden",background:i.cellBg},children:[e.jsxs("div",{style:{display:"flex",gap:14,alignItems:"center",padding:"0 16px",borderBottom:`1px solid ${i.headerBorder}`,flexWrap:"wrap"},children:[e.jsx(St,{active:f==="results",onClick:()=>h("results"),label:"Results",t:i}),e.jsx(St,{active:f==="parameters",onClick:()=>h("parameters"),label:`Run inputs${(((Gn=(Kn=t.blockStudioValidation)==null?void 0:Kn.parameters)==null?void 0:Gn.length)??0)>0?` · ${t.blockStudioValidation.parameters.length}`:""}`,t:i}),e.jsx(St,{active:f==="lineage",onClick:()=>h("lineage"),label:"Lineage",t:i}),e.jsx(St,{active:f==="history",onClick:()=>{h("history"),!Ye&&t.activeBlockPath&&O.getBlockHistory(t.activeBlockPath).then(o=>{Ve(o.entries),Me(!0)})},label:"History",t:i}),e.jsx(St,{active:f==="save",onClick:()=>h("save"),label:"Metadata",t:i}),e.jsx("div",{style:{flex:1}}),t.blockStudioPreview?e.jsxs("span",{style:{fontSize:11,color:i.textMuted,fontFamily:i.font,whiteSpace:"nowrap"},children:[t.blockStudioPreview.result.executionTime?`Ran in ${(t.blockStudioPreview.result.executionTime/1e3).toFixed(1)}s · `:"",t.blockStudioPreview.result.rowCount??t.blockStudioPreview.result.rows.length," rows"]}):null,e.jsx("button",{onClick:()=>Se(!0),style:{background:"transparent",border:"none",color:i.textMuted,cursor:"pointer",fontSize:11,fontFamily:i.font,padding:"4px 6px"},title:"Hide pane",children:"▾ Hide"})]}),e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[f==="results"&&(U?e.jsx(Tr,{elapsedMs:fe}):t.blockStudioPreview?e.jsxs("div",{style:{display:"grid",gap:12,padding:12},children:[(Yn=(Vn=t.blockStudioPreview.invocation)==null?void 0:Vn.resolvedParameters)!=null&&Yn.length?e.jsx(Br,{values:t.blockStudioPreview.invocation.resolvedParameters,t:i}):null,e.jsx("div",{style:{fontSize:11,color:i.textMuted,fontFamily:i.fontMono},children:t.blockStudioPreview.sql}),Zi==="table"?e.jsx(vi,{result:t.blockStudioPreview.result,themeMode:t.themeMode}):e.jsx(Po,{result:t.blockStudioPreview.result,chartConfig:t.blockStudioPreview.chartConfig,themeMode:t.themeMode})]}):M?e.jsx(Mr,{message:M}):e.jsx(at,{message:"Run the block to preview results."})),f==="lineage"&&e.jsx(kr,{blockName:me,loading:it,detail:Ze,graph:ot,paths:B,onSelectNode:o=>{n({type:"SET_LINEAGE_FOCUS",nodeId:o}),n({type:"OPEN_LINEAGE_DRAWER",nodeId:o})},onOpenInspector:()=>{if(me){const o=`block:${me}`;n({type:"SET_LINEAGE_FOCUS",nodeId:o}),n({type:"OPEN_LINEAGE_DRAWER",nodeId:o})}},t:i}),f==="parameters"&&e.jsx(Cr,{parameters:((Xn=t.blockStudioValidation)==null?void 0:Xn.parameters)??[],values:N,onChange:(o,u)=>ce(v=>({...v,[o]:u})),onReset:o=>ce(u=>{const v={...u};return delete v[o],v}),onRun:()=>void Wt(),running:U,t:i}),f==="history"&&e.jsx($r,{entries:nt,t:i}),f==="save"&&e.jsxs("div",{style:{display:"grid",gap:12},children:[t.activeBlockPath&&t.blockStudioMetadata&&e.jsx("div",{style:{padding:"12px 12px 0"},children:e.jsx(zr,{currentStatus:t.blockStudioMetadata.reviewStatus??"draft",blockPath:t.activeBlockPath,onStatusChanged:o=>{t.blockStudioMetadata&&(n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{...t.blockStudioMetadata,reviewStatus:o}}),n({type:"SET_BLOCK_STUDIO_DRAFT",draft:ae(t.blockStudioDraft,"status",o)}))},t:i})}),yn&&e.jsx(Pr,{result:yn,t:i}),e.jsx(wr,{metadata:t.blockStudioMetadata,draftMetadata:et,onChange:o=>{if(!t.blockStudioMetadata)return;n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{...t.blockStudioMetadata,...o}});let u=t.blockStudioDraft;typeof o.name=="string"&&(u=wt(u,o.name)),typeof o.domain=="string"&&(u=ae(u,"domain",o.domain)),typeof o.owner=="string"&&(u=ae(u,"owner",o.owner)),typeof o.description=="string"&&(u=ae(u,"description",o.description)),o.tags&&(u=Ct(u,o.tags)),Le(u)},t:i})]})]})]}),Fe&&F&&e.jsx("div",{style:{position:"absolute",right:16,bottom:16},children:e.jsx("button",{onClick:()=>Se(!1),style:{background:i.btnBg,border:`1px solid ${i.btnBorder}`,borderRadius:6,color:i.textSecondary,cursor:"pointer",fontSize:12,fontFamily:i.font,padding:"8px 12px"},children:"Open Results"})}),!Q&&Qe&&e.jsx("div",{onMouseDown:to,style:{gridColumn:"4",gridRow:"1 / 4",cursor:"col-resize",background:i.headerBorder}}),Qe&&e.jsx(Wo,{t:i,title:"Block AI",subtitle:me?`Current block: ${me}`:"Unsaved governed block draft",expanded:pn,onToggleExpanded:()=>fn(o=>!o),onClose:()=>{Qt(!1),fn(!1)},onNewChat:()=>{x.resetThreadId(),Li(o=>o+1)},running:zi,compact:Q,ariaLabel:"Block Studio AI",style:{gridColumn:Q?"1":"5",gridRow:Q?Tn:"1 / 4"},children:e.jsx($o,{themeMode:t.themeMode,title:"Block AI",scopeHint:me?`Current block: ${me}`:"Block Studio project context",workspaceContext:{surface:"block-studio",task:xn==="edit"?"edit_block":"author_block",draftSessionId:d,blockStudioDraft:t.blockStudioDraft,activeBlockPath:t.activeBlockPath,domain:(Zn=t.blockStudioMetadata)==null?void 0:Zn.domain,importId:Pe==null?void 0:Pe.id,importCandidateId:(Jn=Pe==null?void 0:Pe.candidates[0])==null?void 0:Jn.id,...xn==="edit"?{mode:"edit",blockPath:t.activeBlockPath}:{}},initialMode:"block",initialInput:_i,autoRun:Fi,threadId:x.threadId,onThreadIdChange:x.onThreadIdChange,onRunningChange:Pi,onInsertSql:(o,u)=>Yi(o,{question:u??me??"analysis",title:u}),onInsertDql:o=>{Xi(o)},answerFirstCards:!0,insertDqlActionLabel:"Add to Block Studio",emptyHint:"Describe the governed block you need. DQL checks certified blocks and semantic metrics before creating a review-required draft.",examplePrompts:[{label:"Build from business question",prompt:"Build a reusable governed DQL block for this business question: "},{label:"Find reusable blocks",prompt:"Which certified DQL blocks already answer this analysis, and what should be reused instead of duplicated?"},{label:"Review this block",prompt:"Review this block for grain, compatible metrics and dimensions, parameters, tests, and certification gaps."}]},`${m}:${Ri}`)}),!Qe&&!Q&&e.jsx("button",{type:"button",onClick:()=>Qt(!0),title:"Open Block AI",style:{position:"absolute",right:12,top:58,width:34,height:34,display:"inline-flex",alignItems:"center",justifyContent:"center",borderRadius:8,border:`1px solid ${i.btnBorder}`,background:i.btnBg,color:i.accent,cursor:"pointer",boxShadow:"0 6px 18px rgba(0, 0, 0, 0.12)"},children:e.jsx(Fo,{size:16,strokeWidth:2})}),le&&t.blockStudioMetadata&&e.jsx(er,{metadata:t.blockStudioMetadata,onCancel:()=>{Ce.current=null,re(!1)},onConfirm:o=>{let u=wt(t.blockStudioDraft,o.name);u=ae(u,"owner",o.owner),n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{...t.blockStudioMetadata,...o}}),n({type:"SET_BLOCK_STUDIO_DRAFT",draft:u}),re(!1)},t:i}),Ae&&e.jsx(tr,{saving:I,onCancel:()=>_e(!1),onDiscard:()=>{_e(!1),_t()},onSave:async()=>{We.current=!0,_e(!1),await Vt()&&(We.current=!1,_t())},t:i}),Ne&&se&&e.jsx(nr,{blockName:se.name,blockPath:se.path,deleting:a,error:J,onCancel:()=>{a||(Be(!1),Ie(null),de(null))},onConfirm:()=>void Ki(),t:i})]})}function Zo({active:t,onClick:n,label:r,busy:s,Icon:i,variant:d="secondary",title:p}){const m=zt[Dt(l=>l.themeMode)],x=d==="primary",P=d==="danger";return e.jsxs("button",{onClick:n,disabled:s,"aria-busy":s||void 0,title:p??r,style:{background:x?m.accent:P?`${m.error}0d`:t?`${m.accent}18`:m.btnBg,border:`1px solid ${x?m.accent:P?`${m.error}55`:t?m.accent:m.btnBorder}`,borderRadius:6,height:28,color:x?"#ffffff":P?m.error:t?m.accent:m.textSecondary,cursor:s?"wait":"pointer",display:"inline-flex",alignItems:"center",gap:6,fontSize:11,fontWeight:x?800:600,fontFamily:m.font,padding:"0 10px",whiteSpace:"nowrap",opacity:s?.7:1},children:[s?e.jsx(lt,{size:13,strokeWidth:2,"aria-hidden":"true"}):i?e.jsx(i,{size:13,strokeWidth:2,"aria-hidden":"true"}):null,s?`${r}...`:r]})}function Ke(t){return e.jsx(Zo,{active:!1,...t})}function Jo({source:t,diagnostics:n,parameterCount:r,t:s}){const i=t.split(`
|
|
20
|
-
`),d={block:"var(--text-tertiary)",parameters:"var(--accent)",query:"var(--status-success)",tests:"var(--status-warning)",visualization:"var(--cat-audit)"},p=[];i.forEach((l,f)=>{const h=l.match(/^\s*(block|parameters|query|tests|visualization)\b/);if(h&&!p.some(T=>T.label.toLowerCase().startsWith(h[1]))){const T=h[1],R=T==="block"?"Metadata":T==="parameters"?`Parameters${r?` · ${r}`:""}`:T.charAt(0).toUpperCase()+T.slice(1);p.push({label:R,line:f+1,color:d[T]??"var(--text-tertiary)"})}});const m=(t.match(/^\s*assert\b/gm)??[]).length,x=new Set((t.match(/\b(?:from|join)\s+([a-z_][\w.]*)/gi)??[]).map(l=>l.replace(/^(from|join)\s+/i,""))).size,P=n.filter(l=>l.severity==="error");return e.jsxs("div",{style:{width:208,flexShrink:0,background:s.appBg,display:"flex",flexDirection:"column",overflow:"auto"},children:[e.jsx("div",{style:{padding:"12px 14px 6px",fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:s.textMuted,fontFamily:s.font},children:"Outline"}),e.jsx("div",{style:{padding:"0 8px",display:"flex",flexDirection:"column",gap:1},children:p.length===0?e.jsx("span",{style:{fontSize:11,color:s.textMuted,padding:"2px 8px",fontFamily:s.font},children:"No sections yet."}):p.map(l=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:6},children:[e.jsx("span",{style:{width:8,height:8,borderRadius:2,background:l.color,flexShrink:0}}),e.jsx("span",{style:{flex:1,fontSize:11.5,fontWeight:550,color:s.textSecondary,fontFamily:s.font},children:l.label}),e.jsxs("span",{style:{fontSize:10,color:s.textMuted,fontFamily:s.fontMono},children:[":",l.line]})]},l.label))}),e.jsx("div",{style:{padding:"14px 14px 6px",fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:s.textMuted,fontFamily:s.font},children:"Problems"}),P.length===0?e.jsxs("div",{style:{padding:"0 14px",fontSize:11.5,color:"var(--status-success)",display:"flex",alignItems:"center",gap:6,fontFamily:s.font},children:[e.jsx(Mt,{size:12})," No problems"]}):e.jsx("div",{style:{padding:"0 14px",display:"flex",flexDirection:"column",gap:5},children:P.slice(0,4).map((l,f)=>e.jsx("span",{style:{fontSize:11,color:"var(--status-error)",lineHeight:1.4,fontFamily:s.font},children:l.message},f))}),e.jsx("div",{style:{padding:"14px 14px 6px",fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:s.textMuted,fontFamily:s.font},children:"Context"}),e.jsxs("div",{style:{padding:"0 14px 16px",display:"flex",flexDirection:"column",gap:5,fontSize:11,color:s.textSecondary,fontFamily:s.font},children:[e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{style:{width:6,height:6,borderRadius:999,background:"var(--accent)"}}),r," parameter",r===1?"":"s"," bound"]}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{style:{width:6,height:6,borderRadius:999,background:"var(--status-success)"}}),x," model",x===1?"":"s"," referenced"]}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{style:{width:6,height:6,borderRadius:999,background:"var(--status-warning)"}}),m," test",m===1?"":"s"," declared"]})]})]})}function St({active:t,onClick:n,label:r,t:s}){return e.jsx("button",{type:"button",onClick:n,style:{padding:"9px 1px",fontSize:11.5,fontWeight:650,cursor:"pointer",border:"none",background:"none",fontFamily:s.font,whiteSpace:"nowrap",color:t?s.textPrimary:s.textMuted,boxShadow:t?`inset 0 -2px 0 0 ${s.accent}`:"none"},children:r})}function si(t,n){return bo(t,{variant:n?"accent":"ghost",size:"xs",active:n})}function Tt(t,n){return{display:"inline-flex",alignItems:"center",gap:5,background:n?"var(--accent-dim)":t.btnBg,border:`1px solid ${n?`${t.accent}55`:t.btnBorder}`,borderRadius:999,color:n?t.accent:t.textSecondary,cursor:"pointer",fontSize:11.5,fontFamily:t.fontMono,lineHeight:1.2,padding:"4px 9px"}}function er({metadata:t,onCancel:n,onConfirm:r,t:s}){const[i,d]=c.useState(t.name),[p,m]=c.useState(t.owner),x=!!(i.trim()&&p.trim());return e.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Save block",style:{position:"absolute",inset:0,zIndex:70,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,.32)",padding:18},children:e.jsxs("div",{style:{width:420,maxWidth:"100%",display:"grid",gap:14,padding:18,borderRadius:10,border:`1px solid ${s.headerBorder}`,background:s.cellBg,boxShadow:"0 24px 70px rgba(0,0,0,.35)"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:15,fontWeight:850,color:s.textPrimary},children:"Save governed block"}),e.jsx("div",{style:{marginTop:4,fontSize:11,lineHeight:1.45,color:s.textMuted},children:"Name and owner are required. DQL will run the local governance checks and certify the block when they pass; otherwise it remains a draft with blockers."})]}),e.jsx($,{label:"Block name",t:s,children:e.jsx("input",{autoFocus:!0,value:i,onChange:P=>d(P.target.value),style:ve(s)})}),e.jsx($,{label:"Owner",t:s,children:e.jsx("input",{value:p,onChange:P=>m(P.target.value),placeholder:"analytics@company.com or team name",style:ve(s)})}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[e.jsx("button",{type:"button",onClick:n,style:ie(s),children:"Cancel"}),e.jsx("button",{type:"button",disabled:!x,onClick:()=>x&&r({name:i.trim(),owner:p.trim()}),style:{...je(s),opacity:x?1:.55},children:"Save block"})]})]})})}function tr({saving:t,onSave:n,onDiscard:r,onCancel:s,t:i}){return e.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Unsaved block",style:{position:"fixed",inset:0,zIndex:90,display:"grid",placeItems:"center",padding:20,background:"rgba(0, 0, 0, 0.42)"},children:e.jsxs("div",{style:{width:"min(430px, 100%)",border:`1px solid ${i.cellBorder}`,borderRadius:12,background:i.cellBg,padding:18,display:"grid",gap:14,boxShadow:"0 20px 60px rgba(0, 0, 0, 0.24)"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:15,fontWeight:800,color:i.textPrimary,fontFamily:i.font},children:"Save this block before starting another?"}),e.jsx("div",{style:{marginTop:5,fontSize:12,lineHeight:1.5,color:i.textMuted,fontFamily:i.font},children:"Your current workspace has unsaved changes."})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[e.jsx("button",{type:"button",onClick:s,disabled:t,style:ie(i),children:"Cancel"}),e.jsx("button",{type:"button",onClick:r,disabled:t,style:{...ie(i),color:i.error},children:"Discard"}),e.jsx("button",{type:"button",onClick:()=>void n(),disabled:t,style:je(i),children:t?"Saving…":"Save block"})]})]})})}function nr({blockName:t,blockPath:n,deleting:r,error:s,onCancel:i,onConfirm:d,t:p}){return e.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Delete block",style:{position:"fixed",inset:0,zIndex:95,display:"grid",placeItems:"center",padding:20,background:"rgba(0, 0, 0, 0.42)"},children:e.jsxs("div",{style:{width:"min(460px, 100%)",border:`1px solid ${p.error}55`,borderRadius:12,background:p.cellBg,padding:18,display:"grid",gap:14,boxShadow:"0 20px 60px rgba(0, 0, 0, 0.26)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9},children:[e.jsx("span",{style:{width:30,height:30,display:"grid",placeItems:"center",borderRadius:8,background:`${p.error}12`},children:e.jsx(Nt,{size:16,color:p.error})}),e.jsxs("div",{children:[e.jsxs("div",{style:{fontSize:15,fontWeight:800,color:p.textPrimary,fontFamily:p.font},children:["Delete “",t,"”?"]}),e.jsx("div",{style:{marginTop:3,fontSize:11,color:p.textMuted,fontFamily:p.fontMono},children:n})]})]}),e.jsxs("div",{style:{fontSize:12,lineHeight:1.5,color:p.textSecondary,fontFamily:p.font},children:["This removes the saved ",e.jsx("code",{children:".dql"})," block and its generated semantic companion. Unsaved editor changes are discarded. Git can recover committed versions."]}),s&&e.jsx("div",{role:"alert",style:{padding:"8px 10px",borderRadius:7,border:`1px solid ${p.error}45`,background:`${p.error}0d`,color:p.error,fontSize:11,lineHeight:1.4},children:s}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[e.jsx("button",{type:"button",onClick:i,disabled:r,style:ie(p),children:"Cancel"}),e.jsx("button",{type:"button",onClick:d,disabled:r,style:{...je(p),background:p.error,borderColor:p.error,opacity:r?.65:1},children:r?e.jsxs(e.Fragment,{children:[e.jsx(lt,{size:13,className:"dql-spin"})," Deleting…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Nt,{size:13})," Delete block"]})})]})]})})}function ir({dbtStatus:t,semanticStats:n,semanticObjectCount:r,databaseStats:s,onCreateSql:i,onCreateSemantic:d,onImport:p,onBuildDql:m,t:x}){var R;const P=[{title:"Blank SQL block",detail:"Start with an empty custom query.",action:i,label:"Create",Icon:Ro},{title:"Semantic block",detail:"Build directly from governed metrics.",action:d,label:"Build",Icon:Ot}],l=!!(t!=null&&t.artifacts.manifest.exists),f=(t==null?void 0:t.counts.metrics)??n.metrics,h=t?`${t.counts.models} dbt models · ${f} MetricFlow metrics`:"Waiting for dbt artifacts",T=(t==null?void 0:t.projectName)||((R=t==null?void 0:t.projectPath)==null?void 0:R.split("/").filter(Boolean).pop())||"dbt project";return e.jsxs("div",{style:{height:"100%",overflow:"auto",padding:22,display:"grid",gap:14,alignContent:"start",background:x.appBg},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:16,flexWrap:"wrap"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:20,fontWeight:800,color:x.textPrimary,fontFamily:x.font},children:"Create DQL blocks"}),e.jsx("div",{style:{fontSize:12,color:x.textMuted,lineHeight:1.45,marginTop:5,maxWidth:560,fontFamily:x.font},children:"Start from SQL you already have, or describe the business asset you want DQL to build from project context."})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,padding:"7px 10px",border:`1px solid ${l?"#2ea04340":x.headerBorder}`,borderRadius:8,background:l?"#2ea0430d":x.cellBg},children:[e.jsx(Mt,{size:15,strokeWidth:2,color:l?"#2ea043":x.textMuted,"aria-hidden":"true"}),e.jsx("span",{style:{fontSize:11,color:l?"#2ea043":x.textMuted,fontWeight:700,fontFamily:x.font},children:l?"dbt ready":"dbt pending"})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(260px, 1fr))",gap:10},children:[e.jsx(en,{title:"Ask AI",detail:"Describe the business asset you need. DQL uses this domain's blocks, models, and semantic metrics to draft it.",label:"Describe block",Icon:qo,onClick:m,t:x}),e.jsx(en,{title:"Import SQL",detail:"Paste scripts, upload files, or point at a folder. DQL analyzes candidates without writing block files until you save.",label:"Start import",Icon:ki,onClick:p,t:x}),e.jsx(en,{title:"Build manually",detail:"Use the visual semantic builder for multiple metrics, compatible dimensions, time grain, filters, and chart intent.",label:"Open builder",Icon:Ot,onClick:d,t:x})]}),e.jsxs("details",{style:jt(x),children:[e.jsx("summary",{style:kt(x),children:"Manual options"}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(160px, 1fr))",gap:10},children:P.map(E=>e.jsx(or,{title:E.title,detail:E.detail,label:E.label,Icon:E.Icon,onClick:E.action,t:x},E.title))})]}),e.jsxs("section",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(160px, 1fr))",gap:8},children:[e.jsx(tn,{Icon:sn,label:`${T} dbt`,value:h,tone:l?"success":"neutral",t:x}),e.jsx(tn,{Icon:sn,label:"Database",value:`${s.tables} tables`,tone:s.tables>0?"success":"neutral",t:x}),e.jsx(tn,{Icon:Ot,label:"DQL semantic layer",value:`${r} objects`,tone:r>0?"success":"neutral",t:x})]})]})}function en({title:t,detail:n,label:r,Icon:s,onClick:i,t:d}){return e.jsxs("button",{onClick:i,style:{border:`1px solid ${d.accent}`,borderRadius:8,background:d.cellBg,color:d.textPrimary,cursor:"pointer",display:"grid",gridTemplateColumns:"42px minmax(0, 1fr) auto",gap:12,alignItems:"center",padding:16,minHeight:104,textAlign:"left",fontFamily:d.font,boxShadow:`inset 0 0 0 1px ${d.accent}22`},children:[e.jsx("span",{style:{width:42,height:42,borderRadius:8,display:"inline-flex",alignItems:"center",justifyContent:"center",background:`${d.accent}18`,color:d.accent},children:e.jsx(s,{size:20,strokeWidth:2,"aria-hidden":"true"})}),e.jsxs("span",{style:{display:"grid",gap:5,minWidth:0},children:[e.jsx("span",{style:{fontSize:15,fontWeight:850,color:d.textPrimary},children:t}),e.jsx("span",{style:{fontSize:12,color:d.textMuted,lineHeight:1.4},children:n})]}),e.jsx("span",{style:{color:"#ffffff",background:d.accent,borderRadius:6,padding:"7px 10px",fontSize:11,fontWeight:800,whiteSpace:"nowrap"},children:r})]})}function or({title:t,detail:n,label:r,Icon:s,onClick:i,t:d}){return e.jsxs("button",{onClick:i,style:{textAlign:"left",background:d.cellBg,border:`1px solid ${d.headerBorder}`,borderRadius:8,padding:12,cursor:"pointer",color:d.textPrimary,display:"grid",gridTemplateColumns:"30px minmax(0, 1fr)",gap:10,minHeight:94,fontFamily:d.font,alignItems:"start"},children:[e.jsx("span",{style:{width:30,height:30,borderRadius:7,display:"inline-flex",alignItems:"center",justifyContent:"center",background:`${d.accent}14`,color:d.accent},children:e.jsx(s,{size:16,strokeWidth:2,"aria-hidden":"true"})}),e.jsxs("span",{style:{display:"grid",gap:5,minWidth:0},children:[e.jsx("span",{style:{fontSize:13,fontWeight:800,color:d.textPrimary},children:t}),e.jsx("span",{style:{fontSize:11,color:d.textMuted,lineHeight:1.35},children:n}),e.jsx("span",{style:{color:d.accent,fontSize:11,fontWeight:800},children:r})]})]})}function tn({Icon:t,label:n,value:r,tone:s,t:i}){const d=s==="success"?"#2ea043":i.textMuted;return e.jsxs("div",{style:{border:`1px solid ${i.headerBorder}`,borderRadius:8,background:i.cellBg,padding:"9px 10px",display:"flex",alignItems:"center",gap:8,minWidth:0},children:[e.jsx("span",{style:{color:d,display:"inline-flex",flexShrink:0},children:e.jsx(t,{size:15,strokeWidth:2,"aria-hidden":"true"})}),e.jsxs("span",{style:{display:"grid",gap:2,minWidth:0},children:[e.jsx("span",{style:{fontSize:10,color:i.textMuted,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.04em",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n}),e.jsx("span",{style:{fontSize:12,color:i.textPrimary,fontWeight:700,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r})]})]})}function rr({source:t,databaseStats:n,semanticCount:r,onChange:s,onOpenExplorer:i,onOpenAi:d,t:p}){const m=l=>{var f;return((f=t.match(new RegExp(`\\b${l}\\s*=\\s*"([^"]*)"`,"i")))==null?void 0:f[1])??""},x=l=>{var f;return(((f=t.match(new RegExp(`\\b${l}\\s*=\\s*\\[([\\s\\S]*?)\\]`,"i")))==null?void 0:f[1].match(/"([^"]*)"/g))??[]).map(h=>h.slice(1,-1))},P=[{key:"primaryTerms",label:"Business terms",hint:"net revenue, active customer"},{key:"sourceSystems",label:"Source systems",hint:"billing, product events"},{key:"synonyms",label:"Question aliases",hint:"sales, bookings"}];return e.jsxs("div",{style:{padding:"10px 14px",borderBottom:`1px solid ${p.headerBorder}`,background:p.appBg,display:"grid",gap:10},children:[e.jsxs("div",{style:{display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[e.jsx("div",{style:{fontSize:12,fontWeight:750,color:p.textPrimary},children:"Block context"}),e.jsx("span",{style:{fontSize:11,color:p.textMuted},children:"Only grounded context is kept with the block and used for retrieval."}),e.jsx("div",{style:{flex:1}}),e.jsxs("button",{type:"button",onClick:i,style:ie(p),children:[n.tables," database tables"]}),e.jsx("button",{type:"button",onClick:d,style:ie(p),children:"Review with AI"})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(230px, 1fr))",gap:10},children:[e.jsx($,{label:"Business outcome",t:p,children:e.jsx(Bt,{value:m("businessOutcome"),onChange:l=>s(ae(t,"businessOutcome",l)),placeholder:"Decision or outcome this block supports",style:ve(p)})}),e.jsx($,{label:"Agent guidance",t:p,children:e.jsx(Bt,{value:m("llmContext"),onChange:l=>s(ae(t,"llmContext",l)),placeholder:"When to use this block",style:ve(p)})}),P.map(l=>e.jsx(sr,{label:l.label,hint:l.hint,values:x(l.key),onChange:f=>s(vo(t,l.key,f)),t:p},l.key)),e.jsx($,{label:"Rules and caveats",t:p,children:e.jsx(Bt,{value:m("caveats"),onChange:l=>s(ae(t,"caveats",l)),placeholder:"Known limitation or interpretation rule",style:ve(p)})})]}),e.jsxs("div",{style:{fontSize:10,color:p.textMuted},children:["Available authoring context: ",r," semantic objects, ",n.schemas," schemas, ",n.columns," columns. SQL completion uses the same loaded catalog."]})]})}function sr({label:t,hint:n,values:r,onChange:s,t:i}){const[d,p]=c.useState(""),m=()=>{const x=d.split(",").map(P=>P.trim()).filter(Boolean);x.length>0&&s([...r,...x]),p("")};return e.jsx($,{label:t,t:i,children:e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:5,padding:6,minHeight:36,border:`1px solid ${i.cellBorder}`,borderRadius:6,background:i.cellBg},children:[r.map(x=>e.jsxs("button",{type:"button",onClick:()=>s(r.filter(P=>P!==x)),title:"Remove",style:{...Tt(i,!0),border:"none",cursor:"pointer"},children:[x," ×"]},x)),e.jsx("input",{value:d,onChange:x=>p(x.target.value),onKeyDown:x=>{(x.key==="Enter"||x.key===",")&&(x.preventDefault(),m())},onBlur:m,placeholder:r.length?"Add another…":n,style:{minWidth:120,flex:1,border:"none",outline:"none",background:"transparent",color:i.textPrimary,fontSize:11,fontFamily:i.font}})]})})}function Ci({source:t,kind:n,onChange:r,t:s}){const i=c.useMemo(()=>Co(t),[t]),[d,p]=c.useState(""),[m,x]=c.useState(""),[P,l]=c.useState(!0),[f,h]=c.useState("dynamic"),[T,R]=c.useState("auto"),E=Jt(m,d),ee=T==="auto"?E:T,_=ve(s),k=()=>{d.trim()&&(r(ii(t,{name:d,type:ee,required:P&&!m.trim(),defaultText:m,policy:f})),p(""),x(""),l(!0),h("dynamic"),R("auto"))};return e.jsx(ue,{title:"Runtime parameters",t:s,children:e.jsxs("div",{style:{display:"grid",gap:10},children:[e.jsxs("div",{style:{fontSize:11,color:s.textMuted,lineHeight:1.45},children:["Add a values-only input once, then reuse this block for a different period, region, customer set, or limit.",n==="custom"?e.jsxs(e.Fragment,{children:[" Use ",e.jsx("code",{children:"${parameter_name}"})," in SQL where the value belongs; DQL always binds it safely."]}):" Choose a semantic field above as a filter to create its governed parameter binding."]}),i.length>0&&e.jsx("div",{style:{display:"grid",gap:7},children:i.map(S=>{var pe;const oe=Bo(S),Z=A=>r(ii(t,{name:S.name,type:A.type??S.type,required:A.required??S.required,defaultText:A.defaultText??oe,policy:A.policy??S.policy}));return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"minmax(120px, 1fr) 122px minmax(150px, 1fr) 118px auto",gap:7,alignItems:"center",padding:8,border:`1px solid ${s.cellBorder}`,borderRadius:7,background:s.cellBg},children:[e.jsxs("div",{style:{minWidth:0},children:[e.jsx("div",{style:{fontSize:11,fontWeight:800,color:s.textPrimary},children:S.name}),e.jsxs("div",{style:{fontSize:10,color:s.textMuted},children:[((pe=S.binding)==null?void 0:pe.kind)??"declared value"," · ",S.required?"required":"has default"]})]}),e.jsx("select",{"aria-label":`${S.name} type`,value:S.type,onChange:A=>Z({type:A.target.value}),style:_,children:li.map(A=>e.jsx("option",{value:A,children:A},A))}),S.type==="boolean"?e.jsxs("select",{"aria-label":`${S.name} default`,value:oe,onChange:A=>Z({defaultText:A.target.value,required:!1}),style:_,children:[e.jsx("option",{value:"",children:"Required / no default"}),e.jsx("option",{value:"true",children:"True"}),e.jsx("option",{value:"false",children:"False"})]}):e.jsx("input",{"aria-label":`${S.name} default`,value:oe,onChange:A=>{const U=A.target.value,Y=S.type===Jt(oe,S.name);Z({defaultText:U,required:U.trim()?!1:S.required,...Y?{type:Jt(U,S.name)}:{}})},placeholder:S.type.endsWith("[]")?"West, East":S.required?"Required value":"Default value",style:_}),e.jsx("select",{"aria-label":`${S.name} policy`,value:S.policy,onChange:A=>Z({policy:A.target.value}),style:_,children:lr.map(A=>e.jsx("option",{value:A,children:A},A))}),e.jsx("button",{type:"button",onClick:()=>r(To(t,S.name)),title:`Remove ${S.name}`,style:{border:"none",background:"transparent",color:s.error,cursor:"pointer",fontSize:16,padding:"3px 5px"},children:"×"})]},S.name)})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"minmax(140px, 1fr) minmax(150px, 1.3fr) 150px 130px auto",gap:7,alignItems:"center",padding:9,border:`1px dashed ${s.btnBorder}`,borderRadius:7,background:s.appBg},children:[e.jsx("input",{"aria-label":"New parameter name",value:d,onChange:S=>p(S.target.value),onKeyDown:S=>{S.key==="Enter"&&(S.preventDefault(),k())},placeholder:"region_set",style:_}),e.jsx("input",{"aria-label":"New parameter default",value:m,onChange:S=>{x(S.target.value),S.target.value.trim()&&l(!1)},onKeyDown:S=>{S.key==="Enter"&&(S.preventDefault(),k())},placeholder:"Central, East or 2026-01-01",style:_}),e.jsxs("select",{"aria-label":"New parameter type",value:T,onChange:S=>R(S.target.value),style:_,children:[e.jsxs("option",{value:"auto",children:["Auto · ",E]}),li.map(S=>e.jsx("option",{value:S,children:S},S))]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:5,color:s.textSecondary,fontSize:11,whiteSpace:"nowrap"},children:[e.jsx("input",{type:"checkbox",checked:P&&!m.trim(),onChange:S=>l(S.target.checked)})," Required"]}),e.jsx("button",{type:"button",onClick:k,disabled:!d.trim(),style:{...je(s),opacity:d.trim()?1:.5},children:"Add"})]}),e.jsxs("div",{style:{fontSize:10,color:s.textMuted},children:["Type is inferred from a value you enter: ",e.jsx("code",{children:"10"})," → number, ",e.jsx("code",{children:"2026-01-01"})," → date, ",e.jsx("code",{children:"West, East"})," → string[]. You can override it at any time."]})]})})}const li=["string","number","boolean","date","string[]","number[]","date[]"],lr=["dynamic","static","business","derived","optional","ambiguous_review_required"];function ar({metadata:t,source:n,parameters:r,preview:s,lineageDetail:i,isSemanticBlock:d,running:p,onOpenBuilder:m,onOpenSource:x,onDelete:P,onRun:l,onOpenHistory:f,t:h}){var X,fe,te,N,ce;const T=((t==null?void 0:t.reviewStatus)??"").toLowerCase()==="certified",R=(t==null?void 0:t.name)||"block",E=d?mi(n):null,ee=((fe=(X=n.match(/query\s*=\s*"""([\s\S]*?)"""/i))==null?void 0:X[1])==null?void 0:fe.trim())??"",_=E?Array.from(new Set([...E.dimensions,...E.timeDimension?[E.timeDimension]:[],...E.metrics])):Ii(ee),k=(n.match(/^\s*assert\b.*$/gm)??[]).map(I=>I.trim()),S=((te=i==null?void 0:i.incoming)==null?void 0:te.length)??0,oe=((N=i==null?void 0:i.outgoing)==null?void 0:N.length)??0,[Z,pe]=c.useState(!1),A=((i==null?void 0:i.incoming)??[]).map(I=>{var H;return(H=I.node)==null?void 0:H.name}).filter(Boolean).slice(0,3),U=((i==null?void 0:i.outgoing)??[]).map(I=>{var H;return(H=I.node)==null?void 0:H.name}).filter(Boolean).slice(0,3),Y={fontSize:11,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:h.textMuted,marginBottom:8,fontFamily:h.font},M=(I,H=!1)=>e.jsx("span",{style:{padding:"3px 9px",borderRadius:999,border:`1px solid ${H?`${h.accent}59`:h.headerBorder}`,background:H?"var(--accent-dim)":"var(--bg-1)",color:H?h.accent:h.textSecondary,fontFamily:h.fontMono,fontWeight:H?600:400,fontSize:11.5},children:I},I),K=e.jsx("span",{style:{color:h.textMuted,fontSize:11},children:"→"}),W=[["Last run",s!=null&&s.result.executionTime?`${(s.result.executionTime/1e3).toFixed(1)}s`:"Not run yet"],["Rows",s?String(s.result.rowCount??s.result.rows.length):"—"],["Used in",oe>0?`${oe} downstream`:"—"],["Tests",k.length>0?`${k.length} declared`:"None yet"]];return e.jsx("div",{style:{height:"100%",overflow:"auto",background:h.appBg},children:e.jsxs("div",{style:{width:"min(860px, 100% - 48px)",margin:"0 auto",padding:"26px 0 40px",display:"flex",flexDirection:"column",gap:20,animation:"dql-agent-fadein 0.25s ease-out",fontFamily:h.font},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:14},children:[e.jsx("span",{style:{width:42,height:42,borderRadius:10,background:T?"var(--status-success-bg)":"var(--accent-dim)",color:T?"var(--status-success)":h.accent,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:"1px solid var(--border-subtle)"},children:e.jsx(Ot,{size:20,strokeWidth:1.75})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:17,fontWeight:700,color:h.textPrimary,fontFamily:h.fontMono,letterSpacing:"-0.01em"},children:R}),t!=null&&t.reviewStatus?e.jsx(ji,{status:t.reviewStatus,t:h}):null]}),e.jsx("div",{style:{fontSize:12,color:h.textMuted,marginTop:4},children:[t==null?void 0:t.domain,t!=null&&t.folderPath?`folder: ${t.folderPath}`:null,t==null?void 0:t.owner,...(ce=t==null?void 0:t.tags)!=null&&ce.length?[t.tags.join(", ")]:[]].filter(Boolean).join(" · ")||"Unsaved draft"})]}),e.jsxs("div",{style:{display:"flex",gap:8,flexShrink:0},children:[e.jsxs("button",{type:"button",onClick:m,style:{display:"inline-flex",alignItems:"center",gap:7,height:32,padding:"0 14px",borderRadius:8,border:"none",background:h.accent,color:"#fff",fontSize:12.5,fontWeight:650,cursor:"pointer",fontFamily:h.font,boxShadow:"0 1px 4px rgba(107,93,211,0.25)"},children:[e.jsx(No,{size:13,strokeWidth:1.75})," Open in builder"]}),e.jsxs("button",{type:"button",onClick:l,disabled:p,style:{display:"inline-flex",alignItems:"center",gap:6,height:32,padding:"0 13px",borderRadius:8,border:`1px solid ${h.headerBorder}`,background:h.cellBg,color:h.textSecondary,fontSize:12.5,fontWeight:600,cursor:"pointer",fontFamily:h.font,opacity:p?.7:1},children:[p?e.jsx(lt,{size:12,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):e.jsx(wi,{size:11,fill:"currentColor"})," Run"]}),e.jsx("button",{type:"button","aria-label":`Delete ${R}`,title:"Delete block",onClick:P,style:{width:32,height:32,borderRadius:8,border:`1px solid ${h.error}55`,background:`${h.error}0d`,color:h.error,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer"},children:e.jsx(Nt,{size:14})}),e.jsx("button",{type:"button",title:"History and metadata",onClick:f,style:{width:32,height:32,borderRadius:8,border:`1px solid ${h.headerBorder}`,background:h.cellBg,color:h.textMuted,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer"},children:e.jsx(Eo,{size:15})})]})]}),t!=null&&t.description?e.jsx("div",{style:{fontSize:13.5,lineHeight:1.6,color:h.textSecondary,maxWidth:640},children:t.description}):null,e.jsx("div",{style:{display:"flex",border:"1px solid var(--border-subtle)",borderRadius:10,background:h.cellBg,overflow:"hidden"},children:W.map(([I,H],he)=>e.jsxs("div",{style:{flex:1,padding:"12px 16px",borderRight:he<W.length-1?"1px solid var(--border-subtle)":"none"},children:[e.jsx("div",{style:{fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:h.textMuted},children:I}),e.jsx("div",{style:{fontSize:14,fontWeight:650,color:h.textPrimary,marginTop:3},children:H})]},I))}),e.jsxs("div",{children:[e.jsx("div",{style:Y,children:"Outputs"}),e.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:_.length>0?_.map(I=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11.5,padding:"4px 10px",borderRadius:999,background:"var(--accent-dim)",color:h.accent,border:`1px solid ${h.accent}33`,fontFamily:h.fontMono},children:I},I)):e.jsx("span",{style:{fontSize:11.5,color:h.textMuted},children:"Open the builder to define outputs."})})]}),e.jsxs("div",{children:[e.jsx("div",{style:Y,children:"Parameters"}),e.jsxs("div",{style:{border:"1px solid var(--border-subtle)",borderRadius:9,overflow:"hidden",background:h.cellBg},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1.2fr 0.8fr 1fr 0.9fr",gap:8,padding:"7px 12px",background:"var(--bg-1)",borderBottom:"1px solid var(--border-subtle)",fontSize:10.5,fontWeight:700,color:h.textMuted,textTransform:"uppercase",letterSpacing:"0.04em"},children:[e.jsx("span",{children:"Name"}),e.jsx("span",{children:"Type"}),e.jsx("span",{children:"Default"}),e.jsx("span",{children:"Policy"})]}),r.length===0?e.jsx("div",{style:{padding:"9px 12px",fontSize:12,color:h.textMuted},children:"No parameters — this block always runs the same way."}):r.map((I,H)=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1.2fr 0.8fr 1fr 0.9fr",gap:8,padding:"8px 12px",borderBottom:H<r.length-1?"1px solid var(--border-subtle)":"none",fontSize:12,alignItems:"center"},children:[e.jsx("span",{style:{fontFamily:h.fontMono,fontWeight:600,color:h.textPrimary},children:I.name}),e.jsx("span",{style:{color:h.textSecondary},children:I.type}),e.jsx("span",{style:{fontFamily:h.fontMono,color:I.default!==void 0&&I.default!==null&&I.default!==""?"var(--status-warning)":h.textMuted},children:I.default!==void 0&&I.default!==null&&I.default!==""?JSON.stringify(I.default):I.required?"required":"—"}),e.jsx("span",{style:{color:h.textMuted},children:I.policy})]},I.name))]})]}),e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[e.jsx("span",{style:{...Y,marginBottom:0},children:"DQL source"}),e.jsxs("button",{type:"button",onClick:x,style:{display:"inline-flex",alignItems:"center",gap:5,border:"none",background:"none",color:h.accent,fontSize:11.5,fontWeight:600,cursor:"pointer",fontFamily:h.font,padding:0},children:["Open in DQL Source ",e.jsx(rn,{size:11,strokeWidth:2})]})]}),e.jsx("pre",{style:{margin:0,border:"1px solid var(--border-subtle)",background:h.cellBg,borderRadius:9,padding:"13px 15px",fontSize:11.5,lineHeight:1.65,fontFamily:h.fontMono,whiteSpace:"pre",overflowX:"auto",color:h.textPrimary,maxHeight:320,overflowY:"auto"},children:n.trim()||"Open the builder to author this block."})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:20},children:[e.jsxs("div",{children:[e.jsx("div",{style:Y,children:"Tests"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:k.length>0?k.map(I=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12},children:[e.jsx(Mt,{size:13,color:"var(--status-success)",strokeWidth:2,style:{flexShrink:0}}),e.jsx("span",{style:{fontFamily:h.fontMono,color:h.textSecondary},children:I})]},I)):e.jsx("span",{style:{fontSize:11.5,color:h.textMuted},children:"No tests yet — add assertions in the builder before certification."})})]}),e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>pe(I=>!I),style:{display:"flex",alignItems:"center",gap:6,border:"none",background:"none",cursor:"pointer",padding:0,fontFamily:h.font,marginBottom:8},children:[e.jsx(rn,{size:11,color:h.textMuted,strokeWidth:2,style:{transform:Z?"rotate(90deg)":"none",transition:"transform 0.12s"}}),e.jsx("span",{style:{fontSize:11,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:h.textMuted},children:"Lineage"}),Z?null:e.jsxs("span",{style:{fontSize:10.5,color:h.textMuted},children:[S," upstream · ",oe," downstream"]})]}),Z?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap",fontSize:11.5,animation:"dql-agent-fadein 0.18s ease-out"},children:[A.length>0?A.map(I=>M(I)):M("no upstream"),K,M(R,!0),K,U.length>0?U.map(I=>M(I)):M("no downstream yet")]}):null]})]})]})})}function dr({source:t,metadata:n,semanticLayer:r,dbtStatus:s,domainOptions:i,chartConfig:d,onChange:p,onMetadataChange:m,onOpenAi:x,onSetupRuntime:P,t:l}){const f=mi(t),h={...f,filters:f.requestedFilters},[T,R]=c.useState([]),[E,ee]=c.useState(!1),[_,k]=c.useState(null),[S,oe]=c.useState(null),[Z,pe]=c.useState(0);c.useEffect(()=>{let a=!1;if(h.metrics.length===0){R([]),k(null),oe(null),ee(!1);return}return R([]),k(null),ee(!0),oe(null),O.getCompatibility(h.metrics).then(L=>{a||(k(L),R(L.dimensions))}).catch(L=>{a||(R([]),oe(L instanceof Error?L.message:String(L)))}).finally(()=>{a||ee(!1)}),()=>{a=!0}},[r.dimensions,h.metrics.join("|"),Z]);const A=new Set(T.flatMap(a=>[a.reference??a.name,a.name])),U=new Map(T.flatMap(a=>[[a.reference??a.name,a.qualifiedName??void 0],[a.name,a.qualifiedName??void 0]])),Y=new Map(((_==null?void 0:_.incompatible)??[]).map(a=>[a.name,Yo(a.reason)])),M=new Map(T.flatMap(a=>[[a.reference??a.name,a],[a.name,a]])),K=Array.from(new Map([...r.dimensions,...r.timeDimensions].map(a=>{const L=a.reference??a.name;return[L,{...a,name:L}]})).values()),W=new Map(K.flatMap(a=>[[a.name,a],[a.reference??a.name,a]])),X=T.map(a=>{const L=a.reference??a.name;return{...W.get(L)??W.get(a.name),...a,name:L}}),fe=X.filter(a=>a.isTimeDimension||a.type==="time"),te=un(l),[N,ce]=c.useState(""),[I,H]=c.useState(""),he=c.useMemo(()=>new Map(r.metrics.map(a=>[a.name,a])),[r.metrics]),ke=c.useMemo(()=>new Map([...K,...X].flatMap(a=>[[a.name,a],[a.reference??a.name,a]])),[K,X]),we=c.useMemo(()=>ai(r.metrics,N),[r.metrics,N]),ye=c.useMemo(()=>ai(X,I),[X,I]),Ee=xi(t,"tests"),G=Array.from(new Set([...h.dimensions,...h.timeDimension?[h.timeDimension]:[],...h.metrics])),Ne=(a,L)=>{m({[a]:L}),p(a==="name"?wt(t,L):ae(t,a,L))},Be=a=>{const L=h.metrics.includes(a)?h.metrics.filter(J=>J!==a):[...h.metrics,a];p(fi(t,L))},se=a=>p(hi(t,"dimensions",a)),Ie=a=>{const L=h.dimensions.includes(a)?h.dimensions.filter(J=>J!==a):[...h.dimensions,a];se(L)};return c.useEffect(()=>{if(!_||h.metrics.length===0)return;const a=So(t,Array.from(A));a!==t&&p(a)},[_,t]),e.jsx("div",{style:{height:"100%",overflow:"auto",background:l.appBg},children:e.jsxs("div",{style:{width:"min(820px, 100% - 48px)",margin:"0 auto",padding:"24px 0 40px",display:"flex",flexDirection:"column",animation:"dql-agent-fadein 0.25s ease-out"},children:[e.jsx(Bi,{metadata:n,domains:i,onTextChange:Ne,onFolderChange:a=>m({folderPath:a}),onTagsChange:a=>{m({tags:a}),p(Ct(t,a))},t:l}),e.jsxs(ue,{title:"Metric and grain",hint:"Pick governed semantic objects — they compile to the DQL script.",t:l,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsxs("span",{style:{fontSize:11,fontWeight:750,color:l.textSecondary},children:["Governed metrics · ",h.metrics.length," selected"]}),E&&e.jsx("span",{style:{fontSize:10,color:l.textMuted},children:"Checking compatibility…"})]}),e.jsx(di,{kind:"metric",total:r.metrics.length,search:N,onSearchChange:ce,matches:we,pool:r.metrics,selected:h.metrics,resolveLabel:a=>{var L;return((L=he.get(a))==null?void 0:L.label)||a},onToggle:Be,compatible:a=>{var L,J,de,Te;return((J=(L=he.get(a))==null?void 0:L.execution)==null?void 0:J.status)!=="requires_setup"&&((Te=(de=he.get(a))==null?void 0:de.execution)==null?void 0:Te.status)!=="unsupported"},t:l}),r.metrics.some(a=>a.execution&&a.execution.status!=="ready")&&e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center",fontSize:10.5,color:l.textMuted,lineHeight:1.4},children:[e.jsx("span",{style:{flex:1},children:"Complex metrics are imported but need a full semantic runtime to execute."}),e.jsx("button",{type:"button",onClick:P,style:{border:"none",background:"transparent",color:l.accent,fontSize:10.5,fontWeight:700,cursor:"pointer",whiteSpace:"nowrap"},children:"Set up runtime →"})]}),((_==null?void 0:_.engine)||(_==null?void 0:_.degraded))&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:10,color:l.textMuted,marginTop:2},children:[e.jsxs("span",{style:{padding:"1px 7px",borderRadius:999,background:"var(--accent-dim)",color:"var(--accent)",fontWeight:700},children:["Runs via ",Vo[_.engine]??_.engine]}),_.degraded&&e.jsx("span",{style:{color:"var(--status-warning)"},children:_.degraded})]}),S&&e.jsxs("div",{role:"alert",style:{display:"flex",alignItems:"center",gap:8,fontSize:11,color:"var(--status-warning)",lineHeight:1.4,marginTop:4},children:[e.jsx(Ht,{size:14,style:{flexShrink:0}}),e.jsxs("span",{style:{flex:1},children:["Could not verify governed dimensions: ",S,". Dimension selection is paused so an unapproved join cannot be saved."]}),e.jsx("button",{type:"button",onClick:()=>pe(a=>a+1),style:ie(l),children:"Retry"})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 150px",gap:8},children:[e.jsx($,{label:"Time dimension",t:l,children:e.jsxs("select",{disabled:h.metrics.length===0||E||!!S,value:h.timeDimension,onChange:a=>p(ni(t,"time_dimension",a.target.value)),style:{...te,opacity:h.metrics.length===0||E||S?.6:1},children:[e.jsx("option",{value:"",children:"None"}),fe.map(a=>e.jsxs("option",{value:a.reference??a.name,children:[a.label||a.name," · ",a.name]},a.reference??a.name))]})}),e.jsx($,{label:"Grain",t:l,children:e.jsxs("select",{value:h.granularity,onChange:a=>p(ni(t,"granularity",a.target.value)),style:te,children:[e.jsx("option",{value:"",children:"None"}),Xo(h.timeDimension,M,r.timeDimensions).map(a=>e.jsx("option",{value:a,children:a},a))]})})]}),r.metrics.length===0&&(r.loading?e.jsxs("div",{role:"status",style:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:l.textMuted,lineHeight:1.45},children:[e.jsx(lt,{size:14,className:"dql-spin"}),"Loading ",((s==null?void 0:s.counts.metrics)??0).toLocaleString()," semantic metrics from parsed dbt artifacts… Large catalogs continue loading in the background."]}):((s==null?void 0:s.counts.metrics)??0)>0||s!=null&&s.artifacts.semanticManifest.exists?e.jsxs("div",{role:"alert",style:{fontSize:12,color:"var(--status-warning)",lineHeight:1.45},children:["dbt artifacts contain ",((s==null?void 0:s.counts.metrics)??0).toLocaleString()," metrics, but Block Studio could not load them. Refresh the semantic layer; another dbt parse is not required."]}):e.jsx("div",{style:{fontSize:12,color:"var(--status-warning)",lineHeight:1.45},children:"No semantic metrics were discovered. Run dbt parse or import a semantic layer, then refresh Block Studio."})),h.metrics.length>1&&_&&T.length===0&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#d29922",fontSize:11,lineHeight:1.4},children:[e.jsx(Ht,{size:14})," These metrics do not expose a common dimension or join path.",e.jsx("button",{type:"button",onClick:x,style:ie(l),children:"Resolve with AI"})]})]}),e.jsxs(ue,{title:"Chart intent",hint:"How apps and answers render this block by default.",t:l,children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr 1fr",gap:10},children:[e.jsx($,{label:"Type",t:l,children:e.jsxs("select",{value:d.chart??"table",onChange:a=>p($e(t,{...d,chart:a.target.value})),style:te,children:[e.jsx("option",{value:"table",children:"Table"}),Si.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))]})}),e.jsx($,{label:"X axis",t:l,children:e.jsxs("select",{value:d.x??"",onChange:a=>p($e(t,{...d,x:a.target.value})),style:te,children:[e.jsx("option",{value:"",children:"Auto"}),G.map(a=>e.jsx("option",{value:a,children:qe(a)},a))]})}),e.jsx($,{label:"Y axis",t:l,children:e.jsxs("select",{value:d.y??"",onChange:a=>p($e(t,{...d,y:a.target.value})),style:te,children:[e.jsx("option",{value:"",children:"Auto"}),G.map(a=>e.jsx("option",{value:a,children:qe(a)},a))]})}),e.jsx($,{label:"Series / color",t:l,children:e.jsxs("select",{value:d.color??"",onChange:a=>p($e(t,{...d,color:a.target.value})),style:te,children:[e.jsx("option",{value:"",children:"None"}),G.map(a=>e.jsx("option",{value:a,children:qe(a)},a))]})})]}),e.jsx($,{label:"Title",t:l,children:e.jsx("input",{value:d.title??"",onChange:a=>p($e(t,{...d,title:a.target.value})),placeholder:"Chart title",style:te})})]}),e.jsx(ue,{title:"Dimensions",hint:"Governed group-bys checked against the metric's join path.",t:l,children:h.metrics.length===0?e.jsx("div",{style:{fontSize:12,color:l.textMuted},children:"Choose one or more governed metrics first. Only their connected, approved dimensions will appear."}):E?e.jsxs("div",{role:"status",style:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:l.textMuted},children:[e.jsx(lt,{size:14,className:"dql-spin"}),"Checking common governed dimensions…"]}):S?e.jsx("div",{style:{fontSize:12,color:"var(--status-warning)"},children:"Dimension selection is unavailable until compatibility succeeds."}):X.length===0?e.jsx("div",{style:{fontSize:12,color:l.textMuted},children:"No dimensions are loaded yet."}):e.jsx(di,{kind:"dimension",total:X.length,search:I,onSearchChange:H,matches:ye,pool:X,selected:h.dimensions,resolveLabel:a=>{var L;return((L=ke.get(a))==null?void 0:L.label)||a},resolveMachineName:a=>{var L;return U.get(a)??((L=ke.get(a))==null?void 0:L.name)??a},reasonFor:a=>Y.get(a),onToggle:Ie,compatible:a=>A.has(a),disabled:h.metrics.length===0||E||!!S,emptyHint:E?"Checking common governed dimensions…":S?"Retry compatibility before selecting dimensions.":"Choose a metric first; dimensions are checked against its governed join path.",t:l})}),e.jsxs(ue,{title:"Filters and parameters",hint:"Values-only inputs so this block is reusable across periods and regions.",t:l,children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:7},children:Array.from(new Set([...h.dimensions,...h.timeDimension?[h.timeDimension]:[]])).map(a=>{var J;const L=h.filters.includes(a);return e.jsx("button",{type:"button",onClick:()=>p(jo(t,L?h.filters.filter(de=>de!==a):[...h.filters,a])),style:Tt(l,L),children:((J=ke.get(a))==null?void 0:J.label)||a},a)})}),e.jsx("div",{style:{fontSize:10,color:l.textMuted,marginTop:8},children:h.dimensions.length===0&&!h.timeDimension?"Search and add a compatible dimension first, then choose whether it should also be a dynamic filter.":"Selected fields become governed runtime filters. Values stay dynamic rather than being hard-coded into SQL."}),h.filters.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginTop:8},children:h.filters.map(a=>e.jsxs("span",{style:Tt(l,!0),children:[qe(a)," · dynamic"]},a))})]}),e.jsx(Ci,{source:t,kind:"semantic",onChange:p,t:l}),e.jsx(ue,{title:`Output fields${G.length?` · ${G.length}`:""}`,hint:"What consumers see when this block answers a question.",t:l,children:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:G.length>0?G.map(a=>e.jsx("span",{style:Tt(l,!0),children:qe(a)},a)):e.jsx("span",{style:{fontSize:11,color:l.textMuted},children:"Select metrics and dimensions to define outputs."})})}),e.jsx(ue,{title:"Tests",hint:"Assertions checked on every run and required for certification.",t:l,children:e.jsx(Bt,{multiline:!0,value:Ee,onChange:a=>p(yi(t,"tests",a)),placeholder:`assert row_count >= 1
|
|
21
|
-
assert total_revenue >= 0`,style:{...te,minHeight:64,resize:"vertical",fontFamily:l.fontMono}})}),e.jsxs("details",{style:{padding:"14px 0",color:l.textSecondary,fontFamily:l.font},children:[e.jsx("summary",{style:{cursor:"pointer",fontSize:11,fontWeight:750},children:"Generated DQL preview"}),e.jsx("pre",{style:{maxHeight:240,overflow:"auto",margin:"10px 0 0",whiteSpace:"pre-wrap",color:l.textSecondary,fontSize:11,lineHeight:1.45,fontFamily:l.fontMono,border:"1px solid var(--border-subtle)",background:"var(--bg-2)",borderRadius:9,padding:"12px 14px"},children:t})]})]})})}function Bi({metadata:t,domains:n,onTextChange:r,onFolderChange:s,onTagsChange:i,t:d}){const p=Go(t==null?void 0:t.domain,n),m=un(d);return e.jsx(ue,{title:"Details",hint:"Name, ownership, and where this block lives.",t:d,children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[e.jsx($,{label:"Block name",t:d,children:e.jsx("input",{value:(t==null?void 0:t.name)??"",onChange:x=>r("name",x.target.value),style:{...m,fontFamily:d.fontMono}})}),e.jsx($,{label:"Domain",t:d,children:e.jsxs("select",{"aria-label":"Block domain",value:(t==null?void 0:t.domain)??"",onChange:x=>r("domain",x.target.value),style:m,children:[e.jsx("option",{value:"",children:"Select domain…"}),p.map(x=>e.jsx("option",{value:x.value,disabled:x.disabled,children:x.label},x.value))]})}),e.jsx($,{label:"Owner",t:d,children:e.jsx("input",{value:(t==null?void 0:t.owner)??"",onChange:x=>r("owner",x.target.value),placeholder:"Required to save",style:m})}),e.jsx($,{label:"Tags",t:d,children:e.jsx(bi,{values:(t==null?void 0:t.tags)??[],onChange:i,placeholder:"finance, emea",style:m})}),e.jsxs("div",{style:{gridColumn:"1 / -1"},children:[e.jsx($,{label:"Folder (optional)",t:d,children:e.jsx("input",{"aria-label":"Block folder",value:(t==null?void 0:t.folderPath)??"",onChange:x=>s(x.target.value),placeholder:"executive/monthly",style:{...m,fontFamily:d.fontMono}})}),e.jsx("div",{style:{marginTop:5,fontSize:10,color:d.textMuted,fontFamily:d.fontMono},children:Mi(t)})]}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx($,{label:"Description",t:d,children:e.jsx("input",{value:(t==null?void 0:t.description)??"",onChange:x=>r("description",x.target.value),placeholder:"What business question does this answer?",style:m})})})]})})}function ai(t,n){const r=n.trim().toLowerCase();return r.length<2?[]:t.filter(s=>[s.name,s.label,s.description,s.domain].filter(Boolean).some(i=>i.toLowerCase().includes(r))).slice(0,30)}function di({kind:t,total:n,search:r,onSearchChange:s,matches:i,pool:d=[],selected:p,resolveLabel:m,resolveMachineName:x,reasonFor:P,onToggle:l,compatible:f=()=>!0,disabled:h=!1,emptyHint:T,t:R}){const[E,ee]=c.useState(!1),_=c.useRef(null),k=c.useRef(null),S=t==="metric"?"measures":"dimensions",oe=t==="metric"?"Σ":"ab",Z=t==="metric"?"var(--accent)":"var(--status-success)",pe=t==="metric"?"var(--accent-dim)":"var(--status-success-bg)",A=r.trim().length>=2,U=A?i:d.filter(M=>!p.includes(M.name)).slice(0,8),Y=()=>{ee(!1),s("")};return c.useEffect(()=>{if(!E)return;requestAnimationFrame(()=>{var W;return(W=_.current)==null?void 0:W.focus()});const M=W=>{k.current&&!k.current.contains(W.target)&&Y()},K=W=>{W.key==="Escape"&&Y()};return document.addEventListener("mousedown",M),document.addEventListener("keydown",K),()=>{document.removeEventListener("mousedown",M),document.removeEventListener("keydown",K)}},[E]),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap",marginTop:9},children:[p.map(M=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11.5,padding:"4px 9px",borderRadius:999,background:pe,color:Z,border:`1px solid ${t==="metric"?"rgba(107,93,211,0.2)":"rgba(46,139,87,0.25)"}`,fontFamily:R.fontMono},children:[t==="metric"?`Σ ${m(M)}`:m(M),e.jsx("button",{type:"button",onClick:()=>l(M),title:`Remove ${m(M)}`,style:{border:"none",background:"none",color:Z,cursor:"pointer",padding:0,fontSize:12,lineHeight:1,fontFamily:"inherit"},children:"×"})]},M)),e.jsxs("span",{ref:k,style:{position:"relative"},children:[e.jsxs("button",{type:"button",disabled:h,onClick:()=>ee(M=>!M),title:h?T:`Add ${t}`,style:{border:"1.5px dashed var(--border-strong)",background:"transparent",borderRadius:999,padding:"4px 10px",fontSize:11,fontFamily:R.font,color:h?R.textMuted:R.textSecondary,cursor:h?"not-allowed":"pointer",opacity:h?.6:1},children:["+ Add ",t]}),E&&!h?e.jsxs("div",{style:{position:"absolute",right:0,top:30,zIndex:40,width:300,background:R.cellBg,border:`1px solid ${R.headerBorder}`,borderRadius:10,boxShadow:"0 10px 30px rgba(26,26,26,0.14)",overflow:"hidden",animation:"dql-agent-fadein 0.12s ease-out"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,padding:"8px 10px",borderBottom:"1px solid var(--border-subtle)"},children:[e.jsx(wo,{size:12,color:R.textMuted,style:{flexShrink:0}}),e.jsx("input",{ref:_,value:r,onChange:M=>s(M.target.value),placeholder:`Search ${n.toLocaleString()} ${S}…`,style:{flex:1,border:"none",background:"none",outline:"none",fontSize:12,fontFamily:R.font,color:R.textPrimary,minWidth:0}}),e.jsx("button",{type:"button",onClick:Y,style:{border:"none",background:"none",color:R.textMuted,cursor:"pointer",padding:0,fontSize:13,lineHeight:1},children:"×"})]}),e.jsx("div",{style:{maxHeight:208,overflow:"auto"},children:U.length===0?e.jsx("div",{style:{padding:10,fontSize:11,color:R.textMuted},children:A?`No ${S} match “${r}”.`:`No more ${S} to add.`}):U.map(M=>{const K=p.includes(M.name),W=f(M.name),X=(x==null?void 0:x(M.name))??M.name,fe=X!==(M.label||M.name),te=W?void 0:(P==null?void 0:P(M.name))??"Not compatible with every selected metric";return e.jsxs("button",{type:"button",disabled:!W,onClick:()=>{l(M.name),K||Y()},title:te??M.description??X,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",border:"none",background:K?pe:"none",cursor:W?"pointer":"not-allowed",textAlign:"left",fontFamily:R.font,borderBottom:"1px solid var(--border-subtle)",opacity:W?1:.5},children:[e.jsx("span",{style:{flexShrink:0,width:16,height:16,borderRadius:4,background:pe,color:Z,display:"inline-flex",alignItems:"center",justifyContent:"center",fontSize:t==="metric"?10:9,fontWeight:700,fontFamily:R.fontMono},children:oe}),e.jsxs("span",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:1,overflow:"hidden"},children:[e.jsx("span",{style:{fontSize:12,fontFamily:R.font,color:R.textPrimary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:M.label||M.name}),fe?e.jsx("span",{style:{fontSize:10,fontFamily:R.fontMono,color:R.textMuted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:X}):null]}),e.jsx("span",{style:{flexShrink:0,fontSize:10,color:R.textMuted},children:M.domain||M.type||""})]},M.name)})}),e.jsx("div",{style:{padding:"6px 10px",background:"var(--bg-1)",fontSize:10,color:R.textMuted},children:A?`${U.length} match${U.length===1?"":"es"} · certified shown first`:`Showing top ${U.length} of ${n.toLocaleString()} · type to search all`})]}):null]})]})}function cr({mode:t,onModeChange:n,t:r}){const s=[{key:"semantic",label:"Semantic picker"},{key:"custom",label:"Raw SQL"}];return e.jsx("div",{style:{flexShrink:0,borderBottom:`1px solid ${r.headerBorder}`,background:r.appBg},children:e.jsxs("div",{style:{width:"min(820px, 100% - 48px)",margin:"0 auto",padding:"10px 0",display:"flex",alignItems:"center",gap:10},children:[e.jsx("span",{style:{fontSize:10.5,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:r.textMuted},children:"Query"}),e.jsx("div",{style:{display:"inline-flex",alignItems:"center",gap:2,padding:2,border:`1px solid ${r.headerBorder}`,borderRadius:8,background:r.cellBg},children:s.map(i=>{const d=i.key===t;return e.jsx("button",{type:"button",onClick:()=>n(i.key),style:{border:"none",borderRadius:6,padding:"5px 12px",fontSize:12,fontWeight:600,cursor:"pointer",fontFamily:r.font,background:d?"var(--accent-dim)":"transparent",color:d?r.accent:r.textMuted},children:i.label},i.key)})}),e.jsx("span",{style:{fontSize:11,color:r.textMuted,fontFamily:r.font},children:t==="semantic"?"Pick governed metrics & dimensions — they compile to DQL.":"Write SQL and convert it into a governed DQL script."})]})})}function ur({source:t,metadata:n,domainOptions:r,chartConfig:s,onChange:i,onMetadataChange:d,onConvertToDql:p,t:m}){var ee,_;const x=un(m),P=((_=(ee=t.match(/query\s*=\s*"""([\s\S]*?)"""/i))==null?void 0:ee[1])==null?void 0:_.trim())??"",[l,f]=c.useState(P),h=Ii(l),T=xi(t,"tests"),R=k=>{f(k),i(gi(t,k))},E=(k,S)=>{d({[k]:S}),i(k==="name"?wt(t,S):ae(t,k,S))};return e.jsx("div",{style:{height:"100%",overflow:"auto",background:m.appBg},children:e.jsxs("div",{style:{width:"min(820px, 100% - 48px)",margin:"0 auto",padding:"24px 0 40px",display:"flex",flexDirection:"column",animation:"dql-agent-fadein 0.25s ease-out"},children:[e.jsx(Bi,{metadata:n,domains:r,onTextChange:E,onFolderChange:k=>d({folderPath:k}),onTagsChange:k=>{d({tags:k}),i(Ct(t,k))},t:m}),e.jsxs(ue,{title:"Query",hint:"Write raw SQL — it compiles into a governed DQL script.",t:m,children:[e.jsx("textarea",{rows:7,value:l,onChange:k=>R(k.target.value),spellCheck:!1,style:{border:"1px solid var(--border-default)",background:"var(--bg-1)",borderRadius:8,padding:"10px 12px",fontSize:11.5,lineHeight:1.6,fontFamily:m.fontMono,color:m.textPrimary,outline:"none",resize:"vertical"},placeholder:`SELECT
|
|
22
|
-
category,
|
|
23
|
-
SUM(revenue) AS revenue
|
|
24
|
-
FROM {{ ref('orders') }}
|
|
25
|
-
GROUP BY 1`}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[e.jsx("button",{type:"button",onClick:p,disabled:!l.trim(),style:{display:"inline-flex",alignItems:"center",gap:6,height:28,padding:"0 12px",borderRadius:8,border:`1px solid ${m.accent}`,background:"var(--accent-dim)",color:m.accent,fontSize:11.5,fontWeight:650,cursor:l.trim()?"pointer":"not-allowed",fontFamily:m.font,opacity:l.trim()?1:.6},children:"Convert to DQL script"}),e.jsxs("span",{style:{fontSize:10.5,color:m.textMuted,fontFamily:m.font},children:["Detects ",e.jsx("span",{style:{fontFamily:m.fontMono},children:"${params}"})," and grounds tables against dbt. Open the DQL Source editor for the full script."]})]})]}),e.jsxs(ue,{title:"Chart intent",hint:"How apps and answers render this block by default.",t:m,children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr 1fr",gap:10},children:[e.jsx($,{label:"Type",t:m,children:e.jsxs("select",{value:s.chart??"table",onChange:k=>i($e(t,{...s,chart:k.target.value})),style:x,children:[e.jsx("option",{value:"table",children:"Table"}),Si.map(k=>e.jsx("option",{value:k.value,children:k.label},k.value))]})}),e.jsx($,{label:"X axis",t:m,children:e.jsxs("select",{value:s.x??"",onChange:k=>i($e(t,{...s,x:k.target.value})),style:x,children:[e.jsx("option",{value:"",children:"Auto"}),h.map(k=>e.jsx("option",{value:k,children:qe(k)},k))]})}),e.jsx($,{label:"Y axis",t:m,children:e.jsxs("select",{value:s.y??"",onChange:k=>i($e(t,{...s,y:k.target.value})),style:x,children:[e.jsx("option",{value:"",children:"Auto"}),h.map(k=>e.jsx("option",{value:k,children:qe(k)},k))]})}),e.jsx($,{label:"Series / color",t:m,children:e.jsxs("select",{value:s.color??"",onChange:k=>i($e(t,{...s,color:k.target.value})),style:x,children:[e.jsx("option",{value:"",children:"None"}),h.map(k=>e.jsx("option",{value:k,children:qe(k)},k))]})})]}),e.jsx($,{label:"Title",t:m,children:e.jsx("input",{value:s.title??"",onChange:k=>i($e(t,{...s,title:k.target.value})),style:x})})]}),e.jsx(ue,{title:"Business outputs",hint:"What consumers see when this block answers a question.",t:m,children:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:7},children:h.length>0?h.map(k=>e.jsx("span",{style:Tt(m,!0),children:qe(k)},k)):e.jsx("span",{style:{fontSize:11,color:m.textMuted},children:"Add aliases in DQL Source to expose business-friendly output names."})})}),e.jsx(Ci,{source:t,kind:"custom",onChange:i,t:m}),e.jsx(ue,{title:"Tests",hint:"Assertions checked on every run and required for certification.",t:m,children:e.jsx(Bt,{multiline:!0,value:T,onChange:k=>i(yi(t,"tests",k)),placeholder:`assert row_count >= 1
|
|
26
|
-
assert revenue >= 0`,style:{...x,minHeight:64,resize:"vertical",fontFamily:m.fontMono}})}),e.jsxs("details",{style:{padding:"14px 0",color:m.textSecondary,fontFamily:m.font},children:[e.jsx("summary",{style:{cursor:"pointer",fontSize:11,fontWeight:750},children:"Generated DQL preview"}),e.jsx("pre",{style:{maxHeight:240,overflow:"auto",margin:"10px 0 0",whiteSpace:"pre-wrap",color:m.textSecondary,fontSize:11,lineHeight:1.45,fontFamily:m.fontMono,border:"1px solid var(--border-subtle)",background:"var(--bg-2)",borderRadius:9,padding:"12px 14px"},children:t})]})]})})}function pr({semanticChoice:t,databaseWarning:n,onDismiss:r,onInsertAdvanced:s,onCreateSemantic:i,t:d}){const p=t?`${t.kind==="metric"?"Metric":"Dimension"} "${t.name}" belongs in a Semantic Block. SQL Blocks can still use advanced @metric/@dim refs when you choose that explicitly.`:n??"";return e.jsxs("div",{style:{padding:"10px 12px",borderBottom:`1px solid ${d.headerBorder}`,background:`${d.accent}10`,display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,color:d.textSecondary,lineHeight:1.4,flex:1,minWidth:260},children:p}),t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:i,style:ie(d),children:"Create Semantic Block"}),e.jsx("button",{onClick:s,style:je(d),children:"Insert advanced ref"})]}),e.jsx("button",{onClick:r,style:ie(d),children:"Dismiss"})]})}function an(t){var r,s,i,d,p;const n=((s=(r=t.preview)==null?void 0:r.result)==null?void 0:s.rowCount)??((p=(d=(i=t.preview)==null?void 0:i.result)==null?void 0:d.rows)==null?void 0:p.length);return typeof n=="number"?n:void 0}function It(t){return t?t.startsWith("blocks/_drafts/")||/^domains\/[^/]+\/blocks\/_drafts\//.test(t):!1}function Ge(t){var n,r,s,i,d;return t.reviewStatus==="saved"?{id:t.id,name:t.name,sourcePath:t.sourcePath,status:"saved",rows:an(t),message:"Block saved."}:((n=t.validation)==null?void 0:n.valid)===!1?{id:t.id,name:t.name,sourcePath:t.sourcePath,status:"needs_attention",message:((r=t.validation.diagnostics.find(p=>p.severity==="error"))==null?void 0:r.message)??"DQL validation needs attention."}:t.preview?{id:t.id,name:t.name,sourcePath:t.sourcePath,status:"ready",rows:an(t),savedPath:t.savedPath,message:It(t.savedPath)?"Preview ran successfully. Draft is saved for review.":"Preview ran successfully. Nothing is written until you save."}:((s=t.draftSave)==null?void 0:s.status)==="saved"||It(t.savedPath)?{id:t.id,name:t.name,sourcePath:t.sourcePath,status:"ready",savedPath:((i=t.draftSave)==null?void 0:i.path)??t.savedPath,message:"Draft saved. Run preview, then certify when ready."}:((d=t.draftSave)==null?void 0:d.status)==="error"?{id:t.id,name:t.name,sourcePath:t.sourcePath,status:"needs_attention",message:t.draftSave.error??"Draft preparation failed."}:{id:t.id,name:t.name,sourcePath:t.sourcePath,status:"queued",message:"Ready to process."}}function fr(t){return t==="retrieving"?"Checking certified blocks and semantic metrics.":t==="reviewing"?"Reviewing governed evidence and building the candidate.":t==="ready"?"Analysis ready. Preparing preview.":t==="needs_attention"?"Analysis needs attention.":"Queued for governed retrieval."}async function hr(t,n){for(let r=0;r<240;r+=1){const s=await O.getDqlGenerationSession(t);if(n(s),s.candidates.every(i=>i.analysisStatus==="ready"||i.analysisStatus==="needs_attention"))return s;await new Promise(i=>window.setTimeout(i,500))}throw new Error("Import analysis is still running. You can leave this workspace and resume the session later.")}async function mr(t,n,r){let s=0;const i=Array.from({length:Math.min(Math.max(1,n),t.length)},async()=>{for(;s<t.length;){const d=s;s+=1,await r(t[d])}});await Promise.all(i)}function qt(t){return!!(t.generationMode||t.draftSave||It(t.savedPath))}function gr(t){return t==="creating"?"Reading SQL":t==="running"?"Running previews":t==="saving"?"Saving blocks":t==="complete"?"Import complete":"Ready"}function xr(t){return t==="needs_attention"?"needs attention":t.replace("_"," ")}function yr(t){return t==="saved"||t==="ready"?"ok":t==="needs_attention"?"warn":"info"}function br({session:t,sessions:n,sessionsLoading:r,onClose:s,onSessionChange:i,onRefreshSessions:d,onSelectCandidate:p,onSavedCandidate:m,defaultDomain:x,defaultOwner:P,themeMode:l,t:f,inline:h=!1}){const[T,R]=c.useState("paste"),[E,ee]=c.useState(""),[_,k]=c.useState(""),[S,oe]=c.useState([]),[Z,pe]=c.useState(x),[A,U]=c.useState(P),[Y,M]=c.useState(null),[K,W]=c.useState(!1),[X,fe]=c.useState(!1),[te,N]=c.useState(null),[ce,I]=c.useState(null),[H,he]=c.useState(!1),[ke,we]=c.useState(!0),[ye,Ee]=c.useState(""),[G,Ne]=c.useState(!1),[Be,se]=c.useState({}),[Ie,a]=c.useState("idle"),[L,J]=c.useState({}),de=c.useMemo(()=>t?t.candidates.find(g=>g.id===Y)??t.candidates[0]??null:null,[t,Y]);c.useEffect(()=>{if(!(t!=null&&t.candidates.length)){M(null);return}(!Y||!t.candidates.some(g=>g.id===Y))&&M(t.candidates[0].id)},[t,Y]),c.useEffect(()=>{se({})},[t==null?void 0:t.id]),c.useEffect(()=>{we(!(t!=null&&t.candidates.length))},[t==null?void 0:t.id,t==null?void 0:t.candidates.length]),c.useEffect(()=>{if(!t){J({}),a("idle");return}J(Object.fromEntries(t.candidates.map(g=>[g.id,Ge(g)]))),a(g=>g==="idle"?"complete":g)},[t==null?void 0:t.id]);const Te=c.useMemo(()=>{const g=ye.trim().toLowerCase(),B=(t==null?void 0:t.candidates)??[];return g?B.filter(D=>[D.name,D.domain,D.sourcePath,D.description,...D.lineage.sourceTables].some(w=>w.toLowerCase().includes(g))):B},[ye,t]),De=G||ye.trim()?Te:Te.slice(0,10),re=((t==null?void 0:t.candidates.map(g=>L[g.id]??Ge(g)))??[]).reduce((g,B)=>(B.status==="saved"?g.saved+=1:B.status==="ready"?g.ready+=1:B.status==="needs_attention"?g.attention+=1:g.processing+=1,g),{saved:0,ready:0,attention:0,processing:0}),Ae=t?re.saved>0?3:2:1,_e=(t==null?void 0:t.candidates.filter(g=>{var B;return((B=g.validation)==null?void 0:B.valid)!==!1}).length)??0,Ce=!!(T==="paste"?_.trim():T==="upload"?S.length>0:E.trim()),We=()=>T==="paste"?{inputMode:"paste",sourceKind:"raw-sql",domain:Z,owner:A,sources:[{path:"pasted.sql",content:_}],async:!0,persistence:"session-only"}:T==="upload"?{inputMode:"upload",sourceKind:"raw-sql",domain:Z,owner:A,sources:S,async:!0,persistence:"session-only"}:{path:E,inputMode:"path",sourceKind:"raw-sql",domain:Z,owner:A,async:!0,persistence:"session-only"},dt=async()=>{var g,B,D;W(!0),fe(!0),N(null),se({}),J({}),a("creating");try{const w=await O.createDqlGenerationSession(We());let q=w,ne=Object.fromEntries(w.candidates.map(z=>[z.id,{...Ge(z),status:"queued",message:"Queued for governed retrieval."}]));const y=(z,F)=>{ne={...ne,[z]:F(ne[z])},J(ne)},j=z=>{q={...q,candidates:q.candidates.map(F=>F.id===z.id?z:F)},i(q)};i(q),M(((g=q.candidates[0])==null?void 0:g.id)??null),J(ne),await d(),a("running"),q=await hr(w.id,z=>{q=z,i(z);for(const F of z.candidates)y(F.id,Se=>({...Se,name:F.name,sourcePath:F.sourcePath,status:F.analysisStatus==="needs_attention"?"needs_attention":F.analysisStatus==="ready"?"queued":"running",message:fr(F.analysisStatus)}))}),await mr(q.candidates,2,async z=>{if(z.analysisStatus!=="needs_attention"){y(z.id,F=>({...F,status:"running",message:"Running preview."}));try{const F=await O.previewDqlGenerationCandidate(q.id,z.id);j(F),y(z.id,Se=>{var Q;return{...Se,name:F.name,sourcePath:F.sourcePath,status:"ready",rows:an(F),savedPath:((Q=F.draftSave)==null?void 0:Q.path)??F.savedPath,message:F.recommendedAction==="reuse_existing"?"A governed block already answers this SQL. Reuse it instead of saving a duplicate.":"Preview ran successfully. Nothing is written until you save."}})}catch(F){const Se=(F==null?void 0:F.message)??"Preview failed.";se(Q=>({...Q,[z.id]:Se})),y(z.id,Q=>({...Q,status:"needs_attention",message:Se}))}}}),i(q),M(((B=q.candidates.find(z=>z.reviewStatus!=="rejected"))==null?void 0:B.id)??((D=q.candidates[0])==null?void 0:D.id)??null),await d(),a("complete")}catch(w){N((w==null?void 0:w.message)??"Import failed."),a("idle")}finally{W(!1),fe(!1)}},He=async g=>{var B,D;W(!0),N(null);try{const w=await O.getDqlGenerationSession(g).catch(()=>O.getBlockStudioImport(g));i(w),M(((B=w.candidates.find(q=>q.reviewStatus!=="saved"&&q.reviewStatus!=="rejected"))==null?void 0:B.id)??((D=w.candidates[0])==null?void 0:D.id)??null),se({}),a("complete")}catch(w){N((w==null?void 0:w.message)??"Failed to resume import session.")}finally{W(!1)}},nt=async g=>{I({kind:"one",id:g})},Ve=async()=>{n.length!==0&&I({kind:"all"})},Ye=async()=>{if(!ce)return;const g=ce;W(!0),N(null);try{g.kind==="one"?await O.deleteBlockStudioImport(g.id):await O.clearBlockStudioImports(),(g.kind==="all"||(t==null?void 0:t.id)===g.id)&&(i(null),M(null)),I(null),await d()}catch(B){N((B==null?void 0:B.message)??"Failed to update import history.")}finally{W(!1)}},Me=g=>{t&&(i({...t,candidates:t.candidates.map(B=>B.id===g.id?g:B)}),J(B=>({...B,[g.id]:Ge(g)})))},it=async g=>{if(t){W(!0),N(null),se(B=>{if(!B[g.id])return B;const D={...B};return delete D[g.id],D});try{const B=qt(g)?await O.previewDqlGenerationCandidate(t.id,g.id):await O.runBlockStudioImportCandidate(t.id,g.id);Me(B),M(B.id),se(D=>{if(!D[g.id])return D;const w={...D};return delete w[g.id],w})}catch(B){const D=(B==null?void 0:B.message)??"Candidate run failed.";N(D),M(g.id),se(w=>({...w,[g.id]:D}))}finally{W(!1)}}},Xe=async g=>{if(!t)return;const B=g.owner.trim()||A.trim();if(!B){N("Owner is required before a block can be saved or certified.");return}W(!0),N(null);try{if(qt(g)){const D=await O.saveSelectedDqlGenerationCandidates(t.id,{candidateIds:[g.id],owner:B});i(D.session);const w=D.results[0];if(!w||w.status==="error")throw new Error((w==null?void 0:w.error)??(w==null?void 0:w.blockers.join(" "))??"Candidate save failed.");w.candidate&&Me(w.candidate),w.candidate&&w.block&&m(w.candidate,w.block),w.status==="draft"&&w.blockers.length>0&&N(`Saved as draft: ${w.blockers.join(" ")}`)}else{const D=await O.saveBlockStudioImportCandidate(t.id,g.id);Me(D.candidate),m(D.candidate,D.block)}await d()}catch(D){const w=(D==null?void 0:D.message)??"Candidate save failed.";N(w.includes("409")||w.includes("already exists")?"A block with this name already exists. Rename this candidate, then save again.":w)}finally{W(!1)}},Ze=async()=>{if(!t)return;const g=A.trim()||t.defaults.owner.trim();if(!g){N("Owner is required before blocks can be saved or certified.");return}fe(!0),N(null);try{const B=t.candidates.filter(j=>j.reviewStatus!=="rejected"&&j.analysisStatus!=="needs_attention").map(j=>j.id),D=await O.saveSelectedDqlGenerationCandidates(t.id,{candidateIds:B,owner:g});i(D.session);const w=new Map(D.results.filter(j=>j.status==="error").map(j=>[j.candidateId,j.error??j.blockers.join(" ")])),q=new Map(D.results.filter(j=>j.path).map(j=>[j.candidateId,j.path]));J(Object.fromEntries(D.session.candidates.map(j=>{const z=w.get(j.id),F=q.get(j.id)??j.savedPath;return z?[j.id,{...Ge(j),status:"needs_attention",message:z.includes("409")||z.includes("already exists")?"A block with this name already exists. Rename it in advanced details, then save again.":z}]:F||j.reviewStatus==="saved"?[j.id,{...Ge(j),status:"saved",savedPath:F,message:"Block saved."}]:[j.id,Ge(j)]}))),await d();const ne=D.results.filter(j=>j.status==="error").length,y=D.results.filter(j=>j.status==="draft").length;(ne>0||y>0)&&N(`${D.results.length-ne} saved. ${y} stayed draft; ${ne} need attention.`)}catch(B){N((B==null?void 0:B.message)??"Save all failed.")}finally{fe(!1)}},Je=async g=>{if(!t)return;const B=await O.updateBlockStudioImportCandidate(t.id,g.id,{reviewStatus:"rejected"});Me(B),d()},ot=async g=>{const D=Array.from(g??[]).filter(q=>q.name.toLowerCase().endsWith(".sql")),w=await Promise.all(D.map(async q=>({path:q.name,content:await q.text()})));oe(w),w.length>0&&ee("")};return e.jsxs("div",{style:{position:"relative",height:"100%",display:"grid",gridTemplateRows:"80px minmax(0, 1fr)",minHeight:0,background:f.appBg,borderRadius:h?0:8},children:[e.jsxs("header",{style:{borderBottom:`1px solid ${f.headerBorder}`,background:f.cellBg,padding:"14px 14px 12px",display:"flex",alignItems:"center",gap:14,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,minWidth:260},children:[e.jsx("span",{style:{width:34,height:34,borderRadius:8,display:"inline-flex",alignItems:"center",justifyContent:"center",color:f.accent,background:`${f.accent}16`,flexShrink:0},children:e.jsx(ln,{size:17,strokeWidth:2,"aria-hidden":"true"})}),e.jsxs("span",{style:{display:"grid",gap:2,minWidth:0},children:[e.jsx("span",{style:{fontSize:15,fontWeight:800,color:f.textPrimary,fontFamily:f.font},children:"Import SQL to DQL"}),e.jsx("span",{style:{fontSize:11,color:f.textMuted,fontFamily:f.font,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"SQL source to AI-grounded drafts to review and certify"})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, minmax(130px, 1fr))",gap:6,width:"min(560px, 44vw)",minWidth:390},children:[e.jsx(nn,{index:1,active:Ae===1,complete:!!t,title:"Source",detail:T==="paste"?"Paste SQL":T==="upload"?"Upload files":"Local path",t:f}),e.jsx(nn,{index:2,active:Ae===2,complete:re.ready>0||re.saved>0,title:"Draft",detail:t?`${t.candidates.length} blocks · ${_e} ready`:"Generate DQL",t:f}),e.jsx(nn,{index:3,active:Ae===3,complete:re.saved>0,title:"Review",detail:re.saved>0?`${re.saved} certified`:"Preview and certify",t:f})]}),e.jsx("div",{style:{flex:1}}),e.jsx("button",{onClick:s,title:"Close import","aria-label":"Close import",style:{...ie(f),width:32,height:32,padding:0,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(Oo,{size:15,strokeWidth:2,"aria-hidden":"true"})})]}),e.jsxs("div",{style:{minHeight:0,display:"grid",gridTemplateColumns:"300px minmax(0, 1fr)"},children:[e.jsxs("aside",{style:{borderRight:`1px solid ${f.headerBorder}`,display:"grid",gridTemplateRows:"auto minmax(0, 1fr) auto",minHeight:0,background:f.cellBg},children:[e.jsxs("section",{style:{borderBottom:`1px solid ${f.headerBorder}`,padding:12,display:"grid",gap:10},children:[e.jsxs("button",{onClick:()=>we(g=>!g),style:{background:"transparent",border:"none",color:f.textPrimary,cursor:"pointer",display:"flex",alignItems:"center",gap:8,padding:0,fontFamily:f.font,textAlign:"left"},children:[e.jsx(ki,{size:14,strokeWidth:2,color:f.accent,"aria-hidden":"true"}),e.jsx("span",{style:{fontSize:12,fontWeight:800,flex:1},children:"Source"}),t&&e.jsx("span",{style:{fontSize:10,color:f.textMuted},children:ke?"Hide":"Edit"})]}),ke?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, minmax(0, 1fr))",gap:4},children:["paste","upload","path"].map(g=>e.jsx("button",{onClick:()=>R(g),style:{...ie(f),padding:"6px 4px",color:T===g?f.accent:f.textSecondary,borderColor:T===g?f.accent:f.btnBorder,background:T===g?`${f.accent}14`:f.btnBg},children:g==="paste"?"Paste SQL":g==="upload"?"Upload files":"Local path"},g))}),T==="path"&&e.jsx($,{label:"Path",t:f,children:e.jsx("input",{value:E,onChange:g=>{ee(g.target.value),g.target.value.trim()&&oe([])},placeholder:"./queries or ./legacy.sql",style:ve(f)})}),T==="upload"&&e.jsxs($,{label:"Upload SQL files",t:f,children:[e.jsx("input",{type:"file",multiple:!0,accept:".sql,text/sql,text/plain",onChange:g=>void ot(g.target.files),style:ve(f)}),e.jsx("span",{style:{fontSize:11,color:f.textMuted,fontFamily:f.font},children:S.length>0?`${S.length} SQL file(s) ready`:"Choose one or more SQL files."})]}),T==="paste"&&e.jsx($,{label:"Paste SQL",t:f,children:e.jsx("textarea",{value:_,onChange:g=>k(g.target.value),placeholder:`select ...; go
|
|
27
|
-
select ...`,style:{...ve(f),minHeight:t?86:150,resize:"vertical",fontFamily:f.fontMono}})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[e.jsx($,{label:"Domain",t:f,children:e.jsx("input",{value:Z,onChange:g=>pe(g.target.value),placeholder:"auto",style:ve(f)})}),e.jsx($,{label:"Owner",t:f,children:e.jsx("input",{value:A,onChange:g=>U(g.target.value),placeholder:"analytics",style:ve(f)})})]}),e.jsx("button",{onClick:()=>void dt(),disabled:K||!Ce,style:{...je(f),padding:"8px 12px",opacity:K||!Ce?.65:1,cursor:K||!Ce?"not-allowed":"pointer"},children:K?gr(Ie):"Generate DQL drafts"}),e.jsx("div",{style:{fontSize:11,color:f.textMuted,fontFamily:f.font,lineHeight:1.45},children:"Uses dbt, MetricFlow, warehouse catalog, and existing DQL context when available."})]}):e.jsxs("button",{onClick:()=>we(!0),style:{...ie(f),display:"grid",gap:4,textAlign:"left",width:"100%",justifyItems:"start"},children:[e.jsx("span",{style:{fontSize:11,color:f.textSecondary},children:T==="paste"?"Pasted SQL":T==="upload"?"Uploaded files":"Local path"}),e.jsx("span",{style:{maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:f.textMuted,fontFamily:f.fontMono},children:(t==null?void 0:t.inputPath)??(T==="paste"?"pasted.sql":T==="upload"?`${S.length} file(s)`:E||"./queries")})]})]}),e.jsx("section",{style:{minHeight:0,overflow:"auto",padding:12,display:"grid",alignContent:"start",gap:10},children:t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gap:8},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,fontWeight:800,color:f.textPrimary,fontFamily:f.font},children:"Drafts"}),e.jsx(xe,{label:`${t.candidates.length}`,tone:"info",t:f}),re.ready>0&&e.jsx(xe,{label:`${re.ready} ready`,tone:"ok",t:f}),re.attention>0&&e.jsx(xe,{label:`${re.attention} attention`,tone:"warn",t:f})]}),t.candidates.length>6&&e.jsx("input",{value:ye,onChange:g=>Ee(g.target.value),placeholder:"Search drafts, tables, files...",style:ve(f)})]}),De.map(g=>{var y,j,z,F,Se,Q,Pt,ct;const B=g.id===(de==null?void 0:de.id),D=g.warnings??g.lineage.warnings,w=Be[g.id],q=((j=(y=g.preview)==null?void 0:y.result)==null?void 0:j.rowCount)??((Se=(F=(z=g.preview)==null?void 0:z.result)==null?void 0:F.rows)==null?void 0:Se.length),ne=L[g.id]??Ge(g);return e.jsxs("button",{onClick:()=>{M(g.id)},style:{border:`1px solid ${B?f.accent:w?"#f8514955":f.headerBorder}`,borderRadius:8,background:B?`${f.accent}10`:f.appBg,color:f.textPrimary,padding:10,display:"grid",gap:6,textAlign:"left",cursor:"pointer",minWidth:0},children:[e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{style:{minWidth:0,flex:1,fontSize:12,fontWeight:800,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:g.name}),e.jsx(xe,{label:xr(ne.status),tone:yr(ne.status),t:f})]}),e.jsxs("span",{style:{fontSize:10,color:f.textMuted,fontFamily:f.fontMono,overflowWrap:"anywhere"},children:[g.lineage.statementIndex,"/",g.lineage.totalStatements," · ",g.sourcePath]}),e.jsxs("span",{style:{display:"flex",gap:5,flexWrap:"wrap"},children:[e.jsx(xe,{label:((Q=g.draftSave)==null?void 0:Q.status)==="saved"||It(g.savedPath)?"draft saved":g.reviewStatus,tone:g.reviewStatus==="rejected"?"warn":"info",t:f}),e.jsx(xe,{label:((Pt=g.validation)==null?void 0:Pt.valid)===!1?"fix":"valid",tone:((ct=g.validation)==null?void 0:ct.valid)===!1?"warn":"ok",t:f}),typeof q=="number"&&e.jsx(xe,{label:`${q} rows`,tone:"ok",t:f}),D.length>0&&e.jsx(xe,{label:`${D.length} warning`,tone:"warn",t:f})]}),(w||ne.message)&&e.jsx("span",{style:{fontSize:11,color:w?"#f85149":f.textMuted,lineHeight:1.35,overflowWrap:"anywhere"},children:w??ne.message})]},g.id)}),!G&&!ye.trim()&&Te.length>10&&e.jsxs("button",{onClick:()=>Ne(!0),style:ie(f),children:["Show all ",Te.length," drafts"]}),!t.candidates.some(qt)&&re.ready>0&&e.jsx("button",{onClick:()=>void Ze(),disabled:X,style:je(f),children:X?"Saving...":"Save valid blocks"})]}):e.jsx("div",{style:{fontSize:12,color:f.textMuted,lineHeight:1.5},children:"Paste SQL, upload files, or choose a local path. Analysis stays in this session until you save a block."})}),e.jsxs("details",{open:H,onToggle:g=>he(g.currentTarget.open),style:{borderTop:`1px solid ${f.headerBorder}`,padding:12,display:"grid",gap:8},children:[e.jsxs("summary",{style:{cursor:"pointer",color:f.textSecondary,fontSize:11,fontWeight:800,fontFamily:f.font},children:["Import history",n.length>0?` (${n.length})`:""]}),e.jsxs("div",{style:{display:"grid",gap:8,marginTop:8},children:[e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsx("button",{onClick:()=>void d(),style:ie(f),children:"Refresh"}),n.length>0&&e.jsx("button",{onClick:()=>void Ve(),style:ie(f),children:"Clear"})]}),r?e.jsx("div",{style:{fontSize:12,color:f.textMuted},children:"Loading..."}):n.length===0?e.jsx("div",{style:{fontSize:12,color:f.textMuted},children:"No saved import sessions."}):e.jsx("div",{style:{display:"grid",gap:6,maxHeight:140,overflow:"auto"},children:n.slice(0,6).map(g=>e.jsxs("div",{style:{border:`1px solid ${(t==null?void 0:t.id)===g.id?f.accent:f.btnBorder}`,borderRadius:8,background:(t==null?void 0:t.id)===g.id?`${f.accent}10`:f.btnBg,display:"grid",gridTemplateColumns:"minmax(0, 1fr) auto",overflow:"hidden"},children:[e.jsxs("button",{onClick:()=>void He(g.id),style:{background:"transparent",border:"none",color:f.textSecondary,cursor:"pointer",fontFamily:f.font,padding:"8px 9px",textAlign:"left",display:"grid",gap:3,minWidth:0},children:[e.jsxs("span",{style:{fontSize:11},children:[g.candidateCount," drafts · ",g.savedCount," certified"]}),e.jsx("span",{style:{fontSize:10,color:f.textMuted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:g.inputPath})]}),e.jsx("button",{onClick:()=>void nt(g.id),title:"Delete local import session",style:{background:"transparent",border:"none",borderLeft:`1px solid ${f.headerBorder}`,color:f.textMuted,cursor:"pointer",fontFamily:f.font,padding:"0 8px",fontSize:11,fontWeight:700},children:"Delete"})]},g.id))})]})]})]}),e.jsxs("main",{style:{minWidth:0,minHeight:0,overflow:"auto",padding:20,background:f.appBg},children:[te&&e.jsx("div",{role:"alert",style:{padding:"10px 12px",color:"#f85149",background:"#f8514914",border:"1px solid #f8514933",borderRadius:8,marginBottom:12,fontSize:12},children:te}),!t||!de?e.jsx(jr,{t:f}):e.jsx(Sr,{session:t,candidate:de,loading:K,onCandidateUpdated:Me,onRun:it,onSave:Xe,onReject:Je,onReviewInEditor:p,runError:Be[de.id]??null,themeMode:l,t:f})]})]}),ce&&e.jsx(vr,{t:f,busy:K,title:ce.kind==="all"?"Clear import history?":"Delete import preview?",message:ce.kind==="all"?`This removes ${n.length} local import preview${n.length===1?"":"s"} from .dql/imports. Saved blocks stay in the project.`:"This removes the selected local import preview from .dql/imports. Saved blocks stay in the project.",confirmLabel:ce.kind==="all"?"Clear history":"Delete preview",onCancel:()=>I(null),onConfirm:()=>void Ye()})]})}function vr({title:t,message:n,confirmLabel:r,busy:s,onCancel:i,onConfirm:d,t:p}){return e.jsx("div",{style:{position:"absolute",inset:0,background:"rgba(0, 0, 0, 0.22)",display:"flex",alignItems:"center",justifyContent:"center",padding:20,zIndex:20},children:e.jsxs("div",{style:{width:"min(420px, 92vw)",background:p.cellBg,color:p.textPrimary,border:`1px solid ${p.headerBorder}`,borderRadius:8,boxShadow:"0 18px 48px rgba(0, 0, 0, 0.30)",padding:16,display:"grid",gap:12},children:[e.jsx("div",{style:{fontSize:15,fontWeight:800,fontFamily:p.font},children:t}),e.jsx("div",{style:{fontSize:12,color:p.textMuted,lineHeight:1.5,fontFamily:p.font},children:n}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[e.jsx("button",{onClick:i,disabled:s,style:ie(p),children:"Cancel"}),e.jsx("button",{onClick:d,disabled:s,style:{...je(p),opacity:s?.65:1},children:s?"Working...":r})]})]})})}function Sr({session:t,candidate:n,loading:r,onCandidateUpdated:s,onRun:i,onSave:d,onReject:p,onReviewInEditor:m,runError:x,themeMode:P,t:l}){var We,dt,He,nt,Ve,Ye,Me,it,Xe,Ze,Je,ot,g,B,D,w,q,ne;const[f,h]=c.useState(n.name),[T,R]=c.useState(n.domain),[E,ee]=c.useState(n.owner),[_,k]=c.useState(n.description),[S,oe]=c.useState(n.tags.join(", ")),[Z,pe]=c.useState((n.terms??[]).join(", ")),[A,U]=c.useState(n.pattern??""),[Y,M]=c.useState(n.grain??""),[K,W]=c.useState((n.entities??[]).join(", ")),[X,fe]=c.useState((n.outputs??[]).join(", ")),[te,N]=c.useState((n.dimensions??[]).join(", ")),[ce,I]=c.useState((n.allowedFilters??[]).join(", ")),[H,he]=c.useState((n.sourceSystems??[]).join(", ")),[ke,we]=c.useState((n.replacementFor??[]).join(", ")),[ye,Ee]=c.useState(n.reviewCadence??"monthly"),[G,Ne]=c.useState(n.sql),[Be,se]=c.useState(null),[Ie,a]=c.useState(null),[L,J]=c.useState(!1);c.useEffect(()=>{h(n.name),R(n.domain),ee(n.owner),k(n.description),oe(n.tags.join(", ")),pe((n.terms??[]).join(", ")),U(n.pattern??""),M(n.grain??""),W((n.entities??[]).join(", ")),fe((n.outputs??[]).join(", ")),N((n.dimensions??[]).join(", ")),I((n.allowedFilters??[]).join(", ")),he((n.sourceSystems??[]).join(", ")),we((n.replacementFor??[]).join(", ")),Ee(n.reviewCadence??"monthly"),Ne(n.sql),a(null),J(!1)},[n.id,n.name,n.domain,n.owner,n.description,n.tags,n.terms,n.pattern,n.grain,n.entities,n.outputs,n.dimensions,n.allowedFilters,n.sourceSystems,n.replacementFor,n.reviewCadence,n.sql]);const de=async()=>{a(null);try{const y={name:f,domain:T,owner:E,description:_,tags:S.split(",").map(z=>z.trim()).filter(Boolean),terms:Z.split(",").map(z=>z.trim()).filter(Boolean),pattern:A,grain:Y,entities:K.split(",").map(z=>z.trim()).filter(Boolean),outputs:X.split(",").map(z=>z.trim()).filter(Boolean),dimensions:te.split(",").map(z=>z.trim()).filter(Boolean),allowedFilters:ce.split(",").map(z=>z.trim()).filter(Boolean),sourceSystems:H.split(",").map(z=>z.trim()).filter(Boolean),replacementFor:ke.split(",").map(z=>z.trim()).filter(Boolean),reviewCadence:ye,sql:G,llmContext:n.llmContext},j=qt(n)?await O.updateDqlGenerationCandidate(t.id,n.id,y):await O.updateBlockStudioImportCandidate(t.id,n.id,y);s(j)}catch(y){a((y==null?void 0:y.message)??"Could not update candidate.")}},Te=async y=>{se(y),a(null);try{const j=await O.assistBlockStudioImportCandidate(t.id,n.id,y);s(j)}catch(j){a((j==null?void 0:j.message)??"AI assist failed.")}finally{se(null)}},De=n.warnings??n.lineage.warnings,le=ve(l),re=((dt=(We=n.preview)==null?void 0:We.result)==null?void 0:dt.rowCount)??((Ve=(nt=(He=n.preview)==null?void 0:He.result)==null?void 0:nt.rows)==null?void 0:Ve.length),Ae=((Ye=n.draftSave)==null?void 0:Ye.path)??(It(n.savedPath)?n.savedPath:void 0),_e=n.recommendedAction==="reuse_existing"||((Me=n.draftSave)==null?void 0:Me.status)==="skipped",Ce=n.lineage.sourceTables.length+(((it=n.evidence)==null?void 0:it.length)??0)+n.lineage.parameters.length+De.length;return e.jsxs("div",{style:{display:"grid",gap:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:10,flexWrap:"wrap"},children:[e.jsxs("div",{style:{minWidth:0,flex:1},children:[e.jsx("div",{style:{fontSize:18,fontWeight:800,color:l.textPrimary},children:n.name}),e.jsxs("div",{style:{fontSize:11,color:l.textMuted,fontFamily:l.fontMono,marginTop:3},children:[n.sourcePath," · statement ",n.lineage.statementIndex,"/",n.lineage.totalStatements]})]}),e.jsx("button",{onClick:()=>void i(n),disabled:r,style:ie(l),children:r?"Running...":"Preview"}),e.jsx("button",{onClick:()=>J(y=>!y),style:L?je(l):ie(l),children:L?"Hide context":`Show context${Ce>0?` (${Ce})`:""}`}),e.jsx("button",{onClick:()=>m(n),style:je(l),children:"Edit full DQL"}),e.jsx("button",{onClick:()=>void d(n),disabled:r||n.reviewStatus==="saved"||_e,style:je(l),children:_e?"Reuse existing":n.reviewStatus==="saved"?"Certified":"Save block"})]}),Ie&&e.jsx("div",{role:"alert",style:{fontSize:12,color:"#f85149",background:"#f8514914",borderRadius:8,padding:10},children:Ie}),x&&e.jsxs("div",{role:"alert",style:{fontSize:12,color:"#f85149",background:"#f8514914",border:"1px solid #f8514933",borderRadius:8,padding:10,lineHeight:1.45,overflowWrap:"anywhere"},children:["Preview failed: ",x]}),e.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[e.jsx(xe,{label:((Xe=n.draftSave)==null?void 0:Xe.status)==="skipped"?"reuse recommended":((Ze=n.draftSave)==null?void 0:Ze.status)==="saved"||Ae?"draft saved":n.reviewStatus,tone:n.reviewStatus==="rejected"?"warn":((Je=n.draftSave)==null?void 0:Je.status)==="skipped"?"ok":"info",t:l}),e.jsx(xe,{label:`${Math.round(n.confidence*100)}% confidence`,tone:"info",t:l}),e.jsx(xe,{label:((ot=n.validation)==null?void 0:ot.valid)===!1?"needs fixes":"valid",tone:((g=n.validation)==null?void 0:g.valid)===!1?"warn":"ok",t:l}),typeof re=="number"&&e.jsx(xe,{label:`${re} rows`,tone:"ok",t:l})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:L?"minmax(0, 1fr) minmax(320px, 380px)":"minmax(0, 1fr)",gap:12,alignItems:"start"},children:[e.jsxs("div",{style:{display:"grid",gap:12},children:[e.jsxs(ue,{title:"Review details",t:l,children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[e.jsx($,{label:"Name",t:l,children:e.jsx("input",{value:f,onChange:y=>h(y.target.value),style:le})}),e.jsx($,{label:"Domain",t:l,children:e.jsx("input",{value:T,onChange:y=>R(y.target.value),style:le})}),e.jsx($,{label:"Owner",t:l,children:e.jsx("input",{value:E,onChange:y=>ee(y.target.value),style:le})}),e.jsx($,{label:"Tags",t:l,children:e.jsx("textarea",{value:S,onChange:y=>oe(y.target.value),style:{...le,minHeight:58,resize:"vertical"}})})]}),e.jsx($,{label:"Business description",t:l,children:e.jsx("textarea",{value:_,onChange:y=>k(y.target.value),style:{...le,minHeight:70,resize:"vertical"}})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(140px, 1fr))",gap:8},children:[e.jsx($,{label:"Pattern",t:l,children:e.jsx("select",{value:A,onChange:y=>U(y.target.value),style:le,children:["custom","metric_wrapper","entity_profile","entity_rollup","ranking","trend","bridge","drilldown","replacement"].map(y=>e.jsx("option",{value:y,children:y},y))})}),e.jsx($,{label:"Grain",t:l,children:e.jsx("input",{value:Y,onChange:y=>M(y.target.value),style:le})}),e.jsx($,{label:"Review cadence",t:l,children:e.jsx("select",{value:ye,onChange:y=>Ee(y.target.value),style:le,children:["weekly","monthly","quarterly","semiannual","annual"].map(y=>e.jsx("option",{value:y,children:y},y))})})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[e.jsx($,{label:"Entities",t:l,children:e.jsx("input",{value:K,onChange:y=>W(y.target.value),style:le})}),e.jsx($,{label:"Outputs",t:l,children:e.jsx("input",{value:X,onChange:y=>fe(y.target.value),style:le})}),e.jsx($,{label:"Dimensions",t:l,children:e.jsx("input",{value:te,onChange:y=>N(y.target.value),style:le})}),e.jsx($,{label:"Allowed filters",t:l,children:e.jsx("input",{value:ce,onChange:y=>I(y.target.value),style:le})}),e.jsx($,{label:"Source systems",t:l,children:e.jsx("input",{value:H,onChange:y=>he(y.target.value),style:le})}),e.jsx($,{label:"Terms",t:l,children:e.jsx("input",{value:Z,onChange:y=>pe(y.target.value),style:le})})]}),e.jsx($,{label:"Replaces",t:l,children:e.jsx("input",{value:ke,onChange:y=>we(y.target.value),style:le})}),e.jsx("button",{onClick:()=>void de(),style:{...je(l),justifySelf:"start"},children:"Apply edits"})]}),n.preview&&e.jsxs(ue,{title:"Preview Results",t:l,children:[e.jsxs("div",{style:{fontSize:12,color:l.textMuted,lineHeight:1.45},children:["Query ran successfully",typeof re=="number"?` and returned ${re} rows`:"","."]}),e.jsx("div",{style:{maxHeight:320,overflow:"auto",border:`1px solid ${l.headerBorder}`,borderRadius:8},children:e.jsx(vi,{result:n.preview.result,themeMode:P})})]}),e.jsxs("details",{style:jt(l),children:[e.jsx("summary",{style:kt(l),children:"Original SQL"}),e.jsx("textarea",{value:G,onChange:y=>Ne(y.target.value),style:{...le,minHeight:210,fontFamily:l.fontMono,resize:"vertical",marginTop:10}})]}),e.jsxs("details",{style:jt(l),children:[e.jsx("summary",{style:kt(l),children:"Draft DQL block"}),e.jsx("pre",{style:{margin:"10px 0 0",whiteSpace:"pre-wrap",fontSize:11,lineHeight:1.45,color:l.textSecondary,fontFamily:l.fontMono},children:n.dqlSource})]})]}),L&&e.jsxs("div",{style:{display:"grid",gap:12},children:[(((B=n.similarityMatches)==null?void 0:B.length)||((D=n.draftSave)==null?void 0:D.status)==="skipped")&&e.jsx(ue,{title:"Reuse recommendation",t:l,children:e.jsxs("div",{style:{display:"grid",gap:8},children:[e.jsx(st,{label:"Action",value:n.recommendedAction??"create_new",t:l}),((w=n.draftSave)==null?void 0:w.reason)&&e.jsx("div",{style:{fontSize:12,color:l.textMuted,lineHeight:1.4},children:n.draftSave.reason}),(n.similarityMatches??[]).slice(0,3).map((y,j)=>e.jsxs("div",{style:{border:`1px solid ${l.headerBorder}`,borderRadius:7,padding:8,background:l.appBg},children:[e.jsx("div",{style:{fontSize:11,fontWeight:800,color:l.textSecondary,overflowWrap:"anywhere"},children:y.name}),e.jsxs("div",{style:{fontSize:10,color:l.textMuted,marginTop:3},children:[y.kind," · ",Math.round(y.score*100),"% · ",y.recommendedAction]}),e.jsx("div",{style:{fontSize:11,color:l.textMuted,lineHeight:1.35,marginTop:5},children:y.reason})]},`${y.objectKey??y.name}-${j}`))]})}),(((q=n.parameterDecisions)==null?void 0:q.length)||((ne=n.filterBindings)==null?void 0:ne.length))&&e.jsx(ue,{title:"Parameter contract",t:l,children:e.jsxs("div",{style:{display:"grid",gap:8},children:[(n.parameterDecisions??[]).slice(0,8).map(y=>e.jsxs("div",{style:{border:`1px solid ${l.headerBorder}`,borderRadius:7,padding:8,background:l.appBg},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:11,fontWeight:800,color:l.textSecondary},children:y.name}),e.jsx("span",{style:{fontSize:10,color:l.textMuted},children:y.policy})]}),e.jsxs("div",{style:{fontSize:11,color:l.textMuted,lineHeight:1.35,marginTop:5},children:[y.sourceExpression," = ",String(y.value)]}),e.jsx("div",{style:{fontSize:11,color:l.textMuted,lineHeight:1.35,marginTop:5},children:y.reason})]},y.name)),(n.filterBindings??[]).length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:(n.filterBindings??[]).map(y=>e.jsx(xe,{label:`${y.filter} -> ${y.binding}`,tone:"info",t:l},y.filter))})]})}),e.jsxs(ue,{title:"Grounding",t:l,children:[e.jsxs("div",{style:{display:"grid",gap:5},children:[e.jsx("div",{style:{fontSize:10,color:l.textMuted,textTransform:"uppercase",fontWeight:800},children:"Source tables"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:n.lineage.sourceTables.length?n.lineage.sourceTables.map(y=>e.jsx(xe,{label:y,tone:"info",t:l},y)):e.jsx("span",{style:{fontSize:12,color:l.textMuted},children:"None detected"})})]}),(n.evidence??[]).length>0&&e.jsxs("div",{style:{display:"grid",gap:6},children:[e.jsx("div",{style:{fontSize:10,color:l.textMuted,textTransform:"uppercase",fontWeight:800},children:"Context used"}),(n.evidence??[]).slice(0,5).map((y,j)=>e.jsxs("div",{style:{border:`1px solid ${l.headerBorder}`,borderRadius:7,padding:8,background:l.appBg},children:[e.jsx("div",{style:{fontSize:11,fontWeight:800,color:l.textSecondary,overflowWrap:"anywhere"},children:y.name}),e.jsxs("div",{style:{fontSize:10,color:l.textMuted,marginTop:3},children:[y.kind,y.reason?` · ${y.reason}`:""]}),y.description&&e.jsx("div",{style:{fontSize:11,color:l.textMuted,lineHeight:1.35,marginTop:5},children:y.description})]},`${y.objectKey??y.name}-${j}`))]}),e.jsxs("div",{style:{display:"grid",gap:5},children:[e.jsx("div",{style:{fontSize:10,color:l.textMuted,textTransform:"uppercase",fontWeight:800},children:"Parameters"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:n.lineage.parameters.length?n.lineage.parameters.map(y=>e.jsx(xe,{label:y,tone:"warn",t:l},y)):e.jsx("span",{style:{fontSize:12,color:l.textMuted},children:"None detected"})})]}),De.length>0&&e.jsxs("div",{style:{display:"grid",gap:6},children:[e.jsx("div",{style:{fontSize:10,color:"#d29922",textTransform:"uppercase",fontWeight:800},children:"Warnings"}),De.map((y,j)=>e.jsx("div",{style:{fontSize:12,color:"#d29922",lineHeight:1.4},children:y},j))]})]}),e.jsxs("details",{style:jt(l),children:[e.jsx("summary",{style:kt(l),children:"Generation audit"}),e.jsxs("div",{style:{display:"grid",gap:8,marginTop:10},children:[e.jsx(st,{label:"Method",value:n.generationMode==="ai"?`AI-assisted local generation (${n.generationProvider??"configured provider"})`:"Deterministic local generation",t:l}),Ae&&e.jsx(st,{label:"Draft path",value:Ae,t:l}),e.jsx(st,{label:"Default test",value:"assert row_count > 0",t:l}),e.jsx(st,{label:"Split strategy",value:n.splitStrategy??"semicolon-go",t:l}),n.llmContext&&e.jsx(st,{label:"Agent use",value:n.llmContext,t:l}),(n.conversionNotes??[]).map((y,j)=>e.jsx("div",{style:{fontSize:12,color:l.textMuted,lineHeight:1.4},children:y},j))]})]}),e.jsxs("details",{style:jt(l),children:[e.jsx("summary",{style:kt(l),children:"AI refine tools"}),e.jsxs("div",{style:{display:"grid",gap:10,marginTop:10},children:[e.jsx("div",{style:{fontSize:12,color:l.textMuted,lineHeight:1.45},children:"Use these only when the generated draft needs a targeted improvement before certification."}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:[["explain","Explain"],["fix-validation","Fix validation"],["infer-chart","Infer chart"],["propose-tests","Propose tests"]].map(([y,j])=>e.jsx("button",{onClick:()=>void Te(y),disabled:!!Be,style:ie(l),children:Be===y?"Working...":j},y))}),(n.aiAssistance??[]).length>0&&e.jsx("div",{style:{display:"grid",gap:8},children:(n.aiAssistance??[]).slice().reverse().map((y,j)=>e.jsxs("div",{style:{border:`1px solid ${l.headerBorder}`,borderRadius:8,padding:9,background:l.appBg},children:[e.jsxs("div",{style:{fontSize:10,color:l.textMuted,fontWeight:800,textTransform:"uppercase"},children:[y.action," · ",y.status]}),e.jsx("div",{style:{fontSize:12,color:l.textSecondary,lineHeight:1.45,marginTop:5},children:y.summary})]},`${y.createdAt}-${j}`))})]})]}),e.jsx("button",{onClick:()=>void p(n),disabled:n.reviewStatus==="rejected",style:{...ie(l),justifySelf:"start"},children:n.reviewStatus==="rejected"?"Rejected":"Reject draft"})]})]})]})}function nn({index:t,active:n,complete:r,title:s,detail:i,t:d}){const p=r?"#2ea043":n?d.accent:d.textMuted;return e.jsxs("div",{style:{border:`1px solid ${n?d.accent:d.headerBorder}`,borderRadius:8,padding:"9px 10px",display:"grid",gridTemplateColumns:"24px minmax(0, 1fr)",gap:8,alignItems:"center",background:n?`${d.accent}10`:d.cellBg},children:[e.jsx("span",{style:{width:22,height:22,borderRadius:999,display:"inline-grid",placeItems:"center",background:`${p}18`,color:p,fontSize:11,fontWeight:800,fontFamily:d.font},children:r?"✓":t}),e.jsxs("span",{style:{minWidth:0},children:[e.jsx("span",{style:{display:"block",fontSize:12,fontWeight:700,color:d.textPrimary,fontFamily:d.font},children:s}),e.jsx("span",{style:{display:"block",fontSize:10,color:d.textMuted,fontFamily:d.font,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i})]})]})}function jr({t}){const n=[["1","Add SQL","Paste SQL, upload files, or point to an enterprise SQL folder."],["2","Generate drafts","DQL analyzes statements, project metadata, tables, and business context."],["3","Review and certify","Preview results, edit metadata, then certify the governed block."]];return e.jsxs("div",{style:{display:"grid",gap:12},children:[e.jsx(at,{message:"Add SQL to analyze DQL candidates without creating block files."}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, minmax(0, 1fr))",gap:10},children:n.map(([r,s,i])=>e.jsxs("div",{style:{border:`1px solid ${t.headerBorder}`,borderRadius:8,background:t.appBg,padding:12,display:"grid",gap:6},children:[e.jsx("span",{style:{width:22,height:22,borderRadius:999,display:"inline-grid",placeItems:"center",background:`${t.accent}18`,color:t.accent,fontSize:11,fontWeight:800,fontFamily:t.font},children:r}),e.jsx("span",{style:{fontSize:12,fontWeight:700,color:t.textPrimary,fontFamily:t.font},children:s}),e.jsx("span",{style:{fontSize:11,color:t.textMuted,fontFamily:t.font,lineHeight:1.4},children:i})]},s))})]})}function $({label:t,children:n,t:r}){return e.jsxs("label",{style:{display:"grid",gap:5},children:[e.jsx("span",{style:{fontSize:10,fontWeight:700,color:r.textMuted,letterSpacing:"0.05em",textTransform:"uppercase",fontFamily:r.font},children:t}),n]})}function ue({title:t,hint:n,children:r,t:s}){return e.jsxs("section",{style:{display:"grid",gridTemplateColumns:"176px minmax(0, 1fr)",gap:24,padding:"18px 0",borderBottom:"1px solid var(--border-subtle)"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:12.5,fontWeight:650,color:s.textPrimary,fontFamily:s.font},children:t}),n?e.jsx("div",{style:{fontSize:11,color:s.textMuted,lineHeight:1.45,marginTop:3,fontFamily:s.font},children:n}):null]}),e.jsx("div",{style:{minWidth:0,display:"grid",gap:10,alignContent:"start"},children:r})]})}function st({label:t,value:n,t:r}){return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"110px minmax(0, 1fr)",gap:8,fontSize:12,fontFamily:r.font},children:[e.jsx("span",{style:{color:r.textMuted},children:t}),e.jsx("span",{title:n,style:{color:r.textSecondary,overflowWrap:"anywhere"},children:n})]})}function xe({label:t,tone:n,t:r}){const s=n==="ok"?"#2ea043":n==="warn"?"#d29922":r.accent;return e.jsx("span",{style:{fontSize:10,fontWeight:700,color:s,background:`${s}18`,borderRadius:999,padding:"3px 7px",fontFamily:r.font,textTransform:"uppercase"},children:t})}function jt(t){return{border:`1px solid ${t.headerBorder}`,borderRadius:8,background:t.cellBg,padding:12,color:t.textPrimary,fontFamily:t.font}}function kt(t){return{cursor:"pointer",color:t.textSecondary,fontSize:11,fontWeight:800,textTransform:"uppercase",letterSpacing:"0.05em",fontFamily:t.font}}function ve(t){return{background:t.inputBg,border:`1px solid ${t.inputBorder}`,borderRadius:6,color:t.textPrimary,fontSize:12,fontFamily:t.font,padding:"8px 10px",outline:"none",minWidth:0}}function un(t){return{...ve(t),boxSizing:"border-box",fontSize:11.5,minHeight:32,padding:"6px 8px"}}function ie(t){return{background:t.btnBg,border:`1px solid ${t.btnBorder}`,borderRadius:6,color:t.textSecondary,cursor:"pointer",fontSize:11,fontFamily:t.font,padding:"6px 10px"}}function je(t){return{...ie(t),background:`${t.accent}18`,border:`1px solid ${t.accent}`,color:t.accent,fontWeight:700}}function kr({blockName:t,loading:n,detail:r,graph:s,paths:i,onSelectNode:d,onOpenInspector:p,t:m}){if(!t)return e.jsx(at,{message:"Lineage will appear once the block has a name."});if(n)return e.jsx(at,{message:"Loading block lineage…"});if(!(r!=null&&r.node))return e.jsxs("div",{style:{padding:12,display:"grid",gap:12},children:[e.jsx("div",{style:{fontSize:12,color:m.textMuted,fontFamily:m.font},children:"No lineage node was found for this block yet. Save the block to compile and refresh its focused lineage automatically."}),e.jsx("div",{children:e.jsx("button",{onClick:p,style:{background:m.btnBg,border:`1px solid ${m.btnBorder}`,borderRadius:6,color:m.textPrimary,cursor:"pointer",fontSize:11,fontFamily:m.font,padding:"6px 10px"},children:"Open Focused Lineage"})})]});const x=`block:${t}`;return e.jsxs("div",{style:{padding:12,display:"grid",gap:12,overflowY:"auto"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:12,fontWeight:700,color:m.textPrimary,fontFamily:m.font},children:r.node.name}),e.jsx("div",{style:{fontSize:11,color:m.textMuted,fontFamily:m.font},children:r.node.domain?`Domain: ${r.node.domain}`:"Block lineage focus"})]}),e.jsx("div",{style:{flex:1}}),e.jsx("button",{onClick:p,style:{background:m.btnBg,border:`1px solid ${m.btnBorder}`,borderRadius:6,color:m.textPrimary,cursor:"pointer",fontSize:11,fontFamily:m.font,padding:"6px 10px"},children:"Open Focused Lineage"})]}),(i==null?void 0:i.layerSummary)&&e.jsx(Io,{layerSummary:i.layerSummary,t:m}),s&&s.nodes.length>0&&e.jsx(Lo,{nodes:s.nodes,edges:s.edges,focalNodeId:x,height:360,onNodeClick:d,layoutMode:"flow"}),i&&(i.upstreamPaths.length>0||i.downstreamPaths.length>0)&&e.jsxs("div",{style:{display:"grid",gap:10},children:[i.upstreamPaths.length>0&&e.jsx(oi,{title:"Source to Block",paths:i.upstreamPaths,onNodeClick:d,focalNodeId:x,t:m}),i.downstreamPaths.length>0&&e.jsx(oi,{title:"Block to Consumption",paths:i.downstreamPaths,onNodeClick:d,focalNodeId:x,t:m})]})]})}function wr({metadata:t,draftMetadata:n,onChange:r,t:s}){const i={width:"100%",background:s.inputBg,border:`1px solid ${s.inputBorder}`,borderRadius:6,color:s.textPrimary,fontSize:12,fontFamily:s.font,padding:"8px 10px",outline:"none"},d={name:(n==null?void 0:n.name)||(t==null?void 0:t.name)||"",domain:(n==null?void 0:n.domain)||(t==null?void 0:t.domain)||"uncategorized",folderPath:(t==null?void 0:t.folderPath)||"",description:(n==null?void 0:n.description)||(t==null?void 0:t.description)||"",owner:(n==null?void 0:n.owner)||(t==null?void 0:t.owner)||"",tags:(n==null?void 0:n.tags)||(t==null?void 0:t.tags)||[]};return e.jsxs("div",{style:{display:"grid",gap:10,padding:12},children:[e.jsx("input",{value:d.name,onChange:p=>r({name:p.target.value}),placeholder:"Block name",style:i}),e.jsx("input",{value:d.domain,onChange:p=>r({domain:p.target.value}),placeholder:"Domain",style:i}),e.jsx("input",{value:d.folderPath,onChange:p=>r({folderPath:p.target.value}),placeholder:"Folder (optional), e.g. executive/monthly",style:{...i,fontFamily:s.fontMono}}),e.jsx("input",{value:d.owner,onChange:p=>r({owner:p.target.value}),placeholder:"Owner",style:i}),e.jsx("input",{value:d.description,onChange:p=>r({description:p.target.value}),placeholder:"Description",style:i}),e.jsx(bi,{values:d.tags,onChange:p=>r({tags:p}),placeholder:"Tags",style:i})]})}function Cr({parameters:t,values:n,onChange:r,onReset:s,onRun:i,running:d,t:p}){return t.length===0?e.jsx(at,{message:"This block has no runtime parameters. Add typed params in DQL Source when scope should be configurable."}):e.jsxs("div",{style:{padding:14,display:"grid",gap:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontSize:13,fontWeight:800,color:p.textPrimary},children:"Test parameter values"}),e.jsx("div",{style:{fontSize:11,color:p.textMuted,marginTop:3},children:"These values affect only the preview. Save defaults in the block definition."})]}),e.jsx("button",{type:"button",onClick:i,disabled:d,style:je(p),children:d?"Running…":"Run preview"})]}),e.jsx(Ao,{parameters:t,values:n,onChange:r,onReset:s,t:p,includeNonRuntime:!0,card:!0})]})}function Br({values:t,t:n}){return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:t.map(r=>e.jsxs("span",{style:{fontSize:10,color:n.textSecondary,background:n.appBg,border:`1px solid ${n.cellBorder}`,borderRadius:999,padding:"4px 7px"},children:[r.name," = ",Array.isArray(r.value)?r.value.join(", "):String(r.value)," ",e.jsxs("span",{style:{color:n.textMuted},children:["(",r.source,")"]})]},r.name))})}function at({message:t}){const n=zt[Dt(r=>r.themeMode)];return e.jsx("div",{style:{padding:16,fontSize:12,color:n.textMuted},children:t})}function Tr({elapsedMs:t}){const n=zt[Dt(r=>r.themeMode)];return e.jsx("div",{style:{padding:12},children:e.jsxs("div",{style:{display:"grid",gap:8,border:`1px solid ${n.headerBorder}`,borderRadius:8,background:n.cellBg,padding:12,color:n.textPrimary,fontFamily:n.font},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,fontWeight:700},children:[e.jsx(lt,{size:16,strokeWidth:2,color:n.accent,"aria-hidden":"true"}),e.jsx("span",{children:"Running preview"}),e.jsx("span",{style:{marginLeft:"auto",color:n.textMuted,fontSize:11,fontWeight:500},children:Ir(t)})]}),e.jsx("div",{style:{color:n.textMuted,fontSize:12,lineHeight:1.45},children:"Executing the block query against the active connection."})]})})}function Mr({message:t}){const n=zt[Dt(r=>r.themeMode)];return e.jsx("div",{style:{padding:12},children:e.jsxs("div",{style:{display:"grid",gap:8,border:"1px solid rgba(248, 81, 73, 0.35)",borderRadius:8,background:"rgba(248, 81, 73, 0.08)",color:n.textPrimary,fontFamily:n.font,padding:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,fontWeight:700,color:"#f85149"},children:[e.jsx(Ht,{size:16,strokeWidth:2,"aria-hidden":"true"}),e.jsx("span",{children:"Preview failed"})]}),e.jsx("div",{style:{color:n.textPrimary,fontSize:12,lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:t})]})})}function Ir(t){const n=Math.max(0,Math.floor(t/1e3));if(n<60)return`${n}s`;const r=Math.floor(n/60),s=n%60;return`${r}m ${s}s`}const ci={draft:"#8b949e",review:"#d29922",certified:"#3fb950",deprecated:"#f85149"},Dr={draft:[],review:["draft"],certified:["deprecated"],deprecated:["draft"]};function zr({currentStatus:t,blockPath:n,onStatusChanged:r,t:s}){const[i,d]=c.useState(!1),p=Dr[t]??[],m=async x=>{if(n){d(!0);try{const P=await O.updateBlockStatus(n,x);P.ok&&P.status&&r(P.status)}finally{d(!1)}}};return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"10px 12px",background:s.pillBg,borderRadius:8},children:[e.jsx("span",{style:{fontSize:11,color:s.textMuted,fontFamily:s.font},children:"Status:"}),e.jsx("span",{style:{fontSize:11,fontWeight:600,color:ci[t]??s.textMuted,background:`${ci[t]??s.textMuted}18`,padding:"2px 8px",borderRadius:4,textTransform:"uppercase",letterSpacing:"0.04em",fontFamily:s.font},children:t}),e.jsx("span",{style:{flex:1}}),p.map(x=>e.jsx("button",{onClick:()=>void m(x),disabled:i,style:{background:x==="certified"?"#3fb950":x==="deprecated"?"#f85149":s.btnBg,border:`1px solid ${x==="certified"?"#3fb950":x==="deprecated"?"#f85149":s.btnBorder}`,borderRadius:4,color:x==="certified"||x==="deprecated"?"#fff":s.textSecondary,cursor:i?"not-allowed":"pointer",fontSize:10,fontWeight:600,fontFamily:s.font,padding:"3px 10px",textTransform:"capitalize",opacity:i?.5:1},children:i?"...":x==="certified"?"Certify":x==="deprecated"?"Deprecate":`Move to ${x}`},x))]})}function Pr({result:t,t:n}){var m,x,P;const r=t.checklist,s=r?[["Metadata",r.metadata],["Validation",r.validation],["Run",r.run],["Tests",r.tests],["Chart",r.chart],["Lineage",r.lineage]]:[],i=Array.from(new Set(((m=t.blockers)!=null&&m.length?t.blockers:(r==null?void 0:r.blockers)??[]).map(Rr))),d=Lr(i),p=t.pending?n.accent:t.ok?"#3fb950":"#d29922";return e.jsxs("div",{style:{margin:"12px 12px 0",border:`1px solid ${p}55`,borderRadius:8,background:`${p}0d`,padding:12,display:"grid",gap:10},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontSize:12,fontWeight:800,color:p,fontFamily:n.font},children:t.pending?"Certification running":t.ok?"Block certified":"Unable to certify"}),(r==null?void 0:r.checkedAt)&&e.jsx("span",{style:{fontSize:10,color:n.textMuted,fontFamily:n.fontMono},children:r.checkedAt})]}),e.jsx("div",{style:{fontSize:12,color:n.textMuted,lineHeight:1.45},children:t.pending?"The exact draft is saved and the certification gates are running in the background. You may switch pages or continue other work.":t.ok?r!=null&&r.tests?"Latest edits were saved, the block ran successfully, tests passed, and status was updated to certified.":"Latest edits were saved, the block ran successfully, no block tests are defined, and status was updated to certified.":d?`Latest edits were saved, but certification cannot finish because ${d}. Fix it, then click Certify again.`:"Latest edits were saved, but certification cannot finish yet. Fix the blockers below, then click Certify again."}),s.length>0&&e.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:s.map(([l,f])=>e.jsxs("span",{style:{fontSize:11,fontWeight:700,color:f?"#3fb950":"#d29922",background:f?"#3fb95018":"#d2992218",borderRadius:999,padding:"4px 8px"},children:[f?"✓":"!"," ",l]},l))}),t.error&&e.jsx("div",{style:{fontSize:12,color:"#f85149"},children:t.error}),i.length>0&&e.jsxs("div",{style:{display:"grid",gap:5},children:[e.jsx("div",{style:{fontSize:10,color:"#d29922",textTransform:"uppercase",fontWeight:800},children:"Missing before certification"}),i.map((l,f)=>e.jsx("div",{style:{fontSize:12,color:"#d29922",lineHeight:1.4},children:l},f))]}),(((P=(x=t.certification)==null?void 0:x.warnings)==null?void 0:P.length)??0)>0&&e.jsxs("div",{style:{display:"grid",gap:5},children:[e.jsx("div",{style:{fontSize:10,color:n.textMuted,textTransform:"uppercase",fontWeight:800},children:"Warnings"}),t.certification.warnings.map(l=>e.jsxs("div",{style:{fontSize:12,color:n.textMuted},children:[l.rule,": ",l.message]},`${l.rule}-${l.message}`))]})]})}function Rr(t){const n=t.trim(),r=n.toLowerCase();return r==="missing owner"||r==="block has owner: missing owner"?"Owner is required.":r==="missing domain"||r==="block has domain: missing domain"?"Domain is required.":r==="missing description"||r==="block has description: missing description"?"Description is required.":r==="block has not run successfully"?"The query must run successfully.":r==="tests must pass before certification"||r.startsWith("all tests pass:")?"Tests must pass.":r==="at least one test assertion is required before certification"||r.startsWith("block has tests:")?"Add at least one test assertion.":r==="visualization config is missing"?"Choose a visualization.":n}function Lr(t){const n=t.filter(r=>r.endsWith(" is required.")).map(r=>r.replace(" is required.","").toLowerCase());return n.length===0?t[0]?t[0].replace(/\.$/,"").toLowerCase():"":n.length===1?`${n[0]} is missing`:n.length===2?`${n[0]} and ${n[1]} are missing`:n.length>2?`${n.slice(0,-1).join(", ")}, and ${n[n.length-1]} are missing`:t.includes("Add at least one test assertion.")?"a test assertion is missing":t.includes("Choose a visualization.")?"a visualization is missing":t.includes("Tests must pass.")?"tests must pass":t.includes("The query must run successfully.")?"the query has not run successfully":t[0]?t[0].replace(/\.$/,"").toLowerCase():""}function $r({entries:t,t:n}){return t.length===0?e.jsx(at,{message:"No version history available. Commit changes to build history."}):e.jsxs("div",{style:{padding:12,display:"grid",gap:8},children:[e.jsx("div",{style:{fontSize:12,fontWeight:600,color:n.textPrimary,fontFamily:n.font},children:"Version History"}),t.map(r=>e.jsxs("div",{style:{padding:"8px 12px",border:`1px solid ${n.cellBorder}`,borderRadius:8,background:n.inputBg},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[e.jsx("span",{style:{fontSize:10,fontFamily:n.fontMono,color:n.accent,background:`${n.accent}12`,padding:"1px 6px",borderRadius:4},children:r.hash.slice(0,7)}),e.jsx("span",{style:{fontSize:11,color:n.textMuted,fontFamily:n.font},children:new Date(r.date).toLocaleDateString()}),e.jsx("span",{style:{fontSize:11,color:n.textMuted,fontFamily:n.font,marginLeft:"auto"},children:r.author})]}),e.jsx("div",{style:{fontSize:12,color:n.textPrimary,fontFamily:n.font},children:r.message})]},r.hash))]})}function Er(t,n){const r=t.match(/query\s*=\s*"""([\s\S]*?)"""/i);return r?t.replace(r[0],`query = """${r[1].trimEnd()}
|
|
28
|
-
${n}
|
|
29
|
-
"""`):/^\s*block\s+"/i.test(t.trim())?t.replace(/\n\}\s*$/,`
|
|
30
|
-
|
|
31
|
-
query = """
|
|
32
|
-
${n}
|
|
33
|
-
"""
|
|
34
|
-
}
|
|
35
|
-
`):`${t.trimEnd()}
|
|
36
|
-
${n}
|
|
37
|
-
`}function ui(t,n){const r=n.trim().replace(/;\s*$/,"");if(!r)return t;const s=t.trim();if(!s)return r;const i=t.match(/query\s*=\s*"""[\s\S]*?"""/i);if(i)return t.replace(i[0],`query = """
|
|
38
|
-
${r}
|
|
39
|
-
"""`);if(/^\s*block\s+"/i.test(s)){const d=`
|
|
40
|
-
query = """
|
|
41
|
-
${r}
|
|
42
|
-
"""
|
|
43
|
-
`;return/\}\s*$/.test(t)?t.replace(/\}\s*$/,`${d}}
|
|
44
|
-
`):`${t.trimEnd()}${d}`}return r}function on(t){return ko({name:t,status:"draft",metrics:[],dimensions:[],visualization:{chart:"table"}})}function Ft(t){return`block "${t}" {
|
|
45
|
-
domain = "uncategorized"
|
|
46
|
-
type = "custom"
|
|
47
|
-
description = ""
|
|
48
|
-
owner = ""
|
|
49
|
-
tags = []
|
|
50
|
-
|
|
51
|
-
query = """
|
|
52
|
-
SELECT 1 AS value
|
|
53
|
-
"""
|
|
54
|
-
|
|
55
|
-
visualization {
|
|
56
|
-
chart = "table"
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
`}const Ti="dql.block-studio.draft-session";function dn(){const t=`draft-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;try{window.localStorage.setItem(Ti,t)}catch{}return t}function Ar(){var t;try{const n=(t=window.localStorage.getItem(Ti))==null?void 0:t.trim();if(n)return n}catch{}return dn()}function _r(){var t;if(typeof window>"u")return"";try{return((t=window.localStorage.getItem("dql.block-studio.domain"))==null?void 0:t.trim())??""}catch{return""}}function Wr(t,n){try{const r=window.localStorage.getItem(t);return r==null?n:r==="1"}catch{return n}}function Fr(t,n,r,s){try{const i=Number(window.localStorage.getItem(t));return Number.isFinite(i)?Math.min(s,Math.max(r,i)):n}catch{return n}}function Or(t){return!!(t.blockStudioDraft.trim()||t.blockStudioMetadata||t.activeBlockPath)}function Mi(t){var i,d;const n=((i=t==null?void 0:t.domain)==null?void 0:i.trim())||"uncategorized",r=(d=t==null?void 0:t.folderPath)==null?void 0:d.trim().replace(/\\/g,"/").replace(/^\/+|\/+$/g,""),s=((t==null?void 0:t.name)||"new_block").toLowerCase().replace(/[^a-z0-9_]+/g,"-").replace(/^[-_]+|[-_]+$/g,"")||"new-block";return`blocks/${n}/${r?`${r}/`:""}${s}.dql`}function Ii(t){var r;const n=((r=t.match(/\bselect\b([\s\S]*?)\bfrom\b/i))==null?void 0:r[1])??"";return n?Array.from(new Set(n.split(",").map(s=>{var p,m;const i=(p=s.match(/\bas\s+([a-zA-Z_][\w$]*)\s*$/i))==null?void 0:p[1];return i||(((m=s.trim().match(/(?:^|\.)([a-zA-Z_][\w$]*)$/))==null?void 0:m[1])??"")}).filter(Boolean))).slice(0,24):[]}function qe(t){return t.replace(/[_-]+/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function qr(t,n){const r=n.trim().toLowerCase();if(!r)return t;const s=i=>{const d=[i.label,i.path,i.type].filter(m=>!!m).some(m=>m.toLowerCase().includes(r)),p=(i.children??[]).map(m=>s(m)).filter(m=>!!m);return d||p.length>0?{...i,children:p}:null};return t.map(i=>s(i)).filter(i=>!!i)}function Nr(t){let n=0,r=0,s=0;const i=d=>{d.kind==="schema"&&(n+=1),d.kind==="table"&&(r+=1),d.kind==="column"&&(s+=1);for(const p of d.children??[])i(p)};for(const d of t)i(d);return{schemas:n,tables:r,columns:s}}function Hr(t){const n=[],r=s=>{s.kind==="table"&&s.path&&n.push({path:s.path,columns:(s.children??[]).filter(i=>i.kind==="column").map(i=>i.label)});for(const i of s.children??[])r(i)};for(const s of t)r(s);return n}function pi(t){return["businessOutcome","llmContext","primaryTerms","sourceSystems","synonyms","caveats"].filter(r=>new RegExp(`\\b${r}\\s*=`,"i").test(t)).length}function Qr(t){return t.metrics+t.measures+t.dimensions+t.timeDimensions+t.entities+t.hierarchies+t.semanticModels+t.savedQueries}export{ys as BlockStudio};
|