@oscharko-dev/keiko 0.2.0-beta.0 → 0.2.0-beta.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.
Files changed (102) hide show
  1. package/README.md +6 -5
  2. package/dist/ui/csp-hashes.json +20 -20
  3. package/dist/ui/static/404.html +1 -1
  4. package/dist/ui/static/_next/static/chunks/{422-70c16ea4b1f77f2e.js → 923-4141696576191bc0.js} +1 -1
  5. package/dist/ui/static/_next/static/chunks/app/_not-found/page-03d642dcd0f15b52.js +1 -0
  6. package/dist/ui/static/_next/static/chunks/app/launch/page-c725ff0c02b50663.js +1 -0
  7. package/dist/ui/static/_next/static/chunks/app/layout-aadefe615729db05.js +1 -0
  8. package/dist/ui/static/_next/static/chunks/app/local-knowledge/capsule/{page-0dc74e194a1f0092.js → page-4a7f242906e19a07.js} +1 -1
  9. package/dist/ui/static/_next/static/chunks/app/local-knowledge/page-3361769b8964e659.js +1 -0
  10. package/dist/ui/static/_next/static/chunks/app/memoriaviva/consolidation/{page-dc6c6bd180bc47a3.js → page-44b3f4fa3e10085f.js} +1 -1
  11. package/dist/ui/static/_next/static/chunks/app/memoriaviva/detail/{page-659e308e68ab2b1e.js → page-0cdfb3eeb659daeb.js} +1 -1
  12. package/dist/ui/static/_next/static/chunks/app/memoriaviva/{page-d6ba78f54207b69f.js → page-e78e0cd2876fec41.js} +1 -1
  13. package/dist/ui/static/_next/static/chunks/app/memoriaviva/review-queue/page-e32fe86466827484.js +1 -0
  14. package/dist/ui/static/_next/static/chunks/app/page-9ad91065d05ddfa0.js +1 -0
  15. package/dist/ui/static/_next/static/chunks/{main-app-5b043f6c611974ae.js → main-app-b52a8fa1d8127a5f.js} +1 -1
  16. package/dist/ui/static/apple-touch-icon.png +0 -0
  17. package/dist/ui/static/favicon.ico +0 -0
  18. package/dist/ui/static/icon-192-maskable.png +0 -0
  19. package/dist/ui/static/icon-192.png +0 -0
  20. package/dist/ui/static/icon-512-maskable.png +0 -0
  21. package/dist/ui/static/icon-512.png +0 -0
  22. package/dist/ui/static/index.html +1 -1
  23. package/dist/ui/static/index.txt +3 -3
  24. package/dist/ui/static/launch.html +1 -1
  25. package/dist/ui/static/launch.txt +3 -3
  26. package/dist/ui/static/local-knowledge/capsule.html +1 -1
  27. package/dist/ui/static/local-knowledge/capsule.txt +2 -2
  28. package/dist/ui/static/local-knowledge.html +1 -1
  29. package/dist/ui/static/local-knowledge.txt +2 -2
  30. package/dist/ui/static/memoriaviva/consolidation.html +1 -1
  31. package/dist/ui/static/memoriaviva/consolidation.txt +2 -2
  32. package/dist/ui/static/memoriaviva/detail.html +1 -1
  33. package/dist/ui/static/memoriaviva/detail.txt +2 -2
  34. package/dist/ui/static/memoriaviva/review-queue.html +1 -1
  35. package/dist/ui/static/memoriaviva/review-queue.txt +2 -2
  36. package/dist/ui/static/memoriaviva.html +1 -1
  37. package/dist/ui/static/memoriaviva.txt +2 -2
  38. package/node_modules/@oscharko-dev/keiko-cli/dist/.tsbuildinfo +1 -1
  39. package/node_modules/@oscharko-dev/keiko-cli/package.json +1 -1
  40. package/node_modules/@oscharko-dev/keiko-contracts/dist/.tsbuildinfo +1 -1
  41. package/node_modules/@oscharko-dev/keiko-contracts/dist/index.d.ts +1 -1
  42. package/node_modules/@oscharko-dev/keiko-contracts/dist/index.js +1 -1
  43. package/node_modules/@oscharko-dev/keiko-contracts/package.json +1 -1
  44. package/node_modules/@oscharko-dev/keiko-evaluations/dist/.tsbuildinfo +1 -1
  45. package/node_modules/@oscharko-dev/keiko-evaluations/package.json +1 -1
  46. package/node_modules/@oscharko-dev/keiko-evidence/dist/.tsbuildinfo +1 -1
  47. package/node_modules/@oscharko-dev/keiko-evidence/package.json +1 -1
  48. package/node_modules/@oscharko-dev/keiko-harness/dist/.tsbuildinfo +1 -1
  49. package/node_modules/@oscharko-dev/keiko-harness/package.json +1 -1
  50. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/.tsbuildinfo +1 -1
  51. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/parsers/pdf-parser.d.ts.map +1 -1
  52. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/parsers/pdf-parser.js +2 -2
  53. package/node_modules/@oscharko-dev/keiko-local-knowledge/package.json +1 -1
  54. package/node_modules/@oscharko-dev/keiko-memory-capture/package.json +1 -1
  55. package/node_modules/@oscharko-dev/keiko-memory-consolidation/package.json +1 -1
  56. package/node_modules/@oscharko-dev/keiko-memory-governance/package.json +1 -1
  57. package/node_modules/@oscharko-dev/keiko-memory-retrieval/package.json +1 -1
  58. package/node_modules/@oscharko-dev/keiko-memory-vault/dist/.tsbuildinfo +1 -1
  59. package/node_modules/@oscharko-dev/keiko-memory-vault/package.json +1 -1
  60. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/.tsbuildinfo +1 -1
  61. package/node_modules/@oscharko-dev/keiko-model-gateway/package.json +1 -1
  62. package/node_modules/@oscharko-dev/keiko-quality-intelligence/dist/.tsbuildinfo +1 -1
  63. package/node_modules/@oscharko-dev/keiko-quality-intelligence/package.json +1 -1
  64. package/node_modules/@oscharko-dev/keiko-sdk/dist/.tsbuildinfo +1 -1
  65. package/node_modules/@oscharko-dev/keiko-sdk/package.json +1 -1
  66. package/node_modules/@oscharko-dev/keiko-security/dist/.tsbuildinfo +1 -1
  67. package/node_modules/@oscharko-dev/keiko-security/package.json +1 -1
  68. package/node_modules/@oscharko-dev/keiko-server/dist/.tsbuildinfo +1 -1
  69. package/node_modules/@oscharko-dev/keiko-server/package.json +1 -1
  70. package/node_modules/@oscharko-dev/keiko-tools/dist/.tsbuildinfo +1 -1
  71. package/node_modules/@oscharko-dev/keiko-tools/package.json +1 -1
  72. package/node_modules/@oscharko-dev/keiko-verification/dist/.tsbuildinfo +1 -1
  73. package/node_modules/@oscharko-dev/keiko-verification/package.json +1 -1
  74. package/node_modules/@oscharko-dev/keiko-workflows/dist/.tsbuildinfo +1 -1
  75. package/node_modules/@oscharko-dev/keiko-workflows/package.json +1 -1
  76. package/node_modules/@oscharko-dev/keiko-workspace/dist/.tsbuildinfo +1 -1
  77. package/node_modules/@oscharko-dev/keiko-workspace/package.json +1 -1
  78. package/package.json +4 -3
  79. package/dist/ui/static/_next/static/chunks/app/_not-found/page-c4d800f366186be0.js +0 -1
  80. package/dist/ui/static/_next/static/chunks/app/launch/page-08afd1a052e7662c.js +0 -1
  81. package/dist/ui/static/_next/static/chunks/app/layout-0f75a39edc90325d.js +0 -1
  82. package/dist/ui/static/_next/static/chunks/app/local-knowledge/page-48bd57c5e542349e.js +0 -1
  83. package/dist/ui/static/_next/static/chunks/app/memoriaviva/review-queue/page-7186cd8b22efc78b.js +0 -1
  84. package/dist/ui/static/_next/static/chunks/app/page-f8386b8e05b3db03.js +0 -1
  85. package/node_modules/@napi-rs/canvas/LICENSE +0 -21
  86. package/node_modules/@napi-rs/canvas/README.md +0 -448
  87. package/node_modules/@napi-rs/canvas/geometry.js +0 -873
  88. package/node_modules/@napi-rs/canvas/index.d.ts +0 -1097
  89. package/node_modules/@napi-rs/canvas/index.js +0 -196
  90. package/node_modules/@napi-rs/canvas/js-binding.js +0 -464
  91. package/node_modules/@napi-rs/canvas/load-image.js +0 -156
  92. package/node_modules/@napi-rs/canvas/node-canvas.d.ts +0 -216
  93. package/node_modules/@napi-rs/canvas/node-canvas.js +0 -379
  94. package/node_modules/@napi-rs/canvas/package.json +0 -179
  95. package/node_modules/@napi-rs/canvas-linux-x64-gnu/README.md +0 -3
  96. package/node_modules/@napi-rs/canvas-linux-x64-gnu/package.json +0 -47
  97. package/node_modules/@napi-rs/canvas-linux-x64-gnu/skia.linux-x64-gnu.node +0 -0
  98. package/node_modules/@napi-rs/canvas-linux-x64-musl/README.md +0 -3
  99. package/node_modules/@napi-rs/canvas-linux-x64-musl/package.json +0 -47
  100. package/node_modules/@napi-rs/canvas-linux-x64-musl/skia.linux-x64-musl.node +0 -0
  101. /package/dist/ui/static/_next/static/{IZjQES_2JaG9qZ7_fkEPl → BNiyfCos3TiM2QdurajIZ}/_buildManifest.js +0 -0
  102. /package/dist/ui/static/_next/static/{IZjQES_2JaG9qZ7_fkEPl → BNiyfCos3TiM2QdurajIZ}/_ssgManifest.js +0 -0
@@ -1 +1 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[422],{1352:(e,t,n)=>{"use strict";n.d(t,{Af:()=>i,CZ:()=>m,Ir:()=>o,RT:()=>b,Rx:()=>p,W_:()=>u,ax:()=>f,fC:()=>d,h0:()=>v,hz:()=>g,mc:()=>y,oW:()=>x,tR:()=>c,w0:()=>h,xr:()=>r});var a=n(2982);async function l(e){try{let t=await e.json();return{code:t.error.code,message:t.error.message}}catch(t){return{code:"INTERNAL",message:"HTTP ".concat(e.status.toString())}}}async function s(e,t){var n;let s=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),i=null==t?void 0:t.body,r=await fetch(e,{...t,headers:function(e,t){let n={Accept:"application/json"};return null!=t&&(n["Content-Type"]="application/json"),"GET"!==e&&"HEAD"!==e&&(n["X-Keiko-CSRF"]="1"),n}(s,i)});if(!r.ok){let{code:e,message:t}=await l(r);throw new a.hD(e,t,r.status)}return r.json()}async function i(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s,n=new URLSearchParams;void 0!==e.scope&&e.scope.length>0&&n.set("scope",e.scope.join(",")),void 0!==e.type&&e.type.length>0&&n.set("type",e.type.join(",")),void 0!==e.status&&e.status.length>0&&n.set("status",e.status.join(",")),void 0!==e.sensitivity&&e.sensitivity.length>0&&n.set("sensitivity",e.sensitivity.join(",")),void 0!==e.limit&&n.set("limit",e.limit.toString()),void 0!==e.offset&&n.set("offset",e.offset.toString());let a=n.toString();return t("/api/memory".concat(a.length>0?"?".concat(a):""))}async function r(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:s;return e("/api/memory/review-queue")}async function o(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/consolidation/jobs",{method:"POST",body:JSON.stringify({settings:e})})}async function c(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/consolidation/jobs/".concat(encodeURIComponent(e)))}async function d(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/consolidation/jobs/".concat(encodeURIComponent(e),"/cancel"),{method:"POST",body:"{}"})}async function u(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/".concat(encodeURIComponent(e)))}async function h(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:s;return n("/api/memory/".concat(encodeURIComponent(e)),{method:"PATCH",body:JSON.stringify(t)})}async function p(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/".concat(encodeURIComponent(e),"/pin"),{method:"POST",body:"{}"})}async function m(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/".concat(encodeURIComponent(e),"/unpin"),{method:"POST",body:"{}"})}async function f(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:s;return n("/api/memory/".concat(encodeURIComponent(e),"/archive"),{method:"POST",body:JSON.stringify({...void 0!==t?{reason:t}:{}})})}async function g(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:s;return n("/api/memory/".concat(encodeURIComponent(e),"/forget"),{method:"POST",body:JSON.stringify({acknowledged:!0,...void 0!==t?{reason:t}:{}})})}async function v(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/".concat(encodeURIComponent(e)),{method:"DELETE",body:"{}"})}async function x(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:s;return n("/api/memory/".concat(encodeURIComponent(e),"/correct"),{method:"POST",body:JSON.stringify({body:t})})}async function y(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/proposals/".concat(encodeURIComponent(e),"/accept"),{method:"POST",body:"{}"})}async function b(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:s;return n("/api/memory/proposals/".concat(encodeURIComponent(e),"/reject"),{method:"POST",body:JSON.stringify({...void 0!==t?{reason:t}:{}})})}},4723:(e,t,n)=>{"use strict";n.d(t,{KeikoDesktop:()=>iQ});var a=n(4568),l=n(7620);let s=(0,l.createContext)(null);function i(e){let{value:t,children:n}=e;return(0,a.jsx)(s.Provider,{value:t,children:n})}function r(){let e=(0,l.useContext)(s);if(null===e)throw Error("useChatSessionContext must be used inside ChatSessionProvider");return e}function o(){return(0,l.useContext)(s)}let c=[{id:"read",action:"Read files",scope:"workspace",decision:"allow"},{id:"write",action:"Write files",scope:"src/** \xb7 docs/**",decision:"allow"},{id:"write-prod",action:"Write files",scope:"prod/** \xb7 infra/**",decision:"deny"},{id:"command",action:"Run commands",scope:"test \xb7 build \xb7 lint",decision:"allow"},{id:"command-danger",action:"Run commands",scope:"deploy \xb7 rm \xb7 db",decision:"ask"},{id:"network",action:"Network / fetch",scope:"allowlist",decision:"ask"},{id:"pr",action:"Open pull request",scope:"feature branches",decision:"allow"},{id:"mail",action:"Mail / calendar",scope:"any",decision:"ask"}],d=["Prefers TypeScript + functional React","Writes Conventional Commits","Always reviews diffs before merge","Never touches infra without explicit ok","Deep-work mornings (CET), async afternoons"],u={calendar:!0,mail:!1,jira:!0,docs:!0},h="keiko.twin.mode",p="keiko.twin.persona",m="keiko.twin.policy",f="keiko.twin.memory",g="keiko.twin.bridges",v=(0,l.createContext)(null);function x(e,t){try{let n=window.localStorage.getItem(e);if(null===n)return t;let a=JSON.parse(n);return null==a?t:a}catch(e){return t}}function y(e,t){try{window.localStorage.setItem(e,t)}catch(e){}}function b(e,t){try{window.localStorage.setItem(e,JSON.stringify(t))}catch(e){}}function j(e){let{children:t}=e,[n,s]=(0,l.useState)("manual"),[i,r]=(0,l.useState)("Developer"),[o,j]=(0,l.useState)(c),[w,k]=(0,l.useState)(d),[N,S]=(0,l.useState)(u),[C,R]=(0,l.useState)(!1);(0,l.useEffect)(()=>{s(function(){try{let e=window.localStorage.getItem(h);return"manual"===e||"autonomous"===e?e:"manual"}catch(e){return"manual"}}()),r(function(){try{let e=window.localStorage.getItem(p);if("Developer"===e||"Product Owner"===e||"Designer"===e)return e;return"Developer"}catch(e){return"Developer"}}()),j(x(m,c)),k(x(f,d)),S(x(g,u)),R(!0)},[]),(0,l.useEffect)(()=>{C&&y(h,n)},[n,C]),(0,l.useEffect)(()=>{C&&y(p,i)},[i,C]),(0,l.useEffect)(()=>{C&&b(m,o)},[o,C]),(0,l.useEffect)(()=>{C&&b(f,w)},[w,C]),(0,l.useEffect)(()=>{C&&b(g,N)},[N,C]);let I=(0,l.useCallback)((e,t)=>(function(e,t,n){var a,l,s,i,r,o,c;let d=t=>{var n,a;return null!=(a=null==(n=e.find(e=>e.id===t))?void 0:n.decision)?a:null};return"write"===t?"high"===n?null!=(a=d("write-prod"))?a:"deny":null!=(l=d("write"))?l:"allow":"command"===t?"high"===n?null!=(s=d("command-danger"))?s:"ask":null!=(i=d("command"))?i:"allow":"git"===t?null!=(r=d("pr"))?r:"allow":"mail"===t?null!=(o=d("mail"))?o:"ask":"network"===t&&null!=(c=d("network"))?c:"ask"})(o,e,t),[o]),E=(0,l.useMemo)(()=>({mode:n,setMode:s,persona:i,setPersona:r,policy:o,setPolicy:j,memory:w,setMemory:k,bridges:N,setBridges:S,decide:I}),[n,i,o,w,N,I]);return(0,a.jsx)(v.Provider,{value:E,children:t})}function w(){let e=(0,l.useContext)(v);if(null===e)throw Error("useTwin must be used inside <TwinProvider>");return e}let k=(0,l.createContext)({wins:[],active:null,winCount:0});function N(e){let{size:t=18,sw:n=1.6,vb:l=24,fill:s,style:i,children:r,d:o}=e,c=void 0!==s;return(0,a.jsx)("svg",{width:t,height:t,viewBox:"0 0 ".concat(String(l)," ").concat(String(l)),fill:c?s:"none",stroke:c?"none":"currentColor",strokeWidth:n,strokeLinecap:"round",strokeLinejoin:"round",style:i,"aria-hidden":"true",children:void 0!==o?(0,a.jsx)("path",{d:o}):r})}let S={newChat:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("path",{d:"M4 5h10M4 9h7"}),(0,a.jsx)("path",{d:"M14.5 13.5l4-4a1.6 1.6 0 0 1 2.3 2.3l-6.2 6.2-3 .7.7-3 6.2-6.2"})]}),search:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"11",cy:"11",r:"6.5"}),(0,a.jsx)("path",{d:"M20 20l-4.3-4.3"})]}),plugins:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"4",y:"4",width:"6.5",height:"6.5",rx:"1.5"}),(0,a.jsx)("rect",{x:"13.5",y:"4",width:"6.5",height:"6.5",rx:"1.5"}),(0,a.jsx)("rect",{x:"4",y:"13.5",width:"6.5",height:"6.5",rx:"1.5"}),(0,a.jsx)("rect",{x:"13.5",y:"13.5",width:"6.5",height:"6.5",rx:"1.5"})]}),automations:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"12",cy:"12",r:"8"}),(0,a.jsx)("path",{d:"M12 7.5V12l3 2"})]}),mobile:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"7",y:"3",width:"10",height:"18",rx:"2.5"}),(0,a.jsx)("path",{d:"M11 18h2"})]}),folder:e=>(0,a.jsx)(N,{...e,d:"M3.5 7a2 2 0 0 1 2-2h3.2a2 2 0 0 1 1.4.6l1 1a2 2 0 0 0 1.4.6H18.5a2 2 0 0 1 2 2v6.2a2 2 0 0 1-2 2h-13a2 2 0 0 1-2-2V7Z"}),settings:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("path",{d:"M10.325 4.317c.426 -1.756 2.924 -1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543 -.94 3.31 .826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756 .426 1.756 2.924 0 3.35a1.724 1.724 0 0 0 -1.066 2.573c.94 1.543 -.826 3.31 -2.37 2.37a1.724 1.724 0 0 0 -2.572 1.065c-.426 1.756 -2.924 1.756 -3.35 0a1.724 1.724 0 0 0 -2.573 -1.066c-1.543 .94 -3.31 -.826 -2.37 -2.37a1.724 1.724 0 0 0 -1.065 -2.572c-1.756 -.426 -1.756 -2.924 0 -3.35a1.724 1.724 0 0 0 1.066 -2.573c-.94 -1.543 .826 -3.31 2.37 -2.37c1 .608 2.296 .07 2.572 -1.065z"}),(0,a.jsx)("circle",{cx:"12",cy:"12",r:"3"})]}),files:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("path",{d:"M13 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V9z"}),(0,a.jsx)("path",{d:"M13 3v6h6"})]}),browser:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"12",cy:"12",r:"8.5"}),(0,a.jsx)("path",{d:"M3.5 12h17M12 3.5c2.3 2.3 2.3 14.7 0 17M12 3.5c-2.3 2.3-2.3 14.7 0 17"})]}),review:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("path",{d:"M9 12l2 2 4-4"}),(0,a.jsx)("rect",{x:"3.5",y:"4.5",width:"17",height:"15",rx:"2.5"})]}),terminal:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"3.5",y:"4.5",width:"17",height:"15",rx:"2.5"}),(0,a.jsx)("path",{d:"M7.5 9l3 3-3 3M13 15h4"})]}),agents:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"5",y:"7",width:"14",height:"11",rx:"3"}),(0,a.jsx)("path",{d:"M12 7V4M9 12h.01M15 12h.01M2.5 12.5v2M21.5 12.5v2"})]}),git:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"6",cy:"6",r:"2.5"}),(0,a.jsx)("circle",{cx:"6",cy:"18",r:"2.5"}),(0,a.jsx)("circle",{cx:"17",cy:"9",r:"2.5"}),(0,a.jsx)("path",{d:"M6 8.5v7M17 11.5c0 3-3 3.5-6 4"})]}),plus:e=>(0,a.jsx)(N,{...e,d:"M12 5v14M5 12h14"}),chevron:e=>(0,a.jsx)(N,{...e,d:"M6 9l6 6 6-6"}),chevronR:e=>(0,a.jsx)(N,{...e,d:"M9 6l6 6-6 6"}),mic:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"9",y:"3",width:"6",height:"11",rx:"3"}),(0,a.jsx)("path",{d:"M5.5 11.5a6.5 6.5 0 0 0 13 0M12 18v3"})]}),arrowUp:e=>(0,a.jsx)(N,{...e,d:"M12 19V5M6 11l6-6 6 6"}),spark:e=>(0,a.jsx)(N,{...e,d:"M12 3l1.8 5.6L19 10l-5.2 1.4L12 17l-1.8-5.6L5 10l5.2-1.4z"}),pin:e=>(0,a.jsx)(N,{...e,d:"M9 3h6l-1 5 3 3-5 1-1 8-1-8-5-1 3-3z"}),brain:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("path",{d:"M9.5 2A2.5 2.5 0 0 1 12 4.5v15a2.5 2.5 0 0 1-4.96.44 2.5 2.5 0 0 1-2.96-3.08 3 3 0 0 1-.34-5.58 2.5 2.5 0 0 1 1.32-4.24 2.5 2.5 0 0 1 1.98-3A2.5 2.5 0 0 1 9.5 2Z"}),(0,a.jsx)("path",{d:"M14.5 2A2.5 2.5 0 0 0 12 4.5v15a2.5 2.5 0 0 0 4.96.44 2.5 2.5 0 0 0 2.96-3.08 3 3 0 0 0 .34-5.58 2.5 2.5 0 0 0-1.32-4.24 2.5 2.5 0 0 0-1.98-3A2.5 2.5 0 0 0 14.5 2Z"})]}),archive:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"3.5",y:"5",width:"17",height:"4",rx:"1"}),(0,a.jsx)("path",{d:"M5 9v8a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V9M10 13h4"})]}),sidebar:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"3.5",y:"4.5",width:"17",height:"15",rx:"2.5"}),(0,a.jsx)("path",{d:"M9.5 4.5v15"})]}),minimize:e=>(0,a.jsx)(N,{...e,d:"M5 12h14"}),expand:e=>(0,a.jsx)(N,{...e,d:"M4 9V4h5M20 15v5h-5M20 9V4h-5M4 15v5h5"}),back:e=>(0,a.jsx)(N,{...e,d:"M15 6l-6 6 6 6"}),fwd:e=>(0,a.jsx)(N,{...e,d:"M9 6l6 6-6 6"}),drag:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"9",cy:"6",r:"1.1",fill:"currentColor",stroke:"none"}),(0,a.jsx)("circle",{cx:"15",cy:"6",r:"1.1",fill:"currentColor",stroke:"none"}),(0,a.jsx)("circle",{cx:"9",cy:"12",r:"1.1",fill:"currentColor",stroke:"none"}),(0,a.jsx)("circle",{cx:"15",cy:"12",r:"1.1",fill:"currentColor",stroke:"none"}),(0,a.jsx)("circle",{cx:"9",cy:"18",r:"1.1",fill:"currentColor",stroke:"none"}),(0,a.jsx)("circle",{cx:"15",cy:"18",r:"1.1",fill:"currentColor",stroke:"none"})]}),close:e=>(0,a.jsx)(N,{...e,d:"M6 6l12 12M18 6L6 18"}),dots:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"6",cy:"12",r:"1.3",fill:"currentColor",stroke:"none"}),(0,a.jsx)("circle",{cx:"12",cy:"12",r:"1.3",fill:"currentColor",stroke:"none"}),(0,a.jsx)("circle",{cx:"18",cy:"12",r:"1.3",fill:"currentColor",stroke:"none"})]}),check:e=>(0,a.jsx)(N,{...e,d:"M5 12.5l4.5 4.5L19 6.5"}),reset:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("path",{d:"M4 12a8 8 0 1 1 2.3 5.6"}),(0,a.jsx)("path",{d:"M4 20v-4h4"})]}),file:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("path",{d:"M13 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V9z"}),(0,a.jsx)("path",{d:"M13 3v6h6"})]}),diff:e=>(0,a.jsx)(N,{...e,d:"M12 4v6M9 7h6M5 17h14"}),branch:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"6",cy:"6",r:"2.3"}),(0,a.jsx)("circle",{cx:"6",cy:"18",r:"2.3"}),(0,a.jsx)("circle",{cx:"18",cy:"8",r:"2.3"}),(0,a.jsx)("path",{d:"M6 8.3v7.4M18 10.3c0 4-4 3.7-7 4.7"})]}),cube:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("path",{d:"M12 3l8 4.5v9L12 21l-8-4.5v-9z"}),(0,a.jsx)("path",{d:"M12 12l8-4.5M12 12v9M12 12L4 7.5"})]}),maximize:e=>(0,a.jsx)(N,{...e,children:(0,a.jsx)("rect",{x:"5",y:"5",width:"14",height:"14",rx:"2.5"})}),restore:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"8",y:"8",width:"11",height:"11",rx:"2"}),(0,a.jsx)("path",{d:"M5 15V7a2 2 0 0 1 2-2h8"})]}),split:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"3.5",y:"4.5",width:"17",height:"15",rx:"2.5"}),(0,a.jsx)("path",{d:"M12 4.5v15"})]}),tile:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"3.5",y:"4.5",width:"7",height:"7",rx:"1.5"}),(0,a.jsx)("rect",{x:"13.5",y:"4.5",width:"7",height:"7",rx:"1.5"}),(0,a.jsx)("rect",{x:"3.5",y:"13.5",width:"7",height:"7",rx:"1.5"}),(0,a.jsx)("rect",{x:"13.5",y:"13.5",width:"7",height:"7",rx:"1.5"})]}),cascade:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"4",y:"4",width:"12",height:"12",rx:"2"}),(0,a.jsx)("path",{d:"M20 8v10a2 2 0 0 1-2 2H8"})]}),editor:e=>(0,a.jsx)(N,{...e,children:(0,a.jsx)("path",{d:"M8 9l-3 3 3 3M16 9l3 3-3 3M13.5 6l-3 12"})}),gear:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"12",cy:"12",r:"2.6"}),(0,a.jsx)("path",{d:"M12 3.5v2M12 18.5v2M20.5 12h-2M5.5 12h-2M18 6l-1.4 1.4M7.4 16.6 6 18M18 18l-1.4-1.4M7.4 7.4 6 6"})]}),panelRight:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"3.5",y:"4.5",width:"17",height:"15",rx:"2.5"}),(0,a.jsx)("path",{d:"M14.5 4.5v15"})]}),layers:e=>(0,a.jsx)(N,{...e,d:"M12 3l8 4.5-8 4.5-8-4.5z M4 12l8 4.5 8-4.5 M4 16.5 12 21l8-4.5"}),tokens:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"9",cy:"9",r:"4.5"}),(0,a.jsx)("path",{d:"M14 9.5a4.5 4.5 0 1 1-4 6.9"})]}),bolt:e=>(0,a.jsx)(N,{...e,d:"M13 3 5 13h5l-1 8 8-10h-5z"}),add:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"3.5",y:"3.5",width:"17",height:"17",rx:"3.5"}),(0,a.jsx)("path",{d:"M12 8.5v7M8.5 12h7"})]}),bell:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("path",{d:"M6.5 9a5.5 5.5 0 0 1 11 0c0 4.5 2 5.5 2 5.5H4.5s2-1 2-5.5"}),(0,a.jsx)("path",{d:"M10 19a2 2 0 0 0 4 0"})]}),sun:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,a.jsx)("path",{d:"M12 2.5v2.5M12 19v2.5M2.5 12H5M19 12h2.5M5.1 5.1 6.9 6.9M17.1 17.1l1.8 1.8M18.9 5.1 17.1 6.9M6.9 17.1 5.1 18.9"})]}),moon:e=>(0,a.jsx)(N,{...e,d:"M20 13.5A8 8 0 1 1 10.5 4a6.5 6.5 0 0 0 9.5 9.5z"}),zoomOut:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"11",cy:"11",r:"6.5"}),(0,a.jsx)("path",{d:"M20 20l-4.2-4.2M8.3 11h5.4"})]}),zoomIn:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"11",cy:"11",r:"6.5"}),(0,a.jsx)("path",{d:"M20 20l-4.2-4.2M11 8.3v5.4M8.3 11h5.4"})]}),activity:e=>(0,a.jsx)(N,{...e,d:"M3 12h3l2.5-7 5 14 2.5-7H21"}),localKnowledge:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("path",{d:"M4 19V7a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12"}),(0,a.jsx)("path",{d:"M4 19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2"}),(0,a.jsx)("path",{d:"M9 7v14M9 11h6"})]})};function C(e){let{winCount:t,mode:n,selectedModel:l,projectName:s,branchLabel:i,shellStatusLabel:r,evidenceStatusLabel:o,statusRef:c}=e;return(0,a.jsxs)("footer",{ref:c,className:"footer mono",tabIndex:-1,"aria-label":"Workspace status","aria-live":"polite",children:[(0,a.jsxs)("span",{className:"ft-seg ft-gov","data-mode":n,children:["autonomous"===n?(0,a.jsx)("img",{className:"ft-orca",src:"/assets/keiko-logo.svg",alt:""}):(0,a.jsx)("span",{className:"ft-you",children:"M"}),"autonomous"===n?"Keiko governing":"You \xb7 manual"]}),(0,a.jsxs)("span",{className:"ft-seg ft-opt2",children:[(0,a.jsx)(S.folder,{size:13})," ",s]}),(0,a.jsxs)("span",{className:"ft-seg",children:[(0,a.jsx)(S.branch,{size:13})," ",i]}),(0,a.jsxs)("span",{className:"ft-seg ft-opt2",children:[(0,a.jsx)(S.cube,{size:13})," ",r]}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("span",{className:"ft-seg ft-accent",children:[(0,a.jsx)(S.tile,{size:13})," ",t," ",1===t?"window":"windows"]}),(0,a.jsxs)("span",{className:"ft-seg ft-opt2",children:[(0,a.jsx)(S.bolt,{size:13,style:{color:"var(--accent)"}})," ",null!=l?l:"No model selected"]}),(0,a.jsxs)("span",{className:"ft-seg ft-accent",children:[(0,a.jsx)(S.review,{size:13})," ",o]})]})}let R=[{id:"finder",name:"Finder",tile:"finder"},{id:"terminal",name:"Terminal",tile:"terminal"},{id:"vscode",name:"VS Code",img:"/assets/editors/vscode.svg"},{id:"intellij",name:"IntelliJ IDEA",img:"/assets/editors/intellij.svg"},{id:"goland",name:"GoLand",img:"/assets/editors/goland.svg"},{id:"rustrover",name:"RustRover",img:"/assets/editors/rustrover.svg"},{id:"pycharm",name:"PyCharm",img:"/assets/editors/pycharm.svg"},{id:"webstorm",name:"WebStorm",img:"/assets/editors/webstorm.svg"}],I="keiko.editor",E="intellij";function M(){try{var e;return null!=(e=window.localStorage.getItem(I))?e:E}catch(e){return E}}function T(e){let{ed:t,size:n=20}=e;if(void 0!==t.img)return(0,a.jsx)("img",{className:"ed-img",src:t.img,width:n,height:n,alt:""});let l=Math.round(.27*n);return"terminal"===t.tile?(0,a.jsx)("span",{className:"ed-tile",style:{width:n,height:n,borderRadius:l,background:"#2a2c33"},children:(0,a.jsx)("span",{className:"ed-mark mono",style:{color:"#4ee08d",fontSize:.42*n},children:">_"})}):(0,a.jsx)("span",{className:"ed-tile",style:{width:n,height:n,borderRadius:l,background:"linear-gradient(180deg,#36c4ff,#1e7cf0)"},children:(0,a.jsx)(S.folder,{size:.56*n,style:{color:"#fff"}})})}function q(e){var t;let{project:n}=e,[s,i]=(0,l.useState)(!1),[r,o]=(0,l.useState)(M),c=null!=(t=R.find(e=>e.id===r))?t:R[3],d="Open in ".concat(c.name),u="Open ".concat(n," in ").concat(c.name);return(0,l.useEffect)(()=>{try{window.localStorage.setItem(I,r)}catch(e){}},[r]),(0,a.jsxs)("div",{className:"edm",children:[(0,a.jsxs)("button",{type:"button",className:"edm-trigger",onClick:()=>i(e=>!e),title:u,"aria-label":u,"aria-haspopup":"menu","aria-expanded":s,children:[(0,a.jsx)(T,{ed:c,size:20}),(0,a.jsx)("span",{className:"edm-trigger-label",children:d}),(0,a.jsx)(S.chevron,{size:13,style:{color:"var(--fg-faint)"}})]}),s?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"edm-backdrop",onClick:()=>i(!1),"aria-hidden":"true",role:"presentation"}),(0,a.jsxs)("div",{className:"edm-menu",role:"menu",children:[(0,a.jsxs)("div",{className:"edm-head mono",children:["Open “",n,"” in…"]}),R.map(e=>(0,a.jsxs)("button",{type:"button",className:"edm-item","data-sel":e.id===r,onClick:()=>{o(e.id),i(!1)},role:"menuitemradio","aria-checked":e.id===r,children:[(0,a.jsx)(T,{ed:e,size:24}),(0,a.jsx)("span",{className:"edm-name",children:e.name}),e.id===r?(0,a.jsx)(S.check,{size:14,style:{color:"var(--accent)"}}):null]},e.id))]})]}):null]})}function P(e){let{mode:t,onChange:n}=e;return(0,a.jsxs)("div",{className:"modesw","data-mode":t,role:"group","aria-label":"Agent mode",children:[(0,a.jsxs)("button",{type:"button",className:"modesw-opt","data-on":"manual"===t,"aria-pressed":"manual"===t,onClick:()=>n("manual"),title:"You approve every privileged action",children:[(0,a.jsx)("span",{className:"modesw-av","aria-hidden":"true",children:"M"})," ","You"]}),(0,a.jsxs)("button",{type:"button",className:"modesw-opt","data-on":"autonomous"===t,"aria-pressed":"autonomous"===t,onClick:()=>n("autonomous"),title:"Keiko governs agents per your policy",children:[(0,a.jsx)("img",{className:"modesw-orca",src:"/assets/keiko-logo.svg",alt:""})," Keiko"]})]})}function A(e){let{mode:t,projectName:n,onModeChange:l,openPalette:s,onTileAll:i,onSplitFront:r,onCascade:o}=e;return(0,a.jsxs)("header",{className:"header",children:[(0,a.jsxs)("div",{className:"hd-brand",children:[(0,a.jsx)("img",{className:"hd-logo",src:"/assets/keiko-logo.svg",alt:"Keiko"}),(0,a.jsx)("span",{className:"hd-wordmark",children:"Keiko"})]}),(0,a.jsxs)("div",{className:"tb-tabs",children:[(0,a.jsxs)("div",{className:"tb-tab","data-active":"true",children:[(0,a.jsx)("span",{children:n}),(0,a.jsx)(S.chevron,{size:13,style:{color:"var(--fg-faint)"}})]}),(0,a.jsx)("button",{type:"button",className:"tb-newtab","aria-label":"New tab",children:(0,a.jsx)(S.plus,{size:15})})]}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("div",{className:"hd-tools",children:[(0,a.jsxs)("button",{type:"button",className:"hd-tool hd-tool-cta",onClick:s,title:"New window",children:[(0,a.jsx)(S.add,{size:16}),(0,a.jsx)("span",{children:"New"})]}),(0,a.jsx)("span",{className:"hd-div"}),(0,a.jsx)(q,{project:n}),(0,a.jsx)("span",{className:"hd-div"}),(0,a.jsx)("button",{type:"button",className:"hd-tool",onClick:i,title:"Tile all windows","aria-label":"Tile all windows",children:(0,a.jsx)(S.tile,{size:16})}),(0,a.jsx)("button",{type:"button",className:"hd-tool",onClick:r,title:"Split the two front windows","aria-label":"Split the two front windows",children:(0,a.jsx)(S.split,{size:16})}),(0,a.jsx)("button",{type:"button",className:"hd-tool",onClick:o,title:"Cascade windows","aria-label":"Cascade windows",children:(0,a.jsx)(S.cascade,{size:16})})]}),(0,a.jsx)("span",{className:"hd-div"}),(0,a.jsx)(P,{mode:t,onChange:l}),(0,a.jsxs)("div",{className:"tb-status mono",children:[(0,a.jsx)("span",{className:"dot",style:{background:"var(--ok)"}})," connected"]}),(0,a.jsx)("button",{type:"button",className:"tb-btn","aria-label":"Expand window",children:(0,a.jsx)(S.expand,{size:15})}),(0,a.jsx)("button",{type:"button",className:"tb-btn","aria-label":"Minimize window",children:(0,a.jsx)(S.minimize,{size:16})})]})}var z=n(9664),D=n.n(z);let L=[{id:"keiko",icon:"spark",label:"Keiko",img:"/assets/keiko-logo.svg"},{id:"project",icon:"folder",label:"Project"},{id:"search",icon:"search",label:"Search"},{id:"plugins",icon:"plugins",label:"Plugins"}],F=[{id:"automations",icon:"automations",label:"Automations"},{id:"mobile",icon:"mobile",label:"Keiko mobile"}];function O(e){let{tool:t,active:n,onClick:l}=e,s=S[t.icon];return(0,a.jsx)("button",{type:"button",className:"rail-btn","data-active":n?"true":"false","data-side":"left","aria-label":t.label,"aria-pressed":n,title:t.label,onClick:l,children:void 0!==t.img?(0,a.jsx)("img",{className:"rail-img",src:t.img,alt:""}):(0,a.jsx)(s,{size:19})})}function K(e){let{openTools:t,onTool:n,onNewChat:l,theme:s,onToggleTheme:i}=e;return(0,a.jsxs)("nav",{className:"rail rail-left","aria-label":"Primary workspace navigation",children:[(0,a.jsx)("button",{type:"button",className:"rail-new",onClick:l,"data-side":"left","aria-label":"New chat",title:"New chat",children:(0,a.jsx)(S.newChat,{size:18})}),(0,a.jsx)("div",{className:"rail-div"}),(0,a.jsx)("div",{className:"rail-group",children:L.map(e=>(0,a.jsx)(O,{tool:e,active:t.has(e.id),onClick:()=>n(e.id)},e.id))}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("div",{className:"rail-group",children:[F.map(e=>(0,a.jsx)(O,{tool:e,active:t.has(e.id),onClick:()=>n(e.id)},e.id)),(0,a.jsx)(D(),{href:"/memoriaviva",className:"rail-btn","data-active":"false","data-side":"left","aria-label":"MemoriaViva",title:"MemoriaViva",children:(0,a.jsx)(S.brain,{size:19})}),(0,a.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("quality")?"true":"false","aria-label":"Quality Intelligence","aria-pressed":t.has("quality"),title:"Quality Intelligence",onClick:()=>n("quality"),children:(0,a.jsx)(S.check,{size:19})}),(0,a.jsx)(D(),{href:"/local-knowledge",className:"rail-btn","data-active":"false","data-side":"left","aria-label":"Local Knowledge",title:"Local Knowledge",children:(0,a.jsx)(S.localKnowledge,{size:19})}),(0,a.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("relationships")?"true":"false","aria-label":"Relationships","aria-pressed":t.has("relationships"),title:"Relationships",onClick:()=>n("relationships"),children:(0,a.jsx)(S.branch,{size:19})})]}),(0,a.jsx)("div",{className:"rail-div"}),(0,a.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","aria-label":"light"===s?"Dark mode":"Light mode",title:"light"===s?"Dark mode":"Light mode",onClick:i,children:"light"===s?(0,a.jsx)(S.moon,{size:19}):(0,a.jsx)(S.sun,{size:19})}),(0,a.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("settings")?"true":"false","aria-label":"Settings","aria-pressed":t.has("settings"),title:"Settings",onClick:()=>n("settings"),children:(0,a.jsx)(S.settings,{size:19})}),(0,a.jsx)("button",{type:"button",className:"rail-avatar","data-side":"left","aria-label":"Account",title:"Account",children:"M"})]})}let B=[{id:"inspector",label:"Inspector",icon:"layers"},{id:"activity",label:"Activity",icon:"activity"},{id:"notifications",label:"Notifications",icon:"bell"},{id:"resources",label:"Resources",icon:"cube"}];function W(e){let{openTools:t,onTool:n}=e;return(0,a.jsx)("aside",{className:"rail rail-right","aria-label":"Workspace utilities",children:(0,a.jsx)("div",{className:"rail-group",children:B.map(e=>{let l=S[e.icon];return(0,a.jsx)("button",{type:"button",className:"rail-btn","data-active":t.has(e.id),"data-side":"right","data-tip":e.label,"aria-label":e.label,"aria-pressed":t.has(e.id),onClick:()=>n(e.id),children:(0,a.jsx)(l,{size:19})},e.id)})})})}function U(e,t,n){let a=e.createShader(t);return null===a?null:(e.shaderSource(a,n),e.compileShader(a),e.getShaderParameter(a,e.COMPILE_STATUS))?a:(console.warn("[keiko-shader]",e.getShaderInfoLog(a)),e.deleteShader(a),null)}function _(){let e=window.localStorage.getItem("keiko.wallpaper.opacity");if(null===e)return 1;let t=Number.parseInt(e,10);return Number.isFinite(t)?Math.max(0,Math.min(100,t))/100:1}function H(){let e=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let t=e.current;if(null===t)return;let n=t.parentElement;if(null!==n&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches)return function(e,t){var n;t.style.opacity=String(_());let a=e=>{let n=e.detail,a="number"==typeof n?n:100*_();t.style.opacity=String(Math.max(0,Math.min(100,a))/100)};window.addEventListener("keiko:wallpaper-opacity",a);let l=null;try{l=t.getContext("webgl",{antialias:!1,alpha:!1,premultipliedAlpha:!1,depth:!1})}catch(e){l=null}if(null===l)return()=>{window.removeEventListener("keiko:wallpaper-opacity",a)};let s=U(l,l.VERTEX_SHADER,"\nattribute vec2 aPos;\nvoid main(){ gl_Position = vec4(aPos, 0.0, 1.0); }\n"),i=U(l,l.FRAGMENT_SHADER,"\nprecision highp float;\nuniform vec2 uRes;\nuniform float uTime;\nuniform vec2 uMouse; // 0..1, y up\nuniform float uDark; // 1 = dark theme, 0 = light\nuniform vec2 uRip[4]; // ripple origins (0..1, y up)\nuniform float uRipT[4]; // seconds since each ripple fired (large = inactive)\n\nfloat hash(vec2 p){\n p = fract(p * vec2(123.34, 456.21));\n p += dot(p, p + 45.32);\n return fract(p.x * p.y);\n}\nfloat vnoise(vec2 p){\n vec2 i = floor(p), f = fract(p);\n vec2 u = f * f * (3.0 - 2.0 * f);\n float a = hash(i), b = hash(i + vec2(1.,0.));\n float c = hash(i + vec2(0.,1.)), d = hash(i + vec2(1.,1.));\n return mix(mix(a,b,u.x), mix(c,d,u.x), u.y);\n}\nfloat fbm(vec2 p){\n float v = 0.0, a = 0.5;\n mat2 m = mat2(1.6, 1.2, -1.2, 1.6);\n for(int i = 0; i < 5; i++){ v += a * vnoise(p); p = m * p; a *= 0.5; }\n return v;\n}\n\nvoid main(){\n vec2 uv = gl_FragCoord.xy / uRes.xy;\n float aspect = uRes.x / uRes.y;\n vec2 p = vec2(uv.x * aspect, uv.y);\n vec2 m = vec2(uMouse.x * aspect, uMouse.y);\n\n float t = uTime * 0.06;\n\n // --- click ripples ---------------------------------------------------\n float rip = 0.0;\n for(int i = 0; i < 4; i++){\n float age = uRipT[i];\n if(age < 2.4){\n vec2 rc = vec2(uRip[i].x * aspect, uRip[i].y);\n float d = distance(p, rc);\n float ring = sin(d * 15.0 - age * 9.0);\n float env = exp(-d * 3.6) * exp(-age * 2.1);\n rip += ring * env;\n }\n }\n\n // --- liquid domain warp ---------------------------------------------\n vec2 warp = vec2(\n fbm(p * 2.1 + vec2(0.0, t)),\n fbm(p * 2.1 + vec2(t, 4.7))\n );\n // mouse bends the flow toward the cursor\n vec2 toM = m - p;\n float md = exp(-length(toM) * 2.2);\n warp += toM * md * 0.28;\n warp += rip * 0.07;\n\n float f = fbm(p * 2.4 + warp * 1.7 + vec2(t * 0.6, 0.0));\n\n // --- chrome banding (sharp metallic streaks) ------------------------\n float bands = abs(sin((f * 4.0 + warp.x * 2.0) * 3.14159 + t * 1.4));\n float chrome = pow(bands, 2.6);\n\n // --- palette (brand) -------------------------------------------------\n vec3 baseD = vec3(0.072, 0.085, 0.079); // warm near-black ~ --bg\n vec3 metalD = vec3(0.205, 0.230, 0.216); // chrome mid grey\n vec3 baseL = vec3(0.930, 0.942, 0.935); // near-white\n vec3 metalL = vec3(0.795, 0.835, 0.812); // soft grey\n vec3 green = vec3(0.306, 0.729, 0.529); // #4EBA87\n\n vec3 base = mix(baseL, baseD, uDark);\n vec3 metal = mix(metalL, metalD, uDark);\n\n vec3 col = mix(base, metal, chrome * 0.85);\n\n // orca-green sheen on the brightest specular ridges\n float spec = smoothstep(0.80, 1.0, bands);\n col += green * spec * mix(0.085, 0.16, uDark);\n\n // soft green glow trailing the cursor — fun to fidget with\n col += green * md * 0.085;\n\n // ripple highlight\n vec3 ripCol = mix(green, vec3(1.0), uDark);\n col += ripCol * max(rip, 0.0) * 0.032;\n\n // keep it dezent — pull back toward base\n col = mix(base, col, 0.84);\n\n gl_FragColor = vec4(col, 1.0);\n}\n");if(null===s||null===i)return()=>{window.removeEventListener("keiko:wallpaper-opacity",a)};let r=l.createProgram();if(null===r)return()=>{window.removeEventListener("keiko:wallpaper-opacity",a)};if(l.attachShader(r,s),l.attachShader(r,i),l.linkProgram(r),!l.getProgramParameter(r,l.LINK_STATUS))return console.warn("[keiko-shader]",l.getProgramInfoLog(r)),()=>{window.removeEventListener("keiko:wallpaper-opacity",a)};l.useProgram(r);let o=l.createBuffer();l.bindBuffer(l.ARRAY_BUFFER,o),l.bufferData(l.ARRAY_BUFFER,new Float32Array([-1,-1,3,-1,-1,3]),l.STATIC_DRAW);let c=l.getAttribLocation(r,"aPos");l.enableVertexAttribArray(c),l.vertexAttribPointer(c,2,l.FLOAT,!1,0,0);let d=l.getUniformLocation(r,"uRes"),u=l.getUniformLocation(r,"uTime"),h=l.getUniformLocation(r,"uMouse"),p=l.getUniformLocation(r,"uDark"),m=l.getUniformLocation(r,"uRip"),f=l.getUniformLocation(r,"uRipT"),g=1,v=1,x=Math.min(null!=(n=window.devicePixelRatio)?n:1,1.5),y={tx:.5,ty:.5,x:.5,y:.5},b=new Float32Array(8),j=[,,,,].fill(-1/0),w=0;function k(){let n=e.getBoundingClientRect();g=Math.max(1,Math.round(n.width)),v=Math.max(1,Math.round(n.height)),t.width=Math.round(g*x),t.height=Math.round(v*x),t.style.width="".concat(String(g),"px"),t.style.height="".concat(String(v),"px"),null!==l&&l.viewport(0,0,t.width,t.height)}k();let N="undefined"!=typeof ResizeObserver?new ResizeObserver(k):null;null!==N?N.observe(e):window.addEventListener("resize",k);let S=t=>{let n=e.getBoundingClientRect();y.tx=(t.clientX-n.left)/Math.max(1,n.width),y.ty=1-(t.clientY-n.top)/Math.max(1,n.height)},C=t=>{let n=e.getBoundingClientRect(),a=(t.clientX-n.left)/Math.max(1,n.width),l=1-(t.clientY-n.top)/Math.max(1,n.height);a<0||a>1||l<0||l>1||(b[2*w]=a,b[2*w+1]=l,j[w]=performance.now(),w=(w+1)%4)};e.addEventListener("pointermove",S),e.addEventListener("pointerdown",C);let R=performance.now(),I=0,E=!0,M=new Float32Array(4);function T(){if(!E)return;let e=performance.now();y.x+=(y.tx-y.x)*.06,y.y+=(y.ty-y.y)*.06;for(let t=0;t<4;t++){var n;M[t]=(e-(null!=(n=j[t])?n:-1/0))/1e3}let a=+("light"!==document.documentElement.dataset.theme);null!==l&&(l.uniform2f(d,t.width,t.height),l.uniform1f(u,(e-R)/1e3),l.uniform2f(h,y.x,y.y),l.uniform1f(p,a),l.uniform2fv(m,b),l.uniform1fv(f,M),l.drawArrays(l.TRIANGLES,0,3)),I=requestAnimationFrame(T)}I=requestAnimationFrame(T);let q=()=>{document.hidden?(E=!1,cancelAnimationFrame(I)):E||(E=!0,I=requestAnimationFrame(T))};return document.addEventListener("visibilitychange",q),()=>{if(E=!1,cancelAnimationFrame(I),document.removeEventListener("visibilitychange",q),window.removeEventListener("keiko:wallpaper-opacity",a),e.removeEventListener("pointermove",S),e.removeEventListener("pointerdown",C),null!==N?N.disconnect():window.removeEventListener("resize",k),null!==l){let e=l.getExtension("WEBGL_lose_context");null!==e&&e.loseContext()}}}(n,t)},[]),(0,a.jsx)("canvas",{ref:e,className:"ws-shader","aria-hidden":"true"})}let J={agents:["files","terminal","plugins","review","browser","agents","keiko"],chat:["files","browser","plugins","keiko","connector"],files:["agents","chat","quality"],terminal:["agents"],plugins:["agents","chat"],review:["agents"],browser:["agents","chat"],keiko:["agents","chat"],connector:["chat","quality"],quality:["files","connector","figma"],figma:["quality"]};function V(e,t){var n,a;return void 0!==e&&void 0!==t&&e!==t&&((null!=(n=J[e])?n:[]).includes(t)||(null!=(a=J[t])?a:[]).includes(e))}function G(e){return{left:{x:e.x,y:e.y,w:e.w/2,h:e.h},right:{x:e.x+e.w/2,y:e.y,w:e.w/2,h:e.h},maxi:{x:e.x,y:e.y,w:e.w,h:e.h},tl:{x:e.x,y:e.y,w:e.w/2,h:e.h/2},tr:{x:e.x+e.w/2,y:e.y,w:e.w/2,h:e.h/2},bl:{x:e.x,y:e.y+e.h/2,w:e.w/2,h:e.h/2},br:{x:e.x+e.w/2,y:e.y+e.h/2,w:e.w/2,h:e.h/2}}}let X=new Set(["files","connector","browser","plugins","agents","quality"]);function Y(e,t){return e>=4||t>=8192}function Z(e){let{pathId:t,intensity:n}=e,l="heavy"===n?3:1,s="heavy"===n?1.1:2.2;return(0,a.jsx)(a.Fragment,{children:Array.from({length:l},(e,i)=>(0,a.jsx)("circle",{className:"conn-particle",r:"heavy"===n?3:2.4,"aria-hidden":"true",children:(0,a.jsx)("animateMotion",{dur:"".concat(String(s),"s"),repeatCount:"indefinite",begin:"".concat(String(s/l*i),"s"),rotate:"auto",keyPoints:"0;1",keyTimes:"0;1",calcMode:"linear",children:(0,a.jsx)("mpath",{href:"#".concat(t)})})},i))})}function Q(e){let{wins:t,conns:n,connecting:s,api:i}=e,r=o(),c=function(){let[e,t]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{let e=window.matchMedia("(prefers-reduced-motion: reduce)"),n=e=>t(e);n(e.matches);let a=e=>n(e.matches);return e.addEventListener("change",a),()=>e.removeEventListener("change",a)},[]),e}(),{flowing:d,intensity:u}=function(e,t){let[n,a]=(0,l.useState)("light"),[s,i]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{if(void 0===t)return;a(function(e){switch(e.groundingKind){case"connected-context":return Y(e.contextPack.usage.filesRead,e.contextPack.usage.excerptBytes)?"heavy":"light";case"hybrid":return Y(e.contextPack.folder.usage.filesRead,e.contextPack.folder.usage.excerptBytes)||e.contextPack.knowledge.referencesUsed>=4?"heavy":"light";case"local-knowledge":return e.contextPack.referencesUsed>=4?"heavy":"light";default:return"light"}}(t)),i(!0);let e=setTimeout(()=>i(!1),2500);return()=>clearTimeout(e)},[t]),{flowing:e||s,intensity:n}}((null==r?void 0:r.sending)===!0,null==r?void 0:r.latestGrounded),h=function(e,t){let n=new Map(e.map(e=>[e.id,e])),a=[];for(let e of t){let t=n.get(e.a),l=n.get(e.b);if(void 0===t||void 0===l)continue;let s=function(e,t){let n,a,l,s,i={x:e.x+e.w/2,y:e.y+e.h/2},r={x:t.x+t.w/2,y:t.y+t.h/2},o=r.x-i.x,c=r.y-i.y;if(Math.abs(o)>=Math.abs(c)){n=o>=0?{x:e.x+e.w,y:i.y}:{x:e.x,y:i.y};let c=Math.max(40,Math.abs((a=o>=0?{x:t.x,y:r.y}:{x:t.x+t.w,y:r.y}).x-n.x)/2),d=o>=0?1:-1;l={x:n.x+d*c,y:n.y},s={x:a.x-d*c,y:a.y}}else{n=c>=0?{x:i.x,y:e.y+e.h}:{x:i.x,y:e.y};let o=Math.max(40,Math.abs((a=c>=0?{x:r.x,y:t.y}:{x:r.x,y:t.y+t.h}).y-n.y)/2),d=c>=0?1:-1;l={x:n.x,y:n.y+d*o},s={x:a.x,y:a.y-d*o}}let d={x:(n.x+3*l.x+3*s.x+a.x)/8,y:(n.y+3*l.y+3*s.y+a.y)/8};return{d:"M".concat(String(n.x),",").concat(String(n.y)," C").concat(String(l.x),",").concat(String(l.y)," ").concat(String(s.x),",").concat(String(s.y)," ").concat(String(a.x),",").concat(String(a.y)),mid:d}}(t,l);a.push({c:e,d:s.d,mid:s.mid,label:function(e,t){let n="files"===e.type?e:"files"===t.type?t:null,a=null===n?null:n===e?t:e;if(null!==n&&null!==a&&("chat"===a.type||"agents"===a.type||"quality"===a.type))return"uses ".concat(function(e){if(void 0===e)return"src";let t=e.root;return"string"==typeof t&&t.length>0?t:"src"}(n.cfg),"/");let l=[e.type,t.type];return l.includes("connector")?"uses knowledge":l.includes("figma")?"uses snapshot":l.includes("keiko")?"governed by":"agents"===l[0]&&"agents"===l[1]?"delegates":l.includes("terminal")?"runs in":l.includes("plugins")?"tools":l.includes("review")?"reviews":l.includes("browser")?"browses":"linked"}(t,l),dataChannel:function(e,t){let n=[e.type,t.type].includes("chat"),a="chat"===e.type?X.has(t.type):X.has(e.type);return n&&a}(t,l)})}return a}(t,n),p=null!==s?function(e,t){let n=t.find(t=>t.id===e.from);if(void 0===n)return null;let a={x:n.x+n.w/2,y:n.y+n.h/2},l=e.x-a.x,s=e.y-a.y,i=Math.abs(l)>=Math.abs(s),r=i?{x:l>=0?n.x+n.w:n.x,y:a.y}:{x:a.x,y:s>=0?n.y+n.h:n.y},o=Math.max(40,Math.abs(i?l:s)/2),c=i?{x:r.x+(l>=0?o:-o),y:r.y}:{x:r.x,y:r.y+(s>=0?o:-o)},d=e.x,u=e.y;return{d:"M".concat(String(r.x),",").concat(String(r.y)," C").concat(String(c.x),",").concat(String(c.y)," ").concat(String(d),",").concat(String(u)," ").concat(String(d),",").concat(String(u)),ex:d,ey:u}}(s,t):null;return(0,a.jsxs)("div",{className:"conn-layer",children:[(0,a.jsxs)("svg",{className:"conn-svg",viewBox:"-10000 -10000 20000 20000",preserveAspectRatio:"xMidYMid meet",children:[h.map(e=>{let t=d&&e.dataChannel,n="conn-path-".concat(e.c.id);return(0,a.jsxs)("g",{children:[(0,a.jsx)("path",{id:n,className:"conn-path",d:e.d,"data-active":t?"true":void 0,"data-intensity":t?u:void 0,"data-reduced-motion":t&&c?"true":void 0}),t&&!c?(0,a.jsx)(Z,{pathId:n,intensity:u}):null]},e.c.id)}),null!==p?(0,a.jsx)("path",{className:"conn-path conn-temp",d:p.d}):null,null!==p?(0,a.jsx)("circle",{className:"conn-dot",cx:p.ex,cy:p.ey,r:"5"}):null]}),h.map(e=>{let t=d&&e.dataChannel;return(0,a.jsxs)("button",{type:"button",className:"conn-badge","data-active":t?"true":void 0,"data-intensity":t?u:void 0,style:{left:e.mid.x,top:e.mid.y},onClick:()=>i.removeConn(e.c.id),title:"Remove connection","aria-label":t?"".concat(e.label," — ").concat(u," data exchange in progress. Activate to remove connection."):"Remove connection: ".concat(e.label),children:[(0,a.jsx)(S.git,{size:11})," ",(0,a.jsx)("span",{children:e.label}),t?(0,a.jsx)("span",{className:"conn-flow-tag","aria-hidden":"true",children:"heavy"===u?"⇶":"→"}):null]},e.c.id)})]})}var $=n(2982);let ee={w:150,h:110},et={w:290,h:190},en={chat:{title:"Chat",icon:"newChat",accent:!0,desc:"Talk to Keiko",w:480,h:480,min:{w:300,h:260},config:[{key:"title",label:"Title",type:"text",def:"New chat",optional:!0,placeholder:"Name this conversation"}]},files:{title:"Files",icon:"files",accent:!0,desc:"Browse a folder",w:290,h:340,tiny:{w:200,h:150},config:[{key:"root",label:"Folder",type:"directory",def:""}]},editor:{title:"Editor",icon:"editor",desc:"Edit a file",w:480,h:360,config:[{key:"file",label:"File path",type:"text",def:"windows.jsx",placeholder:"path/to/file.jsx"}]},browser:{title:"Browser",icon:"browser",desc:"Open a URL",w:460,h:340,config:[{key:"url",label:"URL",type:"text",def:"localhost:5173",placeholder:"https://…"}]},terminal:{title:"Terminal",icon:"terminal",accent:!0,desc:"Run commands",w:460,h:250,tiny:{w:250,h:140},config:[{key:"projectPath",label:"Project path",type:"text",def:""},{key:"cwd",label:"Working directory",type:"directory",def:""}]},review:{title:"Review",icon:"review",desc:"Review a proposed diff",w:520,h:420,config:[{key:"runId",label:"Run ID",type:"text",def:"",optional:!0,placeholder:"e.g. r-2026-06-01-…"}]},agents:{title:"Agents",icon:"agents",desc:"Run a BFF workflow",w:520,h:560,tiny:{w:250,h:140},cta:"Start agent",config:[]},integ:{title:"Integrations",icon:"plugins",desc:"Connect apps",w:320,h:300,config:[{key:"provider",label:"Provider",type:"select",options:["GitHub","Linear","Slack","Sentry"],def:"GitHub"}]},keiko:{title:"Keiko",icon:"spark",desc:"Keiko twin",w:344,h:520,tool:!0,singleton:!0},settings:{title:"Settings",icon:"settings",desc:"Preferences",w:470,h:560,tool:!0,singleton:!0},project:{title:"Project",icon:"folder",desc:"Project tree",w:304,h:440,tool:!0,singleton:!0},search:{title:"Search",icon:"search",desc:"Search the workspace",w:320,h:500,tool:!0,singleton:!0},plugins:{title:"Plugins",icon:"plugins",desc:"Plugins & tools",w:320,h:470,tool:!0,singleton:!0},automations:{title:"Automations",icon:"automations",desc:"Workflow automations",w:320,h:300,tool:!0,singleton:!0},mobile:{title:"Keiko mobile",icon:"mobile",desc:"Mobile companion",w:300,h:380,tool:!0,singleton:!0},inspector:{title:"Inspector",icon:"layers",desc:"Inspect the workspace",w:290,h:440,tool:!0,singleton:!0},activity:{title:"Activity",icon:"activity",desc:"Activity timeline",w:322,h:460,tool:!0,singleton:!0},notifications:{title:"Notifications",icon:"bell",desc:"Notifications",w:300,h:360,tool:!0,singleton:!0},resources:{title:"Resources",icon:"cube",desc:"System resources",w:300,h:320,tool:!0,singleton:!0},connector:{title:"Connector",icon:"plugins",accent:!0,desc:"Pick a Local Knowledge connector",w:320,h:380,min:{w:280,h:300},config:[],cta:"Select connector"},quality:{title:"Quality Intelligence",icon:"check",accent:!0,desc:"Design & review test cases",w:384,h:580,min:{w:300,h:320},tiny:{w:260,h:200},tool:!0,singleton:!0},qiRun:{title:"QI Run",icon:"check",desc:"Generated test cases",w:760,h:660,min:{w:320,h:280},tiny:{w:280,h:200},config:[{key:"runId",label:"Run ID",type:"text",def:""}]},relationships:{title:"Relationships",icon:"branch",accent:!0,desc:"Inspect the relationship graph",w:760,h:600,min:{w:360,h:320},tiny:{w:300,h:220},tool:!0,singleton:!0},figma:{title:"Figma Snapshot",icon:"layers",accent:!0,desc:"Capture a Figma board snapshot",w:420,h:540,min:{w:320,h:360},tiny:{w:280,h:240}}},ea=new Map;function el(e,t){ea.set(e,t)}let es=function(){let e={};return Object.keys(en).forEach(t=>{e[t]=function(e,t){var n,a;let l={title:t.title,icon:t.icon,desc:t.desc,w:t.w,h:t.h,min:null!=(n=t.min)?n:ee,tiny:null!=(a=t.tiny)?a:et,render:(t,n)=>{let a=ea.get(e);return void 0!==a?a(t,n):null}},s={};return!0===t.accent&&(s.accent=!0),!0===t.tool&&(s.tool=!0),!0===t.singleton&&(s.singleton=!0),void 0!==t.config&&(s.config=t.config),void 0!==t.cta&&(s.cta=t.cta),{...l,...s}}(t,en[t])}),e}();function ei(e,t,n,a,l){return{x:e.x+Math.max(16,Math.min(l+26*a,e.w-t-16)),y:e.y+Math.max(16,Math.min(l+26*a,e.h-n-16))}}function er(e){let{prev:t,...n}=e;return n}function eo(e,t,n){return e.some(e=>e.a===t&&e.b===n||e.a===n&&e.b===t)}function ec(e){return e.length>0&&(e.startsWith("/")||/^[A-Za-z]:[/\\]/u.test(e))}function ed(e){if("files"!==e.type)return null;let t=e.cfg.resolvedRoot,n=e.cfg.root,a="string"==typeof t&&t.length>0?t:"string"==typeof n&&n.length>0?n:null;return null!==a&&ec(a)?a:null}function eu(e,t){let n="files"===e.type?e:"files"===t.type?t:null,a="chat"===e.type?e:"chat"===t.type?t:null;return null===n||null===a?null:ed(n)}function eh(e){var t;return null!=(t=e.connectedScopes)?t:void 0!==e.connectedScope?[e.connectedScope]:[]}function ep(e){var t;return null!=(t=e.localKnowledgeScopes)?t:void 0!==e.localKnowledgeScope?[e.localKnowledgeScope]:[]}function em(e){return"capsule"===e.kind?"capsule:".concat(e.capsuleId):"set:".concat(e.capsuleSetId)}function ef(e,t){let n="connector"===e.type?e:"connector"===t.type?t:null,a="chat"===e.type?e:"chat"===t.type?t:null;if(null===n||null===a)return null;let l=n.cfg.selectedKind,s=n.cfg.selectedId;return"string"!=typeof l||"string"!=typeof s||0===s.length?null:"capsule"===l?{kind:"capsule",capsuleId:s,connectedAtMs:Date.now()}:"capsule-set"===l?{kind:"capsule-set",capsuleSetId:s,connectedAtMs:Date.now()}:null}let eg={low:"Low",moderate:"Moderate",high:"High",exceeded:"Exceeded"},ev={low:"cmp-budget-badge cmp-budget-badge-low",moderate:"cmp-budget-badge cmp-budget-badge-moderate",high:"cmp-budget-badge cmp-budget-badge-high",exceeded:"cmp-budget-badge cmp-budget-badge-exceeded"};function ex(e,t){if(Number.isFinite(t)&&!(t<=0))return e/t}function ey(e){let t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return -1===n?t:t.slice(n+1)}function eb(e){let{chat:t,scope:n,index:s,allScopes:i,onDisconnect:r,updateScopes:o}=e,[c,d]=(0,l.useState)(!1),[u,h]=(0,l.useState)(null),p=function(e){var t,n;if("string"==typeof e.root&&e.root.length>0){let t=ey(e.root);return 0===t.length?"Connected folder":"Folder: ".concat(t)}if("workspace-root"===e.kind)return"Repository scope";if("directory"===e.kind){let n=ey(null!=(t=e.relativePaths[0])?t:"");return 0===n.length?"Connected folder":"Folder: ".concat(n)}if(1===e.relativePaths.length){let t=ey(null!=(n=e.relativePaths[0])?n:"");return 0===t.length?"Connected file":"File: ".concat(t)}return"".concat(String(e.relativePaths.length)," files connected")}(n);async function m(){if(!c){h(null),d(!0);try{let e=i.filter((e,t)=>t!==s),n=await o(t.id,e.length>0?e:null);null==r||r(n.chat)}catch(e){h(e instanceof $.hD?"".concat(e.code,": ").concat(e.message):e instanceof Error?e.message:"Unable to disconnect scope.")}finally{d(!1)}}}return(0,a.jsxs)("span",{className:"scope-pill-wrap",children:[(0,a.jsxs)("span",{className:"scope-pill",children:[(0,a.jsx)("span",{"aria-hidden":"true",children:"●"}),(0,a.jsx)("span",{role:"status","aria-live":"polite",children:p}),(0,a.jsx)("button",{type:"button",className:"scope-pill-disconnect",disabled:c,"aria-label":"Disconnect ".concat(p," from chat"),title:"Disconnect ".concat(p," from chat"),onClick:()=>{m()},children:(0,a.jsx)("span",{"aria-hidden":"true",children:"\xd7"})})]}),(0,a.jsx)("span",{className:"scope-pill-detail",children:function(e){let t="workspace-root"===e.kind?"the connected repository":"directory"===e.kind?"the connected folder":"the connected file scope";return"Keiko may inspect only ".concat(t,"; safe-read exclusions and context budget limits apply before each answer.")}(n)}),null!==u?(0,a.jsx)("span",{role:"alert",className:"scope-connect-error",children:u}):null]})}function ej(e){let{chat:t,onDisconnect:n,lastGroundedBudgetStatus:l,updateScopes:s=$.Mr}=e,i=eh(t);return 0===i.length?null:(0,a.jsxs)("span",{className:"scope-pill-group",children:[i.map((e,l)=>{var r;return(0,a.jsx)(eb,{chat:t,scope:e,index:l,allScopes:i,onDisconnect:n,updateScopes:s},"".concat(null!=(r=e.root)?r:e.kind,"-").concat(String(e.connectedAtMs),"-").concat(String(l)))}),void 0!==l?(0,a.jsx)("span",{className:"scope-pill-wrap",children:(0,a.jsxs)("span",{className:"scope-pill-detail",style:{display:"flex",gap:8,alignItems:"center",flexWrap:"wrap"},children:[(0,a.jsx)("span",{className:ev[l.pressure],children:l.label}),(0,a.jsx)("span",{children:l.summary})]})}):null]})}function ew(e){return"capsule"===e.kind?"capsule:".concat(e.capsuleId):"set:".concat(e.capsuleSetId)}function ek(e){let{chat:t,scope:n,allScopes:s,onDisconnect:i,updateScopes:r,labels:o}=e,[c,d]=(0,l.useState)(!1),[u,h]=(0,l.useState)(null),p=function(e,t){let n=ew(e),a=t.get(n);return void 0!==a&&a.length>0?a:"capsule"===e.kind?"Connector: ".concat(e.capsuleId):"Connector set: ".concat(e.capsuleSetId)}(n,o),m=ew(n);async function f(){if(!c){h(null),d(!0);try{let e=s.filter(e=>ew(e)!==m),n=await r(t.id,e.length>0?e:null);null==i||i(n.chat)}catch(e){h(e instanceof $.hD?"".concat(e.code,": ").concat(e.message):e instanceof Error?e.message:"Unable to disconnect connector.")}finally{d(!1)}}}return(0,a.jsxs)("span",{className:"scope-pill-wrap",children:[(0,a.jsxs)("span",{className:"scope-pill scope-pill--connector",children:[(0,a.jsx)("span",{"aria-hidden":"true",children:"◆"}),(0,a.jsx)("span",{role:"status","aria-live":"polite",children:p}),(0,a.jsx)("button",{type:"button",className:"scope-pill-disconnect",disabled:c,"aria-label":"Disconnect ".concat(p," from chat"),title:"Disconnect ".concat(p," from chat"),onClick:()=>{f()},children:(0,a.jsx)("span",{"aria-hidden":"true",children:"\xd7"})})]}),null!==u?(0,a.jsx)("span",{role:"alert",className:"scope-connect-error",children:u}):null]})}function eN(e){let{chat:t,onDisconnect:n,updateScopes:l=$.Cp,labels:s=new Map}=e,i=ep(t);return 0===i.length?null:(0,a.jsx)("span",{className:"scope-pill-group scope-pill-group--connector",children:i.map(e=>(0,a.jsx)(ek,{chat:t,scope:e,allScopes:i,onDisconnect:n,updateScopes:l,labels:s},ew(e)))})}let eS="cmp-budget-exceeded-alert",eC={low:"Low",moderate:"Moderate",high:"High",exceeded:"Exceeded"},eR={low:"cmp-budget-badge cmp-budget-badge-low",moderate:"cmp-budget-badge cmp-budget-badge-moderate",high:"cmp-budget-badge cmp-budget-badge-high",exceeded:"cmp-budget-badge cmp-budget-badge-exceeded"};function eI(e){return e>=1e3?"".concat((e/1e3).toFixed(1),"k"):e.toString()}function eE(e){let{budget:t,onClearHistory:n,disabled:l}=e;if(void 0===t||t.contextWindowTokens<=0)return null;let s=eI(t.approximateTokens),i=eI(t.contextWindowTokens),r=t.pressure,o="exceeded"===r;return(0,a.jsxs)("div",{className:"cmp-budget","data-pressure":r,children:[(0,a.jsxs)("div",{className:"cmp-budget-row",children:[(0,a.jsxs)("span",{className:"cmp-budget-count",children:["Approximate context: ",s," / ",i," tokens"]}),(0,a.jsx)("span",{className:eR[r],"aria-label":"Context pressure: ".concat(eC[r]),children:eC[r]}),(0,a.jsx)("span",{className:"cmp-budget-info",role:"img","aria-label":"Token counts are approximate. Actual model usage may vary.",title:"Token counts are approximate. Actual model usage may vary.",children:"i"}),(0,a.jsx)("button",{type:"button",className:"cmp-budget-clear","aria-label":"Clear conversation history for next prompt",onClick:n,disabled:!0===l,children:"Clear history"})]}),o?(0,a.jsx)("div",{id:eS,role:"alert",className:"cmp-budget-alert gw-error",children:"Context exceeds the selected model's window. Clear history or pick a model with a larger context."}):null]})}function eM(e){return Number.isFinite(e)?String(e):"—"}function eT(e){let{label:t,value:n}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("dt",{className:"grounded-context-pack-dt",children:t}),(0,a.jsx)("dd",{className:"grounded-context-pack-dd",children:n})]})}function eq(e){let{contextPack:t}=e,{usage:n,budget:l}=t,s=function(e){if("workspace-root"===e.scopeKind)return"workspace root";let t=e.scopeId.slice(-8);return"".concat(e.scopeKind," (").concat(t,")")}(t),i="files"===t.scopeKind?"Scope: ".concat(String(t.fileCount)," file").concat(1===t.fileCount?"":"s"," in ").concat(s):"Scope: ".concat(s);return(0,a.jsxs)("section",{className:"grounded-context-pack","aria-label":"Context inspection summary",children:[(0,a.jsx)("div",{className:"grounded-context-pack-headline",children:i}),(0,a.jsxs)("dl",{className:"grounded-context-pack-dl",children:[(0,a.jsx)(eT,{label:"Searched",value:"".concat(String(n.searchCalls),"\xd7 / ").concat(eM(l.searchCallsMax))}),(0,a.jsx)(eT,{label:"Read",value:"".concat(String(n.filesRead)," / ").concat(eM(l.filesReadMax)," files")}),(0,a.jsx)(eT,{label:"Bytes",value:"".concat(String(n.excerptBytes)," / ").concat(eM(l.excerptBytesMax)," B")}),(0,a.jsx)(eT,{label:"Input",value:"".concat(String(n.modelInputTokens)," / ").concat(eM(l.modelInputTokensMax)," tokens")}),(0,a.jsx)(eT,{label:"Output",value:"".concat(String(n.modelOutputTokens)," / ").concat(eM(l.modelOutputTokensMax)," tokens")}),(0,a.jsx)(eT,{label:"Rerank",value:"".concat(String(n.rerankCalls)," / ").concat(eM(l.rerankCallsMax)," calls")}),(0,a.jsx)(eT,{label:"Time",value:"".concat(String(t.elapsedMs)," / ").concat(eM(l.elapsedMsMax)," ms")}),(0,a.jsx)(eT,{label:"Query",value:t.queryKind})]})]})}function eP(e){let{citation:t}=e;return(0,a.jsxs)("span",{className:"grounded-citation",title:void 0===t.lineRange?"Evidence citation in ".concat(t.scopePath):"Evidence citation in ".concat(t.scopePath," at lines ").concat(String(t.lineRange.startLine),"-").concat(String(t.lineRange.endLine)),children:[(0,a.jsx)("span",{children:void 0===t.lineRange?t.scopePath:"".concat(t.scopePath,":").concat(String(t.lineRange.startLine),"-").concat(String(t.lineRange.endLine))}),(0,a.jsx)("span",{className:"grounded-citation-score",children:t.score.toFixed(2)})]})}function eA(e){let{citations:t}=e;return 0===t.length?null:(0,a.jsxs)("div",{className:"grounded-citations-wrap",children:[(0,a.jsx)("span",{className:"grounded-citations-label",children:"Evidence"}),(0,a.jsx)("ul",{className:"grounded-citations","aria-label":"Evidence citations",children:t.map(e=>(0,a.jsx)("li",{className:"grounded-citations-item",children:(0,a.jsx)(eP,{citation:e})},e.stableId))})]})}function ez(e){let{citations:t}=e;return 0===t.length?null:(0,a.jsxs)("div",{className:"grounded-citations-wrap",children:[(0,a.jsx)("span",{className:"grounded-citations-label",children:"Knowledge citations"}),(0,a.jsx)("ul",{className:"grounded-citations","aria-label":"Knowledge citations",children:t.map(e=>(0,a.jsx)("li",{className:"grounded-citations-item",children:(0,a.jsxs)("span",{className:"grounded-citation",title:void 0===e.source?e.label:"".concat(e.source," \xb7 ").concat(e.label),children:[(0,a.jsx)("span",{children:void 0===e.source?"".concat(e.marker," ").concat(e.label):"".concat(e.marker," ").concat(e.source," \xb7 ").concat(e.label)}),(0,a.jsx)("span",{className:"grounded-citation-score",children:e.score.toFixed(2)})]})},e.stableId))})]})}function eD(e){let{markers:t}=e;if(0===t.length)return null;let n=Array.from(new Set(t.map(e=>e.kind))).join(", ");return(0,a.jsxs)("div",{className:"grounded-uncertainty",role:"note",children:[(0,a.jsx)("div",{children:"Uncertainty (".concat(String(t.length)," markers — ").concat(n,")")}),(0,a.jsx)("ul",{className:"grounded-uncertainty-list",children:t.map((e,t)=>(0,a.jsx)("li",{children:"".concat(e.kind,": ").concat(e.claim)},"".concat(e.kind,"-").concat(String(t))))})]})}function eL(e){let{omittedCount:t,omittedCounts:n}=e;if(t<=0)return null;let l=Object.entries(n).filter(e=>{let[,t]=e;return t>0}).sort((e,t)=>{let[n]=e,[a]=t;return n<a?-1:+(n>a)}).map(e=>{let[t,n]=e;return"".concat(t.replaceAll("-"," "),": ").concat(String(n))}).join(", "),s=l.length>0?" (".concat(l,")"):"";return(0,a.jsx)("div",{className:"grounded-meta",children:"Omitted: ".concat(String(t)," evidence atoms").concat(s)})}let eF=[{reason:"size-exceeded",label:"larger than 2 MB"},{reason:"binary",label:"binary or an unsupported format"},{reason:"generated",label:"generated artifacts"},{reason:"budget-exhausted",label:"skipped after the exploration budget was reached"},{reason:"tool-unavailable",label:"unreadable"}];function eO(e){let{omittedCounts:t}=e,n=eF.map(e=>{let{reason:n,label:a}=e;return{label:a,count:t[n]}}).filter(e=>e.count>0),l=n.reduce((e,t)=>e+t.count,0);if(l<=0)return null;let s=n.map(e=>"".concat(String(e.count)," ").concat(e.label)).join(", ");return(0,a.jsxs)("div",{className:"grounded-coverage-notice",role:"note",children:[(0,a.jsx)("span",{className:"grounded-coverage-notice-title",children:"Partial coverage"}),(0,a.jsx)("span",{children:"This answer reflects only the searchable files in the connected scope — ".concat(String(l)," ").concat(1===l?"file":"files"," ").concat(1===l?"was":"were"," not searched (").concat(s,"). It does not cover the entire folder.")})]})}function eK(e){let{runId:t}=e;return void 0===t?null:(0,a.jsx)("div",{className:"grounded-meta",children:(0,a.jsx)("a",{href:"/api/evidence/".concat(encodeURIComponent(t)),children:"View connected-context audit evidence"})})}function eB(e){let{contextPack:t}=e;return(0,a.jsxs)("section",{className:"grounded-context-pack","aria-label":"Knowledge scope summary",children:[(0,a.jsx)("div",{className:"grounded-context-pack-headline",children:"Knowledge scope: ".concat(t.scopeLabel)}),(0,a.jsxs)("dl",{className:"grounded-context-pack-dl",children:[(0,a.jsx)(eT,{label:"Mode",value:t.scopeKind}),(0,a.jsx)(eT,{label:"Capsules",value:String(t.capsuleCount)}),(0,a.jsx)(eT,{label:"Sources",value:String(t.sourceCount)}),(0,a.jsx)(eT,{label:"Citations",value:String(t.citationCount)}),(0,a.jsx)(eT,{label:"Context budget",value:"".concat(String(t.referencesUsed)," / ").concat(String(t.referenceBudget)," references")})]})]})}function eW(e){let{contextPack:t}=e;return(0,a.jsxs)("section",{className:"grounded-context-pack","aria-label":"Hybrid source summary",children:[(0,a.jsx)("div",{className:"grounded-context-pack-headline",children:"Hybrid: ".concat(String(t.folderSourceCount)," folder source").concat(1===t.folderSourceCount?"":"s"," + ").concat(String(t.connectorSourceCount)," connector source").concat(1===t.connectorSourceCount?"":"s")}),(0,a.jsx)(eq,{contextPack:t.folder}),(0,a.jsx)(eB,{contextPack:t.knowledge})]})}function eU(e){let{answer:t,busy:n}=e;return void 0===t?n?(0,a.jsx)("div",{className:"grounded-meta",children:"Exploring repository context and asking Keiko…"}):null:"local-knowledge"===t.groundingKind?(0,a.jsxs)("div",{className:"grounded-answer",children:[(0,a.jsx)("div",{className:"grounded-answer-body",children:t.content}),(0,a.jsx)(ez,{citations:t.citations}),(0,a.jsx)(eD,{markers:t.uncertainty}),(0,a.jsx)(eB,{contextPack:t.contextPack})]}):"hybrid"===t.groundingKind?(0,a.jsxs)("div",{className:"grounded-answer",children:[(0,a.jsx)("div",{className:"grounded-answer-body",children:t.content}),(0,a.jsx)(eO,{omittedCounts:t.contextPack.folder.omittedCounts}),(0,a.jsx)(eA,{citations:t.citations}),(0,a.jsx)(ez,{citations:t.knowledgeCitations}),(0,a.jsx)(eD,{markers:t.uncertainty}),(0,a.jsx)(eL,{omittedCount:t.omittedCount,omittedCounts:t.contextPack.folder.omittedCounts}),(0,a.jsx)(eK,{runId:t.evidenceRunId}),(0,a.jsx)(eW,{contextPack:t.contextPack})]}):(0,a.jsxs)("div",{className:"grounded-answer",children:[(0,a.jsx)("div",{className:"grounded-answer-body",children:t.content}),(0,a.jsx)(eO,{omittedCounts:t.contextPack.omittedCounts}),(0,a.jsx)(eA,{citations:t.citations}),(0,a.jsx)(eD,{markers:t.uncertainty}),(0,a.jsx)(eL,{omittedCount:t.omittedCount,omittedCounts:t.contextPack.omittedCounts}),(0,a.jsx)(eK,{runId:t.evidenceRunId}),(0,a.jsx)(eq,{contextPack:t.contextPack})]})}let e_=["<script","</script","<iframe","</iframe","<object","</object","<embed","</embed","<style","</style","<svg","</svg","<form","</form","<meta","<link","<base"],eH=[" ","\n"," ","'",'"'];function eJ(e){var t;let n=function(e){let t=e.toLowerCase().replaceAll("\0",""),n="";for(let e=0;e<t.length;e++){var a;let l=null!=(a=t[e])?a:"";if("<"===l){for(n+="<";e+1<t.length&&(" "===t[e+1]||" "===t[e+1]||"\n"===t[e+1]||"\r"===t[e+1]);)e++;continue}n+=l}return n}(e);for(let e of e_)if(n.includes(e))return!0;let a=0;for(;a<n.length-4;){let e=n[a];if(eH.includes(e)&&"o"===n[a+1]&&"n"===n[a+2]){let e=a+3;for(;e<n.length&&/[a-z]/.test(null!=(t=n[e])?t:"");)e++;if(e<n.length&&"="===n[e])return!0}a++}return!1}function eV(e,t,n,a){a>n&&e.push({kind:"text",text:t.slice(n,a)})}function eG(e){return void 0!==e&&/[A-Za-z0-9]/.test(e)}let eX=new Set([" "," ","\n","<",">",'"']),eY=new Set([".",",",")","]","!","?"]);function eZ(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(t>=16)return e.length>0?[{kind:"text",text:e}]:[];let n=[],a=0,l=0;for(;a<e.length;){let s=function(e,t,n,a){if("`"!==t[n])return -1;let l=t.indexOf("`",n+1);return -1===l?-1:(eV(e,t,a,n),e.push({kind:"inline-code",text:t.slice(n+1,l)}),l+1)}(n,e,a,l);if(-1!==s||-1!==(s=function(e,t,n,a,l){let s=t[n],i=t[n+1];if(n+1>=t.length||("*"!==s||"*"!==i)&&("_"!==s||"_"!==i))return -1;let r=t.indexOf(s+i,n+2);if(-1===r)return -1;eV(e,t,a,n);let o=t.slice(n+2,r);return e.push({kind:"strong",children:eZ(o,l+1)}),r+2}(n,e,a,l,t))||-1!==(s=function(e,t,n,a,l){let s=t[n];if("*"!==s&&"_"!==s||"_"===s&&eG(t[n-1])&&eG(t[n+1])||t[n+1]===s||n>0&&t[n-1]===s)return -1;let i=function(e,t,n){for(let a=n;a<e.length;a++)if(e[a]===t&&e[a-1]!==t&&(a+1>=e.length||e[a+1]!==t))return a;return -1}(t,s,n+1);return -1===i||"_"===s&&eG(t[i-1])&&eG(t[i+1])?-1:(eV(e,t,a,n),e.push({kind:"em",children:eZ(t.slice(n+1,i),l+1)}),i+1)}(n,e,a,l,t))||-1!==(s=function(e,t,n,a){if("["!==t[n])return -1;let l=t.indexOf("]",n+1);if(-1===l||"("!==t[l+1])return -1;let s=t.indexOf(")",l+2);if(-1===s)return -1;let i=t.slice(n+1,l),r=t.slice(l+2,s);return eV(e,t,a,n),!function(e){let t=e.trim().toLowerCase();return t.startsWith("http://")||t.startsWith("https://")}(r)||eJ(i)||eJ(r)?e.push({kind:"text",text:"[".concat(i,"](").concat(r,")")}):e.push({kind:"link",text:i,href:r}),s+1}(n,e,a,l))||-1!==(s=function(e,t,n,a){if("h"!==t[n])return -1;let l="https://"===t.slice(n,n+8),s="http://"===t.slice(n,n+7);if(!l&&!s)return -1;let i=function(e,t){var n,a;let l=t;for(;l<e.length&&!eX.has(null!=(n=e[l])?n:"");)l++;for(;l>t&&eY.has(null!=(a=e[l-1])?a:"");)l--;return l}(t,n);if(i-n<=(l?8:7))return -1;let r=t.slice(n,i);return eV(e,t,a,n),e.push({kind:"link",text:r,href:r}),i}(n,e,a,l))){l=s,a=s;continue}a++}return eV(n,e,l,e.length),n}function eQ(e){let t=e.trim(),n=t.startsWith(":"),a=t.endsWith(":");return n&&a?"center":a?"right":n?"left":void 0}function e$(e){let t=e.trim();return t.startsWith("|")&&(t=t.slice(1)),t.endsWith("|")&&(t=t.slice(0,-1)),t.split("|")}function e0(e){var t,n,a;let l=/^( *)([*+\-]) (.*)$/.exec(e);return l?{match:!0,indent:null!=(n=null==(t=l[1])?void 0:t.length)?n:0,text:null!=(a=l[3])?a:""}:{match:!1}}function e1(e){var t,n,a;let l=/^( *)\d+\. (.*)$/.exec(e);return l?{match:!0,indent:null!=(n=null==(t=l[1])?void 0:t.length)?n:0,text:null!=(a=l[2])?a:""}:{match:!1}}function e2(e){return e.includes("|")}function e5(e){let t=e.trim();return/^(-{3,}|\*{3,}|_{3,})$/.test(t)}function e3(e,t){let n=[],a=t?e1:e0;for(;e.i<e.lines.length;){var l;let t=null!=(l=e.lines[e.i])?l:"",s=a(t);if(s.match)n.push({text:s.text,indent:s.indent}),e.i++;else if(""===t.trim())break;else break}return function e(t,n,a){let l=n?"ol":"ul",s=[],i=0;for(;i<t.length;){let l=t[i];if(void 0===l){i++;continue}let r=l.indent,o=[];for(i++;i<t.length;){let e=t[i];if(void 0===e||e.indent<=r)break;o.push(e),i++}let c=[...eZ(l.text)];o.length>0&&a<16?c.push(e(o,n,a+1)):o.length>0&&c.push({kind:"text",text:o.map(e=>e.text).join("\n")}),s.push({kind:"li",children:c})}return{kind:l,children:s}}(n,t,e.depth)}function e4(e){let{text:t}=e,[n,s]=(0,l.useState)(!1),i=(0,l.useCallback)(()=>{var e;"undefined"!=typeof navigator&&(null==(e=navigator.clipboard)?void 0:e.writeText)!==void 0&&navigator.clipboard.writeText(t).then(()=>{s(!0),setTimeout(()=>{s(!1)},1500)},()=>{})},[t]);return(0,a.jsx)("button",{type:"button",className:"sm-code-copy","aria-label":"Copy code block",title:n?"Copied!":"Copy code block",onClick:i,children:n?"✓":"Copy"})}let e6={1:"h1",2:"h2",3:"h3",4:"h4",5:"h5",6:"h6"},e8={1:"sm-h sm-h1",2:"sm-h sm-h2",3:"sm-h sm-h3",4:"sm-h sm-h4",5:"sm-h sm-h5",6:"sm-h sm-h6"};function e7(e,t){return void 0===e.children?null:e.children.map((e,n)=>e9(e,t+"-"+String(n)))}function e9(e,t){let n=function(e,t){var n,l;switch(e.kind){case"paragraph":return(0,a.jsx)("p",{className:"sm-p",children:e7(e,t)},t);case"heading":{let l=null!=(n=e.level)?n:1,s=e6[l],i=e8[l];return(0,a.jsx)(s,{className:i,children:e7(e,t)},t)}case"blockquote":return(0,a.jsx)("blockquote",{className:"sm-blockquote",children:e7(e,t)},t);case"hr":return(0,a.jsx)("hr",{className:"sm-hr"},t);case"code-block":{let n=e.language,s=null!=(l=e.text)?l:"",i=void 0!==n?"lang-".concat(n):void 0;return(0,a.jsxs)("div",{className:"sm-code-block-frame",children:[(0,a.jsxs)("div",{className:"sm-code-block-header",children:[(0,a.jsx)("span",{className:"sm-code-lang",children:null!=n?n:"untitled"}),(0,a.jsx)(e4,{text:s})]}),(0,a.jsx)("pre",{className:"sm-pre",children:(0,a.jsx)("code",{className:i,children:s})})]},t)}default:return null}}(e,t);if(null!==n)return n;let l=function(e,t){switch(e.kind){case"ul":return(0,a.jsx)("ul",{className:"sm-ul",children:e7(e,t)},t);case"ol":return(0,a.jsx)("ol",{className:"sm-ol",children:e7(e,t)},t);case"li":return(0,a.jsx)("li",{className:"sm-li",children:e7(e,t)},t);default:return null}}(e,t);if(null!==l)return l;let s=function(e,t){let n=void 0!==e.align?{textAlign:e.align}:void 0;switch(e.kind){case"table":return(0,a.jsx)("div",{className:"sm-table-wrapper",children:(0,a.jsx)("table",{className:"sm-table",children:e7(e,t)})},t);case"thead":return(0,a.jsx)("thead",{children:e7(e,t)},t);case"tbody":return(0,a.jsx)("tbody",{children:e7(e,t)},t);case"tr":return(0,a.jsx)("tr",{children:e7(e,t)},t);case"th":return(0,a.jsx)("th",{style:n,children:e7(e,t)},t);case"td":return(0,a.jsx)("td",{style:n,children:e7(e,t)},t);default:return null}}(e,t);if(null!==s)return s;let i=function(e,t){switch(e.kind){case"text":return(0,a.jsx)("span",{children:e.text},t);case"inline-code":return(0,a.jsx)("code",{className:"sm-inline-code",children:e.text},t);case"link":return(0,a.jsx)("a",{href:e.href,className:"sm-link",rel:"noopener noreferrer",target:"_blank",children:e.text},t);case"strong":return(0,a.jsx)("strong",{children:e7(e,t)},t);case"em":return(0,a.jsx)("em",{children:e7(e,t)},t);default:return null}}(e,t);return null!==i?i:null}function te(e){let{source:t}=e,n=function e(t,n){let a=[],l={lines:t.split("\n"),i:0,depth:n};for(;l.i<l.lines.length;)!function(t,n){var a,l;let s=null!=(a=t.lines[t.i])?a:"";if(""===s.trim())return t.i++;if(function(e,t,n){var a;let l=/^(`{3,}|~{3,})(\S*)/.exec(t.trim());if(null===l)return!1;let s=null!=(a=l[1])?a:"```",i=l[2],r=void 0!==i&&i.length>0?i:void 0;return n.push(function(e,t,n){let a=[];for(e.i++;e.i<e.lines.length;){var l,s,i;let n=null!=(l=e.lines[e.i])?l:"",r=/^(`{3,}|~{3,})\s*$/.exec(n.trim());if(null!==r){let n=null!=(s=r[1])?s:"";if(n.startsWith(null!=(i=t[0])?i:"")&&n.length>=t.length){e.i++;break}}a.push(n),e.i++}let r={kind:"code-block",text:a.join("\n")};return void 0!==n?{...r,language:n}:r}(e,s,r)),!0}(t,s,n)||function(e,t,n){var a,l;let s=/^(#{1,6}) (.+)$/.exec(t.trim());if(null===s)return!1;let i=Math.min((null!=(a=s[1])?a:"").length,6),r=null!=(l=s[2])?l:"";return n.push({kind:"heading",level:i,children:eZ(r)}),e.i++,!0}(t,s,n))return;if(e5(s)){n.push({kind:"hr"}),t.i++;return}if(s.trimStart().startsWith("> ")||">"===s.trim())return n.push(function(t){let n=[];for(;t.i<t.lines.length;){var a;let e=null!=(a=t.lines[t.i])?a:"";if(e.trimStart().startsWith("> ")||">"===e.trim())n.push(e.replace(/^( *)> ?/,"")),t.i++;else break}let l=n.join("\n");return t.depth>=16?{kind:"blockquote",children:[{kind:"paragraph",children:[{kind:"text",text:l}]}]}:{kind:"blockquote",children:[...e(l,t.depth+1)]}}(t));if(e2(s.trim())&&function(e){if(0===e.length)return!1;for(let t of e){let e=t.trim().replace(/^:/,"").replace(/:$/,"");if(!/^-+$/.test(e))return!1}return!0}(e$(null!=(l=t.lines[t.i+1])?l:""))&&(n.push(function(e,t){var n,a;e.i++;let l=null!=(n=e.lines[e.i])?n:"",s=[];for(e.i++;e.i<e.lines.length;){let t=null!=(a=e.lines[e.i])?a:"";if(""===t.trim()||!e2(t.trim()))break;s.push(t),e.i++}let i=e$(t),r=e$(l).map(eQ);return{kind:"table",children:[{kind:"thead",children:[{kind:"tr",children:i.map((e,t)=>(function(e,t){let n={kind:"th",children:eZ(e.trim())};return void 0!==t?{...n,align:t}:n})(e,r[t]))}]},{kind:"tbody",children:s.map(e=>({kind:"tr",children:e$(e).map((e,t)=>(function(e,t){let n={kind:"td",children:eZ(e.trim())};return void 0!==t?{...n,align:t}:n})(e,r[t]))}))}]}}(t,s)),1)||(e0(s).match?(n.push(e3(t,!1)),!0):!!e1(s).match&&(n.push(e3(t,!0)),!0)))return;let i=function(e){let t=[];for(;e.i<e.lines.length;){var n;let a=null!=(n=e.lines[e.i])?n:"";if(function(e){let t=e.trim();return!!(""===t||/^#{1,6} /.test(t)||e.trimStart().startsWith("> ")||/^(`{3,}|~{3,})/.test(t))||!!e0(e).match||!!e1(e).match||e5(e)}(a))break;t.push(a),e.i++}return 0===t.length?null:{kind:"paragraph",children:eZ(t.join(" "))}}(t);null!==i&&n.push(i)}(l,a);return a}(t,0);return(0,a.jsx)("div",{className:"sm-root",children:n.map((e,t)=>e9(e,String(t)))})}class tt extends l.Component{static getDerivedStateFromError(){return{failed:!0}}render(){return this.state.failed?(0,a.jsx)("div",{className:"sm-root sm-fallback","data-markdown-fallback":"true",children:this.props.source}):(0,a.jsx)(te,{source:this.props.source})}constructor(...e){super(...e),this.state={failed:!1}}}function tn(e){var t;let{attachment:n,onRemove:l}=e,s="Remove attachment ".concat(n.name),i=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:32;if(e.length<=t)return e;let n=e.lastIndexOf(".");if(n>0&&e.length-n<=8){let a=e.slice(n);return"".concat(e.slice(0,t-a.length-1),"…").concat(a)}return"".concat(e.slice(0,t-1),"…")}(n.name);return(0,a.jsxs)("div",{className:"attach-chip",role:"listitem",children:["image"===n.kind&&void 0!==n.previewDataUrl?(0,a.jsx)("img",{src:n.previewDataUrl,alt:n.name,className:"attach-chip-thumb","aria-hidden":"true",width:40,height:40}):(0,a.jsx)("span",{className:"attach-chip-icon","aria-hidden":"true",children:(0,a.jsx)(S.file,{size:16})}),(0,a.jsx)("span",{className:"attach-chip-name",title:n.name,children:i}),(0,a.jsx)("span",{className:"attach-chip-size",children:(t=n.sizeBytes)<1024?"".concat(String(t)," B"):t<1048576?"".concat((t/1024).toFixed(1)," KB"):"".concat((t/1048576).toFixed(1)," MiB")}),(0,a.jsx)("button",{type:"button",className:"attach-chip-remove","aria-label":s,onClick:()=>l(n.id),children:(0,a.jsx)(S.close,{size:12})})]})}function ta(e){let{attachments:t,onRemove:n}=e;return 0===t.length?null:(0,a.jsx)("div",{className:"attach-strip",role:"list","aria-label":"Pending attachments",children:t.map(e=>(0,a.jsx)(tn,{attachment:e,onRemove:n},e.id))})}function tl(e){let{enabled:t,onFiles:n}=e,[s,i]=(0,l.useState)(!1),r=(0,l.useCallback)(e=>{t&&(e.preventDefault(),i(!0))},[t]),o=(0,l.useCallback)(()=>{i(!1)},[]),c=(0,l.useCallback)(e=>{if(e.preventDefault(),i(!1),!t)return;let a=Array.from(e.dataTransfer.files);a.length>0&&n(a)},[t,n]);return(0,a.jsx)("div",{className:"attach-drop-zone","aria-label":t?"Drop files here to attach":"Attachments not supported by this model","data-dragover":s?"true":void 0,"data-disabled":t?void 0:"true",onDragOver:r,onDragLeave:o,onDrop:c,role:"presentation",children:t?null:(0,a.jsx)("span",{className:"attach-drop-hint",children:"Attachments not supported by this model"})})}let ts="cmp-attach-disabled-hint";function ti(e){let{model:t,onFiles:n}=e,s=(0,l.useRef)(null),i=void 0!==t&&(t.supportsImageInput||t.supportsDocumentInput),r=function(e){if(void 0===e)return"";let t=[];return e.supportsImageInput&&t.push("image/*"),e.supportsDocumentInput&&t.push(".pdf,.txt,.md,.csv,.json,.yaml,.yml"),t.join(",")}(t),o=(0,l.useCallback)(()=>{var e;i&&(null==(e=s.current)||e.click())},[i]),c=(0,l.useCallback)(()=>{var e,t;let a=Array.from(null!=(t=null==(e=s.current)?void 0:e.files)?t:[]);a.length>0&&(n(a),null!==s.current&&(s.current.value=""))},[n]);return(0,a.jsxs)(a.Fragment,{children:[i?null:(0,a.jsx)("span",{id:ts,className:"sr-only",children:"The selected model does not support image or document input. Choose a different model to attach files."}),(0,a.jsx)("input",{ref:s,type:"file",multiple:!0,accept:r,className:"sr-only",tabIndex:-1,"aria-hidden":"true",onChange:c}),(0,a.jsx)("button",{type:"button",className:"cmp-icon","aria-label":"Attach file","aria-disabled":i?void 0:"true","aria-describedby":i?void 0:ts,title:i?"Attach file":"Attachments not supported by this model",onClick:o,children:(0,a.jsx)(S.files,{size:16})})]})}function tr(e){let{reason:t,mimeType:n}=e;return void 0===t?null:(0,a.jsx)("div",{role:"alert",className:"attach-rejection-alert",children:function(e,t){switch(e){case"text-only-model":return"The selected model can't accept this attachment type. Choose a model that supports images or documents.";case"unsupported-type":return"Unsupported file type".concat(void 0!==t&&t.length>0?": ".concat(t):"",". Supported types: images (image/*), PDF, plain text, markdown, JSON, YAML.");case"oversized":return"File is larger than the 8 MiB limit. Choose a smaller file or summarize the content as text.";case"empty":return"Empty file. Add a file with content to attach."}}(t,n)})}function to(e){let{documents:t}=e;if(0===t.length)return null;let n=t.some(e=>e.truncated);return(0,a.jsxs)("div",{role:"status",className:"sent-docs-note","aria-label":"Documents included as context",children:[(0,a.jsx)("span",{className:"sent-docs-note-label",children:1===t.length?"Document included as context:":"Documents included as context:"}),(0,a.jsx)("ul",{className:"sent-docs-note-list",children:t.map(e=>(0,a.jsxs)("li",{className:"sent-docs-note-item",children:[e.displayName,e.truncated?(0,a.jsx)("span",{className:"sent-docs-note-trunc",children:" (truncated)"}):null]},e.id))}),n?(0,a.jsx)("span",{className:"sent-docs-note-hint",children:"Some document text was truncated to fit the context limit."}):null]})}let tc=[{workflowId:"unit-test-generation",label:"Generate unit tests",description:"Drafts a reviewable unit-test patch for a target file. Dry-run only from chat — apply from the workflow view.",prompt:"Target file (workspace-relative)",placeholder:"src/example.ts",buildInput:(e,t)=>({workspaceRoot:e,target:{kind:"file",filePath:t.trim()}})},{workflowId:"bug-investigation",label:"Investigate bug",description:"Investigates a reported issue and proposes a root-cause hypothesis. Dry-run only from chat.",prompt:"Describe the bug",placeholder:"The login button does nothing when the form is empty…",buildInput:(e,t)=>({workspaceRoot:e,report:{description:t.trim()}})}];function td(e){return tc.find(t=>t.workflowId===e)}function tu(e){return"chat"===e.kind&&e.toolCalling&&e.structuredOutput}function th(e){let{selectedModel:t,launch:n}=e,[s,i]=(0,l.useState)(!1),r=(0,l.useRef)(null);return void 0!==t&&tu(t)?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("button",{ref:r,type:"button",className:"cmp-mode",title:"Launch a governed workflow with the current model","aria-haspopup":"dialog","aria-expanded":s,onClick:()=>i(!0),children:[(0,a.jsx)(S.spark,{size:14,style:{color:"var(--accent)"}})," Launch workflow",(0,a.jsx)(S.chevron,{size:12})]}),s?(0,a.jsx)(tm,{modelId:t.id,launch:n,onClose:()=>{var e;i(!1),null==(e=r.current)||e.focus()}}):null]}):null}function tp(e){return Array.from(e.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'))}function tm(e){let{modelId:t,launch:n,onClose:s}=e,i=(0,l.useId)(),r=(0,l.useId)(),[o,c]=(0,l.useState)(),[d,u]=(0,l.useState)(""),[h,p]=(0,l.useState)(!1),[m,f]=(0,l.useState)(),g=(0,l.useRef)(null),v=void 0===o?void 0:td(o);async function x(){if(void 0===v||0===d.trim().length)return;p(!0),f(void 0);let e=await n({workflowId:v.workflowId,modelId:t,text:d});if(p(!1),e.ok)return void s();f(function(e){if(void 0!==e.message&&e.message.length>0)return e.message;switch(e.reason){case"not-workflow-eligible":return"The selected model does not support workflow runs. Pick a model with tool calling and structured output.";case"unknown-workflow":return"That workflow is no longer available.";case"missing-chat":return"Open or create a chat first, then launch the workflow.";case"missing-input":return"Provide an input before launching the workflow.";case"request-failed":return"Could not launch the workflow. Try again, or check the gateway logs.";default:return"Could not launch the workflow."}}(e))}return(0,l.useEffect)(()=>{var e;null==(e=g.current)||e.focus()},[]),(0,l.useEffect)(()=>{function e(e){if("Escape"===e.key)return void s();if("Tab"!==e.key)return;let t=g.current;if(null===t)return;let n=tp(t);if(0===n.length){e.preventDefault(),t.focus();return}let a=n[0],l=n[n.length-1],i=document.activeElement;e.shiftKey&&(i===a||i===t)?(e.preventDefault(),null==l||l.focus()):e.shiftKey||i!==l||(e.preventDefault(),null==a||a.focus())}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[s]),(0,a.jsx)("div",{ref:g,role:"dialog","aria-modal":"true","aria-labelledby":i,tabIndex:-1,className:"wf-dialog-overlay",children:(0,a.jsxs)("div",{className:"wf-dialog",children:[(0,a.jsx)("h2",{id:i,className:"wf-dialog-title",children:"Launch workflow"}),void 0===v?(0,a.jsx)("ul",{className:"wf-dialog-list","aria-label":"Available workflows",children:tc.map(e=>(0,a.jsx)("li",{children:(0,a.jsxs)("button",{type:"button",className:"wf-dialog-choice",onClick:()=>c(e.workflowId),children:[(0,a.jsx)("span",{className:"wf-dialog-choice-label",children:e.label}),(0,a.jsx)("span",{className:"wf-dialog-choice-desc",children:e.description})]})},e.workflowId))}):(0,a.jsxs)("div",{className:"wf-dialog-form",children:[(0,a.jsx)("p",{className:"wf-dialog-form-desc",children:v.description}),(0,a.jsx)("label",{className:"wf-dialog-field",htmlFor:r,children:v.prompt}),(0,a.jsx)("textarea",{id:r,className:"wf-dialog-input mono",rows:3,placeholder:v.placeholder,value:d,onChange:e=>u(e.target.value)}),void 0!==m?(0,a.jsx)("div",{role:"alert",className:"wf-dialog-error",children:m}):null,(0,a.jsxs)("div",{className:"wf-dialog-actions",children:[(0,a.jsx)("button",{type:"button",className:"wf-dialog-cancel",onClick:()=>c(void 0),children:"Back"}),(0,a.jsx)("button",{type:"button",className:"wf-dialog-launch",disabled:h||0===d.trim().length,onClick:()=>{x()},children:h?"Launching…":"Launch"})]})]}),(0,a.jsx)("button",{type:"button",className:"wf-dialog-close","aria-label":"Close launch workflow",onClick:s,children:(0,a.jsx)(S.close,{size:14})})]})})}let tf=[{workflowKind:"unit-test-generation",label:"Generate unit tests",description:"Use the grounded evidence as read-only context and propose in-scope test changes."},{workflowKind:"bug-investigation",label:"Investigate bug",description:"Investigate a bug against the grounded evidence and keep writes inside approved paths."},{workflowKind:"verification",label:"Run verification",description:"Run verification against the grounded workspace context without granting write access."}],tg=["verify","lint","typecheck","tests","manual"];function tv(e){return e.split(/\r?\n|,/).map(e=>e.trim()).filter(e=>e.length>0)}function tx(e){let{answer:t,modelId:n,busy:s,launch:i}=e,[r,o]=(0,l.useState)(!1),c=(0,l.useRef)(null);return void 0===t||"connected-context"!==t.groundingKind||void 0===n?null:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("button",{ref:c,type:"button",className:"cmp-mode",title:"Launch a governed workflow from this grounded answer","aria-haspopup":"dialog","aria-expanded":r,disabled:!0===s,onClick:()=>o(!0),children:[(0,a.jsx)(S.spark,{size:14,style:{color:"var(--accent)"}})," Launch grounded workflow",(0,a.jsx)(S.chevron,{size:12})]}),r?(0,a.jsx)(ty,{answer:t,modelId:n,launch:i,onClose:()=>{var e;o(!1),null==(e=c.current)||e.focus()}}):null]})}function ty(e){let{answer:t,modelId:n,launch:s,onClose:i}=e,r=(0,l.useId)(),o=(0,l.useRef)(null),[c,d]=(0,l.useState)(),[u,h]=(0,l.useState)("file"),[p,m]=(0,l.useState)(""),[f,g]=(0,l.useState)(""),[v,x]=(0,l.useState)(""),[y,b]=(0,l.useState)(""),[j,w]=(0,l.useState)(""),[k,N]=(0,l.useState)(""),[C,R]=(0,l.useState)([]),[I,E]=(0,l.useState)(!1),[M,T]=(0,l.useState)();async function q(){if(void 0===c)return;let e=function(e,t,n,a,l,s){if("unit-test-generation"===e){if("changedFiles"===t){let e=tv(n);return 0===e.length?{ok:!1,message:"Provide at least one changed file."}:{ok:!0,input:{target:{kind:"changedFiles",filePaths:e}}}}let e=n.trim();return 0===e.length?{ok:!1,message:"module"===t?"Provide a module directory.":"Provide a target file."}:"module"===t?{ok:!0,input:{target:{kind:"module",moduleDir:e}}}:{ok:!0,input:{target:{kind:"file",filePath:e}}}}if("bug-investigation"===e){let e=tv(l),t=a.trim();return 0===t.length&&0===e.length?{ok:!1,message:"Provide at least a bug description or one suspected target file."}:{ok:!0,input:{report:{...0===t.length?{}:{description:t},...0===e.length?{}:{targetFiles:e}}}}}let i=tv(s);return{ok:!0,input:0===i.length?{}:{targetFiles:i}}}(c,u,p,f,v,y);if(!e.ok)return void T(e.message);if(0===C.length)return void T("Select at least one expected check.");E(!0),T(void 0);let a=await s({assistantMessageId:t.assistantMessageId,modelId:n,workflowKind:c,input:e.input,editablePaths:tv(j),expectedChecks:C,unknowns:tv(k)});if(E(!1),a.ok)return void i();T(function(e){if(e.ok)return"";if(void 0!==e.message&&e.message.length>0)return e.message;switch(e.reason){case"missing-chat":return"Open a chat with the grounded answer you want to hand off.";case"missing-model":return"Pick a model before launching the grounded workflow.";default:return"Could not launch the grounded workflow."}}(a))}(0,l.useEffect)(()=>{var e;null==(e=o.current)||e.focus()},[]),(0,l.useEffect)(()=>{void 0!==c&&R("unit-test-generation"===c?["tests"]:["verify"])},[c]),(0,l.useEffect)(()=>{function e(e){if("Escape"===e.key)return void i();if("Tab"!==e.key)return;let t=o.current;if(null===t)return;let n=tp(t);if(0===n.length){e.preventDefault(),t.focus();return}let a=n[0],l=n[n.length-1],s=document.activeElement;e.shiftKey&&(s===a||s===t)?(e.preventDefault(),null==l||l.focus()):e.shiftKey||s!==l||(e.preventDefault(),null==a||a.focus())}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[i]);let P=tf.find(e=>e.workflowKind===c);return(0,a.jsx)("div",{ref:o,role:"dialog","aria-modal":"true","aria-labelledby":r,tabIndex:-1,className:"wf-dialog-overlay",children:(0,a.jsxs)("div",{className:"wf-dialog",children:[(0,a.jsx)("h2",{id:r,className:"wf-dialog-title",children:"Grounded workflow handoff"}),void 0===P?(0,a.jsx)("ul",{className:"wf-dialog-list","aria-label":"Available grounded workflows",children:tf.map(e=>(0,a.jsx)("li",{children:(0,a.jsxs)("button",{type:"button",className:"wf-dialog-choice",onClick:()=>d(e.workflowKind),children:[(0,a.jsx)("span",{className:"wf-dialog-choice-label",children:e.label}),(0,a.jsx)("span",{className:"wf-dialog-choice-desc",children:e.description})]})},e.workflowKind))}):(0,a.jsxs)("div",{className:"wf-dialog-form",children:[(0,a.jsx)("p",{className:"wf-dialog-form-desc",children:P.description}),"unit-test-generation"===c?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"wf-dialog-field",children:["Target mode",(0,a.jsxs)("select",{className:"wf-dialog-input mono",value:u,onChange:e=>h(e.target.value),children:[(0,a.jsx)("option",{value:"file",children:"File"}),(0,a.jsx)("option",{value:"module",children:"Module"}),(0,a.jsx)("option",{value:"changedFiles",children:"Changed files"})]})]}),(0,a.jsxs)("label",{className:"wf-dialog-field",children:["module"===u?"Module directory":"changedFiles"===u?"Changed files (one per line)":"Target file",(0,a.jsx)("textarea",{className:"wf-dialog-input mono",rows:"changedFiles"===u?3:2,value:p,onChange:e=>m(e.target.value),placeholder:"module"===u?"src/components":"changedFiles"===u?"src/a.ts\nsrc/b.ts":"src/example.ts"})]})]}):null,"bug-investigation"===c?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"wf-dialog-field",children:["Bug description",(0,a.jsx)("textarea",{className:"wf-dialog-input mono",rows:3,value:f,onChange:e=>g(e.target.value),placeholder:"Describe the failing behavior or regression."})]}),(0,a.jsxs)("label",{className:"wf-dialog-field",children:["Suspected target files (one per line)",(0,a.jsx)("textarea",{className:"wf-dialog-input mono",rows:2,value:v,onChange:e=>x(e.target.value),placeholder:"src/app.ts\\nsrc/lib/foo.ts"})]})]}):null,"verification"===c?(0,a.jsxs)("label",{className:"wf-dialog-field",children:["Target files (optional, one per line)",(0,a.jsx)("textarea",{className:"wf-dialog-input mono",rows:2,value:y,onChange:e=>b(e.target.value),placeholder:"src/app.ts\\nsrc/lib/foo.ts"})]}):null,(0,a.jsxs)("label",{className:"wf-dialog-field",children:["Editable paths (explicit, workspace-relative, one per line)",(0,a.jsx)("textarea",{className:"wf-dialog-input mono",rows:3,value:j,onChange:e=>w(e.target.value),placeholder:"src/example.test.ts"})]}),(0,a.jsxs)("fieldset",{className:"wf-dialog-field",style:{border:0,padding:0,margin:0},children:[(0,a.jsx)("legend",{children:"Expected checks"}),(0,a.jsx)("div",{className:"wf-dialog-form",style:{gap:8},children:tg.map(e=>(0,a.jsxs)("label",{className:"wf-dialog-choice-desc",style:{display:"flex",gap:8},children:[(0,a.jsx)("input",{type:"checkbox",checked:C.includes(e),onChange:()=>{R(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}}),(0,a.jsx)("span",{children:e})]},e))})]}),(0,a.jsxs)("label",{className:"wf-dialog-field",children:["Unknowns (optional, one per line)",(0,a.jsx)("textarea",{className:"wf-dialog-input mono",rows:2,value:k,onChange:e=>N(e.target.value),placeholder:"Need confirmation on public API behavior"})]}),void 0!==M?(0,a.jsx)("div",{role:"alert",className:"wf-dialog-error",children:M}):null,(0,a.jsxs)("div",{className:"wf-dialog-actions",children:[(0,a.jsx)("button",{type:"button",className:"wf-dialog-cancel",onClick:()=>d(void 0),children:"Back"}),(0,a.jsx)("button",{type:"button",className:"wf-dialog-launch",disabled:I,onClick:()=>{q()},children:I?"Launching…":"Launch"})]})]}),(0,a.jsx)("button",{type:"button",className:"wf-dialog-close","aria-label":"Close grounded workflow handoff",onClick:i,children:(0,a.jsx)(S.close,{size:14})})]})})}function tb(e){return"system"===e.role&&"string"==typeof e.runId}function tj(e){var t,n,l;let{message:s}=e,i=null!=(t=s.workflowStatus)?t:"queued",r=null!=(l=null!=(n=s.workflowId)?n:s.taskType)?l:"workflow",o=void 0===s.runId?"":s.runId.slice(0,8);return(0,a.jsxs)("article",{className:"run-summary-card","data-testid":"run-summary-card","data-status":i,role:"group","aria-label":"Workflow run ".concat(r," — ").concat(i),children:[(0,a.jsxs)("header",{className:"run-summary-card-head",children:[(0,a.jsx)(S.spark,{size:14,style:{color:"var(--accent)"}}),(0,a.jsx)("span",{className:"run-summary-card-workflow mono",children:r}),(0,a.jsx)("span",{className:"run-summary-card-status","data-status":i,children:i})]}),(0,a.jsxs)("div",{className:"run-summary-card-body",children:[(0,a.jsx)("p",{className:"run-summary-card-line",children:s.content}),void 0!==s.shortResult&&s.shortResult.length>0?(0,a.jsx)("p",{className:"run-summary-card-result",children:s.shortResult}):null,void 0!==s.runId?(0,a.jsxs)("p",{className:"run-summary-card-meta mono",children:["run ",(0,a.jsx)("span",{"data-runid":s.runId,children:s.runId})," ",(0,a.jsxs)("span",{className:"run-summary-card-runshort",children:["(",o,")"]})]}):null]})]})}function tw(e){let{on:t,onChange:n,label:l}=e;return(0,a.jsx)("button",{role:"switch","aria-checked":t,"aria-label":l,className:"auto-toggle".concat(t?" on":""),onClick:()=>{n(!t)},children:(0,a.jsx)("span",{})})}var tk=n(1352),tN=n(2516);let tS="\n…[truncated]",tC=["text/"],tR=new Set(["application/json","application/x-yaml","application/yaml"]),tI=new TextEncoder;function tE(e){return tI.encode(e).length}function tM(e){let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(t+1):e}async function tT(e,t){let n;if(e.remainingAggregate<=0)return;try{n=await t.file.text()}catch(e){var a;return a=tM(t.name),"Couldn't read \"".concat(a,'" — it was skipped. The other attachments were still sent.')}let l=Math.min(65536,Math.max(e.remainingAggregate-tE(tS),0));if(l<=0)return;let{entry:s,consumed:i}=function(e,t,n){let a=tE(t)>n,l=a?function(e,t){if(t<=0)return"";if(tE(e)<=t)return e;let n=0,a="";for(let l of e){let e=n+tE(l);if(e>t)break;n=e,a+=l}return a}(t,n):t,s=tE(l),i=a?tE(tS):0;return{entry:{id:e.id,displayName:tM(e.name),mimeType:e.mimeType,sizeBytes:e.sizeBytes,extractedBytes:s,truncated:a,truncationMarker:a?tS:void 0,text:l},consumed:s+i}}(t,n,l);0!==s.text.length&&(e.entries.push(s),e.remainingAggregate-=i)}async function tq(e){let t=e.filter(e=>{var t;return t=e.mimeType,!!tC.some(e=>t.startsWith(e))||tR.has(t)}).slice(0,16),n={entries:[],remainingAggregate:262144},a=[];for(let e of t){let t=await tT(n,e);void 0!==t&&a.push(t)}return{entries:n.entries,failures:a}}let tP=["text/"],tA=new Set(["application/pdf","application/json","application/x-yaml","application/yaml"]),tz="New chat",tD=["completed","failed","cancelled"];function tL(e){return"idle"!==e&&!tD.includes(e)}let tF="The conversation context exceeded the model's window. Clear history or pick a larger-context model.",tO=new Set(["CONVERSATION_OVERSIZED_CONTEXT","GATEWAY_CONTEXT_OVERFLOW"]),tK=["context length","context_length_exceeded","max_tokens","too many tokens"];function tB(e){return void 0!==e&&e.contextWindowTokens>0&&"exceeded"===e.pressure}function tW(e){return!function(e){if(e instanceof $.hD&&tO.has(e.code))return!0;let t=e instanceof Error?e.message.toLowerCase():"";return 0!==t.length&&tK.some(e=>t.includes(e))}(e)?e instanceof $.hD?"".concat(e.code,": ").concat(e.message):e instanceof Error?e.message:"Unknown error":tF}function tU(e){return[...e].sort((e,t)=>t.updatedAt-e.updatedAt)}function t_(e){var t;return null==(t=e.find(tN.S_))?void 0:t.id}function tH(e,t){return void 0!==e&&t.some(t=>t.id===e&&(0,tN.S_)(t))?e:t_(t)}let tJ={projects:[],chats:[],messages:[],models:[],activeProject:void 0,activeChat:void 0,selectedModel:void 0};async function tV(){var e;let t=(await (0,$.ZC)().catch(()=>({models:[]}))).models.filter(tN.S_),n=t_(t),a=await (0,$.vj)().catch(()=>({projects:[]})),l=null!=(e=a.projects.find(e=>e.available))?e:a.projects[0];if(void 0!==l){let e=tU((await (0,$.Oz)(l.path).catch(()=>({chats:[]}))).chats),n=e[0];if(void 0!==n){let s=await (0,$.T$)(n.id,l.path),i=tH(n.selectedModel,t);return{models:t,selectedModel:i,projects:Array.from(a.projects),activeProject:l,chats:e,activeChat:n,messages:Array.from(s.messages)}}}if(void 0===n)return{models:t,selectedModel:void 0,projects:Array.from(a.projects),activeProject:l,chats:[],activeChat:void 0,messages:[]};let s={modelId:n,title:tz};(null==l?void 0:l.available)===!0&&(s.projectPath=l.path);let i=await (0,$.tA)(s);return{models:t,selectedModel:i.chat.selectedModel,projects:Array.from(i.projects),activeProject:i.project,chats:tU(i.chats),activeChat:i.chat,messages:Array.from(i.messages)}}var tG=n(9389);let tX="cmp-no-model-alert",tY="cmp-send-hint",tZ="cmp-loading-status";function tQ(e){return t=>{"Enter"!==t.key||t.shiftKey||(t.preventDefault(),e())}}function t$(e){let{message:t}=e;if(tb(t))return(0,a.jsx)(tj,{message:t});let n="user"===t.role;return(0,a.jsx)("article",{className:"chat-msg","data-role":t.role,children:(0,a.jsxs)("div",{className:"chat-msg-bubble",children:[(0,a.jsx)("div",{className:"chat-msg-role",children:n?"You":"Keiko"}),n?t.content:(0,a.jsx)(tt,{source:t.content}),(0,a.jsx)("div",{className:"chat-msg-time",children:new Date(t.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]})})}function t0(){return(0,a.jsx)("article",{className:"chat-msg","data-role":"assistant",children:(0,a.jsxs)("div",{className:"chat-msg-bubble",children:[(0,a.jsx)("div",{className:"chat-msg-role",children:"Keiko"}),(0,a.jsxs)("span",{className:"chat-typing","aria-label":"Keiko is responding",children:[(0,a.jsx)("i",{}),(0,a.jsx)("i",{}),(0,a.jsx)("i",{})]})]})})}function t1(e){let{session:t,ready:n,selectedModelCapability:l,onAttachFiles:s,budgetExceeded:i}=e,{models:r,selectedModel:o,setSelectedModel:c,draft:d,noEligibleModels:u,loading:h,sending:p,cancelSend:m,launchWorkflowFromConversation:f}=t,g=u||i||!n,v=0===d.trim().length,x=u?tX:void 0,y=u?tX:i?eS:h?tZ:v?tY:void 0,b=u?"No conversation-eligible model is configured — connect a gateway in Settings":"Model",j=h||u?"":null!=o?o:"";return(0,a.jsxs)("div",{className:"cmp-bar",children:[(0,a.jsx)(ti,{model:l,onFiles:s}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("label",{className:"cmp-model mono",title:b,children:[(0,a.jsx)(S.cube,{size:13,style:{color:"var(--accent)"}}),(0,a.jsx)("select",{className:"cmp-model-select",value:j,"aria-label":"Model","aria-disabled":u||h?"true":void 0,"aria-describedby":x,title:b,disabled:h,onChange:e=>{u||h||c(e.target.value)},children:h?(0,a.jsx)("option",{value:"",disabled:!0,children:"Loading models…"}):u?(0,a.jsx)("option",{value:"",children:"No conversation-eligible model"}):r.filter(e=>"chat"===e.kind).map(e=>(0,a.jsx)("option",{value:e.id,children:e.id},e.id))}),(0,a.jsx)(S.chevron,{size:12})]}),(0,a.jsx)(th,{selectedModel:l,launch:f}),null,y===tY?(0,a.jsx)("span",{id:tY,className:"sr-only",children:"Type a message to send"}):null,p?(0,a.jsx)("button",{type:"button",className:"cmp-send cmp-send-cancel","data-on":!0,"aria-label":"Cancel response",title:"Cancel response",onClick:m,children:(0,a.jsx)(S.close,{size:16})}):(0,a.jsx)("button",{type:g?"button":"submit",className:"cmp-send","data-on":!g,"aria-disabled":g,"aria-describedby":y,title:u?"No conversation-eligible model is configured — connect a gateway in Settings":i?"Context exceeds the model's window — clear history or pick a larger-context model":h?"Connecting to your gateway":v?"Type a message to send":"Send message","aria-label":"Send message",children:(0,a.jsx)(S.arrowUp,{size:16})})]})}function t2(){return(0,a.jsx)("div",{id:tX,role:"alert",className:"gw-error cmp-no-model",children:"No conversation-eligible model is configured. Connect a gateway in Settings to enable chat."})}function t5(){return(0,a.jsxs)("div",{id:tZ,role:"status",className:"cmp-loading-status",children:[(0,a.jsx)("span",{className:"cmp-loading-dot","aria-hidden":"true"}),"Connecting to your gateway…"]})}function t3(e){let{status:t}=e,n=function(e){switch(e){case"idle":case"completed":case"failed":return"";case"queued":return"Submitting your message…";case"contacting":return"Contacting model…";case"streaming":return"Receiving response…";case"cancelled":return"Response cancelled."}}(t);return 0===n.length?null:(0,a.jsxs)("div",{role:"status","aria-live":"polite","data-send-status":t,className:"cmp-send-status",children:[(0,a.jsx)("span",{className:"cmp-loading-dot","aria-hidden":"true"}),n]})}function t4(e){let{session:t,ready:n,placeholder:s}=e,{draft:i,loading:r,sending:o,sendStatus:c,setDraft:d,sendMessage:u,models:h,selectedModel:p,pendingAttachments:m,addPendingAttachment:f,removePendingAttachment:g,budget:v,clearHistory:x}=t,y=tB(v),[b,j]=(0,l.useState)(),[w,k]=(0,l.useState)(),N=h.find(e=>e.id===p),S=void 0!==N&&(N.supportsImageInput||N.supportsDocumentInput),C=(0,l.useCallback)(async e=>{let t,n;for(let a of e){let e=await f(a);e.ok||void 0!==t||(t=e.reason,n=a.type)}j(t),k(n)},[f]);return(0,a.jsxs)("div",{className:"cmp-box",children:[(0,a.jsx)(tl,{enabled:S,onFiles:C}),(0,a.jsx)(ta,{attachments:m,onRemove:g}),(0,a.jsx)("textarea",{className:"cmp-input",rows:2,value:i,"aria-label":"Chat message",placeholder:s,onChange:e=>d(e.target.value),onKeyDown:tQ(u),disabled:r||o}),(0,a.jsx)(tr,{reason:b,mimeType:w}),(0,a.jsx)(t3,{status:c}),(0,a.jsx)(eE,{budget:v,onClearHistory:x,disabled:o||r}),(0,a.jsx)(t1,{session:t,ready:n,selectedModelCapability:N,onAttachFiles:C,budgetExceeded:y})]})}function t6(e){let{session:t,noEligibleModels:n}=e,{activeProject:l,setDraft:s}=t,i=void 0!==l?["Explain the architecture of ".concat(l.name),"Find a bug in ".concat(l.name),"Write tests for ".concat(l.name)]:["Explain the architecture of this codebase","Find and fix a bug in the workspace store","Write tests for the window manager"];return(0,a.jsxs)("div",{className:"chatw-empty",children:[(0,a.jsx)("h2",{className:"chatw-empty-headline",children:"Start a Keiko conversation"}),(0,a.jsx)("p",{className:"chatw-empty-sub",children:void 0!==l?"Working in ".concat(l.name,". What would you like to explore?"):"Pick a project from the sidebar to scope your workspace, or ask anything below."}),n?null:(0,a.jsx)("div",{className:"chatw-empty-prompts","aria-label":"Starter prompts",children:i.map(e=>(0,a.jsxs)("button",{type:"button",className:"suggest",onClick:()=>s(e),children:[(0,a.jsx)(S.spark,{size:12,style:{color:"var(--accent)"}}),e]},e))})]})}function t8(){return(0,a.jsxs)("div",{className:"chatw-empty-no-chat",children:[(0,a.jsx)("div",{className:"chatw-empty-no-chat-icon","aria-hidden":"true",children:(0,a.jsx)(S.spark,{size:20})}),(0,a.jsx)("p",{className:"chatw-empty-no-chat-label",children:"Pick or start a chat"}),(0,a.jsx)("p",{className:"chatw-empty-no-chat-hint",children:"Select a conversation from the project sidebar, or create a new one to get started."})]})}function t7(e){let{session:t,ready:n}=e,{draft:l,loading:s,sending:i,sendStatus:r,cancelSend:o,setDraft:c,sendMessage:d}=t;return(0,a.jsxs)("form",{className:"composer composer-fill",onSubmit:e=>{e.preventDefault(),d()},children:[(0,a.jsxs)("div",{className:"cmp-box cmp-box-fill",children:[(0,a.jsx)("textarea",{className:"cmp-input cmp-input-mini",value:l,"aria-label":"Chat message",placeholder:s?"Loading...":"Ask Keiko...",onChange:e=>c(e.target.value),onKeyDown:tQ(d),disabled:s||i}),i?(0,a.jsx)("button",{type:"button",className:"cmp-send cmp-send-float cmp-send-cancel","data-on":!0,"aria-label":"Cancel response",title:"Cancel response",onClick:o,children:(0,a.jsx)(S.close,{size:16})}):(0,a.jsx)("button",{type:n?"submit":"button",className:"cmp-send cmp-send-float","data-on":n,"aria-disabled":!n,"aria-label":"Send message",title:"Send",children:(0,a.jsx)(S.arrowUp,{size:16})})]}),(0,a.jsx)(t3,{status:r})]})}function t9(e){let{root:t}=e;return(0,a.jsxs)("div",{className:"chat-ctx",children:[(0,a.jsx)(S.files,{size:12})," Context ",(0,a.jsxs)("span",{className:"mono",children:[t,"/"]})]})}function ne(e){var t,n;return(null==(t=e.localKnowledgeScope)?void 0:t.kind)==="capsule"?"capsule:".concat(e.localKnowledgeScope.capsuleId):(null==(n=e.localKnowledgeScope)?void 0:n.kind)==="capsule-set"?"capsule-set:".concat(e.localKnowledgeScope.capsuleSetId):void 0!==e.connectedScope?"files":"none"}function nt(e){return e instanceof $.hD?"".concat(e.code,": ").concat(e.message):e instanceof Error?e.message:"Unable to update knowledge scope."}function nn(e){let{chat:t,onChatChanged:n}=e,[s,i]=(0,l.useState)([]),[r,o]=(0,l.useState)([]),[c,d]=(0,l.useState)(!1),[u,h]=(0,l.useState)(null);async function p(e){d(!0),h(null);try{if("none"===e){let e=await (0,$.wi)(t.id,{connectedScope:null,localKnowledgeScope:null});n(e.chat);return}if("files"===e){let e=await (0,$.wi)(t.id,{localKnowledgeScope:null});n(e.chat);return}if(e.startsWith("capsule-set:")){let a=await (0,$.wi)(t.id,{connectedScope:null,localKnowledgeScope:{kind:"capsule-set",capsuleSetId:e.slice(12),connectedAtMs:Date.now()}});n(a.chat);return}if(e.startsWith("capsule:")){let a=await (0,$.wi)(t.id,{connectedScope:null,localKnowledgeScope:{kind:"capsule",capsuleId:e.slice(8),connectedAtMs:Date.now()}});n(a.chat)}}catch(e){h(nt(e))}finally{d(!1)}}(0,l.useEffect)(()=>{let e=!1;return async function(){try{let[t,n]=await Promise.allSettled([(0,tG.xr)(),(0,tG.R3)()]);if("fulfilled"!==t.status)throw t.reason;if(e)return;i(t.value.capsules.filter(e=>"ready"===e.lifecycleState)),"fulfilled"===n.status?o(n.value.capsuleSets):(o([]),h(nt(n.reason)))}catch(t){e||h(nt(t))}}(),()=>{e=!0}},[]);let m=ne(t),f=function(e,t){let n=t.map(e=>({value:"capsule:".concat(e.id),label:"Knowledge capsule: ".concat(e.displayName)})),a=ne(e);if(!a.startsWith("capsule:")||n.some(e=>e.value===a))return n;let l=a.slice(8);return[...n,{value:a,label:"Knowledge capsule: ".concat(l," (not ready)")}]}(t,s),g=function(e,t){let n=t.map(e=>({value:"capsule-set:".concat(e.id),label:"Capsule set: ".concat(e.displayName)})),a=ne(e);if(!a.startsWith("capsule-set:")||n.some(e=>e.value===a))return n;let l=a.slice(12);return[...n,{value:a,label:"Capsule set: ".concat(l," (unavailable)")}]}(t,r);return(0,a.jsxs)("label",{style:{display:"inline-flex",alignItems:"center",gap:8,flexWrap:"wrap",fontSize:12},children:[(0,a.jsx)("span",{className:"mono",style:{color:"var(--fg-dim)"},children:"Grounding"}),(0,a.jsxs)("select",{value:m,disabled:c,"aria-label":"Grounding mode",onChange:e=>{p(e.target.value)},children:[(0,a.jsx)("option",{value:"none",children:"Model only"}),(0,a.jsx)("option",{value:"files",disabled:void 0===t.connectedScope,children:"Live Files context"}),f.map(e=>(0,a.jsx)("option",{value:e.value,children:e.label},e.value)),g.map(e=>(0,a.jsx)("option",{value:e.value,children:e.label},e.value))]}),null!==u?(0,a.jsx)("span",{role:"alert",className:"scope-connect-error",children:u}):null]})}function na(e){let{chat:t,onChatChanged:n,lastGroundedBudgetStatus:l}=e;return(0,a.jsxs)("div",{className:"chat-scope-header",style:{padding:"6px 12px",display:"flex",gap:12,flexWrap:"wrap"},children:[(0,a.jsx)(ej,{chat:t,onDisconnect:n,lastGroundedBudgetStatus:l}),(0,a.jsx)(eN,{chat:t,onDisconnect:n}),(0,a.jsx)(nn,{chat:t,onChatChanged:n})]})}function nl(e){let{chat:t,answer:n,busy:l,selectedModelId:s,launchGroundedWorkflowHandoff:i}=e;if(void 0===t)return null;let r=void 0!==t.connectedScope||void 0!==t.connectedScopes&&t.connectedScopes.length>0,o=void 0!==t.localKnowledgeScope||void 0!==t.localKnowledgeScopes&&t.localKnowledgeScopes.length>0;return(r||o)&&(void 0!==n||l)?(0,a.jsxs)("div",{className:"chatw-grounded","aria-live":"polite",children:[(0,a.jsx)(eU,{answer:n,busy:l}),(0,a.jsx)(tx,{answer:n,modelId:s,busy:l,launch:i})]}):null}function ns(e){let{action:t,acceptCandidate:n,rejectCandidate:s,forgetMemoryAction:i}=e,[r,o]=(0,l.useState)(!1),[c,d]=(0,l.useState)(),[u,h]=(0,l.useState)(!1);if("candidate"===t.kind)return(0,a.jsxs)("article",{className:"chat-memory-action",children:[(0,a.jsxs)("div",{className:"chat-memory-action-head",children:[(0,a.jsx)("strong",{children:t.scopeLabel}),(0,a.jsx)("span",{children:t.requiresApproval?"Approval required":"Proposed memory"})]}),(0,a.jsx)("p",{children:t.body}),(0,a.jsxs)("div",{className:"chat-memory-action-buttons",children:[(0,a.jsx)("button",{type:"button",disabled:r,onClick:()=>{o(!0),d(void 0),n(t.proposalId).catch(e=>{d(e instanceof Error?e.message:"Unable to accept memory.")}).finally(()=>o(!1))},children:"Accept"}),(0,a.jsx)("button",{type:"button",disabled:r,onClick:()=>{o(!0),d(void 0),s(t.proposalId).catch(e=>{d(e instanceof Error?e.message:"Unable to reject memory.")}).finally(()=>o(!1))},children:"Reject"})]}),void 0!==c?(0,a.jsx)("div",{role:"alert",className:"cmp-err",children:c}):null]});if("update"===t.kind)return(0,a.jsxs)("article",{className:"chat-memory-action",children:[(0,a.jsxs)("div",{className:"chat-memory-action-head",children:[(0,a.jsx)("strong",{children:"MemoriaViva update detected"}),(0,a.jsx)("span",{children:t.memoryId})]}),(0,a.jsx)("p",{children:void 0!==t.bodyPatch?"Suggested update: ".concat(t.bodyPatch):"Suggested update."})]});if("forget"===t.kind){let e=()=>{o(!0),d(void 0),i(t.memoryId).then(()=>h(!1)).catch(e=>{d(e instanceof Error?e.message:"Unable to forget memory.")}).finally(()=>o(!1))};return(0,a.jsxs)("article",{className:"chat-memory-action",children:[(0,a.jsxs)("div",{className:"chat-memory-action-head",children:[(0,a.jsx)("strong",{children:"MemoriaViva forget detected"}),(0,a.jsx)("span",{children:t.requiresConfirmation?"Confirmation required":t.memoryId})]}),(0,a.jsx)("p",{children:"Matched memory ".concat(t.memoryId," for a forget operation.")}),(0,a.jsx)("div",{className:"chat-memory-action-buttons",children:t.requiresConfirmation?u?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",disabled:r,onClick:e,children:"Forget permanently"}),(0,a.jsx)("button",{type:"button",disabled:r,onClick:()=>{d(void 0),h(!1)},children:"Cancel"})]}):(0,a.jsx)("button",{type:"button",disabled:r,onClick:()=>{d(void 0),h(!0)},children:"Review forget"}):(0,a.jsx)("button",{type:"button",disabled:r,onClick:e,children:"Forget"})}),void 0!==c?(0,a.jsx)("div",{role:"alert",className:"cmp-err",children:c}):null]})}return(0,a.jsxs)("article",{className:"chat-memory-action",children:[(0,a.jsx)("div",{className:"chat-memory-action-head",children:(0,a.jsx)("strong",{children:"MemoriaViva action not created"})}),(0,a.jsx)("p",{children:t.reason})]})}function ni(e){var t;let{memoryEnabled:n,setMemoryEnabled:s,memoryBudgetTokens:i,setMemoryBudgetTokens:r,latestMemory:o,acceptCandidate:c,rejectCandidate:d,forgetMemoryAction:u}=e,[h,p]=(0,l.useState)(!1),m="chat-memory-disclosure",f=null!=(t=null==o?void 0:o.context.memories.length)?t:0;return(0,a.jsxs)("section",{className:"chat-memory-panel","aria-label":"Conversation memory",children:[(0,a.jsxs)("div",{className:"chat-memory-panel-head",children:[(0,a.jsxs)("div",{className:"chat-memory-toggle",children:[(0,a.jsx)(tw,{on:n,onChange:s,label:"Enable memory for the next request"}),(0,a.jsxs)("span",{children:["MemoriaViva ",n?"on":"off"]})]}),(0,a.jsxs)("label",{className:"chat-memory-budget",children:[(0,a.jsx)("span",{children:"Budget"}),(0,a.jsx)("input",{type:"number",min:0,step:100,value:i,onChange:e=>r(Math.max(0,Number(e.target.value)||0))})]}),(0,a.jsx)("button",{type:"button",className:"chip","aria-expanded":h,"aria-controls":m,onClick:()=>p(e=>!e),children:f>0?"".concat(String(f)," memories included"):"No memory included"})]}),h?(0,a.jsxs)("div",{id:m,className:"chat-memory-disclosure",children:[(0,a.jsx)("p",{className:"chat-memory-summary",children:void 0===o?"MemoriaViva disclosure appears after the next response.":o.context.enabled?"Used ".concat(String(o.context.budget.used)," of ").concat(String(o.context.budget.tokens)," MemoriaViva tokens."):"MemoriaViva was disabled for the last request."}),null==o?void 0:o.context.memories.map(e=>(0,a.jsxs)("article",{className:"chat-memory-item",children:[(0,a.jsxs)("div",{className:"chat-memory-item-head",children:[(0,a.jsx)("strong",{children:e.memoryId}),(0,a.jsx)("span",{children:e.inclusionReason})]}),(0,a.jsx)("p",{children:e.bodyExcerpt})]},e.memoryId)),null==o?void 0:o.actions.map(e=>(0,a.jsx)(ns,{action:e,acceptCandidate:c,rejectCandidate:d,forgetMemoryAction:u},"candidate"===e.kind?e.proposalId:"rejected"===e.kind?e.reason:e.memoryId))]}):null]})}function nr(e){let{mini:t=!1,linkedRoot:n=null}=e,s=r(),{messages:i,draft:o,loading:c,sending:d,sendStatus:u,error:h,noEligibleModels:p,selectedModel:m,sendMessage:f,cancelGrounded:g,activeChat:v,replaceChat:x,latestGrounded:y,latestMemory:b,lastSentDocuments:j,memoryEnabled:w,setMemoryEnabled:k,memoryBudgetTokens:N,setMemoryBudgetTokens:S,acceptMemoryCandidate:C,rejectMemoryCandidate:R,launchGroundedWorkflowHandoff:I,forgetMemoryAction:E}=s,M=o.trim().length>0&&!d&&!c&&!p,T=i.filter(e=>"user"===e.role||"assistant"===e.role&&e.content.length>0||tb(e)),q=(0,l.useRef)(null),P=function(e){if(void 0===e)return;let{usage:t,budget:n}=e,a=[ex(t.searchCalls,n.searchCallsMax),ex(t.filesRead,n.filesReadMax),ex(t.excerptBytes,n.excerptBytesMax),ex(t.modelInputTokens,n.modelInputTokensMax),ex(t.modelOutputTokens,n.modelOutputTokensMax),ex(e.elapsedMs,n.elapsedMsMax),ex(t.rerankCalls,n.rerankCallsMax)].filter(e=>void 0!==e),l=0===a.length?0:Math.max(...a),s=l>1?"exceeded":l>=.85?"high":l>=.6?"moderate":"low",i=t.modelInputTokens+t.modelOutputTokens;return{pressure:s,label:eg[s],summary:"Last grounded run: ".concat(i>=1e3?"".concat((i/1e3).toFixed(1),"k"):i.toString()," tokens, ").concat(String(t.filesRead)," files")}}(void 0===y?void 0:"connected-context"===y.groundingKind?y.contextPack:"hybrid"===y.groundingKind?y.contextPack.folder:void 0);return((0,l.useEffect)(()=>{let e=q.current;null!==e&&(e.scrollTop=e.scrollHeight)},[T.length,d]),t)?(0,a.jsxs)("div",{className:"chatw chatw-mini",children:[null!==n?(0,a.jsx)(t9,{root:n}):null,void 0!==v?(0,a.jsx)(na,{chat:v,onChatChanged:x,lastGroundedBudgetStatus:P}):null,p?(0,a.jsx)(t2,{}):null,(0,a.jsx)(t7,{session:s,ready:M})]}):(0,a.jsxs)("div",{className:"chatw",children:[null!==n?(0,a.jsx)(t9,{root:n}):null,void 0!==v?(0,a.jsx)(na,{chat:v,onChatChanged:x,lastGroundedBudgetStatus:P}):null,void 0!==v?(0,a.jsx)(ni,{memoryEnabled:w,setMemoryEnabled:k,memoryBudgetTokens:N,setMemoryBudgetTokens:S,latestMemory:b,acceptCandidate:C,rejectCandidate:R,forgetMemoryAction:E}):null,p?(0,a.jsx)("div",{className:"chatw-foot",children:(0,a.jsx)(t2,{})}):null,c?(0,a.jsx)("div",{className:"chatw-foot",children:(0,a.jsx)(t5,{})}):null,(0,a.jsx)("div",{className:"chatw-scroll",ref:q,"aria-live":"polite",children:0===T.length?void 0!==v?(0,a.jsx)(t6,{session:s,noEligibleModels:p}):(0,a.jsx)(t8,{}):(0,a.jsxs)("div",{className:"chatw-log",children:[T.map(e=>(0,a.jsx)(t$,{message:e},e.id)),d&&"streaming"!==u?(0,a.jsxs)("div",{className:"chatw-typing-row",children:[(0,a.jsx)(t0,{}),(null==v?void 0:v.connectedScope)!==void 0||(null==v?void 0:v.localKnowledgeScope)!==void 0?(0,a.jsx)("button",{type:"button",className:"grounded-cancel-btn","aria-label":"Cancel grounded request",onClick:g,children:"Cancel"}):null]}):null,(0,a.jsx)(nl,{chat:v,answer:y,busy:d,selectedModelId:m,launchGroundedWorkflowHandoff:I}),(0,a.jsx)(to,{documents:j})]})}),T.length>0?(0,a.jsx)("div",{className:"chatw-foot",children:(0,a.jsxs)("form",{className:"composer",onSubmit:e=>{e.preventDefault(),f()},children:[(0,a.jsx)(t4,{session:s,ready:M,placeholder:"Ask Keiko about your code..."}),void 0!==h?(0,a.jsx)("div",{role:"alert",className:"cmp-err",children:h}):null]})}):null,0===T.length&&void 0!==v?(0,a.jsx)("div",{className:"chatw-foot",children:(0,a.jsxs)("form",{className:"composer",onSubmit:e=>{e.preventDefault(),f()},children:[(0,a.jsx)(t4,{session:s,ready:M,placeholder:c?"Connecting to your gateway…":"Ask Keiko about your code…"}),void 0!==h?(0,a.jsx)("div",{role:"alert",className:"cmp-err",children:h}):null]})}):null,0===T.length&&void 0!==h&&void 0===v?(0,a.jsx)("div",{className:"chatw-foot",children:(0,a.jsx)("div",{role:"alert",className:"cmp-err",children:h})}):null]})}let no=["n","s","e","w","ne","nw","se","sw"],nc=["t","r","b","l"];function nd(e){let{icon:t,label:n}=e,l=S[t];return(0,a.jsxs)("div",{className:"too-small",children:[(0,a.jsx)("div",{className:"ts-ico",children:(0,a.jsx)(l,{size:28})}),(0,a.jsxs)("div",{className:"ts-title",children:["Too small to show ",n]}),(0,a.jsx)("div",{className:"ts-sub",children:"Enlarge the window or zoom out"}),(0,a.jsx)("div",{className:"ts-arrow","aria-hidden":"true",children:(0,a.jsx)("svg",{width:"22",height:"22",viewBox:"0 0 22 22",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:(0,a.jsx)("path",{d:"M8 8l8 8M16 11v5h-5"})})})]})}function nu(e){var t,n;let{win:s,top:i,connState:r,view:o,api:c,wsRef:d}=e,u=es[s.type],h=S[u.icon],p=null!=(n=s.zoom)?n:1,m="chat"===s.type||"agents"===s.type||"quality"===s.type?c.linkedFilesRoot(s.id):null,f="agents"===s.type||"quality"===s.type?null==(t=c.linkedFilesContext(s.id))?void 0:t.activeFilePath:void 0,g="quality"===s.type?c.linkedAllFilesRoots(s.id):null!==m?[m]:[],v="quality"===s.type?c.linkedConnectorCapsuleIds(s.id):[],x="quality"===s.type?c.linkedConnectorCapsuleSetIds(s.id):[],y="quality"===s.type?c.linkedFigmaSnapshotRunIds(s.id):[],b=s.w/p,j=s.h/p,w=(0,l.useCallback)(e=>{c.update(s.id,{cfg:{...s.cfg,...e}})},[c,s.cfg,s.id]),k=(0,l.useCallback)((e,t)=>c.add(e,t),[c]),{mode:N,node:C}=function(e,t,n,l,s,i,r,o,c,d,u,h){if("chat"===e){let e=t<430||n<430;return{mode:e?"mini":"full",node:(0,a.jsx)(nr,{mini:e,linkedRoot:s})}}let p=es[e];return t<p.tiny.w||n<p.tiny.h?{mode:"tiny",node:(0,a.jsx)(nd,{icon:p.icon,label:p.title})}:{mode:"full",node:p.render(l,{linkedRoot:s,linkedFilePath:i,linkedRoots:r,linkedCapsuleIds:o,linkedCapsuleSetIds:c,linkedFigmaSnapshotRunIds:d,updateCfg:u,openWindow:h})}}(s.type,b,j,s.cfg,m,f,g,v,x,y,w,k),R=(0,l.useCallback)(e=>c.update(s.id,{zoom:Math.max(.5,Math.min(2,Math.round(10*e)/10))}),[c,s.id]),I=(0,l.useCallback)(e=>{var t,n,a,l;if(0!==e.button||"valid"===r)return;e.preventDefault(),c.focus(s.id);let i=d.current;if(null===i)return;let u=function(e,t){let n=t.zoom;return{z:n,vpx0:-t.x/n,vpy0:-t.y/n,vpw:e.width/n,vph:e.height/n,toWX:a=>(a-e.left-t.x)/n,toWY:a=>(a-e.top-t.y)/n}}(i.getBoundingClientRect(),o),h=s.max,p=h?null!=(a=null==(t=s.prev)?void 0:t.w)?a:480:s.w,m=h?null!=(l=null==(n=s.prev)?void 0:n.h)?l:360:s.h,f=h?p/2:u.toWX(e.clientX)-s.x,g=h?18:u.toWY(e.clientY)-s.y;h&&c.update(s.id,{max:!1,w:p,h:m}),function(e,t,n){let a=30/t.z,l=l=>{let s=t.toWX(l.clientX),i=t.toWY(l.clientY),r=s-n.offX,o=i-n.offY;r=Math.max(t.vpx0-(n.W-120),Math.min(t.vpx0+t.vpw-120,r)),o=Math.max(t.vpy0,Math.min(t.vpy0+t.vph-38,o)),e.setSnap(function(e,t,n,a){let l=e-n.vpx0<a,s=n.vpx0+n.vpw-e<a,i=t-n.vpy0<a,r=n.vpy0+n.vph-t<a;return i&&l?"tl":i&&s?"tr":r&&l?"bl":r&&s?"br":l?"left":s?"right":i?"maxi":null}(s,i,t,a)),e.update(n.winId,{x:r,y:o})},s=()=>{window.removeEventListener("pointermove",l),window.removeEventListener("pointerup",s),e.commitSnap(n.winId),document.body.style.cursor=""};window.addEventListener("pointermove",l),window.addEventListener("pointerup",s)}(c,u,{winId:s.id,offX:f,offY:g,W:p})},[c,s.id,s.x,s.y,s.w,s.h,s.max,s.prev,o,d,r]),E=(0,l.useCallback)(e=>t=>{t.preventDefault(),t.stopPropagation(),c.focus(s.id);let n={x:s.x,y:s.y,w:s.w,h:s.h},a=t.clientX,l=t.clientY,i=o.zoom,r=t=>{let r=function(e,t,n,a,l){let{x:s,y:i,w:r,h:o}=e;t.includes("e")&&(r=e.w+n),t.includes("s")&&(o=e.h+a),t.includes("w")&&(r=e.w-n,s=e.x+n),t.includes("n")&&(o=e.h-a,i=e.y+a);let c=es[l].min,d=c.w>0?c.w:240,u=c.h>0?c.h:150;return r<d&&(t.includes("w")&&(s-=d-r),r=d),o<u&&(t.includes("n")&&(i-=u-o),o=u),{x:s,y:i,w:r,h:o}}(n,e,(t.clientX-a)/i,(t.clientY-l)/i,s.type);c.update(s.id,{...r,max:!1})},d=()=>{window.removeEventListener("pointermove",r),window.removeEventListener("pointerup",d),document.body.style.cursor=""};document.body.style.cursor="n"===e||"s"===e?"ns-resize":"e"===e||"w"===e?"ew-resize":"ne"===e||"sw"===e?"nesw-resize":"nwse-resize",window.addEventListener("pointermove",r),window.addEventListener("pointerup",d)},[c,s.id,s.x,s.y,s.w,s.h,s.type,o.zoom]),M=(0,l.useCallback)((e,t)=>{let n=e.getBoundingClientRect();c.startConnect(s.id,{clientX:"clientX"in t?t.clientX:n.left+n.width/2,clientY:"clientY"in t?t.clientY:n.top+n.height/2,preventDefault:()=>t.preventDefault(),stopPropagation:()=>t.stopPropagation()})},[c,s.id]),T=(0,l.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),M(e.currentTarget,e)},[M]),q=(0,l.useCallback)(e=>{("Enter"===e.key||" "===e.key||"Spacebar"===e.key)&&(e.preventDefault(),e.stopPropagation(),M(e.currentTarget,e))},[M]),P="full"===N?function(e,t){if(void 0===t)return null;let n=e=>{let n=t[e];return"string"==typeof n&&n.length>0?n:null};switch(e){case"files":return n("root");case"browser":return n("url");case"editor":return n("file");case"terminal":return n("cwd");case"review":{let e=n("base"),t=n("head");return null!==e&&null!==t?"".concat(e," → ").concat(t):null}case"agents":return n("role");case"chat":{let e=n("title");return null!==e&&"New chat"!==e?e:null}default:return null}}(s.type,s.cfg):null,A={left:s.x,top:s.y,width:s.w,height:s.h,zIndex:s.z};return(0,a.jsxs)("section",{className:"window","data-top":i?"true":"false","data-max":s.max?"true":"false","data-conn":null!=r?r:void 0,"data-window-id":s.id,style:A,onPointerDown:e=>{"valid"===r&&c.confirmConnect(s.id,e),c.focus(s.id)},children:[(0,a.jsxs)("header",{className:"win-head",onPointerDown:I,onDoubleClick:()=>c.maximize(s.id),children:[(0,a.jsx)("span",{className:"win-ico",style:{color:!0===u.accent?"var(--accent)":"var(--fg-muted)"},children:(0,a.jsx)(h,{size:14})}),(0,a.jsx)("span",{className:"win-title",children:u.title}),null!==P?(0,a.jsx)("span",{className:"win-sub mono",children:P}):null,(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("div",{className:"win-zoom",children:[(0,a.jsx)("button",{type:"button",className:"win-zbtn",title:"Zoom content out","aria-label":"Zoom content out",onPointerDown:e=>e.stopPropagation(),onClick:()=>R(p-.1),children:(0,a.jsx)(S.zoomOut,{size:13})}),(0,a.jsxs)("button",{type:"button",className:"win-zpct",title:"Reset zoom","aria-label":"Reset content zoom",onPointerDown:e=>e.stopPropagation(),onClick:()=>c.update(s.id,{zoom:1}),children:[Math.round(100*p),"%"]}),(0,a.jsx)("button",{type:"button",className:"win-zbtn",title:"Zoom content in","aria-label":"Zoom content in",onPointerDown:e=>e.stopPropagation(),onClick:()=>R(p+.1),children:(0,a.jsx)(S.zoomIn,{size:13})})]}),(0,a.jsx)("button",{type:"button",className:"win-btn",title:s.max?"Restore":"Maximize","aria-label":s.max?"Restore window":"Maximize window",onPointerDown:e=>e.stopPropagation(),onClick:()=>c.maximize(s.id),children:s.max?(0,a.jsx)(S.restore,{size:13}):(0,a.jsx)(S.maximize,{size:13})}),(0,a.jsx)("button",{type:"button",className:"win-btn win-close",title:"Close","aria-label":"Close window",onPointerDown:e=>e.stopPropagation(),onClick:()=>c.close(s.id),children:(0,a.jsx)(S.close,{size:14})})]}),(0,a.jsx)("div",{className:"win-body","data-mode":N,style:"tiny"===N?{}:{zoom:p},children:C}),s.max?null:no.map(e=>(0,a.jsx)("div",{className:"wz wz-".concat(e),onPointerDown:E(e)},e)),s.max?null:nc.map(e=>(0,a.jsx)("div",{className:"win-port wp-".concat(e),title:"Click to connect to another card","aria-label":"Connect from ".concat("t"===e?"top":"r"===e?"right":"b"===e?"bottom":"left"," edge"),role:"button",tabIndex:0,onPointerDown:T,onKeyDown:q},"p".concat(e)))]})}function nh(e){var t;let{ws:n,wsRef:s,openPalette:i,palette:r}=e,{wins:o,view:c,snapPrev:d,conns:u,connecting:h,api:p}=n,m=function(e){if(null===e||0===e.length)return null;let t=e[0];for(let n=1;n<e.length;n++){let a=e[n];a.z>t.z&&(t=a)}return t}(o),f=null!==h&&null!==o&&null!=(t=o.find(e=>e.id===h.from))?t:null,g=(0,l.useMemo)(()=>({backgroundSize:"".concat(String(22*c.zoom),"px ").concat(String(22*c.zoom),"px"),backgroundPosition:"".concat(String(c.x),"px ").concat(String(c.y),"px")}),[c]),v=(0,l.useMemo)(()=>({transform:"translate(".concat(String(c.x),"px, ").concat(String(c.y),"px)"),transformOrigin:"0 0",zoom:c.zoom}),[c]),x=null!==o&&0===o.length;return(0,a.jsxs)("main",{className:"workspace",ref:s,"aria-label":"Workspace surface","data-connecting":null!==h?"true":void 0,onPointerDownCapture:e=>{if(0!==e.button||null===h||null===f||null===o)return;let t=function(e){if(!(e instanceof Element))return;let t=e.closest(".window[data-window-id]");return null==t?void 0:t.dataset.windowId}(e.target);if(void 0===t||t===f.id)return;let n=o.find(e=>e.id===t);void 0!==n&&V(f.type,n.type)&&p.confirmConnect(n.id,e)},onPointerDown:e=>{var t;if(0===e.button&&!((t=e.target)instanceof Element&&(null!==t.closest(".window")||null!==t.closest(".ws-zoom")||null!==t.closest(".ws-fab")||null!==t.closest(".conn-badge")))){if(null!==h)return void p.cancelConnect();!function(e,t){let n=t.clientX,a=t.clientY;document.body.style.cursor="grabbing";let l=t=>{e(t.clientX-n,t.clientY-a),n=t.clientX,a=t.clientY},s=()=>{window.removeEventListener("pointermove",l),window.removeEventListener("pointerup",s),document.body.style.cursor=""};window.addEventListener("pointermove",l),window.addEventListener("pointerup",s)}(p.panBy,e)}},children:[(0,a.jsx)(H,{}),(0,a.jsx)("div",{className:"ws-grid",style:g,"aria-hidden":"true"}),x?(0,a.jsxs)("div",{className:"ws-empty",children:[(0,a.jsx)("img",{className:"ws-empty-logo",src:"/assets/keiko-logo.svg",alt:""}),(0,a.jsx)("div",{className:"ws-empty-title",children:"Empty workspace"}),(0,a.jsx)("div",{className:"ws-empty-sub",children:"Open a window to start working"}),(0,a.jsxs)("button",{type:"button",className:"ws-empty-btn",onClick:i,children:[(0,a.jsx)(S.add,{size:15})," New window"]})]}):null,(0,a.jsxs)("div",{className:"ws-scene",style:v,children:[null!==d?(0,a.jsx)("div",{className:"snap-ghost",style:{left:d.x,top:d.y,width:d.w,height:d.h}}):null,null!==o?(0,a.jsx)(Q,{wins:o,conns:u,connecting:h,api:p}):null,null!==o?o.map(e=>(0,a.jsx)(nu,{win:e,top:null!==m&&e.id===m.id,connState:null===f?null:e.id===f.id?"source":V(f.type,e.type)?"valid":"invalid",view:c,api:p,wsRef:s},e.id)):null]}),(0,a.jsxs)("div",{className:"ws-zoom",children:[(0,a.jsx)("button",{type:"button",className:"ws-zoom-btn",onClick:()=>p.zoomTo(c.zoom-.2),"aria-label":"Zoom out",title:"Zoom out",children:(0,a.jsx)(S.zoomOut,{size:15})}),(0,a.jsxs)("button",{type:"button",className:"ws-zoom-pct mono",onClick:p.resetView,"aria-label":"Reset view",title:"Reset view",children:[Math.round(100*c.zoom),"%"]}),(0,a.jsx)("button",{type:"button",className:"ws-zoom-btn",onClick:()=>p.zoomTo(c.zoom+.2),"aria-label":"Zoom in",title:"Zoom in",children:(0,a.jsx)(S.zoomIn,{size:15})})]}),(0,a.jsx)("button",{type:"button",className:"ws-fab",onPointerDown:e=>e.stopPropagation(),onClick:i,"aria-label":"New window",title:"New window",children:(0,a.jsx)(S.add,{size:20})}),null!=r?r:null]})}function np(e){let{commands:t,onClose:n}=e,[s,i]=(0,l.useState)(""),[r,o]=(0,l.useState)(0),c=(0,l.useRef)(null),d=(0,l.useRef)(null),u=(0,l.useRef)(null);(0,l.useEffect)(()=>(d.current=document.activeElement,()=>{var e,t;null==(t=d.current)||null==(e=t.focus)||e.call(t)}),[]),(0,l.useEffect)(()=>{var e;null==(e=c.current)||e.focus()},[]);let h=(0,l.useMemo)(()=>{let e=s.toLowerCase();return t.filter(t=>{var n;return"".concat(t.label," ").concat(null!=(n=t.group)?n:"").toLowerCase().includes(e)})},[t,s]);(0,l.useEffect)(()=>{o(0)},[s]);let p=e=>{void 0!==e&&(e.run(),n())};return(0,a.jsx)("div",{className:"cmdk-overlay",onPointerDown:n,children:(0,a.jsxs)("div",{ref:u,className:"cmdk",role:"dialog","aria-modal":"true","aria-labelledby":"cmdk-title","aria-describedby":"cmdk-desc",onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{if("Tab"===e.key){var t,a;let n=Array.from(null!=(a=null==(t=u.current)?void 0:t.querySelectorAll("button:not([disabled]),input:not([disabled]),[tabindex]:not([tabindex='-1'])"))?a:[]);if(n.length>0){let t=n[0],a=n[n.length-1];if(e.shiftKey&&document.activeElement===t){e.preventDefault(),a.focus();return}if(!e.shiftKey&&document.activeElement===a){e.preventDefault(),t.focus();return}}}if("ArrowDown"===e.key){e.preventDefault(),o(e=>Math.min(h.length-1,e+1));return}if("ArrowUp"===e.key){e.preventDefault(),o(e=>Math.max(0,e-1));return}if("Enter"===e.key){e.preventDefault(),p(h[r]);return}"Escape"===e.key&&n()},children:[(0,a.jsx)("h2",{id:"cmdk-title",className:"sr-only",children:"Command palette"}),(0,a.jsx)("p",{id:"cmdk-desc",className:"sr-only",children:"Search commands and press Enter to run the selected action."}),(0,a.jsxs)("div",{className:"cmdk-input",children:[(0,a.jsx)(S.search,{size:16}),(0,a.jsx)("input",{ref:c,role:"combobox","aria-expanded":"true","aria-controls":"cmdk-list","aria-activedescendant":h.length>0?"cmdk-row-".concat(String(r)):void 0,"aria-label":"Command query",placeholder:"Type a command…",value:s,onChange:e=>i(e.target.value)}),(0,a.jsx)("span",{className:"kbd",children:"esc"})]}),(0,a.jsxs)("div",{id:"cmdk-list",role:"listbox",className:"cmdk-list",children:[0===h.length&&(0,a.jsx)("div",{className:"cmdk-empty",children:"No matching commands"}),h.map((e,t)=>(0,a.jsxs)("div",{role:"option",id:"cmdk-row-".concat(String(t)),"aria-selected":t===r,className:"cmdk-row","data-sel":t===r,tabIndex:-1,onMouseEnter:()=>o(t),onClick:()=>p(e),children:[(0,a.jsx)("span",{className:"cmdk-ico",children:function(e){var t;let n=null!=(t=S[e])?t:S.spark;return(0,a.jsx)(n,{size:16})}(e.icon)}),(0,a.jsx)("span",{className:"cmdk-label",children:e.label}),(0,a.jsx)("span",{className:"spacer"}),void 0!==e.group&&(0,a.jsx)("span",{className:"cmdk-group mono",children:e.group})]},e.id))]})]})})}var nm=n(7509);function nf(e){let{onCancel:t}=e,n=(0,l.useRef)(null),s=(0,l.useRef)(null),i=(0,l.useRef)(null),[r,o]=(0,l.useState)(""),[c,d]=(0,l.useState)(""),[u,h]=(0,l.useState)(""),[p,m]=(0,l.useState)(""),[f,g]=(0,l.useState)(!1),[v,x]=(0,l.useState)(),[y,b]=(0,l.useState)();async function j(e){if(e.preventDefault(),!f){g(!0),x(void 0),b(void 0);try{let e=Array.from(new Set(p.split(/[\n,]/u).map(e=>e.trim()).filter(e=>e.length>0)));if(function(e){try{return new URL(e.trim()).hostname.endsWith(".services.ai.azure.com")}catch(e){return!1}}(r)&&0===e.length){x("Azure AI Foundry requires deployment names. Paste the names from the Deployments tab."),g(!1);return}let t=(await (0,$.qe)({baseUrl:r,apiKey:c,apiKeyHeaderName:""===u.trim()?void 0:u.trim(),deploymentNames:e})).testedModelIds.length;b("Verified ".concat(String(t)," workflow chat model").concat(1===t?"":"s",". Reloading Keiko...")),window.setTimeout(()=>window.location.reload(),800)}catch(e){x(e instanceof $.hD?"".concat(e.code,": ").concat(e.message):e instanceof Error?e.message:"The gateway could not be configured."),g(!1)}}}(0,l.useEffect)(()=>{var e;return i.current=document.activeElement,null==(e=s.current)||e.focus(),()=>{var e,t;null==(t=i.current)||null==(e=t.focus)||e.call(t)}},[]),(0,l.useEffect)(()=>{let e=n.current;if(null===e)return;let a=n=>{if("Escape"===n.key){if(f||void 0!==y||void 0===t)return;n.preventDefault(),t();return}if("Tab"!==n.key)return;let a=Array.from(e.querySelectorAll("button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex='-1'])"));if(0===a.length)return;let l=a[0],s=a[a.length-1];n.shiftKey&&document.activeElement===l?(n.preventDefault(),s.focus()):n.shiftKey||document.activeElement!==s||(n.preventDefault(),l.focus())};return e.addEventListener("keydown",a),()=>e.removeEventListener("keydown",a)},[f,t,y]);let w=(0,a.jsx)("div",{className:"gw-setup-backdrop",role:"presentation",children:(0,a.jsx)("div",{ref:n,className:"gw-setup",role:"dialog","aria-modal":"true","aria-labelledby":"gw-setup-title","aria-describedby":"gw-setup-desc",children:(0,a.jsxs)("form",{onSubmit:e=>void j(e),children:[(0,a.jsxs)("div",{className:"gw-setup-badge",children:[(0,a.jsx)(S.cube,{size:18}),"Model gateway setup"]}),(0,a.jsx)("h1",{id:"gw-setup-title",children:"Connect Keiko to your internal LLMs"}),(0,a.jsx)("p",{id:"gw-setup-desc",children:"Keiko needs the internal gateway URL and API token before chat and agent workflows can run. The token is tested once and stored only on this machine."}),(0,a.jsxs)("label",{className:"gw-field",children:[(0,a.jsx)("span",{children:"Base URL"}),(0,a.jsx)("input",{className:"gw-input mono",value:r,placeholder:"https://llm-gateway.example.com/v1",autoComplete:"off",disabled:f||void 0!==y,ref:s,onChange:e=>o(e.target.value)})]}),(0,a.jsxs)("label",{className:"gw-field",children:[(0,a.jsx)("span",{children:"API token"}),(0,a.jsx)("input",{className:"gw-input mono",type:"password",value:c,placeholder:"Paste your API token",autoComplete:"off",disabled:f||void 0!==y,onChange:e=>d(e.target.value)})]}),(0,a.jsxs)("label",{className:"gw-field",children:[(0,a.jsx)("span",{children:"API key header optional"}),(0,a.jsx)("input",{className:"gw-input mono",value:u,placeholder:"Authorization",autoComplete:"off",disabled:f||void 0!==y,onChange:e=>h(e.target.value)})]}),(0,a.jsxs)("label",{className:"gw-field",children:[(0,a.jsx)("span",{children:"Deployment names for Azure"}),(0,a.jsx)("textarea",{className:"gw-input gw-textarea mono",value:p,placeholder:"Paste deployment names, one per line",autoComplete:"off",disabled:f||void 0!==y,onChange:e=>m(e.target.value)})]}),(0,a.jsx)("div",{className:"gw-note",children:"Leave the header field empty unless your gateway admin gave you a custom API-key header, for example X-Litellm-Key. Supported headers are Authorization, X-Litellm-Key, X-Api-Key, and api-key. Leave deployment names empty only for OpenAI-compatible gateways with model discovery. For Azure AI Foundry, paste deployment names exactly as shown in the Deployments tab. Testing several deployments can take up to 30 seconds."}),void 0!==v?(0,a.jsx)("div",{className:"gw-error",children:v}):null,void 0!==y?(0,a.jsx)("div",{className:"gw-success",children:y}):null,(0,a.jsxs)("div",{className:"gw-actions",children:[void 0!==t?(0,a.jsx)("button",{className:"gw-cancel",type:"button",disabled:f||void 0!==y,onClick:t,children:"Cancel"}):null,(0,a.jsx)("button",{className:"gw-submit",type:"submit",disabled:f||void 0!==y||""===r.trim()||""===c.trim(),children:f?"Testing connection...":"Test & save"})]})]})})});return"undefined"==typeof document?w:(0,nm.createPortal)(w,document.body)}let ng=[["ask","Ask every action"],["full","Full access"]];function nv(e){let{cfg:t,set:n}=e,l=!1!==t.keikoMode,s="full"===t.access?"full":"ask",i=l?"No rights by default. You approve while manual; Keiko governs per policy when autonomous.":"full"===s?"Legacy: agent acts without prompts.":"Legacy: you approve each privileged action.";return(0,a.jsxs)("div",{className:"permctl",children:[(0,a.jsxs)("button",{type:"button",className:"perm-toggle","data-on":l,"aria-pressed":l,onClick:()=>n("keikoMode",!l),children:[(0,a.jsx)("img",{className:"perm-orca",src:"/assets/keiko-logo.svg",alt:""}),(0,a.jsxs)("span",{className:"perm-tt",children:[(0,a.jsx)("span",{className:"perm-name",children:"Keiko-Mode"}),(0,a.jsx)("span",{className:"perm-desc",children:"Zero standing rights \xb7 Keiko governs"})]}),(0,a.jsx)("span",{className:"perm-sw"+(l?" on":""),children:(0,a.jsx)("span",{})})]}),!l&&(0,a.jsx)("div",{className:"perm-legacy",children:ng.map(e=>{let[t,l]=e;return(0,a.jsx)("button",{type:"button",className:"perm-opt","data-on":s===t,"aria-pressed":s===t,onClick:()=>n("access",t),children:l},t)})}),(0,a.jsx)("div",{className:"perm-note",children:i})]})}function nx(e){if(e instanceof $.hD){if("BAD_ROOT"===e.code)return"Enter an absolute folder path.";if("DENIED"===e.code)return"That location is excluded."}return e instanceof Error?e.message:"Unable to read directories."}function ny(e){let{value:t,projectId:n,selectProjectRoot:s=!1,onSelect:i,onClose:r}=e,[o,c]=(0,l.useState)(null),[d,u]=(0,l.useState)(t),[h,p]=(0,l.useState)(!1),[m,f]=(0,l.useState)(null),g=null!=n?n:t.trim(),v=(0,l.useCallback)(async e=>{if(0===g.length){c(null),f("Enter an absolute folder path.");return}p(!0),f(null);try{let t=await (0,$.xe)(g,e);c(t),u(t.path)}catch(e){f(nx(e))}finally{p(!1)}},[g]);return(0,l.useEffect)(()=>{v(t.length>0?t:void 0)},[v,t]),(0,a.jsxs)("div",{className:"dir-picker",role:"group","aria-label":"Directory picker",children:[(0,a.jsxs)("div",{className:"dir-top",children:[(0,a.jsx)("input",{className:"dlg-input mono dir-path",value:d,onChange:e=>u(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),v(d))}}),(0,a.jsx)("button",{type:"button",className:"dlg-btn dir-go",onClick:()=>void v(d),children:"Go"})]}),null!==o?(0,a.jsx)("div",{className:"dir-roots",children:o.roots.map(e=>(0,a.jsx)("button",{type:"button",className:"dir-chip",onClick:()=>void v(e.path),children:e.label},"".concat(e.label,":").concat(e.path)))}):null,(0,a.jsxs)("div",{className:"dir-list",children:[(null==o?void 0:o.parent)!==null&&(null==o?void 0:o.parent)!==void 0?(0,a.jsxs)("button",{type:"button",className:"dir-row",onClick:()=>{var e;v(null!=(e=o.parent)?e:void 0)},children:[(0,a.jsx)(S.back,{size:14}),(0,a.jsx)("span",{children:"Parent directory"})]}):null,null==o?void 0:o.entries.map(e=>(0,a.jsxs)("button",{type:"button",className:"dir-row",onClick:()=>void v(e.path),children:[(0,a.jsx)(S.folder,{size:14}),(0,a.jsx)("span",{children:e.name})]},e.path)),h?(0,a.jsx)("div",{className:"dir-note",children:"Loading directories..."}):null,h||null===o||0!==o.entries.length?null:(0,a.jsx)("div",{className:"dir-note",children:"No child directories."}),null!==m?(0,a.jsx)("div",{className:"dir-error",children:m}):null]}),(0,a.jsxs)("div",{className:"dir-actions",children:[(0,a.jsx)("button",{type:"button",className:"dlg-btn",onClick:r,children:"Close"}),(0,a.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",onClick:()=>{if(null!==o){var e,t;i(s&&null!=(t=null==(e=o.roots[0])?void 0:e.path)?t:o.path),r()}},disabled:null===o,children:"Use directory"})]})]})}let nb=[{id:"verify",label:"Verify"},{id:"explain-plan",label:"Explain plan"},{id:"unit-test-generation",label:"Generate unit tests"},{id:"bug-investigation",label:"Investigate bug"}];function nj(e){return e.filter(e=>e.available).map(e=>e.path)}function nw(e){return e.split(/[\n,]/u).map(e=>e.trim()).filter(e=>e.length>0)}function nk(e){return e.replaceAll("\\","/")}function nN(e,t){let n=nk(t.trim());if(0===n.length)return"";let a=nk(e.trim()).replace(/\/+$/u,"");if(0===a.length)return n;if(n===a)return".";let l="".concat(a,"/");return n.startsWith(l)?n.slice(l.length):n}function nS(e,t){return nw(t).map(t=>nN(e,t)).join(", ")}function nC(e){var t;let{filesContext:n,firstRef:s,directoryField:i,setDirectoryField:r,setDialogError:o,onConfirm:c}=e,[d,u]=(0,l.useState)("verify"),[h,p]=(0,l.useState)(null!=(t=null==n?void 0:n.root)?t:""),[m,f]=(0,l.useState)(""),[g,v]=(0,l.useState)([]),[x,y]=(0,l.useState)([]),[b,j]=(0,l.useState)(()=>{var e,t;return function(e,t){let n=null===t?"":nN(e,t);return{verifyTargetFiles:n,explainFilePath:n,explainQuestion:"",unitTargetKind:"file",unitFilePath:n,unitModuleDir:"",unitFilePaths:n,bugDescription:"",bugFailingOutput:"",bugStackTrace:"",bugTargetFiles:n}}(null!=(e=null==n?void 0:n.root)?e:"",null!=(t=null==n?void 0:n.activeFilePath)?t:null)}),[w,k]=(0,l.useState)(!0),[N,C]=(0,l.useState)(!1),[R,I]=(0,l.useState)(!1),E=h.trim(),M=null!==n&&n.root===E&&void 0!==n.activeFilePath?n.activeFilePath:null,T=E.length>0&&x.includes(E),q=function(e,t,n,a){if(0===t.length)return"Workspace is required.";if(0===n.length)return"No model is available.";if("explain-plan"===e&&0===a.explainFilePath.trim().length)return"Explain plan requires a filePath.";if("unit-test-generation"===e){if("file"===a.unitTargetKind&&0===a.unitFilePath.trim().length)return"Unit test generation requires a filePath.";if("module"===a.unitTargetKind&&0===a.unitModuleDir.trim().length)return"Unit test generation requires a moduleDir.";if("changedFiles"===a.unitTargetKind&&0===nw(a.unitFilePaths).length)return"Unit test generation requires at least one filePath."}return"bug-investigation"!==e||a.bugDescription.trim().length>0||a.bugFailingOutput.trim().length>0||a.bugStackTrace.trim().length>0||nw(a.bugTargetFiles).length>0?null:"Bug investigation requires description, output, stack trace, or target files."}(d,E,m,b),P=null===q&&T&&!R&&!w;(0,l.useEffect)(()=>{let e=!1;return k(!0),o(null),Promise.all([(0,$.ZC)(),(0,$.vj)()]).then(t=>{let[n,a]=t;if(e)return;let l=n.models.filter(tu);v(l),f(e=>{var t,n;return e||(null!=(n=null==(t=l[0])?void 0:t.id)?n:"")}),y(nj(a.projects))}).catch(t=>{e||o(nx(t))}).finally(()=>{e||k(!1)}),()=>{e=!0}},[o]);let A=e=>{j(t=>({...t,...e}))};(0,l.useEffect)(()=>{if(null===M)return;let e=nN(E,M);j(t=>{let n={};return 0===t.verifyTargetFiles.trim().length&&(n.verifyTargetFiles=e),0===t.explainFilePath.trim().length&&(n.explainFilePath=e),0===t.unitFilePath.trim().length&&(n.unitFilePath=e),0===t.unitFilePaths.trim().length&&(n.unitFilePaths=e),0===t.bugTargetFiles.trim().length&&(n.bugTargetFiles=e),0===Object.keys(n).length?t:{...t,...n}})},[M,E]);let z=async()=>{y(nj((await (0,$.vj)()).projects))},D=async()=>{if(0!==E.length){C(!0),o(null);try{await (0,$.gA)({path:E}),await z()}catch(e){o(nx(e))}finally{C(!1)}}},L=async()=>{if(!P)return void o(null!=q?q:"Workspace is not registered.");I(!0),o(null);let e=function(e,t,n,a){if("verify"===e){let e=nw(a.verifyTargetFiles).map(e=>nN(t,e));return{taskType:"verify",modelId:n,input:{workspaceRoot:t,...e.length>0?{targetFiles:e}:{}}}}if("explain-plan"===e)return{taskType:"explain-plan",modelId:n,input:{workspaceRoot:t,filePath:nN(t,a.explainFilePath),...a.explainQuestion.trim().length>0?{question:a.explainQuestion.trim()}:{}}};if("unit-test-generation"===e){let e=nw(a.unitFilePaths).map(e=>nN(t,e)),l="module"===a.unitTargetKind?{kind:"module",moduleDir:nN(t,a.unitModuleDir)}:"changedFiles"===a.unitTargetKind?{kind:"changedFiles",filePaths:e}:{kind:"file",filePath:nN(t,a.unitFilePath)};return{workflowId:"unit-test-generation",modelId:n,input:{workspaceRoot:t,target:l}}}return{workflowId:"bug-investigation",modelId:n,input:{workspaceRoot:t,report:{...a.bugDescription.trim().length>0?{description:a.bugDescription.trim()}:{},...a.bugFailingOutput.trim().length>0?{failingOutput:a.bugFailingOutput.trim()}:{},...a.bugStackTrace.trim().length>0?{stackTrace:a.bugStackTrace.trim()}:{},...nw(a.bugTargetFiles).length>0?{targetFiles:nw(a.bugTargetFiles).map(e=>nN(t,e))}:{}}}}}(d,E,m,b);try{let t=await (0,$.AD)(e);c({workflow:d,model:m,runId:t.runId,fingerprint:t.fingerprint,workspaceRoot:E,inputJson:JSON.stringify(e.input),...null!==n&&n.root===E?{__connectFilesId:n.id}:{}})}catch(e){e instanceof $.hD&&"WORKSPACE_NOT_REGISTERED"===e.code?(await z().catch(()=>void 0),o("Workspace is not registered.")):o(nx(e))}finally{I(!1)}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"Workflow"}),(0,a.jsxs)("span",{className:"dlg-selwrap",children:[(0,a.jsx)("select",{ref:s,className:"dlg-input mono",value:d,onChange:e=>u(e.target.value),children:nb.map(e=>(0,a.jsx)("option",{value:e.id,children:e.label},e.id))}),(0,a.jsx)("span",{className:"dlg-selchev",children:(0,a.jsx)(S.chevron,{size:15})})]})]}),(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"Workspace"}),(0,a.jsxs)("span",{className:"dlg-dirwrap",children:[(0,a.jsx)("input",{className:"dlg-input mono",value:h,placeholder:"/absolute/project/path",onClick:()=>r("agentWorkspace"),onChange:e=>p(e.target.value)}),(0,a.jsx)("button",{type:"button",className:"dlg-dirbtn",onClick:()=>r("agentWorkspace"),children:"Browse"})]}),"agentWorkspace"===i?(0,a.jsx)(ny,{value:h,projectId:T?E:void 0,onSelect:p,onClose:()=>r(null)}):null]}),E.length>0&&!T?(0,a.jsxs)("div",{className:"dlg-agent-warning",children:[(0,a.jsx)("span",{children:"Workspace is not registered."}),(0,a.jsx)("button",{type:"button",className:"dlg-btn",disabled:N,onClick:()=>void D(),children:N?"Registering...":"Register workspace"})]}):null,(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"Model"}),(0,a.jsxs)("span",{className:"dlg-selwrap",children:[(0,a.jsx)("select",{className:"dlg-input mono",value:m,onChange:e=>f(e.target.value),disabled:0===g.length,children:g.map(e=>(0,a.jsx)("option",{value:e.id,children:e.id},e.id))}),(0,a.jsx)("span",{className:"dlg-selchev",children:(0,a.jsx)(S.chevron,{size:15})})]})]}),null!==M?(0,a.jsxs)("button",{type:"button",className:"dlg-current-file",onClick:()=>{if(null===M)return;let e=nN(E,M);"verify"===d?A({verifyTargetFiles:e}):"explain-plan"===d?A({explainFilePath:e}):"unit-test-generation"===d?"changedFiles"===b.unitTargetKind?A({unitFilePaths:e}):A({unitTargetKind:"file",unitFilePath:e}):A({bugTargetFiles:e})},children:[(0,a.jsx)(S.files,{size:13})," Use current file ",(0,a.jsx)("span",{className:"mono",children:M})]}):null,"verify"===d?(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:["Target files ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,placeholder:"src/file.ts, src/other.ts",value:b.verifyTargetFiles,onChange:e=>A({verifyTargetFiles:e.target.value}),onBlur:e=>A({verifyTargetFiles:nS(E,e.target.value)})})]}):"explain-plan"===d?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"filePath"}),(0,a.jsx)("input",{className:"dlg-input mono",placeholder:"src/file.ts",value:b.explainFilePath,onChange:e=>A({explainFilePath:e.target.value}),onBlur:e=>A({explainFilePath:nN(E,e.target.value)})})]}),(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:["Question ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea",rows:2,placeholder:"What should the plan focus on?",value:b.explainQuestion,onChange:e=>A({explainQuestion:e.target.value})})]})]}):"unit-test-generation"===d?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"targetKind"}),(0,a.jsxs)("span",{className:"dlg-selwrap",children:[(0,a.jsxs)("select",{className:"dlg-input mono",value:b.unitTargetKind,onChange:e=>A({unitTargetKind:e.target.value}),children:[(0,a.jsx)("option",{value:"file",children:"file"}),(0,a.jsx)("option",{value:"module",children:"module"}),(0,a.jsx)("option",{value:"changedFiles",children:"changedFiles"})]}),(0,a.jsx)("span",{className:"dlg-selchev",children:(0,a.jsx)(S.chevron,{size:15})})]})]}),"module"===b.unitTargetKind?(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"moduleDir"}),(0,a.jsx)("input",{className:"dlg-input mono",placeholder:"src/module",value:b.unitModuleDir,onChange:e=>A({unitModuleDir:e.target.value}),onBlur:e=>A({unitModuleDir:nN(E,e.target.value)})})]}):"changedFiles"===b.unitTargetKind?(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"filePaths"}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,placeholder:"src/file.ts, src/other.ts",value:b.unitFilePaths,onChange:e=>A({unitFilePaths:e.target.value}),onBlur:e=>A({unitFilePaths:nS(E,e.target.value)})})]}):(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"filePath"}),(0,a.jsx)("input",{className:"dlg-input mono",placeholder:"src/file.ts",value:b.unitFilePath,onChange:e=>A({unitFilePath:e.target.value}),onBlur:e=>A({unitFilePath:nN(E,e.target.value)})})]})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:["Description ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea",rows:2,placeholder:"Describe the observed bug.",value:b.bugDescription,onChange:e=>A({bugDescription:e.target.value})})]}),(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:["Failing output ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,value:b.bugFailingOutput,onChange:e=>A({bugFailingOutput:e.target.value})})]}),(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:["Stack trace ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,value:b.bugStackTrace,onChange:e=>A({bugStackTrace:e.target.value})})]}),(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:["Target files ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,placeholder:"src/file.ts, src/other.ts",value:b.bugTargetFiles,onChange:e=>A({bugTargetFiles:e.target.value}),onBlur:e=>A({bugTargetFiles:nS(E,e.target.value)})})]})]}),(0,a.jsxs)("div",{className:"dlg-agent-actions",children:[(0,a.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",disabled:!P,onClick:()=>void L(),children:R?"Starting...":"Start agent"}),w?(0,a.jsx)("span",{className:"dlg-note",children:"Loading models and projects..."}):null]})]})}function nR(e){var t,n;let{type:s,types:i,filesContext:r=null,onConfirm:o,onClose:c}=e,d=i[s],u=null!=(t=d.config)?t:[],[h,p]=(0,l.useState)(()=>(function(e){let t={};for(let a of e){var n;t[a.key]=null!=(n=a.def)?n:""}return t})(u)),[m,f]=(0,l.useState)(!1),[g,v]=(0,l.useState)(null),[x,y]=(0,l.useState)(null),b=(0,l.useRef)(null),j=(0,l.useRef)(null);(0,l.useEffect)(()=>(j.current=document.activeElement,()=>{var e,t;null==(t=j.current)||null==(e=t.focus)||e.call(t)}),[]),(0,l.useEffect)(()=>{let e=requestAnimationFrame(()=>{var e;f(!0),null==(e=b.current)||e.focus()});return()=>cancelAnimationFrame(e)},[]),(0,l.useEffect)(()=>{if("files"!==s)return;let e=!1,t=h.root;if("string"!=typeof t||!(t.length>0))return v(null),(0,$.vj)().then(t=>{let n=nj(t.projects)[0];e||void 0===n||p(e=>({...e,root:n}))}).catch(t=>{e||v(nx(t))}),()=>{e=!0}},[h.root,s]);let w=(e,t)=>p(n=>({...n,[e]:t})),k=()=>{"agents"!==s&&o(h)},N=S[d.icon],C=null!=(n=d.cta)?n:"Open ".concat(d.title);return(0,a.jsx)("div",{className:"dlg-overlay"+(m?" in":""),onPointerDown:c,children:(0,a.jsxs)("div",{className:"dlg",role:"dialog","aria-modal":"true","aria-labelledby":"new-window-title","aria-describedby":"new-window-desc",onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{if("Escape"===e.key)return void c();if("Enter"===e.key&&(e.metaKey||e.ctrlKey))return void k();if("Tab"!==e.key)return;let t=function(e){let t=e.querySelectorAll("button,input,select,textarea"),n=[];return t.forEach(e=>{e.hasAttribute("disabled")||(null!==e.offsetParent||"BUTTON"===e.tagName)&&n.push(e)}),n}(e.currentTarget);if(0===t.length)return;let n=t[0],a=t[t.length-1];e.shiftKey&&document.activeElement===n?(e.preventDefault(),a.focus()):e.shiftKey||document.activeElement!==a||(e.preventDefault(),n.focus())},children:[(0,a.jsxs)("div",{className:"dlg-head",children:[(0,a.jsx)("span",{className:"dlg-ico",children:(0,a.jsx)(N,{size:20})}),(0,a.jsxs)("div",{className:"dlg-htext",children:[(0,a.jsxs)("span",{id:"new-window-title",className:"dlg-title",children:["New ",d.title," window"]}),(0,a.jsx)("span",{id:"new-window-desc",className:"dlg-sub",children:d.desc})]}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsx)("button",{type:"button",className:"palette-x",onClick:c,"aria-label":"Cancel",title:"Cancel",children:(0,a.jsx)(S.close,{size:16})})]}),(0,a.jsxs)("div",{className:"dlg-body",children:["agents"===s?(0,a.jsx)(nC,{filesContext:r,firstRef:e=>{b.current=e},directoryField:x,setDirectoryField:y,setDialogError:v,onConfirm:o}):0===u.length&&(0,a.jsxs)("div",{className:"dlg-empty",children:["Add a new ",d.title," window to your workspace."]}),"agents"!==s&&u.map((e,t)=>(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:[e.label,!0===e.optional&&(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),function(e,t,n,l,s){var i,r,o,c;if("perm"===e.type)return(0,a.jsx)(nv,{cfg:t,set:n});let d=t[e.key],u="string"==typeof d?d:void 0===d?"":String(d);if("select"===e.type){let t=null!=(i=e.options)?i:[];return(0,a.jsxs)("span",{className:"dlg-selwrap",children:[(0,a.jsx)("select",{ref:null!=l?l:void 0,className:"dlg-input mono",value:u,onChange:t=>n(e.key,t.target.value),disabled:0===t.length,children:t.map(t=>{var n;return(0,a.jsx)("option",{value:t,children:(null!=(n=e.prefix)?n:"")+t},t)})}),(0,a.jsx)("span",{className:"dlg-selchev",children:(0,a.jsx)(S.chevron,{size:15})})]})}return"textarea"===e.type?(0,a.jsx)("textarea",{ref:null!=l?l:void 0,className:"dlg-input dlg-textarea",rows:3,placeholder:null!=(r=e.placeholder)?r:"",value:u,onChange:t=>n(e.key,t.target.value)}):"directory"===e.type?(0,a.jsxs)("span",{className:"dlg-dirwrap",children:[(0,a.jsx)("input",{ref:null!=l?l:void 0,className:"dlg-input mono",placeholder:null!=(o=e.placeholder)?o:e.label,value:u,onClick:()=>s(e.key),onChange:t=>n(e.key,t.target.value)}),(0,a.jsx)("button",{type:"button",className:"dlg-dirbtn",onClick:()=>s(e.key),children:"Browse"})]}):(0,a.jsx)("input",{ref:null!=l?l:void 0,className:"dlg-input mono",placeholder:null!=(c=e.placeholder)?c:e.label,value:u,onChange:t=>n(e.key,t.target.value)})}(e,h,w,0===t?e=>{b.current=e}:null,y),"directory"===e.type&&x===e.key?(0,a.jsx)(ny,{value:"string"==typeof h[e.key]?h[e.key]:"",selectProjectRoot:"root"===e.key,onSelect:t=>w(e.key,t),onClose:()=>y(null)}):null]},e.key)),null!==g?(0,a.jsx)("div",{className:"dlg-error",children:g}):null]}),(0,a.jsxs)("div",{className:"dlg-foot",children:[(0,a.jsx)("button",{type:"button",className:"dlg-btn",onClick:c,children:"Cancel"}),"agents"!==s?(0,a.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",onClick:k,children:C}):null]})]})})}function nI(e){let{types:t,order:n,onAdd:s,onClose:i}=e,r=(0,l.useRef)(null),o=(0,l.useRef)(null);return(0,l.useEffect)(()=>{var e;o.current=document.activeElement;let t=null==(e=r.current)?void 0:e.querySelector(".pal-card");return null==t||t.focus(),()=>{var e,t;null==(t=o.current)||null==(e=t.focus)||e.call(t)}},[]),(0,a.jsxs)("div",{ref:r,className:"palette",role:"dialog","aria-modal":"true","aria-labelledby":"palette-title","aria-describedby":"palette-desc",onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{if("Escape"===e.key){e.preventDefault(),i();return}if("Tab"===e.key){var t,n;let a=Array.from(null!=(n=null==(t=r.current)?void 0:t.querySelectorAll("button:not([disabled]),[tabindex]:not([tabindex='-1'])"))?n:[]);if(0===a.length)return;let l=a[0],s=a[a.length-1];e.shiftKey&&document.activeElement===l?(e.preventDefault(),s.focus()):e.shiftKey||document.activeElement!==s||(e.preventDefault(),l.focus())}},children:[(0,a.jsxs)("div",{className:"palette-head",children:[(0,a.jsx)("span",{className:"palette-badge",children:(0,a.jsx)(S.add,{size:17})}),(0,a.jsxs)("div",{className:"palette-htext",children:[(0,a.jsx)("span",{id:"palette-title",className:"palette-title",children:"New Window"}),(0,a.jsx)("span",{id:"palette-desc",className:"palette-sub",children:"Pick a card to add to your workspace"})]}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsx)("button",{type:"button",className:"palette-x",onClick:i,"aria-label":"Close window picker",title:"Close",children:(0,a.jsx)(S.close,{size:16})})]}),(0,a.jsx)("div",{className:"palette-grid",children:n.map(e=>{let n=t[e],l=S[n.icon];return(0,a.jsxs)("button",{type:"button",className:"pal-card pal-main",onClick:()=>s(e),children:[(0,a.jsx)("span",{className:"pal-ico",children:(0,a.jsx)(l,{size:18})}),(0,a.jsx)("span",{className:"pal-name",children:n.title}),(0,a.jsx)("span",{className:"pal-desc",children:n.desc}),(0,a.jsx)("span",{className:"pal-add",children:(0,a.jsx)(S.plus,{size:15})})]},e)})})]})}let nE="keiko.theme",nM="dark",nT=[/\bsk-[A-Za-z0-9_-]{20,}\b/,/\bAKIA[0-9A-Z]{16}\b/,/\bgh[pousr]_[A-Za-z0-9]{36,}\b/,/\bxox[abporsu]-[A-Za-z0-9-]{10,}\b/,/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/,/-----BEGIN [A-Z ]*PRIVATE KEY-----/],nq=/\b(?:\d[ -]?){13,19}\b/g;n(7011);let nP={chat:{lifecycle:["draft","streaming","final","archived"],trustBoundary:["ui","model","evidence"],authority:"user-confirm",persistence:"durable.ui"},files:{lifecycle:["connecting","connected","degraded","disconnected","error"],trustBoundary:["ui","fs"],authority:"user",persistence:"fs-reference"},connector:{lifecycle:["connecting","connected","degraded","disconnected","error"],trustBoundary:["ui","fs"],authority:"user",persistence:"fs-reference"},editor:{lifecycle:["viewing","editing","unsaved","saved","error"],trustBoundary:["ui","fs"],authority:"user",persistence:"fs-reference"},browser:{lifecycle:["idle","live","error"],trustBoundary:["ui","network"],authority:"user-confirm",persistence:"transient"},terminal:{lifecycle:["idle","running","blocked","cancelled","error"],trustBoundary:["ui","tool"],authority:"user-confirm",persistence:"transient"},review:{lifecycle:["proposed","needs-review","applied","reverted","archived"],trustBoundary:["ui","evidence"],authority:"user-confirm",persistence:"evidence-reference"},agents:{lifecycle:["proposed","running","blocked","needs-review","verified","cancelled"],trustBoundary:["ui","model","tool","evidence"],authority:"user-confirm",persistence:"durable.ui"},integ:{lifecycle:["idle","connecting","connected","degraded","disconnected","error"],trustBoundary:["ui","network"],authority:"user-confirm",persistence:"durable.config"},keiko:{lifecycle:["live"],trustBoundary:["ui","memory"],authority:"user",persistence:"memory-reference"},settings:{lifecycle:["viewing","editing","saved"],trustBoundary:["ui"],authority:"user",persistence:"durable.config"},project:{lifecycle:["none","connecting","connected","disconnected"],trustBoundary:["ui","fs"],authority:"user",persistence:"durable.config"},search:{lifecycle:["idle","searching","results","error"],trustBoundary:["ui","fs"],authority:"read-only",persistence:"transient"},plugins:{lifecycle:["idle","installed","disabled","enabled"],trustBoundary:["ui"],authority:"user",persistence:"durable.config"},automations:{lifecycle:["idle","enabled","disabled"],trustBoundary:["ui"],authority:"user",persistence:"durable.config"},mobile:{lifecycle:["paired","unpaired","error"],trustBoundary:["ui","network"],authority:"user-confirm",persistence:"durable.config"},inspector:{lifecycle:["empty","focused"],trustBoundary:["ui"],authority:"ui-only",persistence:"transient"},activity:{lifecycle:["live","archived"],trustBoundary:["ui"],authority:"read-only",persistence:"transient"},notifications:{lifecycle:["unread","read","dismissed"],trustBoundary:["ui"],authority:"ui-only",persistence:"transient"},resources:{lifecycle:["live"],trustBoundary:["ui"],authority:"read-only",persistence:"transient"},quality:{lifecycle:["idle","running","results","error"],trustBoundary:["ui","model","evidence"],authority:"user-confirm",persistence:"evidence-reference"},qiRun:{lifecycle:["running","final","needs-review","verified","failed","cancelled"],trustBoundary:["ui","model","evidence"],authority:"user-confirm",persistence:"evidence-reference"},relationships:{lifecycle:["idle","live","degraded","blocked","error"],trustBoundary:["ui","evidence"],authority:"user-confirm",persistence:"durable.ui"},figma:{lifecycle:["idle","running","results","error"],trustBoundary:["ui","evidence","network"],authority:"user-confirm",persistence:"evidence-reference"}},nA=["apikey","accesskey","clientsecret","credential","password","privatekey","secret","token"],nz=["api_key=","apikey=","client_secret=","clientsecret=","credential=","authorization:","password=","secret=","token="],nD=[".env",".env.local",".env.development",".env.test",".env.production"];function nL(e){return"number"==typeof e&&Number.isFinite(e)}function nF(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function nO(e){let t=e.trim();if(0===t.length)return!1;let n=t.toLowerCase();return function(e){for(let t of nT)if(t.test(e))return!0;for(let t of e.matchAll(nq)){let e=t[0].replaceAll(/[ -]/g,"");if(e.length>=13&&e.length<=19&&function(e){let t=0,n=!1;for(let a=e.length-1;a>=0;a-=1){let l=Number(e[a]);n&&(l*=2)>9&&(l-=9),t+=l,n=!n}return t%10==0}(e))return!0}return!1}(t)||function(e){let t="bearer ",n=e.toLowerCase().indexOf(t);if(-1===n)return!1;let a=0;for(let s=n+t.length;s<e.length;s+=1){var l;if(0===(null!=(l=e[s])?l:"").trim().length)break;a+=1}return a>=8}(t)||function(e){if(!e.includes("://"))return!1;try{let t=new URL(e);return t.username.length>0||t.password.length>0}catch(e){return!1}}(t)||nz.some(e=>n.includes(e))||function(e){let t=e.toLowerCase().replaceAll("\\","/").split("/");for(let e=0;e<t.length;e+=1){var n,a;let l=null!=(n=t[e])?n:"",s=null!=(a=t[e+1])?a:"";if(nD.includes(l)||".npmrc"===l||"credentials.json"===l||".aws"===l&&"credentials"===s||".ssh"===l&&s.startsWith("id_"))return!0}return!1}(t)}function nK(e){let t=[];for(let n of e){let e=function(e){var t;if(!nF(e)||!("string"==typeof(t=e.type)&&t in es))return null;let n=e.type;if("transient"===nP[n].persistence||"string"!=typeof e.id||!nL(e.x)||!nL(e.y)||!nL(e.w)||!nL(e.h)||!nL(e.z)||"boolean"!=typeof e.max)return null;let a={id:e.id,type:n,x:e.x,y:e.y,w:e.w,h:e.h,z:e.z,cfg:function(e,t){var n;if(!nF(t)||"durable.config"===nP[e].persistence)return{};let a=new Set((null!=(n=es[e].config)?n:[]).map(e=>e.key)),l={};for(let[n,s]of Object.entries(t)){if(!a.has(n))continue;let t=function(e,t,n){if("string"!=typeof n&&"number"!=typeof n&&"boolean"!=typeof n||function(e){let t=function(e){let t="";for(let n of e.toLowerCase())(n>="a"&&n<="z"||n>="0"&&n<="9")&&(t+=n);return t}(e);return nA.some(e=>t.includes(e))}(t))return;if("string"!=typeof n)return n;let a=nP[e].persistence;return"evidence-reference"===a?!function(e){if(0===e.length||e.length>256||e.startsWith(".")||e.trim()!==e||nO(e))return!1;for(let t of e)if(!function(e){let t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122||46===t||95===t||45===t}(t))return!1;return!0}(n)?void 0:n:nO(n)?"durable.ui"===a?"[REDACTED]":void 0:n}(e,n,s);void 0!==t&&(l[n]=t)}return l}(n,e.cfg),max:e.max},l=function(e){if(nF(e)&&nL(e.x)&&nL(e.y)&&nL(e.w)&&nL(e.h))return{x:e.x,y:e.y,w:e.w,h:e.h}}(e.prev);return{...a,...void 0!==l?{prev:l}:{},...nL(e.zoom)?{zoom:e.zoom}:{}}}(n);null!==e&&t.push(e)}return t}function nB(e,t){let n=new Set(t.map(e=>e.id)),a=[];for(let t of e)"string"==typeof t.id&&"string"==typeof t.a&&"string"==typeof t.b&&n.has(t.a)&&n.has(t.b)&&a.push({id:t.id,a:t.a,b:t.b});return a}let nW="keiko.workspace.v4",nU="keiko.conns.v1",n_="keiko.view";function nH(){try{let e=window.localStorage.getItem(n_);if(null===e)return{zoom:1,x:0,y:0};let t=JSON.parse(e);if("object"==typeof t&&null!==t&&"zoom"in t&&"number"==typeof t.zoom)return{zoom:t.zoom,x:"number"==typeof t.x?t.x:0,y:"number"==typeof t.y?t.y:0}}catch(e){}return{zoom:1,x:0,y:0}}function nJ(e){return Math.max(.3,Math.min(2.5,e))}function nV(e){return Math.max(.5,Math.min(2,Math.round(10*e)/10))}function nG(e){let t=e[0];for(let n=1;n<e.length;n++){let a=e[n];a.z>t.z&&(t=a)}return t}function nX(e,t){try{window.localStorage.setItem(e,JSON.stringify(t))}catch(e){}}let nY=["agent","capsule","capsule-set","chat","connector","data-source","evidence-run","mcp-tool","memory","patch-proposal","skill","tool","workflow-run","workspace-path"],nZ=["capsule","capsule-set","chat","evidence-run","memory","patch-proposal","tool","workflow-run","workspace-path"],nQ=["reads-context","proposes-patch","uses-tool","starts-workflow","produces-evidence","references-document","depends-on"],n$=["draft","active","archived","superseded","revoked","blocked","stale"],n0={"reads-context":{id:"reads-context",displayName:"reads context",semantics:"A consumer endpoint reads the contextual content of the target at a specific point in time.",validSourceKinds:["workflow-run","chat"],validTargetKinds:["memory","capsule","capsule-set","evidence-run","workspace-path","connector","data-source"],cardinality:"N:N",direction:"directed",lifecycle:{creatable:!0,immutable:!0,reconnectable:!1,deletable:!1,archivable:!0},auditEventOnMutation:!0,evidenceRelevance:"reference",ownerPackage:"@oscharko-dev/keiko-workflows",trustBoundary:"per-endpoint"},"proposes-patch":{id:"proposes-patch",displayName:"proposes patch",semantics:"A workflow run proposes a patch against one or more workspace paths. The relationship records the proposal; diff content stays in the harness PatchProposedEvent.",validSourceKinds:["workflow-run"],validTargetKinds:["workspace-path","patch-proposal"],cardinality:"1:N",direction:"directed",lifecycle:{creatable:!0,immutable:!0,reconnectable:!1,deletable:!0,archivable:!0},auditEventOnMutation:!0,evidenceRelevance:"reference",ownerPackage:"@oscharko-dev/keiko-workflows",trustBoundary:"fs"},"uses-tool":{id:"uses-tool",displayName:"uses tool",semantics:"A workflow run uses a registered tool. Per-call arguments and results remain in the harness ToolCallRequest / ToolCallResult envelopes.",validSourceKinds:["workflow-run"],validTargetKinds:["tool","mcp-tool"],cardinality:"N:N",direction:"directed",lifecycle:{creatable:!0,immutable:!0,reconnectable:!1,deletable:!1,archivable:!0},auditEventOnMutation:!0,evidenceRelevance:"reference",ownerPackage:"@oscharko-dev/keiko-workflows",trustBoundary:"tool"},"starts-workflow":{id:"starts-workflow",displayName:"starts workflow",semantics:"A chat or a parent workflow run initiates a workflow run. The relationship records the origin; run identity belongs to the workflow ledger.",validSourceKinds:["chat","workflow-run"],validTargetKinds:["workflow-run"],cardinality:"1:N",direction:"directed",lifecycle:{creatable:!0,immutable:!0,reconnectable:!1,deletable:!1,archivable:!0},auditEventOnMutation:!0,evidenceRelevance:"reference",ownerPackage:"@oscharko-dev/keiko-workflows",trustBoundary:"per-endpoint"},"produces-evidence":{id:"produces-evidence",displayName:"produces evidence",semantics:"A workflow run produces exactly one durable evidence-run record. If a run produces no evidence, no relationship is recorded.",validSourceKinds:["workflow-run"],validTargetKinds:["evidence-run"],cardinality:"1:1",direction:"directed",lifecycle:{creatable:!0,immutable:!0,reconnectable:!1,deletable:!1,archivable:!0},auditEventOnMutation:!0,evidenceRelevance:"produces",ownerPackage:"@oscharko-dev/keiko-evidence",trustBoundary:"evidence"},"references-document":{id:"references-document",displayName:"references document",semantics:"A chat or workflow run holds a structural pointer to a document (workspace file or local-knowledge capsule). Distinct from reads-context: a reference is structural, a read is an event.",validSourceKinds:["chat","workflow-run"],validTargetKinds:["workspace-path","capsule","capsule-set"],cardinality:"N:N",direction:"directed",lifecycle:{creatable:!0,immutable:!1,reconnectable:!0,deletable:!0,archivable:!0},auditEventOnMutation:!0,evidenceRelevance:"reference",ownerPackage:"@oscharko-dev/keiko-workflows",trustBoundary:"per-endpoint"},"depends-on":{id:"depends-on",displayName:"depends on",semantics:"A capsule, capsule-set, workflow run, or memory depends on another. Used by impact analysis (#542). Self-loops and direct two-edge cycles are forbidden at validation time; transitive cycle detection is deferred to impact traversal.",validSourceKinds:["capsule","capsule-set","workflow-run","memory"],validTargetKinds:["capsule","capsule-set","workflow-run","memory","evidence-run","workspace-path"],cardinality:"N:N",direction:"directed",lifecycle:{creatable:!0,immutable:!1,reconnectable:!0,deletable:!0,archivable:!0},auditEventOnMutation:!0,evidenceRelevance:"reference",ownerPackage:"@oscharko-dev/keiko-contracts",trustBoundary:"per-endpoint"}},n1=["prompt","documentcontent","filecontent","toolstdout","toolstderr","secret","credential","apikey","password","token"];class n2 extends Error{constructor(e,t,n,a=[]){super(t),this.name="RelationshipApiError",this.code=e,this.status=n,this.reasons=a}}async function n5(e){let t;try{t=await e.json()}catch(t){throw new n2("relationship/parse-error","Response is not valid JSON.",e.status)}if(!e.ok){var n;let a=t,l=null!=(n=a.error)?n:a,s="string"==typeof l.code?l.code:"relationship/unknown-error",i="string"==typeof l.message?l.message:"An unknown error occurred.",r=Array.isArray(a.reasons)?a.reasons:[];throw new n2(s,i,e.status,r)}return t}function n3(e){let t={"Content-Type":"application/json","X-Keiko-CSRF":"1"};return void 0!==e.idempotencyKey&&(t["Idempotency-Key"]=e.idempotencyKey),void 0!==e.ifMatch&&(t["If-Match"]=e.ifMatch),t}async function n4(e){let t={schemaVersion:"1",proposal:{type:e.type,source:{kind:e.source.kind,id:e.source.id},target:{kind:e.target.kind,id:e.target.id},...void 0!==e.summary?{summary:e.summary}:{}}},n=await fetch("/api/relationships/validate",{method:"POST",headers:n3({}),body:JSON.stringify(t)});return{decision:(await n5(n)).decision}}async function n6(e,t){let n={schemaVersion:"1",proposal:{type:e.type,source:{kind:e.source.kind,id:e.source.id},target:{kind:e.target.kind,id:e.target.id},...void 0!==e.summary?{summary:e.summary}:{}}},a=await fetch("/api/relationships",{method:"POST",headers:n3({idempotencyKey:t}),body:JSON.stringify(n)}),l=await n5(a);return{relationship:l.relationship,etag:l.etag}}async function n8(e){let t=new URLSearchParams;void 0!==e.lifecycle&&t.set("lifecycle",e.lifecycle),void 0!==e.type&&t.set("type",e.type),void 0!==e.sourceKind&&t.set("sourceKind",e.sourceKind),void 0!==e.targetKind&&t.set("targetKind",e.targetKind),void 0!==e.sourceId&&t.set("sourceId",e.sourceId),void 0!==e.targetId&&t.set("targetId",e.targetId),void 0!==e.limit&&t.set("limit",String(e.limit)),void 0!==e.cursor&&t.set("cursor",e.cursor);let n=await fetch("/api/relationships?".concat(t.toString())),a=await n5(n);return{entries:a.entries,truncated:a.truncated,nextCursor:a.nextCursor}}async function n7(e){let t=await fetch("/api/relationships/".concat(encodeURIComponent(e)));return(await n5(t)).relationship}async function n9(e,t,n,a){let l=await fetch("/api/relationships/".concat(encodeURIComponent(e)),{method:"PATCH",headers:n3({idempotencyKey:a,ifMatch:n}),body:JSON.stringify({schemaVersion:"1",...t})}),s=await n5(l);return{relationship:s.relationship,etag:s.etag}}async function ae(e,t,n){let a=await fetch("/api/relationships/".concat(encodeURIComponent(e)),{method:"DELETE",headers:n3({idempotencyKey:n,ifMatch:t})});return(await n5(a)).relationship}async function at(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=new URLSearchParams;void 0!==t.direction&&n.set("direction",t.direction),void 0!==t.maxDepth&&n.set("maxDepth",String(t.maxDepth)),void 0!==t.maxNodes&&n.set("maxNodes",String(t.maxNodes)),void 0!==t.maxRelationships&&n.set("maxRelationships",String(t.maxRelationships));let a=await fetch("/api/relationships/".concat(encodeURIComponent(e),"/dependencies?").concat(n.toString()));return(await n5(a)).report}async function an(e){return n5(await fetch("/api/relationships/".concat(encodeURIComponent(e),"/explain")))}async function aa(){return n5(await fetch("/api/relationships/health"))}let al=[{key:"t",mod:["cmd"]},{key:"t",mod:["ctrl"]},{key:"r",mod:["cmd"]},{key:"r",mod:["ctrl"]},{key:"n",mod:["cmd","shift"]},{key:"n",mod:["ctrl","shift"]},{key:"w",mod:["cmd"]},{key:"w",mod:["ctrl"]}];function as(e){switch(e.kind){case"ui.window.move":return"Move window";case"ui.window.resize":return"Resize window";case"ui.window.zorder":return"Reorder window";case"ui.window.close":return"Close window";case"ui.window.open":return"Open window";case"ui.workspace.pan":return"Pan workspace";case"ui.workspace.zoom":return"Zoom workspace";case"ui.workspace.fit":return"Fit workspace to view";case"ui.panel.toggle":return"Toggle ".concat(e.panel," panel");case"ui.selection.change":return"Change selection";case"ui.tab.switch":return"Switch tab"}}function ai(e){let t=[...e.mod].sort();return"".concat(t.join("+"),"|").concat(e.key.toLowerCase())}let ar={undoStack:[],redoStack:[]};class ao extends Error{constructor(e){super("Workspace keyboard shortcut conflicts detected: ".concat(e.map(e=>"".concat(ai(e.chord)," (").concat(e.commandIds.join(", "),")")).join("; "))),this.name="WorkspaceShortcutConflictError",this.conflicts=e}}class ac extends Error{constructor(e){super("Workspace keyboard shortcut bindings refused: ".concat(e.map(e=>"".concat(e.commandId," → ").concat(ai(e.chord))).join("; ")," are browser-reserved")),this.name="WorkspaceShortcutReservedError",this.reserved=e}}let ad=[{commandId:"undo",chord:{key:"z",mod:["cmd"]}},{commandId:"redo",chord:{key:"z",mod:["cmd","shift"]}},{commandId:"focus-status",chord:{key:"s",mod:["alt"]}}];function au(e){let{project:t,activeProjectPath:n,chats:s,activeChatId:i,onProject:r,onChat:o}=e,c=n===t.path,[d,u]=(0,l.useState)(c),h=t.available?"Available":"Unavailable";return(0,l.useEffect)(()=>{c&&u(!0)},[c]),(0,a.jsxs)("div",{className:"proj",children:[(0,a.jsxs)("button",{className:"proj-head",type:"button","data-active":c?"true":"false","aria-expanded":d,"aria-current":c?"true":void 0,"aria-label":"".concat(t.name," (").concat(h,")"),onClick:()=>{u(e=>!e),r(t)},children:[(0,a.jsx)("span",{className:"proj-caret","data-open":d,children:(0,a.jsx)(S.chevronR,{size:13})}),(0,a.jsx)(S.folder,{size:15}),(0,a.jsx)("span",{className:"proj-name",children:t.name}),(0,a.jsx)("span",{className:"chat-time",children:h})]}),d&&(0,a.jsx)("div",{className:"proj-chats",children:c?0===s.length?(0,a.jsx)("div",{className:"proj-empty",children:"No chats"}):s.map(e=>(0,a.jsxs)("button",{type:"button",className:"chat-row","data-active":i===e.id,"aria-pressed":i===e.id,onClick:()=>{o(e)},children:[(0,a.jsx)("span",{className:"chat-title",children:e.title}),void 0!==e.branchLabel?(0,a.jsx)("span",{className:"chat-meta mono",children:e.branchLabel}):null]},e.id)):(0,a.jsx)("div",{className:"proj-empty",children:"Select project to load chats"})})]})}function ah(){let e=r();return(0,a.jsxs)("div",{className:"tw-scroll",children:[(0,a.jsx)("div",{className:"sb-section",children:(0,a.jsx)("span",{className:"sb-section-label",children:"Projects"})}),0===e.projects.length?(0,a.jsx)("div",{className:"proj-empty",children:"No registered projects"}):e.projects.map(t=>{var n,l,s;return(0,a.jsx)(au,{project:t,activeProjectPath:null==(n=e.activeProject)?void 0:n.path,chats:(null==(l=e.activeProject)?void 0:l.path)===t.path?e.chats:[],activeChatId:null==(s=e.activeChat)?void 0:s.id,onProject:t=>{e.openProject(t)},onChat:t=>{e.openChat(t)}},t.path)})]})}function ap(e){let{name:t,icon:n}=e,l=null!=n?n:function(e){let t=e.toLowerCase();return"dockerfile"===t||t.includes("docker-compose")||t.endsWith(".dockerignore")?"docker":t.endsWith(".json")?"json":t.endsWith(".yml")||t.endsWith(".yaml")?"yaml":t.endsWith(".md")?"markdown":t.endsWith(".properties")||t.endsWith(".env")||t.startsWith(".env.")?"properties":t.endsWith(".java")?"java":t.endsWith(".tsx")?"react":t.endsWith(".ts")?"typescript":t.endsWith(".jsx")||t.endsWith(".js")||t.endsWith(".mjs")||t.endsWith(".cjs")?"javascript":t.endsWith(".py")?"python":t.endsWith(".go")?"go":t.endsWith(".rs")?"rust":t.endsWith(".gradle")?"gradle":t.endsWith(".sql")?"postgresql":t.endsWith(".html")?"html5":t.endsWith(".css")?"css3":t.endsWith(".graphql")||t.endsWith(".gql")?"graphql":t.endsWith(".png")||t.endsWith(".jpg")||t.endsWith(".jpeg")||t.endsWith(".gif")||t.endsWith(".webp")||t.endsWith(".svg")?"image":null}(t);return null!==l?(0,a.jsx)("img",{className:"fi-img",src:"/assets/icons/".concat(l,".svg"),width:"15",height:"15",alt:""}):(0,a.jsx)("span",{className:"fi-fallback",children:(0,a.jsx)(S.file,{size:14})})}let am=[{name:"backend",type:"folder",icon:"spring",children:[{name:"src/main/java/com/keiko/orca",type:"folder",children:[{name:"OrcaApplication.java",type:"file"},{name:"api",type:"folder",open:!1,children:[{name:"AgentController.java",type:"file"},{name:"WorkspaceController.java",type:"file"}]},{name:"service",type:"folder",open:!1,children:[{name:"InferenceService.java",type:"file"},{name:"AgentOrchestrator.java",type:"file"}]},{name:"config",type:"folder",open:!1,children:[{name:"SecurityConfig.java",type:"file"}]}]},{name:"src/main/resources",type:"folder",open:!1,children:[{name:"application.yml",type:"file"},{name:"schema.sql",type:"file"}]},{name:"build.gradle",type:"file"},{name:"Dockerfile",type:"file"}]},{name:"frontend",type:"folder",icon:"react",children:[{name:"src",type:"folder",children:[{name:"App.tsx",type:"file"},{name:"components",type:"folder",open:!1,children:[{name:"Workspace.tsx",type:"file"},{name:"WindowManager.tsx",type:"file"}]},{name:"api",type:"folder",open:!1,children:[{name:"client.ts",type:"file"},{name:"schema.graphql",type:"file"}]},{name:"styles",type:"folder",open:!1,children:[{name:"theme.css",type:"file"}]}]},{name:"package.json",type:"file",mut:"M"},{name:"tsconfig.json",type:"file"},{name:"Dockerfile",type:"file"}]},{name:"deploy",type:"folder",icon:"kubernetes",children:[{name:"k8s",type:"folder",children:[{name:"deployment.yaml",type:"file",icon:"kubernetes"},{name:"service.yaml",type:"file",icon:"kubernetes"},{name:"ingress.yaml",type:"file",icon:"kubernetes"}]},{name:"docker-compose.yml",type:"file"},{name:"prometheus.yml",type:"file",icon:"prometheus"}]},{name:".github/workflows",type:"folder",icon:"github",open:!1,children:[{name:"ci.yml",type:"file"},{name:"release.yml",type:"file"}]},{name:"README.md",type:"file"}];function af(e){let{node:t,depth:n,path:s,active:i,onPick:r}=e,[o,c]=(0,l.useState)(!1!==t.open),d=8+13*n,u="".concat(s,"/").concat(t.name);if("folder"===t.type){var h;return(0,a.jsxs)("div",{children:[(0,a.jsxs)("button",{className:"tr-row",style:{paddingLeft:d},onClick:()=>{c(e=>!e)},children:[(0,a.jsx)("span",{className:"tr-caret","data-open":o,children:(0,a.jsx)(S.chevronR,{size:11})}),void 0!==t.icon?(0,a.jsx)("img",{className:"fi-img",src:"/assets/icons/".concat(t.icon,".svg"),width:"15",height:"15",alt:""}):(0,a.jsx)("span",{className:"fi-fallback",style:{color:"var(--accent)"},children:(0,a.jsx)(S.folder,{size:14})}),(0,a.jsx)("span",{className:"tr-name tr-folder",children:t.name})]}),o&&(null==(h=t.children)?void 0:h.map((e,t)=>(0,a.jsx)(af,{node:e,depth:n+1,path:u,active:i,onPick:r},"".concat(u,"/").concat(e.name,"-").concat(String(t)))))]})}return(0,a.jsxs)("button",{className:"tr-row tr-file","data-active":i===u,style:{paddingLeft:d+14},onClick:()=>{r(u)},children:[(0,a.jsx)(ap,{name:t.name,icon:t.icon}),(0,a.jsx)("span",{className:"tr-name",children:t.name}),void 0!==t.mut&&(0,a.jsx)("span",{className:"file-mut",children:t.mut})]})}function ag(){var e,t;let[n,s]=(0,l.useState)("/frontend/src/App.tsx"),i=o(),r=null!=(t=null==i||null==(e=i.activeProject)?void 0:e.name)?t:"No project selected";return(0,a.jsxs)("div",{className:"srch",children:[(0,a.jsxs)("div",{className:"srch-box",children:[(0,a.jsx)(S.search,{size:15,"aria-hidden":"true"}),(0,a.jsx)("input",{type:"search","aria-label":"Search files and symbols",placeholder:"Search files & symbols…"}),(0,a.jsx)("span",{className:"kbd","aria-hidden":"true",children:"⇧⇧"})]}),(0,a.jsxs)("div",{className:"tw-label srch-label",children:[r," ",(0,a.jsx)("span",{className:"srch-meta mono",children:"workspace search"})]}),(0,a.jsx)("div",{className:"tr",children:am.map((e,t)=>(0,a.jsx)(af,{node:e,depth:0,path:"",active:n,onPick:s},"".concat(e.name,"-").concat(String(t))))})]})}let av=[{name:"Context7",img:"upstash",desc:"Up-to-date library docs",on:!0},{name:"Sequential Thinking",icon:"layers",desc:"Step-by-step reasoning",on:!0},{name:"Filesystem",icon:"files",desc:"Local file access",on:!0},{name:"GitHub",img:"github",desc:"Repos \xb7 PRs \xb7 issues",on:!0},{name:"Playwright",img:"playwright",desc:"Browser automation",on:!1},{name:"Brave Search",img:"brave",desc:"Web search",on:!1},{name:"MemoriaViva",icon:"cube",desc:"Knowledge graph",on:!0}],ax=[{name:"GitHub",img:"github",on:!0},{name:"Linear",img:"linear",on:!0},{name:"PostgreSQL",img:"postgresql",on:!0},{name:"Sentry",img:"sentry",on:!1},{name:"Slack",img:"slack",on:!1},{name:"Notion",img:"notion",on:!1}];function ay(e){let{img:t,icon:n,glyph:l}=e;if(void 0!==t)return(0,a.jsx)("img",{className:"pl-img",src:"/assets/icons/".concat(t,".svg"),width:"20",height:"20",alt:""});if(void 0!==n){let e=S[n];return(0,a.jsx)("span",{className:"pl-line",children:(0,a.jsx)(e,{size:18})})}return(0,a.jsx)("span",{className:"mono pl-glyph",children:l})}function ab(){let[e,t]=(0,l.useState)(av.map(e=>e.on)),n=e.filter(Boolean).length;return(0,a.jsxs)("div",{className:"plg",children:[(0,a.jsxs)("div",{className:"plg-sec",children:[(0,a.jsx)("span",{className:"plg-sec-t",children:"MCP Servers"}),(0,a.jsxs)("span",{className:"plg-sec-c mono",children:[n,"/",av.length," active"]})]}),av.map((n,l)=>{var s;let i=null!=(s=e[l])&&s;return(0,a.jsxs)("div",{className:"plg-row",children:[(0,a.jsx)("span",{className:"plg-ico",children:(0,a.jsx)(ay,{img:n.img,icon:n.icon})}),(0,a.jsxs)("span",{className:"plg-text",children:[(0,a.jsx)("span",{className:"plg-name",children:n.name}),(0,a.jsx)("span",{className:"plg-desc",children:n.desc})]}),(0,a.jsx)("button",{className:"plg-dot".concat(i?" on":""),title:i?"Running":"Stopped","aria-label":"".concat(n.name,": ").concat(i?"running":"stopped"),onClick:()=>{t(e=>{var t;let n=[...e];return n[l]=!(null!=(t=n[l])&&t),n})}})]},n.name)}),(0,a.jsx)("div",{className:"plg-sec plg-sec2",children:(0,a.jsx)("span",{className:"plg-sec-t",children:"Connectors"})}),ax.map(e=>(0,a.jsxs)("button",{className:"plg-row plg-conn","data-on":e.on,children:[(0,a.jsx)("span",{className:"plg-ico",children:(0,a.jsx)(ay,{img:e.img})}),(0,a.jsxs)("span",{className:"plg-text",children:[(0,a.jsx)("span",{className:"plg-name",children:e.name}),(0,a.jsx)("span",{className:"plg-desc",children:e.on?"Connected":"Not connected"})]}),e.on?(0,a.jsx)("span",{className:"integ-on",children:(0,a.jsx)(S.check,{size:13})}):(0,a.jsx)("span",{className:"integ-add",children:(0,a.jsx)(S.plus,{size:14})})]},e.name))]})}let aj=[{id:"nightly-review",name:"Nightly review",when:"02:00 daily",defaultOn:!0},{id:"on-push-lint",name:"On push → lint",when:"git push",defaultOn:!0},{id:"weekly-digest",name:"Weekly digest",when:"Mon 09:00",defaultOn:!1}],aw="keiko.automations.v1",ak=Object.fromEntries(aj.map(e=>[e.id,e.defaultOn]));function aN(){try{let e=localStorage.getItem(aw);if(null===e)return{...ak};let t=JSON.parse(e);if("object"!=typeof t||null===t||Array.isArray(t))return{...ak};let n={...ak};for(let[e,a]of Object.entries(t))e in ak&&"boolean"==typeof a&&(n[e]=a);return n}catch(e){return{...ak}}}function aS(){let[e,t]=(0,l.useState)(aN);return(0,a.jsx)("div",{className:"tw-list",children:aj.map(n=>{var l;let s=null!=(l=e[n.id])?l:n.defaultOn;return(0,a.jsxs)("div",{className:"auto-row",children:[(0,a.jsx)("span",{className:"dot",style:{background:s?"var(--accent)":"var(--fg-faint)"}}),(0,a.jsxs)("span",{className:"auto-text",children:[(0,a.jsx)("span",{className:"auto-name",children:n.name}),(0,a.jsx)("span",{className:"auto-when mono",children:n.when})]}),(0,a.jsx)(tw,{on:s,onChange:()=>{var e;e=n.id,t(t=>{var n;let a={...t,[e]:!(null!=(n=t[e])&&n)};return localStorage.setItem(aw,JSON.stringify(a)),a})},label:n.name})]},n.id)})})}function aC(){return(0,a.jsxs)("div",{className:"tw-pad mob",children:[(0,a.jsxs)("div",{className:"mob-qr",children:[(0,a.jsx)("div",{className:"ph-stripes"}),(0,a.jsx)(S.mobile,{size:28,style:{position:"relative",color:"var(--fg-dim)"}})]}),(0,a.jsx)("div",{className:"mob-title",children:"Keiko mobile"}),(0,a.jsx)("div",{className:"mob-sub",children:"Scan to continue this workspace on your phone."})]})}function aR(){let{wins:e,active:t,winCount:n}=(0,l.useContext)(k),s=null!==t?es[t.type]:null,i=null!==t?Object.entries(t.cfg).filter(e=>{let[,t]=e;return""!==t&&null!=t}):[];return(0,a.jsxs)("div",{className:"tw-pad",children:[(0,a.jsx)("div",{className:"rb-section-label",style:{marginTop:0},children:"Active window"}),null!==t&&null!==s?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"insp-top",children:[(0,a.jsx)("span",{className:"insp-ico",style:{color:!0===s.accent?"var(--accent)":"var(--fg-muted)"},children:function(e,t){let n=S[e];return(0,a.jsx)(n,{size:16})}(s.icon,16)}),(0,a.jsx)("span",{className:"insp-title",children:s.title})]}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Size"}),(0,a.jsxs)("span",{className:"rb-row-v mono",children:[Math.round(t.w)," \xd7 ",Math.round(t.h)]})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Position"}),(0,a.jsxs)("span",{className:"rb-row-v mono",children:[Math.round(t.x),", ",Math.round(t.y)]})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"State"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:t.max?"maximized":"floating"})]})]}),i.length>0&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"rb-section-label",children:"Configuration"}),(0,a.jsx)("div",{className:"rb-rows",children:i.map(e=>{let[t,n]=e;return(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:t}),(0,a.jsx)("span",{className:"rb-row-v mono",children:String(n).slice(0,20)||"—"})]},t)})})]}),(0,a.jsx)("div",{className:"rb-section-label insp-governance",children:"Governance"}),(0,a.jsxs)("div",{className:"rb-rows insp-governance","data-testid":"insp-governance",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Authority"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:nP[t.type].authority})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Persistence"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:nP[t.type].persistence})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Trust"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:nP[t.type].trustBoundary.join(", ")})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Lifecycle"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:nP[t.type].lifecycle.join(" → ")})]})]})]}):(0,a.jsx)("div",{className:"insp-empty",children:"No window focused"}),(0,a.jsx)("div",{className:"rb-section-label",children:"Workspace"}),(0,a.jsx)("div",{className:"rb-rows",children:(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Open windows"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:n})]})})]})}let aI=[{t:"Agent finished build-board",time:"2m",c:"var(--accent)"},{t:"diff-review ready to merge",time:"9m",c:"var(--info)"},{t:"lint-pass queued",time:"14m",c:"var(--fg-faint)"}];function aE(){return(0,a.jsx)("div",{className:"tw-list",children:aI.map((e,t)=>(0,a.jsxs)("div",{className:"nt-row",children:[(0,a.jsx)("span",{className:"dot",style:{background:e.c,marginTop:6}}),(0,a.jsxs)("span",{className:"nt-text",children:[(0,a.jsx)("span",{className:"nt-title",children:e.t}),(0,a.jsxs)("span",{className:"nt-time mono",children:[e.time," ago"]})]})]},t))})}function aM(){return(0,a.jsxs)("div",{className:"tw-pad",children:[(0,a.jsxs)("div",{className:"rb-placeholder",style:{height:150},children:[(0,a.jsx)("div",{className:"ph-stripes"}),(0,a.jsx)("span",{className:"rb-ph-label mono",children:"resources"})]}),(0,a.jsx)("div",{className:"rb-foot mono",style:{marginTop:14},children:"grows with the product"})]})}let aT="keiko-activity",aq={step:"var(--fg-dim)",approval:"var(--warn)",approved:"var(--accent)",rejected:"var(--danger)",stopped:"var(--danger)",open:"var(--info)","twin-approved":"var(--accent)","twin-denied":"var(--danger)"};function aP(){let e=function(){var e;let[,t]=(0,l.useState)(0);return(0,l.useEffect)(()=>{let e=()=>{t(e=>e+1)};return window.addEventListener(aT,e),()=>{window.removeEventListener(aT,e)}},[]),null!=(e=window.__keikoActivity)?e:[]}();return(0,a.jsxs)("div",{className:"tl",children:[0===e.length&&(0,a.jsxs)("div",{className:"tl-empty",children:["No activity yet.",(0,a.jsx)("br",{}),"Start an agent to see its actions stream here."]}),e.map((e,t)=>{var n,l;return(0,a.jsxs)("div",{className:"tl-row",children:[(0,a.jsx)("span",{className:"tl-dot",style:{background:null!=(n=aq[e.type])?n:"var(--fg-faint)"}}),(0,a.jsxs)("div",{className:"tl-body",children:[(0,a.jsx)("span",{className:"tl-text",children:e.text}),(0,a.jsxs)("span",{className:"tl-meta mono",children:[null!=(l=e.agent)?l:"workspace"," \xb7 ",new Date(e.time).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})]})]})]},t)})]})}function aA(e){let{chatId:t,scopeKind:n,currentScopeKind:s,candidateRelativePaths:i,onConnected:r,chat:o,updateScope:c=$.Mr,now:d=Date.now}=e,u=(0,l.useId)(),[h,p]=(0,l.useState)(!1),[m,f]=(0,l.useState)(null),g="workspace-root"!==n&&0===i.length,v=g||h,x=void 0!==s?"Update connected scope":"workspace-root"===n?"Connect repository":"directory"===n?"Connect folder":"Connect to chat",y=g?"Select a folder or file first":x;async function b(){if(!v){f(null),p(!0);try{let e={kind:n,relativePaths:[...i],connectedAtMs:d()},a=[...eh(null!=o?o:{}).filter(t=>t.kind!==e.kind||JSON.stringify(t.relativePaths)!==JSON.stringify(e.relativePaths)),e],l=await c(t,a);null==r||r(l.chat)}catch(e){f(e instanceof $.hD?"".concat(e.code,": ").concat(e.message):e instanceof Error?e.message:"Unable to connect scope.")}finally{p(!1)}}}return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",className:"scope-connect-btn",disabled:h,"aria-disabled":g,"aria-label":g?"Connect to chat (no selection)":x,"aria-describedby":g?u:void 0,title:y,onClick:()=>{g||b()},children:h?"Connecting…":x}),g?(0,a.jsx)("span",{id:u,className:"scope-connect-hint",children:"Select a folder or file first."}):null,null!==m?(0,a.jsx)("span",{role:"alert",className:"scope-connect-error",children:m}):null]})}let az={jsx:"js",js:"js",mjs:"js",ts:"ts",tsx:"ts",java:"java",kt:"kotlin",kts:"kotlin",py:"py",rb:"py",go:"go",rs:"rust",json:"json",yml:"yaml",yaml:"yaml",md:"md",markdown:"md",html:"html",xml:"html",css:"css",sql:"sql",sh:"sh",bash:"sh",cob:"cobol",cbl:"cobol",gradle:"js",graphql:"graphql",gql:"graphql",properties:"props",toml:"props",env:"props",dockerfile:"docker"};function aD(e){var t;let n=e.toLowerCase();if(".env"===n||n.startsWith(".env."))return"props";if("dockerfile"===n||n.startsWith("dockerfile"))return"docker";if(n.includes("docker-compose"))return"yaml";let a=n.split("."),l=a.length>1?a[a.length-1]:void 0;return void 0===l?"code":null!=(t=az[l])?t:"code"}let aL=new Set("const let var function return if else for while do switch case break continue import from export default class extends implements interface enum new async await yield of in typeof instanceof this super public private protected static final readonly void int long double float boolean char byte short val fun object data override companion package def pass lambda try catch except finally throw throws raise with as not and or is null nil None True False true false undefined struct impl trait pub use mod match where select insert update delete create table from join on group by order limit FROM RUN CMD ENV COPY WORKDIR EXPOSE ENTRYPOINT AS".split(" "));function aF(e){let t=[];return e.split(/(`[^`]+`|\*\*[^*]+\*\*)/).forEach(e=>{""!==e&&(e.startsWith("`")?t.push(["str",e]):e.startsWith("**")?t.push(["type",e]):t.push(["id",e]))}),t.length>0?t:[["id",e]]}function aO(e,t){if("md"===t)return e.split("\n").map(e=>{if(/^#{1,6}\s/.test(e))return[["head",e]];if(/^\s*```/.test(e))return[["com",e]];let t=/^(\s*)([-*+]|\d+\.)(\s)/.exec(e);if(null!==t){var n,a,l;let s=null!=(n=t[1])?n:"";return[["ws",s],["key",null!=(a=t[2])?a:""],["ws",null!=(l=t[3])?l:""],...aF(e.slice(t[0].length))]}return aF(e)});if("json"===t)return e.split("\n").map(e=>{let t=[],n=0;for(;n<e.length;){let a=e.slice(n),l=/^"(?:[^"\\]|\\.)*"/.exec(a);if(null!==l){let a=e.slice(n+l[0].length),s=/^\s*:/.test(a);t.push([s?"key2":"str",l[0]]),n+=l[0].length;continue}let s=/^-?\d[\d.eE+\-]*/.exec(a);if(null!==s){t.push(["num",s[0]]),n+=s[0].length;continue}let i=/^(true|false|null)\b/.exec(a);if(null!==i){t.push(["lit",i[0]]),n+=i[0].length;continue}let r=/^\s+/.exec(a);if(null!==r){t.push(["ws",r[0]]),n+=r[0].length;continue}t.push(["punct",a.charAt(0)]),n+=1}return t});let n="py"===t||"sh"===t||"yaml"===t||"props"===t||"docker"===t?{line:"#",block:null}:"sql"===t?{line:"--",block:["/*","*/"]}:"cobol"===t?{line:"*>",block:null}:"html"===t?{line:null,block:["\x3c!--","--\x3e"]}:{line:"//",block:["/*","*/"]},a={inBlock:!1},l=[];for(let t of e.split("\n"))l.push(function(e,t,n){let a=[],l=0;if(t.inBlock&&null!==n.block){let s=e.indexOf(n.block[1]);if(-1===s)return a.push(["com",e]),a;a.push(["com",e.slice(0,s+n.block[1].length)]),l=s+n.block[1].length,t.inBlock=!1}for(;l<e.length;){let i=e.slice(l);if(null!==n.line&&i.startsWith(n.line)){a.push(["com",i]);break}if(null!==n.block&&i.startsWith(n.block[0])){let s=e.indexOf(n.block[1],l+n.block[0].length);if(-1===s){a.push(["com",i]),t.inBlock=!0;break}a.push(["com",e.slice(l,s+n.block[1].length)]),l=s+n.block[1].length;continue}let r=/^(?:"(?:[^"\\]|\\.)*"?|'(?:[^'\\]|\\.)*'?)/.exec(i);if(null!==r&&r[0].length>1){a.push(["str",r[0]]),l+=r[0].length;continue}if(/^\d/.test(i)){var s;let e=/^\d[\w.]*/.exec(i),t=null!=(s=null==e?void 0:e[0])?s:i.charAt(0);a.push(["num",t]),l+=t.length;continue}let o=/^[@A-Za-z_$][\w$]*/.exec(i);if(null!==o){let t=o[0],n="id";aL.has(t)?n="key":t.startsWith("@")||/^[A-Z]/.test(t)?n="type":"("===e.charAt(l+t.length)&&(n="fn"),a.push([n,t]),l+=t.length;continue}let c=/^\s+/.exec(i);if(null!==c){a.push(["ws",c[0]]),l+=c[0].length;continue}let d=/^[^\w\s$@]+/.exec(i);if(null!==d){a.push(["punct",d[0]]),l+=d[0].length;continue}a.push(["id",i.charAt(0)]),l+=1}return a}(t,a,n));return l}function aK(e){if(!Number.isFinite(e)||e<=0)return"0 B";let t=["B","KB","MB","GB"],n=e,a=0;for(;n>=1024&&a<t.length-1;)n/=1024,a+=1;let l=0===a?n.toFixed(0):n.toFixed(n>=10?1:2);return"".concat(l," ").concat(t[a])}function aB(e){return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(new Date(e))}function aW(e){let{label:t,value:n}=e;return(0,a.jsxs)("div",{className:"fpv-meta-row",children:[(0,a.jsx)("span",{children:t}),(0,a.jsx)("strong",{children:n})]})}function aU(e){var t,n,s,i,r;let{root:c,path:d,onClose:u}=e,h=o(),p=null==h?void 0:h.activeChat,m=d.length>0?[d]:[],[f,g]=(0,l.useState)(null),[v,x]=(0,l.useState)(!0),[y,b]=(0,l.useState)(null);(0,l.useEffect)(()=>{let e=!1;return x(!0),b(null),g(null),(0,$.q7)(c,d).then(t=>{e||g(t)}).catch(t=>{e||b(t instanceof $.hD&&"DENIED"===t.code?{message:"This file is excluded from the read surface for safety (matches a deny pattern such as .env, *.pem, node_modules, .git, …).",denied:!0}:t instanceof Error?{message:t.message,denied:!1}:{message:"Unable to read this file.",denied:!1})}).finally(()=>{e||x(!1)}),()=>{e=!0}},[d,c]);let j=(null==y?void 0:y.denied)===!0,w=null!==f?"text"===f.kind?aD(f.name):"image"===f.kind?f.mime:null!=(r=f.extension)?r:"binary":j?"denied":null!==y?"error":"loading",k=j?"Hidden file":null!=(n=null==f?void 0:f.name)?n:null!==y?"Preview unavailable":"Loading preview",N=(null==f?void 0:f.kind)==="text"&&f.content.length<=2e5,C=(null==f?void 0:f.kind)==="text"?N?aO(f.content,aD(f.name)):f.content.split("\n").map(e=>[["id",e]]):[];return(0,a.jsxs)("div",{className:"fpv",children:[(0,a.jsxs)("div",{className:"fpv-bar",children:[(0,a.jsx)("button",{className:"fpv-back",type:"button",onClick:u,title:"Back to files","aria-label":"Back to files",children:(0,a.jsx)(S.back,{size:15})}),(0,a.jsx)(ap,{name:j||null===f?"":f.name}),(0,a.jsx)("span",{className:"fpv-name",title:k,children:k}),(0,a.jsx)("span",{className:"fpv-lang mono",children:w}),(0,a.jsx)("span",{className:"spacer"}),void 0!==p&&null!==h?(0,a.jsx)(aA,{chatId:p.id,scopeKind:"files",currentScopeKind:null==(t=p.connectedScope)?void 0:t.kind,candidateRelativePaths:m,chat:p,onConnected:h.replaceChat}):null,(0,a.jsx)("button",{className:"fpv-back",type:"button",onClick:u,title:"Close preview","aria-label":"Close preview",children:(0,a.jsx)(S.close,{size:15})})]}),v?(0,a.jsx)("div",{className:"fpv-state",children:"Loading preview..."}):null,null!==y?(0,a.jsx)("div",{className:"fpv-state fpv-error",role:"alert",children:y.message}):null,(null==f?void 0:f.kind)==="text"?(0,a.jsxs)(a.Fragment,{children:[f.truncated?(0,a.jsxs)("div",{className:"fpv-banner",children:["Preview truncated at ",aK(f.maxBytes),". Open the file in the editor for full content."]}):null,N?null:(0,a.jsx)("div",{className:"fpv-banner",children:"Syntax highlighting disabled for large previews."}),(0,a.jsx)("div",{className:"fpv-code mono",children:C.map((e,t)=>(0,a.jsxs)("div",{className:"fpv-line",children:[(0,a.jsx)("span",{className:"fpv-num",children:t+1}),(0,a.jsx)("span",{className:"fpv-src",children:e.map((e,t)=>(0,a.jsx)("span",{className:"hl-".concat(e[0]),children:e[1]},t))})]},t))})]}):null,(null==f?void 0:f.kind)==="image"?(0,a.jsxs)("div",{className:"fpv-image-pane",children:[(0,a.jsx)("div",{className:"fpv-image-card",children:(0,a.jsx)("img",{className:"fpv-image",src:f.dataUrl,alt:f.name})}),(0,a.jsxs)("div",{className:"fpv-meta",children:[(0,a.jsx)(aW,{label:"Type",value:f.mime}),(0,a.jsx)(aW,{label:"Size",value:aK(f.sizeBytes)}),(0,a.jsx)(aW,{label:"Modified",value:aB(f.modifiedAt)})]})]}):null,(null==f?void 0:f.kind)==="binary"?(0,a.jsx)("div",{className:"fpv-meta-pane",children:(0,a.jsxs)("div",{className:"fpv-meta-card",children:[(0,a.jsx)(ap,{name:f.name}),(0,a.jsx)("h3",{children:f.name}),(0,a.jsx)("p",{children:"too_large"===f.reason?"Preview disabled because this file exceeds ".concat(aK(null!=(s=f.maxBytes)?s:0),"."):"No safe text or image preview is available for this file type."}),(0,a.jsxs)("div",{className:"fpv-meta",children:[(0,a.jsx)(aW,{label:"Type",value:f.mime}),(0,a.jsx)(aW,{label:"Extension",value:null!=(i=f.extension)?i:"none"}),(0,a.jsx)(aW,{label:"Size",value:aK(f.sizeBytes)}),(0,a.jsx)(aW,{label:"Modified",value:aB(f.modifiedAt)})]})]})}):null]})}function a_(e){let t=e.replace(/[/\\]+$/,""),n=Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\"));return n<0?null:0===n?"/":/^[A-Za-z]:$/.test(t.slice(0,n))?"".concat(t.slice(0,n),"\\"):t.slice(0,n)}function aH(e){var t;let{root:n,onActiveFileChange:s,onRootChange:i}=e,r=o(),c=null==r?void 0:r.activeChat,d=null==n?void 0:n.trim(),u=void 0!==d&&d.length>0?d:null,[h,p]=(0,l.useState)(null),m=null!=(t=null!=u?u:h)?t:"",[f,g]=(0,l.useState)(null),[v,x]=(0,l.useState)(""),[y,b]=(0,l.useState)(null),[j,w]=(0,l.useState)({}),[k,N]=(0,l.useState)(()=>new Set([""])),[C,R]=(0,l.useState)(0),I=(0,l.useRef)(s);I.current=s,(0,l.useEffect)(()=>{if(null!==u)return;let e=!1;return(0,$.vj)().then(t=>{var n;if(e)return;let a=null==(n=t.projects.find(e=>e.available))?void 0:n.path;p(null!=a?a:null)}).catch(()=>{e||p(null)}),()=>{e=!0}},[u]);let E=(0,l.useCallback)(async e=>{if(0===m.length)return void w(t=>({...t,[e]:{entries:[],truncated:!1,loading:!1,error:"No registered project is available."}}));w(t=>{var n,a,l,s;return{...t,[e]:{entries:null!=(l=null==(n=t[e])?void 0:n.entries)?l:[],truncated:null!=(s=null==(a=t[e])?void 0:a.truncated)&&s,loading:!0,error:null}}});try{let n=await (0,$.KD)(m,e);if(""===e){var t;g(n.root),null==(t=I.current)||t.call(I,null,n.root)}w(t=>({...t,[e]:{entries:n.entries,truncated:n.truncated,loading:!1,error:null}}))}catch(t){w(n=>{var a,l,s,i;return{...n,[e]:{entries:null!=(s=null==(a=n[e])?void 0:a.entries)?s:[],truncated:null!=(i=null==(l=n[e])?void 0:l.truncated)&&i,loading:!1,error:t instanceof Error?t.message:"Unable to read this folder."}}})}},[m]);(0,l.useEffect)(()=>{var e;b(null),null==(e=I.current)||e.call(I,null,null),g(null),N(new Set([""])),w({}),E("")},[m,E,C]),(0,l.useEffect)(()=>{x(null!=f?f:m.length>0?m:"")},[f,m]);let M=(0,l.useCallback)(e=>{let t=e.trim();void 0!==i&&0!==t.length&&t!==(null!=f?f:m)&&i(t)},[i,f,m]),T=(0,l.useCallback)(()=>{let e=a_(null!=f?f:m);null!==e&&M(e)},[f,m,M]),q=(e,t)=>{var n;return null===r||void 0===c||0===m.length||"workspace-root"!==e&&0===t.length?null:(0,a.jsx)(aA,{chatId:c.id,scopeKind:e,currentScopeKind:null==(n=c.connectedScope)?void 0:n.kind,candidateRelativePaths:"workspace-root"===e?[]:[t],chat:c,onConnected:r.replaceChat})},P=function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:j[e];return(0,a.jsxs)("div",{className:"tr-dir",children:[(null==n?void 0:n.loading)===!0?(0,a.jsx)("div",{className:"files-note",style:{paddingLeft:22+13*t},children:"Loading..."}):null,(null==n?void 0:n.error)!==null&&(null==n?void 0:n.error)!==void 0?(0,a.jsxs)("div",{className:"files-error",style:{marginLeft:8+13*t},children:[(0,a.jsx)("span",{children:n.error}),(0,a.jsx)("button",{type:"button",onClick:()=>{E(e)},children:"Retry"})]}):null,null==n?void 0:n.entries.map(e=>((e,t)=>{let n=8+13*t,l=k.has(e.path);if("directory"===e.kind){let s=j[e.path];return(0,a.jsxs)("div",{className:"tr-row-wrap",children:[(0,a.jsxs)("button",{className:"tr-row","data-readable":e.readable,style:{paddingLeft:n},type:"button",disabled:!e.readable,"aria-expanded":l,onClick:()=>(e=>{if(!e.readable)return;let t=k.has(e.path);N(t=>{let n=new Set(t);return n.has(e.path)?n.delete(e.path):n.add(e.path),n}),t||void 0!==j[e.path]||E(e.path)})(e),title:e.readable?e.path:"Symlink target is outside the selected root",children:[(0,a.jsx)("span",{className:"tr-caret","data-open":l,children:(0,a.jsx)(S.chevronR,{size:11})}),(0,a.jsx)("span",{className:"fi-fallback",style:{color:"var(--accent)"},children:(0,a.jsx)(S.folder,{size:14})}),(0,a.jsx)("span",{className:"tr-name tr-folder",children:e.name}),e.symlink?(0,a.jsx)("span",{className:"tr-badge",children:"link"}):null]}),e.readable?(0,a.jsx)("div",{className:"tr-connect",style:{paddingLeft:n+20},children:q("directory",e.path)}):null,l?P(e.path,t+1,s):null]},e.path)}return(0,a.jsxs)("button",{className:"tr-row tr-file","data-active":y===e.path,"data-readable":e.readable,style:{paddingLeft:n+14},type:"button",disabled:!e.readable,onClick:()=>{var t;b(e.path),null==(t=I.current)||t.call(I,e.path,null!=f?f:m)},title:e.readable?e.path:"Symlink target is outside the selected root",children:[(0,a.jsx)(ap,{name:e.name}),(0,a.jsx)("span",{className:"tr-name",children:e.name}),e.symlink?(0,a.jsx)("span",{className:"tr-badge",children:"link"}):null,(0,a.jsx)("span",{className:"tr-meta mono",children:function(e){if(!Number.isFinite(e)||e<=0)return"0 B";let t=["B","KB","MB","GB"],n=e,a=0;for(;n>=1024&&a<t.length-1;)n/=1024,a+=1;let l=0===a?n.toFixed(0):n.toFixed(n>=10?1:2);return"".concat(l," ").concat(t[a])}(e.sizeBytes)})]},e.path)})(e,t)),void 0===n||n.loading||null!==n.error||0!==n.entries.length?null:(0,a.jsx)("div",{className:"files-note",style:{paddingLeft:22+13*t},children:"Empty folder."}),(null==n?void 0:n.truncated)===!0?(0,a.jsx)("div",{className:"files-note files-warning",style:{paddingLeft:22+13*t},children:"Showing the first 1000 entries."}):null]})};return null!==y?(0,a.jsx)(aU,{root:null!=f?f:m,path:y,onClose:()=>{var e;b(null),null==(e=I.current)||e.call(I,null,null!=f?f:m)}}):(0,a.jsxs)("div",{className:"files",children:[void 0!==i?(0,a.jsxs)("form",{className:"files-root-bar",role:"group","aria-label":"Folder root",onSubmit:e=>{e.preventDefault(),M(v)},children:[(0,a.jsx)("button",{type:"button",className:"files-root-up",onClick:T,disabled:null===a_(null!=f?f:m),title:"Open parent folder","aria-label":"Open parent folder",children:(0,a.jsx)(S.arrowUp,{size:13})}),(0,a.jsx)("input",{type:"text",className:"files-root-input mono","aria-label":"Folder path — open any folder on this machine",placeholder:"/path/to/any/folder",spellCheck:!1,value:v,onChange:e=>x(e.target.value)}),(0,a.jsx)("button",{type:"submit",className:"files-root-open",title:"Open this folder",children:"Open"})]}):null,(0,a.jsx)("button",{className:"files-refresh",type:"button",onClick:()=>R(e=>e+1),title:"Refresh folder","aria-label":"Refresh folder",children:(0,a.jsx)(S.reset,{size:13})}),(()=>{let e=q("workspace-root","");return null===e?null:(0,a.jsxs)("div",{className:"files-scope-bar",role:"group","aria-label":"Repository scope connector",children:[(0,a.jsx)("span",{className:"files-scope-label",children:"Repository scope"}),e]})})(),(0,a.jsx)("div",{className:"tr files-tree",children:P("",0)})]})}let aJ=[{n:1,t:[["k","const"],[""," "],["v","{ useState }"],[""," = "],["v","React"]]},{n:2,t:[]},{n:3,t:[["k","function"],[""," "],["f","WindowFrame"],["p","({ win, on })"],[""," {"]]},{n:4,t:[[""," "],["k","const"],[""," [drag, setDrag] = "],["f","useState"],["p","(null)"]]},{n:5,t:[[""," "],["k","return"],[""," "],["p","<section"],["a"," className"],["","="],["s",'"window"'],["p",">"]]},{n:6,t:[[""," "],["c","// drag \xb7 resize \xb7 snap"]]},{n:7,t:[[""," "],["p","</section>"]]},{n:8,t:[["","}"]]}];function aV(e){let{file:t="windows.jsx"}=e;return(0,a.jsxs)("div",{className:"editor",children:[(0,a.jsxs)("div",{className:"ed-tabs mono",children:[(0,a.jsxs)("span",{className:"ed-tab active",children:[(0,a.jsx)(S.editor,{size:12})," ",t]}),(0,a.jsx)("span",{className:"ed-tab",children:"styles.css"})]}),(0,a.jsx)("div",{className:"ed-code mono",children:aJ.map(e=>(0,a.jsxs)("div",{className:"ed-line",children:[(0,a.jsx)("span",{className:"ed-num",children:e.n}),(0,a.jsx)("span",{className:"ed-src",children:e.t.map((e,t)=>(0,a.jsx)("span",{className:""===e[0]?void 0:"tk-".concat(e[0]),children:e[1]},t))})]},e.n))})]})}async function aG(e,t){var n,a;let l=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),s="GET"!==l&&"HEAD"!==l,i=await fetch(e,{...t,headers:{Accept:"application/json",...s?{"Content-Type":"application/json"}:{},...s?{"X-Keiko-CSRF":"1"}:{},...null!=(a=null==t?void 0:t.headers)?a:{}}});if(!i.ok){let e="INTERNAL",t="HTTP ".concat(i.status.toString());try{let n=await i.json();e=n.error.code,t=n.error.message}catch(e){}throw new $.hD(e,t,i.status)}if(204!==i.status)return i.json()}async function aX(e){return aG("/api/browser/status?port=".concat(encodeURIComponent(String(e))))}async function aY(e){return aG("/api/browser/sessions",{method:"POST",body:JSON.stringify({port:e})})}async function aZ(e){await aG("/api/browser/sessions/".concat(encodeURIComponent(e)),{method:"DELETE"})}async function aQ(e,t){return aG("/api/browser/sessions/".concat(encodeURIComponent(e),"/navigate"),{method:"POST",body:JSON.stringify({url:t})})}async function a$(e){return aG("/api/browser/sessions/".concat(encodeURIComponent(e),"/screenshot"),{method:"POST",body:JSON.stringify({})})}async function a0(e,t){return aG("/api/browser/sessions/".concat(encodeURIComponent(e),"/apply"),{method:"POST",body:JSON.stringify({captureSeq:t})})}async function a1(e){return aG("/api/browser/sessions/".concat(encodeURIComponent(e),"/content"),{method:"POST",body:JSON.stringify({})})}function a2(e){return e instanceof $.hD?{code:e.code,message:e.message}:e instanceof Error?{code:"INTERNAL",message:e.message}:{code:"INTERNAL",message:"Unexpected error."}}function a5(e){var t,n;let s=null!=(t=e.cdpPort)?t:9222,i=null!=(n=e.url)?n:"http://localhost:5173",[r,o]=(0,l.useState)(String(s)),[c,d]=(0,l.useState)(i),[u,h]=(0,l.useState)(null),[p,m]=(0,l.useState)(null),[f,g]=(0,l.useState)(!1),[v,x]=(0,l.useState)(null),[y,b]=(0,l.useState)([]),[j,w]=(0,l.useState)(null),[k,N]=(0,l.useState)(null),[S,C]=(0,l.useState)(null),R=(0,l.useRef)(null),I=(0,l.useCallback)(()=>{x(null)},[]),E=(0,l.useCallback)(e=>{b(t=>{let n=[...t,e];return n.length>50?n.slice(n.length-50):n}),"navigated"===e.kind&&"string"==typeof e.payload.originOnly&&C(e.payload.originOnly),"error"===e.kind&&x({code:"string"==typeof e.payload.code?e.payload.code:"INTERNAL",message:"string"==typeof e.payload.message?e.payload.message:"Error."})},[]);(0,l.useEffect)(()=>{var e,t;if(null===u){null==(e=R.current)||e.close(),R.current=null;return}let n=new EventSource((t=u.sessionId,"/api/browser/sessions/".concat(encodeURIComponent(t),"/events")));for(let e of["session-opened","navigated","screenshot-captured","page-content-captured","session-closed","trust-warning","error"])n.addEventListener("browser:".concat(e),e=>{try{let t=JSON.parse(e.data);E(t)}catch(e){}});return R.current=n,()=>{n.close(),R.current=null}},[u,E]);let M=(0,l.useCallback)(async()=>{I(),g(!0);try{let e=Number.parseInt(r,10),t=await aX(e);m(t)}catch(e){x(a2(e))}finally{g(!1)}},[r,I]),T=(0,l.useCallback)(async()=>{I(),g(!0);try{let e=Number.parseInt(r,10),t=await aY(e);h(t),b([]),N(null),C(null)}catch(e){x(a2(e))}finally{g(!1)}},[r,I]),q=(0,l.useCallback)(async()=>{if(null!==u){I(),g(!0);try{await aZ(u.sessionId),h(null),w(null),N(null),C(null)}catch(e){x(a2(e))}finally{g(!1)}}},[u,I]),P=(0,l.useCallback)(async()=>{if(null!==u){I(),g(!0);try{let e=await aQ(u.sessionId,c);C(e.originOnly)}catch(e){x(a2(e))}finally{g(!1)}}},[u,c,I]),A=(0,l.useCallback)(async()=>{if(null!==u){I(),g(!0);try{let e=await a$(u.sessionId);e.persisted||w({seq:e.seq,dataBase64:e.dataBase64})}catch(e){x(a2(e))}finally{g(!1)}}},[u,I]),z=(0,l.useCallback)(async()=>{if(null!==u&&null!==j){I(),g(!0);try{let e=await a0(u.sessionId,j.seq);e.persisted&&N(e.path),w(null)}catch(e){x(a2(e))}finally{g(!1)}}},[u,j,I]),D=(0,l.useCallback)(async()=>{if(null!==u){I(),g(!0);try{await a1(u.sessionId)}catch(e){x(a2(e))}finally{g(!1)}}},[u,I]),L=(0,l.useMemo)(()=>f||null!==u,[f,u]),F=(0,l.useMemo)(()=>f||null===u,[f,u]);return(0,a.jsxs)("div",{className:"browser","aria-label":"Browser tool",children:[(0,a.jsxs)("div",{className:"bw-bar",children:[(0,a.jsx)("span",{className:"bw-dot",style:{background:null===u?"var(--line-strong)":"var(--ok)"},"aria-hidden":"true"}),(0,a.jsxs)("label",{className:"bw-field",children:[(0,a.jsx)("span",{className:"bw-field-label",children:"Port"}),(0,a.jsx)("input",{type:"text",inputMode:"numeric",className:"bw-input",value:r,onChange:e=>o(e.target.value),disabled:null!==u||f})]}),(0,a.jsxs)("label",{className:"bw-field bw-field-url",children:[(0,a.jsx)("span",{className:"bw-field-label",children:"URL"}),(0,a.jsx)("input",{type:"url",className:"bw-input bw-input-url",value:c,onChange:e=>d(e.target.value),disabled:f})]})]}),(0,a.jsxs)("div",{className:"bw-actions",role:"toolbar","aria-label":"Browser actions",children:[(0,a.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{M()},disabled:f||null!==u,children:"Check"}),(0,a.jsx)("button",{type:"button",className:"bw-btn bw-btn-primary",onClick:()=>{T()},disabled:L,children:"Open session"}),(0,a.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{P()},disabled:F,children:"Navigate"}),(0,a.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{A()},disabled:F,children:"Screenshot"}),(0,a.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{z()},disabled:f||null===j,children:"Apply"}),(0,a.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{D()},disabled:F,children:"Capture HTML"}),(0,a.jsx)("button",{type:"button",className:"bw-btn bw-btn-danger",onClick:()=>{q()},disabled:F,children:"Close"})]}),null!==p&&null===u?(0,a.jsxs)("p",{className:"bw-status",role:"status",children:["Reachable: ",p.reachable?"yes":"no",null===p.browserVersion?"":" — ".concat(p.browserVersion)]}):null,null!==S?(0,a.jsxs)("p",{className:"bw-status",role:"status","aria-live":"polite",children:["Current origin: ",(0,a.jsx)("span",{className:"mono",children:S})]}):null,null!==j?(0,a.jsx)("p",{className:"bw-status",role:"status",children:"Screenshot ready (dry-run) — press Apply to persist."}):null,null!==k?(0,a.jsxs)("p",{className:"bw-status",role:"status",children:["Persisted as ",(0,a.jsx)("span",{className:"mono",children:k}),"."]}):null,null!==v?(0,a.jsxs)("div",{className:"bw-error",role:"alert",children:[(0,a.jsx)("strong",{children:v.code}),": ",v.message]}):null,(0,a.jsx)("div",{className:"bw-view",children:null!==j?(0,a.jsx)("img",{className:"bw-screenshot",src:"data:image/png;base64,".concat(j.dataBase64),alt:"Pending screenshot preview"}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"ph-stripes","aria-hidden":"true"}),(0,a.jsx)("div",{className:"bw-overlay mono",children:null===u?"no session":"live preview"})]})}),(0,a.jsx)("div",{className:"bw-log","aria-label":"Browser event log","aria-live":"polite","aria-atomic":"false",children:(0,a.jsx)("ul",{className:"bw-log-list",children:y.slice(-10).map((e,t)=>(0,a.jsxs)("li",{className:"bw-log-item",children:[(0,a.jsx)("span",{className:"bw-log-kind",children:function(e){switch(e){case"session-opened":return"session opened";case"navigated":return"navigated";case"screenshot-captured":return"screenshot captured";case"page-content-captured":return"content captured";case"session-closed":return"session closed";case"trust-warning":return"trust warning";case"error":return"error"}}(e.kind)}),(0,a.jsx)("span",{className:"bw-log-detail mono",children:function(e){let t=e.payload;if("navigated"===e.kind){let e="string"==typeof t.originOnly?t.originOnly:"",n="number"==typeof t.httpStatus?" (".concat(String(t.httpStatus),")"):"";return"".concat(e).concat(n)}return"screenshot-captured"===e.kind?!0===t.persisted?"persisted":"dry-run":"page-content-captured"===e.kind?"number"==typeof t.byteLength?"".concat(String(t.byteLength)," bytes"):"":"error"===e.kind||"trust-warning"===e.kind?"string"==typeof t.message?t.message:"string"==typeof t.warning?t.warning:"":""}(e)})]},"".concat(String(e.kind),"-").concat(String(t))))})})]})}async function a3(e,t){var n,a;let l=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),s="GET"!==l&&"HEAD"!==l,i=await fetch(e,{...t,headers:{Accept:"application/json",...s?{"Content-Type":"application/json"}:{},...s?{"X-Keiko-CSRF":"1"}:{},...null!=(a=null==t?void 0:t.headers)?a:{}}});if(!i.ok){let e="INTERNAL",t="HTTP ".concat(i.status.toString());try{let n=await i.json();e=n.error.code,t=n.error.message}catch(e){}throw new $.hD(e,t,i.status)}if(204!==i.status)return i.json()}async function a4(){return a3("/api/terminal/policy")}async function a6(e,t){let n=new URLSearchParams;return n.set("projectId",e),void 0!==t&&t.length>0&&n.set("path",t),a3("/api/terminal/directories?".concat(n.toString()))}async function a8(e){return a3("/api/terminal/executions",{method:"POST",body:JSON.stringify(e)})}async function a7(e){await a3("/api/terminal/executions/".concat(encodeURIComponent(e)),{method:"DELETE"})}function a9(e){return e instanceof $.hD?{code:e.code,message:e.message}:e instanceof Error?{code:"INTERNAL",message:e.message}:{code:"INTERNAL",message:"Unexpected error."}}function le(e){var t,n;let[s,i]=(0,l.useState)(null),[r,o]=(0,l.useState)(""),[c,d]=(0,l.useState)(""),[u,h]=(0,l.useState)(null!=(t=e.cwd)?t:""),[p,m]=(0,l.useState)(null!=(n=e.projectPath)?n:""),[f,g]=(0,l.useState)(!1),[v,x]=(0,l.useState)(null),[y,b]=(0,l.useState)(null),[j,w]=(0,l.useState)(null),[k,N]=(0,l.useState)([]),S=(0,l.useRef)(null),C=(0,l.useRef)(!1),R=(0,l.useRef)(null),[I,E]=(0,l.useState)([]);(0,l.useEffect)(()=>{let e=!1;return a4().then(t=>{e||(i(t),o(e=>{var n;return e.length>0?e:null!=(n=t.commands[0])?n:""}))}).catch(t=>{e||w(a9(t))}),()=>{e=!0}},[]),(0,l.useEffect)(()=>{if(0===p.length)return void E([]);let e=!1;return a6(p,u.length>0?u:void 0).then(t=>{e||E(t.entries)}).catch(()=>{e||E([])}),()=>{e=!0}},[p,u]),(0,l.useEffect)(()=>{let e=new EventSource("/api/terminal/events");S.current=e;let t=e=>{try{let t=JSON.parse(e.data);if("execution-started"===t.kind&&C.current){let e=t.payload;"string"==typeof e.requestId&&e.requestId===R.current&&x(e=>null!==e?e:t.executionId)}if("execution-completed"===t.kind||"execution-failed"===t.kind||"execution-cancelled"===t.kind){let e=t.payload;"string"==typeof e.requestId&&e.requestId===R.current&&x(e=>null===e||e!==t.executionId?e:null)}N(e=>{let n=[t,...e];return n.length>30?n.slice(0,30):n})}catch(e){}};for(let n of["execution-started","execution-completed","execution-failed","execution-cancelled"])e.addEventListener("terminal:".concat(n),t);return()=>{e.close(),S.current=null}},[]);let M=(0,l.useCallback)(async e=>{if(e.preventDefault(),f)return;w(null),b(null),x(null);let t="function"==typeof crypto.randomUUID?crypto.randomUUID():"terminal-".concat(Date.now().toString(36),"-").concat(Math.random().toString(36).slice(2));R.current=t;let n=function(e){let t=e.trim();return 0===t.length?[]:t.split(/\s+/)}(c);C.current=!0,g(!0);try{let e={projectId:p,command:r,args:n,...u.length>0?{cwd:u}:{},requestId:t},a=await a8(e);b(a)}catch(e){w(a9(e))}finally{C.current=!1,g(!1),R.current=null,x(null)}},[c,r,u,p,f]),T=(0,l.useCallback)(async()=>{if(null!==v)try{await a7(v)}catch(e){w(a9(e))}},[v]),q=(0,l.useMemo)(()=>{var e;return null!=(e=null==s?void 0:s.limits)?e:null},[s]);return(0,a.jsxs)("div",{className:"terminal",children:[(0,a.jsxs)("form",{className:"tm-form",onSubmit:e=>void M(e),children:[(0,a.jsxs)("label",{className:"tm-field",children:[(0,a.jsx)("span",{children:"Project path"}),(0,a.jsx)("input",{type:"text",value:p,onChange:e=>m(e.target.value),placeholder:"/absolute/path/to/project",required:!0})]}),(0,a.jsxs)("label",{className:"tm-field",children:[(0,a.jsx)("span",{children:"Command"}),(0,a.jsx)("select",{value:r,onChange:e=>o(e.target.value),disabled:null===s,required:!0,children:null==s?void 0:s.commands.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]}),(0,a.jsxs)("label",{className:"tm-field",children:[(0,a.jsx)("span",{children:"Args (space-separated)"}),(0,a.jsx)("input",{type:"text",value:c,onChange:e=>d(e.target.value),placeholder:"e.g. -la src"})]}),(0,a.jsxs)("label",{className:"tm-field",children:[(0,a.jsx)("span",{children:"Working directory (optional)"}),(0,a.jsx)("input",{type:"text",value:u,onChange:e=>h(e.target.value),placeholder:"(project root)",list:"tm-cwd-suggestions"}),(0,a.jsx)("datalist",{id:"tm-cwd-suggestions",children:I.map(e=>(0,a.jsx)("option",{value:e.path},e.path))})]}),(0,a.jsxs)("div",{className:"tm-actions",children:[(0,a.jsx)("button",{type:"submit",className:"tm-action",disabled:f||null===s,children:f?"Running…":"Run"}),f?(0,a.jsx)("button",{type:"button",className:"tm-action",disabled:null===v,onClick:()=>void T(),children:"Cancel"}):null]}),null!==q?(0,a.jsxs)("p",{className:"tm-limits",children:["Limits: ",q.maxOutputBytes," bytes output, ",q.defaultTimeoutMs," ms timeout"]}):null]}),null!==j?(0,a.jsxs)("div",{className:"tm-error",role:"alert",children:[(0,a.jsxs)("span",{className:"tm-error-text",children:[(0,a.jsx)("strong",{children:j.code}),": ",j.message]}),(0,a.jsx)("button",{type:"button",className:"tm-error-dismiss","aria-label":"Dismiss error",onClick:()=>w(null),children:"✕"})]}):null,null!==y?(0,a.jsxs)("div",{className:"tm-result",role:"status","aria-live":"polite",children:[(0,a.jsxs)("div",{className:"tm-badges",children:[(0,a.jsxs)("span",{className:0===y.exitCode?"tm-badge tm-badge-ok":"tm-badge tm-badge-fail",children:["exit ",String(y.exitCode)]}),(0,a.jsxs)("span",{className:"tm-badge",children:[y.durationMs," ms"]}),y.truncated?(0,a.jsx)("span",{className:"tm-badge tm-badge-warn",children:"truncated"}):null,y.timedOut?(0,a.jsx)("span",{className:"tm-badge tm-badge-warn",children:"timed out"}):null]}),y.stdout.length>0?(0,a.jsx)("pre",{className:"tm-stdout",children:y.stdout}):null,y.stderr.length>0?(0,a.jsx)("pre",{className:"tm-stderr",children:y.stderr}):null]}):null,(0,a.jsx)("ul",{className:"tm-events",role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":"false","aria-label":"Recent terminal events",children:k.map((e,t)=>(0,a.jsxs)("li",{className:"tm-event",children:[(0,a.jsx)("span",{className:"tm-event-kind",children:function(e){switch(e){case"execution-started":return"started";case"execution-completed":return"completed";case"execution-failed":return"failed";case"execution-cancelled":return"cancelled"}}(e.kind)}),(0,a.jsx)("span",{className:"tm-event-detail",children:function(e){let t=e.payload;return"execution-completed"===e.kind?["number"==typeof t.exitCode||null===t.exitCode?"exit ".concat(String(t.exitCode)):"","number"==typeof t.durationMs?"".concat(String(t.durationMs),"ms"):""].filter(Boolean).join(" \xb7 "):"execution-failed"===e.kind?"string"==typeof t.code?t.code:"":"execution-started"===e.kind&&"string"==typeof t.command?t.command:""}(e)})]},"".concat(e.executionId,"-").concat(String(t),"-").concat(e.kind)))})]})}function lt(e){return e.startsWith("a/")||e.startsWith("b/")?e.slice(2):e}function ln(e){return e instanceof $.hD?{code:e.code,message:e.message}:e instanceof Error?{code:"INTERNAL",message:e.message}:{code:"INTERNAL",message:"Unexpected error."}}function la(e){return("dry-run"===e.status||"fix-proposed"===e.status)&&void 0!==e.proposedDiff&&void 0===e.appliedAt}function ll(e){return void 0!==e.proposedDiff&&""!==e.proposedDiff}function ls(e){let{href:t,hasManifest:n,error:l}=e;return n?(0,a.jsx)("a",{className:"rv-evidence-link",href:t,target:"_blank",rel:"noopener noreferrer",children:"Evidence"}):null!==l?(0,a.jsx)("span",{className:"rv-evidence-link rv-evidence-error",role:"status","aria-label":"Evidence unavailable: ".concat(l.message),title:l.message,children:"Evidence error"}):(0,a.jsx)("span",{className:"rv-evidence-link rv-evidence-disabled",role:"link","aria-disabled":"true",children:"Evidence"})}function li(e){let{tokens:t}=e;return(0,a.jsx)(a.Fragment,{children:t.map((e,t)=>(0,a.jsx)("span",{className:"hl-".concat(e[0]),children:e[1]},t))})}function lr(e){var t,n,l;let s,{line:i,lang:r}=e,o="add"===i.kind?"+":"del"===i.kind?"−":"ctx"===i.kind?"\xb7":"",c="ctx"===i.kind?"":" rv-".concat(i.kind);if("meta"!==i.kind&&"code"!==r){let e=null!=(t=aO(i.text,aD(r))[0])?t:[];s=(0,a.jsx)(li,{tokens:e})}else s=i.text;return(0,a.jsxs)("div",{className:"rv-line".concat(c),children:[(0,a.jsx)("span",{className:"rv-sr-only",children:{add:"Added line",del:"Deleted line",ctx:"Context line",meta:"Diff metadata"}[i.kind]}),(0,a.jsx)("span",{className:"rv-num-old rv-num",children:null!=(n=i.oldLine)?n:""}),(0,a.jsx)("span",{className:"rv-num-new rv-num",children:null!=(l=i.newLine)?l:""}),(0,a.jsx)("span",{className:"rv-gutter","aria-hidden":"true",children:o}),(0,a.jsx)("code",{className:"rv-src",children:s})]})}function lo(e){let{hunk:t,lang:n}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"rv-hunk mono","aria-label":"Hunk header ".concat(t.header),children:[(0,a.jsx)("span",{className:"rv-sr-only",children:"Hunk header"}),t.header]}),t.lines.map((e,t)=>(0,a.jsx)(lr,{line:e,lang:n},t))]})}function lc(e){var t;let{file:n,index:l,changedFiles:s,sectionRef:i}=e,r=s.find(e=>e.path===n.path),o=n.path.includes(".")&&null!=(t=n.path.split(".").pop())?t:"code";return(0,a.jsxs)("section",{id:"rv-file-".concat(l),"aria-labelledby":"rv-file-".concat(l,"-h"),ref:i,children:[(0,a.jsxs)("h3",{id:"rv-file-".concat(l,"-h"),className:"rv-file mono",children:[(0,a.jsx)("span",{className:"rv-path",children:n.path}),void 0!==n.oldPath&&(0,a.jsxs)("span",{className:"rv-oldpath",children:[" (was ",n.oldPath,")"]}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("span",{className:"rv-stat add",children:["+",n.addedLines]}),(0,a.jsxs)("span",{className:"rv-stat del",children:["−",n.removedLines]}),(null==r?void 0:r.elevatedReview)===!0&&(0,a.jsx)("span",{className:"rv-elevated","aria-label":"Elevated review",children:"!"})]}),(0,a.jsx)("div",{className:"rv-code mono",children:n.hunks.map((e,t)=>(0,a.jsx)(lo,{hunk:e,lang:o},t))})]})}function ld(e){var t,n,s;let{runId:i}=e,[r,o]=(0,l.useState)(null),[c,d]=(0,l.useState)(!1),[u,h]=(0,l.useState)(null),[p,m]=(0,l.useState)(!1),[f,g]=(0,l.useState)(null),[v,x]=(0,l.useState)(!1),[y,b]=(0,l.useState)(null),[j,w]=(0,l.useState)(null);(0,l.useEffect)(()=>{if(void 0===i||""===i)return;let e=!1;return m(!0),g(null),o(null),d(!1),h(null),w(null),Promise.allSettled([(0,$.Qe)(i),(0,$.tZ)(i)]).then(t=>{let[n,a]=t;if(!e){if("fulfilled"===a.status)d(!0),h(null);else{let e=ln(a.reason);d(!1),h("NOT_FOUND"===e.code?null:e)}if("fulfilled"===n.status){o(n.value.report),m(!1);return}g(ln(n.reason)),m(!1)}}),()=>{e=!0}},[i]);let k="/api/evidence/".concat(encodeURIComponent(null!=i?i:"")),N=(0,l.useMemo)(()=>(null==r?void 0:r.proposedDiff)!==void 0?function(e){let t=new TextEncoder,n=t.encode(e).byteLength;if(0===e.length)return{files:[],truncated:!1,totalBytes:0};let a=e,l=!1;if(n>524288){l=!0;let n=t.encode(e),s=new TextDecoder().decode(n.slice(0,524288)),i=s.lastIndexOf("\n");a=-1===i?s:s.slice(0,i+1)}let s=a.split("\n"),i=s.length>0&&""===s[s.length-1]?s.slice(0,-1):s,r=[],o=null,c=null,d=0,u=0,h=()=>{null!==o&&null!==c&&o.hunks.push(c),c=null},p=()=>{h(),null!==o&&(r.length<400?r.push(o):l=!0),o=null},m=0;for(;m<i.length;){var f,g,v;let e=null!=(f=i[m])?f:"";if(e.startsWith("diff --git ")){p();let t=/^diff --git a\/(.+?) b\/(.+)$/.exec(e);if(null!==t&&void 0!==t[1]&&void 0!==t[2]){let e=t[1],n=t[2],a=lt("b/".concat(n)),l=lt("a/".concat(e)),s={path:a,hunks:[],addedLines:0,removedLines:0};l!==a&&(s.oldPath=l),o=s}m++;continue}if(null!==c){if(e.startsWith("+")){let t={kind:"add",oldLine:null,newLine:u,text:e.slice(1)};c.lines.push(t),null!==o&&o.addedLines++,u++,m++;continue}if(e.startsWith("-")){let t={kind:"del",oldLine:d,newLine:null,text:e.slice(1)};c.lines.push(t),null!==o&&o.removedLines++,d++,m++;continue}if(e.startsWith("\\ ")){let t={kind:"meta",oldLine:null,newLine:null,text:e};c.lines.push(t),m++;continue}if(e.startsWith(" ")||""===e){let t={kind:"ctx",oldLine:d,newLine:u,text:e.startsWith(" ")?e.slice(1):e};c.lines.push(t),d++,u++,m++;continue}}if(e.startsWith("--- ")){let t=e.slice(4);if("/dev/null"!==t&&null===o)p(),o={path:lt(t),hunks:[],addedLines:0,removedLines:0};else if("/dev/null"!==t&&null!==o){let e=lt(t);e!==o.path&&(o.oldPath=e)}m++;continue}if(e.startsWith("+++ ")){let t=e.slice(4);"/dev/null"!==t&&null!==o?o.path=lt(t):"/dev/null"!==t&&(p(),o={path:lt(t),hunks:[],addedLines:0,removedLines:0}),m++;continue}if(e.startsWith("@@ ")){null===o&&(o={path:"(unknown)",hunks:[],addedLines:0,removedLines:0}),h();let t=function(e){let t=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(e);return null===t||void 0===t[1]||void 0===t[2]?null:{oldStart:parseInt(t[1],10),newStart:parseInt(t[2],10)}}(e);d=null!=(g=null==t?void 0:t.oldStart)?g:1,u=null!=(v=null==t?void 0:t.newStart)?v:1,c={header:e,lines:[]},m++;continue}m++}return p(),{files:r,truncated:l,totalBytes:n}}(r.proposedDiff):null,[null==r?void 0:r.proposedDiff]),S=null!=(t=null==r?void 0:r.changedFiles)?t:[],C=(0,l.useMemo)(()=>{var e,t;return{added:null!=(e=null==N?void 0:N.files.reduce((e,t)=>e+t.addedLines,0))?e:0,removed:null!=(t=null==N?void 0:N.files.reduce((e,t)=>e+t.removedLines,0))?t:0}},[N]),R=null!==N&&N.files.length>0?Math.min(null!=j?j:0,N.files.length-1):null,I=null!==R?null==N?void 0:N.files[R]:void 0,E=(null==r?void 0:r.status)==="running";return void 0===i||""===i?(0,a.jsxs)("section",{className:"review rv-empty","aria-label":"Diff review",children:[(0,a.jsx)("h2",{className:"rv-empty-h",children:"Review"}),(0,a.jsx)("p",{className:"rv-empty-p",children:"Enter a run ID in the window configuration to load a proposed diff."})]}):(0,a.jsxs)("section",{className:"review","aria-label":"Diff review",children:[p&&(0,a.jsxs)("div",{className:"rv-loading","aria-busy":"true","aria-label":"Loading diff",children:[(0,a.jsx)("div",{className:"rv-skel"}),(0,a.jsx)("div",{className:"rv-skel rv-skel-sm"})]}),!p&&null!==f&&(0,a.jsxs)("div",{role:"alert",className:"rv-error",children:["NOT_FOUND"===f.code?"No run with that ID was found.":"".concat(f.code,": ").concat(f.message),(c||null!==u)&&(0,a.jsx)("span",{className:"rv-error-evidence",children:(0,a.jsx)(ls,{href:k,hasManifest:c,error:u})})]}),!p&&null===f&&null!==r&&E&&(0,a.jsx)("p",{role:"status","aria-live":"polite",className:"rv-no-diff",children:"Run is still running. The proposed diff will appear when the run completes."}),!p&&null===f&&null!==r&&!E&&!ll(r)&&(0,a.jsx)("p",{className:"rv-no-diff",children:"This run has no proposed diff to review."}),!p&&null===f&&null!==r&&ll(r)&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"rv-header",children:[(0,a.jsx)("span",{className:"rv-status mono",children:null!=(s=({running:"Running",completed:"Completed","dry-run":"Dry run",rejected:"Rejected",cancelled:"Cancelled",failed:"Failed","fix-applied":"Fix applied","fix-proposed":"Fix proposed","investigation-only":"Investigation only"})[n=r.status])?s:n}),void 0!==r.modelId&&(0,a.jsx)("span",{className:"rv-model mono",children:r.modelId}),(0,a.jsxs)("span",{className:"rv-counts mono",children:[null!==N&&"".concat(N.files.length," file").concat(1!==N.files.length?"s":"")," ",(0,a.jsxs)("span",{className:"rv-stat add",children:["+",C.added]})," ",(0,a.jsxs)("span",{className:"rv-stat del",children:["−",C.removed]})]}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsx)(ls,{href:k,hasManifest:c,error:u})]}),null!==N&&N.files.length>0&&null!==R&&void 0!==I&&(0,a.jsxs)("div",{className:"rv-layout",children:[(0,a.jsx)("nav",{className:"rv-filelist","aria-label":"Changed files",children:(0,a.jsx)("ul",{children:N.files.map((e,t)=>{let n=S.find(t=>t.path===e.path),l=R===t;return(0,a.jsx)("li",{children:(0,a.jsxs)("button",{type:"button",className:"rv-filerow","aria-pressed":l,"aria-controls":l?"rv-file-".concat(t):void 0,onClick:()=>{w(t)},children:[(0,a.jsx)("span",{className:"rv-filerow-path mono",children:function(e){if(e.length<=40)return e;let t=e.lastIndexOf("/");return -1===t?e:"…/".concat(e.slice(t+1))}(e.path)}),(0,a.jsxs)("span",{className:"rv-stat add",children:["+",e.addedLines]}),(0,a.jsxs)("span",{className:"rv-stat del",children:["−",e.removedLines]}),(null==n?void 0:n.elevatedReview)===!0&&(0,a.jsx)("span",{className:"rv-elevated","aria-label":"Elevated review",children:"!"})]})},e.path)})})}),(0,a.jsxs)("div",{className:"rv-body",children:[(0,a.jsx)(lc,{file:I,index:R,changedFiles:S,sectionRef:()=>void 0},I.path),N.truncated&&(0,a.jsxs)("p",{role:"note",className:"rv-truncated",children:["Diff truncated at 512 KB. Open the"," ",c?(0,a.jsx)("a",{href:k,target:"_blank",rel:"noopener noreferrer",children:"evidence manifest"}):"evidence manifest"," ","for the full record."]})]})]}),(0,a.jsxs)("div",{className:"rv-controls",children:[(0,a.jsx)("span",{role:"status","aria-live":"polite",className:"rv-apply-status",children:v?"Applying…":void 0!==r.appliedAt?"Applied":""}),null!==y&&(0,a.jsx)("span",{role:"alert",className:"rv-apply-error",children:y.message}),void 0!==r.appliedAt?(0,a.jsx)("span",{className:"rv-final mono",children:"Applied"}):la(r)?(0,a.jsx)("button",{type:"button",className:"arun-btn",disabled:v,onClick:()=>{void 0!==i&&null!==r&&la(r)&&(x(!0),b(null),(0,$.qU)(i).then(e=>{o(e.report),x(!1)}).catch(e=>{b(ln(e)),x(!1)}))},children:v?"Applying…":"Apply"}):null]})]})]})}function lu(e){if(e<1e3)return"".concat(e.toString()," ms");if(e<6e4)return"".concat((e/1e3).toFixed(1)," s");let t=Math.floor(e/6e4),n=Math.floor(e%6e4/1e3);return"".concat(t.toString(),"m ").concat(n.toString(),"s")}function lh(e){return e<1e3?e.toString():"".concat((e/1e3).toFixed(1),"k")}let lp=new Set(["completed","dry-run","rejected","cancelled","failed","fix-applied","fix-proposed","investigation-only"]),lm={verify:"Verify","explain-plan":"Explain plan","unit-test-generation":"Generate unit tests","bug-investigation":"Investigate bug"};function lf(e,t){return void 0===t||0===t.length?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:e}),(0,a.jsx)("pre",{children:t})]})}function lg(e){var t,n,s,i,r,o,c,d,u;let{cfg:h={},linkedRoot:p=null,linkedFilePath:m}=e,f=null!=(n=h.runId)?n:null,g="verify"===(d=h.workflow)||"explain-plan"===d||"unit-test-generation"===d||"bug-investigation"===d?d:null,v=null!=(s=h.model)?s:"",x=function(e){if(void 0===e||0===e.length)return null;try{let t=JSON.parse(e);return"object"!=typeof t||null===t||Array.isArray(t)?null:t}catch(e){return null}}(h.inputJson),y=function(e){let[t,n]=(0,l.useState)([]),[a,s]=(0,l.useState)("connecting"),[i,r]=(0,l.useState)(null),o=(0,l.useRef)(-1);return(0,l.useEffect)(()=>{if(null===e)return;n([]),s("connecting"),r(null),o.current=-1;let t=null,a=!1,l="/api/runs/".concat(encodeURIComponent(e),"/events");(t=new EventSource(o.current>=0?"".concat(l,"?lastEventId=").concat(o.current.toString()):l)).onopen=()=>{a||s("live")},t.onerror=()=>{a||(s("error"),r("Stream disconnected. Attempting to reconnect…"))};let i=e=>{let l;if(!a){try{l=JSON.parse(e.data)}catch(e){return}o.current=l.seq,n(e=>[...e,l]),tN.eQ.has(l.type)&&(s("terminal"),null==t||t.close())}};for(let e of tN.$Q)t.addEventListener(e,i);return()=>{a=!0,null==t||t.close()}},[e]),{events:t,status:a,error:i}}(f),[b,j]=(0,l.useState)(null),[w,k]=(0,l.useState)(null),[N,C]=(0,l.useState)(null),[R,I]=(0,l.useState)(!1),[E,M]=(0,l.useState)(null),[T,q]=(0,l.useState)(null),P=(0,l.useCallback)(async()=>{if(null!==f){C(null);try{let e=await (0,$.Qe)(f);j(e.report),k(null)}catch(e){if(e instanceof $.hD&&404===e.status){try{let e=await (0,$.tZ)(f);k(e.manifest),j(null)}catch(e){C(e instanceof Error?e.message:"Unable to load evidence.")}return}C(e instanceof Error?e.message:"Unable to load run report.")}}},[f]);(0,l.useEffect)(()=>{P()},[P]),(0,l.useEffect)(()=>{"terminal"===y.status&&P()},[P,y.status]),(0,l.useEffect)(()=>{let e=!1;if(0!==v.length)return(0,$.ZC)().then(t=>{var n,a;e||q(null!=(a=null==(n=t.models.find(e=>e.id===v))?void 0:n.costClass)?a:null)}).catch(()=>{e||q(null)}),()=>{e=!0}},[v]);let A=(0,l.useMemo)(()=>(function(e,t){var n,a,l,s,i,r;let o=null!=(s=null==t||null==(n=t.usage)?void 0:n.promptTokens)?s:0,c=null!=(i=null==t||null==(a=t.usage)?void 0:a.completionTokens)?i:0,d=null!=(r=null==t||null==(l=t.usage)?void 0:l.latencyMs)?r:0,u=+((null==t?void 0:t.usage)!==void 0);if(u>0)return{promptTokens:o,completionTokens:c,latencyMs:d,requestCount:u};for(let t of e){let e=function(e){if("model:call:completed"===e.type)return{promptTokens:e.usage.promptTokens,completionTokens:e.usage.completionTokens,latencyMs:e.usage.latencyMs,requestCount:1};let t=e.promptTokens,n=e.completionTokens,a=e.latencyMs;return"number"==typeof t&&"number"==typeof n&&"number"==typeof a?{promptTokens:t,completionTokens:n,latencyMs:a,requestCount:1}:null}(t);null!==e&&(o+=e.promptTokens,c+=e.completionTokens,d+=e.latencyMs,u+=e.requestCount)}return{promptTokens:o,completionTokens:c,latencyMs:d,requestCount:u}})(y.events,b),[y.events,b]),z=null!=(o=null!=(i=null==b?void 0:b.durationMs)?i:null==w?void 0:w.run.durationMs)?o:y.events.length>0?Math.max(0,Date.now()-Number(new Date(null!=(r=null==(t=y.events[0])?void 0:t.ts)?r:Date.now()))):0,D=null!==b?b.status:null!==w?w.run.outcome:"loading",L=null!==b&&lp.has(b.status),F=null!==b&&void 0!==b.proposedDiff&&void 0===b.appliedAt&&("unit-test-generation"===g&&"dry-run"===b.status||"bug-investigation"===g&&"fix-proposed"===b.status),O=async()=>{if(null!==f){C(null);try{await (0,$.Su)(f),await P()}catch(e){C(e instanceof Error?e.message:"Unable to cancel run.")}}},K=async()=>{if(null!==f&&F){I(!0),M(null);try{let e=await (0,$.qU)(f);j(e.report)}catch(e){M(e instanceof Error?e.message:"Unable to apply run.")}finally{I(!1)}}};return null===f||null===g?(0,a.jsxs)("div",{className:"arun arun-empty",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Agent run is not configured."}),(0,a.jsx)("p",{children:"Open a new Agent window from the launcher to start a BFF workflow."})]}):(0,a.jsxs)("div",{className:"arun arun-real",children:[(0,a.jsxs)("div",{className:"arun-head",children:[(0,a.jsx)("span",{className:"arun-role",children:lm[g]}),(0,a.jsx)("span",{className:"ag-model mono",children:v}),null!==T?(0,a.jsx)("span",{className:"arun-gov",children:T}):null,(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("span",{className:"arun-status",children:[(0,a.jsx)("span",{className:"dot","data-live":(null==b?void 0:b.status)==="running"}),D]})]}),(0,a.jsxs)("div",{className:"arun-summary",children:[(0,a.jsx)("strong",{children:function(e,t,n){var a;if(null===t&&null===n)return"Loading run state...";let l=null===e?"Agent run":lm[e];return(null==t?void 0:t.status)==="running"?"".concat(l," is running."):(null==t?void 0:t.status)==="dry-run"?"".concat(l," produced a reviewable dry-run."):(null==t?void 0:t.status)==="fix-proposed"?"".concat(l," proposed a fix."):(null==t?void 0:t.status)==="fix-applied"?"".concat(l," applied changes."):(null==t?void 0:t.status)==="investigation-only"?"".concat(l," completed without a patch."):(null==t?void 0:t.status)==="failed"||(null==t?void 0:t.status)==="rejected"?"".concat(l," failed."):(null==t?void 0:t.status)==="cancelled"?"".concat(l," was cancelled."):null!==t?"".concat(l," completed."):"".concat(l," evidence loaded: ").concat(null!=(a=null==n?void 0:n.run.outcome)?a:"unknown",".")}(g,b,w)}),(0,a.jsxs)("span",{className:"mono",children:["run ",f.slice(0,8)]})]}),(0,a.jsxs)("div",{className:"arun-meters",children:[(0,a.jsxs)("div",{className:"arun-meter",children:[(0,a.jsx)("span",{className:"arun-mk",children:"Elapsed"}),(0,a.jsx)("span",{className:"arun-mv mono",children:lu(z)})]}),(0,a.jsxs)("div",{className:"arun-meter",children:[(0,a.jsx)("span",{className:"arun-mk",children:"Usage"}),(0,a.jsx)("span",{className:"arun-mv mono",children:0===A.requestCount?"No model usage":"".concat(lh(A.promptTokens+A.completionTokens)," tok")})]}),(0,a.jsxs)("div",{className:"arun-meter",children:[(0,a.jsx)("span",{className:"arun-mk",children:"Latency"}),(0,a.jsx)("span",{className:"arun-mv mono",children:0===A.requestCount?"-":lu(A.latencyMs)})]})]}),(0,a.jsxs)("div",{className:"arun-perms",children:[(0,a.jsxs)("span",{className:"arun-perm","data-on":null!==p,children:[(0,a.jsx)(S.files,{size:11}),null!==p?p:null!=(c=h.workspaceRoot)?c:"no workspace"]}),void 0!==m?(0,a.jsxs)("span",{className:"arun-perm","data-on":!0,children:[(0,a.jsx)(S.files,{size:11}),m]}):null]}),null!==x?(0,a.jsxs)("details",{className:"arun-input",children:[(0,a.jsx)("summary",{children:"Run input"}),(0,a.jsx)("pre",{children:JSON.stringify(x,null,2)})]}):null,(0,a.jsx)("div",{className:"arun-log",children:0===y.events.length?(0,a.jsxs)("div",{className:"arun-log-row",children:[(0,a.jsx)("span",{className:"arun-log-ico",children:(0,a.jsx)(S.reset,{size:12})}),(0,a.jsx)("span",{className:"arun-log-text",children:"Waiting for run events..."})]}):y.events.slice().reverse().slice(0,50).map(e=>(0,a.jsxs)("div",{className:"arun-log-row",children:[(0,a.jsx)("span",{className:"arun-log-ico",children:(0,a.jsx)(S.spark,{size:12})}),(0,a.jsx)("span",{className:"arun-log-text",children:function(e){switch(e.type){case"ready":return"SSE stream ready";case"run:started":return"Started ".concat(e.taskType);case"run:completed":return"Run completed";case"run:failed":return"Run failed: ".concat(e.failure.message);case"run:cancelled":return"Run cancelled";case"state:transition":return"".concat(e.from," -> ").concat(e.to).concat(void 0===e.reason?"":": ".concat(e.reason));case"model:call:started":return"Model call started (".concat(e.contextBytes.toString()," bytes)");case"model:call:completed":return"Model call completed (".concat(lh(e.usage.promptTokens+e.usage.completionTokens)," tokens)");case"model:call:failed":return"Model call failed: ".concat(e.message);case"patch:proposed":return"Patch proposed (".concat(e.patchBytes.toString()," bytes)");case"verification:result":return"Verification ".concat(e.passed?"passed":"failed",": ").concat(e.detail);case"workflow:started":return"Unit-test workflow started";case"workflow:model:call:completed":return"Unit-test model call completed (".concat(lh(e.promptTokens+e.completionTokens)," tokens)");case"workflow:verification:result":return"Unit-test verification ".concat(e.overallStatus);case"workflow:completed":return"Unit-test workflow ".concat(e.status);case"workflow:failed":return"Unit-test workflow failed: ".concat(e.message);case"bug:started":return"Bug investigation started";case"bug:model:call:completed":return"Bug model call completed (".concat(lh(e.promptTokens+e.completionTokens)," tokens)");case"bug:rootcause:proposed":return"Root cause proposed".concat(e.hasPatch?" with patch":"");case"bug:verification:result":return"Bug verification ".concat(e.overallStatus);case"bug:completed":return"Bug investigation ".concat(e.status);case"bug:failed":return"Bug investigation failed: ".concat(e.message);default:return e.type}}(e)}),(0,a.jsx)("span",{className:"arun-log-t mono",children:function(e){let t="number"==typeof e.ts?e.ts:Date.parse(e.ts);return Number.isFinite(t)?new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}):""}(e)})]},"".concat(e.runId,":").concat(e.seq,":").concat(e.type)))}),null!==b?(0,a.jsxs)("div",{className:"arun-results",children:[void 0===b.report?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Report"}),(0,a.jsx)("pre",{children:b.report})]}),void 0===b.overallStatus||void 0===b.results?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Verification"}),(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Status"}),(0,a.jsx)("strong",{children:b.overallStatus})]}),b.results.slice(0,8).map(e=>(0,a.jsxs)("div",{className:"arun-check-row",children:[(0,a.jsx)("span",{children:e.kind}),(0,a.jsx)("span",{className:"mono",children:e.status})]},"".concat(e.kind,":").concat(e.command)))]}),lf("Failure",b.failureReason),lf("Covered behavior",b.coveredBehavior),lf("Known gaps",b.knownGaps),lf("Verification note",b.verificationSkipReason),function(e){let t=e.hypothesis;if(void 0===t)return null;let n=[["Root cause",t.rootCause],["Regression test",t.regressionTestStrategy],["Uncertainty",t.uncertainty],["Confidence",t.confidence]].filter(e=>"string"==typeof e[1]&&e[1].length>0);return 0===n.length?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Hypothesis"}),n.map(e=>{let[t,n]=e;return(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:t}),(0,a.jsx)("strong",{children:n})]},t)})]})}(b),void 0===(u=b.nextActions)||0===u.length?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Next actions"}),u.map(e=>(0,a.jsx)("div",{className:"arun-check-row",children:(0,a.jsx)("span",{children:e})},e))]}),void 0!==b.dryRunPreview?(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Dry-run preview"}),(0,a.jsx)("pre",{children:b.dryRunPreview})]}):null,void 0!==b.proposedDiff?(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Proposed diff"}),(0,a.jsx)("pre",{children:b.proposedDiff})]}):null,function(e){let t=e.verificationSummary;return void 0===t?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Verification"}),(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Status"}),(0,a.jsx)("strong",{children:t.overallStatus})]}),(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Duration"}),(0,a.jsx)("strong",{children:lu(t.durationMs)})]}),t.results.slice(0,5).map(e=>(0,a.jsxs)("div",{className:"arun-check-row",children:[(0,a.jsx)("span",{children:e.kind}),(0,a.jsx)("span",{className:"mono",children:e.status})]},"".concat(e.kind,":").concat(e.command)))]})}(b),void 0!==b.applyReport?(0,a.jsxs)("div",{className:"arun-result-card arun-applied",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Applied"}),(0,a.jsx)("pre",{children:JSON.stringify(b.applyReport,null,2)})]}):null]}):null!==w?(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Evidence"}),(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Outcome"}),(0,a.jsx)("strong",{children:w.run.outcome})]}),(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Duration"}),(0,a.jsx)("strong",{children:lu(w.run.durationMs)})]})]}):null,null!==N?(0,a.jsx)("div",{className:"arun-error",children:N}):null,null!==E?(0,a.jsx)("div",{className:"arun-error",children:E}):null,(0,a.jsxs)("div",{className:"arun-controls",children:[(0,a.jsx)("a",{className:"arun-btn ghost",href:"/api/evidence/".concat(encodeURIComponent(f)),target:"_blank",rel:"noreferrer",children:"Evidence"}),F?(0,a.jsx)("button",{type:"button",className:"arun-btn",disabled:R,onClick:()=>void K(),children:R?"Applying...":"Apply"}):(null==b?void 0:b.appliedAt)!==void 0?(0,a.jsx)("span",{className:"arun-final mono",children:"Applied"}):null,L||(null==b?void 0:b.status)!=="running"?null:(0,a.jsx)("button",{type:"button",className:"arun-btn danger",onClick:()=>void O(),children:"Cancel"})]})]})}let lv=[{name:"Messaging",desc:"Catch up on threads",glyph:"#"},{name:"GitHub",desc:"PRs, code & CI",glyph:"{ }"},{name:"Linear",desc:"Track issues",glyph:"⊿"},{name:"Slack",desc:"Team channels",glyph:"≡"},{name:"Sentry",desc:"Error tracking",glyph:"◎"}];function lx(e){let{provider:t="GitHub"}=e;return(0,a.jsx)("div",{className:"integ",children:lv.map(e=>{let n=e.name===t;return(0,a.jsxs)("button",{type:"button",className:"integ-row","data-on":n,"aria-pressed":n,children:[(0,a.jsx)("span",{className:"integ-glyph mono",children:e.glyph}),(0,a.jsxs)("span",{className:"integ-text",children:[(0,a.jsx)("span",{className:"integ-name",children:e.name}),(0,a.jsx)("span",{className:"integ-desc",children:e.desc})]}),n?(0,a.jsx)("span",{className:"integ-on",children:(0,a.jsx)(S.check,{size:13})}):(0,a.jsx)("span",{className:"integ-add",children:(0,a.jsx)(S.plus,{size:14})})]},e.name)})})}let ly={allow:["Allow","var(--accent)"],ask:["Ask","var(--warn)"],deny:["Deny","var(--danger)"]},lb={allow:"ask",ask:"deny",deny:"allow"},lj=[{id:1,label:"Write src/windows.jsx",kind:"write",risk:"low",expect:"allow"},{id:2,label:"Overwrite prod/secrets.env",kind:"write",risk:"high",expect:"deny"},{id:3,label:"Run `npm test`",kind:"command",risk:"low",expect:"allow"},{id:4,label:"Run `kubectl apply` → prod",kind:"command",risk:"high",expect:"ask"},{id:5,label:"Open pull request #142",kind:"git",risk:"low",expect:"allow"},{id:6,label:"Email the customer",kind:"mail",risk:"low",expect:"ask"}],lw=[["Developer","Codes, reviews diffs, runs tests, opens PRs"],["Product Owner","Searches docs, drafts Jira tickets, plans releases"],["Designer","Explores UI options, reviews flows, writes specs"]],lk=[["calendar","Calendar","automations"],["mail","Mail","bell"],["jira","Jira","review"],["docs","Docs","files"]];function lN(e){let{policy:t,setPolicy:n}=e;return(0,a.jsxs)("div",{className:"pol",children:[(0,a.jsx)("div",{className:"pol-hint",children:"Rights an agent inherits when Keiko governs. Tap a decision to cycle through Allow → Ask → Deny."}),t.map(e=>{let t=ly[e.decision];return(0,a.jsxs)("div",{className:"pol-row",children:[(0,a.jsxs)("div",{className:"pol-text",children:[(0,a.jsx)("span",{className:"pol-action",children:e.action}),(0,a.jsx)("span",{className:"pol-scope mono",children:e.scope})]}),(0,a.jsx)("button",{type:"button",className:"pol-dec",style:{color:t[1],borderColor:t[1]},onClick:()=>{let t;return t=e.id,n(e=>e.map(e=>e.id===t?{...e,decision:lb[e.decision]}:e))},children:t[0]})]},e.id)})]})}function lS(e){let{decide:t}=e,[n,s]=(0,l.useState)(!1),i=lj.map(e=>{let n=t(e.kind,e.risk);return{...e,actual:n,pass:n===e.expect}}),r=i.filter(e=>e.pass).length;return(0,a.jsxs)("div",{className:"evl",children:[(0,a.jsxs)("div",{className:"evl-head",children:[(0,a.jsxs)("button",{type:"button",className:"evl-run",onClick:()=>s(!0),children:[(0,a.jsx)(S.spark,{size:13})," Run evaluation"]}),n&&(0,a.jsxs)("span",{className:"evl-score"+(r===i.length?" ok":""),children:[r,"/",i.length," passed"]})]}),(0,a.jsx)("div",{className:"evl-hint",children:"Mock scenarios against your policy before going autonomous."}),i.map(e=>(0,a.jsxs)("div",{className:"evl-row","data-state":n?e.pass?"pass":"fail":"idle",children:[(0,a.jsx)("span",{className:"evl-ico",children:n?e.pass?(0,a.jsx)(S.check,{size:13}):(0,a.jsx)(S.close,{size:13}):(0,a.jsx)("span",{className:"evl-dot"})}),(0,a.jsx)("span",{className:"evl-label",children:e.label}),n&&(0,a.jsx)("span",{className:"evl-res mono",style:{color:ly[e.actual][1]},children:ly[e.actual][0]})]},e.id))]})}function lC(e){let{memory:t,setMemory:n}=e,[s,i]=(0,l.useState)(""),r=()=>{let e=s.trim();""!==e&&(n(t=>[e,...t]),i(""))};return(0,a.jsxs)("div",{className:"mem",children:[(0,a.jsxs)("div",{className:"mem-add",children:[(0,a.jsx)("input",{value:s,onChange:e=>i(e.target.value),placeholder:"Teach Keiko something about you…",onKeyDown:e=>{"Enter"===e.key&&r()}}),(0,a.jsx)("button",{type:"button",onClick:r,"aria-label":"Add memory",children:(0,a.jsx)(S.plus,{size:15})})]}),t.map((e,t)=>(0,a.jsxs)("div",{className:"mem-row",children:[(0,a.jsx)(S.spark,{size:12}),(0,a.jsx)("span",{className:"mem-text",children:e}),(0,a.jsx)("button",{type:"button",className:"mem-x","aria-label":"Remove memory: ".concat(e),onClick:()=>n(e=>e.filter((e,n)=>n!==t)),children:(0,a.jsx)(S.close,{size:12})})]},"".concat(String(t),"-").concat(e)))]})}function lR(e){let{bridges:t,setBridges:n}=e;return(0,a.jsxs)("div",{className:"brg",children:[(0,a.jsx)("div",{className:"evl-hint",children:"What your twin can reach on your behalf."}),lk.map(e=>{let[l,s,i]=e,r=S[i],o=t[l];return(0,a.jsxs)("button",{type:"button",className:"brg-row","data-on":o,"aria-pressed":o,onClick:()=>n(e=>({...e,[l]:!e[l]})),children:[(0,a.jsx)("span",{className:"brg-ico",children:(0,a.jsx)(r,{size:16})}),(0,a.jsx)("span",{className:"brg-name",children:s}),(0,a.jsx)("span",{className:"brg-tg"+(o?" on":""),children:(0,a.jsx)("span",{})})]},l)})]})}function lI(e){let{persona:t,setPersona:n}=e;return(0,a.jsxs)("div",{className:"prs",children:[(0,a.jsx)("div",{className:"evl-hint",children:"Keiko adapts behaviour & tools to who is at the wheel."}),lw.map(e=>{let[l,s]=e;return(0,a.jsxs)("button",{type:"button",className:"prs-row","data-on":t===l,"aria-pressed":t===l,onClick:()=>n(l),children:[(0,a.jsx)("span",{className:"prs-dot"}),(0,a.jsxs)("span",{className:"prs-text",children:[(0,a.jsx)("span",{className:"prs-name",children:l}),(0,a.jsx)("span",{className:"prs-desc",children:s})]}),t===l&&(0,a.jsx)(S.check,{size:14,style:{color:"var(--accent)"}})]},l)})]})}let lE=[["policy","Policy"],["eval","EVAL"],["memory","MemoriaViva"],["bridges","Connections"],["persona","Persona"]];function lM(){let e=w(),[t,n]=(0,l.useState)("policy");return(0,a.jsxs)("div",{className:"twin",children:[(0,a.jsxs)("div",{className:"twin-hero",children:[(0,a.jsx)("img",{className:"twin-orca",src:"/assets/keiko-logo.svg",alt:""}),(0,a.jsxs)("div",{className:"twin-id",children:[(0,a.jsx)("span",{className:"twin-name",children:"Keiko — Digital Twin"}),(0,a.jsxs)("span",{className:"twin-sub mono",children:["mirroring \xb7 ",e.persona]})]}),(0,a.jsx)("span",{className:"twin-mode "+("autonomous"===e.mode?"on":""),children:"autonomous"===e.mode?"Autonomous":"Manual"})]}),(0,a.jsx)("div",{className:"twin-tabs",children:lE.map(e=>{let[l,s]=e;return(0,a.jsx)("button",{type:"button",className:"twin-tab","data-on":t===l,onClick:()=>n(l),children:s},l)})}),(0,a.jsxs)("div",{className:"twin-body",children:["policy"===t&&(0,a.jsx)(lN,{policy:e.policy,setPolicy:e.setPolicy}),"eval"===t&&(0,a.jsx)(lS,{decide:e.decide}),"memory"===t&&(0,a.jsx)(lC,{memory:e.memory,setMemory:e.setMemory}),"bridges"===t&&(0,a.jsx)(lR,{bridges:e.bridges,setBridges:e.setBridges}),"persona"===t&&(0,a.jsx)(lI,{persona:e.persona,setPersona:e.setPersona})]})]})}function lT(e){return"embedding-only"===e?"Embedding model — not selectable for text conversation":"ocr-vision-only"===e?"OCR/vision-only — not selectable for text conversation":"Not a chat model — not selectable for text conversation"}function lq(e){let{model:t}=e,n=(0,tN.nP)(t);return void 0===n?(0,a.jsx)("span",{className:"ml-elig ml-elig-ok","data-testid":"conv-elig-ok",role:"status","aria-label":"Model eligibility: eligible for conversation",children:"Conversation-eligible"}):(0,a.jsxs)("span",{className:"ml-elig ml-elig-no","data-testid":"conv-elig-no",role:"status","aria-label":"Model eligibility: "+lT(n),children:["Not selectable: ",lT(n)]})}function lP(e){var t;let{model:n}=e,l=(0,tN.S_)(n);return(0,a.jsxs)("div",{className:"ml-row",children:[(0,a.jsx)("span",{className:"ml-ico",children:(0,a.jsx)(S.cube,{size:16})}),(0,a.jsxs)("div",{className:"ml-info",children:[(0,a.jsxs)("div",{className:"ml-top",children:[(0,a.jsx)("span",{className:"ml-name",children:n.id}),(0,a.jsx)("span",{className:"ml-type mono",children:"ocr-vision"===(t=n.kind)?"OCR":t}),(0,a.jsx)(lq,{model:n})]}),(0,a.jsxs)("div",{className:"ml-url mono",children:["tools ",n.toolCalling?"yes":"no"," \xb7 structured"," ",n.structuredOutput?"yes":"no"," \xb7 ",n.costClass,"/",n.latencyClass]})]}),(0,a.jsx)("span",{className:"ml-status "+(l?"connected":"ineligible"),title:l?"conversation-eligible":"not selectable for conversation","aria-hidden":"true"})]})}let lA="keiko.wallpaper.opacity";function lz(){let e=window.localStorage.getItem(lA);if(null===e)return 100;let t=Number.parseInt(e,10);return Number.isFinite(t)?Math.max(0,Math.min(100,t)):100}function lD(){let[e,t]=(0,l.useState)(lz);(0,l.useEffect)(()=>{try{window.localStorage.setItem(lA,String(e))}catch(e){}window.dispatchEvent(new CustomEvent("keiko:wallpaper-opacity",{detail:e}))},[e]);let n={"--p":"".concat(String(e),"%")};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"set-sec-h",children:(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"set-sec-t",children:"Workspace wallpaper"}),(0,a.jsx)("div",{className:"set-sec-d",children:"Liquid Chrome — a subtle metallic flow behind the grid that reacts to your cursor and clicks. Set to 0 % for the plain workspace background."})]})}),(0,a.jsxs)("div",{className:"gpref",children:[(0,a.jsxs)("div",{className:"gpref-row",children:[(0,a.jsx)("label",{className:"gpref-label",htmlFor:"wp-op",children:"Wallpaper opacity"}),(0,a.jsxs)("span",{className:"gpref-val mono",children:[e,"%"]})]}),(0,a.jsx)("input",{id:"wp-op",className:"gpref-slider",type:"range",min:0,max:100,step:1,value:e,onChange:e=>t(Number.parseInt(e.target.value,10)),style:n,"aria-label":"Wallpaper opacity"}),(0,a.jsxs)("div",{className:"gpref-scale",children:[(0,a.jsx)("span",{children:"Off"}),(0,a.jsx)("span",{children:"Full"})]})]})]})}function lL(){let[e,t]=(0,l.useState)("models"),[n,s]=(0,l.useState)([]),[i,r]=(0,l.useState)(!1),[o,c]=(0,l.useState)(!0),[d,u]=(0,l.useState)(),[h,p]=(0,l.useState)(!1);(0,l.useEffect)(()=>{let e=!1;return async function(){c(!0),u(void 0);try{let[t,n]=await Promise.all([(0,$.Dz)(),(0,$.ZC)()]);if(e)return;r(t.configPresent),s(n.models)}catch(t){if(e)return;u(t instanceof Error?t.message:"Could not load gateway settings.")}finally{e||c(!1)}}(),()=>{e=!0}},[]);let m=n.filter(tN.S_).length,f=n.length>0;return(0,a.jsxs)("div",{className:"set",children:[(0,a.jsxs)("div",{className:"set-hero",children:[(0,a.jsx)(S.settings,{size:18}),(0,a.jsx)("span",{className:"set-title",children:"Settings"}),(0,a.jsxs)("span",{className:"set-onprem",title:"Runs inside your network",children:[(0,a.jsx)("span",{className:"dot",style:{background:"var(--accent)"}})," Self-hosted"]})]}),(0,a.jsx)("div",{className:"set-tabs",children:["models","general","security"].map(n=>(0,a.jsx)("button",{type:"button",className:"set-tab","data-on":e===n,onClick:()=>t(n),children:"models"===n?"Local Models":"general"===n?"General":"Security"},n))}),(0,a.jsxs)("div",{className:"set-body",children:["models"===e&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"set-sec-h",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"set-sec-t",children:"Model gateway"}),(0,a.jsx)("div",{className:"set-sec-d",children:"Credentials are stored locally by the Keiko loopback server; secrets are never returned to the browser."})]}),(0,a.jsxs)("button",{type:"button",className:"set-add",onClick:()=>p(!0),children:[(0,a.jsx)(S.plus,{size:14}),i?"Update credentials":"Connect gateway"]})]}),(0,a.jsxs)("div",{className:"ml-row",children:[(0,a.jsx)("span",{className:"ml-ico",children:(0,a.jsx)(S.cube,{size:16})}),(0,a.jsxs)("div",{className:"ml-info",children:[(0,a.jsxs)("div",{className:"ml-top",children:[(0,a.jsx)("span",{className:"ml-name",children:i?f?"Gateway connected":"Gateway configured":"Gateway setup required"}),(0,a.jsxs)("span",{className:"ml-type mono",children:[n.length.toString()," models"]}),(0,a.jsxs)("span",{className:"ml-type mono",children:[m.toString()," chat"]})]}),(0,a.jsx)("div",{className:"ml-url mono",children:i?f?"Keiko can use the configured gateway models for chat and agent workflows.":"The gateway is configured, but no conversation-capable models are currently available.":"Enter the gateway base URL and API token before using chat or agent workflows."})]}),(0,a.jsx)("span",{className:"ml-status "+(i?"connected":"untested"),title:i?"gateway configured":"setup required","aria-hidden":"true"})]}),void 0!==d?(0,a.jsx)("div",{className:"gw-error",children:d}):null,o?(0,a.jsx)("div",{className:"set-placeholder",children:"Loading gateway models..."}):0===n.length?(0,a.jsx)("div",{className:"set-placeholder",children:i?"No conversation-capable models are currently available. Review the gateway configuration or discovered model set.":"No models are configured yet. Connect the gateway to load configured model capabilities."}):(0,a.jsx)("div",{className:"set-list",children:n.map(e=>(0,a.jsx)(lP,{model:e},e.id))}),h?(0,a.jsx)(nf,{onCancel:()=>p(!1)}):null]}),"general"===e&&(0,a.jsx)(lD,{}),"security"===e&&(0,a.jsx)("div",{className:"set-placeholder",children:"SSO \xb7 audit log \xb7 data residency — coming soon."})]})]})}function lF(e){return e instanceof $.hD?"".concat(e.code,": ").concat(e.message):e instanceof Error?e.message:"Failed to load connectors."}function lO(){return(0,a.jsx)("div",{className:"connector-picker-status",role:"status","aria-live":"polite",children:"Loading connectors…"})}function lK(e){let{message:t}=e;return(0,a.jsx)("div",{className:"connector-picker-error",role:"alert",children:t})}function lB(){return(0,a.jsxs)("div",{className:"connector-picker-empty",children:[(0,a.jsx)("p",{children:"No ready connectors found."}),(0,a.jsx)("a",{href:"/local-knowledge",className:"connector-picker-create-link",children:"Create a connector"})]})}function lW(e){let{capsules:t,capsuleSets:n,selectedKind:l,selectedId:s}=e,i=function(e,t,n,a){if(void 0===n||void 0===a||0===a.length)return null;if("capsule"===n){let t=e.find(e=>e.id===a);return void 0!==t?t.displayName:"Capsule ".concat(a)}if("capsule-set"===n){let e=t.find(e=>e.id===a);return void 0!==e?e.displayName:"Set ".concat(a)}return null}(t,n,l,s);return null===i?null:(0,a.jsxs)("div",{className:"connector-picker-selected",role:"status","aria-live":"polite",children:[(0,a.jsx)("span",{"aria-hidden":"true",children:"●"}),(0,a.jsx)("span",{children:i})]})}function lU(e){let{selectedKind:t,selectedId:n,onSelect:s}=e,[i,r]=(0,l.useState)([]),[o,c]=(0,l.useState)([]),[d,u]=(0,l.useState)(!0),[h,p]=(0,l.useState)(null);if((0,l.useEffect)(()=>{let e=!1;return async function(){u(!0),p(null);try{let[t,n]=await Promise.allSettled([(0,tG.xr)(),(0,tG.R3)()]);if(e)return;"fulfilled"===t.status?r(t.value.capsules.filter(e=>"ready"===e.lifecycleState)):p(lF(t.reason)),"fulfilled"===n.status&&c(n.value.capsuleSets)}catch(t){e||p(lF(t))}finally{e||u(!1)}}(),()=>{e=!0}},[]),d)return(0,a.jsx)(lO,{});if(null!==h)return(0,a.jsx)(lK,{message:h});let m=i.length>0,f=o.length>0;if(!m&&!f)return(0,a.jsx)(lB,{});let g=void 0!==t&&void 0!==n&&n.length>0?"".concat(t,":").concat(n):"";return(0,a.jsxs)("div",{className:"connector-picker",children:[(0,a.jsx)(lW,{capsules:i,capsuleSets:o,selectedKind:t,selectedId:n}),(0,a.jsx)("label",{className:"connector-picker-label",htmlFor:"connector-picker-select",children:"Select a connector"}),(0,a.jsxs)("select",{id:"connector-picker-select",className:"connector-picker-select",value:g,onChange:e=>{!function(e){if(""===e)return;let t=e.indexOf(":");if(-1===t)return;let n=e.slice(0,t),a=e.slice(t+1);0!==a.length&&s({selectedKind:n,selectedId:a})}(e.target.value)},"aria-label":"Select a Local Knowledge connector",children:[(0,a.jsx)("option",{value:"",disabled:!0,children:"— choose a connector —"}),m&&(0,a.jsx)("optgroup",{label:"Capsules",children:i.map(e=>(0,a.jsx)("option",{value:"capsule:".concat(e.id),children:"".concat(e.displayName," (").concat(function(e){switch(e){case"ready":return"Ready";case"indexing":return"Indexing…";case"error":return"Failed";default:return e}}(e.lifecycleState),")")},"capsule:".concat(e.id)))}),f&&(0,a.jsx)("optgroup",{label:"Capsule sets",children:o.map(e=>(0,a.jsx)("option",{value:"capsule-set:".concat(e.id),children:"".concat(e.displayName," (").concat(String(e.capsuleCount)," capsules)")},"capsule-set:".concat(e.id)))})]}),(0,a.jsx)("div",{className:"connector-picker-footer",children:(0,a.jsx)("a",{href:"/local-knowledge",className:"connector-picker-create-link",children:"Create or manage connectors"})})]})}async function l_(e,t){var n,a;let l=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),s=await fetch(e,{...t,headers:{Accept:"application/json",...(null==t?void 0:t.body)!==void 0?{"Content-Type":"application/json"}:{},..."GET"===l||"HEAD"===l?{}:{"X-Keiko-CSRF":"1"},...null!=(a=null==t?void 0:t.headers)?a:{}}});if(!s.ok){let e="INTERNAL",t="HTTP ".concat(s.status.toString());try{let n=await s.json();e=n.error.code,t=n.error.message}catch(e){}throw new $.hD(e,t,s.status)}return s.json()}async function lH(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return l_("/api/figma/snapshots",{method:"POST",body:JSON.stringify({boardLink:e,...!0===t.acknowledgeReadOnly?{acknowledgeReadOnly:!0}:{},...!0===t.isResnapshot?{isResnapshot:!0}:{}})})}async function lJ(e){return l_("/api/figma/snapshots/".concat(encodeURIComponent(e)))}async function lV(e){return l_("/api/figma/snapshots/".concat(encodeURIComponent(e),"/code"),{method:"POST",body:JSON.stringify({})})}function lG(e){return e instanceof $.hD?"".concat(e.code,": ").concat(e.message):e instanceof Error?e.message:"An unexpected error occurred."}function lX(e){let{index:t,screenId:n,name:l,irSummary:s,imageByteLength:i}=e,r=(i/1024).toFixed(1);return(0,a.jsxs)("article",{className:"figma-snapshot-screen-card","aria-label":"Screen ".concat(String(t+1),": ").concat(l),children:[(0,a.jsx)("div",{className:"figma-snapshot-screen-placeholder","aria-hidden":"true",children:(0,a.jsx)("span",{className:"figma-snapshot-screen-index",children:String(t+1)})}),(0,a.jsxs)("div",{className:"figma-snapshot-screen-meta",children:[(0,a.jsx)("h3",{className:"figma-snapshot-screen-name",children:l}),(0,a.jsx)("p",{className:"figma-snapshot-screen-summary",children:s}),(0,a.jsxs)("p",{className:"figma-snapshot-screen-size",children:[r," KiB"]}),(0,a.jsx)("p",{className:"figma-snapshot-screen-id",children:n})]})]})}function lY(e){let{snapshotRunId:t,updateCfg:n,triggerImpl:s=lH,loadImpl:i=lJ,codegenImpl:r=lV}=e,o=(0,l.useId)(),c=(0,l.useId)(),[d,u]=(0,l.useState)(""),[h,p]=(0,l.useState)("idle"),[m,f]=(0,l.useState)(null),[g,v]=(0,l.useState)(null),[x,y]=(0,l.useState)(!1),[b,j]=(0,l.useState)("idle"),[w,k]=(0,l.useState)(null),[N,S]=(0,l.useState)(null),C=function(e){try{let t=new URL(e.trim()),n=t.hostname.toLowerCase();if("figma.com"!==n&&!n.endsWith(".figma.com")||!/^\/(design|file)\//u.test(t.pathname))return!1;let a=t.searchParams.get("node-id");return null!==a&&a.length>0}catch(e){return!1}}(d),R="building"===h,I=(0,l.useCallback)(async(e,t)=>{p("building"),v(null),j("idle"),k(null);try{let a=await s(e,{acknowledgeReadOnly:x,isResnapshot:t});f(a),n({snapshotRunId:a.runId}),p("done")}catch(e){v(lG(e)),p("error")}},[s,n,x]),E=(0,l.useCallback)(e=>{e.preventDefault(),C&&!R&&I(d,!1)},[d,R,C,I]),M=(0,l.useCallback)(()=>{if(R)return;let e=d.trim().length>0?d:null!==m?"https://www.figma.com/design/".concat(m.fileKey,"/board?node-id=").concat(m.nodeId):"";0!==e.length&&I(e,!0)},[d,R,I,m]),T=(0,l.useCallback)(()=>{var e;let n=null!=(e=null==m?void 0:m.runId)?e:t;void 0!==n&&0!==n.length&&"generating"!==b&&(j("generating"),S(null),r(n).then(e=>{k(e),j("done")}).catch(e=>{S(lG(e)),j("error")}))},[r,b,t,m]),q=(0,l.useCallback)(()=>{void 0!==t&&0!==t.length&&(p("building"),v(null),i(t).then(e=>{f(e),p("done")}).catch(e=>{v(lG(e)),p("error")}))},[i,t]),P=void 0!==t&&t.length>0&&null===m&&"idle"===h;return(0,a.jsxs)("section",{className:"figma-snapshot-window","aria-label":"Figma Snapshot",children:[(0,a.jsxs)("form",{className:"figma-snapshot-form",onSubmit:E,noValidate:!0,children:[(0,a.jsx)("label",{className:"figma-snapshot-label",htmlFor:o,children:"Board link"}),(0,a.jsxs)("div",{className:"figma-snapshot-input-row",children:[(0,a.jsx)("input",{id:o,type:"url",className:"figma-snapshot-input",placeholder:"https://www.figma.com/design/…?node-id=…",value:d,onChange:e=>{u(e.target.value)},"aria-describedby":c,"aria-invalid":d.length>0&&!C?"true":void 0,disabled:R,autoComplete:"off",spellCheck:!1}),(0,a.jsx)("button",{type:"submit",className:"figma-snapshot-trigger-btn",disabled:!C||R,"aria-busy":R,children:R?"Building…":"Snapshot"})]}),(0,a.jsxs)("label",{className:"figma-snapshot-consent",children:[(0,a.jsx)("input",{type:"checkbox",className:"figma-snapshot-consent-checkbox",checked:x,onChange:e=>{y(e.target.checked)},disabled:R}),(0,a.jsxs)("span",{children:["I acknowledge the configured Figma PAT is read-only and least-privilege (",(0,a.jsx)("code",{children:"files:read"}),")."]})]}),(0,a.jsx)("p",{className:"figma-snapshot-hint",children:"Paste a Figma board link with a node-id param (section or frame anchor). The access token is resolved server-side — it never reaches this page."})]}),(0,a.jsxs)("div",{id:c,role:"status","aria-live":"polite","aria-atomic":"true",className:"figma-snapshot-status",children:[R&&(0,a.jsx)("p",{className:"figma-snapshot-progress",children:"Building snapshot — fetching screens from Figma…"}),"error"===h&&null!==g&&(0,a.jsx)("p",{className:"figma-snapshot-error",role:"alert",children:g})]}),P&&(0,a.jsxs)("div",{className:"figma-snapshot-stored-notice",children:[(0,a.jsx)("p",{className:"figma-snapshot-stored-text",children:"A stored snapshot is available."}),(0,a.jsx)("button",{type:"button",className:"figma-snapshot-load-btn",onClick:q,children:"Load snapshot"})]}),null!==m&&"done"===h&&(0,a.jsxs)("div",{className:"figma-snapshot-result",children:[(0,a.jsxs)("div",{className:"figma-snapshot-reduction",children:[(0,a.jsx)("p",{className:"figma-snapshot-reduction-hint",children:m.reductionHint}),m.skippedCount>0&&(0,a.jsxs)("p",{className:"figma-snapshot-skipped-notice",children:[String(m.skippedCount)," screen",1!==m.skippedCount?"s":""," could not be rendered and were skipped."]})]}),(0,a.jsx)("button",{type:"button",className:"figma-snapshot-resnapshot-btn",onClick:M,disabled:R,"aria-label":"Re-snapshot this board",children:"Re-snapshot"}),(0,a.jsxs)("div",{className:"figma-snapshot-codegen",children:[(0,a.jsx)("button",{type:"button",className:"figma-snapshot-codegen-btn",onClick:T,disabled:"generating"===b,"aria-busy":"generating"===b,children:"generating"===b?"Generating code…":"Generate code"}),"error"===b&&null!==N&&(0,a.jsx)("p",{className:"figma-snapshot-error",role:"alert",children:N}),"done"===b&&null!==w&&(0,a.jsxs)("div",{className:"figma-snapshot-code-result",children:[(0,a.jsxs)("p",{className:"figma-snapshot-code-summary",children:[String(w.fileCount)," reviewable file",1!==w.fileCount?"s":""," (",String(w.screenCount)," screen",1!==w.screenCount?"s":"",","," ",w.adapterName,") — proposal only, never auto-applied."]}),w.files.map(e=>(0,a.jsxs)("details",{className:"figma-snapshot-code-file",children:[(0,a.jsx)("summary",{className:"figma-snapshot-code-file-path",children:e.path}),(0,a.jsx)("pre",{className:"figma-snapshot-code-file-contents",children:(0,a.jsx)("code",{children:e.contents})})]},e.path))]})]}),(0,a.jsxs)("details",{className:"figma-snapshot-scopes",children:[(0,a.jsx)("summary",{className:"figma-snapshot-scopes-summary",children:"Required Figma PAT scopes"}),(0,a.jsxs)("ul",{className:"figma-snapshot-scopes-list",children:[(0,a.jsxs)("li",{children:[(0,a.jsx)("code",{children:"file_read"})," — read design file structure and node metadata"]}),(0,a.jsxs)("li",{children:[(0,a.jsx)("code",{children:"files:read"})," — read file content (REST API scope)"]})]}),(0,a.jsxs)("p",{className:"figma-snapshot-scopes-note",children:["The token is read server-side from the ",(0,a.jsx)("code",{children:"FIGMA_ACCESS_TOKEN"})," environment variable or vault. This window never holds or transmits the token."]})]}),m.screens.length>0?(0,a.jsx)("section",{className:"figma-snapshot-gallery","aria-label":"".concat(String(m.screenCount)," captured screen").concat(1!==m.screenCount?"s":""),children:m.screens.map((e,t)=>(0,a.jsx)(lX,{index:t,screenId:e.screenId,name:e.name,irSummary:e.irSummary,imageByteLength:e.imageByteLength},e.screenId))}):(0,a.jsx)("div",{className:"lk-empty",children:(0,a.jsx)("p",{className:"lk-empty-body",children:"No screens were captured from this board section."})})]})]})}async function lZ(e,t){var n,a;let l=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),s=await fetch(e,{...t,headers:{Accept:"application/json",...(null==t?void 0:t.body)!==void 0?{"Content-Type":"application/json"}:{},..."GET"===l||"HEAD"===l?{}:{"X-Keiko-CSRF":"1"},...null!=(a=null==t?void 0:t.headers)?a:{}}});if(!s.ok){let e="INTERNAL",t="HTTP ".concat(s.status.toString());try{let n=await s.json();e=n.error.code,t=n.error.message}catch(e){}throw new $.hD(e,t,s.status)}return s.json()}async function lQ(){return(await lZ("/api/quality-intelligence/runs")).runs}async function l$(e){return lZ("/api/quality-intelligence/runs/".concat(encodeURIComponent(e)))}async function l0(e){let t="QI_RUN_FAILED",n="HTTP ".concat(e.status.toString());try{var a,l,s,i;let r=await e.json();t=null!=(s=null==(a=r.error)?void 0:a.code)?s:t,n=null!=(i=null==(l=r.error)?void 0:l.message)?i:n}catch(e){}return new $.hD(t,n,e.status)}async function l1(e,t,n){var a,l;let s=await fetch("/api/quality-intelligence/runs",{method:"POST",headers:{Accept:"text/event-stream","Content-Type":"application/json","X-Keiko-CSRF":"1"},body:JSON.stringify(e),signal:t}),i=null!=(a=s.headers.get("content-type"))?a:"";if(!s.ok||!i.includes("text/event-stream"))throw await l0(s);let r=s.body;if(null===r)throw new $.hD("QI_NO_STREAM","The server did not return a progress stream.",s.status);let o=r.getReader(),c=new TextDecoder,d="";try{for(;!t.aborted;){let e=await o.read();if(e.done)break;let t=(d+=c.decode(e.value,{stream:!0})).split("\n");for(let e of(d=null!=(l=t.pop())?l:"",t)){let t=e.trim();if(t.startsWith("data:"))try{n(JSON.parse(t.slice(5).trim()))}catch(e){}}}}finally{o.releaseLock()}}async function l2(e,t,n,a){return lZ("/api/quality-intelligence/runs/".concat(encodeURIComponent(e),"/review"),{method:"POST",body:JSON.stringify({action:t,...void 0!==n?{candidateId:n}:{},...void 0!==a?{reviewerLabel:a}:{}})})}async function l5(e,t,n,a){return(await lZ("/api/quality-intelligence/runs/".concat(encodeURIComponent(e),"/edit"),{method:"POST",body:JSON.stringify({candidateId:t,edited:n,...void 0!==a?{editorLabel:a}:{}})})).candidate}async function l3(e,t){return lZ("/api/quality-intelligence/runs/".concat(encodeURIComponent(e),"/re-check"),{method:"POST",body:JSON.stringify({sources:t})})}async function l4(e,t){return lZ("/api/quality-intelligence/runs/".concat(encodeURIComponent(e),"/regenerate-stale"),{method:"POST",body:JSON.stringify({sources:t})})}async function l6(e,t,n){var a,l;return lZ("/api/quality-intelligence/runs/".concat(encodeURIComponent(e),"/export"),{method:"POST",body:JSON.stringify({adapter:t,dryRun:null!=(a=null==n?void 0:n.dryRun)&&a,approvedOnly:null!=(l=null==n?void 0:n.approvedOnly)&&l})})}async function l8(e,t){return lZ("/api/quality-intelligence/runs/".concat(encodeURIComponent(e),"/traceability"),{method:"POST",body:JSON.stringify({format:t})})}function l7(e){var t;let n=e.split(/[\\/]/u).filter(e=>e.length>0);return n.length>0&&null!=(t=n[n.length-1])?t:e}function l9(e){return e.replaceAll("\\","/")}function se(e){return/^[A-Za-z]:[/\\]?$/u.test(e)?e.replaceAll("\\","/"):/^\/\/[^/]+\/[^/]+$/u.test(l9(e))?l9(e):l9(e).replace(/\/+$/u,"")}function st(e){var t,n,a,l,s;let i=null!=(t=e.connectedRoot)?t:null,r=function(e,t){var n,a;let l=null!=(n=null==t?void 0:t.trim())?n:"";if(0===l.length)return null;if(l.startsWith("/")||/^[A-Za-z]:[/\\]/u.test(l)||l.startsWith("\\\\")||l.startsWith("//"))return l;let s=null!=(a=null==e?void 0:e.trim())?a:"";if(0===s.length)return null;let i=se(s),r=l9(l).replace(/^\/+/u,"");return"".concat(i,"/").concat(r)}(i,null!=(n=e.connectedFilePath)?n:null),o=null!==i?se(i):null,c=(void 0!==e.connectedRoots&&null!==e.connectedRoots&&e.connectedRoots.length>0?e.connectedRoots:null!==i?[i]:[]).map(se),d=null!==r?c.filter(e=>e!==o):c,u=[];for(let e of(null!==r&&u.push({kind:"file",label:l7(r),path:r}),d))u.push({kind:"workspace",label:l7(e),path:e});for(let t of null!=(a=e.connectedCapsuleIds)?a:[])u.push({kind:"capsule",label:t,capsuleId:t});for(let t of null!=(l=e.connectedCapsuleSetIds)?l:[])u.push({kind:"capsule-set",label:t,capsuleSetId:t});for(let t of null!=(s=e.connectedFigmaSnapshotRunIds)?s:[])u.push({kind:"figma-snapshot",label:t,snapshotRunId:t});let h=new Set,p=[];for(let e of u){if(p.length>=16)break;let t=function(e){switch(e.kind){case"file":case"workspace":return"".concat(e.kind,":").concat(e.path);case"capsule":return"capsule:".concat(e.capsuleId);case"capsule-set":return"capsule-set:".concat(e.capsuleSetId);case"figma-snapshot":return"figma-snapshot:".concat(e.snapshotRunId)}}(e);h.has(t)||(h.add(t),p.push(e))}return p}let sn=[{id:"regression-default",label:"Regression (default)"},{id:"banking-default",label:"Banking"},{id:"insurance-default",label:"Insurance"}],sa={phase:"Starting…",stageName:null,candidates:0,findings:0,atomCount:null,droppedSourceCount:0,skippedSources:[]};function sl(e){switch(e.kind){case"file":return"File";case"workspace":return"Folder";case"capsule":return"Capsule";case"capsule-set":return"Capsule set";case"figma-snapshot":return"Figma snapshot"}}function ss(e){switch(e.kind){case"file":case"workspace":return e.path;case"capsule":return e.capsuleId;case"capsule-set":return e.capsuleSetId;case"figma-snapshot":return e.snapshotRunId}}function si(e){let{onRunCompleted:t,startImpl:n=l1,connectedRoot:s=null,connectedFilePath:i=null,connectedRoots:r,connectedCapsuleIds:o,connectedCapsuleSetIds:c,connectedFigmaSnapshotRunIds:d}=e,[u,h]=(0,l.useState)(""),[p,m]=(0,l.useState)("requirements"),[f,g]=(0,l.useState)(""),[v,x]=(0,l.useState)(""),[y,b]=(0,l.useState)("regression-default"),[j,w]=(0,l.useState)(""),[k,N]=(0,l.useState)(!1),[S,C]=(0,l.useState)(sa),[R,I]=(0,l.useState)(null),E=(0,l.useRef)(null),M=(0,l.useRef)(null),T=st({connectedRoot:s,connectedFilePath:i,connectedRoots:r,connectedCapsuleIds:o,connectedCapsuleSetIds:c,connectedFigmaSnapshotRunIds:d}),q=T.length>0,P=("requirements"===p?f.trim().length>0:v.trim().length>0)||q,A=j.trim(),z=0===A.length?void 0:/^\d+$/u.test(A)?Number(A):NaN,D=void 0===z||Number.isSafeInteger(z)&&Number.isFinite(z),L=(0,l.useCallback)(e=>{"accepted"===e.type&&(M.current=e.runId),"error"===e.type&&I("".concat(e.code,": ").concat(e.message)),C(t=>(function(e,t){var n,a,l;if("accepted"===t.type)return{...e,phase:"Ingested sources",atomCount:t.atomCount,droppedSourceCount:null!=(n=t.droppedSourceCount)?n:0,skippedSources:null!=(a=t.skippedSources)?a:[]};if("event"===t.type){let n="candidate:proposed"===t.kind?e.candidates+1:e.candidates,a="finding:recorded"===t.kind?e.findings+1:e.findings,s="stage:started"===t.kind?null!=(l=t.stageName)?l:null:e.stageName;return{...e,phase:t.kind,stageName:s,candidates:n,findings:a}}return e})(t,e))},[]),F=(0,l.useCallback)(async()=>{if(!P||k)return;if(!D)return void I("Seed must be a non-negative integer.");N(!0),I(null),C(sa),M.current=null;let e=new AbortController;E.current=e;let a={sources:"requirements"===p&&f.trim().length>0?[{kind:"requirements",label:u.trim()||"Requirements",text:f}]:"workspace"===p&&v.trim().length>0?[{kind:"workspace",label:u.trim()||"Folder",path:v.trim()}]:T,profileId:y,...void 0!==z?{seed:z}:{}};try{await n(a,e.signal,L);let l=M.current;null!==l&&(null==t||t(l))}catch(t){e.signal.aborted||I(t instanceof $.hD?"".concat(t.code,": ").concat(t.message):t instanceof Error?t.message:"An unexpected error occurred.")}finally{N(!1),E.current=null}},[P,p,f,v,u,y,k,T,L,t,z,D,n]),O=(0,l.useCallback)(()=>{var e;null==(e=E.current)||e.abort()},[]);return(0,a.jsxs)("section",{className:"qi-launcher","aria-label":"Start a Quality Intelligence run",children:[(0,a.jsx)("header",{className:"qi-col-header",children:(0,a.jsx)("h2",{className:"qi-col-title",children:"New run"})}),(0,a.jsxs)("div",{className:"qi-launcher-body",children:[1===T.length&&void 0!==T[0]?(0,a.jsxs)("div",{className:"qi-connected-source","data-testid":"qi-connected-source",children:[(0,a.jsxs)("span",{className:"qi-connected-kind",children:["Connected ",sl(T[0]).toLowerCase()]}),(0,a.jsx)("span",{className:"qi-connected-path qi-monospace",title:ss(T[0]),children:ss(T[0])}),(0,a.jsxs)("span",{className:"qi-connected-hint",children:["Generate uses the connected ",sl(T[0]).toLowerCase(),"."]})]}):T.length>1?(0,a.jsxs)("div",{className:"qi-connected-source","data-testid":"qi-connected-source",children:[(0,a.jsxs)("span",{className:"qi-connected-kind",children:["Connected sources (",T.length.toString(),")"]}),(0,a.jsx)("ul",{className:"qi-connected-roots","aria-label":"Connected sources",children:T.map(e=>(0,a.jsxs)("li",{className:"qi-connected-root-item",children:[(0,a.jsx)("span",{className:"qi-connected-root-name",children:sl(e)}),(0,a.jsx)("span",{className:"qi-connected-path qi-monospace",title:ss(e),children:ss(e)})]},"".concat(e.kind,":").concat(ss(e))))}),(0,a.jsx)("span",{className:"qi-connected-hint",children:"Generate uses all connected sources."})]}):null,(0,a.jsxs)("div",{className:"qi-launcher-row",children:[(0,a.jsxs)("label",{className:"qi-field",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Source label"}),(0,a.jsx)("input",{type:"text",className:"qi-input",value:u,placeholder:"e.g. Funds Transfer — acceptance criteria",disabled:k,onChange:e=>{h(e.target.value)}})]}),(0,a.jsxs)("label",{className:"qi-field qi-field-kind",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Source type"}),(0,a.jsxs)("select",{className:"qi-select",value:p,disabled:k,onChange:e=>{m("workspace"===e.target.value?"workspace":"requirements"),I(null)},children:[(0,a.jsx)("option",{value:"requirements",children:"Requirements text"}),(0,a.jsx)("option",{value:"workspace",children:"Local folder"})]})]})]}),"requirements"===p?(0,a.jsxs)("label",{className:"qi-field",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Requirements"}),(0,a.jsx)("textarea",{className:"qi-textarea",value:f,rows:6,placeholder:"Paste requirements or acceptance criteria, one statement per line.",disabled:k,onChange:e=>{g(e.target.value)}})]}):(0,a.jsxs)("label",{className:"qi-field",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Folder path"}),(0,a.jsx)("input",{type:"text",className:"qi-input",value:v,placeholder:"/absolute/path/to/requirements-folder",disabled:k,onChange:e=>{x(e.target.value)}})]}),(0,a.jsxs)("div",{className:"qi-launcher-controls",children:[(0,a.jsxs)("label",{className:"qi-field qi-field-inline",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Policy profile"}),(0,a.jsx)("select",{className:"qi-select",value:y,disabled:k,onChange:e=>{b(e.target.value)},children:sn.map(e=>(0,a.jsx)("option",{value:e.id,children:e.label},e.id))})]}),(0,a.jsxs)("label",{className:"qi-field qi-field-inline",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Seed (optional)"}),(0,a.jsx)("input",{type:"number",min:0,step:1,className:"qi-input",value:j,placeholder:"e.g. 42",disabled:k,onChange:e=>{w(e.target.value),I(null)}})]}),k?(0,a.jsx)("button",{type:"button",className:"qi-btn qi-btn-secondary",onClick:O,children:"Cancel"}):(0,a.jsx)("button",{type:"button",className:"qi-btn qi-btn-primary",disabled:!P||!D,onClick:()=>{F()},children:"Generate test cases"})]}),k?(0,a.jsxs)("div",{className:"qi-progress",role:"status","aria-live":"polite","aria-label":"Run progress","data-testid":"qi-launch-progress",children:[(0,a.jsx)("span",{className:"qi-progress-spinner","aria-hidden":"true"}),(0,a.jsxs)("span",{className:"qi-progress-text",children:[null!==S.stageName?"Stage: ".concat(S.stageName," \xb7 "):"",S.candidates.toString()," test case",1!==S.candidates?"s":"",S.findings>0?" \xb7 ".concat(S.findings.toString()," findings"):""]})]}):null,S.droppedSourceCount>0||S.skippedSources.length>0?(0,a.jsxs)("div",{className:"qi-coverage-notice",role:"status","aria-live":"polite","data-testid":"qi-coverage-notice",children:[S.droppedSourceCount>0?(0,a.jsxs)("p",{className:"qi-coverage-line",children:[S.droppedSourceCount.toString()," source",1!==S.droppedSourceCount?"s":""," over the 16-source limit"," ",1!==S.droppedSourceCount?"were":"was"," not included."]}):null,S.skippedSources.length>0?(0,a.jsxs)("p",{className:"qi-coverage-line",children:[S.skippedSources.length.toString()," connected source",1!==S.skippedSources.length?"s":""," could not be read and"," ",1!==S.skippedSources.length?"were":"was"," skipped:"," ",S.skippedSources.map(e=>e.label).join(", "),"."]}):null]}):null,null!==R?(0,a.jsx)("p",{className:"lk-alert",role:"alert","data-testid":"qi-launch-error",children:R}):null]})]})}function sr(e){return e instanceof $.hD?"".concat(e.code,": ").concat(e.message):e instanceof Error?e.message:"An unexpected error occurred."}function so(e){try{return new Date(e).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"})}catch(t){return e}}let sc={running:"Running",succeeded:"Succeeded",failed:"Failed",cancelled:"Cancelled"},sd={running:"qi-badge-running",succeeded:"qi-badge-succeeded",failed:"qi-badge-failed",cancelled:"qi-badge-cancelled"};function su(e){return"running"===e||"succeeded"===e||"failed"===e||"cancelled"===e}function sh(e){let{status:t}=e,n=su(t)?sc[t]:t,l=su(t)?sd[t]:"qi-badge-default";return(0,a.jsx)("span",{"aria-label":"Status: ".concat(n),className:"qi-badge ".concat(l),children:n})}let sp={critical:"qi-sev-critical",high:"qi-sev-high",medium:"qi-sev-medium",low:"qi-sev-low"};function sm(e){let{severity:t}=e,n="critical"===t||"high"===t||"medium"===t||"low"===t?sp[t]:"qi-sev-low";return(0,a.jsx)("span",{"aria-label":"Severity: ".concat(t),className:"qi-sev ".concat(n),children:t})}function sf(e){let{score:t}=e;if(null===t)return(0,a.jsx)("span",{"aria-label":"Quality score: not available",className:"qi-badge qi-badge-default","data-testid":"qi-quality-badge",children:"—"});let n=Math.round(t);return(0,a.jsx)("span",{"aria-label":"Quality score: ".concat(n.toString()," out of 100"),className:"qi-badge ".concat(n>=90?"qi-quality-high":n>=70?"qi-quality-mid":"qi-quality-low"),"data-testid":"qi-quality-badge",children:n.toString()})}function sg(e){let{flag:t}=e;return(0,a.jsxs)("div",{role:"note","aria-label":"Weak test flagged by the quality judge: ".concat(t.rationale),className:"qi-weak-flag","data-testid":"qi-weak-flag",children:[(0,a.jsxs)("span",{className:"qi-weak-flag-badge",children:[(0,a.jsx)("span",{"aria-hidden":"true",className:"qi-weak-flag-icon",children:"⚠"}),"Weak test"]}),(0,a.jsx)("p",{className:"qi-weak-flag-reason",children:t.rationale})]})}function sv(e){let{height:t=20,width:n="100%"}=e;return(0,a.jsx)("div",{"aria-hidden":"true",className:"qi-skeleton",style:{height:t,width:n}})}function sx(){return(0,a.jsx)("div",{"data-testid":"qi-loading-state","aria-busy":"true",style:{display:"flex",flexDirection:"column",gap:8,padding:"12px 0"},children:[1,2,3].map(e=>(0,a.jsxs)("div",{className:"qi-skeleton-row",children:[(0,a.jsx)(sv,{height:14,width:"60%"}),(0,a.jsx)(sv,{height:12,width:"40%"})]},e))})}function sy(e){let{message:t,onRetry:n}=e;return(0,a.jsxs)("div",{role:"alert","aria-live":"assertive",className:"lk-alert","data-testid":"qi-error-state",children:[t,(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:n,children:"Retry"})]})}function sb(e){let{run:t,onOpen:n}=e;return(0,a.jsx)("li",{children:(0,a.jsxs)("button",{type:"button",className:"qi-run-item",onClick:()=>{n(t.id)},"aria-label":"Open run ".concat(t.id),title:"Open run ".concat(t.id),children:[(0,a.jsx)("span",{className:"qi-run-id",children:t.id.slice(0,16)}),(0,a.jsx)(sh,{status:t.status}),(0,a.jsx)("span",{className:"qi-run-meta",children:so(t.requestedAt)}),(0,a.jsxs)("span",{className:"qi-run-totals",children:[t.totals.candidates.toString()," case",1!==t.totals.candidates?"s":""]})]})})}function sj(e){let{openRun:t,connectedRoot:n=null,connectedFilePath:s=null,connectedRoots:i,connectedCapsuleIds:r,connectedCapsuleSetIds:o,connectedFigmaSnapshotRunIds:c,fetchRunsImpl:d=lQ}=e,[u,h]=(0,l.useState)([]),[p,m]=(0,l.useState)(!0),[f,g]=(0,l.useState)(null),v=(0,l.useCallback)(async()=>{m(!0),g(null);try{h(await d())}catch(e){g(sr(e))}finally{m(!1)}},[d]);(0,l.useEffect)(()=>{v()},[v]);let x=(0,l.useCallback)(e=>{v(),t(e)},[v,t]);return(0,a.jsxs)("div",{className:"qi-hub",children:[(0,a.jsx)(si,{onRunCompleted:x,connectedRoot:n,connectedFilePath:s,connectedRoots:i,connectedCapsuleIds:r,connectedCapsuleSetIds:o,connectedFigmaSnapshotRunIds:c}),(0,a.jsxs)("section",{className:"qi-hub-runs","aria-label":"Quality Intelligence runs",children:[(0,a.jsxs)("header",{className:"qi-col-header",children:[(0,a.jsx)("h2",{className:"qi-col-title",children:"Runs"}),p||null!==f?null:(0,a.jsx)("span",{className:"qi-col-count",children:u.length.toString()})]}),(0,a.jsx)("div",{className:"qi-col-body","aria-live":"polite","aria-busy":p,children:p?(0,a.jsx)(sx,{}):null!==f?(0,a.jsx)(sy,{message:f,onRetry:()=>{v()}}):0===u.length?(0,a.jsxs)("div",{className:"lk-empty",children:[(0,a.jsx)("p",{className:"lk-empty-title",children:"No runs yet"}),(0,a.jsx)("p",{className:"lk-empty-body",children:"Start a run above — generated test cases open as cards on your workspace."})]}):(0,a.jsx)("ul",{className:"qi-run-list","aria-label":"Run list",children:u.map(e=>(0,a.jsx)(sb,{run:e,onOpen:t},e.id))})})]})]})}let sw=["P0","P1","P2","P3"],sk=["safety","compliance","regression","functional","visual"],sN=e=>e.split("\n").map(e=>e.trim()).filter(e=>e.length>0),sS=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]);function sC(e){let{id:t,label:n,value:l,disabled:s=!1,onChange:i}=e;return(0,a.jsxs)("label",{className:"qi-edit-field",htmlFor:t,children:[(0,a.jsx)("span",{className:"qi-edit-label",children:n}),(0,a.jsx)("textarea",{id:t,className:"qi-edit-textarea",value:l,rows:3,disabled:s,onChange:e=>{i(e.target.value)}})]})}function sR(e){let{id:t,label:n,value:l,disabled:s=!1,onChange:i}=e;return(0,a.jsxs)("label",{className:"qi-edit-field",htmlFor:t,children:[(0,a.jsx)("span",{className:"qi-edit-label",children:n}),(0,a.jsx)("input",{id:t,className:"qi-edit-input",value:l,disabled:s,onChange:e=>{i(e.target.value)}})]})}function sI(e){let{id:t,label:n,value:l,options:s,disabled:i=!1,onChange:r}=e;return(0,a.jsxs)("label",{className:"qi-edit-field",htmlFor:t,children:[(0,a.jsx)("span",{className:"qi-edit-label",children:n}),(0,a.jsx)("select",{id:t,className:"qi-edit-select",value:l,disabled:i,onChange:e=>{r(e.target.value)},children:s.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]})}function sE(e){let{onCancel:t,saving:n}=e;return(0,a.jsxs)("div",{className:"qi-edit-actions",children:[(0,a.jsx)("button",{type:"submit",className:"qi-btn qi-btn-approve qi-edit-save",disabled:n,children:"Save"}),(0,a.jsx)("button",{type:"button",className:"qi-btn qi-btn-secondary qi-edit-cancel",onClick:t,disabled:n,children:"Cancel"})]})}function sM(e){let{candidate:t,onSave:n,onCancel:s}=e,[i,r]=(0,l.useState)(()=>({title:t.title,preconditions:t.preconditions.join("\n"),steps:t.steps.join("\n"),expectedResults:t.expectedResults.join("\n"),priority:t.priority,riskClass:t.riskClass,tags:t.tags.join(", ")})),[o,c]=(0,l.useState)(null),[d,u]=(0,l.useState)(!1),h=(0,l.useRef)(null),p=(e,t)=>{c(null),r(n=>({...n,[e]:t}))};(0,l.useEffect)(()=>{let e=e=>{if("Escape"!==e.key||d)return;let t=h.current;null!==t&&t.contains(document.activeElement)&&s()};return document.addEventListener("keydown",e),()=>{document.removeEventListener("keydown",e)}},[s,d]),(0,l.useEffect)(()=>{var e,t;null==(t=h.current)||null==(e=t.querySelector("input.qi-edit-input"))||e.focus()},[]);let m="qi-edit-".concat(t.id),f=async()=>{if(!d){u(!0),c(null);try{await n(function(e,t){let n=sN(t.preconditions),a=sN(t.steps),l=sN(t.expectedResults),s=t.tags.split(",").map(e=>e.trim()).filter(e=>e.length>0);return{...t.title!==e.title?{title:t.title}:{},...!sS(n,e.preconditions)?{preconditions:n}:{},...!sS(a,e.steps)?{steps:a}:{},...!sS(l,e.expectedResults)?{expectedResults:l}:{},...t.priority!==e.priority?{priority:t.priority}:{},...t.riskClass!==e.riskClass?{riskClass:t.riskClass}:{},...!sS(s,e.tags)?{tags:s}:{}}}(t,i))}catch(e){c(sr(e))}finally{u(!1)}}};return(0,a.jsxs)("form",{ref:h,className:"qi-edit-form","aria-label":"Edit ".concat(t.title),"aria-busy":d,onSubmit:e=>{e.preventDefault(),f()},children:[(0,a.jsx)(sR,{id:"".concat(m,"-title"),label:"Title",value:i.title,disabled:d,onChange:e=>{p("title",e)}}),(0,a.jsx)(sC,{id:"".concat(m,"-preconditions"),label:"Preconditions (one per line)",value:i.preconditions,disabled:d,onChange:e=>{p("preconditions",e)}}),(0,a.jsx)(sC,{id:"".concat(m,"-steps"),label:"Steps (one per line)",value:i.steps,disabled:d,onChange:e=>{p("steps",e)}}),(0,a.jsx)(sC,{id:"".concat(m,"-expected"),label:"Expected results (one per line)",value:i.expectedResults,disabled:d,onChange:e=>{p("expectedResults",e)}}),(0,a.jsx)(sI,{id:"".concat(m,"-priority"),label:"Priority",value:i.priority,options:sw,disabled:d,onChange:e=>{p("priority",e)}}),(0,a.jsx)(sI,{id:"".concat(m,"-risk"),label:"Risk class",value:i.riskClass,options:sk,disabled:d,onChange:e=>{p("riskClass",e)}}),(0,a.jsx)(sR,{id:"".concat(m,"-tags"),label:"Tags (comma-separated)",value:i.tags,disabled:d,onChange:e=>{p("tags",e)}}),null!==o?(0,a.jsx)("p",{className:"qi-edit-error",role:"alert","aria-live":"assertive",children:o}):null,(0,a.jsx)(sE,{onCancel:s,saving:d})]})}let sT={open:"Open",approved:"Approved","changes-requested":"Changes requested",rejected:"Rejected",withdrawn:"Withdrawn"},sq={open:"qi-review-open",approved:"qi-review-approved","changes-requested":"qi-review-changes",rejected:"qi-review-rejected",withdrawn:"qi-review-withdrawn"};function sP(e){let{state:t}=e;return(0,a.jsx)("span",{className:"qi-review-badge ".concat(sq[t]),"aria-label":"Review: ".concat(sT[t]),children:sT[t]})}function sA(e){let{items:t,label:n}=e;return 0===t.length?null:(0,a.jsxs)("div",{className:"qi-cand-block",children:[(0,a.jsx)("p",{className:"qi-cand-block-label",children:n}),(0,a.jsx)("ol",{className:"qi-cand-list","aria-label":n,children:t.map((e,t)=>(0,a.jsx)("li",{children:e},"".concat(n,"-").concat(String(t))))})]})}function sz(e){let{className:t,label:n,pressed:l,disabled:s,describedBy:i,onActivate:r}=e;return(0,a.jsx)("button",{type:"button",className:t,...void 0!==l?{"aria-pressed":l}:{},"aria-disabled":s||void 0,"aria-describedby":s?i:void 0,onClick:()=>{s||r()},children:n})}function sD(e){let{candidateId:t,state:n,onReview:l,disabled:s=!1,describedBy:i}=e;return(0,a.jsxs)("div",{className:"qi-cand-actions",role:"group","aria-label":"Review decision",children:[(0,a.jsx)(sz,{className:"qi-btn qi-btn-approve",label:"Approve",pressed:"approved"===n,disabled:s,describedBy:i,onActivate:()=>{l(t,"approve")}}),(0,a.jsx)(sz,{className:"qi-btn qi-btn-reject",label:"Reject",pressed:"rejected"===n,disabled:s,describedBy:i,onActivate:()=>{l(t,"reject")}}),(0,a.jsx)(sz,{className:"qi-btn qi-btn-secondary",label:"Request changes",pressed:"changes-requested"===n,disabled:s,describedBy:i,onActivate:()=>{l(t,"request-changes")}})]})}function sL(e){let{candidate:t,onReview:n,onStartEdit:l,actionsDisabled:s=!1,describedBy:i,editButtonRef:r}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"qi-cand-header",children:[(0,a.jsx)("h3",{className:"qi-cand-title",children:t.title}),(0,a.jsxs)("div",{className:"qi-cand-badges",children:[(0,a.jsx)("span",{className:"qi-cand-pri",children:t.priority}),(0,a.jsx)("span",{className:"qi-cand-risk",children:t.riskClass}),(0,a.jsx)(sP,{state:t.reviewState})]})]}),void 0!==t.weakTestFlag?(0,a.jsx)(sg,{flag:t.weakTestFlag}):null,(0,a.jsx)(sA,{items:t.preconditions,label:"Preconditions"}),(0,a.jsx)(sA,{items:t.steps,label:"Steps"}),(0,a.jsx)(sA,{items:t.expectedResults,label:"Expected results"}),t.tags.length>0?(0,a.jsx)("ul",{className:"qi-cand-tags","aria-label":"Tags",children:t.tags.map(e=>(0,a.jsx)("li",{className:"qi-cand-tag",children:e},e))}):null,(0,a.jsxs)("div",{className:"qi-cand-actions-row",children:[void 0!==l?(0,a.jsx)("button",{ref:r,type:"button",className:"qi-btn qi-btn-secondary qi-cand-edit","aria-disabled":s||void 0,"aria-describedby":s?i:void 0,onClick:()=>{s||l()},children:"Edit"}):null,void 0!==n?(0,a.jsx)(sD,{candidateId:t.id,state:t.reviewState,onReview:n,disabled:s,describedBy:i}):null]})]})}function sF(e){let{candidate:t,onReview:n,onEdit:s,actionsDisabled:i=!1,describedBy:r}=e,[o,c]=(0,l.useState)(!1),d=(0,l.useRef)(null),u=(0,l.useRef)(!1);(0,l.useEffect)(()=>{var e;u.current&&!o&&(null==(e=d.current)||e.focus()),u.current=o},[o]);let h=async e=>{void 0!==s&&await s(t.id,e),c(!1)};return(0,a.jsx)("li",{className:"qi-cand-card",children:o&&void 0!==s?(0,a.jsx)(sM,{candidate:t,onSave:h,onCancel:()=>{c(!1)}}):(0,a.jsx)(sL,{candidate:t,onReview:n,actionsDisabled:i,describedBy:r,editButtonRef:d,onStartEdit:void 0!==s?()=>{c(!0)}:void 0})})}function sO(e){let{candidates:t,onReview:n,onEdit:s,actionsDisabled:i=!1,actionsDisabledReason:r}=e,[o,c]=(0,l.useState)(25),d=(0,l.useId)(),u=i&&void 0!==r;if(0===t.length)return(0,a.jsxs)("div",{className:"lk-empty",children:[(0,a.jsx)("p",{className:"lk-empty-title",children:"No test cases"}),(0,a.jsx)("p",{className:"lk-empty-body",children:"This run produced no generated test cases."})]});let h=t.slice(0,o);return(0,a.jsxs)("div",{className:"qi-cand-pane",children:[u?(0,a.jsx)("p",{id:d,className:"qi-cand-governance-note",role:"note",children:r}):null,(0,a.jsx)("ul",{className:"qi-cand-cards","aria-label":"Generated test cases",children:h.map(e=>(0,a.jsx)(sF,{candidate:e,onReview:n,onEdit:s,actionsDisabled:i,describedBy:u?d:void 0},e.id))}),o<t.length?(0,a.jsxs)("button",{type:"button",className:"qi-btn qi-btn-secondary qi-cand-more",onClick:()=>{c(e=>e+25)},children:["Show more (",(t.length-o).toString()," remaining)"]}):null]})}function sK(e){let{staleCount:t}=e;return 0===t?(0,a.jsxs)("p",{className:"qi-drift-fresh",role:"status","data-testid":"qi-drift-fresh",children:[(0,a.jsx)("span",{"aria-hidden":"true",className:"qi-drift-icon-ok",children:"✓"}),"No drift — every test is current."]}):(0,a.jsxs)("p",{className:"qi-drift-stale",role:"status","data-testid":"qi-drift-stale",children:[(0,a.jsx)("span",{"aria-hidden":"true",className:"qi-drift-icon-warn",children:"⚠"}),"".concat(t.toString()," ").concat(1===t?"test is":"tests are"," stale — source changed since this run.")]})}function sB(e){let{runId:t,connectedSources:n,onRegenerated:s,reCheckImpl:i=l3,regenerateImpl:r=l4}=e,[o,c]=(0,l.useState)(null),[d,u]=(0,l.useState)(!1),[h,p]=(0,l.useState)(null),[m,f]=(0,l.useState)(null),g=(0,l.useCallback)(()=>{(async()=>{u(!0),p(null),f(null);try{c(await i(t,n))}catch(e){p(sr(e))}finally{u(!1)}})()},[i,t,n]),v=(0,l.useCallback)(()=>{(async()=>{u(!0),p(null);try{let e=await r(t,n);f(e),c(null),null==s||s(e)}catch(e){p(sr(e))}finally{u(!1)}})()},[r,t,n,s]);return(0,a.jsxs)("section",{className:"qi-drift-panel","aria-label":"Drift detection",children:[(0,a.jsxs)("div",{className:"qi-drift-head",children:[(0,a.jsx)("h3",{className:"qi-col-subtitle",children:"Living tests"}),(0,a.jsx)("button",{type:"button",className:"qi-btn qi-btn-secondary",onClick:g,disabled:d,"data-testid":"qi-drift-recheck",children:d?"Checking…":"Re-check drift"})]}),null!==h?(0,a.jsx)("p",{className:"lk-alert",role:"alert",children:h}):null,null!==o?(0,a.jsx)(sK,{staleCount:o.staleCount}):null,null!==o&&o.staleCount>0&&null===m?(0,a.jsx)("button",{type:"button",className:"qi-btn qi-btn-approve",onClick:v,disabled:d,"data-testid":"qi-drift-regenerate",children:"Regenerate ".concat(o.staleCount.toString()," stale ").concat(1===o.staleCount?"test":"tests")}):null,null!==m?(0,a.jsx)("p",{className:"qi-drift-regenerated",role:"status","data-testid":"qi-drift-regenerated",children:"Regenerated ".concat(m.regeneratedCount.toString()," test(s) as a new run (").concat(m.preservedCount.toString()," preserved).")}):null]})}let sW={"traceability-csv":"csv","traceability-markdown":"markdown"},sU=[{id:"csv",label:"CSV",tms:!1},{id:"json",label:"JSON",tms:!1},{id:"spreadsheet-safe-csv",label:"Spreadsheet-safe CSV",tms:!1},{id:"markdown",label:"Markdown",tms:!1},{id:"plain-text",label:"Plain text",tms:!1},{id:"pdf",label:"PDF",tms:!1},{id:"zip-bundle",label:"ZIP bundle (all formats)",tms:!1},{id:"traceability-csv",label:"Traceability matrix (CSV)",tms:!1},{id:"traceability-markdown",label:"Traceability matrix (Markdown)",tms:!1},{id:"jira-issues",label:"Jira (preview)",tms:!0},{id:"qtest",label:"qTest (preview)",tms:!0},{id:"xray",label:"Xray (preview)",tms:!0},{id:"polarion",label:"Polarion (preview)",tms:!0},{id:"quality-center",label:"Quality Center (preview)",tms:!0}];function s_(e,t,n,a){let l=new Blob(["base64"===a?function(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}(n):n],{type:t}),s=URL.createObjectURL(l),i=document.createElement("a");i.href=s,i.download=e,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(s)}function sH(e){var t;let{runId:n,exportImpl:s=l6,traceabilityImpl:i=l8}=e,[r,o]=(0,l.useState)("csv"),[c,d]=(0,l.useState)(!1),[u,h]=(0,l.useState)(null),[p,m]=(0,l.useState)(null),[f,g]=(0,l.useState)(null),v=sU.find(e=>e.id===r),x=null!=(t=null==v?void 0:v.tms)&&t,y=(0,l.useCallback)(async()=>{let e=sW[r];if(void 0!==e){let t=await i(n,e);s_(t.filename,t.contentType,t.body),g(t.filename);return}let t=await s(n,r,{dryRun:x,approvedOnly:!1});t.dryRun?m("".concat(t.candidateCount.toString()," candidates \xb7 ").concat(t.byteLen.toString()," bytes\n\n").concat(t.preview)):(s_(t.filename,t.contentType,t.body,t.encoding),g(t.filename))},[n,r,x,s,i]),b=(0,l.useCallback)(async()=>{d(!0),h(null),m(null),g(null);try{await y()}catch(e){h(e instanceof $.hD?"".concat(e.code,": ").concat(e.message):e instanceof Error?e.message:"Export failed.")}finally{d(!1)}},[y]);return(0,a.jsxs)("div",{className:"qi-export","data-testid":"qi-export-bar",children:[(0,a.jsxs)("label",{className:"qi-field qi-field-inline",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Export"}),(0,a.jsx)("select",{className:"qi-select",value:r,disabled:c,onChange:e=>{o(e.target.value),m(null),h(null),g(null)},children:sU.map(e=>(0,a.jsx)("option",{value:e.id,children:e.label},e.id))})]}),(0,a.jsx)("button",{type:"button",className:"qi-btn qi-btn-secondary",disabled:c,onClick:()=>{b()},children:x?"Preview":"Download"}),x?(0,a.jsx)("p",{className:"qi-export-hint",role:"note","data-testid":"qi-export-connector-hint",children:(null==v?void 0:v.id)==="quality-center"?"Quality Center is preview-only. Configure a connector to enable live export.":"External target — preview only. Configure a connector to enable live export."}):null,null!==f?(0,a.jsx)("p",{className:"qi-export-success",role:"status","aria-live":"polite","data-testid":"qi-export-success",children:"Downloaded ".concat(f)}):null,null!==p?(0,a.jsx)("pre",{className:"qi-export-preview",role:"status","aria-live":"polite","data-testid":"qi-export-preview",children:p}):null,null!==u?(0,a.jsx)("p",{className:"lk-alert",role:"alert","data-testid":"qi-export-error",children:u}):null]})}let sJ="keiko.qi.reviewerLabel",sV="Set a reviewer label to review or edit candidates.";function sG(e){let{detail:t}=e;return(0,a.jsxs)("dl",{className:"qi-run-summary","aria-label":"Run summary",children:[(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Status"}),(0,a.jsx)("dd",{children:(0,a.jsx)(sh,{status:t.status})})]}),(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Test cases"}),(0,a.jsx)("dd",{children:t.totals.candidates.toString()})]}),(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Findings"}),(0,a.jsx)("dd",{children:t.totals.findings.toString()})]}),(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Quality"}),(0,a.jsx)("dd",{children:(0,a.jsx)(sf,{score:t.qualityScore})})]}),(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Review"}),(0,a.jsx)("dd",{className:"qi-run-summary-review",children:t.reviewState})]}),(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Requested"}),(0,a.jsx)("dd",{children:so(t.requestedAt)})]}),null!==t.completedAt?(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Completed"}),(0,a.jsx)("dd",{children:so(t.completedAt)})]}):null]})}function sX(e){let{detail:t}=e;return 0===t.findingRefs.length?null:(0,a.jsxs)("section",{className:"qi-run-findings","aria-label":"Findings",children:[(0,a.jsxs)("h3",{className:"qi-col-subtitle",children:["Findings",(0,a.jsx)("span",{className:"qi-col-count",children:t.findingRefs.length.toString()})]}),(0,a.jsx)("ul",{className:"qi-finding-list","aria-label":"Findings list",children:t.findingRefs.map(e=>(0,a.jsxs)("li",{className:"qi-finding-item",children:[(0,a.jsxs)("div",{className:"qi-finding-header",children:[(0,a.jsx)("span",{className:"qi-finding-kind",children:e.kind}),(0,a.jsx)(sm,{severity:e.severity})]}),(0,a.jsx)("p",{className:"qi-finding-summary",children:e.summaryRedacted})]},e.id))})]})}let sY={covered:"Covered","weakly-covered":"Weakly covered",uncovered:"Uncovered"},sZ={covered:"qi-cov-covered","weakly-covered":"qi-cov-weak",uncovered:"qi-cov-uncovered"};function sQ(e){let{detail:t}=e;if(0===t.coverageByAtom.length)return null;let n=t.coverageByAtom.length,l=t.coverageByAtom.filter(e=>"covered"===e.status).length,s=t.coverageByAtom.filter(e=>"covered"!==e.status);return(0,a.jsxs)("section",{className:"qi-coverage-panel","aria-label":"Coverage",children:[(0,a.jsxs)("h3",{className:"qi-col-subtitle",children:["Coverage",(0,a.jsxs)("span",{className:"qi-badge qi-badge-default","aria-label":"Coverage: ".concat(t.coveragePercentage.toFixed(0)," percent, ").concat(l.toString()," of ").concat(n.toString()," requirements covered"),"data-testid":"qi-coverage-pct",children:[t.coveragePercentage.toFixed(0),"%"]})]}),(0,a.jsx)("p",{className:"qi-coverage-summary","data-testid":"qi-coverage-summary",children:"".concat(l.toString()," of ").concat(n.toString()," requirements covered \xb7 ").concat(s.length.toString()," gap").concat(1===s.length?"":"s")}),s.length>0?(0,a.jsxs)("section",{className:"qi-coverage-gaps","aria-label":"Gap radar",children:[(0,a.jsx)("h4",{className:"qi-col-subtitle",children:"Gap radar (".concat(s.length.toString(),")")}),(0,a.jsx)("ul",{className:"qi-coverage-gap-list","aria-label":"Uncovered and weakly covered atoms",children:s.map(e=>{let t=sY[e.status],n=sZ[e.status],l=e.requirementExcerptRedacted;return(0,a.jsxs)("li",{className:"qi-coverage-gap-item","aria-label":void 0===l?"Atom ".concat(e.atomId,": ").concat(t):'Requirement "'.concat(l,'" (atom ').concat(e.atomId,"): ").concat(t),children:[(0,a.jsxs)("span",{className:"qi-coverage-gap-req",children:[void 0===l?null:(0,a.jsx)("span",{className:"qi-coverage-gap-text","data-testid":"qi-coverage-gap-text",children:l}),(0,a.jsx)("span",{className:"qi-coverage-atom-id qi-monospace",children:e.atomId})]}),(0,a.jsx)("span",{className:"qi-badge ".concat(n),"aria-hidden":"true",children:t}),(0,a.jsx)("span",{className:"qi-sr-only",children:t})]},e.atomId)})})]}):null]})}function s$(e){let{runId:t,connectedSources:n,onRegenerated:s,fetchDetailImpl:i=l$,reviewImpl:r=l2,editImpl:o=l5,reCheckImpl:c,regenerateImpl:d}=e,[u,h]=(0,l.useState)(null),[p,m]=(0,l.useState)(!0),[f,g]=(0,l.useState)(null),[v,x]=(0,l.useState)(""),[y,b]=(0,l.useState)(!1),j=(0,l.useId)(),w=(0,l.useId)(),k=(0,l.useRef)(0),N=(0,l.useCallback)(async()=>{let e=k.current+1;k.current=e,m(!0),g(null);try{let n=await i(t);k.current===e&&h(n)}catch(t){k.current===e&&g(sr(t))}finally{k.current===e&&m(!1)}},[i,t]);(0,l.useEffect)(()=>{N()},[N]),(0,l.useEffect)(()=>{x(function(){try{var e;return null!=(e=window.localStorage.getItem(sJ))?e:""}catch(e){return""}}()),b(!0)},[]),(0,l.useEffect)(()=>{if(y)try{window.localStorage.setItem(sJ,v)}catch(e){}},[v,y]);let S=v.trim(),C=S.length>0,R=(0,l.useCallback)((e,n)=>{C&&(async()=>{try{await r(t,n,e,S),await N()}catch(e){g(sr(e))}})()},[C,r,t,S,N]),I=(0,l.useCallback)(async(e,n)=>{if(!C)throw Error(sV);await o(t,e,n,S),await N()},[o,C,t,S,N]);return(0,a.jsxs)("div",{className:"qi-run-card","data-testid":"qi-run-card",children:[(0,a.jsx)("header",{className:"qi-run-card-head",children:(0,a.jsx)("span",{className:"qi-run-id qi-monospace",title:t,children:t})}),(0,a.jsx)("div",{className:"qi-run-card-body",role:"status","aria-live":"polite","aria-busy":p,children:p&&null===u?(0,a.jsx)(sx,{}):null!==f?(0,a.jsx)(sy,{message:f,onRetry:()=>void N()}):null===u?(0,a.jsx)("div",{className:"lk-empty",children:(0,a.jsx)("p",{className:"lk-empty-body",children:"Run not found."})}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("section",{className:"qi-run-governance","aria-label":"Review governance",children:[(0,a.jsxs)("label",{className:"qi-field",htmlFor:"qi-reviewer-label-".concat(t),children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Reviewer label"}),(0,a.jsx)("input",{id:"qi-reviewer-label-".concat(t),className:"qi-input qi-run-governance-input",value:v,placeholder:"Required for review and edit actions","aria-invalid":!C,"aria-describedby":C?j:"".concat(j," ").concat(w),onChange:e=>{x(e.target.value)}})]}),(0,a.jsx)("p",{id:j,className:"qi-run-governance-help",children:"Used for QI review and edit audit entries."}),C?null:(0,a.jsx)("p",{id:w,className:"qi-run-governance-warning",role:"note",children:sV})]}),(0,a.jsx)(sG,{detail:u}),(0,a.jsx)(sX,{detail:u}),(0,a.jsx)(sQ,{detail:u}),void 0!==n&&n.length>0?(0,a.jsx)(sB,{runId:t,connectedSources:n,onRegenerated:s,reCheckImpl:c,regenerateImpl:d}):null,(0,a.jsxs)("section",{className:"qi-run-cases","aria-label":"Generated test cases",children:[(0,a.jsxs)("div",{className:"qi-run-cases-head",children:[(0,a.jsxs)("h3",{className:"qi-col-subtitle",children:["Test cases",(0,a.jsx)("span",{className:"qi-col-count",children:u.candidates.length.toString()})]}),u.candidates.length>0?(0,a.jsx)(sH,{runId:t}):null]}),(0,a.jsx)(sO,{candidates:u.candidates,onReview:R,onEdit:I,actionsDisabled:!C,actionsDisabledReason:sV})]})]})})]})}let s0={inactive:{label:"Inactive",ariaDescription:"No recent activity for this relationship.",iconShape:"hollow-circle",textColor:"var(--fg-muted)",bgColor:"var(--inset)",animated:!1},queued:{label:"Queued",ariaDescription:"A workflow run referencing this relationship is queued.",iconShape:"clock",textColor:"var(--fg-muted)",bgColor:"var(--inset)",animated:!1},active:{label:"Active",ariaDescription:"A model call referencing this relationship is in progress.",iconShape:"filled-circle",textColor:"var(--accent)",bgColor:"var(--accent-dim)",borderColor:"var(--accent-line)",animated:!1},processing:{label:"Processing",ariaDescription:"A tool or command referencing this relationship is executing.",iconShape:"spinning-circle",textColor:"var(--accent)",bgColor:"var(--accent-dim)",borderColor:"var(--accent-line)",animated:!0},completed:{label:"Completed",ariaDescription:"The most recent run referencing this relationship completed successfully.",iconShape:"check",textColor:"var(--accent)",bgColor:"var(--accent-dim)",animated:!1},failed:{label:"Failed",ariaDescription:"The most recent run referencing this relationship failed.",iconShape:"triangle-exclamation",textColor:"var(--danger)",bgColor:"color-mix(in oklch, var(--danger) 12%, var(--card))",animated:!1},blocked:{label:"Blocked",ariaDescription:"The validator denied a recent proposal referencing this relationship; see the inspector for the reason.",iconShape:"filled-square",textColor:"var(--warn)",bgColor:"color-mix(in oklch, var(--warn) 12%, var(--card))",animated:!1},degraded:{label:"Degraded",ariaDescription:"The health check flagged at least one endpoint of this relationship as not currently live.",iconShape:"broken-line",textColor:"var(--warn)",bgColor:"color-mix(in oklch, var(--warn) 8%, var(--card))",animated:!1},"high-throughput":{label:"High throughput",ariaDescription:"More than fifty events referenced this relationship in the last sixty seconds.",iconShape:"stacked-lines",textColor:"var(--accent)",bgColor:"var(--accent-dim)",animated:!1}};function s1(e){let{shape:t,color:n,animated:l,highContrast:s}=e,i=["rb-edge-badge-icon",l?"rb-edge-badge-icon--processing":"",s?"rb-edge-badge-icon--high-contrast":""].filter(e=>e.length>0).join(" "),r=s?2:1.5,o={width:12,height:12,viewBox:"0 0 12 12","aria-hidden":!0,fill:"currentColor",className:i,style:{color:n}};switch(t){case"hollow-circle":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("circle",{cx:"6",cy:"6",r:"4.5",fill:"none",stroke:"currentColor",strokeWidth:r})});case"clock":return(0,a.jsxs)("svg",{...o,children:[(0,a.jsx)("circle",{cx:"6",cy:"6",r:"4.5",fill:"none",stroke:"currentColor",strokeWidth:r}),(0,a.jsx)("path",{d:"M6 3v3l2 1",stroke:"currentColor",strokeWidth:r,strokeLinecap:"round",fill:"none"})]});case"filled-circle":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("circle",{cx:"6",cy:"6",r:"5"})});case"spinning-circle":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("circle",{cx:"6",cy:"6",r:"4.5",fill:"none",stroke:"currentColor",strokeWidth:r,strokeDasharray:"8 4"})});case"check":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("path",{d:"M2 6l3 3 5-5",stroke:"currentColor",strokeWidth:s?2.2:1.8,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})});case"triangle-exclamation":return(0,a.jsxs)("svg",{...o,children:[(0,a.jsx)("path",{d:"M6 1 L11 10 L1 10 Z",fill:"currentColor"}),(0,a.jsx)("path",{d:"M6 5v2.5",stroke:"var(--card)",strokeWidth:r,strokeLinecap:"round",fill:"none"}),(0,a.jsx)("circle",{cx:"6",cy:"9",r:"0.7",fill:"var(--card)"})]});case"filled-square":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("rect",{x:"1.5",y:"1.5",width:"9",height:"9",rx:"1.5"})});case"broken-line":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("path",{d:"M1 6h2.5l1.5-2 2 4 1.5-2H11",stroke:"currentColor",strokeWidth:r,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})});case"stacked-lines":return(0,a.jsxs)("svg",{...o,children:[(0,a.jsx)("rect",{x:"2",y:"2.5",width:"8",height:"1.5",rx:"0.75"}),(0,a.jsx)("rect",{x:"2",y:"5.25",width:"8",height:"1.5",rx:"0.75"}),(0,a.jsx)("rect",{x:"2",y:"8",width:"8",height:"1.5",rx:"0.75"})]})}}function s2(e){let{state:t}=e,n={width:10,height:10,viewBox:"0 0 10 10","aria-hidden":!0,fill:"currentColor"};switch(t){case"draft":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("circle",{cx:"5",cy:"5",r:"4",fill:"none",stroke:"currentColor",strokeWidth:"1.5"})});case"active":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("circle",{cx:"5",cy:"5",r:"4.5"})});case"archived":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("rect",{x:"1",y:"1",width:"8",height:"8",rx:"1"})});case"superseded":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("path",{d:"M2 5h6M6 3l2 2-2 2",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})});case"revoked":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("path",{d:"M2 2l6 6M8 2L2 8",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",fill:"none"})});case"blocked":return(0,a.jsxs)("svg",{...n,children:[(0,a.jsx)("rect",{x:"1",y:"1",width:"8",height:"8",rx:"1"}),(0,a.jsx)("path",{d:"M5 3v3",stroke:"var(--card)",strokeWidth:"1.5",strokeLinecap:"round",fill:"none"}),(0,a.jsx)("circle",{cx:"5",cy:"7.5",r:"0.6",fill:"var(--card)"})]});case"stale":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("rect",{x:"1",y:"1",width:"8",height:"8",rx:"1",fill:"none",stroke:"currentColor",strokeWidth:"1.5"})})}}function s5(e){var t;let{type:n,lifecycle:s,activity:i,throughputCount:r,animateOverride:o=!0,highContrast:c,onClick:d,className:u=""}=e,[h,p]=(0,l.useState)(!1);(0,l.useEffect)(()=>{if(void 0!==c)return;let e=window.matchMedia("(prefers-contrast: more)"),t=e=>{p(e)};t(e.matches);let n=e=>{t(e.matches)};return e.addEventListener("change",n),()=>{e.removeEventListener("change",n)}},[c]);let m=null!=(t=s0[i])?t:s0.inactive,f=n0[n],g=null!=c?c:h,v="high-throughput"===i&&void 0!==r?"".concat(m.label," (").concat(String(r),")"):m.label,x="".concat(f.displayName," — ").concat(m.ariaDescription),y=m.animated&&o,b=g?{color:m.textColor,background:"var(--card)",border:"1px solid ".concat(m.textColor)}:{color:m.textColor,background:m.bgColor,border:void 0!==m.borderColor?"1px solid ".concat(m.borderColor):void 0};return(0,a.jsx)("span",{role:"status","aria-live":"polite","aria-atomic":"true",className:"rb-edge-badge ".concat(u).trim(),"data-activity-state":i,"data-high-contrast":g?"true":void 0,children:void 0!==d?(0,a.jsxs)("button",{type:"button",className:"rb-edge-badge-btn",style:b,"aria-label":x,onClick:d,children:[(0,a.jsx)("span",{"aria-hidden":"true",children:(0,a.jsx)(s1,{shape:m.iconShape,color:m.textColor,animated:y,highContrast:g})}),(0,a.jsx)("span",{className:"visually-hidden",children:m.ariaDescription}),(0,a.jsx)("span",{"aria-hidden":"true",className:"rb-edge-badge-label",children:v}),(0,a.jsx)("span",{className:"rb-edge-badge-type",children:f.displayName}),(0,a.jsx)(s2,{state:s})]}):(0,a.jsxs)("span",{className:"rb-edge-badge-static",style:b,"aria-label":x,children:[(0,a.jsx)("span",{"aria-hidden":"true",children:(0,a.jsx)(s1,{shape:m.iconShape,color:m.textColor,animated:y,highContrast:g})}),(0,a.jsx)("span",{className:"visually-hidden",children:m.ariaDescription}),(0,a.jsx)("span",{"aria-hidden":"true",className:"rb-edge-badge-label",children:v}),(0,a.jsx)("span",{className:"rb-edge-badge-type",children:f.displayName}),(0,a.jsx)(s2,{state:s})]})})}let s3="keiko.relationships.density",s4={minimal:5,standard:25,dense:512};function s6(){try{let e=window.localStorage.getItem(s3);if("minimal"===e||"standard"===e||"dense"===e)return e}catch(e){}return"minimal"}function s8(){return"undefined"!=typeof document&&null!==document.querySelector('[role="dialog"][aria-modal="true"]')}function s7(e,t){return void 0===e||0===e.length?[]:e.split(",").map(e=>e.trim()).filter(e=>t.includes(e))}function s9(e){return{types:s7(e.relType,nQ),lifecycles:s7(e.relLifecycle,n$),activities:s7(e.relActivity,["inactive","queued","active","processing","completed","failed","blocked","degraded","high-throughput"]),srcKinds:s7(e.relSrcKind,nY),tgtKinds:s7(e.relTgtKind,nY)}}let ie={"high-throughput":0,processing:1,active:2,blocked:3,failed:4,degraded:5,queued:6,completed:7,inactive:8};function it(e,t,n){var a;return null!=(a=n.get(e))?a:function(e){switch(e){case"blocked":return"blocked";case"stale":return"degraded";default:return"inactive"}}(t)}function ia(e){var t;let{filters:n,selectedId:s,onSelect:i,onFilterChange:r,activityMap:o=new Map,throughputMap:c=new Map,animateBadges:d=!0,highContrast:u=!1}=e,[h,p]=(0,l.useState)(()=>{let e=n.relDensity;return"minimal"===e||"standard"===e||"dense"===e?e:s6()}),[m,f]=(0,l.useState)(!1),[g,v]=(0,l.useState)([]),[x,y]=(0,l.useState)(!1),[b,j]=(0,l.useState)(null),[w,k]=(0,l.useState)(!1),[N,S]=(0,l.useState)(null),C=(0,l.useRef)(null),[R,I]=(0,l.useState)(null!=(t=n.relType)?t:""),E=(0,l.useRef)(null),M=(0,l.useCallback)(e=>{p(e),void 0===n.relDensity&&function(e){try{window.localStorage.setItem(s3,e)}catch(e){}}(e)},[n.relDensity]);(0,l.useEffect)(()=>{let e=n.relDensity;if("minimal"===e||"standard"===e||"dense"===e)return void p(e);p(s6())},[n.relDensity]),(0,l.useEffect)(()=>{var e;I(null!=(e=n.relType)?e:"")},[n.relType]);let T=(0,l.useCallback)(async()=>{j(null),y(!0);try{let e=s9(n),t=1===e.lifecycles.length?e.lifecycles[0]:"active",a=1===e.types.length?e.types[0]:void 0,l=1===e.srcKinds.length?e.srcKinds[0]:void 0,s=1===e.tgtKinds.length?e.tgtKinds[0]:void 0,i=await n8({lifecycle:t,type:a,sourceKind:l,targetKind:s,limit:s4[h]});v(i.entries),k(i.truncated),S(i.truncated?i.entries.length+1:i.entries.length)}catch(e){j(e instanceof n2?e.message:"Unable to reach the local backend. Check that `keiko serve` is running.")}finally{y(!1)}},[n,h]);(0,l.useEffect)(()=>{T()},[T]),(0,l.useEffect)(()=>{function e(e){if(s8())return;let t=document.activeElement;t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement||(("f"===e.key||"F"===e.key)&&(e.preventDefault(),f(e=>!e)),"Escape"===e.key&&f(!1))}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]),(0,l.useEffect)(()=>{function e(e){if(s8())return;let t=document.activeElement;if(!(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement)&&"/"===e.key){var n;e.preventDefault(),null==(n=C.current)||n.focus()}}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let q=(0,l.useCallback)(e=>{let t=e.target.value;I(t),null!==E.current&&clearTimeout(E.current),E.current=setTimeout(()=>{r({relType:t.length>0?t:void 0})},250)},[r]),P=(0,l.useMemo)(()=>{let e=s9(n);return(0===e.activities.length?g:g.filter(t=>e.activities.includes(it(t.id,t.lifecycle,o)))).slice(0,s4[h])},[o,h,n,g]),A=P.slice(0,25),z=P.slice(25),D=z.length,L=D>0?function(e,t){let n=new Map;for(let l of e){var a;let e=it(l.id,l.lifecycle,t);n.set(e,(null!=(a=n.get(e))?a:0)+1)}return Array.from(n.entries()).sort((e,t)=>{var n,a;return t[1]!==e[1]?t[1]-e[1]:(null!=(n=ie[e[0]])?n:Number.MAX_SAFE_INTEGER)-(null!=(a=ie[t[0]])?a:Number.MAX_SAFE_INTEGER)}).map(e=>{let[t,n]=e,a=1===n?"relationship":"relationships";return"high-throughput"===t?"".concat(n," high-throughput ").concat(a):"".concat(n," ").concat(t," ").concat(a)}).join(", ")}(z,o):"",F=w&&null!==N?"Showing first ".concat(String(P.length)," of ").concat(String(N)," relationships."):"Showing ".concat(String(P.length)," relationship").concat(1!==P.length?"s":"",".");return(0,a.jsxs)("div",{className:"tw-pad","data-testid":"relationship-list-panel","data-relationship-focus":m?"true":void 0,children:[(0,a.jsxs)("div",{role:"group","aria-label":"Relationship density",style:{display:"flex",gap:4,marginBottom:8},children:[["minimal","standard","dense"].map(e=>(0,a.jsx)("button",{type:"button",className:"arun-btn","aria-pressed":h===e,onClick:()=>M(e),style:{textTransform:"capitalize",minWidth:24,minHeight:24},children:e},e)),(0,a.jsx)("button",{type:"button",className:"arun-btn","aria-pressed":m,onClick:()=>f(e=>!e),title:"Toggle focus mode (F)","aria-label":"Focus mode: ".concat(m?"on":"off"),style:{minWidth:24,minHeight:24},children:"Focus"})]}),(0,a.jsxs)("div",{style:{marginBottom:8},children:[(0,a.jsx)("label",{htmlFor:"rel-type-filter",className:"rb-row-k",style:{display:"block",marginBottom:2},children:"Filter by type (press / to focus)"}),(0,a.jsx)("input",{id:"rel-type-filter",ref:C,type:"text",value:R,onChange:q,placeholder:"e.g. reads-context","aria-label":"Filter relationships by type",style:{width:"100%",background:"var(--inset)",border:"1px solid var(--border)",borderRadius:4,padding:"4px 8px",color:"var(--fg)",fontSize:12}})]}),(0,a.jsx)("div",{"aria-live":"polite","aria-atomic":"true",className:"visually-hidden",children:F}),w&&(0,a.jsx)("div",{className:"footer","aria-live":"polite",style:{fontSize:11,color:"var(--fg-muted)",marginBottom:6},children:F}),null!==b&&(0,a.jsxs)("div",{className:"lk-alert",role:"alert","aria-live":"assertive",children:[(0,a.jsx)("span",{children:b}),(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>void T(),children:"Retry"})]}),x&&(0,a.jsx)("div",{style:{color:"var(--fg-muted)",fontSize:12,padding:"8px 0"},"aria-label":"Loading relationships",children:"Loading…"}),!x&&null===b&&0===P.length&&(0,a.jsx)("div",{className:"insp-empty","data-testid":"list-empty",children:"No relationships found for the current filter."}),!x&&P.length>0&&(0,a.jsxs)("div",{role:"list","aria-label":"Relationships",style:{display:"flex",flexDirection:"column",gap:2},children:[A.map(e=>{let t=e.id===s,n=it(e.id,e.lifecycle,o),l=m&&t,r=m&&!t;return(0,a.jsx)("div",{role:"listitem",style:{opacity:r?.4:1},children:(0,a.jsxs)("button",{type:"button","aria-pressed":t,"aria-label":"".concat(e.type," relationship from ").concat(e.source.kind," to ").concat(e.target.kind,", lifecycle: ").concat(e.lifecycle),onClick:()=>i(e.id),onKeyDown:t=>{var n;return n=e.id,void(("Enter"===t.key||" "===t.key)&&(t.preventDefault(),i(n)))},"data-incident":l?"true":void 0,style:{display:"flex",alignItems:"center",gap:6,width:"100%",minHeight:32,padding:"4px 6px",background:t?"var(--accent-dim)":"transparent",border:"1px solid transparent",borderColor:t?"var(--accent-line)":"transparent",borderRadius:4,cursor:"pointer",textAlign:"left"},className:"focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent",children:[(0,a.jsx)(s5,{type:e.type,lifecycle:e.lifecycle,activity:n,throughputCount:c.get(e.id),animateOverride:d,highContrast:u}),(0,a.jsxs)("span",{style:{fontSize:12,color:"var(--fg)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[e.source.kind," → ",e.target.kind]}),(0,a.jsx)("span",{style:{fontSize:11,color:"var(--fg-faint)",whiteSpace:"nowrap"},children:e.lifecycle})]})},e.id)}),D>0&&(0,a.jsxs)("div",{role:"listitem","aria-live":"polite",style:{fontSize:12,color:"var(--fg-muted)",padding:"4px 6px"},"data-testid":"animation-cap-aggregate",children:["+",String(D)," more: ",L]})]})]})}function il(){return(0,a.jsx)("p",{role:"note",style:{margin:"4px 0 0",fontSize:11,color:"var(--fg-muted)",borderLeft:"2px solid var(--warn)",paddingLeft:8},children:"The walk hit a bound before the graph was fully traversed; more objects may be affected than shown."})}function is(e){let{title:t,help:n,report:l,onSelectRelationship:s}=e;if(null===l)return(0,a.jsxs)("section",{style:{marginBottom:12},children:[(0,a.jsx)("div",{className:"rb-section-label",role:"heading","aria-level":4,children:t}),(0,a.jsx)("p",{style:{fontSize:12,color:"var(--fg-muted)",margin:0},children:"Loading…"})]});let i=l.endpoints.slice(1),r=l.relationships,o=i.slice(0,50),c=r.slice(0,50);return(0,a.jsxs)("section",{style:{marginBottom:12},"aria-label":t,children:[(0,a.jsxs)("div",{className:"rb-section-label",role:"heading","aria-level":4,children:[t,(0,a.jsx)("span",{className:"rb-count","aria-hidden":"true",children:i.length})]}),(0,a.jsx)("p",{style:{margin:"0 0 6px",fontSize:11,color:"var(--fg-muted)"},children:n}),0===i.length?(0,a.jsx)("p",{style:{fontSize:12,color:"var(--fg-muted)",margin:0},children:"No further objects are affected in this direction."}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("ul",{style:{listStyle:"none",margin:0,padding:0},children:o.map(e=>(0,a.jsx)("li",{className:"rb-row",style:{fontSize:12},children:(0,a.jsx)("span",{className:"mono",children:"".concat(e.kind,": ").concat(e.id)})},"".concat(e.kind,":").concat(e.id)))}),i.length>o.length&&(0,a.jsxs)("p",{role:"note",style:{margin:"4px 0 0",fontSize:11,color:"var(--fg-muted)"},children:["Showing the first ",String(50)," of ",String(i.length)," ","objects."]}),r.length>0&&(0,a.jsxs)("details",{style:{marginTop:6},children:[(0,a.jsxs)("summary",{style:{fontSize:11,color:"var(--fg-muted)",cursor:"pointer"},children:[String(r.length)," relationship",1===r.length?"":"s"," on the path"]}),(0,a.jsx)("ul",{style:{listStyle:"none",margin:"4px 0 0",padding:0},children:c.map(e=>(0,a.jsx)("li",{style:{marginBottom:2},children:(0,a.jsxs)("button",{type:"button",className:"arun-btn ghost",onClick:()=>s(e.id),"aria-label":"Inspect ".concat(e.type," relationship from ").concat(e.source.kind," ").concat(e.source.id," to ").concat(e.target.kind," ").concat(e.target.id),style:{display:"flex",width:"100%",gap:6,alignItems:"center",textAlign:"left",fontSize:12},children:[(0,a.jsx)("span",{className:"mono",children:e.type}),(0,a.jsxs)("span",{style:{color:"var(--fg-muted)"},children:[e.source.id," → ",e.target.id]})]})},e.id))})]})]}),l.truncated&&(0,a.jsx)(il,{})]})}function ii(e){let{outgoing:t,incoming:n,onSelectRelationship:l}=e;return(0,a.jsxs)("div",{style:{marginTop:8,padding:"8px 10px",border:"1px solid var(--border)",borderRadius:8,background:"var(--inset)"},"aria-label":"Bounded impact analysis",children:[(0,a.jsx)(is,{title:"Downstream impact",help:"Objects this relationship's target leads to. Deleting or revoking here may affect them.",report:t,onSelectRelationship:l}),(0,a.jsx)(is,{title:"Upstream impact",help:"Objects that depend on this relationship's source.",report:n,onSelectRelationship:l})]})}let ir={draft:{bg:"var(--inset)",fg:"var(--fg-muted)"},active:{bg:"var(--accent-dim)",fg:"var(--accent)"},archived:{bg:"var(--inset)",fg:"var(--fg-dim)"},superseded:{bg:"var(--inset)",fg:"var(--fg-dim)"},revoked:{bg:"color-mix(in oklch, var(--danger) 14%, var(--card))",fg:"var(--danger)"},blocked:{bg:"color-mix(in oklch, var(--warn) 12%, var(--card))",fg:"var(--warn)"},stale:{bg:"var(--inset)",fg:"var(--fg-faint)"}},io={draft:"Proposed but not yet validated or awaiting an upstream gate.",active:"Validated and committed. Both endpoints are currently live.",archived:"Preserved for audit but no longer participates in queries by default.",superseded:"Replaced by a newer relationship of the same type.",revoked:"Rejected after proposal or retracted after acceptance. Terminal state.",blocked:"Cannot transition to active because the validator returned a denial reason.",stale:"At least one endpoint is tombstoned, retired, or unavailable."};function ic(e){let{lines:t=3}=e;return(0,a.jsx)("div",{className:"rb-rows","aria-hidden":"true",children:Array.from({length:t},(e,t)=>(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",style:{background:"var(--inset)",borderRadius:3,width:"40%",display:"block",height:12}}),(0,a.jsx)("span",{className:"rb-row-v",style:{background:"var(--inset)",borderRadius:3,width:"55%",display:"block",height:12}})]},t))})}function id(e){let{children:t,style:n}=e;return(0,a.jsx)("div",{className:"rb-section-label",role:"heading","aria-level":3,style:n,children:t})}function iu(e){let{rel:t}=e,n=n0[t.type],l="".concat(t.source.kind," ").concat(t.type," ").concat(t.target.kind);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"insp-top",children:[(0,a.jsx)("span",{className:"chip",style:{fontSize:11},children:t.type}),(0,a.jsx)("span",{className:"insp-title",children:l})]}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Semantics"}),(0,a.jsx)("span",{className:"rb-row-v",children:n.semantics})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Cardinality"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:n.cardinality})]})]})]})}function ih(e){let{label:t,kind:n,id:l}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(id,{children:[t," endpoint"]}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Kind"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:n})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Reference"}),(0,a.jsx)("span",{className:"rb-row-v mono","aria-label":"Reference id: ".concat(l),children:l})]})]})]})}function ip(e){var t;let{lifecycle:n}=e,l="lifecycle-desc-".concat(n),s=null!=(t=ir[n])?t:ir.draft;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(id,{children:"Lifecycle status"}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"State"}),(0,a.jsx)("span",{className:"rb-row-v",children:(0,a.jsx)("span",{className:"chip",style:{background:s.bg,color:s.fg},"aria-describedby":l,children:n})})]}),(0,a.jsx)("div",{className:"rb-row",children:(0,a.jsx)("span",{id:l,className:"rb-row-v",style:{color:"var(--fg-muted)",fontSize:12},children:io[n]})})]})]})}function im(e){let{type:t,lifecycle:n,activity:l,throughputCount:s,animateBadges:i,highContrast:r,transitions:o,densityMode:c}=e,d=o.slice(0,"minimal"===c?3:5);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(id,{children:"Activity"}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Current state"}),(0,a.jsx)("span",{className:"rb-row-v",children:(0,a.jsx)(s5,{type:t,lifecycle:n,activity:l,throughputCount:s,animateOverride:i,highContrast:r})})]}),d.length>0&&(0,a.jsxs)("div",{className:"rb-row",style:{flexDirection:"column",gap:4,alignItems:"flex-start"},children:[(0,a.jsx)("span",{className:"rb-row-k",style:{marginBottom:4},children:"Recent transitions"}),d.map((e,t)=>(0,a.jsxs)("div",{style:{fontSize:12,color:"var(--fg-muted)",display:"flex",gap:8},children:[(0,a.jsxs)("span",{className:"mono",children:[e.from," → ",e.to]}),(0,a.jsx)("time",{dateTime:new Date(e.occurredAt).toISOString(),style:{color:"var(--fg-faint)"},children:new Date(e.occurredAt).toLocaleString()})]},t))]})]})]})}function ig(){return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(id,{children:"Authority status"}),(0,a.jsx)("div",{className:"rb-rows",children:(0,a.jsx)("div",{className:"rb-row","data-testid":"authority-disclaimer",children:(0,a.jsx)("span",{className:"rb-row-v",style:{color:"var(--fg-muted)",fontStyle:"italic"},children:"Relationship: governance only. No model/tool/file/workflow authority granted."})})})]})}function iv(e){let{auditRows:t,loading:n,error:l,onRetry:s,onLoadMore:i,hasMore:r}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(id,{children:"Audit history"}),n&&(0,a.jsx)(ic,{lines:3}),null!==l&&(0,a.jsxs)("div",{className:"lk-alert",role:"alert","aria-live":"assertive",children:[(0,a.jsx)("span",{children:l}),(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:s,children:"Retry"})]}),!n&&null===l&&0===t.length&&(0,a.jsx)("div",{className:"rb-rows",children:(0,a.jsx)("div",{className:"rb-row",children:(0,a.jsx)("span",{className:"rb-row-v",style:{color:"var(--fg-muted)"},children:"No audit events for this relationship yet."})})}),!n&&t.length>0&&(0,a.jsxs)("div",{className:"rb-rows",children:[t.map((e,t)=>(0,a.jsxs)("div",{className:"rb-row",style:{flexDirection:"column",alignItems:"flex-start",gap:2},children:[(0,a.jsxs)("span",{className:"rb-row-k mono",style:{fontSize:11},children:[e.from," → ",e.to]}),(0,a.jsx)("time",{dateTime:new Date(e.occurredAt).toISOString(),style:{color:"var(--fg-faint)",fontSize:11},children:new Date(e.occurredAt).toLocaleString()})]},t)),r&&(0,a.jsx)("div",{className:"rb-row",children:(0,a.jsx)("button",{type:"button",className:"rb-row-v",style:{color:"var(--accent)",fontSize:12,background:"none",border:"none",padding:0,cursor:"pointer",minHeight:24,minWidth:24},onClick:i,"aria-label":"Load more audit events",children:"Load more"})})]})]})}function ix(e){let{rel:t}=e,n=function(e){let t=[];return"evidence-run"===e.source.kind&&t.push(e.source.id),"evidence-run"===e.target.kind&&t.push(e.target.id),t}(t);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(id,{children:"Evidence references"}),0===n.length?(0,a.jsx)("p",{style:{fontSize:12,color:"var(--fg-muted)",margin:"0 0 4px"},"data-testid":"evidence-empty",children:"No evidence references for this relationship."}):(0,a.jsx)("div",{className:"rb-rows",children:n.map(e=>(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Evidence run"}),(0,a.jsx)("span",{className:"rb-row-v mono","aria-label":"Evidence run reference ".concat(e),title:e,children:e})]},e))})]})}function iy(e){let{relationshipId:t,forwardCount:n,reverseCount:l,outgoing:s,incoming:i,expanded:r,onToggle:o,onSelectRelationship:c}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(id,{children:"Impact summary"}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Forward dependencies"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:null===n?"—":String(n)})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Reverse dependencies"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:null===l?"—":String(l)})]}),(0,a.jsx)("div",{className:"rb-row",children:(0,a.jsx)("button",{type:"button",className:"arun-btn",onClick:o,"aria-expanded":r,"aria-controls":"rb-impact-detail","aria-label":r?"Hide impact for relationship ".concat(t):"View impact for relationship ".concat(t),"data-testid":"view-impact-btn",children:r?"Hide impact":"View impact"})})]}),r&&(0,a.jsx)("div",{id:"rb-impact-detail",children:(0,a.jsx)(ii,{outgoing:s,incoming:i,onSelectRelationship:c})})]})}function ib(e){let{codes:t,messages:n,deniedAt:l}=e;return 0===t.length?null:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(id,{children:"Denial reason"}),(0,a.jsxs)("div",{className:"lk-alert",role:"status","aria-live":"polite","data-testid":"denial-section",children:[t.map((e,l)=>{var s;return(0,a.jsxs)("div",{style:{marginBottom:8*(l<t.length-1)},children:[(0,a.jsx)("div",{style:{fontFamily:"var(--mono)",fontSize:11,color:"var(--fg-muted)",marginBottom:2},children:e}),(0,a.jsx)("div",{style:{fontSize:13,color:"var(--fg)"},children:null!=(s=n[l])?s:e})]},e)}),void 0!==l&&(0,a.jsxs)("div",{style:{fontSize:11,color:"var(--fg-faint)",marginTop:6},children:["Denied at ",(0,a.jsx)("time",{dateTime:l,children:l})]})]})]})}function ij(e){return null==e||0===e.length?null:{codes:e.map(e=>e.code),messages:e.map(e=>e.message)}}function iw(e){let{rel:t,onReconnect:n,onArchive:l,onRevoke:s,onViewImpact:i,onViewEvidence:r,mutating:o}=e,c=t.lifecycle,d="blocked"===c,u="active"===c,h="active"===c||"blocked"===c||"archived"===c,p="active"===c;return(0,a.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginTop:8},children:[(0,a.jsx)("button",{type:"button",className:"arun-btn".concat(d?" primary":""),"aria-disabled":!d||o,"aria-label":"Reconnect — only available for blocked relationships",title:d?"Reconnect (R)":"Only blocked relationships can be reconnected.",disabled:!d||o,onClick:d?n:void 0,children:"Reconnect"}),(0,a.jsx)("button",{type:"button",className:"arun-btn","aria-disabled":!u||o,"aria-label":"Archive — only available for active relationships",title:u?"Archive (A)":"Only active relationships can be archived.",disabled:!u||o,onClick:u?l:void 0,children:"Archive"}),(0,a.jsx)("button",{type:"button",className:"arun-btn","aria-disabled":!h||o,"aria-label":"Revoke relationship",title:h?"Revoke (Shift+Delete)":"Already revoked or superseded.",disabled:!h||o,onClick:h?s:void 0,style:{color:h?"var(--danger)":void 0},children:"Revoke"}),(0,a.jsx)("button",{type:"button",className:"arun-btn","aria-disabled":!p,"aria-label":"View impact analysis",title:p?"View Impact (I)":"Impact analysis is unavailable in this state.",disabled:!p,onClick:p?i:void 0,children:"View Impact"}),(0,a.jsx)("button",{type:"button",className:"arun-btn","aria-label":"View evidence references",title:"View Evidence (E)",onClick:r,children:"View Evidence"})]})}function ik(e){var t,n,s;let{relationshipId:i,densityMode:r="minimal",onClearFocus:o,onViewImpact:c,activityMap:d=new Map,throughputMap:u=new Map,animateBadges:h=!0,highContrast:p=!1}=e,[m,f]=(0,l.useState)(null),[g,v]=(0,l.useState)(null),[x,y]=(0,l.useState)(!1),[b,j]=(0,l.useState)(null),[w,k]=(0,l.useState)(!1),[N,S]=(0,l.useState)(null),[C,R]=(0,l.useState)(null),[I,E]=(0,l.useState)(null),[M,T]=(0,l.useState)(null),[q,P]=(0,l.useState)(!1),A=null===I?null:I.relationships.length,z=null===M?null:M.relationships.length,[D,L]=(0,l.useState)(!1),F=(0,l.useRef)(null),O=(0,l.useRef)(0),K=(0,l.useCallback)(async e=>{let t=++O.current;j(null),y(!0),R(null),E(null),T(null),P(!1);let n=setTimeout(()=>{O.current===t&&L(!0)},500);F.current=n;try{let[n,a]=await Promise.all([n7(e),an(e)]);if(O.current!==t)return;f(n),v(a);try{let[n,a]=await Promise.all([at(e,{direction:"outgoing",maxDepth:3,maxRelationships:512}),at(e,{direction:"incoming",maxDepth:3,maxRelationships:512})]);if(O.current!==t)return;E(n),T(a)}catch(e){}}catch(e){if(O.current!==t)return;j(e instanceof n2?e.message:"Unable to reach the local backend. Check that `keiko serve` is running.")}finally{F.current===n?(clearTimeout(n),F.current=null):clearTimeout(n),O.current===t&&(y(!1),L(!1))}},[]);(0,l.useEffect)(()=>{if(null===i){O.current+=1,null!==F.current&&(clearTimeout(F.current),F.current=null),f(null),v(null),j(null),R(null),L(!1),y(!1);return}return K(i),()=>{null!==F.current&&(clearTimeout(F.current),F.current=null)}},[i,K]);let B=(0,l.useCallback)(async e=>{if(null!==m){k(!0),S(null),R(null);try{let t=crypto.randomUUID(),{relationship:n}=await n9(m.id,{transition:{to:e}},String(m.etag),t);f(n),v(null),await K(m.id)}catch(e){S(e instanceof n2?e.message:"Mutation failed. Please retry."),R(e instanceof n2?ij(e.reasons):null)}finally{k(!1)}}},[m,K]),W=(0,l.useCallback)(()=>void B("draft"),[B]),U=(0,l.useCallback)(()=>void B("archived"),[B]),_=(0,l.useCallback)(async()=>{if(null!==m&&window.confirm('Revoke relationship "'.concat(m.type,'"? This cannot be undone.'))){k(!0),S(null),R(null);try{let e=crypto.randomUUID(),t=await ae(m.id,String(m.etag),e);f(t)}catch(e){S(e instanceof n2?e.message:"Revoke failed. Please retry."),R(e instanceof n2?ij(e.reasons):null)}finally{k(!1)}}},[m]),H=(0,l.useCallback)(()=>{P(e=>!e)},[]),J=(0,l.useCallback)(e=>{null==c||c(e)},[c]),V=(0,l.useCallback)(()=>{null!==m&&(window.location.href="/evidence?relId=".concat(encodeURIComponent(m.id)))},[m]);if(null===i)return null;let G=ij(null==g?void 0:g.decision.reasons),X=null!=G?G:C,Y=null!==X&&((null==m?void 0:m.lifecycle)==="blocked"||(null==m?void 0:m.lifecycle)==="revoked"||null!==C),Z=null!==m?null!=(t=d.get(m.id))?t:function(e){switch(e){case"blocked":return"blocked";case"stale":return"degraded";default:return"inactive"}}(m.lifecycle):"inactive",Q=null!==m?u.get(m.id):void 0;return(0,a.jsxs)("div",{className:"tw-pad","aria-busy":x,"data-testid":"relationship-inspector-panel",children:[null!==b&&(0,a.jsxs)("div",{className:"lk-alert",role:"alert","aria-live":"assertive",children:[(0,a.jsx)("span",{children:b}),(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>void K(i),children:"Retry"})]}),null!==N&&(0,a.jsxs)("div",{className:"lk-alert",role:"alert","aria-live":"assertive",children:[(0,a.jsx)("span",{children:N}),(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>S(null),children:"Dismiss"})]}),x&&D&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(id,{style:{marginTop:0},children:"Relationship"}),(0,a.jsx)(ic,{lines:4}),(0,a.jsx)(ic,{lines:3})]}),!x&&null===b&&null===m&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(id,{style:{marginTop:0},children:"Relationship"}),(0,a.jsx)("div",{className:"insp-empty","data-testid":"inspector-not-found",children:"This relationship is no longer available."}),(0,a.jsx)("div",{style:{fontSize:12,color:"var(--fg-muted)",marginTop:4},children:"It may have been deleted, retired by retention, or it never existed in this workspace."}),void 0!==o&&(0,a.jsx)("button",{type:"button",className:"arun-btn",style:{marginTop:8},onClick:o,children:"Clear focus"})]}),!x&&null!==m&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(id,{style:{marginTop:0},children:"Relationship"}),(0,a.jsx)(iu,{rel:m}),(0,a.jsx)(ih,{label:"Source",kind:m.source.kind,id:m.source.id}),(0,a.jsx)(ih,{label:"Target",kind:m.target.kind,id:m.target.id}),(0,a.jsx)(ip,{lifecycle:m.lifecycle}),(0,a.jsx)(im,{type:m.type,lifecycle:m.lifecycle,activity:Z,throughputCount:Q,animateBadges:h,highContrast:p,transitions:null!=(n=null==g?void 0:g.lifecycle)?n:[],densityMode:r}),(0,a.jsx)(ig,{}),(0,a.jsx)(iv,{auditRows:null!=(s=null==g?void 0:g.lifecycle)?s:[],loading:!1,error:null,onRetry:()=>void K(i),onLoadMore:()=>{},hasMore:!1}),(0,a.jsx)(ix,{rel:m}),(0,a.jsx)(iy,{relationshipId:m.id,forwardCount:A,reverseCount:z,outgoing:I,incoming:M,expanded:q,onToggle:H,onSelectRelationship:J}),Y&&null!==X&&(0,a.jsx)(ib,{codes:X.codes,messages:X.messages}),(0,a.jsx)(iw,{rel:m,onReconnect:W,onArchive:U,onRevoke:()=>void _(),onViewImpact:H,onViewEvidence:V,mutating:w})]})]})}let iN=new Set(["kind","id","state","timestamp","count"]);function iS(e){return"".concat(e.kind,": ").concat(e.id)}function iC(e){let{category:t}=e;return(0,a.jsxs)("p",{role:"note",style:{margin:"4px 0 0",fontSize:11,color:"var(--fg-muted)",borderLeft:"2px solid var(--warn)",paddingLeft:8},children:["More ",t," exist than the bounded query returned. Resolve the listed items, then re-run the health check."]})}function iR(e){let{category:t,onSelectRelationship:n}=e;if(0===t.items.length)return null;let l=t.items.slice(0,50),s=t.items.length-l.length;return(0,a.jsxs)("section",{"aria-label":"".concat(t.label," (").concat(String(t.items.length),")"),style:{marginBottom:14},children:[(0,a.jsxs)("div",{className:"rb-section-label",role:"heading","aria-level":3,children:[t.label,(0,a.jsx)("span",{className:"rb-count","aria-hidden":"true",children:t.items.length})]}),(0,a.jsx)("p",{style:{margin:"0 0 6px",fontSize:11,color:"var(--fg-muted)"},children:t.help}),(0,a.jsx)("ul",{style:{listStyle:"none",margin:0,padding:0},children:l.map(e=>(0,a.jsx)("li",{style:{marginBottom:2},children:(0,a.jsxs)("button",{type:"button",className:"arun-btn ghost",onClick:()=>n(e.id),"aria-label":"Inspect ".concat(e.type," relationship from ").concat(iS(e.source)," to ").concat(iS(e.target),", lifecycle ").concat(e.lifecycle),style:{display:"flex",width:"100%",gap:6,alignItems:"center",textAlign:"left",fontSize:12},children:[(0,a.jsx)("span",{className:"mono",style:{color:"var(--fg)"},children:e.type}),(0,a.jsxs)("span",{style:{color:"var(--fg-muted)"},children:[iS(e.source)," → ",iS(e.target)]}),(0,a.jsx)("span",{className:"mono",style:{marginLeft:"auto",color:"var(--fg-muted)"},children:e.lifecycle})]})},e.id))}),s>0&&(0,a.jsxs)("p",{role:"note",style:{margin:"4px 0 0",fontSize:11,color:"var(--fg-muted)"},children:["Showing the first ",String(50)," of ",String(t.items.length),"."]}),t.truncated&&(0,a.jsx)(iC,{category:t.label.toLowerCase()})]})}function iI(e){let{findings:t}=e;if(0===t.orphanedEndpoints.length)return null;let n=t.orphanedEndpoints.slice(0,50);return(0,a.jsxs)("section",{"aria-label":"Orphaned endpoints (".concat(String(t.orphanedEndpoints.length),")"),style:{marginBottom:14},children:[(0,a.jsxs)("div",{className:"rb-section-label",role:"heading","aria-level":3,children:["Orphaned endpoints",(0,a.jsx)("span",{className:"rb-count","aria-hidden":"true",children:t.orphanedEndpoints.length})]}),(0,a.jsx)("p",{style:{margin:"0 0 6px",fontSize:11,color:"var(--fg-muted)"},children:"Endpoints that participate in no live relationship."}),(0,a.jsx)("ul",{style:{listStyle:"none",margin:0,padding:0},children:n.map(e=>(0,a.jsx)("li",{className:"rb-row",style:{fontSize:12},children:(0,a.jsx)("span",{className:"mono",children:iS(e)})},"".concat(e.kind,":").concat(e.id)))}),t.orphanedEndpointsTruncated&&(0,a.jsx)(iC,{category:"orphaned endpoints"})]})}function iE(e){var t,n;let{onSelectRelationship:s}=e,[i,r]=(0,l.useState)(null),[o,c]=(0,l.useState)(!0),[d,u]=(0,l.useState)(null),h=(0,l.useCallback)(async()=>{c(!0),u(null);try{let e=await aa();r(e)}catch(e){u(e instanceof n2?e.message:"Could not load the graph health check.")}finally{c(!1)}},[]);return(0,l.useEffect)(()=>{h()},[h]),(0,a.jsxs)("div",{style:{padding:12,height:"100%",overflowY:"auto"},"aria-busy":o,children:[(0,a.jsxs)("header",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:10},children:[(0,a.jsx)("h2",{style:{margin:0,fontSize:13,fontWeight:600,color:"var(--fg)",flexGrow:1},children:"Graph health"}),(0,a.jsx)("button",{type:"button",className:"arun-btn",onClick:()=>void h(),"aria-label":"Re-run the graph health check",style:{minHeight:24},children:"Refresh"})]}),o&&(0,a.jsx)("p",{style:{fontSize:12,color:"var(--fg-muted)"},"aria-live":"polite",children:"Running health check…"}),null!==d&&(0,a.jsxs)("div",{className:"lk-alert",role:"alert",children:[d,(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>void h(),children:"Retry"})]}),!o&&null===d&&null!==i&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("p",{style:{fontSize:11,color:"var(--fg-faint)",margin:"0 0 10px"},children:["Checked at"," ",(0,a.jsx)("time",{dateTime:new Date(i.checkedAt).toISOString(),children:new Date(i.checkedAt).toLocaleString()}),"."]}),(0,a.jsx)("div",{className:"rb-rows",style:{marginBottom:14},children:n$.filter(e=>{var t;return(null!=(t=i.totals[e])?t:0)>0}).map(e=>{var t;return(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:e}),(0,a.jsx)("span",{className:"rb-row-v mono",children:String(null!=(t=i.totals[e])?t:0)})]},e)})}),0===(t=i.findings).orphanedEndpoints.length+t.staleRelationships.length+t.blockedRelationships.length+t.failedRelationships.length+t.invalidReferences.length+t.cycleParticipants.length?(0,a.jsxs)("div",{className:"lk-empty",children:[(0,a.jsx)("p",{className:"lk-empty-title",children:"Healthy"}),(0,a.jsx)("p",{className:"lk-empty-body",children:"No relationship-graph defects were found."})]}):(0,a.jsxs)(a.Fragment,{children:[[{key:"invalid",label:"Invalid references",help:"An endpoint no longer resolves to a live workspace object.",items:(n=i.findings).invalidReferences,truncated:n.invalidReferencesTruncated},{key:"blocked",label:"Blocked",help:"A policy or endpoint state is blocking this relationship.",items:n.blockedRelationships,truncated:n.blockedRelationshipsTruncated},{key:"failed",label:"Failed (revoked)",help:"The relationship reached the revoked terminal state.",items:n.failedRelationships,truncated:n.failedRelationshipsTruncated},{key:"cycle",label:"Cycle participants",help:"These relationships take part in a dependency cycle.",items:n.cycleParticipants,truncated:n.cycleScanTruncated},{key:"stale",label:"Stale",help:"A health check flagged at least one endpoint as not currently live.",items:n.staleRelationships,truncated:n.staleRelationshipsTruncated}].map(e=>(0,a.jsx)(iR,{category:e,onSelectRelationship:s},e.key)),(0,a.jsx)(iI,{findings:i.findings})]})]})]})}let iM={draft:["draft","active","archived","superseded","revoked","blocked","stale"],active:["active","archived","superseded","revoked","stale"],archived:["archived","superseded","revoked","stale"],superseded:["superseded","stale"],revoked:["revoked"],blocked:["blocked","draft","active","archived","revoked","stale"],stale:["stale","active","archived","superseded","revoked"]};function iT(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function iq(e){return"string"==typeof e&&e.length>0}function iP(e,t,n){return void 0===n?{code:e,message:t}:{code:e,field:n,message:t}}function iA(e,t,n){return iT(e)?iq(e.kind)?iq(e.id)?!!iq(e.workspaceId)||(n.push(iP("denied/schema-version-unsupported","".concat(t,".workspaceId must be a non-empty string"),"".concat(t,".workspaceId"))),!1):(n.push(iP("denied/schema-version-unsupported","".concat(t,".id must be a non-empty string"),"".concat(t,".id"))),!1):(n.push(iP("denied/schema-version-unsupported","".concat(t,".kind must be a non-empty string"),"".concat(t,".kind"))),!1):(n.push(iP("denied/schema-version-unsupported","".concat(t," must be an object"),t)),!1)}function iz(e,t,n){iq(e[t])||n.push(iP("denied/schema-version-unsupported","".concat(t," must be a non-empty string"),t))}function iD(e,t){let n=e.kind;return nY.includes(n)?null:iP("denied/schema-version-unsupported","".concat(t,".kind is not a known object kind"),"".concat(t,".kind"))}function iL(e,t,n){return"missing"===t?void n.push(iP("source"===e?"denied/non-existent-source":"denied/non-existent-target","".concat(e," endpoint does not exist"),e)):"tombstoned"===t?void n.push(iP("denied/endpoint-tombstoned","".concat(e," endpoint has been tombstoned"),e)):"retired"===t?void n.push(iP("denied/endpoint-retired","".concat(e," endpoint has been retired"),e)):void("unavailable"===t&&n.push(iP("denied/endpoint-unavailable","".concat(e," endpoint is unavailable"),e)))}function iF(e,t){let n=e.kind;return nZ.includes(n)?null:iP("denied/object-kind-not-yet-supported","".concat(t,'.kind "').concat(n,'" is reserved for a future release'),"".concat(t,".kind"))}function iO(){return{type:"reads-context",sourceKind:"workflow-run",sourceId:"",targetKind:"memory",targetId:"",summary:""}}let iK=new Set(["denied/path-not-contained","denied/cross-workspace","denied/payload-content-not-permitted"]);function iB(e){return(null==e?void 0:e.codes.some(e=>iK.has(e)))===!0}function iW(e){let{onClose:t}=e,[n,s]=(0,l.useState)(iO),[i,r]=(0,l.useState)([]),[o,c]=(0,l.useState)(null),[d,u]=(0,l.useState)(!1),[h,p]=(0,l.useState)(!1),m=(0,l.useRef)(null),f=(0,l.useRef)(null),g="rel-create-dialog-title",v="rel-create-dialog-desc";(0,l.useEffect)(()=>{var e;null==(e=f.current)||e.focus()},[]);let x=(0,l.useCallback)(e=>{let t=m.current;if(null===t)return;let n=Array.from(t.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter(e=>!e.hasAttribute("disabled")),a=n[0],l=n[n.length-1];"Tab"===e.key&&(e.shiftKey?document.activeElement===a&&(e.preventDefault(),null==l||l.focus()):document.activeElement===l&&(e.preventDefault(),null==a||a.focus()))},[]),y=(0,l.useCallback)(e=>{"Escape"===e.key&&t(null)},[t]);(0,l.useEffect)(()=>(window.addEventListener("keydown",x),window.addEventListener("keydown",y),()=>{window.removeEventListener("keydown",x),window.removeEventListener("keydown",y)}),[x,y]),(0,l.useEffect)(()=>{if(0===n.sourceId.length||0===n.targetId.length)return void r([]);let e=function(e,t){let n=function(e){var t;if(!iT(e))return{errors:[iP("denied/schema-version-unsupported","relationship must be an object")]};let n=[];iz(e,"id",n),iz(e,"workspaceId",n),iz(e,"createdAt",n),iz(e,"updatedAt",n),(!("number"==typeof(t=e.etag)&&Number.isInteger(t)&&Number.isFinite(t))||e.etag<0)&&n.push(iP("denied/schema-version-unsupported","etag must be a non-negative finite integer","etag"));let a=iA(e.source,"source",n),l=iA(e.target,"target",n);return!(n.length>0)&&a&&l?{errors:[],value:{record:e,source:e.source,target:e.target}}:{errors:n}}(e);if(!n.value)return{ok:!1,errors:n.errors};let{record:a,source:l,target:s}=n.value,i=function(e,t,n){let a="1"!==e.schemaVersion?iP("denied/schema-version-unsupported",'schemaVersion must be the literal "'.concat("1",'"'),"schemaVersion"):null;if(a)return[a];let l=function(e){let t=e.type;return iq(t)?nQ.includes(t)?null:iP("denied/schema-version-unsupported","type is not a known relationship type","type"):iP("denied/schema-version-unsupported","type must be a non-empty string","type")}(e);if(l)return[l];let s=iD(t,"source"),i=iD(n,"target");if(null!==s||null!==i){let e=[];return null!==s&&e.push(s),null!==i&&e.push(i),e}let r=function(e){let t=e.lifecycleState;return iq(t)?n$.includes(t)?null:iP("denied/schema-version-unsupported","lifecycleState is not a known lifecycle state","lifecycleState"):iP("denied/schema-version-unsupported","lifecycleState must be a non-empty string","lifecycleState")}(e);return r?[r]:null}(a,l,s);if(i)return{ok:!1,errors:i};let r=function(e){if(!(null==e?void 0:e.endpointResolver))return null;let t=[];return"missing"===e.endpointResolver.source&&iL("source",e.endpointResolver.source,t),"missing"===e.endpointResolver.target&&iL("target",e.endpointResolver.target,t),t}(void 0);if(null!==r&&r.length>0)return{ok:!1,errors:r};let o=function(e,t,n,a){var l,s,i;let r=[],o=e.type,c=e.lifecycleState,d=iF(t,"source");d&&r.push(d);let u=iF(n,"target");u&&r.push(u),null===d&&null===u&&function(e,t,n,a){let l=function(e,t,n){let a=n0[e];return a.validSourceKinds.includes(t)?a.validTargetKinds.includes(n)?null:"denied/target-kind-not-allowed":"denied/source-kind-not-allowed"}(e,t.kind,n.kind);"denied/source-kind-not-allowed"===l?a.push(iP("denied/source-kind-not-allowed",'source.kind "'.concat(t.kind,'" is not permitted for type "').concat(e,'"'),"source.kind")):"denied/target-kind-not-allowed"===l&&a.push(iP("denied/target-kind-not-allowed",'target.kind "'.concat(n.kind,'" is not permitted for type "').concat(e,'"'),"target.kind"))}(o,t,n,r);let h=function(e,t){let n=null==t?void 0:t.cardinalityCounts;return n?"produces-evidence"===e&&"number"==typeof n.producesEvidenceForSource&&n.producesEvidenceForSource>=1?iP("denied/cardinality-exceeded","produces-evidence already exists for this source workflow-run"):"starts-workflow"===e&&"number"==typeof n.startsWorkflowForTarget&&n.startsWorkflowForTarget>=1?iP("denied/cardinality-exceeded","starts-workflow already exists for this target workflow-run"):null:null}(o,a);h&&r.push(h),function(e,t,n,a,l){let s=t.kind===n.kind&&t.id===n.id?iP("denied/cycle-forbidden","source and target refer to the same endpoint"):null;s&&l.push(s);let i="depends-on"===e&&(null==a?void 0:a.dependsOnReverseEdgeExists)===!0?iP("denied/cycle-forbidden","depends-on reverse edge already exists for this endpoint pair"):null;i&&l.push(i)}(o,t,n,a,r);let p=(l=e.workspaceId,t.workspaceId!==l||n.workspaceId!==l?iP("denied/cross-workspace","source and target must be in the relationship's workspace"):null);p&&r.push(p);let m=function(e,t){let n=null==t?void 0:t.previousLifecycleState;return void 0===n||iM[n].includes(e)?null:iP("denied/lifecycle-illegal-transition","transition from ".concat(n," to ").concat(e," is not permitted"),"lifecycleState")}(c,a);for(let t of(m&&r.push(m),s=a,i=r,(null==s?void 0:s.endpointResolver)&&("missing"!==s.endpointResolver.source&&iL("source",s.endpointResolver.source,i),"missing"!==s.endpointResolver.target&&iL("target",s.endpointResolver.target,i)),function(e){let t=[];if(void 0===e.metadata||null===e.metadata)return t;if(!iT(e.metadata))return t.push(iP("denied/payload-content-not-permitted","metadata must be an object when set","metadata")),t;for(let n of Object.keys(e.metadata)){let e=n.toLowerCase().replace(/[^a-z0-9]/g,"");for(let a of n1)if(e.includes(a)){t.push(iP("denied/payload-content-not-permitted","metadata may not carry endpoint content","metadata.".concat(n)));break}}return t}(e)))r.push(t);return r}(a,l,s,void 0);return o.length>0?{ok:!1,errors:o}:{ok:!0,value:a}}({id:"candidate",schemaVersion:"1",workspaceId:"preview",source:{kind:n.sourceKind,id:n.sourceId,workspaceId:"preview"},target:{kind:n.targetKind,id:n.targetId,workspaceId:"preview"},type:n.type,lifecycleState:"active",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),etag:0});e.ok?r([]):r(e.errors.map(e=>e.message))},[n]);let b=(0,l.useRef)(null),j=(0,l.useRef)(0);(0,l.useEffect)(()=>{j.current+=1;let e=j.current;return(null!==b.current&&clearTimeout(b.current),0===n.sourceId.length||0===n.targetId.length||i.length>0)?void p(!1):(b.current=setTimeout(async()=>{p(!0);try{if(await n4({type:n.type,source:{kind:n.sourceKind,id:n.sourceId},target:{kind:n.targetKind,id:n.targetId},summary:n.summary.length>0?n.summary:void 0}),e!==j.current)return;c(e=>(null==e?void 0:e.source)==="submit"||iB(e)?e:null)}catch(t){if(e!==j.current)return;t instanceof n2&&t.reasons.length>0?c({source:"preview",codes:t.reasons.map(e=>e.code),messages:t.reasons.map(e=>e.message)}):c(null)}finally{e===j.current&&p(!1)}},250),()=>{null!==b.current&&clearTimeout(b.current)})},[n,i]);let w=(0,l.useCallback)(async()=>{if(!d){u(!0),c(null);try{let e=crypto.randomUUID(),{relationship:a}=await n6({type:n.type,source:{kind:n.sourceKind,id:n.sourceId},target:{kind:n.targetKind,id:n.targetId},summary:n.summary.length>0?n.summary:void 0},e);t(a)}catch(e){e instanceof n2?e.reasons.length>0?c({source:"submit",codes:e.reasons.map(e=>e.code),messages:e.reasons.map(e=>e.message)}):c({source:"submit",codes:[e.code],messages:[e.message]}):c({source:"submit",codes:["relationship/network-error"],messages:["Unable to reach the local backend. Check that `keiko serve` is running."]})}finally{u(!1)}}},[n,t,d]),k=(0,l.useCallback)(e=>{"Enter"===e.key&&(e.ctrlKey||e.metaKey)&&w()},[w]),N=n0[n.type],S=n.sourceId.trim().length>0&&n.targetId.trim().length>0&&0===i.length&&null===o&&!d,C=iB(o);return(0,a.jsx)("div",{className:"cmdk-overlay",onPointerDown:()=>t(null),"data-testid":"rel-create-overlay",children:(0,a.jsxs)("div",{ref:m,role:"dialog","aria-modal":"true","aria-labelledby":g,"aria-describedby":v,className:"cmdk",style:{maxWidth:480,width:"100%"},onPointerDown:e=>e.stopPropagation(),onKeyDown:k,"data-testid":"rel-create-dialog",children:[(0,a.jsxs)("div",{className:"cmdk-input",style:{borderBottom:"1px solid var(--border)"},children:[(0,a.jsx)("span",{id:g,style:{fontWeight:600,fontSize:14,color:"var(--fg)"},children:"Create relationship"}),(0,a.jsx)("span",{id:v,className:"visually-hidden",children:"Create a new relationship between two workspace endpoints."}),(0,a.jsx)("button",{type:"button",className:"arun-btn",onClick:()=>t(null),"aria-label":"Close dialog",style:{marginLeft:"auto",minWidth:24,minHeight:24},children:"✕"})]}),(0,a.jsxs)("div",{style:{padding:"12px 16px",display:"flex",flexDirection:"column",gap:10},children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{htmlFor:"rel-type",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Type"}),(0,a.jsx)("select",{id:"rel-type",ref:f,value:n.type,onChange:e=>s(t=>({...t,type:e.target.value})),style:{width:"100%",background:"var(--inset)",border:"1px solid var(--border)",borderRadius:4,padding:"4px 8px",color:"var(--fg)",fontSize:13},"aria-label":"Relationship type",children:nQ.map(e=>(0,a.jsx)("option",{value:e,children:n0[e].displayName},e))}),(0,a.jsx)("div",{style:{fontSize:11,color:"var(--fg-muted)",marginTop:3},children:N.semantics})]}),(0,a.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,a.jsxs)("div",{style:{flex:"0 0 140px"},children:[(0,a.jsx)("label",{htmlFor:"rel-src-kind",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Source kind"}),(0,a.jsx)("select",{id:"rel-src-kind",value:n.sourceKind,onChange:e=>s(t=>({...t,sourceKind:e.target.value})),style:{width:"100%",background:"var(--inset)",border:"1px solid var(--border)",borderRadius:4,padding:"4px 8px",color:"var(--fg)",fontSize:12},"aria-label":"Source endpoint kind",children:nZ.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]}),(0,a.jsxs)("div",{style:{flex:1},children:[(0,a.jsx)("label",{htmlFor:"rel-src-id",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Source ID"}),(0,a.jsx)("input",{id:"rel-src-id",type:"text",value:n.sourceId,onChange:e=>s(t=>({...t,sourceId:e.target.value})),placeholder:"endpoint id",style:{width:"100%",background:"var(--inset)",border:"1px solid var(--border)",borderRadius:4,padding:"4px 8px",color:"var(--fg)",fontSize:12},"aria-label":"Source endpoint ID","aria-describedby":"rel-src-kind"})]})]}),(0,a.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,a.jsxs)("div",{style:{flex:"0 0 140px"},children:[(0,a.jsx)("label",{htmlFor:"rel-tgt-kind",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Target kind"}),(0,a.jsx)("select",{id:"rel-tgt-kind",value:n.targetKind,onChange:e=>s(t=>({...t,targetKind:e.target.value})),style:{width:"100%",background:"var(--inset)",border:"1px solid var(--border)",borderRadius:4,padding:"4px 8px",color:"var(--fg)",fontSize:12},"aria-label":"Target endpoint kind",children:nZ.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]}),(0,a.jsxs)("div",{style:{flex:1},children:[(0,a.jsx)("label",{htmlFor:"rel-tgt-id",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Target ID"}),(0,a.jsx)("input",{id:"rel-tgt-id",type:"text",value:n.targetId,onChange:e=>s(t=>({...t,targetId:e.target.value})),placeholder:"endpoint id",style:{width:"100%",background:"var(--inset)",border:"1px solid var(--border)",borderRadius:4,padding:"4px 8px",color:"var(--fg)",fontSize:12},"aria-label":"Target endpoint ID","aria-describedby":"rel-tgt-kind"})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{htmlFor:"rel-summary",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Summary (optional, ≤240 chars)"}),(0,a.jsx)("textarea",{id:"rel-summary",value:n.summary,maxLength:240,rows:2,onChange:e=>s(t=>({...t,summary:e.target.value})),style:{width:"100%",background:"var(--inset)",border:"1px solid var(--border)",borderRadius:4,padding:"4px 8px",color:"var(--fg)",fontSize:12,resize:"vertical"},"aria-label":"Relationship summary"})]}),i.length>0&&(0,a.jsx)("div",{className:"lk-alert",role:"status","aria-live":"polite","data-testid":"client-validation-hints",children:i.map((e,t)=>(0,a.jsx)("div",{style:{fontSize:12},children:e},t))}),h&&(0,a.jsx)("div",{style:{fontSize:12,color:"var(--fg-muted)"},"aria-live":"polite",children:"Validating…"}),null!==o&&(0,a.jsxs)("div",{className:"lk-alert",role:"alert","aria-live":"assertive","data-testid":"server-denial-banner",children:[o.codes.map((e,t)=>{var n;return(0,a.jsxs)("div",{style:{marginBottom:6*(t<o.codes.length-1)},children:[(0,a.jsx)("div",{style:{fontFamily:"var(--mono)",fontSize:11,color:"var(--fg-muted)",marginBottom:2},children:e}),(0,a.jsx)("div",{style:{fontSize:13,color:"var(--fg)"},children:null!=(n=o.messages[t])?n:e})]},e)}),C&&(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>c(null),style:{marginTop:6},children:"Dismiss"})]}),(0,a.jsxs)("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",marginTop:4},children:[(0,a.jsx)("button",{type:"button",className:"arun-btn",onClick:()=>t(null),style:{minWidth:24,minHeight:24},children:"Cancel"}),(0,a.jsx)("button",{type:"button",className:"arun-btn".concat(S?" primary":""),"aria-disabled":!S,disabled:!S,onClick:()=>void w(),"aria-busy":d,style:{minWidth:24,minHeight:24},children:d?"Creating…":"Create"})]})]})]})})}let iU={};function i_(){var e;let{activityMap:t,throughputMap:n,animate:s}=function(e){let t=(0,l.useRef)(new Map),n=(0,l.useRef)("undefined"==typeof document||"visible"===document.visibilityState),[a,s]=(0,l.useState)(new Map),[i,r]=(0,l.useState)(new Map),o=(0,l.useRef)(new Map),c=(0,l.useRef)(new Map),[d,u]=(0,l.useState)(()=>window.matchMedia("(prefers-reduced-motion: reduce)").matches),[h,p]=(0,l.useState)(!1),m=(0,l.useCallback)(()=>{p(!0)},[]),f=(0,l.useCallback)((e,n)=>{let a=new Map(o.current),l=new Set,i=new Set,d=!1;for(let[s,r]of a){var u;let o=e-(null!=(u=t.current.get(s))?u:0);o>=6e4&&"inactive"!==r&&(a.set(s,"inactive"),i.add(s),d=!0),!n&&o>=12e4&&(a.delete(s),l.add(s),i.add(s),d=!0)}if(a.size>512)for(let e of Array.from(a.keys()).sort((e,n)=>{var l,s;let i=a.get(e),r=a.get(n);return"inactive"===i&&"inactive"!==r?-1:"inactive"!==i&&"inactive"===r?1:(null!=(l=t.current.get(e))?l:0)-(null!=(s=t.current.get(n))?s:0)}).slice(0,a.size-512))a.delete(e),l.add(e),i.add(e),d=!0;if(d&&(o.current=a,s(a)),l.size>0)for(let e of l)t.current.delete(e);if(i.size>0){let e=!1,t=new Map(c.current);for(let n of i)t.delete(n)&&(e=!0);e&&(c.current=t,r(t))}},[]);(0,l.useEffect)(()=>{let e=window.matchMedia("(prefers-reduced-motion: reduce)"),t=e=>{u(e.matches)};return e.addEventListener("change",t),()=>{e.removeEventListener("change",t)}},[]);let g=(0,l.useCallback)(e=>{var a;if(!n.current)return;let l=Date.now();l-(null!=(a=t.current.get(e.id))?a:0)<2e3||(t.current.set(e.id,l),s(t=>{let n=new Map(t);return n.set(e.id,e.state),o.current=n,n}),"high-throughput"===e.state&&void 0!==e.count?r(t=>{let n=new Map(t);return n.set(e.id,e.count),c.current=n,n}):r(t=>{if(!t.has(e.id))return t;let n=new Map(t);return n.delete(e.id),c.current=n,n}))},[]);return(0,l.useEffect)(()=>{let e=setInterval(()=>{n.current&&f(Date.now(),!1)},15e3);return()=>{clearInterval(e)}},[f]),(0,l.useEffect)(()=>{if("undefined"==typeof document)return;let e=()=>{n.current="visible"===document.visibilityState,n.current&&f(Date.now(),!0)};return n.current="visible"===document.visibilityState,document.addEventListener("visibilitychange",e),()=>{document.removeEventListener("visibilitychange",e)}},[f]),(0,l.useEffect)(()=>{let e=!1,t=null,a=null;function l(e){let t;try{t=JSON.parse(e)}catch(e){return}let n=function(e){var t;if(null===e||"object"!=typeof e||function e(t){if(null===t||"object"!=typeof t)return!1;for(let n of Object.keys(t))if(function(e){let t=e.toLowerCase();return n1.some(e=>t.includes(e))}(n)||e(t[n]))return!0;return!1}(e))return null;let n={};for(let t of iN)Object.prototype.hasOwnProperty.call(e,t)&&(n[t]=e[t]);return"string"!=typeof n.id||0===n.id.length?null:"inactive"!==(t=n.state)&&"queued"!==t&&"active"!==t&&"processing"!==t&&"completed"!==t&&"failed"!==t&&"blocked"!==t&&"degraded"!==t&&"high-throughput"!==t||"number"!=typeof n.timestamp?null:{kind:"string"==typeof n.kind?n.kind:"relationship:activity",id:n.id,state:n.state,timestamp:n.timestamp,count:"number"==typeof n.count?n.count:void 0}}(t);null!==n&&g(n)}function s(){null!==a&&(clearTimeout(a),a=null)}function i(){null==t||t.close(),t=null}function r(){!e&&null===a&&n.current&&(a=setTimeout(()=>{a=null,o()},5e3))}function o(){if(!e&&n.current){try{t=new EventSource("/api/relationships/events")}catch(e){r();return}t.addEventListener("relationship:activity",e=>{l(e.data)}),t.onmessage=e=>{l(e.data)},t.onerror=()=>{e||(i(),r())}}}o();let c=()=>{if(n.current="visible"===document.visibilityState,!n.current){s(),i();return}f(Date.now(),!0),null===t&&o()};return document.addEventListener("visibilitychange",c),()=>{e=!0,document.removeEventListener("visibilitychange",c),s(),i()}},[void 0,g,f]),{activityMap:a,throughputMap:i,animate:!d&&!h,disable:m}}(),[i,r]=(0,l.useState)(!1),[o,c]=(0,l.useState)(iU),d=o.relFocus,u=null!=(e=o.relDensity)?e:"standard",[h,p]=(0,l.useState)(!1),m=(0,l.useRef)(null),f=(0,l.useRef)(!1),[g,v]=(0,l.useState)(!1),x=(0,l.useCallback)(e=>{c(t=>{let n={...t,...e},a={};for(let[e,t]of Object.entries(n))void 0!==t&&""!==t&&(a[e]=t);return a})},[]),y=(0,l.useCallback)(e=>{x({relFocus:e})},[x]),b=(0,l.useCallback)(()=>{x({relFocus:void 0})},[x]),j=(0,l.useCallback)(e=>{x({relFocus:e})},[x]),w=(0,l.useCallback)(e=>{f.current=!0,p(!1),null!==e&&x({relFocus:e.id})},[x]);return(0,l.useEffect)(()=>{var e;!h&&f.current&&(f.current=!1,null==(e=m.current)||e.focus())},[h]),(0,l.useEffect)(()=>{let e=window.matchMedia("(prefers-contrast: more)"),t=e=>{r(e)};t(e.matches);let n=e=>{t(e.matches)};return e.addEventListener("change",n),()=>e.removeEventListener("change",n)},[]),(0,l.useEffect)(()=>{let e=e=>{let t=e.target;if(!("INPUT"===t.tagName||"TEXTAREA"===t.tagName||"SELECT"===t.tagName||t.isContentEditable)&&"Escape"===e.key){if(h)return;b()}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[h,b]),(0,a.jsxs)(a.Fragment,{children:[h&&(0,a.jsx)(iW,{onClose:w}),(0,a.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden",background:"var(--bg)"},children:[(0,a.jsxs)("header",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 12px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,a.jsx)("button",{type:"button",className:"arun-btn",onClick:()=>v(e=>!e),"aria-pressed":g,"aria-label":"Toggle the graph health view",style:{flex:"0 0 auto",minHeight:24,marginRight:"auto"},children:g?"Hide health":"Graph health"}),(0,a.jsx)("button",{ref:m,type:"button",className:"arun-btn primary",onClick:()=>p(!0),"aria-label":"Create new relationship",style:{flex:"0 0 auto",minWidth:24,minHeight:24},children:"+ New relationship"})]}),(0,a.jsxs)("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[(0,a.jsx)("div",{style:{flex:"0 0 280px",borderRight:"1px solid var(--border)",overflowY:"auto"},children:(0,a.jsx)(ia,{filters:o,selectedId:d,onSelect:y,onFilterChange:x,activityMap:t,throughputMap:n,animateBadges:s,highContrast:i})}),(0,a.jsx)("div",{style:{flex:1,overflowY:"auto"},children:g?(0,a.jsx)(iE,{onSelectRelationship:e=>{v(!1),y(e)}}):(0,a.jsx)(ik,{relationshipId:null!=d?d:null,densityMode:u,onClearFocus:b,onViewImpact:j,activityMap:t,throughputMap:n,animateBadges:s,highContrast:i})})]})]})]})}function iH(e,t){let n=e[t];return"string"==typeof n?n:void 0}el("project",()=>(0,a.jsx)(ah,{})),el("search",()=>(0,a.jsx)(ag,{})),el("plugins",()=>(0,a.jsx)(ab,{})),el("automations",()=>(0,a.jsx)(aS,{})),el("mobile",()=>(0,a.jsx)(aC,{})),el("inspector",()=>(0,a.jsx)(aR,{})),el("notifications",()=>(0,a.jsx)(aE,{})),el("resources",()=>(0,a.jsx)(aM,{})),el("activity",()=>(0,a.jsx)(aP,{})),el("keiko",()=>(0,a.jsx)(lM,{})),el("settings",()=>(0,a.jsx)(lL,{})),el("quality",(e,t)=>{var n;return(0,a.jsx)(sj,{openRun:e=>{t.openWindow("qiRun",{runId:e,...function(e){var t;let n=st({connectedFilePath:null!=(t=e.linkedFilePath)?t:null,connectedRoot:e.linkedRoot,connectedRoots:e.linkedRoots,connectedCapsuleIds:e.linkedCapsuleIds,connectedCapsuleSetIds:e.linkedCapsuleSetIds,connectedFigmaSnapshotRunIds:e.linkedFigmaSnapshotRunIds});return n.length>0?{connectedSourcesJson:JSON.stringify(n)}:{}}(t)})},connectedRoot:t.linkedRoot,connectedFilePath:null!=(n=t.linkedFilePath)?n:null,connectedRoots:t.linkedRoots,connectedCapsuleIds:t.linkedCapsuleIds,connectedCapsuleSetIds:t.linkedCapsuleSetIds,connectedFigmaSnapshotRunIds:t.linkedFigmaSnapshotRunIds})}),el("qiRun",(e,t)=>{let n=iH(e,"runId");if(void 0===n||""===n)return(0,a.jsx)("div",{className:"lk-empty",children:(0,a.jsx)("p",{className:"lk-empty-body",children:"Open a run from the Quality Intelligence hub."})});let l=function(e){var t,n;let a=iH(e,"connectedSourcesJson");if(void 0!==a&&a.length>0)try{let e=JSON.parse(a);if(Array.isArray(e))return e}catch(e){}return st({connectedFilePath:null!=(t=iH(e,"connectedFilePath"))?t:null,connectedRoot:null!=(n=iH(e,"connectedRoot"))?n:null})}(e),s=iH(e,"connectedSourcesJson");return(0,a.jsx)(s$,{runId:n,connectedSources:l,onRegenerated:e=>{t.openWindow("qiRun",{runId:e.runId,...void 0!==s&&s.length>0?{connectedSourcesJson:s}:{}})}})}),el("relationships",()=>(0,a.jsx)(i_,{})),el("files",(e,t)=>{let n=iH(e,"root"),l=(e,n)=>{t.updateCfg({activeFilePath:null!=e?e:void 0,resolvedRoot:null!=n?n:void 0})},s=e=>{t.updateCfg({root:e,activeFilePath:void 0,resolvedRoot:void 0})};return void 0!==n?(0,a.jsx)(aH,{root:n,onActiveFileChange:l,onRootChange:s}):(0,a.jsx)(aH,{onActiveFileChange:l,onRootChange:s})}),el("editor",e=>{let t=iH(e,"file");return void 0!==t?(0,a.jsx)(aV,{file:t}):(0,a.jsx)(aV,{})}),el("browser",e=>{let t=iH(e,"url");return void 0!==t?(0,a.jsx)(a5,{url:t}):(0,a.jsx)(a5,{})}),el("terminal",e=>{let t=iH(e,"cwd"),n=iH(e,"projectPath"),l={};return void 0!==t&&(l.cwd=t),void 0!==n&&(l.projectPath=n),(0,a.jsx)(le,{...l})}),el("review",e=>{let t=iH(e,"runId");return void 0!==t&&""!==t?(0,a.jsx)(ld,{runId:t}):(0,a.jsx)(ld,{})}),el("agents",(e,t)=>(0,a.jsx)(lg,{cfg:function(e){let t={},n=iH(e,"workflow");void 0!==n&&(t.workflow=n);let a=iH(e,"model");void 0!==a&&(t.model=a);let l=iH(e,"runId");void 0!==l&&(t.runId=l);let s=iH(e,"fingerprint");void 0!==s&&(t.fingerprint=s);let i=iH(e,"workspaceRoot");void 0!==i&&(t.workspaceRoot=i);let r=iH(e,"inputJson");void 0!==r&&(t.inputJson=r);let o=function(e,t){let n=e[t];return"boolean"==typeof n?n:void 0}(e,"keikoMode");void 0!==o&&(t.keikoMode=o);let c=function(e){let t=e.access;return"ask"===t||"full"===t?t:void 0}(e);return void 0!==c&&(t.access=c),t}(e),linkedRoot:t.linkedRoot,linkedFilePath:t.linkedFilePath})),el("integ",e=>{let t=iH(e,"provider");return void 0!==t?(0,a.jsx)(lx,{provider:t}):(0,a.jsx)(lx,{})}),el("figma",(e,t)=>{let n=iH(e,"snapshotRunId");return(0,a.jsx)(lY,{snapshotRunId:n,updateCfg:e=>{t.updateCfg(e)}})}),el("connector",(e,t)=>{let n=iH(e,"selectedKind"),l=iH(e,"selectedId");return(0,a.jsx)(lU,{selectedKind:n,selectedId:l,onSelect:e=>{t.updateCfg(e)}})});let iJ={supported:{heading:"Install Keiko",body:"Keep Keiko in your app shelf for fast access.",install:"Install Keiko"},"ios-add-to-home":{heading:"Install Keiko",body:'On iOS Safari, tap Share, then "Add to Home Screen".',install:null}};function iV(){let{available:e,triggerInstall:t}=function(){let[e,t]=(0,l.useState)(!1),n=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let e=e=>{e.preventDefault(),function(e){if("function"!=typeof e.prompt)return!1;let t=e.userChoice;return"object"==typeof t&&null!==t&&"function"==typeof t.then}(e)&&(n.current=e,t(!0))},a=()=>{localStorage.setItem("keiko.pwa.installed","true"),n.current=null,t(!1)};return window.addEventListener("beforeinstallprompt",e,{passive:!1}),window.addEventListener("appinstalled",a),()=>{window.removeEventListener("beforeinstallprompt",e),window.removeEventListener("appinstalled",a)}},[]),{available:e,triggerInstall:(0,l.useCallback)(async()=>{let e=n.current;if(null===e)return;await e.prompt();let{outcome:a}=await e.userChoice;"accepted"===a&&localStorage.setItem("keiko.pwa.installed","true"),n.current=null,t(!1)},[])}}(),[n,s]=(0,l.useState)(!1),[i]=(0,l.useState)(()=>"undefined"!=typeof navigator?function(e){let t=e.toLowerCase();return t.includes("crios/")?"manual":t.includes("chrome/")&&!t.includes("mobile")||t.includes("edg/")||t.includes("chromium/")?"supported":t.includes("firefox/")?"manual":t.includes("safari/")&&(t.includes("iphone")||t.includes("ipad")||t.includes("ipod"))?"ios-add-to-home":(t.includes("safari/")&&t.includes("macintosh"),"manual")}(navigator.userAgent):"manual"),r=(0,l.useRef)(null),o=(0,l.useCallback)(()=>{localStorage.setItem("keiko.pwa.dismissed",new Date().toISOString()),s(!0)},[]),c=(0,l.useCallback)(async()=>{await t()},[t]);if((0,l.useEffect)(()=>{let e=e=>{"Escape"===e.key&&o()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[o]),n||window.matchMedia("(display-mode: standalone)").matches||"true"===localStorage.getItem("keiko.pwa.installed")||null!==localStorage.getItem("keiko.pwa.dismissed")||"supported"===i&&!e||"supported"!==i&&"ios-add-to-home"!==i)return null;let d=iJ[i];return(0,a.jsx)("aside",{className:"install-banner",role:"region","aria-label":"Install Keiko",children:(0,a.jsxs)("div",{className:"install-banner-body",children:[(0,a.jsxs)("div",{className:"install-banner-text",children:[(0,a.jsx)("span",{className:"install-banner-heading",children:d.heading}),(0,a.jsx)("span",{className:"install-banner-desc",children:d.body})]}),(0,a.jsxs)("div",{className:"install-banner-actions",children:[null!==d.install&&(0,a.jsx)("button",{ref:r,type:"button",className:"install-banner-btn-install",onClick:()=>void c(),children:d.install}),(0,a.jsx)("button",{type:"button",className:"install-banner-btn-dismiss","aria-label":"Dismiss install banner",onClick:o,children:(0,a.jsx)("span",{"aria-hidden":"true",children:"Not now"})})]})]})})}let iG=["chat","connector","figma","files","editor","browser","terminal","review","agents","integ"],iX=["project","search","plugins","automations","mobile","inspector","activity","notifications","resources"];function iY(){var e,t,n,s,r,o,c,d;let{theme:u,toggle:h}=function(){let[e,t]=(0,l.useState)(nM),[n,a]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{t(function(){try{let e=window.localStorage.getItem(nE);return"light"===e||"dark"===e?e:nM}catch(e){return nM}}()),a(!0)},[]),(0,l.useEffect)(()=>{if(n){"undefined"!=typeof document&&(document.documentElement.dataset.theme=e);try{window.localStorage.setItem(nE,e)}catch(e){}}},[e,n]),{theme:e,toggle:(0,l.useCallback)(()=>{t(e=>"light"===e?"dark":"light")},[])}}(),p=w(),m=function(){var e;let[t,n]=(0,l.useState)(tJ),[a,s]=(0,l.useState)(""),[i,r]=(0,l.useState)(!0),[o,c]=(0,l.useState)("idle"),d=tL(o),u=(0,l.useRef)("idle"),h=(0,l.useRef)(null),[p,m]=(0,l.useState)(),[f,g]=(0,l.useState)(),[v,x]=(0,l.useState)(),[y,b]=(0,l.useState)(!0),[j,w]=(0,l.useState)(1200),k=(0,l.useRef)(void 0),N=(0,l.useRef)(0),S=(0,l.useRef)([]),[C,R]=(0,l.useState)([]),[I,E]=(0,l.useState)([]),M=(0,l.useCallback)(async e=>{var n;let a;if(0===e.size)return{ok:!1,reason:"empty"};if(e.size>8388608)return{ok:!1,reason:"oversized"};let l=(n=e.type).startsWith("image/")?"image":tP.some(e=>n.startsWith(e))||tA.has(n)?"document":"unsupported-type";if("unsupported-type"===l)return{ok:!1,reason:"unsupported-type"};let s=t.models.find(e=>e.id===t.selectedModel);if(void 0!==s&&("image"===l&&!s.supportsImageInput||"document"===l&&!s.supportsDocumentInput))return{ok:!1,reason:"text-only-model"};if("image"===l)try{a=await new Promise((t,n)=>{let a=new FileReader;a.onload=()=>t(a.result),a.onerror=()=>n(Error("FileReader error")),a.readAsDataURL(e)})}catch(e){return{ok:!1,reason:"unsupported-type"}}let i={id:crypto.randomUUID(),kind:l,name:e.name,mimeType:e.type,sizeBytes:e.size,previewDataUrl:a,file:e};return R(e=>[...e,i]),{ok:!0}},[t.models,t.selectedModel]),T=(0,l.useCallback)(e=>{R(t=>t.filter(t=>t.id!==e))},[]),q=(0,l.useCallback)(()=>{R([])},[]),P=(0,l.useCallback)(async()=>{let e=C.filter(e=>"document"===e.kind&&void 0!==e.file).map(e=>({id:e.id,name:e.name,mimeType:e.mimeType,sizeBytes:e.sizeBytes,file:e.file}));if(0===e.length)return{entries:[],disclosures:[]};let{entries:t,failures:n}=await tq(e);n.length>0&&m(n.join(" "));let a=t.map(e=>({id:e.id,displayName:e.displayName,truncated:e.truncated}));return{entries:t,disclosures:a}},[C]),A=(0,l.useCallback)(()=>{x(void 0)},[]),z=(0,l.useCallback)((e,t)=>({enabled:y,budgetTokens:j,context:{userId:"local-operator",workspaceId:t.path,projectId:t.path,conversationId:e.id}}),[j,y]),D=(0,l.useCallback)(async e=>{await (0,tk.mc)(e),x(t=>void 0===t?t:{...t,actions:t.actions.filter(t=>"candidate"!==t.kind||t.proposalId!==e)})},[]),L=(0,l.useCallback)(async e=>{await (0,tk.RT)(e),x(t=>void 0===t?t:{...t,actions:t.actions.filter(t=>"candidate"!==t.kind||t.proposalId!==e)})},[]),F=(0,l.useCallback)(async e=>{await (0,tk.hz)(e,"user-initiated forget from Conversation Center"),x(t=>void 0===t?t:{...t,actions:t.actions.filter(t=>"forget"!==t.kind||t.memoryId!==e)})},[]),O=(0,l.useCallback)(e=>{u.current=e,c(e)},[]);(0,l.useEffect)(()=>{var e;k.current=null==(e=t.activeChat)?void 0:e.id},[null==(e=t.activeChat)?void 0:e.id]),(0,l.useEffect)(()=>{S.current=t.models},[t.models]),(0,l.useEffect)(()=>{let e=!1;return async function(){r(!0),m(void 0);try{let t=await tV();e||n(e=>({...e,...t}))}catch(t){e||m(tW(t))}finally{e||r(!1)}}(),()=>{e=!0}},[]),(0,l.useEffect)(()=>()=>{var e;null==(e=h.current)||e.abort()},[]);let K=(0,l.useCallback)(e=>{let t;m(void 0),n(n=>(t={selectedModel:n.selectedModel,activeChat:n.activeChat,chats:n.chats},{...n,selectedModel:e,activeChat:void 0===n.activeChat?n.activeChat:{...n.activeChat,selectedModel:e},chats:n.chats.map(t=>void 0!==n.activeChat&&t.id===n.activeChat.id?{...t,selectedModel:e}:t)})),R(t=>t.filter(t=>(function(e,t,n){let a=n.find(e=>e.id===t);return void 0===a||("image"===e.kind?a.supportsImageInput:a.supportsDocumentInput)})(t,e,S.current)));let a=k.current;if(void 0===a)return;let l=N.current+1;N.current=l,(0,$.wi)(a,{selectedModel:e}).then(e=>{N.current===l&&k.current===e.chat.id&&n(t=>{var n;return{...t,selectedModel:e.chat.selectedModel,activeChat:(null==(n=t.activeChat)?void 0:n.id)===e.chat.id?e.chat:t.activeChat,chats:t.chats.map(t=>t.id===e.chat.id?e.chat:t)}})}).catch(e=>{if(N.current===l&&k.current===a&&(m(tW(e)),void 0!==t)){let e=t;n(t=>{var n,l;return{...t,selectedModel:(null==(n=t.activeChat)?void 0:n.id)===a?e.selectedModel:t.selectedModel,activeChat:(null==(l=t.activeChat)?void 0:l.id)===a?e.activeChat:t.activeChat,chats:t.chats.map(t=>{if(t.id!==a)return t;let n=e.chats.find(e=>e.id===a);return void 0!==n?{...t,selectedModel:n.selectedModel}:t})}})}})},[]),B=(0,l.useCallback)(async e=>{let a=tH(t.selectedModel,t.models);if(void 0===a)return void m("No conversation-eligible model is configured. Connect a gateway in Settings.");m(void 0);try{var l,s;let i={modelId:a,title:tz},r=null!=(s=null==e?void 0:e.path)?s:null==(l=t.activeProject)?void 0:l.path;void 0!==r&&(i.projectPath=r);let o=await (0,$.tA)(i);k.current=o.chat.id,n({projects:Array.from(o.projects),chats:tU(o.chats),messages:Array.from(o.messages),models:t.models,activeProject:o.project,activeChat:o.chat,selectedModel:o.chat.selectedModel})}catch(e){m(tW(e))}},[t.selectedModel,t.activeProject,t.models]),W=(0,l.useCallback)(async e=>{m(void 0),n(t=>({...t,activeProject:e}));try{let a=await (0,$.Oz)(e.path),l=tU(a.chats),s=l[0];if(void 0===s)return void await B(e);let i=await (0,$.T$)(s.id,e.path);k.current=s.id;let r=tH(s.selectedModel,t.models);n(e=>({...e,chats:l,activeChat:s,selectedModel:r,messages:Array.from(i.messages)})),x(void 0)}catch(e){m(tW(e))}},[B,t.models]),U=(0,l.useCallback)(async e=>{var a;m(void 0),null==(a=h.current)||a.abort(),h.current=null,k.current=e.id,g(void 0),x(void 0),E([]);try{let a=await (0,$.T$)(e.id,e.projectPath),l=tH(e.selectedModel,t.models);n(t=>{let n=t.projects.find(t=>t.path===e.projectPath);return{...t,activeProject:n,activeChat:e,selectedModel:l,messages:Array.from(a.messages)}})}catch(e){m(tW(e))}},[t.models]),_=(0,l.useCallback)(async e=>{let t=e.trim();if(0!==t.length){m(void 0);try{let e=await (0,$.gA)({path:t}),a=await (0,$.vj)();n(e=>({...e,projects:Array.from(a.projects)})),await B(e.project)}catch(e){m(tW(e))}}},[B]),H=(0,l.useCallback)(e=>{n(t=>({...t,messages:t.messages.filter(t=>t.id!==e)}))},[]),J=(0,l.useCallback)((e,t,a)=>{let l=!1;return{onToken:t=>{l||(O("streaming"),l=!0),n(n=>({...n,messages:n.messages.map(n=>n.id===e?{...n,content:n.content+t}:n)}))},onDone:l=>{n(n=>({...n,activeChat:l.chat,chats:tU([l.chat,...n.chats.filter(e=>e.id!==l.chat.id)]),messages:[...n.messages.filter(n=>n.id!==t&&n.id!==e),...Array.from(l.messages)]})),void 0!==l.memory&&x(l.memory),a("completed")},onError:t=>{let{message:n}=t;m(n),H(e),a("failed")},onCancelled:()=>{H(e),a("cancelled")}}},[H,O]),V=(0,l.useCallback)((e,t,a,l,s,i,r)=>{let o="stream-".concat(String(Date.now()));n(t=>({...t,messages:[...t.messages,{id:o,chatId:e.id,role:"assistant",content:"",timestamp:Date.now(),runId:void 0,workflowId:void 0,workflowStatus:void 0,shortResult:void 0,taskType:void 0}]}));let c={chatId:e.id,projectPath:t.path,content:a,modelId:s,memory:z(e,t),...r.length>0?{documentContext:r}:{}};return new Promise((e,t)=>{let n=J(o,l,e);(0,$.nk)(c,i,n).catch(n=>{H(o),n instanceof $.ZF?t(n):n instanceof DOMException&&"AbortError"===n.name?e("cancelled"):e("failed")})})},[z,J,H]),G=(0,l.useCallback)(async(e,t,a,l,s,i,r)=>{try{O("contacting");let o=await (0,$.xp)({chatId:e.id,projectPath:t.path,content:a,modelId:s,memory:z(e,t),...r.length>0?{documentContext:r}:{}},i);if(i.aborted)return"cancelled";return n(e=>({...e,activeChat:o.chat,chats:tU([o.chat,...e.chats.filter(e=>e.id!==o.chat.id)]),messages:[...e.messages.filter(e=>e.id!==l),...Array.from(o.messages)]})),x(o.memory),"completed"}catch(a){if(a instanceof DOMException&&"AbortError"===a.name)return"cancelled";m(tW(a));try{let a=await (0,$.T$)(e.id,t.path);n(e=>({...e,messages:Array.from(a.messages)}))}catch(e){n(e=>({...e,messages:e.messages.filter(e=>e.id!==l)}))}return"failed"}},[z,O]),X=(0,l.useCallback)(async(e,n,a,l,s,i,r)=>{var o;if((null==(o=t.models.find(e=>e.id===s))?void 0:o.streaming)!==!0)return G(e,n,a,l,s,i,r);O("contacting");try{return await V(e,n,a,l,s,i,r)}catch(e){if(!(e instanceof $.ZF))throw e}return G(e,n,a,l,s,i,r)},[t.models,G,V,O]),Y=(0,l.useCallback)(async(e,t,a,l,s,i)=>{g(void 0);try{O("contacting");let l=await (0,$.Wk)({chatId:e.id,content:a,modelId:s},i);if(k.current!==e.id)return"completed";if(i.aborted)return"cancelled";g(l),x(void 0);let[r,o]=await Promise.all([(0,$.T$)(e.id,t.path),(0,$.Oz)(t.path)]),c=o.chats.find(t=>t.id===e.id);return n(e=>({...e,messages:Array.from(r.messages),chats:tU(o.chats),activeChat:null!=c?c:e.activeChat})),"completed"}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return"cancelled";return m(tW(e)),n(e=>({...e,messages:e.messages.filter(e=>e.id!==l)})),"failed"}},[O]),Z=(0,l.useCallback)(()=>{var e;tL(u.current)&&(null==(e=h.current)||e.abort(),h.current=null,O("cancelled"))},[O]),Q=(0,l.useCallback)(async()=>{var e,l,i,r;if(tL(u.current))return;let o=a.trim(),c=t.activeChat,d=t.activeProject,p=tH(t.selectedModel,t.models);if(0===o.length||void 0===c||void 0===d||void 0===p)return;if(tB((0,tN.pk)({modelContextWindow:null!=(i=null==(e=t.models.find(e=>e.id===p))?void 0:e.contextWindow)?i:0,modelMaxOutputTokens:null!=(r=null==(l=t.models.find(e=>e.id===p))?void 0:l.maxOutputTokens)?r:0,userDraftText:o,conversationHistory:t.messages.filter(e=>"user"===e.role||"assistant"===e.role).map(e=>({role:e.role,content:e.content}))})))return void m(tF);let f={id:"local-".concat(String(Date.now())),chatId:c.id,role:"user",content:o,timestamp:Date.now(),runId:void 0,workflowId:void 0,workflowStatus:void 0,shortResult:void 0,taskType:void 0};O("queued"),s(""),m(void 0),n(e=>({...e,messages:[...e.messages,f]}));let g=new AbortController;h.current=g,x(void 0);try{let e=void 0!==c.connectedScope||void 0!==c.localKnowledgeScope,{entries:t,disclosures:n}=e?{entries:[],disclosures:[]}:await P(),a=e?await Y(c,d,o,f.id,p,g.signal):await X(c,d,o,f.id,p,g.signal,t);"cancelled"===u.current||O(a),"completed"===a&&(q(),E(n))}finally{h.current=null}},[a,t.activeChat,t.activeProject,t.selectedModel,t.models,t.messages,Y,X,P,q,O]),ee=(0,l.useCallback)(()=>{g(void 0),x(void 0),n(e=>({...e,messages:[]}))},[]),et=(0,l.useMemo)(()=>{let e=t.models.find(e=>e.id===t.selectedModel);if(void 0===e)return;let n=t.messages.filter(e=>"user"===e.role||"assistant"===e.role).map(e=>({role:e.role,content:e.content})),l=0,s=0;void 0!==f&&(("connected-context"===f.groundingKind||"hybrid"===f.groundingKind)&&(l=("hybrid"===f.groundingKind?f.contextPack.folder:f.contextPack).usage.excerptBytes),("local-knowledge"===f.groundingKind||"hybrid"===f.groundingKind)&&(s=4*("hybrid"===f.groundingKind?f.contextPack.knowledge:f.contextPack).referenceBudget));let i=y&&void 0!==v&&v.context.enabled?v.context.text.length:0;return(0,tN.pk)({modelContextWindow:e.contextWindow,modelMaxOutputTokens:e.maxOutputTokens,userDraftText:a,conversationHistory:n,repoContextPackBytes:l,knowledgeCapsuleBytes:s,memoryContextBytes:i})},[t.models,t.selectedModel,t.messages,a,f,v,y]),en=(0,l.useCallback)(async e=>{if(tL(u.current))return{ok:!1,reason:"request-failed",message:"A request is already in flight."};let a=e.text.trim();if(0===a.length)return{ok:!1,reason:"missing-input"};let l=t.activeChat,s=t.activeProject;if(void 0===l||void 0===s)return{ok:!1,reason:"missing-chat"};let i=t.models.find(t=>t.id===e.modelId);if(void 0===i||!tu(i))return{ok:!1,reason:"not-workflow-eligible"};let r=td(e.workflowId);if(void 0===r)return{ok:!1,reason:"unknown-workflow"};let o=Date.now(),c=r.buildInput(s.path,a);try{let t=await (0,$.qV)({chatId:l.id,projectPath:s.path,run:{workflowId:e.workflowId,input:c,modelId:e.modelId},user:{content:a,timestamp:o},summary:{content:"Launched: ".concat(r.label),timestamp:o+1}});return n(e=>({...e,messages:Array.from(t.messages)})),{ok:!0,runId:t.run.runId}}catch(t){let e=tW(t);return m(e),{ok:!1,reason:"request-failed",message:e}}},[t.activeChat,t.activeProject,t.models]),ea=(0,l.useCallback)(async e=>{if(tL(u.current))return{ok:!1,reason:"request-failed",message:"A request is already in flight."};if(void 0===t.activeChat)return{ok:!1,reason:"missing-chat"};if(0===e.modelId.trim().length)return{ok:!1,reason:"missing-model"};try{let t=await (0,$.Is)({assistantMessageId:e.assistantMessageId,modelId:e.modelId,workflowKind:e.workflowKind,input:e.input,editablePaths:e.editablePaths,...void 0===e.expectedChecks?{}:{expectedChecks:e.expectedChecks},...void 0===e.unknowns?{}:{unknowns:e.unknowns},requestedAtMs:Date.now()});return n(e=>({...e,messages:Array.from(t.messages)})),{ok:!0,runId:t.run.runId}}catch(t){let e=tW(t);return m(e),{ok:!1,reason:"request-failed",message:e}}},[t.activeChat]),el=(0,l.useCallback)(e=>{n(t=>{var n;return{...t,chats:t.chats.map(t=>t.id===e.id?e:t),activeChat:(null==(n=t.activeChat)?void 0:n.id)===e.id?e:t.activeChat}})},[]);return{projects:t.projects,chats:t.chats,messages:t.messages,models:t.models,activeProject:t.activeProject,activeChat:t.activeChat,selectedModel:t.selectedModel,noEligibleModels:!i&&void 0===tH(t.selectedModel,t.models),draft:a,loading:i,sending:d,sendStatus:o,error:p,setDraft:s,setSelectedModel:K,openNewChat:B,openProject:W,openChat:U,addProject:_,sendMessage:Q,cancelSend:Z,replaceChat:el,latestGrounded:f,cancelGrounded:Z,pendingAttachments:C,addPendingAttachment:M,removePendingAttachment:T,clearPendingAttachments:q,lastSentDocuments:I,budget:et,memoryEnabled:y,setMemoryEnabled:b,memoryBudgetTokens:j,setMemoryBudgetTokens:w,latestMemory:v,clearLatestMemory:A,acceptMemoryCandidate:D,rejectMemoryCandidate:L,forgetMemoryAction:F,clearHistory:ee,launchWorkflowFromConversation:en,launchGroundedWorkflowHandoff:ea}}(),f=(0,l.useRef)(null),[g,v]=(0,l.useState)(tN.ty);(0,l.useEffect)(()=>{(0,$.Dz)().then(e=>v(e.effectiveGroundingLimits)).catch(()=>void 0)},[]);let x=(0,l.useCallback)(e=>{let t=m.activeChat;if(void 0===t)return;let n=eh(t),a=function(e,t,n){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:16;if(!ec(t))return null;if(e.some(e=>e.root===t))return e;let l=[...e,{kind:"workspace-root",relativePaths:[],root:t,connectedAtMs:n}];return l.length>a?l.slice(-a):l}(n,e,Date.now(),g.maxConnectedSources);null!==a&&a!==n&&(0,$.Mr)(t.id,a).then(n=>{var a;m.replaceChat(n.chat),a=t.id,0!==a.length&&0!==e.length&&n6({type:"reads-context",source:{kind:"chat",id:a},target:{kind:"workspace-path",id:e}},function(e,t){let n=0x811c9dc5,a="".concat(e,"|").concat(t);for(let e=0;e<a.length;e+=1)n=Math.imul(n^a.charCodeAt(e),0x1000193);return"rc-".concat((n>>>0).toString(36),"-").concat((65535&a.length).toString(36))}(a,e)).catch(e=>{})}).catch(()=>void 0)},[m,g.maxConnectedSources]),y=(0,l.useCallback)(e=>{var t;let n=m.activeChat;if(void 0===n)return;let a=(t=eh(n),t.filter(t=>t.root!==e));(0,$.Mr)(n.id,a.length>0?a:null).then(e=>{m.replaceChat(e.chat)}).catch(()=>void 0)},[m]),b=function(e){var t,n,a,s,i,r;let o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},[c,d]=(0,l.useState)(null),[u,h]=(0,l.useState)(null),[p,m]=(0,l.useState)(!1),[f,g]=(0,l.useState)([]),[v,x]=(0,l.useState)(null),[y,b]=(0,l.useState)(nH),j=(0,l.useRef)(3),w=(0,l.useRef)(null),k=(0,l.useRef)([]);k.current=null!=c?c:[];let N=(0,l.useRef)([]);N.current=f;let S=(0,l.useRef)(null);S.current=v;let C=(0,l.useRef)(null),R=(0,l.useRef)(()=>void 0),{viewRef:I,worldVP:E,zoomTo:M,resetView:T,panBy:q,rect:P}=function(e){let{wsRef:t,view:n,setView:a}=e,s=(0,l.useRef)(n);s.current=n,(0,l.useEffect)(()=>{nX(n_,n)},[n]),(0,l.useEffect)(()=>{let e=t.current;if(null===e)return;let n=t=>{if(t.metaKey||t.ctrlKey){t.preventDefault();let n=e.getBoundingClientRect(),l=s.current,i=nJ(l.zoom*Math.exp(-(.0015*t.deltaY))),r=(t.clientX-n.left-l.x)/l.zoom,o=(t.clientY-n.top-l.y)/l.zoom;a({zoom:i,x:t.clientX-n.left-r*i,y:t.clientY-n.top-o*i});return}let n=t.target;n instanceof Element&&null!==n.closest(".window")||(t.preventDefault(),a(e=>({...e,x:e.x-t.deltaX,y:e.y-t.deltaY})))};return e.addEventListener("wheel",n,{passive:!1}),()=>{e.removeEventListener("wheel",n)}},[t,a]);let i=(0,l.useCallback)(()=>null===t.current?null:t.current.getBoundingClientRect(),[t]),r=(0,l.useCallback)(()=>{let e=i();if(null===e)return null;let t=s.current;return{x:-t.x/t.zoom,y:-t.y/t.zoom,w:e.width/t.zoom,h:e.height/t.zoom}},[i]),o=(0,l.useCallback)(e=>{let t=i();if(null===t)return;let n=s.current,l=t.width/2,r=t.height/2,o=(l-n.x)/n.zoom,c=(r-n.y)/n.zoom,d=nJ(e);a({zoom:d,x:l-o*d,y:r-c*d})},[i,a]);return{viewRef:s,worldVP:r,zoomTo:o,resetView:(0,l.useCallback)(()=>a({zoom:1,x:0,y:0}),[a]),panBy:(0,l.useCallback)((e,t)=>a(n=>({...n,x:n.x+e,y:n.y+t})),[a]),rect:i}}({wsRef:e,view:y,setView:b});!function(e){let{wsRef:t,setWins:n,setConns:a,zc:s}=e;(0,l.useLayoutEffect)(()=>{let e=t.current;if(null===e)return;e.getBoundingClientRect();let l=null;try{l=function(e){if(null===e)return null;try{let t=JSON.parse(e);if(!Array.isArray(t)||0===t.length)return null;let n=nK(t);return n.length>0?n:null}catch(e){return null}}(window.localStorage.getItem(nW))}catch(e){l=null}null===l&&(l=[]),s.current=0===l.length?1:Math.max(1,...l.map(e=>e.z)),n(l);try{a(function(e,t){if(null===e)return[];try{let n=JSON.parse(e);if(!Array.isArray(n))return[];return nB(n,t)}catch(e){return[]}}(window.localStorage.getItem(nU),l))}catch(e){}},[t,n,a,s])}({wsRef:e,setWins:d,setConns:g,zc:j}),(0,l.useEffect)(()=>{null!==c&&nX(nU,nB(f,c))},[f,c]),(0,l.useEffect)(()=>{null!==c&&g(e=>{let t=e.filter(e=>void 0!==c.find(t=>t.id===e.a)&&void 0!==c.find(t=>t.id===e.b));return t.length===e.length?e:t})},[c,g]),(0,l.useEffect)(()=>{null!==c&&nX(nW,nK(c))},[c]),function(e){let{setWins:t,rect:n,cancelConnectRef:a}=e;(0,l.useEffect)(()=>{let e=e=>{var l,s,i;if(null!==(l=document.activeElement)&&("INPUT"===l.tagName||"TEXTAREA"===l.tagName||"SELECT"===l.tagName))return;if("Escape"===e.key)return void a.current();if((e.metaKey||e.ctrlKey)&&["=","+","-","_","0"].includes(e.key)){e.preventDefault(),s=e.key,t(e=>{var t,n;if(null===e||0===e.length)return e;let a=nG(e),l=(n=null!=(t=a.zoom)?t:1,"0"===s?1:"-"===s||"_"===s?nV(n-.1):nV(n+.1));return e.map(e=>e.id===a.id?{...e,zoom:l}:e)});return}if(!/^Arrow/.test(e.key))return;let r=e.metaKey||e.ctrlKey,o=e.altKey;if(!r&&!o)return;e.preventDefault();let c=n();null!==c&&(i={key:e.key,shift:e.shiftKey},t(e=>{if(null===e||0===e.length)return e;let t=nG(e),n=o?function(e,t,n){let a=n.shift?1:16,l=e.w,s=e.h;"ArrowRight"===n.key?l+=a:"ArrowLeft"===n.key?l-=a:"ArrowDown"===n.key?s+=a:"ArrowUp"===n.key&&(s-=a);let i=es[e.type].min;return l=Math.max(i.w,Math.min(t.width,l)),s=Math.max(i.h,Math.min(t.height,s)),{x:e.x,y:e.y,w:l,h:s}}(t,c,i):function(e,t,n){let a=n.shift?1:16,l=e.x,s=e.y;return"ArrowRight"===n.key?l+=a:"ArrowLeft"===n.key?l-=a:"ArrowDown"===n.key?s+=a:"ArrowUp"===n.key&&(s-=a),{x:l=Math.max(-(e.w-120),Math.min(t.width-120,l)),y:s=Math.max(0,Math.min(t.height-38,s)),w:e.w,h:e.h}}(t,c,i);return e.map(e=>e.id===t.id?{...e,...n,max:!1}:e)}))};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e)}},[t,n,a])}({setWins:d,rect:P,cancelConnectRef:R}),function(e){let{wsRef:t,viewRef:n,setWins:a}=e;(0,l.useEffect)(()=>{let e=t.current;if(null===e||"undefined"==typeof ResizeObserver)return;let l=new ResizeObserver(()=>{let t=e.getBoundingClientRect(),l=n.current,s={x:-l.x/l.zoom,y:-l.y/l.zoom,w:t.width/l.zoom,h:t.height/l.zoom};a(e=>null===e?e:e.map(e=>e.max?{...e,x:s.x,y:s.y,w:s.w,h:s.h}:e))});return l.observe(e),()=>{l.disconnect()}},[t,n,a])}({wsRef:e,viewRef:I,setWins:d});let{update:A,focus:z,close:D,maximize:L,add:F,toggleTool:O}={update:(n=(t={setWins:d,zc:j,worldVP:E}).setWins,(e,t)=>n(n=>null===n?n:n.map(n=>n.id===e?{...n,...t}:n))),focus:(a=t.setWins,s=t.zc,e=>a(t=>null===t?t:t.map(t=>t.id===e?{...t,z:++s.current}:t))),close:(i=t.setWins,e=>i(t=>null===t?t:t.filter(t=>t.id!==e))),maximize:function(e){let{setWins:t,zc:n,worldVP:a}=e;return e=>t(t=>{if(null===t)return t;let l=a();return null===l?t:t.map(t=>t.id!==e?t:t.max&&void 0!==t.prev?{...t,x:t.prev.x,y:t.prev.y,w:t.prev.w,h:t.prev.h,max:!1,z:++n.current}:{...t,max:!0,prev:{x:t.x,y:t.y,w:t.w,h:t.h},x:l.x,y:l.y,w:l.w,h:l.h,z:++n.current})})}(t),add:function(e){let{setWins:t,zc:n,worldVP:a}=e;return(e,l)=>{let s=es[e],i=null;return t(t=>{let r=a();if(null===r)return t;let o=null!=t?t:[];if(!0===s.singleton){let t=o.find(t=>t.type===e);if(void 0!==t)return i=t.id,o.map(e=>e.id===t.id?{...e,z:++n.current}:e)}let c="qiRun"===e?null==l?void 0:l.runId:void 0;if("string"==typeof c&&c.length>0){let e=o.find(e=>"qiRun"===e.type&&e.cfg.runId===c);if(void 0!==e)return i=e.id,o.map(t=>t.id===e.id?{...t,z:++n.current}:t)}let{x:d,y:u}=ei(r,s.w,s.h,o.length,40),h=!0===s.singleton?e:"".concat(e,"-").concat(Date.now().toString(36));return i=h,[...o,{id:h,type:e,x:d,y:u,w:s.w,h:s.h,z:++n.current,cfg:null!=l?l:{},max:!1,zoom:1}]}),i}}(t),toggleTool:function(e){let{setWins:t,zc:n,worldVP:a}=e;return e=>{let l=es[e];t(t=>{let s=a();if(null===s)return t;let i=null!=t?t:[];if(void 0!==i.find(t=>t.type===e))return i.filter(t=>t.type!==e);let{x:r,y:o}=ei(s,l.w,l.h,i.length,28);return[...i,{id:e,type:e,x:r,y:o,w:l.w,h:l.h,z:++n.current,cfg:{},max:!1,zoom:1}]})}}(t)},{tileAll:K,splitFront:B,cascade:W}={tileAll:function(e){let{setWins:t,worldVP:n}=e;return()=>t(e=>{if(null===e||0===e.length)return e;let t=n();if(null===t)return e;let a=e.length,l=Math.ceil(Math.sqrt(a)),s=Math.ceil(a/l),i=(t.w-12*(l+1))/l,r=(t.h-12*(s+1))/s;return e.map((e,n)=>{let a=Math.floor(n/l);return{...er(e),max:!1,x:t.x+12+n%l*(i+12),y:t.y+12+a*(r+12),w:i,h:r}})})}(r={setWins:d,worldVP:E}),splitFront:function(e){let{setWins:t,worldVP:n}=e;return()=>t(e=>{if(null===e||0===e.length)return e;let t=n();if(null===t)return e;let a=[...e].sort((e,t)=>t.z-e.z).slice(0,2).map(e=>e.id);return e.map(e=>{let n=a.indexOf(e.id);return 0===n?{...er(e),max:!1,x:t.x,y:t.y,w:t.w/2,h:t.h}:1===n?{...er(e),max:!1,x:t.x+t.w/2,y:t.y,w:t.w/2,h:t.h}:e})})}(r),cascade:function(e){let{setWins:t,worldVP:n}=e;return()=>t(e=>{if(null===e)return e;let t=n();return null===t?e:e.map((e,n)=>({...er(e),max:!1,x:t.x+24+30*n,y:t.y+24+30*n,w:Math.min(560,t.w-80),h:Math.min(420,t.h-80),z:n+1}))})}(r)},{setSnap:U,commitSnap:_}=function(e){let{setSnapPrev:t,snapZone:n,worldVP:a,update:l}=e;return{setSnap:e=>{if(n.current=e,null===e)return void t(null);let l=a();null!==l&&t(G(l)[e])},commitSnap:e=>{let s=n.current;if(n.current=null,t(null),null===s)return;let i=a();if(null===i)return;let r={...G(i)[s],max:"maxi"===s};"maxi"===s&&(r.prev={x:i.x+40,y:i.y+40,w:480,h:360}),l(e,r)}}}({setSnapPrev:h,snapZone:w,worldVP:E,update:A}),{startConnect:H,confirmConnect:J,cancelConnect:X,removeConn:Y,connect:Z,linkedFilesRoot:Q,linkedFilesContext:$,linkedAllFilesRoots:ee,linkedConnectorCapsuleIds:et,linkedConnectorCapsuleSetIds:en,linkedFigmaSnapshotRunIds:ea,currentFilesContext:el}=function(e){let{wsRef:t,viewRef:n,winsRef:a,connsRef:l,connectingRef:s,connectCleanupRef:i,focus:r,setConns:o,setConnecting:c,onScopeBind:d,onScopeUnbind:u,onConnectorBind:h,onConnectorUnbind:p}=e,m=()=>{null!==i.current&&(i.current(),i.current=null),s.current=null,c(null)},f=e=>{if("files"!==e.type)return null;let t=e.cfg.resolvedRoot,n=e.cfg.root,a="string"==typeof t&&t.length>0?t:"string"==typeof n&&n.length>0?n:"src",l=e.cfg.activeFilePath;return{id:e.id,root:a,..."string"==typeof l&&l.length>0?{activeFilePath:l}:{}}},g=e=>{let t=[];for(let n of l.current){let l=n.a===e?n.b:n.b===e?n.a:null;if(null===l)continue;let s=a.current.find(e=>e.id===l);void 0!==s&&"files"===s.type&&t.push(s)}if(0===t.length)return null;let n=[...t].sort((e,t)=>t.z-e.z),s=n.find(e=>{let t=e.cfg.activeFilePath;return"string"==typeof t&&t.length>0}),i=null!=s?s:n[0];return void 0===i?null:f(i)},v=(e,t)=>{let n=new Set,s=[];for(let i of l.current){if(s.length>=16)break;let l=i.a===e?i.b:i.b===e?i.a:null;if(null===l)continue;let r=a.current.find(e=>e.id===l);if(void 0===r||"connector"!==r.type||r.cfg.selectedKind!==t)continue;let o=r.cfg.selectedId;"string"==typeof o&&0!==o.length&&(n.has(o)||(n.add(o),s.push(o)))}return s};return{startConnect:(e,a)=>{if(a.preventDefault(),a.stopPropagation(),null!==s.current&&s.current.from===e)return void m();let l=t.current;if(null===l)return;let r=l.getBoundingClientRect(),o=n.current,d=e=>(e-r.left-o.x)/o.zoom,u=e=>(e-r.top-o.y)/o.zoom;null!==i.current&&(i.current(),i.current=null);let h={from:e,x:d(a.clientX),y:u(a.clientY)};s.current=h,c(h);let p=t=>{let n={from:e,x:d(t.clientX),y:u(t.clientY)};s.current=n,c(n)};window.addEventListener("pointermove",p),i.current=()=>{window.removeEventListener("pointermove",p)}},confirmConnect:(e,t)=>{t.preventDefault(),t.stopPropagation();let n=s.current;if(null===n)return;let l=a.current,i=l.find(e=>e.id===n.from),c=l.find(t=>t.id===e);if(void 0!==i&&void 0!==c&&V(i.type,c.type)){o(t=>eo(t,n.from,e)?t:[...t,{id:"".concat(n.from,"~").concat(e),a:n.from,b:e}]),r(e);let t=eu(i,c);null!==t&&(null==d||d(t));let a=ef(i,c);null!==a&&(null==h||h(a))}m()},cancelConnect:m,removeConn:e=>{let t=l.current.find(t=>t.id===e);if(o(t=>t.filter(t=>t.id!==e)),void 0===t)return;let n=a.current,s=n.find(e=>e.id===t.a),i=n.find(e=>e.id===t.b);if(void 0===s||void 0===i)return;let r=eu(s,i);null!==r&&(null==u||u(r));let c=ef(s,i);null!==c&&(null==p||p(c))},connect:(e,t)=>{let n=a.current,l=n.find(t=>t.id===e),s=n.find(e=>e.id===t);void 0!==l&&void 0!==s&&V(l.type,s.type)&&o(n=>eo(n,e,t)?n:[...n,{id:"".concat(e,"~").concat(t),a:e,b:t}])},linkedFilesRoot:e=>{var t,n;return null!=(n=null==(t=g(e))?void 0:t.root)?n:null},linkedFilesContext:g,linkedAllFilesRoots:e=>{let t=new Set,n=[];for(let s of l.current){if(n.length>=16)break;let l=s.a===e?s.b:s.b===e?s.a:null;if(null===l)continue;let i=a.current.find(e=>e.id===l);if(void 0===i)continue;let r=ed(i);null===r||t.has(r)||(t.add(r),n.push(r))}return n},linkedConnectorCapsuleIds:e=>v(e,"capsule"),linkedConnectorCapsuleSetIds:e=>v(e,"capsule-set"),linkedFigmaSnapshotRunIds:e=>{let t=new Set,n=[];for(let s of l.current){if(n.length>=16)break;let l=s.a===e?s.b:s.b===e?s.a:null;if(null===l)continue;let i=a.current.find(e=>e.id===l);if(void 0===i||"figma"!==i.type)continue;let r=i.cfg.snapshotRunId;"string"==typeof r&&0!==r.length&&(t.has(r)||(t.add(r),n.push(r)))}return n},currentFilesContext:()=>{var e;let t=a.current.map(e=>f(e)).filter(e=>null!==e);if(1===t.length)return null!=(e=t[0])?e:null;let n=[...a.current].filter(e=>"files"===e.type).sort((e,t)=>t.z-e.z)[0];return void 0===n?null:f(n)}}}({wsRef:e,viewRef:I,winsRef:k,connsRef:N,connectingRef:S,connectCleanupRef:C,focus:z,setConns:g,setConnecting:x,onScopeBind:o.onScopeBind,onScopeUnbind:o.onScopeUnbind,onConnectorBind:o.onConnectorBind,onConnectorUnbind:o.onConnectorUnbind});return R.current=X,(0,l.useEffect)(()=>()=>{null!==C.current&&(C.current(),C.current=null)},[]),{wins:c,snapPrev:u,palOpen:p,setPalOpen:m,conns:f,connecting:v,view:y,api:{add:F,toggleTool:O,focus:z,close:D,maximize:L,update:A,setSnap:U,commitSnap:_,tileAll:K,splitFront:B,cascade:W,startConnect:H,confirmConnect:J,cancelConnect:X,removeConn:Y,connect:Z,linkedFilesRoot:Q,linkedFilesContext:$,linkedAllFilesRoots:ee,linkedConnectorCapsuleIds:et,linkedConnectorCapsuleSetIds:en,linkedFigmaSnapshotRunIds:ea,currentFilesContext:el,zoomTo:M,resetView:T,panBy:q,rect:P}}}(f,{onScopeBind:x,onScopeUnbind:y,onConnectorBind:(0,l.useCallback)(e=>{let t=m.activeChat;if(void 0===t)return;let n=ep(t),a=function(e,t,n){let a=em(t);if(e.some(e=>em(e)===a))return e;let l=[...e,t];return l.length>n?l.slice(-n):l}(n,e,g.maxLocalKnowledgeSources);a!==n&&(0,$.Cp)(t.id,a).then(e=>{m.replaceChat(e.chat)}).catch(()=>void 0)},[m,g.maxLocalKnowledgeSources]),onConnectorUnbind:(0,l.useCallback)(e=>{var t;let n=m.activeChat;if(void 0===n)return;let a="capsule"===e.kind?"capsule:".concat(e.capsuleId):"set:".concat(e.capsuleSetId),l=(t=ep(n),t.filter(e=>em(e)!==a));(0,$.Cp)(n.id,l.length>0?l:null).then(e=>{m.replaceChat(e.chat)}).catch(()=>void 0)},[m])}),[j,N]=(0,l.useState)(!1),[S,R]=(0,l.useState)(null),[I,E]=(0,l.useState)(!1),M=null!=(r=null==(e=b.wins)?void 0:e.length)?r:0,T=function(e){if(null===e||0===e.length)return null;let t=e[0];for(let n=1;n<e.length;n++){let a=e[n];a.z>t.z&&(t=a)}return t}(b.wins),q=(0,l.useMemo)(()=>(function(e){if(null===e)return new Set;let t=new Set;for(let n of e)!0===es[n.type].tool&&t.add(n.type);return t})(b.wins),[b.wins]),P=(0,l.useMemo)(()=>{var e;return{wins:null!=(e=b.wins)?e:[],active:T,winCount:M}},[b.wins,T,M]),z=(0,l.useCallback)(()=>N(!0),[]),D=(0,l.useCallback)(()=>N(!1),[]),L=(0,l.useCallback)(e=>{N(!1),R(e)},[]),F=(0,l.useCallback)(e=>{R(t=>{if(null!==t){let{__connectFilesId:n,...a}=e,l=b.api.add(t,a);"agents"===t&&null!==l&&"string"==typeof n&&n.length>0&&b.api.connect(l,n)}return null})},[b.api]),O=(0,l.useCallback)(()=>R(null),[]),B=(0,l.useCallback)(()=>E(!1),[]),U=(0,l.useRef)(null),_=(0,l.useCallback)(e=>{U.current=e},[]),H=function(e){var t;let{apply:n}=e,a=null!=(t=e.limit)?t:100,[s,i]=(0,l.useState)(ar),r=(0,l.useRef)(n);r.current=n;let o=(0,l.useRef)(s);o.current=s;let c=(0,l.useCallback)(e=>{i(t=>{let n=[...t.undoStack,e];return{undoStack:n.length>a?n.slice(n.length-a):n,redoStack:[]}})},[a]),d=(0,l.useCallback)(()=>{let e=o.current;if(0===e.undoStack.length)return;let t=e.undoStack[e.undoStack.length-1],n=function(e){switch(e.kind){case"ui.window.move":case"ui.window.resize":case"ui.window.zorder":case"ui.workspace.pan":case"ui.workspace.zoom":case"ui.workspace.fit":case"ui.panel.toggle":case"ui.selection.change":case"ui.tab.switch":return{...e,before:e.after,after:e.before};case"ui.window.close":return{...e,kind:"ui.window.open"};case"ui.window.open":return{...e,kind:"ui.window.close"}}}(t);i({undoStack:e.undoStack.slice(0,-1),redoStack:[...e.redoStack,t]}),r.current(n)},[]),u=(0,l.useCallback)(()=>{let e=o.current;if(0===e.redoStack.length)return;let t=e.redoStack[e.redoStack.length-1];i({undoStack:[...e.undoStack,t],redoStack:e.redoStack.slice(0,-1)}),r.current(t)},[]),h=(0,l.useCallback)(()=>{i(ar)},[]);return(0,l.useMemo)(()=>{let e=s.undoStack[s.undoStack.length-1],t=s.redoStack[s.redoStack.length-1];return{canUndo:s.undoStack.length>0,canRedo:s.redoStack.length>0,undoLabel:void 0!==e?as(e):null,redoLabel:void 0!==t?as(t):null,push:c,undo:d,redo:u,clear:h}},[s,c,d,u,h])}({apply:(0,l.useCallback)(e=>{var t;return t=b.api,void("ui.panel.toggle"===e.kind&&e.panel in es&&t.toggleTool(e.panel))},[b.api])}),J=(0,l.useCallback)(e=>{if(!(e in es))return;let t=q.has(e);b.api.toggleTool(e),H.push({kind:"ui.panel.toggle",panel:e,before:t,after:!t})},[b.api,q,H]),X=(0,l.useCallback)(()=>L("chat"),[L]);!function(e){var t;let{bindings:n,dispatch:a}=e,s=null!=(t=e.platform)?t:function(){if("undefined"==typeof navigator)return"other";let e=navigator.platform||"";return/Mac|iPhone|iPad|iPod/i.test(e)?"mac":"other"}(),i=(0,l.useRef)(a);i.current=a;let r=(0,l.useMemo)(()=>(function(e){let t=new Map;for(let n of e){let e=ai(n.chord),a=t.get(e);void 0!==a?a.push(n.commandId):t.set(e,[n.commandId])}let n=[];for(let[,a]of t)if(a.length>1){let t=e.find(e=>a.includes(e.commandId));void 0!==t&&n.push({chord:t.chord,commandIds:a})}return n})(n),[n]),o=(0,l.useMemo)(()=>n.filter(e=>(function(e){for(let t of al)if(ai(e)===ai(t))return!0;return!1})(e.chord)),[n]);if(r.length>0)throw new ao(r);if(o.length>0)throw new ac(o);(0,l.useEffect)(()=>{function e(e){if(!function(e){if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;let t=e.tagName;return"INPUT"===t||"TEXTAREA"===t||"SELECT"===t}(e.target)){for(let t of n)if(function(e,t,n){if(e.key.toLowerCase()!==t.key.toLowerCase())return!1;let a=function(e,t){let n=new Set;for(let a of e)"cmd"===a?n.add("mac"===t?"meta":"ctrl"):"ctrl"===a?n.add("ctrl"):"alt"===a?n.add("alt"):"shift"===a&&n.add("shift");return n}(t.mod,n);return e.metaKey===a.has("meta")&&e.ctrlKey===a.has("ctrl")&&e.altKey===a.has("alt")&&e.shiftKey===a.has("shift")}(e,t.chord,s)){e.preventDefault(),i.current(t.commandId);return}}}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[n,s]),(0,l.useMemo)(()=>({bindings:n,conflicts:r,reserved:o}),[n,r,o])}({bindings:ad,dispatch:(0,l.useCallback)(e=>{var t;"undo"===e?H.undo():"redo"===e?H.redo():"focus-status"===e&&(null==(t=U.current)||t.focus())},[H])}),(0,l.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&("k"===e.key||"K"===e.key)&&(e.preventDefault(),E(e=>!e))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let Y=(0,l.useMemo)(()=>(function(e,t,n,a,l,s){let i=[];for(let e of iG){let t=es[e];i.push({id:"new-".concat(e),label:"New ".concat(t.title),group:"Create",icon:t.icon,run:()=>n(e)})}for(let e of iX){let n=es[e];i.push({id:"open-".concat(e),label:"Open ".concat(n.title),group:"Tools",icon:n.icon,run:()=>t(e)})}return i.push({id:"tile",label:"Tile all windows",group:"Layout",icon:"tile",run:e.tileAll}),i.push({id:"split",label:"Split front windows",group:"Layout",icon:"split",run:e.splitFront}),i.push({id:"cascade",label:"Cascade windows",group:"Layout",icon:"cascade",run:e.cascade}),i.push({id:"theme",label:"Toggle light / dark theme",group:"View",icon:"light"===a?"moon":"sun",run:l}),i.push({id:"undo",label:null!==s.undoLabel?"Undo: ".concat(s.undoLabel):"Undo (window and panel changes only)",group:"Edit",icon:"back",run:s.undo}),i.push({id:"redo",label:null!==s.redoLabel?"Redo: ".concat(s.redoLabel):"Redo (window and panel changes only)",group:"Edit",icon:"fwd",run:s.redo}),i})(b.api,J,L,u,h,H),[b.api,J,L,u,h,H]),Z=!m.loading&&0===m.models.length,Q=(o=null==(t=m.activeProject)?void 0:t.name,m.loading?"Loading project...":void 0!==o&&o.trim().length>0?o:"No project selected"),ee=void 0!==m.activeProject,et=(null==(n=m.activeProject)?void 0:n.available)===!0,en=(c={loading:m.loading,error:m.error,hasProject:ee,projectAvailable:et,noEligibleModels:m.noEligibleModels}).loading?"Loading shell":void 0!==c.error?"Shell error":c.hasProject?c.projectAvailable?c.noEligibleModels?"Gateway setup required":"Ready":"Project unavailable":"No project selected",ea=function(e){let t=(null!=e?e:[]).filter(e=>"review"===e.type);return 0===t.length?"Open review":t.some(e=>"string"==typeof e.cfg.runId&&e.cfg.runId.length>0)?"Evidence ready":"Review open"}(b.wins),el=void 0!==(d=null==(s=m.activeChat)?void 0:s.branchLabel)&&d.trim().length>0?d:"No branch selected",eg=j?(0,a.jsx)(nI,{types:es,order:iG,onAdd:L,onClose:D}):null;return(0,a.jsx)(i,{value:m,children:(0,a.jsx)(k.Provider,{value:P,children:(0,a.jsxs)("div",{className:"app",children:[(0,a.jsx)("h1",{className:"visually-hidden",children:"Keiko workspace"}),(0,a.jsx)(A,{mode:p.mode,projectName:Q,onModeChange:p.setMode,openPalette:z,onTileAll:b.api.tileAll,onSplitFront:b.api.splitFront,onCascade:b.api.cascade}),(0,a.jsxs)("div",{className:"mid",children:[(0,a.jsx)(K,{openTools:q,onTool:J,onNewChat:X,theme:u,onToggleTheme:h}),(0,a.jsx)("div",{className:"stage",children:(0,a.jsx)(nh,{ws:b,wsRef:f,openPalette:z,palette:eg})}),(0,a.jsx)(W,{openTools:q,onTool:J})]}),(0,a.jsx)(C,{winCount:M,mode:p.mode,selectedModel:m.selectedModel,projectName:Q,branchLabel:el,shellStatusLabel:en,evidenceStatusLabel:ea,statusRef:_}),null!==S&&(0,a.jsx)(nR,{type:S,types:es,filesContext:b.api.currentFilesContext(),onConfirm:F,onClose:O}),I&&(0,a.jsx)(np,{commands:Y,onClose:B}),Z?(0,a.jsx)(nf,{}):null,(0,a.jsx)(iV,{})]})})})}function iZ(){let[e,t]=(0,l.useState)(!1);return((0,l.useEffect)(()=>{t(!0)},[]),(0,l.useEffect)(()=>{!function(){if(!("undefined"!=typeof navigator&&"serviceWorker"in navigator))return;let e=navigator.serviceWorker;try{e.register("/sw.js",{scope:"/"}).catch(e=>{})}catch(e){}}()},[]),e)?(0,a.jsx)(j,{children:(0,a.jsx)(iY,{})}):(0,a.jsx)("div",{className:"app","aria-hidden":"true"})}function iQ(){return(0,a.jsx)(iZ,{})}},9389:(e,t,n)=>{"use strict";n.d(t,{FG:()=>m,H9:()=>v,KS:()=>x,Qi:()=>f,R3:()=>o,Tq:()=>p,WM:()=>d,qY:()=>c,r:()=>h,rw:()=>g,xY:()=>y,xr:()=>r,yN:()=>u});var a=n(2982);function l(e,t){let n={Accept:"application/json"};return null!=t&&(n["Content-Type"]="application/json"),"GET"!==e&&"HEAD"!==e&&(n["X-Keiko-CSRF"]="1"),n}async function s(e){try{let t=await e.json();return{code:t.error.code,message:t.error.message}}catch(t){return{code:"INTERNAL",message:"HTTP ".concat(e.status.toString())}}}async function i(e,t){var n;let i=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),r=await fetch(e,{...t,headers:l(i,null==t?void 0:t.body)});if(!r.ok){let{code:e,message:t}=await s(r);throw new a.hD(e,t,r.status)}if(204!==r.status)return r.json()}async function r(){return i("/api/local-knowledge/capsules")}async function o(){return i("/api/local-knowledge/capsule-sets")}async function c(e){return i("/api/local-knowledge/capsules",{method:"POST",body:JSON.stringify(e)})}async function d(e){return i("/api/local-knowledge/capsule-sets",{method:"POST",body:JSON.stringify(e)})}async function u(e,t){return i("/api/local-knowledge/capsules/".concat(encodeURIComponent(e)),{method:"PATCH",body:JSON.stringify(t)})}async function h(e){return i("/api/local-knowledge/capsules/".concat(encodeURIComponent(e),"/index"),{method:"POST",body:JSON.stringify({confirm:!0})})}async function p(e){return i("/api/local-knowledge/capsules/".concat(encodeURIComponent(e),"/index"),{method:"DELETE",body:JSON.stringify({confirm:!0})})}async function m(e,t,n){return i("/api/local-knowledge/capsules/".concat(encodeURIComponent(e),"/connection"),{method:"POST",body:JSON.stringify({scope:t,displayName:n})})}async function f(e){return i("/api/local-knowledge/capsules/".concat(encodeURIComponent(e),"/connection"),{method:"DELETE",body:JSON.stringify({confirm:!0})})}async function g(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:fetch,n="/api/local-knowledge/capsules/".concat(encodeURIComponent(e)),i=await t(n,{headers:l("GET",void 0)});if(!i.ok){let{code:e,message:t}=await s(i);throw new a.hD(e,t,i.status)}return i.json()}async function v(e){return i("/api/local-knowledge/capsules/".concat(encodeURIComponent(e)),{method:"DELETE",body:JSON.stringify({deleteIndex:!0,deleteSources:!1})})}async function x(e){return i("/api/local-knowledge/capsules/".concat(encodeURIComponent(e),"/reindex"),{method:"POST",body:JSON.stringify({mode:"changed-files"})})}async function y(e){return i("/api/local-knowledge/capsules/".concat(encodeURIComponent(e),"/reindex"),{method:"POST",body:JSON.stringify({mode:"repair-failed"})})}},9422:(e,t,n)=>{Promise.resolve().then(n.bind(n,4723))}}]);
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[923],{1352:(e,t,n)=>{"use strict";n.d(t,{Af:()=>i,CZ:()=>m,Ir:()=>o,RT:()=>b,Rx:()=>p,W_:()=>u,ax:()=>f,fC:()=>d,h0:()=>v,hz:()=>g,mc:()=>y,oW:()=>x,tR:()=>c,w0:()=>h,xr:()=>r});var a=n(2982);async function l(e){try{let t=await e.json();return{code:t.error.code,message:t.error.message}}catch(t){return{code:"INTERNAL",message:"HTTP ".concat(e.status.toString())}}}async function s(e,t){var n;let s=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),i=null==t?void 0:t.body,r=await fetch(e,{...t,headers:function(e,t){let n={Accept:"application/json"};return null!=t&&(n["Content-Type"]="application/json"),"GET"!==e&&"HEAD"!==e&&(n["X-Keiko-CSRF"]="1"),n}(s,i)});if(!r.ok){let{code:e,message:t}=await l(r);throw new a.hD(e,t,r.status)}return r.json()}async function i(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s,n=new URLSearchParams;void 0!==e.scope&&e.scope.length>0&&n.set("scope",e.scope.join(",")),void 0!==e.type&&e.type.length>0&&n.set("type",e.type.join(",")),void 0!==e.status&&e.status.length>0&&n.set("status",e.status.join(",")),void 0!==e.sensitivity&&e.sensitivity.length>0&&n.set("sensitivity",e.sensitivity.join(",")),void 0!==e.limit&&n.set("limit",e.limit.toString()),void 0!==e.offset&&n.set("offset",e.offset.toString());let a=n.toString();return t("/api/memory".concat(a.length>0?"?".concat(a):""))}async function r(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:s;return e("/api/memory/review-queue")}async function o(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/consolidation/jobs",{method:"POST",body:JSON.stringify({settings:e})})}async function c(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/consolidation/jobs/".concat(encodeURIComponent(e)))}async function d(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/consolidation/jobs/".concat(encodeURIComponent(e),"/cancel"),{method:"POST",body:"{}"})}async function u(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/".concat(encodeURIComponent(e)))}async function h(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:s;return n("/api/memory/".concat(encodeURIComponent(e)),{method:"PATCH",body:JSON.stringify(t)})}async function p(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/".concat(encodeURIComponent(e),"/pin"),{method:"POST",body:"{}"})}async function m(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/".concat(encodeURIComponent(e),"/unpin"),{method:"POST",body:"{}"})}async function f(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:s;return n("/api/memory/".concat(encodeURIComponent(e),"/archive"),{method:"POST",body:JSON.stringify({...void 0!==t?{reason:t}:{}})})}async function g(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:s;return n("/api/memory/".concat(encodeURIComponent(e),"/forget"),{method:"POST",body:JSON.stringify({acknowledged:!0,...void 0!==t?{reason:t}:{}})})}async function v(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/".concat(encodeURIComponent(e)),{method:"DELETE",body:"{}"})}async function x(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:s;return n("/api/memory/".concat(encodeURIComponent(e),"/correct"),{method:"POST",body:JSON.stringify({body:t})})}async function y(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/proposals/".concat(encodeURIComponent(e),"/accept"),{method:"POST",body:"{}"})}async function b(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:s;return n("/api/memory/proposals/".concat(encodeURIComponent(e),"/reject"),{method:"POST",body:JSON.stringify({...void 0!==t?{reason:t}:{}})})}},4723:(e,t,n)=>{"use strict";n.d(t,{KeikoDesktop:()=>iQ});var a=n(4568),l=n(7620);let s=(0,l.createContext)(null);function i(e){let{value:t,children:n}=e;return(0,a.jsx)(s.Provider,{value:t,children:n})}function r(){let e=(0,l.useContext)(s);if(null===e)throw Error("useChatSessionContext must be used inside ChatSessionProvider");return e}function o(){return(0,l.useContext)(s)}let c=[{id:"read",action:"Read files",scope:"workspace",decision:"allow"},{id:"write",action:"Write files",scope:"src/** \xb7 docs/**",decision:"allow"},{id:"write-prod",action:"Write files",scope:"prod/** \xb7 infra/**",decision:"deny"},{id:"command",action:"Run commands",scope:"test \xb7 build \xb7 lint",decision:"allow"},{id:"command-danger",action:"Run commands",scope:"deploy \xb7 rm \xb7 db",decision:"ask"},{id:"network",action:"Network / fetch",scope:"allowlist",decision:"ask"},{id:"pr",action:"Open pull request",scope:"feature branches",decision:"allow"},{id:"mail",action:"Mail / calendar",scope:"any",decision:"ask"}],d=["Prefers TypeScript + functional React","Writes Conventional Commits","Always reviews diffs before merge","Never touches infra without explicit ok","Deep-work mornings (CET), async afternoons"],u={calendar:!0,mail:!1,jira:!0,docs:!0},h="keiko.twin.mode",p="keiko.twin.persona",m="keiko.twin.policy",f="keiko.twin.memory",g="keiko.twin.bridges",v=(0,l.createContext)(null);function x(e,t){try{let n=window.localStorage.getItem(e);if(null===n)return t;let a=JSON.parse(n);return null==a?t:a}catch(e){return t}}function y(e,t){try{window.localStorage.setItem(e,t)}catch(e){}}function b(e,t){try{window.localStorage.setItem(e,JSON.stringify(t))}catch(e){}}function j(e){let{children:t}=e,[n,s]=(0,l.useState)("manual"),[i,r]=(0,l.useState)("Developer"),[o,j]=(0,l.useState)(c),[w,k]=(0,l.useState)(d),[N,S]=(0,l.useState)(u),[C,R]=(0,l.useState)(!1);(0,l.useEffect)(()=>{s(function(){try{let e=window.localStorage.getItem(h);return"manual"===e||"autonomous"===e?e:"manual"}catch(e){return"manual"}}()),r(function(){try{let e=window.localStorage.getItem(p);if("Developer"===e||"Product Owner"===e||"Designer"===e)return e;return"Developer"}catch(e){return"Developer"}}()),j(x(m,c)),k(x(f,d)),S(x(g,u)),R(!0)},[]),(0,l.useEffect)(()=>{C&&y(h,n)},[n,C]),(0,l.useEffect)(()=>{C&&y(p,i)},[i,C]),(0,l.useEffect)(()=>{C&&b(m,o)},[o,C]),(0,l.useEffect)(()=>{C&&b(f,w)},[w,C]),(0,l.useEffect)(()=>{C&&b(g,N)},[N,C]);let I=(0,l.useCallback)((e,t)=>(function(e,t,n){var a,l,s,i,r,o,c;let d=t=>{var n,a;return null!=(a=null==(n=e.find(e=>e.id===t))?void 0:n.decision)?a:null};return"write"===t?"high"===n?null!=(a=d("write-prod"))?a:"deny":null!=(l=d("write"))?l:"allow":"command"===t?"high"===n?null!=(s=d("command-danger"))?s:"ask":null!=(i=d("command"))?i:"allow":"git"===t?null!=(r=d("pr"))?r:"allow":"mail"===t?null!=(o=d("mail"))?o:"ask":"network"===t&&null!=(c=d("network"))?c:"ask"})(o,e,t),[o]),E=(0,l.useMemo)(()=>({mode:n,setMode:s,persona:i,setPersona:r,policy:o,setPolicy:j,memory:w,setMemory:k,bridges:N,setBridges:S,decide:I}),[n,i,o,w,N,I]);return(0,a.jsx)(v.Provider,{value:E,children:t})}function w(){let e=(0,l.useContext)(v);if(null===e)throw Error("useTwin must be used inside <TwinProvider>");return e}let k=(0,l.createContext)({wins:[],active:null,winCount:0});function N(e){let{size:t=18,sw:n=1.6,vb:l=24,fill:s,style:i,children:r,d:o}=e,c=void 0!==s;return(0,a.jsx)("svg",{width:t,height:t,viewBox:"0 0 ".concat(String(l)," ").concat(String(l)),fill:c?s:"none",stroke:c?"none":"currentColor",strokeWidth:n,strokeLinecap:"round",strokeLinejoin:"round",style:i,"aria-hidden":"true",children:void 0!==o?(0,a.jsx)("path",{d:o}):r})}let S={newChat:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("path",{d:"M4 5h10M4 9h7"}),(0,a.jsx)("path",{d:"M14.5 13.5l4-4a1.6 1.6 0 0 1 2.3 2.3l-6.2 6.2-3 .7.7-3 6.2-6.2"})]}),search:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"11",cy:"11",r:"6.5"}),(0,a.jsx)("path",{d:"M20 20l-4.3-4.3"})]}),plugins:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"4",y:"4",width:"6.5",height:"6.5",rx:"1.5"}),(0,a.jsx)("rect",{x:"13.5",y:"4",width:"6.5",height:"6.5",rx:"1.5"}),(0,a.jsx)("rect",{x:"4",y:"13.5",width:"6.5",height:"6.5",rx:"1.5"}),(0,a.jsx)("rect",{x:"13.5",y:"13.5",width:"6.5",height:"6.5",rx:"1.5"})]}),automations:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"12",cy:"12",r:"8"}),(0,a.jsx)("path",{d:"M12 7.5V12l3 2"})]}),mobile:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"7",y:"3",width:"10",height:"18",rx:"2.5"}),(0,a.jsx)("path",{d:"M11 18h2"})]}),folder:e=>(0,a.jsx)(N,{...e,d:"M3.5 7a2 2 0 0 1 2-2h3.2a2 2 0 0 1 1.4.6l1 1a2 2 0 0 0 1.4.6H18.5a2 2 0 0 1 2 2v6.2a2 2 0 0 1-2 2h-13a2 2 0 0 1-2-2V7Z"}),settings:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("path",{d:"M10.325 4.317c.426 -1.756 2.924 -1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543 -.94 3.31 .826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756 .426 1.756 2.924 0 3.35a1.724 1.724 0 0 0 -1.066 2.573c.94 1.543 -.826 3.31 -2.37 2.37a1.724 1.724 0 0 0 -2.572 1.065c-.426 1.756 -2.924 1.756 -3.35 0a1.724 1.724 0 0 0 -2.573 -1.066c-1.543 .94 -3.31 -.826 -2.37 -2.37a1.724 1.724 0 0 0 -1.065 -2.572c-1.756 -.426 -1.756 -2.924 0 -3.35a1.724 1.724 0 0 0 1.066 -2.573c-.94 -1.543 .826 -3.31 2.37 -2.37c1 .608 2.296 .07 2.572 -1.065z"}),(0,a.jsx)("circle",{cx:"12",cy:"12",r:"3"})]}),files:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("path",{d:"M13 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V9z"}),(0,a.jsx)("path",{d:"M13 3v6h6"})]}),browser:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"12",cy:"12",r:"8.5"}),(0,a.jsx)("path",{d:"M3.5 12h17M12 3.5c2.3 2.3 2.3 14.7 0 17M12 3.5c-2.3 2.3-2.3 14.7 0 17"})]}),review:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("path",{d:"M9 12l2 2 4-4"}),(0,a.jsx)("rect",{x:"3.5",y:"4.5",width:"17",height:"15",rx:"2.5"})]}),terminal:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"3.5",y:"4.5",width:"17",height:"15",rx:"2.5"}),(0,a.jsx)("path",{d:"M7.5 9l3 3-3 3M13 15h4"})]}),agents:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"5",y:"7",width:"14",height:"11",rx:"3"}),(0,a.jsx)("path",{d:"M12 7V4M9 12h.01M15 12h.01M2.5 12.5v2M21.5 12.5v2"})]}),git:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"6",cy:"6",r:"2.5"}),(0,a.jsx)("circle",{cx:"6",cy:"18",r:"2.5"}),(0,a.jsx)("circle",{cx:"17",cy:"9",r:"2.5"}),(0,a.jsx)("path",{d:"M6 8.5v7M17 11.5c0 3-3 3.5-6 4"})]}),plus:e=>(0,a.jsx)(N,{...e,d:"M12 5v14M5 12h14"}),chevron:e=>(0,a.jsx)(N,{...e,d:"M6 9l6 6 6-6"}),chevronR:e=>(0,a.jsx)(N,{...e,d:"M9 6l6 6-6 6"}),mic:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"9",y:"3",width:"6",height:"11",rx:"3"}),(0,a.jsx)("path",{d:"M5.5 11.5a6.5 6.5 0 0 0 13 0M12 18v3"})]}),arrowUp:e=>(0,a.jsx)(N,{...e,d:"M12 19V5M6 11l6-6 6 6"}),spark:e=>(0,a.jsx)(N,{...e,d:"M12 3l1.8 5.6L19 10l-5.2 1.4L12 17l-1.8-5.6L5 10l5.2-1.4z"}),pin:e=>(0,a.jsx)(N,{...e,d:"M9 3h6l-1 5 3 3-5 1-1 8-1-8-5-1 3-3z"}),brain:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("path",{d:"M9.5 2A2.5 2.5 0 0 1 12 4.5v15a2.5 2.5 0 0 1-4.96.44 2.5 2.5 0 0 1-2.96-3.08 3 3 0 0 1-.34-5.58 2.5 2.5 0 0 1 1.32-4.24 2.5 2.5 0 0 1 1.98-3A2.5 2.5 0 0 1 9.5 2Z"}),(0,a.jsx)("path",{d:"M14.5 2A2.5 2.5 0 0 0 12 4.5v15a2.5 2.5 0 0 0 4.96.44 2.5 2.5 0 0 0 2.96-3.08 3 3 0 0 0 .34-5.58 2.5 2.5 0 0 0-1.32-4.24 2.5 2.5 0 0 0-1.98-3A2.5 2.5 0 0 0 14.5 2Z"})]}),archive:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"3.5",y:"5",width:"17",height:"4",rx:"1"}),(0,a.jsx)("path",{d:"M5 9v8a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V9M10 13h4"})]}),sidebar:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"3.5",y:"4.5",width:"17",height:"15",rx:"2.5"}),(0,a.jsx)("path",{d:"M9.5 4.5v15"})]}),minimize:e=>(0,a.jsx)(N,{...e,d:"M5 12h14"}),expand:e=>(0,a.jsx)(N,{...e,d:"M4 9V4h5M20 15v5h-5M20 9V4h-5M4 15v5h5"}),back:e=>(0,a.jsx)(N,{...e,d:"M15 6l-6 6 6 6"}),fwd:e=>(0,a.jsx)(N,{...e,d:"M9 6l6 6-6 6"}),drag:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"9",cy:"6",r:"1.1",fill:"currentColor",stroke:"none"}),(0,a.jsx)("circle",{cx:"15",cy:"6",r:"1.1",fill:"currentColor",stroke:"none"}),(0,a.jsx)("circle",{cx:"9",cy:"12",r:"1.1",fill:"currentColor",stroke:"none"}),(0,a.jsx)("circle",{cx:"15",cy:"12",r:"1.1",fill:"currentColor",stroke:"none"}),(0,a.jsx)("circle",{cx:"9",cy:"18",r:"1.1",fill:"currentColor",stroke:"none"}),(0,a.jsx)("circle",{cx:"15",cy:"18",r:"1.1",fill:"currentColor",stroke:"none"})]}),close:e=>(0,a.jsx)(N,{...e,d:"M6 6l12 12M18 6L6 18"}),dots:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"6",cy:"12",r:"1.3",fill:"currentColor",stroke:"none"}),(0,a.jsx)("circle",{cx:"12",cy:"12",r:"1.3",fill:"currentColor",stroke:"none"}),(0,a.jsx)("circle",{cx:"18",cy:"12",r:"1.3",fill:"currentColor",stroke:"none"})]}),check:e=>(0,a.jsx)(N,{...e,d:"M5 12.5l4.5 4.5L19 6.5"}),reset:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("path",{d:"M4 12a8 8 0 1 1 2.3 5.6"}),(0,a.jsx)("path",{d:"M4 20v-4h4"})]}),file:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("path",{d:"M13 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V9z"}),(0,a.jsx)("path",{d:"M13 3v6h6"})]}),diff:e=>(0,a.jsx)(N,{...e,d:"M12 4v6M9 7h6M5 17h14"}),branch:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"6",cy:"6",r:"2.3"}),(0,a.jsx)("circle",{cx:"6",cy:"18",r:"2.3"}),(0,a.jsx)("circle",{cx:"18",cy:"8",r:"2.3"}),(0,a.jsx)("path",{d:"M6 8.3v7.4M18 10.3c0 4-4 3.7-7 4.7"})]}),cube:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("path",{d:"M12 3l8 4.5v9L12 21l-8-4.5v-9z"}),(0,a.jsx)("path",{d:"M12 12l8-4.5M12 12v9M12 12L4 7.5"})]}),maximize:e=>(0,a.jsx)(N,{...e,children:(0,a.jsx)("rect",{x:"5",y:"5",width:"14",height:"14",rx:"2.5"})}),restore:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"8",y:"8",width:"11",height:"11",rx:"2"}),(0,a.jsx)("path",{d:"M5 15V7a2 2 0 0 1 2-2h8"})]}),split:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"3.5",y:"4.5",width:"17",height:"15",rx:"2.5"}),(0,a.jsx)("path",{d:"M12 4.5v15"})]}),tile:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"3.5",y:"4.5",width:"7",height:"7",rx:"1.5"}),(0,a.jsx)("rect",{x:"13.5",y:"4.5",width:"7",height:"7",rx:"1.5"}),(0,a.jsx)("rect",{x:"3.5",y:"13.5",width:"7",height:"7",rx:"1.5"}),(0,a.jsx)("rect",{x:"13.5",y:"13.5",width:"7",height:"7",rx:"1.5"})]}),cascade:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"4",y:"4",width:"12",height:"12",rx:"2"}),(0,a.jsx)("path",{d:"M20 8v10a2 2 0 0 1-2 2H8"})]}),editor:e=>(0,a.jsx)(N,{...e,children:(0,a.jsx)("path",{d:"M8 9l-3 3 3 3M16 9l3 3-3 3M13.5 6l-3 12"})}),gear:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"12",cy:"12",r:"2.6"}),(0,a.jsx)("path",{d:"M12 3.5v2M12 18.5v2M20.5 12h-2M5.5 12h-2M18 6l-1.4 1.4M7.4 16.6 6 18M18 18l-1.4-1.4M7.4 7.4 6 6"})]}),panelRight:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"3.5",y:"4.5",width:"17",height:"15",rx:"2.5"}),(0,a.jsx)("path",{d:"M14.5 4.5v15"})]}),layers:e=>(0,a.jsx)(N,{...e,d:"M12 3l8 4.5-8 4.5-8-4.5z M4 12l8 4.5 8-4.5 M4 16.5 12 21l8-4.5"}),tokens:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"9",cy:"9",r:"4.5"}),(0,a.jsx)("path",{d:"M14 9.5a4.5 4.5 0 1 1-4 6.9"})]}),bolt:e=>(0,a.jsx)(N,{...e,d:"M13 3 5 13h5l-1 8 8-10h-5z"}),add:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("rect",{x:"3.5",y:"3.5",width:"17",height:"17",rx:"3.5"}),(0,a.jsx)("path",{d:"M12 8.5v7M8.5 12h7"})]}),bell:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("path",{d:"M6.5 9a5.5 5.5 0 0 1 11 0c0 4.5 2 5.5 2 5.5H4.5s2-1 2-5.5"}),(0,a.jsx)("path",{d:"M10 19a2 2 0 0 0 4 0"})]}),sun:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,a.jsx)("path",{d:"M12 2.5v2.5M12 19v2.5M2.5 12H5M19 12h2.5M5.1 5.1 6.9 6.9M17.1 17.1l1.8 1.8M18.9 5.1 17.1 6.9M6.9 17.1 5.1 18.9"})]}),moon:e=>(0,a.jsx)(N,{...e,d:"M20 13.5A8 8 0 1 1 10.5 4a6.5 6.5 0 0 0 9.5 9.5z"}),zoomOut:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"11",cy:"11",r:"6.5"}),(0,a.jsx)("path",{d:"M20 20l-4.2-4.2M8.3 11h5.4"})]}),zoomIn:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("circle",{cx:"11",cy:"11",r:"6.5"}),(0,a.jsx)("path",{d:"M20 20l-4.2-4.2M11 8.3v5.4M8.3 11h5.4"})]}),activity:e=>(0,a.jsx)(N,{...e,d:"M3 12h3l2.5-7 5 14 2.5-7H21"}),localKnowledge:e=>(0,a.jsxs)(N,{...e,children:[(0,a.jsx)("path",{d:"M4 19V7a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12"}),(0,a.jsx)("path",{d:"M4 19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2"}),(0,a.jsx)("path",{d:"M9 7v14M9 11h6"})]})};function C(e){let{winCount:t,mode:n,selectedModel:l,projectName:s,branchLabel:i,shellStatusLabel:r,evidenceStatusLabel:o,statusRef:c}=e;return(0,a.jsxs)("footer",{ref:c,className:"footer mono",tabIndex:-1,"aria-label":"Workspace status","aria-live":"polite",children:[(0,a.jsxs)("span",{className:"ft-seg ft-gov","data-mode":n,children:["autonomous"===n?(0,a.jsx)("img",{className:"ft-orca",src:"/assets/keiko-logo.svg",alt:""}):(0,a.jsx)("span",{className:"ft-you",children:"M"}),"autonomous"===n?"Keiko governing":"You \xb7 manual"]}),(0,a.jsxs)("span",{className:"ft-seg ft-opt2",children:[(0,a.jsx)(S.folder,{size:13})," ",s]}),(0,a.jsxs)("span",{className:"ft-seg",children:[(0,a.jsx)(S.branch,{size:13})," ",i]}),(0,a.jsxs)("span",{className:"ft-seg ft-opt2",children:[(0,a.jsx)(S.cube,{size:13})," ",r]}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("span",{className:"ft-seg ft-accent",children:[(0,a.jsx)(S.tile,{size:13})," ",t," ",1===t?"window":"windows"]}),(0,a.jsxs)("span",{className:"ft-seg ft-opt2",children:[(0,a.jsx)(S.bolt,{size:13,style:{color:"var(--accent)"}})," ",null!=l?l:"No model selected"]}),(0,a.jsxs)("span",{className:"ft-seg ft-accent",children:[(0,a.jsx)(S.review,{size:13})," ",o]})]})}let R=[{id:"finder",name:"Finder",tile:"finder"},{id:"terminal",name:"Terminal",tile:"terminal"},{id:"vscode",name:"VS Code",img:"/assets/editors/vscode.svg"},{id:"intellij",name:"IntelliJ IDEA",img:"/assets/editors/intellij.svg"},{id:"goland",name:"GoLand",img:"/assets/editors/goland.svg"},{id:"rustrover",name:"RustRover",img:"/assets/editors/rustrover.svg"},{id:"pycharm",name:"PyCharm",img:"/assets/editors/pycharm.svg"},{id:"webstorm",name:"WebStorm",img:"/assets/editors/webstorm.svg"}],I="keiko.editor",E="intellij";function M(){try{var e;return null!=(e=window.localStorage.getItem(I))?e:E}catch(e){return E}}function T(e){let{ed:t,size:n=20}=e;if(void 0!==t.img)return(0,a.jsx)("img",{className:"ed-img",src:t.img,width:n,height:n,alt:""});let l=Math.round(.27*n);return"terminal"===t.tile?(0,a.jsx)("span",{className:"ed-tile",style:{width:n,height:n,borderRadius:l,background:"#2a2c33"},children:(0,a.jsx)("span",{className:"ed-mark mono",style:{color:"#4ee08d",fontSize:.42*n},children:">_"})}):(0,a.jsx)("span",{className:"ed-tile",style:{width:n,height:n,borderRadius:l,background:"linear-gradient(180deg,#36c4ff,#1e7cf0)"},children:(0,a.jsx)(S.folder,{size:.56*n,style:{color:"#fff"}})})}function q(e){var t;let{project:n}=e,[s,i]=(0,l.useState)(!1),[r,o]=(0,l.useState)(M),c=null!=(t=R.find(e=>e.id===r))?t:R[3],d="Open in ".concat(c.name),u="Open ".concat(n," in ").concat(c.name);return(0,l.useEffect)(()=>{try{window.localStorage.setItem(I,r)}catch(e){}},[r]),(0,a.jsxs)("div",{className:"edm",children:[(0,a.jsxs)("button",{type:"button",className:"edm-trigger",onClick:()=>i(e=>!e),title:u,"aria-label":u,"aria-haspopup":"menu","aria-expanded":s,children:[(0,a.jsx)(T,{ed:c,size:20}),(0,a.jsx)("span",{className:"edm-trigger-label",children:d}),(0,a.jsx)(S.chevron,{size:13,style:{color:"var(--fg-faint)"}})]}),s?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"edm-backdrop",onClick:()=>i(!1),"aria-hidden":"true",role:"presentation"}),(0,a.jsxs)("div",{className:"edm-menu",role:"menu",children:[(0,a.jsxs)("div",{className:"edm-head mono",children:["Open “",n,"” in…"]}),R.map(e=>(0,a.jsxs)("button",{type:"button",className:"edm-item","data-sel":e.id===r,onClick:()=>{o(e.id),i(!1)},role:"menuitemradio","aria-checked":e.id===r,children:[(0,a.jsx)(T,{ed:e,size:24}),(0,a.jsx)("span",{className:"edm-name",children:e.name}),e.id===r?(0,a.jsx)(S.check,{size:14,style:{color:"var(--accent)"}}):null]},e.id))]})]}):null]})}function P(e){let{mode:t,onChange:n}=e;return(0,a.jsxs)("div",{className:"modesw","data-mode":t,role:"group","aria-label":"Agent mode",children:[(0,a.jsxs)("button",{type:"button",className:"modesw-opt","data-on":"manual"===t,"aria-pressed":"manual"===t,onClick:()=>n("manual"),title:"You approve every privileged action",children:[(0,a.jsx)("span",{className:"modesw-av","aria-hidden":"true",children:"M"})," ","You"]}),(0,a.jsxs)("button",{type:"button",className:"modesw-opt","data-on":"autonomous"===t,"aria-pressed":"autonomous"===t,onClick:()=>n("autonomous"),title:"Keiko governs agents per your policy",children:[(0,a.jsx)("img",{className:"modesw-orca",src:"/assets/keiko-logo.svg",alt:""})," Keiko"]})]})}function A(e){let{mode:t,projectName:n,onModeChange:l,openPalette:s,onTileAll:i,onSplitFront:r,onCascade:o}=e;return(0,a.jsxs)("header",{className:"header",children:[(0,a.jsxs)("div",{className:"hd-brand",children:[(0,a.jsx)("img",{className:"hd-logo",src:"/assets/keiko-logo.svg",alt:"Keiko"}),(0,a.jsx)("span",{className:"hd-wordmark",children:"Keiko"})]}),(0,a.jsxs)("div",{className:"tb-tabs",children:[(0,a.jsxs)("div",{className:"tb-tab","data-active":"true",children:[(0,a.jsx)("span",{children:n}),(0,a.jsx)(S.chevron,{size:13,style:{color:"var(--fg-faint)"}})]}),(0,a.jsx)("button",{type:"button",className:"tb-newtab","aria-label":"New tab",children:(0,a.jsx)(S.plus,{size:15})})]}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("div",{className:"hd-tools",children:[(0,a.jsxs)("button",{type:"button",className:"hd-tool hd-tool-cta",onClick:s,title:"New window",children:[(0,a.jsx)(S.add,{size:16}),(0,a.jsx)("span",{children:"New"})]}),(0,a.jsx)("span",{className:"hd-div"}),(0,a.jsx)(q,{project:n}),(0,a.jsx)("span",{className:"hd-div"}),(0,a.jsx)("button",{type:"button",className:"hd-tool",onClick:i,title:"Tile all windows","aria-label":"Tile all windows",children:(0,a.jsx)(S.tile,{size:16})}),(0,a.jsx)("button",{type:"button",className:"hd-tool",onClick:r,title:"Split the two front windows","aria-label":"Split the two front windows",children:(0,a.jsx)(S.split,{size:16})}),(0,a.jsx)("button",{type:"button",className:"hd-tool",onClick:o,title:"Cascade windows","aria-label":"Cascade windows",children:(0,a.jsx)(S.cascade,{size:16})})]}),(0,a.jsx)("span",{className:"hd-div"}),(0,a.jsx)(P,{mode:t,onChange:l}),(0,a.jsxs)("div",{className:"tb-status mono",children:[(0,a.jsx)("span",{className:"dot",style:{background:"var(--ok)"}})," connected"]}),(0,a.jsx)("button",{type:"button",className:"tb-btn","aria-label":"Expand window",children:(0,a.jsx)(S.expand,{size:15})}),(0,a.jsx)("button",{type:"button",className:"tb-btn","aria-label":"Minimize window",children:(0,a.jsx)(S.minimize,{size:16})})]})}var z=n(9664),D=n.n(z);let L=[{id:"keiko",icon:"spark",label:"Keiko",img:"/assets/keiko-logo.svg"},{id:"project",icon:"folder",label:"Project"},{id:"search",icon:"search",label:"Search"},{id:"plugins",icon:"plugins",label:"Plugins"}],F=[{id:"automations",icon:"automations",label:"Automations"},{id:"mobile",icon:"mobile",label:"Keiko mobile"}];function O(e){let{tool:t,active:n,onClick:l}=e,s=S[t.icon];return(0,a.jsx)("button",{type:"button",className:"rail-btn","data-active":n?"true":"false","data-side":"left","aria-label":t.label,"aria-pressed":n,title:t.label,onClick:l,children:void 0!==t.img?(0,a.jsx)("img",{className:"rail-img",src:t.img,alt:""}):(0,a.jsx)(s,{size:19})})}function K(e){let{openTools:t,onTool:n,onNewChat:l,theme:s,onToggleTheme:i}=e;return(0,a.jsxs)("nav",{className:"rail rail-left","aria-label":"Primary workspace navigation",children:[(0,a.jsx)("button",{type:"button",className:"rail-new",onClick:l,"data-side":"left","aria-label":"New chat",title:"New chat",children:(0,a.jsx)(S.newChat,{size:18})}),(0,a.jsx)("div",{className:"rail-div"}),(0,a.jsx)("div",{className:"rail-group",children:L.map(e=>(0,a.jsx)(O,{tool:e,active:t.has(e.id),onClick:()=>n(e.id)},e.id))}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("div",{className:"rail-group",children:[F.map(e=>(0,a.jsx)(O,{tool:e,active:t.has(e.id),onClick:()=>n(e.id)},e.id)),(0,a.jsx)(D(),{href:"/memoriaviva",className:"rail-btn","data-active":"false","data-side":"left","aria-label":"MemoriaViva",title:"MemoriaViva",children:(0,a.jsx)(S.brain,{size:19})}),(0,a.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("quality")?"true":"false","aria-label":"Quality Intelligence","aria-pressed":t.has("quality"),title:"Quality Intelligence",onClick:()=>n("quality"),children:(0,a.jsx)(S.check,{size:19})}),(0,a.jsx)(D(),{href:"/local-knowledge",className:"rail-btn","data-active":"false","data-side":"left","aria-label":"Local Knowledge",title:"Local Knowledge",children:(0,a.jsx)(S.localKnowledge,{size:19})}),(0,a.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("relationships")?"true":"false","aria-label":"Relationships","aria-pressed":t.has("relationships"),title:"Relationships",onClick:()=>n("relationships"),children:(0,a.jsx)(S.branch,{size:19})})]}),(0,a.jsx)("div",{className:"rail-div"}),(0,a.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","aria-label":"light"===s?"Dark mode":"Light mode",title:"light"===s?"Dark mode":"Light mode",onClick:i,children:"light"===s?(0,a.jsx)(S.moon,{size:19}):(0,a.jsx)(S.sun,{size:19})}),(0,a.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("settings")?"true":"false","aria-label":"Settings","aria-pressed":t.has("settings"),title:"Settings",onClick:()=>n("settings"),children:(0,a.jsx)(S.settings,{size:19})}),(0,a.jsx)("button",{type:"button",className:"rail-avatar","data-side":"left","aria-label":"Account",title:"Account",children:"M"})]})}let B=[{id:"inspector",label:"Inspector",icon:"layers"},{id:"activity",label:"Activity",icon:"activity"},{id:"notifications",label:"Notifications",icon:"bell"},{id:"resources",label:"Resources",icon:"cube"}];function W(e){let{openTools:t,onTool:n}=e;return(0,a.jsx)("aside",{className:"rail rail-right","aria-label":"Workspace utilities",children:(0,a.jsx)("div",{className:"rail-group",children:B.map(e=>{let l=S[e.icon];return(0,a.jsx)("button",{type:"button",className:"rail-btn","data-active":t.has(e.id),"data-side":"right","data-tip":e.label,"aria-label":e.label,"aria-pressed":t.has(e.id),onClick:()=>n(e.id),children:(0,a.jsx)(l,{size:19})},e.id)})})})}function U(e,t,n){let a=e.createShader(t);return null===a?null:(e.shaderSource(a,n),e.compileShader(a),e.getShaderParameter(a,e.COMPILE_STATUS))?a:(console.warn("[keiko-shader]",e.getShaderInfoLog(a)),e.deleteShader(a),null)}function _(){let e=window.localStorage.getItem("keiko.wallpaper.opacity");if(null===e)return 1;let t=Number.parseInt(e,10);return Number.isFinite(t)?Math.max(0,Math.min(100,t))/100:1}function H(){let e=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let t=e.current;if(null===t)return;let n=t.parentElement;if(null!==n&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches)return function(e,t){var n;t.style.opacity=String(_());let a=e=>{let n=e.detail,a="number"==typeof n?n:100*_();t.style.opacity=String(Math.max(0,Math.min(100,a))/100)};window.addEventListener("keiko:wallpaper-opacity",a);let l=null;try{l=t.getContext("webgl",{antialias:!1,alpha:!1,premultipliedAlpha:!1,depth:!1})}catch(e){l=null}if(null===l)return()=>{window.removeEventListener("keiko:wallpaper-opacity",a)};let s=U(l,l.VERTEX_SHADER,"\nattribute vec2 aPos;\nvoid main(){ gl_Position = vec4(aPos, 0.0, 1.0); }\n"),i=U(l,l.FRAGMENT_SHADER,"\nprecision highp float;\nuniform vec2 uRes;\nuniform float uTime;\nuniform vec2 uMouse; // 0..1, y up\nuniform float uDark; // 1 = dark theme, 0 = light\nuniform vec2 uRip[4]; // ripple origins (0..1, y up)\nuniform float uRipT[4]; // seconds since each ripple fired (large = inactive)\n\nfloat hash(vec2 p){\n p = fract(p * vec2(123.34, 456.21));\n p += dot(p, p + 45.32);\n return fract(p.x * p.y);\n}\nfloat vnoise(vec2 p){\n vec2 i = floor(p), f = fract(p);\n vec2 u = f * f * (3.0 - 2.0 * f);\n float a = hash(i), b = hash(i + vec2(1.,0.));\n float c = hash(i + vec2(0.,1.)), d = hash(i + vec2(1.,1.));\n return mix(mix(a,b,u.x), mix(c,d,u.x), u.y);\n}\nfloat fbm(vec2 p){\n float v = 0.0, a = 0.5;\n mat2 m = mat2(1.6, 1.2, -1.2, 1.6);\n for(int i = 0; i < 5; i++){ v += a * vnoise(p); p = m * p; a *= 0.5; }\n return v;\n}\n\nvoid main(){\n vec2 uv = gl_FragCoord.xy / uRes.xy;\n float aspect = uRes.x / uRes.y;\n vec2 p = vec2(uv.x * aspect, uv.y);\n vec2 m = vec2(uMouse.x * aspect, uMouse.y);\n\n float t = uTime * 0.06;\n\n // --- click ripples ---------------------------------------------------\n float rip = 0.0;\n for(int i = 0; i < 4; i++){\n float age = uRipT[i];\n if(age < 2.4){\n vec2 rc = vec2(uRip[i].x * aspect, uRip[i].y);\n float d = distance(p, rc);\n float ring = sin(d * 15.0 - age * 9.0);\n float env = exp(-d * 3.6) * exp(-age * 2.1);\n rip += ring * env;\n }\n }\n\n // --- liquid domain warp ---------------------------------------------\n vec2 warp = vec2(\n fbm(p * 2.1 + vec2(0.0, t)),\n fbm(p * 2.1 + vec2(t, 4.7))\n );\n // mouse bends the flow toward the cursor\n vec2 toM = m - p;\n float md = exp(-length(toM) * 2.2);\n warp += toM * md * 0.28;\n warp += rip * 0.07;\n\n float f = fbm(p * 2.4 + warp * 1.7 + vec2(t * 0.6, 0.0));\n\n // --- chrome banding (sharp metallic streaks) ------------------------\n float bands = abs(sin((f * 4.0 + warp.x * 2.0) * 3.14159 + t * 1.4));\n float chrome = pow(bands, 2.6);\n\n // --- palette (brand) -------------------------------------------------\n vec3 baseD = vec3(0.072, 0.085, 0.079); // warm near-black ~ --bg\n vec3 metalD = vec3(0.205, 0.230, 0.216); // chrome mid grey\n vec3 baseL = vec3(0.930, 0.942, 0.935); // near-white\n vec3 metalL = vec3(0.795, 0.835, 0.812); // soft grey\n vec3 green = vec3(0.306, 0.729, 0.529); // #4EBA87\n\n vec3 base = mix(baseL, baseD, uDark);\n vec3 metal = mix(metalL, metalD, uDark);\n\n vec3 col = mix(base, metal, chrome * 0.85);\n\n // orca-green sheen on the brightest specular ridges\n float spec = smoothstep(0.80, 1.0, bands);\n col += green * spec * mix(0.085, 0.16, uDark);\n\n // soft green glow trailing the cursor — fun to fidget with\n col += green * md * 0.085;\n\n // ripple highlight\n vec3 ripCol = mix(green, vec3(1.0), uDark);\n col += ripCol * max(rip, 0.0) * 0.032;\n\n // keep it dezent — pull back toward base\n col = mix(base, col, 0.84);\n\n gl_FragColor = vec4(col, 1.0);\n}\n");if(null===s||null===i)return()=>{window.removeEventListener("keiko:wallpaper-opacity",a)};let r=l.createProgram();if(null===r)return()=>{window.removeEventListener("keiko:wallpaper-opacity",a)};if(l.attachShader(r,s),l.attachShader(r,i),l.linkProgram(r),!l.getProgramParameter(r,l.LINK_STATUS))return console.warn("[keiko-shader]",l.getProgramInfoLog(r)),()=>{window.removeEventListener("keiko:wallpaper-opacity",a)};l.useProgram(r);let o=l.createBuffer();l.bindBuffer(l.ARRAY_BUFFER,o),l.bufferData(l.ARRAY_BUFFER,new Float32Array([-1,-1,3,-1,-1,3]),l.STATIC_DRAW);let c=l.getAttribLocation(r,"aPos");l.enableVertexAttribArray(c),l.vertexAttribPointer(c,2,l.FLOAT,!1,0,0);let d=l.getUniformLocation(r,"uRes"),u=l.getUniformLocation(r,"uTime"),h=l.getUniformLocation(r,"uMouse"),p=l.getUniformLocation(r,"uDark"),m=l.getUniformLocation(r,"uRip"),f=l.getUniformLocation(r,"uRipT"),g=1,v=1,x=Math.min(null!=(n=window.devicePixelRatio)?n:1,1.5),y={tx:.5,ty:.5,x:.5,y:.5},b=new Float32Array(8),j=[,,,,].fill(-1/0),w=0;function k(){let n=e.getBoundingClientRect();g=Math.max(1,Math.round(n.width)),v=Math.max(1,Math.round(n.height)),t.width=Math.round(g*x),t.height=Math.round(v*x),t.style.width="".concat(String(g),"px"),t.style.height="".concat(String(v),"px"),null!==l&&l.viewport(0,0,t.width,t.height)}k();let N="undefined"!=typeof ResizeObserver?new ResizeObserver(k):null;null!==N?N.observe(e):window.addEventListener("resize",k);let S=t=>{let n=e.getBoundingClientRect();y.tx=(t.clientX-n.left)/Math.max(1,n.width),y.ty=1-(t.clientY-n.top)/Math.max(1,n.height)},C=t=>{let n=e.getBoundingClientRect(),a=(t.clientX-n.left)/Math.max(1,n.width),l=1-(t.clientY-n.top)/Math.max(1,n.height);a<0||a>1||l<0||l>1||(b[2*w]=a,b[2*w+1]=l,j[w]=performance.now(),w=(w+1)%4)};e.addEventListener("pointermove",S),e.addEventListener("pointerdown",C);let R=performance.now(),I=0,E=!0,M=new Float32Array(4);function T(){if(!E)return;let e=performance.now();y.x+=(y.tx-y.x)*.06,y.y+=(y.ty-y.y)*.06;for(let t=0;t<4;t++){var n;M[t]=(e-(null!=(n=j[t])?n:-1/0))/1e3}let a=+("light"!==document.documentElement.dataset.theme);null!==l&&(l.uniform2f(d,t.width,t.height),l.uniform1f(u,(e-R)/1e3),l.uniform2f(h,y.x,y.y),l.uniform1f(p,a),l.uniform2fv(m,b),l.uniform1fv(f,M),l.drawArrays(l.TRIANGLES,0,3)),I=requestAnimationFrame(T)}I=requestAnimationFrame(T);let q=()=>{document.hidden?(E=!1,cancelAnimationFrame(I)):E||(E=!0,I=requestAnimationFrame(T))};return document.addEventListener("visibilitychange",q),()=>{if(E=!1,cancelAnimationFrame(I),document.removeEventListener("visibilitychange",q),window.removeEventListener("keiko:wallpaper-opacity",a),e.removeEventListener("pointermove",S),e.removeEventListener("pointerdown",C),null!==N?N.disconnect():window.removeEventListener("resize",k),null!==l){let e=l.getExtension("WEBGL_lose_context");null!==e&&e.loseContext()}}}(n,t)},[]),(0,a.jsx)("canvas",{ref:e,className:"ws-shader","aria-hidden":"true"})}let J={agents:["files","terminal","plugins","review","browser","agents","keiko"],chat:["files","browser","plugins","keiko","connector"],files:["agents","chat","quality"],terminal:["agents"],plugins:["agents","chat"],review:["agents"],browser:["agents","chat"],keiko:["agents","chat"],connector:["chat","quality"],quality:["files","connector","figma"],figma:["quality"]};function V(e,t){var n,a;return void 0!==e&&void 0!==t&&e!==t&&((null!=(n=J[e])?n:[]).includes(t)||(null!=(a=J[t])?a:[]).includes(e))}function G(e){return{left:{x:e.x,y:e.y,w:e.w/2,h:e.h},right:{x:e.x+e.w/2,y:e.y,w:e.w/2,h:e.h},maxi:{x:e.x,y:e.y,w:e.w,h:e.h},tl:{x:e.x,y:e.y,w:e.w/2,h:e.h/2},tr:{x:e.x+e.w/2,y:e.y,w:e.w/2,h:e.h/2},bl:{x:e.x,y:e.y+e.h/2,w:e.w/2,h:e.h/2},br:{x:e.x+e.w/2,y:e.y+e.h/2,w:e.w/2,h:e.h/2}}}let X=new Set(["files","connector","browser","plugins","agents","quality"]);function Y(e,t){return e>=4||t>=8192}function Z(e){let{pathId:t,intensity:n}=e,l="heavy"===n?3:1,s="heavy"===n?1.1:2.2;return(0,a.jsx)(a.Fragment,{children:Array.from({length:l},(e,i)=>(0,a.jsx)("circle",{className:"conn-particle",r:"heavy"===n?3:2.4,"aria-hidden":"true",children:(0,a.jsx)("animateMotion",{dur:"".concat(String(s),"s"),repeatCount:"indefinite",begin:"".concat(String(s/l*i),"s"),rotate:"auto",keyPoints:"0;1",keyTimes:"0;1",calcMode:"linear",children:(0,a.jsx)("mpath",{href:"#".concat(t)})})},i))})}function Q(e){let{wins:t,conns:n,connecting:s,api:i}=e,r=o(),c=function(){let[e,t]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{let e=window.matchMedia("(prefers-reduced-motion: reduce)"),n=e=>t(e);n(e.matches);let a=e=>n(e.matches);return e.addEventListener("change",a),()=>e.removeEventListener("change",a)},[]),e}(),{flowing:d,intensity:u}=function(e,t){let[n,a]=(0,l.useState)("light"),[s,i]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{if(void 0===t)return;a(function(e){switch(e.groundingKind){case"connected-context":return Y(e.contextPack.usage.filesRead,e.contextPack.usage.excerptBytes)?"heavy":"light";case"hybrid":return Y(e.contextPack.folder.usage.filesRead,e.contextPack.folder.usage.excerptBytes)||e.contextPack.knowledge.referencesUsed>=4?"heavy":"light";case"local-knowledge":return e.contextPack.referencesUsed>=4?"heavy":"light";default:return"light"}}(t)),i(!0);let e=setTimeout(()=>i(!1),2500);return()=>clearTimeout(e)},[t]),{flowing:e||s,intensity:n}}((null==r?void 0:r.sending)===!0,null==r?void 0:r.latestGrounded),h=function(e,t){let n=new Map(e.map(e=>[e.id,e])),a=[];for(let e of t){let t=n.get(e.a),l=n.get(e.b);if(void 0===t||void 0===l)continue;let s=function(e,t){let n,a,l,s,i={x:e.x+e.w/2,y:e.y+e.h/2},r={x:t.x+t.w/2,y:t.y+t.h/2},o=r.x-i.x,c=r.y-i.y;if(Math.abs(o)>=Math.abs(c)){n=o>=0?{x:e.x+e.w,y:i.y}:{x:e.x,y:i.y};let c=Math.max(40,Math.abs((a=o>=0?{x:t.x,y:r.y}:{x:t.x+t.w,y:r.y}).x-n.x)/2),d=o>=0?1:-1;l={x:n.x+d*c,y:n.y},s={x:a.x-d*c,y:a.y}}else{n=c>=0?{x:i.x,y:e.y+e.h}:{x:i.x,y:e.y};let o=Math.max(40,Math.abs((a=c>=0?{x:r.x,y:t.y}:{x:r.x,y:t.y+t.h}).y-n.y)/2),d=c>=0?1:-1;l={x:n.x,y:n.y+d*o},s={x:a.x,y:a.y-d*o}}let d={x:(n.x+3*l.x+3*s.x+a.x)/8,y:(n.y+3*l.y+3*s.y+a.y)/8};return{d:"M".concat(String(n.x),",").concat(String(n.y)," C").concat(String(l.x),",").concat(String(l.y)," ").concat(String(s.x),",").concat(String(s.y)," ").concat(String(a.x),",").concat(String(a.y)),mid:d}}(t,l);a.push({c:e,d:s.d,mid:s.mid,label:function(e,t){let n="files"===e.type?e:"files"===t.type?t:null,a=null===n?null:n===e?t:e;if(null!==n&&null!==a&&("chat"===a.type||"agents"===a.type||"quality"===a.type))return"uses ".concat(function(e){if(void 0===e)return"src";let t=e.root;return"string"==typeof t&&t.length>0?t:"src"}(n.cfg),"/");let l=[e.type,t.type];return l.includes("connector")?"uses knowledge":l.includes("figma")?"uses snapshot":l.includes("keiko")?"governed by":"agents"===l[0]&&"agents"===l[1]?"delegates":l.includes("terminal")?"runs in":l.includes("plugins")?"tools":l.includes("review")?"reviews":l.includes("browser")?"browses":"linked"}(t,l),dataChannel:function(e,t){let n=[e.type,t.type].includes("chat"),a="chat"===e.type?X.has(t.type):X.has(e.type);return n&&a}(t,l)})}return a}(t,n),p=null!==s?function(e,t){let n=t.find(t=>t.id===e.from);if(void 0===n)return null;let a={x:n.x+n.w/2,y:n.y+n.h/2},l=e.x-a.x,s=e.y-a.y,i=Math.abs(l)>=Math.abs(s),r=i?{x:l>=0?n.x+n.w:n.x,y:a.y}:{x:a.x,y:s>=0?n.y+n.h:n.y},o=Math.max(40,Math.abs(i?l:s)/2),c=i?{x:r.x+(l>=0?o:-o),y:r.y}:{x:r.x,y:r.y+(s>=0?o:-o)},d=e.x,u=e.y;return{d:"M".concat(String(r.x),",").concat(String(r.y)," C").concat(String(c.x),",").concat(String(c.y)," ").concat(String(d),",").concat(String(u)," ").concat(String(d),",").concat(String(u)),ex:d,ey:u}}(s,t):null;return(0,a.jsxs)("div",{className:"conn-layer",children:[(0,a.jsxs)("svg",{className:"conn-svg",viewBox:"-10000 -10000 20000 20000",preserveAspectRatio:"xMidYMid meet",children:[h.map(e=>{let t=d&&e.dataChannel,n="conn-path-".concat(e.c.id);return(0,a.jsxs)("g",{children:[(0,a.jsx)("path",{id:n,className:"conn-path",d:e.d,"data-active":t?"true":void 0,"data-intensity":t?u:void 0,"data-reduced-motion":t&&c?"true":void 0}),t&&!c?(0,a.jsx)(Z,{pathId:n,intensity:u}):null]},e.c.id)}),null!==p?(0,a.jsx)("path",{className:"conn-path conn-temp",d:p.d}):null,null!==p?(0,a.jsx)("circle",{className:"conn-dot",cx:p.ex,cy:p.ey,r:"5"}):null]}),h.map(e=>{let t=d&&e.dataChannel;return(0,a.jsxs)("button",{type:"button",className:"conn-badge","data-active":t?"true":void 0,"data-intensity":t?u:void 0,style:{left:e.mid.x,top:e.mid.y},onClick:()=>i.removeConn(e.c.id),title:"Remove connection","aria-label":t?"".concat(e.label," — ").concat(u," data exchange in progress. Activate to remove connection."):"Remove connection: ".concat(e.label),children:[(0,a.jsx)(S.git,{size:11})," ",(0,a.jsx)("span",{children:e.label}),t?(0,a.jsx)("span",{className:"conn-flow-tag","aria-hidden":"true",children:"heavy"===u?"⇶":"→"}):null]},e.c.id)})]})}var $=n(2982);let ee={w:150,h:110},et={w:290,h:190},en={chat:{title:"Chat",icon:"newChat",accent:!0,desc:"Talk to Keiko",w:480,h:480,min:{w:300,h:260},config:[{key:"title",label:"Title",type:"text",def:"New chat",optional:!0,placeholder:"Name this conversation"}]},files:{title:"Files",icon:"files",accent:!0,desc:"Browse a folder",w:290,h:340,tiny:{w:200,h:150},config:[{key:"root",label:"Folder",type:"directory",def:""}]},editor:{title:"Editor",icon:"editor",desc:"Edit a file",w:480,h:360,config:[{key:"file",label:"File path",type:"text",def:"windows.jsx",placeholder:"path/to/file.jsx"}]},browser:{title:"Browser",icon:"browser",desc:"Open a URL",w:460,h:340,config:[{key:"url",label:"URL",type:"text",def:"localhost:5173",placeholder:"https://…"}]},terminal:{title:"Terminal",icon:"terminal",accent:!0,desc:"Run commands",w:460,h:250,tiny:{w:250,h:140},config:[{key:"projectPath",label:"Project path",type:"text",def:""},{key:"cwd",label:"Working directory",type:"directory",def:""}]},review:{title:"Review",icon:"review",desc:"Review a proposed diff",w:520,h:420,config:[{key:"runId",label:"Run ID",type:"text",def:"",optional:!0,placeholder:"e.g. r-2026-06-01-…"}]},agents:{title:"Agents",icon:"agents",desc:"Run a BFF workflow",w:520,h:560,tiny:{w:250,h:140},cta:"Start agent",config:[]},integ:{title:"Integrations",icon:"plugins",desc:"Connect apps",w:320,h:300,config:[{key:"provider",label:"Provider",type:"select",options:["GitHub","Linear","Slack","Sentry"],def:"GitHub"}]},keiko:{title:"Keiko",icon:"spark",desc:"Keiko twin",w:344,h:520,tool:!0,singleton:!0},settings:{title:"Settings",icon:"settings",desc:"Preferences",w:470,h:560,tool:!0,singleton:!0},project:{title:"Project",icon:"folder",desc:"Project tree",w:304,h:440,tool:!0,singleton:!0},search:{title:"Search",icon:"search",desc:"Search the workspace",w:320,h:500,tool:!0,singleton:!0},plugins:{title:"Plugins",icon:"plugins",desc:"Plugins & tools",w:320,h:470,tool:!0,singleton:!0},automations:{title:"Automations",icon:"automations",desc:"Workflow automations",w:320,h:300,tool:!0,singleton:!0},mobile:{title:"Keiko mobile",icon:"mobile",desc:"Mobile companion",w:300,h:380,tool:!0,singleton:!0},inspector:{title:"Inspector",icon:"layers",desc:"Inspect the workspace",w:290,h:440,tool:!0,singleton:!0},activity:{title:"Activity",icon:"activity",desc:"Activity timeline",w:322,h:460,tool:!0,singleton:!0},notifications:{title:"Notifications",icon:"bell",desc:"Notifications",w:300,h:360,tool:!0,singleton:!0},resources:{title:"Resources",icon:"cube",desc:"System resources",w:300,h:320,tool:!0,singleton:!0},connector:{title:"Connector",icon:"plugins",accent:!0,desc:"Pick a Local Knowledge connector",w:320,h:380,min:{w:280,h:300},config:[],cta:"Select connector"},quality:{title:"Quality Intelligence",icon:"check",accent:!0,desc:"Design & review test cases",w:384,h:580,min:{w:300,h:320},tiny:{w:260,h:200},tool:!0,singleton:!0},qiRun:{title:"QI Run",icon:"check",desc:"Generated test cases",w:760,h:660,min:{w:320,h:280},tiny:{w:280,h:200},config:[{key:"runId",label:"Run ID",type:"text",def:""}]},relationships:{title:"Relationships",icon:"branch",accent:!0,desc:"Inspect the relationship graph",w:760,h:600,min:{w:360,h:320},tiny:{w:300,h:220},tool:!0,singleton:!0},figma:{title:"Figma Snapshot",icon:"layers",accent:!0,desc:"Capture a Figma board snapshot",w:420,h:540,min:{w:320,h:360},tiny:{w:280,h:240}}},ea=new Map;function el(e,t){ea.set(e,t)}let es=function(){let e={};return Object.keys(en).forEach(t=>{e[t]=function(e,t){var n,a;let l={title:t.title,icon:t.icon,desc:t.desc,w:t.w,h:t.h,min:null!=(n=t.min)?n:ee,tiny:null!=(a=t.tiny)?a:et,render:(t,n)=>{let a=ea.get(e);return void 0!==a?a(t,n):null}},s={};return!0===t.accent&&(s.accent=!0),!0===t.tool&&(s.tool=!0),!0===t.singleton&&(s.singleton=!0),void 0!==t.config&&(s.config=t.config),void 0!==t.cta&&(s.cta=t.cta),{...l,...s}}(t,en[t])}),e}();function ei(e,t,n,a,l){return{x:e.x+Math.max(16,Math.min(l+26*a,e.w-t-16)),y:e.y+Math.max(16,Math.min(l+26*a,e.h-n-16))}}function er(e){let{prev:t,...n}=e;return n}function eo(e,t,n){return e.some(e=>e.a===t&&e.b===n||e.a===n&&e.b===t)}function ec(e){return e.length>0&&(e.startsWith("/")||/^[A-Za-z]:[/\\]/u.test(e))}function ed(e){if("files"!==e.type)return null;let t=e.cfg.resolvedRoot,n=e.cfg.root,a="string"==typeof t&&t.length>0?t:"string"==typeof n&&n.length>0?n:null;return null!==a&&ec(a)?a:null}function eu(e,t){let n="files"===e.type?e:"files"===t.type?t:null,a="chat"===e.type?e:"chat"===t.type?t:null;return null===n||null===a?null:ed(n)}function eh(e){var t;return null!=(t=e.connectedScopes)?t:void 0!==e.connectedScope?[e.connectedScope]:[]}function ep(e){var t;return null!=(t=e.localKnowledgeScopes)?t:void 0!==e.localKnowledgeScope?[e.localKnowledgeScope]:[]}function em(e){return"capsule"===e.kind?"capsule:".concat(e.capsuleId):"set:".concat(e.capsuleSetId)}function ef(e,t){let n="connector"===e.type?e:"connector"===t.type?t:null,a="chat"===e.type?e:"chat"===t.type?t:null;if(null===n||null===a)return null;let l=n.cfg.selectedKind,s=n.cfg.selectedId;return"string"!=typeof l||"string"!=typeof s||0===s.length?null:"capsule"===l?{kind:"capsule",capsuleId:s,connectedAtMs:Date.now()}:"capsule-set"===l?{kind:"capsule-set",capsuleSetId:s,connectedAtMs:Date.now()}:null}let eg={low:"Low",moderate:"Moderate",high:"High",exceeded:"Exceeded"},ev={low:"cmp-budget-badge cmp-budget-badge-low",moderate:"cmp-budget-badge cmp-budget-badge-moderate",high:"cmp-budget-badge cmp-budget-badge-high",exceeded:"cmp-budget-badge cmp-budget-badge-exceeded"};function ex(e,t){if(Number.isFinite(t)&&!(t<=0))return e/t}function ey(e){let t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return -1===n?t:t.slice(n+1)}function eb(e){let{chat:t,scope:n,index:s,allScopes:i,onDisconnect:r,updateScopes:o}=e,[c,d]=(0,l.useState)(!1),[u,h]=(0,l.useState)(null),p=function(e){var t,n;if("string"==typeof e.root&&e.root.length>0){let t=ey(e.root);return 0===t.length?"Connected folder":"Folder: ".concat(t)}if("workspace-root"===e.kind)return"Repository scope";if("directory"===e.kind){let n=ey(null!=(t=e.relativePaths[0])?t:"");return 0===n.length?"Connected folder":"Folder: ".concat(n)}if(1===e.relativePaths.length){let t=ey(null!=(n=e.relativePaths[0])?n:"");return 0===t.length?"Connected file":"File: ".concat(t)}return"".concat(String(e.relativePaths.length)," files connected")}(n);async function m(){if(!c){h(null),d(!0);try{let e=i.filter((e,t)=>t!==s),n=await o(t.id,e.length>0?e:null);null==r||r(n.chat)}catch(e){h(e instanceof $.hD?"".concat(e.code,": ").concat(e.message):e instanceof Error?e.message:"Unable to disconnect scope.")}finally{d(!1)}}}return(0,a.jsxs)("span",{className:"scope-pill-wrap",children:[(0,a.jsxs)("span",{className:"scope-pill",children:[(0,a.jsx)("span",{"aria-hidden":"true",children:"●"}),(0,a.jsx)("span",{role:"status","aria-live":"polite",children:p}),(0,a.jsx)("button",{type:"button",className:"scope-pill-disconnect",disabled:c,"aria-label":"Disconnect ".concat(p," from chat"),title:"Disconnect ".concat(p," from chat"),onClick:()=>{m()},children:(0,a.jsx)("span",{"aria-hidden":"true",children:"\xd7"})})]}),(0,a.jsx)("span",{className:"scope-pill-detail",children:function(e){let t="workspace-root"===e.kind?"the connected repository":"directory"===e.kind?"the connected folder":"the connected file scope";return"Keiko may inspect only ".concat(t,"; safe-read exclusions and context budget limits apply before each answer.")}(n)}),null!==u?(0,a.jsx)("span",{role:"alert",className:"scope-connect-error",children:u}):null]})}function ej(e){let{chat:t,onDisconnect:n,lastGroundedBudgetStatus:l,updateScopes:s=$.Mr}=e,i=eh(t);return 0===i.length?null:(0,a.jsxs)("span",{className:"scope-pill-group",children:[i.map((e,l)=>{var r;return(0,a.jsx)(eb,{chat:t,scope:e,index:l,allScopes:i,onDisconnect:n,updateScopes:s},"".concat(null!=(r=e.root)?r:e.kind,"-").concat(String(e.connectedAtMs),"-").concat(String(l)))}),void 0!==l?(0,a.jsx)("span",{className:"scope-pill-wrap",children:(0,a.jsxs)("span",{className:"scope-pill-detail",style:{display:"flex",gap:8,alignItems:"center",flexWrap:"wrap"},children:[(0,a.jsx)("span",{className:ev[l.pressure],children:l.label}),(0,a.jsx)("span",{children:l.summary})]})}):null]})}function ew(e){return"capsule"===e.kind?"capsule:".concat(e.capsuleId):"set:".concat(e.capsuleSetId)}function ek(e){let{chat:t,scope:n,allScopes:s,onDisconnect:i,updateScopes:r,labels:o}=e,[c,d]=(0,l.useState)(!1),[u,h]=(0,l.useState)(null),p=function(e,t){let n=ew(e),a=t.get(n);return void 0!==a&&a.length>0?a:"capsule"===e.kind?"Connector: ".concat(e.capsuleId):"Connector set: ".concat(e.capsuleSetId)}(n,o),m=ew(n);async function f(){if(!c){h(null),d(!0);try{let e=s.filter(e=>ew(e)!==m),n=await r(t.id,e.length>0?e:null);null==i||i(n.chat)}catch(e){h(e instanceof $.hD?"".concat(e.code,": ").concat(e.message):e instanceof Error?e.message:"Unable to disconnect connector.")}finally{d(!1)}}}return(0,a.jsxs)("span",{className:"scope-pill-wrap",children:[(0,a.jsxs)("span",{className:"scope-pill scope-pill--connector",children:[(0,a.jsx)("span",{"aria-hidden":"true",children:"◆"}),(0,a.jsx)("span",{role:"status","aria-live":"polite",children:p}),(0,a.jsx)("button",{type:"button",className:"scope-pill-disconnect",disabled:c,"aria-label":"Disconnect ".concat(p," from chat"),title:"Disconnect ".concat(p," from chat"),onClick:()=>{f()},children:(0,a.jsx)("span",{"aria-hidden":"true",children:"\xd7"})})]}),null!==u?(0,a.jsx)("span",{role:"alert",className:"scope-connect-error",children:u}):null]})}function eN(e){let{chat:t,onDisconnect:n,updateScopes:l=$.Cp,labels:s=new Map}=e,i=ep(t);return 0===i.length?null:(0,a.jsx)("span",{className:"scope-pill-group scope-pill-group--connector",children:i.map(e=>(0,a.jsx)(ek,{chat:t,scope:e,allScopes:i,onDisconnect:n,updateScopes:l,labels:s},ew(e)))})}let eS="cmp-budget-exceeded-alert",eC={low:"Low",moderate:"Moderate",high:"High",exceeded:"Exceeded"},eR={low:"cmp-budget-badge cmp-budget-badge-low",moderate:"cmp-budget-badge cmp-budget-badge-moderate",high:"cmp-budget-badge cmp-budget-badge-high",exceeded:"cmp-budget-badge cmp-budget-badge-exceeded"};function eI(e){return e>=1e3?"".concat((e/1e3).toFixed(1),"k"):e.toString()}function eE(e){let{budget:t,onClearHistory:n,disabled:l}=e;if(void 0===t||t.contextWindowTokens<=0)return null;let s=eI(t.approximateTokens),i=eI(t.contextWindowTokens),r=t.pressure,o="exceeded"===r;return(0,a.jsxs)("div",{className:"cmp-budget","data-pressure":r,children:[(0,a.jsxs)("div",{className:"cmp-budget-row",children:[(0,a.jsxs)("span",{className:"cmp-budget-count",children:["Approximate context: ",s," / ",i," tokens"]}),(0,a.jsx)("span",{className:eR[r],"aria-label":"Context pressure: ".concat(eC[r]),children:eC[r]}),(0,a.jsx)("span",{className:"cmp-budget-info",role:"img","aria-label":"Token counts are approximate. Actual model usage may vary.",title:"Token counts are approximate. Actual model usage may vary.",children:"i"}),(0,a.jsx)("button",{type:"button",className:"cmp-budget-clear","aria-label":"Clear conversation history for next prompt",onClick:n,disabled:!0===l,children:"Clear history"})]}),o?(0,a.jsx)("div",{id:eS,role:"alert",className:"cmp-budget-alert gw-error",children:"Context exceeds the selected model's window. Clear history or pick a model with a larger context."}):null]})}function eM(e){return Number.isFinite(e)?String(e):"—"}function eT(e){let{label:t,value:n}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("dt",{className:"grounded-context-pack-dt",children:t}),(0,a.jsx)("dd",{className:"grounded-context-pack-dd",children:n})]})}function eq(e){let{contextPack:t}=e,{usage:n,budget:l}=t,s=function(e){if("workspace-root"===e.scopeKind)return"workspace root";let t=e.scopeId.slice(-8);return"".concat(e.scopeKind," (").concat(t,")")}(t),i="files"===t.scopeKind?"Scope: ".concat(String(t.fileCount)," file").concat(1===t.fileCount?"":"s"," in ").concat(s):"Scope: ".concat(s);return(0,a.jsxs)("section",{className:"grounded-context-pack","aria-label":"Context inspection summary",children:[(0,a.jsx)("div",{className:"grounded-context-pack-headline",children:i}),(0,a.jsxs)("dl",{className:"grounded-context-pack-dl",children:[(0,a.jsx)(eT,{label:"Searched",value:"".concat(String(n.searchCalls),"\xd7 / ").concat(eM(l.searchCallsMax))}),(0,a.jsx)(eT,{label:"Read",value:"".concat(String(n.filesRead)," / ").concat(eM(l.filesReadMax)," files")}),(0,a.jsx)(eT,{label:"Bytes",value:"".concat(String(n.excerptBytes)," / ").concat(eM(l.excerptBytesMax)," B")}),(0,a.jsx)(eT,{label:"Input",value:"".concat(String(n.modelInputTokens)," / ").concat(eM(l.modelInputTokensMax)," tokens")}),(0,a.jsx)(eT,{label:"Output",value:"".concat(String(n.modelOutputTokens)," / ").concat(eM(l.modelOutputTokensMax)," tokens")}),(0,a.jsx)(eT,{label:"Rerank",value:"".concat(String(n.rerankCalls)," / ").concat(eM(l.rerankCallsMax)," calls")}),(0,a.jsx)(eT,{label:"Time",value:"".concat(String(t.elapsedMs)," / ").concat(eM(l.elapsedMsMax)," ms")}),(0,a.jsx)(eT,{label:"Query",value:t.queryKind})]})]})}function eP(e){let{citation:t}=e;return(0,a.jsxs)("span",{className:"grounded-citation",title:void 0===t.lineRange?"Evidence citation in ".concat(t.scopePath):"Evidence citation in ".concat(t.scopePath," at lines ").concat(String(t.lineRange.startLine),"-").concat(String(t.lineRange.endLine)),children:[(0,a.jsx)("span",{children:void 0===t.lineRange?t.scopePath:"".concat(t.scopePath,":").concat(String(t.lineRange.startLine),"-").concat(String(t.lineRange.endLine))}),(0,a.jsx)("span",{className:"grounded-citation-score",children:t.score.toFixed(2)})]})}function eA(e){let{citations:t}=e;return 0===t.length?null:(0,a.jsxs)("div",{className:"grounded-citations-wrap",children:[(0,a.jsx)("span",{className:"grounded-citations-label",children:"Evidence"}),(0,a.jsx)("ul",{className:"grounded-citations","aria-label":"Evidence citations",children:t.map(e=>(0,a.jsx)("li",{className:"grounded-citations-item",children:(0,a.jsx)(eP,{citation:e})},e.stableId))})]})}function ez(e){let{citations:t}=e;return 0===t.length?null:(0,a.jsxs)("div",{className:"grounded-citations-wrap",children:[(0,a.jsx)("span",{className:"grounded-citations-label",children:"Knowledge citations"}),(0,a.jsx)("ul",{className:"grounded-citations","aria-label":"Knowledge citations",children:t.map(e=>(0,a.jsx)("li",{className:"grounded-citations-item",children:(0,a.jsxs)("span",{className:"grounded-citation",title:void 0===e.source?e.label:"".concat(e.source," \xb7 ").concat(e.label),children:[(0,a.jsx)("span",{children:void 0===e.source?"".concat(e.marker," ").concat(e.label):"".concat(e.marker," ").concat(e.source," \xb7 ").concat(e.label)}),(0,a.jsx)("span",{className:"grounded-citation-score",children:e.score.toFixed(2)})]})},e.stableId))})]})}function eD(e){let{markers:t}=e;if(0===t.length)return null;let n=Array.from(new Set(t.map(e=>e.kind))).join(", ");return(0,a.jsxs)("div",{className:"grounded-uncertainty",role:"note",children:[(0,a.jsx)("div",{children:"Uncertainty (".concat(String(t.length)," markers — ").concat(n,")")}),(0,a.jsx)("ul",{className:"grounded-uncertainty-list",children:t.map((e,t)=>(0,a.jsx)("li",{children:"".concat(e.kind,": ").concat(e.claim)},"".concat(e.kind,"-").concat(String(t))))})]})}function eL(e){let{omittedCount:t,omittedCounts:n}=e;if(t<=0)return null;let l=Object.entries(n).filter(e=>{let[,t]=e;return t>0}).sort((e,t)=>{let[n]=e,[a]=t;return n<a?-1:+(n>a)}).map(e=>{let[t,n]=e;return"".concat(t.replaceAll("-"," "),": ").concat(String(n))}).join(", "),s=l.length>0?" (".concat(l,")"):"";return(0,a.jsx)("div",{className:"grounded-meta",children:"Omitted: ".concat(String(t)," evidence atoms").concat(s)})}let eF=[{reason:"size-exceeded",label:"larger than 2 MB"},{reason:"binary",label:"binary or an unsupported format"},{reason:"generated",label:"generated artifacts"},{reason:"budget-exhausted",label:"skipped after the exploration budget was reached"},{reason:"tool-unavailable",label:"unreadable"}];function eO(e){let{omittedCounts:t}=e,n=eF.map(e=>{let{reason:n,label:a}=e;return{label:a,count:t[n]}}).filter(e=>e.count>0),l=n.reduce((e,t)=>e+t.count,0);if(l<=0)return null;let s=n.map(e=>"".concat(String(e.count)," ").concat(e.label)).join(", ");return(0,a.jsxs)("div",{className:"grounded-coverage-notice",role:"note",children:[(0,a.jsx)("span",{className:"grounded-coverage-notice-title",children:"Partial coverage"}),(0,a.jsx)("span",{children:"This answer reflects only the searchable files in the connected scope — ".concat(String(l)," ").concat(1===l?"file":"files"," ").concat(1===l?"was":"were"," not searched (").concat(s,"). It does not cover the entire folder.")})]})}function eK(e){let{runId:t}=e;return void 0===t?null:(0,a.jsx)("div",{className:"grounded-meta",children:(0,a.jsx)("a",{href:"/api/evidence/".concat(encodeURIComponent(t)),children:"View connected-context audit evidence"})})}function eB(e){let{contextPack:t}=e;return(0,a.jsxs)("section",{className:"grounded-context-pack","aria-label":"Knowledge scope summary",children:[(0,a.jsx)("div",{className:"grounded-context-pack-headline",children:"Knowledge scope: ".concat(t.scopeLabel)}),(0,a.jsxs)("dl",{className:"grounded-context-pack-dl",children:[(0,a.jsx)(eT,{label:"Mode",value:t.scopeKind}),(0,a.jsx)(eT,{label:"Capsules",value:String(t.capsuleCount)}),(0,a.jsx)(eT,{label:"Sources",value:String(t.sourceCount)}),(0,a.jsx)(eT,{label:"Citations",value:String(t.citationCount)}),(0,a.jsx)(eT,{label:"Context budget",value:"".concat(String(t.referencesUsed)," / ").concat(String(t.referenceBudget)," references")})]})]})}function eW(e){let{contextPack:t}=e;return(0,a.jsxs)("section",{className:"grounded-context-pack","aria-label":"Hybrid source summary",children:[(0,a.jsx)("div",{className:"grounded-context-pack-headline",children:"Hybrid: ".concat(String(t.folderSourceCount)," folder source").concat(1===t.folderSourceCount?"":"s"," + ").concat(String(t.connectorSourceCount)," connector source").concat(1===t.connectorSourceCount?"":"s")}),(0,a.jsx)(eq,{contextPack:t.folder}),(0,a.jsx)(eB,{contextPack:t.knowledge})]})}function eU(e){let{answer:t,busy:n}=e;return void 0===t?n?(0,a.jsx)("div",{className:"grounded-meta",children:"Exploring repository context and asking Keiko…"}):null:"local-knowledge"===t.groundingKind?(0,a.jsxs)("div",{className:"grounded-answer",children:[(0,a.jsx)("div",{className:"grounded-answer-body",children:t.content}),(0,a.jsx)(ez,{citations:t.citations}),(0,a.jsx)(eD,{markers:t.uncertainty}),(0,a.jsx)(eB,{contextPack:t.contextPack})]}):"hybrid"===t.groundingKind?(0,a.jsxs)("div",{className:"grounded-answer",children:[(0,a.jsx)("div",{className:"grounded-answer-body",children:t.content}),(0,a.jsx)(eO,{omittedCounts:t.contextPack.folder.omittedCounts}),(0,a.jsx)(eA,{citations:t.citations}),(0,a.jsx)(ez,{citations:t.knowledgeCitations}),(0,a.jsx)(eD,{markers:t.uncertainty}),(0,a.jsx)(eL,{omittedCount:t.omittedCount,omittedCounts:t.contextPack.folder.omittedCounts}),(0,a.jsx)(eK,{runId:t.evidenceRunId}),(0,a.jsx)(eW,{contextPack:t.contextPack})]}):(0,a.jsxs)("div",{className:"grounded-answer",children:[(0,a.jsx)("div",{className:"grounded-answer-body",children:t.content}),(0,a.jsx)(eO,{omittedCounts:t.contextPack.omittedCounts}),(0,a.jsx)(eA,{citations:t.citations}),(0,a.jsx)(eD,{markers:t.uncertainty}),(0,a.jsx)(eL,{omittedCount:t.omittedCount,omittedCounts:t.contextPack.omittedCounts}),(0,a.jsx)(eK,{runId:t.evidenceRunId}),(0,a.jsx)(eq,{contextPack:t.contextPack})]})}let e_=["<script","</script","<iframe","</iframe","<object","</object","<embed","</embed","<style","</style","<svg","</svg","<form","</form","<meta","<link","<base"],eH=[" ","\n"," ","'",'"'];function eJ(e){var t;let n=function(e){let t=e.toLowerCase().replaceAll("\0",""),n="";for(let e=0;e<t.length;e++){var a;let l=null!=(a=t[e])?a:"";if("<"===l){for(n+="<";e+1<t.length&&(" "===t[e+1]||" "===t[e+1]||"\n"===t[e+1]||"\r"===t[e+1]);)e++;continue}n+=l}return n}(e);for(let e of e_)if(n.includes(e))return!0;let a=0;for(;a<n.length-4;){let e=n[a];if(eH.includes(e)&&"o"===n[a+1]&&"n"===n[a+2]){let e=a+3;for(;e<n.length&&/[a-z]/.test(null!=(t=n[e])?t:"");)e++;if(e<n.length&&"="===n[e])return!0}a++}return!1}function eV(e,t,n,a){a>n&&e.push({kind:"text",text:t.slice(n,a)})}function eG(e){return void 0!==e&&/[A-Za-z0-9]/.test(e)}let eX=new Set([" "," ","\n","<",">",'"']),eY=new Set([".",",",")","]","!","?"]);function eZ(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(t>=16)return e.length>0?[{kind:"text",text:e}]:[];let n=[],a=0,l=0;for(;a<e.length;){let s=function(e,t,n,a){if("`"!==t[n])return -1;let l=t.indexOf("`",n+1);return -1===l?-1:(eV(e,t,a,n),e.push({kind:"inline-code",text:t.slice(n+1,l)}),l+1)}(n,e,a,l);if(-1!==s||-1!==(s=function(e,t,n,a,l){let s=t[n],i=t[n+1];if(n+1>=t.length||("*"!==s||"*"!==i)&&("_"!==s||"_"!==i))return -1;let r=t.indexOf(s+i,n+2);if(-1===r)return -1;eV(e,t,a,n);let o=t.slice(n+2,r);return e.push({kind:"strong",children:eZ(o,l+1)}),r+2}(n,e,a,l,t))||-1!==(s=function(e,t,n,a,l){let s=t[n];if("*"!==s&&"_"!==s||"_"===s&&eG(t[n-1])&&eG(t[n+1])||t[n+1]===s||n>0&&t[n-1]===s)return -1;let i=function(e,t,n){for(let a=n;a<e.length;a++)if(e[a]===t&&e[a-1]!==t&&(a+1>=e.length||e[a+1]!==t))return a;return -1}(t,s,n+1);return -1===i||"_"===s&&eG(t[i-1])&&eG(t[i+1])?-1:(eV(e,t,a,n),e.push({kind:"em",children:eZ(t.slice(n+1,i),l+1)}),i+1)}(n,e,a,l,t))||-1!==(s=function(e,t,n,a){if("["!==t[n])return -1;let l=t.indexOf("]",n+1);if(-1===l||"("!==t[l+1])return -1;let s=t.indexOf(")",l+2);if(-1===s)return -1;let i=t.slice(n+1,l),r=t.slice(l+2,s);return eV(e,t,a,n),!function(e){let t=e.trim().toLowerCase();return t.startsWith("http://")||t.startsWith("https://")}(r)||eJ(i)||eJ(r)?e.push({kind:"text",text:"[".concat(i,"](").concat(r,")")}):e.push({kind:"link",text:i,href:r}),s+1}(n,e,a,l))||-1!==(s=function(e,t,n,a){if("h"!==t[n])return -1;let l="https://"===t.slice(n,n+8),s="http://"===t.slice(n,n+7);if(!l&&!s)return -1;let i=function(e,t){var n,a;let l=t;for(;l<e.length&&!eX.has(null!=(n=e[l])?n:"");)l++;for(;l>t&&eY.has(null!=(a=e[l-1])?a:"");)l--;return l}(t,n);if(i-n<=(l?8:7))return -1;let r=t.slice(n,i);return eV(e,t,a,n),e.push({kind:"link",text:r,href:r}),i}(n,e,a,l))){l=s,a=s;continue}a++}return eV(n,e,l,e.length),n}function eQ(e){let t=e.trim(),n=t.startsWith(":"),a=t.endsWith(":");return n&&a?"center":a?"right":n?"left":void 0}function e$(e){let t=e.trim();return t.startsWith("|")&&(t=t.slice(1)),t.endsWith("|")&&(t=t.slice(0,-1)),t.split("|")}function e0(e){var t,n,a;let l=/^( *)([*+\-]) (.*)$/.exec(e);return l?{match:!0,indent:null!=(n=null==(t=l[1])?void 0:t.length)?n:0,text:null!=(a=l[3])?a:""}:{match:!1}}function e1(e){var t,n,a;let l=/^( *)\d+\. (.*)$/.exec(e);return l?{match:!0,indent:null!=(n=null==(t=l[1])?void 0:t.length)?n:0,text:null!=(a=l[2])?a:""}:{match:!1}}function e2(e){return e.includes("|")}function e5(e){let t=e.trim();return/^(-{3,}|\*{3,}|_{3,})$/.test(t)}function e3(e,t){let n=[],a=t?e1:e0;for(;e.i<e.lines.length;){var l;let t=null!=(l=e.lines[e.i])?l:"",s=a(t);if(s.match)n.push({text:s.text,indent:s.indent}),e.i++;else if(""===t.trim())break;else break}return function e(t,n,a){let l=n?"ol":"ul",s=[],i=0;for(;i<t.length;){let l=t[i];if(void 0===l){i++;continue}let r=l.indent,o=[];for(i++;i<t.length;){let e=t[i];if(void 0===e||e.indent<=r)break;o.push(e),i++}let c=[...eZ(l.text)];o.length>0&&a<16?c.push(e(o,n,a+1)):o.length>0&&c.push({kind:"text",text:o.map(e=>e.text).join("\n")}),s.push({kind:"li",children:c})}return{kind:l,children:s}}(n,t,e.depth)}function e4(e){let{text:t}=e,[n,s]=(0,l.useState)(!1),i=(0,l.useCallback)(()=>{var e;"undefined"!=typeof navigator&&(null==(e=navigator.clipboard)?void 0:e.writeText)!==void 0&&navigator.clipboard.writeText(t).then(()=>{s(!0),setTimeout(()=>{s(!1)},1500)},()=>{})},[t]);return(0,a.jsx)("button",{type:"button",className:"sm-code-copy","aria-label":"Copy code block",title:n?"Copied!":"Copy code block",onClick:i,children:n?"✓":"Copy"})}let e6={1:"h1",2:"h2",3:"h3",4:"h4",5:"h5",6:"h6"},e8={1:"sm-h sm-h1",2:"sm-h sm-h2",3:"sm-h sm-h3",4:"sm-h sm-h4",5:"sm-h sm-h5",6:"sm-h sm-h6"};function e7(e,t){return void 0===e.children?null:e.children.map((e,n)=>e9(e,t+"-"+String(n)))}function e9(e,t){let n=function(e,t){var n,l;switch(e.kind){case"paragraph":return(0,a.jsx)("p",{className:"sm-p",children:e7(e,t)},t);case"heading":{let l=null!=(n=e.level)?n:1,s=e6[l],i=e8[l];return(0,a.jsx)(s,{className:i,children:e7(e,t)},t)}case"blockquote":return(0,a.jsx)("blockquote",{className:"sm-blockquote",children:e7(e,t)},t);case"hr":return(0,a.jsx)("hr",{className:"sm-hr"},t);case"code-block":{let n=e.language,s=null!=(l=e.text)?l:"",i=void 0!==n?"lang-".concat(n):void 0;return(0,a.jsxs)("div",{className:"sm-code-block-frame",children:[(0,a.jsxs)("div",{className:"sm-code-block-header",children:[(0,a.jsx)("span",{className:"sm-code-lang",children:null!=n?n:"untitled"}),(0,a.jsx)(e4,{text:s})]}),(0,a.jsx)("pre",{className:"sm-pre",children:(0,a.jsx)("code",{className:i,children:s})})]},t)}default:return null}}(e,t);if(null!==n)return n;let l=function(e,t){switch(e.kind){case"ul":return(0,a.jsx)("ul",{className:"sm-ul",children:e7(e,t)},t);case"ol":return(0,a.jsx)("ol",{className:"sm-ol",children:e7(e,t)},t);case"li":return(0,a.jsx)("li",{className:"sm-li",children:e7(e,t)},t);default:return null}}(e,t);if(null!==l)return l;let s=function(e,t){let n=void 0!==e.align?{textAlign:e.align}:void 0;switch(e.kind){case"table":return(0,a.jsx)("div",{className:"sm-table-wrapper",children:(0,a.jsx)("table",{className:"sm-table",children:e7(e,t)})},t);case"thead":return(0,a.jsx)("thead",{children:e7(e,t)},t);case"tbody":return(0,a.jsx)("tbody",{children:e7(e,t)},t);case"tr":return(0,a.jsx)("tr",{children:e7(e,t)},t);case"th":return(0,a.jsx)("th",{style:n,children:e7(e,t)},t);case"td":return(0,a.jsx)("td",{style:n,children:e7(e,t)},t);default:return null}}(e,t);if(null!==s)return s;let i=function(e,t){switch(e.kind){case"text":return(0,a.jsx)("span",{children:e.text},t);case"inline-code":return(0,a.jsx)("code",{className:"sm-inline-code",children:e.text},t);case"link":return(0,a.jsx)("a",{href:e.href,className:"sm-link",rel:"noopener noreferrer",target:"_blank",children:e.text},t);case"strong":return(0,a.jsx)("strong",{children:e7(e,t)},t);case"em":return(0,a.jsx)("em",{children:e7(e,t)},t);default:return null}}(e,t);return null!==i?i:null}function te(e){let{source:t}=e,n=function e(t,n){let a=[],l={lines:t.split("\n"),i:0,depth:n};for(;l.i<l.lines.length;)!function(t,n){var a,l;let s=null!=(a=t.lines[t.i])?a:"";if(""===s.trim())return t.i++;if(function(e,t,n){var a;let l=/^(`{3,}|~{3,})(\S*)/.exec(t.trim());if(null===l)return!1;let s=null!=(a=l[1])?a:"```",i=l[2],r=void 0!==i&&i.length>0?i:void 0;return n.push(function(e,t,n){let a=[];for(e.i++;e.i<e.lines.length;){var l,s,i;let n=null!=(l=e.lines[e.i])?l:"",r=/^(`{3,}|~{3,})\s*$/.exec(n.trim());if(null!==r){let n=null!=(s=r[1])?s:"";if(n.startsWith(null!=(i=t[0])?i:"")&&n.length>=t.length){e.i++;break}}a.push(n),e.i++}let r={kind:"code-block",text:a.join("\n")};return void 0!==n?{...r,language:n}:r}(e,s,r)),!0}(t,s,n)||function(e,t,n){var a,l;let s=/^(#{1,6}) (.+)$/.exec(t.trim());if(null===s)return!1;let i=Math.min((null!=(a=s[1])?a:"").length,6),r=null!=(l=s[2])?l:"";return n.push({kind:"heading",level:i,children:eZ(r)}),e.i++,!0}(t,s,n))return;if(e5(s)){n.push({kind:"hr"}),t.i++;return}if(s.trimStart().startsWith("> ")||">"===s.trim())return n.push(function(t){let n=[];for(;t.i<t.lines.length;){var a;let e=null!=(a=t.lines[t.i])?a:"";if(e.trimStart().startsWith("> ")||">"===e.trim())n.push(e.replace(/^( *)> ?/,"")),t.i++;else break}let l=n.join("\n");return t.depth>=16?{kind:"blockquote",children:[{kind:"paragraph",children:[{kind:"text",text:l}]}]}:{kind:"blockquote",children:[...e(l,t.depth+1)]}}(t));if(e2(s.trim())&&function(e){if(0===e.length)return!1;for(let t of e){let e=t.trim().replace(/^:/,"").replace(/:$/,"");if(!/^-+$/.test(e))return!1}return!0}(e$(null!=(l=t.lines[t.i+1])?l:""))&&(n.push(function(e,t){var n,a;e.i++;let l=null!=(n=e.lines[e.i])?n:"",s=[];for(e.i++;e.i<e.lines.length;){let t=null!=(a=e.lines[e.i])?a:"";if(""===t.trim()||!e2(t.trim()))break;s.push(t),e.i++}let i=e$(t),r=e$(l).map(eQ);return{kind:"table",children:[{kind:"thead",children:[{kind:"tr",children:i.map((e,t)=>(function(e,t){let n={kind:"th",children:eZ(e.trim())};return void 0!==t?{...n,align:t}:n})(e,r[t]))}]},{kind:"tbody",children:s.map(e=>({kind:"tr",children:e$(e).map((e,t)=>(function(e,t){let n={kind:"td",children:eZ(e.trim())};return void 0!==t?{...n,align:t}:n})(e,r[t]))}))}]}}(t,s)),1)||(e0(s).match?(n.push(e3(t,!1)),!0):!!e1(s).match&&(n.push(e3(t,!0)),!0)))return;let i=function(e){let t=[];for(;e.i<e.lines.length;){var n;let a=null!=(n=e.lines[e.i])?n:"";if(function(e){let t=e.trim();return!!(""===t||/^#{1,6} /.test(t)||e.trimStart().startsWith("> ")||/^(`{3,}|~{3,})/.test(t))||!!e0(e).match||!!e1(e).match||e5(e)}(a))break;t.push(a),e.i++}return 0===t.length?null:{kind:"paragraph",children:eZ(t.join(" "))}}(t);null!==i&&n.push(i)}(l,a);return a}(t,0);return(0,a.jsx)("div",{className:"sm-root",children:n.map((e,t)=>e9(e,String(t)))})}class tt extends l.Component{static getDerivedStateFromError(){return{failed:!0}}render(){return this.state.failed?(0,a.jsx)("div",{className:"sm-root sm-fallback","data-markdown-fallback":"true",children:this.props.source}):(0,a.jsx)(te,{source:this.props.source})}constructor(...e){super(...e),this.state={failed:!1}}}function tn(e){var t;let{attachment:n,onRemove:l}=e,s="Remove attachment ".concat(n.name),i=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:32;if(e.length<=t)return e;let n=e.lastIndexOf(".");if(n>0&&e.length-n<=8){let a=e.slice(n);return"".concat(e.slice(0,t-a.length-1),"…").concat(a)}return"".concat(e.slice(0,t-1),"…")}(n.name);return(0,a.jsxs)("div",{className:"attach-chip",role:"listitem",children:["image"===n.kind&&void 0!==n.previewDataUrl?(0,a.jsx)("img",{src:n.previewDataUrl,alt:n.name,className:"attach-chip-thumb","aria-hidden":"true",width:40,height:40}):(0,a.jsx)("span",{className:"attach-chip-icon","aria-hidden":"true",children:(0,a.jsx)(S.file,{size:16})}),(0,a.jsx)("span",{className:"attach-chip-name",title:n.name,children:i}),(0,a.jsx)("span",{className:"attach-chip-size",children:(t=n.sizeBytes)<1024?"".concat(String(t)," B"):t<1048576?"".concat((t/1024).toFixed(1)," KB"):"".concat((t/1048576).toFixed(1)," MiB")}),(0,a.jsx)("button",{type:"button",className:"attach-chip-remove","aria-label":s,onClick:()=>l(n.id),children:(0,a.jsx)(S.close,{size:12})})]})}function ta(e){let{attachments:t,onRemove:n}=e;return 0===t.length?null:(0,a.jsx)("div",{className:"attach-strip",role:"list","aria-label":"Pending attachments",children:t.map(e=>(0,a.jsx)(tn,{attachment:e,onRemove:n},e.id))})}function tl(e){let{enabled:t,onFiles:n}=e,[s,i]=(0,l.useState)(!1),r=(0,l.useCallback)(e=>{t&&(e.preventDefault(),i(!0))},[t]),o=(0,l.useCallback)(()=>{i(!1)},[]),c=(0,l.useCallback)(e=>{if(e.preventDefault(),i(!1),!t)return;let a=Array.from(e.dataTransfer.files);a.length>0&&n(a)},[t,n]);return(0,a.jsx)("div",{className:"attach-drop-zone","aria-label":t?"Drop files here to attach":"Attachments not supported by this model","data-dragover":s?"true":void 0,"data-disabled":t?void 0:"true",onDragOver:r,onDragLeave:o,onDrop:c,role:"presentation",children:t?null:(0,a.jsx)("span",{className:"attach-drop-hint",children:"Attachments not supported by this model"})})}let ts="cmp-attach-disabled-hint";function ti(e){let{model:t,onFiles:n}=e,s=(0,l.useRef)(null),i=void 0!==t&&(t.supportsImageInput||t.supportsDocumentInput),r=function(e){if(void 0===e)return"";let t=[];return e.supportsImageInput&&t.push("image/*"),e.supportsDocumentInput&&t.push(".pdf,.txt,.md,.csv,.json,.yaml,.yml"),t.join(",")}(t),o=(0,l.useCallback)(()=>{var e;i&&(null==(e=s.current)||e.click())},[i]),c=(0,l.useCallback)(()=>{var e,t;let a=Array.from(null!=(t=null==(e=s.current)?void 0:e.files)?t:[]);a.length>0&&(n(a),null!==s.current&&(s.current.value=""))},[n]);return(0,a.jsxs)(a.Fragment,{children:[i?null:(0,a.jsx)("span",{id:ts,className:"sr-only",children:"The selected model does not support image or document input. Choose a different model to attach files."}),(0,a.jsx)("input",{ref:s,type:"file",multiple:!0,accept:r,className:"sr-only",tabIndex:-1,"aria-hidden":"true",onChange:c}),(0,a.jsx)("button",{type:"button",className:"cmp-icon","aria-label":"Attach file","aria-disabled":i?void 0:"true","aria-describedby":i?void 0:ts,title:i?"Attach file":"Attachments not supported by this model",onClick:o,children:(0,a.jsx)(S.files,{size:16})})]})}function tr(e){let{reason:t,mimeType:n}=e;return void 0===t?null:(0,a.jsx)("div",{role:"alert",className:"attach-rejection-alert",children:function(e,t){switch(e){case"text-only-model":return"The selected model can't accept this attachment type. Choose a model that supports images or documents.";case"unsupported-type":return"Unsupported file type".concat(void 0!==t&&t.length>0?": ".concat(t):"",". Supported types: images (image/*), PDF, plain text, markdown, JSON, YAML.");case"oversized":return"File is larger than the 8 MiB limit. Choose a smaller file or summarize the content as text.";case"empty":return"Empty file. Add a file with content to attach."}}(t,n)})}function to(e){let{documents:t}=e;if(0===t.length)return null;let n=t.some(e=>e.truncated);return(0,a.jsxs)("div",{role:"status",className:"sent-docs-note","aria-label":"Documents included as context",children:[(0,a.jsx)("span",{className:"sent-docs-note-label",children:1===t.length?"Document included as context:":"Documents included as context:"}),(0,a.jsx)("ul",{className:"sent-docs-note-list",children:t.map(e=>(0,a.jsxs)("li",{className:"sent-docs-note-item",children:[e.displayName,e.truncated?(0,a.jsx)("span",{className:"sent-docs-note-trunc",children:" (truncated)"}):null]},e.id))}),n?(0,a.jsx)("span",{className:"sent-docs-note-hint",children:"Some document text was truncated to fit the context limit."}):null]})}let tc=[{workflowId:"unit-test-generation",label:"Generate unit tests",description:"Drafts a reviewable unit-test patch for a target file. Dry-run only from chat — apply from the workflow view.",prompt:"Target file (workspace-relative)",placeholder:"src/example.ts",buildInput:(e,t)=>({workspaceRoot:e,target:{kind:"file",filePath:t.trim()}})},{workflowId:"bug-investigation",label:"Investigate bug",description:"Investigates a reported issue and proposes a root-cause hypothesis. Dry-run only from chat.",prompt:"Describe the bug",placeholder:"The login button does nothing when the form is empty…",buildInput:(e,t)=>({workspaceRoot:e,report:{description:t.trim()}})}];function td(e){return tc.find(t=>t.workflowId===e)}function tu(e){return"chat"===e.kind&&e.toolCalling&&e.structuredOutput}function th(e){let{selectedModel:t,launch:n}=e,[s,i]=(0,l.useState)(!1),r=(0,l.useRef)(null);return void 0!==t&&tu(t)?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("button",{ref:r,type:"button",className:"cmp-mode",title:"Launch a governed workflow with the current model","aria-haspopup":"dialog","aria-expanded":s,onClick:()=>i(!0),children:[(0,a.jsx)(S.spark,{size:14,style:{color:"var(--accent)"}})," Launch workflow",(0,a.jsx)(S.chevron,{size:12})]}),s?(0,a.jsx)(tm,{modelId:t.id,launch:n,onClose:()=>{var e;i(!1),null==(e=r.current)||e.focus()}}):null]}):null}function tp(e){return Array.from(e.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'))}function tm(e){let{modelId:t,launch:n,onClose:s}=e,i=(0,l.useId)(),r=(0,l.useId)(),[o,c]=(0,l.useState)(),[d,u]=(0,l.useState)(""),[h,p]=(0,l.useState)(!1),[m,f]=(0,l.useState)(),g=(0,l.useRef)(null),v=void 0===o?void 0:td(o);async function x(){if(void 0===v||0===d.trim().length)return;p(!0),f(void 0);let e=await n({workflowId:v.workflowId,modelId:t,text:d});if(p(!1),e.ok)return void s();f(function(e){if(void 0!==e.message&&e.message.length>0)return e.message;switch(e.reason){case"not-workflow-eligible":return"The selected model does not support workflow runs. Pick a model with tool calling and structured output.";case"unknown-workflow":return"That workflow is no longer available.";case"missing-chat":return"Open or create a chat first, then launch the workflow.";case"missing-input":return"Provide an input before launching the workflow.";case"request-failed":return"Could not launch the workflow. Try again, or check the gateway logs.";default:return"Could not launch the workflow."}}(e))}return(0,l.useEffect)(()=>{var e;null==(e=g.current)||e.focus()},[]),(0,l.useEffect)(()=>{function e(e){if("Escape"===e.key)return void s();if("Tab"!==e.key)return;let t=g.current;if(null===t)return;let n=tp(t);if(0===n.length){e.preventDefault(),t.focus();return}let a=n[0],l=n[n.length-1],i=document.activeElement;e.shiftKey&&(i===a||i===t)?(e.preventDefault(),null==l||l.focus()):e.shiftKey||i!==l||(e.preventDefault(),null==a||a.focus())}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[s]),(0,a.jsx)("div",{ref:g,role:"dialog","aria-modal":"true","aria-labelledby":i,tabIndex:-1,className:"wf-dialog-overlay",children:(0,a.jsxs)("div",{className:"wf-dialog",children:[(0,a.jsx)("h2",{id:i,className:"wf-dialog-title",children:"Launch workflow"}),void 0===v?(0,a.jsx)("ul",{className:"wf-dialog-list","aria-label":"Available workflows",children:tc.map(e=>(0,a.jsx)("li",{children:(0,a.jsxs)("button",{type:"button",className:"wf-dialog-choice",onClick:()=>c(e.workflowId),children:[(0,a.jsx)("span",{className:"wf-dialog-choice-label",children:e.label}),(0,a.jsx)("span",{className:"wf-dialog-choice-desc",children:e.description})]})},e.workflowId))}):(0,a.jsxs)("div",{className:"wf-dialog-form",children:[(0,a.jsx)("p",{className:"wf-dialog-form-desc",children:v.description}),(0,a.jsx)("label",{className:"wf-dialog-field",htmlFor:r,children:v.prompt}),(0,a.jsx)("textarea",{id:r,className:"wf-dialog-input mono",rows:3,placeholder:v.placeholder,value:d,onChange:e=>u(e.target.value)}),void 0!==m?(0,a.jsx)("div",{role:"alert",className:"wf-dialog-error",children:m}):null,(0,a.jsxs)("div",{className:"wf-dialog-actions",children:[(0,a.jsx)("button",{type:"button",className:"wf-dialog-cancel",onClick:()=>c(void 0),children:"Back"}),(0,a.jsx)("button",{type:"button",className:"wf-dialog-launch",disabled:h||0===d.trim().length,onClick:()=>{x()},children:h?"Launching…":"Launch"})]})]}),(0,a.jsx)("button",{type:"button",className:"wf-dialog-close","aria-label":"Close launch workflow",onClick:s,children:(0,a.jsx)(S.close,{size:14})})]})})}let tf=[{workflowKind:"unit-test-generation",label:"Generate unit tests",description:"Use the grounded evidence as read-only context and propose in-scope test changes."},{workflowKind:"bug-investigation",label:"Investigate bug",description:"Investigate a bug against the grounded evidence and keep writes inside approved paths."},{workflowKind:"verification",label:"Run verification",description:"Run verification against the grounded workspace context without granting write access."}],tg=["verify","lint","typecheck","tests","manual"];function tv(e){return e.split(/\r?\n|,/).map(e=>e.trim()).filter(e=>e.length>0)}function tx(e){let{answer:t,modelId:n,busy:s,launch:i}=e,[r,o]=(0,l.useState)(!1),c=(0,l.useRef)(null);return void 0===t||"connected-context"!==t.groundingKind||void 0===n?null:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("button",{ref:c,type:"button",className:"cmp-mode",title:"Launch a governed workflow from this grounded answer","aria-haspopup":"dialog","aria-expanded":r,disabled:!0===s,onClick:()=>o(!0),children:[(0,a.jsx)(S.spark,{size:14,style:{color:"var(--accent)"}})," Launch grounded workflow",(0,a.jsx)(S.chevron,{size:12})]}),r?(0,a.jsx)(ty,{answer:t,modelId:n,launch:i,onClose:()=>{var e;o(!1),null==(e=c.current)||e.focus()}}):null]})}function ty(e){let{answer:t,modelId:n,launch:s,onClose:i}=e,r=(0,l.useId)(),o=(0,l.useRef)(null),[c,d]=(0,l.useState)(),[u,h]=(0,l.useState)("file"),[p,m]=(0,l.useState)(""),[f,g]=(0,l.useState)(""),[v,x]=(0,l.useState)(""),[y,b]=(0,l.useState)(""),[j,w]=(0,l.useState)(""),[k,N]=(0,l.useState)(""),[C,R]=(0,l.useState)([]),[I,E]=(0,l.useState)(!1),[M,T]=(0,l.useState)();async function q(){if(void 0===c)return;let e=function(e,t,n,a,l,s){if("unit-test-generation"===e){if("changedFiles"===t){let e=tv(n);return 0===e.length?{ok:!1,message:"Provide at least one changed file."}:{ok:!0,input:{target:{kind:"changedFiles",filePaths:e}}}}let e=n.trim();return 0===e.length?{ok:!1,message:"module"===t?"Provide a module directory.":"Provide a target file."}:"module"===t?{ok:!0,input:{target:{kind:"module",moduleDir:e}}}:{ok:!0,input:{target:{kind:"file",filePath:e}}}}if("bug-investigation"===e){let e=tv(l),t=a.trim();return 0===t.length&&0===e.length?{ok:!1,message:"Provide at least a bug description or one suspected target file."}:{ok:!0,input:{report:{...0===t.length?{}:{description:t},...0===e.length?{}:{targetFiles:e}}}}}let i=tv(s);return{ok:!0,input:0===i.length?{}:{targetFiles:i}}}(c,u,p,f,v,y);if(!e.ok)return void T(e.message);if(0===C.length)return void T("Select at least one expected check.");E(!0),T(void 0);let a=await s({assistantMessageId:t.assistantMessageId,modelId:n,workflowKind:c,input:e.input,editablePaths:tv(j),expectedChecks:C,unknowns:tv(k)});if(E(!1),a.ok)return void i();T(function(e){if(e.ok)return"";if(void 0!==e.message&&e.message.length>0)return e.message;switch(e.reason){case"missing-chat":return"Open a chat with the grounded answer you want to hand off.";case"missing-model":return"Pick a model before launching the grounded workflow.";default:return"Could not launch the grounded workflow."}}(a))}(0,l.useEffect)(()=>{var e;null==(e=o.current)||e.focus()},[]),(0,l.useEffect)(()=>{void 0!==c&&R("unit-test-generation"===c?["tests"]:["verify"])},[c]),(0,l.useEffect)(()=>{function e(e){if("Escape"===e.key)return void i();if("Tab"!==e.key)return;let t=o.current;if(null===t)return;let n=tp(t);if(0===n.length){e.preventDefault(),t.focus();return}let a=n[0],l=n[n.length-1],s=document.activeElement;e.shiftKey&&(s===a||s===t)?(e.preventDefault(),null==l||l.focus()):e.shiftKey||s!==l||(e.preventDefault(),null==a||a.focus())}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[i]);let P=tf.find(e=>e.workflowKind===c);return(0,a.jsx)("div",{ref:o,role:"dialog","aria-modal":"true","aria-labelledby":r,tabIndex:-1,className:"wf-dialog-overlay",children:(0,a.jsxs)("div",{className:"wf-dialog",children:[(0,a.jsx)("h2",{id:r,className:"wf-dialog-title",children:"Grounded workflow handoff"}),void 0===P?(0,a.jsx)("ul",{className:"wf-dialog-list","aria-label":"Available grounded workflows",children:tf.map(e=>(0,a.jsx)("li",{children:(0,a.jsxs)("button",{type:"button",className:"wf-dialog-choice",onClick:()=>d(e.workflowKind),children:[(0,a.jsx)("span",{className:"wf-dialog-choice-label",children:e.label}),(0,a.jsx)("span",{className:"wf-dialog-choice-desc",children:e.description})]})},e.workflowKind))}):(0,a.jsxs)("div",{className:"wf-dialog-form",children:[(0,a.jsx)("p",{className:"wf-dialog-form-desc",children:P.description}),"unit-test-generation"===c?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"wf-dialog-field",children:["Target mode",(0,a.jsxs)("select",{className:"wf-dialog-input mono",value:u,onChange:e=>h(e.target.value),children:[(0,a.jsx)("option",{value:"file",children:"File"}),(0,a.jsx)("option",{value:"module",children:"Module"}),(0,a.jsx)("option",{value:"changedFiles",children:"Changed files"})]})]}),(0,a.jsxs)("label",{className:"wf-dialog-field",children:["module"===u?"Module directory":"changedFiles"===u?"Changed files (one per line)":"Target file",(0,a.jsx)("textarea",{className:"wf-dialog-input mono",rows:"changedFiles"===u?3:2,value:p,onChange:e=>m(e.target.value),placeholder:"module"===u?"src/components":"changedFiles"===u?"src/a.ts\nsrc/b.ts":"src/example.ts"})]})]}):null,"bug-investigation"===c?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"wf-dialog-field",children:["Bug description",(0,a.jsx)("textarea",{className:"wf-dialog-input mono",rows:3,value:f,onChange:e=>g(e.target.value),placeholder:"Describe the failing behavior or regression."})]}),(0,a.jsxs)("label",{className:"wf-dialog-field",children:["Suspected target files (one per line)",(0,a.jsx)("textarea",{className:"wf-dialog-input mono",rows:2,value:v,onChange:e=>x(e.target.value),placeholder:"src/app.ts\\nsrc/lib/foo.ts"})]})]}):null,"verification"===c?(0,a.jsxs)("label",{className:"wf-dialog-field",children:["Target files (optional, one per line)",(0,a.jsx)("textarea",{className:"wf-dialog-input mono",rows:2,value:y,onChange:e=>b(e.target.value),placeholder:"src/app.ts\\nsrc/lib/foo.ts"})]}):null,(0,a.jsxs)("label",{className:"wf-dialog-field",children:["Editable paths (explicit, workspace-relative, one per line)",(0,a.jsx)("textarea",{className:"wf-dialog-input mono",rows:3,value:j,onChange:e=>w(e.target.value),placeholder:"src/example.test.ts"})]}),(0,a.jsxs)("fieldset",{className:"wf-dialog-field",style:{border:0,padding:0,margin:0},children:[(0,a.jsx)("legend",{children:"Expected checks"}),(0,a.jsx)("div",{className:"wf-dialog-form",style:{gap:8},children:tg.map(e=>(0,a.jsxs)("label",{className:"wf-dialog-choice-desc",style:{display:"flex",gap:8},children:[(0,a.jsx)("input",{type:"checkbox",checked:C.includes(e),onChange:()=>{R(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}}),(0,a.jsx)("span",{children:e})]},e))})]}),(0,a.jsxs)("label",{className:"wf-dialog-field",children:["Unknowns (optional, one per line)",(0,a.jsx)("textarea",{className:"wf-dialog-input mono",rows:2,value:k,onChange:e=>N(e.target.value),placeholder:"Need confirmation on public API behavior"})]}),void 0!==M?(0,a.jsx)("div",{role:"alert",className:"wf-dialog-error",children:M}):null,(0,a.jsxs)("div",{className:"wf-dialog-actions",children:[(0,a.jsx)("button",{type:"button",className:"wf-dialog-cancel",onClick:()=>d(void 0),children:"Back"}),(0,a.jsx)("button",{type:"button",className:"wf-dialog-launch",disabled:I,onClick:()=>{q()},children:I?"Launching…":"Launch"})]})]}),(0,a.jsx)("button",{type:"button",className:"wf-dialog-close","aria-label":"Close grounded workflow handoff",onClick:i,children:(0,a.jsx)(S.close,{size:14})})]})})}function tb(e){return"system"===e.role&&"string"==typeof e.runId}function tj(e){var t,n,l;let{message:s}=e,i=null!=(t=s.workflowStatus)?t:"queued",r=null!=(l=null!=(n=s.workflowId)?n:s.taskType)?l:"workflow",o=void 0===s.runId?"":s.runId.slice(0,8);return(0,a.jsxs)("article",{className:"run-summary-card","data-testid":"run-summary-card","data-status":i,role:"group","aria-label":"Workflow run ".concat(r," — ").concat(i),children:[(0,a.jsxs)("header",{className:"run-summary-card-head",children:[(0,a.jsx)(S.spark,{size:14,style:{color:"var(--accent)"}}),(0,a.jsx)("span",{className:"run-summary-card-workflow mono",children:r}),(0,a.jsx)("span",{className:"run-summary-card-status","data-status":i,children:i})]}),(0,a.jsxs)("div",{className:"run-summary-card-body",children:[(0,a.jsx)("p",{className:"run-summary-card-line",children:s.content}),void 0!==s.shortResult&&s.shortResult.length>0?(0,a.jsx)("p",{className:"run-summary-card-result",children:s.shortResult}):null,void 0!==s.runId?(0,a.jsxs)("p",{className:"run-summary-card-meta mono",children:["run ",(0,a.jsx)("span",{"data-runid":s.runId,children:s.runId})," ",(0,a.jsxs)("span",{className:"run-summary-card-runshort",children:["(",o,")"]})]}):null]})]})}function tw(e){let{on:t,onChange:n,label:l}=e;return(0,a.jsx)("button",{role:"switch","aria-checked":t,"aria-label":l,className:"auto-toggle".concat(t?" on":""),onClick:()=>{n(!t)},children:(0,a.jsx)("span",{})})}var tk=n(1352),tN=n(2516);let tS="\n…[truncated]",tC=["text/"],tR=new Set(["application/json","application/x-yaml","application/yaml"]),tI=new TextEncoder;function tE(e){return tI.encode(e).length}function tM(e){let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(t+1):e}async function tT(e,t){let n;if(e.remainingAggregate<=0)return;try{n=await t.file.text()}catch(e){var a;return a=tM(t.name),"Couldn't read \"".concat(a,'" — it was skipped. The other attachments were still sent.')}let l=Math.min(65536,Math.max(e.remainingAggregate-tE(tS),0));if(l<=0)return;let{entry:s,consumed:i}=function(e,t,n){let a=tE(t)>n,l=a?function(e,t){if(t<=0)return"";if(tE(e)<=t)return e;let n=0,a="";for(let l of e){let e=n+tE(l);if(e>t)break;n=e,a+=l}return a}(t,n):t,s=tE(l),i=a?tE(tS):0;return{entry:{id:e.id,displayName:tM(e.name),mimeType:e.mimeType,sizeBytes:e.sizeBytes,extractedBytes:s,truncated:a,truncationMarker:a?tS:void 0,text:l},consumed:s+i}}(t,n,l);0!==s.text.length&&(e.entries.push(s),e.remainingAggregate-=i)}async function tq(e){let t=e.filter(e=>{var t;return t=e.mimeType,!!tC.some(e=>t.startsWith(e))||tR.has(t)}).slice(0,16),n={entries:[],remainingAggregate:262144},a=[];for(let e of t){let t=await tT(n,e);void 0!==t&&a.push(t)}return{entries:n.entries,failures:a}}let tP=["text/"],tA=new Set(["application/pdf","application/json","application/x-yaml","application/yaml"]),tz="New chat",tD=["completed","failed","cancelled"];function tL(e){return"idle"!==e&&!tD.includes(e)}let tF="The conversation context exceeded the model's window. Clear history or pick a larger-context model.",tO=new Set(["CONVERSATION_OVERSIZED_CONTEXT","GATEWAY_CONTEXT_OVERFLOW"]),tK=["context length","context_length_exceeded","max_tokens","too many tokens"];function tB(e){return void 0!==e&&e.contextWindowTokens>0&&"exceeded"===e.pressure}function tW(e){return!function(e){if(e instanceof $.hD&&tO.has(e.code))return!0;let t=e instanceof Error?e.message.toLowerCase():"";return 0!==t.length&&tK.some(e=>t.includes(e))}(e)?e instanceof $.hD?"".concat(e.code,": ").concat(e.message):e instanceof Error?e.message:"Unknown error":tF}function tU(e){return[...e].sort((e,t)=>t.updatedAt-e.updatedAt)}function t_(e){var t;return null==(t=e.find(tN.S_))?void 0:t.id}function tH(e,t){return void 0!==e&&t.some(t=>t.id===e&&(0,tN.S_)(t))?e:t_(t)}let tJ={projects:[],chats:[],messages:[],models:[],activeProject:void 0,activeChat:void 0,selectedModel:void 0};async function tV(){var e;let t=(await (0,$.ZC)().catch(()=>({models:[]}))).models.filter(tN.S_),n=t_(t),a=await (0,$.vj)().catch(()=>({projects:[]})),l=null!=(e=a.projects.find(e=>e.available))?e:a.projects[0];if(void 0!==l){let e=tU((await (0,$.Oz)(l.path).catch(()=>({chats:[]}))).chats),n=e[0];if(void 0!==n){let s=await (0,$.T$)(n.id,l.path),i=tH(n.selectedModel,t);return{models:t,selectedModel:i,projects:Array.from(a.projects),activeProject:l,chats:e,activeChat:n,messages:Array.from(s.messages)}}}if(void 0===n)return{models:t,selectedModel:void 0,projects:Array.from(a.projects),activeProject:l,chats:[],activeChat:void 0,messages:[]};let s={modelId:n,title:tz};(null==l?void 0:l.available)===!0&&(s.projectPath=l.path);let i=await (0,$.tA)(s);return{models:t,selectedModel:i.chat.selectedModel,projects:Array.from(i.projects),activeProject:i.project,chats:tU(i.chats),activeChat:i.chat,messages:Array.from(i.messages)}}var tG=n(9389);let tX="cmp-no-model-alert",tY="cmp-send-hint",tZ="cmp-loading-status";function tQ(e){return t=>{"Enter"!==t.key||t.shiftKey||(t.preventDefault(),e())}}function t$(e){let{message:t}=e;if(tb(t))return(0,a.jsx)(tj,{message:t});let n="user"===t.role;return(0,a.jsx)("article",{className:"chat-msg","data-role":t.role,children:(0,a.jsxs)("div",{className:"chat-msg-bubble",children:[(0,a.jsx)("div",{className:"chat-msg-role",children:n?"You":"Keiko"}),n?t.content:(0,a.jsx)(tt,{source:t.content}),(0,a.jsx)("div",{className:"chat-msg-time",children:new Date(t.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]})})}function t0(){return(0,a.jsx)("article",{className:"chat-msg","data-role":"assistant",children:(0,a.jsxs)("div",{className:"chat-msg-bubble",children:[(0,a.jsx)("div",{className:"chat-msg-role",children:"Keiko"}),(0,a.jsxs)("span",{className:"chat-typing","aria-label":"Keiko is responding",children:[(0,a.jsx)("i",{}),(0,a.jsx)("i",{}),(0,a.jsx)("i",{})]})]})})}function t1(e){let{session:t,ready:n,selectedModelCapability:l,onAttachFiles:s,budgetExceeded:i}=e,{models:r,selectedModel:o,setSelectedModel:c,draft:d,noEligibleModels:u,loading:h,sending:p,cancelSend:m,launchWorkflowFromConversation:f}=t,g=u||i||!n,v=0===d.trim().length,x=u?tX:void 0,y=u?tX:i?eS:h?tZ:v?tY:void 0,b=u?"No conversation-eligible model is configured — connect a gateway in Settings":"Model",j=h||u?"":null!=o?o:"";return(0,a.jsxs)("div",{className:"cmp-bar",children:[(0,a.jsx)(ti,{model:l,onFiles:s}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("label",{className:"cmp-model mono",title:b,children:[(0,a.jsx)(S.cube,{size:13,style:{color:"var(--accent)"}}),(0,a.jsx)("select",{className:"cmp-model-select",value:j,"aria-label":"Model","aria-disabled":u||h?"true":void 0,"aria-describedby":x,title:b,disabled:h,onChange:e=>{u||h||c(e.target.value)},children:h?(0,a.jsx)("option",{value:"",disabled:!0,children:"Loading models…"}):u?(0,a.jsx)("option",{value:"",children:"No conversation-eligible model"}):r.filter(e=>"chat"===e.kind).map(e=>(0,a.jsx)("option",{value:e.id,children:e.id},e.id))}),(0,a.jsx)(S.chevron,{size:12})]}),(0,a.jsx)(th,{selectedModel:l,launch:f}),null,y===tY?(0,a.jsx)("span",{id:tY,className:"sr-only",children:"Type a message to send"}):null,p?(0,a.jsx)("button",{type:"button",className:"cmp-send cmp-send-cancel","data-on":!0,"aria-label":"Cancel response",title:"Cancel response",onClick:m,children:(0,a.jsx)(S.close,{size:16})}):(0,a.jsx)("button",{type:g?"button":"submit",className:"cmp-send","data-on":!g,"aria-disabled":g,"aria-describedby":y,title:u?"No conversation-eligible model is configured — connect a gateway in Settings":i?"Context exceeds the model's window — clear history or pick a larger-context model":h?"Connecting to your gateway":v?"Type a message to send":"Send message","aria-label":"Send message",children:(0,a.jsx)(S.arrowUp,{size:16})})]})}function t2(){return(0,a.jsx)("div",{id:tX,role:"alert",className:"gw-error cmp-no-model",children:"No conversation-eligible model is configured. Connect a gateway in Settings to enable chat."})}function t5(){return(0,a.jsxs)("div",{id:tZ,role:"status",className:"cmp-loading-status",children:[(0,a.jsx)("span",{className:"cmp-loading-dot","aria-hidden":"true"}),"Connecting to your gateway…"]})}function t3(e){let{status:t}=e,n=function(e){switch(e){case"idle":case"completed":case"failed":return"";case"queued":return"Submitting your message…";case"contacting":return"Contacting model…";case"streaming":return"Receiving response…";case"cancelled":return"Response cancelled."}}(t);return 0===n.length?null:(0,a.jsxs)("div",{role:"status","aria-live":"polite","data-send-status":t,className:"cmp-send-status",children:[(0,a.jsx)("span",{className:"cmp-loading-dot","aria-hidden":"true"}),n]})}function t4(e){let{session:t,ready:n,placeholder:s}=e,{draft:i,loading:r,sending:o,sendStatus:c,setDraft:d,sendMessage:u,models:h,selectedModel:p,pendingAttachments:m,addPendingAttachment:f,removePendingAttachment:g,budget:v,clearHistory:x}=t,y=tB(v),[b,j]=(0,l.useState)(),[w,k]=(0,l.useState)(),N=h.find(e=>e.id===p),S=void 0!==N&&(N.supportsImageInput||N.supportsDocumentInput),C=(0,l.useCallback)(async e=>{let t,n;for(let a of e){let e=await f(a);e.ok||void 0!==t||(t=e.reason,n=a.type)}j(t),k(n)},[f]);return(0,a.jsxs)("div",{className:"cmp-box",children:[(0,a.jsx)(tl,{enabled:S,onFiles:C}),(0,a.jsx)(ta,{attachments:m,onRemove:g}),(0,a.jsx)("textarea",{className:"cmp-input",rows:2,value:i,"aria-label":"Chat message",placeholder:s,onChange:e=>d(e.target.value),onKeyDown:tQ(u),disabled:r||o}),(0,a.jsx)(tr,{reason:b,mimeType:w}),(0,a.jsx)(t3,{status:c}),(0,a.jsx)(eE,{budget:v,onClearHistory:x,disabled:o||r}),(0,a.jsx)(t1,{session:t,ready:n,selectedModelCapability:N,onAttachFiles:C,budgetExceeded:y})]})}function t6(e){let{session:t,noEligibleModels:n}=e,{activeProject:l,setDraft:s}=t,i=void 0!==l?["Explain the architecture of ".concat(l.name),"Find a bug in ".concat(l.name),"Write tests for ".concat(l.name)]:["Explain the architecture of this codebase","Find and fix a bug in the workspace store","Write tests for the window manager"];return(0,a.jsxs)("div",{className:"chatw-empty",children:[(0,a.jsx)("h2",{className:"chatw-empty-headline",children:"Start a Keiko conversation"}),(0,a.jsx)("p",{className:"chatw-empty-sub",children:void 0!==l?"Working in ".concat(l.name,". What would you like to explore?"):"Pick a project from the sidebar to scope your workspace, or ask anything below."}),n?null:(0,a.jsx)("div",{className:"chatw-empty-prompts","aria-label":"Starter prompts",children:i.map(e=>(0,a.jsxs)("button",{type:"button",className:"suggest",onClick:()=>s(e),children:[(0,a.jsx)(S.spark,{size:12,style:{color:"var(--accent)"}}),e]},e))})]})}function t8(){return(0,a.jsxs)("div",{className:"chatw-empty-no-chat",children:[(0,a.jsx)("div",{className:"chatw-empty-no-chat-icon","aria-hidden":"true",children:(0,a.jsx)(S.spark,{size:20})}),(0,a.jsx)("p",{className:"chatw-empty-no-chat-label",children:"Pick or start a chat"}),(0,a.jsx)("p",{className:"chatw-empty-no-chat-hint",children:"Select a conversation from the project sidebar, or create a new one to get started."})]})}function t7(e){let{session:t,ready:n}=e,{draft:l,loading:s,sending:i,sendStatus:r,cancelSend:o,setDraft:c,sendMessage:d}=t;return(0,a.jsxs)("form",{className:"composer composer-fill",onSubmit:e=>{e.preventDefault(),d()},children:[(0,a.jsxs)("div",{className:"cmp-box cmp-box-fill",children:[(0,a.jsx)("textarea",{className:"cmp-input cmp-input-mini",value:l,"aria-label":"Chat message",placeholder:s?"Loading...":"Ask Keiko...",onChange:e=>c(e.target.value),onKeyDown:tQ(d),disabled:s||i}),i?(0,a.jsx)("button",{type:"button",className:"cmp-send cmp-send-float cmp-send-cancel","data-on":!0,"aria-label":"Cancel response",title:"Cancel response",onClick:o,children:(0,a.jsx)(S.close,{size:16})}):(0,a.jsx)("button",{type:n?"submit":"button",className:"cmp-send cmp-send-float","data-on":n,"aria-disabled":!n,"aria-label":"Send message",title:"Send",children:(0,a.jsx)(S.arrowUp,{size:16})})]}),(0,a.jsx)(t3,{status:r})]})}function t9(e){let{root:t}=e;return(0,a.jsxs)("div",{className:"chat-ctx",children:[(0,a.jsx)(S.files,{size:12})," Context ",(0,a.jsxs)("span",{className:"mono",children:[t,"/"]})]})}function ne(e){var t,n;return(null==(t=e.localKnowledgeScope)?void 0:t.kind)==="capsule"?"capsule:".concat(e.localKnowledgeScope.capsuleId):(null==(n=e.localKnowledgeScope)?void 0:n.kind)==="capsule-set"?"capsule-set:".concat(e.localKnowledgeScope.capsuleSetId):void 0!==e.connectedScope?"files":"none"}function nt(e){return e instanceof $.hD?"".concat(e.code,": ").concat(e.message):e instanceof Error?e.message:"Unable to update knowledge scope."}function nn(e){let{chat:t,onChatChanged:n}=e,[s,i]=(0,l.useState)([]),[r,o]=(0,l.useState)([]),[c,d]=(0,l.useState)(!1),[u,h]=(0,l.useState)(null);async function p(e){d(!0),h(null);try{if("none"===e){let e=await (0,$.wi)(t.id,{connectedScope:null,localKnowledgeScope:null});n(e.chat);return}if("files"===e){let e=await (0,$.wi)(t.id,{localKnowledgeScope:null});n(e.chat);return}if(e.startsWith("capsule-set:")){let a=await (0,$.wi)(t.id,{connectedScope:null,localKnowledgeScope:{kind:"capsule-set",capsuleSetId:e.slice(12),connectedAtMs:Date.now()}});n(a.chat);return}if(e.startsWith("capsule:")){let a=await (0,$.wi)(t.id,{connectedScope:null,localKnowledgeScope:{kind:"capsule",capsuleId:e.slice(8),connectedAtMs:Date.now()}});n(a.chat)}}catch(e){h(nt(e))}finally{d(!1)}}(0,l.useEffect)(()=>{let e=!1;return async function(){try{let[t,n]=await Promise.allSettled([(0,tG.xr)(),(0,tG.R3)()]);if("fulfilled"!==t.status)throw t.reason;if(e)return;i(t.value.capsules.filter(e=>"ready"===e.lifecycleState)),"fulfilled"===n.status?o(n.value.capsuleSets):(o([]),h(nt(n.reason)))}catch(t){e||h(nt(t))}}(),()=>{e=!0}},[]);let m=ne(t),f=function(e,t){let n=t.map(e=>({value:"capsule:".concat(e.id),label:"Knowledge capsule: ".concat(e.displayName)})),a=ne(e);if(!a.startsWith("capsule:")||n.some(e=>e.value===a))return n;let l=a.slice(8);return[...n,{value:a,label:"Knowledge capsule: ".concat(l," (not ready)")}]}(t,s),g=function(e,t){let n=t.map(e=>({value:"capsule-set:".concat(e.id),label:"Capsule set: ".concat(e.displayName)})),a=ne(e);if(!a.startsWith("capsule-set:")||n.some(e=>e.value===a))return n;let l=a.slice(12);return[...n,{value:a,label:"Capsule set: ".concat(l," (unavailable)")}]}(t,r);return(0,a.jsxs)("label",{style:{display:"inline-flex",alignItems:"center",gap:8,flexWrap:"wrap",fontSize:12},children:[(0,a.jsx)("span",{className:"mono",style:{color:"var(--fg-dim)"},children:"Grounding"}),(0,a.jsxs)("select",{value:m,disabled:c,"aria-label":"Grounding mode",onChange:e=>{p(e.target.value)},children:[(0,a.jsx)("option",{value:"none",children:"Model only"}),(0,a.jsx)("option",{value:"files",disabled:void 0===t.connectedScope,children:"Live Files context"}),f.map(e=>(0,a.jsx)("option",{value:e.value,children:e.label},e.value)),g.map(e=>(0,a.jsx)("option",{value:e.value,children:e.label},e.value))]}),null!==u?(0,a.jsx)("span",{role:"alert",className:"scope-connect-error",children:u}):null]})}function na(e){let{chat:t,onChatChanged:n,lastGroundedBudgetStatus:l}=e;return(0,a.jsxs)("div",{className:"chat-scope-header",style:{padding:"6px 12px",display:"flex",gap:12,flexWrap:"wrap"},children:[(0,a.jsx)(ej,{chat:t,onDisconnect:n,lastGroundedBudgetStatus:l}),(0,a.jsx)(eN,{chat:t,onDisconnect:n}),(0,a.jsx)(nn,{chat:t,onChatChanged:n})]})}function nl(e){let{chat:t,answer:n,busy:l,selectedModelId:s,launchGroundedWorkflowHandoff:i}=e;if(void 0===t)return null;let r=void 0!==t.connectedScope||void 0!==t.connectedScopes&&t.connectedScopes.length>0,o=void 0!==t.localKnowledgeScope||void 0!==t.localKnowledgeScopes&&t.localKnowledgeScopes.length>0;return(r||o)&&(void 0!==n||l)?(0,a.jsxs)("div",{className:"chatw-grounded","aria-live":"polite",children:[(0,a.jsx)(eU,{answer:n,busy:l}),(0,a.jsx)(tx,{answer:n,modelId:s,busy:l,launch:i})]}):null}function ns(e){let{action:t,acceptCandidate:n,rejectCandidate:s,forgetMemoryAction:i}=e,[r,o]=(0,l.useState)(!1),[c,d]=(0,l.useState)(),[u,h]=(0,l.useState)(!1);if("candidate"===t.kind)return(0,a.jsxs)("article",{className:"chat-memory-action",children:[(0,a.jsxs)("div",{className:"chat-memory-action-head",children:[(0,a.jsx)("strong",{children:t.scopeLabel}),(0,a.jsx)("span",{children:t.requiresApproval?"Approval required":"Proposed memory"})]}),(0,a.jsx)("p",{children:t.body}),(0,a.jsxs)("div",{className:"chat-memory-action-buttons",children:[(0,a.jsx)("button",{type:"button",disabled:r,onClick:()=>{o(!0),d(void 0),n(t.proposalId).catch(e=>{d(e instanceof Error?e.message:"Unable to accept memory.")}).finally(()=>o(!1))},children:"Accept"}),(0,a.jsx)("button",{type:"button",disabled:r,onClick:()=>{o(!0),d(void 0),s(t.proposalId).catch(e=>{d(e instanceof Error?e.message:"Unable to reject memory.")}).finally(()=>o(!1))},children:"Reject"})]}),void 0!==c?(0,a.jsx)("div",{role:"alert",className:"cmp-err",children:c}):null]});if("update"===t.kind)return(0,a.jsxs)("article",{className:"chat-memory-action",children:[(0,a.jsxs)("div",{className:"chat-memory-action-head",children:[(0,a.jsx)("strong",{children:"MemoriaViva update detected"}),(0,a.jsx)("span",{children:t.memoryId})]}),(0,a.jsx)("p",{children:void 0!==t.bodyPatch?"Suggested update: ".concat(t.bodyPatch):"Suggested update."})]});if("forget"===t.kind){let e=()=>{o(!0),d(void 0),i(t.memoryId).then(()=>h(!1)).catch(e=>{d(e instanceof Error?e.message:"Unable to forget memory.")}).finally(()=>o(!1))};return(0,a.jsxs)("article",{className:"chat-memory-action",children:[(0,a.jsxs)("div",{className:"chat-memory-action-head",children:[(0,a.jsx)("strong",{children:"MemoriaViva forget detected"}),(0,a.jsx)("span",{children:t.requiresConfirmation?"Confirmation required":t.memoryId})]}),(0,a.jsx)("p",{children:"Matched memory ".concat(t.memoryId," for a forget operation.")}),(0,a.jsx)("div",{className:"chat-memory-action-buttons",children:t.requiresConfirmation?u?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",disabled:r,onClick:e,children:"Forget permanently"}),(0,a.jsx)("button",{type:"button",disabled:r,onClick:()=>{d(void 0),h(!1)},children:"Cancel"})]}):(0,a.jsx)("button",{type:"button",disabled:r,onClick:()=>{d(void 0),h(!0)},children:"Review forget"}):(0,a.jsx)("button",{type:"button",disabled:r,onClick:e,children:"Forget"})}),void 0!==c?(0,a.jsx)("div",{role:"alert",className:"cmp-err",children:c}):null]})}return(0,a.jsxs)("article",{className:"chat-memory-action",children:[(0,a.jsx)("div",{className:"chat-memory-action-head",children:(0,a.jsx)("strong",{children:"MemoriaViva action not created"})}),(0,a.jsx)("p",{children:t.reason})]})}function ni(e){var t;let{memoryEnabled:n,setMemoryEnabled:s,memoryBudgetTokens:i,setMemoryBudgetTokens:r,latestMemory:o,acceptCandidate:c,rejectCandidate:d,forgetMemoryAction:u}=e,[h,p]=(0,l.useState)(!1),m="chat-memory-disclosure",f=null!=(t=null==o?void 0:o.context.memories.length)?t:0;return(0,a.jsxs)("section",{className:"chat-memory-panel","aria-label":"Conversation memory",children:[(0,a.jsxs)("div",{className:"chat-memory-panel-head",children:[(0,a.jsxs)("div",{className:"chat-memory-toggle",children:[(0,a.jsx)(tw,{on:n,onChange:s,label:"Enable memory for the next request"}),(0,a.jsxs)("span",{children:["MemoriaViva ",n?"on":"off"]})]}),(0,a.jsxs)("label",{className:"chat-memory-budget",children:[(0,a.jsx)("span",{children:"Budget"}),(0,a.jsx)("input",{type:"number",min:0,step:100,value:i,onChange:e=>r(Math.max(0,Number(e.target.value)||0))})]}),(0,a.jsx)("button",{type:"button",className:"chip","aria-expanded":h,"aria-controls":m,onClick:()=>p(e=>!e),children:f>0?"".concat(String(f)," memories included"):"No memory included"})]}),h?(0,a.jsxs)("div",{id:m,className:"chat-memory-disclosure",children:[(0,a.jsx)("p",{className:"chat-memory-summary",children:void 0===o?"MemoriaViva disclosure appears after the next response.":o.context.enabled?"Used ".concat(String(o.context.budget.used)," of ").concat(String(o.context.budget.tokens)," MemoriaViva tokens."):"MemoriaViva was disabled for the last request."}),null==o?void 0:o.context.memories.map(e=>(0,a.jsxs)("article",{className:"chat-memory-item",children:[(0,a.jsxs)("div",{className:"chat-memory-item-head",children:[(0,a.jsx)("strong",{children:e.memoryId}),(0,a.jsx)("span",{children:e.inclusionReason})]}),(0,a.jsx)("p",{children:e.bodyExcerpt})]},e.memoryId)),null==o?void 0:o.actions.map(e=>(0,a.jsx)(ns,{action:e,acceptCandidate:c,rejectCandidate:d,forgetMemoryAction:u},"candidate"===e.kind?e.proposalId:"rejected"===e.kind?e.reason:e.memoryId))]}):null]})}function nr(e){let{mini:t=!1,linkedRoot:n=null}=e,s=r(),{messages:i,draft:o,loading:c,sending:d,sendStatus:u,error:h,noEligibleModels:p,selectedModel:m,sendMessage:f,cancelGrounded:g,activeChat:v,replaceChat:x,latestGrounded:y,latestMemory:b,lastSentDocuments:j,memoryEnabled:w,setMemoryEnabled:k,memoryBudgetTokens:N,setMemoryBudgetTokens:S,acceptMemoryCandidate:C,rejectMemoryCandidate:R,launchGroundedWorkflowHandoff:I,forgetMemoryAction:E}=s,M=o.trim().length>0&&!d&&!c&&!p,T=i.filter(e=>"user"===e.role||"assistant"===e.role&&e.content.length>0||tb(e)),q=(0,l.useRef)(null),P=function(e){if(void 0===e)return;let{usage:t,budget:n}=e,a=[ex(t.searchCalls,n.searchCallsMax),ex(t.filesRead,n.filesReadMax),ex(t.excerptBytes,n.excerptBytesMax),ex(t.modelInputTokens,n.modelInputTokensMax),ex(t.modelOutputTokens,n.modelOutputTokensMax),ex(e.elapsedMs,n.elapsedMsMax),ex(t.rerankCalls,n.rerankCallsMax)].filter(e=>void 0!==e),l=0===a.length?0:Math.max(...a),s=l>1?"exceeded":l>=.85?"high":l>=.6?"moderate":"low",i=t.modelInputTokens+t.modelOutputTokens;return{pressure:s,label:eg[s],summary:"Last grounded run: ".concat(i>=1e3?"".concat((i/1e3).toFixed(1),"k"):i.toString()," tokens, ").concat(String(t.filesRead)," files")}}(void 0===y?void 0:"connected-context"===y.groundingKind?y.contextPack:"hybrid"===y.groundingKind?y.contextPack.folder:void 0);return((0,l.useEffect)(()=>{let e=q.current;null!==e&&(e.scrollTop=e.scrollHeight)},[T.length,d]),t)?(0,a.jsxs)("div",{className:"chatw chatw-mini",children:[null!==n?(0,a.jsx)(t9,{root:n}):null,void 0!==v?(0,a.jsx)(na,{chat:v,onChatChanged:x,lastGroundedBudgetStatus:P}):null,p?(0,a.jsx)(t2,{}):null,(0,a.jsx)(t7,{session:s,ready:M})]}):(0,a.jsxs)("div",{className:"chatw",children:[null!==n?(0,a.jsx)(t9,{root:n}):null,void 0!==v?(0,a.jsx)(na,{chat:v,onChatChanged:x,lastGroundedBudgetStatus:P}):null,void 0!==v?(0,a.jsx)(ni,{memoryEnabled:w,setMemoryEnabled:k,memoryBudgetTokens:N,setMemoryBudgetTokens:S,latestMemory:b,acceptCandidate:C,rejectCandidate:R,forgetMemoryAction:E}):null,p?(0,a.jsx)("div",{className:"chatw-foot",children:(0,a.jsx)(t2,{})}):null,c?(0,a.jsx)("div",{className:"chatw-foot",children:(0,a.jsx)(t5,{})}):null,(0,a.jsx)("div",{className:"chatw-scroll",ref:q,"aria-live":"polite",children:0===T.length?void 0!==v?(0,a.jsx)(t6,{session:s,noEligibleModels:p}):(0,a.jsx)(t8,{}):(0,a.jsxs)("div",{className:"chatw-log",children:[T.map(e=>(0,a.jsx)(t$,{message:e},e.id)),d&&"streaming"!==u?(0,a.jsxs)("div",{className:"chatw-typing-row",children:[(0,a.jsx)(t0,{}),(null==v?void 0:v.connectedScope)!==void 0||(null==v?void 0:v.localKnowledgeScope)!==void 0?(0,a.jsx)("button",{type:"button",className:"grounded-cancel-btn","aria-label":"Cancel grounded request",onClick:g,children:"Cancel"}):null]}):null,(0,a.jsx)(nl,{chat:v,answer:y,busy:d,selectedModelId:m,launchGroundedWorkflowHandoff:I}),(0,a.jsx)(to,{documents:j})]})}),T.length>0?(0,a.jsx)("div",{className:"chatw-foot",children:(0,a.jsxs)("form",{className:"composer",onSubmit:e=>{e.preventDefault(),f()},children:[(0,a.jsx)(t4,{session:s,ready:M,placeholder:"Ask Keiko about your code..."}),void 0!==h?(0,a.jsx)("div",{role:"alert",className:"cmp-err",children:h}):null]})}):null,0===T.length&&void 0!==v?(0,a.jsx)("div",{className:"chatw-foot",children:(0,a.jsxs)("form",{className:"composer",onSubmit:e=>{e.preventDefault(),f()},children:[(0,a.jsx)(t4,{session:s,ready:M,placeholder:c?"Connecting to your gateway…":"Ask Keiko about your code…"}),void 0!==h?(0,a.jsx)("div",{role:"alert",className:"cmp-err",children:h}):null]})}):null,0===T.length&&void 0!==h&&void 0===v?(0,a.jsx)("div",{className:"chatw-foot",children:(0,a.jsx)("div",{role:"alert",className:"cmp-err",children:h})}):null]})}let no=["n","s","e","w","ne","nw","se","sw"],nc=["t","r","b","l"];function nd(e){let{icon:t,label:n}=e,l=S[t];return(0,a.jsxs)("div",{className:"too-small",children:[(0,a.jsx)("div",{className:"ts-ico",children:(0,a.jsx)(l,{size:28})}),(0,a.jsxs)("div",{className:"ts-title",children:["Too small to show ",n]}),(0,a.jsx)("div",{className:"ts-sub",children:"Enlarge the window or zoom out"}),(0,a.jsx)("div",{className:"ts-arrow","aria-hidden":"true",children:(0,a.jsx)("svg",{width:"22",height:"22",viewBox:"0 0 22 22",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:(0,a.jsx)("path",{d:"M8 8l8 8M16 11v5h-5"})})})]})}function nu(e){var t,n;let{win:s,top:i,connState:r,view:o,api:c,wsRef:d}=e,u=es[s.type],h=S[u.icon],p=null!=(n=s.zoom)?n:1,m="chat"===s.type||"agents"===s.type||"quality"===s.type?c.linkedFilesRoot(s.id):null,f="agents"===s.type||"quality"===s.type?null==(t=c.linkedFilesContext(s.id))?void 0:t.activeFilePath:void 0,g="quality"===s.type?c.linkedAllFilesRoots(s.id):null!==m?[m]:[],v="quality"===s.type?c.linkedConnectorCapsuleIds(s.id):[],x="quality"===s.type?c.linkedConnectorCapsuleSetIds(s.id):[],y="quality"===s.type?c.linkedFigmaSnapshotRunIds(s.id):[],b=s.w/p,j=s.h/p,w=(0,l.useCallback)(e=>{c.update(s.id,{cfg:{...s.cfg,...e}})},[c,s.cfg,s.id]),k=(0,l.useCallback)((e,t)=>c.add(e,t),[c]),{mode:N,node:C}=function(e,t,n,l,s,i,r,o,c,d,u,h){if("chat"===e){let e=t<430||n<430;return{mode:e?"mini":"full",node:(0,a.jsx)(nr,{mini:e,linkedRoot:s})}}let p=es[e];return t<p.tiny.w||n<p.tiny.h?{mode:"tiny",node:(0,a.jsx)(nd,{icon:p.icon,label:p.title})}:{mode:"full",node:p.render(l,{linkedRoot:s,linkedFilePath:i,linkedRoots:r,linkedCapsuleIds:o,linkedCapsuleSetIds:c,linkedFigmaSnapshotRunIds:d,updateCfg:u,openWindow:h})}}(s.type,b,j,s.cfg,m,f,g,v,x,y,w,k),R=(0,l.useCallback)(e=>c.update(s.id,{zoom:Math.max(.5,Math.min(2,Math.round(10*e)/10))}),[c,s.id]),I=(0,l.useCallback)(e=>{var t,n,a,l;if(0!==e.button||"valid"===r)return;e.preventDefault(),c.focus(s.id);let i=d.current;if(null===i)return;let u=function(e,t){let n=t.zoom;return{z:n,vpx0:-t.x/n,vpy0:-t.y/n,vpw:e.width/n,vph:e.height/n,toWX:a=>(a-e.left-t.x)/n,toWY:a=>(a-e.top-t.y)/n}}(i.getBoundingClientRect(),o),h=s.max,p=h?null!=(a=null==(t=s.prev)?void 0:t.w)?a:480:s.w,m=h?null!=(l=null==(n=s.prev)?void 0:n.h)?l:360:s.h,f=h?p/2:u.toWX(e.clientX)-s.x,g=h?18:u.toWY(e.clientY)-s.y;h&&c.update(s.id,{max:!1,w:p,h:m}),function(e,t,n){let a=30/t.z,l=l=>{let s=t.toWX(l.clientX),i=t.toWY(l.clientY),r=s-n.offX,o=i-n.offY;r=Math.max(t.vpx0-(n.W-120),Math.min(t.vpx0+t.vpw-120,r)),o=Math.max(t.vpy0,Math.min(t.vpy0+t.vph-38,o)),e.setSnap(function(e,t,n,a){let l=e-n.vpx0<a,s=n.vpx0+n.vpw-e<a,i=t-n.vpy0<a,r=n.vpy0+n.vph-t<a;return i&&l?"tl":i&&s?"tr":r&&l?"bl":r&&s?"br":l?"left":s?"right":i?"maxi":null}(s,i,t,a)),e.update(n.winId,{x:r,y:o})},s=()=>{window.removeEventListener("pointermove",l),window.removeEventListener("pointerup",s),e.commitSnap(n.winId),document.body.style.cursor=""};window.addEventListener("pointermove",l),window.addEventListener("pointerup",s)}(c,u,{winId:s.id,offX:f,offY:g,W:p})},[c,s.id,s.x,s.y,s.w,s.h,s.max,s.prev,o,d,r]),E=(0,l.useCallback)(e=>t=>{t.preventDefault(),t.stopPropagation(),c.focus(s.id);let n={x:s.x,y:s.y,w:s.w,h:s.h},a=t.clientX,l=t.clientY,i=o.zoom,r=t=>{let r=function(e,t,n,a,l){let{x:s,y:i,w:r,h:o}=e;t.includes("e")&&(r=e.w+n),t.includes("s")&&(o=e.h+a),t.includes("w")&&(r=e.w-n,s=e.x+n),t.includes("n")&&(o=e.h-a,i=e.y+a);let c=es[l].min,d=c.w>0?c.w:240,u=c.h>0?c.h:150;return r<d&&(t.includes("w")&&(s-=d-r),r=d),o<u&&(t.includes("n")&&(i-=u-o),o=u),{x:s,y:i,w:r,h:o}}(n,e,(t.clientX-a)/i,(t.clientY-l)/i,s.type);c.update(s.id,{...r,max:!1})},d=()=>{window.removeEventListener("pointermove",r),window.removeEventListener("pointerup",d),document.body.style.cursor=""};document.body.style.cursor="n"===e||"s"===e?"ns-resize":"e"===e||"w"===e?"ew-resize":"ne"===e||"sw"===e?"nesw-resize":"nwse-resize",window.addEventListener("pointermove",r),window.addEventListener("pointerup",d)},[c,s.id,s.x,s.y,s.w,s.h,s.type,o.zoom]),M=(0,l.useCallback)((e,t)=>{let n=e.getBoundingClientRect();c.startConnect(s.id,{clientX:"clientX"in t?t.clientX:n.left+n.width/2,clientY:"clientY"in t?t.clientY:n.top+n.height/2,preventDefault:()=>t.preventDefault(),stopPropagation:()=>t.stopPropagation()})},[c,s.id]),T=(0,l.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),M(e.currentTarget,e)},[M]),q=(0,l.useCallback)(e=>{("Enter"===e.key||" "===e.key||"Spacebar"===e.key)&&(e.preventDefault(),e.stopPropagation(),M(e.currentTarget,e))},[M]),P="full"===N?function(e,t){if(void 0===t)return null;let n=e=>{let n=t[e];return"string"==typeof n&&n.length>0?n:null};switch(e){case"files":return n("root");case"browser":return n("url");case"editor":return n("file");case"terminal":return n("cwd");case"review":{let e=n("base"),t=n("head");return null!==e&&null!==t?"".concat(e," → ").concat(t):null}case"agents":return n("role");case"chat":{let e=n("title");return null!==e&&"New chat"!==e?e:null}default:return null}}(s.type,s.cfg):null,A={left:s.x,top:s.y,width:s.w,height:s.h,zIndex:s.z};return(0,a.jsxs)("section",{className:"window","data-top":i?"true":"false","data-max":s.max?"true":"false","data-conn":null!=r?r:void 0,"data-window-id":s.id,style:A,onPointerDown:e=>{"valid"===r&&c.confirmConnect(s.id,e),c.focus(s.id)},children:[(0,a.jsxs)("header",{className:"win-head",onPointerDown:I,onDoubleClick:()=>c.maximize(s.id),children:[(0,a.jsx)("span",{className:"win-ico",style:{color:!0===u.accent?"var(--accent)":"var(--fg-muted)"},children:(0,a.jsx)(h,{size:14})}),(0,a.jsx)("span",{className:"win-title",children:u.title}),null!==P?(0,a.jsx)("span",{className:"win-sub mono",children:P}):null,(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("div",{className:"win-zoom",children:[(0,a.jsx)("button",{type:"button",className:"win-zbtn",title:"Zoom content out","aria-label":"Zoom content out",onPointerDown:e=>e.stopPropagation(),onClick:()=>R(p-.1),children:(0,a.jsx)(S.zoomOut,{size:13})}),(0,a.jsxs)("button",{type:"button",className:"win-zpct",title:"Reset zoom","aria-label":"Reset content zoom",onPointerDown:e=>e.stopPropagation(),onClick:()=>c.update(s.id,{zoom:1}),children:[Math.round(100*p),"%"]}),(0,a.jsx)("button",{type:"button",className:"win-zbtn",title:"Zoom content in","aria-label":"Zoom content in",onPointerDown:e=>e.stopPropagation(),onClick:()=>R(p+.1),children:(0,a.jsx)(S.zoomIn,{size:13})})]}),(0,a.jsx)("button",{type:"button",className:"win-btn",title:s.max?"Restore":"Maximize","aria-label":s.max?"Restore window":"Maximize window",onPointerDown:e=>e.stopPropagation(),onClick:()=>c.maximize(s.id),children:s.max?(0,a.jsx)(S.restore,{size:13}):(0,a.jsx)(S.maximize,{size:13})}),(0,a.jsx)("button",{type:"button",className:"win-btn win-close",title:"Close","aria-label":"Close window",onPointerDown:e=>e.stopPropagation(),onClick:()=>c.close(s.id),children:(0,a.jsx)(S.close,{size:14})})]}),(0,a.jsx)("div",{className:"win-body","data-mode":N,style:"tiny"===N?{}:{zoom:p},children:C}),s.max?null:no.map(e=>(0,a.jsx)("div",{className:"wz wz-".concat(e),onPointerDown:E(e)},e)),s.max?null:nc.map(e=>(0,a.jsx)("div",{className:"win-port wp-".concat(e),title:"Click to connect to another card","aria-label":"Connect from ".concat("t"===e?"top":"r"===e?"right":"b"===e?"bottom":"left"," edge"),role:"button",tabIndex:0,onPointerDown:T,onKeyDown:q},"p".concat(e)))]})}function nh(e){var t;let{ws:n,wsRef:s,openPalette:i,palette:r}=e,{wins:o,view:c,snapPrev:d,conns:u,connecting:h,api:p}=n,m=function(e){if(null===e||0===e.length)return null;let t=e[0];for(let n=1;n<e.length;n++){let a=e[n];a.z>t.z&&(t=a)}return t}(o),f=null!==h&&null!==o&&null!=(t=o.find(e=>e.id===h.from))?t:null,g=(0,l.useMemo)(()=>({backgroundSize:"".concat(String(22*c.zoom),"px ").concat(String(22*c.zoom),"px"),backgroundPosition:"".concat(String(c.x),"px ").concat(String(c.y),"px")}),[c]),v=(0,l.useMemo)(()=>({transform:"translate(".concat(String(c.x),"px, ").concat(String(c.y),"px)"),transformOrigin:"0 0",zoom:c.zoom}),[c]),x=null!==o&&0===o.length;return(0,a.jsxs)("main",{className:"workspace",ref:s,"aria-label":"Workspace surface","data-connecting":null!==h?"true":void 0,onPointerDownCapture:e=>{if(0!==e.button||null===h||null===f||null===o)return;let t=function(e){if(!(e instanceof Element))return;let t=e.closest(".window[data-window-id]");return null==t?void 0:t.dataset.windowId}(e.target);if(void 0===t||t===f.id)return;let n=o.find(e=>e.id===t);void 0!==n&&V(f.type,n.type)&&p.confirmConnect(n.id,e)},onPointerDown:e=>{var t;if(0===e.button&&!((t=e.target)instanceof Element&&(null!==t.closest(".window")||null!==t.closest(".ws-zoom")||null!==t.closest(".ws-fab")||null!==t.closest(".conn-badge")))){if(null!==h)return void p.cancelConnect();!function(e,t){let n=t.clientX,a=t.clientY;document.body.style.cursor="grabbing";let l=t=>{e(t.clientX-n,t.clientY-a),n=t.clientX,a=t.clientY},s=()=>{window.removeEventListener("pointermove",l),window.removeEventListener("pointerup",s),document.body.style.cursor=""};window.addEventListener("pointermove",l),window.addEventListener("pointerup",s)}(p.panBy,e)}},children:[(0,a.jsx)(H,{}),(0,a.jsx)("div",{className:"ws-grid",style:g,"aria-hidden":"true"}),x?(0,a.jsxs)("div",{className:"ws-empty",children:[(0,a.jsx)("img",{className:"ws-empty-logo",src:"/assets/keiko-logo.svg",alt:""}),(0,a.jsx)("div",{className:"ws-empty-title",children:"Empty workspace"}),(0,a.jsx)("div",{className:"ws-empty-sub",children:"Open a window to start working"}),(0,a.jsxs)("button",{type:"button",className:"ws-empty-btn",onClick:i,children:[(0,a.jsx)(S.add,{size:15})," New window"]})]}):null,(0,a.jsxs)("div",{className:"ws-scene",style:v,children:[null!==d?(0,a.jsx)("div",{className:"snap-ghost",style:{left:d.x,top:d.y,width:d.w,height:d.h}}):null,null!==o?(0,a.jsx)(Q,{wins:o,conns:u,connecting:h,api:p}):null,null!==o?o.map(e=>(0,a.jsx)(nu,{win:e,top:null!==m&&e.id===m.id,connState:null===f?null:e.id===f.id?"source":V(f.type,e.type)?"valid":"invalid",view:c,api:p,wsRef:s},e.id)):null]}),(0,a.jsxs)("div",{className:"ws-zoom",children:[(0,a.jsx)("button",{type:"button",className:"ws-zoom-btn",onClick:()=>p.zoomTo(c.zoom-.2),"aria-label":"Zoom out",title:"Zoom out",children:(0,a.jsx)(S.zoomOut,{size:15})}),(0,a.jsxs)("button",{type:"button",className:"ws-zoom-pct mono",onClick:p.resetView,"aria-label":"Reset view",title:"Reset view",children:[Math.round(100*c.zoom),"%"]}),(0,a.jsx)("button",{type:"button",className:"ws-zoom-btn",onClick:()=>p.zoomTo(c.zoom+.2),"aria-label":"Zoom in",title:"Zoom in",children:(0,a.jsx)(S.zoomIn,{size:15})})]}),(0,a.jsx)("button",{type:"button",className:"ws-fab",onPointerDown:e=>e.stopPropagation(),onClick:i,"aria-label":"New window",title:"New window",children:(0,a.jsx)(S.add,{size:20})}),null!=r?r:null]})}function np(e){let{commands:t,onClose:n}=e,[s,i]=(0,l.useState)(""),[r,o]=(0,l.useState)(0),c=(0,l.useRef)(null),d=(0,l.useRef)(null),u=(0,l.useRef)(null);(0,l.useEffect)(()=>(d.current=document.activeElement,()=>{var e,t;null==(t=d.current)||null==(e=t.focus)||e.call(t)}),[]),(0,l.useEffect)(()=>{var e;null==(e=c.current)||e.focus()},[]);let h=(0,l.useMemo)(()=>{let e=s.toLowerCase();return t.filter(t=>{var n;return"".concat(t.label," ").concat(null!=(n=t.group)?n:"").toLowerCase().includes(e)})},[t,s]);(0,l.useEffect)(()=>{o(0)},[s]);let p=e=>{void 0!==e&&(e.run(),n())};return(0,a.jsx)("div",{className:"cmdk-overlay",onPointerDown:n,children:(0,a.jsxs)("div",{ref:u,className:"cmdk",role:"dialog","aria-modal":"true","aria-labelledby":"cmdk-title","aria-describedby":"cmdk-desc",onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{if("Tab"===e.key){var t,a;let n=Array.from(null!=(a=null==(t=u.current)?void 0:t.querySelectorAll("button:not([disabled]),input:not([disabled]),[tabindex]:not([tabindex='-1'])"))?a:[]);if(n.length>0){let t=n[0],a=n[n.length-1];if(e.shiftKey&&document.activeElement===t){e.preventDefault(),a.focus();return}if(!e.shiftKey&&document.activeElement===a){e.preventDefault(),t.focus();return}}}if("ArrowDown"===e.key){e.preventDefault(),o(e=>Math.min(h.length-1,e+1));return}if("ArrowUp"===e.key){e.preventDefault(),o(e=>Math.max(0,e-1));return}if("Enter"===e.key){e.preventDefault(),p(h[r]);return}"Escape"===e.key&&n()},children:[(0,a.jsx)("h2",{id:"cmdk-title",className:"sr-only",children:"Command palette"}),(0,a.jsx)("p",{id:"cmdk-desc",className:"sr-only",children:"Search commands and press Enter to run the selected action."}),(0,a.jsxs)("div",{className:"cmdk-input",children:[(0,a.jsx)(S.search,{size:16}),(0,a.jsx)("input",{ref:c,role:"combobox","aria-expanded":"true","aria-controls":"cmdk-list","aria-activedescendant":h.length>0?"cmdk-row-".concat(String(r)):void 0,"aria-label":"Command query",placeholder:"Type a command…",value:s,onChange:e=>i(e.target.value)}),(0,a.jsx)("span",{className:"kbd",children:"esc"})]}),(0,a.jsxs)("div",{id:"cmdk-list",role:"listbox",className:"cmdk-list",children:[0===h.length&&(0,a.jsx)("div",{className:"cmdk-empty",children:"No matching commands"}),h.map((e,t)=>(0,a.jsxs)("div",{role:"option",id:"cmdk-row-".concat(String(t)),"aria-selected":t===r,className:"cmdk-row","data-sel":t===r,tabIndex:-1,onMouseEnter:()=>o(t),onClick:()=>p(e),children:[(0,a.jsx)("span",{className:"cmdk-ico",children:function(e){var t;let n=null!=(t=S[e])?t:S.spark;return(0,a.jsx)(n,{size:16})}(e.icon)}),(0,a.jsx)("span",{className:"cmdk-label",children:e.label}),(0,a.jsx)("span",{className:"spacer"}),void 0!==e.group&&(0,a.jsx)("span",{className:"cmdk-group mono",children:e.group})]},e.id))]})]})})}var nm=n(7509);function nf(e){let{onCancel:t}=e,n=(0,l.useRef)(null),s=(0,l.useRef)(null),i=(0,l.useRef)(null),[r,o]=(0,l.useState)(""),[c,d]=(0,l.useState)(""),[u,h]=(0,l.useState)(""),[p,m]=(0,l.useState)(""),[f,g]=(0,l.useState)(!1),[v,x]=(0,l.useState)(),[y,b]=(0,l.useState)();async function j(e){if(e.preventDefault(),!f){g(!0),x(void 0),b(void 0);try{let e=Array.from(new Set(p.split(/[\n,]/u).map(e=>e.trim()).filter(e=>e.length>0)));if(function(e){try{return new URL(e.trim()).hostname.endsWith(".services.ai.azure.com")}catch(e){return!1}}(r)&&0===e.length){x("Azure AI Foundry requires deployment names. Paste the names from the Deployments tab."),g(!1);return}let t=(await (0,$.qe)({baseUrl:r,apiKey:c,apiKeyHeaderName:""===u.trim()?void 0:u.trim(),deploymentNames:e})).testedModelIds.length;b("Verified ".concat(String(t)," workflow chat model").concat(1===t?"":"s",". Reloading Keiko...")),window.setTimeout(()=>window.location.reload(),800)}catch(e){x(e instanceof $.hD?"".concat(e.code,": ").concat(e.message):e instanceof Error?e.message:"The gateway could not be configured."),g(!1)}}}(0,l.useEffect)(()=>{var e;return i.current=document.activeElement,null==(e=s.current)||e.focus(),()=>{var e,t;null==(t=i.current)||null==(e=t.focus)||e.call(t)}},[]),(0,l.useEffect)(()=>{let e=n.current;if(null===e)return;let a=n=>{if("Escape"===n.key){if(f||void 0!==y||void 0===t)return;n.preventDefault(),t();return}if("Tab"!==n.key)return;let a=Array.from(e.querySelectorAll("button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex='-1'])"));if(0===a.length)return;let l=a[0],s=a[a.length-1];n.shiftKey&&document.activeElement===l?(n.preventDefault(),s.focus()):n.shiftKey||document.activeElement!==s||(n.preventDefault(),l.focus())};return e.addEventListener("keydown",a),()=>e.removeEventListener("keydown",a)},[f,t,y]);let w=(0,a.jsx)("div",{className:"gw-setup-backdrop",role:"presentation",children:(0,a.jsx)("div",{ref:n,className:"gw-setup",role:"dialog","aria-modal":"true","aria-labelledby":"gw-setup-title","aria-describedby":"gw-setup-desc",children:(0,a.jsxs)("form",{onSubmit:e=>void j(e),children:[(0,a.jsxs)("div",{className:"gw-setup-badge",children:[(0,a.jsx)(S.cube,{size:18}),"Model gateway setup"]}),(0,a.jsx)("h1",{id:"gw-setup-title",children:"Connect Keiko to your internal LLMs"}),(0,a.jsx)("p",{id:"gw-setup-desc",children:"Keiko needs the internal gateway URL and API token before chat and agent workflows can run. The token is tested once and stored only on this machine."}),(0,a.jsxs)("label",{className:"gw-field",children:[(0,a.jsx)("span",{children:"Base URL"}),(0,a.jsx)("input",{className:"gw-input mono",value:r,placeholder:"https://llm-gateway.example.com/v1",autoComplete:"off",disabled:f||void 0!==y,ref:s,onChange:e=>o(e.target.value)})]}),(0,a.jsxs)("label",{className:"gw-field",children:[(0,a.jsx)("span",{children:"API token"}),(0,a.jsx)("input",{className:"gw-input mono",type:"password",value:c,placeholder:"Paste your API token",autoComplete:"off",disabled:f||void 0!==y,onChange:e=>d(e.target.value)})]}),(0,a.jsxs)("label",{className:"gw-field",children:[(0,a.jsx)("span",{children:"API key header optional"}),(0,a.jsx)("input",{className:"gw-input mono",value:u,placeholder:"Authorization",autoComplete:"off",disabled:f||void 0!==y,onChange:e=>h(e.target.value)})]}),(0,a.jsxs)("label",{className:"gw-field",children:[(0,a.jsx)("span",{children:"Deployment names for Azure"}),(0,a.jsx)("textarea",{className:"gw-input gw-textarea mono",value:p,placeholder:"Paste deployment names, one per line",autoComplete:"off",disabled:f||void 0!==y,onChange:e=>m(e.target.value)})]}),(0,a.jsx)("div",{className:"gw-note",children:"Leave the header field empty unless your gateway admin gave you a custom API-key header, for example X-Litellm-Key. Supported headers are Authorization, X-Litellm-Key, X-Api-Key, and api-key. Leave deployment names empty only for OpenAI-compatible gateways with model discovery. For Azure AI Foundry, paste deployment names exactly as shown in the Deployments tab. Testing several deployments can take up to 30 seconds."}),void 0!==v?(0,a.jsx)("div",{className:"gw-error",children:v}):null,void 0!==y?(0,a.jsx)("div",{className:"gw-success",children:y}):null,(0,a.jsxs)("div",{className:"gw-actions",children:[void 0!==t?(0,a.jsx)("button",{className:"gw-cancel",type:"button",disabled:f||void 0!==y,onClick:t,children:"Cancel"}):null,(0,a.jsx)("button",{className:"gw-submit",type:"submit",disabled:f||void 0!==y||""===r.trim()||""===c.trim(),children:f?"Testing connection...":"Test & save"})]})]})})});return"undefined"==typeof document?w:(0,nm.createPortal)(w,document.body)}let ng=[["ask","Ask every action"],["full","Full access"]];function nv(e){let{cfg:t,set:n}=e,l=!1!==t.keikoMode,s="full"===t.access?"full":"ask",i=l?"No rights by default. You approve while manual; Keiko governs per policy when autonomous.":"full"===s?"Legacy: agent acts without prompts.":"Legacy: you approve each privileged action.";return(0,a.jsxs)("div",{className:"permctl",children:[(0,a.jsxs)("button",{type:"button",className:"perm-toggle","data-on":l,"aria-pressed":l,onClick:()=>n("keikoMode",!l),children:[(0,a.jsx)("img",{className:"perm-orca",src:"/assets/keiko-logo.svg",alt:""}),(0,a.jsxs)("span",{className:"perm-tt",children:[(0,a.jsx)("span",{className:"perm-name",children:"Keiko-Mode"}),(0,a.jsx)("span",{className:"perm-desc",children:"Zero standing rights \xb7 Keiko governs"})]}),(0,a.jsx)("span",{className:"perm-sw"+(l?" on":""),children:(0,a.jsx)("span",{})})]}),!l&&(0,a.jsx)("div",{className:"perm-legacy",children:ng.map(e=>{let[t,l]=e;return(0,a.jsx)("button",{type:"button",className:"perm-opt","data-on":s===t,"aria-pressed":s===t,onClick:()=>n("access",t),children:l},t)})}),(0,a.jsx)("div",{className:"perm-note",children:i})]})}function nx(e){if(e instanceof $.hD){if("BAD_ROOT"===e.code)return"Enter an absolute folder path.";if("DENIED"===e.code)return"That location is excluded."}return e instanceof Error?e.message:"Unable to read directories."}function ny(e){let{value:t,projectId:n,selectProjectRoot:s=!1,onSelect:i,onClose:r}=e,[o,c]=(0,l.useState)(null),[d,u]=(0,l.useState)(t),[h,p]=(0,l.useState)(!1),[m,f]=(0,l.useState)(null),g=null!=n?n:t.trim(),v=(0,l.useCallback)(async e=>{if(0===g.length){c(null),f("Enter an absolute folder path.");return}p(!0),f(null);try{let t=await (0,$.xe)(g,e);c(t),u(t.path)}catch(e){f(nx(e))}finally{p(!1)}},[g]);return(0,l.useEffect)(()=>{v(t.length>0?t:void 0)},[v,t]),(0,a.jsxs)("div",{className:"dir-picker",role:"group","aria-label":"Directory picker",children:[(0,a.jsxs)("div",{className:"dir-top",children:[(0,a.jsx)("input",{className:"dlg-input mono dir-path",value:d,onChange:e=>u(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),v(d))}}),(0,a.jsx)("button",{type:"button",className:"dlg-btn dir-go",onClick:()=>void v(d),children:"Go"})]}),null!==o?(0,a.jsx)("div",{className:"dir-roots",children:o.roots.map(e=>(0,a.jsx)("button",{type:"button",className:"dir-chip",onClick:()=>void v(e.path),children:e.label},"".concat(e.label,":").concat(e.path)))}):null,(0,a.jsxs)("div",{className:"dir-list",children:[(null==o?void 0:o.parent)!==null&&(null==o?void 0:o.parent)!==void 0?(0,a.jsxs)("button",{type:"button",className:"dir-row",onClick:()=>{var e;v(null!=(e=o.parent)?e:void 0)},children:[(0,a.jsx)(S.back,{size:14}),(0,a.jsx)("span",{children:"Parent directory"})]}):null,null==o?void 0:o.entries.map(e=>(0,a.jsxs)("button",{type:"button",className:"dir-row",onClick:()=>void v(e.path),children:[(0,a.jsx)(S.folder,{size:14}),(0,a.jsx)("span",{children:e.name})]},e.path)),h?(0,a.jsx)("div",{className:"dir-note",children:"Loading directories..."}):null,h||null===o||0!==o.entries.length?null:(0,a.jsx)("div",{className:"dir-note",children:"No child directories."}),null!==m?(0,a.jsx)("div",{className:"dir-error",children:m}):null]}),(0,a.jsxs)("div",{className:"dir-actions",children:[(0,a.jsx)("button",{type:"button",className:"dlg-btn",onClick:r,children:"Close"}),(0,a.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",onClick:()=>{if(null!==o){var e,t;i(s&&null!=(t=null==(e=o.roots[0])?void 0:e.path)?t:o.path),r()}},disabled:null===o,children:"Use directory"})]})]})}let nb=[{id:"verify",label:"Verify"},{id:"explain-plan",label:"Explain plan"},{id:"unit-test-generation",label:"Generate unit tests"},{id:"bug-investigation",label:"Investigate bug"}];function nj(e){return e.filter(e=>e.available).map(e=>e.path)}function nw(e){return e.split(/[\n,]/u).map(e=>e.trim()).filter(e=>e.length>0)}function nk(e){return e.replaceAll("\\","/")}function nN(e,t){let n=nk(t.trim());if(0===n.length)return"";let a=nk(e.trim()).replace(/\/+$/u,"");if(0===a.length)return n;if(n===a)return".";let l="".concat(a,"/");return n.startsWith(l)?n.slice(l.length):n}function nS(e,t){return nw(t).map(t=>nN(e,t)).join(", ")}function nC(e){var t;let{filesContext:n,firstRef:s,directoryField:i,setDirectoryField:r,setDialogError:o,onConfirm:c}=e,[d,u]=(0,l.useState)("verify"),[h,p]=(0,l.useState)(null!=(t=null==n?void 0:n.root)?t:""),[m,f]=(0,l.useState)(""),[g,v]=(0,l.useState)([]),[x,y]=(0,l.useState)([]),[b,j]=(0,l.useState)(()=>{var e,t;return function(e,t){let n=null===t?"":nN(e,t);return{verifyTargetFiles:n,explainFilePath:n,explainQuestion:"",unitTargetKind:"file",unitFilePath:n,unitModuleDir:"",unitFilePaths:n,bugDescription:"",bugFailingOutput:"",bugStackTrace:"",bugTargetFiles:n}}(null!=(e=null==n?void 0:n.root)?e:"",null!=(t=null==n?void 0:n.activeFilePath)?t:null)}),[w,k]=(0,l.useState)(!0),[N,C]=(0,l.useState)(!1),[R,I]=(0,l.useState)(!1),E=h.trim(),M=null!==n&&n.root===E&&void 0!==n.activeFilePath?n.activeFilePath:null,T=E.length>0&&x.includes(E),q=function(e,t,n,a){if(0===t.length)return"Workspace is required.";if(0===n.length)return"No model is available.";if("explain-plan"===e&&0===a.explainFilePath.trim().length)return"Explain plan requires a filePath.";if("unit-test-generation"===e){if("file"===a.unitTargetKind&&0===a.unitFilePath.trim().length)return"Unit test generation requires a filePath.";if("module"===a.unitTargetKind&&0===a.unitModuleDir.trim().length)return"Unit test generation requires a moduleDir.";if("changedFiles"===a.unitTargetKind&&0===nw(a.unitFilePaths).length)return"Unit test generation requires at least one filePath."}return"bug-investigation"!==e||a.bugDescription.trim().length>0||a.bugFailingOutput.trim().length>0||a.bugStackTrace.trim().length>0||nw(a.bugTargetFiles).length>0?null:"Bug investigation requires description, output, stack trace, or target files."}(d,E,m,b),P=null===q&&T&&!R&&!w;(0,l.useEffect)(()=>{let e=!1;return k(!0),o(null),Promise.all([(0,$.ZC)(),(0,$.vj)()]).then(t=>{let[n,a]=t;if(e)return;let l=n.models.filter(tu);v(l),f(e=>{var t,n;return e||(null!=(n=null==(t=l[0])?void 0:t.id)?n:"")}),y(nj(a.projects))}).catch(t=>{e||o(nx(t))}).finally(()=>{e||k(!1)}),()=>{e=!0}},[o]);let A=e=>{j(t=>({...t,...e}))};(0,l.useEffect)(()=>{if(null===M)return;let e=nN(E,M);j(t=>{let n={};return 0===t.verifyTargetFiles.trim().length&&(n.verifyTargetFiles=e),0===t.explainFilePath.trim().length&&(n.explainFilePath=e),0===t.unitFilePath.trim().length&&(n.unitFilePath=e),0===t.unitFilePaths.trim().length&&(n.unitFilePaths=e),0===t.bugTargetFiles.trim().length&&(n.bugTargetFiles=e),0===Object.keys(n).length?t:{...t,...n}})},[M,E]);let z=async()=>{y(nj((await (0,$.vj)()).projects))},D=async()=>{if(0!==E.length){C(!0),o(null);try{await (0,$.gA)({path:E}),await z()}catch(e){o(nx(e))}finally{C(!1)}}},L=async()=>{if(!P)return void o(null!=q?q:"Workspace is not registered.");I(!0),o(null);let e=function(e,t,n,a){if("verify"===e){let e=nw(a.verifyTargetFiles).map(e=>nN(t,e));return{taskType:"verify",modelId:n,input:{workspaceRoot:t,...e.length>0?{targetFiles:e}:{}}}}if("explain-plan"===e)return{taskType:"explain-plan",modelId:n,input:{workspaceRoot:t,filePath:nN(t,a.explainFilePath),...a.explainQuestion.trim().length>0?{question:a.explainQuestion.trim()}:{}}};if("unit-test-generation"===e){let e=nw(a.unitFilePaths).map(e=>nN(t,e)),l="module"===a.unitTargetKind?{kind:"module",moduleDir:nN(t,a.unitModuleDir)}:"changedFiles"===a.unitTargetKind?{kind:"changedFiles",filePaths:e}:{kind:"file",filePath:nN(t,a.unitFilePath)};return{workflowId:"unit-test-generation",modelId:n,input:{workspaceRoot:t,target:l}}}return{workflowId:"bug-investigation",modelId:n,input:{workspaceRoot:t,report:{...a.bugDescription.trim().length>0?{description:a.bugDescription.trim()}:{},...a.bugFailingOutput.trim().length>0?{failingOutput:a.bugFailingOutput.trim()}:{},...a.bugStackTrace.trim().length>0?{stackTrace:a.bugStackTrace.trim()}:{},...nw(a.bugTargetFiles).length>0?{targetFiles:nw(a.bugTargetFiles).map(e=>nN(t,e))}:{}}}}}(d,E,m,b);try{let t=await (0,$.AD)(e);c({workflow:d,model:m,runId:t.runId,fingerprint:t.fingerprint,workspaceRoot:E,inputJson:JSON.stringify(e.input),...null!==n&&n.root===E?{__connectFilesId:n.id}:{}})}catch(e){e instanceof $.hD&&"WORKSPACE_NOT_REGISTERED"===e.code?(await z().catch(()=>void 0),o("Workspace is not registered.")):o(nx(e))}finally{I(!1)}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"Workflow"}),(0,a.jsxs)("span",{className:"dlg-selwrap",children:[(0,a.jsx)("select",{ref:s,className:"dlg-input mono",value:d,onChange:e=>u(e.target.value),children:nb.map(e=>(0,a.jsx)("option",{value:e.id,children:e.label},e.id))}),(0,a.jsx)("span",{className:"dlg-selchev",children:(0,a.jsx)(S.chevron,{size:15})})]})]}),(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"Workspace"}),(0,a.jsxs)("span",{className:"dlg-dirwrap",children:[(0,a.jsx)("input",{className:"dlg-input mono",value:h,placeholder:"/absolute/project/path",onClick:()=>r("agentWorkspace"),onChange:e=>p(e.target.value)}),(0,a.jsx)("button",{type:"button",className:"dlg-dirbtn",onClick:()=>r("agentWorkspace"),children:"Browse"})]}),"agentWorkspace"===i?(0,a.jsx)(ny,{value:h,projectId:T?E:void 0,onSelect:p,onClose:()=>r(null)}):null]}),E.length>0&&!T?(0,a.jsxs)("div",{className:"dlg-agent-warning",children:[(0,a.jsx)("span",{children:"Workspace is not registered."}),(0,a.jsx)("button",{type:"button",className:"dlg-btn",disabled:N,onClick:()=>void D(),children:N?"Registering...":"Register workspace"})]}):null,(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"Model"}),(0,a.jsxs)("span",{className:"dlg-selwrap",children:[(0,a.jsx)("select",{className:"dlg-input mono",value:m,onChange:e=>f(e.target.value),disabled:0===g.length,children:g.map(e=>(0,a.jsx)("option",{value:e.id,children:e.id},e.id))}),(0,a.jsx)("span",{className:"dlg-selchev",children:(0,a.jsx)(S.chevron,{size:15})})]})]}),null!==M?(0,a.jsxs)("button",{type:"button",className:"dlg-current-file",onClick:()=>{if(null===M)return;let e=nN(E,M);"verify"===d?A({verifyTargetFiles:e}):"explain-plan"===d?A({explainFilePath:e}):"unit-test-generation"===d?"changedFiles"===b.unitTargetKind?A({unitFilePaths:e}):A({unitTargetKind:"file",unitFilePath:e}):A({bugTargetFiles:e})},children:[(0,a.jsx)(S.files,{size:13})," Use current file ",(0,a.jsx)("span",{className:"mono",children:M})]}):null,"verify"===d?(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:["Target files ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,placeholder:"src/file.ts, src/other.ts",value:b.verifyTargetFiles,onChange:e=>A({verifyTargetFiles:e.target.value}),onBlur:e=>A({verifyTargetFiles:nS(E,e.target.value)})})]}):"explain-plan"===d?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"filePath"}),(0,a.jsx)("input",{className:"dlg-input mono",placeholder:"src/file.ts",value:b.explainFilePath,onChange:e=>A({explainFilePath:e.target.value}),onBlur:e=>A({explainFilePath:nN(E,e.target.value)})})]}),(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:["Question ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea",rows:2,placeholder:"What should the plan focus on?",value:b.explainQuestion,onChange:e=>A({explainQuestion:e.target.value})})]})]}):"unit-test-generation"===d?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"targetKind"}),(0,a.jsxs)("span",{className:"dlg-selwrap",children:[(0,a.jsxs)("select",{className:"dlg-input mono",value:b.unitTargetKind,onChange:e=>A({unitTargetKind:e.target.value}),children:[(0,a.jsx)("option",{value:"file",children:"file"}),(0,a.jsx)("option",{value:"module",children:"module"}),(0,a.jsx)("option",{value:"changedFiles",children:"changedFiles"})]}),(0,a.jsx)("span",{className:"dlg-selchev",children:(0,a.jsx)(S.chevron,{size:15})})]})]}),"module"===b.unitTargetKind?(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"moduleDir"}),(0,a.jsx)("input",{className:"dlg-input mono",placeholder:"src/module",value:b.unitModuleDir,onChange:e=>A({unitModuleDir:e.target.value}),onBlur:e=>A({unitModuleDir:nN(E,e.target.value)})})]}):"changedFiles"===b.unitTargetKind?(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"filePaths"}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,placeholder:"src/file.ts, src/other.ts",value:b.unitFilePaths,onChange:e=>A({unitFilePaths:e.target.value}),onBlur:e=>A({unitFilePaths:nS(E,e.target.value)})})]}):(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"filePath"}),(0,a.jsx)("input",{className:"dlg-input mono",placeholder:"src/file.ts",value:b.unitFilePath,onChange:e=>A({unitFilePath:e.target.value}),onBlur:e=>A({unitFilePath:nN(E,e.target.value)})})]})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:["Description ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea",rows:2,placeholder:"Describe the observed bug.",value:b.bugDescription,onChange:e=>A({bugDescription:e.target.value})})]}),(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:["Failing output ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,value:b.bugFailingOutput,onChange:e=>A({bugFailingOutput:e.target.value})})]}),(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:["Stack trace ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,value:b.bugStackTrace,onChange:e=>A({bugStackTrace:e.target.value})})]}),(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:["Target files ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,placeholder:"src/file.ts, src/other.ts",value:b.bugTargetFiles,onChange:e=>A({bugTargetFiles:e.target.value}),onBlur:e=>A({bugTargetFiles:nS(E,e.target.value)})})]})]}),(0,a.jsxs)("div",{className:"dlg-agent-actions",children:[(0,a.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",disabled:!P,onClick:()=>void L(),children:R?"Starting...":"Start agent"}),w?(0,a.jsx)("span",{className:"dlg-note",children:"Loading models and projects..."}):null]})]})}function nR(e){var t,n;let{type:s,types:i,filesContext:r=null,onConfirm:o,onClose:c}=e,d=i[s],u=null!=(t=d.config)?t:[],[h,p]=(0,l.useState)(()=>(function(e){let t={};for(let a of e){var n;t[a.key]=null!=(n=a.def)?n:""}return t})(u)),[m,f]=(0,l.useState)(!1),[g,v]=(0,l.useState)(null),[x,y]=(0,l.useState)(null),b=(0,l.useRef)(null),j=(0,l.useRef)(null);(0,l.useEffect)(()=>(j.current=document.activeElement,()=>{var e,t;null==(t=j.current)||null==(e=t.focus)||e.call(t)}),[]),(0,l.useEffect)(()=>{let e=requestAnimationFrame(()=>{var e;f(!0),null==(e=b.current)||e.focus()});return()=>cancelAnimationFrame(e)},[]),(0,l.useEffect)(()=>{if("files"!==s)return;let e=!1,t=h.root;if("string"!=typeof t||!(t.length>0))return v(null),(0,$.vj)().then(t=>{let n=nj(t.projects)[0];e||void 0===n||p(e=>({...e,root:n}))}).catch(t=>{e||v(nx(t))}),()=>{e=!0}},[h.root,s]);let w=(e,t)=>p(n=>({...n,[e]:t})),k=()=>{"agents"!==s&&o(h)},N=S[d.icon],C=null!=(n=d.cta)?n:"Open ".concat(d.title);return(0,a.jsx)("div",{className:"dlg-overlay"+(m?" in":""),onPointerDown:c,children:(0,a.jsxs)("div",{className:"dlg",role:"dialog","aria-modal":"true","aria-labelledby":"new-window-title","aria-describedby":"new-window-desc",onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{if("Escape"===e.key)return void c();if("Enter"===e.key&&(e.metaKey||e.ctrlKey))return void k();if("Tab"!==e.key)return;let t=function(e){let t=e.querySelectorAll("button,input,select,textarea"),n=[];return t.forEach(e=>{e.hasAttribute("disabled")||(null!==e.offsetParent||"BUTTON"===e.tagName)&&n.push(e)}),n}(e.currentTarget);if(0===t.length)return;let n=t[0],a=t[t.length-1];e.shiftKey&&document.activeElement===n?(e.preventDefault(),a.focus()):e.shiftKey||document.activeElement!==a||(e.preventDefault(),n.focus())},children:[(0,a.jsxs)("div",{className:"dlg-head",children:[(0,a.jsx)("span",{className:"dlg-ico",children:(0,a.jsx)(N,{size:20})}),(0,a.jsxs)("div",{className:"dlg-htext",children:[(0,a.jsxs)("span",{id:"new-window-title",className:"dlg-title",children:["New ",d.title," window"]}),(0,a.jsx)("span",{id:"new-window-desc",className:"dlg-sub",children:d.desc})]}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsx)("button",{type:"button",className:"palette-x",onClick:c,"aria-label":"Cancel",title:"Cancel",children:(0,a.jsx)(S.close,{size:16})})]}),(0,a.jsxs)("div",{className:"dlg-body",children:["agents"===s?(0,a.jsx)(nC,{filesContext:r,firstRef:e=>{b.current=e},directoryField:x,setDirectoryField:y,setDialogError:v,onConfirm:o}):0===u.length&&(0,a.jsxs)("div",{className:"dlg-empty",children:["Add a new ",d.title," window to your workspace."]}),"agents"!==s&&u.map((e,t)=>(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:[e.label,!0===e.optional&&(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),function(e,t,n,l,s){var i,r,o,c;if("perm"===e.type)return(0,a.jsx)(nv,{cfg:t,set:n});let d=t[e.key],u="string"==typeof d?d:void 0===d?"":String(d);if("select"===e.type){let t=null!=(i=e.options)?i:[];return(0,a.jsxs)("span",{className:"dlg-selwrap",children:[(0,a.jsx)("select",{ref:null!=l?l:void 0,className:"dlg-input mono",value:u,onChange:t=>n(e.key,t.target.value),disabled:0===t.length,children:t.map(t=>{var n;return(0,a.jsx)("option",{value:t,children:(null!=(n=e.prefix)?n:"")+t},t)})}),(0,a.jsx)("span",{className:"dlg-selchev",children:(0,a.jsx)(S.chevron,{size:15})})]})}return"textarea"===e.type?(0,a.jsx)("textarea",{ref:null!=l?l:void 0,className:"dlg-input dlg-textarea",rows:3,placeholder:null!=(r=e.placeholder)?r:"",value:u,onChange:t=>n(e.key,t.target.value)}):"directory"===e.type?(0,a.jsxs)("span",{className:"dlg-dirwrap",children:[(0,a.jsx)("input",{ref:null!=l?l:void 0,className:"dlg-input mono",placeholder:null!=(o=e.placeholder)?o:e.label,value:u,onClick:()=>s(e.key),onChange:t=>n(e.key,t.target.value)}),(0,a.jsx)("button",{type:"button",className:"dlg-dirbtn",onClick:()=>s(e.key),children:"Browse"})]}):(0,a.jsx)("input",{ref:null!=l?l:void 0,className:"dlg-input mono",placeholder:null!=(c=e.placeholder)?c:e.label,value:u,onChange:t=>n(e.key,t.target.value)})}(e,h,w,0===t?e=>{b.current=e}:null,y),"directory"===e.type&&x===e.key?(0,a.jsx)(ny,{value:"string"==typeof h[e.key]?h[e.key]:"",selectProjectRoot:"root"===e.key,onSelect:t=>w(e.key,t),onClose:()=>y(null)}):null]},e.key)),null!==g?(0,a.jsx)("div",{className:"dlg-error",children:g}):null]}),(0,a.jsxs)("div",{className:"dlg-foot",children:[(0,a.jsx)("button",{type:"button",className:"dlg-btn",onClick:c,children:"Cancel"}),"agents"!==s?(0,a.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",onClick:k,children:C}):null]})]})})}function nI(e){let{types:t,order:n,onAdd:s,onClose:i}=e,r=(0,l.useRef)(null),o=(0,l.useRef)(null);return(0,l.useEffect)(()=>{var e;o.current=document.activeElement;let t=null==(e=r.current)?void 0:e.querySelector(".pal-card");return null==t||t.focus(),()=>{var e,t;null==(t=o.current)||null==(e=t.focus)||e.call(t)}},[]),(0,a.jsxs)("div",{ref:r,className:"palette",role:"dialog","aria-modal":"true","aria-labelledby":"palette-title","aria-describedby":"palette-desc",onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{if("Escape"===e.key){e.preventDefault(),i();return}if("Tab"===e.key){var t,n;let a=Array.from(null!=(n=null==(t=r.current)?void 0:t.querySelectorAll("button:not([disabled]),[tabindex]:not([tabindex='-1'])"))?n:[]);if(0===a.length)return;let l=a[0],s=a[a.length-1];e.shiftKey&&document.activeElement===l?(e.preventDefault(),s.focus()):e.shiftKey||document.activeElement!==s||(e.preventDefault(),l.focus())}},children:[(0,a.jsxs)("div",{className:"palette-head",children:[(0,a.jsx)("span",{className:"palette-badge",children:(0,a.jsx)(S.add,{size:17})}),(0,a.jsxs)("div",{className:"palette-htext",children:[(0,a.jsx)("span",{id:"palette-title",className:"palette-title",children:"New Window"}),(0,a.jsx)("span",{id:"palette-desc",className:"palette-sub",children:"Pick a card to add to your workspace"})]}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsx)("button",{type:"button",className:"palette-x",onClick:i,"aria-label":"Close window picker",title:"Close",children:(0,a.jsx)(S.close,{size:16})})]}),(0,a.jsx)("div",{className:"palette-grid",children:n.map(e=>{let n=t[e],l=S[n.icon];return(0,a.jsxs)("button",{type:"button",className:"pal-card pal-main",onClick:()=>s(e),children:[(0,a.jsx)("span",{className:"pal-ico",children:(0,a.jsx)(l,{size:18})}),(0,a.jsx)("span",{className:"pal-name",children:n.title}),(0,a.jsx)("span",{className:"pal-desc",children:n.desc}),(0,a.jsx)("span",{className:"pal-add",children:(0,a.jsx)(S.plus,{size:15})})]},e)})})]})}let nE="keiko.theme",nM="dark",nT=[/\bsk-[A-Za-z0-9_-]{20,}\b/,/\bAKIA[0-9A-Z]{16}\b/,/\bgh[pousr]_[A-Za-z0-9]{36,}\b/,/\bxox[abporsu]-[A-Za-z0-9-]{10,}\b/,/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/,/-----BEGIN [A-Z ]*PRIVATE KEY-----/],nq=/\b(?:\d[ -]?){13,19}\b/g;n(7011);let nP={chat:{lifecycle:["draft","streaming","final","archived"],trustBoundary:["ui","model","evidence"],authority:"user-confirm",persistence:"durable.ui"},files:{lifecycle:["connecting","connected","degraded","disconnected","error"],trustBoundary:["ui","fs"],authority:"user",persistence:"fs-reference"},connector:{lifecycle:["connecting","connected","degraded","disconnected","error"],trustBoundary:["ui","fs"],authority:"user",persistence:"fs-reference"},editor:{lifecycle:["viewing","editing","unsaved","saved","error"],trustBoundary:["ui","fs"],authority:"user",persistence:"fs-reference"},browser:{lifecycle:["idle","live","error"],trustBoundary:["ui","network"],authority:"user-confirm",persistence:"transient"},terminal:{lifecycle:["idle","running","blocked","cancelled","error"],trustBoundary:["ui","tool"],authority:"user-confirm",persistence:"transient"},review:{lifecycle:["proposed","needs-review","applied","reverted","archived"],trustBoundary:["ui","evidence"],authority:"user-confirm",persistence:"evidence-reference"},agents:{lifecycle:["proposed","running","blocked","needs-review","verified","cancelled"],trustBoundary:["ui","model","tool","evidence"],authority:"user-confirm",persistence:"durable.ui"},integ:{lifecycle:["idle","connecting","connected","degraded","disconnected","error"],trustBoundary:["ui","network"],authority:"user-confirm",persistence:"durable.config"},keiko:{lifecycle:["live"],trustBoundary:["ui","memory"],authority:"user",persistence:"memory-reference"},settings:{lifecycle:["viewing","editing","saved"],trustBoundary:["ui"],authority:"user",persistence:"durable.config"},project:{lifecycle:["none","connecting","connected","disconnected"],trustBoundary:["ui","fs"],authority:"user",persistence:"durable.config"},search:{lifecycle:["idle","searching","results","error"],trustBoundary:["ui","fs"],authority:"read-only",persistence:"transient"},plugins:{lifecycle:["idle","installed","disabled","enabled"],trustBoundary:["ui"],authority:"user",persistence:"durable.config"},automations:{lifecycle:["idle","enabled","disabled"],trustBoundary:["ui"],authority:"user",persistence:"durable.config"},mobile:{lifecycle:["paired","unpaired","error"],trustBoundary:["ui","network"],authority:"user-confirm",persistence:"durable.config"},inspector:{lifecycle:["empty","focused"],trustBoundary:["ui"],authority:"ui-only",persistence:"transient"},activity:{lifecycle:["live","archived"],trustBoundary:["ui"],authority:"read-only",persistence:"transient"},notifications:{lifecycle:["unread","read","dismissed"],trustBoundary:["ui"],authority:"ui-only",persistence:"transient"},resources:{lifecycle:["live"],trustBoundary:["ui"],authority:"read-only",persistence:"transient"},quality:{lifecycle:["idle","running","results","error"],trustBoundary:["ui","model","evidence"],authority:"user-confirm",persistence:"evidence-reference"},qiRun:{lifecycle:["running","final","needs-review","verified","failed","cancelled"],trustBoundary:["ui","model","evidence"],authority:"user-confirm",persistence:"evidence-reference"},relationships:{lifecycle:["idle","live","degraded","blocked","error"],trustBoundary:["ui","evidence"],authority:"user-confirm",persistence:"durable.ui"},figma:{lifecycle:["idle","running","results","error"],trustBoundary:["ui","evidence","network"],authority:"user-confirm",persistence:"evidence-reference"}},nA=["apikey","accesskey","clientsecret","credential","password","privatekey","secret","token"],nz=["api_key=","apikey=","client_secret=","clientsecret=","credential=","authorization:","password=","secret=","token="],nD=[".env",".env.local",".env.development",".env.test",".env.production"];function nL(e){return"number"==typeof e&&Number.isFinite(e)}function nF(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function nO(e){let t=e.trim();if(0===t.length)return!1;let n=t.toLowerCase();return function(e){for(let t of nT)if(t.test(e))return!0;for(let t of e.matchAll(nq)){let e=t[0].replaceAll(/[ -]/g,"");if(e.length>=13&&e.length<=19&&function(e){let t=0,n=!1;for(let a=e.length-1;a>=0;a-=1){let l=Number(e[a]);n&&(l*=2)>9&&(l-=9),t+=l,n=!n}return t%10==0}(e))return!0}return!1}(t)||function(e){let t="bearer ",n=e.toLowerCase().indexOf(t);if(-1===n)return!1;let a=0;for(let s=n+t.length;s<e.length;s+=1){var l;if(0===(null!=(l=e[s])?l:"").trim().length)break;a+=1}return a>=8}(t)||function(e){if(!e.includes("://"))return!1;try{let t=new URL(e);return t.username.length>0||t.password.length>0}catch(e){return!1}}(t)||nz.some(e=>n.includes(e))||function(e){let t=e.toLowerCase().replaceAll("\\","/").split("/");for(let e=0;e<t.length;e+=1){var n,a;let l=null!=(n=t[e])?n:"",s=null!=(a=t[e+1])?a:"";if(nD.includes(l)||".npmrc"===l||"credentials.json"===l||".aws"===l&&"credentials"===s||".ssh"===l&&s.startsWith("id_"))return!0}return!1}(t)}function nK(e){let t=[];for(let n of e){let e=function(e){var t;if(!nF(e)||!("string"==typeof(t=e.type)&&t in es))return null;let n=e.type;if("transient"===nP[n].persistence||"string"!=typeof e.id||!nL(e.x)||!nL(e.y)||!nL(e.w)||!nL(e.h)||!nL(e.z)||"boolean"!=typeof e.max)return null;let a={id:e.id,type:n,x:e.x,y:e.y,w:e.w,h:e.h,z:e.z,cfg:function(e,t){var n;if(!nF(t)||"durable.config"===nP[e].persistence)return{};let a=new Set((null!=(n=es[e].config)?n:[]).map(e=>e.key)),l={};for(let[n,s]of Object.entries(t)){if(!a.has(n))continue;let t=function(e,t,n){if("string"!=typeof n&&"number"!=typeof n&&"boolean"!=typeof n||function(e){let t=function(e){let t="";for(let n of e.toLowerCase())(n>="a"&&n<="z"||n>="0"&&n<="9")&&(t+=n);return t}(e);return nA.some(e=>t.includes(e))}(t))return;if("string"!=typeof n)return n;let a=nP[e].persistence;return"evidence-reference"===a?!function(e){if(0===e.length||e.length>256||e.startsWith(".")||e.trim()!==e||nO(e))return!1;for(let t of e)if(!function(e){let t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122||46===t||95===t||45===t}(t))return!1;return!0}(n)?void 0:n:nO(n)?"durable.ui"===a?"[REDACTED]":void 0:n}(e,n,s);void 0!==t&&(l[n]=t)}return l}(n,e.cfg),max:e.max},l=function(e){if(nF(e)&&nL(e.x)&&nL(e.y)&&nL(e.w)&&nL(e.h))return{x:e.x,y:e.y,w:e.w,h:e.h}}(e.prev);return{...a,...void 0!==l?{prev:l}:{},...nL(e.zoom)?{zoom:e.zoom}:{}}}(n);null!==e&&t.push(e)}return t}function nB(e,t){let n=new Set(t.map(e=>e.id)),a=[];for(let t of e)"string"==typeof t.id&&"string"==typeof t.a&&"string"==typeof t.b&&n.has(t.a)&&n.has(t.b)&&a.push({id:t.id,a:t.a,b:t.b});return a}let nW="keiko.workspace.v4",nU="keiko.conns.v1",n_="keiko.view";function nH(){try{let e=window.localStorage.getItem(n_);if(null===e)return{zoom:1,x:0,y:0};let t=JSON.parse(e);if("object"==typeof t&&null!==t&&"zoom"in t&&"number"==typeof t.zoom)return{zoom:t.zoom,x:"number"==typeof t.x?t.x:0,y:"number"==typeof t.y?t.y:0}}catch(e){}return{zoom:1,x:0,y:0}}function nJ(e){return Math.max(.3,Math.min(2.5,e))}function nV(e){return Math.max(.5,Math.min(2,Math.round(10*e)/10))}function nG(e){let t=e[0];for(let n=1;n<e.length;n++){let a=e[n];a.z>t.z&&(t=a)}return t}function nX(e,t){try{window.localStorage.setItem(e,JSON.stringify(t))}catch(e){}}let nY=["agent","capsule","capsule-set","chat","connector","data-source","evidence-run","mcp-tool","memory","patch-proposal","skill","tool","workflow-run","workspace-path"],nZ=["capsule","capsule-set","chat","evidence-run","memory","patch-proposal","tool","workflow-run","workspace-path"],nQ=["reads-context","proposes-patch","uses-tool","starts-workflow","produces-evidence","references-document","depends-on"],n$=["draft","active","archived","superseded","revoked","blocked","stale"],n0={"reads-context":{id:"reads-context",displayName:"reads context",semantics:"A consumer endpoint reads the contextual content of the target at a specific point in time.",validSourceKinds:["workflow-run","chat"],validTargetKinds:["memory","capsule","capsule-set","evidence-run","workspace-path","connector","data-source"],cardinality:"N:N",direction:"directed",lifecycle:{creatable:!0,immutable:!0,reconnectable:!1,deletable:!1,archivable:!0},auditEventOnMutation:!0,evidenceRelevance:"reference",ownerPackage:"@oscharko-dev/keiko-workflows",trustBoundary:"per-endpoint"},"proposes-patch":{id:"proposes-patch",displayName:"proposes patch",semantics:"A workflow run proposes a patch against one or more workspace paths. The relationship records the proposal; diff content stays in the harness PatchProposedEvent.",validSourceKinds:["workflow-run"],validTargetKinds:["workspace-path","patch-proposal"],cardinality:"1:N",direction:"directed",lifecycle:{creatable:!0,immutable:!0,reconnectable:!1,deletable:!0,archivable:!0},auditEventOnMutation:!0,evidenceRelevance:"reference",ownerPackage:"@oscharko-dev/keiko-workflows",trustBoundary:"fs"},"uses-tool":{id:"uses-tool",displayName:"uses tool",semantics:"A workflow run uses a registered tool. Per-call arguments and results remain in the harness ToolCallRequest / ToolCallResult envelopes.",validSourceKinds:["workflow-run"],validTargetKinds:["tool","mcp-tool"],cardinality:"N:N",direction:"directed",lifecycle:{creatable:!0,immutable:!0,reconnectable:!1,deletable:!1,archivable:!0},auditEventOnMutation:!0,evidenceRelevance:"reference",ownerPackage:"@oscharko-dev/keiko-workflows",trustBoundary:"tool"},"starts-workflow":{id:"starts-workflow",displayName:"starts workflow",semantics:"A chat or a parent workflow run initiates a workflow run. The relationship records the origin; run identity belongs to the workflow ledger.",validSourceKinds:["chat","workflow-run"],validTargetKinds:["workflow-run"],cardinality:"1:N",direction:"directed",lifecycle:{creatable:!0,immutable:!0,reconnectable:!1,deletable:!1,archivable:!0},auditEventOnMutation:!0,evidenceRelevance:"reference",ownerPackage:"@oscharko-dev/keiko-workflows",trustBoundary:"per-endpoint"},"produces-evidence":{id:"produces-evidence",displayName:"produces evidence",semantics:"A workflow run produces exactly one durable evidence-run record. If a run produces no evidence, no relationship is recorded.",validSourceKinds:["workflow-run"],validTargetKinds:["evidence-run"],cardinality:"1:1",direction:"directed",lifecycle:{creatable:!0,immutable:!0,reconnectable:!1,deletable:!1,archivable:!0},auditEventOnMutation:!0,evidenceRelevance:"produces",ownerPackage:"@oscharko-dev/keiko-evidence",trustBoundary:"evidence"},"references-document":{id:"references-document",displayName:"references document",semantics:"A chat or workflow run holds a structural pointer to a document (workspace file or local-knowledge capsule). Distinct from reads-context: a reference is structural, a read is an event.",validSourceKinds:["chat","workflow-run"],validTargetKinds:["workspace-path","capsule","capsule-set"],cardinality:"N:N",direction:"directed",lifecycle:{creatable:!0,immutable:!1,reconnectable:!0,deletable:!0,archivable:!0},auditEventOnMutation:!0,evidenceRelevance:"reference",ownerPackage:"@oscharko-dev/keiko-workflows",trustBoundary:"per-endpoint"},"depends-on":{id:"depends-on",displayName:"depends on",semantics:"A capsule, capsule-set, workflow run, or memory depends on another. Used by impact analysis (#542). Self-loops and direct two-edge cycles are forbidden at validation time; transitive cycle detection is deferred to impact traversal.",validSourceKinds:["capsule","capsule-set","workflow-run","memory"],validTargetKinds:["capsule","capsule-set","workflow-run","memory","evidence-run","workspace-path"],cardinality:"N:N",direction:"directed",lifecycle:{creatable:!0,immutable:!1,reconnectable:!0,deletable:!0,archivable:!0},auditEventOnMutation:!0,evidenceRelevance:"reference",ownerPackage:"@oscharko-dev/keiko-contracts",trustBoundary:"per-endpoint"}},n1=["prompt","documentcontent","filecontent","toolstdout","toolstderr","secret","credential","apikey","password","token"];class n2 extends Error{constructor(e,t,n,a=[]){super(t),this.name="RelationshipApiError",this.code=e,this.status=n,this.reasons=a}}async function n5(e){let t;try{t=await e.json()}catch(t){throw new n2("relationship/parse-error","Response is not valid JSON.",e.status)}if(!e.ok){var n;let a=t,l=null!=(n=a.error)?n:a,s="string"==typeof l.code?l.code:"relationship/unknown-error",i="string"==typeof l.message?l.message:"An unknown error occurred.",r=Array.isArray(a.reasons)?a.reasons:[];throw new n2(s,i,e.status,r)}return t}function n3(e){let t={"Content-Type":"application/json","X-Keiko-CSRF":"1"};return void 0!==e.idempotencyKey&&(t["Idempotency-Key"]=e.idempotencyKey),void 0!==e.ifMatch&&(t["If-Match"]=e.ifMatch),t}async function n4(e){let t={schemaVersion:"1",proposal:{type:e.type,source:{kind:e.source.kind,id:e.source.id},target:{kind:e.target.kind,id:e.target.id},...void 0!==e.summary?{summary:e.summary}:{}}},n=await fetch("/api/relationships/validate",{method:"POST",headers:n3({}),body:JSON.stringify(t)});return{decision:(await n5(n)).decision}}async function n6(e,t){let n={schemaVersion:"1",proposal:{type:e.type,source:{kind:e.source.kind,id:e.source.id},target:{kind:e.target.kind,id:e.target.id},...void 0!==e.summary?{summary:e.summary}:{}}},a=await fetch("/api/relationships",{method:"POST",headers:n3({idempotencyKey:t}),body:JSON.stringify(n)}),l=await n5(a);return{relationship:l.relationship,etag:l.etag}}async function n8(e){let t=new URLSearchParams;void 0!==e.lifecycle&&t.set("lifecycle",e.lifecycle),void 0!==e.type&&t.set("type",e.type),void 0!==e.sourceKind&&t.set("sourceKind",e.sourceKind),void 0!==e.targetKind&&t.set("targetKind",e.targetKind),void 0!==e.sourceId&&t.set("sourceId",e.sourceId),void 0!==e.targetId&&t.set("targetId",e.targetId),void 0!==e.limit&&t.set("limit",String(e.limit)),void 0!==e.cursor&&t.set("cursor",e.cursor);let n=await fetch("/api/relationships?".concat(t.toString())),a=await n5(n);return{entries:a.entries,truncated:a.truncated,nextCursor:a.nextCursor}}async function n7(e){let t=await fetch("/api/relationships/".concat(encodeURIComponent(e)));return(await n5(t)).relationship}async function n9(e,t,n,a){let l=await fetch("/api/relationships/".concat(encodeURIComponent(e)),{method:"PATCH",headers:n3({idempotencyKey:a,ifMatch:n}),body:JSON.stringify({schemaVersion:"1",...t})}),s=await n5(l);return{relationship:s.relationship,etag:s.etag}}async function ae(e,t,n){let a=await fetch("/api/relationships/".concat(encodeURIComponent(e)),{method:"DELETE",headers:n3({idempotencyKey:n,ifMatch:t})});return(await n5(a)).relationship}async function at(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=new URLSearchParams;void 0!==t.direction&&n.set("direction",t.direction),void 0!==t.maxDepth&&n.set("maxDepth",String(t.maxDepth)),void 0!==t.maxNodes&&n.set("maxNodes",String(t.maxNodes)),void 0!==t.maxRelationships&&n.set("maxRelationships",String(t.maxRelationships));let a=await fetch("/api/relationships/".concat(encodeURIComponent(e),"/dependencies?").concat(n.toString()));return(await n5(a)).report}async function an(e){return n5(await fetch("/api/relationships/".concat(encodeURIComponent(e),"/explain")))}async function aa(){return n5(await fetch("/api/relationships/health"))}let al=[{key:"t",mod:["cmd"]},{key:"t",mod:["ctrl"]},{key:"r",mod:["cmd"]},{key:"r",mod:["ctrl"]},{key:"n",mod:["cmd","shift"]},{key:"n",mod:["ctrl","shift"]},{key:"w",mod:["cmd"]},{key:"w",mod:["ctrl"]}];function as(e){switch(e.kind){case"ui.window.move":return"Move window";case"ui.window.resize":return"Resize window";case"ui.window.zorder":return"Reorder window";case"ui.window.close":return"Close window";case"ui.window.open":return"Open window";case"ui.workspace.pan":return"Pan workspace";case"ui.workspace.zoom":return"Zoom workspace";case"ui.workspace.fit":return"Fit workspace to view";case"ui.panel.toggle":return"Toggle ".concat(e.panel," panel");case"ui.selection.change":return"Change selection";case"ui.tab.switch":return"Switch tab"}}function ai(e){let t=[...e.mod].sort();return"".concat(t.join("+"),"|").concat(e.key.toLowerCase())}let ar={undoStack:[],redoStack:[]};class ao extends Error{constructor(e){super("Workspace keyboard shortcut conflicts detected: ".concat(e.map(e=>"".concat(ai(e.chord)," (").concat(e.commandIds.join(", "),")")).join("; "))),this.name="WorkspaceShortcutConflictError",this.conflicts=e}}class ac extends Error{constructor(e){super("Workspace keyboard shortcut bindings refused: ".concat(e.map(e=>"".concat(e.commandId," → ").concat(ai(e.chord))).join("; ")," are browser-reserved")),this.name="WorkspaceShortcutReservedError",this.reserved=e}}let ad=[{commandId:"undo",chord:{key:"z",mod:["cmd"]}},{commandId:"redo",chord:{key:"z",mod:["cmd","shift"]}},{commandId:"focus-status",chord:{key:"s",mod:["alt"]}}];function au(e){let{project:t,activeProjectPath:n,chats:s,activeChatId:i,onProject:r,onChat:o}=e,c=n===t.path,[d,u]=(0,l.useState)(c),h=t.available?"Available":"Unavailable";return(0,l.useEffect)(()=>{c&&u(!0)},[c]),(0,a.jsxs)("div",{className:"proj",children:[(0,a.jsxs)("button",{className:"proj-head",type:"button","data-active":c?"true":"false","aria-expanded":d,"aria-current":c?"true":void 0,"aria-label":"".concat(t.name," (").concat(h,")"),onClick:()=>{u(e=>!e),r(t)},children:[(0,a.jsx)("span",{className:"proj-caret","data-open":d,children:(0,a.jsx)(S.chevronR,{size:13})}),(0,a.jsx)(S.folder,{size:15}),(0,a.jsx)("span",{className:"proj-name",children:t.name}),(0,a.jsx)("span",{className:"chat-time",children:h})]}),d&&(0,a.jsx)("div",{className:"proj-chats",children:c?0===s.length?(0,a.jsx)("div",{className:"proj-empty",children:"No chats"}):s.map(e=>(0,a.jsxs)("button",{type:"button",className:"chat-row","data-active":i===e.id,"aria-pressed":i===e.id,onClick:()=>{o(e)},children:[(0,a.jsx)("span",{className:"chat-title",children:e.title}),void 0!==e.branchLabel?(0,a.jsx)("span",{className:"chat-meta mono",children:e.branchLabel}):null]},e.id)):(0,a.jsx)("div",{className:"proj-empty",children:"Select project to load chats"})})]})}function ah(){let e=r();return(0,a.jsxs)("div",{className:"tw-scroll",children:[(0,a.jsx)("div",{className:"sb-section",children:(0,a.jsx)("span",{className:"sb-section-label",children:"Projects"})}),0===e.projects.length?(0,a.jsx)("div",{className:"proj-empty",children:"No registered projects"}):e.projects.map(t=>{var n,l,s;return(0,a.jsx)(au,{project:t,activeProjectPath:null==(n=e.activeProject)?void 0:n.path,chats:(null==(l=e.activeProject)?void 0:l.path)===t.path?e.chats:[],activeChatId:null==(s=e.activeChat)?void 0:s.id,onProject:t=>{e.openProject(t)},onChat:t=>{e.openChat(t)}},t.path)})]})}function ap(e){let{name:t,icon:n}=e,l=null!=n?n:function(e){let t=e.toLowerCase();return"dockerfile"===t||t.includes("docker-compose")||t.endsWith(".dockerignore")?"docker":t.endsWith(".json")?"json":t.endsWith(".yml")||t.endsWith(".yaml")?"yaml":t.endsWith(".md")?"markdown":t.endsWith(".properties")||t.endsWith(".env")||t.startsWith(".env.")?"properties":t.endsWith(".java")?"java":t.endsWith(".tsx")?"react":t.endsWith(".ts")?"typescript":t.endsWith(".jsx")||t.endsWith(".js")||t.endsWith(".mjs")||t.endsWith(".cjs")?"javascript":t.endsWith(".py")?"python":t.endsWith(".go")?"go":t.endsWith(".rs")?"rust":t.endsWith(".gradle")?"gradle":t.endsWith(".sql")?"postgresql":t.endsWith(".html")?"html5":t.endsWith(".css")?"css3":t.endsWith(".graphql")||t.endsWith(".gql")?"graphql":t.endsWith(".png")||t.endsWith(".jpg")||t.endsWith(".jpeg")||t.endsWith(".gif")||t.endsWith(".webp")||t.endsWith(".svg")?"image":null}(t);return null!==l?(0,a.jsx)("img",{className:"fi-img",src:"/assets/icons/".concat(l,".svg"),width:"15",height:"15",alt:""}):(0,a.jsx)("span",{className:"fi-fallback",children:(0,a.jsx)(S.file,{size:14})})}let am=[{name:"backend",type:"folder",icon:"spring",children:[{name:"src/main/java/com/keiko/orca",type:"folder",children:[{name:"OrcaApplication.java",type:"file"},{name:"api",type:"folder",open:!1,children:[{name:"AgentController.java",type:"file"},{name:"WorkspaceController.java",type:"file"}]},{name:"service",type:"folder",open:!1,children:[{name:"InferenceService.java",type:"file"},{name:"AgentOrchestrator.java",type:"file"}]},{name:"config",type:"folder",open:!1,children:[{name:"SecurityConfig.java",type:"file"}]}]},{name:"src/main/resources",type:"folder",open:!1,children:[{name:"application.yml",type:"file"},{name:"schema.sql",type:"file"}]},{name:"build.gradle",type:"file"},{name:"Dockerfile",type:"file"}]},{name:"frontend",type:"folder",icon:"react",children:[{name:"src",type:"folder",children:[{name:"App.tsx",type:"file"},{name:"components",type:"folder",open:!1,children:[{name:"Workspace.tsx",type:"file"},{name:"WindowManager.tsx",type:"file"}]},{name:"api",type:"folder",open:!1,children:[{name:"client.ts",type:"file"},{name:"schema.graphql",type:"file"}]},{name:"styles",type:"folder",open:!1,children:[{name:"theme.css",type:"file"}]}]},{name:"package.json",type:"file",mut:"M"},{name:"tsconfig.json",type:"file"},{name:"Dockerfile",type:"file"}]},{name:"deploy",type:"folder",icon:"kubernetes",children:[{name:"k8s",type:"folder",children:[{name:"deployment.yaml",type:"file",icon:"kubernetes"},{name:"service.yaml",type:"file",icon:"kubernetes"},{name:"ingress.yaml",type:"file",icon:"kubernetes"}]},{name:"docker-compose.yml",type:"file"},{name:"prometheus.yml",type:"file",icon:"prometheus"}]},{name:".github/workflows",type:"folder",icon:"github",open:!1,children:[{name:"ci.yml",type:"file"},{name:"release.yml",type:"file"}]},{name:"README.md",type:"file"}];function af(e){let{node:t,depth:n,path:s,active:i,onPick:r}=e,[o,c]=(0,l.useState)(!1!==t.open),d=8+13*n,u="".concat(s,"/").concat(t.name);if("folder"===t.type){var h;return(0,a.jsxs)("div",{children:[(0,a.jsxs)("button",{className:"tr-row",style:{paddingLeft:d},onClick:()=>{c(e=>!e)},children:[(0,a.jsx)("span",{className:"tr-caret","data-open":o,children:(0,a.jsx)(S.chevronR,{size:11})}),void 0!==t.icon?(0,a.jsx)("img",{className:"fi-img",src:"/assets/icons/".concat(t.icon,".svg"),width:"15",height:"15",alt:""}):(0,a.jsx)("span",{className:"fi-fallback",style:{color:"var(--accent)"},children:(0,a.jsx)(S.folder,{size:14})}),(0,a.jsx)("span",{className:"tr-name tr-folder",children:t.name})]}),o&&(null==(h=t.children)?void 0:h.map((e,t)=>(0,a.jsx)(af,{node:e,depth:n+1,path:u,active:i,onPick:r},"".concat(u,"/").concat(e.name,"-").concat(String(t)))))]})}return(0,a.jsxs)("button",{className:"tr-row tr-file","data-active":i===u,style:{paddingLeft:d+14},onClick:()=>{r(u)},children:[(0,a.jsx)(ap,{name:t.name,icon:t.icon}),(0,a.jsx)("span",{className:"tr-name",children:t.name}),void 0!==t.mut&&(0,a.jsx)("span",{className:"file-mut",children:t.mut})]})}function ag(){var e,t;let[n,s]=(0,l.useState)("/frontend/src/App.tsx"),i=o(),r=null!=(t=null==i||null==(e=i.activeProject)?void 0:e.name)?t:"No project selected";return(0,a.jsxs)("div",{className:"srch",children:[(0,a.jsxs)("div",{className:"srch-box",children:[(0,a.jsx)(S.search,{size:15,"aria-hidden":"true"}),(0,a.jsx)("input",{type:"search","aria-label":"Search files and symbols",placeholder:"Search files & symbols…"}),(0,a.jsx)("span",{className:"kbd","aria-hidden":"true",children:"⇧⇧"})]}),(0,a.jsxs)("div",{className:"tw-label srch-label",children:[r," ",(0,a.jsx)("span",{className:"srch-meta mono",children:"workspace search"})]}),(0,a.jsx)("div",{className:"tr",children:am.map((e,t)=>(0,a.jsx)(af,{node:e,depth:0,path:"",active:n,onPick:s},"".concat(e.name,"-").concat(String(t))))})]})}let av=[{name:"Context7",img:"upstash",desc:"Up-to-date library docs",on:!0},{name:"Sequential Thinking",icon:"layers",desc:"Step-by-step reasoning",on:!0},{name:"Filesystem",icon:"files",desc:"Local file access",on:!0},{name:"GitHub",img:"github",desc:"Repos \xb7 PRs \xb7 issues",on:!0},{name:"Playwright",img:"playwright",desc:"Browser automation",on:!1},{name:"Brave Search",img:"brave",desc:"Web search",on:!1},{name:"MemoriaViva",icon:"cube",desc:"Knowledge graph",on:!0}],ax=[{name:"GitHub",img:"github",on:!0},{name:"Linear",img:"linear",on:!0},{name:"PostgreSQL",img:"postgresql",on:!0},{name:"Sentry",img:"sentry",on:!1},{name:"Slack",img:"slack",on:!1},{name:"Notion",img:"notion",on:!1}];function ay(e){let{img:t,icon:n,glyph:l}=e;if(void 0!==t)return(0,a.jsx)("img",{className:"pl-img",src:"/assets/icons/".concat(t,".svg"),width:"20",height:"20",alt:""});if(void 0!==n){let e=S[n];return(0,a.jsx)("span",{className:"pl-line",children:(0,a.jsx)(e,{size:18})})}return(0,a.jsx)("span",{className:"mono pl-glyph",children:l})}function ab(){let[e,t]=(0,l.useState)(av.map(e=>e.on)),n=e.filter(Boolean).length;return(0,a.jsxs)("div",{className:"plg",children:[(0,a.jsxs)("div",{className:"plg-sec",children:[(0,a.jsx)("span",{className:"plg-sec-t",children:"MCP Servers"}),(0,a.jsxs)("span",{className:"plg-sec-c mono",children:[n,"/",av.length," active"]})]}),av.map((n,l)=>{var s;let i=null!=(s=e[l])&&s;return(0,a.jsxs)("div",{className:"plg-row",children:[(0,a.jsx)("span",{className:"plg-ico",children:(0,a.jsx)(ay,{img:n.img,icon:n.icon})}),(0,a.jsxs)("span",{className:"plg-text",children:[(0,a.jsx)("span",{className:"plg-name",children:n.name}),(0,a.jsx)("span",{className:"plg-desc",children:n.desc})]}),(0,a.jsx)("button",{className:"plg-dot".concat(i?" on":""),title:i?"Running":"Stopped","aria-label":"".concat(n.name,": ").concat(i?"running":"stopped"),onClick:()=>{t(e=>{var t;let n=[...e];return n[l]=!(null!=(t=n[l])&&t),n})}})]},n.name)}),(0,a.jsx)("div",{className:"plg-sec plg-sec2",children:(0,a.jsx)("span",{className:"plg-sec-t",children:"Connectors"})}),ax.map(e=>(0,a.jsxs)("button",{className:"plg-row plg-conn","data-on":e.on,children:[(0,a.jsx)("span",{className:"plg-ico",children:(0,a.jsx)(ay,{img:e.img})}),(0,a.jsxs)("span",{className:"plg-text",children:[(0,a.jsx)("span",{className:"plg-name",children:e.name}),(0,a.jsx)("span",{className:"plg-desc",children:e.on?"Connected":"Not connected"})]}),e.on?(0,a.jsx)("span",{className:"integ-on",children:(0,a.jsx)(S.check,{size:13})}):(0,a.jsx)("span",{className:"integ-add",children:(0,a.jsx)(S.plus,{size:14})})]},e.name))]})}let aj=[{id:"nightly-review",name:"Nightly review",when:"02:00 daily",defaultOn:!0},{id:"on-push-lint",name:"On push → lint",when:"git push",defaultOn:!0},{id:"weekly-digest",name:"Weekly digest",when:"Mon 09:00",defaultOn:!1}],aw="keiko.automations.v1",ak=Object.fromEntries(aj.map(e=>[e.id,e.defaultOn]));function aN(){try{let e=localStorage.getItem(aw);if(null===e)return{...ak};let t=JSON.parse(e);if("object"!=typeof t||null===t||Array.isArray(t))return{...ak};let n={...ak};for(let[e,a]of Object.entries(t))e in ak&&"boolean"==typeof a&&(n[e]=a);return n}catch(e){return{...ak}}}function aS(){let[e,t]=(0,l.useState)(aN);return(0,a.jsx)("div",{className:"tw-list",children:aj.map(n=>{var l;let s=null!=(l=e[n.id])?l:n.defaultOn;return(0,a.jsxs)("div",{className:"auto-row",children:[(0,a.jsx)("span",{className:"dot",style:{background:s?"var(--accent)":"var(--fg-faint)"}}),(0,a.jsxs)("span",{className:"auto-text",children:[(0,a.jsx)("span",{className:"auto-name",children:n.name}),(0,a.jsx)("span",{className:"auto-when mono",children:n.when})]}),(0,a.jsx)(tw,{on:s,onChange:()=>{var e;e=n.id,t(t=>{var n;let a={...t,[e]:!(null!=(n=t[e])&&n)};return localStorage.setItem(aw,JSON.stringify(a)),a})},label:n.name})]},n.id)})})}function aC(){return(0,a.jsxs)("div",{className:"tw-pad mob",children:[(0,a.jsxs)("div",{className:"mob-qr",children:[(0,a.jsx)("div",{className:"ph-stripes"}),(0,a.jsx)(S.mobile,{size:28,style:{position:"relative",color:"var(--fg-dim)"}})]}),(0,a.jsx)("div",{className:"mob-title",children:"Keiko mobile"}),(0,a.jsx)("div",{className:"mob-sub",children:"Scan to continue this workspace on your phone."})]})}function aR(){let{wins:e,active:t,winCount:n}=(0,l.useContext)(k),s=null!==t?es[t.type]:null,i=null!==t?Object.entries(t.cfg).filter(e=>{let[,t]=e;return""!==t&&null!=t}):[];return(0,a.jsxs)("div",{className:"tw-pad",children:[(0,a.jsx)("div",{className:"rb-section-label",style:{marginTop:0},children:"Active window"}),null!==t&&null!==s?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"insp-top",children:[(0,a.jsx)("span",{className:"insp-ico",style:{color:!0===s.accent?"var(--accent)":"var(--fg-muted)"},children:function(e,t){let n=S[e];return(0,a.jsx)(n,{size:16})}(s.icon,16)}),(0,a.jsx)("span",{className:"insp-title",children:s.title})]}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Size"}),(0,a.jsxs)("span",{className:"rb-row-v mono",children:[Math.round(t.w)," \xd7 ",Math.round(t.h)]})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Position"}),(0,a.jsxs)("span",{className:"rb-row-v mono",children:[Math.round(t.x),", ",Math.round(t.y)]})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"State"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:t.max?"maximized":"floating"})]})]}),i.length>0&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"rb-section-label",children:"Configuration"}),(0,a.jsx)("div",{className:"rb-rows",children:i.map(e=>{let[t,n]=e;return(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:t}),(0,a.jsx)("span",{className:"rb-row-v mono",children:String(n).slice(0,20)||"—"})]},t)})})]}),(0,a.jsx)("div",{className:"rb-section-label insp-governance",children:"Governance"}),(0,a.jsxs)("div",{className:"rb-rows insp-governance","data-testid":"insp-governance",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Authority"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:nP[t.type].authority})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Persistence"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:nP[t.type].persistence})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Trust"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:nP[t.type].trustBoundary.join(", ")})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Lifecycle"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:nP[t.type].lifecycle.join(" → ")})]})]})]}):(0,a.jsx)("div",{className:"insp-empty",children:"No window focused"}),(0,a.jsx)("div",{className:"rb-section-label",children:"Workspace"}),(0,a.jsx)("div",{className:"rb-rows",children:(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Open windows"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:n})]})})]})}let aI=[{t:"Agent finished build-board",time:"2m",c:"var(--accent)"},{t:"diff-review ready to merge",time:"9m",c:"var(--info)"},{t:"lint-pass queued",time:"14m",c:"var(--fg-faint)"}];function aE(){return(0,a.jsx)("div",{className:"tw-list",children:aI.map((e,t)=>(0,a.jsxs)("div",{className:"nt-row",children:[(0,a.jsx)("span",{className:"dot",style:{background:e.c,marginTop:6}}),(0,a.jsxs)("span",{className:"nt-text",children:[(0,a.jsx)("span",{className:"nt-title",children:e.t}),(0,a.jsxs)("span",{className:"nt-time mono",children:[e.time," ago"]})]})]},t))})}function aM(){return(0,a.jsxs)("div",{className:"tw-pad",children:[(0,a.jsxs)("div",{className:"rb-placeholder",style:{height:150},children:[(0,a.jsx)("div",{className:"ph-stripes"}),(0,a.jsx)("span",{className:"rb-ph-label mono",children:"resources"})]}),(0,a.jsx)("div",{className:"rb-foot mono",style:{marginTop:14},children:"grows with the product"})]})}let aT="keiko-activity",aq={step:"var(--fg-dim)",approval:"var(--warn)",approved:"var(--accent)",rejected:"var(--danger)",stopped:"var(--danger)",open:"var(--info)","twin-approved":"var(--accent)","twin-denied":"var(--danger)"};function aP(){let e=function(){var e;let[,t]=(0,l.useState)(0);return(0,l.useEffect)(()=>{let e=()=>{t(e=>e+1)};return window.addEventListener(aT,e),()=>{window.removeEventListener(aT,e)}},[]),null!=(e=window.__keikoActivity)?e:[]}();return(0,a.jsxs)("div",{className:"tl",children:[0===e.length&&(0,a.jsxs)("div",{className:"tl-empty",children:["No activity yet.",(0,a.jsx)("br",{}),"Start an agent to see its actions stream here."]}),e.map((e,t)=>{var n,l;return(0,a.jsxs)("div",{className:"tl-row",children:[(0,a.jsx)("span",{className:"tl-dot",style:{background:null!=(n=aq[e.type])?n:"var(--fg-faint)"}}),(0,a.jsxs)("div",{className:"tl-body",children:[(0,a.jsx)("span",{className:"tl-text",children:e.text}),(0,a.jsxs)("span",{className:"tl-meta mono",children:[null!=(l=e.agent)?l:"workspace"," \xb7 ",new Date(e.time).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})]})]})]},t)})]})}function aA(e){let{chatId:t,scopeKind:n,currentScopeKind:s,candidateRelativePaths:i,onConnected:r,chat:o,updateScope:c=$.Mr,now:d=Date.now}=e,u=(0,l.useId)(),[h,p]=(0,l.useState)(!1),[m,f]=(0,l.useState)(null),g="workspace-root"!==n&&0===i.length,v=g||h,x=void 0!==s?"Update connected scope":"workspace-root"===n?"Connect repository":"directory"===n?"Connect folder":"Connect to chat",y=g?"Select a folder or file first":x;async function b(){if(!v){f(null),p(!0);try{let e={kind:n,relativePaths:[...i],connectedAtMs:d()},a=[...eh(null!=o?o:{}).filter(t=>t.kind!==e.kind||JSON.stringify(t.relativePaths)!==JSON.stringify(e.relativePaths)),e],l=await c(t,a);null==r||r(l.chat)}catch(e){f(e instanceof $.hD?"".concat(e.code,": ").concat(e.message):e instanceof Error?e.message:"Unable to connect scope.")}finally{p(!1)}}}return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",className:"scope-connect-btn",disabled:h,"aria-disabled":g,"aria-label":g?"Connect to chat (no selection)":x,"aria-describedby":g?u:void 0,title:y,onClick:()=>{g||b()},children:h?"Connecting…":x}),g?(0,a.jsx)("span",{id:u,className:"scope-connect-hint",children:"Select a folder or file first."}):null,null!==m?(0,a.jsx)("span",{role:"alert",className:"scope-connect-error",children:m}):null]})}let az={jsx:"js",js:"js",mjs:"js",ts:"ts",tsx:"ts",java:"java",kt:"kotlin",kts:"kotlin",py:"py",rb:"py",go:"go",rs:"rust",json:"json",yml:"yaml",yaml:"yaml",md:"md",markdown:"md",html:"html",xml:"html",css:"css",sql:"sql",sh:"sh",bash:"sh",cob:"cobol",cbl:"cobol",gradle:"js",graphql:"graphql",gql:"graphql",properties:"props",toml:"props",env:"props",dockerfile:"docker"};function aD(e){var t;let n=e.toLowerCase();if(".env"===n||n.startsWith(".env."))return"props";if("dockerfile"===n||n.startsWith("dockerfile"))return"docker";if(n.includes("docker-compose"))return"yaml";let a=n.split("."),l=a.length>1?a[a.length-1]:void 0;return void 0===l?"code":null!=(t=az[l])?t:"code"}let aL=new Set("const let var function return if else for while do switch case break continue import from export default class extends implements interface enum new async await yield of in typeof instanceof this super public private protected static final readonly void int long double float boolean char byte short val fun object data override companion package def pass lambda try catch except finally throw throws raise with as not and or is null nil None True False true false undefined struct impl trait pub use mod match where select insert update delete create table from join on group by order limit FROM RUN CMD ENV COPY WORKDIR EXPOSE ENTRYPOINT AS".split(" "));function aF(e){let t=[];return e.split(/(`[^`]+`|\*\*[^*]+\*\*)/).forEach(e=>{""!==e&&(e.startsWith("`")?t.push(["str",e]):e.startsWith("**")?t.push(["type",e]):t.push(["id",e]))}),t.length>0?t:[["id",e]]}function aO(e,t){if("md"===t)return e.split("\n").map(e=>{if(/^#{1,6}\s/.test(e))return[["head",e]];if(/^\s*```/.test(e))return[["com",e]];let t=/^(\s*)([-*+]|\d+\.)(\s)/.exec(e);if(null!==t){var n,a,l;let s=null!=(n=t[1])?n:"";return[["ws",s],["key",null!=(a=t[2])?a:""],["ws",null!=(l=t[3])?l:""],...aF(e.slice(t[0].length))]}return aF(e)});if("json"===t)return e.split("\n").map(e=>{let t=[],n=0;for(;n<e.length;){let a=e.slice(n),l=/^"(?:[^"\\]|\\.)*"/.exec(a);if(null!==l){let a=e.slice(n+l[0].length),s=/^\s*:/.test(a);t.push([s?"key2":"str",l[0]]),n+=l[0].length;continue}let s=/^-?\d[\d.eE+\-]*/.exec(a);if(null!==s){t.push(["num",s[0]]),n+=s[0].length;continue}let i=/^(true|false|null)\b/.exec(a);if(null!==i){t.push(["lit",i[0]]),n+=i[0].length;continue}let r=/^\s+/.exec(a);if(null!==r){t.push(["ws",r[0]]),n+=r[0].length;continue}t.push(["punct",a.charAt(0)]),n+=1}return t});let n="py"===t||"sh"===t||"yaml"===t||"props"===t||"docker"===t?{line:"#",block:null}:"sql"===t?{line:"--",block:["/*","*/"]}:"cobol"===t?{line:"*>",block:null}:"html"===t?{line:null,block:["\x3c!--","--\x3e"]}:{line:"//",block:["/*","*/"]},a={inBlock:!1},l=[];for(let t of e.split("\n"))l.push(function(e,t,n){let a=[],l=0;if(t.inBlock&&null!==n.block){let s=e.indexOf(n.block[1]);if(-1===s)return a.push(["com",e]),a;a.push(["com",e.slice(0,s+n.block[1].length)]),l=s+n.block[1].length,t.inBlock=!1}for(;l<e.length;){let i=e.slice(l);if(null!==n.line&&i.startsWith(n.line)){a.push(["com",i]);break}if(null!==n.block&&i.startsWith(n.block[0])){let s=e.indexOf(n.block[1],l+n.block[0].length);if(-1===s){a.push(["com",i]),t.inBlock=!0;break}a.push(["com",e.slice(l,s+n.block[1].length)]),l=s+n.block[1].length;continue}let r=/^(?:"(?:[^"\\]|\\.)*"?|'(?:[^'\\]|\\.)*'?)/.exec(i);if(null!==r&&r[0].length>1){a.push(["str",r[0]]),l+=r[0].length;continue}if(/^\d/.test(i)){var s;let e=/^\d[\w.]*/.exec(i),t=null!=(s=null==e?void 0:e[0])?s:i.charAt(0);a.push(["num",t]),l+=t.length;continue}let o=/^[@A-Za-z_$][\w$]*/.exec(i);if(null!==o){let t=o[0],n="id";aL.has(t)?n="key":t.startsWith("@")||/^[A-Z]/.test(t)?n="type":"("===e.charAt(l+t.length)&&(n="fn"),a.push([n,t]),l+=t.length;continue}let c=/^\s+/.exec(i);if(null!==c){a.push(["ws",c[0]]),l+=c[0].length;continue}let d=/^[^\w\s$@]+/.exec(i);if(null!==d){a.push(["punct",d[0]]),l+=d[0].length;continue}a.push(["id",i.charAt(0)]),l+=1}return a}(t,a,n));return l}function aK(e){if(!Number.isFinite(e)||e<=0)return"0 B";let t=["B","KB","MB","GB"],n=e,a=0;for(;n>=1024&&a<t.length-1;)n/=1024,a+=1;let l=0===a?n.toFixed(0):n.toFixed(n>=10?1:2);return"".concat(l," ").concat(t[a])}function aB(e){return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(new Date(e))}function aW(e){let{label:t,value:n}=e;return(0,a.jsxs)("div",{className:"fpv-meta-row",children:[(0,a.jsx)("span",{children:t}),(0,a.jsx)("strong",{children:n})]})}function aU(e){var t,n,s,i,r;let{root:c,path:d,onClose:u}=e,h=o(),p=null==h?void 0:h.activeChat,m=d.length>0?[d]:[],[f,g]=(0,l.useState)(null),[v,x]=(0,l.useState)(!0),[y,b]=(0,l.useState)(null);(0,l.useEffect)(()=>{let e=!1;return x(!0),b(null),g(null),(0,$.q7)(c,d).then(t=>{e||g(t)}).catch(t=>{e||b(t instanceof $.hD&&"DENIED"===t.code?{message:"This file is excluded from the read surface for safety (matches a deny pattern such as .env, *.pem, node_modules, .git, …).",denied:!0}:t instanceof Error?{message:t.message,denied:!1}:{message:"Unable to read this file.",denied:!1})}).finally(()=>{e||x(!1)}),()=>{e=!0}},[d,c]);let j=(null==y?void 0:y.denied)===!0,w=null!==f?"text"===f.kind?aD(f.name):"image"===f.kind?f.mime:null!=(r=f.extension)?r:"binary":j?"denied":null!==y?"error":"loading",k=j?"Hidden file":null!=(n=null==f?void 0:f.name)?n:null!==y?"Preview unavailable":"Loading preview",N=(null==f?void 0:f.kind)==="text"&&f.content.length<=2e5,C=(null==f?void 0:f.kind)==="text"?N?aO(f.content,aD(f.name)):f.content.split("\n").map(e=>[["id",e]]):[];return(0,a.jsxs)("div",{className:"fpv",children:[(0,a.jsxs)("div",{className:"fpv-bar",children:[(0,a.jsx)("button",{className:"fpv-back",type:"button",onClick:u,title:"Back to files","aria-label":"Back to files",children:(0,a.jsx)(S.back,{size:15})}),(0,a.jsx)(ap,{name:j||null===f?"":f.name}),(0,a.jsx)("span",{className:"fpv-name",title:k,children:k}),(0,a.jsx)("span",{className:"fpv-lang mono",children:w}),(0,a.jsx)("span",{className:"spacer"}),void 0!==p&&null!==h?(0,a.jsx)(aA,{chatId:p.id,scopeKind:"files",currentScopeKind:null==(t=p.connectedScope)?void 0:t.kind,candidateRelativePaths:m,chat:p,onConnected:h.replaceChat}):null,(0,a.jsx)("button",{className:"fpv-back",type:"button",onClick:u,title:"Close preview","aria-label":"Close preview",children:(0,a.jsx)(S.close,{size:15})})]}),v?(0,a.jsx)("div",{className:"fpv-state",children:"Loading preview..."}):null,null!==y?(0,a.jsx)("div",{className:"fpv-state fpv-error",role:"alert",children:y.message}):null,(null==f?void 0:f.kind)==="text"?(0,a.jsxs)(a.Fragment,{children:[f.truncated?(0,a.jsxs)("div",{className:"fpv-banner",children:["Preview truncated at ",aK(f.maxBytes),". Open the file in the editor for full content."]}):null,N?null:(0,a.jsx)("div",{className:"fpv-banner",children:"Syntax highlighting disabled for large previews."}),(0,a.jsx)("div",{className:"fpv-code mono",children:C.map((e,t)=>(0,a.jsxs)("div",{className:"fpv-line",children:[(0,a.jsx)("span",{className:"fpv-num",children:t+1}),(0,a.jsx)("span",{className:"fpv-src",children:e.map((e,t)=>(0,a.jsx)("span",{className:"hl-".concat(e[0]),children:e[1]},t))})]},t))})]}):null,(null==f?void 0:f.kind)==="image"?(0,a.jsxs)("div",{className:"fpv-image-pane",children:[(0,a.jsx)("div",{className:"fpv-image-card",children:(0,a.jsx)("img",{className:"fpv-image",src:f.dataUrl,alt:f.name})}),(0,a.jsxs)("div",{className:"fpv-meta",children:[(0,a.jsx)(aW,{label:"Type",value:f.mime}),(0,a.jsx)(aW,{label:"Size",value:aK(f.sizeBytes)}),(0,a.jsx)(aW,{label:"Modified",value:aB(f.modifiedAt)})]})]}):null,(null==f?void 0:f.kind)==="binary"?(0,a.jsx)("div",{className:"fpv-meta-pane",children:(0,a.jsxs)("div",{className:"fpv-meta-card",children:[(0,a.jsx)(ap,{name:f.name}),(0,a.jsx)("h3",{children:f.name}),(0,a.jsx)("p",{children:"too_large"===f.reason?"Preview disabled because this file exceeds ".concat(aK(null!=(s=f.maxBytes)?s:0),"."):"No safe text or image preview is available for this file type."}),(0,a.jsxs)("div",{className:"fpv-meta",children:[(0,a.jsx)(aW,{label:"Type",value:f.mime}),(0,a.jsx)(aW,{label:"Extension",value:null!=(i=f.extension)?i:"none"}),(0,a.jsx)(aW,{label:"Size",value:aK(f.sizeBytes)}),(0,a.jsx)(aW,{label:"Modified",value:aB(f.modifiedAt)})]})]})}):null]})}function a_(e){let t=e.replace(/[/\\]+$/,""),n=Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\"));return n<0?null:0===n?"/":/^[A-Za-z]:$/.test(t.slice(0,n))?"".concat(t.slice(0,n),"\\"):t.slice(0,n)}function aH(e){var t;let{root:n,onActiveFileChange:s,onRootChange:i}=e,r=o(),c=null==r?void 0:r.activeChat,d=null==n?void 0:n.trim(),u=void 0!==d&&d.length>0?d:null,[h,p]=(0,l.useState)(null),m=null!=(t=null!=u?u:h)?t:"",[f,g]=(0,l.useState)(null),[v,x]=(0,l.useState)(""),[y,b]=(0,l.useState)(null),[j,w]=(0,l.useState)({}),[k,N]=(0,l.useState)(()=>new Set([""])),[C,R]=(0,l.useState)(0),I=(0,l.useRef)(s);I.current=s,(0,l.useEffect)(()=>{if(null!==u)return;let e=!1;return(0,$.vj)().then(t=>{var n;if(e)return;let a=null==(n=t.projects.find(e=>e.available))?void 0:n.path;p(null!=a?a:null)}).catch(()=>{e||p(null)}),()=>{e=!0}},[u]);let E=(0,l.useCallback)(async e=>{if(0===m.length)return void w(t=>({...t,[e]:{entries:[],truncated:!1,loading:!1,error:"No registered project is available."}}));w(t=>{var n,a,l,s;return{...t,[e]:{entries:null!=(l=null==(n=t[e])?void 0:n.entries)?l:[],truncated:null!=(s=null==(a=t[e])?void 0:a.truncated)&&s,loading:!0,error:null}}});try{let n=await (0,$.KD)(m,e);if(""===e){var t;g(n.root),null==(t=I.current)||t.call(I,null,n.root)}w(t=>({...t,[e]:{entries:n.entries,truncated:n.truncated,loading:!1,error:null}}))}catch(t){w(n=>{var a,l,s,i;return{...n,[e]:{entries:null!=(s=null==(a=n[e])?void 0:a.entries)?s:[],truncated:null!=(i=null==(l=n[e])?void 0:l.truncated)&&i,loading:!1,error:t instanceof Error?t.message:"Unable to read this folder."}}})}},[m]);(0,l.useEffect)(()=>{var e;b(null),null==(e=I.current)||e.call(I,null,null),g(null),N(new Set([""])),w({}),E("")},[m,E,C]),(0,l.useEffect)(()=>{x(null!=f?f:m.length>0?m:"")},[f,m]);let M=(0,l.useCallback)(e=>{let t=e.trim();void 0!==i&&0!==t.length&&t!==(null!=f?f:m)&&i(t)},[i,f,m]),T=(0,l.useCallback)(()=>{let e=a_(null!=f?f:m);null!==e&&M(e)},[f,m,M]),q=(e,t)=>{var n;return null===r||void 0===c||0===m.length||"workspace-root"!==e&&0===t.length?null:(0,a.jsx)(aA,{chatId:c.id,scopeKind:e,currentScopeKind:null==(n=c.connectedScope)?void 0:n.kind,candidateRelativePaths:"workspace-root"===e?[]:[t],chat:c,onConnected:r.replaceChat})},P=function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:j[e];return(0,a.jsxs)("div",{className:"tr-dir",children:[(null==n?void 0:n.loading)===!0?(0,a.jsx)("div",{className:"files-note",style:{paddingLeft:22+13*t},children:"Loading..."}):null,(null==n?void 0:n.error)!==null&&(null==n?void 0:n.error)!==void 0?(0,a.jsxs)("div",{className:"files-error",style:{marginLeft:8+13*t},children:[(0,a.jsx)("span",{children:n.error}),(0,a.jsx)("button",{type:"button",onClick:()=>{E(e)},children:"Retry"})]}):null,null==n?void 0:n.entries.map(e=>((e,t)=>{let n=8+13*t,l=k.has(e.path);if("directory"===e.kind){let s=j[e.path];return(0,a.jsxs)("div",{className:"tr-row-wrap",children:[(0,a.jsxs)("button",{className:"tr-row","data-readable":e.readable,style:{paddingLeft:n},type:"button",disabled:!e.readable,"aria-expanded":l,onClick:()=>(e=>{if(!e.readable)return;let t=k.has(e.path);N(t=>{let n=new Set(t);return n.has(e.path)?n.delete(e.path):n.add(e.path),n}),t||void 0!==j[e.path]||E(e.path)})(e),title:e.readable?e.path:"Symlink target is outside the selected root",children:[(0,a.jsx)("span",{className:"tr-caret","data-open":l,children:(0,a.jsx)(S.chevronR,{size:11})}),(0,a.jsx)("span",{className:"fi-fallback",style:{color:"var(--accent)"},children:(0,a.jsx)(S.folder,{size:14})}),(0,a.jsx)("span",{className:"tr-name tr-folder",children:e.name}),e.symlink?(0,a.jsx)("span",{className:"tr-badge",children:"link"}):null]}),e.readable?(0,a.jsx)("div",{className:"tr-connect",style:{paddingLeft:n+20},children:q("directory",e.path)}):null,l?P(e.path,t+1,s):null]},e.path)}return(0,a.jsxs)("button",{className:"tr-row tr-file","data-active":y===e.path,"data-readable":e.readable,style:{paddingLeft:n+14},type:"button",disabled:!e.readable,onClick:()=>{var t;b(e.path),null==(t=I.current)||t.call(I,e.path,null!=f?f:m)},title:e.readable?e.path:"Symlink target is outside the selected root",children:[(0,a.jsx)(ap,{name:e.name}),(0,a.jsx)("span",{className:"tr-name",children:e.name}),e.symlink?(0,a.jsx)("span",{className:"tr-badge",children:"link"}):null,(0,a.jsx)("span",{className:"tr-meta mono",children:function(e){if(!Number.isFinite(e)||e<=0)return"0 B";let t=["B","KB","MB","GB"],n=e,a=0;for(;n>=1024&&a<t.length-1;)n/=1024,a+=1;let l=0===a?n.toFixed(0):n.toFixed(n>=10?1:2);return"".concat(l," ").concat(t[a])}(e.sizeBytes)})]},e.path)})(e,t)),void 0===n||n.loading||null!==n.error||0!==n.entries.length?null:(0,a.jsx)("div",{className:"files-note",style:{paddingLeft:22+13*t},children:"Empty folder."}),(null==n?void 0:n.truncated)===!0?(0,a.jsx)("div",{className:"files-note files-warning",style:{paddingLeft:22+13*t},children:"Showing the first 1000 entries."}):null]})};return null!==y?(0,a.jsx)(aU,{root:null!=f?f:m,path:y,onClose:()=>{var e;b(null),null==(e=I.current)||e.call(I,null,null!=f?f:m)}}):(0,a.jsxs)("div",{className:"files",children:[void 0!==i?(0,a.jsxs)("form",{className:"files-root-bar",role:"group","aria-label":"Folder root",onSubmit:e=>{e.preventDefault(),M(v)},children:[(0,a.jsx)("button",{type:"button",className:"files-root-up",onClick:T,disabled:null===a_(null!=f?f:m),title:"Open parent folder","aria-label":"Open parent folder",children:(0,a.jsx)(S.arrowUp,{size:13})}),(0,a.jsx)("input",{type:"text",className:"files-root-input mono","aria-label":"Folder path — open any folder on this machine",placeholder:"/path/to/any/folder",spellCheck:!1,value:v,onChange:e=>x(e.target.value)}),(0,a.jsx)("button",{type:"submit",className:"files-root-open",title:"Open this folder",children:"Open"})]}):null,(0,a.jsx)("button",{className:"files-refresh",type:"button",onClick:()=>R(e=>e+1),title:"Refresh folder","aria-label":"Refresh folder",children:(0,a.jsx)(S.reset,{size:13})}),(()=>{let e=q("workspace-root","");return null===e?null:(0,a.jsxs)("div",{className:"files-scope-bar",role:"group","aria-label":"Repository scope connector",children:[(0,a.jsx)("span",{className:"files-scope-label",children:"Repository scope"}),e]})})(),(0,a.jsx)("div",{className:"tr files-tree",children:P("",0)})]})}let aJ=[{n:1,t:[["k","const"],[""," "],["v","{ useState }"],[""," = "],["v","React"]]},{n:2,t:[]},{n:3,t:[["k","function"],[""," "],["f","WindowFrame"],["p","({ win, on })"],[""," {"]]},{n:4,t:[[""," "],["k","const"],[""," [drag, setDrag] = "],["f","useState"],["p","(null)"]]},{n:5,t:[[""," "],["k","return"],[""," "],["p","<section"],["a"," className"],["","="],["s",'"window"'],["p",">"]]},{n:6,t:[[""," "],["c","// drag \xb7 resize \xb7 snap"]]},{n:7,t:[[""," "],["p","</section>"]]},{n:8,t:[["","}"]]}];function aV(e){let{file:t="windows.jsx"}=e;return(0,a.jsxs)("div",{className:"editor",children:[(0,a.jsxs)("div",{className:"ed-tabs mono",children:[(0,a.jsxs)("span",{className:"ed-tab active",children:[(0,a.jsx)(S.editor,{size:12})," ",t]}),(0,a.jsx)("span",{className:"ed-tab",children:"styles.css"})]}),(0,a.jsx)("div",{className:"ed-code mono",children:aJ.map(e=>(0,a.jsxs)("div",{className:"ed-line",children:[(0,a.jsx)("span",{className:"ed-num",children:e.n}),(0,a.jsx)("span",{className:"ed-src",children:e.t.map((e,t)=>(0,a.jsx)("span",{className:""===e[0]?void 0:"tk-".concat(e[0]),children:e[1]},t))})]},e.n))})]})}async function aG(e,t){var n,a;let l=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),s="GET"!==l&&"HEAD"!==l,i=await fetch(e,{...t,headers:{Accept:"application/json",...s?{"Content-Type":"application/json"}:{},...s?{"X-Keiko-CSRF":"1"}:{},...null!=(a=null==t?void 0:t.headers)?a:{}}});if(!i.ok){let e="INTERNAL",t="HTTP ".concat(i.status.toString());try{let n=await i.json();e=n.error.code,t=n.error.message}catch(e){}throw new $.hD(e,t,i.status)}if(204!==i.status)return i.json()}async function aX(e){return aG("/api/browser/status?port=".concat(encodeURIComponent(String(e))))}async function aY(e){return aG("/api/browser/sessions",{method:"POST",body:JSON.stringify({port:e})})}async function aZ(e){await aG("/api/browser/sessions/".concat(encodeURIComponent(e)),{method:"DELETE"})}async function aQ(e,t){return aG("/api/browser/sessions/".concat(encodeURIComponent(e),"/navigate"),{method:"POST",body:JSON.stringify({url:t})})}async function a$(e){return aG("/api/browser/sessions/".concat(encodeURIComponent(e),"/screenshot"),{method:"POST",body:JSON.stringify({})})}async function a0(e,t){return aG("/api/browser/sessions/".concat(encodeURIComponent(e),"/apply"),{method:"POST",body:JSON.stringify({captureSeq:t})})}async function a1(e){return aG("/api/browser/sessions/".concat(encodeURIComponent(e),"/content"),{method:"POST",body:JSON.stringify({})})}function a2(e){return e instanceof $.hD?{code:e.code,message:e.message}:e instanceof Error?{code:"INTERNAL",message:e.message}:{code:"INTERNAL",message:"Unexpected error."}}function a5(e){var t,n;let s=null!=(t=e.cdpPort)?t:9222,i=null!=(n=e.url)?n:"http://localhost:5173",[r,o]=(0,l.useState)(String(s)),[c,d]=(0,l.useState)(i),[u,h]=(0,l.useState)(null),[p,m]=(0,l.useState)(null),[f,g]=(0,l.useState)(!1),[v,x]=(0,l.useState)(null),[y,b]=(0,l.useState)([]),[j,w]=(0,l.useState)(null),[k,N]=(0,l.useState)(null),[S,C]=(0,l.useState)(null),R=(0,l.useRef)(null),I=(0,l.useCallback)(()=>{x(null)},[]),E=(0,l.useCallback)(e=>{b(t=>{let n=[...t,e];return n.length>50?n.slice(n.length-50):n}),"navigated"===e.kind&&"string"==typeof e.payload.originOnly&&C(e.payload.originOnly),"error"===e.kind&&x({code:"string"==typeof e.payload.code?e.payload.code:"INTERNAL",message:"string"==typeof e.payload.message?e.payload.message:"Error."})},[]);(0,l.useEffect)(()=>{var e,t;if(null===u){null==(e=R.current)||e.close(),R.current=null;return}let n=new EventSource((t=u.sessionId,"/api/browser/sessions/".concat(encodeURIComponent(t),"/events")));for(let e of["session-opened","navigated","screenshot-captured","page-content-captured","session-closed","trust-warning","error"])n.addEventListener("browser:".concat(e),e=>{try{let t=JSON.parse(e.data);E(t)}catch(e){}});return R.current=n,()=>{n.close(),R.current=null}},[u,E]);let M=(0,l.useCallback)(async()=>{I(),g(!0);try{let e=Number.parseInt(r,10),t=await aX(e);m(t)}catch(e){x(a2(e))}finally{g(!1)}},[r,I]),T=(0,l.useCallback)(async()=>{I(),g(!0);try{let e=Number.parseInt(r,10),t=await aY(e);h(t),b([]),N(null),C(null)}catch(e){x(a2(e))}finally{g(!1)}},[r,I]),q=(0,l.useCallback)(async()=>{if(null!==u){I(),g(!0);try{await aZ(u.sessionId),h(null),w(null),N(null),C(null)}catch(e){x(a2(e))}finally{g(!1)}}},[u,I]),P=(0,l.useCallback)(async()=>{if(null!==u){I(),g(!0);try{let e=await aQ(u.sessionId,c);C(e.originOnly)}catch(e){x(a2(e))}finally{g(!1)}}},[u,c,I]),A=(0,l.useCallback)(async()=>{if(null!==u){I(),g(!0);try{let e=await a$(u.sessionId);e.persisted||w({seq:e.seq,dataBase64:e.dataBase64})}catch(e){x(a2(e))}finally{g(!1)}}},[u,I]),z=(0,l.useCallback)(async()=>{if(null!==u&&null!==j){I(),g(!0);try{let e=await a0(u.sessionId,j.seq);e.persisted&&N(e.path),w(null)}catch(e){x(a2(e))}finally{g(!1)}}},[u,j,I]),D=(0,l.useCallback)(async()=>{if(null!==u){I(),g(!0);try{await a1(u.sessionId)}catch(e){x(a2(e))}finally{g(!1)}}},[u,I]),L=(0,l.useMemo)(()=>f||null!==u,[f,u]),F=(0,l.useMemo)(()=>f||null===u,[f,u]);return(0,a.jsxs)("div",{className:"browser","aria-label":"Browser tool",children:[(0,a.jsxs)("div",{className:"bw-bar",children:[(0,a.jsx)("span",{className:"bw-dot",style:{background:null===u?"var(--line-strong)":"var(--ok)"},"aria-hidden":"true"}),(0,a.jsxs)("label",{className:"bw-field",children:[(0,a.jsx)("span",{className:"bw-field-label",children:"Port"}),(0,a.jsx)("input",{type:"text",inputMode:"numeric",className:"bw-input",value:r,onChange:e=>o(e.target.value),disabled:null!==u||f})]}),(0,a.jsxs)("label",{className:"bw-field bw-field-url",children:[(0,a.jsx)("span",{className:"bw-field-label",children:"URL"}),(0,a.jsx)("input",{type:"url",className:"bw-input bw-input-url",value:c,onChange:e=>d(e.target.value),disabled:f})]})]}),(0,a.jsxs)("div",{className:"bw-actions",role:"toolbar","aria-label":"Browser actions",children:[(0,a.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{M()},disabled:f||null!==u,children:"Check"}),(0,a.jsx)("button",{type:"button",className:"bw-btn bw-btn-primary",onClick:()=>{T()},disabled:L,children:"Open session"}),(0,a.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{P()},disabled:F,children:"Navigate"}),(0,a.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{A()},disabled:F,children:"Screenshot"}),(0,a.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{z()},disabled:f||null===j,children:"Apply"}),(0,a.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{D()},disabled:F,children:"Capture HTML"}),(0,a.jsx)("button",{type:"button",className:"bw-btn bw-btn-danger",onClick:()=>{q()},disabled:F,children:"Close"})]}),null!==p&&null===u?(0,a.jsxs)("p",{className:"bw-status",role:"status",children:["Reachable: ",p.reachable?"yes":"no",null===p.browserVersion?"":" — ".concat(p.browserVersion)]}):null,null!==S?(0,a.jsxs)("p",{className:"bw-status",role:"status","aria-live":"polite",children:["Current origin: ",(0,a.jsx)("span",{className:"mono",children:S})]}):null,null!==j?(0,a.jsx)("p",{className:"bw-status",role:"status",children:"Screenshot ready (dry-run) — press Apply to persist."}):null,null!==k?(0,a.jsxs)("p",{className:"bw-status",role:"status",children:["Persisted as ",(0,a.jsx)("span",{className:"mono",children:k}),"."]}):null,null!==v?(0,a.jsxs)("div",{className:"bw-error",role:"alert",children:[(0,a.jsx)("strong",{children:v.code}),": ",v.message]}):null,(0,a.jsx)("div",{className:"bw-view",children:null!==j?(0,a.jsx)("img",{className:"bw-screenshot",src:"data:image/png;base64,".concat(j.dataBase64),alt:"Pending screenshot preview"}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"ph-stripes","aria-hidden":"true"}),(0,a.jsx)("div",{className:"bw-overlay mono",children:null===u?"no session":"live preview"})]})}),(0,a.jsx)("div",{className:"bw-log","aria-label":"Browser event log","aria-live":"polite","aria-atomic":"false",children:(0,a.jsx)("ul",{className:"bw-log-list",children:y.slice(-10).map((e,t)=>(0,a.jsxs)("li",{className:"bw-log-item",children:[(0,a.jsx)("span",{className:"bw-log-kind",children:function(e){switch(e){case"session-opened":return"session opened";case"navigated":return"navigated";case"screenshot-captured":return"screenshot captured";case"page-content-captured":return"content captured";case"session-closed":return"session closed";case"trust-warning":return"trust warning";case"error":return"error"}}(e.kind)}),(0,a.jsx)("span",{className:"bw-log-detail mono",children:function(e){let t=e.payload;if("navigated"===e.kind){let e="string"==typeof t.originOnly?t.originOnly:"",n="number"==typeof t.httpStatus?" (".concat(String(t.httpStatus),")"):"";return"".concat(e).concat(n)}return"screenshot-captured"===e.kind?!0===t.persisted?"persisted":"dry-run":"page-content-captured"===e.kind?"number"==typeof t.byteLength?"".concat(String(t.byteLength)," bytes"):"":"error"===e.kind||"trust-warning"===e.kind?"string"==typeof t.message?t.message:"string"==typeof t.warning?t.warning:"":""}(e)})]},"".concat(String(e.kind),"-").concat(String(t))))})})]})}async function a3(e,t){var n,a;let l=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),s="GET"!==l&&"HEAD"!==l,i=await fetch(e,{...t,headers:{Accept:"application/json",...s?{"Content-Type":"application/json"}:{},...s?{"X-Keiko-CSRF":"1"}:{},...null!=(a=null==t?void 0:t.headers)?a:{}}});if(!i.ok){let e="INTERNAL",t="HTTP ".concat(i.status.toString());try{let n=await i.json();e=n.error.code,t=n.error.message}catch(e){}throw new $.hD(e,t,i.status)}if(204!==i.status)return i.json()}async function a4(){return a3("/api/terminal/policy")}async function a6(e,t){let n=new URLSearchParams;return n.set("projectId",e),void 0!==t&&t.length>0&&n.set("path",t),a3("/api/terminal/directories?".concat(n.toString()))}async function a8(e){return a3("/api/terminal/executions",{method:"POST",body:JSON.stringify(e)})}async function a7(e){await a3("/api/terminal/executions/".concat(encodeURIComponent(e)),{method:"DELETE"})}function a9(e){return e instanceof $.hD?{code:e.code,message:e.message}:e instanceof Error?{code:"INTERNAL",message:e.message}:{code:"INTERNAL",message:"Unexpected error."}}function le(e){var t,n;let[s,i]=(0,l.useState)(null),[r,o]=(0,l.useState)(""),[c,d]=(0,l.useState)(""),[u,h]=(0,l.useState)(null!=(t=e.cwd)?t:""),[p,m]=(0,l.useState)(null!=(n=e.projectPath)?n:""),[f,g]=(0,l.useState)(!1),[v,x]=(0,l.useState)(null),[y,b]=(0,l.useState)(null),[j,w]=(0,l.useState)(null),[k,N]=(0,l.useState)([]),S=(0,l.useRef)(null),C=(0,l.useRef)(!1),R=(0,l.useRef)(null),[I,E]=(0,l.useState)([]);(0,l.useEffect)(()=>{let e=!1;return a4().then(t=>{e||(i(t),o(e=>{var n;return e.length>0?e:null!=(n=t.commands[0])?n:""}))}).catch(t=>{e||w(a9(t))}),()=>{e=!0}},[]),(0,l.useEffect)(()=>{if(0===p.length)return void E([]);let e=!1;return a6(p,u.length>0?u:void 0).then(t=>{e||E(t.entries)}).catch(()=>{e||E([])}),()=>{e=!0}},[p,u]),(0,l.useEffect)(()=>{let e=new EventSource("/api/terminal/events");S.current=e;let t=e=>{try{let t=JSON.parse(e.data);if("execution-started"===t.kind&&C.current){let e=t.payload;"string"==typeof e.requestId&&e.requestId===R.current&&x(e=>null!==e?e:t.executionId)}if("execution-completed"===t.kind||"execution-failed"===t.kind||"execution-cancelled"===t.kind){let e=t.payload;"string"==typeof e.requestId&&e.requestId===R.current&&x(e=>null===e||e!==t.executionId?e:null)}N(e=>{let n=[t,...e];return n.length>30?n.slice(0,30):n})}catch(e){}};for(let n of["execution-started","execution-completed","execution-failed","execution-cancelled"])e.addEventListener("terminal:".concat(n),t);return()=>{e.close(),S.current=null}},[]);let M=(0,l.useCallback)(async e=>{if(e.preventDefault(),f)return;w(null),b(null),x(null);let t="function"==typeof crypto.randomUUID?crypto.randomUUID():"terminal-".concat(Date.now().toString(36),"-").concat(Math.random().toString(36).slice(2));R.current=t;let n=function(e){let t=e.trim();return 0===t.length?[]:t.split(/\s+/)}(c);C.current=!0,g(!0);try{let e={projectId:p,command:r,args:n,...u.length>0?{cwd:u}:{},requestId:t},a=await a8(e);b(a)}catch(e){w(a9(e))}finally{C.current=!1,g(!1),R.current=null,x(null)}},[c,r,u,p,f]),T=(0,l.useCallback)(async()=>{if(null!==v)try{await a7(v)}catch(e){w(a9(e))}},[v]),q=(0,l.useMemo)(()=>{var e;return null!=(e=null==s?void 0:s.limits)?e:null},[s]);return(0,a.jsxs)("div",{className:"terminal",children:[(0,a.jsxs)("form",{className:"tm-form",onSubmit:e=>void M(e),children:[(0,a.jsxs)("label",{className:"tm-field",children:[(0,a.jsx)("span",{children:"Project path"}),(0,a.jsx)("input",{type:"text",value:p,onChange:e=>m(e.target.value),placeholder:"/absolute/path/to/project",required:!0})]}),(0,a.jsxs)("label",{className:"tm-field",children:[(0,a.jsx)("span",{children:"Command"}),(0,a.jsx)("select",{value:r,onChange:e=>o(e.target.value),disabled:null===s,required:!0,children:null==s?void 0:s.commands.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]}),(0,a.jsxs)("label",{className:"tm-field",children:[(0,a.jsx)("span",{children:"Args (space-separated)"}),(0,a.jsx)("input",{type:"text",value:c,onChange:e=>d(e.target.value),placeholder:"e.g. -la src"})]}),(0,a.jsxs)("label",{className:"tm-field",children:[(0,a.jsx)("span",{children:"Working directory (optional)"}),(0,a.jsx)("input",{type:"text",value:u,onChange:e=>h(e.target.value),placeholder:"(project root)",list:"tm-cwd-suggestions"}),(0,a.jsx)("datalist",{id:"tm-cwd-suggestions",children:I.map(e=>(0,a.jsx)("option",{value:e.path},e.path))})]}),(0,a.jsxs)("div",{className:"tm-actions",children:[(0,a.jsx)("button",{type:"submit",className:"tm-action",disabled:f||null===s,children:f?"Running…":"Run"}),f?(0,a.jsx)("button",{type:"button",className:"tm-action",disabled:null===v,onClick:()=>void T(),children:"Cancel"}):null]}),null!==q?(0,a.jsxs)("p",{className:"tm-limits",children:["Limits: ",q.maxOutputBytes," bytes output, ",q.defaultTimeoutMs," ms timeout"]}):null]}),null!==j?(0,a.jsxs)("div",{className:"tm-error",role:"alert",children:[(0,a.jsxs)("span",{className:"tm-error-text",children:[(0,a.jsx)("strong",{children:j.code}),": ",j.message]}),(0,a.jsx)("button",{type:"button",className:"tm-error-dismiss","aria-label":"Dismiss error",onClick:()=>w(null),children:"✕"})]}):null,null!==y?(0,a.jsxs)("div",{className:"tm-result",role:"status","aria-live":"polite",children:[(0,a.jsxs)("div",{className:"tm-badges",children:[(0,a.jsxs)("span",{className:0===y.exitCode?"tm-badge tm-badge-ok":"tm-badge tm-badge-fail",children:["exit ",String(y.exitCode)]}),(0,a.jsxs)("span",{className:"tm-badge",children:[y.durationMs," ms"]}),y.truncated?(0,a.jsx)("span",{className:"tm-badge tm-badge-warn",children:"truncated"}):null,y.timedOut?(0,a.jsx)("span",{className:"tm-badge tm-badge-warn",children:"timed out"}):null]}),y.stdout.length>0?(0,a.jsx)("pre",{className:"tm-stdout",children:y.stdout}):null,y.stderr.length>0?(0,a.jsx)("pre",{className:"tm-stderr",children:y.stderr}):null]}):null,(0,a.jsx)("ul",{className:"tm-events",role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":"false","aria-label":"Recent terminal events",children:k.map((e,t)=>(0,a.jsxs)("li",{className:"tm-event",children:[(0,a.jsx)("span",{className:"tm-event-kind",children:function(e){switch(e){case"execution-started":return"started";case"execution-completed":return"completed";case"execution-failed":return"failed";case"execution-cancelled":return"cancelled"}}(e.kind)}),(0,a.jsx)("span",{className:"tm-event-detail",children:function(e){let t=e.payload;return"execution-completed"===e.kind?["number"==typeof t.exitCode||null===t.exitCode?"exit ".concat(String(t.exitCode)):"","number"==typeof t.durationMs?"".concat(String(t.durationMs),"ms"):""].filter(Boolean).join(" \xb7 "):"execution-failed"===e.kind?"string"==typeof t.code?t.code:"":"execution-started"===e.kind&&"string"==typeof t.command?t.command:""}(e)})]},"".concat(e.executionId,"-").concat(String(t),"-").concat(e.kind)))})]})}function lt(e){return e.startsWith("a/")||e.startsWith("b/")?e.slice(2):e}function ln(e){return e instanceof $.hD?{code:e.code,message:e.message}:e instanceof Error?{code:"INTERNAL",message:e.message}:{code:"INTERNAL",message:"Unexpected error."}}function la(e){return("dry-run"===e.status||"fix-proposed"===e.status)&&void 0!==e.proposedDiff&&void 0===e.appliedAt}function ll(e){return void 0!==e.proposedDiff&&""!==e.proposedDiff}function ls(e){let{href:t,hasManifest:n,error:l}=e;return n?(0,a.jsx)("a",{className:"rv-evidence-link",href:t,target:"_blank",rel:"noopener noreferrer",children:"Evidence"}):null!==l?(0,a.jsx)("span",{className:"rv-evidence-link rv-evidence-error",role:"status","aria-label":"Evidence unavailable: ".concat(l.message),title:l.message,children:"Evidence error"}):(0,a.jsx)("span",{className:"rv-evidence-link rv-evidence-disabled",role:"link","aria-disabled":"true",children:"Evidence"})}function li(e){let{tokens:t}=e;return(0,a.jsx)(a.Fragment,{children:t.map((e,t)=>(0,a.jsx)("span",{className:"hl-".concat(e[0]),children:e[1]},t))})}function lr(e){var t,n,l;let s,{line:i,lang:r}=e,o="add"===i.kind?"+":"del"===i.kind?"−":"ctx"===i.kind?"\xb7":"",c="ctx"===i.kind?"":" rv-".concat(i.kind);if("meta"!==i.kind&&"code"!==r){let e=null!=(t=aO(i.text,aD(r))[0])?t:[];s=(0,a.jsx)(li,{tokens:e})}else s=i.text;return(0,a.jsxs)("div",{className:"rv-line".concat(c),children:[(0,a.jsx)("span",{className:"rv-sr-only",children:{add:"Added line",del:"Deleted line",ctx:"Context line",meta:"Diff metadata"}[i.kind]}),(0,a.jsx)("span",{className:"rv-num-old rv-num",children:null!=(n=i.oldLine)?n:""}),(0,a.jsx)("span",{className:"rv-num-new rv-num",children:null!=(l=i.newLine)?l:""}),(0,a.jsx)("span",{className:"rv-gutter","aria-hidden":"true",children:o}),(0,a.jsx)("code",{className:"rv-src",children:s})]})}function lo(e){let{hunk:t,lang:n}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"rv-hunk mono","aria-label":"Hunk header ".concat(t.header),children:[(0,a.jsx)("span",{className:"rv-sr-only",children:"Hunk header"}),t.header]}),t.lines.map((e,t)=>(0,a.jsx)(lr,{line:e,lang:n},t))]})}function lc(e){var t;let{file:n,index:l,changedFiles:s,sectionRef:i}=e,r=s.find(e=>e.path===n.path),o=n.path.includes(".")&&null!=(t=n.path.split(".").pop())?t:"code";return(0,a.jsxs)("section",{id:"rv-file-".concat(l),"aria-labelledby":"rv-file-".concat(l,"-h"),ref:i,children:[(0,a.jsxs)("h3",{id:"rv-file-".concat(l,"-h"),className:"rv-file mono",children:[(0,a.jsx)("span",{className:"rv-path",children:n.path}),void 0!==n.oldPath&&(0,a.jsxs)("span",{className:"rv-oldpath",children:[" (was ",n.oldPath,")"]}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("span",{className:"rv-stat add",children:["+",n.addedLines]}),(0,a.jsxs)("span",{className:"rv-stat del",children:["−",n.removedLines]}),(null==r?void 0:r.elevatedReview)===!0&&(0,a.jsx)("span",{className:"rv-elevated","aria-label":"Elevated review",children:"!"})]}),(0,a.jsx)("div",{className:"rv-code mono",children:n.hunks.map((e,t)=>(0,a.jsx)(lo,{hunk:e,lang:o},t))})]})}function ld(e){var t,n,s;let{runId:i}=e,[r,o]=(0,l.useState)(null),[c,d]=(0,l.useState)(!1),[u,h]=(0,l.useState)(null),[p,m]=(0,l.useState)(!1),[f,g]=(0,l.useState)(null),[v,x]=(0,l.useState)(!1),[y,b]=(0,l.useState)(null),[j,w]=(0,l.useState)(null);(0,l.useEffect)(()=>{if(void 0===i||""===i)return;let e=!1;return m(!0),g(null),o(null),d(!1),h(null),w(null),Promise.allSettled([(0,$.Qe)(i),(0,$.tZ)(i)]).then(t=>{let[n,a]=t;if(!e){if("fulfilled"===a.status)d(!0),h(null);else{let e=ln(a.reason);d(!1),h("NOT_FOUND"===e.code?null:e)}if("fulfilled"===n.status){o(n.value.report),m(!1);return}g(ln(n.reason)),m(!1)}}),()=>{e=!0}},[i]);let k="/api/evidence/".concat(encodeURIComponent(null!=i?i:"")),N=(0,l.useMemo)(()=>(null==r?void 0:r.proposedDiff)!==void 0?function(e){let t=new TextEncoder,n=t.encode(e).byteLength;if(0===e.length)return{files:[],truncated:!1,totalBytes:0};let a=e,l=!1;if(n>524288){l=!0;let n=t.encode(e),s=new TextDecoder().decode(n.slice(0,524288)),i=s.lastIndexOf("\n");a=-1===i?s:s.slice(0,i+1)}let s=a.split("\n"),i=s.length>0&&""===s[s.length-1]?s.slice(0,-1):s,r=[],o=null,c=null,d=0,u=0,h=()=>{null!==o&&null!==c&&o.hunks.push(c),c=null},p=()=>{h(),null!==o&&(r.length<400?r.push(o):l=!0),o=null},m=0;for(;m<i.length;){var f,g,v;let e=null!=(f=i[m])?f:"";if(e.startsWith("diff --git ")){p();let t=/^diff --git a\/(.+?) b\/(.+)$/.exec(e);if(null!==t&&void 0!==t[1]&&void 0!==t[2]){let e=t[1],n=t[2],a=lt("b/".concat(n)),l=lt("a/".concat(e)),s={path:a,hunks:[],addedLines:0,removedLines:0};l!==a&&(s.oldPath=l),o=s}m++;continue}if(null!==c){if(e.startsWith("+")){let t={kind:"add",oldLine:null,newLine:u,text:e.slice(1)};c.lines.push(t),null!==o&&o.addedLines++,u++,m++;continue}if(e.startsWith("-")){let t={kind:"del",oldLine:d,newLine:null,text:e.slice(1)};c.lines.push(t),null!==o&&o.removedLines++,d++,m++;continue}if(e.startsWith("\\ ")){let t={kind:"meta",oldLine:null,newLine:null,text:e};c.lines.push(t),m++;continue}if(e.startsWith(" ")||""===e){let t={kind:"ctx",oldLine:d,newLine:u,text:e.startsWith(" ")?e.slice(1):e};c.lines.push(t),d++,u++,m++;continue}}if(e.startsWith("--- ")){let t=e.slice(4);if("/dev/null"!==t&&null===o)p(),o={path:lt(t),hunks:[],addedLines:0,removedLines:0};else if("/dev/null"!==t&&null!==o){let e=lt(t);e!==o.path&&(o.oldPath=e)}m++;continue}if(e.startsWith("+++ ")){let t=e.slice(4);"/dev/null"!==t&&null!==o?o.path=lt(t):"/dev/null"!==t&&(p(),o={path:lt(t),hunks:[],addedLines:0,removedLines:0}),m++;continue}if(e.startsWith("@@ ")){null===o&&(o={path:"(unknown)",hunks:[],addedLines:0,removedLines:0}),h();let t=function(e){let t=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(e);return null===t||void 0===t[1]||void 0===t[2]?null:{oldStart:parseInt(t[1],10),newStart:parseInt(t[2],10)}}(e);d=null!=(g=null==t?void 0:t.oldStart)?g:1,u=null!=(v=null==t?void 0:t.newStart)?v:1,c={header:e,lines:[]},m++;continue}m++}return p(),{files:r,truncated:l,totalBytes:n}}(r.proposedDiff):null,[null==r?void 0:r.proposedDiff]),S=null!=(t=null==r?void 0:r.changedFiles)?t:[],C=(0,l.useMemo)(()=>{var e,t;return{added:null!=(e=null==N?void 0:N.files.reduce((e,t)=>e+t.addedLines,0))?e:0,removed:null!=(t=null==N?void 0:N.files.reduce((e,t)=>e+t.removedLines,0))?t:0}},[N]),R=null!==N&&N.files.length>0?Math.min(null!=j?j:0,N.files.length-1):null,I=null!==R?null==N?void 0:N.files[R]:void 0,E=(null==r?void 0:r.status)==="running";return void 0===i||""===i?(0,a.jsxs)("section",{className:"review rv-empty","aria-label":"Diff review",children:[(0,a.jsx)("h2",{className:"rv-empty-h",children:"Review"}),(0,a.jsx)("p",{className:"rv-empty-p",children:"Enter a run ID in the window configuration to load a proposed diff."})]}):(0,a.jsxs)("section",{className:"review","aria-label":"Diff review",children:[p&&(0,a.jsxs)("div",{className:"rv-loading","aria-busy":"true","aria-label":"Loading diff",children:[(0,a.jsx)("div",{className:"rv-skel"}),(0,a.jsx)("div",{className:"rv-skel rv-skel-sm"})]}),!p&&null!==f&&(0,a.jsxs)("div",{role:"alert",className:"rv-error",children:["NOT_FOUND"===f.code?"No run with that ID was found.":"".concat(f.code,": ").concat(f.message),(c||null!==u)&&(0,a.jsx)("span",{className:"rv-error-evidence",children:(0,a.jsx)(ls,{href:k,hasManifest:c,error:u})})]}),!p&&null===f&&null!==r&&E&&(0,a.jsx)("p",{role:"status","aria-live":"polite",className:"rv-no-diff",children:"Run is still running. The proposed diff will appear when the run completes."}),!p&&null===f&&null!==r&&!E&&!ll(r)&&(0,a.jsx)("p",{className:"rv-no-diff",children:"This run has no proposed diff to review."}),!p&&null===f&&null!==r&&ll(r)&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"rv-header",children:[(0,a.jsx)("span",{className:"rv-status mono",children:null!=(s=({running:"Running",completed:"Completed","dry-run":"Dry run",rejected:"Rejected",cancelled:"Cancelled",failed:"Failed","fix-applied":"Fix applied","fix-proposed":"Fix proposed","investigation-only":"Investigation only"})[n=r.status])?s:n}),void 0!==r.modelId&&(0,a.jsx)("span",{className:"rv-model mono",children:r.modelId}),(0,a.jsxs)("span",{className:"rv-counts mono",children:[null!==N&&"".concat(N.files.length," file").concat(1!==N.files.length?"s":"")," ",(0,a.jsxs)("span",{className:"rv-stat add",children:["+",C.added]})," ",(0,a.jsxs)("span",{className:"rv-stat del",children:["−",C.removed]})]}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsx)(ls,{href:k,hasManifest:c,error:u})]}),null!==N&&N.files.length>0&&null!==R&&void 0!==I&&(0,a.jsxs)("div",{className:"rv-layout",children:[(0,a.jsx)("nav",{className:"rv-filelist","aria-label":"Changed files",children:(0,a.jsx)("ul",{children:N.files.map((e,t)=>{let n=S.find(t=>t.path===e.path),l=R===t;return(0,a.jsx)("li",{children:(0,a.jsxs)("button",{type:"button",className:"rv-filerow","aria-pressed":l,"aria-controls":l?"rv-file-".concat(t):void 0,onClick:()=>{w(t)},children:[(0,a.jsx)("span",{className:"rv-filerow-path mono",children:function(e){if(e.length<=40)return e;let t=e.lastIndexOf("/");return -1===t?e:"…/".concat(e.slice(t+1))}(e.path)}),(0,a.jsxs)("span",{className:"rv-stat add",children:["+",e.addedLines]}),(0,a.jsxs)("span",{className:"rv-stat del",children:["−",e.removedLines]}),(null==n?void 0:n.elevatedReview)===!0&&(0,a.jsx)("span",{className:"rv-elevated","aria-label":"Elevated review",children:"!"})]})},e.path)})})}),(0,a.jsxs)("div",{className:"rv-body",children:[(0,a.jsx)(lc,{file:I,index:R,changedFiles:S,sectionRef:()=>void 0},I.path),N.truncated&&(0,a.jsxs)("p",{role:"note",className:"rv-truncated",children:["Diff truncated at 512 KB. Open the"," ",c?(0,a.jsx)("a",{href:k,target:"_blank",rel:"noopener noreferrer",children:"evidence manifest"}):"evidence manifest"," ","for the full record."]})]})]}),(0,a.jsxs)("div",{className:"rv-controls",children:[(0,a.jsx)("span",{role:"status","aria-live":"polite",className:"rv-apply-status",children:v?"Applying…":void 0!==r.appliedAt?"Applied":""}),null!==y&&(0,a.jsx)("span",{role:"alert",className:"rv-apply-error",children:y.message}),void 0!==r.appliedAt?(0,a.jsx)("span",{className:"rv-final mono",children:"Applied"}):la(r)?(0,a.jsx)("button",{type:"button",className:"arun-btn",disabled:v,onClick:()=>{void 0!==i&&null!==r&&la(r)&&(x(!0),b(null),(0,$.qU)(i).then(e=>{o(e.report),x(!1)}).catch(e=>{b(ln(e)),x(!1)}))},children:v?"Applying…":"Apply"}):null]})]})]})}function lu(e){if(e<1e3)return"".concat(e.toString()," ms");if(e<6e4)return"".concat((e/1e3).toFixed(1)," s");let t=Math.floor(e/6e4),n=Math.floor(e%6e4/1e3);return"".concat(t.toString(),"m ").concat(n.toString(),"s")}function lh(e){return e<1e3?e.toString():"".concat((e/1e3).toFixed(1),"k")}let lp=new Set(["completed","dry-run","rejected","cancelled","failed","fix-applied","fix-proposed","investigation-only"]),lm={verify:"Verify","explain-plan":"Explain plan","unit-test-generation":"Generate unit tests","bug-investigation":"Investigate bug"};function lf(e,t){return void 0===t||0===t.length?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:e}),(0,a.jsx)("pre",{children:t})]})}function lg(e){var t,n,s,i,r,o,c,d,u;let{cfg:h={},linkedRoot:p=null,linkedFilePath:m}=e,f=null!=(n=h.runId)?n:null,g="verify"===(d=h.workflow)||"explain-plan"===d||"unit-test-generation"===d||"bug-investigation"===d?d:null,v=null!=(s=h.model)?s:"",x=function(e){if(void 0===e||0===e.length)return null;try{let t=JSON.parse(e);return"object"!=typeof t||null===t||Array.isArray(t)?null:t}catch(e){return null}}(h.inputJson),y=function(e){let[t,n]=(0,l.useState)([]),[a,s]=(0,l.useState)("connecting"),[i,r]=(0,l.useState)(null),o=(0,l.useRef)(-1);return(0,l.useEffect)(()=>{if(null===e)return;n([]),s("connecting"),r(null),o.current=-1;let t=null,a=!1,l="/api/runs/".concat(encodeURIComponent(e),"/events");(t=new EventSource(o.current>=0?"".concat(l,"?lastEventId=").concat(o.current.toString()):l)).onopen=()=>{a||s("live")},t.onerror=()=>{a||(s("error"),r("Stream disconnected. Attempting to reconnect…"))};let i=e=>{let l;if(!a){try{l=JSON.parse(e.data)}catch(e){return}o.current=l.seq,n(e=>[...e,l]),tN.eQ.has(l.type)&&(s("terminal"),null==t||t.close())}};for(let e of tN.$Q)t.addEventListener(e,i);return()=>{a=!0,null==t||t.close()}},[e]),{events:t,status:a,error:i}}(f),[b,j]=(0,l.useState)(null),[w,k]=(0,l.useState)(null),[N,C]=(0,l.useState)(null),[R,I]=(0,l.useState)(!1),[E,M]=(0,l.useState)(null),[T,q]=(0,l.useState)(null),P=(0,l.useCallback)(async()=>{if(null!==f){C(null);try{let e=await (0,$.Qe)(f);j(e.report),k(null)}catch(e){if(e instanceof $.hD&&404===e.status){try{let e=await (0,$.tZ)(f);k(e.manifest),j(null)}catch(e){C(e instanceof Error?e.message:"Unable to load evidence.")}return}C(e instanceof Error?e.message:"Unable to load run report.")}}},[f]);(0,l.useEffect)(()=>{P()},[P]),(0,l.useEffect)(()=>{"terminal"===y.status&&P()},[P,y.status]),(0,l.useEffect)(()=>{let e=!1;if(0!==v.length)return(0,$.ZC)().then(t=>{var n,a;e||q(null!=(a=null==(n=t.models.find(e=>e.id===v))?void 0:n.costClass)?a:null)}).catch(()=>{e||q(null)}),()=>{e=!0}},[v]);let A=(0,l.useMemo)(()=>(function(e,t){var n,a,l,s,i,r;let o=null!=(s=null==t||null==(n=t.usage)?void 0:n.promptTokens)?s:0,c=null!=(i=null==t||null==(a=t.usage)?void 0:a.completionTokens)?i:0,d=null!=(r=null==t||null==(l=t.usage)?void 0:l.latencyMs)?r:0,u=+((null==t?void 0:t.usage)!==void 0);if(u>0)return{promptTokens:o,completionTokens:c,latencyMs:d,requestCount:u};for(let t of e){let e=function(e){if("model:call:completed"===e.type)return{promptTokens:e.usage.promptTokens,completionTokens:e.usage.completionTokens,latencyMs:e.usage.latencyMs,requestCount:1};let t=e.promptTokens,n=e.completionTokens,a=e.latencyMs;return"number"==typeof t&&"number"==typeof n&&"number"==typeof a?{promptTokens:t,completionTokens:n,latencyMs:a,requestCount:1}:null}(t);null!==e&&(o+=e.promptTokens,c+=e.completionTokens,d+=e.latencyMs,u+=e.requestCount)}return{promptTokens:o,completionTokens:c,latencyMs:d,requestCount:u}})(y.events,b),[y.events,b]),z=null!=(o=null!=(i=null==b?void 0:b.durationMs)?i:null==w?void 0:w.run.durationMs)?o:y.events.length>0?Math.max(0,Date.now()-Number(new Date(null!=(r=null==(t=y.events[0])?void 0:t.ts)?r:Date.now()))):0,D=null!==b?b.status:null!==w?w.run.outcome:"loading",L=null!==b&&lp.has(b.status),F=null!==b&&void 0!==b.proposedDiff&&void 0===b.appliedAt&&("unit-test-generation"===g&&"dry-run"===b.status||"bug-investigation"===g&&"fix-proposed"===b.status),O=async()=>{if(null!==f){C(null);try{await (0,$.Su)(f),await P()}catch(e){C(e instanceof Error?e.message:"Unable to cancel run.")}}},K=async()=>{if(null!==f&&F){I(!0),M(null);try{let e=await (0,$.qU)(f);j(e.report)}catch(e){M(e instanceof Error?e.message:"Unable to apply run.")}finally{I(!1)}}};return null===f||null===g?(0,a.jsxs)("div",{className:"arun arun-empty",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Agent run is not configured."}),(0,a.jsx)("p",{children:"Open a new Agent window from the launcher to start a BFF workflow."})]}):(0,a.jsxs)("div",{className:"arun arun-real",children:[(0,a.jsxs)("div",{className:"arun-head",children:[(0,a.jsx)("span",{className:"arun-role",children:lm[g]}),(0,a.jsx)("span",{className:"ag-model mono",children:v}),null!==T?(0,a.jsx)("span",{className:"arun-gov",children:T}):null,(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("span",{className:"arun-status",children:[(0,a.jsx)("span",{className:"dot","data-live":(null==b?void 0:b.status)==="running"}),D]})]}),(0,a.jsxs)("div",{className:"arun-summary",children:[(0,a.jsx)("strong",{children:function(e,t,n){var a;if(null===t&&null===n)return"Loading run state...";let l=null===e?"Agent run":lm[e];return(null==t?void 0:t.status)==="running"?"".concat(l," is running."):(null==t?void 0:t.status)==="dry-run"?"".concat(l," produced a reviewable dry-run."):(null==t?void 0:t.status)==="fix-proposed"?"".concat(l," proposed a fix."):(null==t?void 0:t.status)==="fix-applied"?"".concat(l," applied changes."):(null==t?void 0:t.status)==="investigation-only"?"".concat(l," completed without a patch."):(null==t?void 0:t.status)==="failed"||(null==t?void 0:t.status)==="rejected"?"".concat(l," failed."):(null==t?void 0:t.status)==="cancelled"?"".concat(l," was cancelled."):null!==t?"".concat(l," completed."):"".concat(l," evidence loaded: ").concat(null!=(a=null==n?void 0:n.run.outcome)?a:"unknown",".")}(g,b,w)}),(0,a.jsxs)("span",{className:"mono",children:["run ",f.slice(0,8)]})]}),(0,a.jsxs)("div",{className:"arun-meters",children:[(0,a.jsxs)("div",{className:"arun-meter",children:[(0,a.jsx)("span",{className:"arun-mk",children:"Elapsed"}),(0,a.jsx)("span",{className:"arun-mv mono",children:lu(z)})]}),(0,a.jsxs)("div",{className:"arun-meter",children:[(0,a.jsx)("span",{className:"arun-mk",children:"Usage"}),(0,a.jsx)("span",{className:"arun-mv mono",children:0===A.requestCount?"No model usage":"".concat(lh(A.promptTokens+A.completionTokens)," tok")})]}),(0,a.jsxs)("div",{className:"arun-meter",children:[(0,a.jsx)("span",{className:"arun-mk",children:"Latency"}),(0,a.jsx)("span",{className:"arun-mv mono",children:0===A.requestCount?"-":lu(A.latencyMs)})]})]}),(0,a.jsxs)("div",{className:"arun-perms",children:[(0,a.jsxs)("span",{className:"arun-perm","data-on":null!==p,children:[(0,a.jsx)(S.files,{size:11}),null!==p?p:null!=(c=h.workspaceRoot)?c:"no workspace"]}),void 0!==m?(0,a.jsxs)("span",{className:"arun-perm","data-on":!0,children:[(0,a.jsx)(S.files,{size:11}),m]}):null]}),null!==x?(0,a.jsxs)("details",{className:"arun-input",children:[(0,a.jsx)("summary",{children:"Run input"}),(0,a.jsx)("pre",{children:JSON.stringify(x,null,2)})]}):null,(0,a.jsx)("div",{className:"arun-log",children:0===y.events.length?(0,a.jsxs)("div",{className:"arun-log-row",children:[(0,a.jsx)("span",{className:"arun-log-ico",children:(0,a.jsx)(S.reset,{size:12})}),(0,a.jsx)("span",{className:"arun-log-text",children:"Waiting for run events..."})]}):y.events.slice().reverse().slice(0,50).map(e=>(0,a.jsxs)("div",{className:"arun-log-row",children:[(0,a.jsx)("span",{className:"arun-log-ico",children:(0,a.jsx)(S.spark,{size:12})}),(0,a.jsx)("span",{className:"arun-log-text",children:function(e){switch(e.type){case"ready":return"SSE stream ready";case"run:started":return"Started ".concat(e.taskType);case"run:completed":return"Run completed";case"run:failed":return"Run failed: ".concat(e.failure.message);case"run:cancelled":return"Run cancelled";case"state:transition":return"".concat(e.from," -> ").concat(e.to).concat(void 0===e.reason?"":": ".concat(e.reason));case"model:call:started":return"Model call started (".concat(e.contextBytes.toString()," bytes)");case"model:call:completed":return"Model call completed (".concat(lh(e.usage.promptTokens+e.usage.completionTokens)," tokens)");case"model:call:failed":return"Model call failed: ".concat(e.message);case"patch:proposed":return"Patch proposed (".concat(e.patchBytes.toString()," bytes)");case"verification:result":return"Verification ".concat(e.passed?"passed":"failed",": ").concat(e.detail);case"workflow:started":return"Unit-test workflow started";case"workflow:model:call:completed":return"Unit-test model call completed (".concat(lh(e.promptTokens+e.completionTokens)," tokens)");case"workflow:verification:result":return"Unit-test verification ".concat(e.overallStatus);case"workflow:completed":return"Unit-test workflow ".concat(e.status);case"workflow:failed":return"Unit-test workflow failed: ".concat(e.message);case"bug:started":return"Bug investigation started";case"bug:model:call:completed":return"Bug model call completed (".concat(lh(e.promptTokens+e.completionTokens)," tokens)");case"bug:rootcause:proposed":return"Root cause proposed".concat(e.hasPatch?" with patch":"");case"bug:verification:result":return"Bug verification ".concat(e.overallStatus);case"bug:completed":return"Bug investigation ".concat(e.status);case"bug:failed":return"Bug investigation failed: ".concat(e.message);default:return e.type}}(e)}),(0,a.jsx)("span",{className:"arun-log-t mono",children:function(e){let t="number"==typeof e.ts?e.ts:Date.parse(e.ts);return Number.isFinite(t)?new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}):""}(e)})]},"".concat(e.runId,":").concat(e.seq,":").concat(e.type)))}),null!==b?(0,a.jsxs)("div",{className:"arun-results",children:[void 0===b.report?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Report"}),(0,a.jsx)("pre",{children:b.report})]}),void 0===b.overallStatus||void 0===b.results?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Verification"}),(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Status"}),(0,a.jsx)("strong",{children:b.overallStatus})]}),b.results.slice(0,8).map(e=>(0,a.jsxs)("div",{className:"arun-check-row",children:[(0,a.jsx)("span",{children:e.kind}),(0,a.jsx)("span",{className:"mono",children:e.status})]},"".concat(e.kind,":").concat(e.command)))]}),lf("Failure",b.failureReason),lf("Covered behavior",b.coveredBehavior),lf("Known gaps",b.knownGaps),lf("Verification note",b.verificationSkipReason),function(e){let t=e.hypothesis;if(void 0===t)return null;let n=[["Root cause",t.rootCause],["Regression test",t.regressionTestStrategy],["Uncertainty",t.uncertainty],["Confidence",t.confidence]].filter(e=>"string"==typeof e[1]&&e[1].length>0);return 0===n.length?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Hypothesis"}),n.map(e=>{let[t,n]=e;return(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:t}),(0,a.jsx)("strong",{children:n})]},t)})]})}(b),void 0===(u=b.nextActions)||0===u.length?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Next actions"}),u.map(e=>(0,a.jsx)("div",{className:"arun-check-row",children:(0,a.jsx)("span",{children:e})},e))]}),void 0!==b.dryRunPreview?(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Dry-run preview"}),(0,a.jsx)("pre",{children:b.dryRunPreview})]}):null,void 0!==b.proposedDiff?(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Proposed diff"}),(0,a.jsx)("pre",{children:b.proposedDiff})]}):null,function(e){let t=e.verificationSummary;return void 0===t?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Verification"}),(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Status"}),(0,a.jsx)("strong",{children:t.overallStatus})]}),(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Duration"}),(0,a.jsx)("strong",{children:lu(t.durationMs)})]}),t.results.slice(0,5).map(e=>(0,a.jsxs)("div",{className:"arun-check-row",children:[(0,a.jsx)("span",{children:e.kind}),(0,a.jsx)("span",{className:"mono",children:e.status})]},"".concat(e.kind,":").concat(e.command)))]})}(b),void 0!==b.applyReport?(0,a.jsxs)("div",{className:"arun-result-card arun-applied",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Applied"}),(0,a.jsx)("pre",{children:JSON.stringify(b.applyReport,null,2)})]}):null]}):null!==w?(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Evidence"}),(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Outcome"}),(0,a.jsx)("strong",{children:w.run.outcome})]}),(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Duration"}),(0,a.jsx)("strong",{children:lu(w.run.durationMs)})]})]}):null,null!==N?(0,a.jsx)("div",{className:"arun-error",children:N}):null,null!==E?(0,a.jsx)("div",{className:"arun-error",children:E}):null,(0,a.jsxs)("div",{className:"arun-controls",children:[(0,a.jsx)("a",{className:"arun-btn ghost",href:"/api/evidence/".concat(encodeURIComponent(f)),target:"_blank",rel:"noreferrer",children:"Evidence"}),F?(0,a.jsx)("button",{type:"button",className:"arun-btn",disabled:R,onClick:()=>void K(),children:R?"Applying...":"Apply"}):(null==b?void 0:b.appliedAt)!==void 0?(0,a.jsx)("span",{className:"arun-final mono",children:"Applied"}):null,L||(null==b?void 0:b.status)!=="running"?null:(0,a.jsx)("button",{type:"button",className:"arun-btn danger",onClick:()=>void O(),children:"Cancel"})]})]})}let lv=[{name:"Messaging",desc:"Catch up on threads",glyph:"#"},{name:"GitHub",desc:"PRs, code & CI",glyph:"{ }"},{name:"Linear",desc:"Track issues",glyph:"⊿"},{name:"Slack",desc:"Team channels",glyph:"≡"},{name:"Sentry",desc:"Error tracking",glyph:"◎"}];function lx(e){let{provider:t="GitHub"}=e;return(0,a.jsx)("div",{className:"integ",children:lv.map(e=>{let n=e.name===t;return(0,a.jsxs)("button",{type:"button",className:"integ-row","data-on":n,"aria-pressed":n,children:[(0,a.jsx)("span",{className:"integ-glyph mono",children:e.glyph}),(0,a.jsxs)("span",{className:"integ-text",children:[(0,a.jsx)("span",{className:"integ-name",children:e.name}),(0,a.jsx)("span",{className:"integ-desc",children:e.desc})]}),n?(0,a.jsx)("span",{className:"integ-on",children:(0,a.jsx)(S.check,{size:13})}):(0,a.jsx)("span",{className:"integ-add",children:(0,a.jsx)(S.plus,{size:14})})]},e.name)})})}let ly={allow:["Allow","var(--accent)"],ask:["Ask","var(--warn)"],deny:["Deny","var(--danger)"]},lb={allow:"ask",ask:"deny",deny:"allow"},lj=[{id:1,label:"Write src/windows.jsx",kind:"write",risk:"low",expect:"allow"},{id:2,label:"Overwrite prod/secrets.env",kind:"write",risk:"high",expect:"deny"},{id:3,label:"Run `npm test`",kind:"command",risk:"low",expect:"allow"},{id:4,label:"Run `kubectl apply` → prod",kind:"command",risk:"high",expect:"ask"},{id:5,label:"Open pull request #142",kind:"git",risk:"low",expect:"allow"},{id:6,label:"Email the customer",kind:"mail",risk:"low",expect:"ask"}],lw=[["Developer","Codes, reviews diffs, runs tests, opens PRs"],["Product Owner","Searches docs, drafts Jira tickets, plans releases"],["Designer","Explores UI options, reviews flows, writes specs"]],lk=[["calendar","Calendar","automations"],["mail","Mail","bell"],["jira","Jira","review"],["docs","Docs","files"]];function lN(e){let{policy:t,setPolicy:n}=e;return(0,a.jsxs)("div",{className:"pol",children:[(0,a.jsx)("div",{className:"pol-hint",children:"Rights an agent inherits when Keiko governs. Tap a decision to cycle through Allow → Ask → Deny."}),t.map(e=>{let t=ly[e.decision];return(0,a.jsxs)("div",{className:"pol-row",children:[(0,a.jsxs)("div",{className:"pol-text",children:[(0,a.jsx)("span",{className:"pol-action",children:e.action}),(0,a.jsx)("span",{className:"pol-scope mono",children:e.scope})]}),(0,a.jsx)("button",{type:"button",className:"pol-dec",style:{color:t[1],borderColor:t[1]},onClick:()=>{let t;return t=e.id,n(e=>e.map(e=>e.id===t?{...e,decision:lb[e.decision]}:e))},children:t[0]})]},e.id)})]})}function lS(e){let{decide:t}=e,[n,s]=(0,l.useState)(!1),i=lj.map(e=>{let n=t(e.kind,e.risk);return{...e,actual:n,pass:n===e.expect}}),r=i.filter(e=>e.pass).length;return(0,a.jsxs)("div",{className:"evl",children:[(0,a.jsxs)("div",{className:"evl-head",children:[(0,a.jsxs)("button",{type:"button",className:"evl-run",onClick:()=>s(!0),children:[(0,a.jsx)(S.spark,{size:13})," Run evaluation"]}),n&&(0,a.jsxs)("span",{className:"evl-score"+(r===i.length?" ok":""),children:[r,"/",i.length," passed"]})]}),(0,a.jsx)("div",{className:"evl-hint",children:"Mock scenarios against your policy before going autonomous."}),i.map(e=>(0,a.jsxs)("div",{className:"evl-row","data-state":n?e.pass?"pass":"fail":"idle",children:[(0,a.jsx)("span",{className:"evl-ico",children:n?e.pass?(0,a.jsx)(S.check,{size:13}):(0,a.jsx)(S.close,{size:13}):(0,a.jsx)("span",{className:"evl-dot"})}),(0,a.jsx)("span",{className:"evl-label",children:e.label}),n&&(0,a.jsx)("span",{className:"evl-res mono",style:{color:ly[e.actual][1]},children:ly[e.actual][0]})]},e.id))]})}function lC(e){let{memory:t,setMemory:n}=e,[s,i]=(0,l.useState)(""),r=()=>{let e=s.trim();""!==e&&(n(t=>[e,...t]),i(""))};return(0,a.jsxs)("div",{className:"mem",children:[(0,a.jsxs)("div",{className:"mem-add",children:[(0,a.jsx)("input",{value:s,onChange:e=>i(e.target.value),placeholder:"Teach Keiko something about you…",onKeyDown:e=>{"Enter"===e.key&&r()}}),(0,a.jsx)("button",{type:"button",onClick:r,"aria-label":"Add memory",children:(0,a.jsx)(S.plus,{size:15})})]}),t.map((e,t)=>(0,a.jsxs)("div",{className:"mem-row",children:[(0,a.jsx)(S.spark,{size:12}),(0,a.jsx)("span",{className:"mem-text",children:e}),(0,a.jsx)("button",{type:"button",className:"mem-x","aria-label":"Remove memory: ".concat(e),onClick:()=>n(e=>e.filter((e,n)=>n!==t)),children:(0,a.jsx)(S.close,{size:12})})]},"".concat(String(t),"-").concat(e)))]})}function lR(e){let{bridges:t,setBridges:n}=e;return(0,a.jsxs)("div",{className:"brg",children:[(0,a.jsx)("div",{className:"evl-hint",children:"What your twin can reach on your behalf."}),lk.map(e=>{let[l,s,i]=e,r=S[i],o=t[l];return(0,a.jsxs)("button",{type:"button",className:"brg-row","data-on":o,"aria-pressed":o,onClick:()=>n(e=>({...e,[l]:!e[l]})),children:[(0,a.jsx)("span",{className:"brg-ico",children:(0,a.jsx)(r,{size:16})}),(0,a.jsx)("span",{className:"brg-name",children:s}),(0,a.jsx)("span",{className:"brg-tg"+(o?" on":""),children:(0,a.jsx)("span",{})})]},l)})]})}function lI(e){let{persona:t,setPersona:n}=e;return(0,a.jsxs)("div",{className:"prs",children:[(0,a.jsx)("div",{className:"evl-hint",children:"Keiko adapts behaviour & tools to who is at the wheel."}),lw.map(e=>{let[l,s]=e;return(0,a.jsxs)("button",{type:"button",className:"prs-row","data-on":t===l,"aria-pressed":t===l,onClick:()=>n(l),children:[(0,a.jsx)("span",{className:"prs-dot"}),(0,a.jsxs)("span",{className:"prs-text",children:[(0,a.jsx)("span",{className:"prs-name",children:l}),(0,a.jsx)("span",{className:"prs-desc",children:s})]}),t===l&&(0,a.jsx)(S.check,{size:14,style:{color:"var(--accent)"}})]},l)})]})}let lE=[["policy","Policy"],["eval","EVAL"],["memory","MemoriaViva"],["bridges","Connections"],["persona","Persona"]];function lM(){let e=w(),[t,n]=(0,l.useState)("policy");return(0,a.jsxs)("div",{className:"twin",children:[(0,a.jsxs)("div",{className:"twin-hero",children:[(0,a.jsx)("img",{className:"twin-orca",src:"/assets/keiko-logo.svg",alt:""}),(0,a.jsxs)("div",{className:"twin-id",children:[(0,a.jsx)("span",{className:"twin-name",children:"Keiko — Digital Twin"}),(0,a.jsxs)("span",{className:"twin-sub mono",children:["mirroring \xb7 ",e.persona]})]}),(0,a.jsx)("span",{className:"twin-mode "+("autonomous"===e.mode?"on":""),children:"autonomous"===e.mode?"Autonomous":"Manual"})]}),(0,a.jsx)("div",{className:"twin-tabs",children:lE.map(e=>{let[l,s]=e;return(0,a.jsx)("button",{type:"button",className:"twin-tab","data-on":t===l,onClick:()=>n(l),children:s},l)})}),(0,a.jsxs)("div",{className:"twin-body",children:["policy"===t&&(0,a.jsx)(lN,{policy:e.policy,setPolicy:e.setPolicy}),"eval"===t&&(0,a.jsx)(lS,{decide:e.decide}),"memory"===t&&(0,a.jsx)(lC,{memory:e.memory,setMemory:e.setMemory}),"bridges"===t&&(0,a.jsx)(lR,{bridges:e.bridges,setBridges:e.setBridges}),"persona"===t&&(0,a.jsx)(lI,{persona:e.persona,setPersona:e.setPersona})]})]})}function lT(e){return"embedding-only"===e?"Embedding model — not selectable for text conversation":"ocr-vision-only"===e?"OCR/vision-only — not selectable for text conversation":"Not a chat model — not selectable for text conversation"}function lq(e){let{model:t}=e,n=(0,tN.nP)(t);return void 0===n?(0,a.jsx)("span",{className:"ml-elig ml-elig-ok","data-testid":"conv-elig-ok",role:"status","aria-label":"Model eligibility: eligible for conversation",children:"Conversation-eligible"}):(0,a.jsxs)("span",{className:"ml-elig ml-elig-no","data-testid":"conv-elig-no",role:"status","aria-label":"Model eligibility: "+lT(n),children:["Not selectable: ",lT(n)]})}function lP(e){var t;let{model:n}=e,l=(0,tN.S_)(n);return(0,a.jsxs)("div",{className:"ml-row",children:[(0,a.jsx)("span",{className:"ml-ico",children:(0,a.jsx)(S.cube,{size:16})}),(0,a.jsxs)("div",{className:"ml-info",children:[(0,a.jsxs)("div",{className:"ml-top",children:[(0,a.jsx)("span",{className:"ml-name",children:n.id}),(0,a.jsx)("span",{className:"ml-type mono",children:"ocr-vision"===(t=n.kind)?"OCR":t}),(0,a.jsx)(lq,{model:n})]}),(0,a.jsxs)("div",{className:"ml-url mono",children:["tools ",n.toolCalling?"yes":"no"," \xb7 structured"," ",n.structuredOutput?"yes":"no"," \xb7 ",n.costClass,"/",n.latencyClass]})]}),(0,a.jsx)("span",{className:"ml-status "+(l?"connected":"ineligible"),title:l?"conversation-eligible":"not selectable for conversation","aria-hidden":"true"})]})}let lA="keiko.wallpaper.opacity";function lz(){let e=window.localStorage.getItem(lA);if(null===e)return 100;let t=Number.parseInt(e,10);return Number.isFinite(t)?Math.max(0,Math.min(100,t)):100}function lD(){let[e,t]=(0,l.useState)(lz);(0,l.useEffect)(()=>{try{window.localStorage.setItem(lA,String(e))}catch(e){}window.dispatchEvent(new CustomEvent("keiko:wallpaper-opacity",{detail:e}))},[e]);let n={"--p":"".concat(String(e),"%")};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"set-sec-h",children:(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"set-sec-t",children:"Workspace wallpaper"}),(0,a.jsx)("div",{className:"set-sec-d",children:"Liquid Chrome — a subtle metallic flow behind the grid that reacts to your cursor and clicks. Set to 0 % for the plain workspace background."})]})}),(0,a.jsxs)("div",{className:"gpref",children:[(0,a.jsxs)("div",{className:"gpref-row",children:[(0,a.jsx)("label",{className:"gpref-label",htmlFor:"wp-op",children:"Wallpaper opacity"}),(0,a.jsxs)("span",{className:"gpref-val mono",children:[e,"%"]})]}),(0,a.jsx)("input",{id:"wp-op",className:"gpref-slider",type:"range",min:0,max:100,step:1,value:e,onChange:e=>t(Number.parseInt(e.target.value,10)),style:n,"aria-label":"Wallpaper opacity"}),(0,a.jsxs)("div",{className:"gpref-scale",children:[(0,a.jsx)("span",{children:"Off"}),(0,a.jsx)("span",{children:"Full"})]})]})]})}function lL(){let[e,t]=(0,l.useState)("models"),[n,s]=(0,l.useState)([]),[i,r]=(0,l.useState)(!1),[o,c]=(0,l.useState)(!0),[d,u]=(0,l.useState)(),[h,p]=(0,l.useState)(!1);(0,l.useEffect)(()=>{let e=!1;return async function(){c(!0),u(void 0);try{let[t,n]=await Promise.all([(0,$.Dz)(),(0,$.ZC)()]);if(e)return;r(t.configPresent),s(n.models)}catch(t){if(e)return;u(t instanceof Error?t.message:"Could not load gateway settings.")}finally{e||c(!1)}}(),()=>{e=!0}},[]);let m=n.filter(tN.S_).length,f=n.length>0;return(0,a.jsxs)("div",{className:"set",children:[(0,a.jsxs)("div",{className:"set-hero",children:[(0,a.jsx)(S.settings,{size:18}),(0,a.jsx)("span",{className:"set-title",children:"Settings"}),(0,a.jsxs)("span",{className:"set-onprem",title:"Runs inside your network",children:[(0,a.jsx)("span",{className:"dot",style:{background:"var(--accent)"}})," Self-hosted"]})]}),(0,a.jsx)("div",{className:"set-tabs",children:["models","general","security"].map(n=>(0,a.jsx)("button",{type:"button",className:"set-tab","data-on":e===n,onClick:()=>t(n),children:"models"===n?"Local Models":"general"===n?"General":"Security"},n))}),(0,a.jsxs)("div",{className:"set-body",children:["models"===e&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"set-sec-h",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"set-sec-t",children:"Model gateway"}),(0,a.jsx)("div",{className:"set-sec-d",children:"Credentials are stored locally by the Keiko loopback server; secrets are never returned to the browser."})]}),(0,a.jsxs)("button",{type:"button",className:"set-add",onClick:()=>p(!0),children:[(0,a.jsx)(S.plus,{size:14}),i?"Update credentials":"Connect gateway"]})]}),(0,a.jsxs)("div",{className:"ml-row",children:[(0,a.jsx)("span",{className:"ml-ico",children:(0,a.jsx)(S.cube,{size:16})}),(0,a.jsxs)("div",{className:"ml-info",children:[(0,a.jsxs)("div",{className:"ml-top",children:[(0,a.jsx)("span",{className:"ml-name",children:i?f?"Gateway connected":"Gateway configured":"Gateway setup required"}),(0,a.jsxs)("span",{className:"ml-type mono",children:[n.length.toString()," models"]}),(0,a.jsxs)("span",{className:"ml-type mono",children:[m.toString()," chat"]})]}),(0,a.jsx)("div",{className:"ml-url mono",children:i?f?"Keiko can use the configured gateway models for chat and agent workflows.":"The gateway is configured, but no conversation-capable models are currently available.":"Enter the gateway base URL and API token before using chat or agent workflows."})]}),(0,a.jsx)("span",{className:"ml-status "+(i?"connected":"untested"),title:i?"gateway configured":"setup required","aria-hidden":"true"})]}),void 0!==d?(0,a.jsx)("div",{className:"gw-error",children:d}):null,o?(0,a.jsx)("div",{className:"set-placeholder",children:"Loading gateway models..."}):0===n.length?(0,a.jsx)("div",{className:"set-placeholder",children:i?"No conversation-capable models are currently available. Review the gateway configuration or discovered model set.":"No models are configured yet. Connect the gateway to load configured model capabilities."}):(0,a.jsx)("div",{className:"set-list",children:n.map(e=>(0,a.jsx)(lP,{model:e},e.id))}),h?(0,a.jsx)(nf,{onCancel:()=>p(!1)}):null]}),"general"===e&&(0,a.jsx)(lD,{}),"security"===e&&(0,a.jsx)("div",{className:"set-placeholder",children:"SSO \xb7 audit log \xb7 data residency — coming soon."})]})]})}function lF(e){return e instanceof $.hD?"".concat(e.code,": ").concat(e.message):e instanceof Error?e.message:"Failed to load connectors."}function lO(){return(0,a.jsx)("div",{className:"connector-picker-status",role:"status","aria-live":"polite",children:"Loading connectors…"})}function lK(e){let{message:t}=e;return(0,a.jsx)("div",{className:"connector-picker-error",role:"alert",children:t})}function lB(){return(0,a.jsxs)("div",{className:"connector-picker-empty",children:[(0,a.jsx)("p",{children:"No ready connectors found."}),(0,a.jsx)("a",{href:"/local-knowledge",className:"connector-picker-create-link",children:"Create a connector"})]})}function lW(e){let{capsules:t,capsuleSets:n,selectedKind:l,selectedId:s}=e,i=function(e,t,n,a){if(void 0===n||void 0===a||0===a.length)return null;if("capsule"===n){let t=e.find(e=>e.id===a);return void 0!==t?t.displayName:"Capsule ".concat(a)}if("capsule-set"===n){let e=t.find(e=>e.id===a);return void 0!==e?e.displayName:"Set ".concat(a)}return null}(t,n,l,s);return null===i?null:(0,a.jsxs)("div",{className:"connector-picker-selected",role:"status","aria-live":"polite",children:[(0,a.jsx)("span",{"aria-hidden":"true",children:"●"}),(0,a.jsx)("span",{children:i})]})}function lU(e){let{selectedKind:t,selectedId:n,onSelect:s}=e,[i,r]=(0,l.useState)([]),[o,c]=(0,l.useState)([]),[d,u]=(0,l.useState)(!0),[h,p]=(0,l.useState)(null);if((0,l.useEffect)(()=>{let e=!1;return async function(){u(!0),p(null);try{let[t,n]=await Promise.allSettled([(0,tG.xr)(),(0,tG.R3)()]);if(e)return;"fulfilled"===t.status?r(t.value.capsules.filter(e=>"ready"===e.lifecycleState)):p(lF(t.reason)),"fulfilled"===n.status&&c(n.value.capsuleSets)}catch(t){e||p(lF(t))}finally{e||u(!1)}}(),()=>{e=!0}},[]),d)return(0,a.jsx)(lO,{});if(null!==h)return(0,a.jsx)(lK,{message:h});let m=i.length>0,f=o.length>0;if(!m&&!f)return(0,a.jsx)(lB,{});let g=void 0!==t&&void 0!==n&&n.length>0?"".concat(t,":").concat(n):"";return(0,a.jsxs)("div",{className:"connector-picker",children:[(0,a.jsx)(lW,{capsules:i,capsuleSets:o,selectedKind:t,selectedId:n}),(0,a.jsx)("label",{className:"connector-picker-label",htmlFor:"connector-picker-select",children:"Select a connector"}),(0,a.jsxs)("select",{id:"connector-picker-select",className:"connector-picker-select",value:g,onChange:e=>{!function(e){if(""===e)return;let t=e.indexOf(":");if(-1===t)return;let n=e.slice(0,t),a=e.slice(t+1);0!==a.length&&s({selectedKind:n,selectedId:a})}(e.target.value)},"aria-label":"Select a Local Knowledge connector",children:[(0,a.jsx)("option",{value:"",disabled:!0,children:"— choose a connector —"}),m&&(0,a.jsx)("optgroup",{label:"Capsules",children:i.map(e=>(0,a.jsx)("option",{value:"capsule:".concat(e.id),children:"".concat(e.displayName," (").concat(function(e){switch(e){case"ready":return"Ready";case"indexing":return"Indexing…";case"error":return"Failed";default:return e}}(e.lifecycleState),")")},"capsule:".concat(e.id)))}),f&&(0,a.jsx)("optgroup",{label:"Capsule sets",children:o.map(e=>(0,a.jsx)("option",{value:"capsule-set:".concat(e.id),children:"".concat(e.displayName," (").concat(String(e.capsuleCount)," capsules)")},"capsule-set:".concat(e.id)))})]}),(0,a.jsx)("div",{className:"connector-picker-footer",children:(0,a.jsx)("a",{href:"/local-knowledge",className:"connector-picker-create-link",children:"Create or manage connectors"})})]})}async function l_(e,t){var n,a;let l=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),s=await fetch(e,{...t,headers:{Accept:"application/json",...(null==t?void 0:t.body)!==void 0?{"Content-Type":"application/json"}:{},..."GET"===l||"HEAD"===l?{}:{"X-Keiko-CSRF":"1"},...null!=(a=null==t?void 0:t.headers)?a:{}}});if(!s.ok){let e="INTERNAL",t="HTTP ".concat(s.status.toString());try{let n=await s.json();e=n.error.code,t=n.error.message}catch(e){}throw new $.hD(e,t,s.status)}return s.json()}async function lH(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return l_("/api/figma/snapshots",{method:"POST",body:JSON.stringify({boardLink:e,...!0===t.acknowledgeReadOnly?{acknowledgeReadOnly:!0}:{},...!0===t.isResnapshot?{isResnapshot:!0}:{}})})}async function lJ(e){return l_("/api/figma/snapshots/".concat(encodeURIComponent(e)))}async function lV(e){return l_("/api/figma/snapshots/".concat(encodeURIComponent(e),"/code"),{method:"POST",body:JSON.stringify({})})}function lG(e){return e instanceof $.hD?"".concat(e.code,": ").concat(e.message):e instanceof Error?e.message:"An unexpected error occurred."}function lX(e){let{index:t,screenId:n,name:l,irSummary:s,imageByteLength:i}=e,r=(i/1024).toFixed(1);return(0,a.jsxs)("article",{className:"figma-snapshot-screen-card","aria-label":"Screen ".concat(String(t+1),": ").concat(l),children:[(0,a.jsx)("div",{className:"figma-snapshot-screen-placeholder","aria-hidden":"true",children:(0,a.jsx)("span",{className:"figma-snapshot-screen-index",children:String(t+1)})}),(0,a.jsxs)("div",{className:"figma-snapshot-screen-meta",children:[(0,a.jsx)("h3",{className:"figma-snapshot-screen-name",children:l}),(0,a.jsx)("p",{className:"figma-snapshot-screen-summary",children:s}),(0,a.jsxs)("p",{className:"figma-snapshot-screen-size",children:[r," KiB"]}),(0,a.jsx)("p",{className:"figma-snapshot-screen-id",children:n})]})]})}function lY(e){let{snapshotRunId:t,updateCfg:n,triggerImpl:s=lH,loadImpl:i=lJ,codegenImpl:r=lV}=e,o=(0,l.useId)(),c=(0,l.useId)(),[d,u]=(0,l.useState)(""),[h,p]=(0,l.useState)("idle"),[m,f]=(0,l.useState)(null),[g,v]=(0,l.useState)(null),[x,y]=(0,l.useState)(!1),[b,j]=(0,l.useState)("idle"),[w,k]=(0,l.useState)(null),[N,S]=(0,l.useState)(null),C=function(e){try{let t=new URL(e.trim()),n=t.hostname.toLowerCase();if("figma.com"!==n&&!n.endsWith(".figma.com")||!/^\/(design|file)\//u.test(t.pathname))return!1;let a=t.searchParams.get("node-id");return null!==a&&a.length>0}catch(e){return!1}}(d),R="building"===h,I=(0,l.useCallback)(async(e,t)=>{p("building"),v(null),j("idle"),k(null);try{let a=await s(e,{acknowledgeReadOnly:x,isResnapshot:t});f(a),n({snapshotRunId:a.runId}),p("done")}catch(e){v(lG(e)),p("error")}},[s,n,x]),E=(0,l.useCallback)(e=>{e.preventDefault(),C&&!R&&I(d,!1)},[d,R,C,I]),M=(0,l.useCallback)(()=>{if(R)return;let e=d.trim().length>0?d:null!==m?"https://www.figma.com/design/".concat(m.fileKey,"/board?node-id=").concat(m.nodeId):"";0!==e.length&&I(e,!0)},[d,R,I,m]),T=(0,l.useCallback)(()=>{var e;let n=null!=(e=null==m?void 0:m.runId)?e:t;void 0!==n&&0!==n.length&&"generating"!==b&&(j("generating"),S(null),r(n).then(e=>{k(e),j("done")}).catch(e=>{S(lG(e)),j("error")}))},[r,b,t,m]),q=(0,l.useCallback)(()=>{void 0!==t&&0!==t.length&&(p("building"),v(null),i(t).then(e=>{f(e),p("done")}).catch(e=>{v(lG(e)),p("error")}))},[i,t]),P=void 0!==t&&t.length>0&&null===m&&"idle"===h;return(0,a.jsxs)("section",{className:"figma-snapshot-window","aria-label":"Figma Snapshot",children:[(0,a.jsxs)("form",{className:"figma-snapshot-form",onSubmit:E,noValidate:!0,children:[(0,a.jsx)("label",{className:"figma-snapshot-label",htmlFor:o,children:"Board link"}),(0,a.jsxs)("div",{className:"figma-snapshot-input-row",children:[(0,a.jsx)("input",{id:o,type:"url",className:"figma-snapshot-input",placeholder:"https://www.figma.com/design/…?node-id=…",value:d,onChange:e=>{u(e.target.value)},"aria-describedby":c,"aria-invalid":d.length>0&&!C?"true":void 0,disabled:R,autoComplete:"off",spellCheck:!1}),(0,a.jsx)("button",{type:"submit",className:"figma-snapshot-trigger-btn",disabled:!C||R,"aria-busy":R,children:R?"Building…":"Snapshot"})]}),(0,a.jsxs)("label",{className:"figma-snapshot-consent",children:[(0,a.jsx)("input",{type:"checkbox",className:"figma-snapshot-consent-checkbox",checked:x,onChange:e=>{y(e.target.checked)},disabled:R}),(0,a.jsxs)("span",{children:["I acknowledge the configured Figma PAT is read-only and least-privilege (",(0,a.jsx)("code",{children:"files:read"}),")."]})]}),(0,a.jsx)("p",{className:"figma-snapshot-hint",children:"Paste a Figma board link with a node-id param (section or frame anchor). The access token is resolved server-side — it never reaches this page."})]}),(0,a.jsxs)("div",{id:c,role:"status","aria-live":"polite","aria-atomic":"true",className:"figma-snapshot-status",children:[R&&(0,a.jsx)("p",{className:"figma-snapshot-progress",children:"Building snapshot — fetching screens from Figma…"}),"error"===h&&null!==g&&(0,a.jsx)("p",{className:"figma-snapshot-error",role:"alert",children:g})]}),P&&(0,a.jsxs)("div",{className:"figma-snapshot-stored-notice",children:[(0,a.jsx)("p",{className:"figma-snapshot-stored-text",children:"A stored snapshot is available."}),(0,a.jsx)("button",{type:"button",className:"figma-snapshot-load-btn",onClick:q,children:"Load snapshot"})]}),null!==m&&"done"===h&&(0,a.jsxs)("div",{className:"figma-snapshot-result",children:[(0,a.jsxs)("div",{className:"figma-snapshot-reduction",children:[(0,a.jsx)("p",{className:"figma-snapshot-reduction-hint",children:m.reductionHint}),m.skippedCount>0&&(0,a.jsxs)("p",{className:"figma-snapshot-skipped-notice",children:[String(m.skippedCount)," screen",1!==m.skippedCount?"s":""," could not be rendered and were skipped."]})]}),(0,a.jsx)("button",{type:"button",className:"figma-snapshot-resnapshot-btn",onClick:M,disabled:R,"aria-label":"Re-snapshot this board",children:"Re-snapshot"}),(0,a.jsxs)("div",{className:"figma-snapshot-codegen",children:[(0,a.jsx)("button",{type:"button",className:"figma-snapshot-codegen-btn",onClick:T,disabled:"generating"===b,"aria-busy":"generating"===b,children:"generating"===b?"Generating code…":"Generate code"}),"error"===b&&null!==N&&(0,a.jsx)("p",{className:"figma-snapshot-error",role:"alert",children:N}),"done"===b&&null!==w&&(0,a.jsxs)("div",{className:"figma-snapshot-code-result",children:[(0,a.jsxs)("p",{className:"figma-snapshot-code-summary",children:[String(w.fileCount)," reviewable file",1!==w.fileCount?"s":""," (",String(w.screenCount)," screen",1!==w.screenCount?"s":"",","," ",w.adapterName,") — proposal only, never auto-applied."]}),w.files.map(e=>(0,a.jsxs)("details",{className:"figma-snapshot-code-file",children:[(0,a.jsx)("summary",{className:"figma-snapshot-code-file-path",children:e.path}),(0,a.jsx)("pre",{className:"figma-snapshot-code-file-contents",children:(0,a.jsx)("code",{children:e.contents})})]},e.path))]})]}),(0,a.jsxs)("details",{className:"figma-snapshot-scopes",children:[(0,a.jsx)("summary",{className:"figma-snapshot-scopes-summary",children:"Required Figma PAT scopes"}),(0,a.jsxs)("ul",{className:"figma-snapshot-scopes-list",children:[(0,a.jsxs)("li",{children:[(0,a.jsx)("code",{children:"file_read"})," — read design file structure and node metadata"]}),(0,a.jsxs)("li",{children:[(0,a.jsx)("code",{children:"files:read"})," — read file content (REST API scope)"]})]}),(0,a.jsxs)("p",{className:"figma-snapshot-scopes-note",children:["The token is read server-side from the ",(0,a.jsx)("code",{children:"FIGMA_ACCESS_TOKEN"})," environment variable or vault. This window never holds or transmits the token."]})]}),m.screens.length>0?(0,a.jsx)("section",{className:"figma-snapshot-gallery","aria-label":"".concat(String(m.screenCount)," captured screen").concat(1!==m.screenCount?"s":""),children:m.screens.map((e,t)=>(0,a.jsx)(lX,{index:t,screenId:e.screenId,name:e.name,irSummary:e.irSummary,imageByteLength:e.imageByteLength},e.screenId))}):(0,a.jsx)("div",{className:"lk-empty",children:(0,a.jsx)("p",{className:"lk-empty-body",children:"No screens were captured from this board section."})})]})]})}async function lZ(e,t){var n,a;let l=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),s=await fetch(e,{...t,headers:{Accept:"application/json",...(null==t?void 0:t.body)!==void 0?{"Content-Type":"application/json"}:{},..."GET"===l||"HEAD"===l?{}:{"X-Keiko-CSRF":"1"},...null!=(a=null==t?void 0:t.headers)?a:{}}});if(!s.ok){let e="INTERNAL",t="HTTP ".concat(s.status.toString());try{let n=await s.json();e=n.error.code,t=n.error.message}catch(e){}throw new $.hD(e,t,s.status)}return s.json()}async function lQ(){return(await lZ("/api/quality-intelligence/runs")).runs}async function l$(e){return lZ("/api/quality-intelligence/runs/".concat(encodeURIComponent(e)))}async function l0(e){let t="QI_RUN_FAILED",n="HTTP ".concat(e.status.toString());try{var a,l,s,i;let r=await e.json();t=null!=(s=null==(a=r.error)?void 0:a.code)?s:t,n=null!=(i=null==(l=r.error)?void 0:l.message)?i:n}catch(e){}return new $.hD(t,n,e.status)}async function l1(e,t,n){var a,l;let s=await fetch("/api/quality-intelligence/runs",{method:"POST",headers:{Accept:"text/event-stream","Content-Type":"application/json","X-Keiko-CSRF":"1"},body:JSON.stringify(e),signal:t}),i=null!=(a=s.headers.get("content-type"))?a:"";if(!s.ok||!i.includes("text/event-stream"))throw await l0(s);let r=s.body;if(null===r)throw new $.hD("QI_NO_STREAM","The server did not return a progress stream.",s.status);let o=r.getReader(),c=new TextDecoder,d="";try{for(;!t.aborted;){let e=await o.read();if(e.done)break;let t=(d+=c.decode(e.value,{stream:!0})).split("\n");for(let e of(d=null!=(l=t.pop())?l:"",t)){let t=e.trim();if(t.startsWith("data:"))try{n(JSON.parse(t.slice(5).trim()))}catch(e){}}}}finally{o.releaseLock()}}async function l2(e,t,n,a){return lZ("/api/quality-intelligence/runs/".concat(encodeURIComponent(e),"/review"),{method:"POST",body:JSON.stringify({action:t,...void 0!==n?{candidateId:n}:{},...void 0!==a?{reviewerLabel:a}:{}})})}async function l5(e,t,n,a){return(await lZ("/api/quality-intelligence/runs/".concat(encodeURIComponent(e),"/edit"),{method:"POST",body:JSON.stringify({candidateId:t,edited:n,...void 0!==a?{editorLabel:a}:{}})})).candidate}async function l3(e,t){return lZ("/api/quality-intelligence/runs/".concat(encodeURIComponent(e),"/re-check"),{method:"POST",body:JSON.stringify({sources:t})})}async function l4(e,t){return lZ("/api/quality-intelligence/runs/".concat(encodeURIComponent(e),"/regenerate-stale"),{method:"POST",body:JSON.stringify({sources:t})})}async function l6(e,t,n){var a,l;return lZ("/api/quality-intelligence/runs/".concat(encodeURIComponent(e),"/export"),{method:"POST",body:JSON.stringify({adapter:t,dryRun:null!=(a=null==n?void 0:n.dryRun)&&a,approvedOnly:null!=(l=null==n?void 0:n.approvedOnly)&&l})})}async function l8(e,t){return lZ("/api/quality-intelligence/runs/".concat(encodeURIComponent(e),"/traceability"),{method:"POST",body:JSON.stringify({format:t})})}function l7(e){var t;let n=e.split(/[\\/]/u).filter(e=>e.length>0);return n.length>0&&null!=(t=n[n.length-1])?t:e}function l9(e){return e.replaceAll("\\","/")}function se(e){return/^[A-Za-z]:[/\\]?$/u.test(e)?e.replaceAll("\\","/"):/^\/\/[^/]+\/[^/]+$/u.test(l9(e))?l9(e):l9(e).replace(/\/+$/u,"")}function st(e){var t,n,a,l,s;let i=null!=(t=e.connectedRoot)?t:null,r=function(e,t){var n,a;let l=null!=(n=null==t?void 0:t.trim())?n:"";if(0===l.length)return null;if(l.startsWith("/")||/^[A-Za-z]:[/\\]/u.test(l)||l.startsWith("\\\\")||l.startsWith("//"))return l;let s=null!=(a=null==e?void 0:e.trim())?a:"";if(0===s.length)return null;let i=se(s),r=l9(l).replace(/^\/+/u,"");return"".concat(i,"/").concat(r)}(i,null!=(n=e.connectedFilePath)?n:null),o=null!==i?se(i):null,c=(void 0!==e.connectedRoots&&null!==e.connectedRoots&&e.connectedRoots.length>0?e.connectedRoots:null!==i?[i]:[]).map(se),d=null!==r?c.filter(e=>e!==o):c,u=[];for(let e of(null!==r&&u.push({kind:"file",label:l7(r),path:r}),d))u.push({kind:"workspace",label:l7(e),path:e});for(let t of null!=(a=e.connectedCapsuleIds)?a:[])u.push({kind:"capsule",label:t,capsuleId:t});for(let t of null!=(l=e.connectedCapsuleSetIds)?l:[])u.push({kind:"capsule-set",label:t,capsuleSetId:t});for(let t of null!=(s=e.connectedFigmaSnapshotRunIds)?s:[])u.push({kind:"figma-snapshot",label:t,snapshotRunId:t});let h=new Set,p=[];for(let e of u){if(p.length>=16)break;let t=function(e){switch(e.kind){case"file":case"workspace":return"".concat(e.kind,":").concat(e.path);case"capsule":return"capsule:".concat(e.capsuleId);case"capsule-set":return"capsule-set:".concat(e.capsuleSetId);case"figma-snapshot":return"figma-snapshot:".concat(e.snapshotRunId)}}(e);h.has(t)||(h.add(t),p.push(e))}return p}let sn=[{id:"regression-default",label:"Regression (default)"},{id:"banking-default",label:"Banking"},{id:"insurance-default",label:"Insurance"}],sa={phase:"Starting…",stageName:null,candidates:0,findings:0,atomCount:null,droppedSourceCount:0,skippedSources:[]};function sl(e){switch(e.kind){case"file":return"File";case"workspace":return"Folder";case"capsule":return"Capsule";case"capsule-set":return"Capsule set";case"figma-snapshot":return"Figma snapshot"}}function ss(e){switch(e.kind){case"file":case"workspace":return e.path;case"capsule":return e.capsuleId;case"capsule-set":return e.capsuleSetId;case"figma-snapshot":return e.snapshotRunId}}function si(e){let{onRunCompleted:t,startImpl:n=l1,connectedRoot:s=null,connectedFilePath:i=null,connectedRoots:r,connectedCapsuleIds:o,connectedCapsuleSetIds:c,connectedFigmaSnapshotRunIds:d}=e,[u,h]=(0,l.useState)(""),[p,m]=(0,l.useState)("requirements"),[f,g]=(0,l.useState)(""),[v,x]=(0,l.useState)(""),[y,b]=(0,l.useState)("regression-default"),[j,w]=(0,l.useState)(""),[k,N]=(0,l.useState)(!1),[S,C]=(0,l.useState)(sa),[R,I]=(0,l.useState)(null),E=(0,l.useRef)(null),M=(0,l.useRef)(null),T=st({connectedRoot:s,connectedFilePath:i,connectedRoots:r,connectedCapsuleIds:o,connectedCapsuleSetIds:c,connectedFigmaSnapshotRunIds:d}),q=T.length>0,P=("requirements"===p?f.trim().length>0:v.trim().length>0)||q,A=j.trim(),z=0===A.length?void 0:/^\d+$/u.test(A)?Number(A):NaN,D=void 0===z||Number.isSafeInteger(z)&&Number.isFinite(z),L=(0,l.useCallback)(e=>{"accepted"===e.type&&(M.current=e.runId),"error"===e.type&&I("".concat(e.code,": ").concat(e.message)),C(t=>(function(e,t){var n,a,l;if("accepted"===t.type)return{...e,phase:"Ingested sources",atomCount:t.atomCount,droppedSourceCount:null!=(n=t.droppedSourceCount)?n:0,skippedSources:null!=(a=t.skippedSources)?a:[]};if("event"===t.type){let n="candidate:proposed"===t.kind?e.candidates+1:e.candidates,a="finding:recorded"===t.kind?e.findings+1:e.findings,s="stage:started"===t.kind?null!=(l=t.stageName)?l:null:e.stageName;return{...e,phase:t.kind,stageName:s,candidates:n,findings:a}}return e})(t,e))},[]),F=(0,l.useCallback)(async()=>{if(!P||k)return;if(!D)return void I("Seed must be a non-negative integer.");N(!0),I(null),C(sa),M.current=null;let e=new AbortController;E.current=e;let a={sources:"requirements"===p&&f.trim().length>0?[{kind:"requirements",label:u.trim()||"Requirements",text:f}]:"workspace"===p&&v.trim().length>0?[{kind:"workspace",label:u.trim()||"Folder",path:v.trim()}]:T,profileId:y,...void 0!==z?{seed:z}:{}};try{await n(a,e.signal,L);let l=M.current;null!==l&&(null==t||t(l))}catch(t){e.signal.aborted||I(t instanceof $.hD?"".concat(t.code,": ").concat(t.message):t instanceof Error?t.message:"An unexpected error occurred.")}finally{N(!1),E.current=null}},[P,p,f,v,u,y,k,T,L,t,z,D,n]),O=(0,l.useCallback)(()=>{var e;null==(e=E.current)||e.abort()},[]);return(0,a.jsxs)("section",{className:"qi-launcher","aria-label":"Start a Quality Intelligence run",children:[(0,a.jsx)("header",{className:"qi-col-header",children:(0,a.jsx)("h2",{className:"qi-col-title",children:"New run"})}),(0,a.jsxs)("div",{className:"qi-launcher-body",children:[1===T.length&&void 0!==T[0]?(0,a.jsxs)("div",{className:"qi-connected-source","data-testid":"qi-connected-source",children:[(0,a.jsxs)("span",{className:"qi-connected-kind",children:["Connected ",sl(T[0]).toLowerCase()]}),(0,a.jsx)("span",{className:"qi-connected-path qi-monospace",title:ss(T[0]),children:ss(T[0])}),(0,a.jsxs)("span",{className:"qi-connected-hint",children:["Generate uses the connected ",sl(T[0]).toLowerCase(),"."]})]}):T.length>1?(0,a.jsxs)("div",{className:"qi-connected-source","data-testid":"qi-connected-source",children:[(0,a.jsxs)("span",{className:"qi-connected-kind",children:["Connected sources (",T.length.toString(),")"]}),(0,a.jsx)("ul",{className:"qi-connected-roots","aria-label":"Connected sources",children:T.map(e=>(0,a.jsxs)("li",{className:"qi-connected-root-item",children:[(0,a.jsx)("span",{className:"qi-connected-root-name",children:sl(e)}),(0,a.jsx)("span",{className:"qi-connected-path qi-monospace",title:ss(e),children:ss(e)})]},"".concat(e.kind,":").concat(ss(e))))}),(0,a.jsx)("span",{className:"qi-connected-hint",children:"Generate uses all connected sources."})]}):null,(0,a.jsxs)("div",{className:"qi-launcher-row",children:[(0,a.jsxs)("label",{className:"qi-field",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Source label"}),(0,a.jsx)("input",{type:"text",className:"qi-input",value:u,placeholder:"e.g. Funds Transfer — acceptance criteria",disabled:k,onChange:e=>{h(e.target.value)}})]}),(0,a.jsxs)("label",{className:"qi-field qi-field-kind",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Source type"}),(0,a.jsxs)("select",{className:"qi-select",value:p,disabled:k,onChange:e=>{m("workspace"===e.target.value?"workspace":"requirements"),I(null)},children:[(0,a.jsx)("option",{value:"requirements",children:"Requirements text"}),(0,a.jsx)("option",{value:"workspace",children:"Local folder"})]})]})]}),"requirements"===p?(0,a.jsxs)("label",{className:"qi-field",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Requirements"}),(0,a.jsx)("textarea",{className:"qi-textarea",value:f,rows:6,placeholder:"Paste requirements or acceptance criteria, one statement per line.",disabled:k,onChange:e=>{g(e.target.value)}})]}):(0,a.jsxs)("label",{className:"qi-field",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Folder path"}),(0,a.jsx)("input",{type:"text",className:"qi-input",value:v,placeholder:"/absolute/path/to/requirements-folder",disabled:k,onChange:e=>{x(e.target.value)}})]}),(0,a.jsxs)("div",{className:"qi-launcher-controls",children:[(0,a.jsxs)("label",{className:"qi-field qi-field-inline",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Policy profile"}),(0,a.jsx)("select",{className:"qi-select",value:y,disabled:k,onChange:e=>{b(e.target.value)},children:sn.map(e=>(0,a.jsx)("option",{value:e.id,children:e.label},e.id))})]}),(0,a.jsxs)("label",{className:"qi-field qi-field-inline",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Seed (optional)"}),(0,a.jsx)("input",{type:"number",min:0,step:1,className:"qi-input",value:j,placeholder:"e.g. 42",disabled:k,onChange:e=>{w(e.target.value),I(null)}})]}),k?(0,a.jsx)("button",{type:"button",className:"qi-btn qi-btn-secondary",onClick:O,children:"Cancel"}):(0,a.jsx)("button",{type:"button",className:"qi-btn qi-btn-primary",disabled:!P||!D,onClick:()=>{F()},children:"Generate test cases"})]}),k?(0,a.jsxs)("div",{className:"qi-progress",role:"status","aria-live":"polite","aria-label":"Run progress","data-testid":"qi-launch-progress",children:[(0,a.jsx)("span",{className:"qi-progress-spinner","aria-hidden":"true"}),(0,a.jsxs)("span",{className:"qi-progress-text",children:[null!==S.stageName?"Stage: ".concat(S.stageName," \xb7 "):"",S.candidates.toString()," test case",1!==S.candidates?"s":"",S.findings>0?" \xb7 ".concat(S.findings.toString()," findings"):""]})]}):null,S.droppedSourceCount>0||S.skippedSources.length>0?(0,a.jsxs)("div",{className:"qi-coverage-notice",role:"status","aria-live":"polite","data-testid":"qi-coverage-notice",children:[S.droppedSourceCount>0?(0,a.jsxs)("p",{className:"qi-coverage-line",children:[S.droppedSourceCount.toString()," source",1!==S.droppedSourceCount?"s":""," over the 16-source limit"," ",1!==S.droppedSourceCount?"were":"was"," not included."]}):null,S.skippedSources.length>0?(0,a.jsxs)("p",{className:"qi-coverage-line",children:[S.skippedSources.length.toString()," connected source",1!==S.skippedSources.length?"s":""," could not be read and"," ",1!==S.skippedSources.length?"were":"was"," skipped:"," ",S.skippedSources.map(e=>e.label).join(", "),"."]}):null]}):null,null!==R?(0,a.jsx)("p",{className:"lk-alert",role:"alert","data-testid":"qi-launch-error",children:R}):null]})]})}function sr(e){return e instanceof $.hD?"".concat(e.code,": ").concat(e.message):e instanceof Error?e.message:"An unexpected error occurred."}function so(e){try{return new Date(e).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"})}catch(t){return e}}let sc={running:"Running",succeeded:"Succeeded",failed:"Failed",cancelled:"Cancelled"},sd={running:"qi-badge-running",succeeded:"qi-badge-succeeded",failed:"qi-badge-failed",cancelled:"qi-badge-cancelled"};function su(e){return"running"===e||"succeeded"===e||"failed"===e||"cancelled"===e}function sh(e){let{status:t}=e,n=su(t)?sc[t]:t,l=su(t)?sd[t]:"qi-badge-default";return(0,a.jsx)("span",{"aria-label":"Status: ".concat(n),className:"qi-badge ".concat(l),children:n})}let sp={critical:"qi-sev-critical",high:"qi-sev-high",medium:"qi-sev-medium",low:"qi-sev-low"};function sm(e){let{severity:t}=e,n="critical"===t||"high"===t||"medium"===t||"low"===t?sp[t]:"qi-sev-low";return(0,a.jsx)("span",{"aria-label":"Severity: ".concat(t),className:"qi-sev ".concat(n),children:t})}function sf(e){let{score:t}=e;if(null===t)return(0,a.jsx)("span",{"aria-label":"Quality score: not available",className:"qi-badge qi-badge-default","data-testid":"qi-quality-badge",children:"—"});let n=Math.round(t);return(0,a.jsx)("span",{"aria-label":"Quality score: ".concat(n.toString()," out of 100"),className:"qi-badge ".concat(n>=90?"qi-quality-high":n>=70?"qi-quality-mid":"qi-quality-low"),"data-testid":"qi-quality-badge",children:n.toString()})}function sg(e){let{flag:t}=e;return(0,a.jsxs)("div",{role:"note","aria-label":"Weak test flagged by the quality judge: ".concat(t.rationale),className:"qi-weak-flag","data-testid":"qi-weak-flag",children:[(0,a.jsxs)("span",{className:"qi-weak-flag-badge",children:[(0,a.jsx)("span",{"aria-hidden":"true",className:"qi-weak-flag-icon",children:"⚠"}),"Weak test"]}),(0,a.jsx)("p",{className:"qi-weak-flag-reason",children:t.rationale})]})}function sv(e){let{height:t=20,width:n="100%"}=e;return(0,a.jsx)("div",{"aria-hidden":"true",className:"qi-skeleton",style:{height:t,width:n}})}function sx(){return(0,a.jsx)("div",{"data-testid":"qi-loading-state","aria-busy":"true",style:{display:"flex",flexDirection:"column",gap:8,padding:"12px 0"},children:[1,2,3].map(e=>(0,a.jsxs)("div",{className:"qi-skeleton-row",children:[(0,a.jsx)(sv,{height:14,width:"60%"}),(0,a.jsx)(sv,{height:12,width:"40%"})]},e))})}function sy(e){let{message:t,onRetry:n}=e;return(0,a.jsxs)("div",{role:"alert","aria-live":"assertive",className:"lk-alert","data-testid":"qi-error-state",children:[t,(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:n,children:"Retry"})]})}function sb(e){let{run:t,onOpen:n}=e;return(0,a.jsx)("li",{children:(0,a.jsxs)("button",{type:"button",className:"qi-run-item",onClick:()=>{n(t.id)},"aria-label":"Open run ".concat(t.id),title:"Open run ".concat(t.id),children:[(0,a.jsx)("span",{className:"qi-run-id",children:t.id.slice(0,16)}),(0,a.jsx)(sh,{status:t.status}),(0,a.jsx)("span",{className:"qi-run-meta",children:so(t.requestedAt)}),(0,a.jsxs)("span",{className:"qi-run-totals",children:[t.totals.candidates.toString()," case",1!==t.totals.candidates?"s":""]})]})})}function sj(e){let{openRun:t,connectedRoot:n=null,connectedFilePath:s=null,connectedRoots:i,connectedCapsuleIds:r,connectedCapsuleSetIds:o,connectedFigmaSnapshotRunIds:c,fetchRunsImpl:d=lQ}=e,[u,h]=(0,l.useState)([]),[p,m]=(0,l.useState)(!0),[f,g]=(0,l.useState)(null),v=(0,l.useCallback)(async()=>{m(!0),g(null);try{h(await d())}catch(e){g(sr(e))}finally{m(!1)}},[d]);(0,l.useEffect)(()=>{v()},[v]);let x=(0,l.useCallback)(e=>{v(),t(e)},[v,t]);return(0,a.jsxs)("div",{className:"qi-hub",children:[(0,a.jsx)(si,{onRunCompleted:x,connectedRoot:n,connectedFilePath:s,connectedRoots:i,connectedCapsuleIds:r,connectedCapsuleSetIds:o,connectedFigmaSnapshotRunIds:c}),(0,a.jsxs)("section",{className:"qi-hub-runs","aria-label":"Quality Intelligence runs",children:[(0,a.jsxs)("header",{className:"qi-col-header",children:[(0,a.jsx)("h2",{className:"qi-col-title",children:"Runs"}),p||null!==f?null:(0,a.jsx)("span",{className:"qi-col-count",children:u.length.toString()})]}),(0,a.jsx)("div",{className:"qi-col-body","aria-live":"polite","aria-busy":p,children:p?(0,a.jsx)(sx,{}):null!==f?(0,a.jsx)(sy,{message:f,onRetry:()=>{v()}}):0===u.length?(0,a.jsxs)("div",{className:"lk-empty",children:[(0,a.jsx)("p",{className:"lk-empty-title",children:"No runs yet"}),(0,a.jsx)("p",{className:"lk-empty-body",children:"Start a run above — generated test cases open as cards on your workspace."})]}):(0,a.jsx)("ul",{className:"qi-run-list","aria-label":"Run list",children:u.map(e=>(0,a.jsx)(sb,{run:e,onOpen:t},e.id))})})]})]})}let sw=["P0","P1","P2","P3"],sk=["safety","compliance","regression","functional","visual"],sN=e=>e.split("\n").map(e=>e.trim()).filter(e=>e.length>0),sS=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]);function sC(e){let{id:t,label:n,value:l,disabled:s=!1,onChange:i}=e;return(0,a.jsxs)("label",{className:"qi-edit-field",htmlFor:t,children:[(0,a.jsx)("span",{className:"qi-edit-label",children:n}),(0,a.jsx)("textarea",{id:t,className:"qi-edit-textarea",value:l,rows:3,disabled:s,onChange:e=>{i(e.target.value)}})]})}function sR(e){let{id:t,label:n,value:l,disabled:s=!1,onChange:i}=e;return(0,a.jsxs)("label",{className:"qi-edit-field",htmlFor:t,children:[(0,a.jsx)("span",{className:"qi-edit-label",children:n}),(0,a.jsx)("input",{id:t,className:"qi-edit-input",value:l,disabled:s,onChange:e=>{i(e.target.value)}})]})}function sI(e){let{id:t,label:n,value:l,options:s,disabled:i=!1,onChange:r}=e;return(0,a.jsxs)("label",{className:"qi-edit-field",htmlFor:t,children:[(0,a.jsx)("span",{className:"qi-edit-label",children:n}),(0,a.jsx)("select",{id:t,className:"qi-edit-select",value:l,disabled:i,onChange:e=>{r(e.target.value)},children:s.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]})}function sE(e){let{onCancel:t,saving:n}=e;return(0,a.jsxs)("div",{className:"qi-edit-actions",children:[(0,a.jsx)("button",{type:"submit",className:"qi-btn qi-btn-approve qi-edit-save",disabled:n,children:"Save"}),(0,a.jsx)("button",{type:"button",className:"qi-btn qi-btn-secondary qi-edit-cancel",onClick:t,disabled:n,children:"Cancel"})]})}function sM(e){let{candidate:t,onSave:n,onCancel:s}=e,[i,r]=(0,l.useState)(()=>({title:t.title,preconditions:t.preconditions.join("\n"),steps:t.steps.join("\n"),expectedResults:t.expectedResults.join("\n"),priority:t.priority,riskClass:t.riskClass,tags:t.tags.join(", ")})),[o,c]=(0,l.useState)(null),[d,u]=(0,l.useState)(!1),h=(0,l.useRef)(null),p=(e,t)=>{c(null),r(n=>({...n,[e]:t}))};(0,l.useEffect)(()=>{let e=e=>{if("Escape"!==e.key||d)return;let t=h.current;null!==t&&t.contains(document.activeElement)&&s()};return document.addEventListener("keydown",e),()=>{document.removeEventListener("keydown",e)}},[s,d]),(0,l.useEffect)(()=>{var e,t;null==(t=h.current)||null==(e=t.querySelector("input.qi-edit-input"))||e.focus()},[]);let m="qi-edit-".concat(t.id),f=async()=>{if(!d){u(!0),c(null);try{await n(function(e,t){let n=sN(t.preconditions),a=sN(t.steps),l=sN(t.expectedResults),s=t.tags.split(",").map(e=>e.trim()).filter(e=>e.length>0);return{...t.title!==e.title?{title:t.title}:{},...!sS(n,e.preconditions)?{preconditions:n}:{},...!sS(a,e.steps)?{steps:a}:{},...!sS(l,e.expectedResults)?{expectedResults:l}:{},...t.priority!==e.priority?{priority:t.priority}:{},...t.riskClass!==e.riskClass?{riskClass:t.riskClass}:{},...!sS(s,e.tags)?{tags:s}:{}}}(t,i))}catch(e){c(sr(e))}finally{u(!1)}}};return(0,a.jsxs)("form",{ref:h,className:"qi-edit-form","aria-label":"Edit ".concat(t.title),"aria-busy":d,onSubmit:e=>{e.preventDefault(),f()},children:[(0,a.jsx)(sR,{id:"".concat(m,"-title"),label:"Title",value:i.title,disabled:d,onChange:e=>{p("title",e)}}),(0,a.jsx)(sC,{id:"".concat(m,"-preconditions"),label:"Preconditions (one per line)",value:i.preconditions,disabled:d,onChange:e=>{p("preconditions",e)}}),(0,a.jsx)(sC,{id:"".concat(m,"-steps"),label:"Steps (one per line)",value:i.steps,disabled:d,onChange:e=>{p("steps",e)}}),(0,a.jsx)(sC,{id:"".concat(m,"-expected"),label:"Expected results (one per line)",value:i.expectedResults,disabled:d,onChange:e=>{p("expectedResults",e)}}),(0,a.jsx)(sI,{id:"".concat(m,"-priority"),label:"Priority",value:i.priority,options:sw,disabled:d,onChange:e=>{p("priority",e)}}),(0,a.jsx)(sI,{id:"".concat(m,"-risk"),label:"Risk class",value:i.riskClass,options:sk,disabled:d,onChange:e=>{p("riskClass",e)}}),(0,a.jsx)(sR,{id:"".concat(m,"-tags"),label:"Tags (comma-separated)",value:i.tags,disabled:d,onChange:e=>{p("tags",e)}}),null!==o?(0,a.jsx)("p",{className:"qi-edit-error",role:"alert","aria-live":"assertive",children:o}):null,(0,a.jsx)(sE,{onCancel:s,saving:d})]})}let sT={open:"Open",approved:"Approved","changes-requested":"Changes requested",rejected:"Rejected",withdrawn:"Withdrawn"},sq={open:"qi-review-open",approved:"qi-review-approved","changes-requested":"qi-review-changes",rejected:"qi-review-rejected",withdrawn:"qi-review-withdrawn"};function sP(e){let{state:t}=e;return(0,a.jsx)("span",{className:"qi-review-badge ".concat(sq[t]),"aria-label":"Review: ".concat(sT[t]),children:sT[t]})}function sA(e){let{items:t,label:n}=e;return 0===t.length?null:(0,a.jsxs)("div",{className:"qi-cand-block",children:[(0,a.jsx)("p",{className:"qi-cand-block-label",children:n}),(0,a.jsx)("ol",{className:"qi-cand-list","aria-label":n,children:t.map((e,t)=>(0,a.jsx)("li",{children:e},"".concat(n,"-").concat(String(t))))})]})}function sz(e){let{className:t,label:n,pressed:l,disabled:s,describedBy:i,onActivate:r}=e;return(0,a.jsx)("button",{type:"button",className:t,...void 0!==l?{"aria-pressed":l}:{},"aria-disabled":s||void 0,"aria-describedby":s?i:void 0,onClick:()=>{s||r()},children:n})}function sD(e){let{candidateId:t,state:n,onReview:l,disabled:s=!1,describedBy:i}=e;return(0,a.jsxs)("div",{className:"qi-cand-actions",role:"group","aria-label":"Review decision",children:[(0,a.jsx)(sz,{className:"qi-btn qi-btn-approve",label:"Approve",pressed:"approved"===n,disabled:s,describedBy:i,onActivate:()=>{l(t,"approve")}}),(0,a.jsx)(sz,{className:"qi-btn qi-btn-reject",label:"Reject",pressed:"rejected"===n,disabled:s,describedBy:i,onActivate:()=>{l(t,"reject")}}),(0,a.jsx)(sz,{className:"qi-btn qi-btn-secondary",label:"Request changes",pressed:"changes-requested"===n,disabled:s,describedBy:i,onActivate:()=>{l(t,"request-changes")}})]})}function sL(e){let{candidate:t,onReview:n,onStartEdit:l,actionsDisabled:s=!1,describedBy:i,editButtonRef:r}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"qi-cand-header",children:[(0,a.jsx)("h3",{className:"qi-cand-title",children:t.title}),(0,a.jsxs)("div",{className:"qi-cand-badges",children:[(0,a.jsx)("span",{className:"qi-cand-pri",children:t.priority}),(0,a.jsx)("span",{className:"qi-cand-risk",children:t.riskClass}),(0,a.jsx)(sP,{state:t.reviewState})]})]}),void 0!==t.weakTestFlag?(0,a.jsx)(sg,{flag:t.weakTestFlag}):null,(0,a.jsx)(sA,{items:t.preconditions,label:"Preconditions"}),(0,a.jsx)(sA,{items:t.steps,label:"Steps"}),(0,a.jsx)(sA,{items:t.expectedResults,label:"Expected results"}),t.tags.length>0?(0,a.jsx)("ul",{className:"qi-cand-tags","aria-label":"Tags",children:t.tags.map(e=>(0,a.jsx)("li",{className:"qi-cand-tag",children:e},e))}):null,(0,a.jsxs)("div",{className:"qi-cand-actions-row",children:[void 0!==l?(0,a.jsx)("button",{ref:r,type:"button",className:"qi-btn qi-btn-secondary qi-cand-edit","aria-disabled":s||void 0,"aria-describedby":s?i:void 0,onClick:()=>{s||l()},children:"Edit"}):null,void 0!==n?(0,a.jsx)(sD,{candidateId:t.id,state:t.reviewState,onReview:n,disabled:s,describedBy:i}):null]})]})}function sF(e){let{candidate:t,onReview:n,onEdit:s,actionsDisabled:i=!1,describedBy:r}=e,[o,c]=(0,l.useState)(!1),d=(0,l.useRef)(null),u=(0,l.useRef)(!1);(0,l.useEffect)(()=>{var e;u.current&&!o&&(null==(e=d.current)||e.focus()),u.current=o},[o]);let h=async e=>{void 0!==s&&await s(t.id,e),c(!1)};return(0,a.jsx)("li",{className:"qi-cand-card",children:o&&void 0!==s?(0,a.jsx)(sM,{candidate:t,onSave:h,onCancel:()=>{c(!1)}}):(0,a.jsx)(sL,{candidate:t,onReview:n,actionsDisabled:i,describedBy:r,editButtonRef:d,onStartEdit:void 0!==s?()=>{c(!0)}:void 0})})}function sO(e){let{candidates:t,onReview:n,onEdit:s,actionsDisabled:i=!1,actionsDisabledReason:r}=e,[o,c]=(0,l.useState)(25),d=(0,l.useId)(),u=i&&void 0!==r;if(0===t.length)return(0,a.jsxs)("div",{className:"lk-empty",children:[(0,a.jsx)("p",{className:"lk-empty-title",children:"No test cases"}),(0,a.jsx)("p",{className:"lk-empty-body",children:"This run produced no generated test cases."})]});let h=t.slice(0,o);return(0,a.jsxs)("div",{className:"qi-cand-pane",children:[u?(0,a.jsx)("p",{id:d,className:"qi-cand-governance-note",role:"note",children:r}):null,(0,a.jsx)("ul",{className:"qi-cand-cards","aria-label":"Generated test cases",children:h.map(e=>(0,a.jsx)(sF,{candidate:e,onReview:n,onEdit:s,actionsDisabled:i,describedBy:u?d:void 0},e.id))}),o<t.length?(0,a.jsxs)("button",{type:"button",className:"qi-btn qi-btn-secondary qi-cand-more",onClick:()=>{c(e=>e+25)},children:["Show more (",(t.length-o).toString()," remaining)"]}):null]})}function sK(e){let{staleCount:t}=e;return 0===t?(0,a.jsxs)("p",{className:"qi-drift-fresh",role:"status","data-testid":"qi-drift-fresh",children:[(0,a.jsx)("span",{"aria-hidden":"true",className:"qi-drift-icon-ok",children:"✓"}),"No drift — every test is current."]}):(0,a.jsxs)("p",{className:"qi-drift-stale",role:"status","data-testid":"qi-drift-stale",children:[(0,a.jsx)("span",{"aria-hidden":"true",className:"qi-drift-icon-warn",children:"⚠"}),"".concat(t.toString()," ").concat(1===t?"test is":"tests are"," stale — source changed since this run.")]})}function sB(e){let{runId:t,connectedSources:n,onRegenerated:s,reCheckImpl:i=l3,regenerateImpl:r=l4}=e,[o,c]=(0,l.useState)(null),[d,u]=(0,l.useState)(!1),[h,p]=(0,l.useState)(null),[m,f]=(0,l.useState)(null),g=(0,l.useCallback)(()=>{(async()=>{u(!0),p(null),f(null);try{c(await i(t,n))}catch(e){p(sr(e))}finally{u(!1)}})()},[i,t,n]),v=(0,l.useCallback)(()=>{(async()=>{u(!0),p(null);try{let e=await r(t,n);f(e),c(null),null==s||s(e)}catch(e){p(sr(e))}finally{u(!1)}})()},[r,t,n,s]);return(0,a.jsxs)("section",{className:"qi-drift-panel","aria-label":"Drift detection",children:[(0,a.jsxs)("div",{className:"qi-drift-head",children:[(0,a.jsx)("h3",{className:"qi-col-subtitle",children:"Living tests"}),(0,a.jsx)("button",{type:"button",className:"qi-btn qi-btn-secondary",onClick:g,disabled:d,"data-testid":"qi-drift-recheck",children:d?"Checking…":"Re-check drift"})]}),null!==h?(0,a.jsx)("p",{className:"lk-alert",role:"alert",children:h}):null,null!==o?(0,a.jsx)(sK,{staleCount:o.staleCount}):null,null!==o&&o.staleCount>0&&null===m?(0,a.jsx)("button",{type:"button",className:"qi-btn qi-btn-approve",onClick:v,disabled:d,"data-testid":"qi-drift-regenerate",children:"Regenerate ".concat(o.staleCount.toString()," stale ").concat(1===o.staleCount?"test":"tests")}):null,null!==m?(0,a.jsx)("p",{className:"qi-drift-regenerated",role:"status","data-testid":"qi-drift-regenerated",children:"Regenerated ".concat(m.regeneratedCount.toString()," test(s) as a new run (").concat(m.preservedCount.toString()," preserved).")}):null]})}let sW={"traceability-csv":"csv","traceability-markdown":"markdown"},sU=[{id:"csv",label:"CSV",tms:!1},{id:"json",label:"JSON",tms:!1},{id:"spreadsheet-safe-csv",label:"Spreadsheet-safe CSV",tms:!1},{id:"markdown",label:"Markdown",tms:!1},{id:"plain-text",label:"Plain text",tms:!1},{id:"pdf",label:"PDF",tms:!1},{id:"zip-bundle",label:"ZIP bundle (all formats)",tms:!1},{id:"traceability-csv",label:"Traceability matrix (CSV)",tms:!1},{id:"traceability-markdown",label:"Traceability matrix (Markdown)",tms:!1},{id:"jira-issues",label:"Jira (preview)",tms:!0},{id:"qtest",label:"qTest (preview)",tms:!0},{id:"xray",label:"Xray (preview)",tms:!0},{id:"polarion",label:"Polarion (preview)",tms:!0},{id:"quality-center",label:"Quality Center (preview)",tms:!0}];function s_(e,t,n,a){let l=new Blob(["base64"===a?function(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}(n):n],{type:t}),s=URL.createObjectURL(l),i=document.createElement("a");i.href=s,i.download=e,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(s)}function sH(e){var t;let{runId:n,exportImpl:s=l6,traceabilityImpl:i=l8}=e,[r,o]=(0,l.useState)("csv"),[c,d]=(0,l.useState)(!1),[u,h]=(0,l.useState)(null),[p,m]=(0,l.useState)(null),[f,g]=(0,l.useState)(null),v=sU.find(e=>e.id===r),x=null!=(t=null==v?void 0:v.tms)&&t,y=(0,l.useCallback)(async()=>{let e=sW[r];if(void 0!==e){let t=await i(n,e);s_(t.filename,t.contentType,t.body),g(t.filename);return}let t=await s(n,r,{dryRun:x,approvedOnly:!1});t.dryRun?m("".concat(t.candidateCount.toString()," candidates \xb7 ").concat(t.byteLen.toString()," bytes\n\n").concat(t.preview)):(s_(t.filename,t.contentType,t.body,t.encoding),g(t.filename))},[n,r,x,s,i]),b=(0,l.useCallback)(async()=>{d(!0),h(null),m(null),g(null);try{await y()}catch(e){h(e instanceof $.hD?"".concat(e.code,": ").concat(e.message):e instanceof Error?e.message:"Export failed.")}finally{d(!1)}},[y]);return(0,a.jsxs)("div",{className:"qi-export","data-testid":"qi-export-bar",children:[(0,a.jsxs)("label",{className:"qi-field qi-field-inline",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Export"}),(0,a.jsx)("select",{className:"qi-select",value:r,disabled:c,onChange:e=>{o(e.target.value),m(null),h(null),g(null)},children:sU.map(e=>(0,a.jsx)("option",{value:e.id,children:e.label},e.id))})]}),(0,a.jsx)("button",{type:"button",className:"qi-btn qi-btn-secondary",disabled:c,onClick:()=>{b()},children:x?"Preview":"Download"}),x?(0,a.jsx)("p",{className:"qi-export-hint",role:"note","data-testid":"qi-export-connector-hint",children:(null==v?void 0:v.id)==="quality-center"?"Quality Center is preview-only. Configure a connector to enable live export.":"External target — preview only. Configure a connector to enable live export."}):null,null!==f?(0,a.jsx)("p",{className:"qi-export-success",role:"status","aria-live":"polite","data-testid":"qi-export-success",children:"Downloaded ".concat(f)}):null,null!==p?(0,a.jsx)("pre",{className:"qi-export-preview",role:"status","aria-live":"polite","data-testid":"qi-export-preview",children:p}):null,null!==u?(0,a.jsx)("p",{className:"lk-alert",role:"alert","data-testid":"qi-export-error",children:u}):null]})}let sJ="keiko.qi.reviewerLabel",sV="Set a reviewer label to review or edit candidates.";function sG(e){let{detail:t}=e;return(0,a.jsxs)("dl",{className:"qi-run-summary","aria-label":"Run summary",children:[(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Status"}),(0,a.jsx)("dd",{children:(0,a.jsx)(sh,{status:t.status})})]}),(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Test cases"}),(0,a.jsx)("dd",{children:t.totals.candidates.toString()})]}),(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Findings"}),(0,a.jsx)("dd",{children:t.totals.findings.toString()})]}),(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Quality"}),(0,a.jsx)("dd",{children:(0,a.jsx)(sf,{score:t.qualityScore})})]}),(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Review"}),(0,a.jsx)("dd",{className:"qi-run-summary-review",children:t.reviewState})]}),(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Requested"}),(0,a.jsx)("dd",{children:so(t.requestedAt)})]}),null!==t.completedAt?(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Completed"}),(0,a.jsx)("dd",{children:so(t.completedAt)})]}):null]})}function sX(e){let{detail:t}=e;return 0===t.findingRefs.length?null:(0,a.jsxs)("section",{className:"qi-run-findings","aria-label":"Findings",children:[(0,a.jsxs)("h3",{className:"qi-col-subtitle",children:["Findings",(0,a.jsx)("span",{className:"qi-col-count",children:t.findingRefs.length.toString()})]}),(0,a.jsx)("ul",{className:"qi-finding-list","aria-label":"Findings list",children:t.findingRefs.map(e=>(0,a.jsxs)("li",{className:"qi-finding-item",children:[(0,a.jsxs)("div",{className:"qi-finding-header",children:[(0,a.jsx)("span",{className:"qi-finding-kind",children:e.kind}),(0,a.jsx)(sm,{severity:e.severity})]}),(0,a.jsx)("p",{className:"qi-finding-summary",children:e.summaryRedacted})]},e.id))})]})}let sY={covered:"Covered","weakly-covered":"Weakly covered",uncovered:"Uncovered"},sZ={covered:"qi-cov-covered","weakly-covered":"qi-cov-weak",uncovered:"qi-cov-uncovered"};function sQ(e){let{detail:t}=e;if(0===t.coverageByAtom.length)return null;let n=t.coverageByAtom.length,l=t.coverageByAtom.filter(e=>"covered"===e.status).length,s=t.coverageByAtom.filter(e=>"covered"!==e.status);return(0,a.jsxs)("section",{className:"qi-coverage-panel","aria-label":"Coverage",children:[(0,a.jsxs)("h3",{className:"qi-col-subtitle",children:["Coverage",(0,a.jsxs)("span",{className:"qi-badge qi-badge-default","aria-label":"Coverage: ".concat(t.coveragePercentage.toFixed(0)," percent, ").concat(l.toString()," of ").concat(n.toString()," requirements covered"),"data-testid":"qi-coverage-pct",children:[t.coveragePercentage.toFixed(0),"%"]})]}),(0,a.jsx)("p",{className:"qi-coverage-summary","data-testid":"qi-coverage-summary",children:"".concat(l.toString()," of ").concat(n.toString()," requirements covered \xb7 ").concat(s.length.toString()," gap").concat(1===s.length?"":"s")}),s.length>0?(0,a.jsxs)("section",{className:"qi-coverage-gaps","aria-label":"Gap radar",children:[(0,a.jsx)("h4",{className:"qi-col-subtitle",children:"Gap radar (".concat(s.length.toString(),")")}),(0,a.jsx)("ul",{className:"qi-coverage-gap-list","aria-label":"Uncovered and weakly covered atoms",children:s.map(e=>{let t=sY[e.status],n=sZ[e.status],l=e.requirementExcerptRedacted;return(0,a.jsxs)("li",{className:"qi-coverage-gap-item","aria-label":void 0===l?"Atom ".concat(e.atomId,": ").concat(t):'Requirement "'.concat(l,'" (atom ').concat(e.atomId,"): ").concat(t),children:[(0,a.jsxs)("span",{className:"qi-coverage-gap-req",children:[void 0===l?null:(0,a.jsx)("span",{className:"qi-coverage-gap-text","data-testid":"qi-coverage-gap-text",children:l}),(0,a.jsx)("span",{className:"qi-coverage-atom-id qi-monospace",children:e.atomId})]}),(0,a.jsx)("span",{className:"qi-badge ".concat(n),"aria-hidden":"true",children:t}),(0,a.jsx)("span",{className:"qi-sr-only",children:t})]},e.atomId)})})]}):null]})}function s$(e){let{runId:t,connectedSources:n,onRegenerated:s,fetchDetailImpl:i=l$,reviewImpl:r=l2,editImpl:o=l5,reCheckImpl:c,regenerateImpl:d}=e,[u,h]=(0,l.useState)(null),[p,m]=(0,l.useState)(!0),[f,g]=(0,l.useState)(null),[v,x]=(0,l.useState)(""),[y,b]=(0,l.useState)(!1),j=(0,l.useId)(),w=(0,l.useId)(),k=(0,l.useRef)(0),N=(0,l.useCallback)(async()=>{let e=k.current+1;k.current=e,m(!0),g(null);try{let n=await i(t);k.current===e&&h(n)}catch(t){k.current===e&&g(sr(t))}finally{k.current===e&&m(!1)}},[i,t]);(0,l.useEffect)(()=>{N()},[N]),(0,l.useEffect)(()=>{x(function(){try{var e;return null!=(e=window.localStorage.getItem(sJ))?e:""}catch(e){return""}}()),b(!0)},[]),(0,l.useEffect)(()=>{if(y)try{window.localStorage.setItem(sJ,v)}catch(e){}},[v,y]);let S=v.trim(),C=S.length>0,R=(0,l.useCallback)((e,n)=>{C&&(async()=>{try{await r(t,n,e,S),await N()}catch(e){g(sr(e))}})()},[C,r,t,S,N]),I=(0,l.useCallback)(async(e,n)=>{if(!C)throw Error(sV);await o(t,e,n,S),await N()},[o,C,t,S,N]);return(0,a.jsxs)("div",{className:"qi-run-card","data-testid":"qi-run-card",children:[(0,a.jsx)("header",{className:"qi-run-card-head",children:(0,a.jsx)("span",{className:"qi-run-id qi-monospace",title:t,children:t})}),(0,a.jsx)("div",{className:"qi-run-card-body",role:"status","aria-live":"polite","aria-busy":p,children:p&&null===u?(0,a.jsx)(sx,{}):null!==f?(0,a.jsx)(sy,{message:f,onRetry:()=>void N()}):null===u?(0,a.jsx)("div",{className:"lk-empty",children:(0,a.jsx)("p",{className:"lk-empty-body",children:"Run not found."})}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("section",{className:"qi-run-governance","aria-label":"Review governance",children:[(0,a.jsxs)("label",{className:"qi-field",htmlFor:"qi-reviewer-label-".concat(t),children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Reviewer label"}),(0,a.jsx)("input",{id:"qi-reviewer-label-".concat(t),className:"qi-input qi-run-governance-input",value:v,placeholder:"Required for review and edit actions","aria-invalid":!C,"aria-describedby":C?j:"".concat(j," ").concat(w),onChange:e=>{x(e.target.value)}})]}),(0,a.jsx)("p",{id:j,className:"qi-run-governance-help",children:"Used for QI review and edit audit entries."}),C?null:(0,a.jsx)("p",{id:w,className:"qi-run-governance-warning",role:"note",children:sV})]}),(0,a.jsx)(sG,{detail:u}),(0,a.jsx)(sX,{detail:u}),(0,a.jsx)(sQ,{detail:u}),void 0!==n&&n.length>0?(0,a.jsx)(sB,{runId:t,connectedSources:n,onRegenerated:s,reCheckImpl:c,regenerateImpl:d}):null,(0,a.jsxs)("section",{className:"qi-run-cases","aria-label":"Generated test cases",children:[(0,a.jsxs)("div",{className:"qi-run-cases-head",children:[(0,a.jsxs)("h3",{className:"qi-col-subtitle",children:["Test cases",(0,a.jsx)("span",{className:"qi-col-count",children:u.candidates.length.toString()})]}),u.candidates.length>0?(0,a.jsx)(sH,{runId:t}):null]}),(0,a.jsx)(sO,{candidates:u.candidates,onReview:R,onEdit:I,actionsDisabled:!C,actionsDisabledReason:sV})]})]})})]})}let s0={inactive:{label:"Inactive",ariaDescription:"No recent activity for this relationship.",iconShape:"hollow-circle",textColor:"var(--fg-muted)",bgColor:"var(--inset)",animated:!1},queued:{label:"Queued",ariaDescription:"A workflow run referencing this relationship is queued.",iconShape:"clock",textColor:"var(--fg-muted)",bgColor:"var(--inset)",animated:!1},active:{label:"Active",ariaDescription:"A model call referencing this relationship is in progress.",iconShape:"filled-circle",textColor:"var(--accent)",bgColor:"var(--accent-dim)",borderColor:"var(--accent-line)",animated:!1},processing:{label:"Processing",ariaDescription:"A tool or command referencing this relationship is executing.",iconShape:"spinning-circle",textColor:"var(--accent)",bgColor:"var(--accent-dim)",borderColor:"var(--accent-line)",animated:!0},completed:{label:"Completed",ariaDescription:"The most recent run referencing this relationship completed successfully.",iconShape:"check",textColor:"var(--accent)",bgColor:"var(--accent-dim)",animated:!1},failed:{label:"Failed",ariaDescription:"The most recent run referencing this relationship failed.",iconShape:"triangle-exclamation",textColor:"var(--danger)",bgColor:"color-mix(in oklch, var(--danger) 12%, var(--card))",animated:!1},blocked:{label:"Blocked",ariaDescription:"The validator denied a recent proposal referencing this relationship; see the inspector for the reason.",iconShape:"filled-square",textColor:"var(--warn)",bgColor:"color-mix(in oklch, var(--warn) 12%, var(--card))",animated:!1},degraded:{label:"Degraded",ariaDescription:"The health check flagged at least one endpoint of this relationship as not currently live.",iconShape:"broken-line",textColor:"var(--warn)",bgColor:"color-mix(in oklch, var(--warn) 8%, var(--card))",animated:!1},"high-throughput":{label:"High throughput",ariaDescription:"More than fifty events referenced this relationship in the last sixty seconds.",iconShape:"stacked-lines",textColor:"var(--accent)",bgColor:"var(--accent-dim)",animated:!1}};function s1(e){let{shape:t,color:n,animated:l,highContrast:s}=e,i=["rb-edge-badge-icon",l?"rb-edge-badge-icon--processing":"",s?"rb-edge-badge-icon--high-contrast":""].filter(e=>e.length>0).join(" "),r=s?2:1.5,o={width:12,height:12,viewBox:"0 0 12 12","aria-hidden":!0,fill:"currentColor",className:i,style:{color:n}};switch(t){case"hollow-circle":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("circle",{cx:"6",cy:"6",r:"4.5",fill:"none",stroke:"currentColor",strokeWidth:r})});case"clock":return(0,a.jsxs)("svg",{...o,children:[(0,a.jsx)("circle",{cx:"6",cy:"6",r:"4.5",fill:"none",stroke:"currentColor",strokeWidth:r}),(0,a.jsx)("path",{d:"M6 3v3l2 1",stroke:"currentColor",strokeWidth:r,strokeLinecap:"round",fill:"none"})]});case"filled-circle":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("circle",{cx:"6",cy:"6",r:"5"})});case"spinning-circle":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("circle",{cx:"6",cy:"6",r:"4.5",fill:"none",stroke:"currentColor",strokeWidth:r,strokeDasharray:"8 4"})});case"check":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("path",{d:"M2 6l3 3 5-5",stroke:"currentColor",strokeWidth:s?2.2:1.8,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})});case"triangle-exclamation":return(0,a.jsxs)("svg",{...o,children:[(0,a.jsx)("path",{d:"M6 1 L11 10 L1 10 Z",fill:"currentColor"}),(0,a.jsx)("path",{d:"M6 5v2.5",stroke:"var(--card)",strokeWidth:r,strokeLinecap:"round",fill:"none"}),(0,a.jsx)("circle",{cx:"6",cy:"9",r:"0.7",fill:"var(--card)"})]});case"filled-square":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("rect",{x:"1.5",y:"1.5",width:"9",height:"9",rx:"1.5"})});case"broken-line":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("path",{d:"M1 6h2.5l1.5-2 2 4 1.5-2H11",stroke:"currentColor",strokeWidth:r,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})});case"stacked-lines":return(0,a.jsxs)("svg",{...o,children:[(0,a.jsx)("rect",{x:"2",y:"2.5",width:"8",height:"1.5",rx:"0.75"}),(0,a.jsx)("rect",{x:"2",y:"5.25",width:"8",height:"1.5",rx:"0.75"}),(0,a.jsx)("rect",{x:"2",y:"8",width:"8",height:"1.5",rx:"0.75"})]})}}function s2(e){let{state:t}=e,n={width:10,height:10,viewBox:"0 0 10 10","aria-hidden":!0,fill:"currentColor"};switch(t){case"draft":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("circle",{cx:"5",cy:"5",r:"4",fill:"none",stroke:"currentColor",strokeWidth:"1.5"})});case"active":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("circle",{cx:"5",cy:"5",r:"4.5"})});case"archived":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("rect",{x:"1",y:"1",width:"8",height:"8",rx:"1"})});case"superseded":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("path",{d:"M2 5h6M6 3l2 2-2 2",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})});case"revoked":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("path",{d:"M2 2l6 6M8 2L2 8",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",fill:"none"})});case"blocked":return(0,a.jsxs)("svg",{...n,children:[(0,a.jsx)("rect",{x:"1",y:"1",width:"8",height:"8",rx:"1"}),(0,a.jsx)("path",{d:"M5 3v3",stroke:"var(--card)",strokeWidth:"1.5",strokeLinecap:"round",fill:"none"}),(0,a.jsx)("circle",{cx:"5",cy:"7.5",r:"0.6",fill:"var(--card)"})]});case"stale":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("rect",{x:"1",y:"1",width:"8",height:"8",rx:"1",fill:"none",stroke:"currentColor",strokeWidth:"1.5"})})}}function s5(e){var t;let{type:n,lifecycle:s,activity:i,throughputCount:r,animateOverride:o=!0,highContrast:c,onClick:d,className:u=""}=e,[h,p]=(0,l.useState)(!1);(0,l.useEffect)(()=>{if(void 0!==c)return;let e=window.matchMedia("(prefers-contrast: more)"),t=e=>{p(e)};t(e.matches);let n=e=>{t(e.matches)};return e.addEventListener("change",n),()=>{e.removeEventListener("change",n)}},[c]);let m=null!=(t=s0[i])?t:s0.inactive,f=n0[n],g=null!=c?c:h,v="high-throughput"===i&&void 0!==r?"".concat(m.label," (").concat(String(r),")"):m.label,x="".concat(f.displayName," — ").concat(m.ariaDescription),y=m.animated&&o,b=g?{color:m.textColor,background:"var(--card)",border:"1px solid ".concat(m.textColor)}:{color:m.textColor,background:m.bgColor,border:void 0!==m.borderColor?"1px solid ".concat(m.borderColor):void 0};return(0,a.jsx)("span",{role:"status","aria-live":"polite","aria-atomic":"true",className:"rb-edge-badge ".concat(u).trim(),"data-activity-state":i,"data-high-contrast":g?"true":void 0,children:void 0!==d?(0,a.jsxs)("button",{type:"button",className:"rb-edge-badge-btn",style:b,"aria-label":x,onClick:d,children:[(0,a.jsx)("span",{"aria-hidden":"true",children:(0,a.jsx)(s1,{shape:m.iconShape,color:m.textColor,animated:y,highContrast:g})}),(0,a.jsx)("span",{className:"visually-hidden",children:m.ariaDescription}),(0,a.jsx)("span",{"aria-hidden":"true",className:"rb-edge-badge-label",children:v}),(0,a.jsx)("span",{className:"rb-edge-badge-type",children:f.displayName}),(0,a.jsx)(s2,{state:s})]}):(0,a.jsxs)("span",{className:"rb-edge-badge-static",style:b,"aria-label":x,children:[(0,a.jsx)("span",{"aria-hidden":"true",children:(0,a.jsx)(s1,{shape:m.iconShape,color:m.textColor,animated:y,highContrast:g})}),(0,a.jsx)("span",{className:"visually-hidden",children:m.ariaDescription}),(0,a.jsx)("span",{"aria-hidden":"true",className:"rb-edge-badge-label",children:v}),(0,a.jsx)("span",{className:"rb-edge-badge-type",children:f.displayName}),(0,a.jsx)(s2,{state:s})]})})}let s3="keiko.relationships.density",s4={minimal:5,standard:25,dense:512};function s6(){try{let e=window.localStorage.getItem(s3);if("minimal"===e||"standard"===e||"dense"===e)return e}catch(e){}return"minimal"}function s8(){return"undefined"!=typeof document&&null!==document.querySelector('[role="dialog"][aria-modal="true"]')}function s7(e,t){return void 0===e||0===e.length?[]:e.split(",").map(e=>e.trim()).filter(e=>t.includes(e))}function s9(e){return{types:s7(e.relType,nQ),lifecycles:s7(e.relLifecycle,n$),activities:s7(e.relActivity,["inactive","queued","active","processing","completed","failed","blocked","degraded","high-throughput"]),srcKinds:s7(e.relSrcKind,nY),tgtKinds:s7(e.relTgtKind,nY)}}let ie={"high-throughput":0,processing:1,active:2,blocked:3,failed:4,degraded:5,queued:6,completed:7,inactive:8};function it(e,t,n){var a;return null!=(a=n.get(e))?a:function(e){switch(e){case"blocked":return"blocked";case"stale":return"degraded";default:return"inactive"}}(t)}function ia(e){var t;let{filters:n,selectedId:s,onSelect:i,onFilterChange:r,activityMap:o=new Map,throughputMap:c=new Map,animateBadges:d=!0,highContrast:u=!1}=e,[h,p]=(0,l.useState)(()=>{let e=n.relDensity;return"minimal"===e||"standard"===e||"dense"===e?e:s6()}),[m,f]=(0,l.useState)(!1),[g,v]=(0,l.useState)([]),[x,y]=(0,l.useState)(!1),[b,j]=(0,l.useState)(null),[w,k]=(0,l.useState)(!1),[N,S]=(0,l.useState)(null),C=(0,l.useRef)(null),[R,I]=(0,l.useState)(null!=(t=n.relType)?t:""),E=(0,l.useRef)(null),M=(0,l.useCallback)(e=>{p(e),void 0===n.relDensity&&function(e){try{window.localStorage.setItem(s3,e)}catch(e){}}(e)},[n.relDensity]);(0,l.useEffect)(()=>{let e=n.relDensity;if("minimal"===e||"standard"===e||"dense"===e)return void p(e);p(s6())},[n.relDensity]),(0,l.useEffect)(()=>{var e;I(null!=(e=n.relType)?e:"")},[n.relType]);let T=(0,l.useCallback)(async()=>{j(null),y(!0);try{let e=s9(n),t=1===e.lifecycles.length?e.lifecycles[0]:"active",a=1===e.types.length?e.types[0]:void 0,l=1===e.srcKinds.length?e.srcKinds[0]:void 0,s=1===e.tgtKinds.length?e.tgtKinds[0]:void 0,i=await n8({lifecycle:t,type:a,sourceKind:l,targetKind:s,limit:s4[h]});v(i.entries),k(i.truncated),S(i.truncated?i.entries.length+1:i.entries.length)}catch(e){j(e instanceof n2?e.message:"Unable to reach the local backend. Check that `keiko serve` is running.")}finally{y(!1)}},[n,h]);(0,l.useEffect)(()=>{T()},[T]),(0,l.useEffect)(()=>{function e(e){if(s8())return;let t=document.activeElement;t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement||(("f"===e.key||"F"===e.key)&&(e.preventDefault(),f(e=>!e)),"Escape"===e.key&&f(!1))}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]),(0,l.useEffect)(()=>{function e(e){if(s8())return;let t=document.activeElement;if(!(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement)&&"/"===e.key){var n;e.preventDefault(),null==(n=C.current)||n.focus()}}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let q=(0,l.useCallback)(e=>{let t=e.target.value;I(t),null!==E.current&&clearTimeout(E.current),E.current=setTimeout(()=>{r({relType:t.length>0?t:void 0})},250)},[r]),P=(0,l.useMemo)(()=>{let e=s9(n);return(0===e.activities.length?g:g.filter(t=>e.activities.includes(it(t.id,t.lifecycle,o)))).slice(0,s4[h])},[o,h,n,g]),A=P.slice(0,25),z=P.slice(25),D=z.length,L=D>0?function(e,t){let n=new Map;for(let l of e){var a;let e=it(l.id,l.lifecycle,t);n.set(e,(null!=(a=n.get(e))?a:0)+1)}return Array.from(n.entries()).sort((e,t)=>{var n,a;return t[1]!==e[1]?t[1]-e[1]:(null!=(n=ie[e[0]])?n:Number.MAX_SAFE_INTEGER)-(null!=(a=ie[t[0]])?a:Number.MAX_SAFE_INTEGER)}).map(e=>{let[t,n]=e,a=1===n?"relationship":"relationships";return"high-throughput"===t?"".concat(n," high-throughput ").concat(a):"".concat(n," ").concat(t," ").concat(a)}).join(", ")}(z,o):"",F=w&&null!==N?"Showing first ".concat(String(P.length)," of ").concat(String(N)," relationships."):"Showing ".concat(String(P.length)," relationship").concat(1!==P.length?"s":"",".");return(0,a.jsxs)("div",{className:"tw-pad","data-testid":"relationship-list-panel","data-relationship-focus":m?"true":void 0,children:[(0,a.jsxs)("div",{role:"group","aria-label":"Relationship density",style:{display:"flex",gap:4,marginBottom:8},children:[["minimal","standard","dense"].map(e=>(0,a.jsx)("button",{type:"button",className:"arun-btn","aria-pressed":h===e,onClick:()=>M(e),style:{textTransform:"capitalize",minWidth:24,minHeight:24},children:e},e)),(0,a.jsx)("button",{type:"button",className:"arun-btn","aria-pressed":m,onClick:()=>f(e=>!e),title:"Toggle focus mode (F)","aria-label":"Focus mode: ".concat(m?"on":"off"),style:{minWidth:24,minHeight:24},children:"Focus"})]}),(0,a.jsxs)("div",{style:{marginBottom:8},children:[(0,a.jsx)("label",{htmlFor:"rel-type-filter",className:"rb-row-k",style:{display:"block",marginBottom:2},children:"Filter by type (press / to focus)"}),(0,a.jsx)("input",{id:"rel-type-filter",ref:C,type:"text",value:R,onChange:q,placeholder:"e.g. reads-context","aria-label":"Filter relationships by type",style:{width:"100%",background:"var(--inset)",border:"1px solid var(--border)",borderRadius:4,padding:"4px 8px",color:"var(--fg)",fontSize:12}})]}),(0,a.jsx)("div",{"aria-live":"polite","aria-atomic":"true",className:"visually-hidden",children:F}),w&&(0,a.jsx)("div",{className:"footer","aria-live":"polite",style:{fontSize:11,color:"var(--fg-muted)",marginBottom:6},children:F}),null!==b&&(0,a.jsxs)("div",{className:"lk-alert",role:"alert","aria-live":"assertive",children:[(0,a.jsx)("span",{children:b}),(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>void T(),children:"Retry"})]}),x&&(0,a.jsx)("div",{style:{color:"var(--fg-muted)",fontSize:12,padding:"8px 0"},"aria-label":"Loading relationships",children:"Loading…"}),!x&&null===b&&0===P.length&&(0,a.jsx)("div",{className:"insp-empty","data-testid":"list-empty",children:"No relationships found for the current filter."}),!x&&P.length>0&&(0,a.jsxs)("div",{role:"list","aria-label":"Relationships",style:{display:"flex",flexDirection:"column",gap:2},children:[A.map(e=>{let t=e.id===s,n=it(e.id,e.lifecycle,o),l=m&&t,r=m&&!t;return(0,a.jsx)("div",{role:"listitem",style:{opacity:r?.4:1},children:(0,a.jsxs)("button",{type:"button","aria-pressed":t,"aria-label":"".concat(e.type," relationship from ").concat(e.source.kind," to ").concat(e.target.kind,", lifecycle: ").concat(e.lifecycle),onClick:()=>i(e.id),onKeyDown:t=>{var n;return n=e.id,void(("Enter"===t.key||" "===t.key)&&(t.preventDefault(),i(n)))},"data-incident":l?"true":void 0,style:{display:"flex",alignItems:"center",gap:6,width:"100%",minHeight:32,padding:"4px 6px",background:t?"var(--accent-dim)":"transparent",border:"1px solid transparent",borderColor:t?"var(--accent-line)":"transparent",borderRadius:4,cursor:"pointer",textAlign:"left"},className:"focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent",children:[(0,a.jsx)(s5,{type:e.type,lifecycle:e.lifecycle,activity:n,throughputCount:c.get(e.id),animateOverride:d,highContrast:u}),(0,a.jsxs)("span",{style:{fontSize:12,color:"var(--fg)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[e.source.kind," → ",e.target.kind]}),(0,a.jsx)("span",{style:{fontSize:11,color:"var(--fg-faint)",whiteSpace:"nowrap"},children:e.lifecycle})]})},e.id)}),D>0&&(0,a.jsxs)("div",{role:"listitem","aria-live":"polite",style:{fontSize:12,color:"var(--fg-muted)",padding:"4px 6px"},"data-testid":"animation-cap-aggregate",children:["+",String(D)," more: ",L]})]})]})}function il(){return(0,a.jsx)("p",{role:"note",style:{margin:"4px 0 0",fontSize:11,color:"var(--fg-muted)",borderLeft:"2px solid var(--warn)",paddingLeft:8},children:"The walk hit a bound before the graph was fully traversed; more objects may be affected than shown."})}function is(e){let{title:t,help:n,report:l,onSelectRelationship:s}=e;if(null===l)return(0,a.jsxs)("section",{style:{marginBottom:12},children:[(0,a.jsx)("div",{className:"rb-section-label",role:"heading","aria-level":4,children:t}),(0,a.jsx)("p",{style:{fontSize:12,color:"var(--fg-muted)",margin:0},children:"Loading…"})]});let i=l.endpoints.slice(1),r=l.relationships,o=i.slice(0,50),c=r.slice(0,50);return(0,a.jsxs)("section",{style:{marginBottom:12},"aria-label":t,children:[(0,a.jsxs)("div",{className:"rb-section-label",role:"heading","aria-level":4,children:[t,(0,a.jsx)("span",{className:"rb-count","aria-hidden":"true",children:i.length})]}),(0,a.jsx)("p",{style:{margin:"0 0 6px",fontSize:11,color:"var(--fg-muted)"},children:n}),0===i.length?(0,a.jsx)("p",{style:{fontSize:12,color:"var(--fg-muted)",margin:0},children:"No further objects are affected in this direction."}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("ul",{style:{listStyle:"none",margin:0,padding:0},children:o.map(e=>(0,a.jsx)("li",{className:"rb-row",style:{fontSize:12},children:(0,a.jsx)("span",{className:"mono",children:"".concat(e.kind,": ").concat(e.id)})},"".concat(e.kind,":").concat(e.id)))}),i.length>o.length&&(0,a.jsxs)("p",{role:"note",style:{margin:"4px 0 0",fontSize:11,color:"var(--fg-muted)"},children:["Showing the first ",String(50)," of ",String(i.length)," ","objects."]}),r.length>0&&(0,a.jsxs)("details",{style:{marginTop:6},children:[(0,a.jsxs)("summary",{style:{fontSize:11,color:"var(--fg-muted)",cursor:"pointer"},children:[String(r.length)," relationship",1===r.length?"":"s"," on the path"]}),(0,a.jsx)("ul",{style:{listStyle:"none",margin:"4px 0 0",padding:0},children:c.map(e=>(0,a.jsx)("li",{style:{marginBottom:2},children:(0,a.jsxs)("button",{type:"button",className:"arun-btn ghost",onClick:()=>s(e.id),"aria-label":"Inspect ".concat(e.type," relationship from ").concat(e.source.kind," ").concat(e.source.id," to ").concat(e.target.kind," ").concat(e.target.id),style:{display:"flex",width:"100%",gap:6,alignItems:"center",textAlign:"left",fontSize:12},children:[(0,a.jsx)("span",{className:"mono",children:e.type}),(0,a.jsxs)("span",{style:{color:"var(--fg-muted)"},children:[e.source.id," → ",e.target.id]})]})},e.id))})]})]}),l.truncated&&(0,a.jsx)(il,{})]})}function ii(e){let{outgoing:t,incoming:n,onSelectRelationship:l}=e;return(0,a.jsxs)("div",{style:{marginTop:8,padding:"8px 10px",border:"1px solid var(--border)",borderRadius:8,background:"var(--inset)"},"aria-label":"Bounded impact analysis",children:[(0,a.jsx)(is,{title:"Downstream impact",help:"Objects this relationship's target leads to. Deleting or revoking here may affect them.",report:t,onSelectRelationship:l}),(0,a.jsx)(is,{title:"Upstream impact",help:"Objects that depend on this relationship's source.",report:n,onSelectRelationship:l})]})}let ir={draft:{bg:"var(--inset)",fg:"var(--fg-muted)"},active:{bg:"var(--accent-dim)",fg:"var(--accent)"},archived:{bg:"var(--inset)",fg:"var(--fg-dim)"},superseded:{bg:"var(--inset)",fg:"var(--fg-dim)"},revoked:{bg:"color-mix(in oklch, var(--danger) 14%, var(--card))",fg:"var(--danger)"},blocked:{bg:"color-mix(in oklch, var(--warn) 12%, var(--card))",fg:"var(--warn)"},stale:{bg:"var(--inset)",fg:"var(--fg-faint)"}},io={draft:"Proposed but not yet validated or awaiting an upstream gate.",active:"Validated and committed. Both endpoints are currently live.",archived:"Preserved for audit but no longer participates in queries by default.",superseded:"Replaced by a newer relationship of the same type.",revoked:"Rejected after proposal or retracted after acceptance. Terminal state.",blocked:"Cannot transition to active because the validator returned a denial reason.",stale:"At least one endpoint is tombstoned, retired, or unavailable."};function ic(e){let{lines:t=3}=e;return(0,a.jsx)("div",{className:"rb-rows","aria-hidden":"true",children:Array.from({length:t},(e,t)=>(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",style:{background:"var(--inset)",borderRadius:3,width:"40%",display:"block",height:12}}),(0,a.jsx)("span",{className:"rb-row-v",style:{background:"var(--inset)",borderRadius:3,width:"55%",display:"block",height:12}})]},t))})}function id(e){let{children:t,style:n}=e;return(0,a.jsx)("div",{className:"rb-section-label",role:"heading","aria-level":3,style:n,children:t})}function iu(e){let{rel:t}=e,n=n0[t.type],l="".concat(t.source.kind," ").concat(t.type," ").concat(t.target.kind);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"insp-top",children:[(0,a.jsx)("span",{className:"chip",style:{fontSize:11},children:t.type}),(0,a.jsx)("span",{className:"insp-title",children:l})]}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Semantics"}),(0,a.jsx)("span",{className:"rb-row-v",children:n.semantics})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Cardinality"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:n.cardinality})]})]})]})}function ih(e){let{label:t,kind:n,id:l}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(id,{children:[t," endpoint"]}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Kind"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:n})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Reference"}),(0,a.jsx)("span",{className:"rb-row-v mono","aria-label":"Reference id: ".concat(l),children:l})]})]})]})}function ip(e){var t;let{lifecycle:n}=e,l="lifecycle-desc-".concat(n),s=null!=(t=ir[n])?t:ir.draft;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(id,{children:"Lifecycle status"}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"State"}),(0,a.jsx)("span",{className:"rb-row-v",children:(0,a.jsx)("span",{className:"chip",style:{background:s.bg,color:s.fg},"aria-describedby":l,children:n})})]}),(0,a.jsx)("div",{className:"rb-row",children:(0,a.jsx)("span",{id:l,className:"rb-row-v",style:{color:"var(--fg-muted)",fontSize:12},children:io[n]})})]})]})}function im(e){let{type:t,lifecycle:n,activity:l,throughputCount:s,animateBadges:i,highContrast:r,transitions:o,densityMode:c}=e,d=o.slice(0,"minimal"===c?3:5);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(id,{children:"Activity"}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Current state"}),(0,a.jsx)("span",{className:"rb-row-v",children:(0,a.jsx)(s5,{type:t,lifecycle:n,activity:l,throughputCount:s,animateOverride:i,highContrast:r})})]}),d.length>0&&(0,a.jsxs)("div",{className:"rb-row",style:{flexDirection:"column",gap:4,alignItems:"flex-start"},children:[(0,a.jsx)("span",{className:"rb-row-k",style:{marginBottom:4},children:"Recent transitions"}),d.map((e,t)=>(0,a.jsxs)("div",{style:{fontSize:12,color:"var(--fg-muted)",display:"flex",gap:8},children:[(0,a.jsxs)("span",{className:"mono",children:[e.from," → ",e.to]}),(0,a.jsx)("time",{dateTime:new Date(e.occurredAt).toISOString(),style:{color:"var(--fg-faint)"},children:new Date(e.occurredAt).toLocaleString()})]},t))]})]})]})}function ig(){return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(id,{children:"Authority status"}),(0,a.jsx)("div",{className:"rb-rows",children:(0,a.jsx)("div",{className:"rb-row","data-testid":"authority-disclaimer",children:(0,a.jsx)("span",{className:"rb-row-v",style:{color:"var(--fg-muted)",fontStyle:"italic"},children:"Relationship: governance only. No model/tool/file/workflow authority granted."})})})]})}function iv(e){let{auditRows:t,loading:n,error:l,onRetry:s,onLoadMore:i,hasMore:r}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(id,{children:"Audit history"}),n&&(0,a.jsx)(ic,{lines:3}),null!==l&&(0,a.jsxs)("div",{className:"lk-alert",role:"alert","aria-live":"assertive",children:[(0,a.jsx)("span",{children:l}),(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:s,children:"Retry"})]}),!n&&null===l&&0===t.length&&(0,a.jsx)("div",{className:"rb-rows",children:(0,a.jsx)("div",{className:"rb-row",children:(0,a.jsx)("span",{className:"rb-row-v",style:{color:"var(--fg-muted)"},children:"No audit events for this relationship yet."})})}),!n&&t.length>0&&(0,a.jsxs)("div",{className:"rb-rows",children:[t.map((e,t)=>(0,a.jsxs)("div",{className:"rb-row",style:{flexDirection:"column",alignItems:"flex-start",gap:2},children:[(0,a.jsxs)("span",{className:"rb-row-k mono",style:{fontSize:11},children:[e.from," → ",e.to]}),(0,a.jsx)("time",{dateTime:new Date(e.occurredAt).toISOString(),style:{color:"var(--fg-faint)",fontSize:11},children:new Date(e.occurredAt).toLocaleString()})]},t)),r&&(0,a.jsx)("div",{className:"rb-row",children:(0,a.jsx)("button",{type:"button",className:"rb-row-v",style:{color:"var(--accent)",fontSize:12,background:"none",border:"none",padding:0,cursor:"pointer",minHeight:24,minWidth:24},onClick:i,"aria-label":"Load more audit events",children:"Load more"})})]})]})}function ix(e){let{rel:t}=e,n=function(e){let t=[];return"evidence-run"===e.source.kind&&t.push(e.source.id),"evidence-run"===e.target.kind&&t.push(e.target.id),t}(t);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(id,{children:"Evidence references"}),0===n.length?(0,a.jsx)("p",{style:{fontSize:12,color:"var(--fg-muted)",margin:"0 0 4px"},"data-testid":"evidence-empty",children:"No evidence references for this relationship."}):(0,a.jsx)("div",{className:"rb-rows",children:n.map(e=>(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Evidence run"}),(0,a.jsx)("span",{className:"rb-row-v mono","aria-label":"Evidence run reference ".concat(e),title:e,children:e})]},e))})]})}function iy(e){let{relationshipId:t,forwardCount:n,reverseCount:l,outgoing:s,incoming:i,expanded:r,onToggle:o,onSelectRelationship:c}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(id,{children:"Impact summary"}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Forward dependencies"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:null===n?"—":String(n)})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Reverse dependencies"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:null===l?"—":String(l)})]}),(0,a.jsx)("div",{className:"rb-row",children:(0,a.jsx)("button",{type:"button",className:"arun-btn",onClick:o,"aria-expanded":r,"aria-controls":"rb-impact-detail","aria-label":r?"Hide impact for relationship ".concat(t):"View impact for relationship ".concat(t),"data-testid":"view-impact-btn",children:r?"Hide impact":"View impact"})})]}),r&&(0,a.jsx)("div",{id:"rb-impact-detail",children:(0,a.jsx)(ii,{outgoing:s,incoming:i,onSelectRelationship:c})})]})}function ib(e){let{codes:t,messages:n,deniedAt:l}=e;return 0===t.length?null:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(id,{children:"Denial reason"}),(0,a.jsxs)("div",{className:"lk-alert",role:"status","aria-live":"polite","data-testid":"denial-section",children:[t.map((e,l)=>{var s;return(0,a.jsxs)("div",{style:{marginBottom:8*(l<t.length-1)},children:[(0,a.jsx)("div",{style:{fontFamily:"var(--mono)",fontSize:11,color:"var(--fg-muted)",marginBottom:2},children:e}),(0,a.jsx)("div",{style:{fontSize:13,color:"var(--fg)"},children:null!=(s=n[l])?s:e})]},e)}),void 0!==l&&(0,a.jsxs)("div",{style:{fontSize:11,color:"var(--fg-faint)",marginTop:6},children:["Denied at ",(0,a.jsx)("time",{dateTime:l,children:l})]})]})]})}function ij(e){return null==e||0===e.length?null:{codes:e.map(e=>e.code),messages:e.map(e=>e.message)}}function iw(e){let{rel:t,onReconnect:n,onArchive:l,onRevoke:s,onViewImpact:i,onViewEvidence:r,mutating:o}=e,c=t.lifecycle,d="blocked"===c,u="active"===c,h="active"===c||"blocked"===c||"archived"===c,p="active"===c;return(0,a.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginTop:8},children:[(0,a.jsx)("button",{type:"button",className:"arun-btn".concat(d?" primary":""),"aria-disabled":!d||o,"aria-label":"Reconnect — only available for blocked relationships",title:d?"Reconnect (R)":"Only blocked relationships can be reconnected.",disabled:!d||o,onClick:d?n:void 0,children:"Reconnect"}),(0,a.jsx)("button",{type:"button",className:"arun-btn","aria-disabled":!u||o,"aria-label":"Archive — only available for active relationships",title:u?"Archive (A)":"Only active relationships can be archived.",disabled:!u||o,onClick:u?l:void 0,children:"Archive"}),(0,a.jsx)("button",{type:"button",className:"arun-btn","aria-disabled":!h||o,"aria-label":"Revoke relationship",title:h?"Revoke (Shift+Delete)":"Already revoked or superseded.",disabled:!h||o,onClick:h?s:void 0,style:{color:h?"var(--danger)":void 0},children:"Revoke"}),(0,a.jsx)("button",{type:"button",className:"arun-btn","aria-disabled":!p,"aria-label":"View impact analysis",title:p?"View Impact (I)":"Impact analysis is unavailable in this state.",disabled:!p,onClick:p?i:void 0,children:"View Impact"}),(0,a.jsx)("button",{type:"button",className:"arun-btn","aria-label":"View evidence references",title:"View Evidence (E)",onClick:r,children:"View Evidence"})]})}function ik(e){var t,n,s;let{relationshipId:i,densityMode:r="minimal",onClearFocus:o,onViewImpact:c,activityMap:d=new Map,throughputMap:u=new Map,animateBadges:h=!0,highContrast:p=!1}=e,[m,f]=(0,l.useState)(null),[g,v]=(0,l.useState)(null),[x,y]=(0,l.useState)(!1),[b,j]=(0,l.useState)(null),[w,k]=(0,l.useState)(!1),[N,S]=(0,l.useState)(null),[C,R]=(0,l.useState)(null),[I,E]=(0,l.useState)(null),[M,T]=(0,l.useState)(null),[q,P]=(0,l.useState)(!1),A=null===I?null:I.relationships.length,z=null===M?null:M.relationships.length,[D,L]=(0,l.useState)(!1),F=(0,l.useRef)(null),O=(0,l.useRef)(0),K=(0,l.useCallback)(async e=>{let t=++O.current;j(null),y(!0),R(null),E(null),T(null),P(!1);let n=setTimeout(()=>{O.current===t&&L(!0)},500);F.current=n;try{let[n,a]=await Promise.all([n7(e),an(e)]);if(O.current!==t)return;f(n),v(a);try{let[n,a]=await Promise.all([at(e,{direction:"outgoing",maxDepth:3,maxRelationships:512}),at(e,{direction:"incoming",maxDepth:3,maxRelationships:512})]);if(O.current!==t)return;E(n),T(a)}catch(e){}}catch(e){if(O.current!==t)return;j(e instanceof n2?e.message:"Unable to reach the local backend. Check that `keiko serve` is running.")}finally{F.current===n?(clearTimeout(n),F.current=null):clearTimeout(n),O.current===t&&(y(!1),L(!1))}},[]);(0,l.useEffect)(()=>{if(null===i){O.current+=1,null!==F.current&&(clearTimeout(F.current),F.current=null),f(null),v(null),j(null),R(null),L(!1),y(!1);return}return K(i),()=>{null!==F.current&&(clearTimeout(F.current),F.current=null)}},[i,K]);let B=(0,l.useCallback)(async e=>{if(null!==m){k(!0),S(null),R(null);try{let t=crypto.randomUUID(),{relationship:n}=await n9(m.id,{transition:{to:e}},String(m.etag),t);f(n),v(null),await K(m.id)}catch(e){S(e instanceof n2?e.message:"Mutation failed. Please retry."),R(e instanceof n2?ij(e.reasons):null)}finally{k(!1)}}},[m,K]),W=(0,l.useCallback)(()=>void B("draft"),[B]),U=(0,l.useCallback)(()=>void B("archived"),[B]),_=(0,l.useCallback)(async()=>{if(null!==m&&window.confirm('Revoke relationship "'.concat(m.type,'"? This cannot be undone.'))){k(!0),S(null),R(null);try{let e=crypto.randomUUID(),t=await ae(m.id,String(m.etag),e);f(t)}catch(e){S(e instanceof n2?e.message:"Revoke failed. Please retry."),R(e instanceof n2?ij(e.reasons):null)}finally{k(!1)}}},[m]),H=(0,l.useCallback)(()=>{P(e=>!e)},[]),J=(0,l.useCallback)(e=>{null==c||c(e)},[c]),V=(0,l.useCallback)(()=>{null!==m&&(window.location.href="/evidence?relId=".concat(encodeURIComponent(m.id)))},[m]);if(null===i)return null;let G=ij(null==g?void 0:g.decision.reasons),X=null!=G?G:C,Y=null!==X&&((null==m?void 0:m.lifecycle)==="blocked"||(null==m?void 0:m.lifecycle)==="revoked"||null!==C),Z=null!==m?null!=(t=d.get(m.id))?t:function(e){switch(e){case"blocked":return"blocked";case"stale":return"degraded";default:return"inactive"}}(m.lifecycle):"inactive",Q=null!==m?u.get(m.id):void 0;return(0,a.jsxs)("div",{className:"tw-pad","aria-busy":x,"data-testid":"relationship-inspector-panel",children:[null!==b&&(0,a.jsxs)("div",{className:"lk-alert",role:"alert","aria-live":"assertive",children:[(0,a.jsx)("span",{children:b}),(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>void K(i),children:"Retry"})]}),null!==N&&(0,a.jsxs)("div",{className:"lk-alert",role:"alert","aria-live":"assertive",children:[(0,a.jsx)("span",{children:N}),(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>S(null),children:"Dismiss"})]}),x&&D&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(id,{style:{marginTop:0},children:"Relationship"}),(0,a.jsx)(ic,{lines:4}),(0,a.jsx)(ic,{lines:3})]}),!x&&null===b&&null===m&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(id,{style:{marginTop:0},children:"Relationship"}),(0,a.jsx)("div",{className:"insp-empty","data-testid":"inspector-not-found",children:"This relationship is no longer available."}),(0,a.jsx)("div",{style:{fontSize:12,color:"var(--fg-muted)",marginTop:4},children:"It may have been deleted, retired by retention, or it never existed in this workspace."}),void 0!==o&&(0,a.jsx)("button",{type:"button",className:"arun-btn",style:{marginTop:8},onClick:o,children:"Clear focus"})]}),!x&&null!==m&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(id,{style:{marginTop:0},children:"Relationship"}),(0,a.jsx)(iu,{rel:m}),(0,a.jsx)(ih,{label:"Source",kind:m.source.kind,id:m.source.id}),(0,a.jsx)(ih,{label:"Target",kind:m.target.kind,id:m.target.id}),(0,a.jsx)(ip,{lifecycle:m.lifecycle}),(0,a.jsx)(im,{type:m.type,lifecycle:m.lifecycle,activity:Z,throughputCount:Q,animateBadges:h,highContrast:p,transitions:null!=(n=null==g?void 0:g.lifecycle)?n:[],densityMode:r}),(0,a.jsx)(ig,{}),(0,a.jsx)(iv,{auditRows:null!=(s=null==g?void 0:g.lifecycle)?s:[],loading:!1,error:null,onRetry:()=>void K(i),onLoadMore:()=>{},hasMore:!1}),(0,a.jsx)(ix,{rel:m}),(0,a.jsx)(iy,{relationshipId:m.id,forwardCount:A,reverseCount:z,outgoing:I,incoming:M,expanded:q,onToggle:H,onSelectRelationship:J}),Y&&null!==X&&(0,a.jsx)(ib,{codes:X.codes,messages:X.messages}),(0,a.jsx)(iw,{rel:m,onReconnect:W,onArchive:U,onRevoke:()=>void _(),onViewImpact:H,onViewEvidence:V,mutating:w})]})]})}let iN=new Set(["kind","id","state","timestamp","count"]);function iS(e){return"".concat(e.kind,": ").concat(e.id)}function iC(e){let{category:t}=e;return(0,a.jsxs)("p",{role:"note",style:{margin:"4px 0 0",fontSize:11,color:"var(--fg-muted)",borderLeft:"2px solid var(--warn)",paddingLeft:8},children:["More ",t," exist than the bounded query returned. Resolve the listed items, then re-run the health check."]})}function iR(e){let{category:t,onSelectRelationship:n}=e;if(0===t.items.length)return null;let l=t.items.slice(0,50),s=t.items.length-l.length;return(0,a.jsxs)("section",{"aria-label":"".concat(t.label," (").concat(String(t.items.length),")"),style:{marginBottom:14},children:[(0,a.jsxs)("div",{className:"rb-section-label",role:"heading","aria-level":3,children:[t.label,(0,a.jsx)("span",{className:"rb-count","aria-hidden":"true",children:t.items.length})]}),(0,a.jsx)("p",{style:{margin:"0 0 6px",fontSize:11,color:"var(--fg-muted)"},children:t.help}),(0,a.jsx)("ul",{style:{listStyle:"none",margin:0,padding:0},children:l.map(e=>(0,a.jsx)("li",{style:{marginBottom:2},children:(0,a.jsxs)("button",{type:"button",className:"arun-btn ghost",onClick:()=>n(e.id),"aria-label":"Inspect ".concat(e.type," relationship from ").concat(iS(e.source)," to ").concat(iS(e.target),", lifecycle ").concat(e.lifecycle),style:{display:"flex",width:"100%",gap:6,alignItems:"center",textAlign:"left",fontSize:12},children:[(0,a.jsx)("span",{className:"mono",style:{color:"var(--fg)"},children:e.type}),(0,a.jsxs)("span",{style:{color:"var(--fg-muted)"},children:[iS(e.source)," → ",iS(e.target)]}),(0,a.jsx)("span",{className:"mono",style:{marginLeft:"auto",color:"var(--fg-muted)"},children:e.lifecycle})]})},e.id))}),s>0&&(0,a.jsxs)("p",{role:"note",style:{margin:"4px 0 0",fontSize:11,color:"var(--fg-muted)"},children:["Showing the first ",String(50)," of ",String(t.items.length),"."]}),t.truncated&&(0,a.jsx)(iC,{category:t.label.toLowerCase()})]})}function iI(e){let{findings:t}=e;if(0===t.orphanedEndpoints.length)return null;let n=t.orphanedEndpoints.slice(0,50);return(0,a.jsxs)("section",{"aria-label":"Orphaned endpoints (".concat(String(t.orphanedEndpoints.length),")"),style:{marginBottom:14},children:[(0,a.jsxs)("div",{className:"rb-section-label",role:"heading","aria-level":3,children:["Orphaned endpoints",(0,a.jsx)("span",{className:"rb-count","aria-hidden":"true",children:t.orphanedEndpoints.length})]}),(0,a.jsx)("p",{style:{margin:"0 0 6px",fontSize:11,color:"var(--fg-muted)"},children:"Endpoints that participate in no live relationship."}),(0,a.jsx)("ul",{style:{listStyle:"none",margin:0,padding:0},children:n.map(e=>(0,a.jsx)("li",{className:"rb-row",style:{fontSize:12},children:(0,a.jsx)("span",{className:"mono",children:iS(e)})},"".concat(e.kind,":").concat(e.id)))}),t.orphanedEndpointsTruncated&&(0,a.jsx)(iC,{category:"orphaned endpoints"})]})}function iE(e){var t,n;let{onSelectRelationship:s}=e,[i,r]=(0,l.useState)(null),[o,c]=(0,l.useState)(!0),[d,u]=(0,l.useState)(null),h=(0,l.useCallback)(async()=>{c(!0),u(null);try{let e=await aa();r(e)}catch(e){u(e instanceof n2?e.message:"Could not load the graph health check.")}finally{c(!1)}},[]);return(0,l.useEffect)(()=>{h()},[h]),(0,a.jsxs)("div",{style:{padding:12,height:"100%",overflowY:"auto"},"aria-busy":o,children:[(0,a.jsxs)("header",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:10},children:[(0,a.jsx)("h2",{style:{margin:0,fontSize:13,fontWeight:600,color:"var(--fg)",flexGrow:1},children:"Graph health"}),(0,a.jsx)("button",{type:"button",className:"arun-btn",onClick:()=>void h(),"aria-label":"Re-run the graph health check",style:{minHeight:24},children:"Refresh"})]}),o&&(0,a.jsx)("p",{style:{fontSize:12,color:"var(--fg-muted)"},"aria-live":"polite",children:"Running health check…"}),null!==d&&(0,a.jsxs)("div",{className:"lk-alert",role:"alert",children:[d,(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>void h(),children:"Retry"})]}),!o&&null===d&&null!==i&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("p",{style:{fontSize:11,color:"var(--fg-faint)",margin:"0 0 10px"},children:["Checked at"," ",(0,a.jsx)("time",{dateTime:new Date(i.checkedAt).toISOString(),children:new Date(i.checkedAt).toLocaleString()}),"."]}),(0,a.jsx)("div",{className:"rb-rows",style:{marginBottom:14},children:n$.filter(e=>{var t;return(null!=(t=i.totals[e])?t:0)>0}).map(e=>{var t;return(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:e}),(0,a.jsx)("span",{className:"rb-row-v mono",children:String(null!=(t=i.totals[e])?t:0)})]},e)})}),0===(t=i.findings).orphanedEndpoints.length+t.staleRelationships.length+t.blockedRelationships.length+t.failedRelationships.length+t.invalidReferences.length+t.cycleParticipants.length?(0,a.jsxs)("div",{className:"lk-empty",children:[(0,a.jsx)("p",{className:"lk-empty-title",children:"Healthy"}),(0,a.jsx)("p",{className:"lk-empty-body",children:"No relationship-graph defects were found."})]}):(0,a.jsxs)(a.Fragment,{children:[[{key:"invalid",label:"Invalid references",help:"An endpoint no longer resolves to a live workspace object.",items:(n=i.findings).invalidReferences,truncated:n.invalidReferencesTruncated},{key:"blocked",label:"Blocked",help:"A policy or endpoint state is blocking this relationship.",items:n.blockedRelationships,truncated:n.blockedRelationshipsTruncated},{key:"failed",label:"Failed (revoked)",help:"The relationship reached the revoked terminal state.",items:n.failedRelationships,truncated:n.failedRelationshipsTruncated},{key:"cycle",label:"Cycle participants",help:"These relationships take part in a dependency cycle.",items:n.cycleParticipants,truncated:n.cycleScanTruncated},{key:"stale",label:"Stale",help:"A health check flagged at least one endpoint as not currently live.",items:n.staleRelationships,truncated:n.staleRelationshipsTruncated}].map(e=>(0,a.jsx)(iR,{category:e,onSelectRelationship:s},e.key)),(0,a.jsx)(iI,{findings:i.findings})]})]})]})}let iM={draft:["draft","active","archived","superseded","revoked","blocked","stale"],active:["active","archived","superseded","revoked","stale"],archived:["archived","superseded","revoked","stale"],superseded:["superseded","stale"],revoked:["revoked"],blocked:["blocked","draft","active","archived","revoked","stale"],stale:["stale","active","archived","superseded","revoked"]};function iT(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function iq(e){return"string"==typeof e&&e.length>0}function iP(e,t,n){return void 0===n?{code:e,message:t}:{code:e,field:n,message:t}}function iA(e,t,n){return iT(e)?iq(e.kind)?iq(e.id)?!!iq(e.workspaceId)||(n.push(iP("denied/schema-version-unsupported","".concat(t,".workspaceId must be a non-empty string"),"".concat(t,".workspaceId"))),!1):(n.push(iP("denied/schema-version-unsupported","".concat(t,".id must be a non-empty string"),"".concat(t,".id"))),!1):(n.push(iP("denied/schema-version-unsupported","".concat(t,".kind must be a non-empty string"),"".concat(t,".kind"))),!1):(n.push(iP("denied/schema-version-unsupported","".concat(t," must be an object"),t)),!1)}function iz(e,t,n){iq(e[t])||n.push(iP("denied/schema-version-unsupported","".concat(t," must be a non-empty string"),t))}function iD(e,t){let n=e.kind;return nY.includes(n)?null:iP("denied/schema-version-unsupported","".concat(t,".kind is not a known object kind"),"".concat(t,".kind"))}function iL(e,t,n){return"missing"===t?void n.push(iP("source"===e?"denied/non-existent-source":"denied/non-existent-target","".concat(e," endpoint does not exist"),e)):"tombstoned"===t?void n.push(iP("denied/endpoint-tombstoned","".concat(e," endpoint has been tombstoned"),e)):"retired"===t?void n.push(iP("denied/endpoint-retired","".concat(e," endpoint has been retired"),e)):void("unavailable"===t&&n.push(iP("denied/endpoint-unavailable","".concat(e," endpoint is unavailable"),e)))}function iF(e,t){let n=e.kind;return nZ.includes(n)?null:iP("denied/object-kind-not-yet-supported","".concat(t,'.kind "').concat(n,'" is reserved for a future release'),"".concat(t,".kind"))}function iO(){return{type:"reads-context",sourceKind:"workflow-run",sourceId:"",targetKind:"memory",targetId:"",summary:""}}let iK=new Set(["denied/path-not-contained","denied/cross-workspace","denied/payload-content-not-permitted"]);function iB(e){return(null==e?void 0:e.codes.some(e=>iK.has(e)))===!0}function iW(e){let{onClose:t}=e,[n,s]=(0,l.useState)(iO),[i,r]=(0,l.useState)([]),[o,c]=(0,l.useState)(null),[d,u]=(0,l.useState)(!1),[h,p]=(0,l.useState)(!1),m=(0,l.useRef)(null),f=(0,l.useRef)(null),g="rel-create-dialog-title",v="rel-create-dialog-desc";(0,l.useEffect)(()=>{var e;null==(e=f.current)||e.focus()},[]);let x=(0,l.useCallback)(e=>{let t=m.current;if(null===t)return;let n=Array.from(t.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter(e=>!e.hasAttribute("disabled")),a=n[0],l=n[n.length-1];"Tab"===e.key&&(e.shiftKey?document.activeElement===a&&(e.preventDefault(),null==l||l.focus()):document.activeElement===l&&(e.preventDefault(),null==a||a.focus()))},[]),y=(0,l.useCallback)(e=>{"Escape"===e.key&&t(null)},[t]);(0,l.useEffect)(()=>(window.addEventListener("keydown",x),window.addEventListener("keydown",y),()=>{window.removeEventListener("keydown",x),window.removeEventListener("keydown",y)}),[x,y]),(0,l.useEffect)(()=>{if(0===n.sourceId.length||0===n.targetId.length)return void r([]);let e=function(e,t){let n=function(e){var t;if(!iT(e))return{errors:[iP("denied/schema-version-unsupported","relationship must be an object")]};let n=[];iz(e,"id",n),iz(e,"workspaceId",n),iz(e,"createdAt",n),iz(e,"updatedAt",n),(!("number"==typeof(t=e.etag)&&Number.isInteger(t)&&Number.isFinite(t))||e.etag<0)&&n.push(iP("denied/schema-version-unsupported","etag must be a non-negative finite integer","etag"));let a=iA(e.source,"source",n),l=iA(e.target,"target",n);return!(n.length>0)&&a&&l?{errors:[],value:{record:e,source:e.source,target:e.target}}:{errors:n}}(e);if(!n.value)return{ok:!1,errors:n.errors};let{record:a,source:l,target:s}=n.value,i=function(e,t,n){let a="1"!==e.schemaVersion?iP("denied/schema-version-unsupported",'schemaVersion must be the literal "'.concat("1",'"'),"schemaVersion"):null;if(a)return[a];let l=function(e){let t=e.type;return iq(t)?nQ.includes(t)?null:iP("denied/schema-version-unsupported","type is not a known relationship type","type"):iP("denied/schema-version-unsupported","type must be a non-empty string","type")}(e);if(l)return[l];let s=iD(t,"source"),i=iD(n,"target");if(null!==s||null!==i){let e=[];return null!==s&&e.push(s),null!==i&&e.push(i),e}let r=function(e){let t=e.lifecycleState;return iq(t)?n$.includes(t)?null:iP("denied/schema-version-unsupported","lifecycleState is not a known lifecycle state","lifecycleState"):iP("denied/schema-version-unsupported","lifecycleState must be a non-empty string","lifecycleState")}(e);return r?[r]:null}(a,l,s);if(i)return{ok:!1,errors:i};let r=function(e){if(!(null==e?void 0:e.endpointResolver))return null;let t=[];return"missing"===e.endpointResolver.source&&iL("source",e.endpointResolver.source,t),"missing"===e.endpointResolver.target&&iL("target",e.endpointResolver.target,t),t}(void 0);if(null!==r&&r.length>0)return{ok:!1,errors:r};let o=function(e,t,n,a){var l,s,i;let r=[],o=e.type,c=e.lifecycleState,d=iF(t,"source");d&&r.push(d);let u=iF(n,"target");u&&r.push(u),null===d&&null===u&&function(e,t,n,a){let l=function(e,t,n){let a=n0[e];return a.validSourceKinds.includes(t)?a.validTargetKinds.includes(n)?null:"denied/target-kind-not-allowed":"denied/source-kind-not-allowed"}(e,t.kind,n.kind);"denied/source-kind-not-allowed"===l?a.push(iP("denied/source-kind-not-allowed",'source.kind "'.concat(t.kind,'" is not permitted for type "').concat(e,'"'),"source.kind")):"denied/target-kind-not-allowed"===l&&a.push(iP("denied/target-kind-not-allowed",'target.kind "'.concat(n.kind,'" is not permitted for type "').concat(e,'"'),"target.kind"))}(o,t,n,r);let h=function(e,t){let n=null==t?void 0:t.cardinalityCounts;return n?"produces-evidence"===e&&"number"==typeof n.producesEvidenceForSource&&n.producesEvidenceForSource>=1?iP("denied/cardinality-exceeded","produces-evidence already exists for this source workflow-run"):"starts-workflow"===e&&"number"==typeof n.startsWorkflowForTarget&&n.startsWorkflowForTarget>=1?iP("denied/cardinality-exceeded","starts-workflow already exists for this target workflow-run"):null:null}(o,a);h&&r.push(h),function(e,t,n,a,l){let s=t.kind===n.kind&&t.id===n.id?iP("denied/cycle-forbidden","source and target refer to the same endpoint"):null;s&&l.push(s);let i="depends-on"===e&&(null==a?void 0:a.dependsOnReverseEdgeExists)===!0?iP("denied/cycle-forbidden","depends-on reverse edge already exists for this endpoint pair"):null;i&&l.push(i)}(o,t,n,a,r);let p=(l=e.workspaceId,t.workspaceId!==l||n.workspaceId!==l?iP("denied/cross-workspace","source and target must be in the relationship's workspace"):null);p&&r.push(p);let m=function(e,t){let n=null==t?void 0:t.previousLifecycleState;return void 0===n||iM[n].includes(e)?null:iP("denied/lifecycle-illegal-transition","transition from ".concat(n," to ").concat(e," is not permitted"),"lifecycleState")}(c,a);for(let t of(m&&r.push(m),s=a,i=r,(null==s?void 0:s.endpointResolver)&&("missing"!==s.endpointResolver.source&&iL("source",s.endpointResolver.source,i),"missing"!==s.endpointResolver.target&&iL("target",s.endpointResolver.target,i)),function(e){let t=[];if(void 0===e.metadata||null===e.metadata)return t;if(!iT(e.metadata))return t.push(iP("denied/payload-content-not-permitted","metadata must be an object when set","metadata")),t;for(let n of Object.keys(e.metadata)){let e=n.toLowerCase().replace(/[^a-z0-9]/g,"");for(let a of n1)if(e.includes(a)){t.push(iP("denied/payload-content-not-permitted","metadata may not carry endpoint content","metadata.".concat(n)));break}}return t}(e)))r.push(t);return r}(a,l,s,void 0);return o.length>0?{ok:!1,errors:o}:{ok:!0,value:a}}({id:"candidate",schemaVersion:"1",workspaceId:"preview",source:{kind:n.sourceKind,id:n.sourceId,workspaceId:"preview"},target:{kind:n.targetKind,id:n.targetId,workspaceId:"preview"},type:n.type,lifecycleState:"active",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),etag:0});e.ok?r([]):r(e.errors.map(e=>e.message))},[n]);let b=(0,l.useRef)(null),j=(0,l.useRef)(0);(0,l.useEffect)(()=>{j.current+=1;let e=j.current;return(null!==b.current&&clearTimeout(b.current),0===n.sourceId.length||0===n.targetId.length||i.length>0)?void p(!1):(b.current=setTimeout(async()=>{p(!0);try{if(await n4({type:n.type,source:{kind:n.sourceKind,id:n.sourceId},target:{kind:n.targetKind,id:n.targetId},summary:n.summary.length>0?n.summary:void 0}),e!==j.current)return;c(e=>(null==e?void 0:e.source)==="submit"||iB(e)?e:null)}catch(t){if(e!==j.current)return;t instanceof n2&&t.reasons.length>0?c({source:"preview",codes:t.reasons.map(e=>e.code),messages:t.reasons.map(e=>e.message)}):c(null)}finally{e===j.current&&p(!1)}},250),()=>{null!==b.current&&clearTimeout(b.current)})},[n,i]);let w=(0,l.useCallback)(async()=>{if(!d){u(!0),c(null);try{let e=crypto.randomUUID(),{relationship:a}=await n6({type:n.type,source:{kind:n.sourceKind,id:n.sourceId},target:{kind:n.targetKind,id:n.targetId},summary:n.summary.length>0?n.summary:void 0},e);t(a)}catch(e){e instanceof n2?e.reasons.length>0?c({source:"submit",codes:e.reasons.map(e=>e.code),messages:e.reasons.map(e=>e.message)}):c({source:"submit",codes:[e.code],messages:[e.message]}):c({source:"submit",codes:["relationship/network-error"],messages:["Unable to reach the local backend. Check that `keiko serve` is running."]})}finally{u(!1)}}},[n,t,d]),k=(0,l.useCallback)(e=>{"Enter"===e.key&&(e.ctrlKey||e.metaKey)&&w()},[w]),N=n0[n.type],S=n.sourceId.trim().length>0&&n.targetId.trim().length>0&&0===i.length&&null===o&&!d,C=iB(o);return(0,a.jsx)("div",{className:"cmdk-overlay",onPointerDown:()=>t(null),"data-testid":"rel-create-overlay",children:(0,a.jsxs)("div",{ref:m,role:"dialog","aria-modal":"true","aria-labelledby":g,"aria-describedby":v,className:"cmdk",style:{maxWidth:480,width:"100%"},onPointerDown:e=>e.stopPropagation(),onKeyDown:k,"data-testid":"rel-create-dialog",children:[(0,a.jsxs)("div",{className:"cmdk-input",style:{borderBottom:"1px solid var(--border)"},children:[(0,a.jsx)("span",{id:g,style:{fontWeight:600,fontSize:14,color:"var(--fg)"},children:"Create relationship"}),(0,a.jsx)("span",{id:v,className:"visually-hidden",children:"Create a new relationship between two workspace endpoints."}),(0,a.jsx)("button",{type:"button",className:"arun-btn",onClick:()=>t(null),"aria-label":"Close dialog",style:{marginLeft:"auto",minWidth:24,minHeight:24},children:"✕"})]}),(0,a.jsxs)("div",{style:{padding:"12px 16px",display:"flex",flexDirection:"column",gap:10},children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{htmlFor:"rel-type",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Type"}),(0,a.jsx)("select",{id:"rel-type",ref:f,value:n.type,onChange:e=>s(t=>({...t,type:e.target.value})),style:{width:"100%",background:"var(--inset)",border:"1px solid var(--border)",borderRadius:4,padding:"4px 8px",color:"var(--fg)",fontSize:13},"aria-label":"Relationship type",children:nQ.map(e=>(0,a.jsx)("option",{value:e,children:n0[e].displayName},e))}),(0,a.jsx)("div",{style:{fontSize:11,color:"var(--fg-muted)",marginTop:3},children:N.semantics})]}),(0,a.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,a.jsxs)("div",{style:{flex:"0 0 140px"},children:[(0,a.jsx)("label",{htmlFor:"rel-src-kind",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Source kind"}),(0,a.jsx)("select",{id:"rel-src-kind",value:n.sourceKind,onChange:e=>s(t=>({...t,sourceKind:e.target.value})),style:{width:"100%",background:"var(--inset)",border:"1px solid var(--border)",borderRadius:4,padding:"4px 8px",color:"var(--fg)",fontSize:12},"aria-label":"Source endpoint kind",children:nZ.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]}),(0,a.jsxs)("div",{style:{flex:1},children:[(0,a.jsx)("label",{htmlFor:"rel-src-id",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Source ID"}),(0,a.jsx)("input",{id:"rel-src-id",type:"text",value:n.sourceId,onChange:e=>s(t=>({...t,sourceId:e.target.value})),placeholder:"endpoint id",style:{width:"100%",background:"var(--inset)",border:"1px solid var(--border)",borderRadius:4,padding:"4px 8px",color:"var(--fg)",fontSize:12},"aria-label":"Source endpoint ID","aria-describedby":"rel-src-kind"})]})]}),(0,a.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,a.jsxs)("div",{style:{flex:"0 0 140px"},children:[(0,a.jsx)("label",{htmlFor:"rel-tgt-kind",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Target kind"}),(0,a.jsx)("select",{id:"rel-tgt-kind",value:n.targetKind,onChange:e=>s(t=>({...t,targetKind:e.target.value})),style:{width:"100%",background:"var(--inset)",border:"1px solid var(--border)",borderRadius:4,padding:"4px 8px",color:"var(--fg)",fontSize:12},"aria-label":"Target endpoint kind",children:nZ.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]}),(0,a.jsxs)("div",{style:{flex:1},children:[(0,a.jsx)("label",{htmlFor:"rel-tgt-id",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Target ID"}),(0,a.jsx)("input",{id:"rel-tgt-id",type:"text",value:n.targetId,onChange:e=>s(t=>({...t,targetId:e.target.value})),placeholder:"endpoint id",style:{width:"100%",background:"var(--inset)",border:"1px solid var(--border)",borderRadius:4,padding:"4px 8px",color:"var(--fg)",fontSize:12},"aria-label":"Target endpoint ID","aria-describedby":"rel-tgt-kind"})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{htmlFor:"rel-summary",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Summary (optional, ≤240 chars)"}),(0,a.jsx)("textarea",{id:"rel-summary",value:n.summary,maxLength:240,rows:2,onChange:e=>s(t=>({...t,summary:e.target.value})),style:{width:"100%",background:"var(--inset)",border:"1px solid var(--border)",borderRadius:4,padding:"4px 8px",color:"var(--fg)",fontSize:12,resize:"vertical"},"aria-label":"Relationship summary"})]}),i.length>0&&(0,a.jsx)("div",{className:"lk-alert",role:"status","aria-live":"polite","data-testid":"client-validation-hints",children:i.map((e,t)=>(0,a.jsx)("div",{style:{fontSize:12},children:e},t))}),h&&(0,a.jsx)("div",{style:{fontSize:12,color:"var(--fg-muted)"},"aria-live":"polite",children:"Validating…"}),null!==o&&(0,a.jsxs)("div",{className:"lk-alert",role:"alert","aria-live":"assertive","data-testid":"server-denial-banner",children:[o.codes.map((e,t)=>{var n;return(0,a.jsxs)("div",{style:{marginBottom:6*(t<o.codes.length-1)},children:[(0,a.jsx)("div",{style:{fontFamily:"var(--mono)",fontSize:11,color:"var(--fg-muted)",marginBottom:2},children:e}),(0,a.jsx)("div",{style:{fontSize:13,color:"var(--fg)"},children:null!=(n=o.messages[t])?n:e})]},e)}),C&&(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>c(null),style:{marginTop:6},children:"Dismiss"})]}),(0,a.jsxs)("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",marginTop:4},children:[(0,a.jsx)("button",{type:"button",className:"arun-btn",onClick:()=>t(null),style:{minWidth:24,minHeight:24},children:"Cancel"}),(0,a.jsx)("button",{type:"button",className:"arun-btn".concat(S?" primary":""),"aria-disabled":!S,disabled:!S,onClick:()=>void w(),"aria-busy":d,style:{minWidth:24,minHeight:24},children:d?"Creating…":"Create"})]})]})]})})}let iU={};function i_(){var e;let{activityMap:t,throughputMap:n,animate:s}=function(e){let t=(0,l.useRef)(new Map),n=(0,l.useRef)("undefined"==typeof document||"visible"===document.visibilityState),[a,s]=(0,l.useState)(new Map),[i,r]=(0,l.useState)(new Map),o=(0,l.useRef)(new Map),c=(0,l.useRef)(new Map),[d,u]=(0,l.useState)(()=>window.matchMedia("(prefers-reduced-motion: reduce)").matches),[h,p]=(0,l.useState)(!1),m=(0,l.useCallback)(()=>{p(!0)},[]),f=(0,l.useCallback)((e,n)=>{let a=new Map(o.current),l=new Set,i=new Set,d=!1;for(let[s,r]of a){var u;let o=e-(null!=(u=t.current.get(s))?u:0);o>=6e4&&"inactive"!==r&&(a.set(s,"inactive"),i.add(s),d=!0),!n&&o>=12e4&&(a.delete(s),l.add(s),i.add(s),d=!0)}if(a.size>512)for(let e of Array.from(a.keys()).sort((e,n)=>{var l,s;let i=a.get(e),r=a.get(n);return"inactive"===i&&"inactive"!==r?-1:"inactive"!==i&&"inactive"===r?1:(null!=(l=t.current.get(e))?l:0)-(null!=(s=t.current.get(n))?s:0)}).slice(0,a.size-512))a.delete(e),l.add(e),i.add(e),d=!0;if(d&&(o.current=a,s(a)),l.size>0)for(let e of l)t.current.delete(e);if(i.size>0){let e=!1,t=new Map(c.current);for(let n of i)t.delete(n)&&(e=!0);e&&(c.current=t,r(t))}},[]);(0,l.useEffect)(()=>{let e=window.matchMedia("(prefers-reduced-motion: reduce)"),t=e=>{u(e.matches)};return e.addEventListener("change",t),()=>{e.removeEventListener("change",t)}},[]);let g=(0,l.useCallback)(e=>{var a;if(!n.current)return;let l=Date.now();l-(null!=(a=t.current.get(e.id))?a:0)<2e3||(t.current.set(e.id,l),s(t=>{let n=new Map(t);return n.set(e.id,e.state),o.current=n,n}),"high-throughput"===e.state&&void 0!==e.count?r(t=>{let n=new Map(t);return n.set(e.id,e.count),c.current=n,n}):r(t=>{if(!t.has(e.id))return t;let n=new Map(t);return n.delete(e.id),c.current=n,n}))},[]);return(0,l.useEffect)(()=>{let e=setInterval(()=>{n.current&&f(Date.now(),!1)},15e3);return()=>{clearInterval(e)}},[f]),(0,l.useEffect)(()=>{if("undefined"==typeof document)return;let e=()=>{n.current="visible"===document.visibilityState,n.current&&f(Date.now(),!0)};return n.current="visible"===document.visibilityState,document.addEventListener("visibilitychange",e),()=>{document.removeEventListener("visibilitychange",e)}},[f]),(0,l.useEffect)(()=>{let e=!1,t=null,a=null;function l(e){let t;try{t=JSON.parse(e)}catch(e){return}let n=function(e){var t;if(null===e||"object"!=typeof e||function e(t){if(null===t||"object"!=typeof t)return!1;for(let n of Object.keys(t))if(function(e){let t=e.toLowerCase();return n1.some(e=>t.includes(e))}(n)||e(t[n]))return!0;return!1}(e))return null;let n={};for(let t of iN)Object.prototype.hasOwnProperty.call(e,t)&&(n[t]=e[t]);return"string"!=typeof n.id||0===n.id.length?null:"inactive"!==(t=n.state)&&"queued"!==t&&"active"!==t&&"processing"!==t&&"completed"!==t&&"failed"!==t&&"blocked"!==t&&"degraded"!==t&&"high-throughput"!==t||"number"!=typeof n.timestamp?null:{kind:"string"==typeof n.kind?n.kind:"relationship:activity",id:n.id,state:n.state,timestamp:n.timestamp,count:"number"==typeof n.count?n.count:void 0}}(t);null!==n&&g(n)}function s(){null!==a&&(clearTimeout(a),a=null)}function i(){null==t||t.close(),t=null}function r(){!e&&null===a&&n.current&&(a=setTimeout(()=>{a=null,o()},5e3))}function o(){if(!e&&n.current){try{t=new EventSource("/api/relationships/events")}catch(e){r();return}t.addEventListener("relationship:activity",e=>{l(e.data)}),t.onmessage=e=>{l(e.data)},t.onerror=()=>{e||(i(),r())}}}o();let c=()=>{if(n.current="visible"===document.visibilityState,!n.current){s(),i();return}f(Date.now(),!0),null===t&&o()};return document.addEventListener("visibilitychange",c),()=>{e=!0,document.removeEventListener("visibilitychange",c),s(),i()}},[void 0,g,f]),{activityMap:a,throughputMap:i,animate:!d&&!h,disable:m}}(),[i,r]=(0,l.useState)(!1),[o,c]=(0,l.useState)(iU),d=o.relFocus,u=null!=(e=o.relDensity)?e:"standard",[h,p]=(0,l.useState)(!1),m=(0,l.useRef)(null),f=(0,l.useRef)(!1),[g,v]=(0,l.useState)(!1),x=(0,l.useCallback)(e=>{c(t=>{let n={...t,...e},a={};for(let[e,t]of Object.entries(n))void 0!==t&&""!==t&&(a[e]=t);return a})},[]),y=(0,l.useCallback)(e=>{x({relFocus:e})},[x]),b=(0,l.useCallback)(()=>{x({relFocus:void 0})},[x]),j=(0,l.useCallback)(e=>{x({relFocus:e})},[x]),w=(0,l.useCallback)(e=>{f.current=!0,p(!1),null!==e&&x({relFocus:e.id})},[x]);return(0,l.useEffect)(()=>{var e;!h&&f.current&&(f.current=!1,null==(e=m.current)||e.focus())},[h]),(0,l.useEffect)(()=>{let e=window.matchMedia("(prefers-contrast: more)"),t=e=>{r(e)};t(e.matches);let n=e=>{t(e.matches)};return e.addEventListener("change",n),()=>e.removeEventListener("change",n)},[]),(0,l.useEffect)(()=>{let e=e=>{let t=e.target;if(!("INPUT"===t.tagName||"TEXTAREA"===t.tagName||"SELECT"===t.tagName||t.isContentEditable)&&"Escape"===e.key){if(h)return;b()}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[h,b]),(0,a.jsxs)(a.Fragment,{children:[h&&(0,a.jsx)(iW,{onClose:w}),(0,a.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden",background:"var(--bg)"},children:[(0,a.jsxs)("header",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 12px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,a.jsx)("button",{type:"button",className:"arun-btn",onClick:()=>v(e=>!e),"aria-pressed":g,"aria-label":"Toggle the graph health view",style:{flex:"0 0 auto",minHeight:24,marginRight:"auto"},children:g?"Hide health":"Graph health"}),(0,a.jsx)("button",{ref:m,type:"button",className:"arun-btn primary",onClick:()=>p(!0),"aria-label":"Create new relationship",style:{flex:"0 0 auto",minWidth:24,minHeight:24},children:"+ New relationship"})]}),(0,a.jsxs)("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[(0,a.jsx)("div",{style:{flex:"0 0 280px",borderRight:"1px solid var(--border)",overflowY:"auto"},children:(0,a.jsx)(ia,{filters:o,selectedId:d,onSelect:y,onFilterChange:x,activityMap:t,throughputMap:n,animateBadges:s,highContrast:i})}),(0,a.jsx)("div",{style:{flex:1,overflowY:"auto"},children:g?(0,a.jsx)(iE,{onSelectRelationship:e=>{v(!1),y(e)}}):(0,a.jsx)(ik,{relationshipId:null!=d?d:null,densityMode:u,onClearFocus:b,onViewImpact:j,activityMap:t,throughputMap:n,animateBadges:s,highContrast:i})})]})]})]})}function iH(e,t){let n=e[t];return"string"==typeof n?n:void 0}el("project",()=>(0,a.jsx)(ah,{})),el("search",()=>(0,a.jsx)(ag,{})),el("plugins",()=>(0,a.jsx)(ab,{})),el("automations",()=>(0,a.jsx)(aS,{})),el("mobile",()=>(0,a.jsx)(aC,{})),el("inspector",()=>(0,a.jsx)(aR,{})),el("notifications",()=>(0,a.jsx)(aE,{})),el("resources",()=>(0,a.jsx)(aM,{})),el("activity",()=>(0,a.jsx)(aP,{})),el("keiko",()=>(0,a.jsx)(lM,{})),el("settings",()=>(0,a.jsx)(lL,{})),el("quality",(e,t)=>{var n;return(0,a.jsx)(sj,{openRun:e=>{t.openWindow("qiRun",{runId:e,...function(e){var t;let n=st({connectedFilePath:null!=(t=e.linkedFilePath)?t:null,connectedRoot:e.linkedRoot,connectedRoots:e.linkedRoots,connectedCapsuleIds:e.linkedCapsuleIds,connectedCapsuleSetIds:e.linkedCapsuleSetIds,connectedFigmaSnapshotRunIds:e.linkedFigmaSnapshotRunIds});return n.length>0?{connectedSourcesJson:JSON.stringify(n)}:{}}(t)})},connectedRoot:t.linkedRoot,connectedFilePath:null!=(n=t.linkedFilePath)?n:null,connectedRoots:t.linkedRoots,connectedCapsuleIds:t.linkedCapsuleIds,connectedCapsuleSetIds:t.linkedCapsuleSetIds,connectedFigmaSnapshotRunIds:t.linkedFigmaSnapshotRunIds})}),el("qiRun",(e,t)=>{let n=iH(e,"runId");if(void 0===n||""===n)return(0,a.jsx)("div",{className:"lk-empty",children:(0,a.jsx)("p",{className:"lk-empty-body",children:"Open a run from the Quality Intelligence hub."})});let l=function(e){var t,n;let a=iH(e,"connectedSourcesJson");if(void 0!==a&&a.length>0)try{let e=JSON.parse(a);if(Array.isArray(e))return e}catch(e){}return st({connectedFilePath:null!=(t=iH(e,"connectedFilePath"))?t:null,connectedRoot:null!=(n=iH(e,"connectedRoot"))?n:null})}(e),s=iH(e,"connectedSourcesJson");return(0,a.jsx)(s$,{runId:n,connectedSources:l,onRegenerated:e=>{t.openWindow("qiRun",{runId:e.runId,...void 0!==s&&s.length>0?{connectedSourcesJson:s}:{}})}})}),el("relationships",()=>(0,a.jsx)(i_,{})),el("files",(e,t)=>{let n=iH(e,"root"),l=(e,n)=>{t.updateCfg({activeFilePath:null!=e?e:void 0,resolvedRoot:null!=n?n:void 0})},s=e=>{t.updateCfg({root:e,activeFilePath:void 0,resolvedRoot:void 0})};return void 0!==n?(0,a.jsx)(aH,{root:n,onActiveFileChange:l,onRootChange:s}):(0,a.jsx)(aH,{onActiveFileChange:l,onRootChange:s})}),el("editor",e=>{let t=iH(e,"file");return void 0!==t?(0,a.jsx)(aV,{file:t}):(0,a.jsx)(aV,{})}),el("browser",e=>{let t=iH(e,"url");return void 0!==t?(0,a.jsx)(a5,{url:t}):(0,a.jsx)(a5,{})}),el("terminal",e=>{let t=iH(e,"cwd"),n=iH(e,"projectPath"),l={};return void 0!==t&&(l.cwd=t),void 0!==n&&(l.projectPath=n),(0,a.jsx)(le,{...l})}),el("review",e=>{let t=iH(e,"runId");return void 0!==t&&""!==t?(0,a.jsx)(ld,{runId:t}):(0,a.jsx)(ld,{})}),el("agents",(e,t)=>(0,a.jsx)(lg,{cfg:function(e){let t={},n=iH(e,"workflow");void 0!==n&&(t.workflow=n);let a=iH(e,"model");void 0!==a&&(t.model=a);let l=iH(e,"runId");void 0!==l&&(t.runId=l);let s=iH(e,"fingerprint");void 0!==s&&(t.fingerprint=s);let i=iH(e,"workspaceRoot");void 0!==i&&(t.workspaceRoot=i);let r=iH(e,"inputJson");void 0!==r&&(t.inputJson=r);let o=function(e,t){let n=e[t];return"boolean"==typeof n?n:void 0}(e,"keikoMode");void 0!==o&&(t.keikoMode=o);let c=function(e){let t=e.access;return"ask"===t||"full"===t?t:void 0}(e);return void 0!==c&&(t.access=c),t}(e),linkedRoot:t.linkedRoot,linkedFilePath:t.linkedFilePath})),el("integ",e=>{let t=iH(e,"provider");return void 0!==t?(0,a.jsx)(lx,{provider:t}):(0,a.jsx)(lx,{})}),el("figma",(e,t)=>{let n=iH(e,"snapshotRunId");return(0,a.jsx)(lY,{snapshotRunId:n,updateCfg:e=>{t.updateCfg(e)}})}),el("connector",(e,t)=>{let n=iH(e,"selectedKind"),l=iH(e,"selectedId");return(0,a.jsx)(lU,{selectedKind:n,selectedId:l,onSelect:e=>{t.updateCfg(e)}})});let iJ={supported:{heading:"Install Keiko",body:"Keep Keiko in your app shelf for fast access.",install:"Install Keiko"},"ios-add-to-home":{heading:"Install Keiko",body:'On iOS Safari, tap Share, then "Add to Home Screen".',install:null}};function iV(){let{available:e,triggerInstall:t}=function(){let[e,t]=(0,l.useState)(!1),n=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let e=e=>{e.preventDefault(),function(e){if("function"!=typeof e.prompt)return!1;let t=e.userChoice;return"object"==typeof t&&null!==t&&"function"==typeof t.then}(e)&&(n.current=e,t(!0))},a=()=>{localStorage.setItem("keiko.pwa.installed","true"),n.current=null,t(!1)};return window.addEventListener("beforeinstallprompt",e,{passive:!1}),window.addEventListener("appinstalled",a),()=>{window.removeEventListener("beforeinstallprompt",e),window.removeEventListener("appinstalled",a)}},[]),{available:e,triggerInstall:(0,l.useCallback)(async()=>{let e=n.current;if(null===e)return;await e.prompt();let{outcome:a}=await e.userChoice;"accepted"===a&&localStorage.setItem("keiko.pwa.installed","true"),n.current=null,t(!1)},[])}}(),[n,s]=(0,l.useState)(!1),[i]=(0,l.useState)(()=>"undefined"!=typeof navigator?function(e){let t=e.toLowerCase();return t.includes("crios/")?"manual":t.includes("chrome/")&&!t.includes("mobile")||t.includes("edg/")||t.includes("chromium/")?"supported":t.includes("firefox/")?"manual":t.includes("safari/")&&(t.includes("iphone")||t.includes("ipad")||t.includes("ipod"))?"ios-add-to-home":(t.includes("safari/")&&t.includes("macintosh"),"manual")}(navigator.userAgent):"manual"),r=(0,l.useRef)(null),o=(0,l.useCallback)(()=>{localStorage.setItem("keiko.pwa.dismissed",new Date().toISOString()),s(!0)},[]),c=(0,l.useCallback)(async()=>{await t()},[t]);if((0,l.useEffect)(()=>{let e=e=>{"Escape"===e.key&&o()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[o]),n||window.matchMedia("(display-mode: standalone)").matches||"true"===localStorage.getItem("keiko.pwa.installed")||null!==localStorage.getItem("keiko.pwa.dismissed")||"supported"===i&&!e||"supported"!==i&&"ios-add-to-home"!==i)return null;let d=iJ[i];return(0,a.jsx)("aside",{className:"install-banner",role:"region","aria-label":"Install Keiko",children:(0,a.jsxs)("div",{className:"install-banner-body",children:[(0,a.jsxs)("div",{className:"install-banner-text",children:[(0,a.jsx)("span",{className:"install-banner-heading",children:d.heading}),(0,a.jsx)("span",{className:"install-banner-desc",children:d.body})]}),(0,a.jsxs)("div",{className:"install-banner-actions",children:[null!==d.install&&(0,a.jsx)("button",{ref:r,type:"button",className:"install-banner-btn-install",onClick:()=>void c(),children:d.install}),(0,a.jsx)("button",{type:"button",className:"install-banner-btn-dismiss","aria-label":"Dismiss install banner",onClick:o,children:(0,a.jsx)("span",{"aria-hidden":"true",children:"Not now"})})]})]})})}let iG=["chat","connector","figma","files","editor","browser","terminal","review","agents","integ"],iX=["project","search","plugins","automations","mobile","inspector","activity","notifications","resources"];function iY(){var e,t,n,s,r,o,c,d;let{theme:u,toggle:h}=function(){let[e,t]=(0,l.useState)(nM),[n,a]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{t(function(){try{let e=window.localStorage.getItem(nE);return"light"===e||"dark"===e?e:nM}catch(e){return nM}}()),a(!0)},[]),(0,l.useEffect)(()=>{if(n){"undefined"!=typeof document&&(document.documentElement.dataset.theme=e);try{window.localStorage.setItem(nE,e)}catch(e){}}},[e,n]),{theme:e,toggle:(0,l.useCallback)(()=>{t(e=>"light"===e?"dark":"light")},[])}}(),p=w(),m=function(){var e;let[t,n]=(0,l.useState)(tJ),[a,s]=(0,l.useState)(""),[i,r]=(0,l.useState)(!0),[o,c]=(0,l.useState)("idle"),d=tL(o),u=(0,l.useRef)("idle"),h=(0,l.useRef)(null),[p,m]=(0,l.useState)(),[f,g]=(0,l.useState)(),[v,x]=(0,l.useState)(),[y,b]=(0,l.useState)(!0),[j,w]=(0,l.useState)(1200),k=(0,l.useRef)(void 0),N=(0,l.useRef)(0),S=(0,l.useRef)([]),[C,R]=(0,l.useState)([]),[I,E]=(0,l.useState)([]),M=(0,l.useCallback)(async e=>{var n;let a;if(0===e.size)return{ok:!1,reason:"empty"};if(e.size>8388608)return{ok:!1,reason:"oversized"};let l=(n=e.type).startsWith("image/")?"image":tP.some(e=>n.startsWith(e))||tA.has(n)?"document":"unsupported-type";if("unsupported-type"===l)return{ok:!1,reason:"unsupported-type"};let s=t.models.find(e=>e.id===t.selectedModel);if(void 0!==s&&("image"===l&&!s.supportsImageInput||"document"===l&&!s.supportsDocumentInput))return{ok:!1,reason:"text-only-model"};if("image"===l)try{a=await new Promise((t,n)=>{let a=new FileReader;a.onload=()=>t(a.result),a.onerror=()=>n(Error("FileReader error")),a.readAsDataURL(e)})}catch(e){return{ok:!1,reason:"unsupported-type"}}let i={id:crypto.randomUUID(),kind:l,name:e.name,mimeType:e.type,sizeBytes:e.size,previewDataUrl:a,file:e};return R(e=>[...e,i]),{ok:!0}},[t.models,t.selectedModel]),T=(0,l.useCallback)(e=>{R(t=>t.filter(t=>t.id!==e))},[]),q=(0,l.useCallback)(()=>{R([])},[]),P=(0,l.useCallback)(async()=>{let e=C.filter(e=>"document"===e.kind&&void 0!==e.file).map(e=>({id:e.id,name:e.name,mimeType:e.mimeType,sizeBytes:e.sizeBytes,file:e.file}));if(0===e.length)return{entries:[],disclosures:[]};let{entries:t,failures:n}=await tq(e);n.length>0&&m(n.join(" "));let a=t.map(e=>({id:e.id,displayName:e.displayName,truncated:e.truncated}));return{entries:t,disclosures:a}},[C]),A=(0,l.useCallback)(()=>{x(void 0)},[]),z=(0,l.useCallback)((e,t)=>({enabled:y,budgetTokens:j,context:{userId:"local-operator",workspaceId:t.path,projectId:t.path,conversationId:e.id}}),[j,y]),D=(0,l.useCallback)(async e=>{await (0,tk.mc)(e),x(t=>void 0===t?t:{...t,actions:t.actions.filter(t=>"candidate"!==t.kind||t.proposalId!==e)})},[]),L=(0,l.useCallback)(async e=>{await (0,tk.RT)(e),x(t=>void 0===t?t:{...t,actions:t.actions.filter(t=>"candidate"!==t.kind||t.proposalId!==e)})},[]),F=(0,l.useCallback)(async e=>{await (0,tk.hz)(e,"user-initiated forget from Conversation Center"),x(t=>void 0===t?t:{...t,actions:t.actions.filter(t=>"forget"!==t.kind||t.memoryId!==e)})},[]),O=(0,l.useCallback)(e=>{u.current=e,c(e)},[]);(0,l.useEffect)(()=>{var e;k.current=null==(e=t.activeChat)?void 0:e.id},[null==(e=t.activeChat)?void 0:e.id]),(0,l.useEffect)(()=>{S.current=t.models},[t.models]),(0,l.useEffect)(()=>{let e=!1;return async function(){r(!0),m(void 0);try{let t=await tV();e||n(e=>({...e,...t}))}catch(t){e||m(tW(t))}finally{e||r(!1)}}(),()=>{e=!0}},[]),(0,l.useEffect)(()=>()=>{var e;null==(e=h.current)||e.abort()},[]);let K=(0,l.useCallback)(e=>{let t;m(void 0),n(n=>(t={selectedModel:n.selectedModel,activeChat:n.activeChat,chats:n.chats},{...n,selectedModel:e,activeChat:void 0===n.activeChat?n.activeChat:{...n.activeChat,selectedModel:e},chats:n.chats.map(t=>void 0!==n.activeChat&&t.id===n.activeChat.id?{...t,selectedModel:e}:t)})),R(t=>t.filter(t=>(function(e,t,n){let a=n.find(e=>e.id===t);return void 0===a||("image"===e.kind?a.supportsImageInput:a.supportsDocumentInput)})(t,e,S.current)));let a=k.current;if(void 0===a)return;let l=N.current+1;N.current=l,(0,$.wi)(a,{selectedModel:e}).then(e=>{N.current===l&&k.current===e.chat.id&&n(t=>{var n;return{...t,selectedModel:e.chat.selectedModel,activeChat:(null==(n=t.activeChat)?void 0:n.id)===e.chat.id?e.chat:t.activeChat,chats:t.chats.map(t=>t.id===e.chat.id?e.chat:t)}})}).catch(e=>{if(N.current===l&&k.current===a&&(m(tW(e)),void 0!==t)){let e=t;n(t=>{var n,l;return{...t,selectedModel:(null==(n=t.activeChat)?void 0:n.id)===a?e.selectedModel:t.selectedModel,activeChat:(null==(l=t.activeChat)?void 0:l.id)===a?e.activeChat:t.activeChat,chats:t.chats.map(t=>{if(t.id!==a)return t;let n=e.chats.find(e=>e.id===a);return void 0!==n?{...t,selectedModel:n.selectedModel}:t})}})}})},[]),B=(0,l.useCallback)(async e=>{let a=tH(t.selectedModel,t.models);if(void 0===a)return void m("No conversation-eligible model is configured. Connect a gateway in Settings.");m(void 0);try{var l,s;let i={modelId:a,title:tz},r=null!=(s=null==e?void 0:e.path)?s:null==(l=t.activeProject)?void 0:l.path;void 0!==r&&(i.projectPath=r);let o=await (0,$.tA)(i);k.current=o.chat.id,n({projects:Array.from(o.projects),chats:tU(o.chats),messages:Array.from(o.messages),models:t.models,activeProject:o.project,activeChat:o.chat,selectedModel:o.chat.selectedModel})}catch(e){m(tW(e))}},[t.selectedModel,t.activeProject,t.models]),W=(0,l.useCallback)(async e=>{m(void 0),n(t=>({...t,activeProject:e}));try{let a=await (0,$.Oz)(e.path),l=tU(a.chats),s=l[0];if(void 0===s)return void await B(e);let i=await (0,$.T$)(s.id,e.path);k.current=s.id;let r=tH(s.selectedModel,t.models);n(e=>({...e,chats:l,activeChat:s,selectedModel:r,messages:Array.from(i.messages)})),x(void 0)}catch(e){m(tW(e))}},[B,t.models]),U=(0,l.useCallback)(async e=>{var a;m(void 0),null==(a=h.current)||a.abort(),h.current=null,k.current=e.id,g(void 0),x(void 0),E([]);try{let a=await (0,$.T$)(e.id,e.projectPath),l=tH(e.selectedModel,t.models);n(t=>{let n=t.projects.find(t=>t.path===e.projectPath);return{...t,activeProject:n,activeChat:e,selectedModel:l,messages:Array.from(a.messages)}})}catch(e){m(tW(e))}},[t.models]),_=(0,l.useCallback)(async e=>{let t=e.trim();if(0!==t.length){m(void 0);try{let e=await (0,$.gA)({path:t}),a=await (0,$.vj)();n(e=>({...e,projects:Array.from(a.projects)})),await B(e.project)}catch(e){m(tW(e))}}},[B]),H=(0,l.useCallback)(e=>{n(t=>({...t,messages:t.messages.filter(t=>t.id!==e)}))},[]),J=(0,l.useCallback)((e,t,a)=>{let l=!1;return{onToken:t=>{l||(O("streaming"),l=!0),n(n=>({...n,messages:n.messages.map(n=>n.id===e?{...n,content:n.content+t}:n)}))},onDone:l=>{n(n=>({...n,activeChat:l.chat,chats:tU([l.chat,...n.chats.filter(e=>e.id!==l.chat.id)]),messages:[...n.messages.filter(n=>n.id!==t&&n.id!==e),...Array.from(l.messages)]})),void 0!==l.memory&&x(l.memory),a("completed")},onError:t=>{let{message:n}=t;m(n),H(e),a("failed")},onCancelled:()=>{H(e),a("cancelled")}}},[H,O]),V=(0,l.useCallback)((e,t,a,l,s,i,r)=>{let o="stream-".concat(String(Date.now()));n(t=>({...t,messages:[...t.messages,{id:o,chatId:e.id,role:"assistant",content:"",timestamp:Date.now(),runId:void 0,workflowId:void 0,workflowStatus:void 0,shortResult:void 0,taskType:void 0}]}));let c={chatId:e.id,projectPath:t.path,content:a,modelId:s,memory:z(e,t),...r.length>0?{documentContext:r}:{}};return new Promise((e,t)=>{let n=J(o,l,e);(0,$.nk)(c,i,n).catch(n=>{H(o),n instanceof $.ZF?t(n):n instanceof DOMException&&"AbortError"===n.name?e("cancelled"):e("failed")})})},[z,J,H]),G=(0,l.useCallback)(async(e,t,a,l,s,i,r)=>{try{O("contacting");let o=await (0,$.xp)({chatId:e.id,projectPath:t.path,content:a,modelId:s,memory:z(e,t),...r.length>0?{documentContext:r}:{}},i);if(i.aborted)return"cancelled";return n(e=>({...e,activeChat:o.chat,chats:tU([o.chat,...e.chats.filter(e=>e.id!==o.chat.id)]),messages:[...e.messages.filter(e=>e.id!==l),...Array.from(o.messages)]})),x(o.memory),"completed"}catch(a){if(a instanceof DOMException&&"AbortError"===a.name)return"cancelled";m(tW(a));try{let a=await (0,$.T$)(e.id,t.path);n(e=>({...e,messages:Array.from(a.messages)}))}catch(e){n(e=>({...e,messages:e.messages.filter(e=>e.id!==l)}))}return"failed"}},[z,O]),X=(0,l.useCallback)(async(e,n,a,l,s,i,r)=>{var o;if((null==(o=t.models.find(e=>e.id===s))?void 0:o.streaming)!==!0)return G(e,n,a,l,s,i,r);O("contacting");try{return await V(e,n,a,l,s,i,r)}catch(e){if(!(e instanceof $.ZF))throw e}return G(e,n,a,l,s,i,r)},[t.models,G,V,O]),Y=(0,l.useCallback)(async(e,t,a,l,s,i)=>{g(void 0);try{O("contacting");let l=await (0,$.Wk)({chatId:e.id,content:a,modelId:s},i);if(k.current!==e.id)return"completed";if(i.aborted)return"cancelled";g(l),x(void 0);let[r,o]=await Promise.all([(0,$.T$)(e.id,t.path),(0,$.Oz)(t.path)]),c=o.chats.find(t=>t.id===e.id);return n(e=>({...e,messages:Array.from(r.messages),chats:tU(o.chats),activeChat:null!=c?c:e.activeChat})),"completed"}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return"cancelled";return m(tW(e)),n(e=>({...e,messages:e.messages.filter(e=>e.id!==l)})),"failed"}},[O]),Z=(0,l.useCallback)(()=>{var e;tL(u.current)&&(null==(e=h.current)||e.abort(),h.current=null,O("cancelled"))},[O]),Q=(0,l.useCallback)(async()=>{var e,l,i,r;if(tL(u.current))return;let o=a.trim(),c=t.activeChat,d=t.activeProject,p=tH(t.selectedModel,t.models);if(0===o.length||void 0===c||void 0===d||void 0===p)return;if(tB((0,tN.pk)({modelContextWindow:null!=(i=null==(e=t.models.find(e=>e.id===p))?void 0:e.contextWindow)?i:0,modelMaxOutputTokens:null!=(r=null==(l=t.models.find(e=>e.id===p))?void 0:l.maxOutputTokens)?r:0,userDraftText:o,conversationHistory:t.messages.filter(e=>"user"===e.role||"assistant"===e.role).map(e=>({role:e.role,content:e.content}))})))return void m(tF);let f={id:"local-".concat(String(Date.now())),chatId:c.id,role:"user",content:o,timestamp:Date.now(),runId:void 0,workflowId:void 0,workflowStatus:void 0,shortResult:void 0,taskType:void 0};O("queued"),s(""),m(void 0),n(e=>({...e,messages:[...e.messages,f]}));let g=new AbortController;h.current=g,x(void 0);try{let e=void 0!==c.connectedScope||void 0!==c.localKnowledgeScope,{entries:t,disclosures:n}=e?{entries:[],disclosures:[]}:await P(),a=e?await Y(c,d,o,f.id,p,g.signal):await X(c,d,o,f.id,p,g.signal,t);"cancelled"===u.current||O(a),"completed"===a&&(q(),E(n))}finally{h.current=null}},[a,t.activeChat,t.activeProject,t.selectedModel,t.models,t.messages,Y,X,P,q,O]),ee=(0,l.useCallback)(()=>{g(void 0),x(void 0),n(e=>({...e,messages:[]}))},[]),et=(0,l.useMemo)(()=>{let e=t.models.find(e=>e.id===t.selectedModel);if(void 0===e)return;let n=t.messages.filter(e=>"user"===e.role||"assistant"===e.role).map(e=>({role:e.role,content:e.content})),l=0,s=0;void 0!==f&&(("connected-context"===f.groundingKind||"hybrid"===f.groundingKind)&&(l=("hybrid"===f.groundingKind?f.contextPack.folder:f.contextPack).usage.excerptBytes),("local-knowledge"===f.groundingKind||"hybrid"===f.groundingKind)&&(s=4*("hybrid"===f.groundingKind?f.contextPack.knowledge:f.contextPack).referenceBudget));let i=y&&void 0!==v&&v.context.enabled?v.context.text.length:0;return(0,tN.pk)({modelContextWindow:e.contextWindow,modelMaxOutputTokens:e.maxOutputTokens,userDraftText:a,conversationHistory:n,repoContextPackBytes:l,knowledgeCapsuleBytes:s,memoryContextBytes:i})},[t.models,t.selectedModel,t.messages,a,f,v,y]),en=(0,l.useCallback)(async e=>{if(tL(u.current))return{ok:!1,reason:"request-failed",message:"A request is already in flight."};let a=e.text.trim();if(0===a.length)return{ok:!1,reason:"missing-input"};let l=t.activeChat,s=t.activeProject;if(void 0===l||void 0===s)return{ok:!1,reason:"missing-chat"};let i=t.models.find(t=>t.id===e.modelId);if(void 0===i||!tu(i))return{ok:!1,reason:"not-workflow-eligible"};let r=td(e.workflowId);if(void 0===r)return{ok:!1,reason:"unknown-workflow"};let o=Date.now(),c=r.buildInput(s.path,a);try{let t=await (0,$.qV)({chatId:l.id,projectPath:s.path,run:{workflowId:e.workflowId,input:c,modelId:e.modelId},user:{content:a,timestamp:o},summary:{content:"Launched: ".concat(r.label),timestamp:o+1}});return n(e=>({...e,messages:Array.from(t.messages)})),{ok:!0,runId:t.run.runId}}catch(t){let e=tW(t);return m(e),{ok:!1,reason:"request-failed",message:e}}},[t.activeChat,t.activeProject,t.models]),ea=(0,l.useCallback)(async e=>{if(tL(u.current))return{ok:!1,reason:"request-failed",message:"A request is already in flight."};if(void 0===t.activeChat)return{ok:!1,reason:"missing-chat"};if(0===e.modelId.trim().length)return{ok:!1,reason:"missing-model"};try{let t=await (0,$.Is)({assistantMessageId:e.assistantMessageId,modelId:e.modelId,workflowKind:e.workflowKind,input:e.input,editablePaths:e.editablePaths,...void 0===e.expectedChecks?{}:{expectedChecks:e.expectedChecks},...void 0===e.unknowns?{}:{unknowns:e.unknowns},requestedAtMs:Date.now()});return n(e=>({...e,messages:Array.from(t.messages)})),{ok:!0,runId:t.run.runId}}catch(t){let e=tW(t);return m(e),{ok:!1,reason:"request-failed",message:e}}},[t.activeChat]),el=(0,l.useCallback)(e=>{n(t=>{var n;return{...t,chats:t.chats.map(t=>t.id===e.id?e:t),activeChat:(null==(n=t.activeChat)?void 0:n.id)===e.id?e:t.activeChat}})},[]);return{projects:t.projects,chats:t.chats,messages:t.messages,models:t.models,activeProject:t.activeProject,activeChat:t.activeChat,selectedModel:t.selectedModel,noEligibleModels:!i&&void 0===tH(t.selectedModel,t.models),draft:a,loading:i,sending:d,sendStatus:o,error:p,setDraft:s,setSelectedModel:K,openNewChat:B,openProject:W,openChat:U,addProject:_,sendMessage:Q,cancelSend:Z,replaceChat:el,latestGrounded:f,cancelGrounded:Z,pendingAttachments:C,addPendingAttachment:M,removePendingAttachment:T,clearPendingAttachments:q,lastSentDocuments:I,budget:et,memoryEnabled:y,setMemoryEnabled:b,memoryBudgetTokens:j,setMemoryBudgetTokens:w,latestMemory:v,clearLatestMemory:A,acceptMemoryCandidate:D,rejectMemoryCandidate:L,forgetMemoryAction:F,clearHistory:ee,launchWorkflowFromConversation:en,launchGroundedWorkflowHandoff:ea}}(),f=(0,l.useRef)(null),[g,v]=(0,l.useState)(tN.ty);(0,l.useEffect)(()=>{(0,$.Dz)().then(e=>v(e.effectiveGroundingLimits)).catch(()=>void 0)},[]);let x=(0,l.useCallback)(e=>{let t=m.activeChat;if(void 0===t)return;let n=eh(t),a=function(e,t,n){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:16;if(!ec(t))return null;if(e.some(e=>e.root===t))return e;let l=[...e,{kind:"workspace-root",relativePaths:[],root:t,connectedAtMs:n}];return l.length>a?l.slice(-a):l}(n,e,Date.now(),g.maxConnectedSources);null!==a&&a!==n&&(0,$.Mr)(t.id,a).then(n=>{var a;m.replaceChat(n.chat),a=t.id,0!==a.length&&0!==e.length&&n6({type:"reads-context",source:{kind:"chat",id:a},target:{kind:"workspace-path",id:e}},function(e,t){let n=0x811c9dc5,a="".concat(e,"|").concat(t);for(let e=0;e<a.length;e+=1)n=Math.imul(n^a.charCodeAt(e),0x1000193);return"rc-".concat((n>>>0).toString(36),"-").concat((65535&a.length).toString(36))}(a,e)).catch(e=>{})}).catch(()=>void 0)},[m,g.maxConnectedSources]),y=(0,l.useCallback)(e=>{var t;let n=m.activeChat;if(void 0===n)return;let a=(t=eh(n),t.filter(t=>t.root!==e));(0,$.Mr)(n.id,a.length>0?a:null).then(e=>{m.replaceChat(e.chat)}).catch(()=>void 0)},[m]),b=function(e){var t,n,a,s,i,r;let o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},[c,d]=(0,l.useState)(null),[u,h]=(0,l.useState)(null),[p,m]=(0,l.useState)(!1),[f,g]=(0,l.useState)([]),[v,x]=(0,l.useState)(null),[y,b]=(0,l.useState)(nH),j=(0,l.useRef)(3),w=(0,l.useRef)(null),k=(0,l.useRef)([]);k.current=null!=c?c:[];let N=(0,l.useRef)([]);N.current=f;let S=(0,l.useRef)(null);S.current=v;let C=(0,l.useRef)(null),R=(0,l.useRef)(()=>void 0),{viewRef:I,worldVP:E,zoomTo:M,resetView:T,panBy:q,rect:P}=function(e){let{wsRef:t,view:n,setView:a}=e,s=(0,l.useRef)(n);s.current=n,(0,l.useEffect)(()=>{nX(n_,n)},[n]),(0,l.useEffect)(()=>{let e=t.current;if(null===e)return;let n=t=>{if(t.metaKey||t.ctrlKey){t.preventDefault();let n=e.getBoundingClientRect(),l=s.current,i=nJ(l.zoom*Math.exp(-(.0015*t.deltaY))),r=(t.clientX-n.left-l.x)/l.zoom,o=(t.clientY-n.top-l.y)/l.zoom;a({zoom:i,x:t.clientX-n.left-r*i,y:t.clientY-n.top-o*i});return}let n=t.target;n instanceof Element&&null!==n.closest(".window")||(t.preventDefault(),a(e=>({...e,x:e.x-t.deltaX,y:e.y-t.deltaY})))};return e.addEventListener("wheel",n,{passive:!1}),()=>{e.removeEventListener("wheel",n)}},[t,a]);let i=(0,l.useCallback)(()=>null===t.current?null:t.current.getBoundingClientRect(),[t]),r=(0,l.useCallback)(()=>{let e=i();if(null===e)return null;let t=s.current;return{x:-t.x/t.zoom,y:-t.y/t.zoom,w:e.width/t.zoom,h:e.height/t.zoom}},[i]),o=(0,l.useCallback)(e=>{let t=i();if(null===t)return;let n=s.current,l=t.width/2,r=t.height/2,o=(l-n.x)/n.zoom,c=(r-n.y)/n.zoom,d=nJ(e);a({zoom:d,x:l-o*d,y:r-c*d})},[i,a]);return{viewRef:s,worldVP:r,zoomTo:o,resetView:(0,l.useCallback)(()=>a({zoom:1,x:0,y:0}),[a]),panBy:(0,l.useCallback)((e,t)=>a(n=>({...n,x:n.x+e,y:n.y+t})),[a]),rect:i}}({wsRef:e,view:y,setView:b});!function(e){let{wsRef:t,setWins:n,setConns:a,zc:s}=e;(0,l.useLayoutEffect)(()=>{let e=t.current;if(null===e)return;e.getBoundingClientRect();let l=null;try{l=function(e){if(null===e)return null;try{let t=JSON.parse(e);if(!Array.isArray(t)||0===t.length)return null;let n=nK(t);return n.length>0?n:null}catch(e){return null}}(window.localStorage.getItem(nW))}catch(e){l=null}null===l&&(l=[]),s.current=0===l.length?1:Math.max(1,...l.map(e=>e.z)),n(l);try{a(function(e,t){if(null===e)return[];try{let n=JSON.parse(e);if(!Array.isArray(n))return[];return nB(n,t)}catch(e){return[]}}(window.localStorage.getItem(nU),l))}catch(e){}},[t,n,a,s])}({wsRef:e,setWins:d,setConns:g,zc:j}),(0,l.useEffect)(()=>{null!==c&&nX(nU,nB(f,c))},[f,c]),(0,l.useEffect)(()=>{null!==c&&g(e=>{let t=e.filter(e=>void 0!==c.find(t=>t.id===e.a)&&void 0!==c.find(t=>t.id===e.b));return t.length===e.length?e:t})},[c,g]),(0,l.useEffect)(()=>{null!==c&&nX(nW,nK(c))},[c]),function(e){let{setWins:t,rect:n,cancelConnectRef:a}=e;(0,l.useEffect)(()=>{let e=e=>{var l,s,i;if(null!==(l=document.activeElement)&&("INPUT"===l.tagName||"TEXTAREA"===l.tagName||"SELECT"===l.tagName))return;if("Escape"===e.key)return void a.current();if((e.metaKey||e.ctrlKey)&&["=","+","-","_","0"].includes(e.key)){e.preventDefault(),s=e.key,t(e=>{var t,n;if(null===e||0===e.length)return e;let a=nG(e),l=(n=null!=(t=a.zoom)?t:1,"0"===s?1:"-"===s||"_"===s?nV(n-.1):nV(n+.1));return e.map(e=>e.id===a.id?{...e,zoom:l}:e)});return}if(!/^Arrow/.test(e.key))return;let r=e.metaKey||e.ctrlKey,o=e.altKey;if(!r&&!o)return;e.preventDefault();let c=n();null!==c&&(i={key:e.key,shift:e.shiftKey},t(e=>{if(null===e||0===e.length)return e;let t=nG(e),n=o?function(e,t,n){let a=n.shift?1:16,l=e.w,s=e.h;"ArrowRight"===n.key?l+=a:"ArrowLeft"===n.key?l-=a:"ArrowDown"===n.key?s+=a:"ArrowUp"===n.key&&(s-=a);let i=es[e.type].min;return l=Math.max(i.w,Math.min(t.width,l)),s=Math.max(i.h,Math.min(t.height,s)),{x:e.x,y:e.y,w:l,h:s}}(t,c,i):function(e,t,n){let a=n.shift?1:16,l=e.x,s=e.y;return"ArrowRight"===n.key?l+=a:"ArrowLeft"===n.key?l-=a:"ArrowDown"===n.key?s+=a:"ArrowUp"===n.key&&(s-=a),{x:l=Math.max(-(e.w-120),Math.min(t.width-120,l)),y:s=Math.max(0,Math.min(t.height-38,s)),w:e.w,h:e.h}}(t,c,i);return e.map(e=>e.id===t.id?{...e,...n,max:!1}:e)}))};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e)}},[t,n,a])}({setWins:d,rect:P,cancelConnectRef:R}),function(e){let{wsRef:t,viewRef:n,setWins:a}=e;(0,l.useEffect)(()=>{let e=t.current;if(null===e||"undefined"==typeof ResizeObserver)return;let l=new ResizeObserver(()=>{let t=e.getBoundingClientRect(),l=n.current,s={x:-l.x/l.zoom,y:-l.y/l.zoom,w:t.width/l.zoom,h:t.height/l.zoom};a(e=>null===e?e:e.map(e=>e.max?{...e,x:s.x,y:s.y,w:s.w,h:s.h}:e))});return l.observe(e),()=>{l.disconnect()}},[t,n,a])}({wsRef:e,viewRef:I,setWins:d});let{update:A,focus:z,close:D,maximize:L,add:F,toggleTool:O}={update:(n=(t={setWins:d,zc:j,worldVP:E}).setWins,(e,t)=>n(n=>null===n?n:n.map(n=>n.id===e?{...n,...t}:n))),focus:(a=t.setWins,s=t.zc,e=>a(t=>null===t?t:t.map(t=>t.id===e?{...t,z:++s.current}:t))),close:(i=t.setWins,e=>i(t=>null===t?t:t.filter(t=>t.id!==e))),maximize:function(e){let{setWins:t,zc:n,worldVP:a}=e;return e=>t(t=>{if(null===t)return t;let l=a();return null===l?t:t.map(t=>t.id!==e?t:t.max&&void 0!==t.prev?{...t,x:t.prev.x,y:t.prev.y,w:t.prev.w,h:t.prev.h,max:!1,z:++n.current}:{...t,max:!0,prev:{x:t.x,y:t.y,w:t.w,h:t.h},x:l.x,y:l.y,w:l.w,h:l.h,z:++n.current})})}(t),add:function(e){let{setWins:t,zc:n,worldVP:a}=e;return(e,l)=>{let s=es[e],i=null;return t(t=>{let r=a();if(null===r)return t;let o=null!=t?t:[];if(!0===s.singleton){let t=o.find(t=>t.type===e);if(void 0!==t)return i=t.id,o.map(e=>e.id===t.id?{...e,z:++n.current}:e)}let c="qiRun"===e?null==l?void 0:l.runId:void 0;if("string"==typeof c&&c.length>0){let e=o.find(e=>"qiRun"===e.type&&e.cfg.runId===c);if(void 0!==e)return i=e.id,o.map(t=>t.id===e.id?{...t,z:++n.current}:t)}let{x:d,y:u}=ei(r,s.w,s.h,o.length,40),h=!0===s.singleton?e:"".concat(e,"-").concat(Date.now().toString(36));return i=h,[...o,{id:h,type:e,x:d,y:u,w:s.w,h:s.h,z:++n.current,cfg:null!=l?l:{},max:!1,zoom:1}]}),i}}(t),toggleTool:function(e){let{setWins:t,zc:n,worldVP:a}=e;return e=>{let l=es[e];t(t=>{let s=a();if(null===s)return t;let i=null!=t?t:[];if(void 0!==i.find(t=>t.type===e))return i.filter(t=>t.type!==e);let{x:r,y:o}=ei(s,l.w,l.h,i.length,28);return[...i,{id:e,type:e,x:r,y:o,w:l.w,h:l.h,z:++n.current,cfg:{},max:!1,zoom:1}]})}}(t)},{tileAll:K,splitFront:B,cascade:W}={tileAll:function(e){let{setWins:t,worldVP:n}=e;return()=>t(e=>{if(null===e||0===e.length)return e;let t=n();if(null===t)return e;let a=e.length,l=Math.ceil(Math.sqrt(a)),s=Math.ceil(a/l),i=(t.w-12*(l+1))/l,r=(t.h-12*(s+1))/s;return e.map((e,n)=>{let a=Math.floor(n/l);return{...er(e),max:!1,x:t.x+12+n%l*(i+12),y:t.y+12+a*(r+12),w:i,h:r}})})}(r={setWins:d,worldVP:E}),splitFront:function(e){let{setWins:t,worldVP:n}=e;return()=>t(e=>{if(null===e||0===e.length)return e;let t=n();if(null===t)return e;let a=[...e].sort((e,t)=>t.z-e.z).slice(0,2).map(e=>e.id);return e.map(e=>{let n=a.indexOf(e.id);return 0===n?{...er(e),max:!1,x:t.x,y:t.y,w:t.w/2,h:t.h}:1===n?{...er(e),max:!1,x:t.x+t.w/2,y:t.y,w:t.w/2,h:t.h}:e})})}(r),cascade:function(e){let{setWins:t,worldVP:n}=e;return()=>t(e=>{if(null===e)return e;let t=n();return null===t?e:e.map((e,n)=>({...er(e),max:!1,x:t.x+24+30*n,y:t.y+24+30*n,w:Math.min(560,t.w-80),h:Math.min(420,t.h-80),z:n+1}))})}(r)},{setSnap:U,commitSnap:_}=function(e){let{setSnapPrev:t,snapZone:n,worldVP:a,update:l}=e;return{setSnap:e=>{if(n.current=e,null===e)return void t(null);let l=a();null!==l&&t(G(l)[e])},commitSnap:e=>{let s=n.current;if(n.current=null,t(null),null===s)return;let i=a();if(null===i)return;let r={...G(i)[s],max:"maxi"===s};"maxi"===s&&(r.prev={x:i.x+40,y:i.y+40,w:480,h:360}),l(e,r)}}}({setSnapPrev:h,snapZone:w,worldVP:E,update:A}),{startConnect:H,confirmConnect:J,cancelConnect:X,removeConn:Y,connect:Z,linkedFilesRoot:Q,linkedFilesContext:$,linkedAllFilesRoots:ee,linkedConnectorCapsuleIds:et,linkedConnectorCapsuleSetIds:en,linkedFigmaSnapshotRunIds:ea,currentFilesContext:el}=function(e){let{wsRef:t,viewRef:n,winsRef:a,connsRef:l,connectingRef:s,connectCleanupRef:i,focus:r,setConns:o,setConnecting:c,onScopeBind:d,onScopeUnbind:u,onConnectorBind:h,onConnectorUnbind:p}=e,m=()=>{null!==i.current&&(i.current(),i.current=null),s.current=null,c(null)},f=e=>{if("files"!==e.type)return null;let t=e.cfg.resolvedRoot,n=e.cfg.root,a="string"==typeof t&&t.length>0?t:"string"==typeof n&&n.length>0?n:"src",l=e.cfg.activeFilePath;return{id:e.id,root:a,..."string"==typeof l&&l.length>0?{activeFilePath:l}:{}}},g=e=>{let t=[];for(let n of l.current){let l=n.a===e?n.b:n.b===e?n.a:null;if(null===l)continue;let s=a.current.find(e=>e.id===l);void 0!==s&&"files"===s.type&&t.push(s)}if(0===t.length)return null;let n=[...t].sort((e,t)=>t.z-e.z),s=n.find(e=>{let t=e.cfg.activeFilePath;return"string"==typeof t&&t.length>0}),i=null!=s?s:n[0];return void 0===i?null:f(i)},v=(e,t)=>{let n=new Set,s=[];for(let i of l.current){if(s.length>=16)break;let l=i.a===e?i.b:i.b===e?i.a:null;if(null===l)continue;let r=a.current.find(e=>e.id===l);if(void 0===r||"connector"!==r.type||r.cfg.selectedKind!==t)continue;let o=r.cfg.selectedId;"string"==typeof o&&0!==o.length&&(n.has(o)||(n.add(o),s.push(o)))}return s};return{startConnect:(e,a)=>{if(a.preventDefault(),a.stopPropagation(),null!==s.current&&s.current.from===e)return void m();let l=t.current;if(null===l)return;let r=l.getBoundingClientRect(),o=n.current,d=e=>(e-r.left-o.x)/o.zoom,u=e=>(e-r.top-o.y)/o.zoom;null!==i.current&&(i.current(),i.current=null);let h={from:e,x:d(a.clientX),y:u(a.clientY)};s.current=h,c(h);let p=t=>{let n={from:e,x:d(t.clientX),y:u(t.clientY)};s.current=n,c(n)};window.addEventListener("pointermove",p),i.current=()=>{window.removeEventListener("pointermove",p)}},confirmConnect:(e,t)=>{t.preventDefault(),t.stopPropagation();let n=s.current;if(null===n)return;let l=a.current,i=l.find(e=>e.id===n.from),c=l.find(t=>t.id===e);if(void 0!==i&&void 0!==c&&V(i.type,c.type)){o(t=>eo(t,n.from,e)?t:[...t,{id:"".concat(n.from,"~").concat(e),a:n.from,b:e}]),r(e);let t=eu(i,c);null!==t&&(null==d||d(t));let a=ef(i,c);null!==a&&(null==h||h(a))}m()},cancelConnect:m,removeConn:e=>{let t=l.current.find(t=>t.id===e);if(o(t=>t.filter(t=>t.id!==e)),void 0===t)return;let n=a.current,s=n.find(e=>e.id===t.a),i=n.find(e=>e.id===t.b);if(void 0===s||void 0===i)return;let r=eu(s,i);null!==r&&(null==u||u(r));let c=ef(s,i);null!==c&&(null==p||p(c))},connect:(e,t)=>{let n=a.current,l=n.find(t=>t.id===e),s=n.find(e=>e.id===t);void 0!==l&&void 0!==s&&V(l.type,s.type)&&o(n=>eo(n,e,t)?n:[...n,{id:"".concat(e,"~").concat(t),a:e,b:t}])},linkedFilesRoot:e=>{var t,n;return null!=(n=null==(t=g(e))?void 0:t.root)?n:null},linkedFilesContext:g,linkedAllFilesRoots:e=>{let t=new Set,n=[];for(let s of l.current){if(n.length>=16)break;let l=s.a===e?s.b:s.b===e?s.a:null;if(null===l)continue;let i=a.current.find(e=>e.id===l);if(void 0===i)continue;let r=ed(i);null===r||t.has(r)||(t.add(r),n.push(r))}return n},linkedConnectorCapsuleIds:e=>v(e,"capsule"),linkedConnectorCapsuleSetIds:e=>v(e,"capsule-set"),linkedFigmaSnapshotRunIds:e=>{let t=new Set,n=[];for(let s of l.current){if(n.length>=16)break;let l=s.a===e?s.b:s.b===e?s.a:null;if(null===l)continue;let i=a.current.find(e=>e.id===l);if(void 0===i||"figma"!==i.type)continue;let r=i.cfg.snapshotRunId;"string"==typeof r&&0!==r.length&&(t.has(r)||(t.add(r),n.push(r)))}return n},currentFilesContext:()=>{var e;let t=a.current.map(e=>f(e)).filter(e=>null!==e);if(1===t.length)return null!=(e=t[0])?e:null;let n=[...a.current].filter(e=>"files"===e.type).sort((e,t)=>t.z-e.z)[0];return void 0===n?null:f(n)}}}({wsRef:e,viewRef:I,winsRef:k,connsRef:N,connectingRef:S,connectCleanupRef:C,focus:z,setConns:g,setConnecting:x,onScopeBind:o.onScopeBind,onScopeUnbind:o.onScopeUnbind,onConnectorBind:o.onConnectorBind,onConnectorUnbind:o.onConnectorUnbind});return R.current=X,(0,l.useEffect)(()=>()=>{null!==C.current&&(C.current(),C.current=null)},[]),{wins:c,snapPrev:u,palOpen:p,setPalOpen:m,conns:f,connecting:v,view:y,api:{add:F,toggleTool:O,focus:z,close:D,maximize:L,update:A,setSnap:U,commitSnap:_,tileAll:K,splitFront:B,cascade:W,startConnect:H,confirmConnect:J,cancelConnect:X,removeConn:Y,connect:Z,linkedFilesRoot:Q,linkedFilesContext:$,linkedAllFilesRoots:ee,linkedConnectorCapsuleIds:et,linkedConnectorCapsuleSetIds:en,linkedFigmaSnapshotRunIds:ea,currentFilesContext:el,zoomTo:M,resetView:T,panBy:q,rect:P}}}(f,{onScopeBind:x,onScopeUnbind:y,onConnectorBind:(0,l.useCallback)(e=>{let t=m.activeChat;if(void 0===t)return;let n=ep(t),a=function(e,t,n){let a=em(t);if(e.some(e=>em(e)===a))return e;let l=[...e,t];return l.length>n?l.slice(-n):l}(n,e,g.maxLocalKnowledgeSources);a!==n&&(0,$.Cp)(t.id,a).then(e=>{m.replaceChat(e.chat)}).catch(()=>void 0)},[m,g.maxLocalKnowledgeSources]),onConnectorUnbind:(0,l.useCallback)(e=>{var t;let n=m.activeChat;if(void 0===n)return;let a="capsule"===e.kind?"capsule:".concat(e.capsuleId):"set:".concat(e.capsuleSetId),l=(t=ep(n),t.filter(e=>em(e)!==a));(0,$.Cp)(n.id,l.length>0?l:null).then(e=>{m.replaceChat(e.chat)}).catch(()=>void 0)},[m])}),[j,N]=(0,l.useState)(!1),[S,R]=(0,l.useState)(null),[I,E]=(0,l.useState)(!1),M=null!=(r=null==(e=b.wins)?void 0:e.length)?r:0,T=function(e){if(null===e||0===e.length)return null;let t=e[0];for(let n=1;n<e.length;n++){let a=e[n];a.z>t.z&&(t=a)}return t}(b.wins),q=(0,l.useMemo)(()=>(function(e){if(null===e)return new Set;let t=new Set;for(let n of e)!0===es[n.type].tool&&t.add(n.type);return t})(b.wins),[b.wins]),P=(0,l.useMemo)(()=>{var e;return{wins:null!=(e=b.wins)?e:[],active:T,winCount:M}},[b.wins,T,M]),z=(0,l.useCallback)(()=>N(!0),[]),D=(0,l.useCallback)(()=>N(!1),[]),L=(0,l.useCallback)(e=>{N(!1),R(e)},[]),F=(0,l.useCallback)(e=>{R(t=>{if(null!==t){let{__connectFilesId:n,...a}=e,l=b.api.add(t,a);"agents"===t&&null!==l&&"string"==typeof n&&n.length>0&&b.api.connect(l,n)}return null})},[b.api]),O=(0,l.useCallback)(()=>R(null),[]),B=(0,l.useCallback)(()=>E(!1),[]),U=(0,l.useRef)(null),_=(0,l.useCallback)(e=>{U.current=e},[]),H=function(e){var t;let{apply:n}=e,a=null!=(t=e.limit)?t:100,[s,i]=(0,l.useState)(ar),r=(0,l.useRef)(n);r.current=n;let o=(0,l.useRef)(s);o.current=s;let c=(0,l.useCallback)(e=>{i(t=>{let n=[...t.undoStack,e];return{undoStack:n.length>a?n.slice(n.length-a):n,redoStack:[]}})},[a]),d=(0,l.useCallback)(()=>{let e=o.current;if(0===e.undoStack.length)return;let t=e.undoStack[e.undoStack.length-1],n=function(e){switch(e.kind){case"ui.window.move":case"ui.window.resize":case"ui.window.zorder":case"ui.workspace.pan":case"ui.workspace.zoom":case"ui.workspace.fit":case"ui.panel.toggle":case"ui.selection.change":case"ui.tab.switch":return{...e,before:e.after,after:e.before};case"ui.window.close":return{...e,kind:"ui.window.open"};case"ui.window.open":return{...e,kind:"ui.window.close"}}}(t);i({undoStack:e.undoStack.slice(0,-1),redoStack:[...e.redoStack,t]}),r.current(n)},[]),u=(0,l.useCallback)(()=>{let e=o.current;if(0===e.redoStack.length)return;let t=e.redoStack[e.redoStack.length-1];i({undoStack:[...e.undoStack,t],redoStack:e.redoStack.slice(0,-1)}),r.current(t)},[]),h=(0,l.useCallback)(()=>{i(ar)},[]);return(0,l.useMemo)(()=>{let e=s.undoStack[s.undoStack.length-1],t=s.redoStack[s.redoStack.length-1];return{canUndo:s.undoStack.length>0,canRedo:s.redoStack.length>0,undoLabel:void 0!==e?as(e):null,redoLabel:void 0!==t?as(t):null,push:c,undo:d,redo:u,clear:h}},[s,c,d,u,h])}({apply:(0,l.useCallback)(e=>{var t;return t=b.api,void("ui.panel.toggle"===e.kind&&e.panel in es&&t.toggleTool(e.panel))},[b.api])}),J=(0,l.useCallback)(e=>{if(!(e in es))return;let t=q.has(e);b.api.toggleTool(e),H.push({kind:"ui.panel.toggle",panel:e,before:t,after:!t})},[b.api,q,H]),X=(0,l.useCallback)(()=>L("chat"),[L]);!function(e){var t;let{bindings:n,dispatch:a}=e,s=null!=(t=e.platform)?t:function(){if("undefined"==typeof navigator)return"other";let e=navigator.platform||"";return/Mac|iPhone|iPad|iPod/i.test(e)?"mac":"other"}(),i=(0,l.useRef)(a);i.current=a;let r=(0,l.useMemo)(()=>(function(e){let t=new Map;for(let n of e){let e=ai(n.chord),a=t.get(e);void 0!==a?a.push(n.commandId):t.set(e,[n.commandId])}let n=[];for(let[,a]of t)if(a.length>1){let t=e.find(e=>a.includes(e.commandId));void 0!==t&&n.push({chord:t.chord,commandIds:a})}return n})(n),[n]),o=(0,l.useMemo)(()=>n.filter(e=>(function(e){for(let t of al)if(ai(e)===ai(t))return!0;return!1})(e.chord)),[n]);if(r.length>0)throw new ao(r);if(o.length>0)throw new ac(o);(0,l.useEffect)(()=>{function e(e){if(!function(e){if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;let t=e.tagName;return"INPUT"===t||"TEXTAREA"===t||"SELECT"===t}(e.target)){for(let t of n)if(function(e,t,n){if(e.key.toLowerCase()!==t.key.toLowerCase())return!1;let a=function(e,t){let n=new Set;for(let a of e)"cmd"===a?n.add("mac"===t?"meta":"ctrl"):"ctrl"===a?n.add("ctrl"):"alt"===a?n.add("alt"):"shift"===a&&n.add("shift");return n}(t.mod,n);return e.metaKey===a.has("meta")&&e.ctrlKey===a.has("ctrl")&&e.altKey===a.has("alt")&&e.shiftKey===a.has("shift")}(e,t.chord,s)){e.preventDefault(),i.current(t.commandId);return}}}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[n,s]),(0,l.useMemo)(()=>({bindings:n,conflicts:r,reserved:o}),[n,r,o])}({bindings:ad,dispatch:(0,l.useCallback)(e=>{var t;"undo"===e?H.undo():"redo"===e?H.redo():"focus-status"===e&&(null==(t=U.current)||t.focus())},[H])}),(0,l.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&("k"===e.key||"K"===e.key)&&(e.preventDefault(),E(e=>!e))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let Y=(0,l.useMemo)(()=>(function(e,t,n,a,l,s){let i=[];for(let e of iG){let t=es[e];i.push({id:"new-".concat(e),label:"New ".concat(t.title),group:"Create",icon:t.icon,run:()=>n(e)})}for(let e of iX){let n=es[e];i.push({id:"open-".concat(e),label:"Open ".concat(n.title),group:"Tools",icon:n.icon,run:()=>t(e)})}return i.push({id:"tile",label:"Tile all windows",group:"Layout",icon:"tile",run:e.tileAll}),i.push({id:"split",label:"Split front windows",group:"Layout",icon:"split",run:e.splitFront}),i.push({id:"cascade",label:"Cascade windows",group:"Layout",icon:"cascade",run:e.cascade}),i.push({id:"theme",label:"Toggle light / dark theme",group:"View",icon:"light"===a?"moon":"sun",run:l}),i.push({id:"undo",label:null!==s.undoLabel?"Undo: ".concat(s.undoLabel):"Undo (window and panel changes only)",group:"Edit",icon:"back",run:s.undo}),i.push({id:"redo",label:null!==s.redoLabel?"Redo: ".concat(s.redoLabel):"Redo (window and panel changes only)",group:"Edit",icon:"fwd",run:s.redo}),i})(b.api,J,L,u,h,H),[b.api,J,L,u,h,H]),Z=!m.loading&&0===m.models.length,Q=(o=null==(t=m.activeProject)?void 0:t.name,m.loading?"Loading project...":void 0!==o&&o.trim().length>0?o:"No project selected"),ee=void 0!==m.activeProject,et=(null==(n=m.activeProject)?void 0:n.available)===!0,en=(c={loading:m.loading,error:m.error,hasProject:ee,projectAvailable:et,noEligibleModels:m.noEligibleModels}).loading?"Loading shell":void 0!==c.error?"Shell error":c.hasProject?c.projectAvailable?c.noEligibleModels?"Gateway setup required":"Ready":"Project unavailable":"No project selected",ea=function(e){let t=(null!=e?e:[]).filter(e=>"review"===e.type);return 0===t.length?"Open review":t.some(e=>"string"==typeof e.cfg.runId&&e.cfg.runId.length>0)?"Evidence ready":"Review open"}(b.wins),el=void 0!==(d=null==(s=m.activeChat)?void 0:s.branchLabel)&&d.trim().length>0?d:"No branch selected",eg=j?(0,a.jsx)(nI,{types:es,order:iG,onAdd:L,onClose:D}):null;return(0,a.jsx)(i,{value:m,children:(0,a.jsx)(k.Provider,{value:P,children:(0,a.jsxs)("div",{className:"app",children:[(0,a.jsx)("h1",{className:"visually-hidden",children:"Keiko workspace"}),(0,a.jsx)(A,{mode:p.mode,projectName:Q,onModeChange:p.setMode,openPalette:z,onTileAll:b.api.tileAll,onSplitFront:b.api.splitFront,onCascade:b.api.cascade}),(0,a.jsxs)("div",{className:"mid",children:[(0,a.jsx)(K,{openTools:q,onTool:J,onNewChat:X,theme:u,onToggleTheme:h}),(0,a.jsx)("div",{className:"stage",children:(0,a.jsx)(nh,{ws:b,wsRef:f,openPalette:z,palette:eg})}),(0,a.jsx)(W,{openTools:q,onTool:J})]}),(0,a.jsx)(C,{winCount:M,mode:p.mode,selectedModel:m.selectedModel,projectName:Q,branchLabel:el,shellStatusLabel:en,evidenceStatusLabel:ea,statusRef:_}),null!==S&&(0,a.jsx)(nR,{type:S,types:es,filesContext:b.api.currentFilesContext(),onConfirm:F,onClose:O}),I&&(0,a.jsx)(np,{commands:Y,onClose:B}),Z?(0,a.jsx)(nf,{}):null,(0,a.jsx)(iV,{})]})})})}function iZ(){let[e,t]=(0,l.useState)(!1);return((0,l.useEffect)(()=>{t(!0)},[]),(0,l.useEffect)(()=>{!function(){if(!("undefined"!=typeof navigator&&"serviceWorker"in navigator))return;let e=navigator.serviceWorker;try{e.register("/sw.js",{scope:"/"}).catch(e=>{})}catch(e){}}()},[]),e)?(0,a.jsx)(j,{children:(0,a.jsx)(iY,{})}):(0,a.jsx)("div",{className:"app","aria-hidden":"true"})}function iQ(){return(0,a.jsx)(iZ,{})}},6923:(e,t,n)=>{Promise.resolve().then(n.bind(n,4723))},9389:(e,t,n)=>{"use strict";n.d(t,{FG:()=>m,H9:()=>v,KS:()=>x,Qi:()=>f,R3:()=>o,Tq:()=>p,WM:()=>d,qY:()=>c,r:()=>h,rw:()=>g,xY:()=>y,xr:()=>r,yN:()=>u});var a=n(2982);function l(e,t){let n={Accept:"application/json"};return null!=t&&(n["Content-Type"]="application/json"),"GET"!==e&&"HEAD"!==e&&(n["X-Keiko-CSRF"]="1"),n}async function s(e){try{let t=await e.json();return{code:t.error.code,message:t.error.message}}catch(t){return{code:"INTERNAL",message:"HTTP ".concat(e.status.toString())}}}async function i(e,t){var n;let i=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),r=await fetch(e,{...t,headers:l(i,null==t?void 0:t.body)});if(!r.ok){let{code:e,message:t}=await s(r);throw new a.hD(e,t,r.status)}if(204!==r.status)return r.json()}async function r(){return i("/api/local-knowledge/capsules")}async function o(){return i("/api/local-knowledge/capsule-sets")}async function c(e){return i("/api/local-knowledge/capsules",{method:"POST",body:JSON.stringify(e)})}async function d(e){return i("/api/local-knowledge/capsule-sets",{method:"POST",body:JSON.stringify(e)})}async function u(e,t){return i("/api/local-knowledge/capsules/".concat(encodeURIComponent(e)),{method:"PATCH",body:JSON.stringify(t)})}async function h(e){return i("/api/local-knowledge/capsules/".concat(encodeURIComponent(e),"/index"),{method:"POST",body:JSON.stringify({confirm:!0})})}async function p(e){return i("/api/local-knowledge/capsules/".concat(encodeURIComponent(e),"/index"),{method:"DELETE",body:JSON.stringify({confirm:!0})})}async function m(e,t,n){return i("/api/local-knowledge/capsules/".concat(encodeURIComponent(e),"/connection"),{method:"POST",body:JSON.stringify({scope:t,displayName:n})})}async function f(e){return i("/api/local-knowledge/capsules/".concat(encodeURIComponent(e),"/connection"),{method:"DELETE",body:JSON.stringify({confirm:!0})})}async function g(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:fetch,n="/api/local-knowledge/capsules/".concat(encodeURIComponent(e)),i=await t(n,{headers:l("GET",void 0)});if(!i.ok){let{code:e,message:t}=await s(i);throw new a.hD(e,t,i.status)}return i.json()}async function v(e){return i("/api/local-knowledge/capsules/".concat(encodeURIComponent(e)),{method:"DELETE",body:JSON.stringify({deleteIndex:!0,deleteSources:!1})})}async function x(e){return i("/api/local-knowledge/capsules/".concat(encodeURIComponent(e),"/reindex"),{method:"POST",body:JSON.stringify({mode:"changed-files"})})}async function y(e){return i("/api/local-knowledge/capsules/".concat(encodeURIComponent(e),"/reindex"),{method:"POST",body:JSON.stringify({mode:"repair-failed"})})}}}]);