@duckcodeailabs/dql-cli 1.13.1 → 1.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apps-api.d.ts +249 -7
- package/dist/apps-api.d.ts.map +1 -1
- package/dist/apps-api.js +2855 -160
- package/dist/apps-api.js.map +1 -1
- package/dist/assets/dql-notebook/assets/{AgentLogPage-D6fgEAEy.js → AgentLogPage-B3ugEb3H.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildDialog-8miXFPse.js → AiBuildDialog-BK_TDNcM.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildResult-DPJ_SI0R.js → AiBuildResult-Cob_Lj05.js} +8 -8
- package/dist/assets/dql-notebook/assets/{AiSidePanel-NVA6lZnn.js → AiSidePanel-CzIgxmP9.js} +1 -1
- package/dist/assets/dql-notebook/assets/AnalyticsHome-C2vJ2fxY.js +6 -0
- package/dist/assets/dql-notebook/assets/AppsView-DEWQ0sHT.js +5588 -0
- package/dist/assets/dql-notebook/assets/BlockStudio-CaDNTKMM.js +55 -0
- package/dist/assets/dql-notebook/assets/{BusinessArtifactView-DtRMiaF4.js → BusinessArtifactView-zwUOtddi.js} +1 -1
- package/dist/assets/dql-notebook/assets/DbtFirstModelingPage-BlnhTMu3.js +22 -0
- package/dist/assets/dql-notebook/assets/{GitPage-CazC-eTR.js → GitPage-Coevr9NJ.js} +3 -3
- package/dist/assets/dql-notebook/assets/GlobalAiRail-BTZS11x5.js +1 -0
- package/dist/assets/dql-notebook/assets/GovernedContextPage-CjyyM_ne.js +7 -0
- package/dist/assets/dql-notebook/assets/{HelpDocsPage-DMHPsVqP.js → HelpDocsPage-C1UeP85v.js} +1 -1
- package/dist/assets/dql-notebook/assets/{HomePage-DcSI4dnU.js → HomePage-zGPFIvOY.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDAG-BJ6xz06u.js → LineageDAG-DbXnQWu3.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDetailView-8WrQm-MF.js → LineageDetailView-Ch1Db01I.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDrawer-hnqCW_t-.js → LineageDrawer-DLxqJO6D.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineagePathBreadcrumb-B4LZTUsl.js → LineagePathBreadcrumb-B2tNdkr_.js} +3 -3
- package/dist/assets/dql-notebook/assets/{MiniLineageGraph-CotnRuxa.js → MiniLineageGraph-0gY-ZwCy.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewBlockModal-DHn-CEEW.js → NewBlockModal-DKVkXD20.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewNotebookModal-BPGp-8oq.js → NewNotebookModal-BUIByvYT.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NotebookEditor-B0OTHM6W.js → NotebookEditor-D2fIUxjE.js} +5 -5
- package/dist/assets/dql-notebook/assets/{ReadinessPage-CoOIpxWq.js → ReadinessPage-Ci4LyNiQ.js} +1 -1
- package/dist/assets/dql-notebook/assets/{SetupOnboarding-DxK_mFzf.js → SetupOnboarding-BF7ai_0t.js} +1 -1
- package/dist/assets/dql-notebook/assets/SkillsPage-BgYrgirJ.js +10 -0
- package/dist/assets/dql-notebook/assets/{TrustBadge-ZuD5N5Ww.js → TrustBadge-Bob1Laiq.js} +1 -1
- package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-IxDUKSG8.js +88 -0
- package/dist/assets/dql-notebook/assets/{answer-to-notebook-WAVAYjBv.js → answer-to-notebook-Dk42N0pU.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-left-L8odLbyN.js → arrow-left-DKuuTw9l.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-right-WIF1V9a9.js → arrow-right-TH8_ufKG.js} +1 -1
- package/dist/assets/dql-notebook/assets/{book-open-text-BpqWMa4m.js → book-open-text-B-dcHHn0.js} +1 -1
- package/dist/assets/dql-notebook/assets/{circle-x-CQBOM0b0.js → circle-x-BOc2KCZQ.js} +1 -1
- package/dist/assets/dql-notebook/assets/{dagre.esm-DlZi7NR3.js → dagre.esm-CPT_vn5p.js} +1 -1
- package/dist/assets/dql-notebook/assets/{external-link-DYqdQIGp.js → external-link-DtOfpYc6.js} +1 -1
- package/dist/assets/dql-notebook/assets/{grip-vertical-HmUijbwN.js → grip-vertical-B8joDDH9.js} +1 -1
- package/dist/assets/dql-notebook/assets/index-B3shyZsg.css +1 -0
- package/dist/assets/dql-notebook/assets/index-DJRMz64S.js +635 -0
- package/dist/assets/dql-notebook/assets/link-2-DMZPHawg.js +6 -0
- package/dist/assets/dql-notebook/assets/{list-tree-DGKqCxmz.js → list-tree-Dw0qlxPK.js} +1 -1
- package/dist/assets/dql-notebook/assets/{minimize-2-C8dvqCxX.js → minimize-2-DUiSrPS3.js} +1 -1
- package/dist/assets/dql-notebook/assets/{panel-right-open-yuVkIo5n.js → panel-right-open-BrrFrRZQ.js} +1 -1
- package/dist/assets/dql-notebook/assets/{bot-CLR1V6dO.js → play-Ced0HT9g.js} +7 -2
- package/dist/assets/dql-notebook/assets/{rotate-ccw-Di0kRnrM.js → rotate-ccw-D_9U9o7X.js} +1 -1
- package/dist/assets/dql-notebook/assets/{semantic-fields-BMQV0li8.js → semantic-fields-BlDOaonV.js} +1 -1
- package/dist/assets/dql-notebook/assets/{sliders-horizontal-alebptlJ.js → sliders-horizontal-BDt6KRGR.js} +1 -1
- package/dist/assets/dql-notebook/assets/{star-CgCQbnXc.js → star-CxUbF_BW.js} +1 -1
- package/dist/assets/dql-notebook/assets/{triangle-alert-SyuSZ4ht.js → triangle-alert-COWnsSdh.js} +1 -1
- package/dist/assets/dql-notebook/assets/upload-DSFC2kJX.js +6 -0
- package/dist/assets/dql-notebook/assets/usePersistedAgentThreadId-DYdx896E.js +32 -0
- package/dist/assets/dql-notebook/assets/{user-round-J4PQHxo9.js → user-round-Bfu7fosn.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wand-sparkles-c4WDXTCk.js → wand-sparkles-DSpG0c0j.js} +1 -1
- package/dist/assets/dql-notebook/assets/{workflow-NtRLaq7n.js → workflow-B1_pj9gq.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wrench-CS1f1Zv4.js → wrench-CvfM03KZ.js} +1 -1
- package/dist/assets/dql-notebook/assets/{x-CbKEfe5m.js → x-B4coLiOl.js} +1 -1
- package/dist/assets/dql-notebook/index.html +2 -2
- package/dist/commands/app.d.ts.map +1 -1
- package/dist/commands/app.js +65 -133
- package/dist/commands/app.js.map +1 -1
- package/dist/commands/model.js +21 -2
- package/dist/commands/model.js.map +1 -1
- package/dist/llm/providers/dql-agent-provider.d.ts +16 -0
- package/dist/llm/providers/dql-agent-provider.d.ts.map +1 -1
- package/dist/llm/providers/dql-agent-provider.js +65 -2
- package/dist/llm/providers/dql-agent-provider.js.map +1 -1
- package/dist/local-runtime.d.ts +112 -19
- package/dist/local-runtime.d.ts.map +1 -1
- package/dist/local-runtime.js +2026 -694
- package/dist/local-runtime.js.map +1 -1
- package/dist/package.json +10 -10
- package/dist/sql-result-filter.d.ts +9 -0
- package/dist/sql-result-filter.d.ts.map +1 -1
- package/dist/sql-result-filter.js +25 -0
- package/dist/sql-result-filter.js.map +1 -1
- package/package.json +10 -10
- package/dist/assets/dql-notebook/assets/AgentAnswerCard-c8QUo6NH.js +0 -5
- package/dist/assets/dql-notebook/assets/AnalyticsHome-DgwnRW71.js +0 -6
- package/dist/assets/dql-notebook/assets/AppsView-B6LYUpgm.js +0 -4578
- package/dist/assets/dql-notebook/assets/BlockStudio--jNw9XUI.js +0 -60
- package/dist/assets/dql-notebook/assets/DbtFirstModelingPage-DhBsLCYr.js +0 -22
- package/dist/assets/dql-notebook/assets/GlobalAiRail-1Tgweuu2.js +0 -1
- package/dist/assets/dql-notebook/assets/GovernedContextPage-C7qGrH3d.js +0 -16
- package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-duFXXNV_.js +0 -88
- package/dist/assets/dql-notebook/assets/index-Cpx47jCH.js +0 -634
- package/dist/assets/dql-notebook/assets/index-DKu4CZt3.css +0 -1
- package/dist/assets/dql-notebook/assets/upload-BPhfea_E.js +0 -11
- package/dist/assets/dql-notebook/assets/usePersistedAgentThreadId-Bnl9gWhj.js +0 -28
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import{c as zi,r as d,j as e,a5 as Lo,h as Ft,i as $o,k as Ao,a6 as _o,t as Ot,a7 as fn,a as W,a8 as vt,a9 as Wo,e as bn,D as vn,T as tn,P as Fo,S as Et,f as kt,l as Oo,L as Ze,aa as qo,ab as No,ac as ce,ad as Lt,ae as $t,af as Pi,ag as Ri,ah as Ho,b as Qo,ai as Uo,B as Jt,A as Ei,aj as Li,ak as $i,al as Ko,am as bi,an as Ue,z as Go,ao as Ai,Q as _i,ap as Vo,aq as Yo,ar as Xo,w as Zo,E as hn,x as Jo,y as er,H as vi}from"./index-DJRMz64S.js";import{S as tr,a as nr,b as Si}from"./LineagePathBreadcrumb-B2tNdkr_.js";import{u as ir,a as or,T as Wi,b as rr,d as sr,P as lr,E as ar,C as Fi}from"./usePersistedAgentThreadId-DYdx896E.js";import{M as dr}from"./MiniLineageGraph-0gY-ZwCy.js";import{b as Oi,U as cr,B as ur}from"./UnifiedAgentRunPanel-IxDUKSG8.js";import{a as pr,A as fr}from"./AiSidePanel-CzIgxmP9.js";import{P as qi,B as hr}from"./play-Ced0HT9g.js";import{T as ft}from"./triangle-alert-COWnsSdh.js";import{P as mr}from"./panel-right-open-BrrFrRZQ.js";import{X as gr}from"./x-B4coLiOl.js";import"./react-CRB3T2We.js";import"./codemirror-DXt7RW72.js";import"./TrustBadge-Bob1Laiq.js";import"./AiBuildResult-Cob_Lj05.js";import"./user-round-Bfu7fosn.js";import"./rotate-ccw-D_9U9o7X.js";import"./wrench-CvfM03KZ.js";import"./dagre.esm-CPT_vn5p.js";import"./list-tree-Dw0qlxPK.js";import"./minimize-2-DUiSrPS3.js";import"./arrow-right-TH8_ufKG.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 xr=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],yr=zi("chevron-left",xr);/**
|
|
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 br=[["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"}]],Ni=zi("file-input",br);function At({value:t,onChange:n,multiline:s,placeholder:r,style:o,ariaLabel:a,rows:p}){const[m,f]=d.useState(t),E=d.useRef(!1);d.useEffect(()=>{E.current||f(t)},[t]);const l={value:m,placeholder:r,style:o,"aria-label":a,onFocus:()=>{E.current=!0},onBlur:()=>{E.current=!1,f(t)},onChange:h=>{f(h.target.value),n(h.target.value)}};return s?e.jsx("textarea",{...l,rows:p}):e.jsx("input",{type:"text",...l})}function vr(t,n){return Lo(t,n)}const Sr={native:"Native (DQL)","metricflow-cli":"Local MetricFlow","dbt-cloud":"dbt Cloud"};function kr(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 ki=["day","week","month","quarter","year"];function jr(t,n,s){var a,p;if(!t)return ki;const r=(a=n.get(t))==null?void 0:a.granularities;if(r&&r.length>0)return r;const o=(p=s.find(m=>(m.reference??m.name)===t||m.name===t))==null?void 0:p.granularities;return o&&o.length>0?o:ki}function Ws(){var Kn,Gn,Vn,Yn,Xn,Zn,Jn,ei,ti,ni,ii,oi,ri,si,li,ai,di,ci,ui,pi,fi,hi,mi,gi,xi,yi;const t=Ft($o(i=>({activeBlockPath:i.activeBlockPath,authoredDomains:i.authoredDomains,blockStudioDbtStatus:i.blockStudioDbtStatus,blockStudioDirty:i.blockStudioDirty,blockStudioDraft:i.blockStudioDraft,blockStudioImportOpen:i.blockStudioImportOpen,blockStudioLastRun:i.blockStudioLastRun,blockStudioMetadata:i.blockStudioMetadata,blockStudioPreview:i.blockStudioPreview,blockStudioValidation:i.blockStudioValidation,files:i.files,schemaTables:i.schemaTables,semanticLayer:i.semanticLayer,themeMode:i.themeMode}))),n=Ao(),{operations:s,track:r}=_o(),o=Ot[t.themeMode],[a,p]=d.useState(()=>as()),m=t.activeBlockPath?`block-studio.block.${encodeURIComponent(t.activeBlockPath)}`:`block-studio.draft.${a}`,f=ir(m),[E,l]=d.useState("blocks"),[h,k]=d.useState("results"),[b,P]=d.useState(()=>ds()),[L,K]=d.useState([]),[_,w]=d.useState({}),[x,X]=d.useState(""),[H,re]=d.useState(new Set),$=d.useMemo(()=>{const i=t.schemaTables.map(y=>[y.name,y.columns.map(j=>j.name)]),c=ms(L).map(y=>[y.path,y.columns]),S=new Map;for(const[y,j]of[...c,...i])y&&S.set(y,j);return S.size>0?Object.fromEntries(S):void 0},[t.schemaTables,L]),[G,J]=d.useState(!1),[I,N]=d.useState(null),[q,V]=d.useState(null),[ve,te]=d.useState(!1),[Q,ue]=d.useState(null),[Se,Pe]=d.useState(0),[z,Y]=d.useState({}),[we,pe]=d.useState(!1),[De,ge]=d.useState(!1),[Ae,ke]=d.useState(null),[Ie,Ce]=d.useState(null),[u,M]=d.useState(null),[ee,ae]=d.useState(null),[fe,Ke]=d.useState(null),oe=d.useRef(!1),se=d.useRef(null),[qe,le]=d.useState(null),[Je,et]=d.useState(!1),[_e,tt]=d.useState(null),[at,dt]=d.useState(!1),[ht,Re]=d.useState(null),[mt,Ge]=d.useState(0),[gt,Ve]=d.useState(!1),[xt,g]=d.useState(!1),T=d.useRef(null),D=d.useRef(null),C=d.useRef(!1),[U,ne]=d.useState(null),[v,B]=d.useState([]),[R,O]=d.useState(!1),[We,Ee]=d.useState(!1),[wt,Ct]=d.useState(null),[Vi,wn]=d.useState(null),[Yi,Cn]=d.useState(null),[Bn,Xi]=d.useState(340),[qt,Zi]=d.useState(320),[Le,Nt]=d.useState(!1),[Tn,yt]=d.useState(!1),[he,Ji]=d.useState(()=>typeof window<"u"?window.innerWidth<900:!1),[Dn,Ne]=d.useState(()=>t.blockStudioImportOpen?"import":"start"),[Bt,ie]=d.useState("visual"),[nt,nn]=d.useState(()=>cs("dql.block-studio.ai.open",!1)),[Ht,eo]=d.useState(()=>us("dql.block-studio.ai.width",420,360,520)),[In,Mn]=d.useState(!1),[to,no]=d.useState(!1),[io,oo]=d.useState(0),[He,Qt]=d.useState(null),[ro,zn]=d.useState([]),[so,Pn]=d.useState(!1),[Tt,on]=d.useState(null),[Rn,rn]=d.useState(null),[En,lo]=d.useState("ask"),[ao,co]=d.useState(""),[uo,po]=d.useState(void 0),[fo,ho]=d.useState(!1),[Ln,it]=d.useState(null),sn=d.useRef(t.activeBlockPath),Ut=d.useRef(new Set),me=d.useRef(0),Kt=d.useRef(t.blockStudioDraft);Kt.current=t.blockStudioDraft;const Gt=d.useCallback(()=>{me.current+=1,J(!1),N(null),V(null),te(!1),ue(null),Pe(0),Y({}),pe(!1),ge(!1),ke(null),Ce(null),M(null),ae(null),le(null),it(null),Ke(null),B([]),O(!1),k("results")},[]),Qe=fn({queryKey:["block-studio","catalog","summary"],queryFn:()=>W.getBlockStudioCatalog({includeSemantic:!1}),staleTime:3e4}),Dt=fn({queryKey:["block-studio","dbt-status"],queryFn:()=>W.getBlockStudioDbtStatus(),staleTime:3e4}),It=fn({queryKey:["semantic-layer"],queryFn:()=>W.getSemanticLayer(),staleTime:3e4});d.useEffect(()=>{const i=()=>Ge(c=>c+1);return window.addEventListener("dql:block-library-invalidated",i),()=>window.removeEventListener("dql:block-library-invalidated",i)},[]),d.useEffect(()=>{var c,S,y;if(!fe)return;const i=s.find(j=>j.id===fe);if(i){if(i.status==="queued"||i.status==="running"){it({pending:!0,phase:i.phase,progress:i.progress,message:i.message});return}if(i.status==="succeeded"){const j=i.result;it({pending:!1,ok:(j==null?void 0:j.outcome)==="certified",checklist:j==null?void 0:j.checklist,blockers:(j==null?void 0:j.blockers)??((c=j==null?void 0:j.checklist)==null?void 0:c.blockers),error:(j==null?void 0:j.outcome)==="draft_saved_with_blockers"?"The draft was saved. Resolve the certification blockers and try again.":void 0}),le(null)}else le(((S=i.error)==null?void 0:S.message)??"Certification did not complete. The draft remains saved."),it({pending:!1,error:((y=i.error)==null?void 0:y.message)??i.message});Ke(null),k("save")}},[fe,s]),d.useEffect(()=>{n({type:"SET_BLOCK_STUDIO_CATALOG_LOADING",loading:Qe.isLoading}),Qe.data?(n({type:"SET_BLOCK_STUDIO_CATALOG",catalog:Qe.data}),K(Qe.data.databaseTree),ne(null)):Qe.isError&&ne("Failed to load schema. Check your connection and try refreshing.")},[Qe.data,Qe.isError,Qe.isLoading,n]),d.useEffect(()=>{Dt.data?n({type:"SET_BLOCK_STUDIO_DBT_STATUS",status:Dt.data}):Dt.isError&&n({type:"SET_BLOCK_STUDIO_DBT_STATUS",status:null})},[Dt.data,Dt.isError,n]),d.useEffect(()=>{n({type:"SET_SEMANTIC_LOADING",loading:It.isLoading}),It.data&&n({type:"SET_SEMANTIC_LAYER",layer:It.data})},[n,It.data,It.isLoading]);const Vt=d.useCallback(async()=>{Pn(!0);try{const i=await W.listBlockStudioImports();zn(i.sessions??[])}catch{zn([])}finally{Pn(!1)}},[]);d.useEffect(()=>{Vt()},[Vt]),d.useEffect(()=>{const i=sn.current,c=t.activeBlockPath;if(c!==i){const S=fe?s.find(je=>je.id===fe):void 0,y=S==null?void 0:S.result,j=new Set([...Ut.current,y==null?void 0:y.oldPath,y==null?void 0:y.draftPath,y==null?void 0:y.newPath].filter(je=>!!je));!!(c&&j.has(c)&&(!i||j.has(i)))||(Ut.current.clear(),Gt())}c&&c!==i&&n({type:"CLOSE_BLOCK_IMPORT"}),sn.current=c},[t.activeBlockPath,fe,n,s,Gt]),d.useEffect(()=>{if(!t.blockStudioDirty)return;const i=c=>{c.preventDefault(),c.returnValue=""};return window.addEventListener("beforeunload",i),()=>window.removeEventListener("beforeunload",i)},[t.blockStudioDirty]),d.useEffect(()=>{const i=new AbortController,c=window.setTimeout(()=>{t.blockStudioDraft.trim()&&W.validateBlockStudio(t.blockStudioDraft,t.activeBlockPath,i.signal).then(S=>{i.signal.aborted||n({type:"SET_BLOCK_STUDIO_VALIDATION",validation:S})}).catch(()=>{})},250);return()=>{window.clearTimeout(c),i.abort()}},[t.blockStudioDraft,t.activeBlockPath,n]),d.useMemo(()=>fs(L,x),[L,x]);const Yt=d.useMemo(()=>hs(L),[L]),$n={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},An=gs($n);d.useEffect(()=>{const i=()=>Ji(window.innerWidth<900);return i(),window.addEventListener("resize",i),()=>window.removeEventListener("resize",i)},[]),d.useEffect(()=>{try{window.localStorage.setItem("dql.block-studio.ai.open",nt?"1":"0")}catch{}},[nt]),d.useEffect(()=>{try{window.localStorage.setItem("dql.block-studio.ai.width",String(Ht))}catch{}},[Ht]),d.useEffect(()=>{if(b)try{window.localStorage.setItem("dql.block-studio.domain",b)}catch{}},[b]),d.useEffect(()=>{var c,S;const i=(S=(c=t.blockStudioMetadata)==null?void 0:c.domain)==null?void 0:S.trim();i&&i!=="uncategorized"&&P(i)},[t.activeBlockPath,(Kn=t.blockStudioMetadata)==null?void 0:Kn.domain]),d.useEffect(()=>{t.blockStudioImportOpen&&(Ne("import"),n({type:"CLOSE_BLOCK_IMPORT"}))},[n,t.blockStudioImportOpen]),d.useEffect(()=>{var i;Ne(ps(t)?"manual":"start"),ie(((i=vt(t.blockStudioDraft))==null?void 0:i.blockType)==="semantic"?"visual":"source")},[t.activeBlockPath]);const ct=d.useMemo(()=>{var c;const i=vt(t.blockStudioDraft);return t.blockStudioMetadata?{...i,name:(i==null?void 0:i.name)||t.blockStudioMetadata.name,domain:(i==null?void 0:i.domain)||t.blockStudioMetadata.domain,description:(i==null?void 0:i.description)||t.blockStudioMetadata.description,owner:(i==null?void 0:i.owner)||t.blockStudioMetadata.owner,tags:(c=i==null?void 0:i.tags)!=null&&c.length?i.tags:t.blockStudioMetadata.tags,blockType:(i==null?void 0:i.blockType)||"custom",status:(i==null?void 0:i.status)||t.blockStudioMetadata.reviewStatus||"draft"}:i},[t.blockStudioDraft,t.blockStudioMetadata]),xe=(ct==null?void 0:ct.name)??((Gn=t.blockStudioMetadata)==null?void 0:Gn.name)??null,ot=((ct==null?void 0:ct.blockType)??"custom")==="semantic",Ye=!!(t.blockStudioDraft.trim()||t.blockStudioMetadata||t.activeBlockPath);d.useEffect(()=>{var i;if(t.activeBlockPath){if(se.current==="builder"){se.current=null,ie(((i=vt(t.blockStudioDraft))==null?void 0:i.blockType)==="semantic"?"visual":"source");return}t.activeBlockPath&&ie("detail")}},[t.activeBlockPath]);const ln=d.useCallback(async i=>{const c=me.current,S=`block:${i}`;n({type:"SET_LINEAGE_FOCUS",nodeId:S}),Ee(!0);try{const[y,j,F]=await Promise.all([W.fetchLineageNode(S),W.queryLineage({focus:S,upstreamDepth:3,downstreamDepth:2}),W.fetchLineagePaths(S,{maxDepth:6,maxPaths:6})]);if(c!==me.current)return;Ct(y),wn(j.graph??null),Cn(F)}catch{if(c!==me.current)return;Ct(null),wn(null),Cn(null)}finally{c===me.current&&Ee(!1)}},[n]);d.useEffect(()=>{xe&&ln(xe)},[xe,ln]);const _n=d.useCallback(()=>{const i=t.activeBlockPath;if(!i||R)return;const c=me.current;W.getBlockHistory(i).then(S=>{c!==me.current||i!==sn.current||(B(S.entries),O(!0))}).catch(()=>{c===me.current&&(B([]),O(!0))})},[R,t.activeBlockPath]),Fe=i=>{N(null),V(null),le(null),ke(null),Ce(null),M(null),ae(null),n({type:"SET_BLOCK_STUDIO_DRAFT",draft:i});const c=vt(i),S=t.blockStudioMetadata;if(!c||!S||!Ho(i))return;const y={...S,name:c.name||S.name,domain:c.domain||S.domain,description:c.description,owner:c.owner,tags:c.tags,reviewStatus:c.status||S.reviewStatus};(y.name!==S.name||y.domain!==S.domain||y.description!==S.description||y.owner!==S.owner||y.reviewStatus!==S.reviewStatus||y.tags.join("\0")!==S.tags.join("\0"))&&n({type:"SET_BLOCK_STUDIO_METADATA",metadata:y})},mo=i=>{if(i==="semantic"===ot)return;const c=t.blockStudioMetadata,S=(c==null?void 0:c.name)||(i==="semantic"?"new_semantic_block":"new_sql_block");let y=i==="semantic"?yn(S):Zt(S);y=Lt(y,S),i==="custom"&&(y=Li(y,"")),c&&(y=ce(y,"domain",c.domain||"uncategorized"),y=ce(y,"description",c.description??""),y=ce(y,"owner",c.owner??""),y=$t(y,c.tags??[])),Fe(y),ie("visual")},go=(i,c)=>{const S=t.blockStudioMetadata;let y=ot?t.blockStudioDraft:yn((S==null?void 0:S.name)||"new_semantic_block");!ot&&S&&(y=ce(y,"domain",S.domain||"uncategorized"),y=ce(y,"description",S.description??""),y=ce(y,"owner",S.owner??""),y=$t(y,S.tags??[])),y=Pi(y,i),y=Ri(y,"dimensions",c),Fe(y),on(null),rn(null),Ne("manual"),ie("visual")},Wn=()=>{Gt(),n({type:"START_NEW_BLOCK_WORKSPACE"}),p(kn()),Qt(null),Ne("start"),ie("visual")},Fn=async i=>{try{const c={name:i.path.split("/").pop()??i.name,path:i.path,type:"block",folder:"blocks"},S=await W.openBlockStudio(i.path);Gt(),t.files.some(y=>y.path===i.path)||n({type:"FILE_ADDED",file:c}),n({type:"OPEN_BLOCK_STUDIO",file:c,payload:S}),ne(null)}catch(c){ne(c instanceof Error?c.message:"Could not open this block.")}},an=()=>{const i=T.current;if(T.current=null,i){Fn(i);return}Wn()},On=()=>{if(T.current=null,t.blockStudioDirty){g(!0);return}Wn()},qn=()=>{On()},xo=i=>{if(i.path!==t.activeBlockPath){if(t.blockStudioDirty){T.current=i,g(!0);return}Fn(i)}},Nn=i=>{const c=i==="semantic"?"new_semantic_block":"new_sql_block",S=b||"uncategorized",y=i==="semantic"?yn(c):Zt(c),j=ce(y,"domain",S);n({type:"SET_BLOCK_STUDIO_DRAFT",draft:j}),n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{name:c,path:null,domain:S,folderPath:"",description:"",owner:"",tags:[],reviewStatus:"draft",sourceKind:"manual"}}),n({type:"SET_BLOCK_STUDIO_PREVIEW",preview:null}),n({type:"SET_BLOCK_STUDIO_VALIDATION",validation:null}),Ne("manual"),ie("visual")},Mt=async()=>{const i=me.current;J(!0),N(null),V(null),te(!1),ue(Date.now()),Pe(0),n({type:"SET_BLOCK_STUDIO_PREVIEW",preview:null});try{const c=await W.runBlockStudio(t.blockStudioDraft,t.activeBlockPath,z);if(i!==me.current)return;n({type:"SET_BLOCK_STUDIO_PREVIEW",preview:c}),c.validation&&n({type:"SET_BLOCK_STUDIO_VALIDATION",validation:c.validation}),ke(null),Ce(null),k("results")}catch(c){if(i!==me.current)return;const S=c instanceof Error?c.message:String(c),y=Ti(c);N(S),V(y),ke(y??S),Ce("run"),k(/required parameter|provide required parameter/i.test(S)?"parameters":"results")}finally{i===me.current&&(J(!1),ue(null))}},dn=async(i,c={})=>{var F,je,rt;const S=i??Ae;if(De||!S)return;const y=t.blockStudioDraft,j=me.current;ge(!0),le(null),M(null),ae(null);try{const ye=await W.repairAndRunBlockStudio(y,S,z,xe??((F=t.blockStudioMetadata)==null?void 0:F.name)??void 0);if(j!==me.current)return;if(Kt.current!==y)throw new Error("The block changed while AI repair was running. The stale repair was not applied.");const $e=await W.validateBlockStudio(ye.source,t.activeBlockPath);if(j!==me.current)return;if($e.saveable===!1)throw new Error(((je=$e.diagnostics.find(Oe=>Oe.severity==="error"))==null?void 0:je.message)??"The repaired DQL still has an authoring error.");if(Kt.current!==y)throw new Error("The block changed while AI repair was running. The stale repair was not applied.");const de=c.requireCertificationReady?await W.assessBlockStudioCertification(ye.source):null;if(j!==me.current)return;if(Kt.current!==y)throw new Error("The block changed while AI repair was running. The stale repair was not applied.");if(Fe(ye.source),n({type:"SET_BLOCK_STUDIO_VALIDATION",validation:$e}),n({type:"SET_BLOCK_STUDIO_PREVIEW",preview:ye.preview}),N(null),ke(null),Ce(null),V(null),de&&!de.ok){const Oe=Math.max(1,de.blockers.length),pt=(rt=de.checklist.issues)==null?void 0:rt.find(Xt=>Xt.severity==="error");it({pending:!1,ok:!1,checklist:de.checklist,certification:de.certification,blockers:de.blockers,error:"The repair attempt ran, but certification requirements are still not ready."}),ae(`The repair attempt ran, but ${Oe} certification fix${Oe===1?"":"es"} remain${Oe===1?"s":""}.${pt!=null&&pt.title?` ${pt.title}.`:""}`),ie("source"),k("save"),yt(!1);return}de!=null&&de.ok?(it(null),M(`${ye.repairMode==="ai"?"AI repaired":"DQL repaired"} the draft, and every certification check now passes. Review the changes, then click Certify.`)):M(`${ye.repairMode==="ai"?"AI fixed":"DQL fixed"} the draft and the corrected block ran successfully. Review the changes, then save the draft.`),ie("source"),k("results"),yt(!1)}catch(ye){if(j!==me.current)return;const $e=ye instanceof Error?ye.message:String(ye),de=Ti(ye);N($e),V(de),ke(de??$e),Ce("run"),k("results"),yt(!1)}finally{j===me.current&&ge(!1)}},yo=async(i=t.blockStudioDraft)=>{var y,j;if(!t.blockStudioMetadata)throw new Error("Block metadata is required before saving.");const c=await W.saveBlockStudio({path:t.activeBlockPath,source:i,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 Ge(F=>F+1),n({type:"OPEN_BLOCK_STUDIO",file:{name:`${c.metadata.name}.dql`,path:c.path,type:"block",folder:"blocks"},payload:c}),t.files.some(F=>F.path===c.path)||n({type:"FILE_ADDED",file:{name:`${c.metadata.name}.dql`,path:c.path,type:"block",folder:"blocks"}}),((y=c.lineageRefresh)==null?void 0:y.status)==="ready"?ln(c.metadata.name):((j=c.lineageRefresh)==null?void 0:j.status)==="failed"&&(le(`Block saved, but lineage refresh failed: ${c.lineageRefresh.message??"compile failed"}`),setTimeout(()=>le(null),7e3)),c},cn=async()=>{var i,c;if(!((i=t.blockStudioMetadata)!=null&&i.name.trim())||!t.blockStudioMetadata.owner.trim())return D.current="save",Ve(!0),!1;pe(!0),le(null);try{const S=t.blockStudioMetadata.reviewStatus==="certified"&&t.blockStudioDirty?ce(t.blockStudioDraft,"status","draft"):t.blockStudioDraft,y=await W.validateBlockStudio(S,t.activeBlockPath);if(n({type:"SET_BLOCK_STUDIO_VALIDATION",validation:y}),y.saveable===!1||y.saveable===void 0&&!y.valid){const j=((c=y.diagnostics.find(F=>F.severity==="error"))==null?void 0:c.message)??"Fix the block errors before saving.";return le(`Draft not saved: ${j}`),ke(j),Ce("save"),ie("source"),!1}return await yo(S),ke(null),Ce(null),M(null),ae(null),k("save"),!0}catch(S){const y=(S==null?void 0:S.message)??"Save failed";return le(y.includes("409")||y.includes("BLOCK_EXISTS")?"A block with this name already exists. Rename and try again.":y),!1}finally{pe(!1)}},un=(i,c)=>{Re(null),tt({path:i,name:c}),et(!0)},bo=async()=>{var c;const i=_e==null?void 0:_e.path;if(i){dt(!0),Re(null);try{const S=await W.deleteBlockStudio(i);n({type:"FILE_REMOVED",path:S.path}),t.activeBlockPath===S.path&&(n({type:"START_NEW_BLOCK_WORKSPACE"}),p(kn()),Qt(null),Ne("start"),ie("visual")),et(!1),tt(null),Ge(y=>y+1),((c=S.lineageRefresh)==null?void 0:c.status)==="failed"&&ne(`Block deleted, but lineage refresh failed: ${S.lineageRefresh.message??"compile failed"}`)}catch(S){Re(S instanceof Error?S.message:String(S))}finally{dt(!1)}}},Hn=async()=>{var i;if(!((i=t.blockStudioMetadata)!=null&&i.name.trim())||!t.blockStudioMetadata.owner.trim())return D.current="certify",Ve(!0),!1;if(oe.current||fe)return!1;oe.current=!0,pe(!0),le(null);try{it(null);const c=t.blockStudioMetadata.reviewStatus==="certified"&&t.blockStudioDirty?ce(t.blockStudioDraft,"status","draft"):t.blockStudioDraft,S=`${t.blockStudioMetadata.sourceFingerprint??"new"}:${Date.now()}`,y=typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():`block-certification-${S}`,j=await W.requestBlockStudioCertification({source:c,path:t.activeBlockPath,metadata:t.blockStudioMetadata,expectedSourceFingerprint:t.blockStudioMetadata.sourceFingerprint,clientRevision:S,idempotencyKey:y});return r(j.operation),Ke(j.operation.id),Ut.current=new Set([t.activeBlockPath,j.draft.path].filter(F=>!!F)),n({type:"BLOCK_CERTIFICATION_ACCEPTED",source:c}),it({pending:!0}),k("save"),!0}catch(c){Ut.current.clear();const S=(c==null?void 0:c.message)??"Save failed";return le(S.includes("409")||S.includes("BLOCK_EXISTS")?"A block with this name already exists. Rename and try again.":S),setTimeout(()=>le(null),5e3),!1}finally{oe.current=!1,pe(!1)}};d.useEffect(()=>{var S;const i=D.current;if(!i||!((S=t.blockStudioMetadata)!=null&&S.name.trim())||!t.blockStudioMetadata.owner.trim())return;D.current=null,(i==="certify"?Hn():cn()).then(y=>{y&&C.current&&(C.current=!1,an())})},[(Vn=t.blockStudioMetadata)==null?void 0:Vn.name,(Yn=t.blockStudioMetadata)==null?void 0:Yn.owner,t.blockStudioDraft]);const vo=i=>{var y;const c=i.savedPath??((y=i.draftSave)==null?void 0:y.path)??"",S={path:c,source:i.dqlSource,metadata:{name:i.name,path:c||null,domain:i.domain,description:i.description,owner:i.owner,tags:i.tags,reviewStatus:i.reviewStatus,sourceKind:i.sourceKind,sourcePath:i.sourcePath,importId:He==null?void 0:He.id,candidateId:i.id,lineage:i.lineage.sourceTables},companionPath:null,validation:i.validation??{valid:!0,diagnostics:[],semanticRefs:{metrics:[],dimensions:[],segments:[]},executableSql:null}};n({type:"OPEN_BLOCK_STUDIO",file:{name:`${i.name}.dql`,path:c,type:"block",folder:"blocks",isNew:!c},payload:S}),n({type:"SET_BLOCK_STUDIO_PREVIEW",preview:i.preview}),k("results"),Ne("manual"),ie("visual")},So=(i,c)=>{t.files.some(y=>y.path===c.path)||n({type:"FILE_ADDED",file:{name:`${c.metadata.name}.dql`,path:c.path,type:"block",folder:"blocks"}}),Qt(y=>y&&{...y,candidates:y.candidates.map(j=>j.id===i.id?i:j)}),Vt()},ko=(i,c)=>{var F,je,rt,ye,$e,de,Oe;const S=t.blockStudioDraft.trim()?t.blockStudioDraft:Zt(((F=c==null?void 0:c.title)==null?void 0:F.trim())||"AI Generated Block"),y=(je=c==null?void 0:c.blockSource)!=null&&je.trim()?c.blockSource.trim():Ii(S,i);Fe(y);const j=vt(y);j&&n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{name:j.name||(c==null?void 0:c.title)||"AI Generated Block",path:t.activeBlockPath,domain:j.domain||(c==null?void 0:c.domain)||"analytics",description:j.description||(c==null?void 0:c.description)||`AI generated block for ${(c==null?void 0:c.question)??"analysis"}`,owner:j.owner||(c==null?void 0:c.owner)||"",tags:j.tags.length>0?j.tags:(c==null?void 0:c.tags)??["ai-generated","review-required"],reviewStatus:j.status||"draft",sourceKind:((rt=t.blockStudioMetadata)==null?void 0:rt.sourceKind)??"ai-generated",sourcePath:(ye=t.blockStudioMetadata)==null?void 0:ye.sourcePath,importId:($e=t.blockStudioMetadata)==null?void 0:$e.importId,candidateId:(de=t.blockStudioMetadata)==null?void 0:de.candidateId,lineage:(Oe=t.blockStudioMetadata)==null?void 0:Oe.lineage}}),n({type:"SET_BLOCK_STUDIO_VALIDATION",validation:{valid:!0,diagnostics:[{severity:"info",code:"ai_sql_draft_inserted",message:j?"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:i.trim()}}),k("results")},jo=async i=>{var rt,ye,$e,de,Oe,pt,Xt;const c=(ye=(rt=i.dqlArtifact)==null?void 0:rt.source)==null?void 0:ye.trim(),S=(i.sql??"").trim();if(!c&&!S)return;let y;if(($e=i.question)!=null&&$e.trim())try{const Me=await W.composeSemanticBlock(i.question.trim());Me.ok&&Me.source.trim()&&(y=Me.source.trim())}catch{}const j=y||c||Ii(Zt(((de=i.title)==null?void 0:de.trim())||"AI Generated Block"),S),F=vt(j),je=(F==null?void 0:F.name)||((Oe=i.dqlArtifact)==null?void 0:Oe.name)||i.title||"AI Generated Block";pe(!0),le(null);try{const Me=await W.saveAgentBlockDraft({source:j,name:je,domain:(F==null?void 0:F.domain)||((pt=t.blockStudioMetadata)==null?void 0:pt.domain)||"uncategorized",description:(F==null?void 0:F.description)||`AI-generated draft for ${i.title??je}`,tags:(Xt=F==null?void 0:F.tags)!=null&&Xt.length?F.tags:["ai-generated","review-required"],runId:i.sourceRunId});se.current="builder",n({type:"OPEN_BLOCK_STUDIO",file:{name:`${Me.metadata.name}.dql`,path:Me.path,type:"block",folder:"blocks",isNew:!1},payload:Me}),t.files.some(pn=>pn.path===Me.path)||n({type:"FILE_ADDED",file:{name:`${Me.metadata.name}.dql`,path:Me.path,type:"block",folder:"blocks"}}),Ge(pn=>pn+1),Ne("manual"),ie("visual"),k("save")}catch(Me){le(Me instanceof Error?Me.message:String(Me))}finally{pe(!1)}},bt=i=>{const c=(i==null?void 0:i.kind)??"ask";k("results"),lo(c),co((i==null?void 0:i.initialInput)??""),po(i!=null&&i.autoRun?{text:i.autoRun,mode:"block",nonce:Date.now()}:void 0),nn(!0)};d.useCallback(async()=>{try{const i=(await Qe.refetch()).data;i!=null&&i.databaseTree&&K(i.databaseTree),i&&n({type:"SET_BLOCK_STUDIO_CATALOG",catalog:i})}catch{}},[Qe,n]),d.useEffect(()=>{if(!G||!Q)return;const i=()=>Pe(Date.now()-Q);i();const c=window.setInterval(i,1e3);return()=>window.clearInterval(c)},[G,Q]);const Qn=((Xn=t.blockStudioValidation)==null?void 0:Xn.chartConfig)??((Zn=t.blockStudioPreview)==null?void 0:Zn.chartConfig)??{chart:"table"},wo=t.blockStudioPreview?or(t.blockStudioPreview.result,t.blockStudioPreview.chartConfig):"table",Co=i=>{i.preventDefault();const c=i.clientX,S=Bn,y=F=>{const je=Math.min(560,Math.max(300,S+F.clientX-c));Xi(je)},j=()=>{window.removeEventListener("mousemove",y),window.removeEventListener("mouseup",j)};window.addEventListener("mousemove",y),window.addEventListener("mouseup",j)},Bo=i=>{i.preventDefault();const c=i.clientY,S=qt,y=F=>{const je=Math.min(500,Math.max(180,S-(F.clientY-c)));Zi(je)},j=()=>{window.removeEventListener("mousemove",y),window.removeEventListener("mouseup",j)};window.addEventListener("mousemove",y),window.addEventListener("mouseup",j)},To=i=>{i.preventDefault();const c=i.clientX,S=Ht,y=F=>{eo(Math.min(520,Math.max(360,S-(F.clientX-c))))},j=()=>{window.removeEventListener("mousemove",y),window.removeEventListener("mouseup",j)};window.addEventListener("mousemove",y),window.addEventListener("mouseup",j)},ut=Ye&&!Tn,Do=he?"minmax(0, 1fr)":`${Le?0:Bn}px ${Le?0:6}px minmax(0, 1fr) ${nt?6:0}px ${nt?In?`min(${pr}px, 52vw)`:`${Ht}px`:0}`,Io=he?Le?ut?`minmax(0, 1fr) 6px ${qt}px`:"minmax(0, 1fr) 0 0":ut?`minmax(220px, 34vh) minmax(320px, 1fr) 6px ${qt}px`:"minmax(220px, 34vh) minmax(0, 1fr) 0 0":ut?`minmax(0, 1fr) 6px ${qt}px`:"minmax(0, 1fr) 0 0",Mo=he?"1":"3",Un=he?Le?"1":"2":"1",zo=he?"1":"3",Po=he?Le?"2":"3":"2",Ro=he?"1":"3",Eo=he?Le?"3":"4":"3";return e.jsxs("div",{style:{flex:1,position:"relative",display:"grid",gridTemplateColumns:Do,gridTemplateRows:Io,overflow:"hidden",background:o.appBg},children:[e.jsx("div",{style:{gridColumn:"1",gridRow:he?"1":"1 / 4",borderRight:Le?"none":`1px solid ${o.headerBorder}`,borderBottom:he&&!Le?`1px solid ${o.headerBorder}`:"none",display:Le?"none":"flex",flexDirection:"column",overflow:"hidden",background:o.sidebarBg,minWidth:0},children:e.jsx("div",{style:{flex:1,minHeight:0,overflow:"hidden"},children:e.jsx(Wo,{tabs:["blocks","semantic","database"],defaultTab:E,blockDomain:b,onBlockDomainChange:P,onInsertText:i=>{if(ot){rn("That snippet is SQL. Use a SQL Block for raw SELECT work, or keep this Semantic Block on metrics and dimensions.");return}Fe(ls(t.blockStudioDraft,i))},onSemanticCompose:go,onNewBlock:qn,onOpenBlock:xo,onDeleteBlock:i=>un(i.path,i.name),blockLibraryRefreshKey:mt,onCollapse:()=>Nt(!0),footer:t.semanticLayer.loading?`Loading ${(((Jn=t.blockStudioDbtStatus)==null?void 0:Jn.counts.metrics)??0).toLocaleString()} semantic metrics…`:`${t.semanticLayer.provider?`${t.semanticLayer.provider} synced`:"dbt synced"} · ${Yt.tables} table${Yt.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:Le?void 0:Co,style:{gridColumn:"2",gridRow:"1 / 4",display:Le||he?"none":"block",cursor:"col-resize",background:o.headerBorder}}),e.jsxs("div",{style:{display:he&&nt?"none":"flex",flexDirection:"column",minWidth:0,overflow:"hidden",gridColumn:Mo,gridRow:Un},children:[e.jsx("style",{children:`
|
|
12
|
+
@keyframes dql-agent-fadein { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
|
|
13
|
+
@keyframes dql-agent-run-spin { to { transform: rotate(360deg); } }
|
|
14
|
+
`}),e.jsxs("div",{style:{height:46,flexShrink:0,display:"flex",alignItems:"center",gap:10,padding:"0 16px",borderBottom:`1px solid ${o.headerBorder}`,background:o.cellBg,overflowX:"auto"},children:[Le&&e.jsx("button",{onClick:()=>Nt(!1),style:{background:"transparent",border:"none",color:o.textMuted,cursor:"pointer",fontSize:14,fontFamily:o.font,padding:0,lineHeight:1},title:"Open explorer",children:"›"}),e.jsxs("button",{type:"button",onClick:On,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:o.textMuted,fontSize:12,fontFamily:o.font,whiteSpace:"nowrap",cursor:"pointer"},children:[e.jsx(yr,{size:12,strokeWidth:2})," Blocks"]}),e.jsx(bn,{size:11,color:o.textMuted,style:{flexShrink:0}}),e.jsx("span",{style:{fontSize:12.5,fontWeight:600,color:o.textPrimary,fontFamily:o.fontMono,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:220},children:xe||((ei=t.blockStudioMetadata)==null?void 0:ei.name)||(Ye?"new_block":ot?"semantic":"sql")}),((ti=t.blockStudioMetadata)==null?void 0:ti.reviewStatus)&&e.jsx(Oi,{status:t.blockStudioMetadata.reviewStatus,t:o}),Ye&&Dn==="manual"&&Bt!=="detail"&&e.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:2,padding:2,border:`1px solid ${o.headerBorder}`,borderRadius:7,background:o.appBg,marginLeft:6,flexShrink:0},children:[e.jsx("button",{type:"button",onClick:()=>ie("visual"),style:ji(o,Bt==="visual"),children:"Visual Builder"}),e.jsx("button",{type:"button",onClick:()=>ie("source"),style:ji(o,Bt==="source"),children:"DQL Source"})]}),Ye&&e.jsx(st,{label:`Context${Mi(t.blockStudioDraft)?` (${Mi(t.blockStudioDraft)})`:""}`,Icon:vn,onClick:()=>ho(i=>!i)}),e.jsx("div",{style:{flex:1}}),t.activeBlockPath&&e.jsx(st,{label:"Delete",Icon:tn,variant:"danger",title:"Delete this saved block",onClick:()=>{var i;return un(t.activeBlockPath,((i=t.blockStudioMetadata)==null?void 0:i.name)||xe||t.activeBlockPath)}}),e.jsx(st,{label:"New block",Icon:Fo,onClick:qn}),Ye&&e.jsxs(e.Fragment,{children:[e.jsx(st,{label:"Ask AI",Icon:Et,onClick:()=>bt({kind:"ask"})}),t.activeBlockPath&&e.jsx(st,{label:"Modify with AI",Icon:Et,onClick:()=>bt({kind:"edit",initialInput:`Modify this block${xe?` (${xe})`:""}: `})}),e.jsx(st,{label:"Run",Icon:qi,onClick:()=>void Mt(),busy:G}),e.jsx(st,{label:we?"Saving":"Save draft",Icon:kt,variant:"secondary",busy:we,onClick:()=>void cn(),title:"Save changes as a review-required draft"}),e.jsx(st,{label:((ni=t.blockStudioMetadata)==null?void 0:ni.reviewStatus)==="certified"?"Re-certify":"Certify",Icon:Oo,variant:"primary",busy:we||!!fe,onClick:()=>void Hn(),title:"Run validation, query, tests, chart, and lineage gates before certification"})]}),qe&&e.jsx("span",{style:{fontSize:11,color:"var(--status-error)",fontFamily:o.font,padding:"4px 8px",background:"var(--status-error-bg)",borderRadius:6},children:qe})]}),Ae&&Ie==="save"&&e.jsxs("div",{role:"alert",style:{flexShrink:0,display:"flex",alignItems:"flex-start",gap:10,padding:"10px 14px",borderBottom:"1px solid var(--status-error)",background:"var(--status-error-bg)",color:o.textPrimary,fontFamily:o.font},children:[e.jsx(ft,{size:16,color:"var(--status-error)",style:{marginTop:1,flexShrink:0}}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:12,fontWeight:700},children:"This draft was not saved. Your work is still editable."}),e.jsx("div",{style:{marginTop:2,fontSize:11.5,lineHeight:1.45,color:o.textSecondary},children:Ae}),(((ii=t.blockStudioValidation)==null?void 0:ii.diagnostics.filter(i=>i.severity==="error").length)??0)>1&&e.jsx("div",{style:{marginTop:4,fontSize:10.5,color:o.textMuted},children:t.blockStudioValidation.diagnostics.filter(i=>i.severity==="error").slice(1,3).map(i=>i.message).join(" · ")})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,flexWrap:"wrap",justifyContent:"flex-end"},children:[e.jsxs("button",{type:"button",onClick:()=>void dn(),disabled:De,style:{...Te(o),display:"inline-flex",alignItems:"center",gap:6,opacity:De?.72:1},children:[De?e.jsx(Ze,{size:13,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):e.jsx(Et,{size:13}),De?"Fixing & running…":"Fix with AI & run"]}),e.jsx("button",{type:"button",onClick:()=>ie("source"),style:Z(o),children:"Edit DQL"}),e.jsx("button",{type:"button",onClick:()=>bt({kind:"edit",initialInput:`Help me fix this block error without changing its intended grain, parameters, or trust state: ${Ae} `}),style:Z(o),children:"Open Block AI"})]})]}),u&&e.jsxs("div",{role:"status",style:{flexShrink:0,display:"flex",alignItems:"center",gap:8,padding:"8px 14px",borderBottom:"1px solid var(--status-success)",background:"var(--status-success-bg)",color:o.textSecondary,fontSize:11.5,fontFamily:o.font},children:[e.jsx(kt,{size:14,color:"var(--status-success)"})," ",u]}),ee&&e.jsxs("div",{role:"status",style:{flexShrink:0,display:"flex",alignItems:"center",gap:8,padding:"8px 14px",borderBottom:"1px solid var(--status-warning-border)",background:"var(--status-warning-bg)",color:o.textSecondary,fontSize:11.5,fontFamily:o.font},children:[e.jsx(ft,{size:14,color:"var(--status-warning)"})," ",ee]}),Ye&&fo&&e.jsx(zr,{source:t.blockStudioDraft,databaseStats:Yt,semanticCount:An,onChange:Fe,onOpenExplorer:()=>{Nt(!1),l("database")},onOpenAi:()=>bt({kind:"edit",initialInput:"Review and improve this block context. Keep only grounded business references, sources, constraints, and caveats: "}),t:o}),e.jsx("div",{style:{flex:1,overflow:"hidden"},children:Dn==="import"?e.jsx(Qr,{session:He,sessions:ro,sessionsLoading:so,onClose:()=>Ne(Ye?"manual":"start"),onSessionChange:Qt,onRefreshSessions:Vt,onSelectCandidate:vo,onSavedCandidate:So,defaultDomain:((oi=t.blockStudioMetadata)==null?void 0:oi.domain)??b,defaultOwner:((ri=t.blockStudioMetadata)==null?void 0:ri.owner)??"",themeMode:t.themeMode,t:o,inline:!0}):Ye?Bt==="detail"?e.jsx(Er,{metadata:t.blockStudioMetadata,source:t.blockStudioDraft,parameters:((si=t.blockStudioValidation)==null?void 0:si.parameters)??[],preview:t.blockStudioPreview,lastRun:t.blockStudioLastRun??void 0,lineageDetail:wt,isSemanticBlock:ot,running:G,onOpenBuilder:()=>ie("visual"),onOpenSource:()=>ie("source"),onDelete:()=>{var i;return t.activeBlockPath&&un(t.activeBlockPath,((i=t.blockStudioMetadata)==null?void 0:i.name)||xe||t.activeBlockPath)},onRun:()=>void Mt(),onOpenHistory:()=>{k("history"),yt(!1),_n()},t:o}):Bt==="visual"?e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[e.jsx($r,{mode:ot?"semantic":"custom",onModeChange:mo,t:o}),e.jsx("div",{style:{flex:1,minHeight:0},children:ot?e.jsx(Lr,{source:t.blockStudioDraft,metadata:t.blockStudioMetadata,semanticLayer:t.semanticLayer,dbtStatus:t.blockStudioDbtStatus,domainOptions:t.authoredDomains,chartConfig:Qn,onChange:Fe,onMetadataChange:i=>t.blockStudioMetadata&&n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{...t.blockStudioMetadata,...i}}),onOpenAi:()=>bt({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:o},`sem-${t.activeBlockPath??a}`):e.jsx(Ar,{source:t.blockStudioDraft,metadata:t.blockStudioMetadata,domainOptions:t.authoredDomains,chartConfig:Qn,onChange:Fe,onMetadataChange:i=>t.blockStudioMetadata&&n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{...t.blockStudioMetadata,...i}}),onConvertToDql:()=>ie("source"),t:o},`sql-${t.activeBlockPath??a}`)})]}):e.jsxs("div",{style:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[(Tt||Rn)&&e.jsx(_r,{semanticChoice:Tt,databaseWarning:Rn,onDismiss:()=>{on(null),rn(null)},onInsertAdvanced:()=>{if(!Tt)return;const i=qo(Tt.kind==="metric"?"metric":"dimension",Tt.name);Fe(No(t.blockStudioDraft,i)),on(null)},onCreateSemantic:()=>n({type:"OPEN_NEW_BLOCK_MODAL",blockType:"semantic"}),t:o}),e.jsxs("div",{style:{height:34,flexShrink:0,display:"flex",alignItems:"center",gap:10,padding:"0 14px",borderBottom:"1px solid var(--border-subtle)",background:o.appBg},children:[e.jsx("span",{style:{fontSize:11,color:o.textMuted,fontFamily:o.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.activeBlockPath??Ki(t.blockStudioMetadata)}),t.blockStudioDirty&&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}}),t.blockStudioValidation?t.blockStudioValidation.diagnostics.filter(i=>i.severity==="error").length===0?e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11,color:"var(--status-success)",fontWeight:600,whiteSpace:"nowrap",fontFamily:o.font},children:[e.jsx(kt,{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:o.font},children:[e.jsx(ft,{size:12})," ",t.blockStudioValidation.diagnostics.filter(i=>i.severity==="error").length," problem",t.blockStudioValidation.diagnostics.filter(i=>i.severity==="error").length===1?"":"s"]}):e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11,color:o.textMuted,fontWeight:600,whiteSpace:"nowrap",fontFamily:o.font},children:[e.jsx(Ze,{size:12,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}})," Checking"]})]}),e.jsxs("div",{style:{flex:1,minHeight:0,display:"flex",overflow:"hidden"},children:[e.jsx("div",{style:{flex:1,minWidth:0,overflow:"hidden",background:o.cellBg,borderRight:"1px solid var(--border-subtle)"},children:e.jsx(tr,{value:t.blockStudioDraft,onChange:Fe,onRun:()=>void Mt(),themeMode:t.themeMode,autoFocus:!0,wrap:!1,fillHeight:!0,schema:$,dqlMode:!0,errorMessage:(ai=(li=t.blockStudioValidation)==null?void 0:li.diagnostics.find(i=>i.severity==="error"))==null?void 0:ai.message})}),!he&&e.jsx(Cr,{source:t.blockStudioDraft,diagnostics:((di=t.blockStudioValidation)==null?void 0:di.diagnostics)??[],parameterCount:((ui=(ci=t.blockStudioValidation)==null?void 0:ci.parameters)==null?void 0:ui.length)??0,t:o})]})]}):e.jsx(Ir,{dbtStatus:t.blockStudioDbtStatus,semanticStats:$n,semanticObjectCount:An,databaseStats:Yt,onCreateSql:()=>Nn("custom"),onCreateSemantic:()=>Nn("semantic"),onImport:()=>Ne("import"),onBuildDql:()=>bt({kind:"build",initialInput:"Draft a reusable DQL block that "}),t:o})})]}),e.jsx("div",{onMouseDown:ut?Bo:void 0,style:{gridColumn:zo,gridRow:Po,display:ut?"block":"none",cursor:"row-resize",background:o.headerBorder}}),e.jsxs("div",{style:{gridColumn:Ro,gridRow:Eo,borderTop:ut?`1px solid ${o.headerBorder}`:"none",display:ut?"flex":"none",flexDirection:"column",overflow:"hidden",background:o.cellBg},children:[e.jsxs("div",{style:{display:"flex",gap:14,alignItems:"center",padding:"0 16px",borderBottom:`1px solid ${o.headerBorder}`,flexWrap:"wrap"},children:[e.jsx(zt,{active:h==="results",onClick:()=>k("results"),label:"Results",t:o}),e.jsx(zt,{active:h==="parameters",onClick:()=>k("parameters"),label:`Run inputs${(((fi=(pi=t.blockStudioValidation)==null?void 0:pi.parameters)==null?void 0:fi.length)??0)>0?` · ${t.blockStudioValidation.parameters.length}`:""}`,t:o}),e.jsx(zt,{active:h==="lineage",onClick:()=>k("lineage"),label:"Lineage",t:o}),e.jsx(zt,{active:h==="history",onClick:()=>{k("history"),_n()},label:"History",t:o}),e.jsx(zt,{active:h==="save",onClick:()=>k("save"),label:"Metadata",t:o}),e.jsx("div",{style:{flex:1}}),t.blockStudioPreview?e.jsxs("span",{style:{fontSize:11,color:o.textMuted,fontFamily:o.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:()=>yt(!0),style:{background:"transparent",border:"none",color:o.textMuted,cursor:"pointer",fontSize:11,fontFamily:o.font,padding:"4px 6px"},title:"Hide pane",children:"▾ Hide"})]}),e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[h==="results"&&(G?e.jsx(Jr,{elapsedMs:Se}):t.blockStudioPreview?e.jsxs("div",{style:{display:"grid",gap:12,padding:12},children:[(mi=(hi=t.blockStudioPreview.invocation)==null?void 0:hi.resolvedParameters)!=null&&mi.length?e.jsx(Zr,{values:t.blockStudioPreview.invocation.resolvedParameters,t:o}):null,wo==="table"?e.jsx(Wi,{result:t.blockStudioPreview.result,themeMode:t.themeMode}):e.jsx(rr,{result:t.blockStudioPreview.result,chartConfig:t.blockStudioPreview.chartConfig,themeMode:t.themeMode}),e.jsxs("details",{open:ve,onToggle:i=>te(i.currentTarget.open),style:{border:`1px solid ${o.headerBorder}`,borderRadius:8,background:o.pillBg},children:[e.jsx("summary",{style:{cursor:"pointer",padding:"9px 11px",fontSize:11,fontWeight:700,color:o.textSecondary,fontFamily:o.font},children:"Query details"}),e.jsx("pre",{style:{margin:0,padding:"0 11px 11px",maxHeight:220,overflow:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",fontSize:10.5,lineHeight:1.45,color:o.textMuted,fontFamily:o.fontMono},children:t.blockStudioPreview.sql})]})]}):I?e.jsx(es,{message:I,technicalDetails:q,repairing:De,onFix:()=>void dn(q??I),onEdit:()=>ie("source")}):e.jsx(jt,{message:"Run the block to preview results."})),h==="lineage"&&e.jsx(Vr,{blockName:xe,loading:We,detail:wt,graph:Vi,paths:Yi,onSelectNode:i=>{n({type:"SET_LINEAGE_FOCUS",nodeId:i}),n({type:"OPEN_LINEAGE_DRAWER",nodeId:i})},onOpenInspector:()=>{if(xe){const i=`block:${xe}`;n({type:"SET_LINEAGE_FOCUS",nodeId:i}),n({type:"OPEN_LINEAGE_DRAWER",nodeId:i})}},t:o}),h==="parameters"&&e.jsx(Xr,{parameters:((gi=t.blockStudioValidation)==null?void 0:gi.parameters)??[],values:z,onChange:(i,c)=>Y(S=>({...S,[i]:c})),onReset:i=>Y(c=>{const S={...c};return delete S[i],S}),onRun:()=>void Mt(),running:G,t:o}),h==="history"&&e.jsx(ss,{entries:v,t:o}),h==="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(is,{currentStatus:t.blockStudioMetadata.reviewStatus??"draft",blockPath:t.activeBlockPath,onStatusChanged:i=>{t.blockStudioMetadata&&(n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{...t.blockStudioMetadata,reviewStatus:i}}),n({type:"SET_BLOCK_STUDIO_DRAFT",draft:ce(t.blockStudioDraft,"status",i)}))},t:o})}),Ln&&e.jsx(os,{result:Ln,t:o,repairing:De,onEditSource:()=>ie("source"),onEditParameters:()=>k("parameters"),onReviewMetrics:()=>{Nt(!1),l("semantic"),ie("visual")},onRun:()=>void Mt(),onFix:i=>void dn(i.technicalDetails??i.message,{requireCertificationReady:!0})}),e.jsx(Yr,{metadata:t.blockStudioMetadata,draftMetadata:ct,onChange:i=>{if(!t.blockStudioMetadata)return;n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{...t.blockStudioMetadata,...i}});let c=t.blockStudioDraft;typeof i.name=="string"&&(c=Lt(c,i.name)),typeof i.domain=="string"&&(c=ce(c,"domain",i.domain)),typeof i.owner=="string"&&(c=ce(c,"owner",i.owner)),typeof i.description=="string"&&(c=ce(c,"description",i.description)),i.tags&&(c=$t(c,i.tags)),Fe(c)},t:o})]})]})]}),Ye&&Tn&&e.jsx("div",{style:{position:"absolute",right:16,bottom:16},children:e.jsx("button",{onClick:()=>yt(!1),style:{background:o.btnBg,border:`1px solid ${o.btnBorder}`,borderRadius:6,color:o.textSecondary,cursor:"pointer",fontSize:12,fontFamily:o.font,padding:"8px 12px"},children:"Open Results"})}),!he&&nt&&e.jsx("div",{onMouseDown:To,style:{gridColumn:"4",gridRow:"1 / 4",cursor:"col-resize",background:o.headerBorder}}),nt&&e.jsx(fr,{t:o,title:"Block AI",subtitle:xe?`Current block: ${xe}`:"Unsaved governed block draft",expanded:In,onToggleExpanded:()=>Mn(i=>!i),onClose:()=>{nn(!1),Mn(!1)},onNewChat:()=>{f.resetThreadId(),oo(i=>i+1)},running:to,compact:he,ariaLabel:"Block Studio AI",style:{gridColumn:he?"1":"5",gridRow:he?Un:"1 / 4"},children:e.jsx(cr,{themeMode:t.themeMode,title:"Block AI",scopeHint:xe?`Current block: ${xe}`:"Block Studio project context",workspaceContext:{surface:"block-studio",task:En==="edit"?"edit_block":"author_block",draftSessionId:a,blockStudioDraft:t.blockStudioDraft,activeBlockPath:t.activeBlockPath,domain:(xi=t.blockStudioMetadata)==null?void 0:xi.domain,importId:He==null?void 0:He.id,importCandidateId:(yi=He==null?void 0:He.candidates[0])==null?void 0:yi.id,...En==="edit"?{mode:"edit",blockPath:t.activeBlockPath}:{}},initialMode:"block",initialInput:ao,autoRun:uo,threadId:f.threadId,onThreadIdChange:f.onThreadIdChange,onRunningChange:no,onInsertSql:(i,c)=>ko(i,{question:c??xe??"analysis",title:c}),onInsertDql:i=>{jo(i)},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}:${io}`)}),!nt&&!he&&e.jsx("button",{type:"button",onClick:()=>nn(!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 ${o.btnBorder}`,background:o.btnBg,color:o.accent,cursor:"pointer",boxShadow:"0 6px 18px rgba(0, 0, 0, 0.12)"},children:e.jsx(mr,{size:16,strokeWidth:2})}),gt&&t.blockStudioMetadata&&e.jsx(Br,{metadata:t.blockStudioMetadata,onCancel:()=>{D.current=null,Ve(!1)},onConfirm:i=>{let c=Lt(t.blockStudioDraft,i.name);c=ce(c,"owner",i.owner),n({type:"SET_BLOCK_STUDIO_METADATA",metadata:{...t.blockStudioMetadata,...i}}),n({type:"SET_BLOCK_STUDIO_DRAFT",draft:c}),Ve(!1)},t:o}),xt&&e.jsx(Tr,{saving:we,onCancel:()=>g(!1),onDiscard:()=>{g(!1),an()},onSave:async()=>{C.current=!0,g(!1),await cn()&&(C.current=!1,an())},t:o}),Je&&_e&&e.jsx(Dr,{blockName:_e.name,blockPath:_e.path,deleting:at,error:ht,onCancel:()=>{at||(et(!1),tt(null),Re(null))},onConfirm:()=>void bo(),t:o})]})}function wr({active:t,onClick:n,label:s,busy:r,Icon:o,variant:a="secondary",title:p}){const m=Ot[Ft(l=>l.themeMode)],f=a==="primary",E=a==="danger";return e.jsxs("button",{onClick:n,disabled:r,"aria-busy":r||void 0,title:p??s,style:{background:f?m.accent:E?`${m.error}0d`:t?`${m.accent}18`:m.btnBg,border:`1px solid ${f?m.accent:E?`${m.error}55`:t?m.accent:m.btnBorder}`,borderRadius:6,height:28,color:f?"#ffffff":E?m.error:t?m.accent:m.textSecondary,cursor:r?"wait":"pointer",display:"inline-flex",alignItems:"center",gap:6,fontSize:11,fontWeight:f?800:600,fontFamily:m.font,padding:"0 10px",whiteSpace:"nowrap",opacity:r?.7:1},children:[r?e.jsx(Ze,{size:13,strokeWidth:2,"aria-hidden":"true"}):o?e.jsx(o,{size:13,strokeWidth:2,"aria-hidden":"true"}):null,r?`${s}...`:s]})}function st(t){return e.jsx(wr,{active:!1,...t})}function Cr({source:t,diagnostics:n,parameterCount:s,t:r}){const o=t.split(`
|
|
15
|
+
`),a={block:"var(--text-tertiary)",parameters:"var(--accent)",query:"var(--status-success)",tests:"var(--status-warning)",visualization:"var(--cat-audit)"},p=[];o.forEach((l,h)=>{const k=l.match(/^\s*(block|parameters|query|tests|visualization)\b/);if(k&&!p.some(b=>b.label.toLowerCase().startsWith(k[1]))){const b=k[1],P=b==="block"?"Metadata":b==="parameters"?`Parameters${s?` · ${s}`:""}`:b.charAt(0).toUpperCase()+b.slice(1);p.push({label:P,line:h+1,color:a[b]??"var(--text-tertiary)"})}});const m=(t.match(/^\s*assert\b/gm)??[]).length,f=new Set((t.match(/\b(?:from|join)\s+([a-z_][\w.]*)/gi)??[]).map(l=>l.replace(/^(from|join)\s+/i,""))).size,E=n.filter(l=>l.severity==="error");return e.jsxs("div",{style:{width:208,flexShrink:0,background:r.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:r.textMuted,fontFamily:r.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:r.textMuted,padding:"2px 8px",fontFamily:r.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:r.textSecondary,fontFamily:r.font},children:l.label}),e.jsxs("span",{style:{fontSize:10,color:r.textMuted,fontFamily:r.fontMono},children:[":",l.line]})]},l.label))}),e.jsx("div",{style:{padding:"14px 14px 6px",fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:r.textMuted,fontFamily:r.font},children:"Problems"}),E.length===0?e.jsxs("div",{style:{padding:"0 14px",fontSize:11.5,color:"var(--status-success)",display:"flex",alignItems:"center",gap:6,fontFamily:r.font},children:[e.jsx(kt,{size:12})," No problems"]}):e.jsx("div",{style:{padding:"0 14px",display:"flex",flexDirection:"column",gap:5},children:E.slice(0,4).map((l,h)=>e.jsx("span",{style:{fontSize:11,color:"var(--status-error)",lineHeight:1.4,fontFamily:r.font},children:l.message},h))}),e.jsx("div",{style:{padding:"14px 14px 6px",fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:r.textMuted,fontFamily:r.font},children:"Context"}),e.jsxs("div",{style:{padding:"0 14px 16px",display:"flex",flexDirection:"column",gap:5,fontSize:11,color:r.textSecondary,fontFamily:r.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)"}}),s," parameter",s===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)"}}),f," model",f===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 zt({active:t,onClick:n,label:s,t:r}){return e.jsx("button",{type:"button",onClick:n,style:{padding:"9px 1px",fontSize:11.5,fontWeight:650,cursor:"pointer",border:"none",background:"none",fontFamily:r.font,whiteSpace:"nowrap",color:t?r.textPrimary:r.textMuted,boxShadow:t?`inset 0 -2px 0 0 ${r.accent}`:"none"},children:s})}function ji(t,n){return Qo(t,{variant:n?"accent":"ghost",size:"xs",active:n})}function _t(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 Br({metadata:t,onCancel:n,onConfirm:s,t:r}){const[o,a]=d.useState(t.name),[p,m]=d.useState(t.owner),f=!!(o.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 ${r.headerBorder}`,background:r.cellBg,boxShadow:"0 24px 70px rgba(0,0,0,.35)"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:15,fontWeight:850,color:r.textPrimary},children:"Save governed block"}),e.jsx("div",{style:{marginTop:4,fontSize:11,lineHeight:1.45,color:r.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(A,{label:"Block name",t:r,children:e.jsx("input",{autoFocus:!0,value:o,onChange:E=>a(E.target.value),style:ze(r)})}),e.jsx(A,{label:"Owner",t:r,children:e.jsx("input",{value:p,onChange:E=>m(E.target.value),placeholder:"analytics@company.com or team name",style:ze(r)})}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[e.jsx("button",{type:"button",onClick:n,style:Z(r),children:"Cancel"}),e.jsx("button",{type:"button",disabled:!f,onClick:()=>f&&s({name:o.trim(),owner:p.trim()}),style:{...Te(r),opacity:f?1:.55},children:"Save block"})]})]})})}function Tr({saving:t,onSave:n,onDiscard:s,onCancel:r,t:o}){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 ${o.cellBorder}`,borderRadius:12,background:o.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:o.textPrimary,fontFamily:o.font},children:"Save this block before leaving?"}),e.jsx("div",{style:{marginTop:5,fontSize:12,lineHeight:1.5,color:o.textMuted,fontFamily:o.font},children:"Your current Block Studio workspace has unsaved changes."})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[e.jsx("button",{type:"button",onClick:r,disabled:t,style:Z(o),children:"Cancel"}),e.jsx("button",{type:"button",onClick:s,disabled:t,style:{...Z(o),color:o.error},children:"Discard"}),e.jsx("button",{type:"button",onClick:()=>void n(),disabled:t,style:Te(o),children:t?"Saving…":"Save block"})]})]})})}function Dr({blockName:t,blockPath:n,deleting:s,error:r,onCancel:o,onConfirm:a,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(tn,{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."]}),r&&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:r}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[e.jsx("button",{type:"button",onClick:o,disabled:s,style:Z(p),children:"Cancel"}),e.jsx("button",{type:"button",onClick:a,disabled:s,style:{...Te(p),background:p.error,borderColor:p.error,opacity:s?.65:1},children:s?e.jsxs(e.Fragment,{children:[e.jsx(Ze,{size:13,className:"dql-spin"})," Deleting…"]}):e.jsxs(e.Fragment,{children:[e.jsx(tn,{size:13})," Delete block"]})})]})]})})}function Ir({dbtStatus:t,semanticStats:n,semanticObjectCount:s,databaseStats:r,onCreateSql:o,onCreateSemantic:a,onImport:p,onBuildDql:m,t:f}){var P;const E=[{title:"Blank SQL block",detail:"Start with an empty custom query.",action:o,label:"Create",Icon:sr},{title:"Semantic block",detail:"Build directly from governed metrics.",action:a,label:"Build",Icon:Jt}],l=!!(t!=null&&t.artifacts.manifest.exists),h=(t==null?void 0:t.counts.metrics)??n.metrics,k=t?`${t.counts.models} dbt models · ${h} MetricFlow metrics`:"Waiting for dbt artifacts",b=(t==null?void 0:t.projectName)||((P=t==null?void 0:t.projectPath)==null?void 0:P.split("/").filter(Boolean).pop())||"dbt project";return e.jsxs("div",{style:{height:"100%",overflow:"auto",padding:22,display:"grid",gap:14,alignContent:"start",background:f.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:f.textPrimary,fontFamily:f.font},children:"Create DQL blocks"}),e.jsx("div",{style:{fontSize:12,color:f.textMuted,lineHeight:1.45,marginTop:5,maxWidth:560,fontFamily:f.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":f.headerBorder}`,borderRadius:8,background:l?"#2ea0430d":f.cellBg},children:[e.jsx(kt,{size:15,strokeWidth:2,color:l?"#2ea043":f.textMuted,"aria-hidden":"true"}),e.jsx("span",{style:{fontSize:11,color:l?"#2ea043":f.textMuted,fontWeight:700,fontFamily:f.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(mn,{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:hr,onClick:m,t:f}),e.jsx(mn,{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:Ni,onClick:p,t:f}),e.jsx(mn,{title:"Build manually",detail:"Use the visual semantic builder for multiple metrics, compatible dimensions, time grain, filters, and chart intent.",label:"Open builder",Icon:Jt,onClick:a,t:f})]}),e.jsxs("details",{style:Pt(f),children:[e.jsx("summary",{style:Rt(f),children:"Manual options"}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(160px, 1fr))",gap:10},children:E.map(L=>e.jsx(Mr,{title:L.title,detail:L.detail,label:L.label,Icon:L.Icon,onClick:L.action,t:f},L.title))})]}),e.jsxs("section",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(160px, 1fr))",gap:8},children:[e.jsx(gn,{Icon:vn,label:`${b} dbt`,value:k,tone:l?"success":"neutral",t:f}),e.jsx(gn,{Icon:vn,label:"Database",value:`${r.tables} tables`,tone:r.tables>0?"success":"neutral",t:f}),e.jsx(gn,{Icon:Jt,label:"DQL semantic layer",value:`${s} objects`,tone:s>0?"success":"neutral",t:f})]})]})}function mn({title:t,detail:n,label:s,Icon:r,onClick:o,t:a}){return e.jsxs("button",{onClick:o,style:{border:`1px solid ${a.accent}`,borderRadius:8,background:a.cellBg,color:a.textPrimary,cursor:"pointer",display:"grid",gridTemplateColumns:"42px minmax(0, 1fr) auto",gap:12,alignItems:"center",padding:16,minHeight:104,textAlign:"left",fontFamily:a.font,boxShadow:`inset 0 0 0 1px ${a.accent}22`},children:[e.jsx("span",{style:{width:42,height:42,borderRadius:8,display:"inline-flex",alignItems:"center",justifyContent:"center",background:`${a.accent}18`,color:a.accent},children:e.jsx(r,{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:a.textPrimary},children:t}),e.jsx("span",{style:{fontSize:12,color:a.textMuted,lineHeight:1.4},children:n})]}),e.jsx("span",{style:{color:"#ffffff",background:a.accent,borderRadius:6,padding:"7px 10px",fontSize:11,fontWeight:800,whiteSpace:"nowrap"},children:s})]})}function Mr({title:t,detail:n,label:s,Icon:r,onClick:o,t:a}){return e.jsxs("button",{onClick:o,style:{textAlign:"left",background:a.cellBg,border:`1px solid ${a.headerBorder}`,borderRadius:8,padding:12,cursor:"pointer",color:a.textPrimary,display:"grid",gridTemplateColumns:"30px minmax(0, 1fr)",gap:10,minHeight:94,fontFamily:a.font,alignItems:"start"},children:[e.jsx("span",{style:{width:30,height:30,borderRadius:7,display:"inline-flex",alignItems:"center",justifyContent:"center",background:`${a.accent}14`,color:a.accent},children:e.jsx(r,{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:a.textPrimary},children:t}),e.jsx("span",{style:{fontSize:11,color:a.textMuted,lineHeight:1.35},children:n}),e.jsx("span",{style:{color:a.accent,fontSize:11,fontWeight:800},children:s})]})]})}function gn({Icon:t,label:n,value:s,tone:r,t:o}){const a=r==="success"?"#2ea043":o.textMuted;return e.jsxs("div",{style:{border:`1px solid ${o.headerBorder}`,borderRadius:8,background:o.cellBg,padding:"9px 10px",display:"flex",alignItems:"center",gap:8,minWidth:0},children:[e.jsx("span",{style:{color:a,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:o.textMuted,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.04em",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n}),e.jsx("span",{style:{fontSize:12,color:o.textPrimary,fontWeight:700,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s})]})]})}function zr({source:t,databaseStats:n,semanticCount:s,onChange:r,onOpenExplorer:o,onOpenAi:a,t:p}){const m=l=>{var h;return((h=t.match(new RegExp(`\\b${l}\\s*=\\s*"([^"]*)"`,"i")))==null?void 0:h[1])??""},f=l=>{var h;return(((h=t.match(new RegExp(`\\b${l}\\s*=\\s*\\[([\\s\\S]*?)\\]`,"i")))==null?void 0:h[1].match(/"([^"]*)"/g))??[]).map(k=>k.slice(1,-1))},E=[{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:o,style:Z(p),children:[n.tables," database tables"]}),e.jsx("button",{type:"button",onClick:a,style:Z(p),children:"Review with AI"})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(230px, 1fr))",gap:10},children:[e.jsx(A,{label:"Business outcome",t:p,children:e.jsx(At,{value:m("businessOutcome"),onChange:l=>r(ce(t,"businessOutcome",l)),placeholder:"Decision or outcome this block supports",style:ze(p)})}),e.jsx(A,{label:"Agent guidance",t:p,children:e.jsx(At,{value:m("llmContext"),onChange:l=>r(ce(t,"llmContext",l)),placeholder:"When to use this block",style:ze(p)})}),E.map(l=>e.jsx(Pr,{label:l.label,hint:l.hint,values:f(l.key),onChange:h=>r(Uo(t,l.key,h)),t:p},l.key)),e.jsx(A,{label:"Rules and caveats",t:p,children:e.jsx(At,{value:m("caveats"),onChange:l=>r(ce(t,"caveats",l)),placeholder:"Known limitation or interpretation rule",style:ze(p)})})]}),e.jsxs("div",{style:{fontSize:10,color:p.textMuted},children:["Available authoring context: ",s," semantic objects, ",n.schemas," schemas, ",n.columns," columns. SQL completion uses the same loaded catalog."]})]})}function Pr({label:t,hint:n,values:s,onChange:r,t:o}){const[a,p]=d.useState(""),m=()=>{const f=a.split(",").map(E=>E.trim()).filter(Boolean);f.length>0&&r([...s,...f]),p("")};return e.jsx(A,{label:t,t:o,children:e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:5,padding:6,minHeight:36,border:`1px solid ${o.cellBorder}`,borderRadius:6,background:o.cellBg},children:[s.map(f=>e.jsxs("button",{type:"button",onClick:()=>r(s.filter(E=>E!==f)),title:"Remove",style:{..._t(o,!0),border:"none",cursor:"pointer"},children:[f," ×"]},f)),e.jsx("input",{value:a,onChange:f=>p(f.target.value),onKeyDown:f=>{(f.key==="Enter"||f.key===",")&&(f.preventDefault(),m())},onBlur:m,placeholder:s.length?"Add another…":n,style:{minWidth:120,flex:1,border:"none",outline:"none",background:"transparent",color:o.textPrimary,fontSize:11,fontFamily:o.font}})]})})}function Hi({source:t,kind:n,onChange:s,t:r}){const o=d.useMemo(()=>Zo(t),[t]),[a,p]=d.useState(""),[m,f]=d.useState(""),[E,l]=d.useState(!0),[h,k]=d.useState("dynamic"),[b,P]=d.useState("auto"),L=hn(m,a),K=b==="auto"?L:b,_=ze(r),w=()=>{a.trim()&&(s(vi(t,{name:a,type:K,required:E&&!m.trim(),defaultText:m,policy:h})),p(""),f(""),l(!0),k("dynamic"),P("auto"))};return e.jsx(be,{title:"Runtime parameters",t:r,children:e.jsxs("div",{style:{display:"grid",gap:10},children:[e.jsxs("div",{style:{fontSize:11,color:r.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."]}),o.length>0&&e.jsx("div",{style:{display:"grid",gap:7},children:o.map(x=>{var re;const X=Jo(x),H=$=>s(vi(t,{name:x.name,type:$.type??x.type,required:$.required??x.required,defaultText:$.defaultText??X,policy:$.policy??x.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 ${r.cellBorder}`,borderRadius:7,background:r.cellBg},children:[e.jsxs("div",{style:{minWidth:0},children:[e.jsx("div",{style:{fontSize:11,fontWeight:800,color:r.textPrimary},children:x.name}),e.jsxs("div",{style:{fontSize:10,color:r.textMuted},children:[((re=x.binding)==null?void 0:re.kind)??"declared value"," · ",x.required?"required":"has default"]})]}),e.jsx("select",{"aria-label":`${x.name} type`,value:x.type,onChange:$=>H({type:$.target.value}),style:_,children:wi.map($=>e.jsx("option",{value:$,children:$},$))}),x.type==="boolean"?e.jsxs("select",{"aria-label":`${x.name} default`,value:X,onChange:$=>H({defaultText:$.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":`${x.name} default`,value:X,onChange:$=>{const G=$.target.value,J=x.type===hn(X,x.name);H({defaultText:G,required:G.trim()?!1:x.required,...J?{type:hn(G,x.name)}:{}})},placeholder:x.type.endsWith("[]")?"West, East":x.required?"Required value":"Default value",style:_}),e.jsx("select",{"aria-label":`${x.name} policy`,value:x.policy,onChange:$=>H({policy:$.target.value}),style:_,children:Rr.map($=>e.jsx("option",{value:$,children:$},$))}),e.jsx("button",{type:"button",onClick:()=>s(er(t,x.name)),title:`Remove ${x.name}`,style:{border:"none",background:"transparent",color:r.error,cursor:"pointer",fontSize:16,padding:"3px 5px"},children:"×"})]},x.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 ${r.btnBorder}`,borderRadius:7,background:r.appBg},children:[e.jsx("input",{"aria-label":"New parameter name",value:a,onChange:x=>p(x.target.value),onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),w())},placeholder:"region_set",style:_}),e.jsx("input",{"aria-label":"New parameter default",value:m,onChange:x=>{f(x.target.value),x.target.value.trim()&&l(!1)},onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),w())},placeholder:"Central, East or 2026-01-01",style:_}),e.jsxs("select",{"aria-label":"New parameter type",value:b,onChange:x=>P(x.target.value),style:_,children:[e.jsxs("option",{value:"auto",children:["Auto · ",L]}),wi.map(x=>e.jsx("option",{value:x,children:x},x))]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:5,color:r.textSecondary,fontSize:11,whiteSpace:"nowrap"},children:[e.jsx("input",{type:"checkbox",checked:E&&!m.trim(),onChange:x=>l(x.target.checked)})," Required"]}),e.jsx("button",{type:"button",onClick:w,disabled:!a.trim(),style:{...Te(r),opacity:a.trim()?1:.5},children:"Add"})]}),e.jsxs("div",{style:{fontSize:10,color:r.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 wi=["string","number","boolean","date","string[]","number[]","date[]"],Rr=["dynamic","static","business","derived","optional","ambiguous_review_required"];function Er({metadata:t,source:n,parameters:s,preview:r,lastRun:o,lineageDetail:a,isSemanticBlock:p,running:m,onOpenBuilder:f,onOpenSource:E,onDelete:l,onRun:h,onOpenHistory:k,t:b}){var te,Q,ue,Se,Pe;const P=((t==null?void 0:t.reviewStatus)??"").toLowerCase()==="certified",L=(t==null?void 0:t.name)||"block",K=p?Ei(n):null,_=((Q=(te=n.match(/query\s*=\s*"""([\s\S]*?)"""/i))==null?void 0:te[1])==null?void 0:Q.trim())??"",w=K?Array.from(new Set([...K.dimensions,...K.timeDimension?[K.timeDimension]:[],...K.metrics])):Gi(_),x=(n.match(/^\s*assert\b.*$/gm)??[]).map(z=>z.trim()),X=((ue=a==null?void 0:a.incoming)==null?void 0:ue.length)??0,H=((Se=a==null?void 0:a.outgoing)==null?void 0:Se.length)??0,[re,$]=d.useState(!1),G=((a==null?void 0:a.incoming)??[]).map(z=>{var Y;return(Y=z.node)==null?void 0:Y.name}).filter(Boolean).slice(0,3),J=((a==null?void 0:a.outgoing)??[]).map(z=>{var Y;return(Y=z.node)==null?void 0:Y.name}).filter(Boolean).slice(0,3),I={fontSize:11,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:b.textMuted,marginBottom:8,fontFamily:b.font},N=(z,Y=!1)=>e.jsx("span",{style:{padding:"3px 9px",borderRadius:999,border:`1px solid ${Y?`${b.accent}59`:b.headerBorder}`,background:Y?"var(--accent-dim)":"var(--bg-1)",color:Y?b.accent:b.textSecondary,fontFamily:b.fontMono,fontWeight:Y?600:400,fontSize:11.5},children:z},z),q=e.jsx("span",{style:{color:b.textMuted,fontSize:11},children:"→"}),V=(r==null?void 0:r.result.executionTime)??(o==null?void 0:o.executionTime),ve=[["Last run",r||o?typeof V=="number"?`${(V/1e3).toFixed(1)}s`:"Completed":"Not run yet"],["Rows",r?String(r.result.rowCount??r.result.rows.length):o?String(o.rowCount):"—"],["Used in",H>0?`${H} downstream`:"—"],["Tests",x.length>0?`${x.length} declared`:"None yet"]];return e.jsx("div",{style:{height:"100%",overflow:"auto",background:b.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:b.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:P?"var(--status-success-bg)":"var(--accent-dim)",color:P?"var(--status-success)":b.accent,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:"1px solid var(--border-subtle)"},children:e.jsx(Jt,{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:b.textPrimary,fontFamily:b.fontMono,letterSpacing:"-0.01em"},children:L}),t!=null&&t.reviewStatus?e.jsx(Oi,{status:t.reviewStatus,t:b}):null]}),e.jsx("div",{style:{fontSize:12,color:b.textMuted,marginTop:4},children:[t==null?void 0:t.domain,t!=null&&t.folderPath?`folder: ${t.folderPath}`:null,t==null?void 0:t.owner,...(Pe=t==null?void 0:t.tags)!=null&&Pe.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:f,style:{display:"inline-flex",alignItems:"center",gap:7,height:32,padding:"0 14px",borderRadius:8,border:"none",background:b.accent,color:"#fff",fontSize:12.5,fontWeight:650,cursor:"pointer",fontFamily:b.font,boxShadow:"0 1px 4px rgba(107,93,211,0.25)"},children:[e.jsx(lr,{size:13,strokeWidth:1.75})," Open in builder"]}),e.jsxs("button",{type:"button",onClick:h,disabled:m,style:{display:"inline-flex",alignItems:"center",gap:6,height:32,padding:"0 13px",borderRadius:8,border:`1px solid ${b.headerBorder}`,background:b.cellBg,color:b.textSecondary,fontSize:12.5,fontWeight:600,cursor:"pointer",fontFamily:b.font,opacity:m?.7:1},children:[m?e.jsx(Ze,{size:12,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):e.jsx(qi,{size:11,fill:"currentColor"})," Run"]}),e.jsx("button",{type:"button","aria-label":`Delete ${L}`,title:"Delete block",onClick:l,style:{width:32,height:32,borderRadius:8,border:`1px solid ${b.error}55`,background:`${b.error}0d`,color:b.error,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer"},children:e.jsx(tn,{size:14})}),e.jsx("button",{type:"button",title:"History and metadata",onClick:k,style:{width:32,height:32,borderRadius:8,border:`1px solid ${b.headerBorder}`,background:b.cellBg,color:b.textMuted,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer"},children:e.jsx(ar,{size:15})})]})]}),t!=null&&t.description?e.jsx("div",{style:{fontSize:13.5,lineHeight:1.6,color:b.textSecondary,maxWidth:640},children:t.description}):null,e.jsx("div",{style:{display:"flex",border:"1px solid var(--border-subtle)",borderRadius:10,background:b.cellBg,overflow:"hidden"},children:ve.map(([z,Y],we)=>e.jsxs("div",{style:{flex:1,padding:"12px 16px",borderRight:we<ve.length-1?"1px solid var(--border-subtle)":"none"},children:[e.jsx("div",{style:{fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:b.textMuted},children:z}),e.jsx("div",{style:{fontSize:14,fontWeight:650,color:b.textPrimary,marginTop:3},children:Y})]},z))}),e.jsxs("div",{children:[e.jsx("div",{style:I,children:"Outputs"}),e.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:w.length>0?w.map(z=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11.5,padding:"4px 10px",borderRadius:999,background:"var(--accent-dim)",color:b.accent,border:`1px solid ${b.accent}33`,fontFamily:b.fontMono},children:z},z)):e.jsx("span",{style:{fontSize:11.5,color:b.textMuted},children:"Open the builder to define outputs."})})]}),e.jsxs("div",{children:[e.jsx("div",{style:I,children:"Parameters"}),e.jsxs("div",{style:{border:"1px solid var(--border-subtle)",borderRadius:9,overflow:"hidden",background:b.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:b.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"})]}),s.length===0?e.jsx("div",{style:{padding:"9px 12px",fontSize:12,color:b.textMuted},children:"No parameters — this block always runs the same way."}):s.map((z,Y)=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1.2fr 0.8fr 1fr 0.9fr",gap:8,padding:"8px 12px",borderBottom:Y<s.length-1?"1px solid var(--border-subtle)":"none",fontSize:12,alignItems:"center"},children:[e.jsx("span",{style:{fontFamily:b.fontMono,fontWeight:600,color:b.textPrimary},children:z.name}),e.jsx("span",{style:{color:b.textSecondary},children:z.type}),e.jsx("span",{style:{fontFamily:b.fontMono,color:z.default!==void 0&&z.default!==null&&z.default!==""?"var(--status-warning)":b.textMuted},children:z.default!==void 0&&z.default!==null&&z.default!==""?JSON.stringify(z.default):z.required?"required":"—"}),e.jsx("span",{style:{color:b.textMuted},children:z.policy})]},z.name))]})]}),e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[e.jsx("span",{style:{...I,marginBottom:0},children:"DQL source"}),e.jsxs("button",{type:"button",onClick:E,style:{display:"inline-flex",alignItems:"center",gap:5,border:"none",background:"none",color:b.accent,fontSize:11.5,fontWeight:600,cursor:"pointer",fontFamily:b.font,padding:0},children:["Open in DQL Source ",e.jsx(bn,{size:11,strokeWidth:2})]})]}),e.jsx("pre",{style:{margin:0,border:"1px solid var(--border-subtle)",background:b.cellBg,borderRadius:9,padding:"13px 15px",fontSize:11.5,lineHeight:1.65,fontFamily:b.fontMono,whiteSpace:"pre",overflowX:"auto",color:b.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:I,children:"Tests"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:x.length>0?x.map(z=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12},children:[e.jsx(kt,{size:13,color:"var(--status-success)",strokeWidth:2,style:{flexShrink:0}}),e.jsx("span",{style:{fontFamily:b.fontMono,color:b.textSecondary},children:z})]},z)):e.jsx("span",{style:{fontSize:11.5,color:b.textMuted},children:"No tests yet — add assertions in the builder before certification."})})]}),e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>$(z=>!z),style:{display:"flex",alignItems:"center",gap:6,border:"none",background:"none",cursor:"pointer",padding:0,fontFamily:b.font,marginBottom:8},children:[e.jsx(bn,{size:11,color:b.textMuted,strokeWidth:2,style:{transform:re?"rotate(90deg)":"none",transition:"transform 0.12s"}}),e.jsx("span",{style:{fontSize:11,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:b.textMuted},children:"Lineage"}),re?null:e.jsxs("span",{style:{fontSize:10.5,color:b.textMuted},children:[X," upstream · ",H," downstream"]})]}),re?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap",fontSize:11.5,animation:"dql-agent-fadein 0.18s ease-out"},children:[G.length>0?G.map(z=>N(z)):N("no upstream"),q,N(L,!0),q,J.length>0?J.map(z=>N(z)):N("no downstream yet")]}):null]})]})]})})}function Lr({source:t,metadata:n,semanticLayer:s,dbtStatus:r,domainOptions:o,chartConfig:a,onChange:p,onMetadataChange:m,onOpenAi:f,onSetupRuntime:E,t:l}){const h=Ei(t),k={...h,filters:h.requestedFilters},[b,P]=d.useState([]),[L,K]=d.useState(!1),[_,w]=d.useState(null),[x,X]=d.useState(null),[H,re]=d.useState(0);d.useEffect(()=>{let u=!1;if(k.metrics.length===0){P([]),w(null),X(null),K(!1);return}return P([]),w(null),K(!0),X(null),W.getCompatibility(k.metrics).then(M=>{u||(w(M),P(M.dimensions))}).catch(M=>{u||(P([]),X(M instanceof Error?M.message:String(M)))}).finally(()=>{u||K(!1)}),()=>{u=!0}},[s.dimensions,k.metrics.join("|"),H]);const $=new Set(b.flatMap(u=>[u.reference??u.name,u.name])),G=new Map(b.flatMap(u=>[[u.reference??u.name,u.qualifiedName??void 0],[u.name,u.qualifiedName??void 0]])),J=new Map(((_==null?void 0:_.incompatible)??[]).map(u=>[u.name,kr(u.reason)])),I=new Map(b.flatMap(u=>[[u.reference??u.name,u],[u.name,u]])),N=Array.from(new Map([...s.dimensions,...s.timeDimensions].map(u=>{const M=u.reference??u.name;return[M,{...u,name:M}]})).values()),q=new Map(N.flatMap(u=>[[u.name,u],[u.reference??u.name,u]])),V=b.map(u=>{const M=u.reference??u.name;return{...q.get(M)??q.get(u.name),...u,name:M}}),ve=V.filter(u=>u.isTimeDimension||u.type==="time"),te=jn(l),[Q,ue]=d.useState(""),[Se,Pe]=d.useState(""),z=d.useMemo(()=>new Map(s.metrics.map(u=>[u.name,u])),[s.metrics]),Y=d.useMemo(()=>new Map([...N,...V].flatMap(u=>[[u.name,u],[u.reference??u.name,u]])),[N,V]),we=d.useMemo(()=>Ci(s.metrics,Q),[s.metrics,Q]),pe=d.useMemo(()=>Ci(V,Se),[V,Se]),De=$i(t,"tests"),ge=Array.from(new Set([...k.dimensions,...k.timeDimension?[k.timeDimension]:[],...k.metrics])),Ae=(u,M)=>{m({[u]:M}),p(u==="name"?Lt(t,M):ce(t,u,M))},ke=u=>{const M=k.metrics.includes(u)?k.metrics.filter(ee=>ee!==u):[...k.metrics,u];p(Pi(t,M))},Ie=u=>p(Ri(t,"dimensions",u)),Ce=u=>{const M=k.dimensions.includes(u)?k.dimensions.filter(ee=>ee!==u):[...k.dimensions,u];Ie(M)};return d.useEffect(()=>{if(!_||k.metrics.length===0)return;const u=Ko(t,Array.from($));u!==t&&p(u)},[_,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(Qi,{metadata:n,domains:o,onTextChange:Ae,onFolderChange:u=>m({folderPath:u}),onTagsChange:u=>{m({tags:u}),p($t(t,u))},t:l}),e.jsxs(be,{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 · ",k.metrics.length," selected"]}),L&&e.jsx("span",{style:{fontSize:10,color:l.textMuted},children:"Checking compatibility…"})]}),e.jsx(Bi,{kind:"metric",total:s.metrics.length,search:Q,onSearchChange:ue,matches:we,pool:s.metrics,selected:k.metrics,resolveLabel:u=>{var M;return((M=z.get(u))==null?void 0:M.label)||u},onToggle:ke,compatible:u=>{var M,ee,ae,fe;return((ee=(M=z.get(u))==null?void 0:M.execution)==null?void 0:ee.status)!=="requires_setup"&&((fe=(ae=z.get(u))==null?void 0:ae.execution)==null?void 0:fe.status)!=="unsupported"},t:l}),s.metrics.some(u=>u.execution&&u.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:E,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 ",Sr[_.engine]??_.engine]}),_.degraded&&e.jsx("span",{style:{color:"var(--status-warning)"},children:_.degraded})]}),x&&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(ft,{size:14,style:{flexShrink:0}}),e.jsxs("span",{style:{flex:1},children:["Could not verify governed dimensions: ",x,". Dimension selection is paused so an unapproved join cannot be saved."]}),e.jsx("button",{type:"button",onClick:()=>re(u=>u+1),style:Z(l),children:"Retry"})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 150px",gap:8},children:[e.jsx(A,{label:"Time dimension",t:l,children:e.jsxs("select",{disabled:k.metrics.length===0||L||!!x,value:k.timeDimension,onChange:u=>p(bi(t,"time_dimension",u.target.value)),style:{...te,opacity:k.metrics.length===0||L||x?.6:1},children:[e.jsx("option",{value:"",children:"None"}),ve.map(u=>e.jsxs("option",{value:u.reference??u.name,children:[u.label||u.name," · ",u.name]},u.reference??u.name))]})}),e.jsx(A,{label:"Grain",t:l,children:e.jsxs("select",{value:k.granularity,onChange:u=>p(bi(t,"granularity",u.target.value)),style:te,children:[e.jsx("option",{value:"",children:"None"}),jr(k.timeDimension,I,s.timeDimensions).map(u=>e.jsx("option",{value:u,children:u},u))]})})]}),s.metrics.length===0&&(s.loading?e.jsxs("div",{role:"status",style:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:l.textMuted,lineHeight:1.45},children:[e.jsx(Ze,{size:14,className:"dql-spin"}),"Loading ",((r==null?void 0:r.counts.metrics)??0).toLocaleString()," semantic metrics from parsed dbt artifacts… Large catalogs continue loading in the background."]}):((r==null?void 0:r.counts.metrics)??0)>0||r!=null&&r.artifacts.semanticManifest.exists?e.jsxs("div",{role:"alert",style:{fontSize:12,color:"var(--status-warning)",lineHeight:1.45},children:["dbt artifacts contain ",((r==null?void 0:r.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."})),k.metrics.length>1&&_&&b.length===0&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#d29922",fontSize:11,lineHeight:1.4},children:[e.jsx(ft,{size:14})," These metrics do not expose a common dimension or join path.",e.jsx("button",{type:"button",onClick:f,style:Z(l),children:"Resolve with AI"})]})]}),e.jsxs(be,{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(A,{label:"Type",t:l,children:e.jsxs("select",{value:a.chart??"table",onChange:u=>p(Ue(t,{...a,chart:u.target.value})),style:te,children:[e.jsx("option",{value:"table",children:"Table"}),Fi.map(u=>e.jsx("option",{value:u.value,children:u.label},u.value))]})}),e.jsx(A,{label:"X axis",t:l,children:e.jsxs("select",{value:a.x??"",onChange:u=>p(Ue(t,{...a,x:u.target.value})),style:te,children:[e.jsx("option",{value:"",children:"Auto"}),ge.map(u=>e.jsx("option",{value:u,children:Xe(u)},u))]})}),e.jsx(A,{label:"Y axis",t:l,children:e.jsxs("select",{value:a.y??"",onChange:u=>p(Ue(t,{...a,y:u.target.value})),style:te,children:[e.jsx("option",{value:"",children:"Auto"}),ge.map(u=>e.jsx("option",{value:u,children:Xe(u)},u))]})}),e.jsx(A,{label:"Series / color",t:l,children:e.jsxs("select",{value:a.color??"",onChange:u=>p(Ue(t,{...a,color:u.target.value})),style:te,children:[e.jsx("option",{value:"",children:"None"}),ge.map(u=>e.jsx("option",{value:u,children:Xe(u)},u))]})})]}),e.jsx(A,{label:"Title",t:l,children:e.jsx("input",{value:a.title??"",onChange:u=>p(Ue(t,{...a,title:u.target.value})),placeholder:"Chart title",style:te})})]}),e.jsx(be,{title:"Dimensions",hint:"Governed group-bys checked against the metric's join path.",t:l,children:k.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."}):L?e.jsxs("div",{role:"status",style:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:l.textMuted},children:[e.jsx(Ze,{size:14,className:"dql-spin"}),"Checking common governed dimensions…"]}):x?e.jsx("div",{style:{fontSize:12,color:"var(--status-warning)"},children:"Dimension selection is unavailable until compatibility succeeds."}):V.length===0?e.jsx("div",{style:{fontSize:12,color:l.textMuted},children:"No dimensions are loaded yet."}):e.jsx(Bi,{kind:"dimension",total:V.length,search:Se,onSearchChange:Pe,matches:pe,pool:V,selected:k.dimensions,resolveLabel:u=>{var M;return((M=Y.get(u))==null?void 0:M.label)||u},resolveMachineName:u=>{var M;return G.get(u)??((M=Y.get(u))==null?void 0:M.name)??u},reasonFor:u=>J.get(u),onToggle:Ce,compatible:u=>$.has(u),disabled:k.metrics.length===0||L||!!x,emptyHint:L?"Checking common governed dimensions…":x?"Retry compatibility before selecting dimensions.":"Choose a metric first; dimensions are checked against its governed join path.",t:l})}),e.jsxs(be,{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([...k.dimensions,...k.timeDimension?[k.timeDimension]:[]])).map(u=>{var ee;const M=k.filters.includes(u);return e.jsx("button",{type:"button",onClick:()=>p(Go(t,M?k.filters.filter(ae=>ae!==u):[...k.filters,u])),style:_t(l,M),children:((ee=Y.get(u))==null?void 0:ee.label)||u},u)})}),e.jsx("div",{style:{fontSize:10,color:l.textMuted,marginTop:8},children:k.dimensions.length===0&&!k.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."}),k.filters.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginTop:8},children:k.filters.map(u=>e.jsxs("span",{style:_t(l,!0),children:[Xe(u)," · dynamic"]},u))})]}),e.jsx(Hi,{source:t,kind:"semantic",onChange:p,t:l}),e.jsx(be,{title:`Output fields${ge.length?` · ${ge.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:ge.length>0?ge.map(u=>e.jsx("span",{style:_t(l,!0),children:Xe(u)},u)):e.jsx("span",{style:{fontSize:11,color:l.textMuted},children:"Select metrics and dimensions to define outputs."})})}),e.jsx(be,{title:"Tests",hint:"Assertions checked on every run and required for certification.",t:l,children:e.jsx(At,{multiline:!0,value:De,onChange:u=>p(Ai(t,"tests",u)),placeholder:`assert row_count >= 1
|
|
16
|
+
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 Qi({metadata:t,domains:n,onTextChange:s,onFolderChange:r,onTagsChange:o,t:a}){const p=vr(t==null?void 0:t.domain,n),m=jn(a);return e.jsx(be,{title:"Details",hint:"Name, ownership, and where this block lives.",t:a,children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[e.jsx(A,{label:"Block name",t:a,children:e.jsx("input",{value:(t==null?void 0:t.name)??"",onChange:f=>s("name",f.target.value),style:{...m,fontFamily:a.fontMono}})}),e.jsx(A,{label:"Domain",t:a,children:e.jsxs("select",{"aria-label":"Block domain",value:(t==null?void 0:t.domain)??"",onChange:f=>s("domain",f.target.value),style:m,children:[e.jsx("option",{value:"",children:"Select domain…"}),p.map(f=>e.jsx("option",{value:f.value,disabled:f.disabled,children:f.label},f.value))]})}),e.jsx(A,{label:"Owner",t:a,children:e.jsx("input",{value:(t==null?void 0:t.owner)??"",onChange:f=>s("owner",f.target.value),placeholder:"Required to save",style:m})}),e.jsx(A,{label:"Tags",t:a,children:e.jsx(_i,{values:(t==null?void 0:t.tags)??[],onChange:o,placeholder:"finance, emea",style:m})}),e.jsxs("div",{style:{gridColumn:"1 / -1"},children:[e.jsx(A,{label:"Folder (optional)",t:a,children:e.jsx("input",{"aria-label":"Block folder",value:(t==null?void 0:t.folderPath)??"",onChange:f=>r(f.target.value),placeholder:"executive/monthly",style:{...m,fontFamily:a.fontMono}})}),e.jsx("div",{style:{marginTop:5,fontSize:10,color:a.textMuted,fontFamily:a.fontMono},children:Ki(t)})]}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(A,{label:"Description",t:a,children:e.jsx("input",{value:(t==null?void 0:t.description)??"",onChange:f=>s("description",f.target.value),placeholder:"What business question does this answer?",style:m})})})]})})}function Ci(t,n){const s=n.trim().toLowerCase();return s.length<2?[]:t.filter(r=>[r.name,r.label,r.description,r.domain].filter(Boolean).some(o=>o.toLowerCase().includes(s))).slice(0,30)}function Bi({kind:t,total:n,search:s,onSearchChange:r,matches:o,pool:a=[],selected:p,resolveLabel:m,resolveMachineName:f,reasonFor:E,onToggle:l,compatible:h=()=>!0,disabled:k=!1,emptyHint:b,t:P}){const[L,K]=d.useState(!1),_=d.useRef(null),w=d.useRef(null),x=t==="metric"?"measures":"dimensions",X=t==="metric"?"Σ":"ab",H=t==="metric"?"var(--accent)":"var(--status-success)",re=t==="metric"?"var(--accent-dim)":"var(--status-success-bg)",$=s.trim().length>=2,G=$?o:a.filter(I=>!p.includes(I.name)).slice(0,8),J=()=>{K(!1),r("")};return d.useEffect(()=>{if(!L)return;requestAnimationFrame(()=>{var q;return(q=_.current)==null?void 0:q.focus()});const I=q=>{w.current&&!w.current.contains(q.target)&&J()},N=q=>{q.key==="Escape"&&J()};return document.addEventListener("mousedown",I),document.addEventListener("keydown",N),()=>{document.removeEventListener("mousedown",I),document.removeEventListener("keydown",N)}},[L]),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap",marginTop:9},children:[p.map(I=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11.5,padding:"4px 9px",borderRadius:999,background:re,color:H,border:`1px solid ${t==="metric"?"rgba(107,93,211,0.2)":"rgba(46,139,87,0.25)"}`,fontFamily:P.fontMono},children:[t==="metric"?`Σ ${m(I)}`:m(I),e.jsx("button",{type:"button",onClick:()=>l(I),title:`Remove ${m(I)}`,style:{border:"none",background:"none",color:H,cursor:"pointer",padding:0,fontSize:12,lineHeight:1,fontFamily:"inherit"},children:"×"})]},I)),e.jsxs("span",{ref:w,style:{position:"relative"},children:[e.jsxs("button",{type:"button",disabled:k,onClick:()=>K(I=>!I),title:k?b:`Add ${t}`,style:{border:"1.5px dashed var(--border-strong)",background:"transparent",borderRadius:999,padding:"4px 10px",fontSize:11,fontFamily:P.font,color:k?P.textMuted:P.textSecondary,cursor:k?"not-allowed":"pointer",opacity:k?.6:1},children:["+ Add ",t]}),L&&!k?e.jsxs("div",{style:{position:"absolute",right:0,top:30,zIndex:40,width:300,background:P.cellBg,border:`1px solid ${P.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(Xo,{size:12,color:P.textMuted,style:{flexShrink:0}}),e.jsx("input",{ref:_,value:s,onChange:I=>r(I.target.value),placeholder:`Search ${n.toLocaleString()} ${x}…`,style:{flex:1,border:"none",background:"none",outline:"none",fontSize:12,fontFamily:P.font,color:P.textPrimary,minWidth:0}}),e.jsx("button",{type:"button",onClick:J,style:{border:"none",background:"none",color:P.textMuted,cursor:"pointer",padding:0,fontSize:13,lineHeight:1},children:"×"})]}),e.jsx("div",{style:{maxHeight:208,overflow:"auto"},children:G.length===0?e.jsx("div",{style:{padding:10,fontSize:11,color:P.textMuted},children:$?`No ${x} match “${s}”.`:`No more ${x} to add.`}):G.map(I=>{const N=p.includes(I.name),q=h(I.name),V=(f==null?void 0:f(I.name))??I.name,ve=V!==(I.label||I.name),te=q?void 0:(E==null?void 0:E(I.name))??"Not compatible with every selected metric";return e.jsxs("button",{type:"button",disabled:!q,onClick:()=>{l(I.name),N||J()},title:te??I.description??V,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",border:"none",background:N?re:"none",cursor:q?"pointer":"not-allowed",textAlign:"left",fontFamily:P.font,borderBottom:"1px solid var(--border-subtle)",opacity:q?1:.5},children:[e.jsx("span",{style:{flexShrink:0,width:16,height:16,borderRadius:4,background:re,color:H,display:"inline-flex",alignItems:"center",justifyContent:"center",fontSize:t==="metric"?10:9,fontWeight:700,fontFamily:P.fontMono},children:X}),e.jsxs("span",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:1,overflow:"hidden"},children:[e.jsx("span",{style:{fontSize:12,fontFamily:P.font,color:P.textPrimary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:I.label||I.name}),ve?e.jsx("span",{style:{fontSize:10,fontFamily:P.fontMono,color:P.textMuted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:V}):null]}),e.jsx("span",{style:{flexShrink:0,fontSize:10,color:P.textMuted},children:I.domain||I.type||""})]},I.name)})}),e.jsx("div",{style:{padding:"6px 10px",background:"var(--bg-1)",fontSize:10,color:P.textMuted},children:$?`${G.length} match${G.length===1?"":"es"} · certified shown first`:`Showing top ${G.length} of ${n.toLocaleString()} · type to search all`})]}):null]})]})}function $r({mode:t,onModeChange:n,t:s}){const r=[{key:"semantic",label:"Semantic picker"},{key:"custom",label:"Raw SQL"}];return e.jsx("div",{style:{flexShrink:0,borderBottom:`1px solid ${s.headerBorder}`,background:s.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:s.textMuted},children:"Query"}),e.jsx("div",{style:{display:"inline-flex",alignItems:"center",gap:2,padding:2,border:`1px solid ${s.headerBorder}`,borderRadius:8,background:s.cellBg},children:r.map(o=>{const a=o.key===t;return e.jsx("button",{type:"button",onClick:()=>n(o.key),style:{border:"none",borderRadius:6,padding:"5px 12px",fontSize:12,fontWeight:600,cursor:"pointer",fontFamily:s.font,background:a?"var(--accent-dim)":"transparent",color:a?s.accent:s.textMuted},children:o.label},o.key)})}),e.jsx("span",{style:{fontSize:11,color:s.textMuted,fontFamily:s.font},children:t==="semantic"?"Pick governed metrics & dimensions — they compile to DQL.":"Write SQL and convert it into a governed DQL script."})]})})}function Ar({source:t,metadata:n,domainOptions:s,chartConfig:r,onChange:o,onMetadataChange:a,onConvertToDql:p,t:m}){var K,_;const f=jn(m),E=((_=(K=t.match(/query\s*=\s*"""([\s\S]*?)"""/i))==null?void 0:K[1])==null?void 0:_.trim())??"",[l,h]=d.useState(E),k=Gi(l),b=$i(t,"tests"),P=w=>{h(w),o(Li(t,w))},L=(w,x)=>{a({[w]:x}),o(w==="name"?Lt(t,x):ce(t,w,x))};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(Qi,{metadata:n,domains:s,onTextChange:L,onFolderChange:w=>a({folderPath:w}),onTagsChange:w=>{a({tags:w}),o($t(t,w))},t:m}),e.jsxs(be,{title:"Query",hint:"Write raw SQL — it compiles into a governed DQL script.",t:m,children:[e.jsx("textarea",{rows:7,value:l,onChange:w=>P(w.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
|
|
17
|
+
category,
|
|
18
|
+
SUM(revenue) AS revenue
|
|
19
|
+
FROM {{ ref('orders') }}
|
|
20
|
+
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(be,{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(A,{label:"Type",t:m,children:e.jsxs("select",{value:r.chart??"table",onChange:w=>o(Ue(t,{...r,chart:w.target.value})),style:f,children:[e.jsx("option",{value:"table",children:"Table"}),Fi.map(w=>e.jsx("option",{value:w.value,children:w.label},w.value))]})}),e.jsx(A,{label:"X axis",t:m,children:e.jsxs("select",{value:r.x??"",onChange:w=>o(Ue(t,{...r,x:w.target.value})),style:f,children:[e.jsx("option",{value:"",children:"Auto"}),k.map(w=>e.jsx("option",{value:w,children:Xe(w)},w))]})}),e.jsx(A,{label:"Y axis",t:m,children:e.jsxs("select",{value:r.y??"",onChange:w=>o(Ue(t,{...r,y:w.target.value})),style:f,children:[e.jsx("option",{value:"",children:"Auto"}),k.map(w=>e.jsx("option",{value:w,children:Xe(w)},w))]})}),e.jsx(A,{label:"Series / color",t:m,children:e.jsxs("select",{value:r.color??"",onChange:w=>o(Ue(t,{...r,color:w.target.value})),style:f,children:[e.jsx("option",{value:"",children:"None"}),k.map(w=>e.jsx("option",{value:w,children:Xe(w)},w))]})})]}),e.jsx(A,{label:"Title",t:m,children:e.jsx("input",{value:r.title??"",onChange:w=>o(Ue(t,{...r,title:w.target.value})),style:f})})]}),e.jsx(be,{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:k.length>0?k.map(w=>e.jsx("span",{style:_t(m,!0),children:Xe(w)},w)):e.jsx("span",{style:{fontSize:11,color:m.textMuted},children:"Add aliases in DQL Source to expose business-friendly output names."})})}),e.jsx(Hi,{source:t,kind:"custom",onChange:o,t:m}),e.jsx(be,{title:"Tests",hint:"Assertions checked on every run and required for certification.",t:m,children:e.jsx(At,{multiline:!0,value:b,onChange:w=>o(Ai(t,"tests",w)),placeholder:`assert row_count >= 1
|
|
21
|
+
assert revenue >= 0`,style:{...f,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 _r({semanticChoice:t,databaseWarning:n,onDismiss:s,onInsertAdvanced:r,onCreateSemantic:o,t:a}){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 ${a.headerBorder}`,background:`${a.accent}10`,display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,color:a.textSecondary,lineHeight:1.4,flex:1,minWidth:260},children:p}),t&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:o,style:Z(a),children:"Create Semantic Block"}),e.jsx("button",{onClick:r,style:Te(a),children:"Insert advanced ref"})]}),e.jsx("button",{onClick:s,style:Z(a),children:"Dismiss"})]})}function Sn(t){var s,r,o,a,p;const n=((r=(s=t.preview)==null?void 0:s.result)==null?void 0:r.rowCount)??((p=(a=(o=t.preview)==null?void 0:o.result)==null?void 0:a.rows)==null?void 0:p.length);return typeof n=="number"?n:void 0}function Wt(t){return t?t.startsWith("blocks/_drafts/")||/^domains\/[^/]+\/blocks\/_drafts\//.test(t):!1}function lt(t){var n,s,r,o,a;return t.reviewStatus==="saved"?{id:t.id,name:t.name,sourcePath:t.sourcePath,status:"saved",rows:Sn(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:((s=t.validation.diagnostics.find(p=>p.severity==="error"))==null?void 0:s.message)??"DQL validation needs attention."}:t.preview?{id:t.id,name:t.name,sourcePath:t.sourcePath,status:"ready",rows:Sn(t),savedPath:t.savedPath,message:Wt(t.savedPath)?"Preview ran successfully. Draft is saved for review.":"Preview ran successfully. Nothing is written until you save."}:((r=t.draftSave)==null?void 0:r.status)==="saved"||Wt(t.savedPath)?{id:t.id,name:t.name,sourcePath:t.sourcePath,status:"ready",savedPath:((o=t.draftSave)==null?void 0:o.path)??t.savedPath,message:"Draft saved. Run preview, then certify when ready."}:((a=t.draftSave)==null?void 0:a.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 Wr(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 Fr(t,n){for(let s=0;s<240;s+=1){const r=await W.getDqlGenerationSession(t);if(n(r),r.candidates.every(o=>o.analysisStatus==="ready"||o.analysisStatus==="needs_attention"))return r;await new Promise(o=>window.setTimeout(o,500))}throw new Error("Import analysis is still running. You can leave this workspace and resume the session later.")}async function Or(t,n,s){let r=0;const o=Array.from({length:Math.min(Math.max(1,n),t.length)},async()=>{for(;r<t.length;){const a=r;r+=1,await s(t[a])}});await Promise.all(o)}function en(t){return!!(t.generationMode||t.draftSave||Wt(t.savedPath))}function qr(t){return t==="creating"?"Reading SQL":t==="running"?"Running previews":t==="saving"?"Saving blocks":t==="complete"?"Import complete":"Ready"}function Nr(t){return t==="needs_attention"?"needs attention":t.replace("_"," ")}function Hr(t){return t==="saved"||t==="ready"?"ok":t==="needs_attention"?"warn":"info"}function Qr({session:t,sessions:n,sessionsLoading:s,onClose:r,onSessionChange:o,onRefreshSessions:a,onSelectCandidate:p,onSavedCandidate:m,defaultDomain:f,defaultOwner:E,themeMode:l,t:h,inline:k=!1}){const[b,P]=d.useState("paste"),[L,K]=d.useState(""),[_,w]=d.useState(""),[x,X]=d.useState([]),[H,re]=d.useState(f),[$,G]=d.useState(E),[J,I]=d.useState(null),[N,q]=d.useState(!1),[V,ve]=d.useState(!1),[te,Q]=d.useState(null),[ue,Se]=d.useState(null),[Pe,z]=d.useState(!1),[Y,we]=d.useState(!0),[pe,De]=d.useState(""),[ge,Ae]=d.useState(!1),[ke,Ie]=d.useState({}),[Ce,u]=d.useState("idle"),[M,ee]=d.useState({}),ae=d.useMemo(()=>t?t.candidates.find(g=>g.id===J)??t.candidates[0]??null:null,[t,J]);d.useEffect(()=>{if(!(t!=null&&t.candidates.length)){I(null);return}(!J||!t.candidates.some(g=>g.id===J))&&I(t.candidates[0].id)},[t,J]),d.useEffect(()=>{Ie({})},[t==null?void 0:t.id]),d.useEffect(()=>{we(!(t!=null&&t.candidates.length))},[t==null?void 0:t.id,t==null?void 0:t.candidates.length]),d.useEffect(()=>{if(!t){ee({}),u("idle");return}ee(Object.fromEntries(t.candidates.map(g=>[g.id,lt(g)]))),u(g=>g==="idle"?"complete":g)},[t==null?void 0:t.id]);const fe=d.useMemo(()=>{const g=pe.trim().toLowerCase(),T=(t==null?void 0:t.candidates)??[];return g?T.filter(D=>[D.name,D.domain,D.sourcePath,D.description,...D.lineage.sourceTables].some(C=>C.toLowerCase().includes(g))):T},[pe,t]),Ke=ge||pe.trim()?fe:fe.slice(0,10),se=((t==null?void 0:t.candidates.map(g=>M[g.id]??lt(g)))??[]).reduce((g,T)=>(T.status==="saved"?g.saved+=1:T.status==="ready"?g.ready+=1:T.status==="needs_attention"?g.attention+=1:g.processing+=1,g),{saved:0,ready:0,attention:0,processing:0}),qe=t?se.saved>0?3:2:1,le=(t==null?void 0:t.candidates.filter(g=>{var T;return((T=g.validation)==null?void 0:T.valid)!==!1}).length)??0,Je=!!(b==="paste"?_.trim():b==="upload"?x.length>0:L.trim()),et=()=>b==="paste"?{inputMode:"paste",sourceKind:"raw-sql",domain:H,owner:$,sources:[{path:"pasted.sql",content:_}],async:!0,persistence:"session-only"}:b==="upload"?{inputMode:"upload",sourceKind:"raw-sql",domain:H,owner:$,sources:x,async:!0,persistence:"session-only"}:{path:L,inputMode:"path",sourceKind:"raw-sql",domain:H,owner:$,async:!0,persistence:"session-only"},_e=async()=>{var g,T,D;q(!0),ve(!0),Q(null),Ie({}),ee({}),u("creating");try{const C=await W.createDqlGenerationSession(et());let U=C,ne=Object.fromEntries(C.candidates.map(R=>[R.id,{...lt(R),status:"queued",message:"Queued for governed retrieval."}]));const v=(R,O)=>{ne={...ne,[R]:O(ne[R])},ee(ne)},B=R=>{U={...U,candidates:U.candidates.map(O=>O.id===R.id?R:O)},o(U)};o(U),I(((g=U.candidates[0])==null?void 0:g.id)??null),ee(ne),await a(),u("running"),U=await Fr(C.id,R=>{U=R,o(R);for(const O of R.candidates)v(O.id,We=>({...We,name:O.name,sourcePath:O.sourcePath,status:O.analysisStatus==="needs_attention"?"needs_attention":O.analysisStatus==="ready"?"queued":"running",message:Wr(O.analysisStatus)}))}),await Or(U.candidates,2,async R=>{if(R.analysisStatus!=="needs_attention"){v(R.id,O=>({...O,status:"running",message:"Running preview."}));try{const O=await W.previewDqlGenerationCandidate(U.id,R.id);B(O),v(R.id,We=>{var Ee;return{...We,name:O.name,sourcePath:O.sourcePath,status:"ready",rows:Sn(O),savedPath:((Ee=O.draftSave)==null?void 0:Ee.path)??O.savedPath,message:O.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(O){const We=(O==null?void 0:O.message)??"Preview failed.";Ie(Ee=>({...Ee,[R.id]:We})),v(R.id,Ee=>({...Ee,status:"needs_attention",message:We}))}}}),o(U),I(((T=U.candidates.find(R=>R.reviewStatus!=="rejected"))==null?void 0:T.id)??((D=U.candidates[0])==null?void 0:D.id)??null),await a(),u("complete")}catch(C){Q((C==null?void 0:C.message)??"Import failed."),u("idle")}finally{q(!1),ve(!1)}},tt=async g=>{var T,D;q(!0),Q(null);try{const C=await W.getDqlGenerationSession(g).catch(()=>W.getBlockStudioImport(g));o(C),I(((T=C.candidates.find(U=>U.reviewStatus!=="saved"&&U.reviewStatus!=="rejected"))==null?void 0:T.id)??((D=C.candidates[0])==null?void 0:D.id)??null),Ie({}),u("complete")}catch(C){Q((C==null?void 0:C.message)??"Failed to resume import session.")}finally{q(!1)}},at=async g=>{Se({kind:"one",id:g})},dt=async()=>{n.length!==0&&Se({kind:"all"})},ht=async()=>{if(!ue)return;const g=ue;q(!0),Q(null);try{g.kind==="one"?await W.deleteBlockStudioImport(g.id):await W.clearBlockStudioImports(),(g.kind==="all"||(t==null?void 0:t.id)===g.id)&&(o(null),I(null)),Se(null),await a()}catch(T){Q((T==null?void 0:T.message)??"Failed to update import history.")}finally{q(!1)}},Re=g=>{t&&(o({...t,candidates:t.candidates.map(T=>T.id===g.id?g:T)}),ee(T=>({...T,[g.id]:lt(g)})))},mt=async g=>{if(t){q(!0),Q(null),Ie(T=>{if(!T[g.id])return T;const D={...T};return delete D[g.id],D});try{const T=en(g)?await W.previewDqlGenerationCandidate(t.id,g.id):await W.runBlockStudioImportCandidate(t.id,g.id);Re(T),I(T.id),Ie(D=>{if(!D[g.id])return D;const C={...D};return delete C[g.id],C})}catch(T){const D=(T==null?void 0:T.message)??"Candidate run failed.";Q(D),I(g.id),Ie(C=>({...C,[g.id]:D}))}finally{q(!1)}}},Ge=async g=>{if(!t)return;const T=g.owner.trim()||$.trim();if(!T){Q("Owner is required before a block can be saved or certified.");return}q(!0),Q(null);try{if(en(g)){const D=await W.saveSelectedDqlGenerationCandidates(t.id,{candidateIds:[g.id],owner:T});o(D.session);const C=D.results[0];if(!C||C.status==="error")throw new Error((C==null?void 0:C.error)??(C==null?void 0:C.blockers.join(" "))??"Candidate save failed.");C.candidate&&Re(C.candidate),C.candidate&&C.block&&m(C.candidate,C.block),C.status==="draft"&&C.blockers.length>0&&Q(`Saved as draft: ${C.blockers.join(" ")}`)}else{const D=await W.saveBlockStudioImportCandidate(t.id,g.id);Re(D.candidate),m(D.candidate,D.block)}await a()}catch(D){const C=(D==null?void 0:D.message)??"Candidate save failed.";Q(C.includes("409")||C.includes("already exists")?"A block with this name already exists. Rename this candidate, then save again.":C)}finally{q(!1)}},gt=async()=>{if(!t)return;const g=$.trim()||t.defaults.owner.trim();if(!g){Q("Owner is required before blocks can be saved or certified.");return}ve(!0),Q(null);try{const T=t.candidates.filter(B=>B.reviewStatus!=="rejected"&&B.analysisStatus!=="needs_attention").map(B=>B.id),D=await W.saveSelectedDqlGenerationCandidates(t.id,{candidateIds:T,owner:g});o(D.session);const C=new Map(D.results.filter(B=>B.status==="error").map(B=>[B.candidateId,B.error??B.blockers.join(" ")])),U=new Map(D.results.filter(B=>B.path).map(B=>[B.candidateId,B.path]));ee(Object.fromEntries(D.session.candidates.map(B=>{const R=C.get(B.id),O=U.get(B.id)??B.savedPath;return R?[B.id,{...lt(B),status:"needs_attention",message:R.includes("409")||R.includes("already exists")?"A block with this name already exists. Rename it in advanced details, then save again.":R}]:O||B.reviewStatus==="saved"?[B.id,{...lt(B),status:"saved",savedPath:O,message:"Block saved."}]:[B.id,lt(B)]}))),await a();const ne=D.results.filter(B=>B.status==="error").length,v=D.results.filter(B=>B.status==="draft").length;(ne>0||v>0)&&Q(`${D.results.length-ne} saved. ${v} stayed draft; ${ne} need attention.`)}catch(T){Q((T==null?void 0:T.message)??"Save all failed.")}finally{ve(!1)}},Ve=async g=>{if(!t)return;const T=await W.updateBlockStudioImportCandidate(t.id,g.id,{reviewStatus:"rejected"});Re(T),a()},xt=async g=>{const D=Array.from(g??[]).filter(U=>U.name.toLowerCase().endsWith(".sql")),C=await Promise.all(D.map(async U=>({path:U.name,content:await U.text()})));X(C),C.length>0&&K("")};return e.jsxs("div",{style:{position:"relative",height:"100%",display:"grid",gridTemplateRows:"80px minmax(0, 1fr)",minHeight:0,background:h.appBg,borderRadius:k?0:8},children:[e.jsxs("header",{style:{borderBottom:`1px solid ${h.headerBorder}`,background:h.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:h.accent,background:`${h.accent}16`,flexShrink:0},children:e.jsx(Et,{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:h.textPrimary,fontFamily:h.font},children:"Import SQL to DQL"}),e.jsx("span",{style:{fontSize:11,color:h.textMuted,fontFamily:h.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(xn,{index:1,active:qe===1,complete:!!t,title:"Source",detail:b==="paste"?"Paste SQL":b==="upload"?"Upload files":"Local path",t:h}),e.jsx(xn,{index:2,active:qe===2,complete:se.ready>0||se.saved>0,title:"Draft",detail:t?`${t.candidates.length} blocks · ${le} ready`:"Generate DQL",t:h}),e.jsx(xn,{index:3,active:qe===3,complete:se.saved>0,title:"Review",detail:se.saved>0?`${se.saved} certified`:"Preview and certify",t:h})]}),e.jsx("div",{style:{flex:1}}),e.jsx("button",{onClick:r,title:"Close import","aria-label":"Close import",style:{...Z(h),width:32,height:32,padding:0,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(gr,{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 ${h.headerBorder}`,display:"grid",gridTemplateRows:"auto minmax(0, 1fr) auto",minHeight:0,background:h.cellBg},children:[e.jsxs("section",{style:{borderBottom:`1px solid ${h.headerBorder}`,padding:12,display:"grid",gap:10},children:[e.jsxs("button",{onClick:()=>we(g=>!g),style:{background:"transparent",border:"none",color:h.textPrimary,cursor:"pointer",display:"flex",alignItems:"center",gap:8,padding:0,fontFamily:h.font,textAlign:"left"},children:[e.jsx(Ni,{size:14,strokeWidth:2,color:h.accent,"aria-hidden":"true"}),e.jsx("span",{style:{fontSize:12,fontWeight:800,flex:1},children:"Source"}),t&&e.jsx("span",{style:{fontSize:10,color:h.textMuted},children:Y?"Hide":"Edit"})]}),Y?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:()=>P(g),style:{...Z(h),padding:"6px 4px",color:b===g?h.accent:h.textSecondary,borderColor:b===g?h.accent:h.btnBorder,background:b===g?`${h.accent}14`:h.btnBg},children:g==="paste"?"Paste SQL":g==="upload"?"Upload files":"Local path"},g))}),b==="path"&&e.jsx(A,{label:"Path",t:h,children:e.jsx("input",{value:L,onChange:g=>{K(g.target.value),g.target.value.trim()&&X([])},placeholder:"./queries or ./legacy.sql",style:ze(h)})}),b==="upload"&&e.jsxs(A,{label:"Upload SQL files",t:h,children:[e.jsx("input",{type:"file",multiple:!0,accept:".sql,text/sql,text/plain",onChange:g=>void xt(g.target.files),style:ze(h)}),e.jsx("span",{style:{fontSize:11,color:h.textMuted,fontFamily:h.font},children:x.length>0?`${x.length} SQL file(s) ready`:"Choose one or more SQL files."})]}),b==="paste"&&e.jsx(A,{label:"Paste SQL",t:h,children:e.jsx("textarea",{value:_,onChange:g=>w(g.target.value),placeholder:`select ...; go
|
|
22
|
+
select ...`,style:{...ze(h),minHeight:t?86:150,resize:"vertical",fontFamily:h.fontMono}})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[e.jsx(A,{label:"Domain",t:h,children:e.jsx("input",{value:H,onChange:g=>re(g.target.value),placeholder:"auto",style:ze(h)})}),e.jsx(A,{label:"Owner",t:h,children:e.jsx("input",{value:$,onChange:g=>G(g.target.value),placeholder:"analytics",style:ze(h)})})]}),e.jsx("button",{onClick:()=>void _e(),disabled:N||!Je,style:{...Te(h),padding:"8px 12px",opacity:N||!Je?.65:1,cursor:N||!Je?"not-allowed":"pointer"},children:N?qr(Ce):"Generate DQL drafts"}),e.jsx("div",{style:{fontSize:11,color:h.textMuted,fontFamily:h.font,lineHeight:1.45},children:"Uses dbt, MetricFlow, warehouse catalog, and existing DQL context when available."})]}):e.jsxs("button",{onClick:()=>we(!0),style:{...Z(h),display:"grid",gap:4,textAlign:"left",width:"100%",justifyItems:"start"},children:[e.jsx("span",{style:{fontSize:11,color:h.textSecondary},children:b==="paste"?"Pasted SQL":b==="upload"?"Uploaded files":"Local path"}),e.jsx("span",{style:{maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:h.textMuted,fontFamily:h.fontMono},children:(t==null?void 0:t.inputPath)??(b==="paste"?"pasted.sql":b==="upload"?`${x.length} file(s)`:L||"./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:h.textPrimary,fontFamily:h.font},children:"Drafts"}),e.jsx(Be,{label:`${t.candidates.length}`,tone:"info",t:h}),se.ready>0&&e.jsx(Be,{label:`${se.ready} ready`,tone:"ok",t:h}),se.attention>0&&e.jsx(Be,{label:`${se.attention} attention`,tone:"warn",t:h})]}),t.candidates.length>6&&e.jsx("input",{value:pe,onChange:g=>De(g.target.value),placeholder:"Search drafts, tables, files...",style:ze(h)})]}),Ke.map(g=>{var v,B,R,O,We,Ee,wt,Ct;const T=g.id===(ae==null?void 0:ae.id),D=g.warnings??g.lineage.warnings,C=ke[g.id],U=((B=(v=g.preview)==null?void 0:v.result)==null?void 0:B.rowCount)??((We=(O=(R=g.preview)==null?void 0:R.result)==null?void 0:O.rows)==null?void 0:We.length),ne=M[g.id]??lt(g);return e.jsxs("button",{onClick:()=>{I(g.id)},style:{border:`1px solid ${T?h.accent:C?"#f8514955":h.headerBorder}`,borderRadius:8,background:T?`${h.accent}10`:h.appBg,color:h.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(Be,{label:Nr(ne.status),tone:Hr(ne.status),t:h})]}),e.jsxs("span",{style:{fontSize:10,color:h.textMuted,fontFamily:h.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(Be,{label:((Ee=g.draftSave)==null?void 0:Ee.status)==="saved"||Wt(g.savedPath)?"draft saved":g.reviewStatus,tone:g.reviewStatus==="rejected"?"warn":"info",t:h}),e.jsx(Be,{label:((wt=g.validation)==null?void 0:wt.valid)===!1?"fix":"valid",tone:((Ct=g.validation)==null?void 0:Ct.valid)===!1?"warn":"ok",t:h}),typeof U=="number"&&e.jsx(Be,{label:`${U} rows`,tone:"ok",t:h}),D.length>0&&e.jsx(Be,{label:`${D.length} warning`,tone:"warn",t:h})]}),(C||ne.message)&&e.jsx("span",{style:{fontSize:11,color:C?"#f85149":h.textMuted,lineHeight:1.35,overflowWrap:"anywhere"},children:C??ne.message})]},g.id)}),!ge&&!pe.trim()&&fe.length>10&&e.jsxs("button",{onClick:()=>Ae(!0),style:Z(h),children:["Show all ",fe.length," drafts"]}),!t.candidates.some(en)&&se.ready>0&&e.jsx("button",{onClick:()=>void gt(),disabled:V,style:Te(h),children:V?"Saving...":"Save valid blocks"})]}):e.jsx("div",{style:{fontSize:12,color:h.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:Pe,onToggle:g=>z(g.currentTarget.open),style:{borderTop:`1px solid ${h.headerBorder}`,padding:12,display:"grid",gap:8},children:[e.jsxs("summary",{style:{cursor:"pointer",color:h.textSecondary,fontSize:11,fontWeight:800,fontFamily:h.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 a(),style:Z(h),children:"Refresh"}),n.length>0&&e.jsx("button",{onClick:()=>void dt(),style:Z(h),children:"Clear"})]}),s?e.jsx("div",{style:{fontSize:12,color:h.textMuted},children:"Loading..."}):n.length===0?e.jsx("div",{style:{fontSize:12,color:h.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?h.accent:h.btnBorder}`,borderRadius:8,background:(t==null?void 0:t.id)===g.id?`${h.accent}10`:h.btnBg,display:"grid",gridTemplateColumns:"minmax(0, 1fr) auto",overflow:"hidden"},children:[e.jsxs("button",{onClick:()=>void tt(g.id),style:{background:"transparent",border:"none",color:h.textSecondary,cursor:"pointer",fontFamily:h.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:h.textMuted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:g.inputPath})]}),e.jsx("button",{onClick:()=>void at(g.id),title:"Delete local import session",style:{background:"transparent",border:"none",borderLeft:`1px solid ${h.headerBorder}`,color:h.textMuted,cursor:"pointer",fontFamily:h.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:h.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||!ae?e.jsx(Gr,{t:h}):e.jsx(Kr,{session:t,candidate:ae,loading:N,onCandidateUpdated:Re,onRun:mt,onSave:Ge,onReject:Ve,onReviewInEditor:p,runError:ke[ae.id]??null,themeMode:l,t:h})]})]}),ue&&e.jsx(Ur,{t:h,busy:N,title:ue.kind==="all"?"Clear import history?":"Delete import preview?",message:ue.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:ue.kind==="all"?"Clear history":"Delete preview",onCancel:()=>Se(null),onConfirm:()=>void ht()})]})}function Ur({title:t,message:n,confirmLabel:s,busy:r,onCancel:o,onConfirm:a,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:o,disabled:r,style:Z(p),children:"Cancel"}),e.jsx("button",{onClick:a,disabled:r,style:{...Te(p),opacity:r?.65:1},children:r?"Working...":s})]})]})})}function Kr({session:t,candidate:n,loading:s,onCandidateUpdated:r,onRun:o,onSave:a,onReject:p,onReviewInEditor:m,runError:f,themeMode:E,t:l}){var et,_e,tt,at,dt,ht,Re,mt,Ge,gt,Ve,xt,g,T,D,C,U,ne;const[h,k]=d.useState(n.name),[b,P]=d.useState(n.domain),[L,K]=d.useState(n.owner),[_,w]=d.useState(n.description),[x,X]=d.useState(n.tags.join(", ")),[H,re]=d.useState((n.terms??[]).join(", ")),[$,G]=d.useState(n.pattern??""),[J,I]=d.useState(n.grain??""),[N,q]=d.useState((n.entities??[]).join(", ")),[V,ve]=d.useState((n.outputs??[]).join(", ")),[te,Q]=d.useState((n.dimensions??[]).join(", ")),[ue,Se]=d.useState((n.allowedFilters??[]).join(", ")),[Pe,z]=d.useState((n.sourceSystems??[]).join(", ")),[Y,we]=d.useState((n.replacementFor??[]).join(", ")),[pe,De]=d.useState(n.reviewCadence??"monthly"),[ge,Ae]=d.useState(n.sql),[ke,Ie]=d.useState(null),[Ce,u]=d.useState(null),[M,ee]=d.useState(!1);d.useEffect(()=>{k(n.name),P(n.domain),K(n.owner),w(n.description),X(n.tags.join(", ")),re((n.terms??[]).join(", ")),G(n.pattern??""),I(n.grain??""),q((n.entities??[]).join(", ")),ve((n.outputs??[]).join(", ")),Q((n.dimensions??[]).join(", ")),Se((n.allowedFilters??[]).join(", ")),z((n.sourceSystems??[]).join(", ")),we((n.replacementFor??[]).join(", ")),De(n.reviewCadence??"monthly"),Ae(n.sql),u(null),ee(!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 ae=async()=>{u(null);try{const v={name:h,domain:b,owner:L,description:_,tags:x.split(",").map(R=>R.trim()).filter(Boolean),terms:H.split(",").map(R=>R.trim()).filter(Boolean),pattern:$,grain:J,entities:N.split(",").map(R=>R.trim()).filter(Boolean),outputs:V.split(",").map(R=>R.trim()).filter(Boolean),dimensions:te.split(",").map(R=>R.trim()).filter(Boolean),allowedFilters:ue.split(",").map(R=>R.trim()).filter(Boolean),sourceSystems:Pe.split(",").map(R=>R.trim()).filter(Boolean),replacementFor:Y.split(",").map(R=>R.trim()).filter(Boolean),reviewCadence:pe,sql:ge,llmContext:n.llmContext},B=en(n)?await W.updateDqlGenerationCandidate(t.id,n.id,v):await W.updateBlockStudioImportCandidate(t.id,n.id,v);r(B)}catch(v){u((v==null?void 0:v.message)??"Could not update candidate.")}},fe=async v=>{Ie(v),u(null);try{const B=await W.assistBlockStudioImportCandidate(t.id,n.id,v);r(B)}catch(B){u((B==null?void 0:B.message)??"AI assist failed.")}finally{Ie(null)}},Ke=n.warnings??n.lineage.warnings,oe=ze(l),se=((_e=(et=n.preview)==null?void 0:et.result)==null?void 0:_e.rowCount)??((dt=(at=(tt=n.preview)==null?void 0:tt.result)==null?void 0:at.rows)==null?void 0:dt.length),qe=((ht=n.draftSave)==null?void 0:ht.path)??(Wt(n.savedPath)?n.savedPath:void 0),le=n.recommendedAction==="reuse_existing"||((Re=n.draftSave)==null?void 0:Re.status)==="skipped",Je=n.lineage.sourceTables.length+(((mt=n.evidence)==null?void 0:mt.length)??0)+n.lineage.parameters.length+Ke.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 o(n),disabled:s,style:Z(l),children:s?"Running...":"Preview"}),e.jsx("button",{onClick:()=>ee(v=>!v),style:M?Te(l):Z(l),children:M?"Hide context":`Show context${Je>0?` (${Je})`:""}`}),e.jsx("button",{onClick:()=>m(n),style:Te(l),children:"Edit full DQL"}),e.jsx("button",{onClick:()=>void a(n),disabled:s||n.reviewStatus==="saved"||le,style:Te(l),children:le?"Reuse existing":n.reviewStatus==="saved"?"Certified":"Save block"})]}),Ce&&e.jsx("div",{role:"alert",style:{fontSize:12,color:"#f85149",background:"#f8514914",borderRadius:8,padding:10},children:Ce}),f&&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: ",f]}),e.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[e.jsx(Be,{label:((Ge=n.draftSave)==null?void 0:Ge.status)==="skipped"?"reuse recommended":((gt=n.draftSave)==null?void 0:gt.status)==="saved"||qe?"draft saved":n.reviewStatus,tone:n.reviewStatus==="rejected"?"warn":((Ve=n.draftSave)==null?void 0:Ve.status)==="skipped"?"ok":"info",t:l}),e.jsx(Be,{label:`${Math.round(n.confidence*100)}% confidence`,tone:"info",t:l}),e.jsx(Be,{label:((xt=n.validation)==null?void 0:xt.valid)===!1?"needs fixes":"valid",tone:((g=n.validation)==null?void 0:g.valid)===!1?"warn":"ok",t:l}),typeof se=="number"&&e.jsx(Be,{label:`${se} rows`,tone:"ok",t:l})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:M?"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(be,{title:"Review details",t:l,children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[e.jsx(A,{label:"Name",t:l,children:e.jsx("input",{value:h,onChange:v=>k(v.target.value),style:oe})}),e.jsx(A,{label:"Domain",t:l,children:e.jsx("input",{value:b,onChange:v=>P(v.target.value),style:oe})}),e.jsx(A,{label:"Owner",t:l,children:e.jsx("input",{value:L,onChange:v=>K(v.target.value),style:oe})}),e.jsx(A,{label:"Tags",t:l,children:e.jsx("textarea",{value:x,onChange:v=>X(v.target.value),style:{...oe,minHeight:58,resize:"vertical"}})})]}),e.jsx(A,{label:"Business description",t:l,children:e.jsx("textarea",{value:_,onChange:v=>w(v.target.value),style:{...oe,minHeight:70,resize:"vertical"}})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(140px, 1fr))",gap:8},children:[e.jsx(A,{label:"Pattern",t:l,children:e.jsx("select",{value:$,onChange:v=>G(v.target.value),style:oe,children:["custom","metric_wrapper","entity_profile","entity_rollup","ranking","trend","bridge","drilldown","replacement"].map(v=>e.jsx("option",{value:v,children:v},v))})}),e.jsx(A,{label:"Grain",t:l,children:e.jsx("input",{value:J,onChange:v=>I(v.target.value),style:oe})}),e.jsx(A,{label:"Review cadence",t:l,children:e.jsx("select",{value:pe,onChange:v=>De(v.target.value),style:oe,children:["weekly","monthly","quarterly","semiannual","annual"].map(v=>e.jsx("option",{value:v,children:v},v))})})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[e.jsx(A,{label:"Entities",t:l,children:e.jsx("input",{value:N,onChange:v=>q(v.target.value),style:oe})}),e.jsx(A,{label:"Outputs",t:l,children:e.jsx("input",{value:V,onChange:v=>ve(v.target.value),style:oe})}),e.jsx(A,{label:"Dimensions",t:l,children:e.jsx("input",{value:te,onChange:v=>Q(v.target.value),style:oe})}),e.jsx(A,{label:"Allowed filters",t:l,children:e.jsx("input",{value:ue,onChange:v=>Se(v.target.value),style:oe})}),e.jsx(A,{label:"Source systems",t:l,children:e.jsx("input",{value:Pe,onChange:v=>z(v.target.value),style:oe})}),e.jsx(A,{label:"Terms",t:l,children:e.jsx("input",{value:H,onChange:v=>re(v.target.value),style:oe})})]}),e.jsx(A,{label:"Replaces",t:l,children:e.jsx("input",{value:Y,onChange:v=>we(v.target.value),style:oe})}),e.jsx("button",{onClick:()=>void ae(),style:{...Te(l),justifySelf:"start"},children:"Apply edits"})]}),n.preview&&e.jsxs(be,{title:"Preview Results",t:l,children:[e.jsxs("div",{style:{fontSize:12,color:l.textMuted,lineHeight:1.45},children:["Query ran successfully",typeof se=="number"?` and returned ${se} rows`:"","."]}),e.jsx("div",{style:{maxHeight:320,overflow:"auto",border:`1px solid ${l.headerBorder}`,borderRadius:8},children:e.jsx(Wi,{result:n.preview.result,themeMode:E})})]}),e.jsxs("details",{style:Pt(l),children:[e.jsx("summary",{style:Rt(l),children:"Original SQL"}),e.jsx("textarea",{value:ge,onChange:v=>Ae(v.target.value),style:{...oe,minHeight:210,fontFamily:l.fontMono,resize:"vertical",marginTop:10}})]}),e.jsxs("details",{style:Pt(l),children:[e.jsx("summary",{style:Rt(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})]})]}),M&&e.jsxs("div",{style:{display:"grid",gap:12},children:[(((T=n.similarityMatches)==null?void 0:T.length)||((D=n.draftSave)==null?void 0:D.status)==="skipped")&&e.jsx(be,{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}),((C=n.draftSave)==null?void 0:C.reason)&&e.jsx("div",{style:{fontSize:12,color:l.textMuted,lineHeight:1.4},children:n.draftSave.reason}),(n.similarityMatches??[]).slice(0,3).map((v,B)=>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:v.name}),e.jsxs("div",{style:{fontSize:10,color:l.textMuted,marginTop:3},children:[v.kind," · ",Math.round(v.score*100),"% · ",v.recommendedAction]}),e.jsx("div",{style:{fontSize:11,color:l.textMuted,lineHeight:1.35,marginTop:5},children:v.reason})]},`${v.objectKey??v.name}-${B}`))]})}),(((U=n.parameterDecisions)==null?void 0:U.length)||((ne=n.filterBindings)==null?void 0:ne.length))&&e.jsx(be,{title:"Parameter contract",t:l,children:e.jsxs("div",{style:{display:"grid",gap:8},children:[(n.parameterDecisions??[]).slice(0,8).map(v=>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:v.name}),e.jsx("span",{style:{fontSize:10,color:l.textMuted},children:v.policy})]}),e.jsxs("div",{style:{fontSize:11,color:l.textMuted,lineHeight:1.35,marginTop:5},children:[v.sourceExpression," = ",String(v.value)]}),e.jsx("div",{style:{fontSize:11,color:l.textMuted,lineHeight:1.35,marginTop:5},children:v.reason})]},v.name)),(n.filterBindings??[]).length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:(n.filterBindings??[]).map(v=>e.jsx(Be,{label:`${v.filter} -> ${v.binding}`,tone:"info",t:l},v.filter))})]})}),e.jsxs(be,{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(v=>e.jsx(Be,{label:v,tone:"info",t:l},v)):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((v,B)=>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:v.name}),e.jsxs("div",{style:{fontSize:10,color:l.textMuted,marginTop:3},children:[v.kind,v.reason?` · ${v.reason}`:""]}),v.description&&e.jsx("div",{style:{fontSize:11,color:l.textMuted,lineHeight:1.35,marginTop:5},children:v.description})]},`${v.objectKey??v.name}-${B}`))]}),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(v=>e.jsx(Be,{label:v,tone:"warn",t:l},v)):e.jsx("span",{style:{fontSize:12,color:l.textMuted},children:"None detected"})})]}),Ke.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"}),Ke.map((v,B)=>e.jsx("div",{style:{fontSize:12,color:"#d29922",lineHeight:1.4},children:v},B))]})]}),e.jsxs("details",{style:Pt(l),children:[e.jsx("summary",{style:Rt(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}),qe&&e.jsx(St,{label:"Draft path",value:qe,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((v,B)=>e.jsx("div",{style:{fontSize:12,color:l.textMuted,lineHeight:1.4},children:v},B))]})]}),e.jsxs("details",{style:Pt(l),children:[e.jsx("summary",{style:Rt(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(([v,B])=>e.jsx("button",{onClick:()=>void fe(v),disabled:!!ke,style:Z(l),children:ke===v?"Working...":B},v))}),(n.aiAssistance??[]).length>0&&e.jsx("div",{style:{display:"grid",gap:8},children:(n.aiAssistance??[]).slice().reverse().map((v,B)=>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:[v.action," · ",v.status]}),e.jsx("div",{style:{fontSize:12,color:l.textSecondary,lineHeight:1.45,marginTop:5},children:v.summary})]},`${v.createdAt}-${B}`))})]})]}),e.jsx("button",{onClick:()=>void p(n),disabled:n.reviewStatus==="rejected",style:{...Z(l),justifySelf:"start"},children:n.reviewStatus==="rejected"?"Rejected":"Reject draft"})]})]})]})}function xn({index:t,active:n,complete:s,title:r,detail:o,t:a}){const p=s?"#2ea043":n?a.accent:a.textMuted;return e.jsxs("div",{style:{border:`1px solid ${n?a.accent:a.headerBorder}`,borderRadius:8,padding:"9px 10px",display:"grid",gridTemplateColumns:"24px minmax(0, 1fr)",gap:8,alignItems:"center",background:n?`${a.accent}10`:a.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:a.font},children:s?"✓":t}),e.jsxs("span",{style:{minWidth:0},children:[e.jsx("span",{style:{display:"block",fontSize:12,fontWeight:700,color:a.textPrimary,fontFamily:a.font},children:r}),e.jsx("span",{style:{display:"block",fontSize:10,color:a.textMuted,fontFamily:a.font,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:o})]})]})}function Gr({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(jt,{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(([s,r,o])=>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:s}),e.jsx("span",{style:{fontSize:12,fontWeight:700,color:t.textPrimary,fontFamily:t.font},children:r}),e.jsx("span",{style:{fontSize:11,color:t.textMuted,fontFamily:t.font,lineHeight:1.4},children:o})]},r))})]})}function A({label:t,children:n,t:s}){return e.jsxs("label",{style:{display:"grid",gap:5},children:[e.jsx("span",{style:{fontSize:10,fontWeight:700,color:s.textMuted,letterSpacing:"0.05em",textTransform:"uppercase",fontFamily:s.font},children:t}),n]})}function be({title:t,hint:n,children:s,t:r}){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:r.textPrimary,fontFamily:r.font},children:t}),n?e.jsx("div",{style:{fontSize:11,color:r.textMuted,lineHeight:1.45,marginTop:3,fontFamily:r.font},children:n}):null]}),e.jsx("div",{style:{minWidth:0,display:"grid",gap:10,alignContent:"start"},children:s})]})}function St({label:t,value:n,t:s}){return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"110px minmax(0, 1fr)",gap:8,fontSize:12,fontFamily:s.font},children:[e.jsx("span",{style:{color:s.textMuted},children:t}),e.jsx("span",{title:n,style:{color:s.textSecondary,overflowWrap:"anywhere"},children:n})]})}function Be({label:t,tone:n,t:s}){const r=n==="ok"?"#2ea043":n==="warn"?"#d29922":s.accent;return e.jsx("span",{style:{fontSize:10,fontWeight:700,color:r,background:`${r}18`,borderRadius:999,padding:"3px 7px",fontFamily:s.font,textTransform:"uppercase"},children:t})}function Pt(t){return{border:`1px solid ${t.headerBorder}`,borderRadius:8,background:t.cellBg,padding:12,color:t.textPrimary,fontFamily:t.font}}function Rt(t){return{cursor:"pointer",color:t.textSecondary,fontSize:11,fontWeight:800,textTransform:"uppercase",letterSpacing:"0.05em",fontFamily:t.font}}function ze(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 jn(t){return{...ze(t),boxSizing:"border-box",fontSize:11.5,minHeight:32,padding:"6px 8px"}}function Z(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 Te(t){return{...Z(t),background:`${t.accent}18`,border:`1px solid ${t.accent}`,color:t.accent,fontWeight:700}}function Vr({blockName:t,loading:n,detail:s,graph:r,paths:o,onSelectNode:a,onOpenInspector:p,t:m}){if(!t)return e.jsx(jt,{message:"Lineage will appear once the block has a name."});if(n)return e.jsx(jt,{message:"Loading block lineage…"});if(!(s!=null&&s.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 f=`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:s.node.name}),e.jsx("div",{style:{fontSize:11,color:m.textMuted,fontFamily:m.font},children:s.node.domain?`Domain: ${s.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"})]}),(o==null?void 0:o.layerSummary)&&e.jsx(nr,{layerSummary:o.layerSummary,t:m}),r&&r.nodes.length>0&&e.jsx(dr,{nodes:r.nodes,edges:r.edges,focalNodeId:f,height:360,onNodeClick:a,layoutMode:"flow"}),o&&(o.upstreamPaths.length>0||o.downstreamPaths.length>0)&&e.jsxs("div",{style:{display:"grid",gap:10},children:[o.upstreamPaths.length>0&&e.jsx(Si,{title:"Source to Block",paths:o.upstreamPaths,onNodeClick:a,focalNodeId:f,t:m}),o.downstreamPaths.length>0&&e.jsx(Si,{title:"Block to Consumption",paths:o.downstreamPaths,onNodeClick:a,focalNodeId:f,t:m})]})]})}function Yr({metadata:t,draftMetadata:n,onChange:s,t:r}){const o={width:"100%",background:r.inputBg,border:`1px solid ${r.inputBorder}`,borderRadius:6,color:r.textPrimary,fontSize:12,fontFamily:r.font,padding:"8px 10px",outline:"none"},a={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:a.name,onChange:p=>s({name:p.target.value}),placeholder:"Block name",style:o}),e.jsx("input",{value:a.domain,onChange:p=>s({domain:p.target.value}),placeholder:"Domain",style:o}),e.jsx("input",{value:a.folderPath,onChange:p=>s({folderPath:p.target.value}),placeholder:"Folder (optional), e.g. executive/monthly",style:{...o,fontFamily:r.fontMono}}),e.jsx("input",{value:a.owner,onChange:p=>s({owner:p.target.value}),placeholder:"Owner",style:o}),e.jsx("input",{value:a.description,onChange:p=>s({description:p.target.value}),placeholder:"Description",style:o}),e.jsx(_i,{values:a.tags,onChange:p=>s({tags:p}),placeholder:"Tags",style:o})]})}function Xr({parameters:t,values:n,onChange:s,onReset:r,onRun:o,running:a,t:p}){return t.length===0?e.jsx(jt,{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:o,disabled:a,style:Te(p),children:a?"Running…":"Run preview"})]}),e.jsx(ur,{parameters:t,values:n,onChange:s,onReset:r,t:p,includeNonRuntime:!0,card:!0})]})}function Zr({values:t,t:n}){return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:t.map(s=>e.jsxs("span",{style:{fontSize:10,color:n.textSecondary,background:n.appBg,border:`1px solid ${n.cellBorder}`,borderRadius:999,padding:"4px 7px"},children:[s.name," = ",Array.isArray(s.value)?s.value.join(", "):String(s.value)," ",e.jsxs("span",{style:{color:n.textMuted},children:["(",s.source,")"]})]},s.name))})}function jt({message:t}){const n=Ot[Ft(s=>s.themeMode)];return e.jsx("div",{style:{padding:16,fontSize:12,color:n.textMuted},children:t})}function Jr({elapsedMs:t}){const n=Ot[Ft(s=>s.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(Ze,{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:ts(t)})]}),e.jsx("div",{style:{color:n.textMuted,fontSize:12,lineHeight:1.45},children:"Executing the block query against the active connection."})]})})}function Ti(t){if(!(t instanceof Yo)||!t.details||typeof t.details!="object"||Array.isArray(t.details))return null;const n=t.details.technicalDetails;return typeof n=="string"&&n.trim()?n:null}function es({message:t,technicalDetails:n,repairing:s,onFix:r,onEdit:o}){const a=Ot[Ft(p=>p.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:a.textPrimary,fontFamily:a.font,padding:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,fontWeight:700,color:"#f85149"},children:[e.jsx(ft,{size:16,strokeWidth:2,"aria-hidden":"true"}),e.jsx("span",{children:"Preview failed"})]}),e.jsx("div",{style:{color:a.textPrimary,fontSize:12,lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:t}),e.jsx("div",{style:{color:a.textMuted,fontSize:11.5,lineHeight:1.45},children:"Correct the named field or runtime problem, then run the same draft again. Nothing was saved or certified."}),e.jsxs("div",{style:{display:"flex",gap:7,flexWrap:"wrap"},children:[e.jsxs("button",{type:"button",onClick:r,disabled:s,style:{...Te(a),display:"inline-flex",alignItems:"center",gap:6,opacity:s?.72:1},children:[s?e.jsx(Ze,{size:13,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):e.jsx(Et,{size:13}),s?"Fixing & running…":"Fix with AI & run"]}),e.jsx("button",{type:"button",onClick:o,style:Z(a),children:"Edit DQL"})]}),n&&n!==t&&e.jsxs("details",{style:{borderTop:`1px solid ${a.headerBorder}`,paddingTop:7},children:[e.jsx("summary",{style:{cursor:"pointer",color:a.textMuted,fontSize:10.5,fontWeight:700},children:"Technical details"}),e.jsx("pre",{style:{margin:"7px 0 0",maxHeight:180,overflow:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",color:a.textMuted,fontSize:10,lineHeight:1.4,fontFamily:a.fontMono},children:n})]})]})})}function ts(t){const n=Math.max(0,Math.floor(t/1e3));if(n<60)return`${n}s`;const s=Math.floor(n/60),r=n%60;return`${s}m ${r}s`}const Di={draft:"#8b949e",review:"#d29922",certified:"#3fb950",deprecated:"#f85149"},ns={draft:[],review:["draft"],certified:["deprecated"],deprecated:["draft"]};function is({currentStatus:t,blockPath:n,onStatusChanged:s,t:r}){const[o,a]=d.useState(!1),p=ns[t]??[],m=async f=>{if(n){a(!0);try{const E=await W.updateBlockStatus(n,f);E.ok&&E.status&&s(E.status)}finally{a(!1)}}};return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"10px 12px",background:r.pillBg,borderRadius:8},children:[e.jsx("span",{style:{fontSize:11,color:r.textMuted,fontFamily:r.font},children:"Status:"}),e.jsx("span",{style:{fontSize:11,fontWeight:600,color:Di[t]??r.textMuted,background:`${Di[t]??r.textMuted}18`,padding:"2px 8px",borderRadius:4,textTransform:"uppercase",letterSpacing:"0.04em",fontFamily:r.font},children:t}),e.jsx("span",{style:{flex:1}}),p.map(f=>e.jsx("button",{onClick:()=>void m(f),disabled:o,style:{background:f==="certified"?"#3fb950":f==="deprecated"?"#f85149":r.btnBg,border:`1px solid ${f==="certified"?"#3fb950":f==="deprecated"?"#f85149":r.btnBorder}`,borderRadius:4,color:f==="certified"||f==="deprecated"?"#fff":r.textSecondary,cursor:o?"not-allowed":"pointer",fontSize:10,fontWeight:600,fontFamily:r.font,padding:"3px 10px",textTransform:"capitalize",opacity:o?.5:1},children:o?"...":f==="certified"?"Certify":f==="deprecated"?"Deprecate":`Move to ${f}`},f))]})}function os({result:t,t:n,repairing:s,onEditSource:r,onEditParameters:o,onReviewMetrics:a,onRun:p,onFix:m}){var P,L,K,_,w;const f=t.checklist,E=!!((P=f==null?void 0:f.issues)!=null&&P.some(x=>x.code==="tests_failed")||f!=null&&f.blockers.some(x=>/tests? must pass|test failed/i.test(x))),l=f?[["Metadata",f.metadata,!0],["Validation",f.validation,!0],["Run",f.run,!0],["Tests",f.tests,E],["Chart",f.chart,!1],["Lineage",f.lineage,!1]]:[],h=Array.from(new Set(((L=t.blockers)!=null&&L.length?t.blockers:(f==null?void 0:f.blockers)??[]).map(rs))),k=(K=f==null?void 0:f.issues)!=null&&K.length?f.issues:h.map(x=>({severity:"error",code:"certification_blocker",title:"Certification requirement is not ready",message:x,correction:"Update the block, run it again, and retry certification.",action:x==="The query must run successfully."?"run_again":"edit_source"})),b=t.pending?n.accent:t.ok?"#3fb950":"#d29922";return e.jsxs("div",{style:{margin:"12px 12px 0",border:`1px solid ${b}55`,borderRadius:8,background:`${b}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:b,fontFamily:n.font},children:t.pending?"Certification running":t.ok?"Block certified":"Unable to certify"}),(f==null?void 0:f.checkedAt)&&e.jsx("span",{style:{fontSize:10,color:n.textMuted,fontFamily:n.fontMono},children:f.checkedAt})]}),e.jsx("div",{style:{fontSize:12,color:n.textMuted,lineHeight:1.45},children:t.pending?t.message??"The exact draft is saved and the certification gates are running in the background.":t.ok?f!=null&&f.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.":`The draft is saved. Certification stopped with ${k.length||1} required fix${k.length===1?"":"es"}; nothing was partially certified.`}),t.pending&&e.jsxs("div",{style:{display:"grid",gap:5},children:[e.jsx("div",{style:{height:5,borderRadius:999,background:n.headerBorder,overflow:"hidden"},children:e.jsx("div",{style:{height:"100%",width:`${Math.max(4,Math.min(100,t.progress??4))}%`,borderRadius:999,background:n.accent,transition:"width 180ms ease"}})}),e.jsxs("div",{style:{fontSize:10.5,color:n.textMuted,display:"flex",justifyContent:"space-between"},children:[e.jsx("span",{children:t.phase?t.phase.replace(/_/g," "):"queued"}),e.jsxs("span",{children:[Math.round(t.progress??0),"%"]})]})]}),l.length>0&&e.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:l.map(([x,X,H])=>e.jsxs("span",{title:!X&&!H?`${x} is optional for local certification.`:void 0,style:{fontSize:11,fontWeight:700,color:X?"#3fb950":H?"#d29922":n.textMuted,background:X?"#3fb95018":H?"#d2992218":n.pillBg,borderRadius:999,padding:"4px 8px"},children:[X?"✓":H?"!":"○"," ",x,!X&&!H?" · optional":""]},x))}),t.error&&k.length===0&&e.jsx("div",{style:{fontSize:12,color:"#f85149"},children:t.error}),!t.pending&&!t.ok&&k.length>0&&e.jsxs("div",{style:{display:"grid",gap:8},children:[e.jsxs("div",{style:{fontSize:10,color:"#d29922",textTransform:"uppercase",fontWeight:800},children:["Fixes before certification · ",k.length]}),k.map((x,X)=>{var $;const H=x.action==="review_metrics"?"Review metrics":x.action==="run_again"?"Run block":x.action==="edit_parameters"?"Edit run inputs":x.action==="configure_runtime"?"Review runtime":"Edit source",re=x.action==="review_metrics"||x.action==="configure_runtime"?a:x.action==="run_again"?p:x.action==="edit_parameters"?o:r;return e.jsxs("div",{style:{display:"grid",gap:7,border:`1px solid ${b}44`,borderRadius:8,background:n.cellBg,padding:10},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[e.jsx(ft,{size:14,color:b,style:{marginTop:1,flexShrink:0}}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{display:"flex",gap:7,alignItems:"baseline",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,fontWeight:800,color:n.textPrimary},children:x.title??"Certification requirement is not ready"}),x.field&&e.jsx("span",{style:{fontSize:10,color:n.textMuted},children:x.field})]}),((($=x.references)==null?void 0:$.length)??0)>0&&e.jsx("div",{style:{display:"flex",gap:5,flexWrap:"wrap",marginTop:5},children:x.references.map(G=>e.jsx("code",{style:{fontSize:10,color:n.accent,background:n.pillBg,borderRadius:4,padding:"2px 5px"},children:G},G))})]})]}),e.jsx("div",{style:{fontSize:11.5,lineHeight:1.45,color:n.textSecondary},children:x.message}),x.correction&&e.jsxs("div",{style:{fontSize:11.5,lineHeight:1.45,color:n.textPrimary},children:[e.jsx("strong",{children:"How to fix:"})," ",x.correction]}),e.jsxs("div",{style:{display:"flex",gap:7,flexWrap:"wrap"},children:[e.jsx("button",{type:"button",onClick:re,style:Z(n),children:H}),x.technicalDetails&&e.jsx("button",{type:"button",onClick:()=>m(x),disabled:s,style:Z(n),children:s?"Fixing…":"Fix with AI & run"})]}),x.technicalDetails&&x.technicalDetails!==x.message&&e.jsxs("details",{children:[e.jsx("summary",{style:{cursor:"pointer",color:n.textMuted,fontSize:10.5,fontWeight:700},children:"Technical details"}),e.jsx("pre",{style:{margin:"6px 0 0",maxHeight:160,overflow:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",color:n.textMuted,fontSize:10,lineHeight:1.4,fontFamily:n.fontMono},children:x.technicalDetails})]})]},`${x.code??x.message}-${X}`)})]}),(((w=(_=t.certification)==null?void 0:_.warnings)==null?void 0:w.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(x=>e.jsxs("div",{style:{fontSize:12,color:n.textMuted},children:[x.rule,": ",x.message]},`${x.rule}-${x.message}`))]})]})}function rs(t){const n=t.trim(),s=n.toLowerCase();return s==="missing owner"||s==="block has owner: missing owner"?"Owner is required.":s==="missing domain"||s==="block has domain: missing domain"?"Domain is required.":s==="missing description"||s==="block has description: missing description"?"Description is required.":s==="block has not run successfully"?"The query must run successfully.":s==="tests must pass before certification"||s.startsWith("all tests pass:")?"Tests must pass.":s==="at least one test assertion is required before certification"||s.startsWith("block has tests:")?"Add at least one test assertion.":s==="visualization config is missing"?"Choose a visualization.":n}function ss({entries:t,t:n}){return t.length===0?e.jsx(jt,{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(s=>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:s.hash.slice(0,7)}),e.jsx("span",{style:{fontSize:11,color:n.textMuted,fontFamily:n.font},children:new Date(s.date).toLocaleDateString()}),e.jsx("span",{style:{fontSize:11,color:n.textMuted,fontFamily:n.font,marginLeft:"auto"},children:s.author})]}),e.jsx("div",{style:{fontSize:12,color:n.textPrimary,fontFamily:n.font},children:s.message})]},s.hash))]})}function ls(t,n){const s=t.match(/query\s*=\s*"""([\s\S]*?)"""/i);return s?t.replace(s[0],`query = """${s[1].trimEnd()}
|
|
23
|
+
${n}
|
|
24
|
+
"""`):/^\s*block\s+"/i.test(t.trim())?t.replace(/\n\}\s*$/,`
|
|
25
|
+
|
|
26
|
+
query = """
|
|
27
|
+
${n}
|
|
28
|
+
"""
|
|
29
|
+
}
|
|
30
|
+
`):`${t.trimEnd()}
|
|
31
|
+
${n}
|
|
32
|
+
`}function Ii(t,n){const s=n.trim().replace(/;\s*$/,"");if(!s)return t;const r=t.trim();if(!r)return s;const o=t.match(/query\s*=\s*"""[\s\S]*?"""/i);if(o)return t.replace(o[0],`query = """
|
|
33
|
+
${s}
|
|
34
|
+
"""`);if(/^\s*block\s+"/i.test(r)){const a=`
|
|
35
|
+
query = """
|
|
36
|
+
${s}
|
|
37
|
+
"""
|
|
38
|
+
`;return/\}\s*$/.test(t)?t.replace(/\}\s*$/,`${a}}
|
|
39
|
+
`):`${t.trimEnd()}${a}`}return s}function yn(t){return Vo({name:t,status:"draft",metrics:[],dimensions:[],visualization:{chart:"table"}})}function Zt(t){return`block "${t}" {
|
|
40
|
+
domain = "uncategorized"
|
|
41
|
+
type = "custom"
|
|
42
|
+
description = ""
|
|
43
|
+
owner = ""
|
|
44
|
+
tags = []
|
|
45
|
+
|
|
46
|
+
query = """
|
|
47
|
+
SELECT 1 AS value
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
visualization {
|
|
51
|
+
chart = "table"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
`}const Ui="dql.block-studio.draft-session";function kn(){const t=`draft-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;try{window.localStorage.setItem(Ui,t)}catch{}return t}function as(){var t;try{const n=(t=window.localStorage.getItem(Ui))==null?void 0:t.trim();if(n)return n}catch{}return kn()}function ds(){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 cs(t,n){try{const s=window.localStorage.getItem(t);return s==null?n:s==="1"}catch{return n}}function us(t,n,s,r){try{const o=Number(window.localStorage.getItem(t));return Number.isFinite(o)?Math.min(r,Math.max(s,o)):n}catch{return n}}function ps(t){return!!(t.blockStudioDraft.trim()||t.blockStudioMetadata||t.activeBlockPath)}function Ki(t){var o,a;const n=((o=t==null?void 0:t.domain)==null?void 0:o.trim())||"uncategorized",s=(a=t==null?void 0:t.folderPath)==null?void 0:a.trim().replace(/\\/g,"/").replace(/^\/+|\/+$/g,""),r=((t==null?void 0:t.name)||"new_block").toLowerCase().replace(/[^a-z0-9_]+/g,"-").replace(/^[-_]+|[-_]+$/g,"")||"new-block";return`domains/${n}/blocks/${s?`${s}/`:""}${r}.dql`}function Gi(t){var s;const n=((s=t.match(/\bselect\b([\s\S]*?)\bfrom\b/i))==null?void 0:s[1])??"";return n?Array.from(new Set(n.split(",").map(r=>{var p,m;const o=(p=r.match(/\bas\s+([a-zA-Z_][\w$]*)\s*$/i))==null?void 0:p[1];return o||(((m=r.trim().match(/(?:^|\.)([a-zA-Z_][\w$]*)$/))==null?void 0:m[1])??"")}).filter(Boolean))).slice(0,24):[]}function Xe(t){return t.replace(/[_-]+/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function fs(t,n){const s=n.trim().toLowerCase();if(!s)return t;const r=o=>{const a=[o.label,o.path,o.type].filter(m=>!!m).some(m=>m.toLowerCase().includes(s)),p=(o.children??[]).map(m=>r(m)).filter(m=>!!m);return a||p.length>0?{...o,children:p}:null};return t.map(o=>r(o)).filter(o=>!!o)}function hs(t){let n=0,s=0,r=0;const o=a=>{a.kind==="schema"&&(n+=1),a.kind==="table"&&(s+=1),a.kind==="column"&&(r+=1);for(const p of a.children??[])o(p)};for(const a of t)o(a);return{schemas:n,tables:s,columns:r}}function ms(t){const n=[],s=r=>{r.kind==="table"&&r.path&&n.push({path:r.path,columns:(r.children??[]).filter(o=>o.kind==="column").map(o=>o.label)});for(const o of r.children??[])s(o)};for(const r of t)s(r);return n}function Mi(t){return["businessOutcome","llmContext","primaryTerms","sourceSystems","synonyms","caveats"].filter(s=>new RegExp(`\\b${s}\\s*=`,"i").test(t)).length}function gs(t){return t.metrics+t.measures+t.dimensions+t.timeDimensions+t.entities+t.hierarchies+t.semanticModels+t.savedQueries}export{Ws as BlockStudio};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as C,t as k,r as l,a as I,j as t,p as j,q as S,
|
|
1
|
+
import{u as C,t as k,r as l,a as I,j as t,p as j,q as S,aw as L,ax as N}from"./index-DJRMz64S.js";import{M as W}from"./MiniLineageGraph-0gY-ZwCy.js";import"./react-CRB3T2We.js";import"./dagre.esm-CPT_vn5p.js";function w(n){return n.replace(/\.(dqlnb|dql)$/i,"")}function $(n,o){return`${n}:${w(o)}`}function U(){var x,y;const{state:n,dispatch:o}=C(),e=k[n.themeMode],i=n.activeFile,d=i&&(i.type==="term"||i.type==="business_view")?$(i.type,i.name):null,[a,B]=l.useState({nodes:[],edges:[],focalNode:null}),[M,u]=l.useState(!1);l.useEffect(()=>{if(!d)return;let s=!1;return u(!0),I.queryLineage({focus:d,upstreamDepth:3,downstreamDepth:3}).then(h=>{var f,v;s||(B({nodes:((f=h.graph)==null?void 0:f.nodes)??[],edges:((v=h.graph)==null?void 0:v.edges)??[],focalNode:h.focalNode??null}),u(!1))}).catch(()=>{s||u(!1)}),()=>{s=!0}},[d]);const r=a.focalNode,c=l.useMemo(()=>new Map(a.nodes.map(s=>[s.id,s])),[a.nodes]),g=l.useMemo(()=>r?a.edges.filter(s=>s.target===r.id).map(s=>({edge:s,node:c.get(s.source)})).filter(s=>!!s.node):[],[r,a.edges,c]),m=l.useMemo(()=>r?a.edges.filter(s=>s.source===r.id).map(s=>({edge:s,node:c.get(s.target)})).filter(s=>!!s.node):[],[r,a.edges,c]);if(!i||!d)return t.jsx("div",{style:{flex:1,padding:24,color:e.textMuted},children:"Select a business term or business view from Explorer."});const p=(r==null?void 0:r.type)??i.type,T=j[p]??e.accent,E=S[p]??p.toUpperCase(),z=((x=r==null?void 0:r.metadata)==null?void 0:x.path)??((y=r==null?void 0:r.metadata)==null?void 0:y.filePath)??i.path;return t.jsxs("div",{style:{flex:1,minWidth:0,overflow:"auto",background:"var(--color-bg-primary)"},children:[t.jsx("div",{style:{padding:"22px 28px 18px",borderBottom:`1px solid ${e.headerBorder}`,background:e.appBg},children:t.jsx("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:16},children:t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8},children:[t.jsx("span",{style:{color:e.appBg,background:T,borderRadius:5,padding:"3px 7px",fontSize:10,fontWeight:800,letterSpacing:0},title:L[p]??p,children:E}),t.jsxs("span",{style:{color:e.textMuted,fontSize:12},children:["Lineage · ↑ ",g.length," · ↓ ",m.length]})]}),t.jsx("h1",{style:{margin:0,fontSize:26,lineHeight:1.15,color:e.textPrimary},children:(r==null?void 0:r.name)??w(i.name)}),t.jsx("div",{style:{marginTop:7,color:e.textMuted,fontSize:13},children:i.type==="term"?"Business definition used by blocks, views, dashboards, and AI agents.":"Business composition built from trusted terms, DQL blocks, and other business views."})]})})}),t.jsxs("div",{style:{padding:24,display:"grid",gridTemplateColumns:"minmax(300px, 420px) minmax(420px, 1fr)",gap:18},children:[t.jsxs("section",{style:{display:"grid",gap:14,alignContent:"start"},children:[r&&t.jsx(P,{node:r,t:e}),t.jsx(b,{title:"Upstream",connections:g,t:e}),t.jsx(b,{title:"Downstream",connections:m,t:e}),t.jsxs("div",{style:{border:`1px solid ${e.headerBorder}`,borderRadius:8,padding:12,color:e.textMuted,fontSize:12,background:e.sidebarBg},children:[t.jsx("div",{style:{fontWeight:800,color:e.textSecondary,marginBottom:6},children:"Source file"}),t.jsx("div",{style:{overflowWrap:"anywhere"},children:String(z)})]})]}),t.jsxs("section",{style:{minHeight:520,border:`1px solid ${e.headerBorder}`,borderRadius:8,background:e.sidebarBg,overflow:"hidden"},children:[t.jsxs("div",{style:{padding:"12px 14px",borderBottom:`1px solid ${e.headerBorder}`},children:[t.jsx("div",{style:{fontWeight:800,color:e.textPrimary,fontSize:14},children:"Focused lineage"}),t.jsxs("div",{style:{color:e.textMuted,fontSize:12,marginTop:3},children:["Technical inputs and business composition for this ",i.type==="term"?"term":"view","."]})]}),t.jsx("div",{style:{height:470,padding:12},children:M?t.jsx("div",{style:{color:e.textMuted,fontSize:12},children:"Loading lineage..."}):a.nodes.length===0?t.jsx("div",{style:{color:e.textMuted,fontSize:12},children:"No lineage available."}):t.jsx(W,{nodes:a.nodes,edges:a.edges,focalNodeId:d,height:"100%",onNodeClick:s=>{o({type:"SET_LINEAGE_FOCUS",nodeId:s})},interactive:!0})})]})]})]})}function P({node:n,t:o}){const e=n.metadata??{},i=[];return n.domain&&i.push({label:"Domain",value:n.domain}),n.owner&&i.push({label:"Owner",value:n.owner}),n.status&&i.push({label:"Status",value:n.status}),n.type==="term"&&typeof e.termType=="string"&&i.push({label:"Term Type",value:e.termType}),Array.isArray(e.identifiers)&&e.identifiers.length>0&&i.push({label:"Identifiers",value:e.identifiers.map(String).join(", ")}),Array.isArray(e.synonyms)&&e.synonyms.length>0&&i.push({label:"Synonyms",value:e.synonyms.map(String).join(", ")}),typeof e.description=="string"&&e.description.trim()&&i.push({label:"Description",value:e.description}),typeof e.businessOutcome=="string"&&e.businessOutcome.trim()&&i.push({label:"Business Outcome",value:e.businessOutcome}),typeof e.decisionUse=="string"&&e.decisionUse.trim()&&i.push({label:"Decision Use",value:e.decisionUse}),typeof e.reviewCadence=="string"&&e.reviewCadence.trim()&&i.push({label:"Review Cadence",value:e.reviewCadence}),t.jsxs("div",{style:{border:`1px solid ${o.headerBorder}`,borderRadius:8,background:o.sidebarBg,padding:12},children:[t.jsx("div",{style:{fontWeight:800,color:o.textPrimary,marginBottom:10},children:"Business metadata"}),t.jsx("div",{style:{display:"grid",gap:8},children:i.map(d=>t.jsxs("div",{style:{display:"grid",gap:3},children:[t.jsx("div",{style:{color:o.textMuted,fontSize:10,fontWeight:800,textTransform:"uppercase"},children:d.label}),t.jsx("div",{style:{color:o.textSecondary,fontSize:12,lineHeight:1.45},children:d.value})]},d.label))})]})}function b({title:n,connections:o,t:e}){return t.jsxs("div",{style:{border:`1px solid ${e.headerBorder}`,borderRadius:8,background:e.sidebarBg,padding:12},children:[t.jsx("div",{style:{fontWeight:800,color:e.textPrimary,marginBottom:10},children:n}),o.length===0?t.jsxs("div",{style:{color:e.textMuted,fontSize:12},children:["No ",n.toLowerCase()," connections in this focused window."]}):t.jsxs("div",{style:{display:"grid",gap:7},children:[o.slice(0,8).map(({edge:i,node:d})=>{const a=j[d.type]??e.textMuted;return t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"92px 1fr",gap:8,minWidth:0,fontSize:12},children:[t.jsx("span",{style:{color:e.textMuted},children:N[i.type]??i.type}),t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:6,minWidth:0},children:[t.jsx("span",{style:{color:e.appBg,background:a,borderRadius:3,padding:"1px 4px",fontSize:9,fontWeight:800,flexShrink:0},children:S[d.type]??d.type.slice(0,4).toUpperCase()}),t.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:d.name,children:d.name})]})]},`${i.source}-${i.target}-${i.type}`)}),o.length>8&&t.jsxs("div",{style:{color:e.textMuted,fontSize:12},children:[o.length-8," more connection",o.length-8===1?"":"s"," in the graph"]})]})]})}export{U as BusinessArtifactView};
|