@duckcodeailabs/dql-cli 1.13.0 → 1.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apps-api.d.ts +225 -5
- package/dist/apps-api.d.ts.map +1 -1
- package/dist/apps-api.js +1950 -117
- package/dist/apps-api.js.map +1 -1
- package/dist/args.d.ts +2 -0
- package/dist/args.d.ts.map +1 -1
- package/dist/args.js +3 -0
- package/dist/args.js.map +1 -1
- package/dist/assets/dql-notebook/assets/{AgentLogPage-CBGEoGmU.js → AgentLogPage-BlUE3qsX.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildDialog-CwAD3tXE.js → AiBuildDialog-O88iK6UW.js} +1 -1
- package/dist/assets/dql-notebook/assets/AiBuildResult-D-6G4Sh3.js +33 -0
- package/dist/assets/dql-notebook/assets/{AiSidePanel-DjB8PWHG.js → AiSidePanel-MRSGtQDV.js} +1 -1
- package/dist/assets/dql-notebook/assets/AnalyticsHome-CcRVO6zN.js +6 -0
- package/dist/assets/dql-notebook/assets/AppsView-BTkGC-wl.js +5588 -0
- package/dist/assets/dql-notebook/assets/BlockStudio-BrTNaDpb.js +55 -0
- package/dist/assets/dql-notebook/assets/{BusinessArtifactView-C4SZVNW-.js → BusinessArtifactView-itEIUrYy.js} +1 -1
- package/dist/assets/dql-notebook/assets/DbtFirstModelingPage-CbAqOpNc.js +22 -0
- package/dist/assets/dql-notebook/assets/{GitPage-BfVD4tVq.js → GitPage-BxOqRYu2.js} +1 -1
- package/dist/assets/dql-notebook/assets/GlobalAiRail-Tfkx76CI.js +1 -0
- package/dist/assets/dql-notebook/assets/GovernedContextPage-CeaDbepP.js +7 -0
- package/dist/assets/dql-notebook/assets/{HelpDocsPage-BDPNVot1.js → HelpDocsPage-D1lAryYv.js} +1 -1
- package/dist/assets/dql-notebook/assets/{HomePage-DiOnRhEG.js → HomePage-GB6se6xW.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDAG-BiUFX2KL.js → LineageDAG-zCyN-hdg.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDetailView-CfbSvlPJ.js → LineageDetailView-Cg0TgG2Y.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDrawer-CgTScaGB.js → LineageDrawer-DwMcenDf.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineagePathBreadcrumb-D7ZA7k68.js → LineagePathBreadcrumb-DUZx3ksU.js} +1 -1
- package/dist/assets/dql-notebook/assets/{MiniLineageGraph-GkD4y17x.js → MiniLineageGraph-DT_ycl6s.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewBlockModal-B9TfRjt7.js → NewBlockModal-qdhzeJPF.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewNotebookModal-BbO9NKUl.js → NewNotebookModal-BnaDzs1A.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NotebookEditor-CuMpvXR9.js → NotebookEditor-CouPFzdo.js} +26 -31
- package/dist/assets/dql-notebook/assets/{ReadinessPage-BROJ9YBM.js → ReadinessPage-DB_KbH9Y.js} +1 -1
- package/dist/assets/dql-notebook/assets/{SetupOnboarding-BCcZlpuQ.js → SetupOnboarding-CamQq_N2.js} +1 -1
- package/dist/assets/dql-notebook/assets/SkillsPage--mYkOAK2.js +10 -0
- package/dist/assets/dql-notebook/assets/{TrustBadge-vQQh8d0D.js → TrustBadge-ClEYiYeA.js} +1 -1
- package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-DBfsmXes.js +88 -0
- package/dist/assets/dql-notebook/assets/{answer-to-notebook-DuqCcDDl.js → answer-to-notebook-Cg3UyGwh.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-left-CMe1kkOL.js → arrow-left-DnYPGqlr.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-right-DvB_DONr.js → arrow-right-Ct_YGrmU.js} +1 -1
- package/dist/assets/dql-notebook/assets/{book-open-text-CJ3NAvrs.js → book-open-text-DULlwbj6.js} +1 -1
- package/dist/assets/dql-notebook/assets/{circle-x-BCgtha1W.js → circle-x-ByYxoiS9.js} +1 -1
- package/dist/assets/dql-notebook/assets/{dagre.esm-GKp7qoUL.js → dagre.esm-BjYSO53F.js} +1 -1
- package/dist/assets/dql-notebook/assets/{external-link-C-PXokWV.js → external-link-DprWh9Yf.js} +1 -1
- package/dist/assets/dql-notebook/assets/{grip-vertical-B4EHbGXW.js → grip-vertical-CrEEYkXN.js} +1 -1
- package/dist/assets/dql-notebook/assets/{index-1mIC_XX4.js → index-9w93YPF9.js} +127 -126
- package/dist/assets/dql-notebook/assets/index-B3shyZsg.css +1 -0
- package/dist/assets/dql-notebook/assets/{link-2-BLx-goet.js → link-2-BkW-rkEC.js} +1 -1
- package/dist/assets/dql-notebook/assets/{list-tree-BRFpEmvV.js → list-tree-BipBLmIE.js} +1 -1
- package/dist/assets/dql-notebook/assets/{minimize-2-CDwSCGlO.js → minimize-2-BhXsglrO.js} +1 -1
- package/dist/assets/dql-notebook/assets/{panel-right-open-CunA1xO7.js → panel-right-open-BoCSilYB.js} +1 -1
- package/dist/assets/dql-notebook/assets/{bot-CV8DYRrt.js → play-mdoZawPu.js} +7 -2
- package/dist/assets/dql-notebook/assets/{rotate-ccw-DOrfTZk8.js → rotate-ccw-ELiDRUmj.js} +1 -1
- package/dist/assets/dql-notebook/assets/{semantic-fields-AfQvjt5R.js → semantic-fields-DVNRLfeU.js} +1 -1
- package/dist/assets/dql-notebook/assets/sliders-horizontal-GeUzpmKz.js +6 -0
- package/dist/assets/dql-notebook/assets/{star-DDhv4e8M.js → star-D63O81Wp.js} +1 -1
- package/dist/assets/dql-notebook/assets/{triangle-alert-2ZXx8wAu.js → triangle-alert-BWrCxQVE.js} +1 -1
- package/dist/assets/dql-notebook/assets/upload-CI-ldXhC.js +6 -0
- package/dist/assets/dql-notebook/assets/usePersistedAgentThreadId-Cv7Yq2hK.js +32 -0
- package/dist/assets/dql-notebook/assets/{user-round-BA074kiQ.js → user-round-Do21aFGo.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wand-sparkles-CEYHLt9b.js → wand-sparkles-DT7u7F_x.js} +1 -1
- package/dist/assets/dql-notebook/assets/{workflow-CZtyrcR-.js → workflow-DHh2mMbn.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wrench-Ong23-wu.js → wrench-7tYr_GKb.js} +1 -1
- package/dist/assets/dql-notebook/assets/{x-CSo1M3tu.js → x-CcYceFMz.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.d.ts.map +1 -1
- package/dist/commands/model.js +83 -3
- package/dist/commands/model.js.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/llm/providers/dql-agent-provider.d.ts +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 +75 -0
- package/dist/local-runtime.d.ts.map +1 -1
- package/dist/local-runtime.js +2015 -88
- 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-Cp0eh6zU.js +0 -5
- package/dist/assets/dql-notebook/assets/AiBuildResult-CyqTuQe5.js +0 -33
- package/dist/assets/dql-notebook/assets/AnalyticsHome-B7BkvA-R.js +0 -6
- package/dist/assets/dql-notebook/assets/AppsView-CUrqtEGC.js +0 -4583
- package/dist/assets/dql-notebook/assets/BlockStudio-Bl0aGQJR.js +0 -60
- package/dist/assets/dql-notebook/assets/DbtFirstModelingPage-B0uxitnx.js +0 -22
- package/dist/assets/dql-notebook/assets/GlobalAiRail-DUwdy3fB.js +0 -1
- package/dist/assets/dql-notebook/assets/GovernedContextPage-D9f26ZFb.js +0 -7
- package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-Dj4AXAhT.js +0 -83
- package/dist/assets/dql-notebook/assets/chevron-up-HxU1l85K.js +0 -6
- package/dist/assets/dql-notebook/assets/index-DKu4CZt3.css +0 -1
- package/dist/assets/dql-notebook/assets/maximize-2-CCd5uRIZ.js +0 -6
- package/dist/assets/dql-notebook/assets/pencil-D_I14Wyk.js +0 -6
- package/dist/assets/dql-notebook/assets/usePersistedAgentThreadId-3rzkZrqc.js +0 -18
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import{c as Zt,r,j as e,P as ke,aI as _n,aJ as $o,aK as no,u as $t,t as Po,a as le,aL as Xt,a4 as We,aC as No,a0 as Oo,aM as Ao,aN as Eo,aO as To,V as qo,aP as Lo,aQ as oo,B as en,G as so,N as io,l as lo,aR as _o,aS as Fo,S as ao,ap as Pt,aT as Wo}from"./index-1mIC_XX4.js";import{S as Ho,K as Uo}from"./GovernedContextPage-D9f26ZFb.js";import{u as Ko,i as Vo,B as Jo,C as Go,b as Yo,M as Qo,T as Fn,N as Zo,H as dt,c as ct,d as Xo}from"./dagre.esm-GKp7qoUL.js";import{L as Ze}from"./link-2-BLx-goet.js";import{M as ro}from"./maximize-2-CCd5uRIZ.js";import{P as es}from"./panel-right-open-CunA1xO7.js";import{G as tn}from"./user-round-BA074kiQ.js";import{C as mt}from"./circle-x-BCgtha1W.js";import{R as ts}from"./rotate-ccw-DOrfTZk8.js";import"./react-CRB3T2We.js";import"./triangle-alert-2ZXx8wAu.js";import"./chevron-up-HxU1l85K.js";import"./pencil-D_I14Wyk.js";import"./x-CSo1M3tu.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 ns=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]],co=Zt("columns-3",ns);/**
|
|
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 os=[["path",{d:"M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"hod4my"}],["path",{d:"M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"w4yl2u"}],["path",{d:"M3 5a2 2 0 0 0 2 2h3",key:"f2jnh7"}],["path",{d:"M3 3v13a2 2 0 0 0 2 2h3",key:"k8epm1"}]],Bt=Zt("folder-tree",os);/**
|
|
12
|
-
* @license lucide-react v0.563.0 - ISC
|
|
13
|
-
*
|
|
14
|
-
* This source code is licensed under the ISC license.
|
|
15
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const ss=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}],["path",{d:"m8 9 3 3-3 3",key:"12hl5m"}]],is=Zt("panel-right-close",ss);function ls({modeling:t,relationByDbtId:n,detailsByDbtId:o,selectedDomain:s,selectedAreaId:i,selectedId:a,viewMode:x,columnMode:l,search:u,layoutMode:d,density:p,visibleLimit:g,dimUnrelated:b,showEdgeLabels:h,resetLayoutToken:y,focusRequest:j,onVisibleDbtIdsChange:f,onSelectEntity:k,onSelectRelationship:I,onEditRelationship:v,onDraftRelationship:B,onAddRelatedModel:R,onDropDbtModel:T,onCreateDomain:Y,onEditEntity:D,onOpenAi:U,theme:G}){const q=`dql-model-layout:${i??s??"all"}`,N=`${q}:sizes`,[ne,ue]=r.useState(()=>Wn(q)),[S,C]=r.useState(()=>Hn(N));r.useEffect(()=>ue(Wn(q)),[q]),r.useEffect(()=>C(Hn(N)),[N]),r.useEffect(()=>{y&&(localStorage.removeItem(q),localStorage.removeItem(N),ue({}),C({}))},[y]);const[$,A]=r.useState(null),[W,Q]=r.useState(null),V=(M,oe)=>{const re={...S,[M]:Math.round(oe)};C(re),localStorage.setItem(N,JSON.stringify(re))},{nodes:ae,edges:he}=r.useMemo(()=>ds(t,n,o,s,i,a,x,l,u,d,p,g,b,h,ne,S,R,V,G),[t,n,o,s,i,a,x,l,u,d,p,g,b,h,ne,S,R,G]),[Re,ye,He]=Ko(ae);r.useEffect(()=>ye(ae),[ae,ye]);const be=ae.map(M=>M.data.entity.dbtUniqueId),ze=be.join("|");if(r.useEffect(()=>f(be),[f,ze]),!ae.length)return e.jsxs("div",{style:{display:"flex",flexDirection:"column",placeItems:"center",justifyContent:"center",alignItems:"center",gap:12,height:"100%",color:G.textMuted},children:[e.jsx("strong",{style:{color:G.textPrimary},children:u.trim()?`No models or columns match “${u.trim()}”.`:"Start your Domain Model"}),!u.trim()&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"Bind a dbt model, then connect its columns to define governed analytical relationships."}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsxs("button",{onClick:Y,style:Kn(G),children:[e.jsx(ke,{size:13})," Create domain"]}),e.jsxs("button",{onClick:()=>T(""),style:Kn(G,!0),children:[e.jsx(Ze,{size:13})," Bind first model"]})]})]})]});const L=M=>{!M.source||!M.target||B({from:M.source,to:M.target,fromColumn:Un(M.sourceHandle),toColumn:Un(M.targetHandle)})},we=W?t.relationships[W.recordKey]:void 0;return e.jsxs("div",{style:{height:"100%",position:"relative"},onClick:()=>{A(null),Q(null)},children:[e.jsx("style",{children:xs}),e.jsxs(Vo,{nodes:Re,edges:he,onNodesChange:He,nodeTypes:{entity:rs},fitView:!0,fitViewOptions:{padding:.16},minZoom:.2,maxZoom:1.8,nodesDraggable:!0,nodesConnectable:!0,onConnect:L,onNodeDragStop:(M,oe)=>{const re={...ne,[oe.id]:oe.position};ue(re),localStorage.setItem(q,JSON.stringify(re))},onDragOver:M=>{M.dataTransfer.types.includes("application/x-dql-dbt-model")&&M.preventDefault()},onDrop:M=>{const oe=M.dataTransfer.getData("application/x-dql-dbt-model");oe&&(M.preventDefault(),T(oe))},onNodeClick:(M,oe)=>k(oe.id),onNodeDoubleClick:(M,oe)=>D(oe.id),onNodeContextMenu:(M,oe)=>{M.preventDefault(),A({x:M.clientX,y:M.clientY,nodeId:oe.id})},onEdgeClick:(M,oe)=>{M.stopPropagation(),I(oe.id),Q({x:Math.min(M.clientX,window.innerWidth-340),y:Math.min(M.clientY,window.innerHeight-320),recordKey:oe.id})},colorMode:G.appBg.toLowerCase().includes("0")?"dark":"light",proOptions:{hideAttribution:!0},children:[e.jsx(us,{focusRequest:j}),e.jsx(Jo,{color:"var(--border-strong)",gap:22,size:1}),e.jsx(Go,{showInteractive:!1}),e.jsx(Yo,{pannable:!0,zoomable:!0,nodeColor:M=>uo(String(M.data.entity.domain)),maskColor:`${G.appBg}bb`})]},`${d}:${p}:${g}:${y}:${u}`),$&&e.jsxs("div",{style:{position:"fixed",left:$.x,top:$.y,zIndex:50,width:178,border:`1px solid ${G.headerBorder}`,borderRadius:7,background:G.cellBg,boxShadow:"0 12px 32px #0004",padding:4},onClick:M=>M.stopPropagation(),children:[e.jsx(Mt,{label:"Inspect entity",onClick:()=>{k($.nodeId),A(null)},theme:G}),e.jsx(Mt,{label:"Edit Domain Model binding",onClick:()=>{D($.nodeId),A(null)},theme:G}),e.jsx(Mt,{label:"Ask AI about entity",onClick:()=>{U($.nodeId),A(null)},theme:G}),e.jsx(Mt,{label:"Start relationship",onClick:()=>{B({from:$.nodeId,to:""}),A(null)},theme:G})]}),W&&we&&e.jsx(as,{relationship:we,entities:t.entities,x:W.x,y:W.y,theme:G,onClose:()=>Q(null),onEdit:v?()=>{v(W.recordKey),Q(null)}:void 0,onViewProof:()=>{I(W.recordKey),Q(null)}})]})}function as({relationship:t,entities:n,x:o,y:s,theme:i,onClose:a,onEdit:x,onViewProof:l}){var b,h;const u=((b=t.validation)==null?void 0:b.status)==="passed",d=t.keys.map(y=>`${y.from} = ${y.to}`).join(" and ")||"No join keys declared",p=y=>{const j=n[y]??Object.values(n).find(f=>f.id===y||f.localId===y);return(j==null?void 0:j.businessName)||(j==null?void 0:j.localId)||y.split("::").pop()||y},g=y=>e.jsx("span",{style:{padding:"3px 8px",borderRadius:6,background:"var(--accent-dim)",color:"var(--accent)",border:"1px solid rgba(107,93,211,0.2)",fontFamily:i.fontMono,fontSize:11.5,maxWidth:120,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y});return e.jsxs("div",{onClick:y=>y.stopPropagation(),style:{position:"fixed",left:o,top:s,zIndex:60,width:316,background:i.cellBg,border:`1px solid ${i.headerBorder}`,borderRadius:12,boxShadow:"0 12px 34px rgba(26,26,26,0.16)",overflow:"hidden",fontFamily:i.font},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"11px 13px",borderBottom:"1px solid var(--border-subtle)",background:"var(--bg-1)"},children:[e.jsx(Ze,{size:14,color:"var(--accent)",style:{flexShrink:0}}),e.jsx("span",{style:{flex:1,minWidth:0,fontSize:12.5,fontWeight:700,color:i.textPrimary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.localId}),e.jsx("span",{style:{flexShrink:0,border:`1px solid ${u?"var(--status-success-border)":"var(--status-warning-border)"}`,color:u?"var(--status-success)":"var(--status-warning)",background:u?"var(--status-success-bg)":"var(--status-warning-bg)",borderRadius:999,padding:"2px 8px",fontSize:9.5,fontWeight:700},children:u?"Proven":"Unproven"}),e.jsx("button",{type:"button",onClick:a,title:"Close",style:{flexShrink:0,width:20,height:20,borderRadius:5,border:"none",background:"none",color:i.textMuted,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0},children:"×"})]}),e.jsxs("div",{style:{padding:"12px 13px",display:"flex",flexDirection:"column",gap:11},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,fontSize:11.5},children:[g(p(t.from)),e.jsx("span",{style:{color:i.textMuted,fontSize:10.5,fontWeight:650,whiteSpace:"nowrap"},children:t.cardinality.replace(/_/g," ")}),g(p(t.to))]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:i.textMuted,marginBottom:4},children:"Join"}),e.jsx("div",{style:{fontSize:11,fontFamily:i.fontMono,color:i.textPrimary,background:"var(--bg-1)",border:"1px solid var(--border-subtle)",borderRadius:7,padding:"7px 9px",overflowWrap:"anywhere"},children:d})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:i.textMuted,marginBottom:4},children:"Business context"}),e.jsx("div",{style:{fontSize:12,lineHeight:1.55,color:i.textSecondary},children:t.description||`${t.from} ${t.verb??"relates to"} ${t.to}. Add a business description so agents can pick this route with confidence.`})]}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:11,color:u?"var(--status-success)":"var(--status-warning)"},children:u?`Join proof passed — ${((h=t.validation)==null?void 0:h.joinedRows)??"?"} rows joined, agents may use this route.`:"No warehouse proof yet — automatic agent joins stay blocked."}),e.jsxs("div",{style:{display:"flex",gap:8},children:[x?e.jsx("button",{type:"button",onClick:x,style:{display:"inline-flex",alignItems:"center",gap:5,height:27,padding:"0 11px",borderRadius:7,border:"none",background:"var(--accent)",color:"#fff",fontSize:11.5,fontWeight:650,cursor:"pointer",fontFamily:i.font},children:"Edit relationship"}):null,e.jsx("button",{type:"button",onClick:l,style:{display:"inline-flex",alignItems:"center",gap:5,height:27,padding:"0 11px",borderRadius:7,border:`1px solid ${i.headerBorder}`,background:i.cellBg,color:i.textSecondary,fontSize:11.5,fontWeight:600,cursor:"pointer",fontFamily:i.font},children:"View join proof"})]})]})]})}function rs({data:t}){var T,Y;const{recordKey:n,entity:o,detail:s,relation:i,selected:a,viewMode:x,columnMode:l,density:u,theme:d,onAddRelatedModel:p,onResize:g}=t,[b,h]=r.useState(u==="compact"),y=uo(o.domain),j=no(o.analyticalRole),f=o.analyticalRole&&o.analyticalRole!=="unknown"?o.analyticalRole:"entity",k=(s==null?void 0:s.columns)??[],I=new Set(o.keys.length?o.keys:((T=s==null?void 0:s.dqlMeta)==null?void 0:T.keys)??[]),v=new Set(k.filter(D=>!I.has(D.name)&&/(^|_)id$/.test(D.name)).map(D=>D.name)),B=b||x==="business"?[]:l==="all"?k.slice(0,16):l==="keys"?k.filter(D=>I.has(D.name)).slice(0,10):k.filter(D=>I.has(D.name)||D.tests.length>0).slice(0,10),R=(Y=o.conceptRefs)!=null&&Y.length?o.conceptRefs.join(", "):Yt(o.localId??o.id);return e.jsxs("div",{style:{position:"relative",width:"100%",minWidth:236,borderRadius:10,overflow:"visible",border:`1.5px solid ${a?"var(--accent)":"var(--border-default)"}`,boxShadow:a?"0 1px 6px rgba(107,93,211,0.14)":"0 1px 4px rgba(26,26,26,0.05)",background:d.cellBg,color:d.textPrimary},children:[e.jsx(Zo,{position:"bottom-right",resizeDirection:"horizontal",minWidth:240,maxWidth:620,onResizeEnd:(D,U)=>g(n,U.width),style:{width:16,height:16,border:0,background:"transparent",color:d.textMuted},children:e.jsx("span",{title:"Drag to resize model",style:{display:"grid",placeItems:"center"},children:e.jsx(ro,{size:12})})}),b&&x==="data"&&e.jsx(dt,{className:"dql-modeling-handle",id:"entity-target",type:"target",position:ct.Left,style:ut(y)}),e.jsx("button",{className:"nodrag",title:"Add a related model",onClick:D=>{D.stopPropagation(),p({from:n})},style:{position:"absolute",right:-9,top:-9,zIndex:5,width:22,height:22,display:"grid",placeItems:"center",padding:0,borderRadius:999,border:`2px solid ${d.cellBg}`,background:"var(--accent)",color:"#fff",cursor:"pointer",boxShadow:"0 1px 4px rgba(107,93,211,0.3)"},children:e.jsx(ke,{size:12})}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,padding:"9px 12px",borderBottom:"1px solid var(--border-subtle)",background:"var(--bg-1)",borderRadius:"8.5px 8.5px 0 0"},children:[e.jsx("span",{style:{width:8,height:8,borderRadius:2.5,background:j,flexShrink:0}}),e.jsx("span",{style:{flex:1,minWidth:0,fontSize:12.5,fontWeight:700,color:d.textPrimary,fontFamily:d.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:x==="business"?o.businessName||Yt(o.localId??o.id):o.localId??o.id}),e.jsx("span",{style:{flexShrink:0,fontSize:9,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em",color:j},children:f}),x==="data"&&e.jsx("button",{className:"nodrag",title:b?"Expand columns":"Collapse columns",onClick:D=>{D.stopPropagation(),h(U=>!U)},style:{border:0,background:"transparent",color:d.textMuted,cursor:"pointer",padding:0,flexShrink:0},children:b?"▾":"▴"})]}),x==="business"?e.jsxs(e.Fragment,{children:[e.jsx("div",{title:o.businessContext,style:{padding:"9px 12px 7px",fontSize:11.5,lineHeight:1.5,color:d.textSecondary,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},children:o.businessContext||R}),e.jsxs("div",{style:{display:"flex",gap:6,padding:"0 12px 10px",flexWrap:"wrap"},children:[o.owner?e.jsx("span",{style:{fontSize:10,color:d.textMuted,border:"1px solid var(--border-subtle)",background:"var(--bg-1)",borderRadius:999,padding:"2px 7px"},children:o.owner}):null,e.jsx("span",{style:{fontSize:10,color:d.textMuted,border:"1px solid var(--border-subtle)",background:"var(--bg-1)",borderRadius:999,padding:"2px 7px"},children:o.grain?`1 row = ${o.grain}`:o.domain})]})]}):null,B.length>0&&e.jsxs("div",{style:{borderTop:"1px solid var(--border-subtle)",maxHeight:242,overflow:"auto"},children:[B.map(D=>e.jsxs("div",{style:{position:"relative",display:"flex",alignItems:"center",gap:7,padding:"4px 12px",borderBottom:"1px solid var(--border-subtle)",fontSize:11},children:[e.jsx(dt,{className:"dql-modeling-handle",id:`target:${D.name}`,type:"target",position:ct.Left,style:{...ut(y),top:"50%"}}),e.jsx("span",{style:{flexShrink:0,width:17,fontSize:8.5,fontWeight:700,fontFamily:d.fontMono,color:I.has(D.name)?"var(--pk)":v.has(D.name)?"var(--fk)":"transparent"},children:I.has(D.name)?"PK":v.has(D.name)?"FK":"·"}),e.jsx("span",{style:{flex:1,minWidth:0,color:d.textSecondary,fontFamily:d.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:I.has(D.name)?700:500},children:D.name}),e.jsx("span",{style:{flexShrink:0,fontSize:9.5,color:d.textMuted,fontFamily:d.fontMono},children:D.type??""}),e.jsx(dt,{className:"dql-modeling-handle",id:`source:${D.name}`,type:"source",position:ct.Right,style:{...ut(y),top:"50%"}})]},D.name)),k.length>B.length&&e.jsxs("div",{style:{padding:"6px 12px",color:d.textMuted,fontSize:9},children:["+ ",k.length-B.length," more dbt-owned columns"]})]}),(b||x==="business")&&e.jsxs(e.Fragment,{children:[e.jsx(dt,{className:"dql-modeling-handle",id:"entity-target",type:"target",position:ct.Left,style:ut(y)}),e.jsx(dt,{className:"dql-modeling-handle",id:"entity-source",type:"source",position:ct.Right,style:ut(y)})]})]})}function ds(t,n,o,s,i,a,x,l,u,d,p,g,b,h,y,j,f,k,I){const v=i?t.areas[i]:void 0,B=new Set(v?[...v.entityIds,...v.referencedEntityIds]:[]),R=Object.entries(t.relationships).flatMap(([S,C])=>{const $=_n(t,C.from),A=_n(t,C.to);return $&&A?[{recordKey:S,relationship:C,from:$,to:A}]:[]}).filter(({recordKey:S,from:C,to:$})=>{var A,W;return v?v.relationshipIds.includes(S):s?((A=t.entities[C])==null?void 0:A.domain)===s||((W=t.entities[$])==null?void 0:W.domain)===s:!0}),T=new Set(R.flatMap(({from:S,to:C})=>[S,C])),Y=u.trim().toLowerCase();let D=$o(t).filter(({recordKey:S,entity:C})=>{if(v&&!B.has(S)&&!T.has(S)||s&&C.domain!==s&&!T.has(S))return!1;if(!Y)return!0;const $=o[C.dbtUniqueId];return[S,C.id,C.qualifiedId,C.domain,$==null?void 0:$.relation,...($==null?void 0:$.columns.map(A=>A.name))??[]].some(A=>String(A??"").toLowerCase().includes(Y))});const U=Math.min(200,g>0?g:50);if(D.length>U){const S=new Map;for(const C of R)S.set(C.from,(S.get(C.from)??0)+1),S.set(C.to,(S.get(C.to)??0)+1);D=[...D].sort((C,$)=>C.recordKey===a?-1:$.recordKey===a?1:(S.get($.recordKey)??0)-(S.get(C.recordKey)??0)||C.recordKey.localeCompare($.recordKey)).slice(0,U)}const G=[...new Set(D.map(({entity:S})=>S.domain))].sort(),q=[];G.forEach((S,C)=>D.filter(({entity:$})=>$.domain===S).sort(($,A)=>$.recordKey.localeCompare(A.recordKey)).forEach(({recordKey:$,entity:A},W)=>{const Q=o[A.dbtUniqueId],V=x==="business"?0:ps(A,Q,l),ae=j[$]??hs(A,Q,n[A.dbtUniqueId],p);q.push({id:$,type:"entity",position:{x:C*390,y:W*190},data:{recordKey:$,entity:A,detail:Q,relation:n[A.dbtUniqueId],selected:a===$,viewMode:x,columnMode:l,density:p,theme:I,onAddRelatedModel:f,onResize:k},style:{width:ae,height:116+V*29}})}));const N=new Set(q.map(S=>S.id)),ne=R.filter(({from:S,to:C})=>N.has(S)&&N.has(C)).map(({recordKey:S,relationship:C,from:$,to:A})=>{var ze,L;const W=((ze=C.validation)==null?void 0:ze.status)==="passed";C.automaticJoinAllowed||C.staleCertification;const Q=C.keys.map(we=>`${we.from} → ${we.to}`).join(", "),V=C.keys[0],ae=t.entities[$],he=t.entities[A],Re=ae?Jt(ae,o[ae.dbtUniqueId],l):new Set,ye=he?Jt(he,o[he.dbtUniqueId],l):new Set,be=((L=C.verb)==null?void 0:L.trim())||Q;return{id:S,source:$,target:A,sourceHandle:x==="data"&&V&&Re.has(V.from)?`source:${V.from}`:void 0,targetHandle:x==="data"&&V&&ye.has(V.to)?`target:${V.to}`:void 0,type:"default",label:h?`${be} · ${cs(C.cardinality)}`:void 0,animated:C.status==="review",markerEnd:{type:Qo.ArrowClosed,color:a===S?"var(--accent)":"var(--border-strong)"},style:{stroke:a===S?"var(--accent)":"var(--border-strong)",strokeWidth:a===S?2:1.5,cursor:"pointer"},labelStyle:{fill:a===S?"var(--accent)":I.textSecondary,fontSize:10.5,fontWeight:650,cursor:"pointer"},labelBgStyle:{fill:I.cellBg,fillOpacity:1,stroke:a===S?"var(--accent)":I.headerBorder,strokeWidth:1},labelBgPadding:[9,4],labelBgBorderRadius:999}}),ue=new Fn.graphlib.Graph().setDefaultEdgeLabel(()=>({}));if(ue.setGraph({rankdir:"LR",ranksep:p==="compact"?90:p==="wide"?190:135,nodesep:p==="compact"?35:p==="wide"?90:60,marginx:35,marginy:35}),q.forEach(S=>{var C,$;return ue.setNode(S.id,{width:Number(((C=S.style)==null?void 0:C.width)??Gt(p)),height:Number((($=S.style)==null?void 0:$.height)??100)})}),ne.forEach(S=>ue.setEdge(S.source,S.target)),d==="auto"&&Fn.layout(ue),q.forEach(S=>{var A,W;const C=y[S.id];if(C){S.position=C;return}if(d==="grid"){const Q=q.indexOf(S),V=Math.max(1,Math.ceil(Math.sqrt(q.length)));S.position={x:Q%V*360,y:Math.floor(Q/V)*260};return}if(d==="star"){const Q=q.indexOf(S);if(Q===0){S.position={x:0,y:0};return}const V=(Q-1)/Math.max(1,q.length-1)*Math.PI*2;S.position={x:Math.cos(V)*460,y:Math.sin(V)*330};return}const $=ue.node(S.id);$&&(S.position={x:$.x-Number(((A=S.style)==null?void 0:A.width)??Gt(p))/2,y:$.y-Number(((W=S.style)==null?void 0:W.height)??100)/2})}),b&&a&&t.entities[a]){const S=new Set([a]);for(const C of R)C.from===a&&S.add(C.to),C.to===a&&S.add(C.from);for(const C of q)C.style={...C.style,opacity:S.has(C.id)?1:.18,transition:"opacity 160ms ease"}}return{nodes:q,edges:ne}}function cs(t){return t==="one_to_one"?"1:1":t==="one_to_many"?"1:N":t==="many_to_one"?"N:1":t==="many_to_many"?"N:N":"?"}function us({focusRequest:t}){const n=Xo(),o=r.useRef(-1);return r.useEffect(()=>{if(!t||t.token===o.current)return;o.current=t.token;const s=window.setTimeout(()=>{var l,u,d,p;const i=n.getNode(t.id);if(!i)return;const a=Number(((l=i.measured)==null?void 0:l.width)??i.width??((u=i.style)==null?void 0:u.width)??280),x=Number(((d=i.measured)==null?void 0:d.height)??i.height??((p=i.style)==null?void 0:p.height)??120);n.setCenter(i.position.x+a/2,i.position.y+x/2,{zoom:Math.max(.85,n.getZoom()),duration:500})},60);return()=>window.clearTimeout(s)},[t,n]),null}function Mt({label:t,onClick:n,theme:o}){return e.jsx("button",{onClick:n,style:{width:"100%",textAlign:"left",border:0,borderRadius:4,padding:"7px 8px",background:"transparent",color:o.textPrimary,fontSize:11,cursor:"pointer"},children:t})}function ps(t,n,o){return Jt(t,n,o).size}function Jt(t,n,o){var a;const s=(n==null?void 0:n.columns)??[];if(o==="all")return new Set(s.slice(0,16).map(x=>x.name));const i=new Set(t.keys.length?t.keys:((a=n==null?void 0:n.dqlMeta)==null?void 0:a.keys)??[]);return o==="keys"?new Set(s.filter(x=>i.has(x.name)).slice(0,10).map(x=>x.name)):new Set(s.filter(x=>i.has(x.name)||x.tests.length>0).slice(0,10).map(x=>x.name))}function Gt(t){return t==="compact"?250:t==="wide"?340:280}function hs(t,n,o,s){var a;const i=Math.max(Yt(t.localId??t.id).length,(o==null?void 0:o.length)??0,((a=n==null?void 0:n.description)==null?void 0:a.length)??0,...((n==null?void 0:n.columns)??[]).map(x=>x.name.length));return Math.min(s==="wide"?440:380,Gt(s)+Math.max(0,i-34)*2)}function Wn(t){try{const n=JSON.parse(localStorage.getItem(t)??"{}");return Object.fromEntries(Object.entries(n).filter(([,o])=>typeof o.x=="number"&&typeof o.y=="number"))}catch{return{}}}function Hn(t){try{const n=JSON.parse(localStorage.getItem(t)??"{}");return Object.fromEntries(Object.entries(n).filter(([,o])=>typeof o=="number"&&o>=240&&o<=620))}catch{return{}}}function Un(t){return t!=null&&t.includes(":")?t.slice(t.indexOf(":")+1):void 0}function ut(t){return{background:t,border:"2px solid var(--color-bg-card)",width:9,height:9,cursor:"crosshair"}}const xs=`
|
|
17
|
-
.dql-modeling-handle { opacity: 0; transition: opacity 0.12s ease; }
|
|
18
|
-
.react-flow__node:hover .dql-modeling-handle,
|
|
19
|
-
.dql-modeling-handle.connecting,
|
|
20
|
-
.dql-modeling-handle:hover { opacity: 1; }
|
|
21
|
-
`;function Kn(t,n=!1){return{display:"inline-flex",alignItems:"center",gap:6,border:`1px solid ${n?t.accent:t.headerBorder}`,borderRadius:6,padding:"7px 10px",color:n?t.accent:t.textSecondary,background:n?`${t.accent}12`:t.cellBg,cursor:"pointer",fontSize:11,fontWeight:650}}function Yt(t){return t.replace(/[._-]+/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function uo(t){const n=["#6d5ce7","#2e9b63","#d47822","#377cc8","#bd4f8b","#8a6d3b"];let o=0;for(const s of t)o=(o<<5)-o+s.charCodeAt(0)|0;return n[Math.abs(o)%n.length]}function ms(t){return t instanceof Error?t:void 0}function fs(t){return t.details&&typeof t.details=="object"&&!Array.isArray(t.details)?t.details:void 0}function Vn(t){const n=ms(t);if((n==null?void 0:n.code)==="DBT_FIRST_NOT_ENABLED")return{title:"Set up dbt-first modeling",detail:"Domain Studio requires a connected dbt project with manifest v3 and dbt-first modeling enabled. Open Settings → Project & dbt to connect and apply the project.",status:"Modeling mode · Not enabled"};if((n==null?void 0:n.code)==="DBT_MANIFEST_NOT_FOUND"){const s=fs(n),i=typeof(s==null?void 0:s.manifestPath)=="string"&&s.manifestPath.trim()?s.manifestPath:"target/manifest.json";return{title:"dbt manifest is not ready",detail:`The dbt project is connected, but ${i} was not found. Run dbt parse, dbt compile, or dbt build in the configured dbt project, then refresh Domain Studio.`,status:`dbt manifest · Missing (${i})`}}return(n==null?void 0:n.code)==="DBT_MANIFEST_COMPILE_FAILED"?{title:"dbt manifest could not be loaded",detail:`${n.message} Rebuild the dbt manifest, then refresh Domain Studio.`,status:"dbt manifest · Load failed"}:{title:"Domain Studio could not load",detail:t instanceof Error&&t.message?t.message:"The local DQL notebook server did not return Domain Studio data.",status:"Domain Studio · Unavailable"}}function pt(t){return t.toLowerCase().replace(/[^a-z0-9]+/g," ").trim()}function gs(t,n,o=50){const s=pt(n),i=s.split(/\s+/).filter(Boolean);return t.map(a=>{var b;const x=pt(a.label),l=pt(a.value),u=pt(a.description??""),d=pt(((b=a.keywords)==null?void 0:b.join(" "))??""),p=`${x} ${l} ${u} ${d}`;if(i.length&&!i.every(h=>p.includes(h)))return null;let g=0;return s&&((x===s||l===s)&&(g+=1e3),x.startsWith(s)&&(g+=500),l.startsWith(s)&&(g+=350),x.includes(s)&&(g+=200),g+=i.reduce((h,y)=>h+(x.startsWith(y)?80:x.includes(y)?40:10),0)),{option:a,score:g}}).filter(a=>!!a).sort((a,x)=>x.score-a.score||a.option.label.localeCompare(x.option.label)||a.option.value.localeCompare(x.option.value)).slice(0,Math.max(1,o)).map(({option:a})=>a)}function ai(){var at,Ee;const{state:t,dispatch:n}=$t(),o=Po[t.themeMode],[s,i]=r.useState(null),[a,x]=r.useState(!0),[l,u]=r.useState(null),d=r.useMemo(()=>Jn(),[]),[p,g]=r.useState(d.section),[b,h]=r.useState(d.domain),[y,j]=r.useState(d.modelAreaId),[f,k]=r.useState(d.selectedId),[I,v]=r.useState(null),[B,R]=r.useState({}),T=r.useRef(new Map),Y=r.useRef(new Set),D=r.useMemo(()=>Ws(),[]),[U,G]=r.useState(D.viewMode??"business"),[q,N]=r.useState(D.columnMode??"relevant"),[ne,ue]=r.useState(""),[S,C]=r.useState(0),[$,A]=r.useState(null),[W,Q]=r.useState(D.layoutMode??"auto"),[V,ae]=r.useState(D.density??"normal"),[he,Re]=r.useState(D.visibleLimit??50),[ye,He]=r.useState(D.dimUnrelated??!0),[be,ze]=r.useState(D.showEdgeLabels??!0),[L,we]=r.useState(!1),[M,oe]=r.useState(!1),[re,Ue]=r.useState(!1),[Ke,Nt]=r.useState(()=>typeof window<"u"&&window.innerWidth<980),$e=r.useRef(null),ft=r.useRef(null),[xe,H]=r.useState(null),[et,tt]=r.useState(null),[ve,Ve]=r.useState(null),[nt,gt]=r.useState(!1),[ot,Pe]=r.useState(null);r.useEffect(()=>{localStorage.setItem("dql-modeling-preferences",JSON.stringify({modelingView:U,columnMode:q,layoutMode:W,density:V,visibleLimit:he,dimUnrelated:ye,showEdgeLabels:be}))},[U,q,W,V,he,ye,be]),r.useEffect(()=>{const m=()=>Nt(window.innerWidth<980);return window.addEventListener("resize",m),()=>window.removeEventListener("resize",m)},[]);const st=r.useCallback(()=>{Ue(m=>{const z=!m;return z?window.requestAnimationFrame(()=>{var X;return(X=ft.current)==null?void 0:X.focus()}):window.requestAnimationFrame(()=>{var X;return(X=$e.current)==null?void 0:X.focus()}),z})},[]),it=r.useCallback(m=>{g(m),zt(b,m,!1,y,f)},[y,b,f]),yt=r.useCallback(m=>{h(m),j(null),k(null),zt(m,p,!1,null,null)},[p]);r.useEffect(()=>{const m=()=>{const z=Jn();h(z.domain),j(z.modelAreaId),k(z.selectedId),g(z.section)};return window.addEventListener("popstate",m),()=>window.removeEventListener("popstate",m)},[]),r.useEffect(()=>{zt(b,p,!0,y,f)},[y,b,f,p]);const Ne=async()=>{x(!0);try{const m=await le.getDbtFirstModeling();i(m),u(null);const z=b&&m.modeling.packages[b]?b:null;z!==b&&(h(z),zt(z,p,!0))}catch(m){i(null),u(Vn(m))}finally{x(!1)}};r.useEffect(()=>{Ne()},[]);const Z=s==null?void 0:s.modeling.entities[f??""],je=s==null?void 0:s.modeling.relationships[f??""],Oe=r.useMemo(()=>s?Object.values(s.modeling.areas).filter(m=>!b||m.domain===b).sort((m,z)=>m.name.localeCompare(z.name)):[],[s,b]),ee=s==null?void 0:s.modeling.areas[y??""];r.useEffect(()=>{s&&y&&!Oe.some(m=>m.qualifiedId===y)&&j(null)},[s,Oe,y]);const De=r.useCallback(m=>{const z=T.current.get(m);if(z)return z;if(Y.current.has(m))return Promise.resolve(void 0);const X=le.getDbtModelingNode(m).then(Se=>(Y.current.add(m),R(Te=>({...Te,[m]:Se})),Se)).catch(()=>{Y.current.add(m)}).finally(()=>T.current.delete(m));return T.current.set(m,X),X},[]);r.useEffect(()=>{if(!Z){v(null);return}const m=B[Z.dbtUniqueId];if(m){v(m);return}let z=!1;return De(Z.dbtUniqueId).then(X=>{z||v(X??null)}),()=>{z=!0}},[B,De,Z==null?void 0:Z.dbtUniqueId]),r.useEffect(()=>{T.current.clear(),Y.current.clear(),R({})},[s==null?void 0:s.dbtProvenance.manifestFingerprint]);const Ot=r.useCallback(m=>{for(const z of m.slice(0,24))De(z)},[De]);if(a&&!s)return e.jsx(Zn,{t:o,title:"Loading Domain Studio…",detail:"Compiling dbt provenance and the sparse DQL analytical overlay."});if(!s){const m=l??Vn(null);return e.jsx(Zn,{t:o,title:m.title,detail:m.detail,status:m.status})}const bt=Object.fromEntries(Object.values(s.dbtProvenance.nodes).map(m=>[m.uniqueId,m.relation])),At=Object.entries(s.modeling.entities).flatMap(([m,z])=>{var Te;const X=z.businessName||z.localId||z.id,Se=[{recordKey:m,type:"model",label:X,sublabel:z.domain,role:z.analyticalRole}];for(const Ge of((Te=B[z.dbtUniqueId])==null?void 0:Te.columns)??[])Se.push({recordKey:m,type:"column",label:Ge.name,sublabel:X,role:z.analyticalRole});return Se}),jt=m=>{k(m),ue(""),A(z=>({id:m,token:((z==null?void 0:z.token)??0)+1}))},Ae=ee?new Set([...ee.entityIds,...ee.referencedEntityIds]):void 0,vt=Xt(s.modeling,b).filter(({recordKey:m})=>!Ae||Ae.has(m)),lt=Object.values(s.modeling.relationships).filter(m=>{const z=s.modeling.entities[m.from],X=s.modeling.entities[m.to];return ee?ee.relationshipIds.includes(m.qualifiedId):!b||(z==null?void 0:z.domain)===b||(X==null?void 0:X.domain)===b}),St=Object.values(s.dbtProvenance.nodes).filter(m=>!Object.values(s.modeling.entities).some(z=>z.dbtUniqueId===m.uniqueId)),wt=re&&p==="diagram",Je=[...new Set(b?((Ee=(at=s.domainAssets)==null?void 0:at[b])==null?void 0:Ee.skills)??[]:Object.values(s.domainAssets??{}).flatMap(m=>m.skills??[]))].sort();return e.jsxs("div",{style:{flex:1,minHeight:0,display:"flex",flexDirection:"column",background:o.appBg,color:o.textPrimary},children:[e.jsx("header",{style:{minHeight:52,padding:"0 14px",borderBottom:`1px solid ${o.headerBorder}`,background:o.headerBg,display:"flex",alignItems:"center"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:12,alignItems:"center",width:"100%"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[e.jsx(We,{size:16,color:o.accent}),e.jsx("h1",{style:{margin:0,fontSize:12,fontWeight:800,whiteSpace:"nowrap"},children:"Domain workspace"}),e.jsx("span",{style:{color:o.textMuted,fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:b?`/${b}`:"/all domains"})]}),e.jsxs("div",{style:{display:"flex",gap:7},children:[b&&e.jsxs(K,{t:o,onClick:()=>{try{window.sessionStorage.setItem("dql-ask-domain-context",JSON.stringify({domain:b,modelAreaId:ee==null?void 0:ee.qualifiedId}))}catch{}n({type:"SET_MAIN_VIEW",view:"ask"})},children:[e.jsx(No,{size:14})," Ask"]}),e.jsxs(K,{t:o,onClick:()=>H(b?{kind:"area"}:{kind:"domain"}),children:[e.jsx(ke,{size:14})," ",b?"New model area":"New domain"]}),e.jsx(qs,{t:o,title:"Recompile",onClick:()=>void Ne(),children:e.jsx(Oo,{size:15})})]})]})}),e.jsxs("div",{style:{flex:1,minHeight:0,display:"grid",gridTemplateColumns:wt&&!Ke?"clamp(190px, 15vw, 232px) minmax(460px, 1fr) clamp(270px, 22vw, 380px)":"clamp(190px, 15vw, 232px) minmax(0, 1fr)"},children:[e.jsxs("aside",{style:{borderRight:`1px solid ${o.headerBorder}`,overflow:"auto",background:o.appBg},children:[e.jsx(bs,{data:s,selectedDomain:b,onSelect:yt,t:o}),e.jsx(js,{data:s,domain:b,active:p,onSelect:it,t:o}),e.jsx("div",{style:{padding:"10px 12px",borderTop:`1px solid ${o.headerBorder}`,display:"flex",flexDirection:"column",gap:5,fontSize:10.5,color:o.textMuted,fontFamily:o.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(--status-success)",flexShrink:0}}),"dbt synced · ",Object.keys(s.dbtProvenance.nodes).length," model",Object.keys(s.dbtProvenance.nodes).length===1?"":"s"]})})]}),e.jsxs("main",{style:{minWidth:0,minHeight:0,display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{minHeight:42,display:"flex",alignItems:"center",gap:7,padding:"0 10px 0 14px",borderBottom:`1px solid ${o.headerBorder}`,background:o.headerBg},children:[po(p,14,o),e.jsx("strong",{style:{fontSize:11},children:vs(p)}),e.jsx("span",{style:{width:1,height:15,background:o.headerBorder}}),e.jsx("span",{style:{color:o.textMuted,fontSize:10},children:b??"All domains"}),(p==="diagram"||p==="skills")&&b&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,marginLeft:5},children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:5,color:o.textMuted,fontSize:10},children:["Area",e.jsxs("select",{"aria-label":"Active model area",value:y??"",onChange:m=>{j(m.target.value||null),k(null)},style:{...ge(o),minWidth:146,padding:"4px 6px"},children:[e.jsx("option",{value:"",children:"All domain"}),Oe.map(m=>e.jsx("option",{value:m.qualifiedId,children:m.name},m.qualifiedId))]})]}),e.jsx("button",{"aria-label":"Add model area",title:"Add model area",onClick:()=>H({kind:"area"}),style:{...fe(o),width:27,height:27},children:e.jsx(ke,{size:13})})]}),p==="diagram"&&e.jsx("button",{ref:$e,"aria-expanded":re,"aria-controls":"domain-studio-inspector","aria-label":re?"Hide inspector":"Show inspector",title:re?"Hide inspector":"Show inspector",onClick:st,style:{...fe(o),marginLeft:"auto"},children:re?e.jsx(is,{size:14}):e.jsx(es,{size:14})})]}),e.jsxs("div",{style:{flex:1,minHeight:0},children:[p==="overview"&&e.jsx(ws,{data:s,domain:b,t:o,onOpen:it}),p==="diagram"&&e.jsxs("div",{id:"dql-modeling-diagram",style:{height:"100%",display:"flex",flexDirection:"column",...M?{position:"fixed",inset:0,zIndex:90,background:o.appBg}:{}},children:[e.jsx(Cs,{modelingView:U,columnMode:q,search:ne,layoutMode:W,density:V,visibleLimit:he,totalEntities:(Ae==null?void 0:Ae.size)??Object.keys(s.modeling.entities).length,dimUnrelated:ye,showEdgeLabels:be,showLegend:L,fullscreen:M,onBindModel:()=>H({kind:"entity"}),onRelationship:()=>H({kind:"relationship"}),onNewArea:()=>H({kind:"area"}),onModelingView:G,onColumnMode:N,onSearch:ue,searchItems:At,onPickModel:jt,onLayoutMode:Q,onDensity:ae,onVisibleLimit:Re,onDimUnrelated:He,onEdgeLabels:ze,onLegend:we,onFullscreen:()=>oe(m=>!m),onExport:()=>Ms(),onReset:()=>C(m=>m+1),t:o}),ee?e.jsxs("div",{style:{padding:"7px 14px",borderBottom:`1px solid ${o.headerBorder}`,background:"var(--accent-dim)",color:o.textSecondary,display:"flex",alignItems:"center",gap:8,fontSize:10.5},children:[e.jsx(We,{size:13,color:o.accent}),e.jsx("strong",{style:{color:o.textPrimary},children:ee.name}),e.jsx("span",{children:ee.description??"Focused business modeling area"}),e.jsxs("span",{style:{marginLeft:"auto",color:o.textMuted},children:[ee.entityIds.length," model",ee.entityIds.length===1?"":"s"," · ",ee.intentExamples.length," example question",ee.intentExamples.length===1?"":"s"]})]}):null,L&&e.jsx(Is,{t:o}),e.jsx("div",{style:{flex:1,minHeight:0},children:e.jsx(ls,{modeling:s.modeling,relationByDbtId:bt,detailsByDbtId:B,selectedDomain:b,selectedAreaId:y,selectedId:f,viewMode:U,columnMode:q,search:ne,layoutMode:W,density:V,visibleLimit:he,dimUnrelated:ye,showEdgeLabels:be,resetLayoutToken:S,focusRequest:$??void 0,onVisibleDbtIdsChange:Ot,onSelectEntity:k,onSelectRelationship:k,onEditRelationship:m=>{const z=s.modeling.relationships[m];z&&H({kind:"relationship",relationship:z})},onDraftRelationship:m=>H({kind:"relationship",draft:m}),onAddRelatedModel:m=>H({kind:"entity",relationshipFrom:m}),onDropDbtModel:m=>H({kind:"entity",dbtUniqueId:m}),onCreateDomain:()=>H({kind:"domain"}),onEditEntity:m=>{const z=s.modeling.entities[m];z&&H({kind:"entity",entity:z,dbtUniqueId:z.dbtUniqueId})},onOpenAi:m=>{k(m);try{window.sessionStorage.setItem("dql-ask-domain-context",JSON.stringify({domain:b,modelAreaId:ee==null?void 0:ee.qualifiedId,objectId:m}))}catch{}n({type:"SET_MAIN_VIEW",view:"ask"})},theme:o})})]}),p==="terms"&&e.jsx(Ut,{data:s,domain:b,kinds:["terms"],title:"Domain terms",detail:"Business vocabulary owned by this domain and available to governed retrieval.",t:o}),p==="skills"&&e.jsx(Ho,{embedded:!0,domainFilter:b,modelAreaFilter:y,sourcePathFilter:Je}),p==="knowledge"&&e.jsx("div",{style:{height:"100%",overflow:"auto",padding:"18px 20px"},children:e.jsx(Uo,{t:o,domains:Object.values(s.modeling.packages).map(m=>({id:m.id,name:m.id})),initialDomainId:b})}),p==="blocks"&&e.jsx(zs,{data:s,domain:b,t:o}),p==="views"&&e.jsx(Ut,{data:s,domain:b,kinds:["views"],title:"Business views",detail:"Domain-owned business views that compose governed models and blocks.",t:o}),p==="ai"&&e.jsx(Ds,{domain:b,selectedId:f,data:s,t:o,onOpenSkills:()=>it("skills"),onDraftRelationship:()=>H({kind:"relationship",draft:Z&&f?{from:f,to:""}:void 0})}),p==="join-proofs"&&e.jsx(Rs,{relationships:lt,entities:s.modeling.entities,t:o,onSelect:m=>k(Wt(s.modeling.relationships,m)),onEdit:m=>H({kind:"relationship",relationship:m})}),p==="contracts"&&e.jsx($s,{data:s,domain:b,t:o,onCreate:()=>H({kind:"contract"})}),p==="interfaces"&&e.jsx(Bs,{data:s,domain:b,t:o,onCreateExport:()=>H({kind:"export"}),onCreateImport:()=>H({kind:"import"})}),p==="evaluations"&&e.jsx(Ut,{data:s,domain:b,kinds:["evaluations","tests"],title:"Evaluations",detail:"Evidence and regression checks required before governed assets guide agents.",t:o}),p==="notebooks"&&e.jsx(Gn,{data:s,domain:b,kind:"notebooks",t:o}),p==="apps"&&e.jsx(Gn,{data:s,domain:b,kind:"apps",t:o}),p==="dbt"&&e.jsx(Ps,{data:s,domain:b,unbound:St,t:o,onBind:m=>H({kind:"entity",dbtUniqueId:m})})]})]}),wt&&e.jsxs("aside",{id:"domain-studio-inspector",ref:ft,role:"complementary","aria-label":"Domain Studio inspector",tabIndex:-1,onKeyDown:m=>{m.key==="Escape"&&st()},style:{borderLeft:`1px solid ${o.headerBorder}`,overflow:"auto",background:o.appBg,minWidth:0,...Ke?{position:"fixed",inset:"0 0 0 auto",width:"min(90vw, 380px)",zIndex:95,boxShadow:"-12px 0 30px rgba(0,0,0,.18)"}:{}},children:[e.jsx(Ls,{t:o,children:"Inspector"}),Z?e.jsx(Ns,{entity:Z,detail:I,relationships:lt,t:o,onEdit:()=>H({kind:"entity",entity:Z,dbtUniqueId:Z.dbtUniqueId}),onEditDbtSource:()=>tt(Z),onSelectRelationship:m=>k(Wt(s.modeling.relationships,m)),onDelete:()=>{Pe(null),Ve({kind:"entity",id:Z.localId||Z.id,domain:Z.domain,areaId:Z.areaId,label:Z.businessName||Z.localId||Z.id})}}):je?e.jsx(As,{relationship:je,t:o,onEdit:()=>H({kind:"relationship",relationship:je}),onDelete:()=>{Pe(null),Ve({kind:"relationship",id:je.localId||je.id,domain:je.ownerDomain??je.qualifiedId.split("::")[0],areaId:je.areaId,label:je.localId||je.id})}}):e.jsx(Es,{data:s,domainEntities:vt.map(({entity:m})=>m),domainRelationships:lt,t:o,onSelectRelationship:m=>k(Wt(s.modeling.relationships,m))})]})]}),xe&&e.jsx(Ss,{editor:xe,data:s,selectedDomain:b,selectedArea:ee,t:o,onClose:()=>H(null),onApplied:async m=>{H(null),await Ne(),xe.kind==="entity"&&xe.relationshipFrom&&m.operation==="upsert_entity"&&H({kind:"relationship",draft:{...xe.relationshipFrom,to:m.value.id}})}}),et&&I&&e.jsx(Os,{entity:et,detail:I,snapshotId:s.snapshotId,t:o,onClose:()=>tt(null),onApplied:async()=>{tt(null),await Ne()}}),ve&&e.jsx(ys,{pending:ve,busy:nt,error:ot,t:o,onCancel:()=>{Ve(null),Pe(null)},onConfirm:async()=>{gt(!0),Pe(null);try{const m={operation:ve.kind==="entity"?"remove_entity":"remove_relationship",value:{id:ve.id,domain:ve.domain,...ve.areaId?{areaId:ve.areaId}:{}}},z=await le.previewModelingChange(m,s.snapshotId);if(!z.patches.some(X=>X.changed))throw new Error("Nothing to remove — it is no longer in the domain source.");await le.applyModelingChange(m,z.fingerprint,s.snapshotId),Ve(null),k(null),await Ne()}catch(m){Pe(m instanceof Error?m.message:String(m))}finally{gt(!1)}}})]})}function ys({pending:t,busy:n,error:o,t:s,onCancel:i,onConfirm:a}){return e.jsx("div",{role:"dialog","aria-modal":"true","aria-label":`Delete ${t.kind}`,style:{position:"fixed",inset:0,background:"rgba(15,23,42,0.34)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:130},onClick:x=>{x.target===x.currentTarget&&!n&&i()},children:e.jsxs("div",{style:{width:"min(92vw, 420px)",background:s.appBg,border:`1px solid ${s.headerBorder}`,borderRadius:12,padding:18,boxShadow:"0 18px 44px rgba(0,0,0,.22)"},children:[e.jsxs("div",{style:{fontSize:14,fontWeight:700,color:s.textPrimary,marginBottom:6},children:["Delete this ",t.kind,"?"]}),e.jsxs("div",{style:{fontSize:12,color:s.textSecondary,lineHeight:1.5},children:[e.jsx("strong",{style:{fontFamily:s.fontMono},children:t.label})," will be removed from the"," ",e.jsx("strong",{children:t.domain})," domain source. dbt models and warehouse data are not affected."]}),t.kind==="entity"?e.jsx("div",{style:{fontSize:11.5,color:s.textMuted,marginTop:8,lineHeight:1.5},children:"Relationships that reference it are left in place and will report a missing endpoint until you remove or repoint them."}):null,o?e.jsx("div",{style:{fontSize:11.5,color:s.error,marginTop:10,lineHeight:1.5},children:o}):null,e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[e.jsx(K,{t:s,onClick:i,disabled:n,children:"Cancel"}),e.jsx(K,{t:s,danger:!0,onClick:a,disabled:n,children:n?"Deleting…":`Delete ${t.kind}`})]})]})})}function bs({data:t,selectedDomain:n,onSelect:o,t:s}){const{state:i}=$t(),a=To(t.modeling.packages),x=new Map(qo(i.authoredDomains).map(l=>[l.value,l.label]));return e.jsx("nav",{"aria-label":"Domain packages",children:e.jsx(Lo,{id:"domain-workspace-filter",ariaLabel:"Domain workspace",value:n??"",options:a.map(l=>({value:l.id,label:x.get(l.id)??l.label})),onChange:l=>o(l||null),summary:e.jsxs(e.Fragment,{children:[a.length," authored domain",a.length===1?"":"s"," available"]}),t:s})})}function js({data:t,domain:n,active:o,onSelect:s,t:i}){var u;const a=n?[((u=t.domainAssets)==null?void 0:u[n])??{}]:Object.values(t.domainAssets??{}),l={diagram:Xt(t.modeling,n).length,skills:a.reduce((d,p)=>{var g;return d+(((g=p.skills)==null?void 0:g.length)??0)},0),blocks:new Set(a.flatMap(d=>d.blocks??[])).size};return e.jsx("nav",{"aria-label":n?`${n} workspace`:"All domains workspace",style:{padding:"10px 7px 14px"},children:oo.map((d,p)=>e.jsxs("div",{style:{marginTop:p===0?0:12},children:[d.label?e.jsx("div",{style:{padding:"0 8px 6px",color:i.textMuted,fontSize:9,fontWeight:800,textTransform:"uppercase",letterSpacing:".06em"},children:d.label}):null,d.items.map(g=>e.jsxs("button",{onClick:()=>s(g.id),"aria-current":o===g.id?"page":void 0,style:Us(i,o===g.id,!1),children:[po(g.id,14,i,o===g.id),e.jsx("span",{style:{flex:1},children:g.label}),l[g.id]!==void 0&&e.jsx("small",{style:{color:o===g.id?i.accent:i.textMuted},children:l[g.id]})]},g.id))]},d.label??`group-${p}`))})}function po(t,n,o,s=!1){const i=t==="blocks"?en:t==="diagram"||t==="dbt"?so:t==="knowledge"||t==="interfaces"?io:t==="skills"?tn:t==="join-proofs"?Ze:t==="contracts"||t==="evaluations"?lo:t==="views"?co:t==="terms"||t==="notebooks"||t==="apps"?Bt:We;return e.jsx(i,{size:n,color:s?o.accent:o.textMuted})}function vs(t){var n;return t==="ai"?"Draft context":((n=oo.flatMap(o=>o.items).find(o=>o.id===t))==null?void 0:n.label)??t}function Jn(){if(typeof window>"u")return{domain:null,section:"diagram",modelAreaId:null,selectedId:null};const t=new URL(window.location.href).searchParams,n=t.get("domainSection"),o=Ao(n)?n:"diagram";return{domain:t.get("domain"),section:o,modelAreaId:t.get("modelArea"),selectedId:o==="diagram"&&n==="diagram"?t.get("domainObject"):null}}function zt(t,n,o=!1,s=null,i=null){if(typeof window>"u")return;const a=Eo(window.location.href,{domain:t,section:n,modelAreaId:s,selectedId:i});o?window.history.replaceState(window.history.state,"",a):window.history.pushState(window.history.state,"",a)}function Wt(t,n){const o=Object.entries(t).find(([,s])=>s===n);return o?o[0]:n.qualifiedId??n.id}function Ss({editor:t,data:n,selectedDomain:o,selectedArea:s,t:i,onClose:a,onApplied:x}){var jn,vn,Sn,wn,kn,Cn,In,Mn,zn,Dn,Bn,Rn,$n,Pn,Nn,On,An,En,Tn,qn,Ln;const l=t.kind==="relationship"?t.relationship:void 0,u=t.kind==="entity"?t.entity:void 0,d=t.kind==="area"?t.area:void 0,p=t.kind==="relationship"?t.draft:void 0,[g,b]=r.useState((d==null?void 0:d.domain)??(u==null?void 0:u.domain)??o??Object.keys(n.modeling.packages)[0]??""),[h,y]=r.useState((d==null?void 0:d.localId)??((jn=n.modeling.areas[(u==null?void 0:u.areaId)??(l==null?void 0:l.areaId)??""])==null?void 0:jn.localId)??(s==null?void 0:s.localId)??""),[j,f]=r.useState((l==null?void 0:l.localId)??(u==null?void 0:u.localId)??(d==null?void 0:d.localId)??""),[k,I]=r.useState((l==null?void 0:l.owner)??(u==null?void 0:u.owner)??""),[v,B]=r.useState(""),[R,T]=r.useState(t.kind==="entity"?(u==null?void 0:u.dbtUniqueId)??t.dbtUniqueId??"":""),[Y,D]=r.useState((u==null?void 0:u.businessName)??""),[U,G]=r.useState((u==null?void 0:u.businessContext)??""),[q,N]=r.useState(((vn=u==null?void 0:u.conceptRefs)==null?void 0:vn.join(", "))??""),[ne,ue]=r.useState((u==null?void 0:u.analyticalRole)??"unknown"),[S,C]=r.useState((u==null?void 0:u.status)??"draft"),[$,A]=r.useState((u==null?void 0:u.grain)??""),[W,Q]=r.useState((u==null?void 0:u.keys.join(", "))??""),[V,ae]=r.useState((d==null?void 0:d.name)??""),[he,Re]=r.useState((d==null?void 0:d.description)??""),[ye,He]=r.useState((d==null?void 0:d.intentExamples.join(", "))??""),[be,ze]=r.useState((d==null?void 0:d.referencedEntityIds.map(c=>{var P;return((P=n.modeling.entities[c])==null?void 0:P.localId)??c}).join(", "))??""),[L,we]=r.useState((l==null?void 0:l.from)??(p==null?void 0:p.from)??""),[M,oe]=r.useState((l==null?void 0:l.to)??(p==null?void 0:p.to)??""),[re,Ue]=r.useState((l==null?void 0:l.keys.map(c=>`${c.from}=${c.to}`).join(", "))??(p!=null&&p.fromColumn&&p.toColumn?`${p.fromColumn}=${p.toColumn}`:"")),[Ke,Nt]=r.useState((l==null?void 0:l.cardinality)??"unknown"),[$e,ft]=r.useState((l==null?void 0:l.fanout)??"unknown"),[xe,H]=r.useState((l==null?void 0:l.status)??"draft"),[et,tt]=r.useState((l==null?void 0:l.verb)??""),[ve,Ve]=r.useState((l==null?void 0:l.description)??""),[nt,gt]=r.useState(((Sn=l==null?void 0:l.roles)==null?void 0:Sn.from)??""),[ot,Pe]=r.useState(((wn=l==null?void 0:l.roles)==null?void 0:wn.to)??""),[st,it]=r.useState(((kn=l==null?void 0:l.optionality)==null?void 0:kn.from)??"unknown"),[yt,Ne]=r.useState(((Cn=l==null?void 0:l.optionality)==null?void 0:Cn.to)??"unknown"),[Z,je]=r.useState(((In=l==null?void 0:l.joinTypes)==null?void 0:In.join(", "))??"left"),[Oe,ee]=r.useState(((Mn=l==null?void 0:l.aggregation)==null?void 0:Mn.measuresFrom.join(", "))??""),[De,Ot]=r.useState(((zn=l==null?void 0:l.aggregation)==null?void 0:zn.dimensionsFrom.join(", "))??""),[bt,At]=r.useState(((Dn=l==null?void 0:l.importRefs)==null?void 0:Dn.join(", "))??""),[jt,Ae]=r.useState((l==null?void 0:l.attributionBlock)??""),[vt,lt]=r.useState((l==null?void 0:l.evidenceExpiresAt)??""),[St,wt]=r.useState(""),[Je,at]=r.useState(""),[Ee,m]=r.useState(""),[z,X]=r.useState(""),[Se,Te]=r.useState(""),[Ge,on]=r.useState(""),[sn,mo]=r.useState(""),[ln,fo]=r.useState(""),[an,go]=r.useState(""),[rn,yo]=r.useState(""),[dn,bo]=r.useState(""),[cn,jo]=r.useState(""),[un,vo]=r.useState("internal"),[pn,So]=r.useState(""),[kt,Et]=r.useState(null),[Tt,wo]=r.useState(null),[qt,Ye]=r.useState(!1),[Ct,Qe]=r.useState(null),[Lt,rt]=r.useState(l==null?void 0:l.validation),[qe,_t]=r.useState(null),[Ft,ko]=r.useState({}),[hn,Co]=r.useState(!!(l&&(l.roles||l.aggregation||(Bn=l.importRefs)!=null&&Bn.length||l.attributionBlock||l.evidenceExpiresAt)));r.useEffect(()=>{t.kind!=="relationship"||l||j||!L||!M||f(`${L}_to_${M}`.replace(/[^a-zA-Z0-9]+/g,"_").replace(/^_+|_+$/g,"").toLowerCase())},[t.kind,l,L,M,j]),r.useEffect(()=>{var P;if(t.kind!=="entity"||j||!R)return;const c=(P=n.dbtProvenance.nodes[R])==null?void 0:P.name;c&&f(c.replace(/[^a-zA-Z0-9]+/g,"_").replace(/^_+|_+$/g,"").toLowerCase())},[t.kind,j,R,n.dbtProvenance.nodes]),r.useEffect(()=>{if(t.kind!=="entity"||!R){_t(null);return}let c=!1;return le.getDbtModelingNode(R).then(P=>{var E,se;c||(_t(P),Y||D(P.name.replace(/[_-]+/g," ").replace(/\b\w/g,te=>te.toUpperCase())),!$&&((E=P.dqlMeta)!=null&&E.grain)&&A(P.dqlMeta.grain),!W&&((se=P.dqlMeta)!=null&&se.keys.length)&&Q(P.dqlMeta.keys.join(", ")))}).catch(()=>{c||_t(null)}),()=>{c=!0}},[R,t.kind]),r.useEffect(()=>{if(t.kind!=="relationship")return;const P=[L,M].map(se=>{var te;return(te=n.modeling.entities[se])==null?void 0:te.dbtUniqueId}).filter(se=>!!se).filter(se=>!Ft[se]);if(!P.length)return;let E=!1;return le.getDbtModelingNodes(P).then(({details:se})=>{E||ko(te=>({...te,...Object.fromEntries(se.map(me=>[me.uniqueId,me]))}))}).catch(()=>{}),()=>{E=!0}},[t.kind,L,M]);const xn=()=>{if(t.kind==="domain")return{operation:"upsert_domain",value:{id:j,name:j,owner:k,parent:v||void 0,exports:[]}};if(t.kind==="area")return{operation:"upsert_area",value:{id:j,domain:g,name:V||j,description:he||void 0,intentExamples:J(ye),references:J(be)}};if(t.kind==="entity")return{operation:"upsert_entity",value:{id:j,domain:g,dbtModel:R,areaId:h||void 0,businessName:Y||void 0,businessContext:U||void 0,conceptRefs:J(q),analyticalRole:ne,status:S,owner:k||void 0,grain:$||void 0,keys:J(W)}};if(t.kind==="contract")return{operation:"upsert_contract",value:{id:j,domain:g,entities:J(St),blocks:J(Je),status:"draft",owner:k,requiredEvaluation:!0,purpose:Ee||void 0,metricRefs:J(z),dimensions:J(Se),allowedFilters:J(Ge),requiredFilters:J(sn),evaluationRefs:J(ln)}};if(t.kind==="export")return{operation:"upsert_export",value:{id:j,domain:g,entity:an||void 0,metrics:J(z),blocks:J(Je),allowedKeys:J(rn),allowedDimensions:J(Se),allowedFilters:J(Ge),purposes:J(dn),consumerDomains:J(cn),classification:un||void 0,status:xe,owner:k||void 0}};if(t.kind==="import")return{operation:"upsert_import",value:{id:j||void 0,domain:g,exportRef:pn,purpose:Ee,status:xe,owner:k||void 0}};const c=Fs(re),E=!l||l.from===L&&l.to===M&&JSON.stringify(l.keys)===JSON.stringify(c)&&l.cardinality===Ke&&l.fanout===$e?Lt:void 0,se=xe==="certified"&&(E==null?void 0:E.status)!=="passed"?"review":xe,te=n.modeling.entities[L],me=n.modeling.entities[M];return{operation:"upsert_relationship",value:{id:j,domain:g,areaId:h||void 0,from:L,to:M,keys:c,cardinality:Ke,fanout:$e,status:se,owner:k||void 0,ownerDomain:g,verb:et||void 0,description:ve||void 0,roles:nt||ot?{from:nt||void 0,to:ot||void 0}:void 0,optionality:{from:st,to:yt},joinTypes:J(Z),aggregation:Oe||De?{measuresFrom:J(Oe),dimensionsFrom:J(De),requiresPreAggregation:$e!=="safe"}:void 0,attributionBlock:jt||void 0,importRefs:J(bt),evidenceExpiresAt:vt||void 0,crossDomain:(te==null?void 0:te.domain)!==(me==null?void 0:me.domain),validation:E,certifiedAgainst:se==="certified"&&(te!=null&&te.grain)&&(me!=null&&me.grain)?{from:{grain:te.grain,keys:te.keys},to:{grain:me.grain,keys:me.keys}}:void 0}}},Io=async()=>{try{Ye(!0),Qe(null);const c=xn();wo(c),Et(await le.previewModelingChange(c,n.snapshotId))}catch(c){Qe(c instanceof Error?c.message:String(c))}finally{Ye(!1)}},Mo=async()=>{try{Ye(!0),Qe(null);const c=xn();if(c.operation!=="upsert_relationship")return;const P=await le.validateModelingRelationship(c.value,n.snapshotId);rt(P),Qe(P.status==="passed"?"Warehouse proof passed. Preview the source change to save it.":P.message??"Validation failed."),Et(null)}catch(c){Qe(c instanceof Error?c.message:String(c))}finally{Ye(!1)}},zo=async()=>{if(!(!kt||!Tt))try{Ye(!0),await le.applyModelingChange(Tt,kt.fingerprint,n.snapshotId),await x(Tt)}catch(c){Qe(c instanceof Error?c.message:String(c))}finally{Ye(!1)}},mn=Object.entries(n.modeling.entities).map(([c,P])=>{const E=n.dbtProvenance.nodes[P.dbtUniqueId];return{value:c,label:P.businessName||P.localId||P.id,description:`${P.domain} · ${(E==null?void 0:E.relation)??(E==null?void 0:E.name)??P.dbtUniqueId}`,keywords:[P.qualifiedId,P.businessContext??"",P.analyticalRole??""]}}),Le=Ft[((Rn=n.modeling.entities[L])==null?void 0:Rn.dbtUniqueId)??""],_e=Ft[(($n=n.modeling.entities[M])==null?void 0:$n.dbtUniqueId)??""],fn=((Le==null?void 0:Le.columns)??[]).map(c=>({value:c.name,label:c.name,description:[c.type,c.description].filter(Boolean).join(" · ")||"dbt column"})),gn=((_e==null?void 0:_e.columns)??[]).map(c=>({value:c.name,label:c.name,description:[c.type,c.description].filter(Boolean).join(" · ")||"dbt column"})),It=fn.map(c=>c.value).filter(c=>gn.some(P=>P.value.toLowerCase()===c.toLowerCase())).slice(0,5),Be=re?re.split(",").map(c=>{const[P="",E=""]=c.split("=").map(se=>se.trim());return{from:P,to:E}}):[{from:"",to:""}],yn=(c,P,E)=>{const se=Be.map((te,me)=>me===c?{...te,[P]:E}:te);Ue(se.map(te=>`${te.from}=${te.to}`).join(", ")),rt(void 0)},Do=c=>{const P=Be.filter((E,se)=>se!==c);Ue(P.map(E=>`${E.from}=${E.to}`).join(", ")),rt(void 0)},Bo=()=>Ue([...Be.filter(c=>c.from||c.to),{from:"",to:""}].map(c=>`${c.from}=${c.to}`).join(", ")),bn=t.kind==="entity"?!!(g&&j&&R):t.kind==="relationship"?!!(g&&j&&L&&M&&Be.some(c=>c.from&&c.to)&&Be.every(c=>c.from&&c.to)):!0,Ro=t.kind==="domain"?"Create Domain Package":t.kind==="area"?d?"Edit model area":"Create model area":t.kind==="entity"?u?"Edit business entity":"Add dbt model":t.kind==="contract"?"Create analytical contract":t.kind==="export"?"Publish domain export":t.kind==="import"?"Request domain import":l?"Edit relationship":"Create relationship";return e.jsx(xo,{title:Ro,t:i,onClose:a,children:kt?e.jsxs("div",{children:[e.jsx("p",{style:{margin:"0 0 12px",fontSize:12,color:i.textSecondary},children:"Review the exact Domain Package source change before it is written."}),kt.patches.map(c=>e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("strong",{style:{fontSize:12},children:c.path}),e.jsx("pre",{style:Hs(i),children:c.after})]},c.path)),Ct&&e.jsx(ce,{text:Ct,t:i}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[e.jsx(K,{t:i,onClick:()=>Et(null),children:"Back"}),e.jsx(K,{primary:!0,t:i,onClick:()=>void zo(),disabled:qt,children:"Apply to Domain Package"})]})]}):e.jsxs("div",{style:{display:"grid",gap:12},children:[t.kind!=="domain"&&e.jsx(w,{label:"Domain",children:e.jsx(de,{value:g,onChange:b,values:Object.keys(n.modeling.packages),t:i})}),t.kind!=="relationship"&&e.jsx(w,{label:t.kind==="entity"?"Entity id":t.kind==="area"?"Area id":t.kind==="contract"?"Contract id":t.kind==="export"?"Export id":t.kind==="import"?"Import id (optional)":"Domain id",children:e.jsx(O,{value:j,onChange:f,t:i,placeholder:"stable_snake_case_id"})}),t.kind==="domain"&&e.jsx(w,{label:"Parent domain (optional)",children:e.jsx(de,{value:v,onChange:B,values:Object.keys(n.modeling.packages),t:i})}),t.kind==="area"&&e.jsxs(e.Fragment,{children:[e.jsx(ce,{text:"A Model Area is one small, reviewable source file. It filters the same domain graph; it never creates a competing semantic model.",t:i}),e.jsx(w,{label:"Area name",children:e.jsx(O,{value:V,onChange:ae,t:i,placeholder:"Customer lifecycle"})}),e.jsx(w,{label:"Business question or scope",children:e.jsx(O,{value:he,onChange:Re,t:i,placeholder:"How customers progress from first order to repeat purchase."})}),e.jsx(w,{label:"Example questions (comma-separated)",children:e.jsx(O,{value:ye,onChange:He,t:i,placeholder:"Which customers made a second purchase?"})}),e.jsx(w,{label:"Read-only boundary entities (comma-separated)",children:e.jsx(O,{value:be,onChange:ze,t:i,placeholder:"customer"})})]}),t.kind==="entity"&&e.jsxs(e.Fragment,{children:[e.jsx(Xn,{current:R?2:1,labels:["Find dbt model","Add business meaning","Review source change"],t:i}),e.jsx(ce,{text:"Search by model name, relation, or source path. Results stay bounded even when the dbt project has thousands of models.",t:i}),e.jsx(w,{label:"Model area",children:e.jsx(de,{value:h,onChange:y,values:Object.values(n.modeling.areas).filter(c=>c.domain===g).map(c=>c.localId),labels:Object.fromEntries(Object.values(n.modeling.areas).filter(c=>c.domain===g).map(c=>[c.localId,c.name])),t:i})}),e.jsx(w,{label:"dbt model",children:e.jsx(Ts,{value:R,onChange:T,selectedNode:n.dbtProvenance.nodes[R],domain:g,t:i})}),qe&&e.jsx(eo,{title:qe.name,detail:`${qe.relation??qe.uniqueId} · ${qe.columns.length} columns${(Pn=qe.dqlMeta)!=null&&Pn.grain?` · grain: ${qe.dqlMeta.grain}`:""}`,t:i}),e.jsx(w,{label:"Business name",children:e.jsx(O,{value:Y,onChange:D,t:i,placeholder:"Customer order"})}),e.jsx(w,{label:"Business context",children:e.jsx(O,{value:U,onChange:G,t:i,placeholder:"One order used to understand repeat purchasing and revenue."})}),e.jsxs("div",{style:ie,children:[e.jsx(w,{label:"Business concepts",children:e.jsx(O,{value:q,onChange:N,t:i,placeholder:"customer_lifecycle, revenue"})}),e.jsx(w,{label:"Analytical role",children:e.jsx(de,{value:ne,onChange:c=>ue(c),values:["event","dimension","snapshot","bridge","unknown"],t:i})})]}),e.jsxs("div",{style:ie,children:[e.jsx(w,{label:"Grain override (optional)",children:e.jsx(O,{value:$,onChange:A,t:i,placeholder:"Use dbt meta.dql by default"})}),e.jsx(w,{label:"Key overrides (optional)",children:e.jsx(O,{value:W,onChange:Q,t:i,placeholder:"customer_id, order_id"})})]}),e.jsxs("div",{style:ie,children:[e.jsx(w,{label:"Lifecycle",children:e.jsx(de,{value:S,onChange:c=>C(c),values:["draft","review","certified","deprecated"],t:i})}),e.jsx(w,{label:"Owner",children:e.jsx(O,{value:k,onChange:I,t:i,placeholder:"team@company.com"})})]})]}),t.kind==="relationship"&&e.jsxs(e.Fragment,{children:[e.jsx(Xn,{current:!L||!M?1:Be.some(c=>c.from&&c.to)?3:2,labels:["Choose models","Match join keys","Review policy"],t:i}),e.jsx(ce,{text:"Search business names or dbt relations, then match columns from only those two models. DQL keeps the relationship in draft until warehouse validation passes.",t:i}),e.jsx(w,{label:"Model area",children:e.jsx(de,{value:h,onChange:y,values:Object.values(n.modeling.areas).filter(c=>c.domain===g).map(c=>c.localId),labels:Object.fromEntries(Object.values(n.modeling.areas).filter(c=>c.domain===g).map(c=>[c.localId,c.name])),t:i})}),e.jsxs("div",{style:ie,children:[e.jsx(w,{label:"From entity",children:e.jsx(Dt,{ariaLabel:"From entity",value:L,onChange:c=>{we(c),rt(void 0)},options:mn,placeholder:"Search source model…",t:i})}),e.jsx(w,{label:"To entity",children:e.jsx(Dt,{ariaLabel:"To entity",value:M,onChange:c=>{oe(c),rt(void 0)},options:mn.filter(c=>c.value!==L),placeholder:"Search target model…",t:i})})]}),L&&M&&e.jsx(eo,{title:`${((Nn=n.modeling.entities[L])==null?void 0:Nn.businessName)||((On=n.modeling.entities[L])==null?void 0:On.localId)} → ${((An=n.modeling.entities[M])==null?void 0:An.businessName)||((En=n.modeling.entities[M])==null?void 0:En.localId)}`,detail:`${(Le==null?void 0:Le.columns.length)??0} source columns · ${(_e==null?void 0:_e.columns.length)??0} target columns`,t:i}),e.jsx(w,{label:"Join keys",children:e.jsxs("div",{style:{display:"grid",gap:8},children:[It.length>0&&!Be.some(c=>c.from&&c.to)&&e.jsxs("button",{type:"button",onClick:()=>Ue(`${It[0]}=${It[0]}`),style:{...Fe(i),justifySelf:"start"},children:[e.jsx(ao,{size:13})," Use exact match: ",It[0]]}),Be.map((c,P)=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) 24px minmax(0, 1fr) 30px",gap:7,alignItems:"center"},children:[e.jsx(Dt,{ariaLabel:`Source join column ${P+1}`,value:c.from,onChange:E=>yn(P,"from",E),options:fn,placeholder:L?"Source column…":"Choose source first",disabled:!L||!Le,t:i}),e.jsx("span",{"aria-hidden":"true",style:{color:i.textMuted,textAlign:"center"},children:"→"}),e.jsx(Dt,{ariaLabel:`Target join column ${P+1}`,value:c.to,onChange:E=>yn(P,"to",E),options:gn,placeholder:M?"Target column…":"Choose target first",disabled:!M||!_e,t:i}),e.jsx("button",{type:"button","aria-label":"Remove join key",title:"Remove join key",onClick:()=>Do(P),style:fe(i),children:e.jsx(mt,{size:14})})]},`${P}:${c.from}:${c.to}`)),e.jsxs("button",{type:"button",onClick:Bo,style:{...Fe(i),justifySelf:"start"},children:[e.jsx(ke,{size:13})," Add key pair"]})]})}),j&&e.jsxs("div",{style:{color:i.textMuted,fontSize:9.5},children:["Relationship id: ",e.jsx("code",{children:j})]}),e.jsxs("div",{style:ie,children:[e.jsx(w,{label:"Cardinality",children:e.jsx(de,{value:Ke,onChange:c=>Nt(c),values:["unknown","one_to_one","one_to_many","many_to_one","many_to_many"],t:i})}),e.jsx(w,{label:"Fanout policy",children:e.jsx(de,{value:$e,onChange:c=>ft(c),values:["safe","attribution_required","unsafe","unknown"],t:i})})]}),e.jsxs("div",{style:ie,children:[e.jsx(w,{label:"Business verb (optional)",children:e.jsx(O,{value:et,onChange:tt,t:i,placeholder:"belongs to"})}),e.jsx(w,{label:"Description (optional)",children:e.jsx(O,{value:ve,onChange:Ve,t:i,placeholder:"Why this relationship exists"})})]}),L&&M&&((Tn=n.modeling.entities[L])==null?void 0:Tn.domain)!==((qn=n.modeling.entities[M])==null?void 0:qn.domain)&&e.jsx(ce,{text:"This is a cross-domain relationship. Add the approved provider import in Advanced governance before certification.",t:i}),e.jsx("button",{type:"button",onClick:()=>Co(c=>!c),style:{...Fe(i),justifySelf:"start",padding:"6px 0"},children:hn?"Hide advanced governance":"Advanced governance and aggregation"}),hn&&e.jsxs("div",{style:{display:"grid",gap:12,padding:12,border:`1px solid ${i.headerBorder}`,borderRadius:8,background:i.cellBg},children:[e.jsxs("div",{style:ie,children:[e.jsx(w,{label:"Allowed join types",children:e.jsx(O,{value:Z,onChange:je,t:i,placeholder:"left, inner"})}),e.jsx(w,{label:"Lifecycle",children:e.jsx(de,{value:xe??"draft",onChange:c=>H(c),values:["draft","review","certified","deprecated"],t:i})})]}),e.jsxs("div",{style:ie,children:[e.jsx(w,{label:"From role",children:e.jsx(O,{value:nt,onChange:gt,t:i})}),e.jsx(w,{label:"To role",children:e.jsx(O,{value:ot,onChange:Pe,t:i})})]}),e.jsxs("div",{style:ie,children:[e.jsx(w,{label:"From optionality",children:e.jsx(de,{value:st,onChange:c=>it(c),values:["required","optional","unknown"],t:i})}),e.jsx(w,{label:"To optionality",children:e.jsx(de,{value:yt,onChange:c=>Ne(c),values:["required","optional","unknown"],t:i})})]}),e.jsxs("div",{style:ie,children:[e.jsx(w,{label:"Measures allowed from",children:e.jsx(O,{value:Oe,onChange:ee,t:i,placeholder:"order"})}),e.jsx(w,{label:"Dimensions allowed from",children:e.jsx(O,{value:De,onChange:Ot,t:i,placeholder:"customer"})})]}),e.jsxs("div",{style:ie,children:[e.jsx(w,{label:"Required import refs",children:e.jsx(O,{value:bt,onChange:At,t:i,placeholder:"commerce.customer@1"})}),e.jsx(w,{label:"Attribution block",children:e.jsx(O,{value:jt,onChange:Ae,t:i,placeholder:"growth.revenue_by_channel"})})]}),e.jsxs("div",{style:ie,children:[e.jsx(w,{label:"Evidence expires",children:e.jsx(O,{value:vt,onChange:lt,t:i,placeholder:"2026-12-31"})}),e.jsx(w,{label:"Owner",children:e.jsx(O,{value:k,onChange:I,t:i,placeholder:"team@company.com"})})]})]}),Lt&&e.jsx(ho,{evidence:Lt,t:i})]}),t.kind==="contract"&&e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Covered entities",children:e.jsx(O,{value:St,onChange:wt,t:i,placeholder:"order, customer"})}),e.jsx(w,{label:"Certified blocks",children:e.jsx(O,{value:Je,onChange:at,t:i,placeholder:"orders_360"})}),e.jsx(w,{label:"Decision purpose",children:e.jsx(O,{value:Ee,onChange:m,t:i,placeholder:"Revenue reporting"})}),e.jsxs("div",{style:ie,children:[e.jsx(w,{label:"Metrics",children:e.jsx(O,{value:z,onChange:X,t:i})}),e.jsx(w,{label:"Dimensions",children:e.jsx(O,{value:Se,onChange:Te,t:i})})]}),e.jsxs("div",{style:ie,children:[e.jsx(w,{label:"Allowed filters",children:e.jsx(O,{value:Ge,onChange:on,t:i})}),e.jsx(w,{label:"Required filters",children:e.jsx(O,{value:sn,onChange:mo,t:i})})]}),e.jsx(w,{label:"Evaluation refs",children:e.jsx(O,{value:ln,onChange:fo,t:i,placeholder:"revenue_accuracy"})})]}),t.kind==="export"&&e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Exported entity",children:e.jsx(de,{value:an,onChange:go,values:Object.keys(n.modeling.entities).filter(c=>{var P;return((P=n.modeling.entities[c])==null?void 0:P.domain)===g}),t:i})}),e.jsxs("div",{style:ie,children:[e.jsx(w,{label:"Allowed keys",children:e.jsx(O,{value:rn,onChange:yo,t:i})}),e.jsx(w,{label:"Allowed dimensions",children:e.jsx(O,{value:Se,onChange:Te,t:i})})]}),e.jsxs("div",{style:ie,children:[e.jsx(w,{label:"Metrics",children:e.jsx(O,{value:z,onChange:X,t:i})}),e.jsx(w,{label:"Blocks",children:e.jsx(O,{value:Je,onChange:at,t:i})})]}),e.jsx(w,{label:"Allowed filters",children:e.jsx(O,{value:Ge,onChange:on,t:i})}),e.jsxs("div",{style:ie,children:[e.jsx(w,{label:"Approved purposes",children:e.jsx(O,{value:dn,onChange:bo,t:i,placeholder:"revenue reporting"})}),e.jsx(w,{label:"Consumer domains",children:e.jsx(O,{value:cn,onChange:jo,t:i,placeholder:"growth"})})]}),e.jsxs("div",{style:ie,children:[e.jsx(w,{label:"Classification",children:e.jsx(O,{value:un,onChange:vo,t:i})}),e.jsx(w,{label:"Lifecycle",children:e.jsx(de,{value:xe??"draft",onChange:c=>H(c),values:["draft","review","certified","deprecated"],t:i})})]})]}),t.kind==="import"&&e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Provider export",children:e.jsx(de,{value:pn,onChange:So,values:Object.values(((Ln=n.modeling.interfaces)==null?void 0:Ln.exports)??{}).map(c=>`${c.domain}.${c.localId}@${c.version}`),t:i})}),e.jsx(w,{label:"Exact analytical purpose",children:e.jsx(O,{value:Ee,onChange:m,t:i,placeholder:"Revenue by acquisition channel"})}),e.jsx(w,{label:"Lifecycle",children:e.jsx(de,{value:xe??"draft",onChange:c=>H(c),values:["draft","review","certified","deprecated"],t:i})})]}),t.kind!=="entity"&&t.kind!=="relationship"&&t.kind!=="area"&&e.jsx(w,{label:"Owner",children:e.jsx(O,{value:k,onChange:I,t:i,placeholder:"team@company.com"})}),Ct&&e.jsx(ce,{text:Ct,t:i}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[t.kind==="relationship"&&e.jsxs(K,{t:i,onClick:()=>void Mo(),disabled:qt||!bn,children:[e.jsx(lo,{size:14})," Validate in warehouse"]}),e.jsx(K,{primary:!0,t:i,onClick:()=>void Io(),disabled:qt||!bn,children:"Preview source change"})]})]})})}function ws({data:t,domain:n,t:o,onOpen:s}){var l,u,d;const i=Object.values(t.modeling.entities).filter(p=>!n||p.domain===n),a=n?t.modeling.packages[n]:void 0,x=n?((l=t.domainAssets)==null?void 0:l[n])??{}:Object.values(t.domainAssets??{}).reduce((p,g)=>{for(const[b,h]of Object.entries(g))p[b]=[...p[b]??[],...h];return p},{});return e.jsxs(Ie,{children:[e.jsx(Me,{title:(a==null?void 0:a.id)??"Domains",detail:a?"Business context for reusable blocks, safe models, and agent instructions.":"Choose a domain to work with its blocks, modeling, and skills.",t:o}),a&&e.jsxs("div",{style:{display:"grid",gap:16,maxWidth:980},children:[e.jsxs("section",{style:{border:`1px solid ${o.headerBorder}`,borderRadius:8,background:o.cellBg,display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(175px, 1fr))"},children:[e.jsx(Ht,{label:"Owner",value:a.owner??"Not declared",t:o}),e.jsx(Ht,{label:"Parent",value:a.parent??"Top-level domain",t:o}),e.jsx(Ht,{label:"Source",value:a.filePath,t:o})]}),e.jsxs("section",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[e.jsx("h3",{style:{margin:0,fontSize:12},children:"Continue building"}),e.jsxs("span",{style:{color:o.textMuted,fontSize:10},children:["Everything here is scoped to ",a.id,"."]})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(190px, 1fr))",gap:8},children:[{id:"blocks",title:"Blocks",count:((u=x.blocks)==null?void 0:u.length)??0,detail:"Reusable analytics.",icon:e.jsx(en,{size:16})},{id:"diagram",title:"Modeling",count:i.length,detail:"Models and relationships.",icon:e.jsx(so,{size:16})},{id:"knowledge",title:"Knowledge 360",count:Object.values(t.modeling.relationships).filter(p=>{var g,b;return((g=t.modeling.entities[p.from])==null?void 0:g.domain)===n||((b=t.modeling.entities[p.to])==null?void 0:b.domain)===n}).length,detail:"Governed routes and evidence.",icon:e.jsx(io,{size:16})},{id:"skills",title:"Skills",count:((d=x.skills)==null?void 0:d.length)??0,detail:"Agent instructions.",icon:e.jsx(tn,{size:16})}].map(p=>e.jsxs("button",{type:"button",onClick:()=>s(p.id),style:Ks(o),children:[e.jsx("span",{style:{display:"grid",placeItems:"center",width:28,height:28,borderRadius:6,color:o.accent,background:`${o.accent}12`},children:p.icon}),e.jsxs("span",{style:{flex:1,minWidth:0,display:"grid",gap:2,textAlign:"left"},children:[e.jsx("b",{style:{fontSize:11},children:p.title}),e.jsx("span",{style:{color:o.textSecondary,fontSize:10},children:p.detail})]}),e.jsx("strong",{style:{color:o.accent,fontSize:16},children:p.count})]},p.id))})]})]})]})}function Ht({label:t,value:n,t:o}){return e.jsxs("div",{style:{minWidth:0,padding:"10px 12px",borderRight:`1px solid ${o.headerBorder}`},children:[e.jsx("div",{style:{color:o.textMuted,fontSize:9,fontWeight:800,textTransform:"uppercase",letterSpacing:".05em"},children:t}),e.jsx("div",{title:n,style:{marginTop:4,color:o.textSecondary,fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n})]})}function ks({search:t,onSearch:n,items:o,onPick:s,t:i}){var b;const[a,x]=r.useState(!1),l=r.useRef(null),u=t.trim().toLowerCase(),d=u?o.filter(h=>h.label.toLowerCase().includes(u)||h.sublabel.toLowerCase().includes(u)).sort((h,y)=>h.type===y.type?h.label.localeCompare(y.label):h.type==="model"?-1:1).slice(0,14):[],p=h=>h==="dimension"?"var(--status-success)":h==="bridge"?"var(--status-warning)":h==="event"||h==="snapshot"?"var(--accent)":"var(--text-tertiary)",g=a&&u?(b=l.current)==null?void 0:b.getBoundingClientRect():void 0;return e.jsxs("label",{ref:l,style:{position:"relative",width:210,flex:"0 0 210px"},children:[e.jsx(Pt,{size:12,style:{position:"absolute",left:7,top:8,color:i.textMuted}}),e.jsx("input",{"aria-label":"Search diagram",value:t,onChange:h=>{n(h.target.value),x(!0)},onFocus:()=>x(!0),placeholder:"Find model or column",style:{...ge(i),padding:"6px 7px 6px 24px"}}),g&&e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:()=>x(!1),style:{position:"fixed",inset:0,zIndex:60}}),e.jsx("div",{style:{position:"fixed",top:g.bottom+5,left:g.left,zIndex:61,width:300,maxHeight:340,overflow:"auto",background:i.cellBg,border:`1px solid ${i.headerBorder}`,borderRadius:9,boxShadow:"0 12px 30px rgba(26,26,26,0.16)",padding:4},children:d.length===0?e.jsx("div",{style:{padding:"10px 10px",fontSize:11.5,color:i.textMuted,fontFamily:i.font},children:"No matching model or column."}):d.map((h,y)=>e.jsxs("button",{type:"button",onMouseDown:j=>{j.preventDefault(),s(h.recordKey),x(!1)},style:{width:"100%",display:"flex",alignItems:"center",gap:8,textAlign:"left",padding:"7px 8px",border:"none",borderRadius:6,background:"transparent",cursor:"pointer",fontFamily:i.font},children:[e.jsx("span",{style:{width:7,height:7,borderRadius:999,background:p(h.role),flexShrink:0}}),e.jsx("span",{style:{flex:1,minWidth:0,fontSize:12,fontWeight:h.type==="model"?650:500,color:i.textPrimary,fontFamily:i.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h.label}),e.jsx("span",{style:{flexShrink:0,fontSize:9,fontWeight:700,letterSpacing:"0.04em",textTransform:"uppercase",color:i.textMuted},children:h.type==="model"?"model":h.sublabel})]},`${h.type}-${h.recordKey}-${h.label}-${y}`))})]})]})}function Cs({modelingView:t,columnMode:n,search:o,layoutMode:s,density:i,visibleLimit:a,totalEntities:x,dimUnrelated:l,showEdgeLabels:u,showLegend:d,fullscreen:p,onBindModel:g,onRelationship:b,onNewArea:h,onModelingView:y,onColumnMode:j,onSearch:f,searchItems:k,onPickModel:I,onLayoutMode:v,onDensity:B,onVisibleLimit:R,onDimUnrelated:T,onEdgeLabels:Y,onLegend:D,onFullscreen:U,onExport:G,onReset:q,t:N}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,minHeight:50,padding:"0 10px",borderBottom:`1px solid ${N.headerBorder}`,background:N.headerBg,flexWrap:"nowrap",overflowX:"auto",scrollbarWidth:"thin"},children:[e.jsxs("div",{role:"group","aria-label":"Modeling view",style:{display:"inline-flex",alignItems:"center",gap:2,padding:2,border:`1px solid ${N.headerBorder}`,borderRadius:7,background:N.appBg,flexShrink:0},children:[e.jsx("button",{type:"button",onClick:()=>y("business"),style:{border:"none",borderRadius:5,padding:"4px 11px",fontSize:11.5,fontWeight:600,cursor:"pointer",fontFamily:N.font,whiteSpace:"nowrap",background:t==="business"?"var(--accent-dim)":"transparent",color:t==="business"?N.accent:N.textMuted},children:"Business modeling"}),e.jsx("button",{type:"button",onClick:()=>y("data"),style:{border:"none",borderRadius:5,padding:"4px 11px",fontSize:11.5,fontWeight:600,cursor:"pointer",fontFamily:N.font,whiteSpace:"nowrap",background:t==="data"?"var(--accent-dim)":"transparent",color:t==="data"?N.accent:N.textMuted},children:"Data modeling"})]}),e.jsxs("button",{type:"button",onClick:g,style:Vt(N,!0),children:[e.jsx(ke,{size:13})," Add model"]}),e.jsxs("button",{type:"button",onClick:b,style:Vt(N),children:[e.jsx(Ze,{size:13})," Connect"]}),e.jsxs("button",{type:"button",onClick:h,style:Vt(N),children:[e.jsx(We,{size:13})," New area"]}),t==="data"&&e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:5,color:N.textMuted,fontSize:10},children:[e.jsx(co,{size:13}),e.jsxs("select",{"aria-label":"Visible columns",value:n,onChange:ne=>j(ne.target.value),style:{...ge(N),width:104,padding:"5px 6px"},children:[e.jsx("option",{value:"keys",children:"Keys only"}),e.jsx("option",{value:"relevant",children:"Relevant"}),e.jsx("option",{value:"all",children:"All columns"})]})]}),e.jsx(ks,{search:o,onSearch:f,items:k,onPick:I,t:N}),e.jsxs("select",{"aria-label":"Diagram layout",value:s,onChange:ne=>{v(ne.target.value),q()},style:{...ge(N),width:94,padding:"5px 6px"},children:[e.jsx("option",{value:"auto",children:"Auto"}),e.jsx("option",{value:"grid",children:"Grid"}),e.jsx("option",{value:"star",children:"Star"})]}),e.jsxs("select",{"aria-label":"Diagram density",value:i,onChange:ne=>B(ne.target.value),style:{...ge(N),width:92,padding:"5px 6px"},children:[e.jsx("option",{value:"compact",children:"Compact"}),e.jsx("option",{value:"normal",children:"Normal"}),e.jsx("option",{value:"wide",children:"Wide"})]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:4,color:N.textMuted,fontSize:9.5},children:["Canvas ",e.jsxs("select",{"aria-label":"Visible model limit",value:a||50,onChange:ne=>R(Number(ne.target.value)),style:{...ge(N),width:94,padding:"5px 6px"},children:[e.jsx("option",{value:25,children:"25 models"}),e.jsx("option",{value:50,children:"50 models"}),e.jsx("option",{value:100,children:"100 models"}),e.jsx("option",{value:200,children:"200 max"})]})]}),e.jsx("button",{"aria-label":"Dim unrelated models",title:"Dim unrelated models",onClick:()=>T(!l),style:{...fe(N),color:l?N.accent:N.textMuted},children:e.jsx(_o,{size:14})}),e.jsx("button",{"aria-label":"Toggle relationship labels",title:"Toggle relationship labels",onClick:()=>Y(!u),style:{...fe(N),color:u?N.accent:N.textMuted},children:e.jsx(Ze,{size:14})}),e.jsx("button",{"aria-label":"Relationship legend",title:"Relationship legend",onClick:()=>D(!d),style:{...fe(N),color:d?N.accent:N.textMuted},children:e.jsx(We,{size:14})}),e.jsx("button",{"aria-label":"Export diagram as SVG",title:"Export diagram as SVG",onClick:G,style:fe(N),children:e.jsx(Fo,{size:14})}),e.jsx("button",{"aria-label":p?"Exit fullscreen":"Fullscreen diagram",title:p?"Exit fullscreen":"Fullscreen diagram",onClick:U,style:fe(N),children:p?e.jsx(mt,{size:14}):e.jsx(ro,{size:14})}),e.jsx("button",{"aria-label":"Reset to automatic layout",title:"Reset to automatic layout",onClick:q,style:fe(N),children:e.jsx(ts,{size:14})})]})}function Is({t}){return e.jsxs("div",{style:{display:"flex",gap:14,padding:"7px 12px",borderBottom:`1px solid ${t.headerBorder}`,background:t.headerBg,color:t.textSecondary,fontSize:9.5},children:[[["Safe certified","#2e9b63"],["Validated review","#5b73d6"],["Attribution / draft","#9a6b2f"],["Stale certification","#d47822"]].map(([n,o])=>e.jsxs("span",{style:{display:"flex",gap:5,alignItems:"center"},children:[e.jsx("i",{style:{display:"inline-block",width:18,height:3,background:o,borderRadius:2}}),n]},n)),e.jsx("span",{style:{marginLeft:"auto"},children:"1:1 · 1:N · N:1 · N:N"})]})}function Ms(){const t=document.querySelector("#dql-modeling-diagram .react-flow__renderer");if(!(t instanceof HTMLElement))return;const n=t.cloneNode(!0),o=t.getBoundingClientRect(),s=new XMLSerializer().serializeToString(n),i=`<svg xmlns="http://www.w3.org/2000/svg" width="${Math.ceil(o.width)}" height="${Math.ceil(o.height)}"><foreignObject width="100%" height="100%"><div xmlns="http://www.w3.org/1999/xhtml">${s}</div></foreignObject></svg>`,a=URL.createObjectURL(new Blob([i],{type:"image/svg+xml"})),x=document.createElement("a");x.href=a,x.download="dql-domain-model.svg",x.click(),URL.revokeObjectURL(a)}function Ut({data:t,domain:n,kinds:o,title:s,detail:i,t:a}){var l;const x=n?((l=t.domainAssets)==null?void 0:l[n])??{}:Object.values(t.domainAssets??{}).reduce((u,d)=>{for(const[p,g]of Object.entries(d))u[p]=[...u[p]??[],...g];return u},{});return e.jsxs(Ie,{children:[e.jsx(Me,{title:s,detail:i,t:a}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(250px, 1fr))",gap:12},children:o.map(u=>{var d,p;return e.jsxs("section",{style:xt(a),children:[e.jsxs("div",{style:{display:"flex",gap:7,alignItems:"center"},children:[e.jsx(Bt,{size:14,color:a.accent}),e.jsx("b",{style:{textTransform:"capitalize"},children:u}),e.jsx(Xe,{t:a,children:((d=x[u])==null?void 0:d.length)??0})]}),(p=x[u])!=null&&p.length?x[u].map(g=>e.jsx("code",{style:{display:"block",padding:"7px 0",borderBottom:`1px solid ${a.headerBorder}`,color:a.textSecondary,fontSize:10},children:g},g)):e.jsxs("p",{style:{color:a.textMuted,fontSize:11},children:["No ",u," in this domain yet."]})]},u)})})]})}function zs({data:t,domain:n,t:o}){var g,b;const{state:s,dispatch:i}=$t(),[a,x]=r.useState(null),[l,u]=r.useState(null),d=[...new Set(n?((b=(g=t.domainAssets)==null?void 0:g[n])==null?void 0:b.blocks)??[]:Object.values(t.domainAssets??{}).flatMap(h=>h.blocks??[]))].sort(),p=async h=>{x(h),u(null);try{if(n)try{window.localStorage.setItem("dql.block-studio.domain",n)}catch{}const y=s.files.find(f=>f.path===h)??{name:h.split("/").at(-1)??h,path:h,type:"block",folder:h.split("/").slice(0,-1).join("/")};s.files.some(f=>f.path===h)||i({type:"FILE_ADDED",file:y});const j=await le.openBlockStudio(h);i({type:"OPEN_BLOCK_STUDIO",file:y,payload:j})}catch(y){u(y instanceof Error?y.message:String(y))}finally{x(null)}};return e.jsxs(Ie,{children:[e.jsx(Me,{title:"Blocks",detail:n?`Reusable blocks owned by ${n}. Select one to open the exact source in Block Studio.`:"All reusable blocks grouped across the current Domain Packages. Select one to open the exact source in Block Studio.",t:o}),l?e.jsx(ce,{text:l,t:o}):null,d.length?e.jsx("div",{style:{display:"grid",gap:10},children:d.map(h=>{var f;const y=(h.split("/").at(-1)??h).replace(/\.dql$/i,""),j=(f=Object.entries(t.domainAssets??{}).find(([,k])=>{var I;return(I=k.blocks)==null?void 0:I.includes(h)}))==null?void 0:f[0];return e.jsxs("button",{type:"button",onClick:()=>void p(h),"aria-label":`Open block ${y}`,style:{...xt(o),width:"100%",textAlign:"left",cursor:"pointer"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(en,{size:14,color:o.accent}),e.jsx("b",{children:y}),n?null:e.jsx(Xe,{t:o,children:j??"shared"}),a===h?e.jsx(Xe,{t:o,children:"Opening…"}):null]}),e.jsx("code",{style:{display:"block",marginTop:7,color:o.textMuted,fontSize:10},children:h})]},h)})}):e.jsx(Ce,{title:"No domain blocks yet",detail:"Create a block in Block Studio and assign this domain to make it appear here.",t:o})]})}function Gn({data:t,domain:n,kind:o,t:s}){var k,I;const{state:i,dispatch:a}=$t(),[x,l]=r.useState([]),[u,d]=r.useState(!0),[p,g]=r.useState(null),[b,h]=r.useState(null);r.useEffect(()=>{let v=!0;return d(!0),(n?le.getRelatedDomainProducts(n):le.getAllRelatedDomainProducts()).then(B=>{v&&l(B[o])}).catch(()=>{v&&l([])}).finally(()=>{v&&d(!1)}),()=>{v=!1}},[n,o]);const y=n?((I=(k=t.domainAssets)==null?void 0:k[n])==null?void 0:I[o])??[]:Object.values(t.domainAssets??{}).flatMap(v=>v[o]??[]),j=o==="notebooks"?"Notebooks":"Apps",f=async v=>{const B=String(v.id??v.filePath??v.title??v.name??"product");g(B),h(null);try{if(o==="apps"){const U=String(v.id??Yn(String(v.filePath??"")));if(!U)throw new Error("This App has no stable id to open.");a({type:"OPEN_APP",appId:U,experience:"view",section:"dashboards"});return}const R=String(v.filePath??"");if(!R)throw new Error("This Notebook has no source path to open.");const T=i.files.find(U=>U.path===R)??{name:R.split("/").at(-1)??String(v.title??B),path:R,type:"notebook",folder:R.split("/").slice(0,-1).join("/"),...typeof v.ownerDomain=="string"?{ownerDomain:v.ownerDomain}:{},usesDomains:Array.isArray(v.usesDomains)?v.usesDomains.map(String):[]};i.files.some(U=>U.path===R)||a({type:"FILE_ADDED",file:T});const{content:Y}=await le.readNotebook(R),D=Wo(R,Y);a({type:"OPEN_FILE",file:T,cells:D.cells,title:D.title,metadata:D.metadata})}catch(R){h(R instanceof Error?R.message:String(R))}finally{g(null)}};return e.jsxs(Ie,{children:[e.jsx(Me,{title:n?`Related ${j}`:`All ${j}`,detail:n?`${j} are global shared products related to ${n}. This backlink does not create a second copy inside the Domain Package.`:`All global ${j.toLowerCase()} across Domain Packages. Select a domain above to narrow by owner/uses-domain metadata.`,t:s}),b?e.jsx(ce,{text:b,t:s}):null,u?e.jsx(Ce,{title:`Loading related ${j.toLowerCase()}…`,detail:"Resolving global product backlinks from the compiled project snapshot.",t:s}):x.length?e.jsx("div",{style:{display:"grid",gap:10},children:x.map(v=>{const B=String(v.id??v.filePath??v.title??"product"),R=Array.isArray(v.usesDomains)?v.usesDomains.map(String):[],T=String(v.name??v.title??B);return e.jsxs("button",{type:"button",onClick:()=>void f(v),"aria-label":`Open ${o==="notebooks"?"notebook":"app"} ${T}`,style:{...xt(s),width:"100%",textAlign:"left",cursor:"pointer"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(Bt,{size:14,color:s.accent}),e.jsx("b",{children:T}),v.lifecycle?e.jsx(Xe,{t:s,children:String(v.lifecycle)}):null,p===B?e.jsx(Xe,{t:s,children:"Opening…"}):null]}),e.jsx("p",{style:{color:s.textSecondary,fontSize:11,margin:"7px 0 0"},children:String(v.purpose??"No analytical purpose declared yet.")}),e.jsx("code",{style:{display:"block",marginTop:7,color:s.textMuted,fontSize:10},children:String(v.filePath??"")}),e.jsxs("div",{style:{marginTop:7,color:s.textMuted,fontSize:10},children:["Owner: ",String(v.ownerDomain??"Shared")," · Uses: ",R.join(", ")||"none declared"]})]},B)})}):y.length?e.jsxs("div",{style:{display:"grid",gap:10},children:[e.jsx(ce,{text:"These paths use the legacy domain-local layout. They remain readable during migration, but new products should be global and declare ownerDomain / usesDomains.",t:s}),y.map(v=>e.jsxs("button",{type:"button",onClick:()=>void f({id:o==="apps"?Yn(v):v,filePath:v}),"aria-label":`Open ${o==="notebooks"?"notebook":"app"} ${v}`,style:{...xt(s),width:"100%",textAlign:"left",cursor:"pointer"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(Bt,{size:14,color:s.accent}),e.jsx("code",{style:{color:s.textPrimary,fontSize:11},children:v})]}),e.jsx("p",{style:{color:s.textMuted,fontSize:10,margin:"7px 0 0"},children:"Legacy backlink · migrate without duplicating the product."})]},v))]}):e.jsx(Ce,{title:`No related ${j.toLowerCase()} yet`,detail:`Create the ${o==="notebooks"?"notebook":"app"} from the global ${j} surface, then declare this domain in its product context to make the backlink appear here.`,t:s})]})}function Yn(t){const n=t.replace(/\\/g,"/").split("/").filter(Boolean),o=n.indexOf("apps");return o>=0?n[o+1]??"":""}function Ds({domain:t,selectedId:n,data:o,t:s,onOpenSkills:i,onDraftRelationship:a}){const[x,l]=r.useState(null),[u,d]=r.useState([]),[p,g]=r.useState(!1),[b,h]=r.useState(null),y=async()=>{try{g(!0),h(null);const f=await le.startContextBootstrap({ai:!0});l(f),d(f.candidates.filter(k=>{var I;return!t||k.kind!=="domain"||((I=k.domain)==null?void 0:I.id)===t}).map(k=>k.id))}catch(f){h(f instanceof Error?f.message:String(f))}finally{g(!1)}},j=async()=>{if(x)try{g(!0),await le.saveContextBootstrapSelected(x.id,u),h("Selected domain and skill drafts were saved. Review them in Git before activation.")}catch(f){h(f instanceof Error?f.message:String(f))}finally{g(!1)}};return e.jsxs(Ie,{children:[e.jsx(Me,{title:"Modeling Copilot",detail:"AI can propose business context and modeling work from dbt evidence. It writes drafts only; relationships, contracts, blocks, and skills still require explicit review.",t:s,action:e.jsxs(K,{primary:!0,t:s,onClick:()=>void y(),disabled:p,children:[e.jsx(ao,{size:14})," Analyze project"]})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, minmax(190px, 1fr))",gap:10,marginBottom:18},children:[e.jsx(Kt,{icon:e.jsx(We,{size:16}),title:"Domains and concepts",detail:"Detect ownership boundaries, vocabulary, concepts, and candidate subdomains.",t:s}),e.jsx(Kt,{icon:e.jsx(Ze,{size:16}),title:"Relationship proposals",detail:"Suggest keys and cardinality from dbt evidence, then require warehouse validation.",t:s,action:e.jsx("button",{style:Fe(s),onClick:a,children:"Draft manually"})}),e.jsx(Kt,{icon:e.jsx(tn,{size:16}),title:"Domain skills",detail:"Draft governed vocabulary, preferred metrics, blocks, and clarification rules.",t:s,action:e.jsx("button",{style:Fe(s),onClick:i,children:"Manage skills"})})]}),e.jsx(ce,{text:`Active scope: ${t??"all domains"}${n?` · focused object: ${n}`:""} · ${Object.keys(o.modeling.entities).length} bindings · ${Object.keys(o.modeling.relationships).length} governed relationships. AI proposals never treat dbt lineage as join proof and never auto-certify.`,t:s}),x&&e.jsxs("div",{style:{marginTop:16},children:[e.jsx("h3",{style:Qt(s),children:"Review proposal pack"}),x.candidates.length?x.candidates.map(f=>{var k,I,v;return e.jsxs("label",{style:{display:"grid",gridTemplateColumns:"20px 110px 1fr 70px",gap:8,padding:"10px 8px",borderBottom:`1px solid ${s.headerBorder}`,fontSize:11},children:[e.jsx("input",{type:"checkbox",checked:u.includes(f.id),onChange:B=>d(R=>B.target.checked?[...R,f.id]:R.filter(T=>T!==f.id))}),e.jsx("b",{children:f.kind}),e.jsxs("span",{children:[((k=f.domain)==null?void 0:k.name)??((I=f.domain)==null?void 0:I.id)??((v=f.skill)==null?void 0:v.id)??f.id,e.jsx("small",{style:{display:"block",color:s.textMuted,marginTop:3},children:f.evidence.slice(0,2).join(" · ")||"Evidence review required"})]}),e.jsxs("span",{children:[Math.round(f.confidence*100),"%"]})]},f.id)}):e.jsx(Ce,{title:"No proposals",detail:"The current project evidence did not produce a safe domain or skill proposal.",t:s}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:12},children:e.jsx(K,{primary:!0,t:s,onClick:()=>void j(),disabled:p||u.length===0,children:"Save selected drafts"})})]}),b&&e.jsx("div",{style:{marginTop:12},children:e.jsx(ce,{text:b,t:s})})]})}function Kt({icon:t,title:n,detail:o,t:s,action:i}){return e.jsxs("div",{style:xt(s),children:[e.jsxs("div",{style:{display:"flex",gap:7,color:s.accent},children:[t,e.jsx("b",{style:{color:s.textPrimary},children:n})]}),e.jsx("p",{style:{color:s.textSecondary,fontSize:11,lineHeight:1.5},children:o}),i]})}function Bs({data:t,domain:n,t:o,onCreateExport:s,onCreateImport:i}){var l,u;const a=Object.values(((l=t.modeling.interfaces)==null?void 0:l.exports)??{}).filter(d=>!n||d.domain===n),x=Object.values(((u=t.modeling.interfaces)==null?void 0:u.imports)??{}).filter(d=>!n||d.domain===n);return e.jsxs(Ie,{children:[e.jsx(Me,{title:"Cross-domain interfaces",detail:"Domains never join through discovery alone. Providers certify a narrow export; consumers import it for an explicit purpose.",t:o,action:e.jsxs("div",{style:{display:"flex",gap:7},children:[e.jsxs(K,{t:o,onClick:i,children:[e.jsx(ke,{size:14})," Import"]}),e.jsxs(K,{primary:!0,t:o,onClick:s,children:[e.jsx(ke,{size:14})," Export"]})]})}),e.jsx("h3",{style:Qt(o),children:"Published exports"}),a.length?e.jsxs("table",{style:ht,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(_,{children:"Interface"}),e.jsx(_,{children:"Entity"}),e.jsx(_,{children:"Allowed surface"}),e.jsx(_,{children:"Consumers"}),e.jsx(_,{children:"Status"})]})}),e.jsx("tbody",{children:a.map(d=>e.jsxs("tr",{children:[e.jsx(F,{children:e.jsxs("b",{children:[d.domain,".",d.localId,"@",d.version]})}),e.jsx(F,{children:d.entity??"—"}),e.jsx(F,{children:[...d.metrics,...d.blocks,...d.allowedDimensions].join(", ")||"keys only"}),e.jsx(F,{children:d.consumerDomains.join(", ")||"none"}),e.jsx(F,{children:e.jsx(Rt,{status:d.status,t:o})})]},d.qualifiedId))})]}):e.jsx(Ce,{title:"No exports in this scope",detail:"Publish only the entity, metrics, blocks, dimensions, keys, filters, purposes, and consumers another domain may use.",t:o}),e.jsx("h3",{style:Qt(o),children:"Approved imports"}),x.length?e.jsxs("table",{style:ht,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(_,{children:"Import"}),e.jsx(_,{children:"Consumer"}),e.jsx(_,{children:"Provider export"}),e.jsx(_,{children:"Purpose"}),e.jsx(_,{children:"Status"})]})}),e.jsx("tbody",{children:x.map(d=>e.jsxs("tr",{children:[e.jsx(F,{children:e.jsx("b",{children:d.localId})}),e.jsx(F,{children:d.domain}),e.jsx(F,{children:d.exportRef}),e.jsx(F,{children:d.purpose}),e.jsx(F,{children:e.jsx(Rt,{status:d.status,t:o})})]},d.id))})]}):e.jsx(Ce,{title:"No imports in this scope",detail:"A consumer import is required before an automatic cross-domain path can use the provider export.",t:o})]})}function Rs({relationships:t,entities:n,t:o,onSelect:s,onEdit:i}){return e.jsxs(Ie,{children:[e.jsx(Me,{title:"Analytical relationships",detail:"Transformation lineage is context; only these governed edges can prove an analytical join.",t:o}),t.length?e.jsxs("table",{style:ht,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(_,{children:"Relationship"}),e.jsx(_,{children:"Path"}),e.jsx(_,{children:"Cardinality"}),e.jsx(_,{children:"Safety"}),e.jsx(_,{children:"Status"}),e.jsx(_,{children:"Proof"}),e.jsx(_,{})]})}),e.jsx("tbody",{children:t.map(a=>{var x,l,u;return e.jsxs("tr",{onClick:()=>s(a),style:{cursor:"pointer"},children:[e.jsx(F,{children:e.jsx("b",{children:a.localId})}),e.jsxs(F,{children:[a.from," ",e.jsx("span",{style:{color:o.textMuted},children:"→"})," ",a.to,((x=n[a.from])==null?void 0:x.domain)!==((l=n[a.to])==null?void 0:l.domain)&&e.jsx(Xe,{t:o,children:"cross-domain"})]}),e.jsx(F,{children:a.cardinality.replace(/_/g," ")}),e.jsx(F,{children:a.fanout}),e.jsx(F,{children:e.jsx(Rt,{status:a.status,t:o})}),e.jsx(F,{children:a.automaticJoinAllowed?e.jsx("span",{style:{color:"#2e9b63"},children:"certified"}):a.staleCertification?e.jsx("span",{style:{color:"#d47822"},children:"stale"}):((u=a.validation)==null?void 0:u.status)??"not run"}),e.jsx(F,{children:e.jsx("button",{onClick:d=>{d.stopPropagation(),i(a)},style:Fe(o),children:"Edit"})})]},a.qualifiedId??a.id)})})]}):e.jsx(Ce,{title:"No join proofs in this domain",detail:"Drag from a source column handle to a target column handle in Domain Model to create a draft, then validate its cardinality and fanout.",t:o})]})}function $s({data:t,domain:n,t:o,onCreate:s}){const i=Object.values(t.modeling.contracts).filter(a=>!n||a.domain===n);return e.jsxs(Ie,{children:[e.jsx(Me,{title:"Analytical contracts",detail:"Contracts bind governed entities and blocks to evaluation and review requirements.",t:o,action:e.jsxs(K,{primary:!0,t:o,onClick:s,children:[e.jsx(ke,{size:14})," Contract"]})}),i.length?e.jsxs("table",{style:ht,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(_,{children:"Contract"}),e.jsx(_,{children:"Domain"}),e.jsx(_,{children:"Entities"}),e.jsx(_,{children:"Blocks"}),e.jsx(_,{children:"Status"}),e.jsx(_,{children:"Evaluation"})]})}),e.jsx("tbody",{children:i.map(a=>e.jsxs("tr",{children:[e.jsx(F,{children:e.jsx("b",{children:a.id})}),e.jsx(F,{children:a.domain}),e.jsx(F,{children:a.entities.join(", ")||"—"}),e.jsx(F,{children:a.blocks.join(", ")||"—"}),e.jsx(F,{children:e.jsx(Rt,{status:a.status,t:o})}),e.jsx(F,{children:a.requiredEvaluation?"Required":"Optional"})]},a.id))})]}):e.jsx(Ce,{title:"No contracts in this scope",detail:"Create a contract when a set of entities and certified blocks must move through evaluation and review together.",t:o})]})}function Ps({data:t,domain:n,unbound:o,t:s,onBind:i}){const[a,x]=r.useState(""),[l,u]=r.useState(0),d=50,p=new Set(Xt(t.modeling,n).map(({entity:f})=>f.dbtUniqueId)),g=a.trim().toLowerCase(),b=Object.values(t.dbtProvenance.nodes).filter(f=>n&&!p.has(f.uniqueId)?!1:g?[f.name,f.uniqueId,f.relation,f.sourcePath].some(k=>String(k??"").toLowerCase().includes(g)):!0),h=Math.max(1,Math.ceil(b.length/d)),y=Math.min(l,h-1),j=b.slice(y*d,(y+1)*d);return e.jsxs(Ie,{children:[e.jsx(Me,{title:"dbt-owned scope",detail:`Read on demand from ${t.dbtProvenance.manifestPath}. Columns, descriptions, tests, and MetricFlow formulas remain dbt-owned.${n?" This view shows dbt models already bound to this domain.":""}`,t:s,action:e.jsxs("label",{style:{position:"relative",width:230},children:[e.jsx(Pt,{size:13,style:{position:"absolute",top:9,left:8,color:s.textMuted}}),e.jsx("input",{"aria-label":"Search dbt scope",value:a,onChange:f=>{x(f.target.value),u(0)},placeholder:"Find model, relation, or path",style:{...ge(s),paddingLeft:27}})]})}),j.length?e.jsxs(e.Fragment,{children:[e.jsxs("table",{style:ht,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(_,{children:"dbt model"}),e.jsx(_,{children:"Relation"}),e.jsx(_,{children:"Source"}),e.jsx(_,{children:"Metadata"}),e.jsx(_,{})]})}),e.jsx("tbody",{children:j.map(f=>{const k=o.some(I=>I.uniqueId===f.uniqueId);return e.jsxs("tr",{children:[e.jsx(F,{children:e.jsx("b",{children:f.name})}),e.jsx(F,{children:f.relation??"—"}),e.jsx(F,{children:f.sourcePath??"—"}),e.jsx(F,{children:Object.entries(f.available).filter(([,I])=>I).map(([I])=>I).join(", ")}),e.jsx(F,{children:k?e.jsx("button",{onClick:()=>i(f.uniqueId),style:Fe(s),children:"Bind"}):e.jsx("span",{style:{color:"#2e9b63"},children:"Bound"})})]},f.uniqueId)})})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:12,color:s.textMuted,fontSize:10},children:[e.jsxs("span",{children:[b.length," models · page ",y+1," of ",h]}),e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsx(K,{t:s,disabled:y===0,onClick:()=>u(f=>Math.max(0,f-1)),children:"Previous"}),e.jsx(K,{t:s,disabled:y>=h-1,onClick:()=>u(f=>Math.min(h-1,f+1)),children:"Next"})]})]})]}):e.jsx(Ce,{title:a?"No dbt models match this search":n?"No dbt models are bound to this domain":"No dbt models found",detail:n?"Use Bind model in Domain Model to add a dbt model without copying its schema.":"Compile the dbt project, then refresh Domain Studio.",t:s})]})}function Ns({entity:t,detail:n,relationships:o=[],t:s,onEdit:i,onEditDbtSource:a,onSelectRelationship:x,onDelete:l}){var b,h,y,j;const u=no(t.analyticalRole),d=new Set(t.keys.length?t.keys:((b=n==null?void 0:n.dqlMeta)==null?void 0:b.keys)??[]),p={fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:s.textMuted,margin:"0 0 5px"},g=o.filter(f=>f.from===t.id||f.to===t.id||f.from===t.localId||f.to===t.localId);return e.jsxs(nn,{t:s,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,marginBottom:12},children:[e.jsx("span",{style:{width:8,height:8,borderRadius:2.5,background:u,flexShrink:0}}),e.jsx("span",{style:{flex:1,minWidth:0,fontSize:13.5,fontWeight:700,color:s.textPrimary,fontFamily:s.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.businessName||t.localId}),e.jsx("span",{style:{flexShrink:0,fontSize:9,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em",color:u},children:t.analyticalRole??"entity"})]}),e.jsx("p",{style:{margin:"0 0 12px",color:s.textSecondary,fontSize:12,lineHeight:1.6},children:t.businessContext||`Add the DQL-owned business context for ${t.localId}. dbt descriptions remain physical-source documentation.`}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:p,children:"dbt binding"}),e.jsx("div",{style:{fontSize:11,fontFamily:s.fontMono,color:s.textPrimary,background:"var(--bg-1)",border:"1px solid var(--border-subtle)",borderRadius:7,padding:"7px 9px",overflowWrap:"anywhere"},children:(n==null?void 0:n.relation)??t.dbtUniqueId})]}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsxs("div",{style:p,children:["Columns · ",(n==null?void 0:n.columns.length)??"…"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column"},children:n==null?void 0:n.columns.slice(0,16).map(f=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,padding:"4px 2px",borderBottom:"1px solid var(--border-subtle)",fontSize:11.5},children:[e.jsx("span",{style:{flexShrink:0,width:17,fontSize:8.5,fontWeight:700,fontFamily:s.fontMono,color:d.has(f.name)?"var(--pk)":/(^|_)id$/.test(f.name)?"var(--fk)":"transparent"},children:d.has(f.name)?"PK":/(^|_)id$/.test(f.name)?"FK":"·"}),e.jsx("span",{style:{flex:1,minWidth:0,color:s.textSecondary,fontFamily:s.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:f.name}),e.jsx("span",{style:{flexShrink:0,fontSize:10,color:s.textMuted,fontFamily:s.fontMono},children:f.type??"—"})]},f.name))})]}),g.length>0&&x?e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:p,children:"Relationships"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:g.map(f=>e.jsxs("button",{type:"button",onClick:()=>x(f),style:{display:"flex",alignItems:"center",gap:7,padding:"6px 8px",borderRadius:7,border:"1px solid var(--border-subtle)",background:"var(--bg-1)",cursor:"pointer",textAlign:"left",fontFamily:s.font,fontSize:11,color:s.textSecondary},children:[e.jsx("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:f.localId}),e.jsx("span",{style:{fontFamily:s.fontMono,fontSize:10,color:s.textMuted,flexShrink:0},children:f.cardinality==="one_to_one"?"1:1":f.cardinality==="one_to_many"?"1:N":f.cardinality==="many_to_one"?"N:1":"N:N"})]},f.qualifiedId??f.localId))})]}):null,e.jsxs("details",{style:{marginBottom:12},children:[e.jsx("summary",{style:{...p,cursor:"pointer"},children:"More metadata"}),e.jsx(pe,{label:"concepts",value:((h=t.conceptRefs)==null?void 0:h.join(", "))||"Not mapped",t:s}),e.jsx(pe,{label:"owner",value:t.owner??"Not declared",t:s}),e.jsx(pe,{label:"grain",value:t.grain??((y=n==null?void 0:n.dqlMeta)==null?void 0:y.grain)??"Not declared",t:s}),e.jsx(pe,{label:"keys",value:(t.keys.length?t.keys:((j=n==null?void 0:n.dqlMeta)==null?void 0:j.keys)??[]).join(", ")||"Not declared",t:s}),e.jsx(pe,{label:"source",value:(n==null?void 0:n.sourcePath)??t.sourcePath,t:s}),e.jsx(pe,{label:"dbt description",value:(n==null?void 0:n.description)??"Not declared",t:s})]}),e.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[e.jsx(K,{primary:!0,t:s,onClick:i,children:"Edit entity"}),e.jsx(K,{t:s,onClick:a,children:"Preview dbt source patch"}),l?e.jsx(K,{t:s,danger:!0,onClick:l,children:"Delete entity"}):null]})]})}function Os({entity:t,detail:n,snapshotId:o,t:s,onClose:i,onApplied:a}){const x=n.columns.filter(B=>B.tests.length>0).map(B=>`${B.name}: ${B.tests.join(", ")}`).join(`
|
|
22
|
-
`),[l,u]=r.useState(n.description??""),[d,p]=r.useState(x),[g,b]=r.useState(null),[h,y]=r.useState(!1),[j,f]=r.useState(null),k=()=>({uniqueId:t.dbtUniqueId,description:l,columns:d.split(/\r?\n/).flatMap(B=>{const R=B.indexOf(":");if(R<1)return[];const T=B.slice(0,R).trim(),Y=J(B.slice(R+1));return T?[{name:T,tests:Y}]:[]})}),I=async()=>{try{y(!0),f(null),b(await le.previewDbtSourcePatch(k(),o))}catch(B){f(B instanceof Error?B.message:String(B))}finally{y(!1)}},v=async()=>{if(g)try{y(!0),f(null),await le.applyDbtSourcePatch(k(),g.fingerprint,g.snapshotId),await a()}catch(B){f(B instanceof Error?B.message:String(B))}finally{y(!1)}};return e.jsxs(xo,{title:`Edit dbt source · ${n.name}`,t:s,onClose:i,children:[e.jsx(ce,{text:"dbt owns descriptions and tests. DQL will preview a guarded patch to the dbt YAML source; no dbt metadata is copied into the Domain Package.",t:s}),g?e.jsxs("div",{style:{display:"grid",gap:10},children:[e.jsxs("div",{style:{color:s.textSecondary,fontSize:11},children:["Source: ",e.jsx("code",{children:g.patch.path})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[e.jsx(Qn,{title:"Current dbt YAML",source:g.patch.before||"# New dbt schema YAML",t:s}),e.jsx(Qn,{title:"Proposed dbt YAML",source:g.patch.after,t:s})]}),j&&e.jsx(ce,{text:j,t:s}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:7},children:[e.jsx(K,{t:s,onClick:()=>b(null),children:"Back"}),e.jsx(K,{primary:!0,t:s,disabled:h||!g.patch.changed,onClick:()=>void v(),children:g.patch.changed?"Apply dbt source patch":"No changes"})]})]}):e.jsxs("div",{style:{display:"grid",gap:12},children:[e.jsx(w,{label:"Model description",children:e.jsx("textarea",{"aria-label":"Model description",value:l,onChange:B=>u(B.target.value),rows:5,style:{...ge(s),resize:"vertical"}})}),e.jsx(w,{label:"Column tests (one column per line)",children:e.jsx("textarea",{"aria-label":"Column tests",value:d,onChange:B=>p(B.target.value),rows:6,placeholder:"order_id: unique, not_null",style:{...ge(s),resize:"vertical",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace"}})}),e.jsx("p",{style:{margin:0,color:s.textMuted,fontSize:10},children:"Descriptions/tests stay in dbt YAML. Business meaning, relationships, contracts, and policies stay in the DQL Domain Package."}),j&&e.jsx(ce,{text:j,t:s}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:7},children:[e.jsx(K,{t:s,onClick:i,children:"Cancel"}),e.jsx(K,{primary:!0,t:s,disabled:h,onClick:()=>void I(),children:"Preview source patch"})]})]})]})}function Qn({title:t,source:n,t:o}){return e.jsxs("section",{children:[e.jsx("strong",{style:{fontSize:10},children:t}),e.jsx("pre",{tabIndex:0,style:{maxHeight:360,overflow:"auto",whiteSpace:"pre-wrap",background:o.appBg,border:`1px solid ${o.headerBorder}`,borderRadius:6,padding:10,fontSize:9.5,color:o.textSecondary},children:n})]})}function As({relationship:t,t:n,onEdit:o,onDelete:s}){var i,a,x;return e.jsxs(nn,{t:n,children:[e.jsx(_s,{title:t.localId,subtitle:`${t.from} → ${t.to}`,t:n}),e.jsx(K,{primary:!0,t:n,onClick:o,children:"Validate / edit"}),e.jsx("h3",{style:to(n),children:"Business meaning"}),e.jsx(pe,{label:"verb",value:t.verb??"Not described",t:n}),e.jsx("p",{style:{margin:"0 0 8px",color:n.textSecondary,fontSize:11,lineHeight:1.55},children:t.description||`${t.from} relates to ${t.to}. Add a business description so agents can distinguish this route from similarly shaped joins.`}),e.jsx("h3",{style:to(n),children:"Join route"}),e.jsx(pe,{label:"cardinality",value:t.cardinality,t:n}),e.jsx(pe,{label:"fanout",value:t.fanout,t:n}),e.jsx(pe,{label:"lifecycle",value:t.status,t:n}),e.jsx(pe,{label:"join keys",value:t.keys.map(l=>`${l.from} = ${l.to}`).join(", "),t:n}),e.jsx(pe,{label:"endpoint roles",value:[(i=t.roles)==null?void 0:i.from,(a=t.roles)==null?void 0:a.to].filter(Boolean).join(" → ")||"Not declared",t:n}),e.jsx(pe,{label:"allowed joins",value:((x=t.joinTypes)==null?void 0:x.join(", "))||"left",t:n}),e.jsx(pe,{label:"automatic agent join",value:t.automaticJoinAllowed?"Allowed":"Blocked",t:n}),t.validation?e.jsx(ho,{evidence:t.validation,t:n}):e.jsx(ce,{text:"No warehouse proof has been captured. This edge cannot authorize automatic SQL joins.",t:n}),e.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginTop:12},children:[e.jsx(K,{primary:!0,t:n,onClick:o,children:"Edit relationship"}),s?e.jsx(K,{t:n,danger:!0,onClick:s,children:"Delete relationship"}):null]})]})}function Es({data:t,domainEntities:n,domainRelationships:o,t:s,onSelectRelationship:i}){var b;const a=((b=n[0])==null?void 0:b.domain)??"All domains",x=o.filter(h=>{var y;return((y=h.validation)==null?void 0:y.status)==="passed"}).length,l=n.filter(h=>!!h.dbtUniqueId).length,u=n.filter(h=>!h.businessContext),d={fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:s.textMuted,margin:"14px 0 5px"},p=(h,y)=>e.jsxs("div",{style:{border:"1px solid var(--border-subtle)",borderRadius:9,padding:"10px 12px",background:"var(--bg-1)"},children:[e.jsx("div",{style:{fontSize:18,fontWeight:700,color:s.textPrimary},children:h}),e.jsx("div",{style:{fontSize:10.5,color:s.textMuted},children:y})]}),g=(h,y)=>e.jsxs("span",{style:{display:"flex",alignItems:"flex-start",gap:7,fontSize:11.5,color:s.textSecondary,lineHeight:1.45},children:[e.jsx("span",{style:{color:h?"var(--status-success)":"var(--status-warning)",flexShrink:0,fontWeight:700},children:h?"✓":"△"}),y]},y);return e.jsxs(nn,{t:s,children:[e.jsxs("div",{style:{fontSize:11,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:s.textMuted},children:[a," model"]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8,marginTop:12},children:[p(n.length,n.length===1?"entity":"entities"),p(o.length,o.length===1?"relationship":"relationships")]}),e.jsx("p",{style:{margin:"12px 0 0",color:s.textSecondary,fontSize:12,lineHeight:1.6},children:"Select an entity to see its columns and dbt binding, or click a relationship label to review its join, cardinality, and business context."}),e.jsx("div",{style:d,children:"Model health"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[o.length>0?g(x===o.length,x===o.length?"All relationships have join proofs":`${x} of ${o.length} relationships have join proofs`):g(!1,"No relationships yet — drag between column handles to create one"),g(l===n.length&&n.length>0,n.length===0?"No entities bound yet — use Bind model":`${l} of ${n.length} entities bound to dbt`),u.length>0?g(!1,`${u[0].localId}${u.length>1?` and ${u.length-1} more`:""} ha${u.length>1?"ve":"s"} no business description`):n.length>0?g(!0,"Every entity has a business description"):null]}),e.jsx("div",{style:d,children:"Relationships"}),o.length?o.map(h=>e.jsxs("button",{onClick:()=>i(h),style:{display:"flex",alignItems:"center",gap:7,width:"100%",textAlign:"left",border:"1px solid var(--border-subtle)",borderRadius:7,background:"var(--bg-1)",color:s.textSecondary,padding:"6px 8px",marginBottom:4,cursor:"pointer",fontSize:11,fontFamily:s.font},children:[e.jsx("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h.localId}),e.jsx("span",{style:{fontFamily:s.fontMono,fontSize:10,color:s.textMuted,flexShrink:0},children:h.cardinality==="one_to_one"?"1:1":h.cardinality==="one_to_many"?"1:N":h.cardinality==="many_to_one"?"N:1":"N:N"})]},h.qualifiedId)):e.jsx("p",{style:{color:s.textMuted,fontSize:10.5,margin:0},children:"Drag between two column handles to create the first relationship."}),e.jsx("div",{style:d,children:"Ownership boundary"}),e.jsx("p",{style:{color:s.textSecondary,fontSize:11,lineHeight:1.55,margin:0},children:"dbt owns tables, columns, descriptions, tests, and metrics. DQL owns domain membership, analytical identity, safe relationship proof, contracts, certified blocks, and agent policy. Shared apps and notebooks reference this domain without moving inside it."})]})}function ho({evidence:t,t:n}){return e.jsxs("div",{style:{marginTop:12,padding:10,border:`1px solid ${t.status==="passed"?"#2e9b6355":"#c94b5555"}`,background:t.status==="passed"?"#2e9b630d":"#c94b550d",borderRadius:7,fontSize:11},children:[e.jsx("b",{style:{color:t.status==="passed"?"#2e9b63":"#c94b55"},children:t.status==="passed"?"Warehouse proof passed":"Warehouse proof failed"}),e.jsxs("div",{style:{color:n.textSecondary,marginTop:7,lineHeight:1.55},children:["Rows: ",t.fromRows," → ",t.toRows,e.jsx("br",{}),"Joined: ",t.joinedRows," · unmatched: ",t.unmatchedFrom,e.jsx("br",{}),"Max rows/key: ",t.maxFromPerKey," → ",t.maxToPerKey]})]})}function Zn({t,title:n,detail:o,status:s}){return e.jsx("div",{style:{flex:1,display:"grid",placeItems:"center",background:t.appBg,color:t.textPrimary},children:e.jsxs("div",{style:{maxWidth:560,textAlign:"center"},children:[e.jsx(We,{size:34,color:t.accent}),e.jsx("h1",{style:{fontSize:20},children:n}),e.jsx("p",{style:{color:t.textSecondary,lineHeight:1.6},children:o}),s&&e.jsx("code",{style:{fontSize:12},children:s})]})})}function xo({title:t,t:n,onClose:o,children:s}){return e.jsx("div",{style:{position:"fixed",inset:0,zIndex:100,background:"#0008",display:"grid",placeItems:"center",padding:20},onMouseDown:i=>{i.target===i.currentTarget&&o()},children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":t,tabIndex:-1,onKeyDown:i=>{i.key==="Escape"&&o()},style:{width:"min(720px, 94vw)",maxHeight:"88vh",overflow:"auto",background:n.appBg,border:`1px solid ${n.headerBorder}`,borderRadius:12,boxShadow:"0 24px 80px #0006"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",padding:"15px 18px",borderBottom:`1px solid ${n.headerBorder}`},children:[e.jsx("strong",{children:t}),e.jsx("button",{"aria-label":`Close ${t}`,title:"Close",onClick:o,style:fe(n),children:e.jsx(mt,{size:17})})]}),e.jsx("div",{style:{padding:18},children:s})]})})}function Xn({current:t,labels:n,t:o}){return e.jsx("div",{"aria-label":`Step ${t} of ${n.length}`,style:{display:"grid",gridTemplateColumns:`repeat(${n.length}, minmax(0, 1fr))`,gap:6},children:n.map((s,i)=>{const a=i+1,x=a===t,l=a<t;return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0,color:x?o.textPrimary:o.textMuted,fontSize:10,fontWeight:x?700:550},children:[e.jsx("span",{style:{display:"grid",placeItems:"center",width:20,height:20,flex:"0 0 auto",borderRadius:999,border:`1px solid ${x||l?o.accent:o.headerBorder}`,background:l?o.accent:x?"var(--accent-dim)":o.appBg,color:l?"#fff":x?o.accent:o.textMuted},children:l?"✓":a}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s})]},s)})})}function eo({title:t,detail:n,t:o}){return e.jsxs("div",{style:{display:"grid",gap:3,padding:"9px 11px",border:`1px solid ${o.headerBorder}`,borderRadius:7,background:o.cellBg},children:[e.jsx("strong",{style:{fontSize:11},children:t}),e.jsx("span",{style:{color:o.textMuted,fontSize:9.5,overflowWrap:"anywhere"},children:n})]})}function Dt({ariaLabel:t,value:n,onChange:o,options:s,placeholder:i,disabled:a=!1,t:x}){const[l,u]=r.useState(!1),[d,p]=r.useState(""),g=s.find(h=>h.value===n),b=gs(s,d,50);return e.jsxs("div",{style:{position:"relative",minWidth:0},children:[e.jsxs("div",{style:{position:"relative"},children:[e.jsx(Pt,{size:13,"aria-hidden":"true",style:{position:"absolute",left:9,top:"50%",transform:"translateY(-50%)",color:x.textMuted,pointerEvents:"none"}}),e.jsx("input",{role:"combobox","aria-label":t,"aria-expanded":l,"aria-controls":l?"modeling-search-results":void 0,disabled:a,value:l?d:(g==null?void 0:g.label)??n,placeholder:i,onFocus:()=>{u(!0),p("")},onBlur:()=>{u(!1),p("")},onChange:h=>{u(!0),p(h.target.value)},onKeyDown:h=>{h.key==="Escape"&&(u(!1),p(""))},style:{...ge(x),paddingLeft:29,paddingRight:n?29:8,opacity:a?.6:1}}),n&&!a&&e.jsx("button",{type:"button","aria-label":"Clear selection",onMouseDown:h=>h.preventDefault(),onClick:()=>{o(""),p(""),u(!0)},style:{...fe(x),position:"absolute",right:3,top:"50%",transform:"translateY(-50%)",width:24,height:24,border:"none"},children:e.jsx(mt,{size:13})})]}),l&&!a&&e.jsxs("div",{id:"modeling-search-results",role:"listbox",style:{position:"absolute",zIndex:90,top:"calc(100% + 4px)",left:0,right:0,maxHeight:230,overflowY:"auto",border:`1px solid ${x.headerBorder}`,borderRadius:7,background:x.cellBg,boxShadow:"0 12px 32px #0004",padding:4},children:[b.length?b.map(h=>e.jsxs("button",{type:"button",role:"option","aria-selected":h.value===n,onMouseDown:y=>y.preventDefault(),onClick:()=>{o(h.value),u(!1),p("")},style:{display:"grid",width:"100%",gap:2,padding:"8px 9px",border:"none",borderRadius:5,textAlign:"left",background:h.value===n?"var(--accent-dim)":"transparent",color:x.textPrimary,cursor:"pointer"},children:[e.jsx("strong",{style:{fontSize:10.5},children:h.label}),h.description&&e.jsx("span",{style:{color:x.textMuted,fontSize:9,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h.description})]},h.value)):e.jsx("div",{style:{padding:12,color:x.textMuted,fontSize:10},children:"No matching results."}),s.length>50&&e.jsxs("div",{style:{padding:"6px 9px 4px",borderTop:`1px solid ${x.headerBorder}`,color:x.textMuted,fontSize:9},children:["Showing the best 50 of ",s.length.toLocaleString(),". Refine your search for a specific result."]})]})]})}function Ts({value:t,onChange:n,selectedNode:o,t:s}){const[i,a]=r.useState(""),[x,l]=r.useState(!1),[u,d]=r.useState(!1),[p,g]=r.useState(0),[b,h]=r.useState([]);return r.useEffect(()=>{let y=!1;const j=window.setTimeout(()=>{d(!0),le.getDbtModelInventory({q:i,limit:50}).then(f=>{y||(g(f.total),h(f.items.map(k=>{var v;const I=k;return{value:I.uniqueId??"",label:I.name??I.uniqueId??"Unnamed model",description:`${I.relation??I.sourcePath??I.uniqueId}${I.binding?` · already bound to ${I.binding.domain??"a domain"}`:" · unbound"}`,keywords:[I.sourcePath??"",((v=I.binding)==null?void 0:v.businessName)??""]}}).filter(k=>k.value)))}).catch(()=>{y||h([])}).finally(()=>{y||d(!1)})},140);return()=>{y=!0,window.clearTimeout(j)}},[i]),e.jsxs("div",{style:{position:"relative"},children:[e.jsxs("div",{style:{position:"relative"},children:[e.jsx(Pt,{size:13,"aria-hidden":"true",style:{position:"absolute",left:9,top:"50%",transform:"translateY(-50%)",color:s.textMuted,pointerEvents:"none"}}),e.jsx("input",{role:"combobox","aria-label":"Search dbt models","aria-expanded":x,value:x?i:(o==null?void 0:o.name)??t,placeholder:"Search model, relation, or path…",onFocus:()=>{l(!0),a("")},onBlur:()=>{l(!1),a("")},onChange:y=>{a(y.target.value),l(!0)},onKeyDown:y=>{y.key==="Escape"&&l(!1)},style:{...ge(s),paddingLeft:29,paddingRight:t?29:8}}),t&&e.jsx("button",{type:"button","aria-label":"Clear dbt model",onMouseDown:y=>y.preventDefault(),onClick:()=>{n(""),l(!0)},style:{...fe(s),position:"absolute",right:3,top:"50%",transform:"translateY(-50%)",width:24,height:24,border:"none"},children:e.jsx(mt,{size:13})})]}),x&&e.jsxs("div",{role:"listbox",style:{position:"absolute",zIndex:90,top:"calc(100% + 4px)",left:0,right:0,maxHeight:260,overflowY:"auto",border:`1px solid ${s.headerBorder}`,borderRadius:7,background:s.cellBg,boxShadow:"0 12px 32px #0004",padding:4},children:[u&&e.jsx("div",{style:{padding:10,color:s.textMuted,fontSize:10},children:"Searching project inventory…"}),!u&&b.map(y=>e.jsxs("button",{type:"button",role:"option","aria-selected":y.value===t,onMouseDown:j=>j.preventDefault(),onClick:()=>{n(y.value),l(!1),a("")},style:{display:"grid",width:"100%",gap:2,padding:"8px 9px",border:"none",borderRadius:5,textAlign:"left",background:y.value===t?"var(--accent-dim)":"transparent",color:s.textPrimary,cursor:"pointer"},children:[e.jsx("strong",{style:{fontSize:10.5},children:y.label}),e.jsx("span",{style:{color:s.textMuted,fontSize:9,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y.description})]},y.value)),!u&&!b.length&&e.jsx("div",{style:{padding:10,color:s.textMuted,fontSize:10},children:"No dbt models match this search."}),!u&&p>b.length&&e.jsxs("div",{style:{padding:"6px 9px 4px",borderTop:`1px solid ${s.headerBorder}`,color:s.textMuted,fontSize:9},children:["Showing 50 of ",p.toLocaleString(),". Keep typing to narrow the inventory."]})]})]})}function w({label:t,children:n}){return e.jsxs("label",{style:{display:"grid",gap:6,fontSize:11,fontWeight:650},children:[t,n]})}function O({value:t,onChange:n,t:o,placeholder:s}){return e.jsx("input",{value:t,placeholder:s,onChange:i=>n(i.target.value),style:ge(o)})}function de({value:t,onChange:n,values:o,labels:s,t:i}){return e.jsxs("select",{value:t,onChange:a=>n(a.target.value),style:ge(i),children:[e.jsx("option",{value:"",children:"Select…"}),o.map(a=>e.jsx("option",{value:a,children:(s==null?void 0:s[a])??a},a))]})}function K({children:t,t:n,onClick:o,primary:s,disabled:i,danger:a}){return e.jsx("button",{disabled:i,onClick:o,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,border:`1px solid ${a?n.error:s?n.accent:n.headerBorder}`,background:a?`${n.error}12`:s?n.accent:n.appBg,color:a?n.error:s?"#fff":n.textPrimary,borderRadius:6,padding:"7px 10px",fontSize:11,fontWeight:650,cursor:i?"wait":"pointer",opacity:i?.65:1},children:t})}function qs({children:t,title:n,t:o,onClick:s}){return e.jsx("button",{"aria-label":n,title:n,onClick:s,style:fe(o),children:t})}function Xe({children:t,t:n}){return e.jsx("span",{style:{marginLeft:5,border:`1px solid ${n.accent}55`,color:n.accent,background:`${n.accent}10`,borderRadius:999,padding:"3px 7px",fontSize:9,fontWeight:750},children:t})}function Ls({children:t,t:n}){return e.jsx("div",{style:{padding:"15px 12px 8px",color:n.textMuted,fontSize:10,fontWeight:750,textTransform:"uppercase",letterSpacing:".07em"},children:t})}function Ie({children:t}){return e.jsx("div",{style:{height:"100%",overflow:"auto",padding:20},children:t})}function Me({title:t,detail:n,t:o,action:s}){return e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:20,alignItems:"start",marginBottom:18},children:[e.jsxs("div",{children:[e.jsx("h2",{style:{margin:0,fontSize:16},children:t}),e.jsx("p",{style:{margin:"5px 0 0",color:o.textSecondary,fontSize:11},children:n})]}),s]})}function Ce({title:t,detail:n,t:o}){return e.jsxs("div",{style:{border:`1px dashed ${o.headerBorder}`,borderRadius:10,padding:30,textAlign:"center"},children:[e.jsx("strong",{children:t}),e.jsx("p",{style:{color:o.textSecondary,fontSize:12},children:n})]})}function nn({children:t}){return e.jsx("div",{style:{padding:"4px 14px 20px"},children:t})}function _s({title:t,subtitle:n,t:o}){return e.jsxs("div",{style:{marginBottom:14},children:[e.jsx("h2",{style:{margin:0,fontSize:16},children:t}),e.jsx("div",{style:{color:o.textMuted,fontSize:11,marginTop:4},children:n})]})}function pe({label:t,value:n,t:o}){return e.jsxs("div",{style:{padding:"9px 0",borderBottom:`1px solid ${o.headerBorder}`},children:[e.jsx("div",{style:{color:o.textMuted,fontSize:9,textTransform:"uppercase",letterSpacing:".05em"},children:t}),e.jsx("div",{style:{fontSize:11,marginTop:4,overflowWrap:"anywhere"},children:n})]})}function Rt({status:t,t:n}){const o=t==="certified"?"#2e9b63":t==="deprecated"?n.textMuted:t==="review"?"#377cc8":"#9a6b2f";return e.jsx("span",{style:{color:o,background:`${o}15`,borderRadius:999,padding:"3px 7px",fontSize:10},children:t})}function ce({text:t,t:n}){return e.jsx("div",{style:{borderLeft:`3px solid ${n.accent}`,background:`${n.accent}0d`,padding:"9px 10px",color:n.textSecondary,fontSize:11,lineHeight:1.5},children:t})}function _({children:t}){return e.jsx("th",{style:{textAlign:"left",padding:"9px 10px",fontSize:9,textTransform:"uppercase",letterSpacing:".05em",opacity:.65},children:t})}function F({children:t}){return e.jsx("td",{style:{padding:"11px 10px",borderTop:"1px solid var(--border-subtle)",fontSize:11},children:t})}function J(t){return t.split(",").map(n=>n.trim()).filter(Boolean)}function Fs(t){return J(t).map(n=>{const[o,s]=n.split("=").map(i=>i.trim());if(!o||!s)throw new Error(`Invalid join key pair "${n}". Use from_key=to_key.`);return{from:o,to:s}})}function Ws(){try{return JSON.parse(localStorage.getItem("dql-modeling-preferences")??"{}")}catch{return{}}}const ie={display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},Vt=(t,n=!1)=>({display:"inline-flex",alignItems:"center",gap:5,flex:"0 0 auto",border:`1px solid ${n?t.accent:t.headerBorder}`,borderRadius:6,background:n?"var(--accent-dim)":t.appBg,color:n?t.accent:t.textSecondary,padding:"5px 8px",fontSize:10.5,fontWeight:650,cursor:"pointer",whiteSpace:"nowrap"}),ht={width:"100%",borderCollapse:"collapse"},Hs=t=>({whiteSpace:"pre-wrap",maxHeight:300,overflow:"auto",padding:12,borderRadius:7,background:t.activityBarBg,color:t.textSecondary,fontSize:10,lineHeight:1.5}),ge=t=>({width:"100%",boxSizing:"border-box",border:`1px solid ${t.headerBorder}`,background:t.cellBg,color:t.textPrimary,borderRadius:6,padding:"8px 9px",fontSize:11}),fe=t=>({border:`1px solid ${t.headerBorder}`,background:t.appBg,color:t.textSecondary,borderRadius:6,padding:7,display:"grid",placeItems:"center",cursor:"pointer"}),Us=(t,n,o)=>({width:"100%",minHeight:30,padding:o?"6px 8px 6px 14px":"7px 8px",display:"flex",alignItems:"center",gap:7,border:0,borderRadius:6,background:n?`${t.accent}18`:"transparent",color:n?t.accent:t.textSecondary,fontSize:10.5,fontWeight:n?700:500,textAlign:"left",cursor:"pointer"}),Fe=t=>({border:0,background:"transparent",color:t.accent,fontSize:10,fontWeight:650,cursor:"pointer"}),to=t=>({margin:"18px 0 7px",paddingBottom:7,borderBottom:`1px solid ${t.headerBorder}`,fontSize:11,textTransform:"uppercase",letterSpacing:".05em",color:t.textMuted}),Qt=t=>({margin:"22px 0 10px",paddingBottom:8,borderBottom:`1px solid ${t.headerBorder}`,fontSize:12,color:t.textPrimary}),xt=t=>({border:`1px solid ${t.headerBorder}`,background:t.cellBg,borderRadius:9,padding:14}),Ks=t=>({display:"flex",alignItems:"center",gap:9,minHeight:58,border:`1px solid ${t.headerBorder}`,background:t.cellBg,borderRadius:8,padding:"9px 10px",color:t.textPrimary,cursor:"pointer",fontFamily:t.font});export{ai as DbtFirstModelingPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{u as A,t as h,r as g,j as n,a as x}from"./index-1mIC_XX4.js";import{U as b}from"./UnifiedAgentRunPanel-Dj4AXAhT.js";import{A as I,a as w,b as E}from"./AiSidePanel-DjB8PWHG.js";import{u as _}from"./usePersistedAgentThreadId-3rzkZrqc.js";import"./react-CRB3T2We.js";import"./AgentAnswerCard-Cp0eh6zU.js";import"./TrustBadge-vQQh8d0D.js";import"./AiBuildResult-CyqTuQe5.js";import"./user-round-BA074kiQ.js";import"./triangle-alert-2ZXx8wAu.js";import"./rotate-ccw-DOrfTZk8.js";import"./x-CSo1M3tu.js";import"./pencil-D_I14Wyk.js";import"./list-tree-BRFpEmvV.js";import"./wrench-Ong23-wu.js";import"./minimize-2-CDwSCGlO.js";import"./maximize-2-CCd5uRIZ.js";import"./arrow-right-DvB_DONr.js";import"./chevron-up-HxU1l85K.js";function Q(){const{state:o,dispatch:i}=A(),p=h[o.themeMode],{audience:r,context:e}=o.globalAi,l=e.selectedObject,s=_("global-rail"),[a,d]=g.useState(!1),m=(t,c)=>{i({type:"OPEN_APP",appId:t,dashboardId:c,experience:"view",section:"dashboards"}),i({type:"CLOSE_GLOBAL_AI"}),x.listApps().then(u=>i({type:"SET_APPS",apps:u})).catch(()=>{})};return n.jsx(I,{t:p,title:e.title??"AI copilot",subtitle:e.scopeHint??"Ask a follow-up about what you are viewing",expanded:a,onToggleExpanded:()=>d(t=>!t),resizable:!0,minResizeWidth:360,maxResizeWidth:1200,onClose:()=>i({type:"CLOSE_GLOBAL_AI"}),ariaLabel:"App AI",style:{position:"relative",width:a?`min(${w}px, calc(100vw - 96px))`:`min(${E}px, calc(100vw - 64px))`,maxWidth:a?"62vw":"46vw",minWidth:320,flex:"0 0 auto"},children:n.jsx(b,{themeMode:o.themeMode,title:e.title??"AI copilot",scopeHint:e.scopeHint??"Ask a follow-up about what you are viewing",audience:r,selectedObject:l,workspaceContext:e.workspaceContext,examplePrompts:Array.isArray(e.suggestedQuestions)&&e.suggestedQuestions.length>0?e.suggestedQuestions.filter(t=>typeof t=="string").slice(0,4).map(t=>({label:t,prompt:t})):void 0,autoRun:o.globalAi.autoRun?{text:o.globalAi.autoRun.text,mode:o.globalAi.autoRun.mode,nonce:o.globalAi.autoRun.nonce}:void 0,threadId:s.threadId,onThreadIdChange:s.onThreadIdChange,initialMode:"auto",onOpenApp:m})})}export{Q as GlobalAiRail};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import{c as Ve,u as fe,t as we,r as d,a as D,j as e,a4 as se,a0 as ye,L as _,S as ne,P as J,B as Ye,d as Oe,T as ie,$ as We,a5 as Je,Q as de,N as Ie,l as Xe,aU as Le,f as Ze}from"./index-1mIC_XX4.js";import{T as Ne}from"./triangle-alert-2ZXx8wAu.js";import{U as Te,G as re}from"./user-round-BA074kiQ.js";import{C as He}from"./chevron-up-HxU1l85K.js";import{P as _e}from"./pencil-D_I14Wyk.js";import{X as me}from"./x-CSo1M3tu.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 et=[["path",{d:"M13.172 2a2 2 0 0 1 1.414.586l6.71 6.71a2.4 2.4 0 0 1 0 3.408l-4.592 4.592a2.4 2.4 0 0 1-3.408 0l-6.71-6.71A2 2 0 0 1 6 9.172V3a1 1 0 0 1 1-1z",key:"16rjxf"}],["path",{d:"M2 7v6.172a2 2 0 0 0 .586 1.414l6.71 6.71a2.4 2.4 0 0 0 3.191.193",key:"178nd4"}],["circle",{cx:"10.5",cy:"6.5",r:".5",fill:"currentColor",key:"12ikhr"}]],tt=Ve("tags",et),le="dql-context-bootstrap-session",ae="dql-context-bootstrap-selection";function nt(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").slice(0,64)}function $e(t){return t.toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,64)}function it(){return{id:"",name:"",owner:"",boundedContext:"",sourceSystems:[],description:""}}function st({embedded:t=!1}={}){const{state:n,dispatch:r}=fe(),i=we[n.themeMode],[l,a]=d.useState([]),[o,s]=d.useState(!0),[x,S]=d.useState(null),[v,c]=d.useState(null),[I,b]=d.useState(null),[h,u]=d.useState(!1),[R,T]=d.useState(null),[j,M]=d.useState(null),[y,k]=d.useState(!1),[E,L]=d.useState(!1),[O,A]=d.useState(null),[m,p]=d.useState([]),B=d.useCallback(()=>{let g=!1;return s(!0),S(null),D.getDomains().then(C=>{if(g)return;const W=Array.isArray(C==null?void 0:C.domains)?C.domains:[];a(W),r({type:"SET_AUTHORED_DOMAINS",domains:W})}).catch(C=>{g||(a([]),S(C instanceof Error&&C.message?C.message:"Could not load domains. Is the local DQL server running?"))}).finally(()=>{g||s(!1)}),()=>{g=!0}},[r]);d.useEffect(()=>B(),[B]),d.useEffect(()=>{const g=window.sessionStorage.getItem(le);let C=!1;const W=$=>{if($&&!C){M($);try{const f=JSON.parse(window.sessionStorage.getItem(ae)??"[]");p(Array.isArray(f)?f.filter(w=>typeof w=="string"):$.candidates.filter(w=>w.action!=="unchanged").map(w=>w.id))}catch{p($.candidates.filter(f=>f.action!=="unchanged").map(f=>f.id))}}};return(g?D.getContextBootstrap(g):D.getLatestContextBootstrap()).then(W).catch(async()=>{window.sessionStorage.removeItem(le),window.sessionStorage.removeItem(ae),g&&W(await D.getLatestContextBootstrap().catch(()=>null))}),()=>{C=!0}},[]),d.useEffect(()=>{j&&(window.sessionStorage.setItem(le,j.id),window.sessionStorage.setItem(ae,JSON.stringify(m)))},[j==null?void 0:j.id,m]);const N=d.useMemo(()=>[...l].sort((g,C)=>g.name.localeCompare(C.name)),[l]),z=d.useCallback(g=>{a(C=>{const W=C.findIndex($=>$.id===g.id),P=W===-1?[...C,g]:[...C];return W!==-1&&(P[W]=g),r({type:"SET_AUTHORED_DOMAINS",domains:P}),P}),c(null)},[r]),Z=d.useCallback(async()=>{if(I){u(!0),T(null);try{await D.deleteDomain(I.id),a(g=>{const C=g.filter(W=>W.id!==I.id);return r({type:"SET_AUTHORED_DOMAINS",domains:C}),C}),b(null)}catch(g){T(g instanceof Error&&g.message?g.message:"Could not delete this domain.")}finally{u(!1)}}},[r,I]),G=d.useCallback(async()=>{k(!0),A(null);try{const g=await D.startContextBootstrap({ai:!0});M(g);const C=g.candidates.filter(W=>W.action!=="unchanged").map(W=>W.id);p(C),window.sessionStorage.setItem(le,g.id),window.sessionStorage.setItem(ae,JSON.stringify(C))}catch(g){A(g instanceof Error?g.message:"Could not draft repository context.")}finally{k(!1)}},[]);d.useEffect(()=>{if(!t)return;const g=()=>{G()};return window.addEventListener("dql:context-build",g),()=>window.removeEventListener("dql:context-build",g)},[t,G]),d.useEffect(()=>{if(!j||["ready","needs_attention"].includes(j.status))return;let g=!1;const C=async()=>{try{const P=await D.getContextBootstrap(j.id);g||M(P)}catch(P){g||A(P instanceof Error?P.message:"Could not update AI draft progress.")}};C();const W=window.setInterval(()=>void C(),750);return()=>{g=!0,window.clearInterval(W)}},[j==null?void 0:j.id,j==null?void 0:j.status]);const F=d.useCallback(async()=>{if(!(!j||m.length===0)){L(!0),A(null);try{await D.saveContextBootstrapSelected(j.id,m),M(null),p([]),window.sessionStorage.removeItem(le),window.sessionStorage.removeItem(ae),B()}catch(g){A(g instanceof Error?g.message:"Could not save selected drafts.")}finally{L(!1)}}},[j,m,B]);return e.jsxs("div",{style:{flex:1,minWidth:0,overflow:"auto",background:i.appBg},children:[e.jsxs("div",{style:{maxWidth:980,margin:"0 auto",padding:"22px 28px 40px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-end",justifyContent:"space-between",gap:18,marginBottom:18},children:[e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9},children:[e.jsx(se,{size:20,strokeWidth:1.9,color:i.accent}),e.jsx("div",{style:{fontSize:22,fontWeight:700,color:i.textPrimary},children:"Domains"})]}),e.jsx("div",{style:{fontSize:13,color:i.textMuted,marginTop:6,maxWidth:680,lineHeight:1.5},children:"Domains are the top of your business model — each one owns the terms, skills, and blocks beneath it. Name the business area, who owns it, the bounded context, and the source systems it draws from."})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0},children:[e.jsxs("button",{type:"button",onClick:()=>B(),title:"Refresh",style:X(i),children:[e.jsx(ye,{size:13,strokeWidth:2})," Refresh"]}),e.jsxs("button",{type:"button",onClick:()=>void G(),disabled:y,style:X(i),children:[y?e.jsx(_,{size:13,strokeWidth:2}):e.jsx(ne,{size:13,strokeWidth:2})," Draft with AI"]}),e.jsxs("button",{type:"button",onClick:()=>c({kind:"create"}),style:ue(i),children:[e.jsx(J,{size:14,strokeWidth:2.2})," Add domain"]})]})]}),o?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:i.textMuted,fontSize:13,padding:"40px 0"},children:[e.jsx(_,{size:15,strokeWidth:2})," Loading domains…"]}):x?e.jsx(at,{t:i,message:x,onRetry:()=>B()}):N.length===0?e.jsx(lt,{t:i,onAdd:()=>c({kind:"create"})}):e.jsx("div",{style:{display:"grid",gap:10},children:N.map(g=>e.jsx(rt,{domain:g,t:i,onEdit:()=>c({kind:"edit",domain:g}),onDelete:()=>{T(null),b(g)}},g.id))}),O?e.jsx("div",{style:{marginTop:12},children:e.jsx(pe,{t:i,tone:"error",children:O})}):null,j?e.jsxs("section",{style:{marginTop:18,border:`1px solid ${i.cellBorder}`,borderRadius:10,background:i.cellBg,padding:14},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:12,alignItems:"center",flexWrap:"wrap"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:13,fontWeight:750,color:i.textPrimary},children:"Repository-guided AI draft"}),e.jsx("div",{style:{fontSize:12,color:i.textMuted,marginTop:3},children:"Inventory is deterministic; AI may enrich only grounded prose and guidance. Nothing is written to Git until you save."})]}),e.jsxs("button",{type:"button",disabled:E||m.length===0||!["ready","needs_attention"].includes(j.status),onClick:()=>void F(),style:{...ue(i),opacity:E||m.length===0||!["ready","needs_attention"].includes(j.status)?.55:1},children:[E?e.jsx(_,{size:13,strokeWidth:2}):e.jsx(J,{size:13,strokeWidth:2})," Save selected drafts"]})]}),e.jsx(dt,{t:i,session:j}),e.jsx("div",{style:{display:"grid",gap:9,marginTop:12},children:j.candidates.map(g=>{const C=g.action!=="unchanged",W=m.includes(g.id);return e.jsx(ct,{candidate:g,selected:W,selectable:C,disabled:E,t:i,onToggle:()=>p(P=>W?P.filter($=>$!==g.id):[...P,g.id])},g.id)})})]}):null]}),v?e.jsx(ot,{mode:v,existingIds:l.map(g=>g.id),domains:l,t:i,onClose:()=>c(null),onSaved:z}):null,I?e.jsx(pt,{domain:I,t:i,deleting:h,error:R,onCancel:()=>{h||b(null)},onConfirm:Z}):null]})}function rt({domain:t,t:n,onEdit:r,onDelete:i}){const l=t.sourceSystems??[],[a,o]=d.useState(!1);return e.jsxs("section",{style:{border:`1px solid ${n.cellBorder}`,borderRadius:10,background:n.cellBg,padding:"13px 15px",display:"flex",alignItems:"flex-start",gap:14},children:[e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:13.5,fontWeight:750,color:n.textPrimary},children:t.name}),t.parent?e.jsxs("span",{style:Se(n),children:["↳ ",t.parent]}):null,t.owner?e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,color:n.textMuted},children:[e.jsx(Te,{size:11,strokeWidth:2})," ",t.owner]}):null,t.businessOwner?e.jsxs("span",{style:Se(n),children:[e.jsx(Te,{size:10,strokeWidth:2.2})," Business owner: ",t.businessOwner]}):null]}),t.description?e.jsx("div",{style:{fontSize:12.5,color:n.textSecondary,marginTop:5,lineHeight:1.5},children:t.description}):e.jsx("div",{style:{fontSize:12,color:n.textMuted,marginTop:5,fontStyle:"italic"},children:"No description yet."}),l.length>0?e.jsx("div",{style:{display:"flex",gap:5,marginTop:9,flexWrap:"wrap"},children:l.map(s=>e.jsx("span",{style:Ce(n),children:s},s))}):null,e.jsxs("div",{style:{display:"flex",gap:7,marginTop:9,flexWrap:"wrap"},children:[e.jsx(je,{t:n,icon:e.jsx(Ye,{size:11,strokeWidth:2}),label:"blocks",count:t.blockCount??0}),e.jsx(je,{t:n,icon:e.jsx(re,{size:11,strokeWidth:2}),label:"skills",count:t.skillCount??0}),e.jsx(je,{t:n,icon:e.jsx(tt,{size:11,strokeWidth:2}),label:"terms",count:t.termCount??0})]}),a?e.jsxs("div",{style:{display:"grid",gap:9,marginTop:12,paddingTop:11,borderTop:`1px solid ${n.btnBorder}`},children:[t.boundedContext?e.jsx(De,{t:n,label:"Business boundary",children:t.boundedContext}):null,t.businessOutcome?e.jsx(De,{t:n,label:"Decision outcome",children:t.businessOutcome}):null,e.jsx(ce,{t:n,label:"In scope",values:t.inScope,empty:"Not defined yet"}),e.jsx(ce,{t:n,label:"Out of scope",values:t.outOfScope,empty:"Not defined yet"}),e.jsx(ce,{t:n,label:"Primary terms",values:t.primaryTerms,empty:"No terms linked yet"}),e.jsx(ce,{t:n,label:"Tags",values:t.tags,empty:"No tags"})]}):null]}),e.jsxs("div",{style:{display:"flex",gap:6,flexShrink:0},children:[e.jsxs("button",{type:"button",onClick:()=>o(s=>!s),style:{...X(n),padding:"5px 7px",fontSize:11.5},title:a?"Hide domain details":"Show domain details",children:[a?e.jsx(He,{size:13}):e.jsx(Oe,{size:13}),a?"Less":"Details"]}),e.jsx("button",{type:"button",onClick:r,style:ke(n),title:"Edit domain",children:e.jsx(_e,{size:13,strokeWidth:2})}),e.jsx("button",{type:"button",onClick:i,style:ke(n),title:"Delete domain",children:e.jsx(ie,{size:13,strokeWidth:2})})]})]})}function ot({mode:t,existingIds:n,domains:r,t:i,onClose:l,onSaved:a}){const o=t.kind==="edit",[s,x]=d.useState(()=>t.kind==="edit"?{...t.domain}:it()),[S,v]=d.useState(o),[c,I]=d.useState(!1),[b,h]=d.useState(null),u=d.useCallback((y,k)=>{x(E=>({...E,[y]:k}))},[]),R=y=>{x(k=>({...k,name:y,...!o&&!S?{id:$e(y)}:{}}))},T=!o&&s.id.length>0&&n.includes(s.id),j=s.id.trim().length>0&&s.name.trim().length>0&&!T&&!c,M=d.useCallback(async()=>{var k,E,L,O,A;const y={...s,id:s.id.trim(),name:s.name.trim(),owner:(k=s.owner)!=null&&k.trim()?s.owner.trim():void 0,businessOwner:(E=s.businessOwner)!=null&&E.trim()?s.businessOwner.trim():void 0,parent:(L=s.parent)!=null&&L.trim()?s.parent.trim():void 0,boundedContext:(O=s.boundedContext)!=null&&O.trim()?s.boundedContext.trim():void 0,description:(A=s.description)!=null&&A.trim()?s.description.trim():void 0,sourceSystems:(s.sourceSystems??[]).map(m=>m.trim()).filter(Boolean),primaryTerms:(s.primaryTerms??[]).map(m=>m.trim()).filter(Boolean),tags:(s.tags??[]).map(m=>m.trim()).filter(Boolean),inScope:(s.inScope??[]).map(m=>m.trim()).filter(Boolean),outOfScope:(s.outOfScope??[]).map(m=>m.trim()).filter(Boolean),dbtGroups:(s.dbtGroups??[]).map(m=>m.trim()).filter(Boolean),dbtPaths:(s.dbtPaths??[]).map(m=>m.trim()).filter(Boolean),dbtTags:(s.dbtTags??[]).map(m=>m.trim()).filter(Boolean),semanticDomains:(s.semanticDomains??[]).map(m=>m.trim()).filter(Boolean),semanticTags:(s.semanticTags??[]).map(m=>m.trim()).filter(Boolean)};I(!0),h(null);try{const m=o?await D.updateDomain(y.id,y):await D.createDomain(y);a(m.domain??y)}catch(m){h(m instanceof Error&&m.message?m.message:"Could not save this domain. Try again.")}finally{I(!1)}},[s,o,a]);return e.jsx("div",{style:ft,onClick:()=>!c&&l(),children:e.jsxs("div",{style:yt(i),onClick:y=>y.stopPropagation(),children:[e.jsxs("div",{style:mt(i),children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(se,{size:16,strokeWidth:2,color:i.accent}),e.jsx("div",{style:{fontSize:15,fontWeight:700,color:i.textPrimary},children:o?"Edit domain":"New domain"})]}),e.jsx("button",{type:"button",onClick:()=>!c&&l(),style:ke(i),title:"Close",children:e.jsx(me,{size:15,strokeWidth:2})})]}),e.jsxs("div",{style:{flex:1,minHeight:0,overflow:"auto",padding:"16px 18px",display:"grid",gap:16},children:[e.jsx(K,{label:"Name",t:i,hint:o?void 0:"A short, human label for this business area.",children:e.jsx("input",{type:"text",value:s.name,onChange:y=>R(y.target.value),placeholder:"Revenue",style:Q(i)})}),e.jsxs(K,{label:"ID (slug)",t:i,hint:"Used as the on-disk identifier. Letters, numbers, and dashes.",children:[e.jsx("input",{type:"text",value:s.id,disabled:o,onChange:y=>{v(!0),u("id",nt(y.target.value))},onBlur:()=>u("id",$e(s.id)),placeholder:"revenue",style:{...Q(i),fontFamily:i.fontMono,opacity:o?.7:1}}),T?e.jsx(pe,{t:i,tone:"error",children:"A domain with this id already exists."}):null]}),e.jsx(K,{label:"Parent domain",t:i,hint:"Optional. Depth becomes Domain, Subdomain, Microdomain, and beyond.",children:e.jsxs("select",{value:s.parent??"",onChange:y=>u("parent",y.target.value||void 0),style:Q(i),children:[e.jsx("option",{value:"",children:"Top-level domain"}),r.filter(y=>y.id!==s.id).map(y=>e.jsx("option",{value:y.id,children:y.name},y.id))]})}),e.jsx(K,{label:"Owner",t:i,hint:"The team or person accountable for this domain.",children:e.jsx("input",{type:"text",value:s.owner??"",onChange:y=>u("owner",y.target.value),placeholder:"finance-analytics",style:Q(i)})}),e.jsx(K,{label:"Business owner",t:i,hint:"The stakeholder accountable for business use and definitions.",children:e.jsx("input",{type:"text",value:s.businessOwner??"",onChange:y=>u("businessOwner",y.target.value),placeholder:"Revenue Operations",style:Q(i)})}),e.jsx(K,{label:"Bounded context",t:i,hint:"The conceptual boundary this domain owns, e.g. 'recognized revenue and invoicing'.",children:e.jsx("input",{type:"text",value:s.boundedContext??"",onChange:y=>u("boundedContext",y.target.value),placeholder:"Recognized revenue and invoicing",style:Q(i)})}),e.jsx(K,{label:"Source systems",t:i,hint:"The upstream systems this domain draws from — type a name and press Enter.",children:e.jsx(be,{t:i,values:s.sourceSystems??[],onChange:y=>u("sourceSystems",y),placeholder:"Add a source system…"})}),e.jsx(K,{label:"Primary terms",t:i,hint:"Business concepts the agent should use to recognize this domain.",children:e.jsx(be,{t:i,values:s.primaryTerms??[],onChange:y=>u("primaryTerms",y),placeholder:"Add a term…"})}),e.jsx(K,{label:"Scope tags",t:i,hint:"Short labels used for routing and discovery.",children:e.jsx(be,{t:i,values:s.tags??[],onChange:y=>u("tags",y),placeholder:"Add a tag…"})}),e.jsx(K,{label:"Description",t:i,hint:"What this domain covers and how it's used.",children:e.jsx("textarea",{value:s.description??"",onChange:y=>u("description",y.target.value),rows:5,placeholder:"All recognized-revenue metrics and the blocks that report them, sourced from the billing warehouse.",style:xt(i)})}),b?e.jsx(pe,{t:i,tone:"error",children:b}):null]}),e.jsxs("div",{style:bt(i),children:[e.jsx("button",{type:"button",onClick:()=>!c&&l(),style:X(i),children:"Cancel"}),e.jsxs("button",{type:"button",onClick:M,disabled:!j,style:{...ue(i),opacity:j?1:.55},children:[c?e.jsx(_,{size:13,strokeWidth:2}):null,c?"Saving…":o?"Save changes":"Create domain"]})]})]})})}function be({t,values:n,onChange:r,placeholder:i}){const[l,a]=d.useState(""),o=s=>{const x=s.trim();!x||n.includes(x)||(r([...n,x]),a(""))};return e.jsxs("div",{style:{display:"grid",gap:7},children:[n.length>0?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:n.map(s=>e.jsxs("span",{style:gt(t),children:[s,e.jsx("button",{type:"button",onClick:()=>r(n.filter(x=>x!==s)),style:ht(t),title:"Remove",children:e.jsx(me,{size:11,strokeWidth:2.4})})]},s))}):null,e.jsx("input",{type:"text",value:l,onChange:s=>a(s.target.value),onKeyDown:s=>{s.key==="Enter"&&(s.preventDefault(),o(l))},placeholder:i,style:Q(t)})]})}function lt({t,onAdd:n}){return e.jsxs("div",{style:{border:`1px dashed ${t.cellBorder}`,borderRadius:12,background:t.cellBg,padding:"34px 28px",textAlign:"center",display:"grid",gap:12,justifyItems:"center"},children:[e.jsx("div",{style:{width:44,height:44,borderRadius:10,background:`${t.accent}18`,color:t.accent,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(se,{size:22,strokeWidth:1.9})}),e.jsx("div",{style:{fontSize:15,fontWeight:700,color:t.textPrimary},children:"Name your business domains"}),e.jsx("div",{style:{fontSize:13,color:t.textMuted,maxWidth:460,lineHeight:1.55},children:`Domains organize everything below them — terms, skills, and blocks. Add your first one, like "Revenue" or "Customer", and you'll be able to pick it when authoring blocks and skills.`}),e.jsxs("button",{type:"button",onClick:n,style:{...ue(t),marginTop:4},children:[e.jsx(J,{size:14,strokeWidth:2.2})," Add your first domain"]})]})}function at({t,message:n,onRetry:r}){return e.jsxs("div",{style:{border:`1px solid ${t.warning}55`,borderRadius:10,background:`${t.warning}12`,padding:"16px 18px",display:"flex",alignItems:"flex-start",gap:11},children:[e.jsx(Ne,{size:16,strokeWidth:2,color:t.warning,style:{marginTop:1,flexShrink:0}}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:13,fontWeight:650,color:t.textPrimary},children:"Domains are not available right now"}),e.jsx("div",{style:{fontSize:12.5,color:t.textSecondary,marginTop:4,lineHeight:1.5},children:n}),e.jsxs("button",{type:"button",onClick:r,style:{...X(t),marginTop:10},children:[e.jsx(ye,{size:13,strokeWidth:2})," Retry"]})]})]})}function dt({t,session:n}){var l;const r=!["ready","needs_attention"].includes(n.status),i=n.ai.mode==="evidence_only"?"Evidence-only":n.ai.provider?`${n.ai.provider} grounded`:"Preparing AI";return e.jsxs("div",{style:{marginTop:14,padding:"10px 11px",borderRadius:8,background:t.appBg,border:`1px solid ${t.btnBorder}`},children:[e.jsxs("div",{style:{display:"flex",gap:9,alignItems:"center",flexWrap:"wrap",fontSize:12,color:t.textSecondary},children:[r?e.jsx(_,{size:14,strokeWidth:2,color:t.accent}):e.jsx(ne,{size:14,strokeWidth:2,color:t.accent}),e.jsx("strong",{style:{color:t.textPrimary,textTransform:"capitalize"},children:n.status.replace("_"," ")}),e.jsx("span",{children:i}),e.jsxs("span",{children:[n.progress.domains.ready,"/",n.progress.domains.total," domains"]}),e.jsxs("span",{children:[n.progress.skills.ready,"/",n.progress.skills.total," skills"]})]}),e.jsx("div",{style:{height:5,borderRadius:999,background:t.btnBg,overflow:"hidden",marginTop:9},children:e.jsx("div",{style:{width:`${Math.max(3,Math.min(100,n.progress.percent))}%`,height:"100%",background:t.accent,transition:"width 260ms ease"}})}),e.jsx("div",{style:{marginTop:7,fontSize:11.5,color:t.textMuted,lineHeight:1.45},children:n.progress.message}),(l=n.warnings)!=null&&l.length?e.jsx("div",{style:{marginTop:7,fontSize:11.5,color:t.warning,lineHeight:1.45},children:n.warnings.slice(-2).join(" ")}):null]})}function ct({candidate:t,selected:n,selectable:r,disabled:i,t:l,onToggle:a}){var I,b,h,u,R,T,j,M,y,k,E,L,O,A,m,p,B,N,z,Z,G,F,g,C,W,P;const[o,s]=d.useState(!1),x=t.kind==="domain",S=((I=t.domain)==null?void 0:I.name)??((b=t.skill)==null?void 0:b.id)??t.id.replace(/^(domain|skill):/,""),v=x?((h=t.domain)==null?void 0:h.description)??((u=t.domain)==null?void 0:u.boundedContext):((R=t.skill)==null?void 0:R.description)??((j=(T=t.skill)==null?void 0:T.body)==null?void 0:j.split(`
|
|
7
|
-
`).find(Boolean)),c=x?[["Business outcome",(M=t.domain)==null?void 0:M.businessOutcome],["In scope",(k=(y=t.domain)==null?void 0:y.inScope)==null?void 0:k.join(" · ")],["Out of scope",(L=(E=t.domain)==null?void 0:E.outOfScope)==null?void 0:L.join(" · ")],["Primary terms",(A=(O=t.domain)==null?void 0:O.primaryTerms)==null?void 0:A.join(" · ")]]:[["Applies when",(p=(m=t.skill)==null?void 0:m.triggers)==null?void 0:p.join(" · ")],["Ask first when",(N=(B=t.skill)==null?void 0:B.clarifyWhen)==null?void 0:N.join(" · ")],["Avoid when",(Z=(z=t.skill)==null?void 0:z.exclusions)==null?void 0:Z.join(" · ")],["Preferred metrics",(F=(G=t.skill)==null?void 0:G.preferredMetrics)==null?void 0:F.join(" · ")],["Preferred blocks",(C=(g=t.skill)==null?void 0:g.preferredBlocks)==null?void 0:C.join(" · ")]];return e.jsx("article",{style:{border:`1px solid ${n?`${l.accent}66`:l.btnBorder}`,background:n?`${l.accent}08`:l.appBg,borderRadius:8,padding:"10px 11px",opacity:r?1:.72},children:e.jsxs("div",{style:{display:"flex",gap:9,alignItems:"flex-start"},children:[e.jsx("input",{"aria-label":`Select ${x?"domain":"skill"} ${S}`,type:"checkbox",disabled:!r||i,checked:n,onChange:a,style:{marginTop:3}}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",gap:7,alignItems:"center",flexWrap:"wrap"},children:[e.jsxs("strong",{style:{color:l.textPrimary,fontSize:12.5},children:[x?"Domain":"Skill"," · ",S]}),e.jsx("span",{style:Se(l),children:t.action.replace("_"," ")}),e.jsxs("span",{style:{fontSize:11,color:l.textMuted},children:[Math.round(t.confidence*100),"% evidence confidence"]})]}),v?e.jsx("p",{style:{marginTop:5,color:l.textSecondary,fontSize:12,lineHeight:1.45},children:v}):e.jsx("p",{style:{marginTop:5,color:l.textMuted,fontSize:12,fontStyle:"italic"},children:"Waiting for grounded guidance…"}),e.jsx("div",{style:{display:"flex",gap:5,marginTop:7,flexWrap:"wrap"},children:t.evidence.map($=>e.jsx("span",{style:Ce(l),children:$},$))}),o?e.jsxs("div",{style:{marginTop:9,display:"grid",gap:6,borderTop:`1px solid ${l.btnBorder}`,paddingTop:9},children:[c.filter(([,$])=>!!$).map(([$,f])=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"116px minmax(0, 1fr)",gap:8,fontSize:11.5,lineHeight:1.45},children:[e.jsx("strong",{style:{color:l.textMuted},children:$}),e.jsx("span",{style:{color:l.textSecondary},children:f})]},$)),!x&&((W=t.skill)!=null&&W.body)?e.jsx("pre",{style:{margin:0,whiteSpace:"pre-wrap",fontFamily:l.font,fontSize:11.5,color:l.textSecondary,background:l.cellBg,padding:9,borderRadius:6,maxHeight:180,overflow:"auto"},children:t.skill.body}):null,(P=t.notes)!=null&&P.length?e.jsx("div",{style:{fontSize:11.5,color:l.accent},children:t.notes.join(" ")}):null]}):null]}),e.jsxs("button",{type:"button",onClick:()=>s($=>!$),style:{...X(l),padding:"4px 6px",fontSize:11.5},"aria-expanded":o,children:[o?e.jsx(He,{size:13}):e.jsx(Oe,{size:13}),o?"Less":"Review"]})]})})}function pt({domain:t,t:n,deleting:r,error:i,onCancel:l,onConfirm:a}){return e.jsx("div",{style:jt,onClick:l,children:e.jsxs("div",{style:vt(n),onClick:o=>o.stopPropagation(),children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9},children:[e.jsx(ie,{size:16,strokeWidth:2,color:n.error}),e.jsx("div",{style:{fontSize:15,fontWeight:700,color:n.textPrimary},children:"Delete this domain?"})]}),e.jsxs("div",{style:{fontSize:13,color:n.textSecondary,lineHeight:1.55},children:[e.jsx("span",{style:{fontWeight:700,color:n.textPrimary},children:t.name})," will be removed. Blocks, skills, and terms that referenced it will become unassigned. This can't be undone."]}),i?e.jsx(pe,{t:n,tone:"error",children:i}):null,e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[e.jsx("button",{type:"button",onClick:l,disabled:r,style:X(n),children:"Cancel"}),e.jsxs("button",{type:"button",onClick:a,disabled:r,style:{...ut(n),opacity:r?.6:1},children:[r?e.jsx(_,{size:13,strokeWidth:2}):e.jsx(ie,{size:13,strokeWidth:2}),r?"Deleting…":"Delete"]})]})]})})}function je({t,icon:n,label:r,count:i}){return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11,fontWeight:600,color:i>0?t.textSecondary:t.textMuted,background:t.btnBg,border:`1px solid ${t.btnBorder}`,borderRadius:6,padding:"3px 8px"},children:[n,i," ",r]})}function De({t,label:n,children:r}){return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"118px minmax(0, 1fr)",gap:10,fontSize:12,lineHeight:1.5},children:[e.jsx("strong",{style:{color:t.textMuted},children:n}),e.jsx("span",{style:{color:t.textSecondary},children:r})]})}function ce({t,label:n,values:r,empty:i}){return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"118px minmax(0, 1fr)",gap:10,fontSize:12,lineHeight:1.5},children:[e.jsx("strong",{style:{color:t.textMuted},children:n}),e.jsx("div",{style:{display:"flex",gap:5,flexWrap:"wrap"},children:r!=null&&r.length?r.map(l=>e.jsx("span",{style:Ce(t),children:l},l)):e.jsx("span",{style:{color:t.textMuted,fontStyle:"italic"},children:i})})]})}function K({label:t,hint:n,t:r,children:i}){return e.jsxs("div",{style:{display:"grid",gap:6},children:[e.jsx("label",{style:{fontSize:12,fontWeight:700,color:r.textPrimary},children:t}),n?e.jsx("div",{style:{fontSize:11.5,color:r.textMuted,lineHeight:1.45,marginTop:-2},children:n}):null,i]})}function pe({t,tone:n,children:r}){const i=n==="error"?t.error:t.textMuted;return e.jsx("div",{style:{fontSize:11.5,color:i,lineHeight:1.45},children:r})}function ue(t){return{display:"inline-flex",alignItems:"center",gap:6,padding:"7px 13px",borderRadius:7,border:`1px solid ${t.accent}`,background:t.accent,color:"#ffffff",fontSize:12.5,fontWeight:700,fontFamily:t.font,cursor:"pointer"}}function X(t){return{display:"inline-flex",alignItems:"center",gap:5,padding:"7px 11px",borderRadius:7,border:`1px solid ${t.btnBorder}`,background:t.btnBg,color:t.textSecondary,fontSize:12,fontWeight:600,fontFamily:t.font,cursor:"pointer"}}function ut(t){return{display:"inline-flex",alignItems:"center",gap:6,padding:"7px 13px",borderRadius:7,border:`1px solid ${t.error}`,background:t.error,color:"#ffffff",fontSize:12.5,fontWeight:700,fontFamily:t.font,cursor:"pointer"}}function ke(t){return{display:"inline-flex",alignItems:"center",justifyContent:"center",width:30,height:30,borderRadius:7,border:`1px solid ${t.btnBorder}`,background:t.btnBg,color:t.textSecondary,cursor:"pointer",flexShrink:0}}function Q(t){return{width:"100%",border:`1px solid ${t.btnBorder}`,borderRadius:7,background:t.cellBg,color:t.textPrimary,fontSize:12.5,fontFamily:t.font,padding:"8px 10px",boxSizing:"border-box"}}function xt(t){return{...Q(t),resize:"vertical",lineHeight:1.5,padding:"9px 11px"}}function Se(t){return{display:"inline-flex",alignItems:"center",gap:4,fontSize:10.5,fontWeight:700,color:t.accent,background:`${t.accent}14`,border:`1px solid ${t.accent}38`,borderRadius:999,padding:"2px 8px"}}function Ce(t){return{fontSize:11,fontWeight:600,color:t.textSecondary,background:t.btnBg,border:`1px solid ${t.btnBorder}`,borderRadius:6,padding:"3px 8px",fontFamily:t.fontMono}}function gt(t){return{display:"inline-flex",alignItems:"center",gap:4,fontSize:11.5,fontWeight:600,color:t.textPrimary,background:`${t.accent}14`,border:`1px solid ${t.accent}38`,borderRadius:6,padding:"3px 4px 3px 9px",fontFamily:t.fontMono}}function ht(t){return{display:"inline-flex",alignItems:"center",justifyContent:"center",border:"none",background:"transparent",color:t.textMuted,cursor:"pointer",padding:2,borderRadius:4}}const ft={position:"fixed",inset:0,background:"rgba(0, 0, 0, 0.42)",display:"flex",justifyContent:"flex-end",zIndex:60};function yt(t){return{width:"min(560px, 100%)",height:"100%",background:t.appBg,borderLeft:`1px solid ${t.headerBorder}`,display:"flex",flexDirection:"column",boxShadow:"-8px 0 28px rgba(0,0,0,0.18)"}}function mt(t){return{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 18px",borderBottom:`1px solid ${t.headerBorder}`,flexShrink:0}}function bt(t){return{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:8,padding:"13px 18px",borderTop:`1px solid ${t.headerBorder}`,flexShrink:0}}const jt={position:"fixed",inset:0,background:"rgba(0, 0, 0, 0.42)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:70,padding:20};function vt(t){return{width:"min(420px, 100%)",background:t.cellBg,border:`1px solid ${t.cellBorder}`,borderRadius:12,padding:20,display:"grid",gap:13,boxShadow:"0 18px 48px rgba(0,0,0,0.3)"}}function kt(t,n,r){var a,o;if(n&&t.domain!==n&&!((a=t.domains)!=null&&a.includes(n)))return!1;const i=(o=r==null?void 0:r.split("::").at(-1))==null?void 0:o.toLowerCase();if(!i)return!0;const l=(t.modelAreaRefs??[]).map(s=>{var x;return(x=s.split("::").at(-1))==null?void 0:x.toLowerCase()});return l.length===0||l.includes(i)}function Re(t){return t.replace(/\\/g,"/").replace(/^\.\//,"").replace(/\/+$/,"")}function St(t,n){if(!n)return!0;const r=Re(t.sourcePath);return n.some(i=>{const l=Re(i);return r===l||r.endsWith(`/${l}`)})}function wt(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").slice(0,64)}function Me(t){return t.toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,64)}function Ct(){return{id:"",scope:"project",description:"",body:"",preferredMetrics:[],preferredBlocks:[],vocabulary:{},sourcePath:""}}function zt({embedded:t=!1,domainFilter:n=null,modelAreaFilter:r=null,sourcePathFilter:i}={}){var $;const{state:l}=fe(),a=we[l.themeMode],[o,s]=d.useState([]),[x,S]=d.useState(!0),[v,c]=d.useState(null),[I,b]=d.useState({metrics:[],blocks:[]}),h=l.authoredDomains,[u,R]=d.useState(null),[T,j]=d.useState(!1),[M,y]=d.useState("skills"),[k,E]=d.useState(!1),[L,O]=d.useState(null),[A,m]=d.useState(null),[p,B]=d.useState(null),[N,z]=d.useState(!1),[Z,G]=d.useState(null),F=d.useCallback(()=>{let f=!1;return S(!0),c(null),D.getSkills().then(w=>{f||s(Array.isArray(w==null?void 0:w.skills)?w.skills:[])}).catch(w=>{f||(s([]),c(w instanceof Error&&w.message?w.message:"Could not load skills. Is the local DQL server running?"))}).finally(()=>{f||S(!1)}),D.getSkillOptions().then(w=>{f||b({metrics:Array.isArray(w==null?void 0:w.metrics)?w.metrics:[],blocks:Array.isArray(w==null?void 0:w.blocks)?w.blocks:[]})}).catch(()=>{f||b({metrics:[],blocks:[]})}),D.getSkillPathSettings().then(w=>{f||(R(w),y(w.path))}).catch(()=>{f||R(null)}),()=>{f=!0}},[]);d.useEffect(()=>F(),[F]);const g=d.useMemo(()=>o.filter(f=>kt(f,n,r)).filter(f=>St(f,i)).sort((f,w)=>f.id.localeCompare(w.id)),[o,n,r,i]),C=d.useCallback(f=>{s(w=>{const oe=w.findIndex(Be=>(Be.qualifiedId??Be.id)===(f.qualifiedId??f.id));if(oe===-1)return[...w,f];const ze=[...w];return ze[oe]=f,ze}),m(null)},[]),W=d.useCallback(async()=>{if(p){z(!0),G(null);try{const f=p.qualifiedId??p.id;await D.deleteSkill(f),s(w=>w.filter(oe=>(oe.qualifiedId??oe.id)!==f)),B(null)}catch(f){G(f instanceof Error&&f.message?f.message:"Could not delete this skill.")}finally{z(!1)}}},[p]),P=d.useCallback(async()=>{E(!0),O(null);try{const f=await D.updateSkillPath(M);R(f),y(f.path),j(!1),F()}catch(f){O(f instanceof Error&&f.message?f.message:"Could not use this Skills folder.")}finally{E(!1)}},[F,M]);return e.jsxs("div",{style:{flex:1,minWidth:0,overflow:"auto",background:a.appBg},children:[e.jsxs("div",{style:{maxWidth:980,margin:"0 auto",padding:t?"18px 20px 40px":"22px 28px 40px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-end",justifyContent:"space-between",gap:18,marginBottom:18},children:[e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9},children:[e.jsx(re,{size:20,strokeWidth:1.9,color:a.accent}),e.jsx("div",{style:{fontSize:t?18:22,fontWeight:700,color:a.textPrimary},children:r?`${($=r.split("::").at(-1))==null?void 0:$.replace(/_/g," ")} skills`:n?`${n} skills`:i?"Authored domain skills":"Skills"})]}),e.jsxs("div",{style:{fontSize:13,color:a.textMuted,marginTop:6,maxWidth:680,lineHeight:1.5},children:["Definitions, vocabulary, and instructions the AI follows when answering",r?" in this model area":n?" in this domain":i?" from authored domains":"",". Applied only when their triggers match — drafts never guide answers."]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:7,color:a.textMuted,fontSize:10.5,minWidth:0},children:[e.jsx(We,{size:12,strokeWidth:1.8}),e.jsx("span",{children:"Skill folder"}),e.jsx("code",{style:{color:a.textSecondary,fontFamily:a.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(u==null?void 0:u.path)??"skills"}),u?e.jsxs("span",{children:["· ",u.exists?`${u.skillCount} loaded${i?` · ${g.length} shown here`:""}`:"not found"]}):null]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0},children:[e.jsxs("button",{type:"button",onClick:()=>F(),title:"Refresh",style:V(a),children:[e.jsx(ye,{size:13,strokeWidth:2})," Refresh"]}),e.jsxs("button",{type:"button",onClick:()=>{O(null),j(f=>!f)},style:V(a),children:[e.jsx(We,{size:13,strokeWidth:2})," Skill folder"]}),e.jsxs("button",{type:"button",onClick:()=>m({kind:"create"}),style:ge(a),children:[e.jsx(J,{size:14,strokeWidth:2.2})," Add skill"]})]})]}),T?e.jsxs("div",{style:{border:"1px solid var(--border-subtle)",borderRadius:10,background:a.cellBg,padding:"12px 14px",marginBottom:16,display:"grid",gap:8},children:[e.jsx("div",{style:{fontSize:12.5,fontWeight:700,color:a.textPrimary},children:"Use an existing Skills folder"}),e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[e.jsx("input",{"aria-label":"Existing Skills folder",value:M,onChange:f=>y(f.target.value),onKeyDown:f=>{f.key==="Enter"&&M.trim()&&!k&&P()},placeholder:"skills or ../skills",style:{...H(a),flex:1,fontFamily:a.fontMono}}),e.jsx("button",{type:"button",onClick:()=>j(!1),disabled:k,style:V(a),children:"Cancel"}),e.jsxs("button",{type:"button",onClick:()=>void P(),disabled:!M.trim()||k,style:{...ge(a),opacity:M.trim()&&!k?1:.55},children:[k?e.jsx(_,{size:13,strokeWidth:2}):null,k?"Connecting…":"Use folder"]})]}),e.jsxs("div",{style:{fontSize:10.5,lineHeight:1.45,color:a.textMuted},children:["Relative paths start from the DQL project. If DQL is in a ",e.jsx("code",{style:{fontFamily:a.fontMono},children:"/dql"})," folder inside your dbt repo, use ",e.jsx("code",{style:{fontFamily:a.fontMono},children:"../skills"}),". Existing ",e.jsx("code",{style:{fontFamily:a.fontMono},children:".skill.md"})," and Markdown skill files are loaded in place and stay Git-owned by that repo."]}),u!=null&&u.resolvedPath?e.jsxs("div",{style:{fontSize:10.5,color:a.textMuted,fontFamily:a.fontMono,overflowWrap:"anywhere"},children:["Resolved: ",u.resolvedPath]}):null,L?e.jsx(xe,{t:a,tone:"error",children:L}):null]}):null,x?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:a.textMuted,fontSize:13,padding:"40px 0"},children:[e.jsx(_,{size:15,strokeWidth:2})," Loading skills…"]}):v?e.jsx(Dt,{t:a,message:v,onRetry:()=>F()}):g.length===0?e.jsx($t,{t:a,onAdd:()=>m({kind:"create"})}):e.jsx("div",{style:{display:"grid",gap:10},children:g.map(f=>e.jsx(Bt,{skill:f,t:a,onEdit:()=>m({kind:"edit",skill:f}),onDelete:()=>{G(null),B(f)}},f.qualifiedId??f.id))})]}),A?e.jsx(Wt,{mode:A,options:I,domains:h,defaultDomain:n,defaultModelArea:r,existingIds:o.map(f=>f.id),t:a,onClose:()=>m(null),onSaved:C}):null,p?e.jsx(Rt,{skill:p,t:a,deleting:N,error:Z,onCancel:()=>{N||B(null)},onConfirm:W}):null]})}function Bt({skill:t,t:n,onEdit:r,onDelete:i}){var s,x,S;const[l,a]=d.useState(!1),o=(s=t.domains)!=null&&s.length?t.domains:t.domain?[t.domain]:[];return e.jsxs("section",{style:{border:"1px solid var(--border-subtle)",borderRadius:11,background:n.cellBg,overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,padding:"12px 14px"},children:[e.jsx("span",{style:{width:28,height:28,borderRadius:7,background:"var(--accent-dim)",color:n.accent,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(re,{size:14,strokeWidth:1.75})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:13,fontWeight:650,color:n.textPrimary,fontFamily:n.fontMono},children:t.id}),t.status==="draft"?e.jsx("span",{style:Ee(n),children:"draft — inactive"}):null,t.status==="active"||!t.status?e.jsx("span",{style:Mt(n),children:"active"}):null,o.map(v=>e.jsx("span",{style:Pt(n),children:v},v)),t.isStarter?e.jsxs("span",{style:Ee(n),title:"A dbt-seeded starter — edit it to make it yours",children:[e.jsx(ne,{size:10,strokeWidth:2.2})," starter — edit me"]}):null]}),e.jsx("div",{style:{fontSize:12,color:t.description?n.textSecondary:n.textMuted,fontStyle:t.description?void 0:"italic",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.description||"No description yet."}),e.jsx("div",{title:t.sourcePath,style:{marginTop:3,color:n.textMuted,fontSize:10,fontFamily:n.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.sourcePath})]}),e.jsx("button",{type:"button",onClick:()=>a(v=>!v),style:{...V(n),height:26,padding:"0 10px",fontSize:11},title:l?"Hide skill details":"Show skill details",children:l?"Hide details":"Details"}),e.jsx("button",{type:"button",onClick:r,style:{...he(n),width:26,height:26},title:"Edit skill",children:e.jsx(_e,{size:12,strokeWidth:1.75})}),e.jsx("button",{type:"button",onClick:i,style:{...he(n),width:26,height:26},title:"Delete skill",children:e.jsx(ie,{size:12,strokeWidth:1.75})})]}),l?e.jsxs("div",{style:{borderTop:"1px solid var(--border-subtle)",padding:"12px 14px",display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px 20px"},children:[e.jsx(ee,{t:n,label:"Apply when",values:t.triggers,empty:"No trigger phrases defined"}),e.jsx(ee,{t:n,label:"Prefer these metrics",values:t.preferredMetrics,empty:"No preferred metrics",accent:!0,mono:!0}),e.jsx(ee,{t:n,label:"Reuse these blocks",values:t.preferredBlocks,empty:"No preferred blocks",accent:!0,mono:!0}),e.jsx(ee,{t:n,label:"Ask first when",values:t.clarifyWhen,empty:"No clarification rule defined"}),(x=t.exclusions)!=null&&x.length?e.jsx(ee,{t:n,label:"Avoid when",values:t.exclusions,empty:""}):null,(S=t.modelAreaRefs)!=null&&S.length?e.jsx(ee,{t:n,label:"Focus on model areas",values:t.modelAreaRefs,empty:"",mono:!0}):null,t.body?e.jsxs("div",{style:{gridColumn:"1 / -1"},children:[e.jsx("div",{style:te(n),children:"Guidance"}),e.jsx("div",{style:{fontSize:12,lineHeight:1.6,color:n.textSecondary,background:"var(--bg-1)",border:"1px solid var(--border-subtle)",borderRadius:8,padding:"10px 12px",whiteSpace:"pre-wrap",maxHeight:220,overflow:"auto"},children:t.body})]}):null]}):null]})}function Wt({mode:t,options:n,domains:r,defaultDomain:i=null,defaultModelArea:l=null,existingIds:a,t:o,onClose:s,onSaved:x}){const{dispatch:S}=fe(),v=t.kind==="edit",[c,I]=d.useState(()=>t.kind==="edit"?{...t.skill}:{...Ct(),domain:i??void 0,domains:i?[i]:[],modelAreaRefs:l?[l]:[]}),[b,h]=d.useState(v),[u,R]=d.useState(()=>t.kind==="edit"?t.skill.id:""),[T,j]=d.useState(!1),[M,y]=d.useState(null),k=d.useCallback((p,B)=>{I(N=>({...N,[p]:B}))},[]),E=p=>{R(p),!v&&!b&&k("id",Me(p))},L=!v&&c.id.length>0&&a.includes(c.id),O=c.id.trim().length>0&&c.body.trim().length>0&&!L&&!T,A=Je(c.domain,r),m=d.useCallback(async()=>{var B,N;const p={...c,id:c.id.trim(),description:(B=c.description)!=null&&B.trim()?c.description.trim():void 0,body:c.body,domain:(N=c.domain)!=null&&N.trim()?c.domain.trim():void 0,domains:(c.domains??(c.domain?[c.domain]:[])).map(z=>z.trim()).filter(Boolean),modelAreaRefs:(c.modelAreaRefs??[]).map(z=>z.trim()).filter(Boolean),triggers:(c.triggers??[]).map(z=>z.trim()).filter(Boolean),exclusions:(c.exclusions??[]).map(z=>z.trim()).filter(Boolean),preferredDimensions:(c.preferredDimensions??[]).map(z=>z.trim()).filter(Boolean),requiredFilters:(c.requiredFilters??[]).map(z=>z.trim()).filter(Boolean),clarifyWhen:(c.clarifyWhen??[]).map(z=>z.trim()).filter(Boolean),examples:(c.examples??[]).map(z=>z.trim()).filter(Boolean)};j(!0),y(null);try{const z=v?await D.updateSkill(p.id,p):await D.createSkill(p);x(z.skill??p)}catch(z){y(z instanceof Error&&z.message?z.message:"Could not save this skill. Try again.")}finally{j(!1)}},[c,v,x]);return e.jsx("div",{style:Lt,onClick:()=>!T&&s(),children:e.jsxs("div",{style:Nt(o),onClick:p=>p.stopPropagation(),children:[e.jsxs("div",{style:Ht(),children:[e.jsx("span",{style:{width:30,height:30,borderRadius:8,background:"var(--accent-dim)",color:o.accent,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(re,{size:15,strokeWidth:1.75})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:14,fontWeight:700,color:o.textPrimary},children:v?"Edit skill":"New skill"}),e.jsx("div",{style:{fontSize:11,color:o.textMuted,marginTop:1},children:"Git-backed guidance · applied only when triggers match"})]}),e.jsx("button",{type:"button",onClick:()=>!T&&s(),style:{...he(o),width:26,height:26,border:"none",background:"none"},title:"Close",children:e.jsx(me,{size:14,strokeWidth:2})})]}),e.jsxs("div",{style:{flex:1,minHeight:0,overflow:"auto",padding:"18px 22px",display:"grid",gridTemplateColumns:"1fr 1fr",gap:"20px 28px",alignContent:"start"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[e.jsx("div",{style:te(o),children:"Identity"}),e.jsxs("label",{style:U,children:[e.jsx("span",{style:q(o),children:"Name"}),e.jsx("input",{type:"text",value:u,onChange:p=>E(p.target.value),placeholder:"e.g. Revenue definition",style:H(o)}),e.jsxs("span",{style:{fontSize:10.5,color:o.textMuted},children:["Saved as"," ",e.jsx("input",{type:"text",value:`skills/${c.id}.skill.md`,disabled:v,onChange:p=>{h(!0),k("id",wt(p.target.value.replace(/^skills\//,"").replace(/\.skill\.md$/,"")))},onBlur:()=>k("id",Me(c.id)),title:"File name — letters, numbers, and dashes",style:{border:"none",background:"none",outline:"none",padding:0,fontFamily:o.fontMono,fontSize:10.5,color:o.textSecondary,width:`${Math.max(20,c.id.length+15)}ch`,borderBottom:v?"none":`1px dashed ${o.btnBorder}`}})]}),L?e.jsx(xe,{t:o,tone:"error",children:"A skill with this id already exists."}):null]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[e.jsxs("label",{style:U,children:[e.jsx("span",{style:q(o),children:"Domain"}),e.jsxs("select",{value:c.domain??"",onChange:p=>{const B=p.target.value||void 0;k("domain",B),k("domains",B?[B]:[])},style:{...H(o),cursor:"pointer",color:c.domain?o.textPrimary:o.textMuted},children:[e.jsx("option",{value:"",children:r.length===0?"No domains yet":"No domain"}),A.map(p=>e.jsx("option",{value:p.value,disabled:p.disabled,children:p.label},p.value))]})]}),e.jsxs("label",{style:U,children:[e.jsx("span",{style:q(o),children:"Type"}),e.jsxs("select",{value:c.kind??"custom",onChange:p=>k("kind",p.target.value),style:{...H(o),cursor:"pointer"},children:[e.jsx("option",{value:"custom",children:"Custom guidance"}),e.jsx("option",{value:"domain_reference",children:"Domain reference — broad context"}),e.jsx("option",{value:"metric_policy",children:"Policy — focused rule"}),e.jsx("option",{value:"glossary",children:"Glossary"}),e.jsx("option",{value:"analysis_pattern",children:"Analysis pattern"}),e.jsx("option",{value:"sql_policy",children:"SQL policy"})]})]})]}),e.jsx("button",{type:"button",onClick:()=>S({type:"SET_MAIN_VIEW",view:"domains"}),style:{border:"none",background:"none",padding:0,fontSize:10.5,color:o.accent,cursor:"pointer",fontFamily:o.font,alignSelf:"flex-start"},title:"Create a new domain on the Domains page",children:"+ New domain"}),e.jsxs("div",{children:[e.jsx("span",{style:{...q(o),display:"block",marginBottom:5},children:"Lifecycle"}),e.jsx("div",{style:{display:"inline-flex",alignItems:"center",gap:2,padding:2,border:`1px solid ${o.btnBorder}`,borderRadius:7,background:"var(--bg-1)"},children:["active","draft","deprecated"].map(p=>{const B=(c.status??"active")===p;return e.jsx("button",{type:"button",onClick:()=>k("status",p),style:{border:"none",borderRadius:5,padding:"4px 12px",fontSize:11.5,fontWeight:600,cursor:"pointer",fontFamily:o.font,background:B?o.cellBg:"transparent",color:B?o.textPrimary:o.textMuted,boxShadow:B?"0 1px 3px rgba(26,26,26,0.1)":"none",textTransform:"capitalize"},children:p},p)})}),e.jsx("span",{style:{fontSize:10.5,color:o.textMuted,marginLeft:8},children:(c.status??"active")==="active"?"Guides matching answers.":c.status==="draft"?"Drafts never guide answers.":"Kept in Git for history only."})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[e.jsx("div",{style:te(o),children:"When to apply"}),e.jsxs("label",{style:U,children:[e.jsx("span",{style:q(o),children:"Apply when the question mentions"}),e.jsx(It,{t:o,values:c.triggers??[],onChange:p=>k("triggers",p),placeholder:"Add phrase, press Enter"})]}),e.jsxs("label",{style:U,children:[e.jsx("span",{style:q(o),children:"Ask first when"}),e.jsx(de,{values:c.clarifyWhen??[],onChange:p=>k("clarifyWhen",p),placeholder:"e.g. 'sales' could mean revenue or order count",style:H(o)})]}),e.jsxs("label",{style:U,children:[e.jsx("span",{style:q(o),children:"Avoid when"}),e.jsx(de,{values:c.exclusions??[],onChange:p=>k("exclusions",p),placeholder:"e.g. question is about pipeline or bookings",style:H(o)})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10,gridRow:"span 2"},children:[e.jsx("div",{style:te(o),children:"Guidance"}),e.jsxs("label",{style:U,children:[e.jsx("span",{style:q(o),children:"One-line summary"}),e.jsx("input",{type:"text",value:c.description??"",onChange:p=>k("description",p.target.value),placeholder:"What rule does this skill encode?",style:H(o)})]}),e.jsxs("label",{style:U,children:[e.jsx("span",{style:q(o),children:"Full guidance"}),e.jsx("textarea",{value:c.body,onChange:p=>k("body",p.target.value),rows:9,placeholder:"Definitions, exclusions, edge cases — written for the agent.",style:At(o)})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[e.jsx("div",{style:te(o),children:"Prefer these assets"}),e.jsxs("label",{style:U,children:[e.jsx("span",{style:q(o),children:"Metrics"}),e.jsx(Pe,{t:o,options:n.metrics,optionKind:"metrics",selected:c.preferredMetrics,onChange:p=>k("preferredMetrics",p),placeholder:"Search metrics…",emptyOptionsHint:"No metrics available from the project yet."})]}),e.jsxs("label",{style:U,children:[e.jsx("span",{style:q(o),children:"Blocks"}),e.jsx(Pe,{t:o,options:n.blocks,optionKind:"blocks",selected:c.preferredBlocks,onChange:p=>k("preferredBlocks",p),placeholder:"Search blocks…",emptyOptionsHint:"No blocks available from the project yet."})]})]}),e.jsxs("details",{style:{gridColumn:"1 / -1"},children:[e.jsx("summary",{style:{fontSize:11.5,fontWeight:650,color:o.accent,cursor:"pointer"},children:"Advanced — model areas, dimensions, and vocabulary"}),e.jsxs("div",{style:{display:"grid",gap:14,marginTop:12},children:[e.jsx(ve,{label:"Focused model areas (optional)",t:o,hint:"Comma-separated area ids from the Model workspace. This boosts the skill only inside its selected domain; it never expands access.",children:e.jsx(de,{values:c.modelAreaRefs??[],onChange:p=>k("modelAreaRefs",p),placeholder:"customer_lifecycle, revenue_reporting",style:H(o)})}),e.jsx(ve,{label:"Preferred dimensions",t:o,hint:"Business-safe dimensions the agent should prefer when they are compatible.",children:e.jsx(de,{values:c.preferredDimensions??[],onChange:p=>k("preferredDimensions",p),placeholder:"region, month",style:H(o)})}),e.jsx(ve,{label:"Vocabulary",t:o,hint:"Map your terms to a target, e.g. arr → metric:arr or revenue → block:revenue_by_region.",children:e.jsx(Tt,{t:o,value:c.vocabulary,onChange:p=>k("vocabulary",p)})})]})]}),M?e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(xe,{t:o,tone:"error",children:M})}):null]}),e.jsxs("div",{style:_t(),children:[e.jsx("span",{style:{fontSize:10.5,color:o.textMuted,flex:1,textAlign:"left"},children:"Saved to Git — review in source control before merging."}),e.jsx("button",{type:"button",onClick:()=>!T&&s(),style:V(o),children:"Cancel"}),e.jsxs("button",{type:"button",onClick:m,disabled:!O,style:{...ge(o),opacity:O?1:.55},children:[T?e.jsx(_,{size:13,strokeWidth:2}):null,T?"Saving…":v?"Save changes":"Create skill"]})]})]})})}function It({t,values:n,onChange:r,placeholder:i}){const[l,a]=d.useState(""),o=s=>{const x=s.trim().replace(/,$/,"");!x||n.includes(x)||(r([...n,x]),a(""))};return e.jsxs("div",{style:Fe(t),children:[n.map(s=>e.jsxs("span",{style:Ge(t),children:[s,e.jsx("button",{type:"button",onClick:()=>r(n.filter(x=>x!==s)),style:Ke(t),title:"Remove",children:"×"})]},s)),e.jsx("input",{type:"text",value:l,onChange:s=>a(s.target.value),onKeyDown:s=>{s.key==="Enter"||s.key===","?(s.preventDefault(),o(l)):s.key==="Backspace"&&!l&&n.length&&r(n.slice(0,-1))},onBlur:()=>o(l),placeholder:n.length?"":i,style:qe(t)})]})}function Pe({t,options:n,optionKind:r,selected:i,onChange:l,placeholder:a,emptyOptionsHint:o}){const[s,x]=d.useState(""),[S,v]=d.useState(n);d.useEffect(()=>{let b=!1;const h=window.setTimeout(()=>{D.getSkillOptions(s).then(u=>{b||v(r==="metrics"?u.metrics:u.blocks)}).catch(()=>{b||v(n)})},160);return()=>{b=!0,window.clearTimeout(h)}},[r,n,s]);const c=d.useMemo(()=>S.filter(b=>!i.includes(b)).filter(b=>s?b.toLowerCase().includes(s.toLowerCase()):!0).slice(0,8),[S,i,s]),I=b=>{const h=b.trim();!h||i.includes(h)||(l([...i,h]),x(""))};return e.jsxs("div",{style:{display:"grid",gap:6},children:[e.jsxs("div",{style:Fe(t),children:[i.map(b=>e.jsxs("span",{style:{...Ge(t),fontFamily:t.fontMono},children:[b,e.jsx("button",{type:"button",onClick:()=>l(i.filter(h=>h!==b)),style:Ke(t),title:"Remove",children:"×"})]},b)),e.jsx("input",{type:"text",value:s,onChange:b=>x(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),I(s))},placeholder:i.length?"":a,style:qe(t)})]}),c.length>0?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:c.map(b=>e.jsxs("button",{type:"button",onClick:()=>I(b),style:Ot(t),children:[e.jsx(J,{size:10,strokeWidth:2.4})," ",b]},b))}):S.length===0?e.jsxs("div",{style:{fontSize:11,color:t.textMuted},children:[o," You can still type a value and press Enter."]}):null]})}function Tt({t,value:n,onChange:r}){const[i,l]=d.useState(()=>Object.entries(n??{}).map(([s,x])=>({term:s,target:x}))),a=s=>{l(s);const x={};for(const S of s){const v=S.term.trim();v&&(x[v]=S.target.trim())}r(x)},o=(s,x)=>{a(i.map((S,v)=>v===s?{...S,...x}:S))};return e.jsxs("div",{style:{display:"grid",gap:7},children:[i.map((s,x)=>e.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[e.jsx("input",{type:"text",value:s.term,onChange:S=>o(x,{term:S.target.value}),placeholder:"arr",style:{...H(t),flex:1}}),e.jsx("span",{style:{color:t.textMuted,fontSize:13},children:"→"}),e.jsx("input",{type:"text",value:s.target,onChange:S=>o(x,{target:S.target.value}),placeholder:"metric:arr",style:{...H(t),flex:1.3,fontFamily:t.fontMono}}),e.jsx("button",{type:"button",onClick:()=>a(i.filter((S,v)=>v!==x)),style:he(t),title:"Remove row",children:e.jsx(me,{size:13,strokeWidth:2})})]},x)),e.jsxs("button",{type:"button",onClick:()=>l([...i,{term:"",target:""}]),style:{...V(t),justifySelf:"start"},children:[e.jsx(J,{size:12,strokeWidth:2.2})," Add term"]})]})}function $t({t,onAdd:n}){return e.jsxs("div",{style:{border:`1px dashed ${t.cellBorder}`,borderRadius:12,background:t.cellBg,padding:"34px 28px",textAlign:"center",display:"grid",gap:12,justifyItems:"center"},children:[e.jsx("div",{style:{width:44,height:44,borderRadius:10,background:`${t.accent}18`,color:t.accent,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(re,{size:22,strokeWidth:1.9})}),e.jsx("div",{style:{fontSize:15,fontWeight:700,color:t.textPrimary},children:"Teach the AI your business rules"}),e.jsx("div",{style:{fontSize:13,color:t.textMuted,maxWidth:460,lineHeight:1.55},children:'Skills are the definitions, rules, and vocabulary the AI follows when it answers — like "revenue = recognized, not bookings" or "always exclude test accounts." Add your first one to start guiding every answer.'}),e.jsxs("button",{type:"button",onClick:n,style:{...ge(t),marginTop:4},children:[e.jsx(J,{size:14,strokeWidth:2.2})," Add your first skill"]})]})}function Dt({t,message:n,onRetry:r}){return e.jsxs("div",{style:{border:`1px solid ${t.warning}55`,borderRadius:10,background:`${t.warning}12`,padding:"16px 18px",display:"flex",alignItems:"flex-start",gap:11},children:[e.jsx(Ne,{size:16,strokeWidth:2,color:t.warning,style:{marginTop:1,flexShrink:0}}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:13,fontWeight:650,color:t.textPrimary},children:"Skills are not available right now"}),e.jsx("div",{style:{fontSize:12.5,color:t.textSecondary,marginTop:4,lineHeight:1.5},children:n}),e.jsxs("button",{type:"button",onClick:r,style:{...V(t),marginTop:10},children:[e.jsx(ye,{size:13,strokeWidth:2})," Retry"]})]})]})}function Rt({skill:t,t:n,deleting:r,error:i,onCancel:l,onConfirm:a}){return e.jsx("div",{style:Ft,onClick:l,children:e.jsxs("div",{style:qt(n),onClick:o=>o.stopPropagation(),children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9},children:[e.jsx(ie,{size:16,strokeWidth:2,color:n.error}),e.jsx("div",{style:{fontSize:15,fontWeight:700,color:n.textPrimary},children:"Delete this skill?"})]}),e.jsxs("div",{style:{fontSize:13,color:n.textSecondary,lineHeight:1.55},children:[e.jsx("span",{style:{fontFamily:n.fontMono,color:n.textPrimary},children:t.id})," will be removed and the AI will stop following it. This can't be undone."]}),i?e.jsx(xe,{t:n,tone:"error",children:i}):null,e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[e.jsx("button",{type:"button",onClick:l,disabled:r,style:V(n),children:"Cancel"}),e.jsxs("button",{type:"button",onClick:a,disabled:r,style:{...Et(n),opacity:r?.6:1},children:[r?e.jsx(_,{size:13,strokeWidth:2}):e.jsx(ie,{size:13,strokeWidth:2}),r?"Deleting…":"Delete"]})]})]})})}function te(t){return{fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:t.textMuted,marginBottom:5}}function ee({t,label:n,values:r,empty:i,accent:l=!1,mono:a=!1}){return e.jsxs("div",{style:{minWidth:0},children:[e.jsx("div",{style:te(t),children:n}),e.jsx("div",{style:{display:"flex",gap:5,flexWrap:"wrap"},children:r!=null&&r.length?r.map(o=>e.jsx("span",{style:{fontSize:11,padding:"3px 9px",borderRadius:999,background:l?"var(--accent-dim)":"var(--bg-1)",color:l?t.accent:t.textSecondary,border:l?`1px solid ${t.accent}33`:"1px solid var(--border-subtle)",fontFamily:a?t.fontMono:void 0},children:o},o)):e.jsx("span",{style:{fontSize:11.5,color:t.textMuted,fontStyle:"italic"},children:i})})]})}function ve({label:t,hint:n,t:r,children:i}){return e.jsxs("div",{style:{display:"grid",gap:6},children:[e.jsx("label",{style:{fontSize:12,fontWeight:700,color:r.textPrimary},children:t}),n?e.jsx("div",{style:{fontSize:11.5,color:r.textMuted,lineHeight:1.45,marginTop:-2},children:n}):null,i]})}function xe({t,tone:n,children:r}){const i=n==="error"?t.error:t.textMuted;return e.jsx("div",{style:{fontSize:11.5,color:i,lineHeight:1.45},children:r})}function Mt(t){return{display:"inline-flex",alignItems:"center",fontSize:10.5,fontWeight:700,color:t.success,background:`${t.success}14`,border:`1px solid ${t.success}38`,borderRadius:999,padding:"2px 7px"}}function Pt(t){return{display:"inline-flex",alignItems:"center",fontSize:10.5,fontWeight:700,color:t.accent,background:`${t.accent}14`,border:`1px solid ${t.accent}38`,borderRadius:999,padding:"2px 7px"}}function ge(t){return{display:"inline-flex",alignItems:"center",gap:6,padding:"7px 13px",borderRadius:7,border:`1px solid ${t.accent}`,background:t.accent,color:"#ffffff",fontSize:12.5,fontWeight:700,fontFamily:t.font,cursor:"pointer"}}function V(t){return{display:"inline-flex",alignItems:"center",gap:5,padding:"7px 11px",borderRadius:7,border:`1px solid ${t.btnBorder}`,background:t.btnBg,color:t.textSecondary,fontSize:12,fontWeight:600,fontFamily:t.font,cursor:"pointer"}}function Et(t){return{display:"inline-flex",alignItems:"center",gap:6,padding:"7px 13px",borderRadius:7,border:`1px solid ${t.error}`,background:t.error,color:"#ffffff",fontSize:12.5,fontWeight:700,fontFamily:t.font,cursor:"pointer"}}function he(t){return{display:"inline-flex",alignItems:"center",justifyContent:"center",width:30,height:30,borderRadius:7,border:`1px solid ${t.btnBorder}`,background:t.btnBg,color:t.textSecondary,cursor:"pointer",flexShrink:0}}function H(t){return{width:"100%",border:`1px solid ${t.btnBorder}`,borderRadius:7,background:t.cellBg,color:t.textPrimary,fontSize:12.5,fontFamily:t.font,padding:"8px 10px",boxSizing:"border-box"}}function At(t){return{...H(t),resize:"vertical",lineHeight:1.5,padding:"9px 11px"}}function Ee(t){return{display:"inline-flex",alignItems:"center",gap:4,fontSize:10,fontWeight:700,letterSpacing:"0.02em",color:t.warning,background:`${t.warning}16`,border:`1px solid ${t.warning}40`,borderRadius:999,padding:"2px 8px"}}function Fe(t){return{display:"flex",alignItems:"center",gap:5,flexWrap:"wrap",border:`1px solid ${t.btnBorder}`,background:t.cellBg,borderRadius:7,padding:"6px 8px"}}function qe(t){return{flex:1,minWidth:110,border:"none",background:"none",outline:"none",fontSize:11.5,fontFamily:t.font,color:t.textPrimary,padding:2}}function Ge(t){return{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,padding:"2.5px 8px",borderRadius:999,background:"var(--accent-dim)",color:t.accent,border:`1px solid ${t.accent}33`}}function Ke(t){return{border:"none",background:"none",color:t.accent,cursor:"pointer",padding:0,fontSize:12,lineHeight:1,fontFamily:t.font}}const U={display:"flex",flexDirection:"column",gap:4};function q(t){return{fontSize:11,fontWeight:650,color:t.textSecondary}}function Ot(t){return{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,fontWeight:600,color:t.textSecondary,background:t.btnBg,border:`1px solid ${t.btnBorder}`,borderRadius:6,padding:"3px 8px",cursor:"pointer",fontFamily:t.fontMono}}const Lt={position:"fixed",inset:0,background:"rgba(26, 26, 26, 0.22)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:60};function Nt(t){return{width:"min(860px, 94vw)",height:"min(640px, 90vh)",background:t.cellBg,border:`1px solid ${t.headerBorder}`,borderRadius:14,display:"flex",flexDirection:"column",overflow:"hidden",boxShadow:"0 24px 70px rgba(26,26,26,0.22)"}}function Ht(t){return{display:"flex",alignItems:"center",gap:10,padding:"14px 18px",borderBottom:"1px solid var(--border-subtle)",flexShrink:0}}function _t(t){return{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:8,padding:"12px 18px",borderTop:"1px solid var(--border-subtle)",background:"var(--bg-1)",flexShrink:0}}const Ft={position:"fixed",inset:0,background:"rgba(0, 0, 0, 0.42)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:70,padding:20};function qt(t){return{width:"min(420px, 100%)",background:t.cellBg,border:`1px solid ${t.cellBorder}`,borderRadius:12,padding:20,display:"grid",gap:13,boxShadow:"0 18px 48px rgba(0,0,0,0.3)"}}function Gt({initialTab:t="overview"}){const{state:n}=fe(),r=we[n.themeMode],[i,l]=d.useState(t),[a,o]=d.useState([]),[s,x]=d.useState([]),[S,v]=d.useState(!0);d.useEffect(()=>l(t),[t]);const c=d.useCallback(()=>{let u=!1;return v(!0),Promise.all([D.getDomains(),D.getSkills()]).then(([R,T])=>{u||(o(Array.isArray(R.domains)?R.domains:[]),x(Array.isArray(T.skills)?T.skills:[]))}).catch(()=>{u||(o([]),x([]))}).finally(()=>{u||v(!1)}),()=>{u=!0}},[]);d.useEffect(()=>c(),[c]);const I=d.useMemo(()=>{const u=a.filter(j=>!!(j.businessOwner||j.owner)).length,R=s.filter(j=>!j.status||j.status==="active").length,T=s.filter(j=>j.status==="draft").length;return{ownedDomains:u,activeSkills:R,draftSkills:T}},[a,s]),b=d.useCallback(()=>{l("domains"),window.setTimeout(()=>window.dispatchEvent(new Event("dql:context-build")),50)},[]),h=[{id:"overview",label:"Overview"},{id:"domains",label:"Domains",count:a.length},{id:"skills",label:"Skills",count:s.length},{id:"knowledge",label:"Knowledge 360"}];return e.jsx("div",{style:{flex:1,minWidth:0,overflow:"auto",background:r.appBg},children:e.jsxs("div",{style:{maxWidth:1040,margin:"0 auto",padding:"22px 28px 40px"},children:[e.jsxs("header",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-end",gap:18,marginBottom:15},children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",gap:9,alignItems:"center"},children:[e.jsx(se,{size:20,color:r.accent}),e.jsx("h1",{style:{fontSize:22,color:r.textPrimary},children:"Governed context"})]}),e.jsx("p",{style:{marginTop:6,fontSize:13,lineHeight:1.5,color:r.textMuted,maxWidth:700},children:"Domains define business boundaries. Skills teach the agent approved vocabulary, reuse rules, and when to ask for clarification."})]}),e.jsxs("button",{type:"button",onClick:b,style:Qe(r),children:[e.jsx(ne,{size:14})," Build with AI"]})]}),e.jsx("nav",{"aria-label":"Governed context sections",style:{display:"flex",gap:3,borderBottom:`1px solid ${r.headerBorder}`,marginBottom:18},children:h.map(u=>e.jsxs("button",{type:"button",onClick:()=>l(u.id),style:{border:"none",borderBottom:`2px solid ${i===u.id?r.accent:"transparent"}`,background:"transparent",padding:"9px 12px",color:i===u.id?r.textPrimary:r.textMuted,fontWeight:i===u.id?700:600,cursor:"pointer",fontFamily:r.font,fontSize:12.5},children:[u.label,u.count!==void 0?` · ${u.count}`:""]},u.id))}),i==="overview"?e.jsx(Kt,{t:r,loading:S,domains:a,skills:s,status:I,onBuild:b,onTab:l}):null,i==="domains"?e.jsx(st,{embedded:!0}):null,i==="skills"?e.jsx(zt,{embedded:!0}):null,i==="knowledge"?e.jsx(Ue,{t:r,domains:a}):null]})})}function Ue({t,domains:n,initialDomainId:r}){var I,b;const[i,l]=d.useState(r??((I=n[0])==null?void 0:I.id)??""),[a,o]=d.useState(null),[s,x]=d.useState(!1),[S,v]=d.useState(null);d.useEffect(()=>{var h;!i&&((h=n[0])!=null&&h.id)&&l(n[0].id)},[i,n]),d.useEffect(()=>{r&&n.some(h=>h.id===r)&&l(r)},[n,r]),d.useEffect(()=>{if(!i){o(null);return}let h=!1;return x(!0),v(null),D.getDomainKnowledge(i).then(u=>{h||o(u)}).catch(u=>{h||(o(null),v(u instanceof Error?u.message:"Could not load the compiled knowledge capsule."))}).finally(()=>{h||x(!1)}),()=>{h=!0}},[i]);const c=d.useMemo(()=>{const h={};for(const u of(a==null?void 0:a.objects)??[])h[u.kind]=(h[u.kind]??0)+1;return Object.entries(h).sort((u,R)=>R[1]-u[1]||u[0].localeCompare(R[0]))},[a]);return e.jsxs("div",{style:{display:"grid",gap:14},children:[e.jsx("section",{style:{border:`1px solid ${t.cellBorder}`,borderRadius:10,background:t.cellBg,padding:15},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:12,flexWrap:"wrap"},children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",gap:7,alignItems:"center",color:t.textPrimary,fontWeight:700,fontSize:13},children:[e.jsx(Ie,{size:16,color:t.accent})," Compiled Domain 360"]}),e.jsx("div",{style:{marginTop:4,color:t.textMuted,fontSize:12},children:"The same qualified graph, route policy, and skill snapshot used by Ask."})]}),e.jsxs("select",{"aria-label":"Domain knowledge capsule",value:i,onChange:h=>l(h.target.value),style:{minWidth:210,border:`1px solid ${t.inputBorder}`,borderRadius:7,background:t.inputBg,color:t.textPrimary,padding:"7px 9px",fontFamily:t.font},children:[e.jsx("option",{value:"",children:"Select a domain"}),[...n].sort((h,u)=>h.name.localeCompare(u.name)).map(h=>e.jsx("option",{value:h.id,children:h.name},h.id))]})]})}),s?e.jsxs("div",{style:{color:t.textMuted,display:"flex",gap:8,alignItems:"center",padding:24},children:[e.jsx(_,{size:15})," Loading compiled knowledge…"]}):null,S?e.jsx("div",{style:{border:`1px solid ${t.error}`,background:t.cellBg,color:t.error,borderRadius:8,padding:12,fontSize:12.5},children:S}):null,a?e.jsxs(e.Fragment,{children:[e.jsxs("section",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:9},children:[e.jsx(Y,{t,label:"Objects",value:a.counts.objects,detail:"qualified knowledge",icon:e.jsx(se,{size:16})}),e.jsx(Y,{t,label:"Relations",value:a.counts.edges,detail:"provenance + policy",icon:e.jsx(Ie,{size:16})}),e.jsx(Y,{t,label:"Authorized",value:a.counts.routeStates.authorized??0,detail:"safe cross-domain routes",icon:e.jsx(Xe,{size:16})}),e.jsx(Y,{t,label:"Blocked / stale",value:(a.counts.routeStates.blocked??0)+(a.counts.routeStates.stale??0),detail:"never auto-joined",icon:e.jsx(Le,{size:16})})]}),e.jsxs("section",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1.2fr) minmax(0, 1fr)",gap:12},children:[e.jsxs("div",{style:{border:`1px solid ${t.cellBorder}`,borderRadius:9,background:t.cellBg,padding:14},children:[e.jsx("strong",{style:{color:t.textPrimary,fontSize:13},children:"Knowledge capsule"}),e.jsx("p",{style:{color:t.textSecondary,fontSize:12.5,lineHeight:1.5,margin:"7px 0 11px"},children:((b=a.capsule)==null?void 0:b.description)||"Compiled domain boundary and governed references."}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:c.map(([h,u])=>e.jsxs("span",{style:{border:`1px solid ${t.cellBorder}`,background:t.pillBg,color:t.textSecondary,borderRadius:999,padding:"3px 7px",fontSize:11},children:[h.replace(/_/g," ")," · ",u]},h))}),e.jsxs("div",{style:{marginTop:11,color:t.textMuted,fontSize:11},children:["Snapshot ",a.snapshotId.slice(0,12)," · graph ",a.sourceFingerprint.slice(0,12),a.truncated?" · bounded response":""]})]}),e.jsxs("div",{style:{border:`1px solid ${t.cellBorder}`,borderRadius:9,background:t.cellBg,padding:14},children:[e.jsx("strong",{style:{color:t.textPrimary,fontSize:13},children:"Cross-domain routes"}),e.jsx("div",{style:{display:"grid",gap:7,marginTop:9},children:a.routes.length?a.routes.map(h=>e.jsxs("div",{style:{borderTop:`1px solid ${t.headerBorder}`,paddingTop:7},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:8,color:t.textSecondary,fontSize:12},children:[e.jsxs("span",{children:[h.providerDomainId," → ",h.consumerDomainId]}),e.jsx("span",{style:{color:h.state==="authorized"?t.success:h.state==="observed"?t.textMuted:t.warning,fontWeight:700},children:h.state})]}),e.jsx("div",{style:{marginTop:3,color:t.textMuted,fontSize:11},children:h.purpose||h.reasonCodes.join(", ")||"governed route"})]},h.id)):e.jsx("div",{style:{color:t.textMuted,fontSize:12,marginTop:8},children:"No cross-domain routes declared."})})]})]})]}):null]})}function Kt({t,loading:n,domains:r,skills:i,status:l,onBuild:a,onTab:o}){if(n)return e.jsxs("div",{style:{padding:"42px 0",color:t.textMuted,display:"flex",gap:8,alignItems:"center",fontSize:13},children:[e.jsx(_,{size:15})," Loading governed context…"]});const s=[];return r.length?l.ownedDomains<r.length&&s.push(`${r.length-l.ownedDomains} domain${r.length-l.ownedDomains===1?"":"s"} still need an owner.`):s.push("Create a business domain before relying on AI guidance."),i.length||s.push("Draft a domain skill so the agent has governed business guidance."),l.draftSkills&&s.push(`${l.draftSkills} skill${l.draftSkills===1?" is":"s are"} still draft-only and will not guide answers.`),e.jsxs("div",{style:{display:"grid",gap:16},children:[e.jsxs("section",{style:{display:"grid",gridTemplateColumns:"repeat(3, minmax(0, 1fr))",gap:10},children:[e.jsx(Y,{t,label:"Domains",value:r.length,detail:`${l.ownedDomains} with an owner`,icon:e.jsx(se,{size:17})}),e.jsx(Y,{t,label:"Active skills",value:l.activeSkills,detail:"available to the agent",icon:e.jsx(re,{size:17})}),e.jsx(Y,{t,label:"Draft skills",value:l.draftSkills,detail:"review before activation",icon:e.jsx(ne,{size:17})})]}),e.jsxs("section",{style:{border:`1px solid ${t.cellBorder}`,borderRadius:10,background:t.cellBg,padding:16,display:"grid",gap:10},children:[e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[e.jsx(Ze,{size:16,color:s.length?t.warning:t.success}),e.jsx("strong",{style:{color:t.textPrimary,fontSize:13},children:"Readiness"})]}),s.length?e.jsx("div",{style:{display:"grid",gap:6},children:s.map(x=>e.jsxs("div",{style:{display:"flex",gap:7,color:t.textSecondary,fontSize:12.5},children:[e.jsx(Le,{size:14,color:t.warning}),x]},x))}):e.jsx("div",{style:{color:t.success,fontSize:12.5},children:"Your agent has owned domains and active governed skills available for retrieval."}),e.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",marginTop:2},children:[e.jsxs("button",{type:"button",onClick:a,style:Qe(t),children:[e.jsx(ne,{size:13})," Build domains & skills with AI"]}),e.jsx("button",{type:"button",onClick:()=>o("domains"),style:Ae(t),children:"Manage domains"}),e.jsx("button",{type:"button",onClick:()=>o("skills"),style:Ae(t),children:"Manage skills"})]})]})]})}function Y({t,label:n,value:r,detail:i,icon:l}){return e.jsxs("div",{style:{border:`1px solid ${t.cellBorder}`,borderRadius:9,background:t.cellBg,padding:13},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",color:t.textMuted,fontSize:12},children:[n,l]}),e.jsx("div",{style:{color:t.textPrimary,fontSize:25,fontWeight:750,marginTop:7},children:r}),e.jsx("div",{style:{color:t.textMuted,fontSize:11.5,marginTop:3},children:i})]})}function Qe(t){return{display:"inline-flex",alignItems:"center",gap:6,padding:"7px 12px",borderRadius:7,border:`1px solid ${t.accent}`,background:t.accent,color:"#fff",fontWeight:700,fontSize:12.5,fontFamily:t.font,cursor:"pointer"}}function Ae(t){return{display:"inline-flex",alignItems:"center",padding:"7px 12px",borderRadius:7,border:`1px solid ${t.btnBorder}`,background:t.btnBg,color:t.textSecondary,fontWeight:650,fontSize:12.5,fontFamily:t.font,cursor:"pointer"}}const Zt=Object.freeze(Object.defineProperty({__proto__:null,GovernedContextPage:Gt,Knowledge360:Ue},Symbol.toStringTag,{value:"Module"}));export{Zt as G,Ue as K,zt as S};
|