@oscharko-dev/keiko 0.2.7 → 0.2.9

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 (747) hide show
  1. package/README.md +63 -1
  2. package/dist/ui/csp-hashes.json +16 -15
  3. package/dist/ui/static/404.html +1 -1
  4. package/dist/ui/static/__next.__PAGE__.txt +2 -2
  5. package/dist/ui/static/__next._full.txt +3 -3
  6. package/dist/ui/static/__next._head.txt +1 -1
  7. package/dist/ui/static/__next._index.txt +2 -2
  8. package/dist/ui/static/__next._tree.txt +2 -2
  9. package/dist/ui/static/_next/static/chunks/{3868.ea5f0ddf5e222dba.js → 3868.e696705096570012.js} +1 -1
  10. package/dist/ui/static/_next/static/chunks/4664.01816161d4b14377.js +1 -0
  11. package/dist/ui/static/_next/static/chunks/4666.f3269a33692c9356.js +1 -0
  12. package/dist/ui/static/_next/static/chunks/7224.f9cb1fa496edbc51.js +1 -0
  13. package/dist/ui/static/_next/static/chunks/{3170.e25f90ed08f303e3.js → 7800.38d2bc697871471d.js} +2 -2
  14. package/dist/ui/static/_next/static/chunks/8296.6be6ff3991e15b05.js +1 -0
  15. package/dist/ui/static/_next/static/chunks/8395.e30ea9a63eb35cb3.js +1 -0
  16. package/dist/ui/static/_next/static/chunks/8776.c01a1d09c42a68f9.js +3 -0
  17. package/dist/ui/static/_next/static/chunks/8824-7bd1fafeeeda68c2.js +102 -0
  18. package/dist/ui/static/_next/static/chunks/8835-b68c3abd8ddcb452.js +1 -0
  19. package/dist/ui/static/_next/static/chunks/webpack-4e37711fe87dbc9e.js +1 -0
  20. package/dist/ui/static/_next/static/css/5881ca0ca97f8d4f.css +3 -0
  21. package/dist/ui/static/_not-found/__next._full.txt +2 -2
  22. package/dist/ui/static/_not-found/__next._head.txt +1 -1
  23. package/dist/ui/static/_not-found/__next._index.txt +2 -2
  24. package/dist/ui/static/_not-found/__next._not-found.__PAGE__.txt +1 -1
  25. package/dist/ui/static/_not-found/__next._not-found.txt +1 -1
  26. package/dist/ui/static/_not-found/__next._tree.txt +2 -2
  27. package/dist/ui/static/_not-found.html +1 -1
  28. package/dist/ui/static/_not-found.txt +2 -2
  29. package/dist/ui/static/index.html +1 -1
  30. package/dist/ui/static/index.txt +3 -3
  31. package/dist/ui/static/keiko-playback-worklet.js +1 -0
  32. package/dist/ui/static/launch/__next._full.txt +3 -3
  33. package/dist/ui/static/launch/__next._head.txt +1 -1
  34. package/dist/ui/static/launch/__next._index.txt +2 -2
  35. package/dist/ui/static/launch/__next._tree.txt +2 -2
  36. package/dist/ui/static/launch/__next.launch.__PAGE__.txt +2 -2
  37. package/dist/ui/static/launch/__next.launch.txt +1 -1
  38. package/dist/ui/static/launch.html +1 -1
  39. package/dist/ui/static/launch.txt +3 -3
  40. package/dist/ui/static/local-knowledge/__next._full.txt +3 -3
  41. package/dist/ui/static/local-knowledge/__next._head.txt +1 -1
  42. package/dist/ui/static/local-knowledge/__next._index.txt +2 -2
  43. package/dist/ui/static/local-knowledge/__next._tree.txt +2 -2
  44. package/dist/ui/static/local-knowledge/__next.local-knowledge.__PAGE__.txt +2 -2
  45. package/dist/ui/static/local-knowledge/__next.local-knowledge.txt +1 -1
  46. package/dist/ui/static/local-knowledge/capsule/__next._full.txt +3 -3
  47. package/dist/ui/static/local-knowledge/capsule/__next._head.txt +1 -1
  48. package/dist/ui/static/local-knowledge/capsule/__next._index.txt +2 -2
  49. package/dist/ui/static/local-knowledge/capsule/__next._tree.txt +2 -2
  50. package/dist/ui/static/local-knowledge/capsule/__next.local-knowledge.capsule.__PAGE__.txt +2 -2
  51. package/dist/ui/static/local-knowledge/capsule/__next.local-knowledge.capsule.txt +1 -1
  52. package/dist/ui/static/local-knowledge/capsule/__next.local-knowledge.txt +1 -1
  53. package/dist/ui/static/local-knowledge/capsule.html +1 -1
  54. package/dist/ui/static/local-knowledge/capsule.txt +3 -3
  55. package/dist/ui/static/local-knowledge.html +1 -1
  56. package/dist/ui/static/local-knowledge.txt +3 -3
  57. package/dist/ui/static/memoriaviva/__next._full.txt +2 -2
  58. package/dist/ui/static/memoriaviva/__next._head.txt +1 -1
  59. package/dist/ui/static/memoriaviva/__next._index.txt +2 -2
  60. package/dist/ui/static/memoriaviva/__next._tree.txt +2 -2
  61. package/dist/ui/static/memoriaviva/__next.memoriaviva.__PAGE__.txt +1 -1
  62. package/dist/ui/static/memoriaviva/__next.memoriaviva.txt +1 -1
  63. package/dist/ui/static/memoriaviva/consolidation/__next._full.txt +2 -2
  64. package/dist/ui/static/memoriaviva/consolidation/__next._head.txt +1 -1
  65. package/dist/ui/static/memoriaviva/consolidation/__next._index.txt +2 -2
  66. package/dist/ui/static/memoriaviva/consolidation/__next._tree.txt +2 -2
  67. package/dist/ui/static/memoriaviva/consolidation/__next.memoriaviva.consolidation.__PAGE__.txt +1 -1
  68. package/dist/ui/static/memoriaviva/consolidation/__next.memoriaviva.consolidation.txt +1 -1
  69. package/dist/ui/static/memoriaviva/consolidation/__next.memoriaviva.txt +1 -1
  70. package/dist/ui/static/memoriaviva/consolidation.html +1 -1
  71. package/dist/ui/static/memoriaviva/consolidation.txt +2 -2
  72. package/dist/ui/static/memoriaviva/detail/__next._full.txt +2 -2
  73. package/dist/ui/static/memoriaviva/detail/__next._head.txt +1 -1
  74. package/dist/ui/static/memoriaviva/detail/__next._index.txt +2 -2
  75. package/dist/ui/static/memoriaviva/detail/__next._tree.txt +2 -2
  76. package/dist/ui/static/memoriaviva/detail/__next.memoriaviva.detail.__PAGE__.txt +1 -1
  77. package/dist/ui/static/memoriaviva/detail/__next.memoriaviva.detail.txt +1 -1
  78. package/dist/ui/static/memoriaviva/detail/__next.memoriaviva.txt +1 -1
  79. package/dist/ui/static/memoriaviva/detail.html +1 -1
  80. package/dist/ui/static/memoriaviva/detail.txt +2 -2
  81. package/dist/ui/static/memoriaviva/review-queue/__next._full.txt +2 -2
  82. package/dist/ui/static/memoriaviva/review-queue/__next._head.txt +1 -1
  83. package/dist/ui/static/memoriaviva/review-queue/__next._index.txt +2 -2
  84. package/dist/ui/static/memoriaviva/review-queue/__next._tree.txt +2 -2
  85. package/dist/ui/static/memoriaviva/review-queue/__next.memoriaviva.review-queue.__PAGE__.txt +1 -1
  86. package/dist/ui/static/memoriaviva/review-queue/__next.memoriaviva.review-queue.txt +1 -1
  87. package/dist/ui/static/memoriaviva/review-queue/__next.memoriaviva.txt +1 -1
  88. package/dist/ui/static/memoriaviva/review-queue.html +1 -1
  89. package/dist/ui/static/memoriaviva/review-queue.txt +2 -2
  90. package/dist/ui/static/memoriaviva.html +1 -1
  91. package/dist/ui/static/memoriaviva.txt +2 -2
  92. package/node_modules/@oscharko-dev/keiko-cli/dist/.tsbuildinfo +1 -1
  93. package/node_modules/@oscharko-dev/keiko-cli/dist/install-layout.d.ts +0 -1
  94. package/node_modules/@oscharko-dev/keiko-cli/dist/install-layout.d.ts.map +1 -1
  95. package/node_modules/@oscharko-dev/keiko-cli/dist/install-layout.js +1 -1
  96. package/node_modules/@oscharko-dev/keiko-cli/dist/launcher-paths.d.ts +0 -1
  97. package/node_modules/@oscharko-dev/keiko-cli/dist/launcher-paths.d.ts.map +1 -1
  98. package/node_modules/@oscharko-dev/keiko-cli/dist/launcher-paths.js +1 -1
  99. package/node_modules/@oscharko-dev/keiko-cli/dist/lifecycle.d.ts.map +1 -1
  100. package/node_modules/@oscharko-dev/keiko-cli/dist/lifecycle.js +33 -7
  101. package/node_modules/@oscharko-dev/keiko-cli/dist/state-paths.d.ts +0 -1
  102. package/node_modules/@oscharko-dev/keiko-cli/dist/state-paths.d.ts.map +1 -1
  103. package/node_modules/@oscharko-dev/keiko-cli/dist/state-paths.js +1 -1
  104. package/node_modules/@oscharko-dev/keiko-cli/dist/ui.d.ts +0 -2
  105. package/node_modules/@oscharko-dev/keiko-cli/dist/ui.d.ts.map +1 -1
  106. package/node_modules/@oscharko-dev/keiko-cli/dist/ui.js +2 -2
  107. package/node_modules/@oscharko-dev/keiko-cli/package.json +14 -14
  108. package/node_modules/@oscharko-dev/keiko-contracts/dist/.tsbuildinfo +1 -1
  109. package/node_modules/@oscharko-dev/keiko-contracts/dist/bff-wire.d.ts +86 -19
  110. package/node_modules/@oscharko-dev/keiko-contracts/dist/bff-wire.d.ts.map +1 -1
  111. package/node_modules/@oscharko-dev/keiko-contracts/dist/command-runner.d.ts +81 -0
  112. package/node_modules/@oscharko-dev/keiko-contracts/dist/command-runner.d.ts.map +1 -0
  113. package/node_modules/@oscharko-dev/keiko-contracts/dist/command-runner.js +209 -0
  114. package/node_modules/@oscharko-dev/keiko-contracts/dist/container-runtime.d.ts +125 -0
  115. package/node_modules/@oscharko-dev/keiko-contracts/dist/container-runtime.d.ts.map +1 -0
  116. package/node_modules/@oscharko-dev/keiko-contracts/dist/container-runtime.js +287 -0
  117. package/node_modules/@oscharko-dev/keiko-contracts/dist/context-engineering.js +2 -2
  118. package/node_modules/@oscharko-dev/keiko-contracts/dist/discussion-intelligence.d.ts +70 -0
  119. package/node_modules/@oscharko-dev/keiko-contracts/dist/discussion-intelligence.d.ts.map +1 -0
  120. package/node_modules/@oscharko-dev/keiko-contracts/dist/discussion-intelligence.js +440 -0
  121. package/node_modules/@oscharko-dev/keiko-contracts/dist/editor-agent-governance.d.ts +65 -0
  122. package/node_modules/@oscharko-dev/keiko-contracts/dist/editor-agent-governance.d.ts.map +1 -0
  123. package/node_modules/@oscharko-dev/keiko-contracts/dist/editor-agent-governance.js +180 -0
  124. package/node_modules/@oscharko-dev/keiko-contracts/dist/editor-agent.d.ts +29 -1
  125. package/node_modules/@oscharko-dev/keiko-contracts/dist/editor-agent.d.ts.map +1 -1
  126. package/node_modules/@oscharko-dev/keiko-contracts/dist/editor-agent.js +183 -6
  127. package/node_modules/@oscharko-dev/keiko-contracts/dist/editor-builtin-capabilities.d.ts +13 -0
  128. package/node_modules/@oscharko-dev/keiko-contracts/dist/editor-builtin-capabilities.d.ts.map +1 -0
  129. package/node_modules/@oscharko-dev/keiko-contracts/dist/editor-builtin-capabilities.js +135 -0
  130. package/node_modules/@oscharko-dev/keiko-contracts/dist/editor-language-mode-map.d.ts +11 -0
  131. package/node_modules/@oscharko-dev/keiko-contracts/dist/editor-language-mode-map.d.ts.map +1 -0
  132. package/node_modules/@oscharko-dev/keiko-contracts/dist/editor-language-mode-map.js +89 -0
  133. package/node_modules/@oscharko-dev/keiko-contracts/dist/editor-layout.d.ts +37 -0
  134. package/node_modules/@oscharko-dev/keiko-contracts/dist/editor-layout.d.ts.map +1 -1
  135. package/node_modules/@oscharko-dev/keiko-contracts/dist/editor-layout.js +125 -8
  136. package/node_modules/@oscharko-dev/keiko-contracts/dist/editor-workspace-path.d.ts +20 -0
  137. package/node_modules/@oscharko-dev/keiko-contracts/dist/editor-workspace-path.d.ts.map +1 -0
  138. package/node_modules/@oscharko-dev/keiko-contracts/dist/editor-workspace-path.js +133 -0
  139. package/node_modules/@oscharko-dev/keiko-contracts/dist/evidence.d.ts +3 -1
  140. package/node_modules/@oscharko-dev/keiko-contracts/dist/evidence.d.ts.map +1 -1
  141. package/node_modules/@oscharko-dev/keiko-contracts/dist/gateway.d.ts +72 -3
  142. package/node_modules/@oscharko-dev/keiko-contracts/dist/gateway.d.ts.map +1 -1
  143. package/node_modules/@oscharko-dev/keiko-contracts/dist/gateway.js +73 -3
  144. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-commit-intent.d.ts +28 -0
  145. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-commit-intent.d.ts.map +1 -0
  146. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-commit-intent.js +155 -0
  147. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-commit-policy.d.ts +29 -0
  148. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-commit-policy.d.ts.map +1 -0
  149. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-commit-policy.js +173 -0
  150. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-delivery-action-sheet.d.ts +157 -0
  151. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-delivery-action-sheet.d.ts.map +1 -0
  152. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-delivery-action-sheet.js +430 -0
  153. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-delivery-evidence.d.ts +92 -0
  154. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-delivery-evidence.d.ts.map +1 -0
  155. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-delivery-evidence.js +272 -0
  156. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-delivery-policy.d.ts +40 -0
  157. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-delivery-policy.d.ts.map +1 -0
  158. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-delivery-policy.js +183 -0
  159. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-delivery-provider.d.ts +53 -0
  160. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-delivery-provider.d.ts.map +1 -0
  161. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-delivery-provider.js +96 -0
  162. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-delivery.d.ts +202 -0
  163. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-delivery.d.ts.map +1 -0
  164. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-delivery.js +410 -0
  165. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-history.d.ts +27 -0
  166. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-history.d.ts.map +1 -0
  167. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-history.js +73 -0
  168. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-merge.d.ts +67 -0
  169. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-merge.d.ts.map +1 -0
  170. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-merge.js +323 -0
  171. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-pull-request.d.ts +112 -0
  172. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-pull-request.d.ts.map +1 -0
  173. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-pull-request.js +351 -0
  174. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-repository-agent.d.ts +46 -0
  175. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-repository-agent.d.ts.map +1 -0
  176. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-repository-agent.js +198 -0
  177. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-repository-summary.d.ts +54 -0
  178. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-repository-summary.d.ts.map +1 -0
  179. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-repository-summary.js +105 -0
  180. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-repository.d.ts +60 -0
  181. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-repository.d.ts.map +1 -0
  182. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-repository.js +106 -0
  183. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-sync.d.ts +49 -0
  184. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-sync.d.ts.map +1 -0
  185. package/node_modules/@oscharko-dev/keiko-contracts/dist/git-sync.js +110 -0
  186. package/node_modules/@oscharko-dev/keiko-contracts/dist/index.d.ts +63 -9
  187. package/node_modules/@oscharko-dev/keiko-contracts/dist/index.d.ts.map +1 -1
  188. package/node_modules/@oscharko-dev/keiko-contracts/dist/index.js +33 -6
  189. package/node_modules/@oscharko-dev/keiko-contracts/dist/lsp-process.d.ts +38 -0
  190. package/node_modules/@oscharko-dev/keiko-contracts/dist/lsp-process.d.ts.map +1 -0
  191. package/node_modules/@oscharko-dev/keiko-contracts/dist/lsp-process.js +103 -0
  192. package/node_modules/@oscharko-dev/keiko-contracts/dist/prompt-enhancer-analyzer.d.ts.map +1 -1
  193. package/node_modules/@oscharko-dev/keiko-contracts/dist/prompt-enhancer-analyzer.js +198 -22
  194. package/node_modules/@oscharko-dev/keiko-contracts/dist/runtime-capabilities.d.ts +44 -0
  195. package/node_modules/@oscharko-dev/keiko-contracts/dist/runtime-capabilities.d.ts.map +1 -0
  196. package/node_modules/@oscharko-dev/keiko-contracts/dist/runtime-capabilities.js +141 -0
  197. package/node_modules/@oscharko-dev/keiko-contracts/dist/task-workspace.d.ts +302 -0
  198. package/node_modules/@oscharko-dev/keiko-contracts/dist/task-workspace.d.ts.map +1 -0
  199. package/node_modules/@oscharko-dev/keiko-contracts/dist/task-workspace.js +1236 -0
  200. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-action-intent.d.ts +86 -0
  201. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-action-intent.d.ts.map +1 -0
  202. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-action-intent.js +387 -0
  203. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-playback.d.ts +50 -0
  204. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-playback.d.ts.map +1 -0
  205. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-playback.js +240 -0
  206. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-protocol.d.ts +165 -0
  207. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-protocol.d.ts.map +1 -0
  208. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-protocol.js +312 -0
  209. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-transcript.d.ts +57 -0
  210. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-transcript.d.ts.map +1 -0
  211. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-transcript.js +221 -0
  212. package/node_modules/@oscharko-dev/keiko-contracts/package.json +5 -1
  213. package/node_modules/@oscharko-dev/keiko-evaluations/dist/.tsbuildinfo +1 -1
  214. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/correction.d.ts +5 -0
  215. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/correction.d.ts.map +1 -0
  216. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/correction.js +53 -0
  217. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/index.d.ts +5 -0
  218. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/index.d.ts.map +1 -0
  219. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/index.js +17 -0
  220. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/no-voice.d.ts +6 -0
  221. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/no-voice.d.ts.map +1 -0
  222. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/no-voice.js +79 -0
  223. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/voice.d.ts +5 -0
  224. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/voice.d.ts.map +1 -0
  225. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/voice.js +57 -0
  226. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/index.d.ts +6 -0
  227. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/index.d.ts.map +1 -0
  228. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/index.js +9 -0
  229. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/render.d.ts +3 -0
  230. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/render.d.ts.map +1 -0
  231. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/render.js +49 -0
  232. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/runner.d.ts +13 -0
  233. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/runner.d.ts.map +1 -0
  234. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/runner.js +80 -0
  235. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/scorer.d.ts +8 -0
  236. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/scorer.d.ts.map +1 -0
  237. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/scorer.js +225 -0
  238. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/types.d.ts +71 -0
  239. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/types.d.ts.map +1 -0
  240. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/types.js +29 -0
  241. package/node_modules/@oscharko-dev/keiko-evaluations/dist/index.d.ts +2 -0
  242. package/node_modules/@oscharko-dev/keiko-evaluations/dist/index.d.ts.map +1 -1
  243. package/node_modules/@oscharko-dev/keiko-evaluations/dist/index.js +6 -0
  244. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/adversarial.d.ts +9 -0
  245. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/adversarial.d.ts.map +1 -0
  246. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/adversarial.js +163 -0
  247. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/index.d.ts +5 -0
  248. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/index.d.ts.map +1 -0
  249. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/index.js +17 -0
  250. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/no-voice.d.ts +5 -0
  251. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/no-voice.d.ts.map +1 -0
  252. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/no-voice.js +37 -0
  253. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/segment.d.ts +11 -0
  254. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/segment.d.ts.map +1 -0
  255. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/segment.js +25 -0
  256. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/voice.d.ts +6 -0
  257. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/voice.d.ts.map +1 -0
  258. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/voice.js +74 -0
  259. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/index.d.ts +6 -0
  260. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/index.d.ts.map +1 -0
  261. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/index.js +10 -0
  262. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/render.d.ts +3 -0
  263. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/render.d.ts.map +1 -0
  264. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/render.js +49 -0
  265. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/runner.d.ts +14 -0
  266. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/runner.d.ts.map +1 -0
  267. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/runner.js +149 -0
  268. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/scorer.d.ts +8 -0
  269. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/scorer.d.ts.map +1 -0
  270. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/scorer.js +247 -0
  271. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/types.d.ts +82 -0
  272. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/types.d.ts.map +1 -0
  273. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/types.js +30 -0
  274. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/capability.d.ts +4 -0
  275. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/capability.d.ts.map +1 -0
  276. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/capability.js +26 -0
  277. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/full-realtime.d.ts +3 -0
  278. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/full-realtime.d.ts.map +1 -0
  279. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/full-realtime.js +36 -0
  280. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/index.d.ts +5 -0
  281. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/index.d.ts.map +1 -0
  282. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/index.js +21 -0
  283. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/no-voice.d.ts +3 -0
  284. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/no-voice.d.ts.map +1 -0
  285. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/no-voice.js +33 -0
  286. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/privacy.d.ts +3 -0
  287. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/privacy.d.ts.map +1 -0
  288. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/privacy.js +69 -0
  289. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/speech-output.d.ts +3 -0
  290. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/speech-output.d.ts.map +1 -0
  291. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/speech-output.js +32 -0
  292. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/stt-only.d.ts +3 -0
  293. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/stt-only.d.ts.map +1 -0
  294. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/stt-only.js +35 -0
  295. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/index.d.ts +10 -0
  296. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/index.d.ts.map +1 -0
  297. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/index.js +14 -0
  298. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/metrics.d.ts +10 -0
  299. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/metrics.d.ts.map +1 -0
  300. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/metrics.js +142 -0
  301. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/privacy.d.ts +9 -0
  302. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/privacy.d.ts.map +1 -0
  303. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/privacy.js +100 -0
  304. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/profiles.d.ts +15 -0
  305. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/profiles.d.ts.map +1 -0
  306. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/profiles.js +58 -0
  307. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/render.d.ts +3 -0
  308. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/render.d.ts.map +1 -0
  309. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/render.js +53 -0
  310. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/runner.d.ts +13 -0
  311. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/runner.d.ts.map +1 -0
  312. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/runner.js +141 -0
  313. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/scorer.d.ts +8 -0
  314. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/scorer.d.ts.map +1 -0
  315. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/scorer.js +323 -0
  316. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/types.d.ts +149 -0
  317. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/types.d.ts.map +1 -0
  318. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/types.js +45 -0
  319. package/node_modules/@oscharko-dev/keiko-evaluations/package.json +9 -9
  320. package/node_modules/@oscharko-dev/keiko-evidence/dist/.tsbuildinfo +1 -1
  321. package/node_modules/@oscharko-dev/keiko-evidence/package.json +4 -4
  322. package/node_modules/@oscharko-dev/keiko-harness/dist/.tsbuildinfo +1 -1
  323. package/node_modules/@oscharko-dev/keiko-harness/package.json +6 -6
  324. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/.tsbuildinfo +1 -1
  325. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/parsers/html-parser.js +2 -2
  326. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/retrieval/scoped-vector-search.js +2 -2
  327. package/node_modules/@oscharko-dev/keiko-local-knowledge/package.json +6 -6
  328. package/node_modules/@oscharko-dev/keiko-memory-capture/package.json +3 -3
  329. package/node_modules/@oscharko-dev/keiko-memory-consolidation/package.json +3 -3
  330. package/node_modules/@oscharko-dev/keiko-memory-governance/package.json +3 -3
  331. package/node_modules/@oscharko-dev/keiko-memory-retrieval/package.json +3 -3
  332. package/node_modules/@oscharko-dev/keiko-memory-vault/dist/.tsbuildinfo +1 -1
  333. package/node_modules/@oscharko-dev/keiko-memory-vault/package.json +3 -3
  334. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/.tsbuildinfo +1 -1
  335. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/capabilities.d.ts +8 -1
  336. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/capabilities.d.ts.map +1 -1
  337. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/capabilities.js +97 -1
  338. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/config.d.ts.map +1 -1
  339. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/config.js +215 -2
  340. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/http.d.ts +1 -0
  341. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/http.d.ts.map +1 -1
  342. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/http.js +51 -5
  343. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/index.d.ts +6 -3
  344. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/index.d.ts.map +1 -1
  345. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/index.js +5 -2
  346. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/model-selection.d.ts +10 -2
  347. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/model-selection.d.ts.map +1 -1
  348. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/model-selection.js +86 -1
  349. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/promptEnhancer/generator.d.ts.map +1 -1
  350. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/promptEnhancer/generator.js +417 -14
  351. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/realtime-voice-adapter.d.ts +49 -0
  352. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/realtime-voice-adapter.d.ts.map +1 -0
  353. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/realtime-voice-adapter.js +306 -0
  354. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/speech-to-text-adapter.d.ts +33 -0
  355. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/speech-to-text-adapter.d.ts.map +1 -0
  356. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/speech-to-text-adapter.js +238 -0
  357. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/text-to-speech-adapter.d.ts +56 -0
  358. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/text-to-speech-adapter.d.ts.map +1 -0
  359. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/text-to-speech-adapter.js +240 -0
  360. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/types.d.ts +13 -3
  361. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/types.d.ts.map +1 -1
  362. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/types.js +1 -1
  363. package/node_modules/@oscharko-dev/keiko-model-gateway/package.json +3 -3
  364. package/node_modules/@oscharko-dev/keiko-quality-intelligence/dist/.tsbuildinfo +1 -1
  365. package/node_modules/@oscharko-dev/keiko-quality-intelligence/package.json +3 -3
  366. package/node_modules/@oscharko-dev/keiko-sandbox/dist/.tsbuildinfo +1 -1
  367. package/node_modules/@oscharko-dev/keiko-sandbox/package.json +2 -2
  368. package/node_modules/@oscharko-dev/keiko-sdk/dist/.tsbuildinfo +1 -1
  369. package/node_modules/@oscharko-dev/keiko-sdk/package.json +9 -9
  370. package/node_modules/@oscharko-dev/keiko-security/dist/.tsbuildinfo +1 -1
  371. package/node_modules/@oscharko-dev/keiko-security/dist/redaction.d.ts.map +1 -1
  372. package/node_modules/@oscharko-dev/keiko-security/dist/redaction.js +12 -0
  373. package/node_modules/@oscharko-dev/keiko-security/package.json +2 -2
  374. package/node_modules/@oscharko-dev/keiko-server/dist/.tsbuildinfo +1 -1
  375. package/node_modules/@oscharko-dev/keiko-server/dist/chat-handlers.d.ts +18 -2
  376. package/node_modules/@oscharko-dev/keiko-server/dist/chat-handlers.d.ts.map +1 -1
  377. package/node_modules/@oscharko-dev/keiko-server/dist/chat-handlers.js +185 -3
  378. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner-errors.d.ts +17 -0
  379. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner-errors.d.ts.map +1 -0
  380. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner-errors.js +37 -0
  381. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner-evidence.d.ts +23 -0
  382. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner-evidence.d.ts.map +1 -0
  383. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner-evidence.js +69 -0
  384. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner-routes.d.ts +7 -0
  385. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner-routes.d.ts.map +1 -0
  386. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner-routes.js +175 -0
  387. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner.d.ts +29 -0
  388. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner.d.ts.map +1 -0
  389. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner.js +348 -0
  390. package/node_modules/@oscharko-dev/keiko-server/dist/conversation-prompt.d.ts +2 -2
  391. package/node_modules/@oscharko-dev/keiko-server/dist/conversation-prompt.d.ts.map +1 -1
  392. package/node_modules/@oscharko-dev/keiko-server/dist/conversation-prompt.js +17 -1
  393. package/node_modules/@oscharko-dev/keiko-server/dist/csp.d.ts.map +1 -1
  394. package/node_modules/@oscharko-dev/keiko-server/dist/csp.js +3 -0
  395. package/node_modules/@oscharko-dev/keiko-server/dist/deps.d.ts +28 -1
  396. package/node_modules/@oscharko-dev/keiko-server/dist/deps.d.ts.map +1 -1
  397. package/node_modules/@oscharko-dev/keiko-server/dist/deps.js +288 -13
  398. package/node_modules/@oscharko-dev/keiko-server/dist/discussion-prompt.d.ts +4 -0
  399. package/node_modules/@oscharko-dev/keiko-server/dist/discussion-prompt.d.ts.map +1 -0
  400. package/node_modules/@oscharko-dev/keiko-server/dist/discussion-prompt.js +19 -0
  401. package/node_modules/@oscharko-dev/keiko-server/dist/editor/agentActionAudit.d.ts +18 -0
  402. package/node_modules/@oscharko-dev/keiko-server/dist/editor/agentActionAudit.d.ts.map +1 -0
  403. package/node_modules/@oscharko-dev/keiko-server/dist/editor/agentActionAudit.js +80 -0
  404. package/node_modules/@oscharko-dev/keiko-server/dist/editor/agentRoutes.d.ts +1 -0
  405. package/node_modules/@oscharko-dev/keiko-server/dist/editor/agentRoutes.d.ts.map +1 -1
  406. package/node_modules/@oscharko-dev/keiko-server/dist/editor/agentRoutes.js +292 -55
  407. package/node_modules/@oscharko-dev/keiko-server/dist/editor/agentSessionRegistry.d.ts +35 -0
  408. package/node_modules/@oscharko-dev/keiko-server/dist/editor/agentSessionRegistry.d.ts.map +1 -0
  409. package/node_modules/@oscharko-dev/keiko-server/dist/editor/agentSessionRegistry.js +243 -0
  410. package/node_modules/@oscharko-dev/keiko-server/dist/editor/completionRoutes.d.ts.map +1 -1
  411. package/node_modules/@oscharko-dev/keiko-server/dist/editor/completionRoutes.js +5 -10
  412. package/node_modules/@oscharko-dev/keiko-server/dist/editor/languageRoutes.d.ts +12 -1
  413. package/node_modules/@oscharko-dev/keiko-server/dist/editor/languageRoutes.d.ts.map +1 -1
  414. package/node_modules/@oscharko-dev/keiko-server/dist/editor/languageRoutes.js +71 -8
  415. package/node_modules/@oscharko-dev/keiko-server/dist/editor/languageService.d.ts +3 -2
  416. package/node_modules/@oscharko-dev/keiko-server/dist/editor/languageService.d.ts.map +1 -1
  417. package/node_modules/@oscharko-dev/keiko-server/dist/editor/languageService.js +41 -3
  418. package/node_modules/@oscharko-dev/keiko-server/dist/editor/languageServiceHost.d.ts.map +1 -1
  419. package/node_modules/@oscharko-dev/keiko-server/dist/editor/languageServiceHost.js +2 -2
  420. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/hostLanguageOperation.d.ts +17 -0
  421. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/hostLanguageOperation.d.ts.map +1 -0
  422. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/hostLanguageOperation.js +436 -0
  423. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/hostLanguageProviders.d.ts +26 -0
  424. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/hostLanguageProviders.d.ts.map +1 -0
  425. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/hostLanguageProviders.js +161 -0
  426. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspFrameCodec.d.ts +13 -0
  427. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspFrameCodec.d.ts.map +1 -0
  428. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspFrameCodec.js +164 -0
  429. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspJsonRpcClient.d.ts +34 -0
  430. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspJsonRpcClient.d.ts.map +1 -0
  431. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspJsonRpcClient.js +173 -0
  432. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspLanguageProvider.d.ts +7 -0
  433. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspLanguageProvider.d.ts.map +1 -0
  434. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspLanguageProvider.js +29 -0
  435. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspLifecycleLedger.d.ts +5 -0
  436. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspLifecycleLedger.d.ts.map +1 -0
  437. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspLifecycleLedger.js +37 -0
  438. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspNodeAdapter.d.ts +31 -0
  439. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspNodeAdapter.d.ts.map +1 -0
  440. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspNodeAdapter.js +230 -0
  441. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspProcessManager.d.ts +24 -0
  442. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspProcessManager.d.ts.map +1 -0
  443. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspProcessManager.js +255 -0
  444. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspRestartThrottle.d.ts +6 -0
  445. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspRestartThrottle.d.ts.map +1 -0
  446. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspRestartThrottle.js +24 -0
  447. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspStatusRoute.d.ts +8 -0
  448. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspStatusRoute.d.ts.map +1 -0
  449. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspStatusRoute.js +22 -0
  450. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspTransport.d.ts +19 -0
  451. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspTransport.d.ts.map +1 -0
  452. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspTransport.js +55 -0
  453. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/testing/fakeLspProcess.d.ts +23 -0
  454. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/testing/fakeLspProcess.d.ts.map +1 -0
  455. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/testing/fakeLspProcess.js +132 -0
  456. package/node_modules/@oscharko-dev/keiko-server/dist/files.d.ts +63 -0
  457. package/node_modules/@oscharko-dev/keiko-server/dist/files.d.ts.map +1 -1
  458. package/node_modules/@oscharko-dev/keiko-server/dist/files.js +799 -1
  459. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-readiness.d.ts +6 -0
  460. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-readiness.d.ts.map +1 -0
  461. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-readiness.js +624 -0
  462. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-setup.d.ts +2 -0
  463. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-setup.d.ts.map +1 -1
  464. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-setup.js +275 -11
  465. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/actionSheetProjection.d.ts +30 -0
  466. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/actionSheetProjection.d.ts.map +1 -0
  467. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/actionSheetProjection.js +206 -0
  468. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/actionSheetRoutes.d.ts +29 -0
  469. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/actionSheetRoutes.d.ts.map +1 -0
  470. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/actionSheetRoutes.js +293 -0
  471. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/agentOperationsRoutes.d.ts +33 -0
  472. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/agentOperationsRoutes.d.ts.map +1 -0
  473. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/agentOperationsRoutes.js +405 -0
  474. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/commitRoutes.d.ts +23 -0
  475. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/commitRoutes.d.ts.map +1 -0
  476. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/commitRoutes.js +204 -0
  477. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/evidenceRoutes.d.ts +9 -0
  478. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/evidenceRoutes.d.ts.map +1 -0
  479. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/evidenceRoutes.js +101 -0
  480. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/execution.d.ts +38 -0
  481. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/execution.d.ts.map +1 -0
  482. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/execution.js +117 -0
  483. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/localMutationRoutes.d.ts +30 -0
  484. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/localMutationRoutes.d.ts.map +1 -0
  485. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/localMutationRoutes.js +165 -0
  486. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/mergeExecution.d.ts +63 -0
  487. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/mergeExecution.d.ts.map +1 -0
  488. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/mergeExecution.js +168 -0
  489. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/mergeRoutes.d.ts +12 -0
  490. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/mergeRoutes.d.ts.map +1 -0
  491. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/mergeRoutes.js +218 -0
  492. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/mutationEvidenceLedger.d.ts +23 -0
  493. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/mutationEvidenceLedger.d.ts.map +1 -0
  494. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/mutationEvidenceLedger.js +87 -0
  495. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/prExecution.d.ts +54 -0
  496. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/prExecution.d.ts.map +1 -0
  497. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/prExecution.js +192 -0
  498. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/prRoutes.d.ts +12 -0
  499. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/prRoutes.d.ts.map +1 -0
  500. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/prRoutes.js +256 -0
  501. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/pushExecution.d.ts +43 -0
  502. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/pushExecution.d.ts.map +1 -0
  503. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/pushExecution.js +124 -0
  504. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/pushRoutes.d.ts +12 -0
  505. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/pushRoutes.d.ts.map +1 -0
  506. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/pushRoutes.js +200 -0
  507. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/requestGuards.d.ts +15 -0
  508. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/requestGuards.d.ts.map +1 -0
  509. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/requestGuards.js +97 -0
  510. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/syncEvidence.d.ts +37 -0
  511. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/syncEvidence.d.ts.map +1 -0
  512. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/syncEvidence.js +85 -0
  513. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/syncExecution.d.ts +30 -0
  514. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/syncExecution.d.ts.map +1 -0
  515. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/syncExecution.js +266 -0
  516. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/syncRoutes.d.ts +13 -0
  517. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/syncRoutes.d.ts.map +1 -0
  518. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/syncRoutes.js +200 -0
  519. package/node_modules/@oscharko-dev/keiko-server/dist/gitPorcelainStatus.d.ts +15 -0
  520. package/node_modules/@oscharko-dev/keiko-server/dist/gitPorcelainStatus.d.ts.map +1 -0
  521. package/node_modules/@oscharko-dev/keiko-server/dist/gitPorcelainStatus.js +104 -0
  522. package/node_modules/@oscharko-dev/keiko-server/dist/gitRepositoryReads.d.ts +10 -0
  523. package/node_modules/@oscharko-dev/keiko-server/dist/gitRepositoryReads.d.ts.map +1 -0
  524. package/node_modules/@oscharko-dev/keiko-server/dist/gitRepositoryReads.js +314 -0
  525. package/node_modules/@oscharko-dev/keiko-server/dist/gitRepositoryRoutes.d.ts +7 -0
  526. package/node_modules/@oscharko-dev/keiko-server/dist/gitRepositoryRoutes.d.ts.map +1 -0
  527. package/node_modules/@oscharko-dev/keiko-server/dist/gitRepositoryRoutes.js +221 -0
  528. package/node_modules/@oscharko-dev/keiko-server/dist/gitRoutes.d.ts +66 -0
  529. package/node_modules/@oscharko-dev/keiko-server/dist/gitRoutes.d.ts.map +1 -0
  530. package/node_modules/@oscharko-dev/keiko-server/dist/gitRoutes.js +543 -0
  531. package/node_modules/@oscharko-dev/keiko-server/dist/governed-workflow.d.ts +2 -0
  532. package/node_modules/@oscharko-dev/keiko-server/dist/governed-workflow.d.ts.map +1 -1
  533. package/node_modules/@oscharko-dev/keiko-server/dist/governed-workflow.js +4 -0
  534. package/node_modules/@oscharko-dev/keiko-server/dist/grounded-qa-hybrid.d.ts.map +1 -1
  535. package/node_modules/@oscharko-dev/keiko-server/dist/grounded-qa-hybrid.js +2 -0
  536. package/node_modules/@oscharko-dev/keiko-server/dist/grounded-qa-multi-source.d.ts.map +1 -1
  537. package/node_modules/@oscharko-dev/keiko-server/dist/grounded-qa-multi-source.js +1 -0
  538. package/node_modules/@oscharko-dev/keiko-server/dist/grounded-qa.d.ts +11 -0
  539. package/node_modules/@oscharko-dev/keiko-server/dist/grounded-qa.d.ts.map +1 -1
  540. package/node_modules/@oscharko-dev/keiko-server/dist/grounded-qa.js +14 -4
  541. package/node_modules/@oscharko-dev/keiko-server/dist/headers.d.ts +4 -1
  542. package/node_modules/@oscharko-dev/keiko-server/dist/headers.d.ts.map +1 -1
  543. package/node_modules/@oscharko-dev/keiko-server/dist/headers.js +11 -4
  544. package/node_modules/@oscharko-dev/keiko-server/dist/index.d.ts +8 -1
  545. package/node_modules/@oscharko-dev/keiko-server/dist/index.d.ts.map +1 -1
  546. package/node_modules/@oscharko-dev/keiko-server/dist/index.js +9 -1
  547. package/node_modules/@oscharko-dev/keiko-server/dist/local-knowledge-grounded-qa.d.ts.map +1 -1
  548. package/node_modules/@oscharko-dev/keiko-server/dist/local-knowledge-grounded-qa.js +11 -2
  549. package/node_modules/@oscharko-dev/keiko-server/dist/qualityIntelligence/figmaSnapshotRoutes.d.ts +1 -1
  550. package/node_modules/@oscharko-dev/keiko-server/dist/qualityIntelligence/figmaSnapshotRoutes.d.ts.map +1 -1
  551. package/node_modules/@oscharko-dev/keiko-server/dist/qualityIntelligence/figmaSnapshotRoutes.js +1 -1
  552. package/node_modules/@oscharko-dev/keiko-server/dist/read-handlers.d.ts +5 -0
  553. package/node_modules/@oscharko-dev/keiko-server/dist/read-handlers.d.ts.map +1 -1
  554. package/node_modules/@oscharko-dev/keiko-server/dist/read-handlers.js +57 -1
  555. package/node_modules/@oscharko-dev/keiko-server/dist/routes.d.ts.map +1 -1
  556. package/node_modules/@oscharko-dev/keiko-server/dist/routes.js +260 -12
  557. package/node_modules/@oscharko-dev/keiko-server/dist/run-engine.d.ts.map +1 -1
  558. package/node_modules/@oscharko-dev/keiko-server/dist/run-engine.js +3 -0
  559. package/node_modules/@oscharko-dev/keiko-server/dist/run-handlers.d.ts +0 -1
  560. package/node_modules/@oscharko-dev/keiko-server/dist/run-handlers.d.ts.map +1 -1
  561. package/node_modules/@oscharko-dev/keiko-server/dist/run-handlers.js +64 -211
  562. package/node_modules/@oscharko-dev/keiko-server/dist/run-request.d.ts +11 -0
  563. package/node_modules/@oscharko-dev/keiko-server/dist/run-request.d.ts.map +1 -1
  564. package/node_modules/@oscharko-dev/keiko-server/dist/run-request.js +158 -10
  565. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/capabilityDetector.d.ts +38 -0
  566. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/capabilityDetector.d.ts.map +1 -0
  567. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/capabilityDetector.js +443 -0
  568. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/capabilityRoutes.d.ts +9 -0
  569. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/capabilityRoutes.d.ts.map +1 -0
  570. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/capabilityRoutes.js +45 -0
  571. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerEngineDetector.d.ts +17 -0
  572. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerEngineDetector.d.ts.map +1 -0
  573. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerEngineDetector.js +222 -0
  574. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRoutes.d.ts +8 -0
  575. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRoutes.d.ts.map +1 -0
  576. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRoutes.js +207 -0
  577. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRunner-errors.d.ts +18 -0
  578. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRunner-errors.d.ts.map +1 -0
  579. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRunner-errors.js +42 -0
  580. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRunner-evidence.d.ts +24 -0
  581. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRunner-evidence.d.ts.map +1 -0
  582. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRunner-evidence.js +74 -0
  583. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRunner.d.ts +37 -0
  584. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRunner.d.ts.map +1 -0
  585. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRunner.js +443 -0
  586. package/node_modules/@oscharko-dev/keiko-server/dist/server.d.ts.map +1 -1
  587. package/node_modules/@oscharko-dev/keiko-server/dist/server.js +24 -4
  588. package/node_modules/@oscharko-dev/keiko-server/dist/store/db.d.ts.map +1 -1
  589. package/node_modules/@oscharko-dev/keiko-server/dist/store/db.js +2 -1
  590. package/node_modules/@oscharko-dev/keiko-server/dist/store/index.d.ts +1 -1
  591. package/node_modules/@oscharko-dev/keiko-server/dist/store/index.d.ts.map +1 -1
  592. package/node_modules/@oscharko-dev/keiko-server/dist/store/messages.d.ts +2 -1
  593. package/node_modules/@oscharko-dev/keiko-server/dist/store/messages.d.ts.map +1 -1
  594. package/node_modules/@oscharko-dev/keiko-server/dist/store/messages.js +46 -4
  595. package/node_modules/@oscharko-dev/keiko-server/dist/store/schema.d.ts +1 -1
  596. package/node_modules/@oscharko-dev/keiko-server/dist/store/schema.d.ts.map +1 -1
  597. package/node_modules/@oscharko-dev/keiko-server/dist/store/schema.js +68 -1
  598. package/node_modules/@oscharko-dev/keiko-server/dist/store/types.d.ts +3 -2
  599. package/node_modules/@oscharko-dev/keiko-server/dist/store/types.d.ts.map +1 -1
  600. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/active-store.d.ts +21 -0
  601. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/active-store.d.ts.map +1 -0
  602. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/active-store.js +55 -0
  603. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/authorization.d.ts +7 -0
  604. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/authorization.d.ts.map +1 -0
  605. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/authorization.js +54 -0
  606. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/binding.d.ts +3 -0
  607. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/binding.d.ts.map +1 -0
  608. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/binding.js +22 -0
  609. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/cleanup.d.ts +4 -0
  610. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/cleanup.d.ts.map +1 -0
  611. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/cleanup.js +428 -0
  612. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/errors.d.ts +14 -0
  613. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/errors.d.ts.map +1 -0
  614. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/errors.js +81 -0
  615. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/evidence.d.ts +32 -0
  616. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/evidence.d.ts.map +1 -0
  617. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/evidence.js +52 -0
  618. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/field-safety.d.ts +3 -0
  619. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/field-safety.d.ts.map +1 -0
  620. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/field-safety.js +42 -0
  621. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/health.d.ts +4 -0
  622. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/health.d.ts.map +1 -0
  623. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/health.js +163 -0
  624. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/lifecycle.d.ts +3 -0
  625. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/lifecycle.d.ts.map +1 -0
  626. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/lifecycle.js +248 -0
  627. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/locks.d.ts +13 -0
  628. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/locks.d.ts.map +1 -0
  629. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/locks.js +44 -0
  630. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/managed-root.d.ts +7 -0
  631. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/managed-root.d.ts.map +1 -0
  632. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/managed-root.js +98 -0
  633. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/mutex.d.ts +8 -0
  634. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/mutex.d.ts.map +1 -0
  635. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/mutex.js +82 -0
  636. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/naming.d.ts +15 -0
  637. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/naming.d.ts.map +1 -0
  638. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/naming.js +0 -0
  639. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/provisioning.d.ts +3 -0
  640. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/provisioning.d.ts.map +1 -0
  641. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/provisioning.js +528 -0
  642. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/reconciliation.d.ts +15 -0
  643. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/reconciliation.d.ts.map +1 -0
  644. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/reconciliation.js +274 -0
  645. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/repair.d.ts +3 -0
  646. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/repair.d.ts.map +1 -0
  647. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/repair.js +286 -0
  648. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/routes.d.ts +19 -0
  649. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/routes.d.ts.map +1 -0
  650. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/routes.js +481 -0
  651. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/store.d.ts +12 -0
  652. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/store.d.ts.map +1 -0
  653. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/store.js +128 -0
  654. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/types.d.ts +170 -0
  655. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/types.d.ts.map +1 -0
  656. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/types.js +5 -0
  657. package/node_modules/@oscharko-dev/keiko-server/dist/voice-action-governance.d.ts +23 -0
  658. package/node_modules/@oscharko-dev/keiko-server/dist/voice-action-governance.d.ts.map +1 -0
  659. package/node_modules/@oscharko-dev/keiko-server/dist/voice-action-governance.js +126 -0
  660. package/node_modules/@oscharko-dev/keiko-server/dist/voice-handlers.d.ts +6 -0
  661. package/node_modules/@oscharko-dev/keiko-server/dist/voice-handlers.d.ts.map +1 -0
  662. package/node_modules/@oscharko-dev/keiko-server/dist/voice-handlers.js +570 -0
  663. package/node_modules/@oscharko-dev/keiko-server/dist/voice-realtime-grounded-tool.d.ts +31 -0
  664. package/node_modules/@oscharko-dev/keiko-server/dist/voice-realtime-grounded-tool.d.ts.map +1 -0
  665. package/node_modules/@oscharko-dev/keiko-server/dist/voice-realtime-grounded-tool.js +322 -0
  666. package/node_modules/@oscharko-dev/keiko-server/dist/voice-realtime.d.ts +69 -0
  667. package/node_modules/@oscharko-dev/keiko-server/dist/voice-realtime.d.ts.map +1 -0
  668. package/node_modules/@oscharko-dev/keiko-server/dist/voice-realtime.js +787 -0
  669. package/node_modules/@oscharko-dev/keiko-server/dist/workspace-state-handlers.d.ts +5 -0
  670. package/node_modules/@oscharko-dev/keiko-server/dist/workspace-state-handlers.d.ts.map +1 -0
  671. package/node_modules/@oscharko-dev/keiko-server/dist/workspace-state-handlers.js +106 -0
  672. package/node_modules/@oscharko-dev/keiko-server/package.json +20 -19
  673. package/node_modules/@oscharko-dev/keiko-tools/dist/.tsbuildinfo +1 -1
  674. package/node_modules/@oscharko-dev/keiko-tools/dist/git-commit-intent-node.d.ts +7 -0
  675. package/node_modules/@oscharko-dev/keiko-tools/dist/git-commit-intent-node.d.ts.map +1 -0
  676. package/node_modules/@oscharko-dev/keiko-tools/dist/git-commit-intent-node.js +42 -0
  677. package/node_modules/@oscharko-dev/keiko-tools/dist/git-merge-gateway.d.ts +95 -0
  678. package/node_modules/@oscharko-dev/keiko-tools/dist/git-merge-gateway.d.ts.map +1 -0
  679. package/node_modules/@oscharko-dev/keiko-tools/dist/git-merge-gateway.js +536 -0
  680. package/node_modules/@oscharko-dev/keiko-tools/dist/git-merge-node.d.ts +17 -0
  681. package/node_modules/@oscharko-dev/keiko-tools/dist/git-merge-node.d.ts.map +1 -0
  682. package/node_modules/@oscharko-dev/keiko-tools/dist/git-merge-node.js +243 -0
  683. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-adapter.d.ts +51 -0
  684. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-adapter.d.ts.map +1 -0
  685. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-adapter.js +207 -0
  686. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-evidence.d.ts +23 -0
  687. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-evidence.d.ts.map +1 -0
  688. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-evidence.js +283 -0
  689. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-node.d.ts +22 -0
  690. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-node.d.ts.map +1 -0
  691. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-node.js +145 -0
  692. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-orchestrator.d.ts +92 -0
  693. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-orchestrator.d.ts.map +1 -0
  694. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-orchestrator.js +321 -0
  695. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-preflight.d.ts +35 -0
  696. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-preflight.d.ts.map +1 -0
  697. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-preflight.js +226 -0
  698. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-taxonomy.d.ts +15 -0
  699. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-taxonomy.d.ts.map +1 -0
  700. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-taxonomy.js +102 -0
  701. package/node_modules/@oscharko-dev/keiko-tools/dist/git-pr-gateway.d.ts +101 -0
  702. package/node_modules/@oscharko-dev/keiko-tools/dist/git-pr-gateway.d.ts.map +1 -0
  703. package/node_modules/@oscharko-dev/keiko-tools/dist/git-pr-gateway.js +487 -0
  704. package/node_modules/@oscharko-dev/keiko-tools/dist/git-pr-node.d.ts +17 -0
  705. package/node_modules/@oscharko-dev/keiko-tools/dist/git-pr-node.d.ts.map +1 -0
  706. package/node_modules/@oscharko-dev/keiko-tools/dist/git-pr-node.js +173 -0
  707. package/node_modules/@oscharko-dev/keiko-tools/dist/git-publish-gateway.d.ts +72 -0
  708. package/node_modules/@oscharko-dev/keiko-tools/dist/git-publish-gateway.d.ts.map +1 -0
  709. package/node_modules/@oscharko-dev/keiko-tools/dist/git-publish-gateway.js +423 -0
  710. package/node_modules/@oscharko-dev/keiko-tools/dist/git-publish-node.d.ts +17 -0
  711. package/node_modules/@oscharko-dev/keiko-tools/dist/git-publish-node.d.ts.map +1 -0
  712. package/node_modules/@oscharko-dev/keiko-tools/dist/git-publish-node.js +107 -0
  713. package/node_modules/@oscharko-dev/keiko-tools/dist/git-worktree-adapter.d.ts +78 -0
  714. package/node_modules/@oscharko-dev/keiko-tools/dist/git-worktree-adapter.d.ts.map +1 -0
  715. package/node_modules/@oscharko-dev/keiko-tools/dist/git-worktree-adapter.js +300 -0
  716. package/node_modules/@oscharko-dev/keiko-tools/dist/git-worktree-snapshot-node.d.ts +31 -0
  717. package/node_modules/@oscharko-dev/keiko-tools/dist/git-worktree-snapshot-node.d.ts.map +1 -0
  718. package/node_modules/@oscharko-dev/keiko-tools/dist/git-worktree-snapshot-node.js +189 -0
  719. package/node_modules/@oscharko-dev/keiko-tools/dist/index.d.ts +9 -0
  720. package/node_modules/@oscharko-dev/keiko-tools/dist/index.d.ts.map +1 -1
  721. package/node_modules/@oscharko-dev/keiko-tools/dist/index.js +37 -0
  722. package/node_modules/@oscharko-dev/keiko-tools/package.json +9 -5
  723. package/node_modules/@oscharko-dev/keiko-verification/dist/.tsbuildinfo +1 -1
  724. package/node_modules/@oscharko-dev/keiko-verification/package.json +5 -5
  725. package/node_modules/@oscharko-dev/keiko-workflows/dist/.tsbuildinfo +1 -1
  726. package/node_modules/@oscharko-dev/keiko-workflows/dist/contextpack/assemble.d.ts.map +1 -1
  727. package/node_modules/@oscharko-dev/keiko-workflows/dist/contextpack/assemble.js +2 -2
  728. package/node_modules/@oscharko-dev/keiko-workflows/package.json +10 -10
  729. package/node_modules/@oscharko-dev/keiko-workspace/dist/.tsbuildinfo +1 -1
  730. package/node_modules/@oscharko-dev/keiko-workspace/dist/repoSearchEntries.d.ts.map +1 -1
  731. package/node_modules/@oscharko-dev/keiko-workspace/dist/repoSearchEntries.js +2 -2
  732. package/node_modules/@oscharko-dev/keiko-workspace/package.json +3 -3
  733. package/package.json +50 -29
  734. package/dist/ui/static/_next/static/chunks/8776.140362f8c6f4d7f1.js +0 -3
  735. package/dist/ui/static/_next/static/chunks/8824-87c539abddefabd6.js +0 -98
  736. package/dist/ui/static/_next/static/chunks/8835-d642f66c1962fa68.js +0 -1
  737. package/dist/ui/static/_next/static/chunks/9385.4cf1f094775e2625.js +0 -1
  738. package/dist/ui/static/_next/static/chunks/webpack-cb574cb028380487.js +0 -1
  739. package/dist/ui/static/_next/static/css/04e93b3f30b67861.css +0 -3
  740. package/node_modules/@oscharko-dev/keiko-contracts/dist/conversation-budget.d.ts +0 -37
  741. package/node_modules/@oscharko-dev/keiko-contracts/dist/conversation-budget.d.ts.map +0 -1
  742. package/node_modules/@oscharko-dev/keiko-contracts/dist/conversation-budget.js +0 -97
  743. package/node_modules/@oscharko-dev/keiko-server/dist/grounded-handoff.d.ts +0 -4
  744. package/node_modules/@oscharko-dev/keiko-server/dist/grounded-handoff.d.ts.map +0 -1
  745. package/node_modules/@oscharko-dev/keiko-server/dist/grounded-handoff.js +0 -445
  746. /package/dist/ui/static/_next/static/{GYCj4qCpIh2_0CNX8YDA0 → tzWFDxPPJ3-NtjB1T1JFu}/_buildManifest.js +0 -0
  747. /package/dist/ui/static/_next/static/{GYCj4qCpIh2_0CNX8YDA0 → tzWFDxPPJ3-NtjB1T1JFu}/_ssgManifest.js +0 -0
@@ -0,0 +1,102 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8824],{32620:(e,t,n)=>{"use strict";n.d(t,{$k:()=>h,Qe:()=>g,Wq:()=>f});var l=n(98803);let a="snapshots";function r(e,t){return`${e}\u0000${t}`;}function i(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>{var t;return n(null!=(t=e.error)?t:Error("IndexedDB request failed."));};});}function s(e){return new Promise((t,n)=>{e.oncomplete=()=>t(),e.onerror=()=>{var t;return n(null!=(t=e.error)?t:Error("IndexedDB transaction failed."));},e.onabort=()=>{var t;return n(null!=(t=e.error)?t:Error("IndexedDB transaction aborted."));};});}async function o(){return"u"<typeof indexedDB?null:new Promise((e,t)=>{let n=indexedDB.open("keiko-editor-hot-exit",1);n.onupgradeneeded=()=>{let e=n.result;e.objectStoreNames.contains(a)||e.createObjectStore(a);},n.onsuccess=()=>e(n.result),n.onerror=()=>{var e;return t(null!=(e=n.error)?e:Error("IndexedDB open failed."));};}).catch(()=>null);}function c(e){return new TextEncoder().encode(JSON.stringify(e)).length;}let d=Promise.resolve();function u(e){let t=d.then(e,e);return d=t.then(()=>void 0,()=>void 0),t;}async function p(e){let t=e.transaction(a,"readonly"),n=await i(t.objectStore(a).getAll());return await s(t),n.filter(l.sM);}async function m(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=await p(e),o=i.filter(e=>(0,l.YL)(e,t));if(o.length>0){let t=e.transaction(a,"readwrite");for(let e of o)t.objectStore(a).delete(r(e.workspaceRoot,e.relativePath));await s(t);}let d=null===n?null:r(n.workspaceRoot,n.relativePath),u=i.filter(e=>!(0,l.YL)(e,t)).filter(e=>r(e.workspaceRoot,e.relativePath)!==d).sort((e,t)=>e.updatedAt-t.updatedAt),m=(null===n?0:c(n))+u.reduce((e,t)=>e+c(t),0);if(m<=8388608)return;let h=e.transaction(a,"readwrite");for(let e of u){if(m<=8388608)break;h.objectStore(a).delete(r(e.workspaceRoot,e.relativePath)),m-=c(e);}await s(h);}async function h(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Date.now(),c=await o();if(null===c)return null;try{let o=c.transaction(a,"readonly"),d=await i(o.objectStore(a).get(r(e,t)));if(await s(o),!(0,l.sM)(d)||(0,l.YL)(d,n))return null;return d;}finally{c.close();}}async function f(e){if(e.schemaVersion===l.qP)return u(async()=>{let t=await o();if(null!==t)try{await m(t,e.updatedAt,e);let n=t.transaction(a,"readwrite");n.objectStore(a).put(e,r(e.workspaceRoot,e.relativePath)),await s(n);}finally{t.close();}});}async function g(e,t){return u(async()=>{let n=await o();if(null!==n)try{let l=n.transaction(a,"readwrite");l.objectStore(a).delete(r(e,t)),await s(l);}finally{n.close();}});}},41535:(e,t,n)=>{"use strict";let l,a;n.d(t,{KeikoDesktop:()=>gq});var r=n(54568),i=n(7620);let s=(0,i.createContext)(null);function o(e){let{value:t,children:n}=e;return(0,r.jsx)(s.Provider,{value:t,children:n});}function c(){let e=(0,i.useContext)(s);if(null===e)throw Error("useChatSessionContext must be used inside ChatSessionProvider");return e;}function d(){return(0,i.useContext)(s);}let u=(0,i.createContext)(null);function p(e){let{value:t,children:n}=e;return(0,r.jsx)(u.Provider,{value:t,children:n});}var m=n(73599);let h=["provisioning","active","paused","handoff-ready","archived","merged","abandoned","recovery-required","failed","cleanup-pending"],f={provisioning:["active","recovery-required","failed","cleanup-pending"],active:["paused","handoff-ready","recovery-required","failed","cleanup-pending"],paused:["active","handoff-ready","archived","abandoned","recovery-required","cleanup-pending"],"handoff-ready":["active","merged","archived","abandoned","recovery-required","cleanup-pending"],merged:["archived","cleanup-pending"],archived:["cleanup-pending"],abandoned:["cleanup-pending"],"recovery-required":["active","paused","failed","abandoned","cleanup-pending"],failed:["recovery-required","abandoned","cleanup-pending"],"cleanup-pending":["archived","abandoned","recovery-required"]},g=["retryable","repairable","blocked","policy-denied","terminal"];async function v(e,t){var n,l,a;let r=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),i="GET"!==r&&"HEAD"!==r,s=await fetch(e,{...t,headers:{Accept:"application/json",...(i?{"Content-Type":"application/json"}:{}),...(i?{"X-Keiko-CSRF":"1"}:{}),...(null!=(l=null==t?void 0:t.headers)?l:{})}});if(!s.ok){let e,t="INTERNAL",n=`HTTP ${s.status.toString()}`;try{let l=await s.json();t=l.error.code,n=l.error.message,a=l.error.failureClass,e="string"==typeof a&&g.includes(a)?l.error.failureClass:void 0;}catch{}throw Object.assign(new m.hD(t,n,s.status),{failureClass:e});}if(204!==s.status)return s.json();}async function b(e){return v("/api/task-workspaces",{method:"POST",body:JSON.stringify(e)});}async function y(e){let t=new URLSearchParams();return t.set("root",e),(await v(`/api/task-workspaces?${t.toString()}`)).instances;}async function x(){return(await v("/api/task-workspaces/active")).active;}async function w(e){return v("/api/task-workspaces/active",{method:"POST",body:JSON.stringify(e)});}async function j(){await v("/api/task-workspaces/active",{method:"DELETE"});}async function k(e){return v(`/api/task-workspaces/${encodeURIComponent(e.workspaceId)}/pause`,{method:"POST",body:JSON.stringify({requestedBy:e.requestedBy})});}async function N(e){return v(`/api/task-workspaces/${encodeURIComponent(e.workspaceId)}/resume`,{method:"POST",body:JSON.stringify({requestedBy:e.requestedBy})});}async function S(e){return v(`/api/task-workspaces/${encodeURIComponent(e.workspaceId)}/handoff`,{method:"POST",body:JSON.stringify({requestedBy:e.requestedBy})});}let C="studio-operator",R={instances:[],active:null,loading:!1,switching:!1,error:null};function I(e,t){switch(t.kind){case"load-start":return{...e,loading:!0,error:null};case"mutate-start":return{...e,switching:!0,error:null};case"settle":return{instances:t.instances,active:t.active,loading:!1,switching:!1,error:null};case"fail":return{...e,loading:!1,switching:!1,error:t.error};default:return e;}}function E(e){return e instanceof Error?e.message:"Task workspace action failed.";}var $=n(75571);let A={success:"var(--feedback-success, #2e7d32)",warning:"var(--feedback-warning, #b8860b)",danger:"var(--feedback-danger, #c0392b)",info:"var(--feedback-info, #2b6cb0)",muted:"var(--text-tertiary, #888)"},T={healthy:"success",degraded:"warning",drifted:"warning","locked-out":"danger",missing:"danger",unknown:"muted"};function F(e){return e.driftMarkers.includes("uncommitted-changes");}function D(e,t,n){let l=A[t],a={display:"inline-flex",alignItems:"center",gap:"0.25rem",padding:"0.05rem 0.4rem",borderRadius:"var(--radius-sm, 4px)",fontSize:"0.72rem",fontWeight:600,color:"var(--text-primary, #111)",background:`color-mix(in oklch, ${l} 18%, var(--surface-raised, var(--surface, transparent)))`,border:`1px solid color-mix(in oklch, ${l} 48%, var(--border-subtle, transparent))`};return(0,r.jsx)("span",{className:"tw-switcher-badge",style:a,title:n,children:e});}function M(e){var t,n;let l,{instance:a}=e,i=F(a);return(0,r.jsxs)("div",{className:"tw-switcher-active",children:[(0,r.jsxs)("div",{className:"tw-switcher-identity",children:[(0,r.jsx)("strong",{className:"tw-switcher-task",title:a.taskId,children:a.taskId}),(0,r.jsxs)("span",{className:"tw-switcher-branch",title:a.taskBranch,children:[a.taskBranch,(0,r.jsxs)("span",{className:"tw-switcher-base",children:[" ← ",a.baseBranch]})]})]}),(0,r.jsxs)("div",{className:"tw-switcher-badges",style:{display:"flex",flexWrap:"wrap",gap:"0.3rem"},children:[D(a.lifecycleState,"info","Lifecycle state"),D(a.health,T[a.health],"Workspace health"),i?D("uncommitted","warning","The worktree has uncommitted changes"):D("clean","success","The worktree is clean"),null!==a.lock?D(`locked: ${a.lock.reason}`,"danger",`Held by ${a.lock.owner}`):null]}),(0,r.jsx)("p",{className:"tw-switcher-path",style:{fontSize:"0.72rem",color:A.muted},children:(0,r.jsx)("span",{title:a.managedWorktreePath,children:null!=(n=(l=(t=a.managedWorktreePath).replace(/[/\\]+$/u,"").split(/[/\\]/u))[l.length-1])?n:t})}),(0,r.jsxs)("p",{className:"tw-switcher-activity",style:{fontSize:"0.7rem",color:A.muted},children:["Updated ",a.updatedAt]}),a.recoveryHints.length>0?(0,r.jsxs)("details",{className:"tw-switcher-recovery",children:[(0,r.jsxs)("summary",{children:["Recovery hints (",a.recoveryHints.length,")"]}),(0,r.jsx)("ul",{children:a.recoveryHints.map((e,t)=>(0,r.jsxs)("li",{children:[e.marker,": ",e.strategy,e.operatorActionRequired?" (operator action required)":""]},`${e.marker}-${String(t)}`))})]}):null]});}function P(e){let t=!e.enabled||e.busy;return(0,r.jsx)("button",{type:"button",className:"tw-switcher-action","aria-disabled":t,onClick:()=>{t||e.onClick();},children:e.label});}let L=(0,i.memo)(function(){var e,t,n,l,a,s;let o=function(){let e=(0,i.useContext)(u);if(null===e)throw Error("useActiveWorkspace must be used inside ActiveWorkspaceProvider");return e;}(),[c,d]=(0,i.useState)(!1),[p,m]=(0,i.useState)(""),[g,v]=(0,i.useState)(""),b=(0,i.useId)(),y=(0,i.useId)(),x=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(!c)return;let e=e=>{if("Escape"===e.key){var t;d(!1),null==(t=x.current)||t.focus();}};return document.addEventListener("keydown",e),()=>{document.removeEventListener("keydown",e);};},[c]);let w=o.activeInstance,j=null!==w&&"string"==typeof(s=a=w.lifecycleState)&&h.includes(s)?f[a]:[],k=null!==w&&j.includes("paused"),N=null!==w&&j.includes("handoff-ready"),S=null===w?"No active task workspace":`Active: ${w.taskId} on ${w.taskBranch} (${w.lifecycleState}, ${w.health})`,C=null===w?"Task workspace context: no active workspace":`Task workspace context: ${w.taskId}`,R=null!=(e=null!=(t=null==(n=o.activeInstance)?void 0:n.repositoryRoot)?t:null==(l=o.instances[0])?void 0:l.repositoryRoot)?e:null,I=o.switching||null===R||""===p.trim()||""===g.trim();return(0,r.jsxs)("div",{className:"tw-switcher",style:{position:"relative"},children:[(0,r.jsxs)("button",{ref:x,type:"button",className:"tw-switcher-trigger","aria-expanded":c,"aria-controls":b,"aria-describedby":y,"aria-label":C,"aria-busy":o.switching,onClick:()=>{d(e=>!e);},"data-active":null!==w?"true":"false",children:[(0,r.jsx)($.F.branch,{size:14}),(0,r.jsx)("span",{className:"tw-switcher-trigger-label",children:null===w?"Task workspace":w.taskId}),o.switching?(0,r.jsx)("span",{"aria-hidden":"true",children:"…"}):null]}),(0,r.jsx)("div",{id:y,role:"status","aria-live":"polite",className:"tw-switcher-status-sr",children:S}),c?(0,r.jsxs)("div",{id:b,className:"tw-switcher-panel",role:"group","aria-label":"Task workspace context",children:[(0,r.jsxs)("div",{className:"tw-switcher-panel-head",children:[(0,r.jsx)("span",{className:"tw-switcher-kicker",children:"Task workspace"}),(0,r.jsx)("strong",{children:null===w?"No workspace bound":w.taskId})]}),null!==o.error?(0,r.jsx)("p",{role:"alert",className:"tw-switcher-error",style:{color:A.danger},children:o.error}):null,null!==w?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(M,{instance:w}),(0,r.jsxs)("div",{className:"tw-switcher-actions",style:{display:"flex",gap:"0.4rem",flexWrap:"wrap",marginTop:"0.4rem"},children:[P({label:"Pause",onClick:()=>void o.pause(w.workspaceId),enabled:k,busy:o.switching}),P({label:"Prepare handoff",onClick:()=>void o.prepareHandoff(w.workspaceId),enabled:N&&!F(w),busy:o.switching}),P({label:"Clear active",onClick:()=>void o.clearActive(),enabled:!0,busy:o.switching})]})]}):(0,r.jsxs)("div",{className:"tw-switcher-empty",children:[(0,r.jsx)("span",{className:"tw-switcher-empty-icon","aria-hidden":"true",children:(0,r.jsx)($.F.branch,{size:16})}),(0,r.jsxs)("div",{children:[(0,r.jsx)("strong",{children:"No active task workspace"}),(0,r.jsx)("p",{children:null===R?"Open a project before creating a managed task workspace.":"Switch to an existing workspace or create one for this repository."})]})]}),(0,r.jsxs)("div",{className:"tw-switcher-section",children:[(0,r.jsx)("div",{className:"tw-switcher-section-title",children:"Available workspaces"}),0===o.instances.length?(0,r.jsx)("p",{className:"tw-switcher-list-empty",children:o.loading?"Loading workspaces…":"No managed task workspaces yet."}):(0,r.jsx)("div",{className:"tw-switcher-list",role:"list","aria-label":"Task workspaces",children:o.instances.map(e=>{let t=(null==w?void 0:w.workspaceId)===e.workspaceId;return(0,r.jsxs)("div",{role:"listitem",className:"tw-switcher-list-item",children:[(0,r.jsxs)("span",{className:"tw-switcher-list-label",title:e.managedWorktreePath,children:[(0,r.jsx)("strong",{children:e.taskId}),(0,r.jsx)("span",{children:e.lifecycleState}),F(e)?D("dirty","warning"):null]}),P({label:t?"Active":"Switch",onClick:()=>void o.switchTo(e.workspaceId),enabled:!t&&("active"===e.lifecycleState||"paused"===e.lifecycleState||"handoff-ready"===e.lifecycleState),busy:o.switching})]},e.workspaceId);})})]}),null!==R?(0,r.jsxs)("div",{className:"tw-switcher-section",children:[(0,r.jsx)("div",{className:"tw-switcher-section-title",children:"Create workspace"}),(0,r.jsxs)("form",{className:"tw-switcher-create",onSubmit:e=>{e.preventDefault(),I||o.provision({root:R,taskId:p.trim(),baseBranch:g.trim()}).then(()=>{m(""),v("");});},children:[(0,r.jsxs)("label",{className:"tw-switcher-field",children:[(0,r.jsx)("span",{children:"Task id"}),(0,r.jsx)("input",{type:"text",value:p,onChange:e=>{m(e.target.value);},placeholder:"e.g. 446-binding"})]}),(0,r.jsxs)("label",{className:"tw-switcher-field",children:[(0,r.jsx)("span",{children:"Base branch"}),(0,r.jsx)("input",{type:"text",value:g,onChange:e=>{v(e.target.value);},placeholder:"e.g. dev"})]}),(0,r.jsx)("button",{type:"submit",className:"tw-switcher-create-submit",disabled:I,"aria-disabled":I,children:"Create task workspace"})]})]}):null]}):null]});}),q=[{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"}],z={calendar:!0,mail:!1,jira:!0,docs:!0},O="keiko.twin.mode",B="keiko.twin.persona",W="keiko.twin.policy",K="keiko.twin.bridges",U=(0,i.createContext)(null);function V(e,t){try{let n=window.localStorage.getItem(e);if(null===n)return t;let l=JSON.parse(n);return null==l?t:l;}catch{return t;}}function H(e,t){try{window.localStorage.setItem(e,t);}catch{}}function _(e,t){try{window.localStorage.setItem(e,JSON.stringify(t));}catch{}}function G(e){let{children:t}=e,[n,l]=(0,i.useState)("manual"),[a,s]=(0,i.useState)("Developer"),[o,c]=(0,i.useState)(q),[d,u]=(0,i.useState)(z),[p,m]=(0,i.useState)(!1);(0,i.useEffect)(()=>{l(function(){try{let e=window.localStorage.getItem(O);return"manual"===e||"autonomous"===e?e:"manual";}catch{return"manual";}}()),s(function(){try{let e=window.localStorage.getItem(B);if("Developer"===e||"Product Owner"===e||"Designer"===e)return e;return"Developer";}catch{return"Developer";}}()),c(V(W,q)),u(V(K,z));try{window.localStorage.removeItem("keiko.twin.memory");}catch{}m(!0);},[]),(0,i.useEffect)(()=>{p&&H(O,n);},[n,p]),(0,i.useEffect)(()=>{p&&H(B,a);},[a,p]),(0,i.useEffect)(()=>{p&&_(W,o);},[o,p]),(0,i.useEffect)(()=>{p&&_(K,d);},[d,p]);let h=(0,i.useCallback)((e,t)=>{var n,l,a,r,i,s,c;let d;return d=e=>{var t,n;return null!=(t=null==(n=o.find(t=>t.id===e))?void 0:n.decision)?t:null;},"write"===e?"high"===t?null!=(r=d("write-prod"))?r:"deny":null!=(i=d("write"))?i:"allow":"command"===e?"high"===t?null!=(s=d("command-danger"))?s:"ask":null!=(c=d("command"))?c:"allow":"git"===e?null!=(n=d("pr"))?n:"allow":"mail"===e?null!=(l=d("mail"))?l:"ask":"network"===e&&null!=(a=d("network"))?a:"ask";},[o]),f=(0,i.useMemo)(()=>({mode:n,setMode:l,persona:a,setPersona:s,policy:o,setPolicy:c,bridges:d,setBridges:u,decide:h}),[n,a,o,d,h]);return(0,r.jsx)(U.Provider,{value:f,children:t});}function J(){let e=(0,i.useContext)(U);if(null===e)throw Error("useTwin must be used inside <TwinProvider>");return e;}let Y=(0,i.createContext)({wins:[],active:null,winCount:0}),X="keiko.locale",Z={"app.skipToContent":"Skip to content","app.workspaceHeading":"Keiko workspace","header.tileAll":"Tile all windows","header.splitFront":"Split front windows","header.cascade":"Cascade windows","rail.primaryNavigation":"Primary workspace navigation","rail.newChat":"New chat","rail.chatHistory":"Chat History","rail.memoria":"MemoriaViva","rail.quality":"Quality Intelligence","rail.promptEnhancer":"Prompt Enhancer","rail.localKnowledge":"Local Knowledge","rail.figma":"Figma Snapshot","rail.lightMode":"Light mode","rail.darkMode":"Dark mode","rail.settings":"Settings","common.optional":"optional","common.loading":"Loading...","common.cancel":"Cancel","common.retry":"Retry","common.dismissError":"Dismiss error","common.status":"Status","common.duration":"Duration","common.confidence":"Confidence","newWindow.chat.title":"New Chat window","newWindow.chat.description":"Talk to Keiko","newWindow.chat.fieldTitle":"Title","newWindow.chat.defaultTitle":"New chat","newWindow.chat.placeholder":"Name this conversation","newWindow.chat.open":"Open Chat","mode.group":"Agent mode","mode.manual.title":"You approve every privileged action","mode.manual.label":"You","mode.autonomous.title":"Keiko governs agents per your policy","chat.role.user":"You","chat.keikoLogo":"Keiko logo","chat.keikoResponding":"Keiko is responding","chat.copy.unavailable":"Copy unavailable: the clipboard requires a secure (HTTPS) connection.","chat.copy.copiedStatus":"Answer copied","chat.copy.failedStatus":"Clipboard access failed. Select the answer manually and copy it.","chat.copy.copied":"Copied","chat.copy.message":"Copy answer","chat.copy.short":"Copy","chat.questionMap.label":"Conversation questions","chat.questionMap.jump":"Jump to question {index}: {preview}","chat.answer.expand":"Expand answer","chat.answer.collapse":"Collapse answer","chat.messageLabel":"Chat message","chat.conversation":"Conversation","chat.conversationReady":"Conversation ready","chat.empty.headline":"How can I help you today?","chat.empty.noChat.title":"Pick or start a chat","chat.empty.noChat.hint":"Select a conversation from the project sidebar, or create a new one to get started.","chat.hero.title":"What should we build?","chat.hero.loadingWorkspace":"Loading local workspace...","chat.hero.placeholder":"Describe a task, paste a link, or ask anything...","chat.workLocally":"Work locally","chat.composer.placeholder":"Ask Keiko...","chat.composer.loading":"Loading...","chat.model.menuTitle":"Models","chat.model.title":"Model","chat.model.loading":"Loading models...","chat.model.noEligible":"No conversation-eligible model","chat.model.change":"Change model","chat.model.noneConfiguredTitle":"No conversation-eligible model is configured - connect a gateway in Settings","chat.noModelAlert":"No conversation-eligible model is configured. Connect a gateway in Settings to enable chat.","chat.loadingGateway":"Connecting to your gateway...","chat.send.hint":"Type a message to send","chat.send.label":"Send message","chat.send.noModel":"No model available","chat.send.connecting":"Connecting to gateway","chat.send.cancel":"Cancel response","chat.send.statusQueued":"Submitting your message…","chat.send.statusContacting":"Contacting model…","chat.send.statusStreaming":"Receiving response…","chat.send.statusCancelled":"Response cancelled.","chat.voice":"Voice","chat.error.send":"Could not send message.","chat.error.load":"Could not load chat.","chat.error.scopeUpdate":"Unable to update knowledge scope.","chat.error.memoryUpdate":"Unable to update memory.","chat.grounding.label":"Grounding","chat.grounding.mode":"Grounding mode","chat.grounding.strategy":"Strategy","chat.grounding.modelOnly":"Model only","chat.grounding.liveFiles":"Live Files context","chat.grounding.multiple":"Multiple sources","chat.grounding.disconnectConfirm":"This will disconnect {count} grounding {sourceLabel}. Continue?","chat.grounding.sourceSingular":"source","chat.grounding.sourcePlural":"sources","chat.grounding.capsule":"Knowledge capsule: {name}","chat.grounding.capsuleSet":"Capsule set: {name}","chat.grounding.unavailable":"{label} (unavailable)","chat.memory.panel":"Conversation memory","chat.memory.included":"{count} memories included","chat.memory.noneIncluded":"No memories included","chat.memory.disclosurePending":"MemoriaViva disclosure appears after the next response.","chat.memory.usedTokens":"Used {used} of {tokens} MemoriaViva tokens.","chat.memory.disabledLast":"MemoriaViva was disabled for the last request.","chat.memory.provenance":"Provenance for {id}","chat.memory.source":"Source","chat.memory.sensitivity":"Sensitivity","chat.memory.status":"Status","chat.memory.confidence":"Confidence","chat.memory.captured":"Captured","chat.memory.approvalRequired":"Approval required","chat.memory.proposedMemory":"Proposed memory","chat.memory.accept":"Accept","chat.memory.reject":"Reject","chat.memory.accepted":"MemoriaViva proposal accepted.","chat.memory.rejected":"MemoriaViva proposal rejected.","chat.memory.acceptError":"Unable to accept memory.","chat.memory.rejectError":"Unable to reject memory.","chat.memory.updateDetected":"MemoriaViva update detected","chat.memory.suggestedUpdate":"Suggested update: {body}","chat.memory.suggestedUpdateFallback":"Suggested update.","chat.memory.forgetDetected":"MemoriaViva forget detected","chat.memory.confirmationRequired":"Confirmation required","chat.memory.forgetMatched":"Matched memory {id} for a forget operation.","chat.memory.forget":"Forget","chat.memory.reviewForget":"Review forget","chat.memory.forgetPermanently":"Forget permanently","chat.memory.forgetCompleted":"MemoriaViva forget action completed.","chat.memory.forgetError":"Unable to forget memory.","chat.memory.proposalDeclined":"Memory proposal declined","chat.memory.noReason":"No reason provided","chat.memory.actionNotCreated":"MemoriaViva action not created","chat.grounded.cancel":"Cancel grounded request","attachment.rejection.textOnly":"The selected model can't accept this attachment type. Choose a model that supports images or documents.","attachment.rejection.unsupported":"Unsupported file type{mime}. Supported types: images (image/*), PDF, plain text, markdown, JSON, YAML.","attachment.rejection.oversized":"File is larger than the 8 MiB limit. Choose a smaller file or summarize the content as text.","attachment.rejection.empty":"Empty file. Add a file with content to attach.","attachment.remove":"Remove attachment {name}","attachment.pending":"Pending attachments","attachment.drop":"Drop files here to attach","attachment.disabledDifferentModel":"The selected model does not support image or document input. Choose a different model to attach files.","attachment.disabledNoModel":"The selected model does not support image or document input. No configured model currently supports attachments.","attachment.attachFile":"Attach file","attachment.notSupported":"Attachments not supported","attachment.docsContext":"Documents included as context","attachment.docContextLabel":"Document included as context:","attachment.docsContextLabel":"Documents included as context:","attachment.truncated":" (truncated)","attachment.truncatedHint":"Some document text was truncated to fit the context limit.","footer.status":"Workspace status","footer.version":"Keiko version {version}","footer.versionLoading":"version loading","footer.versionUnavailable":"version unavailable","footer.windowSingular":"{count} window","footer.windowPlural":"{count} windows","footer.openWindows":"Open windows","footer.minimized":"Minimized","footer.fullscreen":"Fullscreen","footer.visible":"Visible","footer.restore":"Restore","footer.focus":"Focus","footer.windowAction":"{action} {title} window{suffix}","scope.pressure.low":"Low","scope.pressure.moderate":"Moderate","scope.pressure.high":"High","scope.pressure.exceeded":"Exceeded","scope.budgetSummary":"Last grounded run: {tokens} tokens, {files} files","scope.connectedFolder":"Connected folder","scope.folder":"Folder: {name}","scope.repository":"Repository scope","scope.connectedFile":"Connected file","scope.file":"File: {name}","scope.filesConnected":"{count} files connected","scope.boundary.repository":"Keiko may inspect only the connected repository; safe-read exclusions and context budget limits apply before each answer.","scope.boundary.folder":"Keiko may inspect only the connected folder; safe-read exclusions and context budget limits apply before each answer.","scope.boundary.file":"Keiko may inspect only the connected file scope; safe-read exclusions and context budget limits apply before each answer.","scope.disconnect":"Disconnect {label} from chat","scope.disconnectWithPath":"Disconnect {label} from chat ({path})","scope.disconnectError":"Unable to disconnect scope.","settings.title":"Settings","settings.selfHosted":"Self-hosted","settings.selfHostedTitle":"Runs inside your network","settings.tabs.models":"Models","settings.tabs.general":"General","settings.tabs.security":"Security","settings.language.title":"Language","settings.language.description":"Choose the language used by the Keiko browser interface.","settings.language.label":"Interface language","settings.language.compactLabel":"Language","settings.language.help":"Saved on this device and applied immediately.","settings.voice.title":"Assistant voice","settings.voice.description":"Choose the voice used by Voice Dialogue.","settings.voice.label":"Voice","settings.voice.help":"Saved on this device and used the next time Voice Dialogue speaks.","settings.voice.unavailable":"Voice choices become available after a configured voice provider exposes speech output.","settings.wallpaper.title":"Workspace wallpaper","settings.wallpaper.description":"Liquid Chrome - a subtle metallic flow behind the grid that reacts to your cursor and clicks. Turn it off to stop the WebGL animation completely.","settings.wallpaper.toggle":"Liquid wallpaper","settings.wallpaper.running":"Running","settings.wallpaper.stopped":"Stopped","settings.wallpaper.opacity":"Wallpaper opacity","settings.scale.off":"Off","settings.scale.full":"Full","settings.scale.base":"Base","settings.scale.lighter":"Lighter","settings.scale.subtle":"Subtle","settings.scale.strong":"Strong","settings.workspace.backgroundBrightness":"Workspace background brightness","settings.workspace.gridStrength":"Workspace grid strength","settings.workspace.cameraAnimation":"Workspace camera smoothness","settings.workspace.cameraAnimationMinimal":"Minimal","settings.workspace.cameraAnimationSmooth":"Smooth","settings.workspace.cameraAnimationHelp":"Move right to make pan and zoom transitions softer. Minimal applies changes immediately.","settings.workspace.borderStrength":"Workspace border strength","settings.workspace.innerGlow":"Workspace inner glow","settings.models.gatewayTitle":"Model gateway","settings.models.gatewayDescription":"Credentials are stored locally by the Keiko loopback server; secrets are never returned to the browser.","settings.models.updateCredentials":"Update credentials","settings.models.connectGateway":"Connect gateway","settings.models.setupRequired":"Gateway setup required","settings.models.connected":"Gateway connected","settings.models.configured":"Gateway configured","settings.models.detailSetup":"Enter the gateway base URL and API token before using chat or agent workflows.","settings.models.detailNoModels":"The gateway is configured, but no conversation-capable models are currently available.","settings.models.detailNoChat":"Gateway connected, but none of the discovered models can be used for conversation. Add a chat-capable deployment.","settings.models.detailReady":"Keiko can use the configured gateway models for chat and agent workflows.","settings.models.modelCount":"{count} models","settings.models.chatCount":"{count} chat","settings.models.statusConfigured":"gateway configured","settings.models.statusSetupRequired":"setup required","settings.models.statusConversationEligible":"conversation-eligible","settings.models.statusEmbedding":"available for embeddings","settings.models.statusNotSelectable":"not selectable for conversation","settings.models.loadError":"Could not load gateway settings - the local Keiko backend did not respond.","settings.models.retry":"Retry","settings.models.loading":"Loading gateway models...","settings.models.emptyConfigured":"No conversation-capable models are currently available. Review the gateway configuration or discovered model set.","settings.models.emptyUnconfigured":"No models are configured yet. Connect the gateway to load configured model capabilities.","settings.models.eligibilityOk":"Conversation-eligible","settings.models.eligibilityOkAria":"Model eligibility: eligible for conversation","settings.models.eligibilityPrefix":"Model eligibility: {label}","settings.models.embeddingLabel":"Embedding-ready","settings.models.embeddingAvailable":"Available for embeddings; not shown in the chat model picker","settings.models.ineligibleEmbedding":"Embedding model - not selectable for text conversation","settings.models.ineligibleOcr":"OCR/vision-only - not selectable for text conversation","settings.models.ineligibleGeneric":"Not a chat model - not selectable for text conversation","settings.models.ineligibleShortOcr":"OCR/vision-only","settings.models.ineligibleShortGeneric":"not a chat model","settings.models.notSelectable":"Not selectable - {reason}","settings.models.voiceProviderAvailable":"Voice provider - available for {capabilities}{personas}","settings.models.voiceProviderBadge":"Voice provider - {label}","settings.models.voiceCapabilitySpeechToText":"speech-to-text","settings.models.voiceCapabilitySpeechOutput":"speech output","settings.models.voiceCapabilityRealtimeDialogue":"realtime dialogue","settings.models.voiceCapabilityVoice":"voice","settings.models.voicePersonas":"; voices: {personas}","settings.models.readinessError":"Readiness check failed. The gateway configuration was not changed.","settings.models.copyReport":"Copy report","settings.models.copied":"Copied","settings.models.reportCopied":"Readiness report copied.","settings.models.reportCopyFailed":"Clipboard access failed. Select and copy the report details manually.","settings.models.checkingReadiness":"Checking {mode} readiness...","settings.models.readinessModeDeep":"deep","settings.models.readinessModeBasic":"basic","settings.models.workingToday":"Working today","settings.models.notVerified":"Not verified","settings.models.verifiedCapabilities":"Verified capabilities","settings.models.capabilityStreaming":"Streaming","settings.models.capabilityTools":"Tools","settings.models.capabilityJson":"JSON","settings.models.capabilityReasoning":"Reasoning","settings.models.capabilityImage":"Image","settings.models.capabilityPdf":"PDF","settings.models.contextTokensShort":"{count} ctx","settings.models.runReadiness":"Run readiness check","settings.models.deepProbes":"Deep probes","settings.models.capabilitySummary":"tools {tools} \xb7 structured {structured} \xb7 {costClass}/{latencyClass}","settings.models.yes":"yes","settings.models.no":"no","settings.security.placeholder":"SSO \xb7 audit log \xb7 data residency - coming soon."},Q={en:Z,de:{"app.skipToContent":"Zum Inhalt springen","app.workspaceHeading":"Keiko-Arbeitsbereich","header.tileAll":"Alle Fenster kacheln","header.splitFront":"Vordere Fenster teilen","header.cascade":"Fenster stapeln","rail.primaryNavigation":"Primaere Arbeitsbereichsnavigation","rail.newChat":"Neuer Chat","rail.chatHistory":"Chatverlauf","rail.memoria":"MemoriaViva","rail.quality":"Quality Intelligence","rail.promptEnhancer":"Prompt Enhancer","rail.localKnowledge":"Lokales Wissen","rail.figma":"Figma-Snapshot","rail.lightMode":"Heller Modus","rail.darkMode":"Dunkler Modus","rail.settings":"Einstellungen","common.optional":"optional","common.loading":"Laedt...","common.cancel":"Abbrechen","common.retry":"Erneut versuchen","common.dismissError":"Fehler ausblenden","common.status":"Status","common.duration":"Dauer","common.confidence":"Konfidenz","newWindow.chat.title":"Neues Chatfenster","newWindow.chat.description":"Mit Keiko sprechen","newWindow.chat.fieldTitle":"Titel","newWindow.chat.defaultTitle":"Neuer Chat","newWindow.chat.placeholder":"Konversation benennen","newWindow.chat.open":"Chat oeffnen","mode.group":"Agentenmodus","mode.manual.title":"Du bestaetigst jede privilegierte Aktion","mode.manual.label":"Du","mode.autonomous.title":"Keiko steuert Agenten nach deiner Richtlinie","chat.role.user":"Du","chat.keikoLogo":"Keiko-Logo","chat.keikoResponding":"Keiko antwortet","chat.copy.unavailable":"Kopieren nicht verfuegbar: Die Zwischenablage erfordert eine sichere HTTPS-Verbindung.","chat.copy.copiedStatus":"Antwort kopiert","chat.copy.failedStatus":"Zugriff auf die Zwischenablage fehlgeschlagen. Waehle die Antwort manuell aus und kopiere sie.","chat.copy.copied":"Kopiert","chat.copy.message":"Antwort kopieren","chat.copy.short":"Kopieren","chat.questionMap.label":"Fragen im Chatverlauf","chat.questionMap.jump":"Zu Frage {index} springen: {preview}","chat.answer.expand":"Antwort ausklappen","chat.answer.collapse":"Antwort einklappen","chat.messageLabel":"Chatnachricht","chat.conversation":"Konversation","chat.conversationReady":"Konversation bereit","chat.empty.headline":"Wie kann ich dir heute helfen?","chat.empty.noChat.title":"Chat auswaehlen oder starten","chat.empty.noChat.hint":"Waehle eine Konversation aus der Projekt-Seitenleiste oder erstelle eine neue.","chat.hero.title":"Was sollen wir bauen?","chat.hero.loadingWorkspace":"Lokaler Arbeitsbereich wird geladen...","chat.hero.placeholder":"Beschreibe eine Aufgabe, fuege einen Link ein oder frag etwas...","chat.workLocally":"Lokal arbeiten","chat.composer.placeholder":"Frag Keiko...","chat.composer.loading":"Laedt...","chat.model.menuTitle":"Modelle","chat.model.title":"Modell","chat.model.loading":"Modelle werden geladen...","chat.model.noEligible":"Kein dialogfaehiges Modell","chat.model.change":"Modell wechseln","chat.model.noneConfiguredTitle":"Kein dialogfaehiges Modell ist konfiguriert - verbinde ein Gateway in den Einstellungen","chat.noModelAlert":"Kein dialogfaehiges Modell ist konfiguriert. Verbinde ein Gateway in den Einstellungen, um Chat zu aktivieren.","chat.loadingGateway":"Verbindung zum Gateway wird hergestellt...","chat.send.hint":"Gib eine Nachricht ein, um sie zu senden","chat.send.label":"Nachricht senden","chat.send.noModel":"Kein Modell verfuegbar","chat.send.connecting":"Gateway wird verbunden","chat.send.cancel":"Antwort abbrechen","chat.send.statusQueued":"Nachricht wird gesendet...","chat.send.statusContacting":"Modell wird kontaktiert...","chat.send.statusStreaming":"Antwort wird empfangen...","chat.send.statusCancelled":"Antwort abgebrochen.","chat.voice":"Spracheingabe","chat.error.send":"Nachricht konnte nicht gesendet werden.","chat.error.load":"Chat konnte nicht geladen werden.","chat.error.scopeUpdate":"Wissensbereich konnte nicht aktualisiert werden.","chat.error.memoryUpdate":"Speicher konnte nicht aktualisiert werden.","chat.grounding.label":"Grounding","chat.grounding.mode":"Grounding-Modus","chat.grounding.strategy":"Strategie","chat.grounding.modelOnly":"Nur Modell","chat.grounding.liveFiles":"Live-Dateikontext","chat.grounding.multiple":"Mehrere Quellen","chat.grounding.disconnectConfirm":"Dadurch werden {count} Grounding-{sourceLabel} getrennt. Fortfahren?","chat.grounding.sourceSingular":"Quelle","chat.grounding.sourcePlural":"Quellen","chat.grounding.capsule":"Wissenskapsel: {name}","chat.grounding.capsuleSet":"Kapselset: {name}","chat.grounding.unavailable":"{label} (nicht verfuegbar)","chat.memory.panel":"Konversationsspeicher","chat.memory.included":"{count} Erinnerungen einbezogen","chat.memory.noneIncluded":"Keine Erinnerungen einbezogen","chat.memory.disclosurePending":"MemoriaViva-Hinweis erscheint nach der naechsten Antwort.","chat.memory.usedTokens":"{used} von {tokens} MemoriaViva-Token verwendet.","chat.memory.disabledLast":"MemoriaViva war fuer die letzte Anfrage deaktiviert.","chat.memory.provenance":"Herkunft fuer {id}","chat.memory.source":"Quelle","chat.memory.sensitivity":"Sensitivitaet","chat.memory.status":"Status","chat.memory.confidence":"Konfidenz","chat.memory.captured":"Erfasst","chat.memory.approvalRequired":"Bestaetigung erforderlich","chat.memory.proposedMemory":"Vorgeschlagene Erinnerung","chat.memory.accept":"Akzeptieren","chat.memory.reject":"Ablehnen","chat.memory.accepted":"MemoriaViva-Vorschlag akzeptiert.","chat.memory.rejected":"MemoriaViva-Vorschlag abgelehnt.","chat.memory.acceptError":"Erinnerung konnte nicht akzeptiert werden.","chat.memory.rejectError":"Erinnerung konnte nicht abgelehnt werden.","chat.memory.updateDetected":"MemoriaViva-Aktualisierung erkannt","chat.memory.suggestedUpdate":"Vorgeschlagene Aktualisierung: {body}","chat.memory.suggestedUpdateFallback":"Vorgeschlagene Aktualisierung.","chat.memory.forgetDetected":"MemoriaViva-Vergessen erkannt","chat.memory.confirmationRequired":"Bestaetigung erforderlich","chat.memory.forgetMatched":"Erinnerung {id} fuer eine Vergessen-Aktion gefunden.","chat.memory.forget":"Vergessen","chat.memory.reviewForget":"Vergessen pruefen","chat.memory.forgetPermanently":"Dauerhaft vergessen","chat.memory.forgetCompleted":"MemoriaViva-Vergessen abgeschlossen.","chat.memory.forgetError":"Erinnerung konnte nicht vergessen werden.","chat.memory.proposalDeclined":"Speichervorschlag abgelehnt","chat.memory.noReason":"Kein Grund angegeben","chat.memory.actionNotCreated":"MemoriaViva-Aktion nicht erstellt","chat.grounded.cancel":"Grounded-Anfrage abbrechen","attachment.rejection.textOnly":"Das ausgewaehlte Modell kann diesen Anhangstyp nicht verarbeiten. Waehle ein Modell mit Bild- oder Dokumentunterstuetzung.","attachment.rejection.unsupported":"Nicht unterstuetzter Dateityp{mime}. Unterstuetzte Typen: Bilder (image/*), PDF, Klartext, Markdown, JSON, YAML.","attachment.rejection.oversized":"Die Datei ist groesser als das Limit von 8 MiB. Waehle eine kleinere Datei oder fasse den Inhalt als Text zusammen.","attachment.rejection.empty":"Leere Datei. Fuege eine Datei mit Inhalt hinzu.","attachment.remove":"Anhang {name} entfernen","attachment.pending":"Ausstehende Anhaenge","attachment.drop":"Dateien hier ablegen, um sie anzufuegen","attachment.disabledDifferentModel":"Das ausgewaehlte Modell unterstuetzt keine Bild- oder Dokumenteingabe. Waehle ein anderes Modell, um Dateien anzufuegen.","attachment.disabledNoModel":"Das ausgewaehlte Modell unterstuetzt keine Bild- oder Dokumenteingabe. Kein konfiguriertes Modell unterstuetzt aktuell Anhaenge.","attachment.attachFile":"Datei anfuegen","attachment.notSupported":"Anhaenge nicht unterstuetzt","attachment.docsContext":"Dokumente als Kontext einbezogen","attachment.docContextLabel":"Dokument als Kontext einbezogen:","attachment.docsContextLabel":"Dokumente als Kontext einbezogen:","attachment.truncated":" (gekuerzt)","attachment.truncatedHint":"Ein Teil des Dokumenttexts wurde gekuerzt, damit er ins Kontextlimit passt.","footer.status":"Arbeitsbereich-Status","footer.version":"Keiko-Version {version}","footer.versionLoading":"Version wird geladen","footer.versionUnavailable":"Version nicht verfuegbar","footer.windowSingular":"{count} Fenster","footer.windowPlural":"{count} Fenster","footer.openWindows":"Offene Fenster","footer.minimized":"Minimiert","footer.fullscreen":"Vollbild","footer.visible":"Sichtbar","footer.restore":"Wiederherstellen","footer.focus":"Fokussieren","footer.windowAction":"{action} {title}-Fenster{suffix}","scope.pressure.low":"Niedrig","scope.pressure.moderate":"Moderat","scope.pressure.high":"Hoch","scope.pressure.exceeded":"Ueberschritten","scope.budgetSummary":"Letzter Grounding-Lauf: {tokens} Token, {files} Dateien","scope.connectedFolder":"Verbundener Ordner","scope.folder":"Ordner: {name}","scope.repository":"Repository-Bereich","scope.connectedFile":"Verbundene Datei","scope.file":"Datei: {name}","scope.filesConnected":"{count} Dateien verbunden","scope.boundary.repository":"Keiko darf nur das verbundene Repository pruefen; Safe-Read-Ausschluesse und Kontextbudget-Limits gelten vor jeder Antwort.","scope.boundary.folder":"Keiko darf nur den verbundenen Ordner pruefen; Safe-Read-Ausschluesse und Kontextbudget-Limits gelten vor jeder Antwort.","scope.boundary.file":"Keiko darf nur den verbundenen Dateibereich pruefen; Safe-Read-Ausschluesse und Kontextbudget-Limits gelten vor jeder Antwort.","scope.disconnect":"{label} vom Chat trennen","scope.disconnectWithPath":"{label} vom Chat trennen ({path})","scope.disconnectError":"Bereich konnte nicht getrennt werden.","settings.title":"Einstellungen","settings.selfHosted":"Self-hosted","settings.selfHostedTitle":"Laeuft in deinem Netzwerk","settings.tabs.models":"Modelle","settings.tabs.general":"Allgemein","settings.tabs.security":"Sicherheit","settings.language.title":"Sprache","settings.language.description":"Waehle die Sprache fuer die Keiko-Browseroberflaeche.","settings.language.label":"Oberflaechensprache","settings.language.compactLabel":"Sprache","settings.language.help":"Wird auf diesem Geraet gespeichert und sofort angewendet.","settings.voice.title":"Assistenzstimme","settings.voice.description":"Waehle die Stimme fuer den Voice Dialogue.","settings.voice.label":"Stimme","settings.voice.help":"Wird auf diesem Geraet gespeichert und beim naechsten Voice-Dialogue-Sprechen verwendet.","settings.voice.unavailable":"Stimmen werden verfuegbar, sobald ein konfigurierter Sprachanbieter Sprachausgabe bereitstellt.","settings.wallpaper.title":"Arbeitsbereich-Hintergrund","settings.wallpaper.description":"Liquid Chrome - ein dezenter metallischer Verlauf hinter dem Raster, der auf Cursor und Klicks reagiert. Schalte ihn aus, um die WebGL-Animation vollstaendig zu stoppen.","settings.wallpaper.toggle":"Liquid-Hintergrund","settings.wallpaper.running":"Aktiv","settings.wallpaper.stopped":"Gestoppt","settings.wallpaper.opacity":"Hintergrund-Deckkraft","settings.scale.off":"Aus","settings.scale.full":"Voll","settings.scale.base":"Basis","settings.scale.lighter":"Heller","settings.scale.subtle":"Dezent","settings.scale.strong":"Stark","settings.workspace.backgroundBrightness":"Arbeitsbereich-Helligkeit","settings.workspace.gridStrength":"Rasterstaerke","settings.workspace.cameraAnimation":"Workspace-Kamera-Sanftheit","settings.workspace.cameraAnimationMinimal":"Minimal","settings.workspace.cameraAnimationSmooth":"Sanft","settings.workspace.cameraAnimationHelp":"Je weiter rechts, desto sanfter werden Schwenken und Zoom. Minimal wendet Aenderungen direkt an.","settings.workspace.borderStrength":"Rahmenstaerke","settings.workspace.innerGlow":"Inneres Leuchten","settings.models.gatewayTitle":"Modell-Gateway","settings.models.gatewayDescription":"Zugangsdaten werden lokal vom Keiko-Loopback-Server gespeichert; Secrets werden nie an den Browser zurueckgegeben.","settings.models.updateCredentials":"Zugangsdaten aktualisieren","settings.models.connectGateway":"Gateway verbinden","settings.models.setupRequired":"Gateway-Einrichtung erforderlich","settings.models.connected":"Gateway verbunden","settings.models.configured":"Gateway konfiguriert","settings.models.detailSetup":"Gib Gateway-Basis-URL und API-Token ein, bevor du Chat- oder Agent-Workflows nutzt.","settings.models.detailNoModels":"Das Gateway ist konfiguriert, aber aktuell sind keine dialogfaehigen Modelle verfuegbar.","settings.models.detailNoChat":"Gateway verbunden, aber keines der gefundenen Modelle kann fuer Konversationen genutzt werden. Fuege ein chatfaehiges Deployment hinzu.","settings.models.detailReady":"Keiko kann die konfigurierten Gateway-Modelle fuer Chat- und Agent-Workflows nutzen.","settings.models.modelCount":"{count} Modelle","settings.models.chatCount":"{count} Chat","settings.models.statusConfigured":"Gateway konfiguriert","settings.models.statusSetupRequired":"Einrichtung erforderlich","settings.models.statusConversationEligible":"konversationsfaehig","settings.models.statusEmbedding":"fuer Embeddings verfuegbar","settings.models.statusNotSelectable":"nicht fuer Konversationen auswaehlbar","settings.models.loadError":"Gateway-Einstellungen konnten nicht geladen werden - das lokale Keiko-Backend hat nicht geantwortet.","settings.models.retry":"Erneut versuchen","settings.models.loading":"Gateway-Modelle werden geladen...","settings.models.emptyConfigured":"Aktuell sind keine dialogfaehigen Modelle verfuegbar. Pruefe die Gateway-Konfiguration oder die gefundenen Modelle.","settings.models.emptyUnconfigured":"Noch sind keine Modelle konfiguriert. Verbinde das Gateway, um konfigurierte Modellfaehigkeiten zu laden.","settings.models.eligibilityOk":"Konversationsfaehig","settings.models.eligibilityOkAria":"Modelleignung: fuer Konversationen geeignet","settings.models.eligibilityPrefix":"Modelleignung: {label}","settings.models.embeddingLabel":"Embedding-bereit","settings.models.embeddingAvailable":"Fuer Embeddings verfuegbar; nicht in der Chat-Modellauswahl sichtbar","settings.models.ineligibleEmbedding":"Embedding-Modell - nicht fuer Textkonversationen auswaehlbar","settings.models.ineligibleOcr":"Nur OCR/Vision - nicht fuer Textkonversationen auswaehlbar","settings.models.ineligibleGeneric":"Kein Chat-Modell - nicht fuer Textkonversationen auswaehlbar","settings.models.ineligibleShortOcr":"nur OCR/Vision","settings.models.ineligibleShortGeneric":"kein Chat-Modell","settings.models.notSelectable":"Nicht auswaehlbar - {reason}","settings.models.voiceProviderAvailable":"Sprachanbieter - verfuegbar fuer {capabilities}{personas}","settings.models.voiceProviderBadge":"Sprachanbieter - {label}","settings.models.voiceCapabilitySpeechToText":"Speech-to-Text","settings.models.voiceCapabilitySpeechOutput":"Sprachausgabe","settings.models.voiceCapabilityRealtimeDialogue":"Echtzeitdialog","settings.models.voiceCapabilityVoice":"Sprache","settings.models.voicePersonas":"; Stimmen: {personas}","settings.models.readinessError":"Bereitschaftspruefung fehlgeschlagen. Die Gateway-Konfiguration wurde nicht geaendert.","settings.models.copyReport":"Bericht kopieren","settings.models.copied":"Kopiert","settings.models.reportCopied":"Bereitschaftsbericht kopiert.","settings.models.reportCopyFailed":"Zugriff auf die Zwischenablage fehlgeschlagen. Waehle die Berichtdetails aus und kopiere sie manuell.","settings.models.checkingReadiness":"Bereitschaftspruefung laeuft ({mode})...","settings.models.readinessModeDeep":"tief","settings.models.readinessModeBasic":"einfach","settings.models.workingToday":"Heute funktionsfaehig","settings.models.notVerified":"Nicht verifiziert","settings.models.verifiedCapabilities":"Verifizierte Faehigkeiten","settings.models.capabilityStreaming":"Streaming","settings.models.capabilityTools":"Tools","settings.models.capabilityJson":"JSON","settings.models.capabilityReasoning":"Reasoning","settings.models.capabilityImage":"Bild","settings.models.capabilityPdf":"PDF","settings.models.contextTokensShort":"{count} ctx","settings.models.runReadiness":"Bereitschaft pruefen","settings.models.deepProbes":"Tiefe Pruefungen","settings.models.capabilitySummary":"Tools {tools} \xb7 strukturiert {structured} \xb7 {costClass}/{latencyClass}","settings.models.yes":"ja","settings.models.no":"nein","settings.security.placeholder":"SSO \xb7 Audit-Log \xb7 Datenresidenz - bald verfuegbar."}};function ee(e,t){var n;let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return(null!=(n=Q[e][t])?n:Z[t]).replace(/\{([a-zA-Z0-9_]+)\}/gu,(e,t)=>{let n=l[t];return void 0===n?e:String(n);});}function et(){try{var e=window.localStorage.getItem(X);if(null==e)return"en";let t=e.trim().toLowerCase().replace(/_/gu,"-");return 0===t.length?"en":"de"===t||t.startsWith("de-")?"de":"en";}catch{return"en";}}let en=(0,i.createContext)({locale:"en",setLocale:()=>void 0,t:(e,t)=>ee("en",e,t)});function el(e){let{children:t}=e,[n,l]=(0,i.useState)(et);(0,i.useEffect)(()=>{"u">typeof document&&(document.documentElement.lang=n,document.documentElement.dataset.locale=n);try{window.localStorage.setItem(X,n);}catch{}},[n]);let a=(0,i.useCallback)(e=>{l(e);},[]),s=(0,i.useCallback)((e,t)=>ee(n,e,t),[n]),o=(0,i.useMemo)(()=>({locale:n,setLocale:a,t:s}),[n,a,s]);return(0,r.jsx)(en.Provider,{value:o,children:t});}function ea(){return(0,i.useContext)(en);}let er={w:150,h:110},ei={w:290,h:190},es={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"}]},chatHistory:{title:"Chat History",icon:"archive",desc:"Manage conversations",w:380,h:560,min:{w:300,h:320},tiny:{w:260,h:220},tool:!0,singleton:!0},memoria:{title:"MemoriaViva",icon:"brain",desc:"Review governed memory",w:680,h:600,min:{w:420,h:360},tiny:{w:300,h:220},tool:!0,singleton:!0},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:"Open a folder or file",w:920,h:620,min:{w:620,h:380},config:[{key:"root",label:"Folder",type:"directory",def:"",optional:!0,placeholder:"/absolute/folder/path"},{key:"file",label:"File path",type:"text",def:"",optional:!0,placeholder:"optional relative file path"}]},browser:{title:"Browser",icon:"browser",desc:"Open a URL",w:460,h:340,config:[{key:"url",label:"URL",type:"text",def:"",optional:!0,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:""}]},commands:{title:"Tasks",icon:"terminal",accent:!0,desc:"Run test/build/run tasks",w:460,h:280,tiny:{w:250,h:140},config:[{key:"projectPath",label:"Project path",type:"text",def:""}]},runtime:{title:"Runtime",icon:"cube",accent:!0,desc:"Runtime, Git, tasks, and audit",w:500,h:390,min:{w:320,h:260},tiny:{w:260,h:200},config:[{key:"projectPath",label:"Project path",type:"text",def:"",optional:!0}]},containerStatus:{title:"Containers",icon:"cube",desc:"Container engine status & diagnostics",w:460,h:320,min:{w:300,h:220},tiny:{w:250,h:160},config:[{key:"projectPath",label:"Project path",type:"text",def:"",optional:!0}]},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:"Choose a coding agent",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:"Review alerts & updates",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:"Knowledge Connector",icon:"server",accent:!0,desc:"Pick a Local Knowledge connector",w:320,h:380,min:{w:220,h:180},config:[]},localKnowledge:{title:"Local Knowledge",icon:"localKnowledge",accent:!0,desc:"Manage knowledge capsules",w:720,h:560,min:{w:360,h:320},tiny:{w:300,h:220},tool:!0,singleton:!0},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},promptEnhancer:{title:"Prompt Enhancer",icon:"spark",accent:!0,desc:"Turn a raw prompt into a governed, reviewable Enhanced Prompt",w:880,h:720,min:{w:520,h:420},tiny:{w:320,h:240},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:"Manage Figma snapshots",w:420,h:540,min:{w:320,h:360},tiny:{w:280,h:240},tool:!0,singleton:!0},figmaView:{title:"Figma View",icon:"layers",accent:!0,desc:"Inspect a scoped Figma screen view",w:360,h:360,min:{w:300,h:260},tiny:{w:260,h:200}},figmaJson:{title:"Figma JSON",icon:"file",accent:!0,desc:"Inspect scoped Figma Screen-IR JSON",w:520,h:540,min:{w:340,h:300},tiny:{w:280,h:220}},figmaImage:{title:"Figma Image",icon:"file",accent:!0,desc:"Inspect a scoped Figma screen render",w:560,h:420,min:{w:300,h:240},tiny:{w:240,h:180}},governedGit:{title:"Git",icon:"git",accent:!0,desc:"Branch, stage, commit, and publish",w:520,h:640,min:{w:360,h:420},tiny:{w:300,h:240},tool:!0,singleton:!0,config:[{key:"projectPath",label:"Project path",type:"text",def:""}]},governedPullRequest:{title:"Pull Request",icon:"git",accent:!0,desc:"Open a review-ready PR under policy",w:540,h:680,min:{w:380,h:440},tiny:{w:320,h:260},config:[{key:"projectPath",label:"Project path",type:"text",def:""},{key:"headBranchName",label:"Head branch",type:"text",def:""}]},governedMerge:{title:"Merge",icon:"git",accent:!0,desc:"Merge a review-ready PR under policy",w:540,h:680,min:{w:380,h:440},tiny:{w:320,h:260},config:[{key:"projectPath",label:"Project path",type:"text",def:""},{key:"headBranchName",label:"Head branch",type:"text",def:""}]}},eo=new Map();function ec(e,t){eo.set(e,t);}let ed=(a={},Object.keys(es).forEach(e=>{var t,n,l;let r,i;a[e]=(r={title:(t=es[e]).title,icon:t.icon,desc:t.desc,w:t.w,h:t.h,min:null!=(n=t.min)?n:er,tiny:null!=(l=t.tiny)?l:ei,render:(t,n)=>{let l=eo.get(e);return void 0!==l?l(t,n):null;}},i={},!0===t.accent&&(i.accent=!0),!0===t.tool&&(i.tool=!0),!0===t.singleton&&(i.singleton=!0),void 0!==t.config&&(i.config=t.config),void 0!==t.cta&&(i.cta=t.cta),{...r,...i});}),a),eu={agents:["files","terminal","plugins","review","browser","agents","keiko"],chat:["files","browser","plugins","keiko","connector"],files:["agents","chat","quality","editor","promptEnhancer"],editor:["files","connector"],terminal:["agents"],plugins:["agents","chat"],review:["agents"],browser:["agents","chat"],keiko:["agents","chat"],connector:["chat","quality","editor"],quality:["files","connector","figma","figmaView","figmaJson","figmaImage"],promptEnhancer:["files"],figma:["quality"],figmaView:["quality"],figmaJson:["quality"],figmaImage:["quality"]};function ep(e,t){var n,l;return void 0!==e&&void 0!==t&&e!==t&&((null!=(n=eu[e])?n:[]).includes(t)||(null!=(l=eu[t])?l:[]).includes(e));}function em(e,t){let n="files"===e.type?e:"files"===t.type?t:null,l=null===n?null:n===e?t:e;if(null!==n&&null!==l&&("chat"===l.type||"agents"===l.type||"quality"===l.type||"editor"===l.type||"promptEnhancer"===l.type)){let e=function(e){if(void 0===e)return null;let t=e.resolvedRoot;if("string"==typeof t&&t.length>0)return t;let n=e.root;return"string"==typeof n&&n.length>0?n:null;}(n.cfg);return null===e?"no folder selected":`uses ${function(e,t){var n,l,a;let r=null==e?void 0:e.activeFilePath;if("string"==typeof r&&r.length>0)return null!=(l=r.split(/[/\\]/u).filter(Boolean).pop())?l:r;let i=null==e?void 0:e.activeDirectoryPath;return"string"==typeof i&&i.length>0?`${null!=(a=i.split(/[/\\]/u).filter(Boolean).pop())?a:i}/`:`${null!=(n=t.split(/[/\\]/u).filter(Boolean).pop())?n:t}/`;}(n.cfg,e)}`;}let a=[e.type,t.type];if(a.includes("connector"))return"uses knowledge";if(a.includes("figmaJson"))return"uses JSON";if(a.includes("figmaImage"))return"uses image";if(a.includes("figmaView"))return"uses view";if(a.includes("figma")){var r;let n="figma"===e.type?e:"figma"===t.type?t:null,l=null==n||null==(r=n.cfg)?void 0:r.selectedScreenName;return"string"==typeof l&&l.trim().length>0?"uses view":"uses snapshot";}return a.includes("keiko")?"governed by":"agents"===a[0]&&"agents"===a[1]?"delegates":a.includes("terminal")?"runs in":a.includes("plugins")?"uses tools":a.includes("review")?"reviews":a.includes("browser")?"browses":"connected";}function eh(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}};}function ef(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":{let e=n("file"),t=n("root");return null!==e&&null!==t?`${e} — ${t}`:e;}case"terminal":return n("cwd");case"commands":case"runtime":return n("projectPath");case"review":{let e=n("base"),t=n("head");return null!==e&&null!==t?`${e} → ${t}`:null;}case"agents":return n("role");case"chat":{let e=n("title");return null!==e&&"New chat"!==e?e:null;}case"figma":case"figmaView":return n("selectedScreenName");case"figmaJson":var l;return null!=(l=n("selectedScreenName"))?l:n("screenId");default:return null;}}let eg=(0,i.memo)(function(e){let{winCount:t,windows:n,windowPaletteOpen:l,onToggleWindowPalette:a,onSelectWindow:s,onCloseWindowPalette:o,statusRef:c}=e,{t:d}=ea(),u=(0,i.useRef)(null),[p,h]=(0,i.useState)(d("footer.versionLoading")),f=1===t?d("footer.windowSingular",{count:t}):d("footer.windowPlural",{count:t}),g=(0,i.useMemo)(()=>[...n].sort((e,t)=>t.z-e.z),[n]);return(0,i.useEffect)(()=>{let e=!1;return async function(){try{let t=await(0,m.T7)();e||h(t.version);}catch{e||h(d("footer.versionUnavailable"));}}(),()=>{e=!0;};},[d]),(0,i.useEffect)(()=>{if(!l)return;if(0===t)return void o();let e=e=>{let t=e.target;t instanceof Node&&null!==u.current&&!u.current.contains(t)&&o();},n=e=>{"Escape"===e.key&&o();};return document.addEventListener("pointerdown",e),document.addEventListener("keydown",n),()=>{document.removeEventListener("pointerdown",e),document.removeEventListener("keydown",n);};},[o,t,l]),(0,r.jsxs)("footer",{ref:c,className:"footer mono",tabIndex:-1,"aria-label":d("footer.status"),"aria-live":"polite",children:[(0,r.jsx)("span",{className:"spacer"}),(0,r.jsxs)("span",{className:"ft-brand","aria-label":d("footer.version",{version:p}),children:["Keiko | ",p]}),(0,r.jsxs)("span",{className:"ft-window-wrap",ref:u,children:[(0,r.jsxs)("button",{type:"button",className:"ft-seg ft-accent ft-window-trigger","aria-atomic":"true","aria-expanded":l,"aria-controls":"footer-window-palette",disabled:0===t,onClick:a,children:[(0,r.jsx)($.F.tile,{size:13})," ",f]}),l&&t>0?(0,r.jsxs)("div",{id:"footer-window-palette",className:"ft-window-palette",role:"group","aria-label":d("footer.openWindows"),children:[(0,r.jsx)("div",{className:"ft-window-palette-head",children:d("footer.openWindows")}),(0,r.jsx)("div",{className:"ft-window-list",children:g.map(e=>{let t=ed[e.type],n=$.F[t.icon],l=ef(e.type,e.cfg),a=!0===e.minimized?d("footer.minimized"):e.max?d("footer.fullscreen"):d("footer.visible"),i=!0===e.minimized?d("footer.restore"):d("footer.focus"),o=null!==l?` - ${l}`:"";return(0,r.jsxs)("button",{type:"button",className:"ft-window-card","data-minimized":!0===e.minimized?"true":"false","aria-label":d("footer.windowAction",{action:i,title:t.title,suffix:o}),onClick:()=>s(e.id),children:[(0,r.jsx)("span",{className:"ft-window-icon",style:{color:!0===t.accent?"var(--accent)":void 0},children:(0,r.jsx)(n,{size:14})}),(0,r.jsxs)("span",{className:"ft-window-copy",children:[(0,r.jsx)("span",{className:"ft-window-title",children:t.title}),(0,r.jsx)("span",{className:"ft-window-sub",title:null!=l?l:a,children:null!=l?l:a})]}),(0,r.jsx)("span",{className:"ft-window-state",children:a})]},e.id);})})]}):null]})]});}),ev=(0,i.memo)(function(e){let{onTileAll:t,onSplitFront:n,onCascade:l,contextControl:a}=e,{t:i}=ea();return(0,r.jsxs)("header",{className:"header",children:[(0,r.jsxs)("div",{className:"hd-brand",children:[(0,r.jsx)("img",{className:"hd-logo",src:"/assets/keiko-logo.svg",alt:""}),(0,r.jsx)("span",{className:"hd-wordmark",children:"Keiko"})]}),void 0!==a?(0,r.jsx)("div",{className:"hd-context",children:a}):null,(0,r.jsx)("span",{className:"spacer"}),(0,r.jsxs)("div",{className:"hd-tools",children:[(0,r.jsx)("button",{type:"button",className:"hd-tool ui-tip",onClick:t,"data-tip":i("header.tileAll"),"aria-label":i("header.tileAll"),children:(0,r.jsx)($.F.tile,{size:16})}),(0,r.jsx)("button",{type:"button",className:"hd-tool ui-tip",onClick:n,"data-tip":i("header.splitFront"),"aria-label":i("header.splitFront"),children:(0,r.jsx)($.F.split,{size:16})}),(0,r.jsx)("button",{type:"button",className:"hd-tool ui-tip",onClick:l,"data-tip":i("header.cascade"),"aria-label":i("header.cascade"),children:(0,r.jsx)($.F.cascade,{size:16})})]})]});}),eb=[{id:"chatHistory",icon:"archive"}];function ey(e){let{tool:t,label:n,active:l,onClick:a}=e,i=$.F[t.icon];return(0,r.jsx)("button",{type:"button",className:"rail-btn","data-active":l?"true":"false","data-side":"left","aria-label":n,"aria-pressed":l,"data-tip":n,onClick:a,children:void 0!==t.img?(0,r.jsx)("img",{className:"rail-img",src:t.img,alt:""}):(0,r.jsx)(i,{size:19})});}let ex=(0,i.memo)(function(e){let{openTools:t,onTool:n,onNewChat:l,theme:a,onToggleTheme:i}=e,{t:s}=ea(),o="light"===a?s("rail.darkMode"):s("rail.lightMode");return(0,r.jsxs)("nav",{className:"rail rail-left","aria-label":s("rail.primaryNavigation"),children:[(0,r.jsx)("button",{type:"button",className:"rail-new",onClick:l,"data-side":"left","aria-label":s("rail.newChat"),"data-tip":s("rail.newChat"),children:(0,r.jsx)($.F.newChat,{size:18})}),(0,r.jsx)("div",{className:"rail-div"}),(0,r.jsx)("div",{className:"rail-group",children:eb.map(e=>(0,r.jsx)(ey,{tool:e,label:s("rail.chatHistory"),active:t.has(e.id),onClick:()=>n(e.id)},e.id))}),(0,r.jsx)("span",{className:"spacer"}),(0,r.jsxs)("div",{className:"rail-group",children:[(0,r.jsx)("button",{type:"button",className:"rail-btn","data-active":t.has("memoria")?"true":"false","data-side":"left","aria-label":s("rail.memoria"),"aria-pressed":t.has("memoria"),"data-tip":s("rail.memoria"),onClick:()=>n("memoria"),children:(0,r.jsx)($.F.brain,{size:19})}),(0,r.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("quality")?"true":"false","aria-label":s("rail.quality"),"aria-pressed":t.has("quality"),"data-tip":s("rail.quality"),onClick:()=>n("quality"),children:(0,r.jsx)($.F.check,{size:19})}),(0,r.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("promptEnhancer")?"true":"false","aria-label":s("rail.promptEnhancer"),"aria-pressed":t.has("promptEnhancer"),"data-tip":s("rail.promptEnhancer"),onClick:()=>n("promptEnhancer"),children:(0,r.jsx)($.F.spark,{size:19})}),(0,r.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("governedGit")?"true":"false","aria-label":"Git","aria-pressed":t.has("governedGit"),"data-tip":"Git",onClick:()=>n("governedGit"),children:(0,r.jsx)($.F.git,{size:19})}),(0,r.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("localKnowledge")?"true":"false","aria-label":s("rail.localKnowledge"),"aria-pressed":t.has("localKnowledge"),"data-tip":s("rail.localKnowledge"),onClick:()=>n("localKnowledge"),children:(0,r.jsx)($.F.localKnowledge,{size:19})}),(0,r.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("figma")?"true":"false","aria-label":s("rail.figma"),"aria-pressed":t.has("figma"),"data-tip":s("rail.figma"),onClick:()=>n("figma"),children:(0,r.jsx)($.F.layers,{size:19})})]}),(0,r.jsx)("div",{className:"rail-div"}),(0,r.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","aria-label":o,"aria-pressed":"light"===a,"data-tip":o,onClick:i,children:"light"===a?(0,r.jsx)($.F.moon,{size:19}):(0,r.jsx)($.F.sun,{size:19})}),(0,r.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("settings")?"true":"false","aria-label":s("rail.settings"),"aria-pressed":t.has("settings"),"data-tip":s("rail.settings"),onClick:()=>n("settings"),children:(0,r.jsx)($.F.settings,{size:19})})]});}),ew=(0,i.memo)(function(e){return(0,r.jsx)("aside",{className:"rail rail-right","aria-label":"Workspace utilities",children:(0,r.jsx)("span",{className:"spacer"})});});function ej(e){return e.toFixed(2);}function ek(e){let{onNewWindow:t}=e,n=(0,i.useId)(),l=`ewb-${n.replace(/:/gu,"")}`,a=(0,i.useRef)(null),s=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=e=>{var t;null==(t=a.current)||t.setAttribute("d",function(e){var t,n,l,a;let r=[];for(let t=0;t<150;t++){let n=t/150*Math.PI*2,l=1+.07*(.55*Math.sin(3*n+e)+.32*Math.sin(5*n-.8*e+1.7)+.22*Math.sin(2*n+.5*e+.4));r.push([140+127.44000000000001*l*Math.cos(n),140+118*l*Math.sin(n)]);}let i=`M${ej(null!=(t=null==(l=r[0])?void 0:l[0])?t:140)} ${ej(null!=(n=null==(a=r[0])?void 0:a[1])?n:140)} `;for(let e=0;e<r.length;e++){let t=r[(e-1+r.length)%r.length],n=r[e],l=r[(e+1)%r.length],a=r[(e+2)%r.length],s=n[0]+(l[0]-t[0])/6,o=n[1]+(l[1]-t[1])/6,c=l[0]-(a[0]-n[0])/6,d=l[1]-(a[1]-n[1])/6;i+=`C${ej(s)} ${ej(o)} ${ej(c)} ${ej(d)} ${ej(l[0])} ${ej(l[1])} `;}return`${i}Z`;}(e));};if(e(.7),"function"==typeof window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches||"function"!=typeof window.requestAnimationFrame)return;let t=0,n=()=>{0!==t&&(window.cancelAnimationFrame(t),t=0);},l=n=>{e(85e-5*n),t=window.requestAnimationFrame(l);},r=()=>{0===t&&!0!==document.hidden&&(t=window.requestAnimationFrame(l));},i=()=>{!0===document.hidden?n():r();};return r(),document.addEventListener("visibilitychange",i),window.addEventListener("blur",n),window.addEventListener("focus",r),()=>{n(),document.removeEventListener("visibilitychange",i),window.removeEventListener("blur",n),window.removeEventListener("focus",r);};},[]);let o=(0,i.useCallback)(()=>{let e=s.current;null!==e&&(e.classList.remove("is-pulse"),e.getBoundingClientRect(),e.classList.add("is-pulse")),t();},[t]);return(0,r.jsx)("button",{type:"button",className:"empty-workspace-blob","aria-label":"Open a new window",onClick:o,children:(0,r.jsxs)("svg",{width:"320",height:"320",viewBox:"0 0 280 280","aria-hidden":"true",children:[(0,r.jsx)("defs",{children:(0,r.jsxs)("mask",{id:l,maskUnits:"userSpaceOnUse",x:"0",y:"0",width:"280",height:"280",children:[(0,r.jsx)("rect",{x:"0",y:"0",width:"280",height:"280",fill:"#fff"}),(0,r.jsx)("g",{transform:"translate(107,64) scale(0.080625)",children:(0,r.jsx)("g",{transform:"translate(1024 0) scale(-1 1)",children:(0,r.jsx)("g",{transform:"translate(1024,1024) scale(-0.1,-0.1)",fill:"#000",children:(0,r.jsx)("path",{d:"M3465 8223 c-144 -8 -314 -52 -408 -105 -69 -39 -146 -99 -146 -113 0 -5 30 -24 68 -42 146 -70 323 -229 377 -340 25 -49 29 -70 29 -138 -1 -72 -5 -88 -39 -160 -36 -75 -54 -95 -265 -305 -134 -132 -270 -279 -331 -355 -339 -425 -552 -896 -626 -1390 -25 -165 -25 -549 0 -720 92 -645 368 -1196 826 -1655 322 -324 710 -562 1145 -704 389 -126 793 -172 1155 -130 235 27 377 63 579 149 205 87 268 86 423 -7 102 -62 231 -115 335 -138 247 -56 562 -26 794 74 92 40 244 136 232 146 -4 3 -26 12 -48 19 -86 28 -246 116 -385 211 -162 112 -284 182 -357 207 l-48 17 40 15 c185 70 436 223 595 363 438 386 695 1014 678 1663 l-3 120 -50 -70 c-64 -90 -248 -280 -350 -362 -171 -136 -366 -255 -645 -391 -288 -140 -442 -243 -590 -391 -136 -137 -247 -316 -325 -526 -47 -127 -114 -262 -160 -326 -79 -107 -237 -224 -384 -283 -136 -55 -355 -96 -514 -96 -274 0 -548 71 -832 215 -242 123 -375 216 -553 389 -175 171 -287 332 -361 517 -44 114 -63 216 -63 359 0 152 17 233 74 350 35 70 59 102 136 179 l95 94 21 -29 c55 -75 219 -277 277 -338 171 -183 337 -256 582 -256 56 0 126 -3 155 -7 53 -6 54 -7 76 -57 30 -66 97 -128 172 -156 151 -57 318 11 395 160 33 62 34 193 3 261 -30 64 -88 125 -148 157 -44 23 -63 27 -141 27 -78 0 -97 -4 -140 -27 -58 -30 -131 -105 -141 -142 -6 -25 -8 -26 -93 -26 -47 0 -131 5 -186 10 -87 8 -111 15 -182 51 -45 22 -109 66 -143 96 -59 53 -326 361 -319 367 14 11 179 47 241 52 102 9 177 -7 318 -66 158 -66 243 -89 357 -99 157 -12 413 5 582 40 l93 19 44 -39 c59 -52 135 -75 228 -69 117 8 212 72 262 176 23 47 28 71 28 138 0 70 -4 89 -29 138 -55 110 -145 167 -270 174 -65 3 -91 0 -137 -18 -107 -40 -183 -140 -195 -257 l-6 -52 -51 -11 c-104 -23 -285 -41 -411 -42 -149 -1 -211 12 -402 88 -186 74 -256 88 -403 81 -193 -8 -377 -70 -546 -182 -342 -228 -485 -611 -399 -1064 30 -157 119 -388 209 -541 20 -35 35 -64 33 -66 -8 -8 -111 108 -190 214 -154 206 -278 489 -324 737 -28 154 -25 492 6 635 46 216 133 391 256 514 82 82 161 128 271 156 152 39 300 23 529 -57 217 -76 308 -101 410 -114 137 -17 284 -7 426 30 272 70 414 145 809 425 217 153 399 238 610 283 64 14 129 18 265 18 197 0 269 -9 615 -76 461 -89 843 -149 952 -149 41 0 41 0 23 -20 -28 -31 -169 -119 -254 -158 -167 -77 -388 -145 -716 -222 -399 -93 -508 -128 -608 -194 -102 -68 -160 -160 -217 -346 -35 -115 -102 -286 -149 -378 -85 -168 -227 -341 -377 -458 -105 -82 -115 -107 -69 -162 29 -34 65 -44 109 -29 86 29 261 181 371 322 126 162 201 309 295 581 61 176 90 232 145 283 62 57 163 93 470 165 439 104 640 169 863 278 206 100 368 240 434 375 32 67 33 71 33 198 -1 120 -3 138 -34 229 -98 294 -319 655 -573 936 -381 421 -968 723 -1618 834 -448 76 -767 83 -1169 25 -80 -12 -165 -19 -190 -17 -26 3 -90 26 -146 53 -343 162 -576 233 -842 255 -114 9 -141 10 -248 3z m2926 -1227 c164 -27 346 -102 485 -202 181 -129 354 -348 354 -448 0 -64 -75 -126 -154 -126 -60 0 -63 4 -52 70 8 50 7 65 -9 100 -29 64 -74 93 -151 98 -54 4 -70 1 -107 -21 -42 -25 -61 -52 -91 -129 -25 -64 -55 -73 -246 -73 -121 0 -187 5 -248 18 -318 70 -556 242 -556 402 0 218 388 374 775 311z m-2249 -611 c119 -21 208 -50 321 -106 114 -56 177 -100 266 -184 67 -63 157 -173 148 -181 -2 -3 -61 18 -130 45 -131 52 -298 100 -427 122 -113 20 -367 17 -470 -4 -502 -106 -885 -433 -1160 -992 -70 -142 -160 -379 -160 -424 0 -9 -5 -23 -11 -31 -13 -19 -5 316 10 410 80 482 295 846 661 1117 145 107 350 197 522 228 100 18 326 18 430 0z m1485 -1456 c95 -36 119 -159 42 -223 -78 -66 -209 -1 -209 104 0 60 33 100 99 121 36 10 36 10 68 -2z m-591 -822 c29 -26 37 -42 40 -77 6 -54 -9 -86 -55 -117 -41 -28 -70 -29 -119 -4 -44 22 -62 55 -62 112 0 51 13 75 53 99 50 31 101 26 143 -13z"})})})}),(0,r.jsx)("text",{x:"140",y:"172",textAnchor:"middle",fill:"#000",fontFamily:"var(--font-ui)",fontSize:"16",fontWeight:"700",children:"Empty workspace"}),(0,r.jsx)("text",{x:"140",y:"191",textAnchor:"middle",fill:"#000",fontFamily:"var(--font-ui)",fontSize:"11",fontWeight:"400",children:"Open a window to start working"})]})}),(0,r.jsx)("g",{ref:s,className:"empty-workspace-blob__group",children:(0,r.jsx)("path",{ref:a,className:"empty-workspace-blob__fill",mask:`url(#${l})`})})]})});}function eN(e){return 0===e.button&&!(0===e.button&&e.ctrlKey);}function eS(e){return e instanceof Element&&null!==e.closest("button,input,textarea,select,a[href],summary,[contenteditable='true'],[contenteditable=''],[role='button'],[role='checkbox'],[role='dialog'],[role='link'],[role='menuitem'],[role='option'],[role='radio'],[role='switch'],[role='tab'],[data-text-selectable='true'],.dlg-overlay,.mc-dialog-backdrop,.cmdk-overlay,.window,.ws-zoom,.ws-fab,.empty-workspace-blob,.conn-badge");}function eC(e){return e instanceof Element&&null!==e.closest("input, textarea, select, [contenteditable='true'], [contenteditable=''], [data-text-selectable='true']");}function eR(){return!("u"<typeof document)&&"true"===document.documentElement.getAttribute("data-keiko-modal-open");}let eI=0,eE="",e$="";function eA(){if("u"<typeof document)return()=>void 0;let e=document.body;0===eI&&(eE=e.style.cursor,e$=e.style.userSelect,e.style.cursor="grabbing",e.style.userSelect="none"),eI+=1;let t=!1;return()=>{t||(t=!0,0===(eI=Math.max(0,eI-1))&&(e.style.cursor=eE,e.style.userSelect=e$));};}let eT="keiko.wallpaper.enabled",eF="keiko.wallpaper.opacity",eD="keiko.workspace.background.brightness",eM="keiko.workspace.grid.strength",eP="keiko.frame.border.strength",eL="keiko.frame.inner.glow.strength",eq="keiko.workspace.camera.smoothness",ez="keiko:wallpaper-enabled",eO="keiko:wallpaper-opacity",eB="keiko:workspace-background-brightness",eW="keiko:workspace-grid-strength",eK="keiko:frame-border-strength",eU="keiko:frame-inner-glow-strength",eV="keiko:workspace-camera-smoothness";function eH(e){return Number.isFinite(e)?Math.max(0,Math.min(100,e)):0;}function e_(){try{var e;if("function"!=typeof(null==(e=window.localStorage)?void 0:e.getItem))return!1;return"true"===window.localStorage.getItem(eT);}catch{return!1;}}function eG(){try{var e;if("function"!=typeof(null==(e=window.localStorage)?void 0:e.getItem))return 100;let t=window.localStorage.getItem(eF);if(null===t)return 100;return eH(Number.parseInt(t,10));}catch{return 100;}}function eJ(){try{var e;if("function"!=typeof(null==(e=window.localStorage)?void 0:e.getItem))return 0;let t=window.localStorage.getItem(eD);if(null===t)return 0;return eH(Number.parseInt(t,10));}catch{return 0;}}function eY(){try{var e;if("function"!=typeof(null==(e=window.localStorage)?void 0:e.getItem))return 28;let t=window.localStorage.getItem(eM);if(null===t)return 28;return eH(Number.parseInt(t,10));}catch{return 28;}}function eX(){try{var e;if("function"!=typeof(null==(e=window.localStorage)?void 0:e.getItem))return 42;let t=window.localStorage.getItem(eP);if(null===t)return 42;return eH(Number.parseInt(t,10));}catch{return 42;}}function eZ(){try{var e;if("function"!=typeof(null==(e=window.localStorage)?void 0:e.getItem))return 0;let t=window.localStorage.getItem(eL);if(null===t)return 0;return eH(Number.parseInt(t,10));}catch{return 0;}}function eQ(){try{var e;if("function"!=typeof(null==(e=window.localStorage)?void 0:e.getItem))return 0;let t=window.localStorage.getItem(eq);if(null!==t)return eH(Number.parseInt(t,10));let n=window.localStorage.getItem("keiko.workspace.camera.animationMode");return 100*("smooth"===n);}catch{return 0;}}function e0(e){"u">typeof document&&document.documentElement.style.setProperty("--workspace-bg-brightness",`${eH(e)}%`);}function e1(e){"u">typeof document&&document.documentElement.style.setProperty("--workspace-grid-strength",`${eH(e)}%`);}function e2(e){"u">typeof document&&document.documentElement.style.setProperty("--frame-border-strength",`${eH(e)}%`);}function e4(e){"u">typeof document&&document.documentElement.style.setProperty("--frame-inner-glow-strength",`${eH(e)}%`);}let e3=`
2
+ attribute vec2 aPos;
3
+ void main(){ gl_Position = vec4(aPos, 0.0, 1.0); }
4
+ `,e6=`
5
+ precision highp float;
6
+ uniform vec2 uRes;
7
+ uniform float uTime;
8
+ uniform float uLight; // 1 = light theme, 0 = dark; WebGL default 0 keeps failure mode dark
9
+ uniform vec2 uRip[4]; // ripple origins (0..1, y up)
10
+ uniform float uRipT[4]; // seconds since each ripple fired (large = inactive)
11
+
12
+ float hash(vec2 p){
13
+ p = fract(p * vec2(123.34, 456.21));
14
+ p += dot(p, p + 45.32);
15
+ return fract(p.x * p.y);
16
+ }
17
+ float vnoise(vec2 p){
18
+ vec2 i = floor(p), f = fract(p);
19
+ vec2 u = f * f * (3.0 - 2.0 * f);
20
+ float a = hash(i), b = hash(i + vec2(1.,0.));
21
+ float c = hash(i + vec2(0.,1.)), d = hash(i + vec2(1.,1.));
22
+ return mix(mix(a,b,u.x), mix(c,d,u.x), u.y);
23
+ }
24
+ float fbm(vec2 p){
25
+ float v = 0.0, a = 0.5;
26
+ mat2 m = mat2(1.6, 1.2, -1.2, 1.6);
27
+ for(int i = 0; i < 5; i++){ v += a * vnoise(p); p = m * p; a *= 0.5; }
28
+ return v;
29
+ }
30
+
31
+ void main(){
32
+ vec2 uv = gl_FragCoord.xy / uRes.xy;
33
+ float aspect = uRes.x / uRes.y;
34
+ vec2 p = vec2(uv.x * aspect, uv.y);
35
+
36
+ float t = uTime * 0.06;
37
+
38
+ // --- click ripples ---------------------------------------------------
39
+ float rip = 0.0;
40
+ for(int i = 0; i < 4; i++){
41
+ float age = uRipT[i];
42
+ if(age < 2.4){
43
+ vec2 rc = vec2(uRip[i].x * aspect, uRip[i].y);
44
+ float d = distance(p, rc);
45
+ float ring = sin(d * 15.0 - age * 9.0);
46
+ float env = exp(-d * 3.6) * exp(-age * 2.1);
47
+ rip += ring * env;
48
+ }
49
+ }
50
+
51
+ // --- liquid domain warp ---------------------------------------------
52
+ vec2 warp = vec2(
53
+ fbm(p * 2.1 + vec2(0.0, t)),
54
+ fbm(p * 2.1 + vec2(t, 4.7))
55
+ );
56
+ warp += rip * 0.07;
57
+
58
+ float f = fbm(p * 2.4 + warp * 1.7 + vec2(t * 0.6, 0.0));
59
+
60
+ // --- chrome banding (sharp metallic streaks) ------------------------
61
+ float bands = abs(sin((f * 4.0 + warp.x * 2.0) * 3.14159 + t * 1.4));
62
+ float chrome = pow(bands, 2.6);
63
+
64
+ // --- palette (brand) -------------------------------------------------
65
+ vec3 baseD = vec3(0.072, 0.085, 0.079); // warm near-black ~ --bg
66
+ vec3 metalD = vec3(0.205, 0.230, 0.216); // chrome mid grey
67
+ vec3 baseL = vec3(0.930, 0.942, 0.935); // near-white
68
+ vec3 metalL = vec3(0.795, 0.835, 0.812); // soft grey
69
+ vec3 green = vec3(0.306, 0.729, 0.529); // #4EBA87
70
+
71
+ vec3 base = mix(baseD, baseL, uLight);
72
+ vec3 metal = mix(metalD, metalL, uLight);
73
+
74
+ vec3 col = mix(base, metal, chrome * 0.85);
75
+
76
+ // orca-green sheen on the brightest specular ridges
77
+ float spec = smoothstep(0.80, 1.0, bands);
78
+ col += green * spec * mix(0.16, 0.085, uLight);
79
+
80
+ // ripple highlight
81
+ vec3 ripCol = mix(vec3(1.0), green, uLight);
82
+ col += ripCol * max(rip, 0.0) * 0.032;
83
+
84
+ // keep it dezent — pull back toward base
85
+ col = mix(base, col, 0.84);
86
+
87
+ gl_FragColor = vec4(col, 1.0);
88
+ }
89
+ `;function e5(e,t,n){let l=e.createShader(t);return null===l?null:(e.shaderSource(l,n),e.compileShader(l),e.getShaderParameter(l,e.COMPILE_STATUS))?l:(e.deleteShader(l),null);}function e8(){let e=(0,i.useRef)(null),[t,n]=(0,i.useState)(e_);return(0,i.useEffect)(()=>{e0(eJ()),e1(eY()),e2(eX()),e4(eZ());let e=e=>{let t=e.detail;e0("number"==typeof t?t:eJ());},t=e=>{let t=e.detail;e1("number"==typeof t?t:eY());},n=e=>{let t=e.detail;e2("number"==typeof t?t:eX());},l=e=>{let t=e.detail;e4("number"==typeof t?t:eZ());};return window.addEventListener(eB,e),window.addEventListener(eW,t),window.addEventListener(eK,n),window.addEventListener(eU,l),()=>{window.removeEventListener(eB,e),window.removeEventListener(eW,t),window.removeEventListener(eK,n),window.removeEventListener(eU,l);};},[]),(0,i.useEffect)(()=>{let e=e=>{let t=e.detail;n("boolean"==typeof t?t:e_());},t=e=>{(null===e.key||e.key===eT)&&n(e_());};return window.addEventListener(ez,e),window.addEventListener("storage",t),()=>{window.removeEventListener(ez,e),window.removeEventListener("storage",t);};},[]),(0,i.useEffect)(()=>{let n;if(!t)return;let l=e.current;if(null===l)return;let a=l.parentElement;if(null===a)return;let r=window.matchMedia("(prefers-reduced-motion: reduce)"),i=()=>{r.matches?(null==n||n(),n=void 0):void 0===n&&(n=function(e,t){var n;t.style.opacity=String(eG()/100);let l=e=>{let n=e.detail,l="number"==typeof n?n:eG();t.style.opacity=String(eH(l)/100);};window.addEventListener(eO,l);let a=null;try{a=t.getContext("webgl",{antialias:!1,alpha:!1,premultipliedAlpha:!1,depth:!1});}catch{a=null;}if(null===a)return()=>{window.removeEventListener(eO,l);};let r=e5(a,a.VERTEX_SHADER,e3),i=e5(a,a.FRAGMENT_SHADER,e6);if(null===r||null===i)return()=>{window.removeEventListener(eO,l);};let s=a.createProgram();if(null===s||(a.attachShader(s,r),a.attachShader(s,i),a.linkProgram(s),!a.getProgramParameter(s,a.LINK_STATUS)))return()=>{window.removeEventListener(eO,l);};a.useProgram(s);let o=a.createBuffer();a.bindBuffer(a.ARRAY_BUFFER,o),a.bufferData(a.ARRAY_BUFFER,new Float32Array([-1,-1,3,-1,-1,3]),a.STATIC_DRAW);let c=a.getAttribLocation(s,"aPos");a.enableVertexAttribArray(c),a.vertexAttribPointer(c,2,a.FLOAT,!1,0,0);let d=a.getUniformLocation(s,"uRes"),u=a.getUniformLocation(s,"uTime"),p=a.getUniformLocation(s,"uLight"),m=a.getUniformLocation(s,"uRip"),h=a.getUniformLocation(s,"uRipT"),f=1,g=1,v=Math.min(null!=(n=window.devicePixelRatio)?n:1,1.5),b=new Float32Array(8),y=[,,,,].fill(-1/0),x=0;function w(){let n=e.getBoundingClientRect();f=Math.max(1,Math.round(n.width)),g=Math.max(1,Math.round(n.height)),t.width=Math.round(f*v),t.height=Math.round(g*v),t.style.width=`${String(f)}px`,t.style.height=`${String(g)}px`,null!==a&&a.viewport(0,0,t.width,t.height);}w();let j="u">typeof ResizeObserver?new ResizeObserver(w):null;null!==j?j.observe(e):window.addEventListener("resize",w);let k=t=>{let n=e.getBoundingClientRect(),l=(t.clientX-n.left)/Math.max(1,n.width),a=1-(t.clientY-n.top)/Math.max(1,n.height);l<0||l>1||a<0||a>1||(b[2*x]=l,b[2*x+1]=a,y[x]=performance.now(),x=(x+1)%4);};e.addEventListener("pointerdown",k);let N=performance.now(),S=0,C=!0,R=0,I=new Float32Array(4),E=1e3/30,$=1e3/60;function A(){if(!C)return;S=requestAnimationFrame(A);let n=performance.now(),l=!function(e){for(let n=0;n<4;n++){var t;if(e-(null!=(t=y[n])?t:-1/0)<2400)return!0;}return!1;}(n)?E:$;if(n-R<l||"true"===e.dataset.panning||"true"===e.dataset.windowMaxed)return;R=n;for(let e=0;e<4;e++){var r;I[e]=(n-(null!=(r=y[e])?r:-1/0))/1e3;}let i=+("light"===document.documentElement.dataset.theme);null!==a&&(a.uniform2f(d,t.width,t.height),a.uniform1f(u,(n-N)/1e3),a.uniform1f(p,i),a.uniform2fv(m,b),a.uniform1fv(h,I),a.drawArrays(a.TRIANGLES,0,3));}S=requestAnimationFrame(A);let T=()=>{document.hidden?(C=!1,cancelAnimationFrame(S)):C||(C=!0,S=requestAnimationFrame(A));};return document.addEventListener("visibilitychange",T),()=>{C=!1,cancelAnimationFrame(S),document.removeEventListener("visibilitychange",T),window.removeEventListener(eO,l),e.removeEventListener("pointerdown",k),null!==j?j.disconnect():window.removeEventListener("resize",w),null!==a&&(a.deleteBuffer(o),a.deleteProgram(s),a.deleteShader(r),a.deleteShader(i));};}(a,l));};return i(),r.addEventListener("change",i),()=>{r.removeEventListener("change",i),null==n||n();};},[t]),t?(0,r.jsx)("canvas",{ref:e,className:"ws-shader","aria-hidden":"true"}):null;}let e9=new Set(["files","connector","browser","plugins","agents","quality"]);function e7(e,t){return e>=4||t>=8192;}function te(e){let{pathId:t,intensity:n}=e,l="heavy"===n?3:1,a="heavy"===n?1.1:2.2;return(0,r.jsx)(r.Fragment,{children:Array.from({length:l},(e,i)=>(0,r.jsx)("circle",{className:"conn-particle",r:"heavy"===n?3:2.4,"aria-hidden":"true",children:(0,r.jsx)("animateMotion",{dur:`${String(a)}s`,repeatCount:"indefinite",begin:`${String(a/l*i)}s`,rotate:"auto",keyPoints:"0;1",keyTimes:"0;1",calcMode:"linear",children:(0,r.jsx)("mpath",{href:`#${t}`})})},i))});}let tt=(0,i.memo)(function(e){let{wins:t,conns:n,connecting:l,api:a}=e,s=d(),o=function(){let[e,t]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let e=window.matchMedia("(prefers-reduced-motion: reduce)");t(e.matches);let n=e=>t(e.matches);return e.addEventListener("change",n),()=>e.removeEventListener("change",n);},[]),e;}(),{armedId:c,arm:u,disarm:p}=function(){let[e,t]=(0,i.useState)(null);return(0,i.useEffect)(()=>{if(null===e)return;let n=setTimeout(()=>t(null),3e3);return()=>clearTimeout(n);},[e]),{armedId:e,arm:e=>t(e),disarm:()=>t(null)};}(),{flowing:m,intensity:h}=function(e,t){let[n,l]=(0,i.useState)("light"),[a,r]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{if(void 0===t)return;l(function(e){switch(e.groundingKind){case"connected-context":return e7(e.contextPack.usage.filesRead,e.contextPack.usage.excerptBytes)?"heavy":"light";case"hybrid":return e7(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)),r(!0);let e=setTimeout(()=>r(!1),2500);return()=>clearTimeout(e);},[t]),{flowing:e||a,intensity:n};}((null==s?void 0:s.sending)===!0,null==s?void 0:s.latestGrounded),f=(0,i.useMemo)(()=>function(e,t){let n=new Map(e.map(e=>[e.id,e])),l=[];for(let e of t){let t=n.get(e.a),a=n.get(e.b);if(void 0===t||void 0===a)continue;let r=function(e,t){let n,l,a,r,i={x:e.x+e.w/2,y:e.y+e.h/2},s={x:t.x+t.w/2,y:t.y+t.h/2},o=s.x-i.x,c=s.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((l=o>=0?{x:t.x,y:s.y}:{x:t.x+t.w,y:s.y}).x-n.x)/2),d=o>=0?1:-1;a={x:n.x+d*c,y:n.y},r={x:l.x-d*c,y:l.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((l=c>=0?{x:s.x,y:t.y}:{x:s.x,y:t.y+t.h}).y-n.y)/2),d=c>=0?1:-1;a={x:n.x,y:n.y+d*o},r={x:l.x,y:l.y-d*o};}let d={x:(n.x+3*a.x+3*r.x+l.x)/8,y:(n.y+3*a.y+3*r.y+l.y)/8};return{d:`M${String(n.x)},${String(n.y)} C${String(a.x)},${String(a.y)} ${String(r.x)},${String(r.y)} ${String(l.x)},${String(l.y)}`,mid:d};}(t,a);l.push({c:e,d:r.d,mid:r.mid,label:em(t,a),dataChannel:function(e,t){let n=[e.type,t.type].includes("chat"),l="chat"===e.type?e9.has(t.type):e9.has(e.type);return n&&l;}(t,a)});}return l;}(t,n),[t,n]),g=null!==l?function(e,t){let n=t.find(t=>t.id===e.from);if(void 0===n)return null;let l={x:n.x+n.w/2,y:n.y+n.h/2},a=e.x-l.x,r=e.y-l.y,i=Math.abs(a)>=Math.abs(r),s=i?{x:a>=0?n.x+n.w:n.x,y:l.y}:{x:l.x,y:r>=0?n.y+n.h:n.y},o=Math.max(40,Math.abs(i?a:r)/2),c=i?{x:s.x+(a>=0?o:-o),y:s.y}:{x:s.x,y:s.y+(r>=0?o:-o)},d=e.x,u=e.y;return{d:`M${String(s.x)},${String(s.y)} C${String(c.x)},${String(c.y)} ${String(d)},${String(u)} ${String(d)},${String(u)}`,ex:d,ey:u};}(l,t):null;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"conn-layer",children:(0,r.jsxs)("svg",{className:"conn-svg",viewBox:"-10000 -10000 20000 20000",preserveAspectRatio:"xMidYMid meet",children:[f.map(e=>{let t=m&&e.dataChannel,n=`conn-path-${e.c.id}`;return(0,r.jsxs)("g",{children:[(0,r.jsx)("path",{id:n,className:"conn-path",d:e.d,"data-active":t?"true":void 0,"data-intensity":t?h:void 0,"data-reduced-motion":t&&o?"true":void 0}),t&&!o?(0,r.jsx)(te,{pathId:n,intensity:h}):null]},e.c.id);}),null!==g?(0,r.jsx)("path",{className:"conn-path conn-temp",d:g.d}):null,null!==g?(0,r.jsx)("circle",{className:"conn-dot",cx:g.ex,cy:g.ey,r:"5"}):null]})}),(0,r.jsx)("div",{className:"conn-badge-layer",children:f.map(e=>{let n,l=m&&e.dataChannel;if(!function(e,t){let n,l=arguments.length>2&&void 0!==arguments[2]&&arguments[2],a=(n=Math.min(240,Math.max(40,7.2*e.label.length))+(44+18*!!l),{left:e.mid.x-n/2,right:e.mid.x+n/2,top:e.mid.y-13,bottom:e.mid.y+13});return!t.some(e=>{var t;return!0!==e.minimized&&(t={left:e.x,top:e.y,right:e.x+e.w,bottom:e.y+e.h},a.left<t.right&&a.right>t.left&&a.top<t.bottom&&a.bottom>t.top);});}(e,t,l))return null;let i=c===e.c.id,s=(n=[`Connection: ${e.label}`],void 0!==e.c.boundRoot&&n.push(`Root: ${e.c.boundRoot}`),void 0!==e.c.boundScopeKind&&n.push(`Scope: ${e.c.boundScopeKind}`),void 0!==e.c.boundRelativePath&&e.c.boundRelativePath.length>0&&n.push(`Path: ${e.c.boundRelativePath}`),void 0!==e.c.boundConnectorKind&&void 0!==e.c.boundConnectorId&&n.push(`Knowledge: ${e.c.boundConnectorKind} ${e.c.boundConnectorId}`),n.join("\n"));return(0,r.jsxs)("button",{type:"button",className:"conn-badge","data-active":l?"true":void 0,"data-intensity":l?h:void 0,"data-armed":i?"true":void 0,style:{left:e.mid.x,top:e.mid.y},onClick:()=>{i?(p(),a.removeConn(e.c.id)):u(e.c.id);},onBlur:()=>{i&&p();},title:i?`Click again to remove: ${e.label}
90
+
91
+ ${s}`:`${s}
92
+
93
+ Click once to arm removal.`,"aria-label":i?`Confirm removal of connection: ${e.label}. Activate again to remove.`:l?`${e.label} — ${h} data exchange in progress. Activate to remove connection.`:`Remove connection: ${e.label}`,children:[(0,r.jsx)($.F.git,{size:11})," ",(0,r.jsx)("span",{children:i?"Remove?":e.label}),l&&!i?(0,r.jsx)("span",{className:"conn-flow-tag","aria-hidden":"true",children:"heavy"===h?"⇶":"→"}):null]},e.c.id);})})]});}),tn=["n","s","e","w","ne","nw","se","sw"],tl=["t","r","b","l"];function ta(e){let{icon:t,label:n}=e,l=$.F[t];return(0,r.jsxs)("div",{className:"too-small",children:[(0,r.jsx)("div",{className:"ts-ico",children:(0,r.jsx)(l,{size:28})}),(0,r.jsxs)("div",{className:"ts-title",children:["Too small to show ",n]}),(0,r.jsx)("div",{className:"ts-sub",children:"Enlarge the window or zoom its content out"}),(0,r.jsx)("div",{className:"ts-arrow","aria-hidden":"true",children:(0,r.jsx)("svg",{width:"22",height:"22",viewBox:"0 0 22 22",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("path",{d:"M8 8l8 8M16 11v5h-5"})})})]});}function tr(e,t){return"figmaView"===e&&"string"==typeof t.selectedScreenIdsJson&&t.selectedScreenIdsJson.length>0;}function ti(e,t){return e.x===t.x&&e.y===t.y&&e.w===t.w&&e.h===t.h;}let ts=Object.freeze([]),to=Object.freeze({linkedRoot:null,linkedFilePath:void 0,linkedRoots:ts,linkedCapsuleIds:ts,linkedCapsuleSetIds:ts,linkedFigmaSnapshotRunIds:ts,linkedFigmaSnapshotSources:void 0,linkedImageSources:void 0}),tc=(0,i.memo)(function(e){var t,n,l,a,s;let{win:o,top:c,connState:d,api:p,wsRef:m,linkRevision:h}=e,f=ed[o.type],g=void 0!==(a=o.type)&&((null!=(s=eu[a])?s:[]).length>0||Object.values(eu).some(e=>e.includes(a))),v=$.F[f.icon],b=(0,i.useContext)(u),y=null!=(t=null==b?void 0:b.activeRoot)?t:null,x=null!=(n=null==b?void 0:b.activeBinding)?n:null,[w,j]=(0,i.useState)(!1),k=(0,i.useRef)(null),N=(0,i.useRef)(null),S=(0,i.useRef)(null),C=null!=(l=o.zoom)?l:1,R=function(e,t){if(!tr(e,t))return null;let n="string"==typeof t.snapshotRunId?t.snapshotRunId:"",l="string"==typeof t.selectedScreenIdsJson?t.selectedScreenIdsJson:"",a="string"==typeof t.selectedScreenName?t.selectedScreenName:"";return`${n}
94
+ ${l}
95
+ ${a}`;}(o.type,o.cfg),I=(0,i.useMemo)(()=>{var e,t,n,l,a;let r,i,s,c,d,u,m,h;return e=o.type,t=o.id,r="quality"===e||"editor"===e,i="chat"===e||"agents"===e||"quality"===e||"editor"===e||"promptEnhancer"===e?p.linkedFilesRoot(t):null,s="agents"===e||"quality"===e||"editor"===e||"promptEnhancer"===e?null==(n=p.linkedFilesContext(t))?void 0:n.activeFilePath:void 0,c="quality"===e||"promptEnhancer"===e?p.linkedAllFilesRoots(t):null!==i?[i]:ts,d=r?p.linkedConnectorCapsuleIds(t):ts,u=r?p.linkedConnectorCapsuleSetIds(t):ts,m="quality"===e?p.linkedFigmaSnapshotRunIds(t):ts,null===(h={linkedRoot:i,linkedFilePath:s,linkedRoots:c,linkedCapsuleIds:d,linkedCapsuleSetIds:u,linkedFigmaSnapshotRunIds:m,linkedFigmaSnapshotSources:"quality"===e?null==(l=p.linkedFigmaSnapshotSources)?void 0:l.call(p,t):void 0,linkedImageSources:"quality"===e?null==(a=p.linkedImageSources)?void 0:a.call(p,t):void 0}).linkedRoot&&void 0===h.linkedFilePath&&0===h.linkedRoots.length&&0===h.linkedCapsuleIds.length&&0===h.linkedCapsuleSetIds.length&&0===h.linkedFigmaSnapshotRunIds.length&&(void 0===h.linkedFigmaSnapshotSources||0===h.linkedFigmaSnapshotSources.length)&&(void 0===h.linkedImageSources||0===h.linkedImageSources.length)?to:h;},[p,o.type,o.id,h]),E=Math.round(o.w/C*1e3)/1e3,A=Math.round(o.h/C*1e3)/1e3,T=(0,i.useCallback)(e=>{p.update(o.id,{cfg:{...o.cfg,...e}});},[p,o.cfg,o.id]),F=(0,i.useCallback)((e,t)=>p.add(e,t),[p]),D=(0,i.useCallback)(e=>p.openEditorFile(e),[p]),{mode:M,node:P}=(0,i.useMemo)(()=>function(e,t,n,l,a,i,s,o,c,d,u,p,m,h,f,g,v,b){let y=ed[t];if("chat"===t){let t=n<520,r=n<430;return{mode:r?"mini":"full",node:y.render(a,{windowId:e,mini:r,minimalChat:n<360||l<320,compact:n<640,controlsNarrow:t,barCompact:n<520,workflowCompact:t,linkedRoot:i,linkedFilePath:s,linkedRoots:o,linkedCapsuleIds:c,linkedCapsuleSetIds:d,linkedFigmaSnapshotRunIds:u,linkedFigmaSnapshotSources:p,linkedImageSources:m,activeRoot:h,activeBinding:f,updateCfg:g,openWindow:v,openEditorFile:b})};}return n<y.tiny.w||l<y.tiny.h?{mode:"tiny",node:(0,r.jsx)(ta,{icon:y.icon,label:y.title})}:{mode:"full",node:y.render(a,{windowId:e,linkedRoot:i,linkedFilePath:s,linkedRoots:o,linkedCapsuleIds:c,linkedCapsuleSetIds:d,linkedFigmaSnapshotRunIds:u,linkedFigmaSnapshotSources:p,linkedImageSources:m,activeRoot:h,activeBinding:f,updateCfg:g,openWindow:v,openEditorFile:b})};}(o.id,o.type,E,A,o.cfg,I.linkedRoot,I.linkedFilePath,I.linkedRoots,I.linkedCapsuleIds,I.linkedCapsuleSetIds,I.linkedFigmaSnapshotRunIds,I.linkedFigmaSnapshotSources,I.linkedImageSources,y,x,T,F,D),[o.id,o.type,o.cfg,E,A,I,y,x,T,F,D]),L=(0,i.useCallback)(e=>p.update(o.id,{zoom:Math.max(.5,Math.min(2,Math.round(10*e)/10))}),[p,o.id]);(0,i.useEffect)(()=>{S.current!==R&&(S.current=null);},[R]);let q=(0,i.useCallback)(()=>{null!==R&&(S.current=R);},[R]);(0,i.useEffect)(()=>{if(!tr(o.type,o.cfg)||o.max||"full"!==M||null===R)return;let e=k.current;if(null===e)return;let t=null,n=()=>{if(t=null,S.current===R)return;let n=e.scrollHeight-e.clientHeight;if(n<=8)return;let l=Math.ceil(o.h+n);l<=o.h+8||p.update(o.id,{h:l});},l=()=>{null===t&&(t="function"==typeof window.requestAnimationFrame?window.requestAnimationFrame(n):window.setTimeout(n,0));};l();let a="u">typeof ResizeObserver?new ResizeObserver(l):null;null==a||a.observe(e);let r=e.firstElementChild;return null!==r&&(null==a||a.observe(r)),()=>{null!==t&&("function"==typeof window.cancelAnimationFrame?window.cancelAnimationFrame(t):window.clearTimeout(t)),null==a||a.disconnect();};},[p,M,R,o.cfg,o.h,o.id,o.max,o.type]),(0,i.useEffect)(()=>()=>{var e;null==(e=N.current)||e.call(N),N.current=null;},[]);let z=(0,i.useCallback)(e=>{eC(e)?window.setTimeout(()=>p.focus(o.id),180):e instanceof Element&&null!==e.closest("button,input,textarea,select,a[href],summary,[contenteditable='true'],[contenteditable=''],[role='button'],[role='checkbox'],[role='link'],[role='menuitem'],[role='option'],[role='radio'],[role='switch'],[role='tab'],[data-text-selectable='true']")?window.setTimeout(()=>p.focus(o.id),0):p.focus(o.id);},[p,o.id]),O=(0,i.useCallback)(e=>{var t,n,l,a,r,i,s,c,u;let h,f,g,v,b,y,x,w,k,N,S,C,R,I;if(!(eN(u=e)||1===u.button)||"valid"===d)return;e.preventDefault(),z(e.target);let E=m.current;if(null===E)return;let $=(r=E.getBoundingClientRect(),{z:h=(i=p.currentView()).zoom,vpx0:-i.x/h,vpy0:-i.y/h,vpw:r.width/h,vph:r.height/h,toWX:e=>(e-r.left-i.x)/h,toWY:e=>(e-r.top-i.y)/h}),A=o.max,T=A?null!=(t=null==(l=o.prev)?void 0:l.w)?t:480:o.w,F=A?null!=(n=null==(a=o.prev)?void 0:a.h)?n:360:o.h,D=A?T/2:$.toWX(e.clientX)-o.x,M=A?18:$.toWY(e.clientY)-o.y;A&&p.update(o.id,{max:!1,w:T,h:F}),j(!0),s={winId:o.id,offX:D,offY:M,W:T},c=()=>j(!1),g=30/$.z,v=0,b=0,y=null,x=!1,w=null,k=null,N=null,S=()=>{N=null,x&&(x=!1,y!==f&&(f=y,p.setSnap(y)),(v!==w||b!==k)&&(w=v,k=b,p.update(s.winId,{x:v,y:b})));},C=e=>{let t,n,l,a,r=$.toWX(e.clientX),i=$.toWY(e.clientY),o=r-s.offX,c=i-s.offY;o=Math.max($.vpx0-(s.W-120),Math.min($.vpx0+$.vpw-120,o)),c=Math.max($.vpy0,Math.min($.vpy0+$.vph-38,c)),v=o,b=c,t=r-$.vpx0<g,n=$.vpx0+$.vpw-r<g,l=i-$.vpy0<g,a=$.vpy0+$.vph-i<g,y=l&&t?"tl":l&&n?"tr":a&&t?"bl":a&&n?"br":t?"left":n?"right":l?"maxi":null,x=!0,null===N&&(N="function"==typeof window.requestAnimationFrame?window.requestAnimationFrame(S):window.setTimeout(S,0));},R=()=>{window.removeEventListener("pointermove",C),window.removeEventListener("pointerup",R),window.removeEventListener("pointercancel",R),null!==N&&("function"==typeof window.cancelAnimationFrame?window.cancelAnimationFrame(N):window.clearTimeout(N),N=null),S(),p.commitSnap(s.winId),I(),null==c||c();},I=eA(),window.addEventListener("pointermove",C),window.addEventListener("pointerup",R),window.addEventListener("pointercancel",R);},[p,o.id,o.x,o.y,o.w,o.h,o.max,o.prev,m,d,z]),B=(0,i.useCallback)(e=>t=>{var n;if(!eN(t))return;t.preventDefault(),t.stopPropagation(),null==(n=N.current)||n.call(N),N.current=null,p.focus(o.id);let l={x:o.x,y:o.y,w:o.w,h:o.h},a=l,r=t.clientX,i=t.clientY,s=p.currentView().zoom,c=document.body.style.cursor,d=!0,u=null,m=null,h=()=>{if(m=null,null===u)return;let e=u;u=null,ti(a,e)||(a=e,p.update(o.id,{...e,max:!1}));},f=function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];d&&(d=!1,window.removeEventListener("pointermove",v),window.removeEventListener("pointerup",g),window.removeEventListener("pointercancel",g),window.removeEventListener("blur",g),e?null!==u&&null===m&&(m="function"==typeof window.requestAnimationFrame?window.requestAnimationFrame(h):window.setTimeout(h,0)):(null!==m&&("function"==typeof window.cancelAnimationFrame?window.cancelAnimationFrame(m):window.clearTimeout(m),m=null),u=null),document.body.style.cursor=c,N.current===f&&(N.current=null));},g=()=>{f(!0);},v=t=>{var n;!d||(0===t.buttons?f(!0):(n=function(e,t,n,l,a){let{x:r,y:i,w:s,h:o}=e;t.includes("e")&&(s=e.w+n),t.includes("s")&&(o=e.h+l),t.includes("w")&&(s=e.w-n,r=e.x+n),t.includes("n")&&(o=e.h-l,i=e.y+l);let c=ed[a].min,d=c.w>0?c.w:240,u=c.h>0?c.h:150;return s<d&&(t.includes("w")&&(r-=d-s),s=d),o<u&&(t.includes("n")&&(i-=u-o),o=u),{x:r,y:i,w:s,h:o};}(l,e,(t.clientX-r)/s,(t.clientY-i)/s,o.type),null!==u&&ti(u,n)||null===u&&ti(a,n)||(q(),u=n,null===m&&(m="function"==typeof window.requestAnimationFrame?window.requestAnimationFrame(h):window.setTimeout(h,0)))));};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",v),window.addEventListener("pointerup",g),window.addEventListener("pointercancel",g),window.addEventListener("blur",g),N.current=f;},[p,o.id,o.x,o.y,o.w,o.h,o.type,q]),W=(0,i.useCallback)((e,t)=>{let n=e.getBoundingClientRect();p.startConnect(o.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()});},[p,o.id]),K=(0,i.useCallback)(e=>{eN(e)&&(e.preventDefault(),e.stopPropagation(),W(e.currentTarget,e));},[W]),U=(0,i.useCallback)(e=>{if("Enter"===e.key||" "===e.key||"Spacebar"===e.key){if("valid"===d)return void p.confirmConnect(o.id,{preventDefault:()=>e.preventDefault(),stopPropagation:()=>e.stopPropagation()});e.preventDefault(),e.stopPropagation(),W(e.currentTarget,e);}},[W,d,p,o.id]),V=(0,i.useCallback)(()=>{p.close(o.id),requestAnimationFrame(()=>{var e;let t=null!=(e=document.querySelector('.window[data-top="true"]'))?e:document.querySelector(".ws-fab");null==t||t.focus({preventScroll:!0});});},[p,o.id]),H=(0,i.useCallback)(()=>{p.minimize(o.id),requestAnimationFrame(()=>{var e;let t=null!=(e=document.querySelector('.window[data-top="true"]'))?e:document.querySelector(".ws-fab");null==t||t.focus({preventScroll:!0});});},[p,o.id]),_="full"===M?ef(o.type,o.cfg):null,G="full"===M&&E>=340,J="full"===M&&"editor"!==o.type,Y=(0,i.useMemo)(()=>J?{contain:"layout style",contentVisibility:"auto",containIntrinsicSize:`${String(Math.round(E))}px ${String(Math.round(A))}px`}:{contain:"layout style"},[J,E,A]),X=(0,i.useMemo)(()=>({left:o.x,top:o.y,width:o.w,height:o.h,zIndex:o.z}),[o.x,o.y,o.w,o.h,o.z]),Z=(0,i.useMemo)(()=>({width:E,height:A,transform:`scale(${String(C)})`,transformOrigin:"0 0"}),[E,A,C]);return(0,r.jsxs)("section",{className:"window","aria-label":null!==_?`${f.title} — ${_}`:f.title,"aria-roledescription":"window","data-top":c?"true":"false","data-max":o.max?"true":"false","data-conn":null!=d?d:void 0,"data-dragging":w?"true":void 0,"data-window-id":o.id,style:X,tabIndex:-1,onPointerDown:e=>{"valid"===d&&p.confirmConnect(o.id,e),z(e.target);},onFocusCapture:()=>{c||window.setTimeout(()=>p.focus(o.id),0);},children:[(0,r.jsxs)("div",{className:"win-content-zoom",style:Z,children:[(0,r.jsxs)("header",{className:"win-head",onPointerDown:O,onDoubleClick:e=>{(function(e){let t=e.target;if(t instanceof Element&&null!==t.closest("button,[role='button']"))return!1;let n=e.currentTarget.getBoundingClientRect(),l=Math.min(210,n.width/2);return e.clientX<n.right-l;})(e)&&p.maximize(o.id);},children:[(0,r.jsx)("span",{className:"win-ico",style:{color:!0===f.accent?"var(--accent)":"var(--fg-muted)"},children:(0,r.jsx)(v,{size:14})}),(0,r.jsx)("span",{className:"win-title",children:f.title}),null!==_?(0,r.jsx)("span",{className:"win-sub mono",title:_,children:(0,r.jsx)("span",{className:"win-sub-text",children:_})}):null,(0,r.jsx)("span",{className:"spacer"}),G?(0,r.jsxs)("div",{className:"win-zoom",children:[(0,r.jsx)("button",{type:"button",className:"win-zbtn ui-tip","data-tip":"Zoom content out","aria-label":`Zoom ${f.title} content out`,disabled:C<=.5,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>{e.stopPropagation();},onClick:()=>L(C-.1),children:(0,r.jsx)($.F.zoomOut,{size:13})}),(0,r.jsxs)("button",{type:"button",className:"win-zpct ui-tip","data-tip":"Reset content zoom to 100%","aria-label":`${String(Math.round(100*C))}% — reset ${f.title} content zoom`,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>{e.stopPropagation();},onClick:()=>p.update(o.id,{zoom:1}),children:[Math.round(100*C),"%"]}),(0,r.jsx)("button",{type:"button",className:"win-zbtn ui-tip","data-tip":"Zoom content in","aria-label":`Zoom ${f.title} content in`,disabled:C>=2,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>{e.stopPropagation();},onClick:()=>L(C+.1),children:(0,r.jsx)($.F.zoomIn,{size:13})})]}):null,(0,r.jsxs)("div",{className:"win-traffic",role:"group","aria-label":`${f.title} window controls`,children:[(0,r.jsx)("button",{type:"button",className:"win-traffic-btn win-traffic-minimize ui-tip","data-tip":"Minimize","aria-label":`Minimize ${f.title} window`,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>{e.stopPropagation();},onClick:H,children:(0,r.jsx)($.F.minimize,{size:17})}),(0,r.jsx)("button",{type:"button",className:"win-traffic-btn win-traffic-maximize ui-tip","data-tip":o.max?"Restore":"Full screen","aria-label":o.max?`Restore ${f.title} window`:`Full screen ${f.title} window`,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>{e.stopPropagation();},onClick:()=>p.maximize(o.id),children:o.max?(0,r.jsx)($.F.restore,{size:17}):(0,r.jsx)($.F.maximize,{size:17})}),(0,r.jsx)("button",{type:"button",className:"win-traffic-btn win-traffic-close ui-tip","data-tip":"Close","aria-label":`Close ${f.title} window`,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>{e.stopPropagation();},onClick:V,children:(0,r.jsx)($.F.close,{size:17})})]})]}),(0,r.jsx)("div",{ref:k,className:"win-body","data-mode":M,style:Y,children:P})]}),o.max?null:tn.map(e=>(0,r.jsx)("div",{className:`wz wz-${e}`,onPointerDown:B(e)},e)),!o.max&&g?tl.map(e=>(0,r.jsx)("button",{type:"button",className:`win-port wp-${e}`,title:"Click to connect to another window","aria-label":`Connect ${f.title} from ${"t"===e?"top":"r"===e?"right":"b"===e?"bottom":"left"} edge`,onPointerDown:K,onKeyDown:U},`p${e}`)):null]});}),td=[/\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-----/],tu=/\b(?:\d[ -]?){13,19}\b/g;n(63680);let tp={chat:{lifecycle:["draft","streaming","final","archived"],trustBoundary:["ui","model","evidence"],authority:"user-confirm",persistence:"durable.ui"},chatHistory:{lifecycle:["live","archived"],trustBoundary:["ui"],authority:"user-confirm",persistence:"durable.ui"},memoria:{lifecycle:["live","needs-review","archived"],trustBoundary:["ui","memory"],authority:"user-confirm",persistence:"memory-reference"},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"},localKnowledge:{lifecycle:["idle","connecting","connected","degraded","disconnected","error"],trustBoundary:["ui","fs","model"],authority:"user-confirm",persistence:"durable.ui"},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"},commands:{lifecycle:["idle","running","blocked","cancelled","error"],trustBoundary:["ui","fs","tool"],authority:"user-confirm",persistence:"fs-reference"},runtime:{lifecycle:["idle","connected","degraded","running","blocked","error"],trustBoundary:["ui","fs","tool","evidence"],authority:"user-confirm",persistence:"fs-reference"},containerStatus:{lifecycle:["idle","connecting","connected","degraded","running","blocked","error"],trustBoundary:["ui","fs","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"},promptEnhancer:{lifecycle:["idle","running","results","error"],trustBoundary:["ui","model","evidence"],authority:"user-confirm",persistence:"transient"},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"},figmaView:{lifecycle:["idle","results","error"],trustBoundary:["ui","evidence"],authority:"user-confirm",persistence:"evidence-reference"},figmaJson:{lifecycle:["idle","results","error"],trustBoundary:["ui","evidence"],authority:"user-confirm",persistence:"evidence-reference"},figmaImage:{lifecycle:["idle","results","error"],trustBoundary:["ui","evidence","model"],authority:"user-confirm",persistence:"evidence-reference"},governedGit:{lifecycle:["idle","running","blocked","cancelled","error"],trustBoundary:["ui","fs","tool","evidence"],authority:"user-confirm",persistence:"fs-reference"},governedPullRequest:{lifecycle:["idle","running","blocked","cancelled","error"],trustBoundary:["ui","fs","tool","evidence"],authority:"user-confirm",persistence:"fs-reference"},governedMerge:{lifecycle:["idle","running","blocked","cancelled","error"],trustBoundary:["ui","fs","tool","evidence"],authority:"user-confirm",persistence:"fs-reference"}},tm=["apikey","accesskey","clientsecret","credential","password","privatekey","secret","token"],th=["api_key=","apikey=","client_secret=","clientsecret=","credential=","authorization:","password=","secret=","token="],tf=[".env",".env.local",".env.development",".env.test",".env.production"],tg={chat:["chatId"],editor:["openFiles","layoutJson"],files:["activeFilePath","activeDirectoryPath","resolvedRoot"],figma:["snapshotRunId","selectedScreenIdsJson","selectedScreenName"],figmaView:["snapshotRunId","selectedScreenIdsJson","selectedScreenName"],figmaJson:["snapshotRunId","screenId","selectedScreenIdsJson","selectedScreenName"],figmaImage:["snapshotRunId","screenId","selectedScreenName","imageSrc"]};function tv(e){return"number"==typeof e&&Number.isFinite(e);}function tb(e){return"object"==typeof e&&null!==e&&!Array.isArray(e);}function ty(e){let t=e.trim();if(0===t.length)return!1;let n=t.toLowerCase();return function(e){for(let t of td)if(t.test(e))return!0;for(let t of e.matchAll(tu)){let e=t[0].replaceAll(/[ -]/g,"");if(e.length>=13&&e.length<=19&&function(e){let t=0,n=!1;for(let l=e.length-1;l>=0;l-=1){let a=Number(e[l]);n&&(a*=2)>9&&(a-=9),t+=a,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 l=0;for(let r=n+t.length;r<e.length;r+=1){var a;if(0===(null!=(a=e[r])?a:"").trim().length)break;l+=1;}return l>=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{return!1;}}(t)||th.some(e=>n.includes(e))||function(e){let t=e.toLowerCase().replaceAll("\\","/").split("/");for(let e=0;e<t.length;e+=1){var n,l;let a=null!=(n=t[e])?n:"",r=null!=(l=t[e+1])?l:"";if(tf.includes(a)||".npmrc"===a||"credentials.json"===a||".aws"===a&&"credentials"===r||".ssh"===a&&r.startsWith("id_"))return!0;}return!1;}(t);}function tx(e){if(0===e.length||e.length>256||e.startsWith(".")||e.trim()!==e||ty(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;}function tw(e){if(0===e.length||e.length>256||e.trim()!==e||ty(e))return!1;for(let t of e){let e=t.charCodeAt(0),n=e>=48&&e<=57,l=e>=65&&e<=90,a=e>=97&&e<=122,r=46===e||58===e||95===e||45===e;if(!n&&!l&&!a&&!r)return!1;}return!0;}function tj(e){if(!Array.isArray(e)||0===e.length)return;let t=[];for(let n of e){if("string"!=typeof n)return;let e=n.trim().replace(/\\/gu,"/").replace(/^\/+/u,"");if(!(0===e.length||e.length>512||ty(e)||t.includes(e))&&(t.push(e),t.length>=64))break;}return t.length>0?t:void 0;}function tk(e){let t=[];for(let n of e){let e=function(e){var t;if(!tb(e)||!("string"==typeof(t=e.type)&&t in ed))return null;let n=e.type;if("transient"===tp[n].persistence||"string"!=typeof e.id||!tv(e.x)||!tv(e.y)||!tv(e.w)||!tv(e.h)||!tv(e.z)||"boolean"!=typeof e.max)return null;let l={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,l;if(!tb(t)||"durable.config"===tp[e].persistence)return{};let a=new Set([...(null!=(n=ed[e].config)?n:[]).map(e=>e.key),...(null!=(l=tg[e])?l:[])]),r={};for(let[n,l]of Object.entries(t)){if(!a.has(n))continue;let t=function(e,t,n){let l;if("editor"===e&&"openFiles"===t)return tj(n);if("editor"===e&&"layoutJson"===t)return function(e){let t;if("string"!=typeof e||0===e.length)return;try{t=JSON.parse(e);}catch{return;}if("object"!=typeof t||null===t||Array.isArray(t))return;let n=t;if(2===n.schemaVersion||2===n.version){let e=tb(n.panes)?n.panes:{},t={};for(let[n,a]of Object.entries(e)){var l;if(!tb(a))continue;let e="string"==typeof a.activeFile?a.activeFile.trim():"",r=tj(a.openFiles),i=null!=(l=tj(a.tabOrder))?l:r;if(void 0===r&&0===e.length)continue;let s=null!=r?r:tj([e]);void 0!==s&&(t[n.slice(0,48)]={id:n.slice(0,48),activeFile:e.length>0?e.replace(/\\/gu,"/").replace(/^\/+/u,""):s[0],openFiles:s,tabOrder:null!=i?i:s});}let a=new Set(Object.keys(t)),r=e=>{if(!tb(e))return null;if("pane"===e.type&&"string"==typeof e.paneId&&a.has(e.paneId))return{type:"pane",paneId:e.paneId};if("split"===e.type){let t=r(e.first),n=r(e.second);if(null===t||null===n)return null;let l="number"==typeof e.ratio&&Number.isFinite(e.ratio)?Math.min(85,Math.max(15,Math.round(e.ratio))):50;return{type:"split",id:"string"==typeof e.id?e.id.slice(0,48):"split-1",direction:"column"===e.direction?"column":"row",ratio:l,first:t,second:n};}return null;},i=r(n.tree),s=Object.keys(t)[0];if(null===i||void 0===s)return;let o="string"==typeof n.activePaneId&&a.has(n.activePaneId)?n.activePaneId:s,c="number"==typeof n.sidebarWidth&&Number.isFinite(n.sidebarWidth)?Math.min(440,Math.max(180,Math.round(n.sidebarWidth))):260;return JSON.stringify({schemaVersion:2,root:"string"==typeof n.root?n.root:"",activePaneId:o,tree:i,panes:t,sidebarWidth:c,sidebarCollapsed:!0===n.sidebarCollapsed});}let a=Array.isArray(n.panes)?n.panes.slice(0,2):[],r=[];for(let[e,t]of a.entries()){if("object"!=typeof t||null===t||Array.isArray(t))return;let n="string"==typeof t.file?t.file.trim():"",l=tj(t.openFiles);if(n.length>512||ty(n))continue;let a=null!=l?l:n.length>0?tj([n]):void 0;void 0!==a&&r.push({id:"string"==typeof t.id&&t.id.trim().length>0?t.id.trim().slice(0,32):`pane-${e+1}`,file:n.length>0?n.replace(/\\/gu,"/").replace(/^\/+/u,""):a[0],openFiles:a});}if(0===r.length)return;let i="column"===n.direction?"column":"row",s="number"==typeof n.splitRatio&&Number.isFinite(n.splitRatio)?Math.min(75,Math.max(25,Math.round(n.splitRatio))):50,o="number"==typeof n.sidebarWidth&&Number.isFinite(n.sidebarWidth)?Math.min(440,Math.max(180,Math.round(n.sidebarWidth))):260,c="string"==typeof n.activePaneId&&r.some(e=>e.id===n.activePaneId)?n.activePaneId:r[0].id;return JSON.stringify({version:1,panes:r,activePaneId:c,direction:i,splitRatio:s,sidebarWidth:o,sidebarCollapsed:!0===n.sidebarCollapsed});}(n);if("figma"===e||"figmaView"===e||"figmaJson"===e||"figmaImage"===e)return function(e,t){if("string"==typeof t){if("snapshotRunId"===e)return tx(t)?t:void 0;if("screenId"===e)return tw(t)?t:void 0;if("imageSrc"===e)return /^\/api\/figma\/snapshots\/[^/?#]+\/screens\/\d+\/image$/u.test(t)?t:void 0;if("selectedScreenIdsJson"===e){let e;try{e=JSON.parse(t);}catch{return;}if(!Array.isArray(e)||0===e.length||e.length>16)return;let n=[];for(let t of e){if("string"!=typeof t)return;let e=t.trim();if(!tw(e))return;n.push(e);}return JSON.stringify(n);}if("selectedScreenName"===e){if(t.length>256||ty(t))return;return t;}}}(t,n);if("string"!=typeof n&&"number"!=typeof n&&"boolean"!=typeof n||(l=function(e){let t="";for(let n of e.toLowerCase())(n>="a"&&n<="z"||n>="0"&&n<="9")&&(t+=n);return t;}(t),tm.some(e=>l.includes(e))))return;if("string"!=typeof n)return n;let a=tp[e].persistence;return"evidence-reference"===a?tx(n)?n:void 0:ty(n)?"durable.ui"===a?"[REDACTED]":void 0:n;}(e,n,l);void 0!==t&&(r[n]=t);}return r;}(n,e.cfg),max:e.max},a=function(e){if(tb(e)&&tv(e.x)&&tv(e.y)&&tv(e.w)&&tv(e.h))return{x:e.x,y:e.y,w:e.w,h:e.h};}(e.prev);return{...l,...(!0===e.minimized?{minimized:!0}:{}),...(void 0!==a?{prev:a}:{}),...(tv(e.zoom)?{zoom:e.zoom}:{})};}(n);null!==e&&t.push("figma"!==e.type||void 0===function(e){let t=e.selectedScreenIdsJson;if("string"==typeof t)try{let e=JSON.parse(t);if(!Array.isArray(e))return;let n=e[0];return"string"==typeof n&&n.length>0?n:void 0;}catch{return;}}(e.cfg)?e:{...e,type:"figmaView",cfg:{...e.cfg}});}let n=t.filter(e=>"figma"===e.type);if(n.length<=1)return t;let l=n.reduce((e,t)=>t.z>e.z?t:e);return t.filter(e=>"figma"!==e.type||e.id===l.id);}function tN(e,t){let n=new Set(t.map(e=>e.id)),l=[];for(let t of e){if("string"!=typeof t.id||"string"!=typeof t.a||"string"!=typeof t.b||!n.has(t.a)||!n.has(t.b))continue;let e="string"==typeof t.boundRoot&&t.boundRoot.length>0,a="workspace-root"===t.boundScopeKind||"directory"===t.boundScopeKind||"files"===t.boundScopeKind,r="string"==typeof t.boundRelativePath&&t.boundRelativePath.length>0,i="string"==typeof t.boundChatWindowId&&t.boundChatWindowId.length>0&&n.has(t.boundChatWindowId),s=("capsule"===t.boundConnectorKind||"capsule-set"===t.boundConnectorKind)&&"string"==typeof t.boundConnectorId&&t.boundConnectorId.length>0;l.push({id:t.id,a:t.a,b:t.b,...(i?{boundChatWindowId:t.boundChatWindowId}:{}),...(e?{boundRoot:t.boundRoot}:{}),...(a?{boundScopeKind:t.boundScopeKind}:{}),...(r?{boundRelativePath:t.boundRelativePath}:{}),...(s?{boundConnectorKind:t.boundConnectorKind,boundConnectorId:t.boundConnectorId}:{})});}return l;}var tS=n(49690);let tC=/^[A-Za-z]:/u;function tR(e){return e.startsWith("/")||e.startsWith("\\")||e.startsWith("~")||tC.test(e);}function tI(e){let t=e.replace(/\\/gu,"/"),n=t.split("/").filter(e=>e.length>0).join("/");return 0===n.length?"":t.startsWith("/")?`/${n}`:n;}function tE(e){return(0,tS.Qf)(e);}function t$(e,t){var n;let l=null!=(n=null==t?void 0:t.trim())?n:"";if(0===l.length)return{kind:"empty"};if(l.includes("\0"))return{kind:"outside-root",candidate:tI(l)};if(tR(l)){let t;return null===(t=function(e,t){let n=tI(e),l=tI(t);if(0===n.length)return null;let a=n.toLowerCase(),r=l.toLowerCase();return r===a?"":r.startsWith(`${a}/`)?l.slice(n.length+1):null;}(e,l))?{kind:"outside-root",candidate:tI(l)}:0===t.length?{kind:"root"}:tE(t)?{kind:"relative",path:t}:{kind:"outside-root",candidate:tI(l)};}let a=tI(l).replace(/^\.\//u,"");return 0===a.length?{kind:"empty"}:tE(a)?{kind:"relative",path:a}:{kind:"outside-root",candidate:a};}function tA(e){return"object"==typeof e&&null!==e&&!Array.isArray(e);}function tT(e,t,n){return Math.min(n,Math.max(t,e));}function tF(e){return tT(Math.round(e),15,85);}function tD(e){if(!Array.isArray(e))return[];let t=[];for(let n of e)"string"==typeof n&&n.length>0&&!t.includes(n)&&t.push(n);return t;}function tM(e,t,n){let l=[],a=e=>{e.length>0&&!l.includes(e)&&l.push(e);};for(let e of null!=n?n:[])a(e);for(let e of t)a(e);return a(e),l;}function tP(e,t,n){var l;let a=tM(t,n);return{id:e,openFiles:a,activeFile:t.length>0?t:null!=(l=a[0])?l:"",tabOrder:a};}function tL(e,t){if(!tA(e))return null;let n="string"==typeof e.id&&e.id.length>0?e.id:t,l="string"==typeof e.activeFile?e.activeFile:"string"==typeof e.file?e.file:"",a=tP(n,l,tM(l,tD(e.openFiles),tD(e.tabOrder)));return a.openFiles.length>0||a.activeFile.length>0?a:null;}function tq(e){return"column"===e?"column":"row";}function tz(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return"pane"===e.type?t.push(e.paneId):(tz(e.first,t),tz(e.second,t)),t;}function tO(e,t){return"number"==typeof e.sidebarWidth&&Number.isFinite(e.sidebarWidth)?tT(e.sidebarWidth,t.minSidebarWidth,t.maxSidebarWidth):t.defaultSidebarWidth;}function tB(e,t,n){return"string"==typeof e.activePaneId&&void 0!==t[e.activePaneId]?e.activePaneId:n;}function tW(e){var t;let n=function(e){if(void 0!==e.layoutJson&&e.layoutJson.trim().length>0)try{let n=JSON.parse(e.layoutJson);if(tA(n)){var t;let l=null!=(t=n.schemaVersion)?t:n.version,a=2===l||"2"===l?function(e,t,n){var l,a;let r=function(e){if(!tA(e))return{};let t={};for(let[n,l]of Object.entries(e)){let e=tL(l,n);null!==e&&(t[e.id]=e);}return t;}(t.panes),i=Object.keys(r)[0];if(void 0===i)return null;let s=null!=(l=function e(t,n){var l;return tA(t)?null!==(l="pane"===t.type&&"string"==typeof t.paneId&&void 0!==n[t.paneId]?{type:"pane",paneId:t.paneId}:null)&&void 0!==l?l:function(t,n){if("split"!==t.type)return null;let l=e(t.first,n),a=e(t.second,n);if(null===l||null===a)return null;let r="string"==typeof t.id&&t.id.length>0?t.id:"split-1",i="number"==typeof t.ratio&&Number.isFinite(t.ratio)?t.ratio:50;return{type:"split",id:r,direction:tq(t.direction),ratio:tF(i),first:l,second:a};}(t,n):null;}(t.tree,r))?l:{type:"pane",paneId:i},o=function(e,t){let n={};for(let l of new Set(tz(e))){let e=t[l];void 0!==e&&(n[l]=e);}return n;}(s,r);return{schemaVersion:2,root:e,activePaneId:tB(t,o,null!=(a=tz(s)[0])?a:i),tree:s,panes:o,sidebarWidth:tO(t,n),sidebarCollapsed:!0===t.sidebarCollapsed};}(e.root,n,e):function(e,t,n){var l;let a=Array.isArray(l=t.panes)?l.map((e,t)=>tL(e,`pane-${String(t+1)}`)).filter(e=>null!==e):[];if(0===a.length)return null;let r={};for(let e of a)r[e.id]=e;let i=a[0];if(void 0===i)return null;let s=function(e,t,n){if(void 0===t)return{type:"pane",paneId:e.id};let l="number"==typeof n.splitRatio&&Number.isFinite(n.splitRatio)?tF(n.splitRatio):50;return{type:"split",id:"split-1",direction:tq(n.direction),ratio:l,first:{type:"pane",paneId:e.id},second:{type:"pane",paneId:t.id}};}(i,a[1],t);return{schemaVersion:2,root:e,activePaneId:tB(t,r,i.id),tree:s,panes:r,sidebarWidth:tO(t,n),sidebarCollapsed:!0===t.sidebarCollapsed};}(e.root,n,e);if(null!==a)return a;}}catch{}return null;}(e);if(null!==n)return n;let l=tP("pane-1",e.file.length>0?e.file:null!=(t=e.openFiles[0])?t:"",e.openFiles);return{schemaVersion:2,root:e.root,activePaneId:l.id,tree:{type:"pane",paneId:l.id},panes:{[l.id]:l},sidebarWidth:e.defaultSidebarWidth,sidebarCollapsed:!1};}function tK(e){return JSON.stringify({schemaVersion:2,root:e.root,activePaneId:e.activePaneId,tree:e.tree,panes:e.panes,sidebarWidth:Math.round(e.sidebarWidth),sidebarCollapsed:e.sidebarCollapsed});}function tU(e){return tz(e.tree);}function tV(e){return tU(e).map(t=>e.panes[t]).filter(e=>void 0!==e);}function tH(e){var t,n;return null!=(t=null!=(n=e.panes[e.activePaneId])?n:tV(e)[0])?t:tP("pane-1","",[]);}function t_(e,t,n){let l=e.panes[t];return void 0===l?e:{...e,panes:{...e.panes,[t]:n(l)}};}function tG(e,t){return e.filter(e=>e!==t);}function tJ(e,t,n){let l=tG(e,t),a=void 0===n?l.length:tT(n,0,l.length);return[...l.slice(0,a),t,...l.slice(a)];}function tY(e,t,n){var l;let a=tM(n,t);return{...e,openFiles:a,tabOrder:a,activeFile:n.length>0?n:null!=(l=a[0])?l:""};}function tX(e,t,n,l,a){let r=e.panes[t];if(void 0===r)return e;let i=null!=l?l:r.activeFile;if(0===i.length)return e;let s=function(e){let t=Object.keys(e.panes).length+1;for(;void 0!==e.panes[`pane-${String(t)}`];)t+=1;return`pane-${String(t)}`;}(e),o=tP(s,i,[i]),c={type:"split",id:function(e){let t=new Set(),n=e=>{"split"===e.type&&(t.add(e.id),n(e.first),n(e.second));};n(e);let l=t.size+1;for(;t.has(`split-${String(l)}`);)l+=1;return`split-${String(l)}`;}(e.tree),direction:n,ratio:50,first:{type:"pane",paneId:a?s:t},second:{type:"pane",paneId:a?t:s}};return{...e,activePaneId:s,tree:function e(t,n,l){return"pane"===t.type?t.paneId===n?l:t:{...t,first:e(t.first,n,l),second:e(t.second,n,l)};}(e.tree,t,c),panes:{...e.panes,[s]:o}};}function tZ(e,t){var n;if(void 0===e.panes[t]||tU(e).length<=1)return e;let l=function e(t,n){if("pane"===t.type)return t.paneId===n?null:t;let l=e(t.first,n),a=e(t.second,n);return null===l?a:null===a?l:{...t,first:l,second:a};}(e.tree,t);if(null===l)return e;let a={};for(let[n,l]of Object.entries(e.panes))n!==t&&(a[n]=l);let r=e.activePaneId===t&&null!=(n=tz(l)[0])?n:e.activePaneId;return{...e,tree:l,panes:a,activePaneId:r};}function tQ(e,t,n){var l,a,r;let i=e.panes[t];if(!(null==i?void 0:i.openFiles.includes(n)))return e;let s=i.tabOrder.indexOf(n),o=tG(i.openFiles,n);if(0===o.length)return tU(e).length>1?tZ(e,t):t_(e,t,e=>tY(e,[],""));let c=i.activeFile===n?null!=(l=null!=(a=null!=(r=o[s])?r:o[s-1])?a:o[0])?l:"":i.activeFile;return t_(e,t,e=>tY(e,o,c));}function t0(e,t,n,l,a){if(t===n)return t_(e,n,e=>tY(e,tJ(e.tabOrder,l,a),l));let r=e.panes[t],i=e.panes[n];if(void 0===r||void 0===i||!r.openFiles.includes(l))return e;let s=tQ(e,t,l);return void 0===s.panes[n]?s:{...(s=t_(s,n,e=>tY(e,tJ(e.tabOrder,l,a),l))),activePaneId:n};}function t1(e){let t=[];for(let n of e)n.length>0&&!t.includes(n)&&t.push(n);return t;}let t2=new Set(["open-file","select-file","close-tab","reorder-tab"]),t4=new Set(["close-pane","move-tab","drop-tab","split-pane"]);function t3(e,t){if(t2.has(t.type)){switch(t.type){case"open-file":return t_(e,t.paneId,e=>tY(e,tM(t.file,e.openFiles),t.file));case"select-file":return t_({...e,activePaneId:t.paneId},t.paneId,e=>e.openFiles.includes(t.file)?tY(e,e.openFiles,t.file):e);case"close-tab":return tQ(e,t.paneId,t.file);case"reorder-tab":return t_(e,t.paneId,e=>e.openFiles.includes(t.file)?tY(e,tJ(e.tabOrder,t.file,t.targetIndex),t.file):e);}return;}return t4.has(t.type)?function(e,t){switch(t.type){case"close-pane":return tZ(e,t.paneId);case"move-tab":return t0(e,t.fromPaneId,t.toPaneId,t.file,t.targetIndex);case"drop-tab":var n;return"center"===(n=t.intent).zone?t0(e,n.fromPaneId,n.toPaneId,n.file,n.targetIndex):tX(t0(e,n.fromPaneId,n.fromPaneId,n.file),n.toPaneId,"top"===n.zone||"bottom"===n.zone?"column":"row",n.file,"top"===n.zone||"left"===n.zone);case"split-pane":return tX(e,t.paneId,t.direction,t.file,!1);}}(e,t):function(e,t){switch(t.type){case"set-active-pane":return void 0===e.panes[t.paneId]?e:{...e,activePaneId:t.paneId};case"resize-split":return{...e,tree:function e(t,n,l){return"pane"===t.type?t:{...t,ratio:t.id===n?tF(l):t.ratio,first:e(t.first,n,l),second:e(t.second,n,l)};}(e.tree,t.splitId,t.ratio)};case"set-sidebar":return{...e,sidebarWidth:null!=(l=t.width)?l:e.sidebarWidth,sidebarCollapsed:null!=(a=t.collapsed)?a:e.sidebarCollapsed};case"replace-root":let n;return n=tP("pane-1","",[]),{schemaVersion:2,root:t.root,activePaneId:n.id,tree:{type:"pane",paneId:n.id},panes:{[n.id]:n},sidebarWidth:null!=(r=t.sidebarWidth)?r:e.sidebarWidth,sidebarCollapsed:!1};case"rename-file":return function(e,t,n){if(0===t.length||0===n.length||t===n)return e;let l={},a=!1;for(let[r,i]of Object.entries(e.panes)){let e=function(e,t,n){var l,a;let r=e=>e===t?n:e.startsWith(`${t}/`)?`${n}${e.slice(t.length)}`:e,i=t1(e.openFiles.map(r)),s=t1(e.tabOrder.map(r)),o=r(e.activeFile);return i.length===e.openFiles.length&&i.every((t,n)=>t===e.openFiles[n])&&o===e.activeFile?e:{...e,openFiles:i,tabOrder:s,activeFile:o.length>0?o:null!=(l=null!=(a=s[0])?a:i[0])?l:""};}(i,t,n);e!==i&&(a=!0),l[r]=e;}return a?{...e,panes:l}:e;}(e,t.from,t.to);case"remove-file":var l,a,r,i=t.file;if(0===i.length)return e;let s=[];for(let t of tV(e))for(let e of t.openFiles)(e===i||e.startsWith(`${i}/`))&&s.push([t.id,e]);return s.reduce((e,t)=>{let[n,l]=t;return tQ(e,n,l);},e);}}(e,t);}function t6(e){let t=[];for(let n of tV(e))for(let e of n.openFiles)e.length>0&&!t.includes(e)&&t.push(e);return t;}function t5(e,t,n,l,a){return{x:e.x+Math.max(16,Math.min(a+26*l,e.w-t-16)),y:e.y+Math.max(16,Math.min(a+26*l,e.h-n-16))};}function t8(e){return e.trim().replace(/\\/gu,"/").replace(/\/+$/u,"");}function t9(e,t){if("string"!=typeof t)return"";let n=t$(e,t);if("relative"===n.kind)return n.path;if("outside-root"===n.kind){let e=n.candidate.replace(/^\/+/u,"");return tE(e)?e:"";}return"";}function t7(e,t){let n=e[t];return"string"==typeof n?n:void 0;}function ne(e){let{prev:t,...n}=e;return n;}function nt(e,t,n){return e.some(e=>e.a===t&&e.b===n||e.a===n&&e.b===t);}function nn(e,t){return(null==e?void 0:e.type)==="chat"?e.id:(null==t?void 0:t.type)==="chat"?t.id:null;}function nl(e){return e.length>0&&(e.startsWith("/")||/^[A-Za-z]:[/\\]/u.test(e));}function na(e){return /^[A-Za-z]:[/\\]?$/u.test(e)?e.replace(/\\/gu,"/"):e.replace(/\\/gu,"/").replace(/\/+$/u,"");}function nr(e){if("files"!==e.type)return null;let t=e.cfg.resolvedRoot,n=e.cfg.root,l="string"==typeof t&&t.length>0?t:"string"==typeof n&&n.length>0?n:null;return null!==l&&nl(l)?l:null;}function ni(e){return e.replace(/\\/gu,"/").replace(/^\/+/u,"").replace(/\/+$/u,"");}function ns(e,t){return void 0!==e.root&&void 0!==t.root&&na(e.root)===na(t.root)&&e.kind===t.kind&&e.relativePaths.length===t.relativePaths.length&&e.relativePaths.every((e,n)=>{var l;return ni(e)===ni(null!=(l=t.relativePaths[n])?l:"");});}function no(e,t,n){let l="files"===e.type?e:"files"===t.type?t:null,a="chat"===e.type?e:"chat"===t.type?t:null;if(null===l||null===a)return null;let r=nr(l);if(null===r)return null;let i=l.cfg.activeFilePath;if("string"==typeof i&&i.length>0)return{kind:"files",relativePaths:[ni(i)],root:na(r),connectedAtMs:n};let s=l.cfg.activeDirectoryPath;return"string"==typeof s&&s.length>0?{kind:"directory",relativePaths:[ni(s)],root:na(r),connectedAtMs:n}:{kind:"workspace-root",relativePaths:[],root:na(r),connectedAtMs:n};}function nc(e){if("string"!=typeof e.boundRoot||0===e.boundRoot.length)return null;let t=Date.now();return"directory"===e.boundScopeKind?"string"!=typeof e.boundRelativePath||0===e.boundRelativePath.length?null:{kind:"directory",relativePaths:[ni(e.boundRelativePath)],root:na(e.boundRoot),connectedAtMs:t}:"files"===e.boundScopeKind?"string"!=typeof e.boundRelativePath||0===e.boundRelativePath.length?null:{kind:"files",relativePaths:[ni(e.boundRelativePath)],root:na(e.boundRoot),connectedAtMs:t}:{kind:"workspace-root",relativePaths:[],root:na(e.boundRoot),connectedAtMs:t};}function nd(e){return Math.max(e.maxConnectedSources,e.maxLocalKnowledgeSources);}function nu(e,t){return e.filter(e=>!ns(e,t));}function np(e){var t;return null!=(t=e.connectedScopes)?t:void 0!==e.connectedScope?[e.connectedScope]:[];}function nm(e){var t;return null!=(t=e.localKnowledgeScopes)?t:void 0!==e.localKnowledgeScope?[e.localKnowledgeScope]:[];}function nh(e){return"capsule"===e.kind?`capsule:${e.capsuleId}`:`set:${e.capsuleSetId}`;}function nf(e){return"string"!=typeof e.boundConnectorId||0===e.boundConnectorId.length?null:"capsule"===e.boundConnectorKind?{kind:"capsule",capsuleId:e.boundConnectorId,connectedAtMs:0}:"capsule-set"===e.boundConnectorKind?{kind:"capsule-set",capsuleSetId:e.boundConnectorId,connectedAtMs:0}:null;}function ng(e,t){let n="connector"===e.type?e:"connector"===t.type?t:null,l="chat"===e.type?e:"chat"===t.type?t:null;if(null===n||null===l)return null;let a=n.cfg.selectedKind,r=n.cfg.selectedId;if("string"!=typeof a||"string"!=typeof r)return null;let i=r.trim();return 0===i.length?null:"capsule"===a?{kind:"capsule",capsuleId:i,connectedAtMs:Date.now()}:"capsule-set"===a?{kind:"capsule-set",capsuleSetId:i,connectedAtMs:Date.now()}:null;}let nv="keiko.workspace.v4",nb="keiko.conns.v1",ny="keiko.view",nx="/api/workspace/state";function nw(){try{let e=window.localStorage.getItem(ny);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{}return{zoom:1,x:0,y:0};}function nj(e){return Math.max(.3,Math.min(2.5,e));}function nk(e){return Math.max(.5,Math.min(2,Math.round(10*e)/10));}function nN(e){let t=null;for(let n=0;n<e.length;n++){let l=e[n];if(!0!==l.minimized){if(null===t){t=l;continue;}l.z>t.z&&(t=l);}}return t;}function nS(e,t){try{window.localStorage.setItem(e,JSON.stringify(t));}catch{}}function nC(e){let t=null,n=null,l=()=>{null!==t&&(clearTimeout(t),t=null);let e=n;n=null,null!==e&&e();};return{schedule:a=>{n=a,null!==t&&clearTimeout(t),t=setTimeout(l,e);},flush:l,cancel:()=>{null!==t&&(clearTimeout(t),t=null),n=null;}};}function nR(e,t){let n=(0,i.useRef)(null);null===n.current&&(n.current=nC(300));let l=(0,i.useRef)(e);l.current=e,(0,i.useEffect)(()=>{var e;null==(e=n.current)||e.schedule(()=>l.current());},t),(0,i.useEffect)(()=>{let e=n.current;if(null===e)return;let t=()=>e.flush(),l=()=>{"u">typeof document&&"hidden"===document.visibilityState&&e.flush();};return window.addEventListener("pagehide",t),document.addEventListener("visibilitychange",l),()=>{window.removeEventListener("pagehide",t),document.removeEventListener("visibilitychange",l),e.flush();};},[]);}function nI(e){let t=e.deltaMode===WheelEvent.DOM_DELTA_LINE?16:2===e.deltaMode?800:1;return{x:e.deltaX*t,y:e.deltaY*t};}function nE(e){return 1-Math.pow(1-e,3);}function n$(e,t,n){return{zoom:e.zoom+(t.zoom-e.zoom)*n,x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n};}function nA(){let e=null;try{e=function(e){if(null===e)return null;try{let t=JSON.parse(e);if(!Array.isArray(t)||0===t.length)return null;let n=tk(t);return n.length>0?n:null;}catch{return null;}}(window.localStorage.getItem(nv));}catch{e=null;}let t=null!=e?e:[];try{return{wins:t,conns:function(e,t){if(null===e)return[];try{let n=JSON.parse(e);if(!Array.isArray(n))return[];return tN(n,t);}catch{return[];}}(window.localStorage.getItem(nb),t)};}catch{return{wins:t,conns:[]};}}async function nT(){if("function"!=typeof fetch)return null;try{let e=await fetch(nx,{headers:{Accept:"application/json"}});if(!e.ok)return null;let t=await e.json();if("object"!=typeof t||null===t||!("workspace"in t))return null;let n=t.workspace;if("object"!=typeof n||null===n||"number"!=typeof n.revision||!Array.isArray(n.windows)||!Array.isArray(n.connections))return null;return{revision:n.revision,windows:n.windows,connections:n.connections};}catch{return null;}}async function nF(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("function"!=typeof fetch)return null;try{let l=await fetch(nx,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json","X-Keiko-CSRF":"1"},body:JSON.stringify({windows:e,connections:t}),...(!0===n.keepalive?{keepalive:!0}:{}),...(void 0!==n.signal?{signal:n.signal}:{})});if(!l.ok)return null;let a=await l.json(),r="object"==typeof a&&null!==a&&"workspace"in a?a.workspace:void 0;if("object"!=typeof r||null===r)return null;let i=r.revision;return"number"==typeof i?i:null;}catch{return null;}}function nD(e,t,n,l){l.current=0===e.wins.length?1:Math.max(1,...e.wins.map(e=>e.z)),t(e.wins),n(e.conns);}let nM={Equal:"=",NumpadAdd:"+",Minus:"-",NumpadSubtract:"-",Digit0:"0",Numpad0:"0"},nP="application/x-keiko-local-knowledge-connector",nL="keiko:local-knowledge-connector-drop";function nq(e){if(!Array.from(e.types).includes(nP))return null;try{let t=JSON.parse(e.getData(nP));if("object"!=typeof t||null===t||"capsule"!==t.kind||"string"!=typeof t.id||0===t.id.trim().length)return null;let n="string"==typeof t.label?t.label.trim():"",l="string"==typeof t.lifecycleState?t.lifecycleState.trim():"";return{kind:"capsule",id:t.id.trim(),...(n.length>0?{label:n}:{}),...(l.length>0?{lifecycleState:l}:{})};}catch{return null;}}let nz="application/x-keiko-figma-view",nO="keiko:figma-view-drop";function nB(e){return"string"==typeof e&&e.trim().length>0?e.trim():null;}function nW(e){if(!Array.from(e.types).includes(nz))return null;try{let t=JSON.parse(e.getData(nz));if("object"!=typeof t||null===t)return null;let n=nB(t.snapshotRunId),l=nB(t.screenId),a=nB(t.name);if(null===n||null===l||null===a)return null;return{snapshotRunId:n,screenId:l,name:a};}catch{return null;}}let nK="application/x-keiko-figma-json",nU="keiko:figma-json-drop";function nV(e){return"string"==typeof e&&e.trim().length>0?e.trim():null;}function nH(e){if(!Array.from(e.types).includes(nK))return null;try{let t=JSON.parse(e.getData(nK));if("object"!=typeof t||null===t)return null;let n=nV(t.snapshotRunId),l=nV(t.screenId),a=nV(t.name);if(null===n||null===l||null===a)return null;let r=nV(t.sourceWindowId);return{snapshotRunId:n,screenId:l,name:a,...(null!==r?{sourceWindowId:r}:{})};}catch{return null;}}let n_="application/x-keiko-figma-image",nG="keiko:figma-image-drop";function nJ(e){return"string"==typeof e&&e.trim().length>0?e.trim():null;}function nY(e){if(!Array.from(e.types).includes(n_))return null;try{let t=JSON.parse(e.getData(n_));if("object"!=typeof t||null===t)return null;let n=nJ(t.snapshotRunId),l=nJ(t.screenId),a=nJ(t.name),r=nJ(t.imageSrc);if(null===n||null===l||null===a||null===r||!/^\/api\/figma\/snapshots\/[^/?#]+\/screens\/\d+\/image$/u.test(r))return null;let i=nJ(t.sourceWindowId);return{snapshotRunId:n,screenId:l,name:a,imageSrc:r,...(null!==i?{sourceWindowId:i}:{})};}catch{return null;}}let nX={w:260,h:220},nZ={w:360,h:360},nQ={w:520,h:540},n0={w:560,h:420};function n1(e){let{clientX:t,clientY:n,rect:l,view:a,size:r=nX}=e;return{x:Math.round((t-l.left-a.x)/a.zoom-r.w/2),y:Math.round((n-l.top-a.y)/a.zoom-28)};}function n2(e,t){let n=e+t;return e<1&&n>1||e>1&&n<1?1:n;}function n4(e,t,n){var l;t.preventDefault();let a=t.currentTarget;null==(l=a.setPointerCapture)||l.call(a,t.pointerId);let r=t.clientX,i=t.clientY,s=eA();n(!0);let o=t=>{e(t.clientX-r,t.clientY-i),r=t.clientX,i=t.clientY;},c=()=>{var e,l;window.removeEventListener("pointermove",o),window.removeEventListener("pointerup",c),window.removeEventListener("pointercancel",c),n(!1),(null==(e=a.hasPointerCapture)?void 0:e.call(a,t.pointerId))===!0&&(null==(l=a.releasePointerCapture)||l.call(a,t.pointerId)),s();};window.addEventListener("pointermove",o),window.addEventListener("pointerup",c),window.addEventListener("pointercancel",c);}function n3(e){let{wins:t,connecting:n,conns:l}=e,[a,s]=(0,i.useState)(""),o=(0,i.useRef)(null),c=(0,i.useRef)(l.length);return(0,i.useEffect)(()=>{let e=o.current;o.current=n;let a=c.current;if(c.current=l.length,null===e&&null!==n){let e=null==t?void 0:t.find(e=>e.id===n.from),l=void 0!==e?ed[e.type].title:"window";s(`Connecting from ${l} — select a highlighted window, press Escape to cancel`);return;}if(null!==e&&null===n)if(l.length>a){let e=l[l.length-1],n=void 0!==e?null==t?void 0:t.find(t=>t.id===e.a):void 0,a=void 0!==e?null==t?void 0:t.find(t=>t.id===e.b):void 0;s(void 0!==n&&void 0!==a?`Connected: ${em(n,a)}`:"Connected");}else s("Connection cancelled");},[n,l,t]),(0,r.jsx)("div",{className:"sr-only","aria-live":"polite",children:a});}let n6=[];function n5(e){var t,n;let l,a,s,o,c,{ws:d,wsRef:u,openPalette:p,palette:m}=e,{wins:h,view:f,snapPrev:g,conns:v,connecting:b,api:y}=d,[x,w]=(0,i.useState)(!1),[j,k]=(0,i.useState)(!1),N=(0,i.useRef)(!1),S=function(e){let[t,n]=(0,i.useState)(!1),l=(0,i.useRef)(e),a=(0,i.useRef)(null);return(0,i.useEffect)(()=>{e!==l.current&&(l.current=e,n(!0),null!==a.current&&clearTimeout(a.current),a.current=setTimeout(()=>n(!1),160));},[e]),(0,i.useEffect)(()=>()=>{null!==a.current&&clearTimeout(a.current);},[]),t;}(f.zoom),C=(0,i.useMemo)(()=>null===h?null:h.filter(e=>!0!==e.minimized),[h]),R=(l=(0,i.useRef)(0),a=(0,i.useRef)(null),s=null===h?"":h.map(e=>`${e.id}:${e.type}`).join("|"),o=null===h?n6:h.map(e=>e.cfg),(null===(c=a.current)||c.conns!==v||c.keys!==s||c.cfgs.length!==o.length||o.some((e,t)=>e!==c.cfgs[t]))&&(l.current+=1,a.current={conns:v,keys:s,cfgs:o}),l.current),I=function(e){if(null===e||0===e.length)return null;let t=null;for(let n=0;n<e.length;n++){let l=e[n];if(!0!==l.minimized){if(null===t){t=l;continue;}l.z>t.z&&(t=l);}}return t;}(C),E=null!==b&&null!==C&&null!=(t=C.find(e=>e.id===b.from))?t:null;(0,i.useEffect)(()=>{let e=e=>{N.current=e,k(e);},t=t=>{var n;!("Space"!==t.code||(n=t.target)instanceof Element&&null!==n.closest("input,textarea,select,button,a[href],summary,[contenteditable='true'],[contenteditable=''],[role='button'],[role='checkbox'],[role='dialog'],[role='link'],[role='menuitem'],[role='option'],[role='radio'],[role='switch'],[role='tab'],[data-text-selectable='true']"))&&(t.preventDefault(),N.current||e(!0));},n=t=>{"Space"===t.code&&e(!1);},l=()=>{e(!1);};return window.addEventListener("keydown",t),window.addEventListener("keyup",n),window.addEventListener("blur",l),()=>{window.removeEventListener("keydown",t),window.removeEventListener("keyup",n),window.removeEventListener("blur",l);};},[]);let A=(0,i.useMemo)(()=>({backgroundSize:`${String(22*f.zoom)}px ${String(22*f.zoom)}px`,backgroundPosition:`${String(f.x)}px ${String(f.y)}px`}),[f]),T=(0,i.useMemo)(()=>S?{transform:`translate(${String(f.x)}px, ${String(f.y)}px) scale(${String(f.zoom)})`,transformOrigin:"0 0"}:{transform:`translate(${String(f.x/f.zoom)}px, ${String(f.y/f.zoom)}px)`,transformOrigin:"0 0",zoom:f.zoom},[f,S]),F=(0,i.useCallback)((e,t,n,l)=>{let a=y.add("connector",{presentation:"node",selectedKind:e.kind,selectedId:e.id,...(void 0!==e.label?{selectedLabel:e.label}:{}),...(void 0!==e.lifecycleState?{selectedState:e.lifecycleState}:{})});null!==a&&y.update(a,{...n1({clientX:t,clientY:n,rect:l,view:f}),...nX});},[y,f]),D=(0,i.useCallback)((e,t,n,l)=>{let a=y.add("figmaView",{snapshotRunId:e.snapshotRunId,selectedScreenIdsJson:JSON.stringify([e.screenId]),selectedScreenName:e.name});null!==a&&y.update(a,{...n1({clientX:t,clientY:n,rect:l,view:f,size:nZ}),...nZ});},[y,f]),M=(0,i.useCallback)(e=>{if(null===h)return[];let t=new Map(h.map(e=>[e.id,e])),n=[];for(let l of v){let a=l.a===e?l.b:l.b===e?l.a:null;if(null===a)continue;let r=t.get(a);(null==r?void 0:r.type)==="quality"&&n.push({connId:l.id,qualityId:r.id});}return n;},[v,h]),P=(0,i.useCallback)((e,t,n,l)=>{let a=y.add("figmaJson",{snapshotRunId:e.snapshotRunId,screenId:e.screenId,selectedScreenIdsJson:JSON.stringify([e.screenId]),selectedScreenName:e.name});if(null===a||(y.update(a,{...n1({clientX:t,clientY:n,rect:l,view:f,size:nQ}),...nQ}),void 0===e.sourceWindowId))return;let r=M(e.sourceWindowId);if(0!==r.length){for(let e of r)y.removeConn(e.connId);window.setTimeout(()=>{for(let e of r)y.connect(a,e.qualityId);},0);}},[y,M,f]),L=(0,i.useCallback)((e,t,n,l)=>{let a=y.add("figmaImage",{snapshotRunId:e.snapshotRunId,screenId:e.screenId,selectedScreenName:e.name,imageSrc:e.imageSrc});if(null===a||(y.update(a,{...n1({clientX:t,clientY:n,rect:l,view:f,size:n0}),...n0}),void 0===e.sourceWindowId))return;let r=M(e.sourceWindowId);if(0!==r.length){for(let e of r)y.removeConn(e.connId);window.setTimeout(()=>{for(let e of r)y.connect(a,e.qualityId);},0);}},[y,M,f]);(0,i.useEffect)(()=>{let e=e=>{var t;if(!(e instanceof CustomEvent)||!function(e){if("object"!=typeof e||null===e)return!1;let t=e.payload;return"number"==typeof e.clientX&&"number"==typeof e.clientY&&"object"==typeof t&&null!==t&&"capsule"===t.kind&&"string"==typeof t.id;}(e.detail))return;let n=null==(t=u.current)?void 0:t.getBoundingClientRect();if(void 0===n)return;let{clientX:l,clientY:a,payload:r}=e.detail;l<n.left||l>n.right||a<n.top||a>n.bottom||F(r,l,a,n);};return window.addEventListener(nL,e),()=>{window.removeEventListener(nL,e);};},[F,u]),(0,i.useEffect)(()=>{let e=e=>{var t;if(!(e instanceof CustomEvent)||!function(e){if("object"!=typeof e||null===e)return!1;let t=e.payload;return"number"==typeof e.clientX&&"number"==typeof e.clientY&&"object"==typeof t&&null!==t&&"string"==typeof t.snapshotRunId&&"string"==typeof t.screenId&&"string"==typeof t.name;}(e.detail))return;let n=null==(t=u.current)?void 0:t.getBoundingClientRect();if(void 0===n)return;let{clientX:l,clientY:a,payload:r}=e.detail;l<n.left||l>n.right||a<n.top||a>n.bottom||D(r,l,a,n);};return window.addEventListener(nO,e),()=>{window.removeEventListener(nO,e);};},[D,u]),(0,i.useEffect)(()=>{let e=e=>{var t;if(!(e instanceof CustomEvent)||!function(e){if("object"!=typeof e||null===e)return!1;let t=e.payload;return"number"==typeof e.clientX&&"number"==typeof e.clientY&&"object"==typeof t&&null!==t&&"string"==typeof t.snapshotRunId&&"string"==typeof t.screenId&&"string"==typeof t.name&&(void 0===t.sourceWindowId||"string"==typeof t.sourceWindowId);}(e.detail))return;let n=null==(t=u.current)?void 0:t.getBoundingClientRect();if(void 0===n)return;let{clientX:l,clientY:a,payload:r}=e.detail;l<n.left||l>n.right||a<n.top||a>n.bottom||P(r,l,a,n);};return window.addEventListener(nU,e),()=>{window.removeEventListener(nU,e);};},[P,u]),(0,i.useEffect)(()=>{let e=e=>{var t;if(!(e instanceof CustomEvent)||!function(e){if("object"!=typeof e||null===e)return!1;let t=e.payload;return"number"==typeof e.clientX&&"number"==typeof e.clientY&&"object"==typeof t&&null!==t&&"string"==typeof t.snapshotRunId&&"string"==typeof t.screenId&&"string"==typeof t.name&&"string"==typeof t.imageSrc&&(void 0===t.sourceWindowId||"string"==typeof t.sourceWindowId);}(e.detail))return;let n=null==(t=u.current)?void 0:t.getBoundingClientRect();if(void 0===n)return;let{clientX:l,clientY:a,payload:r}=e.detail;l<n.left||l>n.right||a<n.top||a>n.bottom||L(r,l,a,n);};return window.addEventListener(nG,e),()=>{window.removeEventListener(nG,e);};},[L,u]);let q=null!==h&&0===h.length,z=null!=(n=null==h?void 0:h.some(e=>e.max))&&n;return(0,r.jsxs)("main",{className:"workspace",ref:u,"aria-label":"Workspace surface",tabIndex:0,"data-window-maxed":z?"true":void 0,"data-canvas-overlays-hidden":z?"true":"false","data-connecting":null!==b?"true":void 0,"data-panning":x?"true":void 0,"data-hand-tool":j?"true":void 0,onPointerDownCapture:e=>{if(eR())return;if(N.current&&eN(e)&&null===b&&!eC(e.target)&&!eS(e.target)){n4(y.panBy,e,w),e.stopPropagation();return;}if(0!==e.button||null===b||null===E||null===C)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===E.id)return;let n=C.find(e=>e.id===t);void 0!==n&&ep(E.type,n.type)&&y.confirmConnect(n.id,e);},onPointerDown:e=>{if(!(eR()||eS(e.target))){var t;if(null!==b){eN(e)&&y.cancelConnect();return;}(eN(t=e)||1===t.button)&&n4(y.panBy,e,w);}},onKeyDown:e=>{if(e.target!==e.currentTarget)return;let t=e.shiftKey?192:48;switch(e.key){case"ArrowLeft":y.panBy(t,0);break;case"ArrowRight":y.panBy(-t,0);break;case"ArrowUp":y.panBy(0,t);break;case"ArrowDown":y.panBy(0,-t);break;default:return;}e.preventDefault();},onDragOver:e=>{(null!==nq(e.dataTransfer)||null!==nW(e.dataTransfer)||null!==nH(e.dataTransfer)||null!==nY(e.dataTransfer))&&(e.preventDefault(),e.dataTransfer.dropEffect="copy");},onDrop:e=>{let t=nq(e.dataTransfer),n=nW(e.dataTransfer),l=nH(e.dataTransfer),a=nY(e.dataTransfer);if(null===t&&null===n&&null===l&&null===a)return;e.preventDefault(),e.stopPropagation();let r=e.currentTarget.getBoundingClientRect();null!==t?F(t,e.clientX,e.clientY,r):null!==n?D(n,e.clientX,e.clientY,r):null!==l?P(l,e.clientX,e.clientY,r):null!==a&&L(a,e.clientX,e.clientY,r);},children:[(0,r.jsx)(e8,{}),(0,r.jsx)("div",{className:"ws-grid",style:A,"aria-hidden":"true"}),(0,r.jsx)(n3,{wins:C,connecting:b,conns:v}),null!==b?(0,r.jsx)("div",{className:"ws-connect-hint","aria-hidden":"true",children:"Click a highlighted window to connect — Esc to cancel"}):null,q?(0,r.jsx)("div",{className:"ws-empty",children:(0,r.jsx)(ek,{onNewWindow:p})}):null,(0,r.jsxs)("div",{className:"ws-scene",style:T,children:[null!==g?(0,r.jsx)("div",{className:"snap-ghost",style:{left:g.x,top:g.y,width:g.w,height:g.h}}):null,null!==C?(0,r.jsx)(tt,{wins:C,conns:v,connecting:b,api:y}):null,null!==C?C.map(e=>(0,r.jsx)(tc,{win:e,top:null!==I&&e.id===I.id,connState:null===E?null:e.id===E.id?"source":ep(E.type,e.type)?"valid":"invalid",api:y,wsRef:u,linkRevision:R},e.id)):null]}),(0,r.jsxs)("div",{className:"ws-zoom",children:[(0,r.jsx)("button",{type:"button",className:"ws-zoom-btn ui-tip cmp-tip-start",onClick:()=>y.zoomTo(n2(f.zoom,-.2)),disabled:f.zoom<=.3,"aria-label":"Zoom out","data-tip":"Zoom out",children:(0,r.jsx)($.F.zoomOut,{size:15})}),(0,r.jsx)("button",{type:"button",className:"ws-zoom-btn ui-tip cmp-tip-start",onClick:y.fitView,disabled:null===C||0===C.length,"aria-label":"Fit workspace to windows","data-tip":"Fit workspace to windows",children:(0,r.jsx)($.F.expand,{size:15})}),(0,r.jsxs)("button",{type:"button",className:"ws-zoom-pct mono ui-tip",onClick:y.resetView,"aria-label":`${String(Math.round(100*f.zoom))}% — reset`,"data-tip":"Reset",children:[Math.round(100*f.zoom),"%"]}),(0,r.jsx)("button",{type:"button",className:"ws-zoom-btn ui-tip cmp-tip-end",onClick:()=>y.zoomTo(n2(f.zoom,.2)),disabled:f.zoom>=2.5,"aria-label":"Zoom in","data-tip":"Zoom in",children:(0,r.jsx)($.F.zoomIn,{size:15})})]}),(0,r.jsx)("button",{type:"button",className:"ws-fab ui-tip cmp-tip-end",onPointerDown:e=>e.stopPropagation(),onClick:p,"aria-label":"New window","data-tip":"New window",children:(0,r.jsx)($.F.add,{size:20})}),z?null:null!=m?m:null]});}function n8(e){let{commands:t,onClose:n}=e,[l,a]=(0,i.useState)(""),[s,o]=(0,i.useState)(0),c=(0,i.useRef)(null),d=(0,i.useRef)(null),u=(0,i.useRef)(null);(0,i.useEffect)(()=>(d.current=document.activeElement,()=>{var e,t;null==(t=d.current)||null==(e=t.focus)||e.call(t);}),[]),(0,i.useEffect)(()=>{var e;null==(e=c.current)||e.focus();},[]);let p=(0,i.useMemo)(()=>{let e=l.toLowerCase();return t.filter(t=>{var n;return`${t.label} ${null!=(n=t.group)?n:""}`.toLowerCase().includes(e);});},[t,l]);(0,i.useEffect)(()=>{o(0);},[l]),(0,i.useEffect)(()=>{var e,t;null==(t=document.getElementById(`cmdk-row-${String(s)}`))||null==(e=t.scrollIntoView)||e.call(t,{block:"nearest"});},[s,p]);let m=e=>{void 0!==e&&(e.run(),n());};return(0,r.jsx)("div",{className:"cmdk-overlay",onPointerDown:n,children:(0,r.jsxs)("div",{ref:u,className:"cmdk",role:"dialog","aria-modal":"true","aria-labelledby":"cmdk-title","aria-describedby":"cmdk-desc",tabIndex:-1,onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{if("Tab"===e.key){var t,l;let n=Array.from(null!=(t=null==(l=u.current)?void 0:l.querySelectorAll("button:not([disabled]),input:not([disabled]),[tabindex]:not([tabindex='-1'])"))?t:[]);if(n.length>0){let t=n[0],l=n[n.length-1];if(e.shiftKey&&document.activeElement===t){e.preventDefault(),l.focus();return;}if(!e.shiftKey&&document.activeElement===l){e.preventDefault(),t.focus();return;}}}if("ArrowDown"===e.key){e.preventDefault(),o(e=>Math.min(p.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(),m(p[s]);return;}"Escape"===e.key&&n();},children:[(0,r.jsx)("h2",{id:"cmdk-title",className:"sr-only",children:"Command palette"}),(0,r.jsx)("p",{id:"cmdk-desc",className:"sr-only",children:"Search commands and press Enter to run the selected action."}),(0,r.jsxs)("div",{className:"cmdk-input",children:[(0,r.jsx)($.F.search,{size:16}),(0,r.jsx)("input",{ref:c,role:"combobox","aria-expanded":"true","aria-controls":"cmdk-list","aria-activedescendant":p.length>0?`cmdk-row-${String(s)}`:void 0,"aria-label":"Command query",placeholder:"Type a command…",value:l,onChange:e=>a(e.target.value)}),(0,r.jsx)("span",{className:"kbd",children:"esc"})]}),(0,r.jsx)("div",{className:"sr-only",role:"status",children:0===p.length?"No matching commands":`${String(p.length)} command${1===p.length?"":"s"}`}),(0,r.jsxs)("div",{id:"cmdk-list",role:"listbox",className:"cmdk-list",children:[0===p.length&&(0,r.jsx)("div",{className:"cmdk-empty",children:"No matching commands"}),p.map((e,t)=>{var n,l;let a;return(0,r.jsxs)("div",{role:"option",id:`cmdk-row-${String(t)}`,"aria-selected":t===s,className:"cmdk-row","data-sel":t===s,tabIndex:-1,onMouseEnter:()=>o(t),onClick:()=>m(e),children:[(0,r.jsx)("span",{className:"cmdk-ico",children:(n=e.icon,a=null!=(l=$.F[n])?l:$.F.spark,(0,r.jsx)(a,{size:16}))}),(0,r.jsx)("span",{className:"cmdk-label",children:e.label}),(0,r.jsx)("span",{className:"spacer"}),void 0!==e.shortcut&&(0,r.jsx)("span",{className:"kbd",children:e.shortcut}),void 0!==e.group&&(0,r.jsx)("span",{className:"cmdk-group mono",children:e.group})]},e.id);})]})]})});}var n9=n(97509);function n7(e){return Array.from(new Set(e.split(/[\n,]/u).map(e=>e.trim()).filter(e=>e.length>0)));}function le(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Request timeout",n=e.trim();if(""===n)return;let l=Number(n);if(!Number.isInteger(l)||l<=0)throw Error(`${t} must be a positive integer in milliseconds.`);return l;}function lt(e){let{onCancel:t,preserveExisting:n=!1,storedApiKeyHeaderName:l,storedModels:a=[]}=e,s=(0,i.useRef)(null),o=(0,i.useRef)(null),c=(0,i.useRef)(null),d=(0,i.useRef)(null),u=(0,i.useRef)(void 0),[p,h]=(0,i.useState)(""),[f,g]=(0,i.useState)(""),[v,b]=(0,i.useState)(""),[y,x]=(0,i.useState)(""),[w,j]=(0,i.useState)(""),[k,N]=(0,i.useState)(""),[S,C]=(0,i.useState)(""),[R,I]=(0,i.useState)(""),[E,A]=(0,i.useState)(""),[T,F]=(0,i.useState)(""),[D,M]=(0,i.useState)("azure-foundry"),[P,L]=(0,i.useState)(""),[q,z]=(0,i.useState)(""),[O,B]=(0,i.useState)(!1),[W,K]=(0,i.useState)(),[U,V]=(0,i.useState)(),[H,_]=(0,i.useState)();async function G(e){var t,l,a,r;if(e.preventDefault(),!O){B(!0),K(void 0),V(void 0),_(void 0),null==(t=s.current)||t.focus();try{let e,t,i=n7(w);if(function(e){try{return new URL(e.trim()).hostname.endsWith(".services.ai.azure.com");}catch{return!1;}}(p)&&0===i.length){K("Azure AI Foundry requires deployment names. Paste the names from the Deployments tab."),B(!1);return;}try{e=le(y),t=le(P,"Voice request timeout");}catch(e){K(e instanceof Error?e.message:"Request timeout is invalid."),B(!1);return;}let s=n7(k),o=""!==S.trim()||""!==R.trim()||""!==E.trim()||""!==T.trim()||""!==P.trim(),c=!n||""!==p.trim()||""!==f.trim()||""!==v.trim()||i.length>0||s.length>0,d=c||void 0!==e,h=""!==q.trim(),g=await(0,m.qe)({baseUrl:""===p.trim()?void 0:p.trim(),apiKey:""===f.trim()?void 0:f.trim(),apiKeyHeaderName:""===v.trim()?void 0:v.trim(),...(void 0===e?{}:{timeoutMs:e}),deploymentNames:i,preserveExisting:n,...(0===s.length?{}:{imageInputModelIds:s}),...(o?{voiceBaseUrl:""===S.trim()?void 0:S.trim(),voiceApiKey:""===R.trim()?void 0:R.trim(),voiceApiKeyHeaderName:""===E.trim()?void 0:E.trim(),voiceModelId:""===T.trim()?void 0:T.trim(),voiceProviderLocality:D,...(void 0===t?{}:{voiceTimeoutMs:t})}:{}),...(""===q.trim()?{}:{figmaAccessToken:q.trim()})}),b=g.testedModelIds.length,x=(r=null!=(l=g.skippedModelIds)?l:[],0===r.length?"":` Could not verify deployment${1===r.length?"":"s"}: ${r.join(", ")}.`),j=`Verified ${String(b)} workflow chat model${1===b?"":"s"}`;B(!1),h&&!d?_(o?"Updated voice dictation credentials and verified Figma access token. Reloading Keiko…":"Verified Figma access token. Reloading Keiko…"):h&&!c?_(o?"Updated model gateway settings, voice dictation credentials, and verified Figma access token. Reloading Keiko…":"Updated model gateway settings and verified Figma access token. Reloading Keiko…"):h||c?h?_(o?`${j}, updated voice dictation credentials, and verified Figma access token. Reloading Keiko…${x}`:`${j} and Figma access token. Reloading Keiko…${x}`):_(`${j}${o?" and updated voice dictation credentials":""}. Reloading Keiko…${x}`):_(o?"Updated voice dictation credentials. Reloading Keiko…":"Updated model gateway settings. Reloading Keiko…"),u.current=window.setTimeout(()=>window.location.reload(),0===(null!=(a=g.skippedModelIds)?a:[]).length?800:1800);}catch(t){let e=t instanceof m.hD?{message:t.message,code:t.code}:t instanceof Error?{message:t.message}:{message:"The gateway could not be configured."};K(e.message),V(e.code),B(!1);}}}(0,i.useEffect)(()=>{var e,t,l,a;let r=document.documentElement,i=Number(null!=(e=r.dataset.keikoModalOpenCount)?e:"0");r.dataset.keikoModalOpenCount=String(i+1),r.setAttribute("data-keiko-modal-open","true");let s=Number(null!=(t=r.dataset.keikoGatewaySetupOpenCount)?t:"0");return r.dataset.keikoGatewaySetupOpenCount=String(s+1),r.setAttribute("data-keiko-gateway-setup-open","true"),d.current=document.activeElement,n?null==(l=c.current)||l.focus():null==(a=o.current)||a.focus(),()=>{var e,t,n,l;void 0!==u.current&&window.clearTimeout(u.current);let a=Math.max(0,Number(null!=(e=r.dataset.keikoModalOpenCount)?e:"1")-1);0===a?(delete r.dataset.keikoModalOpenCount,r.removeAttribute("data-keiko-modal-open")):r.dataset.keikoModalOpenCount=String(a);let i=Math.max(0,Number(null!=(t=r.dataset.keikoGatewaySetupOpenCount)?t:"1")-1);0===i?(delete r.dataset.keikoGatewaySetupOpenCount,r.removeAttribute("data-keiko-gateway-setup-open")):r.dataset.keikoGatewaySetupOpenCount=String(i),null==(l=d.current)||null==(n=l.focus)||n.call(l);};},[n]),(0,i.useEffect)(()=>{let e=s.current;if(null===e)return;let n=n=>{if("Escape"===n.key){if(O||void 0!==H||void 0===t)return;n.preventDefault(),t();return;}if("Tab"!==n.key)return;let l=Array.from(e.querySelectorAll("button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),summary,[tabindex]:not([tabindex='-1'])"));if(0===l.length)return;let a=l[0],r=l[l.length-1];n.shiftKey&&document.activeElement===a?(n.preventDefault(),r.focus()):n.shiftKey||document.activeElement!==r||(n.preventDefault(),a.focus());};return e.addEventListener("keydown",n),()=>e.removeEventListener("keydown",n);},[O,t,H]),(0,i.useEffect)(()=>{if(void 0!==W&&!O){var e,t;n&&""===p.trim()&&""===f.trim()?null==(e=c.current)||e.focus():null==(t=o.current)||t.focus();}},[f,p,O,W,n]);let J=n7(w),Y=n7(k),X=""!==S.trim()||""!==R.trim()||""!==E.trim()||""!==T.trim()||""!==P.trim(),Z=!n,Q=""!==p.trim()||""!==f.trim()||""!==v.trim()||""!==y.trim()||J.length>0||Y.length>0||X,ee=""!==q.trim(),et=!O&&void 0===H&&(Z?""!==p.trim()&&""!==f.trim():Q||ee),en=a.map(e=>e.id),el=en.slice(0,6),ea=Math.max(0,en.length-el.length),er=a.filter(e=>"voice"===e.kind&&!0===e.supportsSpeechInput).map(e=>e.id),ei=(0,r.jsxs)("div",{className:"gw-grid",children:[(0,r.jsxs)("label",{className:"gw-field gw-span-2",children:[(0,r.jsxs)("span",{children:["Base URL ",n?(0,r.jsx)("span",{className:"dlg-opt",children:"leave blank to keep"}):null]}),(0,r.jsx)("input",{className:"gw-input mono",value:p,placeholder:n?"Only enter a value to replace the stored gateway URL":"https://llm-gateway.example.com/v1",autoComplete:"off",disabled:O||void 0!==H,ref:o,onChange:e=>h(e.target.value)})]}),(0,r.jsxs)("label",{className:"gw-field",children:[(0,r.jsxs)("span",{children:["API token ",n?(0,r.jsx)("span",{className:"dlg-opt",children:"leave blank to keep"}):null]}),(0,r.jsx)("input",{className:"gw-input mono",type:"password",value:f,placeholder:n?"Only enter a value to replace the stored token":"Paste your API token",autoComplete:"off",disabled:O||void 0!==H,onChange:e=>g(e.target.value)})]}),(0,r.jsxs)("label",{className:"gw-field",children:[(0,r.jsxs)("span",{children:["API key header ",(0,r.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,r.jsx)("input",{className:"gw-input mono",value:v,placeholder:n?"Leave blank to keep stored header":"Authorization",autoComplete:"off",disabled:O||void 0!==H,onChange:e=>b(e.target.value)})]}),(0,r.jsxs)("label",{className:"gw-field",children:[(0,r.jsxs)("span",{children:["Request timeout (ms) ",(0,r.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,r.jsx)("input",{className:"gw-input mono",inputMode:"numeric",value:y,placeholder:n?"Leave blank to keep stored timeout":"30000",autoComplete:"off",disabled:O||void 0!==H,onChange:e=>x(e.target.value)})]}),(0,r.jsxs)("label",{className:"gw-field",children:[(0,r.jsx)("span",{children:"Deployment names for Azure"}),(0,r.jsx)("textarea",{className:"gw-input gw-textarea mono",value:w,placeholder:"Paste deployment names, one per line",autoComplete:"off",disabled:O||void 0!==H,onChange:e=>j(e.target.value)})]}),(0,r.jsxs)("label",{className:"gw-field",children:[(0,r.jsxs)("span",{children:["Image-input models ",(0,r.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,r.jsx)("textarea",{className:"gw-input gw-textarea mono",value:k,placeholder:"Paste image-capable model names, one per line",autoComplete:"off",disabled:O||void 0!==H,onChange:e=>N(e.target.value)})]})]}),es=(0,r.jsxs)("div",{className:"gw-grid",children:[(0,r.jsxs)("label",{className:"gw-field",children:[(0,r.jsxs)("span",{children:["STT model ",(0,r.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,r.jsx)("input",{className:"gw-input mono",value:T,placeholder:"keiko-stt",autoComplete:"off",disabled:O||void 0!==H,onChange:e=>F(e.target.value)})]}),(0,r.jsxs)("label",{className:"gw-field",children:[(0,r.jsxs)("span",{children:["Provider locality ",(0,r.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,r.jsxs)("select",{className:"gw-input mono",value:D,disabled:O||void 0!==H,onChange:e=>M(e.target.value),children:[(0,r.jsx)("option",{value:"azure-foundry",children:"Azure Foundry"}),(0,r.jsx)("option",{value:"customer-hosted",children:"Customer-hosted"}),(0,r.jsx)("option",{value:"local-only",children:"Local-only"})]})]}),(0,r.jsxs)("label",{className:"gw-field gw-span-2",children:[(0,r.jsxs)("span",{children:["STT endpoint URL"," ",n?(0,r.jsx)("span",{className:"dlg-opt",children:"leave blank to keep"}):null]}),(0,r.jsx)("input",{className:"gw-input mono",value:S,placeholder:n?"Only enter a value to replace the stored STT URL":"https://voice-gateway.example.com/openai/v1",autoComplete:"off",disabled:O||void 0!==H,onChange:e=>C(e.target.value)})]}),(0,r.jsxs)("label",{className:"gw-field",children:[(0,r.jsxs)("span",{children:["STT credential"," ",n?(0,r.jsx)("span",{className:"dlg-opt",children:"leave blank to keep"}):null]}),(0,r.jsx)("input",{className:"gw-input mono",type:"password",value:R,placeholder:n?"Only enter a value to replace the stored STT credential":"Paste your STT credential",autoComplete:"off",disabled:O||void 0!==H,onChange:e=>I(e.target.value)})]}),(0,r.jsxs)("label",{className:"gw-field",children:[(0,r.jsxs)("span",{children:["STT auth header ",(0,r.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,r.jsx)("input",{className:"gw-input mono",value:E,placeholder:n?"Leave blank to keep stored header":"api-key",autoComplete:"off",disabled:O||void 0!==H,onChange:e=>A(e.target.value)})]}),(0,r.jsxs)("label",{className:"gw-field",children:[(0,r.jsxs)("span",{children:["STT timeout (ms) ",(0,r.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,r.jsx)("input",{className:"gw-input mono",inputMode:"numeric",value:P,placeholder:n?"Leave blank to keep stored timeout":"30000",autoComplete:"off",disabled:O||void 0!==H,onChange:e=>L(e.target.value)})]})]}),eo=(0,r.jsx)("div",{className:"gw-setup-backdrop",role:"presentation",children:(0,r.jsx)("div",{ref:s,className:"gw-setup",role:"dialog","aria-modal":"true","aria-labelledby":"gw-setup-title","aria-describedby":"gw-setup-desc",tabIndex:-1,children:(0,r.jsxs)("form",{className:"gw-form",onSubmit:e=>void G(e),children:[(0,r.jsxs)("div",{className:"gw-head",children:[(0,r.jsxs)("div",{className:"gw-setup-badge",children:[(0,r.jsx)($.F.cube,{size:18}),n?"Credential update":"Model gateway setup"]}),(0,r.jsx)("h1",{id:"gw-setup-title",children:n?"Update Keiko credentials":"Connect Keiko to your internal LLMs"}),(0,r.jsx)("p",{id:"gw-setup-desc",children:n?"Leave stored gateway fields blank to keep the current value. Keiko never returns existing secrets to the browser.":"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,r.jsxs)("section",{className:"gw-section","aria-labelledby":"gw-model-section-title",children:[(0,r.jsx)("div",{className:"gw-section-head",children:(0,r.jsxs)("div",{children:[(0,r.jsx)("h2",{id:"gw-model-section-title",children:"Model gateway"}),(0,r.jsx)("p",{children:n?"Blank gateway fields keep the stored value.":"Base URL and API token are required."})]})}),n?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"gw-current","aria-label":"Stored model gateway credentials",children:[(0,r.jsxs)("div",{className:"gw-current-row",children:[(0,r.jsx)("span",{children:"Gateway URL"}),(0,r.jsx)("strong",{children:"Stored"})]}),(0,r.jsxs)("div",{className:"gw-current-row",children:[(0,r.jsx)("span",{children:"API token"}),(0,r.jsx)("strong",{className:"mono",children:"••••••••••••"})]}),(0,r.jsxs)("div",{className:"gw-current-row",children:[(0,r.jsx)("span",{children:"API key header"}),(0,r.jsx)("strong",{className:"mono",children:null!=l?l:"authorization"})]}),(0,r.jsxs)("div",{className:"gw-current-models",children:[(0,r.jsx)("span",{children:"Configured models"}),(0,r.jsxs)("div",{className:"gw-model-chips",children:[0===el.length?(0,r.jsx)("strong",{children:"Stored"}):el.map(e=>(0,r.jsx)("strong",{className:"mono",children:e},e)),ea>0?(0,r.jsxs)("strong",{children:["+",ea.toString()]}):null]})]})]}),(0,r.jsxs)("details",{className:"gw-replace",children:[(0,r.jsx)("summary",{children:"Replace model gateway settings"}),ei]})]}):ei]}),(0,r.jsxs)("section",{className:"gw-section","aria-labelledby":"gw-voice-section-title",children:[(0,r.jsx)("div",{className:"gw-section-head",children:(0,r.jsxs)("div",{children:[(0,r.jsx)("h2",{id:"gw-voice-section-title",children:"Voice dictation"}),(0,r.jsx)("p",{children:"Optional speech-to-text provider for composer dictation."})]})}),n?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"gw-current","aria-label":"Stored voice dictation credentials",children:[(0,r.jsxs)("div",{className:"gw-current-row",children:[(0,r.jsx)("span",{children:"STT provider"}),(0,r.jsx)("strong",{children:er.length>0?"Stored":"Not configured"})]}),er.length>0?(0,r.jsxs)("div",{className:"gw-current-models",children:[(0,r.jsx)("span",{children:"Voice models"}),(0,r.jsx)("div",{className:"gw-model-chips",children:er.map(e=>(0,r.jsx)("strong",{className:"mono",children:e},e))})]}):null]}),(0,r.jsxs)("details",{className:"gw-replace",children:[(0,r.jsx)("summary",{children:"Update voice dictation credentials"}),es]})]}):es]}),(0,r.jsxs)("section",{className:"gw-section","aria-labelledby":"gw-figma-section-title",children:[(0,r.jsx)("div",{className:"gw-section-head",children:(0,r.jsxs)("div",{children:[(0,r.jsx)("h2",{id:"gw-figma-section-title",children:"Figma Snapshot"}),(0,r.jsx)("p",{children:"Optional connector credential."})]})}),(0,r.jsxs)("label",{className:"gw-field",children:[(0,r.jsxs)("span",{children:["Figma access token ",(0,r.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,r.jsx)("input",{className:"gw-input mono",type:"password",value:q,placeholder:n?"Stored Figma token is kept when blank":"Paste a read-only Figma PAT when needed",autoComplete:"off",disabled:O||void 0!==H,ref:c,onChange:e=>z(e.target.value)})]})]}),(0,r.jsx)("div",{className:"gw-note",children:"Stored secrets stay local and are never returned to the browser. Supported API-key headers: Authorization, X-Litellm-Key, X-Api-Key, api-key."}),void 0!==W?(0,r.jsxs)("div",{className:"gw-error",role:"alert",children:[W,void 0!==U?(0,r.jsx)("div",{className:"gw-error-code mono",children:U}):null]}):null,void 0!==H?(0,r.jsx)("div",{className:"gw-success",role:"status",children:H}):null,O?(0,r.jsx)("div",{className:"gw-pending",role:"status",children:"Testing credentials…"}):null,(0,r.jsx)("span",{id:"gw-submit-requirements",className:"visually-hidden",children:n?"Enter at least one field to update. Blank stored gateway fields keep their current value.":"Base URL and API token are required. The Figma access token is optional."}),(0,r.jsxs)("div",{className:"gw-actions",children:[void 0!==t?(0,r.jsx)("button",{className:"gw-cancel",type:"button",disabled:O||void 0!==H,onClick:t,children:"Cancel"}):null,(0,r.jsx)("button",{className:"gw-submit",type:"submit",disabled:!et,"aria-busy":O,"aria-describedby":"gw-submit-requirements",children:O?"Testing credentials…":"Test & save"})]})]})})});return"u"<typeof document?eo:(0,n9.createPortal)(eo,document.body);}var ln=n(80266);let ll=[["ask","Ask every action"],["full","Full access"]];function la(e){let{cfg:t,set:n}=e,l=!1!==t.keikoMode,a="full"===t.access?"full":"ask",i=l?"No rights by default. You approve while manual; Keiko governs per policy when autonomous.":"full"===a?"Legacy: agent acts without prompts.":"Legacy: you approve each privileged action.";return(0,r.jsxs)("div",{className:"permctl",children:[(0,r.jsxs)("button",{type:"button",className:"perm-toggle","data-on":l,"aria-pressed":l,onClick:()=>n("keikoMode",!l),children:[(0,r.jsx)("img",{className:"perm-orca",src:"/assets/keiko-logo.svg",alt:""}),(0,r.jsxs)("span",{className:"perm-tt",children:[(0,r.jsx)("span",{className:"perm-name",children:"Keiko-Mode"}),(0,r.jsx)("span",{className:"perm-desc",children:"Zero standing rights \xb7 Keiko governs"})]}),(0,r.jsx)("span",{className:"perm-sw"+(l?" on":""),children:(0,r.jsx)("span",{})})]}),!l&&(0,r.jsx)("div",{className:"perm-legacy",children:ll.map(e=>{let[t,l]=e;return(0,r.jsx)("button",{type:"button",className:"perm-opt","data-on":a===t,"aria-pressed":a===t,onClick:()=>n("access",t),children:l},t);})}),(0,r.jsx)("div",{className:"perm-note",children:i})]});}function lr(e){if(e instanceof m.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 li(e){let{value:t,projectId:n,selectProjectRoot:l=!1,onSelect:a,onClose:s}=e,[o,c]=(0,i.useState)(null),[d,u]=(0,i.useState)(t),[p,h]=(0,i.useState)(!1),[f,g]=(0,i.useState)(null),v=null!=n?n:t.trim(),b=(0,i.useCallback)(async e=>{if(0===v.length){c(null),g("Enter an absolute folder path.");return;}h(!0),g(null);try{let t=await(0,m.xe)(v,e);c(t),u(t.path);}catch(e){g(lr(e));}finally{h(!1);}},[v]);return(0,i.useEffect)(()=>{b(t.length>0?t:void 0);},[]),(0,r.jsxs)("div",{className:"dir-picker",role:"group","aria-label":"Directory picker",children:[(0,r.jsxs)("div",{className:"dir-top",children:[(0,r.jsx)("input",{className:"dlg-input mono dir-path",value:d,"aria-label":"Folder path",placeholder:"/absolute/folder/path",onChange:e=>u(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),e.stopPropagation(),b(d));}}),(0,r.jsx)("button",{type:"button",className:"dlg-btn dir-go",onClick:()=>void b(d),children:"Go"})]}),null!==o?(0,r.jsx)("div",{className:"dir-roots",children:o.roots.map(e=>(0,r.jsx)("button",{type:"button",className:"dir-chip",onClick:()=>void b(e.path),children:e.label},`${e.label}:${e.path}`))}):null,(0,r.jsxs)("div",{className:"dir-list",children:[(null==o?void 0:o.parent)!==null&&(null==o?void 0:o.parent)!==void 0?(0,r.jsxs)("button",{type:"button",className:"dir-row",onClick:()=>{var e;b(null!=(e=o.parent)?e:void 0);},children:[(0,r.jsx)($.F.back,{size:14}),(0,r.jsx)("span",{children:"Parent directory"})]}):null,null==o?void 0:o.entries.map(e=>(0,r.jsxs)("button",{type:"button",className:"dir-row",onClick:()=>void b(e.path),children:[(0,r.jsx)($.F.folder,{size:14}),(0,r.jsx)("span",{children:e.name})]},e.path)),p?(0,r.jsx)("div",{className:"dir-note",role:"status",children:"Loading directories…"}):null,p||null===o||0!==o.entries.length?null:(0,r.jsx)("div",{className:"dir-note",children:"No child directories."}),null!==f?(0,r.jsx)("div",{className:"dir-error",role:"alert",children:f}):null]}),(0,r.jsxs)("div",{className:"dir-actions",children:[(0,r.jsx)("button",{type:"button",className:"dlg-btn",onClick:s,children:"Close"}),(0,r.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",onClick:()=>{if(null!==o){var e,t;a(l&&null!=(e=null==(t=o.roots[0])?void 0:t.path)?e:o.path),s();}},disabled:null===o,children:"Use directory"})]})]});}let ls=[{id:"unit-test-generation",label:"Unit Test Agent",scope:"Source file"},{id:"bug-investigation",label:"Bugfix Agent",scope:"Bug report"}];function lo(e){return e.filter(e=>e.available).map(e=>e.path);}function lc(e){return e.split(/[\n,]/u).map(e=>e.trim()).filter(e=>e.length>0);}function ld(e){let t=lp(e.trim()).replace(/\/+$/u,""),n=t.lastIndexOf("/");return n>0?t.slice(0,n):"";}let lu=function(e){return"chat"===e.kind&&e.toolCalling&&e.structuredOutput;};function lp(e){return e.replaceAll("\\","/");}function lm(e,t){let n=lp(t.trim());if(0===n.length)return"";let l=lp(e.trim()).replace(/\/+$/u,"");if(0===l.length)return n;if(n===l)return".";let a=`${l}/`;return n.startsWith(a)?n.slice(a.length):n;}function lh(e){let{root:t,value:n,onSelect:l,onClose:a}=e,s=lm(t,n),[o,c]=(0,i.useState)(ld(s)),[d,u]=(0,i.useState)(s),[p,h]=(0,i.useState)([]),[f,g]=(0,i.useState)(!1),[v,b]=(0,i.useState)(!1),[y,x]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(0===t.trim().length){h([]),g(!1),b(!1),x("Select a repository first.");return;}let e=!1;return b(!0),x(null),(0,m.KD)(t.trim(),o).then(t=>{e||(h(t.entries),g(t.truncated));}).catch(t=>{e||(h([]),g(!1),x(lr(t)));}).finally(()=>{e||b(!1);}),()=>{e=!0;};},[o,t]);let w=p.filter(e=>"directory"===e.kind),j=p.filter(e=>"directory"!==e.kind);return(0,r.jsxs)("div",{className:"file-picker",role:"group","aria-label":"File picker",children:[(0,r.jsx)("div",{className:"file-picker-head",children:(0,r.jsx)("span",{className:"file-picker-path mono",children:0===o.length?"Repository root":o})}),(0,r.jsxs)("div",{className:"dir-list file-picker-list",children:[o.length>0?(0,r.jsxs)("button",{type:"button",className:"dir-row",onClick:()=>c(ld(o)),children:[(0,r.jsx)($.F.back,{size:14}),(0,r.jsx)("span",{children:"Parent folder"})]}):null,w.map(e=>(0,r.jsxs)("button",{type:"button",className:"dir-row file-picker-row",disabled:!e.readable,onClick:()=>c(e.path),title:e.path,children:[(0,r.jsx)($.F.folder,{size:14}),(0,r.jsx)("span",{children:e.name})]},e.path)),j.map(e=>(0,r.jsxs)("button",{type:"button",className:"dir-row file-picker-row","data-selected":d===e.path?"true":void 0,disabled:!e.readable,"aria-pressed":d===e.path,onClick:()=>u(e.path),title:e.path,children:[(0,r.jsx)($.F.file,{size:14}),(0,r.jsx)("span",{children:e.name}),(0,r.jsx)("span",{className:"file-picker-meta mono",children:function(e){if(!Number.isFinite(e)||e<=0)return"0 B";let t=["B","KB","MB","GB"],n=e,l=0;for(;n>=1024&&l<t.length-1;)n/=1024,l+=1;let a=0===l?n.toFixed(0):n.toFixed(n>=10?1:2);return`${a} ${t[l]}`;}(e.sizeBytes)})]},e.path)),v?(0,r.jsx)("div",{className:"dir-note",role:"status",children:"Loading files…"}):null,v||null!==y||0!==p.length?null:(0,r.jsx)("div",{className:"dir-note",children:"No files in this folder."}),f?(0,r.jsxs)("div",{className:"dir-note file-picker-warning",role:"status",children:["Showing only the first ",p.length.toString()," entries."]}):null,null!==y?(0,r.jsx)("div",{className:"dir-error",role:"alert",children:y}):null]}),(0,r.jsxs)("div",{className:"dir-actions",children:[(0,r.jsx)("button",{type:"button",className:"dlg-btn",onClick:a,children:"Close"}),(0,r.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",onClick:()=>{0!==d.trim().length&&(l(lm(t,d)),a());},disabled:0===d.trim().length,children:"Use file"})]})]});}function lf(e){var t,n,l,a;let{filesContext:s,directoryField:o,setDirectoryField:c,setDialogError:d,onConfirm:u,onClose:p}=e,[h,f]=(0,i.useState)("unit-test-generation"),[g,v]=(0,i.useState)(null!=(t=null==s?void 0:s.root)?t:""),[b,y]=(0,i.useState)(""),[x,w]=(0,i.useState)([]),[j,k]=(0,i.useState)([]),[N,S]=(0,i.useState)(()=>{var e,t,n,l;let a;return n=null!=(e=null==s?void 0:s.root)?e:"",{verifyTargetFiles:a=null===(l=null!=(t=null==s?void 0:s.activeFilePath)?t:null)?"":lm(n,l),explainFilePath:a,explainQuestion:"",unitFilePath:a,bugDescription:"",bugFailingOutput:"",bugStackTrace:"",bugTargetFiles:a};}),[C,R]=(0,i.useState)(!0),[I,E]=(0,i.useState)(!1),[A,T]=(0,i.useState)(!1),F=g.trim(),D=null!==s&&s.root===F&&void 0!==s.activeFilePath?s.activeFilePath:null,M=F.length>0&&j.includes(F),P=0===F.length?"Repository is required.":0===b.length?"No compatible model is available.":"explain-plan"===h&&0===N.explainFilePath.trim().length?"Explain plan requires a file path.":"unit-test-generation"===h&&0===N.unitFilePath.trim().length?"Unit Test Agent requires a source file.":"bug-investigation"===h&&0===N.bugDescription.trim().length?"Bugfix Agent requires an observed behavior.":null,L=null===P&&M&&!A&&!C,q=null!=(n=ls.find(e=>e.id===h))?n:ls[0],z="unit-test-generation"===h?"Start Unit Test Agent":"Start Bugfix Agent",O=null!=(l=j[0])?l:"",B=F.length>0?F:null!=(a=null==s?void 0:s.root)?a:O,W=B.length>0,K="agent-repository-browse-help",U="agent-source-file-browse-help";(0,i.useEffect)(()=>{let e=!1;return R(!0),d(null),Promise.all([(0,m.ZC)(),(0,m.vj)()]).then(t=>{let[n,l]=t;if(e)return;let a=n.models.filter(lu);w(a),y(e=>{var t,n;return e||(null!=(t=null==(n=a[0])?void 0:n.id)?t:"");}),k(lo(l.projects));}).catch(t=>{e||d(lr(t));}).finally(()=>{e||R(!1);}),()=>{e=!0;};},[d]);let V=e=>{S(t=>({...t,...e}));};(0,i.useEffect)(()=>{if(null===D)return;let e=lm(F,D);S(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.bugTargetFiles.trim().length&&(n.bugTargetFiles=e),0===Object.keys(n).length?t:{...t,...n};});},[D,F]);let H=async()=>{k(lo((await(0,m.vj)()).projects));},_=async()=>{if(0!==F.length){E(!0),d(null);try{await(0,m.gA)({path:F}),await H();}catch(e){d(lr(e));}finally{E(!1);}}},G=async()=>{if(!L)return void d(null!=P?P:"Repository is not registered.");T(!0),d(null);let e=function(e,t,n,l){if("verify"===e){let e=lc(l.verifyTargetFiles).map(e=>lm(t,e));return{taskType:"verify",modelId:n,input:{workspaceRoot:t,...(e.length>0?{targetFiles:e}:{})}};}return"explain-plan"===e?{taskType:"explain-plan",modelId:n,input:{workspaceRoot:t,filePath:lm(t,l.explainFilePath),...(l.explainQuestion.trim().length>0?{question:l.explainQuestion.trim()}:{})}}:"unit-test-generation"===e?{workflowId:"unit-test-generation",modelId:n,input:{workspaceRoot:t,target:{kind:"file",filePath:lm(t,l.unitFilePath)}}}:{workflowId:"bug-investigation",modelId:n,input:{workspaceRoot:t,report:{...(l.bugDescription.trim().length>0?{description:l.bugDescription.trim()}:{}),...(l.bugFailingOutput.trim().length>0?{failingOutput:l.bugFailingOutput.trim()}:{}),...(l.bugStackTrace.trim().length>0?{stackTrace:l.bugStackTrace.trim()}:{}),...(lc(l.bugTargetFiles).length>0?{targetFiles:lc(l.bugTargetFiles).map(e=>lm(t,e))}:{})}}};}(h,F,b,N);try{let t=await(0,m.AD)(e);u({workflow:h,model:b,runId:t.runId,fingerprint:t.fingerprint,workspaceRoot:F,inputJson:JSON.stringify(e.input),...(null!==s&&s.root===F?{__connectFilesId:s.id}:{})});}catch(e){e instanceof m.hD&&"WORKSPACE_NOT_REGISTERED"===e.code?(await H().catch(()=>void 0),d("Repository is not registered.")):d(lr(e));}finally{T(!1);}};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"dlg-agent-grid",children:[(0,r.jsxs)("div",{className:"dlg-field",children:[(0,r.jsx)("span",{className:"dlg-label",children:"Agent"}),(0,r.jsx)("span",{className:"dlg-selwrap",children:(0,r.jsx)(ln.A,{triggerClassName:"dlg-input",value:h,ariaLabel:"Agent",autoFocus:!0,menuTitle:"Agent",menuCountLabel:`${ls.length.toString()} agents`,sections:[{options:ls.map(e=>({value:e.id,label:e.label}))}],onValueChange:e=>{let t=ls.find(t=>t.id===e);void 0!==t&&f(t.id);}})})]}),(0,r.jsxs)("div",{className:"dlg-field",children:[(0,r.jsx)("span",{className:"dlg-label",children:"Model"}),(0,r.jsx)("span",{className:"dlg-selwrap",children:(0,r.jsx)(ln.A,{triggerClassName:"dlg-input mono",value:b,ariaLabel:"Model",disabled:0===x.length,menuTitle:"Model",mono:!0,sections:[{options:x.map(e=>({value:e.id,label:e.id}))}],onValueChange:y})})]})]}),(0,r.jsxs)("label",{className:"dlg-field",children:[(0,r.jsx)("span",{className:"dlg-label",children:"Repository"}),(0,r.jsxs)("span",{className:"dlg-dirwrap",children:[(0,r.jsx)("input",{className:"dlg-input mono",value:g,placeholder:"/absolute/repository/path",onChange:e=>v(e.target.value)}),(0,r.jsx)("button",{type:"button",className:"dlg-btn dlg-dirbtn",disabled:!W,"aria-describedby":W?void 0:K,onClick:()=>{W&&(0===F.length&&v(B),c("agentWorkspace"));},children:"Browse"})]}),W?null:(0,r.jsx)("span",{id:K,className:"dlg-note",children:"Enter an absolute repository path to enable Browse."}),"agentWorkspace"===o?(0,r.jsx)(li,{value:B,projectId:j.includes(B)?B:void 0,onSelect:v,onClose:()=>c(null)}):null]}),F.length>0&&!M?(0,r.jsxs)("div",{className:"dlg-agent-warning",children:[(0,r.jsx)("span",{children:"Repository is not registered."}),(0,r.jsx)("button",{type:"button",className:"dlg-btn",disabled:I,onClick:()=>void _(),children:I?"Registering…":"Register repository"})]}):null,null!==D?(0,r.jsxs)("button",{type:"button",className:"dlg-current-file",onClick:()=>{if(null===D)return;let e=lm(F,D);"unit-test-generation"===h?V({unitFilePath:e}):V({bugTargetFiles:e});},title:D,children:[(0,r.jsx)($.F.files,{size:13})," Use current file ",(0,r.jsx)("span",{className:"mono",children:D})]}):null,(0,r.jsxs)("div",{className:"dlg-agent-task",children:[(0,r.jsxs)("div",{className:"dlg-agent-task-head",children:[(0,r.jsx)("span",{className:"dlg-agent-task-title",children:q.label}),(0,r.jsx)("span",{className:"dlg-agent-task-scope",children:q.scope})]}),"unit-test-generation"===h?(0,r.jsxs)("label",{className:"dlg-field",children:[(0,r.jsx)("span",{className:"dlg-label",children:"Source file"}),(0,r.jsxs)("span",{className:"dlg-dirwrap",children:[(0,r.jsx)("input",{className:"dlg-input mono",placeholder:"src/file.ts",value:N.unitFilePath,onChange:e=>V({unitFilePath:e.target.value}),onBlur:e=>V({unitFilePath:lm(F,e.target.value)})}),(0,r.jsx)("button",{type:"button",className:"dlg-btn dlg-dirbtn","aria-label":"Browse source file",disabled:!M,"aria-describedby":M?void 0:U,onClick:()=>{M&&c("unitSourceFile");},children:"Browse"})]}),M?null:(0,r.jsx)("span",{id:U,className:"dlg-note",children:"Select a registered repository before browsing source files."}),"unitSourceFile"===o?(0,r.jsx)(lh,{root:F,value:N.unitFilePath,onSelect:e=>V({unitFilePath:e}),onClose:()=>c(null)}):null]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("label",{className:"dlg-field",children:[(0,r.jsx)("span",{className:"dlg-label",children:"Observed behavior"}),(0,r.jsx)("textarea",{className:"dlg-input dlg-textarea",rows:2,placeholder:"Describe the observed bug.",value:N.bugDescription,onChange:e=>V({bugDescription:e.target.value})})]}),(0,r.jsxs)("label",{className:"dlg-field",children:[(0,r.jsxs)("span",{className:"dlg-label",children:["Failing output ",(0,r.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,r.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,value:N.bugFailingOutput,onChange:e=>V({bugFailingOutput:e.target.value})})]}),(0,r.jsxs)("label",{className:"dlg-field",children:[(0,r.jsxs)("span",{className:"dlg-label",children:["Stack trace ",(0,r.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,r.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,value:N.bugStackTrace,onChange:e=>V({bugStackTrace:e.target.value})})]}),(0,r.jsxs)("label",{className:"dlg-field",children:[(0,r.jsxs)("span",{className:"dlg-label",children:["Related files ",(0,r.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,r.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,placeholder:"src/file.ts, src/other.ts",value:N.bugTargetFiles,onChange:e=>V({bugTargetFiles:e.target.value}),onBlur:e=>V({bugTargetFiles:lc(e.target.value).map(e=>lm(F,e)).join(", ")})})]})]})]}),(0,r.jsxs)("div",{className:"dlg-agent-actions",children:[C?(0,r.jsx)("span",{id:"agent-start-validation",className:"dlg-note",role:"status",children:"Loading models and projects…"}):null,C||null===P?null:(0,r.jsx)("span",{id:"agent-start-validation",className:"dlg-note",role:"status",children:P}),(0,r.jsx)("button",{type:"button",className:"dlg-btn",onClick:p,children:"Cancel"}),(0,r.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",disabled:!L,"aria-busy":A,"aria-describedby":L||A?void 0:"agent-start-validation",onClick:()=>void G(),children:A?"Starting…":z})]})]});}function lg(e){var t;let{type:n,types:l,filesContext:a=null,onConfirm:s,onClose:o}=e,{t:c}=ea(),d=l[n],u=(0,i.useMemo)(()=>{var e,t;return t=null!=(e=d.config)?e:[],"chat"!==n?t:t.map(e=>"title"===e.key?{...e,label:c("newWindow.chat.fieldTitle"),def:c("newWindow.chat.defaultTitle"),placeholder:c("newWindow.chat.placeholder")}:e);},[c,d.config,n]),[p,h]=(0,i.useState)(()=>function(e){let t={};for(let l of e){var n;t[l.key]=null!=(n=l.def)?n:"";}return t;}(u)),[f,g]=(0,i.useState)(!1),[v,b]=(0,i.useState)(null),[y,x]=(0,i.useState)(null),w=(0,i.useRef)(null),j=(0,i.useRef)(null),k=(0,i.useRef)(null),N="chat"===n?c("newWindow.chat.title"):`New ${d.title} window`,S="chat"===n?c("newWindow.chat.description"):d.desc,C="chat"===n?c("newWindow.chat.open"):null!=(t=d.cta)?t:`Open ${d.title}`;(0,i.useEffect)(()=>(k.current=document.activeElement,()=>{let e=k.current;null!==e&&e.isConnected?e.focus():requestAnimationFrame(()=>{var e,t;(null!=(e=null!=(t=document.querySelector('.window[data-top="true"]'))?t:document.querySelector(".ws-fab"))?e:document.body).focus({preventScroll:!0});});}),[]),(0,i.useEffect)(()=>{let e=requestAnimationFrame(()=>{var e,t;g(!0),null==(t=null!=(e=w.current)?e:j.current)||t.focus();});return()=>cancelAnimationFrame(e);},[]),(0,i.useEffect)(()=>{let e=e=>{"Escape"===e.key&&o();};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e);};},[o]),(0,i.useEffect)(()=>{if("files"!==n&&"editor"!==n)return;let e=!1,t=p.root;if("string"!=typeof t||!(t.length>0))return b(null),(0,m.vj)().then(t=>{let n=lo(t.projects)[0];e||void 0===n||h(e=>({...e,root:n}));}).catch(t=>{e||b(lr(t));}),()=>{e=!0;};},[p.root,n]);let R=(e,t)=>h(n=>({...n,[e]:t})),I=()=>{"agents"!==n&&s(p);},E=$.F[d.icon];return(0,r.jsx)("div",{className:"dlg-overlay"+(f?" in":""),onPointerDown:o,children:(0,r.jsxs)("div",{ref:j,className:"agents"===n?"dlg dlg-agents":"dlg",role:"dialog","aria-modal":"true","aria-labelledby":"new-window-title","aria-describedby":"new-window-desc",tabIndex:-1,onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{let t,n;if("Escape"===e.key)return void o();if("Enter"===e.key&&(e.metaKey||e.ctrlKey))return void I();if("Enter"===e.key){let t=e.target instanceof HTMLElement?e.target.tagName:"";("INPUT"===t||"SELECT"===t)&&(e.preventDefault(),I());return;}if("Tab"!==e.key)return;let l=(t=e.currentTarget.querySelectorAll("button,input,select,textarea"),n=[],t.forEach(e=>{e.hasAttribute("disabled")||(null!==e.offsetParent||"BUTTON"===e.tagName)&&n.push(e);}),n);if(0===l.length)return;let a=l[0],r=l[l.length-1];e.shiftKey&&document.activeElement===a?(e.preventDefault(),r.focus()):e.shiftKey||document.activeElement!==r||(e.preventDefault(),a.focus());},children:[(0,r.jsxs)("div",{className:"dlg-head",children:[(0,r.jsx)("span",{className:"dlg-ico",children:(0,r.jsx)(E,{size:20})}),(0,r.jsxs)("div",{className:"dlg-htext",children:[(0,r.jsx)("span",{id:"new-window-title",className:"dlg-title",children:N}),(0,r.jsx)("span",{id:"new-window-desc",className:"dlg-sub",children:S})]}),(0,r.jsx)("span",{className:"spacer"}),(0,r.jsx)("button",{type:"button",className:"palette-x",onClick:o,"aria-label":c("common.cancel"),title:c("common.cancel"),children:(0,r.jsx)($.F.close,{size:16})})]}),(0,r.jsxs)("div",{className:"dlg-body",children:["agents"===n?(0,r.jsx)(lf,{filesContext:a,directoryField:y,setDirectoryField:x,setDialogError:b,onConfirm:s,onClose:o}):0===u.length&&(0,r.jsxs)("div",{className:"dlg-empty",children:["Add a new ",d.title," window to your workspace."]}),"agents"!==n&&u.map((e,t)=>(0,r.jsxs)("label",{className:"dlg-field",children:[(0,r.jsxs)("span",{className:"dlg-label",children:[e.label,!0===e.optional&&(0,r.jsx)("span",{className:"dlg-opt",children:c("common.optional")})]}),function(e,t,n,l,a){var i,s,o,c;if("perm"===e.type)return(0,r.jsx)(la,{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!=(s=e.options)?s:[];return(0,r.jsx)("span",{className:"dlg-selwrap",children:(0,r.jsx)(ln.A,{triggerClassName:"dlg-input mono",value:u,disabled:0===t.length,autoFocus:null!==l,menuTitle:e.label,mono:!0,sections:[{options:t.map(t=>{var n;return{value:t,label:`${null!=(n=e.prefix)?n:""}${t}`};})}],onValueChange:t=>n(e.key,t)})});}return"textarea"===e.type?(0,r.jsx)("textarea",{ref:null!=l?l:void 0,className:"dlg-input dlg-textarea",rows:3,placeholder:null!=(o=e.placeholder)?o:"",value:u,onChange:t=>n(e.key,t.target.value)}):"directory"===e.type?(0,r.jsxs)("span",{className:"dlg-dirwrap",children:[(0,r.jsx)("input",{ref:null!=l?l:void 0,className:"dlg-input mono",placeholder:null!=(c=e.placeholder)?c:e.label,value:u,onClick:()=>a(e.key),onChange:t=>n(e.key,t.target.value)}),(0,r.jsx)("button",{type:"button",className:"dlg-btn dlg-dirbtn",onClick:()=>a(e.key),children:"Browse"})]}):(0,r.jsx)("input",{ref:null!=l?l:void 0,className:"dlg-input mono",placeholder:null!=(i=e.placeholder)?i:e.label,value:u,onChange:t=>n(e.key,t.target.value)});}(e,p,R,0===t?e=>{w.current=e;}:null,x),"directory"===e.type&&y===e.key?(0,r.jsx)(li,{value:"string"==typeof p[e.key]?p[e.key]:"",selectProjectRoot:"root"===e.key,onSelect:t=>R(e.key,t),onClose:()=>x(null)}):null]},e.key)),null!==v?(0,r.jsx)("div",{className:"dlg-error",role:"alert",children:v}):null]}),"agents"!==n?(0,r.jsxs)("div",{className:"dlg-foot",children:[(0,r.jsx)("button",{type:"button",className:"dlg-btn",onClick:o,children:c("common.cancel")}),(0,r.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",onClick:I,children:C})]}):null]})});}function lv(e){let{types:t,order:n,onAdd:l,onClose:a}=e,s=n.length<=4?2:3,o=(0,i.useRef)(null),c=(0,i.useRef)(null),[d,u]=(0,i.useState)(0);return(0,i.useEffect)(()=>{var e;c.current=document.activeElement;let t=null==(e=o.current)?void 0:e.querySelector(".pal-card");return null==t||t.focus(),()=>{var e,t;let n=document.activeElement;(null===n||n===document.body)&&(null==(t=c.current)||null==(e=t.focus)||e.call(t));};},[]),(0,i.useEffect)(()=>{let e=e=>{null!==o.current&&e.target instanceof Node&&!o.current.contains(e.target)&&a();};return document.addEventListener("pointerdown",e),()=>{document.removeEventListener("pointerdown",e);};},[a]),(0,r.jsxs)("div",{ref:o,className:"palette",role:"dialog","aria-labelledby":"palette-title","aria-describedby":"palette-desc",tabIndex:-1,onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{var t,n,l;if("Escape"===e.key){e.preventDefault(),a();return;}if(!(e.target instanceof HTMLElement)||!e.target.classList.contains("pal-card"))return;let r=Array.from(null!=(t=null==(n=o.current)?void 0:n.querySelectorAll(".pal-card"))?t:[]),i=function(e,t,n,l){let a;if(0===n)return null;if("Home"===e)return 0;if("End"===e)return n-1;if("ArrowRight"===e)a=1;else if("ArrowLeft"===e)a=-1;else if("ArrowDown"===e)a=l;else{if("ArrowUp"!==e)return null;a=-l;}return Math.max(0,Math.min(n-1,t+a));}(e.key,r.indexOf(e.target),r.length,s);null!==i&&(e.preventDefault(),u(i),null==(l=r[i])||l.focus());},onBlur:e=>{var t;e.relatedTarget instanceof Node&&(null==(t=o.current)?void 0:t.contains(e.relatedTarget))!==!0&&a();},"data-columns":s,children:[(0,r.jsxs)("div",{className:"palette-head",children:[(0,r.jsx)("span",{className:"palette-badge",children:(0,r.jsx)($.F.add,{size:17})}),(0,r.jsxs)("div",{className:"palette-htext",children:[(0,r.jsx)("span",{id:"palette-title",className:"palette-title",children:"New window"}),(0,r.jsx)("span",{id:"palette-desc",className:"palette-sub",children:"Pick a card to add to your workspace"})]}),(0,r.jsx)("span",{className:"spacer"}),(0,r.jsx)("button",{type:"button",className:"palette-x",onClick:a,"aria-label":"Close",title:"Close",children:(0,r.jsx)($.F.close,{size:16})})]}),(0,r.jsx)("div",{className:"palette-grid",children:n.map((e,n)=>{let a=t[e],i=$.F[a.icon];return(0,r.jsxs)("button",{type:"button",className:"pal-card pal-main",tabIndex:n===d?0:-1,onFocus:()=>u(n),onClick:()=>l(e),children:[(0,r.jsx)("span",{className:"pal-ico",children:(0,r.jsx)(i,{size:18})}),(0,r.jsx)("span",{className:"pal-name",children:a.title}),(0,r.jsx)("span",{className:"pal-desc",children:a.desc}),(0,r.jsx)("span",{className:"pal-add","aria-hidden":"true",children:(0,r.jsx)($.F.plus,{size:15})})]},e);})})]});}async function lb(e){try{let t=await e.json();return{code:t.error.code,message:t.error.message};}catch{return{code:"INTERNAL",message:`HTTP ${e.status.toString()}`};}}async function ly(e,t){var n;let l,a,r=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),i=null==t?void 0:t.body,s=await fetch(e,{...t,headers:(l={Accept:"application/json"},((a="GET"!==r&&"HEAD"!==r)||null!=i)&&(l["Content-Type"]="application/json"),a&&(l["X-Keiko-CSRF"]="1"),l)});if(!s.ok){let{code:e,message:t}=await lb(s);throw new m.hD(e,t,s.status);}return s.json();}async function lx(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:ly,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 l=n.toString();return t(`/api/memory${l.length>0?`?${l}`:""}`);}async function lw(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:ly;return e("/api/memory/review-queue");}async function lj(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:ly;return t("/api/memory/consolidation/jobs",{method:"POST",body:JSON.stringify({settings:e})});}async function lk(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:ly;return t(`/api/memory/consolidation/jobs/${encodeURIComponent(e)}`);}async function lN(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:ly;return t(`/api/memory/consolidation/jobs/${encodeURIComponent(e)}/cancel`,{method:"POST",body:"{}"});}async function lS(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:ly;return t(`/api/memory/${encodeURIComponent(e)}`);}async function lC(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:ly;return n(`/api/memory/${encodeURIComponent(e)}`,{method:"PATCH",body:JSON.stringify(t)});}async function lR(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:ly;return t(`/api/memory/${encodeURIComponent(e)}/pin`,{method:"POST",body:"{}"});}async function lI(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:ly;return t(`/api/memory/${encodeURIComponent(e)}/unpin`,{method:"POST",body:"{}"});}async function lE(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:ly;return n(`/api/memory/${encodeURIComponent(e)}/archive`,{method:"POST",body:JSON.stringify({...(void 0!==t?{reason:t}:{})})});}async function l$(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:ly;return n(`/api/memory/${encodeURIComponent(e)}/forget`,{method:"POST",body:JSON.stringify({acknowledged:!0,...(void 0!==t?{reason:t}:{})})});}async function lA(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:ly;return n(`/api/memory/${encodeURIComponent(e)}`,{method:"DELETE",body:JSON.stringify({acknowledged:!0,...(void 0!==t?{reason:t}:{})})});}async function lT(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:ly;return n(`/api/memory/${encodeURIComponent(e)}/correct`,{method:"POST",body:JSON.stringify({body:t})});}async function lF(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:ly;return t(`/api/memory/proposals/${encodeURIComponent(e)}/accept`,{method:"POST",body:"{}"});}async function lD(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:ly;return n(`/api/memory/proposals/${encodeURIComponent(e)}/reject`,{method:"POST",body:JSON.stringify({...(void 0!==t?{reason:t}:{})})});}let lM=new Set(["completed","dry-run","fix-applied","fix-proposed","investigation-only"]);function lP(e){return e.length>200?e.slice(0,200):e;}function lL(e){if(null!==e&&"object"==typeof e)return e;}function lq(){return"Investigation complete; root cause documented.";}function lz(e){let t=e.workflowId;return"unit-test-generation"===t||"unit-tests"===t?"unit-tests":"bug-investigation"===t?"bug":"verify"===e.taskType?"verify":"explain-plan"===e.taskType?"explain":"other";}var lO=n(81962);let lB=[/\bsk-[A-Za-z0-9_-]{12,}\b/g,/\bBearer\s+[A-Za-z0-9._~+/=-]{12,}\b/gi,/\bgho_[A-Za-z0-9_]{12,}\b/g,/\bghp_[A-Za-z0-9_]{12,}\b/g],lW=/\s+\(([A-Z][A-Z0-9_/-]{2,})\)\s*$/;function lK(e){let t=e;for(let e of lB)t=t.replace(e,"[REDACTED]");return t.replace(/\bBearer\s+\[REDACTED\]/gi,"[REDACTED]");}function lU(e,t){return"BAD_REQUEST"===t&&e.toLowerCase().includes("too broad")&&e.toLowerCase().includes("connected");}function lV(e){return"CLARIFICATION_NEEDED"===e;}function lH(e,t,n){return"GATEWAY_TIMEOUT"===t&&(0===e.length||e===t)?"The model gateway timed out before the model returned a response.":e.length>0?e:n;}function l_(e,t){return lV(t)?"Keiko braucht mehr Kontext":lU(e,t)?"Narrow the connected-source question":"GATEWAY_TIMEOUT"===t?"Model gateway timed out":"PAYLOAD_TOO_LARGE"===t?"Request is too large":"NO_MODEL"===t?"No model is available":void 0!==t?"Request failed":"Something went wrong";}function lG(e,t){return lV(t)?"Nenne eine konkrete Datei, einen Identifier, eine Fehlermeldung oder eine exakte Phrase.":lU(e,t)?"Ask about a specific file, folder, symbol, identifier, or exact phrase. For broad questions over large project folders, narrow the Files scope first.":"GATEWAY_TIMEOUT"===t?"Retry the request. If it repeats, choose a smaller prompt or another configured model, then check the gateway base URL, proxy, and model deployment availability in Settings.":"PAYLOAD_TOO_LARGE"===t?"Reduce the selected scope or remove large attachments before retrying.":void 0;}function lJ(e,t){if(e instanceof m.hD){let n=lH(lK(e.message.trim()),e.code,t);return`${n} (${e.code})`;}return e instanceof Error&&e.message.trim().length>0?lK(e.message.trim()):t;}let lY="\n…[truncated]",lX=["text/"],lZ=new Set(["application/json","application/x-yaml","application/yaml"]),lQ=new TextEncoder();function l0(e){return lQ.encode(e).length;}function l1(e){let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(t+1):e;}let l2=`${String(256)} KB`;function l4(e){return`"${e}" won't be sent — the ${l2} attachment limit was already used by earlier files.`;}async function l3(e,t){var n,l;let a,r,i,s,o;if(e.remainingAggregate<=0)return l4(l1(t.name));try{a=await t.file.text();}catch{return n=l1(t.name),`Couldn't read "${n}" — it will be skipped. Your message will be sent without it.`;}let c=Math.min(65536,Math.max(e.remainingAggregate-l0(lY),0));if(c<=0)return l4(l1(t.name));let{entry:d,consumed:u}=(i=(r=l0(l=a)>c)?function(e,t){if(t<=0)return"";if(l0(e)<=t)return e;let n=0,l="";for(let a of e){let e=n+l0(a);if(e>t)break;n=e,l+=a;}return l;}(l,c):l,s=l0(i),o=r?l0(lY):0,{entry:{id:t.id,displayName:l1(t.name),mimeType:t.mimeType,sizeBytes:t.sizeBytes,extractedBytes:s,truncated:r,truncationMarker:r?lY:void 0,text:i},consumed:s+o});if(0===d.text.length)return 0===a.length?void 0:l4(l1(t.name));e.entries.push(d),e.remainingAggregate-=u;}async function l6(e){let t=e.filter(e=>{var t;return t=e.mimeType,!!lX.some(e=>t.startsWith(e))||lZ.has(t);}),n=t.slice(0,16),l={entries:[],remainingAggregate:262144},a=[];for(let e of n){let t=await l3(l,e);void 0!==t&&a.push(t);}for(let e of t.slice(16)){var r;a.push((r=l1(e.name),`"${r}" won't be sent — only the first ${String(16)} documents are included.`));}return{entries:l.entries,failures:a};}let l5={enabled:!0,budgetTokens:1200},l8=new Set();function l9(e){if(e.enabled!==l5.enabled||e.budgetTokens!==l5.budgetTokens)for(let t of(l5=e,l8))t();}function l7(e){return l8.add(e),()=>{l8.delete(e);};}function ae(){return l5;}function at(){let e=(0,i.useSyncExternalStore)(l7,ae,ae),t=(0,i.useCallback)(e=>{l9({...l5,enabled:e});},[]),n=(0,i.useCallback)(e=>{l9({...l5,budgetTokens:!Number.isFinite(e)||e<=0?0:Math.floor(e)});},[]);return{memoryEnabled:e.enabled,setMemoryEnabled:t,memoryBudgetTokens:e.budgetTokens,setMemoryBudgetTokens:n};}let an=["text/"],al=new Set(["application/pdf","application/json","application/x-yaml","application/yaml"]),aa="New chat",ar="keiko:chat-upsert",ai="keiko:chat-delete",as=["completed","failed","cancelled"];function ao(e){return"idle"!==e&&!as.includes(e);}let ac="The model request completed, but the provider did not return any answer text. Retry once; if it happens again, check the selected model deployment in Settings.",ad=new Set(["CONVERSATION_OVERSIZED_CONTEXT","GATEWAY_CONTEXT_OVERFLOW"]),au=["context length","context_length_exceeded","max_tokens","too many tokens"],ap=["empty assistant response","empty grounded answer","without assistant content"];function am(e){let t;return function(e){if(e instanceof m.hD&&ad.has(e.code))return!0;let t=e instanceof Error?e.message.toLowerCase():"";return 0!==t.length&&au.some(e=>t.includes(e));}(e)?"The conversation context exceeded the model's window. Open a new chat or pick a larger-context model.":0!==(t=e instanceof Error?e.message.toLowerCase():"").length&&ap.some(e=>t.includes(e))?e instanceof m.hD?`${ac} (${e.code})`:ac:lJ(e,"Something went wrong. Try again.");}function ah(e){return[...e].sort((e,t)=>t.updatedAt-e.updatedAt);}function af(e){window.dispatchEvent(new CustomEvent(ar,{detail:e}));}function ag(e){var t;return null==(t=e.find(lO.S_))?void 0:t.id;}function av(e,t){return void 0!==e&&t.some(t=>t.id===e&&(0,lO.S_)(t))?e:ag(t);}function ab(e){return void 0!==e.connectedScope||void 0!==e.connectedScopes&&e.connectedScopes.length>0||void 0!==e.localKnowledgeScope||void 0!==e.localKnowledgeScopes&&e.localKnowledgeScopes.length>0;}let ay={projects:[],chats:[],messages:[],models:[],activeProject:void 0,activeChat:void 0,selectedModel:void 0};async function ax(e){var t;let n=(await(0,m.ZC)()).models.filter(lO.S_),l=ag(n),a=[...(await(0,m.vj)().catch(()=>({projects:[]}))).projects].sort((e,t)=>e.favorite!==t.favorite?e.favorite?-1:1:e.lastOpenedAt!==t.lastOpenedAt?t.lastOpenedAt-e.lastOpenedAt:e.path.localeCompare(t.path)),r=null!=(t=a.find(e=>e.available))?t:a[0];if(void 0!==r){let e=ah((await(0,m.Oz)(r.path).catch(()=>({chats:[]}))).chats),t=e[0];if(void 0!==t){let l=await(0,m.T$)(t.id,r.path),i=av(t.selectedModel,n);return{models:n,selectedModel:i,projects:Array.from(a),activeProject:r,chats:e,activeChat:t,messages:Array.from(l.messages)};}}if(void 0===l||!e)return{models:n,selectedModel:l,projects:Array.from(a),activeProject:r,chats:[],activeChat:void 0,messages:[]};let i={modelId:l,title:aa};(null==r?void 0:r.available)===!0&&(i.projectPath=r.path);let s=await(0,m.tA)(i);return af(s.chat),{models:n,selectedModel:s.chat.selectedModel,projects:Array.from(s.projects),activeProject:s.project,chats:ah(s.chats),activeChat:s.chat,messages:Array.from(s.messages)};}function aw(){var e,t;let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},l=null==(e=n.autoCreate)||e,[a,r]=(0,i.useState)(ay),[s,o]=(0,i.useState)(""),[c,d]=(0,i.useState)(!0),[u,p]=(0,i.useState)("idle"),h=ao(u),f=(0,i.useRef)("idle"),g=(0,i.useRef)(null),[v,b]=(0,i.useState)(),[y,x]=(0,i.useState)(),[w,j]=(0,i.useState)(),{memoryEnabled:k,setMemoryEnabled:N,memoryBudgetTokens:S,setMemoryBudgetTokens:C}=at(),R=(0,i.useRef)(!0),I=(0,i.useRef)(void 0),E=(0,i.useRef)(new Set()),$=(0,i.useRef)(0),A=(0,i.useRef)([]),[T,F]=(0,i.useState)([]),[D,M]=(0,i.useState)([]),P=(0,i.useCallback)(async e=>{var t;let n;if(0===e.size)return{ok:!1,reason:"empty"};if(e.size>8388608)return{ok:!1,reason:"oversized"};let l=(t=e.type).startsWith("image/")?"image":an.some(e=>t.startsWith(e))||al.has(t)?"document":"unsupported-type";if("unsupported-type"===l)return{ok:!1,reason:"unsupported-type"};let r=a.models.find(e=>e.id===a.selectedModel);if(void 0!==r&&("image"===l&&!r.supportsImageInput||"document"===l&&!r.supportsDocumentInput))return{ok:!1,reason:"text-only-model"};if("image"===l)try{n=await new Promise((t,n)=>{let l=new FileReader();l.onload=()=>t(l.result),l.onerror=()=>n(Error("FileReader error")),l.readAsDataURL(e);});}catch{return{ok:!1,reason:"unsupported-type"};}let i={id:crypto.randomUUID(),kind:l,name:e.name,mimeType:e.type,sizeBytes:e.size,previewDataUrl:n,file:e};return F(e=>[...e,i]),{ok:!0};},[a.models,a.selectedModel]),L=(0,i.useCallback)(e=>{F(t=>t.filter(t=>t.id!==e));},[]),q=(0,i.useCallback)(()=>{F([]);},[]),z=(0,i.useCallback)(async()=>{let e=T.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 l6(e);n.length>0&&b(n.join(" "));let l=t.map(e=>({id:e.id,displayName:e.displayName,truncated:e.truncated}));return{entries:t,disclosures:l};},[T]),O=(0,i.useCallback)(()=>{j(void 0);},[]),B=(0,i.useCallback)((e,t)=>({enabled:k,budgetTokens:S,context:{userId:"local-operator",workspaceId:t.path,projectId:t.path,conversationId:e.id}}),[S,k]),W=(0,i.useCallback)(async e=>{await lF(e),j(t=>void 0===t?t:{...t,actions:t.actions.filter(t=>"candidate"!==t.kind||t.proposalId!==e)});},[]),K=(0,i.useCallback)(async e=>{await lD(e),j(t=>void 0===t?t:{...t,actions:t.actions.filter(t=>"candidate"!==t.kind||t.proposalId!==e)});},[]),U=(0,i.useCallback)(async e=>{await l$(e,"user-initiated forget from Conversation Center"),j(t=>void 0===t?t:{...t,actions:t.actions.filter(t=>"forget"!==t.kind||t.memoryId!==e)});},[]),V=(0,i.useCallback)(e=>{f.current=e,p(e);},[]),H=(0,i.useCallback)(async(e,t,n,l)=>{let a=n.runId;if(void 0===a)return void E.current.delete(l);let i={...(void 0===n.workflowId?{}:{workflowId:n.workflowId}),...(void 0===n.taskType?{}:{taskType:n.taskType})};try{for(let l=0;l<120;l+=1){let s;if(!R.current||I.current!==e.id)return;try{let e=await(0,m.Qe)(a),t=function(e,t){let n=lL(e);if(void 0===n)return{kind:"unknown"};let l=function(e){let t=e.status;if("string"==typeof t)return t;}(n),a=lz(t);return"running"===l?{kind:"running"}:"cancelled"===l?{kind:"terminal",summary:{workflowStatus:"cancelled",shortResult:"Run cancelled."}}:"failed"===l||"rejected"===l?{kind:"terminal",summary:{workflowStatus:"failed",shortResult:lP(function(e){let t,n,l=(t=lL(e.failure),n=null==t?void 0:t.message,"string"==typeof n&&n.length>0?n:void 0);return void 0!==l?lP(`Run failed: ${l}.`):"Run failed.";}(n))}}:void 0!==l&&lM.has(l)?{kind:"terminal",summary:{workflowStatus:"completed",shortResult:lP(function(e,t){if("unit-tests"===t)return function(e){let t,n=e.addedTestFiles;if(Array.isArray(n)){let e=0,l=!1;for(let t of n){let n=lL(t),a=null==n?void 0:n.estimatedTestCount;"number"==typeof a&&Number.isFinite(a)&&(e+=a,l=!0);}l&&(t=e);}let l=Array.isArray(n)?n.length:0;return l>0&&void 0!==t?`Generated ${String(l)} test files; ${String(t)} tests proposed.`:l>0?`Generated ${String(l)} test files.`:"Completed.";}(e);if("bug"===t)return lq();if("verify"===t){let t,n;return t=lL(e.verificationSummary),n=null==t?void 0:t.results,Array.isArray(n)&&n.length>0?`Verification passed: ${String(n.length)} classifications.`:"Verification passed.";}if("explain"===t){let t=e.dryRunPreview;if("string"==typeof t&&t.length>0){let e=t.split("\n").filter(e=>e.trim().length>0);if(e.length>0)return`Plan generated; ${String(e.length)} steps.`;}return"Plan generated.";}return"Completed.";}(n,a))}}:{kind:"unknown"};}(e.report,i);"terminal"===t.kind&&(s=t.summary);}catch(e){if(!(e instanceof m.hD)||404!==e.status)return;try{let e=await(0,m.tZ)(a),t=function(e,t){let n=lL(e),l=void 0===n?void 0:lL(n.run),a=void 0===l?void 0:l.outcome,r=lz(t);return"cancelled"===a?{workflowStatus:"cancelled",shortResult:"Run cancelled."}:"failed"===a||"limit-exceeded"===a?{workflowStatus:"failed",shortResult:"Run failed."}:"completed"===a?{workflowStatus:"completed",shortResult:lP("bug"===r?lq():"verify"===r?"Verification passed.":"explain"===r?"Plan generated.":"unit-tests"===r?"Generated tests.":"Completed.")}:{workflowStatus:"completed",shortResult:"Completed."};}(e.manifest,i);s={workflowStatus:"failed"===t.workflowStatus||"cancelled"===t.workflowStatus?t.workflowStatus:"completed",shortResult:t.shortResult};}catch{}}if(void 0!==s){let l=await(0,m.mj)(n.id,e.id,t,s);if(!R.current||I.current!==e.id)return;r(t=>{var a;return(null==(a=t.activeChat)?void 0:a.id)!==e.id?t:{...t,messages:t.messages.map(e=>e.id===n.id?l.message:e)};});return;}l<119&&(await new Promise(e=>{globalThis.setTimeout(e,1e3);}));}}finally{E.current.delete(l);}},[]);(0,i.useEffect)(()=>{var e;I.current=null==(e=a.activeChat)?void 0:e.id;},[null==(t=a.activeChat)?void 0:t.id]),(0,i.useEffect)(()=>{A.current=a.models;},[a.models]),(0,i.useEffect)(()=>{let e=!1;return async function(){d(!0),b(void 0);try{let t=await ax(l);e||r(e=>({...e,...t}));}catch(t){e||b(am(t));}finally{e||d(!1);}}(),()=>{e=!0;};},[l]),(0,i.useEffect)(()=>{let e=e=>{let t=e.detail;"object"==typeof t&&null!==t&&"string"==typeof t.id&&"string"==typeof t.projectPath&&"string"==typeof t.title&&"string"==typeof t.selectedModel&&r(e=>{var n,l;return{...e,chats:ah([t,...e.chats.filter(e=>e.id!==t.id)]),activeChat:(null==(n=e.activeChat)?void 0:n.id)===t.id?t:e.activeChat,selectedModel:(null==(l=e.activeChat)?void 0:l.id)===t.id?av(t.selectedModel,e.models):e.selectedModel};});},t=e=>{let t=e.detail;"object"==typeof t&&null!==t&&"string"==typeof t.chatId&&r(e=>{var n,l;return{...e,chats:e.chats.filter(e=>e.id!==t.chatId),activeChat:(null==(n=e.activeChat)?void 0:n.id)===t.chatId?void 0:e.activeChat,messages:(null==(l=e.activeChat)?void 0:l.id)===t.chatId?[]:e.messages};});};return window.addEventListener(ar,e),window.addEventListener(ai,t),()=>{window.removeEventListener(ar,e),window.removeEventListener(ai,t);};},[]),(0,i.useEffect)(()=>(R.current=!0,()=>{var e;R.current=!1,null==(e=g.current)||e.abort();}),[]),(0,i.useEffect)(()=>{let e=a.activeChat,t=a.activeProject;if(void 0!==e&&void 0!==t)for(let n of a.messages){if("system"!==n.role||"string"!=typeof n.runId||void 0!==n.workflowStatus&&"pending"!==n.workflowStatus&&"running"!==n.workflowStatus)continue;let l=n.runId;if(void 0===l)continue;let a=`${n.id}:${l}`;E.current.has(a)||(E.current.add(a),H(e,t.path,n,a));}},[a.activeChat,a.activeProject,a.messages,H]);let _=(0,i.useCallback)(e=>{let t;b(void 0),r(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)})),F(t=>t.filter(t=>{let n;return void 0===(n=A.current.find(t=>t.id===e))||("image"===t.kind?n.supportsImageInput:n.supportsDocumentInput);}));let n=I.current;if(void 0===n)return;let l=$.current+1;$.current=l,(0,m.wi)(n,{selectedModel:e}).then(e=>{$.current!==l||I.current===e.chat.id&&(af(e.chat),r(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($.current===l&&I.current===n&&(b(am(e)),void 0!==t)){let e=t;r(t=>{var l,a;return{...t,selectedModel:(null==(l=t.activeChat)?void 0:l.id)===n?e.selectedModel:t.selectedModel,activeChat:(null==(a=t.activeChat)?void 0:a.id)===n?e.activeChat:t.activeChat,chats:t.chats.map(t=>{if(t.id!==n)return t;let l=e.chats.find(e=>e.id===n);return void 0!==l?{...t,selectedModel:l.selectedModel}:t;})};});}});},[]),G=(0,i.useCallback)(async(e,t)=>{let n=av(a.selectedModel,a.models);if(void 0===n)return void b("No conversation-eligible model is configured. Connect a gateway in Settings.");b(void 0);try{var l,i;let s=null==t?void 0:t.trim(),o={modelId:n,title:void 0!==s&&s.length>0?s:aa},c=null!=(l=null==e?void 0:e.path)?l:null==(i=a.activeProject)?void 0:i.path;void 0!==c&&(o.projectPath=c);let d=await(0,m.tA)(o);return I.current=d.chat.id,af(d.chat),r({projects:Array.from(d.projects),chats:ah(d.chats),messages:Array.from(d.messages),models:a.models,activeProject:d.project,activeChat:d.chat,selectedModel:d.chat.selectedModel}),d.chat;}catch(e){b(am(e));return;}},[a.selectedModel,a.activeProject,a.models]),J=(0,i.useCallback)(async e=>{b(void 0),r(t=>({...t,activeProject:e}));try{let t=await(0,m.Oz)(e.path),n=ah(t.chats),l=n[0];if(void 0===l)return void(await G(e));let i=await(0,m.T$)(l.id,e.path);I.current=l.id;let s=av(l.selectedModel,a.models);r(e=>({...e,chats:n,activeChat:l,selectedModel:s,messages:Array.from(i.messages)})),j(void 0);}catch(e){b(am(e));}},[G,a.models]),Y=(0,i.useCallback)(async e=>{var t;b(void 0),null==(t=g.current)||t.abort(),g.current=null,I.current=e.id,x(void 0),j(void 0),M([]);try{let t=await(0,m.T$)(e.id,e.projectPath),n=av(e.selectedModel,a.models);r(l=>{let a=l.projects.find(t=>t.path===e.projectPath);return{...l,activeProject:a,activeChat:e,selectedModel:n,messages:Array.from(t.messages)};});}catch(e){b(am(e));}},[a.models]),X=(0,i.useCallback)(async e=>{let t=e.trim();if(0!==t.length){b(void 0);try{let e=await(0,m.gA)({path:t}),n=await(0,m.vj)();r(e=>({...e,projects:Array.from(n.projects)})),await G(e.project);}catch(e){b(am(e));}}},[G]),Z=(0,i.useCallback)(e=>{r(t=>({...t,messages:t.messages.filter(t=>t.id!==e)}));},[]),Q=(0,i.useCallback)((e,t,n)=>{let l=!1;return{onToken:t=>{l||(V("streaming"),l=!0),r(n=>({...n,messages:n.messages.map(n=>n.id===e?{...n,content:n.content+t}:n)}));},onDone:l=>{r(n=>({...n,activeChat:l.chat,chats:ah([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)]})),af(l.chat),void 0!==l.memory&&j(l.memory),n("completed");},onError:t=>{let{code:l,message:a}=t;b(am(new m.hD(l,a,0))),Z(e),n("failed");},onCancelled:()=>{Z(e),n("cancelled");}};},[Z,V]),ee=(0,i.useCallback)((e,t,n,l,a,i,s)=>{let o=`stream-${String(Date.now())}`;r(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:n,modelId:a,memory:B(e,t),...(s.length>0?{documentContext:s}:{})};return new Promise((e,t)=>{let n=Q(o,l,e);(0,m.nk)(c,i,n).catch(n=>{Z(o),n instanceof m.ZF?t(n):n instanceof DOMException&&"AbortError"===n.name?e("cancelled"):(b(am(n)),r(e=>({...e,messages:e.messages.filter(e=>e.id!==l)})),e("failed"));});});},[B,Q,Z]),et=(0,i.useCallback)(async(e,t,n,l,a,i,s)=>{try{V("contacting");let o=await(0,m.xp)({chatId:e.id,projectPath:t.path,content:n,modelId:a,memory:B(e,t),...(s.length>0?{documentContext:s}:{})},i);if(i.aborted)return"cancelled";return r(e=>({...e,activeChat:o.chat,chats:ah([o.chat,...e.chats.filter(e=>e.id!==o.chat.id)]),messages:[...e.messages.filter(e=>e.id!==l),...Array.from(o.messages)]})),af(o.chat),j(o.memory),"completed";}catch(n){if(n instanceof DOMException&&"AbortError"===n.name)return"cancelled";b(am(n));try{let n=await(0,m.T$)(e.id,t.path);r(e=>({...e,messages:Array.from(n.messages)}));}catch{r(e=>({...e,messages:e.messages.filter(e=>e.id!==l)}));}return"failed";}},[B,V]),en=(0,i.useCallback)(async(e,t,n,l,r,i,s)=>{var o;if((null==(o=a.models.find(e=>e.id===r))?void 0:o.streaming)!==!0)return et(e,t,n,l,r,i,s);V("contacting");try{return await ee(e,t,n,l,r,i,s);}catch(e){if(!(e instanceof m.ZF))throw e;}return et(e,t,n,l,r,i,s);},[a.models,et,ee,V]),el=(0,i.useCallback)(async(e,t,n,l,a,i)=>{x(void 0);try{V("contacting");let t=await(0,m.Wk)({chatId:e.id,content:n,modelId:a},i);if(I.current!==e.id)return"completed";if(i.aborted)return"cancelled";x(t),j(void 0);let[l,s]=await Promise.all([(0,m.T$)(e.id,e.projectPath),(0,m.Oz)(e.projectPath)]),o=s.chats.find(t=>t.id===e.id);return r(e=>({...e,messages:Array.from(l.messages),chats:ah(s.chats),activeChat:null!=o?o:e.activeChat})),void 0!==o&&af(o),"completed";}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return"cancelled";return b(am(e)),r(e=>({...e,messages:e.messages.filter(e=>e.id!==l)})),"failed";}},[V]),ea=(0,i.useCallback)(()=>{var e;ao(f.current)&&(null==(e=g.current)||e.abort(),g.current=null,V("cancelled"));},[V]),er=(0,i.useCallback)(async e=>{var t;if(ao(f.current))return;let n=(null!=(t=null==e?void 0:e.text)?t:s).trim(),l=a.activeChat,i=a.activeProject,c=av(a.selectedModel,a.models);if(0===n.length||void 0===l||void 0===i||void 0===c)return;if(ab(l)&&T.length>0)return void b("Attachments are not supported for grounded chats. Remove the attachment or switch to a non-grounded chat.");let d={id:`local-${String(Date.now())}`,chatId:l.id,role:"user",content:n,timestamp:Date.now(),runId:void 0,workflowId:void 0,workflowStatus:void 0,shortResult:void 0,taskType:void 0};V("queued"),o(""),b(void 0),r(e=>({...e,messages:[...e.messages,d]}));let u=new AbortController();g.current=u,j(void 0);try{let e=ab(l),{entries:t,disclosures:a}=e?{entries:[],disclosures:[]}:await z(),r=e?await el(l,i,n,d.id,c,u.signal):await en(l,i,n,d.id,c,u.signal,t);"cancelled"===f.current||V(r),"completed"===r&&(q(),M(a));}finally{g.current=null;}},[s,a.activeChat,a.activeProject,a.selectedModel,a.models,T,el,en,z,q,V]),ei=(0,i.useCallback)(async e=>{var t,n,l;let i=a.activeChat;if(void 0===i||0===e.length)return;let s=null!=(t=null==(n=a.activeProject)?void 0:n.path)?t:i.projectPath;try{let t=await(0,m.IU)({chatId:i.id,projectPath:s,messages:e,memory:B(i,null!=(l=a.activeProject)?l:{path:s})});if(!R.current||I.current!==i.id)return;af(t.chat),void 0!==t.memory&&j(t.memory),r(e=>{var n;if((null==(n=e.activeChat)?void 0:n.id)!==i.id)return e;let l=new Set(e.messages.map(e=>e.id)),a=t.messages.filter(e=>!l.has(e.id));return{...e,activeChat:t.chat,chats:ah([t.chat,...e.chats.filter(e=>e.id!==t.chat.id)]),messages:[...e.messages,...a]};});}catch(e){b(am(e));}},[B,a.activeChat,a.activeProject]),es=(0,i.useCallback)(async(e,t)=>{var n;let l=a.activeChat;if(void 0===l)throw Error("No active chat is available for grounded voice.");let i=null!=(n=a.activeProject)?n:{path:l.projectPath},s=av(a.selectedModel,a.models),o=await(0,m.Du)({chatId:l.id,projectPath:i.path,callId:e.callId,query:e.query,...(void 0===e.userTranscript?{}:{userTranscript:e.userTranscript}),...(void 0===s?{}:{modelId:s}),memory:B(l,i)},t);return R.current&&I.current===l.id&&(af(o.chat),x(o.groundedAnswer),void 0!==o.memory&&j(o.memory),r(e=>{var t;if((null==(t=e.activeChat)?void 0:t.id)!==l.id)return e;let n=new Set(e.messages.map(e=>e.id)),a=o.messages.filter(e=>!n.has(e.id));return{...e,activeChat:o.chat,chats:ah([o.chat,...e.chats.filter(e=>e.id!==o.chat.id)]),messages:[...e.messages,...a]};})),o.toolOutput;},[B,a.activeChat,a.activeProject,a.models,a.selectedModel]),eo=(0,i.useCallback)(e=>{af(e),r(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};});},[]),ec=(0,i.useCallback)(()=>{b(void 0);},[]);return{projects:a.projects,chats:a.chats,messages:a.messages,models:a.models,activeProject:a.activeProject,activeChat:a.activeChat,selectedModel:a.selectedModel,noEligibleModels:!c&&void 0===av(a.selectedModel,a.models),draft:s,loading:c,sending:h,sendStatus:u,error:v,clearError:ec,setDraft:o,setSelectedModel:_,openNewChat:G,openProject:J,openChat:Y,addProject:X,sendMessage:er,appendVoiceTurn:ei,runRealtimeGroundedTool:es,cancelSend:ea,replaceChat:eo,latestGrounded:y,cancelGrounded:ea,pendingAttachments:T,addPendingAttachment:P,removePendingAttachment:L,clearPendingAttachments:q,lastSentDocuments:D,memoryEnabled:k,setMemoryEnabled:N,memoryBudgetTokens:S,setMemoryBudgetTokens:C,latestMemory:w,clearLatestMemory:O,acceptMemoryCandidate:W,rejectMemoryCandidate:K,forgetMemoryAction:U};}let aj="keiko.theme",ak="dark",aN=["agent","capsule","capsule-set","chat","connector","data-source","evidence-run","mcp-tool","memory","patch-proposal","skill","tool","workflow-run","workspace-path"],aS=["capsule","capsule-set","chat","evidence-run","memory","patch-proposal","tool","workflow-run","workspace-path"],aC=["reads-context","proposes-patch","uses-tool","starts-workflow","produces-evidence","references-document","depends-on"],aR=["draft","active","archived","superseded","revoked","blocked","stale"],aI={"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"}},aE=["prompt","documentcontent","filecontent","toolstdout","toolstderr","secret","credential","apikey","password","token"],a$="Unable to reach the local backend. Check that the Keiko server is running (keiko ui).";class aA extends Error{constructor(e,t,n,l=[]){super(t),this.name="RelationshipApiError",this.code=e,this.status=n,this.reasons=l;}}async function aT(e){let t;try{t=await e.json();}catch{throw new aA("relationship/parse-error","Response is not valid JSON.",e.status);}if(!e.ok){var n;let l=t,a=null!=(n=l.error)?n:l,r="string"==typeof a.code?a.code:"relationship/unknown-error",i="string"==typeof a.message?a.message:"An unknown error occurred.",s=Array.isArray(l.reasons)?l.reasons:[];throw new aA(r,i,e.status,s);}return t;}function aF(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 aD(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:aF({}),body:JSON.stringify(t)});return{decision:(await aT(n)).decision};}async function aM(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}:{})}},l=await fetch("/api/relationships",{method:"POST",headers:aF({idempotencyKey:t}),body:JSON.stringify(n)}),a=await aT(l);return{relationship:a.relationship,etag:a.etag};}async function aP(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?${t.toString()}`),l=await aT(n);return{entries:l.entries,truncated:l.truncated,nextCursor:l.nextCursor};}async function aL(e){let t=await fetch(`/api/relationships/${encodeURIComponent(e)}`);return(await aT(t)).relationship;}async function aq(e,t,n,l){let a=await fetch(`/api/relationships/${encodeURIComponent(e)}`,{method:"PATCH",headers:aF({idempotencyKey:l,ifMatch:n}),body:JSON.stringify({schemaVersion:"1",...t})}),r=await aT(a);return{relationship:r.relationship,etag:r.etag};}async function az(e,t,n){let l=await fetch(`/api/relationships/${encodeURIComponent(e)}`,{method:"DELETE",headers:aF({idempotencyKey:n,ifMatch:t})});return(await aT(l)).relationship;}async function aO(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 l=await fetch(`/api/relationships/${encodeURIComponent(e)}/dependencies?${n.toString()}`);return(await aT(l)).report;}async function aB(e){return aT(await fetch(`/api/relationships/${encodeURIComponent(e)}/explain`));}async function aW(){return aT(await fetch("/api/relationships/health"));}let aK=[{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 aU(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 ${e.panel} panel`;case"ui.selection.change":return"Change selection";case"ui.tab.switch":return"Switch tab";}}function aV(e){let t=[...e.mod].sort();return`${t.join("+")}|${e.key.toLowerCase()}`;}let aH={undoStack:[],redoStack:[]};class a_ extends Error{constructor(e){super(`Workspace keyboard shortcut conflicts detected: ${e.map(e=>`${aV(e.chord)} (${e.commandIds.join(", ")})`).join("; ")}`),this.name="WorkspaceShortcutConflictError",this.conflicts=e;}}class aG extends Error{constructor(e){super(`Workspace keyboard shortcut bindings refused: ${e.map(e=>`${e.commandId} → ${aV(e.chord)}`).join("; ")} are browser-reserved`),this.name="WorkspaceShortcutReservedError",this.reserved=e;}}let aJ=[{commandId:"undo",chord:{key:"z",mod:["cmd"]}},{commandId:"redo",chord:{key:"z",mod:["cmd","shift"]}},{commandId:"focus-status",chord:{key:"s",mod:["alt"]}}];var aY=n(82175);function aX(e){var t,n;let{notice:l,className:a="ui-error-notice",id:s,onDismiss:o}=e,{t:c}=ea(),d=`${l.title}
96
+ ${l.message}
97
+ ${null!=(t=l.code)?t:""}
98
+ ${null!=(n=l.remediation)?n:""}`,[u,p]=(0,i.useState)();return u===d?null:(0,r.jsxs)("div",{id:s,className:a,role:"alert","aria-live":"assertive",children:[(0,r.jsxs)("div",{className:"ui-error-notice-title-row",children:[(0,r.jsx)("div",{className:"ui-error-notice-title",children:l.title}),(0,r.jsx)("button",{type:"button",className:"ui-error-notice-close","aria-label":c("common.dismissError"),title:c("common.dismissError"),onClick:()=>{p(d),null==o||o();},children:(0,r.jsx)($.F.close,{size:14})})]}),(0,r.jsx)("div",{className:"ui-error-notice-message",children:l.message}),void 0!==l.remediation?(0,r.jsx)("div",{className:"ui-error-notice-remediation",children:l.remediation}):null,void 0!==l.code?(0,r.jsx)("div",{className:"ui-error-notice-code mono",children:l.code}):null]});}function aZ(e){let{error:t,fallback:n,className:l,id:a,onDismiss:i}=e;return(0,r.jsx)(aX,{id:a,className:l,notice:function(e,t){var n;let l;if(e instanceof m.hD){let n=lH(lK(e.message.trim()),e.code,t);return{title:l_(n,e.code),message:n,code:e.code,remediation:lG(n,e.code)};}let a=(n=lK(("string"==typeof e?e.trim():e instanceof Error?e.message.trim():"")||t),null===(l=lW.exec(n))?{message:n,code:void 0}:{message:n.slice(0,l.index).trim(),code:l[1]});return{title:l_(a.message,a.code),message:a.message,code:a.code,remediation:lG(a.message,a.code)};}(t,n),onDismiss:i});}var aQ=n(65538),a0=n(55176);let a1=/@?((?:[A-Za-z0-9_.-]+\/)*[A-Za-z0-9_.-]+\.[A-Za-z0-9][A-Za-z0-9]{0,15})(?::(\d{1,7})(?:-(\d{1,7}))?)?/gu,a2=String.raw`@?(?:[A-Za-z0-9_.-]+\/)*[A-Za-z0-9_.-]+\.[A-Za-z0-9][A-Za-z0-9]{0,15}(?::\d{1,7}(?:-\d{1,7})?)?`,a4=RegExp(String.raw`\[\s*(${a2})\s*\]`,"giu"),a3=RegExp(String.raw`\[\s*(${a2})\s*\]\s*(?:\[source:\s*[^\]]+\]\s*)?(${a2})`,"giu"),a6=RegExp(String.raw`(${a2})\s+(?:\[source:\s*[^\]]+\]\s*)?(${a2})`,"giu"),a5=/\[source:\s*[^\]]+\]/giu,a8=new Set(["astro","bash","c","cc","cjs","config","cpp","cs","css","csv","cts","go","gradle","h","hpp","htm","html","ini","java","js","json","jsonc","jsx","kt","kts","less","lock","lua","md","mdx","mjs","mts","php","py","rb","rs","sass","scala","scss","sh","sql","svelte","swift","toml","ts","tsx","txt","vue","xml","yaml","yml","zsh"]);function a9(e){return e.replace(/\\/gu,"/").replace(/^\/+/u,"").replace(/\/+$/u,"");}function a7(e){var t,n,l,a;return null===e?null:[e.path.toLowerCase(),null!=(t=null==(l=e.lineStart)?void 0:l.toString())?t:"",null!=(n=null==(a=e.lineEnd)?void 0:a.toString())?n:""].join(":");}function re(e,t,n){let l=a7(ra(e)),a=a7(ra(t));return null!==l&&l===a?e:n;}function rt(e){return e.replace(a3,(e,t,n)=>re(t,n,e.replace(a5,""))).replace(a6,(e,t,n)=>re(t,n,e.replace(a5,""))).replace(a4,(e,t)=>null===ra(t)?e:t).replace(a5,"").replace(/[ \t]{2,}/gu," ").replace(/[ \t]+([,.;:!?])/gu,"$1");}function rn(e){if(void 0===e)return;let t=Number.parseInt(e,10);return Number.isSafeInteger(t)&&t>0?t:void 0;}function rl(e,t){var n,l;let a=null!=(n=e[0])?n:"",r=e.index;if(!function(e,t){var n;if(t<=0)return!0;let l=null!=(n=e[t-1])?n:"";return!/[A-Za-z0-9_./:@-]/u.test(l);}(t,r)||!function(e,t){var n;if(t>=e.length)return!0;let l=null!=(n=e[t])?n:"";return!/[A-Za-z0-9_/:+-]/u.test(l);}(t,r+a.length))return null;let i=a9(null!=(l=e[1])?l:"");if(!function(e){var t,n,l;let a=a9(e);if(0===a.length||a!==e||a.startsWith(".")||a.includes("..")||!a.includes("."))return!1;let r=a.split("/");if(r.some(e=>0===e.length||"."===e||".."===e))return!1;let i=null!=(n=null==(l=(null!=(t=r[r.length-1])?t:"").split(".").pop())?void 0:l.toLowerCase())?n:"";return a8.has(i);}(i))return null;let s=rn(e[2]),o=rn(e[3]),c=void 0===s?void 0:Math.max(s,null!=o?o:s);return{label:a,path:i,...(void 0===s?{}:{lineStart:s}),...(void 0===c?{}:{lineEnd:c})};}function ra(e){var t,n;a1.lastIndex=0;let l=a1.exec(e);return null===l||0!==l.index||(null!=(t=null==(n=l[0])?void 0:n.length)?t:0)!==e.length?null:rl(l,e);}function rr(e){var t;let n=e.replace(/\\/gu,"/").replace(/\/+$/u,"").split("/").filter(e=>e.length>0);return null!=(t=n[n.length-1])?t:e;}function ri(e){var t;let n=null!=(t=e.path.split("/").filter(Boolean).pop())?t:e.path;return void 0===e.lineStart?n:void 0===e.lineEnd||e.lineEnd===e.lineStart?`${n}:${String(e.lineStart)}`:`${n}:${String(e.lineStart)}-${String(e.lineEnd)}`;}function rs(e){return e.replace(/\\/gu,"/").replace(/\/+$/u,"").split("/").filter(e=>e.length>0).slice(-2).join("/");}function ro(e){let{reference:t,roots:n,openReference:l,className:a="repo-ref-link"}=e,[s,o]=(0,i.useState)("idle"),[c,d]=(0,i.useState)(""),u=(0,i.useMemo)(()=>{let e=new Set(),t=[];for(let l of n){let n=l.root.trim();if(0===n.length||e.has(n))continue;e.add(n);let a=l.label.trim();t.push({root:n,label:a.length>0?a:rr(n)});}return t;},[n]),p=(0,i.useMemo)(()=>u.filter(e=>{var n,l;let a,r;return n=t.path,null===(r=void 0===(a=null==(l=a9(n).split("/")[0])?void 0:l.toLocaleLowerCase())||0===a.length?null:u.some(e=>rr(e.root).toLocaleLowerCase()===a)?a:null)||rr(e.root).toLocaleLowerCase()===r;}).map(e=>{var n,l;let a,r;return{...e,openPath:(n=t.path,l=e.root,a=a9(n),(r=a9(rr(l))).length>0&&a.startsWith(`${r}/`)?a.slice(r.length+1):a)};}).sort((e,t)=>e.openPath.length-t.openPath.length||e.root.localeCompare(t.root)),[t,u]),m=(0,i.useMemo)(()=>{let e=p[0];return void 0===e?[]:p.filter(t=>t.openPath.length===e.openPath.length);},[p]),h=(0,i.useCallback)(e=>{if(void 0===l)return;let n=e.openPath;o("opening"),d(`Opening ${n}…`);let a=l({root:e.root,path:n,...(void 0===t.lineStart?{}:{lineStart:t.lineStart}),...(void 0===t.lineEnd?{}:{lineEnd:t.lineEnd})});if(a.ok){o("opened"),d(`Opened ${n} in editor.`),window.setTimeout(()=>{o("idle"),d("");},1800);return;}o("failed"),d(a.message);},[l,t]),f=(0,i.useCallback)(()=>{if(void 0===l||0===u.length){o("failed"),d("Connect a Files window to open repository references.");return;}if(0===p.length){o("failed"),d("This repository reference does not match any connected source.");return;}if(1===m.length){let e=m[0];void 0!==e&&h(e);return;}o(e=>"choosing"===e?"idle":"choosing"),d("Select a repository source.");},[m,h,l,p.length,u.length]),g=(0,i.useCallback)(e=>{if("Escape"===e.key){o("idle"),d("");return;}("Enter"===e.key||" "===e.key)&&(e.preventDefault(),f());},[f]);if(void 0===l)return(0,r.jsx)("span",{title:t.label,children:ri(t)});let v="failed"===s;return(0,r.jsxs)("span",{className:"repo-ref",children:[(0,r.jsxs)("button",{type:"button",className:a,"aria-label":`Open ${t.path}${void 0===t.lineStart?"":void 0===t.lineEnd||t.lineEnd===t.lineStart?` at line ${String(t.lineStart)}`:` at lines ${String(t.lineStart)}-${String(t.lineEnd)}`} in editor`,"aria-expanded":m.length>1?"choosing"===s:void 0,"data-state":s,title:t.label,onClick:f,onKeyDown:g,children:[(0,r.jsx)("span",{className:"repo-ref-file-icon","aria-hidden":"true",children:(0,r.jsx)(a0.o,{name:t.path})}),(0,r.jsx)("span",{children:ri(t)})]}),"choosing"===s?(0,r.jsx)("span",{className:"repo-ref-picker",role:"dialog","aria-label":"Select repository source",children:m.map(e=>(0,r.jsxs)("button",{type:"button",className:"repo-ref-root",onClick:()=>h(e),children:[(0,r.jsx)("span",{children:e.label}),rs(e.root)===e.label?null:(0,r.jsx)("span",{className:"repo-ref-root-path",children:rs(e.root)})]},e.root))}):null,c.length>0?(0,r.jsx)("span",{role:v?"alert":"status",className:"repo-ref-status",children:c}):null]});}function rc(e){return Number.isFinite(e)?String(e):"—";}function rd(e,t){return Number.isFinite(e)?t(e):"—";}function ru(e){return e.toLocaleString("en-US");}function rp(e){return e.replaceAll("-"," ");}function rm(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:`${t}s`;return 1===e?t:n;}function rh(e){let{label:t,value:n}=e;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("dt",{className:"grounded-context-pack-dt",children:t}),(0,r.jsx)("dd",{className:"grounded-context-pack-dd",children:n})]});}function rf(e){let{summary:t}=e,n=Object.entries(t.bucketCounts).filter(e=>{let[,t]=e;return t>0;}).sort((e,t)=>t[1]!==e[1]?t[1]-e[1]:e[0]<t[0]?-1:1);return 0===n.length?null:(0,r.jsxs)("details",{className:"grounded-ranking-rationale",children:[(0,r.jsx)("summary",{"aria-label":"Why these files were selected",children:"Why these files?"}),(0,r.jsx)("dl",{className:"grounded-context-pack-dl",children:n.map(e=>{let[t,n]=e;return(0,r.jsx)(rh,{label:rp(t),value:ru(n)},`bucket-${t}`);})}),t.ecosystems.length>0?(0,r.jsx)("p",{className:"grounded-ranking-ecosystems",children:`Ecosystems: ${t.ecosystems.map(e=>`${e.id} (${ru(e.count)})`).join(", ")}`}):null]});}function rg(e){let{contextPack:t}=e,{usage:n,budget:l}=t,a=function(e){if("workspace-root"===e.scopeKind)return"workspace root";let t=e.scopeId.slice(-8);return`${rp(e.scopeKind)} (${t})`;}(t),i="files"===t.scopeKind?`Scope: ${String(t.fileCount)} file${1===t.fileCount?"":"s"} in ${a}`:`Scope: ${a}`;return(0,r.jsxs)("section",{className:"grounded-context-pack","aria-label":"Context inspection summary",children:[(0,r.jsx)("div",{className:"grounded-context-pack-headline",children:i}),(0,r.jsxs)("dl",{className:"grounded-context-pack-dl",children:[(0,r.jsx)(rh,{label:"Searched",value:`${String(n.searchCalls)} / ${rc(l.searchCallsMax)} searches`}),(0,r.jsx)(rh,{label:"Read",value:`${String(n.filesRead)} / ${rc(l.filesReadMax)} files`}),(0,r.jsx)(rh,{label:"Bytes",value:`${(0,aQ.z3)(n.excerptBytes)} / ${rd(l.excerptBytesMax,aQ.z3)}`}),(0,r.jsx)(rh,{label:"Input",value:`${ru(n.modelInputTokens)} / ${rd(l.modelInputTokensMax,ru)} tokens`}),(0,r.jsx)(rh,{label:"Output",value:`${ru(n.modelOutputTokens)} / ${rd(l.modelOutputTokensMax,ru)} tokens`}),(0,r.jsx)(rh,{label:"Rerank",value:`${String(n.rerankCalls)} / ${rc(l.rerankCallsMax)} calls`}),(0,r.jsx)(rh,{label:"Time",value:`${(0,aQ._V)(t.elapsedMs)} / ${rd(l.elapsedMsMax,aQ._V)}`}),(0,r.jsx)(rh,{label:"Query",value:rp(t.queryKind)})]}),void 0!==t.rankingSummary?(0,r.jsx)(rf,{summary:t.rankingSummary}):null]});}function rv(e){return void 0===e.lineRange?e.scopePath:`${e.scopePath}:${String(e.lineRange.startLine)}-${String(e.lineRange.endLine)}`;}function rb(e){let{score:t}=e;return(0,r.jsxs)("span",{className:"grounded-citation-score",children:[(0,r.jsx)("span",{className:"sr-only",children:"relevance "}),t.toFixed(2)]});}function ry(e){var t;let{citation:n,repositoryRoots:l,openRepositoryReference:a}=e,i=null==(t=n.documentFormat)?void 0:t.toUpperCase(),s=void 0===i&&void 0!==a&&l.length>0;return(0,r.jsxs)("span",{className:"grounded-citation",title:function(e){let t=`relevance ${e.score.toFixed(2)}`,n=void 0===e.documentFormat?"Evidence citation":`${e.documentFormat.toUpperCase()} document evidence (extracted text)`;if(void 0===e.lineRange)return`${n} in ${e.scopePath} — ${t}`;let l=void 0===e.documentFormat?`at lines ${String(e.lineRange.startLine)}-${String(e.lineRange.endLine)}`:`at extracted span ${String(e.lineRange.startLine)}-${String(e.lineRange.endLine)}`;return`${n} in ${e.scopePath} ${l} — ${t}`;}(n),children:[void 0===i?null:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"grounded-citation-doc-badge",children:i}),(0,r.jsx)("span",{className:"sr-only",children:" document evidence extracted text "})]}),(0,r.jsx)("span",{className:"grounded-citation-range",children:s?(0,r.jsx)(ro,{reference:{label:rv(n),path:n.scopePath,...(void 0===n.lineRange?{}:{lineStart:n.lineRange.startLine,lineEnd:n.lineRange.endLine})},roots:l,openReference:a,className:"repo-ref-link grounded-citation-open"}):rv(n)}),(0,r.jsx)(rb,{score:n.score})]});}function rx(e){let t=new Set(),n=[];for(let l of e)t.has(l.stableId)||(t.add(l.stableId),n.push(l));return n;}function rw(e){let{total:t,expanded:n,onToggle:l}=e;return t<=8?null:(0,r.jsx)("button",{type:"button",className:"grounded-citations-more","aria-expanded":n,onClick:l,children:n?"Show fewer citations":`Show all ${String(t)} citations`});}function rj(e){let{citations:t,repositoryRoots:n,openRepositoryReference:l}=e,[a,s]=(0,i.useState)(!1);if(0===t.length)return null;let o=rx([...t].sort((e,t)=>t.score-e.score)),c=a?o:o.slice(0,8);return(0,r.jsxs)("div",{className:"grounded-citations-wrap",children:[(0,r.jsx)("span",{className:"grounded-citations-label",children:"Evidence"}),(0,r.jsx)("ul",{className:"grounded-citations","aria-label":"Evidence citations",children:c.map(e=>(0,r.jsx)("li",{className:"grounded-citations-item",children:(0,r.jsx)(ry,{citation:e,repositoryRoots:n,openRepositoryReference:l})},e.stableId))}),(0,r.jsx)(rw,{total:o.length,expanded:a,onToggle:()=>{s(e=>!e);}})]});}function rk(e){return rx(e).length;}function rN(e){let{title:t,summary:n,hasCoverageWarning:l=!1,children:a}=e;return(0,r.jsxs)("details",{className:"grounded-evidence-disclosure",children:[(0,r.jsxs)("summary",{className:"grounded-evidence-summary",children:[(0,r.jsx)("span",{className:"grounded-evidence-summary-title",children:t}),(0,r.jsx)("span",{className:"grounded-evidence-summary-meta",children:n}),l?(0,r.jsx)("span",{className:"grounded-evidence-summary-badge",children:"Partial coverage"}):null]}),(0,r.jsx)("div",{className:"grounded-evidence-body",children:a})]});}function rS(e){let{citations:t}=e,[n,l]=(0,i.useState)(!1);if(0===t.length)return null;let a=rx([...t].sort((e,t)=>t.score-e.score)),s=n?a:a.slice(0,8);return(0,r.jsxs)("div",{className:"grounded-citations-wrap",children:[(0,r.jsx)("span",{className:"grounded-citations-label",children:"Knowledge citations"}),(0,r.jsx)("ul",{className:"grounded-citations","aria-label":"Knowledge citations",children:s.map(e=>(0,r.jsx)("li",{className:"grounded-citations-item",children:(0,r.jsxs)("span",{className:"grounded-citation",title:void 0===e.source?`${e.label} — relevance ${e.score.toFixed(2)}`:`${e.source} \xb7 ${e.label} — relevance ${e.score.toFixed(2)}`,children:[(0,r.jsx)("span",{children:void 0===e.source?`${e.marker} ${e.label}`:`${e.marker} ${e.source} \xb7 ${e.label}`}),(0,r.jsx)(rb,{score:e.score})]})},e.stableId))}),(0,r.jsx)(rw,{total:a.length,expanded:n,onToggle:()=>{l(e=>!e);}})]});}function rC(e){let{markers:t}=e;if(0===t.length)return null;let n=Array.from(new Set(t.map(e=>rp(e.kind)))).join(", ");return(0,r.jsxs)("div",{className:"grounded-uncertainty",role:"note",children:[(0,r.jsx)("div",{children:`Uncertainty (${String(t.length)} markers — ${n})`}),(0,r.jsx)("ul",{className:"grounded-uncertainty-list",children:t.map((e,t)=>(0,r.jsx)("li",{children:`${rp(e.kind)}: ${e.claim}`},`${e.kind}-${String(t)}`))})]});}function rR(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,[l]=t;return n<l?-1:+(n>l);}).map(e=>{let[t,n]=e;return`${rp(t)}: ${String(n)}`;}).join(", "),a=l.length>0?` (${l})`:"";return(0,r.jsx)("div",{className:"grounded-meta",children:`Not used: ${String(t)} excerpt${1===t?"":"s"}${a}`});}let rI=[{reason:"size-exceeded",label:"larger than 2 MB"},{reason:"binary",label:"binary or an unsupported format"},{reason:"tool-unavailable",label:"unreadable"},{reason:"unsupported-format",label:"an unsupported document format"},{reason:"no-text-layer",label:"a scanned document with no text layer"},{reason:"malformed-document",label:"a malformed document"},{reason:"encrypted-document",label:"a password-protected document"}];function rE(e){var t,n,l,a,i;let{omittedCounts:s}=e,o=rI.map(e=>{var t;let{reason:n,label:l}=e;return{label:l,count:null!=(t=s[n])?t:0};}).filter(e=>e.count>0),c=o.reduce((e,t)=>e+t.count,0);if(c<=0)return null;let d=o.map(e=>`${String(e.count)} ${e.label}`).join(", "),u=(null!=(t=s.binary)?t:0)>0||(null!=(n=s["unsupported-format"])?n:0)>0||(null!=(l=s["no-text-layer"])?l:0)>0||(null!=(a=s["malformed-document"])?a:0)>0||(null!=(i=s["encrypted-document"])?i:0)>0;return(0,r.jsxs)("div",{className:"grounded-coverage-notice",role:"note",children:[(0,r.jsx)("span",{className:"grounded-coverage-notice-title",children:"Partial coverage"}),(0,r.jsx)("span",{children:`This answer reflects only the searchable files in the connected scope — ${String(c)} ${1===c?"file":"files"} ${1===c?"was":"were"} not searched (${d}). It does not cover the entire folder.`}),u?(0,r.jsx)("span",{children:"Repository Search reads text, code, and small DOCX, XLSX, and text-layer PDF documents. Larger, scanned, encrypted, or other document formats remain available through Local Knowledge."}):null]});}function r$(e){return rI.some(t=>{let{reason:n}=t;return e[n]>0;});}function rA(e){let{runId:t,runIds:n}=e,l=Array.from(new Set([...(void 0===t?[]:[t]),...(null!=n?n:[])]));return 0===l.length?null:(0,r.jsx)("div",{className:"grounded-meta",children:l.map((e,t)=>(0,r.jsxs)("a",{className:"sm-link",href:`/api/evidence/${encodeURIComponent(e)}`,target:"_blank",rel:"noopener noreferrer",children:[1===l.length?"View connected-context audit evidence":`View connected-context audit evidence ${String(t+1)}`," ",(0,r.jsx)("span",{className:"sr-only",children:"(opens in new tab)"})]},e))});}function rT(e){let{contextPack:t}=e;return(0,r.jsxs)("section",{className:"grounded-context-pack","aria-label":"Knowledge scope summary",children:[(0,r.jsx)("div",{className:"grounded-context-pack-headline",children:`Knowledge scope: ${t.scopeLabel}`}),(0,r.jsxs)("dl",{className:"grounded-context-pack-dl",children:[(0,r.jsx)(rh,{label:"Mode",value:rp(t.scopeKind)}),(0,r.jsx)(rh,{label:"Capsules",value:String(t.capsuleCount)}),(0,r.jsx)(rh,{label:"Sources",value:String(t.sourceCount)}),(0,r.jsx)(rh,{label:"Citations",value:String(t.citationCount)}),(0,r.jsx)(rh,{label:"Context budget",value:`${String(t.referencesUsed)} / ${String(t.referenceBudget)} references`})]})]});}function rF(e){let{contextPack:t}=e;return(0,r.jsxs)("section",{className:"grounded-context-pack","aria-label":"Hybrid source summary",children:[(0,r.jsx)("div",{className:"grounded-context-pack-headline",children:`Hybrid: ${String(t.folderSourceCount)} folder source${1===t.folderSourceCount?"":"s"} + ${String(t.connectorSourceCount)} connector source${1===t.connectorSourceCount?"":"s"}`}),(0,r.jsx)(rg,{contextPack:t.folder}),(0,r.jsx)(rT,{contextPack:t.knowledge})]});}function rD(e){let t,n,l,a,i,s,{answer:o,busy:c,repositoryRoots:d=[],openRepositoryReference:u}=e;if(void 0===o)return c?(0,r.jsx)("div",{className:"grounded-meta",role:"status","aria-live":"polite","aria-busy":"true",children:"Searching connected sources and asking Keiko…"}):null;if("local-knowledge"===o.groundingKind){let e,t;return(0,r.jsx)("div",{className:"grounded-answer",children:(0,r.jsxs)(rN,{title:"Knowledge evidence",summary:(t=rm(e=rk(o.citations),"citation"),`${ru(e)} ${t} \xb7 ${ru(o.contextPack.referencesUsed)} / ${ru(o.contextPack.referenceBudget)} references`),children:[(0,r.jsx)(rS,{citations:o.citations}),(0,r.jsx)(rC,{markers:o.uncertainty}),(0,r.jsx)(rT,{contextPack:o.contextPack})]})});}if("hybrid"===o.groundingKind){let e,t;return(0,r.jsx)("div",{className:"grounded-answer",children:(0,r.jsxs)(rN,{title:"Grounding evidence",summary:(e=rk(o.citations),t=rk(o.knowledgeCitations),`${ru(e)} file ${rm(e,"citation")} \xb7 ${ru(t)} knowledge ${rm(t,"citation")}`),hasCoverageWarning:r$(o.contextPack.folder.omittedCounts),children:[(0,r.jsx)(rE,{omittedCounts:o.contextPack.folder.omittedCounts}),(0,r.jsx)(rj,{citations:o.citations,repositoryRoots:d,openRepositoryReference:u}),(0,r.jsx)(rS,{citations:o.knowledgeCitations}),(0,r.jsx)(rC,{markers:o.uncertainty}),(0,r.jsx)(rR,{omittedCount:o.omittedCount,omittedCounts:o.contextPack.folder.omittedCounts}),(0,r.jsx)(rA,{runId:o.evidenceRunId,runIds:o.evidenceRunIds}),(0,r.jsx)(rF,{contextPack:o.contextPack})]})});}return(0,r.jsx)("div",{className:"grounded-answer",children:(0,r.jsxs)(rN,{title:"Evidence",summary:(t=rk(o.citations),n=o.contextPack.usage.filesRead,l=rc(o.contextPack.budget.filesReadMax),a=o.contextPack.omittedCount,i=rm(t,"citation"),s=a>0?` \xb7 ${ru(a)} not used`:"",`${ru(t)} ${i} \xb7 ${ru(n)} / ${l} files read${s}`),hasCoverageWarning:r$(o.contextPack.omittedCounts),children:[(0,r.jsx)(rE,{omittedCounts:o.contextPack.omittedCounts}),(0,r.jsx)(rj,{citations:o.citations,repositoryRoots:d,openRepositoryReference:u}),(0,r.jsx)(rC,{markers:o.uncertainty}),(0,r.jsx)(rR,{omittedCount:o.contextPack.omittedCount,omittedCounts:o.contextPack.omittedCounts}),(0,r.jsx)(rA,{runId:o.evidenceRunId,runIds:o.evidenceRunIds}),(0,r.jsx)(rg,{contextPack:o.contextPack})]})});}function rM(e){return e.charAt(0).toUpperCase()+e.slice(1);}function rP(e){let{laneCounts:t}=e,n=Object.entries(t).filter(e=>{let[,t]=e;return t>0;});return(0,r.jsx)(r.Fragment,{children:n.map(e=>{let[t,n]=e;return(0,r.jsx)(rh,{label:rp(t),value:n.toLocaleString("en-US")},`lane-${t}`);})});}function rL(e){var t;let n,{contextSummary:l}=e;return void 0===l?null:(0,r.jsxs)("details",{className:"ctx-status grounded-evidence-disclosure",children:[(0,r.jsxs)("summary",{className:"ctx-status-summary grounded-evidence-summary","aria-label":"Context assembly details",title:"Conservative assembled-context estimate for this grounded answer, produced by the context allocator's keiko-conservative-utf8-v1 token estimator. It is separate from the live composer context below.",children:[(0,r.jsx)("span",{className:"grounded-evidence-summary-title",children:"Context"}),(0,r.jsx)("span",{className:"grounded-evidence-summary-meta",children:(n=Object.values((t=l).laneCounts).filter(e=>e>0).length,[`${(0,aQ._y)(t.totalEstimatedTokens)} est. assembled tokens`,`${rM(t.budgetPressure)} pressure`,`${n.toLocaleString("en-US")} ${1===n?"lane":"lanes"}`,t.compactionActive?"Compaction active":"Compaction inactive"].join(" \xb7 "))})]}),(0,r.jsx)("div",{className:"ctx-status-body grounded-evidence-body",children:(0,r.jsxs)("dl",{className:"ctx-status-dl grounded-context-pack-dl",children:[(0,r.jsx)(rh,{label:"Estimator",value:"keiko-conservative-utf8-v1"}),(0,r.jsx)(rh,{label:"Assembled estimate",value:`${(0,aQ._y)(l.totalEstimatedTokens)} tok`}),(0,r.jsx)(rh,{label:"Budget pressure",value:rM(l.budgetPressure)}),(0,r.jsx)(rP,{laneCounts:l.laneCounts}),(0,r.jsx)(rh,{label:"Compaction",value:l.compactionActive?"Active":"Inactive"})]})})]});}let rq=["<script","</script","<iframe","</iframe","<object","</object","<embed","</embed","<style","</style","<svg","</svg","<form","</form","<meta","<link","<base"],rz=[" ","\n"," ","'",'"'];function rO(e){var t;let n=function(e){let t=e.toLowerCase().replaceAll("\0",""),n="";for(let e=0;e<t.length;e++){var l;let a=null!=(l=t[e])?l:"";if("<"===a){for(n+="<";e+1<t.length&&(" "===t[e+1]||" "===t[e+1]||"\n"===t[e+1]||"\r"===t[e+1]);)e++;continue;}n+=a;}return n;}(e);for(let e of rq)if(n.includes(e))return!0;let l=0;for(;l<n.length-4;){let e=n[l];if(rz.includes(e)&&"o"===n[l+1]&&"n"===n[l+2]){let e=l+3;for(;e<n.length&&/[a-z]/.test(null!=(t=n[e])?t:"");)e++;if(e<n.length&&"="===n[e])return!0;}l++;}return!1;}function rB(e,t,n,l){l>n&&e.push({kind:"text",text:t.slice(n,l)});}function rW(e){return void 0!==e&&/[A-Za-z0-9]/.test(e);}let rK=new Set([" "," ","\n","<",">",'"']),rU=new Set([".",",",")","]","!","?"]);function rV(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=[],l=0,a=0;for(;l<e.length;){let r=function(e,t,n,l){if("`"!==t[n])return-1;let a=t.indexOf("`",n+1);return-1===a?-1:(rB(e,t,l,n),e.push({kind:"inline-code",text:t.slice(n+1,a)}),a+1);}(n,e,l,a);if(-1!==r||-1!==(r=function(e,t,n,l,a){let r=t[n],i=t[n+1];if(n+1>=t.length||("*"!==r||"*"!==i)&&("_"!==r||"_"!==i))return-1;let s=t.indexOf(r+i,n+2);if(-1===s)return-1;rB(e,t,l,n);let o=t.slice(n+2,s);return e.push({kind:"strong",children:rV(o,a+1)}),s+2;}(n,e,l,a,t))||-1!==(r=function(e,t,n,l,a){let r=t[n];if("*"!==r&&"_"!==r||"_"===r&&rW(t[n-1])&&rW(t[n+1])||t[n+1]===r||n>0&&t[n-1]===r)return-1;let i=function(e,t,n){for(let l=n;l<e.length;l++)if(e[l]===t&&e[l-1]!==t&&(l+1>=e.length||e[l+1]!==t))return l;return-1;}(t,r,n+1);return-1===i||"_"===r&&rW(t[i-1])&&rW(t[i+1])?-1:(rB(e,t,l,n),e.push({kind:"em",children:rV(t.slice(n+1,i),a+1)}),i+1);}(n,e,l,a,t))||-1!==(r=function(e,t,n,l){let a;if("["!==t[n])return-1;let r=t.indexOf("]",n+1);if(-1===r||"("!==t[r+1])return-1;let i=t.indexOf(")",r+2);if(-1===i)return-1;let s=t.slice(n+1,r),o=t.slice(r+2,i);return rB(e,t,l,n),((a=o.trim().toLowerCase()).startsWith("http://")||a.startsWith("https://"))&&!rO(s)&&!rO(o)?e.push({kind:"link",text:s,href:o}):e.push({kind:"text",text:`[${s}](${o})`}),i+1;}(n,e,l,a))||-1!==(r=function(e,t,n,l){if("h"!==t[n])return-1;let a="https://"===t.slice(n,n+8),r="http://"===t.slice(n,n+7);if(!a&&!r)return-1;let i=function(e,t){var n,l;let a=t;for(;a<e.length&&!rK.has(null!=(n=e[a])?n:"");)a++;for(;a>t&&rU.has(null!=(l=e[a-1])?l:"");)a--;return a;}(t,n);if(i-n<=(a?8:7))return-1;let s=t.slice(n,i);return rB(e,t,l,n),e.push({kind:"link",text:s,href:s}),i;}(n,e,l,a))){a=r,l=r;continue;}l++;}return rB(n,e,a,e.length),n;}function rH(e){let t=e.trim(),n=t.startsWith(":"),l=t.endsWith(":");return n&&l?"center":l?"right":n?"left":void 0;}function r_(e){let t=e.trim();return t.startsWith("|")&&(t=t.slice(1)),t.endsWith("|")&&(t=t.slice(0,-1)),t.split("|");}function rG(e){var t,n,l;let a=/^( *)([*+\-]) (.*)$/.exec(e);return a?{match:!0,indent:null!=(t=null==(l=a[1])?void 0:l.length)?t:0,text:null!=(n=a[3])?n:""}:{match:!1};}function rJ(e){var t,n,l;let a=/^( *)\d+\. (.*)$/.exec(e);return a?{match:!0,indent:null!=(t=null==(l=a[1])?void 0:l.length)?t:0,text:null!=(n=a[2])?n:""}:{match:!1};}function rY(e){return e.includes("|");}function rX(e){let t=e.trim();return /^(-{3,}|\*{3,}|_{3,})$/.test(t);}function rZ(e,t){let n=[],l=t?rJ:rG;for(;e.i<e.lines.length;){var a;let t=null!=(a=e.lines[e.i])?a:"",r=l(t);if(r.match)n.push({text:r.text,indent:r.indent}),e.i++;else if(""===t.trim())break;else break;}return function e(t,n,l){let a=n?"ol":"ul",r=[],i=0;for(;i<t.length;){let a=t[i];if(void 0===a){i++;continue;}let s=a.indent,o=[];for(i++;i<t.length;){let e=t[i];if(void 0===e||e.indent<=s)break;o.push(e),i++;}let c=[...rV(a.text)];o.length>0&&l<16?c.push(e(o,n,l+1)):o.length>0&&c.push({kind:"text",text:o.map(e=>e.text).join("\n")}),r.push({kind:"li",children:c});}return{kind:a,children:r};}(n,t,e.depth);}let rQ={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 r0(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 l=n.split("."),a=l.length>1?l[l.length-1]:void 0;return void 0===a?"code":null!=(t=rQ[a])?t:"code";}let r1=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 r2(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 r4(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,l,a;return[["ws",null!=(n=t[1])?n:""],["key",null!=(l=t[2])?l:""],["ws",null!=(a=t[3])?a:""],...r2(e.slice(t[0].length))];}return r2(e);});if("json"===t)return e.split("\n").map(e=>{let t=[],n=0;for(;n<e.length;){let l=e.slice(n),a=/^"(?:[^"\\]|\\.)*"/.exec(l);if(null!==a){let l=e.slice(n+a[0].length),r=/^\s*:/.test(l);t.push([r?"key2":"str",a[0]]),n+=a[0].length;continue;}let r=/^-?\d[\d.eE+\-]*/.exec(l);if(null!==r){t.push(["num",r[0]]),n+=r[0].length;continue;}let i=/^(true|false|null)\b/.exec(l);if(null!==i){t.push(["lit",i[0]]),n+=i[0].length;continue;}let s=/^\s+/.exec(l);if(null!==s){t.push(["ws",s[0]]),n+=s[0].length;continue;}t.push(["punct",l.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:["/*","*/"]},l={inBlock:!1},a=[];for(let t of e.split("\n"))a.push(function(e,t,n){let l=[],a=0;if(t.inBlock&&null!==n.block){let r=e.indexOf(n.block[1]);if(-1===r)return l.push(["com",e]),l;l.push(["com",e.slice(0,r+n.block[1].length)]),a=r+n.block[1].length,t.inBlock=!1;}for(;a<e.length;){let i=e.slice(a);if(null!==n.line&&i.startsWith(n.line)){l.push(["com",i]);break;}if(null!==n.block&&i.startsWith(n.block[0])){let r=e.indexOf(n.block[1],a+n.block[0].length);if(-1===r){l.push(["com",i]),t.inBlock=!0;break;}l.push(["com",e.slice(a,r+n.block[1].length)]),a=r+n.block[1].length;continue;}let s=/^(?:"(?:[^"\\]|\\.)*"?|'(?:[^'\\]|\\.)*'?)/.exec(i);if(null!==s&&s[0].length>1){l.push(["str",s[0]]),a+=s[0].length;continue;}if(/^\d/.test(i)){var r;let e=/^\d[\w.]*/.exec(i),t=null!=(r=null==e?void 0:e[0])?r:i.charAt(0);l.push(["num",t]),a+=t.length;continue;}let o=/^[@A-Za-z_$][\w$]*/.exec(i);if(null!==o){let t=o[0],n="id";r1.has(t)||r1.has(t.toLowerCase())?n="key":t.startsWith("@")||/^[A-Z]/.test(t)?n="type":"("===e.charAt(a+t.length)&&(n="fn"),l.push([n,t]),a+=t.length;continue;}let c=/^\s+/.exec(i);if(null!==c){l.push(["ws",c[0]]),a+=c[0].length;continue;}let d=/^[^\w\s$@"']+/.exec(i);if(null!==d){l.push(["punct",d[0]]),a+=d[0].length;continue;}l.push(["id",i.charAt(0)]),a+=1;}return l;}(t,l,n));return a;}function r3(e){let{text:t}=e,[n,l]=(0,i.useState)("idle"),[a,s]=(0,i.useState)(""),o=(0,i.useCallback)(()=>{var e;if("u"<typeof navigator||(null==(e=navigator.clipboard)?void 0:e.writeText)===void 0){l("failed"),s("Clipboard unavailable. Select the code manually and copy it.");return;}navigator.clipboard.writeText(t).then(()=>{l("copied"),s("Code copied"),setTimeout(()=>{l("idle"),s("");},1500);},()=>{l("failed"),s("Clipboard access failed. Select the code manually and copy it.");});},[t]),c="copied"===n;return(0,r.jsxs)("div",{className:"sm-code-copy-wrap",children:[(0,r.jsxs)("button",{type:"button",className:"sm-code-copy","aria-label":c?"Copied":"Copy code block",title:c?"Copied":"Copy code block","data-copied":c?"true":"false","data-failed":"failed"===n?"true":"false",onClick:o,children:[(0,r.jsx)($.F.copy,{size:13,"aria-hidden":"true"}),(0,r.jsx)("span",{children:c?"Copied":"Copy"})]}),(0,r.jsx)("span",{role:"status",className:"sm-code-copy-status",children:a})]});}function r6(e){var t;let n,{text:l,language:a,codeClass:i,long:s}=e,o=r4(l,0===(n=null!=(t=null==a?void 0:a.trim().toLowerCase())?t:"").length?"code":"typescript"===n||"tsx"===n?"ts":"javascript"===n||"jsx"===n||"node"===n?"js":"python"===n?"py":"shell"===n||"bash"===n||"zsh"===n?"sh":"markdown"===n?"md":"yml"===n?"yaml":"plaintext"===n||"text"===n||"plain"===n?"code":r0(`snippet.${n}`)),c=Math.max(2,String(o.length).length);return(0,r.jsx)("pre",{className:"sm-pre","data-long":s?"true":"false",role:"region","aria-label":`${null!=a?a:"text"} code block`,tabIndex:0,style:{"--sm-code-line-no-width":`${String(c)}ch`},children:(0,r.jsx)("code",{className:i,children:o.map((e,t)=>(0,r.jsxs)("span",{className:"sm-code-line",children:[(0,r.jsx)("span",{className:"sm-code-line-no","aria-hidden":"true",children:t+1}),(0,r.jsx)("span",{className:"sm-code-line-src",children:e.map((e,n)=>(0,r.jsx)("span",{className:`hl-${e[0]}`,children:e[1]},`${String(t)}-${String(n)}`))})]},t))})});}let r5={1:"h3",2:"h4",3:"h5",4:"h6",5:"h6",6:"h6"},r8={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 r9(e,t,n){return void 0===e.children?null:e.children.map((e,l)=>r7(e,t+"-"+String(l),n));}function r7(e,t,n){let l=function(e,t,n){var l,a;switch(e.kind){case"paragraph":return(0,r.jsx)("p",{className:"sm-p",children:r9(e,t,n)},t);case"heading":{let a=null!=(l=e.level)?l:1,i=r5[a],s=r8[a];return(0,r.jsx)(i,{className:s,children:r9(e,t,n)},t);}case"blockquote":return(0,r.jsx)("blockquote",{className:"sm-blockquote",children:r9(e,t,n)},t);case"hr":return(0,r.jsx)("hr",{className:"sm-hr"},t);case"code-block":{let n=e.language,l=null!=(a=e.text)?a:"",i=void 0!==n?`lang-${n}`:void 0,s=(0===l.length?1:l.split(/\r\n|\r|\n/u).length)>24;return(0,r.jsxs)("div",{className:"sm-code-block-frame","data-long":s?"true":"false",children:[(0,r.jsxs)("div",{className:"sm-code-block-header",children:[(0,r.jsx)("span",{className:"sm-code-lang",children:null!=n?n:"text"}),(0,r.jsx)(r3,{text:l})]}),(0,r.jsx)(r6,{text:l,language:n,codeClass:i,long:s})]},t);}default:return null;}}(e,t,n);if(null!==l)return l;let a=function(e,t,n){switch(e.kind){case"ul":return(0,r.jsx)("ul",{className:"sm-ul",children:r9(e,t,n)},t);case"ol":return(0,r.jsx)("ol",{className:"sm-ol",children:r9(e,t,n)},t);case"li":return(0,r.jsx)("li",{className:"sm-li",children:r9(e,t,n)},t);default:return null;}}(e,t,n);if(null!==a)return a;let i=function(e,t,n){let l=void 0!==e.align?{textAlign:e.align}:void 0;switch(e.kind){case"table":return(0,r.jsx)("div",{className:"sm-table-wrapper",children:(0,r.jsx)("table",{className:"sm-table",children:r9(e,t,n)})},t);case"thead":return(0,r.jsx)("thead",{children:r9(e,t,n)},t);case"tbody":return(0,r.jsx)("tbody",{children:r9(e,t,n)},t);case"tr":return(0,r.jsx)("tr",{children:r9(e,t,n)},t);case"th":return(0,r.jsx)("th",{style:l,children:r9(e,t,n)},t);case"td":return(0,r.jsx)("td",{style:l,children:r9(e,t,n)},t);default:return null;}}(e,t,n);if(null!==i)return i;let s=function(e,t,n){var l,a;switch(e.kind){case"text":return function(e,t,n){var l;let a=rt(e);if(void 0===n.openRepositoryReference)return(0,r.jsx)("span",{children:a},t);let i=function(e){let t=[],n=0;for(a1.lastIndex=0;;){var l,a;let r=a1.exec(e);if(null===r)break;let i=rl(r,e);null!==i&&(r.index>n&&t.push({kind:"text",text:e.slice(n,r.index)}),t.push({kind:"reference",reference:i}),n=r.index+(null!=(l=null==(a=r[0])?void 0:a.length)?l:0));}return 0===n?[{kind:"text",text:e}]:(n<e.length&&t.push({kind:"text",text:e.slice(n)}),t);}(a);return 1===i.length&&(null==(l=i[0])?void 0:l.kind)==="text"?(0,r.jsx)("span",{children:a},t):(0,r.jsx)("span",{children:i.map((e,l)=>{let a=`${t}-repo-${String(l)}`;if("text"===e.kind)return(0,r.jsx)("span",{children:e.text},a);let i=e.reference;return void 0===i?null:(0,r.jsx)(ro,{reference:i,roots:n.repositoryRoots,openReference:n.openRepositoryReference},a);})},t);}(null!=(l=e.text)?l:"",t,n);case"inline-code":let i,s;return i=null!=(a=e.text)?a:"",s=void 0===n.openRepositoryReference?null:ra(i),(0,r.jsx)("code",{className:"sm-inline-code",children:null===s?i:(0,r.jsx)(ro,{reference:s,roots:n.repositoryRoots,openReference:n.openRepositoryReference,className:"repo-ref-link repo-ref-link-inline-code"})},t);case"link":return(0,r.jsxs)("a",{href:e.href,className:"sm-link",rel:"noopener noreferrer",target:"_blank",children:[e.text,(0,r.jsx)("span",{className:"sr-only",children:" (opens in new tab)"})]},t);case"strong":return(0,r.jsx)("strong",{children:r9(e,t,n)},t);case"em":return(0,r.jsx)("em",{children:r9(e,t,n)},t);default:return null;}}(e,t,n);return null!==s?s:null;}function ie(e){let{source:t,repositoryRoots:n=[],openRepositoryReference:l}=e,a=function e(t,n){let l=[],a={lines:t.split("\n"),i:0,depth:n};for(;a.i<a.lines.length;)!function(t,n){var l,a;let r=null!=(l=t.lines[t.i])?l:"";if(""===r.trim())return t.i++;if(function(e,t,n){var l;let a=/^(`{3,}|~{3,})(\S*)/.exec(t.trim());if(null===a)return!1;let r=null!=(l=a[1])?l:"```",i=a[2],s=void 0!==i&&i.length>0?i:void 0;return n.push(function(e,t,n){let l=[];for(e.i++;e.i<e.lines.length;){var a,r,i;let n=null!=(a=e.lines[e.i])?a:"",s=/^(`{3,}|~{3,})\s*$/.exec(n.trim());if(null!==s){let n=null!=(r=s[1])?r:"";if(n.startsWith(null!=(i=t[0])?i:"")&&n.length>=t.length){e.i++;break;}}l.push(n),e.i++;}let s={kind:"code-block",text:l.join("\n")};return void 0!==n?{...s,language:n}:s;}(e,r,s)),!0;}(t,r,n)||function(e,t,n){var l,a;let r=/^(#{1,6}) (.+)$/.exec(t.trim());if(null===r)return!1;let i=Math.min((null!=(l=r[1])?l:"").length,6),s=null!=(a=r[2])?a:"";return n.push({kind:"heading",level:i,children:rV(s)}),e.i++,!0;}(t,r,n))return;if(rX(r)){n.push({kind:"hr"}),t.i++;return;}if(r.trimStart().startsWith("> ")||">"===r.trim())return n.push(function(t){let n=[];for(;t.i<t.lines.length;){var l;let e=null!=(l=t.lines[t.i])?l:"";if(e.trimStart().startsWith("> ")||">"===e.trim())n.push(e.replace(/^( *)> ?/,"")),t.i++;else break;}let a=n.join("\n");return t.depth>=16?{kind:"blockquote",children:[{kind:"paragraph",children:[{kind:"text",text:a}]}]}:{kind:"blockquote",children:[...e(a,t.depth+1)]};}(t));if(rY(r.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;}(r_(null!=(a=t.lines[t.i+1])?a:""))&&(n.push(function(e,t){var n,l;let a,r;e.i++;let i=null!=(n=e.lines[e.i])?n:"",s=[];for(e.i++;e.i<e.lines.length;){let t=null!=(l=e.lines[e.i])?l:"";if(""===t.trim()||!rY(t.trim()))break;s.push(t),e.i++;}return a=r_(t),r=r_(i).map(rH),{kind:"table",children:[{kind:"thead",children:[{kind:"tr",children:a.map((e,t)=>{var n;let l;return n=r[t],l={kind:"th",children:rV(e.trim())},void 0!==n?{...l,align:n}:l;})}]},{kind:"tbody",children:s.map(e=>({kind:"tr",children:r_(e).map((e,t)=>{var n;let l;return n=r[t],l={kind:"td",children:rV(e.trim())},void 0!==n?{...l,align:n}:l;})}))}]};}(t,r)),1)||(rG(r).match?(n.push(rZ(t,!1)),!0):!!rJ(r).match&&(n.push(rZ(t,!0)),!0)))return;let i=function(e){let t=[];for(;e.i<e.lines.length;){var n;let l=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))||!!rG(e).match||!!rJ(e).match||rX(e);}(l))break;t.push(l),e.i++;}return 0===t.length?null:{kind:"paragraph",children:rV(t.join(" "))};}(t);null!==i&&n.push(i);}(a,l);return l;}(t,0),i={repositoryRoots:n,openRepositoryReference:l};return(0,r.jsx)("div",{className:"sm-root",children:a.map((e,t)=>r7(e,String(t),i))});}class it extends i.Component{static getDerivedStateFromError(){return{failed:!0};}render(){return this.state.failed?(0,r.jsx)("div",{className:"sm-root sm-fallback","data-markdown-fallback":"true",children:this.props.source}):(0,r.jsx)(ie,{source:this.props.source,repositoryRoots:this.props.repositoryRoots,openRepositoryReference:this.props.openRepositoryReference});}constructor(...e){super(...e),this.state={failed:!1};}}function il(e){var t;let{attachment:n,onRemove:l}=e,{t:a}=ea(),i=a("attachment.remove",{name:n.name}),s=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 l=e.slice(n);return`${e.slice(0,t-l.length-1)}…${l}`;}return`${e.slice(0,t-1)}…`;}(n.name);return(0,r.jsxs)("div",{className:"attach-chip",role:"listitem",children:["image"===n.kind&&void 0!==n.previewDataUrl?(0,r.jsx)("img",{src:n.previewDataUrl,alt:"",className:"attach-chip-thumb",width:40,height:40}):(0,r.jsx)("span",{className:"attach-chip-icon","aria-hidden":"true",children:(0,r.jsx)($.F.file,{size:16})}),(0,r.jsx)("span",{className:"attach-chip-name",title:n.name,children:s}),(0,r.jsx)("span",{className:"attach-chip-size",children:(t=n.sizeBytes)<1024?`${String(t)} B`:t<1048576?`${(t/1024).toFixed(1)} KB`:`${(t/1048576).toFixed(1)} MiB`}),(0,r.jsx)("button",{type:"button",className:"attach-chip-remove","aria-label":i,onClick:()=>l(n.id),children:(0,r.jsx)($.F.close,{size:12})})]});}function ia(e){let{attachments:t,onRemove:n}=e,{t:l}=ea();return 0===t.length?null:(0,r.jsx)("div",{className:"attach-strip",role:"list","aria-label":l("attachment.pending"),children:t.map(e=>(0,r.jsx)(il,{attachment:e,onRemove:n},e.id))});}function ir(e){let{enabled:t,onFiles:n}=e,{t:l}=ea(),[a,s]=(0,i.useState)(!1),[o,c]=(0,i.useState)(!1);(0,i.useEffect)(()=>{if(!t)return;let e=0,n=t=>{var n,l;Array.from(null!=(n=null==(l=t.dataTransfer)?void 0:l.types)?n:[]).includes("Files")&&(e+=1,c(!0));},l=()=>{0===(e=Math.max(0,e-1))&&c(!1);},a=()=>{e=0,c(!1);};return window.addEventListener("dragenter",n),window.addEventListener("dragleave",l),window.addEventListener("drop",a),window.addEventListener("dragend",a),()=>{window.removeEventListener("dragenter",n),window.removeEventListener("dragleave",l),window.removeEventListener("drop",a),window.removeEventListener("dragend",a);};},[t]);let d=(0,i.useCallback)(e=>{t&&(e.preventDefault(),s(!0));},[t]),u=(0,i.useCallback)(()=>{s(!1);},[]),p=(0,i.useCallback)(e=>{if(e.preventDefault(),s(!1),!t)return;let l=Array.from(e.dataTransfer.files);l.length>0&&n(l);},[t,n]);return t?(0,r.jsx)("div",{className:"attach-drop-zone","data-dragover":a?"true":void 0,"data-active":o?"true":"false","aria-hidden":"true",onDragOver:d,onDragLeave:u,onDrop:p,children:(0,r.jsx)("span",{className:"attach-drop-hint",children:l("attachment.drop")})}):null;}let ii="cmp-attach-disabled-hint";function is(e){let{model:t,onFiles:n,anyModelSupportsAttachments:l=!0}=e,{t:a}=ea(),s=(0,i.useRef)(null),o=void 0!==t&&(t.supportsImageInput||t.supportsDocumentInput),c=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),d=(0,i.useCallback)(()=>{var e;o&&(null==(e=s.current)||e.click());},[o]),u=(0,i.useCallback)(()=>{var e,t;let l=Array.from(null!=(e=null==(t=s.current)?void 0:t.files)?e:[]);l.length>0&&(n(l),null!==s.current&&(s.current.value=""));},[n]);return(0,r.jsxs)(r.Fragment,{children:[o?null:(0,r.jsx)("span",{id:ii,className:"sr-only",children:a(l?"attachment.disabledDifferentModel":"attachment.disabledNoModel")}),(0,r.jsx)("input",{ref:s,type:"file",multiple:!0,accept:c,className:"sr-only",tabIndex:-1,"aria-hidden":"true",onChange:u}),(0,r.jsx)("button",{type:"button",className:"cmp-icon cmp-tip-start","aria-label":a("attachment.attachFile"),"aria-disabled":o?void 0:"true","aria-describedby":o?void 0:ii,"data-tip":a(o?"attachment.attachFile":"attachment.notSupported"),onClick:d,children:(0,r.jsx)($.F.plus,{size:16})})]});}function io(e){let{reason:t,mimeType:n}=e,{t:l}=ea();return void 0===t?null:(0,r.jsx)("div",{role:"alert",className:"attach-rejection-alert",children:function(e,t,n){let l=null!=t?t:(e,t)=>{switch(e){case"attachment.rejection.textOnly":return"The selected model can't accept this attachment type. Choose a model that supports images or documents.";case"attachment.rejection.unsupported":var n;return`Unsupported file type${String(null!=(n=null==t?void 0:t.mime)?n:"")}. Supported types: images (image/*), PDF, plain text, markdown, JSON, YAML.`;case"attachment.rejection.oversized":return"File is larger than the 8 MiB limit. Choose a smaller file or summarize the content as text.";case"attachment.rejection.empty":return"Empty file. Add a file with content to attach.";default:return e;}},a=void 0!==n&&n.length>0?`: ${n}`:"";switch(e){case"text-only-model":return l("attachment.rejection.textOnly");case"unsupported-type":return l("attachment.rejection.unsupported",{mime:a});case"oversized":return l("attachment.rejection.oversized");case"empty":return l("attachment.rejection.empty");}}(t,l,n)});}function ic(e){let{documents:t}=e,{t:n}=ea();if(0===t.length)return null;let l=t.some(e=>e.truncated);return(0,r.jsxs)("div",{role:"note",className:"sent-docs-note","aria-label":n("attachment.docsContext"),children:[(0,r.jsx)("span",{className:"sent-docs-note-label",children:1===t.length?n("attachment.docContextLabel"):n("attachment.docsContextLabel")}),(0,r.jsx)("ul",{className:"sent-docs-note-list",children:t.map(e=>(0,r.jsxs)("li",{className:"sent-docs-note-item",children:[e.displayName,e.truncated?(0,r.jsx)("span",{className:"sent-docs-note-trunc",children:n("attachment.truncated")}):null]},e.id))}),l?(0,r.jsx)("span",{className:"sent-docs-note-hint",children:n("attachment.truncatedHint")}):null]});}function id(e){return"system"===e.role&&"string"==typeof e.runId;}function iu(e){var t,n,l;let{message:a,onOpenResult:s}=e,o=null!=(t=a.workflowStatus)?t:"queued",c=null!=(n=null!=(l=a.workflowId)?l:a.taskType)?n:"workflow",d=void 0===a.runId?"":a.runId.slice(0,8),u=void 0===a.runId?void 0:`/api/evidence/${encodeURIComponent(a.runId)}`,[p,m]=(0,i.useState)(""),h=(0,i.useRef)(o);return(0,i.useEffect)(()=>{h.current!==o&&(h.current=o,m(`Workflow ${c}: ${o}`));},[o,c]),(0,r.jsxs)("article",{className:"run-summary-card","data-testid":"run-summary-card","data-status":o,"aria-label":`Workflow run ${c} - ${o}`,children:[(0,r.jsxs)("header",{className:"run-summary-card-head",children:[(0,r.jsx)($.F.spark,{size:14,style:{color:"var(--accent)"}}),(0,r.jsx)("span",{className:"run-summary-card-workflow mono",children:c}),(0,r.jsx)("span",{className:"run-summary-card-status","data-status":o,children:o})]}),(0,r.jsxs)("div",{className:"run-summary-card-body",children:[(0,r.jsx)("p",{className:"run-summary-card-line",children:a.content}),void 0!==a.shortResult&&a.shortResult.length>0?(0,r.jsx)("p",{className:"run-summary-card-result",children:a.shortResult}):null,void 0!==a.runId?(0,r.jsxs)("p",{className:"run-summary-card-meta mono",children:["run"," ",(0,r.jsx)("span",{className:"run-summary-card-runshort","data-runid":a.runId,title:a.runId,children:d})]}):null,void 0!==a.runId?(0,r.jsxs)("div",{className:"run-summary-card-actions","aria-label":"Workflow result actions",children:[void 0!==s?(0,r.jsx)("button",{type:"button",className:"run-summary-card-action",onClick:()=>s(a),children:"Open result"}):null,void 0!==u?(0,r.jsx)("a",{className:"run-summary-card-action run-summary-card-action-secondary",href:u,target:"_blank",rel:"noreferrer",children:"Evidence"}):null]}):null]}),(0,r.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite","data-testid":"run-summary-card-sr",children:p})]});}async function ip(){return null!=l||(l=(0,m.z3)().then(e=>e.voice).catch(e=>{throw l=void 0,e;})),l;}class im extends Error{constructor(e,t){super(t),this.reason=e,this.name="DictationRecorderError";}}let ih=["audio/webm;codecs=opus","audio/webm","audio/ogg;codecs=opus","audio/ogg","audio/mp4"];function ig(){return"u">typeof navigator&&void 0!==navigator.mediaDevices&&"function"==typeof navigator.mediaDevices.getUserMedia&&"u">typeof MediaRecorder;}function iv(e){for(let t of e.getTracks())t.stop();}let ib={echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0,channelCount:1};async function iy(){try{return await navigator.mediaDevices.getUserMedia({audio:ib});}catch(e){if(e instanceof Error&&"OverconstrainedError"===e.name)return navigator.mediaDevices.getUserMedia({audio:!0});throw e;}}function ix(){return{async start(){var e;let t;if(!ig())throw new im("unsupported","This browser does not support microphone capture.");try{t=await iy();}catch(t){let e;throw new im("NotAllowedError"===(e=t instanceof Error?t.name:"")||"SecurityError"===e?"permission-denied":"NotFoundError"===e||"OverconstrainedError"===e||"DevicesNotFoundError"===e?"no-microphone":"capture-failed","Microphone access is unavailable.");}try{let n,l,a,r,i;return e=t,n=function(){for(let e of ih)if(MediaRecorder.isTypeSupported(e))return e;return"";}(),l=""===n?new MediaRecorder(e):new MediaRecorder(e,{mimeType:n}),a=[],l.addEventListener("dataavailable",e=>{e.data.size>0&&a.push(e.data);}),r=Date.now(),l.start(),i=!1,{stream:e,async stop(){if(i)throw new im("capture-failed","The recording is no longer active.");i=!0;let t=new Promise((e,t)=>{l.addEventListener("stop",()=>e(),{once:!0}),l.addEventListener("error",()=>t(new im("capture-failed","Audio capture failed.")),{once:!0});});l.stop();try{await t;}finally{iv(e);}let s=""!==l.mimeType?l.mimeType:n||"audio/webm",o=new Blob(a,{type:s});return{audioBase64:await new Promise((e,t)=>{let n=new FileReader();n.onerror=()=>{t(new im("capture-failed","The captured audio could not be read."));},n.onload=()=>{let l=n.result;if("string"!=typeof l)return void t(new im("capture-failed","The captured audio could not be read."));let a=l.indexOf(",");e(a>=0?l.slice(a+1):l);},n.readAsDataURL(o);}),mimeType:s,durationMs:Math.max(1,Date.now()-r)};},cancel(){i||(i=!0,"inactive"!==l.state&&l.stop(),iv(e));}};}catch(e){throw iv(t),new im("capture-failed",e instanceof Error?e.message:"Audio capture could not start.");}}};}let iw={phase:"idle",transcript:"",errorReason:void 0,errorMessage:void 0};function ij(e,t){switch(t.type){case"requesting":return{...iw,phase:"requesting"};case"recording":return{...iw,phase:"recording"};case"transcribing":return{...iw,phase:"transcribing"};case"preview":return{...iw,phase:"preview",transcript:t.transcript};case"editTranscript":return{...e,transcript:t.value};case"error":return{...iw,phase:"error",errorReason:t.reason,errorMessage:t.message};case"reset":return iw;}}function ik(e){return e instanceof im?{reason:e.reason,message:e.message}:e instanceof m.hD?{reason:"VOICE_UNAVAILABLE"===e.code?"unavailable":"transcribe-failed",message:e.message}:{reason:"capture-failed",message:"Dictation could not be completed."};}let iN="cmp-voice-privacy-hint",iS="cmp-voice-privacy-note",iC="Audio is sent only to your configured speech-to-text endpoint and is not stored.";function iR(e){let{phase:t,onStart:n,onStop:l,buttonRef:a,compact:i=!1}=e,s="recording"===t,o="requesting"===t||"transcribing"===t,c=function(e){switch(e){case"requesting":return"Starting microphone…";case"recording":return"Stop dictation";case"transcribing":return"Transcribing your dictation…";default:return"Dictate a message";}}(t);return(0,r.jsxs)("button",{type:"button",ref:a,className:`cmp-icon cmp-voice ui-tip${i?" cmp-mode-compact":""}`,"data-recording":s?"true":"false","data-tip":c,"aria-label":c,"aria-pressed":s,"aria-busy":o,"aria-describedby":iN,"aria-disabled":o,onClick:()=>{o||(s?l():n());},children:[s?(0,r.jsxs)("span",{className:"cmp-voice-recording","aria-hidden":"true",children:[(0,r.jsx)("span",{className:"cmp-voice-dot"}),(0,r.jsx)($.F.close,{size:14})]}):(0,r.jsx)($.F.mic,{size:16}),(0,r.jsx)("span",{id:iN,className:"sr-only",children:iC})]});}function iI(e){let{phase:t,transcript:n,error:l,onTranscriptChange:a,onInsert:s,onDiscard:o,onRetry:c}=e,d=(0,i.useRef)(null),u=(0,i.useRef)(null);return((0,i.useEffect)(()=>{var e,n;"preview"===t?null==(e=d.current)||e.focus():"error"===t&&(null==(n=u.current)||n.focus());},[t]),"transcribing"===t)?(0,r.jsxs)("div",{className:"cmp-voice-preview",role:"status","aria-live":"polite",children:[(0,r.jsx)("span",{className:"cmp-loading-dot","aria-hidden":"true"}),"Transcribing your dictation…"]}):"error"===t&&void 0!==l?(0,r.jsxs)("div",{className:"cmp-voice-preview cmp-voice-error",role:"alert","aria-atomic":"true",children:[(0,r.jsx)("p",{className:"cmp-voice-error-text",children:function(e){switch(e){case"permission-denied":return"Microphone access was denied. Allow microphone access in your browser to dictate.";case"no-microphone":return"No microphone was found. Connect a microphone and try again.";case"unsupported":return"This browser does not support microphone dictation.";case"unavailable":return"Speech-to-text dictation is not available right now.";case"transcribe-failed":case"capture-failed":return"Dictation could not be completed.";}}(l.reason)}),(0,r.jsxs)("div",{className:"cmp-voice-actions",children:[(0,r.jsx)("button",{type:"button",ref:u,className:"cmp-voice-btn",onClick:c,children:"Try again"}),(0,r.jsx)("button",{type:"button",className:"cmp-voice-btn",onClick:o,children:"Dismiss"})]})]}):"preview"!==t?null:(0,r.jsxs)("div",{className:"cmp-voice-preview",role:"group","aria-label":"Dictation transcript preview",children:[(0,r.jsx)("span",{role:"status","aria-live":"polite",className:"sr-only",children:"Transcript ready for review."}),(0,r.jsx)("label",{className:"cmp-voice-label",htmlFor:"cmp-voice-transcript",children:"Review your dictation"}),(0,r.jsx)("textarea",{id:"cmp-voice-transcript",ref:d,className:"cmp-voice-transcript",rows:3,value:n,"aria-describedby":iS,onChange:e=>a(e.target.value)}),(0,r.jsx)("p",{id:iS,className:"cmp-voice-privacy",children:iC}),(0,r.jsxs)("div",{className:"cmp-voice-actions",children:[(0,r.jsx)("button",{type:"button",className:"cmp-voice-btn cmp-voice-btn-primary","aria-label":"Insert transcript into the message",disabled:0===n.trim().length,onClick:s,children:"Insert"}),(0,r.jsx)("button",{type:"button",className:"cmp-voice-btn","aria-label":"Re-record the dictation",onClick:c,children:"Re-record"}),(0,r.jsx)("button",{type:"button",className:"cmp-voice-btn","aria-label":"Discard the dictation",onClick:o,children:"Discard"})]})]});}function iE(e){let{controller:t,onAfterDiscard:n}=e;return(0,r.jsx)(iI,{phase:t.phase,transcript:t.transcript,error:t.error,onTranscriptChange:t.setTranscript,onInsert:t.insert,onRetry:t.retry,onDiscard:()=>{t.discard(),n();}});}let i$=["client-to-host","host-to-client"],iA=["session.create","session.created","session.close","session.closed","capability.offer","capability.select","signal.sdp.offer","signal.sdp.answer","signal.ice.candidate","media.track.state","control.cancel","control.interrupt","transcript.partial","transcript.committed","transcript.discarded","playback.state","policy.decision","error"],iT={none:[],"speech-to-text":["session.create","session.created","session.close","session.closed","capability.offer","capability.select","control.cancel","transcript.partial","transcript.committed","transcript.discarded","policy.decision","error"],"speech-output":["session.create","session.created","session.close","session.closed","capability.offer","capability.select","control.cancel","control.interrupt","playback.state","policy.decision","error"],"full-realtime":[...iA]};function iF(e,t){return iT[t].includes(e);}let iD=["preparing","speaking","paused"],iM=["interrupted","canceled","failed","complete"];function iP(e){return iD.includes(e);}function iL(e){return iM.includes(e);}function iq(e){switch(e){case"unavailable":return;case"preparing":case"complete":return"idle";case"speaking":return"playing";case"paused":return"paused";case"interrupted":return"interrupted";case"canceled":case"failed":return"stopped";default:throw Error(`unhandled voice playback phase: ${JSON.stringify(e)}`);}}function iz(){return{now:()=>performance.now()};}let iO={prepare:e=>e.playbackAllowed,"play-started":e=>e.playbackAllowed,pause:e=>e.playbackAllowed,resume:e=>e.playbackAllowed,interrupt:e=>e.interruptAllowed,stop:e=>e.playbackAllowed,fail:e=>e.playbackAllowed,complete:e=>e.playbackAllowed,replay:e=>e.playbackAllowed&&e.replayAllowed,"set-muted":e=>e.playbackAllowed};function iB(e){return{phase:"unavailable",muted:!1,spoke:!1,interruptions:0,replays:0,failureKind:void 0,lastInterruptAtMs:void 0,lastTransitionAtMs:void 0};}function iW(e){return(t,n)=>(0,m.Je)(void 0===e?{text:t}:{text:t,persona:e},n);}function iK(){return new Audio();}function iU(e){return URL.createObjectURL(e);}function iV(e){URL.revokeObjectURL(e);}function iH(e){return e instanceof DOMException&&"AbortError"===e.name;}let i_="cmp-voice-playback-privacy-hint";function iG(e){let{muted:t}=e;return(0,r.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",children:[(0,r.jsx)("path",{d:"M4 9v6h4l5 4V5L8 9H4z",fill:"currentColor",stroke:"currentColor",strokeWidth:1.5,strokeLinejoin:"round"}),t?(0,r.jsx)("path",{d:"M16 9l5 6M21 9l-5 6",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round"}):(0,r.jsx)("path",{d:"M16 9.5a3.5 3.5 0 010 5M18.5 7a7 7 0 010 10",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round"})]});}function iJ(e){let{muted:t,onToggle:n,buttonRef:l,compact:a=!1}=e,i=t?"Unmute assistant voice":"Mute assistant voice";return(0,r.jsxs)("button",{type:"button",ref:l,className:`cmp-icon cmp-voice ui-tip${a?" cmp-mode-compact":""}`,"data-muted":t?"true":"false","data-tip":i,"aria-label":i,"aria-pressed":t,"aria-describedby":i_,onClick:n,children:[(0,r.jsx)(iG,{muted:t}),(0,r.jsx)("span",{id:i_,className:"sr-only",children:"Assistant speech is optional. The full response is always available as text in the conversation."})]});}var iY=n(74883);class iX extends Error{constructor(e,t){super(t),this.reason=e,this.name="VoiceRtcError";}}function iZ(){return"u">typeof navigator&&void 0!==navigator.mediaDevices&&"function"==typeof navigator.mediaDevices.getUserMedia&&"u">typeof RTCPeerConnection;}function iQ(e){for(let t of e.getTracks())t.stop();}let i0={echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0,channelCount:1};async function i1(){try{return await navigator.mediaDevices.getUserMedia({audio:i0});}catch(e){if(e instanceof Error&&"OverconstrainedError"===e.name)return navigator.mediaDevices.getUserMedia({audio:!0});throw e;}}function i2(){return{async connect(){let e,t,n;if(!iZ())throw new iX("unsupported","This browser does not support real-time voice.");try{e=await i1();}catch(t){let e;throw new iX("NotAllowedError"===(e=t instanceof Error?t.name:"")||"SecurityError"===e?"permission-denied":"NotFoundError"===e||"OverconstrainedError"===e||"DevicesNotFoundError"===e?"no-microphone":"connection-failed","Microphone access is unavailable.");}try{for(let n of(t=new RTCPeerConnection(),e.getTracks()))t.addTrack(n,e);n=t.createDataChannel("oai-events");let l=await t.createOffer();return await t.setLocalDescription(l),await new Promise(e=>{let n;if("complete"===t.iceGatheringState)return void e();let l=()=>{"complete"===t.iceGatheringState&&(void 0!==n&&clearTimeout(n),t.removeEventListener("icegatheringstatechange",l),e());};n=setTimeout(()=>{t.removeEventListener("icegatheringstatechange",l),e();},2e3),t.addEventListener("icegatheringstatechange",l);}),function(e,t,n){let l,a,r,i,s=e.localDescription;if(null===s)throw new iX("connection-failed","Local SDP description is unavailable.");let o=s.sdp;e.ontrack=e=>{let t=e.streams[0];void 0!==l&&void 0!==t&&l(t);},e.onconnectionstatechange=()=>{void 0!==a&&a(e.connectionState);};let c=()=>{void 0!==i&&i(n.readyState);};return n.addEventListener("open",c),n.addEventListener("closing",c),n.addEventListener("close",c),n.addEventListener("error",c),n.addEventListener("message",e=>{if(void 0===r)return;let t="string"==typeof e.data?e.data:String(e.data);try{r(JSON.parse(t));}catch{r(t);}}),{offerSdp:o,async applyAnswer(t){await e.setRemoteDescription({type:"answer",sdp:t});},setInputMuted(e){for(let n of"function"==typeof t.getAudioTracks?t.getAudioTracks():t.getTracks())n.enabled=!e;},onRemoteTrack(e){l=e;},onConnectionStateChange(e){a=e;},onDataChannelEvent(e){r=e;},onDataChannelStateChange(e){i=e;},sendDataChannelEvent:e=>"open"===n.readyState&&(n.send(JSON.stringify(e)),!0),close(){iQ(t);try{n.close();}catch{}e.close();}};}(t,e,n);}catch(t){if(iQ(e),t instanceof iX)throw t;throw new iX("connection-failed",t instanceof Error?t.message:"WebRTC connection could not start.");}}};}let i4={offered:!1,capture:"none",speaks:!1,canInterrupt:!1},i3="keiko.voice.dialog.persona",i6="keiko:voice-dialog-persona",i5=new Set(iY.RX);function i8(e){if(0===e.length)return;let t=null;try{t=window.localStorage.getItem(i3);}catch{t=null;}return null!==t&&i5.has(t)&&e.includes(t)?t:e[0];}function i9(e){try{window.localStorage.setItem(i3,e),window.dispatchEvent(new CustomEvent(i6,{detail:e}));}catch{}}class i7 extends Error{constructor(e,t){super(t),this.reason=e,this.name="VoiceControlError";}}function se(e){return"object"==typeof e&&null!==e&&!Array.isArray(e);}function st(e,t){let n=e[t];return"string"==typeof n&&n.length>0?n:void 0;}function sn(e){let t=st(e,"response_id");if(void 0!==t)return t;let n=e.response;return se(n)?st(n,"id"):void 0;}function sl(e){let t=st(e,"item_id");if(void 0!==t)return t;let n=e.item;return se(n)?st(n,"id"):void 0;}function sa(e){let t=st(e,"call_id");if(void 0!==t)return t;let n=e.item;if(se(n)){let e=st(n,"call_id");if(void 0!==e)return e;}return sl(e);}function sr(e,t){var n,l;if(!se(e)||"function_call"!==e.type)return;let a=null!=(n=st(e,"call_id"))?n:sa(t),r=st(e,"name");if(void 0!==a&&void 0!==r)return{callId:a,name:r,argumentsText:function(e){if("string"==typeof e)return e;if(null==e)return"";try{return JSON.stringify(e);}catch{return"";}}(e.arguments),itemId:null!=(l=st(e,"id"))?l:sl(t)};}let si={disabled:"none",idle:"none",listening:"user",thinking:"assistant",speaking:"assistant",interrupted:"none",yielding:"none",recovering:"none"},ss={"user-speech-start":e=>e.canCaptureUserVoice,"user-end-of-turn":e=>e.canCaptureUserVoice,"dictation-commit":e=>e.usesManualCommit,"dictation-discard":e=>e.usesManualCommit,"assistant-speech-start":e=>e.playbackAllowed,"assistant-speech-end":e=>e.playbackAllowed,"user-interrupt":e=>e.interruptAllowed,backchannel:e=>e.floorControl&&e.playbackAllowed,"provider-failure":()=>!0,"permission-denied":()=>!0,recovered:()=>!0,"session-closed":()=>!0};function so(e){return{state:"none"===e?"disabled":"idle",turnIndex:0,interruptions:0,backchannels:0,pendingCommit:!1,lastEndOfTurnAtMs:void 0,lastInterruptAtMs:void 0,lastTransitionAtMs:void 0};}function sc(){let e="u">typeof Audio?new Audio():void 0;return void 0!==e&&(e.autoplay=!0),{attach(t){var n;void 0!==e&&(e.srcObject=t,null==(n=e.play)||n.call(e).catch(()=>{}));},setMuted(t){void 0!==e&&(e.muted=t);},release(){if(void 0!==e){try{var t;null==(t=e.pause)||t.call(e);}catch{}e.srcObject=null;}}};}let sd={phase:"idle",errorReason:void 0,errorMessage:void 0};function su(e,t){switch(t.type){case"requesting":return{...sd,phase:"requesting"};case"negotiating":return{...sd,phase:"negotiating"};case"connected":return{...sd,phase:"connected"};case"error":return{...sd,phase:"error",errorReason:t.reason,errorMessage:t.message};case"reset":return sd;}}function sp(e){var t;return null!=(t=e.itemId)?t:e.responseId;}let sm={idle:"Voice dialogue is ready.",connecting:"Connecting the voice dialogue…",listening:"Listening to you.",thinking:"The assistant is thinking.",speaking:"The assistant is speaking.",muted:"The assistant is speaking. Playback is muted.",interrupted:"Voice dialogue interrupted.",error:"Voice dialogue could not continue. You can keep chatting in text."},sh={male:"Male voice",female:"Female voice",neutral:"Neutral voice"};function sf(){return(0,r.jsx)("img",{src:"/assets/keiko-logo.svg",alt:"",width:34,height:34,"aria-hidden":"true",decoding:"async"});}let sg="Voice dialogue mode";function sv(e){let{active:t,onToggle:n,disabled:l=!1,compact:a=!1,buttonRef:i}=e;return(0,r.jsx)("button",{type:"button",ref:i,role:"switch","aria-checked":t,"aria-label":sg,"data-tip":sg,"data-active":t?"true":"false",disabled:l,className:`cmp-icon cmp-voice cmp-voice-dialog-logo ui-tip${a?" cmp-mode-compact":""}`,onClick:n,children:(0,r.jsx)(sf,{})});}var sb=n(29464);let sy="cmp-no-model-alert",sx="cmp-send-hint",sw="cmp-loading-status";function sj(e){let t=new Date(e),n=t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});return t.toDateString()===new Date().toDateString()?n:`${t.toLocaleDateString([],{month:"short",day:"numeric"})}, ${n}`;}let sk=/\s*[[【[]\d+[\]】]]/g;async function sN(e){var t;let n="u"<typeof navigator||null==(t=navigator.clipboard)?void 0:t.writeText;if(void 0!==n&&void 0!==navigator.clipboard)try{await n.call(navigator.clipboard,e);return;}catch{}if("u"<typeof document||null===document.body)throw Error("clipboard-unavailable");let l=document.activeElement instanceof HTMLElement?document.activeElement:null,a=document.createElement("textarea");a.value=e,a.setAttribute("readonly","true"),a.style.position="fixed",a.style.inset="0 auto auto -9999px",a.style.width="1px",a.style.height="1px",a.style.opacity="0",document.body.appendChild(a);try{if(a.focus(),a.select(),!("function"==typeof document.execCommand&&document.execCommand("copy")))throw Error("clipboard-fallback-failed");}finally{a.remove(),null==l||l.focus();}}function sS(e){let{content:t}=e,{t:n}=ea(),[l,a]=(0,i.useState)("idle"),[s,o]=(0,i.useState)(""),c=(0,i.useCallback)(()=>{sN(rt(t).replace(sk,"")).then(()=>{a("copied"),o(n("chat.copy.copiedStatus")),setTimeout(()=>{a("idle"),o("");},1500);},()=>{a("failed"),o(n("chat.copy.failedStatus"));});},[t,n]),d="copied"===l;return(0,r.jsxs)("div",{className:"chat-msg-copy-wrap",children:[(0,r.jsx)("button",{type:"button",className:"chat-msg-copy","aria-label":d?n("chat.copy.copied"):n("chat.copy.message"),title:d?n("chat.copy.copied"):n("chat.copy.message"),"data-copied":d?"true":"false","data-failed":"failed"===l?"true":"false",onClick:c,children:(0,r.jsx)($.F.copy,{size:20,"aria-hidden":"true"})}),(0,r.jsx)("span",{role:"status",className:"chat-msg-copy-status",children:s})]});}let sC=(0,i.memo)(function(e){var t;let{message:n,onOpenRunResult:l,repositoryRoots:a,openRepositoryReference:s,streaming:o=!1,layout:c="stack"}=e,{t:d}=ea(),u=(0,i.useId)(),[p,m]=(0,i.useState)(!1),h=id(n),f="user"===n.role,g=!f&&!h&&((t=n.content).length>=1800||t.split(/\r\n|\r|\n/u).length>=32);return h?(0,r.jsx)(iu,{message:n,onOpenResult:l}):(0,r.jsx)("article",{className:"chat-msg","data-role":n.role,"data-layout":c,children:(0,r.jsxs)("div",{className:"chat-msg-bubble",children:[f?(0,r.jsx)("div",{className:"chat-msg-role",children:d("chat.role.user")}):(0,r.jsx)(sR,{}),(0,r.jsxs)("div",{id:f?void 0:u,className:"chat-msg-content","data-collapsed":!f&&p?"true":"false","data-collapsible":g?"true":"false",children:[f?n.content:(0,r.jsx)(it,{source:n.content,repositoryRoots:a,openRepositoryReference:s}),o&&!f?(0,r.jsx)("span",{className:"ai-stream-cursor","aria-hidden":"true"}):null]}),(0,r.jsxs)("div",{className:"chat-msg-foot",children:[(0,r.jsx)("div",{className:"chat-msg-time",title:new Date(n.timestamp).toLocaleString(),children:sj(n.timestamp)}),f?null:(0,r.jsxs)("div",{className:"chat-msg-actions",children:[(0,r.jsx)(sS,{content:n.content}),g?(0,r.jsxs)("button",{type:"button",className:"chat-msg-collapse","aria-controls":u,"aria-expanded":!p,onClick:()=>{m(e=>!e);},children:[(0,r.jsx)($.F.chevron,{size:12,"aria-hidden":"true"}),(0,r.jsx)("span",{children:d(p?"chat.answer.expand":"chat.answer.collapse")})]}):null]})]}),f||void 0===n.groundedAnswer?null:(0,r.jsxs)("div",{className:"chatw-grounded chatw-grounded-inline",children:[(0,r.jsx)(rD,{answer:n.groundedAnswer,busy:!1,repositoryRoots:a,openRepositoryReference:s}),(0,r.jsx)(rL,{contextSummary:function(e){if(void 0!==e){if("connected-context"===e.groundingKind)return e.contextPack.contextSummary;if("hybrid"===e.groundingKind)return e.contextPack.folder.contextSummary;}}(n.groundedAnswer)})]})]})});});function sR(e){let{pulsing:t=!1}=e,{t:n}=ea();return(0,r.jsx)("div",{className:"chat-msg-brand","data-pulsing":t?"true":"false",role:"img","aria-label":n("chat.keikoLogo"),children:(0,r.jsx)(aY.default,{src:"/assets/keiko-logo.svg",width:22,height:22,alt:"","aria-hidden":"true"})});}function sI(){let{t:e}=ea();return(0,r.jsx)("article",{className:"chat-msg","data-role":"assistant",children:(0,r.jsxs)("div",{className:"chat-msg-bubble",children:[(0,r.jsx)(sR,{pulsing:!0}),(0,r.jsxs)("span",{className:"chat-typing",role:"img","aria-label":e("chat.keikoResponding"),children:[(0,r.jsx)("i",{}),(0,r.jsx)("i",{}),(0,r.jsx)("i",{})]})]})});}function sE(e,t,n){let l=Math.max(0,Math.min(1,t));e.style.setProperty("--wave-width",`${(8+16*l).toFixed(1)}px`),e.dataset.peak=n?"true":"false";}function s$(e){let{items:t,onJump:n}=e,{t:l}=ea(),a=(0,i.useRef)(new Map()),s=(0,i.useCallback)(e=>{let t,n=Array.from(a.current.values());if(0===n.length)return;let l=1/0;for(let a of n){let n=a.getBoundingClientRect(),r=Math.abs(e-(n.top+n.height/2));r<l&&(l=r,t=a),sE(a,Math.exp(-(r*r)/1058),!1);}void 0!==t&&sE(t,1,!0);},[]),o=(0,i.useCallback)(()=>{for(let e of a.current.values())sE(e,0,!1);},[]),c=(0,i.useCallback)((e,t)=>{null===t?a.current.delete(e):a.current.set(e,t);},[]);return t.length<2?null:(0,r.jsx)("nav",{className:"chat-question-map","aria-label":l("chat.questionMap.label"),onPointerMove:e=>s(e.clientY),onPointerLeave:o,children:(0,r.jsx)("ol",{className:"chat-question-map-list",children:t.map(e=>(0,r.jsx)("li",{className:"chat-question-map-item",children:(0,r.jsxs)("button",{ref:t=>c(e.id,t),type:"button",className:"chat-question-map-button","data-peak":"false",style:{"--wave-width":"8px"},"aria-label":l("chat.questionMap.jump",{index:e.index,preview:e.preview}),onFocus:e=>{let t=e.currentTarget.getBoundingClientRect();s(t.top+t.height/2);},onBlur:o,onClick:()=>n(e.id),children:[(0,r.jsx)("span",{className:"chat-question-map-mark","aria-hidden":"true"}),(0,r.jsxs)("span",{className:"chat-question-map-card","aria-hidden":"true",children:[(0,r.jsx)("span",{className:"chat-question-map-card-title",children:e.preview}),(0,r.jsx)("span",{className:"chat-question-map-card-time",children:e.time})]})]})},e.id))})});}let sA=(0,i.memo)(function(e){let{messages:t,onOpenRunResult:n,repositoryRoots:l,openRepositoryReference:a,sending:s,sendStatus:o,activeChat:c,onCancelGrounded:d,registerQuestionAnchor:u}=e,{t:p}=ea(),m=(0,i.useMemo)(()=>function(e){let t=[],n=null;for(let l of e){if("user"===l.role){n={id:l.id,user:l,responses:[]},t.push(n);continue;}null===n&&(n={id:l.id,user:null,responses:[]},t.push(n)),n.responses.push(l);}return t;}(t),[t]);return(0,r.jsxs)("div",{className:"chatw-thread",children:[m.map(e=>{let t=e.user;return(0,r.jsxs)("div",{className:"chat-turn",children:[(0,r.jsx)("div",{className:"chat-turn-cell chat-turn-prompt","data-chat-question-id":null==t?void 0:t.id,ref:null!==t&&void 0!==u?e=>u(t.id,e):void 0,children:null!==t?(0,r.jsx)(sC,{message:t,onOpenRunResult:n,repositoryRoots:l,openRepositoryReference:a,layout:"turn"}):null}),(0,r.jsx)("div",{className:"chat-turn-cell chat-turn-answer",children:e.responses.map((t,i)=>(0,r.jsx)(sC,{message:t,onOpenRunResult:n,repositoryRoots:l,openRepositoryReference:a,layout:"turn",streaming:"streaming"===o&&"assistant"===t.role&&e===m[m.length-1]&&i===e.responses.length-1},t.id))})]},e.id);}),s&&"streaming"!==o?(0,r.jsxs)("div",{className:"chat-turn chat-turn-pending",children:[(0,r.jsx)("div",{className:"chat-turn-cell chat-turn-prompt"}),(0,r.jsx)("div",{className:"chat-turn-cell chat-turn-answer",children:(0,r.jsxs)("div",{className:"chatw-typing-row",children:[(0,r.jsx)(sI,{}),s3(c)?(0,r.jsx)("button",{type:"button",className:"grounded-cancel-btn","aria-label":p("chat.grounded.cancel"),onClick:d,children:p("common.cancel")}):null]})})]}):null]});});function sT(e){return void 0!==e.connectedScopes?e.connectedScopes:void 0!==e.connectedScope?[e.connectedScope]:[];}function sF(e){var t;let n=e.replace(/\\/gu,"/").replace(/\/+$/u,"").split("/").filter(e=>e.length>0);return null!=(t=n[n.length-1])?t:e;}function sD(e,t){if(void 0===e)return[];let n=null!=t?t:e.projectPath,l=new Set(),a=[];for(let t of sT(e)){var r;let e=null!=(r=t.root)?r:n;0===e.length||l.has(e)||(l.add(e),a.push({root:e,label:sF(e)}));}return a;}function sM(e){return e.replace(/\\/gu,"/").replace(/\/+$/u,"");}function sP(e){return e.replace(/\\/gu,"/").replace(/^\/+/u,"").replace(/\/+$/u,"");}function sL(e,t){return`${e}\u0001${t}`;}function sq(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"picker";return{id:sL(e.root,e.path),root:e.root,path:e.path,name:e.name,directory:e.directory,verified:!0,source:t};}let sz=/(^|\s)@((?:[A-Za-z0-9_.-]+\/)*[A-Za-z0-9_.-]+\.[A-Za-z0-9][A-Za-z0-9]{0,15})(?=$|\s)/gu;function sO(e,t){var n;let l=Math.max(0,Math.min(t,e.length)),a=e.slice(0,l),r=a.lastIndexOf("@");if(r<0)return null;let i=0===r?"":null!=(n=a[r-1])?n:"";if(i.length>0&&!/\s|[(\[{]/u.test(i))return null;let s=a.slice(r+1);return s.includes("@")||/\s/u.test(s)?null:{start:r,end:l,query:s};}function sB(e){switch(e){case"source":return"Source";case"test":return"Test";case"config":return"Config";case"docs":return"Docs";case"generated":return"Generated";case"asset":return"Asset";case"other":case void 0:return"File";}}function sW(e){return lJ(e,"Unable to reference repository file.");}function sK(e){var t,n;let{roots:l,selectedRoot:a,onRootChange:i,search:s,pickingPath:o,highlightedIndex:c,pickError:d,onPick:u,onClose:p}=e,m=null!=(t=l.find(e=>e.root===a))?t:l[0],h=null!=d?d:s.error,f=e=>{e.stopPropagation();};return(0,r.jsxs)("div",{className:"repo-focus-popover",role:"dialog","aria-label":"Reference repository file",onPointerDown:f,onMouseDown:f,children:[(0,r.jsxs)("div",{className:"repo-focus-head",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("span",{className:"repo-focus-title",children:"Repository file"}),(0,r.jsx)("span",{className:"repo-focus-subtitle",children:null!=(n=null==m?void 0:m.label)?n:"Connected source"})]}),(0,r.jsx)("button",{type:"button",className:"repo-focus-close","aria-label":"Close repository file picker",onClick:p,children:(0,r.jsx)($.F.close,{size:13})})]}),l.length>1?(0,r.jsx)(ln.A,{triggerClassName:"repo-focus-source-select",value:a,ariaLabel:"Repository source",menuTitle:"Connected repositories",menuClassName:"repo-focus-source-menu",menuMinWidth:240,sections:[{options:l.map(e=>({value:e.root,label:e.label}))}],onValueChange:i}):null,(0,r.jsx)("div",{className:"repo-focus-message",role:null===h?"status":"alert",children:null!=h?h:s.searching?"Searching repository files...":s.message}),s.results.length>0?(0,r.jsx)("div",{className:"repo-focus-results",role:"listbox","aria-label":"Repository file results",children:s.results.map((e,t)=>{var n;let l;return(0,r.jsxs)("button",{type:"button",className:(l="generated"===e.fileRole||"asset"===e.fileRole,`repo-focus-result${l?" repo-focus-result-secondary":""}`),role:"option","aria-selected":t===c?"true":"false","data-highlighted":t===c?"true":"false","aria-label":`Reference ${e.path}`,disabled:null!==o,onPointerDown:t=>{0===t.button&&null===o&&(t.preventDefault(),t.stopPropagation(),u(e));},onClick:t=>{t.stopPropagation(),0===t.detail&&null===o&&u(e);},children:[(0,r.jsxs)("span",{className:"repo-focus-result-main",children:[(0,r.jsx)("span",{className:"repo-focus-result-name",children:e.name}),(0,r.jsxs)("span",{className:"repo-focus-result-badges","aria-hidden":"true",children:[(0,r.jsx)("span",{className:(n=e.fileRole,`repo-focus-badge repo-focus-badge-${null!=n?n:"other"}`),children:sB(e.fileRole)}),"nested-git-root"===e.rootKind?(0,r.jsx)("span",{className:"repo-focus-badge repo-focus-badge-root",children:"Nested repo"}):null]})]}),(0,r.jsx)("span",{className:"repo-focus-result-path",children:0===e.directory.length?"Repository root":e.directory}),(0,r.jsx)("span",{className:"sr-only",children:`${sB(e.fileRole)}; ${function(e){switch(e){case"exact":return"Exact match";case"strong":return"Strong match";case"path":return"Path match";case"weak":case void 0:return"Weak match";}}(e.matchQuality)}${"nested-git-root"===e.rootKind?"; nested repository root":""}.`})]},`${e.root}:${e.path}`);})}):null]});}function sU(e){let{references:t,onRemove:n}=e;return 0===t.length?null:(0,r.jsx)("div",{className:"repo-token-strip",role:"list","aria-label":"Referenced repository files",children:t.map(e=>(0,r.jsxs)("div",{className:`repo-token${e.verified?"":" repo-token-unverified"}`,role:"listitem",title:e.verified?`${e.path} — ${e.root}`:`Reference not verified yet — ${e.path} — ${e.root}`,children:[(0,r.jsx)("span",{className:"repo-token-icon","aria-hidden":"true",children:(0,r.jsx)(a0.o,{name:e.name})}),(0,r.jsxs)("span",{className:"repo-token-main",children:[(0,r.jsx)("span",{className:"repo-token-name",children:e.name}),(0,r.jsx)("span",{className:"repo-token-path",children:0===e.directory.length?sF(e.root):e.directory})]}),e.verified?null:(0,r.jsx)("span",{className:"repo-token-status","aria-label":"Reference not verified yet",children:"Unverified"}),(0,r.jsx)("button",{type:"button",className:"repo-token-remove","aria-label":`Remove repository reference ${e.path}`,onClick:()=>n(e.id),children:(0,r.jsx)($.F.close,{size:12})})]},e.id))});}function sV(e){let{muted:t,onToggle:n,buttonRef:l,compact:a=!1}=e,s=(0,i.useId)(),o=t?"Unmute voice dialogue microphone":"Mute voice dialogue microphone";return(0,r.jsxs)("button",{type:"button",ref:l,className:`cmp-icon cmp-voice cmp-voice-dialog-mute ui-tip${a?" cmp-mode-compact":""}`,"data-muted":t?"true":"false","data-tip":o,"aria-label":o,"aria-pressed":t,"aria-describedby":s,onClick:n,children:[(0,r.jsxs)("span",{className:"cmp-voice-dialog-mic-glyph","aria-hidden":"true",children:[(0,r.jsx)($.F.mic,{size:16}),t?(0,r.jsx)("span",{className:"cmp-voice-dialog-mic-slash"}):null]}),(0,r.jsx)("span",{id:s,className:"sr-only",children:"When muted, Keiko cannot hear your microphone until you unmute."})]});}function sH(e){let{voiceMuted:t,onToggleVoiceMute:n,playbackButtonRef:l,voiceDialogActive:a,onToggleVoiceDialog:i,voiceDialogButtonRef:s,compact:o=!1}=e;return(0,r.jsx)("div",{className:"cmp-bar cmp-bar-voice-dialog",children:(0,r.jsxs)("div",{className:"cmp-bar-main cmp-bar-main-voice-dialog",children:[(0,r.jsx)(sv,{active:a,onToggle:i,buttonRef:s,compact:o}),(0,r.jsx)(sV,{muted:t,onToggle:n,buttonRef:l,compact:o})]})});}function s_(e){let{session:t,ready:n,selectedModelCapability:l,onAttachFiles:a,controlsNarrow:i=!1,barCompact:s=!1,voiceDictationVisible:o,dictation:c,micButtonRef:d,voiceSpeechOutputVisible:u,voiceMuted:p,onToggleVoiceMute:m,playbackButtonRef:h,voiceDialogAvailable:f,voiceDialogActive:g,onToggleVoiceDialog:v,voiceDialogButtonRef:b}=e,{t:y}=ea(),{models:x,selectedModel:w,setSelectedModel:j,draft:k,noEligibleModels:N,loading:S,sending:C,cancelSend:R}=t,I=N||!n,E=0===k.trim().length,A=N?sy:void 0,T=N?sy:S?sw:E?sx:void 0,F=S||N?"":null!=w?w:"",D=y(S?"chat.model.loading":N?"chat.model.noEligible":"chat.model.change");return(0,r.jsxs)("div",{className:`cmp-bar${s?" cmp-bar-compact":""}`,children:[(0,r.jsxs)("div",{className:"cmp-bar-model",children:[(0,r.jsx)(is,{model:l,onFiles:a,anyModelSupportsAttachments:x.some(e=>e.supportsImageInput||e.supportsDocumentInput)}),(0,r.jsx)("div",{className:`cmp-model mono ui-tip${i?" cmp-model-compact":" cmp-pill-standard"}`,"data-tip":i?D:void 0,children:(0,r.jsx)(ln.A,{triggerClassName:"cmp-model-select",value:F,ariaLabel:y("chat.model.menuTitle"),ariaDescribedBy:A,disabled:S,placeholder:y(S?"chat.model.loading":N?"chat.model.noEligible":"chat.model.menuTitle"),leadingVisual:(0,r.jsx)($.F.cube,{size:i?16:13,style:{color:"var(--accent)"}}),menuTitle:y("chat.model.menuTitle"),menuClassName:"cmp-model-menu",menuMinWidth:i?118:280,mono:!0,sections:[{options:S?[{value:"",label:y("chat.model.loading"),disabled:!0}]:N?[{value:"",label:y("chat.model.noEligible"),disabled:!0}]:x.filter(e=>"chat"===e.kind).map(e=>({value:e.id,label:e.id}))}],onValueChange:e=>{N||S||j(e);}})})]}),(0,r.jsxs)("div",{className:"cmp-bar-main",children:[o?(0,r.jsx)(iR,{phase:c.phase,onStart:c.start,onStop:c.stop,buttonRef:d,compact:i}):null,f?(0,r.jsx)(sv,{active:g,onToggle:v,buttonRef:b,compact:i}):null,u?(0,r.jsx)(iJ,{muted:p,onToggle:m,buttonRef:h,compact:i}):null,C?(0,r.jsx)("button",{type:"button",className:"cmp-send cmp-send-cancel cmp-tip-end","data-on":!0,"aria-label":y("chat.send.cancel"),"data-tip":y("chat.send.cancel"),onClick:R,children:(0,r.jsx)($.F.close,{size:16})}):(0,r.jsx)("button",{type:I?"button":"submit",className:"cmp-send cmp-tip-end","data-on":!I,"data-tip":y(N?"chat.send.noModel":S?"chat.send.connecting":"chat.send.label"),"aria-disabled":I,"aria-describedby":T,"aria-label":y("chat.send.label"),children:(0,r.jsx)($.F.arrowUp,{size:16})})]}),T===sx?(0,r.jsx)("span",{id:sx,className:"sr-only",children:y("chat.send.hint")}):null]});}function sG(){let{t:e}=ea();return(0,r.jsx)("div",{id:sy,role:"alert",className:"gw-error cmp-no-model",children:e("chat.noModelAlert")});}function sJ(){let{t:e}=ea();return(0,r.jsxs)("div",{id:sw,role:"status",className:"cmp-loading-status",children:[(0,r.jsx)("span",{className:"cmp-loading-dot","aria-hidden":"true"}),e("chat.loadingGateway")]});}function sY(e){let{status:t}=e,{t:n}=ea(),l="queued"===t?n("chat.send.statusQueued"):"contacting"===t?n("chat.send.statusContacting"):"streaming"===t?n("chat.send.statusStreaming"):"cancelled"===t?n("chat.send.statusCancelled"):"";return(0,r.jsx)("div",{role:"status","aria-live":"polite","data-send-status":t,className:"cmp-send-status",children:0===l.length?null:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"cmp-loading-dot","aria-hidden":"true"}),l]})});}function sX(e){var t,n,l,a,s;let{session:o,ready:c,placeholder:d,minimal:u=!1,compact:p=!1,controlsNarrow:h=!1,barCompact:f=!1}=e,{t:g}=ea(),{draft:v,loading:b,sending:y,sendStatus:x,setDraft:w,sendMessage:j,models:k,selectedModel:N,pendingAttachments:S,addPendingAttachment:C,removePendingAttachment:R,error:I,messages:E,activeChat:$,activeProject:A,replaceChat:T}=o,F=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=F.current;null!==e&&(e.style.height="auto",e.style.height=`${String(Math.min(e.scrollHeight,220))}px`);},[v]);let[D,M]=(0,i.useState)(),[P,L]=(0,i.useState)(),q=k.find(e=>e.id===N),z=void 0!==q&&(q.supportsImageInput||q.supportsDocumentInput),O=(0,i.useCallback)(async e=>{let t,n;for(let l of e){let e=await C(l);e.ok||void 0!==t||(t=e.reason,n=l.type);}M(t),L(n);},[C]),B=function(){let[e,t]=(0,i.useState)(void 0);return(0,i.useEffect)(()=>{let e=!1;return ip().then(n=>{e||t(n);},()=>{}),()=>{e=!0;};},[]),e;}(),W=void 0!==B&&B.available&&B.capabilities.speechToText&&ig(),K=void 0!==B&&B.available&&B.capabilities.speechOutput&&("speech-output"===B.profile||"full-realtime"===B.profile),U=(0,i.useRef)(null),V=(0,i.useRef)(null),H=(0,i.useRef)(null),_=(0,i.useRef)(null),G=(0,i.useRef)(null),J=(0,i.useRef)(null),Y=function(e){var t,n;let{onInsert:l,language:a}=e,[r,s]=(0,i.useReducer)(ij,iw),o=null!=(t=e.createRecorder)?t:ix,c=null!=(n=e.transcribe)?n:m.VJ,d=e.vad,u=(0,i.useRef)(void 0),p=(0,i.useRef)(void 0),h=(0,i.useRef)(void 0),f=(0,i.useRef)(void 0),g=(0,i.useRef)(!0),v=(0,i.useRef)(!1),b=(0,i.useRef)(!1),y=(0,i.useCallback)(()=>{void 0!==h.current&&(clearTimeout(h.current),h.current=void 0);},[]),x=(0,i.useCallback)(()=>{void 0!==f.current&&(f.current.stop(),f.current=void 0);},[]),w=(0,i.useCallback)(()=>{let e=p.current;void 0!==e&&(p.current=void 0,y(),x(),s({type:"transcribing"}),e.stop().then(e=>{let t;return c((t=Number.isInteger(e.durationMs)&&e.durationMs>0&&e.durationMs<=12e4?e.durationMs:void 0,{audio:e.audioBase64,mimeType:e.mimeType,...(void 0!==t?{durationMs:t}:{}),...(void 0!==a?{language:a}:{})}));}).then(e=>{g.current&&s({type:"preview",transcript:e.transcript});}).catch(e=>{if(!g.current)return;let{reason:t,message:n}=ik(e);s({type:"error",reason:t,message:n});}));},[y,x,a,c]),j=(0,i.useCallback)(()=>{var e;void 0!==p.current||v.current||(v.current=!0,b.current=!1,s({type:"requesting"}),(null!=(e=u.current)?e:u.current=o()).start().then(e=>{(v.current=!1,!g.current||b.current)?e.cancel():(p.current=e,s({type:"recording"}),h.current=setTimeout(()=>w(),12e4),void 0!==d&&void 0!==e.stream&&(f.current=d.start(e.stream,e=>{"end-of-turn"===e&&w();})));},e=>{if(v.current=!1,!g.current)return;let{reason:t,message:n}=ik(e);s({type:"error",reason:t,message:n});}));},[o,w,d]),k=(0,i.useCallback)(()=>{var e;b.current=!0,y(),x(),null==(e=p.current)||e.cancel(),p.current=void 0,s({type:"reset"});},[y,x]),N=(0,i.useCallback)(()=>{k();},[k]),S=(0,i.useCallback)(()=>{k(),j();},[k,j]),C=(0,i.useCallback)(()=>{let e=r.transcript.trim();e.length>0&&l(e),s({type:"reset"});},[l,r.transcript]),R=(0,i.useCallback)(e=>{s({type:"editTranscript",value:e});},[]);return(0,i.useEffect)(()=>(g.current=!0,()=>{var e;g.current=!1,void 0!==h.current&&(clearTimeout(h.current),h.current=void 0),void 0!==f.current&&(f.current.stop(),f.current=void 0),null==(e=p.current)||e.cancel(),p.current=void 0;}),[]),{phase:r.phase,transcript:r.transcript,error:void 0!==r.errorReason&&void 0!==r.errorMessage?{reason:r.errorReason,message:r.errorMessage}:void 0,busy:"recording"===r.phase||"transcribing"===r.phase,start:j,stop:w,cancel:k,retry:S,discard:N,insert:C,setTranscript:R};}({onInsert:(0,i.useCallback)(e=>{var t;w(0===v.trim().length?e:`${v.replace(/\s+$/u,"")} ${e}`),null==(t=F.current)||t.focus();},[v,w])}),X=function(e){var t,n,l,a;let r,{capability:s}=e,o=(null!=(t=null==s?void 0:s.availableVoicePersonas)?t:[]).join(","),c=(0,i.useMemo)(()=>{var e;return null!=(e=null==s?void 0:s.availableVoicePersonas)?e:[];},[o]),d=(n=iZ(),r=null!=(l=null==s||null==(a=s.availableVoicePersonas)?void 0:a.length)?l:0,!(void 0!==s&&s.available&&"full-realtime"===s.profile&&s.capabilities.realtimeVoice&&s.transport.webrtcMedia&&n&&r>0)?i4:{offered:!0,capture:"webrtc",speaks:!0,canInterrupt:!0}).offered,[u,p]=(0,i.useState)(()=>{var e;return null!=(e=i8(c))?e:iY.RX[0];}),[m,h]=(0,i.useState)(!1);(0,i.useEffect)(()=>{0!==c.length&&p(e=>{var t;return c.includes(e)?e:null!=(t=i8(c))?t:c[0];});},[c]),(0,i.useEffect)(()=>{if(0===c.length)return;let e=()=>{var e;p(null!=(e=i8(c))?e:c[0]);},t=t=>{t.key===i3&&e();};return window.addEventListener(i6,e),window.addEventListener("storage",t),()=>{window.removeEventListener(i6,e),window.removeEventListener("storage",t);};},[c]),(0,i.useEffect)(()=>{d||h(!1);},[d]);let f=(0,i.useCallback)(e=>{c.includes(e)&&(p(e),i9(e));},[c]),g=(0,i.useCallback)(()=>{d&&h(!0);},[d]);return{available:d,availablePersonas:c,persona:u,selectPersona:f,active:m&&d,enter:g,leave:(0,i.useCallback)(()=>{h(!1);},[])};}({capability:B}),Z=function(e){var t,n,l,a,r,s,o,c,d;let{profile:u,enabled:p,text:h,messageId:f,replayAllowed:g,turnManager:v,persona:b}=e,y=function(e){let{profile:t,replayAllowed:n,turnManager:l}=e,a=(0,i.useMemo)(()=>function(e){var t;let{profile:n}=e,l=null!=(t=e.clock)?t:iz(),a=e.observer,r={playbackAllowed:iF("playback.state",n),interruptAllowed:iF("control.interrupt",n),replayAllowed:!0===e.replayAllowed},i=iB(n);function s(){return{profile:n,available:r.playbackAllowed,phase:i.phase,active:iP(i.phase),settled:iL(i.phase),speaking:"speaking"===i.phase,paused:"paused"===i.phase,muted:i.muted,replayAllowed:r.replayAllowed,spoke:i.spoke,interruptions:i.interruptions,replays:i.replays,wireState:iq(i.phase),failureKind:i.failureKind,lastInterruptAtMs:i.lastInterruptAtMs};}function o(e,t,n){var l;let r=i.phase,s=void 0===i.lastTransitionAtMs?0:n-i.lastTransitionAtMs;i.phase=e,i.lastTransitionAtMs=n,null==a||null==(l=a.onTransition)||l.call(a,{from:r,to:e,trigger:t,wireState:iq(e),latencyMs:s});}function c(e){for(let n of e){var t;null==a||null==(t=a.onEffect)||t.call(a,{effect:n,phase:i.phase});}}return{dispatch:function(e){if(!r.playbackAllowed||!iO[e.kind](r))return{outcome:"not-allowed-for-profile",effects:[],snapshot:s()};let t=i.phase,n=i.muted,d=function(e,t){switch(e.kind){case"prepare":return"unavailable"===i.phase||iL(i.phase)?(i.spoke=!1,i.failureKind=void 0,o("preparing","prepare",t),c(["request-synthesis"]),["request-synthesis"]):[];case"play-started":if("preparing"!==i.phase)return[];i.spoke=!0,o("speaking","play-started",t);let n=["start-output","notify-turn-speech-start"];return c(n),n;case"pause":return"speaking"!==i.phase?[]:(o("paused","pause",t),c(["pause-output"]),["pause-output"]);case"resume":return"paused"!==i.phase?[]:(o("speaking","resume",t),c(["resume-output"]),["resume-output"]);case"interrupt":return function(e,t){var n;if("speaking"!==i.phase&&"paused"!==i.phase)return[];let l="number"==typeof e&&Number.isFinite(e)?e:void 0;i.interruptions+=1,i.lastInterruptAtMs=l,o("interrupted","interrupt",t);let r=["stop-output","notify-turn-interrupt"];return c(r),null==a||null==(n=a.onInterrupt)||n.call(a,{phase:i.phase,atMs:l,interruptions:i.interruptions}),r;}(e.atMs,t);case"stop":if(!iP(i.phase))return[];o("canceled","stop",t);let l=["stop-output","notify-turn-speech-stopped"];return c(l),l;case"fail":var r=e.failure;if("preparing"!==i.phase&&"speaking"!==i.phase)return[];i.failureKind=r,o("failed","fail",t);let s=["stop-output","notify-turn-speech-stopped"];return c(s),s;case"complete":return iP(i.phase)?(o("complete","complete",t),c(["notify-turn-speech-completed"]),["notify-turn-speech-completed"]):[];case"replay":return iL(i.phase)?(i.replays+=1,i.spoke=!1,i.failureKind=void 0,o("preparing","replay",t),c(["request-synthesis"]),["request-synthesis"]):[];case"set-muted":var d=e.muted;if(i.muted===d)return[];i.muted=d;let u=d?"mute-output":"unmute-output";return c([u]),[u];}}(e,l.now());return{outcome:i.phase!==t||i.muted!==n||d.length>0?"transitioned":"no-op",effects:d,snapshot:s()};},snapshot:s,reset:function(){i=iB(n);}};}({profile:t,replayAllowed:n}),[t,n]),[r,s]=(0,i.useState)(()=>a.snapshot());(0,i.useEffect)(()=>{s(a.snapshot());},[a]);let o=(0,i.useRef)(!0);(0,i.useEffect)(()=>(o.current=!0,()=>{o.current=!1;}),[]);let c=(0,i.useCallback)(e=>{let t=a.dispatch(e);void 0!==l&&function(e,t){for(let n of e.effects){let l=function(e,t){switch(e){case"notify-turn-speech-start":return{kind:"assistant-speech-start"};case"notify-turn-speech-completed":return{kind:"assistant-speech-end",how:"completed"};case"notify-turn-speech-stopped":return{kind:"assistant-speech-end",how:"stopped"};case"notify-turn-interrupt":return{kind:"user-interrupt",atMs:t};default:return;}}(n,e.snapshot.lastInterruptAtMs);void 0!==l&&t.apply(l);}}(t,l),o.current&&s(t.snapshot);},[a,l]),d=(0,i.useCallback)(()=>{c({kind:"set-muted",muted:!a.snapshot().muted});},[a,c]),u=(0,i.useCallback)(e=>c({kind:"set-muted",muted:e}),[c]),p=(0,i.useCallback)(()=>c({kind:"pause"}),[c]),m=(0,i.useCallback)(()=>c({kind:"resume"}),[c]),h=(0,i.useCallback)(()=>c({kind:"stop"}),[c]),f=(0,i.useCallback)(e=>c({kind:"interrupt",atMs:e}),[c]),g=(0,i.useCallback)(()=>c({kind:"replay"}),[c]),v=(0,i.useCallback)(()=>c({kind:"prepare"}),[c]),b=(0,i.useCallback)(()=>c({kind:"play-started"}),[c]),y=(0,i.useCallback)(()=>c({kind:"complete"}),[c]);return{snapshot:r,toggleMute:d,setMuted:u,pause:p,resume:m,stop:h,interrupt:f,replay:g,prepare:v,playStarted:b,complete:y,fail:(0,i.useCallback)(e=>c({kind:"fail",failure:e}),[c]),reset:(0,i.useCallback)(()=>{a.reset(),o.current&&s(a.snapshot());},[a])};}({profile:u,replayAllowed:g,turnManager:v}),x=(0,i.useRef)(y);x.current=y;let w=(0,i.useRef)(null!=(t=e.synthesize)?t:iW(b));w.current=null!=(n=e.synthesize)?n:iW(b);let j=(0,i.useRef)(null!=(l=e.createAudio)?l:iK);j.current=null!=(a=e.createAudio)?a:iK;let k=(0,i.useRef)(null!=(r=e.createObjectUrl)?r:iU);k.current=null!=(s=e.createObjectUrl)?s:iU;let N=(0,i.useRef)(null!=(o=e.revokeObjectUrl)?o:iV);N.current=null!=(c=e.revokeObjectUrl)?c:iV;let S=(0,i.useRef)(null),C=(0,i.useRef)(null),R=(0,i.useRef)(null),I=(0,i.useRef)({id:void 0,nonce:0}),[E,$]=(0,i.useState)(0),A=(0,i.useRef)(!1),T=(0,i.useRef)(void 0);A.current||(A.current=!0,T.current=(null!=(d=e.createStreamingSink)?d:function(){let e,t;if(!("u">typeof AudioContext&&"u">typeof AudioWorkletNode))return;let n=0;async function l(){if(void 0!==t)return t;let n=new AudioContext({sampleRate:24e3});await n.audioWorklet.addModule("/keiko-playback-worklet.js");let l=new AudioWorkletNode(n,"keiko-playback",{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[1]});return l.connect(n.destination),e=n,t=l,l;}async function a(e,t,n,l){let a,r=t.getReader(),i=0;try{for(;;){let{done:t,value:l}=await r.read();if(t)break;if(n.aborted)return void(await r.cancel());let{samples:s,leftover:o}=function(e,t){let n=e;if(void 0!==t&&t.length>0){let l=new Uint8Array(t.length+e.length);l.set(t),l.set(e,t.length),n=l;}let l=n.length-n.length%2,a=l<n.length?n.slice(l):void 0,r=new Int16Array(l/2),i=new DataView(n.buffer,n.byteOffset,l);for(let e=0;e<r.length;e+=1)r[e]=i.getInt16(2*e,!0);return{samples:r,leftover:a};}(l,a);a=o,s.length>0&&(i+=s.length,e.port.postMessage(s,[s.buffer]));}0===i?l.onError():e.port.postMessage({type:"end"});}catch{n.aborted||l.onError();}}return{async play(t,r,i){let s,o;try{s=await l();}catch{return!1;}if(r.aborted)return!0;n=0;let c=!1;await(null==e?void 0:e.resume().catch(()=>{})),s.port.postMessage({type:"config",primeFrames:2400}),s.port.onmessage=e=>{let t=e.data;if("position"===t.type){var l;n=null!=(l=t.frames)?l:n,c||(c=!0,i.onStart());}else"ended"===t.type&&i.onEnded();};try{o=await(0,m.Fw)(t,r);}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return!0;return!1;}return null!==o.body&&(a(s,o.body,r,i),!0);},stop(){null==t||t.port.postMessage(null),null==e||e.suspend().catch(()=>{});},positionMs(){if(void 0!==t&&0!==n)return Math.round(n/24e3*1e3);}};})());let F=(0,i.useRef)(b);F.current=b;let D=(0,i.useCallback)(()=>{var e,t;null==(e=C.current)||e.abort(),C.current=null,null==(t=T.current)||t.stop();let n=S.current;if(null!==n){n.onplaying=null,n.onended=null,n.onerror=null;try{n.pause();}catch{}n.src="",S.current=null;}null!==R.current&&(N.current(R.current),R.current=null);},[]),M=y.snapshot.available;(0,i.useEffect)(()=>{let e=x.current;if(!p||!M||void 0===f||void 0===h||0===h.trim().length||I.current.id===f&&I.current.nonce===E)return;let t=I.current.id===f;if(I.current={id:f,nonce:E},e.snapshot.muted&&!t)return;let n=!1,l=new AbortController();C.current=l,e.prepare();let a=()=>{let e=j.current();e.muted=!1,S.current=e,Promise.resolve(w.current(h,l.signal)).then(t=>{let a;if(n||l.signal.aborted)return;let r=new Blob([(a=atob(t.audio),Uint8Array.from(a,e=>e.charCodeAt(0)))],{type:t.mimeType}),i=k.current(r);return R.current=i,e.src=i,e.onplaying=()=>{n||x.current.playStarted();},e.onended=()=>{n||(x.current.complete(),D());},e.onerror=()=>{n||(x.current.fail("internal"),D());},Promise.resolve(e.play()).catch(e=>{n||iH(e)||(x.current.fail("internal"),D());});}).catch(e=>{n||iH(e)||(x.current.fail(function(e){if(e instanceof m.hD)switch(e.code){case"VOICE_RATE_LIMITED":return"rate-limited";case"VOICE_TIMEOUT":return"timeout";case"VOICE_UNAVAILABLE":return"unavailable";default:return"provider-error";}return"internal";}(e)),D());});},r=T.current;return void 0===r?a():r.play({text:h,...(void 0!==F.current?{persona:F.current}:{})},l.signal,{onStart:()=>{n||x.current.playStarted();},onEnded:()=>{n||(x.current.complete(),D());},onError:()=>{n||l.signal.aborted||(x.current.fail("internal"),D());}}).then(e=>{e||n||l.signal.aborted||a();}).catch(()=>{n||l.signal.aborted||a();}),()=>{n=!0,D();};},[p,M,h,f,E,D]);let P=(0,i.useCallback)(e=>{x.current.setMuted(e),e&&(D(),x.current.snapshot.active&&x.current.stop());},[D]),L=(0,i.useCallback)(()=>{P(!x.current.snapshot.muted);},[P]),q=(0,i.useCallback)(()=>{var e;null==(e=S.current)||e.pause(),x.current.pause();},[]),z=(0,i.useCallback)(()=>{let e=S.current;null!==e&&Promise.resolve(e.play()).catch(()=>{}),x.current.resume();},[]),O=(0,i.useCallback)(()=>{D(),x.current.stop();},[D]),B=(0,i.useCallback)(e=>{D(),x.current.interrupt(e);},[D]),W=(0,i.useCallback)(()=>{$(e=>e+1),x.current.replay();},[]);return(0,i.useMemo)(()=>({snapshot:y.snapshot,toggleMute:L,setMuted:P,pause:q,resume:z,stop:O,interrupt:B,replay:W,prepare:y.prepare,playStarted:y.playStarted,complete:y.complete,fail:y.fail,reset:y.reset}),[y,L,P,q,z,O,B,W]);}({profile:null!=(t=null==B?void 0:B.profile)?t:"none",enabled:!1,text:void 0,messageId:void 0}),Q=function(e){if(void 0===e)return;let t=void 0!==e.connectedScopes?e.connectedScopes.length:+(void 0!==e.connectedScope),n=void 0!==e.localKnowledgeScopes?e.localKnowledgeScopes.length:+(void 0!==e.localKnowledgeScope),l=t+n;if(0!==l)return{enabled:!0,sourceCount:l,kind:t>0&&n>0?"hybrid":l>1?"multi":t>0?"files":"knowledge"};}($),ee=function(e){var t,n;let[l,a]=(0,i.useReducer)(su,sd),r=(0,i.useRef)(function(e){var t;let n,l,a,r,{profile:i}=e,s=null!=(t=e.clock)?t:iz(),o=e.observer,c=(n=iF("media.track.state",i),l=iF("playback.state",i),a=iF("control.interrupt",i),{mediaAllowed:n,playbackAllowed:l,interruptAllowed:a,transcriptAllowed:r=iF("transcript.committed",i),floorControl:n,usesManualCommit:r&&!n,canCaptureUserVoice:n||r}),d=so(i);function u(){return{profile:i,active:"disabled"!==d.state,state:d.state,floorHolder:si[d.state],turnIndex:d.turnIndex,interruptions:d.interruptions,backchannels:d.backchannels,pendingCommit:d.pendingCommit,recovering:"recovering"===d.state,lastEndOfTurnAtMs:d.lastEndOfTurnAtMs,lastInterruptAtMs:d.lastInterruptAtMs};}function p(e,t,n){var l;let a=d.state,r=void 0===d.lastTransitionAtMs?0:n-d.lastTransitionAtMs;d.state=e,d.lastTransitionAtMs=n,null==o||null==(l=o.onTransition)||l.call(o,{from:a,to:e,trigger:t,floorHolder:si[e],turnIndex:d.turnIndex,latencyMs:r});}function m(e){for(let n of e){var t;null==o||null==(t=o.onEffect)||t.call(o,{effect:n,state:d.state,turnIndex:d.turnIndex});}}function h(e,t,n){var l,a,r;if("idle"===d.state||"listening"===d.state||"recovering"===d.state)return[];if(d.lastInterruptAtMs=t,"yielding"===d.state)return d.interruptions+=1,p("idle","user-interrupt",t),null==o||null==(a=o.onInterrupt)||a.call(o,{state:d.state,atMs:e,interruptions:d.interruptions}),[];let i=(r=n,"speaking"===d.state||r?["stop-playback","cancel-speech-generation","preserve-user-turn"]:"thinking"===d.state?["cancel-speech-generation"]:["stop-playback"]);return d.interruptions+=1,p("interrupted","user-interrupt",t),m(i),null==o||null==(l=o.onInterrupt)||l.call(o,{state:d.state,atMs:e,interruptions:d.interruptions}),i;}return{apply:function(e){if("none"===i||"disabled"===d.state||!ss[e.kind](c))return{outcome:"not-allowed-for-profile",effects:[],snapshot:u()};let t=d.state,n=d.turnIndex,l=d.pendingCommit,a=function(e,t){switch(e.kind){case"user-speech-start":var n,l,a;if("speaking"===d.state){let e=h(t,t,!0);return p("listening","user-speech-start",t),e;}return"thinking"===d.state?(p("listening","user-speech-start",t),m(["preserve-user-turn"]),["preserve-user-turn"]):("listening"===d.state||p("listening","user-speech-start",t),[]);case"user-end-of-turn":return"listening"!==d.state||((d.lastEndOfTurnAtMs=t,c.floorControl)?(d.turnIndex+=1,d.pendingCommit=!1,p("thinking","user-end-of-turn",t)):(d.pendingCommit=!0,p("idle","user-end-of-turn",t))),[];case"dictation-commit":return"idle"===d.state&&d.pendingCommit&&(d.turnIndex+=1,d.pendingCommit=!1,d.lastEndOfTurnAtMs=t,p("idle","dictation-commit",t)),[];case"dictation-discard":return"idle"===d.state&&d.pendingCommit&&(d.pendingCommit=!1,p("idle","dictation-discard",t)),[];case"assistant-speech-start":return"speaking"===d.state||("thinking"===d.state||"idle"===d.state||"interrupted"===d.state)&&p("speaking","assistant-speech-start",t),[];case"assistant-speech-end":return n=e.how,"completed"===n?"speaking"===d.state?p("yielding","assistant-speech-end",t):"thinking"===d.state&&p("idle","assistant-speech-end",t):"speaking"===d.state?p("interrupted","assistant-speech-end",t):"thinking"===d.state&&p("idle","assistant-speech-end",t),[];case"user-interrupt":return h(e.atMs,t,!1);case"backchannel":return d.backchannels+=1,m(["emit-backchannel"]),null==o||null==(l=o.onBackchannel)||l.call(o,{state:d.state,backchannels:d.backchannels}),["emit-backchannel"];case"provider-failure":return a=e.recoverable,a?(p("recovering","provider-failure",t),m(["begin-recovery"]),["begin-recovery"]):(p("disabled","provider-failure",t),[]);case"permission-denied":return p("disabled","permission-denied",t),[];case"recovered":return"recovering"===d.state&&p("idle","recovered",t),[];case"session-closed":return p("disabled","session-closed",t),[];}}(e,s.now());return{outcome:d.state!==t||d.turnIndex!==n||d.pendingCommit!==l||a.length>0?"transitioned":"no-op",effects:a,snapshot:u()};},snapshot:u,reset:function(){d=so(i);}};}({profile:"full-realtime"})),[s,o]=(0,i.useState)(()=>r.current.snapshot()),[c,d]=(0,i.useState)(!1),u=null!=(t=e.createTransport)?t:i2,p=(0,i.useRef)(e.persona);p.current=e.persona;let m=(0,i.useRef)(e.chatContext);m.current=e.chatContext;let h=(0,i.useMemo)(()=>{var t;return null!=(t=e.createControl)?t:()=>{var e,t,n;let l,a;return e=void 0,t=p.current,n=m.current,a=null!=e?e:e=>new WebSocket(e),{negotiate:e=>new Promise((r,i)=>{let s,o=crypto.randomUUID(),c=crypto.randomUUID();try{let e;l=a((e="https:"===location.protocol?"wss:":"ws:",`${e}//${location.host}/api/voice/control`));}catch(e){i(new i7("unavailable",e instanceof Error?e.message:"WebSocket could not be opened."));return;}let d=!1,u=!1,p=()=>{void 0!==s&&(clearTimeout(s),s=void 0);},m=e=>{p(),i(e);};s=setTimeout(()=>{s=void 0;try{null==l||l.close();}catch{}i(new i7("connection-failed","Voice control negotiation timed out."));},15e3),l.addEventListener("error",()=>{d?m(new i7("connection-failed","Voice control connection was lost.")):m(new i7("unavailable","Voice control connection failed."));}),l.addEventListener("close",()=>{d?m(new i7("connection-failed","Voice control connection closed during negotiation.")):m(new i7("unavailable","Voice control connection was closed."));}),l.addEventListener("open",()=>{d=!0,null==l||l.send(JSON.stringify({protocolVersion:"1",sessionId:o,seq:0,direction:"client-to-host",kind:"session.create",idempotencyKey:c,requestedProfile:"full-realtime",negotiationMode:"proxied-sdp",...(void 0!==t?{persona:t}:{}),...(void 0!==n?{chatContext:n}:{})}));}),l.addEventListener("message",t=>{var n;let a;try{a=JSON.parse("string"==typeof t.data?t.data:String(t.data));}catch{m(new i7("connection-failed","Received an unparseable control message."));return;}if(!function(e){var t,n,l,a;return!!("object"==typeof e&&null!==e&&!Array.isArray(e))&&"1"===e.protocolVersion&&"string"==typeof(t=e.sessionId)&&t.trim().length>0&&"number"==typeof(n=e.seq)&&Number.isInteger(n)&&n>=0&&"string"==typeof(l=e.direction)&&i$.includes(l)&&"string"==typeof(a=e.kind)&&iA.includes(a);}(a))return;let i=a;if("error"===i.kind)return void m(new i7("negotiation-failed"===i.code?"negotiation-failed":"connection-failed",`Voice control error: ${i.code}`));if("session.created"===i.kind){u=!0,null==l||l.send(JSON.stringify({protocolVersion:"1",sessionId:o,seq:1,direction:"client-to-host",kind:"signal.sdp.offer",sdp:e}));return;}if("signal.sdp.answer"===i.kind&&u){n=i.sdp,p(),r(n);return;}});}),close(){try{null==l||l.close();}catch{}l=void 0;}};};},[e.createControl]),f=null!=(n=e.createAudioSink)?n:sc,g=(0,i.useRef)(e.onUserTranscriptCommitted),v=(0,i.useRef)(e.onAssistantTranscriptCommitted),b=(0,i.useRef)(e.onGroundedToolCall),y=(0,i.useRef)(!0===e.groundingActive);g.current=e.onUserTranscriptCommitted,v.current=e.onAssistantTranscriptCommitted,b.current=e.onGroundedToolCall,y.current=!0===e.groundingActive;let x=(0,i.useRef)(void 0),w=(0,i.useRef)(void 0),j=(0,i.useRef)(void 0),k=(0,i.useRef)(new Set()),N=(0,i.useRef)(new Set()),S=(0,i.useRef)(new Set()),C=(0,i.useRef)(""),R=(0,i.useRef)(void 0),I=(0,i.useRef)(void 0),E=(0,i.useRef)(new Map()),$=(0,i.useRef)(new Set()),A=(0,i.useRef)(new Map()),T=(0,i.useRef)(void 0),F=(0,i.useRef)(!0),D=(0,i.useCallback)(e=>{let t=r.current.apply(e);if(o(t.snapshot),t.effects.includes("stop-playback")||t.effects.includes("cancel-speech-generation")){var n,l;null==(l=x.current)||null==(n=l.sendDataChannelEvent)||n.call(l,{type:"response.cancel"});}},[]),M=(0,i.useCallback)(()=>{for(let e of(r.current.reset(),o(r.current.snapshot()),k.current.clear(),N.current.clear(),S.current.clear(),C.current="",R.current=void 0,I.current=void 0,E.current.clear(),$.current.clear(),A.current.values()))e.abort();A.current.clear();},[]),P=(0,i.useCallback)(e=>{var t;let n=sp(e);if(void 0!==n){if(k.current.has(n))return;k.current.add(n);}if(S.current.clear(),y.current){I.current=void 0===n?{text:e.text}:{text:e.text,itemId:n};return;}null==(t=g.current)||t.call(g,e.text);},[]),L=(0,i.useCallback)(()=>{var e;let t=I.current;void 0!==t&&(I.current=void 0,null==(e=g.current)||e.call(g,t.text));},[]),q=(0,i.useCallback)(e=>{var t,n,l,a,r,i,s;let o=E.current.get(e.callId);E.current.set(e.callId,{argumentsText:`${null!=(t=null==o?void 0:o.argumentsText)?t:""}${e.delta}`,...((null!=(n=e.name)?n:null==o?void 0:o.name)?{name:null!=(l=e.name)?l:null==o?void 0:o.name}:{}),...((null!=(a=e.responseId)?a:null==o?void 0:o.responseId)?{responseId:null!=(r=e.responseId)?r:null==o?void 0:o.responseId}:{}),...((null!=(i=e.itemId)?i:null==o?void 0:o.itemId)?{itemId:null!=(s=e.itemId)?s:null==o?void 0:o.itemId}:{})});},[]),z=(0,i.useCallback)((e,t)=>{var n,l,a,r;null==(l=x.current)||null==(n=l.sendDataChannelEvent)||n.call(l,{type:"conversation.item.create",item:{type:"function_call_output",call_id:e,output:function(e){try{return JSON.stringify(e);}catch{return JSON.stringify({status:"error",message:"Grounded retrieval output could not be serialized."});}}(t)}}),null==(r=x.current)||null==(a=r.sendDataChannelEvent)||a.call(r,{type:"response.create"});},[]),O=(0,i.useCallback)(e=>{var t,n,l,a,r;let i=E.current.get(e.callId);if("search_keiko_grounding"!==(e.name||(null==i?void 0:i.name)))return;let s=function(e){let t=e.trim();if(0!==t.length){try{let e=JSON.parse(t);if("object"==typeof e&&null!==e&&!Array.isArray(e)&&"string"==typeof e.query){let t=e.query.trim();return t.length>0?t:void 0;}}catch{}return t;}}(e.argumentsText.trim().length>0?e.argumentsText:null!=(t=null==i?void 0:i.argumentsText)?t:"");if(void 0===s)return;let o=`${e.callId}:${s.replace(/\s+/gu," ").trim().toLowerCase()}`;if($.current.has(o))return;$.current.add(o),E.current.delete(e.callId),D({kind:"user-end-of-turn"});let c=b.current;if(!y.current||void 0===c)return void z(e.callId,{status:"error",message:"Grounded retrieval is not available for this chat."});let d=I.current,u=new AbortController();A.current.set(o,u),c({callId:e.callId,query:s,...((null==d?void 0:d.text)===void 0?{}:{userTranscript:d.text}),...((null!=(n=e.responseId)?n:null==i?void 0:i.responseId)?{responseId:null!=(l=e.responseId)?l:null==i?void 0:i.responseId}:{}),...((null!=(a=e.itemId)?a:null==i?void 0:i.itemId)?{itemId:null!=(r=e.itemId)?r:null==i?void 0:i.itemId}:{})},u.signal).then(t=>{u.signal.aborted||(I.current=void 0,z(e.callId,t));}).catch(t=>{u.signal.aborted||(L(),D({kind:"provider-failure",recoverable:!0}),z(e.callId,{status:"error",message:t instanceof Error?t.message:"Grounded retrieval failed before an answer could be prepared."}));}).finally(()=>{A.current.delete(o);});},[D,L,z]),B=(0,i.useCallback)(e=>{var t,n;if(y.current){C.current="",R.current=void 0,D({kind:"assistant-speech-end",how:"completed"});return;}let l=sp(e);if(void 0!==l){if(N.current.has(l))return;N.current.add(l);}let a=`${null!=(n=e.responseId)?n:"unknown-response"}:${e.text.replace(/\s+/gu," ").trim()}`;S.current.has(a)||(S.current.add(a),C.current="",R.current=void 0,D({kind:"assistant-speech-start"}),null==(t=v.current)||t.call(v,e.text),D({kind:"assistant-speech-end",how:"completed"}));},[D]),W=(0,i.useCallback)(e=>{let t=C.current.trim();0!==t.length&&B({kind:"assistant-transcript-committed",text:t,responseId:null!=e?e:R.current});},[B]),K=(0,i.useCallback)(e=>{let t=function(e){var t,n,l;if(se(e))switch(null!=(t=st(e,"type"))?t:st(e,"kind")){case"input_audio_buffer.speech_started":return{kind:"user-speech-start",itemId:sl(e)};case"input_audio_buffer.speech_stopped":return{kind:"user-speech-stop",itemId:sl(e)};case"conversation.item.input_audio_transcription.completed":{let t=null==(n=st(e,"transcript"))?void 0:n.trim();return void 0===t||0===t.length?void 0:{kind:"user-transcript-committed",text:t,itemId:sl(e)};}case"conversation.item.input_audio_transcription.failed":case"error":return{kind:"error",message:function(e){var t;let n=e.error;if(se(n)){let e=st(n,"message");if(void 0!==e)return e;let t=st(n,"code");if(void 0!==t)return`Realtime error: ${t}`;}return null!=(t=st(e,"message"))?t:"Realtime voice provider reported an error.";}(e)};case"response.audio_transcript.delta":case"response.output_audio_transcript.delta":{let t=st(e,"delta");return void 0===t?void 0:{kind:"assistant-transcript-delta",delta:t,responseId:sn(e),itemId:sl(e)};}case"response.audio_transcript.done":case"response.output_audio_transcript.done":{let t=null==(l=st(e,"transcript"))?void 0:l.trim();return void 0===t||0===t.length?void 0:{kind:"assistant-transcript-committed",text:t,responseId:sn(e),itemId:sl(e)};}case"response.function_call_arguments.delta":{let t=sa(e),n=st(e,"delta");return void 0===t||void 0===n?void 0:{kind:"function-call-arguments-delta",callId:t,name:st(e,"name"),delta:n,responseId:sn(e),itemId:sl(e)};}case"response.output_item.done":{let t=sr(e.item,e);if(void 0!==t)return{kind:"function-call-committed",callId:t.callId,name:t.name,argumentsText:t.argumentsText,responseId:sn(e),itemId:t.itemId};let n=function(e){let t=e.item;if(!se(t)||"assistant"!==t.role||!Array.isArray(t.content))return;let n=[];for(let e of t.content)if(se(e)){let t=st(e,"transcript");void 0!==t&&n.push(t);}let l=n.join("").trim();return l.length>0?l:void 0;}(e);return void 0===n?void 0:{kind:"assistant-transcript-committed",text:n,responseId:sn(e),itemId:sl(e)};}case"response.audio.delta":case"response.output_audio.delta":case"output_audio_buffer.started":return{kind:"assistant-output-start",responseId:sn(e),itemId:sl(e)};case"output_audio_buffer.stopped":return{kind:"assistant-output-stop",responseId:sn(e),itemId:sl(e)};case"response.cancelled":return{kind:"response-cancelled",responseId:sn(e)};case"response.done":{let t=function(e){let t=e.response;if(se(t)&&Array.isArray(t.output))for(let n of t.output){let t=sr(n,e);if(void 0!==t)return t;}}(e);if(void 0!==t)return{kind:"function-call-committed",callId:t.callId,name:t.name,argumentsText:t.argumentsText,responseId:sn(e),itemId:t.itemId};return{kind:"response-done",responseId:sn(e),status:function(e){let t=e.response,n=se(t)?st(t,"status"):st(e,"status");if("completed"===n||"cancelled"===n||"failed"===n||"incomplete"===n)return n;}(e)};}default:return;}}(e);if(void 0!==t)switch(t.kind){case"user-speech-start":D({kind:"user-speech-start"});return;case"user-speech-stop":D({kind:"user-end-of-turn"});return;case"user-transcript-committed":P(t);return;case"assistant-output-start":D({kind:"assistant-speech-start"});return;case"assistant-output-stop":D({kind:"assistant-speech-end",how:"completed"});return;case"assistant-transcript-delta":C.current+=t.delta,R.current=t.responseId,D({kind:"assistant-speech-start"});return;case"assistant-transcript-committed":B(t);return;case"function-call-arguments-delta":q(t);return;case"function-call-committed":O(t);return;case"response-done":if("cancelled"===t.status)return void D({kind:"assistant-speech-end",how:"stopped"});if("failed"===t.status||"incomplete"===t.status)return void D({kind:"provider-failure",recoverable:!0});y.current&&L(),W(t.responseId),D({kind:"assistant-speech-end",how:"completed"});return;case"response-cancelled":D({kind:"assistant-speech-end",how:"stopped"});return;case"error":D({kind:"provider-failure",recoverable:!0}),a({type:"error",reason:"connection-failed",message:t.message});return;}},[q,D,B,W,P,O,L]),U=(0,i.useCallback)(()=>{var e,t,n;void 0!==T.current&&(clearTimeout(T.current),T.current=void 0),null==(e=j.current)||e.release(),j.current=void 0,null==(t=x.current)||t.close(),x.current=void 0,null==(n=w.current)||n.close(),w.current=void 0,M();},[M]);(0,i.useEffect)(()=>{var e,t;null==(t=x.current)||null==(e=t.setInputMuted)||e.call(t,c);},[c]);let V=(0,i.useCallback)(()=>{var e,t;null==(t=x.current)||null==(e=t.sendDataChannelEvent)||e.call(t,{type:"response.cancel"}),U(),a({type:"reset"});},[U]),H=(0,i.useCallback)(()=>{if(void 0!==x.current)return;a({type:"requesting"});let e=u(),t=h();w.current=t,e.connect().then(async e=>{var n,l;if(!F.current){e.close(),t.close();return;}x.current=e,null==(n=e.setInputMuted)||n.call(e,c),a({type:"negotiating"});let r=f();j.current=r,e.onRemoteTrack(e=>{F.current&&r.attach(e);}),null==(l=e.onDataChannelEvent)||l.call(e,e=>{F.current&&K(e);}),e.onConnectionStateChange(e=>{F.current&&("connected"===e?(void 0!==T.current&&(clearTimeout(T.current),T.current=void 0),a({type:"connected"})):"failed"===e||"closed"===e?(U(),a({type:"reset"})):"disconnected"===e&&void 0===T.current&&(T.current=setTimeout(()=>{T.current=void 0,F.current&&(U(),a({type:"reset"}));},5e3)));});let i=await t.negotiate(e.offerSdp);F.current?(await e.applyAnswer(i),F.current||e.close()):e.close();}).catch(e=>{if(!F.current)return;U();let{reason:t,message:n}=e instanceof iX||e instanceof i7?{reason:e.reason,message:e.message}:{reason:"connection-failed",message:"Real-time voice could not be started."};a({type:"error",reason:t,message:n});});},[u,h,f,c,K,U]),_=(0,i.useCallback)(()=>{U(),a({type:"reset"}),H();},[U,H]),G=(0,i.useCallback)(()=>{var e,t;for(let n of(null==(t=x.current)||null==(e=t.sendDataChannelEvent)||e.call(t,{type:"response.cancel"}),A.current.values()))n.abort();A.current.clear(),D({kind:"user-interrupt"});},[D]),J=(0,i.useCallback)(()=>{d(e=>!e);},[]);return(0,i.useEffect)(()=>(F.current=!0,()=>{F.current=!1,U();}),[U]),{phase:l.phase,busy:"requesting"===l.phase||"negotiating"===l.phase||"connected"===l.phase,error:void 0!==l.errorReason&&void 0!==l.errorMessage?{reason:l.errorReason,message:l.errorMessage}:void 0,turnSnapshot:s,listening:"listening"===s.state,speaking:"speaking"===s.state,canInterrupt:"assistant"===s.floorHolder,muted:c,start:H,stop:V,retry:_,interrupt:G,toggleMute:J};}({persona:X.persona,chatContext:void 0===$?void 0:{chatId:$.id,memory:{enabled:o.memoryEnabled,budgetTokens:o.memoryBudgetTokens},...(void 0===Q?{}:{grounding:Q})},groundingActive:(null==Q?void 0:Q.enabled)===!0,onGroundedToolCall:o.runRealtimeGroundedTool,onUserTranscriptCommitted:e=>{var t;return null==(t=o.appendVoiceTurn)?void 0:t.call(o,[{role:"user",content:e}]);},onAssistantTranscriptCommitted:e=>{var t;return null==(t=o.appendVoiceTurn)?void 0:t.call(o,[{role:"assistant",content:e}]);}}),et=X.available&&void 0!==$,en=function(e){let{realtimePhase:t,turnState:n,muted:l}=e;return"error"===t?"error":"requesting"===t||"negotiating"===t||"recovering"===n?"connecting":"interrupted"===n?"interrupted":"speaking"===n?l?"muted":"speaking":"thinking"===n?"thinking":"listening"===n?"listening":"idle";}({realtimePhase:ee.phase,turnState:ee.turnSnapshot.state,muted:ee.muted}),el=function(e){let{voiceDialogActive:t,voiceDialogAvailable:n,voiceDialogState:l,listening:a,speaking:r,sending:i,sendStatus:s,hasSessionError:o}=e;return t?!n||o||"error"===l?{active:!0,state:"error",intensity:"high"}:"interrupted"===l?{active:!0,state:"interrupted",intensity:"medium"}:"muted"===l?{active:!0,state:"muted",intensity:"medium"}:r||"speaking"===l?{active:!0,state:"speaking",intensity:"medium"}:a||"listening"===l?{active:!0,state:"listening",intensity:"medium"}:"thinking"===l||"connecting"===l||i||"queued"===s||"contacting"===s||"streaming"===s?{active:!0,state:"thinking",intensity:"high"}:{active:!0,state:"ready",intensity:"low"}:{active:!1,state:"ready",intensity:"low"};}({voiceDialogActive:X.active,voiceDialogAvailable:et,voiceDialogState:en,listening:ee.listening,speaking:ee.speaking,sending:y,sendStatus:x,hasSessionError:void 0!==I||void 0!==ee.error}),er=(0,i.useCallback)(()=>{et&&(X.enter(),ee.start());},[X,et,ee]),ei=(0,i.useCallback)(()=>{ee.stop(),X.leave();},[ee,X]),es=(0,i.useRef)(!1),eo=(0,i.useCallback)(()=>{es.current=!0,X.active?ei():er();},[X.active,er,ei]);(0,i.useEffect)(()=>{X.active&&!et&&ei();},[ei,X.active,et]),(0,i.useEffect)(()=>{X.active||"idle"===ee.phase||ee.stop();},[X.active,ee]);let ec=X.active?ee.muted:Z.snapshot.muted,ed=X.active?ee.toggleMute:Z.toggleMute,[eu,ep]=(0,i.useState)("idle"),em=(0,i.useRef)(X.active),eh=(0,i.useRef)(void 0);(0,i.useEffect)(()=>{if(em.current!==X.active){if(em.current=X.active,es.current){var e;es.current=!1,null==(e=H.current)||e.focus();}void 0!==eh.current&&clearTimeout(eh.current),ep(X.active?"entering":"leaving"),eh.current=setTimeout(()=>{eh.current=void 0,ep("idle");},460);}},[X.active]),(0,i.useEffect)(()=>()=>{void 0!==eh.current&&clearTimeout(eh.current);},[]);let ef=(0,i.useMemo)(()=>sD($,null==A?void 0:A.path),[$,null==A?void 0:A.path]),eg=ef.map(e=>e.root).join("\x01"),[ev,eb]=(0,i.useState)(null!=(n=null==(s=ef[0])?void 0:s.root)?n:""),[ey,ex]=(0,i.useState)(null),[ew,ej]=(0,i.useState)(null),[ek,eN]=(0,i.useState)(null),[eS,eC]=(0,i.useState)(0),[eR,eI]=(0,i.useState)([]),eE=null!==ey&&ef.length>0,e$=function(e,t,n){let[l,a]=(0,i.useState)([]),[r,s]=(0,i.useState)(!1),[o,c]=(0,i.useState)("Type after @ to search connected repository files."),[d,u]=(0,i.useState)(null);return(0,i.useEffect)(()=>{if(!e){s(!1),a([]),u(null);return;}let l=n.trim();if(0===t.length||0===l.length){s(!1),a([]),c("Type after @ to search connected repository files."),u(null);return;}let r=new AbortController(),i=!1;s(!0),u(null),c("Searching repository files...");let o=window.setTimeout(()=>{(0,m.Gb)(t,l,24,{signal:r.signal}).then(e=>{if(!i)if(a(e.results),0===e.results.length)c("No matching repository files.");else{let t=e.results.length;c(`${String(t)} ${1===t?"file":"files"} found${e.truncated?"; refine query; search scanned limit reached.":"."}`);}}).catch(e=>{i||"u">typeof DOMException&&e instanceof DOMException&&"AbortError"===e.name||(a([]),u(sW(e)),c("Repository search failed."));}).finally(()=>{i||s(!1);});},120);return()=>{i=!0,window.clearTimeout(o),r.abort();};},[e,n,t]),{results:l,searching:r,message:o,error:d};}(eE,ev,null!=(l=null==ey?void 0:ey.query)?l:"");(0,i.useEffect)(()=>{if(0===ef.length){eb(""),ex(null);return;}if(!ef.some(e=>e.root===ev)){var e,t;eb(null!=(e=null==(t=ef[0])?void 0:t.root)?e:"");}},[eg,ef,ev]),(0,i.useEffect)(()=>{eC(0);},[null==ey?void 0:ey.query,e$.results]),(0,i.useEffect)(()=>{eI(e=>{var t;return function(e){let t=new Set(),n=[];for(sz.lastIndex=0;;){var l;let a=sz.exec(e);if(null===a)break;let r=sP(null!=(l=a[2])?l:"");0===r.length||t.has(r)||(t.add(r),n.push(r));}return n;}((t={current:e,draft:v,selectedRoot:ev,roots:ef,searchResults:e$.results}).draft).map(e=>{let n=t.current.find(t=>t.path===e);if((null==n?void 0:n.verified)===!0)return n;let l=t.searchResults.find(t=>t.path===e);return void 0!==l?sq(l,"draft"):null!=n?n:function(e,t,n){var l,a,r;let i=sP(e);if(0===i.length||i.includes(".."))return null;let s=t.length>0?t:null!=(l=null==(r=n[0])?void 0:r.root)?l:"";if(0===s.length)return null;let o=i.split("/").filter(e=>e.length>0),c=null!=(a=o[o.length-1])?a:i,d=o.length>1?o.slice(0,-1).join("/"):"";return{id:sL(s,i),root:s,path:i,name:c,directory:d,verified:!1,source:"draft"};}(e,t.selectedRoot,t.roots);}).filter(e=>null!==e);});},[v,eg,ef,e$.results,ev]);let eA=(0,i.useCallback)((e,t)=>{if(0===ef.length)return void ex(null);let n=sO(e,t);ex(n),null!==n&&eN(null);},[ef.length]),eT=(0,i.useCallback)(async e=>{if(void 0!==$){ej(e.path),eN(null);try{var t,n,l;let a,r,i,s,o,c=function(e,t,n){let l=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Date.now,a=sP(n);if(0===a.length)throw Error("Select a repository file first.");let r=sT(e),i=[],s=!1,o=!1;for(let n of r){var c;let r=null!=(c=n.root)?c:e.projectPath;if("files"===n.kind&&r===t){if(s=!0,n.relativePaths.includes(a)){i.push(n);continue;}if(n.relativePaths.length>=50)throw Error(`This Files source already references ${String(50)} files.`);i.push({...n,root:t,relativePaths:[...n.relativePaths,a],connectedAtMs:l()}),o=!0;continue;}i.push(n);}return s||(i.push({kind:"files",root:t,relativePaths:[a],connectedAtMs:l()}),o=!0),{scopes:i,changed:o};}($,e.root,e.path);if(c.changed){let e=await(0,m.wi)($.id,{connectedScopes:c.scopes});T(e.chat);}let d=null!=(t=null==(n=F.current)?void 0:n.selectionStart)?t:v.length,u=null!=ey?ey:sO(v,d),p=null===u?{value:a=function(e,t){let n=`@${t}`;if(e.split(/\s+/u).includes(n))return e;let l=e.trimEnd();return 0===l.length?n:`${l} ${n}`;}(v,e.path),cursor:a.length}:(l=e.path,r=`@${l}`,i=v.slice(0,u.start),s=v.slice(u.end),o=0!==s.length&&/^[\s.,;:!?)}\]]/u.test(s)?r:`${r} `,{value:`${i}${o}${s}`,cursor:i.length+o.length});eI(t=>{var n;return n=sq(e),t.some(e=>e.id===n.id)?t:[...t,n];}),w(p.value),ex(null),requestAnimationFrame(()=>{var e,t;null==(e=F.current)||e.focus(),null==(t=F.current)||t.setSelectionRange(p.cursor,p.cursor);});}catch(e){eN(sW(e));}finally{ej(null);}}},[$,v,T,ey,w]),eF=(0,i.useCallback)(e=>{let t=eR.find(t=>t.id===e);if(void 0!==t){var n,l;let a;eI(t=>t.filter(t=>t.id!==e)),w((n=t.path,0===(a=v.replace((l=n,RegExp(`(^|\\s)@${l.replace(/[.*+?^${}()|[\]\\]/gu,"\\$&")}(?=$|\\s)`,"gu")),"$1").replace(/[ \t]{2,}/gu," ")).trim().length?"":a)),requestAnimationFrame(()=>{var e;null==(e=F.current)||e.focus();});}},[v,eR,w]),eD=(0,i.useCallback)(e=>{var t;let n=e.target.value;w(n),eA(n,null!=(t=e.target.selectionStart)?t:n.length);},[w,eA]),eM=(0,i.useCallback)(e=>{var t;if(null===ey)return;let n=e.currentTarget;eA(n.value,null!=(t=n.selectionStart)?t:n.value.length);},[ey,eA]),eP=(0,i.useCallback)(e=>{var t;if(eE){if("Escape"===e.key){e.preventDefault(),ex(null);return;}if("ArrowDown"===e.key&&e$.results.length>0){e.preventDefault(),eC(e=>Math.min(e$.results.length-1,e+1));return;}if("ArrowUp"===e.key&&e$.results.length>0){e.preventDefault(),eC(e=>Math.max(0,e-1));return;}if(("Enter"===e.key||"Tab"===e.key)&&e$.results.length>0){e.preventDefault();let n=null!=(t=e$.results[eS])?t:e$.results[0];void 0!==n&&eT(n);return;}}(e=>{!e.nativeEvent.isComposing&&("Enter"!==e.key||e.shiftKey||(e.preventDefault(),j()));})(e);},[eT,eS,eE,e$.results,j]),eL=["cmp-box",p?"cmp-box-compact":"",X.active?"cmp-box-voice-dialog":"","entering"===eu?"cmp-box-voice-dialog-entering":"","leaving"===eu?"cmp-box-voice-dialog-leaving":""].filter(Boolean).join(" ");return(0,r.jsxs)("div",{className:eL,"data-voice-aura":el.active?"on":void 0,"data-voice-aura-state":el.active?el.state:void 0,"data-voice-aura-intensity":el.active?el.intensity:void 0,children:[(0,r.jsxs)("div",{className:`cmp-input-stack${X.active?" cmp-input-stack-voice-dialog":""}`,children:[X.active?null:(0,r.jsx)(ir,{enabled:z,onFiles:O}),(0,r.jsx)("textarea",{className:"cmp-input",ref:F,rows:2,value:v,"aria-label":g("chat.messageLabel"),placeholder:d,onChange:eD,onSelect:eM,onKeyDown:eP}),!X.active&&eE?(0,r.jsxs)("div",{className:"repo-focus repo-focus-inline",children:[(0,r.jsx)("span",{className:"sr-only",role:"status","aria-live":"polite",children:null!=(a=null!=ek?ek:e$.error)?a:e$.message}),(0,r.jsx)(sK,{roots:ef,selectedRoot:ev,onRootChange:e=>{eb(e),eC(0);},search:e$,pickingPath:ew,highlightedIndex:eS,pickError:ek,onPick:e=>{eT(e);},onClose:()=>ex(null)})]}):null,X.active?null:(0,r.jsx)(sU,{references:eR,onRemove:eF}),X.active?null:(0,r.jsx)(ia,{attachments:S,onRemove:R}),X.active?null:(0,r.jsx)(io,{reason:D,mimeType:P}),X.active?null:(0,r.jsx)(sY,{status:x}),el.active?(0,r.jsx)("span",{className:"sr-only",role:"status","aria-live":"polite","aria-atomic":"true",children:sm[en]}):null,!X.active&&W?(0,r.jsx)(iE,{controller:Y,onAfterDiscard:()=>{var e;return null==(e=U.current)?void 0:e.focus();}}):null]}),(0,r.jsxs)("div",{className:`cmp-footer-row${"idle"!==eu?" cmp-footer-row-motion":""}`,children:[X.active&&"entering"===eu?(0,r.jsx)("div",{className:"cmp-composer-motion-layer cmp-composer-motion-layer-normal","aria-hidden":"true",inert:!0,children:(0,r.jsx)(s_,{session:o,ready:c,selectedModelCapability:q,onAttachFiles:O,controlsNarrow:h,barCompact:f,voiceDictationVisible:W,dictation:Y,micButtonRef:_,voiceSpeechOutputVisible:K,voiceMuted:Z.snapshot.muted,onToggleVoiceMute:Z.toggleMute,playbackButtonRef:G,voiceDialogAvailable:et,voiceDialogActive:!1,onToggleVoiceDialog:eo,voiceDialogButtonRef:J})}):null,X.active?(0,r.jsx)(sH,{voiceMuted:ec,onToggleVoiceMute:ed,playbackButtonRef:V,voiceDialogActive:X.active,onToggleVoiceDialog:eo,voiceDialogButtonRef:H,compact:h}):(0,r.jsx)(s_,{session:o,ready:c,selectedModelCapability:q,onAttachFiles:O,controlsNarrow:h,barCompact:f,voiceDictationVisible:W,dictation:Y,micButtonRef:U,voiceSpeechOutputVisible:K,voiceMuted:ec,onToggleVoiceMute:ed,playbackButtonRef:V,voiceDialogAvailable:et,voiceDialogActive:X.active,onToggleVoiceDialog:eo,voiceDialogButtonRef:H}),X.active||"leaving"!==eu?null:(0,r.jsx)("div",{className:"cmp-composer-motion-layer cmp-composer-motion-layer-voice","aria-hidden":"true",inert:!0,children:(0,r.jsx)(sH,{voiceMuted:ee.muted,onToggleVoiceMute:ed,playbackButtonRef:G,voiceDialogActive:!0,onToggleVoiceDialog:eo,voiceDialogButtonRef:J,compact:h})})]})]});}function sZ(e){let{minimal:t=!1}=e,{t:n}=ea();return t?(0,r.jsx)("div",{className:"chatw-empty chatw-empty-minimal",role:"note","aria-label":n("chat.conversationReady"),children:(0,r.jsx)("h2",{className:"chatw-empty-headline",children:n("chat.empty.headline")})}):(0,r.jsx)("div",{className:"chatw-empty",children:(0,r.jsx)("h2",{className:"chatw-empty-headline",children:n("chat.empty.headline")})});}function sQ(){let{t:e}=ea();return(0,r.jsxs)("div",{className:"chatw-empty-no-chat",children:[(0,r.jsx)("div",{className:"chatw-empty-no-chat-icon","aria-hidden":"true",children:(0,r.jsx)($.F.spark,{size:20})}),(0,r.jsx)("p",{className:"chatw-empty-no-chat-label",children:e("chat.empty.noChat.title")}),(0,r.jsx)("p",{className:"chatw-empty-no-chat-hint",children:e("chat.empty.noChat.hint")})]});}function s0(e){return(void 0!==e.connectedScopes?e.connectedScopes.length:+(void 0!==e.connectedScope))+(void 0!==e.localKnowledgeScopes?e.localKnowledgeScopes.length:+(void 0!==e.localKnowledgeScope));}function s1(e){var t,n;if(s0(e)>1)return"multi";let l=null!=(t=null==(n=e.localKnowledgeScopes)?void 0:n[0])?t:e.localKnowledgeScope;return(null==l?void 0:l.kind)==="capsule"?`capsule:${l.capsuleId}`:(null==l?void 0:l.kind)==="capsule-set"?`capsule-set:${l.capsuleSetId}`:s4(e)?"files":"none";}function s2(e){return void 0!==e.localKnowledgeScopes?e.localKnowledgeScopes:void 0!==e.localKnowledgeScope?[e.localKnowledgeScope]:[];}function s4(e){return void 0!==e&&(void 0!==e.connectedScope||void 0!==e.connectedScopes&&e.connectedScopes.length>0);}function s3(e){return s4(e)||void 0!==e&&(void 0!==e.localKnowledgeScope||void 0!==e.localKnowledgeScopes&&e.localKnowledgeScopes.length>0);}function s6(e,t){return lJ(e,t("chat.error.scopeUpdate"));}function s5(e){let{chat:t,onChatChanged:n,catalog:l,connected:a}=e,{t:s}=ea(),{capsules:o,capsuleSets:c,loadError:d}=l,[u,p]=(0,i.useState)(!1),[h,f]=(0,i.useState)(null);async function g(e){p(!0),f(null);try{if("none"===e){let e=s0(t);if(e>0&&!window.confirm(s("chat.grounding.disconnectConfirm",{count:e,sourceLabel:1===e?s("chat.grounding.sourceSingular"):s("chat.grounding.sourcePlural")})))return;let l=await(0,m.wi)(t.id,{connectedScopes:null,localKnowledgeScopes:null});n(l.chat);return;}if("files"===e){let e=await(0,m.wi)(t.id,{localKnowledgeScopes:null});n(e.chat);return;}if(e.startsWith("capsule-set:")){let l={kind:"capsule-set",capsuleSetId:e.slice(12),connectedAtMs:Date.now()},a=s2(t),r=a.some(e=>"capsule-set"===e.kind&&e.capsuleSetId===l.capsuleSetId)?a:[...a,l],i=await(0,m.wi)(t.id,{localKnowledgeScopes:r});n(i.chat);return;}if(e.startsWith("capsule:")){let l={kind:"capsule",capsuleId:e.slice(8),connectedAtMs:Date.now()},a=s2(t),r=a.some(e=>"capsule"===e.kind&&e.capsuleId===l.capsuleId)?a:[...a,l],i=await(0,m.wi)(t.id,{localKnowledgeScopes:r});n(i.chat);}}catch(e){f(s6(e,s));}finally{p(!1);}}let v=s1(t),b=function(e,t,n){let l=t.map(e=>({value:`capsule:${e.id}`,label:n("chat.grounding.capsule",{name:e.displayName})})),a=s1(e);if(!a.startsWith("capsule:")||l.some(e=>e.value===a))return l;let r=a.slice(8);return[...l,{value:a,label:n("chat.grounding.unavailable",{label:n("chat.grounding.capsule",{name:r})})}];}(t,o,s),y=function(e,t,n){let l=t.map(e=>({value:`capsule-set:${e.id}`,label:n("chat.grounding.capsuleSet",{name:e.displayName})})),a=s1(e);if(!a.startsWith("capsule-set:")||l.some(e=>e.value===a))return l;let r=a.slice(12);return[...l,{value:a,label:n("chat.grounding.unavailable",{label:n("chat.grounding.capsuleSet",{name:r})})}];}(t,c,s),x=null!=h?h:d;return(0,r.jsxs)("div",{className:"scope-grounding","data-connected":a?"true":"false",children:[(0,r.jsx)("span",{className:"scope-grounding-label mono",children:s("chat.grounding.label")}),(0,r.jsx)(ln.A,{triggerClassName:"scope-grounding-select",value:v,disabled:u,ariaLabel:s("chat.grounding.mode"),menuTitle:s("chat.grounding.strategy"),sections:[{options:[{value:"none",label:s("chat.grounding.modelOnly")},{value:"files",label:s("chat.grounding.liveFiles"),disabled:!s4(t)},...("multi"===v?[{value:"multi",label:s("chat.grounding.multiple"),disabled:!0}]:[]),...b.map(e=>({value:e.value,label:e.label})),...y.map(e=>({value:e.value,label:e.label}))]}],onValueChange:e=>{g(e);}}),null!==x?(0,r.jsx)("span",{role:"alert",className:"scope-connect-error",children:x}):null]});}function s8(e){let{chat:t,onChatChanged:n,memoryControl:l}=e,a=function(){let{t:e}=ea(),[t,n]=(0,i.useState)([]),[l,a]=(0,i.useState)([]),[r,s]=(0,i.useState)(null);return(0,i.useEffect)(()=>{let t=!1;return async function(){try{let[l,r]=await Promise.allSettled([(0,sb.xr)(),(0,sb.R3)()]);if("fulfilled"!==l.status)throw l.reason;if(t)return;n(l.value.capsules.filter(e=>"ready"===e.lifecycleState)),"fulfilled"===r.status?a(r.value.capsuleSets):(a([]),s(s6(r.reason,e)));}catch(n){t||s(s6(n,e));}}(),()=>{t=!0;};},[e]),{capsules:t,capsuleSets:l,loadError:r};}(),s=s3(t);return(0,r.jsxs)("div",{className:"chat-scope-header","data-grounded":s?"true":"false",children:[(0,r.jsx)(s5,{chat:t,onChatChanged:n,catalog:a,connected:s}),void 0!==l?(0,r.jsx)("div",{className:"chat-scope-header-actions",children:l}):null]});}function s9(e){let{chat:t,busy:n}=e;return void 0!==t&&s3(t)&&n?(0,r.jsx)("div",{className:"chatw-grounded",children:(0,r.jsx)(rD,{answer:void 0,busy:n})}):null;}function s7(e){let{action:t,acceptCandidate:n,rejectCandidate:l,forgetMemoryAction:a,onActionSettled:s}=e,{t:o}=ea(),[c,d]=(0,i.useState)(!1),[u,p]=(0,i.useState)(),[m,h]=(0,i.useState)(!1),f=(0,i.useCallback)((e,t,n)=>{c||(d(!0),p(void 0),e().then(()=>{s(t);}).catch(e=>{p(e instanceof Error?e.message:n);}).finally(()=>d(!1)));},[c,s]);if("candidate"===t.kind)return(0,r.jsxs)("article",{className:"chat-memory-action",children:[(0,r.jsxs)("div",{className:"chat-memory-action-head",children:[(0,r.jsx)("strong",{children:t.scopeLabel}),(0,r.jsx)("span",{children:t.requiresApproval?o("chat.memory.approvalRequired"):o("chat.memory.proposedMemory")})]}),(0,r.jsx)("p",{children:t.body}),(0,r.jsxs)("div",{className:"chat-memory-action-buttons",children:[(0,r.jsx)("button",{type:"button","aria-disabled":c,"aria-busy":c,onClick:()=>{f(()=>n(t.proposalId),o("chat.memory.accepted"),o("chat.memory.acceptError"));},children:o("chat.memory.accept")}),(0,r.jsx)("button",{type:"button","aria-disabled":c,"aria-busy":c,onClick:()=>{f(()=>l(t.proposalId),o("chat.memory.rejected"),o("chat.memory.rejectError"));},children:o("chat.memory.reject")})]}),void 0!==u?(0,r.jsx)(aZ,{error:u,fallback:o("chat.error.memoryUpdate"),onDismiss:()=>p(void 0)}):null]});if("update"===t.kind)return(0,r.jsxs)("article",{className:"chat-memory-action",children:[(0,r.jsxs)("div",{className:"chat-memory-action-head",children:[(0,r.jsx)("strong",{children:o("chat.memory.updateDetected")}),(0,r.jsx)("span",{children:t.memoryId})]}),(0,r.jsx)("p",{children:void 0!==t.bodyPatch?o("chat.memory.suggestedUpdate",{body:t.bodyPatch}):o("chat.memory.suggestedUpdateFallback")})]});if("forget"===t.kind){let e=()=>{f(()=>a(t.memoryId).then(()=>h(!1)),o("chat.memory.forgetCompleted"),o("chat.memory.forgetError"));};return(0,r.jsxs)("article",{className:"chat-memory-action",children:[(0,r.jsxs)("div",{className:"chat-memory-action-head",children:[(0,r.jsx)("strong",{children:o("chat.memory.forgetDetected")}),(0,r.jsx)("span",{children:t.requiresConfirmation?o("chat.memory.confirmationRequired"):t.memoryId})]}),(0,r.jsx)("p",{children:o("chat.memory.forgetMatched",{id:t.memoryId})}),(0,r.jsx)("div",{className:"chat-memory-action-buttons",children:t.requiresConfirmation?m?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{type:"button","aria-disabled":c,"aria-busy":c,onClick:e,children:o("chat.memory.forgetPermanently")}),(0,r.jsx)("button",{type:"button","aria-disabled":c,"aria-busy":c,onClick:()=>{c||(p(void 0),h(!1));},children:o("common.cancel")})]}):(0,r.jsx)("button",{type:"button","aria-disabled":c,"aria-busy":c,onClick:()=>{c||(p(void 0),h(!0));},children:o("chat.memory.reviewForget")}):(0,r.jsx)("button",{type:"button","aria-disabled":c,"aria-busy":c,onClick:e,children:o("chat.memory.forget")})}),void 0!==u?(0,r.jsx)(aZ,{error:u,fallback:o("chat.error.memoryUpdate"),onDismiss:()=>p(void 0)}):null]});}return"rejected"===t.kind?(0,r.jsxs)("article",{className:"chat-memory-action",children:[(0,r.jsx)("div",{className:"chat-memory-action-head",children:(0,r.jsx)("strong",{children:o("chat.memory.proposalDeclined")})}),(0,r.jsx)("p",{children:""!==t.reason?t.reason:o("chat.memory.noReason")})]}):(0,r.jsx)("article",{className:"chat-memory-action",children:(0,r.jsx)("div",{className:"chat-memory-action-head",children:(0,r.jsx)("strong",{children:o("chat.memory.actionNotCreated")})})});}function oe(e){let{disclosure:t}=e;return(0,r.jsxs)("button",{ref:t.disclosureButtonRef,type:"button",className:"chat-memory-disclosure-toggle ui-tip cmp-tip-end","aria-expanded":t.open,"aria-controls":t.disclosureId,"aria-label":t.memoryDisclosureLabel,"data-empty":0===t.memoryCount?"true":"false","data-tip":t.memoryDisclosureLabel,onClick:t.toggleDisclosure,children:[(0,r.jsx)($.F.brain,{size:16}),t.memoryCount>0?(0,r.jsx)("span",{className:"chat-memory-count","aria-hidden":"true",children:t.memoryCountLabel}):null]});}function ot(e){let{latestMemory:t,acceptCandidate:n,rejectCandidate:l,forgetMemoryAction:a,disclosure:i}=e,{t:s}=ea();return i.open?(0,r.jsx)("section",{className:"chat-memory-panel","aria-label":s("chat.memory.panel"),children:(0,r.jsxs)("div",{id:i.disclosureId,className:"chat-memory-disclosure",children:[(0,r.jsx)("p",{className:"chat-memory-summary",children:void 0===t?s("chat.memory.disclosurePending"):t.context.enabled?s("chat.memory.usedTokens",{used:t.context.budget.used,tokens:t.context.budget.tokens}):s("chat.memory.disabledLast")}),null==t?void 0:t.context.memories.map(e=>(0,r.jsxs)("article",{className:"chat-memory-item",children:[(0,r.jsxs)("div",{className:"chat-memory-item-head",children:[(0,r.jsx)("strong",{children:e.memoryId}),(0,r.jsx)("span",{children:e.inclusionReason})]}),(0,r.jsx)("p",{children:e.bodyExcerpt}),(0,r.jsxs)("dl",{className:"chat-memory-meta","aria-label":s("chat.memory.provenance",{id:e.memoryId}),children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:s("chat.memory.source")}),(0,r.jsx)("dd",{children:e.sourceKind})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:s("chat.memory.sensitivity")}),(0,r.jsx)("dd",{children:e.sensitivity})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:s("chat.memory.status")}),(0,r.jsx)("dd",{children:e.status})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:s("chat.memory.confidence")}),(0,r.jsx)("dd",{children:`${String(Math.round(100*e.confidence))}%`})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:s("chat.memory.captured")}),(0,r.jsx)("dd",{children:new Date(e.capturedAt).toISOString().slice(0,10)})]})]}),void 0!==e.captureRationale?(0,r.jsx)("p",{className:"chat-memory-rationale",children:e.captureRationale}):null]},e.memoryId)),null==t?void 0:t.actions.map(e=>(0,r.jsx)(s7,{action:e,acceptCandidate:n,rejectCandidate:l,forgetMemoryAction:a,onActionSettled:i.handleActionSettled},"candidate"===e.kind?e.proposalId:"rejected"===e.kind?e.reason:e.memoryId)),(0,r.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite","aria-atomic":"true",children:i.actionStatus})]})}):null;}function on(e){let{mini:t=!1,minimalChat:n=!1,compact:l=!1,controlsNarrow:a=!1,barCompact:s=!1,workflowCompact:o=!1,linkedRoot:d=null,linkedRoots:u=[],openEditorFile:p,onOpenRunResult:m}=e,{t:h}=ea(),f=c(),{messages:g,draft:v,loading:b,sending:y,sendStatus:x,error:w,noEligibleModels:j,sendMessage:k,cancelGrounded:N,activeProject:S,activeChat:C,replaceChat:R,latestMemory:I,lastSentDocuments:E,acceptMemoryCandidate:$,rejectMemoryCandidate:A,forgetMemoryAction:T}=f,F=v.trim().length>0&&!y&&!b&&!j,D=g.filter(e=>"user"===e.role||"assistant"===e.role&&e.content.length>0||id(e)),M=(0,i.useRef)(null),P=(0,i.useMemo)(()=>function(e){let t=new Set(),n=[];for(let l of e){let e=l.trim();0===e.length||t.has(e)||(t.add(e),n.push({root:e,label:rr(e)}));}return n;}(function(e){let t=sD(e.chat,e.activeProjectPath).map(e=>e.root);e.linkedRoots.length>0?t.push(...e.linkedRoots):null!==e.linkedRoot&&t.push(e.linkedRoot);let n=new Set(),l=[];for(let e of t){let t=e.trim();0===t.length||n.has(t)||(n.add(t),l.push(t));}return l.filter(e=>!l.some(t=>{let n,l;return t!==e&&(n=sM(e),l=sM(t),n.length>0&&l.length>n.length&&l.startsWith(`${n}/`));}));}({chat:C,activeProjectPath:null==S?void 0:S.path,linkedRoot:d,linkedRoots:u})),[C,null==S?void 0:S.path,d,u]),L=(0,i.useRef)(!0),q=(0,i.useRef)(!1),z=D.length>0?D[D.length-1]:void 0,O=void 0===z?"":z.content,B=l||t,W=a||t||n||o,K=s||n,U=function(e){var t;let{t:n}=ea(),[l,a]=(0,i.useState)(!1),[r,s]=(0,i.useState)(""),o=(0,i.useId)(),c=`${o}-chat-memory-disclosure`,d=(0,i.useRef)(null),u=(0,i.useCallback)(e=>{var t;s(e),null==(t=d.current)||t.focus();},[]),p=(0,i.useCallback)(()=>{a(e=>!e);},[]),m=null!=(t=null==e?void 0:e.context.memories.length)?t:0,h=m>0?n("chat.memory.included",{count:m}):n("chat.memory.noneIncluded"),f=m>99?"99+":String(m);return{open:l,actionStatus:r,disclosureId:c,disclosureButtonRef:d,memoryCount:m,memoryCountLabel:f,memoryDisclosureLabel:h,toggleDisclosure:p,handleActionSettled:u};}(I),V=(0,i.useRef)(new Map()),H=(0,i.useMemo)(()=>D.filter(e=>"user"===e.role).map((e,t)=>{let n;return{id:e.id,index:t+1,preview:(n=e.content.replace(/\s+/g," ").trim()).length<=76?n:`${n.slice(0,73).trimEnd()}...`,time:sj(e.timestamp)};}),[D]),_=(0,i.useCallback)((e,t)=>{null===t?V.current.delete(e):V.current.set(e,t);},[]),G=(0,i.useCallback)(e=>{let t=V.current.get(e);void 0!==t&&(L.current=!1,t.scrollIntoView({block:"start",behavior:"smooth"}));},[]);return(0,i.useEffect)(()=>{y&&!q.current&&(L.current=!0),q.current=y;let e=M.current;null!==e&&L.current&&(e.scrollTop=e.scrollHeight);},[D.length,y,O]),(0,r.jsxs)("div",{className:`chatw${B?" chatw-compact":""}${n?" chatw-minimal":""}`,children:[void 0!==C?(0,r.jsx)(s8,{chat:C,onChatChanged:R,memoryControl:(0,r.jsx)(oe,{disclosure:U})}):null,void 0!==C?(0,r.jsx)(ot,{latestMemory:I,acceptCandidate:$,rejectCandidate:A,forgetMemoryAction:T,disclosure:U}):null,j?(0,r.jsx)("div",{className:"chatw-foot",children:(0,r.jsx)(sG,{})}):null,b?(0,r.jsx)("div",{className:"chatw-foot",children:(0,r.jsx)(sJ,{})}):null,(0,r.jsx)("div",{className:"chatw-scroll",ref:M,role:"log","aria-label":"Conversation",tabIndex:0,onScroll:e=>{let t=e.currentTarget;L.current=t.scrollHeight-t.scrollTop-t.clientHeight<64;},children:0===D.length?void 0!==C?(0,r.jsx)(sZ,{minimal:n}):(0,r.jsx)(sQ,{}):(0,r.jsxs)("div",{className:"chatw-log-shell",children:[(0,r.jsx)(s$,{items:H,onJump:G}),(0,r.jsxs)("div",{className:"chatw-log",children:[(0,r.jsx)(sA,{messages:D,onOpenRunResult:m,repositoryRoots:P,openRepositoryReference:p,sending:y,sendStatus:x,activeChat:C,onCancelGrounded:N,registerQuestionAnchor:_}),(0,r.jsx)(s9,{chat:C,busy:y}),(0,r.jsx)(ic,{documents:E})]})]})}),D.length>0||void 0!==C?(0,r.jsx)("div",{className:"chatw-foot",children:(0,r.jsxs)("form",{className:`composer${B?" composer-chat-compact":""}`,onSubmit:e=>{e.preventDefault(),k();},children:[(0,r.jsx)(sX,{session:f,ready:F,placeholder:h(0===D.length&&b?"chat.loadingGateway":"chat.composer.placeholder"),minimal:n,compact:B,controlsNarrow:W,barCompact:K}),void 0!==w?(0,r.jsx)(aZ,{error:w,fallback:h("chat.error.send"),onDismiss:f.clearError}):null]})}):null,0===D.length&&void 0!==w&&void 0===C?(0,r.jsx)("div",{className:"chatw-foot",children:(0,r.jsx)(aZ,{error:w,fallback:"Could not load chat.",onDismiss:f.clearError})}):null]});}let ol=new Set(["ArrowDown","ArrowUp","ArrowRight","ArrowLeft","Home","End"]);function oa(e){return Array.from(e.querySelectorAll("button[role='treeitem']"));}function or(e){let{project:t,activeProjectPath:n,chats:l,activeChatId:a,onProject:s,onChat:o,treeRef:c}=e,d=n===t.path,[u,p]=(0,i.useState)(d),m=t.available?"Available":"Unavailable";return(0,i.useEffect)(()=>{d&&p(!0);},[d]),(0,r.jsxs)("div",{className:"proj",children:[(0,r.jsxs)("button",{className:"proj-head",type:"button",role:"treeitem","aria-level":1,"aria-expanded":u,"aria-selected":d,"data-active":d?"true":"false","aria-current":d?"true":void 0,"aria-label":`${t.name} (${m})`,tabIndex:d?0:-1,onClick:()=>{p(e=>!e),s(t),null!==c.current&&oa(c.current).forEach(e=>{e.tabIndex=-1;});},children:[(0,r.jsx)("span",{className:"proj-caret","data-open":u,"aria-hidden":"true",children:(0,r.jsx)($.F.chevronR,{size:13})}),(0,r.jsx)($.F.folder,{size:15,"aria-hidden":"true"}),(0,r.jsx)("span",{className:"proj-name",children:t.name}),(0,r.jsx)("span",{className:"chat-time",children:m})]}),u&&(0,r.jsx)("div",{className:"proj-chats",role:"group","aria-label":t.name,children:d?0===l.length?(0,r.jsx)("div",{className:"proj-empty",children:"No chats"}):l.map(e=>(0,r.jsxs)("button",{type:"button",role:"treeitem","aria-level":2,"aria-selected":a===e.id,className:"chat-row","data-active":a===e.id,tabIndex:-1,onClick:()=>{o(e);},children:[(0,r.jsx)("span",{className:"chat-title",children:e.title}),void 0!==e.branchLabel?(0,r.jsx)("span",{className:"chat-meta mono",children:e.branchLabel}):null]},e.id)):(0,r.jsx)("div",{className:"proj-empty",children:"Select project to load chats"})})]});}function oi(){let e=c(),t=(0,i.useRef)(null);return(0,r.jsxs)("div",{className:"tw-scroll",children:[(0,r.jsx)("div",{className:"sb-section",children:(0,r.jsx)("span",{className:"sb-section-label",children:"Projects"})}),0===e.projects.length?(0,r.jsx)("div",{className:"proj-empty",children:"No registered projects"}):(0,r.jsx)("div",{className:"proj-tree",role:"tree","aria-label":"Projects",tabIndex:-1,ref:t,onKeyDown:e=>{ol.has(e.key)&&null!==t.current&&function(e,t){var n,l,a,r,i,s,o,c,d;let u=oa(t),p=e.target;if(!(p instanceof HTMLElement))return;let m=p.closest("button[role='treeitem']");if(null===m)return;let h=u.indexOf(m);if(h<0)return;e.preventDefault();let f=e.key;if("ArrowDown"===f)null==(n=u[h+1])||n.focus();else if("ArrowUp"===f)null==(l=u[h-1])||l.focus();else if("Home"===f)null==(a=u[0])||a.focus();else if("End"===f)null==(r=u[u.length-1])||r.focus();else if("ArrowRight"===f)"false"===m.getAttribute("aria-expanded")?m.click():"true"===m.getAttribute("aria-expanded")&&(null==(i=u[h+1])||i.focus());else if("ArrowLeft"===f)if("true"===m.getAttribute("aria-expanded"))m.click();else{let e=Number(null!=(s=m.getAttribute("aria-level"))?s:"1");for(let t=h-1;t>=0;t-=1)if(Number(null!=(o=null==(c=u[t])?void 0:c.getAttribute("aria-level"))?o:"1")<e){null==(d=u[t])||d.focus();break;}}}(e,t.current);},children:e.projects.map(n=>{var l,a,i;return(0,r.jsx)(or,{project:n,activeProjectPath:null==(l=e.activeProject)?void 0:l.path,chats:(null==(a=e.activeProject)?void 0:a.path)===n.path?e.chats:[],activeChatId:null==(i=e.activeChat)?void 0:i.id,treeRef:t,onProject:t=>{e.openProject(t);},onChat:t=>{e.openChat(t);}},n.path);})})]});}function os(e){let{openChatWindow:t}=e,n=c(),[l,a]=(0,i.useState)(""),[s,o]=(0,i.useState)("active"),[d,u]=(0,i.useState)(null),[p,h]=(0,i.useState)(""),[f,g]=(0,i.useState)(null),[v,b]=(0,i.useState)(null),[y,x]=(0,i.useState)(null),[w,j]=(0,i.useState)(null),k=(0,i.useRef)(null),N=(0,i.useId)(),S=(0,i.useId)(),C=(0,i.useId)(),R=(0,i.useId)(),I=(0,i.useMemo)(()=>n.chats.filter(e=>"closed"!==e.status).length,[n.chats]),E=n.chats.length-I,A=(0,i.useMemo)(()=>[...n.chats].sort((e,t)=>t.updatedAt-e.updatedAt).filter(e=>"deleted"===s?"closed"===e.status:"closed"!==e.status).filter(e=>{var t,n;let a;return 0===(a=l.trim().toLowerCase()).length||e.title.toLowerCase().includes(a)||e.selectedModel.toLowerCase().includes(a)||null!=(t=null==(n=e.branchLabel)?void 0:n.toLowerCase().includes(a))&&t;}),[l,n.chats,s]);(0,i.useEffect)(()=>{var e;null!==d&&(null==(e=k.current)||e.focus({preventScroll:!0}));},[d]);let T=async()=>{x(null);let e=await n.openNewChat(void 0,"New chat");void 0!==e&&t(e);},F=e=>{u(e.id),h(e.title),g(null),x(null),j(null);},D=async e=>{let t=p.trim();if(0===t.length){var l;j("Title cannot be empty."),null==(l=k.current)||l.focus({preventScroll:!0});return;}if(t===e.title){u(null),j(null);return;}b(e.id),x(null),j(null);try{let l=await(0,m.wi)(e.id,{title:t});n.replaceChat(l.chat),u(null);}catch{x("Rename failed.");}finally{b(null);}},M=async e=>{b(e.id),x(null);try{let t=await(0,m.wi)(e.id,{status:"closed"});n.replaceChat(t.chat),g(null);}catch(t){let e=t instanceof Error?t.message:"Request failed.";x(`Delete failed: ${e}`);}finally{b(null);}},P=async e=>{b(e.id),x(null);try{let t=await(0,m.wi)(e.id,{status:"open"});n.replaceChat(t.chat),g(null);}catch(t){let e=t instanceof Error?t.message:"Request failed.";x(`Restore failed: ${e}`);}finally{b(null);}};return(0,r.jsxs)("div",{className:"chat-history",children:[(0,r.jsxs)("div",{className:"chat-history-head",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"chat-history-kicker",children:"Conversations"}),(0,r.jsx)("h2",{children:"Chat History"})]}),(0,r.jsxs)("button",{type:"button",className:"lk-btn lk-btn-primary",onClick:()=>void T(),children:[(0,r.jsx)($.F.newChat,{size:15}),"New"]})]}),(0,r.jsxs)("label",{className:"chat-history-search",children:[(0,r.jsx)($.F.search,{size:15}),(0,r.jsx)("input",{value:l,onChange:e=>a(e.target.value),placeholder:"Search","aria-label":"Search chat history"})]}),(0,r.jsxs)("div",{className:"chat-history-tabs",role:"tablist","aria-label":"Conversation state",children:[(0,r.jsxs)("button",{type:"button",id:N,role:"tab","aria-selected":"active"===s,"aria-controls":C,className:"chat-history-tab",onClick:()=>{o("active"),g(null);},children:["Active ",(0,r.jsx)("span",{children:I})]}),(0,r.jsxs)("button",{type:"button",id:S,role:"tab","aria-selected":"deleted"===s,"aria-controls":C,className:"chat-history-tab",onClick:()=>{o("deleted"),g(null);},children:["Deleted ",(0,r.jsx)("span",{children:E})]})]}),null!==y?(0,r.jsx)("div",{className:"lk-alert",role:"alert",children:y}):null,(0,r.jsx)("div",{id:C,className:"chat-history-list",role:"tabpanel","aria-labelledby":"active"===s?N:S,children:0===A.length?(0,r.jsx)("div",{className:"lk-empty",children:(0,r.jsx)("p",{className:"lk-empty-title",children:"No conversations"})}):A.map(e=>{var n;let l=np(e).length+nm(e).length,a=d===e.id,i=f===e.id,s=v===e.id,o="closed"===e.status;return(0,r.jsxs)("article",{className:"chat-history-row","data-chat-id":e.id,"data-state":o?"deleted":"active",children:[(0,r.jsx)("div",{className:"chat-history-row-main",children:a?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("input",{ref:k,className:"chat-history-title-input",value:p,"aria-invalid":null!==w,"aria-describedby":null!==w?R:void 0,onChange:e=>{h(e.target.value),null!==w&&j(null);},onKeyDown:t=>{"Enter"===t.key&&D(e),"Escape"===t.key&&(u(null),j(null));}}),null!==w?(0,r.jsx)("span",{id:R,className:"chat-history-rename-error",role:"alert",children:w}):null]}):(0,r.jsxs)("button",{type:"button",className:"chat-history-open",disabled:o,onClick:()=>t(e),children:[(0,r.jsx)("span",{className:"chat-history-title",children:e.title}),(0,r.jsxs)("span",{className:"chat-history-meta",children:[(n=e.updatedAt,new Intl.DateTimeFormat(void 0,{month:"short",day:"2-digit",hour:"2-digit",minute:"2-digit"}).format(new Date(n)))," / ",e.selectedModel,l>0?` / ${String(l)} sources`:""]})]})}),(0,r.jsx)("div",{className:"chat-history-actions",children:a?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-primary",disabled:s,onClick:()=>void D(e),children:"Save"}),(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost",disabled:s,onClick:()=>{u(null),j(null);},children:"Cancel"})]}):i?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-danger",disabled:s,onClick:()=>void M(e),children:"Delete"}),(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost",disabled:s,onClick:()=>g(null),children:"Cancel"})]}):o?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("button",{type:"button",className:"lk-btn lk-btn-primary",disabled:s,onClick:()=>void P(e),children:[(0,r.jsx)($.F.restore,{size:14}),"Restore"]}),(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost",onClick:()=>F(e),children:"Rename"})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost",onClick:()=>F(e),children:"Rename"}),(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost",onClick:()=>{g(e.id),u(null);},children:"Delete"})]})})]},e.id);})})]});}function oo(){var e,t;let n=d(),l=null!=(e=null==n||null==(t=n.activeProject)?void 0:t.name)?e:"No project selected",a=(0,i.useId)();return(0,r.jsxs)("div",{className:"srch",children:[(0,r.jsxs)("div",{className:"srch-box",children:[(0,r.jsx)($.F.search,{size:15,"aria-hidden":"true"}),(0,r.jsx)("input",{type:"search","aria-label":"Search files and symbols","aria-describedby":a,placeholder:"Search files & symbols…",disabled:!0})]}),(0,r.jsxs)("div",{className:"tw-label srch-label",children:[l," ",(0,r.jsx)("span",{className:"srch-meta mono",children:"workspace search"})]}),(0,r.jsxs)("div",{className:"tw-pad",children:[(0,r.jsxs)("div",{className:"rb-placeholder",style:{height:150},children:[(0,r.jsx)("div",{className:"ph-stripes"}),(0,r.jsx)("span",{className:"rb-ph-label mono",children:"search"})]}),(0,r.jsx)("div",{id:a,className:"rb-foot mono",style:{marginTop:14},children:"Search across workspace files & symbols — coming soon."})]})]});}let oc="connectedSourcesJson";function od(e,t){let n=e[t];return"string"==typeof n?n:void 0;}function ou(e,t){return"string"==typeof e[t];}function op(e){if(!("object"==typeof e&&null!==e&&!Array.isArray(e))||!ou(e,"label"))return!1;switch(e.kind){case"file":case"workspace":return ou(e,"path");case"capsule":return ou(e,"capsuleId");case"capsule-set":return ou(e,"capsuleSetId");case"figma-snapshot":let t;return ou(e,"snapshotRunId")&&(void 0===(t=e.screenIds)||Array.isArray(t)&&t.length>0&&t.every(e=>"string"==typeof e&&e.trim().length>0));case"image":return"figma-snapshot-screen"===e.sourceKind&&ou(e,"snapshotRunId")&&ou(e,"screenId");default:return!1;}}function om(e){return e.length>0?{[oc]:JSON.stringify(e)}:{};}function oh(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 of(e){return e.replaceAll("\\","/");}function og(e){if(/^[A-Za-z]:[/\\]?$/u.test(e))return e.replaceAll("\\","/");if(/^\/\/[^/]+\/[^/]+$/u.test(of(e)))return of(e);let t=of(e).replace(/\/+$/u,"");return 0===t.length&&e.length>0?"/":t;}function ov(e){var t,n,l,a,r,i;let s=null!=(t=e.connectedRoot)?t:null,o=function(e,t){var n,l;let a=null!=(n=null==t?void 0:t.trim())?n:"";if(0===a.length)return null;if(a.startsWith("/")||/^[A-Za-z]:[/\\]/u.test(a)||a.startsWith("\\\\")||a.startsWith("//"))return a;let r=null!=(l=null==e?void 0:e.trim())?l:"";if(0===r.length)return null;let i=og(r),s=of(a).replace(/^\/+/u,""),o=i.endsWith("/")?"":"/";return`${i}${o}${s}`;}(s,null!=(n=e.connectedFilePath)?n:null),c=null!==s?og(s):null,d=(void 0!==e.connectedRoots&&null!==e.connectedRoots&&e.connectedRoots.length>0?e.connectedRoots:null!==s?[s]:[]).map(og),u=null!==o?d.filter(e=>e!==c):d,p=[];for(let e of(null!==o&&p.push({kind:"file",label:oh(o),path:o}),u))p.push({kind:"workspace",label:oh(e),path:e});for(let t of null!=(l=e.connectedCapsuleIds)?l:[])p.push({kind:"capsule",label:t,capsuleId:t});for(let t of null!=(a=e.connectedCapsuleSetIds)?a:[])p.push({kind:"capsule-set",label:t,capsuleSetId:t});for(let t of void 0!==e.connectedFigmaSnapshotSources?e.connectedFigmaSnapshotSources:(null!=(r=e.connectedFigmaSnapshotRunIds)?r:[]).map(e=>({kind:"figma-snapshot",label:e,snapshotRunId:e})))p.push(t);for(let t of null!=(i=e.connectedImageSources)?i:[])p.push(t);let m=new Set(),h=[];for(let e of p){if(h.length>=16)break;let t=function(e){switch(e.kind){case"file":case"workspace":return`${e.kind}:${e.path}`;case"capsule":return`capsule:${e.capsuleId}`;case"capsule-set":return`capsule-set:${e.capsuleSetId}`;case"figma-snapshot":{let t=e.screenIds,n=void 0===t||0===t.length?"*":[...new Set(t.map(e=>e.trim()).filter(e=>e.length>0))].sort().join(",");return`figma-snapshot:${e.snapshotRunId}:${n}`;}case"image":return`image:${e.sourceKind}:${e.snapshotRunId}:${e.screenId}`;}}(e);m.has(t)||(m.add(t),h.push(e));}return h;}let ob=[{value:"auto",label:"Auto (recommended)"},{value:"fast",label:"Fast"},{value:"precise",label:"Precise"},{value:"research",label:"Research"},{value:"creative",label:"Creative"},{value:"technical",label:"Technical"},{value:"safety-critical",label:"Safety-critical"},{value:"agentic",label:"Agentic"}],oy=[{value:"clarify",label:"Ask clarifying questions"},{value:"assume",label:"State explicit assumptions"}],ox="__none__";function ow(e){return e.replaceAll("-"," ");}async function oj(e){var t;let n="u"<typeof navigator||null==(t=navigator.clipboard)?void 0:t.writeText;if(void 0!==n&&void 0!==navigator.clipboard)try{await n.call(navigator.clipboard,e);return;}catch{}if("u"<typeof document||null===document.body)throw Error("clipboard-unavailable");let l=document.activeElement instanceof HTMLElement?document.activeElement:null,a=document.createElement("textarea");a.value=e,a.setAttribute("readonly","true"),a.style.position="fixed",a.style.inset="0 auto auto -9999px",a.style.width="1px",a.style.height="1px",a.style.opacity="0",document.body.appendChild(a);try{if(a.focus(),a.select(),!("function"==typeof document.execCommand&&document.execCommand("copy")))throw Error("clipboard-fallback-failed");}finally{a.remove(),null==l||l.focus();}}function ok(e){let{items:t,empty:n}=e;return 0===t.length?void 0===n?null:(0,r.jsx)("p",{className:"pe-empty",children:n}):(0,r.jsx)("ul",{className:"pe-list",children:t.map((e,t)=>(0,r.jsx)("li",{children:e},`${String(t)}:${e.slice(0,24)}`))});}function oN(e){let{title:t,children:n}=e;return(0,r.jsxs)("section",{className:"pe-section","aria-label":t,children:[(0,r.jsx)("h4",{className:"pe-section-title",children:t}),n]});}function oS(e){let{result:t}=e,n=[["Task",ow(t.analysis.taskClass)],["Domain",ow(t.analysis.domain)],["Criticality",ow(t.analysis.criticality)],["Profile",ow(t.analysis.recommendedProfile)],["Input",`${t.analysis.normalizedInputLength.toLocaleString("en-US")} chars`]];return(0,r.jsx)("dl",{className:"pe-analysis","aria-label":"Prompt enhancement analysis",children:n.map(e=>{let[t,n]=e;return(0,r.jsxs)("div",{className:"pe-analysis-item",children:[(0,r.jsx)("dt",{children:t}),(0,r.jsx)("dd",{children:n})]},t);})});}function oC(e){var t;let{routing:n}=e,l="available"===n.availability?"ok":"unavailable"===n.availability?"warn":"muted",a="available"===n.availability?`Model ready: ${null!=(t=n.resolvedModelId)?t:""}`:"unavailable"===n.availability?"Selected model unavailable - enhancement still completed deterministically":"No downstream model selected - enhancement is provider-neutral";return(0,r.jsxs)("div",{className:`pe-routing pe-routing-${l}`,"data-testid":"pe-model-routing",role:"status","aria-live":"polite",children:[(0,r.jsx)("span",{className:"pe-routing-icon","aria-hidden":"true",children:"ok"===l?(0,r.jsx)($.F.check,{size:14}):(0,r.jsx)($.F.info,{size:14})}),(0,r.jsx)("span",{children:a})]});}function oR(e){let{safety:t}=e,n=t.requiresHumanReview;return(0,r.jsxs)(oN,{title:"Safety",children:[(0,r.jsxs)("dl",{className:"pe-safety-summary","data-testid":"pe-safety-decision",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:"Decision:"}),(0,r.jsx)("dd",{children:ow(t.decision)})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:"Verification:"}),(0,r.jsx)("dd",{children:ow(t.verificationStatus)})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:"Human review:"}),(0,r.jsx)("dd",{children:n?"required":"not required"})]})]}),n?(0,r.jsx)("p",{className:"pe-safety-warning",role:"alert",children:"This prompt requires human review before any downstream use."}):null,t.findings.length>0?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("h5",{className:"pe-subhead",children:"Safety findings"}),(0,r.jsx)("ul",{className:"pe-list","data-testid":"pe-safety-findings",children:t.findings.map(e=>(0,r.jsxs)("li",{children:[(0,r.jsx)("span",{className:`pe-sev pe-sev-${e.severity}`,children:e.severity})," ",e.detail]},`${e.ruleId}:${e.code}`))})]}):null,t.leastPrivilege.length>0?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("h5",{className:"pe-subhead",children:"Least-privilege constraints"}),(0,r.jsx)(ok,{items:[...t.leastPrivilege]})]}):null]});}function oI(e){let{plan:t,readiness:n}=e,l="ready"===n.status?"Grounding readiness: connected context available":"unavailable"===n.status?"Grounding readiness: unavailable - connect a Files window and regenerate to mark this prompt grounding-ready.":"Grounding readiness: not required";return(0,r.jsxs)(oN,{title:"Grounding plan",children:[(0,r.jsxs)("div",{className:`pe-grounding-readiness pe-grounding-readiness-${n.status}`,"data-testid":"pe-grounding-readiness",role:"status","aria-live":"polite",children:[(0,r.jsx)("span",{className:"pe-routing-icon","aria-hidden":"true",children:(0,r.jsx)($.F.info,{size:14})}),(0,r.jsx)("span",{children:l})]}),(0,r.jsxs)("p",{className:"pe-grounding-meta",children:["Strategy: ",(0,r.jsx)("strong",{children:ow(t.strategy)})," /"," ",t.required?"required":"optional"," / citations:"," ",ow(t.citation.discipline)," (",ow(t.citation.granularity),")"]}),t.sourcePriority.length>0?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("h5",{className:"pe-subhead",children:"Source priority"}),(0,r.jsx)("ol",{className:"pe-list",children:t.sourcePriority.map(e=>(0,r.jsxs)("li",{children:[e.source,e.required?" (required)":""]},e.source))})]}):null,(0,r.jsx)(ok,{items:[...t.directives]})]});}function oE(e){var t;let{evidence:n,fingerprint:l}=e;return(0,r.jsxs)("p",{className:"pe-evidence","data-testid":"pe-evidence",children:["Evidence fingerprint: ",l.slice(0,16),"...","recorded"===n.status&&void 0!==n.runId?(0,r.jsxs)(r.Fragment,{children:[" ","Manifest:"," ",(0,r.jsx)("a",{href:null!=(t=n.manifestUrl)?t:"#",target:"_blank",rel:"noreferrer","aria-label":`Prompt enhancement evidence manifest ${n.runId}`,children:n.runId})]}):" Manifest not recorded."]});}function o$(e){let{candidates:t}=e;return(0,r.jsx)(oN,{title:"Candidate scorecards",children:(0,r.jsx)("div",{className:"c-tablewrap",children:(0,r.jsx)("div",{className:"c-tablescroll",children:(0,r.jsxs)("table",{className:"c-table responsive pe-scorecards","data-testid":"pe-scorecards",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{children:[(0,r.jsx)("th",{scope:"col",children:"Profile"}),(0,r.jsx)("th",{scope:"col",className:"num",children:"Score"}),(0,r.jsx)("th",{scope:"col",className:"num",children:"Tokens"}),(0,r.jsx)("th",{scope:"col",children:"Winner"})]})}),(0,r.jsx)("tbody",{children:t.scorecards.map(e=>{let n=e.candidateId===t.winnerCandidateId;return(0,r.jsxs)("tr",{className:n?"pe-winner":void 0,"aria-selected":n?"true":void 0,children:[(0,r.jsx)("th",{scope:"row",children:e.profile}),(0,r.jsx)("td",{className:"num","data-label":"Score",children:e.aggregateScore.toFixed(3)}),(0,r.jsx)("td",{className:"num","data-label":"Tokens",children:e.estimatedTokens.toLocaleString("en-US")}),(0,r.jsx)("td",{"data-label":"Winner",children:n?(0,r.jsx)("span",{className:"pe-winner-mark","aria-label":"Winner",children:"★"}):(0,r.jsx)("span",{"aria-hidden":"true",children:"-"})})]},e.candidateId);})})]})})})});}function oA(e){let{result:t}=e,n=t.enhancedPrompt,l=t.analysis.missingContext.map(e=>"assumption"===e.kind?e.statement:e.question);return(0,r.jsxs)("div",{className:"pe-section-grid",children:[(0,r.jsx)(oN,{title:"Role",children:(0,r.jsx)("p",{children:n.role})}),(0,r.jsx)(oN,{title:"Objective",children:(0,r.jsx)("p",{children:n.goal})}),(0,r.jsx)(oN,{title:"Context",children:(0,r.jsx)(ok,{items:[...n.context],empty:"No additional context."})}),(0,r.jsx)(oN,{title:t.analysis.missingContext.some(e=>"assumption"===e.kind)?"Assumptions":"Clarification questions",children:(0,r.jsx)(ok,{items:l,empty:"No clarifications or assumptions needed."})}),(0,r.jsx)(oN,{title:"Steps",children:(0,r.jsx)(ok,{items:[...n.taskDecomposition]})}),(0,r.jsx)(oN,{title:"Constraints",children:(0,r.jsx)(ok,{items:[...n.constraints]})}),(0,r.jsxs)(oN,{title:"Output schema",children:[(0,r.jsxs)("p",{children:["Format: ",(0,r.jsx)("strong",{children:n.outputSchema.format}),n.outputSchema.structured?" / structured":""]}),(0,r.jsx)(ok,{items:[...n.outputSchema.hints]})]}),(0,r.jsx)(oN,{title:"Quality criteria",children:(0,r.jsx)(ok,{items:[...n.qualityCriteria]})}),(0,r.jsx)(oN,{title:"Uncertainty handling",children:(0,r.jsx)(ok,{items:[...n.uncertaintyHandling]})}),(0,r.jsx)(oN,{title:"Safety rules",children:(0,r.jsx)(ok,{items:[...n.safetyRules]})})]});}function oT(){let{connectedRoot:e=null,connectedFilePath:t=null,connectedRoots:n,enhanceImpl:l=m.fG,fetchModelsImpl:a=m.ZC}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},[s,o]=(0,i.useState)(""),[c,d]=(0,i.useState)("auto"),[u,p]=(0,i.useState)("clarify"),[h,f]=(0,i.useState)(ox),[g,v]=(0,i.useState)([]),[b,y]=(0,i.useState)(null),[x,w]=(0,i.useState)(null),[j,k]=(0,i.useState)(!1),[N,S]=(0,i.useState)(null),[C,R]=(0,i.useState)("idle"),[I,E]=(0,i.useState)(null),A=(0,i.useRef)(null),T=(0,i.useRef)(null),F=(0,i.useId)(),D=(0,i.useId)(),M=(0,i.useId)();(0,i.useEffect)(()=>{let e=!1;return a().then(t=>{e||v(t.models.filter(e=>"chat"===e.kind));}).catch(()=>{}),()=>{e=!0;};},[a]),(0,i.useEffect)(()=>()=>{var e;null==(e=T.current)||e.abort();},[]);let P=(0,i.useMemo)(()=>function(e){var t;let{connectedRoot:n,connectedFilePath:l,connectedRoots:a}=e,r=ov({connectedRoot:null!=n?n:null,connectedFilePath:null!=l?l:null,connectedRoots:a});if(0===r.length)return{hasConnectedContext:!1,attachmentCount:0,label:"No connected Files source",signature:"none"};let i=r.map(e=>e.label),s=1===i.length?null!=(t=i[0])?t:"Connected source":`${i.length.toString()} connected sources`;return{hasConnectedContext:!0,attachmentCount:r.length,label:s,signature:JSON.stringify(r)};}({connectedRoot:e,connectedFilePath:t,connectedRoots:n}),[e,t,n]);(0,i.useEffect)(()=>{if("copied"!==C)return;let e=window.setTimeout(()=>{R("idle"),E(null);},3e3);return()=>{window.clearTimeout(e);};},[C]);let L=(0,i.useCallback)(async()=>{var e;let t=s.trim();if(0===t.length)return void S("Enter a prompt draft to enhance.");null==(e=T.current)||e.abort();let n=new AbortController();T.current=n,k(!0),S(null),R("idle"),E(null);let a={text:t,missingInformationStrategy:"assume"===u?"assume":"clarify",...(P.hasConnectedContext?{hasConnectedContext:!0,attachmentCount:P.attachmentCount}:{}),...("auto"===c?{}:{profilePreference:c}),...(h===ox?{}:{modelId:h})};try{let e=await l(a,n.signal);n.signal.aborted||(y(e),w(P.signature));}catch(e){n.signal.aborted||S(e instanceof m.hD?`${e.message} (${e.code})`:e instanceof Error&&"AbortError"===e.name?"Request cancelled.":"Prompt enhancement failed. Please try again.");}finally{n.signal.aborted||k(!1);}},[s,u,P,c,h,l]),q=(0,i.useCallback)(async()=>{if(null!==b){S(null),R("copying"),E("Copying rendered prompt...");try{await oj(b.renderedPrompt),R("copied"),E("Copied to clipboard.");}catch{R("failed"),E("Clipboard access failed. Select text manually and use Cmd/Ctrl+C.");}}},[b]),z=(0,i.useCallback)(()=>{var e,t;null==(e=T.current)||e.abort(),T.current=null,o(""),y(null),w(null),k(!1),S(null),R("idle"),E(null),null==(t=A.current)||t.focus();},[]),O=[{options:[{value:ox,label:"Deterministic only (no model)"},...g.map(e=>({value:e.id,label:e.id}))]}],B=s.trim().length,W=B>0||null!==b||j||null!==N||"idle"!==C||null!==I,K=null!==b&&null!==x&&x!==P.signature;return(0,r.jsxs)("div",{className:"pe-panel","data-testid":"prompt-enhancer-panel",children:[(0,r.jsxs)("div",{className:"pe-header","data-testid":"pe-header",children:[(0,r.jsx)("span",{className:"pe-header-icon","aria-hidden":"true",children:(0,r.jsx)($.F.spark,{size:18})}),(0,r.jsxs)("div",{className:"pe-header-copy",children:[(0,r.jsx)("p",{className:"pe-eyebrow",children:"Governed prompt workspace"}),(0,r.jsx)("h3",{className:"pe-title",children:"Prompt Enhancer"})]}),(0,r.jsx)("span",{className:"pe-header-chip",children:"No execution"})]}),(0,r.jsxs)("form",{className:"pe-form",onSubmit:e=>{e.preventDefault(),L();},children:[(0,r.jsxs)("div",{className:"pe-draft-card",children:[(0,r.jsxs)("div",{className:"pe-field-head",children:[(0,r.jsx)("label",{className:"pe-label",htmlFor:F,children:"Raw prompt"}),(0,r.jsxs)("span",{className:"pe-counter",id:D,children:[B.toLocaleString("en-US")," chars"]})]}),(0,r.jsx)("textarea",{ref:A,id:F,className:"pe-draft",value:s,onChange:e=>{o(e.target.value);},rows:8,placeholder:"Describe the task you want a strong prompt for...","aria-describedby":null===N?D:`${D} ${M}`})]}),(0,r.jsxs)("aside",{className:"pe-controls-card","aria-label":"Enhancement controls",children:[(0,r.jsxs)("div",{className:"pe-controls",children:[(0,r.jsxs)("div",{className:"pe-control",children:[(0,r.jsx)("span",{className:"pe-label","aria-hidden":"true",children:"Profile"}),(0,r.jsx)(ln.A,{value:c,ariaLabel:"Profile",onValueChange:d,sections:[{options:ob.map(e=>({...e}))}],triggerClassName:"pe-select",menuClassName:"pe-select-menu"})]}),(0,r.jsxs)("div",{className:"pe-control",children:[(0,r.jsx)("span",{className:"pe-label","aria-hidden":"true",children:"Missing information"}),(0,r.jsx)(ln.A,{value:u,ariaLabel:"Missing information",onValueChange:p,sections:[{options:oy.map(e=>({...e}))}],triggerClassName:"pe-select",menuClassName:"pe-select-menu"})]}),(0,r.jsxs)("div",{className:"pe-control",children:[(0,r.jsx)("span",{className:"pe-label","aria-hidden":"true",children:"Readiness model"}),(0,r.jsx)(ln.A,{value:h,ariaLabel:"Readiness model",onValueChange:f,sections:O,triggerClassName:"pe-select",menuClassName:"pe-select-menu"})]})]}),(0,r.jsxs)("div",{className:"pe-grounding-context","data-connected":P.hasConnectedContext?"true":"false","data-testid":"pe-grounding-context",children:[(0,r.jsx)("span",{className:"pe-routing-icon","aria-hidden":"true",children:(0,r.jsx)($.F.layers,{size:14})}),(0,r.jsxs)("span",{children:[(0,r.jsx)("span",{className:"pe-context-label",children:"Grounding context"}),(0,r.jsx)("strong",{children:P.label})]})]}),K?(0,r.jsx)("p",{className:"pe-context-stale",role:"status","aria-live":"polite",children:"Grounding context changed. Regenerate to update this review artifact."}):null,(0,r.jsxs)("div",{className:"pe-command-row",children:[(0,r.jsxs)("button",{type:"submit",className:"pe-button pe-button-primary pe-enhance",disabled:j||0===B,children:[(0,r.jsx)($.F.spark,{size:15}),(0,r.jsx)("span",{children:j?"Enhancing...":"Enhance prompt"})]}),(0,r.jsxs)("button",{type:"button",className:"pe-button pe-button-secondary pe-clear",onClick:z,disabled:!W,"aria-label":"Clear prompt workspace",children:[(0,r.jsx)($.F.reset,{size:15}),(0,r.jsx)("span",{children:"Clear"})]})]}),(0,r.jsx)("p",{className:"pe-status",role:"status","aria-live":"polite",children:j?"Enhancing prompt...":0===B?"Waiting for draft":"Ready"})]})]}),null!==N?(0,r.jsx)("p",{className:"pe-error",role:"alert",id:M,children:N}):null,null!==b?(0,r.jsxs)("div",{className:"pe-result","data-testid":"pe-result",children:[(0,r.jsxs)("div",{className:"pe-result-head",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"pe-eyebrow",children:"Review artifact"}),(0,r.jsx)("h4",{className:"pe-result-title",children:"Enhanced prompt"})]}),(0,r.jsx)(oC,{routing:b.modelRouting})]}),(0,r.jsx)(oS,{result:b}),(0,r.jsxs)(oN,{title:"Rendered prompt",children:[(0,r.jsx)("pre",{className:"pe-rendered","aria-label":"Rendered prompt text","data-text-selectable":"true",children:b.renderedPrompt}),(0,r.jsxs)("div",{className:"pe-actions",children:[null!==I?(0,r.jsx)("p",{className:`pe-copy-status pe-copy-status-${C}`,role:"failed"===C?"alert":"status","aria-live":"polite",children:I}):null,(0,r.jsxs)("button",{type:"button",className:"pe-button pe-button-secondary pe-copy",disabled:"copying"===C,onClick:()=>{q();},children:[(0,r.jsx)($.F.file,{size:15}),(0,r.jsx)("span",{children:"copying"===C?"Copying...":"Copy rendered prompt"})]})]})]}),(0,r.jsxs)("div",{className:"pe-review-grid",children:[(0,r.jsx)(oR,{safety:b.safety}),(0,r.jsx)(oI,{plan:b.enhancedPrompt.groundingPlan,readiness:b.groundingReadiness})]}),(0,r.jsx)(oA,{result:b}),(0,r.jsx)(o$,{candidates:b.candidates}),(0,r.jsx)(oE,{evidence:b.evidence,fingerprint:b.inputFingerprintSha256})]}):(0,r.jsxs)("div",{className:"pe-empty-state","aria-label":"Prompt enhancement empty state",children:[(0,r.jsx)($.F.layers,{size:18}),(0,r.jsx)("span",{children:"No enhanced prompt yet."})]})]});}let oF=[{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}],oD=[{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 oM(e){let{img:t,icon:n,glyph:l}=e;if(void 0!==t)return(0,r.jsx)("img",{className:"pl-img",src:`/assets/icons/${t}.svg`,width:"20",height:"20",alt:""});if(void 0!==n){let e=$.F[n];return(0,r.jsx)("span",{className:"pl-line",children:(0,r.jsx)(e,{size:18})});}return(0,r.jsx)("span",{className:"mono pl-glyph",children:l});}function oP(){let[e,t]=(0,i.useState)(oF.map(e=>e.on)),n=e.filter(Boolean).length;return(0,r.jsxs)("div",{className:"plg",children:[(0,r.jsxs)("div",{className:"plg-sec",children:[(0,r.jsx)("span",{className:"plg-sec-t",children:"MCP Servers"}),(0,r.jsxs)("span",{className:"plg-sec-c mono",children:[n,"/",oF.length," active"]})]}),oF.map((n,l)=>{var a;let i=null!=(a=e[l])&&a;return(0,r.jsxs)("div",{className:"plg-row",children:[(0,r.jsx)("span",{className:"plg-ico",children:(0,r.jsx)(oM,{img:n.img,icon:n.icon})}),(0,r.jsxs)("span",{className:"plg-text",children:[(0,r.jsx)("span",{className:"plg-name",children:n.name}),(0,r.jsx)("span",{className:"plg-desc",children:n.desc})]}),(0,r.jsx)("button",{className:`plg-dot${i?" on":""}`,title:i?"Running":"Stopped","aria-label":`${n.name}: ${i?"running":"stopped"}`,onClick:()=>{t(e=>{var t;let n=[...e];return n[l]=!(null!=(t=n[l])&&t),n;});}})]},n.name);}),(0,r.jsx)("div",{className:"plg-sec plg-sec2",children:(0,r.jsx)("span",{className:"plg-sec-t",children:"Connectors"})}),oD.map(e=>(0,r.jsxs)("button",{className:"plg-row plg-conn","data-on":e.on,children:[(0,r.jsx)("span",{className:"plg-ico",children:(0,r.jsx)(oM,{img:e.img})}),(0,r.jsxs)("span",{className:"plg-text",children:[(0,r.jsx)("span",{className:"plg-name",children:e.name}),(0,r.jsx)("span",{className:"plg-desc",children:e.on?"Connected":"Not connected"})]}),e.on?(0,r.jsx)("span",{className:"integ-on",children:(0,r.jsx)($.F.check,{size:13})}):(0,r.jsx)("span",{className:"integ-add",children:(0,r.jsx)($.F.plus,{size:14})})]},e.name))]});}function oL(e){let{on:t,onChange:n,label:l}=e;return(0,r.jsx)("button",{type:"button",role:"switch","aria-checked":t,"aria-label":l,className:`auto-toggle${t?" on":""}`,onClick:()=>{n(!t);},children:(0,r.jsx)("span",{})});}let oq=[{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}],oz="keiko.automations.v1",oO=Object.fromEntries(oq.map(e=>[e.id,e.defaultOn]));function oB(){try{let e=localStorage.getItem(oz);if(null===e)return{...oO};let t=JSON.parse(e);if("object"!=typeof t||null===t||Array.isArray(t))return{...oO};let n={...oO};for(let[e,l]of Object.entries(t))e in oO&&"boolean"==typeof l&&(n[e]=l);return n;}catch{return{...oO};}}function oW(){let[e,t]=(0,i.useState)(oB);return(0,r.jsx)("div",{className:"tw-list",children:oq.map(n=>{var l;let a=null!=(l=e[n.id])?l:n.defaultOn;return(0,r.jsxs)("div",{className:"auto-row",children:[(0,r.jsx)("span",{className:"dot",style:{background:a?"var(--accent)":"var(--fg-faint)"}}),(0,r.jsxs)("span",{className:"auto-text",children:[(0,r.jsx)("span",{className:"auto-name",children:n.name}),(0,r.jsx)("span",{className:"auto-when mono",children:n.when})]}),(0,r.jsx)(oL,{on:a,onChange:()=>{var e;e=n.id,t(t=>{var n;let l={...t,[e]:!(null!=(n=t[e])&&n)};try{localStorage.setItem(oz,JSON.stringify(l));}catch{}return l;});},label:n.name})]},n.id);})});}function oK(){return(0,r.jsxs)("div",{className:"tw-pad mob",children:[(0,r.jsxs)("div",{className:"mob-qr",children:[(0,r.jsx)("div",{className:"ph-stripes"}),(0,r.jsx)($.F.mobile,{size:28,style:{position:"relative",color:"var(--fg-dim)"}})]}),(0,r.jsx)("div",{className:"mob-title",children:"Keiko Mobile"}),(0,r.jsx)("div",{className:"mob-sub",children:"Scan to continue this workspace on your phone."})]});}function oU(){var e;let t,{wins:n,active:l,winCount:a}=(0,i.useContext)(Y),s=null!==l?ed[l.type]:null,o=null!==l?Object.entries(l.cfg).filter(e=>{let[,t]=e;return""!==t&&null!=t;}):[];return(0,r.jsxs)("div",{className:"tw-pad",children:[(0,r.jsx)("div",{className:"rb-section-label",style:{marginTop:0},children:"Active window"}),null!==l&&null!==s?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"insp-top",children:[(0,r.jsx)("span",{className:"insp-ico",style:{color:!0===s.accent?"var(--accent)":"var(--fg-muted)"},children:(e=s.icon,t=$.F[e],(0,r.jsx)(t,{size:16}))}),(0,r.jsx)("span",{className:"insp-title",children:s.title})]}),(0,r.jsxs)("div",{className:"rb-rows",children:[(0,r.jsxs)("div",{className:"rb-row",children:[(0,r.jsx)("span",{className:"rb-row-k",children:"Size"}),(0,r.jsxs)("span",{className:"rb-row-v mono",children:[Math.round(l.w)," \xd7 ",Math.round(l.h)]})]}),(0,r.jsxs)("div",{className:"rb-row",children:[(0,r.jsx)("span",{className:"rb-row-k",children:"Position"}),(0,r.jsxs)("span",{className:"rb-row-v mono",children:[Math.round(l.x),", ",Math.round(l.y)]})]}),(0,r.jsxs)("div",{className:"rb-row",children:[(0,r.jsx)("span",{className:"rb-row-k",children:"State"}),(0,r.jsx)("span",{className:"rb-row-v mono",children:l.max?"maximized":"floating"})]})]}),o.length>0&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"rb-section-label",children:"Configuration"}),(0,r.jsx)("div",{className:"rb-rows",children:o.map(e=>{let[t,n]=e;return(0,r.jsxs)("div",{className:"rb-row",children:[(0,r.jsx)("span",{className:"rb-row-k",children:t}),(0,r.jsx)("span",{className:"rb-row-v mono",children:String(n).slice(0,20)||"—"})]},t);})})]}),(0,r.jsx)("div",{className:"rb-section-label insp-governance",children:"Governance"}),(0,r.jsxs)("div",{className:"rb-rows insp-governance","data-testid":"insp-governance",children:[(0,r.jsxs)("div",{className:"rb-row",children:[(0,r.jsx)("span",{className:"rb-row-k",children:"Authority"}),(0,r.jsx)("span",{className:"rb-row-v mono",children:tp[l.type].authority})]}),(0,r.jsxs)("div",{className:"rb-row",children:[(0,r.jsx)("span",{className:"rb-row-k",children:"Persistence"}),(0,r.jsx)("span",{className:"rb-row-v mono",children:tp[l.type].persistence})]}),(0,r.jsxs)("div",{className:"rb-row",children:[(0,r.jsx)("span",{className:"rb-row-k",children:"Trust"}),(0,r.jsx)("span",{className:"rb-row-v mono",children:tp[l.type].trustBoundary.join(", ")})]}),(0,r.jsxs)("div",{className:"rb-row",children:[(0,r.jsx)("span",{className:"rb-row-k",children:"Lifecycle"}),(0,r.jsx)("span",{className:"rb-row-v mono",children:tp[l.type].lifecycle.join(" → ")})]})]})]}):(0,r.jsx)("div",{className:"insp-empty",children:"No window focused"}),(0,r.jsx)("div",{className:"rb-section-label",children:"Workspace"}),(0,r.jsx)("div",{className:"rb-rows",children:(0,r.jsxs)("div",{className:"rb-row",children:[(0,r.jsx)("span",{className:"rb-row-k",children:"Open windows"}),(0,r.jsx)("span",{className:"rb-row-v mono",children:a})]})})]});}let oV=[{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 oH(){return(0,r.jsx)("ul",{className:"tw-list",children:oV.map((e,t)=>(0,r.jsxs)("li",{className:"nt-row",children:[(0,r.jsx)("span",{className:"dot",style:{background:e.c,marginTop:6},"aria-hidden":"true"}),(0,r.jsxs)("span",{className:"nt-text",children:[(0,r.jsx)("span",{className:"nt-title",children:e.t}),(0,r.jsxs)("span",{className:"nt-time mono",children:[e.time," ago"]})]})]},t))});}function o_(){return(0,r.jsxs)("div",{className:"tw-pad",children:[(0,r.jsxs)("div",{className:"rb-placeholder",style:{height:150},children:[(0,r.jsx)("div",{className:"ph-stripes"}),(0,r.jsx)("span",{className:"rb-ph-label mono",children:"resources"})]}),(0,r.jsx)("div",{className:"rb-foot mono",style:{marginTop:14},children:"Shared assets & references — coming soon."})]});}let oG="keiko-activity",oJ={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 oY(){let e=function(){var e;let[,t]=(0,i.useState)(0);return(0,i.useEffect)(()=>{let e=()=>{t(e=>e+1);};return window.addEventListener(oG,e),()=>{window.removeEventListener(oG,e);};},[]),null!=(e=window.__keikoActivity)?e:[];}();return(0,r.jsxs)("div",{className:"tl",role:"log","aria-label":"Activity timeline",children:[0===e.length&&(0,r.jsxs)("div",{className:"tl-empty",children:["No activity yet.",(0,r.jsx)("br",{}),"Start an agent to see its actions stream here."]}),e.map((e,t)=>{var n,l;return(0,r.jsxs)("div",{className:"tl-row",children:[(0,r.jsx)("span",{className:"tl-dot","aria-hidden":"true",style:{background:null!=(n=oJ[e.type])?n:"var(--fg-faint)"}}),(0,r.jsxs)("div",{className:"tl-body",children:[(0,r.jsx)("span",{className:"visually-hidden",children:e.type}),(0,r.jsx)("span",{className:"tl-text",children:e.text}),(0,r.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);})]});}let oX={docx:"DOCX",xlsx:"XLSX",pdf:"PDF"};function oZ(e){if(!Number.isFinite(e)||e<=0)return"0 B";let t=["B","KB","MB","GB"],n=e,l=0;for(;n>=1024&&l<t.length-1;)n/=1024,l+=1;let a=0===l?n.toFixed(0):n.toFixed(n>=10?1:2);return`${a} ${t[l]}`;}function oQ(e){return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(new Date(e));}async function o0(e){var t;let n="u"<typeof navigator||null==(t=navigator.clipboard)?void 0:t.writeText;if(void 0!==n&&void 0!==navigator.clipboard)try{await n.call(navigator.clipboard,e);return;}catch{}if("u"<typeof document||null===document.body)throw Error("clipboard-unavailable");let l=document.createElement("textarea");l.value=e,l.setAttribute("readonly",""),l.style.position="fixed",l.style.opacity="0",l.style.pointerEvents="none",document.body.append(l),l.select();try{if(!("function"==typeof document.execCommand&&document.execCommand("copy")))throw Error("clipboard-fallback-failed");}finally{l.remove();}}function o1(e){let{label:t,value:n}=e;return(0,r.jsxs)("div",{className:"fpv-meta-row",children:[(0,r.jsx)("span",{children:t}),(0,r.jsx)("strong",{children:n})]});}function o2(e){var t,n,l,a;let{root:s,path:o,onClose:c,onOpenInEditor:d}=e,[u,p]=(0,i.useState)(null),[h,f]=(0,i.useState)(!0),[g,v]=(0,i.useState)(null),[b,y]=(0,i.useState)(0),[x,w]=(0,i.useState)("idle"),[j,k]=(0,i.useState)(null),N=(0,i.useRef)(null),S=(0,i.useRef)(null);(0,i.useEffect)(()=>{var e;null==(e=N.current)||e.focus({preventScroll:!0});},[]),(0,i.useEffect)(()=>{let e=!1,t=S.current,n=null===t||t.root!==s||t.path!==o,l=null!==t&&!n&&b>0;return S.current={root:s,path:o},f(!0),v(null),w(l?"refreshing":"idle"),l||p(null),(0,m.q7)(s,o).then(t=>{!e&&(p(t),l&&w("refreshed"));}).catch(t=>{!e&&(v(t instanceof m.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:/^HTTP \d+$/.test(t.message)?"The file could not be loaded. Try again.":t.message,denied:!1}:{message:"Unable to read this file.",denied:!1}),l&&w("failed"));}).finally(()=>{e||f(!1);}),()=>{e=!0;};},[o,s,b]),(0,i.useEffect)(()=>{if("refreshed"!==x)return;let e=window.setTimeout(()=>w("idle"),2400);return()=>window.clearTimeout(e);},[x]);let C=()=>y(e=>e+1),R=e=>{var t,n;let l;if(null===u)return;let a="name"===e?u.name:(t=u.root,n=u.path,l=t.includes("\\")&&!t.includes("/")?"\\":"/",`${t.replace(/[/\\]+$/u,"")}${l}${n.replace(/\//gu,l)}`);k(null),o0(a).then(()=>k("name"===e?"File name copied":"File path copied"),()=>k("Clipboard access failed."));},I=(null==g?void 0:g.denied)===!0,E=null!==u?"text"===u.kind?null!=(l=u.extension)?l:"text":"image"===u.kind?u.mime:null!=(a=u.extension)?a:"binary":I?"denied":null!==g?"error":"loading",A=I?"Hidden file":null!=(t=null==u?void 0:u.name)?t:null!==g?"Preview unavailable":"Loading preview",T=(null==u?void 0:u.kind)==="text"&&u.content.length<=2e5,F=void 0!==d&&(null==u?void 0:u.kind)==="text"&&!u.truncated,D="refreshing"===x?"Refreshing...":"refreshed"===x?"Reloaded":"failed"===x?"Refresh failed":"",M=(null==u?void 0:u.kind)==="text"?T?r4(u.content,r0(u.name)):u.content.split("\n").map(e=>[["id",e]]):[];return(0,r.jsxs)("div",{className:"fpv",onKeyDown:e=>{"Escape"===e.key&&(e.stopPropagation(),c());},children:[(0,r.jsxs)("div",{className:"fpv-bar",children:[(0,r.jsx)("button",{className:"fpv-back",type:"button",ref:N,onClick:c,title:"Back to files","aria-label":"Back to files",children:(0,r.jsx)($.F.back,{size:15})}),(0,r.jsx)(a0.o,{name:I||null===u?"":u.name}),(0,r.jsx)("span",{className:"fpv-name",title:A,children:A}),null!==u?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{className:"fpv-back fpv-copy",type:"button",onClick:()=>R("name"),title:"Copy file name","aria-label":"Copy file name",children:(0,r.jsx)($.F.copy,{size:13})}),(0,r.jsx)("button",{className:"fpv-back fpv-copy",type:"button",onClick:()=>R("path"),title:"Copy file path","aria-label":"Copy file path",children:(0,r.jsx)($.F.copy,{size:13})})]}):null,(0,r.jsx)("span",{className:"fpv-lang mono",children:E}),(0,r.jsx)("span",{className:"spacer"}),null!==j?(0,r.jsx)("span",{className:"fpv-status fpv-copy-status",role:"Clipboard access failed."===j?"alert":"status","aria-live":"polite",children:j}):null,(0,r.jsx)("button",{className:"fpv-back fpv-refresh",type:"button",onClick:C,disabled:h,"data-state":x,title:h?"Refreshing preview":"Refresh preview","aria-label":h?"Refreshing preview":"Refresh preview",children:(0,r.jsx)($.F.reset,{size:14})}),D.length>0?(0,r.jsx)("span",{className:"fpv-status mono","data-state":x,role:"status","aria-live":"polite",children:D}):null,F?(0,r.jsx)("button",{className:"fpv-back",type:"button",onClick:()=>d(s,o),title:"Open in editor","aria-label":"Open in editor",children:(0,r.jsx)($.F.editor,{size:15})}):null,(0,r.jsx)("button",{className:"fpv-back",type:"button",onClick:c,title:"Close preview","aria-label":"Close preview",children:(0,r.jsx)($.F.close,{size:15})})]}),h&&null===u?(0,r.jsx)("div",{className:"fpv-state",role:"status",children:"Loading preview…"}):null,null!==g?(0,r.jsxs)("div",{className:"fpv-state fpv-error",role:"alert",children:[(0,r.jsx)("span",{children:g.message}),g.denied?null:(0,r.jsx)("button",{type:"button",className:"fpv-retry",onClick:C,children:"Retry"})]}):null,(null==u?void 0:u.kind)==="text"?(0,r.jsxs)(r.Fragment,{children:[u.truncated?(0,r.jsxs)("div",{className:"fpv-banner",children:["Preview truncated at ",oZ(u.maxBytes),". Larger files can't be shown in full here."]}):null,T?null:(0,r.jsx)("div",{className:"fpv-banner",children:"Syntax highlighting disabled for large previews."}),(0,r.jsx)("div",{className:"fpv-code mono",tabIndex:0,role:"region","aria-label":`File preview: ${u.name}`,style:{"--fpv-gutter-w":`max(44px, calc(${String(String(M.length).length)}ch + 16px))`},children:M.map((e,t)=>(0,r.jsxs)("div",{className:"fpv-line",children:[(0,r.jsx)("span",{className:"fpv-num",children:t+1}),(0,r.jsx)("span",{className:"fpv-src",children:e.map((e,t)=>(0,r.jsx)("span",{className:`hl-${e[0]}`,children:e[1]},t))})]},t))})]}):null,(null==u?void 0:u.kind)==="image"?(0,r.jsxs)("div",{className:"fpv-image-pane",children:[(0,r.jsx)("div",{className:"fpv-image-card",children:(0,r.jsx)("img",{className:"fpv-image",src:u.dataUrl,alt:u.name})}),(0,r.jsxs)("div",{className:"fpv-meta",children:[(0,r.jsx)(o1,{label:"Type",value:u.mime}),(0,r.jsx)(o1,{label:"Size",value:oZ(u.sizeBytes)}),(0,r.jsx)(o1,{label:"Modified",value:oQ(u.modifiedAt)})]})]}):null,(null==u?void 0:u.kind)==="binary"?(0,r.jsx)("div",{className:"fpv-meta-pane",children:(0,r.jsxs)("div",{className:"fpv-meta-card",children:[(0,r.jsx)(a0.o,{name:u.name}),(0,r.jsx)("h3",{children:u.name}),(0,r.jsx)("p",{children:function(e){var t;if("too_large"===e.reason)return`Preview disabled because this file exceeds ${oZ(null!=(t=e.maxBytes)?t:0)}.`;let n=oX[function(e){var t;let n=null==(t=e.extension)?void 0:t.trim().toLowerCase();if(void 0!==n&&n.length>0)return n;let l=e.name.lastIndexOf(".");return l>=0?e.name.slice(l+1).trim().toLowerCase():"";}(e)];return void 0!==n?`${n} files up to 2 MB are searchable in Repository Search via bounded text extraction when explicitly connected to a chat. Encrypted, scanned, or larger documents are not extracted — use Local Knowledge for those. No inline preview is available for this format here.`:"No safe text or image preview is available for this file type.";}(u)}),(0,r.jsxs)("div",{className:"fpv-meta",children:[(0,r.jsx)(o1,{label:"Type",value:u.mime}),(0,r.jsx)(o1,{label:"Extension",value:null!=(n=u.extension)?n:"none"}),(0,r.jsx)(o1,{label:"Size",value:oZ(u.sizeBytes)}),(0,r.jsx)(o1,{label:"Modified",value:oQ(u.modifiedAt)})]})]})}):null]});}function o4(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))?`${t.slice(0,n)}\\`:t.slice(0,n);}function o3(e){let t=e.lastIndexOf("/");return t<0?null:e.slice(0,t);}function o6(e,t){return null===e||0===e.length?t:`${e}/${t}`;}function o5(e){return e instanceof Error?e.message:"Unable to read this folder.";}function o8(e){return 8+18*e;}let o9=new Set(["ArrowDown","ArrowUp","ArrowRight","ArrowLeft","Home","End"]);function o7(e){if(!Number.isFinite(e)||e<=0)return"0 B";let t=["B","KB","MB","GB"],n=e,l=0;for(;n>=1024&&l<t.length-1;)n/=1024,l+=1;let a=0===l?n.toFixed(0):n.toFixed(n>=10?1:2);return`${a} ${t[l]}`;}function ce(e){var t,n,l,a,s,o,c,d,u,p;let h,f,{root:g,activeFilePath:v,openFilesDirectly:b=!1,onActiveFileChange:y,onRootChange:x,onOpenFile:w,onOpenGitDelivery:j,onFilesMutated:k}=e,N=null==g?void 0:g.trim(),S=void 0!==N&&N.length>0?N:null,[C,R]=(0,i.useState)(null),I=null!=(t=null!=S?S:C)?t:"",[E,A]=(0,i.useState)(null),[T,F]=(0,i.useState)(""),[D,M]=(0,i.useState)(null),[P,L]=(0,i.useState)(null),[q,z]=(0,i.useState)({}),[O,B]=(0,i.useState)(()=>new Set([""])),W=(0,i.useRef)(y);W.current=y;let K=(0,i.useRef)(null),U=(0,i.useRef)(null),V=(0,i.useId)(),[H,_]=(0,i.useState)({loading:!1,status:null,error:null}),[G,J]=(0,i.useState)(null),[Y,X]=(0,i.useState)(null),[Z,Q]=(0,i.useState)(""),[ee,et]=(0,i.useState)(!1),[en,el]=(0,i.useState)(null),[ea,er]=(0,i.useState)(null),[ei,es]=(0,i.useState)(null),[eo,ec]=(0,i.useState)(null),ed=(0,i.useRef)(k);ed.current=k,(0,i.useEffect)(()=>{var e,t;if(null!==D||null!==G)return;let n=U.current;if(null===n)return;U.current=null;let l=null==(e=K.current)?void 0:e.querySelector(`.tr-file[data-path="${"u">typeof CSS&&"function"==typeof CSS.escape?CSS.escape(n):n.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"]`);null==(t=null!=l?l:K.current)||t.focus({preventScroll:!0});},[G,D]),(0,i.useEffect)(()=>{if(null!==S)return;let e=!1;return(0,m.vj)().then(t=>{var n;if(e)return;let l=null==(n=t.projects.find(e=>e.available))?void 0:n.path;R(null!=l?l:null);}).catch(()=>{e||R(null);}),()=>{e=!0;};},[S]);let eu=(0,i.useCallback)(async e=>{if(0===I.length)return void z(t=>({...t,[e]:{entries:[],truncated:!1,loading:!1,error:null,notice:"no-root"}}));z(t=>{var n,l,a,r;return{...t,[e]:{entries:null!=(n=null==(a=t[e])?void 0:a.entries)?n:[],truncated:null!=(l=null==(r=t[e])?void 0:r.truncated)&&l,loading:!0,error:null,notice:null}};});try{let n=await(0,m.KD)(I,e);if(""===e){var t;A(n.root),null==(t=W.current)||t.call(W,null,n.root,null),L(null);}z(t=>({...t,[e]:{entries:n.entries,truncated:n.truncated,loading:!1,error:null,notice:null}}));}catch(t){z(n=>{var l,a,r,i;return{...n,[e]:{entries:null!=(l=null==(r=n[e])?void 0:r.entries)?l:[],truncated:null!=(a=null==(i=n[e])?void 0:i.truncated)&&a,loading:!1,error:o5(t),notice:null}};});}},[I]);(0,i.useEffect)(()=>{var e;M(null),J(null),L(null),null==(e=W.current)||e.call(W,null,null,null),A(null),B(new Set([""])),z({}),eu("");},[I,eu]),(0,i.useEffect)(()=>{let e=null!=E?E:I.length>0?I:null;if(null===e)return void _({loading:!1,status:null,error:null});let t=!1;return _(e=>({...e,loading:!0,error:null})),(0,m.lv)(e).then(e=>{t||_({loading:!1,status:e,error:null});}).catch(e=>{t||_({loading:!1,status:null,error:o5(e)});}),()=>{t=!0;};},[I,E]);let ep=function(e,t){if(null===t||0===t.length)return e;let n=e.includes("\\")&&!e.includes("/")?"\\":"/";return`${e.replace(/[/\\]+$/u,"")}${n}${t.replace(/\//gu,n)}`;}(null!=E?E:I.length>0?I:"",P);(0,i.useEffect)(()=>{F(ep);},[ep]);let em=(0,i.useCallback)(e=>{let t=e.trim();void 0===x||0===t.length||t!==ep&&x(t);},[x,ep]),eh=(0,i.useCallback)(e=>{var t;M(null),L(e),null==(t=W.current)||t.call(W,null,null!=E?E:I,e),null!==e&&void 0===q[e]&&eu(e);},[I,q,eu,E]),ef=(0,i.useCallback)(()=>{M(null),eu(null!=P?P:"");},[P,eu]),eg=null!=E?E:I,ev=eg.length>0,eb=(0,i.useCallback)((e,t)=>{er(null),el(null),Q(""),X({kind:e,parentPath:t}),null!==t&&(B(e=>e.has(t)?e:new Set(e).add(t)),void 0===q[t]&&eu(t));},[q,eu]),ey=(0,i.useCallback)(e=>{er(null),el(null),Q(e.name),X({kind:"rename",path:e.path,name:e.name});},[]),ex=(0,i.useCallback)(()=>{X(null),Q(""),el(null);},[]),ew=(0,i.useCallback)(async()=>{var e,t,n,l;if(null===Y||0===eg.length||ee)return;let a=Z.trim();if("rename"===Y.kind&&a===Y.name)return void ex();let r=0===a.length?"Enter a name.":"."===a||".."===a?"That name is reserved.":/[/\\]/u.test(a)?"A name cannot contain a slash.":null;if(null!==r)return void el(r);et(!0),el(null);try{if("rename"===Y.kind){let t=o3(Y.path),n=await(0,m.OD)({root:eg,path:Y.path,newPath:o6(t,a)});X(null),Q(""),D===Y.path&&M(n.path),await eu(null!=t?t:""),null==(e=ed.current)||e.call(ed,{op:"rename",mutation:n});}else{let e=await(0,m.Yl)({root:eg,path:o6(Y.parentPath,a),kind:"new-file"===Y.kind?"file":"directory"});X(null),Q(""),await eu(null!=(t=Y.parentPath)?t:""),"directory"===e.kind?B(t=>new Set(t).add(e.path)):void 0!==w&&(null==(l=W.current)||l.call(W,e.path,eg),w(eg,e.path)),null==(n=ed.current)||n.call(ed,{op:"create",mutation:e});}}catch(e){el(o5(e));}finally{et(!1);}},[ex,Z,eu,eg,w,ee,Y,D]),ej=(0,i.useCallback)(async e=>{if(0!==eg.length&&!ee){et(!0),el(null);try{var t,n;let l=await(0,m.Z1)({root:eg,path:e.path});es(null),D===e.path&&M(null),await eu(null!=(t=o3(e.path))?t:""),null==(n=ed.current)||n.call(ed,{op:"delete",mutation:l});}catch(e){el(o5(e));}finally{et(!1);}}},[eu,eg,ee,D]),ek=(0,i.useCallback)(async e=>{var t,n,l;if(0===eg.length||ee)return;let a=o3(e.path),r=new Set((null!=(t=null==(n=q[null!=a?a:""])?void 0:n.entries)?t:[]).map(e=>e.name)),i=o6(a,function(e,t){let n=e.lastIndexOf("."),l=n>0?e.slice(0,n):e,a=n>0?e.slice(n):"",r=`${l} copy${a}`,i=2;for(;t.has(r);)r=`${l} copy ${String(i)}${a}`,i+=1;return r;}(e.name,r));er(null),et(!0),el(null);try{let t=await(0,m.zv)({root:eg,sourcePath:e.path,destPath:i});await eu(null!=a?a:""),null==(l=ed.current)||l.call(ed,{op:"create",mutation:t});}catch(e){el(o5(e));}finally{et(!1);}},[q,eu,eg,ee]),eN=(0,i.useCallback)(async(e,t)=>{if(0===eg.length||ee)return;let n=o6(t,e.slice(e.lastIndexOf("/")+1));if(n!==e&&o3(e)!==t&&t!==e&&(null==t?void 0:t.startsWith(`${e}/`))!==!0){et(!0),el(null);try{var l,a;let r=await(0,m.OD)({root:eg,path:e,newPath:n});await eu(null!=(l=o3(e))?l:""),await eu(null!=t?t:""),null==(a=ed.current)||a.call(ed,{op:"rename",mutation:r});}catch(e){el(o5(e));}finally{et(!1);}}},[eu,eg,ee]),eS=(0,i.useCallback)((e,t)=>{ev&&(e.preventDefault(),e.stopPropagation(),el(null),er({x:e.clientX,y:e.clientY,entry:t}));},[ev]);(0,i.useEffect)(()=>{if(null===ea)return;let e=()=>er(null),t=e=>{"Escape"===e.key&&er(null);};return window.addEventListener("pointerdown",e),window.addEventListener("resize",e),window.addEventListener("keydown",t),()=>{window.removeEventListener("pointerdown",e),window.removeEventListener("resize",e),window.removeEventListener("keydown",t);};},[ea]);let eC=(0,i.useCallback)(()=>{if(null!==P)return void eh(function(e){let t=e.replace(/\/+$/u,""),n=t.lastIndexOf("/");if(n<0)return null;let l=t.slice(0,n);return l.length>0?l:null;}(P));let e=o4(null!=E?E:I);null!==e&&em(e);},[I,P,eh,em,E]),eR=(0,i.useCallback)(e=>{let t=null!=E?E:I;0!==t.length&&(M(null),J({path:e,loading:!0,response:null,error:null}),(0,m.w2)({root:t,path:e}).then(t=>{J({path:e,loading:!1,response:t,error:null});}).catch(t=>{J({path:e,loading:!1,response:null,error:o5(t)});}));},[I,E]),eI=(0,i.useCallback)(e=>{for(let t of Object.values(q)){let n=t.entries.find(t=>t.path===e);if(void 0!==n)return n;}return null;},[q]),eE=new Map(((null==(a=H.status)?void 0:a.available)===!0?H.status.changes:[]).map(e=>[e.path,e])),e$=function(e){var t;if(e.loading&&null===e.status)return"Git status loading";if(null!==e.error)return"Git status unavailable";let n=e.status;if(null===n)return null;if(!n.available)return"unsafe"===n.state?"Git unsafe":"Git unavailable";let l=n.detached?"detached HEAD":null!=(t=n.branch)?t:"unknown branch";if(n.clean)return`Git ${l} clean`;let a=n.changes.length;return`Git ${l} ${String(a)} changed ${1===a?"file":"files"}`;}(H),eA=(null==(s=H.status)?void 0:s.available)===!0?null!=(n=H.status.repositoryRoot)?n:H.status.root:"",eT=void 0!==j&&(null==(o=H.status)?void 0:o.available)===!0&&eA.length>0,eF=(e,t,n)=>(0,r.jsxs)("div",{className:"tr-row-wrap",children:[(0,r.jsxs)("div",{className:"tr-dir-line",style:{paddingLeft:o8(e)},children:[(0,r.jsx)("span",{className:"tr-caret tr-caret-ghost","aria-hidden":"true",children:(0,r.jsx)($.F.chevronR,{size:11})}),t,(0,r.jsx)("input",{className:"files-root-input mono",style:{flex:1,minWidth:0},"aria-label":n,autoFocus:!0,spellCheck:!1,disabled:ee,value:Z,onChange:e=>Q(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),ew()):"Escape"===e.key&&(e.preventDefault(),ex());},onBlur:()=>{ee||ex();}})]}),null!==en?(0,r.jsx)("div",{className:"files-error",role:"alert",style:{marginLeft:o8(e)},children:(0,r.jsx)("span",{children:en})}):null]},"__files-inline-editor__"),eD=function(e,t){var n;let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:q[e];return(0,r.jsxs)("div",{className:"tr-dir",role:0===t?void 0:"group",children:[(null==l?void 0:l.loading)===!0?(0,r.jsx)("div",{className:"files-note",role:"status",style:{paddingLeft:o8(t)+18},children:"Loading…"}):null,(null==l?void 0:l.notice)==="no-root"?(0,r.jsx)("div",{className:"files-note",role:"status",style:{paddingLeft:o8(t)+18},children:void 0!==x?"No folder is open yet. Enter a folder path above and press Open.":"No registered project is available."}):null,(null==l?void 0:l.error)!==null&&(null==l?void 0:l.error)!==void 0?(0,r.jsxs)("div",{className:"files-error",role:"alert",style:{marginLeft:o8(t)},children:[(0,r.jsx)("span",{children:l.error}),(0,r.jsx)("button",{type:"button",className:"files-retry",onClick:()=>{eu(e);},children:"Retry"})]}):null,(null==l?void 0:l.truncated)===!0?(0,r.jsxs)("div",{className:"files-note files-warning",role:"status",style:{paddingLeft:o8(t)+18},children:["Showing only the first ",l.entries.length," entries — this folder contains more."]}):null,null!==Y&&"rename"!==Y.kind&&(null!=(n=Y.parentPath)?n:"")===e?eF(t,"new-folder"===Y.kind?(0,r.jsx)("span",{className:"fi-fallback",style:{color:"var(--accent)"},children:(0,r.jsx)($.F.folder,{size:14})}):(0,r.jsx)(a0.o,{name:Z.length>0?Z:"new-file"}),"new-folder"===Y.kind?"New folder name":"New file name"):null,null==l?void 0:l.entries.map(e=>((e,t)=>{var n;let l=o8(t),a=O.has(e.path);if((null==Y?void 0:Y.kind)==="rename"&&Y.path===e.path)return eF(t,"directory"===e.kind?(0,r.jsx)("span",{className:"fi-fallback",style:{color:"var(--accent)"},children:(0,r.jsx)($.F.folder,{size:14})}):(0,r.jsx)(a0.o,{name:Z.length>0?Z:e.name}),`Rename ${e.name}`);let i="This link can't be opened from this folder.";if("directory"===e.kind){let n=q[e.path];return(0,r.jsxs)("div",{className:"tr-row-wrap",children:[(0,r.jsxs)("div",{className:"tr-dir-line",style:{paddingLeft:l},children:[(0,r.jsx)("button",{className:"tr-caret-btn",type:"button",tabIndex:-1,disabled:!e.readable,"aria-label":`${a?"Collapse":"Expand"} folder: ${e.name}`,onClick:()=>(e=>{if(!e.readable)return;let t=O.has(e.path);B(t=>{let n=new Set(t);return n.has(e.path)?n.delete(e.path):n.add(e.path),n;}),t||void 0!==q[e.path]||eu(e.path);})(e),title:e.readable?`${a?"Collapse":"Expand"} ${e.path}`:i,children:(0,r.jsx)("span",{className:"tr-caret","data-open":a,children:(0,r.jsx)($.F.chevronR,{size:11})})}),(0,r.jsxs)("button",{className:"tr-row tr-dir-enter",role:"treeitem","aria-level":t+1,"aria-selected":P===e.path,"data-active":P===e.path,"data-readable":e.readable,"data-path":e.path,type:"button",draggable:ev&&e.readable,"aria-disabled":!e.readable||void 0,"aria-describedby":e.readable?void 0:V,"aria-expanded":a,onClick:()=>{e.readable&&eh(e.path);},onContextMenu:t=>eS(t,e),onDragStart:t=>{t.dataTransfer.effectAllowed="move",t.dataTransfer.setData("text/plain",e.path),ec(e.path);},onDragEnd:()=>ec(null),onDragOver:t=>{e.readable&&null!==eo&&eo!==e.path&&(t.preventDefault(),t.dataTransfer.dropEffect="move");},onDrop:t=>{t.preventDefault(),ec(null),null!==eo&&eN(eo,e.path);},title:e.readable?e.path:i,children:[(0,r.jsx)("span",{className:"fi-fallback",style:{color:"var(--accent)"},children:(0,r.jsx)($.F.folder,{size:14})}),(0,r.jsx)("span",{className:"tr-name tr-folder",children:e.name}),e.symlink?(0,r.jsx)("span",{className:"tr-badge",children:"link"}):null]})]}),a?eD(e.path,t+1,n):null]},e.path);}let s=null!=(n=null!=D?D:v)?n:null,o=eE.get(e.path);return(0,r.jsxs)("div",{className:"tr-row-wrap tr-file-wrap",children:[(0,r.jsxs)("button",{className:"tr-row tr-file",onContextMenu:t=>eS(t,e),role:"treeitem","aria-level":t+1,"aria-selected":s===e.path,"data-active":s===e.path,"data-readable":e.readable,"data-path":e.path,style:{paddingLeft:l},type:"button",draggable:ev&&e.readable,"aria-disabled":!e.readable||void 0,"aria-describedby":e.readable?void 0:V,onDragStart:t=>{t.dataTransfer.effectAllowed="move",t.dataTransfer.setData("text/plain",e.path),ec(e.path);},onDragEnd:()=>ec(null),onClick:()=>{var t,n;if(!e.readable)return;let l=null!=E?E:I;if(b&&void 0!==w){null==(n=W.current)||n.call(W,e.path,l),w(l,e.path);return;}M(e.path),null==(t=W.current)||t.call(W,e.path,l);},title:e.readable?e.path:i,children:[(0,r.jsx)("span",{className:"tr-caret tr-caret-ghost","aria-hidden":"true",children:(0,r.jsx)($.F.chevronR,{size:11})}),(0,r.jsx)(a0.o,{name:e.name}),(0,r.jsx)("span",{className:"tr-name",children:e.name}),e.symlink?(0,r.jsx)("span",{className:"tr-badge",children:"link"}):null,void 0!==o?(0,r.jsx)("span",{className:"tr-badge tr-git",children:o.conflicted?"U":o.untracked?"?":" "!==o.indexStatus?o.indexStatus:o.worktreeStatus}):null,(0,r.jsx)("span",{className:"tr-meta mono",children:o7(e.sizeBytes)})]}),void 0!==o&&e.readable?(0,r.jsx)("button",{className:"tr-git-diff",type:"button",onClick:()=>eR(e.path),title:`View Git diff for ${e.path}`,"aria-label":`View Git diff for ${e.path}`,children:(0,r.jsx)($.F.diff,{size:13})}):null]},e.path);})(e,t)),void 0===l||l.loading||null!==l.error||null!==l.notice||0!==l.entries.length?null:(0,r.jsx)("div",{className:"files-note",role:"status",style:{paddingLeft:o8(t)+18},children:"Empty folder."})]});};if(null!==G){let e=null!=(d=null==(u=G.response)?void 0:u.diff)?d:"";return(0,r.jsxs)("div",{className:"fpv",ref:K,tabIndex:-1,children:[(0,r.jsxs)("div",{className:"fpv-bar",children:[(0,r.jsx)("button",{className:"fpv-back",type:"button",onClick:()=>{U.current=G.path,J(null);},title:"Back to files","aria-label":"Back to files",children:(0,r.jsx)($.F.back,{size:15})}),(0,r.jsx)($.F.diff,{size:15}),(0,r.jsx)("span",{className:"fpv-name",title:G.path,children:G.path}),(0,r.jsx)("span",{className:"fpv-lang mono",children:"git diff"}),(0,r.jsx)("span",{className:"spacer"}),(0,r.jsx)("button",{className:"fpv-back",type:"button",onClick:()=>{U.current=G.path,J(null);},title:"Close diff","aria-label":"Close diff",children:(0,r.jsx)($.F.close,{size:15})})]}),G.loading?(0,r.jsx)("div",{className:"fpv-state",role:"status",children:"Loading diff…"}):null,null!==G.error?(0,r.jsx)("div",{className:"fpv-state fpv-error",role:"alert",children:(0,r.jsx)("span",{children:G.error})}):null,(null==(p=G.response)?void 0:p.truncated)===!0?(0,r.jsxs)("div",{className:"fpv-banner",children:["Diff truncated at ",o7(G.response.maxBytes),"."]}):null,null!==G.response?(0,r.jsx)("div",{className:"fpv-code mono",tabIndex:0,role:"region","aria-label":`Git diff: ${G.path}`,children:e.length>0?e.split("\n").map((e,t)=>(0,r.jsx)("div",{className:"fpv-line",children:(0,r.jsx)("span",{className:"fpv-src",children:e.length>0?e:" "})},t)):(0,r.jsx)("div",{className:"fpv-line",children:(0,r.jsx)("span",{className:"fpv-src",children:"No diff available."})})}):null]});}return null!==D?(0,r.jsx)(o2,{root:null!=E?E:I,path:D,onOpenInEditor:w,onClose:()=>{var e;U.current=D,M(null),null==(e=W.current)||e.call(W,null,null!=E?E:I);}}):(0,r.jsxs)("div",{className:"files",ref:K,tabIndex:-1,children:[void 0!==x?(0,r.jsxs)("form",{className:"files-root-bar",role:"group","aria-label":"Folder root",onSubmit:e=>{e.preventDefault(),em(T);},children:[(0,r.jsx)("button",{type:"button",className:"files-root-up",onClick:eC,disabled:null===P&&null===o4(null!=E?E:I),title:"Open parent folder","aria-label":"Open parent folder",children:(0,r.jsx)($.F.arrowUp,{size:13})}),(0,r.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:T,onChange:e=>F(e.target.value)}),(0,r.jsx)("button",{type:"submit",className:"files-root-open",title:"Open this folder",children:"Open"})]}):null,null!==e$?(0,r.jsxs)("div",{className:"files-git-status",role:"status","data-state":null!=(l=null==(c=H.status)?void 0:c.state)?l:null!==H.error?"error":"loading",children:[(0,r.jsx)($.F.git,{size:13}),(0,r.jsx)("span",{children:e$}),eT?(0,r.jsx)("button",{className:"files-root-up",style:{width:24,height:24,marginLeft:"auto"},type:"button",onClick:()=>j(eA),title:"Open Git","aria-label":"Open Git",children:(0,r.jsx)($.F.branch,{size:13})}):null]}):null,(0,r.jsx)("button",{className:"files-refresh",type:"button",onClick:ef,title:"Refresh folder","aria-label":"Refresh folder",children:(0,r.jsx)($.F.reset,{size:13})}),ev?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{className:"files-refresh",style:{right:62},type:"button",onClick:()=>eb("new-file",P),title:"New file","aria-label":"New file",children:(0,r.jsx)($.F.file,{size:13})}),(0,r.jsx)("button",{className:"files-refresh",style:{right:34},type:"button",onClick:()=>eb("new-folder",P),title:"New folder","aria-label":"New folder",children:(0,r.jsx)($.F.folder,{size:13})})]}):null,(0,r.jsx)("span",{id:V,className:"visually-hidden",children:"This link can't be opened from this folder."}),(0,r.jsx)("div",{className:"tr files-tree",role:"tree","aria-label":"Files",tabIndex:-1,onKeyDown:e=>{if(ev&&("F2"===e.key||"Delete"===e.key)){let t=e.target instanceof HTMLElement?e.target.closest("button.tr-row[data-readable='true']"):null,n=null==t?void 0:t.getAttribute("data-path"),l=null!=n?eI(n):null;null!==l&&(e.preventDefault(),"F2"===e.key?ey(l):(el(null),es(l)));return;}if(!o9.has(e.key))return;let t=e.target,n=t instanceof HTMLElement?t.closest("button.tr-row"):null;if(null===n)return;let l=Array.from(e.currentTarget.querySelectorAll("button.tr-row")),a=l.indexOf(n);a<0||(e.preventDefault(),function(e,t,n){var l,a,r,i,s,o;let c=e[t];if(void 0===c)return;let d=null==(l=c.closest(".tr-row-wrap"))?void 0:l.querySelector("button.tr-caret-btn");if("ArrowDown"===n)null==(a=e[t+1])||a.focus();else if("ArrowUp"===n)null==(r=e[t-1])||r.focus();else if("Home"===n)null==(i=e[0])||i.focus();else if("End"===n)null==(s=e[e.length-1])||s.focus();else if("ArrowRight"===n){let n=c.getAttribute("aria-expanded");"false"===n?null==d||d.click():"true"===n&&(null==(o=e[t+1])||o.focus());}else"ArrowLeft"===n&&("true"===c.getAttribute("aria-expanded")?null==d||d.click():function(e,t){var n,l,a,r,i;let s=Number(null!=(n=null==(l=e[t])?void 0:l.getAttribute("aria-level"))?n:"1");for(let n=t-1;n>=0;n-=1)if(Number(null!=(a=null==(r=e[n])?void 0:r.getAttribute("aria-level"))?a:"1")<s){null==(i=e[n])||i.focus();return;}}(e,t));}(l,a,e.key));},children:eD(null!=P?P:"",0)}),null!==ea?(0,r.jsx)("div",{role:"menu","aria-label":"File actions",onPointerDown:e=>e.stopPropagation(),style:{position:"fixed",top:ea.y,left:ea.x,zIndex:9700,minWidth:176,padding:6,background:"var(--popover-surface)",border:"1px solid var(--popover-border)",borderRadius:"var(--radius)",boxShadow:"var(--popover-shadow)",display:"flex",flexDirection:"column",gap:2},children:(h=null!==ea.entry&&ea.entry.readable?ea.entry:null,f=null===ea.entry?P:"directory"===ea.entry.kind?ea.entry.path:o3(ea.entry.path),(0,r.jsxs)(r.Fragment,{children:[null!==h?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("button",{type:"button",className:"edm-item",role:"menuitem",onClick:()=>ey(h),children:[(0,r.jsx)($.F.edit,{size:14}),(0,r.jsx)("span",{children:"Rename…"})]}),(0,r.jsxs)("button",{type:"button",className:"edm-item",role:"menuitem",onClick:()=>void ek(h),children:[(0,r.jsx)($.F.copy,{size:14}),(0,r.jsx)("span",{children:"Duplicate"})]}),(0,r.jsxs)("button",{type:"button",className:"edm-item",role:"menuitem",onClick:()=>{er(null),el(null),es(h);},children:[(0,r.jsx)($.F.trash,{size:14}),(0,r.jsx)("span",{children:"Delete…"})]})]}):null,(0,r.jsxs)("button",{type:"button",className:"edm-item",role:"menuitem",onClick:()=>eb("new-file",f),children:[(0,r.jsx)($.F.file,{size:14}),(0,r.jsx)("span",{children:"New File…"})]}),(0,r.jsxs)("button",{type:"button",className:"edm-item",role:"menuitem",onClick:()=>eb("new-folder",f),children:[(0,r.jsx)($.F.folder,{size:14}),(0,r.jsx)("span",{children:"New Folder…"})]})]}))}):null,null!==ei?(0,r.jsx)("div",{className:"ed-dialog-backdrop",role:"presentation",children:(0,r.jsxs)("div",{className:"ed-dirty-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"files-delete-title",tabIndex:-1,children:[(0,r.jsxs)("h2",{id:"files-delete-title",children:["Delete ","directory"===ei.kind?"folder":"file","?"]}),(0,r.jsxs)("p",{children:["“",ei.name,"” will be permanently deleted","directory"===ei.kind?", including everything inside it":"",". This cannot be undone."]}),null!==en?(0,r.jsx)("p",{role:"alert",children:en}):null,(0,r.jsxs)("div",{className:"ed-dialog-actions",children:[(0,r.jsx)("button",{type:"button",className:"ed-reload",onClick:()=>void ej(ei),disabled:ee,children:ee?"Deleting…":"Delete"}),(0,r.jsx)("button",{type:"button",className:"ed-icon-action",onClick:()=>{es(null),el(null);},disabled:ee,children:"Cancel"})]})]})}):null]});}var ct=n(42925),cn=n(32620);let cl=[{id:"view.splitRight",title:"Split Editor Right",keybinding:"Ctrl/⌘ ⌥ \\",run:e=>e.splitActive("row"),isAvailable:e=>null!==e.activeFile},{id:"view.splitDown",title:"Split Editor Down",run:e=>e.splitActive("column"),isAvailable:e=>null!==e.activeFile},{id:"view.closeSplit",title:"Close Editor Split",run:e=>e.closeActiveSplit(),isAvailable:e=>e.paneCount>1},{id:"tab.next",title:"Next Tab",keybinding:"Ctrl/⌘ ⌥ →",run:e=>e.nextTab(),isAvailable:e=>null!==e.activeFile},{id:"tab.prev",title:"Previous Tab",keybinding:"Ctrl/⌘ ⌥ ←",run:e=>e.prevTab(),isAvailable:e=>null!==e.activeFile},{id:"tab.close",title:"Close Tab",run:e=>e.closeActiveTab(),isAvailable:e=>null!==e.activeFile},{id:"tab.reopenClosed",title:"Reopen Closed Editor",keybinding:"Ctrl/⌘ ⌥ T",run:e=>e.reopenClosed(),isAvailable:e=>e.closedTabCount>0},{id:"files.saveAll",title:"Save All",keybinding:"Ctrl/⌘ ⌥ S",run:e=>e.saveAll(),isAvailable:e=>e.dirtyCount>0}];function ca(e){let{mode:t,root:n,host:l,onOpenFile:a,onClose:s}=e,[o,c]=(0,i.useState)("commands"===t?">":""),[d,u]=(0,i.useState)([]),[p,h]=(0,i.useState)(0),f=(0,i.useRef)(null),g=(0,i.useId)(),v=o.startsWith(">")?"commands":"files",b=o.startsWith(">")?o.slice(1).trim():"";(0,i.useEffect)(()=>{var e,t;null==(e=f.current)||e.focus(),null==(t=f.current)||t.select();},[]),(0,i.useEffect)(()=>{if("files"!==v)return;let e=o.trim();if(0===e.length)return void u([]);let t=new AbortController(),l=setTimeout(()=>{(0,m.Gb)(n,e,30,{signal:t.signal}).then(e=>u(e.results)).catch(()=>{});},120);return()=>{clearTimeout(l),t.abort();};},[v,o,n]);let y=(0,i.useMemo)(()=>{let e;return"commands"===v?(e=cl.filter(e=>void 0===e.isAvailable||e.isAvailable(l)),0===b.length?e:e.map(e=>({command:e,score:function(e,t){if(0===e.length)return t.length;let n=e.toLowerCase(),l=t.toLowerCase(),a=0,r=0,i=-1;for(let e=0;e<l.length&&r<n.length;e+=1){if(l[e]!==n[r])continue;0===r&&(a+=e),i===e-1&&(a-=3);let t=0===e?"/":l[e-1];("/"===t||"."===t||"_"===t||"-"===t||" "===t)&&(a-=2),i=e,r+=1;}return r<n.length?null:a+(t.length-i);}(b,e.title)})).filter(e=>null!==e.score).sort((e,t)=>e.score-t.score).map(e=>e.command)):[];},[b,v,l]),x="files"===v?d.length:y.length;(0,i.useEffect)(()=>{h(0);},[o,v,d]);let w=e=>{if("files"===v){let t=d[e];void 0!==t&&(a(t.root,t.path),s());return;}let t=y[e];void 0!==t&&(t.run(l),s());},j=e=>`${g}-opt-${String(e)}`;return(0,r.jsx)("div",{className:"ed-dialog-backdrop",role:"presentation",style:{alignItems:"flex-start",paddingTop:"12vh"},onPointerDown:s,children:(0,r.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":"files"===v?"Go to file":"Run command",onPointerDown:e=>e.stopPropagation(),style:{width:"min(560px, 92vw)",maxHeight:"60vh",display:"flex",flexDirection:"column",background:"var(--popover-surface)",border:"1px solid var(--popover-border)",borderRadius:"var(--radius)",boxShadow:"var(--popover-shadow)",overflow:"hidden"},children:[(0,r.jsx)("input",{ref:f,type:"text",className:"files-root-input mono",style:{margin:8,width:"auto"},spellCheck:!1,autoComplete:"off",role:"combobox","aria-expanded":x>0,"aria-controls":g,"aria-activedescendant":x>0?j(p):void 0,"aria-label":"files"===v?"File name — type to search, prefix with > for commands":"Command name",placeholder:"files"===v?"Go to file… (› for commands)":"Run a command…",value:o,onChange:e=>c(e.target.value),onKeyDown:e=>{"ArrowDown"===e.key?(e.preventDefault(),x>0&&h(e=>(e+1)%x)):"ArrowUp"===e.key?(e.preventDefault(),x>0&&h(e=>(e-1+x)%x)):"Enter"===e.key?(e.preventDefault(),w(p)):"Escape"===e.key&&(e.preventDefault(),s());}}),(0,r.jsx)("div",{id:g,role:"listbox","aria-label":"files"===v?"Files":"Commands",style:{overflowY:"auto",padding:"0 6px 6px"},children:0===x?(0,r.jsx)("div",{className:"files-note",role:"status",style:{padding:"6px 9px"},children:"files"===v?0===o.trim().length?"Type to search files.":"No matching files.":"No matching commands."}):"files"===v?d.map((e,t)=>(0,r.jsxs)("button",{type:"button",id:j(t),role:"option","aria-selected":t===p,className:"edm-item",style:t===p?{background:"var(--surface-elevated)"}:void 0,onPointerEnter:()=>h(t),onClick:()=>w(t),children:[(0,r.jsx)(a0.o,{name:e.name}),(0,r.jsxs)("span",{style:{minWidth:0,flex:1,display:"flex",flexDirection:"column"},children:[(0,r.jsx)("span",{style:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.name}),e.directory.length>0?(0,r.jsx)("span",{className:"mono",style:{fontSize:"0.78em",color:"var(--text-secondary)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.directory}):null]})]},`${e.root}\0${e.path}`)):y.map((e,t)=>(0,r.jsxs)("button",{type:"button",id:j(t),role:"option","aria-selected":t===p,className:"edm-item",style:t===p?{background:"var(--surface-elevated)"}:void 0,onPointerEnter:()=>h(t),onClick:()=>w(t),children:[(0,r.jsx)("span",{style:{flex:1},children:e.title}),void 0!==e.keybinding?(0,r.jsx)("span",{className:"mono",style:{fontSize:"0.78em",color:"var(--text-secondary)"},children:e.keybinding}):null]},e.id))})]})});}let cr=(0,ct.default)(()=>n.e(8395).then(n.bind(n,88395)),{loadableGenerated:{webpack:()=>[88395]},ssr:!1,loading:()=>(0,r.jsx)("div",{className:"ed-host-loading","aria-hidden":"true"})});function ci(e,t,n){return Math.min(n,Math.max(t,e));}function cs(e,t){let n=t$(e,t);return"relative"===n.kind?n.path:"";}function co(e,t,n){let l=[],a=t=>{let n=cs(e,t);0===n.length||l.includes(n)||l.push(n);};for(let e of null!=n?n:[])a(e);return a(t),l;}function cc(e,t){let n={};for(let[l,a]of Object.entries(t.panes))n[l]=function(e,t){let n=co(e,t.activeFile,t.openFiles),l=cs(e,t.activeFile)||n[0]||"",a=co(e,l,t.tabOrder);return{...t,openFiles:n,activeFile:l,tabOrder:a.length>0?a:n};}(e,a);return{...t,root:e,panes:n};}function cd(e){return cc(e.root,tW({root:e.root,file:e.file,openFiles:e.openFiles,layoutJson:e.layoutJson,defaultSidebarWidth:260,minSidebarWidth:180,maxSidebarWidth:440}));}function cu(e){let t=new Set();for(let n of Object.values(e))for(let e of Object.keys(n))t.add(e);return[...t];}function cp(e){let t="editor-dirty-close-title",n=(0,i.useRef)(null);return(0,i.useEffect)(()=>{var e;null==(e=n.current)||e.focus();},[]),(0,i.useEffect)(()=>{let t=t=>{"Escape"!==t.key||e.pending.saving||e.onCancel();};return document.addEventListener("keydown",t),()=>{document.removeEventListener("keydown",t);};},[e]),(0,r.jsx)("div",{className:"ed-dialog-backdrop",role:"presentation",children:(0,r.jsxs)("div",{className:"ed-dirty-dialog",ref:n,role:"dialog","aria-modal":"true","aria-labelledby":t,tabIndex:-1,children:[(0,r.jsx)("h2",{id:t,children:"Unsaved editor changes"}),(0,r.jsx)("p",{children:"Choose how to handle these files before continuing."}),(0,r.jsx)("ul",{children:e.pending.dirtyFiles.map(e=>(0,r.jsx)("li",{children:e},e))}),void 0!==e.pending.error?(0,r.jsx)("p",{role:"alert",children:e.pending.error}):null,(0,r.jsxs)("div",{className:"ed-dialog-actions",children:[(0,r.jsx)("button",{type:"button",className:"ed-save",onClick:e.onSave,disabled:e.pending.saving,children:e.pending.saving?"Saving...":"Save"}),(0,r.jsx)("button",{type:"button",className:"ed-reload",onClick:e.onDiscard,disabled:e.pending.saving,children:"Discard"}),(0,r.jsx)("button",{type:"button",className:"ed-icon-action",onClick:e.onCancel,disabled:e.pending.saving,children:"Cancel"})]})]})});}function cm(e){var t,n;let{root:l,file:a,openFiles:s,layoutJson:o,onWorkspaceChange:c,...d}=e,u=null!=(t=null==l?void 0:l.trim())?t:"",p=cs(u,a),m=co(u,p,s),h=cd({root:u,file:p,openFiles:m,layoutJson:o}),[f,g]=(0,i.useState)(u),[v,b]=(0,i.useState)(h),y=(0,i.useRef)(v);y.current=v;let[x,w]=(0,i.useState)({}),[j,k]=(0,i.useState)(null),[N,S]=(0,i.useState)(null),[C,R]=(0,i.useState)(null),I=(0,i.useRef)(0),E=(0,i.useRef)(new Map()),A=(0,i.useRef)(null!=(n=null==l?void 0:l.trim())?n:""),T=(0,i.useRef)(null),[F,D]=(0,i.useState)(null),M=(0,i.useRef)([]),P=(0,i.useCallback)((e,t)=>{var n;let l=tH(t);return{root:e,file:l.activeFile.length>0?l.activeFile:void 0,openFiles:(n=t6(t)).length>0?n:void 0,layoutJson:tK(t)};},[]),L=(0,i.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:f,n=cc(t,e);b(n),w(e=>function(e,t){let n=function(e){let t=new Set();for(let n of Object.values(e))for(let e of Object.keys(n))t.add(e);return t;}(e);if(0===n.size)return 0===Object.keys(e).length?e:{};let l={};for(let e of tV(t)){let t;for(let l of e.openFiles)n.has(l)&&(null!=t||(t={}),t[l]=!0);void 0!==t&&(l[e.id]=t);}return!function(e,t){let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let a of n){var l;let n=null!=(l=e[a])?l:{},r=t[a];if(void 0===r)return!1;let i=Object.keys(n);if(i.length!==Object.keys(r).length)return!1;for(let e of i)if(!0!==r[e])return!1;}return!0;}(e,l)?l:e;}(e,n)),t.length>0&&(null==c||c(P(t,n)));},[P,c,f]);(0,i.useEffect)(()=>{var e,t;let n=null!=(e=null==l?void 0:l.trim())?e:"",r=cs(n,a),i=co(n,r,s),d=cd({root:n,file:r,openFiles:i,layoutJson:o}),u=tH(d),p=t6(d),m=A.current!==n;if(A.current=n,g(n),b(d),m&&w({}),0===n.length||void 0===c)return;let h=(null!=(t=null==a?void 0:a.trim())?t:"")!==u.activeFile,f=void 0===s?0!==p.length:!(s.length===p.length&&s.every((e,t)=>e===p[t])),v=o!==tK(d);(h||f||v)&&c(P(n,d));},[P,s,a,o,c,l]);let q=(0,i.useMemo)(()=>cu(x),[x]),z=tH(v).activeFile;(0,i.useEffect)(()=>{if(0===q.length)return;let e=e=>{e.preventDefault(),e.returnValue="";};return window.addEventListener("beforeunload",e),()=>{window.removeEventListener("beforeunload",e);};},[q.length]);let O=(0,i.useCallback)((e,t,n)=>{w(l=>{var a;let r=null!=(a=l[e])?a:{};if(n)return!0===r[t]?l:{...l,[e]:{...r,[t]:!0}};if(!0!==r[t])return l;let{[t]:i,...s}=r;return{...l,[e]:s};});},[]),B=(0,i.useCallback)((e,t)=>{I.current+=1;let n=I.current;return L(t3(y.current,{type:"select-file",paneId:e,file:t})),R({id:n,paneId:e,file:t}),new Promise(e=>{E.current.set(n,e);});},[L]),W=(0,i.useCallback)((e,t,n,l)=>{let a=E.current.get(e);E.current.delete(e),R(t=>(null==t?void 0:t.id)===e?null:t),l&&O(t,n,!1),null==a||a(l);},[O]),K=(0,i.useCallback)(e=>{var t,n,l;let a,r=new Set(cu(x)),i="root-change"===e.reason||"window-close"===e.reason?e.files.filter(e=>r.has(e)):(t=e.paneId,n=e.files,a=null!=(l=x[t])?l:{},n.filter(e=>!0===a[e]));return 0===i.length?(e.apply(),!0):(k({intent:function(e){let t=[];for(let n of e.files)n.length>0&&!t.includes(n)&&t.push(n);return{paneId:e.paneId,files:t,reason:e.reason};}({paneId:e.paneId,files:i,reason:e.reason}),apply:e.apply,dirtyFiles:i,saving:!1}),!1);},[x]),U=(0,i.useCallback)(()=>{null===j||j.saving||(k({...j,saving:!0,error:void 0}),(async()=>{for(let n of j.dirtyFiles){var e,t;let l=null!=(e=null==(t=Object.entries(x).find(e=>{let[,t]=e;return!0===t[n];}))?void 0:t[0])?e:j.intent.paneId;if(!(await B(l,n)))return void k({...j,saving:!1,error:"Save failed. The close action was not applied."});}j.apply(),k(null);})());},[x,j,B]),V=(0,i.useCallback)(()=>{if(null!==j&&!j.saving){for(let e of j.dirtyFiles){for(let[t,n]of Object.entries(x))!0===n[e]&&O(t,e,!1);(0,cn.Qe)(f,e);}j.apply(),k(null);}},[x,O,j,f]),H=(0,i.useCallback)(()=>{(null==j?void 0:j.saving)!==!0&&k(null);},[null==j?void 0:j.saving]),_=(0,i.useCallback)(e=>{var t;let n=e.trim();0===n.length||K({paneId:null!=(t=tU(y.current)[0])?t:y.current.activePaneId,files:q,reason:"root-change",apply:()=>{let e=t3(y.current,{type:"replace-root",root:n,sidebarWidth:y.current.sidebarWidth});g(n),w({}),L(e,n);}});},[L,q,K]),G=(0,i.useCallback)((e,t)=>{let n=function(e,t){let n=tI(e.trim()),l=t$(n,t);switch(l.kind){case"relative":return n.length>0?{root:n,file:l.path}:null;case"root":case"empty":return n.length>0?{root:n,file:""}:null;case"outside-root":{let e,t,n=l.candidate;if(!tR(n))return null;let a=(e=n.lastIndexOf("/"))<0?"":0===e?"/":n.slice(0,e),r=(t=n.lastIndexOf("/"))<0?n:n.slice(t+1);if(0===a.length||!tE(r))return null;return{root:a,file:r};}}}(e,t);if(null===n||0===n.file.length)return;let l=tH(y.current).id,a=t3(y.current,{type:"open-file",paneId:l,file:n.file});g(n.root),L(a,n.root);},[L]),J=(0,i.useCallback)((e,t)=>{0!==f.length&&0!==t.length&&L(t3(y.current,{type:"select-file",paneId:e,file:t}));},[L,f]),Y=(0,i.useCallback)(e=>{let{op:t,mutation:n}=e;"rename"===t&&void 0!==n.previousPath&&n.previousPath!==n.path?(L(t3(y.current,{type:"rename-file",from:n.previousPath,to:n.path})),(0,cn.Qe)(f,n.previousPath)):"delete"===t&&(L(t3(y.current,{type:"remove-file",file:n.path})),(0,cn.Qe)(f,n.path));},[L,f]),X=(0,i.useCallback)((e,t)=>{if(0===t.length)return;let n=M.current.filter(e=>e.file!==t);n.push({paneId:e,file:t}),M.current=n.slice(-20);},[]),Z=(0,i.useCallback)(async(e,t)=>K({paneId:e,files:[t],reason:"tab-close",apply:()=>{O(e,t,!1),X(e,t),L(t3(y.current,{type:"close-tab",paneId:e,file:t}));}}),[L,O,X,K]),Q=(0,i.useCallback)((e,t)=>{L(t3(y.current,{type:"split-pane",paneId:e,direction:t}));},[L]),ee=(0,i.useCallback)(e=>{let t=y.current.panes[e];void 0!==t&&K({paneId:e,files:t.openFiles,reason:"pane-close",apply:()=>{for(let n of t.openFiles)X(e,n);w(t=>{let{[e]:n,...l}=t;return l;}),L(t3(y.current,{type:"close-pane",paneId:e}));}});},[L,X,K]),et=(0,i.useCallback)(()=>{L(t3(y.current,{type:"set-sidebar",collapsed:!y.current.sidebarCollapsed}));},[L]),en=(0,i.useRef)(null),el=(0,i.useRef)(null),ea=(0,i.useCallback)(e=>{let t=T.current;if(null===t)return;let n=ci(e-t.getBoundingClientRect().left,180,440);t.style.setProperty("--ed-sidebar-width",`${String(n)}px`),el.current=n;},[]),er=(0,i.useCallback)(()=>{let e=el.current;el.current=null,null!==e&&L(t3(y.current,{type:"set-sidebar",width:e,collapsed:!1}));},[L]),ei=(0,i.useCallback)(e=>{1===e.buttons&&ea(e.clientX);},[ea]),es=(0,i.useCallback)(e=>{L(t3(y.current,{type:"set-sidebar",width:ci(y.current.sidebarWidth+e,180,440),collapsed:!1}));},[L]),eo=(0,i.useCallback)((e,t,n,l)=>{let a=t.getBoundingClientRect(),r=ci("row"===e.direction?(n-a.left)/a.width*100:(l-a.top)/a.height*100,15,85);t.style.setProperty("--ed-split-ratio",`${String(r)}%`),en.current={splitId:e.id,ratio:r};},[]),ec=(0,i.useCallback)(()=>{let e=en.current;en.current=null,null!==e&&L(t3(y.current,{type:"resize-split",splitId:e.splitId,ratio:e.ratio}));},[L]),ed=(0,i.useCallback)((e,t)=>{L(t3(y.current,{type:"resize-split",splitId:e.id,ratio:ci(e.ratio+t,15,85)}));},[L]),eu=(0,i.useCallback)(e=>{e.preventDefault();let t=e=>ea(e.clientX),n=()=>{window.removeEventListener("mousemove",t),window.removeEventListener("mouseup",n),er();};window.addEventListener("mousemove",t),window.addEventListener("mouseup",n,{once:!0});},[ea,er]),ep=(0,i.useCallback)((e,t)=>{t.preventDefault();let n=t.currentTarget.parentElement;if(null===n)return;let l=t=>eo(e,n,t.clientX,t.clientY),a=()=>{window.removeEventListener("mousemove",l),window.removeEventListener("mouseup",a),ec();};window.addEventListener("mousemove",l),window.addEventListener("mouseup",a,{once:!0});},[eo,ec]),em=(0,i.useCallback)(e=>{let t=e.shiftKey?32:12;"ArrowLeft"===e.key?(e.preventDefault(),es(-t)):"ArrowRight"===e.key&&(e.preventDefault(),es(t));},[es]),eh=(0,i.useCallback)((e,t)=>{let n=t.shiftKey?10:2,l="row"===e.direction?"ArrowLeft":"ArrowUp",a="row"===e.direction?"ArrowRight":"ArrowDown";t.key===l?(t.preventDefault(),ed(e,-n)):t.key===a&&(t.preventDefault(),ed(e,n));},[ed]),ef=(0,i.useCallback)(e=>{e.currentTarget.setPointerCapture(e.pointerId);},[]),eg=(0,i.useCallback)(e=>{e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId);},[]),ev=(0,i.useCallback)((e,t,n)=>{if(!n.altKey)return;let l=y.current.panes[e];if(void 0!==l&&("ArrowLeft"===n.key||"ArrowRight"===n.key)){n.preventDefault();let a=tU(y.current);if(n.shiftKey){let l=a.indexOf(e),r="ArrowLeft"===n.key?a[l-1]:a[l+1];void 0!==r&&L(t3(y.current,{type:"move-tab",fromPaneId:e,toPaneId:r,file:t}));return;}let r=l.tabOrder.indexOf(t),i="ArrowLeft"===n.key?r-1:r+1;L(t3(y.current,{type:"reorder-tab",paneId:e,file:t,targetIndex:i}));}},[L]),eb=(0,i.useCallback)((e,t,n)=>{n.preventDefault(),null!==N&&(L(t3(y.current,{type:"drop-tab",intent:{fromPaneId:N.paneId,toPaneId:e,file:N.file,zone:t}})),S(null));},[L,N]),ey=(0,i.useCallback)((e,t,n)=>{L(t3(y.current,{type:"move-tab",fromPaneId:e,toPaneId:t,file:n}));},[L]),ex=(0,i.useCallback)(()=>{let e=tH(y.current);e.activeFile.length>0&&Z(e.id,e.activeFile);},[Z]),ew=(0,i.useCallback)(e=>{let t=tH(y.current),n=t.tabOrder;if(n.length<2)return;let l=n.indexOf(t.activeFile),a=n[(l+e+n.length)%n.length];void 0!==a&&J(t.id,a);},[J]),ej=(0,i.useCallback)(()=>{let e=M.current.pop();void 0!==e&&G(f,e.file);},[G,f]),ek=(0,i.useCallback)(()=>{for(let[e,t]of Object.entries(x))for(let n of Object.keys(t))B(e,n);},[x,B]),eN=(0,i.useCallback)(e=>Q(tH(y.current).id,e),[Q]),eS=(0,i.useCallback)(()=>ee(tH(y.current).id),[ee]),eC=(0,i.useCallback)(()=>D({mode:"files"}),[]),eR=(0,i.useCallback)(()=>D({mode:"commands"}),[]),eI={root:f,activePaneId:v.activePaneId,paneCount:tU(v).length,activeFile:z.length>0?z:null,closedTabCount:M.current.length,dirtyCount:q.length,openQuickOpen:eC,openCommandPalette:eR,splitActive:eN,closeActiveSplit:eS,closeActiveTab:ex,nextTab:()=>ew(1),prevTab:()=>ew(-1),reopenClosed:ej,saveAll:ek},eE=(0,i.useRef)(eI);eE.current=eI,(0,i.useEffect)(()=>{let e=T.current;if(null===e)return;let t=e=>{if(!(e.metaKey||e.ctrlKey))return;let t=eE.current,n=e.key.toLowerCase();if("p"===n&&!e.altKey){e.preventDefault(),e.stopPropagation(),e.shiftKey?t.openCommandPalette():t.openQuickOpen();return;}if(!e.altKey)return;let l=t=>{e.preventDefault(),e.stopPropagation(),t();};"arrowright"===n?l(t.nextTab):"arrowleft"===n?l(t.prevTab):"t"===n?l(t.reopenClosed):"\\"===n?l(()=>t.splitActive("row")):"s"===n&&l(t.saveAll);};return e.addEventListener("keydown",t,!0),()=>e.removeEventListener("keydown",t,!0);},[f]);let e$=(0,i.useMemo)(()=>Object.values(v.panes).map(e=>({paneId:e.id,activeFile:e.activeFile.length>0?e.activeFile:null,openFiles:e.openFiles})),[v.panes]),eA=tU(v).length,eT=(0,i.useMemo)(()=>{let e=new Map();for(let t of Object.values(v.panes)){let n=t.id;e.set(n,{onSelectOpenFile:e=>J(n,e),onCloseOpenFile:e=>Z(n,e),onDirtyChange:(e,t)=>O(n,e,t),onMoveTab:(e,t,n)=>ey(e,n,t),onSplitPane:(e,t)=>Q(e,t),toolbarExtras:function(e,t,n,l){return(0,r.jsxs)("span",{className:"ed-pane-actions","aria-label":"Editor split controls",children:[(0,r.jsx)("button",{type:"button",className:"ed-icon-action ui-tip","aria-label":`Split ${e.activeFile||"editor"} right`,"data-tip":"Split right",onClick:()=>n(e.id,"row"),children:(0,r.jsx)($.F.split,{size:14})}),(0,r.jsx)("button",{type:"button",className:"ed-icon-action ui-tip","aria-label":`Split ${e.activeFile||"editor"} down`,"data-tip":"Split down",onClick:()=>n(e.id,"column"),children:(0,r.jsx)($.F.panelDown,{size:14})}),t?(0,r.jsx)("button",{type:"button",className:"ed-icon-action ui-tip","aria-label":`Close split ${e.activeFile||"editor"}`,"data-tip":"Close split",onClick:()=>l(e.id),children:(0,r.jsx)($.F.close,{size:14})}):null]});}(t,eA>1,Q,ee),renderTabHandle:(e,t,l)=>({draggable:!0,onDragStart:t=>{t.dataTransfer.effectAllowed="move",t.dataTransfer.setData("text/plain",e),S({paneId:n,file:e});},onDragEnd:()=>S(null),onKeyDown:t=>ev(n,e,t),"data-active":t?"true":"false","data-dirty":l?"true":"false"})});}return e;},[v.panes,eA,J,Z,O,ey,Q,ee,ev]);if(0===f.length)return(0,r.jsx)(cr,{...d});let eF=e=>{if("pane"===e.type){let t=v.panes[e.paneId];return void 0===t?null:(e=>{var t;let n=eT.get(e.id);if(void 0===n)return null;let l={...d,root:f,...(e.activeFile.length>0?{file:e.activeFile}:{}),openFiles:e.openFiles,dirtyFiles:q,windowId:`${null!=(t=d.windowId)?t:"editor"}-${e.id}`,paneId:e.id,layoutPanes:e$,activePaneId:v.activePaneId,onSelectOpenFile:n.onSelectOpenFile,onSplitPane:n.onSplitPane,onMoveTab:n.onMoveTab,onCloseOpenFile:n.onCloseOpenFile,onDirtyChange:n.onDirtyChange,toolbarExtras:n.toolbarExtras,externalSaveRequest:null!==C&&C.paneId===e.id?C:void 0,onExternalSaveComplete:W,renderTabHandle:n.renderTabHandle};return(0,r.jsxs)("section",{className:"ed-pane","data-active":e.id===v.activePaneId?"true":"false","data-dragging":null===N?"false":"true",children:[(0,r.jsx)("div",{className:"ed-pane-drop-zones","aria-hidden":"true",children:["left","right","top","bottom","center"].map(t=>(0,r.jsx)("button",{type:"button",className:`ed-pane-drop-zone ${t}`,tabIndex:-1,"aria-label":`Drop tab ${t}`,onDragOver:e=>e.preventDefault(),onDrop:n=>eb(e.id,t,n)},t))}),(0,r.jsx)(cr,{...l})]},e.id);})(t);}return(0,r.jsxs)("div",{className:`ed-panes ${e.direction}`,"data-split-id":e.id,style:{"--ed-split-ratio":`${String(e.ratio)}%`},children:[eF(e.first),(0,r.jsx)("button",{type:"button",className:"ed-pane-resizer ui-tip",role:"separator","aria-label":"Resize editor split","aria-orientation":"row"===e.direction?"vertical":"horizontal","aria-valuemin":15,"aria-valuemax":85,"aria-valuenow":Math.round(e.ratio),"data-tip":"Resize editor split",onPointerDown:ef,onPointerMove:t=>{if(1!==t.buttons)return;let n=t.currentTarget.parentElement;null!==n&&eo(e,n,t.clientX,t.clientY);},onPointerUp:e=>{eg(e),ec();},onPointerCancel:e=>{eg(e),ec();},onMouseDown:t=>ep(e,t),onKeyDown:t=>eh(e,t)}),eF(e.second)]});},eD=1===tU(v).length;return(0,r.jsxs)("div",{className:`editor-workspace${v.sidebarCollapsed?" sidebar-collapsed":""}`,ref:T,style:{"--ed-sidebar-width":`${String(v.sidebarWidth)}px`},children:[v.sidebarCollapsed?(0,r.jsx)("button",{type:"button",className:"ed-sidebar-restore ui-tip","aria-label":"Show project tree","data-tip":"Show project tree",onClick:et,children:(0,r.jsx)($.F.sidebar,{size:15})}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("aside",{className:"ed-sidebar","aria-label":"Editor files",children:[(0,r.jsx)("div",{className:"ed-sidebar-chrome",children:(0,r.jsx)("button",{type:"button",className:"ed-icon-action ui-tip","aria-label":"Hide project tree","data-tip":"Hide project tree",onClick:et,children:(0,r.jsx)($.F.sidebar,{size:14})})}),(0,r.jsx)(ce,{root:f,activeFilePath:z.length>0?z:void 0,openFilesDirectly:!0,onRootChange:_,onOpenFile:G,onFilesMutated:Y})]}),(0,r.jsx)("button",{type:"button",className:"ed-sidebar-resizer ui-tip","aria-label":"Resize project tree","data-tip":"Resize project tree",onPointerDown:ef,onPointerMove:ei,onPointerUp:e=>{eg(e),er();},onPointerCancel:e=>{eg(e),er();},onMouseDown:eu,onKeyDown:em})]}),(0,r.jsx)("div",{className:"ed-main",children:(0,r.jsx)("div",{className:`ed-panes ed-panes-root${eD?" single":""}`,children:eF(v.tree)})}),null!==j?(0,r.jsx)(cp,{pending:j,onSave:U,onDiscard:V,onCancel:H}):null,null!==F?(0,r.jsx)(ca,{mode:F.mode,root:f,host:eI,onOpenFile:G,onClose:()=>D(null)}):null]});}async function ch(e,t){var n,l;let a=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),r="GET"!==a&&"HEAD"!==a,i=await fetch(e,{...t,headers:{Accept:"application/json",...(r?{"Content-Type":"application/json"}:{}),...(r?{"X-Keiko-CSRF":"1"}:{}),...(null!=(l=null==t?void 0:t.headers)?l:{})}});if(!i.ok){let e="INTERNAL",t=`HTTP ${i.status.toString()}`;try{let n=await i.json();e=n.error.code,t=n.error.message;}catch{}throw new m.hD(e,t,i.status);}if(204!==i.status)return i.json();}async function cf(e){return ch(`/api/browser/status?port=${encodeURIComponent(String(e))}`);}async function cg(e){return ch("/api/browser/sessions",{method:"POST",body:JSON.stringify({port:e})});}async function cv(e){await ch(`/api/browser/sessions/${encodeURIComponent(e)}`,{method:"DELETE"});}async function cb(e,t){return ch(`/api/browser/sessions/${encodeURIComponent(e)}/navigate`,{method:"POST",body:JSON.stringify({url:t})});}async function cy(e){return ch(`/api/browser/sessions/${encodeURIComponent(e)}/screenshot`,{method:"POST",body:JSON.stringify({})});}async function cx(e,t){return ch(`/api/browser/sessions/${encodeURIComponent(e)}/apply`,{method:"POST",body:JSON.stringify({captureSeq:t})});}async function cw(e){return ch(`/api/browser/sessions/${encodeURIComponent(e)}/content`,{method:"POST",body:JSON.stringify({})});}function cj(e){return e instanceof m.hD?{code:e.code,message:e.message}:e instanceof Error?{code:"INTERNAL",message:e.message}:{code:"INTERNAL",message:"Unexpected error."};}function ck(e){var t,n;let l=null!=(t=e.cdpPort)?t:9222,a=null!=(n=e.url)?n:"http://localhost:5173",[s,o]=(0,i.useState)(String(l)),[c,d]=(0,i.useState)(a),[u,p]=(0,i.useState)(null),[m,h]=(0,i.useState)(null),[f,g]=(0,i.useState)(!1),[v,b]=(0,i.useState)(null),[y,x]=(0,i.useState)(null),[w,j]=(0,i.useState)([]),[k,N]=(0,i.useState)(null),[S,C]=(0,i.useState)(null),[R,I]=(0,i.useState)(null),E=(0,i.useRef)(null),$=(0,i.useCallback)(()=>{x(null);},[]),A=(0,i.useCallback)(e=>{j(t=>{let n=[...t,e];return n.length>50?n.slice(n.length-50):n;}),"navigated"===e.kind&&"string"==typeof e.payload.originOnly&&I(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,i.useEffect)(()=>{var e,t;if(null===u){null==(e=E.current)||e.close(),E.current=null;return;}let n=new EventSource((t=u.sessionId,`/api/browser/sessions/${encodeURIComponent(t)}/events`));for(let e of["session-opened","navigated","screenshot-captured","page-content-captured","session-closed","trust-warning","error"])n.addEventListener(`browser:${e}`,e=>{try{let t=JSON.parse(e.data);A(t);}catch{}});return E.current=n,()=>{n.close(),E.current=null;};},[u,A]);let T=(0,i.useCallback)(async()=>{$(),g(!0);try{let e=Number.parseInt(s,10),t=await cf(e);h(t);}catch(e){x(cj(e));}finally{g(!1);}},[s,$]),F=(0,i.useCallback)(async()=>{$(),g(!0);try{let e=Number.parseInt(s,10),t=await cg(e);p(t),j([]),C(null),I(null);}catch(e){x(cj(e));}finally{g(!1);}},[s,$]),D=(0,i.useCallback)(async()=>{if(null!==u){$(),g(!0);try{await cv(u.sessionId),p(null),N(null),C(null),I(null);}catch(e){x(cj(e));}finally{g(!1);}}},[u,$]),M=(0,i.useCallback)(async()=>{if(null!==u){$(),g(!0);try{let e=await cb(u.sessionId,c);I(e.originOnly);}catch(e){x(cj(e));}finally{g(!1);}}},[u,c,$]),P=(0,i.useCallback)(async()=>{if(null!==u){$(),g(!0);try{let e=await cy(u.sessionId);e.persisted||N({seq:e.seq,dataBase64:e.dataBase64});}catch(e){x(cj(e));}finally{g(!1);}}},[u,$]),L=(0,i.useCallback)(async()=>{if(null!==u&&null!==k){$(),g(!0);try{let e=await cx(u.sessionId,k.seq);e.persisted&&C(e.path),N(null);}catch(e){x(cj(e));}finally{g(!1);}}},[u,k,$]),q=(0,i.useCallback)(async()=>{if(null!==u){$(),g(!0);try{await cw(u.sessionId);}catch(e){x(cj(e));}finally{g(!1);}}},[u,$]),z=(0,i.useMemo)(()=>f||null!==u,[f,u]),O=(0,i.useMemo)(()=>f||null===u,[f,u]),B=f||null!==u,W=f||null===k,K=f&&null!==v?v:null!==k?"Screenshot ready (dry-run) — press Apply to persist.":null!==S?`Persisted as ${S}.`:null!==R?`Current origin: ${R}`:null!==m&&null===u?`Reachable: ${m.reachable?"yes":"no"}`:"";return(0,r.jsxs)("div",{className:"browser",children:[(0,r.jsxs)("div",{className:"bw-bar",children:[(0,r.jsx)("span",{className:"bw-dot",style:{background:null===u?"var(--line-strong)":"var(--ok)"},"aria-hidden":"true"}),(0,r.jsxs)("label",{className:"bw-field",children:[(0,r.jsx)("span",{className:"bw-field-label",children:"Port"}),(0,r.jsx)("input",{type:"text",inputMode:"numeric",className:"bw-input",value:s,onChange:e=>o(e.target.value),disabled:null!==u||f})]}),(0,r.jsxs)("label",{className:"bw-field bw-field-url",children:[(0,r.jsx)("span",{className:"bw-field-label",children:"URL"}),(0,r.jsx)("input",{type:"url",className:"bw-input bw-input-url",value:c,onChange:e=>d(e.target.value),disabled:f})]})]}),(0,r.jsxs)("div",{className:"bw-actions",role:"group","aria-label":"Browser actions",children:[(0,r.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{B||(b("Checking Chrome…"),T());},"aria-disabled":B,children:"Check"}),(0,r.jsx)("button",{type:"button",className:"bw-btn bw-btn-primary",onClick:()=>{z||(b("Opening session…"),F());},"aria-disabled":z,children:"Open session"}),(0,r.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{O||(b("Navigating…"),M());},"aria-disabled":O,children:"Navigate"}),(0,r.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{O||(b("Capturing screenshot…"),P());},"aria-disabled":O,children:"Screenshot"}),(0,r.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{W||(b("Applying screenshot…"),L());},"aria-disabled":W,children:"Apply"}),(0,r.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{O||(b("Capturing HTML…"),q());},"aria-disabled":O,children:"Capture HTML"}),(0,r.jsx)("button",{type:"button",className:"bw-btn bw-btn-danger",onClick:()=>{O||(b("Closing session…"),D());},"aria-disabled":O,children:"Close"})]}),(0,r.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite",children:K}),f&&null!==v?(0,r.jsx)("p",{className:"bw-status",children:v}):null,null!==m&&null===u?(0,r.jsxs)("p",{className:"bw-status",children:["Reachable: ",m.reachable?"yes":"no",null===m.browserVersion?"":` — ${m.browserVersion}`]}):null,null!==R?(0,r.jsxs)("p",{className:"bw-status",children:["Current origin: ",(0,r.jsx)("span",{className:"mono",children:R})]}):null,null!==k?(0,r.jsx)("p",{className:"bw-status",children:"Screenshot ready (dry-run) — press Apply to persist."}):null,null!==S?(0,r.jsxs)("p",{className:"bw-status",children:["Persisted as ",(0,r.jsx)("span",{className:"mono",children:S}),"."]}):null,null!==y?(0,r.jsxs)("div",{className:"bw-error",role:"alert",children:[y.message," ",(0,r.jsxs)("span",{className:"err-code mono",children:["(",y.code,")"]})]}):null,(0,r.jsx)("div",{className:"bw-view",children:null!==k?(0,r.jsx)("img",{className:"bw-screenshot",src:`data:image/png;base64,${k.dataBase64}`,alt:"Pending screenshot preview"}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"ph-stripes","aria-hidden":"true"}),(0,r.jsx)("div",{className:"bw-overlay mono",children:null===u?"No session — choose a port and press Open session":"Session open — use Screenshot to capture a preview"})]})}),(0,r.jsx)("div",{className:"bw-log",role:"log","aria-label":"Browser event log",children:(0,r.jsx)("ul",{className:"bw-log-list",children:w.slice(-10).reverse().map((e,t)=>(0,r.jsxs)("li",{className:"bw-log-item",children:[(0,r.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,r.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?` (${String(t.httpStatus)})`:"";return`${e}${n}`;}return"screenshot-captured"===e.kind?!0===t.persisted?"persisted":"dry-run":"page-content-captured"===e.kind?"number"==typeof t.byteLength?`${String(t.byteLength)} bytes`:"":"error"===e.kind||"trust-warning"===e.kind?"string"==typeof t.message?t.message:"string"==typeof t.warning?t.warning:"":"";}(e)})]},`${String(e.kind)}-${String(t)}`))})})]});}async function cN(e,t){var n,l;let a=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),r="GET"!==a&&"HEAD"!==a,i=await fetch(e,{...t,headers:{Accept:"application/json",...(r?{"Content-Type":"application/json"}:{}),...(r?{"X-Keiko-CSRF":"1"}:{}),...(null!=(l=null==t?void 0:t.headers)?l:{})}});if(!i.ok){let e="INTERNAL",t=`HTTP ${i.status.toString()}`;try{let n=await i.json();e=n.error.code,t=n.error.message;}catch{}throw new m.hD(e,t,i.status);}if(204!==i.status)return i.json();}async function cS(){return cN("/api/terminal/policy");}async function cC(e,t){let n=new URLSearchParams();return n.set("projectId",e),void 0!==t&&t.length>0&&n.set("path",t),cN(`/api/terminal/directories?${n.toString()}`);}async function cR(e){return cN("/api/terminal/executions",{method:"POST",body:JSON.stringify(e)});}async function cI(e){await cN(`/api/terminal/executions/${encodeURIComponent(e)}`,{method:"DELETE"});}function cE(e){return e instanceof m.hD?{code:e.code,message:e.message}:e instanceof Error?{code:"INTERNAL",message:e.message}:{code:"INTERNAL",message:"Unexpected error."};}function c$(e){var t,n,l;let[a,s]=(0,i.useState)(null),[o,c]=(0,i.useState)(""),[d,u]=(0,i.useState)(""),[p,m]=(0,i.useState)(null!=(t=e.cwd)?t:""),[h,f]=(0,i.useState)(null!=(n=e.projectPath)?n:""),[g,v]=(0,i.useState)(!1),[b,y]=(0,i.useState)(null),[x,w]=(0,i.useState)(null),[j,k]=(0,i.useState)(null),[N,S]=(0,i.useState)([]),C=(0,i.useRef)(null),R=(0,i.useRef)(!1),I=(0,i.useRef)(null),[E,$]=(0,i.useState)([]);(0,i.useEffect)(()=>{let e=!1;return cS().then(t=>{e||(s(t),c(e=>{var n;return e.length>0?e:null!=(n=t.commands[0])?n:"";}));}).catch(t=>{e||k(cE(t));}),()=>{e=!0;};},[]),(0,i.useEffect)(()=>{if(0===h.length)return void $([]);let e=!1;return cC(h,p.length>0?p:void 0).then(t=>{e||$(t.entries);}).catch(()=>{e||$([]);}),()=>{e=!0;};},[h,p]),(0,i.useEffect)(()=>{let e=new EventSource("/api/terminal/events");C.current=e;let t=e=>{try{let t=JSON.parse(e.data);if("execution-started"===t.kind&&R.current){let e=t.payload;"string"==typeof e.requestId&&e.requestId===I.current&&y(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===I.current&&y(e=>null===e||e!==t.executionId?e:null);}S(e=>{let n=[t,...e];return n.length>30?n.slice(0,30):n;});}catch{}};for(let n of["execution-started","execution-completed","execution-failed","execution-cancelled"])e.addEventListener(`terminal:${n}`,t);return()=>{e.close(),C.current=null;};},[]);let A=(0,i.useCallback)(async e=>{let t;if(e.preventDefault(),g)return;k(null),w(null),y(null);let n="function"==typeof crypto.randomUUID?crypto.randomUUID():`terminal-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;I.current=n;let l=0===(t=d.trim()).length?[]:t.split(/\s+/);R.current=!0,v(!0);try{let e={projectId:h,command:o,args:l,...(p.length>0?{cwd:p}:{}),requestId:n},t=await cR(e);w(t);}catch(e){k(cE(e));}finally{R.current=!1,v(!1),I.current=null,y(null);}},[d,o,p,h,g]),T=(0,i.useCallback)(async()=>{if(null!==b)try{await cI(b);}catch(e){k(cE(e));}},[b]),F=(0,i.useMemo)(()=>{var e;return null!=(e=null==a?void 0:a.limits)?e:null;},[a]),D=(0,i.useRef)(null),M=(0,i.useRef)(!1);return(0,i.useEffect)(()=>{if(M.current&&!g&&document.activeElement===document.body){var e;null==(e=D.current)||e.focus();}M.current=g;},[g]),(0,r.jsxs)("div",{className:"terminal",children:[(0,r.jsxs)("form",{className:"tm-form",onSubmit:e=>void A(e),children:[(0,r.jsxs)("label",{className:"tm-field",children:[(0,r.jsx)("span",{children:"Project path"}),(0,r.jsx)("input",{type:"text",value:h,onChange:e=>f(e.target.value),placeholder:"/absolute/path/to/project",required:!0})]}),(0,r.jsxs)("div",{className:"tm-field",children:[(0,r.jsx)("span",{children:"Command"}),(0,r.jsx)(ln.A,{value:o,ariaLabel:"Command",disabled:null===a,menuTitle:"Allowed commands",mono:!0,sections:[{options:null!=(l=null==a?void 0:a.commands.map(e=>({value:e,label:e})))?l:[]}],onValueChange:c})]}),(0,r.jsxs)("label",{className:"tm-field",children:[(0,r.jsx)("span",{children:"Args (space-separated)"}),(0,r.jsx)("input",{type:"text",value:d,onChange:e=>u(e.target.value),placeholder:"e.g. -la src"})]}),(0,r.jsxs)("label",{className:"tm-field",children:[(0,r.jsx)("span",{children:"Working directory (optional)"}),(0,r.jsx)("input",{type:"text",value:p,onChange:e=>m(e.target.value),placeholder:"(project root)",list:"tm-cwd-suggestions"}),(0,r.jsx)("datalist",{id:"tm-cwd-suggestions",children:E.map(e=>(0,r.jsx)("option",{value:e.path},e.path))})]}),(0,r.jsxs)("div",{className:"tm-actions",children:[(0,r.jsx)("button",{type:"submit",className:"tm-action","data-primary":"true",ref:D,disabled:null===a,"aria-disabled":g||null===a,children:g?"Running…":"Run"}),g?(0,r.jsx)("button",{type:"button",className:"tm-action","aria-disabled":null===b,onClick:()=>void T(),children:"Cancel"}):null]}),null!==F?(0,r.jsxs)("p",{className:"tm-limits",children:["Limits: ",(0,aQ.z3)(F.maxOutputBytes)," output \xb7"," ",(0,aQ._V)(F.defaultTimeoutMs)," timeout"]}):null]}),null!==j?(0,r.jsxs)("div",{className:"tm-error",role:"alert",children:[(0,r.jsxs)("span",{className:"tm-error-text",children:[j.message," ",(0,r.jsxs)("span",{className:"err-code mono",children:["(",j.code,")"]})]}),(0,r.jsx)("button",{type:"button",className:"tm-error-dismiss","aria-label":"Dismiss error",onClick:()=>k(null),children:"✕"})]}):null,(0,r.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite",children:null!==x?`Command finished: exit ${String(x.exitCode)}, ${String(x.durationMs)} ms${x.truncated?", output truncated":""}${x.timedOut?", timed out":""}`:""}),null!==x?(0,r.jsxs)("div",{className:"tm-result",children:[(0,r.jsxs)("div",{className:"tm-badges",children:[(0,r.jsxs)("span",{className:0===x.exitCode?"tm-badge tm-badge-ok":"tm-badge tm-badge-fail",children:["exit ",String(x.exitCode)]}),(0,r.jsxs)("span",{className:"tm-badge",children:[x.durationMs," ms"]}),x.truncated?(0,r.jsx)("span",{className:"tm-badge tm-badge-warn",children:"truncated"}):null,x.timedOut?(0,r.jsx)("span",{className:"tm-badge tm-badge-warn",children:"timed out"}):null]}),x.stdout.length>0?(0,r.jsx)("pre",{className:"tm-stdout",children:x.stdout}):null,x.stderr.length>0?(0,r.jsx)("pre",{className:"tm-stderr",children:x.stderr}):null]}):null,(0,r.jsx)("ul",{className:"tm-events",role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":"false","aria-label":"Recent terminal events",children:N.map((e,t)=>{var n;let l;return(0,r.jsxs)("li",{className:"tm-event",children:[(0,r.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,r.jsx)("span",{className:"tm-event-detail",children:(l=(n=e).payload,"execution-completed"===n.kind?["number"==typeof l.exitCode||null===l.exitCode?`exit ${String(l.exitCode)}`:"","number"==typeof l.durationMs?`${String(l.durationMs)}ms`:""].filter(Boolean).join(" \xb7 "):"execution-failed"===n.kind?"string"==typeof l.code?l.code:"":"execution-started"===n.kind&&"string"==typeof l.command?l.command:"")})]},`${e.executionId}-${String(t)}-${e.kind}`);})})]});}async function cA(e,t){var n,l;let a=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),r="GET"!==a&&"HEAD"!==a,i=await fetch(e,{...t,headers:{Accept:"application/json",...(r?{"Content-Type":"application/json"}:{}),...(r?{"X-Keiko-CSRF":"1"}:{}),...(null!=(l=null==t?void 0:t.headers)?l:{})}});if(!i.ok){let e="INTERNAL",t=`HTTP ${i.status.toString()}`;try{let n=await i.json();e=n.error.code,t=n.error.message;}catch{}throw new m.hD(e,t,i.status);}if(204!==i.status)return i.json();}async function cT(e){let t=new URLSearchParams();return t.set("projectId",e),cA(`/api/commands/catalog?${t.toString()}`);}async function cF(e){return cA("/api/commands/runs",{method:"POST",body:JSON.stringify(e)});}async function cD(e){await cA(`/api/commands/runs/${encodeURIComponent(e)}`,{method:"DELETE"});}function cM(e){return e instanceof m.hD?{code:e.code,message:e.message}:e instanceof Error?{code:"INTERNAL",message:e.message}:{code:"INTERNAL",message:"Unexpected error."};}function cP(e,t){return null!==t&&"string"==typeof e.payload.requestId&&e.payload.requestId===t;}function cL(e){var t;let n,[l,a]=(0,i.useState)(null!=(t=e.projectPath)?t:"");(0,i.useEffect)(()=>{var t;a(null!=(t=e.projectPath)?t:"");},[e.projectPath]);let[s,o]=(0,i.useState)([]),[c,d]=(0,i.useState)(""),[u,p]=(0,i.useState)(!1),[m,h]=(0,i.useState)(null),[f,g]=(0,i.useState)(null),[v,b]=(0,i.useState)(null),[y,x]=(0,i.useState)([]),w=(0,i.useRef)(!1),j=(0,i.useRef)(null),k=(0,i.useRef)(null),N=(0,i.useRef)(!1);(0,i.useEffect)(()=>{if(0===l.length)return void o([]);let e=!1;return cT(l).then(t=>{e||(o(t.tasks),d(e=>{var n,l;return e.length>0?e:null!=(n=null==(l=t.tasks[0])?void 0:l.id)?n:"";}));}).catch(t=>{e||(o([]),b(cM(t)));}),()=>{e=!0;};},[l]),(0,i.useEffect)(()=>{let e=new EventSource("/api/commands/events"),t=e=>{let t;try{t=JSON.parse(e.data);}catch{return;}"run-started"===t.kind&&w.current&&cP(t,j.current)&&h(e=>null!=e?e:t.runId),"run-started"!==t.kind&&cP(t,j.current)&&h(e=>e===t.runId?null:e),x(e=>[t,...e].slice(0,30));};for(let n of["run-started","run-completed","run-failed","run-cancelled"])e.addEventListener(`command:${n}`,t);return()=>{e.close();};},[]),(0,i.useEffect)(()=>{if(N.current&&!u&&document.activeElement===document.body){var e;null==(e=k.current)||e.focus();}N.current=u;},[u]);let S=(0,i.useCallback)(async e=>{if(e.preventDefault(),u||w.current||0===c.length)return;b(null),g(null),h(null);let t="function"==typeof crypto.randomUUID?crypto.randomUUID():`command-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;j.current=t,w.current=!0,p(!0);try{let e=await cF({projectId:l,taskId:c,requestId:t});g(e);}catch(e){b(cM(e));}finally{w.current=!1,p(!1),j.current=null,h(null);}},[l,u,c]),C=(0,i.useCallback)(async()=>{if(null!==m)try{await cD(m);}catch(e){b(cM(e));}},[m]);return(0,r.jsxs)("div",{className:"terminal commands",children:[(0,r.jsxs)("form",{className:"tm-form",onSubmit:e=>void S(e),children:[(0,r.jsxs)("label",{className:"tm-field",children:[(0,r.jsx)("span",{children:"Project path"}),(0,r.jsx)("input",{type:"text",value:l,onChange:e=>a(e.target.value),placeholder:"/absolute/path/to/project",required:!0})]}),(0,r.jsxs)("div",{className:"tm-field",children:[(0,r.jsx)("span",{children:"Task"}),(0,r.jsx)(ln.A,{value:c,ariaLabel:"Task",disabled:0===s.length,menuTitle:"Discovered tasks",mono:!0,sections:[{options:s.map(e=>({value:e.id,label:`${e.kind} \xb7 ${e.label}`}))}],onValueChange:d})]}),(0,r.jsxs)("div",{className:"tm-actions",children:[(0,r.jsx)("button",{type:"submit",className:"tm-action","data-primary":"true",ref:k,disabled:u||0===s.length||0===c.length,"aria-disabled":u||0===s.length||0===c.length,children:u?"Running…":"Run task"}),u?(0,r.jsx)("button",{type:"button",className:"tm-action",disabled:null===m,"aria-disabled":null===m,onClick:()=>void C(),children:"Cancel"}):null]}),0===s.length&&l.length>0&&null===v?(0,r.jsx)("p",{className:"tm-limits",role:"status",children:"No runnable test, build, or run tasks were discovered for this project."}):null]}),null!==v?(0,r.jsxs)("div",{className:"tm-error",role:"alert",children:[(0,r.jsxs)("span",{className:"tm-error-text",children:[v.message," ",(0,r.jsxs)("span",{className:"err-code mono",children:["(",v.code,")"]})]}),(0,r.jsx)("button",{type:"button",className:"tm-error-dismiss","aria-label":"Dismiss error",onClick:()=>b(null),children:"✕"})]}):null,(0,r.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite",children:null!==f?(n=[`exit ${String(f.exitCode)}`,`${String(f.durationMs)} ms`],f.truncated&&n.push("output truncated"),f.timedOut&&n.push("timed out"),n.push(f.failureReason),n.push(`run ${f.runId}`,`task ${f.taskId}`),`Run finished: ${n.join(", ")}`):""}),null!==f?(0,r.jsxs)("div",{className:"tm-result",children:[(0,r.jsxs)("div",{className:"tm-badges",children:[(0,r.jsxs)("span",{className:0===f.exitCode?"tm-badge tm-badge-ok":"tm-badge tm-badge-fail",children:["exit ",String(f.exitCode)]}),(0,r.jsxs)("span",{className:"tm-badge",children:[f.durationMs," ms"]}),(0,r.jsx)("span",{className:"tm-badge",children:f.failureReason}),(0,r.jsxs)("span",{className:"tm-badge",children:["run ",f.runId]}),(0,r.jsxs)("span",{className:"tm-badge",children:["task ",f.taskId]}),f.truncated?(0,r.jsx)("span",{className:"tm-badge tm-badge-warn",children:"truncated"}):null,f.timedOut?(0,r.jsx)("span",{className:"tm-badge tm-badge-warn",children:"timed out"}):null]}),f.stdout.length>0?(0,r.jsx)("pre",{className:"tm-stdout",children:f.stdout}):null,f.stderr.length>0?(0,r.jsx)("pre",{className:"tm-stderr",children:f.stderr}):null]}):null,(0,r.jsx)("div",{role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":"false","aria-label":"Recent command run events",children:(0,r.jsx)("ul",{className:"tm-events",children:y.map((e,t)=>{var n;let l;return(0,r.jsxs)("li",{className:"tm-event",children:[(0,r.jsx)("span",{className:"tm-event-kind",children:function(e){switch(e){case"run-started":return"started";case"run-completed":return"completed";case"run-failed":return"failed";case"run-cancelled":return"cancelled";}}(e.kind)}),(0,r.jsx)("span",{className:"tm-event-detail",children:(l=(n=e).payload,"run-completed"===n.kind||"run-failed"===n.kind?["string"==typeof l.failureReason?l.failureReason:"","number"==typeof l.durationMs?`${String(l.durationMs)}ms`:""].filter(Boolean).join(" \xb7 "):"")})]},`${e.runId}-${String(t)}-${e.kind}`);})})})]});}function cq(e){let{action:t}=e,n=$.F[t.icon];return(0,r.jsxs)("button",{type:"button",className:"tm-action",disabled:!0===t.disabled,onClick:t.onClick,style:{justifyContent:"flex-start",minHeight:34},children:[(0,r.jsx)(n,{size:14}),(0,r.jsx)("span",{children:t.label})]});}function cz(e){var t;let[n,l]=(0,i.useState)(null!=(t=e.projectPath)?t:"");(0,i.useEffect)(()=>{var t;l(null!=(t=e.projectPath)?t:"");},[e.projectPath]);let a=n.trim(),s=a.length>0,o=[{id:"files",label:"Files & Git diff",icon:"files",onClick:()=>e.onOpenFiles(s?a:void 0)},{id:"commands",label:"Tasks",icon:"terminal",disabled:!s,onClick:()=>e.onOpenCommands(a)},{id:"containers",label:"Containers",icon:"cube",onClick:()=>e.onOpenContainers(s?a:void 0)},{id:"governed-git",label:"Git",icon:"git",disabled:!s,onClick:()=>e.onOpenGovernedGit(a)},{id:"pull-request",label:"Pull Request",icon:"branch",disabled:!s,onClick:()=>e.onOpenPullRequest(a)},{id:"merge",label:"Merge",icon:"check",disabled:!s,onClick:()=>e.onOpenMerge(a)}];return(0,r.jsxs)("div",{className:"terminal commands",children:[(0,r.jsxs)("form",{className:"tm-form",onSubmit:t=>{var n;t.preventDefault(),s&&(null==(n=e.onProjectPathChange)||n.call(e,a));},children:[(0,r.jsxs)("label",{className:"tm-field",children:[(0,r.jsx)("span",{children:"Project path"}),(0,r.jsx)("input",{type:"text",value:n,onChange:e=>l(e.target.value),onBlur:()=>{var t;s&&(null==(t=e.onProjectPathChange)||t.call(e,a));},placeholder:"/absolute/path/to/project"})]}),(0,r.jsx)("div",{role:"group","aria-label":"Runtime actions",style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:8},children:o.map(e=>(0,r.jsx)(cq,{action:e},e.id))}),s?null:(0,r.jsx)("p",{className:"tm-limits",role:"status",children:"Add a project path to enable task and Git workflows."})]}),(0,r.jsx)("div",{role:"region","aria-label":"Runtime audit metadata",children:(0,r.jsxs)("ul",{className:"tm-events",children:[(0,r.jsxs)("li",{className:"tm-event",children:[(0,r.jsx)("span",{className:"tm-event-kind",children:"Commands"}),(0,r.jsx)("span",{className:"tm-event-detail",children:"runId / taskId / exit status"})]}),(0,r.jsxs)("li",{className:"tm-event",children:[(0,r.jsx)("span",{className:"tm-event-kind",children:"Containers"}),(0,r.jsx)("span",{className:"tm-event-detail",children:"runId / taskId / engine / exit status"})]}),(0,r.jsxs)("li",{className:"tm-event",children:[(0,r.jsx)("span",{className:"tm-event-kind",children:"Git"}),(0,r.jsx)("span",{className:"tm-event-detail",children:"policy / approval / evidence ledger"})]})]})})]});}let cO={listRepositories:m.vj,registerRepository:m.gA,cloneRepository:m.eR,listBranches:m.BU,getSummary:m.dF,getHistory:m.Pi,getRemotes:m.uy,getStatus:m.lv,getDiff:m.w2,branchCreate:m.im,branchSwitch:m.IL,stage:m.dW,unstage:m.IP,commitPreview:m.qY,commitExecute:m.zE,syncPreview:m.Cl,syncExecute:m.LV,pushPreview:m.xZ,pushExecute:m.z9,prPreview:m.RA,prExecute:m.ej,mergePreview:m.x0,mergeExecute:m.IO},cB={"mixed-scope":"Mixed scope — changes span several areas","wip-marker":"Work-in-progress marker in the subject","large-change":"Large change — many files staged","empty-body":"No commit body","non-conventional-subject":"Subject is not a conventional-commit type"},cW={"empty-subject":"The subject line is empty","missing-conventional-prefix":"Missing a conventional-commit type prefix","disallowed-type":"The commit type is not allowed","subject-too-long":"The subject line is too long","missing-issue-key":"Missing the required issue key","missing-signoff":"Missing the Signed-off-by trailer"},cK={succeeded:"Succeeded",blocked:"Blocked","approval-required":"Approval required",failed:"Failed","recovery-required":"Recovery required"};function cU(e){return e instanceof m.hD?`${e.message} (${e.code})`:e instanceof Error?e.message:"An unexpected error occurred.";}function cV(e,t){let[n,l]=(0,i.useState)({busy:!1,outcome:null,error:null}),[a,r]=(0,i.useState)(null),[s,o]=(0,i.useState)(null),[c,d]=(0,i.useState)(null),u=(0,i.useRef)(0),p=(0,i.useRef)(0),m=(0,i.useCallback)(e=>{let t=u.current+1;u.current=t,l({busy:!0,outcome:null,error:null}),e().then(e=>{u.current===t&&l({busy:!1,outcome:e,error:null});},e=>{u.current===t&&l({busy:!1,outcome:null,error:cU(e)});});},[]);return{flow:n,preview:a,previewDraft:s,previewError:c,runMutation:m,runPreview:(0,i.useCallback)(n=>{let l=p.current+1;p.current=l,r(null),o(null),d(null),e.commitPreview({projectId:t,messageDraft:n}).then(e=>{p.current===l&&(r(e),o(n));},e=>{p.current===l&&(r(null),o(null),d(cU(e)));});},[e,t]),reset:(0,i.useCallback)(()=>{u.current+=1,p.current+=1,l({busy:!1,outcome:null,error:null}),r(null),o(null),d(null);},[])};}let cH={mergePreview:m.x0,mergeExecute:m.IO},c_={squash:"Squash and merge",rebase:"Rebase and merge","merge-commit":"Create a merge commit","provider-default":"Provider default"};function cG(e){var t;return null!=(t=c_[e])?t:e;}let cJ={display:"flex",flexDirection:"column",gap:"var(--space-2)",padding:"var(--space-3)",border:"1px solid var(--border-default)",borderRadius:"var(--radius-md)",background:"var(--card)"},cY={margin:0,font:"var(--text-label)",color:"var(--text-heading)"},cX={width:"100%",padding:"var(--space-2)",border:"1px solid var(--border-default)",borderRadius:"var(--radius-control)",background:"var(--background-secondary)",color:"var(--text-body)",font:"var(--text-body-sm)"},cZ={display:"flex",gap:"var(--space-2)",flexWrap:"wrap"},cQ={padding:"var(--space-2) var(--space-3)",border:"1px solid var(--border-default)",borderRadius:"var(--radius-control)",background:"var(--button-primary-surface)",color:"var(--button-primary-text)",cursor:"pointer"},c0={padding:"var(--space-2) var(--space-3)",border:"1px solid var(--border-default)",borderRadius:"var(--radius-control)",background:"var(--button-secondary-surface)",color:"var(--button-secondary-text)",cursor:"pointer"},c1={font:"var(--text-caption)",color:"var(--fg-muted)",display:"flex",flexDirection:"column",gap:"var(--space-1)"},c2={font:"var(--text-caption)",color:"var(--fg-muted)",margin:0};function c4(e){return[e.ownerAndRepo,e.prExternalId,e.baseBranchName,e.headBranchName].join(" ");}function c3(e,t){return{projectId:t,ownerAndRepo:e.ownerAndRepo,prExternalId:e.prExternalId,baseBranchName:e.baseBranchName,headBranchName:e.headBranchName,mergeStrategy:e.mergeStrategy||"provider-default",deleteBranchAfterMerge:e.deleteBranchAfterMerge};}function c6(e){let{form:t,busy:n,onChange:l}=e;return(0,r.jsxs)("section",{style:cJ,"aria-label":"Merge target",children:[(0,r.jsxs)("h3",{style:cY,children:[(0,r.jsx)($.F.git,{size:12})," Merge target"]}),(0,r.jsxs)("div",{style:cZ,children:[(0,r.jsxs)("label",{style:{...c1,flex:1},children:["Repository (owner/repo)",(0,r.jsx)("input",{style:cX,value:t.ownerAndRepo,disabled:n,onChange:e=>l("ownerAndRepo",e.target.value)})]}),(0,r.jsxs)("label",{style:{...c1,flex:1},children:["Pull Request number",(0,r.jsx)("input",{style:cX,value:t.prExternalId,disabled:n,onChange:e=>l("prExternalId",e.target.value),"aria-label":"Pull Request number",inputMode:"numeric"})]})]}),(0,r.jsxs)("div",{style:cZ,children:[(0,r.jsxs)("label",{style:{...c1,flex:1},children:["Base branch",(0,r.jsx)("input",{style:cX,value:t.baseBranchName,disabled:n,onChange:e=>l("baseBranchName",e.target.value),"aria-label":"Base branch"})]}),(0,r.jsxs)("label",{style:{...c1,flex:1},children:["Head branch",(0,r.jsx)("input",{style:cX,value:t.headBranchName,disabled:n,onChange:e=>l("headBranchName",e.target.value),"aria-label":"Head branch"})]})]})]});}function c5(e){var t;let{form:n,preview:l,busy:a,onChange:i}=e,s=null!=(t=null==l?void 0:l.eligibleStrategies)?t:[],o=null!==l&&!l.requestedStrategyEligible;return(0,r.jsxs)("section",{style:cJ,"aria-label":"Merge strategy",children:[(0,r.jsxs)("h3",{style:cY,children:[(0,r.jsx)($.F.git,{size:12})," Strategy"]}),(0,r.jsxs)("label",{style:c1,children:["Merge strategy",(0,r.jsx)("select",{style:cX,value:n.mergeStrategy,disabled:a||0===s.length,onChange:e=>i("mergeStrategy",e.target.value),"aria-label":"Merge strategy","data-testid":"gm-strategy",children:0===s.length?(0,r.jsx)("option",{value:"",children:"Run preview to load eligible strategies"}):s.map(e=>(0,r.jsx)("option",{value:e,children:cG(e)},e))})]}),o?(0,r.jsxs)("p",{style:c2,role:"note","data-field":"strategy-ineligible",children:["The requested strategy “",cG(l.requestedStrategy),"” is not eligible.",void 0!==l.selectedDefaultStrategy?` Defaulting to “${cG(l.selectedDefaultStrategy)}”.`:""]}):null,(0,r.jsxs)("label",{style:{...c1,flexDirection:"row",alignItems:"center"},children:[(0,r.jsx)("input",{type:"checkbox",checked:n.deleteBranchAfterMerge,disabled:a,onChange:e=>i("deleteBranchAfterMerge",e.target.checked),"aria-label":"Delete head branch after merge"}),"Delete head branch after merge"]})]});}function c8(e){let{preview:t}=e;return(0,r.jsxs)("section",{style:cJ,"aria-label":"Readiness","aria-live":"polite","data-testid":"gm-readiness",children:[(0,r.jsxs)("h3",{style:cY,children:[(0,r.jsx)($.F.info,{size:12})," Readiness"]}),(0,r.jsxs)("p",{style:c2,"data-field":"mergeable",children:["Mergeable: ",t.readiness.mergeable?"yes":"no"]}),(0,r.jsxs)("p",{style:c2,"data-field":"recommendation",children:["Recommendation: ",t.recommendation]}),(0,r.jsxs)("p",{style:c2,"data-field":"policy",children:["Policy: ",t.policyOutcome,void 0!==t.policyBlockReason?` (${t.policyBlockReason})`:""]}),(0,r.jsxs)("p",{style:c2,"data-field":"risk",children:["Risk: ",t.riskClass," (severity ",t.riskSeverity,")"]}),(0,r.jsxs)("p",{style:c2,"data-field":"approval",children:["Final approval required: ",t.requiresApproval?"yes":"no"]}),t.readiness.blockers.length>0?(0,r.jsx)("ul",{style:{margin:0,paddingLeft:"var(--space-4)",font:"var(--text-caption)"},children:t.readiness.blockers.map(e=>(0,r.jsxs)("li",{style:{color:"var(--fg-muted)"},"data-blocker":e.code,children:["blocker: ",e.code," (",e.remediation,")",void 0!==e.actionHint?` → ${e.actionHint}`:""]},e.code))}):null]});}function c9(e){let{confirmed:t,busy:n,onChange:l}=e;return(0,r.jsxs)("section",{style:cJ,"aria-label":"High-risk merge confirmation","data-testid":"gm-approval",children:[(0,r.jsxs)("h3",{style:cY,children:[(0,r.jsx)($.F.info,{size:12})," High-risk confirmation"]}),(0,r.jsx)("p",{style:c2,children:"This merge is policy-gated as high risk. Confirm explicitly before merging; the server still enforces the approval token."}),(0,r.jsxs)("label",{style:{...c1,flexDirection:"row",alignItems:"center"},children:[(0,r.jsx)("input",{type:"checkbox",checked:t,disabled:n,onChange:e=>l(e.target.checked),"aria-label":"I confirm this high-risk merge"}),"I confirm this high-risk merge"]})]});}function c7(e){var t,n,l;let{outcome:a,error:i}=e;if(null!==i)return(0,r.jsxs)("p",{role:"alert",style:{font:"var(--text-body-sm)",color:"var(--feedback-danger)"},children:[(0,r.jsx)($.F.info,{size:12})," ",i]});if(null===a)return null;let s=[...(void 0!==a.merged?[`merged: ${a.merged?"yes":"no"}`]:[]),...(void 0!==a.branchDeleted?[`branch deleted: ${a.branchDeleted?"yes":"no"}`]:[]),...(void 0!==a.blockReason?[`reason: ${a.blockReason}`]:[]),...(void 0!==a.mergeable?[`mergeable: ${a.mergeable?"yes":"no"}`]:[]),...(null!=(t=a.readinessBlockers)?t:[]).map(e=>`blocker: ${e.code}${void 0!==e.actionHint?` → ${e.actionHint}`:""}`),...(null!=(n=a.preflightFindingCodes)?n:[]).map(e=>`preflight: ${e}`),...(null!=(l=a.requiredApprovers)?l:[]).map(e=>`approver: ${e}`),...(void 0!==a.mergeRejectionReason?[`rejected: ${a.mergeRejectionReason}`]:[]),...(void 0!==a.recoveryDisposition?[`recover: ${a.recoveryDisposition}`]:[]),...(void 0!==a.recoveryActionHint?[`hint: ${a.recoveryActionHint}`]:[]),...(void 0!==a.executionErrorCode?[`error: ${a.executionErrorCode}`]:[])];return(0,r.jsxs)("div",{"data-testid":"gm-outcome",style:{display:"flex",flexDirection:"column",gap:"var(--space-1)"},children:[(0,r.jsxs)("p",{style:{font:"var(--text-body-sm)",color:"var(--text-body)",margin:0},children:[(0,r.jsx)($.F.check,{size:12})," ",a.actionKind,": ",a.status]}),s.length>0?(0,r.jsx)("ul",{style:{margin:0,paddingLeft:"var(--space-4)",font:"var(--text-caption)"},children:s.map(e=>(0,r.jsx)("li",{style:{color:"var(--fg-muted)"},children:e},e))}):null]});}function de(e){var t,n;let{client:l,projectId:a,headBranchName:s,ownerAndRepo:o,baseBranchName:c,prExternalId:d,titleId:u,liveId:p}=e,[h,f]=(0,i.useState)(()=>function(e){let{headBranchName:t,ownerAndRepo:n,baseBranchName:l,prExternalId:a}=e;return{ownerAndRepo:null!=n?n:"",prExternalId:null!=a?a:"",baseBranchName:null!=l?l:"",headBranchName:null!=t?t:"",mergeStrategy:"",deleteBranchAfterMerge:!1};}({headBranchName:s,ownerAndRepo:o,baseBranchName:c,prExternalId:d})),[g,v]=(0,i.useState)(!1),[b,y]=(0,i.useState)(""),x=function(e){let[t,n]=(0,i.useState)({preview:null,outcome:null,error:null,busy:!1}),l=(0,i.useRef)(0),a=(0,i.useCallback)((e,t)=>{t===l.current&&n(t=>({...t,busy:!1,error:e instanceof m.hD?`${e.message} (${e.code})`:e instanceof Error?e.message:"An unexpected error occurred."}));},[]),r=(0,i.useCallback)(async t=>{let r=l.current+=1;n(e=>({...e,busy:!0,error:null}));try{let a=await e.mergePreview(t);if(r!==l.current)return null;return n(e=>({...e,busy:!1,preview:a})),a;}catch(e){return a(e,r),null;}},[e,a]),s=(0,i.useCallback)(t=>{let r=l.current+=1;n(e=>({...e,busy:!0,error:null,outcome:null})),e.mergeExecute(t).then(e=>{r===l.current&&n(t=>({...t,busy:!1,outcome:e}));}).catch(e=>{a(e,r);});},[e,a]);return{...t,runPreview:r,runExecute:s};}(l),w=(0,i.useCallback)((e,t)=>{f(n=>({...n,[e]:t}));},[]),j=(0,i.useCallback)(()=>{let e=c4(h);x.runPreview(c3(h,a)).then(t=>{var n,l;if(null===t)return;let a=null!=(n=null!=(l=t.selectedDefaultStrategy)?l:t.eligibleStrategies[0])?n:"";f(e=>({...e,mergeStrategy:a})),y(e),v(!1);});},[x,h,a]),k=(0,i.useCallback)(()=>{x.runExecute(c3(h,a));},[x,h,a]),N=""!==h.ownerAndRepo&&""!==h.prExternalId&&""!==h.baseBranchName&&""!==h.headBranchName,S=x.preview,C=null!=(t=null==S?void 0:S.requiresApproval)&&t,R=null!=(n=null==S?void 0:S.readiness.mergeable)&&n,I=null!==S&&b===c4(h),E=N&&I&&""!==h.mergeStrategy&&R&&(!C||g);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-3)",padding:"var(--space-3)",overflow:"auto",height:"100%"},"aria-labelledby":u,children:[(0,r.jsxs)("h2",{id:u,style:{...cY,font:"var(--text-title)"},children:[(0,r.jsx)($.F.git,{size:14})," Merge"]}),(0,r.jsx)("p",{id:p,"data-testid":"gm-live",role:"status","aria-live":"polite",style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:x.busy?"Merge action running.":null!==x.error?`Merge action failed: ${x.error}`:null!==x.outcome?`Merge ${x.outcome.status}.`:null!==x.preview?`Preview ready. Recommendation: ${x.preview.recommendation}.`:""}),(0,r.jsx)(c6,{form:h,busy:x.busy,onChange:w}),(0,r.jsx)(c5,{form:h,preview:S,busy:x.busy,onChange:w}),null!==S?(0,r.jsx)(c8,{preview:S}):null,C?(0,r.jsx)(c9,{confirmed:g,busy:x.busy,onChange:v}):null,(0,r.jsxs)("div",{style:cZ,children:[(0,r.jsx)("button",{type:"button",style:c0,disabled:x.busy||!N,onClick:j,children:"Preview"}),(0,r.jsx)("button",{type:"button",style:cQ,disabled:x.busy||!E,onClick:k,"data-testid":"gm-submit",children:"Merge Pull Request"})]}),(0,r.jsx)(c7,{outcome:x.outcome,error:x.error})]});}function dt(e){let{projectId:t,headBranchName:n,ownerAndRepo:l,baseBranchName:a,prExternalId:s,client:o=cH}=e,c=(0,i.useId)(),d=(0,i.useId)();return void 0===t||""===t?(0,r.jsx)("div",{"data-testid":"gm-empty",style:{padding:"var(--space-4)",color:"var(--fg-muted)",font:"var(--text-body-sm)"},children:(0,r.jsxs)("p",{children:[(0,r.jsx)($.F.git,{size:13})," Select a project to open a merge."]})}):(0,r.jsx)(de,{client:o,projectId:t,headBranchName:n,ownerAndRepo:l,baseBranchName:a,prExternalId:s,titleId:c,liveId:d});}let dn={prPreview:m.RA,prExecute:m.ej},dl={display:"flex",flexDirection:"column",gap:"var(--space-2)",padding:"var(--space-3)",border:"1px solid var(--border-default)",borderRadius:"var(--radius-md)",background:"var(--card)"},da={margin:0,font:"var(--text-label)",color:"var(--text-heading)"},dr={width:"100%",padding:"var(--space-2)",border:"1px solid var(--border-default)",borderRadius:"var(--radius-control)",background:"var(--background-secondary)",color:"var(--text-body)",font:"var(--text-body-sm)"},di={display:"flex",gap:"var(--space-2)",flexWrap:"wrap"},ds={padding:"var(--space-2) var(--space-3)",border:"1px solid var(--border-default)",borderRadius:"var(--radius-control)",background:"var(--button-primary-surface)",color:"var(--button-primary-text)",cursor:"pointer"},dc={padding:"var(--space-2) var(--space-3)",border:"1px solid var(--border-default)",borderRadius:"var(--radius-control)",background:"var(--button-secondary-surface)",color:"var(--button-secondary-text)",cursor:"pointer"},dd={font:"var(--text-caption)",color:"var(--fg-muted)",display:"flex",flexDirection:"column",gap:"var(--space-1)"},du={font:"var(--text-caption)",color:"var(--fg-muted)",margin:0};function dp(e,t){let n={projectId:t,ownerAndRepo:e.ownerAndRepo,headBranchName:e.headBranchName,baseBranchName:e.baseBranchName,title:e.title,body:e.body};return"pr-create"===e.kind?{...n,kind:"pr-create",isDraft:e.isDraft}:{...n,kind:"pr-update",prExternalId:e.prExternalId,convertToDraft:"to-draft"===e.draftTransition,convertFromDraft:"to-ready"===e.draftTransition};}function dm(e){let{form:t,busy:n,onChange:l}=e;return(0,r.jsxs)("div",{style:di,children:[(0,r.jsxs)("label",{style:{...dd,flex:1},children:["Repository (owner/repo)",(0,r.jsx)("input",{style:dr,value:t.ownerAndRepo,disabled:n,onChange:e=>l("ownerAndRepo",e.target.value)})]}),(0,r.jsxs)("label",{style:{...dd,flex:1},children:["Base branch",(0,r.jsx)("input",{style:dr,value:t.baseBranchName,disabled:n,onChange:e=>l("baseBranchName",e.target.value),"aria-label":"Base branch"})]})]});}function dh(e){let{form:t,busy:n,onChange:l}=e;return(0,r.jsxs)("section",{style:dl,"aria-label":"Pull Request metadata",children:[(0,r.jsxs)("h3",{style:da,children:[(0,r.jsx)($.F.git,{size:12})," Metadata"]}),(0,r.jsxs)("fieldset",{style:{border:"1px solid var(--border-default)",borderRadius:"var(--radius-control)",padding:"var(--space-2)"},children:[(0,r.jsx)("legend",{style:du,children:"Action"}),(0,r.jsxs)("div",{style:di,children:[(0,r.jsxs)("label",{style:{...dd,flexDirection:"row",alignItems:"center"},children:[(0,r.jsx)("input",{type:"radio",name:"pull-request-action",checked:"pr-create"===t.kind,disabled:n,onChange:()=>l("kind","pr-create")}),"Create"]}),(0,r.jsxs)("label",{style:{...dd,flexDirection:"row",alignItems:"center"},children:[(0,r.jsx)("input",{type:"radio",name:"pull-request-action",checked:"pr-update"===t.kind,disabled:n,onChange:()=>l("kind","pr-update")}),"Update"]})]})]}),"pr-update"===t.kind?(0,r.jsxs)("div",{style:di,children:[(0,r.jsxs)("label",{style:{...dd,flex:1},children:["Pull Request number",(0,r.jsx)("input",{style:dr,inputMode:"numeric",value:t.prExternalId,disabled:n,onChange:e=>l("prExternalId",e.target.value),"aria-label":"Pull Request number"})]}),(0,r.jsxs)("label",{style:{...dd,flex:1},children:["Draft state",(0,r.jsxs)("select",{style:dr,value:t.draftTransition,disabled:n,onChange:e=>l("draftTransition",e.target.value),"aria-label":"Draft state",children:[(0,r.jsx)("option",{value:"none",children:"No change"}),(0,r.jsx)("option",{value:"to-ready",children:"Mark ready"}),(0,r.jsx)("option",{value:"to-draft",children:"Convert to draft"})]})]})]}):null,(0,r.jsxs)("label",{style:dd,children:["Head branch",(0,r.jsx)("input",{style:dr,value:t.headBranchName,disabled:n,onChange:e=>l("headBranchName",e.target.value),"aria-label":"Head branch"})]}),(0,r.jsx)(dm,{form:t,busy:n,onChange:l}),(0,r.jsxs)("label",{style:dd,children:["Title",(0,r.jsx)("input",{style:dr,value:t.title,disabled:n,onChange:e=>l("title",e.target.value),"aria-label":"Pull Request title"})]}),(0,r.jsxs)("label",{style:dd,children:["Body",(0,r.jsx)("textarea",{style:{...dr,minHeight:100,resize:"vertical"},value:t.body,disabled:n,onChange:e=>l("body",e.target.value),"aria-label":"Pull Request body"})]}),(0,r.jsxs)("label",{style:{...dd,flexDirection:"row",alignItems:"center"},children:[(0,r.jsx)("input",{type:"checkbox",checked:"pr-create"===t.kind&&t.isDraft,disabled:n||"pr-create"!==t.kind,onChange:e=>l("isDraft",e.target.checked),"aria-label":"Open as draft"}),"Open as draft"]})]});}function df(e){let{preview:t}=e;return(0,r.jsxs)("section",{style:dl,"aria-label":"Readiness","data-testid":"gpr-readiness",children:[(0,r.jsxs)("h3",{style:da,children:[(0,r.jsx)($.F.info,{size:12})," Readiness"]}),(0,r.jsxs)("p",{style:du,"data-field":"objectExists",children:["Remote PR object: ",t.readiness.objectExists?"exists":"not created yet"]}),(0,r.jsxs)("p",{style:du,"data-field":"reviewReady",children:["Ready for review: ",t.readiness.reviewReady?"yes":"no"]}),(0,r.jsxs)("p",{style:du,"data-field":"recommendation",children:["Recommendation: ",t.recommendation]}),(0,r.jsxs)("p",{style:du,"data-field":"policy",children:["Policy: ",t.policyOutcome,void 0!==t.policyBlockReason?` (${t.policyBlockReason})`:""]}),(0,r.jsxs)("p",{style:du,"data-field":"risk",children:["Risk: ",t.riskClass," — ",t.riskNarrative]}),t.readiness.blockerCodes.length>0?(0,r.jsx)("ul",{style:{margin:0,paddingLeft:"var(--space-4)",font:"var(--text-caption)"},children:t.readiness.blockerCodes.map(e=>(0,r.jsxs)("li",{style:{color:"var(--fg-muted)"},"data-blocker":e,children:["blocker: ",e]},e))}):null,t.suggestedLabels.length>0?(0,r.jsxs)("p",{style:du,"data-field":"labels",children:["Suggested labels: ",t.suggestedLabels.join(", ")]}):null,t.suggestedIssueRefs.length>0?(0,r.jsxs)("p",{style:du,"data-field":"linkage",children:["Linked issues: ",t.suggestedIssueRefs.join(", ")]}):null]});}function dg(e){var t,n;let{outcome:l,error:a}=e;if(null!==a)return(0,r.jsxs)("p",{role:"alert",style:{font:"var(--text-body-sm)",color:"var(--feedback-danger)"},children:[(0,r.jsx)($.F.info,{size:12})," ",a]});if(null===l)return null;let i=[...(void 0!==l.createdPrExternalId?[`pr: #${l.createdPrExternalId}`]:[]),...(void 0!==l.blockReason?[`reason: ${l.blockReason}`]:[]),...(null!=(t=l.preflightFindingCodes)?t:[]).map(e=>`preflight: ${e}`),...(null!=(n=l.requiredApprovers)?n:[]).map(e=>`approver: ${e}`),...(void 0!==l.prRejectionReason?[`rejected: ${l.prRejectionReason}`]:[]),...(void 0!==l.recoveryDisposition?[`recover: ${l.recoveryDisposition}`]:[]),...(void 0!==l.recoveryActionHint?[`hint: ${l.recoveryActionHint}`]:[]),...(void 0!==l.executionErrorCode?[`error: ${l.executionErrorCode}`]:[])];return(0,r.jsxs)("div",{"data-testid":"gpr-outcome",style:{display:"flex",flexDirection:"column",gap:"var(--space-1)"},children:[(0,r.jsxs)("p",{style:{font:"var(--text-body-sm)",color:"var(--text-body)",margin:0},children:[(0,r.jsx)($.F.check,{size:12})," ",l.actionKind,": ",l.status]}),i.length>0?(0,r.jsx)("ul",{style:{margin:0,paddingLeft:"var(--space-4)",font:"var(--text-caption)"},children:i.map(e=>(0,r.jsx)("li",{style:{color:"var(--fg-muted)"},children:e},e))}):null]});}function dv(e){let{client:t,projectId:n,headBranchName:l,ownerAndRepo:a,baseBranchName:s,titleId:o,liveId:c}=e,[d,u]=(0,i.useState)(()=>function(e){let{headBranchName:t,ownerAndRepo:n,baseBranchName:l}=e;return{kind:"pr-create",ownerAndRepo:null!=n?n:"",headBranchName:null!=t?t:"",baseBranchName:null!=l?l:"",title:"",body:"",isDraft:!1,prExternalId:"",draftTransition:"none"};}({headBranchName:l,ownerAndRepo:a,baseBranchName:s})),p=function(e){let[t,n]=(0,i.useState)({preview:null,outcome:null,error:null,busy:!1}),l=(0,i.useRef)(0),a=(0,i.useCallback)((e,t)=>{t===l.current&&n(t=>({...t,busy:!1,error:e instanceof m.hD?`${e.message} (${e.code})`:e instanceof Error?e.message:"An unexpected error occurred."}));},[]),r=(0,i.useCallback)(async t=>{let r=l.current+=1;n(e=>({...e,busy:!0,error:null}));try{let a=await e.prPreview(t);if(r!==l.current)return null;return n(e=>({...e,busy:!1,preview:a})),a;}catch(e){return a(e,r),null;}},[e,a]),s=(0,i.useCallback)(t=>{let r=l.current+=1;n(e=>({...e,busy:!0,error:null,outcome:null})),e.prExecute(t).then(e=>{r===l.current&&n(t=>({...t,busy:!1,outcome:e}));}).catch(e=>{a(e,r);});},[e,a]);return{...t,runPreview:r,runExecute:s};}(t),h=(0,i.useCallback)((e,t)=>{u(n=>({...n,[e]:t}));},[]),f=(0,i.useCallback)(()=>{p.runPreview(dp(d,n)).then(e=>{null!==e&&u(t=>({...t,title:""===t.title?e.composedTitle:t.title,body:""===t.body?e.composedBody:t.body}));});},[p,d,n]),g=(0,i.useCallback)(()=>{p.runExecute(dp(d,n));},[p,d,n]),v=""!==d.ownerAndRepo&&""!==d.headBranchName&&""!==d.baseBranchName&&("pr-create"===d.kind||""!==d.prExternalId),b=v&&""!==d.title;return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-3)",padding:"var(--space-3)",overflow:"auto",height:"100%"},"aria-labelledby":o,children:[(0,r.jsxs)("h2",{id:o,style:{...da,font:"var(--text-title)"},children:[(0,r.jsx)($.F.git,{size:14})," Pull Request"]}),(0,r.jsx)("p",{id:c,"data-testid":"gpr-live",role:"status","aria-live":"polite",style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:p.busy?"Pull request action running.":null!==p.error?`Pull request action failed: ${p.error}`:null!==p.outcome?`Pull request ${p.outcome.status}.`:null!==p.preview?`Preview ready. Recommendation: ${p.preview.recommendation}.`:""}),(0,r.jsx)(dh,{form:d,busy:p.busy,onChange:h}),null!==p.preview?(0,r.jsx)(df,{preview:p.preview}):null,(0,r.jsxs)("div",{style:di,children:[(0,r.jsx)("button",{type:"button",style:dc,disabled:p.busy||!v,onClick:f,children:"Preview"}),(0,r.jsx)("button",{type:"button",style:ds,disabled:p.busy||!b,onClick:g,"data-testid":"gpr-submit",children:"pr-create"===d.kind?"Create Pull Request":"Update Pull Request"})]}),(0,r.jsx)(dg,{outcome:p.outcome,error:p.error})]});}function db(e){let{projectId:t,headBranchName:n,ownerAndRepo:l,baseBranchName:a,client:s=dn}=e,o=(0,i.useId)(),c=(0,i.useId)();return void 0===t||""===t?(0,r.jsx)("div",{"data-testid":"gpr-empty",style:{padding:"var(--space-4)",color:"var(--fg-muted)",font:"var(--text-body-sm)"},children:(0,r.jsxs)("p",{children:[(0,r.jsx)($.F.git,{size:13})," Select a project to open a pull request."]})}):(0,r.jsx)(dv,{client:s,projectId:t,headBranchName:n,ownerAndRepo:l,baseBranchName:a,titleId:o,liveId:c});}let dy={display:"flex",flexDirection:"column",minHeight:"100%",minWidth:0,background:"var(--card)",color:"var(--fg)"},dx={height:66,flex:"none",display:"flex",alignItems:"stretch",borderBottom:"1px solid var(--line-soft)",background:"var(--surface)"},dw={height:66,flex:"none",display:"flex",alignItems:"center",gap:14,padding:"0 18px",borderBottom:"1px solid var(--line-soft)",background:"var(--surface)"},dj={display:"flex",alignItems:"center",gap:11,padding:"0 18px",border:0,background:"transparent",cursor:"pointer",textAlign:"left",borderRight:"1px solid var(--line-soft)"},dk={fontSize:10,fontWeight:600,letterSpacing:"0.07em",textTransform:"uppercase",color:"var(--fg-faint)",fontFamily:"var(--font-mono)",lineHeight:1.1},dN={display:"flex",alignItems:"center",gap:6,padding:"0 16px",borderLeft:"1px solid var(--line-soft)"},dS={flex:1,display:"flex",minHeight:0},dC={width:384,flex:"none",display:"flex",flexDirection:"column",minWidth:0,minHeight:0,borderRight:"1px solid var(--line-soft)",background:"var(--card)"},dR={flex:1,minWidth:0,minHeight:0,display:"flex",flexDirection:"column",background:"var(--ed-bg)"},dI={display:"inline-flex",alignItems:"center",justifyContent:"center",gap:7,height:34,padding:"0 13px",borderRadius:9,font:"500 12.5px var(--font-ui)",cursor:"pointer",whiteSpace:"nowrap"},dE={...dI,border:"1px solid var(--line)",background:"var(--card)",color:"var(--fg)"},d$={...dI,height:40,padding:"0 18px",border:0,background:"var(--accent)",color:"var(--ink-inverse)",font:"650 13px var(--font-ui)"};function dA(e){return e?{opacity:"var(--opacity-disabled, 0.6)",cursor:"not-allowed"}:{};}let dT={height:44,flex:"none",display:"flex",alignItems:"stretch",padding:"0 8px",borderBottom:"1px solid var(--line-soft)"},dF={display:"flex",alignItems:"center",gap:8,padding:"10px 14px 6px",color:"var(--fg-faint)"},dD={display:"inline-flex",alignItems:"center",justifyContent:"center",width:15,height:15,flex:"none",borderRadius:4,background:"var(--accent-solid)",color:"var(--accent-solid-ink)"},dM={display:"flex",alignItems:"center",gap:8,flexWrap:"wrap",padding:"0 14px 8px"},dP={display:"inline-flex",alignItems:"center",gap:5,height:26,padding:"0 10px",borderRadius:7,border:"1px solid var(--line)",background:"var(--card)",color:"var(--fg-muted)",font:"500 11.5px var(--font-ui)",cursor:"pointer",whiteSpace:"nowrap"},dL={flex:1,minHeight:0,overflowY:"auto",padding:"2px 8px 8px"},dq={fontSize:13,fontWeight:500,color:"var(--fg)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},dz={fontFamily:"var(--font-mono)",fontSize:10.5,color:"var(--fg-faint)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},dO={flex:"none",borderTop:"1px solid var(--line-soft)",background:"var(--surface)",padding:"13px 14px",display:"flex",flexDirection:"column",gap:10},dB={width:"100%",minHeight:54,padding:"9px 12px",borderRadius:9,border:0,background:"var(--inset)",boxShadow:"inset 0 0 0 1px var(--line)",color:"var(--fg-muted)",font:"400 13px var(--font-ui)",lineHeight:1.5,resize:"vertical"},dW={display:"flex",alignItems:"center",gap:6},dK={height:44,flex:"none",display:"flex",alignItems:"center",gap:12,padding:"0 14px",borderBottom:"1px solid var(--line-soft)",background:"var(--surface)"},dU={fontFamily:"var(--font-mono)",fontSize:12,color:"var(--fg-faint)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},dV={display:"inline-flex",alignItems:"center",gap:2,padding:2,borderRadius:8,background:"var(--inset)",boxShadow:"inset 0 0 0 1px var(--line)"},dH={flex:1,minHeight:0,overflowY:"auto",padding:"6px 8px",display:"flex",flexDirection:"column",gap:0};function d_(e){return{display:"inline-flex",alignItems:"center",justifyContent:"center",width:e,height:e,flex:"none",borderRadius:"50%",background:"var(--accent-dim)",color:"var(--accent-text)",fontFamily:"var(--font-mono)",fontWeight:700,boxShadow:"inset 0 0 0 1px var(--accent-line)"};}let dG={display:"inline-flex",fontFamily:"var(--font-mono)",fontSize:9.5,fontWeight:600,color:"var(--accent-on-tint)",background:"var(--accent-dim)",padding:"1px 6px",borderRadius:999,boxShadow:"inset 0 0 0 1px var(--accent-line)"},dJ={fontFamily:"var(--font-mono)",color:"var(--fg-muted)",background:"var(--inset)",padding:"1px 7px",borderRadius:6},dY={flex:"none",padding:"13px 16px",borderBottom:"1px solid var(--line-soft)",background:"var(--surface)",display:"flex",flexDirection:"column",gap:8},dX={flex:1,minHeight:0,display:"flex",alignItems:"center",justifyContent:"center",padding:40,overflowY:"auto"},dZ={width:"100%",maxWidth:520,display:"flex",flexDirection:"column",alignItems:"center",textAlign:"center"},dQ={display:"grid",placeItems:"center",width:72,height:72,borderRadius:20,background:"var(--inset)",color:"var(--fg-dim)",boxShadow:"inset 0 0 0 1px var(--line-soft)"},d0={fontSize:19,fontWeight:600,color:"var(--fg)",marginTop:20,letterSpacing:"-0.01em"},d1={fontSize:13.5,color:"var(--fg-muted)",lineHeight:1.6,marginTop:8,maxWidth:400},d2={fontSize:10.5,fontWeight:600,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--fg-faint)",fontFamily:"var(--font-mono)",marginBottom:8},d4={display:"grid",placeItems:"center",width:34,height:34,flex:"none",borderRadius:9,background:"var(--accent-dim)",color:"var(--accent-text)",boxShadow:"inset 0 0 0 1px var(--accent-line)"},d3={display:"flex",alignItems:"flex-start",gap:9,marginTop:22,padding:"11px 13px",borderRadius:11,background:"var(--accent-dim)",boxShadow:"inset 0 0 0 1px var(--accent-line)",textAlign:"left"},d6={margin:0,font:"400 13px var(--font-ui)",color:"var(--fg-muted)"},d5={display:"block",marginTop:2,font:"400 11px var(--font-mono)",color:"var(--fg-faint)",overflowWrap:"anywhere"},d8={fontFamily:"var(--font-mono)",fontSize:11,color:"var(--accent-text)"},d9={display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:10,flex:1,minHeight:0,padding:28,textAlign:"center",color:"var(--fg-muted)"},d7={display:"flex",flexDirection:"column",gap:8,padding:12,borderRadius:9,background:"var(--inset)",boxShadow:"inset 0 0 0 1px var(--line)"},ue={width:"100%",minHeight:34,padding:"0 12px",border:0,borderRadius:9,background:"var(--inset)",boxShadow:"inset 0 0 0 1px var(--line)",color:"var(--fg)",font:"400 13px var(--font-ui)"};({...dB});let ut={position:"absolute",zIndex:20,top:"calc(100% + 6px)",left:0,width:300,maxWidth:"min(80vw, 360px)",borderRadius:11,background:"var(--card)",boxShadow:"var(--shadow-pop)",padding:8},un={listStyle:"none",margin:0,padding:8,display:"flex",flexDirection:"column",gap:2,overflow:"auto",flex:1,minHeight:0},ul={display:"block",width:"100%",textAlign:"left",padding:"8px 10px",border:0,borderRadius:9,background:"transparent",color:"var(--fg)",cursor:"pointer",minWidth:0},ua={background:"var(--accent-dim)",boxShadow:"inset 2px 0 0 var(--accent)"},ur={display:"inline-flex",alignItems:"center",gap:6,padding:"3px 10px",borderRadius:999,background:"var(--inset)",boxShadow:"inset 0 0 0 1px var(--line)",color:"var(--fg-muted)",font:"600 11px var(--font-ui)",whiteSpace:"nowrap"};function ui(e){let{branches:t,currentBranch:n,loading:l,disabled:a,busy:s,onSwitchBranch:o,onCreateBranch:c}=e,[d,u]=(0,i.useState)(!1),[p,m]=(0,i.useState)(""),h=(0,i.useId)(),f=(0,i.useId)(),g=(0,i.useRef)(null),v=(0,i.useRef)(null),b=(0,i.useRef)([]),y=(0,i.useMemo)(()=>t.filter(e=>{let t;return 0===(t=p.trim().toLowerCase()).length||e.name.toLowerCase().includes(t);}),[t,p]),x=function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];u(!1),m(""),e&&queueMicrotask(()=>{var e;return null==(e=g.current)?void 0:e.focus();});},w=e=>{var t;let n=Math.max(0,Math.min(e,y.length-1));null==(t=b.current[n])||t.focus();},j=n.length>0?n:l?"Loading branches":"No branch";return(0,i.useEffect)(()=>{var e;d&&(null==(e=v.current)||e.focus());},[d]),(0,r.jsxs)("div",{style:{position:"relative",display:"inline-flex",alignItems:"center",gap:6},children:[(0,r.jsxs)("button",{ref:g,type:"button",role:"combobox","aria-label":`Branch: ${j}`,"aria-haspopup":"listbox","aria-expanded":d,"aria-controls":h,disabled:a||l||0===t.length,style:{...dE,minWidth:168,...dA(a||l)},onClick:()=>{a||l||0===t.length||u(e=>!e);},children:[(0,r.jsx)($.F.branch,{size:12}),(0,r.jsx)("span",{className:"mono",style:{overflow:"hidden",textOverflow:"ellipsis"},children:j})]}),(0,r.jsxs)("button",{type:"button","aria-label":"New branch",disabled:a||l||0===t.length||s,style:{...dP,...dA(a||l||s)},onClick:c,children:[(0,r.jsx)($.F.plus,{size:11})," New"]}),d?(0,r.jsxs)("div",{style:ut,children:[(0,r.jsx)("label",{htmlFor:f,style:{display:"block",marginBottom:6,font:"600 11px var(--font-ui)",color:"var(--fg-faint)",textTransform:"uppercase"},children:"Search branches"}),(0,r.jsx)("input",{ref:v,id:f,type:"search",value:p,"aria-label":"Search branches",style:{...ue,marginBottom:10},onChange:e=>m(e.currentTarget.value),onKeyDown:e=>{"Escape"===e.key&&x(!0),"ArrowDown"===e.key&&(e.preventDefault(),w(0));}}),(0,r.jsx)("div",{id:h,role:"listbox","aria-label":"Branches",style:{...un,maxHeight:260,padding:0},children:0===y.length?(0,r.jsx)("p",{style:{...d6,padding:12},children:"No matching branches."}):y.map((e,t)=>{let l=e.name===n||e.current;return(0,r.jsxs)("button",{ref:e=>{b.current[t]=e;},type:"button",role:"option","aria-selected":l,disabled:s,style:{...ul,...(l?ua:{}),...dA(s)},onClick:()=>{l||o(e.name),x(!0);},onKeyDown:e=>{"ArrowDown"===e.key?(e.preventDefault(),w(t+1)):"ArrowUp"===e.key?(e.preventDefault(),w(t-1)):"Home"===e.key?(e.preventDefault(),w(0)):"End"===e.key?(e.preventDefault(),w(y.length-1)):"Escape"===e.key&&(e.preventDefault(),x(!0));},children:[(0,r.jsx)("span",{className:"mono",children:e.name}),l?(0,r.jsx)("span",{style:{float:"right",font:"400 11px var(--font-ui)"},children:"current"}):null]},e.name);})})]}):null]});}function us(e){var t,n;let{view:l,busy:a,outcome:s,error:o,onRun:c}=e,d=l.disabled||a,u=(0,i.useId)();return(0,r.jsxs)("div",{style:{display:"inline-flex",flexDirection:"column",gap:3,minWidth:0},children:[(0,r.jsxs)("button",{type:"button",disabled:d,style:{...d$,minWidth:112,...dA(d)},"aria-label":`Run sync: ${a?"syncing":l.label}`,"aria-describedby":u,onClick:c,children:[(0,r.jsx)($.F.reset,{size:12})," ",a?"Syncing":l.label]}),(0,r.jsx)("span",{id:u,role:null===o?"status":"alert","aria-label":`Sync: ${null!=(t=null!=o?o:s)?t:l.description}`,"aria-live":"polite","aria-atomic":"true",style:{...ur,maxWidth:320,whiteSpace:"normal",color:null===o?"var(--fg-muted)":"var(--danger)"},children:null!=(n=null!=o?o:s)?n:l.description}),"fetch"===l.action&&l.description.startsWith("Diverged")?(0,r.jsx)("span",{style:{...d6,maxWidth:320},children:"Use the Merge entry point after fetching to reconcile diverged branches."}):null]});}function uo(e){let{label:t,children:n,minWidth:l,last:a}=e;return(0,r.jsx)("div",{style:{...dj,minWidth:l,cursor:"default",...(!0===a?{borderRight:"none"}:null)},children:(0,r.jsxs)("span",{style:{display:"flex",flexDirection:"column",gap:4,minWidth:0},children:[void 0!==t?(0,r.jsx)("span",{style:dk,children:t}):null,n]})});}function uc(e){var t;let n,{repositories:l,selectedPath:a,branches:i,branchesLoading:s,status:o,branchBusy:c,syncView:d,syncBusy:u,syncOutcome:p,syncError:m,onSelectRepository:h,onSwitchBranch:f,onCreateBranch:g,onRunSync:v,onOpenEditor:b,onOpenFiles:y}=e,x=null!==a,w=void 0!==(n=i.find(e=>e.current))?n.name:null!=(t=null==o?void 0:o.branch)?t:"";return x?(0,r.jsxs)("header",{style:dx,"aria-label":"Repository toolbar",children:[(0,r.jsx)(uo,{label:"Repository",minWidth:188,children:(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,r.jsx)("span",{style:{color:"var(--fg-dim)"},children:(0,r.jsx)($.F.folder,{size:16})}),(0,r.jsx)(ln.A,{value:null!=a?a:"",ariaLabel:"Repository",menuTitle:"Repository",placeholder:"Select a repository",triggerStyle:{minWidth:0,border:"none",background:"transparent",padding:0,height:"auto",font:"600 14px var(--font-ui)",color:"var(--fg)"},sections:[{options:l.map(e=>({value:e.path,label:e.name,description:e.path}))}],onValueChange:h})]})}),(0,r.jsx)(uo,{label:"Current branch",minWidth:212,children:(0,r.jsx)(ui,{branches:i,currentBranch:w,loading:s,disabled:(null==o?void 0:o.available)===!1,busy:c,onSwitchBranch:f,onCreateBranch:g})}),(0,r.jsx)(uo,{minWidth:196,last:!0,children:(0,r.jsx)(us,{view:d,busy:u,outcome:p,error:m,onRun:v})}),(0,r.jsx)("span",{style:{flex:1}}),void 0!==b||void 0!==y?(0,r.jsxs)("div",{style:dN,children:[void 0!==b?(0,r.jsxs)("button",{type:"button",style:dE,onClick:()=>{null!==a&&b(a);},children:[(0,r.jsx)("span",{style:{color:"var(--fg-dim)"},children:(0,r.jsx)($.F.code,{size:15})}),"Open in Editor"]}):null,void 0!==y?(0,r.jsxs)("button",{type:"button",style:dE,onClick:()=>{null!==a&&y(a);},children:[(0,r.jsx)("span",{style:{color:"var(--fg-dim)"},children:(0,r.jsx)($.F.files,{size:15})}),"Open Files"]}):null]}):null]}):(0,r.jsxs)("header",{style:dw,"aria-label":"Repository toolbar",children:[(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:10,color:"var(--fg-faint)"},children:[(0,r.jsx)($.F.folder,{size:16}),(0,r.jsx)("span",{style:{fontSize:14,color:"var(--fg-muted)"},children:"Select a repository"})]}),(0,r.jsx)("span",{style:{width:1,height:26,background:"var(--line-soft)"}}),(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:9,color:"var(--fg-faint)"},children:[(0,r.jsx)($.F.branch,{size:16}),(0,r.jsx)("span",{style:{fontSize:13,color:"var(--fg-faint)"},children:"No branch"})]}),(0,r.jsx)("span",{style:{flex:1}}),void 0!==b?(0,r.jsxs)("button",{type:"button",style:{...dE,...dA(!0)},disabled:!0,children:[(0,r.jsx)("span",{style:{color:"var(--fg-dim)"},children:(0,r.jsx)($.F.code,{size:15})}),"Open in Editor"]}):null]});}function ud(e){let{repositories:t,loading:n,error:l,onSelect:a,onConnect:i,onClone:s}=e;return(0,r.jsx)("div",{style:dX,children:(0,r.jsxs)("div",{style:dZ,children:[(0,r.jsx)("div",{"aria-hidden":"true",style:dQ,children:(0,r.jsx)($.F.branch,{size:28})}),(0,r.jsx)("h2",{style:d0,children:"No repository connected"}),(0,r.jsx)("p",{style:d1,children:"Connect a folder or repository to review changes, stage commits, and open pull requests — all in one window."}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginTop:22},children:[(0,r.jsxs)("button",{type:"button",style:d$,onClick:i,children:[(0,r.jsx)($.F.folder,{size:16})," Connect repository"]}),(0,r.jsxs)("button",{type:"button",style:dE,onClick:s,children:[(0,r.jsx)($.F.link,{size:15})," Clone from URL"]})]}),(0,r.jsxs)("div",{style:{width:"100%",marginTop:34,textAlign:"left"},children:[(0,r.jsx)("div",{style:d2,children:"Recent"}),null!==l?(0,r.jsx)("p",{role:"alert",style:{...d6,fontSize:12},children:l}):n&&0===t.length?(0,r.jsx)("p",{role:"status",style:{...d6,fontSize:12},children:"Loading repositories…"}):0===t.length?(0,r.jsx)("p",{style:{...d6,fontSize:12},children:"No repositories yet. Connect or clone one to get started."}):(0,r.jsx)("ul",{style:{listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:8},children:t.map(e=>(0,r.jsx)("li",{children:(0,r.jsxs)("button",{type:"button",style:{width:"100%",display:"flex",alignItems:"center",gap:12,padding:"11px 13px",borderRadius:11,border:"1px solid var(--line-soft)",background:"var(--card)",cursor:"pointer",textAlign:"left"},title:e.path,onClick:()=>a(e.path),children:[(0,r.jsx)("span",{"aria-hidden":"true",style:d4,children:(0,r.jsx)($.F.folder,{size:16})}),(0,r.jsxs)("span",{style:{display:"flex",flexDirection:"column",gap:2,minWidth:0,flex:1},children:[(0,r.jsx)("span",{style:{fontSize:13.5,fontWeight:600,color:"var(--fg)"},children:e.name}),(0,r.jsx)("span",{style:d5,children:e.path})]}),(0,r.jsx)("span",{"aria-hidden":"true",style:{color:"var(--fg-faint)"},children:(0,r.jsx)($.F.chevronR,{size:15})})]})},e.path))})]}),(0,r.jsxs)("div",{style:d3,children:[(0,r.jsx)("span",{"aria-hidden":"true",style:{display:"inline-flex",color:"var(--accent-text)",marginTop:1},children:(0,r.jsx)($.F.spark,{size:14})}),(0,r.jsx)("span",{style:{fontSize:12,color:"var(--fg-muted)",lineHeight:1.55},children:"Once a repository is connected, Keiko can summarize your working changes and draft commit messages for you."})]})]})});}let uu={position:"fixed",inset:0,display:"grid",placeItems:"center",padding:"var(--space-5)",background:"color-mix(in oklch, var(--surface-backdrop, #000) 55%, transparent)",zIndex:1e3},up={display:"flex",flexDirection:"column",gap:"var(--space-5)",width:"min(440px, 100%)",maxHeight:"100%",overflow:"auto",padding:"var(--space-6)",borderRadius:"var(--radius)",background:"var(--card)",boxShadow:"var(--shadow-pop)"},um={display:"flex",flexDirection:"column",gap:"var(--space-3)",font:"600 11px var(--font-ui)",textTransform:"uppercase",letterSpacing:"0.02em",color:"var(--fg-faint)"},uh={...dE,flex:1},uf={border:"1px solid var(--accent-line)",background:"var(--accent-dim)",color:"var(--accent-text)"};function ug(e){let{client:t,onAdded:n,onClose:l,initialMode:a="clone"}=e,[s,o]=(0,i.useState)(a),[c,d]=(0,i.useState)(""),[u,p]=(0,i.useState)(""),[m,h]=(0,i.useState)(""),[f,g]=(0,i.useState)(!1),[v,b]=(0,i.useState)(null),y=(0,i.useRef)(null),x=(0,i.useRef)(null),w=(0,i.useRef)(null);(0,i.useEffect)(()=>(w.current=document.activeElement,()=>{let e=w.current;null!==e&&e.isConnected&&e.focus();}),[]),(0,i.useEffect)(()=>{let e=requestAnimationFrame(()=>{var e,t;null==(t=null!=(e=x.current)?e:y.current)||t.focus();});return()=>cancelAnimationFrame(e);},[s]);let j="clone"===s?""!==c.trim()&&""!==u.trim():""!==m.trim();return(0,r.jsx)("div",{style:uu,onPointerDown:l,children:(0,r.jsxs)("div",{ref:y,role:"dialog","aria-modal":"true","aria-label":"Add repository",tabIndex:-1,style:up,onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{if("Escape"===e.key){e.preventDefault(),l();return;}if("Tab"!==e.key)return;let t=e.currentTarget,n=Array.from(t.querySelectorAll("button,input,textarea")).filter(e=>!e.hasAttribute("disabled"));if(0===n.length)return;let a=n[0],r=n[n.length-1],i=document.activeElement,s=!(i instanceof HTMLElement)||!t.contains(i);e.shiftKey&&(s||i===a)?(e.preventDefault(),r.focus()):!e.shiftKey&&(s||i===r)&&(e.preventDefault(),a.focus());},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-4)"},children:[(0,r.jsx)("h2",{style:{margin:0,font:"600 17px var(--font-ui)",color:"var(--fg)"},children:"Add repository"}),(0,r.jsx)("span",{style:{flex:1}}),(0,r.jsx)("button",{type:"button",style:{...dE,padding:"0 var(--space-3)"},onClick:l,"aria-label":"Close",title:"Close",children:(0,r.jsx)($.F.close,{size:14})})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:"var(--space-3)"},role:"group","aria-label":"Add mode",children:[(0,r.jsx)("button",{type:"button","aria-pressed":"clone"===s,style:{...uh,...("clone"===s?uf:{})},onClick:()=>o("clone"),children:"Clone repository"}),(0,r.jsx)("button",{type:"button","aria-pressed":"open"===s,style:{...uh,...("open"===s?uf:{})},onClick:()=>o("open"),children:"Open local repository"})]}),"clone"===s?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("label",{style:um,children:["Repository URL",(0,r.jsx)("input",{ref:x,style:ue,value:c,onChange:e=>d(e.target.value),"aria-label":"Repository URL",placeholder:"https://github.com/org/repo.git"})]}),(0,r.jsxs)("label",{style:um,children:["Clone to folder",(0,r.jsx)("input",{style:ue,value:u,onChange:e=>p(e.target.value),"aria-label":"Clone to folder",placeholder:"/Users/me/Work/repo"})]})]}):(0,r.jsxs)("label",{style:um,children:["Local repository path",(0,r.jsx)("input",{ref:x,style:ue,value:m,onChange:e=>h(e.target.value),"aria-label":"Local repository path",placeholder:"/Users/me/Work/existing-repo"})]}),null!==v?(0,r.jsx)("p",{role:"alert",style:{...d6,color:"var(--fg)"},children:v}):null,(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:"var(--space-4)"},children:[(0,r.jsx)("button",{type:"button",style:dE,onClick:l,children:"Cancel"}),(0,r.jsx)("button",{type:"button",style:{...d$,...dA(f||!j)},disabled:f||!j,onClick:()=>{f||!j||(g(!0),b(null),("clone"===s?t.cloneRepository({repositoryUrl:c.trim(),destinationPath:u.trim()}):t.registerRepository({path:m.trim()})).then(e=>{g(!1),n(e.project),l();},e=>{g(!1),b(cU(e));}));},children:f?"Adding…":"clone"===s?"Clone repository":"Open repository"})]})]})});}function uv(e){let{children:t,tone:n="neutral"}=e,l=function(e){switch(e){case"success":return"var(--ok)";case"warning":return"var(--warn)";case"danger":return"var(--danger)";case"info":return"var(--info)";case"accent":return"var(--accent-text)";case"neutral":return"var(--fg-muted)";}}(n);return(0,r.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:6,width:"fit-content",padding:"3px 10px",borderRadius:999,border:`1px solid color-mix(in oklch, ${l} 42%, transparent)`,background:"neutral"===n?"var(--inset)":`color-mix(in oklch, ${l} 12%, transparent)`,color:l,font:"600 11px var(--font-ui)",whiteSpace:"nowrap"},children:[(0,r.jsx)("span",{"aria-hidden":"true",style:{width:6,height:6,borderRadius:"50%",background:"currentColor"}}),t]});}function ub(e){let{label:t,testid:n,items:l}=e;return 0===l.length?null:(0,r.jsxs)("div",{"data-testid":n,children:[(0,r.jsx)("p",{style:{margin:"0 0 6px",font:"600 11px var(--font-ui)",color:"var(--fg-faint)",textTransform:"uppercase",letterSpacing:"0.03em"},children:t}),(0,r.jsx)("ul",{style:{margin:0,paddingLeft:18,font:"400 12px var(--font-ui)"},children:l.map(e=>(0,r.jsxs)("li",{style:{color:"var(--fg)",lineHeight:1.5},children:[(0,r.jsx)($.F.info,{size:11})," ",e.text]},e.key))})]});}function uy(e){var t,n,l,a;let{outcome:i,error:s,testid:o="git-outcome"}=e;if(null!==s)return(0,r.jsxs)("div",{"data-testid":o,role:"alert",style:{...d7,boxShadow:"inset 0 0 0 1px color-mix(in oklch, var(--danger) 48%, var(--line))",background:"color-mix(in oklch, var(--danger) 10%, var(--inset))"},children:[(0,r.jsxs)(uv,{tone:"danger",children:[(0,r.jsx)($.F.info,{size:11})," Error"]}),(0,r.jsx)("p",{style:{...d6,color:"var(--fg)"},children:s})]});if(null===i)return null;let c="succeeded"===(a=i.status)?"success":"approval-required"===a||"recovery-required"===a?"warning":"blocked"===a||"failed"===a?"danger":"neutral",d=[...(void 0!==i.blockReason?[`reason: ${i.blockReason}`]:[]),...(null!=(t=i.preflightFindingCodes)?t:[]).map(e=>`preflight: ${e}`),...(null!=(n=i.requiredApprovers)?n:[]).map(e=>`approver: ${e}`),...(void 0!==i.executionErrorCode?[`error: ${i.executionErrorCode}`]:[]),...(null!=(l=i.messageViolations)?l:[]).map(e=>cW[e])],u="success"===c?"color-mix(in oklch, var(--ok) 42%, var(--line))":"warning"===c?"color-mix(in oklch, var(--warn) 42%, var(--line))":"danger"===c?"color-mix(in oklch, var(--danger) 42%, var(--line))":"var(--line)";return(0,r.jsxs)("div",{"data-testid":o,role:"danger"===c?"alert":"status",style:{...d7,boxShadow:`inset 0 0 0 1px ${u}`},children:[(0,r.jsxs)(uv,{tone:c,children:[(0,r.jsx)($.F.check,{size:11})," ",cK[i.status]]}),(0,r.jsxs)("p",{style:{margin:0,font:"600 13px var(--font-ui)",color:"var(--fg)"},children:[i.actionKind,": ",cK[i.status]]}),d.length>0?(0,r.jsx)("ul",{style:{margin:0,paddingLeft:18,font:"400 11px var(--font-ui)"},children:d.map(e=>(0,r.jsx)("li",{style:{color:"var(--fg-muted)",lineHeight:1.5},children:e},e))}):null]});}function ux(e){var t;let{history:n,loading:l,error:a,selectedSha:s,onSelect:o}=e,c=(0,i.useRef)([]),d=null!=(t=null==n?void 0:n.entries)?t:[],u=e=>{var t;let n=Math.max(0,Math.min(e,d.length-1));null==(t=c.current[n])||t.focus();};return null!==a?(0,r.jsx)("p",{className:"rv-empty",role:"alert",style:{padding:14},children:a}):l&&null===n?(0,r.jsx)("p",{className:"rv-empty",role:"status",style:{padding:14},children:"Loading history…"}):null===n?(0,r.jsxs)("div",{style:d9,role:"status","aria-live":"polite",children:[(0,r.jsx)($.F.activity,{size:20}),(0,r.jsx)("p",{style:d6,children:"Commit history appears after selecting a repository."})]}):n.available?0===d.length?(0,r.jsxs)("div",{style:d9,role:"status","aria-live":"polite",children:[(0,r.jsx)($.F.activity,{size:20}),(0,r.jsx)("p",{style:d6,children:"No commits yet. Make a commit to start history."})]}):(0,r.jsx)("div",{role:"listbox","aria-label":"Commit history",style:dH,children:d.map((e,t)=>{var n;let l,a=e.sha===s,i=e.refs.some(e=>"HEAD"===e||e.startsWith("HEAD"));return(0,r.jsxs)("button",{ref:e=>{c.current[t]=e;},type:"button",role:"option","aria-selected":a,style:{display:"flex",alignItems:"flex-start",gap:11,width:"100%",padding:"11px 10px",border:0,borderRadius:9,cursor:"pointer",textAlign:"left",background:a?"var(--accent-dim)":"transparent",boxShadow:a?"inset 2px 0 0 var(--accent)":"none"},onClick:()=>o(e),onKeyDown:e=>{"ArrowDown"===e.key?(e.preventDefault(),u(t+1)):"ArrowUp"===e.key?(e.preventDefault(),u(t-1)):"Home"===e.key?(e.preventDefault(),u(0)):"End"===e.key&&(e.preventDefault(),u(d.length-1));},children:[(0,r.jsx)("span",{"aria-hidden":"true",style:{...d_(28),fontSize:10.5},children:e.author.slice(0,2).toUpperCase()}),(0,r.jsxs)("span",{style:{display:"flex",flexDirection:"column",gap:3,minWidth:0,flex:1},children:[(0,r.jsx)("span",{style:{fontSize:13,fontWeight:500,color:"var(--fg)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:1.3},children:e.subject}),(0,r.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:7,fontSize:11,color:"var(--fg-faint)"},children:[(0,r.jsx)("span",{className:"mono",style:{color:"var(--fg-muted)"},children:e.shortSha}),(0,r.jsx)("span",{"aria-hidden":"true",children:"\xb7"}),(0,r.jsx)("span",{children:e.author}),(0,r.jsx)("span",{"aria-hidden":"true",children:"\xb7"}),(0,r.jsx)("span",{children:Number.isNaN((l=new Date(n=e.date)).getTime())?n:l.toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"})}),i?(0,r.jsx)("span",{style:dG,children:"HEAD"}):null]})]})]},e.sha);})}):(0,r.jsxs)("div",{style:d9,role:"status","aria-live":"polite",children:[(0,r.jsx)($.F.activity,{size:20}),(0,r.jsx)("p",{style:d6,children:"History is unavailable for this repository."})]});}function uw(e){let{entry:t}=e;return(0,r.jsx)("div",{className:"rv-empty",role:"region","aria-label":"Commit details",children:(0,r.jsxs)("dl",{style:{display:"grid",gridTemplateColumns:"max-content minmax(0, 1fr)",gap:"6px 16px",width:"min(560px, 100%)",textAlign:"left",font:"400 13px var(--font-ui)",color:"var(--fg-muted)"},children:[(0,r.jsx)("dt",{children:"Commit"}),(0,r.jsx)("dd",{className:"mono",style:{margin:0,color:"var(--fg)",overflowWrap:"anywhere"},children:t.sha}),(0,r.jsx)("dt",{children:"Short SHA"}),(0,r.jsx)("dd",{className:"mono",style:{margin:0,color:"var(--fg)"},children:t.shortSha}),(0,r.jsx)("dt",{children:"Parents"}),(0,r.jsx)("dd",{style:{margin:0,color:"var(--fg)"},children:t.parentCount}),(0,r.jsx)("dt",{children:"Changed files"}),(0,r.jsx)("dd",{style:{margin:0,color:"var(--fg)"},children:t.changedFileCount}),(0,r.jsx)("dt",{children:"Refs"}),(0,r.jsx)("dd",{style:{margin:0,color:"var(--fg)"},children:0===t.refs.length?"None":t.refs.join(", ")})]})});}function uj(e){return"A"===e?"added":"C"===e?"copied":"D"===e?"deleted":"M"===e?"modified":"R"===e?"renamed":"T"===e?"type changed":"U"===e?"unmerged":`status ${e}`;}let uk=[{id:"changes",label:"Changes"},{id:"history",label:"History"}];function uN(e){var t;let{tab:n,onTabChange:l,status:a,statusLoading:s,statusError:o,selectedChangePath:c,onSelectChange:d,onStageFile:u,onUnstageFile:p,onStageAll:m,onUnstageAll:h,stagingBusy:f,stagingOutcome:g,stagingError:v,history:b,historyLoading:y,historyError:x,selectedCommitSha:w,onSelectCommit:j,commitComposer:k}=e,N=(0,i.useRef)(null),S=(0,i.useId)(),C=null!=(t=null==a?void 0:a.changes.length)?t:0,R=e=>{var t,a;let r,i=uk.findIndex(e=>e.id===n);if("ArrowRight"===e.key)r=(i+1)%uk.length;else if("ArrowLeft"===e.key)r=(i-1+uk.length)%uk.length;else if("Home"===e.key)r=0;else{if("End"!==e.key)return;r=uk.length-1;}e.preventDefault();let s=uk[r];if(void 0===s)return;l(s.id);let o=null==(t=N.current)?void 0:t.querySelectorAll('[role="tab"]');null==o||null==(a=o[r])||a.focus();};return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",minHeight:0,flex:1},children:[(0,r.jsx)("div",{style:dT,children:(0,r.jsx)("div",{ref:N,role:"tablist","aria-label":"Changes and history",style:{display:"flex",alignItems:"stretch"},children:uk.map(e=>{let t=e.id===n;return(0,r.jsxs)("button",{type:"button",role:"tab",id:`${S}-tab-${e.id}`,"aria-selected":t?"true":"false","aria-controls":`${S}-panel-${e.id}`,tabIndex:t?0:-1,style:{position:"relative",display:"inline-flex",alignItems:"center",gap:7,padding:"0 12px",border:0,background:"transparent",cursor:"pointer",fontSize:13,fontWeight:600,color:t?"var(--fg)":"var(--fg-muted)"},onClick:()=>l(e.id),onKeyDown:R,children:[e.label,"changes"===e.id?(0,r.jsx)("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",minWidth:18,height:18,padding:"0 5px",borderRadius:999,fontFamily:"var(--font-mono)",fontSize:10.5,fontWeight:600,background:t?"var(--accent-dim)":"var(--inset)",color:t?"var(--accent-on-tint)":"var(--fg-muted)"},children:C}):null,(0,r.jsx)("span",{"aria-hidden":"true",style:{position:"absolute",left:8,right:8,bottom:-1,height:2,borderRadius:2,background:t?"var(--accent)":"transparent"}})]},e.id);})})}),(0,r.jsxs)("div",{role:"tabpanel",id:`${S}-panel-changes`,"aria-labelledby":`${S}-tab-changes`,hidden:"changes"!==n,style:{display:"changes"===n?"flex":"none",flexDirection:"column",minHeight:0,flex:1},children:[(0,r.jsx)(uS,{status:a,statusLoading:s,statusError:o,selectedChangePath:c,onSelectChange:d,onStageFile:u,onUnstageFile:p,onStageAll:m,onUnstageAll:h,stagingBusy:f,stagingOutcome:g,stagingError:v}),k]}),(0,r.jsx)("div",{role:"tabpanel",id:`${S}-panel-history`,"aria-labelledby":`${S}-tab-history`,hidden:"history"!==n,style:{display:"history"===n?"flex":"none",flexDirection:"column",minHeight:0,flex:1},children:(0,r.jsx)(ux,{history:b,loading:y,error:x,selectedSha:w,onSelect:j})})]});}function uS(e){let{status:t,statusLoading:n,statusError:l,selectedChangePath:a,onSelectChange:i,onStageFile:s,onUnstageFile:o,onStageAll:c,onUnstageAll:d,stagingBusy:u,stagingOutcome:p,stagingError:m}=e;if(null!==l)return(0,r.jsx)("p",{className:"rv-empty",role:"alert",style:{padding:14},children:l});if(n&&null===t)return(0,r.jsx)("p",{className:"rv-empty",role:"status",style:{padding:14},children:"Loading changes…"});if(null===t)return(0,r.jsxs)("div",{style:d9,role:"status","aria-live":"polite",children:[(0,r.jsx)($.F.git,{size:20}),(0,r.jsx)("p",{style:d6,children:"Select a repository to view its changes."})]});if(!t.available){var h;return(0,r.jsxs)("div",{style:d9,role:"status","aria-live":"polite",children:[(0,r.jsx)($.F.git,{size:20}),(0,r.jsx)("p",{style:d6,children:null!=(h=t.message)?h:"This folder is not a Git repository."})]});}if(t.detached)return(0,r.jsxs)("div",{style:d9,role:"alert","aria-live":"assertive",children:[(0,r.jsx)($.F.branch,{size:20}),(0,r.jsx)("p",{style:d6,children:"Detached HEAD. Switch to an existing branch or create a branch before committing or syncing."})]});let f=!t.clean&&t.changes.length>0,g=u||t.truncated,v=t.stagedCount>0&&!t.truncated,b=(t.unstagedCount>0||t.untrackedCount>0)&&!t.truncated;return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",minHeight:0,flex:1},children:[t.conflictedCount>0?(0,r.jsxs)("div",{role:"alert",style:{display:"flex",alignItems:"center",gap:8,padding:"8px 14px",borderBottom:"1px solid var(--line-soft)",color:"var(--danger)",background:"color-mix(in oklch, var(--danger) 10%, transparent)",font:"400 13px var(--font-ui)"},children:[(0,r.jsx)($.F.info,{size:14}),"Resolve conflicted files before committing or syncing."]}):null,f?(0,r.jsxs)("div",{style:dF,children:[(0,r.jsx)("span",{"aria-hidden":"true",style:dD,children:(0,r.jsx)($.F.check,{size:11})}),(0,r.jsxs)("span",{style:{fontSize:12,fontWeight:600,color:"var(--fg-muted)"},children:[t.stagedCount," of ",t.changes.length," files staged"]})]}):null,f?(0,r.jsxs)("div",{style:dM,children:[(0,r.jsx)("span",{style:{flex:1,minWidth:0}}),(0,r.jsxs)("button",{type:"button",style:{...dP,...dA(g||!b)},disabled:g||!b,onClick:c,children:[(0,r.jsx)($.F.check,{size:11})," Stage all"]}),(0,r.jsxs)("button",{type:"button",style:{...dP,...dA(g||!v)},disabled:g||!v,onClick:d,children:[(0,r.jsx)($.F.reset,{size:11})," Unstage all"]})]}):null,null!==m||null!==p?(0,r.jsx)("div",{style:{padding:"0 14px 8px"},children:(0,r.jsx)(uy,{outcome:p,error:m,testid:"git-staging-outcome"})}):null,t.truncated?(0,r.jsxs)("p",{style:{...d6,padding:"0 14px 6px",fontSize:12},role:"status",children:["Showing the first ",t.maxChanges," changes; the list is truncated."]}):null,(0,r.jsx)("div",{style:dL,children:t.clean||0===t.changes.length?(0,r.jsx)("div",{className:"rv-empty",children:(0,r.jsx)("p",{className:"rv-empty-p",children:"No changes"})}):(0,r.jsx)("nav",{"aria-label":"Changed files",children:(0,r.jsx)("ul",{style:{listStyle:"none",margin:0,padding:0},children:t.changes.map(e=>(0,r.jsx)(uR,{change:e,selected:e.path===a,stagingBusy:u,onSelect:()=>i(e.path),onToggleStage:()=>e.staged?o(e):s(e)},e.path))})})})]});}let uC={position:"absolute",inset:0,width:"100%",height:"100%",margin:0,opacity:0,cursor:"pointer"};function uR(e){var t,n;let l,a,{change:i,selected:s,stagingBusy:o,onSelect:c,onToggleStage:d}=e,u=function(e){if(e.conflicted)return"conflicted";if(e.untracked)return"untracked";let t=" "!==e.indexStatus?uj(e.indexStatus):null,n=" "!==e.worktreeStatus?uj(e.worktreeStatus):null;return null!==t&&null!==n?`staged ${t}; worktree ${n}`:null!==t?`staged ${t}`:null!==n?n:"changed";}(i),p=i.conflicted?"U":i.untracked?"A":" "!==i.indexStatus?i.indexStatus:i.worktreeStatus,m=`${i.staged?"Unstage":"Stage"} ${i.path}`,{dir:h,name:f}=(l=(t=i.path).lastIndexOf("/"))<0?{dir:"",name:t}:{dir:t.slice(0,l+1),name:t.slice(l+1)};return(0,r.jsx)("li",{style:{padding:"0 0 2px"},children:(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:11,width:"100%",padding:"9px 10px",border:0,borderRadius:9,cursor:"pointer",textAlign:"left",background:s?"var(--accent-dim)":"transparent",boxShadow:s?"inset 2px 0 0 var(--accent)":"none"},children:[(0,r.jsxs)("label",{style:{position:"relative",display:"inline-flex",flex:"none",cursor:"pointer"},children:[(0,r.jsx)("input",{type:"checkbox",checked:i.staged,disabled:o,onChange:d,"aria-label":m,title:m,style:uC}),(0,r.jsx)("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:16,height:16,flex:"none",borderRadius:5,background:(n=i.staged)?"var(--accent-solid)":"transparent",boxShadow:n?"none":"inset 0 0 0 1.5px var(--line-strong)",color:"var(--accent-solid-ink)",cursor:"pointer"},children:i.staged?(0,r.jsx)($.F.check,{size:11}):null})]}),(0,r.jsxs)("button",{type:"button",title:i.path,"aria-label":`${i.path}, ${u}`,"aria-pressed":s,onClick:c,style:{display:"flex",flexDirection:"column",gap:2,minWidth:0,flex:1,border:0,background:"transparent",cursor:"pointer",textAlign:"left",padding:0},children:[(0,r.jsxs)("span",{style:dq,children:[(0,r.jsxs)("span",{className:"rv-sr-only",children:[u," "]}),f]}),""!==h?(0,r.jsx)("span",{style:dz,children:h}):null]}),(0,r.jsx)("span",{"aria-hidden":"true",style:(a=function(e){switch(e){case"A":case"?":return"var(--ok)";case"D":case"U":return"var(--danger)";case"R":case"T":return"var(--warn)";default:return"var(--info)";}}(p),{display:"inline-flex",alignItems:"center",justifyContent:"center",width:18,height:18,flex:"none",borderRadius:5,fontFamily:"var(--font-mono)",fontSize:11,fontWeight:700,background:`color-mix(in oklch, ${a} 16%, transparent)`,color:a}),children:p})]})});}function uI(e){let t,n,l,{projectId:a,branchName:s,stagedFileCount:o,busy:c,outcome:d,error:u,preview:p,previewDraft:m,previewError:h,onPreview:f,onCommit:g,onCreatePullRequest:v,onMerge:b}=e,[y,x]=(0,i.useState)(""),[w,j]=(0,i.useState)(""),k=(0,i.useId)(),N=`${k}-hint`,S=`${k}-preview`,C=(0,i.useRef)(f);C.current=f;let R=null!==a&&""!==a,I=o>0,E=(t=y.trim(),""===(n=w.trim())?t:`${t}
99
+
100
+ ${n}`),A=""===y.trim();(0,i.useEffect)(()=>{if(!R||!I)return;let e=setTimeout(()=>C.current(E),400);return()=>clearTimeout(e);},[R,I,E,o]);let T=null!==p&&m===E?p:null,F=null!==T&&!T.messageValidation.ok,D=!A&&null===T,M=c||!R||!I||A||D||F;l=R?I?A?"Enter a commit summary.":D?"Wait for commit policy preview.":F?"Resolve the commit-policy issues below to commit.":"Commits the staged changes to the current branch.":"Stage changes to commit them to the current branch.":"Select a repository to commit.";let P=void 0!==s&&""!==s?`Commit to ${s}`:"Commit";return(0,r.jsxs)("section",{style:dO,"aria-label":"Commit",children:[(0,r.jsx)("input",{type:"text","aria-label":"Summary",style:{width:"100%",minHeight:38,padding:"0 12px",borderRadius:9,border:0,background:"var(--inset)",boxShadow:"inset 0 0 0 1px var(--line)",color:"var(--fg)",font:"400 13px var(--font-ui)"},value:y,disabled:!R,"aria-invalid":F?"true":void 0,"aria-describedby":F?S:N,onChange:e=>x(e.target.value),placeholder:"Concise summary of the change"}),(0,r.jsx)("textarea",{"aria-label":"Description",style:dB,value:w,disabled:!R,onChange:e=>j(e.target.value),placeholder:"Optional — explain the intent and verification"}),(0,r.jsx)("p",{id:N,role:"status","aria-live":"polite",style:{...d6,fontSize:11.5,color:"var(--fg-faint)"},children:l}),(0,r.jsxs)("button",{type:"button",style:{...d$,width:"100%",...dA(M)},disabled:M,"aria-describedby":N,onClick:()=>g(E),children:[(0,r.jsx)($.F.commit,{size:16})," ",P]}),void 0!==v||void 0!==b?(0,r.jsxs)("div",{style:dW,children:[void 0!==v?(0,r.jsxs)("button",{type:"button",style:{...dE,flex:1,...dA(!R)},disabled:!R,onClick:v,children:[(0,r.jsx)("span",{style:{color:"var(--fg-dim)"},children:(0,r.jsx)($.F.pullRequest,{size:16})}),"Create pull request"]}):null,void 0!==b?(0,r.jsxs)("button",{type:"button",style:{...dE,flex:1,...dA(!R)},disabled:!R,onClick:b,children:[(0,r.jsx)("span",{style:{color:"var(--fg-dim)"},children:(0,r.jsx)($.F.merge,{size:16})}),"Merge…"]}):null]}):null,null!==h?(0,r.jsxs)("div",{role:"alert",style:{...d7,boxShadow:"inset 0 0 0 1px color-mix(in oklch, var(--danger) 48%, var(--line))"},children:[(0,r.jsxs)(uv,{tone:"danger",children:[(0,r.jsx)($.F.info,{size:11})," Preview unavailable"]}),(0,r.jsx)("p",{style:d6,children:h})]}):null,null!==T?(0,r.jsx)(uE,{id:S,preview:T}):null,(0,r.jsx)(uy,{outcome:d,error:u,testid:"git-commit-outcome"})]});}function uE(e){let{id:t,preview:n}=e,l=n.messageValidation.ok?[]:n.messageValidation.violations,a=!n.messageValidation.ok,{summary:i,intent:s}=n;return(0,r.jsxs)("div",{id:t,"data-testid":"git-commit-preview",role:a?"alert":"status","aria-live":a?void 0:"polite",style:d7,children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,r.jsxs)(uv,{tone:a?"danger":"success",children:[(0,r.jsx)($.F.check,{size:11})," ",a?"Policy: action needed":"Meets commit policy"]}),(0,r.jsxs)("p",{style:{...d6,fontSize:12,color:"var(--fg)"},children:[i.stagedFileCount," staged file",1===i.stagedFileCount?"":"s"," across ",i.areaCount," area",1===i.areaCount?"":"s",i.touchesTests?" \xb7 touches tests":""]})]}),void 0!==s.suggestedSubjectPrefix?(0,r.jsxs)("p",{style:{...d6,fontSize:12,color:"var(--fg)"},children:["Suggested prefix: ",(0,r.jsx)("code",{style:d8,children:s.suggestedSubjectPrefix})]}):null,(0,r.jsx)(ub,{label:"Message-policy violations",testid:"git-commit-violations",items:l.map(e=>({key:e,text:cW[e]}))}),(0,r.jsx)(ub,{label:"Quality warnings",testid:"git-commit-warnings",items:s.warnings.map(e=>({key:e,text:cB[e]}))}),(0,r.jsx)(ub,{label:"Preflight findings",testid:"git-commit-findings",items:n.preflightFindingCodes.map(e=>({key:e,text:e}))})]});}function u$(e){return e.startsWith("a/")||e.startsWith("b/")?e.slice(2):e;}function uA(e){let t=new TextEncoder(),n=t.encode(e).byteLength;if(0===e.length)return{files:[],truncated:!1,totalBytes:0};let l=e,a=!1;if(n>524288){a=!0;let n=t.encode(e),r=new TextDecoder().decode(n.slice(0,524288)),i=r.lastIndexOf("\n");l=-1===i?r:r.slice(0,i+1);}let r=l.split("\n"),i=r.length>0&&""===r[r.length-1]?r.slice(0,-1):r,s=[],o=null,c=null,d=0,u=0,p=()=>{null!==o&&null!==c&&o.hunks.push(c),c=null;},m=()=>{p(),null!==o&&(s.length<400?s.push(o):a=!0),o=null;},h=0;for(;h<i.length;){var f,g,v;let e=null!=(f=i[h])?f:"";if(e.startsWith("diff --git ")){m();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],l=u$(`b/${n}`),a=u$(`a/${e}`),r={path:l,hunks:[],addedLines:0,removedLines:0};a!==l&&(r.oldPath=a),o=r;}h++;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++,h++;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++,h++;continue;}if(e.startsWith("\\ ")){let t={kind:"meta",oldLine:null,newLine:null,text:e};c.lines.push(t),h++;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++,h++;continue;}}if(e.startsWith("--- ")){let t=e.slice(4);if("/dev/null"!==t&&null===o)m(),o={path:u$(t),hunks:[],addedLines:0,removedLines:0};else if("/dev/null"!==t&&null!==o){let e=u$(t);e!==o.path&&(o.oldPath=e);}h++;continue;}if(e.startsWith("+++ ")){let t=e.slice(4);"/dev/null"!==t&&null!==o?o.path=u$(t):"/dev/null"!==t&&(m(),o={path:u$(t),hunks:[],addedLines:0,removedLines:0}),h++;continue;}if(e.startsWith("@@ ")){null===o&&(o={path:"(unknown)",hunks:[],addedLines:0,removedLines:0}),p();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:[]},h++;continue;}h++;}return m(),{files:s,truncated:a,totalBytes:n};}function uT(e){let{tokens:t}=e;return(0,r.jsx)(r.Fragment,{children:t.map((e,t)=>(0,r.jsx)("span",{className:`hl-${e[0]}`,children:e[1]},t))});}function uF(e){var t,n,l;let a,{line:i,lang:s}=e,o="add"===i.kind?"+":"del"===i.kind?"−":"ctx"===i.kind?"\xb7":"",c="ctx"===i.kind?"":` rv-${i.kind}`;if("meta"!==i.kind&&"code"!==s){let e=null!=(l=r4(i.text,r0(s))[0])?l:[];a=(0,r.jsx)(uT,{tokens:e});}else a=i.text;return(0,r.jsxs)("div",{className:`rv-line${c}`,children:[(0,r.jsx)("span",{className:"rv-sr-only",children:{add:"Added line",del:"Deleted line",ctx:"Context line",meta:"Diff metadata"}[i.kind]}),(0,r.jsx)("span",{className:"rv-num-old rv-num",children:null!=(t=i.oldLine)?t:""}),(0,r.jsx)("span",{className:"rv-num-new rv-num",children:null!=(n=i.newLine)?n:""}),(0,r.jsx)("span",{className:"rv-gutter","aria-hidden":"true",children:o}),(0,r.jsx)("code",{className:"rv-src",children:a})]});}function uD(e){let{hunk:t,lang:n}=e;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"rv-hunk mono","aria-label":`Hunk header ${t.header}`,children:[(0,r.jsx)("span",{className:"rv-sr-only",children:"Hunk header"}),t.header]}),t.lines.map((e,t)=>(0,r.jsx)(uF,{line:e,lang:n},t))]});}function uM(e){var t;let{file:n,index:l,changedFiles:a,sectionRef:i}=e,s=a.find(e=>e.path===n.path),o=n.path.includes(".")&&null!=(t=n.path.split(".").pop())?t:"code";return(0,r.jsxs)("section",{id:`rv-file-${l}`,"aria-labelledby":`rv-file-${l}-h`,ref:i,children:[(0,r.jsxs)("h3",{id:`rv-file-${l}-h`,className:"rv-file mono",children:[(0,r.jsx)("span",{className:"rv-path",children:n.path}),void 0!==n.oldPath&&(0,r.jsxs)("span",{className:"rv-oldpath",children:[" (was ",n.oldPath,")"]}),(0,r.jsx)("span",{className:"spacer"}),(0,r.jsxs)("span",{className:"rv-stat add",children:["+",n.addedLines]}),(0,r.jsxs)("span",{className:"rv-stat del",children:["−",n.removedLines]}),(null==s?void 0:s.elevatedReview)===!0&&(0,r.jsx)("span",{className:"rv-elevated","aria-label":"Elevated review",children:"!"})]}),(0,r.jsx)("div",{className:"rv-code mono",children:n.hunks.map((e,t)=>(0,r.jsx)(uD,{hunk:e,lang:o},t))})]});}let uP={loading:!1,diff:null,truncated:!1,error:null},uL=[{id:"worktree",label:"Worktree"},{id:"staged",label:"Staged"}];function uq(e){var t,n;let{client:l,repositoryRoot:a,selectedChangePath:s,selectedCommit:o,scope:c,onScopeChange:d,revision:u}=e,[p,m]=(0,i.useState)(uP);(0,i.useEffect)(()=>{if(null!==o||null===a||null===s)return void m(uP);let e=!1;return m({loading:!0,diff:null,truncated:!1,error:null}),l.getDiff({root:a,path:s,scope:c}).then(t=>{e||m({loading:!1,diff:t.diff,truncated:t.truncated,error:null});},t=>{e||m({loading:!1,diff:null,truncated:!1,error:cU(t)});}),()=>{e=!0;};},[l,a,s,o,c,u]);let h=null!==p.diff&&(n=p.diff,/^Binary files .+ differ$/m.test(n)||n.includes("GIT binary patch")),f=(0,i.useMemo)(()=>null===p.diff||h?null:uA(p.diff),[p.diff,h]);return(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",minWidth:0,minHeight:0,flex:1},children:[null!==o?(0,r.jsx)(uO,{entry:o}):null!==s?(0,r.jsxs)("div",{style:dK,children:[(0,r.jsx)(uz,{path:s}),(0,r.jsx)("span",{style:{flex:1}}),(0,r.jsx)("div",{role:"group","aria-label":"Diff scope",style:dV,children:uL.map(e=>{let t=e.id===c;return(0,r.jsx)("button",{type:"button",style:{appearance:"none",height:22,padding:"0 10px",borderRadius:6,border:0,background:t?"var(--card)":"transparent",color:t?"var(--fg)":"var(--fg-muted)",font:`${t?600:500} 11px var(--font-ui)`,cursor:"pointer",whiteSpace:"nowrap"},"aria-pressed":t,onClick:()=>d(e.id),children:e.label},e.id);})})]}):null,(0,r.jsx)("div",{style:{flex:1,minHeight:0,overflow:"auto"},className:"review",role:"region","aria-label":"Diff",tabIndex:0,children:(0,r.jsx)(uB,{selectedChangePath:s,selectedCommit:o,state:p,binary:h,files:null!=(t=null==f?void 0:f.files)?t:null})})]});}function uz(e){let t,{path:n}=e,{dir:l,name:a}=(t=n.lastIndexOf("/"))<0?{dir:"",name:n}:{dir:n.slice(0,t+1),name:n.slice(t+1)};return(0,r.jsxs)("span",{style:dU,title:n,children:[l,(0,r.jsx)("span",{style:{color:"var(--fg)"},children:a})]});}function uO(e){var t;let n,{entry:l}=e;return(0,r.jsxs)("div",{style:dY,children:[(0,r.jsx)("h2",{tabIndex:-1,style:{margin:0,fontSize:14,fontWeight:600,color:"var(--fg)"},children:l.subject}),(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:9,flexWrap:"wrap",fontSize:11.5,color:"var(--fg-muted)"},children:[(0,r.jsx)("span",{"aria-hidden":"true",style:{...d_(22),fontSize:9.5},children:l.author.slice(0,2).toUpperCase()}),(0,r.jsx)("span",{style:{color:"var(--fg)"},children:l.author}),(0,r.jsx)("span",{children:"committed"}),(0,r.jsx)("span",{style:dJ,children:l.shortSha}),(0,r.jsx)("span",{children:"\xb7"}),(0,r.jsx)("span",{children:Number.isNaN((n=new Date(t=l.date)).getTime())?t:n.toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"})}),(0,r.jsx)("span",{style:{flex:1}}),(0,r.jsxs)("span",{style:{color:"var(--fg-faint)"},children:[l.changedFileCount," ",1===l.changedFileCount?"file changed":"files changed"]})]})]});}function uB(e){let{selectedChangePath:t,selectedCommit:n,state:l,binary:a,files:i}=e;return null!==n?(0,r.jsx)(uw,{entry:n}):null===t?(0,r.jsxs)("div",{className:"rv-empty","aria-label":"Diff",children:[(0,r.jsx)("h2",{className:"rv-empty-h",children:"Diff"}),(0,r.jsx)("p",{className:"rv-empty-p",children:"Select a change to view its diff."})]}):null!==l.error?(0,r.jsx)("p",{className:"rv-empty",role:"alert",style:{padding:14},children:l.error}):l.loading?(0,r.jsx)("p",{className:"rv-empty",role:"status",style:{padding:14},children:"Loading diff…"}):a?(0,r.jsx)("div",{className:"rv-empty",children:(0,r.jsx)("p",{className:"rv-empty-p",style:d6,children:"Binary file — no text diff to display."})}):null===i||0===i.length?(0,r.jsx)("div",{className:"rv-empty",children:(0,r.jsx)("p",{className:"rv-empty-p",style:d6,children:"No diff content for this change."})}):(0,r.jsxs)("div",{className:"rv-body",children:[l.truncated?(0,r.jsx)("p",{className:"rv-truncated",role:"status",style:{...d6,padding:14},children:"This diff is large and has been truncated."}):null,i.map((e,t)=>(0,r.jsx)(uM,{file:e,index:t,changedFiles:[],sectionRef:()=>void 0},e.path))]});}function uW(e){var t,n,l,a;let{branches:s,currentBranch:o,busy:c,error:d,onCreate:u,onClose:p}=e,m=null!=(t=null!=(n=null==(l=s.find(e=>e.name===o))?void 0:l.name)?n:null==(a=s[0])?void 0:a.name)?t:"",[h,f]=(0,i.useState)(""),[g,v]=(0,i.useState)(m),b=(0,i.useRef)(null),y=(0,i.useRef)(null);(0,i.useEffect)(()=>{var e;null==(e=y.current)||e.focus();},[]);let x=h.trim(),w=x.length>0&&g.length>0&&!c,j=(0,r.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"New branch",tabIndex:-1,onKeyDown:e=>{var t,n;if("Escape"===e.key)return void p();if("Tab"!==e.key)return;let l=Array.from(null!=(t=null==(n=b.current)?void 0:n.querySelectorAll('button:not([disabled]), input:not([disabled]), [role="combobox"]:not([aria-disabled="true"])'))?t:[]);if(0===l.length)return;let a=l[0],r=l[l.length-1];e.shiftKey&&document.activeElement===a?(e.preventDefault(),r.focus()):e.shiftKey||document.activeElement!==r||(e.preventDefault(),a.focus());},style:{position:"fixed",inset:0,zIndex:100,display:"grid",placeItems:"center",background:"color-mix(in oklch, var(--surface-primary) 45%, transparent)"},children:(0,r.jsxs)("form",{ref:b,style:{display:"flex",flexDirection:"column",gap:"var(--space-4)",width:"min(420px, calc(100vw - 48px))",padding:"var(--space-5)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-card)",background:"var(--surface-primary)",boxShadow:"var(--shadow-popover)"},onSubmit:e=>{e.preventDefault(),w&&u({branchName:x,baseBranchName:g});},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-3)"},children:[(0,r.jsx)($.F.branch,{size:16}),(0,r.jsx)("h2",{style:{margin:0,font:"var(--weight-semibold) var(--text-body) var(--font-ui)"},children:"New branch"})]}),(0,r.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:"var(--space-2)"},children:[(0,r.jsx)("span",{style:{font:"var(--weight-semibold) var(--text-caption) var(--font-ui)",color:"var(--text-faint)",textTransform:"uppercase"},children:"Branch name"}),(0,r.jsx)("input",{ref:y,value:h,style:ue,"aria-label":"Branch name",onChange:e=>f(e.currentTarget.value)})]}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-2)"},children:[(0,r.jsx)("span",{style:{font:"var(--weight-semibold) var(--text-caption) var(--font-ui)",color:"var(--text-faint)",textTransform:"uppercase"},children:"Base branch"}),(0,r.jsx)(ln.A,{value:g,ariaLabel:"Base branch",menuTitle:"Base branch",leadingVisual:(0,r.jsx)($.F.branch,{size:12}),mono:!0,sections:[{options:s.map(e=>({value:e.name,label:e.name,...(e.name===o?{badge:"current"}:{})}))}],onValueChange:v})]}),(0,r.jsx)("p",{style:d6,children:"The branch starts from the selected base branch. Commit hashes stay internal."}),null!==d?(0,r.jsx)("p",{role:"alert",style:{...d6,color:"var(--feedback-danger)"},children:d}):null,(0,r.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:"var(--space-3)"},children:[(0,r.jsx)("button",{type:"button",style:dE,onClick:p,children:"Cancel"}),(0,r.jsx)("button",{type:"submit",disabled:!w,style:{...d$,...dA(!w)},children:"Create branch"})]})]})});return"u"<typeof document?j:(0,n9.createPortal)(j,document.body);}function uK(e){if(void 0===e||""===e)return;let t=e.replace(/\.git$/u,""),n=/^git@github\.com:([A-Za-z0-9._-]+\/[A-Za-z0-9._-]+)$/u.exec(t);if((null==n?void 0:n[1])!==void 0)return n[1];try{let e=new URL(t);if("github.com"!==e.hostname)return;let n=e.pathname.split("/").filter(Boolean);if(n.length>=2)return`${n[0]}/${n[1]}`;}catch{}}function uU(e){var t,n,l,a,s,o,c,d;let u,{projectId:p,onOpenFiles:m,onOpenEditor:h,updateCfg:f,client:g=cO}=e,[v,b]=(0,i.useState)([]),[y,x]=(0,i.useState)(!1),[w,j]=(0,i.useState)(null),[k,N]=(0,i.useState)(void 0!==p&&""!==p?p:null),[S,C]=(0,i.useState)([]),[R,I]=(0,i.useState)(!1),[E,A]=(0,i.useState)(null),[T,F]=(0,i.useState)(null),[D,M]=(0,i.useState)(!1),[P,L]=(0,i.useState)(null),[q,z]=(0,i.useState)([]),[O,B]=(0,i.useState)(null),[W,K]=(0,i.useState)(null),[U,V]=(0,i.useState)(null),[H,_]=(0,i.useState)(!1),[G,J]=(0,i.useState)(null),[Y,X]=(0,i.useState)(null),[Z,Q]=(0,i.useState)(null),[ee,et]=(0,i.useState)(null),[en,el]=(0,i.useState)(!1),[ea,er]=(0,i.useState)(null),[ei,es]=(0,i.useState)(0),[eo,ec]=(0,i.useState)("changes"),[ed,eu]=(0,i.useState)(null),[ep,em]=(0,i.useState)("worktree"),[eh,ef]=(0,i.useState)(0),[eg,ev]=(0,i.useState)(!1),[eb,ey]=(0,i.useState)("clone"),[ex,ew]=(0,i.useState)(!1),[ej,ek]=(0,i.useState)(!1),[eN,eS]=(0,i.useState)(null),[eC,eR]=(0,i.useState)(null),[eI,eE]=(0,i.useState)("diff"),[e$,eA]=(0,i.useState)(""),eT=(0,i.useRef)(0),eF=(0,i.useRef)(null),eD=(0,i.useRef)(null),eM=(0,i.useRef)(null),eP=null!=k?k:"",eL=cV(g,eP),eq=cV(g,eP),ez=cV(g,eP),eO=eL.reset,eB=eq.reset,eW=ez.reset,eK=(0,i.useCallback)(()=>{eF.current="u"<typeof document?null:document.activeElement,ew(!0);},[]),eU=(0,i.useCallback)(()=>{ew(!1);let e=eF.current;eF.current=null,null!==e&&queueMicrotask(()=>e.focus());},[]),eV=(0,i.useCallback)(()=>{x(!0),j(null),g.listRepositories().then(e=>{b(e.projects),x(!1);},e=>{b([]),x(!1),j(cU(e));});},[g]);(0,i.useEffect)(()=>{eV();},[eV]),(0,i.useEffect)(()=>{void 0!==p&&""!==p&&N(p);},[p]),(0,i.useEffect)(()=>{if("diff"===eI)return;let e=window.requestAnimationFrame(()=>{var e;let t=null==(e=eD.current)?void 0:e.querySelector("h2");t instanceof HTMLElement&&(t.tabIndex=-1,t.focus());});return()=>window.cancelAnimationFrame(e);},[eI]),(0,i.useEffect)(()=>{eB(),eW(),eO(),eT.current+=1,eS(null),eR(null),ek(!1),eu(null),em("worktree"),eE("diff"),eA(""),K(null),V(null),_(!1),J(null),X(null);},[k,eB,eW,eO]),(0,i.useEffect)(()=>{if(null===k)return void C([]);let e=!1;return I(!0),g.listBranches(k).then(t=>{e||(C(t.available?t.branches:[]),I(!1));},()=>{e||(C([]),I(!1));}),()=>{e=!0;};},[g,k,ei]),(0,i.useEffect)(()=>{if(null===k){A(null),F(null),L(null);return;}let e=!1;return M(!0),L(null),g.getSummary(k).then(t=>{e||(A(t),F(k),M(!1));},t=>{e||(A(null),F(null),M(!1),L(cU(t)));}),()=>{e=!0;};},[g,k,ei]),(0,i.useEffect)(()=>{if(null===k){z([]),B(null);return;}let e=!1;return g.getRemotes(k).then(t=>{e||(z(t.available?t.remotes:[]),B(k));},()=>{e||(z([]),B(null));}),()=>{e=!0;};},[g,k]),(0,i.useEffect)(()=>{if(null===k){K(null),V(null),J(null),X(null);return;}if("history"!==eo)return void _(!1);let e=!1;return _(!0),J(null),g.getHistory({root:k,limit:50}).then(t=>{e||(K(t),V(k),_(!1),X(e=>{var n,l;return 0===t.entries.length?null:null!==e&&t.entries.some(t=>t.sha===e)?e:null!=(n=null==(l=t.entries[0])?void 0:l.sha)?n:null;}));},t=>{e||(K(null),V(null),_(!1),J(cU(t)));}),()=>{e=!0;};},[g,k,ei,eo]),(0,i.useEffect)(()=>{if(null===k){Q(null),et(null),er(null);return;}let e=!1;return el(!0),er(null),g.getStatus(k).then(t=>{e||(Q(t),et(k),el(!1),eu(e=>{if(null===e)return null;let n=t.changes.find(t=>t.path===e);return void 0===n?null:(em(e=>!n.staged||n.unstaged||n.untracked||"worktree"!==e?!n.staged&&(n.unstaged||n.untracked||n.conflicted)&&"staged"===e?"worktree":e:"staged"),e);}));},t=>{e||(Q(null),et(null),el(!1),er(cU(t)));}),()=>{e=!0;};},[g,k,ei]);let eH=eq.flow.outcome;(0,i.useEffect)(()=>{(null==eH?void 0:eH.status)==="succeeded"&&es(e=>e+1);},[eH]);let e_=ez.flow.outcome;(0,i.useEffect)(()=>{(null==e_?void 0:e_.status)==="succeeded"&&(es(e=>e+1),ef(e=>e+1));},[e_]);let eG=eL.flow.outcome;(0,i.useEffect)(()=>{(null==eG?void 0:eG.status)==="succeeded"&&(eU(),es(e=>e+1));},[eG,eU]);let eJ=(0,i.useCallback)(e=>{N(e),null==f||f({projectPath:e});},[f]),eY=(0,i.useCallback)(e=>{eV(),eJ(e.path);},[eV,eJ]),eX=null!==k&&ee===k?Z:null,eZ=null!==k&&T===k?E:null,eQ=null!==k&&O===k?q:[],e0=null!==k&&U===k?W:null,e1=null!=(t=null==e0?void 0:e0.entries.find(e=>e.sha===Y))?t:null,e2=(0,i.useCallback)(e=>{eu(e);let t=null==eX?void 0:eX.changes.find(t=>t.path===e);void 0!==t&&em(!t.staged||t.unstaged||t.untracked?"worktree":"staged");},[eX]),e4=(0,i.useCallback)(e=>{null!==k&&eq.runMutation(()=>g.stage({projectId:k,pathspecs:[e.path],includeUntracked:e.untracked}));},[g,k,eq]),e3=(0,i.useCallback)(e=>{null!==k&&eq.runMutation(()=>g.unstage({projectId:k,pathspecs:[e.path]}));},[g,k,eq]),e6=(0,i.useCallback)(()=>{if(null===k||null===eX||eX.truncated)return;let e=eX.changes.filter(e=>e.unstaged||e.untracked).map(e=>e.path);if(0===e.length)return;let t=eX.changes.some(e=>e.untracked);eq.runMutation(()=>g.stage({projectId:k,pathspecs:e,includeUntracked:t}));},[eX,g,k,eq]),e5=(0,i.useCallback)(()=>{if(null===k||null===eX||eX.truncated)return;let e=eX.changes.filter(e=>e.staged).map(e=>e.path);0!==e.length&&eq.runMutation(()=>g.unstage({projectId:k,pathspecs:e}));},[eX,g,k,eq]),e8=(0,i.useCallback)(e=>{null!==k&&ez.runMutation(()=>g.commitExecute({projectId:k,message:e}));},[g,ez,k]),e9=(0,i.useCallback)(e=>{null!==k&&eL.runMutation(()=>g.branchSwitch({projectId:k,branchName:e}));},[eL,g,k]),e7=(0,i.useCallback)(e=>{let{branchName:t,baseBranchName:n}=e;if(null===k)return;let l=S.find(e=>e.name===n);void 0!==l&&eL.runMutation(async()=>{let e=await g.branchCreate({projectId:k,branchName:t,baseBranchName:n,startPointRefHash:l.headRefHash});if("succeeded"!==e.status)return e;let a=await g.branchSwitch({projectId:k,branchName:t});return"succeeded"===a.status?{...a,actionKind:"branch-create"}:a;});},[eL,S,g,k]),te=function(e,t){var n,l,a,r;if(t&&null===e)return{action:"blocked",label:"Sync",description:"Checking repository sync state.",disabled:!0};if(null===e)return{action:"blocked",label:"Sync",description:"Select a repository to sync.",disabled:!0};if(!e.available)return{action:"blocked",label:"Sync unavailable",description:"Open a Git repository before syncing.",disabled:!0};if(e.detached)return{action:"blocked",label:"Detached HEAD",description:"Switch to a branch or create a branch before syncing.",disabled:!0};if(e.conflictedCount>0)return{action:"blocked",label:"Resolve conflicts",description:"Resolve conflicted files in Changes before syncing.",disabled:!0};let i=null!=(n=e.branch)?n:"";if(0===i.length)return{action:"blocked",label:"No branch",description:"Create or switch to a branch before syncing.",disabled:!0};let s=null!=(r=e.remotes.find(e=>"origin"===e.name))?r:e.remotes[0];if(void 0===s)return{action:"blocked",label:"No remote",description:"Add a Git remote before fetching, pulling, or pushing.",disabled:!0};if(void 0===e.upstream)return{action:"publish-upstream",label:"Publish upstream",description:`Publish ${i} to ${s.name} and set upstream tracking.`,disabled:!1,remoteAlias:s.name,remoteBranchName:i,sourceBranchName:i,setUpstreamTracking:!0};let o=null!=(l=e.upstream.remote)?l:s.name,c=null!=(a=e.upstream.branch)?a:i;return e.ahead>0&&e.behind>0?{action:"fetch",label:"Fetch",description:`Diverged: ${e.ahead.toString()} ahead, ${e.behind.toString()} behind. Fetch latest, then use Merge to reconcile.`,disabled:!1,remoteAlias:o}:e.behind>0?{action:"pull",label:"Pull",description:`${e.behind.toString()} behind ${e.upstream.ref}. Pull fast-forward changes.`,disabled:!1,remoteAlias:o}:e.ahead>0?{action:"push",label:"Push",description:`${e.ahead.toString()} ahead of ${e.upstream.ref}. Push local commits.`,disabled:!1,remoteAlias:o,remoteBranchName:c,sourceBranchName:i,setUpstreamTracking:!1}:{action:"fetch",label:"Fetch",description:`Up to date with ${e.upstream.ref}. Fetch checks for remote updates.`,disabled:!1,remoteAlias:o};}(eZ,D),tt=(0,i.useCallback)(()=>{if(null===k||te.disabled||"blocked"===te.action)return;let e=eT.current+1;eT.current=e,ek(!0),eS(null),eR(null);let t=t=>{eT.current===e&&(ek(!1),eS(t),es(e=>e+1));},n=t=>{eT.current===e&&(ek(!1),eR(cU(t)));};if("fetch"===te.action||"pull"===te.action){let e=te.action;g.syncPreview({operation:e,projectId:k,remote:te.remoteAlias}).then(n=>{if(!n.executable){var l;t(`Blocked: ${null!=(l=n.blockReason)?l:"sync unavailable"}`);return;}return g.syncExecute({operation:e,projectId:k,remote:te.remoteAlias});}).then(n=>{void 0!==n&&t(`${"fetch"===e?"Fetch":"Pull"}: ${n.status}`);},n);return;}if(("push"===te.action||"publish-upstream"===te.action)&&void 0!==te.remoteAlias&&void 0!==te.remoteBranchName&&void 0!==te.sourceBranchName){var l;let e={projectId:k,remoteAlias:te.remoteAlias,remoteBranchName:te.remoteBranchName,sourceBranchName:te.sourceBranchName,forcePush:!1,setUpstreamTracking:null!=(l=te.setUpstreamTracking)&&l};g.pushPreview(e).then(n=>{if("allowed"!==n.policyOutcome||n.preflightBlockingCodes.length>0){var l;t(`Blocked: ${null!=(l=n.policyBlockReason)?l:n.preflightBlockingCodes.join(", ")}`);return;}return g.pushExecute(e);}).then(e=>{void 0!==e&&t(`${"push"===te.action?"Push":"Publish upstream"}: ${e.status}`);},n);}},[g,k,te]),tn=(0,i.useCallback)(e=>{null!==k&&(eE(e),eA("pull-request"===e?"Pull Request panel opened.":"Merge panel opened."));},[k]),tl=(0,i.useCallback)(()=>{eE("diff"),eA("Diff panel opened."),window.requestAnimationFrame(()=>{var e;let t=null==(e=eM.current)?void 0:e.querySelector('[role="region"][aria-label="Diff"]');t instanceof HTMLElement&&t.focus();});},[]),ta=eq.flow.outcome,tr=null!=(n=null==eX?void 0:eX.branch)?n:null==eZ?void 0:eZ.branch,ti=function(e){for(let n of e){var t;let e=null!=(t=uK(n.fetchUrl))?t:uK(n.pushUrl);if(void 0!==e)return e;}}(eQ),ts=(u=null==eZ||null==(d=eZ.upstream)?void 0:d.branch,void 0!==tr&&void 0!==u&&u!==tr?u:void 0!==tr&&"main"!==tr?"main":null!=(c=null!=u?u:tr)?c:"main");return(0,r.jsxs)("div",{style:dy,"aria-label":"Git",children:[(0,r.jsx)("h2",{className:"rv-sr-only",children:"Git"}),(0,r.jsx)("p",{role:"status","aria-live":"polite",style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:e$}),(0,r.jsx)(uc,{repositories:v,selectedPath:k,branches:S,branchesLoading:R,status:eX,statusLoading:en,branchBusy:eL.flow.busy,syncView:null===P?te:{action:"blocked",label:"Sync unavailable",description:P,disabled:!0},syncBusy:ej,syncOutcome:eN,syncError:eC,onSelectRepository:eJ,onSwitchBranch:e9,onCreateBranch:eK,onRunSync:tt,onOpenEditor:h,onOpenFiles:m}),(0,r.jsx)("div",{style:dS,children:null===k?(0,r.jsx)(ud,{repositories:v,loading:y,error:w,onSelect:eJ,onConnect:()=>{ey("open"),ev(!0);},onClone:()=>{ey("clone"),ev(!0);}}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{style:dC,children:(0,r.jsx)(uN,{tab:eo,onTabChange:ec,status:eX,statusLoading:en,statusError:ea,selectedChangePath:ed,onSelectChange:e2,onStageFile:e4,onUnstageFile:e3,onStageAll:e6,onUnstageAll:e5,stagingBusy:eq.flow.busy,stagingOutcome:ta,stagingError:eq.flow.error,history:e0,historyLoading:H,historyError:G,selectedCommitSha:Y,onSelectCommit:e=>X(e.sha),commitComposer:(0,r.jsx)(uI,{projectId:k,branchName:tr,stagedFileCount:null!=(l=null==eX?void 0:eX.stagedCount)?l:0,busy:ez.flow.busy,outcome:ez.flow.outcome,error:ez.flow.error,preview:ez.preview,previewDraft:ez.previewDraft,previewError:ez.previewError,onPreview:ez.runPreview,onCommit:e8,onCreatePullRequest:()=>tn("pull-request"),onMerge:()=>tn("merge")},`${k}:${eh.toString()}`)})}),"diff"===eI?(0,r.jsx)("div",{ref:eM,style:{minWidth:0,minHeight:0,display:"contents"},children:(0,r.jsx)(uq,{client:g,repositoryRoot:k,selectedChangePath:ed,selectedCommit:"history"===eo?e1:null,scope:ep,onScopeChange:em,revision:ei})}):(0,r.jsxs)("div",{ref:eD,style:dR,role:"region","aria-label":"pull-request"===eI?"Pull Request":"Merge",children:[(0,r.jsx)("div",{style:dK,children:(0,r.jsxs)("button",{type:"button",style:dE,onClick:tl,children:[(0,r.jsx)($.F.chevronR,{size:12,style:{transform:"rotate(180deg)"}})," Back to diff"]})}),"pull-request"===eI?(0,r.jsx)(db,{projectId:k,headBranchName:tr,ownerAndRepo:ti,baseBranchName:ts,client:g}):(0,r.jsx)(dt,{projectId:k,headBranchName:tr,ownerAndRepo:ti,baseBranchName:ts,client:g})]})]})}),eg?(0,r.jsx)(ug,{client:g,initialMode:eb,onAdded:eY,onClose:()=>ev(!1)}):null,ex?(0,r.jsx)(uW,{branches:S,currentBranch:null!=(a=null!=(s=null==eX?void 0:eX.branch)?s:null==(o=S.find(e=>e.current))?void 0:o.name)?a:"",busy:eL.flow.busy,error:eL.flow.error,onCreate:e7,onClose:eU}):null]});}async function uV(e,t){var n,l;let a=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),r="GET"!==a&&"HEAD"!==a,i=await fetch(e,{...t,headers:{Accept:"application/json",...(r?{"Content-Type":"application/json"}:{}),...(r?{"X-Keiko-CSRF":"1"}:{}),...(null!=(l=null==t?void 0:t.headers)?l:{})}});if(!i.ok){let e="INTERNAL",t=`HTTP ${i.status.toString()}`;try{let n=await i.json();e=n.error.code,t=n.error.message;}catch{}throw new m.hD(e,t,i.status);}if(204!==i.status)return i.json();}async function uH(e){let t=new URLSearchParams();return t.set("root",e),uV(`/api/containers/capability?${t.toString()}`);}async function u_(e){let t=new URLSearchParams();return t.set("projectId",e),uV(`/api/containers/catalog?${t.toString()}`);}async function uG(e){return uV("/api/containers/runs",{method:"POST",body:JSON.stringify(e)});}async function uJ(e){await uV(`/api/containers/runs/${encodeURIComponent(e)}`,{method:"DELETE"});}function uY(e){return e instanceof m.hD?{code:e.code,message:e.message}:e instanceof Error?{code:"INTERNAL",message:e.message}:{code:"INTERNAL",message:"Unexpected error."};}function uX(e,t){return null!==t&&"string"==typeof e.payload.requestId&&e.payload.requestId===t;}function uZ(e){let{engines:t}=e;return(0,r.jsx)("ul",{className:"tm-events","aria-label":"Container engines",children:t.map(e=>{let t=function(e){switch(e){case"available":return"ok";case"not-running":case"permission-denied":return"warn";case"missing":case"unsupported":return"faint";case"policy-blocked":return"danger";}}(e.state);return(0,r.jsxs)("li",{className:"tm-event",children:[(0,r.jsxs)("span",{className:"tm-event-kind",children:[(0,r.jsx)("span",{className:"dot",style:{background:"ok"===t?"var(--ok)":"warn"===t?"var(--warn)":"danger"===t?"var(--danger)":"var(--fg-faint)",marginInlineEnd:6},"aria-hidden":"true"}),e.engine]}),(0,r.jsxs)("span",{className:"tm-event-detail",children:[function(e){switch(e){case"available":return"Available";case"missing":return"Not installed";case"unsupported":return"Unsupported version";case"permission-denied":return"Permission denied";case"not-running":return"Engine not running";case"policy-blocked":return"Blocked by policy";}}(e.state),void 0!==e.version&&e.version.length>0?` \xb7 ${e.version}`:""]}),void 0!==e.remediationHint&&e.remediationHint.length>0?(0,r.jsx)("span",{className:"tm-limits",style:{color:"var(--fg-faint)"},children:e.remediationHint}):null]},e.engine);})});}function uQ(e){var t;let n,l=null!=(t=e.projectPath)?t:"",[a,s]=(0,i.useState)(null),[o,c]=(0,i.useState)([]),[d,u]=(0,i.useState)(""),[p,m]=(0,i.useState)(!1),[h,f]=(0,i.useState)(null),[g,v]=(0,i.useState)(null),[b,y]=(0,i.useState)(null),[x,w]=(0,i.useState)([]),j=(0,i.useRef)(!1),k=(0,i.useRef)(null),N=(0,i.useRef)(null),S=(0,i.useRef)(!1),C=(null==a?void 0:a.anyAvailable)===!0,R=C&&o.length>0;(0,i.useEffect)(()=>{let e=!1;return y(null),uH(l).then(t=>{e||s(t);}).catch(t=>{e||(s(null),y(uY(t)));}),()=>{e=!0;};},[l]),(0,i.useEffect)(()=>{if(!C||0===l.length){c([]),u("");return;}let e=!1;return u_(l).then(t=>{e||(c(t.tasks),u(e=>{var n,l;return e.length>0?e:null!=(n=null==(l=t.tasks[0])?void 0:l.id)?n:"";}));}).catch(t=>{e||(c([]),y(uY(t)));}),()=>{e=!0;};},[C,l]),(0,i.useEffect)(()=>{let e=new EventSource("/api/containers/events"),t=e=>{let t;try{t=JSON.parse(e.data);}catch{return;}"run-started"===t.kind&&j.current&&uX(t,k.current)&&f(e=>null!=e?e:t.runId),"run-started"!==t.kind&&uX(t,k.current)&&f(e=>e===t.runId?null:e),w(e=>[t,...e].slice(0,30));};for(let n of["run-started","run-completed","run-failed","run-cancelled"])e.addEventListener(`container:${n}`,t);return()=>{e.close();};},[]),(0,i.useEffect)(()=>{if(S.current&&!p&&document.activeElement===document.body){var e;null==(e=N.current)||e.focus();}S.current=p;},[p]);let I=(0,i.useCallback)(async e=>{if(e.preventDefault(),p||j.current||!R||0===d.length)return;y(null),v(null),f(null);let t="function"==typeof crypto.randomUUID?crypto.randomUUID():`container-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;k.current=t,j.current=!0,m(!0);try{let e=await uG({projectId:l,taskId:d,requestId:t});v(e);}catch(e){y(uY(e));}finally{j.current=!1,m(!1),k.current=null,f(null);}},[R,l,p,d]),E=(0,i.useCallback)(async()=>{if(null!==h)try{await uJ(h);}catch(e){y(uY(e));}},[h]);return(0,r.jsxs)("div",{className:"terminal commands",children:[(0,r.jsx)("section",{role:"status","aria-live":"polite","aria-label":"Container engine status",children:null===a?(0,r.jsx)("p",{className:"tm-limits",style:{color:"var(--fg-faint)"},children:"Checking for a container engine…"}):0===a.engines.length?(0,r.jsx)("p",{className:"tm-limits",style:{color:"var(--fg-faint)"},children:"No container engine was detected. Container diagnostics are unavailable; the rest of Keiko is unaffected."}):(0,r.jsx)(uZ,{engines:a.engines})}),R?(0,r.jsxs)("form",{className:"tm-form",onSubmit:e=>void I(e),children:[(0,r.jsxs)("div",{className:"tm-field",children:[(0,r.jsx)("span",{children:"Diagnostic task"}),(0,r.jsx)(ln.A,{value:d,ariaLabel:"Diagnostic task",disabled:0===o.length,menuTitle:"Allowlisted tasks",mono:!0,sections:[{options:o.map(e=>({value:e.id,label:`${e.kind} \xb7 ${e.label}`}))}],onValueChange:u})]}),(0,r.jsxs)("div",{className:"tm-actions",children:[(0,r.jsx)("button",{type:"submit",className:"tm-action","data-primary":"true",ref:N,disabled:p||0===o.length||0===d.length,"aria-disabled":p||0===o.length||0===d.length,children:p?"Running…":"Run diagnostic"}),p?(0,r.jsx)("button",{type:"button",className:"tm-action",disabled:null===h,"aria-disabled":null===h,onClick:()=>void E(),children:"Cancel"}):null]})]}):null,null!==b?(0,r.jsxs)("div",{className:"tm-error",role:"alert",children:[(0,r.jsxs)("span",{className:"tm-error-text",children:[b.message," ",(0,r.jsxs)("span",{className:"err-code mono",children:["(",b.code,")"]})]}),(0,r.jsx)("button",{type:"button",className:"tm-error-dismiss","aria-label":"Dismiss error",onClick:()=>y(null),children:"✕"})]}):null,(0,r.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite",children:null!==g?(n=[g.engine,`exit ${null===g.exitCode?"n/a":String(g.exitCode)}`,`${String(g.durationMs)} ms`],g.truncated&&n.push("output truncated"),g.timedOut&&n.push("timed out"),n.push(g.failureReason),n.push(`run ${g.runId}`,`task ${g.taskId}`),`Run finished: ${n.join(", ")}`):""}),null!==g?(0,r.jsxs)("div",{className:"tm-result",children:[(0,r.jsxs)("div",{className:"tm-badges",children:[(0,r.jsx)("span",{className:"tm-badge",children:g.engine}),(0,r.jsxs)("span",{className:0===g.exitCode?"tm-badge tm-badge-ok":"tm-badge tm-badge-fail",children:["exit ",null===g.exitCode?"n/a":String(g.exitCode)]}),(0,r.jsxs)("span",{className:"tm-badge",children:[g.durationMs," ms"]}),(0,r.jsx)("span",{className:"tm-badge",children:g.failureReason}),(0,r.jsxs)("span",{className:"tm-badge",children:["run ",g.runId]}),(0,r.jsxs)("span",{className:"tm-badge",children:["task ",g.taskId]}),g.truncated?(0,r.jsx)("span",{className:"tm-badge tm-badge-warn",children:"truncated"}):null,g.timedOut?(0,r.jsx)("span",{className:"tm-badge tm-badge-warn",children:"timed out"}):null]}),g.stdout.length>0?(0,r.jsx)("pre",{className:"tm-stdout",children:g.stdout}):null,g.stderr.length>0?(0,r.jsx)("pre",{className:"tm-stderr",children:g.stderr}):null]}):null,R?(0,r.jsx)("div",{role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":"false","aria-label":"Recent container run events",children:(0,r.jsx)("ul",{className:"tm-events",children:x.map((e,t)=>{var n;let l;return(0,r.jsxs)("li",{className:"tm-event",children:[(0,r.jsx)("span",{className:"tm-event-kind",children:function(e){switch(e){case"run-started":return"started";case"run-completed":return"completed";case"run-failed":return"failed";case"run-cancelled":return"cancelled";}}(e.kind)}),(0,r.jsx)("span",{className:"tm-event-detail",children:(l=(n=e).payload,"run-completed"===n.kind||"run-failed"===n.kind?["string"==typeof l.failureReason?l.failureReason:"","number"==typeof l.durationMs?`${String(l.durationMs)}ms`:""].filter(Boolean).join(" \xb7 "):"")})]},`${e.runId}-${String(t)}-${e.kind}`);})})}):null]});}function u0(e){return e instanceof m.hD?{code:e.code,message:e.message}:e instanceof Error?{code:"INTERNAL",message:e.message}:{code:"INTERNAL",message:"Unexpected error."};}function u1(e){return("dry-run"===e.status||"fix-proposed"===e.status)&&void 0!==e.proposedDiff&&void 0===e.appliedAt;}function u2(e){return void 0!==e.proposedDiff&&""!==e.proposedDiff;}function u4(e){let{href:t,hasManifest:n,error:l}=e;return n?(0,r.jsx)("a",{className:"rv-evidence-link",href:t,target:"_blank",rel:"noopener noreferrer",children:"Evidence"}):null!==l?(0,r.jsxs)("span",{className:"rv-evidence-link rv-evidence-error",role:"alert",children:["Evidence error: ",l.message]}):(0,r.jsx)("button",{type:"button",className:"rv-evidence-link rv-evidence-disabled",disabled:!0,children:"Evidence"});}function u3(e){var t,n;let{runId:l,onRunIdSubmit:a}=e,[s,o]=(0,i.useState)(null),[c,d]=(0,i.useState)(!1),[u,p]=(0,i.useState)(null),[h,f]=(0,i.useState)(!1),[g,v]=(0,i.useState)(null),[b,y]=(0,i.useState)(!1),[x,w]=(0,i.useState)(null),[j,k]=(0,i.useState)(null),[N,S]=(0,i.useState)(""),[C,R]=(0,i.useState)(!1),I=(0,i.useRef)(null);(0,i.useEffect)(()=>()=>{null!==I.current&&window.clearTimeout(I.current);},[]),(0,i.useEffect)(()=>{if(void 0===l||""===l)return;let e=!1;return f(!0),v(null),o(null),d(!1),p(null),k(null),Promise.allSettled([(0,m.Qe)(l),(0,m.tZ)(l)]).then(t=>{let[n,l]=t;if(!e){if("fulfilled"===l.status)d(!0),p(null);else{let e=u0(l.reason);d(!1),p("NOT_FOUND"===e.code?null:e);}if("fulfilled"===n.status){o(n.value.report),f(!1);return;}v(u0(n.reason)),f(!1);}}),()=>{e=!0;};},[l]);let E=`/api/evidence/${encodeURIComponent(null!=l?l:"")}`,$=(0,i.useMemo)(()=>(null==s?void 0:s.proposedDiff)!==void 0?uA(s.proposedDiff):null,[null==s?void 0:s.proposedDiff]),A=null!=(t=null==s?void 0:s.changedFiles)?t:[],T=(0,i.useMemo)(()=>{var e,t;return{added:null!=(e=null==$?void 0:$.files.reduce((e,t)=>e+t.addedLines,0))?e:0,removed:null!=(t=null==$?void 0:$.files.reduce((e,t)=>e+t.removedLines,0))?t:0};},[$]),F=null!==$&&$.files.length>0?Math.min(null!=j?j:0,$.files.length-1):null,D=null!==F?null==$?void 0:$.files[F]:void 0,M=(null==s?void 0:s.status)==="running";return void 0===l||""===l?(0,r.jsxs)("section",{className:"review rv-empty","aria-label":"Diff review",children:[(0,r.jsx)("h2",{className:"rv-empty-h",children:"Review"}),void 0!==a?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("p",{className:"rv-empty-p",children:"Paste a run ID below to load a proposed diff."}),(0,r.jsxs)("form",{className:"rv-empty-form",onSubmit:e=>{e.preventDefault();let t=N.trim();0!==t.length&&a(t);},children:[(0,r.jsx)("label",{className:"rv-empty-label",htmlFor:"rv-runid-input",children:"Run ID"}),(0,r.jsx)("input",{id:"rv-runid-input",className:"rv-runid-input mono",type:"text",value:N,onChange:e=>S(e.target.value),placeholder:"e.g. 7f3a9c12…"}),(0,r.jsx)("button",{type:"submit",className:"arun-btn",children:"Load run"})]})]}):(0,r.jsx)("p",{className:"rv-empty-p",children:"Enter a run ID in the window configuration to load a proposed diff."})]}):(0,r.jsxs)("section",{className:"review","aria-label":"Diff review",children:[h&&(0,r.jsxs)("div",{className:"rv-loading",role:"status","aria-busy":"true","aria-label":"Loading diff",children:[(0,r.jsx)("div",{className:"rv-skel"}),(0,r.jsx)("div",{className:"rv-skel rv-skel-sm"})]}),!h&&null!==g&&(0,r.jsxs)("div",{role:"alert",className:"rv-error",children:["NOT_FOUND"===g.code?"No run with that ID was found.":(0,r.jsxs)(r.Fragment,{children:[g.message," ",(0,r.jsxs)("span",{className:"err-code mono",children:["(",g.code,")"]})]}),(c||null!==u)&&(0,r.jsx)("span",{className:"rv-error-evidence",children:(0,r.jsx)(u4,{href:E,hasManifest:c,error:u})})]}),(0,r.jsx)("p",{role:"status","aria-live":"polite",className:!h&&null===g&&null!==s&&M?"rv-no-diff":"sr-only",children:!h&&null===g&&null!==s&&M?"Run is still running. The proposed diff will appear when the run completes.":""}),!h&&null===g&&null!==s&&!M&&!u2(s)&&(0,r.jsx)("p",{className:"rv-no-diff",children:"This run has no proposed diff to review."}),!h&&null===g&&null!==s&&u2(s)&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"rv-header",children:[(0,r.jsx)("span",{className:"rv-status mono",children:(0,aQ.az)(s.status)}),void 0!==s.modelId&&(0,r.jsx)("span",{className:"rv-model mono",children:s.modelId}),(0,r.jsxs)("span",{className:"rv-counts mono",children:[null!==$&&`${$.files.length} file${1!==$.files.length?"s":""}`," ",(0,r.jsxs)("span",{className:"rv-stat add",children:["+",T.added]})," ",(0,r.jsxs)("span",{className:"rv-stat del",children:["−",T.removed]})]}),(0,r.jsx)("span",{className:"spacer"}),(0,r.jsx)(u4,{href:E,hasManifest:c,error:u})]}),null!==$&&$.files.length>0&&null!==F&&void 0!==D&&(0,r.jsxs)("div",{className:"rv-layout",children:[(0,r.jsx)("nav",{className:"rv-filelist","aria-label":"Changed files",children:(0,r.jsx)("ul",{children:$.files.map((e,t)=>{let n=A.find(t=>t.path===e.path),l=F===t;return(0,r.jsx)("li",{children:(0,r.jsxs)("button",{type:"button",className:"rv-filerow",title:e.path,"aria-pressed":l,"aria-controls":l?`rv-file-${t}`:void 0,onClick:()=>{k(t);},children:[(0,r.jsx)("span",{className:"rv-filerow-path mono",children:function(e){if(e.length<=40)return e;let t=e.split("/");return t.length<=2?e:`…/${t.slice(-2).join("/")}`;}(e.path)}),(0,r.jsxs)("span",{className:"rv-stat add",children:["+",e.addedLines]}),(0,r.jsxs)("span",{className:"rv-stat del",children:["−",e.removedLines]}),(null==n?void 0:n.elevatedReview)===!0&&(0,r.jsx)("span",{className:"rv-elevated","aria-label":"Elevated review",children:"!"})]})},e.path);})})}),(0,r.jsxs)("div",{className:"rv-body",children:[(0,r.jsx)(uM,{file:D,index:F,changedFiles:A,sectionRef:()=>void 0},D.path),$.truncated&&(0,r.jsxs)("p",{role:"note",className:"rv-truncated",children:["Diff truncated at 512 KB. Open the"," ",c?(0,r.jsx)("a",{href:E,target:"_blank",rel:"noopener noreferrer",children:"evidence manifest"}):"evidence manifest"," ","for the full record."]})]})]}),(0,r.jsxs)("div",{className:"rv-controls",children:[(0,r.jsx)("span",{role:"status","aria-live":"polite",className:"rv-apply-status",children:b?"Applying…":void 0!==s.appliedAt?"Applied":""}),null!==x&&(0,r.jsx)("span",{role:"alert",className:"rv-apply-error",children:x.message}),void 0!==s.appliedAt?(0,r.jsx)("span",{className:"rv-final mono",children:"Applied"}):u1(s)?(0,r.jsx)("button",{type:"button",className:"arun-btn","aria-disabled":b,onClick:()=>{if(!b){if(!C){R(!0),null!==I.current&&window.clearTimeout(I.current),I.current=window.setTimeout(()=>{R(!1),I.current=null;},6e3);return;}null!==I.current&&(window.clearTimeout(I.current),I.current=null),R(!1),void 0!==l&&null!==s&&u1(s)&&!b&&(y(!0),w(null),(0,m.qU)(l).then(e=>{o(e.report),y(!1);}).catch(e=>{w(u0(e)),y(!1);}));}},children:b?"Applying…":C?`Confirm apply (${(null!=(n=null==$?void 0:$.files.length)?n:0).toString()} file${(null==$?void 0:$.files.length)===1?"":"s"})`:"Apply"}):null]})]})]});}let u6=new Set(["completed","dry-run","rejected","cancelled","failed","fix-applied","fix-proposed","investigation-only"]),u5={verify:"Verify","explain-plan":"Explain plan","unit-test-generation":"Generate unit tests","bug-investigation":"Investigate bug"};function u8(e,t){return void 0===t||0===t.length?null:(0,r.jsxs)("div",{className:"arun-result-card",children:[(0,r.jsx)("div",{className:"arun-result-title",children:e}),(0,r.jsx)("pre",{children:t})]});}let u9={high:"High",medium:"Medium",low:"Low — verify"};function u7(e){let{level:t}=e;return(0,r.jsxs)("div",{className:"arun-kv",children:[(0,r.jsx)("span",{children:"Confidence"}),(0,r.jsxs)("span",{className:"ai-conf","data-level":t,children:[(0,r.jsxs)("span",{className:"track","aria-hidden":"true",children:[(0,r.jsx)("i",{}),(0,r.jsx)("i",{}),(0,r.jsx)("i",{})]}),(0,r.jsx)("span",{className:"lbl",children:u9[t]})]})]});}function pe(e){var t,n,l,a,s,o,c,d,u,p,h;let f,{cfg:g={},linkedRoot:v=null,linkedFilePath:b}=e,y=null!=(t=g.runId)?t:null,x="verify"===(p=g.workflow)||"explain-plan"===p||"unit-test-generation"===p||"bug-investigation"===p?p:null,w=null!=(n=g.model)?n:"",j=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{return null;}}(g.inputJson),k=function(e){let[t,n]=(0,i.useState)([]),[l,a]=(0,i.useState)("connecting"),[r,s]=(0,i.useState)(null),o=(0,i.useRef)(-1);return(0,i.useEffect)(()=>{if(null===e)return;n([]),a("connecting"),s(null),o.current=-1;let t=null,l=!1,r=`/api/runs/${encodeURIComponent(e)}/events`;(t=new EventSource(o.current>=0?`${r}?lastEventId=${o.current.toString()}`:r)).onopen=()=>{l||(a("live"),s(null));},t.onerror=()=>{l||(a("error"),s("Stream disconnected. Attempting to reconnect…"));};let i=e=>{let r;if(!l){try{r=JSON.parse(e.data);}catch{return;}o.current=r.seq,n(e=>[...e,r]),lO.eQ.has(r.type)&&(a("terminal"),null==t||t.close());}};for(let e of lO.$Q)t.addEventListener(e,i);return()=>{l=!0,null==t||t.close();};},[e]),{events:t,status:l,error:r};}(y),[N,S]=(0,i.useState)(null),[C,R]=(0,i.useState)(null),[I,E]=(0,i.useState)(null),[A,T]=(0,i.useState)(!1),[F,D]=(0,i.useState)(null),[M,P]=(0,i.useState)(null),[L,q]=(0,i.useState)(!1),z=(0,i.useRef)(null),O=(0,i.useRef)(null),B=(0,i.useCallback)(async()=>{if(null!==y){E(null);try{let e=await(0,m.Qe)(y);S(e.report),R(null);}catch(e){if(e instanceof m.hD&&404===e.status){try{let e=await(0,m.tZ)(y);R(e.manifest),S(null);}catch(e){E(e instanceof Error?e.message:"Unable to load evidence.");}return;}E(e instanceof Error?e.message:"Unable to load run report.");}}},[y]);(0,i.useEffect)(()=>{B();},[B]),(0,i.useEffect)(()=>{"terminal"===k.status&&B();},[B,k.status]),(0,i.useEffect)(()=>{let e=!1;if(0!==w.length)return(0,m.ZC)().then(t=>{var n,l;e||P(null!=(n=null==(l=t.models.find(e=>e.id===w))?void 0:l.costClass)?n:null);}).catch(()=>{e||P(null);}),()=>{e=!0;};},[w]);let W=(0,i.useMemo)(()=>function(e,t){var n,l,a,r,i,s;let o=null!=(n=null==t||null==(r=t.usage)?void 0:r.promptTokens)?n:0,c=null!=(l=null==t||null==(i=t.usage)?void 0:i.completionTokens)?l:0,d=null!=(a=null==t||null==(s=t.usage)?void 0:s.latencyMs)?a: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,l=e.latencyMs;return"number"==typeof t&&"number"==typeof n&&"number"==typeof l?{promptTokens:t,completionTokens:n,latencyMs:l,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};}(k.events,N),[k.events,N]),K=null!=(l=null!=(a=null==N?void 0:N.durationMs)?a:null==C?void 0:C.run.durationMs)?l:k.events.length>0?Math.max(0,Date.now()-Number(new Date(null!=(s=null==(d=k.events[0])?void 0:d.ts)?s:Date.now()))):0,U=null!==N?N.status:null!==C?C.run.outcome:"loading",V=null!==N?(0,aQ.az)(N.status):null!==C?(0,aQ.FR)(C.run.outcome):"Loading…",H=null!==N&&u6.has(N.status),_=null!==N&&void 0!==N.proposedDiff&&void 0===N.appliedAt&&("unit-test-generation"===x&&"dry-run"===N.status||"bug-investigation"===x&&"fix-proposed"===N.status),G=!H&&(null==N?void 0:N.status)==="running",J=function(e){if(void 0===e||0===e.length)return 0;let t=e.match(/^diff --git /gm);if(null!==t)return t.length;let n=e.match(/^\+\+\+ /gm);return null===n?0:n.length;}(null==N?void 0:N.proposedDiff),Y=A||"connecting"===k.status||(null==N?void 0:N.status)==="running"||null===N&&null===C&&null===I,X=(0,i.useRef)(!1);(0,i.useEffect)(()=>{if(X.current&&!G&&document.activeElement===document.body){var e;null==(e=O.current)||e.focus();}X.current=G;},[G]),(0,i.useEffect)(()=>()=>{null!==z.current&&window.clearTimeout(z.current);},[]);let Z=async()=>{if(null!==y){E(null);try{await(0,m.Su)(y),await B();}catch(e){E(e instanceof Error?e.message:"Unable to cancel run.");}}},Q=async()=>{if(null!==y&&_&&!A){T(!0),D(null);try{let e=await(0,m.qU)(y);S(e.report);}catch(e){D(e instanceof Error?e.message:"Unable to apply run.");}finally{T(!1);}}};return null===y||null===x?(0,r.jsxs)("div",{className:"arun arun-empty",children:[(0,r.jsx)("div",{className:"arun-result-title",children:"Agent run is not configured."}),(0,r.jsx)("p",{children:"Open a new Agent window from the launcher to start a workflow."})]}):(0,r.jsxs)("div",{className:"arun arun-real","aria-busy":Y?"true":void 0,children:[(0,r.jsxs)("div",{className:"arun-head",children:[(0,r.jsx)("span",{className:"arun-role",children:u5[x]}),w.length>0?(0,r.jsx)("span",{className:"ag-model mono",children:w}):null,null!==M?(0,r.jsx)("span",{className:"arun-gov",title:"Model cost class",children:(0,aQ.Kb)(M)}):null,(0,r.jsx)("span",{className:"spacer"}),(0,r.jsxs)("span",{className:"arun-status",children:[(0,r.jsx)("span",{className:"dot","data-live":(null==N?void 0:N.status)==="running","data-status":U}),V]})]}),(0,r.jsxs)("div",{className:"arun-summary",role:"status","aria-live":"polite",children:[(0,r.jsx)("strong",{children:function(e,t,n){var l,a;if(null===t&&null===n)return"Loading run state…";let r=null===e?"Agent run":u5[e];return(null==t?void 0:t.status)==="running"?`${r} is running.`:(null==t?void 0:t.status)==="dry-run"?`${r} produced a reviewable dry-run.`:(null==t?void 0:t.status)==="fix-proposed"?`${r} proposed a fix.`:(null==t?void 0:t.status)==="fix-applied"?`${r} applied changes.`:(null==t?void 0:t.status)==="investigation-only"?`${r} completed without a patch.`:(null==t?void 0:t.status)==="failed"||(null==t?void 0:t.status)==="rejected"?`${r} failed.`:(null==t?void 0:t.status)==="cancelled"?`${r} was cancelled.`:null!==t?`${r} completed.`:(null==n||null==(a=n.patch)?void 0:a.redactedDiff)!==void 0?`${r} evidence loaded with a reviewable diff.`:`${r} evidence loaded: ${null!=(l=null==n?void 0:n.run.outcome)?l:"unknown"}.`;}(x,N,C)}),(0,r.jsxs)("span",{className:"mono",title:y,children:["run ",y.slice(0,8)]})]}),(0,r.jsxs)("div",{className:"arun-meters",children:[(0,r.jsxs)("div",{className:"arun-meter",children:[(0,r.jsx)("span",{className:"arun-mk",children:"Elapsed"}),(0,r.jsx)("span",{className:"arun-mv mono",children:(0,aQ._V)(K)})]}),(0,r.jsxs)("div",{className:"arun-meter",children:[(0,r.jsx)("span",{className:"arun-mk",children:"Usage"}),(0,r.jsx)("span",{className:"arun-mv mono",children:0===W.requestCount?"No model usage":`${(0,aQ._y)(W.promptTokens+W.completionTokens)} tok`})]}),(0,r.jsxs)("div",{className:"arun-meter",children:[(0,r.jsx)("span",{className:"arun-mk",children:"Latency"}),(0,r.jsx)("span",{className:"arun-mv mono",children:0===W.requestCount?"—":(0,aQ._V)(W.latencyMs)})]})]}),(0,r.jsxs)("div",{className:"arun-perms",children:[(0,r.jsxs)("span",{className:"arun-perm","data-on":null!==v,title:null!==v?v:null!=(o=g.workspaceRoot)?o:void 0,children:[(0,r.jsx)($.F.files,{size:11}),(0,r.jsx)("span",{className:"arun-perm-path",children:null!==v?v:null!=(c=g.workspaceRoot)?c:"no workspace"})]}),void 0!==b?(0,r.jsxs)("span",{className:"arun-perm","data-on":!0,title:b,children:[(0,r.jsx)($.F.files,{size:11}),(0,r.jsx)("span",{className:"arun-perm-path",children:b})]}):null]}),null!==j?(0,r.jsxs)("details",{className:"arun-input",children:[(0,r.jsx)("summary",{children:"Run input"}),(0,r.jsx)("pre",{children:JSON.stringify(j,null,2)})]}):null,(0,r.jsxs)("div",{className:"arun-log",role:"log","aria-live":"polite","aria-label":"Run events","aria-busy":Y?"true":void 0,children:["error"===k.status&&null!==k.error?(0,r.jsxs)("div",{className:"arun-log-row",children:[(0,r.jsx)("span",{className:"arun-log-ico",children:(0,r.jsx)($.F.reset,{size:12})}),(0,r.jsx)("span",{className:"arun-log-text",children:k.error})]}):null,0===k.events.length?"error"===k.status?null:(0,r.jsxs)("div",{className:"arun-log-row",children:[(0,r.jsx)("span",{className:"arun-log-ico",children:(0,r.jsx)($.F.reset,{size:12})}),(0,r.jsx)("span",{className:"arun-log-text",children:"connecting"===k.status?"Connecting to run events…":"Waiting for run events…"})]}):k.events.slice().reverse().slice(0,50).map(e=>{let t;return(0,r.jsxs)("div",{className:"arun-log-row",children:[(0,r.jsx)("span",{className:"arun-log-ico",children:(0,r.jsx)($.F.spark,{size:12})}),(0,r.jsx)("span",{className:"arun-log-text",children:function(e){switch(e.type){case"ready":return"SSE stream ready";case"run:started":return`Started ${e.taskType}`;case"run:completed":return"Run completed";case"run:failed":return`Run failed: ${e.failure.message}`;case"run:cancelled":return"Run cancelled";case"state:transition":return`${e.from} -> ${e.to}${void 0===e.reason?"":`: ${e.reason}`}`;case"model:call:started":return`Model call started (${(0,aQ.z3)(e.contextBytes)})`;case"model:call:completed":return`Model call completed (${(0,aQ._y)(e.usage.promptTokens+e.usage.completionTokens)} tokens)`;case"model:call:failed":return`Model call failed: ${e.message}`;case"patch:proposed":return`Patch proposed (${(0,aQ.z3)(e.patchBytes)})`;case"verification:result":return`Verification ${e.passed?"passed":"failed"}: ${e.detail}`;case"workflow:started":return"Unit-test workflow started";case"workflow:model:call:completed":return`Unit-test model call completed (${(0,aQ._y)(e.promptTokens+e.completionTokens)} tokens)`;case"workflow:verification:result":return`Unit-test verification ${e.overallStatus}`;case"workflow:completed":return`Unit-test workflow ${e.status}`;case"workflow:failed":return`Unit-test workflow failed: ${e.message}`;case"bug:started":return"Bug investigation started";case"bug:model:call:completed":return`Bug model call completed (${(0,aQ._y)(e.promptTokens+e.completionTokens)} tokens)`;case"bug:rootcause:proposed":return`Root cause proposed${e.hasPatch?" with patch":""}`;case"bug:verification:result":return`Bug verification ${e.overallStatus}`;case"bug:completed":return`Bug investigation ${e.status}`;case"bug:failed":return`Bug investigation failed: ${e.message}`;default:return e.type;}}(e)}),(0,r.jsx)("span",{className:"arun-log-t mono",children:Number.isFinite(t="number"==typeof e.ts?e.ts:Date.parse(e.ts))?new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}):""})]},`${e.runId}:${e.seq}:${e.type}`);})]}),null!==N?(0,r.jsxs)("div",{className:"arun-results",children:[void 0===N.report?null:(0,r.jsxs)("div",{className:"arun-result-card",children:[(0,r.jsx)("div",{className:"arun-result-title",children:"Report"}),(0,r.jsx)("pre",{children:N.report})]}),void 0===N.overallStatus||void 0===N.results?null:(0,r.jsxs)("div",{className:"arun-result-card",children:[(0,r.jsx)("div",{className:"arun-result-title",children:"Verification"}),(0,r.jsxs)("div",{className:"arun-kv",children:[(0,r.jsx)("span",{children:"Status"}),(0,r.jsx)("strong",{children:N.overallStatus})]}),N.results.slice(0,8).map(e=>(0,r.jsxs)("div",{className:"arun-check-row",children:[(0,r.jsx)("span",{children:e.kind}),(0,r.jsx)("span",{className:"mono",children:e.status})]},`${e.kind}:${e.command}`))]}),u8("Failure",N.failureReason),u8("Covered behavior",N.coveredBehavior),u8("Known gaps",N.knownGaps),u8("Verification note",N.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]].filter(e=>"string"==typeof e[1]&&e[1].length>0),l="string"==typeof t.confidence?t.confidence:"",a="low"===l||"medium"===l||"high"===l?l:void 0,i=l.length>0&&void 0===a?l:void 0;return 0===n.length&&void 0===a&&void 0===i?null:(0,r.jsxs)("div",{className:"arun-result-card",children:[(0,r.jsx)("div",{className:"arun-result-title",children:"Hypothesis"}),n.map(e=>{let[t,n]=e;return(0,r.jsxs)("div",{className:"arun-kv",children:[(0,r.jsx)("span",{children:t}),(0,r.jsx)("strong",{children:n})]},t);}),void 0!==i?(0,r.jsxs)("div",{className:"arun-kv",children:[(0,r.jsx)("span",{children:"Confidence"}),(0,r.jsx)("strong",{children:i})]}):null,void 0!==a?(0,r.jsx)(u7,{level:a}):null]});}(N),void 0===(h=N.nextActions)||0===h.length?null:(0,r.jsxs)("div",{className:"arun-result-card",children:[(0,r.jsx)("div",{className:"arun-result-title",children:"Next actions"}),h.map(e=>(0,r.jsx)("div",{className:"arun-check-row",children:(0,r.jsx)("span",{children:e})},e))]}),void 0!==N.dryRunPreview?(0,r.jsxs)("div",{className:"arun-result-card",children:[(0,r.jsx)("div",{className:"arun-result-title",children:"Dry-run preview"}),(0,r.jsx)("pre",{children:N.dryRunPreview})]}):null,void 0!==N.proposedDiff?(0,r.jsxs)("div",{className:"arun-result-card",children:[(0,r.jsx)("div",{className:"arun-result-title",children:"Proposed diff"}),(0,r.jsx)("pre",{children:N.proposedDiff})]}):null,void 0===(f=N.verificationSummary)?null:(0,r.jsxs)("div",{className:"arun-result-card",children:[(0,r.jsx)("div",{className:"arun-result-title",children:"Verification"}),(0,r.jsxs)("div",{className:"arun-kv",children:[(0,r.jsx)("span",{children:"Status"}),(0,r.jsx)("strong",{children:f.overallStatus})]}),(0,r.jsxs)("div",{className:"arun-kv",children:[(0,r.jsx)("span",{children:"Duration"}),(0,r.jsx)("strong",{children:(0,aQ._V)(f.durationMs)})]}),f.results.slice(0,5).map(e=>(0,r.jsxs)("div",{className:"arun-check-row",children:[(0,r.jsx)("span",{children:e.kind}),(0,r.jsx)("span",{className:"mono",children:e.status})]},`${e.kind}:${e.command}`))]}),void 0!==N.applyReport?(0,r.jsxs)("div",{className:"arun-result-card arun-applied",children:[(0,r.jsx)("div",{className:"arun-result-title",children:"Applied"}),(0,r.jsx)("pre",{children:JSON.stringify(N.applyReport,null,2)})]}):null]}):null!==C?(0,r.jsxs)("div",{className:"arun-results",children:[(0,r.jsxs)("div",{className:"arun-result-card",children:[(0,r.jsx)("div",{className:"arun-result-title",children:"Evidence"}),(0,r.jsxs)("div",{className:"arun-kv",children:[(0,r.jsx)("span",{children:"Outcome"}),(0,r.jsx)("strong",{children:C.run.outcome})]}),(0,r.jsxs)("div",{className:"arun-kv",children:[(0,r.jsx)("span",{children:"Duration"}),(0,r.jsx)("strong",{children:(0,aQ._V)(C.run.durationMs)})]}),void 0!==C.patch?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"arun-kv",children:[(0,r.jsx)("span",{children:"Changed files"}),(0,r.jsx)("strong",{children:C.patch.changedFiles.toString()})]}),(0,r.jsxs)("div",{className:"arun-kv",children:[(0,r.jsx)("span",{children:"Patch size"}),(0,r.jsx)("strong",{children:(0,aQ.z3)(C.patch.patchBytes)})]})]}):null]}),(null==(u=C.patch)?void 0:u.redactedDiff)!==void 0?(0,r.jsxs)("div",{className:"arun-result-card",children:[(0,r.jsx)("div",{className:"arun-result-title",children:"Proposed diff"}),(0,r.jsx)("pre",{children:C.patch.redactedDiff})]}):null]}):null,null!==I?(0,r.jsx)("div",{className:"arun-error",role:"alert",children:I}):null,null!==F?(0,r.jsx)("div",{className:"arun-error",role:"alert",children:F}):null,(0,r.jsxs)("div",{className:"arun-controls",children:[(0,r.jsx)("a",{className:"arun-btn ghost",href:`/api/evidence/${encodeURIComponent(y)}`,target:"_blank",rel:"noreferrer",ref:O,children:"Evidence"}),_?(0,r.jsx)("button",{type:"button",className:"arun-btn","aria-disabled":A,onClick:()=>{if(!A){if(!L){q(!0),null!==z.current&&window.clearTimeout(z.current),z.current=window.setTimeout(()=>{q(!1),z.current=null;},6e3);return;}null!==z.current&&(window.clearTimeout(z.current),z.current=null),q(!1),Q();}},children:A?"Applying…":L?`Confirm apply (${J.toString()} file${1===J?"":"s"})`:"Apply"}):(null==N?void 0:N.appliedAt)!==void 0?(0,r.jsx)("span",{className:"arun-final mono",children:"Applied"}):null,G?(0,r.jsx)("button",{type:"button",className:"arun-btn danger",onClick:()=>void Z(),children:"Cancel"}):null]})]});}let pt=[{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 pn(){return(0,r.jsx)("ul",{className:"integ","aria-label":"Integrations",children:pt.map(e=>(0,r.jsxs)("li",{className:"integ-row",children:[(0,r.jsx)("span",{className:"integ-glyph mono",children:e.glyph}),(0,r.jsxs)("span",{className:"integ-text",children:[(0,r.jsx)("span",{className:"integ-name",children:e.name}),(0,r.jsx)("span",{className:"integ-desc",children:e.desc})]}),(0,r.jsx)("span",{className:"integ-status",children:"Not connected — coming soon"})]},e.name))});}let pl={allow:["Allow","var(--accent)"],ask:["Ask","var(--warn)"],deny:["Deny","var(--danger)"]},pa={allow:"ask",ask:"deny",deny:"allow"},pr=[{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"}],pi=[["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"]],ps=[["calendar","Calendar","automations"],["mail","Mail","bell"],["jira","Jira","review"],["docs","Docs","files"]];function po(e){let{policy:t,setPolicy:n}=e;return(0,r.jsxs)("div",{className:"pol",children:[(0,r.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=pl[e.decision];return(0,r.jsxs)("div",{className:"pol-row",children:[(0,r.jsxs)("div",{className:"pol-text",children:[(0,r.jsx)("span",{className:"pol-action",children:e.action}),(0,r.jsx)("span",{className:"pol-scope mono",children:e.scope})]}),(0,r.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:pa[e.decision]}:e));},children:t[0]})]},e.id);})]});}function pc(e){let{decide:t}=e,[n,l]=(0,i.useState)(!1),a=pr.map(e=>{let n=t(e.kind,e.risk);return{...e,actual:n,pass:n===e.expect};}),s=a.filter(e=>e.pass).length;return(0,r.jsxs)("div",{className:"evl",children:[(0,r.jsxs)("div",{className:"evl-head",children:[(0,r.jsxs)("button",{type:"button",className:"evl-run",onClick:()=>l(!0),children:[(0,r.jsx)($.F.spark,{size:13})," Run evaluation"]}),n&&(0,r.jsxs)("span",{className:"evl-score"+(s===a.length?" ok":""),children:[s,"/",a.length," passed"]})]}),(0,r.jsx)("div",{className:"evl-hint",children:"Mock scenarios against your policy before going autonomous."}),a.map(e=>(0,r.jsxs)("div",{className:"evl-row","data-state":n?e.pass?"pass":"fail":"idle",children:[(0,r.jsx)("span",{className:"evl-ico",children:n?e.pass?(0,r.jsx)($.F.check,{size:13}):(0,r.jsx)($.F.close,{size:13}):(0,r.jsx)("span",{className:"evl-dot"})}),(0,r.jsx)("span",{className:"evl-label",children:e.label}),n&&(0,r.jsx)("span",{className:"evl-res mono",style:{color:pl[e.actual][1]},children:pl[e.actual][0]})]},e.id))]});}function pd(e){let{bridges:t,setBridges:n}=e;return(0,r.jsxs)("div",{className:"brg",children:[(0,r.jsx)("div",{className:"evl-hint",children:"What your twin can reach on your behalf."}),ps.map(e=>{let[l,a,i]=e,s=$.F[i],o=t[l];return(0,r.jsxs)("button",{type:"button",className:"brg-row","data-on":o,"aria-pressed":o,onClick:()=>n(e=>({...e,[l]:!e[l]})),children:[(0,r.jsx)("span",{className:"brg-ico",children:(0,r.jsx)(s,{size:16})}),(0,r.jsx)("span",{className:"brg-name",children:a}),(0,r.jsx)("span",{className:"brg-tg"+(o?" on":""),children:(0,r.jsx)("span",{})})]},l);})]});}function pu(e){let{persona:t,setPersona:n}=e;return(0,r.jsxs)("div",{className:"prs",children:[(0,r.jsx)("div",{className:"evl-hint",children:"Keiko adapts behaviour & tools to who is at the wheel."}),pi.map(e=>{let[l,a]=e;return(0,r.jsxs)("button",{type:"button",className:"prs-row","data-on":t===l,"aria-pressed":t===l,onClick:()=>n(l),children:[(0,r.jsx)("span",{className:"prs-dot"}),(0,r.jsxs)("span",{className:"prs-text",children:[(0,r.jsx)("span",{className:"prs-name",children:l}),(0,r.jsx)("span",{className:"prs-desc",children:a})]}),t===l&&(0,r.jsx)($.F.check,{size:14,style:{color:"var(--accent)"}})]},l);})]});}let pp=[["policy","Policy"],["eval","EVAL"],["bridges","Connections"],["persona","Persona"]];function pm(){let e=J(),[t,n]=(0,i.useState)("policy");return(0,r.jsxs)("div",{className:"twin",children:[(0,r.jsxs)("div",{className:"twin-hero",children:[(0,r.jsx)("img",{className:"twin-orca",src:"/assets/keiko-logo.svg",alt:""}),(0,r.jsxs)("div",{className:"twin-id",children:[(0,r.jsx)("span",{className:"twin-name",children:"Keiko — Digital Twin"}),(0,r.jsxs)("span",{className:"twin-sub mono",children:["mirroring \xb7 ",e.persona]})]}),(0,r.jsx)("span",{className:"twin-mode "+("autonomous"===e.mode?"on":""),children:"autonomous"===e.mode?"Autonomous":"Manual"})]}),(0,r.jsx)("div",{className:"twin-tabs",children:pp.map(e=>{let[l,a]=e;return(0,r.jsx)("button",{type:"button",className:"twin-tab","data-on":t===l,onClick:()=>n(l),children:a},l);})}),(0,r.jsxs)("div",{className:"twin-body",children:["policy"===t&&(0,r.jsx)(po,{policy:e.policy,setPolicy:e.setPolicy}),"eval"===t&&(0,r.jsx)(pc,{decide:e.decide}),"bridges"===t&&(0,r.jsx)(pd,{bridges:e.bridges,setBridges:e.setBridges}),"persona"===t&&(0,r.jsx)(pu,{persona:e.persona,setPersona:e.setPersona})]})]});}let ph="keiko:gateway-setup-request",pf=!1;function pg(){pf=!0,window.dispatchEvent(new CustomEvent(ph));}function pv(){let e=pf;return pf=!1,e;}function pb(e,t){let n=(0,lO.iu)(e),l=[];n.speechToText&&l.push(t("settings.models.voiceCapabilitySpeechToText")),n.speechOutput&&l.push(t("settings.models.voiceCapabilitySpeechOutput")),n.realtimeVoice&&l.push(t("settings.models.voiceCapabilityRealtimeDialogue"));let a=l.length>0?l.join(", "):t("settings.models.voiceCapabilityVoice"),r=n.personas.length>0?t("settings.models.voicePersonas",{personas:n.personas.join(", ")}):"";return t("settings.models.voiceProviderAvailable",{capabilities:a,personas:r});}function py(e){let{model:t}=e,{t:n}=ea(),l=(0,lO.nP)(t);if((0,lO.gB)(t)){let e,l=pb(t,n);return(0,r.jsx)("span",{className:"ml-elig ml-elig-voice","data-testid":"voice-elig-ok",role:"status","aria-label":n("settings.models.eligibilityPrefix",{label:l}),title:l,children:n("settings.models.voiceProviderBadge",{label:n((e=(0,lO.iu)(t)).realtimeVoice?"settings.models.voiceCapabilityRealtimeDialogue":e.speechOutput?"settings.models.voiceCapabilitySpeechOutput":e.speechToText?"settings.models.voiceCapabilitySpeechToText":"settings.models.voiceCapabilityVoice")})});}if(void 0===l)return(0,r.jsx)("span",{className:"ml-elig ml-elig-ok","data-testid":"conv-elig-ok",role:"status","aria-label":n("settings.models.eligibilityOkAria"),children:n("settings.models.eligibilityOk")});if("embedding-only"===l){let e=n("settings.models.embeddingAvailable");return(0,r.jsx)("span",{className:"ml-elig ml-elig-embed","data-testid":"embedding-elig-ok",role:"status","aria-label":n("settings.models.eligibilityPrefix",{label:e}),title:e,children:n("settings.models.embeddingLabel")});}let a=n("embedding-only"===l?"settings.models.ineligibleEmbedding":"ocr-vision-only"===l?"settings.models.ineligibleOcr":"settings.models.ineligibleGeneric");return(0,r.jsx)("span",{className:"ml-elig ml-elig-no","data-testid":"conv-elig-no",role:"status","aria-label":n("settings.models.eligibilityPrefix",{label:a}),title:a,children:n("settings.models.notSelectable",{reason:n("ocr-vision-only"===l?"settings.models.ineligibleShortOcr":"settings.models.ineligibleShortGeneric")})});}async function px(e){var t;let n="u"<typeof navigator||null==(t=navigator.clipboard)?void 0:t.writeText;if(void 0!==n&&void 0!==navigator.clipboard)try{await n.call(navigator.clipboard,e);return;}catch{}if("u"<typeof document||null===document.body)throw Error("clipboard-unavailable");let l=document.activeElement instanceof HTMLElement?document.activeElement:null,a=document.createElement("textarea");a.value=e,a.setAttribute("readonly","true"),a.style.position="fixed",a.style.inset="0 auto auto -9999px",a.style.width="1px",a.style.height="1px",a.style.opacity="0",document.body.appendChild(a);try{if(a.focus(),a.select(),!("function"==typeof document.execCommand&&document.execCommand("copy")))throw Error("clipboard-fallback-failed");}finally{a.remove(),null==l||l.focus();}}function pw(e){let t=void 0===e.warning?"":` Warning: ${e.warning}`;return`- ${e.name}: ${e.status} (${e.latencyMs.toString()} ms) ${e.evidence}${t}`;}function pj(e,t){return e.probes.some(e=>e.name===t&&"passed"===e.status);}function pk(e){let{report:t}=e,{t:n}=ea(),[l,a]=(0,i.useState)("idle"),[s,o]=(0,i.useState)("");async function c(){try{var e;let l,r;await px((e=t,["Keiko Gateway Readiness Report",`Model: ${e.modelId}`,`Checked at: ${e.checkedAt}`,`Overall status: ${e.overallStatus}`,`Verified capabilities: ${l=e.verifiedCapabilities,r=[["streaming",l.streaming],["toolCalling",l.toolCalling],["structuredOutput",l.structuredOutput],["reasoningOutput",l.reasoningOutput],["imageInput",l.imageInput],["documentInput",l.documentInput]].map(e=>{let[t,n]=e;return`${t}=${!0===n?"yes":"no"}`;}),void 0!==l.testedContextTokens&&r.push(`testedContextTokens=${l.testedContextTokens.toString()}`),r.join(", ")}`,"","Probes:",...e.probes.map(pw),"","Raw JSON:",JSON.stringify(e,null,2)].join("\n"))),a("copied"),o(n("settings.models.reportCopied"));}catch{a("failed"),o(n("settings.models.reportCopyFailed"));}}return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("button",{type:"button",className:"ml-check secondary","data-copied":"copied"===l?"true":"false","data-failed":"failed"===l?"true":"false",onClick:()=>{c();},children:[(0,r.jsx)($.F.copy,{size:12,"aria-hidden":"true"}),"copied"===l?n("settings.models.copied"):n("settings.models.copyReport")]}),(0,r.jsx)("span",{className:"ml-url mono",role:"failed"===l?"alert":"status","aria-live":"polite",children:s})]});}function pN(e){var t;let n,{state:l}=e,{t:a}=ea();if(void 0===l||"idle"===l.status)return null;if("running"===l.status)return(0,r.jsx)("div",{className:"ml-readiness",role:"status",children:a("settings.models.checkingReadiness",{mode:a(l.deep?"settings.models.readinessModeDeep":"settings.models.readinessModeBasic")})});if("error"===l.status)return(0,r.jsx)("div",{className:"ml-readiness ml-readiness-error",role:"alert",children:l.message});let i=l.report,s=pj(i,"chat"),o=null!=(t=null==(n=i.probes.find(e=>"passed"!==e.status&&"skipped"!==e.status))?void 0:n.warning)?t:null==n?void 0:n.evidence;return(0,r.jsx)("div",{className:"ml-readiness",children:(0,r.jsx)("div",{className:"ml-rrow",children:(0,r.jsxs)("div",{className:"ml-rsummary",role:"failed"===i.overallStatus?"alert":"status",children:[(0,r.jsxs)("div",{className:"ml-rhead",children:[(0,r.jsx)("span",{className:"ml-rstatus "+i.overallStatus,children:a(s?"settings.models.workingToday":"settings.models.notVerified")}),(0,r.jsx)("span",{className:"ml-rtime mono",children:new Date(i.checkedAt).toLocaleTimeString()})]}),(0,r.jsxs)("div",{className:"ml-rbadges","aria-label":a("settings.models.verifiedCapabilities"),children:[pj(i,"streaming")?(0,r.jsx)("span",{children:a("settings.models.capabilityStreaming")}):null,pj(i,"tool_calling")?(0,r.jsx)("span",{children:a("settings.models.capabilityTools")}):null,pj(i,"json_schema")?(0,r.jsx)("span",{children:a("settings.models.capabilityJson")}):null,pj(i,"reasoning")?(0,r.jsx)("span",{children:a("settings.models.capabilityReasoning")}):null,pj(i,"image_input")?(0,r.jsx)("span",{children:a("settings.models.capabilityImage")}):null,pj(i,"document_input")?(0,r.jsx)("span",{children:a("settings.models.capabilityPdf")}):null,void 0!==i.verifiedCapabilities.testedContextTokens?(0,r.jsx)("span",{children:a("settings.models.contextTokensShort",{count:i.verifiedCapabilities.testedContextTokens.toLocaleString()})}):null]}),void 0!==o?(0,r.jsx)("div",{className:"ml-rwarn",children:o}):null]})})});}function pS(e){var t;let{model:n,readiness:l,onRunReadiness:a}=e,{t:i}=ea(),s=(0,lO.S_)(n),o="embedding"===n.kind,c=(0,lO.gB)(n),d=s?i("settings.models.statusConversationEligible"):o?i("settings.models.statusEmbedding"):c?pb(n,i):i("settings.models.statusNotSelectable"),u="voice"===n.kind?$.F.mic:$.F.cube;return(0,r.jsxs)("div",{className:"ml-row",children:[(0,r.jsx)("span",{className:"ml-ico",children:(0,r.jsx)(u,{size:16})}),(0,r.jsxs)("div",{className:"ml-info",children:[(0,r.jsxs)("div",{className:"ml-top",children:[(0,r.jsx)("span",{className:"ml-name",children:n.id}),(0,r.jsx)("span",{className:"ml-type mono",children:"ocr-vision"===(t=n.kind)?"OCR":t}),(0,r.jsx)(py,{model:n})]}),(0,r.jsx)("div",{className:"ml-url mono",children:i("settings.models.capabilitySummary",{tools:i(n.toolCalling?"settings.models.yes":"settings.models.no"),structured:i(n.structuredOutput?"settings.models.yes":"settings.models.no"),costClass:n.costClass,latencyClass:n.latencyClass})}),(0,r.jsx)(pN,{state:l})]}),s?(0,r.jsxs)("div",{className:"ml-actions",children:[(0,r.jsxs)("button",{type:"button",className:"ml-check",disabled:(null==l?void 0:l.status)==="running",onClick:()=>a(n.id,!1),children:[(0,r.jsx)($.F.activity,{size:13}),i("settings.models.runReadiness")]}),(0,r.jsx)("button",{type:"button",className:"ml-check secondary",disabled:(null==l?void 0:l.status)==="running",onClick:()=>a(n.id,!0),children:i("settings.models.deepProbes")}),(null==l?void 0:l.status)==="done"?(0,r.jsx)(pk,{report:l.report}):null]}):null,(0,r.jsx)("span",{className:"ml-status "+(s||o||c?"connected":"ineligible"),title:d,"aria-hidden":"true"})]});}function pC(e){let{voicePersonas:t}=e,{locale:n,setLocale:l,t:a}=ea(),s=(0,i.useMemo)(()=>t.length>0?t:iY.RX,[t]),[o,c]=(0,i.useState)(()=>{var e;return null!=(e=i8(s))?e:s[0];}),[d,u]=(0,i.useState)(e_),[p,m]=(0,i.useState)(eG),[h,f]=(0,i.useState)(eJ),[g,v]=(0,i.useState)(eY),[b,y]=(0,i.useState)(eQ),[x,w]=(0,i.useState)(eX),[j,k]=(0,i.useState)(eZ);(0,i.useEffect)(()=>{var e;c(null!=(e=i8(s))?e:s[0]);},[s]),(0,i.useEffect)(()=>{let e=()=>{var e;c(null!=(e=i8(s))?e:s[0]);},t=t=>{t.key===i3&&e();};return window.addEventListener(i6,e),window.addEventListener("storage",t),()=>{window.removeEventListener(i6,e),window.removeEventListener("storage",t);};},[s]);let N=[{options:s.map(e=>({value:e,label:sh[e]}))}];(0,i.useEffect)(()=>{try{window.localStorage.setItem(eT,d?"true":"false");}catch{}window.dispatchEvent(new CustomEvent(ez,{detail:d}));},[d]),(0,i.useEffect)(()=>{try{window.localStorage.setItem(eF,String(p));}catch{}window.dispatchEvent(new CustomEvent(eO,{detail:p}));},[p]),(0,i.useEffect)(()=>{try{window.localStorage.setItem(eD,String(h));}catch{}e0(h),window.dispatchEvent(new CustomEvent(eB,{detail:h}));},[h]),(0,i.useEffect)(()=>{try{window.localStorage.setItem(eM,String(g));}catch{}e1(g),window.dispatchEvent(new CustomEvent(eW,{detail:g}));},[g]),(0,i.useEffect)(()=>{try{window.localStorage.setItem(eq,String(b));}catch{}window.dispatchEvent(new CustomEvent(eV,{detail:b}));},[b]),(0,i.useEffect)(()=>{try{window.localStorage.setItem(eP,String(x));}catch{}e2(x),window.dispatchEvent(new CustomEvent(eK,{detail:x}));},[x]),(0,i.useEffect)(()=>{try{window.localStorage.setItem(eL,String(j));}catch{}e4(j),window.dispatchEvent(new CustomEvent(eU,{detail:j}));},[j]);let S={"--p":`${String(p)}%`},C={"--p":`${String(h)}%`},R={"--p":`${String(g)}%`},I={"--p":`${String(b)}%`},E={"--p":`${String(x)}%`},A={"--p":`${String(j)}%`},T="settings-language-help";return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"set-sec-h",children:(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"set-sec-t",children:a("settings.language.title")}),(0,r.jsx)("div",{className:"set-sec-d",children:a("settings.language.description")})]})}),(0,r.jsxs)("div",{className:"gpref",children:[(0,r.jsxs)("div",{className:"gpref-row",children:[(0,r.jsx)("span",{className:"gpref-label",children:a("settings.language.label")}),(0,r.jsx)(ln.A,{ariaLabel:a("settings.language.label"),ariaDescribedBy:T,attached:!1,leadingVisual:(0,r.jsx)($.F.browser,{size:15}),menuMinWidth:172,onValueChange:e=>{("en"===e||"de"===e)&&l(e);},sections:[{options:[{value:"en",label:"English"},{value:"de",label:"Deutsch"}]}],showMenuHeader:!1,triggerClassName:"settings-language-select",value:n})]}),(0,r.jsx)("div",{id:T,className:"gpref-help",children:a("settings.language.help")})]}),(0,r.jsx)("div",{className:"set-sec-h",children:(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"set-sec-t",children:a("settings.voice.title")}),(0,r.jsx)("div",{className:"set-sec-d",children:a("settings.voice.description")})]})}),(0,r.jsxs)("div",{className:"gpref",children:[(0,r.jsxs)("div",{className:"gpref-row",children:[(0,r.jsx)("span",{className:"gpref-label",children:a("settings.voice.label")}),(0,r.jsx)(ln.A,{ariaLabel:a("settings.voice.label"),ariaDescribedBy:"settings-voice-help",attached:!1,leadingVisual:(0,r.jsx)($.F.mic,{size:15}),menuMinWidth:172,onValueChange:e=>{s.includes(e)&&(c(e),i9(e));},sections:N,showMenuHeader:!1,triggerClassName:"settings-language-select",value:o})]}),(0,r.jsx)("div",{id:"settings-voice-help",className:"gpref-help",children:a(t.length>0?"settings.voice.help":"settings.voice.unavailable")})]}),(0,r.jsx)("div",{className:"set-sec-h",children:(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"set-sec-t",children:a("settings.wallpaper.title")}),(0,r.jsx)("div",{className:"set-sec-d",children:a("settings.wallpaper.description")})]})}),(0,r.jsxs)("div",{className:"gpref",children:[(0,r.jsxs)("div",{className:"gpref-row",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"gpref-label",children:a("settings.wallpaper.toggle")}),(0,r.jsx)("div",{className:"gpref-help",children:a(d?"settings.wallpaper.running":"settings.wallpaper.stopped")})]}),(0,r.jsx)(oL,{on:d,onChange:u,label:a("settings.wallpaper.toggle")})]}),(0,r.jsxs)("div",{className:"gpref-row",children:[(0,r.jsx)("label",{className:"gpref-label",htmlFor:"wp-op",children:a("settings.wallpaper.opacity")}),(0,r.jsxs)("span",{className:"gpref-val mono",children:[p,"%"]})]}),(0,r.jsx)("input",{id:"wp-op",className:"gpref-slider",type:"range",min:0,max:100,step:1,value:p,disabled:!d,onChange:e=>m(Number.parseInt(e.target.value,10)),style:S,"aria-label":a("settings.wallpaper.opacity")}),(0,r.jsxs)("div",{className:"gpref-scale",children:[(0,r.jsx)("span",{children:a("settings.scale.off")}),(0,r.jsx)("span",{children:a("settings.scale.full")})]})]}),(0,r.jsxs)("div",{className:"gpref",children:[(0,r.jsxs)("div",{className:"gpref-row",children:[(0,r.jsx)("label",{className:"gpref-label",htmlFor:"ws-bg-bright",children:a("settings.workspace.backgroundBrightness")}),(0,r.jsxs)("span",{className:"gpref-val mono",children:[h,"%"]})]}),(0,r.jsx)("input",{id:"ws-bg-bright",className:"gpref-slider",type:"range",min:0,max:100,step:1,value:h,onChange:e=>f(Number.parseInt(e.target.value,10)),style:C,"aria-label":a("settings.workspace.backgroundBrightness")}),(0,r.jsxs)("div",{className:"gpref-scale",children:[(0,r.jsx)("span",{children:a("settings.scale.base")}),(0,r.jsx)("span",{children:a("settings.scale.lighter")})]})]}),(0,r.jsxs)("div",{className:"gpref",children:[(0,r.jsxs)("div",{className:"gpref-row",children:[(0,r.jsx)("label",{className:"gpref-label",htmlFor:"ws-grid-strength",children:a("settings.workspace.gridStrength")}),(0,r.jsxs)("span",{className:"gpref-val mono",children:[g,"%"]})]}),(0,r.jsx)("input",{id:"ws-grid-strength",className:"gpref-slider",type:"range",min:0,max:100,step:1,value:g,onChange:e=>v(Number.parseInt(e.target.value,10)),style:R,"aria-label":a("settings.workspace.gridStrength")}),(0,r.jsxs)("div",{className:"gpref-scale",children:[(0,r.jsx)("span",{children:a("settings.scale.subtle")}),(0,r.jsx)("span",{children:a("settings.scale.strong")})]})]}),(0,r.jsxs)("div",{className:"gpref",children:[(0,r.jsxs)("div",{className:"gpref-row",children:[(0,r.jsx)("label",{className:"gpref-label",htmlFor:"ws-camera-smoothness",children:a("settings.workspace.cameraAnimation")}),(0,r.jsxs)("span",{className:"gpref-val mono",children:[b,"%"]})]}),(0,r.jsx)("input",{id:"ws-camera-smoothness",className:"gpref-slider",type:"range",min:0,max:100,step:1,value:b,onChange:e=>y(Number.parseInt(e.target.value,10)),style:I,"aria-label":a("settings.workspace.cameraAnimation")}),(0,r.jsxs)("div",{className:"gpref-scale",children:[(0,r.jsx)("span",{children:a("settings.workspace.cameraAnimationMinimal")}),(0,r.jsx)("span",{children:a("settings.workspace.cameraAnimationSmooth")})]}),(0,r.jsx)("div",{className:"gpref-help",children:a("settings.workspace.cameraAnimationHelp")})]}),(0,r.jsxs)("div",{className:"gpref",children:[(0,r.jsxs)("div",{className:"gpref-row",children:[(0,r.jsx)("label",{className:"gpref-label",htmlFor:"frame-border-strength",children:a("settings.workspace.borderStrength")}),(0,r.jsxs)("span",{className:"gpref-val mono",children:[x,"%"]})]}),(0,r.jsx)("input",{id:"frame-border-strength",className:"gpref-slider",type:"range",min:0,max:100,step:1,value:x,onChange:e=>w(Number.parseInt(e.target.value,10)),style:E,"aria-label":a("settings.workspace.borderStrength")}),(0,r.jsxs)("div",{className:"gpref-scale",children:[(0,r.jsx)("span",{children:a("settings.scale.subtle")}),(0,r.jsx)("span",{children:a("settings.scale.strong")})]})]}),(0,r.jsxs)("div",{className:"gpref",children:[(0,r.jsxs)("div",{className:"gpref-row",children:[(0,r.jsx)("label",{className:"gpref-label",htmlFor:"frame-inner-glow-strength",children:a("settings.workspace.innerGlow")}),(0,r.jsxs)("span",{className:"gpref-val mono",children:[j,"%"]})]}),(0,r.jsx)("input",{id:"frame-inner-glow-strength",className:"gpref-slider",type:"range",min:0,max:100,step:1,value:j,onChange:e=>k(Number.parseInt(e.target.value,10)),style:A,"aria-label":a("settings.workspace.innerGlow")}),(0,r.jsxs)("div",{className:"gpref-scale",children:[(0,r.jsx)("span",{children:a("settings.scale.off")}),(0,r.jsx)("span",{children:a("settings.scale.strong")})]})]})]});}function pR(){var e;let{t}=ea(),[n,l]=(0,i.useState)("models"),[a,s]=(0,i.useState)([]),[o,c]=(0,i.useState)(null),[d,u]=(0,i.useState)(!1),[p,h]=(0,i.useState)(!0),[f,g]=(0,i.useState)(),[v,b]=(0,i.useState)({}),[y,x]=(0,i.useState)(!1),[w,j]=(0,i.useState)(!1),[k,N]=(0,i.useState)(0);(0,i.useEffect)(()=>{let e=()=>{l("models"),j(!0);};pv()&&e();let t=()=>{pv()&&e();};return window.addEventListener(ph,t),()=>{window.removeEventListener(ph,t);};},[]),(0,i.useEffect)(()=>{w&&!p&&void 0===f&&(x(!0),j(!1));},[w,p,f]),(0,i.useEffect)(()=>{let e=!1;return async function(){h(!0),g(void 0);try{let[t,n]=await Promise.all([(0,m.Dz)(),(0,m.ZC)()]);if(e)return;c(t.config),u(t.configPresent),s(n.models);}catch(n){if(e)return;g(function(e,t){let n=t("settings.models.loadError");if(!(e instanceof Error))return n;let l=e.message.trim();return 0===l.length||/^HTTP \d+$/u.test(l)||"Failed to fetch"===l||"Load failed"===l||"NetworkError when attempting to fetch a resource."===l?n:l;}(n,t));}finally{e||h(!1);}}(),()=>{e=!0;};},[k,t]);let S=a.filter(lO.S_).length,C=(0,i.useMemo)(()=>function(e){let t=new Set();for(let n of e)for(let e of(0,lO.iu)(n).personas)t.add(e);return iY.RX.filter(e=>t.has(e));}(a),[a]),R=a.length>0,I=d?R?t("settings.models.connected"):t("settings.models.configured"):t("settings.models.setupRequired"),E=d?R?0===S?t("settings.models.detailNoChat"):t("settings.models.detailReady"):t("settings.models.detailNoModels"):t("settings.models.detailSetup"),A=d?"connected":"untested";async function T(e,n){b(t=>({...t,[e]:{status:"running",deep:n}}));try{let t=await(0,m.IN)(e,n?{includeDeepProbes:!0}:void 0);b(n=>({...n,[e]:{status:"done",report:t}}));}catch(n){b(l=>({...l,[e]:{status:"error",message:n instanceof Error&&n.message.trim().length>0?n.message:t("settings.models.readinessError")}}));}}return(0,r.jsxs)("div",{className:"set",children:[(0,r.jsxs)("div",{className:"set-hero",children:[(0,r.jsx)($.F.settings,{size:18}),(0,r.jsx)("span",{className:"set-title",children:t("settings.title")}),(0,r.jsxs)("span",{className:"set-onprem",title:t("settings.selfHostedTitle"),children:[(0,r.jsx)("span",{className:"dot",style:{background:"var(--accent)"}})," ",t("settings.selfHosted")]})]}),(0,r.jsx)("div",{className:"set-tabs",children:["models","general","security"].map(e=>(0,r.jsx)("button",{type:"button",className:"set-tab","data-on":n===e,"aria-pressed":n===e,onPointerDown:()=>l(e),onClick:()=>l(e),children:"models"===e?t("settings.tabs.models"):"general"===e?t("settings.tabs.general"):t("settings.tabs.security")},e))}),(0,r.jsxs)("div",{className:"set-body",children:["models"===n&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"set-sec-h",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"set-sec-t",children:t("settings.models.gatewayTitle")}),(0,r.jsx)("div",{className:"set-sec-d",children:t("settings.models.gatewayDescription")})]}),(0,r.jsxs)("button",{type:"button",className:"set-add",onClick:()=>x(!0),children:[(0,r.jsx)($.F.plus,{size:14}),d?t("settings.models.updateCredentials"):t("settings.models.connectGateway")]})]}),(0,r.jsxs)("div",{className:"ml-row",children:[(0,r.jsx)("span",{className:"ml-ico",children:(0,r.jsx)($.F.cube,{size:16})}),(0,r.jsxs)("div",{className:"ml-info",children:[(0,r.jsxs)("div",{className:"ml-top",children:[(0,r.jsx)("span",{className:"ml-name",children:I}),(0,r.jsx)("span",{className:"ml-type mono",children:t("settings.models.modelCount",{count:a.length})}),(0,r.jsx)("span",{className:"ml-type mono",children:t("settings.models.chatCount",{count:S})})]}),(0,r.jsx)("div",{className:"ml-url mono",children:E})]}),(0,r.jsx)("span",{className:"ml-status "+A,title:d?t("settings.models.statusConfigured"):t("settings.models.statusSetupRequired"),"aria-hidden":"true"})]}),void 0!==f?(0,r.jsxs)("div",{className:"gw-error",role:"alert",children:[f,(0,r.jsx)("button",{type:"button",className:"gw-error-retry",onClick:()=>N(e=>e+1),children:t("settings.models.retry")})]}):null,p?(0,r.jsx)("div",{className:"set-placeholder",role:"status",children:t("settings.models.loading")}):0===a.length?(0,r.jsx)("div",{className:"set-placeholder",role:"status",children:d?t("settings.models.emptyConfigured"):t("settings.models.emptyUnconfigured")}):(0,r.jsx)("div",{className:"set-list",children:a.map(e=>(0,r.jsx)(pS,{model:e,readiness:v[e.id],onRunReadiness:(e,t)=>{T(e,t);}},e.id))}),y?(0,r.jsx)(lt,{onCancel:()=>x(!1),preserveExisting:d,storedApiKeyHeaderName:null==o||null==(e=o.providers[0])?void 0:e.credentialHeaderName,storedModels:a}):null]}),"general"===n&&(0,r.jsx)(pC,{voicePersonas:C}),"security"===n&&(0,r.jsx)("div",{className:"set-placeholder",children:t("settings.security.placeholder")})]})]});}function pI(e){return e instanceof m.hD?`${e.message} (${e.code})`:e instanceof Error?e.message:"Failed to load connectors.";}function pE(){return(0,r.jsx)("div",{className:"connector-picker-status",role:"status","aria-live":"polite",children:"Loading connectors…"});}function p$(e){let{message:t,onRetry:n}=e;return(0,r.jsxs)("div",{className:"connector-picker-error",role:"alert",children:[(0,r.jsx)("p",{children:t}),(0,r.jsx)("button",{type:"button",className:"connector-picker-retry",onClick:n,children:"Try again"})]});}function pA(e){let{onManageConnectors:t}=e;return(0,r.jsx)("div",{className:"connector-picker-empty",children:(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-primary connector-picker-create-link",onClick:t,children:"Create a connector"})});}function pT(e){let{capsules:t,capsuleSets:n,selectedKind:l,selectedId:a}=e,i=function(e,t,n,l){if(void 0===n||void 0===l||0===l.length)return null;if("capsule"===n){let t=e.find(e=>e.id===l);return void 0!==t?t.displayName:`Capsule ${l}`;}if("capsule-set"===n){let e=t.find(e=>e.id===l);return void 0!==e?e.displayName:`Set ${l}`;}return null;}(t,n,l,a);return null===i?null:(0,r.jsxs)("div",{className:"connector-picker-selected",role:"status","aria-live":"polite",children:[(0,r.jsx)("span",{"aria-hidden":"true",children:"●"}),(0,r.jsx)("span",{children:i})]});}function pF(e){let{selectedLabel:t,selectedState:n,onManageConnectors:l}=e,a=void 0!==t&&t.trim().length>0?t.trim():"Knowledge capsule";return(0,r.jsxs)("div",{className:"connector-node","data-testid":"knowledge-connector-node",children:[(0,r.jsx)("div",{className:"connector-node-icon","aria-hidden":"true",children:(0,r.jsx)($.F.server,{size:42})}),(0,r.jsxs)("div",{className:"connector-node-copy",children:[(0,r.jsx)("p",{className:"connector-node-kicker",children:function(e){switch(e){case"ready":return"Indexed";case"draft":return"Draft";case"indexing":return"Indexing";case"stale":return"Stale";case"error":return"Failed";default:return"Local Knowledge";}}(n)}),(0,r.jsx)("h2",{className:"connector-node-title",title:a,children:a}),(0,r.jsx)("p",{className:"connector-node-meta",children:"Local Knowledge capsule"})]}),(0,r.jsx)("button",{type:"button",className:"connector-node-manage",onClick:l,children:"Manage"})]});}function pD(e){let{selectedKind:t,selectedId:n,selectedLabel:l,selectedState:a,presentation:s,onSelect:o,onManageConnectors:c=()=>void 0}=e,[d,u]=(0,i.useState)([]),[p,m]=(0,i.useState)([]),[h,f]=(0,i.useState)(!0),[g,v]=(0,i.useState)(null),[b,y]=(0,i.useState)(!1),[x,w]=(0,i.useState)(0),j="node"===s&&"capsule"===t&&void 0!==n&&n.length>0;if((0,i.useEffect)(()=>{if(j)return;let e=!1;return async function(){f(!0),v(null),y(!1);try{let[t,n]=await Promise.allSettled([(0,sb.xr)(),(0,sb.R3)()]);if(e)return;"fulfilled"===t.status?u(t.value.capsules.filter(e=>"ready"===e.lifecycleState)):v(pI(t.reason)),"fulfilled"===n.status?m(n.value.capsuleSets):y(!0);}catch(t){e||v(pI(t));}finally{e||f(!1);}}(),()=>{e=!0;};},[j,x]),j)return(0,r.jsx)(pF,{selectedLabel:l,selectedState:a,onManageConnectors:c});if(h)return(0,r.jsx)(pE,{});if(null!==g)return(0,r.jsx)(p$,{message:g,onRetry:()=>{w(e=>e+1);}});let k=d.length>0,N=p.length>0;if(!k&&!N)return(0,r.jsx)(pA,{onManageConnectors:c});let S=void 0!==t&&void 0!==n&&n.length>0?`${t}:${n}`:"";return(0,r.jsxs)("div",{className:"connector-picker",children:[(0,r.jsx)(pT,{capsules:d,capsuleSets:p,selectedKind:t,selectedId:n}),(0,r.jsx)("div",{className:"connector-picker-label",children:"Select a connector"}),(0,r.jsx)(ln.A,{triggerClassName:"connector-picker-select",value:S,ariaLabel:"Select a connector",placeholder:"— choose a connector —",menuTitle:"Available connectors",sections:[...(k?[{label:"Capsules",options:d.map(e=>({value:`capsule:${e.id}`,label:`${e.displayName} (${function(e){switch(e){case"ready":return"Ready";case"indexing":return"Indexing…";case"error":return"Failed";default:return e;}}(e.lifecycleState)})`}))}]:[]),...(N?[{label:"Capsule sets",options:p.map(e=>({value:`capsule-set:${e.id}`,label:`${e.displayName} (${String(e.capsuleCount)} capsules)`}))}]:[])],onValueChange:e=>{!function(e){if(""===e)return;let t=e.indexOf(":");if(-1===t)return;let n=e.slice(0,t),l=e.slice(t+1);0!==l.length&&o({selectedKind:n,selectedId:l});}(e);}}),b?(0,r.jsx)("p",{className:"connector-picker-notice",role:"status",children:"Capsule sets could not be loaded."}):null,(0,r.jsx)("div",{className:"connector-picker-footer",children:(0,r.jsx)("button",{type:"button",className:"connector-picker-create-link",onClick:c,children:"Create or manage connectors"})})]});}async function pM(e,t){var n,l;let a=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),r="GET"!==a&&"HEAD"!==a,i=await fetch(e,{...t,headers:{Accept:"application/json",...(r?{"Content-Type":"application/json"}:{}),...(r?{"X-Keiko-CSRF":"1"}:{}),...(null!=(l=null==t?void 0:t.headers)?l:{})}});if(!i.ok){let e="INTERNAL",t=`HTTP ${i.status.toString()}`;try{let n=await i.json();e=n.error.code,t=n.error.message;}catch{}throw new m.hD(e,t,i.status);}return i.json();}async function pP(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return pM("/api/figma/snapshots",{method:"POST",...(void 0!==t.signal?{signal:t.signal}:{}),body:JSON.stringify({boardLink:e,...(!0===t.acknowledgeReadOnly?{acknowledgeReadOnly:!0}:{}),...(!0===t.isResnapshot?{isResnapshot:!0}:{}),...(void 0!==t.version?{version:t.version}:{})})});}async function pL(e,t){return pM(`/api/figma/snapshots/${encodeURIComponent(e)}`,{...(void 0!==t?{signal:t}:{})});}async function pq(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=new URLSearchParams();void 0!==e.fileKey&&t.set("fileKey",e.fileKey),void 0!==e.nodeId&&t.set("nodeId",e.nodeId),void 0!==e.limit&&t.set("limit",String(e.limit));let n=t.size>0?`?${t.toString()}`:"";return(await pM(`/api/figma/snapshots${n}`,{...(void 0!==e.signal?{signal:e.signal}:{})})).snapshots;}async function pz(e,t,n){return pM(`/api/figma/snapshots/${encodeURIComponent(e)}`,{method:"PATCH",...(void 0!==n?{signal:n}:{}),body:JSON.stringify({displayName:t})});}async function pO(e,t){return pM(`/api/figma/snapshots/${encodeURIComponent(e)}`,{method:"DELETE",...(void 0!==t?{signal:t}:{})});}function pB(e,t){return`/api/figma/snapshots/${encodeURIComponent(e)}/screens/${encodeURIComponent(String(t))}/image`;}async function pW(e,t,n){return pM(`/api/figma/snapshots/${encodeURIComponent(e)}/screens/${encodeURIComponent(t)}/json`,{...(void 0!==n?{signal:n}:{})});}async function pK(e,t){return pM(`/api/figma/snapshots/${encodeURIComponent(e)}/code`,{method:"POST",...(void 0!==t?{signal:t}:{}),body:JSON.stringify({})});}async function pU(){return pM("/api/figma/token",{method:"DELETE",body:JSON.stringify({})});}let pV=/"(?:\\(?:["\\/bfnrt]|u[0-9a-fA-F]{4})|[^"\\])*"\s*:?|[-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?|\b(?:true|false|null)\b|[{}\[\],:]/gu;function pH(e){return 0===e.length?0:"u">typeof TextEncoder?new TextEncoder().encode(e).byteLength:e.length;}function p_(e){let{text:t,className:n}=e,l=function(e){let t=[],n=0;for(let l of e.matchAll(pV)){let a=l[0],r=l.index;r>n&&t.push(e.slice(n,r)),t.push({kind:a.startsWith('"')?a.endsWith(":")?"key":"string":"true"===a||"false"===a?"boolean":"null"===a?"null":/^-?\d/u.test(a)?"number":"punctuation",text:a}),n=r+a.length;}return n<e.length&&t.push(e.slice(n)),t;}(t);return(0,r.jsx)("pre",{className:n,children:(0,r.jsx)("code",{children:l.map((e,t)=>"string"==typeof e?e:(0,r.jsx)("span",{className:`json-token-${e.kind}`,children:e.text},`${e.kind}-${t.toString()}`))})});}let pG=[];function pJ(e){try{let t=new URL(e.trim()),n=t.hostname.toLowerCase();if("https:"!==t.protocol||"figma.com"!==n&&"www.figma.com"!==n||!/^\/(design|file)\//u.test(t.pathname))return!1;let l=t.searchParams.get("node-id");return null!==l&&l.length>0;}catch{return!1;}}function pY(e){let t=new URL(`https://www.figma.com/design/${e.fileKey}/board`);return t.searchParams.set("node-id",e.nodeId),void 0!==e.version&&e.version.length>0&&t.searchParams.set("version",e.version),t.toString();}function pX(e){var t;return null!=(t=e.displayName)?t:`Snapshot ${(0,aQ.Yq)(e.fetchedAt)}`;}function pZ(e){return void 0===e||0===e.length?"Latest":e;}function pQ(e){return e.length<=16?e:`${e.slice(0,12)}…`;}function p0(e){var t;return null!=(t=e.management)?t:{};}function p1(e,t){return{runId:e.runId,...(void 0!==t.displayName?{displayName:t.displayName}:{}),management:p0(t),fileKey:e.fileKey,nodeId:e.nodeId,version:e.version,fetchedAt:e.fetchedAt,screenCount:e.screenCount,skippedCount:e.skippedCount,...(void 0!==e.structuralOnlyCount?{structuralOnlyCount:e.structuralOnlyCount}:{}),reductionHint:e.reductionHint,integrityHash:e.integrityHash};}let p2=new Set(["FIGMA_PROXY_EGRESS_FAILED","FIGMA_PROXY_UNREACHABLE","FIGMA_PROXY_AUTH_REQUIRED","FIGMA_PROXY_BLOCKED_BY_POLICY"]),p4=new Set(["FIGMA_TLS_CA_FAILURE"]),p3=new Set(["FIGMA_NETWORK_UNREACHABLE","FIGMA_EGRESS_TIMEOUT","FIGMA_EGRESS_FAILED"]),p6=new Set(["FIGMA_TOKEN_MISSING","FIGMA_TOKEN_INVALID","FIGMA_TOKEN_EXPIRED","FIGMA_TOKEN_REVOKED","FIGMA_INSUFFICIENT_SCOPE"]);function p5(e){return e instanceof m.hD?p6.has(e.code)?{title:"Figma access token needs attention",detail:`${e.code}: ${e.message}`,status:`HTTP ${e.status.toString()}`,remediation:"Open the Figma access token settings to add or rotate the read-only token, then retry. No snapshot was stored.",assertive:!0,tokenConfig:!0}:"FIGMA_UPSTREAM_UNAVAILABLE"===e.code?{title:"Figma is currently unavailable",detail:`${e.code}: ${e.message}`,status:`HTTP ${e.status.toString()}`,remediation:"Retry later — no snapshot was stored.",assertive:!0}:p2.has(e.code)?{title:"Figma snapshot blocked by outbound egress",detail:`${e.code}: ${e.message}`,status:`HTTP ${e.status.toString()}`,remediation:"Check the configured proxy, NO_PROXY rules, and CA bundle, then retry. No snapshot was stored.",assertive:!0}:p4.has(e.code)?{title:"Figma snapshot blocked by outbound egress",detail:`${e.code}: ${e.message}`,status:`HTTP ${e.status.toString()}`,remediation:"A TLS certificate verification failure blocked the request. Check the CA bundle configuration, then retry. No snapshot was stored.",assertive:!0}:p3.has(e.code)?{title:"Figma snapshot blocked by outbound egress",detail:`${e.code}: ${e.message}`,status:`HTTP ${e.status.toString()}`,remediation:"The outbound network request to Figma failed. Check DNS resolution and network connectivity, then retry. No snapshot was stored.",assertive:!0}:{title:"Figma snapshot failed",detail:e.message}:e instanceof Error?{title:"Figma snapshot failed",detail:e.message}:{title:"Figma snapshot failed",detail:"An unexpected error occurred."};}function p8(e){let t=p5(e);return void 0===t.status?t.detail:`${t.detail} (${t.status})`;}function p9(e,t){let n=document.elementFromPoint(e,t);return n instanceof Element&&null!==n.closest("main.workspace")&&null===n.closest(".window");}function p7(e,t){let n={payload:e,clientX:t.clientX,clientY:t.clientY};window.dispatchEvent(new CustomEvent(nO,{detail:n}));}function me(e,t){let n={payload:e,clientX:t.clientX,clientY:t.clientY};window.dispatchEvent(new CustomEvent(nU,{detail:n}));}function mt(e,t){let n={payload:e,clientX:t.clientX,clientY:t.clientY};window.dispatchEvent(new CustomEvent(nG,{detail:n}));}function mn(e){let{index:t,screenId:n,name:l,irSummary:a,imageSrc:s,imageByteLength:o,structuralReason:c,onAddSource:d,isSourceSelected:u=!1,dragPayload:p}=e,m=(0,i.useRef)(null),h=(0,i.useRef)(!1),f=(0,i.useRef)(!1),g=void 0!==p&&void 0!==d&&!u,v=u?`${l} preview is already the active scoped source`:`Drag screen ${l} to the workspace, or click to add it as a Quality Intelligence source`,b=void 0!==s?(0,r.jsx)(aY.default,{className:"figma-snapshot-screen-image",src:s,alt:`Captured preview for ${l}`,loading:"lazy",width:72,height:54,unoptimized:!0}):(0,r.jsxs)("div",{className:"figma-snapshot-screen-image figma-snapshot-screen-placeholder","aria-label":`Structural data only for ${l}`,role:"img",children:[(0,r.jsx)($.F.layers,{className:"figma-snapshot-screen-frame-icon","aria-hidden":"true"}),(0,r.jsx)("span",{className:"figma-snapshot-screen-placeholder-label",children:"IR"})]});return(0,r.jsxs)("article",{className:"figma-snapshot-screen-card","aria-label":`Screen ${String(t+1)}: ${l}`,children:[void 0!==d?(0,r.jsx)("button",{type:"button",className:"figma-snapshot-screen-preview-btn",onClick:e=>{if(f.current){f.current=!1,e.preventDefault(),e.stopPropagation();return;}null==d||d();},disabled:u,"aria-disabled":u?"true":void 0,"aria-label":v,draggable:g,onDragStart:e=>{g&&(e.dataTransfer.effectAllowed="copy",e.dataTransfer.setData(nz,JSON.stringify(p)),e.dataTransfer.setData("text/plain",l));},onDragEnd:e=>{g&&p9(e.clientX,e.clientY)&&p7(p,e);},onPointerDown:e=>{g&&0===e.button&&(h.current=!1,m.current={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY},e.currentTarget.setPointerCapture(e.pointerId));},onPointerMove:e=>{let t=m.current;null===t||t.pointerId!==e.pointerId||Math.hypot(e.clientX-t.startX,e.clientY-t.startY)>=6&&e.preventDefault();},onPointerUp:e=>{let t=m.current;if(null===t||t.pointerId!==e.pointerId)return;m.current=null,e.currentTarget.releasePointerCapture(e.pointerId);let n=Math.hypot(e.clientX-t.startX,e.clientY-t.startY);n>=6&&(h.current=!0),n>=6&&void 0!==p&&p9(e.clientX,e.clientY)&&(e.preventDefault(),f.current=!0,p7(p,e));},onPointerCancel:e=>{let t=m.current;null!==t&&t.pointerId===e.pointerId&&(m.current=null,e.currentTarget.releasePointerCapture(e.pointerId));},onMouseDown:e=>{if(!g||0!==e.button||void 0===p)return;let t=e.clientX,n=e.clientY,l=e=>{Math.hypot(e.clientX-t,e.clientY-n)>=6&&e.preventDefault();},a=e=>{if(window.removeEventListener("mousemove",l),window.removeEventListener("mouseup",a),h.current){h.current=!1;return;}Math.hypot(e.clientX-t,e.clientY-n)>=6&&p9(e.clientX,e.clientY)&&(e.preventDefault(),f.current=!0,p7(p,e));};window.addEventListener("mousemove",l),window.addEventListener("mouseup",a);},children:b}):b,(0,r.jsxs)("div",{className:"figma-snapshot-screen-meta",children:[(0,r.jsx)("h3",{className:"figma-snapshot-screen-name",title:l,children:l}),(0,r.jsx)("p",{className:"figma-snapshot-screen-summary",children:a}),(0,r.jsx)("p",{className:"figma-snapshot-screen-size",children:void 0!==o?(0,aQ.z3)(o):`Structural IR only${void 0!==c?` (${c})`:""}`}),(0,r.jsx)("p",{className:"figma-snapshot-screen-id",children:n}),void 0!==d?(0,r.jsx)("div",{className:"figma-snapshot-screen-actions",children:(0,r.jsx)("button",{type:"button",className:"figma-snapshot-screen-source-btn",onClick:d,disabled:u,"aria-disabled":u?"true":void 0,"aria-label":u?`${l} is already the active scoped source`:`Add screen ${l} to the workspace as a Quality Intelligence source`,children:u?"Source active":"Add to workspace"})}):null]})]});}function ml(e){let{name:t,screenId:n,irSummary:l,imageSrc:a,imageByteLength:s,structuralReason:o,snapshotRunId:c,capturedAt:d,imageDragPayload:u}=e,p=(0,i.useRef)(null),m=(0,i.useRef)(!1),h=void 0!==a&&void 0!==u,f=void 0!==a?(0,r.jsx)(aY.default,{className:"figma-view-preview-image",src:a,alt:`Captured preview for ${t}`,loading:"eager",width:360,height:240,draggable:!1,unoptimized:!0}):(0,r.jsxs)("div",{className:"figma-view-preview-image figma-view-preview-placeholder","aria-label":`Structural data only for ${t}`,role:"img",children:[(0,r.jsx)($.F.layers,{className:"figma-view-preview-icon","aria-hidden":"true"}),(0,r.jsx)("span",{children:"Structural IR"})]});return(0,r.jsxs)("article",{className:"figma-view-source-card","aria-label":`Figma view source: ${t}`,children:[h?(0,r.jsx)("button",{type:"button",className:"figma-view-preview figma-view-preview-drag-surface",draggable:!0,onDragStart:e=>{h&&(e.dataTransfer.effectAllowed="copyMove",e.dataTransfer.setData(n_,JSON.stringify(u)),e.dataTransfer.setData("text/plain",`${u.name}.png`));},onDragEnd:e=>{h&&p9(e.clientX,e.clientY)&&mt(u,e);},onKeyDown:e=>{if(!h||"Enter"!==e.key&&" "!==e.key)return;e.preventDefault();let t=e.currentTarget.getBoundingClientRect();mt(u,{clientX:t.right+24,clientY:t.top+t.height/2});},onPointerDown:e=>{h&&0===e.button&&(m.current=!1,p.current={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY},e.currentTarget.setPointerCapture(e.pointerId));},onPointerMove:e=>{let t=p.current;null===t||t.pointerId!==e.pointerId||Math.hypot(e.clientX-t.startX,e.clientY-t.startY)>=6&&e.preventDefault();},onPointerUp:e=>{let t=p.current;if(null===t||t.pointerId!==e.pointerId)return;p.current=null,e.currentTarget.releasePointerCapture(e.pointerId);let n=Math.hypot(e.clientX-t.startX,e.clientY-t.startY);n>=6&&(m.current=!0),n>=6&&h&&p9(e.clientX,e.clientY)&&(e.preventDefault(),mt(u,e));},onPointerCancel:e=>{let t=p.current;null!==t&&t.pointerId===e.pointerId&&(p.current=null,e.currentTarget.releasePointerCapture(e.pointerId));},onMouseDown:e=>{if(!h||0!==e.button)return;let t=e.clientX,n=e.clientY,l=e=>{Math.hypot(e.clientX-t,e.clientY-n)>=6&&e.preventDefault();},a=e=>{if(window.removeEventListener("mousemove",l),window.removeEventListener("mouseup",a),m.current){m.current=!1;return;}Math.hypot(e.clientX-t,e.clientY-n)>=6&&p9(e.clientX,e.clientY)&&(e.preventDefault(),mt(u,e));};window.addEventListener("mousemove",l),window.addEventListener("mouseup",a);},"aria-label":`Create a standalone image source for ${t}`,title:`Drag image for ${t} to the workspace`,children:f}):(0,r.jsx)("div",{className:"figma-view-preview",children:f}),(0,r.jsxs)("div",{className:"figma-view-source-meta",children:[(0,r.jsx)("p",{className:"figma-view-source-kicker",children:"QI view source"}),(0,r.jsx)("h2",{className:"figma-view-source-title",title:t,children:t}),(0,r.jsx)("p",{className:"figma-view-source-summary",children:l}),(0,r.jsxs)("dl",{className:"figma-view-source-facts",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:"Screen"}),(0,r.jsx)("dd",{children:n})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:"Snapshot"}),(0,r.jsx)("dd",{children:c})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:"Captured"}),(0,r.jsx)("dd",{children:d})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:"Preview"}),(0,r.jsx)("dd",{children:void 0!==s?(0,aQ.z3)(s):`Structural IR${void 0!==o?` (${o})`:""}`})]})]})]})]});}function ma(e){var t,n,l,a,s;let o,c,d,u,{sourceWindowId:p,snapshotRunId:h,selectedScreenIds:f=pG,selectedScreenName:g,openScreenSource:v,openTokenSettings:b,updateCfg:y,triggerImpl:x=pP,loadImpl:w=pL,listImpl:j=pq,updateMetadataImpl:k=pz,deleteImpl:N=pO,loadScreenJsonImpl:S=pW,codegenImpl:C=pK,revokeImpl:R=pU}=e,I=(0,i.useId)(),E=(0,i.useId)(),A=(0,i.useId)(),T=(0,i.useId)(),[F,D]=(0,i.useState)(""),[M,P]=(0,i.useState)("idle"),[L,q]=(0,i.useState)(null),[z,O]=(0,i.useState)(null),[B,W]=(0,i.useState)(null),[K,U]=(0,i.useState)(null),[V,H]=(0,i.useState)(0),[_,G]=(0,i.useState)("recent"),[J,Y]=(0,i.useState)([]),[X,Z]=(0,i.useState)([]),[Q,ee]=(0,i.useState)(!1),[et,en]=(0,i.useState)(!1),[el,ea]=(0,i.useState)(null),[er,ei]=(0,i.useState)(null),[es,eo]=(0,i.useState)(null),[ec,ed]=(0,i.useState)(""),[eu,ep]=(0,i.useState)(null),[em,eh]=(0,i.useState)(null),[ef,eg]=(0,i.useState)(null),[ev,eb]=(0,i.useState)(null),[ey,ex]=(0,i.useState)(!1),[ew,ej]=(0,i.useState)(!1),ek=(0,i.useRef)(null),eN=(0,i.useRef)(null),eS=(0,i.useRef)(null),eC=(0,i.useRef)(null),eR=(0,i.useRef)(null),eI=(0,i.useRef)(null),eE=(0,i.useRef)(null),e$=(0,i.useRef)(null),eA=(0,i.useRef)(!1),eT=(0,i.useCallback)(()=>{ej(!0);},[]),[eF,eD]=(0,i.useState)("idle"),[eM,eP]=(0,i.useState)(null),[eL,eq]=(0,i.useState)(null),[ez,eO]=(0,i.useState)("idle"),[eB,eW]=(0,i.useState)(null),[eK,eU]=(0,i.useState)(null),[eV,eH]=(0,i.useState)(null),[e_,eG]=(0,i.useState)(!1),[eJ,eY]=(0,i.useState)(null),[eX,eZ]=(0,i.useState)(null),eQ=(0,i.useRef)(null),e0=(0,i.useRef)(null),[e1,e2]=(0,i.useState)(24),e4=f.join("\0"),e3=pJ(F),e6=function(e){let t=e.trim();if(0===t.length||pJ(t))return null;try{let e=new URL(t),n=e.hostname.toLowerCase();if("https:"===e.protocol&&("figma.com"===n||"www.figma.com"===n)&&/^\/(design|file)\//u.test(e.pathname))return"Add a node-id by selecting a frame or section in Figma and copying its link (Copy link to selection).";}catch{}return"This doesn't look like a Figma board link. Use a figma.com design/file link that includes a node-id parameter.";}(F),e5=(0,i.useMemo)(()=>null!==L?{fileKey:L.fileKey,nodeId:L.nodeId}:function(e){try{let t=new URL(e.trim()),n=t.hostname.toLowerCase();if("https:"!==t.protocol||"figma.com"!==n&&"www.figma.com"!==n)return null;let[,l,a]=t.pathname.split("/");if("design"!==l&&"file"!==l||void 0===a||0===a.length)return null;let r=t.searchParams.get("node-id");if(null===r||0===r.length)return null;return{fileKey:a,nodeId:r};}catch{return null;}}(F),[F,L]),e8=null==e5?void 0:e5.fileKey,e9=null==e5?void 0:e5.nodeId,e7="building"===M,te="loading"===M,tt=e7||te,tn=e7&&null!==K?(c=Math.floor((o=Math.max(0,Math.floor(V/1e3)))/3600),d=Math.floor(o%3600/60),u=o%60,c>0?`${String(c)}h ${String(d)}m ${String(u)}s`:d>0?`${String(d)}m ${String(u)}s`:`${String(u)}s`):null,tl=(0,i.useMemo)(()=>new Set(f),[f]),ta=f.length>0,tr=ta&&void 0!==h&&h.length>0,ti=(0,i.useMemo)(()=>{var e;if(null===L)return[];let t=new Set(L.screens.map(e=>e.screenId)),n=[...L.screens.map((e,t)=>({kind:"rendered",screen:e,imageIndex:t})),...(null!=(e=L.structuralScreens)?e:[]).filter(e=>!t.has(e.screenId)).map(e=>({kind:"structural",screen:e}))];return ta?n.filter(e=>tl.has(e.screen.screenId)):n;},[ta,tl,L]),ts=1===f.length?f[0]:void 0,to=(0,i.useMemo)(()=>null===eB?"":JSON.stringify(eB,null,2),[eB]),tc=(0,i.useMemo)(()=>pH(to),[to]),td=(null!=(t=null==L?void 0:L.screens.length)?t:0)+(null!=(n=null==L||null==(a=L.structuralScreens)?void 0:a.length)?n:0),tu=null===L?{}:p0(L);(0,i.useEffect)(()=>{var e;ew&&"error"===M&&(null==(e=ek.current)||e.focus());},[ew,M]),(0,i.useEffect)(()=>{var e;e_&&(null==(e=eQ.current)||e.focus());},[e_]),(0,i.useEffect)(()=>{if(!e7||null===K)return;H(Date.now()-K);let e=window.setInterval(()=>{H(Date.now()-K);},1e3);return()=>{window.clearInterval(e);};},[e7,K]),(0,i.useEffect)(()=>()=>{var e,t,n,l,a;null==(e=eN.current)||e.abort(),null==(t=eS.current)||t.abort(),null==(n=eC.current)||n.abort(),null==(l=eR.current)||l.abort(),null==(a=eI.current)||a.abort();},[]),(0,i.useEffect)(()=>{null===e5&&"board"===_&&G("recent");},[e5,_]);let tp=(0,i.useCallback)(()=>{var e;null==(e=eR.current)||e.abort();let t=new AbortController();if(eR.current=t,en(!0),ei(null),j({limit:12,signal:t.signal}).then(e=>{Z(e);}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name||(Z([]),ei(p8(e)));}).finally(()=>{eR.current===t&&en(!1);}),void 0===e8||void 0===e9){Y([]),ea(null),ee(!1);return;}ee(!0),ea(null),j({fileKey:e8,nodeId:e9,limit:12,signal:t.signal}).then(e=>{Y(e);}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name||(Y([]),ea(p8(e)));}).finally(()=>{eR.current===t&&ee(!1);});},[e8,e9,j]);(0,i.useEffect)(()=>{tp();},[tp,null==L?void 0:L.runId]);let tm=(0,i.useCallback)(e=>{var t;if(0===e.length||tt)return;null==(t=eN.current)||t.abort();let n=new AbortController();eN.current=n,P("loading"),O(null),W(null),eD("idle"),eP(null),eq(null),eO("idle"),eW(null),eU(null),eH(null),w(e,n.signal).then(e=>{q(e),D(pY(e)),y({snapshotRunId:e.runId}),P("done");}).catch(t=>{t instanceof DOMException&&"AbortError"===t.name||(t instanceof m.hD&&"FIGMA_SNAPSHOT_NOT_FOUND"===t.code?(h===e&&y({snapshotRunId:void 0}),O({...p5(t),detail:h===e?`${t.message} The stored run ID has been cleared.`:t.message})):O(p5(t)),P("error"));});},[tt,w,h,y]);(0,i.useEffect)(()=>{tr&&void 0!==h&&0!==h.length&&null===L&&"idle"===M&&tm(h);},[M,tr,tm,h,L]);let th=(0,i.useCallback)(async(e,t)=>{var n,l,a;null==(n=eN.current)||n.abort(),null==(l=eS.current)||l.abort(),null==(a=eC.current)||a.abort(),eS.current=null,eC.current=null;let r=new AbortController();eN.current=r,eE.current={link:e,isResnapshot:t},P("building"),O(null),W(null),U(Date.now()),H(0),eD("idle"),eP(null),eO("idle"),eW(null),eU(null),eH(null);try{let n=await x(e,{acknowledgeReadOnly:ey,isResnapshot:t,signal:r.signal});q(n),D(pY(n)),y({snapshotRunId:n.runId}),P("done"),U(null),H(0),eE.current=null;}catch(n){if(n instanceof DOMException&&"AbortError"===n.name)return;if(U(null),H(0),n instanceof m.hD&&"FIGMA_CONSENT_REQUIRED"===n.code){let e=p5(n);O({...e,detail:`${e.detail} Tick the acknowledgement checkbox below, then snapshot again.`}),eT();}else n instanceof m.hD&&"FIGMA_BUILD_TIMEOUT"===n.code?(W({link:e,isResnapshot:t}),O({title:"Figma snapshot is still running",detail:"This window stopped waiting for the snapshot result. The server may still finish the build in the background.",status:`HTTP ${n.status.toString()}`,remediation:"Reconnect to the same board to keep waiting, or close this window and return later."})):O(p5(n));P("error"),eE.current=null;}},[x,y,ey,eT]),tf=(0,i.useCallback)(e=>{if(e.preventDefault(),e3&&!tt){if(!ey){O({title:"Figma snapshot failed",detail:"Tick the read-only acknowledgement checkbox below, then snapshot again."}),P("error"),eT();return;}th(F,!1);}},[F,tt,ey,e3,th,eT]),tg=(0,i.useCallback)(()=>{tt||null!==L&&th(pY(L),!0);},[tt,th,L]),tv=(0,i.useCallback)(()=>{var e;null==(e=eN.current)||e.abort(),eN.current=null,U(null),H(0),null!==eE.current&&W(eE.current),eE.current=null,P("idle"),O(null);},[]),tb=(0,i.useCallback)(()=>{tt||null===B||th(B.link,B.isResnapshot);},[tt,B,th]),ty=(0,i.useCallback)(()=>{var e;let t=null!=(e=null==L?void 0:L.runId)?e:h;if(void 0===t||0===t.length||"generating"===eF)return;let n=new AbortController();eS.current=n,eD("generating"),eq(null),C(t,n.signal).then(e=>{eP(e),eD("done");}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name?eD("idle"):(eq(p8(e)),eD("error"));}).finally(()=>{eS.current===n&&(eS.current=null);});},[C,eF,h,L]),tx=(0,i.useCallback)(()=>{var e,t;let n=null!=(e=null==L?void 0:L.runId)?e:h;if(void 0===n||0===n.length||void 0===ts||"loading"===ez)return;null==(t=eC.current)||t.abort();let l=new AbortController();eC.current=l,eO("loading"),eU(null),eH(null),S(n,ts,l.signal).then(e=>{eW(e),eO("done");}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name?eO("idle"):(eW(null),eU(p8(e)),eO("error"));}).finally(()=>{eC.current===l&&(eC.current=null);});},[ts,S,ez,h,null==L?void 0:L.runId]),tw=(0,i.useCallback)(()=>{if(0!==to.length){if(void 0===navigator.clipboard)return void eH("Clipboard unavailable");navigator.clipboard.writeText(to).then(()=>{eH("Copied");}).catch(()=>{eH("Copy failed");});}},[to]),tj=(0,i.useMemo)(()=>{var e,t,n,l,a;let r=null!=(e=null!=(t=null==eB?void 0:eB.runId)?t:null==L?void 0:L.runId)?e:h,i=null!=(n=null==eB?void 0:eB.screen.screenId)?n:ts,s=null!=(l=null!=(a=null==eB?void 0:eB.screen.name)?a:g)?l:i;return void 0===r||0===r.length||void 0===i||0===i.length||void 0===s||0===s.length?null:{snapshotRunId:r,screenId:i,name:s,...(void 0!==p?{sourceWindowId:p}:{})};},[ts,null==eB?void 0:eB.runId,null==eB?void 0:eB.screen.name,null==eB?void 0:eB.screen.screenId,g,h,p,null==L?void 0:L.runId]),tk=(0,i.useCallback)(e=>{null!==tj&&(e.dataTransfer.effectAllowed="copyMove",e.dataTransfer.setData(nK,JSON.stringify(tj)),e.dataTransfer.setData("text/plain",`${tj.name}.json`));},[tj]),tN=(0,i.useCallback)(e=>{null!==tj&&p9(e.clientX,e.clientY)&&me(tj,e);},[tj]),tS=(0,i.useCallback)(e=>{if(null===tj||"Enter"!==e.key&&" "!==e.key)return;e.preventDefault();let t=e.currentTarget.getBoundingClientRect();me(tj,{clientX:t.right+24,clientY:t.top+t.height/2});},[tj]),tC=(0,i.useCallback)(e=>{null!==tj&&0===e.button&&(eA.current=!1,e$.current={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY},e.currentTarget.setPointerCapture(e.pointerId));},[tj]),tR=(0,i.useCallback)(e=>{let t=e$.current;null===t||t.pointerId!==e.pointerId||Math.hypot(e.clientX-t.startX,e.clientY-t.startY)>=6&&e.preventDefault();},[]),tI=(0,i.useCallback)(e=>{let t=e$.current;if(null===t||t.pointerId!==e.pointerId)return;e$.current=null,e.currentTarget.releasePointerCapture(e.pointerId);let n=Math.hypot(e.clientX-t.startX,e.clientY-t.startY);n>=6&&(eA.current=!0),n>=6&&null!==tj&&p9(e.clientX,e.clientY)&&(e.preventDefault(),me(tj,e));},[tj]),tE=(0,i.useCallback)(e=>{let t=e$.current;null!==t&&t.pointerId===e.pointerId&&(e$.current=null,e.currentTarget.releasePointerCapture(e.pointerId));},[]),t$=(0,i.useCallback)(e=>{if(null===tj||0!==e.button)return;let t=e.clientX,n=e.clientY,l=e=>{Math.hypot(e.clientX-t,e.clientY-n)>=6&&e.preventDefault();},a=e=>{if(window.removeEventListener("mousemove",l),window.removeEventListener("mouseup",a),eA.current){eA.current=!1;return;}Math.hypot(e.clientX-t,e.clientY-n)>=6&&p9(e.clientX,e.clientY)&&(e.preventDefault(),me(tj,e));};window.addEventListener("mousemove",l),window.addEventListener("mouseup",a);},[tj]),tA=(0,i.useCallback)(()=>{var e;null==(e=eS.current)||e.abort(),eS.current=null,eD("idle"),eq(null);},[]),tT=(0,i.useCallback)(()=>{void 0===h||0===h.length||tt||tm(h);},[tt,tm,h]);(0,i.useEffect)(()=>{e2(24);},[e4,null==L?void 0:L.runId]),(0,i.useEffect)(()=>{var e;null==(e=eC.current)||e.abort(),eC.current=null,eO("idle"),eW(null),eU(null),eH(null);},[e4,h]);let tF=(0,i.useCallback)(()=>{eG(!1),eZ(null),eY(null),R().then(e=>{eY(e.message),requestAnimationFrame(()=>{var e;return null==(e=e0.current)?void 0:e.focus();});}).catch(e=>{eZ(p8(e)),requestAnimationFrame(()=>{var e;return null==(e=e0.current)?void 0:e.focus();});});},[R]),tD=(0,i.useCallback)(()=>{eG(!1),requestAnimationFrame(()=>{var e;return null==(e=e0.current)?void 0:e.focus();});},[]),tM=(0,i.useCallback)(e=>{var t;eo(e.runId),ed(null!=(t=e.displayName)?t:""),ep(null),eh(null),eb(null);},[]),tP=(0,i.useCallback)(()=>{eo(null),ed("");},[]),tL=(0,i.useCallback)(e=>{var t;if(null!==ef)return;null==(t=eI.current)||t.abort();let n=new AbortController();eI.current=n,eg(e),eb(null);let l=ec.trim();k(e,0===l.length?null:l,n.signal).then(t=>{(null==L?void 0:L.runId)===e&&q(t),Y(n=>n.map(n=>n.runId===e?p1(n,t):n)),Z(n=>n.map(n=>n.runId===e?p1(n,t):n)),eo(null),ed("");}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name||eb(p8(e));}).finally(()=>{eI.current===n&&(eI.current=null),eg(null);});},[ec,ef,null==L?void 0:L.runId,k]),tq=(0,i.useCallback)(e=>{ep(t=>t===e?null:e),eo(null),eh(null),eb(null);},[]),tz=(0,i.useCallback)(e=>{eh(e),eo(null),ep(null),eb(null);},[]),tO=(0,i.useCallback)(e=>{var t;if(null!==ef)return;null==(t=eI.current)||t.abort();let n=new AbortController();eI.current=n,eg(e),eb(null),N(e,n.signal).then(t=>{Y(t=>t.filter(t=>t.runId!==e)),Z(t=>t.filter(t=>t.runId!==e)),eh(null),eo(null),ep(null),(null==L?void 0:L.runId)===e&&(q(null),P("idle"),eD("idle"),eP(null),eO("idle"),eW(null)),((null==L?void 0:L.runId)===e||h===e)&&y({snapshotRunId:void 0});}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name||eb(p8(e));}).finally(()=>{eI.current===n&&(eI.current=null),eg(null);});},[N,ef,h,null==L?void 0:L.runId,y]),tB=void 0!==h&&h.length>0&&null===L&&("idle"===M||"loading"===M||"error"===M),tW=(e,t,n,l,a,i)=>t?(0,r.jsx)("p",{className:"figma-snapshot-dashboard-status",children:"Loading snapshots…"}):null!==n?(0,r.jsx)("p",{className:"figma-snapshot-dashboard-status figma-snapshot-dashboard-status-error",children:n}):0===e.length?(0,r.jsxs)("div",{className:"figma-snapshot-dashboard-empty",children:[(0,r.jsx)("p",{className:"figma-snapshot-dashboard-empty-title",children:l}),(0,r.jsx)("p",{className:"figma-snapshot-dashboard-empty-detail",children:a})]}):(0,r.jsx)("div",{className:"figma-snapshot-dashboard-list",role:"list",children:e.map(e=>{var t;let n=(null==L?void 0:L.runId)===e.runId,l=pX(e),a=p0(e),s=ef===e.runId,o=eu===e.runId,c=es===e.runId,d=em===e.runId;return(0,r.jsxs)("article",{className:"figma-snapshot-dashboard-item",role:"listitem","aria-current":n?"true":void 0,"aria-busy":te&&h===e.runId?"true":void 0,children:[(0,r.jsxs)("div",{className:"figma-snapshot-dashboard-item-head",children:[(0,r.jsxs)("div",{className:"figma-snapshot-dashboard-item-title-block",children:[(0,r.jsx)("h3",{className:"figma-snapshot-dashboard-item-title",title:l,children:l}),(0,r.jsx)("span",{className:"figma-snapshot-dashboard-item-date",children:(0,aQ.Yq)(e.fetchedAt)})]}),n&&(0,r.jsx)("span",{className:"figma-snapshot-dashboard-item-badge",children:"Current"}),(0,r.jsxs)("div",{className:"figma-snapshot-dashboard-item-actions",children:[(0,r.jsx)("button",{type:"button",className:"figma-snapshot-dashboard-load",onClick:()=>{tm(e.runId);},disabled:tt,"aria-disabled":tt?"true":void 0,"aria-label":`Load snapshot ${l}`,children:"Load"}),(0,r.jsx)("button",{type:"button",className:"figma-snapshot-dashboard-icon-btn",onClick:()=>tM(e),disabled:s,"aria-label":`Rename snapshot ${l}`,title:"Rename",children:(0,r.jsx)($.F.edit,{"aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button",className:"figma-snapshot-dashboard-icon-btn",onClick:()=>tq(e.runId),"aria-expanded":o,"aria-label":`${o?"Hide":"Show"} metadata for snapshot ${l}`,title:"Metadata",children:(0,r.jsx)($.F.info,{"aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button",className:"figma-snapshot-dashboard-icon-btn figma-snapshot-dashboard-icon-btn-danger",onClick:()=>tz(e.runId),disabled:s,"aria-label":`Delete snapshot ${l}`,title:"Delete",children:(0,r.jsx)($.F.trash,{"aria-hidden":"true"})})]})]}),(0,r.jsx)("p",{className:"figma-snapshot-dashboard-item-hint",children:e.reductionHint}),(0,r.jsxs)("p",{className:"figma-snapshot-dashboard-item-meta",children:[e.screenCount.toString()," screen",1!==e.screenCount?"s":"",e.skippedCount>0?`, ${e.skippedCount.toString()} skipped`:", no skipped renders"]}),i&&(0,r.jsxs)("p",{className:"figma-snapshot-dashboard-item-scope",children:[e.fileKey," \xb7 ",e.nodeId]}),c?(0,r.jsxs)("form",{className:"figma-snapshot-dashboard-rename",onSubmit:t=>{t.preventDefault(),tL(e.runId);},children:[(0,r.jsx)("input",{type:"text",className:"figma-snapshot-dashboard-rename-input",value:ec,onChange:e=>ed(e.target.value),maxLength:120,disabled:s,"aria-label":`Snapshot name for ${l}`,placeholder:"Snapshot name"}),(0,r.jsx)("button",{type:"submit",className:"figma-snapshot-dashboard-rename-save",disabled:s,"aria-busy":s,children:"Save"}),(0,r.jsx)("button",{type:"button",className:"figma-snapshot-dashboard-rename-cancel",onClick:tP,disabled:s,children:"Cancel"})]}):null,d?(0,r.jsxs)("div",{className:"figma-snapshot-dashboard-delete-confirm",children:[(0,r.jsx)("span",{children:"Delete this snapshot?"}),(0,r.jsx)("button",{type:"button",className:"figma-snapshot-dashboard-delete-confirm-btn",onClick:()=>tO(e.runId),disabled:s,"aria-busy":s,children:"Delete"}),(0,r.jsx)("button",{type:"button",className:"figma-snapshot-dashboard-delete-cancel-btn",onClick:()=>eh(null),disabled:s,children:"Cancel"})]}):null,o?(0,r.jsxs)("dl",{className:"figma-snapshot-dashboard-details",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:"Run"}),(0,r.jsx)("dd",{children:e.runId})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:"Version"}),(0,r.jsx)("dd",{children:pZ(e.version)})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:"Integrity"}),(0,r.jsx)("dd",{title:e.integrityHash,children:pQ(e.integrityHash)})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:"Structural"}),(0,r.jsx)("dd",{children:(null!=(t=e.structuralOnlyCount)?t:0).toString()})]}),void 0!==a.updatedAt?(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:"Name updated"}),(0,r.jsx)("dd",{children:(0,aQ.Yq)(a.updatedAt)})]}):null]}):null]},e.runId);})});if(tr){let e=null!=g?g:f.join(", "),t=void 0!==ts&&(null!=(s=null==L?void 0:L.runId)?s:h)!==void 0&&"loading"!==ez;return(0,r.jsxs)("section",{className:"figma-snapshot-window figma-view-window","aria-label":`Figma view source ${e}`,children:[(0,r.jsxs)("div",{className:"figma-view-source-header",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"figma-view-source-eyebrow",children:"Figma view"}),(0,r.jsx)("h1",{className:"figma-view-source-heading",title:e,children:e})]}),(0,r.jsxs)("div",{className:"figma-view-source-actions",children:[(0,r.jsx)("span",{className:"figma-view-source-badge",children:"QI source"}),(0,r.jsx)("button",{type:"button",className:"figma-view-json-btn",onClick:tx,disabled:!t,"aria-disabled":t?void 0:"true","aria-busy":"loading"===ez?"true":void 0,children:"loading"===ez?"Loading JSON…":"Inspect JSON"})]})]}),(0,r.jsxs)("div",{id:E,role:"status","aria-live":"polite","aria-atomic":"true",className:"figma-snapshot-status",children:[te&&(0,r.jsx)("p",{className:"figma-snapshot-progress",children:"Loading view preview…"}),"error"===M&&null!==z&&(0,r.jsx)("p",{className:"figma-snapshot-error",children:z.detail}),"done"===M&&null!==L&&(0,r.jsxs)("p",{className:"sr-only",children:["Figma view loaded — ",e,"."]})]}),null===L?(0,r.jsxs)("div",{className:"figma-view-source-empty",children:[(0,r.jsx)("p",{className:"figma-view-source-empty-title",children:te?"Loading the selected view…":"Selected view preview not loaded."}),!te&&(0,r.jsx)("button",{type:"button",className:"figma-snapshot-load-btn",onClick:tT,children:"Load view"})]}):ti.length>0?ti.map(e=>{let t="rendered"===e.kind?pB(L.runId,e.imageIndex):void 0,n=void 0===t?void 0:{snapshotRunId:L.runId,screenId:e.screen.screenId,name:e.screen.name,imageSrc:t,...(void 0!==p?{sourceWindowId:p}:{})};return(0,r.jsx)(ml,{name:e.screen.name,screenId:e.screen.screenId,irSummary:e.screen.irSummary,imageSrc:t,imageByteLength:"rendered"===e.kind?e.screen.imageByteLength:void 0,structuralReason:"structural"===e.kind?e.screen.reason:void 0,snapshotRunId:L.runId,capturedAt:(0,aQ.Yq)(L.fetchedAt),imageDragPayload:n},e.screen.screenId);}):(0,r.jsx)("div",{className:"lk-empty",children:(0,r.jsx)("p",{className:"lk-empty-body",children:"The selected screen is not present in this stored snapshot."})}),"error"===ez&&null!==eK?(0,r.jsx)("p",{className:"figma-snapshot-error",role:"alert",children:eK}):null,"done"===ez&&null!==eB?(0,r.jsxs)("section",{className:"figma-view-json-inspector","aria-label":`Scoped JSON for ${eB.screen.name}`,children:[(0,r.jsxs)("div",{className:"figma-view-json-inspector-header",children:[(0,r.jsxs)("div",{className:"figma-view-json-drag-surface",role:"button",tabIndex:null!==tj?0:-1,draggable:!1,onDragStart:tk,onDragEnd:tN,onKeyDown:tS,onPointerDown:tC,onPointerMove:tR,onPointerUp:tI,onPointerCancel:tE,onMouseDown:t$,"aria-label":`Create a standalone JSON source for ${eB.screen.name}`,"aria-disabled":null===tj?"true":void 0,title:`Drag JSON for ${eB.screen.name} to the workspace`,children:[(0,r.jsx)("p",{className:"figma-view-json-kicker",children:"Stored Screen-IR JSON"}),(0,r.jsx)("h2",{className:"figma-view-json-title",children:eB.screen.screenId}),(0,r.jsxs)("p",{className:"figma-view-json-meta",children:[eB.screen.kind," \xb7 ",(0,aQ.z3)(tc)," \xb7"," ",eB.relatedLinks.length.toString()," related link",1!==eB.relatedLinks.length?"s":""]})]}),(0,r.jsx)("button",{type:"button",className:"figma-view-json-copy-btn",onClick:tw,children:"Copy JSON"})]}),null!==eV?(0,r.jsx)("p",{className:"figma-view-json-copy-status",role:"status",children:eV}):null,(0,r.jsx)(p_,{text:to,className:"figma-view-json-code"})]}):null]});}return(0,r.jsxs)("section",{className:"figma-snapshot-window","aria-label":"Figma Snapshot",children:[(0,r.jsxs)("form",{className:"figma-snapshot-form",onSubmit:tf,noValidate:!0,children:[(0,r.jsx)("label",{className:"figma-snapshot-label",htmlFor:I,children:"Board link"}),(0,r.jsxs)("div",{className:"figma-snapshot-input-row",children:[(0,r.jsx)("input",{id:I,type:"url",className:"figma-snapshot-input",placeholder:"https://www.figma.com/design/…?node-id=…",value:F,onChange:e=>{D(e.target.value),null!==z&&O(null),"error"===M&&P("idle"),null!==B&&W(null),ew&&ej(!1);},"aria-describedby":null!==e6?`${A} ${E}`:E,"aria-invalid":null!==e6?"true":void 0,readOnly:tt,autoComplete:"off",spellCheck:!1}),(0,r.jsx)("button",{type:"submit",className:"figma-snapshot-trigger-btn",disabled:!e3&&!tt,"aria-disabled":!e3||tt?"true":void 0,"aria-busy":e7,children:e7?"Building…":"Snapshot"})]}),null!==e6&&(0,r.jsx)("p",{id:A,className:"figma-snapshot-link-error",role:"alert",children:e6}),(0,r.jsxs)("label",{className:"figma-snapshot-consent",children:[(0,r.jsx)("input",{type:"checkbox",className:"figma-snapshot-consent-checkbox",ref:ek,checked:ey,"aria-invalid":ew?"true":void 0,onChange:e=>{ex(e.target.checked),null!==z&&O(null),"error"===M&&P("idle"),ej(!1);},disabled:e7}),(0,r.jsxs)("span",{children:["I acknowledge the configured Figma PAT is read-only and least-privilege (",(0,r.jsx)("code",{children:"file_content:read"}),")."," ",(0,r.jsx)("span",{className:"figma-snapshot-consent-required",children:"Required before the first snapshot of a board."})]})]}),(0,r.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."})]}),"error"===M&&null!==z&&!0===z.assertive&&(0,r.jsxs)("div",{className:"figma-snapshot-error-card",role:"alert","aria-labelledby":`${E}-error-title`,children:[(0,r.jsx)("p",{id:`${E}-error-title`,className:"figma-snapshot-error-title",children:z.title}),(0,r.jsx)("p",{className:"figma-snapshot-error-detail",children:z.detail}),void 0!==z.status&&(0,r.jsx)("p",{className:"figma-snapshot-error-status",children:z.status}),void 0!==z.remediation&&(0,r.jsx)("p",{className:"figma-snapshot-error-remediation",children:z.remediation}),!0===z.tokenConfig&&void 0!==b&&(0,r.jsx)("button",{type:"button",className:"figma-snapshot-error-action",onClick:b,children:"Open Figma access token settings"})]}),(0,r.jsxs)("div",{id:E,role:"status","aria-live":"polite","aria-atomic":"true",className:"figma-snapshot-status",children:[e7&&(0,r.jsxs)("p",{className:"figma-snapshot-progress",children:["Building snapshot — fetching screens from Figma…"," ",null!==tn?`${tn} elapsed.`:""," Large boards can take several minutes."]}),te&&(0,r.jsx)("p",{className:"figma-snapshot-progress",children:"Loading stored snapshot…"}),"done"===M&&null!==L&&(0,r.jsxs)("p",{className:"sr-only",children:["Snapshot complete — ",L.reductionHint,"."]}),"done"===eF&&null!==eM&&(0,r.jsxs)("p",{className:"sr-only",children:["Code generated — ",String(eM.fileCount)," file",1!==eM.fileCount?"s":""," ready for review."]}),"idle"===M&&(0,r.jsx)("p",{className:"sr-only","aria-live":"polite"}),"error"===M&&null!==z&&!0!==z.assertive&&(0,r.jsx)("p",{className:"figma-snapshot-error",children:z.detail})]}),e7&&(0,r.jsxs)("div",{className:"figma-snapshot-cancel-row",children:[(0,r.jsx)("button",{type:"button",className:"figma-snapshot-cancel-btn",onClick:tv,children:"Cancel"}),(0,r.jsx)("p",{className:"figma-snapshot-cancel-note",role:"status","aria-live":"polite",children:"Cancelling stops this window from waiting — the server-side build continues on demand."})]}),null!==B&&!tt&&(0,r.jsxs)("div",{className:"figma-snapshot-stored-notice",children:[(0,r.jsx)("p",{className:"figma-snapshot-stored-text",children:"This window is no longer waiting. The server may still be building the snapshot in the background. You can close this window safely."}),(0,r.jsx)("button",{type:"button",className:"figma-snapshot-load-btn",onClick:tb,children:"Reconnect build"})]}),"idle"===M&&null===L&&null===B&&!tB&&(0,r.jsxs)("div",{className:"figma-snapshot-empty",children:[(0,r.jsx)("p",{className:"figma-snapshot-empty-title",children:"Capture screens from a Figma board"}),(0,r.jsxs)("ol",{className:"figma-snapshot-empty-steps",children:[(0,r.jsx)("li",{children:"In Figma, select the frame or section you want to capture."}),(0,r.jsx)("li",{children:"Copy its link (Copy link to selection) — it contains the node-id."}),(0,r.jsx)("li",{children:"Paste it above, acknowledge the read-only scope, then take the snapshot."})]}),(0,r.jsx)("p",{className:"figma-snapshot-empty-note",children:"The snapshot stores the captured screens and their structure as immutable evidence — connect this window to Quality Intelligence to ground generated tests in the design. Requires a Figma access token configured on the server."})]}),tB&&(0,r.jsxs)("div",{className:"figma-snapshot-stored-notice",children:[(0,r.jsx)("p",{className:"figma-snapshot-stored-text",children:"A stored snapshot is available."}),(0,r.jsx)("button",{type:"button",className:"figma-snapshot-load-btn",onClick:tT,"aria-disabled":te?"true":void 0,"aria-busy":te,children:te?"Loading…":"Load snapshot"})]}),(0,r.jsxs)("section",{className:"figma-snapshot-dashboard","aria-label":"Snapshot dashboard",children:[(0,r.jsxs)("div",{className:"figma-snapshot-dashboard-header",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"figma-snapshot-dashboard-eyebrow",children:"Snapshot dashboard"}),(0,r.jsx)("h2",{className:"figma-snapshot-dashboard-title",children:"Stored snapshots"})]}),(0,r.jsx)("button",{type:"button",className:"figma-snapshot-dashboard-refresh",onClick:tp,children:"Refresh"})]}),(0,r.jsxs)("div",{className:"figma-snapshot-dashboard-tabs",role:"tablist","aria-label":"Snapshot views",children:[(0,r.jsx)("button",{type:"button",className:"figma-snapshot-dashboard-tab",role:"tab","aria-selected":"board"===_,"aria-controls":`${T}-board-panel`,id:`${T}-board-tab`,onClick:()=>{null!==e5&&G("board");},disabled:null===e5,children:"This board"}),(0,r.jsx)("button",{type:"button",className:"figma-snapshot-dashboard-tab",role:"tab","aria-selected":"recent"===_,"aria-controls":`${T}-recent-panel`,id:`${T}-recent-tab`,onClick:()=>{G("recent");},children:"Recent"})]}),null!==ev?(0,r.jsx)("p",{className:"figma-snapshot-dashboard-status figma-snapshot-dashboard-status-error",role:"alert",children:ev}):null,"board"===_?(0,r.jsx)("div",{id:`${T}-board-panel`,className:"figma-snapshot-dashboard-panel",role:"tabpanel","aria-labelledby":`${T}-board-tab`,children:null===e5?tW([],!1,null,"No board selected yet","Paste a valid Figma board link or load a stored snapshot to see this board's history.",!1):tW(J,Q,el,"No snapshots stored for this board","Take the first snapshot for this board to make it available here.",!1)}):(0,r.jsx)("div",{id:`${T}-recent-panel`,className:"figma-snapshot-dashboard-panel",role:"tabpanel","aria-labelledby":`${T}-recent-tab`,children:tW(X,et,er,"No snapshots stored yet","Stored Figma snapshots will appear here once the first board capture completes.",!0)})]}),null!==L&&(0,r.jsxs)("div",{className:"figma-snapshot-result",children:[(0,r.jsxs)("div",{className:"figma-snapshot-reduction",children:[(0,r.jsxs)("div",{className:"figma-snapshot-result-head",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("h2",{className:"figma-snapshot-result-title",title:pX(L),children:pX(L)}),(0,r.jsx)("p",{className:"figma-snapshot-result-run",children:L.runId})]}),(0,r.jsx)("span",{className:"figma-snapshot-result-hash",title:L.integrityHash,children:pQ(L.integrityHash)})]}),(0,r.jsx)("p",{className:"figma-snapshot-reduction-hint",children:L.reductionHint}),(0,r.jsxs)("p",{className:"figma-snapshot-captured-at",children:["Captured ",(0,aQ.Yq)(L.fetchedAt)]}),(0,r.jsxs)("dl",{className:"figma-snapshot-result-metadata",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:"File"}),(0,r.jsx)("dd",{children:L.fileKey})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:"Node"}),(0,r.jsx)("dd",{children:L.nodeId})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:"Version"}),(0,r.jsx)("dd",{children:pZ(L.version)})]}),void 0!==tu.updatedAt?(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:"Name updated"}),(0,r.jsx)("dd",{children:(0,aQ.Yq)(tu.updatedAt)})]}):null]}),ta&&(0,r.jsxs)("p",{className:"figma-snapshot-scope-note",children:["QI source scope: ",null!=g?g:f.join(", ")]}),L.skippedCount>0&&(0,r.jsxs)("p",{className:"figma-snapshot-skipped-notice",children:[String(L.skippedCount)," screen",1!==L.skippedCount?"s":""," could not be rendered and were skipped."]})]}),(0,r.jsx)("button",{type:"button",className:"figma-snapshot-resnapshot-btn",onClick:tg,"aria-disabled":tt?"true":void 0,"aria-busy":e7,"aria-label":"Re-snapshot this board",children:e7?"Building…":"Re-snapshot"}),(0,r.jsxs)("div",{className:"figma-snapshot-codegen",children:[(0,r.jsxs)("div",{className:"figma-snapshot-codegen-actions",children:[(0,r.jsx)("button",{type:"button",className:"figma-snapshot-codegen-btn",onClick:ty,"aria-disabled":"generating"===eF?"true":void 0,"aria-busy":"generating"===eF,children:"generating"===eF?"Generating code…":"Generate code"}),"generating"===eF&&(0,r.jsx)("button",{type:"button",className:"figma-snapshot-codegen-cancel-btn",onClick:tA,children:"Cancel"})]}),"error"===eF&&null!==eL&&(0,r.jsx)("p",{className:"figma-snapshot-error",role:"alert",children:eL}),"done"===eF&&null!==eM&&(0,r.jsxs)("div",{className:"figma-snapshot-code-result",children:[(0,r.jsxs)("p",{className:"figma-snapshot-code-summary",children:[String(eM.fileCount)," reviewable file",1!==eM.fileCount?"s":""," (",String(eM.screenCount)," screen",1!==eM.screenCount?"s":"",","," ",eM.adapterName,") — proposal only, never auto-applied."]}),eM.files.map(e=>(0,r.jsxs)("details",{className:"figma-snapshot-code-file",children:[(0,r.jsx)("summary",{className:"figma-snapshot-code-file-path",children:e.path}),(0,r.jsx)("pre",{className:"figma-snapshot-code-file-contents",children:(0,r.jsx)("code",{children:e.contents})})]},e.path))]})]}),(0,r.jsxs)("details",{className:"figma-snapshot-scopes",children:[(0,r.jsx)("summary",{className:"figma-snapshot-scopes-summary",children:"Required Figma PAT scopes"}),(0,r.jsx)("ul",{className:"figma-snapshot-scopes-list",children:(0,r.jsxs)("li",{children:[(0,r.jsx)("code",{children:"file_content:read"})," — read design file structure, node metadata, and rendered images"]})}),(0,r.jsxs)("p",{className:"figma-snapshot-scopes-note",children:["The token is read server-side from the vault, Keiko config, or"," ",(0,r.jsx)("code",{children:"FIGMA_ACCESS_TOKEN"})," environment variable. This window never holds or transmits the token."]}),(0,r.jsxs)("div",{className:"figma-snapshot-revoke-row",children:[e_?(0,r.jsxs)("span",{className:"figma-snapshot-revoke-confirm",children:[(0,r.jsx)("span",{className:"figma-snapshot-revoke-confirm-label",children:"Really revoke the stored token?"}),(0,r.jsx)("button",{ref:eQ,type:"button",className:"figma-snapshot-revoke-confirm-btn",onClick:tF,children:"Yes, revoke"}),(0,r.jsx)("button",{type:"button",className:"figma-snapshot-revoke-cancel-btn",onClick:tD,children:"Cancel"})]}):(0,r.jsx)("button",{ref:e0,type:"button",className:"figma-snapshot-revoke-btn",onClick:()=>{eG(!0),eY(null),eZ(null);},children:"Revoke stored token"}),(0,r.jsx)("p",{className:"figma-snapshot-revoke-status",role:"status","aria-live":"polite","aria-atomic":"true",children:null!=(l=null!=eJ?eJ:eX)?l:""})]})]}),ti.length>0?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("section",{className:"figma-snapshot-gallery","aria-label":ta?`${String(ti.length)} selected screen${1!==ti.length?"s":""}`:`${String(td)} captured and structural screen${1!==td?"s":""}`,children:ti.slice(0,e1).map((e,t)=>{let n=void 0===v?void 0:()=>v({snapshotRunId:L.runId,screenId:e.screen.screenId,name:e.screen.name}),l={snapshotRunId:L.runId,screenId:e.screen.screenId,name:e.screen.name};return"rendered"===e.kind?(0,r.jsx)(mn,{index:t,screenId:e.screen.screenId,name:e.screen.name,irSummary:e.screen.irSummary,imageSrc:pB(L.runId,e.imageIndex),imageByteLength:e.screen.imageByteLength,onAddSource:n,isSourceSelected:tl.has(e.screen.screenId),dragPayload:l},e.screen.screenId):(0,r.jsx)(mn,{index:t,screenId:e.screen.screenId,name:e.screen.name,irSummary:e.screen.irSummary,structuralReason:e.screen.reason,onAddSource:n,isSourceSelected:tl.has(e.screen.screenId),dragPayload:l},e.screen.screenId);})}),e1<ti.length?(0,r.jsx)("button",{type:"button",className:"figma-snapshot-gallery-more",onClick:()=>e2(e=>Math.min(e+24,ti.length)),children:"Show more screens"}):null]}):(0,r.jsx)("div",{className:"lk-empty",children:(0,r.jsx)("p",{className:"lk-empty-body",children:ta?"The selected screen is not present in this stored snapshot.":"No screens were captured from this board section."})})]})]});}function mr(e){var t;let n,{snapshotRunId:l,screenId:a,screenName:s,loadScreenJsonImpl:o=pW}=e,c=(0,i.useRef)(null),[d,u]=(0,i.useState)("idle"),[p,m]=(0,i.useState)(null),[h,f]=(0,i.useState)(null),[g,v]=(0,i.useState)(null),b=void 0!==(n=null==s?void 0:s.trim())&&n.length>0?n:null!=(t=null==a?void 0:a.trim())?t:"Selected Figma view",y=(0,i.useMemo)(()=>null===p?"":JSON.stringify(p,null,2),[p]),x=(0,i.useMemo)(()=>pH(y),[y]),w=(0,i.useCallback)(()=>{var e;if(void 0===l||0===l.trim().length||void 0===a||0===a.trim().length){m(null),u("error"),f("Missing Figma JSON source reference.");return;}null==(e=c.current)||e.abort();let t=new AbortController();c.current=t,u("loading"),f(null),v(null),o(l,a,t.signal).then(e=>{m(e),u("done");}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name||(m(null),f(e instanceof Error?e.message:"Failed to load Figma JSON."),u("error"));}).finally(()=>{c.current===t&&(c.current=null);});},[o,a,l]);(0,i.useEffect)(()=>(w(),()=>{var e;null==(e=c.current)||e.abort(),c.current=null;}),[w]);let j=(0,i.useCallback)(()=>{if(0!==y.length){if(void 0===navigator.clipboard)return void v("Clipboard unavailable");navigator.clipboard.writeText(y).then(()=>v("Copied")).catch(()=>v("Copy failed"));}},[y]);return(0,r.jsxs)("section",{className:"figma-json-window","aria-label":`Figma JSON source ${b}`,children:[(0,r.jsxs)("header",{className:"figma-json-header",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"figma-json-eyebrow",children:"Figma JSON"}),(0,r.jsx)("h1",{className:"figma-json-heading",title:b,children:b}),(0,r.jsx)("p",{className:"figma-json-meta",children:null!==p?`${p.screen.kind} \xb7 ${(0,aQ.z3)(x)} \xb7 captured ${(0,aQ.Yq)(p.fetchedAt)}`:a})]}),(0,r.jsxs)("div",{className:"figma-json-actions",children:[(0,r.jsx)("span",{className:"figma-view-source-badge",children:"QI source"}),(0,r.jsx)("button",{type:"button",className:"figma-view-json-copy-btn",onClick:j,disabled:0===y.length,"aria-disabled":0===y.length?"true":void 0,children:"Copy JSON"})]})]}),"loading"===d?(0,r.jsx)("p",{className:"figma-json-status",role:"status",children:"Loading JSON…"}):null,"error"===d&&null!==h?(0,r.jsxs)("div",{className:"figma-json-error",role:"alert",children:[(0,r.jsx)("p",{children:h}),(0,r.jsx)("button",{type:"button",className:"figma-snapshot-load-btn",onClick:w,children:"Retry"})]}):null,null!==g?(0,r.jsx)("p",{className:"figma-view-json-copy-status",role:"status",children:g}):null,"done"===d&&y.length>0?(0,r.jsx)(p_,{text:y,className:"figma-json-code"}):null]});}function mi(e){let t,{imageSrc:n,screenName:l}=e,a=void 0!==(t=null==l?void 0:l.trim())&&t.length>0?t:"Figma image source";return void 0===n||0===n.trim().length?(0,r.jsx)("section",{className:"figma-image-window","aria-label":a,children:(0,r.jsx)("div",{className:"figma-image-missing",role:"alert",children:"Image preview is unavailable."})}):(0,r.jsx)("section",{className:"figma-image-window","aria-label":a,children:(0,r.jsx)(aY.default,{className:"figma-image-preview",src:n,alt:a,width:720,height:480,unoptimized:!0,priority:!0})});}async function ms(e,t){var n,l;let a=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),r="GET"!==a&&"HEAD"!==a,i=await fetch(e,{...t,headers:{Accept:"application/json",...(r?{"Content-Type":"application/json"}:{}),...(r?{"X-Keiko-CSRF":"1"}:{}),...(null!=(l=null==t?void 0:t.headers)?l:{})}});if(!i.ok){let e="INTERNAL",t=`HTTP ${i.status.toString()}`;try{let n=await i.json();e=n.error.code,t=n.error.message;}catch{}throw new m.hD(e,t,i.status);}return i.json();}async function mo(){return ms("/api/quality-intelligence/runs");}async function mc(e){return ms(`/api/quality-intelligence/runs/${encodeURIComponent(e)}`);}async function md(e){let t="QI_RUN_FAILED",n=`HTTP ${e.status.toString()}`;try{var l,a,r,i;let s=await e.json();t=null!=(l=null==(r=s.error)?void 0:r.code)?l:t,n=null!=(a=null==(i=s.error)?void 0:i.message)?a:n;}catch{}return new m.hD(t,n,e.status);}async function mu(e,t,n){var l,a;let r=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!=(l=r.headers.get("content-type"))?l:"";if(!r.ok||!i.includes("text/event-stream"))throw await md(r);let s=r.body;if(null===s)throw new m.hD("QI_NO_STREAM","The server did not return a progress stream.",r.status);let o=s.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!=(a=t.pop())?a:"",t)){let t=e.trim();if(t.startsWith("data:"))try{n(JSON.parse(t.slice(5).trim()));}catch{}}}}finally{await o.cancel().catch(()=>{}),o.releaseLock();}}async function mp(e){return ms(`/api/quality-intelligence/runs/${encodeURIComponent(e)}`,{method:"DELETE"});}async function mm(e,t,n,l){return ms(`/api/quality-intelligence/runs/${encodeURIComponent(e)}/review`,{method:"POST",body:JSON.stringify({action:t,...(void 0!==n?{candidateId:n}:{}),...(void 0!==l?{reviewerLabel:l}:{})})});}async function mh(e,t,n,l){return(await ms(`/api/quality-intelligence/runs/${encodeURIComponent(e)}/edit`,{method:"POST",body:JSON.stringify({candidateId:t,edited:n,...(void 0!==l?{editorLabel:l}:{})})})).candidate;}async function mf(e,t){return ms(`/api/quality-intelligence/runs/${encodeURIComponent(e)}/re-check`,{method:"POST",body:JSON.stringify({sources:t})});}async function mg(e,t){return ms(`/api/quality-intelligence/runs/${encodeURIComponent(e)}/regenerate-stale`,{method:"POST",body:JSON.stringify({sources:t})});}async function mv(e,t,n){var l,a;return ms(`/api/quality-intelligence/runs/${encodeURIComponent(e)}/export`,{method:"POST",body:JSON.stringify({adapter:t,dryRun:null!=(l=null==n?void 0:n.dryRun)&&l,approvedOnly:null!=(a=null==n?void 0:n.approvedOnly)&&a})});}async function mb(e,t){return ms(`/api/quality-intelligence/runs/${encodeURIComponent(e)}/traceability`,{method:"POST",body:JSON.stringify({format:t})});}var my=n(76308);function mx(e){let{label:t,disabled:n=!1,onStepUp:l,onStepDown:a}=e,i=`Increase ${t}`,s=`Decrease ${t}`;return(0,r.jsxs)("span",{className:"number-control-stepper",children:[(0,r.jsx)("button",{type:"button",className:"number-control-stepper-button number-control-stepper-up","aria-label":i,disabled:n,onPointerDown:e=>{e.preventDefault();},onClick:e=>{e.stopPropagation(),l();}}),(0,r.jsx)("button",{type:"button",className:"number-control-stepper-button number-control-stepper-down","aria-label":s,disabled:n,onPointerDown:e=>{e.preventDefault();},onClick:e=>{e.stopPropagation(),a();}})]});}let mw={open:"Open",approved:"Approved","changes-requested":"Changes requested",rejected:"Rejected",withdrawn:"Withdrawn"},mj={open:"qi-review-open",approved:"qi-review-approved","changes-requested":"qi-review-changes",rejected:"qi-review-rejected",withdrawn:"qi-review-withdrawn"};function mk(e){let{state:t}=e;return(0,r.jsxs)("span",{className:`qi-review-badge ${mj[t]}`,children:[(0,r.jsx)("span",{className:"sr-only",children:"Review: "}),mw[t]]});}function mN(e){if(e instanceof m.hD){var t,n;return t=e.code,n=e.message,`${n} (${t})`;}return e instanceof Error?e.message:"An unexpected error occurred.";}function mS(e){try{return new Date(e).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"});}catch{return e;}}let mC={running:"Running",succeeded:"Succeeded",failed:"Failed",cancelled:"Cancelled"},mR={running:"qi-badge-running",succeeded:"qi-badge-succeeded",failed:"qi-badge-failed",cancelled:"qi-badge-cancelled"};function mI(e){return"running"===e||"succeeded"===e||"failed"===e||"cancelled"===e;}function mE(e){let{status:t}=e,n=mI(t)?mC[t]:t,l=mI(t)?mR[t]:"qi-badge-default";return(0,r.jsx)("span",{className:`qi-badge ${l}`,children:n});}let m$={critical:"qi-sev-critical",high:"qi-sev-high",medium:"qi-sev-medium",low:"qi-sev-low"};function mA(e){let{severity:t}=e,n="critical"===t||"high"===t||"medium"===t||"low"===t?m$[t]:"qi-sev-low";return(0,r.jsxs)("span",{className:`qi-sev ${n}`,children:[(0,r.jsx)("span",{className:"sr-only",children:"Severity: "}),t]});}function mT(e){let{score:t}=e;if(null===t)return(0,r.jsxs)("span",{className:"qi-badge qi-badge-default","data-testid":"qi-quality-badge",children:[(0,r.jsx)("span",{"aria-hidden":"true",children:"—"}),(0,r.jsx)("span",{className:"sr-only",children:"Quality score not available"})]});let n=Math.round(t);return(0,r.jsxs)("span",{className:`qi-badge ${n>=90?"qi-quality-high":n>=70?"qi-quality-mid":"qi-quality-low"}`,"data-testid":"qi-quality-badge",children:[n.toString(),(0,r.jsx)("span",{className:"sr-only",children:" out of 100"})]});}function mF(e){let{flag:t}=e;return(0,r.jsxs)("div",{role:"note","aria-label":`Weak test flagged by the quality judge: ${t.rationale}`,className:"qi-weak-flag","data-testid":"qi-weak-flag",children:[(0,r.jsxs)("span",{className:"qi-weak-flag-badge",children:[(0,r.jsx)("span",{"aria-hidden":"true",className:"qi-weak-flag-icon",children:"⚠"}),"Weak test"]}),(0,r.jsx)("p",{className:"qi-weak-flag-reason",children:t.rationale})]});}let mD={verifiability:"Verifiability",atomicity:"Atomicity",determinism:"Determinism","ac-fidelity":"AC fidelity"};function mM(e){let{verdict:t}=e,n=Math.round(t.score),l="strong"===t.verdict?"Strong":"Weak";return(0,r.jsxs)("div",{role:"note","aria-label":`Quality judge verdict: ${l}, ${n.toString()} out of 100. ${t.overallRationale}`,className:"qi-cand-block","data-testid":"qi-quality-verdict",children:[(0,r.jsx)("p",{className:"qi-cand-block-label",children:"Quality verdict"}),(0,r.jsxs)("p",{children:[l," - ",n.toString(),"/100"]}),(0,r.jsx)("ul",{className:"qi-cand-list","aria-label":"Quality dimensions",children:t.dimensions.map(e=>{var t;return(0,r.jsxs)("li",{children:[null!=(t=mD[e.name])?t:e.name," ",Math.round(e.score).toString(),": ",e.rationale]},e.name);})})]});}function mP(e){let{height:t=20,width:n="100%"}=e;return(0,r.jsx)("div",{"aria-hidden":"true",className:"qi-skeleton",style:{height:t,width:n}});}function mL(){return(0,r.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,r.jsxs)("div",{className:"qi-skeleton-row",children:[(0,r.jsx)(mP,{height:14,width:"60%"}),(0,r.jsx)(mP,{height:12,width:"40%"})]},e))});}function mq(e){let{message:t,onRetry:n}=e;return(0,r.jsxs)("div",{role:"alert","aria-live":"assertive",className:"lk-alert","data-testid":"qi-error-state",children:[t,(0,r.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:n,children:"Retry"})]});}let mz=[{id:"regression-default",label:"Regression (default)"},{id:"banking-default",label:"Banking"},{id:"insurance-default",label:"Insurance"}],mO=[{id:"requirements",label:"Requirements",hint:"Paste text"},{id:"workspace",label:"Folder",hint:"Browse local"},{id:"file",label:"File",hint:"Browse local"},{id:"capsule",label:"Capsule",hint:"Local Knowledge"},{id:"capsule-set",label:"Capsule set",hint:"Local Knowledge"}];function mB(e){let{kind:t}=e;return"requirements"===t?(0,r.jsx)($.F.review,{size:15}):"workspace"===t?(0,r.jsx)($.F.folder,{size:15}):"file"===t?(0,r.jsx)($.F.file,{size:15}):"capsule-set"===t?(0,r.jsx)($.F.layers,{size:15}):(0,r.jsx)("svg",{"aria-hidden":"true",className:"qi-source-kind-icon-svg",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{d:"M12 3.8 19 7.7v8.6L12 20.2 5 16.3V7.7z"})});}let mW={phase:"Starting…",stageName:null,candidates:0,findings:0,atomCount:null,droppedSourceCount:0,skippedSources:[]},mK="Der Lauf wurde nicht erfolgreich abgeschlossen. Passe die Quelle an und versuche es erneut.";function mU(e){switch(e.code){case"QI_IMAGE_DESCRIPTION_UNAVAILABLE":return`${e.label} (image was readable, but the image model produced no usable description)`;case"QI_IMAGE_UNAVAILABLE":return`${e.label} (stored image could not be found or read)`;case"QI_FIGMA_SNAPSHOT_UNAVAILABLE":return`${e.label} (stored Figma snapshot could not be found or read)`;case"QI_SOURCE_EMPTY":return`${e.label} (source produced no usable evidence)`;case"QI_SOURCE_DENIED":return`${e.label} (source is in a protected location)`;case"QI_SOURCE_TOO_LARGE":return`${e.label} (source is too large for this run)`;case"QI_SOURCE_UNSUPPORTED":return`${e.label} (source format is not supported)`;case"QI_WORKSPACE_NOT_FOUND":return`${e.label} (workspace path could not be read)`;case"QI_CAPSULE_UNAVAILABLE":return`${e.label} (knowledge source is unavailable)`;default:return`${e.label} (could not be read)`;}}function mV(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 e.label.startsWith("JSON \xb7")?"Figma JSON":"Figma snapshot";case"image":return"Image";}}function mH(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 void 0!==e.screenIds&&e.screenIds.length>0?`${e.snapshotRunId}#${e.screenIds.join(",")}`:e.snapshotRunId;case"image":return`${e.snapshotRunId}#${e.screenId}`;}}function m_(e){let{onRunCompleted:t,startImpl:n=mu,fetchCapsulesImpl:l=sb.xr,fetchCapsuleSetsImpl:a=sb.R3,fetchProjectsImpl:s=m.vj,fetchFilesTreeImpl:o=m.KD,connectedRoot:c=null,connectedFilePath:d=null,connectedRoots:u,connectedCapsuleIds:p,connectedCapsuleSetIds:h,connectedFigmaSnapshotRunIds:f,connectedFigmaSnapshotSources:g,connectedImageSources:v}=e,[b,y]=(0,i.useState)(""),[x,w]=(0,i.useState)("requirements"),[j,k]=(0,i.useState)(""),[N,S]=(0,i.useState)(""),[C,R]=(0,i.useState)(""),[I,E]=(0,i.useState)(""),[$,A]=(0,i.useState)(!1),[T,F]=(0,i.useState)([]),[D,M]=(0,i.useState)([]),[P,L]=(0,i.useState)(!1),[q,z]=(0,i.useState)(null),[O,B]=(0,i.useState)("regression-default"),[W,K]=(0,i.useState)(""),[U,V]=(0,i.useState)(!1),[H,_]=(0,i.useState)(mW),[G,J]=(0,i.useState)(null),[Y,X]=(0,i.useState)(null),Z=(0,i.useRef)(null),Q=(0,i.useRef)(null),ee=(0,i.useRef)(null),et=(0,i.useRef)(!1),en=ov({connectedRoot:c,connectedFilePath:d,connectedRoots:u,connectedCapsuleIds:p,connectedCapsuleSetIds:h,connectedFigmaSnapshotRunIds:f,connectedFigmaSnapshotSources:g,connectedImageSources:v}),el=en.length>0,ea=T.find(e=>e.id===C),er=D.find(e=>e.id===I),ei=N.trim().length>0,es="requirements"===x?j.trim().length>0:"workspace"===x||"file"===x?ei:"capsule"===x?C.trim().length>0:I.trim().length>0,eo="requirements"===x?0===j.trim().length:("workspace"===x||"file"===x)&&!ei,ec=es||eo&&el,ed=W.trim(),eu=0===ed.length?void 0:/^\d+$/u.test(ed)?Number(ed):NaN,ep=void 0===eu||Number.isSafeInteger(eu)&&Number.isFinite(eu),em=e=>{let t=Number.parseInt(W.trim(),10);K(String(Math.max(0,(Number.isFinite(t)?t:0)+e))),J(null);},eh=!ec||!ep,ef=(0,i.useId)(),eg=(0,i.useId)(),ev=(0,i.useId)(),eb=(0,i.useId)(),ey=(0,i.useId)(),ex=ec?ep?void 0:eg:ef,ew="workspace"===x||"file"===x?x:null,ej=(0,i.useCallback)(e=>{w(e),A(!1),J(null),z(null);},[]),ek=(0,i.useCallback)((e,t)=>{U||0!==e.button||ej(t);},[ej,U]),eN=(0,i.useCallback)(e=>{var t,n;if(U)return;let l="ArrowRight"===e.key||"ArrowDown"===e.key?1:"ArrowLeft"===e.key||"ArrowUp"===e.key?-1:0;if(0===l)return;e.preventDefault();let a=mO.length,r=(Math.max(0,mO.findIndex(e=>e.id===x))+l+a)%a,i=mO[r];void 0!==i&&(ej(i.id),null==(n=e.currentTarget.parentElement)||null==(t=n.querySelectorAll('[role="radio"]')[r])||t.focus());},[ej,U,x]),eS=(0,i.useCallback)(e=>{var t,n,l,a,r;"event"===e.type&&("stage:failed"===e.kind||"run:failed"===e.kind)&&"string"==typeof e.reasonSummary&&(ee.current=e.reasonSummary),"done"===e.type&&("succeeded"===e.status?(Q.current=e.runId,!0===e.degraded&&X(function(e){let t="Die Modellgenerierung ist fehlgeschlagen — Keiko hat deterministische Baseline-Testf\xe4lle aus der Evidenz erstellt. Diese sind nicht modellgest\xfctzt; pr\xfcfe das Modell-Gateway und starte den Lauf f\xfcr modellgest\xfctzte Testf\xe4lle erneut.";if(null==e||0===e.trim().length)return t;if("qi-error: UnparseableModelOutputError"===e)return`${t} (Modellausgabe nicht als JSON parsebar)`;if("qi-error: QI_PROMPT_TOO_LARGE"===e)return`${t} (Quellkontext f\xfcr das Modell zu gro\xdf)`;let n=e.startsWith("qi-error: ")?e.slice(10):e.startsWith("qi-safe-error: ")?e.slice(15):e;return`${t} (${n})`;}(null!=(t=e.reasonSummary)?t:null))):"failed"===e.status&&J(null==(l=null!=(n=e.reasonSummary)?n:ee.current)||0===l.trim().length?mK:"qi-run-error"===l?"Die Modellgenerierung ist fehlgeschlagen, bevor nutzbare Testf\xe4lle zur\xfcckgegeben wurden. Versuche es mit einer kleineren Quelle oder pr\xfcfe das ausgew\xe4hlte Modell-Gateway.":"qi-error: UnparseableModelOutputError"===l?"Das Modell hat eine Ausgabe geliefert, die nicht zu Testf\xe4llen geparst werden konnte. Versuche es erneut oder nutze ein Modell mit strukturierter JSON-Ausgabe.":"qi-error: QI_PROMPT_TOO_LARGE"===l?"Der zusammengestellte Quellkontext ist f\xfcr das Modell zu gro\xdf. Reduziere die Quelle und versuche es erneut.":l.startsWith("qi-error: ")?`${mK} (${l.slice(10)})`:l.startsWith("qi-safe-error: ")?`${mK} (${l.slice(15)})`:`${mK} (${l})`)),"error"===e.type&&J((a=e.code,r=e.message,`${r} (${a})`)),_(t=>function(e,t){var n,l,a;if("accepted"===t.type)return{...e,phase:"Ingested sources",atomCount:t.atomCount,droppedSourceCount:null!=(n=t.droppedSourceCount)?n:0,skippedSources:null!=(l=t.skippedSources)?l:[]};if("event"===t.type){let n="candidate:proposed"===t.kind?e.candidates+1:e.candidates,l="finding:recorded"===t.kind?e.findings+1:e.findings,r=null!=(a=t.stageName)?a:e.stageName;return{...e,phase:t.kind,stageName:r,candidates:n,findings:l};}return e;}(t,e));},[]),eC="capsule"===x||"capsule-set"===x;(0,i.useEffect)(()=>{if(!eC)return;let e=!1;return async function(){L(!0),z(null);try{let[t,n]=await Promise.allSettled([l(),a()]);if(e)return;"fulfilled"===t.status?F(t.value.capsules.filter(e=>"ready"===e.lifecycleState)):(F([]),"capsule"===x&&z(mN(t.reason))),"fulfilled"===n.status?M(n.value.capsuleSets):(M([]),"capsule-set"===x&&z(mN(n.reason)));}finally{e||L(!1);}}(),()=>{e=!0;};},[l,a,eC,x]),(0,i.useEffect)(()=>{var e,t,n,l;if("capsule"===x){let n=T.some(e=>e.id===C)?C:null!=(e=null==(t=T[0])?void 0:t.id)?e:"";n!==C&&R(n);}if("capsule-set"===x){let e=D.some(e=>e.id===I)?I:null!=(n=null==(l=D[0])?void 0:l.id)?n:"";e!==I&&E(e);}},[C,I,D,T,x]);let eR=(0,i.useCallback)(()=>{let e=b.trim();return"requirements"===x&&j.trim().length>0?[{kind:"requirements",label:e||"Requirements",text:j}]:"workspace"===x&&N.trim().length>0?[{kind:"workspace",label:e||"Folder",path:N.trim()}]:"file"===x&&N.trim().length>0?[{kind:"file",label:e||"File",path:N.trim()}]:"capsule"===x&&C.trim().length>0?[{kind:"capsule",label:e||(null==ea?void 0:ea.displayName)||"Knowledge capsule",capsuleId:C.trim()}]:"capsule-set"===x&&I.trim().length>0?[{kind:"capsule-set",label:e||(null==er?void 0:er.displayName)||"Capsule set",capsuleSetId:I.trim()}]:null;},[C,I,b,N,ea,er,x,j]),eI=(0,i.useCallback)(async()=>{var e;if(!ec||U||!ep||et.current)return;et.current=!0,V(!0),J(null),X(null),_(mW),Q.current=null,ee.current=null;let l=new AbortController();Z.current=l;let a=null!=(e=eR())?e:en,r={sources:a,profileId:O,...(void 0!==eu?{seed:eu}:{})};try{await n(r,l.signal,eS);let e=Q.current;null!==e&&(null==t||t(e,a.filter(e=>"requirements"!==e.kind)));}catch(e){l.signal.aborted||J(mN(e));}finally{V(!1),Z.current=null,et.current=!1;}},[ec,O,U,en,eR,eS,t,eu,ep,n]),eE=(0,i.useCallback)(()=>{var e;null==(e=Z.current)||e.abort();},[]),e$=H.droppedSourceCount>0?`${H.droppedSourceCount.toString()} source${1!==H.droppedSourceCount?"s":""} over the 16-source limit ${1!==H.droppedSourceCount?"were":"was"} not included.`:null,eA=function(e){if(0===e.length)return null;let t=e.length.toString(),n=1!==e.length?"sources were":"source was";return`${t} connected ${n} skipped: ${e.map(mU).join(", ")}.`;}(H.skippedSources),eT=[e$,eA].filter(e=>null!==e).join(" ");return(0,r.jsxs)("section",{className:"qi-launcher","aria-label":"Start a Quality Intelligence run",children:[(0,r.jsx)("header",{className:"qi-col-header",children:(0,r.jsx)("h2",{className:"qi-col-title",children:"New run"})}),(0,r.jsxs)("div",{className:"qi-launcher-body",children:[1===en.length&&void 0!==en[0]?(0,r.jsxs)("div",{className:"qi-connected-source","data-testid":"qi-connected-source",children:[(0,r.jsxs)("span",{className:"qi-connected-kind",children:["Connected ",mV(en[0]).toLowerCase()]}),(0,r.jsx)("span",{className:"qi-connected-path qi-monospace",title:mH(en[0]),children:mH(en[0])}),(0,r.jsx)("span",{className:"qi-connected-hint",children:es?"Manual input below overrides the connected source for this run.":`Generate uses the connected ${mV(en[0]).toLowerCase()}.`})]}):en.length>1?(0,r.jsxs)("div",{className:"qi-connected-source","data-testid":"qi-connected-source",children:[(0,r.jsxs)("span",{className:"qi-connected-kind",children:["Connected sources (",en.length.toString(),")"]}),(0,r.jsx)("ul",{className:"qi-connected-roots","aria-label":"Connected sources",children:en.map(e=>(0,r.jsxs)("li",{className:"qi-connected-root-item",children:[(0,r.jsx)("span",{className:"qi-connected-root-name",children:mV(e)}),(0,r.jsx)("span",{className:"qi-connected-path qi-monospace",title:mH(e),children:mH(e)})]},`${e.kind}:${mH(e)}`))}),(0,r.jsx)("span",{className:"qi-connected-hint",children:es?"Manual input below overrides the connected sources for this run.":"Generate uses all connected sources."})]}):null,(0,r.jsxs)("div",{className:"qi-launcher-row",children:[(0,r.jsxs)("label",{className:"qi-field",children:[(0,r.jsx)("span",{className:"qi-field-label",children:"Source label"}),(0,r.jsx)("input",{type:"text",className:"qi-input",value:b,placeholder:"e.g. Funds Transfer — acceptance criteria",disabled:U,"aria-describedby":el&&!es?ev:void 0,onChange:e=>{y(e.target.value);}}),el&&!es?(0,r.jsx)("span",{className:"qi-field-hint",id:ev,children:"Applies to manual input only — connected sources use their own labels."}):null]}),(0,r.jsxs)("div",{className:"qi-field qi-field-kind",children:[(0,r.jsx)("span",{className:"qi-field-label",id:eb,children:"Source type"}),(0,r.jsx)("div",{className:"qi-source-kind-grid",role:"radiogroup","aria-labelledby":eb,"aria-disabled":U||void 0,children:mO.map(e=>(0,r.jsxs)("button",{type:"button",className:"qi-source-kind-option",role:"radio","aria-label":e.label,"data-tip":e.label,"aria-checked":x===e.id,tabIndex:x===e.id?0:-1,disabled:U,onPointerDown:t=>{ek(t,e.id);},onClick:()=>ej(e.id),onKeyDown:eN,children:[(0,r.jsx)("span",{className:"qi-source-kind-label",children:e.label}),(0,r.jsx)("span",{className:"qi-source-kind-icon","aria-hidden":"true",children:(0,r.jsx)(mB,{kind:e.id})})]},e.id))})]})]}),function(){if("requirements"===x)return(0,r.jsxs)("label",{className:"qi-field",children:[(0,r.jsx)("span",{className:"qi-field-label",children:"Requirements"}),(0,r.jsx)("textarea",{className:"qi-textarea",value:j,rows:6,placeholder:"Paste requirements or acceptance criteria, one statement per line.",disabled:U,onChange:e=>{k(e.target.value);}})]});if("workspace"===x||"file"===x){let e="file"===x;return(0,r.jsxs)("div",{className:"qi-field",children:[(0,r.jsx)("span",{className:"qi-field-label",id:ey,children:e?"File path":"Folder path"}),(0,r.jsxs)("div",{className:"qi-path-picker",children:[(0,r.jsx)("div",{className:"qi-path-value qi-monospace",role:"textbox","aria-readonly":"true","aria-labelledby":ey,title:N,"data-empty":0===N.trim().length?"true":void 0,children:N.trim().length>0?N:e?"Choose a local file…":"Choose a local folder…"}),(0,r.jsx)("button",{type:"button",className:"qi-btn qi-btn-secondary qi-browse-btn",disabled:U,onClick:()=>A(!0),children:"Browse"})]})]});}let e="capsule"===x,t=e?T:D;return(0,r.jsxs)("label",{className:"qi-field",children:[(0,r.jsx)("span",{className:"qi-field-label",children:e?"Knowledge capsule":"Capsule set"}),(0,r.jsxs)("select",{className:"qi-select",value:e?C:I,disabled:U||P||null!==q||0===t.length,onChange:t=>{e?R(t.target.value):E(t.target.value);},children:[P?(0,r.jsx)("option",{value:"",children:"Loading connectors..."}):null,P||0!==t.length?null:(0,r.jsx)("option",{value:"",children:e?"No ready capsules":"No capsule sets"}),e?T.map(e=>(0,r.jsx)("option",{value:e.id,children:e.displayName},e.id)):D.map(e=>(0,r.jsx)("option",{value:e.id,children:`${e.displayName} (${String(e.capsuleCount)} capsules)`},e.id))]})]});}(),null!==q?(0,r.jsx)("p",{className:"lk-alert",role:"alert","data-testid":"qi-connector-error",children:q}):null,(0,r.jsxs)("div",{className:"qi-launcher-controls",children:[(0,r.jsxs)("div",{className:"qi-field qi-field-inline qi-policy-profile-field",children:[(0,r.jsx)("span",{className:"qi-field-label",children:"Policy profile"}),(0,r.jsx)(ln.A,{triggerClassName:"qi-select",value:O,ariaLabel:"Policy profile",disabled:U,menuTitle:"Policy",menuClassName:"qi-policy-profile-menu",sections:[{options:mz.map(e=>({value:e.id,label:e.label}))}],onValueChange:B})]}),(0,r.jsxs)("label",{className:"qi-field qi-field-inline",children:[(0,r.jsx)("span",{className:"qi-field-label",children:"Seed (optional)"}),(0,r.jsxs)("span",{className:"number-control qi-number-control",children:[(0,r.jsx)("input",{type:"number",min:0,step:1,className:"qi-input number-control-input",value:W,placeholder:"e.g. 42",disabled:U,"aria-invalid":!ep||void 0,"aria-describedby":ep?void 0:eg,onChange:e=>{K(e.target.value),J(null);},onWheel:e=>{U||0===e.deltaY||(e.preventDefault(),em(e.deltaY<0?1:-1));}}),(0,r.jsx)(mx,{label:"seed",disabled:U,onStepUp:()=>em(1),onStepDown:()=>em(-1)})]}),ep?null:(0,r.jsx)("span",{className:"qi-field-error",id:eg,children:"Seed must be a non-negative integer."})]}),(0,r.jsx)("button",{type:"button",className:U?"qi-btn qi-btn-secondary":"qi-btn qi-btn-primary","aria-disabled":!U&&eh||void 0,"aria-describedby":U?void 0:ex,onClick:()=>{U?eE():eh||eI();},children:U?"Cancel":"Generate test cases"}),U||ec?null:(0,r.jsx)("span",{className:"qi-generate-hint",id:ef,children:"Add requirements text, a folder path, a file path, select a capsule, select a capsule set, or connect a source to generate."})]}),U?(0,r.jsxs)("div",{className:"qi-progress","data-testid":"qi-launch-progress","aria-hidden":"true",children:[(0,r.jsx)("span",{className:"qi-progress-spinner","aria-hidden":"true"}),(0,r.jsxs)("span",{className:"qi-progress-text",children:[null!==H.stageName?`Stage: ${H.stageName} \xb7 `:"",H.candidates.toString()," test case",1!==H.candidates?"s":"",H.findings>0?` \xb7 ${H.findings.toString()} finding${1!==H.findings?"s":""}`:""]})]}):null,(0,r.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite","data-testid":"qi-launch-progress-sr",children:function(e,t){if(!e)return"";if(null===t.stageName&&0===t.candidates&&0===t.findings)return"Generating test cases…";let n=null!==t.stageName?`Stage: ${t.stageName}. `:"",l=`${t.candidates.toString()} test case${1!==t.candidates?"s":""}`,a=t.findings>0?`, ${t.findings.toString()} finding${1!==t.findings?"s":""}`:"";return`${n}${l}${a}`;}(U,H)}),(0,r.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite",children:eT}),null!==e$||null!==eA?(0,r.jsxs)("div",{className:"qi-coverage-notice","data-testid":"qi-coverage-notice",children:[null!==e$?(0,r.jsx)("p",{className:"qi-coverage-line",children:e$}):null,null!==eA?(0,r.jsx)("p",{className:"qi-coverage-line",children:eA}):null]}):null,null!==Y?(0,r.jsx)("p",{className:"qi-degraded-notice",role:"status","data-testid":"qi-launch-degraded",children:Y}):null,null!==G?(0,r.jsx)("p",{className:"lk-alert",role:"alert","data-testid":"qi-launch-error",children:G}):null]}),$&&null!==ew?(0,r.jsx)(my.c2,{mode:"file"===ew?"file":"folder",title:`Choose ${"file"===ew?"file":"folder"} source`,description:"Browse a registered local project or enter an absolute folder root.",initialRootPath:"file"===ew?(0,my.pD)(N):N,fetchProjectsImpl:s,fetchFilesTreeImpl:o,onCancel:()=>A(!1),onApply:e=>{var t;S("file"===ew?(0,my.$e)(e.rootPath,null!=(t=e.files[0])?t:null):e.folderPath),A(!1),J(null);}}):null]});}function mG(e){var t;let{run:n,onOpen:l,onDelete:a,deleting:s}=e,o=n.totals.candidates,[c,d]=(0,i.useState)(!1),u=(0,i.useRef)(null),p=(0,i.useRef)(null),m=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(c){var e;null==(e=p.current)||e.focus();}},[c]);let h=(0,i.useCallback)(()=>{d(!1),requestAnimationFrame(()=>{var e;null==(e=u.current)||e.focus();});},[]),f=(0,i.useCallback)(e=>{"Escape"===e.key&&(e.preventDefault(),h());},[h]),g=(0,i.useCallback)(()=>{s||a(n.id);},[s,a,n.id]);return(0,r.jsxs)("li",{style:{display:"flex",alignItems:"stretch"},children:[(0,r.jsxs)("button",{type:"button",className:"qi-run-item",style:{flex:1},onClick:()=>{l(n.id,[]);},"aria-label":`Open run ${n.id} — ${mI(t=n.status)?mC[t]:t}, ${mS(n.requestedAt)}, ${o.toString()} test case${1!==o?"s":""}, review ${mw[n.reviewState]}`,title:`Open run ${n.id}`,children:[(0,r.jsx)("span",{className:"qi-run-title",children:mS(n.requestedAt)}),(0,r.jsx)(mE,{status:n.status}),(0,r.jsx)(mk,{state:n.reviewState}),(0,r.jsxs)("span",{className:"qi-run-id",children:[n.id.slice(0,16),"…"]}),(0,r.jsxs)("span",{className:"qi-run-totals",children:[n.totals.candidates.toString()," test case",1!==n.totals.candidates?"s":""]})]}),c?(0,r.jsxs)("div",{className:"qi-cand-actions",role:"group","aria-label":`Confirm deleting run ${mS(n.requestedAt)}`,style:{display:"flex",alignItems:"center",gap:4,padding:"0 6px",flexShrink:0},children:[(0,r.jsx)("button",{ref:m,type:"button",className:"qi-btn qi-btn-reject",style:{minWidth:0,padding:"4px 10px",fontSize:12,flexShrink:0},"aria-label":`Confirm delete of run ${mS(n.requestedAt)}`,"aria-busy":s||void 0,"aria-disabled":s||void 0,onClick:g,onKeyDown:f,children:s?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{"aria-hidden":"true",children:"Deleting…"}),(0,r.jsx)("span",{className:"sr-only",children:"Deleting run, please wait"})]}):"Confirm delete"}),(0,r.jsx)("button",{ref:p,type:"button",className:"qi-btn qi-btn-secondary",style:{minWidth:0,padding:"4px 10px",fontSize:12,flexShrink:0},"aria-disabled":s||void 0,onClick:()=>{s||h();},onKeyDown:f,children:"Cancel"})]}):(0,r.jsx)("button",{ref:u,type:"button",className:"qi-btn qi-btn-reject",style:{alignSelf:"center",minWidth:0,padding:"4px 10px",fontSize:12,margin:"0 6px 0 0",flexShrink:0},"aria-label":`Delete run ${mS(n.requestedAt)}`,onClick:()=>{d(!0);},children:"Delete"})]});}function mJ(e){let{openRun:t,connectedRoot:n=null,connectedFilePath:l=null,connectedRoots:a,connectedCapsuleIds:s,connectedCapsuleSetIds:o,connectedFigmaSnapshotRunIds:c,connectedFigmaSnapshotSources:d,connectedImageSources:u,fetchRunsImpl:p=mo,deleteImpl:m=mp}=e,[h,f]=(0,i.useState)([]),[g,v]=(0,i.useState)(0),[b,y]=(0,i.useState)(!1),[x,w]=(0,i.useState)(!0),[j,k]=(0,i.useState)(null),[N,S]=(0,i.useState)(25),[C,R]=(0,i.useState)(null),[I,E]=(0,i.useState)(""),$=(0,i.useCallback)(async()=>{w(!0),k(null);try{let e=await p();f(e.runs),v(e.totalRunIds),y(e.truncated);}catch(e){k(mN(e));}finally{w(!1);}},[p]);(0,i.useEffect)(()=>{$();},[$]);let A=(0,i.useCallback)((e,n)=>{$(),t(e,n);},[$,t]),T=(0,i.useCallback)(async e=>{if(null===C){R(e),k(null);try{await m(e),E("Run deleted."),await $();}catch(e){k(mN(e));}finally{R(null);}}},[C,m,$]);return(0,r.jsxs)("div",{className:"qi-hub",children:[(0,r.jsx)(m_,{onRunCompleted:A,connectedRoot:n,connectedFilePath:l,connectedRoots:a,connectedCapsuleIds:s,connectedCapsuleSetIds:o,connectedFigmaSnapshotRunIds:c,connectedFigmaSnapshotSources:d,connectedImageSources:u}),(0,r.jsxs)("section",{className:"qi-hub-runs","aria-label":"Quality Intelligence runs",children:[(0,r.jsxs)("header",{className:"qi-col-header",children:[(0,r.jsx)("h2",{className:"qi-col-title",children:"Runs"}),x||null!==j?null:(0,r.jsx)("span",{className:"qi-col-count",children:g.toString()})]}),(0,r.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite",children:x?"Loading runs…":null===j?`Run list loaded: ${h.length.toString()} run${1===h.length?"":"s"}${b?` of ${g.toString()}`:""}.`:""}),(0,r.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite","aria-atomic":"true",children:I}),(0,r.jsx)("div",{className:"qi-col-body","aria-busy":x,children:x?(0,r.jsx)(mL,{}):null!==j?(0,r.jsx)(mq,{message:j,onRetry:()=>{$();}}):0===h.length?(0,r.jsxs)("div",{className:"lk-empty",children:[(0,r.jsx)("p",{className:"lk-empty-title",children:"No runs yet"}),(0,r.jsx)("p",{className:"lk-empty-body",children:"Start a run above — generated test cases open as cards on your workspace."})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("ul",{className:"qi-run-list","aria-label":"Run list",children:h.slice(0,N).map(e=>(0,r.jsx)(mG,{run:e,onOpen:t,onDelete:e=>{T(e);},deleting:C===e.id},e.id))}),N<h.length?(0,r.jsxs)("button",{type:"button",className:"qi-btn qi-btn-secondary qi-show-more",onClick:()=>{S(e=>e+25);},children:["Show more runs (",(h.length-N).toString()," remaining)"]}):null,b?(0,r.jsx)("p",{className:"qi-runs-truncated","data-testid":"qi-runs-truncated",children:`Showing ${h.length.toString()} of ${g.toString()} runs.`}):null]})})]})]});}let mY=["P0","P1","P2","P3"],mX=["safety","compliance","regression","functional","visual"],mZ=e=>e.split("\n").map(e=>e.trim()).filter(e=>e.length>0),mQ=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]);function m0(e,t){let n=mZ(t.preconditions),l=mZ(t.steps),a=mZ(t.expectedResults),r=t.tags.split(",").map(e=>e.trim()).filter(e=>e.length>0);return{...(t.title!==e.title?{title:t.title}:{}),...(!mQ(n,e.preconditions)?{preconditions:n}:{}),...(!mQ(l,e.steps)?{steps:l}:{}),...(!mQ(a,e.expectedResults)?{expectedResults:a}:{}),...(t.priority!==e.priority?{priority:t.priority}:{}),...(t.riskClass!==e.riskClass?{riskClass:t.riskClass}:{}),...(!mQ(r,e.tags)?{tags:r}:{})};}function m1(e){let{id:t,label:n,value:l,disabled:a=!1,onChange:i}=e;return(0,r.jsxs)("label",{className:"qi-edit-field",htmlFor:t,children:[(0,r.jsx)("span",{className:"qi-edit-label",children:n}),(0,r.jsx)("textarea",{id:t,className:"qi-edit-textarea",value:l,rows:3,disabled:a,onChange:e=>{i(e.target.value);}})]});}function m2(e){let{id:t,label:n,value:l,disabled:a=!1,required:i=!1,onChange:s}=e;return(0,r.jsxs)("label",{className:"qi-edit-field",htmlFor:t,children:[(0,r.jsx)("span",{className:"qi-edit-label","data-required":i?"true":void 0,children:n}),(0,r.jsx)("input",{id:t,className:"qi-edit-input",value:l,disabled:a,required:i,"aria-required":i?"true":void 0,onChange:e=>{s(e.target.value);}})]});}function m4(e){let{id:t,label:n,value:l,options:a,disabled:i=!1,onChange:s}=e;return(0,r.jsxs)("label",{className:"qi-edit-field",htmlFor:t,children:[(0,r.jsx)("span",{className:"qi-edit-label",children:n}),(0,r.jsx)("select",{id:t,className:"qi-edit-select",value:l,disabled:i,onChange:e=>{s(e.target.value);},children:a.map(e=>(0,r.jsx)("option",{value:e,children:e},e))})]});}function m3(e){let{onCancel:t,saving:n}=e;return(0,r.jsxs)("div",{className:"qi-edit-actions",children:[(0,r.jsx)("button",{type:"submit",className:"qi-btn qi-btn-approve qi-edit-save","aria-disabled":n||void 0,children:"Save"}),(0,r.jsx)("button",{type:"button",className:"qi-btn qi-btn-secondary qi-edit-cancel","aria-disabled":n||void 0,onClick:()=>{n||t();},children:"Cancel"})]});}function m6(e){let{candidate:t,onSave:n,onCancel:l}=e,[a,s]=(0,i.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,i.useState)(null),[d,u]=(0,i.useState)(!1),[p,m]=(0,i.useState)(!1),h=(0,i.useRef)(null),f=(e,t)=>{c(null),m(!1),s(n=>({...n,[e]:t}));},g=(0,i.useCallback)(()=>{d||(!(Object.keys(m0(t,a)).length>0)||p?l():m(!0));},[t,p,l,d,a]);(0,i.useEffect)(()=>{let e=e=>{if("Escape"!==e.key||d)return;let t=h.current;null!==t&&t.contains(document.activeElement)&&g();};return document.addEventListener("keydown",e),()=>{document.removeEventListener("keydown",e);};},[g,d]),(0,i.useEffect)(()=>{var e,t;null==(t=h.current)||null==(e=t.querySelector("input.qi-edit-input"))||e.focus();},[]);let v=`qi-edit-${t.id}`,b=async()=>{if(!d){u(!0),c(null);try{await n(m0(t,a));}catch(e){c(mN(e));}finally{u(!1);}}};return(0,r.jsxs)("form",{ref:h,className:"qi-edit-form","aria-label":`Edit ${t.title}`,"aria-busy":d,onSubmit:e=>{e.preventDefault(),b();},children:[(0,r.jsxs)("div",{className:"qi-edit-head",children:[(0,r.jsxs)("div",{className:"qi-edit-head-copy",children:[(0,r.jsx)("p",{className:"qi-edit-eyebrow",children:"Edit test case"}),(0,r.jsx)("h3",{className:"qi-edit-heading",children:t.title})]}),(0,r.jsx)(m3,{onCancel:g,saving:d})]}),null!==o?(0,r.jsx)("p",{className:"qi-edit-error",role:"alert","aria-live":"assertive",children:o}):null,(0,r.jsx)("p",{className:"qi-edit-discard-note",role:"status","aria-live":"polite",children:p?"Unsaved changes — press Escape or activate Cancel again to discard them.":""}),(0,r.jsxs)("div",{className:"qi-edit-layout",children:[(0,r.jsxs)("div",{className:"qi-edit-main",children:[(0,r.jsx)(m2,{id:`${v}-title`,label:"Title",value:a.title,disabled:d,required:!0,onChange:e=>{f("title",e);}}),(0,r.jsx)(m1,{id:`${v}-preconditions`,label:"Preconditions (one per line)",value:a.preconditions,disabled:d,onChange:e=>{f("preconditions",e);}}),(0,r.jsx)(m1,{id:`${v}-steps`,label:"Steps (one per line)",value:a.steps,disabled:d,onChange:e=>{f("steps",e);}}),(0,r.jsx)(m1,{id:`${v}-expected`,label:"Expected results (one per line)",value:a.expectedResults,disabled:d,onChange:e=>{f("expectedResults",e);}})]}),(0,r.jsxs)("div",{className:"qi-edit-side",children:[(0,r.jsx)(m4,{id:`${v}-priority`,label:"Priority",value:a.priority,options:mY,disabled:d,onChange:e=>{f("priority",e);}}),(0,r.jsx)(m4,{id:`${v}-risk`,label:"Risk class",value:a.riskClass,options:mX,disabled:d,onChange:e=>{f("riskClass",e);}}),(0,r.jsx)(m2,{id:`${v}-tags`,label:"Tags (comma-separated)",value:a.tags,disabled:d,onChange:e=>{f("tags",e);}})]})]})]});}let m5=new Set(["approved","rejected","withdrawn"]);function m8(e){let{items:t,label:n}=e;return 0===t.length?null:(0,r.jsxs)("div",{className:"qi-cand-block",children:[(0,r.jsx)("p",{className:"qi-cand-block-label",children:n}),(0,r.jsx)("ol",{className:"qi-cand-list","aria-label":n,children:t.map((e,t)=>(0,r.jsx)("li",{children:e},`${n}-${String(t)}`))})]});}function m9(e){let{candidate:t}=e;return(0,r.jsxs)("dl",{className:"qi-cand-meta","aria-label":"Test case metadata",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:"Steps"}),(0,r.jsx)("dd",{children:t.steps.length.toString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:"Expected"}),(0,r.jsx)("dd",{children:t.expectedResults.length.toString()})]}),void 0!==t.qualityVerdict?(0,r.jsxs)("div",{children:[(0,r.jsx)("dt",{children:"Quality"}),(0,r.jsx)("dd",{children:Math.round(t.qualityVerdict.score).toString()})]}):null]});}function m7(e){let{title:t,children:n}=e;return(0,r.jsxs)("details",{className:"qi-cand-accordion",children:[(0,r.jsx)("summary",{className:"qi-cand-accordion-summary",children:(0,r.jsx)("span",{children:t})}),(0,r.jsx)("div",{className:"qi-cand-accordion-body",children:n})]});}function he(e){let{candidate:t}=e;return(0,r.jsxs)(m7,{title:"Scenario",children:[(0,r.jsx)(m8,{items:t.preconditions,label:"Preconditions"}),(0,r.jsx)(m8,{items:t.steps,label:"Steps"}),(0,r.jsx)(m8,{items:t.expectedResults,label:"Expected results"})]});}function ht(e){let{candidate:t}=e;return 0===t.tags.length&&void 0===t.qualityVerdict&&void 0===t.weakTestFlag?null:(0,r.jsxs)(m7,{title:"Evidence",children:[void 0!==t.weakTestFlag?(0,r.jsx)(mF,{flag:t.weakTestFlag}):null,void 0!==t.qualityVerdict?(0,r.jsx)(mM,{verdict:t.qualityVerdict}):null,t.tags.length>0?(0,r.jsx)("ul",{className:"qi-cand-tags","aria-label":"Tags",children:t.tags.map(e=>(0,r.jsx)("li",{className:"qi-cand-tag",children:e},e))}):null]});}function hn(e){let{className:t,label:n,pressed:l,disabled:a,describedBy:i,onActivate:s}=e;return(0,r.jsx)("button",{type:"button",className:t,...(void 0!==l?{"aria-pressed":l}:{}),"aria-disabled":a||void 0,"aria-describedby":a?i:void 0,onClick:()=>{a||s();},children:n});}function hl(e){let{candidateId:t,state:n,onReview:l,disabled:a=!1,describedBy:s,pendingReview:o}=e,c=null!=o,d=e=>c&&o.candidateId===t&&o.action===e,u=m5.has(n),p=(0,i.useId)(),m=u?p:s;return(0,r.jsxs)("div",{className:"qi-cand-actions",role:"group","aria-label":"Review decision",children:[u?(0,r.jsx)("p",{id:p,className:"qi-cand-governance-note",role:"note",children:"This review decision is final — reopen to change it."}):null,(0,r.jsx)(hn,{className:"qi-btn qi-btn-approve",label:d("approve")?"Saving…":"Approve",pressed:"approved"===n,disabled:a||c||u,describedBy:m,onActivate:()=>{l(t,"approve");}}),(0,r.jsx)(hn,{className:"qi-btn qi-btn-reject",label:d("reject")?"Saving…":"Reject",pressed:"rejected"===n,disabled:a||c||u,describedBy:m,onActivate:()=>{l(t,"reject");}}),(0,r.jsx)(hn,{className:"qi-btn qi-btn-secondary",label:d("request-changes")?"Saving…":"Request changes",pressed:"changes-requested"===n,disabled:a||c||u,describedBy:m,onActivate:()=>{l(t,"request-changes");}}),u?(0,r.jsx)(hn,{className:"qi-btn qi-btn-secondary",label:d("reopen")?"Saving…":"Reopen",disabled:a||c,describedBy:a?s:void 0,onActivate:()=>{l(t,"reopen");}}):null]});}function ha(e){let{candidate:t,onReview:n,onStartEdit:l,actionsDisabled:a=!1,actionsDisabledReason:s,describedBy:o,editButtonRef:c,pendingReview:d}=e,u=(0,i.useId)(),p=a&&void 0!==s?[o,u].filter(Boolean).join(" "):o;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"qi-cand-header",children:[(0,r.jsx)("div",{className:"qi-cand-title-wrap",children:(0,r.jsx)("h3",{className:"qi-cand-title",children:t.title})}),(0,r.jsxs)("div",{className:"qi-cand-status",children:[(0,r.jsxs)("div",{className:"qi-cand-badges",children:[(0,r.jsx)("span",{className:"qi-cand-risk",children:t.riskClass}),"open"!==t.reviewState?(0,r.jsx)(mk,{state:t.reviewState}):null]}),(0,r.jsx)(m9,{candidate:t})]})]}),(0,r.jsxs)("div",{className:"qi-cand-accordion-stack",children:[(0,r.jsx)(he,{candidate:t}),(0,r.jsx)(ht,{candidate:t})]}),(0,r.jsxs)("div",{className:"qi-cand-actions-row",children:[a&&void 0!==s?(0,r.jsx)("p",{id:u,className:"qi-cand-action-note",role:"note",children:s}):null,(0,r.jsxs)("div",{className:"qi-cand-action-buttons",children:[void 0!==l?(0,r.jsx)("button",{ref:c,type:"button",className:"qi-btn qi-btn-secondary qi-cand-edit","aria-disabled":a||void 0,"aria-describedby":a?p:void 0,onClick:()=>{a||l();},children:"Edit"}):null,void 0!==n?(0,r.jsx)(hl,{candidateId:t.id,state:t.reviewState,onReview:n,disabled:a,describedBy:p,pendingReview:d}):null]})]})]});}function hr(e){let{candidate:t,onReview:n,onEdit:l,actionsDisabled:a=!1,actionsDisabledReason:s,describedBy:o,pendingReview:c}=e,[d,u]=(0,i.useState)(!1),p=(0,i.useRef)(null),m=(0,i.useRef)(!1);(0,i.useEffect)(()=>{var e;m.current&&!d&&(null==(e=p.current)||e.focus()),m.current=d;},[d]);let h=async e=>{void 0!==l&&(await l(t.id,e)),u(!1);};return(0,r.jsx)("li",{className:d?"qi-cand-card qi-cand-card-editing":"qi-cand-card",children:d&&void 0!==l?(0,r.jsx)(m6,{candidate:t,onSave:h,onCancel:()=>{u(!1);}}):(0,r.jsx)(ha,{candidate:t,onReview:n,actionsDisabled:a,actionsDisabledReason:s,describedBy:o,pendingReview:c,editButtonRef:p,onStartEdit:void 0!==l?()=>{u(!0);}:void 0})});}function hi(e){let{candidates:t,onReview:n,onEdit:l,actionsDisabled:a=!1,actionsDisabledReason:s,pendingReview:o}=e,[c,d]=(0,i.useState)(25),u=(0,i.useId)(),p=a&&void 0!==s;if(0===t.length)return(0,r.jsxs)("div",{className:"lk-empty",children:[(0,r.jsx)("p",{className:"lk-empty-title",children:"No test cases"}),(0,r.jsx)("p",{className:"lk-empty-body",children:"This run produced no generated test cases."})]});let m=[...t].sort((e,t)=>!!e.tags.includes("source:deterministic-baseline")-!!t.tags.includes("source:deterministic-baseline")).slice(0,c);return(0,r.jsxs)("div",{className:"qi-cand-pane",children:[p?(0,r.jsx)("p",{id:u,className:"qi-cand-governance-note",role:"note",children:s}):null,(0,r.jsx)("ul",{className:"qi-cand-cards","aria-label":"Test case list",children:m.map(e=>(0,r.jsx)(hr,{candidate:e,onReview:n,onEdit:l,actionsDisabled:a,actionsDisabledReason:s,describedBy:p?u:void 0,pendingReview:o},e.id))}),c<t.length?(0,r.jsxs)("button",{type:"button",className:"qi-btn qi-btn-secondary qi-cand-more",onClick:()=>{d(e=>e+25);},children:["Show more test cases (",(t.length-c).toString()," remaining)"]}):null]});}function hs(e){return 0===e?"No drift — every test is current.":`${e.toString()} ${1===e?"test is":"tests are"} stale — source changed since this run.`;}function ho(e){let t=e.regeneratedCount,n=e.preservedCount;return`Regenerated ${t.toString()} ${1===t?"test":"tests"} as a new run (${n.toString()} ${1===n?"test":"tests"} preserved).`;}function hc(e){let{staleCount:t}=e;return 0===t?(0,r.jsxs)("p",{className:"qi-drift-fresh","data-testid":"qi-drift-fresh",children:[(0,r.jsx)("span",{"aria-hidden":"true",className:"qi-drift-icon-ok",children:"✓"}),hs(0)]}):(0,r.jsxs)("p",{className:"qi-drift-stale","data-testid":"qi-drift-stale",children:[(0,r.jsx)("span",{"aria-hidden":"true",className:"qi-drift-icon-warn",children:"⚠"}),hs(t)]});}function hd(e){let{runId:t,connectedSources:n,onRegenerated:l,reCheckImpl:a=mf,regenerateImpl:s=mg}=e,[o,c]=(0,i.useState)(null),[d,u]=(0,i.useState)(null),p=null!==d,[m,h]=(0,i.useState)(null),[f,g]=(0,i.useState)(null),v=(0,i.useRef)(null),b=(0,i.useRef)(null),y=(0,i.useCallback)(()=>{p||(async()=>{u("check"),h(null),g(null);try{c(await a(t,n));}catch(e){h(mN(e));}finally{u(null);}})();},[p,a,t,n]),x=(0,i.useCallback)(()=>{p||(async()=>{u("regenerate"),h(null);try{let a=await s(t,n);if(document.activeElement===b.current){var e;null==(e=v.current)||e.focus();}g(a),c(null),null==l||l(a);}catch(e){h(mN(e));}finally{u(null);}})();},[p,s,t,n,l]);return(0,r.jsxs)("section",{className:"qi-drift-panel","aria-label":"Drift detection",children:[(0,r.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite",children:null!==f?ho(f):null!==o?hs(o.staleCount):""}),(0,r.jsxs)("div",{className:"qi-drift-head",children:[(0,r.jsx)("h3",{className:"qi-col-subtitle",children:"Living tests"}),(0,r.jsx)("button",{type:"button",ref:v,className:"qi-btn qi-btn-secondary",onClick:y,"aria-disabled":p||void 0,"data-testid":"qi-drift-recheck",children:"check"===d?"Checking…":"Re-check drift"})]}),null!==m?(0,r.jsx)("p",{className:"lk-alert",role:"alert",children:m}):null,null!==o?(0,r.jsx)(hc,{staleCount:o.staleCount}):null,null!==o&&o.staleCount>0&&null===f?(0,r.jsx)("button",{type:"button",ref:b,className:"qi-btn qi-btn-approve",onClick:x,"aria-disabled":p||void 0,"data-testid":"qi-drift-regenerate",children:"regenerate"===d?"Regenerating…":`Regenerate ${o.staleCount.toString()} stale ${1===o.staleCount?"test":"tests"}`}):null,null!==f?(0,r.jsx)("p",{className:"qi-drift-regenerated","data-testid":"qi-drift-regenerated",children:ho(f)}):null]});}let hu={"traceability-csv":"csv","traceability-markdown":"markdown"},hp=[{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 hm(e,t,n,l){let a=new Blob(["base64"===l?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}),r=URL.createObjectURL(a),i=document.createElement("a");i.href=r,i.download=e,document.body.appendChild(i),i.click(),i.remove(),window.setTimeout(()=>{URL.revokeObjectURL(r);},250);}function hh(e){var t;let{runId:n,exportImpl:l=mv,traceabilityImpl:a=mb}=e,[s,o]=(0,i.useState)("csv"),[c,d]=(0,i.useState)(!1),[u,p]=(0,i.useState)(null),[m,h]=(0,i.useState)(null),[f,g]=(0,i.useState)(null),[v,b]=(0,i.useState)(!1),y=hp.find(e=>e.id===s),x=null!=(t=null==y?void 0:y.tms)&&t,w=(0,i.useCallback)(async()=>{let e=hu[s];if(void 0!==e){let t=await a(n,e);hm(t.filename,t.contentType,t.body),g(t.filename);return;}let t=await l(n,s,{dryRun:x,approvedOnly:v});t.dryRun?h(`${t.candidateCount.toString()} test case${1===t.candidateCount?"":"s"} \xb7 ${t.byteLen.toString()} bytes
101
+
102
+ ${t.preview}`):(hm(t.filename,t.contentType,t.body,t.encoding),g(t.filename));},[n,s,x,v,l,a]),j=(0,i.useCallback)(async()=>{d(!0),p(null),h(null),g(null);try{await w();}catch(e){p(mN(e));}finally{d(!1);}},[w]);return(0,r.jsxs)("div",{className:"qi-export","data-testid":"qi-export-bar",children:[(0,r.jsxs)("div",{className:"qi-export-head",children:[(0,r.jsxs)("div",{className:"qi-export-copy",children:[(0,r.jsx)("p",{className:"qi-export-title",children:"Export"}),x?null:(0,r.jsx)("p",{className:"qi-export-hint",role:"note","data-testid":"qi-export-scope-notice",children:v?"Exports approved test cases only.":"Exports all test cases, including unapproved."})]}),x?null:(0,r.jsxs)("label",{className:"qi-export-approved-label",children:[(0,r.jsx)("input",{type:"checkbox",className:"qi-checkbox",checked:v,disabled:c,onChange:e=>{b(e.target.checked);},"data-testid":"qi-export-approved-only"}),(0,r.jsx)("span",{children:"Approved only"})]})]}),(0,r.jsxs)("div",{className:"qi-export-controls",children:[(0,r.jsxs)("div",{className:"qi-field qi-export-format",children:[(0,r.jsx)("span",{className:"qi-field-label",children:"Format"}),(0,r.jsx)(ln.A,{triggerClassName:"qi-select",value:s,ariaLabel:"Export",disabled:c,ariaDescribedBy:x?"qi-export-connector-hint":void 0,menuTitle:"Export",sections:[{options:hp.map(e=>({value:e.id,label:e.label}))}],onValueChange:e=>{o(e),h(null),p(null),g(null);}})]}),(0,r.jsx)("button",{type:"button",className:"qi-btn qi-btn-primary qi-export-action",disabled:c,onClick:()=>{j();},children:c?"Exporting…":x?"Preview":"Download"})]}),(0,r.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite",children:null!==f?`Downloaded ${f}`:null!==m?"Export preview ready below.":""}),x?(0,r.jsx)("p",{id:"qi-export-connector-hint",className:"qi-export-hint",role:"note","data-testid":"qi-export-connector-hint",children:(null==y?void 0:y.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,r.jsx)("p",{className:"qi-export-success","data-testid":"qi-export-success",children:`Downloaded ${f}`}):null,null!==m?(0,r.jsx)("pre",{className:"qi-export-preview",role:"region","aria-label":"Export preview",tabIndex:0,"data-testid":"qi-export-preview",children:m}):null,null!==u?(0,r.jsx)("p",{className:"lk-alert",role:"alert","data-testid":"qi-export-error",children:u}):null]});}let hf="keiko.qi.reviewerLabel",hg="Set a reviewer label to review or edit candidates.";function hv(e){let{detail:t}=e;return(0,r.jsxs)("dl",{className:"qi-run-summary","aria-label":"Run summary",children:[(0,r.jsxs)("div",{className:"qi-run-summary-item",children:[(0,r.jsx)("dt",{children:"Status"}),(0,r.jsx)("dd",{children:(0,r.jsx)(mE,{status:t.status})})]}),(0,r.jsxs)("div",{className:"qi-run-summary-item",children:[(0,r.jsx)("dt",{children:"Test cases"}),(0,r.jsx)("dd",{children:t.totals.candidates.toString()})]}),(0,r.jsxs)("div",{className:"qi-run-summary-item",children:[(0,r.jsx)("dt",{children:"Findings"}),(0,r.jsx)("dd",{children:t.totals.findings.toString()})]}),(0,r.jsxs)("div",{className:"qi-run-summary-item",children:[(0,r.jsx)("dt",{children:"Quality"}),(0,r.jsx)("dd",{children:(0,r.jsx)(mT,{score:t.qualityScore})})]}),(0,r.jsxs)("div",{className:"qi-run-summary-item",children:[(0,r.jsx)("dt",{children:"Review"}),(0,r.jsx)("dd",{className:"qi-run-summary-review",children:mw[t.reviewState]})]}),(0,r.jsxs)("div",{className:"qi-run-summary-item",children:[(0,r.jsx)("dt",{children:"Requested"}),(0,r.jsx)("dd",{children:mS(t.requestedAt)})]}),null!==t.completedAt?(0,r.jsxs)("div",{className:"qi-run-summary-item",children:[(0,r.jsx)("dt",{children:"Completed"}),(0,r.jsx)("dd",{children:mS(t.completedAt)})]}):null]});}let hb={"logic-defect":"Logic defect","faithfulness-defect":"Faithfulness defect","semantic-defect":"Semantic defect","mutation-defect":"Mutation defect","policy-violation":"Policy violation","manual-rejection":"Manual rejection","coverage-gap":"Coverage gap","test-quality":"Test quality"};function hy(e){let{detail:t}=e,[n,l]=(0,i.useState)(20),a=t.findingRefs.length;if(0===a)return null;let s=t.findingRefs.slice(0,n);return(0,r.jsxs)("section",{className:"qi-run-findings","aria-label":"Findings",children:[(0,r.jsxs)("h3",{className:"qi-col-subtitle",children:["Findings",(0,r.jsx)("span",{className:"qi-col-count",children:a.toString()})]}),(0,r.jsx)("ul",{className:"qi-finding-list","aria-label":"Findings list",children:s.map(e=>{var t;return(0,r.jsxs)("li",{className:"qi-finding-item",children:[(0,r.jsxs)("div",{className:"qi-finding-header",children:[(0,r.jsx)("span",{className:"qi-finding-kind",children:null!=(t=hb[e.kind])?t:e.kind}),(0,r.jsx)(mA,{severity:e.severity})]}),(0,r.jsx)("p",{className:"qi-finding-summary",children:e.summaryRedacted})]},e.id);})}),n<a?(0,r.jsxs)("button",{type:"button",className:"qi-btn qi-btn-secondary qi-show-more",onClick:()=>{l(e=>e+20);},children:["Show more findings (",(a-n).toString()," remaining)"]}):null]});}let hx={covered:"Covered","weakly-covered":"Weakly covered",uncovered:"Uncovered"},hw={covered:"qi-cov-covered","weakly-covered":"qi-cov-weak",uncovered:"qi-cov-uncovered"},hj={uncovered:0,"weakly-covered":1,covered:2};function hk(e){let{detail:t}=e,[n,l]=(0,i.useState)(20),{total:a,coveredCount:s,gaps:o}=(0,i.useMemo)(()=>{let e=t.coverageByAtom;return{total:e.length,coveredCount:e.filter(e=>"covered"===e.status).length,gaps:e.filter(e=>"covered"!==e.status).sort((e,t)=>hj[e.status]-hj[t.status])};},[t.coverageByAtom]);if(0===a)return null;let c=o.slice(0,n);return(0,r.jsxs)("section",{className:"qi-coverage-panel","aria-label":"Coverage",children:[(0,r.jsxs)("h3",{className:"qi-col-subtitle",children:["Coverage",(0,r.jsxs)("span",{className:"qi-badge qi-badge-default","aria-label":`Coverage: ${t.coveragePercentage.toFixed(0)} percent, ${s.toString()} of ${a.toString()} requirements covered`,"data-testid":"qi-coverage-pct",children:[t.coveragePercentage.toFixed(0),"%"]})]}),(0,r.jsx)("p",{className:"qi-coverage-summary","data-testid":"qi-coverage-summary",children:`${s.toString()} of ${a.toString()} requirements covered \xb7 ${o.length.toString()} gap${1===o.length?"":"s"}`}),o.length>0?(0,r.jsxs)("section",{className:"qi-coverage-gaps","aria-label":"Gap radar",children:[(0,r.jsx)("h4",{className:"qi-col-subtitle",children:`Gap radar (${o.length.toString()})`}),(0,r.jsx)("ul",{className:"qi-coverage-gap-list","aria-label":"Uncovered and weakly covered atoms",children:c.map(e=>{let t=hx[e.status],n=hw[e.status],l=e.requirementExcerptRedacted;return(0,r.jsxs)("li",{className:"qi-coverage-gap-item","aria-label":void 0===l?`Atom ${e.atomId}: ${t}`:`Requirement "${l}" (atom ${e.atomId}): ${t}`,children:[(0,r.jsxs)("span",{className:"qi-coverage-gap-req",children:[void 0===l?null:(0,r.jsx)("span",{className:"qi-coverage-gap-text","data-testid":"qi-coverage-gap-text",children:l}),(0,r.jsx)("span",{className:"qi-coverage-atom-id qi-monospace",children:e.atomId})]}),(0,r.jsx)("span",{className:`qi-badge ${n}`,"aria-hidden":"true",children:t}),(0,r.jsx)("span",{className:"qi-sr-only",children:t})]},e.atomId);})}),n<o.length?(0,r.jsxs)("button",{type:"button",className:"qi-btn qi-btn-secondary qi-show-more",onClick:()=>{l(e=>e+20);},children:["Show more gaps (",(o.length-n).toString()," remaining)"]}):null]}):null]});}function hN(e){let{detail:t}=e,n=(0,i.useId)();return t.drift.reCheckSupported?(0,r.jsxs)("section",{className:"qi-drift-panel","aria-label":"Drift detection",children:[(0,r.jsxs)("div",{className:"qi-drift-head",children:[(0,r.jsx)("h3",{className:"qi-col-subtitle",children:"Living tests"}),(0,r.jsx)("button",{type:"button",className:"qi-btn qi-btn-secondary","aria-disabled":"true","aria-describedby":n,"data-testid":"qi-drift-recheck-unavailable",onClick:e=>{e.preventDefault();},children:"Re-check drift"})]}),(0,r.jsx)("p",{id:n,className:"qi-drift-note","data-testid":"qi-drift-unavailable",children:"Drift fingerprints are recorded for this run, but this card has no current source handle. Reopen it from the connected source or start a new run from the current source."})]}):null;}function hS(e){let{runId:t,connectedSources:n,onRegenerated:l,fetchDetailImpl:a=mc,reviewImpl:s=mm,editImpl:o=mh,reCheckImpl:c,regenerateImpl:d}=e,[u,p]=(0,i.useState)(null),[m,h]=(0,i.useState)(!0),[f,g]=(0,i.useState)(null),[v,b]=(0,i.useState)(null),[y,x]=(0,i.useState)(null),[w,j]=(0,i.useState)(""),[k,N]=(0,i.useState)(!1),S=(0,i.useId)(),C=(0,i.useId)(),[R,I]=(0,i.useState)(""),E=(0,i.useRef)(0),$=(0,i.useRef)(0),A=(0,i.useCallback)(async()=>{let e=$.current+1;$.current=e,h(!0),g(null);try{let n=await a(t);$.current===e&&p(n);}catch(t){$.current===e&&g(mN(t));}finally{$.current===e&&h(!1);}},[a,t]);(0,i.useEffect)(()=>{A();},[A]),(0,i.useEffect)(()=>{j(function(){try{var e;return null!=(e=window.localStorage.getItem(hf))?e:"";}catch{return"";}}()),N(!0);},[]),(0,i.useEffect)(()=>{if(k)try{window.localStorage.setItem(hf,w);}catch{}},[w,k]);let T=w.trim(),F=T.length>0,D=(0,i.useCallback)((e,n)=>{F&&null===y&&(x({candidateId:e,action:n}),(async()=>{b(null);try{var l,a;await s(t,n,e,T),await A();let r=mw["approve"===n?"approved":"reject"===n?"rejected":"request-changes"===n?"changes-requested":"open"],i=null!=(l=null==u||null==(a=u.candidates.find(t=>t.id===e))?void 0:a.title)?l:e;E.current+=1,I(`Candidate "${i}" marked ${r}. (${E.current.toString()})`);}catch(e){b(mN(e));}finally{x(null);}})());},[F,y,s,t,T,A,u]),M=(0,i.useCallback)(async(e,n)=>{if(!F)throw Error(hg);await o(t,e,n,T),await A();},[o,F,t,T,A]);return(0,r.jsxs)("div",{className:"qi-run-card","data-testid":"qi-run-card",children:[(0,r.jsx)("header",{className:"qi-run-card-head",children:(0,r.jsx)("span",{className:"qi-run-id qi-monospace",title:t,role:"heading","aria-level":2,"aria-label":`Quality Intelligence run ${t}`,children:t})}),(0,r.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite",children:m?"Loading run…":null===f&&null!==u?`Run loaded: ${u.totals.candidates.toString()} test case${1===u.totals.candidates?"":"s"}.`:""}),(0,r.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite","data-testid":"qi-review-announce",children:R}),(0,r.jsx)("div",{className:"qi-run-card-body","aria-busy":m,children:m&&null===u?(0,r.jsx)(mL,{}):null!==f?(0,r.jsx)(mq,{message:f,onRetry:()=>void A()}):null===u?(0,r.jsx)("div",{className:"lk-empty",children:(0,r.jsx)("p",{className:"lk-empty-body",children:"Run not found."})}):(0,r.jsxs)(r.Fragment,{children:[null!==v?(0,r.jsxs)("div",{className:"lk-alert qi-action-error",role:"alert","data-testid":"qi-action-error",children:[v,(0,r.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>{b(null);},children:"Dismiss"})]}):null,(0,r.jsxs)("section",{className:"qi-run-governance","aria-label":"Review governance",children:[(0,r.jsxs)("label",{className:"qi-field",htmlFor:`qi-reviewer-label-${t}`,children:[(0,r.jsx)("span",{className:"qi-field-label",children:"Reviewer label"}),(0,r.jsx)("input",{id:`qi-reviewer-label-${t}`,className:"qi-input qi-run-governance-input",value:w,placeholder:"Required for review and edit actions","aria-invalid":!F,"aria-describedby":F?S:`${S} ${C}`,onChange:e=>{j(e.target.value);}})]}),(0,r.jsx)("p",{id:S,className:"qi-run-governance-help",children:"Used for QI review and edit audit entries."}),(0,r.jsx)("p",{id:C,className:"qi-run-governance-warning",role:"status","aria-live":"polite",children:F?"":hg})]}),(0,r.jsx)(hv,{detail:u}),(0,r.jsx)(hy,{detail:u}),(0,r.jsx)(hk,{detail:u}),void 0!==n&&n.length>0?(0,r.jsx)(hd,{runId:t,connectedSources:n,onRegenerated:l,reCheckImpl:c,regenerateImpl:d}):(0,r.jsx)(hN,{detail:u}),(0,r.jsxs)("section",{className:"qi-run-cases","aria-label":"Generated test cases",children:[(0,r.jsxs)("div",{className:"qi-run-cases-head",children:[(0,r.jsxs)("h3",{className:"qi-col-subtitle",children:["Test cases",(0,r.jsx)("span",{className:"qi-col-count",children:u.candidates.length.toString()})]}),u.candidates.length>0?(0,r.jsx)(hh,{runId:t}):null]}),(0,r.jsx)(hi,{candidates:u.candidates,onReview:D,pendingReview:y,onEdit:M,actionsDisabled:!F,actionsDisabledReason:hg})]})]})})]});}let hC={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 hR(e){let{shape:t,color:n,animated:l,highContrast:a}=e,i=["rb-edge-badge-icon",l?"rb-edge-badge-icon--processing":"",a?"rb-edge-badge-icon--high-contrast":""].filter(e=>e.length>0).join(" "),s=a?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,r.jsx)("svg",{...o,children:(0,r.jsx)("circle",{cx:"6",cy:"6",r:"4.5",fill:"none",stroke:"currentColor",strokeWidth:s})});case"clock":return(0,r.jsxs)("svg",{...o,children:[(0,r.jsx)("circle",{cx:"6",cy:"6",r:"4.5",fill:"none",stroke:"currentColor",strokeWidth:s}),(0,r.jsx)("path",{d:"M6 3v3l2 1",stroke:"currentColor",strokeWidth:s,strokeLinecap:"round",fill:"none"})]});case"filled-circle":return(0,r.jsx)("svg",{...o,children:(0,r.jsx)("circle",{cx:"6",cy:"6",r:"5"})});case"spinning-circle":return(0,r.jsx)("svg",{...o,children:(0,r.jsx)("circle",{cx:"6",cy:"6",r:"4.5",fill:"none",stroke:"currentColor",strokeWidth:s,strokeDasharray:"8 4"})});case"check":return(0,r.jsx)("svg",{...o,children:(0,r.jsx)("path",{d:"M2 6l3 3 5-5",stroke:"currentColor",strokeWidth:a?2.2:1.8,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})});case"triangle-exclamation":return(0,r.jsxs)("svg",{...o,children:[(0,r.jsx)("path",{d:"M6 1 L11 10 L1 10 Z",fill:"currentColor"}),(0,r.jsx)("path",{d:"M6 5v2.5",stroke:"var(--card)",strokeWidth:s,strokeLinecap:"round",fill:"none"}),(0,r.jsx)("circle",{cx:"6",cy:"9",r:"0.7",fill:"var(--card)"})]});case"filled-square":return(0,r.jsx)("svg",{...o,children:(0,r.jsx)("rect",{x:"1.5",y:"1.5",width:"9",height:"9",rx:"1.5"})});case"broken-line":return(0,r.jsx)("svg",{...o,children:(0,r.jsx)("path",{d:"M1 6h2.5l1.5-2 2 4 1.5-2H11",stroke:"currentColor",strokeWidth:s,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})});case"stacked-lines":return(0,r.jsxs)("svg",{...o,children:[(0,r.jsx)("rect",{x:"2",y:"2.5",width:"8",height:"1.5",rx:"0.75"}),(0,r.jsx)("rect",{x:"2",y:"5.25",width:"8",height:"1.5",rx:"0.75"}),(0,r.jsx)("rect",{x:"2",y:"8",width:"8",height:"1.5",rx:"0.75"})]});}}function hI(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,r.jsx)("svg",{...n,children:(0,r.jsx)("circle",{cx:"5",cy:"5",r:"4",fill:"none",stroke:"currentColor",strokeWidth:"1.5"})});case"active":return(0,r.jsx)("svg",{...n,children:(0,r.jsx)("circle",{cx:"5",cy:"5",r:"4.5"})});case"archived":return(0,r.jsx)("svg",{...n,children:(0,r.jsx)("rect",{x:"1",y:"1",width:"8",height:"8",rx:"1"})});case"superseded":return(0,r.jsx)("svg",{...n,children:(0,r.jsx)("path",{d:"M2 5h6M6 3l2 2-2 2",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})});case"revoked":return(0,r.jsx)("svg",{...n,children:(0,r.jsx)("path",{d:"M2 2l6 6M8 2L2 8",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",fill:"none"})});case"blocked":return(0,r.jsxs)("svg",{...n,children:[(0,r.jsx)("rect",{x:"1",y:"1",width:"8",height:"8",rx:"1"}),(0,r.jsx)("path",{d:"M5 3v3",stroke:"var(--card)",strokeWidth:"1.5",strokeLinecap:"round",fill:"none"}),(0,r.jsx)("circle",{cx:"5",cy:"7.5",r:"0.6",fill:"var(--card)"})]});case"stale":return(0,r.jsx)("svg",{...n,children:(0,r.jsx)("rect",{x:"1",y:"1",width:"8",height:"8",rx:"1",fill:"none",stroke:"currentColor",strokeWidth:"1.5"})});}}function hE(e){var t;let{type:n,lifecycle:l,activity:a,throughputCount:s,animateOverride:o=!0,highContrast:c,onClick:d,className:u=""}=e,[p,m]=(0,i.useState)(!1);(0,i.useEffect)(()=>{if(void 0!==c)return;let e=window.matchMedia("(prefers-contrast: more)"),t=e=>{m(e);};t(e.matches);let n=e=>{t(e.matches);};return e.addEventListener("change",n),()=>{e.removeEventListener("change",n);};},[c]);let h=null!=(t=hC[a])?t:hC.inactive,f=aI[n],g=null!=c?c:p,v="high-throughput"===a&&void 0!==s?`${h.label} (${String(s)})`:h.label,b=`${f.displayName} — ${h.ariaDescription}`,y=h.animated&&o,x=g?{color:h.textColor,background:"var(--card)",border:`1px solid ${h.textColor}`}:{color:h.textColor,background:h.bgColor,border:void 0!==h.borderColor?`1px solid ${h.borderColor}`:void 0};return(0,r.jsx)("span",{role:"status","aria-live":"polite","aria-atomic":"true",className:`rb-edge-badge ${u}`.trim(),"data-activity-state":a,"data-high-contrast":g?"true":void 0,children:void 0!==d?(0,r.jsxs)("button",{type:"button",className:"rb-edge-badge-btn",style:x,"aria-label":b,onClick:d,children:[(0,r.jsx)("span",{"aria-hidden":"true",children:(0,r.jsx)(hR,{shape:h.iconShape,color:h.textColor,animated:y,highContrast:g})}),(0,r.jsx)("span",{className:"visually-hidden",children:h.ariaDescription}),(0,r.jsx)("span",{"aria-hidden":"true",className:"rb-edge-badge-label",children:v}),(0,r.jsx)("span",{className:"rb-edge-badge-type",children:f.displayName}),(0,r.jsx)(hI,{state:l})]}):(0,r.jsxs)("span",{className:"rb-edge-badge-static",style:x,"aria-label":b,children:[(0,r.jsx)("span",{"aria-hidden":"true",children:(0,r.jsx)(hR,{shape:h.iconShape,color:h.textColor,animated:y,highContrast:g})}),(0,r.jsx)("span",{className:"visually-hidden",children:h.ariaDescription}),(0,r.jsx)("span",{"aria-hidden":"true",className:"rb-edge-badge-label",children:v}),(0,r.jsx)("span",{className:"rb-edge-badge-type",children:f.displayName}),(0,r.jsx)(hI,{state:l})]})});}let h$="keiko.relationships.density",hA={minimal:5,standard:25,dense:512};function hT(){try{let e=window.localStorage.getItem(h$);if("minimal"===e||"standard"===e||"dense"===e)return e;}catch{}return"minimal";}function hF(e,t){return void 0===e||0===e.length?[]:e.split(",").map(e=>e.trim()).filter(e=>t.includes(e));}function hD(e){return{types:hF(e.relType,aC),lifecycles:hF(e.relLifecycle,aR),activities:hF(e.relActivity,["inactive","queued","active","processing","completed","failed","blocked","degraded","high-throughput"]),srcKinds:hF(e.relSrcKind,aN),tgtKinds:hF(e.relTgtKind,aN)};}let hM={"high-throughput":0,processing:1,active:2,blocked:3,failed:4,degraded:5,queued:6,completed:7,inactive:8};function hP(e,t,n){var l;return null!=(l=n.get(e))?l:function(e){switch(e){case"blocked":return"blocked";case"stale":return"degraded";default:return"inactive";}}(t);}function hL(e){var t,n,l,a,s,o,c;let{filters:d,selectedId:u,onSelect:p,onFilterChange:m,activityMap:h=new Map(),throughputMap:f=new Map(),animateBadges:g=!0,highContrast:v=!1}=e,[b,y]=(0,i.useState)(()=>{let e=d.relDensity;return"minimal"===e||"standard"===e||"dense"===e?e:hT();}),[x,w]=(0,i.useState)(!1),[j,k]=(0,i.useState)([]),[N,S]=(0,i.useState)(!1),[C,R]=(0,i.useState)(null),[I,E]=(0,i.useState)(!1),$=(0,i.useRef)(null),A=(0,i.useRef)(null),[T,F]=(0,i.useState)(null!=(t=d.relType)?t:""),D=(0,i.useRef)(null),M=(0,i.useCallback)(e=>{y(e),m({relDensity:e});try{window.localStorage.setItem(h$,e);}catch{}},[m]);(0,i.useEffect)(()=>{let e=d.relDensity;"minimal"===e||"standard"===e||"dense"===e?y(e):y(hT());},[d.relDensity]),(0,i.useEffect)(()=>{var e;F(null!=(e=d.relType)?e:"");},[d.relType]);let P=(0,i.useCallback)(async()=>{R(null),S(!0);try{let e=hD(d),t=1===e.lifecycles.length?e.lifecycles[0]:"active",n=1===e.types.length?e.types[0]:void 0,l=1===e.srcKinds.length?e.srcKinds[0]:void 0,a=1===e.tgtKinds.length?e.tgtKinds[0]:void 0,r=await aP({lifecycle:t,type:n,sourceKind:l,targetKind:a,limit:hA[b]});k(r.entries),E(r.truncated);}catch(e){R(e instanceof aA?e.message:a$);}finally{S(!1);}},[d,b]);(0,i.useEffect)(()=>{P();},[P]),(0,i.useEffect)(()=>{let e=$.current;if(null!==e)return e.addEventListener("keydown",t),()=>e.removeEventListener("keydown",t);function t(e){if(!("u"<typeof document)&&null!==document.querySelector('[role="dialog"][aria-modal="true"]'))return;let t=e.target;if(!(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement||t instanceof HTMLElement&&t.isContentEditable)){if("f"===e.key||"F"===e.key)e.preventDefault(),w(e=>!e);else if("Escape"===e.key)w(!1);else if("/"===e.key){var n;e.preventDefault(),null==(n=A.current)||n.focus();}}}},[]);let L=(0,i.useCallback)(e=>{let t=e.target.value;F(t),null!==D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{m({relType:t.length>0?t:void 0});},250);},[m]),q=(0,i.useMemo)(()=>{var e;let t=hD(d),n=(null!=(e=d.relType)?e:"").split(",").map(e=>e.trim().toLowerCase()).filter(e=>e.length>0),l=0===n.length?j:j.filter(e=>n.some(t=>e.type.toLowerCase().includes(t)));return(0===t.activities.length?l:l.filter(e=>t.activities.includes(hP(e.id,e.lifecycle,h)))).slice(0,hA[b]);},[h,b,d,j]),z=q.slice(0,25),O=q.slice(25),B=O.length,W=B>0?function(e,t){let n=new Map();for(let a of e){var l;let e=hP(a.id,a.lifecycle,t);n.set(e,(null!=(l=n.get(e))?l:0)+1);}return Array.from(n.entries()).sort((e,t)=>{var n,l;return t[1]!==e[1]?t[1]-e[1]:(null!=(n=hM[e[0]])?n:Number.MAX_SAFE_INTEGER)-(null!=(l=hM[t[0]])?l:Number.MAX_SAFE_INTEGER);}).map(e=>{let t,[n,l]=e;return t=1===l?"relationship":"relationships","high-throughput"===n?`${l} high-throughput ${t}`:`${l} ${n} ${t}`;}).join(", ");}(O,h):"",K=I?`Showing first ${String(q.length)} relationships — more available.`:`Showing ${String(q.length)} relationship${1!==q.length?"s":""}.`,U=(null!=(n=d.relType)?n:"").trim().length>0||(null!=(l=d.relActivity)?l:"").trim().length>0||(null!=(a=d.relSrcKind)?a:"").trim().length>0||(null!=(s=d.relTgtKind)?s:"").trim().length>0||(null!=(o=d.relLifecycle)?o:"").trim().length>0&&"active"!==d.relLifecycle,V=hF(d.relLifecycle,aR),H=1===V.length&&null!=(c=V[0])?c:"active";return(0,r.jsxs)("div",{ref:$,className:"tw-pad","data-testid":"relationship-list-panel","data-relationship-focus":x?"true":void 0,children:[(0,r.jsxs)("div",{role:"group","aria-label":"Relationship density",style:{display:"flex",flexWrap:"wrap",gap:"var(--space-2)",marginBottom:8},children:[["minimal","standard","dense"].map(e=>(0,r.jsx)("button",{type:"button",className:"arun-btn","aria-pressed":b===e,onClick:()=>M(e),style:{textTransform:"capitalize",minWidth:24,minHeight:24},children:e},e)),(0,r.jsx)("button",{type:"button",className:"arun-btn","aria-pressed":x,onClick:()=>w(e=>!e),title:"Toggle focus mode (F)","aria-label":`Focus mode: ${x?"on":"off"}`,style:{minWidth:24,minHeight:24},children:"Focus"})]}),(0,r.jsxs)("div",{style:{marginBottom:8},children:[(0,r.jsx)("label",{htmlFor:"rel-type-filter",className:"rb-row-k",style:{display:"block",marginBottom:2,fontSize:11,fontWeight:600},children:"Filter by type (press / to focus)"}),(0,r.jsx)("input",{id:"rel-type-filter",ref:A,type:"text",list:"rel-type-filter-options",value:T,onChange:L,placeholder:"e.g. reads-context","aria-label":"Filter relationships by type",style:{width:"100%",background:"var(--inset)",border:"1px solid var(--line)",borderRadius:9,padding:"4px 8px",minHeight:24,color:"var(--fg)",fontSize:13}}),(0,r.jsx)("datalist",{id:"rel-type-filter-options",children:aC.map(e=>(0,r.jsx)("option",{value:e},e))})]}),(0,r.jsxs)("div",{style:{marginBottom:8},children:[(0,r.jsx)("label",{htmlFor:"rel-lifecycle-filter",className:"rb-row-k",style:{display:"block",marginBottom:2,fontSize:11,fontWeight:600},children:"Lifecycle"}),(0,r.jsx)("select",{id:"rel-lifecycle-filter",value:H,onChange:e=>m({relLifecycle:e.target.value}),"aria-label":"Filter relationships by lifecycle",style:{width:"100%",background:"var(--inset)",border:"1px solid var(--line)",borderRadius:9,padding:"4px 8px",minHeight:24,color:"var(--fg)",fontSize:13},children:aR.map(e=>(0,r.jsx)("option",{value:e,children:e},e))})]}),(0,r.jsx)("div",{"aria-live":"polite","aria-atomic":"true",className:"visually-hidden",children:K}),I&&(0,r.jsx)("div",{"data-testid":"list-truncation-note",style:{fontSize:11,color:"var(--fg-muted)",marginBottom:6},children:K}),null!==C&&(0,r.jsxs)("div",{className:"lk-alert",role:"alert","aria-live":"assertive",children:[(0,r.jsx)("span",{children:C}),(0,r.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>void P(),children:"Retry"})]}),N&&0===j.length&&(0,r.jsx)("div",{role:"status",className:"insp-empty",children:"Loading…"}),(!N||j.length>0)&&null===C&&0===q.length&&(0,r.jsx)("div",{className:"insp-empty","data-testid":"list-empty",children:U?"No relationships match the current filter.":'No active relationships yet. Create one with "+ New relationship", or connect a source — connections appear here automatically.'}),q.length>0&&(0,r.jsxs)("div",{role:"list","aria-label":"Relationships","aria-busy":N||void 0,style:{display:"flex",flexDirection:"column",gap:"var(--space-1)",opacity:N?.6:1,transition:"opacity 0.15s ease"},children:[z.map(e=>{var t;let n=e.id===u,l=hP(e.id,e.lifecycle,h),a=x&&n,i=x&&!n;return(0,r.jsx)("div",{role:"listitem",style:{opacity:i?.4:1},children:(0,r.jsxs)("button",{type:"button","aria-pressed":n,"aria-label":`${e.type} relationship from ${e.source.kind} ${e.source.id} to ${e.target.kind} ${e.target.id}, lifecycle: ${e.lifecycle}`,title:`${e.source.id} → ${e.target.id}`,onClick:()=>p(e.id),onKeyDown:t=>{var n;return n=e.id,void(("Enter"===t.key||" "===t.key)&&(t.preventDefault(),p(n)));},"data-incident":a?"true":void 0,className:"rel-row",children:[(0,r.jsx)(hE,{type:e.type,lifecycle:e.lifecycle,activity:l,throughputCount:f.get(e.id),animateOverride:g,highContrast:v}),(0,r.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column"},children:[(0,r.jsxs)("span",{style:{fontSize:12,color:"var(--fg)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[e.source.kind," → ",e.target.kind]}),(0,r.jsx)("span",{style:{fontSize:10.5,color:"var(--fg-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:null!=(t=e.summary)?t:`${e.source.id} → ${e.target.id}`})]}),(0,r.jsx)("span",{style:{fontSize:11,color:"var(--fg-muted)",whiteSpace:"nowrap"},children:e.lifecycle})]})},e.id);}),B>0&&(0,r.jsxs)("div",{role:"listitem","aria-live":"polite",style:{fontSize:12,color:"var(--fg-muted)",padding:"4px 6px"},"data-testid":"animation-cap-aggregate",children:["+",String(B)," more: ",W]})]})]});}function hq(){return(0,r.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 hz(e){let{title:t,help:n,report:l,onSelectRelationship:a}=e;if(null===l)return(0,r.jsxs)("section",{style:{marginBottom:12},children:[(0,r.jsx)("div",{className:"rb-section-label",role:"heading","aria-level":4,children:t}),(0,r.jsx)("p",{style:{fontSize:12,color:"var(--fg-muted)",margin:0},children:"Loading…"})]});let i=l.endpoints.slice(1),s=l.relationships,o=i.slice(0,50),c=s.slice(0,50);return(0,r.jsxs)("section",{style:{marginBottom:12},"aria-label":t,children:[(0,r.jsxs)("div",{className:"rb-section-label",role:"heading","aria-level":4,children:[t,(0,r.jsx)("span",{className:"rb-count","aria-hidden":"true",children:i.length})]}),(0,r.jsx)("p",{style:{margin:"0 0 6px",fontSize:11,color:"var(--fg-muted)"},children:n}),0===i.length?(0,r.jsx)("p",{style:{fontSize:12,color:"var(--fg-muted)",margin:0},children:"No further objects are affected in this direction."}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("ul",{style:{listStyle:"none",margin:0,padding:0},children:o.map(e=>(0,r.jsx)("li",{className:"rb-row",style:{fontSize:12},children:(0,r.jsx)("span",{className:"mono",children:`${e.kind}: ${e.id}`})},`${e.kind}:${e.id}`))}),i.length>o.length&&(0,r.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."]}),s.length>0&&(0,r.jsxs)("details",{style:{marginTop:6},children:[(0,r.jsxs)("summary",{style:{fontSize:11,color:"var(--fg-muted)",cursor:"pointer"},children:[String(s.length)," relationship",1===s.length?"":"s"," on the path"]}),(0,r.jsx)("ul",{style:{listStyle:"none",margin:"4px 0 0",padding:0},children:c.map(e=>(0,r.jsx)("li",{style:{marginBottom:2},children:(0,r.jsxs)("button",{type:"button",className:"arun-btn ghost",onClick:()=>a(e.id),"aria-label":`Inspect ${e.type} relationship from ${e.source.kind} ${e.source.id} to ${e.target.kind} ${e.target.id}`,style:{display:"flex",width:"100%",gap:"var(--space-3)",alignItems:"center",textAlign:"left",fontSize:12},children:[(0,r.jsx)("span",{className:"mono",children:e.type}),(0,r.jsxs)("span",{style:{color:"var(--fg-muted)"},children:[e.source.id," → ",e.target.id]})]})},e.id))})]})]}),l.truncated&&(0,r.jsx)(hq,{})]});}function hO(e){let{outgoing:t,incoming:n,onSelectRelationship:l}=e;return(0,r.jsxs)("div",{style:{marginTop:8,padding:"8px 10px",border:"1px solid var(--line)",borderRadius:8,background:"var(--inset)"},"aria-label":"Bounded impact analysis",children:[(0,r.jsx)(hz,{title:"Downstream impact",help:"Objects this relationship's target leads to. Deleting or revoking here may affect them.",report:t,onSelectRelationship:l}),(0,r.jsx)(hz,{title:"Upstream impact",help:"Objects that depend on this relationship's source.",report:n,onSelectRelationship:l})]});}let hB={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)"}},hW={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 hK(e){let{lines:t=3}=e;return(0,r.jsx)("div",{className:"rb-rows","aria-hidden":"true",children:Array.from({length:t},(e,t)=>(0,r.jsxs)("div",{className:"rb-row",children:[(0,r.jsx)("span",{className:"rb-row-k",style:{background:"var(--inset)",borderRadius:3,width:"40%",display:"block",height:12}}),(0,r.jsx)("span",{className:"rb-row-v",style:{background:"var(--inset)",borderRadius:3,width:"55%",display:"block",height:12}})]},t))});}function hU(e){let{children:t,style:n}=e;return(0,r.jsx)("div",{className:"rb-section-label",role:"heading","aria-level":3,style:n,children:t});}function hV(e){let{rel:t}=e,n=aI[t.type],l=`${t.source.kind} ${t.type} ${t.target.kind}`;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"insp-top",children:[(0,r.jsx)("span",{className:"chip",style:{fontSize:11},children:t.type}),(0,r.jsx)("span",{className:"insp-title",children:l})]}),(0,r.jsxs)("div",{className:"rb-rows",children:[(0,r.jsxs)("div",{className:"rb-row",children:[(0,r.jsx)("span",{className:"rb-row-k",children:"Semantics"}),(0,r.jsx)("span",{className:"rb-row-v",children:n.semantics})]}),(0,r.jsxs)("div",{className:"rb-row",children:[(0,r.jsx)("span",{className:"rb-row-k",children:"Cardinality"}),(0,r.jsx)("span",{className:"rb-row-v mono",children:n.cardinality})]})]})]});}function hH(e){let{label:t,kind:n,id:l}=e;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(hU,{children:[t," endpoint"]}),(0,r.jsxs)("div",{className:"rb-rows",children:[(0,r.jsxs)("div",{className:"rb-row",children:[(0,r.jsx)("span",{className:"rb-row-k",children:"Kind"}),(0,r.jsx)("span",{className:"rb-row-v mono",children:n})]}),(0,r.jsxs)("div",{className:"rb-row",children:[(0,r.jsx)("span",{className:"rb-row-k",children:"Reference"}),(0,r.jsx)("span",{className:"rb-row-v mono","aria-label":`Reference id: ${l}`,children:l})]})]})]});}function h_(e){var t;let{lifecycle:n}=e,l=`lifecycle-desc-${n}`,a=null!=(t=hB[n])?t:hB.draft;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(hU,{children:"Lifecycle status"}),(0,r.jsxs)("div",{className:"rb-rows",children:[(0,r.jsxs)("div",{className:"rb-row",children:[(0,r.jsx)("span",{className:"rb-row-k",children:"State"}),(0,r.jsx)("span",{className:"rb-row-v",children:(0,r.jsx)("span",{className:"chip",style:{background:a.bg,color:a.fg},"aria-describedby":l,children:n})})]}),(0,r.jsx)("div",{className:"rb-row",children:(0,r.jsx)("span",{id:l,className:"rb-row-v",style:{color:"var(--fg-muted)",fontSize:12},children:hW[n]})})]})]});}function hG(e){let{type:t,lifecycle:n,activity:l,throughputCount:a,animateBadges:i,highContrast:s,transitions:o,densityMode:c}=e,d=o.slice(0,"minimal"===c?3:5);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(hU,{children:"Activity"}),(0,r.jsxs)("div",{className:"rb-rows",children:[(0,r.jsxs)("div",{className:"rb-row",children:[(0,r.jsx)("span",{className:"rb-row-k",children:"Current state"}),(0,r.jsx)("span",{className:"rb-row-v",children:(0,r.jsx)(hE,{type:t,lifecycle:n,activity:l,throughputCount:a,animateOverride:i,highContrast:s})})]}),d.length>0&&(0,r.jsxs)("div",{className:"rb-row",style:{flexDirection:"column",gap:"var(--space-2)",alignItems:"flex-start"},children:[(0,r.jsx)("span",{className:"rb-row-k",style:{marginBottom:4},children:"Recent transitions"}),d.map((e,t)=>(0,r.jsxs)("div",{style:{fontSize:12,color:"var(--fg-muted)",display:"flex",gap:"var(--space-4)"},children:[(0,r.jsxs)("span",{className:"mono",children:[e.from," → ",e.to]}),(0,r.jsx)("time",{dateTime:new Date(e.occurredAt).toISOString(),style:{color:"var(--fg-faint)"},children:new Date(e.occurredAt).toLocaleString()})]},t))]})]})]});}function hJ(){return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(hU,{children:"Authority status"}),(0,r.jsx)("div",{className:"rb-rows",children:(0,r.jsx)("div",{className:"rb-row","data-testid":"authority-disclaimer",children:(0,r.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 hY(e){let{auditRows:t,loading:n,error:l,onRetry:a,onLoadMore:i,hasMore:s}=e;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(hU,{children:"Audit history"}),n&&(0,r.jsx)(hK,{lines:3}),null!==l&&(0,r.jsxs)("div",{className:"lk-alert",role:"alert","aria-live":"assertive",children:[(0,r.jsx)("span",{children:l}),(0,r.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:a,children:"Retry"})]}),!n&&null===l&&0===t.length&&(0,r.jsx)("div",{className:"rb-rows",children:(0,r.jsx)("div",{className:"rb-row",children:(0,r.jsx)("span",{className:"rb-row-v",style:{color:"var(--fg-muted)"},children:"No audit events for this relationship yet."})})}),!n&&t.length>0&&(0,r.jsxs)("div",{className:"rb-rows",children:[t.map((e,t)=>(0,r.jsxs)("div",{className:"rb-row",style:{flexDirection:"column",alignItems:"flex-start",gap:"var(--space-1)"},children:[(0,r.jsxs)("span",{className:"rb-row-k mono",style:{fontSize:11},children:[e.from," → ",e.to]}),(0,r.jsx)("time",{dateTime:new Date(e.occurredAt).toISOString(),style:{color:"var(--fg-faint)",fontSize:11},children:new Date(e.occurredAt).toLocaleString()})]},t)),s&&(0,r.jsx)("div",{className:"rb-row",children:(0,r.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 hX(e){let t,{rel:n}=e,l=(t=[],"evidence-run"===n.source.kind&&t.push(n.source.id),"evidence-run"===n.target.kind&&t.push(n.target.id),t);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(hU,{children:"Evidence references"}),0===l.length?(0,r.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,r.jsx)("div",{className:"rb-rows",children:l.map(e=>(0,r.jsxs)("div",{className:"rb-row",children:[(0,r.jsx)("span",{className:"rb-row-k",children:"Evidence run"}),(0,r.jsx)("span",{className:"rb-row-v mono","aria-label":`Evidence run reference ${e}`,title:e,children:e})]},e))})]});}function hZ(e){let{relationshipId:t,forwardCount:n,reverseCount:l,outgoing:a,incoming:i,expanded:s,onToggle:o,onSelectRelationship:c}=e;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(hU,{children:"Impact summary"}),(0,r.jsxs)("div",{className:"rb-rows",children:[(0,r.jsxs)("div",{className:"rb-row",children:[(0,r.jsx)("span",{className:"rb-row-k",children:"Forward dependencies"}),(0,r.jsx)("span",{className:"rb-row-v mono",children:null===n?"—":String(n)})]}),(0,r.jsxs)("div",{className:"rb-row",children:[(0,r.jsx)("span",{className:"rb-row-k",children:"Reverse dependencies"}),(0,r.jsx)("span",{className:"rb-row-v mono",children:null===l?"—":String(l)})]}),(0,r.jsx)("div",{className:"rb-row",children:(0,r.jsx)("button",{type:"button",className:"arun-btn",onClick:o,"aria-expanded":s,"aria-controls":"rb-impact-detail","aria-label":s?`Hide impact for relationship ${t}`:`View impact for relationship ${t}`,"data-testid":"view-impact-btn",children:s?"Hide impact":"View impact"})})]}),s&&(0,r.jsx)("div",{id:"rb-impact-detail",children:(0,r.jsx)(hO,{outgoing:a,incoming:i,onSelectRelationship:c})})]});}function hQ(e){let{codes:t,messages:n,deniedAt:l}=e;return 0===t.length?null:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(hU,{children:"Denial reason"}),(0,r.jsxs)("div",{className:"lk-alert",role:"status","aria-live":"polite","data-testid":"denial-section",children:[t.map((e,l)=>{var a;return(0,r.jsxs)("div",{style:{marginBottom:8*(l<t.length-1)},children:[(0,r.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--fg-muted)",marginBottom:2},children:e}),(0,r.jsx)("div",{style:{fontSize:13,color:"var(--fg)"},children:null!=(a=n[l])?a:e})]},e);}),void 0!==l&&(0,r.jsxs)("div",{style:{fontSize:11,color:"var(--fg-faint)",marginTop:6},children:["Denied at ",(0,r.jsx)("time",{dateTime:l,children:l})]})]})]});}function h0(e){return null==e||0===e.length?null:{codes:e.map(e=>e.code),messages:e.map(e=>e.message)};}function h1(e){let{rel:t,onReconnect:n,onArchive:l,onRevoke:a,onViewImpact:i,onViewEvidence:s,mutating:o}=e,c=t.lifecycle,d="blocked"===c,u="active"===c,p="active"===c||"blocked"===c||"archived"===c,m="active"===c;return(0,r.jsxs)("div",{style:{display:"flex",gap:"var(--space-3)",flexWrap:"wrap",marginTop:8},children:[(0,r.jsx)("button",{type:"button",className:`arun-btn${d?" primary":""}`,"aria-disabled":!d||o,"aria-label":"Reconnect — only available for blocked relationships",title:d?"Reconnect this relationship":"Only blocked relationships can be reconnected.",disabled:!d||o,onClick:d?n:void 0,children:"Reconnect"}),(0,r.jsx)("button",{type:"button",className:"arun-btn","aria-disabled":!u||o,"aria-label":"Archive — only available for active relationships",title:u?"Archive this relationship":"Only active relationships can be archived.",disabled:!u||o,onClick:u?l:void 0,children:"Archive"}),(0,r.jsx)("button",{type:"button",className:"arun-btn","aria-disabled":!p||o,"aria-label":"Revoke relationship",title:p?"Revoke this relationship":"Already revoked or superseded.",disabled:!p||o,onClick:p?a:void 0,style:{color:p?"var(--danger)":void 0},children:"Revoke"}),(0,r.jsx)("button",{type:"button",className:"arun-btn","aria-disabled":!m,"aria-label":"View impact analysis",title:m?"Toggle the impact analysis card":"Impact analysis is unavailable in this state.",disabled:!m,onClick:m?i:void 0,children:"View impact"}),(0,r.jsx)("button",{type:"button",className:"arun-btn","aria-label":"View evidence references",title:"Jump to the evidence references section",onClick:s,children:"View evidence"})]});}function h2(e){var t,n,l;let{relationshipId:a,densityMode:s="minimal",onClearFocus:o,onViewImpact:c,activityMap:d=new Map(),throughputMap:u=new Map(),animateBadges:p=!0,highContrast:m=!1}=e,[h,f]=(0,i.useState)(null),[g,v]=(0,i.useState)(null),[b,y]=(0,i.useState)(!1),[x,w]=(0,i.useState)(null),[j,k]=(0,i.useState)(!1),[N,S]=(0,i.useState)(null),[C,R]=(0,i.useState)(null),[I,E]=(0,i.useState)(null),[$,A]=(0,i.useState)(null),[T,F]=(0,i.useState)(!1),D=null===I?null:I.relationships.length,M=null===$?null:$.relationships.length,[P,L]=(0,i.useState)(!1),q=(0,i.useRef)(null),z=(0,i.useRef)(0),O=(0,i.useCallback)(async e=>{let t=++z.current;w(null),y(!0),R(null),E(null),A(null),F(!1);let n=setTimeout(()=>{z.current===t&&L(!0);},500);q.current=n;try{let[n,l]=await Promise.all([aL(e),aB(e)]);if(z.current!==t)return;f(n),v(l);try{let[n,l]=await Promise.all([aO(e,{direction:"outgoing",maxDepth:3,maxRelationships:512}),aO(e,{direction:"incoming",maxDepth:3,maxRelationships:512})]);if(z.current!==t)return;E(n),A(l);}catch{}}catch(e){if(z.current!==t)return;w(e instanceof aA?e.message:a$);}finally{q.current===n?(clearTimeout(n),q.current=null):clearTimeout(n),z.current===t&&(y(!1),L(!1));}},[]);(0,i.useEffect)(()=>{if(null===a){z.current+=1,null!==q.current&&(clearTimeout(q.current),q.current=null),f(null),v(null),w(null),R(null),L(!1),y(!1);return;}return O(a),()=>{null!==q.current&&(clearTimeout(q.current),q.current=null);};},[a,O]);let B=(0,i.useCallback)(async e=>{if(null!==h){k(!0),S(null),R(null);try{let t=crypto.randomUUID(),{relationship:n}=await aq(h.id,{transition:{to:e}},String(h.etag),t);f(n),v(null),await O(h.id);}catch(e){S(e instanceof aA?e.message:"Mutation failed. Please retry."),R(e instanceof aA?h0(e.reasons):null);}finally{k(!1);}}},[h,O]),W=(0,i.useCallback)(()=>void B("draft"),[B]),K=(0,i.useCallback)(()=>void B("archived"),[B]),U=(0,i.useCallback)(async()=>{if(null!==h&&window.confirm(`Revoke relationship "${h.type}"? This cannot be undone.`)){k(!0),S(null),R(null);try{let e=crypto.randomUUID(),t=await az(h.id,String(h.etag),e);f(t);}catch(e){S(e instanceof aA?e.message:"Revoke failed. Please retry."),R(e instanceof aA?h0(e.reasons):null);}finally{k(!1);}}},[h]),V=(0,i.useCallback)(()=>{F(e=>!e);},[]),H=(0,i.useCallback)(e=>{null==c||c(e);},[c]),_=(0,i.useRef)(null),G=(0,i.useCallback)(()=>{var e,t;null==(t=_.current)||null==(e=t.scrollIntoView)||e.call(t,{block:"start"});},[]);if(null===a)return(0,r.jsxs)("div",{className:"tw-pad","data-testid":"relationship-inspector-panel",children:[(0,r.jsx)(hU,{style:{marginTop:0},children:"Relationship"}),(0,r.jsx)("div",{className:"insp-empty","data-testid":"inspector-empty",children:"Select a relationship from the list to inspect it."}),(0,r.jsx)("div",{style:{fontSize:12,color:"var(--fg-muted)",marginTop:4},children:"If the list is empty, use “+ New relationship” in the toolbar to create one."})]});let J=h0(null==g?void 0:g.decision.reasons),Y=null!=J?J:C,X=null!==Y&&((null==h?void 0:h.lifecycle)==="blocked"||(null==h?void 0:h.lifecycle)==="revoked"||null!==C),Z=null!==h?null!=(t=d.get(h.id))?t:function(e){switch(e){case"blocked":return"blocked";case"stale":return"degraded";default:return"inactive";}}(h.lifecycle):"inactive",Q=null!==h?u.get(h.id):void 0;return(0,r.jsxs)("div",{className:"tw-pad","aria-busy":b,"data-testid":"relationship-inspector-panel",children:[null!==x&&(0,r.jsxs)("div",{className:"lk-alert",role:"alert","aria-live":"assertive",children:[(0,r.jsx)("span",{children:x}),(0,r.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>void O(a),children:"Retry"})]}),null!==N&&(0,r.jsxs)("div",{className:"lk-alert",role:"alert","aria-live":"assertive",children:[(0,r.jsx)("span",{children:N}),(0,r.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>S(null),children:"Dismiss"})]}),b&&P&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(hU,{style:{marginTop:0},children:"Relationship"}),(0,r.jsx)(hK,{lines:4}),(0,r.jsx)(hK,{lines:3})]}),!b&&null===x&&null===h&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(hU,{style:{marginTop:0},children:"Relationship"}),(0,r.jsx)("div",{className:"insp-empty","data-testid":"inspector-not-found",children:"This relationship is no longer available."}),(0,r.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,r.jsx)("button",{type:"button",className:"arun-btn",style:{marginTop:8},onClick:o,children:"Clear focus"})]}),!b&&null!==h&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(hU,{style:{marginTop:0},children:"Relationship"}),(0,r.jsx)(hV,{rel:h}),(0,r.jsx)(hH,{label:"Source",kind:h.source.kind,id:h.source.id}),(0,r.jsx)(hH,{label:"Target",kind:h.target.kind,id:h.target.id}),(0,r.jsx)(h_,{lifecycle:h.lifecycle}),(0,r.jsx)(hG,{type:h.type,lifecycle:h.lifecycle,activity:Z,throughputCount:Q,animateBadges:p,highContrast:m,transitions:null!=(n=null==g?void 0:g.lifecycle)?n:[],densityMode:s}),(0,r.jsx)(hJ,{}),(0,r.jsx)(hY,{auditRows:null!=(l=null==g?void 0:g.lifecycle)?l:[],loading:!1,error:null,onRetry:()=>void O(a),onLoadMore:()=>{},hasMore:!1}),(0,r.jsx)("div",{ref:_,children:(0,r.jsx)(hX,{rel:h})}),(0,r.jsx)(hZ,{relationshipId:h.id,forwardCount:D,reverseCount:M,outgoing:I,incoming:$,expanded:T,onToggle:V,onSelectRelationship:H}),X&&null!==Y&&(0,r.jsx)(hQ,{codes:Y.codes,messages:Y.messages}),(0,r.jsx)(h1,{rel:h,onReconnect:W,onArchive:K,onRevoke:()=>void U(),onViewImpact:V,onViewEvidence:G,mutating:j})]})]});}let h4=new Set(["kind","id","state","timestamp","count"]);function h3(e){return`${e.kind}: ${e.id}`;}function h6(e){let{category:t}=e;return(0,r.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 h5(e){let{category:t,onSelectRelationship:n}=e;if(0===t.items.length)return null;let l=t.items.slice(0,50),a=t.items.length-l.length;return(0,r.jsxs)("section",{"aria-label":`${t.label} (${String(t.items.length)})`,style:{marginBottom:14},children:[(0,r.jsxs)("div",{className:"rb-section-label",role:"heading","aria-level":3,children:[t.label,(0,r.jsx)("span",{className:"rb-count","aria-hidden":"true",children:t.items.length})]}),(0,r.jsx)("p",{style:{margin:"0 0 6px",fontSize:11,color:"var(--fg-muted)"},children:t.help}),(0,r.jsx)("ul",{style:{listStyle:"none",margin:0,padding:0},children:l.map(e=>(0,r.jsx)("li",{style:{marginBottom:2},children:(0,r.jsxs)("button",{type:"button",className:"arun-btn ghost",onClick:()=>n(e.id),"aria-label":`Inspect ${e.type} relationship from ${h3(e.source)} to ${h3(e.target)}, lifecycle ${e.lifecycle}`,style:{display:"flex",width:"100%",gap:6,alignItems:"center",textAlign:"left",fontSize:12},children:[(0,r.jsx)("span",{className:"mono",style:{color:"var(--fg)"},children:e.type}),(0,r.jsxs)("span",{style:{color:"var(--fg-muted)"},children:[h3(e.source)," → ",h3(e.target)]}),(0,r.jsx)("span",{className:"mono",style:{marginLeft:"auto",color:"var(--fg-muted)"},children:e.lifecycle})]})},e.id))}),a>0&&(0,r.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,r.jsx)(h6,{category:t.label.toLowerCase()})]});}function h8(e){let{findings:t}=e;if(0===t.orphanedEndpoints.length)return null;let n=t.orphanedEndpoints.slice(0,50);return(0,r.jsxs)("section",{"aria-label":`Orphaned endpoints (${String(t.orphanedEndpoints.length)})`,style:{marginBottom:14},children:[(0,r.jsxs)("div",{className:"rb-section-label",role:"heading","aria-level":3,children:["Orphaned endpoints",(0,r.jsx)("span",{className:"rb-count","aria-hidden":"true",children:t.orphanedEndpoints.length})]}),(0,r.jsx)("p",{style:{margin:"0 0 6px",fontSize:11,color:"var(--fg-muted)"},children:"Endpoints that participate in no live relationship."}),(0,r.jsx)("ul",{style:{listStyle:"none",margin:0,padding:0},children:n.map(e=>(0,r.jsx)("li",{className:"rb-row",style:{fontSize:12},children:(0,r.jsx)("span",{className:"mono",children:h3(e)})},`${e.kind}:${e.id}`))}),t.orphanedEndpointsTruncated&&(0,r.jsx)(h6,{category:"orphaned endpoints"})]});}function h9(e){var t,n;let{onSelectRelationship:l}=e,[a,s]=(0,i.useState)(null),[o,c]=(0,i.useState)(!0),[d,u]=(0,i.useState)(null),p=(0,i.useCallback)(async()=>{c(!0),u(null);try{let e=await aW();s(e);}catch(e){u(e instanceof aA?e.message:"Could not load the graph health check.");}finally{c(!1);}},[]);return(0,i.useEffect)(()=>{p();},[p]),(0,r.jsxs)("div",{style:{padding:12,height:"100%",overflowY:"auto"},"aria-busy":o,children:[(0,r.jsxs)("header",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:10},children:[(0,r.jsx)("h2",{style:{margin:0,fontSize:13,fontWeight:600,color:"var(--fg)",flexGrow:1},children:"Graph health"}),(0,r.jsx)("button",{type:"button",className:"arun-btn",onClick:()=>void p(),"aria-label":"Re-run the graph health check",style:{minHeight:24},children:"Refresh"})]}),o&&(0,r.jsx)("p",{style:{fontSize:12,color:"var(--fg-muted)"},"aria-live":"polite",children:"Running health check…"}),null!==d&&(0,r.jsxs)("div",{className:"lk-alert",role:"alert",children:[d,(0,r.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>void p(),children:"Retry"})]}),!o&&null===d&&null!==a&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("p",{style:{fontSize:11,color:"var(--fg-faint)",margin:"0 0 10px"},children:["Checked at"," ",(0,r.jsx)("time",{dateTime:new Date(a.checkedAt).toISOString(),children:new Date(a.checkedAt).toLocaleString()}),"."]}),(0,r.jsx)("div",{className:"rb-rows",style:{marginBottom:14},children:aR.filter(e=>{var t;return(null!=(t=a.totals[e])?t:0)>0;}).map(e=>{var t;return(0,r.jsxs)("div",{className:"rb-row",children:[(0,r.jsx)("span",{className:"rb-row-k",children:e}),(0,r.jsx)("span",{className:"rb-row-v mono",children:String(null!=(t=a.totals[e])?t:0)})]},e);})}),0===(t=a.findings).orphanedEndpoints.length+t.staleRelationships.length+t.blockedRelationships.length+t.failedRelationships.length+t.invalidReferences.length+t.cycleParticipants.length?(0,r.jsxs)("div",{className:"lk-empty",children:[(0,r.jsx)("p",{className:"lk-empty-title",children:"Healthy"}),(0,r.jsx)("p",{className:"lk-empty-body",children:"No relationship-graph defects were found."})]}):(0,r.jsxs)(r.Fragment,{children:[[{key:"invalid",label:"Invalid references",help:"An endpoint no longer resolves to a live workspace object.",items:(n=a.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,r.jsx)(h5,{category:e,onSelectRelationship:l},e.key)),(0,r.jsx)(h8,{findings:a.findings})]})]})]});}let h7={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 fe(e){return"object"==typeof e&&null!==e&&!Array.isArray(e);}function ft(e){return"string"==typeof e&&e.length>0;}function fn(e,t,n){return void 0===n?{code:e,message:t}:{code:e,field:n,message:t};}function fl(e,t,n){return fe(e)?ft(e.kind)?ft(e.id)?!!ft(e.workspaceId)||(n.push(fn("denied/schema-version-unsupported",`${t}.workspaceId must be a non-empty string`,`${t}.workspaceId`)),!1):(n.push(fn("denied/schema-version-unsupported",`${t}.id must be a non-empty string`,`${t}.id`)),!1):(n.push(fn("denied/schema-version-unsupported",`${t}.kind must be a non-empty string`,`${t}.kind`)),!1):(n.push(fn("denied/schema-version-unsupported",`${t} must be an object`,t)),!1);}function fa(e,t,n){ft(e[t])||n.push(fn("denied/schema-version-unsupported",`${t} must be a non-empty string`,t));}function fr(e,t){let n=e.kind;return aN.includes(n)?null:fn("denied/schema-version-unsupported",`${t}.kind is not a known object kind`,`${t}.kind`);}function fi(e,t,n){"missing"===t?n.push(fn("source"===e?"denied/non-existent-source":"denied/non-existent-target",`${e} endpoint does not exist`,e)):"tombstoned"===t?n.push(fn("denied/endpoint-tombstoned",`${e} endpoint has been tombstoned`,e)):"retired"===t?n.push(fn("denied/endpoint-retired",`${e} endpoint has been retired`,e)):"unavailable"===t&&n.push(fn("denied/endpoint-unavailable",`${e} endpoint is unavailable`,e));}function fs(e,t){let n=e.kind;return aS.includes(n)?null:fn("denied/object-kind-not-yet-supported",`${t}.kind "${n}" is reserved for a future release`,`${t}.kind`);}function fo(){return{type:"reads-context",sourceKind:"workflow-run",sourceId:"",targetKind:"memory",targetId:"",summary:""};}let fc=new Set(["denied/path-not-contained","denied/cross-workspace","denied/payload-content-not-permitted"]);function fd(e){return(null==e?void 0:e.codes.some(e=>fc.has(e)))===!0;}function fu(e){let{onClose:t}=e,[n,l]=(0,i.useState)(fo),[a,s]=(0,i.useState)([]),[o,c]=(0,i.useState)(null),[d,u]=(0,i.useState)(!1),[p,m]=(0,i.useState)(!1),h=(0,i.useRef)(null),f="rel-create-dialog-title",g="rel-create-dialog-desc",v=(0,i.useCallback)(e=>{let t=h.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")),l=n[0],a=n[n.length-1];"Tab"===e.key&&(e.shiftKey?document.activeElement===l&&(e.preventDefault(),null==a||a.focus()):document.activeElement===a&&(e.preventDefault(),null==l||l.focus()));},[]),b=(0,i.useCallback)(e=>{"Escape"===e.key&&t(null);},[t]);(0,i.useEffect)(()=>{let e=h.current;if(null!==e)return e.addEventListener("keydown",v),e.addEventListener("keydown",b),()=>{e.removeEventListener("keydown",v),e.removeEventListener("keydown",b);};},[v,b]),(0,i.useEffect)(()=>{if(0===n.sourceId.length||0===n.targetId.length)return void s([]);let e=function(e){let t=function(e){var t;if(!fe(e))return{errors:[fn("denied/schema-version-unsupported","relationship must be an object")]};let n=[];fa(e,"id",n),fa(e,"workspaceId",n),fa(e,"createdAt",n),fa(e,"updatedAt",n),(!("number"==typeof(t=e.etag)&&Number.isInteger(t)&&Number.isFinite(t))||e.etag<0)&&n.push(fn("denied/schema-version-unsupported","etag must be a non-negative finite integer","etag"));let l=fl(e.source,"source",n),a=fl(e.target,"target",n);return!(n.length>0)&&l&&a?{errors:[],value:{record:e,source:e.source,target:e.target}}:{errors:n};}(e);if(!t.value)return{ok:!1,errors:t.errors};let{record:n,source:l,target:a}=t.value,r=function(e,t,n){let l,a,r="1"!==e.schemaVersion?fn("denied/schema-version-unsupported",'schemaVersion must be the literal "1"',"schemaVersion"):null;if(r)return[r];let i=ft(l=e.type)?aC.includes(l)?null:fn("denied/schema-version-unsupported","type is not a known relationship type","type"):fn("denied/schema-version-unsupported","type must be a non-empty string","type");if(i)return[i];let s=fr(t,"source"),o=fr(n,"target");if(null!==s||null!==o){let e=[];return null!==s&&e.push(s),null!==o&&e.push(o),e;}let c=ft(a=e.lifecycleState)?aR.includes(a)?null:fn("denied/schema-version-unsupported","lifecycleState is not a known lifecycle state","lifecycleState"):fn("denied/schema-version-unsupported","lifecycleState must be a non-empty string","lifecycleState");return c?[c]:null;}(n,l,a);if(r)return{ok:!1,errors:r};let i=function(e){if(!(null==e?void 0:e.endpointResolver))return null;let t=[];return"missing"===e.endpointResolver.source&&fi("source",e.endpointResolver.source,t),"missing"===e.endpointResolver.target&&fi("target",e.endpointResolver.target,t),t;}(void 0);if(null!==i&&i.length>0)return{ok:!1,errors:i};let s=function(e,t,n,l){var a,r,i,s,o;let c,d,u,p,m,h,f=[],g=e.type,v=e.lifecycleState,b=fs(t,"source");b&&f.push(b);let y=fs(n,"target");y&&f.push(y),null===b&&null===y&&(a=t.kind,r=n.kind,"denied/source-kind-not-allowed"===(d=(c=aI[g]).validSourceKinds.includes(a)?c.validTargetKinds.includes(r)?null:"denied/target-kind-not-allowed":"denied/source-kind-not-allowed")?f.push(fn("denied/source-kind-not-allowed",`source.kind "${t.kind}" is not permitted for type "${g}"`,"source.kind")):"denied/target-kind-not-allowed"===d&&f.push(fn("denied/target-kind-not-allowed",`target.kind "${n.kind}" is not permitted for type "${g}"`,"target.kind")));let x=(u=null==l?void 0:l.cardinalityCounts)?"produces-evidence"===g&&"number"==typeof u.producesEvidenceForSource&&u.producesEvidenceForSource>=1?fn("denied/cardinality-exceeded","produces-evidence already exists for this source workflow-run"):"starts-workflow"===g&&"number"==typeof u.startsWorkflowForTarget&&u.startsWorkflowForTarget>=1?fn("denied/cardinality-exceeded","starts-workflow already exists for this target workflow-run"):null:null;x&&f.push(x),(p=t.kind===n.kind&&t.id===n.id?fn("denied/cycle-forbidden","source and target refer to the same endpoint"):null)&&f.push(p),(m="depends-on"===g&&(null==l?void 0:l.dependsOnReverseEdgeExists)===!0?fn("denied/cycle-forbidden","depends-on reverse edge already exists for this endpoint pair"):null)&&f.push(m);let w=(i=e.workspaceId,t.workspaceId!==i||n.workspaceId!==i?fn("denied/cross-workspace","source and target must be in the relationship's workspace"):null);w&&f.push(w);let j=void 0===(h=null==l?void 0:l.previousLifecycleState)||h7[h].includes(v)?null:fn("denied/lifecycle-illegal-transition",`transition from ${h} to ${v} is not permitted`,"lifecycleState");for(let t of(j&&f.push(j),s=l,o=f,(null==s?void 0:s.endpointResolver)&&("missing"!==s.endpointResolver.source&&fi("source",s.endpointResolver.source,o),"missing"!==s.endpointResolver.target&&fi("target",s.endpointResolver.target,o)),function(e){let t=[];if(void 0===e.metadata||null===e.metadata)return t;if(!fe(e.metadata))return t.push(fn("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 l of aE)if(e.includes(l)){t.push(fn("denied/payload-content-not-permitted","metadata may not carry endpoint content",`metadata.${n}`));break;}}return t;}(e)))f.push(t);return f;}(n,l,a,void 0);return s.length>0?{ok:!1,errors:s}:{ok:!0,value:n};}({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?s([]):s(e.errors.map(e=>e.message));},[n]);let y=(0,i.useRef)(null),x=(0,i.useRef)(0);(0,i.useEffect)(()=>{x.current+=1;let e=x.current;return(null!==y.current&&clearTimeout(y.current),0===n.sourceId.length||0===n.targetId.length||a.length>0)?void m(!1):(y.current=setTimeout(async()=>{m(!0);try{if(await aD({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!==x.current)return;c(e=>fd(e)?e:null);}catch(t){if(e!==x.current)return;t instanceof aA&&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===x.current&&m(!1);}},250),()=>{null!==y.current&&clearTimeout(y.current);});},[n,a]),(0,i.useEffect)(()=>{c(e=>(null==e?void 0:e.source)!=="submit"||fd(e)?e:null);},[n]);let w=n.sourceId.trim().length>0&&n.targetId.trim().length>0&&0===a.length&&null===o&&!d,j=(0,i.useCallback)(async()=>{if(w){u(!0),c(null);try{let e=crypto.randomUUID(),{relationship:l}=await aM({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(l);}catch(e){e instanceof aA?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:[a$]});}finally{u(!1);}}},[w,n,t]),k=(0,i.useCallback)(e=>{"Enter"===e.key&&(e.ctrlKey||e.metaKey)&&j();},[j]),N=aI[n.type],S=fd(o),C=[a.length>0?"rel-create-client-hints":null,null!==o?"rel-create-server-denial":null].filter(e=>null!==e),R=(0,r.jsx)("div",{className:"cmdk-overlay",onPointerDown:()=>t(null),"data-testid":"rel-create-overlay",children:(0,r.jsxs)("div",{ref:h,role:"dialog","aria-modal":"true","aria-labelledby":f,"aria-describedby":g,className:"cmdk",style:{maxWidth:480,width:"100%"},onPointerDown:e=>e.stopPropagation(),onKeyDown:k,"data-testid":"rel-create-dialog",children:[(0,r.jsxs)("div",{className:"cmdk-input",style:{borderBottom:"1px solid var(--line)"},children:[(0,r.jsx)("span",{id:f,style:{fontWeight:600,fontSize:14,color:"var(--fg)"},children:"Create relationship"}),(0,r.jsx)("span",{id:g,className:"visually-hidden",children:"Create a new relationship between two workspace endpoints."}),(0,r.jsx)("button",{type:"button",className:"palette-x",onClick:()=>t(null),"aria-label":"Close",title:"Close",style:{marginLeft:"auto"},children:(0,r.jsx)($.F.close,{size:16})})]}),(0,r.jsxs)("div",{style:{padding:"12px 16px",display:"flex",flexDirection:"column",gap:10},children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{htmlFor:"rel-type",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Type"}),(0,r.jsx)(ln.A,{value:n.type,ariaLabel:"Relationship type",autoFocus:!0,menuTitle:"Relationship type",triggerStyle:{width:"100%",background:"var(--inset)",border:"1px solid var(--line)",borderRadius:4,padding:"4px 8px",minHeight:24,color:"var(--fg)",fontSize:13},sections:[{options:aC.map(e=>({value:e,label:aI[e].displayName}))}],onValueChange:e=>l(t=>({...t,type:e}))}),(0,r.jsx)("div",{style:{fontSize:11,color:"var(--fg-muted)",marginTop:3},children:N.semantics})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:"var(--space-3)"},children:[(0,r.jsxs)("div",{style:{flex:"0 0 140px"},children:[(0,r.jsx)("label",{htmlFor:"rel-src-kind",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Source kind"}),(0,r.jsx)("select",{id:"rel-src-kind",value:n.sourceKind,onChange:e=>l(t=>({...t,sourceKind:e.target.value})),style:{width:"100%",background:"var(--inset)",border:"1px solid var(--line)",borderRadius:4,padding:"4px 8px",minHeight:24,color:"var(--fg)",fontSize:12},"aria-label":"Source endpoint kind",children:aS.map(e=>(0,r.jsx)("option",{value:e,children:e},e))})]}),(0,r.jsxs)("div",{style:{flex:1},children:[(0,r.jsx)("label",{htmlFor:"rel-src-id",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Source ID"}),(0,r.jsx)("input",{id:"rel-src-id",type:"text",value:n.sourceId,onChange:e=>l(t=>({...t,sourceId:e.target.value})),placeholder:"endpoint id",style:{width:"100%",background:"var(--inset)",border:"1px solid var(--line)",borderRadius:4,padding:"4px 8px",minHeight:24,color:"var(--fg)",fontSize:12},"aria-label":"Source endpoint ID","aria-describedby":"rel-src-kind"})]})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:"var(--space-3)"},children:[(0,r.jsxs)("div",{style:{flex:"0 0 140px"},children:[(0,r.jsx)("label",{htmlFor:"rel-tgt-kind",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Target kind"}),(0,r.jsx)("select",{id:"rel-tgt-kind",value:n.targetKind,onChange:e=>l(t=>({...t,targetKind:e.target.value})),style:{width:"100%",background:"var(--inset)",border:"1px solid var(--line)",borderRadius:4,padding:"4px 8px",minHeight:24,color:"var(--fg)",fontSize:12},"aria-label":"Target endpoint kind",children:aS.map(e=>(0,r.jsx)("option",{value:e,children:e},e))})]}),(0,r.jsxs)("div",{style:{flex:1},children:[(0,r.jsx)("label",{htmlFor:"rel-tgt-id",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Target ID"}),(0,r.jsx)("input",{id:"rel-tgt-id",type:"text",value:n.targetId,onChange:e=>l(t=>({...t,targetId:e.target.value})),placeholder:"endpoint id",style:{width:"100%",background:"var(--inset)",border:"1px solid var(--line)",borderRadius:4,padding:"4px 8px",minHeight:24,color:"var(--fg)",fontSize:12},"aria-label":"Target endpoint ID","aria-describedby":"rel-tgt-kind"})]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{htmlFor:"rel-summary",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Summary (optional, ≤240 chars)"}),(0,r.jsx)("textarea",{id:"rel-summary",value:n.summary,maxLength:240,rows:2,onChange:e=>l(t=>({...t,summary:e.target.value})),style:{width:"100%",background:"var(--inset)",border:"1px solid var(--line)",borderRadius:4,padding:"4px 8px",minHeight:24,color:"var(--fg)",fontSize:12,resize:"vertical"},"aria-label":"Relationship summary"})]}),a.length>0&&(0,r.jsx)("div",{id:"rel-create-client-hints",className:"lk-alert",role:"status","aria-live":"polite","data-testid":"client-validation-hints",children:a.map((e,t)=>(0,r.jsx)("div",{style:{fontSize:12},children:e},t))}),p&&(0,r.jsx)("div",{style:{fontSize:12,color:"var(--fg-muted)"},"aria-live":"polite",children:"Validating…"}),null!==o&&(0,r.jsxs)("div",{id:"rel-create-server-denial",className:"lk-alert",role:"alert","aria-live":"assertive","data-testid":"server-denial-banner",children:[o.codes.map((e,t)=>{var n;return(0,r.jsxs)("div",{style:{marginBottom:6*(t<o.codes.length-1)},children:[(0,r.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--fg-muted)",marginBottom:2},children:e}),(0,r.jsx)("div",{style:{fontSize:13,color:"var(--fg)"},children:null!=(n=o.messages[t])?n:e})]},e);}),S&&(0,r.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>c(null),style:{marginTop:6},children:"Dismiss"})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:"var(--space-4)",justifyContent:"flex-end",marginTop:4},children:[(0,r.jsx)("button",{type:"button",className:"arun-btn",onClick:()=>t(null),style:{minWidth:24,minHeight:24},children:"Cancel"}),(0,r.jsx)("button",{type:"button",className:`arun-btn${w?" primary":""}`,"aria-disabled":!w,"aria-describedby":C.length>0?C.join(" "):void 0,onClick:()=>void j(),"aria-busy":d,style:{minWidth:24,minHeight:24},children:d?"Creating…":"Create"})]})]})]})});return"u"<typeof document?R:(0,n9.createPortal)(R,document.body);}let fp={};function fm(){var e;let{activityMap:t,throughputMap:n,animate:l}=function(){let e=(0,i.useRef)(new Map()),t=(0,i.useRef)("u"<typeof document||"visible"===document.visibilityState),[n,l]=(0,i.useState)(new Map()),[a,r]=(0,i.useState)(new Map()),s=(0,i.useRef)(new Map()),o=(0,i.useRef)(new Map()),[c,d]=(0,i.useState)(()=>window.matchMedia("(prefers-reduced-motion: reduce)").matches),[u,p]=(0,i.useState)(!1),m=(0,i.useCallback)(()=>{p(!0);},[]),h=(0,i.useCallback)((t,n)=>{let a=new Map(s.current),i=new Set(),c=new Set(),d=!1;for(let[l,r]of a){var u;let s=t-(null!=(u=e.current.get(l))?u:0);s>=6e4&&"inactive"!==r&&(a.set(l,"inactive"),c.add(l),d=!0),!n&&s>=12e4&&(a.delete(l),i.add(l),c.add(l),d=!0);}if(a.size>512)for(let t of Array.from(a.keys()).sort((t,n)=>{var l,r;let i=a.get(t),s=a.get(n);return"inactive"===i&&"inactive"!==s?-1:"inactive"!==i&&"inactive"===s?1:(null!=(l=e.current.get(t))?l:0)-(null!=(r=e.current.get(n))?r:0);}).slice(0,a.size-512))a.delete(t),i.add(t),c.add(t),d=!0;if(d&&(s.current=a,l(a)),i.size>0)for(let t of i)e.current.delete(t);if(c.size>0){let e=!1,t=new Map(o.current);for(let n of c)t.delete(n)&&(e=!0);e&&(o.current=t,r(t));}},[]);(0,i.useEffect)(()=>{let e=window.matchMedia("(prefers-reduced-motion: reduce)"),t=e=>{d(e.matches);};return e.addEventListener("change",t),()=>{e.removeEventListener("change",t);};},[]);let f=(0,i.useCallback)(n=>{var a;if(!t.current)return;let i=Date.now();i-(null!=(a=e.current.get(n.id))?a:0)<2e3||(e.current.set(n.id,i),l(e=>{let t=new Map(e);return t.set(n.id,n.state),s.current=t,t;}),"high-throughput"===n.state&&void 0!==n.count?r(e=>{let t=new Map(e);return t.set(n.id,n.count),o.current=t,t;}):r(e=>{if(!e.has(n.id))return e;let t=new Map(e);return t.delete(n.id),o.current=t,t;}));},[]);return(0,i.useEffect)(()=>{let e=setInterval(()=>{t.current&&h(Date.now(),!1);},15e3);return()=>{clearInterval(e);};},[h]),(0,i.useEffect)(()=>{if("u"<typeof document)return;let e=()=>{t.current="visible"===document.visibilityState,t.current&&h(Date.now(),!0);};return t.current="visible"===document.visibilityState,document.addEventListener("visibilitychange",e),()=>{document.removeEventListener("visibilitychange",e);};},[h]),(0,i.useEffect)(()=>{let e=!1,n=null,l=null;function a(e){let t;try{t=JSON.parse(e);}catch{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 aE.some(e=>t.includes(e));}(n)||e(t[n]))return!0;return!1;}(e))return null;let n={};for(let t of h4)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&&f(n);}function r(){null!==l&&(clearTimeout(l),l=null);}function i(){null==n||n.close(),n=null;}function s(){!e&&null===l&&t.current&&(l=setTimeout(()=>{l=null,o();},5e3));}function o(){if(!e&&t.current){try{n=new EventSource("/api/relationships/events");}catch{s();return;}n.addEventListener("relationship:activity",e=>{a(e.data);}),n.onmessage=e=>{a(e.data);},n.onerror=()=>{e||(i(),s());};}}o();let c=()=>{if(t.current="visible"===document.visibilityState,!t.current){r(),i();return;}h(Date.now(),!0),null===n&&o();};return document.addEventListener("visibilitychange",c),()=>{e=!0,document.removeEventListener("visibilitychange",c),r(),i();};},[void 0,f,h]),{activityMap:n,throughputMap:a,animate:!c&&!u,disable:m};}(),[a,s]=(0,i.useState)(!1),[o,c]=(0,i.useState)(fp),d=o.relFocus,u=null!=(e=o.relDensity)?e:"minimal",[p,m]=(0,i.useState)(!1),h=(0,i.useRef)(null),f=(0,i.useRef)(!1),g=(0,i.useRef)(null),[v,b]=(0,i.useState)(!1),y=(0,i.useCallback)(e=>{c(t=>{let n={...t,...e},l={};for(let[e,t]of Object.entries(n))void 0!==t&&""!==t&&(l[e]=t);return l;});},[]),x=(0,i.useCallback)(e=>{y({relFocus:e});},[y]),w=(0,i.useCallback)(()=>{y({relFocus:void 0});},[y]),j=(0,i.useCallback)(e=>{y({relFocus:e});},[y]),k=(0,i.useCallback)(e=>{f.current=!0,m(!1),null!==e&&y({relFocus:e.id});},[y]);return(0,i.useEffect)(()=>{var e;!p&&f.current&&(f.current=!1,null==(e=h.current)||e.focus());},[p]),(0,i.useEffect)(()=>{let e=window.matchMedia("(prefers-contrast: more)"),t=e=>{s(e);};t(e.matches);let n=e=>{t(e.matches);};return e.addEventListener("change",n),()=>e.removeEventListener("change",n);},[]),(0,i.useEffect)(()=>{let e=g.current;if(null===e)return;let t=e=>{let t=e.target;if(!("INPUT"===t.tagName||"TEXTAREA"===t.tagName||"SELECT"===t.tagName||t.isContentEditable)&&"Escape"===e.key){if(p||null!==document.querySelector('[role="dialog"][aria-modal="true"]'))return;w();}};return e.addEventListener("keydown",t),()=>e.removeEventListener("keydown",t);},[p,w]),(0,r.jsxs)(r.Fragment,{children:[p&&(0,r.jsx)(fu,{onClose:k}),(0,r.jsxs)("div",{ref:g,style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden",background:"var(--bg)"},children:[(0,r.jsxs)("header",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 12px",borderBottom:"1px solid var(--line)",flexShrink:0},children:[(0,r.jsx)("button",{type:"button",className:"arun-btn",onClick:()=>b(e=>!e),"aria-pressed":v,"aria-label":"Toggle the graph health view",style:{flex:"0 0 auto",minHeight:24,marginRight:"auto"},children:v?"Hide health":"Graph health"}),(0,r.jsx)("button",{ref:h,type:"button",className:"arun-btn primary",onClick:()=>m(!0),"aria-label":"Create new relationship",style:{flex:"0 0 auto",minWidth:24,minHeight:24},children:"+ New relationship"})]}),(0,r.jsxs)("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[(0,r.jsx)("div",{style:{flex:"0 0 280px",borderRight:"1px solid var(--line)",overflowY:"auto"},children:(0,r.jsx)(hL,{filters:o,selectedId:d,onSelect:x,onFilterChange:y,activityMap:t,throughputMap:n,animateBadges:l,highContrast:a})}),(0,r.jsx)("div",{style:{flex:1,overflowY:"auto"},children:v?(0,r.jsx)(h9,{onSelectRelationship:e=>{b(!1),x(e);}}):(0,r.jsx)(h2,{relationshipId:null!=d?d:null,densityMode:u,onClearFocus:w,onViewImpact:j,activityMap:t,throughputMap:n,animateBadges:l,highContrast:a})})]})]})]});}var fh=n(65587),ff=n.n(fh);let fg={NOT_FOUND:"The memory could not be found. It may have been deleted.",BAD_REQUEST:"The request was rejected as invalid. Adjust the input and try again.",CONFLICT:"The memory changed in the meantime. Reload the page and try again.",GOVERNANCE_ERROR:"Governance rules blocked this action.",MEMORY_ERROR:"The memory store reported an error. Retry, or check the server log.",MEMORY_UNAVAILABLE:"The memory store is currently unavailable. Retry in a moment.",PAYLOAD_TOO_LARGE:"The submitted content is too large. Shorten it and try again.",INTERNAL:"Something went wrong on the server. Retry, or check the server log."};function fv(e){if(e instanceof m.hD){let t=fg[e.code];return void 0!==t?`${t} (${e.code})`:e.message.trim().length>0?`${e.message} (${e.code})`:`Something went wrong. Retry, or check the server log. (${e.code})`;}return e instanceof Error&&e.message.trim().length>0?e.message:"An unexpected error occurred.";}let fb={jaccardThreshold:.85,staleConfidenceThreshold:.3,maxAgeMs:7776e6,maxClustersPerRun:100,maxRecordsPerRun:1e3};function fy(e,t){return`${e.toString()} ${1===e?t:`${t}s`}`;}function fx(e){return"completed"===e||"failed"===e||"canceled"===e||"skipped"===e;}function fw(e){return void 0===e?"—":new Date(e).toLocaleString();}function fj(e){let{id:t,onOpenDetail:n}=e;return void 0!==n?(0,r.jsx)("button",{type:"button",className:"mc-id-link mc-link-button",title:t,onClick:()=>n(t),children:t}):(0,r.jsx)(ff(),{href:`/memoriaviva/detail?id=${encodeURIComponent(t)}`,className:"mc-id-link",title:t,children:t});}function fk(e){let{ids:t,onOpenDetail:n}=e;return(0,r.jsx)(r.Fragment,{children:t.map((e,t)=>(0,r.jsxs)(i.Fragment,{children:[t>0?", ":null,(0,r.jsx)(fj,{id:e,onOpenDetail:n})]},`${t.toString()}:${e}`))});}function fN(e){let{item:t,onOpenDetail:n}=e;return void 0===t.proposedAction?(0,r.jsx)(r.Fragment,{children:"No automatic action proposed."}):"merge"===t.proposedAction.kind?(0,r.jsxs)(r.Fragment,{children:["Merge into ",(0,r.jsx)(fj,{id:t.proposedAction.winner,onOpenDetail:n}),"; replace ",(0,r.jsx)(fk,{ids:t.proposedAction.losers,onOpenDetail:n}),"."]}):(0,r.jsxs)(r.Fragment,{children:["Supersede ",(0,r.jsx)(fj,{id:t.proposedAction.older,onOpenDetail:n})," with"," ",(0,r.jsx)(fj,{id:t.proposedAction.newer,onOpenDetail:n}),"."]});}function fS(e){let{flag:t,onOpenDetail:n}=e;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(fj,{id:t.memoryId,onOpenDetail:n})," — ",t.reason]});}function fC(e){let{label:t,name:n,value:l,min:a,max:s,step:o,help:c,disabled:d=!1,onChange:u}=e,p=(0,i.useId)(),m=e=>{var t;let r=null!=o?o:1,i=Number.isFinite(l)?l:null!=a?a:0,c=Math.min(function(e){let[,t=""]=e.toString().split(".");return t.length;}(r)+2,8);u(n,(t=Number((i+e*r).toFixed(c)),void 0!==a&&t<a?a:void 0!==s&&t>s?s:t));};return(0,r.jsxs)("div",{style:{display:"grid",gap:"var(--space-3)"},children:[(0,r.jsxs)("label",{style:{display:"grid",gap:"var(--space-3)"},children:[(0,r.jsx)("span",{className:"mc-dialog-label",children:t}),(0,r.jsxs)("span",{className:"number-control",children:[(0,r.jsx)("input",{type:"number",inputMode:"decimal",className:"mc-dialog-input number-control-input",name:n,value:Number.isFinite(l)?l:"",min:a,max:s,step:o,disabled:d,"aria-describedby":p,onChange:e=>{u(n,Number(e.target.value));},onWheel:e=>{d||0===e.deltaY||(e.preventDefault(),m(e.deltaY<0?1:-1));}}),(0,r.jsx)(mx,{label:t.toLowerCase(),disabled:d,onStepUp:()=>m(1),onStepDown:()=>m(-1)})]})]}),(0,r.jsx)("span",{id:p,style:{color:"var(--fg-muted)",fontSize:12},children:c})]});}function fR(e){var t,n,l,a,s,o,c,d,u,p;let{startJobImpl:m=lj,fetchJobImpl:h=lk,cancelJobImpl:f=lN,pollIntervalMs:g=2e3,onBack:v,onOpenDetail:b}=e,[y,x]=(0,i.useState)(fb),[w,j]=(0,i.useState)(null),[k,N]=(0,i.useState)(!1),[S,C]=(0,i.useState)(!1),[R,I]=(0,i.useState)(!1),[E,$]=(0,i.useState)(null),[A,T]=(0,i.useState)(null),F=null!=(t=null==w?void 0:w.job)?t:null,D=null!==F&&!fx(F.state),M=(0,i.useMemo)(()=>{var e,t,n;if(null===F)return null;let l=F.result;return{reviewCount:null!=(e=null==l?void 0:l.reviewItems.length)?e:0,staleCount:null!=(t=null==l?void 0:l.staleFlags.length)?t:0,edgeCount:null!=(n=null==l?void 0:l.edgesProposed.length)?n:0};},[F]),P=(0,i.useCallback)((e,t)=>{x(n=>({...n,[e]:t}));},[]),L=(0,i.useCallback)(async e=>{C(!0);try{let t=await h(e);j(t.job),T(null);}catch(e){T(fv(e));}finally{C(!1);}},[h]);(0,i.useEffect)(()=>{if(null===F||fx(F.state))return;let e=window.setInterval(()=>{L(F.id);},g);return()=>{window.clearInterval(e);};},[F,g,L]);let q=(0,i.useCallback)(async e=>{if(e.preventDefault(),!k&&!D){N(!0),$(null),T(null);try{let e=await m(y);j(e.job);}catch(e){$(fv(e));}finally{N(!1);}}},[y,m,k,D]),z=(0,i.useCallback)(async()=>{if(null!==F&&!R){I(!0),T(null);try{let e=await f(F.id);j(e.job);}catch(e){T(fv(e));}finally{I(!1);}}},[F,f,R]);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("header",{className:"lk-header mc-consolidation-header",children:[(0,r.jsxs)("div",{className:"mc-consolidation-heading",style:{display:"grid",gap:"var(--space-2)"},children:[(0,r.jsx)("h1",{className:"lk-title",children:"MemoriaViva Consolidation"}),(0,r.jsx)("p",{style:{margin:0,color:"var(--fg-muted)"},children:"Start a bounded consolidation job, inspect its output, and cancel it while it is still queued or running."})]}),void 0!==v?(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost lk-btn-lg","aria-label":"Back to MemoriaViva",onClick:v,children:"Back"}):(0,r.jsx)(ff(),{href:"/memoriaviva",className:"lk-btn lk-btn-ghost lk-btn-lg","aria-label":"Back to MemoriaViva",children:"Back"})]}),(0,r.jsxs)("div",{className:"mc-consolidation-scroll",children:[(0,r.jsx)("section",{"aria-label":"Consolidation settings",style:{display:"grid",gap:16,padding:16,border:"1px solid var(--line)",borderRadius:14,background:"var(--card)"},children:(0,r.jsxs)("form",{onSubmit:q,style:{display:"grid",gap:16},children:[(0,r.jsxs)("div",{style:{display:"grid",gap:"var(--space-5)",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))"},children:[(0,r.jsx)(fC,{label:"Jaccard threshold",name:"jaccardThreshold",value:y.jaccardThreshold,min:0,max:1,step:.01,disabled:k||D,help:"Similarity floor for near-duplicate detection.",onChange:P}),(0,r.jsx)(fC,{label:"Stale confidence threshold",name:"staleConfidenceThreshold",value:y.staleConfidenceThreshold,min:0,max:1,step:.01,disabled:k||D,help:"Memories at or below this confidence are flagged stale.",onChange:P}),(0,r.jsx)(fC,{label:"Max age (days)",name:"maxAgeMs",value:y.maxAgeMs/864e5,min:0,step:1,disabled:k||D,help:"Memories older than this are checked for staleness.",onChange:(e,t)=>{P(e,864e5*t);}}),(0,r.jsx)(fC,{label:"Max clusters per run",name:"maxClustersPerRun",value:y.maxClustersPerRun,min:0,max:1e3,step:1,disabled:k||D,help:"Hard bound on duplicate clusters inspected in one run.",onChange:P}),(0,r.jsx)(fC,{label:"Max records per run",name:"maxRecordsPerRun",value:y.maxRecordsPerRun,min:0,max:1e3,step:1,disabled:k||D,help:"Hard bound on accepted records admitted to one scan.",onChange:P})]}),null!==E?(0,r.jsx)("div",{role:"alert",className:"lk-alert",children:E}):null,(0,r.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",gap:"var(--space-5)"},children:[(0,r.jsx)("button",{type:"submit",className:"lk-btn lk-btn-primary","aria-disabled":k||D,"aria-busy":k,children:k?"Starting…":"Start consolidation"}),(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost","aria-disabled":null===F||S,"aria-busy":S,onClick:()=>{null===F||S||L(F.id);},children:S?"Refreshing…":"Refresh status"}),D?(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost","aria-disabled":R,"aria-busy":R,onClick:()=>{z();},children:R?"Canceling…":"Cancel job"}):null]})]})}),(0,r.jsx)("section",{"aria-label":"Consolidation job status",style:{display:"grid",gap:16,padding:16,border:"1px solid var(--line)",borderRadius:14,background:"var(--card)"},children:null===F?(0,r.jsx)("p",{style:{margin:0,color:"var(--fg-muted)"},children:"No consolidation job started yet."}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{style:{display:"grid",gap:"var(--space-5)",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))"},children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{color:"var(--fg-muted)",fontSize:12},children:"State"}),(0,r.jsx)("div",{role:"status","aria-live":"polite","aria-atomic":"true",style:{fontWeight:700,textTransform:"capitalize"},children:F.state})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{color:"var(--fg-muted)",fontSize:12},children:"Job ID"}),(0,r.jsx)("div",{style:{wordBreak:"break-all"},children:F.id})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{color:"var(--fg-muted)",fontSize:12},children:"Started"}),(0,r.jsx)("div",{children:fw(F.startedAt)})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{color:"var(--fg-muted)",fontSize:12},children:"Completed"}),(0,r.jsx)("div",{children:fw(F.completedAt)})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{color:"var(--fg-muted)",fontSize:12},children:"Clusters inspected"}),(0,r.jsx)("div",{style:{fontVariantNumeric:"tabular-nums"},children:null!=(n=null==(o=F.result)?void 0:o.clustersInspected)?n:0})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{color:"var(--fg-muted)",fontSize:12},children:"Elapsed"}),(0,r.jsx)("div",{style:{fontVariantNumeric:"tabular-nums"},children:(p=null!=(l=null==(c=F.result)?void 0:c.elapsedMs)?l:0)<1e3?`${p.toString()} ms`:`${(p/1e3).toFixed(1)} s`})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{color:"var(--fg-muted)",fontSize:12},children:"Records inspected"}),(0,r.jsxs)("div",{style:{fontVariantNumeric:"tabular-nums"},children:[null!=(a=null==(d=F.result)?void 0:d.recordsInspected)?a:0,(null==(u=F.result)?void 0:u.truncated)===!0?" (truncated)":""]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{style:{color:"var(--fg-muted)",fontSize:12},children:"Memories loaded"}),(0,r.jsx)("div",{style:{fontVariantNumeric:"tabular-nums"},children:null!=(s=null==w?void 0:w.memoryCount)?s:0})]})]}),null!==A?(0,r.jsx)("div",{role:"alert",className:"lk-alert",children:A}):null,void 0!==F.error&&F.error.length>0?(0,r.jsx)("div",{role:"alert",className:"lk-alert",children:F.error}):null,null!==M?(0,r.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",gap:"var(--space-5)"},children:[(0,r.jsx)("span",{className:"mc-badge mc-badge-default",children:fy(M.reviewCount,"review item")}),(0,r.jsx)("span",{className:"mc-badge mc-badge-default",children:fy(M.staleCount,"stale flag")}),(0,r.jsx)("span",{className:"mc-badge mc-badge-default",children:fy(M.edgeCount,"proposed edge")})]}):null]})}),(null==F?void 0:F.result)!==void 0?(0,r.jsxs)("section",{"aria-label":"Consolidation results","aria-live":"polite","aria-atomic":"false",style:{display:"grid",gap:16,gridTemplateColumns:"repeat(auto-fit, minmax(280px, 1fr))"},children:[(0,r.jsxs)("article",{style:{display:"grid",gap:"var(--space-5)",padding:16,border:"1px solid var(--line)",borderRadius:14,background:"var(--card)"},children:[(0,r.jsx)("h2",{className:"lk-section-head",style:{margin:0},children:"Review items"}),0===F.result.reviewItems.length?(0,r.jsx)("p",{style:{margin:0,color:"var(--fg-muted)"},children:"No review items returned."}):(0,r.jsx)("ul",{style:{listStyle:"none",padding:0,margin:0,display:"grid",gap:"var(--space-5)"},children:F.result.reviewItems.map(e=>(0,r.jsxs)("li",{style:{display:"grid",gap:"var(--space-2)"},children:[(0,r.jsx)("strong",{style:{textTransform:"capitalize"},children:e.reason.replaceAll("-"," ")}),(0,r.jsx)("span",{children:(0,r.jsx)(fk,{ids:e.relatedMemoryIds,onOpenDetail:b})}),(0,r.jsx)("span",{style:{color:"var(--fg-muted)"},children:(0,r.jsx)(fN,{item:e,onOpenDetail:b})})]},e.id))})]}),(0,r.jsxs)("article",{style:{display:"grid",gap:"var(--space-5)",padding:16,border:"1px solid var(--line)",borderRadius:14,background:"var(--card)"},children:[(0,r.jsx)("h2",{className:"lk-section-head",style:{margin:0},children:"Stale flags"}),0===F.result.staleFlags.length?(0,r.jsx)("p",{style:{margin:0,color:"var(--fg-muted)"},children:"No stale flags returned."}):(0,r.jsx)("ul",{style:{listStyle:"none",padding:0,margin:0,display:"grid",gap:"var(--space-5)"},children:F.result.staleFlags.map(e=>(0,r.jsx)("li",{children:(0,r.jsx)(fS,{flag:e,onOpenDetail:b})},`${e.memoryId}:${e.reason}`))})]}),(0,r.jsxs)("article",{style:{display:"grid",gap:"var(--space-5)",padding:16,border:"1px solid var(--line)",borderRadius:14,background:"var(--card)"},children:[(0,r.jsx)("h2",{className:"lk-section-head",style:{margin:0},children:"Proposed edges"}),0===F.result.edgesProposed.length?(0,r.jsx)("p",{style:{margin:0,color:"var(--fg-muted)"},children:"No edges proposed."}):(0,r.jsx)("ul",{style:{listStyle:"none",padding:0,margin:0,display:"grid",gap:"var(--space-5)"},children:F.result.edgesProposed.map(e=>(0,r.jsxs)("li",{style:{display:"grid",gap:"var(--space-2)"},children:[(0,r.jsx)("strong",{children:e.kind}),(0,r.jsxs)("span",{children:[(0,r.jsx)(fj,{id:e.fromMemoryId,onOpenDetail:b})," →"," ",(0,r.jsx)(fj,{id:e.toMemoryId,onOpenDetail:b})]}),void 0!==e.provenanceSummary?(0,r.jsx)("span",{style:{color:"var(--fg-muted)"},children:e.provenanceSummary}):null]},e.id))})]})]}):null]})]});}let fI=["user","workspace","project","workflow","global"],fE=["episodic","semantic-fact","procedural","preference","correction","decision","negative","pinned"],f$=["public","confidential","restricted"],fA=["proposed","accepted","rejected","superseded","archived","forgotten","conflicted","expired"],fT={user:"User",workspace:"Workspace",project:"Project",workflow:"Workflow",global:"Global"},fF={episodic:"Episodic","semantic-fact":"Fact",procedural:"Procedural",preference:"Preference",correction:"Correction",decision:"Decision",negative:"Negative",pinned:"Pinned"},fD={proposed:"Proposed",accepted:"Accepted",rejected:"Rejected",superseded:"Superseded",archived:"Archived",forgotten:"Forgotten",conflicted:"Conflicted",expired:"Expired"},fM={public:"Public",confidential:"Confidential",restricted:"Restricted"};function fP(e,t){return e.includes(t)?e.filter(e=>e!==t):[...e,t];}function fL(e){let{label:t,items:n,labels:l,active:a,onToggle:i}=e;return(0,r.jsxs)("div",{className:"mc-filter-row",role:"group","aria-label":`Filter by ${t}`,children:[(0,r.jsx)("span",{className:"mc-filter-label",children:t}),(0,r.jsx)("div",{className:"mc-filter-chips",children:n.map(e=>{let t=a.includes(e);return(0,r.jsx)("button",{type:"button",className:"mc-chip","data-active":String(t),"aria-pressed":t,onClick:()=>{i(e);},children:l[e]},e);})})]});}function fq(e){let{filters:t,onChange:n}=e;return(0,r.jsxs)("section",{className:"mc-filters","aria-label":"Memory filters",children:[(0,r.jsx)(fL,{label:"Scope",items:fI,labels:fT,active:t.scope,onToggle:e=>{n({...t,scope:fP(t.scope,e)});}}),(0,r.jsx)(fL,{label:"Type",items:fE,labels:fF,active:t.type,onToggle:e=>{n({...t,type:fP(t.type,e)});}}),(0,r.jsx)(fL,{label:"Status",items:fA,labels:fD,active:t.status,onToggle:e=>{n({...t,status:fP(t.status,e)});}}),(0,r.jsx)(fL,{label:"Sensitivity",items:f$,labels:fM,active:t.sensitivity,onToggle:e=>{n({...t,sensitivity:fP(t.sensitivity,e)});}})]});}let fz={public:"Public",confidential:"Confidential",restricted:"Restricted"};function fO(e){let{record:t,mode:n="edit",onSave:l,onClose:a,editMemoryImpl:s=lC,correctMemoryImpl:o=lT}=e,[c,d]=(0,i.useState)(t.body),[u,p]=(0,i.useState)(t.tags.join(", ")),[m,h]=(0,i.useState)(t.provenance.sensitivity),[f,g]=(0,i.useState)(!1),[v,b]=(0,i.useState)(null),[y,x]=(0,i.useState)(!1),w=(0,i.useRef)(null),j=(0,i.useRef)(null),k=(0,i.useRef)(null),N=(0,i.useRef)(null),S=(0,i.useId)(),C=(0,i.useId)(),R="correct"===n;(0,i.useEffect)(()=>{var e;return N.current=document.activeElement instanceof HTMLElement?document.activeElement:null,null==(e=w.current)||e.focus(),()=>{var e;null==(e=N.current)||e.focus();};},[]);let I=(0,i.useCallback)(e=>{var t,n,l;if("Escape"===e.key)return void a();if("Tab"!==e.key)return;let r=null==(t=k.current)?void 0:t.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]):not([disabled])');if(void 0===r||0===r.length){e.preventDefault(),null==(n=k.current)||n.focus();return;}let i=r[0],s=r[r.length-1];if(void 0===i||void 0===s){e.preventDefault(),null==(l=k.current)||l.focus();return;}let o=document.activeElement;e.shiftKey||o!==s?e.shiftKey&&o===i&&(e.preventDefault(),s.focus()):(e.preventDefault(),i.focus());},[a]),E=(0,i.useCallback)(e=>{e.target===j.current&&a();},[a]),$=(0,i.useCallback)(async()=>{let e=c.trim();if(0===e.length){var n;b("Body cannot be empty."),x(!0),null==(n=w.current)||n.focus();return;}let a=u.split(",").map(e=>e.trim()).filter(e=>e.length>0);g(!0),b(null);try{if(R){let n=await o(t.id,e);l(n.correction);}else{let n=await s(t.id,{body:e,tags:a,sensitivity:m});l(n.memory);}}catch(e){b(fv(e));}finally{g(!1);}},[c,u,m,t.id,R,o,s,l]);return(0,r.jsx)("div",{ref:j,className:"mc-dialog-backdrop",role:"presentation",onClick:E,children:(0,r.jsxs)("div",{ref:k,role:"dialog","aria-modal":"true","aria-labelledby":S,tabIndex:-1,className:"mc-dialog",onKeyDown:I,children:[(0,r.jsx)("h2",{id:S,className:"mc-dialog-title",children:R?"Correct memory":"Edit memory"}),(0,r.jsxs)("div",{className:"mc-dialog-field",children:[(0,r.jsx)("label",{htmlFor:"edit-body",className:"mc-dialog-label",children:R?"Corrected body":"Body"}),(0,r.jsx)("textarea",{id:"edit-body",ref:w,className:"mc-dialog-textarea",value:c,rows:5,onChange:e=>{d(e.target.value),y&&(x(!1),b(null));},disabled:f,"aria-required":"true","aria-invalid":y?"true":void 0,"aria-describedby":y?C:void 0})]}),R?null:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"mc-dialog-field",children:[(0,r.jsxs)("label",{htmlFor:"edit-tags",className:"mc-dialog-label",children:["Tags ",(0,r.jsx)("span",{className:"mc-dialog-hint",children:"(comma-separated)"})]}),(0,r.jsx)("input",{id:"edit-tags",type:"text",className:"mc-dialog-input",value:u,onChange:e=>{p(e.target.value);},disabled:f})]}),(0,r.jsxs)("div",{className:"mc-dialog-field",children:[(0,r.jsx)("label",{htmlFor:"edit-sensitivity",className:"mc-dialog-label",children:"Sensitivity"}),(0,r.jsx)("select",{id:"edit-sensitivity",className:"mc-dialog-select",value:m,onChange:e=>{h(e.target.value);},disabled:f,children:f$.map(e=>(0,r.jsx)("option",{value:e,children:fz[e]},e))})]})]}),null!==v?(0,r.jsx)("p",{id:C,role:"alert",className:"mc-dialog-error",children:v}):null,(0,r.jsxs)("div",{className:"mc-dialog-actions",children:[(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost",onClick:a,disabled:f,children:"Cancel"}),(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-primary",onClick:()=>{$();},disabled:f,"aria-busy":f,children:f?R?"Submitting…":"Saving…":R?"Submit correction":"Save"})]})]})});}function fB(e){let{record:t,mode:n="forget",onComplete:l,onClose:a,forgetMemoryImpl:s=l$,deleteMemoryImpl:o=lA}=e,[c,d]=(0,i.useState)(!1),[u,p]=(0,i.useState)(null),m=(0,i.useRef)(null),h=(0,i.useRef)(null),f=(0,i.useRef)(null),g=(0,i.useRef)(null),v="delete"===n;(0,i.useEffect)(()=>{var e;return g.current=document.activeElement instanceof HTMLElement?document.activeElement:null,null==(e=m.current)||e.focus(),()=>{var e;null==(e=g.current)||e.focus();};},[]);let b=(0,i.useCallback)(e=>{var t,n,l;if("Escape"===e.key)return void a();if("Tab"!==e.key)return;let r=null==(t=f.current)?void 0:t.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]):not([disabled])');if(void 0===r||0===r.length){e.preventDefault(),null==(n=f.current)||n.focus();return;}let i=r[0],s=r[r.length-1];if(void 0===i||void 0===s){e.preventDefault(),null==(l=f.current)||l.focus();return;}let o=document.activeElement;e.shiftKey||o!==s?e.shiftKey&&o===i&&(e.preventDefault(),s.focus()):(e.preventDefault(),i.focus());},[a]),y=(0,i.useCallback)(e=>{e.target===h.current&&a();},[a]),x=(0,i.useCallback)(async()=>{d(!0),p(null);try{v?await o(t.id,"user-initiated delete from MemoriaViva"):await s(t.id,"user-initiated forget from MemoriaViva"),l();}catch(e){p(fv(e)),d(!1);}},[o,s,v,l,t.id]);return(0,r.jsx)("div",{ref:h,className:"mc-dialog-backdrop",role:"presentation",onClick:y,children:(0,r.jsxs)("div",{ref:f,role:"dialog","aria-modal":"true","aria-labelledby":"forget-dialog-title","aria-describedby":"forget-dialog-desc",tabIndex:-1,className:"mc-dialog",onKeyDown:b,children:[(0,r.jsx)("h2",{id:"forget-dialog-title",className:"mc-dialog-title",children:v?"Delete this memory?":"Forget this memory?"}),(0,r.jsx)("p",{id:"forget-dialog-desc",className:"mc-dialog-body",children:(0,r.jsxs)(r.Fragment,{children:["This action is ",(0,r.jsx)("strong",{children:"permanent"}),". The memory will be removed and a tombstone audit record will be created. You cannot undo this."]})}),(0,r.jsx)("blockquote",{className:"mc-dialog-quote","aria-label":"Memory content to be removed",children:t.body.length>120?`${t.body.slice(0,120)}…`:t.body}),null!==u?(0,r.jsx)("p",{role:"alert",className:"mc-dialog-error",children:u}):null,(0,r.jsxs)("div",{className:"mc-dialog-actions",children:[(0,r.jsx)("button",{ref:m,type:"button",className:"lk-btn lk-btn-ghost",onClick:a,disabled:c,children:"Cancel"}),(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-danger",onClick:()=>{x();},disabled:c,"aria-busy":c,children:c?v?"Deleting…":"Forgetting…":v?"Delete permanently":"Forget permanently"})]})]})});}function fW(e){let{record:t,onRecordChange:n,acceptImpl:l=lF,rejectImpl:a=lD,pinImpl:s=lR,unpinImpl:o=lI,archiveImpl:c=lE,deleteImpl:d=lA,correctImpl:u=lT}=e,[p,m]=(0,i.useState)(null),[h,f]=(0,i.useState)(null),[g,v]=(0,i.useState)(null),[b,y]=(0,i.useState)(!1),[x,w]=(0,i.useState)(!1),[j,k]=(0,i.useState)(!1),[N,S]=(0,i.useState)(!1),C=(0,i.useCallback)(async(e,t)=>{if(null===p){m(e),f(null),v(null);try{await t();}catch(e){f(fv(e));}finally{m(null);}}},[p]),R=(0,i.useCallback)(()=>{C("accept",async()=>{n((await l(t.id)).memory);});},[l,n,t.id,C]),I=(0,i.useCallback)(()=>{C("reject",async()=>{n((await a(t.id,"rejected by user in MemoriaViva")).memory);});},[n,t.id,a,C]),E=(0,i.useCallback)(()=>{C("pin",async()=>{n((await s(t.id)).memory);});},[n,s,t.id,C]),$=(0,i.useCallback)(()=>{C("unpin",async()=>{n((await o(t.id)).memory);});},[n,t.id,C,o]),A=(0,i.useCallback)(()=>{C("archive",async()=>{n((await c(t.id,"archived by user in MemoriaViva")).memory);});},[c,n,t.id,C]),T=(0,i.useCallback)(e=>{w(!1),v(`Correction submitted for review: ${e.body}`);},[]),F="proposed"===t.status,D="accepted"===t.status||"superseded"===t.status||"conflicted"===t.status||"expired"===t.status,M="forgotten"===t.status;return(0,r.jsxs)("div",{className:"mc-actions",role:"group","aria-label":"Memory actions",children:[F?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-primary","aria-disabled":null!==p,"aria-busy":"accept"===p,onClick:R,"aria-label":"Approve this memory proposal",children:"accept"===p?"Approving…":"Approve"}),(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost","aria-disabled":null!==p,"aria-busy":"reject"===p,onClick:I,"aria-label":"Reject this memory proposal",children:"reject"===p?"Rejecting…":"Reject"})]}):null,M?null:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost","aria-disabled":null!==p,onClick:()=>{null===p&&(f(null),v(null),y(!0));},"aria-label":"Edit memory body, tags, or sensitivity",children:"Edit"}),(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost","aria-disabled":null!==p,onClick:()=>{null===p&&(f(null),v(null),w(!0));},"aria-label":"Create a correction proposal for this memory",children:"Correct"})]}),M?null:t.pinned?(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost","aria-disabled":null!==p,"aria-busy":"unpin"===p,onClick:$,"aria-label":"Unpin this memory",children:"unpin"===p?"Unpinning…":"Unpin"}):(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost","aria-disabled":null!==p,"aria-busy":"pin"===p,onClick:E,"aria-label":"Pin this memory for priority retrieval",children:"pin"===p?"Pinning…":"Pin"}),D?(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost","aria-disabled":null!==p,"aria-busy":"archive"===p,onClick:A,"aria-label":"Archive this memory",children:"archive"===p?"Archiving…":"Archive"}):null,M?null:(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-danger","aria-disabled":null!==p,onClick:()=>{null===p&&(f(null),v(null),k(!0));},"aria-label":"Forget this memory permanently",children:"Forget"}),(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-danger","aria-disabled":null!==p,onClick:()=>{null===p&&(f(null),v(null),S(!0));},"aria-label":"Delete this memory record",children:"Delete"}),null!==h?(0,r.jsx)("p",{role:"alert","aria-live":"assertive",className:"mc-action-error",children:h}):null,null!==g?(0,r.jsx)("p",{role:"status","aria-live":"polite",className:"mc-action-notice",children:g}):null,b?(0,r.jsx)(fO,{record:t,onSave:e=>{y(!1),n(e);},onClose:()=>{y(!1);}}):null,x?(0,r.jsx)(fO,{mode:"correct",record:t,correctMemoryImpl:u,onSave:T,onClose:()=>{w(!1);}}):null,j?(0,r.jsx)(fB,{record:t,onComplete:()=>{k(!1),n(null);},onClose:()=>{k(!1);}}):null,N?(0,r.jsx)(fB,{mode:"delete",record:t,deleteMemoryImpl:d,onComplete:()=>{S(!1),n(null);},onClose:()=>{S(!1);}}):null]});}function fK(e){return new Date(e).toLocaleString();}function fU(e){let{label:t,value:n}=e;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("dt",{className:"mc-meta-label",children:t}),(0,r.jsx)("dd",{className:"mc-meta-value",children:n})]});}function fV(e){let{provenance:t}=e;return(0,r.jsxs)("section",{"aria-label":"Provenance",className:"mc-section",children:[(0,r.jsx)("h2",{className:"lk-section-head",children:"Provenance"}),(0,r.jsxs)("dl",{className:"mc-meta",children:[(0,r.jsx)(fU,{label:"Source kind",value:t.sourceKind}),(0,r.jsx)(fU,{label:"Captured at",value:fK(t.capturedAt)}),(0,r.jsx)(fU,{label:"Confidence",value:`${(100*t.confidence).toFixed(0)}%`}),(0,r.jsx)(fU,{label:"Sensitivity",value:t.sensitivity}),void 0!==t.captureRationale?(0,r.jsx)(fU,{label:"Rationale",value:t.captureRationale}):null,void 0!==t.modelIdentity?(0,r.jsx)(fU,{label:"Model",value:`${t.modelIdentity.provider} / ${t.modelIdentity.modelId}`}):null]})]});}function fH(e){let{validity:t}=e;return(0,r.jsxs)("section",{"aria-label":"Validity",className:"mc-section",children:[(0,r.jsx)("h2",{className:"lk-section-head",children:"Validity"}),(0,r.jsxs)("dl",{className:"mc-meta",children:[(0,r.jsx)(fU,{label:"Valid from",value:fK(t.validFrom)}),(0,r.jsx)(fU,{label:"Valid until",value:void 0!==t.validUntil?fK(t.validUntil):"No expiry"})]})]});}function f_(e){let{tags:t}=e;return 0===t.length?(0,r.jsx)("span",{className:"mc-meta-empty",children:"No tags"}):(0,r.jsx)("ul",{className:"mc-tags","aria-label":"Tags",children:t.map(e=>(0,r.jsx)("li",{className:"mc-tag",children:e},e))});}function fG(e){let{onBack:t,controlRef:n,children:l="Back to MemoriaViva"}=e;return void 0!==t?(0,r.jsx)("button",{ref:n,type:"button",className:"mc-back-link lk-btn lk-btn-ghost",onClick:t,children:l}):(0,r.jsx)(ff(),{ref:n,href:"/memoriaviva",className:"mc-back-link lk-btn lk-btn-ghost","aria-label":"Back to MemoriaViva",children:l});}function fJ(e){let{record:t,onBack:n}=e;return(0,r.jsxs)("header",{className:"mc-detail-header",children:[(0,r.jsxs)("div",{className:"mc-detail-title-row",children:[(0,r.jsxs)("h1",{className:"lk-title",style:{flex:1},children:[fF[t.type]," memory"]}),(0,r.jsx)("span",{className:`mc-badge mc-badge-${t.status}`,children:t.status}),t.pinned?(0,r.jsx)("span",{"aria-label":"Pinned",className:"mc-badge mc-badge-pinned",children:"Pinned"}):null]}),(0,r.jsx)(fG,{onBack:n,children:"Back"})]});}function fY(e){let{id:t,fetchMemoryImpl:n=lS,onBack:l}=e,[a,s]=(0,i.useState)(null),[o,c]=(0,i.useState)(!0),[d,u]=(0,i.useState)(null),[p,m]=(0,i.useState)(!1),h=(0,i.useRef)(null),f=(0,i.useCallback)(e=>{h.current=e;},[]),g=(0,i.useCallback)(e=>{null===e&&m(!0),s(e);},[]);(0,i.useEffect)(()=>{var e;p&&null===a&&(null==(e=h.current)||e.focus());},[p,a]);let v=(0,i.useCallback)(async()=>{c(!0),u(null);try{let e=await n(t);s(e.memory);}catch(e){u(fv(e));}finally{c(!1);}},[t,n]);return((0,i.useEffect)(()=>{v();},[v]),o)?(0,r.jsx)("p",{role:"status","aria-live":"polite",className:"lk-loading",children:"Loading memory…"}):null!==d?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{role:"alert","aria-live":"assertive",className:"lk-alert",children:[d,(0,r.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>{v();},children:"Retry"})]}),(0,r.jsx)("p",{children:(0,r.jsx)(fG,{onBack:l})})]}):null===a?(0,r.jsx)("div",{className:"lk-empty",children:(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"lk-empty-title",children:p?"Memory removed":"Memory not found"}),(0,r.jsx)("p",{role:"status","aria-live":"polite",className:"lk-empty-body",children:p?"The memory was forgotten or deleted and is no longer available.":"This memory may have been deleted. Open a memory from the list instead."}),(0,r.jsx)("p",{children:(0,r.jsx)(fG,{onBack:l,controlRef:f})})]})}):(0,r.jsxs)("article",{"aria-label":`Memory record: ${a.body.slice(0,60)}`,className:"mc-detail",children:[(0,r.jsx)(fJ,{record:a,onBack:l}),(0,r.jsxs)("section",{"aria-label":"Memory body",className:"mc-section",children:[(0,r.jsx)("h2",{className:"lk-section-head",children:"Content"}),(0,r.jsx)("p",{className:"mc-body-text",children:a.body})]}),(0,r.jsxs)("section",{"aria-label":"Details",className:"mc-section",children:[(0,r.jsx)("h2",{className:"lk-section-head",children:"Details"}),(0,r.jsxs)("dl",{className:"mc-meta",children:[(0,r.jsx)(fU,{label:"ID",value:(0,r.jsx)("code",{className:"mc-code",children:a.id})}),(0,r.jsx)(fU,{label:"Scope",value:function(e){switch(e.kind){case"user":return`user:${e.userId}`;case"workspace":return`workspace:${e.workspaceId}`;case"project":return`project:${e.projectId}`;case"workflow":return`workflow:${e.workflowDefinitionId}`;case"global":return"global";default:return"unknown";}}(a.scope)}),(0,r.jsx)(fU,{label:"Type",value:fF[a.type]}),(0,r.jsx)(fU,{label:"Created",value:fK(a.createdAt)}),(0,r.jsx)(fU,{label:"Updated",value:fK(a.updatedAt)}),void 0!==a.staleReason?(0,r.jsx)(fU,{label:"Stale reason",value:(0,r.jsx)("em",{children:a.staleReason})}):null]})]}),(0,r.jsx)(fV,{provenance:a.provenance}),(0,r.jsx)(fH,{validity:a.validity}),(0,r.jsxs)("section",{"aria-label":"Tags",className:"mc-section",children:[(0,r.jsx)("h2",{className:"lk-section-head",children:"Tags"}),(0,r.jsx)(f_,{tags:a.tags})]}),(0,r.jsxs)("section",{"aria-label":"Actions",className:"mc-section",children:[(0,r.jsx)("h2",{className:"lk-section-head",children:"Actions"}),(0,r.jsx)(fW,{record:a,onRecordChange:g})]})]});}var fX=n(79748);let fZ={proposed:"mc-badge-proposed",accepted:"mc-badge-accepted",conflicted:"mc-badge-conflicted",rejected:"mc-badge-rejected",archived:"mc-badge-archived",forgotten:"mc-badge-forgotten",superseded:"mc-badge-superseded",expired:"mc-badge-expired"};function fQ(e){var t;let{status:n}=e,l=null!=(t=fZ[n])?t:"mc-badge-default";return(0,r.jsx)("span",{className:`mc-badge ${l}`,children:n});}function f0(e){var t;let{record:n,onOpenDetail:l}=e,a=(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"mc-row-main",children:[(0,r.jsx)("span",{className:"mc-row-body",title:n.body,children:n.body}),(0,r.jsxs)("div",{className:"mc-row-meta",children:[(0,r.jsx)("span",{className:"mc-row-type",children:fF[n.type]}),(0,r.jsx)("span",{className:"mc-row-scope",children:fT[n.scope.kind]}),(0,r.jsxs)("span",{className:"mc-row-source",children:["Source ",n.provenance.sourceKind]}),(0,r.jsx)("span",{className:"mc-row-confidence",children:(t=n.provenance.confidence,`${(100*t).toFixed(0)}% confidence`)}),(0,r.jsxs)("span",{className:"mc-row-sensitivity",children:["Sensitivity ",n.provenance.sensitivity]}),n.pinned?(0,r.jsx)("span",{className:"mc-badge mc-badge-pinned",children:"Pinned"}):null]})]}),(0,r.jsx)(fQ,{status:n.status})]});return(0,r.jsx)("li",{children:void 0!==l?(0,r.jsx)("button",{type:"button",className:"mc-row mc-row-button",onClick:()=>l(n.id),children:a}):(0,r.jsx)(ff(),{href:`/memoriaviva/detail?id=${encodeURIComponent(n.id)}`,className:"mc-row",children:a})});}function f1(e){let{hasFilters:t}=e;return(0,r.jsx)("div",{"data-testid":"memory-empty-state",className:"lk-empty",children:(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"lk-empty-title",children:"No memories found"}),(0,r.jsx)("p",{className:"lk-empty-body",children:t?"Try removing some filters to see more memories.":"Memories will appear here once the system captures them from your conversations and workflows."})]})});}function f2(e){let{filters:t,onFilterChange:n,fetchMemoriesImpl:l=lx,onOpenDetail:a,onOpenConsolidation:s,onOpenReviewQueue:o,policyEnabled:c,onPolicyEnabledChange:d,showWorkspaceBackLink:u=!0,settingsSlot:p}=e,[m,h]=(0,i.useState)([]),[f,g]=(0,i.useState)(!0),[v,b]=(0,i.useState)(null),[y,x]=(0,i.useState)(!0),w=null!=c?c:y,j=t.scope.length>0||t.type.length>0||t.status.length>0||t.sensitivity.length>0,k=(0,i.useCallback)(async e=>{g(!0),b(null);try{let t=await l(e);h(t.memories);}catch(e){b(fv(e));}finally{g(!1);}},[l]);return(0,i.useEffect)(()=>{k(t);},[t,k]),(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("header",{className:"lk-header",children:[(0,r.jsx)("h1",{className:"lk-title",children:"MemoriaViva"}),(0,r.jsxs)("div",{className:"mc-view-actions",children:[(0,r.jsxs)("div",{className:"mc-policy-switch",children:[(0,r.jsx)(oL,{on:w,onChange:null!=d?d:x,label:"Enable MemoriaViva policy"}),(0,r.jsxs)("span",{children:["Policy ",w?"on":"off"]})]}),u?(0,r.jsx)(ff(),{href:"/",className:"lk-btn lk-btn-ghost lk-btn-lg",children:"Back to Workspace"}):null,void 0!==s?(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost lk-btn-lg",onClick:s,children:"Consolidation"}):(0,r.jsx)(ff(),{href:"/memoriaviva/consolidation",className:"lk-btn lk-btn-ghost lk-btn-lg",children:"Consolidation"}),void 0!==o?(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost lk-btn-lg mc-queue-link",onClick:o,children:"Review queue"}):(0,r.jsx)(ff(),{href:"/memoriaviva/review-queue",className:"lk-btn lk-btn-ghost lk-btn-lg mc-queue-link",children:"Review queue"})]})]}),p,(0,r.jsx)(fq,{filters:t,onChange:n}),(0,r.jsx)("p",{role:"status",className:"visually-hidden",children:f||null!==v?null:`${m.length.toString()} ${1===m.length?"memory":"memories"} found`}),(0,r.jsx)("section",{"aria-label":"Memory records","aria-busy":f,style:{flex:1,minHeight:0,overflowY:"auto"},children:f&&0===m.length?(0,r.jsx)("p",{role:"status","aria-live":"polite",className:"lk-loading",children:"Loading memories…"}):null!==v?(0,r.jsxs)("div",{role:"alert","aria-live":"assertive",className:"lk-alert",children:[v,(0,r.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>{k(t);},children:"Retry"})]}):0===m.length?(0,r.jsx)(f1,{hasFilters:j}):(0,r.jsx)("ul",{"aria-label":"Memory list",style:{listStyle:"none",padding:0,margin:0,display:"flex",flexDirection:"column",gap:4,opacity:f?.6:1,transition:"opacity 0.15s ease"},children:m.map(e=>(0,r.jsx)(f0,{record:e,onOpenDetail:a},e.id))})})]});}function f4(e){let{record:t,busyAction:n,rowError:l,onAccept:a,onReject:i,onArchive:s,onOpenDetail:o}=e,c=`memory-review-body-${t.id}`,d=`View details for memory ${t.id}: ${t.body.slice(0,80)}`,u=void 0!==t.staleReason||"expired"===t.status;return(0,r.jsx)("li",{"data-review-row-id":t.id,children:(0,r.jsxs)("article",{className:"mc-review-row",children:[(0,r.jsxs)("div",{className:"mc-review-body",children:[(0,r.jsx)("p",{id:c,className:"mc-row-body",children:t.body}),(0,r.jsxs)("div",{className:"mc-row-meta",children:[(0,r.jsx)("span",{className:"mc-row-type",children:fF[t.type]}),(0,r.jsx)("span",{className:"mc-row-scope",children:fT[t.scope.kind]}),(0,r.jsx)("span",{className:`mc-badge mc-badge-${t.status}`,children:t.status}),u?(0,r.jsxs)("span",{className:"mc-row-stale",children:["Stale",void 0!==t.staleReason?`: ${t.staleReason}`:""]}):null,void 0!==o?(0,r.jsx)("button",{type:"button",className:"mc-row-detail-link mc-link-button","aria-label":d,onClick:()=>o(t.id),children:"View details"}):(0,r.jsx)(ff(),{href:`/memoriaviva/detail?id=${encodeURIComponent(t.id)}`,className:"mc-row-detail-link","aria-label":d,children:"View details"})]}),null!==l?(0,r.jsx)("p",{role:"alert",className:"mc-action-error",children:l}):null]}),(0,r.jsx)("div",{className:"mc-review-actions",role:"group","aria-labelledby":c,children:"proposed"===t.status?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-primary","aria-disabled":null!==n,"aria-busy":"accept"===n,onClick:()=>{null===n&&a(t);},children:"accept"===n?"Approving…":"Approve"}),(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost","aria-disabled":null!==n,"aria-busy":"reject"===n,onClick:()=>{null===n&&i(t);},children:"reject"===n?"Rejecting…":"Reject"})]}):"conflicted"===t.status?(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost","aria-disabled":null!==n,"aria-busy":"reject"===n,onClick:()=>{null===n&&i(t);},children:"reject"===n?"Rejecting…":"Reject conflict"}):(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost","aria-disabled":null!==n,"aria-busy":"archive"===n,onClick:()=>{null===n&&s(t);},children:"archive"===n?"Archiving…":"Archive stale"})})]})});}function f3(e){let{fetchQueueImpl:t=lw,acceptImpl:n=lF,rejectImpl:l=lD,archiveImpl:a=lE,onBack:s,onOpenDetail:o}=e,[c,d]=(0,i.useState)([]),[u,p]=(0,i.useState)(!0),[m,h]=(0,i.useState)(null),[f,g]=(0,i.useState)({}),[v,b]=(0,i.useState)({}),[y,x]=(0,i.useState)(""),w=(0,i.useRef)(null),j=(0,i.useRef)(null),k=(0,i.useRef)(null),N=(0,i.useCallback)(async()=>{p(!0),h(null);try{let e=await t();d(e.memories),g({}),b({});}catch(e){h(fv(e));}finally{p(!1);}},[t]);(0,i.useEffect)(()=>{N();},[N]);let S=(0,i.useCallback)(e=>{g(t=>{let n={...t};return delete n[e],n;}),b(t=>{let n={...t};return delete n[e],n;});},[]),C=(0,i.useCallback)(e=>{var t;let n=c.findIndex(t=>t.id===e),l=null!=(t=c[n+1])?t:c[n-1];k.current=void 0!==l?l.id:"",d(t=>t.filter(t=>t.id!==e)),S(e);},[c,S]);(0,i.useEffect)(()=>{var e,t,n;let l=k.current;if(null===l)return;k.current=null;let a=""===l?null:null!=(e=null==(t=w.current)?void 0:t.querySelector(`[data-review-row-id="${CSS.escape(l)}"]`))?e:null,r=null===a?null:a.querySelector("button");null!==r?r.focus():null==(n=j.current)||n.focus();},[c]);let R=(0,i.useCallback)(async(e,t)=>{let r=e.id;g(e=>({...e,[r]:t})),b(e=>{let t={...e};return delete t[r],t;});try{"accept"===t?await n(r):"archive"===t?await a(r,"archived stale memory from review queue"):await l(r,"conflicted"===e.status?"rejected conflict from review queue":"rejected from review queue"),C(r),x("accept"===t?"Memory approved":"archive"===t?"Memory archived":"Memory rejected");}catch(e){b(t=>({...t,[r]:fv(e)})),g(e=>{let t={...e};return delete t[r],t;});}},[n,a,l,C]);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("header",{className:"lk-header mc-review-header",children:[(0,r.jsx)("h1",{className:"lk-title",tabIndex:-1,ref:j,children:"Review queue"}),(0,r.jsxs)("span",{role:"status","aria-live":"polite",className:"mc-badge-count",children:[c.length.toString()," awaiting review"]}),void 0!==s?(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost lk-btn-lg","aria-label":"Back to MemoriaViva",onClick:s,children:"Back"}):(0,r.jsx)(ff(),{href:"/memoriaviva",className:"lk-btn lk-btn-ghost lk-btn-lg","aria-label":"Back to MemoriaViva",children:"Back"})]}),(0,r.jsx)("p",{role:"status",className:"visually-hidden",children:y}),(0,r.jsx)("section",{"aria-label":"Memories awaiting review","aria-busy":u,style:{flex:1,minHeight:0,overflowY:"auto"},children:u?(0,r.jsx)("p",{role:"status","aria-live":"polite",className:"lk-loading",children:"Loading review queue…"}):null!==m?(0,r.jsxs)("div",{role:"alert","aria-live":"assertive",className:"lk-alert",children:[m,(0,r.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>{N();},children:"Retry"})]}):0===c.length?(0,r.jsx)("div",{"data-testid":"review-queue-empty",className:"lk-empty",children:(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"lk-empty-title",children:"Queue is clear"}),(0,r.jsx)("p",{className:"lk-empty-body",children:"No memories are waiting for review. Proposed, conflicted, and stale memories appear here."})]})}):(0,r.jsx)("ul",{ref:w,"aria-label":"Review queue",style:{listStyle:"none",padding:0,margin:0,display:"flex",flexDirection:"column",gap:8},children:c.map(e=>{var t,n;return(0,r.jsx)(f4,{record:e,busyAction:null!=(t=f[e.id])?t:null,rowError:null!=(n=v[e.id])?n:null,onAccept:e=>{R(e,"accept");},onReject:e=>{R(e,"reject");},onArchive:e=>{R(e,"archive");},onOpenDetail:o},e.id);})})})]});}let f6={scope:[],type:[],status:[],sensitivity:[]};function f5(){let{memoryEnabled:e,setMemoryEnabled:t,memoryBudgetTokens:n,setMemoryBudgetTokens:l}=at(),a=(0,i.useId)(),s=`${a}-memoriaviva-budget`,o=`${a}-memoriaviva-budget-help`,c=(0,i.useCallback)(e=>{l(Math.max(0,n+e));},[n,l]),d=(0,i.useCallback)(e=>{l(Math.max(0,Number(e.target.value)||0));},[l]),u=(0,i.useCallback)(e=>{0!==e.deltaY&&(e.preventDefault(),c(e.deltaY<0?100:-100));},[c]);return(0,r.jsxs)("section",{className:"mv-settings","aria-label":"MemoriaViva request settings",children:[(0,r.jsxs)("div",{className:"mv-settings-main",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("h2",{className:"mv-settings-title",children:"Request settings"}),(0,r.jsx)("p",{className:"mv-settings-copy",children:"Controls how MemoriaViva contributes memory context to chat requests."})]}),(0,r.jsx)("span",{className:"mv-settings-status","data-enabled":e?"true":"false",children:e?"Enabled for chat":"Disabled for chat"})]}),(0,r.jsxs)("div",{className:"mv-settings-grid",children:[(0,r.jsxs)("div",{className:"mv-setting-toggle",children:[(0,r.jsxs)("span",{children:[(0,r.jsx)("strong",{children:"Use in chat"}),(0,r.jsx)("span",{children:"Attach relevant memories when the next request is sent."})]}),(0,r.jsx)(oL,{on:e,onChange:t,label:"Use MemoriaViva in chat requests"})]}),(0,r.jsxs)("div",{className:"mv-setting-budget",children:[(0,r.jsx)("label",{htmlFor:s,children:"Memory context budget"}),(0,r.jsxs)("div",{className:"mv-budget-control",children:[(0,r.jsxs)("span",{className:"number-control number-control-pill",children:[(0,r.jsx)("input",{id:s,type:"number",className:"number-control-input",min:0,step:100,value:n,"aria-label":"MemoriaViva context budget","aria-describedby":o,onChange:d,onWheel:u}),(0,r.jsx)(mx,{label:"MemoriaViva context budget",onStepUp:()=>c(100),onStepDown:()=>c(-100)})]}),(0,r.jsx)("span",{className:"mv-budget-unit",children:"tokens"})]}),(0,r.jsx)("p",{id:o,className:"mv-setting-help",children:"Limits the MemoriaViva memory context attached to the next chat request."})]})]})]});}function f8(){let{fetchMemoriesImpl:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},[t,n]=(0,i.useState)({kind:"list"}),[l,a]=(0,i.useState)(f6),[s,o]=(0,i.useState)(!0),c=(0,i.useCallback)(()=>{n({kind:"list"});},[]),d=(0,i.useCallback)(e=>{n({kind:"detail",id:e});},[]);return(0,r.jsx)("div",{className:"memoria-window",children:"list"===t.kind?(0,r.jsx)(f2,{filters:l,onFilterChange:a,onOpenDetail:d,onOpenConsolidation:()=>n({kind:"consolidation"}),onOpenReviewQueue:()=>n({kind:"reviewQueue"}),policyEnabled:s,onPolicyEnabledChange:o,showWorkspaceBackLink:!1,...(void 0===e?{}:{fetchMemoriesImpl:e}),settingsSlot:(0,r.jsx)(f5,{})}):"detail"===t.kind?(0,r.jsx)(fY,{id:t.id,onBack:c}):"consolidation"===t.kind?(0,r.jsx)(fR,{onBack:c,onOpenDetail:d}):(0,r.jsx)(f3,{onBack:c,onOpenDetail:d})});}var f9=n(19217),f7=n(25780),ge=n(23934);function gt(e){return Array.from(e.querySelectorAll("button:not([disabled]),input:not([disabled]),[tabindex]:not([tabindex='-1'])"));}function gn(e){let{capsule:t,checked:n,disabled:l,onToggle:a}=e;return(0,r.jsx)("li",{className:"lk-compose-member",children:(0,r.jsxs)("label",{className:"lk-compose-member-label",children:[(0,r.jsx)("input",{type:"checkbox",checked:n,disabled:l,onChange:()=>a(t.id)}),(0,r.jsx)("span",{className:"lk-compose-member-name",title:t.displayName,children:t.displayName}),(0,r.jsx)("span",{className:"lk-badge","data-state":t.lifecycleState,children:f7.Z[t.lifecycleState]})]})});}function gl(e){let t,{capsules:n,onCancel:l,onCreated:a,createImpl:s=sb.WM}=e,o=(0,i.useId)(),c=(0,i.useId)(),d=(0,i.useId)(),u=(0,i.useRef)(null),[p,m]=(0,i.useState)(""),[h,f]=(0,i.useState)(new Set()),[g,v]=(0,i.useState)(!1),[b,y]=(0,i.useState)(null);function x(e){f(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n;}),null!==b&&y(null);}async function w(e){var t;e.preventDefault();let n=(t=h.size,0===p.trim().length?"Set name is required.":0===t?"Select at least one capsule to combine.":t>16?"A set can hold at most 16 capsules.":null);if(null!==n)return void y(n);v(!0),y(null);try{await s({displayName:p.trim(),capsuleIds:[...h]}),a();}catch(e){y((0,ge.W)(e));}finally{v(!1);}}(0,f9.i)(),(0,i.useEffect)(()=>{var e;let t=document.activeElement,n=u.current;return null!==n&&(null==(e=gt(n)[0])||e.focus()),()=>{var e;return null==t||null==(e=t.focus)?void 0:e.call(t);};},[u]),(0,i.useEffect)(()=>{let e=u.current;if(null!==e)return e.addEventListener("keydown",t),()=>e.removeEventListener("keydown",t);function t(t){if("Escape"===t.key&&!g){t.preventDefault(),l();return;}if("Tab"!==t.key)return;let n=gt(e);if(0===n.length)return void t.preventDefault();let a=n[0],r=n[n.length-1];t.shiftKey&&document.activeElement===a?(t.preventDefault(),null==r||r.focus()):t.shiftKey||document.activeElement!==r||(t.preventDefault(),null==a||a.focus());}},[u,g,l]),t=(0,i.useRef)(!1),(0,i.useEffect)(()=>{let e=u.current;if(null!==e){if(g)t.current=!0,e.focus();else if(t.current){var n;t.current=!1,null==(n=gt(e)[0])||n.focus();}}},[u,g]);let j="Set name is required."===b,k="Select at least one capsule to combine."===b;return(0,n9.createPortal)((0,r.jsx)("div",{className:"mc-dialog-backdrop",role:"presentation",children:(0,r.jsxs)("div",{ref:u,className:"mc-dialog",role:"dialog","aria-modal":"true","aria-labelledby":o,tabIndex:-1,children:[(0,r.jsx)("h2",{id:o,className:"mc-dialog-title",children:"Combine capsules into a set"}),(0,r.jsxs)("form",{onSubmit:e=>void w(e),children:[(0,r.jsxs)("label",{className:"mc-dialog-field",htmlFor:c,children:[(0,r.jsx)("span",{className:"mc-dialog-label",children:"Set name"}),(0,r.jsx)("input",{id:c,className:"mc-dialog-input",value:p,disabled:g,autoComplete:"off","aria-invalid":j,"aria-describedby":j?d:void 0,onChange:e=>{m(e.target.value),null!==b&&y(null);}})]}),(0,r.jsxs)("fieldset",{className:"lk-compose-fieldset",disabled:g,"aria-invalid":k,"aria-describedby":k?d:void 0,children:[(0,r.jsxs)("legend",{className:"mc-dialog-label",children:["Capsules (",h.size.toString(),"/","16",")"]}),0===n.length?(0,r.jsx)("p",{className:"lkd-empty-note",children:"No capsules available to combine."}):(0,r.jsx)("ul",{className:"lk-compose-member-list","aria-label":"Selectable capsules",children:n.map(e=>(0,r.jsx)(gn,{capsule:e,checked:h.has(e.id),disabled:g,onToggle:x},e.id))})]}),null!==b?(0,r.jsx)("div",{id:d,role:"alert","aria-live":"assertive",className:"mc-dialog-error",children:b}):null,(0,r.jsxs)("div",{className:"mc-dialog-actions",children:[(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost",disabled:g,onClick:l,children:"Cancel"}),(0,r.jsx)("button",{type:"submit",className:"lk-btn lk-btn-primary",disabled:g,"aria-busy":g,children:g?"Combining…":"Combine"})]})]})]})}),document.body);}var ga=n(68835);function gr(e){let{message:t,onRetry:n,onDismiss:l}=e;return(0,r.jsxs)("div",{role:"alert","aria-live":"assertive",className:"lk-alert",children:[t,void 0!==n?(0,r.jsx)("button",{type:"button",onClick:n,"aria-label":"Retry loading capsules",className:"lk-alert-retry",children:"Retry"}):null,void 0!==l?(0,r.jsx)("button",{type:"button",onClick:l,"aria-label":"Dismiss error message",className:"lk-alert-retry",children:"Dismiss"}):null]});}function gi(e){return Array.from(e.querySelectorAll("button:not([disabled]),input:not([disabled]),textarea:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex='-1'])"));}function gs(e){let{busy:t,error:n,onCancel:l,onSubmit:a}=e,s=(0,i.useId)(),o=(0,i.useId)(),c=(0,i.useId)(),d=(0,i.useId)(),u=(0,i.useRef)(null),p=(0,i.useRef)(null),m=(0,i.useRef)(null),[h,f]=(0,i.useState)(""),[g,v]=(0,i.useState)(null);(0,f9.i)(),(0,i.useEffect)(()=>{var e;return m.current=document.activeElement,null==(e=p.current)||e.focus(),()=>{var e,t;null==(t=m.current)||null==(e=t.focus)||e.call(t);};},[]),(0,i.useEffect)(()=>{let e=u.current;if(null===e)return;let n=n=>{if("Escape"===n.key&&!t){n.preventDefault(),l();return;}if("Tab"!==n.key)return;let a=gi(e);if(0===a.length)return void n.preventDefault();let r=a[0],i=a[a.length-1];n.shiftKey&&document.activeElement===r?(n.preventDefault(),null==i||i.focus()):n.shiftKey||document.activeElement!==i||(n.preventDefault(),null==r||r.focus());};return e.addEventListener("keydown",n),()=>e.removeEventListener("keydown",n);},[t,l]);let b=(0,i.useRef)(!1);async function y(e){e.preventDefault();let t=h.trim();0===t.length?v("Capsule display name is required."):(v(null),await a(t));}(0,i.useEffect)(()=>{let e=u.current;if(null!==e){if(t)b.current=!0,e.focus();else if(b.current){var n;b.current=!1,null==(n=gi(e)[0])||n.focus();}}},[t]);let x=null!=g?g:n;return(0,n9.createPortal)((0,r.jsx)("div",{className:"mc-dialog-backdrop",role:"presentation",children:(0,r.jsxs)("div",{ref:u,className:"mc-dialog",role:"dialog","aria-modal":"true","aria-labelledby":s,"aria-describedby":o,tabIndex:-1,children:[(0,r.jsx)("h2",{id:s,className:"mc-dialog-title",children:"Create capsule"}),(0,r.jsx)("p",{id:o,className:"mc-dialog-body",children:"Name the capsule. After creating it, connect a source and start indexing from the capsule page."}),(0,r.jsxs)("form",{onSubmit:e=>void y(e),children:[(0,r.jsxs)("label",{className:"mc-dialog-field",htmlFor:c,children:[(0,r.jsx)("span",{className:"mc-dialog-label",children:"Capsule display name"}),(0,r.jsx)("input",{id:c,ref:p,className:"mc-dialog-input",value:h,disabled:t,autoComplete:"off","aria-invalid":null!==x,"aria-describedby":null!==x?d:void 0,onChange:e=>{f(e.target.value),null!==g&&v(null);}})]}),null!==x?(0,r.jsx)("div",{id:d,role:"alert","aria-live":"assertive",className:"mc-dialog-error",children:x}):null,(0,r.jsxs)("div",{className:"mc-dialog-actions",children:[(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost",disabled:t,onClick:l,children:"Cancel"}),(0,r.jsx)("button",{type:"submit",className:"lk-btn lk-btn-primary",disabled:t,children:t?"Creating…":"Create capsule"})]})]})]})}),document.body);}function go(e){let{capsuleName:t,onCancel:n,onConfirm:l}=e,a=(0,i.useId)(),s=(0,i.useId)(),o=(0,i.useRef)(null);return(0,f9.i)(),(0,i.useEffect)(()=>{var e;let t=document.activeElement,n=o.current;return null!==n&&(null==(e=gi(n)[0])||e.focus()),()=>{var e;return null==t||null==(e=t.focus)?void 0:e.call(t);};},[]),(0,i.useEffect)(()=>{let e=o.current;if(null===e)return;let t=t=>{if("Escape"===t.key){t.preventDefault(),n();return;}if("Tab"!==t.key)return;let l=gi(e);if(0===l.length)return void t.preventDefault();let a=l[0],r=l[l.length-1];t.shiftKey&&document.activeElement===a?(t.preventDefault(),null==r||r.focus()):t.shiftKey||document.activeElement!==r||(t.preventDefault(),null==a||a.focus());};return e.addEventListener("keydown",t),()=>e.removeEventListener("keydown",t);},[n]),(0,n9.createPortal)((0,r.jsx)("div",{className:"mc-dialog-backdrop",role:"presentation",children:(0,r.jsxs)("div",{ref:o,className:"mc-dialog",role:"dialog","aria-modal":"true","aria-labelledby":a,"aria-describedby":s,tabIndex:-1,children:[(0,r.jsx)("h2",{id:a,className:"mc-dialog-title",children:"Disconnect capsule"}),(0,r.jsxs)("p",{id:s,className:"mc-dialog-body",children:['Disconnect "',t,'"? The capsule keeps its index, but the source link is removed.']}),(0,r.jsxs)("div",{className:"mc-dialog-actions",children:[(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost",onClick:n,children:"Cancel"}),(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-danger",onClick:l,children:"Disconnect"})]})]})}),document.body);}function gc(e){let{state:t}=e;return(0,r.jsx)("span",{className:"lk-badge","data-state":t,children:f7.Z[t]});}function gd(e){let{capsule:t,busy:n,busyKind:l,onStart:a,onCancel:s}=e,{id:o,displayName:c,lifecycleState:d,sourceCount:u}=t,p=(0,i.useId)();if("indexing"===d)return(0,r.jsx)("button",{type:"button",disabled:n,"aria-busy":"cancel"===l,"aria-label":`Cancel indexing for capsule ${c}`,onClick:()=>{s(o);},className:"lk-btn lk-btn-ghost",children:"cancel"===l?"Cancelling…":"Cancel"});let m=u>0;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{type:"button",disabled:n,"aria-disabled":!m||void 0,"aria-busy":"index"===l,"aria-label":`Start indexing capsule ${c}`,"aria-describedby":m?void 0:p,title:m?void 0:"Attach a source before indexing this capsule.",onClick:()=>{m&&a(o);},className:"lk-btn lk-btn-primary",children:"index"===l?"Indexing…":"Index"}),m?null:(0,r.jsx)("span",{id:p,className:"visually-hidden",children:"Attach a source before indexing."})]});}function gu(e){let{capsule:t,busy:n,busyKind:l,onStart:a,onCancel:i,onDisconnect:s,onHealth:o,onAddToWorkspace:c}=e,{id:d,displayName:u}=t;return(0,r.jsxs)("div",{role:"group","aria-label":`Actions for capsule ${u}`,className:"lk-capsule-actions",children:[(0,r.jsx)(gd,{capsule:t,busy:n,busyKind:l,onStart:a,onCancel:i}),(0,r.jsx)("button",{type:"button",disabled:n,"aria-label":`Add capsule ${u} to workspace`,onClick:()=>{c(d);},className:"lk-btn lk-btn-ghost",children:"Add to workspace"}),(0,r.jsx)("button",{type:"button",disabled:n,"aria-label":`Open details for capsule ${u}`,onClick:()=>{o(d);},className:"lk-btn lk-btn-ghost",children:"Details"}),(0,r.jsx)("button",{type:"button",disabled:n,"aria-busy":"disconnect"===l,"aria-label":`Disconnect capsule ${u}`,onClick:()=>{s(d);},className:"lk-btn lk-btn-danger",children:"disconnect"===l?"Disconnecting…":"Disconnect"})]});}function gp(e){return e instanceof Element&&null!==e.closest(".lk-capsule-actions,a,input,select,textarea");}function gm(e,t){let n=document.elementFromPoint(e,t);return n instanceof Element&&null!==n.closest("main.workspace")&&null===n.closest(".window");}function gh(e,t){let n={payload:e,clientX:t.clientX,clientY:t.clientY};window.dispatchEvent(new CustomEvent(nL,{detail:n}));}function gf(e){let{capsule:t,busy:n,busyKind:l,onStart:a,onCancel:s,onDisconnect:o,onHealth:c,onAddToWorkspace:d}=e,[u,p]=(0,i.useState)(null),m=(0,i.useRef)(!1),h=(0,i.useRef)(!1),f={kind:"capsule",id:t.id,label:t.displayName,lifecycleState:t.lifecycleState},g=e=>{h.current||(h.current=!0,gh(f,e),window.setTimeout(()=>{h.current=!1;},250));},v=(e,n)=>{m.current=!0;let l=!1,a=a=>{let r=a.clientX-e,i=a.clientY-n;!l&&6>Math.hypot(r,i)||(l=!0,document.body.style.cursor="grabbing",p({x:a.clientX,y:a.clientY,label:t.displayName,state:t.lifecycleState}));},r=e=>{window.removeEventListener("pointermove",a),window.removeEventListener("pointerup",r),window.removeEventListener("mousemove",a),window.removeEventListener("mouseup",r),m.current=!1,document.body.style.cursor="",p(null),l&&gm(e.clientX,e.clientY)&&g(e);};window.addEventListener("pointermove",a),window.addEventListener("pointerup",r),window.addEventListener("mousemove",a),window.addEventListener("mouseup",r);};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("article",{"aria-label":`Capsule: ${t.displayName}`,className:"lk-capsule-row",children:[(0,r.jsxs)("button",{type:"button",className:"lk-capsule-drag-handle","aria-label":`Drag capsule ${t.displayName} to workspace`,title:"Drag to the workspace to create a connector card",onPointerDown:e=>{gp(e.target)||eN(e)&&(e.preventDefault(),e.stopPropagation(),v(e.clientX,e.clientY));},onMouseDown:e=>{m.current||gp(e.target)||eN(e)&&(e.preventDefault(),e.stopPropagation(),v(e.clientX,e.clientY));},onDragStart:e=>{gp(e.target)?e.preventDefault():(e.dataTransfer.effectAllowed="copy",e.dataTransfer.setData(nP,JSON.stringify(f)),e.dataTransfer.setData("text/plain",t.displayName));},onDragEnd:e=>{gm(e.clientX,e.clientY)&&g(e);},draggable:!0,children:[(0,r.jsx)("span",{"aria-hidden":"true",className:"lk-capsule-icon",children:"⬡"}),(0,r.jsxs)("span",{className:"lk-capsule-info",children:[(0,r.jsx)("span",{className:"lk-capsule-name",title:t.displayName,children:t.displayName}),(0,r.jsx)(gc,{state:t.lifecycleState})]})]}),(0,r.jsx)(gu,{capsule:t,busy:n,busyKind:l,onStart:a,onCancel:s,onDisconnect:o,onHealth:c,onAddToWorkspace:d})]}),null!==u?(0,n9.createPortal)((0,r.jsxs)("div",{className:"lk-connector-drag-ghost",style:{left:u.x+14,top:u.y+14},"aria-hidden":"true",children:[(0,r.jsx)("span",{className:"lk-connector-drag-ghost-icon",children:"▣"}),(0,r.jsxs)("span",{className:"lk-connector-drag-ghost-copy",children:[(0,r.jsx)("span",{children:u.label}),(0,r.jsx)("small",{children:f7.Z[u.state]})]})]}),document.body):null]});}function gg(e){let{creating:t,onCreateCapsule:n}=e;return(0,r.jsxs)("div",{"data-testid":"empty-state",className:"lk-empty",children:[(0,r.jsx)("span",{"aria-hidden":"true",className:"lk-empty-icon",children:"⬡"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"lk-empty-title",children:"No capsules yet"}),(0,r.jsx)("p",{className:"lk-empty-body",children:"Create a capsule to start indexing your local knowledge sources."})]}),(0,r.jsx)("button",{type:"button",disabled:t,"aria-label":"Create your first knowledge capsule",onClick:n,className:"lk-btn lk-btn-primary lk-btn-xl",children:t?"Creating…":"Create your first capsule"})]});}function gv(e){let{capsules:t,isLoading:n,creating:l,actionBusy:a,actionKind:i,onCreateCapsule:s,onStartIndexing:o,onCancelIndexing:c,onDisconnect:d,onOpenHealth:u}=e;return n?(0,r.jsx)("p",{role:"status","aria-live":"polite",className:"lk-loading",children:"Loading capsules…"}):0===t.length?(0,r.jsx)(gg,{creating:l,onCreateCapsule:s}):(0,r.jsx)("ul",{"aria-label":"Knowledge capsule list",style:{display:"flex",flexDirection:"column",gap:8,listStyle:"none",padding:0,margin:0},children:t.map(e=>(0,r.jsx)("li",{style:{display:"block"},children:(0,r.jsx)(gf,{capsule:e,busy:a===e.id,busyKind:a===e.id?i:null,onStart:o,onCancel:c,onDisconnect:d,onHealth:u,onAddToWorkspace:()=>{let t=function(){let e=document.querySelector("main.workspace");if(!(e instanceof HTMLElement))return null;let t=e.getBoundingClientRect();return 0===t.width||0===t.height?null:{clientX:Math.round(t.left+t.width/2),clientY:Math.round(t.top+t.height/2)};}();null!==t&&gh({kind:"capsule",id:e.id,label:e.displayName,lifecycleState:e.lifecycleState},t);}})},e.id))});}function gb(e){let{creating:t,createDialogOpen:n,combineDialogOpen:l,combineDisabled:a,showBackToWorkspace:s,loadStatus:o,loadError:c,actionError:d,createError:u,reload:p,onCreateCapsule:m,onCombineCapsules:h,onDismissCreateError:f,onDismissActionError:g}=e,v=(0,i.useId)();return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("header",{className:"lk-header",children:[(0,r.jsx)("h1",{className:"lk-title",children:"Local Knowledge Connector"}),(0,r.jsxs)("div",{className:"lk-header-actions",children:[s?(0,r.jsx)(ff(),{href:"/",className:"lk-btn lk-btn-ghost lk-btn-lg",children:"Back to Workspace"}):null,(0,r.jsx)("button",{type:"button","aria-disabled":a,"aria-describedby":a?v:void 0,"aria-label":"Combine capsules into a set","aria-haspopup":"dialog","aria-expanded":l,title:a?"Create capsules first, then combine them into a set.":void 0,onClick:()=>{a||h();},className:"lk-btn lk-btn-ghost lk-btn-lg",children:"Combine capsules"}),a?(0,r.jsx)("span",{id:v,className:"visually-hidden",children:"Create capsules first, then combine them into a set."}):null,(0,r.jsx)("button",{type:"button",disabled:t,"aria-label":"Create a new knowledge capsule","aria-haspopup":"dialog","aria-expanded":n,onClick:m,className:"lk-btn lk-btn-primary lk-btn-lg",children:t?"Creating…":"Create capsule"})]})]}),"error"===o&&null!==c?(0,r.jsx)(gr,{message:c,onRetry:p}):null,null===u||n?null:(0,r.jsx)(gr,{message:u,onDismiss:f}),null!==d?(0,r.jsx)(gr,{message:d,onDismiss:g}):null]});}function gy(e){let t,n,{onOpenCapsule:l,showBackToWorkspace:a=!0}=e,[s,o]=(0,i.useState)(null),c=(0,i.useCallback)(e=>{void 0!==l?l(e):o(e);},[l]),{capsules:d,loadStatus:u,loadError:p,actionBusy:m,actionKind:h,actionError:f,creating:g,createError:v,reload:b,clearCreateError:y,clearActionError:x,handleStartIndexing:w,handleCancelIndexing:j,handleDisconnect:k,handleOpenHealth:N,handleCreateCapsule:S}=function(e){let{fetchCapsulesImpl:t=sb.xr,createCapsuleImpl:n=sb.qY,startIndexingImpl:l=sb.r,cancelIndexingImpl:a=sb.Tq,disconnectCapsuleImpl:r=sb.Qi,onOpenCapsule:s}=e,{capsules:o,loadStatus:c,loadError:d,reload:u}=function(e){let[t,n]=(0,i.useState)([]),[l,a]=(0,i.useState)("loading"),[r,s]=(0,i.useState)(null),o=(0,i.useCallback)(async()=>{a("loading"),s(null);try{let t=await e();n(t.capsules),a("ready");}catch(e){s((0,ge.W)(e)),a("error");}},[e]);return(0,i.useEffect)(()=>{o();},[o]),{capsules:t,loadStatus:l,loadError:r,reload:function(){o();}};}(t),{actionBusy:p,actionKind:m,actionError:h,clearActionError:f,handleStartIndexing:g,handleCancelIndexing:v,handleDisconnect:b,handleOpenHealth:y}=function(e,t,n,l,a){let r=(0,fX.useRouter)(),[s,o]=(0,i.useState)(null),[c,d]=(0,i.useState)(null),[u,p]=(0,i.useState)(null);async function m(t,n,l){o(t),d(n),p(null);try{await l(),e();}catch(e){p((0,ge.W)(e));}finally{o(null),d(null);}}return{actionBusy:s,actionKind:c,actionError:u,clearActionError:function(){p(null);},handleStartIndexing:function(e){m(e,"index",()=>t(e));},handleCancelIndexing:function(e){m(e,"cancel",()=>n(e));},handleDisconnect:function(e){m(e,"disconnect",()=>l(e));},handleOpenHealth:function(e){void 0!==a?a(e):r.push(`/local-knowledge/capsule?capsuleId=${encodeURIComponent(e)}`);}};}(u,l,a,r,s),{creating:x,createError:w,clearCreateError:j,handleCreateCapsule:k}=function(e,t){let[n,l]=(0,i.useState)(!1),[a,r]=(0,i.useState)(null);return{creating:n,createError:a,clearCreateError:function(){r(null);},handleCreateCapsule:async function n(n){l(!0),r(null);try{await e({displayName:n}),t();}catch(e){r((0,ge.W)(e));}finally{l(!1);}}};}(n,u);return{capsules:o,loadStatus:c,loadError:d,actionBusy:p,actionKind:m,actionError:h,creating:x,createError:w,reload:u,clearCreateError:j,clearActionError:f,handleStartIndexing:g,handleCancelIndexing:v,handleDisconnect:b,handleOpenHealth:y,handleCreateCapsule:k};}({...e,onOpenCapsule:c}),C="loading"===u,[R,I]=(0,i.useState)(!1),[E,$]=(0,i.useState)(!1),[A,T]=(0,i.useState)(null);async function F(e){try{await S(e),I(!1);}catch{}}return null!==s&&void 0===l?(0,r.jsxs)("div",{className:"lk-page",children:[(0,r.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost lk-btn-lg lk-back-inline",onClick:()=>{o(null),b();},children:"Back to capsules"}),(0,r.jsx)(ga.CapsuleDetail,{capsuleId:s,onDeleted:()=>{o(null),b();}})]}):(0,r.jsxs)("div",{className:"lk-page",children:[(0,r.jsx)(gb,{creating:g,createDialogOpen:R,combineDialogOpen:E,combineDisabled:C||0===d.length,showBackToWorkspace:a,loadStatus:u,loadError:p,actionError:f,createError:v,reload:b,onCreateCapsule:()=>I(!0),onCombineCapsules:()=>$(!0),onDismissCreateError:y,onDismissActionError:x}),(0,r.jsx)("p",{role:"status",className:"visually-hidden",children:C||null!==p?null:(t=d.filter(e=>"indexing"===e.lifecycleState).length,n=`${d.length.toString()} capsule${1===d.length?"":"s"}`,t>0?`${n}, ${t.toString()} indexing`:n)}),(0,r.jsxs)("section",{"aria-label":"Knowledge capsules","aria-busy":C,style:{flex:1,minHeight:0,overflowY:"auto"},children:[(0,r.jsx)("h2",{className:"lk-section-head",children:"Knowledge Capsules"}),(0,r.jsx)(gv,{capsules:d,isLoading:C,creating:g,actionBusy:m,actionKind:h,onCreateCapsule:()=>I(!0),onStartIndexing:w,onCancelIndexing:j,onDisconnect:e=>{var t;return T(null!=(t=d.find(t=>t.id===e))?t:null);},onOpenHealth:N})]}),R?(0,r.jsx)(gs,{busy:g,error:v,onCancel:()=>{I(!1),y();},onSubmit:F}):null,E?(0,r.jsx)(gl,{capsules:d,onCancel:()=>$(!1),onCreated:function(){$(!1),b();}}):null,null!==A?(0,r.jsx)(go,{capsuleName:A.displayName,onCancel:()=>T(null),onConfirm:()=>{k(A.id),T(null);}}):null]});}function gx(e,t){let n=e[t];return"string"==typeof n?n:void 0;}function gw(e,t){var n,l,a;return null!=(n=null!=(l=null!=(a=e.activeRoot)?a:t)?l:e.linkedRoot)?n:void 0;}function gj(e,t){let n=e[t];return"number"==typeof n&&Number.isFinite(n)?n:void 0;}function gk(e,t){let n=gx(e,t);if(void 0===n||0===n.trim().length)return[];try{let e=JSON.parse(n);if(!Array.isArray(e))return[];return e.filter(e=>"string"==typeof e&&e.trim().length>0).map(e=>e.trim());}catch{return[];}}function gN(e){var t;let{cfg:n,ctx:l}=e,a=aw({autoCreate:!1}),s=(0,i.useRef)(!1),c=gx(n,"chatId"),d=gx(n,"title"),{updateCfg:u}=l,{activeChat:p,activeProject:m,chats:h,loading:f,openChat:g,openNewChat:v}=a,b=void 0!==p&&"closed"!==p.status?p:void 0;(0,i.useEffect)(()=>{if(!f){if(void 0!==c){if((null==b?void 0:b.id)===c)return;let e=h.find(e=>e.id===c&&"closed"!==e.status);void 0!==e&&g(e);return;}s.current||(s.current=!0,v(void 0,d).then(e=>{void 0!==e&&u({chatId:e.id,title:e.title});}).finally(()=>{s.current=!1;}));}},[c,null==b?void 0:b.id,h,f,g,v,d,u]),(0,i.useEffect)(()=>{f||void 0===c||(null==b?void 0:b.id)!==c||b.title!==d&&u({title:b.title});},[null==b?void 0:b.id,null==b?void 0:b.title,c,f,d,u]);let y=void 0!==c&&!a.loading&&(null==b?void 0:b.id)!==c&&!a.chats.some(e=>e.id===c&&"closed"!==e.status),x=a.loading||void 0!==c&&(null==b?void 0:b.id)!==c,w=(0,i.useCallback)(e=>{var t,n;if(void 0===e.runId)return;let a={runId:e.runId},r=null!=(t=e.workflowId)?t:e.taskType;void 0!==r&&(a.workflow=r);let i=null!=(n=l.activeRoot)?n:null==m?void 0:m.path;void 0!==i&&(a.workspaceRoot=i),l.openWindow("agents",a);},[null==m?void 0:m.path,l]);return(0,r.jsx)(o,{value:a,children:y?(0,r.jsxs)("div",{className:"lk-empty",children:[(0,r.jsx)("p",{className:"lk-empty-title",children:"Chat not found"}),(0,r.jsx)("p",{className:"lk-empty-body",children:"This conversation was deleted or is no longer available."})]}):x?(0,r.jsx)("div",{className:"lk-loading",children:"Opening chat..."}):(0,r.jsx)(on,{mini:!0===l.mini,minimalChat:!0===l.minimalChat,compact:!0===l.compact,controlsNarrow:!0===l.controlsNarrow,barCompact:!0===l.barCompact,workflowCompact:!0===l.workflowCompact,linkedRoot:null!=(t=l.activeRoot)?t:l.linkedRoot,linkedRoots:l.linkedRoots,openEditorFile:l.openEditorFile,onOpenRunResult:w})});}ec("chat",(e,t)=>(0,r.jsx)(gN,{cfg:e,ctx:t})),ec("chatHistory",(e,t)=>(0,r.jsx)(os,{openChatWindow:e=>{t.openWindow("chat",{chatId:e.id,title:e.title});}})),ec("project",()=>(0,r.jsx)(oi,{})),ec("promptEnhancer",(e,t)=>{var n;return(0,r.jsx)(oT,{connectedRoot:t.linkedRoot,connectedFilePath:null!=(n=t.linkedFilePath)?n:null,connectedRoots:t.linkedRoots});}),ec("search",()=>(0,r.jsx)(oo,{})),ec("plugins",()=>(0,r.jsx)(oP,{})),ec("automations",()=>(0,r.jsx)(oW,{})),ec("mobile",()=>(0,r.jsx)(oK,{})),ec("inspector",()=>(0,r.jsx)(oU,{})),ec("notifications",()=>(0,r.jsx)(oH,{})),ec("resources",()=>(0,r.jsx)(o_,{})),ec("activity",()=>(0,r.jsx)(oY,{})),ec("keiko",()=>(0,r.jsx)(pm,{})),ec("settings",()=>(0,r.jsx)(pR,{})),ec("localKnowledge",()=>(0,r.jsx)(gy,{showBackToWorkspace:!1})),ec("quality",(e,t)=>{var n;return(0,r.jsx)(mJ,{openRun:(e,n)=>{var l;let a=void 0!==n?{[oc]:JSON.stringify(n.filter(op))}:om(ov({connectedFilePath:null!=(l=t.linkedFilePath)?l:null,connectedRoot:t.linkedRoot,connectedRoots:t.linkedRoots,connectedCapsuleIds:t.linkedCapsuleIds,connectedCapsuleSetIds:t.linkedCapsuleSetIds,connectedFigmaSnapshotRunIds:t.linkedFigmaSnapshotRunIds,connectedFigmaSnapshotSources:t.linkedFigmaSnapshotSources,connectedImageSources:t.linkedImageSources}));t.openWindow("qiRun",{runId:e,...a});},connectedRoot:t.linkedRoot,connectedFilePath:null!=(n=t.linkedFilePath)?n:null,connectedRoots:t.linkedRoots,connectedCapsuleIds:t.linkedCapsuleIds,connectedCapsuleSetIds:t.linkedCapsuleSetIds,connectedFigmaSnapshotRunIds:t.linkedFigmaSnapshotRunIds,connectedFigmaSnapshotSources:t.linkedFigmaSnapshotSources,connectedImageSources:t.linkedImageSources});}),ec("qiRun",(e,t)=>{let n=gx(e,"runId");if(void 0===n||""===n)return(0,r.jsx)("div",{className:"lk-empty",children:(0,r.jsx)("p",{className:"lk-empty-body",children:"Open a run from the Quality Intelligence hub."})});let l=function(e){var t,n;let l=od(e,oc);if(void 0!==l&&l.length>0){let e=function(e){try{let t=JSON.parse(e);if(!Array.isArray(t)||!t.every(op))return null;return t;}catch{return null;}}(l);if(null!==e)return e;}return ov({connectedFilePath:null!=(t=od(e,"connectedFilePath"))?t:null,connectedRoot:null!=(n=od(e,"connectedRoot"))?n:null});}(e),a=om(l);return(0,r.jsx)(hS,{runId:n,connectedSources:l,onRegenerated:e=>{t.openWindow("qiRun",{runId:e.runId,...a});}});}),ec("relationships",()=>(0,r.jsx)(fm,{})),ec("files",(e,t)=>{let n=gw(t,gx(e,"root")),l=(e,n,l)=>{let a={activeFilePath:null!=e?e:void 0,resolvedRoot:null!=n?n:void 0};void 0!==l&&(a.activeDirectoryPath=null!=l?l:void 0),t.updateCfg(a);},a=e=>{t.updateCfg({root:e,activeFilePath:void 0,activeDirectoryPath:void 0,resolvedRoot:void 0});},i=(e,n)=>{t.openWindow("editor",{root:e,file:n,openFiles:[n]});},s=e=>{t.openWindow("governedGit",{projectPath:e});};return void 0!==n?(0,r.jsx)(ce,{root:n,onActiveFileChange:l,onRootChange:a,onOpenFile:i,onOpenGitDelivery:s}):(0,r.jsx)(ce,{onActiveFileChange:l,onRootChange:a,onOpenFile:i,onOpenGitDelivery:s});}),ec("editor",(e,t)=>{var n;let l=gw(t,gx(e,"root")),a=gx(e,"file"),i=function(e,t){let n=e[t];if(!Array.isArray(n))return;let l=n.filter(e=>"string"==typeof e&&e.trim().length>0).map(e=>e.trim());return l.length>0?l:void 0;}(e,"openFiles"),s=gx(e,"layoutJson"),o=gj(e,"revealLineStart"),c=gj(e,"revealLineEnd"),d=gx(e,"revealRequestId"),u={};return void 0!==l&&(u.root=l),void 0!==a&&(u.file=a),void 0!==i&&(u.openFiles=i),void 0!==s&&(u.layoutJson=s),void 0!==o&&(u.revealLineStart=o),void 0!==c&&(u.revealLineEnd=c),void 0!==d&&(u.revealRequestId=d),u.linkedRoot=t.linkedRoot,u.linkedFilePath=t.linkedFilePath,u.linkedCapsuleIds=t.linkedCapsuleIds,u.linkedCapsuleSetIds=t.linkedCapsuleSetIds,u.windowId=t.windowId,u.onWorkspaceChange=e=>{t.updateCfg(e);},(0,r.jsx)(cm,{...u},null!=(n=t.activeRoot)?n:"unbound");}),ec("browser",e=>{let t=gx(e,"url");return void 0!==t&&""!==t?(0,r.jsx)(ck,{url:t}):(0,r.jsx)(ck,{});}),ec("terminal",(e,t)=>{var n;let l=gw(t,gx(e,"projectPath")),a=null!=(n=t.activeRoot)?n:gx(e,"cwd"),i={};return void 0!==a&&(i.cwd=a),void 0!==l&&(i.projectPath=l),(0,r.jsx)(c$,{...i});}),ec("commands",(e,t)=>{let n=gw(t,gx(e,"projectPath")),l={};return void 0!==n&&(l.projectPath=n),(0,r.jsx)(cL,{...l});}),ec("runtime",(e,t)=>{let n=gw(t,gx(e,"projectPath")),l=(e,n)=>{t.openWindow(e,{projectPath:n});};return(0,r.jsx)(cz,{projectPath:n,onProjectPathChange:e=>t.updateCfg({projectPath:e}),onOpenFiles:e=>{t.openWindow("files",void 0!==e?{root:e}:void 0);},onOpenCommands:e=>l("commands",e),onOpenContainers:e=>{t.openWindow("containerStatus",void 0!==e?{projectPath:e}:void 0);},onOpenGovernedGit:e=>l("governedGit",e),onOpenPullRequest:e=>l("governedPullRequest",e),onOpenMerge:e=>l("governedMerge",e)});}),ec("governedGit",(e,t)=>{var n;let l=gw(t,null!=(n=gx(e,"projectPath"))?n:gx(e,"workspaceRoot"));return(0,r.jsx)(uU,{projectId:l,onOpenFiles:e=>t.openWindow("files",{root:e}),onOpenEditor:e=>t.openWindow("editor",{root:e}),openWindow:(e,n)=>t.openWindow(e,n),updateCfg:e=>t.updateCfg(e)});}),ec("governedPullRequest",(e,t)=>{var n,l;let a=gw(t,null!=(n=gx(e,"projectPath"))?n:gx(e,"workspaceRoot")),i=null!=(l=gx(e,"headBranchName"))?l:void 0;return(0,r.jsx)(db,{projectId:a,headBranchName:i});}),ec("governedMerge",(e,t)=>{var n,l;let a=gw(t,null!=(n=gx(e,"projectPath"))?n:gx(e,"workspaceRoot")),i=null!=(l=gx(e,"headBranchName"))?l:void 0;return(0,r.jsx)(dt,{projectId:a,headBranchName:i});}),ec("containerStatus",(e,t)=>{let n=gw(t,gx(e,"projectPath")),l={};return void 0!==n&&(l.projectPath=n),(0,r.jsx)(uQ,{...l});}),ec("review",(e,t)=>{let n=gx(e,"runId"),l=e=>{t.updateCfg({runId:e});};return void 0!==n&&""!==n?(0,r.jsx)(u3,{runId:n,onRunIdSubmit:l}):(0,r.jsx)(u3,{onRunIdSubmit:l});}),ec("agents",(e,t)=>{var n;let l,a,i,s,o,c,d,u,p,m,h;return(0,r.jsx)(pe,{cfg:(i={},void 0!==(s=gx(n=e,"workflow"))&&(i.workflow=s),void 0!==(o=gx(n,"model"))&&(i.model=o),void 0!==(c=gx(n,"runId"))&&(i.runId=c),void 0!==(d=gx(n,"fingerprint"))&&(i.fingerprint=d),void 0!==(u=gx(n,"workspaceRoot"))&&(i.workspaceRoot=u),void 0!==(p=gx(n,"inputJson"))&&(i.inputJson=p),void 0!==(m="boolean"==typeof(l=n.keikoMode)?l:void 0)&&(i.keikoMode=m),void 0!==(h="ask"===(a=n.access)||"full"===a?a:void 0)&&(i.access=h),i),linkedRoot:t.linkedRoot,linkedFilePath:t.linkedFilePath});}),ec("memoria",()=>(0,r.jsx)(f8,{})),ec("integ",()=>(0,r.jsx)(pn,{})),ec("figma",(e,t)=>{let n=gx(e,"snapshotRunId"),l=gk(e,"selectedScreenIdsJson"),a=gx(e,"selectedScreenName");return(0,r.jsx)(ma,{sourceWindowId:t.windowId,snapshotRunId:n,selectedScreenIds:l,selectedScreenName:a,openScreenSource:e=>{let{snapshotRunId:n,screenId:l,name:a}=e;t.openWindow("figmaView",{snapshotRunId:n,selectedScreenIdsJson:JSON.stringify([l]),selectedScreenName:a});},openTokenSettings:()=>{pg(),t.openWindow("settings");},updateCfg:e=>{t.updateCfg(e);}});}),ec("figmaView",(e,t)=>{let n=gx(e,"snapshotRunId"),l=gk(e,"selectedScreenIdsJson"),a=gx(e,"selectedScreenName");return(0,r.jsx)(ma,{sourceWindowId:t.windowId,snapshotRunId:n,selectedScreenIds:l,selectedScreenName:a,openTokenSettings:()=>{pg(),t.openWindow("settings");},updateCfg:e=>{t.updateCfg(e);}});}),ec("figmaJson",e=>{let t=gx(e,"snapshotRunId"),n=gx(e,"screenId"),l=gx(e,"selectedScreenName");return(0,r.jsx)(mr,{snapshotRunId:t,screenId:n,screenName:l});}),ec("figmaImage",e=>{let t=gx(e,"imageSrc"),n=gx(e,"selectedScreenName");return(0,r.jsx)(mi,{imageSrc:t,screenName:n});}),ec("connector",(e,t)=>{let n=gx(e,"presentation"),l=gx(e,"selectedKind"),a=gx(e,"selectedId"),i=gx(e,"selectedLabel"),s=gx(e,"selectedState");return(0,r.jsx)(pD,{presentation:n,selectedKind:l,selectedId:a,selectedLabel:i,selectedState:s,onSelect:e=>{t.updateCfg(e);},onManageConnectors:()=>{t.openWindow("localKnowledge");}});});let gS={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 gC(){let{available:e,triggerInstall:t}=function(){let[e,t]=(0,i.useState)(!1),n=(0,i.useRef)(null);return(0,i.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));},l=()=>{localStorage.setItem("keiko.pwa.installed","true"),n.current=null,t(!1);};return window.addEventListener("beforeinstallprompt",e,{passive:!1}),window.addEventListener("appinstalled",l),()=>{window.removeEventListener("beforeinstallprompt",e),window.removeEventListener("appinstalled",l);};},[]),{available:e,triggerInstall:(0,i.useCallback)(async()=>{let e=n.current;if(null===e)return;await e.prompt();let{outcome:l}=await e.userChoice;"accepted"===l&&localStorage.setItem("keiko.pwa.installed","true"),n.current=null,t(!1);},[])};}(),[n,l]=(0,i.useState)(!1),[a]=(0,i.useState)(()=>{let e;return"u">typeof navigator?(e=navigator.userAgent.toLowerCase()).includes("crios/")?"manual":e.includes("chrome/")&&!e.includes("mobile")||e.includes("edg/")||e.includes("chromium/")?"supported":e.includes("firefox/")?"manual":e.includes("safari/")&&(e.includes("iphone")||e.includes("ipad")||e.includes("ipod"))?"ios-add-to-home":(e.includes("safari/")&&e.includes("macintosh"),"manual"):"manual";}),s=(0,i.useRef)(null),o=(0,i.useCallback)(()=>{localStorage.setItem("keiko.pwa.dismissed",new Date().toISOString()),l(!0);},[]),c=(0,i.useCallback)(async()=>{await t();},[t]),d=(0,i.useCallback)(e=>{"Escape"!==e.key||e.defaultPrevented||o();},[o]);if(n||window.matchMedia("(display-mode: standalone)").matches||"true"===localStorage.getItem("keiko.pwa.installed")||function(){let e=localStorage.getItem("keiko.pwa.dismissed");if(null===e)return!1;let t=Date.parse(e);return!!Number.isNaN(t)||Date.now()-t<2592e6;}()||"supported"===a&&!e||"supported"!==a&&"ios-add-to-home"!==a)return null;let u=gS[a];return(0,r.jsx)("aside",{className:"install-banner",role:"region","aria-label":"Install Keiko",onKeyDown:d,children:(0,r.jsxs)("div",{className:"install-banner-body",children:[(0,r.jsxs)("div",{className:"install-banner-text",children:[(0,r.jsx)("span",{className:"install-banner-heading",children:u.heading}),(0,r.jsx)("span",{className:"install-banner-desc",children:u.body})]}),(0,r.jsxs)("div",{className:"install-banner-actions",children:[null!==u.install&&(0,r.jsx)("button",{ref:s,type:"button",className:"install-banner-btn-install",onClick:()=>void c(),children:u.install}),(0,r.jsx)("button",{type:"button",className:"install-banner-btn-dismiss",onClick:o,children:"Not now"})]})]})});}let gR="keiko.service-worker-update-reload-pending",gI=!1;function gE(){gI||function(){try{if("true"!==window.sessionStorage.getItem(gR))return!1;return window.sessionStorage.removeItem(gR),!0;}catch{return!0;}}()&&(gI=!0,window.location.reload());}function g$(e){let t=e.waiting;if(null!==t){try{window.sessionStorage.setItem(gR,"true");}catch{}try{t.postMessage({type:"KEIKO_ACTIVATE_WAITING_SERVICE_WORKER"});}catch{try{window.sessionStorage.removeItem(gR);}catch{}}}}function gA(e){return null===e||void 0===e.root?null:[e.root.replace(/\\/gu,"/").replace(/\/+$/u,""),e.kind,...e.relativePaths.map(e=>e.replace(/\\/gu,"/").replace(/^\/+|\/+$/gu,""))].join("\0");}function gT(e,t){if(/^\/+$/u.test(e.trim().replace(/\\/gu,"/"))){let e=t.trim().replace(/\\/gu,"/");return 0===e.length?"":e.replace(/^\/+/u,"");}let n=t$(e,t);return"relative"===n.kind?n.path:"root"===n.kind||"empty"===n.kind?"":null;}let gF=["chat","connector","files","editor","agents"],gD=["chatHistory","memoria","settings","automations","mobile","inspector","activity","notifications","resources","localKnowledge","governedGit","figma","quality","promptEnhancer","relationships"];function gM(e){requestAnimationFrame(()=>{var t;let n=document.querySelector(`[data-window-id="${e}"]`);null===n||(null!=(t=n.querySelector("textarea, input, select, button, [tabindex]"))?t:n).focus();});}function gP(){var e,t,n,l,a,s,c,d,u,h,f;let g,{t:v}=ea(),{theme:$,toggle:A}=function(){let[e,t]=(0,i.useState)(ak),[n,l]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{t(function(){try{let e=window.localStorage.getItem(aj);return"light"===e||"dark"===e?e:ak;}catch{return ak;}}()),l(!0);},[]),(0,i.useEffect)(()=>{if(n){"u">typeof document&&(document.documentElement.dataset.theme=e);try{window.localStorage.setItem(aj,e);}catch{}}},[e,n]),{theme:e,toggle:(0,i.useCallback)(()=>{t(e=>"light"===e?"dark":"light");},[])};}(),T=J(),F=aw({autoCreate:!1}),D=function(){var e,t,n,l;let[a,r]=(0,i.useReducer)(I,R),s=(0,i.useRef)(null),o=(0,i.useCallback)(async()=>{let e=s.current,[t,n]=await Promise.all([x(),null===e||0===e.length?Promise.resolve([]):y(e).catch(()=>[])]);r({kind:"settle",instances:n,active:t});},[]),c=(0,i.useCallback)(async e=>{void 0!==e&&(s.current=e),r({kind:"load-start"});try{await o();}catch(e){r({kind:"fail",error:E(e)});}},[o]),d=(0,i.useCallback)(async e=>{r({kind:"mutate-start"});try{await e(),await o();}catch(e){r({kind:"fail",error:E(e)});}},[o]),u=(0,i.useCallback)(e=>d(()=>w({workspaceId:e,requestedBy:C})),[d]),p=(0,i.useCallback)(()=>d(()=>j()),[d]),m=(0,i.useCallback)(e=>d(()=>k({workspaceId:e,requestedBy:C})),[d]),h=(0,i.useCallback)(e=>d(()=>N({workspaceId:e,requestedBy:C})),[d]),f=(0,i.useCallback)(e=>d(()=>S({workspaceId:e,requestedBy:C})),[d]),g=(0,i.useCallback)(e=>d(async()=>{s.current=e.root,await b({...e,requestedBy:C});}),[d]),v=null!=(e=null==(n=a.active)?void 0:n.binding)?e:null,$=null!=(t=null==(l=a.active)?void 0:l.instance)?t:null;return(0,i.useMemo)(()=>{var e;return{instances:a.instances,activeBinding:v,activeInstance:$,activeRoot:null!=(e=null==v?void 0:v.activeRoot)?e:null,loading:a.loading,switching:a.switching,error:a.error,refresh:c,switchTo:u,clearActive:p,pause:m,resume:h,prepareHandoff:f,provision:g};},[a.instances,a.loading,a.switching,a.error,v,$,c,u,p,m,h,f,g]);}(),M=(0,i.useRef)(null),P=(0,i.useRef)(null),[q,z]=(0,i.useState)(lO.ty);(0,i.useEffect)(()=>{(0,m.Dz)().then(e=>z(e.effectiveGroundingLimits)).catch(()=>void 0);},[]);let O=D.refresh,B=null==(n=F.activeProject)?void 0:n.path;(0,i.useEffect)(()=>{O(B);},[O,B]);let[W,K]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(null===W)return;let e=window.setTimeout(()=>K(null),1e4);return()=>window.clearTimeout(e);},[W]);let U=(0,i.useCallback)((e,t)=>(K(`Source limit reached — this chat already has ${String(e)} of ${String(t)} connected sources. Disconnect a source before connecting another.`),!1),[]),V=(0,i.useCallback)(e=>(K(e),!1),[]),H=(0,i.useCallback)(e=>{var t,n,l;let a=function(e){if((null==e?void 0:e.type)!=="chat")return;let t=e.cfg.chatId;return"string"==typeof t&&t.length>0?t:void 0;}(null==(n=P.current)?void 0:n.find(t=>t.id===e));if(void 0===a)return;let r=null!=(t=F.chats.find(e=>e.id===a))?t:(null==(l=F.activeChat)?void 0:l.id)===a?F.activeChat:void 0;return(null==r?void 0:r.status)==="closed"?void 0:r;},[F.activeChat,F.chats]),_=(0,i.useCallback)(async function(e,t){var n;let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=H(e);if(void 0===a)return V("Open a ready chat window before connecting a source.");let r=null===l?np(a):nu(np(a),l),i=nm(a);if(r.some(e=>ns(e,t))){if(null!==l){let e=await(0,m.Mr)(a.id,r.length>0?r:null);F.replaceChat(e.chat);}return!0;}let s=nd(q);if(r.length+i.length>=s)return U(r.length+i.length,s);let o={...t,connectedAtMs:Date.now()},c=function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:16;if(void 0===t.root)return null;let l=na(t.root);if(!nl(l))return null;let a=t.relativePaths.map(ni),r={kind:t.kind,relativePaths:a,root:l,connectedAtMs:t.connectedAtMs};return e.some(e=>ns(e,r))||e.length>=n?e:[...e,r];}(r,o,q.maxConnectedSources);if(null===c)return V("Choose a local folder before connecting it to chat.");if(c===r)return U(r.length+i.length,s);try{let e=await(0,m.Mr)(a.id,c);F.replaceChat(e.chat),K(null);let t=function(e){var t;if(void 0===e.root)return null;let n=null==(t=e.relativePaths[0])?void 0:t.replace(/\\/gu,"/").replace(/^\/+/u,"");if(void 0===n||0===n.length)return e.root;let l=e.root.replace(/\\/gu,"/").replace(/\/+$/u,"");return`${l}/${n}`;}(o);return null!==t&&(n=a.id,0!==n.length&&0!==t.length&&aM({type:"reads-context",source:{kind:"chat",id:n},target:{kind:"workspace-path",id:t}},function(e,t){let n=0x811c9dc5,l=`${e}|${t}`;for(let e=0;e<l.length;e+=1)n=Math.imul(n^l.charCodeAt(e),0x1000193);return`rc-${(n>>>0).toString(36)}-${(65535&l.length).toString(36)}`;}(n,t)).catch(e=>{})),!0;}catch{return V("Keiko could not connect that source. Check that it is still available and try again.");}},[H,F,q,U,V]),G=(0,i.useCallback)(async(e,t)=>_(e,t),[_]),X=(0,i.useCallback)((e,t)=>{let n=H(e);if(void 0===n)return;let l=nu(np(n),t);(0,m.Mr)(n.id,l.length>0?l:null).then(e=>{F.replaceChat(e.chat);}).catch(e=>{console.warn("[keiko] connected-scope unbind failed",e);});},[H,F]),Z=(0,i.useCallback)(async(e,t)=>{var n;let l,a,r=H(e);if(void 0===r)return V("Open a ready chat window before connecting a source.");let i=nm(r),s=np(r);if(l=nh(t),i.some(e=>nh(e)===l))return!0;let o=nd(q);if(s.length+i.length>=o)return U(s.length+i.length,o);let c=(n=q.maxLocalKnowledgeSources,a=nh(t),i.some(e=>nh(e)===a)||i.length>=n?i:[...i,t]);if(c===i)return U(s.length+i.length,o);try{let e=await(0,m.Cp)(r.id,c);return F.replaceChat(e.chat),K(null),!0;}catch{return V("Keiko could not connect that knowledge source. Check that it is still available and try again.");}},[H,F,q,U,V]),Q=(0,i.useCallback)((e,t)=>{var n;let l=H(e);if(void 0===l)return;let a="capsule"===t.kind?`capsule:${t.capsuleId}`:`set:${t.capsuleSetId}`,r=(n=nm(l),n.filter(e=>nh(e)!==a));(0,m.Cp)(l.id,r.length>0?r:null).then(e=>{F.replaceChat(e.chat);}).catch(()=>void 0);},[H,F]),[ee,et]=(0,i.useState)(eQ);(0,i.useEffect)(()=>{let e=e=>{let t=e.detail;et("number"==typeof t?t:0);};return window.addEventListener(eV,e),()=>{window.removeEventListener(eV,e);};},[]);let en=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},[n,l]=(0,i.useState)(null),[a,r]=(0,i.useState)(null),[s,o]=(0,i.useState)(!1),[c,d]=(0,i.useState)([]),[u,p]=(0,i.useState)(null),[m,h]=(0,i.useState)(nw),{cameraSmoothness:f=0,onScopeBind:g,onScopeUnbind:v,onConnectorBind:b,onConnectorUnbind:y}=t,x=(0,i.useRef)(3),w=(0,i.useRef)(null),j=(0,i.useRef)(!1),k=(0,i.useCallback)(()=>{j.current=!0;},[]),N=(0,i.useRef)([]);N.current=null!=n?n:[];let S=(0,i.useRef)([]);S.current=c;let C=(0,i.useMemo)(()=>new Map((null!=n?n:[]).map(e=>[e.id,e])),[n]),R=(0,i.useMemo)(()=>new Map(c.map(e=>[e.id,e])),[c]),I=(0,i.useMemo)(()=>{let e=new Map();for(let t of c){let n=e.get(t.a);void 0===n?e.set(t.a,[t]):n.push(t);let l=e.get(t.b);void 0===l?e.set(t.b,[t]):l.push(t);}return e;},[c]),E=(0,i.useRef)(C);E.current=C;let $=(0,i.useRef)(R);$.current=R;let A=(0,i.useRef)(I);A.current=I;let T=(0,i.useRef)(null);T.current=u;let F=(0,i.useRef)(null),D=(0,i.useRef)(()=>void 0),{viewRef:M,worldVP:P,zoomTo:L,fitView:q,resetView:z,panBy:O,rect:B}=function(e){let{wsRef:t,view:n,cameraSmoothness:l,winsRef:a,setView:r,setWins:s}=e,o=(0,i.useRef)(n);o.current=n;let c=(0,i.useRef)(n);c.current=n;let d=(0,i.useRef)(null),u=(0,i.useRef)(1),p=(0,i.useRef)(90),m=(0,i.useRef)(null),h=(0,i.useRef)(null),f=(0,i.useRef)(n),g=(0,i.useRef)(n),v=(0,i.useRef)(0),b=(0,i.useRef)(null);null===b.current&&(b.current=nC(300));let y=(0,i.useCallback)(()=>{var e;null==(e=b.current)||e.schedule(()=>nS(ny,o.current));},[]);(0,i.useEffect)(()=>{let e=b.current;if(null===e)return;let t=()=>e.flush(),n=()=>{"u">typeof document&&"hidden"===document.visibilityState&&e.flush();};return window.addEventListener("pagehide",t),document.addEventListener("visibilitychange",n),()=>{window.removeEventListener("pagehide",t),document.removeEventListener("visibilitychange",n),e.flush();};},[]),(0,i.useEffect)(()=>()=>{null!==m.current&&"function"==typeof window.cancelAnimationFrame&&window.cancelAnimationFrame(m.current),null!==h.current&&"function"==typeof window.cancelAnimationFrame&&window.cancelAnimationFrame(h.current);},[]);let x=(0,i.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:90,a=Math.min(100,Math.max(0,l*t));if(a<=0||"function"==typeof window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches||"function"!=typeof window.requestAnimationFrame||"function"!=typeof window.cancelAnimationFrame){null!==h.current&&(window.cancelAnimationFrame(h.current),h.current=null),r(e);return;}let i=n+(280-n)*a/100,s="u">typeof performance&&"function"==typeof performance.now?performance.now():Date.now();if(f.current=null===h.current?c.current:n$(f.current,g.current,nE(Math.min(1,(s-v.current)/i))),g.current=e,v.current=s,null!==h.current)return;let o=e=>{let t=Math.min(1,Math.max(0,(e-v.current)/i)),n=nE(t);if(t>=1){h.current=null,r(g.current);return;}r(n$(f.current,g.current,n)),h.current=window.requestAnimationFrame(o);};h.current=window.requestAnimationFrame(o);},[l,r]),w=(0,i.useCallback)(()=>{null!==h.current&&"function"==typeof window.cancelAnimationFrame&&(window.cancelAnimationFrame(h.current),h.current=null,r(g.current),c.current=g.current);},[r]),j=(0,i.useCallback)(function(e){var t,n,l;let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=null!=(t=d.current)?t:o.current,s="function"==typeof e?e(i):e,c=null!=(n=a.smoothnessScale)?n:1,h=null!=(l=a.minDurationMs)?l:90;if(o.current=s,d.current=s,u.current=c,p.current=h,y(),"function"!=typeof window.requestAnimationFrame||"function"!=typeof window.cancelAnimationFrame){d.current=null,r(s);return;}null===m.current&&(m.current=window.requestAnimationFrame(()=>{m.current=null;let e=d.current,t=u.current,n=p.current;d.current=null,u.current=1,p.current=90,null!==e&&x(e,t,n);}));},[x,y,r]);(0,i.useEffect)(()=>{let e=t.current;if(null===e)return;let n=t=>{if(t.metaKey||t.ctrlKey){var n,l,a;t.preventDefault();let r=(n=t.target)instanceof Element&&null!=(l=null==(a=n.closest(".window[data-window-id]"))?void 0:a.dataset.windowId)?l:null;if(null!==r){w(),s(e=>null===e?e:e.map(e=>{var n,l,a;let i,s;return e.id===r?(n=e,l=t.deltaY,(s=nk((i=null!=(a=n.zoom)?a:1)*Math.exp(-(.0015*l))))===i?n:{...n,zoom:s}):e;}));return;}let i=e.getBoundingClientRect(),c=o.current,d=nI(t),u=nj(c.zoom*Math.exp(-(.0015*d.y))),p=(t.clientX-i.left-c.x)/c.zoom,m=(t.clientY-i.top-c.y)/c.zoom;j({zoom:u,x:t.clientX-i.left-p*u,y:t.clientY-i.top-m*u});return;}let r=t.target;if(r instanceof Element&&null!==r.closest(".window"))return;t.preventDefault();let i=nI(t);j(e=>({...e,x:e.x-i.x,y:e.y-i.y}),{minDurationMs:0,smoothnessScale:.65});};return e.addEventListener("wheel",n,{passive:!1}),()=>{e.removeEventListener("wheel",n);};},[t,s,j,w]);let k=(0,i.useCallback)(()=>null===t.current?null:t.current.getBoundingClientRect(),[t]),N=(0,i.useCallback)(()=>{let e=k();if(null===e)return null;let t=o.current;return{x:-t.x/t.zoom,y:-t.y/t.zoom,w:e.width/t.zoom,h:e.height/t.zoom};},[k]),S=(0,i.useCallback)(e=>{let t=k();if(null===t)return;let n=o.current,l=t.width/2,a=t.height/2,r=(l-n.x)/n.zoom,i=(a-n.y)/n.zoom,s=nj(e);j({zoom:s,x:l-r*s,y:a-i*s});},[k,j]),C=(0,i.useCallback)(()=>{let e=k();null!==e&&j(function(e,t){let n=e.filter(e=>!0!==e.minimized);if(0===n.length)return{zoom:1,x:0,y:0};let l=1/0,a=1/0,r=-1/0,i=-1/0;for(let e of n)l=Math.min(l,e.x),a=Math.min(a,e.y),r=Math.max(r,e.x+e.w),i=Math.max(i,e.y+e.h);let s=Math.max(1,r-l),o=Math.max(1,i-a),c=nj(Math.min(1,Math.max(1,t.width-144)/s,Math.max(1,t.height-144)/o)),d=l+s/2,u=a+o/2;return{zoom:c,x:Math.round(t.width/2-d*c),y:Math.round(t.height/2-u*c)};}(a.current,e));},[k,a,j]);return{viewRef:o,worldVP:N,zoomTo:S,fitView:C,resetView:(0,i.useCallback)(()=>j({zoom:1,x:0,y:0}),[j]),panBy:(0,i.useCallback)((e,t)=>j(n=>({...n,x:n.x+e,y:n.y+t}),{minDurationMs:0,smoothnessScale:.65}),[j]),rect:k};}({wsRef:e,view:m,cameraSmoothness:f,winsRef:N,setView:h,setWins:l});!function(e){let{wsRef:t,setWins:n,setConns:l,zc:a}=e;(0,i.useLayoutEffect)(()=>{null!==t.current&&nD(nA(),n,l,a);},[t,n,l,a]);}({wsRef:e,setWins:l,setConns:d,zc:x}),function(e){let{setWins:t,setConns:n,zc:l,beforeApplyRemote:a}=e;(0,i.useEffect)(()=>{let e=e=>{null!==e.storageArea&&e.storageArea!==window.localStorage||(e.key===nv||e.key===nb)&&(a(),nD(nA(),t,n,l));};return window.addEventListener("storage",e),()=>{window.removeEventListener("storage",e);};},[t,n,l,a]);}({setWins:l,setConns:d,zc:x,beforeApplyRemote:k}),function(e){let{wins:t,conns:n,setWins:l,setConns:a,zc:r,suppressNextPersistRef:s}=e,o=(0,i.useRef)(0),c=(0,i.useRef)(t);c.current=t;let d=(0,i.useRef)(n);d.current=n;let u=(0,i.useRef)(null);null===u.current&&(u.current=nC(300));let p=(0,i.useRef)(null),m="u"<typeof navigator||!0!==navigator.webdriver,h=(0,i.useCallback)(e=>{var t;let n=c.current;if(null===n)return;let l=tk(n),a=tN(d.current,l);null==(t=p.current)||t.abort();let r="function"==typeof AbortController?new AbortController():null;p.current=r,nF(l,a,{...(null!==r?{signal:r.signal}:{}),keepalive:e}).then(e=>{null!==e&&e>o.current&&(o.current=e);});},[]),f=(0,i.useCallback)(e=>{var t,n;let i,c=(t=e.windows,n=e.connections,{wins:i=tk(t),conns:tN(n,i)});e.revision>o.current&&(o.current=e.revision),s.current=!0,nD(c,l,a,r);},[l,a,r,s]);(0,i.useEffect)(()=>{if(!m)return;let e=!1,t=null,n=async()=>{var t,n;let l=await nT();e||null===l||l.revision<=o.current||0===o.current&&0===l.windows.length&&(null!=(t=null==(n=c.current)?void 0:n.length)?t:0)>0||f(l);},l=()=>{null!==t&&(window.clearInterval(t),t=null);},a=()=>{"u">typeof document&&"hidden"===document.visibilityState?l():(n(),null===t&&(t=window.setInterval(()=>{n();},1500)));};return a(),document.addEventListener("visibilitychange",a),()=>{e=!0,l(),document.removeEventListener("visibilitychange",a);};},[f,m]),(0,i.useEffect)(()=>{var e;if(m&&null!==t){if(s.current){s.current=!1;return;}null==(e=u.current)||e.schedule(()=>h(!1));}},[t,n,s,m,h]),(0,i.useEffect)(()=>{if(!m)return;let e=u.current,t=()=>{null==e||e.cancel(),h(!0);},n=()=>{"u">typeof document&&"hidden"===document.visibilityState&&t();};return window.addEventListener("pagehide",t),document.addEventListener("visibilitychange",n),()=>{window.removeEventListener("pagehide",t),document.removeEventListener("visibilitychange",n),null==e||e.flush();};},[m,h]);}({wins:n,conns:c,setWins:l,setConns:d,zc:x,suppressNextPersistRef:j}),nR(()=>{null!==n&&nS(nb,tN(c,n));},[c,n]),(0,i.useEffect)(()=>{null!==n&&d(e=>{let t=e.filter(e=>void 0!==n.find(t=>t.id===e.a)&&void 0!==n.find(t=>t.id===e.b));return t.length===e.length?e:t;});},[n,d]),nR(()=>{null!==n&&nS(nv,tk(n));},[n]),function(e){let{setWins:t,rect:n,cancelConnectRef:l}=e;(0,i.useEffect)(()=>{let e=e=>{var a,r;if("Escape"===e.key)return void l.current();if(null!==(a=document.activeElement)&&("INPUT"===a.tagName||"TEXTAREA"===a.tagName||"SELECT"===a.tagName))return;let i=nM[e.code];if((e.metaKey||e.ctrlKey)&&e.altKey&&void 0!==i){e.preventDefault(),t(e=>{var t,n;if(null===e||0===e.length)return e;let l=nN(e);if(null===l)return e;let a=(n=null!=(t=l.zoom)?t:1,"0"===i?1:"-"===i||"_"===i?nk(n-.1):nk(n+.1));return e.map(e=>e.id===l.id?{...e,zoom:a}:e);});return;}if(!/^Arrow/.test(e.key))return;let s=e.metaKey||e.ctrlKey,o=e.altKey;if(!s&&!o)return;e.preventDefault();let c=n();null!==c&&(r={key:e.key,shift:e.shiftKey},t(e=>{let t,n,l,a,i,s,d;if(null===e||0===e.length)return e;let u=nN(e);if(null===u)return e;let p=o?(t=r.shift?1:16,n=u.w,l=u.h,"ArrowRight"===r.key?n+=t:"ArrowLeft"===r.key?n-=t:"ArrowDown"===r.key?l+=t:"ArrowUp"===r.key&&(l-=t),n=Math.max((a=ed[u.type].min).w,Math.min(c.width,n)),l=Math.max(a.h,Math.min(c.height,l)),{x:u.x,y:u.y,w:n,h:l}):(i=r.shift?1:16,s=u.x,d=u.y,"ArrowRight"===r.key?s+=i:"ArrowLeft"===r.key?s-=i:"ArrowDown"===r.key?d+=i:"ArrowUp"===r.key&&(d-=i),{x:s=Math.max(-(u.w-120),Math.min(c.width-120,s)),y:d=Math.max(0,Math.min(c.height-38,d)),w:u.w,h:u.h});return e.map(e=>e.id===u.id?{...e,...p,max:!1}:e);}));};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e);};},[t,n,l]);}({setWins:l,rect:B,cancelConnectRef:D}),function(e){let{wsRef:t,viewRef:n,setWins:l}=e;(0,i.useEffect)(()=>{let e=t.current;if(null===e||"u"<typeof ResizeObserver)return;let a=new ResizeObserver(()=>{let t=e.getBoundingClientRect(),a=n.current,r={x:-a.x/a.zoom,y:-a.y/a.zoom,w:t.width/a.zoom,h:t.height/a.zoom};l(e=>null===e?e:e.map(e=>function(e,t){if(e.max)return{...e,x:t.x,y:t.y,w:t.w,h:t.h};if(t.w<520||t.h<420){let n=t.x+8,l=t.y+8;return n===e.x&&l===e.y?e:{...e,x:n,y:l};}let n=Math.max(t.x-(e.w-120),Math.min(t.x+t.w-120,e.x)),l=Math.max(t.y,Math.min(t.y+t.h-38,e.y));return n===e.x&&l===e.y?e:{...e,x:n,y:l};}(e,r)));});return a.observe(e),()=>{a.disconnect();};},[t,n,l]);}({wsRef:e,viewRef:M,setWins:l});let W=(0,i.useMemo)(()=>{var e,t,n,a,r,i,s,o;return{update:(t=(e={setWins:l,zc:x,worldVP:P,winsRef:N}).setWins,(e,n)=>t(t=>{if(null===t)return t;let l=!1,a=t.map(t=>{if(t.id!==e)return t;for(let[e,a]of Object.entries(n))if(t[e]!==a)return l=!0,{...t,...n};return t;});return l?a:t;})),focus:(n=e.setWins,a=e.zc,e=>n(t=>{if(null===t)return t;let n=t.find(t=>t.id===e);if(void 0===n)return t;let l=t.reduce((e,t)=>Math.max(e,t.z),-1/0);return!0!==n.minimized&&n.z>=l?t:(a.current=Math.max(a.current+1,l+1),t.map(t=>t.id===e?{...t,z:a.current}:t));})),close:(r=e.setWins,e=>r(t=>null!==t&&t.some(t=>t.id===e)?t.filter(t=>t.id!==e):t)),minimize:(i=e.setWins,e=>i(t=>{if(null===t)return t;let n=!1,l=t.map(t=>t.id!==e||!0===t.minimized?t:(n=!0,{...t,minimized:!0}));return n?l:t;})),restore:(s=e.setWins,o=e.zc,e=>s(t=>{if(null===t)return t;let n=t.find(t=>t.id===e);if(void 0===n)return t;let l=t.reduce((e,t)=>Math.max(e,t.z),-1/0);return!0!==n.minimized&&n.z>=l?t:(o.current=Math.max(o.current+1,l+1),t.map(t=>t.id===e?{...t,minimized:!1,z:o.current}:t));})),maximize:function(e){let{setWins:t,zc:n,worldVP:l}=e;return e=>t(t=>{if(null===t)return t;let a=l();return null===a?t:t.map(t=>{if(t.id!==e)return t;if(t.max){var l,r;let e,i,s,o=null!=(l=t.prev)?l:(r=t.type,i=Math.min((e=ed[r]).w,Math.max(e.min.w,a.w-32)),s=Math.min(e.h,Math.max(e.min.h,a.h-32)),{x:a.x+Math.max(16,Math.round((a.w-i)/2)),y:a.y+Math.max(16,Math.round((a.h-s)/2)),w:i,h:s}),{prev:c,...d}=t;return{...d,x:o.x,y:o.y,w:o.w,h:o.h,max:!1,z:++n.current};}return{...t,max:!0,prev:{x:t.x,y:t.y,w:t.w,h:t.h},x:a.x,y:a.y,w:a.w,h:a.h,z:++n.current};});});}(e),add:function(e){let{setWins:t,zc:n,worldVP:l}=e;return(e,a)=>{let r=ed[e],i="figma"===e&&"string"==typeof(null==a?void 0:a.selectedScreenIdsJson)&&a.selectedScreenIdsJson.length>0,s=i?360:r.w,o=i?360:r.h,c=i?Math.max(r.min.w,300):r.min.w,d=i?Math.max(r.min.h,260):r.min.h,u=null;return t(t=>{let i=l();if(null===i)return t;let p=null!=t?t:[];if(!0===r.singleton){let t=p.find(t=>t.type===e);if(void 0!==t)return u=t.id,p.map(e=>e.id===t.id?{...e,cfg:void 0===a?e.cfg:{...e.cfg,...a},minimized:!1,z:++n.current}:e);}let m="qiRun"===e?null==a?void 0:a.runId:void 0;if("string"==typeof m&&m.length>0){let e=p.find(e=>"qiRun"===e.type&&e.cfg.runId===m);if(void 0!==e)return u=e.id,p.map(t=>t.id===e.id?{...t,cfg:void 0===a?t.cfg:{...t.cfg,...a},minimized:!1,z:++n.current}:t);}let h="chat"===e?null==a?void 0:a.chatId:void 0;if("string"==typeof h&&h.length>0){let e=p.find(e=>"chat"===e.type&&e.cfg.chatId===h);if(void 0!==e)return u=e.id,p.map(t=>t.id===e.id?{...t,minimized:!1,z:++n.current}:t);}let{x:f,y:g}=t5(i,s,o,p.length,40),v=!0===r.singleton?e:`${e}-${Date.now().toString(36)}`;return u=v,[...p,{id:v,type:e,x:f,y:g,w:Math.max(s,c),h:Math.max(o,d),z:++n.current,cfg:null!=a?a:{},max:!1,zoom:1}];}),u;};}(e),openEditorFile:function(e){let{setWins:t,zc:n,worldVP:l,winsRef:a}=e;return e=>{var r;let{root:i,path:s,lineStart:o,lineEnd:c}=e,d=t8(i);if(0===d.length)return{ok:!1,message:"Select a repository source before opening file references."};let u=t9(d,s);if(0===u.length)return{ok:!1,message:"This repository reference is not a valid file path."};let p=l();if(null===p)return{ok:!1,message:"Unable to open editor because the workspace viewport is not ready."};let m=function(e,t){if(void 0===e)return{};let n=Math.max(1,Math.floor(e)),l=Math.max(n,Math.floor(null!=t?t:n));return{revealLineStart:n,revealLineEnd:l,revealRequestId:`${Date.now().toString(36)}:${n.toString()}:${l.toString()}`};}(o,c),h=null!=(r=null==a?void 0:a.current)?r:[],f=h.find(e=>"editor"===e.type&&t8("string"==typeof e.cfg.root?e.cfg.root:"")===d);if(void 0!==f){let e=f.id;return t(t=>null===t?t:t.map(t=>{var l,a;let r,i;if(t.id!==e)return t;let s=(l=t.cfg,i=t3(r=tW({root:d,file:t9(d,null!=(a=t7(l,"file"))?a:""),openFiles:function(e,t,n){let l=[],a=e=>{let n=t9(t,e);0===n.length||l.includes(n)||l.push(n);};if(Array.isArray(e.openFiles))for(let t of e.openFiles)a(t);return a(e.file),a(n),l;}(l,d,u),layoutJson:t7(l,"layoutJson"),defaultSidebarWidth:260,minSidebarWidth:180,maxSidebarWidth:440}),{type:"open-file",paneId:tH(r).id,file:u}),{file:u,openFiles:t6(i),layoutJson:tK(i)});return{...t,minimized:!1,z:++n.current,cfg:{...t.cfg,root:d,...s,...m}};})),{ok:!0,windowId:e};}let g=ed.editor,{x:v,y:b}=t5(p,g.w,g.h,h.length,40),y=`editor-${Date.now().toString(36)}`;return t(e=>[...(null!=e?e:[]),{id:y,type:"editor",x:v,y:b,w:Math.max(g.w,g.min.w),h:Math.max(g.h,g.min.h),z:++n.current,cfg:{root:d,file:u,openFiles:[u],layoutJson:tK(tW({root:d,file:u,openFiles:[u],defaultSidebarWidth:260,minSidebarWidth:180,maxSidebarWidth:440})),...m},max:!1,zoom:1}]),{ok:!0,windowId:y};};}(e),toggleTool:function(e){let{setWins:t,zc:n,worldVP:l}=e;return e=>{let a=ed[e];t(t=>{let r=l();if(null===r)return t;let i=null!=t?t:[],s=i.find(t=>t.type===e);if(void 0!==s&&!0===s.minimized)return i.map(e=>e.id===s.id?{...e,minimized:!1,z:++n.current}:e);if(void 0!==s)return i.filter(t=>t.type!==e);let{x:o,y:c}=t5(r,a.w,a.h,i.length,28);return[...i,{id:e,type:e,x:o,y:c,w:a.w,h:a.h,z:++n.current,cfg:{},max:!1,zoom:1}];});};}(e)};},[l,x,P,N]),K=(0,i.useMemo)(()=>{var e;return{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 l=e.length,a=Math.ceil(Math.sqrt(l)),r=Math.ceil(l/a),i=(t.w-12*(a+1))/a,s=(t.h-12*(r+1))/r;return e.map((e,n)=>{let l=Math.floor(n/a);return{...ne(e),max:!1,minimized:!1,x:t.x+12+n%a*(i+12),y:t.y+12+l*(s+12),w:i,h:s};});});}(e={setWins:l,worldVP:P}),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 l=[...e].filter(e=>!0!==e.minimized).sort((e,t)=>t.z-e.z).slice(0,2).map(e=>e.id);return e.map(e=>{let n=l.indexOf(e.id);return 0===n?{...ne(e),max:!1,minimized:!1,x:t.x,y:t.y,w:t.w/2,h:t.h}:1===n?{...ne(e),max:!1,minimized:!1,x:t.x+t.w/2,y:t.y,w:t.w/2,h:t.h}:e;});});}(e),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)=>({...ne(e),max:!1,minimized:!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}));});}(e)};},[l,P]),U=(0,i.useMemo)(()=>function(e){let{setSnapPrev:t,snapZone:n,worldVP:l,update:a}=e;return{setSnap:e=>{if(n.current=e,null===e)return void t(null);let a=l();null!==a&&t(eh(a)[e]);},commitSnap:e=>{let r=n.current;if(n.current=null,t(null),null===r)return;let i=l();if(null===i)return;let s={...eh(i)[r],max:"maxi"===r};"maxi"===r&&(s.prev={x:i.x+40,y:i.y+40,w:480,h:360}),a(e,s);}};}({setSnapPrev:r,snapZone:w,worldVP:P,update:W.update}),[r,w,P,W]),V=(0,i.useMemo)(()=>function(e){let{wsRef:t,viewRef:n,winsRef:l,connsRef:a,winsByIdRef:r,connsByIdRef:i,connsByEndpointRef:s,connectingRef:o,connectCleanupRef:c,focus:d,setConns:u,setConnecting:p,onScopeBind:m,onScopeUnbind:h,onConnectorBind:f,onConnectorUnbind:g}=e,v=e=>{var t;return null!=(t=null==r?void 0:r.current.get(e))?t:l.current.find(t=>t.id===e);},b=e=>{var t;return null!=(t=null==s?void 0:s.current.get(e))?t:a.current.filter(t=>t.a===e||t.b===e);},y=()=>{null!==c.current&&(c.current(),c.current=null),o.current=null,p(null);},x=e=>{if("files"!==e.type)return null;let t=e.cfg.resolvedRoot,n=e.cfg.root,l="string"==typeof t&&t.length>0?t:"string"==typeof n&&n.length>0?n:null;if(null===l||!nl(l))return null;let a=e.cfg.activeFilePath;return{id:e.id,root:l,...("string"==typeof a&&a.length>0?{activeFilePath:a}:{})};},w=e=>{let t=[];for(let n of b(e)){let l=n.a===e?n.b:n.b===e?n.a:null;if(null===l)continue;let a=v(l);void 0!==a&&"files"===a.type&&t.push(a);}if(0===t.length)return null;let n=[...t].sort((e,t)=>t.z-e.z),l=n.find(e=>{let t=e.cfg.activeFilePath;return"string"==typeof t&&t.length>0;}),a=null!=l?l:n[0];return void 0===a?null:x(a);},j=(e,t)=>{let n=new Set(),l=[];for(let a of b(e)){if(l.length>=16)break;let r=a.a===e?a.b:a.b===e?a.a:null;if(null===r)continue;let i=v(r);if(void 0===i||"connector"!==i.type||i.cfg.selectedKind!==t)continue;let s=i.cfg.selectedId;"string"==typeof s&&0!==s.trim().length&&(n.has(s)||(n.add(s),l.push(s)));}return l;},k=e=>{let t=(e=>{if("string"!=typeof e||0===e.trim().length)return[];try{let t=JSON.parse(e);if(!Array.isArray(t))return[];let n=t.filter(e=>"string"==typeof e&&""!==e.trim()).map(e=>e.trim());return[...new Set(n)].sort();}catch{return[];}})(e.cfg.selectedScreenIdsJson);if(t.length>0)return t;let n=e.cfg.screenId;return"string"==typeof n&&n.trim().length>0?[n.trim()]:[];};return{startConnect:(e,l)=>{if(l.preventDefault(),l.stopPropagation(),null!==o.current&&o.current.from===e)return void y();let a=t.current;if(null===a)return;let r=a.getBoundingClientRect(),i=n.current,s=e=>(e-r.left-i.x)/i.zoom,d=e=>(e-r.top-i.y)/i.zoom;null!==c.current&&(c.current(),c.current=null);let u={from:e,x:s(l.clientX),y:d(l.clientY)};o.current=u,p(u);let m=t=>{let n={from:e,x:s(t.clientX),y:d(t.clientY)};o.current=n,p(n);};window.addEventListener("pointermove",m),c.current=()=>{window.removeEventListener("pointermove",m);};},confirmConnect:(e,t)=>{t.preventDefault(),t.stopPropagation();let n=o.current;if(null===n)return;let l=v(n.from),a=v(e);if(void 0!==l&&void 0!==a&&ep(l.type,a.type)){let t,s=no(l,a,Date.now()),o=null===s?ng(l,a):null,c=null!==s||null!==o?nn(l,a):null;try{var r,i;t=null!==s&&null!==c?null==(r=null==m?void 0:m(c,s))||r:null===o||null!==c&&(null==(i=null==f?void 0:f(c,o))||i);}catch{t=!1;}Promise.resolve(t).then(t=>{t&&void 0!==v(n.from)&&void 0!==v(e)&&(u(t=>nt(t,n.from,e)?t:[...t,{id:`${n.from}~${e}`,a:n.from,b:e,...(null!==c?{boundChatWindowId:c}:{}),...(null!==s?{boundRoot:s.root,boundScopeKind:s.kind,boundRelativePath:s.relativePaths[0]}:{}),...(null!==o?"capsule"===o.kind?{boundConnectorKind:"capsule",boundConnectorId:o.capsuleId}:{boundConnectorKind:"capsule-set",boundConnectorId:o.capsuleSetId}:{})}]),d(e));}).catch(()=>void 0);}y();},cancelConnect:y,removeConn:e=>{var t,n,l,r;let s=null!=(r=null==i?void 0:i.current.get(e))?r:a.current.find(t=>t.id===e);if(u(t=>t.filter(t=>t.id!==e)),void 0===s)return;let o=v(s.a),c=v(s.b),d=void 0!==o&&void 0!==c,p=null!=(t=s.boundChatWindowId)?t:d?nn(o,c):null,m=null!=(n=nc(s))?n:d?no(o,c,Date.now()):null;null!==m&&null!==p&&(null==h||h(p,m));let f=null!=(l=nf(s))?l:d?ng(o,c):null;null!==f&&null!==p&&(null==g||g(p,f));},connect:(e,t)=>{let n=v(e),l=v(t);void 0!==n&&void 0!==l&&ep(n.type,l.type)&&u(n=>nt(n,e,t)?n:[...n,{id:`${e}~${t}`,a:e,b:t}]);},linkedFilesRoot:e=>{var t,n;return null!=(t=null==(n=w(e))?void 0:n.root)?t:null;},linkedFilesContext:w,linkedAllFilesRoots:e=>{let t=new Set(),n=[];for(let l of b(e)){if(n.length>=16)break;let a=l.a===e?l.b:l.b===e?l.a:null;if(null===a)continue;let r=v(a);if(void 0===r)continue;let i=nr(r);null===i||t.has(i)||(t.add(i),n.push(i));}return n;},linkedConnectorCapsuleIds:e=>j(e,"capsule"),linkedConnectorCapsuleSetIds:e=>j(e,"capsule-set"),linkedFigmaSnapshotRunIds:e=>{let t=new Set(),n=[];for(let l of b(e)){if(n.length>=16)break;let a=l.a===e?l.b:l.b===e?l.a:null;if(null===a)continue;let r=v(a);if(void 0===r||"figma"!==r.type)continue;let i=r.cfg.snapshotRunId;"string"==typeof i&&0!==i.trim().length&&(t.has(i)||(t.add(i),n.push(i)));}return n;},linkedFigmaSnapshotSources:e=>{let t=new Set(),n=[];for(let l of b(e)){if(n.length>=16)break;let a=l.a===e?l.b:l.b===e?l.a:null;if(null===a)continue;let r=v(a);if(void 0===r||"figma"!==r.type&&"figmaView"!==r.type&&"figmaJson"!==r.type)continue;let i=r.cfg.snapshotRunId;if("string"!=typeof i||0===i.trim().length)continue;let s=r.cfg.selectedScreenIdsJson,o=r.cfg.selectedScreenName,c=k(r);if(("figmaJson"===r.type||"figmaView"===r.type||void 0!==s||"string"==typeof o&&o.trim().length>0)&&0===c.length)continue;let d=`${i}:${c.join(",")||"*"}`;if(t.has(d))continue;t.add(d);let u=c.length>0&&"string"==typeof o&&o.trim().length>0?"figmaJson"===r.type?`JSON \xb7 ${o}`:o:i;n.push({kind:"figma-snapshot",label:u,snapshotRunId:i,...(c.length>0?{screenIds:c}:{})});}return n;},linkedImageSources:e=>{let t=new Set(),n=[];for(let l of b(e)){if(n.length>=16)break;let a=l.a===e?l.b:l.b===e?l.a:null;if(null===a)continue;let r=v(a);if(void 0===r||"figmaImage"!==r.type)continue;let i=r.cfg.snapshotRunId,s=r.cfg.screenId;if("string"!=typeof i||0===i.trim().length||"string"!=typeof s||0===s.trim().length)continue;let o=`${i}:${s}`;if(t.has(o))continue;t.add(o);let c=r.cfg.selectedScreenName,d="string"==typeof c&&c.trim().length>0?`Image \xb7 ${c}`:`Image \xb7 ${s}`;n.push({kind:"image",label:d,sourceKind:"figma-snapshot-screen",snapshotRunId:i,screenId:s});}return n;},currentFilesContext:()=>{let e=null,t=0,n=null;for(let a of l.current){if("files"!==a.type)continue;let l=x(a);null!==l&&(t+=1,e=l),(null===n||a.z>n.z)&&(n=a);}return 1===t?e:null===n?null:x(n);}};}({wsRef:e,viewRef:M,winsRef:N,connsRef:S,winsByIdRef:E,connsByIdRef:$,connsByEndpointRef:A,connectingRef:T,connectCleanupRef:F,focus:W.focus,setConns:d,setConnecting:p,onScopeBind:g,onScopeUnbind:v,onConnectorBind:b,onConnectorUnbind:y}),[e,M,N,S,E,$,A,T,F,W,d,p,g,v,b,y]);D.current=V.cancelConnect;let H=(0,i.useCallback)(e=>{let t=E.current.get(e);if(void 0!==t){var n,l,a,r;for(let i of null!=(n=A.current.get(e))?n:[]){let n=i.a===e?i.b:i.b===e?i.a:null;if(null===n)continue;let s=E.current.get(n);if(void 0===s)continue;let o=null!=(l=i.boundChatWindowId)?l:"chat"===t.type?t.id:"chat"===s.type?s.id:null,c=null!=(a=nc(i))?a:no(t,s,Date.now());null!==c&&null!==o&&(null==v||v(o,c));let d=null!=(r=nf(i))?r:ng(t,s);null!==d&&null!==o&&(null==y||y(o,d));}}W.close(e);},[E,A,W,v,y]),_=(0,i.useCallback)((e,t)=>{d(n=>n.map(n=>n.id===e?{...n,boundScopeKind:t.kind,...(void 0!==t.root?{boundRoot:t.root}:{}),...(void 0!==t.relativePaths[0]?{boundRelativePath:t.relativePaths[0]}:{})}:n));},[d]),G=(0,i.useCallback)(()=>M.current,[M]);(0,i.useEffect)(()=>()=>{null!==F.current&&(F.current(),F.current=null);},[]);let J=(0,i.useMemo)(()=>({add:W.add,openEditorFile:W.openEditorFile,toggleTool:W.toggleTool,focus:W.focus,close:H,minimize:W.minimize,restore:W.restore,maximize:W.maximize,update:W.update,setSnap:U.setSnap,commitSnap:U.commitSnap,tileAll:K.tileAll,splitFront:K.splitFront,cascade:K.cascade,startConnect:V.startConnect,confirmConnect:V.confirmConnect,cancelConnect:V.cancelConnect,removeConn:V.removeConn,updateConnBoundScope:_,connect:V.connect,linkedFilesRoot:V.linkedFilesRoot,linkedFilesContext:V.linkedFilesContext,linkedAllFilesRoots:V.linkedAllFilesRoots,linkedConnectorCapsuleIds:V.linkedConnectorCapsuleIds,linkedConnectorCapsuleSetIds:V.linkedConnectorCapsuleSetIds,linkedFigmaSnapshotRunIds:V.linkedFigmaSnapshotRunIds,linkedFigmaSnapshotSources:V.linkedFigmaSnapshotSources,linkedImageSources:V.linkedImageSources,currentFilesContext:V.currentFilesContext,zoomTo:L,fitView:q,resetView:z,panBy:O,rect:B,currentView:G}),[W,U,K,V,H,_,G,L,q,z,O,B]);return{wins:n,snapPrev:a,palOpen:s,setPalOpen:o,conns:c,connecting:u,view:m,api:J};}(M,{cameraSmoothness:ee,onScopeBind:G,onScopeUnbind:X,onConnectorBind:Z,onConnectorUnbind:Q});P.current=en.wins,(0,i.useEffect)(()=>{if(null!==en.wins)for(let t of en.conns){var e;let n=en.wins.find(e=>e.id===t.a),l=en.wins.find(e=>e.id===t.b);if(void 0===n||void 0===l)continue;let a=null!=(e=t.boundChatWindowId)?e:"chat"===n.type?n.id:"chat"===l.type?l.id:null;if(null===a)continue;let r=no(n,l,Date.now());if(null===r)continue;let i=nc(t);gA(i)!==gA(r)&&_(a,r,i).then(e=>{e&&en.api.updateConnBoundScope(t.id,r);});}},[_,en.api,en.conns,en.wins]);let[el,er]=(0,i.useState)(!1),[ei,es]=(0,i.useState)(null),[eo,ec]=(0,i.useState)(!1),[eu,em]=(0,i.useState)(!1),ef=null!=(e=null==(l=en.wins)?void 0:l.length)?e:0,eb=function(e){if(null===e||0===e.length)return null;let t=null;for(let n=0;n<e.length;n++){let l=e[n];if(!0!==l.minimized){if(null===t){t=l;continue;}l.z>t.z&&(t=l);}}return t;}(en.wins),ey=(0,i.useMemo)(()=>function(e){if(null===e)return new Set();let t=new Set();for(let n of e)!0===ed[n.type].tool&&t.add(n.type);return t;}(en.wins),[en.wins]),ej=(0,i.useMemo)(()=>{var e;return{wins:null!=(e=en.wins)?e:[],active:eb,winCount:ef};},[en.wins,eb,ef]),ek=(0,i.useCallback)(()=>er(!0),[]),eN=(0,i.useCallback)(()=>er(!1),[]),eS=(0,i.useCallback)(()=>em(e=>!e),[]),eC=(0,i.useCallback)(()=>em(!1),[]),eR=(0,i.useCallback)(e=>{en.api.restore(e),em(!1);},[en.api]),eI=(0,i.useCallback)(e=>{if(er(!1),"connector"===e){let t=en.api.add(e);null!==t&&gM(t);return;}es(e);},[en.api]),eE=(0,i.useCallback)(e=>{if(es(null),null===ei)return;let{__connectFilesId:t,...n}="editor"===ei?function(e){let t="string"==typeof e.root?e.root.trim():"",n="string"==typeof e.file?e.file.trim():"";if(0===t.length)return e;let l=gT(t,n),a={...e,root:t},r=function(e,t,n){let l=[],a=t=>{let n=gT(e,t);null===n||0===n.length||l.includes(n)||l.push(n);};if(Array.isArray(t))for(let e of t)"string"==typeof e&&a(e);return n.length>0&&a(n),l;}(t,e.openFiles,null!=l?l:"");return null!==l&&l.length>0?a.file=l:delete a.file,r.length>0?a.openFiles=r:delete a.openFiles,a;}(e):e,l=en.api.add(ei,n);"agents"===ei&&null!==l&&"string"==typeof t&&t.length>0&&en.api.connect(l,t),null!==l&&gM(l);},[ei,en.api]),e$=(0,i.useCallback)(()=>es(null),[]),eA=(0,i.useCallback)(()=>ec(!1),[]),eT=(0,i.useCallback)(()=>ec(!0),[]),eF=(0,i.useRef)(null),eD=(0,i.useCallback)(e=>{eF.current=e;},[]),eM=function(e){var t;let{apply:n}=e,l=null!=(t=e.limit)?t:100,[a,r]=(0,i.useState)(aH),s=(0,i.useRef)(n);s.current=n;let o=(0,i.useRef)(a);o.current=a;let c=(0,i.useCallback)(e=>{r(t=>{let n=[...t.undoStack,e];return{undoStack:n.length>l?n.slice(n.length-l):n,redoStack:[]};});},[l]),d=(0,i.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);r({undoStack:e.undoStack.slice(0,-1),redoStack:[...e.redoStack,t]}),s.current(n);},[]),u=(0,i.useCallback)(()=>{let e=o.current;if(0===e.redoStack.length)return;let t=e.redoStack[e.redoStack.length-1];r({undoStack:[...e.undoStack,t],redoStack:e.redoStack.slice(0,-1)}),s.current(t);},[]),p=(0,i.useCallback)(()=>{r(aH);},[]);return(0,i.useMemo)(()=>{let e=a.undoStack[a.undoStack.length-1],t=a.redoStack[a.redoStack.length-1];return{canUndo:a.undoStack.length>0,canRedo:a.redoStack.length>0,undoLabel:void 0!==e?aU(e):null,redoLabel:void 0!==t?aU(t):null,push:c,undo:d,redo:u,clear:p};},[a,c,d,u,p]);}({apply:(0,i.useCallback)(e=>{var t;return t=en.api,void("ui.panel.toggle"===e.kind&&e.panel in ed&&t.toggleTool(e.panel));},[en.api])}),eP=(0,i.useCallback)(e=>{if(!(e in ed))return;let t=ey.has(e);en.api.toggleTool(e),eM.push({kind:"ui.panel.toggle",panel:e,before:t,after:!t});},[en.api,ey,eM]),eL=(0,i.useCallback)(()=>eI("chat"),[eI]),eq=(0,i.useRef)(!1);(0,i.useEffect)(()=>{if(eq.current||null===en.wins)return;eq.current=!0;let e=window.location.pathname.replace(/\/+$/u,""),t="/relationships"===e?"relationships":"/local-knowledge"===e?"localKnowledge":null;null!==t&&(en.wins.some(e=>e.type===t)||eP(t),window.history.replaceState(null,"","/"));},[en.wins,eP]),function(e){var t;let{bindings:n,dispatch:l}=e,a=null!=(t=e.platform)?t:function(){if("u"<typeof navigator)return"other";let e=navigator.platform||"";return /Mac|iPhone|iPad|iPod/i.test(e)?"mac":"other";}(),r=(0,i.useRef)(l);r.current=l;let s=(0,i.useMemo)(()=>function(e){let t=new Map();for(let n of e){let e=aV(n.chord),l=t.get(e);void 0!==l?l.push(n.commandId):t.set(e,[n.commandId]);}let n=[];for(let[,l]of t)if(l.length>1){let t=e.find(e=>l.includes(e.commandId));void 0!==t&&n.push({chord:t.chord,commandIds:l});}return n;}(n),[n]),o=(0,i.useMemo)(()=>n.filter(e=>function(e){for(let t of aK)if(aV(e)===aV(t))return!0;return!1;}(e.chord)),[n]);if(s.length>0)throw new a_(s);if(o.length>0)throw new aG(o);(0,i.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()||t.mod.includes("alt")&&/^[a-z]$/i.test(t.key)&&e.code===`Key${t.key.toUpperCase()}`))return!1;let l=function(e,t){let n=new Set();for(let l of e)"cmd"===l?n.add("mac"===t?"meta":"ctrl"):"ctrl"===l?n.add("ctrl"):"alt"===l?n.add("alt"):"shift"===l&&n.add("shift");return n;}(t.mod,n);return e.metaKey===l.has("meta")&&e.ctrlKey===l.has("ctrl")&&e.altKey===l.has("alt")&&e.shiftKey===l.has("shift");}(e,t.chord,a)){e.preventDefault(),r.current(t.commandId);return;}}}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e);},[n,a]),(0,i.useMemo)(()=>({bindings:n,conflicts:s,reserved:o}),[n,s,o]);}({bindings:aJ,dispatch:(0,i.useCallback)(e=>{var t;"undo"===e?eM.undo():"redo"===e?eM.redo():"focus-status"===e&&(null==(t=eF.current)||t.focus());},[eM])}),(0,i.useEffect)(()=>{let e=document.documentElement,t=()=>{e.setAttribute("data-input-modality","pointer");},n=t=>{t.metaKey||t.ctrlKey||t.altKey||"Tab"===t.key&&e.setAttribute("data-input-modality","keyboard");};return e.setAttribute("data-input-modality","pointer"),window.addEventListener("pointerdown",t,!0),window.addEventListener("mousedown",t,!0),window.addEventListener("keydown",n,!0),()=>{window.removeEventListener("pointerdown",t,!0),window.removeEventListener("mousedown",t,!0),window.removeEventListener("keydown",n,!0),e.removeAttribute("data-input-modality");};},[]);let ez=(0,i.useMemo)(()=>function(e,t,n,l,a,r){let i=[];for(let e of gF){let t=ed[e];i.push({id:`new-${e}`,label:`New ${t.title}`,group:"Create",icon:t.icon,run:()=>n(e)});}for(let e of gD){let n=ed[e];i.push({id:`open-${e}`,label:`Open ${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"===l?"moon":"sun",run:a}),i.push({id:"undo",label:null!==r.undoLabel?`Undo: ${r.undoLabel}`:"Undo (window and panel changes only)",group:"Edit",icon:"back",shortcut:"⌘Z",run:r.undo}),i.push({id:"redo",label:null!==r.redoLabel?`Redo: ${r.redoLabel}`:"Redo (window and panel changes only)",group:"Edit",icon:"fwd",shortcut:"⇧⌘Z",run:r.redo}),i;}(en.api,eP,eI,$,A,eM),[en.api,eP,eI,$,A,eM]),eO=!F.loading&&void 0===F.error&&0===F.models.length,eB=(d=null==(a=F.activeProject)?void 0:a.name,F.loading?"Loading project…":void 0!==d&&d.trim().length>0?d:"No project selected"),eW=void 0!==F.activeProject,eK=(null==(s=F.activeProject)?void 0:s.available)===!0,eU=(u={loading:F.loading,error:F.error,hasProject:eW,projectAvailable:eK,noEligibleModels:F.noEligibleModels}).loading?"Loading shell…":void 0!==u.error?"Shell error":u.hasProject?u.projectAvailable?u.noEligibleModels?"Gateway setup required":"Ready":"Project unavailable":"No project selected",eH=0===(g=(null!=(h=en.wins)?h:[]).filter(e=>"review"===e.type)).length?"No review open":g.some(e=>"string"==typeof e.cfg.runId&&e.cfg.runId.length>0)?"Evidence ready":"Review window open",e_=void 0!==(f=null==(c=F.activeChat)?void 0:c.branchLabel)&&f.trim().length>0?f:"No branch selected",eG=el?(0,r.jsx)(lv,{types:ed,order:gF,onAdd:eI,onClose:eN}):null;return(0,r.jsx)(p,{value:D,children:(0,r.jsx)(o,{value:F,children:(0,r.jsx)(Y.Provider,{value:ej,children:(0,r.jsxs)("div",{className:"app",children:[(0,r.jsx)("a",{className:"skip-link",href:"#main",children:v("app.skipToContent")}),(0,r.jsx)("h1",{className:"visually-hidden",children:v("app.workspaceHeading")}),(0,r.jsx)(ev,{openPalette:ek,openCommandPalette:eT,onTileAll:en.api.tileAll,onSplitFront:en.api.splitFront,onCascade:en.api.cascade,contextControl:(0,r.jsx)(L,{})}),(0,r.jsxs)("div",{className:"mid",children:[eO?null:(0,r.jsx)(ex,{openTools:ey,onTool:eP,onNewChat:eL,theme:$,onToggleTheme:A}),(0,r.jsxs)("div",{className:"stage",id:"main",tabIndex:-1,children:[(0,r.jsx)(n5,{ws:en,wsRef:M,openPalette:ek,palette:eG}),null!==W&&(0,r.jsxs)("div",{className:"source-limit-alert",role:"alert",children:[(0,r.jsx)("span",{children:W}),(0,r.jsx)("button",{type:"button",className:"source-limit-alert-dismiss","aria-label":"Dismiss source connection notice",onClick:()=>K(null),children:"\xd7"})]})]}),eO?null:(0,r.jsx)(ew,{openTools:ey,onTool:eP})]}),(0,r.jsx)(eg,{winCount:ef,windows:null!=(t=en.wins)?t:[],windowPaletteOpen:eu,onToggleWindowPalette:eS,onSelectWindow:eR,onCloseWindowPalette:eC,mode:T.mode,selectedModel:F.selectedModel,projectName:eB,branchLabel:e_,shellStatusLabel:eU,evidenceStatusLabel:eH,statusRef:eD}),null!==ei&&(0,r.jsx)(lg,{type:ei,types:ed,filesContext:en.api.currentFilesContext(),onConfirm:eE,onClose:e$}),eo&&(0,r.jsx)(n8,{commands:ez,onClose:eA}),eO?(0,r.jsx)(lt,{}):null,(0,r.jsx)(gC,{})]})})})});}function gL(){let[e,t]=(0,i.useState)(!1);return((0,i.useEffect)(()=>{try{window.sessionStorage.removeItem("keiko.app-boot-recovery-reload-count");}catch{}t(!0);},[]),(0,i.useEffect)(()=>{!function(){if(!("u">typeof navigator&&"serviceWorker"in navigator))return;let e=navigator.serviceWorker;try{e.register("/sw.js",{scope:"/"}).then(t=>{e.addEventListener("controllerchange",gE),null!==e.controller&&g$(t),t.addEventListener("updatefound",()=>{let n;n=t.installing,null!==n&&n.addEventListener("statechange",()=>{"installed"!==n.state||null!==e.controller&&g$(t);});});}).catch(e=>{});}catch{}}();},[]),e)?(0,r.jsx)(el,{children:(0,r.jsx)(G,{children:(0,r.jsx)(gP,{})})}):(0,r.jsx)("div",{className:"app","aria-hidden":"true",children:(0,r.jsx)("div",{className:"app-boot",children:(0,r.jsx)("img",{className:"app-boot-logo",src:"/assets/keiko-logo.svg",alt:""})})});}function gq(){return(0,r.jsx)(gL,{});}},48824:(e,t,n)=>{Promise.resolve().then(n.bind(n,41535));},55176:(e,t,n)=>{"use strict";n.d(t,{o:()=>r});var l=n(54568),a=n(75571);function r(e){let t,{name:n,icon:r}=e,i=null!=r?r:"dockerfile"===(t=n.toLowerCase())||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;return null!==i?(0,l.jsx)("img",{className:"fi-img",src:`/assets/icons/${i}.svg`,width:"15",height:"15",alt:""}):(0,l.jsx)("span",{className:"fi-fallback",children:(0,l.jsx)(a.F.file,{size:14})});}},98803:(e,t,n)=>{"use strict";n.d(t,{YL:()=>u,qP:()=>l,sM:()=>d});let l=1;function a(e){return"object"==typeof e&&null!==e&&!Array.isArray(e);}function r(e){return"string"==typeof e&&e.length>0;}function i(e){return"string"==typeof e&&/^[a-f0-9]{64}$/u.test(e);}function s(e){return"number"==typeof e&&Number.isFinite(e)&&e>=0;}function o(e,t){return null===e||t(e);}function c(e){return a(e)&&s(e.sizeBytes)&&s(e.modifiedAt)&&i(e.contentHash);}function d(e){return!!a(e)&&[e.schemaVersion===l,r(e.workspaceRoot),r(e.relativePath),"string"==typeof e.content,o(e.baseVersion,c),i(e.contentHash),o(e.savedContentHash,i),s(e.updatedAt),r(e.paneId),r(e.windowId)].every(Boolean);}function u(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:6048e5;return e.updatedAt+n<t;}}}]);