@duckcodeailabs/dql-cli 1.13.1 → 1.13.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/dist/apps-api.d.ts +249 -7
  2. package/dist/apps-api.d.ts.map +1 -1
  3. package/dist/apps-api.js +2855 -160
  4. package/dist/apps-api.js.map +1 -1
  5. package/dist/assets/dql-notebook/assets/{AgentLogPage-D6fgEAEy.js → AgentLogPage-B3ugEb3H.js} +1 -1
  6. package/dist/assets/dql-notebook/assets/{AiBuildDialog-8miXFPse.js → AiBuildDialog-BK_TDNcM.js} +1 -1
  7. package/dist/assets/dql-notebook/assets/{AiBuildResult-DPJ_SI0R.js → AiBuildResult-Cob_Lj05.js} +8 -8
  8. package/dist/assets/dql-notebook/assets/{AiSidePanel-NVA6lZnn.js → AiSidePanel-CzIgxmP9.js} +1 -1
  9. package/dist/assets/dql-notebook/assets/AnalyticsHome-C2vJ2fxY.js +6 -0
  10. package/dist/assets/dql-notebook/assets/AppsView-DEWQ0sHT.js +5588 -0
  11. package/dist/assets/dql-notebook/assets/BlockStudio-CaDNTKMM.js +55 -0
  12. package/dist/assets/dql-notebook/assets/{BusinessArtifactView-DtRMiaF4.js → BusinessArtifactView-zwUOtddi.js} +1 -1
  13. package/dist/assets/dql-notebook/assets/DbtFirstModelingPage-BlnhTMu3.js +22 -0
  14. package/dist/assets/dql-notebook/assets/{GitPage-CazC-eTR.js → GitPage-Coevr9NJ.js} +3 -3
  15. package/dist/assets/dql-notebook/assets/GlobalAiRail-BTZS11x5.js +1 -0
  16. package/dist/assets/dql-notebook/assets/GovernedContextPage-CjyyM_ne.js +7 -0
  17. package/dist/assets/dql-notebook/assets/{HelpDocsPage-DMHPsVqP.js → HelpDocsPage-C1UeP85v.js} +1 -1
  18. package/dist/assets/dql-notebook/assets/{HomePage-DcSI4dnU.js → HomePage-zGPFIvOY.js} +1 -1
  19. package/dist/assets/dql-notebook/assets/{LineageDAG-BJ6xz06u.js → LineageDAG-DbXnQWu3.js} +1 -1
  20. package/dist/assets/dql-notebook/assets/{LineageDetailView-8WrQm-MF.js → LineageDetailView-Ch1Db01I.js} +1 -1
  21. package/dist/assets/dql-notebook/assets/{LineageDrawer-hnqCW_t-.js → LineageDrawer-DLxqJO6D.js} +1 -1
  22. package/dist/assets/dql-notebook/assets/{LineagePathBreadcrumb-B4LZTUsl.js → LineagePathBreadcrumb-B2tNdkr_.js} +3 -3
  23. package/dist/assets/dql-notebook/assets/{MiniLineageGraph-CotnRuxa.js → MiniLineageGraph-0gY-ZwCy.js} +1 -1
  24. package/dist/assets/dql-notebook/assets/{NewBlockModal-DHn-CEEW.js → NewBlockModal-DKVkXD20.js} +1 -1
  25. package/dist/assets/dql-notebook/assets/{NewNotebookModal-BPGp-8oq.js → NewNotebookModal-BUIByvYT.js} +1 -1
  26. package/dist/assets/dql-notebook/assets/{NotebookEditor-B0OTHM6W.js → NotebookEditor-D2fIUxjE.js} +5 -5
  27. package/dist/assets/dql-notebook/assets/{ReadinessPage-CoOIpxWq.js → ReadinessPage-Ci4LyNiQ.js} +1 -1
  28. package/dist/assets/dql-notebook/assets/{SetupOnboarding-DxK_mFzf.js → SetupOnboarding-BF7ai_0t.js} +1 -1
  29. package/dist/assets/dql-notebook/assets/SkillsPage-BgYrgirJ.js +10 -0
  30. package/dist/assets/dql-notebook/assets/{TrustBadge-ZuD5N5Ww.js → TrustBadge-Bob1Laiq.js} +1 -1
  31. package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-IxDUKSG8.js +88 -0
  32. package/dist/assets/dql-notebook/assets/{answer-to-notebook-WAVAYjBv.js → answer-to-notebook-Dk42N0pU.js} +1 -1
  33. package/dist/assets/dql-notebook/assets/{arrow-left-L8odLbyN.js → arrow-left-DKuuTw9l.js} +1 -1
  34. package/dist/assets/dql-notebook/assets/{arrow-right-WIF1V9a9.js → arrow-right-TH8_ufKG.js} +1 -1
  35. package/dist/assets/dql-notebook/assets/{book-open-text-BpqWMa4m.js → book-open-text-B-dcHHn0.js} +1 -1
  36. package/dist/assets/dql-notebook/assets/{circle-x-CQBOM0b0.js → circle-x-BOc2KCZQ.js} +1 -1
  37. package/dist/assets/dql-notebook/assets/{dagre.esm-DlZi7NR3.js → dagre.esm-CPT_vn5p.js} +1 -1
  38. package/dist/assets/dql-notebook/assets/{external-link-DYqdQIGp.js → external-link-DtOfpYc6.js} +1 -1
  39. package/dist/assets/dql-notebook/assets/{grip-vertical-HmUijbwN.js → grip-vertical-B8joDDH9.js} +1 -1
  40. package/dist/assets/dql-notebook/assets/index-B3shyZsg.css +1 -0
  41. package/dist/assets/dql-notebook/assets/index-DJRMz64S.js +635 -0
  42. package/dist/assets/dql-notebook/assets/link-2-DMZPHawg.js +6 -0
  43. package/dist/assets/dql-notebook/assets/{list-tree-DGKqCxmz.js → list-tree-Dw0qlxPK.js} +1 -1
  44. package/dist/assets/dql-notebook/assets/{minimize-2-C8dvqCxX.js → minimize-2-DUiSrPS3.js} +1 -1
  45. package/dist/assets/dql-notebook/assets/{panel-right-open-yuVkIo5n.js → panel-right-open-BrrFrRZQ.js} +1 -1
  46. package/dist/assets/dql-notebook/assets/{bot-CLR1V6dO.js → play-Ced0HT9g.js} +7 -2
  47. package/dist/assets/dql-notebook/assets/{rotate-ccw-Di0kRnrM.js → rotate-ccw-D_9U9o7X.js} +1 -1
  48. package/dist/assets/dql-notebook/assets/{semantic-fields-BMQV0li8.js → semantic-fields-BlDOaonV.js} +1 -1
  49. package/dist/assets/dql-notebook/assets/{sliders-horizontal-alebptlJ.js → sliders-horizontal-BDt6KRGR.js} +1 -1
  50. package/dist/assets/dql-notebook/assets/{star-CgCQbnXc.js → star-CxUbF_BW.js} +1 -1
  51. package/dist/assets/dql-notebook/assets/{triangle-alert-SyuSZ4ht.js → triangle-alert-COWnsSdh.js} +1 -1
  52. package/dist/assets/dql-notebook/assets/upload-DSFC2kJX.js +6 -0
  53. package/dist/assets/dql-notebook/assets/usePersistedAgentThreadId-DYdx896E.js +32 -0
  54. package/dist/assets/dql-notebook/assets/{user-round-J4PQHxo9.js → user-round-Bfu7fosn.js} +1 -1
  55. package/dist/assets/dql-notebook/assets/{wand-sparkles-c4WDXTCk.js → wand-sparkles-DSpG0c0j.js} +1 -1
  56. package/dist/assets/dql-notebook/assets/{workflow-NtRLaq7n.js → workflow-B1_pj9gq.js} +1 -1
  57. package/dist/assets/dql-notebook/assets/{wrench-CS1f1Zv4.js → wrench-CvfM03KZ.js} +1 -1
  58. package/dist/assets/dql-notebook/assets/{x-CbKEfe5m.js → x-B4coLiOl.js} +1 -1
  59. package/dist/assets/dql-notebook/index.html +2 -2
  60. package/dist/commands/app.d.ts.map +1 -1
  61. package/dist/commands/app.js +65 -133
  62. package/dist/commands/app.js.map +1 -1
  63. package/dist/commands/model.js +21 -2
  64. package/dist/commands/model.js.map +1 -1
  65. package/dist/llm/providers/dql-agent-provider.d.ts +16 -0
  66. package/dist/llm/providers/dql-agent-provider.d.ts.map +1 -1
  67. package/dist/llm/providers/dql-agent-provider.js +65 -2
  68. package/dist/llm/providers/dql-agent-provider.js.map +1 -1
  69. package/dist/local-runtime.d.ts +112 -19
  70. package/dist/local-runtime.d.ts.map +1 -1
  71. package/dist/local-runtime.js +2026 -694
  72. package/dist/local-runtime.js.map +1 -1
  73. package/dist/package.json +10 -10
  74. package/dist/sql-result-filter.d.ts +9 -0
  75. package/dist/sql-result-filter.d.ts.map +1 -1
  76. package/dist/sql-result-filter.js +25 -0
  77. package/dist/sql-result-filter.js.map +1 -1
  78. package/package.json +10 -10
  79. package/dist/assets/dql-notebook/assets/AgentAnswerCard-c8QUo6NH.js +0 -5
  80. package/dist/assets/dql-notebook/assets/AnalyticsHome-DgwnRW71.js +0 -6
  81. package/dist/assets/dql-notebook/assets/AppsView-B6LYUpgm.js +0 -4578
  82. package/dist/assets/dql-notebook/assets/BlockStudio--jNw9XUI.js +0 -60
  83. package/dist/assets/dql-notebook/assets/DbtFirstModelingPage-DhBsLCYr.js +0 -22
  84. package/dist/assets/dql-notebook/assets/GlobalAiRail-1Tgweuu2.js +0 -1
  85. package/dist/assets/dql-notebook/assets/GovernedContextPage-C7qGrH3d.js +0 -16
  86. package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-duFXXNV_.js +0 -88
  87. package/dist/assets/dql-notebook/assets/index-Cpx47jCH.js +0 -634
  88. package/dist/assets/dql-notebook/assets/index-DKu4CZt3.css +0 -1
  89. package/dist/assets/dql-notebook/assets/upload-BPhfea_E.js +0 -11
  90. package/dist/assets/dql-notebook/assets/usePersistedAgentThreadId-Bnl9gWhj.js +0 -28
@@ -1,16 +0,0 @@
1
- import{c as Ue,u as ve,t as ke,r as d,a as M,j as e,a4 as oe,a0 as pe,L as F,S as te,P as ne,B as lt,d as Qe,T as re,l as Be,f as Ve,$ as Ee,a5 as at,Q as xe,N as Oe,aU as Je}from"./index-Cpx47jCH.js";import{T as Te}from"./triangle-alert-SyuSZ4ht.js";import{U as He,G as le}from"./user-round-J4PQHxo9.js";import{C as Ye,U as dt}from"./UnifiedAgentRunPanel-duFXXNV_.js";import{P as Xe,u as ct}from"./usePersistedAgentThreadId-Bnl9gWhj.js";import{X as ue}from"./x-CbKEfe5m.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 pt=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M9 10h6",key:"9gxzsh"}],["path",{d:"M12 13V7",key:"h0r20n"}],["path",{d:"M9 17h6",key:"r8uit2"}]],ut=Ue("file-diff",pt);/**
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 xt=[["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"}]],gt=Ue("tags",xt),de="dql-context-bootstrap-session",ce="dql-context-bootstrap-selection";function ht(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").slice(0,64)}function Ne(t){return t.toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,64)}function ft(){return{id:"",name:"",owner:"",boundedContext:"",sourceSystems:[],description:""}}function yt({embedded:t=!1}={}){const{state:n,dispatch:s}=ve(),i=ke[n.themeMode],[l,a]=d.useState([]),[o,r]=d.useState(!0),[p,S]=d.useState(null),[w,c]=d.useState(null),[z,j]=d.useState(null),[h,u]=d.useState(!1),[D,T]=d.useState(null),[v,f]=d.useState(null),[x,b]=d.useState(!1),[W,O]=d.useState(!1),[N,A]=d.useState(null),[k,g]=d.useState([]),$=d.useCallback(()=>{let y=!1;return r(!0),S(null),M.getDomains().then(C=>{if(y)return;const R=Array.isArray(C==null?void 0:C.domains)?C.domains:[];a(R),s({type:"SET_AUTHORED_DOMAINS",domains:R})}).catch(C=>{y||(a([]),S(C instanceof Error&&C.message?C.message:"Could not load domains. Is the local DQL server running?"))}).finally(()=>{y||r(!1)}),()=>{y=!0}},[s]);d.useEffect(()=>$(),[$]),d.useEffect(()=>{const y=window.sessionStorage.getItem(de);let C=!1;const R=P=>{if(P&&!C){f(P);try{const H=JSON.parse(window.sessionStorage.getItem(ce)??"[]");g(Array.isArray(H)?H.filter(V=>typeof V=="string"):P.candidates.filter(V=>V.action!=="unchanged").map(V=>V.id))}catch{g(P.candidates.filter(H=>H.action!=="unchanged").map(H=>H.id))}}};return(y?M.getContextBootstrap(y):M.getLatestContextBootstrap()).then(R).catch(async()=>{window.sessionStorage.removeItem(de),window.sessionStorage.removeItem(ce),y&&R(await M.getLatestContextBootstrap().catch(()=>null))}),()=>{C=!0}},[]),d.useEffect(()=>{v&&(window.sessionStorage.setItem(de,v.id),window.sessionStorage.setItem(ce,JSON.stringify(k)))},[v==null?void 0:v.id,k]);const L=d.useMemo(()=>[...l].sort((y,C)=>y.name.localeCompare(C.name)),[l]),B=d.useCallback(y=>{a(C=>{const R=C.findIndex(P=>P.id===y.id),E=R===-1?[...C,y]:[...C];return R!==-1&&(E[R]=y),s({type:"SET_AUTHORED_DOMAINS",domains:E}),E}),c(null)},[s]),_=d.useCallback(async()=>{if(z){u(!0),T(null);try{await M.deleteDomain(z.id),a(y=>{const C=y.filter(R=>R.id!==z.id);return s({type:"SET_AUTHORED_DOMAINS",domains:C}),C}),j(null)}catch(y){T(y instanceof Error&&y.message?y.message:"Could not delete this domain.")}finally{u(!1)}}},[s,z]),Y=d.useCallback(async()=>{b(!0),A(null);try{const y=await M.startContextBootstrap({ai:!0});f(y);const C=y.candidates.filter(R=>R.action!=="unchanged").map(R=>R.id);g(C),window.sessionStorage.setItem(de,y.id),window.sessionStorage.setItem(ce,JSON.stringify(C))}catch(y){A(y instanceof Error?y.message:"Could not draft repository context.")}finally{b(!1)}},[]);d.useEffect(()=>{if(!t)return;const y=()=>{Y()};return window.addEventListener("dql:context-build",y),()=>window.removeEventListener("dql:context-build",y)},[t,Y]),d.useEffect(()=>{if(!v||["ready","needs_attention"].includes(v.status))return;let y=!1;const C=async()=>{try{const E=await M.getContextBootstrap(v.id);y||f(E)}catch(E){y||A(E instanceof Error?E.message:"Could not update AI draft progress.")}};C();const R=window.setInterval(()=>void C(),750);return()=>{y=!0,window.clearInterval(R)}},[v==null?void 0:v.id,v==null?void 0:v.status]);const G=d.useCallback(async()=>{if(!(!v||k.length===0)){O(!0),A(null);try{await M.saveContextBootstrapSelected(v.id,k),f(null),g([]),window.sessionStorage.removeItem(de),window.sessionStorage.removeItem(ce),$()}catch(y){A(y instanceof Error?y.message:"Could not save selected drafts.")}finally{O(!1)}}},[v,k,$]);return e.jsxs("div",{style:{flex:1,minWidth:0,overflow:"auto",background:i.appBg},children:[e.jsxs("div",{style:{maxWidth:980,margin:"0 auto",padding:"22px 28px 40px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-end",justifyContent:"space-between",gap:18,marginBottom:18},children:[e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9},children:[e.jsx(oe,{size:20,strokeWidth:1.9,color:i.accent}),e.jsx("div",{style:{fontSize:22,fontWeight:700,color:i.textPrimary},children:"Domains"})]}),e.jsx("div",{style:{fontSize:13,color:i.textMuted,marginTop:6,maxWidth:680,lineHeight:1.5},children:"Domains are the top of your business model — each one owns the terms, skills, and blocks beneath it. Name the business area, who owns it, the bounded context, and the source systems it draws from."})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0},children:[e.jsxs("button",{type:"button",onClick:()=>$(),title:"Refresh",style:ie(i),children:[e.jsx(pe,{size:13,strokeWidth:2})," Refresh"]}),e.jsxs("button",{type:"button",onClick:()=>void Y(),disabled:x,style:ie(i),children:[x?e.jsx(F,{size:13,strokeWidth:2}):e.jsx(te,{size:13,strokeWidth:2})," Draft with AI"]}),e.jsxs("button",{type:"button",onClick:()=>c({kind:"create"}),style:ye(i),children:[e.jsx(ne,{size:14,strokeWidth:2.2})," Add domain"]})]})]}),o?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:i.textMuted,fontSize:13,padding:"40px 0"},children:[e.jsx(F,{size:15,strokeWidth:2})," Loading domains…"]}):p?e.jsx(vt,{t:i,message:p,onRetry:()=>$()}):L.length===0?e.jsx(jt,{t:i,onAdd:()=>c({kind:"create"})}):e.jsx("div",{style:{display:"grid",gap:10},children:L.map(y=>e.jsx(mt,{domain:y,t:i,onEdit:()=>c({kind:"edit",domain:y}),onDelete:()=>{T(null),j(y)}},y.id))}),N?e.jsx("div",{style:{marginTop:12},children:e.jsx(fe,{t:i,tone:"error",children:N})}):null,v?e.jsxs("section",{style:{marginTop:18,border:`1px solid ${i.cellBorder}`,borderRadius:10,background:i.cellBg,padding:14},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:12,alignItems:"center",flexWrap:"wrap"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:13,fontWeight:750,color:i.textPrimary},children:"Repository-guided AI draft"}),e.jsx("div",{style:{fontSize:12,color:i.textMuted,marginTop:3},children:"Inventory is deterministic; AI may enrich only grounded prose and guidance. Nothing is written to Git until you save."})]}),e.jsxs("button",{type:"button",disabled:W||k.length===0||!["ready","needs_attention"].includes(v.status),onClick:()=>void G(),style:{...ye(i),opacity:W||k.length===0||!["ready","needs_attention"].includes(v.status)?.55:1},children:[W?e.jsx(F,{size:13,strokeWidth:2}):e.jsx(ne,{size:13,strokeWidth:2})," Save selected drafts"]})]}),e.jsx(kt,{t:i,session:v}),e.jsx("div",{style:{display:"grid",gap:9,marginTop:12},children:v.candidates.map(y=>{const C=y.action!=="unchanged",R=k.includes(y.id);return e.jsx(St,{candidate:y,selected:R,selectable:C,disabled:W,t:i,onToggle:()=>g(E=>R?E.filter(P=>P!==y.id):[...E,y.id])},y.id)})})]}):null]}),w?e.jsx(bt,{mode:w,existingIds:l.map(y=>y.id),domains:l,t:i,onClose:()=>c(null),onSaved:B}):null,z?e.jsx(wt,{domain:z,t:i,deleting:h,error:D,onCancel:()=>{h||j(null)},onConfirm:_}):null]})}function mt({domain:t,t:n,onEdit:s,onDelete:i}){const l=t.sourceSystems??[],[a,o]=d.useState(!1);return e.jsxs("section",{style:{border:`1px solid ${n.cellBorder}`,borderRadius:10,background:n.cellBg,padding:"13px 15px",display:"flex",alignItems:"flex-start",gap:14},children:[e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:13.5,fontWeight:750,color:n.textPrimary},children:t.name}),t.parent?e.jsxs("span",{style:We(n),children:["↳ ",t.parent]}):null,t.owner?e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,color:n.textMuted},children:[e.jsx(He,{size:11,strokeWidth:2})," ",t.owner]}):null,t.businessOwner?e.jsxs("span",{style:We(n),children:[e.jsx(He,{size:10,strokeWidth:2.2})," Business owner: ",t.businessOwner]}):null]}),t.description?e.jsx("div",{style:{fontSize:12.5,color:n.textSecondary,marginTop:5,lineHeight:1.5},children:t.description}):e.jsx("div",{style:{fontSize:12,color:n.textMuted,marginTop:5,fontStyle:"italic"},children:"No description yet."}),l.length>0?e.jsx("div",{style:{display:"flex",gap:5,marginTop:9,flexWrap:"wrap"},children:l.map(r=>e.jsx("span",{style:$e(n),children:r},r))}):null,e.jsxs("div",{style:{display:"flex",gap:7,marginTop:9,flexWrap:"wrap"},children:[e.jsx(we,{t:n,icon:e.jsx(lt,{size:11,strokeWidth:2}),label:"blocks",count:t.blockCount??0}),e.jsx(we,{t:n,icon:e.jsx(le,{size:11,strokeWidth:2}),label:"skills",count:t.skillCount??0}),e.jsx(we,{t:n,icon:e.jsx(gt,{size:11,strokeWidth:2}),label:"terms",count:t.termCount??0})]}),a?e.jsxs("div",{style:{display:"grid",gap:9,marginTop:12,paddingTop:11,borderTop:`1px solid ${n.btnBorder}`},children:[t.boundedContext?e.jsx(_e,{t:n,label:"Business boundary",children:t.boundedContext}):null,t.businessOutcome?e.jsx(_e,{t:n,label:"Decision outcome",children:t.businessOutcome}):null,e.jsx(ge,{t:n,label:"In scope",values:t.inScope,empty:"Not defined yet"}),e.jsx(ge,{t:n,label:"Out of scope",values:t.outOfScope,empty:"Not defined yet"}),e.jsx(ge,{t:n,label:"Primary terms",values:t.primaryTerms,empty:"No terms linked yet"}),e.jsx(ge,{t:n,label:"Tags",values:t.tags,empty:"No tags"})]}):null]}),e.jsxs("div",{style:{display:"flex",gap:6,flexShrink:0},children:[e.jsxs("button",{type:"button",onClick:()=>o(r=>!r),style:{...ie(n),padding:"5px 7px",fontSize:11.5},title:a?"Hide domain details":"Show domain details",children:[a?e.jsx(Ye,{size:13}):e.jsx(Qe,{size:13}),a?"Less":"Details"]}),e.jsx("button",{type:"button",onClick:s,style:Ie(n),title:"Edit domain",children:e.jsx(Xe,{size:13,strokeWidth:2})}),e.jsx("button",{type:"button",onClick:i,style:Ie(n),title:"Delete domain",children:e.jsx(re,{size:13,strokeWidth:2})})]})]})}function bt({mode:t,existingIds:n,domains:s,t:i,onClose:l,onSaved:a}){const o=t.kind==="edit",[r,p]=d.useState(()=>t.kind==="edit"?{...t.domain}:ft()),[S,w]=d.useState(o),[c,z]=d.useState(!1),[j,h]=d.useState(null),u=d.useCallback((x,b)=>{p(W=>({...W,[x]:b}))},[]),D=x=>{p(b=>({...b,name:x,...!o&&!S?{id:Ne(x)}:{}}))},T=!o&&r.id.length>0&&n.includes(r.id),v=r.id.trim().length>0&&r.name.trim().length>0&&!T&&!c,f=d.useCallback(async()=>{var b,W,O,N,A;const x={...r,id:r.id.trim(),name:r.name.trim(),owner:(b=r.owner)!=null&&b.trim()?r.owner.trim():void 0,businessOwner:(W=r.businessOwner)!=null&&W.trim()?r.businessOwner.trim():void 0,parent:(O=r.parent)!=null&&O.trim()?r.parent.trim():void 0,boundedContext:(N=r.boundedContext)!=null&&N.trim()?r.boundedContext.trim():void 0,description:(A=r.description)!=null&&A.trim()?r.description.trim():void 0,sourceSystems:(r.sourceSystems??[]).map(k=>k.trim()).filter(Boolean),primaryTerms:(r.primaryTerms??[]).map(k=>k.trim()).filter(Boolean),tags:(r.tags??[]).map(k=>k.trim()).filter(Boolean),inScope:(r.inScope??[]).map(k=>k.trim()).filter(Boolean),outOfScope:(r.outOfScope??[]).map(k=>k.trim()).filter(Boolean),dbtGroups:(r.dbtGroups??[]).map(k=>k.trim()).filter(Boolean),dbtPaths:(r.dbtPaths??[]).map(k=>k.trim()).filter(Boolean),dbtTags:(r.dbtTags??[]).map(k=>k.trim()).filter(Boolean),semanticDomains:(r.semanticDomains??[]).map(k=>k.trim()).filter(Boolean),semanticTags:(r.semanticTags??[]).map(k=>k.trim()).filter(Boolean)};z(!0),h(null);try{const k=o?await M.updateDomain(x.id,x):await M.createDomain(x);a(k.domain??x)}catch(k){h(k instanceof Error&&k.message?k.message:"Could not save this domain. Try again.")}finally{z(!1)}},[r,o,a]);return e.jsx("div",{style:Wt,onClick:()=>!c&&l(),children:e.jsxs("div",{style:Rt(i),onClick:x=>x.stopPropagation(),children:[e.jsxs("div",{style:Tt(i),children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(oe,{size:16,strokeWidth:2,color:i.accent}),e.jsx("div",{style:{fontSize:15,fontWeight:700,color:i.textPrimary},children:o?"Edit domain":"New domain"})]}),e.jsx("button",{type:"button",onClick:()=>!c&&l(),style:Ie(i),title:"Close",children:e.jsx(ue,{size:15,strokeWidth:2})})]}),e.jsxs("div",{style:{flex:1,minHeight:0,overflow:"auto",padding:"16px 18px",display:"grid",gap:16},children:[e.jsx(U,{label:"Name",t:i,hint:o?void 0:"A short, human label for this business area.",children:e.jsx("input",{type:"text",value:r.name,onChange:x=>D(x.target.value),placeholder:"Revenue",style:X(i)})}),e.jsxs(U,{label:"ID (slug)",t:i,hint:"Used as the on-disk identifier. Letters, numbers, and dashes.",children:[e.jsx("input",{type:"text",value:r.id,disabled:o,onChange:x=>{w(!0),u("id",ht(x.target.value))},onBlur:()=>u("id",Ne(r.id)),placeholder:"revenue",style:{...X(i),fontFamily:i.fontMono,opacity:o?.7:1}}),T?e.jsx(fe,{t:i,tone:"error",children:"A domain with this id already exists."}):null]}),e.jsx(U,{label:"Parent domain",t:i,hint:"Optional. Depth becomes Domain, Subdomain, Microdomain, and beyond.",children:e.jsxs("select",{value:r.parent??"",onChange:x=>u("parent",x.target.value||void 0),style:X(i),children:[e.jsx("option",{value:"",children:"Top-level domain"}),s.filter(x=>x.id!==r.id).map(x=>e.jsx("option",{value:x.id,children:x.name},x.id))]})}),e.jsx(U,{label:"Owner",t:i,hint:"The team or person accountable for this domain.",children:e.jsx("input",{type:"text",value:r.owner??"",onChange:x=>u("owner",x.target.value),placeholder:"finance-analytics",style:X(i)})}),e.jsx(U,{label:"Business owner",t:i,hint:"The stakeholder accountable for business use and definitions.",children:e.jsx("input",{type:"text",value:r.businessOwner??"",onChange:x=>u("businessOwner",x.target.value),placeholder:"Revenue Operations",style:X(i)})}),e.jsx(U,{label:"Bounded context",t:i,hint:"The conceptual boundary this domain owns, e.g. 'recognized revenue and invoicing'.",children:e.jsx("input",{type:"text",value:r.boundedContext??"",onChange:x=>u("boundedContext",x.target.value),placeholder:"Recognized revenue and invoicing",style:X(i)})}),e.jsx(U,{label:"Source systems",t:i,hint:"The upstream systems this domain draws from — type a name and press Enter.",children:e.jsx(Se,{t:i,values:r.sourceSystems??[],onChange:x=>u("sourceSystems",x),placeholder:"Add a source system…"})}),e.jsx(U,{label:"Primary terms",t:i,hint:"Business concepts the agent should use to recognize this domain.",children:e.jsx(Se,{t:i,values:r.primaryTerms??[],onChange:x=>u("primaryTerms",x),placeholder:"Add a term…"})}),e.jsx(U,{label:"Scope tags",t:i,hint:"Short labels used for routing and discovery.",children:e.jsx(Se,{t:i,values:r.tags??[],onChange:x=>u("tags",x),placeholder:"Add a tag…"})}),e.jsx(U,{label:"Description",t:i,hint:"What this domain covers and how it's used.",children:e.jsx("textarea",{value:r.description??"",onChange:x=>u("description",x.target.value),rows:5,placeholder:"All recognized-revenue metrics and the blocks that report them, sourced from the billing warehouse.",style:zt(i)})}),j?e.jsx(fe,{t:i,tone:"error",children:j}):null]}),e.jsxs("div",{style:$t(i),children:[e.jsx("button",{type:"button",onClick:()=>!c&&l(),style:ie(i),children:"Cancel"}),e.jsxs("button",{type:"button",onClick:f,disabled:!v,style:{...ye(i),opacity:v?1:.55},children:[c?e.jsx(F,{size:13,strokeWidth:2}):null,c?"Saving…":o?"Save changes":"Create domain"]})]})]})})}function Se({t,values:n,onChange:s,placeholder:i}){const[l,a]=d.useState(""),o=r=>{const p=r.trim();!p||n.includes(p)||(s([...n,p]),a(""))};return e.jsxs("div",{style:{display:"grid",gap:7},children:[n.length>0?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:n.map(r=>e.jsxs("span",{style:Bt(t),children:[r,e.jsx("button",{type:"button",onClick:()=>s(n.filter(p=>p!==r)),style:It(t),title:"Remove",children:e.jsx(ue,{size:11,strokeWidth:2.4})})]},r))}):null,e.jsx("input",{type:"text",value:l,onChange:r=>a(r.target.value),onKeyDown:r=>{r.key==="Enter"&&(r.preventDefault(),o(l))},placeholder:i,style:X(t)})]})}function jt({t,onAdd:n}){return e.jsxs("div",{style:{border:`1px dashed ${t.cellBorder}`,borderRadius:12,background:t.cellBg,padding:"34px 28px",textAlign:"center",display:"grid",gap:12,justifyItems:"center"},children:[e.jsx("div",{style:{width:44,height:44,borderRadius:10,background:`${t.accent}18`,color:t.accent,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(oe,{size:22,strokeWidth:1.9})}),e.jsx("div",{style:{fontSize:15,fontWeight:700,color:t.textPrimary},children:"Name your business domains"}),e.jsx("div",{style:{fontSize:13,color:t.textMuted,maxWidth:460,lineHeight:1.55},children:`Domains organize everything below them — terms, skills, and blocks. Add your first one, like "Revenue" or "Customer", and you'll be able to pick it when authoring blocks and skills.`}),e.jsxs("button",{type:"button",onClick:n,style:{...ye(t),marginTop:4},children:[e.jsx(ne,{size:14,strokeWidth:2.2})," Add your first domain"]})]})}function vt({t,message:n,onRetry:s}){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(Te,{size:16,strokeWidth:2,color:t.warning,style:{marginTop:1,flexShrink:0}}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:13,fontWeight:650,color:t.textPrimary},children:"Domains are not available right now"}),e.jsx("div",{style:{fontSize:12.5,color:t.textSecondary,marginTop:4,lineHeight:1.5},children:n}),e.jsxs("button",{type:"button",onClick:s,style:{...ie(t),marginTop:10},children:[e.jsx(pe,{size:13,strokeWidth:2})," Retry"]})]})]})}function kt({t,session:n}){var l;const s=!["ready","needs_attention"].includes(n.status),i=n.ai.mode==="evidence_only"?"Evidence-only":n.ai.provider?`${n.ai.provider} grounded`:"Preparing AI";return e.jsxs("div",{style:{marginTop:14,padding:"10px 11px",borderRadius:8,background:t.appBg,border:`1px solid ${t.btnBorder}`},children:[e.jsxs("div",{style:{display:"flex",gap:9,alignItems:"center",flexWrap:"wrap",fontSize:12,color:t.textSecondary},children:[s?e.jsx(F,{size:14,strokeWidth:2,color:t.accent}):e.jsx(te,{size:14,strokeWidth:2,color:t.accent}),e.jsx("strong",{style:{color:t.textPrimary,textTransform:"capitalize"},children:n.status.replace("_"," ")}),e.jsx("span",{children:i}),e.jsxs("span",{children:[n.progress.domains.ready,"/",n.progress.domains.total," domains"]}),e.jsxs("span",{children:[n.progress.skills.ready,"/",n.progress.skills.total," skills"]})]}),e.jsx("div",{style:{height:5,borderRadius:999,background:t.btnBg,overflow:"hidden",marginTop:9},children:e.jsx("div",{style:{width:`${Math.max(3,Math.min(100,n.progress.percent))}%`,height:"100%",background:t.accent,transition:"width 260ms ease"}})}),e.jsx("div",{style:{marginTop:7,fontSize:11.5,color:t.textMuted,lineHeight:1.45},children:n.progress.message}),(l=n.warnings)!=null&&l.length?e.jsx("div",{style:{marginTop:7,fontSize:11.5,color:t.warning,lineHeight:1.45},children:n.warnings.slice(-2).join(" ")}):null]})}function St({candidate:t,selected:n,selectable:s,disabled:i,t:l,onToggle:a}){var z,j,h,u,D,T,v,f,x,b,W,O,N,A,k,g,$,L,B,_,Y,G,y,C,R,E;const[o,r]=d.useState(!1),p=t.kind==="domain",S=((z=t.domain)==null?void 0:z.name)??((j=t.skill)==null?void 0:j.id)??t.id.replace(/^(domain|skill):/,""),w=p?((h=t.domain)==null?void 0:h.description)??((u=t.domain)==null?void 0:u.boundedContext):((D=t.skill)==null?void 0:D.description)??((v=(T=t.skill)==null?void 0:T.body)==null?void 0:v.split(`
12
- `).find(Boolean)),c=p?[["Business outcome",(f=t.domain)==null?void 0:f.businessOutcome],["In scope",(b=(x=t.domain)==null?void 0:x.inScope)==null?void 0:b.join(" · ")],["Out of scope",(O=(W=t.domain)==null?void 0:W.outOfScope)==null?void 0:O.join(" · ")],["Primary terms",(A=(N=t.domain)==null?void 0:N.primaryTerms)==null?void 0:A.join(" · ")]]:[["Applies when",(g=(k=t.skill)==null?void 0:k.triggers)==null?void 0:g.join(" · ")],["Ask first when",(L=($=t.skill)==null?void 0:$.clarifyWhen)==null?void 0:L.join(" · ")],["Avoid when",(_=(B=t.skill)==null?void 0:B.exclusions)==null?void 0:_.join(" · ")],["Preferred metrics",(G=(Y=t.skill)==null?void 0:Y.preferredMetrics)==null?void 0:G.join(" · ")],["Preferred blocks",(C=(y=t.skill)==null?void 0:y.preferredBlocks)==null?void 0:C.join(" · ")]];return e.jsx("article",{style:{border:`1px solid ${n?`${l.accent}66`:l.btnBorder}`,background:n?`${l.accent}08`:l.appBg,borderRadius:8,padding:"10px 11px",opacity:s?1:.72},children:e.jsxs("div",{style:{display:"flex",gap:9,alignItems:"flex-start"},children:[e.jsx("input",{"aria-label":`Select ${p?"domain":"skill"} ${S}`,type:"checkbox",disabled:!s||i,checked:n,onChange:a,style:{marginTop:3}}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",gap:7,alignItems:"center",flexWrap:"wrap"},children:[e.jsxs("strong",{style:{color:l.textPrimary,fontSize:12.5},children:[p?"Domain":"Skill"," · ",S]}),e.jsx("span",{style:We(l),children:t.action.replace("_"," ")}),e.jsxs("span",{style:{fontSize:11,color:l.textMuted},children:[Math.round(t.confidence*100),"% evidence confidence"]})]}),w?e.jsx("p",{style:{marginTop:5,color:l.textSecondary,fontSize:12,lineHeight:1.45},children:w}):e.jsx("p",{style:{marginTop:5,color:l.textMuted,fontSize:12,fontStyle:"italic"},children:"Waiting for grounded guidance…"}),e.jsx("div",{style:{display:"flex",gap:5,marginTop:7,flexWrap:"wrap"},children:t.evidence.map(P=>e.jsx("span",{style:$e(l),children:P},P))}),o?e.jsxs("div",{style:{marginTop:9,display:"grid",gap:6,borderTop:`1px solid ${l.btnBorder}`,paddingTop:9},children:[c.filter(([,P])=>!!P).map(([P,H])=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"116px minmax(0, 1fr)",gap:8,fontSize:11.5,lineHeight:1.45},children:[e.jsx("strong",{style:{color:l.textMuted},children:P}),e.jsx("span",{style:{color:l.textSecondary},children:H})]},P)),!p&&((R=t.skill)!=null&&R.body)?e.jsx("pre",{style:{margin:0,whiteSpace:"pre-wrap",fontFamily:l.font,fontSize:11.5,color:l.textSecondary,background:l.cellBg,padding:9,borderRadius:6,maxHeight:180,overflow:"auto"},children:t.skill.body}):null,(E=t.notes)!=null&&E.length?e.jsx("div",{style:{fontSize:11.5,color:l.accent},children:t.notes.join(" ")}):null]}):null]}),e.jsxs("button",{type:"button",onClick:()=>r(P=>!P),style:{...ie(l),padding:"4px 6px",fontSize:11.5},"aria-expanded":o,children:[o?e.jsx(Ye,{size:13}):e.jsx(Qe,{size:13}),o?"Less":"Review"]})]})})}function wt({domain:t,t:n,deleting:s,error:i,onCancel:l,onConfirm:a}){return e.jsx("div",{style:Mt,onClick:l,children:e.jsxs("div",{style:Dt(n),onClick:o=>o.stopPropagation(),children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9},children:[e.jsx(re,{size:16,strokeWidth:2,color:n.error}),e.jsx("div",{style:{fontSize:15,fontWeight:700,color:n.textPrimary},children:"Delete this domain?"})]}),e.jsxs("div",{style:{fontSize:13,color:n.textSecondary,lineHeight:1.55},children:[e.jsx("span",{style:{fontWeight:700,color:n.textPrimary},children:t.name})," will be removed. Blocks, skills, and terms that referenced it will become unassigned. This can't be undone."]}),i?e.jsx(fe,{t:n,tone:"error",children:i}):null,e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[e.jsx("button",{type:"button",onClick:l,disabled:s,style:ie(n),children:"Cancel"}),e.jsxs("button",{type:"button",onClick:a,disabled:s,style:{...Ct(n),opacity:s?.6:1},children:[s?e.jsx(F,{size:13,strokeWidth:2}):e.jsx(re,{size:13,strokeWidth:2}),s?"Deleting…":"Delete"]})]})]})})}function we({t,icon:n,label:s,count:i}){return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11,fontWeight:600,color:i>0?t.textSecondary:t.textMuted,background:t.btnBg,border:`1px solid ${t.btnBorder}`,borderRadius:6,padding:"3px 8px"},children:[n,i," ",s]})}function _e({t,label:n,children:s}){return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"118px minmax(0, 1fr)",gap:10,fontSize:12,lineHeight:1.5},children:[e.jsx("strong",{style:{color:t.textMuted},children:n}),e.jsx("span",{style:{color:t.textSecondary},children:s})]})}function ge({t,label:n,values:s,empty:i}){return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"118px minmax(0, 1fr)",gap:10,fontSize:12,lineHeight:1.5},children:[e.jsx("strong",{style:{color:t.textMuted},children:n}),e.jsx("div",{style:{display:"flex",gap:5,flexWrap:"wrap"},children:s!=null&&s.length?s.map(l=>e.jsx("span",{style:$e(t),children:l},l)):e.jsx("span",{style:{color:t.textMuted,fontStyle:"italic"},children:i})})]})}function U({label:t,hint:n,t:s,children:i}){return e.jsxs("div",{style:{display:"grid",gap:6},children:[e.jsx("label",{style:{fontSize:12,fontWeight:700,color:s.textPrimary},children:t}),n?e.jsx("div",{style:{fontSize:11.5,color:s.textMuted,lineHeight:1.45,marginTop:-2},children:n}):null,i]})}function fe({t,tone:n,children:s}){const i=n==="error"?t.error:t.textMuted;return e.jsx("div",{style:{fontSize:11.5,color:i,lineHeight:1.45},children:s})}function ye(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 ie(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 Ct(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 Ie(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 X(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 zt(t){return{...X(t),resize:"vertical",lineHeight:1.5,padding:"9px 11px"}}function We(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 $e(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 Bt(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 It(t){return{display:"inline-flex",alignItems:"center",justifyContent:"center",border:"none",background:"transparent",color:t.textMuted,cursor:"pointer",padding:2,borderRadius:4}}const Wt={position:"fixed",inset:0,background:"rgba(0, 0, 0, 0.42)",display:"flex",justifyContent:"flex-end",zIndex:60};function Rt(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 Tt(t){return{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 18px",borderBottom:`1px solid ${t.headerBorder}`,flexShrink:0}}function $t(t){return{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:8,padding:"13px 18px",borderTop:`1px solid ${t.headerBorder}`,flexShrink:0}}const Mt={position:"fixed",inset:0,background:"rgba(0, 0, 0, 0.42)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:70,padding:20};function Dt(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 Pt(t,n,s){var a,o;if(n&&t.domain!==n&&!((a=t.domains)!=null&&a.includes(n)))return!1;const i=(o=s==null?void 0:s.split("::").at(-1))==null?void 0:o.toLowerCase();if(!i)return!0;const l=(t.modelAreaRefs??[]).map(r=>{var p;return(p=r.split("::").at(-1))==null?void 0:p.toLowerCase()});return l.length===0||l.includes(i)}function Le(t){return t.replace(/\\/g,"/").replace(/^\.\//,"").replace(/\/+$/,"")}function At(t,n){if(!n)return!0;const s=Le(t.sourcePath);return n.some(i=>{const l=Le(i);return s===l||s.endsWith(`/${l}`)})}function Et({proposal:t,theme:n,onClose:s,onCommitted:i}){const[l,a]=d.useState(t),[o,r]=d.useState(()=>t.operations.map(f=>f.id)),[p,S]=d.useState(null),[w,c]=d.useState(null),[z,j]=d.useState(!1),h=l.diagnostics.filter(f=>f.severity==="blocking"),u=d.useMemo(()=>new Map(l.operations.map(f=>[f.id,l.patches.filter(x=>x.operationId===f.id)])),[l]),D=async(f,x)=>{const b=x?[...o,f]:o.filter(W=>W!==f);r(b),S("preview"),c(null),j(!1);try{const W=await M.repreviewContextProposal(l.id,b);a(W),r(W.operations.map(O=>O.id))}catch(W){r(o),c(W instanceof Error?W.message:String(W))}finally{S(null)}},T=async()=>{S("commit"),c(null),j(!1);try{const f=await M.commitContextProposal(l.id,l.proposalHash,crypto.randomUUID());a(f.proposal),i(f.proposal)}catch(f){c(f instanceof Error?f.message:String(f)),j(!0)}finally{S(null)}},v=async()=>{S("rebase"),c(null);try{const f=await M.repreviewContextProposal(l.id,o,{rebase:!0});a(f),r(f.operations.map(x=>x.id)),j(!1)}catch(f){c(f instanceof Error?f.message:String(f))}finally{S(null)}};return e.jsx("div",{role:"presentation",onClick:()=>!p&&s(),style:{position:"fixed",inset:0,zIndex:130,background:"rgba(8, 10, 16, .48)",display:"flex",justifyContent:"flex-end"},children:e.jsxs("aside",{role:"dialog","aria-modal":"true","aria-label":"Review context proposal",onClick:f=>f.stopPropagation(),style:{width:"min(720px, 96vw)",height:"100%",background:n.appBg,borderLeft:"1px solid var(--border-default)",boxShadow:"-18px 0 50px rgba(0,0,0,.24)",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:10},children:[e.jsx("span",{style:{width:30,height:30,borderRadius:8,background:"var(--accent-dim)",color:n.accent,display:"inline-flex",alignItems:"center",justifyContent:"center"},children:e.jsx(ut,{size:16})}),e.jsxs("div",{style:{flex:1},children:[e.jsx("strong",{style:{fontSize:14},children:"Review exact proposal"}),e.jsxs("div",{style:{marginTop:2,fontSize:10.5,color:n.textMuted},children:[l.origin.replace(/_/g," ")," · immutable revision · ",l.trustState.replace(/_/g," ")]})]}),e.jsx("button",{type:"button","aria-label":"Close proposal",disabled:!!p,onClick:s,style:Ot(n),children:e.jsx(ue,{size:15})})]}),e.jsxs("div",{style:{flex:1,minHeight:0,overflow:"auto",padding:18},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, minmax(0, 1fr))",gap:8,marginBottom:14},children:[e.jsx(Ce,{label:"Files",value:l.impact.files,theme:n}),e.jsx(Ce,{label:"Modeling",value:l.impact.modelingChanges,theme:n}),e.jsx(Ce,{label:"Skills",value:l.impact.skillChanges,theme:n})]}),e.jsxs("div",{style:{padding:"10px 12px",border:"1px solid var(--border-subtle)",borderRadius:9,background:"var(--bg-1)",color:n.textSecondary,fontSize:11,lineHeight:1.5,marginBottom:14},children:[e.jsx(Be,{size:14,style:{verticalAlign:-3,marginRight:7,color:n.accent}}),"Nothing below has changed source. Saving compiles the complete candidate and writes every selected patch together or writes nothing."]}),l.diagnostics.map((f,x)=>e.jsxs("div",{style:{display:"flex",gap:8,padding:"8px 10px",marginBottom:6,borderRadius:7,background:f.severity==="blocking"?"var(--status-error-bg, rgba(180,50,50,.1))":"var(--bg-1)",color:f.severity==="blocking"?"var(--status-error, #c45555)":n.textSecondary,fontSize:10.5},children:[f.severity==="blocking"?e.jsx(Te,{size:13}):e.jsx(Ve,{size:13}),e.jsxs("span",{children:[e.jsx("b",{children:f.code})," · ",f.message]})]},`${f.code}-${x}`)),e.jsx("div",{style:{display:"grid",gap:10,marginTop:14},children:l.operations.map(f=>{const x=u.get(f.id)??[];return e.jsxs("section",{style:{border:"1px solid var(--border-subtle)",borderRadius:9,overflow:"hidden",background:n.cellBg},children:[e.jsxs("label",{style:{display:"flex",gap:9,alignItems:"flex-start",padding:"11px 12px",cursor:p?"wait":"pointer"},children:[e.jsx("input",{type:"checkbox",checked:o.includes(f.id),disabled:!!p,onChange:b=>void D(f.id,b.target.checked)}),e.jsxs("span",{style:{flex:1,minWidth:0},children:[e.jsx("b",{style:{display:"block",fontSize:11.5},children:f.kind.replace(/_/g," ")}),e.jsx("code",{style:{display:"block",marginTop:3,color:n.textMuted,fontSize:9.5,overflowWrap:"anywhere"},children:f.id})]}),e.jsxs("span",{style:{fontSize:10,color:n.textMuted},children:[x.length," patch",x.length===1?"":"es"]})]}),x.map(b=>e.jsxs("details",{style:{borderTop:"1px solid var(--border-subtle)"},children:[e.jsx("summary",{style:{padding:"8px 12px",cursor:"pointer",color:n.textSecondary,fontSize:10.5},children:e.jsx("code",{children:b.path})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:1,background:"var(--border-subtle)"},children:[e.jsx(Fe,{title:"Before",value:b.before,theme:n}),e.jsx(Fe,{title:"After",value:b.after,theme:n})]})]},`${b.operationId}-${b.path}`))]},f.id)})}),w?e.jsx("div",{role:"alert",style:{color:"var(--status-error, #c45555)",fontSize:11,marginTop:12},children:w}):null]}),e.jsxs("footer",{style:{padding:"12px 18px",borderTop:"1px solid var(--border-subtle)",display:"flex",alignItems:"center",gap:9},children:[e.jsxs("span",{style:{flex:1,fontSize:10.5,color:n.textMuted},children:["Proposal ",e.jsx("code",{children:l.proposalHash.slice(0,12)})]}),z?e.jsxs("button",{type:"button",onClick:()=>void v(),disabled:!!p,style:Re(n),children:[e.jsx(pe,{size:13})," Rebase proposal"]}):null,e.jsx("button",{type:"button",onClick:s,disabled:!!p,style:Re(n),children:"Cancel"}),e.jsxs("button",{type:"button",onClick:()=>void T(),disabled:!!p||o.length===0||h.length>0,style:{...Ht(n),opacity:p||o.length===0||h.length?.55:1},children:[p?e.jsx(F,{size:13}):e.jsx(Be,{size:13})," ",p==="preview"?"Repreviewing…":p==="commit"?"Saving…":"Save as draft"]})]})]})})}function Ce({label:t,value:n,theme:s}){return e.jsxs("div",{style:{border:"1px solid var(--border-subtle)",borderRadius:8,padding:"9px 10px",background:s.cellBg},children:[e.jsx("b",{style:{fontSize:15},children:n}),e.jsx("span",{style:{display:"block",marginTop:2,color:s.textMuted,fontSize:9.5},children:t})]})}function Fe({title:t,value:n,theme:s}){return e.jsxs("div",{style:{minWidth:0,background:"var(--bg-1)",padding:9},children:[e.jsx("b",{style:{fontSize:9,color:s.textMuted},children:t}),e.jsx("pre",{style:{margin:"7px 0 0",fontSize:9.5,lineHeight:1.45,whiteSpace:"pre-wrap",overflowWrap:"anywhere",maxHeight:240,overflow:"auto",color:s.textSecondary},children:n||"∅"})]})}const Ot=t=>({border:"1px solid var(--border-subtle)",background:t.cellBg,color:t.textSecondary,width:29,height:29,borderRadius:7,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer"}),Re=t=>({border:"1px solid var(--border-default)",background:t.cellBg,color:t.textPrimary,minHeight:31,borderRadius:7,padding:"0 12px",cursor:"pointer"}),Ht=t=>({...Re(t),background:t.accent,borderColor:t.accent,color:"var(--accent-fg)",display:"inline-flex",alignItems:"center",gap:6,fontWeight:650});function Nt(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").slice(0,64)}function qe(t){return t.toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,64)}function _t(){return{id:"",scope:"project",description:"",body:"",preferredMetrics:[],preferredBlocks:[],vocabulary:{},sourcePath:""}}function Lt({embedded:t=!1,domainFilter:n=null,modelAreaFilter:s=null,sourcePathFilter:i}={}){var De;const{state:l}=ve(),a=ke[l.themeMode],[o,r]=d.useState([]),[p,S]=d.useState(!0),[w,c]=d.useState(null),[z,j]=d.useState({metrics:[],blocks:[],modelingRefs:[]}),h=l.authoredDomains,[u,D]=d.useState(null),[T,v]=d.useState(!1),[f,x]=d.useState("skills"),[b,W]=d.useState(!1),[O,N]=d.useState(null),[A,k]=d.useState(null),[g,$]=d.useState(!1),[L,B]=d.useState(null),[_,Y]=d.useState(()=>{try{const m=window.sessionStorage.getItem("dql-skill-ai-correction");return m?(window.sessionStorage.removeItem("dql-skill-ai-correction"),JSON.parse(m)):null}catch{return null}}),[G,y]=d.useState(null),[C,R]=d.useState(!1),[E,P]=d.useState(null),H=d.useCallback(()=>{let m=!1;return S(!0),c(null),M.getSkills().then(I=>{m||r(Array.isArray(I==null?void 0:I.skills)?I.skills:[])}).catch(I=>{m||(r([]),c(I instanceof Error&&I.message?I.message:"Could not load skills. Is the local DQL server running?"))}).finally(()=>{m||S(!1)}),M.getSkillOptions().then(I=>{m||j({metrics:Array.isArray(I==null?void 0:I.metrics)?I.metrics:[],blocks:Array.isArray(I==null?void 0:I.blocks)?I.blocks:[],modelingRefs:Array.isArray(I==null?void 0:I.modelingRefs)?I.modelingRefs:[]})}).catch(()=>{m||j({metrics:[],blocks:[],modelingRefs:[]})}),M.getSkillPathSettings().then(I=>{m||(D(I),x(I.path))}).catch(()=>{m||D(null)}),()=>{m=!0}},[]);d.useEffect(()=>H(),[H]),d.useEffect(()=>{_&&$(!0)},[_]);const V=d.useMemo(()=>o.filter(m=>Pt(m,n,s)).filter(m=>At(m,i)).sort((m,I)=>m.id.localeCompare(I.id)),[o,n,s,i]),rt=d.useCallback(m=>{r(I=>{const ae=I.findIndex(Ae=>(Ae.qualifiedId??Ae.id)===(m.qualifiedId??m.id));if(ae===-1)return[...I,m];const Pe=[...I];return Pe[ae]=m,Pe}),k(null)},[]),ot=d.useCallback(async()=>{if(G){R(!0),P(null);try{const m=G.qualifiedId??G.id;await M.deleteSkill(m),r(I=>I.filter(ae=>(ae.qualifiedId??ae.id)!==m)),y(null)}catch(m){P(m instanceof Error&&m.message?m.message:"Could not delete this skill.")}finally{R(!1)}}},[G]),Me=d.useCallback(async()=>{W(!0),N(null);try{const m=await M.updateSkillPath(f);D(m),x(m.path),v(!1),H()}catch(m){N(m instanceof Error&&m.message?m.message:"Could not use this Skills folder.")}finally{W(!1)}},[H,f]);return e.jsxs("div",{style:{flex:1,minWidth:0,overflow:"auto",background:a.appBg},children:[e.jsxs("div",{style:{maxWidth:980,margin:"0 auto",padding:t?"18px 20px 40px":"22px 28px 40px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-end",justifyContent:"space-between",gap:18,marginBottom:18},children:[e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9},children:[e.jsx(le,{size:20,strokeWidth:1.9,color:a.accent}),e.jsx("div",{style:{fontSize:t?18:22,fontWeight:700,color:a.textPrimary},children:s?`${(De=s.split("::").at(-1))==null?void 0:De.replace(/_/g," ")} skills`:n?`${n} skills`:i?"Authored domain skills":"Skills"})]}),e.jsxs("div",{style:{fontSize:13,color:a.textMuted,marginTop:6,maxWidth:680,lineHeight:1.5},children:["Definitions, vocabulary, and instructions the AI follows when answering",s?" in this model area":n?" in this domain":i?" from authored domains":"",". Applied only when their triggers match — drafts never guide answers."]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:7,color:a.textMuted,fontSize:10.5,minWidth:0},children:[e.jsx(Ee,{size:12,strokeWidth:1.8}),e.jsx("span",{children:"Skill folder"}),e.jsx("code",{style:{color:a.textSecondary,fontFamily:a.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(u==null?void 0:u.path)??"skills"}),u?e.jsxs("span",{children:["· ",u.exists?`${u.skillCount} loaded${i?` · ${V.length} shown here`:""}`:"not found"]}):null]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0},children:[e.jsxs("button",{type:"button",onClick:()=>H(),title:"Refresh",style:J(a),children:[e.jsx(pe,{size:13,strokeWidth:2})," Refresh"]}),e.jsxs("button",{type:"button",onClick:()=>{N(null),v(m=>!m)},style:J(a),children:[e.jsx(Ee,{size:13,strokeWidth:2})," Skill folder"]}),e.jsxs("button",{type:"button",onClick:()=>$(m=>!m),style:J(a),children:[e.jsx(te,{size:13,strokeWidth:2})," Skills AI"]}),e.jsxs("button",{type:"button",onClick:()=>k({kind:"create"}),style:be(a),children:[e.jsx(ne,{size:14,strokeWidth:2.2})," Add skill"]})]})]}),T?e.jsxs("div",{style:{border:"1px solid var(--border-subtle)",borderRadius:10,background:a.cellBg,padding:"12px 14px",marginBottom:16,display:"grid",gap:8},children:[e.jsx("div",{style:{fontSize:12.5,fontWeight:700,color:a.textPrimary},children:"Use an existing Skills folder"}),e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[e.jsx("input",{"aria-label":"Existing Skills folder",value:f,onChange:m=>x(m.target.value),onKeyDown:m=>{m.key==="Enter"&&f.trim()&&!b&&Me()},placeholder:"skills or ../skills",style:{...q(a),flex:1,fontFamily:a.fontMono}}),e.jsx("button",{type:"button",onClick:()=>v(!1),disabled:b,style:J(a),children:"Cancel"}),e.jsxs("button",{type:"button",onClick:()=>void Me(),disabled:!f.trim()||b,style:{...be(a),opacity:f.trim()&&!b?1:.55},children:[b?e.jsx(F,{size:13,strokeWidth:2}):null,b?"Connecting…":"Use folder"]})]}),e.jsxs("div",{style:{fontSize:10.5,lineHeight:1.45,color:a.textMuted},children:["Relative paths start from the DQL project. If DQL is in a ",e.jsx("code",{style:{fontFamily:a.fontMono},children:"/dql"})," folder inside your dbt repo, use ",e.jsx("code",{style:{fontFamily:a.fontMono},children:"../skills"}),". Existing ",e.jsx("code",{style:{fontFamily:a.fontMono},children:".skill.md"})," and Markdown skill files are loaded in place and stay Git-owned by that repo."]}),u!=null&&u.resolvedPath?e.jsxs("div",{style:{fontSize:10.5,color:a.textMuted,fontFamily:a.fontMono,overflowWrap:"anywhere"},children:["Resolved: ",u.resolvedPath]}):null,O?e.jsx(me,{t:a,tone:"error",children:O}):null]}):null,g?e.jsx(Ft,{themeMode:l.themeMode,domain:n,modelAreaId:s,selectedSkill:(A==null?void 0:A.kind)==="edit"?A.skill:o.find(m=>(m.qualifiedId??m.id)===(_==null?void 0:_.skillId)||m.id===(_==null?void 0:_.skillId)),correction:_,onCorrectionStarted:()=>Y(null),onReviewProposal:B}):null,p?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:a.textMuted,fontSize:13,padding:"40px 0"},children:[e.jsx(F,{size:15,strokeWidth:2})," Loading skills…"]}):w?e.jsx(Vt,{t:a,message:w,onRetry:()=>H()}):V.length===0?e.jsx(Qt,{t:a,onAdd:()=>k({kind:"create"})}):e.jsx("div",{style:{display:"grid",gap:10},children:V.map(m=>e.jsx(qt,{skill:m,t:a,onEdit:()=>k({kind:"edit",skill:m}),onDelete:()=>{P(null),y(m)}},m.qualifiedId??m.id))})]}),A?e.jsx(Gt,{mode:A,options:z,domains:h,defaultDomain:n,defaultModelArea:s,existingIds:o.map(m=>m.id),t:a,onClose:()=>k(null),onSaved:rt}):null,G?e.jsx(Jt,{skill:G,t:a,deleting:C,error:E,onCancel:()=>{C||y(null)},onConfirm:ot}):null,L?e.jsx(Et,{proposal:L,theme:a,onClose:()=>B(null),onCommitted:()=>{B(null),H()}}):null]})}function Ft({themeMode:t,domain:n,modelAreaId:s,selectedSkill:i,correction:l,onCorrectionStarted:a,onReviewProposal:o}){const r=ke[t],p=`skills:${n??"all"}:${s??"all"}:${(i==null?void 0:i.qualifiedId)??(i==null?void 0:i.id)??"new"}`,{threadId:S,onThreadIdChange:w}=ct(p);return e.jsx("section",{style:{height:"min(600px, calc(100vh - 260px))",minHeight:400,marginBottom:18,border:"1px solid var(--border-default)",borderRadius:11,overflow:"hidden",background:r.cellBg},children:e.jsx(dt,{themeMode:t,title:"Skills AI",scopeHint:"Skill proposal · metadata only · activation stays separate",composerPlaceholder:"Describe skill guidance or a correction…",initialMode:"skill",selectedObject:i?{kind:"skill",id:i.qualifiedId??i.id,title:i.id,path:i.sourcePath}:s?{kind:"model_area",id:s}:n?{kind:"domain",id:n}:{kind:"workspace",title:"New skill draft"},workspaceContext:{domain:n,modelAreaId:s,targetSkillId:(i==null?void 0:i.qualifiedId)??(i==null?void 0:i.id),providerSafety:"metadata_only"},threadId:S,onThreadIdChange:w,autoRun:l&&i?{text:`${l.feedback??"Correct this skill."}
13
-
14
- Applied skill: ${i.qualifiedId??i.id}
15
- Question: ${l.question??"Not retained"}
16
- Save any corrected version as draft and preserve its analytical policy.`,mode:"skill",nonce:1}:void 0,onRunningChange:c=>{c&&l&&a()},onReviewAuthoringProposal:c=>{const z=c.payload;(z==null?void 0:z.version)===1&&z.trustState==="review_required"&&o(z)},emptyHint:"Describe the skill guidance or correction. Skills AI can draft metadata and canonical references, but cannot activate, grant tools, or make joins permissible.",examplePrompts:[{label:"Create a skill",prompt:"Create a draft skill for the selected domain and area, with triggers, exclusions, clarification rules, and examples."},{label:"Improve this skill",prompt:"Improve the selected skill while preserving its analytical policy and governed references."},{label:"Add vocabulary rules",prompt:"Propose vocabulary and clarification guidance for this domain without inventing governed references."}]})})}function qt({skill:t,t:n,onEdit:s,onDelete:i}){var r,p,S,w;const[l,a]=d.useState(!1),o=(r=t.domains)!=null&&r.length?t.domains:t.domain?[t.domain]:[];return e.jsxs("section",{style:{border:"1px solid var(--border-subtle)",borderRadius:11,background:n.cellBg,overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,padding:"12px 14px"},children:[e.jsx("span",{style:{width:28,height:28,borderRadius:7,background:"var(--accent-dim)",color:n.accent,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(le,{size:14,strokeWidth:1.75})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:13,fontWeight:650,color:n.textPrimary,fontFamily:n.fontMono},children:t.id}),t.status==="draft"?e.jsx("span",{style:Ge(n),children:"draft — inactive"}):null,t.status==="active"||!t.status?e.jsx("span",{style:Yt(n),children:"active"}):null,o.map(c=>e.jsx("span",{style:Xt(n),children:c},c)),t.isStarter?e.jsxs("span",{style:Ge(n),title:"A dbt-seeded starter — edit it to make it yours",children:[e.jsx(te,{size:10,strokeWidth:2.2})," starter — edit me"]}):null]}),e.jsx("div",{style:{fontSize:12,color:t.description?n.textSecondary:n.textMuted,fontStyle:t.description?void 0:"italic",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.description||"No description yet."}),e.jsx("div",{title:t.sourcePath,style:{marginTop:3,color:n.textMuted,fontSize:10,fontFamily:n.fontMono,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.sourcePath})]}),e.jsx("button",{type:"button",onClick:()=>a(c=>!c),style:{...J(n),height:26,padding:"0 10px",fontSize:11},title:l?"Hide skill details":"Show skill details",children:l?"Hide details":"Details"}),e.jsx("button",{type:"button",onClick:s,style:{...je(n),width:26,height:26},title:"Edit skill",children:e.jsx(Xe,{size:12,strokeWidth:1.75})}),e.jsx("button",{type:"button",onClick:i,style:{...je(n),width:26,height:26},title:"Delete skill",children:e.jsx(re,{size:12,strokeWidth:1.75})})]}),l?e.jsxs("div",{style:{borderTop:"1px solid var(--border-subtle)",padding:"12px 14px",display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px 20px"},children:[e.jsx(Z,{t:n,label:"Apply when",values:t.triggers,empty:"No trigger phrases defined"}),e.jsx(Z,{t:n,label:"Prefer these metrics",values:t.preferredMetrics,empty:"No preferred metrics",accent:!0,mono:!0}),e.jsx(Z,{t:n,label:"Reuse these blocks",values:t.preferredBlocks,empty:"No preferred blocks",accent:!0,mono:!0}),e.jsx(Z,{t:n,label:"Ask first when",values:t.clarifyWhen,empty:"No clarification rule defined"}),(p=t.exclusions)!=null&&p.length?e.jsx(Z,{t:n,label:"Avoid when",values:t.exclusions,empty:""}):null,(S=t.modelAreaRefs)!=null&&S.length?e.jsx(Z,{t:n,label:"Focus on model areas",values:t.modelAreaRefs,empty:"",mono:!0}):null,(w=t.sourceRefs)!=null&&w.length?e.jsx(Z,{t:n,label:"Guided modeling objects",values:t.sourceRefs,empty:"",mono:!0}):null,t.body?e.jsxs("div",{style:{gridColumn:"1 / -1"},children:[e.jsx("div",{style:se(n),children:"Guidance"}),e.jsx("div",{style:{fontSize:12,lineHeight:1.6,color:n.textSecondary,background:"var(--bg-1)",border:"1px solid var(--border-subtle)",borderRadius:8,padding:"10px 12px",whiteSpace:"pre-wrap",maxHeight:220,overflow:"auto"},children:t.body})]}):null]}):null]})}function Gt({mode:t,options:n,domains:s,defaultDomain:i=null,defaultModelArea:l=null,existingIds:a,t:o,onClose:r,onSaved:p}){const{dispatch:S}=ve(),w=t.kind==="edit",[c,z]=d.useState(()=>t.kind==="edit"?{...t.skill}:{..._t(),domain:i??void 0,domains:i?[i]:[],modelAreaRefs:l?[l]:[]}),[j,h]=d.useState(w),[u,D]=d.useState(()=>t.kind==="edit"?t.skill.id:""),[T,v]=d.useState(!1),[f,x]=d.useState(null),b=d.useCallback((g,$)=>{z(L=>({...L,[g]:$}))},[]),W=g=>{D(g),!w&&!j&&b("id",qe(g))},O=!w&&c.id.length>0&&a.includes(c.id),N=c.id.trim().length>0&&c.body.trim().length>0&&!O&&!T,A=at(c.domain,s),k=d.useCallback(async()=>{var $,L;const g={...c,id:c.id.trim(),description:($=c.description)!=null&&$.trim()?c.description.trim():void 0,body:c.body,domain:(L=c.domain)!=null&&L.trim()?c.domain.trim():void 0,domains:(c.domains??(c.domain?[c.domain]:[])).map(B=>B.trim()).filter(Boolean),modelAreaRefs:(c.modelAreaRefs??[]).map(B=>B.trim()).filter(Boolean),triggers:(c.triggers??[]).map(B=>B.trim()).filter(Boolean),exclusions:(c.exclusions??[]).map(B=>B.trim()).filter(Boolean),preferredDimensions:(c.preferredDimensions??[]).map(B=>B.trim()).filter(Boolean),requiredFilters:(c.requiredFilters??[]).map(B=>B.trim()).filter(Boolean),clarifyWhen:(c.clarifyWhen??[]).map(B=>B.trim()).filter(Boolean),examples:(c.examples??[]).map(B=>B.trim()).filter(Boolean),sourceRefs:(c.sourceRefs??[]).map(B=>B.trim()).filter(Boolean)};v(!0),x(null);try{const B=w?await M.updateSkill(t.kind==="edit"?t.skill.qualifiedId??t.skill.id:g.id,g):await M.createSkill(g);p(B.skill??g)}catch(B){x(B instanceof Error&&B.message?B.message:"Could not save this skill. Try again.")}finally{v(!1)}},[c,w,t,p]);return e.jsx("div",{style:nn,onClick:()=>!T&&r(),children:e.jsxs("div",{style:sn(o),onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{style:rn(),children:[e.jsx("span",{style:{width:30,height:30,borderRadius:8,background:"var(--accent-dim)",color:o.accent,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(le,{size:15,strokeWidth:1.75})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:14,fontWeight:700,color:o.textPrimary},children:w?"Edit skill":"New skill"}),e.jsx("div",{style:{fontSize:11,color:o.textMuted,marginTop:1},children:"Git-backed guidance · applied only when triggers match"})]}),e.jsx("button",{type:"button",onClick:()=>!T&&r(),style:{...je(o),width:26,height:26,border:"none",background:"none"},title:"Close",children:e.jsx(ue,{size:14,strokeWidth:2})})]}),e.jsxs("div",{style:{flex:1,minHeight:0,overflow:"auto",padding:"18px 22px",display:"grid",gridTemplateColumns:"1fr 1fr",gap:"20px 28px",alignContent:"start"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[e.jsx("div",{style:se(o),children:"Identity"}),e.jsxs("label",{style:Q,children:[e.jsx("span",{style:K(o),children:"Name"}),e.jsx("input",{type:"text",value:u,onChange:g=>W(g.target.value),placeholder:"e.g. Revenue definition",style:q(o)}),e.jsxs("span",{style:{fontSize:10.5,color:o.textMuted},children:["Saved as"," ",e.jsx("input",{type:"text",value:`skills/${c.id}.skill.md`,disabled:w,onChange:g=>{h(!0),b("id",Nt(g.target.value.replace(/^skills\//,"").replace(/\.skill\.md$/,"")))},onBlur:()=>b("id",qe(c.id)),title:"File name — letters, numbers, and dashes",style:{border:"none",background:"none",outline:"none",padding:0,fontFamily:o.fontMono,fontSize:10.5,color:o.textSecondary,width:`${Math.max(20,c.id.length+15)}ch`,borderBottom:w?"none":`1px dashed ${o.btnBorder}`}})]}),O?e.jsx(me,{t:o,tone:"error",children:"A skill with this id already exists."}):null]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[e.jsxs("label",{style:Q,children:[e.jsx("span",{style:K(o),children:"Domain"}),e.jsxs("select",{value:c.domain??"",onChange:g=>{const $=g.target.value||void 0;b("domain",$),b("domains",$?[$]:[])},style:{...q(o),cursor:"pointer",color:c.domain?o.textPrimary:o.textMuted},children:[e.jsx("option",{value:"",children:s.length===0?"No domains yet":"No domain"}),A.map(g=>e.jsx("option",{value:g.value,disabled:g.disabled,children:g.label},g.value))]})]}),e.jsxs("label",{style:Q,children:[e.jsx("span",{style:K(o),children:"Type"}),e.jsxs("select",{value:c.kind??"custom",onChange:g=>b("kind",g.target.value),style:{...q(o),cursor:"pointer"},children:[e.jsx("option",{value:"custom",children:"Custom guidance"}),e.jsx("option",{value:"domain_reference",children:"Domain reference — broad context"}),e.jsx("option",{value:"metric_policy",children:"Policy — focused rule"}),e.jsx("option",{value:"glossary",children:"Glossary"}),e.jsx("option",{value:"analysis_pattern",children:"Analysis pattern"}),e.jsx("option",{value:"sql_policy",children:"SQL policy"})]})]})]}),e.jsx("button",{type:"button",onClick:()=>S({type:"SET_MAIN_VIEW",view:"domains"}),style:{border:"none",background:"none",padding:0,fontSize:10.5,color:o.accent,cursor:"pointer",fontFamily:o.font,alignSelf:"flex-start"},title:"Create a new domain on the Domains page",children:"+ New domain"}),e.jsxs("div",{children:[e.jsx("span",{style:{...K(o),display:"block",marginBottom:5},children:"Lifecycle"}),e.jsx("div",{style:{display:"inline-flex",alignItems:"center",gap:2,padding:2,border:`1px solid ${o.btnBorder}`,borderRadius:7,background:"var(--bg-1)"},children:["active","draft","deprecated"].map(g=>{const $=(c.status??"active")===g;return e.jsx("button",{type:"button",onClick:()=>b("status",g),style:{border:"none",borderRadius:5,padding:"4px 12px",fontSize:11.5,fontWeight:600,cursor:"pointer",fontFamily:o.font,background:$?o.cellBg:"transparent",color:$?o.textPrimary:o.textMuted,boxShadow:$?"0 1px 3px rgba(26,26,26,0.1)":"none",textTransform:"capitalize"},children:g},g)})}),e.jsx("span",{style:{fontSize:10.5,color:o.textMuted,marginLeft:8},children:(c.status??"active")==="active"?"Guides matching answers.":c.status==="draft"?"Drafts never guide answers.":"Kept in Git for history only."})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[e.jsx("div",{style:se(o),children:"When to apply"}),e.jsxs("label",{style:Q,children:[e.jsx("span",{style:K(o),children:"Apply when the question mentions"}),e.jsx(Kt,{t:o,values:c.triggers??[],onChange:g=>b("triggers",g),placeholder:"Add phrase, press Enter"})]}),e.jsxs("label",{style:Q,children:[e.jsx("span",{style:K(o),children:"Ask first when"}),e.jsx(xe,{values:c.clarifyWhen??[],onChange:g=>b("clarifyWhen",g),placeholder:"e.g. 'sales' could mean revenue or order count",style:q(o)})]}),e.jsxs("label",{style:Q,children:[e.jsx("span",{style:K(o),children:"Avoid when"}),e.jsx(xe,{values:c.exclusions??[],onChange:g=>b("exclusions",g),placeholder:"e.g. question is about pipeline or bookings",style:q(o)})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10,gridRow:"span 2"},children:[e.jsx("div",{style:se(o),children:"Guidance"}),e.jsxs("label",{style:Q,children:[e.jsx("span",{style:K(o),children:"One-line summary"}),e.jsx("input",{type:"text",value:c.description??"",onChange:g=>b("description",g.target.value),placeholder:"What rule does this skill encode?",style:q(o)})]}),e.jsxs("label",{style:Q,children:[e.jsx("span",{style:K(o),children:"Full guidance"}),e.jsx("textarea",{value:c.body,onChange:g=>b("body",g.target.value),rows:9,placeholder:"Definitions, exclusions, edge cases — written for the agent.",style:en(o)})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[e.jsx("div",{style:se(o),children:"Prefer these assets"}),e.jsxs("label",{style:Q,children:[e.jsx("span",{style:K(o),children:"Metrics"}),e.jsx(ze,{t:o,options:n.metrics,optionKind:"metrics",selected:c.preferredMetrics,onChange:g=>b("preferredMetrics",g),placeholder:"Search metrics…",emptyOptionsHint:"No metrics available from the project yet."})]}),e.jsxs("label",{style:Q,children:[e.jsx("span",{style:K(o),children:"Blocks"}),e.jsx(ze,{t:o,options:n.blocks,optionKind:"blocks",selected:c.preferredBlocks,onChange:g=>b("preferredBlocks",g),placeholder:"Search blocks…",emptyOptionsHint:"No blocks available from the project yet."})]})]}),e.jsxs("details",{style:{gridColumn:"1 / -1"},children:[e.jsx("summary",{style:{fontSize:11.5,fontWeight:650,color:o.accent,cursor:"pointer"},children:"Advanced — model areas, dimensions, and vocabulary"}),e.jsxs("div",{style:{display:"grid",gap:14,marginTop:12},children:[e.jsx(he,{label:"Focused model areas (optional)",t:o,hint:"Comma-separated area ids from the Model workspace. This boosts the skill only inside its selected domain; it never expands access.",children:e.jsx(xe,{values:c.modelAreaRefs??[],onChange:g=>b("modelAreaRefs",g),placeholder:"customer_lifecycle, revenue_reporting",style:q(o)})}),e.jsx(he,{label:"Preferred dimensions",t:o,hint:"Business-safe dimensions the agent should prefer when they are compatible.",children:e.jsx(xe,{values:c.preferredDimensions??[],onChange:g=>b("preferredDimensions",g),placeholder:"region, month",style:q(o)})}),e.jsx(he,{label:"Qualified models and relationships",t:o,hint:"Optional canonical IDs from Modeling. Validated references create guided_by edges; legacy free text cannot authorize joins.",children:e.jsx(ze,{t:o,options:n.modelingRefs,optionKind:"modelingRefs",selected:c.sourceRefs??[],onChange:g=>b("sourceRefs",g),placeholder:"Search qualified models and relationships…",emptyOptionsHint:"No governed Modeling references are available yet."})}),e.jsx(he,{label:"Vocabulary",t:o,hint:"Map your terms to a target, e.g. arr → metric:arr or revenue → block:revenue_by_region.",children:e.jsx(Ut,{t:o,value:c.vocabulary,onChange:g=>b("vocabulary",g)})})]})]}),f?e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(me,{t:o,tone:"error",children:f})}):null]}),e.jsxs("div",{style:on(),children:[e.jsx("span",{style:{fontSize:10.5,color:o.textMuted,flex:1,textAlign:"left"},children:"Saved to Git — review in source control before merging."}),e.jsx("button",{type:"button",onClick:()=>!T&&r(),style:J(o),children:"Cancel"}),e.jsxs("button",{type:"button",onClick:k,disabled:!N,style:{...be(o),opacity:N?1:.55},children:[T?e.jsx(F,{size:13,strokeWidth:2}):null,T?"Saving…":w?"Save changes":"Create skill"]})]})]})})}function Kt({t,values:n,onChange:s,placeholder:i}){const[l,a]=d.useState(""),o=r=>{const p=r.trim().replace(/,$/,"");!p||n.includes(p)||(s([...n,p]),a(""))};return e.jsxs("div",{style:Ze(t),children:[n.map(r=>e.jsxs("span",{style:tt(t),children:[r,e.jsx("button",{type:"button",onClick:()=>s(n.filter(p=>p!==r)),style:nt(t),title:"Remove",children:"×"})]},r)),e.jsx("input",{type:"text",value:l,onChange:r=>a(r.target.value),onKeyDown:r=>{r.key==="Enter"||r.key===","?(r.preventDefault(),o(l)):r.key==="Backspace"&&!l&&n.length&&s(n.slice(0,-1))},onBlur:()=>o(l),placeholder:n.length?"":i,style:et(t)})]})}function ze({t,options:n,optionKind:s,selected:i,onChange:l,placeholder:a,emptyOptionsHint:o}){const[r,p]=d.useState(""),[S,w]=d.useState(n);d.useEffect(()=>{let j=!1;const h=window.setTimeout(()=>{M.getSkillOptions(r).then(u=>{j||w(s==="metrics"?u.metrics:s==="blocks"?u.blocks:u.modelingRefs)}).catch(()=>{j||w(n)})},160);return()=>{j=!0,window.clearTimeout(h)}},[s,n,r]);const c=d.useMemo(()=>S.filter(j=>!i.includes(j)).filter(j=>r?j.toLowerCase().includes(r.toLowerCase()):!0).slice(0,8),[S,i,r]),z=j=>{const h=j.trim();!h||i.includes(h)||(l([...i,h]),p(""))};return e.jsxs("div",{style:{display:"grid",gap:6},children:[e.jsxs("div",{style:Ze(t),children:[i.map(j=>e.jsxs("span",{style:{...tt(t),fontFamily:t.fontMono},children:[j,e.jsx("button",{type:"button",onClick:()=>l(i.filter(h=>h!==j)),style:nt(t),title:"Remove",children:"×"})]},j)),e.jsx("input",{type:"text",value:r,onChange:j=>p(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),z(r))},placeholder:i.length?"":a,style:et(t)})]}),c.length>0?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:c.map(j=>e.jsxs("button",{type:"button",onClick:()=>z(j),style:tn(t),children:[e.jsx(ne,{size:10,strokeWidth:2.4})," ",j]},j))}):S.length===0?e.jsxs("div",{style:{fontSize:11,color:t.textMuted},children:[o," You can still type a value and press Enter."]}):null]})}function Ut({t,value:n,onChange:s}){const[i,l]=d.useState(()=>Object.entries(n??{}).map(([r,p])=>({term:r,target:p}))),a=r=>{l(r);const p={};for(const S of r){const w=S.term.trim();w&&(p[w]=S.target.trim())}s(p)},o=(r,p)=>{a(i.map((S,w)=>w===r?{...S,...p}:S))};return e.jsxs("div",{style:{display:"grid",gap:7},children:[i.map((r,p)=>e.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[e.jsx("input",{type:"text",value:r.term,onChange:S=>o(p,{term:S.target.value}),placeholder:"arr",style:{...q(t),flex:1}}),e.jsx("span",{style:{color:t.textMuted,fontSize:13},children:"→"}),e.jsx("input",{type:"text",value:r.target,onChange:S=>o(p,{target:S.target.value}),placeholder:"metric:arr",style:{...q(t),flex:1.3,fontFamily:t.fontMono}}),e.jsx("button",{type:"button",onClick:()=>a(i.filter((S,w)=>w!==p)),style:je(t),title:"Remove row",children:e.jsx(ue,{size:13,strokeWidth:2})})]},p)),e.jsxs("button",{type:"button",onClick:()=>l([...i,{term:"",target:""}]),style:{...J(t),justifySelf:"start"},children:[e.jsx(ne,{size:12,strokeWidth:2.2})," Add term"]})]})}function Qt({t,onAdd:n}){return e.jsxs("div",{style:{border:`1px dashed ${t.cellBorder}`,borderRadius:12,background:t.cellBg,padding:"34px 28px",textAlign:"center",display:"grid",gap:12,justifyItems:"center"},children:[e.jsx("div",{style:{width:44,height:44,borderRadius:10,background:`${t.accent}18`,color:t.accent,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(le,{size:22,strokeWidth:1.9})}),e.jsx("div",{style:{fontSize:15,fontWeight:700,color:t.textPrimary},children:"Teach the AI your business rules"}),e.jsx("div",{style:{fontSize:13,color:t.textMuted,maxWidth:460,lineHeight:1.55},children:'Skills are the definitions, rules, and vocabulary the AI follows when it answers — like "revenue = recognized, not bookings" or "always exclude test accounts." Add your first one to start guiding every answer.'}),e.jsxs("button",{type:"button",onClick:n,style:{...be(t),marginTop:4},children:[e.jsx(ne,{size:14,strokeWidth:2.2})," Add your first skill"]})]})}function Vt({t,message:n,onRetry:s}){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(Te,{size:16,strokeWidth:2,color:t.warning,style:{marginTop:1,flexShrink:0}}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:13,fontWeight:650,color:t.textPrimary},children:"Skills are not available right now"}),e.jsx("div",{style:{fontSize:12.5,color:t.textSecondary,marginTop:4,lineHeight:1.5},children:n}),e.jsxs("button",{type:"button",onClick:s,style:{...J(t),marginTop:10},children:[e.jsx(pe,{size:13,strokeWidth:2})," Retry"]})]})]})}function Jt({skill:t,t:n,deleting:s,error:i,onCancel:l,onConfirm:a}){return e.jsx("div",{style:ln,onClick:l,children:e.jsxs("div",{style:an(n),onClick:o=>o.stopPropagation(),children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9},children:[e.jsx(re,{size:16,strokeWidth:2,color:n.error}),e.jsx("div",{style:{fontSize:15,fontWeight:700,color:n.textPrimary},children:"Delete this skill?"})]}),e.jsxs("div",{style:{fontSize:13,color:n.textSecondary,lineHeight:1.55},children:[e.jsx("span",{style:{fontFamily:n.fontMono,color:n.textPrimary},children:t.id})," will be removed and the AI will stop following it. This can't be undone."]}),i?e.jsx(me,{t:n,tone:"error",children:i}):null,e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[e.jsx("button",{type:"button",onClick:l,disabled:s,style:J(n),children:"Cancel"}),e.jsxs("button",{type:"button",onClick:a,disabled:s,style:{...Zt(n),opacity:s?.6:1},children:[s?e.jsx(F,{size:13,strokeWidth:2}):e.jsx(re,{size:13,strokeWidth:2}),s?"Deleting…":"Delete"]})]})]})})}function se(t){return{fontSize:10,fontWeight:700,letterSpacing:"0.05em",textTransform:"uppercase",color:t.textMuted,marginBottom:5}}function Z({t,label:n,values:s,empty:i,accent:l=!1,mono:a=!1}){return e.jsxs("div",{style:{minWidth:0},children:[e.jsx("div",{style:se(t),children:n}),e.jsx("div",{style:{display:"flex",gap:5,flexWrap:"wrap"},children:s!=null&&s.length?s.map(o=>e.jsx("span",{style:{fontSize:11,padding:"3px 9px",borderRadius:999,background:l?"var(--accent-dim)":"var(--bg-1)",color:l?t.accent:t.textSecondary,border:l?`1px solid ${t.accent}33`:"1px solid var(--border-subtle)",fontFamily:a?t.fontMono:void 0},children:o},o)):e.jsx("span",{style:{fontSize:11.5,color:t.textMuted,fontStyle:"italic"},children:i})})]})}function he({label:t,hint:n,t:s,children:i}){return e.jsxs("div",{style:{display:"grid",gap:6},children:[e.jsx("label",{style:{fontSize:12,fontWeight:700,color:s.textPrimary},children:t}),n?e.jsx("div",{style:{fontSize:11.5,color:s.textMuted,lineHeight:1.45,marginTop:-2},children:n}):null,i]})}function me({t,tone:n,children:s}){const i=n==="error"?t.error:t.textMuted;return e.jsx("div",{style:{fontSize:11.5,color:i,lineHeight:1.45},children:s})}function Yt(t){return{display:"inline-flex",alignItems:"center",fontSize:10.5,fontWeight:700,color:t.success,background:`${t.success}14`,border:`1px solid ${t.success}38`,borderRadius:999,padding:"2px 7px"}}function Xt(t){return{display:"inline-flex",alignItems:"center",fontSize:10.5,fontWeight:700,color:t.accent,background:`${t.accent}14`,border:`1px solid ${t.accent}38`,borderRadius:999,padding:"2px 7px"}}function be(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 J(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 Zt(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 je(t){return{display:"inline-flex",alignItems:"center",justifyContent:"center",width:30,height:30,borderRadius:7,border:`1px solid ${t.btnBorder}`,background:t.btnBg,color:t.textSecondary,cursor:"pointer",flexShrink:0}}function q(t){return{width:"100%",border:`1px solid ${t.btnBorder}`,borderRadius:7,background:t.cellBg,color:t.textPrimary,fontSize:12.5,fontFamily:t.font,padding:"8px 10px",boxSizing:"border-box"}}function en(t){return{...q(t),resize:"vertical",lineHeight:1.5,padding:"9px 11px"}}function Ge(t){return{display:"inline-flex",alignItems:"center",gap:4,fontSize:10,fontWeight:700,letterSpacing:"0.02em",color:t.warning,background:`${t.warning}16`,border:`1px solid ${t.warning}40`,borderRadius:999,padding:"2px 8px"}}function Ze(t){return{display:"flex",alignItems:"center",gap:5,flexWrap:"wrap",border:`1px solid ${t.btnBorder}`,background:t.cellBg,borderRadius:7,padding:"6px 8px"}}function et(t){return{flex:1,minWidth:110,border:"none",background:"none",outline:"none",fontSize:11.5,fontFamily:t.font,color:t.textPrimary,padding:2}}function tt(t){return{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,padding:"2.5px 8px",borderRadius:999,background:"var(--accent-dim)",color:t.accent,border:`1px solid ${t.accent}33`}}function nt(t){return{border:"none",background:"none",color:t.accent,cursor:"pointer",padding:0,fontSize:12,lineHeight:1,fontFamily:t.font}}const Q={display:"flex",flexDirection:"column",gap:4};function K(t){return{fontSize:11,fontWeight:650,color:t.textSecondary}}function tn(t){return{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,fontWeight:600,color:t.textSecondary,background:t.btnBg,border:`1px solid ${t.btnBorder}`,borderRadius:6,padding:"3px 8px",cursor:"pointer",fontFamily:t.fontMono}}const nn={position:"fixed",inset:0,background:"rgba(26, 26, 26, 0.22)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:60};function sn(t){return{width:"min(860px, 94vw)",height:"min(640px, 90vh)",background:t.cellBg,border:`1px solid ${t.headerBorder}`,borderRadius:14,display:"flex",flexDirection:"column",overflow:"hidden",boxShadow:"0 24px 70px rgba(26,26,26,0.22)"}}function rn(t){return{display:"flex",alignItems:"center",gap:10,padding:"14px 18px",borderBottom:"1px solid var(--border-subtle)",flexShrink:0}}function on(t){return{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:8,padding:"12px 18px",borderTop:"1px solid var(--border-subtle)",background:"var(--bg-1)",flexShrink:0}}const ln={position:"fixed",inset:0,background:"rgba(0, 0, 0, 0.42)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:70,padding:20};function an(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 dn({initialTab:t="overview"}){const{state:n}=ve(),s=ke[n.themeMode],[i,l]=d.useState(t),[a,o]=d.useState([]),[r,p]=d.useState([]),[S,w]=d.useState(!0);d.useEffect(()=>l(t),[t]);const c=d.useCallback(()=>{let u=!1;return w(!0),Promise.all([M.getDomains(),M.getSkills()]).then(([D,T])=>{u||(o(Array.isArray(D.domains)?D.domains:[]),p(Array.isArray(T.skills)?T.skills:[]))}).catch(()=>{u||(o([]),p([]))}).finally(()=>{u||w(!1)}),()=>{u=!0}},[]);d.useEffect(()=>c(),[c]);const z=d.useMemo(()=>{const u=a.filter(v=>!!(v.businessOwner||v.owner)).length,D=r.filter(v=>!v.status||v.status==="active").length,T=r.filter(v=>v.status==="draft").length;return{ownedDomains:u,activeSkills:D,draftSkills:T}},[a,r]),j=d.useCallback(()=>{l("domains"),window.setTimeout(()=>window.dispatchEvent(new Event("dql:context-build")),50)},[]),h=[{id:"overview",label:"Overview"},{id:"domains",label:"Domains",count:a.length},{id:"skills",label:"Skills",count:r.length},{id:"knowledge",label:"Knowledge 360"}];return e.jsx("div",{style:{flex:1,minWidth:0,overflow:"auto",background:s.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(oe,{size:20,color:s.accent}),e.jsx("h1",{style:{fontSize:22,color:s.textPrimary},children:"Governed context"})]}),e.jsx("p",{style:{marginTop:6,fontSize:13,lineHeight:1.5,color:s.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:j,style:st(s),children:[e.jsx(te,{size:14})," Build with AI"]})]}),e.jsx("nav",{"aria-label":"Governed context sections",style:{display:"flex",gap:3,borderBottom:`1px solid ${s.headerBorder}`,marginBottom:18},children:h.map(u=>e.jsxs("button",{type:"button",onClick:()=>l(u.id),style:{border:"none",borderBottom:`2px solid ${i===u.id?s.accent:"transparent"}`,background:"transparent",padding:"9px 12px",color:i===u.id?s.textPrimary:s.textMuted,fontWeight:i===u.id?700:600,cursor:"pointer",fontFamily:s.font,fontSize:12.5},children:[u.label,u.count!==void 0?` · ${u.count}`:""]},u.id))}),i==="overview"?e.jsx(cn,{t:s,loading:S,domains:a,skills:r,status:z,onBuild:j,onTab:l}):null,i==="domains"?e.jsx(yt,{embedded:!0}):null,i==="skills"?e.jsx(Lt,{embedded:!0}):null,i==="knowledge"?e.jsx(it,{t:s,domains:a}):null]})})}function it({t,domains:n,initialDomainId:s}){var z,j;const[i,l]=d.useState(s??((z=n[0])==null?void 0:z.id)??""),[a,o]=d.useState(null),[r,p]=d.useState(!1),[S,w]=d.useState(null);d.useEffect(()=>{var h;!i&&((h=n[0])!=null&&h.id)&&l(n[0].id)},[i,n]),d.useEffect(()=>{s&&n.some(h=>h.id===s)&&l(s)},[n,s]),d.useEffect(()=>{if(!i){o(null);return}let h=!1;return p(!0),w(null),M.getDomainKnowledge(i).then(u=>{h||o(u)}).catch(u=>{h||(o(null),w(u instanceof Error?u.message:"Could not load the compiled knowledge capsule."))}).finally(()=>{h||p(!1)}),()=>{h=!0}},[i]);const c=d.useMemo(()=>{const h={};for(const u of(a==null?void 0:a.objects)??[])h[u.kind]=(h[u.kind]??0)+1;return Object.entries(h).sort((u,D)=>D[1]-u[1]||u[0].localeCompare(D[0]))},[a]);return e.jsxs("div",{style:{display:"grid",gap:14},children:[e.jsx("section",{style:{border:`1px solid ${t.cellBorder}`,borderRadius:10,background:t.cellBg,padding:15},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:12,flexWrap:"wrap"},children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",gap:7,alignItems:"center",color:t.textPrimary,fontWeight:700,fontSize:13},children:[e.jsx(Oe,{size:16,color:t.accent})," Compiled Domain 360"]}),e.jsx("div",{style:{marginTop:4,color:t.textMuted,fontSize:12},children:"The same qualified graph, route policy, and skill snapshot used by Ask."})]}),e.jsxs("select",{"aria-label":"Domain knowledge capsule",value:i,onChange:h=>l(h.target.value),style:{minWidth:210,border:`1px solid ${t.inputBorder}`,borderRadius:7,background:t.inputBg,color:t.textPrimary,padding:"7px 9px",fontFamily:t.font},children:[e.jsx("option",{value:"",children:"Select a domain"}),[...n].sort((h,u)=>h.name.localeCompare(u.name)).map(h=>e.jsx("option",{value:h.id,children:h.name},h.id))]})]})}),r?e.jsxs("div",{style:{color:t.textMuted,display:"flex",gap:8,alignItems:"center",padding:24},children:[e.jsx(F,{size:15})," Loading compiled knowledge…"]}):null,S?e.jsx("div",{style:{border:`1px solid ${t.error}`,background:t.cellBg,color:t.error,borderRadius:8,padding:12,fontSize:12.5},children:S}):null,a?e.jsxs(e.Fragment,{children:[e.jsxs("section",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:9},children:[e.jsx(ee,{t,label:"Objects",value:a.counts.objects,detail:"qualified knowledge",icon:e.jsx(oe,{size:16})}),e.jsx(ee,{t,label:"Relations",value:a.counts.edges,detail:"provenance + policy",icon:e.jsx(Oe,{size:16})}),e.jsx(ee,{t,label:"Authorized",value:a.counts.routeStates.authorized??0,detail:"safe cross-domain routes",icon:e.jsx(Be,{size:16})}),e.jsx(ee,{t,label:"Blocked / stale",value:(a.counts.routeStates.blocked??0)+(a.counts.routeStates.stale??0),detail:"never auto-joined",icon:e.jsx(Je,{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:((j=a.capsule)==null?void 0:j.description)||"Compiled domain boundary and governed references."}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:c.map(([h,u])=>e.jsxs("span",{style:{border:`1px solid ${t.cellBorder}`,background:t.pillBg,color:t.textSecondary,borderRadius:999,padding:"3px 7px",fontSize:11},children:[h.replace(/_/g," ")," · ",u]},h))}),e.jsxs("div",{style:{marginTop:11,color:t.textMuted,fontSize:11},children:["Snapshot ",a.snapshotId.slice(0,12)," · graph ",a.sourceFingerprint.slice(0,12),a.truncated?" · bounded response":""]})]}),e.jsxs("div",{style:{border:`1px solid ${t.cellBorder}`,borderRadius:9,background:t.cellBg,padding:14},children:[e.jsx("strong",{style:{color:t.textPrimary,fontSize:13},children:"Cross-domain routes"}),e.jsx("div",{style:{display:"grid",gap:7,marginTop:9},children:a.routes.length?a.routes.map(h=>e.jsxs("div",{style:{borderTop:`1px solid ${t.headerBorder}`,paddingTop:7},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:8,color:t.textSecondary,fontSize:12},children:[e.jsxs("span",{children:[h.providerDomainId," → ",h.consumerDomainId]}),e.jsx("span",{style:{color:h.state==="authorized"?t.success:h.state==="observed"?t.textMuted:t.warning,fontWeight:700},children:h.state})]}),e.jsx("div",{style:{marginTop:3,color:t.textMuted,fontSize:11},children:h.purpose||h.reasonCodes.join(", ")||"governed route"})]},h.id)):e.jsx("div",{style:{color:t.textMuted,fontSize:12,marginTop:8},children:"No cross-domain routes declared."})})]})]})]}):null]})}function cn({t,loading:n,domains:s,skills:i,status:l,onBuild:a,onTab:o}){if(n)return e.jsxs("div",{style:{padding:"42px 0",color:t.textMuted,display:"flex",gap:8,alignItems:"center",fontSize:13},children:[e.jsx(F,{size:15})," Loading governed context…"]});const r=[];return s.length?l.ownedDomains<s.length&&r.push(`${s.length-l.ownedDomains} domain${s.length-l.ownedDomains===1?"":"s"} still need an owner.`):r.push("Create a business domain before relying on AI guidance."),i.length||r.push("Draft a domain skill so the agent has governed business guidance."),l.draftSkills&&r.push(`${l.draftSkills} skill${l.draftSkills===1?" is":"s are"} still draft-only and will not guide answers.`),e.jsxs("div",{style:{display:"grid",gap:16},children:[e.jsxs("section",{style:{display:"grid",gridTemplateColumns:"repeat(3, minmax(0, 1fr))",gap:10},children:[e.jsx(ee,{t,label:"Domains",value:s.length,detail:`${l.ownedDomains} with an owner`,icon:e.jsx(oe,{size:17})}),e.jsx(ee,{t,label:"Active skills",value:l.activeSkills,detail:"available to the agent",icon:e.jsx(le,{size:17})}),e.jsx(ee,{t,label:"Draft skills",value:l.draftSkills,detail:"review before activation",icon:e.jsx(te,{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(Ve,{size:16,color:r.length?t.warning:t.success}),e.jsx("strong",{style:{color:t.textPrimary,fontSize:13},children:"Readiness"})]}),r.length?e.jsx("div",{style:{display:"grid",gap:6},children:r.map(p=>e.jsxs("div",{style:{display:"flex",gap:7,color:t.textSecondary,fontSize:12.5},children:[e.jsx(Je,{size:14,color:t.warning}),p]},p))}):e.jsx("div",{style:{color:t.success,fontSize:12.5},children:"Your agent has owned domains and active governed skills available for retrieval."}),e.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",marginTop:2},children:[e.jsxs("button",{type:"button",onClick:a,style:st(t),children:[e.jsx(te,{size:13})," Build domains & skills with AI"]}),e.jsx("button",{type:"button",onClick:()=>o("domains"),style:Ke(t),children:"Manage domains"}),e.jsx("button",{type:"button",onClick:()=>o("skills"),style:Ke(t),children:"Manage skills"})]})]})]})}function ee({t,label:n,value:s,detail:i,icon:l}){return e.jsxs("div",{style:{border:`1px solid ${t.cellBorder}`,borderRadius:9,background:t.cellBg,padding:13},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",color:t.textMuted,fontSize:12},children:[n,l]}),e.jsx("div",{style:{color:t.textPrimary,fontSize:25,fontWeight:750,marginTop:7},children:s}),e.jsx("div",{style:{color:t.textMuted,fontSize:11.5,marginTop:3},children:i})]})}function st(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 Ke(t){return{display:"inline-flex",alignItems:"center",padding:"7px 12px",borderRadius:7,border:`1px solid ${t.btnBorder}`,background:t.btnBg,color:t.textSecondary,fontWeight:650,fontSize:12.5,fontFamily:t.font,cursor:"pointer"}}const yn=Object.freeze(Object.defineProperty({__proto__:null,GovernedContextPage:dn,Knowledge360:it},Symbol.toStringTag,{value:"Module"}));export{Et as C,yn as G,it as K,Lt as S};