@duckcodeailabs/dql-cli 1.13.1 → 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/assets/dql-notebook/assets/{AgentLogPage-D6fgEAEy.js → AgentLogPage-BlUE3qsX.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildDialog-8miXFPse.js → AiBuildDialog-O88iK6UW.js} +1 -1
- package/dist/assets/dql-notebook/assets/{AiBuildResult-DPJ_SI0R.js → AiBuildResult-D-6G4Sh3.js} +8 -8
- package/dist/assets/dql-notebook/assets/{AiSidePanel-NVA6lZnn.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--jNw9XUI.js → BlockStudio-BrTNaDpb.js} +10 -15
- package/dist/assets/dql-notebook/assets/{BusinessArtifactView-DtRMiaF4.js → BusinessArtifactView-itEIUrYy.js} +1 -1
- package/dist/assets/dql-notebook/assets/DbtFirstModelingPage-CbAqOpNc.js +22 -0
- package/dist/assets/dql-notebook/assets/{GitPage-CazC-eTR.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-DMHPsVqP.js → HelpDocsPage-D1lAryYv.js} +1 -1
- package/dist/assets/dql-notebook/assets/{HomePage-DcSI4dnU.js → HomePage-GB6se6xW.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDAG-BJ6xz06u.js → LineageDAG-zCyN-hdg.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDetailView-8WrQm-MF.js → LineageDetailView-Cg0TgG2Y.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineageDrawer-hnqCW_t-.js → LineageDrawer-DwMcenDf.js} +1 -1
- package/dist/assets/dql-notebook/assets/{LineagePathBreadcrumb-B4LZTUsl.js → LineagePathBreadcrumb-DUZx3ksU.js} +1 -1
- package/dist/assets/dql-notebook/assets/{MiniLineageGraph-CotnRuxa.js → MiniLineageGraph-DT_ycl6s.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewBlockModal-DHn-CEEW.js → NewBlockModal-qdhzeJPF.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NewNotebookModal-BPGp-8oq.js → NewNotebookModal-BnaDzs1A.js} +1 -1
- package/dist/assets/dql-notebook/assets/{NotebookEditor-B0OTHM6W.js → NotebookEditor-CouPFzdo.js} +5 -5
- package/dist/assets/dql-notebook/assets/{ReadinessPage-CoOIpxWq.js → ReadinessPage-DB_KbH9Y.js} +1 -1
- package/dist/assets/dql-notebook/assets/{SetupOnboarding-DxK_mFzf.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-ZuD5N5Ww.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-WAVAYjBv.js → answer-to-notebook-Cg3UyGwh.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-left-L8odLbyN.js → arrow-left-DnYPGqlr.js} +1 -1
- package/dist/assets/dql-notebook/assets/{arrow-right-WIF1V9a9.js → arrow-right-Ct_YGrmU.js} +1 -1
- package/dist/assets/dql-notebook/assets/{book-open-text-BpqWMa4m.js → book-open-text-DULlwbj6.js} +1 -1
- package/dist/assets/dql-notebook/assets/{circle-x-CQBOM0b0.js → circle-x-ByYxoiS9.js} +1 -1
- package/dist/assets/dql-notebook/assets/{dagre.esm-DlZi7NR3.js → dagre.esm-BjYSO53F.js} +1 -1
- package/dist/assets/dql-notebook/assets/{external-link-DYqdQIGp.js → external-link-DprWh9Yf.js} +1 -1
- package/dist/assets/dql-notebook/assets/{grip-vertical-HmUijbwN.js → grip-vertical-CrEEYkXN.js} +1 -1
- package/dist/assets/dql-notebook/assets/{index-Cpx47jCH.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-BkW-rkEC.js +6 -0
- package/dist/assets/dql-notebook/assets/{list-tree-DGKqCxmz.js → list-tree-BipBLmIE.js} +1 -1
- package/dist/assets/dql-notebook/assets/{minimize-2-C8dvqCxX.js → minimize-2-BhXsglrO.js} +1 -1
- package/dist/assets/dql-notebook/assets/{panel-right-open-yuVkIo5n.js → panel-right-open-BoCSilYB.js} +1 -1
- package/dist/assets/dql-notebook/assets/{bot-CLR1V6dO.js → play-mdoZawPu.js} +7 -2
- package/dist/assets/dql-notebook/assets/{rotate-ccw-Di0kRnrM.js → rotate-ccw-ELiDRUmj.js} +1 -1
- package/dist/assets/dql-notebook/assets/{semantic-fields-BMQV0li8.js → semantic-fields-DVNRLfeU.js} +1 -1
- package/dist/assets/dql-notebook/assets/{sliders-horizontal-alebptlJ.js → sliders-horizontal-GeUzpmKz.js} +1 -1
- package/dist/assets/dql-notebook/assets/{star-CgCQbnXc.js → star-D63O81Wp.js} +1 -1
- package/dist/assets/dql-notebook/assets/{triangle-alert-SyuSZ4ht.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-J4PQHxo9.js → user-round-Do21aFGo.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wand-sparkles-c4WDXTCk.js → wand-sparkles-DT7u7F_x.js} +1 -1
- package/dist/assets/dql-notebook/assets/{workflow-NtRLaq7n.js → workflow-DHh2mMbn.js} +1 -1
- package/dist/assets/dql-notebook/assets/{wrench-CS1f1Zv4.js → wrench-7tYr_GKb.js} +1 -1
- package/dist/assets/dql-notebook/assets/{x-CbKEfe5m.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.js +21 -2
- package/dist/commands/model.js.map +1 -1
- package/dist/llm/providers/dql-agent-provider.d.ts +16 -0
- package/dist/llm/providers/dql-agent-provider.d.ts.map +1 -1
- package/dist/llm/providers/dql-agent-provider.js +65 -2
- package/dist/llm/providers/dql-agent-provider.js.map +1 -1
- package/dist/local-runtime.d.ts +65 -0
- package/dist/local-runtime.d.ts.map +1 -1
- package/dist/local-runtime.js +1008 -125
- package/dist/local-runtime.js.map +1 -1
- package/dist/package.json +10 -10
- package/dist/sql-result-filter.d.ts +9 -0
- package/dist/sql-result-filter.d.ts.map +1 -1
- package/dist/sql-result-filter.js +25 -0
- package/dist/sql-result-filter.js.map +1 -1
- package/package.json +10 -10
- package/dist/assets/dql-notebook/assets/AgentAnswerCard-c8QUo6NH.js +0 -5
- package/dist/assets/dql-notebook/assets/AnalyticsHome-DgwnRW71.js +0 -6
- package/dist/assets/dql-notebook/assets/AppsView-B6LYUpgm.js +0 -4578
- package/dist/assets/dql-notebook/assets/DbtFirstModelingPage-DhBsLCYr.js +0 -22
- package/dist/assets/dql-notebook/assets/GlobalAiRail-1Tgweuu2.js +0 -1
- package/dist/assets/dql-notebook/assets/GovernedContextPage-C7qGrH3d.js +0 -16
- package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-duFXXNV_.js +0 -88
- package/dist/assets/dql-notebook/assets/index-DKu4CZt3.css +0 -1
- package/dist/assets/dql-notebook/assets/upload-BPhfea_E.js +0 -11
- package/dist/assets/dql-notebook/assets/usePersistedAgentThreadId-Bnl9gWhj.js +0 -28
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as C,t as k,r as l,a as I,j as t,p as j,q as S,au as L,av as N}from"./index-
|
|
1
|
+
import{u as C,t as k,r as l,a as I,j as t,p as j,q as S,au as L,av as N}from"./index-9w93YPF9.js";import{M as W}from"./MiniLineageGraph-DT_ycl6s.js";import"./react-CRB3T2We.js";import"./dagre.esm-BjYSO53F.js";function w(n){return n.replace(/\.(dqlnb|dql)$/i,"")}function $(n,o){return`${n}:${w(o)}`}function U(){var y,x;const{state:n,dispatch:o}=C(),e=k[n.themeMode],i=n.activeFile,d=i&&(i.type==="term"||i.type==="business_view")?$(i.type,i.name):null,[a,B]=l.useState({nodes:[],edges:[],focalNode:null}),[M,u]=l.useState(!1);l.useEffect(()=>{if(!d)return;let s=!1;return u(!0),I.queryLineage({focus:d,upstreamDepth:3,downstreamDepth:3}).then(h=>{var f,v;s||(B({nodes:((f=h.graph)==null?void 0:f.nodes)??[],edges:((v=h.graph)==null?void 0:v.edges)??[],focalNode:h.focalNode??null}),u(!1))}).catch(()=>{s||u(!1)}),()=>{s=!0}},[d]);const r=a.focalNode,c=l.useMemo(()=>new Map(a.nodes.map(s=>[s.id,s])),[a.nodes]),g=l.useMemo(()=>r?a.edges.filter(s=>s.target===r.id).map(s=>({edge:s,node:c.get(s.source)})).filter(s=>!!s.node):[],[r,a.edges,c]),m=l.useMemo(()=>r?a.edges.filter(s=>s.source===r.id).map(s=>({edge:s,node:c.get(s.target)})).filter(s=>!!s.node):[],[r,a.edges,c]);if(!i||!d)return t.jsx("div",{style:{flex:1,padding:24,color:e.textMuted},children:"Select a business term or business view from Explorer."});const p=(r==null?void 0:r.type)??i.type,T=j[p]??e.accent,E=S[p]??p.toUpperCase(),z=((y=r==null?void 0:r.metadata)==null?void 0:y.path)??((x=r==null?void 0:r.metadata)==null?void 0:x.filePath)??i.path;return t.jsxs("div",{style:{flex:1,minWidth:0,overflow:"auto",background:"var(--color-bg-primary)"},children:[t.jsx("div",{style:{padding:"22px 28px 18px",borderBottom:`1px solid ${e.headerBorder}`,background:e.appBg},children:t.jsx("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:16},children:t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:8},children:[t.jsx("span",{style:{color:e.appBg,background:T,borderRadius:5,padding:"3px 7px",fontSize:10,fontWeight:800,letterSpacing:0},title:L[p]??p,children:E}),t.jsxs("span",{style:{color:e.textMuted,fontSize:12},children:["Lineage · ↑ ",g.length," · ↓ ",m.length]})]}),t.jsx("h1",{style:{margin:0,fontSize:26,lineHeight:1.15,color:e.textPrimary},children:(r==null?void 0:r.name)??w(i.name)}),t.jsx("div",{style:{marginTop:7,color:e.textMuted,fontSize:13},children:i.type==="term"?"Business definition used by blocks, views, dashboards, and AI agents.":"Business composition built from trusted terms, DQL blocks, and other business views."})]})})}),t.jsxs("div",{style:{padding:24,display:"grid",gridTemplateColumns:"minmax(300px, 420px) minmax(420px, 1fr)",gap:18},children:[t.jsxs("section",{style:{display:"grid",gap:14,alignContent:"start"},children:[r&&t.jsx(P,{node:r,t:e}),t.jsx(b,{title:"Upstream",connections:g,t:e}),t.jsx(b,{title:"Downstream",connections:m,t:e}),t.jsxs("div",{style:{border:`1px solid ${e.headerBorder}`,borderRadius:8,padding:12,color:e.textMuted,fontSize:12,background:e.sidebarBg},children:[t.jsx("div",{style:{fontWeight:800,color:e.textSecondary,marginBottom:6},children:"Source file"}),t.jsx("div",{style:{overflowWrap:"anywhere"},children:String(z)})]})]}),t.jsxs("section",{style:{minHeight:520,border:`1px solid ${e.headerBorder}`,borderRadius:8,background:e.sidebarBg,overflow:"hidden"},children:[t.jsxs("div",{style:{padding:"12px 14px",borderBottom:`1px solid ${e.headerBorder}`},children:[t.jsx("div",{style:{fontWeight:800,color:e.textPrimary,fontSize:14},children:"Focused lineage"}),t.jsxs("div",{style:{color:e.textMuted,fontSize:12,marginTop:3},children:["Technical inputs and business composition for this ",i.type==="term"?"term":"view","."]})]}),t.jsx("div",{style:{height:470,padding:12},children:M?t.jsx("div",{style:{color:e.textMuted,fontSize:12},children:"Loading lineage..."}):a.nodes.length===0?t.jsx("div",{style:{color:e.textMuted,fontSize:12},children:"No lineage available."}):t.jsx(W,{nodes:a.nodes,edges:a.edges,focalNodeId:d,height:"100%",onNodeClick:s=>{o({type:"SET_LINEAGE_FOCUS",nodeId:s})},interactive:!0})})]})]})]})}function P({node:n,t:o}){const e=n.metadata??{},i=[];return n.domain&&i.push({label:"Domain",value:n.domain}),n.owner&&i.push({label:"Owner",value:n.owner}),n.status&&i.push({label:"Status",value:n.status}),n.type==="term"&&typeof e.termType=="string"&&i.push({label:"Term Type",value:e.termType}),Array.isArray(e.identifiers)&&e.identifiers.length>0&&i.push({label:"Identifiers",value:e.identifiers.map(String).join(", ")}),Array.isArray(e.synonyms)&&e.synonyms.length>0&&i.push({label:"Synonyms",value:e.synonyms.map(String).join(", ")}),typeof e.description=="string"&&e.description.trim()&&i.push({label:"Description",value:e.description}),typeof e.businessOutcome=="string"&&e.businessOutcome.trim()&&i.push({label:"Business Outcome",value:e.businessOutcome}),typeof e.decisionUse=="string"&&e.decisionUse.trim()&&i.push({label:"Decision Use",value:e.decisionUse}),typeof e.reviewCadence=="string"&&e.reviewCadence.trim()&&i.push({label:"Review Cadence",value:e.reviewCadence}),t.jsxs("div",{style:{border:`1px solid ${o.headerBorder}`,borderRadius:8,background:o.sidebarBg,padding:12},children:[t.jsx("div",{style:{fontWeight:800,color:o.textPrimary,marginBottom:10},children:"Business metadata"}),t.jsx("div",{style:{display:"grid",gap:8},children:i.map(d=>t.jsxs("div",{style:{display:"grid",gap:3},children:[t.jsx("div",{style:{color:o.textMuted,fontSize:10,fontWeight:800,textTransform:"uppercase"},children:d.label}),t.jsx("div",{style:{color:o.textSecondary,fontSize:12,lineHeight:1.45},children:d.value})]},d.label))})]})}function b({title:n,connections:o,t:e}){return t.jsxs("div",{style:{border:`1px solid ${e.headerBorder}`,borderRadius:8,background:e.sidebarBg,padding:12},children:[t.jsx("div",{style:{fontWeight:800,color:e.textPrimary,marginBottom:10},children:n}),o.length===0?t.jsxs("div",{style:{color:e.textMuted,fontSize:12},children:["No ",n.toLowerCase()," connections in this focused window."]}):t.jsxs("div",{style:{display:"grid",gap:7},children:[o.slice(0,8).map(({edge:i,node:d})=>{const a=j[d.type]??e.textMuted;return t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"92px 1fr",gap:8,minWidth:0,fontSize:12},children:[t.jsx("span",{style:{color:e.textMuted},children:N[i.type]??i.type}),t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:6,minWidth:0},children:[t.jsx("span",{style:{color:e.appBg,background:a,borderRadius:3,padding:"1px 4px",fontSize:9,fontWeight:800,flexShrink:0},children:S[d.type]??d.type.slice(0,4).toUpperCase()}),t.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:d.name,children:d.name})]})]},`${i.source}-${i.target}-${i.type}`)}),o.length>8&&t.jsxs("div",{style:{color:e.textMuted,fontSize:12},children:[o.length-8," more connection",o.length-8===1?"":"s"," in the graph"]})]})]})}export{U as BusinessArtifactView};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import{c as sn,r as a,j as e,P as et,aJ as qn,aK as Lo,aL as oo,a as Z,ap as Ft,$ as No,aM as so,L as Oo,u as Wt,t as _o,aN as io,a4 as Ze,aC as Eo,a0 as qo,aO as ao,aP as To,aQ as Fo,aR as Wo,V as Ho,aS as Uo,aT as lo,B as ro,G as Ko,S as Ht,aU as Yo,aV as Vo,aW as Jo,aX as Tn,l as Qo,aY as Go}from"./index-9w93YPF9.js";import{S as Xo,C as Zo}from"./SkillsPage--mYkOAK2.js";import{u as es,i as ts,B as ns,C as os,b as ss,M as is,T as Fn,N as as,H as ft,c as yt,d as ls}from"./dagre.esm-BjYSO53F.js";import{L as Ot}from"./link-2-BkW-rkEC.js";import{M as co,F as an,u as rs}from"./usePersistedAgentThreadId-Cv7Yq2hK.js";import{U as ds}from"./UnifiedAgentRunPanel-DBfsmXes.js";import{U as cs}from"./upload-CI-ldXhC.js";import{X as us}from"./x-CcYceFMz.js";import{P as ps}from"./panel-right-open-BoCSilYB.js";import{G as hs}from"./user-round-Do21aFGo.js";import{S as xs}from"./sliders-horizontal-GeUzpmKz.js";import{C as tt}from"./circle-x-ByYxoiS9.js";import{R as gs}from"./rotate-ccw-ELiDRUmj.js";import"./react-CRB3T2We.js";import"./triangle-alert-BWrCxQVE.js";import"./TrustBadge-ClEYiYeA.js";import"./AiBuildResult-D-6G4Sh3.js";import"./wrench-7tYr_GKb.js";import"./list-tree-BipBLmIE.js";import"./minimize-2-BhXsglrO.js";import"./arrow-right-Ct_YGrmU.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 ms=[["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"}]],fs=sn("columns-3",ms);/**
|
|
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 ys=[["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"}]],Gt=sn("folder-tree",ys);/**
|
|
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 bs=[["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"}]],js=sn("panel-right-close",bs);function vs({modeling:t,ghostEntityIds:n,ghostRelationshipIds:s,relationByDbtId:o,detailsByDbtId:i,selectedDomain:r,selectedAreaId:d,selectedId:h,viewMode:y,columnMode:l,search:u,layoutMode:m,density:f,visibleLimit:c,dimUnrelated:x,showEdgeLabels:I,resetLayoutToken:v,focusRequest:w,onVisibleDbtIdsChange:B,onSelectEntity:b,onSelectRelationship:S,onEditRelationship:P,onDraftRelationship:q,onAddRelatedModel:N,onAddModel:j,onCreateDomain:E,onEditEntity:C,onOpenAi:O,theme:M}){const T=`dql-model-layout:${d??r??"all"}`,re=`${T}:sizes`,[be,de]=a.useState(()=>Wn(T)),[k,D]=a.useState(()=>Hn(re));a.useEffect(()=>de(Wn(T)),[T]),a.useEffect(()=>D(Hn(re)),[re]),a.useEffect(()=>{v&&(localStorage.removeItem(T),localStorage.removeItem(re),de({}),D({}))},[v]);const[A,F]=a.useState(null),[U,V]=a.useState(null),K=(R,oe)=>{const me={...k,[R]:Math.round(oe)};D(me),localStorage.setItem(re,JSON.stringify(me))},{nodes:ie,edges:ce}=a.useMemo(()=>ks(t,o,i,r,d,h,y,l,u,m,f,c,x,I,be,k,N,K,M,n,s),[t,o,i,r,d,h,y,l,u,m,f,c,x,I,be,k,N,M,n,s]),[De,ge,_e]=es(ie);a.useEffect(()=>ge(ie),[ie,ge]);const we=ie.map(R=>R.data.entity.dbtUniqueId),je=we.join("|");if(a.useEffect(()=>B(we),[B,je]),!ie.length)return e.jsxs("div",{style:{display:"flex",flexDirection:"column",placeItems:"center",justifyContent:"center",alignItems:"center",gap:12,height:"100%",color:M.textMuted},children:[e.jsx("strong",{style:{color:M.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:E,style:Kn(M),children:[e.jsx(et,{size:13})," Create domain"]}),e.jsxs("button",{onClick:j,style:Kn(M,!0),children:[e.jsx(Ot,{size:13})," Bind first model"]})]})]})]});const H=R=>{!R.source||!R.target||q({from:R.source,to:R.target,fromColumn:Un(R.sourceHandle),toColumn:Un(R.targetHandle)})},Ce=U?t.relationships[U.recordKey]:void 0;return e.jsxs("div",{style:{height:"100%",position:"relative"},onClick:()=>{F(null),V(null)},children:[e.jsx("style",{children:Ds}),e.jsxs(ts,{nodes:De,edges:ce,onNodesChange:_e,nodeTypes:{entity:ws},fitView:!0,fitViewOptions:{padding:.16},minZoom:.2,maxZoom:1.8,nodesDraggable:!0,nodesConnectable:!0,onConnect:H,onNodeDragStop:(R,oe)=>{const me={...be,[oe.id]:oe.position};de(me),localStorage.setItem(T,JSON.stringify(me))},onNodeClick:(R,oe)=>b(oe.id),onNodeDoubleClick:(R,oe)=>C(oe.id),onNodeContextMenu:(R,oe)=>{R.preventDefault(),F({x:R.clientX,y:R.clientY,nodeId:oe.id})},onEdgeClick:(R,oe)=>{R.stopPropagation(),S(oe.id),V({x:Math.min(R.clientX,window.innerWidth-340),y:Math.min(R.clientY,window.innerHeight-320),recordKey:oe.id})},colorMode:M.appBg.toLowerCase().includes("0")?"dark":"light",proOptions:{hideAttribution:!0},children:[e.jsx(Is,{focusRequest:w}),e.jsx(ns,{color:"var(--border-strong)",gap:22,size:1}),e.jsx(os,{showInteractive:!1}),e.jsx(ss,{pannable:!0,zoomable:!0,nodeColor:R=>uo(String(R.data.entity.domain)),maskColor:`${M.appBg}bb`})]},`${m}:${f}:${c}:${v}:${u}`),A&&e.jsxs("div",{style:{position:"fixed",left:A.x,top:A.y,zIndex:50,width:178,border:`1px solid ${M.headerBorder}`,borderRadius:7,background:M.cellBg,boxShadow:"0 12px 32px #0004",padding:4},onClick:R=>R.stopPropagation(),children:[e.jsx(At,{label:"Inspect entity",onClick:()=>{b(A.nodeId),F(null)},theme:M}),e.jsx(At,{label:"Edit Domain Model binding",onClick:()=>{C(A.nodeId),F(null)},theme:M}),e.jsx(At,{label:"Ask AI about entity",onClick:()=>{O(A.nodeId),F(null)},theme:M}),e.jsx(At,{label:"Start relationship",onClick:()=>{q({from:A.nodeId,to:""}),F(null)},theme:M})]}),U&&Ce&&e.jsx(Ss,{relationship:Ce,entities:t.entities,x:U.x,y:U.y,theme:M,onClose:()=>V(null),onEdit:P?()=>{P(U.recordKey),V(null)}:void 0,onViewProof:()=>{S(U.recordKey),V(null)}})]})}function Ss({relationship:t,entities:n,x:s,y:o,theme:i,onClose:r,onEdit:d,onViewProof:h}){var f,c;const y=((f=t.validation)==null?void 0:f.status)==="passed",l=t.keys.map(x=>`${x.from} = ${x.to}`).join(" and ")||"No join keys declared",u=x=>{const I=n[x]??Object.values(n).find(v=>v.id===x||v.localId===x);return(I==null?void 0:I.businessName)||(I==null?void 0:I.localId)||x.split("::").pop()||x},m=x=>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:x});return e.jsxs("div",{onClick:x=>x.stopPropagation(),style:{position:"fixed",left:s,top:o,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(Ot,{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 ${y?"var(--status-success-border)":"var(--status-warning-border)"}`,color:y?"var(--status-success)":"var(--status-warning)",background:y?"var(--status-success-bg)":"var(--status-warning-bg)",borderRadius:999,padding:"2px 8px",fontSize:9.5,fontWeight:700},children:y?"Proven":"Unproven"}),e.jsx("button",{type:"button",onClick:r,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:[m(u(t.from)),e.jsx("span",{style:{color:i.textMuted,fontSize:10.5,fontWeight:650,whiteSpace:"nowrap"},children:t.cardinality.replace(/_/g," ")}),m(u(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:l})]}),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:y?"var(--status-success)":"var(--status-warning)"},children:y?`Join proof passed — ${((c=t.validation)==null?void 0:c.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:[d?e.jsx("button",{type:"button",onClick:d,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:h,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 ws({data:t}){var q,N;const{recordKey:n,entity:s,detail:o,relation:i,selected:r,viewMode:d,columnMode:h,density:y,theme:l,onAddRelatedModel:u,onResize:m}=t,[f,c]=a.useState(y==="compact"),x=uo(s.domain),I=oo(s.analyticalRole),v=s.analyticalRole&&s.analyticalRole!=="unknown"?s.analyticalRole:"entity",w=(o==null?void 0:o.columns)??[],B=new Set(s.keys.length?s.keys:((q=o==null?void 0:o.dqlMeta)==null?void 0:q.keys)??[]),b=new Set(w.filter(j=>!B.has(j.name)&&/(^|_)id$/.test(j.name)).map(j=>j.name)),S=f||d==="business"?[]:h==="all"?w.slice(0,16):h==="keys"?w.filter(j=>B.has(j.name)).slice(0,10):w.filter(j=>B.has(j.name)||j.tests.length>0).slice(0,10),P=(N=s.conceptRefs)!=null&&N.length?s.conceptRefs.join(", "):en(s.localId??s.id);return e.jsxs("div",{style:{position:"relative",width:"100%",minWidth:236,borderRadius:10,overflow:"visible",border:`1.5px solid ${r?"var(--accent)":"var(--border-default)"}`,boxShadow:r?"0 1px 6px rgba(107,93,211,0.14)":"0 1px 4px rgba(26,26,26,0.05)",background:l.cellBg,color:l.textPrimary},children:[e.jsx(as,{position:"bottom-right",resizeDirection:"horizontal",minWidth:240,maxWidth:620,onResizeEnd:(j,E)=>m(n,E.width),style:{width:16,height:16,border:0,background:"transparent",color:l.textMuted},children:e.jsx("span",{title:"Drag to resize model",style:{display:"grid",placeItems:"center"},children:e.jsx(co,{size:12})})}),f&&d==="data"&&e.jsx(ft,{className:"dql-modeling-handle",id:"entity-target",type:"target",position:yt.Left,style:bt(x)}),e.jsx("button",{className:"nodrag",title:"Add a related model",onClick:j=>{j.stopPropagation(),u({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 ${l.cellBg}`,background:"var(--accent)",color:"#fff",cursor:"pointer",boxShadow:"0 1px 4px rgba(107,93,211,0.3)"},children:e.jsx(et,{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:I,flexShrink:0}}),e.jsx("span",{style:{flex:1,minWidth:0,fontSize:12.5,fontWeight:700,color:l.textPrimary,fontFamily:l.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d==="business"?s.businessName||en(s.localId??s.id):s.localId??s.id}),e.jsx("span",{style:{flexShrink:0,fontSize:9,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em",color:I},children:v}),d==="data"&&e.jsx("button",{className:"nodrag",title:f?"Expand columns":"Collapse columns",onClick:j=>{j.stopPropagation(),c(E=>!E)},style:{border:0,background:"transparent",color:l.textMuted,cursor:"pointer",padding:0,flexShrink:0},children:f?"▾":"▴"})]}),d==="business"?e.jsxs(e.Fragment,{children:[e.jsx("div",{title:s.businessContext,style:{padding:"9px 12px 7px",fontSize:11.5,lineHeight:1.5,color:l.textSecondary,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},children:s.businessContext||P}),e.jsxs("div",{style:{display:"flex",gap:6,padding:"0 12px 10px",flexWrap:"wrap"},children:[s.owner?e.jsx("span",{style:{fontSize:10,color:l.textMuted,border:"1px solid var(--border-subtle)",background:"var(--bg-1)",borderRadius:999,padding:"2px 7px"},children:s.owner}):null,e.jsx("span",{style:{fontSize:10,color:l.textMuted,border:"1px solid var(--border-subtle)",background:"var(--bg-1)",borderRadius:999,padding:"2px 7px"},children:s.grain?`1 row = ${s.grain}`:s.domain})]})]}):null,S.length>0&&e.jsxs("div",{style:{borderTop:"1px solid var(--border-subtle)",maxHeight:242,overflow:"auto"},children:[S.map(j=>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(ft,{className:"dql-modeling-handle",id:`target:${j.name}`,type:"target",position:yt.Left,style:{...bt(x),top:"50%"}}),e.jsx("span",{style:{flexShrink:0,width:17,fontSize:8.5,fontWeight:700,fontFamily:l.fontMono,color:B.has(j.name)?"var(--pk)":b.has(j.name)?"var(--fk)":"transparent"},children:B.has(j.name)?"PK":b.has(j.name)?"FK":"·"}),e.jsx("span",{style:{flex:1,minWidth:0,color:l.textSecondary,fontFamily:l.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:B.has(j.name)?700:500},children:j.name}),e.jsx("span",{style:{flexShrink:0,fontSize:9.5,color:l.textMuted,fontFamily:l.fontMono},children:j.type??""}),e.jsx(ft,{className:"dql-modeling-handle",id:`source:${j.name}`,type:"source",position:yt.Right,style:{...bt(x),top:"50%"}})]},j.name)),w.length>S.length&&e.jsxs("div",{style:{padding:"6px 12px",color:l.textMuted,fontSize:9},children:["+ ",w.length-S.length," more dbt-owned columns"]})]}),(f||d==="business")&&e.jsxs(e.Fragment,{children:[e.jsx(ft,{className:"dql-modeling-handle",id:"entity-target",type:"target",position:yt.Left,style:bt(x)}),e.jsx(ft,{className:"dql-modeling-handle",id:"entity-source",type:"source",position:yt.Right,style:bt(x)})]})]})}function ks(t,n,s,o,i,r,d,h,y,l,u,m,f,c,x,I,v,w,B,b,S){const P=i?t.areas[i]:void 0,q=new Set(P?[...P.entityIds,...P.referencedEntityIds]:[]),N=Object.entries(t.relationships).flatMap(([k,D])=>{const A=qn(t,D.from),F=qn(t,D.to);return A&&F?[{recordKey:k,relationship:D,from:A,to:F}]:[]}).filter(({recordKey:k,from:D,to:A})=>{var F,U;return P?P.relationshipIds.includes(k):o?((F=t.entities[D])==null?void 0:F.domain)===o||((U=t.entities[A])==null?void 0:U.domain)===o:!0}),j=new Set(N.flatMap(({from:k,to:D})=>[k,D])),E=y.trim().toLowerCase();let C=Lo(t).filter(({recordKey:k,entity:D})=>{if(P&&!q.has(k)&&!j.has(k)||o&&D.domain!==o&&!j.has(k))return!1;if(!E)return!0;const A=s[D.dbtUniqueId];return[k,D.id,D.qualifiedId,D.domain,A==null?void 0:A.relation,...(A==null?void 0:A.columns.map(F=>F.name))??[]].some(F=>String(F??"").toLowerCase().includes(E))});const O=Math.min(200,m>0?m:50);if(C.length>O){const k=new Map;for(const D of N)k.set(D.from,(k.get(D.from)??0)+1),k.set(D.to,(k.get(D.to)??0)+1);C=[...C].sort((D,A)=>D.recordKey===r?-1:A.recordKey===r?1:(k.get(A.recordKey)??0)-(k.get(D.recordKey)??0)||D.recordKey.localeCompare(A.recordKey)).slice(0,O)}const M=[...new Set(C.map(({entity:k})=>k.domain))].sort(),T=[];M.forEach((k,D)=>C.filter(({entity:A})=>A.domain===k).sort((A,F)=>A.recordKey.localeCompare(F.recordKey)).forEach(({recordKey:A,entity:F},U)=>{const V=s[F.dbtUniqueId],K=d==="business"?0:Ms(F,V,h),ie=I[A]??zs(F,V,n[F.dbtUniqueId],u);T.push({id:A,type:"entity",position:{x:D*390,y:U*190},data:{recordKey:A,entity:F,detail:V,relation:n[F.dbtUniqueId],selected:r===A,viewMode:d,columnMode:h,density:u,theme:B,onAddRelatedModel:v,onResize:w},style:{width:ie,height:116+K*29,...b!=null&&b.has(A)?{outline:"2px dashed var(--accent)",outlineOffset:2,opacity:.9,borderRadius:12}:{}}})}));const re=new Set(T.map(k=>k.id)),be=N.filter(({from:k,to:D})=>re.has(k)&&re.has(D)).map(({recordKey:k,relationship:D,from:A,to:F})=>{var H,Ce;const U=((H=D.validation)==null?void 0:H.status)==="passed";D.automaticJoinAllowed||D.staleCertification;const V=D.keys.map(R=>`${R.from} → ${R.to}`).join(", "),K=D.keys[0],ie=t.entities[A],ce=t.entities[F],De=ie?Xt(ie,s[ie.dbtUniqueId],h):new Set,ge=ce?Xt(ce,s[ce.dbtUniqueId],h):new Set,we=((Ce=D.verb)==null?void 0:Ce.trim())||V,je=(S==null?void 0:S.has(k))??!1;return{id:k,source:A,target:F,sourceHandle:d==="data"&&K&&De.has(K.from)?`source:${K.from}`:void 0,targetHandle:d==="data"&&K&&ge.has(K.to)?`target:${K.to}`:void 0,type:"default",label:c?`${we} · ${Cs(D.cardinality)}${je?" · proposed":""}`:void 0,animated:je||D.status==="review"||D.status==="reviewed",markerEnd:{type:is.ArrowClosed,color:je||r===k?"var(--accent)":"var(--border-strong)"},style:{stroke:je||r===k?"var(--accent)":"var(--border-strong)",strokeWidth:r===k?2:1.5,cursor:"pointer",...je?{strokeDasharray:"6 4",opacity:.85}:{}},labelStyle:{fill:r===k?"var(--accent)":B.textSecondary,fontSize:10.5,fontWeight:650,cursor:"pointer"},labelBgStyle:{fill:B.cellBg,fillOpacity:1,stroke:r===k?"var(--accent)":B.headerBorder,strokeWidth:1},labelBgPadding:[9,4],labelBgBorderRadius:999}}),de=new Fn.graphlib.Graph().setDefaultEdgeLabel(()=>({}));if(de.setGraph({rankdir:"LR",ranksep:u==="compact"?90:u==="wide"?190:135,nodesep:u==="compact"?35:u==="wide"?90:60,marginx:35,marginy:35}),T.forEach(k=>{var D,A;return de.setNode(k.id,{width:Number(((D=k.style)==null?void 0:D.width)??Zt(u)),height:Number(((A=k.style)==null?void 0:A.height)??100)})}),be.forEach(k=>de.setEdge(k.source,k.target)),l==="auto"&&Fn.layout(de),T.forEach(k=>{var F,U;const D=x[k.id];if(D){k.position=D;return}if(l==="grid"){const V=T.indexOf(k),K=Math.max(1,Math.ceil(Math.sqrt(T.length)));k.position={x:V%K*360,y:Math.floor(V/K)*260};return}if(l==="star"){const V=T.indexOf(k);if(V===0){k.position={x:0,y:0};return}const K=(V-1)/Math.max(1,T.length-1)*Math.PI*2;k.position={x:Math.cos(K)*460,y:Math.sin(K)*330};return}const A=de.node(k.id);A&&(k.position={x:A.x-Number(((F=k.style)==null?void 0:F.width)??Zt(u))/2,y:A.y-Number(((U=k.style)==null?void 0:U.height)??100)/2})}),f&&r&&t.entities[r]){const k=new Set([r]);for(const D of N)D.from===r&&k.add(D.to),D.to===r&&k.add(D.from);for(const D of T)D.style={...D.style,opacity:k.has(D.id)?1:.18,transition:"opacity 160ms ease"}}return{nodes:T,edges:be}}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 Is({focusRequest:t}){const n=ls(),s=a.useRef(-1);return a.useEffect(()=>{if(!t||t.token===s.current)return;s.current=t.token;const o=window.setTimeout(()=>{var h,y,l,u;const i=n.getNode(t.id);if(!i)return;const r=Number(((h=i.measured)==null?void 0:h.width)??i.width??((y=i.style)==null?void 0:y.width)??280),d=Number(((l=i.measured)==null?void 0:l.height)??i.height??((u=i.style)==null?void 0:u.height)??120);n.setCenter(i.position.x+r/2,i.position.y+d/2,{zoom:Math.max(.85,n.getZoom()),duration:500})},60);return()=>window.clearTimeout(o)},[t,n]),null}function At({label:t,onClick:n,theme:s}){return e.jsx("button",{onClick:n,style:{width:"100%",textAlign:"left",border:0,borderRadius:4,padding:"7px 8px",background:"transparent",color:s.textPrimary,fontSize:11,cursor:"pointer"},children:t})}function Ms(t,n,s){return Xt(t,n,s).size}function Xt(t,n,s){var r;const o=(n==null?void 0:n.columns)??[];if(s==="all")return new Set(o.slice(0,16).map(d=>d.name));const i=new Set(t.keys.length?t.keys:((r=n==null?void 0:n.dqlMeta)==null?void 0:r.keys)??[]);return s==="keys"?new Set(o.filter(d=>i.has(d.name)).slice(0,10).map(d=>d.name)):new Set(o.filter(d=>i.has(d.name)||d.tests.length>0).slice(0,10).map(d=>d.name))}function Zt(t){return t==="compact"?250:t==="wide"?340:280}function zs(t,n,s,o){var r;const i=Math.max(en(t.localId??t.id).length,(s==null?void 0:s.length)??0,((r=n==null?void 0:n.description)==null?void 0:r.length)??0,...((n==null?void 0:n.columns)??[]).map(d=>d.name.length));return Math.min(o==="wide"?440:380,Zt(o)+Math.max(0,i-34)*2)}function Wn(t){try{const n=JSON.parse(localStorage.getItem(t)??"{}");return Object.fromEntries(Object.entries(n).filter(([,s])=>typeof s.x=="number"&&typeof s.y=="number"))}catch{return{}}}function Hn(t){try{const n=JSON.parse(localStorage.getItem(t)??"{}");return Object.fromEntries(Object.entries(n).filter(([,s])=>typeof s=="number"&&s>=240&&s<=620))}catch{return{}}}function Un(t){return t!=null&&t.includes(":")?t.slice(t.indexOf(":")+1):void 0}function bt(t){return{background:t,border:"2px solid var(--color-bg-card)",width:9,height:9,cursor:"crosshair"}}const Ds=`
|
|
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 en(t){return t.replace(/[._-]+/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function uo(t){const n=["#6d5ce7","#2e9b63","#d47822","#377cc8","#bd4f8b","#8a6d3b"];let s=0;for(const o of t)s=(s<<5)-s+o.charCodeAt(0)|0;return n[Math.abs(s)%n.length]}const $s=so;function po(t,n,s){var f;const o=t.modeling.areas[s??""],i=Object.keys(t.modeling.packages??{}),r=n??(i.length===1?i[0]:xo(((f=t.dbtProvenance)==null?void 0:f.projectName)??"").replace(/-/g,"_")||"analytics"),[d,h]=a.useState(r),[y,l]=a.useState((o==null?void 0:o.localId)??(o==null?void 0:o.id)??$s),u=!i.includes(d),m=!Object.values(t.modeling.areas??{}).some(c=>c.domain===d&&(c.localId===y||c.id===y));return{scopeDomain:d,setScopeDomain:h,scopeArea:y,setScopeArea:l,domains:i,domainIsNew:u,areaIsNew:m}}function ho({scope:t,theme:n}){return e.jsxs(e.Fragment,{children:[e.jsxs("label",{style:_t(n),children:["Domain",e.jsx("input",{"aria-label":"Domain",list:"dql-scope-domains",value:t.scopeDomain,onChange:s=>t.setScopeDomain(s.target.value),style:St(n)}),e.jsx("datalist",{id:"dql-scope-domains",children:t.domains.map(s=>e.jsx("option",{value:s},s))}),e.jsx("small",{style:{color:t.domainIsNew?"var(--status-warning)":n.textMuted},children:t.domainIsNew?"Will be created with these models.":"Existing Domain."})]}),e.jsxs("label",{style:_t(n),children:["Subject area",e.jsx("input",{"aria-label":"Subject area",value:t.scopeArea,onChange:s=>t.setScopeArea(s.target.value),style:St(n)}),e.jsxs("small",{style:{color:t.areaIsNew?"var(--status-warning)":n.textMuted},children:[t.areaIsNew?"Will be created with these models.":"Existing subject area."," A subject area is one focused diagram inside the Domain — it organizes source and sharpens retrieval, and never changes what an agent is allowed to use."]})]})]})}function Rs({data:t,domain:n,areaId:s,theme:o,onClose:i,onProposal:r}){const[d,h]=a.useState(""),[y,l]=a.useState([]),[u,m]=a.useState({}),[f,c]=a.useState([]),[x,I]=a.useState(1),[v,w]=a.useState(!1),[B,b]=a.useState(null),S=po(t,n,s);a.useEffect(()=>{let j=!0;const E=window.setTimeout(()=>{Z.getDbtModelInventory({q:d,limit:100,physicalOnly:!0}).then(C=>{if(!j)return;const O=C.items.filter(M=>!M.binding);l(O),m(M=>({...M,...Object.fromEntries(O.map(T=>[T.uniqueId,T]))}))}).catch(C=>{j&&b(C instanceof Error?C.message:String(C))})},180);return()=>{j=!1,window.clearTimeout(E)}},[d]);const P=f.flatMap(j=>u[j]?[u[j]]:[]),q=a.useMemo(()=>As(t,S.scopeDomain,S.scopeArea,P),[t,S.scopeArea,S.scopeDomain,P]),N=async()=>{var j;w(!0),b(null);try{const E=await Z.createContextProposal({origin:"dbt_discovery",expectedSnapshotId:(j=t.snapshot)==null?void 0:j.id,operations:q});r(E)}catch(E){b(E instanceof Error?E.message:String(E))}finally{w(!1)}};return e.jsxs(go,{title:"Add models",subtitle:`Step ${x} of 3 · ${x===1?"Select dbt models":x===2?"Assign ownership":"Review proposal inputs"}`,theme:o,busy:v,onClose:i,children:[x===1?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{position:"relative"},children:[e.jsx(Ft,{size:14,style:{position:"absolute",left:10,top:10,color:o.textMuted}}),e.jsx("input",{autoFocus:!0,"aria-label":"Search dbt models",value:d,onChange:j=>h(j.target.value),placeholder:"Search model name, package, or relation",style:{...St(o),width:"100%",paddingLeft:32}})]}),e.jsxs("div",{style:{display:"grid",gap:6,marginTop:12},children:[y.map(j=>e.jsxs("label",{style:Et(o),children:[e.jsx("input",{type:"checkbox",checked:f.includes(j.uniqueId),onChange:E=>c(C=>E.target.checked?[...C,j.uniqueId]:C.filter(O=>O!==j.uniqueId))}),e.jsxs("span",{style:{flex:1},children:[e.jsx("b",{style:{display:"block",fontSize:11.5},children:j.name}),e.jsx("code",{style:{color:o.textMuted,fontSize:9.5},children:j.uniqueId})]}),e.jsx("small",{style:{color:o.textMuted},children:j.packageName})]},j.uniqueId)),y.length?null:e.jsx(vt,{theme:o,children:"No unbound dbt models match this search."})]})]}):x===2?e.jsxs(e.Fragment,{children:[e.jsx(ho,{scope:S,theme:o}),e.jsx(vt,{theme:o,children:"Every model receives exactly one Domain and subject area. DQL stores the dbt unique ID and business overlay; dbt-owned columns, SQL, tests, descriptions, and lineage remain in dbt."})]}):e.jsxs(e.Fragment,{children:[e.jsxs(vt,{theme:o,children:[q.length," sparse entity-binding patch",q.length===1?"":"es"," will be prepared. No source changes occur until the exact proposal is reviewed and explicitly saved."]}),P.map(j=>e.jsxs("div",{style:Et(o),children:[e.jsxs("span",{style:{flex:1},children:[e.jsx("b",{style:{display:"block",fontSize:11},children:j.name}),e.jsx("code",{style:{fontSize:9.5,color:o.textMuted},children:j.uniqueId})]}),e.jsxs("span",{style:{fontSize:10,color:o.textMuted},children:[S.scopeDomain," / ",S.scopeArea]})]},j.uniqueId))]}),B?e.jsx("div",{role:"alert",style:{color:"var(--status-error)",fontSize:11,marginTop:10},children:B}):null,e.jsx(tn,{theme:o,busy:v,back:x>1?()=>I(x-1):void 0,next:x<3?()=>I(x+1):()=>void N(),nextLabel:x<3?"Continue":"Create review proposal",disabled:f.length===0||!S.scopeDomain.trim()||!S.scopeArea.trim()})]})}function Bs({data:t,domain:n,areaId:s,theme:o,onClose:i,onProposal:r}){const[d,h]=a.useState("current_project"),[y,l]=a.useState(""),[u,m]=a.useState(""),[f,c]=a.useState("modeling.yml"),[x,I]=a.useState(null),[v,w]=a.useState([]),[B,b]=a.useState(!1),[S,P]=a.useState(null),q=po(t,n,s),N=async()=>{b(!0),P(null);try{const C=await Z.createModelingImport({mode:d,...d==="path"?{path:y}:{},...d==="paste"||d==="upload"?{content:u,filename:f}:{}});I(C),w(C.candidates.filter(O=>O.action==="import").map(O=>O.id))}catch(C){P(C instanceof Error?C.message:String(C))}finally{b(!1)}},j=async()=>{var C;if(x){b(!0),P(null);try{const O=await Z.previewModelingImport(x.id,{selectedCandidateIds:v,domain:q.scopeDomain,areaId:q.scopeArea,expectedSnapshotId:((C=t.snapshot)==null?void 0:C.id)??""});r(O.proposal)}catch(O){P(O instanceof Error?O.message:String(O))}finally{b(!1)}}},E=C=>{if(!C)return;c(C.name);const O=new FileReader;O.onload=()=>m(String(O.result??"")),O.onerror=()=>P("Could not read the selected YAML file."),O.readAsText(C)};return e.jsxs(go,{title:"Import modeling YAML",subtitle:x?"Classify, select, and review":"Choose a safe import source",theme:o,busy:B,onClose:i,children:[x?e.jsxs(e.Fragment,{children:[e.jsxs(vt,{theme:o,children:[e.jsx(an,{size:13,style:{verticalAlign:-2,marginRight:5}}),"DQL modeling becomes a reviewed copy; dbt YAML becomes a sparse overlay. Generic YAML is not imported."]}),e.jsx("div",{style:{display:"grid",gap:7},children:x.candidates.map(C=>e.jsxs("label",{style:{...Et(o),opacity:C.action==="import"?1:.72},children:[e.jsx("input",{type:"checkbox",disabled:C.action!=="import",checked:v.includes(C.id),onChange:O=>w(M=>O.target.checked?[...M,C.id]:M.filter(T=>T!==C.id))}),e.jsxs("span",{style:{flex:1},children:[e.jsx("b",{style:{display:"block",fontSize:11},children:C.name}),e.jsxs("span",{style:{display:"block",marginTop:2,color:o.textMuted,fontSize:9.5},children:[C.dialect.replace(/_/g," ")," · ",C.summary]}),C.warnings.map(O=>e.jsx("small",{style:{display:"block",color:"var(--status-warning)",marginTop:3},children:O},O))]}),e.jsx("span",{style:{fontSize:9.5,color:o.textMuted},children:C.action.replace(/_/g," ")})]},C.id))}),e.jsx(ho,{scope:q,theme:o}),e.jsx(tn,{theme:o,busy:B,back:()=>{I(null),w([])},next:()=>void j(),nextLabel:"Review exact patches",disabled:!v.length||!q.scopeDomain.trim()||!q.scopeArea.trim()})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, 1fr)",gap:6},children:["current_project","path","upload","paste"].map(C=>e.jsx("button",{type:"button",onClick:()=>h(C),style:{...Ut(o),...d===C?{borderColor:o.accent,color:o.accent,background:"var(--accent-dim)"}:{}},children:C==="current_project"?"Project":C[0].toUpperCase()+C.slice(1)},C))}),d==="current_project"?e.jsxs(vt,{theme:o,children:[e.jsx(No,{size:13,style:{verticalAlign:-2,marginRight:5}}),"Search the current project for DQL and dbt YAML. Existing DQL source opens in place and is not copied."]}):null,d==="path"?e.jsxs("label",{style:_t(o),children:["Local file or directory",e.jsx("input",{"aria-label":"Local YAML path",value:y,onChange:C=>l(C.target.value),placeholder:"models or domains/sales",style:St(o)}),e.jsx("small",{children:"Loopback-only and confined to the current approved project root."})]}):null,d==="upload"?e.jsxs("label",{style:{...Et(o),marginTop:12},children:[e.jsx(cs,{size:15}),e.jsx("span",{style:{flex:1},children:"Choose a YAML file"}),e.jsx("input",{type:"file",accept:".yml,.yaml,text/yaml",onChange:C=>{var O;return E((O=C.target.files)==null?void 0:O[0])}})]}):null,d==="paste"?e.jsxs("label",{style:_t(o),children:["Paste DQL or dbt YAML",e.jsx("textarea",{"aria-label":"Paste modeling YAML",value:u,onChange:C=>m(C.target.value),rows:14,style:{...St(o),resize:"vertical",fontFamily:o.fontMono}})]}):null,e.jsx(tn,{theme:o,busy:B,next:()=>void N(),nextLabel:"Discover YAML",disabled:d==="path"&&!y.trim()||(d==="paste"||d==="upload")&&!u.trim()})]}),S?e.jsx("div",{role:"alert",style:{color:"var(--status-error)",fontSize:11,marginTop:10},children:S}):null]})}function As(t,n,s,o){if(!n.trim()||!s.trim())return[];const i=new Set(Object.values(t.modeling.entities).filter(r=>r.domain===n).map(r=>r.localId||r.id));return[...o].sort((r,d)=>r.uniqueId.localeCompare(d.uniqueId)).map(r=>{const d=xo(r.name)||"model";let h=d;i.has(h)&&(h=`${d}-${r.identityFingerprint.slice(0,6).toLowerCase()}`);let y=2;for(;i.has(h);)h=`${d}-${y++}`;return i.add(h),{id:`bind:${r.uniqueId}`,kind:"modeling_change",change:{operation:"upsert_entity",value:{id:h,domain:n,areaId:s,dbtModel:r.uniqueId,businessName:Ps(r.name),status:"draft"}},evidence:[`dbt unique id ${r.uniqueId}`,`manifest fingerprint ${r.identityFingerprint}`]}})}function xo(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,64)}function Ps(t){return t.replace(/[_-]+/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function go({title:t,subtitle:n,theme:s,busy:o,onClose:i,children:r}){return e.jsx("div",{onClick:()=>!o&&i(),style:{position:"fixed",inset:0,zIndex:120,background:"rgba(8,10,16,.46)",display:"flex",justifyContent:"flex-end"},children:e.jsxs("aside",{role:"dialog","aria-modal":"true","aria-label":t,onClick:d=>d.stopPropagation(),style:{width:"min(600px, 96vw)",height:"100%",background:s.appBg,borderLeft:"1px solid var(--border-default)",boxShadow:"-16px 0 45px rgba(0,0,0,.22)",display:"flex",flexDirection:"column"},children:[e.jsxs("header",{style:{minHeight:58,padding:"0 18px",borderBottom:"1px solid var(--border-subtle)",display:"flex",alignItems:"center",gap:9},children:[e.jsxs("div",{style:{flex:1},children:[e.jsx("b",{style:{display:"block",fontSize:14},children:t}),e.jsx("small",{style:{color:s.textMuted},children:n})]}),e.jsx("button",{"aria-label":"Close",disabled:o,onClick:i,style:{...Ut(s),width:30,padding:0},children:e.jsx(us,{size:14})})]}),e.jsx("div",{style:{flex:1,minHeight:0,overflow:"auto",padding:18},children:r})]})})}function tn({theme:t,busy:n,back:s,next:o,nextLabel:i,disabled:r=!1}){return e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[s?e.jsx("button",{type:"button",onClick:s,disabled:n,style:Ut(t),children:"Back"}):null,e.jsxs("button",{type:"button",onClick:o,disabled:n||r,style:{...Ls(t),opacity:n||r?.55:1},children:[n?e.jsx(Oo,{size:13}):null,i]})]})}function vt({theme:t,children:n}){return e.jsx("div",{style:{margin:"12px 0",padding:"10px 11px",border:"1px solid var(--border-subtle)",borderRadius:8,background:"var(--bg-1)",color:t.textSecondary,fontSize:10.5,lineHeight:1.5},children:n})}const St=t=>({boxSizing:"border-box",border:"1px solid var(--border-default)",background:t.inputBg,color:t.textPrimary,borderRadius:7,padding:"8px 9px",outline:"none"}),_t=t=>({display:"grid",gap:6,marginTop:12,color:t.textSecondary,fontSize:11}),Et=t=>({display:"flex",gap:9,alignItems:"center",border:"1px solid var(--border-subtle)",borderRadius:8,background:t.cellBg,padding:"9px 10px"}),Ut=t=>({minHeight:31,border:"1px solid var(--border-default)",borderRadius:7,background:t.cellBg,color:t.textPrimary,padding:"0 11px",cursor:"pointer",display:"inline-flex",gap:6,alignItems:"center",justifyContent:"center"}),Ls=t=>({...Ut(t),background:t.accent,borderColor:t.accent,color:"var(--accent-fg)",fontWeight:650});function Ns(t){return t instanceof Error?t:void 0}function Os(t){return t.details&&typeof t.details=="object"&&!Array.isArray(t.details)?t.details:void 0}function Yn(t){const n=Ns(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 o=Os(n),i=typeof(o==null?void 0:o.manifestPath)=="string"&&o.manifestPath.trim()?o.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 jt(t){return t.toLowerCase().replace(/[^a-z0-9]+/g," ").trim()}function _s(t,n,s=50){const o=jt(n),i=o.split(/\s+/).filter(Boolean);return t.map(r=>{var f;const d=jt(r.label),h=jt(r.value),y=jt(r.description??""),l=jt(((f=r.keywords)==null?void 0:f.join(" "))??""),u=`${d} ${h} ${y} ${l}`;if(i.length&&!i.every(c=>u.includes(c)))return null;let m=0;return o&&((d===o||h===o)&&(m+=1e3),d.startsWith(o)&&(m+=500),h.startsWith(o)&&(m+=350),d.includes(o)&&(m+=200),m+=i.reduce((c,x)=>c+(d.startsWith(x)?80:d.includes(x)?40:10),0)),{option:r,score:m}}).filter(r=>!!r).sort((r,d)=>d.score-r.score||r.option.label.localeCompare(d.option.label)||r.option.value.localeCompare(d.option.value)).slice(0,Math.max(1,s)).map(({option:r})=>r)}function Ri(){var pt,ht;const{state:t,dispatch:n}=Wt(),s=_o[t.themeMode],[o,i]=a.useState(null),[r,d]=a.useState(!0),[h,y]=a.useState(null),l=a.useMemo(()=>Vn(),[]),[u,m]=a.useState(l.section),[f,c]=a.useState(l.domain),[x,I]=a.useState(l.modelAreaId),[v,w]=a.useState(l.selectedId),[B,b]=a.useState(null),[S,P]=a.useState({}),q=a.useRef(new Map),N=a.useRef(new Set),j=a.useMemo(()=>to(),[]),[E,C]=a.useState(j.viewMode??"business"),[O,M]=a.useState(j.columnMode??"relevant"),[T,re]=a.useState(""),[be,de]=a.useState(0),[k,D]=a.useState(null),[A,F]=a.useState(j.layoutMode??"auto"),[U,V]=a.useState(j.density??"normal"),[K,ie]=a.useState(j.visibleLimit??50),[ce,De]=a.useState(j.dimUnrelated??!0),[ge,_e]=a.useState(j.showEdgeLabels??!0),[we,je]=a.useState(!1),[H,Ce]=a.useState(!1),[R,oe]=a.useState(!1),[me,Ee]=a.useState(()=>typeof window<"u"&&window.innerWidth<980),qe=a.useRef(null),wt=a.useRef(null),[ve,te]=a.useState(null),[ue,pe]=a.useState(null),[nt,ke]=a.useState(null),[$e,ot]=a.useState(()=>to().aiDockOpen===!0),[Te,Kt]=a.useState(null),[st,kt]=a.useState(null),[it,at]=a.useState(null),[Se,Fe]=a.useState(null),[Ct,It]=a.useState(!1),[lt,Re]=a.useState(null);a.useEffect(()=>{localStorage.setItem("dql-modeling-preferences",JSON.stringify({modelingView:E,columnMode:O,layoutMode:A,density:U,visibleLimit:K,dimUnrelated:ce,showEdgeLabels:ge,aiDockOpen:$e}))},[E,O,A,U,K,ce,ge,$e]),a.useEffect(()=>{const g=()=>Ee(window.innerWidth<980);return window.addEventListener("resize",g),()=>window.removeEventListener("resize",g)},[]);const We=a.useCallback(()=>{oe(g=>{const $=!g;return $?window.requestAnimationFrame(()=>{var G;return(G=wt.current)==null?void 0:G.focus()}):window.requestAnimationFrame(()=>{var G;return(G=qe.current)==null?void 0:G.focus()}),$})},[]),rt=a.useCallback(g=>{m(g),Pt(f,g,!1,x,v)},[x,f,v]),Mt=a.useCallback(g=>{c(g),I(null),w(null),Pt(g,u,!1,null,null)},[u]);a.useEffect(()=>{const g=()=>{const $=Vn();c($.domain),I($.modelAreaId),w($.selectedId),m($.section)};return window.addEventListener("popstate",g),()=>window.removeEventListener("popstate",g)},[]),a.useEffect(()=>{Pt(f,u,!0,x,v)},[x,f,v,u]);const Be=async()=>{d(!0);try{const g=await Z.getDbtFirstModeling();i(g),y(null);const $=f&&g.modeling.packages[f]?f:null;$!==f&&(c($),Pt($,u,!0))}catch(g){i(null),y(Yn(g))}finally{d(!1)}};a.useEffect(()=>{Be()},[]),a.useEffect(()=>{let g=null;try{g=window.sessionStorage.getItem("dql-context-proposal-handoff"),g&&window.sessionStorage.removeItem("dql-context-proposal-handoff")}catch{}g&&Z.getContextProposal(g).then($=>{ke($),m($.impact.skillChanges>0&&$.impact.modelingChanges===0?"skills":"diagram")}).catch(()=>{})},[]);const He=a.useMemo(()=>Ws((o==null?void 0:o.modeling)??{entities:{},relationships:{}},Te),[o==null?void 0:o.modeling,Te]),Q=o==null?void 0:o.modeling.entities[v??""],he=o==null?void 0:o.modeling.relationships[v??""],dt=a.useMemo(()=>o?Object.values(o.modeling.areas).filter(g=>!f||g.domain===f).sort((g,$)=>g.name.localeCompare($.name)):[],[o,f]),J=o==null?void 0:o.modeling.areas[x??""];a.useEffect(()=>{o&&x&&!dt.some(g=>g.qualifiedId===x)&&I(null)},[o,dt,x]);const Ue=a.useCallback(g=>{const $=q.current.get(g);if($)return $;if(N.current.has(g))return Promise.resolve(void 0);const G=Z.getDbtModelingNode(g).then(Ie=>(N.current.add(g),P(Je=>({...Je,[g]:Ie})),Ie)).catch(()=>{N.current.add(g)}).finally(()=>q.current.delete(g));return q.current.set(g,G),G},[]);a.useEffect(()=>{if(!Q){b(null);return}const g=S[Q.dbtUniqueId];if(g){b(g);return}let $=!1;return Ue(Q.dbtUniqueId).then(G=>{$||b(G??null)}),()=>{$=!0}},[S,Ue,Q==null?void 0:Q.dbtUniqueId]),a.useEffect(()=>{q.current.clear(),N.current.clear(),P({})},[o==null?void 0:o.dbtProvenance.manifestFingerprint]);const Ke=a.useCallback(g=>{for(const $ of g.slice(0,24))Ue($)},[Ue]);if(r&&!o)return e.jsx(Xn,{t:s,title:"Loading Domain Studio…",detail:"Compiling dbt provenance and the sparse DQL analytical overlay."});if(!o){const g=h??Yn(null);return e.jsx(Xn,{t:s,title:g.title,detail:g.detail,status:g.status})}const zt=Object.fromEntries(Object.values(o.dbtProvenance.nodes).map(g=>[g.uniqueId,g.relation])),Ye=Object.entries(o.modeling.entities).flatMap(([g,$])=>{var Je;const G=$.businessName||$.localId||$.id,Ie=[{recordKey:g,type:"model",label:G,sublabel:$.domain,role:$.analyticalRole}];for(const $t of((Je=S[$.dbtUniqueId])==null?void 0:Je.columns)??[])Ie.push({recordKey:g,type:"column",label:$t.name,sublabel:G,role:$.analyticalRole});return Ie}),Dt=g=>{w(g),re(""),D($=>({id:g,token:(($==null?void 0:$.token)??0)+1}))},Ae=J?new Set([...J.entityIds,...J.referencedEntityIds]):void 0,ct=io(o.modeling,f).filter(({recordKey:g})=>!Ae||Ae.has(g)),Pe=Object.values(o.modeling.relationships).filter(g=>{const $=o.modeling.entities[g.from],G=o.modeling.entities[g.to];return J?J.relationshipIds.includes(g.qualifiedId):!f||($==null?void 0:$.domain)===f||(G==null?void 0:G.domain)===f});Object.values(o.dbtProvenance.nodes).filter(g=>!Object.values(o.modeling.entities).some($=>$.dbtUniqueId===g.uniqueId));const ut=R&&u==="diagram",Ve=[...new Set(f?((ht=(pt=o.domainAssets)==null?void 0:pt[f])==null?void 0:ht.skills)??[]:Object.values(o.domainAssets??{}).flatMap(g=>g.skills??[]))].sort();return e.jsxs("div",{style:{flex:1,minHeight:0,display:"flex",flexDirection:"column",background:s.appBg,color:s.textPrimary},children:[e.jsx("header",{style:{minHeight:52,padding:"0 14px",borderBottom:`1px solid ${s.headerBorder}`,background:s.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(Ze,{size:16,color:s.accent}),e.jsx("h1",{style:{margin:0,fontSize:12,fontWeight:800,whiteSpace:"nowrap"},children:"Modeling workspace"}),e.jsx("span",{style:{color:s.textMuted,fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:f?`/${f}`:"/all domains"})]}),e.jsxs("div",{style:{display:"flex",gap:7},children:[f&&e.jsxs(se,{t:s,onClick:()=>{try{window.sessionStorage.setItem("dql-ask-domain-context",JSON.stringify({domain:f,modelAreaId:J==null?void 0:J.qualifiedId}))}catch{}n({type:"SET_MAIN_VIEW",view:"ask"})},children:[e.jsx(Eo,{size:14})," Ask"]}),e.jsxs(se,{t:s,onClick:()=>pe("yaml"),children:[e.jsx(an,{size:14})," Import YAML"]}),e.jsx(si,{t:s,title:"Recompile",onClick:()=>void Be(),children:e.jsx(qo,{size:15})})]})]})}),e.jsxs("div",{style:{flex:1,minHeight:0,display:"grid",gridTemplateColumns:ut&&!me?"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 ${s.headerBorder}`,overflow:"auto",background:s.appBg},children:[e.jsx(qs,{data:o,selectedDomain:f,onSelect:Mt,t:s}),e.jsx(Ts,{data:o,domain:f,active:u,onSelect:rt,t:s}),e.jsx("div",{style:{padding:"10px 12px",borderTop:`1px solid ${s.headerBorder}`,display:"flex",flexDirection:"column",gap:5,fontSize:10.5,color:s.textMuted,fontFamily:s.font},children:e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{style:{width:6,height:6,borderRadius:999,background:"var(--status-success)",flexShrink:0}}),"dbt synced · ",Object.keys(o.dbtProvenance.nodes).length," model",Object.keys(o.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 ${s.headerBorder}`,background:s.headerBg},children:[mo(u,14,s),e.jsx("strong",{style:{fontSize:11},children:Fs(u)}),e.jsx("span",{style:{width:1,height:15,background:s.headerBorder}}),e.jsx("span",{style:{color:s.textMuted,fontSize:10},children:f??"All domains"}),(u==="diagram"||u==="skills")&&f&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,marginLeft:5},children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:5,color:s.textMuted,fontSize:10},children:["Area",e.jsxs("select",{"aria-label":"Active subject area",value:x??"",onChange:g=>{I(g.target.value||null),w(null)},style:{...ye(s),minWidth:146,padding:"4px 6px"},children:[e.jsx("option",{value:"",children:"All domain"}),dt.map(g=>e.jsx("option",{value:g.qualifiedId,children:g.name},g.qualifiedId))]})]}),e.jsx("button",{"aria-label":"Add subject area",title:"Add subject area",onClick:()=>te({kind:"area"}),style:{...ze(s),width:27,height:27},children:e.jsx(et,{size:13})})]}),u==="diagram"&&e.jsx("button",{ref:qe,"aria-expanded":R,"aria-controls":"domain-studio-inspector","aria-label":R?"Hide inspector":"Show inspector",title:R?"Hide inspector":"Show inspector",onClick:We,style:{...ze(s),marginLeft:"auto"},children:R?e.jsx(js,{size:14}):e.jsx(ps,{size:14})})]}),e.jsxs("div",{style:{flex:1,minHeight:0},children:[u==="diagram"&&e.jsxs("div",{id:"dql-modeling-diagram",style:{height:"100%",display:"flex",flexDirection:"column",...H?{position:"fixed",inset:0,zIndex:90,background:s.appBg}:{}},children:[e.jsx(Ys,{modelingView:E,columnMode:O,search:T,layoutMode:A,density:U,visibleLimit:K,dimUnrelated:ce,showEdgeLabels:ge,showLegend:we,fullscreen:H,aiOpen:$e,onBindModel:()=>pe("models"),onRelationship:()=>te({kind:"relationship"}),onToggleAi:()=>ot(g=>!g),onModelingView:C,onColumnMode:M,onSearch:re,searchItems:Ye,onPickModel:Dt,onLayoutMode:F,onDensity:V,onVisibleLimit:ie,onDimUnrelated:De,onEdgeLabels:_e,onLegend:je,onFullscreen:()=>Ce(g=>!g),onExport:()=>Qs(),onReset:()=>de(g=>g+1),t:s}),J?e.jsxs("div",{style:{padding:"7px 14px",borderBottom:`1px solid ${s.headerBorder}`,background:"var(--accent-dim)",color:s.textSecondary,display:"flex",alignItems:"center",gap:8,fontSize:10.5},children:[e.jsx(Ze,{size:13,color:s.accent}),e.jsx("strong",{style:{color:s.textPrimary},children:J.name}),e.jsx("span",{children:J.description??"Focused business modeling area"}),e.jsxs("span",{style:{marginLeft:"auto",color:s.textMuted},children:[J.entityIds.length," model",J.entityIds.length===1?"":"s"," · ",J.intentExamples.length," example question",J.intentExamples.length===1?"":"s"]})]}):null,we&&e.jsx(Vs,{t:s}),e.jsxs("div",{style:{flex:1,minHeight:0,display:"flex"},children:[e.jsx("div",{style:{flex:1,minWidth:0},children:ct.length===0?e.jsx(Js,{t:s,connectedModels:Object.keys(o.dbtProvenance.nodes).length,onDbt:()=>pe("models"),onYaml:()=>pe("yaml"),onManual:()=>te({kind:"entity"})}):e.jsx(vs,{modeling:He.modeling,ghostEntityIds:He.ghostEntityIds,ghostRelationshipIds:He.ghostRelationshipIds,relationByDbtId:zt,detailsByDbtId:S,selectedDomain:f,selectedAreaId:x,selectedId:v,viewMode:E,columnMode:O,search:T,layoutMode:A,density:U,visibleLimit:K,dimUnrelated:ce,showEdgeLabels:ge,resetLayoutToken:be,focusRequest:k??void 0,onVisibleDbtIdsChange:Ke,onSelectEntity:w,onSelectRelationship:w,onEditRelationship:g=>{const $=o.modeling.relationships[g];$&&te({kind:"relationship",relationship:$})},onDraftRelationship:g=>te({kind:"relationship",draft:g}),onAddRelatedModel:g=>te({kind:"entity",relationshipFrom:g}),onAddModel:()=>pe("models"),onCreateDomain:()=>te({kind:"domain"}),onEditEntity:g=>{const $=o.modeling.entities[g];$&&te({kind:"entity",entity:$,dbtUniqueId:$.dbtUniqueId})},onOpenAi:g=>{w(g);try{window.sessionStorage.setItem("dql-ask-domain-context",JSON.stringify({domain:f,modelAreaId:J==null?void 0:J.qualifiedId,objectId:g}))}catch{}n({type:"SET_MAIN_VIEW",view:"ask"})},theme:s})}),$e&&e.jsx("aside",{"aria-label":"Modeling AI",style:{width:"clamp(320px, 30vw, 460px)",borderLeft:`1px solid ${s.headerBorder}`,background:s.appBg,display:"flex",flexDirection:"column",minHeight:0},children:e.jsx(Xs,{domain:f,areaId:x,selectedId:v,data:o,themeMode:t.themeMode,t:s,correction:st,onClose:()=>ot(!1),onCorrectionStarted:()=>kt(null),onReviewProposal:ke,onPreviewProposal:Kt,onOpenSkills:()=>rt("skills"),onDraftRelationship:()=>te({kind:"relationship",draft:Q&&v?{from:v,to:""}:void 0})})})]})]}),u==="skills"&&e.jsx(Xo,{embedded:!0,domainFilter:f,modelAreaFilter:x,sourcePathFilter:Ve}),u==="blocks"&&e.jsx(Gs,{data:o,domain:f,t:s}),u==="notebooks"&&e.jsx(Jn,{data:o,domain:f,kind:"notebooks",t:s}),u==="apps"&&e.jsx(Jn,{data:o,domain:f,kind:"apps",t:s})]})]}),ut&&e.jsxs("aside",{id:"domain-studio-inspector",ref:wt,role:"complementary","aria-label":"Domain Studio inspector",tabIndex:-1,onKeyDown:g=>{g.key==="Escape"&&We()},style:{borderLeft:`1px solid ${s.headerBorder}`,overflow:"auto",background:s.appBg,minWidth:0,...me?{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(ii,{t:s,children:"Inspector"}),Q?e.jsx(Zs,{entity:Q,detail:B,relationships:Pe,t:s,onEdit:()=>te({kind:"entity",entity:Q,dbtUniqueId:Q.dbtUniqueId}),onEditDbtSource:()=>at(Q),onSelectRelationship:g=>w(nn(o.modeling.relationships,g)),onDelete:()=>{Re(null),Fe({kind:"entity",id:Q.localId||Q.id,domain:Q.domain,areaId:Q.areaId,label:Q.businessName||Q.localId||Q.id})}}):he?e.jsx(ti,{relationship:he,t:s,onEdit:()=>te({kind:"relationship",relationship:he}),onDelete:()=>{Re(null),Fe({kind:"relationship",id:he.localId||he.id,domain:he.ownerDomain??he.qualifiedId.split("::")[0],areaId:he.areaId,label:he.localId||he.id})}}):e.jsx(ni,{data:o,domainEntities:ct.map(({entity:g})=>g),domainRelationships:Pe,t:s,onSelectRelationship:g=>w(nn(o.modeling.relationships,g))})]})]}),ue==="models"?e.jsx(Rs,{data:o,domain:f,areaId:x,theme:s,onClose:()=>pe(null),onProposal:g=>{pe(null),ke(g)}}):null,ue==="yaml"?e.jsx(Bs,{data:o,domain:f,areaId:x,theme:s,onClose:()=>pe(null),onProposal:g=>{pe(null),ke(g)}}):null,nt?e.jsx(Zo,{proposal:nt,theme:s,onClose:()=>ke(null),onCommitted:()=>{ke(null),Be()}}):null,ve&&e.jsx(Us,{editor:ve,data:o,selectedDomain:f,selectedArea:J,t:s,onClose:()=>te(null),onProposal:g=>{te(null),ke(g)},onFixWithAi:(g,$)=>{te(null),g&&w(g),rt("diagram"),ot(!0),kt({text:"Fix the failed relationship validation. Keep it draft, remove stale proof, and explain the corrected cardinality, fanout, or keys using the attached receipt.",nonce:Date.now(),evidence:$})},onApplied:async g=>{te(null),await Be(),ve.kind==="entity"&&ve.relationshipFrom&&g.operation==="upsert_entity"&&te({kind:"relationship",draft:{...ve.relationshipFrom,to:g.value.id}})}}),it&&B&&e.jsx(ei,{entity:it,detail:B,snapshotId:o.snapshotId,t:s,onClose:()=>at(null),onApplied:async()=>{at(null),await Be()}}),Se&&e.jsx(Es,{pending:Se,busy:Ct,error:lt,t:s,onCancel:()=>{Fe(null),Re(null)},onConfirm:async()=>{It(!0),Re(null);try{const g={operation:Se.kind==="entity"?"remove_entity":"remove_relationship",value:{id:Se.id,domain:Se.domain,...Se.areaId?{areaId:Se.areaId}:{}}},$=await Z.createContextProposal({origin:"manual",expectedSnapshotId:o.snapshotId,operations:[{id:`manual:${g.operation}:${Se.id}`,kind:"modeling_change",change:g,evidence:["manual Modeling workspace removal"]}]});if(!$.patches.some(G=>G.changed))throw new Error("Nothing to remove — it is no longer in the domain source.");Fe(null),w(null),ke($)}catch(g){Re(g instanceof Error?g.message:String(g))}finally{It(!1)}}})]})}function Es({pending:t,busy:n,error:s,t:o,onCancel:i,onConfirm:r}){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:d=>{d.target===d.currentTarget&&!n&&i()},children:e.jsxs("div",{style:{width:"min(92vw, 420px)",background:o.appBg,border:`1px solid ${o.headerBorder}`,borderRadius:12,padding:18,boxShadow:"0 18px 44px rgba(0,0,0,.22)"},children:[e.jsxs("div",{style:{fontSize:14,fontWeight:700,color:o.textPrimary,marginBottom:6},children:["Delete this ",t.kind,"?"]}),e.jsxs("div",{style:{fontSize:12,color:o.textSecondary,lineHeight:1.5},children:[e.jsx("strong",{style:{fontFamily:o.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:o.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,s?e.jsx("div",{style:{fontSize:11.5,color:o.error,marginTop:10,lineHeight:1.5},children:s}):null,e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[e.jsx(se,{t:o,onClick:i,disabled:n,children:"Cancel"}),e.jsx(se,{t:o,danger:!0,onClick:r,disabled:n,children:n?"Deleting…":`Delete ${t.kind}`})]})]})})}function qs({data:t,selectedDomain:n,onSelect:s,t:o}){const{state:i}=Wt(),r=Wo(t.modeling.packages),d=new Map(Ho(i.authoredDomains).map(h=>[h.value,h.label]));return e.jsx("nav",{"aria-label":"Domain packages",children:e.jsx(Uo,{id:"domain-workspace-filter",ariaLabel:"Domain workspace",value:n??"",options:r.map(h=>({value:h.id,label:d.get(h.id)??h.label})),onChange:h=>s(h||null),summary:e.jsxs(e.Fragment,{children:[r.length," authored domain",r.length===1?"":"s"," available"]}),t:o})})}function Ts({data:t,domain:n,active:s,onSelect:o,t:i}){var y;const r=n?[((y=t.domainAssets)==null?void 0:y[n])??{}]:Object.values(t.domainAssets??{}),h={diagram:io(t.modeling,n).length,skills:r.reduce((l,u)=>{var m;return l+(((m=u.skills)==null?void 0:m.length)??0)},0),blocks:new Set(r.flatMap(l=>l.blocks??[])).size};return e.jsx("nav",{"aria-label":n?`${n} workspace`:"All domains workspace",style:{padding:"10px 7px 14px"},children:lo.map((l,u)=>e.jsxs("div",{style:{marginTop:u===0?0:12},children:[l.label?e.jsx("div",{style:{padding:"0 8px 6px",color:i.textMuted,fontSize:9,fontWeight:800,textTransform:"uppercase",letterSpacing:".06em"},children:l.label}):null,l.items.map(m=>e.jsxs("button",{onClick:()=>o(m.id),"aria-current":s===m.id?"page":void 0,style:ri(i,s===m.id,!1),children:[mo(m.id,14,i,s===m.id),e.jsx("span",{style:{flex:1},children:m.label}),h[m.id]!==void 0&&e.jsx("small",{style:{color:s===m.id?i.accent:i.textMuted},children:h[m.id]})]},m.id))]},l.label??`group-${u}`))})}function mo(t,n,s,o=!1){const i=t==="blocks"?ro:t==="diagram"?Ko:t==="skills"?hs:t==="notebooks"||t==="apps"?Gt:Ze;return e.jsx(i,{size:n,color:o?s.accent:s.textMuted})}function Fs(t){var n;return((n=lo.flatMap(s=>s.items).find(s=>s.id===t))==null?void 0:n.label)??t}function Vn(){if(typeof window>"u")return{domain:null,section:"diagram",modelAreaId:null,selectedId:null};let t=null;try{t=window.localStorage.getItem(ao)}catch{t=null}return To(window.location.href,t)}function Pt(t,n,s=!1,o=null,i=null){if(typeof window>"u")return;const r=Fo(window.location.href,{domain:t,section:n,modelAreaId:o,selectedId:i});s?window.history.replaceState(window.history.state,"",r):window.history.pushState(window.history.state,"",r);try{window.localStorage.setItem(ao,JSON.stringify({domain:t,section:n,modelAreaId:o,selectedId:i}))}catch{}}function Ws(t,n){const s=new Set,o=new Set;if(!n)return{modeling:t,ghostEntityIds:s,ghostRelationshipIds:o};const i={...t.entities},r={...t.relationships};for(const d of n.operations){if(d.kind!=="modeling_change")continue;const h=d.change;if(h.operation==="upsert_entity"){const y=`${h.value.domain}::entity::${h.value.id}`;s.add(y),i[y]={...i[y]??{},id:h.value.id,localId:h.value.id,qualifiedId:y,domain:h.value.domain,dbtUniqueId:h.value.dbtModel,businessName:h.value.businessName,businessContext:h.value.businessContext,grain:h.value.grain,keys:h.value.keys??[],analyticalRole:h.value.analyticalRole,status:"draft",sourcePath:"(proposed)",identityFingerprint:`ghost:${y}`}}else if(h.operation==="upsert_relationship"){const y=`${h.value.domain}::relationship::${h.value.id}`;o.add(y),r[y]={...r[y]??{},id:h.value.id,localId:h.value.id,qualifiedId:y,from:`${h.value.domain}::entity::${h.value.from}`,to:`${h.value.domain}::entity::${h.value.to}`,keys:h.value.keys,cardinality:h.value.cardinality,fanout:h.value.fanout,status:"draft",crossDomain:!1,ownerDomain:h.value.domain,verb:h.value.verb,description:h.value.description,rationale:h.value.rationale,sourcePath:"(proposed)",fingerprint:`ghost:${y}`,staleCertification:!1,automaticJoinAllowed:!1}}}return{modeling:{...t,entities:i,relationships:r},ghostEntityIds:s,ghostRelationshipIds:o}}function Hs(t){var o;const n=Object.keys(t.modeling.packages??{});return n.length===1?n[0]:(((o=t.dbtProvenance)==null?void 0:o.projectName)??"").toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_|_$/g,"")||"analytics"}function nn(t,n){const s=Object.entries(t).find(([,o])=>o===n);return s?s[0]:n.qualifiedId??n.id}function Us({editor:t,data:n,selectedDomain:s,selectedArea:o,t:i,onClose:r,onProposal:d,onFixWithAi:h,onApplied:y}){var bn,jn,vn,Sn,wn,kn,Cn,In,Mn,zn,Dn,$n,Rn,Bn,An,Pn,Ln,Nn,On,_n,En;const l=t.kind==="relationship"?t.relationship:void 0,u=t.kind==="entity"?t.entity:void 0,m=t.kind==="area"?t.area:void 0,f=t.kind==="relationship"?t.draft:void 0,[c,x]=a.useState((m==null?void 0:m.domain)??(u==null?void 0:u.domain)??s??Object.keys(n.modeling.packages)[0]??Hs(n)),[I,v]=a.useState((m==null?void 0:m.localId)??((bn=n.modeling.areas[(u==null?void 0:u.areaId)??(l==null?void 0:l.areaId)??""])==null?void 0:bn.localId)??(o==null?void 0:o.localId)??so),[w,B]=a.useState((l==null?void 0:l.localId)??(u==null?void 0:u.localId)??(m==null?void 0:m.localId)??""),[b,S]=a.useState((l==null?void 0:l.owner)??(u==null?void 0:u.owner)??""),[P,q]=a.useState(""),[N,j]=a.useState(t.kind==="entity"?(u==null?void 0:u.dbtUniqueId)??t.dbtUniqueId??"":""),[E,C]=a.useState((u==null?void 0:u.businessName)??""),[O,M]=a.useState((u==null?void 0:u.businessContext)??""),[T,re]=a.useState(((jn=u==null?void 0:u.conceptRefs)==null?void 0:jn.join(", "))??""),[be,de]=a.useState((u==null?void 0:u.analyticalRole)??"unknown"),[k,D]=a.useState((u==null?void 0:u.status)??"draft"),[A,F]=a.useState((u==null?void 0:u.grain)??""),[U,V]=a.useState((u==null?void 0:u.keys.join(", "))??""),[K,ie]=a.useState((m==null?void 0:m.name)??""),[ce,De]=a.useState((m==null?void 0:m.description)??""),[ge,_e]=a.useState((m==null?void 0:m.intentExamples.join(", "))??""),[we,je]=a.useState((m==null?void 0:m.referencedEntityIds.map(p=>{var L;return((L=n.modeling.entities[p])==null?void 0:L.localId)??p}).join(", "))??""),[H,Ce]=a.useState((l==null?void 0:l.from)??(f==null?void 0:f.from)??""),[R,oe]=a.useState((l==null?void 0:l.to)??(f==null?void 0:f.to)??""),[me,Ee]=a.useState((l==null?void 0:l.keys.map(p=>`${p.from}=${p.to}`).join(", "))??(f!=null&&f.fromColumn&&f.toColumn?`${f.fromColumn}=${f.toColumn}`:"")),[qe,wt]=a.useState((l==null?void 0:l.cardinality)??"unknown"),[ve,te]=a.useState((l==null?void 0:l.fanout)??"unknown"),[ue,pe]=a.useState((l==null?void 0:l.status)??"draft"),[nt,ke]=a.useState((l==null?void 0:l.verb)??""),[$e,ot]=a.useState((l==null?void 0:l.description)??""),[Te,Kt]=a.useState(((vn=l==null?void 0:l.roles)==null?void 0:vn.from)??""),[st,kt]=a.useState(((Sn=l==null?void 0:l.roles)==null?void 0:Sn.to)??""),[it,at]=a.useState(((wn=l==null?void 0:l.optionality)==null?void 0:wn.from)??"unknown"),[Se,Fe]=a.useState(((kn=l==null?void 0:l.optionality)==null?void 0:kn.to)??"unknown"),[Ct,It]=a.useState(((Cn=l==null?void 0:l.joinTypes)==null?void 0:Cn.join(", "))??"left"),[lt,Re]=a.useState(((In=l==null?void 0:l.aggregation)==null?void 0:In.measuresFrom.join(", "))??""),[We,rt]=a.useState(((Mn=l==null?void 0:l.aggregation)==null?void 0:Mn.dimensionsFrom.join(", "))??""),[Mt,Be]=a.useState(((zn=l==null?void 0:l.importRefs)==null?void 0:zn.join(", "))??""),[He,Q]=a.useState((l==null?void 0:l.attributionBlock)??""),[he,dt]=a.useState((l==null?void 0:l.evidenceExpiresAt)??""),[J,Ue]=a.useState(""),[Ke,zt]=a.useState(""),[Ye,Dt]=a.useState(""),[Ae,ct]=a.useState(""),[Pe,ut]=a.useState(""),[Ve,pt]=a.useState(""),[ht,g]=a.useState(""),[$,G]=a.useState(""),[Ie,Je]=a.useState(""),[$t,vo]=a.useState(""),[rn,So]=a.useState(""),[dn,wo]=a.useState(""),[cn,ko]=a.useState("internal"),[un,Co]=a.useState(""),[di,Io]=a.useState(null),[pn,Rt]=a.useState(!1),[hn,xt]=a.useState(null),[gt,mt]=a.useState(l==null?void 0:l.validation),[Le,Yt]=a.useState(null),[Vt,Mo]=a.useState({}),[xn,zo]=a.useState(!!(l&&(l.roles||l.aggregation||(Dn=l.importRefs)!=null&&Dn.length||l.attributionBlock||l.evidenceExpiresAt)));a.useEffect(()=>{t.kind!=="relationship"||l||w||!H||!R||B(`${H}_to_${R}`.replace(/[^a-zA-Z0-9]+/g,"_").replace(/^_+|_+$/g,"").toLowerCase())},[t.kind,l,H,R,w]),a.useEffect(()=>{var L;if(t.kind!=="entity"||w||!N)return;const p=(L=n.dbtProvenance.nodes[N])==null?void 0:L.name;p&&B(p.replace(/[^a-zA-Z0-9]+/g,"_").replace(/^_+|_+$/g,"").toLowerCase())},[t.kind,w,N,n.dbtProvenance.nodes]),a.useEffect(()=>{if(t.kind!=="entity"||!N){Yt(null);return}let p=!1;return Z.getDbtModelingNode(N).then(L=>{var W,ee;p||(Yt(L),E||C(L.name.replace(/[_-]+/g," ").replace(/\b\w/g,X=>X.toUpperCase())),!A&&((W=L.dqlMeta)!=null&&W.grain)&&F(L.dqlMeta.grain),!U&&((ee=L.dqlMeta)!=null&&ee.keys.length)&&V(L.dqlMeta.keys.join(", ")))}).catch(()=>{p||Yt(null)}),()=>{p=!0}},[N,t.kind]),a.useEffect(()=>{if(t.kind!=="relationship")return;const L=[H,R].map(ee=>{var X;return(X=n.modeling.entities[ee])==null?void 0:X.dbtUniqueId}).filter(ee=>!!ee).filter(ee=>!Vt[ee]);if(!L.length)return;let W=!1;return Z.getDbtModelingNodes(L).then(({details:ee})=>{W||Mo(X=>({...X,...Object.fromEntries(ee.map(xe=>[xe.uniqueId,xe]))}))}).catch(()=>{}),()=>{W=!0}},[t.kind,H,R]);const Jt=()=>{if(t.kind==="domain")return{operation:"upsert_domain",value:{id:w,name:w,owner:b,parent:P||void 0,exports:[]}};if(t.kind==="area")return{operation:"upsert_area",value:{id:w,domain:c,name:K||w,description:ce||void 0,intentExamples:Y(ge),references:Y(we)}};if(t.kind==="entity")return{operation:"upsert_entity",value:{id:w,domain:c,dbtModel:N,areaId:I||void 0,businessName:E||void 0,businessContext:O||void 0,conceptRefs:Y(T),analyticalRole:be,status:k,owner:b||void 0,grain:A||void 0,keys:Y(U)}};if(t.kind==="contract")return{operation:"upsert_contract",value:{id:w,domain:c,entities:Y(J),blocks:Y(Ke),status:"draft",owner:b,requiredEvaluation:!0,purpose:Ye||void 0,metricRefs:Y(Ae),dimensions:Y(Pe),allowedFilters:Y(Ve),requiredFilters:Y(ht),evaluationRefs:Y($)}};if(t.kind==="export")return{operation:"upsert_export",value:{id:w,domain:c,entity:Ie||void 0,metrics:Y(Ae),blocks:Y(Ke),allowedKeys:Y($t),allowedDimensions:Y(Pe),allowedFilters:Y(Ve),purposes:Y(rn),consumerDomains:Y(dn),classification:cn||void 0,status:ue,owner:b||void 0}};if(t.kind==="import")return{operation:"upsert_import",value:{id:w||void 0,domain:c,exportRef:un,purpose:Ye,status:ue,owner:b||void 0}};const p=li(me),W=!l||l.from===H&&l.to===R&&JSON.stringify(l.keys)===JSON.stringify(p)&&l.cardinality===qe&&l.fanout===ve?gt:void 0,ee=ue==="certified"&&(W==null?void 0:W.status)!=="passed"?"reviewed":ue,X=n.modeling.entities[H],xe=n.modeling.entities[R];return{operation:"upsert_relationship",value:{id:w,domain:c,areaId:I||void 0,from:H,to:R,keys:p,cardinality:qe,fanout:ve,status:ee,owner:b||void 0,ownerDomain:c,verb:nt||void 0,description:$e||void 0,roles:Te||st?{from:Te||void 0,to:st||void 0}:void 0,optionality:{from:it,to:Se},joinTypes:Y(Ct),aggregation:lt||We?{measuresFrom:Y(lt),dimensionsFrom:Y(We),requiresPreAggregation:ve!=="safe"}:void 0,attributionBlock:He||void 0,importRefs:Y(Mt),evidenceExpiresAt:he||void 0,crossDomain:(X==null?void 0:X.domain)!==(xe==null?void 0:xe.domain),validation:W,certifiedAgainst:ee==="certified"&&(X!=null&&X.grain)&&(xe!=null&&xe.grain)?{from:{grain:X.grain,keys:X.keys},to:{grain:xe.grain,keys:xe.keys}}:void 0}}},Do=async()=>{try{Rt(!0),xt(null);const p=Jt();if(Io(p),Tn(p,u,m)){const W=await Z.previewModelingChange(p,n.snapshotId);await Z.applyModelingChange(p,W.fingerprint,n.snapshotId),await y(p);return}const L=await Z.createContextProposal({origin:"manual",expectedSnapshotId:n.snapshotId,operations:[{id:`manual:${p.operation}:${w||Date.now().toString(36)}`,kind:"modeling_change",change:p,evidence:["manual Modeling workspace authoring"]}]});d(L)}catch(p){xt(p instanceof Error?p.message:String(p))}finally{Rt(!1)}},$o=async()=>{try{Rt(!0),xt(null);const p=Jt();if(p.operation!=="upsert_relationship")return;const L=await Z.validateModelingRelationship(p.value,n.snapshotId);mt(L),xt(L.status==="passed"?"Warehouse proof passed. Preview the source change to save it.":L.message??"Validation failed.")}catch(p){xt(p instanceof Error?p.message:String(p))}finally{Rt(!1)}},gn=Object.entries(n.modeling.entities).map(([p,L])=>{const W=n.dbtProvenance.nodes[L.dbtUniqueId];return{value:p,label:L.businessName||L.localId||L.id,description:`${L.domain} · ${(W==null?void 0:W.relation)??(W==null?void 0:W.name)??L.dbtUniqueId}`,keywords:[L.qualifiedId,L.businessContext??"",L.analyticalRole??""]}}),Ne=Vt[(($n=n.modeling.entities[H])==null?void 0:$n.dbtUniqueId)??""],Oe=Vt[((Rn=n.modeling.entities[R])==null?void 0:Rn.dbtUniqueId)??""],mn=((Ne==null?void 0:Ne.columns)??[]).map(p=>({value:p.name,label:p.name,description:[p.type,p.description].filter(Boolean).join(" · ")||"dbt column"})),fn=((Oe==null?void 0:Oe.columns)??[]).map(p=>({value:p.name,label:p.name,description:[p.type,p.description].filter(Boolean).join(" · ")||"dbt column"})),Bt=mn.map(p=>p.value).filter(p=>fn.some(L=>L.value.toLowerCase()===p.toLowerCase())).slice(0,5),Me=me?me.split(",").map(p=>{const[L="",W=""]=p.split("=").map(ee=>ee.trim());return{from:L,to:W}}):[{from:"",to:""}],yn=(p,L,W)=>{const ee=Me.map((X,xe)=>xe===p?{...X,[L]:W}:X);Ee(ee.map(X=>`${X.from}=${X.to}`).join(", ")),mt(void 0)},Ro=p=>{const L=Me.filter((W,ee)=>ee!==p);Ee(L.map(W=>`${W.from}=${W.to}`).join(", ")),mt(void 0)},Bo=()=>Ee([...Me.filter(p=>p.from||p.to),{from:"",to:""}].map(p=>`${p.from}=${p.to}`).join(", ")),Qt=t.kind==="entity"?!!(c&&w&&N):t.kind==="relationship"?!!(c&&w&&H&&R&&Me.some(p=>p.from&&p.to)&&Me.every(p=>p.from&&p.to)):!0,Ao=(()=>{if(!Qt)return!1;try{return Tn(Jt(),u,m)}catch{return!1}})(),Po=t.kind==="domain"?"Create Domain Package":t.kind==="area"?m?"Edit subject area":"Create subject 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(yo,{title:Po,t:i,onClose:r,children:e.jsxs("div",{style:{display:"grid",gap:12},children:[t.kind!=="domain"&&e.jsx(z,{label:"Domain",children:e.jsx(ae,{value:c,onChange:x,values:Object.keys(n.modeling.packages),t:i})}),t.kind!=="relationship"&&e.jsx(z,{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(_,{value:w,onChange:B,t:i,placeholder:"stable_snake_case_id"})}),t.kind==="domain"&&e.jsx(z,{label:"Parent domain (optional)",children:e.jsx(ae,{value:P,onChange:q,values:Object.keys(n.modeling.packages),t:i})}),t.kind==="area"&&e.jsxs(e.Fragment,{children:[e.jsx(fe,{text:"A subject area is one small, reviewable source file — a focused diagram inside this Domain. It filters the same domain graph; it never creates a competing semantic model and never changes what an agent is allowed to use.",t:i}),e.jsx(z,{label:"Area name",children:e.jsx(_,{value:K,onChange:ie,t:i,placeholder:"Customer lifecycle"})}),e.jsx(z,{label:"Business question or scope",children:e.jsx(_,{value:ce,onChange:De,t:i,placeholder:"How customers progress from first order to repeat purchase."})}),e.jsx(z,{label:"Example questions (comma-separated)",children:e.jsx(_,{value:ge,onChange:_e,t:i,placeholder:"Which customers made a second purchase?"})}),e.jsx(z,{label:"Read-only boundary entities (comma-separated)",children:e.jsx(_,{value:we,onChange:je,t:i,placeholder:"customer"})})]}),t.kind==="entity"&&e.jsxs(e.Fragment,{children:[e.jsx(Zn,{current:N?2:1,labels:["Find dbt model","Add business meaning","Review source change"],t:i}),e.jsx(fe,{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(z,{label:"Subject area",children:e.jsx(ae,{value:I,onChange:v,values:Object.values(n.modeling.areas).filter(p=>p.domain===c).map(p=>p.localId),labels:Object.fromEntries(Object.values(n.modeling.areas).filter(p=>p.domain===c).map(p=>[p.localId,p.name])),t:i})}),e.jsx(z,{label:"dbt model",children:e.jsx(oi,{value:N,onChange:j,selectedNode:n.dbtProvenance.nodes[N],domain:c,t:i})}),Le&&e.jsx(eo,{title:Le.name,detail:`${Le.relation??Le.uniqueId} · ${Le.columns.length} columns${(Bn=Le.dqlMeta)!=null&&Bn.grain?` · grain: ${Le.dqlMeta.grain}`:""}`,t:i}),e.jsx(z,{label:"Business name",children:e.jsx(_,{value:E,onChange:C,t:i,placeholder:"Customer order"})}),e.jsx(z,{label:"Business context",children:e.jsx(_,{value:O,onChange:M,t:i,placeholder:"One order used to understand repeat purchasing and revenue."})}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Business concepts",children:e.jsx(_,{value:T,onChange:re,t:i,placeholder:"customer_lifecycle, revenue"})}),e.jsx(z,{label:"Analytical role",children:e.jsx(ae,{value:be,onChange:p=>de(p),values:["event","dimension","snapshot","bridge","unknown"],t:i})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Grain override (optional)",children:e.jsx(_,{value:A,onChange:F,t:i,placeholder:"Use dbt meta.dql by default"})}),e.jsx(z,{label:"Key overrides (optional)",children:e.jsx(_,{value:U,onChange:V,t:i,placeholder:"customer_id, order_id"})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Lifecycle",children:e.jsx(ae,{value:k==="review"?"reviewed":k,onChange:p=>D(p),values:["draft","evaluated","reviewed","certified","deprecated"],t:i})}),e.jsx(z,{label:"Owner",children:e.jsx(_,{value:b,onChange:S,t:i,placeholder:"team@company.com"})})]})]}),t.kind==="relationship"&&e.jsxs(e.Fragment,{children:[e.jsx(Zn,{current:!H||!R?1:Me.some(p=>p.from&&p.to)?3:2,labels:["Choose models","Match join keys","Review policy"],t:i}),e.jsx(fe,{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(z,{label:"Subject area",children:e.jsx(ae,{value:I,onChange:v,values:Object.values(n.modeling.areas).filter(p=>p.domain===c).map(p=>p.localId),labels:Object.fromEntries(Object.values(n.modeling.areas).filter(p=>p.domain===c).map(p=>[p.localId,p.name])),t:i})}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"From entity",children:e.jsx(Nt,{ariaLabel:"From entity",value:H,onChange:p=>{Ce(p),mt(void 0)},options:gn,placeholder:"Search source model…",t:i})}),e.jsx(z,{label:"To entity",children:e.jsx(Nt,{ariaLabel:"To entity",value:R,onChange:p=>{oe(p),mt(void 0)},options:gn.filter(p=>p.value!==H),placeholder:"Search target model…",t:i})})]}),H&&R&&e.jsx(eo,{title:`${((An=n.modeling.entities[H])==null?void 0:An.businessName)||((Pn=n.modeling.entities[H])==null?void 0:Pn.localId)} → ${((Ln=n.modeling.entities[R])==null?void 0:Ln.businessName)||((Nn=n.modeling.entities[R])==null?void 0:Nn.localId)}`,detail:`${(Ne==null?void 0:Ne.columns.length)??0} source columns · ${(Oe==null?void 0:Oe.columns.length)??0} target columns`,t:i}),e.jsx(z,{label:"Join keys",children:e.jsxs("div",{style:{display:"grid",gap:8},children:[Bt.length>0&&!Me.some(p=>p.from&&p.to)&&e.jsxs("button",{type:"button",onClick:()=>Ee(`${Bt[0]}=${Bt[0]}`),style:{...Xe(i),justifySelf:"start"},children:[e.jsx(Ht,{size:13})," Use exact match: ",Bt[0]]}),Me.map((p,L)=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) 24px minmax(0, 1fr) 30px",gap:7,alignItems:"center"},children:[e.jsx(Nt,{ariaLabel:`Source join column ${L+1}`,value:p.from,onChange:W=>yn(L,"from",W),options:mn,placeholder:H?"Source column…":"Choose source first",disabled:!H||!Ne,t:i}),e.jsx("span",{"aria-hidden":"true",style:{color:i.textMuted,textAlign:"center"},children:"→"}),e.jsx(Nt,{ariaLabel:`Target join column ${L+1}`,value:p.to,onChange:W=>yn(L,"to",W),options:fn,placeholder:R?"Target column…":"Choose target first",disabled:!R||!Oe,t:i}),e.jsx("button",{type:"button","aria-label":"Remove join key",title:"Remove join key",onClick:()=>Ro(L),style:ze(i),children:e.jsx(tt,{size:14})})]},`${L}:${p.from}:${p.to}`)),e.jsxs("button",{type:"button",onClick:Bo,style:{...Xe(i),justifySelf:"start"},children:[e.jsx(et,{size:13})," Add key pair"]})]})}),w&&e.jsxs("div",{style:{color:i.textMuted,fontSize:9.5},children:["Relationship id: ",e.jsx("code",{children:w})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Cardinality",children:e.jsx(ae,{value:qe,onChange:p=>wt(p),values:["unknown","one_to_one","one_to_many","many_to_one","many_to_many"],t:i})}),e.jsx(z,{label:"Fanout policy",children:e.jsx(ae,{value:ve==="unsafe"?"forbidden":ve,onChange:p=>te(p),values:["safe","dedupe_required","attribution_required","forbidden","unknown"],t:i})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Business verb (optional)",children:e.jsx(_,{value:nt,onChange:ke,t:i,placeholder:"belongs to"})}),e.jsx(z,{label:"Description (optional)",children:e.jsx(_,{value:$e,onChange:ot,t:i,placeholder:"Why this relationship exists"})})]}),H&&R&&((On=n.modeling.entities[H])==null?void 0:On.domain)!==((_n=n.modeling.entities[R])==null?void 0:_n.domain)&&e.jsx(fe,{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:()=>zo(p=>!p),style:{...Xe(i),justifySelf:"start",padding:"6px 0"},children:xn?"Hide advanced governance":"Advanced governance and aggregation"}),xn&&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:ne,children:[e.jsx(z,{label:"Allowed join types",children:e.jsx(_,{value:Ct,onChange:It,t:i,placeholder:"left, inner"})}),e.jsx(z,{label:"Lifecycle",children:e.jsx(ae,{value:ue==="review"?"reviewed":ue??"draft",onChange:p=>pe(p),values:["draft","evaluated","reviewed","certified","deprecated"],t:i})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"From role",children:e.jsx(_,{value:Te,onChange:Kt,t:i})}),e.jsx(z,{label:"To role",children:e.jsx(_,{value:st,onChange:kt,t:i})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"From optionality",children:e.jsx(ae,{value:it,onChange:p=>at(p),values:["required","optional","unknown"],t:i})}),e.jsx(z,{label:"To optionality",children:e.jsx(ae,{value:Se,onChange:p=>Fe(p),values:["required","optional","unknown"],t:i})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Measures allowed from",children:e.jsx(_,{value:lt,onChange:Re,t:i,placeholder:"order"})}),e.jsx(z,{label:"Dimensions allowed from",children:e.jsx(_,{value:We,onChange:rt,t:i,placeholder:"customer"})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Required import refs",children:e.jsx(_,{value:Mt,onChange:Be,t:i,placeholder:"commerce.customer@1"})}),e.jsx(z,{label:"Attribution block",children:e.jsx(_,{value:He,onChange:Q,t:i,placeholder:"growth.revenue_by_channel"})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Evidence expires",children:e.jsx(_,{value:he,onChange:dt,t:i,placeholder:"2026-12-31"})}),e.jsx(z,{label:"Owner",children:e.jsx(_,{value:b,onChange:S,t:i,placeholder:"team@company.com"})})]})]}),gt&&e.jsx(fo,{evidence:gt,t:i,onFixWithAi:gt.status==="failed"?()=>h(l?nn(n.modeling.relationships,l):null,gt):void 0})]}),t.kind==="contract"&&e.jsxs(e.Fragment,{children:[e.jsx(z,{label:"Covered entities",children:e.jsx(_,{value:J,onChange:Ue,t:i,placeholder:"order, customer"})}),e.jsx(z,{label:"Certified blocks",children:e.jsx(_,{value:Ke,onChange:zt,t:i,placeholder:"orders_360"})}),e.jsx(z,{label:"Decision purpose",children:e.jsx(_,{value:Ye,onChange:Dt,t:i,placeholder:"Revenue reporting"})}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Metrics",children:e.jsx(_,{value:Ae,onChange:ct,t:i})}),e.jsx(z,{label:"Dimensions",children:e.jsx(_,{value:Pe,onChange:ut,t:i})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Allowed filters",children:e.jsx(_,{value:Ve,onChange:pt,t:i})}),e.jsx(z,{label:"Required filters",children:e.jsx(_,{value:ht,onChange:g,t:i})})]}),e.jsx(z,{label:"Evaluation refs",children:e.jsx(_,{value:$,onChange:G,t:i,placeholder:"revenue_accuracy"})})]}),t.kind==="export"&&e.jsxs(e.Fragment,{children:[e.jsx(z,{label:"Exported entity",children:e.jsx(ae,{value:Ie,onChange:Je,values:Object.keys(n.modeling.entities).filter(p=>{var L;return((L=n.modeling.entities[p])==null?void 0:L.domain)===c}),t:i})}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Allowed keys",children:e.jsx(_,{value:$t,onChange:vo,t:i})}),e.jsx(z,{label:"Allowed dimensions",children:e.jsx(_,{value:Pe,onChange:ut,t:i})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Metrics",children:e.jsx(_,{value:Ae,onChange:ct,t:i})}),e.jsx(z,{label:"Blocks",children:e.jsx(_,{value:Ke,onChange:zt,t:i})})]}),e.jsx(z,{label:"Allowed filters",children:e.jsx(_,{value:Ve,onChange:pt,t:i})}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Approved purposes",children:e.jsx(_,{value:rn,onChange:So,t:i,placeholder:"revenue reporting"})}),e.jsx(z,{label:"Consumer domains",children:e.jsx(_,{value:dn,onChange:wo,t:i,placeholder:"growth"})})]}),e.jsxs("div",{style:ne,children:[e.jsx(z,{label:"Classification",children:e.jsx(_,{value:cn,onChange:ko,t:i})}),e.jsx(z,{label:"Lifecycle",children:e.jsx(ae,{value:ue==="review"?"reviewed":ue??"draft",onChange:p=>pe(p),values:["draft","evaluated","reviewed","certified","deprecated"],t:i})})]})]}),t.kind==="import"&&e.jsxs(e.Fragment,{children:[e.jsx(z,{label:"Provider export",children:e.jsx(ae,{value:un,onChange:Co,values:Object.values(((En=n.modeling.interfaces)==null?void 0:En.exports)??{}).map(p=>`${p.domain}.${p.localId}@${p.version}`),t:i})}),e.jsx(z,{label:"Exact analytical purpose",children:e.jsx(_,{value:Ye,onChange:Dt,t:i,placeholder:"Revenue by acquisition channel"})}),e.jsx(z,{label:"Lifecycle",children:e.jsx(ae,{value:ue==="review"?"reviewed":ue??"draft",onChange:p=>pe(p),values:["draft","evaluated","reviewed","certified","deprecated"],t:i})})]}),t.kind!=="entity"&&t.kind!=="relationship"&&t.kind!=="area"&&e.jsx(z,{label:"Owner",children:e.jsx(_,{value:b,onChange:S,t:i,placeholder:"team@company.com"})}),hn&&e.jsx(fe,{text:hn,t:i}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[t.kind==="relationship"&&e.jsxs(se,{t:i,onClick:()=>void $o(),disabled:pn||!Qt,children:[e.jsx(Qo,{size:14})," Validate in warehouse"]}),e.jsx(se,{primary:!0,t:i,onClick:()=>void Do(),disabled:pn||!Qt,children:Ao?"Save":"Preview source change"})]})]})})}function Ks({search:t,onSearch:n,items:s,onPick:o,t:i}){var f;const[r,d]=a.useState(!1),h=a.useRef(null),y=t.trim().toLowerCase(),l=y?s.filter(c=>c.label.toLowerCase().includes(y)||c.sublabel.toLowerCase().includes(y)).sort((c,x)=>c.type===x.type?c.label.localeCompare(x.label):c.type==="model"?-1:1).slice(0,14):[],u=c=>c==="dimension"?"var(--status-success)":c==="bridge"?"var(--status-warning)":c==="event"||c==="snapshot"?"var(--accent)":"var(--text-tertiary)",m=r&&y?(f=h.current)==null?void 0:f.getBoundingClientRect():void 0;return e.jsxs("label",{ref:h,style:{position:"relative",width:210,flex:"0 0 210px"},children:[e.jsx(Ft,{size:12,style:{position:"absolute",left:7,top:8,color:i.textMuted}}),e.jsx("input",{"aria-label":"Search diagram",value:t,onChange:c=>{n(c.target.value),d(!0)},onFocus:()=>d(!0),placeholder:"Find model or column",style:{...ye(i),padding:"6px 7px 6px 24px"}}),m&&e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:()=>d(!1),style:{position:"fixed",inset:0,zIndex:60}}),e.jsx("div",{style:{position:"fixed",top:m.bottom+5,left:m.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:l.length===0?e.jsx("div",{style:{padding:"10px 10px",fontSize:11.5,color:i.textMuted,fontFamily:i.font},children:"No matching model or column."}):l.map((c,x)=>e.jsxs("button",{type:"button",onMouseDown:I=>{I.preventDefault(),o(c.recordKey),d(!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:u(c.role),flexShrink:0}}),e.jsx("span",{style:{flex:1,minWidth:0,fontSize:12,fontWeight:c.type==="model"?650:500,color:i.textPrimary,fontFamily:i.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.label}),e.jsx("span",{style:{flexShrink:0,fontSize:9,fontWeight:700,letterSpacing:"0.04em",textTransform:"uppercase",color:i.textMuted},children:c.type==="model"?"model":c.sublabel})]},`${c.type}-${c.recordKey}-${c.label}-${x}`))})]})]})}function Ys({modelingView:t,columnMode:n,search:s,layoutMode:o,density:i,visibleLimit:r,dimUnrelated:d,showEdgeLabels:h,showLegend:y,fullscreen:l,aiOpen:u,onBindModel:m,onRelationship:f,onToggleAi:c,onModelingView:x,onColumnMode:I,onSearch:v,searchItems:w,onPickModel:B,onLayoutMode:b,onDensity:S,onVisibleLimit:P,onDimUnrelated:q,onEdgeLabels:N,onLegend:j,onFullscreen:E,onExport:C,onReset:O,t:M}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,minHeight:50,padding:"0 10px",borderBottom:`1px solid ${M.headerBorder}`,background:M.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 ${M.headerBorder}`,borderRadius:7,background:M.appBg,flexShrink:0},children:[e.jsx("button",{type:"button",onClick:()=>x("business"),style:{border:"none",borderRadius:5,padding:"4px 11px",fontSize:11.5,fontWeight:600,cursor:"pointer",fontFamily:M.font,whiteSpace:"nowrap",background:t==="business"?"var(--accent-dim)":"transparent",color:t==="business"?M.accent:M.textMuted},children:"Business modeling"}),e.jsx("button",{type:"button",onClick:()=>x("data"),style:{border:"none",borderRadius:5,padding:"4px 11px",fontSize:11.5,fontWeight:600,cursor:"pointer",fontFamily:M.font,whiteSpace:"nowrap",background:t==="data"?"var(--accent-dim)":"transparent",color:t==="data"?M.accent:M.textMuted},children:"Data modeling"})]}),e.jsx(Ks,{search:s,onSearch:v,items:w,onPick:B,t:M}),e.jsxs("button",{type:"button",onClick:m,style:Ge(M,!0),children:[e.jsx(et,{size:13})," Add models"]}),e.jsxs("button",{type:"button",onClick:f,style:Ge(M),children:[e.jsx(Ot,{size:13})," Connect"]}),e.jsxs("button",{type:"button","aria-pressed":u,onClick:c,style:{...Ge(M),...u?{borderColor:M.accent,color:M.accent,background:"var(--accent-dim)"}:{}},children:[e.jsx(Ht,{size:13})," Build with AI"]}),e.jsxs("details",{style:{position:"relative",flexShrink:0},children:[e.jsxs("summary",{style:{...Ge(M),listStyle:"none"},children:[e.jsx(xs,{size:13})," View"]}),e.jsxs("div",{role:"group","aria-label":"Modeling view options",style:{position:"fixed",zIndex:70,width:250,marginTop:6,right:12,padding:10,display:"grid",gap:9,border:`1px solid ${M.headerBorder}`,borderRadius:9,background:M.cellBg,boxShadow:"0 14px 34px rgba(0,0,0,.18)"},children:[t==="data"&&e.jsxs("label",{style:Lt(M),children:[e.jsxs("span",{children:[e.jsx(fs,{size:13})," Columns"]}),e.jsxs("select",{"aria-label":"Visible columns",value:n,onChange:T=>I(T.target.value),style:{...ye(M),width:108,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.jsxs("label",{style:Lt(M),children:[e.jsx("span",{children:"Layout"}),e.jsxs("select",{"aria-label":"Diagram layout",value:o,onChange:T=>{b(T.target.value),O()},style:{...ye(M),width:108,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("label",{style:Lt(M),children:[e.jsx("span",{children:"Density"}),e.jsxs("select",{"aria-label":"Diagram density",value:i,onChange:T=>S(T.target.value),style:{...ye(M),width:108,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:Lt(M),children:[e.jsx("span",{children:"Canvas"}),e.jsxs("select",{"aria-label":"Visible model limit",value:r||50,onChange:T=>P(Number(T.target.value)),style:{...ye(M),width:108,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.jsxs("button",{type:"button",onClick:()=>q(!d),style:Qe(M,d),children:[e.jsx(Yo,{size:14})," Dim unrelated models"]}),e.jsxs("button",{type:"button",onClick:()=>N(!h),style:Qe(M,h),children:[e.jsx(Ot,{size:14})," Relationship labels"]}),e.jsxs("button",{type:"button",onClick:()=>j(!y),style:Qe(M,y),children:[e.jsx(Ze,{size:14})," Relationship legend"]}),e.jsxs("button",{type:"button",onClick:C,style:Qe(M),children:[e.jsx(Vo,{size:14})," Export SVG"]}),e.jsxs("button",{type:"button",onClick:E,style:Qe(M,l),children:[l?e.jsx(tt,{size:14}):e.jsx(co,{size:14})," ",l?"Exit fullscreen":"Fullscreen"]}),e.jsxs("button",{type:"button",onClick:O,style:Qe(M),children:[e.jsx(gs,{size:14})," Reset layout"]})]})]})]})}const Lt=t=>({display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,color:t.textSecondary,fontSize:10.5}),Qe=(t,n=!1)=>({border:"none",borderRadius:6,padding:"6px 7px",display:"flex",alignItems:"center",gap:7,background:n?"var(--accent-dim)":"transparent",color:n?t.accent:t.textSecondary,fontSize:10.5,textAlign:"left",cursor:"pointer"});function Vs({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,s])=>e.jsxs("span",{style:{display:"flex",gap:5,alignItems:"center"},children:[e.jsx("i",{style:{display:"inline-block",width:18,height:3,background:s,borderRadius:2}}),n]},n)),e.jsx("span",{style:{marginLeft:"auto"},children:"1:1 · 1:N · N:1 · N:N"})]})}function Js({t,connectedModels:n,onDbt:s,onYaml:o,onManual:i}){const r=[{icon:e.jsx(Ze,{size:20}),title:"Use connected dbt",detail:`${n} model${n===1?"":"s"} available. Search, multi-select, confirm where they belong, then review the bindings.`,action:s},{icon:e.jsx(an,{size:20}),title:"Import modeling YAML",detail:"Discover DQL modeling or dbt YAML from this project, a safe local path, an upload, or pasted content. Relationships declared in dbt tests come across as draft edges.",action:o},{icon:e.jsx(et,{size:20}),title:"Start manually",detail:"Create one model binding or relationship with guided review.",action:i}];return e.jsx("div",{style:{height:"100%",display:"grid",placeItems:"center",padding:28},children:e.jsxs("div",{style:{width:"min(840px, 100%)"},children:[e.jsxs("div",{style:{textAlign:"center",marginBottom:18},children:[e.jsx("h2",{style:{margin:0,fontSize:18},children:"Start modeling domain context"}),e.jsx("p",{style:{margin:"7px 0 0",color:t.textMuted,fontSize:11.5},children:"Choose the source you already have. Every path creates the same write-free proposal before a draft can be saved."})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, minmax(0, 1fr))",gap:10},children:r.map(d=>e.jsxs("button",{type:"button",onClick:d.action,style:{...Tt(t),minHeight:150,textAlign:"left",cursor:"pointer"},children:[e.jsx("span",{style:{width:38,height:38,borderRadius:9,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"var(--accent-dim)",color:t.accent},children:d.icon}),e.jsx("b",{style:{display:"block",marginTop:12},children:d.title}),e.jsx("span",{style:{display:"block",marginTop:6,color:t.textSecondary,fontSize:10.5,lineHeight:1.5},children:d.detail})]},d.title))})]})})}function Qs(){const t=document.querySelector("#dql-modeling-diagram .react-flow__renderer");if(!(t instanceof HTMLElement))return;const n=t.cloneNode(!0),s=t.getBoundingClientRect(),o=new XMLSerializer().serializeToString(n),i=`<svg xmlns="http://www.w3.org/2000/svg" width="${Math.ceil(s.width)}" height="${Math.ceil(s.height)}"><foreignObject width="100%" height="100%"><div xmlns="http://www.w3.org/1999/xhtml">${o}</div></foreignObject></svg>`,r=URL.createObjectURL(new Blob([i],{type:"image/svg+xml"})),d=document.createElement("a");d.href=r,d.download="dql-domain-model.svg",d.click(),URL.revokeObjectURL(r)}function Gs({data:t,domain:n,t:s}){var m,f;const{state:o,dispatch:i}=Wt(),[r,d]=a.useState(null),[h,y]=a.useState(null),l=[...new Set(n?((f=(m=t.domainAssets)==null?void 0:m[n])==null?void 0:f.blocks)??[]:Object.values(t.domainAssets??{}).flatMap(c=>c.blocks??[]))].sort(),u=async c=>{d(c),y(null);try{if(n)try{window.localStorage.setItem("dql.block-studio.domain",n)}catch{}const x=o.files.find(v=>v.path===c)??{name:c.split("/").at(-1)??c,path:c,type:"block",folder:c.split("/").slice(0,-1).join("/")};o.files.some(v=>v.path===c)||i({type:"FILE_ADDED",file:x});const I=await Z.openBlockStudio(c);i({type:"OPEN_BLOCK_STUDIO",file:x,payload:I})}catch(x){y(x instanceof Error?x.message:String(x))}finally{d(null)}};return e.jsxs(bo,{children:[e.jsx(jo,{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:s}),h?e.jsx(fe,{text:h,t:s}):null,l.length?e.jsx("div",{style:{display:"grid",gap:10},children:l.map(c=>{var v;const x=(c.split("/").at(-1)??c).replace(/\.dql$/i,""),I=(v=Object.entries(t.domainAssets??{}).find(([,w])=>{var B;return(B=w.blocks)==null?void 0:B.includes(c)}))==null?void 0:v[0];return e.jsxs("button",{type:"button",onClick:()=>void u(c),"aria-label":`Open block ${x}`,style:{...Tt(s),width:"100%",textAlign:"left",cursor:"pointer"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(ro,{size:14,color:s.accent}),e.jsx("b",{children:x}),n?null:e.jsx(qt,{t:s,children:I??"shared"}),r===c?e.jsx(qt,{t:s,children:"Opening…"}):null]}),e.jsx("code",{style:{display:"block",marginTop:7,color:s.textMuted,fontSize:10},children:c})]},c)})}):e.jsx(on,{title:"No domain blocks yet",detail:"Create a block in Block Studio and assign this domain to make it appear here.",t:s})]})}function Jn({data:t,domain:n,kind:s,t:o}){var w,B;const{state:i,dispatch:r}=Wt(),[d,h]=a.useState([]),[y,l]=a.useState(!0),[u,m]=a.useState(null),[f,c]=a.useState(null);a.useEffect(()=>{let b=!0;return l(!0),(n?Z.getRelatedDomainProducts(n):Z.getAllRelatedDomainProducts()).then(S=>{b&&h(S[s])}).catch(()=>{b&&h([])}).finally(()=>{b&&l(!1)}),()=>{b=!1}},[n,s]);const x=n?((B=(w=t.domainAssets)==null?void 0:w[n])==null?void 0:B[s])??[]:Object.values(t.domainAssets??{}).flatMap(b=>b[s]??[]),I=s==="notebooks"?"Notebooks":"Apps",v=async b=>{const S=String(b.id??b.filePath??b.title??b.name??"product");m(S),c(null);try{if(s==="apps"){const E=String(b.id??Qn(String(b.filePath??"")));if(!E)throw new Error("This App has no stable id to open.");r({type:"OPEN_APP",appId:E,experience:"view",section:"dashboards"});return}const P=String(b.filePath??"");if(!P)throw new Error("This Notebook has no source path to open.");const q=i.files.find(E=>E.path===P)??{name:P.split("/").at(-1)??String(b.title??S),path:P,type:"notebook",folder:P.split("/").slice(0,-1).join("/"),...typeof b.ownerDomain=="string"?{ownerDomain:b.ownerDomain}:{},usesDomains:Array.isArray(b.usesDomains)?b.usesDomains.map(String):[]};i.files.some(E=>E.path===P)||r({type:"FILE_ADDED",file:q});const{content:N}=await Z.readNotebook(P),j=Go(P,N);r({type:"OPEN_FILE",file:q,cells:j.cells,title:j.title,metadata:j.metadata})}catch(P){c(P instanceof Error?P.message:String(P))}finally{m(null)}};return e.jsxs(bo,{children:[e.jsx(jo,{title:n?`Related ${I}`:`All ${I}`,detail:n?`${I} are global shared products related to ${n}. This backlink does not create a second copy inside the Domain Package.`:`All global ${I.toLowerCase()} across Domain Packages. Select a domain above to narrow by owner/uses-domain metadata.`,t:o}),f?e.jsx(fe,{text:f,t:o}):null,y?e.jsx(on,{title:`Loading related ${I.toLowerCase()}…`,detail:"Resolving global product backlinks from the compiled project snapshot.",t:o}):d.length?e.jsx("div",{style:{display:"grid",gap:10},children:d.map(b=>{const S=String(b.id??b.filePath??b.title??"product"),P=Array.isArray(b.usesDomains)?b.usesDomains.map(String):[],q=String(b.name??b.title??S);return e.jsxs("button",{type:"button",onClick:()=>void v(b),"aria-label":`Open ${s==="notebooks"?"notebook":"app"} ${q}`,style:{...Tt(o),width:"100%",textAlign:"left",cursor:"pointer"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(Gt,{size:14,color:o.accent}),e.jsx("b",{children:q}),b.lifecycle?e.jsx(qt,{t:o,children:String(b.lifecycle)}):null,u===S?e.jsx(qt,{t:o,children:"Opening…"}):null]}),e.jsx("p",{style:{color:o.textSecondary,fontSize:11,margin:"7px 0 0"},children:String(b.purpose??"No analytical purpose declared yet.")}),e.jsx("code",{style:{display:"block",marginTop:7,color:o.textMuted,fontSize:10},children:String(b.filePath??"")}),e.jsxs("div",{style:{marginTop:7,color:o.textMuted,fontSize:10},children:["Owner: ",String(b.ownerDomain??"Shared")," · Uses: ",P.join(", ")||"none declared"]})]},S)})}):x.length?e.jsxs("div",{style:{display:"grid",gap:10},children:[e.jsx(fe,{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:o}),x.map(b=>e.jsxs("button",{type:"button",onClick:()=>void v({id:s==="apps"?Qn(b):b,filePath:b}),"aria-label":`Open ${s==="notebooks"?"notebook":"app"} ${b}`,style:{...Tt(o),width:"100%",textAlign:"left",cursor:"pointer"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(Gt,{size:14,color:o.accent}),e.jsx("code",{style:{color:o.textPrimary,fontSize:11},children:b})]}),e.jsx("p",{style:{color:o.textMuted,fontSize:10,margin:"7px 0 0"},children:"Legacy backlink · migrate without duplicating the product."})]},b))]}):e.jsx(on,{title:`No related ${I.toLowerCase()} yet`,detail:`Create the ${s==="notebooks"?"notebook":"app"} from the global ${I} surface, then declare this domain in its product context to make the backlink appear here.`,t:o})]})}function Qn(t){const n=t.replace(/\\/g,"/").split("/").filter(Boolean),s=n.indexOf("apps");return s>=0?n[s+1]??"":""}function Xs({domain:t,areaId:n,selectedId:s,data:o,themeMode:i,t:r,correction:d,onClose:h,onCorrectionStarted:y,onReviewProposal:l,onPreviewProposal:u,onOpenSkills:m,onDraftRelationship:f}){const{threadId:c,onThreadIdChange:x}=rs(Jo(t)),I=s?o.modeling.relationships[s]:void 0,v=s?o.modeling.entities[s]:void 0,w=n?o.modeling.areas[n]:void 0,B=I?{kind:"relationship",id:I.qualifiedId,title:I.id}:v?{kind:"model",id:v.qualifiedId,title:v.businessName||v.id}:w?{kind:"model_area",id:w.qualifiedId,title:w.name}:t?{kind:"domain",id:t,title:t}:{kind:"workspace",title:"New modeling draft"},[b,S]=a.useState(null),P=N=>{const j=N.payload;(j==null?void 0:j.version)===1&&j.trustState==="review_required"&&(S(j),u(j))},q=()=>{S(null),u(null)};return a.useEffect(()=>()=>u(null),[]),e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[e.jsxs("header",{style:{display:"flex",alignItems:"center",gap:8,padding:"10px 12px",borderBottom:`1px solid ${r.headerBorder}`},children:[e.jsx(Ht,{size:14,color:r.accent}),e.jsx("strong",{style:{fontSize:12},children:"Build with AI"}),e.jsx("span",{style:{marginLeft:"auto"}}),e.jsx("button",{type:"button",onClick:m,style:Xe(r),children:"Skills"}),e.jsx("button",{type:"button",onClick:f,style:Xe(r),children:"Connect manually"}),e.jsx("button",{type:"button","aria-label":"Close Modeling AI",onClick:h,style:{...ze(r),width:26,height:26},children:e.jsx(tt,{size:14})})]}),e.jsxs("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${r.headerBorder}`,color:r.textMuted,fontSize:10.5,lineHeight:1.5},children:[t??"new domain",n?` · ${n}`:"",s?` · focused: ${s}`:""," · ",Object.keys(o.modeling.entities).length," models · ",Object.keys(o.modeling.relationships).length," relationships. Proposals are drafts: nothing is written, certified, or joinable until you save and validate it."]}),b?e.jsxs("div",{role:"status",style:{margin:"10px 12px 0",padding:"10px 11px",border:"1px solid var(--accent)",borderRadius:9,background:"var(--accent-dim)",fontSize:11,lineHeight:1.5},children:[e.jsx("strong",{style:{display:"block",fontSize:11.5},children:"Previewing on the canvas"}),e.jsxs("span",{style:{color:r.textSecondary},children:[b.impact.modelingChanges," modeling change",b.impact.modelingChanges===1?"":"s"," shown as dashed outlines. Nothing is saved yet."]}),e.jsxs("div",{style:{display:"flex",gap:7,marginTop:9},children:[e.jsx("button",{type:"button",onClick:()=>{l(b)},style:{...Ge(r,!0),minHeight:27},children:"Review exact changes"}),e.jsx("button",{type:"button",onClick:q,style:{...Ge(r),minHeight:27},children:"Discard"})]})]}):null,e.jsx("div",{style:{flex:1,minHeight:0,margin:"10px 12px 12px",border:`1px solid ${r.headerBorder}`,borderRadius:10,overflow:"hidden"},children:e.jsx(ds,{themeMode:i,title:"Modeling AI",scopeHint:"Modeling proposal · metadata only · explicit draft save",composerPlaceholder:"Describe the model you want…",initialMode:"modeling",selectedObject:B,workspaceContext:{surface:"modeling",domain:t,modelAreaId:n,snapshotId:o.snapshotId,focusedObjectId:s,providerSafety:"no_query_rows",...d?{correction:!0,validationReceipt:d.evidence}:{}},threadId:c,onThreadIdChange:x,autoRun:d?{text:d.text,mode:"modeling",nonce:d.nonce}:void 0,onRunningChange:N=>{N&&d&&y()},onReviewAuthoringProposal:N=>P(N),emptyHint:"Describe the models and relationships you want. Every model and column is checked against the current dbt snapshot before anything is proposed.",examplePrompts:[{label:"Model this area",prompt:"Bind the relevant unbound dbt models for this area, write business context for each, and connect them with draft relationships."},{label:"Describe this model",prompt:"Write the business context and grain for the focused model using only dbt metadata evidence."},{label:"Connect these models",prompt:"Propose draft relationships between the models in this area and explain the evidence for each key pair."}]})})]})}function Zs({entity:t,detail:n,relationships:s=[],t:o,onEdit:i,onEditDbtSource:r,onSelectRelationship:d,onDelete:h}){var f,c,x,I;const y=oo(t.analyticalRole),l=new Set(t.keys.length?t.keys:((f=n==null?void 0:n.dqlMeta)==null?void 0:f.keys)??[]),u={fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:o.textMuted,margin:"0 0 5px"},m=s.filter(v=>v.from===t.id||v.to===t.id||v.from===t.localId||v.to===t.localId);return e.jsxs(ln,{t:o,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:y,flexShrink:0}}),e.jsx("span",{style:{flex:1,minWidth:0,fontSize:13.5,fontWeight:700,color:o.textPrimary,fontFamily:o.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:y},children:t.analyticalRole??"entity"})]}),e.jsx("p",{style:{margin:"0 0 12px",color:o.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:u,children:"dbt binding"}),e.jsx("div",{style:{fontSize:11,fontFamily:o.fontMono,color:o.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:u,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(v=>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:o.fontMono,color:l.has(v.name)?"var(--pk)":/(^|_)id$/.test(v.name)?"var(--fk)":"transparent"},children:l.has(v.name)?"PK":/(^|_)id$/.test(v.name)?"FK":"·"}),e.jsx("span",{style:{flex:1,minWidth:0,color:o.textSecondary,fontFamily:o.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:v.name}),e.jsx("span",{style:{flexShrink:0,fontSize:10,color:o.textMuted,fontFamily:o.fontMono},children:v.type??"—"})]},v.name))})]}),m.length>0&&d?e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:u,children:"Relationships"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:m.map(v=>e.jsxs("button",{type:"button",onClick:()=>d(v),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:o.font,fontSize:11,color:o.textSecondary},children:[e.jsx("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:v.localId}),e.jsx("span",{style:{fontFamily:o.fontMono,fontSize:10,color:o.textMuted,flexShrink:0},children:v.cardinality==="one_to_one"?"1:1":v.cardinality==="one_to_many"?"1:N":v.cardinality==="many_to_one"?"N:1":"N:N"})]},v.qualifiedId??v.localId))})]}):null,e.jsxs("details",{style:{marginBottom:12},children:[e.jsx("summary",{style:{...u,cursor:"pointer"},children:"More metadata"}),e.jsx(le,{label:"concepts",value:((c=t.conceptRefs)==null?void 0:c.join(", "))||"Not mapped",t:o}),e.jsx(le,{label:"owner",value:t.owner??"Not declared",t:o}),e.jsx(le,{label:"grain",value:t.grain??((x=n==null?void 0:n.dqlMeta)==null?void 0:x.grain)??"Not declared",t:o}),e.jsx(le,{label:"keys",value:(t.keys.length?t.keys:((I=n==null?void 0:n.dqlMeta)==null?void 0:I.keys)??[]).join(", ")||"Not declared",t:o}),e.jsx(le,{label:"source",value:(n==null?void 0:n.sourcePath)??t.sourcePath,t:o}),e.jsx(le,{label:"dbt description",value:(n==null?void 0:n.description)??"Not declared",t:o})]}),e.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[e.jsx(se,{primary:!0,t:o,onClick:i,children:"Edit entity"}),e.jsx(se,{t:o,onClick:r,children:"Preview dbt source patch"}),h?e.jsx(se,{t:o,danger:!0,onClick:h,children:"Delete entity"}):null]})]})}function ei({entity:t,detail:n,snapshotId:s,t:o,onClose:i,onApplied:r}){const d=n.columns.filter(S=>S.tests.length>0).map(S=>`${S.name}: ${S.tests.join(", ")}`).join(`
|
|
22
|
+
`),[h,y]=a.useState(n.description??""),[l,u]=a.useState(d),[m,f]=a.useState(null),[c,x]=a.useState(!1),[I,v]=a.useState(null),w=()=>({uniqueId:t.dbtUniqueId,description:h,columns:l.split(/\r?\n/).flatMap(S=>{const P=S.indexOf(":");if(P<1)return[];const q=S.slice(0,P).trim(),N=Y(S.slice(P+1));return q?[{name:q,tests:N}]:[]})}),B=async()=>{try{x(!0),v(null),f(await Z.previewDbtSourcePatch(w(),s))}catch(S){v(S instanceof Error?S.message:String(S))}finally{x(!1)}},b=async()=>{if(m)try{x(!0),v(null),await Z.applyDbtSourcePatch(w(),m.fingerprint,m.snapshotId),await r()}catch(S){v(S instanceof Error?S.message:String(S))}finally{x(!1)}};return e.jsxs(yo,{title:`Edit dbt source · ${n.name}`,t:o,onClose:i,children:[e.jsx(fe,{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:o}),m?e.jsxs("div",{style:{display:"grid",gap:10},children:[e.jsxs("div",{style:{color:o.textSecondary,fontSize:11},children:["Source: ",e.jsx("code",{children:m.patch.path})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[e.jsx(Gn,{title:"Current dbt YAML",source:m.patch.before||"# New dbt schema YAML",t:o}),e.jsx(Gn,{title:"Proposed dbt YAML",source:m.patch.after,t:o})]}),I&&e.jsx(fe,{text:I,t:o}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:7},children:[e.jsx(se,{t:o,onClick:()=>f(null),children:"Back"}),e.jsx(se,{primary:!0,t:o,disabled:c||!m.patch.changed,onClick:()=>void b(),children:m.patch.changed?"Apply dbt source patch":"No changes"})]})]}):e.jsxs("div",{style:{display:"grid",gap:12},children:[e.jsx(z,{label:"Model description",children:e.jsx("textarea",{"aria-label":"Model description",value:h,onChange:S=>y(S.target.value),rows:5,style:{...ye(o),resize:"vertical"}})}),e.jsx(z,{label:"Column tests (one column per line)",children:e.jsx("textarea",{"aria-label":"Column tests",value:l,onChange:S=>u(S.target.value),rows:6,placeholder:"order_id: unique, not_null",style:{...ye(o),resize:"vertical",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace"}})}),e.jsx("p",{style:{margin:0,color:o.textMuted,fontSize:10},children:"Descriptions/tests stay in dbt YAML. Business meaning, relationships, contracts, and policies stay in the DQL Domain Package."}),I&&e.jsx(fe,{text:I,t:o}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:7},children:[e.jsx(se,{t:o,onClick:i,children:"Cancel"}),e.jsx(se,{primary:!0,t:o,disabled:c,onClick:()=>void B(),children:"Preview source patch"})]})]})]})}function Gn({title:t,source:n,t:s}){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:s.appBg,border:`1px solid ${s.headerBorder}`,borderRadius:6,padding:10,fontSize:9.5,color:s.textSecondary},children:n})]})}function ti({relationship:t,t:n,onEdit:s,onDelete:o}){var i,r,d;return e.jsxs(ln,{t:n,children:[e.jsx(ai,{title:t.localId,subtitle:`${t.from} → ${t.to}`,t:n}),e.jsx(se,{primary:!0,t:n,onClick:s,children:"Validate / edit"}),e.jsx("h3",{style:no(n),children:"Business meaning"}),e.jsx(le,{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:no(n),children:"Join route"}),e.jsx(le,{label:"cardinality",value:t.cardinality,t:n}),e.jsx(le,{label:"fanout",value:t.fanout,t:n}),e.jsx(le,{label:"lifecycle",value:t.status,t:n}),e.jsx(le,{label:"join keys",value:t.keys.map(h=>`${h.from} = ${h.to}`).join(", "),t:n}),e.jsx(le,{label:"endpoint roles",value:[(i=t.roles)==null?void 0:i.from,(r=t.roles)==null?void 0:r.to].filter(Boolean).join(" → ")||"Not declared",t:n}),e.jsx(le,{label:"allowed joins",value:((d=t.joinTypes)==null?void 0:d.join(", "))||"left",t:n}),e.jsx(le,{label:"automatic agent join",value:t.automaticJoinAllowed?"Allowed":"Blocked",t:n}),t.validation?e.jsx(fo,{evidence:t.validation,t:n}):e.jsx(fe,{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(se,{primary:!0,t:n,onClick:s,children:"Edit relationship"}),o?e.jsx(se,{t:n,danger:!0,onClick:o,children:"Delete relationship"}):null]})]})}function ni({data:t,domainEntities:n,domainRelationships:s,t:o,onSelectRelationship:i}){var f;const r=((f=n[0])==null?void 0:f.domain)??"All domains",d=s.filter(c=>{var x;return((x=c.validation)==null?void 0:x.status)==="passed"}).length,h=n.filter(c=>!!c.dbtUniqueId).length,y=n.filter(c=>!c.businessContext),l={fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:o.textMuted,margin:"14px 0 5px"},u=(c,x)=>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:o.textPrimary},children:c}),e.jsx("div",{style:{fontSize:10.5,color:o.textMuted},children:x})]}),m=(c,x)=>e.jsxs("span",{style:{display:"flex",alignItems:"flex-start",gap:7,fontSize:11.5,color:o.textSecondary,lineHeight:1.45},children:[e.jsx("span",{style:{color:c?"var(--status-success)":"var(--status-warning)",flexShrink:0,fontWeight:700},children:c?"✓":"△"}),x]},x);return e.jsxs(ln,{t:o,children:[e.jsxs("div",{style:{fontSize:11,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:o.textMuted},children:[r," model"]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8,marginTop:12},children:[u(n.length,n.length===1?"entity":"entities"),u(s.length,s.length===1?"relationship":"relationships")]}),e.jsx("p",{style:{margin:"12px 0 0",color:o.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:l,children:"Model health"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[s.length>0?m(d===s.length,d===s.length?"All relationships have join proofs":`${d} of ${s.length} relationships have join proofs`):m(!1,"No relationships yet — drag between column handles to create one"),m(h===n.length&&n.length>0,n.length===0?"No entities bound yet — use Bind model":`${h} of ${n.length} entities bound to dbt`),y.length>0?m(!1,`${y[0].localId}${y.length>1?` and ${y.length-1} more`:""} ha${y.length>1?"ve":"s"} no business description`):n.length>0?m(!0,"Every entity has a business description"):null]}),e.jsx("div",{style:l,children:"Relationships"}),s.length?s.map(c=>e.jsxs("button",{onClick:()=>i(c),style:{display:"flex",alignItems:"center",gap:7,width:"100%",textAlign:"left",border:"1px solid var(--border-subtle)",borderRadius:7,background:"var(--bg-1)",color:o.textSecondary,padding:"6px 8px",marginBottom:4,cursor:"pointer",fontSize:11,fontFamily:o.font},children:[e.jsx("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.localId}),e.jsx("span",{style:{fontFamily:o.fontMono,fontSize:10,color:o.textMuted,flexShrink:0},children:c.cardinality==="one_to_one"?"1:1":c.cardinality==="one_to_many"?"1:N":c.cardinality==="many_to_one"?"N:1":"N:N"})]},c.qualifiedId)):e.jsx("p",{style:{color:o.textMuted,fontSize:10.5,margin:0},children:"Drag between two column handles to create the first relationship."}),e.jsx("div",{style:l,children:"Ownership boundary"}),e.jsx("p",{style:{color:o.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 fo({evidence:t,t:n,onFixWithAi:s}){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]}),s?e.jsxs("button",{type:"button",onClick:s,style:{...Xe(n),marginTop:9},children:[e.jsx(Ht,{size:13})," Fix with Modeling AI"]}):null]})}function Xn({t,title:n,detail:s,status:o}){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(Ze,{size:34,color:t.accent}),e.jsx("h1",{style:{fontSize:20},children:n}),e.jsx("p",{style:{color:t.textSecondary,lineHeight:1.6},children:s}),o&&e.jsx("code",{style:{fontSize:12},children:o})]})})}function yo({title:t,t:n,onClose:s,children:o}){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&&s()},children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":t,tabIndex:-1,onKeyDown:i=>{i.key==="Escape"&&s()},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:s,style:ze(n),children:e.jsx(tt,{size:17})})]}),e.jsx("div",{style:{padding:18},children:o})]})})}function Zn({current:t,labels:n,t:s}){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((o,i)=>{const r=i+1,d=r===t,h=r<t;return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0,color:d?s.textPrimary:s.textMuted,fontSize:10,fontWeight:d?700:550},children:[e.jsx("span",{style:{display:"grid",placeItems:"center",width:20,height:20,flex:"0 0 auto",borderRadius:999,border:`1px solid ${d||h?s.accent:s.headerBorder}`,background:h?s.accent:d?"var(--accent-dim)":s.appBg,color:h?"#fff":d?s.accent:s.textMuted},children:h?"✓":r}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:o})]},o)})})}function eo({title:t,detail:n,t:s}){return e.jsxs("div",{style:{display:"grid",gap:3,padding:"9px 11px",border:`1px solid ${s.headerBorder}`,borderRadius:7,background:s.cellBg},children:[e.jsx("strong",{style:{fontSize:11},children:t}),e.jsx("span",{style:{color:s.textMuted,fontSize:9.5,overflowWrap:"anywhere"},children:n})]})}function Nt({ariaLabel:t,value:n,onChange:s,options:o,placeholder:i,disabled:r=!1,t:d}){const[h,y]=a.useState(!1),[l,u]=a.useState(""),m=o.find(c=>c.value===n),f=_s(o,l,50);return e.jsxs("div",{style:{position:"relative",minWidth:0},children:[e.jsxs("div",{style:{position:"relative"},children:[e.jsx(Ft,{size:13,"aria-hidden":"true",style:{position:"absolute",left:9,top:"50%",transform:"translateY(-50%)",color:d.textMuted,pointerEvents:"none"}}),e.jsx("input",{role:"combobox","aria-label":t,"aria-expanded":h,"aria-controls":h?"modeling-search-results":void 0,disabled:r,value:h?l:(m==null?void 0:m.label)??n,placeholder:i,onFocus:()=>{y(!0),u("")},onBlur:()=>{y(!1),u("")},onChange:c=>{y(!0),u(c.target.value)},onKeyDown:c=>{c.key==="Escape"&&(y(!1),u(""))},style:{...ye(d),paddingLeft:29,paddingRight:n?29:8,opacity:r?.6:1}}),n&&!r&&e.jsx("button",{type:"button","aria-label":"Clear selection",onMouseDown:c=>c.preventDefault(),onClick:()=>{s(""),u(""),y(!0)},style:{...ze(d),position:"absolute",right:3,top:"50%",transform:"translateY(-50%)",width:24,height:24,border:"none"},children:e.jsx(tt,{size:13})})]}),h&&!r&&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 ${d.headerBorder}`,borderRadius:7,background:d.cellBg,boxShadow:"0 12px 32px #0004",padding:4},children:[f.length?f.map(c=>e.jsxs("button",{type:"button",role:"option","aria-selected":c.value===n,onMouseDown:x=>x.preventDefault(),onClick:()=>{s(c.value),y(!1),u("")},style:{display:"grid",width:"100%",gap:2,padding:"8px 9px",border:"none",borderRadius:5,textAlign:"left",background:c.value===n?"var(--accent-dim)":"transparent",color:d.textPrimary,cursor:"pointer"},children:[e.jsx("strong",{style:{fontSize:10.5},children:c.label}),c.description&&e.jsx("span",{style:{color:d.textMuted,fontSize:9,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.description})]},c.value)):e.jsx("div",{style:{padding:12,color:d.textMuted,fontSize:10},children:"No matching results."}),o.length>50&&e.jsxs("div",{style:{padding:"6px 9px 4px",borderTop:`1px solid ${d.headerBorder}`,color:d.textMuted,fontSize:9},children:["Showing the best 50 of ",o.length.toLocaleString(),". Refine your search for a specific result."]})]})]})}function oi({value:t,onChange:n,selectedNode:s,t:o}){const[i,r]=a.useState(""),[d,h]=a.useState(!1),[y,l]=a.useState(!1),[u,m]=a.useState(0),[f,c]=a.useState([]);return a.useEffect(()=>{let x=!1;const I=window.setTimeout(()=>{l(!0),Z.getDbtModelInventory({q:i,limit:50}).then(v=>{x||(m(v.total),c(v.items.map(w=>{var b;const B=w;return{value:B.uniqueId??"",label:B.name??B.uniqueId??"Unnamed model",description:`${B.relation??B.sourcePath??B.uniqueId}${B.binding?` · already bound to ${B.binding.domain??"a domain"}`:" · unbound"}`,keywords:[B.sourcePath??"",((b=B.binding)==null?void 0:b.businessName)??""]}}).filter(w=>w.value)))}).catch(()=>{x||c([])}).finally(()=>{x||l(!1)})},140);return()=>{x=!0,window.clearTimeout(I)}},[i]),e.jsxs("div",{style:{position:"relative"},children:[e.jsxs("div",{style:{position:"relative"},children:[e.jsx(Ft,{size:13,"aria-hidden":"true",style:{position:"absolute",left:9,top:"50%",transform:"translateY(-50%)",color:o.textMuted,pointerEvents:"none"}}),e.jsx("input",{role:"combobox","aria-label":"Search dbt models","aria-expanded":d,value:d?i:(s==null?void 0:s.name)??t,placeholder:"Search model, relation, or path…",onFocus:()=>{h(!0),r("")},onBlur:()=>{h(!1),r("")},onChange:x=>{r(x.target.value),h(!0)},onKeyDown:x=>{x.key==="Escape"&&h(!1)},style:{...ye(o),paddingLeft:29,paddingRight:t?29:8}}),t&&e.jsx("button",{type:"button","aria-label":"Clear dbt model",onMouseDown:x=>x.preventDefault(),onClick:()=>{n(""),h(!0)},style:{...ze(o),position:"absolute",right:3,top:"50%",transform:"translateY(-50%)",width:24,height:24,border:"none"},children:e.jsx(tt,{size:13})})]}),d&&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 ${o.headerBorder}`,borderRadius:7,background:o.cellBg,boxShadow:"0 12px 32px #0004",padding:4},children:[y&&e.jsx("div",{style:{padding:10,color:o.textMuted,fontSize:10},children:"Searching project inventory…"}),!y&&f.map(x=>e.jsxs("button",{type:"button",role:"option","aria-selected":x.value===t,onMouseDown:I=>I.preventDefault(),onClick:()=>{n(x.value),h(!1),r("")},style:{display:"grid",width:"100%",gap:2,padding:"8px 9px",border:"none",borderRadius:5,textAlign:"left",background:x.value===t?"var(--accent-dim)":"transparent",color:o.textPrimary,cursor:"pointer"},children:[e.jsx("strong",{style:{fontSize:10.5},children:x.label}),e.jsx("span",{style:{color:o.textMuted,fontSize:9,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:x.description})]},x.value)),!y&&!f.length&&e.jsx("div",{style:{padding:10,color:o.textMuted,fontSize:10},children:"No dbt models match this search."}),!y&&u>f.length&&e.jsxs("div",{style:{padding:"6px 9px 4px",borderTop:`1px solid ${o.headerBorder}`,color:o.textMuted,fontSize:9},children:["Showing 50 of ",u.toLocaleString(),". Keep typing to narrow the inventory."]})]})]})}function z({label:t,children:n}){return e.jsxs("label",{style:{display:"grid",gap:6,fontSize:11,fontWeight:650},children:[t,n]})}function _({value:t,onChange:n,t:s,placeholder:o}){return e.jsx("input",{value:t,placeholder:o,onChange:i=>n(i.target.value),style:ye(s)})}function ae({value:t,onChange:n,values:s,labels:o,t:i}){return e.jsxs("select",{value:t,onChange:r=>n(r.target.value),style:ye(i),children:[e.jsx("option",{value:"",children:"Select…"}),s.map(r=>e.jsx("option",{value:r,children:(o==null?void 0:o[r])??r},r))]})}function se({children:t,t:n,onClick:s,primary:o,disabled:i,danger:r}){return e.jsx("button",{disabled:i,onClick:s,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,border:`1px solid ${r?n.error:o?n.accent:n.headerBorder}`,background:r?`${n.error}12`:o?n.accent:n.appBg,color:r?n.error:o?"#fff":n.textPrimary,borderRadius:6,padding:"7px 10px",fontSize:11,fontWeight:650,cursor:i?"wait":"pointer",opacity:i?.65:1},children:t})}function si({children:t,title:n,t:s,onClick:o}){return e.jsx("button",{"aria-label":n,title:n,onClick:o,style:ze(s),children:t})}function qt({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 ii({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 bo({children:t}){return e.jsx("div",{style:{height:"100%",overflow:"auto",padding:20},children:t})}function jo({title:t,detail:n,t:s,action:o}){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:s.textSecondary,fontSize:11},children:n})]}),o]})}function on({title:t,detail:n,t:s}){return e.jsxs("div",{style:{border:`1px dashed ${s.headerBorder}`,borderRadius:10,padding:30,textAlign:"center"},children:[e.jsx("strong",{children:t}),e.jsx("p",{style:{color:s.textSecondary,fontSize:12},children:n})]})}function ln({children:t}){return e.jsx("div",{style:{padding:"4px 14px 20px"},children:t})}function ai({title:t,subtitle:n,t:s}){return e.jsxs("div",{style:{marginBottom:14},children:[e.jsx("h2",{style:{margin:0,fontSize:16},children:t}),e.jsx("div",{style:{color:s.textMuted,fontSize:11,marginTop:4},children:n})]})}function le({label:t,value:n,t:s}){return e.jsxs("div",{style:{padding:"9px 0",borderBottom:`1px solid ${s.headerBorder}`},children:[e.jsx("div",{style:{color:s.textMuted,fontSize:9,textTransform:"uppercase",letterSpacing:".05em"},children:t}),e.jsx("div",{style:{fontSize:11,marginTop:4,overflowWrap:"anywhere"},children:n})]})}function fe({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 Y(t){return t.split(",").map(n=>n.trim()).filter(Boolean)}function li(t){return Y(t).map(n=>{const[s,o]=n.split("=").map(i=>i.trim());if(!s||!o)throw new Error(`Invalid join key pair "${n}". Use from_key=to_key.`);return{from:s,to:o}})}function to(){try{return JSON.parse(localStorage.getItem("dql-modeling-preferences")??"{}")}catch{return{}}}const ne={display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},Ge=(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"}),ye=t=>({width:"100%",boxSizing:"border-box",border:`1px solid ${t.headerBorder}`,background:t.cellBg,color:t.textPrimary,borderRadius:6,padding:"8px 9px",fontSize:11}),ze=t=>({border:`1px solid ${t.headerBorder}`,background:t.appBg,color:t.textSecondary,borderRadius:6,padding:7,display:"grid",placeItems:"center",cursor:"pointer"}),ri=(t,n,s)=>({width:"100%",minHeight:30,padding:s?"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"}),Xe=t=>({border:0,background:"transparent",color:t.accent,fontSize:10,fontWeight:650,cursor:"pointer"}),no=t=>({margin:"18px 0 7px",paddingBottom:7,borderBottom:`1px solid ${t.headerBorder}`,fontSize:11,textTransform:"uppercase",letterSpacing:".05em",color:t.textMuted}),Tt=t=>({border:`1px solid ${t.headerBorder}`,background:t.cellBg,borderRadius:9,padding:14});export{Ri as DbtFirstModelingPage};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as Ye,t as Ze,h as et,r as d,a as g,j as t,a0 as we,G as ne,d as tt,g as re,P as nt,aD as rt,aE as ze,ap as it,l as st,aF as ot,S as lt}from"./index-
|
|
1
|
+
import{c as Ye,t as Ze,h as et,r as d,a as g,j as t,a0 as we,G as ne,d as tt,g as re,P as nt,aD as rt,aE as ze,ap as it,l as st,aF as ot,S as lt}from"./index-9w93YPF9.js";import{E as $e}from"./external-link-DprWh9Yf.js";import{X as at}from"./x-CcYceFMz.js";import"./react-CRB3T2We.js";/**
|
|
2
2
|
* @license lucide-react v0.563.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{u as h,t as g,r as x,j as l,a as b}from"./index-9w93YPF9.js";import{U as E}from"./UnifiedAgentRunPanel-DBfsmXes.js";import{A as P,a as _,b as w}from"./AiSidePanel-MRSGtQDV.js";import{u as I}from"./usePersistedAgentThreadId-Cv7Yq2hK.js";import"./react-CRB3T2We.js";import"./AiBuildResult-D-6G4Sh3.js";import"./user-round-Do21aFGo.js";import"./triangle-alert-BWrCxQVE.js";import"./rotate-ccw-ELiDRUmj.js";import"./x-CcYceFMz.js";import"./list-tree-BipBLmIE.js";import"./wrench-7tYr_GKb.js";import"./minimize-2-BhXsglrO.js";import"./arrow-right-Ct_YGrmU.js";import"./TrustBadge-ClEYiYeA.js";function M(){const{state:o,dispatch:i}=h(),r=g[o.themeMode],{audience:d,context:e}=o.globalAi,m=e.selectedObject,s=I("global-rail"),[a,c]=x.useState(!1),u=(t,n,p)=>{i(p?{type:"OPEN_APP_DRAFT",draftId:p,appId:t,dashboardId:n}:{type:"OPEN_APP",appId:t,dashboardId:n,experience:"view",section:"dashboards"}),i({type:"CLOSE_GLOBAL_AI"}),b.listApps().then(A=>i({type:"SET_APPS",apps:A})).catch(()=>{})};return l.jsx(P,{t:r,title:e.title??"AI copilot",subtitle:e.scopeHint??"Ask a follow-up about what you are viewing",expanded:a,onToggleExpanded:()=>c(t=>!t),resizable:!0,minResizeWidth:360,maxResizeWidth:1200,onClose:()=>i({type:"CLOSE_GLOBAL_AI"}),ariaLabel:"App AI",style:{position:"relative",width:a?`min(${_}px, calc(100vw - 96px))`:`min(${w}px, calc(100vw - 64px))`,maxWidth:a?"62vw":"46vw",minWidth:320,flex:"0 0 auto"},children:l.jsx(E,{themeMode:o.themeMode,title:e.title??"AI copilot",scopeHint:e.scopeHint??"Ask a follow-up about what you are viewing",audience:d,selectedObject:m,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:u})})}export{M as GlobalAiRail};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{c as ke,u as ge,t as he,r as a,a as B,j as e,a4 as q,a0 as fe,L,S as Y,P as se,B as we,d as ye,T as re,N as de,l as Ce,aI as me,f as ze}from"./index-9w93YPF9.js";import{T as Be}from"./triangle-alert-BWrCxQVE.js";import{U as ce,G as be}from"./user-round-Do21aFGo.js";import{C as je}from"./UnifiedAgentRunPanel-DBfsmXes.js";import{P as Te}from"./usePersistedAgentThreadId-Cv7Yq2hK.js";import{X as ve}from"./x-CcYceFMz.js";import{S as We}from"./SkillsPage--mYkOAK2.js";import"./react-CRB3T2We.js";import"./AiBuildResult-D-6G4Sh3.js";import"./rotate-ccw-ELiDRUmj.js";import"./list-tree-BipBLmIE.js";import"./wrench-7tYr_GKb.js";import"./minimize-2-BhXsglrO.js";import"./arrow-right-Ct_YGrmU.js";import"./TrustBadge-ClEYiYeA.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 Ie=[["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"}]],De=ke("tags",Ie),U="dql-context-bootstrap-session",J="dql-context-bootstrap-selection";function Re(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").slice(0,64)}function pe(t){return t.toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,64)}function Ee(){return{id:"",name:"",owner:"",boundedContext:"",sourceSystems:[],description:""}}function $e({embedded:t=!1}={}){const{state:i,dispatch:r}=ge(),n=he[i.themeMode],[o,c]=a.useState([]),[h,s]=a.useState(!0),[y,T]=a.useState(null),[z,b]=a.useState(null),[v,S]=a.useState(null),[p,d]=a.useState(!1),[w,C]=a.useState(null),[g,E]=a.useState(null),[u,W]=a.useState(!1),[I,M]=a.useState(!1),[P,D]=a.useState(null),[x,A]=a.useState([]),$=a.useCallback(()=>{let l=!1;return s(!0),T(null),B.getDomains().then(f=>{if(l)return;const m=Array.isArray(f==null?void 0:f.domains)?f.domains:[];c(m),r({type:"SET_AUTHORED_DOMAINS",domains:m})}).catch(f=>{l||(c([]),T(f instanceof Error&&f.message?f.message:"Could not load domains. Is the local DQL server running?"))}).finally(()=>{l||s(!1)}),()=>{l=!0}},[r]);a.useEffect(()=>$(),[$]),a.useEffect(()=>{const l=window.sessionStorage.getItem(U);let f=!1;const m=j=>{if(j&&!f){E(j);try{const O=JSON.parse(window.sessionStorage.getItem(J)??"[]");A(Array.isArray(O)?O.filter(K=>typeof K=="string"):j.candidates.filter(K=>K.action!=="unchanged").map(K=>K.id))}catch{A(j.candidates.filter(O=>O.action!=="unchanged").map(O=>O.id))}}};return(l?B.getContextBootstrap(l):B.getLatestContextBootstrap()).then(m).catch(async()=>{window.sessionStorage.removeItem(U),window.sessionStorage.removeItem(J),l&&m(await B.getLatestContextBootstrap().catch(()=>null))}),()=>{f=!0}},[]),a.useEffect(()=>{g&&(window.sessionStorage.setItem(U,g.id),window.sessionStorage.setItem(J,JSON.stringify(x)))},[g==null?void 0:g.id,x]);const G=a.useMemo(()=>[...o].sort((l,f)=>l.name.localeCompare(f.name)),[o]),Q=a.useCallback(l=>{c(f=>{const m=f.findIndex(j=>j.id===l.id),k=m===-1?[...f,l]:[...f];return m!==-1&&(k[m]=l),r({type:"SET_AUTHORED_DOMAINS",domains:k}),k}),b(null)},[r]),V=a.useCallback(async()=>{if(v){d(!0),C(null);try{await B.deleteDomain(v.id),c(l=>{const f=l.filter(m=>m.id!==v.id);return r({type:"SET_AUTHORED_DOMAINS",domains:f}),f}),S(null)}catch(l){C(l instanceof Error&&l.message?l.message:"Could not delete this domain.")}finally{d(!1)}}},[r,v]),_=a.useCallback(async()=>{W(!0),D(null);try{const l=await B.startContextBootstrap({ai:!0});E(l);const f=l.candidates.filter(m=>m.action!=="unchanged").map(m=>m.id);A(f),window.sessionStorage.setItem(U,l.id),window.sessionStorage.setItem(J,JSON.stringify(f))}catch(l){D(l instanceof Error?l.message:"Could not draft repository context.")}finally{W(!1)}},[]);a.useEffect(()=>{if(!t)return;const l=()=>{_()};return window.addEventListener("dql:context-build",l),()=>window.removeEventListener("dql:context-build",l)},[t,_]),a.useEffect(()=>{if(!g||["ready","needs_attention"].includes(g.status))return;let l=!1;const f=async()=>{try{const k=await B.getContextBootstrap(g.id);l||E(k)}catch(k){l||D(k instanceof Error?k.message:"Could not update AI draft progress.")}};f();const m=window.setInterval(()=>void f(),750);return()=>{l=!0,window.clearInterval(m)}},[g==null?void 0:g.id,g==null?void 0:g.status]);const X=a.useCallback(async()=>{if(!(!g||x.length===0)){M(!0),D(null);try{await B.saveContextBootstrapSelected(g.id,x),E(null),A([]),window.sessionStorage.removeItem(U),window.sessionStorage.removeItem(J),$()}catch(l){D(l instanceof Error?l.message:"Could not save selected drafts.")}finally{M(!1)}}},[g,x,$]);return e.jsxs("div",{style:{flex:1,minWidth:0,overflow:"auto",background:n.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(q,{size:20,strokeWidth:1.9,color:n.accent}),e.jsx("div",{style:{fontSize:22,fontWeight:700,color:n.textPrimary},children:"Domains"})]}),e.jsx("div",{style:{fontSize:13,color:n.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:()=>$(),title:"Refresh",style:F(n),children:[e.jsx(fe,{size:13,strokeWidth:2})," Refresh"]}),e.jsxs("button",{type:"button",onClick:()=>void _(),disabled:u,style:F(n),children:[u?e.jsx(L,{size:13,strokeWidth:2}):e.jsx(Y,{size:13,strokeWidth:2})," Draft with AI"]}),e.jsxs("button",{type:"button",onClick:()=>b({kind:"create"}),style:te(n),children:[e.jsx(se,{size:14,strokeWidth:2.2})," Add domain"]})]})]}),h?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:n.textMuted,fontSize:13,padding:"40px 0"},children:[e.jsx(L,{size:15,strokeWidth:2})," Loading domains…"]}):y?e.jsx(Oe,{t:n,message:y,onRetry:()=>$()}):G.length===0?e.jsx(Ae,{t:n,onAdd:()=>b({kind:"create"})}):e.jsx("div",{style:{display:"grid",gap:10},children:G.map(l=>e.jsx(Me,{domain:l,t:n,onEdit:()=>b({kind:"edit",domain:l}),onDelete:()=>{C(null),S(l)}},l.id))}),P?e.jsx("div",{style:{marginTop:12},children:e.jsx(ee,{t:n,tone:"error",children:P})}):null,g?e.jsxs("section",{style:{marginTop:18,border:`1px solid ${n.cellBorder}`,borderRadius:10,background:n.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:n.textPrimary},children:"Repository-guided AI draft"}),e.jsx("div",{style:{fontSize:12,color:n.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:I||x.length===0||!["ready","needs_attention"].includes(g.status),onClick:()=>void X(),style:{...te(n),opacity:I||x.length===0||!["ready","needs_attention"].includes(g.status)?.55:1},children:[I?e.jsx(L,{size:13,strokeWidth:2}):e.jsx(se,{size:13,strokeWidth:2})," Save selected drafts"]})]}),e.jsx(Ne,{t:n,session:g}),e.jsx("div",{style:{display:"grid",gap:9,marginTop:12},children:g.candidates.map(l=>{const f=l.action!=="unchanged",m=x.includes(l.id);return e.jsx(Le,{candidate:l,selected:m,selectable:f,disabled:I,t:n,onToggle:()=>A(k=>m?k.filter(j=>j!==l.id):[...k,l.id])},l.id)})})]}):null]}),z?e.jsx(Pe,{mode:z,existingIds:o.map(l=>l.id),domains:o,t:n,onClose:()=>b(null),onSaved:Q}):null,v?e.jsx(He,{domain:v,t:n,deleting:p,error:w,onCancel:()=>{p||S(null)},onConfirm:V}):null]})}function Me({domain:t,t:i,onEdit:r,onDelete:n}){const o=t.sourceSystems??[],[c,h]=a.useState(!1);return e.jsxs("section",{style:{border:`1px solid ${i.cellBorder}`,borderRadius:10,background:i.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:i.textPrimary},children:t.name}),t.parent?e.jsxs("span",{style:le(i),children:["↳ ",t.parent]}):null,t.owner?e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,color:i.textMuted},children:[e.jsx(ce,{size:11,strokeWidth:2})," ",t.owner]}):null,t.businessOwner?e.jsxs("span",{style:le(i),children:[e.jsx(ce,{size:10,strokeWidth:2.2})," Business owner: ",t.businessOwner]}):null]}),t.description?e.jsx("div",{style:{fontSize:12.5,color:i.textSecondary,marginTop:5,lineHeight:1.5},children:t.description}):e.jsx("div",{style:{fontSize:12,color:i.textMuted,marginTop:5,fontStyle:"italic"},children:"No description yet."}),o.length>0?e.jsx("div",{style:{display:"flex",gap:5,marginTop:9,flexWrap:"wrap"},children:o.map(s=>e.jsx("span",{style:ae(i),children:s},s))}):null,e.jsxs("div",{style:{display:"flex",gap:7,marginTop:9,flexWrap:"wrap"},children:[e.jsx(ie,{t:i,icon:e.jsx(we,{size:11,strokeWidth:2}),label:"blocks",count:t.blockCount??0}),e.jsx(ie,{t:i,icon:e.jsx(be,{size:11,strokeWidth:2}),label:"skills",count:t.skillCount??0}),e.jsx(ie,{t:i,icon:e.jsx(De,{size:11,strokeWidth:2}),label:"terms",count:t.termCount??0})]}),c?e.jsxs("div",{style:{display:"grid",gap:9,marginTop:12,paddingTop:11,borderTop:`1px solid ${i.btnBorder}`},children:[t.boundedContext?e.jsx(ue,{t:i,label:"Business boundary",children:t.boundedContext}):null,t.businessOutcome?e.jsx(ue,{t:i,label:"Decision outcome",children:t.businessOutcome}):null,e.jsx(Z,{t:i,label:"In scope",values:t.inScope,empty:"Not defined yet"}),e.jsx(Z,{t:i,label:"Out of scope",values:t.outOfScope,empty:"Not defined yet"}),e.jsx(Z,{t:i,label:"Primary terms",values:t.primaryTerms,empty:"No terms linked yet"}),e.jsx(Z,{t:i,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:()=>h(s=>!s),style:{...F(i),padding:"5px 7px",fontSize:11.5},title:c?"Hide domain details":"Show domain details",children:[c?e.jsx(je,{size:13}):e.jsx(ye,{size:13}),c?"Less":"Details"]}),e.jsx("button",{type:"button",onClick:r,style:oe(i),title:"Edit domain",children:e.jsx(Te,{size:13,strokeWidth:2})}),e.jsx("button",{type:"button",onClick:n,style:oe(i),title:"Delete domain",children:e.jsx(re,{size:13,strokeWidth:2})})]})]})}function Pe({mode:t,existingIds:i,domains:r,t:n,onClose:o,onSaved:c}){const h=t.kind==="edit",[s,y]=a.useState(()=>t.kind==="edit"?{...t.domain}:Ee()),[T,z]=a.useState(h),[b,v]=a.useState(!1),[S,p]=a.useState(null),d=a.useCallback((u,W)=>{y(I=>({...I,[u]:W}))},[]),w=u=>{y(W=>({...W,name:u,...!h&&!T?{id:pe(u)}:{}}))},C=!h&&s.id.length>0&&i.includes(s.id),g=s.id.trim().length>0&&s.name.trim().length>0&&!C&&!b,E=a.useCallback(async()=>{var W,I,M,P,D;const u={...s,id:s.id.trim(),name:s.name.trim(),owner:(W=s.owner)!=null&&W.trim()?s.owner.trim():void 0,businessOwner:(I=s.businessOwner)!=null&&I.trim()?s.businessOwner.trim():void 0,parent:(M=s.parent)!=null&&M.trim()?s.parent.trim():void 0,boundedContext:(P=s.boundedContext)!=null&&P.trim()?s.boundedContext.trim():void 0,description:(D=s.description)!=null&&D.trim()?s.description.trim():void 0,sourceSystems:(s.sourceSystems??[]).map(x=>x.trim()).filter(Boolean),primaryTerms:(s.primaryTerms??[]).map(x=>x.trim()).filter(Boolean),tags:(s.tags??[]).map(x=>x.trim()).filter(Boolean),inScope:(s.inScope??[]).map(x=>x.trim()).filter(Boolean),outOfScope:(s.outOfScope??[]).map(x=>x.trim()).filter(Boolean),dbtGroups:(s.dbtGroups??[]).map(x=>x.trim()).filter(Boolean),dbtPaths:(s.dbtPaths??[]).map(x=>x.trim()).filter(Boolean),dbtTags:(s.dbtTags??[]).map(x=>x.trim()).filter(Boolean),semanticDomains:(s.semanticDomains??[]).map(x=>x.trim()).filter(Boolean),semanticTags:(s.semanticTags??[]).map(x=>x.trim()).filter(Boolean)};v(!0),p(null);try{const x=h?await B.updateDomain(u.id,u):await B.createDomain(u);c(x.domain??u)}catch(x){p(x instanceof Error&&x.message?x.message:"Could not save this domain. Try again.")}finally{v(!1)}},[s,h,c]);return e.jsx("div",{style:Ke,onClick:()=>!b&&o(),children:e.jsxs("div",{style:Ue(n),onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{style:Je(n),children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(q,{size:16,strokeWidth:2,color:n.accent}),e.jsx("div",{style:{fontSize:15,fontWeight:700,color:n.textPrimary},children:h?"Edit domain":"New domain"})]}),e.jsx("button",{type:"button",onClick:()=>!b&&o(),style:oe(n),title:"Close",children:e.jsx(ve,{size:15,strokeWidth:2})})]}),e.jsxs("div",{style:{flex:1,minHeight:0,overflow:"auto",padding:"16px 18px",display:"grid",gap:16},children:[e.jsx(R,{label:"Name",t:n,hint:h?void 0:"A short, human label for this business area.",children:e.jsx("input",{type:"text",value:s.name,onChange:u=>w(u.target.value),placeholder:"Revenue",style:N(n)})}),e.jsxs(R,{label:"ID (slug)",t:n,hint:"Used as the on-disk identifier. Letters, numbers, and dashes.",children:[e.jsx("input",{type:"text",value:s.id,disabled:h,onChange:u=>{z(!0),d("id",Re(u.target.value))},onBlur:()=>d("id",pe(s.id)),placeholder:"revenue",style:{...N(n),fontFamily:n.fontMono,opacity:h?.7:1}}),C?e.jsx(ee,{t:n,tone:"error",children:"A domain with this id already exists."}):null]}),e.jsx(R,{label:"Parent domain",t:n,hint:"Optional. Depth becomes Domain, Subdomain, Microdomain, and beyond.",children:e.jsxs("select",{value:s.parent??"",onChange:u=>d("parent",u.target.value||void 0),style:N(n),children:[e.jsx("option",{value:"",children:"Top-level domain"}),r.filter(u=>u.id!==s.id).map(u=>e.jsx("option",{value:u.id,children:u.name},u.id))]})}),e.jsx(R,{label:"Owner",t:n,hint:"The team or person accountable for this domain.",children:e.jsx("input",{type:"text",value:s.owner??"",onChange:u=>d("owner",u.target.value),placeholder:"finance-analytics",style:N(n)})}),e.jsx(R,{label:"Business owner",t:n,hint:"The stakeholder accountable for business use and definitions.",children:e.jsx("input",{type:"text",value:s.businessOwner??"",onChange:u=>d("businessOwner",u.target.value),placeholder:"Revenue Operations",style:N(n)})}),e.jsx(R,{label:"Bounded context",t:n,hint:"The conceptual boundary this domain owns, e.g. 'recognized revenue and invoicing'.",children:e.jsx("input",{type:"text",value:s.boundedContext??"",onChange:u=>d("boundedContext",u.target.value),placeholder:"Recognized revenue and invoicing",style:N(n)})}),e.jsx(R,{label:"Source systems",t:n,hint:"The upstream systems this domain draws from — type a name and press Enter.",children:e.jsx(ne,{t:n,values:s.sourceSystems??[],onChange:u=>d("sourceSystems",u),placeholder:"Add a source system…"})}),e.jsx(R,{label:"Primary terms",t:n,hint:"Business concepts the agent should use to recognize this domain.",children:e.jsx(ne,{t:n,values:s.primaryTerms??[],onChange:u=>d("primaryTerms",u),placeholder:"Add a term…"})}),e.jsx(R,{label:"Scope tags",t:n,hint:"Short labels used for routing and discovery.",children:e.jsx(ne,{t:n,values:s.tags??[],onChange:u=>d("tags",u),placeholder:"Add a tag…"})}),e.jsx(R,{label:"Description",t:n,hint:"What this domain covers and how it's used.",children:e.jsx("textarea",{value:s.description??"",onChange:u=>d("description",u.target.value),rows:5,placeholder:"All recognized-revenue metrics and the blocks that report them, sourced from the billing warehouse.",style:_e(n)})}),S?e.jsx(ee,{t:n,tone:"error",children:S}):null]}),e.jsxs("div",{style:Ye(n),children:[e.jsx("button",{type:"button",onClick:()=>!b&&o(),style:F(n),children:"Cancel"}),e.jsxs("button",{type:"button",onClick:E,disabled:!g,style:{...te(n),opacity:g?1:.55},children:[b?e.jsx(L,{size:13,strokeWidth:2}):null,b?"Saving…":h?"Save changes":"Create domain"]})]})]})})}function ne({t,values:i,onChange:r,placeholder:n}){const[o,c]=a.useState(""),h=s=>{const y=s.trim();!y||i.includes(y)||(r([...i,y]),c(""))};return e.jsxs("div",{style:{display:"grid",gap:7},children:[i.length>0?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:i.map(s=>e.jsxs("span",{style:qe(t),children:[s,e.jsx("button",{type:"button",onClick:()=>r(i.filter(y=>y!==s)),style:Ge(t),title:"Remove",children:e.jsx(ve,{size:11,strokeWidth:2.4})})]},s))}):null,e.jsx("input",{type:"text",value:o,onChange:s=>c(s.target.value),onKeyDown:s=>{s.key==="Enter"&&(s.preventDefault(),h(o))},placeholder:n,style:N(t)})]})}function Ae({t,onAdd:i}){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(q,{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:i,style:{...te(t),marginTop:4},children:[e.jsx(se,{size:14,strokeWidth:2.2})," Add your first domain"]})]})}function Oe({t,message:i,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(Be,{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:i}),e.jsxs("button",{type:"button",onClick:r,style:{...F(t),marginTop:10},children:[e.jsx(fe,{size:13,strokeWidth:2})," Retry"]})]})]})}function Ne({t,session:i}){var o;const r=!["ready","needs_attention"].includes(i.status),n=i.ai.mode==="evidence_only"?"Evidence-only":i.ai.provider?`${i.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(L,{size:14,strokeWidth:2,color:t.accent}):e.jsx(Y,{size:14,strokeWidth:2,color:t.accent}),e.jsx("strong",{style:{color:t.textPrimary,textTransform:"capitalize"},children:i.status.replace("_"," ")}),e.jsx("span",{children:n}),e.jsxs("span",{children:[i.progress.domains.ready,"/",i.progress.domains.total," domains"]}),e.jsxs("span",{children:[i.progress.skills.ready,"/",i.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,i.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:i.progress.message}),(o=i.warnings)!=null&&o.length?e.jsx("div",{style:{marginTop:7,fontSize:11.5,color:t.warning,lineHeight:1.45},children:i.warnings.slice(-2).join(" ")}):null]})}function Le({candidate:t,selected:i,selectable:r,disabled:n,t:o,onToggle:c}){var v,S,p,d,w,C,g,E,u,W,I,M,P,D,x,A,$,G,Q,V,_,X,l,f,m,k;const[h,s]=a.useState(!1),y=t.kind==="domain",T=((v=t.domain)==null?void 0:v.name)??((S=t.skill)==null?void 0:S.id)??t.id.replace(/^(domain|skill):/,""),z=y?((p=t.domain)==null?void 0:p.description)??((d=t.domain)==null?void 0:d.boundedContext):((w=t.skill)==null?void 0:w.description)??((g=(C=t.skill)==null?void 0:C.body)==null?void 0:g.split(`
|
|
7
|
+
`).find(Boolean)),b=y?[["Business outcome",(E=t.domain)==null?void 0:E.businessOutcome],["In scope",(W=(u=t.domain)==null?void 0:u.inScope)==null?void 0:W.join(" · ")],["Out of scope",(M=(I=t.domain)==null?void 0:I.outOfScope)==null?void 0:M.join(" · ")],["Primary terms",(D=(P=t.domain)==null?void 0:P.primaryTerms)==null?void 0:D.join(" · ")]]:[["Applies when",(A=(x=t.skill)==null?void 0:x.triggers)==null?void 0:A.join(" · ")],["Ask first when",(G=($=t.skill)==null?void 0:$.clarifyWhen)==null?void 0:G.join(" · ")],["Avoid when",(V=(Q=t.skill)==null?void 0:Q.exclusions)==null?void 0:V.join(" · ")],["Preferred metrics",(X=(_=t.skill)==null?void 0:_.preferredMetrics)==null?void 0:X.join(" · ")],["Preferred blocks",(f=(l=t.skill)==null?void 0:l.preferredBlocks)==null?void 0:f.join(" · ")]];return e.jsx("article",{style:{border:`1px solid ${i?`${o.accent}66`:o.btnBorder}`,background:i?`${o.accent}08`:o.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 ${y?"domain":"skill"} ${T}`,type:"checkbox",disabled:!r||n,checked:i,onChange:c,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:o.textPrimary,fontSize:12.5},children:[y?"Domain":"Skill"," · ",T]}),e.jsx("span",{style:le(o),children:t.action.replace("_"," ")}),e.jsxs("span",{style:{fontSize:11,color:o.textMuted},children:[Math.round(t.confidence*100),"% evidence confidence"]})]}),z?e.jsx("p",{style:{marginTop:5,color:o.textSecondary,fontSize:12,lineHeight:1.45},children:z}):e.jsx("p",{style:{marginTop:5,color:o.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(j=>e.jsx("span",{style:ae(o),children:j},j))}),h?e.jsxs("div",{style:{marginTop:9,display:"grid",gap:6,borderTop:`1px solid ${o.btnBorder}`,paddingTop:9},children:[b.filter(([,j])=>!!j).map(([j,O])=>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:o.textMuted},children:j}),e.jsx("span",{style:{color:o.textSecondary},children:O})]},j)),!y&&((m=t.skill)!=null&&m.body)?e.jsx("pre",{style:{margin:0,whiteSpace:"pre-wrap",fontFamily:o.font,fontSize:11.5,color:o.textSecondary,background:o.cellBg,padding:9,borderRadius:6,maxHeight:180,overflow:"auto"},children:t.skill.body}):null,(k=t.notes)!=null&&k.length?e.jsx("div",{style:{fontSize:11.5,color:o.accent},children:t.notes.join(" ")}):null]}):null]}),e.jsxs("button",{type:"button",onClick:()=>s(j=>!j),style:{...F(o),padding:"4px 6px",fontSize:11.5},"aria-expanded":h,children:[h?e.jsx(je,{size:13}):e.jsx(ye,{size:13}),h?"Less":"Review"]})]})})}function He({domain:t,t:i,deleting:r,error:n,onCancel:o,onConfirm:c}){return e.jsx("div",{style:Qe,onClick:o,children:e.jsxs("div",{style:Ve(i),onClick:h=>h.stopPropagation(),children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9},children:[e.jsx(re,{size:16,strokeWidth:2,color:i.error}),e.jsx("div",{style:{fontSize:15,fontWeight:700,color:i.textPrimary},children:"Delete this domain?"})]}),e.jsxs("div",{style:{fontSize:13,color:i.textSecondary,lineHeight:1.55},children:[e.jsx("span",{style:{fontWeight:700,color:i.textPrimary},children:t.name})," will be removed. Blocks, skills, and terms that referenced it will become unassigned. This can't be undone."]}),n?e.jsx(ee,{t:i,tone:"error",children:n}):null,e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[e.jsx("button",{type:"button",onClick:o,disabled:r,style:F(i),children:"Cancel"}),e.jsxs("button",{type:"button",onClick:c,disabled:r,style:{...Fe(i),opacity:r?.6:1},children:[r?e.jsx(L,{size:13,strokeWidth:2}):e.jsx(re,{size:13,strokeWidth:2}),r?"Deleting…":"Delete"]})]})]})})}function ie({t,icon:i,label:r,count:n}){return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11,fontWeight:600,color:n>0?t.textSecondary:t.textMuted,background:t.btnBg,border:`1px solid ${t.btnBorder}`,borderRadius:6,padding:"3px 8px"},children:[i,n," ",r]})}function ue({t,label:i,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:i}),e.jsx("span",{style:{color:t.textSecondary},children:r})]})}function Z({t,label:i,values:r,empty:n}){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:i}),e.jsx("div",{style:{display:"flex",gap:5,flexWrap:"wrap"},children:r!=null&&r.length?r.map(o=>e.jsx("span",{style:ae(t),children:o},o)):e.jsx("span",{style:{color:t.textMuted,fontStyle:"italic"},children:n})})]})}function R({label:t,hint:i,t:r,children:n}){return e.jsxs("div",{style:{display:"grid",gap:6},children:[e.jsx("label",{style:{fontSize:12,fontWeight:700,color:r.textPrimary},children:t}),i?e.jsx("div",{style:{fontSize:11.5,color:r.textMuted,lineHeight:1.45,marginTop:-2},children:i}):null,n]})}function ee({t,tone:i,children:r}){const n=i==="error"?t.error:t.textMuted;return e.jsx("div",{style:{fontSize:11.5,color:n,lineHeight:1.45},children:r})}function te(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 F(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 Fe(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 oe(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 N(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 _e(t){return{...N(t),resize:"vertical",lineHeight:1.5,padding:"9px 11px"}}function le(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 ae(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 qe(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 Ge(t){return{display:"inline-flex",alignItems:"center",justifyContent:"center",border:"none",background:"transparent",color:t.textMuted,cursor:"pointer",padding:2,borderRadius:4}}const Ke={position:"fixed",inset:0,background:"rgba(0, 0, 0, 0.42)",display:"flex",justifyContent:"flex-end",zIndex:60};function Ue(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 Je(t){return{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 18px",borderBottom:`1px solid ${t.headerBorder}`,flexShrink:0}}function Ye(t){return{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:8,padding:"13px 18px",borderTop:`1px solid ${t.headerBorder}`,flexShrink:0}}const Qe={position:"fixed",inset:0,background:"rgba(0, 0, 0, 0.42)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:70,padding:20};function Ve(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 ht({initialTab:t="overview"}){const{state:i}=ge(),r=he[i.themeMode],[n,o]=a.useState(t),[c,h]=a.useState([]),[s,y]=a.useState([]),[T,z]=a.useState(!0);a.useEffect(()=>o(t),[t]);const b=a.useCallback(()=>{let d=!1;return z(!0),Promise.all([B.getDomains(),B.getSkills()]).then(([w,C])=>{d||(h(Array.isArray(w.domains)?w.domains:[]),y(Array.isArray(C.skills)?C.skills:[]))}).catch(()=>{d||(h([]),y([]))}).finally(()=>{d||z(!1)}),()=>{d=!0}},[]);a.useEffect(()=>b(),[b]);const v=a.useMemo(()=>{const d=c.filter(g=>!!(g.businessOwner||g.owner)).length,w=s.filter(g=>!g.status||g.status==="active").length,C=s.filter(g=>g.status==="draft").length;return{ownedDomains:d,activeSkills:w,draftSkills:C}},[c,s]),S=a.useCallback(()=>{o("domains"),window.setTimeout(()=>window.dispatchEvent(new Event("dql:context-build")),50)},[]),p=[{id:"overview",label:"Overview"},{id:"domains",label:"Domains",count:c.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(q,{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:S,style:Se(r),children:[e.jsx(Y,{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:p.map(d=>e.jsxs("button",{type:"button",onClick:()=>o(d.id),style:{border:"none",borderBottom:`2px solid ${n===d.id?r.accent:"transparent"}`,background:"transparent",padding:"9px 12px",color:n===d.id?r.textPrimary:r.textMuted,fontWeight:n===d.id?700:600,cursor:"pointer",fontFamily:r.font,fontSize:12.5},children:[d.label,d.count!==void 0?` · ${d.count}`:""]},d.id))}),n==="overview"?e.jsx(Ze,{t:r,loading:T,domains:c,skills:s,status:v,onBuild:S,onTab:o}):null,n==="domains"?e.jsx($e,{embedded:!0}):null,n==="skills"?e.jsx(We,{embedded:!0}):null,n==="knowledge"?e.jsx(Xe,{t:r,domains:c}):null]})})}function Xe({t,domains:i,initialDomainId:r}){var v,S;const[n,o]=a.useState(r??((v=i[0])==null?void 0:v.id)??""),[c,h]=a.useState(null),[s,y]=a.useState(!1),[T,z]=a.useState(null);a.useEffect(()=>{var p;!n&&((p=i[0])!=null&&p.id)&&o(i[0].id)},[n,i]),a.useEffect(()=>{r&&i.some(p=>p.id===r)&&o(r)},[i,r]),a.useEffect(()=>{if(!n){h(null);return}let p=!1;return y(!0),z(null),B.getDomainKnowledge(n).then(d=>{p||h(d)}).catch(d=>{p||(h(null),z(d instanceof Error?d.message:"Could not load the compiled knowledge capsule."))}).finally(()=>{p||y(!1)}),()=>{p=!0}},[n]);const b=a.useMemo(()=>{const p={};for(const d of(c==null?void 0:c.objects)??[])p[d.kind]=(p[d.kind]??0)+1;return Object.entries(p).sort((d,w)=>w[1]-d[1]||d[0].localeCompare(w[0]))},[c]);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(de,{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:n,onChange:p=>o(p.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"}),[...i].sort((p,d)=>p.name.localeCompare(d.name)).map(p=>e.jsx("option",{value:p.id,children:p.name},p.id))]})]})}),s?e.jsxs("div",{style:{color:t.textMuted,display:"flex",gap:8,alignItems:"center",padding:24},children:[e.jsx(L,{size:15})," Loading compiled knowledge…"]}):null,T?e.jsx("div",{style:{border:`1px solid ${t.error}`,background:t.cellBg,color:t.error,borderRadius:8,padding:12,fontSize:12.5},children:T}):null,c?e.jsxs(e.Fragment,{children:[e.jsxs("section",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:9},children:[e.jsx(H,{t,label:"Objects",value:c.counts.objects,detail:"qualified knowledge",icon:e.jsx(q,{size:16})}),e.jsx(H,{t,label:"Relations",value:c.counts.edges,detail:"provenance + policy",icon:e.jsx(de,{size:16})}),e.jsx(H,{t,label:"Authorized",value:c.counts.routeStates.authorized??0,detail:"safe cross-domain routes",icon:e.jsx(Ce,{size:16})}),e.jsx(H,{t,label:"Blocked / stale",value:(c.counts.routeStates.blocked??0)+(c.counts.routeStates.stale??0),detail:"never auto-joined",icon:e.jsx(me,{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:((S=c.capsule)==null?void 0:S.description)||"Compiled domain boundary and governed references."}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:b.map(([p,d])=>e.jsxs("span",{style:{border:`1px solid ${t.cellBorder}`,background:t.pillBg,color:t.textSecondary,borderRadius:999,padding:"3px 7px",fontSize:11},children:[p.replace(/_/g," ")," · ",d]},p))}),e.jsxs("div",{style:{marginTop:11,color:t.textMuted,fontSize:11},children:["Snapshot ",c.snapshotId.slice(0,12)," · graph ",c.sourceFingerprint.slice(0,12),c.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:c.routes.length?c.routes.map(p=>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:[p.providerDomainId," → ",p.consumerDomainId]}),e.jsx("span",{style:{color:p.state==="authorized"?t.success:p.state==="observed"?t.textMuted:t.warning,fontWeight:700},children:p.state})]}),e.jsx("div",{style:{marginTop:3,color:t.textMuted,fontSize:11},children:p.purpose||p.reasonCodes.join(", ")||"governed route"})]},p.id)):e.jsx("div",{style:{color:t.textMuted,fontSize:12,marginTop:8},children:"No cross-domain routes declared."})})]})]})]}):null]})}function Ze({t,loading:i,domains:r,skills:n,status:o,onBuild:c,onTab:h}){if(i)return e.jsxs("div",{style:{padding:"42px 0",color:t.textMuted,display:"flex",gap:8,alignItems:"center",fontSize:13},children:[e.jsx(L,{size:15})," Loading governed context…"]});const s=[];return r.length?o.ownedDomains<r.length&&s.push(`${r.length-o.ownedDomains} domain${r.length-o.ownedDomains===1?"":"s"} still need an owner.`):s.push("Create a business domain before relying on AI guidance."),n.length||s.push("Draft a domain skill so the agent has governed business guidance."),o.draftSkills&&s.push(`${o.draftSkills} skill${o.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(H,{t,label:"Domains",value:r.length,detail:`${o.ownedDomains} with an owner`,icon:e.jsx(q,{size:17})}),e.jsx(H,{t,label:"Active skills",value:o.activeSkills,detail:"available to the agent",icon:e.jsx(be,{size:17})}),e.jsx(H,{t,label:"Draft skills",value:o.draftSkills,detail:"review before activation",icon:e.jsx(Y,{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(y=>e.jsxs("div",{style:{display:"flex",gap:7,color:t.textSecondary,fontSize:12.5},children:[e.jsx(me,{size:14,color:t.warning}),y]},y))}):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:c,style:Se(t),children:[e.jsx(Y,{size:13})," Build domains & skills with AI"]}),e.jsx("button",{type:"button",onClick:()=>h("domains"),style:xe(t),children:"Manage domains"}),e.jsx("button",{type:"button",onClick:()=>h("skills"),style:xe(t),children:"Manage skills"})]})]})]})}function H({t,label:i,value:r,detail:n,icon:o}){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:[i,o]}),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:n})]})}function Se(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 xe(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"}}export{ht as GovernedContextPage,Xe as Knowledge360};
|
package/dist/assets/dql-notebook/assets/{HelpDocsPage-DMHPsVqP.js → HelpDocsPage-D1lAryYv.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as k,u as z,t as R,r as u,j as e,aC as I}from"./index-
|
|
1
|
+
import{c as k,u as z,t as R,r as u,j as e,aC as I}from"./index-9w93YPF9.js";import"./react-CRB3T2We.js";/**
|
|
2
2
|
* @license lucide-react v0.563.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as ot,r as c,a as q,j as e,u as Be,t as Ye,S as Ie,B as ue,C as rt,b as Je,d as st,e as at,L as lt,f as dt,G as Ne,D as be,N as ct,g as pt}from"./index-
|
|
1
|
+
import{c as ot,r as c,a as q,j as e,u as Be,t as Ye,S as Ie,B as ue,C as rt,b as Je,d as st,e as at,L as lt,f as dt,G as Ne,D as be,N as ct,g as pt}from"./index-9w93YPF9.js";import{T as xt}from"./TrustBadge-ClEYiYeA.js";import{A as he}from"./arrow-right-Ct_YGrmU.js";import{T as Ke}from"./triangle-alert-BWrCxQVE.js";import{B as Ee}from"./book-open-text-DULlwbj6.js";import{W as ut}from"./workflow-DHh2mMbn.js";import"./react-CRB3T2We.js";/**
|
|
2
2
|
* @license lucide-react v0.563.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|