@oscharko-dev/keiko 0.2.8 → 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 (722) 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 +33 -0
  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/runtime-capabilities.d.ts +44 -0
  193. package/node_modules/@oscharko-dev/keiko-contracts/dist/runtime-capabilities.d.ts.map +1 -0
  194. package/node_modules/@oscharko-dev/keiko-contracts/dist/runtime-capabilities.js +141 -0
  195. package/node_modules/@oscharko-dev/keiko-contracts/dist/task-workspace.d.ts +302 -0
  196. package/node_modules/@oscharko-dev/keiko-contracts/dist/task-workspace.d.ts.map +1 -0
  197. package/node_modules/@oscharko-dev/keiko-contracts/dist/task-workspace.js +1236 -0
  198. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-action-intent.d.ts +86 -0
  199. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-action-intent.d.ts.map +1 -0
  200. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-action-intent.js +387 -0
  201. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-playback.d.ts +50 -0
  202. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-playback.d.ts.map +1 -0
  203. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-playback.js +240 -0
  204. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-protocol.d.ts +165 -0
  205. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-protocol.d.ts.map +1 -0
  206. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-protocol.js +312 -0
  207. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-transcript.d.ts +57 -0
  208. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-transcript.d.ts.map +1 -0
  209. package/node_modules/@oscharko-dev/keiko-contracts/dist/voice-transcript.js +221 -0
  210. package/node_modules/@oscharko-dev/keiko-contracts/package.json +5 -1
  211. package/node_modules/@oscharko-dev/keiko-evaluations/dist/.tsbuildinfo +1 -1
  212. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/correction.d.ts +5 -0
  213. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/correction.d.ts.map +1 -0
  214. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/correction.js +53 -0
  215. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/index.d.ts +5 -0
  216. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/index.d.ts.map +1 -0
  217. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/index.js +17 -0
  218. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/no-voice.d.ts +6 -0
  219. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/no-voice.d.ts.map +1 -0
  220. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/no-voice.js +79 -0
  221. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/voice.d.ts +5 -0
  222. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/voice.d.ts.map +1 -0
  223. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/fixtures/voice.js +57 -0
  224. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/index.d.ts +6 -0
  225. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/index.d.ts.map +1 -0
  226. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/index.js +9 -0
  227. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/render.d.ts +3 -0
  228. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/render.d.ts.map +1 -0
  229. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/render.js +49 -0
  230. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/runner.d.ts +13 -0
  231. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/runner.d.ts.map +1 -0
  232. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/runner.js +80 -0
  233. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/scorer.d.ts +8 -0
  234. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/scorer.d.ts.map +1 -0
  235. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/scorer.js +225 -0
  236. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/types.d.ts +71 -0
  237. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/types.d.ts.map +1 -0
  238. package/node_modules/@oscharko-dev/keiko-evaluations/dist/discussion/types.js +29 -0
  239. package/node_modules/@oscharko-dev/keiko-evaluations/dist/index.d.ts +2 -0
  240. package/node_modules/@oscharko-dev/keiko-evaluations/dist/index.d.ts.map +1 -1
  241. package/node_modules/@oscharko-dev/keiko-evaluations/dist/index.js +6 -0
  242. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/adversarial.d.ts +9 -0
  243. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/adversarial.d.ts.map +1 -0
  244. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/adversarial.js +163 -0
  245. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/index.d.ts +5 -0
  246. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/index.d.ts.map +1 -0
  247. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/index.js +17 -0
  248. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/no-voice.d.ts +5 -0
  249. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/no-voice.d.ts.map +1 -0
  250. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/no-voice.js +37 -0
  251. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/segment.d.ts +11 -0
  252. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/segment.d.ts.map +1 -0
  253. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/segment.js +25 -0
  254. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/voice.d.ts +6 -0
  255. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/voice.d.ts.map +1 -0
  256. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/fixtures/voice.js +74 -0
  257. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/index.d.ts +6 -0
  258. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/index.d.ts.map +1 -0
  259. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/index.js +10 -0
  260. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/render.d.ts +3 -0
  261. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/render.d.ts.map +1 -0
  262. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/render.js +49 -0
  263. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/runner.d.ts +14 -0
  264. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/runner.d.ts.map +1 -0
  265. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/runner.js +149 -0
  266. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/scorer.d.ts +8 -0
  267. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/scorer.d.ts.map +1 -0
  268. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/scorer.js +247 -0
  269. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/types.d.ts +82 -0
  270. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/types.d.ts.map +1 -0
  271. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-action/types.js +30 -0
  272. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/capability.d.ts +4 -0
  273. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/capability.d.ts.map +1 -0
  274. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/capability.js +26 -0
  275. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/full-realtime.d.ts +3 -0
  276. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/full-realtime.d.ts.map +1 -0
  277. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/full-realtime.js +36 -0
  278. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/index.d.ts +5 -0
  279. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/index.d.ts.map +1 -0
  280. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/index.js +21 -0
  281. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/no-voice.d.ts +3 -0
  282. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/no-voice.d.ts.map +1 -0
  283. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/no-voice.js +33 -0
  284. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/privacy.d.ts +3 -0
  285. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/privacy.d.ts.map +1 -0
  286. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/privacy.js +69 -0
  287. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/speech-output.d.ts +3 -0
  288. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/speech-output.d.ts.map +1 -0
  289. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/speech-output.js +32 -0
  290. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/stt-only.d.ts +3 -0
  291. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/stt-only.d.ts.map +1 -0
  292. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/fixtures/stt-only.js +35 -0
  293. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/index.d.ts +10 -0
  294. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/index.d.ts.map +1 -0
  295. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/index.js +14 -0
  296. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/metrics.d.ts +10 -0
  297. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/metrics.d.ts.map +1 -0
  298. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/metrics.js +142 -0
  299. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/privacy.d.ts +9 -0
  300. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/privacy.d.ts.map +1 -0
  301. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/privacy.js +100 -0
  302. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/profiles.d.ts +15 -0
  303. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/profiles.d.ts.map +1 -0
  304. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/profiles.js +58 -0
  305. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/render.d.ts +3 -0
  306. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/render.d.ts.map +1 -0
  307. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/render.js +53 -0
  308. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/runner.d.ts +13 -0
  309. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/runner.d.ts.map +1 -0
  310. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/runner.js +141 -0
  311. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/scorer.d.ts +8 -0
  312. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/scorer.d.ts.map +1 -0
  313. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/scorer.js +323 -0
  314. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/types.d.ts +149 -0
  315. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/types.d.ts.map +1 -0
  316. package/node_modules/@oscharko-dev/keiko-evaluations/dist/voice-twin/types.js +45 -0
  317. package/node_modules/@oscharko-dev/keiko-evaluations/package.json +9 -9
  318. package/node_modules/@oscharko-dev/keiko-evidence/dist/.tsbuildinfo +1 -1
  319. package/node_modules/@oscharko-dev/keiko-evidence/package.json +4 -4
  320. package/node_modules/@oscharko-dev/keiko-harness/dist/.tsbuildinfo +1 -1
  321. package/node_modules/@oscharko-dev/keiko-harness/package.json +6 -6
  322. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/.tsbuildinfo +1 -1
  323. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/parsers/html-parser.js +2 -2
  324. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/retrieval/scoped-vector-search.js +2 -2
  325. package/node_modules/@oscharko-dev/keiko-local-knowledge/package.json +6 -6
  326. package/node_modules/@oscharko-dev/keiko-memory-capture/package.json +3 -3
  327. package/node_modules/@oscharko-dev/keiko-memory-consolidation/package.json +3 -3
  328. package/node_modules/@oscharko-dev/keiko-memory-governance/package.json +3 -3
  329. package/node_modules/@oscharko-dev/keiko-memory-retrieval/package.json +3 -3
  330. package/node_modules/@oscharko-dev/keiko-memory-vault/dist/.tsbuildinfo +1 -1
  331. package/node_modules/@oscharko-dev/keiko-memory-vault/package.json +3 -3
  332. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/.tsbuildinfo +1 -1
  333. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/capabilities.d.ts +8 -1
  334. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/capabilities.d.ts.map +1 -1
  335. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/capabilities.js +97 -1
  336. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/config.d.ts.map +1 -1
  337. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/config.js +215 -2
  338. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/http.d.ts +1 -0
  339. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/http.d.ts.map +1 -1
  340. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/http.js +51 -5
  341. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/index.d.ts +6 -3
  342. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/index.d.ts.map +1 -1
  343. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/index.js +5 -2
  344. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/model-selection.d.ts +10 -2
  345. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/model-selection.d.ts.map +1 -1
  346. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/model-selection.js +86 -1
  347. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/realtime-voice-adapter.d.ts +49 -0
  348. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/realtime-voice-adapter.d.ts.map +1 -0
  349. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/realtime-voice-adapter.js +306 -0
  350. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/speech-to-text-adapter.d.ts +33 -0
  351. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/speech-to-text-adapter.d.ts.map +1 -0
  352. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/speech-to-text-adapter.js +238 -0
  353. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/text-to-speech-adapter.d.ts +56 -0
  354. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/text-to-speech-adapter.d.ts.map +1 -0
  355. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/text-to-speech-adapter.js +240 -0
  356. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/types.d.ts +13 -3
  357. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/types.d.ts.map +1 -1
  358. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/types.js +1 -1
  359. package/node_modules/@oscharko-dev/keiko-model-gateway/package.json +3 -3
  360. package/node_modules/@oscharko-dev/keiko-quality-intelligence/dist/.tsbuildinfo +1 -1
  361. package/node_modules/@oscharko-dev/keiko-quality-intelligence/package.json +3 -3
  362. package/node_modules/@oscharko-dev/keiko-sandbox/dist/.tsbuildinfo +1 -1
  363. package/node_modules/@oscharko-dev/keiko-sandbox/package.json +2 -2
  364. package/node_modules/@oscharko-dev/keiko-sdk/dist/.tsbuildinfo +1 -1
  365. package/node_modules/@oscharko-dev/keiko-sdk/package.json +9 -9
  366. package/node_modules/@oscharko-dev/keiko-security/dist/.tsbuildinfo +1 -1
  367. package/node_modules/@oscharko-dev/keiko-security/dist/redaction.d.ts.map +1 -1
  368. package/node_modules/@oscharko-dev/keiko-security/dist/redaction.js +12 -0
  369. package/node_modules/@oscharko-dev/keiko-security/package.json +2 -2
  370. package/node_modules/@oscharko-dev/keiko-server/dist/.tsbuildinfo +1 -1
  371. package/node_modules/@oscharko-dev/keiko-server/dist/chat-handlers.d.ts +18 -2
  372. package/node_modules/@oscharko-dev/keiko-server/dist/chat-handlers.d.ts.map +1 -1
  373. package/node_modules/@oscharko-dev/keiko-server/dist/chat-handlers.js +185 -3
  374. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner-errors.d.ts +17 -0
  375. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner-errors.d.ts.map +1 -0
  376. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner-errors.js +37 -0
  377. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner-evidence.d.ts +23 -0
  378. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner-evidence.d.ts.map +1 -0
  379. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner-evidence.js +69 -0
  380. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner-routes.d.ts +7 -0
  381. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner-routes.d.ts.map +1 -0
  382. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner-routes.js +175 -0
  383. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner.d.ts +29 -0
  384. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner.d.ts.map +1 -0
  385. package/node_modules/@oscharko-dev/keiko-server/dist/command-runner.js +348 -0
  386. package/node_modules/@oscharko-dev/keiko-server/dist/conversation-prompt.d.ts +2 -2
  387. package/node_modules/@oscharko-dev/keiko-server/dist/conversation-prompt.d.ts.map +1 -1
  388. package/node_modules/@oscharko-dev/keiko-server/dist/conversation-prompt.js +17 -1
  389. package/node_modules/@oscharko-dev/keiko-server/dist/csp.d.ts.map +1 -1
  390. package/node_modules/@oscharko-dev/keiko-server/dist/csp.js +3 -0
  391. package/node_modules/@oscharko-dev/keiko-server/dist/deps.d.ts +27 -1
  392. package/node_modules/@oscharko-dev/keiko-server/dist/deps.d.ts.map +1 -1
  393. package/node_modules/@oscharko-dev/keiko-server/dist/deps.js +288 -13
  394. package/node_modules/@oscharko-dev/keiko-server/dist/discussion-prompt.d.ts +4 -0
  395. package/node_modules/@oscharko-dev/keiko-server/dist/discussion-prompt.d.ts.map +1 -0
  396. package/node_modules/@oscharko-dev/keiko-server/dist/discussion-prompt.js +19 -0
  397. package/node_modules/@oscharko-dev/keiko-server/dist/editor/agentActionAudit.d.ts +18 -0
  398. package/node_modules/@oscharko-dev/keiko-server/dist/editor/agentActionAudit.d.ts.map +1 -0
  399. package/node_modules/@oscharko-dev/keiko-server/dist/editor/agentActionAudit.js +80 -0
  400. package/node_modules/@oscharko-dev/keiko-server/dist/editor/agentRoutes.d.ts +1 -0
  401. package/node_modules/@oscharko-dev/keiko-server/dist/editor/agentRoutes.d.ts.map +1 -1
  402. package/node_modules/@oscharko-dev/keiko-server/dist/editor/agentRoutes.js +292 -55
  403. package/node_modules/@oscharko-dev/keiko-server/dist/editor/agentSessionRegistry.d.ts +35 -0
  404. package/node_modules/@oscharko-dev/keiko-server/dist/editor/agentSessionRegistry.d.ts.map +1 -0
  405. package/node_modules/@oscharko-dev/keiko-server/dist/editor/agentSessionRegistry.js +243 -0
  406. package/node_modules/@oscharko-dev/keiko-server/dist/editor/completionRoutes.d.ts.map +1 -1
  407. package/node_modules/@oscharko-dev/keiko-server/dist/editor/completionRoutes.js +5 -10
  408. package/node_modules/@oscharko-dev/keiko-server/dist/editor/languageRoutes.d.ts +12 -1
  409. package/node_modules/@oscharko-dev/keiko-server/dist/editor/languageRoutes.d.ts.map +1 -1
  410. package/node_modules/@oscharko-dev/keiko-server/dist/editor/languageRoutes.js +71 -8
  411. package/node_modules/@oscharko-dev/keiko-server/dist/editor/languageService.d.ts +3 -2
  412. package/node_modules/@oscharko-dev/keiko-server/dist/editor/languageService.d.ts.map +1 -1
  413. package/node_modules/@oscharko-dev/keiko-server/dist/editor/languageService.js +41 -3
  414. package/node_modules/@oscharko-dev/keiko-server/dist/editor/languageServiceHost.d.ts.map +1 -1
  415. package/node_modules/@oscharko-dev/keiko-server/dist/editor/languageServiceHost.js +2 -2
  416. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/hostLanguageOperation.d.ts +17 -0
  417. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/hostLanguageOperation.d.ts.map +1 -0
  418. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/hostLanguageOperation.js +436 -0
  419. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/hostLanguageProviders.d.ts +26 -0
  420. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/hostLanguageProviders.d.ts.map +1 -0
  421. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/hostLanguageProviders.js +161 -0
  422. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspFrameCodec.d.ts +13 -0
  423. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspFrameCodec.d.ts.map +1 -0
  424. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspFrameCodec.js +164 -0
  425. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspJsonRpcClient.d.ts +34 -0
  426. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspJsonRpcClient.d.ts.map +1 -0
  427. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspJsonRpcClient.js +173 -0
  428. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspLanguageProvider.d.ts +7 -0
  429. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspLanguageProvider.d.ts.map +1 -0
  430. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspLanguageProvider.js +29 -0
  431. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspLifecycleLedger.d.ts +5 -0
  432. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspLifecycleLedger.d.ts.map +1 -0
  433. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspLifecycleLedger.js +37 -0
  434. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspNodeAdapter.d.ts +31 -0
  435. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspNodeAdapter.d.ts.map +1 -0
  436. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspNodeAdapter.js +230 -0
  437. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspProcessManager.d.ts +24 -0
  438. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspProcessManager.d.ts.map +1 -0
  439. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspProcessManager.js +255 -0
  440. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspRestartThrottle.d.ts +6 -0
  441. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspRestartThrottle.d.ts.map +1 -0
  442. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspRestartThrottle.js +24 -0
  443. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspStatusRoute.d.ts +8 -0
  444. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspStatusRoute.d.ts.map +1 -0
  445. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspStatusRoute.js +22 -0
  446. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspTransport.d.ts +19 -0
  447. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspTransport.d.ts.map +1 -0
  448. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/lspTransport.js +55 -0
  449. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/testing/fakeLspProcess.d.ts +23 -0
  450. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/testing/fakeLspProcess.d.ts.map +1 -0
  451. package/node_modules/@oscharko-dev/keiko-server/dist/editor/lsp/testing/fakeLspProcess.js +132 -0
  452. package/node_modules/@oscharko-dev/keiko-server/dist/files.d.ts +45 -0
  453. package/node_modules/@oscharko-dev/keiko-server/dist/files.d.ts.map +1 -1
  454. package/node_modules/@oscharko-dev/keiko-server/dist/files.js +631 -7
  455. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-readiness.js +3 -3
  456. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-setup.d.ts +2 -0
  457. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-setup.d.ts.map +1 -1
  458. package/node_modules/@oscharko-dev/keiko-server/dist/gateway-setup.js +275 -11
  459. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/actionSheetProjection.d.ts +30 -0
  460. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/actionSheetProjection.d.ts.map +1 -0
  461. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/actionSheetProjection.js +206 -0
  462. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/actionSheetRoutes.d.ts +29 -0
  463. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/actionSheetRoutes.d.ts.map +1 -0
  464. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/actionSheetRoutes.js +293 -0
  465. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/agentOperationsRoutes.d.ts +33 -0
  466. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/agentOperationsRoutes.d.ts.map +1 -0
  467. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/agentOperationsRoutes.js +405 -0
  468. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/commitRoutes.d.ts +23 -0
  469. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/commitRoutes.d.ts.map +1 -0
  470. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/commitRoutes.js +204 -0
  471. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/evidenceRoutes.d.ts +9 -0
  472. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/evidenceRoutes.d.ts.map +1 -0
  473. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/evidenceRoutes.js +101 -0
  474. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/execution.d.ts +38 -0
  475. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/execution.d.ts.map +1 -0
  476. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/execution.js +117 -0
  477. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/localMutationRoutes.d.ts +30 -0
  478. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/localMutationRoutes.d.ts.map +1 -0
  479. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/localMutationRoutes.js +165 -0
  480. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/mergeExecution.d.ts +63 -0
  481. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/mergeExecution.d.ts.map +1 -0
  482. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/mergeExecution.js +168 -0
  483. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/mergeRoutes.d.ts +12 -0
  484. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/mergeRoutes.d.ts.map +1 -0
  485. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/mergeRoutes.js +218 -0
  486. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/mutationEvidenceLedger.d.ts +23 -0
  487. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/mutationEvidenceLedger.d.ts.map +1 -0
  488. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/mutationEvidenceLedger.js +87 -0
  489. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/prExecution.d.ts +54 -0
  490. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/prExecution.d.ts.map +1 -0
  491. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/prExecution.js +192 -0
  492. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/prRoutes.d.ts +12 -0
  493. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/prRoutes.d.ts.map +1 -0
  494. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/prRoutes.js +256 -0
  495. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/pushExecution.d.ts +43 -0
  496. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/pushExecution.d.ts.map +1 -0
  497. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/pushExecution.js +124 -0
  498. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/pushRoutes.d.ts +12 -0
  499. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/pushRoutes.d.ts.map +1 -0
  500. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/pushRoutes.js +200 -0
  501. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/requestGuards.d.ts +15 -0
  502. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/requestGuards.d.ts.map +1 -0
  503. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/requestGuards.js +97 -0
  504. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/syncEvidence.d.ts +37 -0
  505. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/syncEvidence.d.ts.map +1 -0
  506. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/syncEvidence.js +85 -0
  507. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/syncExecution.d.ts +30 -0
  508. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/syncExecution.d.ts.map +1 -0
  509. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/syncExecution.js +266 -0
  510. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/syncRoutes.d.ts +13 -0
  511. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/syncRoutes.d.ts.map +1 -0
  512. package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/syncRoutes.js +200 -0
  513. package/node_modules/@oscharko-dev/keiko-server/dist/gitPorcelainStatus.d.ts +15 -0
  514. package/node_modules/@oscharko-dev/keiko-server/dist/gitPorcelainStatus.d.ts.map +1 -0
  515. package/node_modules/@oscharko-dev/keiko-server/dist/gitPorcelainStatus.js +104 -0
  516. package/node_modules/@oscharko-dev/keiko-server/dist/gitRepositoryReads.d.ts +10 -0
  517. package/node_modules/@oscharko-dev/keiko-server/dist/gitRepositoryReads.d.ts.map +1 -0
  518. package/node_modules/@oscharko-dev/keiko-server/dist/gitRepositoryReads.js +314 -0
  519. package/node_modules/@oscharko-dev/keiko-server/dist/gitRepositoryRoutes.d.ts +7 -0
  520. package/node_modules/@oscharko-dev/keiko-server/dist/gitRepositoryRoutes.d.ts.map +1 -0
  521. package/node_modules/@oscharko-dev/keiko-server/dist/gitRepositoryRoutes.js +221 -0
  522. package/node_modules/@oscharko-dev/keiko-server/dist/gitRoutes.d.ts +66 -0
  523. package/node_modules/@oscharko-dev/keiko-server/dist/gitRoutes.d.ts.map +1 -0
  524. package/node_modules/@oscharko-dev/keiko-server/dist/gitRoutes.js +543 -0
  525. package/node_modules/@oscharko-dev/keiko-server/dist/governed-workflow.d.ts +2 -0
  526. package/node_modules/@oscharko-dev/keiko-server/dist/governed-workflow.d.ts.map +1 -1
  527. package/node_modules/@oscharko-dev/keiko-server/dist/governed-workflow.js +4 -0
  528. package/node_modules/@oscharko-dev/keiko-server/dist/grounded-qa.d.ts +11 -0
  529. package/node_modules/@oscharko-dev/keiko-server/dist/grounded-qa.d.ts.map +1 -1
  530. package/node_modules/@oscharko-dev/keiko-server/dist/grounded-qa.js +13 -4
  531. package/node_modules/@oscharko-dev/keiko-server/dist/headers.d.ts +4 -1
  532. package/node_modules/@oscharko-dev/keiko-server/dist/headers.d.ts.map +1 -1
  533. package/node_modules/@oscharko-dev/keiko-server/dist/headers.js +11 -4
  534. package/node_modules/@oscharko-dev/keiko-server/dist/index.d.ts +8 -1
  535. package/node_modules/@oscharko-dev/keiko-server/dist/index.d.ts.map +1 -1
  536. package/node_modules/@oscharko-dev/keiko-server/dist/index.js +9 -1
  537. package/node_modules/@oscharko-dev/keiko-server/dist/qualityIntelligence/figmaSnapshotRoutes.d.ts +1 -1
  538. package/node_modules/@oscharko-dev/keiko-server/dist/qualityIntelligence/figmaSnapshotRoutes.d.ts.map +1 -1
  539. package/node_modules/@oscharko-dev/keiko-server/dist/qualityIntelligence/figmaSnapshotRoutes.js +1 -1
  540. package/node_modules/@oscharko-dev/keiko-server/dist/read-handlers.d.ts +5 -0
  541. package/node_modules/@oscharko-dev/keiko-server/dist/read-handlers.d.ts.map +1 -1
  542. package/node_modules/@oscharko-dev/keiko-server/dist/read-handlers.js +57 -1
  543. package/node_modules/@oscharko-dev/keiko-server/dist/routes.d.ts.map +1 -1
  544. package/node_modules/@oscharko-dev/keiko-server/dist/routes.js +259 -6
  545. package/node_modules/@oscharko-dev/keiko-server/dist/run-engine.d.ts.map +1 -1
  546. package/node_modules/@oscharko-dev/keiko-server/dist/run-engine.js +3 -0
  547. package/node_modules/@oscharko-dev/keiko-server/dist/run-handlers.d.ts.map +1 -1
  548. package/node_modules/@oscharko-dev/keiko-server/dist/run-handlers.js +74 -4
  549. package/node_modules/@oscharko-dev/keiko-server/dist/run-request.d.ts +11 -0
  550. package/node_modules/@oscharko-dev/keiko-server/dist/run-request.d.ts.map +1 -1
  551. package/node_modules/@oscharko-dev/keiko-server/dist/run-request.js +158 -10
  552. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/capabilityDetector.d.ts +38 -0
  553. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/capabilityDetector.d.ts.map +1 -0
  554. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/capabilityDetector.js +443 -0
  555. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/capabilityRoutes.d.ts +9 -0
  556. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/capabilityRoutes.d.ts.map +1 -0
  557. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/capabilityRoutes.js +45 -0
  558. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerEngineDetector.d.ts +17 -0
  559. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerEngineDetector.d.ts.map +1 -0
  560. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerEngineDetector.js +222 -0
  561. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRoutes.d.ts +8 -0
  562. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRoutes.d.ts.map +1 -0
  563. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRoutes.js +207 -0
  564. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRunner-errors.d.ts +18 -0
  565. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRunner-errors.d.ts.map +1 -0
  566. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRunner-errors.js +42 -0
  567. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRunner-evidence.d.ts +24 -0
  568. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRunner-evidence.d.ts.map +1 -0
  569. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRunner-evidence.js +74 -0
  570. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRunner.d.ts +37 -0
  571. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRunner.d.ts.map +1 -0
  572. package/node_modules/@oscharko-dev/keiko-server/dist/runtime/containerRunner.js +443 -0
  573. package/node_modules/@oscharko-dev/keiko-server/dist/server.d.ts.map +1 -1
  574. package/node_modules/@oscharko-dev/keiko-server/dist/server.js +24 -4
  575. package/node_modules/@oscharko-dev/keiko-server/dist/store/schema.d.ts +1 -1
  576. package/node_modules/@oscharko-dev/keiko-server/dist/store/schema.d.ts.map +1 -1
  577. package/node_modules/@oscharko-dev/keiko-server/dist/store/schema.js +62 -1
  578. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/active-store.d.ts +21 -0
  579. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/active-store.d.ts.map +1 -0
  580. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/active-store.js +55 -0
  581. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/authorization.d.ts +7 -0
  582. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/authorization.d.ts.map +1 -0
  583. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/authorization.js +54 -0
  584. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/binding.d.ts +3 -0
  585. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/binding.d.ts.map +1 -0
  586. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/binding.js +22 -0
  587. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/cleanup.d.ts +4 -0
  588. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/cleanup.d.ts.map +1 -0
  589. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/cleanup.js +428 -0
  590. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/errors.d.ts +14 -0
  591. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/errors.d.ts.map +1 -0
  592. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/errors.js +81 -0
  593. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/evidence.d.ts +32 -0
  594. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/evidence.d.ts.map +1 -0
  595. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/evidence.js +52 -0
  596. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/field-safety.d.ts +3 -0
  597. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/field-safety.d.ts.map +1 -0
  598. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/field-safety.js +42 -0
  599. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/health.d.ts +4 -0
  600. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/health.d.ts.map +1 -0
  601. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/health.js +163 -0
  602. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/lifecycle.d.ts +3 -0
  603. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/lifecycle.d.ts.map +1 -0
  604. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/lifecycle.js +248 -0
  605. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/locks.d.ts +13 -0
  606. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/locks.d.ts.map +1 -0
  607. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/locks.js +44 -0
  608. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/managed-root.d.ts +7 -0
  609. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/managed-root.d.ts.map +1 -0
  610. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/managed-root.js +98 -0
  611. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/mutex.d.ts +8 -0
  612. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/mutex.d.ts.map +1 -0
  613. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/mutex.js +82 -0
  614. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/naming.d.ts +15 -0
  615. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/naming.d.ts.map +1 -0
  616. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/naming.js +0 -0
  617. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/provisioning.d.ts +3 -0
  618. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/provisioning.d.ts.map +1 -0
  619. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/provisioning.js +528 -0
  620. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/reconciliation.d.ts +15 -0
  621. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/reconciliation.d.ts.map +1 -0
  622. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/reconciliation.js +274 -0
  623. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/repair.d.ts +3 -0
  624. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/repair.d.ts.map +1 -0
  625. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/repair.js +286 -0
  626. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/routes.d.ts +19 -0
  627. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/routes.d.ts.map +1 -0
  628. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/routes.js +481 -0
  629. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/store.d.ts +12 -0
  630. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/store.d.ts.map +1 -0
  631. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/store.js +128 -0
  632. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/types.d.ts +170 -0
  633. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/types.d.ts.map +1 -0
  634. package/node_modules/@oscharko-dev/keiko-server/dist/task-workspace/types.js +5 -0
  635. package/node_modules/@oscharko-dev/keiko-server/dist/voice-action-governance.d.ts +23 -0
  636. package/node_modules/@oscharko-dev/keiko-server/dist/voice-action-governance.d.ts.map +1 -0
  637. package/node_modules/@oscharko-dev/keiko-server/dist/voice-action-governance.js +126 -0
  638. package/node_modules/@oscharko-dev/keiko-server/dist/voice-handlers.d.ts +6 -0
  639. package/node_modules/@oscharko-dev/keiko-server/dist/voice-handlers.d.ts.map +1 -0
  640. package/node_modules/@oscharko-dev/keiko-server/dist/voice-handlers.js +570 -0
  641. package/node_modules/@oscharko-dev/keiko-server/dist/voice-realtime-grounded-tool.d.ts +31 -0
  642. package/node_modules/@oscharko-dev/keiko-server/dist/voice-realtime-grounded-tool.d.ts.map +1 -0
  643. package/node_modules/@oscharko-dev/keiko-server/dist/voice-realtime-grounded-tool.js +322 -0
  644. package/node_modules/@oscharko-dev/keiko-server/dist/voice-realtime.d.ts +69 -0
  645. package/node_modules/@oscharko-dev/keiko-server/dist/voice-realtime.d.ts.map +1 -0
  646. package/node_modules/@oscharko-dev/keiko-server/dist/voice-realtime.js +787 -0
  647. package/node_modules/@oscharko-dev/keiko-server/dist/workspace-state-handlers.d.ts +5 -0
  648. package/node_modules/@oscharko-dev/keiko-server/dist/workspace-state-handlers.d.ts.map +1 -0
  649. package/node_modules/@oscharko-dev/keiko-server/dist/workspace-state-handlers.js +106 -0
  650. package/node_modules/@oscharko-dev/keiko-server/package.json +20 -19
  651. package/node_modules/@oscharko-dev/keiko-tools/dist/.tsbuildinfo +1 -1
  652. package/node_modules/@oscharko-dev/keiko-tools/dist/git-commit-intent-node.d.ts +7 -0
  653. package/node_modules/@oscharko-dev/keiko-tools/dist/git-commit-intent-node.d.ts.map +1 -0
  654. package/node_modules/@oscharko-dev/keiko-tools/dist/git-commit-intent-node.js +42 -0
  655. package/node_modules/@oscharko-dev/keiko-tools/dist/git-merge-gateway.d.ts +95 -0
  656. package/node_modules/@oscharko-dev/keiko-tools/dist/git-merge-gateway.d.ts.map +1 -0
  657. package/node_modules/@oscharko-dev/keiko-tools/dist/git-merge-gateway.js +536 -0
  658. package/node_modules/@oscharko-dev/keiko-tools/dist/git-merge-node.d.ts +17 -0
  659. package/node_modules/@oscharko-dev/keiko-tools/dist/git-merge-node.d.ts.map +1 -0
  660. package/node_modules/@oscharko-dev/keiko-tools/dist/git-merge-node.js +243 -0
  661. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-adapter.d.ts +51 -0
  662. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-adapter.d.ts.map +1 -0
  663. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-adapter.js +207 -0
  664. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-evidence.d.ts +23 -0
  665. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-evidence.d.ts.map +1 -0
  666. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-evidence.js +283 -0
  667. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-node.d.ts +22 -0
  668. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-node.d.ts.map +1 -0
  669. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-node.js +145 -0
  670. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-orchestrator.d.ts +92 -0
  671. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-orchestrator.d.ts.map +1 -0
  672. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-orchestrator.js +321 -0
  673. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-preflight.d.ts +35 -0
  674. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-preflight.d.ts.map +1 -0
  675. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-preflight.js +226 -0
  676. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-taxonomy.d.ts +15 -0
  677. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-taxonomy.d.ts.map +1 -0
  678. package/node_modules/@oscharko-dev/keiko-tools/dist/git-mutation-taxonomy.js +102 -0
  679. package/node_modules/@oscharko-dev/keiko-tools/dist/git-pr-gateway.d.ts +101 -0
  680. package/node_modules/@oscharko-dev/keiko-tools/dist/git-pr-gateway.d.ts.map +1 -0
  681. package/node_modules/@oscharko-dev/keiko-tools/dist/git-pr-gateway.js +487 -0
  682. package/node_modules/@oscharko-dev/keiko-tools/dist/git-pr-node.d.ts +17 -0
  683. package/node_modules/@oscharko-dev/keiko-tools/dist/git-pr-node.d.ts.map +1 -0
  684. package/node_modules/@oscharko-dev/keiko-tools/dist/git-pr-node.js +173 -0
  685. package/node_modules/@oscharko-dev/keiko-tools/dist/git-publish-gateway.d.ts +72 -0
  686. package/node_modules/@oscharko-dev/keiko-tools/dist/git-publish-gateway.d.ts.map +1 -0
  687. package/node_modules/@oscharko-dev/keiko-tools/dist/git-publish-gateway.js +423 -0
  688. package/node_modules/@oscharko-dev/keiko-tools/dist/git-publish-node.d.ts +17 -0
  689. package/node_modules/@oscharko-dev/keiko-tools/dist/git-publish-node.d.ts.map +1 -0
  690. package/node_modules/@oscharko-dev/keiko-tools/dist/git-publish-node.js +107 -0
  691. package/node_modules/@oscharko-dev/keiko-tools/dist/git-worktree-adapter.d.ts +78 -0
  692. package/node_modules/@oscharko-dev/keiko-tools/dist/git-worktree-adapter.d.ts.map +1 -0
  693. package/node_modules/@oscharko-dev/keiko-tools/dist/git-worktree-adapter.js +300 -0
  694. package/node_modules/@oscharko-dev/keiko-tools/dist/git-worktree-snapshot-node.d.ts +31 -0
  695. package/node_modules/@oscharko-dev/keiko-tools/dist/git-worktree-snapshot-node.d.ts.map +1 -0
  696. package/node_modules/@oscharko-dev/keiko-tools/dist/git-worktree-snapshot-node.js +189 -0
  697. package/node_modules/@oscharko-dev/keiko-tools/dist/index.d.ts +9 -0
  698. package/node_modules/@oscharko-dev/keiko-tools/dist/index.d.ts.map +1 -1
  699. package/node_modules/@oscharko-dev/keiko-tools/dist/index.js +37 -0
  700. package/node_modules/@oscharko-dev/keiko-tools/package.json +9 -5
  701. package/node_modules/@oscharko-dev/keiko-verification/dist/.tsbuildinfo +1 -1
  702. package/node_modules/@oscharko-dev/keiko-verification/package.json +5 -5
  703. package/node_modules/@oscharko-dev/keiko-workflows/dist/.tsbuildinfo +1 -1
  704. package/node_modules/@oscharko-dev/keiko-workflows/dist/contextpack/assemble.d.ts.map +1 -1
  705. package/node_modules/@oscharko-dev/keiko-workflows/dist/contextpack/assemble.js +2 -2
  706. package/node_modules/@oscharko-dev/keiko-workflows/package.json +10 -10
  707. package/node_modules/@oscharko-dev/keiko-workspace/dist/.tsbuildinfo +1 -1
  708. package/node_modules/@oscharko-dev/keiko-workspace/dist/repoSearchEntries.d.ts.map +1 -1
  709. package/node_modules/@oscharko-dev/keiko-workspace/dist/repoSearchEntries.js +2 -2
  710. package/node_modules/@oscharko-dev/keiko-workspace/package.json +3 -3
  711. package/package.json +50 -29
  712. package/dist/ui/static/_next/static/chunks/8776.8b33803959adfdcf.js +0 -3
  713. package/dist/ui/static/_next/static/chunks/8824-1b90854002e51dae.js +0 -98
  714. package/dist/ui/static/_next/static/chunks/8835-7a3269c7abf41dca.js +0 -1
  715. package/dist/ui/static/_next/static/chunks/9385.6543855a745f1347.js +0 -1
  716. package/dist/ui/static/_next/static/chunks/webpack-b38f050528b4d7a7.js +0 -1
  717. package/dist/ui/static/_next/static/css/a1d25933a2ce4659.css +0 -3
  718. package/node_modules/@oscharko-dev/keiko-contracts/dist/conversation-budget.d.ts +0 -37
  719. package/node_modules/@oscharko-dev/keiko-contracts/dist/conversation-budget.d.ts.map +0 -1
  720. package/node_modules/@oscharko-dev/keiko-contracts/dist/conversation-budget.js +0 -97
  721. /package/dist/ui/static/_next/static/{V6PH3CS6q84y0pJQupf9J → tzWFDxPPJ3-NtjB1T1JFu}/_buildManifest.js +0 -0
  722. /package/dist/ui/static/_next/static/{V6PH3CS6q84y0pJQupf9J → tzWFDxPPJ3-NtjB1T1JFu}/_ssgManifest.js +0 -0
@@ -1,98 +0,0 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8824],{6123:(e,t,n)=>{"use strict";let l;n.d(t,{KeikoDesktop:()=>u8});var a=n(54568),i=n(7620);let r=(0,i.createContext)(null);function s(e){let{value:t,children:n}=e;return(0,a.jsx)(r.Provider,{value:t,children:n});}function o(){let e=(0,i.useContext)(r);if(null===e)throw Error("useChatSessionContext must be used inside ChatSessionProvider");return e;}function c(){return(0,i.useContext)(r);}let d=[{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"}],u={calendar:!0,mail:!1,jira:!0,docs:!0},p="keiko.twin.mode",m="keiko.twin.persona",h="keiko.twin.policy",f="keiko.twin.bridges",g=(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 b(e,t){try{window.localStorage.setItem(e,t);}catch{}}function x(e,t){try{window.localStorage.setItem(e,JSON.stringify(t));}catch{}}function y(e){let{children:t}=e,[n,l]=(0,i.useState)("manual"),[r,s]=(0,i.useState)("Developer"),[o,c]=(0,i.useState)(d),[y,j]=(0,i.useState)(u),[w,k]=(0,i.useState)(!1);(0,i.useEffect)(()=>{l(function(){try{let e=window.localStorage.getItem(p);return"manual"===e||"autonomous"===e?e:"manual";}catch{return"manual";}}()),s(function(){try{let e=window.localStorage.getItem(m);if("Developer"===e||"Product Owner"===e||"Designer"===e)return e;return"Developer";}catch{return"Developer";}}()),c(v(h,d)),j(v(f,u));try{window.localStorage.removeItem("keiko.twin.memory");}catch{}k(!0);},[]),(0,i.useEffect)(()=>{w&&b(p,n);},[n,w]),(0,i.useEffect)(()=>{w&&b(m,r);},[r,w]),(0,i.useEffect)(()=>{w&&x(h,o);},[o,w]),(0,i.useEffect)(()=>{w&&x(f,y);},[y,w]);let N=(0,i.useCallback)((e,t)=>{var n,l,a,i,r,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!=(i=d("write-prod"))?i:"deny":null!=(r=d("write"))?r:"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]),S=(0,i.useMemo)(()=>({mode:n,setMode:l,persona:r,setPersona:s,policy:o,setPolicy:c,bridges:y,setBridges:j,decide:N}),[n,r,o,y,N]);return(0,a.jsx)(g.Provider,{value:S,children:t});}function j(){let e=(0,i.useContext)(g);if(null===e)throw Error("useTwin must be used inside <TwinProvider>");return e;}let w=(0,i.createContext)({wins:[],active:null,winCount:0});var k=n(73599),N=n(75571);let S={w:150,h:110},C={w:290,h:190},I={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:""}]},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}}},R=new Map();function $(e,t){R.set(e,t);}let E=(l={},Object.keys(I).forEach(e=>{var t,n,a;let i,r;l[e]=(i={title:(t=I[e]).title,icon:t.icon,desc:t.desc,w:t.w,h:t.h,min:null!=(n=t.min)?n:S,tiny:null!=(a=t.tiny)?a:C,render:(t,n)=>{let l=R.get(e);return void 0!==l?l(t,n):null;}},r={},!0===t.accent&&(r.accent=!0),!0===t.tool&&(r.tool=!0),!0===t.singleton&&(r.singleton=!0),void 0!==t.config&&(r.config=t.config),void 0!==t.cta&&(r.cta=t.cta),{...i,...r});}),l),A={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 F(e,t){var n,l;return void 0!==e&&void 0!==t&&e!==t&&((null!=(n=A[e])?n:[]).includes(t)||(null!=(l=A[t])?l:[]).includes(e));}function T(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 i=null==e?void 0:e.activeFilePath;if("string"==typeof i&&i.length>0)return null!=(l=i.split(/[/\\]/u).filter(Boolean).pop())?l:i;let r=null==e?void 0:e.activeDirectoryPath;return"string"==typeof r&&r.length>0?`${null!=(a=r.split(/[/\\]/u).filter(Boolean).pop())?a:r}/`:`${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 i;let n="figma"===e.type?e:"figma"===t.type?t:null,l=null==n||null==(i=n.cfg)?void 0:i.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 D(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 M(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"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;}}function P(e){let{winCount:t,windows:n,windowPaletteOpen:l,onToggleWindowPalette:r,onSelectWindow:s,onCloseWindowPalette:o,statusRef:c}=e,d=(0,i.useRef)(null),[u,p]=(0,i.useState)("version loading"),m=`${String(t)} ${1===t?"window":"windows"}`,h=[...n].sort((e,t)=>t.z-e.z);return(0,i.useEffect)(()=>{let e=!1;return async function(){try{let t=await(0,k.T7)();e||p(t.version);}catch{e||p("version unavailable");}}(),()=>{e=!0;};},[]),(0,i.useEffect)(()=>{if(!l)return;if(0===t)return void o();let e=e=>{let t=e.target;t instanceof Node&&null!==d.current&&!d.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,a.jsxs)("footer",{ref:c,className:"footer mono",tabIndex:-1,"aria-label":"Workspace status","aria-live":"polite",children:[(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("span",{className:"ft-brand","aria-label":`Keiko version ${u}`,children:["Keiko | ",u]}),(0,a.jsxs)("span",{className:"ft-window-wrap",ref:d,children:[(0,a.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:r,children:[(0,a.jsx)(N.F.tile,{size:13})," ",m]}),l&&t>0?(0,a.jsxs)("div",{id:"footer-window-palette",className:"ft-window-palette",role:"group","aria-label":"Open windows",children:[(0,a.jsx)("div",{className:"ft-window-palette-head",children:"Open windows"}),(0,a.jsx)("div",{className:"ft-window-list",children:h.map(e=>{let t=E[e.type],n=N.F[t.icon],l=M(e.type,e.cfg),i=!0===e.minimized?"Minimized":e.max?"Fullscreen":"Visible",r=!0===e.minimized?"Restore":"Focus";return(0,a.jsxs)("button",{type:"button",className:"ft-window-card","data-minimized":!0===e.minimized?"true":"false","aria-label":`${r} ${t.title} window${null!==l?` - ${l}`:""}`,onClick:()=>s(e.id),children:[(0,a.jsx)("span",{className:"ft-window-icon",style:{color:!0===t.accent?"var(--accent)":void 0},children:(0,a.jsx)(n,{size:14})}),(0,a.jsxs)("span",{className:"ft-window-copy",children:[(0,a.jsx)("span",{className:"ft-window-title",children:t.title}),(0,a.jsx)("span",{className:"ft-window-sub",title:null!=l?l:i,children:null!=l?l:i})]}),(0,a.jsx)("span",{className:"ft-window-state",children:i})]},e.id);})})]}):null]})]});}function q(e){let{openPalette:t,openCommandPalette:n,onTileAll:l,onSplitFront:i,onCascade:r}=e;return(0,a.jsxs)("header",{className:"header",children:[(0,a.jsxs)("div",{className:"hd-brand",children:[(0,a.jsx)("img",{className:"hd-logo",src:"/assets/keiko-logo.svg",alt:""}),(0,a.jsx)("span",{className:"hd-wordmark",children:"Keiko"})]}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("div",{className:"hd-tools",children:[(0,a.jsx)("button",{type:"button",className:"hd-tool ui-tip",onClick:l,"data-tip":"Tile all windows","aria-label":"Tile all windows",children:(0,a.jsx)(N.F.tile,{size:16})}),(0,a.jsx)("button",{type:"button",className:"hd-tool ui-tip",onClick:i,"data-tip":"Split front windows","aria-label":"Split front windows",children:(0,a.jsx)(N.F.split,{size:16})}),(0,a.jsx)("button",{type:"button",className:"hd-tool ui-tip",onClick:r,"data-tip":"Cascade windows","aria-label":"Cascade windows",children:(0,a.jsx)(N.F.cascade,{size:16})})]})]});}let L=[{id:"chatHistory",icon:"archive",label:"Chat History"}];function z(e){let{tool:t,active:n,onClick:l}=e,i=N.F[t.icon];return(0,a.jsx)("button",{type:"button",className:"rail-btn","data-active":n?"true":"false","data-side":"left","aria-label":t.label,"aria-pressed":n,"data-tip":t.label,onClick:l,children:void 0!==t.img?(0,a.jsx)("img",{className:"rail-img",src:t.img,alt:""}):(0,a.jsx)(i,{size:19})});}function O(e){let{openTools:t,onTool:n,onNewChat:l,theme:i,onToggleTheme:r}=e;return(0,a.jsxs)("nav",{className:"rail rail-left","aria-label":"Primary workspace navigation",children:[(0,a.jsx)("button",{type:"button",className:"rail-new",onClick:l,"data-side":"left","aria-label":"New chat","data-tip":"New chat",children:(0,a.jsx)(N.F.newChat,{size:18})}),(0,a.jsx)("div",{className:"rail-div"}),(0,a.jsx)("div",{className:"rail-group",children:L.map(e=>(0,a.jsx)(z,{tool:e,active:t.has(e.id),onClick:()=>n(e.id)},e.id))}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("div",{className:"rail-group",children:[(0,a.jsx)("button",{type:"button",className:"rail-btn","data-active":t.has("memoria")?"true":"false","data-side":"left","aria-label":"MemoriaViva","aria-pressed":t.has("memoria"),"data-tip":"MemoriaViva",onClick:()=>n("memoria"),children:(0,a.jsx)(N.F.brain,{size:19})}),(0,a.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("quality")?"true":"false","aria-label":"Quality Intelligence","aria-pressed":t.has("quality"),"data-tip":"Quality Intelligence",onClick:()=>n("quality"),children:(0,a.jsx)(N.F.check,{size:19})}),(0,a.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("promptEnhancer")?"true":"false","aria-label":"Prompt Enhancer","aria-pressed":t.has("promptEnhancer"),"data-tip":"Prompt Enhancer",onClick:()=>n("promptEnhancer"),children:(0,a.jsx)(N.F.spark,{size:19})}),(0,a.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("localKnowledge")?"true":"false","aria-label":"Local Knowledge","aria-pressed":t.has("localKnowledge"),"data-tip":"Local Knowledge",onClick:()=>n("localKnowledge"),children:(0,a.jsx)(N.F.localKnowledge,{size:19})}),(0,a.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("figma")?"true":"false","aria-label":"Figma Snapshot","aria-pressed":t.has("figma"),"data-tip":"Figma Snapshot",onClick:()=>n("figma"),children:(0,a.jsx)(N.F.layers,{size:19})})]}),(0,a.jsx)("div",{className:"rail-div"}),(0,a.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","aria-label":"light"===i?"Dark mode":"Light mode","aria-pressed":"light"===i,"data-tip":"light"===i?"Dark mode":"Light mode",onClick:r,children:"light"===i?(0,a.jsx)(N.F.moon,{size:19}):(0,a.jsx)(N.F.sun,{size:19})}),(0,a.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("settings")?"true":"false","aria-label":"Settings","aria-pressed":t.has("settings"),"data-tip":"Settings",onClick:()=>n("settings"),children:(0,a.jsx)(N.F.settings,{size:19})})]});}function K(e){return(0,a.jsx)("aside",{className:"rail rail-right","aria-label":"Workspace utilities",children:(0,a.jsx)("span",{className:"spacer"})});}function W(e){return e.toFixed(2);}function B(e){let{onNewWindow:t}=e,n=(0,i.useId)(),l=`ewb-${n.replace(/:/gu,"")}`,r=(0,i.useRef)(null),s=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=e=>{var t;null==(t=r.current)||t.setAttribute("d",function(e){var t,n,l,a;let i=[];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));i.push([140+127.44000000000001*l*Math.cos(n),140+118*l*Math.sin(n)]);}let r=`M${W(null!=(t=null==(l=i[0])?void 0:l[0])?t:140)} ${W(null!=(n=null==(a=i[0])?void 0:a[1])?n:140)} `;for(let e=0;e<i.length;e++){let t=i[(e-1+i.length)%i.length],n=i[e],l=i[(e+1)%i.length],a=i[(e+2)%i.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;r+=`C${W(s)} ${W(o)} ${W(c)} ${W(d)} ${W(l[0])} ${W(l[1])} `;}return`${r}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);},a=()=>{0===t&&!0!==document.hidden&&(t=window.requestAnimationFrame(l));},i=()=>{!0===document.hidden?n():a();};return a(),document.addEventListener("visibilitychange",i),window.addEventListener("blur",n),window.addEventListener("focus",a),()=>{n(),document.removeEventListener("visibilitychange",i),window.removeEventListener("blur",n),window.removeEventListener("focus",a);};},[]);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,a.jsx)("button",{type:"button",className:"empty-workspace-blob","aria-label":"Open a new window",onClick:o,children:(0,a.jsxs)("svg",{width:"320",height:"320",viewBox:"0 0 280 280","aria-hidden":"true",children:[(0,a.jsx)("defs",{children:(0,a.jsxs)("mask",{id:l,maskUnits:"userSpaceOnUse",x:"0",y:"0",width:"280",height:"280",children:[(0,a.jsx)("rect",{x:"0",y:"0",width:"280",height:"280",fill:"#fff"}),(0,a.jsx)("g",{transform:"translate(107,64) scale(0.080625)",children:(0,a.jsx)("g",{transform:"translate(1024 0) scale(-1 1)",children:(0,a.jsx)("g",{transform:"translate(1024,1024) scale(-0.1,-0.1)",fill:"#000",children:(0,a.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,a.jsx)("text",{x:"140",y:"172",textAnchor:"middle",fill:"#000",fontFamily:"var(--font-ui)",fontSize:"16",fontWeight:"700",children:"Empty workspace"}),(0,a.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,a.jsx)("g",{ref:s,className:"empty-workspace-blob__group",children:(0,a.jsx)("path",{ref:r,className:"empty-workspace-blob__fill",mask:`url(#${l})`})})]})});}function U(e){return 0===e.button&&!(0===e.button&&e.ctrlKey);}function _(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 V(e){return e instanceof Element&&null!==e.closest("input, textarea, select, [contenteditable='true'], [contenteditable=''], [data-text-selectable='true']");}function J(){return!("u"<typeof document)&&"true"===document.documentElement.getAttribute("data-keiko-modal-open");}let H=0,Y="",X="";function G(){if("u"<typeof document)return()=>void 0;let e=document.body;0===H&&(Y=e.style.cursor,X=e.style.userSelect,e.style.cursor="grabbing",e.style.userSelect="none"),H+=1;let t=!1;return()=>{t||(t=!0,0===(H=Math.max(0,H-1))&&(e.style.cursor=Y,e.style.userSelect=X));};}let Q="keiko.wallpaper.enabled",Z="keiko.wallpaper.opacity",ee="keiko.workspace.background.brightness",et="keiko.workspace.grid.strength",en="keiko.frame.border.strength",el="keiko.frame.inner.glow.strength",ea="keiko:wallpaper-enabled",ei="keiko:wallpaper-opacity",er="keiko:workspace-background-brightness",es="keiko:workspace-grid-strength",eo="keiko:frame-border-strength",ec="keiko:frame-inner-glow-strength";function ed(e){return Number.isFinite(e)?Math.max(0,Math.min(100,e)):0;}function eu(){try{var e;if("function"!=typeof(null==(e=window.localStorage)?void 0:e.getItem))return!1;return"true"===window.localStorage.getItem(Q);}catch{return!1;}}function ep(){try{var e;if("function"!=typeof(null==(e=window.localStorage)?void 0:e.getItem))return 100;let t=window.localStorage.getItem(Z);if(null===t)return 100;return ed(Number.parseInt(t,10));}catch{return 100;}}function em(){try{var e;if("function"!=typeof(null==(e=window.localStorage)?void 0:e.getItem))return 0;let t=window.localStorage.getItem(ee);if(null===t)return 0;return ed(Number.parseInt(t,10));}catch{return 0;}}function eh(){try{var e;if("function"!=typeof(null==(e=window.localStorage)?void 0:e.getItem))return 28;let t=window.localStorage.getItem(et);if(null===t)return 28;return ed(Number.parseInt(t,10));}catch{return 28;}}function ef(){try{var e;if("function"!=typeof(null==(e=window.localStorage)?void 0:e.getItem))return 42;let t=window.localStorage.getItem(en);if(null===t)return 42;return ed(Number.parseInt(t,10));}catch{return 42;}}function eg(){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 ed(Number.parseInt(t,10));}catch{return 0;}}function ev(e){"u">typeof document&&document.documentElement.style.setProperty("--workspace-bg-brightness",`${ed(e)}%`);}function eb(e){"u">typeof document&&document.documentElement.style.setProperty("--workspace-grid-strength",`${ed(e)}%`);}function ex(e){"u">typeof document&&document.documentElement.style.setProperty("--frame-border-strength",`${ed(e)}%`);}function ey(e){"u">typeof document&&document.documentElement.style.setProperty("--frame-inner-glow-strength",`${ed(e)}%`);}let ej=`
2
- attribute vec2 aPos;
3
- void main(){ gl_Position = vec4(aPos, 0.0, 1.0); }
4
- `,ew=`
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 ek(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 eN(){let e=(0,i.useRef)(null),[t,n]=(0,i.useState)(eu);return(0,i.useEffect)(()=>{ev(em()),eb(eh()),ex(ef()),ey(eg());let e=e=>{let t=e.detail;ev("number"==typeof t?t:em());},t=e=>{let t=e.detail;eb("number"==typeof t?t:eh());},n=e=>{let t=e.detail;ex("number"==typeof t?t:ef());},l=e=>{let t=e.detail;ey("number"==typeof t?t:eg());};return window.addEventListener(er,e),window.addEventListener(es,t),window.addEventListener(eo,n),window.addEventListener(ec,l),()=>{window.removeEventListener(er,e),window.removeEventListener(es,t),window.removeEventListener(eo,n),window.removeEventListener(ec,l);};},[]),(0,i.useEffect)(()=>{let e=e=>{let t=e.detail;n("boolean"==typeof t?t:eu());},t=e=>{(null===e.key||e.key===Q)&&n(eu());};return window.addEventListener(ea,e),window.addEventListener("storage",t),()=>{window.removeEventListener(ea,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 i=window.matchMedia("(prefers-reduced-motion: reduce)"),r=()=>{i.matches?(null==n||n(),n=void 0):void 0===n&&(n=function(e,t){var n;t.style.opacity=String(ep()/100);let l=e=>{let n=e.detail,l="number"==typeof n?n:ep();t.style.opacity=String(ed(l)/100);};window.addEventListener(ei,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(ei,l);};let i=ek(a,a.VERTEX_SHADER,ej),r=ek(a,a.FRAGMENT_SHADER,ew);if(null===i||null===r)return()=>{window.removeEventListener(ei,l);};let s=a.createProgram();if(null===s||(a.attachShader(s,i),a.attachShader(s,r),a.linkProgram(s),!a.getProgramParameter(s,a.LINK_STATUS)))return()=>{window.removeEventListener(ei,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),x=[,,,,].fill(-1/0),y=0;function j(){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);}j();let w="u">typeof ResizeObserver?new ResizeObserver(j):null;null!==w?w.observe(e):window.addEventListener("resize",j);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*y]=l,b[2*y+1]=a,x[y]=performance.now(),y=(y+1)%4);};e.addEventListener("pointerdown",k);let N=performance.now(),S=0,C=!0,I=new Float32Array(4);function R(){if(!C)return;let e=performance.now();for(let t=0;t<4;t++){var n;I[t]=(e-(null!=(n=x[t])?n:-1/0))/1e3;}let l=+("light"===document.documentElement.dataset.theme);null!==a&&(a.uniform2f(d,t.width,t.height),a.uniform1f(u,(e-N)/1e3),a.uniform1f(p,l),a.uniform2fv(m,b),a.uniform1fv(h,I),a.drawArrays(a.TRIANGLES,0,3)),S=requestAnimationFrame(R);}S=requestAnimationFrame(R);let $=()=>{document.hidden?(C=!1,cancelAnimationFrame(S)):C||(C=!0,S=requestAnimationFrame(R));};return document.addEventListener("visibilitychange",$),()=>{C=!1,cancelAnimationFrame(S),document.removeEventListener("visibilitychange",$),window.removeEventListener(ei,l),e.removeEventListener("pointerdown",k),null!==w?w.disconnect():window.removeEventListener("resize",j),null!==a&&(a.deleteBuffer(o),a.deleteProgram(s),a.deleteShader(i),a.deleteShader(r));};}(a,l));};return r(),i.addEventListener("change",r),()=>{i.removeEventListener("change",r),null==n||n();};},[t]),t?(0,a.jsx)("canvas",{ref:e,className:"ws-shader","aria-hidden":"true"}):null;}let eS=new Set(["files","connector","browser","plugins","agents","quality"]);function eC(e,t){return e>=4||t>=8192;}function eI(e){let{pathId:t,intensity:n}=e,l="heavy"===n?3:1,i="heavy"===n?1.1:2.2;return(0,a.jsx)(a.Fragment,{children:Array.from({length:l},(e,r)=>(0,a.jsx)("circle",{className:"conn-particle",r:"heavy"===n?3:2.4,"aria-hidden":"true",children:(0,a.jsx)("animateMotion",{dur:`${String(i)}s`,repeatCount:"indefinite",begin:`${String(i/l*r)}s`,rotate:"auto",keyPoints:"0;1",keyTimes:"0;1",calcMode:"linear",children:(0,a.jsx)("mpath",{href:`#${t}`})})},r))});}function eR(e){let{wins:t,conns:n,connecting:l,api:r}=e,s=c(),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:d,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 eC(e.contextPack.usage.filesRead,e.contextPack.usage.excerptBytes)?"heavy":"light";case"hybrid":return eC(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=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 i=function(e,t){let n,l,a,i,r={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-r.x,c=s.y-r.y;if(Math.abs(o)>=Math.abs(c)){n=o>=0?{x:e.x+e.w,y:r.y}:{x:e.x,y:r.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},i={x:l.x-d*c,y:l.y};}else{n=c>=0?{x:r.x,y:e.y+e.h}:{x:r.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},i={x:l.x,y:l.y-d*o};}let d={x:(n.x+3*a.x+3*i.x+l.x)/8,y:(n.y+3*a.y+3*i.y+l.y)/8};return{d:`M${String(n.x)},${String(n.y)} C${String(a.x)},${String(a.y)} ${String(i.x)},${String(i.y)} ${String(l.x)},${String(l.y)}`,mid:d};}(t,a);l.push({c:e,d:i.d,mid:i.mid,label:T(t,a),dataChannel:function(e,t){let n=[e.type,t.type].includes("chat"),l="chat"===e.type?eS.has(t.type):eS.has(e.type);return n&&l;}(t,a)});}return l;}(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,i=e.y-l.y,r=Math.abs(a)>=Math.abs(i),s=r?{x:a>=0?n.x+n.w:n.x,y:l.y}:{x:l.x,y:i>=0?n.y+n.h:n.y},o=Math.max(40,Math.abs(r?a:i)/2),c=r?{x:s.x+(a>=0?o:-o),y:s.y}:{x:s.x,y:s.y+(i>=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,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"conn-layer",children:(0,a.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,a.jsxs)("g",{children:[(0,a.jsx)("path",{id:n,className:"conn-path",d:e.d,"data-active":t?"true":void 0,"data-intensity":t?h:void 0,"data-reduced-motion":t&&o?"true":void 0}),t&&!o?(0,a.jsx)(eI,{pathId:n,intensity:h}):null]},e.c.id);}),null!==g?(0,a.jsx)("path",{className:"conn-path conn-temp",d:g.d}):null,null!==g?(0,a.jsx)("circle",{className:"conn-dot",cx:g.ex,cy:g.ey,r:"5"}):null]})}),(0,a.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=d===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,a.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(),r.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,a.jsx)(N.F.git,{size:11})," ",(0,a.jsx)("span",{children:i?"Remove?":e.label}),l&&!i?(0,a.jsx)("span",{className:"conn-flow-tag","aria-hidden":"true",children:"heavy"===h?"⇶":"→"}):null]},e.c.id);})})]});}let e$=["n","s","e","w","ne","nw","se","sw"],eE=["t","r","b","l"];function eA(e){let{icon:t,label:n}=e,l=N.F[t];return(0,a.jsxs)("div",{className:"too-small",children:[(0,a.jsx)("div",{className:"ts-ico",children:(0,a.jsx)(l,{size:28})}),(0,a.jsxs)("div",{className:"ts-title",children:["Too small to show ",n]}),(0,a.jsx)("div",{className:"ts-sub",children:"Enlarge the window or zoom its content out"}),(0,a.jsx)("div",{className:"ts-arrow","aria-hidden":"true",children:(0,a.jsx)("svg",{width:"22",height:"22",viewBox:"0 0 22 22",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:(0,a.jsx)("path",{d:"M8 8l8 8M16 11v5h-5"})})})]});}function eF(e){var t,n,l,r,s,o;let{win:c,top:d,connState:u,view:p,api:m,wsRef:h}=e,f=E[c.type],g=void 0!==(s=c.type)&&((null!=(o=A[s])?o:[]).length>0||Object.values(A).some(e=>e.includes(s))),v=N.F[f.icon],[b,x]=(0,i.useState)(!1),y=(0,i.useRef)(null),j=(0,i.useRef)(null),w=null!=(t=c.zoom)?t:1,k="chat"===c.type||"agents"===c.type||"quality"===c.type||"editor"===c.type||"promptEnhancer"===c.type,S="agents"===c.type||"quality"===c.type||"editor"===c.type||"promptEnhancer"===c.type,C="quality"===c.type||"editor"===c.type,I=k?m.linkedFilesRoot(c.id):null,R=S?null==(n=m.linkedFilesContext(c.id))?void 0:n.activeFilePath:void 0,$="quality"===c.type||"promptEnhancer"===c.type?m.linkedAllFilesRoots(c.id):null!==I?[I]:[],F=C?m.linkedConnectorCapsuleIds(c.id):[],T=C?m.linkedConnectorCapsuleSetIds(c.id):[],D="quality"===c.type?m.linkedFigmaSnapshotRunIds(c.id):[],P="quality"===c.type?null==(l=m.linkedFigmaSnapshotSources)?void 0:l.call(m,c.id):void 0,q="quality"===c.type?null==(r=m.linkedImageSources)?void 0:r.call(m,c.id):void 0,L=c.w/w,z=c.h/w,O=(0,i.useCallback)(e=>{m.update(c.id,{cfg:{...c.cfg,...e}});},[m,c.cfg,c.id]),K=(0,i.useCallback)((e,t)=>m.add(e,t),[m]),W=(0,i.useCallback)(e=>m.openEditorFile(e),[m]),{mode:B,node:_}=function(e,t,n,l,i,r,s,o,c,d,u,p,m,h,f,g){let v=E[t];if("chat"===t){let t=n<520,a=n<430;return{mode:a?"mini":"full",node:v.render(i,{windowId:e,mini:a,minimalChat:n<360||l<320,compact:n<640,controlsNarrow:t,barCompact:n<520,workflowCompact:t,linkedRoot:r,linkedFilePath:s,linkedRoots:o,linkedCapsuleIds:c,linkedCapsuleSetIds:d,linkedFigmaSnapshotRunIds:u,linkedFigmaSnapshotSources:p,linkedImageSources:m,updateCfg:h,openWindow:f,openEditorFile:g})};}return n<v.tiny.w||l<v.tiny.h?{mode:"tiny",node:(0,a.jsx)(eA,{icon:v.icon,label:v.title})}:{mode:"full",node:v.render(i,{windowId:e,linkedRoot:r,linkedFilePath:s,linkedRoots:o,linkedCapsuleIds:c,linkedCapsuleSetIds:d,linkedFigmaSnapshotRunIds:u,linkedFigmaSnapshotSources:p,linkedImageSources:m,updateCfg:h,openWindow:f,openEditorFile:g})};}(c.id,c.type,L,z,c.cfg,I,R,$,F,T,D,P,q,O,K,W),J=(0,i.useCallback)(e=>m.update(c.id,{zoom:Math.max(.5,Math.min(2,Math.round(10*e)/10))}),[m,c.id]);(0,i.useEffect)(()=>{var e,t;if(e=c.type,t=c.cfg,"figmaView"!==e||"string"!=typeof t.selectedScreenIdsJson||!(t.selectedScreenIdsJson.length>0)||c.max||"full"!==B)return;let n=y.current;if(null===n)return;let l=null,a=()=>{l=null;let e=n.scrollHeight-n.clientHeight;if(e<=8)return;let t=Math.ceil(c.h+e);t<=c.h+8||m.update(c.id,{h:t});},i=()=>{null===l&&(l="function"==typeof window.requestAnimationFrame?window.requestAnimationFrame(a):window.setTimeout(a,0));};i();let r="u">typeof ResizeObserver?new ResizeObserver(i):null;null==r||r.observe(n);let s=n.firstElementChild;return null!==s&&(null==r||r.observe(s)),()=>{null!==l&&("function"==typeof window.cancelAnimationFrame?window.cancelAnimationFrame(l):window.clearTimeout(l)),null==r||r.disconnect();};},[m,B,c.cfg,c.h,c.id,c.max,c.type]),(0,i.useEffect)(()=>()=>{var e;null==(e=j.current)||e.call(j),j.current=null;},[]);let H=(0,i.useCallback)(e=>{V(e)?window.setTimeout(()=>m.focus(c.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(()=>m.focus(c.id),0):m.focus(c.id);},[m,c.id]),Y=(0,i.useCallback)(e=>{var t,n,l,a,i,r,s,o;let d,f,g,v,b;if(!(U(o=e)||1===o.button)||"valid"===u)return;e.preventDefault(),H(e.target);let y=h.current;if(null===y)return;let j=(i=y.getBoundingClientRect(),{z:d=p.zoom,vpx0:-p.x/d,vpy0:-p.y/d,vpw:i.width/d,vph:i.height/d,toWX:e=>(e-i.left-p.x)/d,toWY:e=>(e-i.top-p.y)/d}),w=c.max,k=w?null!=(t=null==(l=c.prev)?void 0:l.w)?t:480:c.w,N=w?null!=(n=null==(a=c.prev)?void 0:a.h)?n:360:c.h,S=w?k/2:j.toWX(e.clientX)-c.x,C=w?18:j.toWY(e.clientY)-c.y;w&&m.update(c.id,{max:!1,w:k,h:N}),x(!0),r={winId:c.id,offX:S,offY:C,W:k},s=()=>x(!1),f=30/j.z,g=e=>{let t,n,l,a,i=j.toWX(e.clientX),s=j.toWY(e.clientY),o=i-r.offX,c=s-r.offY;o=Math.max(j.vpx0-(r.W-120),Math.min(j.vpx0+j.vpw-120,o)),c=Math.max(j.vpy0,Math.min(j.vpy0+j.vph-38,c)),m.setSnap((t=i-j.vpx0<f,n=j.vpx0+j.vpw-i<f,l=s-j.vpy0<f,a=j.vpy0+j.vph-s<f,l&&t?"tl":l&&n?"tr":a&&t?"bl":a&&n?"br":t?"left":n?"right":l?"maxi":null)),m.update(r.winId,{x:o,y:c});},v=()=>{window.removeEventListener("pointermove",g),window.removeEventListener("pointerup",v),window.removeEventListener("pointercancel",v),m.commitSnap(r.winId),b(),null==s||s();},b=G(),window.addEventListener("pointermove",g),window.addEventListener("pointerup",v),window.addEventListener("pointercancel",v);},[m,c.id,c.x,c.y,c.w,c.h,c.max,c.prev,p,h,u,H]),X=(0,i.useCallback)(e=>t=>{var n;if(!U(t))return;t.preventDefault(),t.stopPropagation(),null==(n=j.current)||n.call(j),j.current=null,m.focus(c.id);let l={x:c.x,y:c.y,w:c.w,h:c.h},a=l,i=t.clientX,r=t.clientY,s=p.zoom,o=document.body.style.cursor,d=!0,u=()=>{d&&(d=!1,window.removeEventListener("pointermove",f),window.removeEventListener("pointerup",h),window.removeEventListener("pointercancel",h),window.removeEventListener("blur",h),document.body.style.cursor=o,j.current===u&&(j.current=null));},h=()=>{u();},f=t=>{var n;if(!d)return;if(0===t.buttons)return void u();let o=function(e,t,n,l,a){let{x:i,y:r,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,i=e.x+n),t.includes("n")&&(o=e.h-l,r=e.y+l);let c=E[a].min,d=c.w>0?c.w:240,u=c.h>0?c.h:150;return s<d&&(t.includes("w")&&(i-=d-s),s=d),o<u&&(t.includes("n")&&(r-=u-o),o=u),{x:i,y:r,w:s,h:o};}(l,e,(t.clientX-i)/s,(t.clientY-r)/s,c.type);((n=a).x!==o.x||n.y!==o.y||n.w!==o.w||n.h!==o.h)&&(a=o,m.update(c.id,{...o,max:!1}));};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",f),window.addEventListener("pointerup",h),window.addEventListener("pointercancel",h),window.addEventListener("blur",h),j.current=u;},[m,c.id,c.x,c.y,c.w,c.h,c.type,p.zoom]),Q=(0,i.useCallback)((e,t)=>{let n=e.getBoundingClientRect();m.startConnect(c.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()});},[m,c.id]),Z=(0,i.useCallback)(e=>{U(e)&&(e.preventDefault(),e.stopPropagation(),Q(e.currentTarget,e));},[Q]),ee=(0,i.useCallback)(e=>{if("Enter"===e.key||" "===e.key||"Spacebar"===e.key){if("valid"===u)return void m.confirmConnect(c.id,{preventDefault:()=>e.preventDefault(),stopPropagation:()=>e.stopPropagation()});e.preventDefault(),e.stopPropagation(),Q(e.currentTarget,e);}},[Q,u,m,c.id]),et=(0,i.useCallback)(()=>{m.close(c.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});});},[m,c.id]),en=(0,i.useCallback)(()=>{m.minimize(c.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});});},[m,c.id]),el="full"===B?M(c.type,c.cfg):null,ea="full"===B&&L>=340,ei="tiny"===B?{}:{zoom:w},er={left:c.x,top:c.y,width:c.w,height:c.h,zIndex:c.z};return(0,a.jsxs)("section",{className:"window","aria-label":null!==el?`${f.title} — ${el}`:f.title,"aria-roledescription":"window","data-top":d?"true":"false","data-max":c.max?"true":"false","data-conn":null!=u?u:void 0,"data-dragging":b?"true":void 0,"data-window-id":c.id,style:er,tabIndex:-1,onPointerDown:e=>{"valid"===u&&m.confirmConnect(c.id,e),H(e.target);},onFocusCapture:()=>{d||window.setTimeout(()=>m.focus(c.id),0);},children:[(0,a.jsxs)("header",{className:"win-head",onPointerDown:Y,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)&&m.maximize(c.id);},children:[(0,a.jsx)("span",{className:"win-ico",style:{color:!0===f.accent?"var(--accent)":"var(--fg-muted)"},children:(0,a.jsx)(v,{size:14})}),(0,a.jsx)("span",{className:"win-title",children:f.title}),null!==el?(0,a.jsx)("span",{className:"win-sub mono",title:el,children:(0,a.jsx)("span",{className:"win-sub-text",children:el})}):null,(0,a.jsx)("span",{className:"spacer"}),ea?(0,a.jsxs)("div",{className:"win-zoom",children:[(0,a.jsx)("button",{type:"button",className:"win-zbtn ui-tip","data-tip":"Zoom content out","aria-label":`Zoom ${f.title} content out`,disabled:w<=.5,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>{e.stopPropagation();},onClick:()=>J(w-.1),children:(0,a.jsx)(N.F.zoomOut,{size:13})}),(0,a.jsxs)("button",{type:"button",className:"win-zpct ui-tip","data-tip":"Reset content zoom to 100%","aria-label":`${String(Math.round(100*w))}% — reset ${f.title} content zoom`,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>{e.stopPropagation();},onClick:()=>m.update(c.id,{zoom:1}),children:[Math.round(100*w),"%"]}),(0,a.jsx)("button",{type:"button",className:"win-zbtn ui-tip","data-tip":"Zoom content in","aria-label":`Zoom ${f.title} content in`,disabled:w>=2,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>{e.stopPropagation();},onClick:()=>J(w+.1),children:(0,a.jsx)(N.F.zoomIn,{size:13})})]}):null,(0,a.jsxs)("div",{className:"win-traffic",role:"group","aria-label":`${f.title} window controls`,children:[(0,a.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:en,children:(0,a.jsx)(N.F.minimize,{size:17})}),(0,a.jsx)("button",{type:"button",className:"win-traffic-btn win-traffic-maximize ui-tip","data-tip":c.max?"Restore":"Full screen","aria-label":c.max?`Restore ${f.title} window`:`Full screen ${f.title} window`,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>{e.stopPropagation();},onClick:()=>m.maximize(c.id),children:c.max?(0,a.jsx)(N.F.restore,{size:17}):(0,a.jsx)(N.F.maximize,{size:17})}),(0,a.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:et,children:(0,a.jsx)(N.F.close,{size:17})})]})]}),(0,a.jsx)("div",{ref:y,className:"win-body","data-mode":B,style:ei,children:_}),c.max?null:e$.map(e=>(0,a.jsx)("div",{className:`wz wz-${e}`,onPointerDown:X(e)},e)),!c.max&&g?eE.map(e=>(0,a.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:Z,onKeyDown:ee},`p${e}`)):null]});}let eT=[/\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-----/],eD=/\b(?:\d[ -]?){13,19}\b/g;n(63680);let eM={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"},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"}},eP=["apikey","accesskey","clientsecret","credential","password","privatekey","secret","token"],eq=["api_key=","apikey=","client_secret=","clientsecret=","credential=","authorization:","password=","secret=","token="],eL=[".env",".env.local",".env.development",".env.test",".env.production"],ez={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 eO(e){return"number"==typeof e&&Number.isFinite(e);}function eK(e){return"object"==typeof e&&null!==e&&!Array.isArray(e);}function eW(e){let t=e.trim();if(0===t.length)return!1;let n=t.toLowerCase();return function(e){for(let t of eT)if(t.test(e))return!0;for(let t of e.matchAll(eD)){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 i=n+t.length;i<e.length;i+=1){var a;if(0===(null!=(a=e[i])?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)||eq.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:"",i=null!=(l=t[e+1])?l:"";if(eL.includes(a)||".npmrc"===a||"credentials.json"===a||".aws"===a&&"credentials"===i||".ssh"===a&&i.startsWith("id_"))return!0;}return!1;}(t);}function eB(e){if(0===e.length||e.length>256||e.startsWith(".")||e.trim()!==e||eW(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 eU(e){if(0===e.length||e.length>256||e.trim()!==e||eW(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,i=46===e||58===e||95===e||45===e;if(!n&&!l&&!a&&!i)return!1;}return!0;}function e_(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||eW(e)||t.includes(e))&&(t.push(e),t.length>=64))break;}return t.length>0?t:void 0;}function eV(e){let t=[];for(let n of e){let e=function(e){var t;if(!eK(e)||!("string"==typeof(t=e.type)&&t in E))return null;let n=e.type;if("transient"===eM[n].persistence||"string"!=typeof e.id||!eO(e.x)||!eO(e.y)||!eO(e.w)||!eO(e.h)||!eO(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(!eK(t)||"durable.config"===eM[e].persistence)return{};let a=new Set([...(null!=(n=E[e].config)?n:[]).map(e=>e.key),...(null!=(l=ez[e])?l:[])]),i={};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 e_(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=eK(n.panes)?n.panes:{},t={};for(let[n,a]of Object.entries(e)){var l;if(!eK(a))continue;let e="string"==typeof a.activeFile?a.activeFile.trim():"",i=e_(a.openFiles),r=null!=(l=e_(a.tabOrder))?l:i;if(void 0===i&&0===e.length)continue;let s=null!=i?i:e_([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!=r?r:s});}let a=new Set(Object.keys(t)),i=e=>{if(!eK(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=i(e.first),n=i(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;},r=i(n.tree),s=Object.keys(t)[0];if(null===r||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:r,panes:t,sidebarWidth:c,sidebarCollapsed:!0===n.sidebarCollapsed});}let a=Array.isArray(n.panes)?n.panes.slice(0,2):[],i=[];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=e_(t.openFiles);if(n.length>512||eW(n))continue;let a=null!=l?l:n.length>0?e_([n]):void 0;void 0!==a&&i.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===i.length)return;let r="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&&i.some(e=>e.id===n.activePaneId)?n.activePaneId:i[0].id;return JSON.stringify({version:1,panes:i,activePaneId:c,direction:r,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 eB(t)?t:void 0;if("screenId"===e)return eU(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(!eU(e))return;n.push(e);}return JSON.stringify(n);}if("selectedScreenName"===e){if(t.length>256||eW(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),eP.some(e=>l.includes(e))))return;if("string"!=typeof n)return n;let a=eM[e].persistence;return"evidence-reference"===a?eB(n)?n:void 0:eW(n)?"durable.ui"===a?"[REDACTED]":void 0:n;}(e,n,l);void 0!==t&&(i[n]=t);}return i;}(n,e.cfg),max:e.max},a=function(e){if(eK(e)&&eO(e.x)&&eO(e.y)&&eO(e.w)&&eO(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}:{}),...(eO(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 eJ(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,i="string"==typeof t.boundRelativePath&&t.boundRelativePath.length>0,r="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,...(r?{boundChatWindowId:t.boundChatWindowId}:{}),...(e?{boundRoot:t.boundRoot}:{}),...(a?{boundScopeKind:t.boundScopeKind}:{}),...(i?{boundRelativePath:t.boundRelativePath}:{}),...(s?{boundConnectorKind:t.boundConnectorKind,boundConnectorId:t.boundConnectorId}:{})});}return l;}function eH(e){return"object"==typeof e&&null!==e&&!Array.isArray(e);}function eY(e,t,n){return Math.min(n,Math.max(t,e));}function eX(e){return eY(Math.round(e),15,85);}function eG(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 eQ(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 eZ(e,t,n){var l;let a=eQ(t,n);return{id:e,openFiles:a,activeFile:t.length>0?t:null!=(l=a[0])?l:"",tabOrder:a};}function e0(e,t){if(!eH(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=eZ(n,l,eQ(l,eG(e.openFiles),eG(e.tabOrder)));return a.openFiles.length>0||a.activeFile.length>0?a:null;}function e1(e){return"column"===e?"column":"row";}function e2(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return"pane"===e.type?t.push(e.paneId):(e2(e.first,t),e2(e.second,t)),t;}function e4(e,t){return"number"==typeof e.sidebarWidth&&Number.isFinite(e.sidebarWidth)?eY(e.sidebarWidth,t.minSidebarWidth,t.maxSidebarWidth):t.defaultSidebarWidth;}function e3(e,t,n){return"string"==typeof e.activePaneId&&void 0!==t[e.activePaneId]?e.activePaneId:n;}function e5(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(eH(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 i=function(e){if(!eH(e))return{};let t={};for(let[n,l]of Object.entries(e)){let e=e0(l,n);null!==e&&(t[e.id]=e);}return t;}(t.panes),r=Object.keys(i)[0];if(void 0===r)return null;let s=null!=(l=function e(t,n){var l;return eH(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 i="string"==typeof t.id&&t.id.length>0?t.id:"split-1",r="number"==typeof t.ratio&&Number.isFinite(t.ratio)?t.ratio:50;return{type:"split",id:i,direction:e1(t.direction),ratio:eX(r),first:l,second:a};}(t,n):null;}(t.tree,i))?l:{type:"pane",paneId:r},o=function(e,t){let n={};for(let l of new Set(e2(e))){let e=t[l];void 0!==e&&(n[l]=e);}return n;}(s,i);return{schemaVersion:2,root:e,activePaneId:e3(t,o,null!=(a=e2(s)[0])?a:r),tree:s,panes:o,sidebarWidth:e4(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)=>e0(e,`pane-${String(t+1)}`)).filter(e=>null!==e):[];if(0===a.length)return null;let i={};for(let e of a)i[e.id]=e;let r=a[0];if(void 0===r)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)?eX(n.splitRatio):50;return{type:"split",id:"split-1",direction:e1(n.direction),ratio:l,first:{type:"pane",paneId:e.id},second:{type:"pane",paneId:t.id}};}(r,a[1],t);return{schemaVersion:2,root:e,activePaneId:e3(t,i,r.id),tree:s,panes:i,sidebarWidth:e4(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=eZ("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 e6(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 e8(e){return e2(e.tree);}function e7(e){return e8(e).map(t=>e.panes[t]).filter(e=>void 0!==e);}function e9(e){var t,n;return null!=(t=null!=(n=e.panes[e.activePaneId])?n:e7(e)[0])?t:eZ("pane-1","",[]);}function te(e,t,n){let l=e.panes[t];return void 0===l?e:{...e,panes:{...e.panes,[t]:n(l)}};}function tt(e,t){return e.filter(e=>e!==t);}function tn(e,t,n){let l=tt(e,t),a=void 0===n?l.length:eY(n,0,l.length);return[...l.slice(0,a),t,...l.slice(a)];}function tl(e,t,n){var l;let a=eQ(n,t);return{...e,openFiles:a,tabOrder:a,activeFile:n.length>0?n:null!=(l=a[0])?l:""};}function ta(e,t,n,l,a){let i=e.panes[t];if(void 0===i)return e;let r=null!=l?l:i.activeFile;if(0===r.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=eZ(s,r,[r]),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 ti(e,t){var n;if(void 0===e.panes[t]||e8(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 i=e.activePaneId===t&&null!=(n=e2(l)[0])?n:e.activePaneId;return{...e,tree:l,panes:a,activePaneId:i};}function tr(e,t,n){var l,a,i;let r=e.panes[t];if(!(null==r?void 0:r.openFiles.includes(n)))return e;let s=r.tabOrder.indexOf(n),o=tt(r.openFiles,n);if(0===o.length)return e8(e).length>1?ti(e,t):te(e,t,e=>tl(e,[],""));let c=r.activeFile===n?null!=(l=null!=(a=null!=(i=o[s])?i:o[s-1])?a:o[0])?l:"":r.activeFile;return te(e,t,e=>tl(e,o,c));}function ts(e,t,n,l,a){if(t===n)return te(e,n,e=>tl(e,tn(e.tabOrder,l,a),l));let i=e.panes[t],r=e.panes[n];if(void 0===i||void 0===r||!i.openFiles.includes(l))return e;let s=tr(e,t,l);return void 0===s.panes[n]?s:{...(s=te(s,n,e=>tl(e,tn(e.tabOrder,l,a),l))),activePaneId:n};}let to=new Set(["open-file","select-file","close-tab","reorder-tab"]),tc=new Set(["close-pane","move-tab","drop-tab","split-pane"]);function td(e,t){if(to.has(t.type)){switch(t.type){case"open-file":return te(e,t.paneId,e=>tl(e,eQ(t.file,e.openFiles),t.file));case"select-file":return te({...e,activePaneId:t.paneId},t.paneId,e=>e.openFiles.includes(t.file)?tl(e,e.openFiles,t.file):e);case"close-tab":return tr(e,t.paneId,t.file);case"reorder-tab":return te(e,t.paneId,e=>e.openFiles.includes(t.file)?tl(e,tn(e.tabOrder,t.file,t.targetIndex),t.file):e);}return;}return tc.has(t.type)?function(e,t){switch(t.type){case"close-pane":return ti(e,t.paneId);case"move-tab":return ts(e,t.fromPaneId,t.toPaneId,t.file,t.targetIndex);case"drop-tab":var n;return"center"===(n=t.intent).zone?ts(e,n.fromPaneId,n.toPaneId,n.file,n.targetIndex):ta(ts(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 ta(e,t.paneId,t.direction,t.file,!1);}}(e,t):function(e,t){var n,l,a;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?eX(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!=(n=t.width)?n:e.sidebarWidth,sidebarCollapsed:null!=(l=t.collapsed)?l:e.sidebarCollapsed};case"replace-root":let i;return i=eZ("pane-1","",[]),{schemaVersion:2,root:t.root,activePaneId:i.id,tree:{type:"pane",paneId:i.id},panes:{[i.id]:i},sidebarWidth:null!=(a=t.sidebarWidth)?a:e.sidebarWidth,sidebarCollapsed:!1};}}(e,t);}function tu(e){let t=[];for(let n of e7(e))for(let e of n.openFiles)e.length>0&&!t.includes(e)&&t.push(e);return t;}function tp(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 tm(e){return e.trim().replace(/\\/gu,"/").replace(/\/+$/u,"");}function th(e){return e.trim().replace(/\\/gu,"/").replace(/^\/+/u,"").replace(/\/+$/u,"");}function tf(e,t){let n=e[t];return"string"==typeof n?n:void 0;}function tg(e){let{prev:t,...n}=e;return n;}function tv(e,t,n){return e.some(e=>e.a===t&&e.b===n||e.a===n&&e.b===t);}function tb(e,t){return(null==e?void 0:e.type)==="chat"?e.id:(null==t?void 0:t.type)==="chat"?t.id:null;}function tx(e){return e.length>0&&(e.startsWith("/")||/^[A-Za-z]:[/\\]/u.test(e));}function ty(e){return /^[A-Za-z]:[/\\]?$/u.test(e)?e.replace(/\\/gu,"/"):e.replace(/\\/gu,"/").replace(/\/+$/u,"");}function tj(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&&tx(l)?l:null;}function tw(e){return e.replace(/\\/gu,"/").replace(/^\/+/u,"").replace(/\/+$/u,"");}function tk(e,t){return void 0!==e.root&&void 0!==t.root&&ty(e.root)===ty(t.root)&&e.kind===t.kind&&e.relativePaths.length===t.relativePaths.length&&e.relativePaths.every((e,n)=>{var l;return tw(e)===tw(null!=(l=t.relativePaths[n])?l:"");});}function tN(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 i=tj(l);if(null===i)return null;let r=l.cfg.activeFilePath;if("string"==typeof r&&r.length>0)return{kind:"files",relativePaths:[tw(r)],root:ty(i),connectedAtMs:n};let s=l.cfg.activeDirectoryPath;return"string"==typeof s&&s.length>0?{kind:"directory",relativePaths:[tw(s)],root:ty(i),connectedAtMs:n}:{kind:"workspace-root",relativePaths:[],root:ty(i),connectedAtMs:n};}function tS(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:[tw(e.boundRelativePath)],root:ty(e.boundRoot),connectedAtMs:t}:"files"===e.boundScopeKind?"string"!=typeof e.boundRelativePath||0===e.boundRelativePath.length?null:{kind:"files",relativePaths:[tw(e.boundRelativePath)],root:ty(e.boundRoot),connectedAtMs:t}:{kind:"workspace-root",relativePaths:[],root:ty(e.boundRoot),connectedAtMs:t};}function tC(e){return Math.max(e.maxConnectedSources,e.maxLocalKnowledgeSources);}function tI(e,t){return e.filter(e=>!tk(e,t));}function tR(e){var t;return null!=(t=e.connectedScopes)?t:void 0!==e.connectedScope?[e.connectedScope]:[];}function t$(e){var t;return null!=(t=e.localKnowledgeScopes)?t:void 0!==e.localKnowledgeScope?[e.localKnowledgeScope]:[];}function tE(e){return"capsule"===e.kind?`capsule:${e.capsuleId}`:`set:${e.capsuleSetId}`;}function tA(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 tF(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,i=n.cfg.selectedId;if("string"!=typeof a||"string"!=typeof i)return null;let r=i.trim();return 0===r.length?null:"capsule"===a?{kind:"capsule",capsuleId:r,connectedAtMs:Date.now()}:"capsule-set"===a?{kind:"capsule-set",capsuleSetId:r,connectedAtMs:Date.now()}:null;}let tT="keiko.workspace.v4",tD="keiko.conns.v1",tM="keiko.view";function tP(){try{let e=window.localStorage.getItem(tM);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 tq(e){return Math.max(.3,Math.min(2.5,e));}function tL(e){return Math.max(.5,Math.min(2,Math.round(10*e)/10));}function tz(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 tO(e,t){try{window.localStorage.setItem(e,JSON.stringify(t));}catch{}}function tK(e){let t=e.deltaMode===WheelEvent.DOM_DELTA_LINE?16:2===e.deltaMode?800:1;return{x:e.deltaX*t,y:e.deltaY*t};}let tW={Equal:"=",NumpadAdd:"+",Minus:"-",NumpadSubtract:"-",Digit0:"0",Numpad0:"0"},tB="application/x-keiko-local-knowledge-connector",tU="keiko:local-knowledge-connector-drop";function t_(e){if(!Array.from(e.types).includes(tB))return null;try{let t=JSON.parse(e.getData(tB));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 tV="application/x-keiko-figma-view",tJ="keiko:figma-view-drop";function tH(e){return"string"==typeof e&&e.trim().length>0?e.trim():null;}function tY(e){if(!Array.from(e.types).includes(tV))return null;try{let t=JSON.parse(e.getData(tV));if("object"!=typeof t||null===t)return null;let n=tH(t.snapshotRunId),l=tH(t.screenId),a=tH(t.name);if(null===n||null===l||null===a)return null;return{snapshotRunId:n,screenId:l,name:a};}catch{return null;}}let tX="application/x-keiko-figma-json",tG="keiko:figma-json-drop";function tQ(e){return"string"==typeof e&&e.trim().length>0?e.trim():null;}function tZ(e){if(!Array.from(e.types).includes(tX))return null;try{let t=JSON.parse(e.getData(tX));if("object"!=typeof t||null===t)return null;let n=tQ(t.snapshotRunId),l=tQ(t.screenId),a=tQ(t.name);if(null===n||null===l||null===a)return null;let i=tQ(t.sourceWindowId);return{snapshotRunId:n,screenId:l,name:a,...(null!==i?{sourceWindowId:i}:{})};}catch{return null;}}let t0="application/x-keiko-figma-image",t1="keiko:figma-image-drop";function t2(e){return"string"==typeof e&&e.trim().length>0?e.trim():null;}function t4(e){if(!Array.from(e.types).includes(t0))return null;try{let t=JSON.parse(e.getData(t0));if("object"!=typeof t||null===t)return null;let n=t2(t.snapshotRunId),l=t2(t.screenId),a=t2(t.name),i=t2(t.imageSrc);if(null===n||null===l||null===a||null===i||!/^\/api\/figma\/snapshots\/[^/?#]+\/screens\/\d+\/image$/u.test(i))return null;let r=t2(t.sourceWindowId);return{snapshotRunId:n,screenId:l,name:a,imageSrc:i,...(null!==r?{sourceWindowId:r}:{})};}catch{return null;}}let t3={w:260,h:220},t5={w:360,h:360},t6={w:520,h:540},t8={w:560,h:420};function t7(e){let{clientX:t,clientY:n,rect:l,view:a,size:i=t3}=e;return{x:Math.round((t-l.left-a.x)/a.zoom-i.w/2),y:Math.round((n-l.top-a.y)/a.zoom-28)};}function t9(e,t){let n=e+t;return e<1&&n>1||e>1&&n<1?1:n;}function ne(e,t,n){var l;t.preventDefault();let a=t.currentTarget;null==(l=a.setPointerCapture)||l.call(a,t.pointerId);let i=t.clientX,r=t.clientY,s=G();n(!0);let o=t=>{e(t.clientX-i,t.clientY-r),i=t.clientX,r=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 nt(e){let{wins:t,connecting:n,conns:l}=e,[r,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?E[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: ${T(n,a)}`:"Connected");}else s("Connection cancelled");},[n,l,t]),(0,a.jsx)("div",{className:"sr-only","aria-live":"polite",children:r});}function nn(e){var t,n;let{ws:l,wsRef:r,openPalette:s,palette:o}=e,{wins:c,view:d,snapPrev:u,conns:p,connecting:m,api:h}=l,[f,g]=(0,i.useState)(!1),[v,b]=(0,i.useState)(!1),x=(0,i.useRef)(!1),y=(0,i.useMemo)(()=>null===c?null:c.filter(e=>!0!==e.minimized),[c]),j=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;}(y),w=null!==m&&null!==y&&null!=(t=y.find(e=>e.id===m.from))?t:null;(0,i.useEffect)(()=>{let e=e=>{x.current=e,b(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(),x.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 k=(0,i.useMemo)(()=>({backgroundSize:`${String(22*d.zoom)}px ${String(22*d.zoom)}px`,backgroundPosition:`${String(d.x)}px ${String(d.y)}px`}),[d]),S=(0,i.useMemo)(()=>({transform:`translate(${String(d.x/d.zoom)}px, ${String(d.y/d.zoom)}px)`,transformOrigin:"0 0",zoom:d.zoom}),[d]),C=(0,i.useCallback)((e,t,n,l)=>{let a=h.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&&h.update(a,{...t7({clientX:t,clientY:n,rect:l,view:d}),...t3});},[h,d]),I=(0,i.useCallback)((e,t,n,l)=>{let a=h.add("figmaView",{snapshotRunId:e.snapshotRunId,selectedScreenIdsJson:JSON.stringify([e.screenId]),selectedScreenName:e.name});null!==a&&h.update(a,{...t7({clientX:t,clientY:n,rect:l,view:d,size:t5}),...t5});},[h,d]),R=(0,i.useCallback)(e=>{if(null===c)return[];let t=new Map(c.map(e=>[e.id,e])),n=[];for(let l of p){let a=l.a===e?l.b:l.b===e?l.a:null;if(null===a)continue;let i=t.get(a);(null==i?void 0:i.type)==="quality"&&n.push({connId:l.id,qualityId:i.id});}return n;},[p,c]),$=(0,i.useCallback)((e,t,n,l)=>{let a=h.add("figmaJson",{snapshotRunId:e.snapshotRunId,screenId:e.screenId,selectedScreenIdsJson:JSON.stringify([e.screenId]),selectedScreenName:e.name});if(null===a||(h.update(a,{...t7({clientX:t,clientY:n,rect:l,view:d,size:t6}),...t6}),void 0===e.sourceWindowId))return;let i=R(e.sourceWindowId);if(0!==i.length){for(let e of i)h.removeConn(e.connId);window.setTimeout(()=>{for(let e of i)h.connect(a,e.qualityId);},0);}},[h,R,d]),E=(0,i.useCallback)((e,t,n,l)=>{let a=h.add("figmaImage",{snapshotRunId:e.snapshotRunId,screenId:e.screenId,selectedScreenName:e.name,imageSrc:e.imageSrc});if(null===a||(h.update(a,{...t7({clientX:t,clientY:n,rect:l,view:d,size:t8}),...t8}),void 0===e.sourceWindowId))return;let i=R(e.sourceWindowId);if(0!==i.length){for(let e of i)h.removeConn(e.connId);window.setTimeout(()=>{for(let e of i)h.connect(a,e.qualityId);},0);}},[h,R,d]);(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=r.current)?void 0:t.getBoundingClientRect();if(void 0===n)return;let{clientX:l,clientY:a,payload:i}=e.detail;l<n.left||l>n.right||a<n.top||a>n.bottom||C(i,l,a,n);};return window.addEventListener(tU,e),()=>{window.removeEventListener(tU,e);};},[C,r]),(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=r.current)?void 0:t.getBoundingClientRect();if(void 0===n)return;let{clientX:l,clientY:a,payload:i}=e.detail;l<n.left||l>n.right||a<n.top||a>n.bottom||I(i,l,a,n);};return window.addEventListener(tJ,e),()=>{window.removeEventListener(tJ,e);};},[I,r]),(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=r.current)?void 0:t.getBoundingClientRect();if(void 0===n)return;let{clientX:l,clientY:a,payload:i}=e.detail;l<n.left||l>n.right||a<n.top||a>n.bottom||$(i,l,a,n);};return window.addEventListener(tG,e),()=>{window.removeEventListener(tG,e);};},[$,r]),(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=r.current)?void 0:t.getBoundingClientRect();if(void 0===n)return;let{clientX:l,clientY:a,payload:i}=e.detail;l<n.left||l>n.right||a<n.top||a>n.bottom||E(i,l,a,n);};return window.addEventListener(t1,e),()=>{window.removeEventListener(t1,e);};},[E,r]);let A=null!==c&&0===c.length,T=null!=(n=null==c?void 0:c.some(e=>e.max))&&n;return(0,a.jsxs)("main",{className:"workspace",ref:r,"aria-label":"Workspace surface",tabIndex:0,"data-window-maxed":T?"true":void 0,"data-canvas-overlays-hidden":T?"true":"false","data-connecting":null!==m?"true":void 0,"data-panning":f?"true":void 0,"data-hand-tool":v?"true":void 0,onPointerDownCapture:e=>{if(J())return;if(x.current&&U(e)&&null===m&&!V(e.target)&&!_(e.target)){ne(h.panBy,e,g),e.stopPropagation();return;}if(0!==e.button||null===m||null===w||null===y)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===w.id)return;let n=y.find(e=>e.id===t);void 0!==n&&F(w.type,n.type)&&h.confirmConnect(n.id,e);},onPointerDown:e=>{if(!(J()||_(e.target))){var t;if(null!==m){U(e)&&h.cancelConnect();return;}(U(t=e)||1===t.button)&&ne(h.panBy,e,g);}},onKeyDown:e=>{if(e.target!==e.currentTarget)return;let t=e.shiftKey?192:48;switch(e.key){case"ArrowLeft":h.panBy(t,0);break;case"ArrowRight":h.panBy(-t,0);break;case"ArrowUp":h.panBy(0,t);break;case"ArrowDown":h.panBy(0,-t);break;default:return;}e.preventDefault();},onDragOver:e=>{(null!==t_(e.dataTransfer)||null!==tY(e.dataTransfer)||null!==tZ(e.dataTransfer)||null!==t4(e.dataTransfer))&&(e.preventDefault(),e.dataTransfer.dropEffect="copy");},onDrop:e=>{let t=t_(e.dataTransfer),n=tY(e.dataTransfer),l=tZ(e.dataTransfer),a=t4(e.dataTransfer);if(null===t&&null===n&&null===l&&null===a)return;e.preventDefault(),e.stopPropagation();let i=e.currentTarget.getBoundingClientRect();null!==t?C(t,e.clientX,e.clientY,i):null!==n?I(n,e.clientX,e.clientY,i):null!==l?$(l,e.clientX,e.clientY,i):null!==a&&E(a,e.clientX,e.clientY,i);},children:[(0,a.jsx)(eN,{}),(0,a.jsx)("div",{className:"ws-grid",style:k,"aria-hidden":"true"}),(0,a.jsx)(nt,{wins:y,connecting:m,conns:p}),null!==m?(0,a.jsx)("div",{className:"ws-connect-hint","aria-hidden":"true",children:"Click a highlighted window to connect — Esc to cancel"}):null,A?(0,a.jsx)("div",{className:"ws-empty",children:(0,a.jsx)(B,{onNewWindow:s})}):null,(0,a.jsxs)("div",{className:"ws-scene",style:S,children:[null!==u?(0,a.jsx)("div",{className:"snap-ghost",style:{left:u.x,top:u.y,width:u.w,height:u.h}}):null,null!==y?(0,a.jsx)(eR,{wins:y,conns:p,connecting:m,api:h}):null,null!==y?y.map(e=>(0,a.jsx)(eF,{win:e,top:null!==j&&e.id===j.id,connState:null===w?null:e.id===w.id?"source":F(w.type,e.type)?"valid":"invalid",view:d,api:h,wsRef:r},e.id)):null]}),(0,a.jsxs)("div",{className:"ws-zoom",children:[(0,a.jsx)("button",{type:"button",className:"ws-zoom-btn ui-tip cmp-tip-start",onClick:()=>h.zoomTo(t9(d.zoom,-.2)),disabled:d.zoom<=.3,"aria-label":"Zoom out","data-tip":"Zoom out",children:(0,a.jsx)(N.F.zoomOut,{size:15})}),(0,a.jsx)("button",{type:"button",className:"ws-zoom-btn ui-tip cmp-tip-start",onClick:h.fitView,disabled:null===y||0===y.length,"aria-label":"Fit workspace to windows","data-tip":"Fit workspace to windows",children:(0,a.jsx)(N.F.expand,{size:15})}),(0,a.jsxs)("button",{type:"button",className:"ws-zoom-pct mono ui-tip",onClick:h.resetView,"aria-label":`${String(Math.round(100*d.zoom))}% — reset`,"data-tip":"Reset",children:[Math.round(100*d.zoom),"%"]}),(0,a.jsx)("button",{type:"button",className:"ws-zoom-btn ui-tip cmp-tip-end",onClick:()=>h.zoomTo(t9(d.zoom,.2)),disabled:d.zoom>=2.5,"aria-label":"Zoom in","data-tip":"Zoom in",children:(0,a.jsx)(N.F.zoomIn,{size:15})})]}),(0,a.jsx)("button",{type:"button",className:"ws-fab ui-tip cmp-tip-end",onPointerDown:e=>e.stopPropagation(),onClick:s,"aria-label":"New window","data-tip":"New window",children:(0,a.jsx)(N.F.add,{size:20})}),T?null:null!=o?o:null]});}function nl(e){let{commands:t,onClose:n}=e,[l,r]=(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,a.jsx)("div",{className:"cmdk-overlay",onPointerDown:n,children:(0,a.jsxs)("div",{ref:u,className:"cmdk",role:"dialog","aria-modal":"true","aria-labelledby":"cmdk-title","aria-describedby":"cmdk-desc",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,a.jsx)("h2",{id:"cmdk-title",className:"sr-only",children:"Command palette"}),(0,a.jsx)("p",{id:"cmdk-desc",className:"sr-only",children:"Search commands and press Enter to run the selected action."}),(0,a.jsxs)("div",{className:"cmdk-input",children:[(0,a.jsx)(N.F.search,{size:16}),(0,a.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=>r(e.target.value)}),(0,a.jsx)("span",{className:"kbd",children:"esc"})]}),(0,a.jsx)("div",{className:"sr-only",role:"status",children:0===p.length?"No matching commands":`${String(p.length)} command${1===p.length?"":"s"}`}),(0,a.jsxs)("div",{id:"cmdk-list",role:"listbox",className:"cmdk-list",children:[0===p.length&&(0,a.jsx)("div",{className:"cmdk-empty",children:"No matching commands"}),p.map((e,t)=>{var n,l;let i;return(0,a.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,a.jsx)("span",{className:"cmdk-ico",children:(n=e.icon,i=null!=(l=N.F[n])?l:N.F.spark,(0,a.jsx)(i,{size:16}))}),(0,a.jsx)("span",{className:"cmdk-label",children:e.label}),(0,a.jsx)("span",{className:"spacer"}),void 0!==e.shortcut&&(0,a.jsx)("span",{className:"kbd",children:e.shortcut}),void 0!==e.group&&(0,a.jsx)("span",{className:"cmdk-group mono",children:e.group})]},e.id);})]})]})});}var na=n(97509);function ni(e){return Array.from(new Set(e.split(/[\n,]/u).map(e=>e.trim()).filter(e=>e.length>0)));}function nr(e){let{onCancel:t,preserveExisting:n=!1,storedApiKeyHeaderName:l,storedModels:r=[]}=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,m]=(0,i.useState)(""),[h,f]=(0,i.useState)(""),[g,v]=(0,i.useState)(""),[b,x]=(0,i.useState)(""),[y,j]=(0,i.useState)(""),[w,S]=(0,i.useState)(""),[C,I]=(0,i.useState)(""),[R,$]=(0,i.useState)(!1),[E,A]=(0,i.useState)(),[F,T]=(0,i.useState)(),[D,M]=(0,i.useState)();async function P(e){var t,l,a,i;if(e.preventDefault(),!R){$(!0),A(void 0),T(void 0),M(void 0),null==(t=s.current)||t.focus();try{let e,t=ni(y);if(function(e){try{return new URL(e.trim()).hostname.endsWith(".services.ai.azure.com");}catch{return!1;}}(p)&&0===t.length){A("Azure AI Foundry requires deployment names. Paste the names from the Deployments tab."),$(!1);return;}try{e=function(e){let t=e.trim();if(""===t)return;let n=Number(t);if(!Number.isInteger(n)||n<=0)throw Error("Request timeout must be a positive integer in milliseconds.");return n;}(b);}catch(e){A(e instanceof Error?e.message:"Request timeout is invalid."),$(!1);return;}let r=ni(w),s=!n||""!==p.trim()||""!==h.trim()||""!==g.trim()||t.length>0||r.length>0,o=s||void 0!==e,c=""!==C.trim(),d=await(0,k.qe)({baseUrl:""===p.trim()?void 0:p.trim(),apiKey:""===h.trim()?void 0:h.trim(),apiKeyHeaderName:""===g.trim()?void 0:g.trim(),...(void 0===e?{}:{timeoutMs:e}),deploymentNames:t,preserveExisting:n,...(0===r.length?{}:{imageInputModelIds:r}),...(""===C.trim()?{}:{figmaAccessToken:C.trim()})}),m=d.testedModelIds.length,f=(i=null!=(l=d.skippedModelIds)?l:[],0===i.length?"":` Could not verify deployment${1===i.length?"":"s"}: ${i.join(", ")}.`);$(!1),c&&!o?M("Verified Figma access token. Reloading Keiko…"):c&&!s?M("Updated model gateway settings and verified Figma access token. Reloading Keiko…"):c||s?c?M(`Verified ${String(m)} workflow chat model${1===m?"":"s"} and Figma access token. Reloading Keiko…${f}`):M(`Verified ${String(m)} workflow chat model${1===m?"":"s"}. Reloading Keiko…${f}`):M("Updated model gateway settings. Reloading Keiko…"),u.current=window.setTimeout(()=>window.location.reload(),0===(null!=(a=d.skippedModelIds)?a:[]).length?800:1800);}catch(t){let e=t instanceof k.hD?{message:t.message,code:t.code}:t instanceof Error?{message:t.message}:{message:"The gateway could not be configured."};A(e.message),T(e.code),$(!1);}}}(0,i.useEffect)(()=>{var e,t,l,a;let i=document.documentElement,r=Number(null!=(e=i.dataset.keikoModalOpenCount)?e:"0");i.dataset.keikoModalOpenCount=String(r+1),i.setAttribute("data-keiko-modal-open","true");let s=Number(null!=(t=i.dataset.keikoGatewaySetupOpenCount)?t:"0");return i.dataset.keikoGatewaySetupOpenCount=String(s+1),i.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=i.dataset.keikoModalOpenCount)?e:"1")-1);0===a?(delete i.dataset.keikoModalOpenCount,i.removeAttribute("data-keiko-modal-open")):i.dataset.keikoModalOpenCount=String(a);let r=Math.max(0,Number(null!=(t=i.dataset.keikoGatewaySetupOpenCount)?t:"1")-1);0===r?(delete i.dataset.keikoGatewaySetupOpenCount,i.removeAttribute("data-keiko-gateway-setup-open")):i.dataset.keikoGatewaySetupOpenCount=String(r),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(R||void 0!==D||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],i=l[l.length-1];n.shiftKey&&document.activeElement===a?(n.preventDefault(),i.focus()):n.shiftKey||document.activeElement!==i||(n.preventDefault(),a.focus());};return e.addEventListener("keydown",n),()=>e.removeEventListener("keydown",n);},[R,t,D]),(0,i.useEffect)(()=>{if(void 0!==E&&!R){var e,t;n&&""===p.trim()&&""===h.trim()?null==(e=c.current)||e.focus():null==(t=o.current)||t.focus();}},[h,p,R,E,n]);let q=ni(y),L=ni(w),z=!n,O=""!==p.trim()||""!==h.trim()||""!==g.trim()||""!==b.trim()||q.length>0||L.length>0,K=""!==C.trim(),W=!R&&void 0===D&&(z?""!==p.trim()&&""!==h.trim():O||K),B=r.map(e=>e.id),U=B.slice(0,6),_=Math.max(0,B.length-U.length),V=(0,a.jsxs)("div",{className:"gw-grid",children:[(0,a.jsxs)("label",{className:"gw-field gw-span-2",children:[(0,a.jsxs)("span",{children:["Base URL ",n?(0,a.jsx)("span",{className:"dlg-opt",children:"leave blank to keep"}):null]}),(0,a.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:R||void 0!==D,ref:o,onChange:e=>m(e.target.value)})]}),(0,a.jsxs)("label",{className:"gw-field",children:[(0,a.jsxs)("span",{children:["API token ",n?(0,a.jsx)("span",{className:"dlg-opt",children:"leave blank to keep"}):null]}),(0,a.jsx)("input",{className:"gw-input mono",type:"password",value:h,placeholder:n?"Only enter a value to replace the stored token":"Paste your API token",autoComplete:"off",disabled:R||void 0!==D,onChange:e=>f(e.target.value)})]}),(0,a.jsxs)("label",{className:"gw-field",children:[(0,a.jsxs)("span",{children:["API key header ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("input",{className:"gw-input mono",value:g,placeholder:n?"Leave blank to keep stored header":"Authorization",autoComplete:"off",disabled:R||void 0!==D,onChange:e=>v(e.target.value)})]}),(0,a.jsxs)("label",{className:"gw-field",children:[(0,a.jsxs)("span",{children:["Request timeout (ms) ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("input",{className:"gw-input mono",inputMode:"numeric",value:b,placeholder:n?"Leave blank to keep stored timeout":"30000",autoComplete:"off",disabled:R||void 0!==D,onChange:e=>x(e.target.value)})]}),(0,a.jsxs)("label",{className:"gw-field",children:[(0,a.jsx)("span",{children:"Deployment names for Azure"}),(0,a.jsx)("textarea",{className:"gw-input gw-textarea mono",value:y,placeholder:"Paste deployment names, one per line",autoComplete:"off",disabled:R||void 0!==D,onChange:e=>j(e.target.value)})]}),(0,a.jsxs)("label",{className:"gw-field",children:[(0,a.jsxs)("span",{children:["Image-input models ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("textarea",{className:"gw-input gw-textarea mono",value:w,placeholder:"Paste image-capable model names, one per line",autoComplete:"off",disabled:R||void 0!==D,onChange:e=>S(e.target.value)})]})]}),J=(0,a.jsx)("div",{className:"gw-setup-backdrop",role:"presentation",children:(0,a.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,a.jsxs)("form",{className:"gw-form",onSubmit:e=>void P(e),children:[(0,a.jsxs)("div",{className:"gw-head",children:[(0,a.jsxs)("div",{className:"gw-setup-badge",children:[(0,a.jsx)(N.F.cube,{size:18}),n?"Credential update":"Model gateway setup"]}),(0,a.jsx)("h1",{id:"gw-setup-title",children:n?"Update Keiko credentials":"Connect Keiko to your internal LLMs"}),(0,a.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,a.jsxs)("section",{className:"gw-section","aria-labelledby":"gw-model-section-title",children:[(0,a.jsx)("div",{className:"gw-section-head",children:(0,a.jsxs)("div",{children:[(0,a.jsx)("h2",{id:"gw-model-section-title",children:"Model gateway"}),(0,a.jsx)("p",{children:n?"Blank gateway fields keep the stored value.":"Base URL and API token are required."})]})}),n?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"gw-current","aria-label":"Stored model gateway credentials",children:[(0,a.jsxs)("div",{className:"gw-current-row",children:[(0,a.jsx)("span",{children:"Gateway URL"}),(0,a.jsx)("strong",{children:"Stored"})]}),(0,a.jsxs)("div",{className:"gw-current-row",children:[(0,a.jsx)("span",{children:"API token"}),(0,a.jsx)("strong",{className:"mono",children:"••••••••••••"})]}),(0,a.jsxs)("div",{className:"gw-current-row",children:[(0,a.jsx)("span",{children:"API key header"}),(0,a.jsx)("strong",{className:"mono",children:null!=l?l:"authorization"})]}),(0,a.jsxs)("div",{className:"gw-current-models",children:[(0,a.jsx)("span",{children:"Configured models"}),(0,a.jsxs)("div",{className:"gw-model-chips",children:[0===U.length?(0,a.jsx)("strong",{children:"Stored"}):U.map(e=>(0,a.jsx)("strong",{className:"mono",children:e},e)),_>0?(0,a.jsxs)("strong",{children:["+",_.toString()]}):null]})]})]}),(0,a.jsxs)("details",{className:"gw-replace",children:[(0,a.jsx)("summary",{children:"Replace model gateway settings"}),V]})]}):V]}),(0,a.jsxs)("section",{className:"gw-section","aria-labelledby":"gw-figma-section-title",children:[(0,a.jsx)("div",{className:"gw-section-head",children:(0,a.jsxs)("div",{children:[(0,a.jsx)("h2",{id:"gw-figma-section-title",children:"Figma Snapshot"}),(0,a.jsx)("p",{children:"Optional connector credential."})]})}),(0,a.jsxs)("label",{className:"gw-field",children:[(0,a.jsxs)("span",{children:["Figma access token ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("input",{className:"gw-input mono",type:"password",value:C,placeholder:n?"Stored Figma token is kept when blank":"Paste a read-only Figma PAT when needed",autoComplete:"off",disabled:R||void 0!==D,ref:c,onChange:e=>I(e.target.value)})]})]}),(0,a.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!==E?(0,a.jsxs)("div",{className:"gw-error",role:"alert",children:[E,void 0!==F?(0,a.jsx)("div",{className:"gw-error-code mono",children:F}):null]}):null,void 0!==D?(0,a.jsx)("div",{className:"gw-success",role:"status",children:D}):null,R?(0,a.jsx)("div",{className:"gw-pending",role:"status",children:"Testing credentials…"}):null,(0,a.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,a.jsxs)("div",{className:"gw-actions",children:[void 0!==t?(0,a.jsx)("button",{className:"gw-cancel",type:"button",disabled:R||void 0!==D,onClick:t,children:"Cancel"}):null,(0,a.jsx)("button",{className:"gw-submit",type:"submit",disabled:!W,"aria-busy":R,"aria-describedby":"gw-submit-requirements",children:R?"Testing credentials…":"Test & save"})]})]})})});return"u"<typeof document?J:(0,na.createPortal)(J,document.body);}function ns(e){return e.findIndex(e=>!0!==e.disabled);}function no(e,t,n){if(0===e.length)return-1;let l=t;for(let t=0;t<e.length;t+=1){var a;if(l=(l+n+e.length)%e.length,(null==(a=e[l])?void 0:a.disabled)!==!0)return l;}return-1;}function nc(e){let{active:t,index:n,onCommit:l,onOptionKeyDown:r,option:s,setOptionRef:o}=e,c=(0,i.useRef)(null),d=(0,i.useRef)(null),u=(0,i.useRef)(null),[p,m]=(0,i.useState)(null),h=()=>{null!==u.current&&(clearTimeout(u.current),u.current=null),m(null);},f=()=>{null!==u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{let e=d.current,t=c.current;if(null===e||null===t||e.scrollWidth<=e.clientWidth)return;let n=t.getBoundingClientRect(),l=Math.min(520,window.innerWidth-32),a=n.right+8+l<=window.innerWidth-16?"top-left":"top-right";m({left:"top-left"===a?n.right+8:n.left-8,placement:a,top:n.top-6});},1500);};return(0,i.useEffect)(()=>h,[]),(0,a.jsxs)("button",{ref:e=>{c.current=e,o(n,e);},"aria-selected":t,className:`ksel-option${t?" ksel-option-active":""}`,"data-disabled":!0===s.disabled?"true":void 0,disabled:s.disabled,onBlur:h,onClick:()=>l(s),onFocus:f,onKeyDown:e=>r(e,n),onPointerEnter:f,onPointerLeave:h,role:"option",type:"button",children:[(0,a.jsxs)("span",{className:"ksel-option-copy",children:[(0,a.jsx)("span",{className:"ksel-option-label",ref:d,children:s.label}),void 0!==s.description?(0,a.jsx)("span",{className:"ksel-option-desc",children:s.description}):null]}),void 0!==s.badge?(0,a.jsx)("span",{className:"ksel-option-badge",children:s.badge}):null,null!==p?(0,na.createPortal)((0,a.jsx)("div",{className:"ksel-overflow-tooltip","data-placement":p.placement,role:"tooltip",style:{left:`${p.left.toString()}px`,top:`${p.top.toString()}px`},children:s.label}),document.body):null]});}function nd(e){var t,n,l;let{value:r,sections:s,onValueChange:o,disabled:c=!1,placeholder:d="Select an option",ariaLabel:u,ariaDescribedBy:p,ariaLabelledBy:m,triggerClassName:h,menuClassName:f,menuTitle:g,menuCountLabel:v,showMenuHeader:b=!0,leadingVisual:x,mono:y=!1,showChevron:j=!0,menuMinWidth:w,attached:k=!0,triggerStyle:N,autoFocus:S=!1}=e,C=(0,i.useRef)(null),I=(0,i.useRef)(null),R=(0,i.useRef)([]),$=(0,i.useId)(),[E,A]=(0,i.useState)(!1),[F,T]=(0,i.useState)(-1),[D,M]=(0,i.useState)(null),[P,q]=(0,i.useState)(!1),L=(0,i.useMemo)(()=>s.flatMap((e,t)=>e.options.map((n,l)=>{var a;return{...n,key:`${null!=(a=e.label)?a:"section"}-${t.toString()}-${n.value}-${l.toString()}`,sectionLabel:e.label};})),[s]),z=L.findIndex(e=>e.value===r),O=-1===z?null:L[z],K=null!=(t=null==O?void 0:O.label)?t:d,W=null!=(n=null==O?void 0:O.description)?n:null,B=()=>{A(!1),T(-1);},U=e=>{var t,n;if(c||0===L.length)return;let l=void 0!==e&&(null==(t=L[e])?void 0:t.disabled)!==!0?e:z>=0&&(null==(n=L[z])?void 0:n.disabled)!==!0?z:ns(L);A(!0),T(l);};function _(e){var t;e.disabled||(o(e.value),B(),null==(t=C.current)||t.focus());}function V(e,t){if("Escape"===e.key){var n;e.preventDefault(),B(),null==(n=C.current)||n.focus();return;}if("Tab"===e.key)return void B();if("ArrowDown"===e.key){e.preventDefault(),T(no(L,t,1));return;}if("ArrowUp"===e.key){e.preventDefault(),T(no(L,t,-1));return;}if("Home"===e.key){e.preventDefault(),T(ns(L));return;}if("End"===e.key){e.preventDefault(),T(no(L,0,-1));return;}if("Enter"===e.key||" "===e.key){e.preventDefault();let n=L[t];void 0!==n&&_(n);}}(0,i.useEffect)(()=>{if(!E)return;let e=e=>{let t=e.target;null!==C.current&&t instanceof Node&&C.current.contains(t)||null!==I.current&&t instanceof Node&&I.current.contains(t)||B();},t=()=>B();return window.addEventListener("pointerdown",e,!0),window.addEventListener("blur",t),()=>{window.removeEventListener("pointerdown",e,!0),window.removeEventListener("blur",t);};},[E]),(0,i.useLayoutEffect)(()=>{if(!E||null===C.current)return;let e=()=>{var e;let t=null==(e=C.current)?void 0:e.getBoundingClientRect();if(void 0===t)return;let n=Math.min(void 0!==w&&t.width<Math.min(w,96)?w:t.width,window.innerWidth-32),l=k&&1>Math.abs(n-t.width),a=l?-1:6,i=window.innerHeight-t.bottom-16,r=t.top-16,s=i<Math.max(96,2*t.height)&&r>i;q(s);let o=s?r:i,c=50*!!b+2,d=Math.max(t.height,Math.min(Math.max(t.height,o-c),380)),u=d+c,p=window.getComputedStyle(C.current);M({left:Math.min(Math.max(16,t.left),window.innerWidth-n-16),width:n,top:s?Math.max(16,t.top-u-a):Math.min(t.bottom+a,window.innerHeight-16-u),optionHeight:Math.max(28,Math.min(t.height,30)),maxHeight:d,openUp:s,attached:l,fontFamily:p.fontFamily,fontSize:p.fontSize,fontWeight:p.fontWeight,letterSpacing:p.letterSpacing,lineHeight:p.lineHeight});};return e(),window.addEventListener("resize",e),window.addEventListener("scroll",e,!0),()=>{window.removeEventListener("resize",e),window.removeEventListener("scroll",e,!0);};},[E,k,w,b]),(0,i.useLayoutEffect)(()=>{if(!E||null===D||!D.openUp||null===C.current||null===I.current)return;let e=C.current.getBoundingClientRect(),t=I.current.getBoundingClientRect();if(t.height<=0)return;let n=D.attached?-1:6,l=Math.max(16,e.top-t.height-n);.5>Math.abs(l-D.top)||M(e=>null===e?e:{...e,top:l});},[E,D]),(0,i.useEffect)(()=>{var e,t;E&&!(F<0)&&(null==(e=R.current[F])||e.focus(),null==(t=R.current[F])||t.scrollIntoView({block:"nearest"}));},[E,F]),(0,i.useEffect)(()=>{if(!E)return;let e=e=>{var t,n;if("Escape"===e.key){B(),null==(t=C.current)||t.focus();return;}if(1===e.key.length&&!e.metaKey&&!e.ctrlKey&&!e.altKey){if((n=e.target)instanceof HTMLElement&&("INPUT"===n.tagName||"TEXTAREA"===n.tagName||"SELECT"===n.tagName||n.isContentEditable))return;let t=e.key.toLowerCase(),l=F>=0?F:z>=0?z:0;for(let e=1;e<=L.length;e+=1){let n=(l+e)%L.length,a=L[n];if(void 0!==a&&!0!==a.disabled&&a.label.toLowerCase().startsWith(t)){T(n);break;}}}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e);},[E,F,L,z]);let J=["ksel-trigger",y?"mono":"",null!=h?h:"",E?"ksel-trigger-open":"",E&&(null==D?void 0:D.attached)===!0?P?"ksel-trigger-open-up":"ksel-trigger-open-down":"",c?"ksel-trigger-disabled":""].filter(e=>e.length>0).join(" "),H=E&&null!==D?(0,na.createPortal)((0,a.jsxs)("div",{ref:I,className:["ksel-menu",D.attached?"ksel-menu-attached":"",D.openUp?"ksel-menu-open-up":"ksel-menu-open-down",null!=f?f:""].filter(e=>e.length>0).join(" "),style:{left:`${D.left.toString()}px`,top:`${D.top.toString()}px`,width:`${D.width.toString()}px`,"--ksel-option-height":`${D.optionHeight.toString()}px`,fontFamily:D.fontFamily,fontSize:D.fontSize,fontWeight:D.fontWeight,letterSpacing:D.letterSpacing,lineHeight:D.lineHeight},children:[b?(0,a.jsxs)("div",{className:"ksel-menu-head",children:[(0,a.jsx)("div",{className:"ksel-menu-title",children:null!=(l=null!=g?g:u)?l:d}),(0,a.jsx)("div",{className:"ksel-menu-note",children:null!=v?v:`${L.length.toString()} options`})]}):null,(0,a.jsx)("div",{className:"ksel-menu-scroll",role:"listbox",id:$,style:{maxHeight:`${D.maxHeight.toString()}px`},children:s.map((e,t)=>{var n;return(0,a.jsxs)("div",{className:"ksel-section",children:[void 0!==e.label?(0,a.jsx)("div",{className:"ksel-section-label",children:e.label}):null,e.options.map(t=>{var n;let l=L.findIndex(n=>n.value===t.value&&n.sectionLabel===e.label),i=l===z,r=L[l];return void 0===r?null:(0,a.jsx)(nc,{active:i,index:l,onCommit:_,onOptionKeyDown:V,option:r,setOptionRef:(e,t)=>{R.current[e]=t;}},`${null!=(n=e.label)?n:"section"}-${t.value}`);})]},`${null!=(n=e.label)?n:"section"}-${t.toString()}`);})})]}),document.body):null;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("button",{ref:C,"aria-controls":$,"aria-describedby":p,"aria-expanded":E,"aria-haspopup":"listbox","aria-label":u,"aria-labelledby":m,autoFocus:S,className:J,disabled:c,onClick:()=>{E?B():U();},onKeyDown:function(e){if(!c){if("ArrowDown"===e.key||"ArrowUp"===e.key){e.preventDefault(),U(z>=0?z:ns(L));return;}("Enter"===e.key||" "===e.key)&&(e.preventDefault(),E?B():U());}},role:"combobox",style:N,type:"button",children:[void 0!==x?(0,a.jsx)("span",{className:"ksel-trigger-leading",children:x}):null,(0,a.jsxs)("span",{className:"ksel-trigger-copy",children:[(0,a.jsx)("span",{className:"ksel-trigger-label",children:K}),null!==W?(0,a.jsx)("span",{className:"ksel-trigger-desc",children:W}):null]}),j?(0,a.jsx)("span",{"aria-hidden":"true",className:`ksel-trigger-caret${E?" ksel-trigger-caret-open":""}`,children:(0,a.jsx)("svg",{fill:"none",height:"12",viewBox:"0 0 12 12",width:"12",children:(0,a.jsx)("path",{d:"M2.25 4.5 6 8.25 9.75 4.5",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5"})})}):null]}),H]});}let nu=[["ask","Ask every action"],["full","Full access"]];function np(e){let{cfg:t,set:n}=e,l=!1!==t.keikoMode,i="full"===t.access?"full":"ask",r=l?"No rights by default. You approve while manual; Keiko governs per policy when autonomous.":"full"===i?"Legacy: agent acts without prompts.":"Legacy: you approve each privileged action.";return(0,a.jsxs)("div",{className:"permctl",children:[(0,a.jsxs)("button",{type:"button",className:"perm-toggle","data-on":l,"aria-pressed":l,onClick:()=>n("keikoMode",!l),children:[(0,a.jsx)("img",{className:"perm-orca",src:"/assets/keiko-logo.svg",alt:""}),(0,a.jsxs)("span",{className:"perm-tt",children:[(0,a.jsx)("span",{className:"perm-name",children:"Keiko-Mode"}),(0,a.jsx)("span",{className:"perm-desc",children:"Zero standing rights \xb7 Keiko governs"})]}),(0,a.jsx)("span",{className:"perm-sw"+(l?" on":""),children:(0,a.jsx)("span",{})})]}),!l&&(0,a.jsx)("div",{className:"perm-legacy",children:nu.map(e=>{let[t,l]=e;return(0,a.jsx)("button",{type:"button",className:"perm-opt","data-on":i===t,"aria-pressed":i===t,onClick:()=>n("access",t),children:l},t);})}),(0,a.jsx)("div",{className:"perm-note",children:r})]});}function nm(e){if(e instanceof k.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 nh(e){let{value:t,projectId:n,selectProjectRoot:l=!1,onSelect:r,onClose:s}=e,[o,c]=(0,i.useState)(null),[d,u]=(0,i.useState)(t),[p,m]=(0,i.useState)(!1),[h,f]=(0,i.useState)(null),g=null!=n?n:t.trim(),v=(0,i.useCallback)(async e=>{if(0===g.length){c(null),f("Enter an absolute folder path.");return;}m(!0),f(null);try{let t=await(0,k.xe)(g,e);c(t),u(t.path);}catch(e){f(nm(e));}finally{m(!1);}},[g]);return(0,i.useEffect)(()=>{v(t.length>0?t:void 0);},[]),(0,a.jsxs)("div",{className:"dir-picker",role:"group","aria-label":"Directory picker",children:[(0,a.jsxs)("div",{className:"dir-top",children:[(0,a.jsx)("input",{className:"dlg-input mono dir-path",value:d,"aria-label":"Folder path",placeholder:"/absolute/folder/path",onChange:e=>u(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),e.stopPropagation(),v(d));}}),(0,a.jsx)("button",{type:"button",className:"dlg-btn dir-go",onClick:()=>void v(d),children:"Go"})]}),null!==o?(0,a.jsx)("div",{className:"dir-roots",children:o.roots.map(e=>(0,a.jsx)("button",{type:"button",className:"dir-chip",onClick:()=>void v(e.path),children:e.label},`${e.label}:${e.path}`))}):null,(0,a.jsxs)("div",{className:"dir-list",children:[(null==o?void 0:o.parent)!==null&&(null==o?void 0:o.parent)!==void 0?(0,a.jsxs)("button",{type:"button",className:"dir-row",onClick:()=>{var e;v(null!=(e=o.parent)?e:void 0);},children:[(0,a.jsx)(N.F.back,{size:14}),(0,a.jsx)("span",{children:"Parent directory"})]}):null,null==o?void 0:o.entries.map(e=>(0,a.jsxs)("button",{type:"button",className:"dir-row",onClick:()=>void v(e.path),children:[(0,a.jsx)(N.F.folder,{size:14}),(0,a.jsx)("span",{children:e.name})]},e.path)),p?(0,a.jsx)("div",{className:"dir-note",role:"status",children:"Loading directories…"}):null,p||null===o||0!==o.entries.length?null:(0,a.jsx)("div",{className:"dir-note",children:"No child directories."}),null!==h?(0,a.jsx)("div",{className:"dir-error",role:"alert",children:h}):null]}),(0,a.jsxs)("div",{className:"dir-actions",children:[(0,a.jsx)("button",{type:"button",className:"dlg-btn",onClick:s,children:"Close"}),(0,a.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",onClick:()=>{if(null!==o){var e,t;r(l&&null!=(e=null==(t=o.roots[0])?void 0:t.path)?e:o.path),s();}},disabled:null===o,children:"Use directory"})]})]});}let nf=[{id:"unit-test-generation",label:"Unit Test Agent",scope:"Source file"},{id:"bug-investigation",label:"Bugfix Agent",scope:"Bug report"}];function ng(e){return e.filter(e=>e.available).map(e=>e.path);}function nv(e){return e.split(/[\n,]/u).map(e=>e.trim()).filter(e=>e.length>0);}function nb(e){let t=ny(e.trim()).replace(/\/+$/u,""),n=t.lastIndexOf("/");return n>0?t.slice(0,n):"";}let nx=function(e){return"chat"===e.kind&&e.toolCalling&&e.structuredOutput;};function ny(e){return e.replaceAll("\\","/");}function nj(e,t){let n=ny(t.trim());if(0===n.length)return"";let l=ny(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 nw(e){let{root:t,value:n,onSelect:l,onClose:r}=e,s=nj(t,n),[o,c]=(0,i.useState)(nb(s)),[d,u]=(0,i.useState)(s),[p,m]=(0,i.useState)([]),[h,f]=(0,i.useState)(!1),[g,v]=(0,i.useState)(!1),[b,x]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(0===t.trim().length){m([]),f(!1),v(!1),x("Select a repository first.");return;}let e=!1;return v(!0),x(null),(0,k.KD)(t.trim(),o).then(t=>{e||(m(t.entries),f(t.truncated));}).catch(t=>{e||(m([]),f(!1),x(nm(t)));}).finally(()=>{e||v(!1);}),()=>{e=!0;};},[o,t]);let y=p.filter(e=>"directory"===e.kind),j=p.filter(e=>"directory"!==e.kind);return(0,a.jsxs)("div",{className:"file-picker",role:"group","aria-label":"File picker",children:[(0,a.jsx)("div",{className:"file-picker-head",children:(0,a.jsx)("span",{className:"file-picker-path mono",children:0===o.length?"Repository root":o})}),(0,a.jsxs)("div",{className:"dir-list file-picker-list",children:[o.length>0?(0,a.jsxs)("button",{type:"button",className:"dir-row",onClick:()=>c(nb(o)),children:[(0,a.jsx)(N.F.back,{size:14}),(0,a.jsx)("span",{children:"Parent folder"})]}):null,y.map(e=>(0,a.jsxs)("button",{type:"button",className:"dir-row file-picker-row",disabled:!e.readable,onClick:()=>c(e.path),title:e.path,children:[(0,a.jsx)(N.F.folder,{size:14}),(0,a.jsx)("span",{children:e.name})]},e.path)),j.map(e=>(0,a.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,a.jsx)(N.F.file,{size:14}),(0,a.jsx)("span",{children:e.name}),(0,a.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)),g?(0,a.jsx)("div",{className:"dir-note",role:"status",children:"Loading files…"}):null,g||null!==b||0!==p.length?null:(0,a.jsx)("div",{className:"dir-note",children:"No files in this folder."}),h?(0,a.jsxs)("div",{className:"dir-note file-picker-warning",role:"status",children:["Showing only the first ",p.length.toString()," entries."]}):null,null!==b?(0,a.jsx)("div",{className:"dir-error",role:"alert",children:b}):null]}),(0,a.jsxs)("div",{className:"dir-actions",children:[(0,a.jsx)("button",{type:"button",className:"dlg-btn",onClick:r,children:"Close"}),(0,a.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",onClick:()=>{0!==d.trim().length&&(l(nj(t,d)),r());},disabled:0===d.trim().length,children:"Use file"})]})]});}function nk(e){var t,n;let{filesContext:l,firstRef:r,directoryField:s,setDirectoryField:o,setDialogError:c,onConfirm:d}=e,[u,p]=(0,i.useState)("unit-test-generation"),[m,h]=(0,i.useState)(null!=(t=null==l?void 0:l.root)?t:""),[f,g]=(0,i.useState)(""),[v,b]=(0,i.useState)([]),[x,y]=(0,i.useState)([]),[j,w]=(0,i.useState)(()=>{var e,t,n,a;let i;return n=null!=(e=null==l?void 0:l.root)?e:"",{verifyTargetFiles:i=null===(a=null!=(t=null==l?void 0:l.activeFilePath)?t:null)?"":nj(n,a),explainFilePath:i,explainQuestion:"",unitFilePath:i,bugDescription:"",bugFailingOutput:"",bugStackTrace:"",bugTargetFiles:i};}),[S,C]=(0,i.useState)(!0),[I,R]=(0,i.useState)(!1),[$,E]=(0,i.useState)(!1),A=m.trim(),F=null!==l&&l.root===A&&void 0!==l.activeFilePath?l.activeFilePath:null,T=A.length>0&&x.includes(A),D=0===A.length?"Repository is required.":0===f.length?"No compatible model is available.":"explain-plan"===u&&0===j.explainFilePath.trim().length?"Explain plan requires a file path.":"unit-test-generation"===u&&0===j.unitFilePath.trim().length?"Unit Test Agent requires a source file.":"bug-investigation"===u&&0===j.bugDescription.trim().length?"Bugfix Agent requires an observed behavior.":null,M=null===D&&T&&!$&&!S,P=null!=(n=nf.find(e=>e.id===u))?n:nf[0],q="unit-test-generation"===u?"Start Unit Test Agent":"Start Bugfix Agent";(0,i.useEffect)(()=>{let e=!1;return C(!0),c(null),Promise.all([(0,k.ZC)(),(0,k.vj)()]).then(t=>{let[n,l]=t;if(e)return;let a=n.models.filter(nx);b(a),g(e=>{var t,n;return e||(null!=(t=null==(n=a[0])?void 0:n.id)?t:"");}),y(ng(l.projects));}).catch(t=>{e||c(nm(t));}).finally(()=>{e||C(!1);}),()=>{e=!0;};},[c]);let L=e=>{w(t=>({...t,...e}));};(0,i.useEffect)(()=>{if(null===F)return;let e=nj(A,F);w(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};});},[F,A]);let z=async()=>{y(ng((await(0,k.vj)()).projects));},O=async()=>{if(0!==A.length){R(!0),c(null);try{await(0,k.gA)({path:A}),await z();}catch(e){c(nm(e));}finally{R(!1);}}},K=async()=>{if(!M)return void c(null!=D?D:"Repository is not registered.");E(!0),c(null);let e=function(e,t,n,l){if("verify"===e){let e=nv(l.verifyTargetFiles).map(e=>nj(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:nj(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:nj(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()}:{}),...(nv(l.bugTargetFiles).length>0?{targetFiles:nv(l.bugTargetFiles).map(e=>nj(t,e))}:{})}}};}(u,A,f,j);try{let t=await(0,k.AD)(e);d({workflow:u,model:f,runId:t.runId,fingerprint:t.fingerprint,workspaceRoot:A,inputJson:JSON.stringify(e.input),...(null!==l&&l.root===A?{__connectFilesId:l.id}:{})});}catch(e){e instanceof k.hD&&"WORKSPACE_NOT_REGISTERED"===e.code?(await z().catch(()=>void 0),c("Repository is not registered.")):c(nm(e));}finally{E(!1);}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"dlg-agent-grid",children:[(0,a.jsxs)("div",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"Agent"}),(0,a.jsx)("span",{className:"dlg-selwrap",children:(0,a.jsx)(nd,{triggerClassName:"dlg-input",value:u,ariaLabel:"Agent",autoFocus:!0,menuTitle:"Agent",menuCountLabel:`${nf.length.toString()} agents`,sections:[{options:nf.map(e=>({value:e.id,label:e.label}))}],onValueChange:e=>{let t=nf.find(t=>t.id===e);void 0!==t&&p(t.id);}})})]}),(0,a.jsxs)("div",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"Model"}),(0,a.jsx)("span",{className:"dlg-selwrap",children:(0,a.jsx)(nd,{triggerClassName:"dlg-input mono",value:f,ariaLabel:"Model",disabled:0===v.length,menuTitle:"Model",mono:!0,sections:[{options:v.map(e=>({value:e.id,label:e.id}))}],onValueChange:g})})]})]}),(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"Repository"}),(0,a.jsxs)("span",{className:"dlg-dirwrap",children:[(0,a.jsx)("input",{className:"dlg-input mono",value:m,placeholder:"/absolute/repository/path",onClick:()=>o("agentWorkspace"),onChange:e=>h(e.target.value)}),(0,a.jsx)("button",{type:"button",className:"dlg-btn dlg-dirbtn",onClick:()=>o("agentWorkspace"),children:"Browse"})]}),"agentWorkspace"===s?(0,a.jsx)(nh,{value:m,projectId:T?A:void 0,onSelect:h,onClose:()=>o(null)}):null]}),A.length>0&&!T?(0,a.jsxs)("div",{className:"dlg-agent-warning",children:[(0,a.jsx)("span",{children:"Repository is not registered."}),(0,a.jsx)("button",{type:"button",className:"dlg-btn",disabled:I,onClick:()=>void O(),children:I?"Registering…":"Register repository"})]}):null,null!==F?(0,a.jsxs)("button",{type:"button",className:"dlg-current-file",onClick:()=>{if(null===F)return;let e=nj(A,F);"unit-test-generation"===u?L({unitFilePath:e}):L({bugTargetFiles:e});},title:F,children:[(0,a.jsx)(N.F.files,{size:13})," Use current file ",(0,a.jsx)("span",{className:"mono",children:F})]}):null,(0,a.jsxs)("div",{className:"dlg-agent-task",children:[(0,a.jsxs)("div",{className:"dlg-agent-task-head",children:[(0,a.jsx)("span",{className:"dlg-agent-task-title",children:P.label}),(0,a.jsx)("span",{className:"dlg-agent-task-scope",children:P.scope})]}),"unit-test-generation"===u?(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"Source file"}),(0,a.jsxs)("span",{className:"dlg-dirwrap",children:[(0,a.jsx)("input",{className:"dlg-input mono",placeholder:"src/file.ts",value:j.unitFilePath,onChange:e=>L({unitFilePath:e.target.value}),onBlur:e=>L({unitFilePath:nj(A,e.target.value)})}),(0,a.jsx)("button",{type:"button",className:"dlg-btn dlg-dirbtn","aria-label":"Browse source file",onClick:()=>o("unitSourceFile"),children:"Browse"})]}),"unitSourceFile"===s?(0,a.jsx)(nw,{root:A,value:j.unitFilePath,onSelect:e=>L({unitFilePath:e}),onClose:()=>o(null)}):null]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"Observed behavior"}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea",rows:2,placeholder:"Describe the observed bug.",value:j.bugDescription,onChange:e=>L({bugDescription:e.target.value})})]}),(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:["Failing output ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,value:j.bugFailingOutput,onChange:e=>L({bugFailingOutput:e.target.value})})]}),(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:["Stack trace ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,value:j.bugStackTrace,onChange:e=>L({bugStackTrace:e.target.value})})]}),(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:["Related files ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,placeholder:"src/file.ts, src/other.ts",value:j.bugTargetFiles,onChange:e=>L({bugTargetFiles:e.target.value}),onBlur:e=>L({bugTargetFiles:nv(e.target.value).map(e=>nj(A,e)).join(", ")})})]})]})]}),(0,a.jsxs)("div",{className:"dlg-agent-actions",children:[(0,a.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",disabled:!M,"aria-busy":$,"aria-describedby":M||$?void 0:"agent-start-validation",onClick:()=>void K(),children:$?"Starting…":q}),S?(0,a.jsx)("span",{id:"agent-start-validation",className:"dlg-note",role:"status",children:"Loading models and projects…"}):null,S||null===D?null:(0,a.jsx)("span",{id:"agent-start-validation",className:"dlg-note",role:"status",children:D})]})]});}function nN(e){var t,n;let{type:l,types:r,filesContext:s=null,onConfirm:o,onClose:c}=e,d=r[l],u=null!=(t=d.config)?t:[],[p,m]=(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)),[h,f]=(0,i.useState)(!1),[g,v]=(0,i.useState)(null),[b,x]=(0,i.useState)(null),y=(0,i.useRef)(null),j=(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():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;f(!0),null==(t=null!=(e=y.current)?e:j.current)||t.focus();});return()=>cancelAnimationFrame(e);},[]),(0,i.useEffect)(()=>{let e=e=>{"Escape"===e.key&&c();};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e);};},[c]),(0,i.useEffect)(()=>{if("files"!==l&&"editor"!==l)return;let e=!1,t=p.root;if("string"!=typeof t||!(t.length>0))return v(null),(0,k.vj)().then(t=>{let n=ng(t.projects)[0];e||void 0===n||m(e=>({...e,root:n}));}).catch(t=>{e||v(nm(t));}),()=>{e=!0;};},[p.root,l]);let S=(e,t)=>m(n=>({...n,[e]:t})),C=()=>{"agents"!==l&&o(p);},I=N.F[d.icon],R=null!=(n=d.cta)?n:`Open ${d.title}`;return(0,a.jsx)("div",{className:"dlg-overlay"+(h?" in":""),onPointerDown:c,children:(0,a.jsxs)("div",{ref:j,className:"agents"===l?"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 c();if("Enter"===e.key&&(e.metaKey||e.ctrlKey))return void C();if("Enter"===e.key){let t=e.target instanceof HTMLElement?e.target.tagName:"";("INPUT"===t||"SELECT"===t)&&(e.preventDefault(),C());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],i=l[l.length-1];e.shiftKey&&document.activeElement===a?(e.preventDefault(),i.focus()):e.shiftKey||document.activeElement!==i||(e.preventDefault(),a.focus());},children:[(0,a.jsxs)("div",{className:"dlg-head",children:[(0,a.jsx)("span",{className:"dlg-ico",children:(0,a.jsx)(I,{size:20})}),(0,a.jsxs)("div",{className:"dlg-htext",children:[(0,a.jsxs)("span",{id:"new-window-title",className:"dlg-title",children:["New ",d.title," window"]}),(0,a.jsx)("span",{id:"new-window-desc",className:"dlg-sub",children:d.desc})]}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsx)("button",{type:"button",className:"palette-x",onClick:c,"aria-label":"Cancel",title:"Cancel",children:(0,a.jsx)(N.F.close,{size:16})})]}),(0,a.jsxs)("div",{className:"dlg-body",children:["agents"===l?(0,a.jsx)(nk,{filesContext:s,firstRef:e=>{y.current=e;},directoryField:b,setDirectoryField:x,setDialogError:v,onConfirm:o}):0===u.length&&(0,a.jsxs)("div",{className:"dlg-empty",children:["Add a new ",d.title," window to your workspace."]}),"agents"!==l&&u.map((e,t)=>(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:[e.label,!0===e.optional&&(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),function(e,t,n,l,i){var r,s,o,c;if("perm"===e.type)return(0,a.jsx)(np,{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,a.jsx)("span",{className:"dlg-selwrap",children:(0,a.jsx)(nd,{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,a.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,a.jsxs)("span",{className:"dlg-dirwrap",children:[(0,a.jsx)("input",{ref:null!=l?l:void 0,className:"dlg-input mono",placeholder:null!=(c=e.placeholder)?c:e.label,value:u,onClick:()=>i(e.key),onChange:t=>n(e.key,t.target.value)}),(0,a.jsx)("button",{type:"button",className:"dlg-btn dlg-dirbtn",onClick:()=>i(e.key),children:"Browse"})]}):(0,a.jsx)("input",{ref:null!=l?l:void 0,className:"dlg-input mono",placeholder:null!=(r=e.placeholder)?r:e.label,value:u,onChange:t=>n(e.key,t.target.value)});}(e,p,S,0===t?e=>{y.current=e;}:null,x),"directory"===e.type&&b===e.key?(0,a.jsx)(nh,{value:"string"==typeof p[e.key]?p[e.key]:"",selectProjectRoot:"root"===e.key,onSelect:t=>S(e.key,t),onClose:()=>x(null)}):null]},e.key)),null!==g?(0,a.jsx)("div",{className:"dlg-error",role:"alert",children:g}):null]}),(0,a.jsxs)("div",{className:"dlg-foot",children:[(0,a.jsx)("button",{type:"button",className:"dlg-btn",onClick:c,children:"Cancel"}),"agents"!==l?(0,a.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",onClick:C,children:R}):null]})]})});}function nS(e){let{types:t,order:n,onAdd:l,onClose:r}=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)&&r();};return document.addEventListener("pointerdown",e),()=>{document.removeEventListener("pointerdown",e);};},[r]),(0,a.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(),r();return;}if(!(e.target instanceof HTMLElement)||!e.target.classList.contains("pal-card"))return;let a=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,a.indexOf(e.target),a.length,s);null!==i&&(e.preventDefault(),u(i),null==(l=a[i])||l.focus());},onBlur:e=>{var t;e.relatedTarget instanceof Node&&(null==(t=o.current)?void 0:t.contains(e.relatedTarget))!==!0&&r();},"data-columns":s,children:[(0,a.jsxs)("div",{className:"palette-head",children:[(0,a.jsx)("span",{className:"palette-badge",children:(0,a.jsx)(N.F.add,{size:17})}),(0,a.jsxs)("div",{className:"palette-htext",children:[(0,a.jsx)("span",{id:"palette-title",className:"palette-title",children:"New window"}),(0,a.jsx)("span",{id:"palette-desc",className:"palette-sub",children:"Pick a card to add to your workspace"})]}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsx)("button",{type:"button",className:"palette-x",onClick:r,"aria-label":"Close",title:"Close",children:(0,a.jsx)(N.F.close,{size:16})})]}),(0,a.jsx)("div",{className:"palette-grid",children:n.map((e,n)=>{let i=t[e],r=N.F[i.icon];return(0,a.jsxs)("button",{type:"button",className:"pal-card pal-main",tabIndex:n===d?0:-1,onFocus:()=>u(n),onClick:()=>l(e),children:[(0,a.jsx)("span",{className:"pal-ico",children:(0,a.jsx)(r,{size:18})}),(0,a.jsx)("span",{className:"pal-name",children:i.title}),(0,a.jsx)("span",{className:"pal-desc",children:i.desc}),(0,a.jsx)("span",{className:"pal-add","aria-hidden":"true",children:(0,a.jsx)(N.F.plus,{size:15})})]},e);})})]});}async function nC(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 nI(e,t){var n;let l,a,i=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),r=null==t?void 0:t.body,s=await fetch(e,{...t,headers:(l={Accept:"application/json"},((a="GET"!==i&&"HEAD"!==i)||null!=r)&&(l["Content-Type"]="application/json"),a&&(l["X-Keiko-CSRF"]="1"),l)});if(!s.ok){let{code:e,message:t}=await nC(s);throw new k.hD(e,t,s.status);}return s.json();}async function nR(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:nI,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 n$(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:nI;return e("/api/memory/review-queue");}async function nE(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:nI;return t("/api/memory/consolidation/jobs",{method:"POST",body:JSON.stringify({settings:e})});}async function nA(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:nI;return t(`/api/memory/consolidation/jobs/${encodeURIComponent(e)}`);}async function nF(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:nI;return t(`/api/memory/consolidation/jobs/${encodeURIComponent(e)}/cancel`,{method:"POST",body:"{}"});}async function nT(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:nI;return t(`/api/memory/${encodeURIComponent(e)}`);}async function nD(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:nI;return n(`/api/memory/${encodeURIComponent(e)}`,{method:"PATCH",body:JSON.stringify(t)});}async function nM(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:nI;return t(`/api/memory/${encodeURIComponent(e)}/pin`,{method:"POST",body:"{}"});}async function nP(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:nI;return t(`/api/memory/${encodeURIComponent(e)}/unpin`,{method:"POST",body:"{}"});}async function nq(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:nI;return n(`/api/memory/${encodeURIComponent(e)}/archive`,{method:"POST",body:JSON.stringify({...(void 0!==t?{reason:t}:{})})});}async function nL(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:nI;return n(`/api/memory/${encodeURIComponent(e)}/forget`,{method:"POST",body:JSON.stringify({acknowledged:!0,...(void 0!==t?{reason:t}:{})})});}async function nz(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:nI;return n(`/api/memory/${encodeURIComponent(e)}`,{method:"DELETE",body:JSON.stringify({acknowledged:!0,...(void 0!==t?{reason:t}:{})})});}async function nO(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:nI;return n(`/api/memory/${encodeURIComponent(e)}/correct`,{method:"POST",body:JSON.stringify({body:t})});}async function nK(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:nI;return t(`/api/memory/proposals/${encodeURIComponent(e)}/accept`,{method:"POST",body:"{}"});}async function nW(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:nI;return n(`/api/memory/proposals/${encodeURIComponent(e)}/reject`,{method:"POST",body:JSON.stringify({...(void 0!==t?{reason:t}:{})})});}let nB=new Set(["completed","dry-run","fix-applied","fix-proposed","investigation-only"]);function nU(e){return e.length>200?e.slice(0,200):e;}function n_(e){if(null!==e&&"object"==typeof e)return e;}function nV(){return"Investigation complete; root cause documented.";}function nJ(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 nH=n(4503);let nY=[/\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],nX=/\s+\(([A-Z][A-Z0-9_/-]{2,})\)\s*$/;function nG(e){let t=e;for(let e of nY)t=t.replace(e,"[REDACTED]");return t.replace(/\bBearer\s+\[REDACTED\]/gi,"[REDACTED]");}function nQ(e,t){return"BAD_REQUEST"===t&&e.toLowerCase().includes("too broad")&&e.toLowerCase().includes("connected");}function nZ(e){return"CLARIFICATION_NEEDED"===e;}function n0(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 n1(e,t){return nZ(t)?"Keiko braucht mehr Kontext":nQ(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 n2(e,t){return nZ(t)?"Nenne eine konkrete Datei, einen Identifier, eine Fehlermeldung oder eine exakte Phrase.":nQ(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 n4(e,t){if(e instanceof k.hD){let n=n0(nG(e.message.trim()),e.code,t);return`${n} (${e.code})`;}return e instanceof Error&&e.message.trim().length>0?nG(e.message.trim()):t;}let n3="\n…[truncated]",n5=["text/"],n6=new Set(["application/json","application/x-yaml","application/yaml"]),n8=new TextEncoder();function n7(e){return n8.encode(e).length;}function n9(e){let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(t+1):e;}let le=`${String(256)} KB`;function lt(e){return`"${e}" won't be sent — the ${le} attachment limit was already used by earlier files.`;}async function ln(e,t){var n,l;let a,i,r,s,o;if(e.remainingAggregate<=0)return lt(n9(t.name));try{a=await t.file.text();}catch{return n=n9(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-n7(n3),0));if(c<=0)return lt(n9(t.name));let{entry:d,consumed:u}=(r=(i=n7(l=a)>c)?function(e,t){if(t<=0)return"";if(n7(e)<=t)return e;let n=0,l="";for(let a of e){let e=n+n7(a);if(e>t)break;n=e,l+=a;}return l;}(l,c):l,s=n7(r),o=i?n7(n3):0,{entry:{id:t.id,displayName:n9(t.name),mimeType:t.mimeType,sizeBytes:t.sizeBytes,extractedBytes:s,truncated:i,truncationMarker:i?n3:void 0,text:r},consumed:s+o});if(0===d.text.length)return 0===a.length?void 0:lt(n9(t.name));e.entries.push(d),e.remainingAggregate-=u;}async function ll(e){let t=e.filter(e=>{var t;return t=e.mimeType,!!n5.some(e=>t.startsWith(e))||n6.has(t);}),n=t.slice(0,16),l={entries:[],remainingAggregate:262144},a=[];for(let e of n){let t=await ln(l,e);void 0!==t&&a.push(t);}for(let e of t.slice(16)){var i;a.push((i=n9(e.name),`"${i}" won't be sent — only the first ${String(16)} documents are included.`));}return{entries:l.entries,failures:a};}let la=["text/"],li=new Set(["application/pdf","application/json","application/x-yaml","application/yaml"]),lr="New chat",ls="keiko:chat-upsert",lo="keiko:chat-delete",lc=["completed","failed","cancelled"];function ld(e){return"idle"!==e&&!lc.includes(e);}let lu="The conversation context exceeded the model's window. Clear history or pick a larger-context model.",lp="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.",lm=new Set(["CONVERSATION_OVERSIZED_CONTEXT","GATEWAY_CONTEXT_OVERFLOW"]),lh=["context length","context_length_exceeded","max_tokens","too many tokens"],lf=["empty assistant response","empty grounded answer","without assistant content"];function lg(e){return void 0!==e&&e.contextWindowTokens>0&&"exceeded"===e.pressure;}function lv(e){let t;return function(e){if(e instanceof k.hD&&lm.has(e.code))return!0;let t=e instanceof Error?e.message.toLowerCase():"";return 0!==t.length&&lh.some(e=>t.includes(e));}(e)?lu:0!==(t=e instanceof Error?e.message.toLowerCase():"").length&&lf.some(e=>t.includes(e))?e instanceof k.hD?`${lp} (${e.code})`:lp:n4(e,"Something went wrong. Try again.");}function lb(e){return[...e].sort((e,t)=>t.updatedAt-e.updatedAt);}function lx(e){window.dispatchEvent(new CustomEvent(ls,{detail:e}));}function ly(e){var t;return null==(t=e.find(nH.S_))?void 0:t.id;}function lj(e,t){return void 0!==e&&t.some(t=>t.id===e&&(0,nH.S_)(t))?e:ly(t);}function lw(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 lk={projects:[],chats:[],messages:[],models:[],activeProject:void 0,activeChat:void 0,selectedModel:void 0};async function lN(e){var t;let n=(await(0,k.ZC)()).models.filter(nH.S_),l=ly(n),a=[...(await(0,k.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)),i=null!=(t=a.find(e=>e.available))?t:a[0];if(void 0!==i){let e=lb((await(0,k.Oz)(i.path).catch(()=>({chats:[]}))).chats),t=e[0];if(void 0!==t){let l=await(0,k.T$)(t.id,i.path),r=lj(t.selectedModel,n);return{models:n,selectedModel:r,projects:Array.from(a),activeProject:i,chats:e,activeChat:t,messages:Array.from(l.messages)};}}if(void 0===l||!e)return{models:n,selectedModel:l,projects:Array.from(a),activeProject:i,chats:[],activeChat:void 0,messages:[]};let r={modelId:l,title:lr};(null==i?void 0:i.available)===!0&&(r.projectPath=i.path);let s=await(0,k.tA)(r);return lx(s.chat),{models:n,selectedModel:s.chat.selectedModel,projects:Array.from(s.projects),activeProject:s.project,chats:lb(s.chats),activeChat:s.chat,messages:Array.from(s.messages)};}function lS(){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)(lk),[s,o]=(0,i.useState)(""),[c,d]=(0,i.useState)(!0),[u,p]=(0,i.useState)("idle"),m=ld(u),h=(0,i.useRef)("idle"),f=(0,i.useRef)(null),[g,v]=(0,i.useState)(),[b,x]=(0,i.useState)(),[y,j]=(0,i.useState)(),[w,N]=(0,i.useState)(!0),[S,C]=(0,i.useState)(1200),I=(0,i.useRef)(!0),R=(0,i.useRef)(void 0),$=(0,i.useRef)(new Set()),E=(0,i.useRef)(0),A=(0,i.useRef)([]),[F,T]=(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":la.some(e=>t.startsWith(e))||li.has(t)?"document":"unsupported-type";if("unsupported-type"===l)return{ok:!1,reason:"unsupported-type"};let i=a.models.find(e=>e.id===a.selectedModel);if(void 0!==i&&("image"===l&&!i.supportsImageInput||"document"===l&&!i.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 r={id:crypto.randomUUID(),kind:l,name:e.name,mimeType:e.type,sizeBytes:e.size,previewDataUrl:n,file:e};return T(e=>[...e,r]),{ok:!0};},[a.models,a.selectedModel]),q=(0,i.useCallback)(e=>{T(t=>t.filter(t=>t.id!==e));},[]),L=(0,i.useCallback)(()=>{T([]);},[]),z=(0,i.useCallback)(async()=>{let e=F.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 ll(e);n.length>0&&v(n.join(" "));let l=t.map(e=>({id:e.id,displayName:e.displayName,truncated:e.truncated}));return{entries:t,disclosures:l};},[F]),O=(0,i.useCallback)(()=>{j(void 0);},[]),K=(0,i.useCallback)((e,t)=>({enabled:w,budgetTokens:S,context:{userId:"local-operator",workspaceId:t.path,projectId:t.path,conversationId:e.id}}),[S,w]),W=(0,i.useCallback)(async e=>{await nK(e),j(t=>void 0===t?t:{...t,actions:t.actions.filter(t=>"candidate"!==t.kind||t.proposalId!==e)});},[]),B=(0,i.useCallback)(async e=>{await nW(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 nL(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)});},[]),_=(0,i.useCallback)(e=>{h.current=e,p(e);},[]),V=(0,i.useCallback)(async(e,t,n,l)=>{let a=n.runId;if(void 0===a)return void $.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(!I.current||R.current!==e.id)return;try{let e=await(0,k.Qe)(a),t=function(e,t){let n=n_(e);if(void 0===n)return{kind:"unknown"};let l=function(e){let t=e.status;if("string"==typeof t)return t;}(n),a=nJ(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:nU(function(e){let t,n,l=(t=n_(e.failure),n=null==t?void 0:t.message,"string"==typeof n&&n.length>0?n:void 0);return void 0!==l?nU(`Run failed: ${l}.`):"Run failed.";}(n))}}:void 0!==l&&nB.has(l)?{kind:"terminal",summary:{workflowStatus:"completed",shortResult:nU(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=n_(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 nV();if("verify"===t){let t,n;return t=n_(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 k.hD)||404!==e.status)return;try{let e=await(0,k.tZ)(a),t=function(e,t){let n=n_(e),l=void 0===n?void 0:n_(n.run),a=void 0===l?void 0:l.outcome,i=nJ(t);return"cancelled"===a?{workflowStatus:"cancelled",shortResult:"Run cancelled."}:"failed"===a||"limit-exceeded"===a?{workflowStatus:"failed",shortResult:"Run failed."}:"completed"===a?{workflowStatus:"completed",shortResult:nU("bug"===i?nV():"verify"===i?"Verification passed.":"explain"===i?"Plan generated.":"unit-tests"===i?"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,k.mj)(n.id,e.id,t,s);if(!I.current||R.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{$.current.delete(l);}},[]);(0,i.useEffect)(()=>{var e;R.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),v(void 0);try{let t=await lN(l);e||r(e=>({...e,...t}));}catch(t){e||v(lv(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:lb([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?lj(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(ls,e),window.addEventListener(lo,t),()=>{window.removeEventListener(ls,e),window.removeEventListener(lo,t);};},[]),(0,i.useEffect)(()=>(I.current=!0,()=>{var e;I.current=!1,null==(e=f.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}`;$.current.has(a)||($.current.add(a),V(e,t.path,n,a));}},[a.activeChat,a.activeProject,a.messages,V]);let J=(0,i.useCallback)(e=>{let t;v(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)})),T(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=R.current;if(void 0===n)return;let l=E.current+1;E.current=l,(0,k.wi)(n,{selectedModel:e}).then(e=>{E.current!==l||R.current===e.chat.id&&(lx(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(E.current===l&&R.current===n&&(v(lv(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;})};});}});},[]),H=(0,i.useCallback)(async(e,t)=>{let n=lj(a.selectedModel,a.models);if(void 0===n)return void v("No conversation-eligible model is configured. Connect a gateway in Settings.");v(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:lr},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,k.tA)(o);return R.current=d.chat.id,lx(d.chat),r({projects:Array.from(d.projects),chats:lb(d.chats),messages:Array.from(d.messages),models:a.models,activeProject:d.project,activeChat:d.chat,selectedModel:d.chat.selectedModel}),d.chat;}catch(e){v(lv(e));return;}},[a.selectedModel,a.activeProject,a.models]),Y=(0,i.useCallback)(async e=>{v(void 0),r(t=>({...t,activeProject:e}));try{let t=await(0,k.Oz)(e.path),n=lb(t.chats),l=n[0];if(void 0===l)return void(await H(e));let i=await(0,k.T$)(l.id,e.path);R.current=l.id;let s=lj(l.selectedModel,a.models);r(e=>({...e,chats:n,activeChat:l,selectedModel:s,messages:Array.from(i.messages)})),j(void 0);}catch(e){v(lv(e));}},[H,a.models]),X=(0,i.useCallback)(async e=>{var t;v(void 0),null==(t=f.current)||t.abort(),f.current=null,R.current=e.id,x(void 0),j(void 0),M([]);try{let t=await(0,k.T$)(e.id,e.projectPath),n=lj(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){v(lv(e));}},[a.models]),G=(0,i.useCallback)(async e=>{let t=e.trim();if(0!==t.length){v(void 0);try{let e=await(0,k.gA)({path:t}),n=await(0,k.vj)();r(e=>({...e,projects:Array.from(n.projects)})),await H(e.project);}catch(e){v(lv(e));}}},[H]),Q=(0,i.useCallback)(e=>{r(t=>({...t,messages:t.messages.filter(t=>t.id!==e)}));},[]),Z=(0,i.useCallback)((e,t,n)=>{let l=!1;return{onToken:t=>{l||(_("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:lb([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)]})),lx(l.chat),void 0!==l.memory&&j(l.memory),n("completed");},onError:t=>{let{code:l,message:a}=t;v(lv(new k.hD(l,a,0))),Q(e),n("failed");},onCancelled:()=>{Q(e),n("cancelled");}};},[Q,_]),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:K(e,t),...(s.length>0?{documentContext:s}:{})};return new Promise((e,t)=>{let n=Z(o,l,e);(0,k.nk)(c,i,n).catch(n=>{Q(o),n instanceof k.ZF?t(n):n instanceof DOMException&&"AbortError"===n.name?e("cancelled"):(v(lv(n)),r(e=>({...e,messages:e.messages.filter(e=>e.id!==l)})),e("failed"));});});},[K,Z,Q]),et=(0,i.useCallback)(async(e,t,n,l,a,i,s)=>{try{_("contacting");let o=await(0,k.xp)({chatId:e.id,projectPath:t.path,content:n,modelId:a,memory:K(e,t),...(s.length>0?{documentContext:s}:{})},i);if(i.aborted)return"cancelled";return r(e=>({...e,activeChat:o.chat,chats:lb([o.chat,...e.chats.filter(e=>e.id!==o.chat.id)]),messages:[...e.messages.filter(e=>e.id!==l),...Array.from(o.messages)]})),lx(o.chat),j(o.memory),"completed";}catch(n){if(n instanceof DOMException&&"AbortError"===n.name)return"cancelled";v(lv(n));try{let n=await(0,k.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";}},[K,_]),en=(0,i.useCallback)(async(e,t,n,l,i,r,s)=>{var o;if((null==(o=a.models.find(e=>e.id===i))?void 0:o.streaming)!==!0)return et(e,t,n,l,i,r,s);_("contacting");try{return await ee(e,t,n,l,i,r,s);}catch(e){if(!(e instanceof k.ZF))throw e;}return et(e,t,n,l,i,r,s);},[a.models,et,ee,_]),el=(0,i.useCallback)(async(e,t,n,l,a,i)=>{x(void 0);try{_("contacting");let t=await(0,k.Wk)({chatId:e.id,content:n,modelId:a},i);if(R.current!==e.id)return"completed";if(i.aborted)return"cancelled";x(t),j(void 0);let[l,s]=await Promise.all([(0,k.T$)(e.id,e.projectPath),(0,k.Oz)(e.projectPath)]),o=s.chats.find(t=>t.id===e.id);return r(e=>({...e,messages:Array.from(l.messages),chats:lb(s.chats),activeChat:null!=o?o:e.activeChat})),void 0!==o&&lx(o),"completed";}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return"cancelled";return v(lv(e)),r(e=>({...e,messages:e.messages.filter(e=>e.id!==l)})),"failed";}},[_]),ea=(0,i.useCallback)(()=>{var e;ld(h.current)&&(null==(e=f.current)||e.abort(),f.current=null,_("cancelled"));},[_]),ei=(0,i.useCallback)(async()=>{var e,t,n,l;if(ld(h.current))return;let i=s.trim(),c=a.activeChat,d=a.activeProject,u=lj(a.selectedModel,a.models);if(0===i.length||void 0===c||void 0===d||void 0===u)return;if(lg((0,nH.pk)({modelContextWindow:null!=(e=null==(n=a.models.find(e=>e.id===u))?void 0:n.contextWindow)?e:0,modelMaxOutputTokens:null!=(t=null==(l=a.models.find(e=>e.id===u))?void 0:l.maxOutputTokens)?t:0,userDraftText:i,conversationHistory:a.messages.filter(e=>"user"===e.role||"assistant"===e.role).map(e=>({role:e.role,content:e.content}))})))return void v(lu);if(lw(c)&&F.length>0)return void v("Attachments are not supported for grounded chats. Remove the attachment or switch to a non-grounded chat.");let p={id:`local-${String(Date.now())}`,chatId:c.id,role:"user",content:i,timestamp:Date.now(),runId:void 0,workflowId:void 0,workflowStatus:void 0,shortResult:void 0,taskType:void 0};_("queued"),o(""),v(void 0),r(e=>({...e,messages:[...e.messages,p]}));let m=new AbortController();f.current=m,j(void 0);try{let e=lw(c),{entries:t,disclosures:n}=e?{entries:[],disclosures:[]}:await z(),l=e?await el(c,d,i,p.id,u,m.signal):await en(c,d,i,p.id,u,m.signal,t);"cancelled"===h.current||_(l),"completed"===l&&(L(),M(n));}finally{f.current=null;}},[s,a.activeChat,a.activeProject,a.selectedModel,a.models,a.messages,F,el,en,z,L,_]),er=(0,i.useCallback)(()=>{x(void 0),j(void 0),r(e=>({...e,messages:[]}));},[]),es=(0,i.useMemo)(()=>{let e=a.models.find(e=>e.id===a.selectedModel);if(void 0===e)return;let t=a.messages.filter(e=>"user"===e.role||"assistant"===e.role).map(e=>({role:e.role,content:e.content})),n=0,l=0;void 0!==b&&(("connected-context"===b.groundingKind||"hybrid"===b.groundingKind)&&(n=("hybrid"===b.groundingKind?b.contextPack.folder:b.contextPack).usage.excerptBytes),("local-knowledge"===b.groundingKind||"hybrid"===b.groundingKind)&&(l=4*("hybrid"===b.groundingKind?b.contextPack.knowledge:b.contextPack).referenceBudget));let i=w&&void 0!==y&&y.context.enabled?y.context.text.length:0;return(0,nH.pk)({modelContextWindow:e.contextWindow,modelMaxOutputTokens:e.maxOutputTokens,userDraftText:s,conversationHistory:t,repoContextPackBytes:n,knowledgeCapsuleBytes:l,memoryContextBytes:i});},[a.models,a.selectedModel,a.messages,s,b,y,w]),eo=(0,i.useCallback)(e=>{lx(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)(()=>{v(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===lj(a.selectedModel,a.models),draft:s,loading:c,sending:m,sendStatus:u,error:g,clearError:ec,setDraft:o,setSelectedModel:J,openNewChat:H,openProject:Y,openChat:X,addProject:G,sendMessage:ei,cancelSend:ea,replaceChat:eo,latestGrounded:b,cancelGrounded:ea,pendingAttachments:F,addPendingAttachment:P,removePendingAttachment:q,clearPendingAttachments:L,lastSentDocuments:D,budget:es,memoryEnabled:w,setMemoryEnabled:N,memoryBudgetTokens:S,setMemoryBudgetTokens:C,latestMemory:y,clearLatestMemory:O,acceptMemoryCandidate:W,rejectMemoryCandidate:B,forgetMemoryAction:U,clearHistory:er};}let lC="keiko.theme",lI="dark",lR=["agent","capsule","capsule-set","chat","connector","data-source","evidence-run","mcp-tool","memory","patch-proposal","skill","tool","workflow-run","workspace-path"],l$=["capsule","capsule-set","chat","evidence-run","memory","patch-proposal","tool","workflow-run","workspace-path"],lE=["reads-context","proposes-patch","uses-tool","starts-workflow","produces-evidence","references-document","depends-on"],lA=["draft","active","archived","superseded","revoked","blocked","stale"],lF={"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"}},lT=["prompt","documentcontent","filecontent","toolstdout","toolstderr","secret","credential","apikey","password","token"],lD="Unable to reach the local backend. Check that the Keiko server is running (keiko ui).";class lM extends Error{constructor(e,t,n,l=[]){super(t),this.name="RelationshipApiError",this.code=e,this.status=n,this.reasons=l;}}async function lP(e){let t;try{t=await e.json();}catch{throw new lM("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,i="string"==typeof a.code?a.code:"relationship/unknown-error",r="string"==typeof a.message?a.message:"An unknown error occurred.",s=Array.isArray(l.reasons)?l.reasons:[];throw new lM(i,r,e.status,s);}return t;}function lq(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 lL(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:lq({}),body:JSON.stringify(t)});return{decision:(await lP(n)).decision};}async function lz(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:lq({idempotencyKey:t}),body:JSON.stringify(n)}),a=await lP(l);return{relationship:a.relationship,etag:a.etag};}async function lO(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 lP(n);return{entries:l.entries,truncated:l.truncated,nextCursor:l.nextCursor};}async function lK(e){let t=await fetch(`/api/relationships/${encodeURIComponent(e)}`);return(await lP(t)).relationship;}async function lW(e,t,n,l){let a=await fetch(`/api/relationships/${encodeURIComponent(e)}`,{method:"PATCH",headers:lq({idempotencyKey:l,ifMatch:n}),body:JSON.stringify({schemaVersion:"1",...t})}),i=await lP(a);return{relationship:i.relationship,etag:i.etag};}async function lB(e,t,n){let l=await fetch(`/api/relationships/${encodeURIComponent(e)}`,{method:"DELETE",headers:lq({idempotencyKey:n,ifMatch:t})});return(await lP(l)).relationship;}async function lU(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 lP(l)).report;}async function l_(e){return lP(await fetch(`/api/relationships/${encodeURIComponent(e)}/explain`));}async function lV(){return lP(await fetch("/api/relationships/health"));}let lJ=[{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 lH(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 lY(e){let t=[...e.mod].sort();return`${t.join("+")}|${e.key.toLowerCase()}`;}let lX={undoStack:[],redoStack:[]};class lG extends Error{constructor(e){super(`Workspace keyboard shortcut conflicts detected: ${e.map(e=>`${lY(e.chord)} (${e.commandIds.join(", ")})`).join("; ")}`),this.name="WorkspaceShortcutConflictError",this.conflicts=e;}}class lQ extends Error{constructor(e){super(`Workspace keyboard shortcut bindings refused: ${e.map(e=>`${e.commandId} → ${lY(e.chord)}`).join("; ")} are browser-reserved`),this.name="WorkspaceShortcutReservedError",this.reserved=e;}}let lZ=[{commandId:"undo",chord:{key:"z",mod:["cmd"]}},{commandId:"redo",chord:{key:"z",mod:["cmd","shift"]}},{commandId:"focus-status",chord:{key:"s",mod:["alt"]}}];var l0=n(82175);let l1="cmp-budget-exceeded-alert",l2={low:"Low",moderate:"Moderate",high:"High",exceeded:"Exceeded"},l4={low:"cmp-budget-badge cmp-budget-badge-low",moderate:"cmp-budget-badge cmp-budget-badge-moderate",high:"cmp-budget-badge cmp-budget-badge-high",exceeded:"cmp-budget-badge cmp-budget-badge-exceeded"},l3="Approximate next-request context. Estimated from UTF-8 bytes / 4; actual provider tokenization may vary. Stored grounded-answer evidence is counted only when it is attached to the next request.";function l5(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:e.toString();}function l6(e){let{budget:t,onClearHistory:n,disabled:l,compact:r=!1}=e,[s,o]=(0,i.useState)(!1),[c,d]=(0,i.useState)(!1),u=(0,i.useRef)(null),p=(0,i.useRef)(null);if((0,i.useEffect)(()=>{if(s){var e;null==(e=u.current)||e.focus();}},[s]),void 0===t)return null;let m=t.contextWindowTokens>0,h=l5(t.approximateTokens),f=l5(t.contextWindowTokens),g=t.pressure,v=m&&"exceeded"===g;return(0,a.jsxs)("div",{className:"cmp-budget","data-pressure":m?g:"unknown",children:[(0,a.jsxs)("div",{className:"cmp-budget-row",children:[(0,a.jsx)("span",{className:"cmp-budget-count",children:m?r?`Context: ${h} / ${f}`:`Approximate context: ${h} / ${f} tokens`:r?`Context: ${h}`:`Approximate context: ${h} tokens`}),m?(0,a.jsx)("span",{className:l4[g],"aria-label":`Context pressure: ${l2[g]}`,children:l2[g]}):null,(0,a.jsx)("span",{className:"cmp-budget-info",role:"img",tabIndex:0,"aria-label":l3,"data-tip":l3,children:"i"}),s?(0,a.jsxs)("span",{className:"cmp-budget-confirm",children:[(0,a.jsx)("span",{className:"cmp-budget-confirm-label",id:"cmp-budget-confirm-label",children:"Clear history?"}),(0,a.jsx)("button",{type:"button",ref:u,className:"cmp-budget-clear","aria-describedby":"cmp-budget-confirm-label",onClick:function(){n(),o(!1),d(!0),requestAnimationFrame(()=>{var e;return null==(e=p.current)?void 0:e.focus();});},children:"Clear"}),(0,a.jsx)("button",{type:"button",className:"cmp-budget-clear",onClick:function(){o(!1),requestAnimationFrame(()=>{var e;return null==(e=p.current)?void 0:e.focus();});},children:"Cancel"})]}):(0,a.jsx)("button",{type:"button",ref:p,className:"cmp-budget-clear","aria-label":"Clear conversation history for next prompt",onClick:()=>{d(!1),o(!0);},disabled:!0===l,children:r?"Clear":"Clear history"}),c?(0,a.jsx)("span",{role:"status",className:"cmp-budget-cleared",children:"History cleared for the next prompt — messages remain saved."}):null]}),v?(0,a.jsx)("div",{id:l1,role:"alert",className:"cmp-budget-alert gw-error",children:"Context exceeds the selected model's window. Clear history or pick a model with a larger context."}):null]});}function l8(e){var t,n;let{notice:l,className:r="ui-error-notice",id:s,onDismiss:o}=e,c=`${l.title}
94
- ${l.message}
95
- ${null!=(t=l.code)?t:""}
96
- ${null!=(n=l.remediation)?n:""}`,[d,u]=(0,i.useState)();return d===c?null:(0,a.jsxs)("div",{id:s,className:r,role:"alert","aria-live":"assertive",children:[(0,a.jsxs)("div",{className:"ui-error-notice-title-row",children:[(0,a.jsx)("div",{className:"ui-error-notice-title",children:l.title}),(0,a.jsx)("button",{type:"button",className:"ui-error-notice-close","aria-label":"Dismiss error",title:"Dismiss error",onClick:()=>{u(c),null==o||o();},children:(0,a.jsx)(N.F.close,{size:14})})]}),(0,a.jsx)("div",{className:"ui-error-notice-message",children:l.message}),void 0!==l.remediation?(0,a.jsx)("div",{className:"ui-error-notice-remediation",children:l.remediation}):null,void 0!==l.code?(0,a.jsx)("div",{className:"ui-error-notice-code mono",children:l.code}):null]});}function l7(e){let{error:t,fallback:n,className:l,id:i,onDismiss:r}=e;return(0,a.jsx)(l8,{id:i,className:l,notice:function(e,t){var n;let l;if(e instanceof k.hD){let n=n0(nG(e.message.trim()),e.code,t);return{title:n1(n,e.code),message:n,code:e.code,remediation:n2(n,e.code)};}let a=(n=nG(("string"==typeof e?e.trim():e instanceof Error?e.message.trim():"")||t),null===(l=nX.exec(n))?{message:n,code:void 0}:{message:n.slice(0,l.index).trim(),code:l[1]});return{title:n1(a.message,a.code),message:a.message,code:a.code,remediation:n2(a.message,a.code)};}(t,n),onDismiss:r});}var l9=n(65538),ae=n(55176);let at=/@?((?:[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,an=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})?)?`,al=RegExp(String.raw`\[\s*(${an})\s*\]`,"giu"),aa=RegExp(String.raw`\[\s*(${an})\s*\]\s*(?:\[source:\s*[^\]]+\]\s*)?(${an})`,"giu"),ai=RegExp(String.raw`(${an})\s+(?:\[source:\s*[^\]]+\]\s*)?(${an})`,"giu"),ar=/\[source:\s*[^\]]+\]/giu,as=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 ao(e){return e.replace(/\\/gu,"/").replace(/^\/+/u,"").replace(/\/+$/u,"");}function ac(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 ad(e,t,n){let l=ac(ah(e)),a=ac(ah(t));return null!==l&&l===a?e:n;}function au(e){return e.replace(aa,(e,t,n)=>ad(t,n,e.replace(ar,""))).replace(ai,(e,t,n)=>ad(t,n,e.replace(ar,""))).replace(al,(e,t)=>null===ah(t)?e:t).replace(ar,"").replace(/[ \t]{2,}/gu," ").replace(/[ \t]+([,.;:!?])/gu,"$1");}function ap(e){if(void 0===e)return;let t=Number.parseInt(e,10);return Number.isSafeInteger(t)&&t>0?t:void 0;}function am(e,t){var n,l;let a=null!=(n=e[0])?n:"",i=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,i)||!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,i+a.length))return null;let r=ao(null!=(l=e[1])?l:"");if(!function(e){var t,n,l;let a=ao(e);if(0===a.length||a!==e||a.startsWith(".")||a.includes("..")||!a.includes("."))return!1;let i=a.split("/");if(i.some(e=>0===e.length||"."===e||".."===e))return!1;let r=null!=(n=null==(l=(null!=(t=i[i.length-1])?t:"").split(".").pop())?void 0:l.toLowerCase())?n:"";return as.has(r);}(r))return null;let s=ap(e[2]),o=ap(e[3]),c=void 0===s?void 0:Math.max(s,null!=o?o:s);return{label:a,path:r,...(void 0===s?{}:{lineStart:s}),...(void 0===c?{}:{lineEnd:c})};}function ah(e){var t,n;at.lastIndex=0;let l=at.exec(e);return null===l||0!==l.index||(null!=(t=null==(n=l[0])?void 0:n.length)?t:0)!==e.length?null:am(l,e);}function af(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 ag(e){let{reference:t,roots:n,openReference:l,className:r="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:af(n)});}return t;},[n]),p=(0,i.useCallback)(e=>{if(void 0===l)return;o("opening"),d(`Opening ${t.path}…`);let n=l({root:e.root,path:t.path,...(void 0===t.lineStart?{}:{lineStart:t.lineStart}),...(void 0===t.lineEnd?{}:{lineEnd:t.lineEnd})});if(n.ok){o("opened"),d(`Opened ${t.path} in editor.`),window.setTimeout(()=>{o("idle"),d("");},1800);return;}o("failed"),d(n.message);},[l,t]),m=(0,i.useCallback)(()=>{if(void 0===l||0===u.length){o("failed"),d("Connect a Files window to open repository references.");return;}if(1===u.length){let e=u[0];void 0!==e&&p(e);return;}o(e=>"choosing"===e?"idle":"choosing"),d("Select a repository source.");},[p,l,u]),h=(0,i.useCallback)(e=>{if("Escape"===e.key){o("idle"),d("");return;}("Enter"===e.key||" "===e.key)&&(e.preventDefault(),m());},[m]);if(void 0===l||0===u.length)return(0,a.jsx)("span",{children:t.label});let f="failed"===s;return(0,a.jsxs)("span",{className:"repo-ref",children:[(0,a.jsxs)("button",{type:"button",className:r,"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":u.length>1?"choosing"===s:void 0,"data-state":s,onClick:m,onKeyDown:h,children:[(0,a.jsx)("span",{className:"repo-ref-file-icon","aria-hidden":"true",children:(0,a.jsx)(ae.o,{name:t.path})}),(0,a.jsx)("span",{children:t.label})]}),"choosing"===s?(0,a.jsx)("span",{className:"repo-ref-picker",role:"dialog","aria-label":"Select repository source",children:u.map(e=>(0,a.jsx)("button",{type:"button",className:"repo-ref-root",onClick:()=>p(e),children:e.label},e.root))}):null,c.length>0?(0,a.jsx)("span",{role:f?"alert":"status",className:"repo-ref-status",children:c}):null]});}function av(e){return Number.isFinite(e)?String(e):"—";}function ab(e,t){return Number.isFinite(e)?t(e):"—";}function ax(e){return e.toLocaleString("en-US");}function ay(e){return e.replaceAll("-"," ");}function aj(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:`${t}s`;return 1===e?t:n;}function aw(e){let{label:t,value:n}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("dt",{className:"grounded-context-pack-dt",children:t}),(0,a.jsx)("dd",{className:"grounded-context-pack-dd",children:n})]});}function ak(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,a.jsxs)("details",{className:"grounded-ranking-rationale",children:[(0,a.jsx)("summary",{"aria-label":"Why these files were selected",children:"Why these files?"}),(0,a.jsx)("dl",{className:"grounded-context-pack-dl",children:n.map(e=>{let[t,n]=e;return(0,a.jsx)(aw,{label:ay(t),value:ax(n)},`bucket-${t}`);})}),t.ecosystems.length>0?(0,a.jsx)("p",{className:"grounded-ranking-ecosystems",children:`Ecosystems: ${t.ecosystems.map(e=>`${e.id} (${ax(e.count)})`).join(", ")}`}):null]});}function aN(e){let{contextPack:t}=e,{usage:n,budget:l}=t,i=function(e){if("workspace-root"===e.scopeKind)return"workspace root";let t=e.scopeId.slice(-8);return`${ay(e.scopeKind)} (${t})`;}(t),r="files"===t.scopeKind?`Scope: ${String(t.fileCount)} file${1===t.fileCount?"":"s"} in ${i}`:`Scope: ${i}`;return(0,a.jsxs)("section",{className:"grounded-context-pack","aria-label":"Context inspection summary",children:[(0,a.jsx)("div",{className:"grounded-context-pack-headline",children:r}),(0,a.jsxs)("dl",{className:"grounded-context-pack-dl",children:[(0,a.jsx)(aw,{label:"Searched",value:`${String(n.searchCalls)} / ${av(l.searchCallsMax)} searches`}),(0,a.jsx)(aw,{label:"Read",value:`${String(n.filesRead)} / ${av(l.filesReadMax)} files`}),(0,a.jsx)(aw,{label:"Bytes",value:`${(0,l9.z3)(n.excerptBytes)} / ${ab(l.excerptBytesMax,l9.z3)}`}),(0,a.jsx)(aw,{label:"Input",value:`${ax(n.modelInputTokens)} / ${ab(l.modelInputTokensMax,ax)} tokens`}),(0,a.jsx)(aw,{label:"Output",value:`${ax(n.modelOutputTokens)} / ${ab(l.modelOutputTokensMax,ax)} tokens`}),(0,a.jsx)(aw,{label:"Rerank",value:`${String(n.rerankCalls)} / ${av(l.rerankCallsMax)} calls`}),(0,a.jsx)(aw,{label:"Time",value:`${(0,l9._V)(t.elapsedMs)} / ${ab(l.elapsedMsMax,l9._V)}`}),(0,a.jsx)(aw,{label:"Query",value:ay(t.queryKind)})]}),void 0!==t.rankingSummary?(0,a.jsx)(ak,{summary:t.rankingSummary}):null]});}function aS(e){return void 0===e.lineRange?e.scopePath:`${e.scopePath}:${String(e.lineRange.startLine)}-${String(e.lineRange.endLine)}`;}function aC(e){let{score:t}=e;return(0,a.jsxs)("span",{className:"grounded-citation-score",children:[(0,a.jsx)("span",{className:"sr-only",children:"relevance "}),t.toFixed(2)]});}function aI(e){var t;let{citation:n,repositoryRoots:l,openRepositoryReference:i}=e,r=null==(t=n.documentFormat)?void 0:t.toUpperCase(),s=void 0===r&&void 0!==i&&l.length>0;return(0,a.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===r?null:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{className:"grounded-citation-doc-badge",children:r}),(0,a.jsx)("span",{className:"sr-only",children:" document evidence extracted text "})]}),(0,a.jsx)("span",{className:"grounded-citation-range",children:s?(0,a.jsx)(ag,{reference:{label:aS(n),path:n.scopePath,...(void 0===n.lineRange?{}:{lineStart:n.lineRange.startLine,lineEnd:n.lineRange.endLine})},roots:l,openReference:i,className:"repo-ref-link grounded-citation-open"}):aS(n)}),(0,a.jsx)(aC,{score:n.score})]});}function aR(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 a$(e){let{total:t,expanded:n,onToggle:l}=e;return t<=8?null:(0,a.jsx)("button",{type:"button",className:"grounded-citations-more","aria-expanded":n,onClick:l,children:n?"Show fewer citations":`Show all ${String(t)} citations`});}function aE(e){let{citations:t,repositoryRoots:n,openRepositoryReference:l}=e,[r,s]=(0,i.useState)(!1);if(0===t.length)return null;let o=aR([...t].sort((e,t)=>t.score-e.score)),c=r?o:o.slice(0,8);return(0,a.jsxs)("div",{className:"grounded-citations-wrap",children:[(0,a.jsx)("span",{className:"grounded-citations-label",children:"Evidence"}),(0,a.jsx)("ul",{className:"grounded-citations","aria-label":"Evidence citations",children:c.map(e=>(0,a.jsx)("li",{className:"grounded-citations-item",children:(0,a.jsx)(aI,{citation:e,repositoryRoots:n,openRepositoryReference:l})},e.stableId))}),(0,a.jsx)(a$,{total:o.length,expanded:r,onToggle:()=>{s(e=>!e);}})]});}function aA(e){return aR(e).length;}function aF(e){let{title:t,summary:n,hasCoverageWarning:l=!1,children:i}=e;return(0,a.jsxs)("details",{className:"grounded-evidence-disclosure",children:[(0,a.jsxs)("summary",{className:"grounded-evidence-summary",children:[(0,a.jsx)("span",{className:"grounded-evidence-summary-title",children:t}),(0,a.jsx)("span",{className:"grounded-evidence-summary-meta",children:n}),l?(0,a.jsx)("span",{className:"grounded-evidence-summary-badge",children:"Partial coverage"}):null]}),(0,a.jsx)("div",{className:"grounded-evidence-body",children:i})]});}function aT(e){let{citations:t}=e,[n,l]=(0,i.useState)(!1);if(0===t.length)return null;let r=aR([...t].sort((e,t)=>t.score-e.score)),s=n?r:r.slice(0,8);return(0,a.jsxs)("div",{className:"grounded-citations-wrap",children:[(0,a.jsx)("span",{className:"grounded-citations-label",children:"Knowledge citations"}),(0,a.jsx)("ul",{className:"grounded-citations","aria-label":"Knowledge citations",children:s.map(e=>(0,a.jsx)("li",{className:"grounded-citations-item",children:(0,a.jsxs)("span",{className:"grounded-citation",title:void 0===e.source?`${e.label} — relevance ${e.score.toFixed(2)}`:`${e.source} \xb7 ${e.label} — relevance ${e.score.toFixed(2)}`,children:[(0,a.jsx)("span",{children:void 0===e.source?`${e.marker} ${e.label}`:`${e.marker} ${e.source} \xb7 ${e.label}`}),(0,a.jsx)(aC,{score:e.score})]})},e.stableId))}),(0,a.jsx)(a$,{total:r.length,expanded:n,onToggle:()=>{l(e=>!e);}})]});}function aD(e){let{markers:t}=e;if(0===t.length)return null;let n=Array.from(new Set(t.map(e=>ay(e.kind)))).join(", ");return(0,a.jsxs)("div",{className:"grounded-uncertainty",role:"note",children:[(0,a.jsx)("div",{children:`Uncertainty (${String(t.length)} markers — ${n})`}),(0,a.jsx)("ul",{className:"grounded-uncertainty-list",children:t.map((e,t)=>(0,a.jsx)("li",{children:`${ay(e.kind)}: ${e.claim}`},`${e.kind}-${String(t)}`))})]});}function aM(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`${ay(t)}: ${String(n)}`;}).join(", "),i=l.length>0?` (${l})`:"";return(0,a.jsx)("div",{className:"grounded-meta",children:`Not used: ${String(t)} excerpt${1===t?"":"s"}${i}`});}let aP=[{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 aq(e){let{omittedCounts:t}=e,n=aP.map(e=>{let{reason:n,label:l}=e;return{label:l,count:t[n]};}).filter(e=>e.count>0),l=n.reduce((e,t)=>e+t.count,0);if(l<=0)return null;let i=n.map(e=>`${String(e.count)} ${e.label}`).join(", "),r=t.binary>0||t["unsupported-format"]>0||t["no-text-layer"]>0||t["malformed-document"]>0||t["encrypted-document"]>0;return(0,a.jsxs)("div",{className:"grounded-coverage-notice",role:"note",children:[(0,a.jsx)("span",{className:"grounded-coverage-notice-title",children:"Partial coverage"}),(0,a.jsx)("span",{children:`This answer reflects only the searchable files in the connected scope — ${String(l)} ${1===l?"file":"files"} ${1===l?"was":"were"} not searched (${i}). It does not cover the entire folder.`}),r?(0,a.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 aL(e){return aP.some(t=>{let{reason:n}=t;return e[n]>0;});}function az(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,a.jsx)("div",{className:"grounded-meta",children:l.map((e,t)=>(0,a.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,a.jsx)("span",{className:"sr-only",children:"(opens in new tab)"})]},e))});}function aO(e){let{contextPack:t}=e;return(0,a.jsxs)("section",{className:"grounded-context-pack","aria-label":"Knowledge scope summary",children:[(0,a.jsx)("div",{className:"grounded-context-pack-headline",children:`Knowledge scope: ${t.scopeLabel}`}),(0,a.jsxs)("dl",{className:"grounded-context-pack-dl",children:[(0,a.jsx)(aw,{label:"Mode",value:ay(t.scopeKind)}),(0,a.jsx)(aw,{label:"Capsules",value:String(t.capsuleCount)}),(0,a.jsx)(aw,{label:"Sources",value:String(t.sourceCount)}),(0,a.jsx)(aw,{label:"Citations",value:String(t.citationCount)}),(0,a.jsx)(aw,{label:"Context budget",value:`${String(t.referencesUsed)} / ${String(t.referenceBudget)} references`})]})]});}function aK(e){let{contextPack:t}=e;return(0,a.jsxs)("section",{className:"grounded-context-pack","aria-label":"Hybrid source summary",children:[(0,a.jsx)("div",{className:"grounded-context-pack-headline",children:`Hybrid: ${String(t.folderSourceCount)} folder source${1===t.folderSourceCount?"":"s"} + ${String(t.connectorSourceCount)} connector source${1===t.connectorSourceCount?"":"s"}`}),(0,a.jsx)(aN,{contextPack:t.folder}),(0,a.jsx)(aO,{contextPack:t.knowledge})]});}function aW(e){let t,n,l,i,r,s,{answer:o,busy:c,repositoryRoots:d=[],openRepositoryReference:u}=e;if(void 0===o)return c?(0,a.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,a.jsx)("div",{className:"grounded-answer",children:(0,a.jsxs)(aF,{title:"Knowledge evidence",summary:(t=aj(e=aA(o.citations),"citation"),`${ax(e)} ${t} \xb7 ${ax(o.contextPack.referencesUsed)} / ${ax(o.contextPack.referenceBudget)} references`),children:[(0,a.jsx)(aT,{citations:o.citations}),(0,a.jsx)(aD,{markers:o.uncertainty}),(0,a.jsx)(aO,{contextPack:o.contextPack})]})});}if("hybrid"===o.groundingKind){let e,t;return(0,a.jsx)("div",{className:"grounded-answer",children:(0,a.jsxs)(aF,{title:"Grounding evidence",summary:(e=aA(o.citations),t=aA(o.knowledgeCitations),`${ax(e)} file ${aj(e,"citation")} \xb7 ${ax(t)} knowledge ${aj(t,"citation")}`),hasCoverageWarning:aL(o.contextPack.folder.omittedCounts),children:[(0,a.jsx)(aq,{omittedCounts:o.contextPack.folder.omittedCounts}),(0,a.jsx)(aE,{citations:o.citations,repositoryRoots:d,openRepositoryReference:u}),(0,a.jsx)(aT,{citations:o.knowledgeCitations}),(0,a.jsx)(aD,{markers:o.uncertainty}),(0,a.jsx)(aM,{omittedCount:o.omittedCount,omittedCounts:o.contextPack.folder.omittedCounts}),(0,a.jsx)(az,{runId:o.evidenceRunId,runIds:o.evidenceRunIds}),(0,a.jsx)(aK,{contextPack:o.contextPack})]})});}return(0,a.jsx)("div",{className:"grounded-answer",children:(0,a.jsxs)(aF,{title:"Evidence",summary:(t=aA(o.citations),n=o.contextPack.usage.filesRead,l=av(o.contextPack.budget.filesReadMax),i=o.contextPack.omittedCount,r=aj(t,"citation"),s=i>0?` \xb7 ${ax(i)} not used`:"",`${ax(t)} ${r} \xb7 ${ax(n)} / ${l} files read${s}`),hasCoverageWarning:aL(o.contextPack.omittedCounts),children:[(0,a.jsx)(aq,{omittedCounts:o.contextPack.omittedCounts}),(0,a.jsx)(aE,{citations:o.citations,repositoryRoots:d,openRepositoryReference:u}),(0,a.jsx)(aD,{markers:o.uncertainty}),(0,a.jsx)(aM,{omittedCount:o.contextPack.omittedCount,omittedCounts:o.contextPack.omittedCounts}),(0,a.jsx)(az,{runId:o.evidenceRunId,runIds:o.evidenceRunIds}),(0,a.jsx)(aN,{contextPack:o.contextPack})]})});}function aB(e){return e.charAt(0).toUpperCase()+e.slice(1);}function aU(e){let{laneCounts:t}=e,n=Object.entries(t).filter(e=>{let[,t]=e;return t>0;});return(0,a.jsx)(a.Fragment,{children:n.map(e=>{let[t,n]=e;return(0,a.jsx)(aw,{label:ay(t),value:n.toLocaleString("en-US")},`lane-${t}`);})});}function a_(e){var t;let n,{contextSummary:l}=e;return void 0===l?null:(0,a.jsxs)("details",{className:"ctx-status grounded-evidence-disclosure",children:[(0,a.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,a.jsx)("span",{className:"grounded-evidence-summary-title",children:"Context"}),(0,a.jsx)("span",{className:"grounded-evidence-summary-meta",children:(n=Object.values((t=l).laneCounts).filter(e=>e>0).length,[`${(0,l9._y)(t.totalEstimatedTokens)} est. assembled tokens`,`${aB(t.budgetPressure)} pressure`,`${n.toLocaleString("en-US")} ${1===n?"lane":"lanes"}`,t.compactionActive?"Compaction active":"Compaction inactive"].join(" \xb7 "))})]}),(0,a.jsx)("div",{className:"ctx-status-body grounded-evidence-body",children:(0,a.jsxs)("dl",{className:"ctx-status-dl grounded-context-pack-dl",children:[(0,a.jsx)(aw,{label:"Estimator",value:"keiko-conservative-utf8-v1"}),(0,a.jsx)(aw,{label:"Assembled estimate",value:`${(0,l9._y)(l.totalEstimatedTokens)} tok`}),(0,a.jsx)(aw,{label:"Budget pressure",value:aB(l.budgetPressure)}),(0,a.jsx)(aU,{laneCounts:l.laneCounts}),(0,a.jsx)(aw,{label:"Compaction",value:l.compactionActive?"Active":"Inactive"})]})})]});}function aV(e){let{label:t,disabled:n=!1,onStepUp:l,onStepDown:i}=e,r=`Increase ${t}`,s=`Decrease ${t}`;return(0,a.jsxs)("span",{className:"number-control-stepper",children:[(0,a.jsx)("button",{type:"button",className:"number-control-stepper-button number-control-stepper-up","aria-label":r,disabled:n,onPointerDown:e=>{e.preventDefault();},onClick:e=>{e.stopPropagation(),l();}}),(0,a.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(),i();}})]});}let aJ=["<script","</script","<iframe","</iframe","<object","</object","<embed","</embed","<style","</style","<svg","</svg","<form","</form","<meta","<link","<base"],aH=[" ","\n"," ","'",'"'];function aY(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 aJ)if(n.includes(e))return!0;let l=0;for(;l<n.length-4;){let e=n[l];if(aH.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 aX(e,t,n,l){l>n&&e.push({kind:"text",text:t.slice(n,l)});}function aG(e){return void 0!==e&&/[A-Za-z0-9]/.test(e);}let aQ=new Set([" "," ","\n","<",">",'"']),aZ=new Set([".",",",")","]","!","?"]);function a0(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 i=function(e,t,n,l){if("`"!==t[n])return-1;let a=t.indexOf("`",n+1);return-1===a?-1:(aX(e,t,l,n),e.push({kind:"inline-code",text:t.slice(n+1,a)}),a+1);}(n,e,l,a);if(-1!==i||-1!==(i=function(e,t,n,l,a){let i=t[n],r=t[n+1];if(n+1>=t.length||("*"!==i||"*"!==r)&&("_"!==i||"_"!==r))return-1;let s=t.indexOf(i+r,n+2);if(-1===s)return-1;aX(e,t,l,n);let o=t.slice(n+2,s);return e.push({kind:"strong",children:a0(o,a+1)}),s+2;}(n,e,l,a,t))||-1!==(i=function(e,t,n,l,a){let i=t[n];if("*"!==i&&"_"!==i||"_"===i&&aG(t[n-1])&&aG(t[n+1])||t[n+1]===i||n>0&&t[n-1]===i)return-1;let r=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,i,n+1);return-1===r||"_"===i&&aG(t[r-1])&&aG(t[r+1])?-1:(aX(e,t,l,n),e.push({kind:"em",children:a0(t.slice(n+1,r),a+1)}),r+1);}(n,e,l,a,t))||-1!==(i=function(e,t,n,l){let a;if("["!==t[n])return-1;let i=t.indexOf("]",n+1);if(-1===i||"("!==t[i+1])return-1;let r=t.indexOf(")",i+2);if(-1===r)return-1;let s=t.slice(n+1,i),o=t.slice(i+2,r);return aX(e,t,l,n),((a=o.trim().toLowerCase()).startsWith("http://")||a.startsWith("https://"))&&!aY(s)&&!aY(o)?e.push({kind:"link",text:s,href:o}):e.push({kind:"text",text:`[${s}](${o})`}),r+1;}(n,e,l,a))||-1!==(i=function(e,t,n,l){if("h"!==t[n])return-1;let a="https://"===t.slice(n,n+8),i="http://"===t.slice(n,n+7);if(!a&&!i)return-1;let r=function(e,t){var n,l;let a=t;for(;a<e.length&&!aQ.has(null!=(n=e[a])?n:"");)a++;for(;a>t&&aZ.has(null!=(l=e[a-1])?l:"");)a--;return a;}(t,n);if(r-n<=(a?8:7))return-1;let s=t.slice(n,r);return aX(e,t,l,n),e.push({kind:"link",text:s,href:s}),r;}(n,e,l,a))){a=i,l=i;continue;}l++;}return aX(n,e,a,e.length),n;}function a1(e){let t=e.trim(),n=t.startsWith(":"),l=t.endsWith(":");return n&&l?"center":l?"right":n?"left":void 0;}function a2(e){let t=e.trim();return t.startsWith("|")&&(t=t.slice(1)),t.endsWith("|")&&(t=t.slice(0,-1)),t.split("|");}function a4(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 a3(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 a5(e){return e.includes("|");}function a6(e){let t=e.trim();return /^(-{3,}|\*{3,}|_{3,})$/.test(t);}function a8(e,t){let n=[],l=t?a3:a4;for(;e.i<e.lines.length;){var a;let t=null!=(a=e.lines[e.i])?a:"",i=l(t);if(i.match)n.push({text:i.text,indent:i.indent}),e.i++;else if(""===t.trim())break;else break;}return function e(t,n,l){let a=n?"ol":"ul",i=[],r=0;for(;r<t.length;){let a=t[r];if(void 0===a){r++;continue;}let s=a.indent,o=[];for(r++;r<t.length;){let e=t[r];if(void 0===e||e.indent<=s)break;o.push(e),r++;}let c=[...a0(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")}),i.push({kind:"li",children:c});}return{kind:a,children:i};}(n,t,e.depth);}let a7={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 a9(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=a7[a])?t:"code";}let ie=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 it(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 il(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:""],...it(e.slice(t[0].length))];}return it(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),i=/^\s*:/.test(l);t.push([i?"key2":"str",a[0]]),n+=a[0].length;continue;}let i=/^-?\d[\d.eE+\-]*/.exec(l);if(null!==i){t.push(["num",i[0]]),n+=i[0].length;continue;}let r=/^(true|false|null)\b/.exec(l);if(null!==r){t.push(["lit",r[0]]),n+=r[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 i=e.indexOf(n.block[1]);if(-1===i)return l.push(["com",e]),l;l.push(["com",e.slice(0,i+n.block[1].length)]),a=i+n.block[1].length,t.inBlock=!1;}for(;a<e.length;){let r=e.slice(a);if(null!==n.line&&r.startsWith(n.line)){l.push(["com",r]);break;}if(null!==n.block&&r.startsWith(n.block[0])){let i=e.indexOf(n.block[1],a+n.block[0].length);if(-1===i){l.push(["com",r]),t.inBlock=!0;break;}l.push(["com",e.slice(a,i+n.block[1].length)]),a=i+n.block[1].length;continue;}let s=/^(?:"(?:[^"\\]|\\.)*"?|'(?:[^'\\]|\\.)*'?)/.exec(r);if(null!==s&&s[0].length>1){l.push(["str",s[0]]),a+=s[0].length;continue;}if(/^\d/.test(r)){var i;let e=/^\d[\w.]*/.exec(r),t=null!=(i=null==e?void 0:e[0])?i:r.charAt(0);l.push(["num",t]),a+=t.length;continue;}let o=/^[@A-Za-z_$][\w$]*/.exec(r);if(null!==o){let t=o[0],n="id";ie.has(t)||ie.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(r);if(null!==c){l.push(["ws",c[0]]),a+=c[0].length;continue;}let d=/^[^\w\s$@"']+/.exec(r);if(null!==d){l.push(["punct",d[0]]),a+=d[0].length;continue;}l.push(["id",r.charAt(0)]),a+=1;}return l;}(t,l,n));return a;}function ia(e){let{text:t}=e,[n,l]=(0,i.useState)("idle"),[r,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,a.jsxs)("div",{className:"sm-code-copy-wrap",children:[(0,a.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,a.jsx)(N.F.copy,{size:13,"aria-hidden":"true"}),(0,a.jsx)("span",{children:c?"Copied":"Copy"})]}),(0,a.jsx)("span",{role:"status",className:"sm-code-copy-status",children:r})]});}function ii(e){var t;let n,{text:l,language:i,codeClass:r,long:s}=e,o=il(l,0===(n=null!=(t=null==i?void 0:i.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":a9(`snippet.${n}`)),c=Math.max(2,String(o.length).length);return(0,a.jsx)("pre",{className:"sm-pre","data-long":s?"true":"false",role:"region","aria-label":`${null!=i?i:"text"} code block`,tabIndex:0,style:{"--sm-code-line-no-width":`${String(c)}ch`},children:(0,a.jsx)("code",{className:r,children:o.map((e,t)=>(0,a.jsxs)("span",{className:"sm-code-line",children:[(0,a.jsx)("span",{className:"sm-code-line-no","aria-hidden":"true",children:t+1}),(0,a.jsx)("span",{className:"sm-code-line-src",children:e.map((e,n)=>(0,a.jsx)("span",{className:`hl-${e[0]}`,children:e[1]},`${String(t)}-${String(n)}`))})]},t))})});}let ir={1:"h3",2:"h4",3:"h5",4:"h6",5:"h6",6:"h6"},is={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 io(e,t,n){return void 0===e.children?null:e.children.map((e,l)=>ic(e,t+"-"+String(l),n));}function ic(e,t,n){let l=function(e,t,n){var l,i;switch(e.kind){case"paragraph":return(0,a.jsx)("p",{className:"sm-p",children:io(e,t,n)},t);case"heading":{let i=null!=(l=e.level)?l:1,r=ir[i],s=is[i];return(0,a.jsx)(r,{className:s,children:io(e,t,n)},t);}case"blockquote":return(0,a.jsx)("blockquote",{className:"sm-blockquote",children:io(e,t,n)},t);case"hr":return(0,a.jsx)("hr",{className:"sm-hr"},t);case"code-block":{let n=e.language,l=null!=(i=e.text)?i:"",r=void 0!==n?`lang-${n}`:void 0,s=(0===l.length?1:l.split(/\r\n|\r|\n/u).length)>24;return(0,a.jsxs)("div",{className:"sm-code-block-frame","data-long":s?"true":"false",children:[(0,a.jsxs)("div",{className:"sm-code-block-header",children:[(0,a.jsx)("span",{className:"sm-code-lang",children:null!=n?n:"text"}),(0,a.jsx)(ia,{text:l})]}),(0,a.jsx)(ii,{text:l,language:n,codeClass:r,long:s})]},t);}default:return null;}}(e,t,n);if(null!==l)return l;let i=function(e,t,n){switch(e.kind){case"ul":return(0,a.jsx)("ul",{className:"sm-ul",children:io(e,t,n)},t);case"ol":return(0,a.jsx)("ol",{className:"sm-ol",children:io(e,t,n)},t);case"li":return(0,a.jsx)("li",{className:"sm-li",children:io(e,t,n)},t);default:return null;}}(e,t,n);if(null!==i)return i;let r=function(e,t,n){let l=void 0!==e.align?{textAlign:e.align}:void 0;switch(e.kind){case"table":return(0,a.jsx)("div",{className:"sm-table-wrapper",children:(0,a.jsx)("table",{className:"sm-table",children:io(e,t,n)})},t);case"thead":return(0,a.jsx)("thead",{children:io(e,t,n)},t);case"tbody":return(0,a.jsx)("tbody",{children:io(e,t,n)},t);case"tr":return(0,a.jsx)("tr",{children:io(e,t,n)},t);case"th":return(0,a.jsx)("th",{style:l,children:io(e,t,n)},t);case"td":return(0,a.jsx)("td",{style:l,children:io(e,t,n)},t);default:return null;}}(e,t,n);if(null!==r)return r;let s=function(e,t,n){var l,i;switch(e.kind){case"text":return function(e,t,n){var l;let i=au(e);if(void 0===n.openRepositoryReference||0===n.repositoryRoots.length)return(0,a.jsx)("span",{children:i},t);let r=function(e){let t=[],n=0;for(at.lastIndex=0;;){var l,a;let i=at.exec(e);if(null===i)break;let r=am(i,e);null!==r&&(i.index>n&&t.push({kind:"text",text:e.slice(n,i.index)}),t.push({kind:"reference",reference:r}),n=i.index+(null!=(l=null==(a=i[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);}(i);return 1===r.length&&(null==(l=r[0])?void 0:l.kind)==="text"?(0,a.jsx)("span",{children:i},t):(0,a.jsx)("span",{children:r.map((e,l)=>{let i=`${t}-repo-${String(l)}`;if("text"===e.kind)return(0,a.jsx)("span",{children:e.text},i);let r=e.reference;return void 0===r?null:(0,a.jsx)(ag,{reference:r,roots:n.repositoryRoots,openReference:n.openRepositoryReference},i);})},t);}(null!=(l=e.text)?l:"",t,n);case"inline-code":let r,s;return r=null!=(i=e.text)?i:"",s=void 0===n.openRepositoryReference||0===n.repositoryRoots.length?null:ah(r),(0,a.jsx)("code",{className:"sm-inline-code",children:null===s?r:(0,a.jsx)(ag,{reference:s,roots:n.repositoryRoots,openReference:n.openRepositoryReference,className:"repo-ref-link repo-ref-link-inline-code"})},t);case"link":return(0,a.jsxs)("a",{href:e.href,className:"sm-link",rel:"noopener noreferrer",target:"_blank",children:[e.text,(0,a.jsx)("span",{className:"sr-only",children:" (opens in new tab)"})]},t);case"strong":return(0,a.jsx)("strong",{children:io(e,t,n)},t);case"em":return(0,a.jsx)("em",{children:io(e,t,n)},t);default:return null;}}(e,t,n);return null!==s?s:null;}function id(e){let{source:t,repositoryRoots:n=[],openRepositoryReference:l}=e,i=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 i=null!=(l=t.lines[t.i])?l:"";if(""===i.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 i=null!=(l=a[1])?l:"```",r=a[2],s=void 0!==r&&r.length>0?r:void 0;return n.push(function(e,t,n){let l=[];for(e.i++;e.i<e.lines.length;){var a,i,r;let n=null!=(a=e.lines[e.i])?a:"",s=/^(`{3,}|~{3,})\s*$/.exec(n.trim());if(null!==s){let n=null!=(i=s[1])?i:"";if(n.startsWith(null!=(r=t[0])?r:"")&&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,i,s)),!0;}(t,i,n)||function(e,t,n){var l,a;let i=/^(#{1,6}) (.+)$/.exec(t.trim());if(null===i)return!1;let r=Math.min((null!=(l=i[1])?l:"").length,6),s=null!=(a=i[2])?a:"";return n.push({kind:"heading",level:r,children:a0(s)}),e.i++,!0;}(t,i,n))return;if(a6(i)){n.push({kind:"hr"}),t.i++;return;}if(i.trimStart().startsWith("> ")||">"===i.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(a5(i.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;}(a2(null!=(a=t.lines[t.i+1])?a:""))&&(n.push(function(e,t){var n,l;let a,i;e.i++;let r=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()||!a5(t.trim()))break;s.push(t),e.i++;}return a=a2(t),i=a2(r).map(a1),{kind:"table",children:[{kind:"thead",children:[{kind:"tr",children:a.map((e,t)=>{var n;let l;return n=i[t],l={kind:"th",children:a0(e.trim())},void 0!==n?{...l,align:n}:l;})}]},{kind:"tbody",children:s.map(e=>({kind:"tr",children:a2(e).map((e,t)=>{var n;let l;return n=i[t],l={kind:"td",children:a0(e.trim())},void 0!==n?{...l,align:n}:l;})}))}]};}(t,i)),1)||(a4(i).match?(n.push(a8(t,!1)),!0):!!a3(i).match&&(n.push(a8(t,!0)),!0)))return;let r=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))||!!a4(e).match||!!a3(e).match||a6(e);}(l))break;t.push(l),e.i++;}return 0===t.length?null:{kind:"paragraph",children:a0(t.join(" "))};}(t);null!==r&&n.push(r);}(a,l);return l;}(t,0),r={repositoryRoots:n,openRepositoryReference:l};return(0,a.jsx)("div",{className:"sm-root",children:i.map((e,t)=>ic(e,String(t),r))});}class iu extends i.Component{static getDerivedStateFromError(){return{failed:!0};}render(){return this.state.failed?(0,a.jsx)("div",{className:"sm-root sm-fallback","data-markdown-fallback":"true",children:this.props.source}):(0,a.jsx)(id,{source:this.props.source,repositoryRoots:this.props.repositoryRoots,openRepositoryReference:this.props.openRepositoryReference});}constructor(...e){super(...e),this.state={failed:!1};}}function ip(e){var t;let{attachment:n,onRemove:l}=e,i=`Remove attachment ${n.name}`,r=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,a.jsxs)("div",{className:"attach-chip",role:"listitem",children:["image"===n.kind&&void 0!==n.previewDataUrl?(0,a.jsx)("img",{src:n.previewDataUrl,alt:"",className:"attach-chip-thumb",width:40,height:40}):(0,a.jsx)("span",{className:"attach-chip-icon","aria-hidden":"true",children:(0,a.jsx)(N.F.file,{size:16})}),(0,a.jsx)("span",{className:"attach-chip-name",title:n.name,children:r}),(0,a.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,a.jsx)("button",{type:"button",className:"attach-chip-remove","aria-label":i,onClick:()=>l(n.id),children:(0,a.jsx)(N.F.close,{size:12})})]});}function im(e){let{attachments:t,onRemove:n}=e;return 0===t.length?null:(0,a.jsx)("div",{className:"attach-strip",role:"list","aria-label":"Pending attachments",children:t.map(e=>(0,a.jsx)(ip,{attachment:e,onRemove:n},e.id))});}function ih(e){let{enabled:t,onFiles:n}=e,[l,r]=(0,i.useState)(!1),[s,o]=(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,o(!0));},l=()=>{0===(e=Math.max(0,e-1))&&o(!1);},a=()=>{e=0,o(!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 c=(0,i.useCallback)(e=>{t&&(e.preventDefault(),r(!0));},[t]),d=(0,i.useCallback)(()=>{r(!1);},[]),u=(0,i.useCallback)(e=>{if(e.preventDefault(),r(!1),!t)return;let l=Array.from(e.dataTransfer.files);l.length>0&&n(l);},[t,n]);return t?(0,a.jsx)("div",{className:"attach-drop-zone","data-dragover":l?"true":void 0,"data-active":s?"true":"false","aria-hidden":"true",onDragOver:c,onDragLeave:d,onDrop:u,children:(0,a.jsx)("span",{className:"attach-drop-hint",children:"Drop files here to attach"})}):null;}let ig="cmp-attach-disabled-hint";function iv(e){let{model:t,onFiles:n,anyModelSupportsAttachments:l=!0}=e,r=(0,i.useRef)(null),s=void 0!==t&&(t.supportsImageInput||t.supportsDocumentInput),o=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),c=(0,i.useCallback)(()=>{var e;s&&(null==(e=r.current)||e.click());},[s]),d=(0,i.useCallback)(()=>{var e,t;let l=Array.from(null!=(e=null==(t=r.current)?void 0:t.files)?e:[]);l.length>0&&(n(l),null!==r.current&&(r.current.value=""));},[n]);return(0,a.jsxs)(a.Fragment,{children:[s?null:(0,a.jsx)("span",{id:ig,className:"sr-only",children:l?"The selected model does not support image or document input. Choose a different model to attach files.":"The selected model does not support image or document input. No configured model currently supports attachments."}),(0,a.jsx)("input",{ref:r,type:"file",multiple:!0,accept:o,className:"sr-only",tabIndex:-1,"aria-hidden":"true",onChange:d}),(0,a.jsx)("button",{type:"button",className:"cmp-icon cmp-tip-start","aria-label":"Attach file","aria-disabled":s?void 0:"true","aria-describedby":s?void 0:ig,"data-tip":s?"Attach file":"Attachments not supported",onClick:c,children:(0,a.jsx)(N.F.files,{size:16})})]});}function ib(e){let{reason:t,mimeType:n}=e;return void 0===t?null:(0,a.jsx)("div",{role:"alert",className:"attach-rejection-alert",children:function(e,t){switch(e){case"text-only-model":return"The selected model can't accept this attachment type. Choose a model that supports images or documents.";case"unsupported-type":return`Unsupported file type${void 0!==t&&t.length>0?`: ${t}`:""}. Supported types: images (image/*), PDF, plain text, markdown, JSON, YAML.`;case"oversized":return"File is larger than the 8 MiB limit. Choose a smaller file or summarize the content as text.";case"empty":return"Empty file. Add a file with content to attach.";}}(t,n)});}function ix(e){let{documents:t}=e;if(0===t.length)return null;let n=t.some(e=>e.truncated);return(0,a.jsxs)("div",{role:"note",className:"sent-docs-note","aria-label":"Documents included as context",children:[(0,a.jsx)("span",{className:"sent-docs-note-label",children:1===t.length?"Document included as context:":"Documents included as context:"}),(0,a.jsx)("ul",{className:"sent-docs-note-list",children:t.map(e=>(0,a.jsxs)("li",{className:"sent-docs-note-item",children:[e.displayName,e.truncated?(0,a.jsx)("span",{className:"sent-docs-note-trunc",children:" (truncated)"}):null]},e.id))}),n?(0,a.jsx)("span",{className:"sent-docs-note-hint",children:"Some document text was truncated to fit the context limit."}):null]});}function iy(e){return"system"===e.role&&"string"==typeof e.runId;}function ij(e){var t,n,l;let{message:r,onOpenResult:s}=e,o=null!=(t=r.workflowStatus)?t:"queued",c=null!=(n=null!=(l=r.workflowId)?l:r.taskType)?n:"workflow",d=void 0===r.runId?"":r.runId.slice(0,8),u=void 0===r.runId?void 0:`/api/evidence/${encodeURIComponent(r.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,a.jsxs)("article",{className:"run-summary-card","data-testid":"run-summary-card","data-status":o,"aria-label":`Workflow run ${c} - ${o}`,children:[(0,a.jsxs)("header",{className:"run-summary-card-head",children:[(0,a.jsx)(N.F.spark,{size:14,style:{color:"var(--accent)"}}),(0,a.jsx)("span",{className:"run-summary-card-workflow mono",children:c}),(0,a.jsx)("span",{className:"run-summary-card-status","data-status":o,children:o})]}),(0,a.jsxs)("div",{className:"run-summary-card-body",children:[(0,a.jsx)("p",{className:"run-summary-card-line",children:r.content}),void 0!==r.shortResult&&r.shortResult.length>0?(0,a.jsx)("p",{className:"run-summary-card-result",children:r.shortResult}):null,void 0!==r.runId?(0,a.jsxs)("p",{className:"run-summary-card-meta mono",children:["run"," ",(0,a.jsx)("span",{className:"run-summary-card-runshort","data-runid":r.runId,title:r.runId,children:d})]}):null,void 0!==r.runId?(0,a.jsxs)("div",{className:"run-summary-card-actions","aria-label":"Workflow result actions",children:[void 0!==s?(0,a.jsx)("button",{type:"button",className:"run-summary-card-action",onClick:()=>s(r),children:"Open result"}):null,void 0!==u?(0,a.jsx)("a",{className:"run-summary-card-action run-summary-card-action-secondary",href:u,target:"_blank",rel:"noreferrer",children:"Evidence"}):null]}):null]}),(0,a.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite","data-testid":"run-summary-card-sr",children:p})]});}function iw(e){let{on:t,onChange:n,label:l}=e;return(0,a.jsx)("button",{type:"button",role:"switch","aria-checked":t,"aria-label":l,className:`auto-toggle${t?" on":""}`,onClick:()=>{n(!t);},children:(0,a.jsx)("span",{})});}var ik=n(29464);let iN="cmp-no-model-alert",iS="cmp-send-hint",iC="cmp-loading-status",iI="Ask Keiko...",iR=/\s*[[【[]\d+[\]】]]/g;async function i$(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 iE(e){let{content:t}=e,[n,l]=(0,i.useState)("idle"),[r,s]=(0,i.useState)(""),o=(0,i.useCallback)(()=>{i$(au(t).replace(iR,"")).then(()=>{l("copied"),s("Answer copied"),setTimeout(()=>{l("idle"),s("");},1500);},()=>{l("failed"),s("Clipboard access failed. Select the answer manually and copy it.");});},[t]),c="copied"===n;return(0,a.jsxs)("div",{className:"chat-msg-copy-wrap",children:[(0,a.jsxs)("button",{type:"button",className:"chat-msg-copy ui-tip","aria-label":c?"Copied":"Copy answer","data-tip":c?"Copied":"Copy answer","data-copied":c?"true":"false","data-failed":"failed"===n?"true":"false",onClick:o,children:[(0,a.jsx)(N.F.copy,{size:13,"aria-hidden":"true"}),(0,a.jsx)("span",{children:c?"Copied":"Copy answer"})]}),(0,a.jsx)("span",{role:"status",className:"chat-msg-copy-status",children:r})]});}function iA(e){var t;let n,l,{message:r,onOpenRunResult:s,repositoryRoots:o,openRepositoryReference:c,streaming:d=!1,layout:u="stack"}=e,p=(0,i.useId)(),[m,h]=(0,i.useState)(!1),f=iy(r),g="user"===r.role,v=!g&&!f&&((t=r.content).length>=1800||t.split(/\r\n|\r|\n/u).length>=32);return f?(0,a.jsx)(ij,{message:r,onOpenResult:s}):(0,a.jsx)("article",{className:"chat-msg","data-role":r.role,"data-layout":u,children:(0,a.jsxs)("div",{className:"chat-msg-bubble",children:[g?(0,a.jsx)("div",{className:"chat-msg-role",children:"You"}):(0,a.jsx)(iF,{}),(0,a.jsxs)("div",{id:g?void 0:p,className:"chat-msg-content","data-collapsed":!g&&m?"true":"false","data-collapsible":v?"true":"false",children:[g?r.content:(0,a.jsx)(iu,{source:r.content,repositoryRoots:o,openRepositoryReference:c}),d&&!g?(0,a.jsx)("span",{className:"ai-stream-cursor","aria-hidden":"true"}):null]}),(0,a.jsxs)("div",{className:"chat-msg-foot",children:[(0,a.jsx)("div",{className:"chat-msg-time",title:new Date(r.timestamp).toLocaleString(),children:(l=(n=new Date(r.timestamp)).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),n.toDateString()===new Date().toDateString()?l:`${n.toLocaleDateString([],{month:"short",day:"numeric"})}, ${l}`)}),g?null:(0,a.jsxs)("div",{className:"chat-msg-actions",children:[(0,a.jsx)(iE,{content:r.content}),v?(0,a.jsxs)("button",{type:"button",className:"chat-msg-collapse","aria-controls":p,"aria-expanded":!m,onClick:()=>{h(e=>!e);},children:[(0,a.jsx)(N.F.chevron,{size:12,"aria-hidden":"true"}),(0,a.jsx)("span",{children:m?"Expand answer":"Collapse answer"})]}):null]})]}),g||void 0===r.groundedAnswer?null:(0,a.jsxs)("div",{className:"chatw-grounded chatw-grounded-inline",children:[(0,a.jsx)(aW,{answer:r.groundedAnswer,busy:!1,repositoryRoots:o,openRepositoryReference:c}),(0,a.jsx)(a_,{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;}}(r.groundedAnswer)})]})]})});}function iF(e){let{pulsing:t=!1}=e;return(0,a.jsx)("div",{className:"chat-msg-brand","data-pulsing":t?"true":"false",role:"img","aria-label":"Keiko logo",children:(0,a.jsx)(l0.default,{src:"/assets/keiko-logo.svg",width:22,height:22,alt:"","aria-hidden":"true"})});}function iT(){return(0,a.jsx)("article",{className:"chat-msg","data-role":"assistant",children:(0,a.jsxs)("div",{className:"chat-msg-bubble",children:[(0,a.jsx)(iF,{pulsing:!0}),(0,a.jsxs)("span",{className:"chat-typing",role:"img","aria-label":"Keiko is responding",children:[(0,a.jsx)("i",{}),(0,a.jsx)("i",{}),(0,a.jsx)("i",{})]})]})});}function iD(e){let{messages:t,onOpenRunResult:n,repositoryRoots:l,openRepositoryReference:r,sending:s,sendStatus:o,activeChat:c,onCancelGrounded:d}=e,u=(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,a.jsxs)("div",{className:"chatw-thread",children:[u.map(e=>(0,a.jsxs)("div",{className:"chat-turn",children:[(0,a.jsx)("div",{className:"chat-turn-cell chat-turn-prompt",children:null!==e.user?(0,a.jsx)(iA,{message:e.user,onOpenRunResult:n,repositoryRoots:l,openRepositoryReference:r,layout:"turn"}):null}),(0,a.jsx)("div",{className:"chat-turn-cell chat-turn-answer",children:e.responses.map((t,i)=>(0,a.jsx)(iA,{message:t,onOpenRunResult:n,repositoryRoots:l,openRepositoryReference:r,layout:"turn",streaming:"streaming"===o&&"assistant"===t.role&&e===u[u.length-1]&&i===e.responses.length-1},t.id))})]},e.id)),s&&"streaming"!==o?(0,a.jsxs)("div",{className:"chat-turn chat-turn-pending",children:[(0,a.jsx)("div",{className:"chat-turn-cell chat-turn-prompt"}),(0,a.jsx)("div",{className:"chat-turn-cell chat-turn-answer",children:(0,a.jsxs)("div",{className:"chatw-typing-row",children:[(0,a.jsx)(iT,{}),iX(c)?(0,a.jsx)("button",{type:"button",className:"grounded-cancel-btn","aria-label":"Cancel grounded request",onClick:d,children:"Cancel"}):null]})})]}):null]});}function iM(e){return void 0!==e.connectedScopes?e.connectedScopes:void 0!==e.connectedScope?[e.connectedScope]:[];}function iP(e,t){var n;let l=Math.max(0,Math.min(t,e.length)),a=e.slice(0,l),i=a.lastIndexOf("@");if(i<0)return null;let r=0===i?"":null!=(n=a[i-1])?n:"";if(r.length>0&&!/\s|[(\[{]/u.test(r))return null;let s=a.slice(i+1);return s.includes("@")||/\s/u.test(s)?null:{start:i,end:l,query:s};}function iq(e){return n4(e,"Unable to reference repository file.");}function iL(e){var t,n;let{roots:l,selectedRoot:i,onRootChange:r,search:s,pickingPath:o,highlightedIndex:c,pickError:d,onPick:u,onClose:p}=e,m=null!=(t=l.find(e=>e.root===i))?t:l[0],h=null!=d?d:s.error,f=e=>{e.stopPropagation();};return(0,a.jsxs)("div",{className:"repo-focus-popover",role:"dialog","aria-label":"Reference repository file",onPointerDown:f,onMouseDown:f,children:[(0,a.jsxs)("div",{className:"repo-focus-head",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("span",{className:"repo-focus-title",children:"Repository file"}),(0,a.jsx)("span",{className:"repo-focus-subtitle",children:null!=(n=null==m?void 0:m.label)?n:"Connected source"})]}),(0,a.jsx)("button",{type:"button",className:"repo-focus-close","aria-label":"Close repository file picker",onClick:p,children:(0,a.jsx)(N.F.close,{size:13})})]}),l.length>1?(0,a.jsx)(nd,{triggerClassName:"repo-focus-source-select",value:i,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:r}):null,(0,a.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,a.jsx)("div",{className:"repo-focus-results",role:"listbox","aria-label":"Repository file results",children:s.results.map((e,t)=>(0,a.jsxs)("button",{type:"button",className:"repo-focus-result",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,a.jsx)("span",{className:"repo-focus-result-name",children:e.name}),(0,a.jsx)("span",{className:"repo-focus-result-path",children:0===e.directory.length?"Repository root":e.directory})]},`${e.root}:${e.path}`))}):null]});}function iz(e){let{session:t,ready:n,selectedModelCapability:l,onAttachFiles:i,compact:r=!1,controlsNarrow:s=!1,barCompact:o=!1,budgetExceeded:c}=e,{models:d,selectedModel:u,setSelectedModel:p,draft:m,noEligibleModels:h,loading:f,sending:g,cancelSend:v}=t,b=h||c||!n,x=0===m.trim().length,y=h?iN:void 0,j=h?iN:c?l1:f?iC:x?iS:void 0,w=f||h?"":null!=u?u:"",k=f?"Loading models…":h?"No conversation-eligible model":"Change model";return(0,a.jsxs)("div",{className:`cmp-bar${o?" cmp-bar-compact":""}`,children:[(0,a.jsxs)("div",{className:"cmp-bar-main",children:[(0,a.jsx)(iv,{model:l,onFiles:i,anyModelSupportsAttachments:d.some(e=>e.supportsImageInput||e.supportsDocumentInput)}),(0,a.jsx)("div",{className:`cmp-model mono ui-tip${s?" cmp-model-compact":" cmp-pill-standard"}`,"data-tip":s?k:void 0,children:(0,a.jsx)(nd,{triggerClassName:"cmp-model-select",value:w,ariaLabel:"Models",ariaDescribedBy:y,disabled:f,placeholder:f?"Loading models…":h?"No conversation-eligible model":"Models",leadingVisual:(0,a.jsx)(N.F.cube,{size:s?16:13,style:{color:"var(--accent)"}}),menuTitle:"Models",menuClassName:"cmp-model-menu",menuMinWidth:s?118:280,mono:!0,sections:[{options:f?[{value:"",label:"Loading models…",disabled:!0}]:h?[{value:"",label:"No conversation-eligible model",disabled:!0}]:d.filter(e=>"chat"===e.kind).map(e=>({value:e.id,label:e.id}))}],onValueChange:e=>{h||f||p(e);}})}),null]}),j===iS?(0,a.jsx)("span",{id:iS,className:"sr-only",children:"Type a message to send"}):null,g?(0,a.jsx)("button",{type:"button",className:"cmp-send cmp-send-cancel cmp-tip-end","data-on":!0,"aria-label":"Cancel response","data-tip":"Cancel response",onClick:v,children:(0,a.jsx)(N.F.close,{size:16})}):(0,a.jsx)("button",{type:b?"button":"submit",className:"cmp-send cmp-tip-end","data-on":!b,"data-tip":h?"No model available":c?"Context too large":f?"Connecting to gateway":"Send message","aria-disabled":b,"aria-describedby":j,"aria-label":"Send message",children:(0,a.jsx)(N.F.arrowUp,{size:16})})]});}function iO(){return(0,a.jsx)("div",{id:iN,role:"alert",className:"gw-error cmp-no-model",children:"No conversation-eligible model is configured. Connect a gateway in Settings to enable chat."});}function iK(){return(0,a.jsxs)("div",{id:iC,role:"status",className:"cmp-loading-status",children:[(0,a.jsx)("span",{className:"cmp-loading-dot","aria-hidden":"true"}),"Connecting to your gateway…"]});}function iW(e){let{status:t}=e,n=function(e){switch(e){case"idle":case"completed":case"failed":return"";case"queued":return"Submitting your message…";case"contacting":return"Contacting model…";case"streaming":return"Receiving response…";case"cancelled":return"Response cancelled.";}}(t);return(0,a.jsx)("div",{role:"status","aria-live":"polite","data-send-status":t,className:"cmp-send-status",children:0===n.length?null:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{className:"cmp-loading-dot","aria-hidden":"true"}),n]})});}function iB(e){var t,n,l,r;let{session:s,ready:o,placeholder:c,minimal:d=!1,compact:u=!1,controlsNarrow:p=!1,barCompact:m=!1}=e,{draft:h,loading:f,sending:g,sendStatus:v,setDraft:b,sendMessage:x,models:y,selectedModel:j,pendingAttachments:w,addPendingAttachment:N,removePendingAttachment:S,budget:C,clearHistory:I,activeChat:R,activeProject:$,replaceChat:E}=s,A=lg(C),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`);},[h]);let[T,D]=(0,i.useState)(),[M,P]=(0,i.useState)(),q=y.find(e=>e.id===j),L=void 0!==q&&(q.supportsImageInput||q.supportsDocumentInput),z=(0,i.useCallback)(async e=>{let t,n;for(let l of e){let e=await N(l);e.ok||void 0!==t||(t=e.reason,n=l.type);}D(t),P(n);},[N]),O=(0,i.useMemo)(()=>function(e,t){if(void 0===e)return[];let n=null!=t?t:e.projectPath,l=new Set(),a=[];for(let t of iM(e)){var i;let e=null!=(i=t.root)?i:n;0===e.length||l.has(e)||(l.add(e),a.push({root:e,label:function(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;}(e)}));}return a;}(R,null==$?void 0:$.path),[R,null==$?void 0:$.path]),K=O.map(e=>e.root).join("\x01"),[W,B]=(0,i.useState)(null!=(t=null==(r=O[0])?void 0:r.root)?t:""),[U,_]=(0,i.useState)(null),[V,J]=(0,i.useState)(null),[H,Y]=(0,i.useState)(null),[X,G]=(0,i.useState)(0),Q=null!==U&&O.length>0,Z=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 i=!1;return s(!0),u(null),c("Searching repository files..."),(0,k.Gb)(t,l,24).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 the query for more.":"."}`);}}).catch(e=>{i||(a([]),u(iq(e)),c("Repository search failed."));}).finally(()=>{i||s(!1);}),()=>{i=!0;};},[e,n,t]),{results:l,searching:r,message:o,error:d};}(Q,W,null!=(n=null==U?void 0:U.query)?n:"");(0,i.useEffect)(()=>{if(0===O.length){B(""),_(null);return;}if(!O.some(e=>e.root===W)){var e,t;B(null!=(e=null==(t=O[0])?void 0:t.root)?e:"");}},[K,O,W]),(0,i.useEffect)(()=>{G(0);},[null==U?void 0:U.query,Z.results]);let ee=(0,i.useCallback)((e,t)=>{if(0===O.length)return void _(null);let n=iP(e,t);_(n),null!==n&&Y(null);},[O.length]),et=(0,i.useCallback)(async e=>{if(void 0!==R){J(e.path),Y(null);try{var t,n,l;let a,i,r,s,o,c=function(e,t,n){let l=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Date.now,a=n.replace(/\\/gu,"/").replace(/^\/+/u,"").replace(/\/+$/u,"");if(0===a.length)throw Error("Select a repository file first.");let i=iM(e),r=[],s=!1,o=!1;for(let n of i){var c;let i=null!=(c=n.root)?c:e.projectPath;if("files"===n.kind&&i===t){if(s=!0,n.relativePaths.includes(a)){r.push(n);continue;}if(n.relativePaths.length>=50)throw Error(`This Files source already references ${String(50)} files.`);r.push({...n,root:t,relativePaths:[...n.relativePaths,a],connectedAtMs:l()}),o=!0;continue;}r.push(n);}return s||(r.push({kind:"files",root:t,relativePaths:[a],connectedAtMs:l()}),o=!0),{scopes:r,changed:o};}(R,e.root,e.path);if(c.changed){let e=await(0,k.wi)(R.id,{connectedScopes:c.scopes});E(e.chat);}let d=null!=(t=null==(n=F.current)?void 0:n.selectionStart)?t:h.length,u=null!=U?U:iP(h,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}`;}(h,e.path),cursor:a.length}:(l=e.path,i=`@${l}`,r=h.slice(0,u.start),s=h.slice(u.end),o=0!==s.length&&/^[\s.,;:!?)}\]]/u.test(s)?i:`${i} `,{value:`${r}${o}${s}`,cursor:r.length+o.length});b(p.value),_(null),requestAnimationFrame(()=>{var e,t;null==(e=F.current)||e.focus(),null==(t=F.current)||t.setSelectionRange(p.cursor,p.cursor);});}catch(e){Y(iq(e));}finally{J(null);}}},[R,h,E,U,b]),en=(0,i.useCallback)(e=>{var t;let n=e.target.value;b(n),ee(n,null!=(t=e.target.selectionStart)?t:n.length);},[b,ee]),el=(0,i.useCallback)(e=>{var t;if(null===U)return;let n=e.currentTarget;ee(n.value,null!=(t=n.selectionStart)?t:n.value.length);},[U,ee]),ea=(0,i.useCallback)(e=>{var t;if(Q){if("Escape"===e.key){e.preventDefault(),_(null);return;}if("ArrowDown"===e.key&&Z.results.length>0){e.preventDefault(),G(e=>Math.min(Z.results.length-1,e+1));return;}if("ArrowUp"===e.key&&Z.results.length>0){e.preventDefault(),G(e=>Math.max(0,e-1));return;}if(("Enter"===e.key||"Tab"===e.key)&&Z.results.length>0){e.preventDefault();let n=null!=(t=Z.results[X])?t:Z.results[0];void 0!==n&&et(n);return;}}(e=>{!e.nativeEvent.isComposing&&("Enter"!==e.key||e.shiftKey||(e.preventDefault(),x()));})(e);},[et,X,Q,Z.results,x]);return(0,a.jsxs)("div",{className:`cmp-box${u?" cmp-box-compact":""}`,children:[(0,a.jsxs)("div",{className:"cmp-input-stack",children:[(0,a.jsx)(ih,{enabled:L,onFiles:z}),(0,a.jsx)("textarea",{className:"cmp-input",ref:F,rows:2,value:h,"aria-label":"Chat message",placeholder:c,onChange:en,onSelect:el,onKeyDown:ea}),Q?(0,a.jsxs)("div",{className:"repo-focus repo-focus-inline",children:[(0,a.jsx)("span",{className:"sr-only",role:"status","aria-live":"polite",children:null!=(l=null!=H?H:Z.error)?l:Z.message}),(0,a.jsx)(iL,{roots:O,selectedRoot:W,onRootChange:e=>{B(e),G(0);},search:Z,pickingPath:V,highlightedIndex:X,pickError:H,onPick:e=>{et(e);},onClose:()=>_(null)})]}):null,(0,a.jsx)(im,{attachments:w,onRemove:S}),(0,a.jsx)(ib,{reason:T,mimeType:M}),(0,a.jsx)(iW,{status:v})]}),(0,a.jsxs)("div",{className:"cmp-footer-row",children:[d?null:(0,a.jsx)(l6,{budget:C,onClearHistory:I,disabled:g||f,compact:u}),(0,a.jsx)(iz,{session:s,ready:o,selectedModelCapability:q,onAttachFiles:z,compact:u,controlsNarrow:p,barCompact:m,budgetExceeded:A})]})]});}function iU(e){let{minimal:t=!1}=e;return t?(0,a.jsx)("div",{className:"chatw-empty chatw-empty-minimal",role:"note","aria-label":"Conversation ready",children:(0,a.jsx)("h2",{className:"chatw-empty-headline",children:"How can I help you today?"})}):(0,a.jsx)("div",{className:"chatw-empty",children:(0,a.jsx)("h2",{className:"chatw-empty-headline",children:"How can I help you today?"})});}function i_(){return(0,a.jsxs)("div",{className:"chatw-empty-no-chat",children:[(0,a.jsx)("div",{className:"chatw-empty-no-chat-icon","aria-hidden":"true",children:(0,a.jsx)(N.F.spark,{size:20})}),(0,a.jsx)("p",{className:"chatw-empty-no-chat-label",children:"Pick or start a chat"}),(0,a.jsx)("p",{className:"chatw-empty-no-chat-hint",children:"Select a conversation from the project sidebar, or create a new one to get started."})]});}function iV(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 iJ(e){var t,n;if(iV(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}`:iY(e)?"files":"none";}function iH(e){return void 0!==e.localKnowledgeScopes?e.localKnowledgeScopes:void 0!==e.localKnowledgeScope?[e.localKnowledgeScope]:[];}function iY(e){return void 0!==e&&(void 0!==e.connectedScope||void 0!==e.connectedScopes&&e.connectedScopes.length>0);}function iX(e){return iY(e)||void 0!==e&&(void 0!==e.localKnowledgeScope||void 0!==e.localKnowledgeScopes&&e.localKnowledgeScopes.length>0);}function iG(e){return n4(e,"Unable to update knowledge scope.");}function iQ(e){let{chat:t,onChatChanged:n,catalog:l,connected:r}=e,{capsules:s,capsuleSets:o,loadError:c}=l,[d,u]=(0,i.useState)(!1),[p,m]=(0,i.useState)(null);async function h(e){u(!0),m(null);try{if("none"===e){let e=iV(t);if(e>0&&!window.confirm(`This will disconnect ${String(e)} grounding ${1===e?"source":"sources"}. Continue?`))return;let l=await(0,k.wi)(t.id,{connectedScopes:null,localKnowledgeScopes:null});n(l.chat);return;}if("files"===e){let e=await(0,k.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=iH(t),i=a.some(e=>"capsule-set"===e.kind&&e.capsuleSetId===l.capsuleSetId)?a:[...a,l],r=await(0,k.wi)(t.id,{localKnowledgeScopes:i});n(r.chat);return;}if(e.startsWith("capsule:")){let l={kind:"capsule",capsuleId:e.slice(8),connectedAtMs:Date.now()},a=iH(t),i=a.some(e=>"capsule"===e.kind&&e.capsuleId===l.capsuleId)?a:[...a,l],r=await(0,k.wi)(t.id,{localKnowledgeScopes:i});n(r.chat);}}catch(e){m(iG(e));}finally{u(!1);}}let f=iJ(t),g=function(e,t){let n=t.map(e=>({value:`capsule:${e.id}`,label:`Knowledge capsule: ${e.displayName}`})),l=iJ(e);if(!l.startsWith("capsule:")||n.some(e=>e.value===l))return n;let a=l.slice(8);return[...n,{value:l,label:`Knowledge capsule: ${a} (unavailable)`}];}(t,s),v=function(e,t){let n=t.map(e=>({value:`capsule-set:${e.id}`,label:`Capsule set: ${e.displayName}`})),l=iJ(e);if(!l.startsWith("capsule-set:")||n.some(e=>e.value===l))return n;let a=l.slice(12);return[...n,{value:l,label:`Capsule set: ${a} (unavailable)`}];}(t,o),b=null!=p?p:c;return(0,a.jsxs)("div",{className:"scope-grounding","data-connected":r?"true":"false",children:[(0,a.jsx)("span",{className:"scope-grounding-label mono",children:"Grounding"}),(0,a.jsx)(nd,{triggerClassName:"scope-grounding-select",value:f,disabled:d,ariaLabel:"Grounding mode",menuTitle:"Strategy",sections:[{options:[{value:"none",label:"Model only"},{value:"files",label:"Live Files context",disabled:!iY(t)},...("multi"===f?[{value:"multi",label:"Multiple sources",disabled:!0}]:[]),...g.map(e=>({value:e.value,label:e.label})),...v.map(e=>({value:e.value,label:e.label}))]}],onValueChange:e=>{h(e);}}),null!==b?(0,a.jsx)("span",{role:"alert",className:"scope-connect-error",children:b}):null]});}function iZ(e){let{chat:t,onChatChanged:n}=e,l=function(){let[e,t]=(0,i.useState)([]),[n,l]=(0,i.useState)([]),[a,r]=(0,i.useState)(null);return(0,i.useEffect)(()=>{let e=!1;return async function(){try{let[n,a]=await Promise.allSettled([(0,ik.xr)(),(0,ik.R3)()]);if("fulfilled"!==n.status)throw n.reason;if(e)return;t(n.value.capsules.filter(e=>"ready"===e.lifecycleState)),"fulfilled"===a.status?l(a.value.capsuleSets):(l([]),r(iG(a.reason)));}catch(t){e||r(iG(t));}}(),()=>{e=!0;};},[]),{capsules:e,capsuleSets:n,loadError:a};}(),r=iX(t);return(0,a.jsx)("div",{className:"chat-scope-header","data-grounded":r?"true":"false",children:(0,a.jsx)(iQ,{chat:t,onChatChanged:n,catalog:l,connected:r})});}function i0(e){let{chat:t,busy:n}=e;return void 0!==t&&iX(t)&&n?(0,a.jsx)("div",{className:"chatw-grounded",children:(0,a.jsx)(aW,{answer:void 0,busy:n})}):null;}function i1(e){let{action:t,acceptCandidate:n,rejectCandidate:l,forgetMemoryAction:r,onActionSettled:s}=e,[o,c]=(0,i.useState)(!1),[d,u]=(0,i.useState)(),[p,m]=(0,i.useState)(!1),h=(0,i.useCallback)((e,t,n)=>{o||(c(!0),u(void 0),e().then(()=>{s(t);}).catch(e=>{u(e instanceof Error?e.message:n);}).finally(()=>c(!1)));},[o,s]);if("candidate"===t.kind)return(0,a.jsxs)("article",{className:"chat-memory-action",children:[(0,a.jsxs)("div",{className:"chat-memory-action-head",children:[(0,a.jsx)("strong",{children:t.scopeLabel}),(0,a.jsx)("span",{children:t.requiresApproval?"Approval required":"Proposed memory"})]}),(0,a.jsx)("p",{children:t.body}),(0,a.jsxs)("div",{className:"chat-memory-action-buttons",children:[(0,a.jsx)("button",{type:"button","aria-disabled":o,"aria-busy":o,onClick:()=>{h(()=>n(t.proposalId),"MemoriaViva proposal accepted.","Unable to accept memory.");},children:"Accept"}),(0,a.jsx)("button",{type:"button","aria-disabled":o,"aria-busy":o,onClick:()=>{h(()=>l(t.proposalId),"MemoriaViva proposal rejected.","Unable to reject memory.");},children:"Reject"})]}),void 0!==d?(0,a.jsx)(l7,{error:d,fallback:"Unable to update memory.",onDismiss:()=>u(void 0)}):null]});if("update"===t.kind)return(0,a.jsxs)("article",{className:"chat-memory-action",children:[(0,a.jsxs)("div",{className:"chat-memory-action-head",children:[(0,a.jsx)("strong",{children:"MemoriaViva update detected"}),(0,a.jsx)("span",{children:t.memoryId})]}),(0,a.jsx)("p",{children:void 0!==t.bodyPatch?`Suggested update: ${t.bodyPatch}`:"Suggested update."})]});if("forget"===t.kind){let e=()=>{h(()=>r(t.memoryId).then(()=>m(!1)),"MemoriaViva forget action completed.","Unable to forget memory.");};return(0,a.jsxs)("article",{className:"chat-memory-action",children:[(0,a.jsxs)("div",{className:"chat-memory-action-head",children:[(0,a.jsx)("strong",{children:"MemoriaViva forget detected"}),(0,a.jsx)("span",{children:t.requiresConfirmation?"Confirmation required":t.memoryId})]}),(0,a.jsx)("p",{children:`Matched memory ${t.memoryId} for a forget operation.`}),(0,a.jsx)("div",{className:"chat-memory-action-buttons",children:t.requiresConfirmation?p?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button","aria-disabled":o,"aria-busy":o,onClick:e,children:"Forget permanently"}),(0,a.jsx)("button",{type:"button","aria-disabled":o,"aria-busy":o,onClick:()=>{o||(u(void 0),m(!1));},children:"Cancel"})]}):(0,a.jsx)("button",{type:"button","aria-disabled":o,"aria-busy":o,onClick:()=>{o||(u(void 0),m(!0));},children:"Review forget"}):(0,a.jsx)("button",{type:"button","aria-disabled":o,"aria-busy":o,onClick:e,children:"Forget"})}),void 0!==d?(0,a.jsx)(l7,{error:d,fallback:"Unable to update memory.",onDismiss:()=>u(void 0)}):null]});}return"rejected"===t.kind?(0,a.jsxs)("article",{className:"chat-memory-action",children:[(0,a.jsx)("div",{className:"chat-memory-action-head",children:(0,a.jsx)("strong",{children:"Memory proposal declined"})}),(0,a.jsx)("p",{children:""!==t.reason?t.reason:"No reason provided"})]}):(0,a.jsx)("article",{className:"chat-memory-action",children:(0,a.jsx)("div",{className:"chat-memory-action-head",children:(0,a.jsx)("strong",{children:"MemoriaViva action not created"})})});}function i2(e){var t;let{memoryEnabled:n,setMemoryEnabled:l,memoryBudgetTokens:r,setMemoryBudgetTokens:s,latestMemory:o,acceptCandidate:c,rejectCandidate:d,forgetMemoryAction:u,compact:p=!1}=e,[m,h]=(0,i.useState)(!1),[f,g]=(0,i.useState)(""),v=(0,i.useId)(),b=`${v}-chat-memory-disclosure`,x=(0,i.useRef)(null),y=(0,i.useCallback)(e=>{var t;g(e),null==(t=x.current)||t.focus();},[]),j=null!=(t=null==o?void 0:o.context.memories.length)?t:0,w=j>0?`${String(j)} memories included`:"No memories included",k=e=>{s(Math.max(0,r+e));},S=(0,a.jsxs)("label",{className:"chat-memory-budget",children:[(0,a.jsx)("span",{children:"Budget (tokens)"}),(0,a.jsxs)("span",{className:"number-control number-control-pill",children:[(0,a.jsx)("input",{type:"number",className:"number-control-input",min:0,step:100,value:r,onChange:e=>s(Math.max(0,Number(e.target.value)||0)),onWheel:e=>{0===e.deltaY||(e.preventDefault(),k(100*(e.deltaY<0?1:-1)));}}),(0,a.jsx)(aV,{label:"memory budget",onStepUp:()=>k(100),onStepDown:()=>k(-100)})]})]});return(0,a.jsxs)("section",{className:"chat-memory-panel","aria-label":"Conversation memory",children:[(0,a.jsxs)("div",{className:"chat-memory-panel-head",children:[(0,a.jsxs)("div",{className:"chat-memory-toggle",children:[(0,a.jsx)(iw,{on:n,onChange:l,label:"Enable MemoriaViva for the next request"}),(0,a.jsxs)("span",{children:["MemoriaViva ",n?"on":"off"]})]}),p?null:S,(0,a.jsx)("button",{ref:x,type:"button",className:`chip${p?" chip-icon chat-memory-disclosure-toggle ui-tip cmp-tip-end":""}`,"aria-expanded":m,"aria-controls":b,"aria-label":w,"data-tip":p?w:void 0,onClick:()=>h(e=>!e),children:p?(0,a.jsx)(N.F.brainSlash,{size:16,style:{color:"var(--accent)"}}):w})]}),m?(0,a.jsxs)("div",{id:b,className:"chat-memory-disclosure",children:[(0,a.jsx)("p",{className:"chat-memory-summary",children:void 0===o?"MemoriaViva disclosure appears after the next response.":o.context.enabled?`Used ${String(o.context.budget.used)} of ${String(o.context.budget.tokens)} MemoriaViva tokens.`:"MemoriaViva was disabled for the last request."}),null==o?void 0:o.context.memories.map(e=>(0,a.jsxs)("article",{className:"chat-memory-item",children:[(0,a.jsxs)("div",{className:"chat-memory-item-head",children:[(0,a.jsx)("strong",{children:e.memoryId}),(0,a.jsx)("span",{children:e.inclusionReason})]}),(0,a.jsx)("p",{children:e.bodyExcerpt}),(0,a.jsxs)("dl",{className:"chat-memory-meta","aria-label":`Provenance for ${e.memoryId}`,children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Source"}),(0,a.jsx)("dd",{children:e.sourceKind})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Sensitivity"}),(0,a.jsx)("dd",{children:e.sensitivity})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Status"}),(0,a.jsx)("dd",{children:e.status})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Confidence"}),(0,a.jsx)("dd",{children:`${String(Math.round(100*e.confidence))}%`})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Captured"}),(0,a.jsx)("dd",{children:new Date(e.capturedAt).toISOString().slice(0,10)})]})]}),void 0!==e.captureRationale?(0,a.jsx)("p",{className:"chat-memory-rationale",children:e.captureRationale}):null]},e.memoryId)),null==o?void 0:o.actions.map(e=>(0,a.jsx)(i1,{action:e,acceptCandidate:c,rejectCandidate:d,forgetMemoryAction:u,onActionSettled:y},"candidate"===e.kind?e.proposalId:"rejected"===e.kind?e.reason:e.memoryId)),(0,a.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite","aria-atomic":"true",children:f})]}):null]});}function i4(e){let{mini:t=!1,minimalChat:n=!1,compact:l=!1,controlsNarrow:r=!1,barCompact:s=!1,workflowCompact:c=!1,linkedRoot:d=null,linkedRoots:u=[],openEditorFile:p,onOpenRunResult:m}=e,h=o(),{messages:f,draft:g,loading:v,sending:b,sendStatus:x,error:y,noEligibleModels:j,selectedModel:w,sendMessage:k,cancelGrounded:N,activeChat:S,replaceChat:C,latestMemory:I,lastSentDocuments:R,memoryEnabled:$,setMemoryEnabled:E,memoryBudgetTokens:A,setMemoryBudgetTokens:F,acceptMemoryCandidate:T,rejectMemoryCandidate:D,forgetMemoryAction:M}=h,P=g.trim().length>0&&!b&&!v&&!j,q=f.filter(e=>"user"===e.role||"assistant"===e.role&&e.content.length>0||iy(e)),L=(0,i.useRef)(null),z=(0,i.useMemo)(()=>{var e=u.length>0?u:null===d?[]:[d];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:af(e)}));}return n;},[d,u]),O=(0,i.useRef)(!0),K=(0,i.useRef)(!1),W=q.length>0?q[q.length-1]:void 0,B=void 0===W?"":W.content,U=l||t,_=r||t||n||c,V=s||n;return(0,i.useEffect)(()=>{b&&!K.current&&(O.current=!0),K.current=b;let e=L.current;null!==e&&O.current&&(e.scrollTop=e.scrollHeight);},[q.length,b,B]),(0,a.jsxs)("div",{className:`chatw${U?" chatw-compact":""}${n?" chatw-minimal":""}`,children:[void 0!==S?(0,a.jsx)(iZ,{chat:S,onChatChanged:C}):null,void 0!==S?(0,a.jsx)(i2,{memoryEnabled:$,setMemoryEnabled:E,memoryBudgetTokens:A,setMemoryBudgetTokens:F,latestMemory:I,acceptCandidate:T,rejectCandidate:D,forgetMemoryAction:M,compact:U||n}):null,j?(0,a.jsx)("div",{className:"chatw-foot",children:(0,a.jsx)(iO,{})}):null,v?(0,a.jsx)("div",{className:"chatw-foot",children:(0,a.jsx)(iK,{})}):null,(0,a.jsx)("div",{className:"chatw-scroll",ref:L,role:"log","aria-label":"Conversation",tabIndex:0,onScroll:e=>{let t=e.currentTarget;O.current=t.scrollHeight-t.scrollTop-t.clientHeight<64;},children:0===q.length?void 0!==S?(0,a.jsx)(iU,{minimal:n}):(0,a.jsx)(i_,{}):(0,a.jsxs)("div",{className:"chatw-log",children:[(0,a.jsx)(iD,{messages:q,onOpenRunResult:m,repositoryRoots:z,openRepositoryReference:p,sending:b,sendStatus:x,activeChat:S,onCancelGrounded:N}),(0,a.jsx)(i0,{chat:S,busy:b}),(0,a.jsx)(ix,{documents:R})]})}),q.length>0?(0,a.jsx)("div",{className:"chatw-foot",children:(0,a.jsxs)("form",{className:`composer${U?" composer-chat-compact":""}`,onSubmit:e=>{e.preventDefault(),k();},children:[(0,a.jsx)(iB,{session:h,ready:P,placeholder:iI,minimal:n,compact:U,controlsNarrow:_,barCompact:V}),void 0!==y?(0,a.jsx)(l7,{error:y,fallback:"Could not send message.",onDismiss:h.clearError}):null]})}):null,0===q.length&&void 0!==S?(0,a.jsx)("div",{className:"chatw-foot",children:(0,a.jsxs)("form",{className:`composer${U?" composer-chat-compact":""}`,onSubmit:e=>{e.preventDefault(),k();},children:[(0,a.jsx)(iB,{session:h,ready:P,placeholder:v?"Connecting to your gateway…":iI,minimal:n,compact:U,controlsNarrow:_,barCompact:V}),void 0!==y?(0,a.jsx)(l7,{error:y,fallback:"Could not send message.",onDismiss:h.clearError}):null]})}):null,0===q.length&&void 0!==y&&void 0===S?(0,a.jsx)("div",{className:"chatw-foot",children:(0,a.jsx)(l7,{error:y,fallback:"Could not load chat.",onDismiss:h.clearError})}):null]});}let i3=new Set(["ArrowDown","ArrowUp","ArrowRight","ArrowLeft","Home","End"]);function i5(e){return Array.from(e.querySelectorAll("button[role='treeitem']"));}function i6(e){let{project:t,activeProjectPath:n,chats:l,activeChatId:r,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,a.jsxs)("div",{className:"proj",children:[(0,a.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&&i5(c.current).forEach(e=>{e.tabIndex=-1;});},children:[(0,a.jsx)("span",{className:"proj-caret","data-open":u,"aria-hidden":"true",children:(0,a.jsx)(N.F.chevronR,{size:13})}),(0,a.jsx)(N.F.folder,{size:15,"aria-hidden":"true"}),(0,a.jsx)("span",{className:"proj-name",children:t.name}),(0,a.jsx)("span",{className:"chat-time",children:m})]}),u&&(0,a.jsx)("div",{className:"proj-chats",role:"group","aria-label":t.name,children:d?0===l.length?(0,a.jsx)("div",{className:"proj-empty",children:"No chats"}):l.map(e=>(0,a.jsxs)("button",{type:"button",role:"treeitem","aria-level":2,"aria-selected":r===e.id,className:"chat-row","data-active":r===e.id,tabIndex:-1,onClick:()=>{o(e);},children:[(0,a.jsx)("span",{className:"chat-title",children:e.title}),void 0!==e.branchLabel?(0,a.jsx)("span",{className:"chat-meta mono",children:e.branchLabel}):null]},e.id)):(0,a.jsx)("div",{className:"proj-empty",children:"Select project to load chats"})})]});}function i8(){let e=o(),t=(0,i.useRef)(null);return(0,a.jsxs)("div",{className:"tw-scroll",children:[(0,a.jsx)("div",{className:"sb-section",children:(0,a.jsx)("span",{className:"sb-section-label",children:"Projects"})}),0===e.projects.length?(0,a.jsx)("div",{className:"proj-empty",children:"No registered projects"}):(0,a.jsx)("div",{className:"proj-tree",role:"tree","aria-label":"Projects",tabIndex:-1,ref:t,onKeyDown:e=>{i3.has(e.key)&&null!==t.current&&function(e,t){var n,l,a,i,r,s,o,c,d;let u=i5(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==(i=u[u.length-1])||i.focus();else if("ArrowRight"===f)"false"===m.getAttribute("aria-expanded")?m.click():"true"===m.getAttribute("aria-expanded")&&(null==(r=u[h+1])||r.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,i,r;return(0,a.jsx)(i6,{project:n,activeProjectPath:null==(l=e.activeProject)?void 0:l.path,chats:(null==(i=e.activeProject)?void 0:i.path)===n.path?e.chats:[],activeChatId:null==(r=e.activeChat)?void 0:r.id,treeRef:t,onProject:t=>{e.openProject(t);},onChat:t=>{e.openChat(t);}},n.path);})})]});}function i7(e){let{openChatWindow:t}=e,n=o(),[l,r]=(0,i.useState)(""),[s,c]=(0,i.useState)("active"),[d,u]=(0,i.useState)(null),[p,m]=(0,i.useState)(""),[h,f]=(0,i.useState)(null),[g,v]=(0,i.useState)(null),[b,x]=(0,i.useState)(null),[y,j]=(0,i.useState)(null),w=(0,i.useRef)(null),S=(0,i.useId)(),C=(0,i.useId)(),I=(0,i.useId)(),R=(0,i.useId)(),$=(0,i.useMemo)(()=>n.chats.filter(e=>"closed"!==e.status).length,[n.chats]),E=n.chats.length-$,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=w.current)||e.focus({preventScroll:!0}));},[d]);let F=async()=>{x(null);let e=await n.openNewChat(void 0,"New chat");void 0!==e&&t(e);},T=e=>{u(e.id),m(e.title),f(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=w.current)||l.focus({preventScroll:!0});return;}if(t===e.title){u(null),j(null);return;}v(e.id),x(null),j(null);try{let l=await(0,k.wi)(e.id,{title:t});n.replaceChat(l.chat),u(null);}catch{x("Rename failed.");}finally{v(null);}},M=async e=>{v(e.id),x(null);try{let t=await(0,k.wi)(e.id,{status:"closed"});n.replaceChat(t.chat),f(null);}catch(t){let e=t instanceof Error?t.message:"Request failed.";x(`Delete failed: ${e}`);}finally{v(null);}},P=async e=>{v(e.id),x(null);try{let t=await(0,k.wi)(e.id,{status:"open"});n.replaceChat(t.chat),f(null);}catch(t){let e=t instanceof Error?t.message:"Request failed.";x(`Restore failed: ${e}`);}finally{v(null);}};return(0,a.jsxs)("div",{className:"chat-history",children:[(0,a.jsxs)("div",{className:"chat-history-head",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"chat-history-kicker",children:"Conversations"}),(0,a.jsx)("h2",{children:"Chat History"})]}),(0,a.jsxs)("button",{type:"button",className:"lk-btn lk-btn-primary",onClick:()=>void F(),children:[(0,a.jsx)(N.F.newChat,{size:15}),"New"]})]}),(0,a.jsxs)("label",{className:"chat-history-search",children:[(0,a.jsx)(N.F.search,{size:15}),(0,a.jsx)("input",{value:l,onChange:e=>r(e.target.value),placeholder:"Search","aria-label":"Search chat history"})]}),(0,a.jsxs)("div",{className:"chat-history-tabs",role:"tablist","aria-label":"Conversation state",children:[(0,a.jsxs)("button",{type:"button",id:S,role:"tab","aria-selected":"active"===s,"aria-controls":I,className:"chat-history-tab",onClick:()=>{c("active"),f(null);},children:["Active ",(0,a.jsx)("span",{children:$})]}),(0,a.jsxs)("button",{type:"button",id:C,role:"tab","aria-selected":"deleted"===s,"aria-controls":I,className:"chat-history-tab",onClick:()=>{c("deleted"),f(null);},children:["Deleted ",(0,a.jsx)("span",{children:E})]})]}),null!==b?(0,a.jsx)("div",{className:"lk-alert",role:"alert",children:b}):null,(0,a.jsx)("div",{id:I,className:"chat-history-list",role:"tabpanel","aria-labelledby":"active"===s?S:C,children:0===A.length?(0,a.jsx)("div",{className:"lk-empty",children:(0,a.jsx)("p",{className:"lk-empty-title",children:"No conversations"})}):A.map(e=>{var n;let l=tR(e).length+t$(e).length,i=d===e.id,r=h===e.id,s=g===e.id,o="closed"===e.status;return(0,a.jsxs)("article",{className:"chat-history-row","data-chat-id":e.id,"data-state":o?"deleted":"active",children:[(0,a.jsx)("div",{className:"chat-history-row-main",children:i?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("input",{ref:w,className:"chat-history-title-input",value:p,"aria-invalid":null!==y,"aria-describedby":null!==y?R:void 0,onChange:e=>{m(e.target.value),null!==y&&j(null);},onKeyDown:t=>{"Enter"===t.key&&D(e),"Escape"===t.key&&(u(null),j(null));}}),null!==y?(0,a.jsx)("span",{id:R,className:"chat-history-rename-error",role:"alert",children:y}):null]}):(0,a.jsxs)("button",{type:"button",className:"chat-history-open",disabled:o,onClick:()=>t(e),children:[(0,a.jsx)("span",{className:"chat-history-title",children:e.title}),(0,a.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,a.jsx)("div",{className:"chat-history-actions",children:i?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-primary",disabled:s,onClick:()=>void D(e),children:"Save"}),(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost",disabled:s,onClick:()=>{u(null),j(null);},children:"Cancel"})]}):r?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-danger",disabled:s,onClick:()=>void M(e),children:"Delete"}),(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost",disabled:s,onClick:()=>f(null),children:"Cancel"})]}):o?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("button",{type:"button",className:"lk-btn lk-btn-primary",disabled:s,onClick:()=>void P(e),children:[(0,a.jsx)(N.F.restore,{size:14}),"Restore"]}),(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost",onClick:()=>T(e),children:"Rename"})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost",onClick:()=>T(e),children:"Rename"}),(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost",onClick:()=>{f(e.id),u(null);},children:"Delete"})]})})]},e.id);})})]});}function i9(){var e,t;let n=c(),l=null!=(e=null==n||null==(t=n.activeProject)?void 0:t.name)?e:"No project selected",r=(0,i.useId)();return(0,a.jsxs)("div",{className:"srch",children:[(0,a.jsxs)("div",{className:"srch-box",children:[(0,a.jsx)(N.F.search,{size:15,"aria-hidden":"true"}),(0,a.jsx)("input",{type:"search","aria-label":"Search files and symbols","aria-describedby":r,placeholder:"Search files & symbols…",disabled:!0})]}),(0,a.jsxs)("div",{className:"tw-label srch-label",children:[l," ",(0,a.jsx)("span",{className:"srch-meta mono",children:"workspace search"})]}),(0,a.jsxs)("div",{className:"tw-pad",children:[(0,a.jsxs)("div",{className:"rb-placeholder",style:{height:150},children:[(0,a.jsx)("div",{className:"ph-stripes"}),(0,a.jsx)("span",{className:"rb-ph-label mono",children:"search"})]}),(0,a.jsx)("div",{id:r,className:"rb-foot mono",style:{marginTop:14},children:"Search across workspace files & symbols — coming soon."})]})]});}let re="connectedSourcesJson";function rt(e,t){let n=e[t];return"string"==typeof n?n:void 0;}function rn(e,t){return"string"==typeof e[t];}function rl(e){if(!("object"==typeof e&&null!==e&&!Array.isArray(e))||!rn(e,"label"))return!1;switch(e.kind){case"file":case"workspace":return rn(e,"path");case"capsule":return rn(e,"capsuleId");case"capsule-set":return rn(e,"capsuleSetId");case"figma-snapshot":let t;return rn(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&&rn(e,"snapshotRunId")&&rn(e,"screenId");default:return!1;}}function ra(e){return e.length>0?{[re]:JSON.stringify(e)}:{};}function ri(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 rr(e){return e.replaceAll("\\","/");}function rs(e){if(/^[A-Za-z]:[/\\]?$/u.test(e))return e.replaceAll("\\","/");if(/^\/\/[^/]+\/[^/]+$/u.test(rr(e)))return rr(e);let t=rr(e).replace(/\/+$/u,"");return 0===t.length&&e.length>0?"/":t;}function ro(e){var t,n,l,a,i,r;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 i=null!=(l=null==e?void 0:e.trim())?l:"";if(0===i.length)return null;let r=rs(i),s=rr(a).replace(/^\/+/u,""),o=r.endsWith("/")?"":"/";return`${r}${o}${s}`;}(s,null!=(n=e.connectedFilePath)?n:null),c=null!==s?rs(s):null,d=(void 0!==e.connectedRoots&&null!==e.connectedRoots&&e.connectedRoots.length>0?e.connectedRoots:null!==s?[s]:[]).map(rs),u=null!==o?d.filter(e=>e!==c):d,p=[];for(let e of(null!==o&&p.push({kind:"file",label:ri(o),path:o}),u))p.push({kind:"workspace",label:ri(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!=(i=e.connectedFigmaSnapshotRunIds)?i:[]).map(e=>({kind:"figma-snapshot",label:e,snapshotRunId:e})))p.push(t);for(let t of null!=(r=e.connectedImageSources)?r:[])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 rc=[{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"}],rd=[{value:"clarify",label:"Ask clarifying questions"},{value:"assume",label:"State explicit assumptions"}],ru="__none__";function rp(e){return e.replaceAll("-"," ");}async function rm(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 rh(e){let{items:t,empty:n}=e;return 0===t.length?void 0===n?null:(0,a.jsx)("p",{className:"pe-empty",children:n}):(0,a.jsx)("ul",{className:"pe-list",children:t.map((e,t)=>(0,a.jsx)("li",{children:e},`${String(t)}:${e.slice(0,24)}`))});}function rf(e){let{title:t,children:n}=e;return(0,a.jsxs)("section",{className:"pe-section","aria-label":t,children:[(0,a.jsx)("h4",{className:"pe-section-title",children:t}),n]});}function rg(e){let{result:t}=e,n=[["Task",rp(t.analysis.taskClass)],["Domain",rp(t.analysis.domain)],["Criticality",rp(t.analysis.criticality)],["Profile",rp(t.analysis.recommendedProfile)],["Input",`${t.analysis.normalizedInputLength.toLocaleString("en-US")} chars`]];return(0,a.jsx)("dl",{className:"pe-analysis","aria-label":"Prompt enhancement analysis",children:n.map(e=>{let[t,n]=e;return(0,a.jsxs)("div",{className:"pe-analysis-item",children:[(0,a.jsx)("dt",{children:t}),(0,a.jsx)("dd",{children:n})]},t);})});}function rv(e){var t;let{routing:n}=e,l="available"===n.availability?"ok":"unavailable"===n.availability?"warn":"muted",i="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,a.jsxs)("div",{className:`pe-routing pe-routing-${l}`,"data-testid":"pe-model-routing",role:"status","aria-live":"polite",children:[(0,a.jsx)("span",{className:"pe-routing-icon","aria-hidden":"true",children:"ok"===l?(0,a.jsx)(N.F.check,{size:14}):(0,a.jsx)(N.F.info,{size:14})}),(0,a.jsx)("span",{children:i})]});}function rb(e){let{safety:t}=e,n=t.requiresHumanReview;return(0,a.jsxs)(rf,{title:"Safety",children:[(0,a.jsxs)("dl",{className:"pe-safety-summary","data-testid":"pe-safety-decision",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Decision:"}),(0,a.jsx)("dd",{children:rp(t.decision)})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Verification:"}),(0,a.jsx)("dd",{children:rp(t.verificationStatus)})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Human review:"}),(0,a.jsx)("dd",{children:n?"required":"not required"})]})]}),n?(0,a.jsx)("p",{className:"pe-safety-warning",role:"alert",children:"This prompt requires human review before any downstream use."}):null,t.findings.length>0?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("h5",{className:"pe-subhead",children:"Safety findings"}),(0,a.jsx)("ul",{className:"pe-list","data-testid":"pe-safety-findings",children:t.findings.map(e=>(0,a.jsxs)("li",{children:[(0,a.jsx)("span",{className:`pe-sev pe-sev-${e.severity}`,children:e.severity})," ",e.detail]},`${e.ruleId}:${e.code}`))})]}):null,t.leastPrivilege.length>0?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("h5",{className:"pe-subhead",children:"Least-privilege constraints"}),(0,a.jsx)(rh,{items:[...t.leastPrivilege]})]}):null]});}function rx(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,a.jsxs)(rf,{title:"Grounding plan",children:[(0,a.jsxs)("div",{className:`pe-grounding-readiness pe-grounding-readiness-${n.status}`,"data-testid":"pe-grounding-readiness",role:"status","aria-live":"polite",children:[(0,a.jsx)("span",{className:"pe-routing-icon","aria-hidden":"true",children:(0,a.jsx)(N.F.info,{size:14})}),(0,a.jsx)("span",{children:l})]}),(0,a.jsxs)("p",{className:"pe-grounding-meta",children:["Strategy: ",(0,a.jsx)("strong",{children:rp(t.strategy)})," /"," ",t.required?"required":"optional"," / citations:"," ",rp(t.citation.discipline)," (",rp(t.citation.granularity),")"]}),t.sourcePriority.length>0?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("h5",{className:"pe-subhead",children:"Source priority"}),(0,a.jsx)("ol",{className:"pe-list",children:t.sourcePriority.map(e=>(0,a.jsxs)("li",{children:[e.source,e.required?" (required)":""]},e.source))})]}):null,(0,a.jsx)(rh,{items:[...t.directives]})]});}function ry(e){var t;let{evidence:n,fingerprint:l}=e;return(0,a.jsxs)("p",{className:"pe-evidence","data-testid":"pe-evidence",children:["Evidence fingerprint: ",l.slice(0,16),"...","recorded"===n.status&&void 0!==n.runId?(0,a.jsxs)(a.Fragment,{children:[" ","Manifest:"," ",(0,a.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 rj(e){let{candidates:t}=e;return(0,a.jsx)(rf,{title:"Candidate scorecards",children:(0,a.jsx)("div",{className:"c-tablewrap",children:(0,a.jsx)("div",{className:"c-tablescroll",children:(0,a.jsxs)("table",{className:"c-table responsive pe-scorecards","data-testid":"pe-scorecards",children:[(0,a.jsx)("thead",{children:(0,a.jsxs)("tr",{children:[(0,a.jsx)("th",{scope:"col",children:"Profile"}),(0,a.jsx)("th",{scope:"col",className:"num",children:"Score"}),(0,a.jsx)("th",{scope:"col",className:"num",children:"Tokens"}),(0,a.jsx)("th",{scope:"col",children:"Winner"})]})}),(0,a.jsx)("tbody",{children:t.scorecards.map(e=>{let n=e.candidateId===t.winnerCandidateId;return(0,a.jsxs)("tr",{className:n?"pe-winner":void 0,"aria-selected":n?"true":void 0,children:[(0,a.jsx)("th",{scope:"row",children:e.profile}),(0,a.jsx)("td",{className:"num","data-label":"Score",children:e.aggregateScore.toFixed(3)}),(0,a.jsx)("td",{className:"num","data-label":"Tokens",children:e.estimatedTokens.toLocaleString("en-US")}),(0,a.jsx)("td",{"data-label":"Winner",children:n?(0,a.jsx)("span",{className:"pe-winner-mark","aria-label":"Winner",children:"★"}):(0,a.jsx)("span",{"aria-hidden":"true",children:"-"})})]},e.candidateId);})})]})})})});}function rw(e){let{result:t}=e,n=t.enhancedPrompt,l=t.analysis.missingContext.map(e=>"assumption"===e.kind?e.statement:e.question);return(0,a.jsxs)("div",{className:"pe-section-grid",children:[(0,a.jsx)(rf,{title:"Role",children:(0,a.jsx)("p",{children:n.role})}),(0,a.jsx)(rf,{title:"Objective",children:(0,a.jsx)("p",{children:n.goal})}),(0,a.jsx)(rf,{title:"Context",children:(0,a.jsx)(rh,{items:[...n.context],empty:"No additional context."})}),(0,a.jsx)(rf,{title:t.analysis.missingContext.some(e=>"assumption"===e.kind)?"Assumptions":"Clarification questions",children:(0,a.jsx)(rh,{items:l,empty:"No clarifications or assumptions needed."})}),(0,a.jsx)(rf,{title:"Steps",children:(0,a.jsx)(rh,{items:[...n.taskDecomposition]})}),(0,a.jsx)(rf,{title:"Constraints",children:(0,a.jsx)(rh,{items:[...n.constraints]})}),(0,a.jsxs)(rf,{title:"Output schema",children:[(0,a.jsxs)("p",{children:["Format: ",(0,a.jsx)("strong",{children:n.outputSchema.format}),n.outputSchema.structured?" / structured":""]}),(0,a.jsx)(rh,{items:[...n.outputSchema.hints]})]}),(0,a.jsx)(rf,{title:"Quality criteria",children:(0,a.jsx)(rh,{items:[...n.qualityCriteria]})}),(0,a.jsx)(rf,{title:"Uncertainty handling",children:(0,a.jsx)(rh,{items:[...n.uncertaintyHandling]})}),(0,a.jsx)(rf,{title:"Safety rules",children:(0,a.jsx)(rh,{items:[...n.safetyRules]})})]});}function rk(){let{connectedRoot:e=null,connectedFilePath:t=null,connectedRoots:n,enhanceImpl:l=k.fG,fetchModelsImpl:r=k.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"),[m,h]=(0,i.useState)(ru),[f,g]=(0,i.useState)([]),[v,b]=(0,i.useState)(null),[x,y]=(0,i.useState)(null),[j,w]=(0,i.useState)(!1),[S,C]=(0,i.useState)(null),[I,R]=(0,i.useState)("idle"),[$,E]=(0,i.useState)(null),A=(0,i.useRef)(null),F=(0,i.useRef)(null),T=(0,i.useId)(),D=(0,i.useId)(),M=(0,i.useId)();(0,i.useEffect)(()=>{let e=!1;return r().then(t=>{e||g(t.models.filter(e=>"chat"===e.kind));}).catch(()=>{}),()=>{e=!0;};},[r]),(0,i.useEffect)(()=>()=>{var e;null==(e=F.current)||e.abort();},[]);let P=(0,i.useMemo)(()=>function(e){var t;let{connectedRoot:n,connectedFilePath:l,connectedRoots:a}=e,i=ro({connectedRoot:null!=n?n:null,connectedFilePath:null!=l?l:null,connectedRoots:a});if(0===i.length)return{hasConnectedContext:!1,attachmentCount:0,label:"No connected Files source",signature:"none"};let r=i.map(e=>e.label),s=1===r.length?null!=(t=r[0])?t:"Connected source":`${r.length.toString()} connected sources`;return{hasConnectedContext:!0,attachmentCount:i.length,label:s,signature:JSON.stringify(i)};}({connectedRoot:e,connectedFilePath:t,connectedRoots:n}),[e,t,n]);(0,i.useEffect)(()=>{if("copied"!==I)return;let e=window.setTimeout(()=>{R("idle"),E(null);},3e3);return()=>{window.clearTimeout(e);};},[I]);let q=(0,i.useCallback)(async()=>{var e;let t=s.trim();if(0===t.length)return void C("Enter a prompt draft to enhance.");null==(e=F.current)||e.abort();let n=new AbortController();F.current=n,w(!0),C(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}),...(m===ru?{}:{modelId:m})};try{let e=await l(a,n.signal);n.signal.aborted||(b(e),y(P.signature));}catch(e){n.signal.aborted||C(e instanceof k.hD?`${e.message} (${e.code})`:e instanceof Error&&"AbortError"===e.name?"Request cancelled.":"Prompt enhancement failed. Please try again.");}finally{n.signal.aborted||w(!1);}},[s,u,P,c,m,l]),L=(0,i.useCallback)(async()=>{if(null!==v){C(null),R("copying"),E("Copying rendered prompt...");try{await rm(v.renderedPrompt),R("copied"),E("Copied to clipboard.");}catch{R("failed"),E("Clipboard access failed. Select text manually and use Cmd/Ctrl+C.");}}},[v]),z=(0,i.useCallback)(()=>{var e,t;null==(e=F.current)||e.abort(),F.current=null,o(""),b(null),y(null),w(!1),C(null),R("idle"),E(null),null==(t=A.current)||t.focus();},[]),O=[{options:[{value:ru,label:"Deterministic only (no model)"},...f.map(e=>({value:e.id,label:e.id}))]}],K=s.trim().length,W=K>0||null!==v||j||null!==S||"idle"!==I||null!==$,B=null!==v&&null!==x&&x!==P.signature;return(0,a.jsxs)("div",{className:"pe-panel","data-testid":"prompt-enhancer-panel",children:[(0,a.jsxs)("div",{className:"pe-header","data-testid":"pe-header",children:[(0,a.jsx)("span",{className:"pe-header-icon","aria-hidden":"true",children:(0,a.jsx)(N.F.spark,{size:18})}),(0,a.jsxs)("div",{className:"pe-header-copy",children:[(0,a.jsx)("p",{className:"pe-eyebrow",children:"Governed prompt workspace"}),(0,a.jsx)("h3",{className:"pe-title",children:"Prompt Enhancer"})]}),(0,a.jsx)("span",{className:"pe-header-chip",children:"No execution"})]}),(0,a.jsxs)("form",{className:"pe-form",onSubmit:e=>{e.preventDefault(),q();},children:[(0,a.jsxs)("div",{className:"pe-draft-card",children:[(0,a.jsxs)("div",{className:"pe-field-head",children:[(0,a.jsx)("label",{className:"pe-label",htmlFor:T,children:"Raw prompt"}),(0,a.jsxs)("span",{className:"pe-counter",id:D,children:[K.toLocaleString("en-US")," chars"]})]}),(0,a.jsx)("textarea",{ref:A,id:T,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===S?D:`${D} ${M}`})]}),(0,a.jsxs)("aside",{className:"pe-controls-card","aria-label":"Enhancement controls",children:[(0,a.jsxs)("div",{className:"pe-controls",children:[(0,a.jsxs)("div",{className:"pe-control",children:[(0,a.jsx)("span",{className:"pe-label","aria-hidden":"true",children:"Profile"}),(0,a.jsx)(nd,{value:c,ariaLabel:"Profile",onValueChange:d,sections:[{options:rc.map(e=>({...e}))}],triggerClassName:"pe-select",menuClassName:"pe-select-menu"})]}),(0,a.jsxs)("div",{className:"pe-control",children:[(0,a.jsx)("span",{className:"pe-label","aria-hidden":"true",children:"Missing information"}),(0,a.jsx)(nd,{value:u,ariaLabel:"Missing information",onValueChange:p,sections:[{options:rd.map(e=>({...e}))}],triggerClassName:"pe-select",menuClassName:"pe-select-menu"})]}),(0,a.jsxs)("div",{className:"pe-control",children:[(0,a.jsx)("span",{className:"pe-label","aria-hidden":"true",children:"Readiness model"}),(0,a.jsx)(nd,{value:m,ariaLabel:"Readiness model",onValueChange:h,sections:O,triggerClassName:"pe-select",menuClassName:"pe-select-menu"})]})]}),(0,a.jsxs)("div",{className:"pe-grounding-context","data-connected":P.hasConnectedContext?"true":"false","data-testid":"pe-grounding-context",children:[(0,a.jsx)("span",{className:"pe-routing-icon","aria-hidden":"true",children:(0,a.jsx)(N.F.layers,{size:14})}),(0,a.jsxs)("span",{children:[(0,a.jsx)("span",{className:"pe-context-label",children:"Grounding context"}),(0,a.jsx)("strong",{children:P.label})]})]}),B?(0,a.jsx)("p",{className:"pe-context-stale",role:"status","aria-live":"polite",children:"Grounding context changed. Regenerate to update this review artifact."}):null,(0,a.jsxs)("div",{className:"pe-command-row",children:[(0,a.jsxs)("button",{type:"submit",className:"pe-button pe-button-primary pe-enhance",disabled:j||0===K,children:[(0,a.jsx)(N.F.spark,{size:15}),(0,a.jsx)("span",{children:j?"Enhancing...":"Enhance prompt"})]}),(0,a.jsxs)("button",{type:"button",className:"pe-button pe-button-secondary pe-clear",onClick:z,disabled:!W,"aria-label":"Clear prompt workspace",children:[(0,a.jsx)(N.F.reset,{size:15}),(0,a.jsx)("span",{children:"Clear"})]})]}),(0,a.jsx)("p",{className:"pe-status",role:"status","aria-live":"polite",children:j?"Enhancing prompt...":0===K?"Waiting for draft":"Ready"})]})]}),null!==S?(0,a.jsx)("p",{className:"pe-error",role:"alert",id:M,children:S}):null,null!==v?(0,a.jsxs)("div",{className:"pe-result","data-testid":"pe-result",children:[(0,a.jsxs)("div",{className:"pe-result-head",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"pe-eyebrow",children:"Review artifact"}),(0,a.jsx)("h4",{className:"pe-result-title",children:"Enhanced prompt"})]}),(0,a.jsx)(rv,{routing:v.modelRouting})]}),(0,a.jsx)(rg,{result:v}),(0,a.jsxs)(rf,{title:"Rendered prompt",children:[(0,a.jsx)("pre",{className:"pe-rendered","aria-label":"Rendered prompt text","data-text-selectable":"true",children:v.renderedPrompt}),(0,a.jsxs)("div",{className:"pe-actions",children:[null!==$?(0,a.jsx)("p",{className:`pe-copy-status pe-copy-status-${I}`,role:"failed"===I?"alert":"status","aria-live":"polite",children:$}):null,(0,a.jsxs)("button",{type:"button",className:"pe-button pe-button-secondary pe-copy",disabled:"copying"===I,onClick:()=>{L();},children:[(0,a.jsx)(N.F.file,{size:15}),(0,a.jsx)("span",{children:"copying"===I?"Copying...":"Copy rendered prompt"})]})]})]}),(0,a.jsxs)("div",{className:"pe-review-grid",children:[(0,a.jsx)(rb,{safety:v.safety}),(0,a.jsx)(rx,{plan:v.enhancedPrompt.groundingPlan,readiness:v.groundingReadiness})]}),(0,a.jsx)(rw,{result:v}),(0,a.jsx)(rj,{candidates:v.candidates}),(0,a.jsx)(ry,{evidence:v.evidence,fingerprint:v.inputFingerprintSha256})]}):(0,a.jsxs)("div",{className:"pe-empty-state","aria-label":"Prompt enhancement empty state",children:[(0,a.jsx)(N.F.layers,{size:18}),(0,a.jsx)("span",{children:"No enhanced prompt yet."})]})]});}let rN=[{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}],rS=[{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 rC(e){let{img:t,icon:n,glyph:l}=e;if(void 0!==t)return(0,a.jsx)("img",{className:"pl-img",src:`/assets/icons/${t}.svg`,width:"20",height:"20",alt:""});if(void 0!==n){let e=N.F[n];return(0,a.jsx)("span",{className:"pl-line",children:(0,a.jsx)(e,{size:18})});}return(0,a.jsx)("span",{className:"mono pl-glyph",children:l});}function rI(){let[e,t]=(0,i.useState)(rN.map(e=>e.on)),n=e.filter(Boolean).length;return(0,a.jsxs)("div",{className:"plg",children:[(0,a.jsxs)("div",{className:"plg-sec",children:[(0,a.jsx)("span",{className:"plg-sec-t",children:"MCP Servers"}),(0,a.jsxs)("span",{className:"plg-sec-c mono",children:[n,"/",rN.length," active"]})]}),rN.map((n,l)=>{var i;let r=null!=(i=e[l])&&i;return(0,a.jsxs)("div",{className:"plg-row",children:[(0,a.jsx)("span",{className:"plg-ico",children:(0,a.jsx)(rC,{img:n.img,icon:n.icon})}),(0,a.jsxs)("span",{className:"plg-text",children:[(0,a.jsx)("span",{className:"plg-name",children:n.name}),(0,a.jsx)("span",{className:"plg-desc",children:n.desc})]}),(0,a.jsx)("button",{className:`plg-dot${r?" on":""}`,title:r?"Running":"Stopped","aria-label":`${n.name}: ${r?"running":"stopped"}`,onClick:()=>{t(e=>{var t;let n=[...e];return n[l]=!(null!=(t=n[l])&&t),n;});}})]},n.name);}),(0,a.jsx)("div",{className:"plg-sec plg-sec2",children:(0,a.jsx)("span",{className:"plg-sec-t",children:"Connectors"})}),rS.map(e=>(0,a.jsxs)("button",{className:"plg-row plg-conn","data-on":e.on,children:[(0,a.jsx)("span",{className:"plg-ico",children:(0,a.jsx)(rC,{img:e.img})}),(0,a.jsxs)("span",{className:"plg-text",children:[(0,a.jsx)("span",{className:"plg-name",children:e.name}),(0,a.jsx)("span",{className:"plg-desc",children:e.on?"Connected":"Not connected"})]}),e.on?(0,a.jsx)("span",{className:"integ-on",children:(0,a.jsx)(N.F.check,{size:13})}):(0,a.jsx)("span",{className:"integ-add",children:(0,a.jsx)(N.F.plus,{size:14})})]},e.name))]});}let rR=[{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}],r$="keiko.automations.v1",rE=Object.fromEntries(rR.map(e=>[e.id,e.defaultOn]));function rA(){try{let e=localStorage.getItem(r$);if(null===e)return{...rE};let t=JSON.parse(e);if("object"!=typeof t||null===t||Array.isArray(t))return{...rE};let n={...rE};for(let[e,l]of Object.entries(t))e in rE&&"boolean"==typeof l&&(n[e]=l);return n;}catch{return{...rE};}}function rF(){let[e,t]=(0,i.useState)(rA);return(0,a.jsx)("div",{className:"tw-list",children:rR.map(n=>{var l;let i=null!=(l=e[n.id])?l:n.defaultOn;return(0,a.jsxs)("div",{className:"auto-row",children:[(0,a.jsx)("span",{className:"dot",style:{background:i?"var(--accent)":"var(--fg-faint)"}}),(0,a.jsxs)("span",{className:"auto-text",children:[(0,a.jsx)("span",{className:"auto-name",children:n.name}),(0,a.jsx)("span",{className:"auto-when mono",children:n.when})]}),(0,a.jsx)(iw,{on:i,onChange:()=>{var e;e=n.id,t(t=>{var n;let l={...t,[e]:!(null!=(n=t[e])&&n)};try{localStorage.setItem(r$,JSON.stringify(l));}catch{}return l;});},label:n.name})]},n.id);})});}function rT(){return(0,a.jsxs)("div",{className:"tw-pad mob",children:[(0,a.jsxs)("div",{className:"mob-qr",children:[(0,a.jsx)("div",{className:"ph-stripes"}),(0,a.jsx)(N.F.mobile,{size:28,style:{position:"relative",color:"var(--fg-dim)"}})]}),(0,a.jsx)("div",{className:"mob-title",children:"Keiko Mobile"}),(0,a.jsx)("div",{className:"mob-sub",children:"Scan to continue this workspace on your phone."})]});}function rD(){var e;let t,{wins:n,active:l,winCount:r}=(0,i.useContext)(w),s=null!==l?E[l.type]:null,o=null!==l?Object.entries(l.cfg).filter(e=>{let[,t]=e;return""!==t&&null!=t;}):[];return(0,a.jsxs)("div",{className:"tw-pad",children:[(0,a.jsx)("div",{className:"rb-section-label",style:{marginTop:0},children:"Active window"}),null!==l&&null!==s?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"insp-top",children:[(0,a.jsx)("span",{className:"insp-ico",style:{color:!0===s.accent?"var(--accent)":"var(--fg-muted)"},children:(e=s.icon,t=N.F[e],(0,a.jsx)(t,{size:16}))}),(0,a.jsx)("span",{className:"insp-title",children:s.title})]}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Size"}),(0,a.jsxs)("span",{className:"rb-row-v mono",children:[Math.round(l.w)," \xd7 ",Math.round(l.h)]})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Position"}),(0,a.jsxs)("span",{className:"rb-row-v mono",children:[Math.round(l.x),", ",Math.round(l.y)]})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"State"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:l.max?"maximized":"floating"})]})]}),o.length>0&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"rb-section-label",children:"Configuration"}),(0,a.jsx)("div",{className:"rb-rows",children:o.map(e=>{let[t,n]=e;return(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:t}),(0,a.jsx)("span",{className:"rb-row-v mono",children:String(n).slice(0,20)||"—"})]},t);})})]}),(0,a.jsx)("div",{className:"rb-section-label insp-governance",children:"Governance"}),(0,a.jsxs)("div",{className:"rb-rows insp-governance","data-testid":"insp-governance",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Authority"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:eM[l.type].authority})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Persistence"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:eM[l.type].persistence})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Trust"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:eM[l.type].trustBoundary.join(", ")})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Lifecycle"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:eM[l.type].lifecycle.join(" → ")})]})]})]}):(0,a.jsx)("div",{className:"insp-empty",children:"No window focused"}),(0,a.jsx)("div",{className:"rb-section-label",children:"Workspace"}),(0,a.jsx)("div",{className:"rb-rows",children:(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Open windows"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:r})]})})]});}let rM=[{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 rP(){return(0,a.jsx)("ul",{className:"tw-list",children:rM.map((e,t)=>(0,a.jsxs)("li",{className:"nt-row",children:[(0,a.jsx)("span",{className:"dot",style:{background:e.c,marginTop:6},"aria-hidden":"true"}),(0,a.jsxs)("span",{className:"nt-text",children:[(0,a.jsx)("span",{className:"nt-title",children:e.t}),(0,a.jsxs)("span",{className:"nt-time mono",children:[e.time," ago"]})]})]},t))});}function rq(){return(0,a.jsxs)("div",{className:"tw-pad",children:[(0,a.jsxs)("div",{className:"rb-placeholder",style:{height:150},children:[(0,a.jsx)("div",{className:"ph-stripes"}),(0,a.jsx)("span",{className:"rb-ph-label mono",children:"resources"})]}),(0,a.jsx)("div",{className:"rb-foot mono",style:{marginTop:14},children:"Shared assets & references — coming soon."})]});}let rL="keiko-activity",rz={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 rO(){let e=function(){var e;let[,t]=(0,i.useState)(0);return(0,i.useEffect)(()=>{let e=()=>{t(e=>e+1);};return window.addEventListener(rL,e),()=>{window.removeEventListener(rL,e);};},[]),null!=(e=window.__keikoActivity)?e:[];}();return(0,a.jsxs)("div",{className:"tl",role:"log","aria-label":"Activity timeline",children:[0===e.length&&(0,a.jsxs)("div",{className:"tl-empty",children:["No activity yet.",(0,a.jsx)("br",{}),"Start an agent to see its actions stream here."]}),e.map((e,t)=>{var n,l;return(0,a.jsxs)("div",{className:"tl-row",children:[(0,a.jsx)("span",{className:"tl-dot","aria-hidden":"true",style:{background:null!=(n=rz[e.type])?n:"var(--fg-faint)"}}),(0,a.jsxs)("div",{className:"tl-body",children:[(0,a.jsx)("span",{className:"visually-hidden",children:e.type}),(0,a.jsx)("span",{className:"tl-text",children:e.text}),(0,a.jsxs)("span",{className:"tl-meta mono",children:[null!=(l=e.agent)?l:"workspace"," \xb7 ",new Date(e.time).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})]})]})]},t);})]});}let rK={docx:"DOCX",xlsx:"XLSX",pdf:"PDF"};function rW(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 rB(e){return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(new Date(e));}function rU(e){let{label:t,value:n}=e;return(0,a.jsxs)("div",{className:"fpv-meta-row",children:[(0,a.jsx)("span",{children:t}),(0,a.jsx)("strong",{children:n})]});}function r_(e){var t,n,l,r;let{root:s,path:o,onClose:c,onOpenInEditor: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)(0),[x,y]=(0,i.useState)("idle"),j=(0,i.useRef)(null),w=(0,i.useRef)(null);(0,i.useEffect)(()=>{var e;null==(e=j.current)||e.focus({preventScroll:!0});},[]),(0,i.useEffect)(()=>{let e=!1,t=w.current,n=null===t||t.root!==s||t.path!==o,l=null!==t&&!n&&v>0;return w.current={root:s,path:o},h(!0),g(null),y(l?"refreshing":"idle"),l||p(null),(0,k.q7)(s,o).then(t=>{!e&&(p(t),l&&y("refreshed"));}).catch(t=>{!e&&(g(t instanceof k.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&&y("failed"));}).finally(()=>{e||h(!1);}),()=>{e=!0;};},[o,s,v]),(0,i.useEffect)(()=>{if("refreshed"!==x)return;let e=window.setTimeout(()=>y("idle"),2400);return()=>window.clearTimeout(e);},[x]);let S=()=>b(e=>e+1),C=(null==f?void 0:f.denied)===!0,I=null!==u?"text"===u.kind?null!=(l=u.extension)?l:"text":"image"===u.kind?u.mime:null!=(r=u.extension)?r:"binary":C?"denied":null!==f?"error":"loading",R=C?"Hidden file":null!=(t=null==u?void 0:u.name)?t:null!==f?"Preview unavailable":"Loading preview",$=(null==u?void 0:u.kind)==="text"&&u.content.length<=2e5,E=void 0!==d&&(null==u?void 0:u.kind)==="text"&&!u.truncated,A="refreshing"===x?"Refreshing...":"refreshed"===x?"Reloaded":"failed"===x?"Refresh failed":"",F=(null==u?void 0:u.kind)==="text"?$?il(u.content,a9(u.name)):u.content.split("\n").map(e=>[["id",e]]):[];return(0,a.jsxs)("div",{className:"fpv",onKeyDown:e=>{"Escape"===e.key&&(e.stopPropagation(),c());},children:[(0,a.jsxs)("div",{className:"fpv-bar",children:[(0,a.jsx)("button",{className:"fpv-back",type:"button",ref:j,onClick:c,title:"Back to files","aria-label":"Back to files",children:(0,a.jsx)(N.F.back,{size:15})}),(0,a.jsx)(ae.o,{name:C||null===u?"":u.name}),(0,a.jsx)("span",{className:"fpv-name",title:R,children:R}),(0,a.jsx)("span",{className:"fpv-lang mono",children:I}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsx)("button",{className:"fpv-back fpv-refresh",type:"button",onClick:S,disabled:m,"data-state":x,title:m?"Refreshing preview":"Refresh preview","aria-label":m?"Refreshing preview":"Refresh preview",children:(0,a.jsx)(N.F.reset,{size:14})}),A.length>0?(0,a.jsx)("span",{className:"fpv-status mono","data-state":x,role:"status","aria-live":"polite",children:A}):null,E?(0,a.jsx)("button",{className:"fpv-back",type:"button",onClick:()=>d(s,o),title:"Open in editor","aria-label":"Open in editor",children:(0,a.jsx)(N.F.editor,{size:15})}):null,(0,a.jsx)("button",{className:"fpv-back",type:"button",onClick:c,title:"Close preview","aria-label":"Close preview",children:(0,a.jsx)(N.F.close,{size:15})})]}),m&&null===u?(0,a.jsx)("div",{className:"fpv-state",role:"status",children:"Loading preview…"}):null,null!==f?(0,a.jsxs)("div",{className:"fpv-state fpv-error",role:"alert",children:[(0,a.jsx)("span",{children:f.message}),f.denied?null:(0,a.jsx)("button",{type:"button",className:"fpv-retry",onClick:S,children:"Retry"})]}):null,(null==u?void 0:u.kind)==="text"?(0,a.jsxs)(a.Fragment,{children:[u.truncated?(0,a.jsxs)("div",{className:"fpv-banner",children:["Preview truncated at ",rW(u.maxBytes),". Larger files can't be shown in full here."]}):null,$?null:(0,a.jsx)("div",{className:"fpv-banner",children:"Syntax highlighting disabled for large previews."}),(0,a.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(F.length).length)}ch + 16px))`},children:F.map((e,t)=>(0,a.jsxs)("div",{className:"fpv-line",children:[(0,a.jsx)("span",{className:"fpv-num",children:t+1}),(0,a.jsx)("span",{className:"fpv-src",children:e.map((e,t)=>(0,a.jsx)("span",{className:`hl-${e[0]}`,children:e[1]},t))})]},t))})]}):null,(null==u?void 0:u.kind)==="image"?(0,a.jsxs)("div",{className:"fpv-image-pane",children:[(0,a.jsx)("div",{className:"fpv-image-card",children:(0,a.jsx)("img",{className:"fpv-image",src:u.dataUrl,alt:u.name})}),(0,a.jsxs)("div",{className:"fpv-meta",children:[(0,a.jsx)(rU,{label:"Type",value:u.mime}),(0,a.jsx)(rU,{label:"Size",value:rW(u.sizeBytes)}),(0,a.jsx)(rU,{label:"Modified",value:rB(u.modifiedAt)})]})]}):null,(null==u?void 0:u.kind)==="binary"?(0,a.jsx)("div",{className:"fpv-meta-pane",children:(0,a.jsxs)("div",{className:"fpv-meta-card",children:[(0,a.jsx)(ae.o,{name:u.name}),(0,a.jsx)("h3",{children:u.name}),(0,a.jsx)("p",{children:function(e){var t;if("too_large"===e.reason)return`Preview disabled because this file exceeds ${rW(null!=(t=e.maxBytes)?t:0)}.`;let n=rK[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,a.jsxs)("div",{className:"fpv-meta",children:[(0,a.jsx)(rU,{label:"Type",value:u.mime}),(0,a.jsx)(rU,{label:"Extension",value:null!=(n=u.extension)?n:"none"}),(0,a.jsx)(rU,{label:"Size",value:rW(u.sizeBytes)}),(0,a.jsx)(rU,{label:"Modified",value:rB(u.modifiedAt)})]})]})}):null]});}function rV(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 rJ(e){return 8+18*e;}let rH=new Set(["ArrowDown","ArrowUp","ArrowRight","ArrowLeft","Home","End"]);function rY(e){var t;let{root:n,activeFilePath:l,openFilesDirectly:r=!1,onActiveFileChange:s,onRootChange:o,onOpenFile:c}=e,d=null==n?void 0:n.trim(),u=void 0!==d&&d.length>0?d:null,[p,m]=(0,i.useState)(null),h=null!=(t=null!=u?u:p)?t:"",[f,g]=(0,i.useState)(null),[v,b]=(0,i.useState)(""),[x,y]=(0,i.useState)(null),[j,w]=(0,i.useState)(null),[S,C]=(0,i.useState)({}),[I,R]=(0,i.useState)(()=>new Set([""])),[$,E]=(0,i.useState)(0),A=(0,i.useRef)(s);A.current=s;let F=(0,i.useRef)(null),T=(0,i.useRef)(null),D=(0,i.useId)();(0,i.useEffect)(()=>{var e,t;if(null!==x)return;let n=T.current;if(null===n)return;T.current=null;let l=null==(e=F.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:F.current)||t.focus({preventScroll:!0});},[x]),(0,i.useEffect)(()=>{if(null!==u)return;let e=!1;return(0,k.vj)().then(t=>{var n;if(e)return;let l=null==(n=t.projects.find(e=>e.available))?void 0:n.path;m(null!=l?l:null);}).catch(()=>{e||m(null);}),()=>{e=!0;};},[u]);let M=(0,i.useCallback)(async e=>{if(0===h.length)return void C(t=>({...t,[e]:{entries:[],truncated:!1,loading:!1,error:null,notice:"no-root"}}));C(t=>{var n,l,a,i;return{...t,[e]:{entries:null!=(n=null==(a=t[e])?void 0:a.entries)?n:[],truncated:null!=(l=null==(i=t[e])?void 0:i.truncated)&&l,loading:!0,error:null,notice:null}};});try{let n=await(0,k.KD)(h,e);if(""===e){var t;g(n.root),null==(t=A.current)||t.call(A,null,n.root,null),w(null);}C(t=>({...t,[e]:{entries:n.entries,truncated:n.truncated,loading:!1,error:null,notice:null}}));}catch(t){C(n=>{var l,a,i,r;return{...n,[e]:{entries:null!=(l=null==(i=n[e])?void 0:i.entries)?l:[],truncated:null!=(a=null==(r=n[e])?void 0:r.truncated)&&a,loading:!1,error:t instanceof Error?t.message:"Unable to read this folder.",notice:null}};});}},[h]);(0,i.useEffect)(()=>{var e;y(null),w(null),null==(e=A.current)||e.call(A,null,null,null),g(null),R(new Set([""])),C({}),M("");},[h,M,$]);let P=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!=f?f:h.length>0?h:"",j);(0,i.useEffect)(()=>{b(P);},[P]);let q=(0,i.useCallback)(e=>{let t=e.trim();void 0===o||0===t.length||t!==P&&o(t);},[o,P]),L=(0,i.useCallback)(e=>{var t;y(null),w(e),null==(t=A.current)||t.call(A,null,null!=f?f:h,e),null!==e&&void 0===S[e]&&M(e);},[h,S,M,f]),z=(0,i.useCallback)(()=>{if(null!==j)return void L(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;}(j));let e=rV(null!=f?f:h);null!==e&&q(e);},[h,j,L,q,f]),O=function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:S[e];return(0,a.jsxs)("div",{className:"tr-dir",role:0===t?void 0:"group",children:[(null==n?void 0:n.loading)===!0?(0,a.jsx)("div",{className:"files-note",role:"status",style:{paddingLeft:rJ(t)+18},children:"Loading…"}):null,(null==n?void 0:n.notice)==="no-root"?(0,a.jsx)("div",{className:"files-note",role:"status",style:{paddingLeft:rJ(t)+18},children:void 0!==o?"No folder is open yet. Enter a folder path above and press Open.":"No registered project is available."}):null,(null==n?void 0:n.error)!==null&&(null==n?void 0:n.error)!==void 0?(0,a.jsxs)("div",{className:"files-error",role:"alert",style:{marginLeft:rJ(t)},children:[(0,a.jsx)("span",{children:n.error}),(0,a.jsx)("button",{type:"button",className:"files-retry",onClick:()=>{M(e);},children:"Retry"})]}):null,(null==n?void 0:n.truncated)===!0?(0,a.jsxs)("div",{className:"files-note files-warning",role:"status",style:{paddingLeft:rJ(t)+18},children:["Showing only the first ",n.entries.length," entries — this folder contains more."]}):null,null==n?void 0:n.entries.map(e=>((e,t)=>{var n;let i=rJ(t),s=I.has(e.path),o="This link can't be opened from this folder.";if("directory"===e.kind){let n=S[e.path];return(0,a.jsxs)("div",{className:"tr-row-wrap",children:[(0,a.jsxs)("div",{className:"tr-dir-line",style:{paddingLeft:i},children:[(0,a.jsx)("button",{className:"tr-caret-btn",type:"button",tabIndex:-1,disabled:!e.readable,"aria-label":`${s?"Collapse":"Expand"} folder: ${e.name}`,onClick:()=>(e=>{if(!e.readable)return;let t=I.has(e.path);R(t=>{let n=new Set(t);return n.has(e.path)?n.delete(e.path):n.add(e.path),n;}),t||void 0!==S[e.path]||M(e.path);})(e),title:e.readable?`${s?"Collapse":"Expand"} ${e.path}`:o,children:(0,a.jsx)("span",{className:"tr-caret","data-open":s,children:(0,a.jsx)(N.F.chevronR,{size:11})})}),(0,a.jsxs)("button",{className:"tr-row tr-dir-enter",role:"treeitem","aria-level":t+1,"aria-selected":j===e.path,"data-active":j===e.path,"data-readable":e.readable,"data-path":e.path,type:"button","aria-disabled":!e.readable||void 0,"aria-describedby":e.readable?void 0:D,"aria-expanded":s,onClick:()=>{e.readable&&L(e.path);},title:e.readable?e.path:o,children:[(0,a.jsx)("span",{className:"fi-fallback",style:{color:"var(--accent)"},children:(0,a.jsx)(N.F.folder,{size:14})}),(0,a.jsx)("span",{className:"tr-name tr-folder",children:e.name}),e.symlink?(0,a.jsx)("span",{className:"tr-badge",children:"link"}):null]})]}),s?O(e.path,t+1,n):null]},e.path);}let d=null!=(n=null!=x?x:l)?n:null;return(0,a.jsxs)("button",{className:"tr-row tr-file",role:"treeitem","aria-level":t+1,"aria-selected":d===e.path,"data-active":d===e.path,"data-readable":e.readable,"data-path":e.path,style:{paddingLeft:i},type:"button","aria-disabled":!e.readable||void 0,"aria-describedby":e.readable?void 0:D,onClick:()=>{var t,n;if(!e.readable)return;let l=null!=f?f:h;if(r&&void 0!==c){null==(n=A.current)||n.call(A,e.path,l),c(l,e.path);return;}y(e.path),null==(t=A.current)||t.call(A,e.path,l);},title:e.readable?e.path:o,children:[(0,a.jsx)("span",{className:"tr-caret tr-caret-ghost","aria-hidden":"true",children:(0,a.jsx)(N.F.chevronR,{size:11})}),(0,a.jsx)(ae.o,{name:e.name}),(0,a.jsx)("span",{className:"tr-name",children:e.name}),e.symlink?(0,a.jsx)("span",{className:"tr-badge",children:"link"}):null,(0,a.jsx)("span",{className:"tr-meta mono",children:function(e){if(!Number.isFinite(e)||e<=0)return"0 B";let t=["B","KB","MB","GB"],n=e,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);})(e,t)),void 0===n||n.loading||null!==n.error||null!==n.notice||0!==n.entries.length?null:(0,a.jsx)("div",{className:"files-note",role:"status",style:{paddingLeft:rJ(t)+18},children:"Empty folder."})]});};return null!==x?(0,a.jsx)(r_,{root:null!=f?f:h,path:x,onOpenInEditor:c,onClose:()=>{var e;T.current=x,y(null),null==(e=A.current)||e.call(A,null,null!=f?f:h);}}):(0,a.jsxs)("div",{className:"files",ref:F,tabIndex:-1,children:[void 0!==o?(0,a.jsxs)("form",{className:"files-root-bar",role:"group","aria-label":"Folder root",onSubmit:e=>{e.preventDefault(),q(v);},children:[(0,a.jsx)("button",{type:"button",className:"files-root-up",onClick:z,disabled:null===j&&null===rV(null!=f?f:h),title:"Open parent folder","aria-label":"Open parent folder",children:(0,a.jsx)(N.F.arrowUp,{size:13})}),(0,a.jsx)("input",{type:"text",className:"files-root-input mono","aria-label":"Folder path — open any folder on this machine",placeholder:"/path/to/any/folder",spellCheck:!1,value:v,onChange:e=>b(e.target.value)}),(0,a.jsx)("button",{type:"submit",className:"files-root-open",title:"Open this folder",children:"Open"})]}):null,(0,a.jsx)("button",{className:"files-refresh",type:"button",onClick:()=>E(e=>e+1),title:"Refresh folder","aria-label":"Refresh folder",children:(0,a.jsx)(N.F.reset,{size:13})}),(0,a.jsx)("span",{id:D,className:"visually-hidden",children:"This link can't be opened from this folder."}),(0,a.jsx)("div",{className:"tr files-tree",role:"tree","aria-label":"Files",tabIndex:-1,onKeyDown:e=>{if(!rH.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,i,r,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==(i=e[t-1])||i.focus();else if("Home"===n)null==(r=e[0])||r.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,i,r;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==(i=e[n])?void 0:i.getAttribute("aria-level"))?a:"1")<s){null==(r=e[n])||r.focus();return;}}(e,t));}(l,a,e.key));},children:O(null!=j?j:"",0)})]});}let rX=(0,n(42925).default)(()=>n.e(9385).then(n.bind(n,19385)),{loadableGenerated:{webpack:()=>[19385]},ssr:!1,loading:()=>(0,a.jsx)("div",{className:"ed-host-loading","aria-hidden":"true"})});function rG(e,t,n){return Math.min(n,Math.max(t,e));}function rQ(e){return e.trim().replace(/\\/gu,"/").replace(/\/+$/u,"");}function rZ(e,t){var n;let l=null!=(n=null==t?void 0:t.trim())?n:"";if(0===e.trim().length||0===l.length)return l;let a=rQ(e),i=rQ(l),r=a.toLowerCase(),s=i.toLowerCase();return s===r?"":s.startsWith(`${r}/`)?i.slice(a.length+1).replace(/^\/+/u,""):l;}function r0(e,t,n){let l=[],a=t=>{let n=rZ(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 r1(e,t){let n={};for(let[l,a]of Object.entries(t.panes))n[l]=function(e,t){let n=r0(e,t.activeFile,t.openFiles),l=rZ(e,t.activeFile)||n[0]||"",a=r0(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 r2(e){return r1(e.root,e5({root:e.root,file:e.file,openFiles:e.openFiles,layoutJson:e.layoutJson,defaultSidebarWidth:260,minSidebarWidth:180,maxSidebarWidth:440}));}function r4(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 r3(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,a.jsx)("div",{className:"ed-dialog-backdrop",role:"presentation",children:(0,a.jsxs)("div",{className:"ed-dirty-dialog",ref:n,role:"dialog","aria-modal":"true","aria-labelledby":t,tabIndex:-1,children:[(0,a.jsx)("h2",{id:t,children:"Unsaved editor changes"}),(0,a.jsx)("p",{children:"Choose how to handle these files before continuing."}),(0,a.jsx)("ul",{children:e.pending.dirtyFiles.map(e=>(0,a.jsx)("li",{children:e},e))}),void 0!==e.pending.error?(0,a.jsx)("p",{role:"alert",children:e.pending.error}):null,(0,a.jsxs)("div",{className:"ed-dialog-actions",children:[(0,a.jsx)("button",{type:"button",className:"ed-save",onClick:e.onSave,disabled:e.pending.saving,children:e.pending.saving?"Saving...":"Save"}),(0,a.jsx)("button",{type:"button",className:"ed-reload",onClick:e.onDiscard,disabled:e.pending.saving,children:"Discard"}),(0,a.jsx)("button",{type:"button",className:"ed-icon-action",onClick:e.onCancel,disabled:e.pending.saving,children:"Cancel"})]})]})});}function r5(e){var t,n;let{root:l,file:r,openFiles:s,layoutJson:o,onWorkspaceChange:c,...d}=e,u=null!=(t=null==l?void 0:l.trim())?t:"",p=rZ(u,r),m=r0(u,p,s),h=r2({root:u,file:p,openFiles:m,layoutJson:o}),[f,g]=(0,i.useState)(u),[v,b]=(0,i.useState)(h),[x,y]=(0,i.useState)({}),[j,w]=(0,i.useState)(null),[k,S]=(0,i.useState)(null),[C,I]=(0,i.useState)(null),R=(0,i.useRef)(0),$=(0,i.useRef)(new Map()),E=(0,i.useRef)(null!=(n=null==l?void 0:l.trim())?n:""),A=(0,i.useRef)(null),F=(0,i.useCallback)((e,t)=>{var n;let l=e9(t);return{root:e,file:l.activeFile.length>0?l.activeFile:void 0,openFiles:(n=tu(t)).length>0?n:void 0,layoutJson:e6(t)};},[]),T=(0,i.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:f,n=r1(t,e);b(n),t.length>0&&(null==c||c(F(t,n)));},[F,c,f]);(0,i.useEffect)(()=>{var e,t;let n=null!=(e=null==l?void 0:l.trim())?e:"",a=rZ(n,r),i=r0(n,a,s),d=r2({root:n,file:a,openFiles:i,layoutJson:o}),u=e9(d),p=tu(d),m=E.current!==n;if(E.current=n,g(n),b(d),m&&y({}),0===n.length||void 0===c)return;let h=(null!=(t=null==r?void 0:r.trim())?t:"")!==u.activeFile,f=void 0===s?0!==p.length:!(s.length===p.length&&s.every((e,t)=>e===p[t])),v=o!==e6(d);(h||f||v)&&c(F(n,d));},[F,s,r,o,c,l]);let D=(0,i.useMemo)(()=>r4(x),[x]),M=e9(v),P=M.activeFile;(0,i.useEffect)(()=>{if(0===D.length)return;let e=e=>{e.preventDefault(),e.returnValue="";};return window.addEventListener("beforeunload",e),()=>{window.removeEventListener("beforeunload",e);};},[D.length]);let q=(0,i.useCallback)((e,t,n)=>{y(l=>{var a;let i=null!=(a=l[e])?a:{};if(n)return!0===i[t]?l:{...l,[e]:{...i,[t]:!0}};if(!0!==i[t])return l;let{[t]:r,...s}=i;return{...l,[e]:s};});},[]),L=(0,i.useCallback)((e,t)=>{R.current+=1;let n=R.current;return T(td(v,{type:"select-file",paneId:e,file:t})),I({id:n,paneId:e,file:t}),new Promise(e=>{$.current.set(n,e);});},[T,v]),z=(0,i.useCallback)((e,t,n,l)=>{let a=$.current.get(e);$.current.delete(e),(null==C?void 0:C.id)===e&&I(null),l&&q(t,n,!1),null==a||a(l);},[q,null==C?void 0:C.id]),O=(0,i.useCallback)(e=>{var t,n,l;let a,i=new Set(r4(x)),r="root-change"===e.reason||"window-close"===e.reason?e.files.filter(e=>i.has(e)):(t=e.paneId,n=e.files,a=null!=(l=x[t])?l:{},n.filter(e=>!0===a[e]));return 0===r.length?(e.apply(),!0):(w({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:r,reason:e.reason}),apply:e.apply,dirtyFiles:r,saving:!1}),!1);},[x]),K=(0,i.useCallback)(()=>{null===j||j.saving||(w({...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 L(l,n)))return void w({...j,saving:!1,error:"Save failed. The close action was not applied."});}j.apply(),w(null);})());},[x,j,L]),W=(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]&&q(t,e,!1);j.apply(),w(null);}},[x,q,j]),B=(0,i.useCallback)(()=>{(null==j?void 0:j.saving)!==!0&&w(null);},[null==j?void 0:j.saving]),U=(0,i.useCallback)(e=>{var t;let n=e.trim();0===n.length||O({paneId:null!=(t=e8(v)[0])?t:v.activePaneId,files:D,reason:"root-change",apply:()=>{let e=td(v,{type:"replace-root",root:n,sidebarWidth:v.sidebarWidth});g(n),y({}),T(e,n);}});},[T,D,v,O]),_=(0,i.useCallback)((e,t)=>{let n=e.trim(),l=rZ(n,t);if(0===n.length||0===l.length)return;let a=td(v,{type:"open-file",paneId:M.id,file:l});g(n),T(a,n);},[T,M.id,v]),V=(0,i.useCallback)((e,t)=>{0!==f.length&&0!==t.length&&T(td(v,{type:"select-file",paneId:e,file:t}));},[T,v,f]),J=(0,i.useCallback)(async(e,t)=>O({paneId:e,files:[t],reason:"tab-close",apply:()=>{q(e,t,!1),T(td(v,{type:"close-tab",paneId:e,file:t}));}}),[T,v,q,O]),H=(0,i.useCallback)((e,t)=>{T(td(v,{type:"split-pane",paneId:e,direction:t}));},[T,v]),Y=(0,i.useCallback)(e=>{let t=v.panes[e];void 0!==t&&O({paneId:e,files:t.openFiles,reason:"pane-close",apply:()=>{y(t=>{let{[e]:n,...l}=t;return l;}),T(td(v,{type:"close-pane",paneId:e}));}});},[T,v,O]),X=(0,i.useCallback)(()=>{T(td(v,{type:"set-sidebar",collapsed:!v.sidebarCollapsed}));},[T,v]),G=(0,i.useCallback)(e=>{null===A.current||T(td(v,{type:"set-sidebar",width:rG(e-A.current.getBoundingClientRect().left,180,440),collapsed:!1}));},[T,v]),Q=(0,i.useCallback)(e=>{1===e.buttons&&G(e.clientX);},[G]),Z=(0,i.useCallback)((e,t,n,l)=>{let a="row"===e.direction?(n-t.left)/t.width*100:(l-t.top)/t.height*100;T(td(v,{type:"resize-split",splitId:e.id,ratio:rG(a,15,85)}));},[T,v]),ee=(0,i.useCallback)(e=>{e.preventDefault();let t=e=>G(e.clientX),n=()=>{window.removeEventListener("mousemove",t),window.removeEventListener("mouseup",n);};window.addEventListener("mousemove",t),window.addEventListener("mouseup",n,{once:!0});},[G]),et=(0,i.useCallback)((e,t)=>{t.preventDefault();let n=t.currentTarget.parentElement;if(null===n)return;let l=t=>Z(e,n.getBoundingClientRect(),t.clientX,t.clientY),a=()=>{window.removeEventListener("mousemove",l),window.removeEventListener("mouseup",a);};window.addEventListener("mousemove",l),window.addEventListener("mouseup",a,{once:!0});},[Z]),en=(0,i.useCallback)(e=>{e.currentTarget.setPointerCapture(e.pointerId);},[]),el=(0,i.useCallback)(e=>{e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId);},[]),ea=(0,i.useCallback)((e,t,n)=>{if(!n.altKey)return;let l=v.panes[e];if(void 0!==l&&("ArrowLeft"===n.key||"ArrowRight"===n.key)){n.preventDefault();let a=e8(v);if(n.shiftKey){let l=a.indexOf(e),i="ArrowLeft"===n.key?a[l-1]:a[l+1];void 0!==i&&T(td(v,{type:"move-tab",fromPaneId:e,toPaneId:i,file:t}));return;}let i=l.tabOrder.indexOf(t);T(td(v,{type:"reorder-tab",paneId:e,file:t,targetIndex:"ArrowLeft"===n.key?i-1:i+1}));}},[T,v]),ei=(0,i.useCallback)((e,t,n)=>{n.preventDefault(),null!==k&&(T(td(v,{type:"drop-tab",intent:{fromPaneId:k.paneId,toPaneId:e,file:k.file,zone:t}})),S(null));},[T,k,v]);if(0===f.length)return(0,a.jsx)(rX,{...d});let er=e=>{if("pane"===e.type){var t;let n,l,i=v.panes[e.paneId];return void 0===i?null:(n=e7(v).map(e=>({paneId:e.id,activeFile:e.activeFile.length>0?e.activeFile:null,openFiles:e.openFiles})),l={...d,root:f,...(i.activeFile.length>0?{file:i.activeFile}:{}),openFiles:i.openFiles,dirtyFiles:D,windowId:`${null!=(t=d.windowId)?t:"editor"}-${i.id}`,paneId:i.id,layoutPanes:n,activePaneId:v.activePaneId,onSelectOpenFile:e=>V(i.id,e),onCloseOpenFile:e=>J(i.id,e),onDirtyChange:(e,t)=>q(i.id,e,t),toolbarExtras:(0,a.jsxs)("span",{className:"ed-pane-actions","aria-label":"Editor split controls",children:[(0,a.jsx)("button",{type:"button",className:"ed-icon-action","aria-label":`Split ${i.activeFile||"editor"} right`,title:"Split right",onClick:()=>H(i.id,"row"),children:(0,a.jsx)(N.F.split,{size:14})}),(0,a.jsx)("button",{type:"button",className:"ed-icon-action","aria-label":`Split ${i.activeFile||"editor"} down`,title:"Split down",onClick:()=>H(i.id,"column"),children:(0,a.jsx)(N.F.tile,{size:14})}),e8(v).length>1?(0,a.jsx)("button",{type:"button",className:"ed-icon-action","aria-label":`Close split ${i.activeFile||"editor"}`,title:"Close split",onClick:()=>Y(i.id),children:(0,a.jsx)(N.F.close,{size:14})}):null]}),externalSaveRequest:null!==C&&C.paneId===i.id?C:void 0,onExternalSaveComplete:z},(0,a.jsxs)("section",{className:"ed-pane","data-active":i.id===v.activePaneId?"true":"false","data-dragging":null===k?"false":"true",children:[(0,a.jsx)("div",{className:"ed-pane-drop-zones","aria-hidden":"true",children:["left","right","top","bottom","center"].map(e=>(0,a.jsx)("button",{type:"button",className:`ed-pane-drop-zone ${e}`,tabIndex:-1,"aria-label":`Drop tab ${e}`,onDragOver:e=>e.preventDefault(),onDrop:t=>ei(i.id,e,t)},e))}),(0,a.jsx)(rX,{...l,renderTabHandle:(e,t,n)=>({draggable:!0,onDragStart:t=>{t.dataTransfer.effectAllowed="move",t.dataTransfer.setData("text/plain",e),S({paneId:i.id,file:e});},onDragEnd:()=>S(null),onKeyDown:t=>ea(i.id,e,t),"data-active":t?"true":"false","data-dirty":n?"true":"false"})})]},i.id));}return(0,a.jsxs)("div",{className:`ed-panes ${e.direction}`,"data-split-id":e.id,style:{"--ed-split-ratio":`${String(e.ratio)}%`},children:[er(e.first),(0,a.jsx)("button",{type:"button",className:"ed-pane-resizer","aria-label":"Resize editor split",title:"Resize editor split",onPointerDown:en,onPointerMove:t=>{if(1!==t.buttons)return;let n=t.currentTarget.parentElement;null!==n&&Z(e,n.getBoundingClientRect(),t.clientX,t.clientY);},onPointerUp:el,onPointerCancel:el,onMouseDown:t=>et(e,t)}),er(e.second)]});},es=1===e8(v).length;return(0,a.jsxs)("div",{className:`editor-workspace${v.sidebarCollapsed?" sidebar-collapsed":""}`,ref:A,style:{"--ed-sidebar-width":`${String(v.sidebarWidth)}px`},children:[v.sidebarCollapsed?(0,a.jsx)("button",{type:"button",className:"ed-sidebar-restore","aria-label":"Show project tree",title:"Show project tree",onClick:X,children:(0,a.jsx)(N.F.sidebar,{size:15})}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("aside",{className:"ed-sidebar","aria-label":"Editor files",children:[(0,a.jsx)("div",{className:"ed-sidebar-chrome",children:(0,a.jsx)("button",{type:"button",className:"ed-icon-action","aria-label":"Hide project tree",title:"Hide project tree",onClick:X,children:(0,a.jsx)(N.F.sidebar,{size:14})})}),(0,a.jsx)(rY,{root:f,activeFilePath:P.length>0?P:void 0,openFilesDirectly:!0,onRootChange:U,onOpenFile:_})]}),(0,a.jsx)("button",{type:"button",className:"ed-sidebar-resizer","aria-label":"Resize project tree",title:"Resize project tree",onPointerDown:en,onPointerMove:Q,onPointerUp:el,onPointerCancel:el,onMouseDown:ee})]}),(0,a.jsx)("div",{className:"ed-main",children:(0,a.jsx)("div",{className:`ed-panes ed-panes-root${es?" single":""}`,children:er(v.tree)})}),null!==j?(0,a.jsx)(r3,{pending:j,onSave:K,onDiscard:W,onCancel:B}):null]});}async function r6(e,t){var n,l;let a=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),i="GET"!==a&&"HEAD"!==a,r=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(!r.ok){let e="INTERNAL",t=`HTTP ${r.status.toString()}`;try{let n=await r.json();e=n.error.code,t=n.error.message;}catch{}throw new k.hD(e,t,r.status);}if(204!==r.status)return r.json();}async function r8(e){return r6(`/api/browser/status?port=${encodeURIComponent(String(e))}`);}async function r7(e){return r6("/api/browser/sessions",{method:"POST",body:JSON.stringify({port:e})});}async function r9(e){await r6(`/api/browser/sessions/${encodeURIComponent(e)}`,{method:"DELETE"});}async function se(e,t){return r6(`/api/browser/sessions/${encodeURIComponent(e)}/navigate`,{method:"POST",body:JSON.stringify({url:t})});}async function st(e){return r6(`/api/browser/sessions/${encodeURIComponent(e)}/screenshot`,{method:"POST",body:JSON.stringify({})});}async function sn(e,t){return r6(`/api/browser/sessions/${encodeURIComponent(e)}/apply`,{method:"POST",body:JSON.stringify({captureSeq:t})});}async function sl(e){return r6(`/api/browser/sessions/${encodeURIComponent(e)}/content`,{method:"POST",body:JSON.stringify({})});}function sa(e){return e instanceof k.hD?{code:e.code,message:e.message}:e instanceof Error?{code:"INTERNAL",message:e.message}:{code:"INTERNAL",message:"Unexpected error."};}function si(e){var t,n;let l=null!=(t=e.cdpPort)?t:9222,r=null!=(n=e.url)?n:"http://localhost:5173",[s,o]=(0,i.useState)(String(l)),[c,d]=(0,i.useState)(r),[u,p]=(0,i.useState)(null),[m,h]=(0,i.useState)(null),[f,g]=(0,i.useState)(!1),[v,b]=(0,i.useState)(null),[x,y]=(0,i.useState)(null),[j,w]=(0,i.useState)([]),[k,N]=(0,i.useState)(null),[S,C]=(0,i.useState)(null),[I,R]=(0,i.useState)(null),$=(0,i.useRef)(null),E=(0,i.useCallback)(()=>{y(null);},[]),A=(0,i.useCallback)(e=>{w(t=>{let n=[...t,e];return n.length>50?n.slice(n.length-50):n;}),"navigated"===e.kind&&"string"==typeof e.payload.originOnly&&R(e.payload.originOnly),"error"===e.kind&&y({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=$.current)||e.close(),$.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 $.current=n,()=>{n.close(),$.current=null;};},[u,A]);let F=(0,i.useCallback)(async()=>{E(),g(!0);try{let e=Number.parseInt(s,10),t=await r8(e);h(t);}catch(e){y(sa(e));}finally{g(!1);}},[s,E]),T=(0,i.useCallback)(async()=>{E(),g(!0);try{let e=Number.parseInt(s,10),t=await r7(e);p(t),w([]),C(null),R(null);}catch(e){y(sa(e));}finally{g(!1);}},[s,E]),D=(0,i.useCallback)(async()=>{if(null!==u){E(),g(!0);try{await r9(u.sessionId),p(null),N(null),C(null),R(null);}catch(e){y(sa(e));}finally{g(!1);}}},[u,E]),M=(0,i.useCallback)(async()=>{if(null!==u){E(),g(!0);try{let e=await se(u.sessionId,c);R(e.originOnly);}catch(e){y(sa(e));}finally{g(!1);}}},[u,c,E]),P=(0,i.useCallback)(async()=>{if(null!==u){E(),g(!0);try{let e=await st(u.sessionId);e.persisted||N({seq:e.seq,dataBase64:e.dataBase64});}catch(e){y(sa(e));}finally{g(!1);}}},[u,E]),q=(0,i.useCallback)(async()=>{if(null!==u&&null!==k){E(),g(!0);try{let e=await sn(u.sessionId,k.seq);e.persisted&&C(e.path),N(null);}catch(e){y(sa(e));}finally{g(!1);}}},[u,k,E]),L=(0,i.useCallback)(async()=>{if(null!==u){E(),g(!0);try{await sl(u.sessionId);}catch(e){y(sa(e));}finally{g(!1);}}},[u,E]),z=(0,i.useMemo)(()=>f||null!==u,[f,u]),O=(0,i.useMemo)(()=>f||null===u,[f,u]),K=f||null!==u,W=f||null===k,B=f&&null!==v?v:null!==k?"Screenshot ready (dry-run) — press Apply to persist.":null!==S?`Persisted as ${S}.`:null!==I?`Current origin: ${I}`:null!==m&&null===u?`Reachable: ${m.reachable?"yes":"no"}`:"";return(0,a.jsxs)("div",{className:"browser",children:[(0,a.jsxs)("div",{className:"bw-bar",children:[(0,a.jsx)("span",{className:"bw-dot",style:{background:null===u?"var(--line-strong)":"var(--ok)"},"aria-hidden":"true"}),(0,a.jsxs)("label",{className:"bw-field",children:[(0,a.jsx)("span",{className:"bw-field-label",children:"Port"}),(0,a.jsx)("input",{type:"text",inputMode:"numeric",className:"bw-input",value:s,onChange:e=>o(e.target.value),disabled:null!==u||f})]}),(0,a.jsxs)("label",{className:"bw-field bw-field-url",children:[(0,a.jsx)("span",{className:"bw-field-label",children:"URL"}),(0,a.jsx)("input",{type:"url",className:"bw-input bw-input-url",value:c,onChange:e=>d(e.target.value),disabled:f})]})]}),(0,a.jsxs)("div",{className:"bw-actions",role:"group","aria-label":"Browser actions",children:[(0,a.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{K||(b("Checking Chrome…"),F());},"aria-disabled":K,children:"Check"}),(0,a.jsx)("button",{type:"button",className:"bw-btn bw-btn-primary",onClick:()=>{z||(b("Opening session…"),T());},"aria-disabled":z,children:"Open session"}),(0,a.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{O||(b("Navigating…"),M());},"aria-disabled":O,children:"Navigate"}),(0,a.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{O||(b("Capturing screenshot…"),P());},"aria-disabled":O,children:"Screenshot"}),(0,a.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{W||(b("Applying screenshot…"),q());},"aria-disabled":W,children:"Apply"}),(0,a.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{O||(b("Capturing HTML…"),L());},"aria-disabled":O,children:"Capture HTML"}),(0,a.jsx)("button",{type:"button",className:"bw-btn bw-btn-danger",onClick:()=>{O||(b("Closing session…"),D());},"aria-disabled":O,children:"Close"})]}),(0,a.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite",children:B}),f&&null!==v?(0,a.jsx)("p",{className:"bw-status",children:v}):null,null!==m&&null===u?(0,a.jsxs)("p",{className:"bw-status",children:["Reachable: ",m.reachable?"yes":"no",null===m.browserVersion?"":` — ${m.browserVersion}`]}):null,null!==I?(0,a.jsxs)("p",{className:"bw-status",children:["Current origin: ",(0,a.jsx)("span",{className:"mono",children:I})]}):null,null!==k?(0,a.jsx)("p",{className:"bw-status",children:"Screenshot ready (dry-run) — press Apply to persist."}):null,null!==S?(0,a.jsxs)("p",{className:"bw-status",children:["Persisted as ",(0,a.jsx)("span",{className:"mono",children:S}),"."]}):null,null!==x?(0,a.jsxs)("div",{className:"bw-error",role:"alert",children:[x.message," ",(0,a.jsxs)("span",{className:"err-code mono",children:["(",x.code,")"]})]}):null,(0,a.jsx)("div",{className:"bw-view",children:null!==k?(0,a.jsx)("img",{className:"bw-screenshot",src:`data:image/png;base64,${k.dataBase64}`,alt:"Pending screenshot preview"}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"ph-stripes","aria-hidden":"true"}),(0,a.jsx)("div",{className:"bw-overlay mono",children:null===u?"No session — choose a port and press Open session":"Session open — use Screenshot to capture a preview"})]})}),(0,a.jsx)("div",{className:"bw-log",role:"log","aria-label":"Browser event log",children:(0,a.jsx)("ul",{className:"bw-log-list",children:j.slice(-10).reverse().map((e,t)=>(0,a.jsxs)("li",{className:"bw-log-item",children:[(0,a.jsx)("span",{className:"bw-log-kind",children:function(e){switch(e){case"session-opened":return"session opened";case"navigated":return"navigated";case"screenshot-captured":return"screenshot captured";case"page-content-captured":return"content captured";case"session-closed":return"session closed";case"trust-warning":return"trust warning";case"error":return"error";}}(e.kind)}),(0,a.jsx)("span",{className:"bw-log-detail mono",children:function(e){let t=e.payload;if("navigated"===e.kind){let e="string"==typeof t.originOnly?t.originOnly:"",n="number"==typeof t.httpStatus?` (${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 sr(e,t){var n,l;let a=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),i="GET"!==a&&"HEAD"!==a,r=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(!r.ok){let e="INTERNAL",t=`HTTP ${r.status.toString()}`;try{let n=await r.json();e=n.error.code,t=n.error.message;}catch{}throw new k.hD(e,t,r.status);}if(204!==r.status)return r.json();}async function ss(){return sr("/api/terminal/policy");}async function so(e,t){let n=new URLSearchParams();return n.set("projectId",e),void 0!==t&&t.length>0&&n.set("path",t),sr(`/api/terminal/directories?${n.toString()}`);}async function sc(e){return sr("/api/terminal/executions",{method:"POST",body:JSON.stringify(e)});}async function sd(e){await sr(`/api/terminal/executions/${encodeURIComponent(e)}`,{method:"DELETE"});}function su(e){return e instanceof k.hD?{code:e.code,message:e.message}:e instanceof Error?{code:"INTERNAL",message:e.message}:{code:"INTERNAL",message:"Unexpected error."};}function sp(e){var t,n,l;let[r,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,x]=(0,i.useState)(null),[y,j]=(0,i.useState)(null),[w,k]=(0,i.useState)(null),[N,S]=(0,i.useState)([]),C=(0,i.useRef)(null),I=(0,i.useRef)(!1),R=(0,i.useRef)(null),[$,E]=(0,i.useState)([]);(0,i.useEffect)(()=>{let e=!1;return ss().then(t=>{e||(s(t),c(e=>{var n;return e.length>0?e:null!=(n=t.commands[0])?n:"";}));}).catch(t=>{e||k(su(t));}),()=>{e=!0;};},[]),(0,i.useEffect)(()=>{if(0===h.length)return void E([]);let e=!1;return so(h,p.length>0?p:void 0).then(t=>{e||E(t.entries);}).catch(()=>{e||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&&I.current){let e=t.payload;"string"==typeof e.requestId&&e.requestId===R.current&&x(e=>null!==e?e:t.executionId);}if("execution-completed"===t.kind||"execution-failed"===t.kind||"execution-cancelled"===t.kind){let e=t.payload;"string"==typeof e.requestId&&e.requestId===R.current&&x(e=>null===e||e!==t.executionId?e:null);}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),j(null),x(null);let n="function"==typeof crypto.randomUUID?crypto.randomUUID():`terminal-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;R.current=n;let l=0===(t=d.trim()).length?[]:t.split(/\s+/);I.current=!0,v(!0);try{let e={projectId:h,command:o,args:l,...(p.length>0?{cwd:p}:{}),requestId:n},t=await sc(e);j(t);}catch(e){k(su(e));}finally{I.current=!1,v(!1),R.current=null,x(null);}},[d,o,p,h,g]),F=(0,i.useCallback)(async()=>{if(null!==b)try{await sd(b);}catch(e){k(su(e));}},[b]),T=(0,i.useMemo)(()=>{var e;return null!=(e=null==r?void 0:r.limits)?e:null;},[r]),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,a.jsxs)("div",{className:"terminal",children:[(0,a.jsxs)("form",{className:"tm-form",onSubmit:e=>void A(e),children:[(0,a.jsxs)("label",{className:"tm-field",children:[(0,a.jsx)("span",{children:"Project path"}),(0,a.jsx)("input",{type:"text",value:h,onChange:e=>f(e.target.value),placeholder:"/absolute/path/to/project",required:!0})]}),(0,a.jsxs)("div",{className:"tm-field",children:[(0,a.jsx)("span",{children:"Command"}),(0,a.jsx)(nd,{value:o,ariaLabel:"Command",disabled:null===r,menuTitle:"Allowed commands",mono:!0,sections:[{options:null!=(l=null==r?void 0:r.commands.map(e=>({value:e,label:e})))?l:[]}],onValueChange:c})]}),(0,a.jsxs)("label",{className:"tm-field",children:[(0,a.jsx)("span",{children:"Args (space-separated)"}),(0,a.jsx)("input",{type:"text",value:d,onChange:e=>u(e.target.value),placeholder:"e.g. -la src"})]}),(0,a.jsxs)("label",{className:"tm-field",children:[(0,a.jsx)("span",{children:"Working directory (optional)"}),(0,a.jsx)("input",{type:"text",value:p,onChange:e=>m(e.target.value),placeholder:"(project root)",list:"tm-cwd-suggestions"}),(0,a.jsx)("datalist",{id:"tm-cwd-suggestions",children:$.map(e=>(0,a.jsx)("option",{value:e.path},e.path))})]}),(0,a.jsxs)("div",{className:"tm-actions",children:[(0,a.jsx)("button",{type:"submit",className:"tm-action","data-primary":"true",ref:D,disabled:null===r,"aria-disabled":g||null===r,children:g?"Running…":"Run"}),g?(0,a.jsx)("button",{type:"button",className:"tm-action","aria-disabled":null===b,onClick:()=>void F(),children:"Cancel"}):null]}),null!==T?(0,a.jsxs)("p",{className:"tm-limits",children:["Limits: ",(0,l9.z3)(T.maxOutputBytes)," output \xb7"," ",(0,l9._V)(T.defaultTimeoutMs)," timeout"]}):null]}),null!==w?(0,a.jsxs)("div",{className:"tm-error",role:"alert",children:[(0,a.jsxs)("span",{className:"tm-error-text",children:[w.message," ",(0,a.jsxs)("span",{className:"err-code mono",children:["(",w.code,")"]})]}),(0,a.jsx)("button",{type:"button",className:"tm-error-dismiss","aria-label":"Dismiss error",onClick:()=>k(null),children:"✕"})]}):null,(0,a.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite",children:null!==y?`Command finished: exit ${String(y.exitCode)}, ${String(y.durationMs)} ms${y.truncated?", output truncated":""}${y.timedOut?", timed out":""}`:""}),null!==y?(0,a.jsxs)("div",{className:"tm-result",children:[(0,a.jsxs)("div",{className:"tm-badges",children:[(0,a.jsxs)("span",{className:0===y.exitCode?"tm-badge tm-badge-ok":"tm-badge tm-badge-fail",children:["exit ",String(y.exitCode)]}),(0,a.jsxs)("span",{className:"tm-badge",children:[y.durationMs," ms"]}),y.truncated?(0,a.jsx)("span",{className:"tm-badge tm-badge-warn",children:"truncated"}):null,y.timedOut?(0,a.jsx)("span",{className:"tm-badge tm-badge-warn",children:"timed out"}):null]}),y.stdout.length>0?(0,a.jsx)("pre",{className:"tm-stdout",children:y.stdout}):null,y.stderr.length>0?(0,a.jsx)("pre",{className:"tm-stderr",children:y.stderr}):null]}):null,(0,a.jsx)("ul",{className:"tm-events",role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":"false","aria-label":"Recent terminal events",children:N.map((e,t)=>{var n;let l;return(0,a.jsxs)("li",{className:"tm-event",children:[(0,a.jsx)("span",{className:"tm-event-kind",children:function(e){switch(e){case"execution-started":return"started";case"execution-completed":return"completed";case"execution-failed":return"failed";case"execution-cancelled":return"cancelled";}}(e.kind)}),(0,a.jsx)("span",{className:"tm-event-detail",children:(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}`);})})]});}function sm(e){return e.startsWith("a/")||e.startsWith("b/")?e.slice(2):e;}function sh(e){return e instanceof k.hD?{code:e.code,message:e.message}:e instanceof Error?{code:"INTERNAL",message:e.message}:{code:"INTERNAL",message:"Unexpected error."};}function sf(e){return("dry-run"===e.status||"fix-proposed"===e.status)&&void 0!==e.proposedDiff&&void 0===e.appliedAt;}function sg(e){return void 0!==e.proposedDiff&&""!==e.proposedDiff;}function sv(e){let{href:t,hasManifest:n,error:l}=e;return n?(0,a.jsx)("a",{className:"rv-evidence-link",href:t,target:"_blank",rel:"noopener noreferrer",children:"Evidence"}):null!==l?(0,a.jsxs)("span",{className:"rv-evidence-link rv-evidence-error",role:"alert",children:["Evidence error: ",l.message]}):(0,a.jsx)("button",{type:"button",className:"rv-evidence-link rv-evidence-disabled",disabled:!0,children:"Evidence"});}function sb(e){let{tokens:t}=e;return(0,a.jsx)(a.Fragment,{children:t.map((e,t)=>(0,a.jsx)("span",{className:`hl-${e[0]}`,children:e[1]},t))});}function sx(e){var t,n,l;let i,{line:r,lang:s}=e,o="add"===r.kind?"+":"del"===r.kind?"−":"ctx"===r.kind?"\xb7":"",c="ctx"===r.kind?"":` rv-${r.kind}`;if("meta"!==r.kind&&"code"!==s){let e=null!=(l=il(r.text,a9(s))[0])?l:[];i=(0,a.jsx)(sb,{tokens:e});}else i=r.text;return(0,a.jsxs)("div",{className:`rv-line${c}`,children:[(0,a.jsx)("span",{className:"rv-sr-only",children:{add:"Added line",del:"Deleted line",ctx:"Context line",meta:"Diff metadata"}[r.kind]}),(0,a.jsx)("span",{className:"rv-num-old rv-num",children:null!=(t=r.oldLine)?t:""}),(0,a.jsx)("span",{className:"rv-num-new rv-num",children:null!=(n=r.newLine)?n:""}),(0,a.jsx)("span",{className:"rv-gutter","aria-hidden":"true",children:o}),(0,a.jsx)("code",{className:"rv-src",children:i})]});}function sy(e){let{hunk:t,lang:n}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"rv-hunk mono","aria-label":`Hunk header ${t.header}`,children:[(0,a.jsx)("span",{className:"rv-sr-only",children:"Hunk header"}),t.header]}),t.lines.map((e,t)=>(0,a.jsx)(sx,{line:e,lang:n},t))]});}function sj(e){var t;let{file:n,index:l,changedFiles:i,sectionRef:r}=e,s=i.find(e=>e.path===n.path),o=n.path.includes(".")&&null!=(t=n.path.split(".").pop())?t:"code";return(0,a.jsxs)("section",{id:`rv-file-${l}`,"aria-labelledby":`rv-file-${l}-h`,ref:r,children:[(0,a.jsxs)("h3",{id:`rv-file-${l}-h`,className:"rv-file mono",children:[(0,a.jsx)("span",{className:"rv-path",children:n.path}),void 0!==n.oldPath&&(0,a.jsxs)("span",{className:"rv-oldpath",children:[" (was ",n.oldPath,")"]}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("span",{className:"rv-stat add",children:["+",n.addedLines]}),(0,a.jsxs)("span",{className:"rv-stat del",children:["−",n.removedLines]}),(null==s?void 0:s.elevatedReview)===!0&&(0,a.jsx)("span",{className:"rv-elevated","aria-label":"Elevated review",children:"!"})]}),(0,a.jsx)("div",{className:"rv-code mono",children:n.hunks.map((e,t)=>(0,a.jsx)(sy,{hunk:e,lang:o},t))})]});}function sw(e){var t,n;let{runId:l,onRunIdSubmit:r}=e,[s,o]=(0,i.useState)(null),[c,d]=(0,i.useState)(!1),[u,p]=(0,i.useState)(null),[m,h]=(0,i.useState)(!1),[f,g]=(0,i.useState)(null),[v,b]=(0,i.useState)(!1),[x,y]=(0,i.useState)(null),[j,w]=(0,i.useState)(null),[N,S]=(0,i.useState)(""),[C,I]=(0,i.useState)(!1),R=(0,i.useRef)(null);(0,i.useEffect)(()=>()=>{null!==R.current&&window.clearTimeout(R.current);},[]),(0,i.useEffect)(()=>{if(void 0===l||""===l)return;let e=!1;return h(!0),g(null),o(null),d(!1),p(null),w(null),Promise.allSettled([(0,k.Qe)(l),(0,k.tZ)(l)]).then(t=>{let[n,l]=t;if(!e){if("fulfilled"===l.status)d(!0),p(null);else{let e=sh(l.reason);d(!1),p("NOT_FOUND"===e.code?null:e);}if("fulfilled"===n.status){o(n.value.report),h(!1);return;}g(sh(n.reason)),h(!1);}}),()=>{e=!0;};},[l]);let $=`/api/evidence/${encodeURIComponent(null!=l?l:"")}`,E=(0,i.useMemo)(()=>(null==s?void 0:s.proposedDiff)!==void 0?function(e){let t=new TextEncoder(),n=t.encode(e).byteLength;if(0===e.length)return{files:[],truncated:!1,totalBytes:0};let l=e,a=!1;if(n>524288){a=!0;let n=t.encode(e),i=new TextDecoder().decode(n.slice(0,524288)),r=i.lastIndexOf("\n");l=-1===r?i:i.slice(0,r+1);}let i=l.split("\n"),r=i.length>0&&""===i[i.length-1]?i.slice(0,-1):i,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<r.length;){var f,g,v;let e=null!=(f=r[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=sm(`b/${n}`),a=sm(`a/${e}`),i={path:l,hunks:[],addedLines:0,removedLines:0};a!==l&&(i.oldPath=a),o=i;}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:sm(t),hunks:[],addedLines:0,removedLines:0};else if("/dev/null"!==t&&null!==o){let e=sm(t);e!==o.path&&(o.oldPath=e);}h++;continue;}if(e.startsWith("+++ ")){let t=e.slice(4);"/dev/null"!==t&&null!==o?o.path=sm(t):"/dev/null"!==t&&(m(),o={path:sm(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};}(s.proposedDiff):null,[null==s?void 0:s.proposedDiff]),A=null!=(t=null==s?void 0:s.changedFiles)?t:[],F=(0,i.useMemo)(()=>{var e,t;return{added:null!=(e=null==E?void 0:E.files.reduce((e,t)=>e+t.addedLines,0))?e:0,removed:null!=(t=null==E?void 0:E.files.reduce((e,t)=>e+t.removedLines,0))?t:0};},[E]),T=null!==E&&E.files.length>0?Math.min(null!=j?j:0,E.files.length-1):null,D=null!==T?null==E?void 0:E.files[T]:void 0,M=(null==s?void 0:s.status)==="running";return void 0===l||""===l?(0,a.jsxs)("section",{className:"review rv-empty","aria-label":"Diff review",children:[(0,a.jsx)("h2",{className:"rv-empty-h",children:"Review"}),void 0!==r?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{className:"rv-empty-p",children:"Paste a run ID below to load a proposed diff."}),(0,a.jsxs)("form",{className:"rv-empty-form",onSubmit:e=>{e.preventDefault();let t=N.trim();0!==t.length&&r(t);},children:[(0,a.jsx)("label",{className:"rv-empty-label",htmlFor:"rv-runid-input",children:"Run ID"}),(0,a.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,a.jsx)("button",{type:"submit",className:"arun-btn",children:"Load run"})]})]}):(0,a.jsx)("p",{className:"rv-empty-p",children:"Enter a run ID in the window configuration to load a proposed diff."})]}):(0,a.jsxs)("section",{className:"review","aria-label":"Diff review",children:[m&&(0,a.jsxs)("div",{className:"rv-loading",role:"status","aria-busy":"true","aria-label":"Loading diff",children:[(0,a.jsx)("div",{className:"rv-skel"}),(0,a.jsx)("div",{className:"rv-skel rv-skel-sm"})]}),!m&&null!==f&&(0,a.jsxs)("div",{role:"alert",className:"rv-error",children:["NOT_FOUND"===f.code?"No run with that ID was found.":(0,a.jsxs)(a.Fragment,{children:[f.message," ",(0,a.jsxs)("span",{className:"err-code mono",children:["(",f.code,")"]})]}),(c||null!==u)&&(0,a.jsx)("span",{className:"rv-error-evidence",children:(0,a.jsx)(sv,{href:$,hasManifest:c,error:u})})]}),(0,a.jsx)("p",{role:"status","aria-live":"polite",className:!m&&null===f&&null!==s&&M?"rv-no-diff":"sr-only",children:!m&&null===f&&null!==s&&M?"Run is still running. The proposed diff will appear when the run completes.":""}),!m&&null===f&&null!==s&&!M&&!sg(s)&&(0,a.jsx)("p",{className:"rv-no-diff",children:"This run has no proposed diff to review."}),!m&&null===f&&null!==s&&sg(s)&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"rv-header",children:[(0,a.jsx)("span",{className:"rv-status mono",children:(0,l9.az)(s.status)}),void 0!==s.modelId&&(0,a.jsx)("span",{className:"rv-model mono",children:s.modelId}),(0,a.jsxs)("span",{className:"rv-counts mono",children:[null!==E&&`${E.files.length} file${1!==E.files.length?"s":""}`," ",(0,a.jsxs)("span",{className:"rv-stat add",children:["+",F.added]})," ",(0,a.jsxs)("span",{className:"rv-stat del",children:["−",F.removed]})]}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsx)(sv,{href:$,hasManifest:c,error:u})]}),null!==E&&E.files.length>0&&null!==T&&void 0!==D&&(0,a.jsxs)("div",{className:"rv-layout",children:[(0,a.jsx)("nav",{className:"rv-filelist","aria-label":"Changed files",children:(0,a.jsx)("ul",{children:E.files.map((e,t)=>{let n=A.find(t=>t.path===e.path),l=T===t;return(0,a.jsx)("li",{children:(0,a.jsxs)("button",{type:"button",className:"rv-filerow",title:e.path,"aria-pressed":l,"aria-controls":l?`rv-file-${t}`:void 0,onClick:()=>{w(t);},children:[(0,a.jsx)("span",{className:"rv-filerow-path mono",children:function(e){if(e.length<=40)return e;let t=e.split("/");return t.length<=2?e:`…/${t.slice(-2).join("/")}`;}(e.path)}),(0,a.jsxs)("span",{className:"rv-stat add",children:["+",e.addedLines]}),(0,a.jsxs)("span",{className:"rv-stat del",children:["−",e.removedLines]}),(null==n?void 0:n.elevatedReview)===!0&&(0,a.jsx)("span",{className:"rv-elevated","aria-label":"Elevated review",children:"!"})]})},e.path);})})}),(0,a.jsxs)("div",{className:"rv-body",children:[(0,a.jsx)(sj,{file:D,index:T,changedFiles:A,sectionRef:()=>void 0},D.path),E.truncated&&(0,a.jsxs)("p",{role:"note",className:"rv-truncated",children:["Diff truncated at 512 KB. Open the"," ",c?(0,a.jsx)("a",{href:$,target:"_blank",rel:"noopener noreferrer",children:"evidence manifest"}):"evidence manifest"," ","for the full record."]})]})]}),(0,a.jsxs)("div",{className:"rv-controls",children:[(0,a.jsx)("span",{role:"status","aria-live":"polite",className:"rv-apply-status",children:v?"Applying…":void 0!==s.appliedAt?"Applied":""}),null!==x&&(0,a.jsx)("span",{role:"alert",className:"rv-apply-error",children:x.message}),void 0!==s.appliedAt?(0,a.jsx)("span",{className:"rv-final mono",children:"Applied"}):sf(s)?(0,a.jsx)("button",{type:"button",className:"arun-btn","aria-disabled":v,onClick:()=>{if(!v){if(!C){I(!0),null!==R.current&&window.clearTimeout(R.current),R.current=window.setTimeout(()=>{I(!1),R.current=null;},6e3);return;}null!==R.current&&(window.clearTimeout(R.current),R.current=null),I(!1),void 0!==l&&null!==s&&sf(s)&&!v&&(b(!0),y(null),(0,k.qU)(l).then(e=>{o(e.report),b(!1);}).catch(e=>{y(sh(e)),b(!1);}));}},children:v?"Applying…":C?`Confirm apply (${(null!=(n=null==E?void 0:E.files.length)?n:0).toString()} file${(null==E?void 0:E.files.length)===1?"":"s"})`:"Apply"}):null]})]})]});}let sk=new Set(["completed","dry-run","rejected","cancelled","failed","fix-applied","fix-proposed","investigation-only"]),sN={verify:"Verify","explain-plan":"Explain plan","unit-test-generation":"Generate unit tests","bug-investigation":"Investigate bug"};function sS(e,t){return void 0===t||0===t.length?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:e}),(0,a.jsx)("pre",{children:t})]});}let sC={high:"High",medium:"Medium",low:"Low — verify"};function sI(e){let{level:t}=e;return(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Confidence"}),(0,a.jsxs)("span",{className:"ai-conf","data-level":t,children:[(0,a.jsxs)("span",{className:"track","aria-hidden":"true",children:[(0,a.jsx)("i",{}),(0,a.jsx)("i",{}),(0,a.jsx)("i",{})]}),(0,a.jsx)("span",{className:"lbl",children:sC[t]})]})]});}function sR(e){var t,n,l,r,s,o,c,d,u,p,m;let h,{cfg:f={},linkedRoot:g=null,linkedFilePath:v}=e,b=null!=(t=f.runId)?t:null,x="verify"===(p=f.workflow)||"explain-plan"===p||"unit-test-generation"===p||"bug-investigation"===p?p:null,y=null!=(n=f.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;}}(f.inputJson),w=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,i=`/api/runs/${encodeURIComponent(e)}/events`;(t=new EventSource(o.current>=0?`${i}?lastEventId=${o.current.toString()}`:i)).onopen=()=>{l||(a("live"),s(null));},t.onerror=()=>{l||(a("error"),s("Stream disconnected. Attempting to reconnect…"));};let r=e=>{let i;if(!l){try{i=JSON.parse(e.data);}catch{return;}o.current=i.seq,n(e=>[...e,i]),nH.eQ.has(i.type)&&(a("terminal"),null==t||t.close());}};for(let e of nH.$Q)t.addEventListener(e,r);return()=>{l=!0,null==t||t.close();};},[e]),{events:t,status:l,error:r};}(b),[S,C]=(0,i.useState)(null),[I,R]=(0,i.useState)(null),[$,E]=(0,i.useState)(null),[A,F]=(0,i.useState)(!1),[T,D]=(0,i.useState)(null),[M,P]=(0,i.useState)(null),[q,L]=(0,i.useState)(!1),z=(0,i.useRef)(null),O=(0,i.useRef)(null),K=(0,i.useCallback)(async()=>{if(null!==b){E(null);try{let e=await(0,k.Qe)(b);C(e.report),R(null);}catch(e){if(e instanceof k.hD&&404===e.status){try{let e=await(0,k.tZ)(b);R(e.manifest),C(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.");}}},[b]);(0,i.useEffect)(()=>{K();},[K]),(0,i.useEffect)(()=>{"terminal"===w.status&&K();},[K,w.status]),(0,i.useEffect)(()=>{let e=!1;if(0!==y.length)return(0,k.ZC)().then(t=>{var n,l;e||P(null!=(n=null==(l=t.models.find(e=>e.id===y))?void 0:l.costClass)?n:null);}).catch(()=>{e||P(null);}),()=>{e=!0;};},[y]);let W=(0,i.useMemo)(()=>function(e,t){var n,l,a,i,r,s;let o=null!=(n=null==t||null==(i=t.usage)?void 0:i.promptTokens)?n:0,c=null!=(l=null==t||null==(r=t.usage)?void 0:r.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};}(w.events,S),[w.events,S]),B=null!=(l=null!=(r=null==S?void 0:S.durationMs)?r:null==I?void 0:I.run.durationMs)?l:w.events.length>0?Math.max(0,Date.now()-Number(new Date(null!=(s=null==(d=w.events[0])?void 0:d.ts)?s:Date.now()))):0,U=null!==S?S.status:null!==I?I.run.outcome:"loading",_=null!==S?(0,l9.az)(S.status):null!==I?(0,l9.FR)(I.run.outcome):"Loading…",V=null!==S&&sk.has(S.status),J=null!==S&&void 0!==S.proposedDiff&&void 0===S.appliedAt&&("unit-test-generation"===x&&"dry-run"===S.status||"bug-investigation"===x&&"fix-proposed"===S.status),H=!V&&(null==S?void 0:S.status)==="running",Y=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==S?void 0:S.proposedDiff),X=A||"connecting"===w.status||(null==S?void 0:S.status)==="running"||null===S&&null===I&&null===$,G=(0,i.useRef)(!1);(0,i.useEffect)(()=>{if(G.current&&!H&&document.activeElement===document.body){var e;null==(e=O.current)||e.focus();}G.current=H;},[H]),(0,i.useEffect)(()=>()=>{null!==z.current&&window.clearTimeout(z.current);},[]);let Q=async()=>{if(null!==b){E(null);try{await(0,k.Su)(b),await K();}catch(e){E(e instanceof Error?e.message:"Unable to cancel run.");}}},Z=async()=>{if(null!==b&&J&&!A){F(!0),D(null);try{let e=await(0,k.qU)(b);C(e.report);}catch(e){D(e instanceof Error?e.message:"Unable to apply run.");}finally{F(!1);}}};return null===b||null===x?(0,a.jsxs)("div",{className:"arun arun-empty",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Agent run is not configured."}),(0,a.jsx)("p",{children:"Open a new Agent window from the launcher to start a workflow."})]}):(0,a.jsxs)("div",{className:"arun arun-real","aria-busy":X?"true":void 0,children:[(0,a.jsxs)("div",{className:"arun-head",children:[(0,a.jsx)("span",{className:"arun-role",children:sN[x]}),y.length>0?(0,a.jsx)("span",{className:"ag-model mono",children:y}):null,null!==M?(0,a.jsx)("span",{className:"arun-gov",title:"Model cost class",children:(0,l9.Kb)(M)}):null,(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("span",{className:"arun-status",children:[(0,a.jsx)("span",{className:"dot","data-live":(null==S?void 0:S.status)==="running","data-status":U}),_]})]}),(0,a.jsxs)("div",{className:"arun-summary",role:"status","aria-live":"polite",children:[(0,a.jsx)("strong",{children:function(e,t,n){var l,a;if(null===t&&null===n)return"Loading run state…";let i=null===e?"Agent run":sN[e];return(null==t?void 0:t.status)==="running"?`${i} is running.`:(null==t?void 0:t.status)==="dry-run"?`${i} produced a reviewable dry-run.`:(null==t?void 0:t.status)==="fix-proposed"?`${i} proposed a fix.`:(null==t?void 0:t.status)==="fix-applied"?`${i} applied changes.`:(null==t?void 0:t.status)==="investigation-only"?`${i} completed without a patch.`:(null==t?void 0:t.status)==="failed"||(null==t?void 0:t.status)==="rejected"?`${i} failed.`:(null==t?void 0:t.status)==="cancelled"?`${i} was cancelled.`:null!==t?`${i} completed.`:(null==n||null==(a=n.patch)?void 0:a.redactedDiff)!==void 0?`${i} evidence loaded with a reviewable diff.`:`${i} evidence loaded: ${null!=(l=null==n?void 0:n.run.outcome)?l:"unknown"}.`;}(x,S,I)}),(0,a.jsxs)("span",{className:"mono",title:b,children:["run ",b.slice(0,8)]})]}),(0,a.jsxs)("div",{className:"arun-meters",children:[(0,a.jsxs)("div",{className:"arun-meter",children:[(0,a.jsx)("span",{className:"arun-mk",children:"Elapsed"}),(0,a.jsx)("span",{className:"arun-mv mono",children:(0,l9._V)(B)})]}),(0,a.jsxs)("div",{className:"arun-meter",children:[(0,a.jsx)("span",{className:"arun-mk",children:"Usage"}),(0,a.jsx)("span",{className:"arun-mv mono",children:0===W.requestCount?"No model usage":`${(0,l9._y)(W.promptTokens+W.completionTokens)} tok`})]}),(0,a.jsxs)("div",{className:"arun-meter",children:[(0,a.jsx)("span",{className:"arun-mk",children:"Latency"}),(0,a.jsx)("span",{className:"arun-mv mono",children:0===W.requestCount?"—":(0,l9._V)(W.latencyMs)})]})]}),(0,a.jsxs)("div",{className:"arun-perms",children:[(0,a.jsxs)("span",{className:"arun-perm","data-on":null!==g,title:null!==g?g:null!=(o=f.workspaceRoot)?o:void 0,children:[(0,a.jsx)(N.F.files,{size:11}),(0,a.jsx)("span",{className:"arun-perm-path",children:null!==g?g:null!=(c=f.workspaceRoot)?c:"no workspace"})]}),void 0!==v?(0,a.jsxs)("span",{className:"arun-perm","data-on":!0,title:v,children:[(0,a.jsx)(N.F.files,{size:11}),(0,a.jsx)("span",{className:"arun-perm-path",children:v})]}):null]}),null!==j?(0,a.jsxs)("details",{className:"arun-input",children:[(0,a.jsx)("summary",{children:"Run input"}),(0,a.jsx)("pre",{children:JSON.stringify(j,null,2)})]}):null,(0,a.jsxs)("div",{className:"arun-log",role:"log","aria-live":"polite","aria-label":"Run events","aria-busy":X?"true":void 0,children:["error"===w.status&&null!==w.error?(0,a.jsxs)("div",{className:"arun-log-row",children:[(0,a.jsx)("span",{className:"arun-log-ico",children:(0,a.jsx)(N.F.reset,{size:12})}),(0,a.jsx)("span",{className:"arun-log-text",children:w.error})]}):null,0===w.events.length?"error"===w.status?null:(0,a.jsxs)("div",{className:"arun-log-row",children:[(0,a.jsx)("span",{className:"arun-log-ico",children:(0,a.jsx)(N.F.reset,{size:12})}),(0,a.jsx)("span",{className:"arun-log-text",children:"connecting"===w.status?"Connecting to run events…":"Waiting for run events…"})]}):w.events.slice().reverse().slice(0,50).map(e=>{let t;return(0,a.jsxs)("div",{className:"arun-log-row",children:[(0,a.jsx)("span",{className:"arun-log-ico",children:(0,a.jsx)(N.F.spark,{size:12})}),(0,a.jsx)("span",{className:"arun-log-text",children:function(e){switch(e.type){case"ready":return"SSE stream ready";case"run:started":return`Started ${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,l9.z3)(e.contextBytes)})`;case"model:call:completed":return`Model call completed (${(0,l9._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,l9.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,l9._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,l9._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,a.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!==S?(0,a.jsxs)("div",{className:"arun-results",children:[void 0===S.report?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Report"}),(0,a.jsx)("pre",{children:S.report})]}),void 0===S.overallStatus||void 0===S.results?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Verification"}),(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Status"}),(0,a.jsx)("strong",{children:S.overallStatus})]}),S.results.slice(0,8).map(e=>(0,a.jsxs)("div",{className:"arun-check-row",children:[(0,a.jsx)("span",{children:e.kind}),(0,a.jsx)("span",{className:"mono",children:e.status})]},`${e.kind}:${e.command}`))]}),sS("Failure",S.failureReason),sS("Covered behavior",S.coveredBehavior),sS("Known gaps",S.knownGaps),sS("Verification note",S.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:"",i="low"===l||"medium"===l||"high"===l?l:void 0,r=l.length>0&&void 0===i?l:void 0;return 0===n.length&&void 0===i&&void 0===r?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Hypothesis"}),n.map(e=>{let[t,n]=e;return(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:t}),(0,a.jsx)("strong",{children:n})]},t);}),void 0!==r?(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Confidence"}),(0,a.jsx)("strong",{children:r})]}):null,void 0!==i?(0,a.jsx)(sI,{level:i}):null]});}(S),void 0===(m=S.nextActions)||0===m.length?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Next actions"}),m.map(e=>(0,a.jsx)("div",{className:"arun-check-row",children:(0,a.jsx)("span",{children:e})},e))]}),void 0!==S.dryRunPreview?(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Dry-run preview"}),(0,a.jsx)("pre",{children:S.dryRunPreview})]}):null,void 0!==S.proposedDiff?(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Proposed diff"}),(0,a.jsx)("pre",{children:S.proposedDiff})]}):null,void 0===(h=S.verificationSummary)?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Verification"}),(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Status"}),(0,a.jsx)("strong",{children:h.overallStatus})]}),(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Duration"}),(0,a.jsx)("strong",{children:(0,l9._V)(h.durationMs)})]}),h.results.slice(0,5).map(e=>(0,a.jsxs)("div",{className:"arun-check-row",children:[(0,a.jsx)("span",{children:e.kind}),(0,a.jsx)("span",{className:"mono",children:e.status})]},`${e.kind}:${e.command}`))]}),void 0!==S.applyReport?(0,a.jsxs)("div",{className:"arun-result-card arun-applied",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Applied"}),(0,a.jsx)("pre",{children:JSON.stringify(S.applyReport,null,2)})]}):null]}):null!==I?(0,a.jsxs)("div",{className:"arun-results",children:[(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Evidence"}),(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Outcome"}),(0,a.jsx)("strong",{children:I.run.outcome})]}),(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Duration"}),(0,a.jsx)("strong",{children:(0,l9._V)(I.run.durationMs)})]}),void 0!==I.patch?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Changed files"}),(0,a.jsx)("strong",{children:I.patch.changedFiles.toString()})]}),(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Patch size"}),(0,a.jsx)("strong",{children:(0,l9.z3)(I.patch.patchBytes)})]})]}):null]}),(null==(u=I.patch)?void 0:u.redactedDiff)!==void 0?(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Proposed diff"}),(0,a.jsx)("pre",{children:I.patch.redactedDiff})]}):null]}):null,null!==$?(0,a.jsx)("div",{className:"arun-error",role:"alert",children:$}):null,null!==T?(0,a.jsx)("div",{className:"arun-error",role:"alert",children:T}):null,(0,a.jsxs)("div",{className:"arun-controls",children:[(0,a.jsx)("a",{className:"arun-btn ghost",href:`/api/evidence/${encodeURIComponent(b)}`,target:"_blank",rel:"noreferrer",ref:O,children:"Evidence"}),J?(0,a.jsx)("button",{type:"button",className:"arun-btn","aria-disabled":A,onClick:()=>{if(!A){if(!q){L(!0),null!==z.current&&window.clearTimeout(z.current),z.current=window.setTimeout(()=>{L(!1),z.current=null;},6e3);return;}null!==z.current&&(window.clearTimeout(z.current),z.current=null),L(!1),Z();}},children:A?"Applying…":q?`Confirm apply (${Y.toString()} file${1===Y?"":"s"})`:"Apply"}):(null==S?void 0:S.appliedAt)!==void 0?(0,a.jsx)("span",{className:"arun-final mono",children:"Applied"}):null,H?(0,a.jsx)("button",{type:"button",className:"arun-btn danger",onClick:()=>void Q(),children:"Cancel"}):null]})]});}let s$=[{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 sE(){return(0,a.jsx)("ul",{className:"integ","aria-label":"Integrations",children:s$.map(e=>(0,a.jsxs)("li",{className:"integ-row",children:[(0,a.jsx)("span",{className:"integ-glyph mono",children:e.glyph}),(0,a.jsxs)("span",{className:"integ-text",children:[(0,a.jsx)("span",{className:"integ-name",children:e.name}),(0,a.jsx)("span",{className:"integ-desc",children:e.desc})]}),(0,a.jsx)("span",{className:"integ-status",children:"Not connected — coming soon"})]},e.name))});}let sA={allow:["Allow","var(--accent)"],ask:["Ask","var(--warn)"],deny:["Deny","var(--danger)"]},sF={allow:"ask",ask:"deny",deny:"allow"},sT=[{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"}],sD=[["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"]],sM=[["calendar","Calendar","automations"],["mail","Mail","bell"],["jira","Jira","review"],["docs","Docs","files"]];function sP(e){let{policy:t,setPolicy:n}=e;return(0,a.jsxs)("div",{className:"pol",children:[(0,a.jsx)("div",{className:"pol-hint",children:"Rights an agent inherits when Keiko governs. Tap a decision to cycle through Allow → Ask → Deny."}),t.map(e=>{let t=sA[e.decision];return(0,a.jsxs)("div",{className:"pol-row",children:[(0,a.jsxs)("div",{className:"pol-text",children:[(0,a.jsx)("span",{className:"pol-action",children:e.action}),(0,a.jsx)("span",{className:"pol-scope mono",children:e.scope})]}),(0,a.jsx)("button",{type:"button",className:"pol-dec",style:{color:t[1],borderColor:t[1]},onClick:()=>{let t;return t=e.id,n(e=>e.map(e=>e.id===t?{...e,decision:sF[e.decision]}:e));},children:t[0]})]},e.id);})]});}function sq(e){let{decide:t}=e,[n,l]=(0,i.useState)(!1),r=sT.map(e=>{let n=t(e.kind,e.risk);return{...e,actual:n,pass:n===e.expect};}),s=r.filter(e=>e.pass).length;return(0,a.jsxs)("div",{className:"evl",children:[(0,a.jsxs)("div",{className:"evl-head",children:[(0,a.jsxs)("button",{type:"button",className:"evl-run",onClick:()=>l(!0),children:[(0,a.jsx)(N.F.spark,{size:13})," Run evaluation"]}),n&&(0,a.jsxs)("span",{className:"evl-score"+(s===r.length?" ok":""),children:[s,"/",r.length," passed"]})]}),(0,a.jsx)("div",{className:"evl-hint",children:"Mock scenarios against your policy before going autonomous."}),r.map(e=>(0,a.jsxs)("div",{className:"evl-row","data-state":n?e.pass?"pass":"fail":"idle",children:[(0,a.jsx)("span",{className:"evl-ico",children:n?e.pass?(0,a.jsx)(N.F.check,{size:13}):(0,a.jsx)(N.F.close,{size:13}):(0,a.jsx)("span",{className:"evl-dot"})}),(0,a.jsx)("span",{className:"evl-label",children:e.label}),n&&(0,a.jsx)("span",{className:"evl-res mono",style:{color:sA[e.actual][1]},children:sA[e.actual][0]})]},e.id))]});}function sL(e){let{bridges:t,setBridges:n}=e;return(0,a.jsxs)("div",{className:"brg",children:[(0,a.jsx)("div",{className:"evl-hint",children:"What your twin can reach on your behalf."}),sM.map(e=>{let[l,i,r]=e,s=N.F[r],o=t[l];return(0,a.jsxs)("button",{type:"button",className:"brg-row","data-on":o,"aria-pressed":o,onClick:()=>n(e=>({...e,[l]:!e[l]})),children:[(0,a.jsx)("span",{className:"brg-ico",children:(0,a.jsx)(s,{size:16})}),(0,a.jsx)("span",{className:"brg-name",children:i}),(0,a.jsx)("span",{className:"brg-tg"+(o?" on":""),children:(0,a.jsx)("span",{})})]},l);})]});}function sz(e){let{persona:t,setPersona:n}=e;return(0,a.jsxs)("div",{className:"prs",children:[(0,a.jsx)("div",{className:"evl-hint",children:"Keiko adapts behaviour & tools to who is at the wheel."}),sD.map(e=>{let[l,i]=e;return(0,a.jsxs)("button",{type:"button",className:"prs-row","data-on":t===l,"aria-pressed":t===l,onClick:()=>n(l),children:[(0,a.jsx)("span",{className:"prs-dot"}),(0,a.jsxs)("span",{className:"prs-text",children:[(0,a.jsx)("span",{className:"prs-name",children:l}),(0,a.jsx)("span",{className:"prs-desc",children:i})]}),t===l&&(0,a.jsx)(N.F.check,{size:14,style:{color:"var(--accent)"}})]},l);})]});}let sO=[["policy","Policy"],["eval","EVAL"],["bridges","Connections"],["persona","Persona"]];function sK(){let e=j(),[t,n]=(0,i.useState)("policy");return(0,a.jsxs)("div",{className:"twin",children:[(0,a.jsxs)("div",{className:"twin-hero",children:[(0,a.jsx)("img",{className:"twin-orca",src:"/assets/keiko-logo.svg",alt:""}),(0,a.jsxs)("div",{className:"twin-id",children:[(0,a.jsx)("span",{className:"twin-name",children:"Keiko — Digital Twin"}),(0,a.jsxs)("span",{className:"twin-sub mono",children:["mirroring \xb7 ",e.persona]})]}),(0,a.jsx)("span",{className:"twin-mode "+("autonomous"===e.mode?"on":""),children:"autonomous"===e.mode?"Autonomous":"Manual"})]}),(0,a.jsx)("div",{className:"twin-tabs",children:sO.map(e=>{let[l,i]=e;return(0,a.jsx)("button",{type:"button",className:"twin-tab","data-on":t===l,onClick:()=>n(l),children:i},l);})}),(0,a.jsxs)("div",{className:"twin-body",children:["policy"===t&&(0,a.jsx)(sP,{policy:e.policy,setPolicy:e.setPolicy}),"eval"===t&&(0,a.jsx)(sq,{decide:e.decide}),"bridges"===t&&(0,a.jsx)(sL,{bridges:e.bridges,setBridges:e.setBridges}),"persona"===t&&(0,a.jsx)(sz,{persona:e.persona,setPersona:e.setPersona})]})]});}function sW(e){return"embedding-only"===e?"Embedding model — not selectable for text conversation":"ocr-vision-only"===e?"OCR/vision-only — not selectable for text conversation":"Not a chat model — not selectable for text conversation";}function sB(){return"Available for embeddings; not shown in the chat model picker";}function sU(e){let{model:t}=e,n=(0,nH.nP)(t);return void 0===n?(0,a.jsx)("span",{className:"ml-elig ml-elig-ok","data-testid":"conv-elig-ok",role:"status","aria-label":"Model eligibility: eligible for conversation",children:"Conversation-eligible"}):"embedding-only"===n?(0,a.jsx)("span",{className:"ml-elig ml-elig-embed","data-testid":"embedding-elig-ok",role:"status","aria-label":"Model eligibility: "+sB(),title:sB(),children:"Embedding-ready"}):(0,a.jsxs)("span",{className:"ml-elig ml-elig-no","data-testid":"conv-elig-no",role:"status","aria-label":"Model eligibility: "+sW(n),title:sW(n),children:["Not selectable — ","ocr-vision-only"===n?"OCR/vision-only":"not a chat model"]});}async function s_(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 sV(e){let t=void 0===e.warning?"":` Warning: ${e.warning}`;return`- ${e.name}: ${e.status} (${e.latencyMs.toString()} ms) ${e.evidence}${t}`;}function sJ(e,t){return e.probes.some(e=>e.name===t&&"passed"===e.status);}function sH(e){let{report:t}=e,[n,l]=(0,i.useState)("idle"),[r,s]=(0,i.useState)("");async function o(){try{var e;let n,a;await s_((e=t,["Keiko Gateway Readiness Report",`Model: ${e.modelId}`,`Checked at: ${e.checkedAt}`,`Overall status: ${e.overallStatus}`,`Verified capabilities: ${n=e.verifiedCapabilities,a=[["streaming",n.streaming],["toolCalling",n.toolCalling],["structuredOutput",n.structuredOutput],["reasoningOutput",n.reasoningOutput],["imageInput",n.imageInput],["documentInput",n.documentInput]].map(e=>{let[t,n]=e;return`${t}=${!0===n?"yes":"no"}`;}),void 0!==n.testedContextTokens&&a.push(`testedContextTokens=${n.testedContextTokens.toString()}`),a.join(", ")}`,"","Probes:",...e.probes.map(sV),"","Raw JSON:",JSON.stringify(e,null,2)].join("\n"))),l("copied"),s("Readiness report copied.");}catch{l("failed"),s("Clipboard access failed. Select and copy the report details manually.");}}return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("button",{type:"button",className:"ml-check secondary","data-copied":"copied"===n?"true":"false","data-failed":"failed"===n?"true":"false",onClick:()=>{o();},children:[(0,a.jsx)(N.F.copy,{size:12,"aria-hidden":"true"}),"copied"===n?"Copied":"Copy report"]}),(0,a.jsx)("span",{className:"ml-url mono",role:"failed"===n?"alert":"status","aria-live":"polite",children:r})]});}function sY(e){var t;let n,{state:l}=e;if(void 0===l||"idle"===l.status)return null;if("running"===l.status)return(0,a.jsxs)("div",{className:"ml-readiness",role:"status",children:["Checking ",l.deep?"deep":"basic"," readiness…"]});if("error"===l.status)return(0,a.jsx)("div",{className:"ml-readiness ml-readiness-error",role:"alert",children:l.message});let i=l.report,r=sJ(i,"chat"),s=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,a.jsx)("div",{className:"ml-readiness",children:(0,a.jsx)("div",{className:"ml-rrow",children:(0,a.jsxs)("div",{className:"ml-rsummary",role:"failed"===i.overallStatus?"alert":"status",children:[(0,a.jsxs)("div",{className:"ml-rhead",children:[(0,a.jsx)("span",{className:"ml-rstatus "+i.overallStatus,children:r?"Working today":"Not verified"}),(0,a.jsx)("span",{className:"ml-rtime mono",children:new Date(i.checkedAt).toLocaleTimeString()})]}),(0,a.jsxs)("div",{className:"ml-rbadges","aria-label":"Verified capabilities",children:[sJ(i,"streaming")?(0,a.jsx)("span",{children:"Streaming"}):null,sJ(i,"tool_calling")?(0,a.jsx)("span",{children:"Tools"}):null,sJ(i,"json_schema")?(0,a.jsx)("span",{children:"JSON"}):null,sJ(i,"reasoning")?(0,a.jsx)("span",{children:"Reasoning"}):null,sJ(i,"image_input")?(0,a.jsx)("span",{children:"Image"}):null,sJ(i,"document_input")?(0,a.jsx)("span",{children:"PDF"}):null,void 0!==i.verifiedCapabilities.testedContextTokens?(0,a.jsxs)("span",{children:[i.verifiedCapabilities.testedContextTokens.toLocaleString()," ctx"]}):null]}),void 0!==s?(0,a.jsx)("div",{className:"ml-rwarn",children:s}):null]})})});}function sX(e){var t;let{model:n,readiness:l,onRunReadiness:i}=e,r=(0,nH.S_)(n),s="embedding"===n.kind;return(0,a.jsxs)("div",{className:"ml-row",children:[(0,a.jsx)("span",{className:"ml-ico",children:(0,a.jsx)(N.F.cube,{size:16})}),(0,a.jsxs)("div",{className:"ml-info",children:[(0,a.jsxs)("div",{className:"ml-top",children:[(0,a.jsx)("span",{className:"ml-name",children:n.id}),(0,a.jsx)("span",{className:"ml-type mono",children:"ocr-vision"===(t=n.kind)?"OCR":t}),(0,a.jsx)(sU,{model:n})]}),(0,a.jsxs)("div",{className:"ml-url mono",children:["tools ",n.toolCalling?"yes":"no"," \xb7 structured"," ",n.structuredOutput?"yes":"no"," \xb7 ",n.costClass,"/",n.latencyClass]}),(0,a.jsx)(sY,{state:l})]}),r?(0,a.jsxs)("div",{className:"ml-actions",children:[(0,a.jsxs)("button",{type:"button",className:"ml-check",disabled:(null==l?void 0:l.status)==="running",onClick:()=>i(n.id,!1),children:[(0,a.jsx)(N.F.activity,{size:13}),"Run readiness check"]}),(0,a.jsx)("button",{type:"button",className:"ml-check secondary",disabled:(null==l?void 0:l.status)==="running",onClick:()=>i(n.id,!0),children:"Deep probes"}),(null==l?void 0:l.status)==="done"?(0,a.jsx)(sH,{report:l.report}):null]}):null,(0,a.jsx)("span",{className:"ml-status "+(r||s?"connected":"ineligible"),title:r?"conversation-eligible":s?"available for embeddings":"not selectable for conversation","aria-hidden":"true"})]});}function sG(){let[e,t]=(0,i.useState)(eu),[n,l]=(0,i.useState)(ep),[r,s]=(0,i.useState)(em),[o,c]=(0,i.useState)(eh),[d,u]=(0,i.useState)(ef),[p,m]=(0,i.useState)(eg);(0,i.useEffect)(()=>{try{window.localStorage.setItem(Q,e?"true":"false");}catch{}window.dispatchEvent(new CustomEvent(ea,{detail:e}));},[e]),(0,i.useEffect)(()=>{try{window.localStorage.setItem(Z,String(n));}catch{}window.dispatchEvent(new CustomEvent(ei,{detail:n}));},[n]),(0,i.useEffect)(()=>{try{window.localStorage.setItem(ee,String(r));}catch{}ev(r),window.dispatchEvent(new CustomEvent(er,{detail:r}));},[r]),(0,i.useEffect)(()=>{try{window.localStorage.setItem(et,String(o));}catch{}eb(o),window.dispatchEvent(new CustomEvent(es,{detail:o}));},[o]),(0,i.useEffect)(()=>{try{window.localStorage.setItem(en,String(d));}catch{}ex(d),window.dispatchEvent(new CustomEvent(eo,{detail:d}));},[d]),(0,i.useEffect)(()=>{try{window.localStorage.setItem(el,String(p));}catch{}ey(p),window.dispatchEvent(new CustomEvent(ec,{detail:p}));},[p]);let h={"--p":`${String(n)}%`},f={"--p":`${String(r)}%`},g={"--p":`${String(o)}%`},v={"--p":`${String(d)}%`},b={"--p":`${String(p)}%`};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"set-sec-h",children:(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"set-sec-t",children:"Workspace wallpaper"}),(0,a.jsx)("div",{className:"set-sec-d",children:"Liquid Chrome — a subtle metallic flow behind the grid that reacts to your cursor and clicks. Turn it off to stop the WebGL animation completely."})]})}),(0,a.jsxs)("div",{className:"gpref",children:[(0,a.jsxs)("div",{className:"gpref-row",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"gpref-label",children:"Liquid wallpaper"}),(0,a.jsx)("div",{className:"gpref-help",children:e?"Running":"Stopped"})]}),(0,a.jsx)(iw,{on:e,onChange:t,label:"Liquid wallpaper"})]}),(0,a.jsxs)("div",{className:"gpref-row",children:[(0,a.jsx)("label",{className:"gpref-label",htmlFor:"wp-op",children:"Wallpaper opacity"}),(0,a.jsxs)("span",{className:"gpref-val mono",children:[n,"%"]})]}),(0,a.jsx)("input",{id:"wp-op",className:"gpref-slider",type:"range",min:0,max:100,step:1,value:n,disabled:!e,onChange:e=>l(Number.parseInt(e.target.value,10)),style:h,"aria-label":"Wallpaper opacity"}),(0,a.jsxs)("div",{className:"gpref-scale",children:[(0,a.jsx)("span",{children:"Off"}),(0,a.jsx)("span",{children:"Full"})]})]}),(0,a.jsxs)("div",{className:"gpref",children:[(0,a.jsxs)("div",{className:"gpref-row",children:[(0,a.jsx)("label",{className:"gpref-label",htmlFor:"ws-bg-bright",children:"Workspace background brightness"}),(0,a.jsxs)("span",{className:"gpref-val mono",children:[r,"%"]})]}),(0,a.jsx)("input",{id:"ws-bg-bright",className:"gpref-slider",type:"range",min:0,max:100,step:1,value:r,onChange:e=>s(Number.parseInt(e.target.value,10)),style:f,"aria-label":"Workspace background brightness"}),(0,a.jsxs)("div",{className:"gpref-scale",children:[(0,a.jsx)("span",{children:"Base"}),(0,a.jsx)("span",{children:"Lighter"})]})]}),(0,a.jsxs)("div",{className:"gpref",children:[(0,a.jsxs)("div",{className:"gpref-row",children:[(0,a.jsx)("label",{className:"gpref-label",htmlFor:"ws-grid-strength",children:"Workspace grid strength"}),(0,a.jsxs)("span",{className:"gpref-val mono",children:[o,"%"]})]}),(0,a.jsx)("input",{id:"ws-grid-strength",className:"gpref-slider",type:"range",min:0,max:100,step:1,value:o,onChange:e=>c(Number.parseInt(e.target.value,10)),style:g,"aria-label":"Workspace grid strength"}),(0,a.jsxs)("div",{className:"gpref-scale",children:[(0,a.jsx)("span",{children:"Subtle"}),(0,a.jsx)("span",{children:"Strong"})]})]}),(0,a.jsxs)("div",{className:"gpref",children:[(0,a.jsxs)("div",{className:"gpref-row",children:[(0,a.jsx)("label",{className:"gpref-label",htmlFor:"frame-border-strength",children:"Workspace border strength"}),(0,a.jsxs)("span",{className:"gpref-val mono",children:[d,"%"]})]}),(0,a.jsx)("input",{id:"frame-border-strength",className:"gpref-slider",type:"range",min:0,max:100,step:1,value:d,onChange:e=>u(Number.parseInt(e.target.value,10)),style:v,"aria-label":"Workspace border strength"}),(0,a.jsxs)("div",{className:"gpref-scale",children:[(0,a.jsx)("span",{children:"Subtle"}),(0,a.jsx)("span",{children:"Strong"})]})]}),(0,a.jsxs)("div",{className:"gpref",children:[(0,a.jsxs)("div",{className:"gpref-row",children:[(0,a.jsx)("label",{className:"gpref-label",htmlFor:"frame-inner-glow-strength",children:"Workspace inner glow"}),(0,a.jsxs)("span",{className:"gpref-val mono",children:[p,"%"]})]}),(0,a.jsx)("input",{id:"frame-inner-glow-strength",className:"gpref-slider",type:"range",min:0,max:100,step:1,value:p,onChange:e=>m(Number.parseInt(e.target.value,10)),style:b,"aria-label":"Workspace inner glow"}),(0,a.jsxs)("div",{className:"gpref-scale",children:[(0,a.jsx)("span",{children:"Off"}),(0,a.jsx)("span",{children:"Strong"})]})]})]});}function sQ(){var e;let[t,n]=(0,i.useState)("models"),[l,r]=(0,i.useState)([]),[s,o]=(0,i.useState)(null),[c,d]=(0,i.useState)(!1),[u,p]=(0,i.useState)(!0),[m,h]=(0,i.useState)(),[f,g]=(0,i.useState)({}),[v,b]=(0,i.useState)(!1),[x,y]=(0,i.useState)(0);(0,i.useEffect)(()=>{let e=!1;return async function(){p(!0),h(void 0);try{let[t,n]=await Promise.all([(0,k.Dz)(),(0,k.ZC)()]);if(e)return;o(t.config),d(t.configPresent),r(n.models);}catch(t){if(e)return;h(function(e){let t="Could not load gateway settings — the local Keiko backend did not respond.";if(!(e instanceof Error))return t;let n=e.message.trim();return 0===n.length||/^HTTP \d+$/u.test(n)||"Failed to fetch"===n||"Load failed"===n||"NetworkError when attempting to fetch a resource."===n?t:n;}(t));}finally{e||p(!1);}}(),()=>{e=!0;};},[x]);let j=l.filter(nH.S_).length,w=l.length>0,S=c?w?0===j?"Gateway connected, but none of the discovered models can be used for conversation. Add a chat-capable deployment.":"Keiko can use the configured gateway models for chat and agent workflows.":"The gateway is configured, but no conversation-capable models are currently available.":"Enter the gateway base URL and API token before using chat or agent workflows.",C=c?"connected":"untested";async function I(e,t){g(n=>({...n,[e]:{status:"running",deep:t}}));try{let n=await(0,k.IN)(e,t?{includeDeepProbes:!0}:void 0);g(t=>({...t,[e]:{status:"done",report:n}}));}catch(t){g(n=>({...n,[e]:{status:"error",message:t instanceof Error&&t.message.trim().length>0?t.message:"Readiness check failed. The gateway configuration was not changed."}}));}}return(0,a.jsxs)("div",{className:"set",children:[(0,a.jsxs)("div",{className:"set-hero",children:[(0,a.jsx)(N.F.settings,{size:18}),(0,a.jsx)("span",{className:"set-title",children:"Settings"}),(0,a.jsxs)("span",{className:"set-onprem",title:"Runs inside your network",children:[(0,a.jsx)("span",{className:"dot",style:{background:"var(--accent)"}})," Self-hosted"]})]}),(0,a.jsx)("div",{className:"set-tabs",children:["models","general","security"].map(e=>(0,a.jsx)("button",{type:"button",className:"set-tab","data-on":t===e,"aria-pressed":t===e,onPointerDown:()=>n(e),onClick:()=>n(e),children:"models"===e?"Models":"general"===e?"General":"Security"},e))}),(0,a.jsxs)("div",{className:"set-body",children:["models"===t&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"set-sec-h",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"set-sec-t",children:"Model gateway"}),(0,a.jsx)("div",{className:"set-sec-d",children:"Credentials are stored locally by the Keiko loopback server; secrets are never returned to the browser."})]}),(0,a.jsxs)("button",{type:"button",className:"set-add",onClick:()=>b(!0),children:[(0,a.jsx)(N.F.plus,{size:14}),c?"Update credentials":"Connect gateway"]})]}),(0,a.jsxs)("div",{className:"ml-row",children:[(0,a.jsx)("span",{className:"ml-ico",children:(0,a.jsx)(N.F.cube,{size:16})}),(0,a.jsxs)("div",{className:"ml-info",children:[(0,a.jsxs)("div",{className:"ml-top",children:[(0,a.jsx)("span",{className:"ml-name",children:c?w?"Gateway connected":"Gateway configured":"Gateway setup required"}),(0,a.jsxs)("span",{className:"ml-type mono",children:[l.length.toString()," models"]}),(0,a.jsxs)("span",{className:"ml-type mono",children:[j.toString()," chat"]})]}),(0,a.jsx)("div",{className:"ml-url mono",children:S})]}),(0,a.jsx)("span",{className:"ml-status "+C,title:c?"gateway configured":"setup required","aria-hidden":"true"})]}),void 0!==m?(0,a.jsxs)("div",{className:"gw-error",role:"alert",children:[m,(0,a.jsx)("button",{type:"button",className:"gw-error-retry",onClick:()=>y(e=>e+1),children:"Retry"})]}):null,u?(0,a.jsx)("div",{className:"set-placeholder",role:"status",children:"Loading gateway models…"}):0===l.length?(0,a.jsx)("div",{className:"set-placeholder",role:"status",children:c?"No conversation-capable models are currently available. Review the gateway configuration or discovered model set.":"No models are configured yet. Connect the gateway to load configured model capabilities."}):(0,a.jsx)("div",{className:"set-list",children:l.map(e=>(0,a.jsx)(sX,{model:e,readiness:f[e.id],onRunReadiness:(e,t)=>{I(e,t);}},e.id))}),v?(0,a.jsx)(nr,{onCancel:()=>b(!1),preserveExisting:c,storedApiKeyHeaderName:null==s||null==(e=s.providers[0])?void 0:e.credentialHeaderName,storedModels:l}):null]}),"general"===t&&(0,a.jsx)(sG,{}),"security"===t&&(0,a.jsx)("div",{className:"set-placeholder",children:"SSO \xb7 audit log \xb7 data residency — coming soon."})]})]});}function sZ(e){return e instanceof k.hD?`${e.message} (${e.code})`:e instanceof Error?e.message:"Failed to load connectors.";}function s0(){return(0,a.jsx)("div",{className:"connector-picker-status",role:"status","aria-live":"polite",children:"Loading connectors…"});}function s1(e){let{message:t,onRetry:n}=e;return(0,a.jsxs)("div",{className:"connector-picker-error",role:"alert",children:[(0,a.jsx)("p",{children:t}),(0,a.jsx)("button",{type:"button",className:"connector-picker-retry",onClick:n,children:"Try again"})]});}function s2(e){let{onManageConnectors:t}=e;return(0,a.jsx)("div",{className:"connector-picker-empty",children:(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-primary connector-picker-create-link",onClick:t,children:"Create a connector"})});}function s4(e){let{capsules:t,capsuleSets:n,selectedKind:l,selectedId:i}=e,r=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,i);return null===r?null:(0,a.jsxs)("div",{className:"connector-picker-selected",role:"status","aria-live":"polite",children:[(0,a.jsx)("span",{"aria-hidden":"true",children:"●"}),(0,a.jsx)("span",{children:r})]});}function s3(e){let{selectedId:t,selectedLabel:n,selectedState:l,onManageConnectors:i}=e,r=void 0!==n&&n.trim().length>0?n.trim():`Capsule ${t}`;return(0,a.jsxs)("div",{className:"connector-node","data-testid":"knowledge-connector-node",children:[(0,a.jsx)("div",{className:"connector-node-icon","aria-hidden":"true",children:(0,a.jsx)(N.F.server,{size:42})}),(0,a.jsxs)("div",{className:"connector-node-copy",children:[(0,a.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";}}(l)}),(0,a.jsx)("h2",{className:"connector-node-title",title:r,children:r}),(0,a.jsx)("p",{className:"connector-node-id mono",title:t,children:t})]}),(0,a.jsx)("button",{type:"button",className:"connector-node-manage",onClick:i,children:"Manage"})]});}function s5(e){let{selectedKind:t,selectedId:n,selectedLabel:l,selectedState:r,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,x]=(0,i.useState)(!1),[y,j]=(0,i.useState)(0),w="node"===s&&"capsule"===t&&void 0!==n&&n.length>0;if((0,i.useEffect)(()=>{if(w)return;let e=!1;return async function(){f(!0),v(null),x(!1);try{let[t,n]=await Promise.allSettled([(0,ik.xr)(),(0,ik.R3)()]);if(e)return;"fulfilled"===t.status?u(t.value.capsules.filter(e=>"ready"===e.lifecycleState)):v(sZ(t.reason)),"fulfilled"===n.status?m(n.value.capsuleSets):x(!0);}catch(t){e||v(sZ(t));}finally{e||f(!1);}}(),()=>{e=!0;};},[w,y]),w)return(0,a.jsx)(s3,{selectedId:n,selectedLabel:l,selectedState:r,onManageConnectors:c});if(h)return(0,a.jsx)(s0,{});if(null!==g)return(0,a.jsx)(s1,{message:g,onRetry:()=>{j(e=>e+1);}});let k=d.length>0,N=p.length>0;if(!k&&!N)return(0,a.jsx)(s2,{onManageConnectors:c});let S=void 0!==t&&void 0!==n&&n.length>0?`${t}:${n}`:"";return(0,a.jsxs)("div",{className:"connector-picker",children:[(0,a.jsx)(s4,{capsules:d,capsuleSets:p,selectedKind:t,selectedId:n}),(0,a.jsx)("div",{className:"connector-picker-label",children:"Select a connector"}),(0,a.jsx)(nd,{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,a.jsx)("p",{className:"connector-picker-notice",role:"status",children:"Capsule sets could not be loaded."}):null,(0,a.jsx)("div",{className:"connector-picker-footer",children:(0,a.jsx)("button",{type:"button",className:"connector-picker-create-link",onClick:c,children:"Create or manage connectors"})})]});}async function s6(e,t){var n,l;let a=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),i="GET"!==a&&"HEAD"!==a,r=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(!r.ok){let e="INTERNAL",t=`HTTP ${r.status.toString()}`;try{let n=await r.json();e=n.error.code,t=n.error.message;}catch{}throw new k.hD(e,t,r.status);}return r.json();}async function s8(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return s6("/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 s7(e,t){return s6(`/api/figma/snapshots/${encodeURIComponent(e)}`,{...(void 0!==t?{signal:t}:{})});}async function s9(){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 s6(`/api/figma/snapshots${n}`,{...(void 0!==e.signal?{signal:e.signal}:{})})).snapshots;}async function oe(e,t,n){return s6(`/api/figma/snapshots/${encodeURIComponent(e)}`,{method:"PATCH",...(void 0!==n?{signal:n}:{}),body:JSON.stringify({displayName:t})});}async function ot(e,t){return s6(`/api/figma/snapshots/${encodeURIComponent(e)}`,{method:"DELETE",...(void 0!==t?{signal:t}:{})});}function on(e,t){return`/api/figma/snapshots/${encodeURIComponent(e)}/screens/${encodeURIComponent(String(t))}/image`;}async function ol(e,t,n){return s6(`/api/figma/snapshots/${encodeURIComponent(e)}/screens/${encodeURIComponent(t)}/json`,{...(void 0!==n?{signal:n}:{})});}async function oa(e,t){return s6(`/api/figma/snapshots/${encodeURIComponent(e)}/code`,{method:"POST",...(void 0!==t?{signal:t}:{}),body:JSON.stringify({})});}async function oi(){return s6("/api/figma/token",{method:"DELETE",body:JSON.stringify({})});}let or=/"(?:\\(?:["\\/bfnrt]|u[0-9a-fA-F]{4})|[^"\\])*"\s*:?|[-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?|\b(?:true|false|null)\b|[{}\[\],:]/gu;function os(e){return 0===e.length?0:"u">typeof TextEncoder?new TextEncoder().encode(e).byteLength:e.length;}function oo(e){let{text:t,className:n}=e,l=function(e){let t=[],n=0;for(let l of e.matchAll(or)){let a=l[0],i=l.index;i>n&&t.push(e.slice(n,i)),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=i+a.length;}return n<e.length&&t.push(e.slice(n)),t;}(t);return(0,a.jsx)("pre",{className:n,children:(0,a.jsx)("code",{children:l.map((e,t)=>"string"==typeof e?e:(0,a.jsx)("span",{className:`json-token-${e.kind}`,children:e.text},`${e.kind}-${t.toString()}`))})});}let oc=[];function od(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 ou(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 op(e){var t;return null!=(t=e.displayName)?t:`Snapshot ${(0,l9.Yq)(e.fetchedAt)}`;}function om(e){return void 0===e||0===e.length?"Latest":e;}function oh(e){return e.length<=16?e:`${e.slice(0,12)}…`;}function of(e){var t;return null!=(t=e.management)?t:{};}function og(e,t){return{runId:e.runId,...(void 0!==t.displayName?{displayName:t.displayName}:{}),management:of(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 ov=new Set(["FIGMA_PROXY_EGRESS_FAILED","FIGMA_PROXY_UNREACHABLE","FIGMA_PROXY_AUTH_REQUIRED","FIGMA_PROXY_BLOCKED_BY_POLICY"]),ob=new Set(["FIGMA_TLS_CA_FAILURE"]),ox=new Set(["FIGMA_NETWORK_UNREACHABLE","FIGMA_EGRESS_TIMEOUT","FIGMA_EGRESS_FAILED"]);function oy(e){return e instanceof k.hD?"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}:ov.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}:ob.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}:ox.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 oj(e){let t=oy(e);return void 0===t.status?t.detail:`${t.detail} (${t.status})`;}function ow(e,t){let n=document.elementFromPoint(e,t);return n instanceof Element&&null!==n.closest("main.workspace")&&null===n.closest(".window");}function ok(e,t){let n={payload:e,clientX:t.clientX,clientY:t.clientY};window.dispatchEvent(new CustomEvent(tJ,{detail:n}));}function oN(e,t){let n={payload:e,clientX:t.clientX,clientY:t.clientY};window.dispatchEvent(new CustomEvent(tG,{detail:n}));}function oS(e,t){let n={payload:e,clientX:t.clientX,clientY:t.clientY};window.dispatchEvent(new CustomEvent(t1,{detail:n}));}function oC(e){let{index:t,screenId:n,name:l,irSummary:r,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,a.jsx)(l0.default,{className:"figma-snapshot-screen-image",src:s,alt:`Captured preview for ${l}`,loading:"lazy",width:72,height:54,unoptimized:!0}):(0,a.jsxs)("div",{className:"figma-snapshot-screen-image figma-snapshot-screen-placeholder","aria-label":`Structural data only for ${l}`,role:"img",children:[(0,a.jsx)(N.F.layers,{className:"figma-snapshot-screen-frame-icon","aria-hidden":"true"}),(0,a.jsx)("span",{className:"figma-snapshot-screen-placeholder-label",children:"IR"})]});return(0,a.jsxs)("article",{className:"figma-snapshot-screen-card","aria-label":`Screen ${String(t+1)}: ${l}`,children:[void 0!==d?(0,a.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(tV,JSON.stringify(p)),e.dataTransfer.setData("text/plain",l));},onDragEnd:e=>{g&&ow(e.clientX,e.clientY)&&ok(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&&ow(e.clientX,e.clientY)&&(e.preventDefault(),f.current=!0,ok(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&&ow(e.clientX,e.clientY)&&(e.preventDefault(),f.current=!0,ok(p,e));};window.addEventListener("mousemove",l),window.addEventListener("mouseup",a);},children:b}):b,(0,a.jsxs)("div",{className:"figma-snapshot-screen-meta",children:[(0,a.jsx)("h3",{className:"figma-snapshot-screen-name",title:l,children:l}),(0,a.jsx)("p",{className:"figma-snapshot-screen-summary",children:r}),(0,a.jsx)("p",{className:"figma-snapshot-screen-size",children:void 0!==o?(0,l9.z3)(o):`Structural IR only${void 0!==c?` (${c})`:""}`}),(0,a.jsx)("p",{className:"figma-snapshot-screen-id",children:n}),void 0!==d?(0,a.jsx)("div",{className:"figma-snapshot-screen-actions",children:(0,a.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 oI(e){let{name:t,screenId:n,irSummary:l,imageSrc:r,imageByteLength:s,structuralReason:o,snapshotRunId:c,capturedAt:d,imageDragPayload:u}=e,p=(0,i.useRef)(null),m=(0,i.useRef)(!1),h=void 0!==r&&void 0!==u,f=void 0!==r?(0,a.jsx)(l0.default,{className:"figma-view-preview-image",src:r,alt:`Captured preview for ${t}`,loading:"eager",width:360,height:240,draggable:!1,unoptimized:!0}):(0,a.jsxs)("div",{className:"figma-view-preview-image figma-view-preview-placeholder","aria-label":`Structural data only for ${t}`,role:"img",children:[(0,a.jsx)(N.F.layers,{className:"figma-view-preview-icon","aria-hidden":"true"}),(0,a.jsx)("span",{children:"Structural IR"})]});return(0,a.jsxs)("article",{className:"figma-view-source-card","aria-label":`Figma view source: ${t}`,children:[h?(0,a.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(t0,JSON.stringify(u)),e.dataTransfer.setData("text/plain",`${u.name}.png`));},onDragEnd:e=>{h&&ow(e.clientX,e.clientY)&&oS(u,e);},onKeyDown:e=>{if(!h||"Enter"!==e.key&&" "!==e.key)return;e.preventDefault();let t=e.currentTarget.getBoundingClientRect();oS(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&&ow(e.clientX,e.clientY)&&(e.preventDefault(),oS(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&&ow(e.clientX,e.clientY)&&(e.preventDefault(),oS(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,a.jsx)("div",{className:"figma-view-preview",children:f}),(0,a.jsxs)("div",{className:"figma-view-source-meta",children:[(0,a.jsx)("p",{className:"figma-view-source-kicker",children:"QI view source"}),(0,a.jsx)("h2",{className:"figma-view-source-title",title:t,children:t}),(0,a.jsx)("p",{className:"figma-view-source-summary",children:l}),(0,a.jsxs)("dl",{className:"figma-view-source-facts",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Screen"}),(0,a.jsx)("dd",{children:n})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Snapshot"}),(0,a.jsx)("dd",{children:c})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Captured"}),(0,a.jsx)("dd",{children:d})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Preview"}),(0,a.jsx)("dd",{children:void 0!==s?(0,l9.z3)(s):`Structural IR${void 0!==o?` (${o})`:""}`})]})]})]})]});}function oR(e){var t,n,l,r,s;let o,c,d,u,{sourceWindowId:p,snapshotRunId:m,selectedScreenIds:h=oc,selectedScreenName:f,openScreenSource:g,updateCfg:v,triggerImpl:b=s8,loadImpl:x=s7,listImpl:y=s9,updateMetadataImpl:j=oe,deleteImpl:w=ot,loadScreenJsonImpl:S=ol,codegenImpl:C=oa,revokeImpl:I=oi}=e,R=(0,i.useId)(),$=(0,i.useId)(),E=(0,i.useId)(),A=(0,i.useId)(),[F,T]=(0,i.useState)(""),[D,M]=(0,i.useState)("idle"),[P,q]=(0,i.useState)(null),[L,z]=(0,i.useState)(null),[O,K]=(0,i.useState)(null),[W,B]=(0,i.useState)(null),[U,_]=(0,i.useState)(0),[V,J]=(0,i.useState)("recent"),[H,Y]=(0,i.useState)([]),[X,G]=(0,i.useState)([]),[Q,Z]=(0,i.useState)(!1),[ee,et]=(0,i.useState)(!1),[en,el]=(0,i.useState)(null),[ea,ei]=(0,i.useState)(null),[er,es]=(0,i.useState)(null),[eo,ec]=(0,i.useState)(""),[ed,eu]=(0,i.useState)(null),[ep,em]=(0,i.useState)(null),[eh,ef]=(0,i.useState)(null),[eg,ev]=(0,i.useState)(null),[eb,ex]=(0,i.useState)(!1),[ey,ej]=(0,i.useState)(!1),ew=(0,i.useRef)(null),ek=(0,i.useRef)(null),eN=(0,i.useRef)(null),eS=(0,i.useRef)(null),eC=(0,i.useRef)(null),eI=(0,i.useRef)(null),eR=(0,i.useRef)(null),e$=(0,i.useRef)(null),eE=(0,i.useRef)(!1),eA=(0,i.useCallback)(()=>{ej(!0);},[]),[eF,eT]=(0,i.useState)("idle"),[eD,eM]=(0,i.useState)(null),[eP,eq]=(0,i.useState)(null),[eL,ez]=(0,i.useState)("idle"),[eO,eK]=(0,i.useState)(null),[eW,eB]=(0,i.useState)(null),[eU,e_]=(0,i.useState)(null),[eV,eJ]=(0,i.useState)(!1),[eH,eY]=(0,i.useState)(null),[eX,eG]=(0,i.useState)(null),eQ=(0,i.useRef)(null),eZ=(0,i.useRef)(null),[e0,e1]=(0,i.useState)(24),e2=h.join("\0"),e4=od(F),e3=function(e){let t=e.trim();if(0===t.length||od(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!==P?{fileKey:P.fileKey,nodeId:P.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 i=t.searchParams.get("node-id");if(null===i||0===i.length)return null;return{fileKey:a,nodeId:i};}catch{return null;}}(F),[F,P]),e6=null==e5?void 0:e5.fileKey,e8=null==e5?void 0:e5.nodeId,e7="building"===D,e9="loading"===D,te=e7||e9,tt=e7&&null!==W?(c=Math.floor((o=Math.max(0,Math.floor(U/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,tn=(0,i.useMemo)(()=>new Set(h),[h]),tl=h.length>0,ta=tl&&void 0!==m&&m.length>0,ti=(0,i.useMemo)(()=>{var e;if(null===P)return[];let t=new Set(P.screens.map(e=>e.screenId)),n=[...P.screens.map((e,t)=>({kind:"rendered",screen:e,imageIndex:t})),...(null!=(e=P.structuralScreens)?e:[]).filter(e=>!t.has(e.screenId)).map(e=>({kind:"structural",screen:e}))];return tl?n.filter(e=>tn.has(e.screen.screenId)):n;},[tl,tn,P]),tr=1===h.length?h[0]:void 0,ts=(0,i.useMemo)(()=>null===eO?"":JSON.stringify(eO,null,2),[eO]),to=(0,i.useMemo)(()=>os(ts),[ts]),tc=(null!=(t=null==P?void 0:P.screens.length)?t:0)+(null!=(n=null==P||null==(r=P.structuralScreens)?void 0:r.length)?n:0),td=null===P?{}:of(P);(0,i.useEffect)(()=>{var e;ey&&"error"===D&&(null==(e=ew.current)||e.focus());},[ey,D]),(0,i.useEffect)(()=>{var e;eV&&(null==(e=eQ.current)||e.focus());},[eV]),(0,i.useEffect)(()=>{if(!e7||null===W)return;_(Date.now()-W);let e=window.setInterval(()=>{_(Date.now()-W);},1e3);return()=>{window.clearInterval(e);};},[e7,W]),(0,i.useEffect)(()=>()=>{var e,t,n,l,a;null==(e=ek.current)||e.abort(),null==(t=eN.current)||t.abort(),null==(n=eS.current)||n.abort(),null==(l=eC.current)||l.abort(),null==(a=eI.current)||a.abort();},[]),(0,i.useEffect)(()=>{null===e5&&"board"===V&&J("recent");},[e5,V]);let tu=(0,i.useCallback)(()=>{var e;null==(e=eC.current)||e.abort();let t=new AbortController();if(eC.current=t,et(!0),ei(null),y({limit:12,signal:t.signal}).then(e=>{G(e);}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name||(G([]),ei(oj(e)));}).finally(()=>{eC.current===t&&et(!1);}),void 0===e6||void 0===e8){Y([]),el(null),Z(!1);return;}Z(!0),el(null),y({fileKey:e6,nodeId:e8,limit:12,signal:t.signal}).then(e=>{Y(e);}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name||(Y([]),el(oj(e)));}).finally(()=>{eC.current===t&&Z(!1);});},[e6,e8,y]);(0,i.useEffect)(()=>{tu();},[tu,null==P?void 0:P.runId]);let tp=(0,i.useCallback)(e=>{var t;if(0===e.length||te)return;null==(t=ek.current)||t.abort();let n=new AbortController();ek.current=n,M("loading"),z(null),K(null),eT("idle"),eM(null),eq(null),ez("idle"),eK(null),eB(null),e_(null),x(e,n.signal).then(e=>{q(e),T(ou(e)),v({snapshotRunId:e.runId}),M("done");}).catch(t=>{t instanceof DOMException&&"AbortError"===t.name||(t instanceof k.hD&&"FIGMA_SNAPSHOT_NOT_FOUND"===t.code?(m===e&&v({snapshotRunId:void 0}),z({...oy(t),detail:m===e?`${t.message} The stored run ID has been cleared.`:t.message})):z(oy(t)),M("error"));});},[te,x,m,v]);(0,i.useEffect)(()=>{ta&&void 0!==m&&0!==m.length&&null===P&&"idle"===D&&tp(m);},[D,ta,tp,m,P]);let tm=(0,i.useCallback)(async(e,t)=>{var n,l,a;null==(n=ek.current)||n.abort(),null==(l=eN.current)||l.abort(),null==(a=eS.current)||a.abort(),eN.current=null,eS.current=null;let i=new AbortController();ek.current=i,eR.current={link:e,isResnapshot:t},M("building"),z(null),K(null),B(Date.now()),_(0),eT("idle"),eM(null),ez("idle"),eK(null),eB(null),e_(null);try{let n=await b(e,{acknowledgeReadOnly:eb,isResnapshot:t,signal:i.signal});q(n),T(ou(n)),v({snapshotRunId:n.runId}),M("done"),B(null),_(0),eR.current=null;}catch(n){if(n instanceof DOMException&&"AbortError"===n.name)return;if(B(null),_(0),n instanceof k.hD&&"FIGMA_CONSENT_REQUIRED"===n.code){let e=oy(n);z({...e,detail:`${e.detail} Tick the acknowledgement checkbox below, then snapshot again.`}),eA();}else n instanceof k.hD&&"FIGMA_BUILD_TIMEOUT"===n.code?(K({link:e,isResnapshot:t}),z({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."})):z(oy(n));M("error"),eR.current=null;}},[b,v,eb,eA]),th=(0,i.useCallback)(e=>{if(e.preventDefault(),e4&&!te){if(!eb){z({title:"Figma snapshot failed",detail:"Tick the read-only acknowledgement checkbox below, then snapshot again."}),M("error"),eA();return;}tm(F,!1);}},[F,te,eb,e4,tm,eA]),tf=(0,i.useCallback)(()=>{te||null!==P&&tm(ou(P),!0);},[te,tm,P]),tg=(0,i.useCallback)(()=>{var e;null==(e=ek.current)||e.abort(),ek.current=null,B(null),_(0),null!==eR.current&&K(eR.current),eR.current=null,M("idle"),z(null);},[]),tv=(0,i.useCallback)(()=>{te||null===O||tm(O.link,O.isResnapshot);},[te,O,tm]),tb=(0,i.useCallback)(()=>{var e;let t=null!=(e=null==P?void 0:P.runId)?e:m;if(void 0===t||0===t.length||"generating"===eF)return;let n=new AbortController();eN.current=n,eT("generating"),eq(null),C(t,n.signal).then(e=>{eM(e),eT("done");}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name?eT("idle"):(eq(oj(e)),eT("error"));}).finally(()=>{eN.current===n&&(eN.current=null);});},[C,eF,m,P]),tx=(0,i.useCallback)(()=>{var e,t;let n=null!=(e=null==P?void 0:P.runId)?e:m;if(void 0===n||0===n.length||void 0===tr||"loading"===eL)return;null==(t=eS.current)||t.abort();let l=new AbortController();eS.current=l,ez("loading"),eB(null),e_(null),S(n,tr,l.signal).then(e=>{eK(e),ez("done");}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name?ez("idle"):(eK(null),eB(oj(e)),ez("error"));}).finally(()=>{eS.current===l&&(eS.current=null);});},[tr,S,eL,m,null==P?void 0:P.runId]),ty=(0,i.useCallback)(()=>{if(0!==ts.length){if(void 0===navigator.clipboard)return void e_("Clipboard unavailable");navigator.clipboard.writeText(ts).then(()=>{e_("Copied");}).catch(()=>{e_("Copy failed");});}},[ts]),tj=(0,i.useMemo)(()=>{var e,t,n,l,a;let i=null!=(e=null!=(t=null==eO?void 0:eO.runId)?t:null==P?void 0:P.runId)?e:m,r=null!=(n=null==eO?void 0:eO.screen.screenId)?n:tr,s=null!=(l=null!=(a=null==eO?void 0:eO.screen.name)?a:f)?l:r;return void 0===i||0===i.length||void 0===r||0===r.length||void 0===s||0===s.length?null:{snapshotRunId:i,screenId:r,name:s,...(void 0!==p?{sourceWindowId:p}:{})};},[tr,null==eO?void 0:eO.runId,null==eO?void 0:eO.screen.name,null==eO?void 0:eO.screen.screenId,f,m,p,null==P?void 0:P.runId]),tw=(0,i.useCallback)(e=>{null!==tj&&(e.dataTransfer.effectAllowed="copyMove",e.dataTransfer.setData(tX,JSON.stringify(tj)),e.dataTransfer.setData("text/plain",`${tj.name}.json`));},[tj]),tk=(0,i.useCallback)(e=>{null!==tj&&ow(e.clientX,e.clientY)&&oN(tj,e);},[tj]),tN=(0,i.useCallback)(e=>{if(null===tj||"Enter"!==e.key&&" "!==e.key)return;e.preventDefault();let t=e.currentTarget.getBoundingClientRect();oN(tj,{clientX:t.right+24,clientY:t.top+t.height/2});},[tj]),tS=(0,i.useCallback)(e=>{null!==tj&&0===e.button&&(eE.current=!1,e$.current={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY},e.currentTarget.setPointerCapture(e.pointerId));},[tj]),tC=(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&&(eE.current=!0),n>=6&&null!==tj&&ow(e.clientX,e.clientY)&&(e.preventDefault(),oN(tj,e));},[tj]),tR=(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),eE.current){eE.current=!1;return;}Math.hypot(e.clientX-t,e.clientY-n)>=6&&ow(e.clientX,e.clientY)&&(e.preventDefault(),oN(tj,e));};window.addEventListener("mousemove",l),window.addEventListener("mouseup",a);},[tj]),tE=(0,i.useCallback)(()=>{var e;null==(e=eN.current)||e.abort(),eN.current=null,eT("idle"),eq(null);},[]),tA=(0,i.useCallback)(()=>{void 0===m||0===m.length||te||tp(m);},[te,tp,m]);(0,i.useEffect)(()=>{e1(24);},[e2,null==P?void 0:P.runId]),(0,i.useEffect)(()=>{var e;null==(e=eS.current)||e.abort(),eS.current=null,ez("idle"),eK(null),eB(null),e_(null);},[e2,m]);let tF=(0,i.useCallback)(()=>{eJ(!1),eG(null),eY(null),I().then(e=>{eY(e.message),requestAnimationFrame(()=>{var e;return null==(e=eZ.current)?void 0:e.focus();});}).catch(e=>{eG(oj(e)),requestAnimationFrame(()=>{var e;return null==(e=eZ.current)?void 0:e.focus();});});},[I]),tT=(0,i.useCallback)(()=>{eJ(!1),requestAnimationFrame(()=>{var e;return null==(e=eZ.current)?void 0:e.focus();});},[]),tD=(0,i.useCallback)(e=>{var t;es(e.runId),ec(null!=(t=e.displayName)?t:""),eu(null),em(null),ev(null);},[]),tM=(0,i.useCallback)(()=>{es(null),ec("");},[]),tP=(0,i.useCallback)(e=>{var t;if(null!==eh)return;null==(t=eI.current)||t.abort();let n=new AbortController();eI.current=n,ef(e),ev(null);let l=eo.trim();j(e,0===l.length?null:l,n.signal).then(t=>{(null==P?void 0:P.runId)===e&&q(t),Y(n=>n.map(n=>n.runId===e?og(n,t):n)),G(n=>n.map(n=>n.runId===e?og(n,t):n)),es(null),ec("");}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name||ev(oj(e));}).finally(()=>{eI.current===n&&(eI.current=null),ef(null);});},[eo,eh,null==P?void 0:P.runId,j]),tq=(0,i.useCallback)(e=>{eu(t=>t===e?null:e),es(null),em(null),ev(null);},[]),tL=(0,i.useCallback)(e=>{em(e),es(null),eu(null),ev(null);},[]),tz=(0,i.useCallback)(e=>{var t;if(null!==eh)return;null==(t=eI.current)||t.abort();let n=new AbortController();eI.current=n,ef(e),ev(null),w(e,n.signal).then(t=>{Y(t=>t.filter(t=>t.runId!==e)),G(t=>t.filter(t=>t.runId!==e)),em(null),es(null),eu(null),(null==P?void 0:P.runId)===e&&(q(null),M("idle"),eT("idle"),eM(null),ez("idle"),eK(null)),((null==P?void 0:P.runId)===e||m===e)&&v({snapshotRunId:void 0});}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name||ev(oj(e));}).finally(()=>{eI.current===n&&(eI.current=null),ef(null);});},[w,eh,m,null==P?void 0:P.runId,v]),tO=void 0!==m&&m.length>0&&null===P&&("idle"===D||"loading"===D||"error"===D),tK=(e,t,n,l,i,r)=>t?(0,a.jsx)("p",{className:"figma-snapshot-dashboard-status",children:"Loading snapshots…"}):null!==n?(0,a.jsx)("p",{className:"figma-snapshot-dashboard-status figma-snapshot-dashboard-status-error",children:n}):0===e.length?(0,a.jsxs)("div",{className:"figma-snapshot-dashboard-empty",children:[(0,a.jsx)("p",{className:"figma-snapshot-dashboard-empty-title",children:l}),(0,a.jsx)("p",{className:"figma-snapshot-dashboard-empty-detail",children:i})]}):(0,a.jsx)("div",{className:"figma-snapshot-dashboard-list",role:"list",children:e.map(e=>{var t;let n=(null==P?void 0:P.runId)===e.runId,l=op(e),i=of(e),s=eh===e.runId,o=ed===e.runId,c=er===e.runId,d=ep===e.runId;return(0,a.jsxs)("article",{className:"figma-snapshot-dashboard-item",role:"listitem","aria-current":n?"true":void 0,"aria-busy":e9&&m===e.runId?"true":void 0,children:[(0,a.jsxs)("div",{className:"figma-snapshot-dashboard-item-head",children:[(0,a.jsxs)("div",{className:"figma-snapshot-dashboard-item-title-block",children:[(0,a.jsx)("h3",{className:"figma-snapshot-dashboard-item-title",title:l,children:l}),(0,a.jsx)("span",{className:"figma-snapshot-dashboard-item-date",children:(0,l9.Yq)(e.fetchedAt)})]}),n&&(0,a.jsx)("span",{className:"figma-snapshot-dashboard-item-badge",children:"Current"}),(0,a.jsxs)("div",{className:"figma-snapshot-dashboard-item-actions",children:[(0,a.jsx)("button",{type:"button",className:"figma-snapshot-dashboard-load",onClick:()=>{tp(e.runId);},disabled:te,"aria-disabled":te?"true":void 0,"aria-label":`Load snapshot ${l}`,children:"Load"}),(0,a.jsx)("button",{type:"button",className:"figma-snapshot-dashboard-icon-btn",onClick:()=>tD(e),disabled:s,"aria-label":`Rename snapshot ${l}`,title:"Rename",children:(0,a.jsx)(N.F.edit,{"aria-hidden":"true"})}),(0,a.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,a.jsx)(N.F.info,{"aria-hidden":"true"})}),(0,a.jsx)("button",{type:"button",className:"figma-snapshot-dashboard-icon-btn figma-snapshot-dashboard-icon-btn-danger",onClick:()=>tL(e.runId),disabled:s,"aria-label":`Delete snapshot ${l}`,title:"Delete",children:(0,a.jsx)(N.F.trash,{"aria-hidden":"true"})})]})]}),(0,a.jsx)("p",{className:"figma-snapshot-dashboard-item-hint",children:e.reductionHint}),(0,a.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"]}),r&&(0,a.jsxs)("p",{className:"figma-snapshot-dashboard-item-scope",children:[e.fileKey," \xb7 ",e.nodeId]}),c?(0,a.jsxs)("form",{className:"figma-snapshot-dashboard-rename",onSubmit:t=>{t.preventDefault(),tP(e.runId);},children:[(0,a.jsx)("input",{type:"text",className:"figma-snapshot-dashboard-rename-input",value:eo,onChange:e=>ec(e.target.value),maxLength:120,disabled:s,"aria-label":`Snapshot name for ${l}`,placeholder:"Snapshot name"}),(0,a.jsx)("button",{type:"submit",className:"figma-snapshot-dashboard-rename-save",disabled:s,"aria-busy":s,children:"Save"}),(0,a.jsx)("button",{type:"button",className:"figma-snapshot-dashboard-rename-cancel",onClick:tM,disabled:s,children:"Cancel"})]}):null,d?(0,a.jsxs)("div",{className:"figma-snapshot-dashboard-delete-confirm",children:[(0,a.jsx)("span",{children:"Delete this snapshot?"}),(0,a.jsx)("button",{type:"button",className:"figma-snapshot-dashboard-delete-confirm-btn",onClick:()=>tz(e.runId),disabled:s,"aria-busy":s,children:"Delete"}),(0,a.jsx)("button",{type:"button",className:"figma-snapshot-dashboard-delete-cancel-btn",onClick:()=>em(null),disabled:s,children:"Cancel"})]}):null,o?(0,a.jsxs)("dl",{className:"figma-snapshot-dashboard-details",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Run"}),(0,a.jsx)("dd",{children:e.runId})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Version"}),(0,a.jsx)("dd",{children:om(e.version)})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Integrity"}),(0,a.jsx)("dd",{title:e.integrityHash,children:oh(e.integrityHash)})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Structural"}),(0,a.jsx)("dd",{children:(null!=(t=e.structuralOnlyCount)?t:0).toString()})]}),void 0!==i.updatedAt?(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Name updated"}),(0,a.jsx)("dd",{children:(0,l9.Yq)(i.updatedAt)})]}):null]}):null]},e.runId);})});if(ta){let e=null!=f?f:h.join(", "),t=void 0!==tr&&(null!=(s=null==P?void 0:P.runId)?s:m)!==void 0&&"loading"!==eL;return(0,a.jsxs)("section",{className:"figma-snapshot-window figma-view-window","aria-label":`Figma view source ${e}`,children:[(0,a.jsxs)("div",{className:"figma-view-source-header",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"figma-view-source-eyebrow",children:"Figma view"}),(0,a.jsx)("h1",{className:"figma-view-source-heading",title:e,children:e})]}),(0,a.jsxs)("div",{className:"figma-view-source-actions",children:[(0,a.jsx)("span",{className:"figma-view-source-badge",children:"QI source"}),(0,a.jsx)("button",{type:"button",className:"figma-view-json-btn",onClick:tx,disabled:!t,"aria-disabled":t?void 0:"true","aria-busy":"loading"===eL?"true":void 0,children:"loading"===eL?"Loading JSON…":"Inspect JSON"})]})]}),(0,a.jsxs)("div",{id:$,role:"status","aria-live":"polite","aria-atomic":"true",className:"figma-snapshot-status",children:[e9&&(0,a.jsx)("p",{className:"figma-snapshot-progress",children:"Loading view preview…"}),"error"===D&&null!==L&&(0,a.jsx)("p",{className:"figma-snapshot-error",children:L.detail}),"done"===D&&null!==P&&(0,a.jsxs)("p",{className:"sr-only",children:["Figma view loaded — ",e,"."]})]}),null===P?(0,a.jsxs)("div",{className:"figma-view-source-empty",children:[(0,a.jsx)("p",{className:"figma-view-source-empty-title",children:e9?"Loading the selected view…":"Selected view preview not loaded."}),!e9&&(0,a.jsx)("button",{type:"button",className:"figma-snapshot-load-btn",onClick:tA,children:"Load view"})]}):ti.length>0?ti.map(e=>{let t="rendered"===e.kind?on(P.runId,e.imageIndex):void 0,n=void 0===t?void 0:{snapshotRunId:P.runId,screenId:e.screen.screenId,name:e.screen.name,imageSrc:t,...(void 0!==p?{sourceWindowId:p}:{})};return(0,a.jsx)(oI,{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:P.runId,capturedAt:(0,l9.Yq)(P.fetchedAt),imageDragPayload:n},e.screen.screenId);}):(0,a.jsx)("div",{className:"lk-empty",children:(0,a.jsx)("p",{className:"lk-empty-body",children:"The selected screen is not present in this stored snapshot."})}),"error"===eL&&null!==eW?(0,a.jsx)("p",{className:"figma-snapshot-error",role:"alert",children:eW}):null,"done"===eL&&null!==eO?(0,a.jsxs)("section",{className:"figma-view-json-inspector","aria-label":`Scoped JSON for ${eO.screen.name}`,children:[(0,a.jsxs)("div",{className:"figma-view-json-inspector-header",children:[(0,a.jsxs)("div",{className:"figma-view-json-drag-surface",role:"button",tabIndex:null!==tj?0:-1,draggable:!1,onDragStart:tw,onDragEnd:tk,onKeyDown:tN,onPointerDown:tS,onPointerMove:tC,onPointerUp:tI,onPointerCancel:tR,onMouseDown:t$,"aria-label":`Create a standalone JSON source for ${eO.screen.name}`,"aria-disabled":null===tj?"true":void 0,title:`Drag JSON for ${eO.screen.name} to the workspace`,children:[(0,a.jsx)("p",{className:"figma-view-json-kicker",children:"Stored Screen-IR JSON"}),(0,a.jsx)("h2",{className:"figma-view-json-title",children:eO.screen.screenId}),(0,a.jsxs)("p",{className:"figma-view-json-meta",children:[eO.screen.kind," \xb7 ",(0,l9.z3)(to)," \xb7"," ",eO.relatedLinks.length.toString()," related link",1!==eO.relatedLinks.length?"s":""]})]}),(0,a.jsx)("button",{type:"button",className:"figma-view-json-copy-btn",onClick:ty,children:"Copy JSON"})]}),null!==eU?(0,a.jsx)("p",{className:"figma-view-json-copy-status",role:"status",children:eU}):null,(0,a.jsx)(oo,{text:ts,className:"figma-view-json-code"})]}):null]});}return(0,a.jsxs)("section",{className:"figma-snapshot-window","aria-label":"Figma Snapshot",children:[(0,a.jsxs)("form",{className:"figma-snapshot-form",onSubmit:th,noValidate:!0,children:[(0,a.jsx)("label",{className:"figma-snapshot-label",htmlFor:R,children:"Board link"}),(0,a.jsxs)("div",{className:"figma-snapshot-input-row",children:[(0,a.jsx)("input",{id:R,type:"url",className:"figma-snapshot-input",placeholder:"https://www.figma.com/design/…?node-id=…",value:F,onChange:e=>{T(e.target.value),null!==L&&z(null),"error"===D&&M("idle"),null!==O&&K(null),ey&&ej(!1);},"aria-describedby":null!==e3?`${E} ${$}`:$,"aria-invalid":null!==e3?"true":void 0,readOnly:te,autoComplete:"off",spellCheck:!1}),(0,a.jsx)("button",{type:"submit",className:"figma-snapshot-trigger-btn",disabled:!e4&&!te,"aria-disabled":!e4||te?"true":void 0,"aria-busy":e7,children:e7?"Building…":"Snapshot"})]}),null!==e3&&(0,a.jsx)("p",{id:E,className:"figma-snapshot-link-error",role:"alert",children:e3}),(0,a.jsxs)("label",{className:"figma-snapshot-consent",children:[(0,a.jsx)("input",{type:"checkbox",className:"figma-snapshot-consent-checkbox",ref:ew,checked:eb,"aria-invalid":ey?"true":void 0,onChange:e=>{ex(e.target.checked),null!==L&&z(null),"error"===D&&M("idle"),ej(!1);},disabled:e7}),(0,a.jsxs)("span",{children:["I acknowledge the configured Figma PAT is read-only and least-privilege (",(0,a.jsx)("code",{children:"file_content:read"}),")."," ",(0,a.jsx)("span",{className:"figma-snapshot-consent-required",children:"Required before the first snapshot of a board."})]})]}),(0,a.jsx)("p",{className:"figma-snapshot-hint",children:"Paste a Figma board link with a node-id param (section or frame anchor). The access token is resolved server-side — it never reaches this page."})]}),"error"===D&&null!==L&&!0===L.assertive&&(0,a.jsxs)("div",{className:"figma-snapshot-error-card",role:"alert","aria-labelledby":`${$}-error-title`,children:[(0,a.jsx)("p",{id:`${$}-error-title`,className:"figma-snapshot-error-title",children:L.title}),(0,a.jsx)("p",{className:"figma-snapshot-error-detail",children:L.detail}),void 0!==L.status&&(0,a.jsx)("p",{className:"figma-snapshot-error-status",children:L.status}),void 0!==L.remediation&&(0,a.jsx)("p",{className:"figma-snapshot-error-remediation",children:L.remediation})]}),(0,a.jsxs)("div",{id:$,role:"status","aria-live":"polite","aria-atomic":"true",className:"figma-snapshot-status",children:[e7&&(0,a.jsxs)("p",{className:"figma-snapshot-progress",children:["Building snapshot — fetching screens from Figma…"," ",null!==tt?`${tt} elapsed.`:""," Large boards can take several minutes."]}),e9&&(0,a.jsx)("p",{className:"figma-snapshot-progress",children:"Loading stored snapshot…"}),"done"===D&&null!==P&&(0,a.jsxs)("p",{className:"sr-only",children:["Snapshot complete — ",P.reductionHint,"."]}),"done"===eF&&null!==eD&&(0,a.jsxs)("p",{className:"sr-only",children:["Code generated — ",String(eD.fileCount)," file",1!==eD.fileCount?"s":""," ready for review."]}),"idle"===D&&(0,a.jsx)("p",{className:"sr-only","aria-live":"polite"}),"error"===D&&null!==L&&!0!==L.assertive&&(0,a.jsx)("p",{className:"figma-snapshot-error",children:L.detail})]}),e7&&(0,a.jsxs)("div",{className:"figma-snapshot-cancel-row",children:[(0,a.jsx)("button",{type:"button",className:"figma-snapshot-cancel-btn",onClick:tg,children:"Cancel"}),(0,a.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!==O&&!te&&(0,a.jsxs)("div",{className:"figma-snapshot-stored-notice",children:[(0,a.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,a.jsx)("button",{type:"button",className:"figma-snapshot-load-btn",onClick:tv,children:"Reconnect build"})]}),"idle"===D&&null===P&&null===O&&!tO&&(0,a.jsxs)("div",{className:"figma-snapshot-empty",children:[(0,a.jsx)("p",{className:"figma-snapshot-empty-title",children:"Capture screens from a Figma board"}),(0,a.jsxs)("ol",{className:"figma-snapshot-empty-steps",children:[(0,a.jsx)("li",{children:"In Figma, select the frame or section you want to capture."}),(0,a.jsx)("li",{children:"Copy its link (Copy link to selection) — it contains the node-id."}),(0,a.jsx)("li",{children:"Paste it above, acknowledge the read-only scope, then take the snapshot."})]}),(0,a.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."})]}),tO&&(0,a.jsxs)("div",{className:"figma-snapshot-stored-notice",children:[(0,a.jsx)("p",{className:"figma-snapshot-stored-text",children:"A stored snapshot is available."}),(0,a.jsx)("button",{type:"button",className:"figma-snapshot-load-btn",onClick:tA,"aria-disabled":e9?"true":void 0,"aria-busy":e9,children:e9?"Loading…":"Load snapshot"})]}),(0,a.jsxs)("section",{className:"figma-snapshot-dashboard","aria-label":"Snapshot dashboard",children:[(0,a.jsxs)("div",{className:"figma-snapshot-dashboard-header",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"figma-snapshot-dashboard-eyebrow",children:"Snapshot dashboard"}),(0,a.jsx)("h2",{className:"figma-snapshot-dashboard-title",children:"Stored snapshots"})]}),(0,a.jsx)("button",{type:"button",className:"figma-snapshot-dashboard-refresh",onClick:tu,children:"Refresh"})]}),(0,a.jsxs)("div",{className:"figma-snapshot-dashboard-tabs",role:"tablist","aria-label":"Snapshot views",children:[(0,a.jsx)("button",{type:"button",className:"figma-snapshot-dashboard-tab",role:"tab","aria-selected":"board"===V,"aria-controls":`${A}-board-panel`,id:`${A}-board-tab`,onClick:()=>{null!==e5&&J("board");},disabled:null===e5,children:"This board"}),(0,a.jsx)("button",{type:"button",className:"figma-snapshot-dashboard-tab",role:"tab","aria-selected":"recent"===V,"aria-controls":`${A}-recent-panel`,id:`${A}-recent-tab`,onClick:()=>{J("recent");},children:"Recent"})]}),null!==eg?(0,a.jsx)("p",{className:"figma-snapshot-dashboard-status figma-snapshot-dashboard-status-error",role:"alert",children:eg}):null,"board"===V?(0,a.jsx)("div",{id:`${A}-board-panel`,className:"figma-snapshot-dashboard-panel",role:"tabpanel","aria-labelledby":`${A}-board-tab`,children:null===e5?tK([],!1,null,"No board selected yet","Paste a valid Figma board link or load a stored snapshot to see this board's history.",!1):tK(H,Q,en,"No snapshots stored for this board","Take the first snapshot for this board to make it available here.",!1)}):(0,a.jsx)("div",{id:`${A}-recent-panel`,className:"figma-snapshot-dashboard-panel",role:"tabpanel","aria-labelledby":`${A}-recent-tab`,children:tK(X,ee,ea,"No snapshots stored yet","Stored Figma snapshots will appear here once the first board capture completes.",!0)})]}),null!==P&&(0,a.jsxs)("div",{className:"figma-snapshot-result",children:[(0,a.jsxs)("div",{className:"figma-snapshot-reduction",children:[(0,a.jsxs)("div",{className:"figma-snapshot-result-head",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("h2",{className:"figma-snapshot-result-title",title:op(P),children:op(P)}),(0,a.jsx)("p",{className:"figma-snapshot-result-run",children:P.runId})]}),(0,a.jsx)("span",{className:"figma-snapshot-result-hash",title:P.integrityHash,children:oh(P.integrityHash)})]}),(0,a.jsx)("p",{className:"figma-snapshot-reduction-hint",children:P.reductionHint}),(0,a.jsxs)("p",{className:"figma-snapshot-captured-at",children:["Captured ",(0,l9.Yq)(P.fetchedAt)]}),(0,a.jsxs)("dl",{className:"figma-snapshot-result-metadata",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"File"}),(0,a.jsx)("dd",{children:P.fileKey})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Node"}),(0,a.jsx)("dd",{children:P.nodeId})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Version"}),(0,a.jsx)("dd",{children:om(P.version)})]}),void 0!==td.updatedAt?(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Name updated"}),(0,a.jsx)("dd",{children:(0,l9.Yq)(td.updatedAt)})]}):null]}),tl&&(0,a.jsxs)("p",{className:"figma-snapshot-scope-note",children:["QI source scope: ",null!=f?f:h.join(", ")]}),P.skippedCount>0&&(0,a.jsxs)("p",{className:"figma-snapshot-skipped-notice",children:[String(P.skippedCount)," screen",1!==P.skippedCount?"s":""," could not be rendered and were skipped."]})]}),(0,a.jsx)("button",{type:"button",className:"figma-snapshot-resnapshot-btn",onClick:tf,"aria-disabled":te?"true":void 0,"aria-busy":e7,"aria-label":"Re-snapshot this board",children:e7?"Building…":"Re-snapshot"}),(0,a.jsxs)("div",{className:"figma-snapshot-codegen",children:[(0,a.jsxs)("div",{className:"figma-snapshot-codegen-actions",children:[(0,a.jsx)("button",{type:"button",className:"figma-snapshot-codegen-btn",onClick:tb,"aria-disabled":"generating"===eF?"true":void 0,"aria-busy":"generating"===eF,children:"generating"===eF?"Generating code…":"Generate code"}),"generating"===eF&&(0,a.jsx)("button",{type:"button",className:"figma-snapshot-codegen-cancel-btn",onClick:tE,children:"Cancel"})]}),"error"===eF&&null!==eP&&(0,a.jsx)("p",{className:"figma-snapshot-error",role:"alert",children:eP}),"done"===eF&&null!==eD&&(0,a.jsxs)("div",{className:"figma-snapshot-code-result",children:[(0,a.jsxs)("p",{className:"figma-snapshot-code-summary",children:[String(eD.fileCount)," reviewable file",1!==eD.fileCount?"s":""," (",String(eD.screenCount)," screen",1!==eD.screenCount?"s":"",","," ",eD.adapterName,") — proposal only, never auto-applied."]}),eD.files.map(e=>(0,a.jsxs)("details",{className:"figma-snapshot-code-file",children:[(0,a.jsx)("summary",{className:"figma-snapshot-code-file-path",children:e.path}),(0,a.jsx)("pre",{className:"figma-snapshot-code-file-contents",children:(0,a.jsx)("code",{children:e.contents})})]},e.path))]})]}),(0,a.jsxs)("details",{className:"figma-snapshot-scopes",children:[(0,a.jsx)("summary",{className:"figma-snapshot-scopes-summary",children:"Required Figma PAT scopes"}),(0,a.jsx)("ul",{className:"figma-snapshot-scopes-list",children:(0,a.jsxs)("li",{children:[(0,a.jsx)("code",{children:"file_content:read"})," — read design file structure, node metadata, and rendered images"]})}),(0,a.jsxs)("p",{className:"figma-snapshot-scopes-note",children:["The token is read server-side from the vault, Keiko config, or"," ",(0,a.jsx)("code",{children:"FIGMA_ACCESS_TOKEN"})," environment variable. This window never holds or transmits the token."]}),(0,a.jsxs)("div",{className:"figma-snapshot-revoke-row",children:[eV?(0,a.jsxs)("span",{className:"figma-snapshot-revoke-confirm",children:[(0,a.jsx)("span",{className:"figma-snapshot-revoke-confirm-label",children:"Really revoke the stored token?"}),(0,a.jsx)("button",{ref:eQ,type:"button",className:"figma-snapshot-revoke-confirm-btn",onClick:tF,children:"Yes, revoke"}),(0,a.jsx)("button",{type:"button",className:"figma-snapshot-revoke-cancel-btn",onClick:tT,children:"Cancel"})]}):(0,a.jsx)("button",{ref:eZ,type:"button",className:"figma-snapshot-revoke-btn",onClick:()=>{eJ(!0),eY(null),eG(null);},children:"Revoke stored token"}),(0,a.jsx)("p",{className:"figma-snapshot-revoke-status",role:"status","aria-live":"polite","aria-atomic":"true",children:null!=(l=null!=eH?eH:eX)?l:""})]})]}),ti.length>0?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("section",{className:"figma-snapshot-gallery","aria-label":tl?`${String(ti.length)} selected screen${1!==ti.length?"s":""}`:`${String(tc)} captured and structural screen${1!==tc?"s":""}`,children:ti.slice(0,e0).map((e,t)=>{let n=void 0===g?void 0:()=>g({snapshotRunId:P.runId,screenId:e.screen.screenId,name:e.screen.name}),l={snapshotRunId:P.runId,screenId:e.screen.screenId,name:e.screen.name};return"rendered"===e.kind?(0,a.jsx)(oC,{index:t,screenId:e.screen.screenId,name:e.screen.name,irSummary:e.screen.irSummary,imageSrc:on(P.runId,e.imageIndex),imageByteLength:e.screen.imageByteLength,onAddSource:n,isSourceSelected:tn.has(e.screen.screenId),dragPayload:l},e.screen.screenId):(0,a.jsx)(oC,{index:t,screenId:e.screen.screenId,name:e.screen.name,irSummary:e.screen.irSummary,structuralReason:e.screen.reason,onAddSource:n,isSourceSelected:tn.has(e.screen.screenId),dragPayload:l},e.screen.screenId);})}),e0<ti.length?(0,a.jsx)("button",{type:"button",className:"figma-snapshot-gallery-more",onClick:()=>e1(e=>Math.min(e+24,ti.length)),children:"Show more screens"}):null]}):(0,a.jsx)("div",{className:"lk-empty",children:(0,a.jsx)("p",{className:"lk-empty-body",children:tl?"The selected screen is not present in this stored snapshot.":"No screens were captured from this board section."})})]})]});}function o$(e){var t;let n,{snapshotRunId:l,screenId:r,screenName:s,loadScreenJsonImpl:o=ol}=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==r?void 0:r.trim())?t:"Selected Figma view",x=(0,i.useMemo)(()=>null===p?"":JSON.stringify(p,null,2),[p]),y=(0,i.useMemo)(()=>os(x),[x]),j=(0,i.useCallback)(()=>{var e;if(void 0===l||0===l.trim().length||void 0===r||0===r.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,r,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,r,l]);(0,i.useEffect)(()=>(j(),()=>{var e;null==(e=c.current)||e.abort(),c.current=null;}),[j]);let w=(0,i.useCallback)(()=>{if(0!==x.length){if(void 0===navigator.clipboard)return void v("Clipboard unavailable");navigator.clipboard.writeText(x).then(()=>v("Copied")).catch(()=>v("Copy failed"));}},[x]);return(0,a.jsxs)("section",{className:"figma-json-window","aria-label":`Figma JSON source ${b}`,children:[(0,a.jsxs)("header",{className:"figma-json-header",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"figma-json-eyebrow",children:"Figma JSON"}),(0,a.jsx)("h1",{className:"figma-json-heading",title:b,children:b}),(0,a.jsx)("p",{className:"figma-json-meta",children:null!==p?`${p.screen.kind} \xb7 ${(0,l9.z3)(y)} \xb7 captured ${(0,l9.Yq)(p.fetchedAt)}`:r})]}),(0,a.jsxs)("div",{className:"figma-json-actions",children:[(0,a.jsx)("span",{className:"figma-view-source-badge",children:"QI source"}),(0,a.jsx)("button",{type:"button",className:"figma-view-json-copy-btn",onClick:w,disabled:0===x.length,"aria-disabled":0===x.length?"true":void 0,children:"Copy JSON"})]})]}),"loading"===d?(0,a.jsx)("p",{className:"figma-json-status",role:"status",children:"Loading JSON…"}):null,"error"===d&&null!==h?(0,a.jsxs)("div",{className:"figma-json-error",role:"alert",children:[(0,a.jsx)("p",{children:h}),(0,a.jsx)("button",{type:"button",className:"figma-snapshot-load-btn",onClick:j,children:"Retry"})]}):null,null!==g?(0,a.jsx)("p",{className:"figma-view-json-copy-status",role:"status",children:g}):null,"done"===d&&x.length>0?(0,a.jsx)(oo,{text:x,className:"figma-json-code"}):null]});}function oE(e){let t,{imageSrc:n,screenName:l}=e,i=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,a.jsx)("section",{className:"figma-image-window","aria-label":i,children:(0,a.jsx)("div",{className:"figma-image-missing",role:"alert",children:"Image preview is unavailable."})}):(0,a.jsx)("section",{className:"figma-image-window","aria-label":i,children:(0,a.jsx)(l0.default,{className:"figma-image-preview",src:n,alt:i,width:720,height:480,unoptimized:!0,priority:!0})});}async function oA(e,t){var n,l;let a=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),i="GET"!==a&&"HEAD"!==a,r=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(!r.ok){let e="INTERNAL",t=`HTTP ${r.status.toString()}`;try{let n=await r.json();e=n.error.code,t=n.error.message;}catch{}throw new k.hD(e,t,r.status);}return r.json();}async function oF(){return oA("/api/quality-intelligence/runs");}async function oT(e){return oA(`/api/quality-intelligence/runs/${encodeURIComponent(e)}`);}async function oD(e){let t="QI_RUN_FAILED",n=`HTTP ${e.status.toString()}`;try{var l,a,i,r;let s=await e.json();t=null!=(l=null==(i=s.error)?void 0:i.code)?l:t,n=null!=(a=null==(r=s.error)?void 0:r.message)?a:n;}catch{}return new k.hD(t,n,e.status);}async function oM(e,t,n){var l,a;let i=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}),r=null!=(l=i.headers.get("content-type"))?l:"";if(!i.ok||!r.includes("text/event-stream"))throw await oD(i);let s=i.body;if(null===s)throw new k.hD("QI_NO_STREAM","The server did not return a progress stream.",i.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 oP(e){return oA(`/api/quality-intelligence/runs/${encodeURIComponent(e)}`,{method:"DELETE"});}async function oq(e,t,n,l){return oA(`/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 oL(e,t,n,l){return(await oA(`/api/quality-intelligence/runs/${encodeURIComponent(e)}/edit`,{method:"POST",body:JSON.stringify({candidateId:t,edited:n,...(void 0!==l?{editorLabel:l}:{})})})).candidate;}async function oz(e,t){return oA(`/api/quality-intelligence/runs/${encodeURIComponent(e)}/re-check`,{method:"POST",body:JSON.stringify({sources:t})});}async function oO(e,t){return oA(`/api/quality-intelligence/runs/${encodeURIComponent(e)}/regenerate-stale`,{method:"POST",body:JSON.stringify({sources:t})});}async function oK(e,t,n){var l,a;return oA(`/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 oW(e,t){return oA(`/api/quality-intelligence/runs/${encodeURIComponent(e)}/traceability`,{method:"POST",body:JSON.stringify({format:t})});}var oB=n(76308);let oU={open:"Open",approved:"Approved","changes-requested":"Changes requested",rejected:"Rejected",withdrawn:"Withdrawn"},o_={open:"qi-review-open",approved:"qi-review-approved","changes-requested":"qi-review-changes",rejected:"qi-review-rejected",withdrawn:"qi-review-withdrawn"};function oV(e){let{state:t}=e;return(0,a.jsxs)("span",{className:`qi-review-badge ${o_[t]}`,children:[(0,a.jsx)("span",{className:"sr-only",children:"Review: "}),oU[t]]});}function oJ(e){if(e instanceof k.hD){var t,n;return t=e.code,n=e.message,`${n} (${t})`;}return e instanceof Error?e.message:"An unexpected error occurred.";}function oH(e){try{return new Date(e).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"});}catch{return e;}}let oY={running:"Running",succeeded:"Succeeded",failed:"Failed",cancelled:"Cancelled"},oX={running:"qi-badge-running",succeeded:"qi-badge-succeeded",failed:"qi-badge-failed",cancelled:"qi-badge-cancelled"};function oG(e){return"running"===e||"succeeded"===e||"failed"===e||"cancelled"===e;}function oQ(e){let{status:t}=e,n=oG(t)?oY[t]:t,l=oG(t)?oX[t]:"qi-badge-default";return(0,a.jsx)("span",{className:`qi-badge ${l}`,children:n});}let oZ={critical:"qi-sev-critical",high:"qi-sev-high",medium:"qi-sev-medium",low:"qi-sev-low"};function o0(e){let{severity:t}=e,n="critical"===t||"high"===t||"medium"===t||"low"===t?oZ[t]:"qi-sev-low";return(0,a.jsxs)("span",{className:`qi-sev ${n}`,children:[(0,a.jsx)("span",{className:"sr-only",children:"Severity: "}),t]});}function o1(e){let{score:t}=e;if(null===t)return(0,a.jsxs)("span",{className:"qi-badge qi-badge-default","data-testid":"qi-quality-badge",children:[(0,a.jsx)("span",{"aria-hidden":"true",children:"—"}),(0,a.jsx)("span",{className:"sr-only",children:"Quality score not available"})]});let n=Math.round(t);return(0,a.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,a.jsx)("span",{className:"sr-only",children:" out of 100"})]});}function o2(e){let{flag:t}=e;return(0,a.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,a.jsxs)("span",{className:"qi-weak-flag-badge",children:[(0,a.jsx)("span",{"aria-hidden":"true",className:"qi-weak-flag-icon",children:"⚠"}),"Weak test"]}),(0,a.jsx)("p",{className:"qi-weak-flag-reason",children:t.rationale})]});}let o4={verifiability:"Verifiability",atomicity:"Atomicity",determinism:"Determinism","ac-fidelity":"AC fidelity"};function o3(e){let{verdict:t}=e,n=Math.round(t.score),l="strong"===t.verdict?"Strong":"Weak";return(0,a.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,a.jsx)("p",{className:"qi-cand-block-label",children:"Quality verdict"}),(0,a.jsxs)("p",{children:[l," - ",n.toString(),"/100"]}),(0,a.jsx)("ul",{className:"qi-cand-list","aria-label":"Quality dimensions",children:t.dimensions.map(e=>{var t;return(0,a.jsxs)("li",{children:[null!=(t=o4[e.name])?t:e.name," ",Math.round(e.score).toString(),": ",e.rationale]},e.name);})})]});}function o5(e){let{height:t=20,width:n="100%"}=e;return(0,a.jsx)("div",{"aria-hidden":"true",className:"qi-skeleton",style:{height:t,width:n}});}function o6(){return(0,a.jsx)("div",{"data-testid":"qi-loading-state","aria-busy":"true",style:{display:"flex",flexDirection:"column",gap:8,padding:"12px 0"},children:[1,2,3].map(e=>(0,a.jsxs)("div",{className:"qi-skeleton-row",children:[(0,a.jsx)(o5,{height:14,width:"60%"}),(0,a.jsx)(o5,{height:12,width:"40%"})]},e))});}function o8(e){let{message:t,onRetry:n}=e;return(0,a.jsxs)("div",{role:"alert","aria-live":"assertive",className:"lk-alert","data-testid":"qi-error-state",children:[t,(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:n,children:"Retry"})]});}let o7=[{id:"regression-default",label:"Regression (default)"},{id:"banking-default",label:"Banking"},{id:"insurance-default",label:"Insurance"}],o9=[{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 ce(e){let{kind:t}=e;return"requirements"===t?(0,a.jsx)(N.F.review,{size:15}):"workspace"===t?(0,a.jsx)(N.F.folder,{size:15}):"file"===t?(0,a.jsx)(N.F.file,{size:15}):"capsule-set"===t?(0,a.jsx)(N.F.layers,{size:15}):(0,a.jsx)("svg",{"aria-hidden":"true",className:"qi-source-kind-icon-svg",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"M12 3.8 19 7.7v8.6L12 20.2 5 16.3V7.7z"})});}let ct={phase:"Starting…",stageName:null,candidates:0,findings:0,atomCount:null,droppedSourceCount:0,skippedSources:[]},cn="Der Lauf wurde nicht erfolgreich abgeschlossen. Passe die Quelle an und versuche es erneut.";function cl(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 ca(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 ci(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 cr(e){let{onRunCompleted:t,startImpl:n=oM,fetchCapsulesImpl:l=ik.xr,fetchCapsuleSetsImpl:r=ik.R3,fetchProjectsImpl:s=k.vj,fetchFilesTreeImpl:o=k.KD,connectedRoot:c=null,connectedFilePath:d=null,connectedRoots:u,connectedCapsuleIds:p,connectedCapsuleSetIds:m,connectedFigmaSnapshotRunIds:h,connectedFigmaSnapshotSources:f,connectedImageSources:g}=e,[v,b]=(0,i.useState)(""),[x,y]=(0,i.useState)("requirements"),[j,w]=(0,i.useState)(""),[N,S]=(0,i.useState)(""),[C,I]=(0,i.useState)(""),[R,$]=(0,i.useState)(""),[E,A]=(0,i.useState)(!1),[F,T]=(0,i.useState)([]),[D,M]=(0,i.useState)([]),[P,q]=(0,i.useState)(!1),[L,z]=(0,i.useState)(null),[O,K]=(0,i.useState)("regression-default"),[W,B]=(0,i.useState)(""),[U,_]=(0,i.useState)(!1),[V,J]=(0,i.useState)(ct),[H,Y]=(0,i.useState)(null),[X,G]=(0,i.useState)(null),Q=(0,i.useRef)(null),Z=(0,i.useRef)(null),ee=(0,i.useRef)(null),et=(0,i.useRef)(!1),en=ro({connectedRoot:c,connectedFilePath:d,connectedRoots:u,connectedCapsuleIds:p,connectedCapsuleSetIds:m,connectedFigmaSnapshotRunIds:h,connectedFigmaSnapshotSources:f,connectedImageSources:g}),el=en.length>0,ea=F.find(e=>e.id===C),ei=D.find(e=>e.id===R),er=N.trim().length>0,es="requirements"===x?j.trim().length>0:"workspace"===x||"file"===x?er:"capsule"===x?C.trim().length>0:R.trim().length>0,eo="requirements"===x?0===j.trim().length:("workspace"===x||"file"===x)&&!er,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);B(String(Math.max(0,(Number.isFinite(t)?t:0)+e))),Y(null);},eh=!ec||!ep,ef=(0,i.useId)(),eg=(0,i.useId)(),ev=(0,i.useId)(),eb=(0,i.useId)(),ex=(0,i.useId)(),ey=ec?ep?void 0:eg:ef,ej="workspace"===x||"file"===x?x:null,ew=(0,i.useCallback)(e=>{y(e),A(!1),Y(null),z(null);},[]),ek=(0,i.useCallback)((e,t)=>{U||0!==e.button||ew(t);},[ew,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=o9.length,i=(Math.max(0,o9.findIndex(e=>e.id===x))+l+a)%a,r=o9[i];void 0!==r&&(ew(r.id),null==(n=e.currentTarget.parentElement)||null==(t=n.querySelectorAll('[role="radio"]')[i])||t.focus());},[ew,U,x]),eS=(0,i.useCallback)(e=>{var t,n,l,a,i;"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?(Z.current=e.runId,!0===e.degraded&&G(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&&Y(null==(l=null!=(n=e.reasonSummary)?n:ee.current)||0===l.trim().length?cn:"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: ")?`${cn} (${l.slice(10)})`:l.startsWith("qi-safe-error: ")?`${cn} (${l.slice(15)})`:`${cn} (${l})`)),"error"===e.type&&Y((a=e.code,i=e.message,`${i} (${a})`)),J(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,i=null!=(a=t.stageName)?a:e.stageName;return{...e,phase:t.kind,stageName:i,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(){q(!0),z(null);try{let[t,n]=await Promise.allSettled([l(),r()]);if(e)return;"fulfilled"===t.status?T(t.value.capsules.filter(e=>"ready"===e.lifecycleState)):(T([]),"capsule"===x&&z(oJ(t.reason))),"fulfilled"===n.status?M(n.value.capsuleSets):(M([]),"capsule-set"===x&&z(oJ(n.reason)));}finally{e||q(!1);}}(),()=>{e=!0;};},[l,r,eC,x]),(0,i.useEffect)(()=>{var e,t,n,l;if("capsule"===x){let n=F.some(e=>e.id===C)?C:null!=(e=null==(t=F[0])?void 0:t.id)?e:"";n!==C&&I(n);}if("capsule-set"===x){let e=D.some(e=>e.id===R)?R:null!=(n=null==(l=D[0])?void 0:l.id)?n:"";e!==R&&$(e);}},[C,R,D,F,x]);let eI=(0,i.useCallback)(()=>{let e=v.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&&R.trim().length>0?[{kind:"capsule-set",label:e||(null==ei?void 0:ei.displayName)||"Capsule set",capsuleSetId:R.trim()}]:null;},[C,R,v,N,ea,ei,x,j]),eR=(0,i.useCallback)(async()=>{var e;if(!ec||U||!ep||et.current)return;et.current=!0,_(!0),Y(null),G(null),J(ct),Z.current=null,ee.current=null;let l=new AbortController();Q.current=l;let a=null!=(e=eI())?e:en,i={sources:a,profileId:O,...(void 0!==eu?{seed:eu}:{})};try{await n(i,l.signal,eS);let e=Z.current;null!==e&&(null==t||t(e,a.filter(e=>"requirements"!==e.kind)));}catch(e){l.signal.aborted||Y(oJ(e));}finally{_(!1),Q.current=null,et.current=!1;}},[ec,O,U,en,eI,eS,t,eu,ep,n]),e$=(0,i.useCallback)(()=>{var e;null==(e=Q.current)||e.abort();},[]),eE=V.droppedSourceCount>0?`${V.droppedSourceCount.toString()} source${1!==V.droppedSourceCount?"s":""} over the 16-source limit ${1!==V.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(cl).join(", ")}.`;}(V.skippedSources),eF=[eE,eA].filter(e=>null!==e).join(" ");return(0,a.jsxs)("section",{className:"qi-launcher","aria-label":"Start a Quality Intelligence run",children:[(0,a.jsx)("header",{className:"qi-col-header",children:(0,a.jsx)("h2",{className:"qi-col-title",children:"New run"})}),(0,a.jsxs)("div",{className:"qi-launcher-body",children:[1===en.length&&void 0!==en[0]?(0,a.jsxs)("div",{className:"qi-connected-source","data-testid":"qi-connected-source",children:[(0,a.jsxs)("span",{className:"qi-connected-kind",children:["Connected ",ca(en[0]).toLowerCase()]}),(0,a.jsx)("span",{className:"qi-connected-path qi-monospace",title:ci(en[0]),children:ci(en[0])}),(0,a.jsx)("span",{className:"qi-connected-hint",children:es?"Manual input below overrides the connected source for this run.":`Generate uses the connected ${ca(en[0]).toLowerCase()}.`})]}):en.length>1?(0,a.jsxs)("div",{className:"qi-connected-source","data-testid":"qi-connected-source",children:[(0,a.jsxs)("span",{className:"qi-connected-kind",children:["Connected sources (",en.length.toString(),")"]}),(0,a.jsx)("ul",{className:"qi-connected-roots","aria-label":"Connected sources",children:en.map(e=>(0,a.jsxs)("li",{className:"qi-connected-root-item",children:[(0,a.jsx)("span",{className:"qi-connected-root-name",children:ca(e)}),(0,a.jsx)("span",{className:"qi-connected-path qi-monospace",title:ci(e),children:ci(e)})]},`${e.kind}:${ci(e)}`))}),(0,a.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,a.jsxs)("div",{className:"qi-launcher-row",children:[(0,a.jsxs)("label",{className:"qi-field",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Source label"}),(0,a.jsx)("input",{type:"text",className:"qi-input",value:v,placeholder:"e.g. Funds Transfer — acceptance criteria",disabled:U,"aria-describedby":el&&!es?ev:void 0,onChange:e=>{b(e.target.value);}}),el&&!es?(0,a.jsx)("span",{className:"qi-field-hint",id:ev,children:"Applies to manual input only — connected sources use their own labels."}):null]}),(0,a.jsxs)("div",{className:"qi-field qi-field-kind",children:[(0,a.jsx)("span",{className:"qi-field-label",id:eb,children:"Source type"}),(0,a.jsx)("div",{className:"qi-source-kind-grid",role:"radiogroup","aria-labelledby":eb,"aria-disabled":U||void 0,children:o9.map(e=>(0,a.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:()=>ew(e.id),onKeyDown:eN,children:[(0,a.jsx)("span",{className:"qi-source-kind-label",children:e.label}),(0,a.jsx)("span",{className:"qi-source-kind-icon","aria-hidden":"true",children:(0,a.jsx)(ce,{kind:e.id})})]},e.id))})]})]}),function(){if("requirements"===x)return(0,a.jsxs)("label",{className:"qi-field",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Requirements"}),(0,a.jsx)("textarea",{className:"qi-textarea",value:j,rows:6,placeholder:"Paste requirements or acceptance criteria, one statement per line.",disabled:U,onChange:e=>{w(e.target.value);}})]});if("workspace"===x||"file"===x){let e="file"===x;return(0,a.jsxs)("div",{className:"qi-field",children:[(0,a.jsx)("span",{className:"qi-field-label",id:ex,children:e?"File path":"Folder path"}),(0,a.jsxs)("div",{className:"qi-path-picker",children:[(0,a.jsx)("div",{className:"qi-path-value qi-monospace",role:"textbox","aria-readonly":"true","aria-labelledby":ex,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,a.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?F:D;return(0,a.jsxs)("label",{className:"qi-field",children:[(0,a.jsx)("span",{className:"qi-field-label",children:e?"Knowledge capsule":"Capsule set"}),(0,a.jsxs)("select",{className:"qi-select",value:e?C:R,disabled:U||P||null!==L||0===t.length,onChange:t=>{e?I(t.target.value):$(t.target.value);},children:[P?(0,a.jsx)("option",{value:"",children:"Loading connectors..."}):null,P||0!==t.length?null:(0,a.jsx)("option",{value:"",children:e?"No ready capsules":"No capsule sets"}),e?F.map(e=>(0,a.jsx)("option",{value:e.id,children:e.displayName},e.id)):D.map(e=>(0,a.jsx)("option",{value:e.id,children:`${e.displayName} (${String(e.capsuleCount)} capsules)`},e.id))]})]});}(),null!==L?(0,a.jsx)("p",{className:"lk-alert",role:"alert","data-testid":"qi-connector-error",children:L}):null,(0,a.jsxs)("div",{className:"qi-launcher-controls",children:[(0,a.jsxs)("div",{className:"qi-field qi-field-inline qi-policy-profile-field",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Policy profile"}),(0,a.jsx)(nd,{triggerClassName:"qi-select",value:O,ariaLabel:"Policy profile",disabled:U,menuTitle:"Policy",menuClassName:"qi-policy-profile-menu",sections:[{options:o7.map(e=>({value:e.id,label:e.label}))}],onValueChange:K})]}),(0,a.jsxs)("label",{className:"qi-field qi-field-inline",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Seed (optional)"}),(0,a.jsxs)("span",{className:"number-control qi-number-control",children:[(0,a.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=>{B(e.target.value),Y(null);},onWheel:e=>{U||0===e.deltaY||(e.preventDefault(),em(e.deltaY<0?1:-1));}}),(0,a.jsx)(aV,{label:"seed",disabled:U,onStepUp:()=>em(1),onStepDown:()=>em(-1)})]}),ep?null:(0,a.jsx)("span",{className:"qi-field-error",id:eg,children:"Seed must be a non-negative integer."})]}),(0,a.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:ey,onClick:()=>{U?e$():eh||eR();},children:U?"Cancel":"Generate test cases"}),U||ec?null:(0,a.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,a.jsxs)("div",{className:"qi-progress","data-testid":"qi-launch-progress","aria-hidden":"true",children:[(0,a.jsx)("span",{className:"qi-progress-spinner","aria-hidden":"true"}),(0,a.jsxs)("span",{className:"qi-progress-text",children:[null!==V.stageName?`Stage: ${V.stageName} \xb7 `:"",V.candidates.toString()," test case",1!==V.candidates?"s":"",V.findings>0?` \xb7 ${V.findings.toString()} finding${1!==V.findings?"s":""}`:""]})]}):null,(0,a.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,V)}),(0,a.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite",children:eF}),null!==eE||null!==eA?(0,a.jsxs)("div",{className:"qi-coverage-notice","data-testid":"qi-coverage-notice",children:[null!==eE?(0,a.jsx)("p",{className:"qi-coverage-line",children:eE}):null,null!==eA?(0,a.jsx)("p",{className:"qi-coverage-line",children:eA}):null]}):null,null!==X?(0,a.jsx)("p",{className:"qi-degraded-notice",role:"status","data-testid":"qi-launch-degraded",children:X}):null,null!==H?(0,a.jsx)("p",{className:"lk-alert",role:"alert","data-testid":"qi-launch-error",children:H}):null]}),E&&null!==ej?(0,a.jsx)(oB.c2,{mode:"file"===ej?"file":"folder",title:`Choose ${"file"===ej?"file":"folder"} source`,description:"Browse a registered local project or enter an absolute folder root.",initialRootPath:"file"===ej?(0,oB.pD)(N):N,fetchProjectsImpl:s,fetchFilesTreeImpl:o,onCancel:()=>A(!1),onApply:e=>{var t;S("file"===ej?(0,oB.$e)(e.rootPath,null!=(t=e.files[0])?t:null):e.folderPath),A(!1),Y(null);}}):null]});}function cs(e){var t;let{run:n,onOpen:l,onDelete:r,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||r(n.id);},[s,r,n.id]);return(0,a.jsxs)("li",{style:{display:"flex",alignItems:"stretch"},children:[(0,a.jsxs)("button",{type:"button",className:"qi-run-item",style:{flex:1},onClick:()=>{l(n.id,[]);},"aria-label":`Open run ${n.id} — ${oG(t=n.status)?oY[t]:t}, ${oH(n.requestedAt)}, ${o.toString()} test case${1!==o?"s":""}, review ${oU[n.reviewState]}`,title:`Open run ${n.id}`,children:[(0,a.jsx)("span",{className:"qi-run-title",children:oH(n.requestedAt)}),(0,a.jsx)(oQ,{status:n.status}),(0,a.jsx)(oV,{state:n.reviewState}),(0,a.jsxs)("span",{className:"qi-run-id",children:[n.id.slice(0,16),"…"]}),(0,a.jsxs)("span",{className:"qi-run-totals",children:[n.totals.candidates.toString()," test case",1!==n.totals.candidates?"s":""]})]}),c?(0,a.jsxs)("div",{className:"qi-cand-actions",role:"group","aria-label":`Confirm deleting run ${oH(n.requestedAt)}`,style:{display:"flex",alignItems:"center",gap:4,padding:"0 6px",flexShrink:0},children:[(0,a.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 ${oH(n.requestedAt)}`,"aria-busy":s||void 0,"aria-disabled":s||void 0,onClick:g,onKeyDown:f,children:s?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{"aria-hidden":"true",children:"Deleting…"}),(0,a.jsx)("span",{className:"sr-only",children:"Deleting run, please wait"})]}):"Confirm delete"}),(0,a.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,a.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 ${oH(n.requestedAt)}`,onClick:()=>{d(!0);},children:"Delete"})]});}function co(e){let{openRun:t,connectedRoot:n=null,connectedFilePath:l=null,connectedRoots:r,connectedCapsuleIds:s,connectedCapsuleSetIds:o,connectedFigmaSnapshotRunIds:c,connectedFigmaSnapshotSources:d,connectedImageSources:u,fetchRunsImpl:p=oF,deleteImpl:m=oP}=e,[h,f]=(0,i.useState)([]),[g,v]=(0,i.useState)(0),[b,x]=(0,i.useState)(!1),[y,j]=(0,i.useState)(!0),[w,k]=(0,i.useState)(null),[N,S]=(0,i.useState)(25),[C,I]=(0,i.useState)(null),[R,$]=(0,i.useState)(""),E=(0,i.useCallback)(async()=>{j(!0),k(null);try{let e=await p();f(e.runs),v(e.totalRunIds),x(e.truncated);}catch(e){k(oJ(e));}finally{j(!1);}},[p]);(0,i.useEffect)(()=>{E();},[E]);let A=(0,i.useCallback)((e,n)=>{E(),t(e,n);},[E,t]),F=(0,i.useCallback)(async e=>{if(null===C){I(e),k(null);try{await m(e),$("Run deleted."),await E();}catch(e){k(oJ(e));}finally{I(null);}}},[C,m,E]);return(0,a.jsxs)("div",{className:"qi-hub",children:[(0,a.jsx)(cr,{onRunCompleted:A,connectedRoot:n,connectedFilePath:l,connectedRoots:r,connectedCapsuleIds:s,connectedCapsuleSetIds:o,connectedFigmaSnapshotRunIds:c,connectedFigmaSnapshotSources:d,connectedImageSources:u}),(0,a.jsxs)("section",{className:"qi-hub-runs","aria-label":"Quality Intelligence runs",children:[(0,a.jsxs)("header",{className:"qi-col-header",children:[(0,a.jsx)("h2",{className:"qi-col-title",children:"Runs"}),y||null!==w?null:(0,a.jsx)("span",{className:"qi-col-count",children:g.toString()})]}),(0,a.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite",children:y?"Loading runs…":null===w?`Run list loaded: ${h.length.toString()} run${1===h.length?"":"s"}${b?` of ${g.toString()}`:""}.`:""}),(0,a.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite","aria-atomic":"true",children:R}),(0,a.jsx)("div",{className:"qi-col-body","aria-busy":y,children:y?(0,a.jsx)(o6,{}):null!==w?(0,a.jsx)(o8,{message:w,onRetry:()=>{E();}}):0===h.length?(0,a.jsxs)("div",{className:"lk-empty",children:[(0,a.jsx)("p",{className:"lk-empty-title",children:"No runs yet"}),(0,a.jsx)("p",{className:"lk-empty-body",children:"Start a run above — generated test cases open as cards on your workspace."})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("ul",{className:"qi-run-list","aria-label":"Run list",children:h.slice(0,N).map(e=>(0,a.jsx)(cs,{run:e,onOpen:t,onDelete:e=>{F(e);},deleting:C===e.id},e.id))}),N<h.length?(0,a.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,a.jsx)("p",{className:"qi-runs-truncated","data-testid":"qi-runs-truncated",children:`Showing ${h.length.toString()} of ${g.toString()} runs.`}):null]})})]})]});}let cc=["P0","P1","P2","P3"],cd=["safety","compliance","regression","functional","visual"],cu=e=>e.split("\n").map(e=>e.trim()).filter(e=>e.length>0),cp=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]);function cm(e,t){let n=cu(t.preconditions),l=cu(t.steps),a=cu(t.expectedResults),i=t.tags.split(",").map(e=>e.trim()).filter(e=>e.length>0);return{...(t.title!==e.title?{title:t.title}:{}),...(!cp(n,e.preconditions)?{preconditions:n}:{}),...(!cp(l,e.steps)?{steps:l}:{}),...(!cp(a,e.expectedResults)?{expectedResults:a}:{}),...(t.priority!==e.priority?{priority:t.priority}:{}),...(t.riskClass!==e.riskClass?{riskClass:t.riskClass}:{}),...(!cp(i,e.tags)?{tags:i}:{})};}function ch(e){let{id:t,label:n,value:l,disabled:i=!1,onChange:r}=e;return(0,a.jsxs)("label",{className:"qi-edit-field",htmlFor:t,children:[(0,a.jsx)("span",{className:"qi-edit-label",children:n}),(0,a.jsx)("textarea",{id:t,className:"qi-edit-textarea",value:l,rows:3,disabled:i,onChange:e=>{r(e.target.value);}})]});}function cf(e){let{id:t,label:n,value:l,disabled:i=!1,required:r=!1,onChange:s}=e;return(0,a.jsxs)("label",{className:"qi-edit-field",htmlFor:t,children:[(0,a.jsx)("span",{className:"qi-edit-label","data-required":r?"true":void 0,children:n}),(0,a.jsx)("input",{id:t,className:"qi-edit-input",value:l,disabled:i,required:r,"aria-required":r?"true":void 0,onChange:e=>{s(e.target.value);}})]});}function cg(e){let{id:t,label:n,value:l,options:i,disabled:r=!1,onChange:s}=e;return(0,a.jsxs)("label",{className:"qi-edit-field",htmlFor:t,children:[(0,a.jsx)("span",{className:"qi-edit-label",children:n}),(0,a.jsx)("select",{id:t,className:"qi-edit-select",value:l,disabled:r,onChange:e=>{s(e.target.value);},children:i.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]});}function cv(e){let{onCancel:t,saving:n}=e;return(0,a.jsxs)("div",{className:"qi-edit-actions",children:[(0,a.jsx)("button",{type:"submit",className:"qi-btn qi-btn-approve qi-edit-save","aria-disabled":n||void 0,children:"Save"}),(0,a.jsx)("button",{type:"button",className:"qi-btn qi-btn-secondary qi-edit-cancel","aria-disabled":n||void 0,onClick:()=>{n||t();},children:"Cancel"})]});}function cb(e){let{candidate:t,onSave:n,onCancel:l}=e,[r,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(cm(t,r)).length>0)||p?l():m(!0));},[t,p,l,d,r]);(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(cm(t,r));}catch(e){c(oJ(e));}finally{u(!1);}}};return(0,a.jsxs)("form",{ref:h,className:"qi-edit-form","aria-label":`Edit ${t.title}`,"aria-busy":d,onSubmit:e=>{e.preventDefault(),b();},children:[(0,a.jsxs)("div",{className:"qi-edit-head",children:[(0,a.jsxs)("div",{className:"qi-edit-head-copy",children:[(0,a.jsx)("p",{className:"qi-edit-eyebrow",children:"Edit test case"}),(0,a.jsx)("h3",{className:"qi-edit-heading",children:t.title})]}),(0,a.jsx)(cv,{onCancel:g,saving:d})]}),null!==o?(0,a.jsx)("p",{className:"qi-edit-error",role:"alert","aria-live":"assertive",children:o}):null,(0,a.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,a.jsxs)("div",{className:"qi-edit-layout",children:[(0,a.jsxs)("div",{className:"qi-edit-main",children:[(0,a.jsx)(cf,{id:`${v}-title`,label:"Title",value:r.title,disabled:d,required:!0,onChange:e=>{f("title",e);}}),(0,a.jsx)(ch,{id:`${v}-preconditions`,label:"Preconditions (one per line)",value:r.preconditions,disabled:d,onChange:e=>{f("preconditions",e);}}),(0,a.jsx)(ch,{id:`${v}-steps`,label:"Steps (one per line)",value:r.steps,disabled:d,onChange:e=>{f("steps",e);}}),(0,a.jsx)(ch,{id:`${v}-expected`,label:"Expected results (one per line)",value:r.expectedResults,disabled:d,onChange:e=>{f("expectedResults",e);}})]}),(0,a.jsxs)("div",{className:"qi-edit-side",children:[(0,a.jsx)(cg,{id:`${v}-priority`,label:"Priority",value:r.priority,options:cc,disabled:d,onChange:e=>{f("priority",e);}}),(0,a.jsx)(cg,{id:`${v}-risk`,label:"Risk class",value:r.riskClass,options:cd,disabled:d,onChange:e=>{f("riskClass",e);}}),(0,a.jsx)(cf,{id:`${v}-tags`,label:"Tags (comma-separated)",value:r.tags,disabled:d,onChange:e=>{f("tags",e);}})]})]})]});}let cx=new Set(["approved","rejected","withdrawn"]);function cy(e){let{items:t,label:n}=e;return 0===t.length?null:(0,a.jsxs)("div",{className:"qi-cand-block",children:[(0,a.jsx)("p",{className:"qi-cand-block-label",children:n}),(0,a.jsx)("ol",{className:"qi-cand-list","aria-label":n,children:t.map((e,t)=>(0,a.jsx)("li",{children:e},`${n}-${String(t)}`))})]});}function cj(e){let{candidate:t}=e;return(0,a.jsxs)("dl",{className:"qi-cand-meta","aria-label":"Test case metadata",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Steps"}),(0,a.jsx)("dd",{children:t.steps.length.toString()})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Expected"}),(0,a.jsx)("dd",{children:t.expectedResults.length.toString()})]}),void 0!==t.qualityVerdict?(0,a.jsxs)("div",{children:[(0,a.jsx)("dt",{children:"Quality"}),(0,a.jsx)("dd",{children:Math.round(t.qualityVerdict.score).toString()})]}):null]});}function cw(e){let{title:t,children:n}=e;return(0,a.jsxs)("details",{className:"qi-cand-accordion",children:[(0,a.jsx)("summary",{className:"qi-cand-accordion-summary",children:(0,a.jsx)("span",{children:t})}),(0,a.jsx)("div",{className:"qi-cand-accordion-body",children:n})]});}function ck(e){let{candidate:t}=e;return(0,a.jsxs)(cw,{title:"Scenario",children:[(0,a.jsx)(cy,{items:t.preconditions,label:"Preconditions"}),(0,a.jsx)(cy,{items:t.steps,label:"Steps"}),(0,a.jsx)(cy,{items:t.expectedResults,label:"Expected results"})]});}function cN(e){let{candidate:t}=e;return 0===t.tags.length&&void 0===t.qualityVerdict&&void 0===t.weakTestFlag?null:(0,a.jsxs)(cw,{title:"Evidence",children:[void 0!==t.weakTestFlag?(0,a.jsx)(o2,{flag:t.weakTestFlag}):null,void 0!==t.qualityVerdict?(0,a.jsx)(o3,{verdict:t.qualityVerdict}):null,t.tags.length>0?(0,a.jsx)("ul",{className:"qi-cand-tags","aria-label":"Tags",children:t.tags.map(e=>(0,a.jsx)("li",{className:"qi-cand-tag",children:e},e))}):null]});}function cS(e){let{className:t,label:n,pressed:l,disabled:i,describedBy:r,onActivate:s}=e;return(0,a.jsx)("button",{type:"button",className:t,...(void 0!==l?{"aria-pressed":l}:{}),"aria-disabled":i||void 0,"aria-describedby":i?r:void 0,onClick:()=>{i||s();},children:n});}function cC(e){let{candidateId:t,state:n,onReview:l,disabled:r=!1,describedBy:s,pendingReview:o}=e,c=null!=o,d=e=>c&&o.candidateId===t&&o.action===e,u=cx.has(n),p=(0,i.useId)(),m=u?p:s;return(0,a.jsxs)("div",{className:"qi-cand-actions",role:"group","aria-label":"Review decision",children:[u?(0,a.jsx)("p",{id:p,className:"qi-cand-governance-note",role:"note",children:"This review decision is final — reopen to change it."}):null,(0,a.jsx)(cS,{className:"qi-btn qi-btn-approve",label:d("approve")?"Saving…":"Approve",pressed:"approved"===n,disabled:r||c||u,describedBy:m,onActivate:()=>{l(t,"approve");}}),(0,a.jsx)(cS,{className:"qi-btn qi-btn-reject",label:d("reject")?"Saving…":"Reject",pressed:"rejected"===n,disabled:r||c||u,describedBy:m,onActivate:()=>{l(t,"reject");}}),(0,a.jsx)(cS,{className:"qi-btn qi-btn-secondary",label:d("request-changes")?"Saving…":"Request changes",pressed:"changes-requested"===n,disabled:r||c||u,describedBy:m,onActivate:()=>{l(t,"request-changes");}}),u?(0,a.jsx)(cS,{className:"qi-btn qi-btn-secondary",label:d("reopen")?"Saving…":"Reopen",disabled:r||c,describedBy:r?s:void 0,onActivate:()=>{l(t,"reopen");}}):null]});}function cI(e){let{candidate:t,onReview:n,onStartEdit:l,actionsDisabled:r=!1,actionsDisabledReason:s,describedBy:o,editButtonRef:c,pendingReview:d}=e,u=(0,i.useId)(),p=r&&void 0!==s?[o,u].filter(Boolean).join(" "):o;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"qi-cand-header",children:[(0,a.jsx)("div",{className:"qi-cand-title-wrap",children:(0,a.jsx)("h3",{className:"qi-cand-title",children:t.title})}),(0,a.jsxs)("div",{className:"qi-cand-status",children:[(0,a.jsxs)("div",{className:"qi-cand-badges",children:[(0,a.jsx)("span",{className:"qi-cand-risk",children:t.riskClass}),"open"!==t.reviewState?(0,a.jsx)(oV,{state:t.reviewState}):null]}),(0,a.jsx)(cj,{candidate:t})]})]}),(0,a.jsxs)("div",{className:"qi-cand-accordion-stack",children:[(0,a.jsx)(ck,{candidate:t}),(0,a.jsx)(cN,{candidate:t})]}),(0,a.jsxs)("div",{className:"qi-cand-actions-row",children:[r&&void 0!==s?(0,a.jsx)("p",{id:u,className:"qi-cand-action-note",role:"note",children:s}):null,(0,a.jsxs)("div",{className:"qi-cand-action-buttons",children:[void 0!==l?(0,a.jsx)("button",{ref:c,type:"button",className:"qi-btn qi-btn-secondary qi-cand-edit","aria-disabled":r||void 0,"aria-describedby":r?p:void 0,onClick:()=>{r||l();},children:"Edit"}):null,void 0!==n?(0,a.jsx)(cC,{candidateId:t.id,state:t.reviewState,onReview:n,disabled:r,describedBy:p,pendingReview:d}):null]})]})]});}function cR(e){let{candidate:t,onReview:n,onEdit:l,actionsDisabled:r=!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,a.jsx)("li",{className:d?"qi-cand-card qi-cand-card-editing":"qi-cand-card",children:d&&void 0!==l?(0,a.jsx)(cb,{candidate:t,onSave:h,onCancel:()=>{u(!1);}}):(0,a.jsx)(cI,{candidate:t,onReview:n,actionsDisabled:r,actionsDisabledReason:s,describedBy:o,pendingReview:c,editButtonRef:p,onStartEdit:void 0!==l?()=>{u(!0);}:void 0})});}function c$(e){let{candidates:t,onReview:n,onEdit:l,actionsDisabled:r=!1,actionsDisabledReason:s,pendingReview:o}=e,[c,d]=(0,i.useState)(25),u=(0,i.useId)(),p=r&&void 0!==s;if(0===t.length)return(0,a.jsxs)("div",{className:"lk-empty",children:[(0,a.jsx)("p",{className:"lk-empty-title",children:"No test cases"}),(0,a.jsx)("p",{className:"lk-empty-body",children:"This run produced no generated test cases."})]});let m=[...t].sort((e,t)=>!!e.tags.includes("source:deterministic-baseline")-!!t.tags.includes("source:deterministic-baseline")).slice(0,c);return(0,a.jsxs)("div",{className:"qi-cand-pane",children:[p?(0,a.jsx)("p",{id:u,className:"qi-cand-governance-note",role:"note",children:s}):null,(0,a.jsx)("ul",{className:"qi-cand-cards","aria-label":"Test case list",children:m.map(e=>(0,a.jsx)(cR,{candidate:e,onReview:n,onEdit:l,actionsDisabled:r,actionsDisabledReason:s,describedBy:p?u:void 0,pendingReview:o},e.id))}),c<t.length?(0,a.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 cE(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 cA(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 cF(e){let{staleCount:t}=e;return 0===t?(0,a.jsxs)("p",{className:"qi-drift-fresh","data-testid":"qi-drift-fresh",children:[(0,a.jsx)("span",{"aria-hidden":"true",className:"qi-drift-icon-ok",children:"✓"}),cE(0)]}):(0,a.jsxs)("p",{className:"qi-drift-stale","data-testid":"qi-drift-stale",children:[(0,a.jsx)("span",{"aria-hidden":"true",className:"qi-drift-icon-warn",children:"⚠"}),cE(t)]});}function cT(e){let{runId:t,connectedSources:n,onRegenerated:l,reCheckImpl:r=oz,regenerateImpl:s=oO}=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),x=(0,i.useCallback)(()=>{p||(async()=>{u("check"),h(null),g(null);try{c(await r(t,n));}catch(e){h(oJ(e));}finally{u(null);}})();},[p,r,t,n]),y=(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(oJ(e));}finally{u(null);}})();},[p,s,t,n,l]);return(0,a.jsxs)("section",{className:"qi-drift-panel","aria-label":"Drift detection",children:[(0,a.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite",children:null!==f?cA(f):null!==o?cE(o.staleCount):""}),(0,a.jsxs)("div",{className:"qi-drift-head",children:[(0,a.jsx)("h3",{className:"qi-col-subtitle",children:"Living tests"}),(0,a.jsx)("button",{type:"button",ref:v,className:"qi-btn qi-btn-secondary",onClick:x,"aria-disabled":p||void 0,"data-testid":"qi-drift-recheck",children:"check"===d?"Checking…":"Re-check drift"})]}),null!==m?(0,a.jsx)("p",{className:"lk-alert",role:"alert",children:m}):null,null!==o?(0,a.jsx)(cF,{staleCount:o.staleCount}):null,null!==o&&o.staleCount>0&&null===f?(0,a.jsx)("button",{type:"button",ref:b,className:"qi-btn qi-btn-approve",onClick:y,"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,a.jsx)("p",{className:"qi-drift-regenerated","data-testid":"qi-drift-regenerated",children:cA(f)}):null]});}let cD={"traceability-csv":"csv","traceability-markdown":"markdown"},cM=[{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 cP(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}),i=URL.createObjectURL(a),r=document.createElement("a");r.href=i,r.download=e,document.body.appendChild(r),r.click(),r.remove(),window.setTimeout(()=>{URL.revokeObjectURL(i);},250);}function cq(e){var t;let{runId:n,exportImpl:l=oK,traceabilityImpl:r=oW}=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),x=cM.find(e=>e.id===s),y=null!=(t=null==x?void 0:x.tms)&&t,j=(0,i.useCallback)(async()=>{let e=cD[s];if(void 0!==e){let t=await r(n,e);cP(t.filename,t.contentType,t.body),g(t.filename);return;}let t=await l(n,s,{dryRun:y,approvedOnly:v});t.dryRun?h(`${t.candidateCount.toString()} test case${1===t.candidateCount?"":"s"} \xb7 ${t.byteLen.toString()} bytes
97
-
98
- ${t.preview}`):(cP(t.filename,t.contentType,t.body,t.encoding),g(t.filename));},[n,s,y,v,l,r]),w=(0,i.useCallback)(async()=>{d(!0),p(null),h(null),g(null);try{await j();}catch(e){p(oJ(e));}finally{d(!1);}},[j]);return(0,a.jsxs)("div",{className:"qi-export","data-testid":"qi-export-bar",children:[(0,a.jsxs)("div",{className:"qi-export-head",children:[(0,a.jsxs)("div",{className:"qi-export-copy",children:[(0,a.jsx)("p",{className:"qi-export-title",children:"Export"}),y?null:(0,a.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."})]}),y?null:(0,a.jsxs)("label",{className:"qi-export-approved-label",children:[(0,a.jsx)("input",{type:"checkbox",className:"qi-checkbox",checked:v,disabled:c,onChange:e=>{b(e.target.checked);},"data-testid":"qi-export-approved-only"}),(0,a.jsx)("span",{children:"Approved only"})]})]}),(0,a.jsxs)("div",{className:"qi-export-controls",children:[(0,a.jsxs)("div",{className:"qi-field qi-export-format",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Format"}),(0,a.jsx)(nd,{triggerClassName:"qi-select",value:s,ariaLabel:"Export",disabled:c,ariaDescribedBy:y?"qi-export-connector-hint":void 0,menuTitle:"Export",sections:[{options:cM.map(e=>({value:e.id,label:e.label}))}],onValueChange:e=>{o(e),h(null),p(null),g(null);}})]}),(0,a.jsx)("button",{type:"button",className:"qi-btn qi-btn-primary qi-export-action",disabled:c,onClick:()=>{w();},children:c?"Exporting…":y?"Preview":"Download"})]}),(0,a.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite",children:null!==f?`Downloaded ${f}`:null!==m?"Export preview ready below.":""}),y?(0,a.jsx)("p",{id:"qi-export-connector-hint",className:"qi-export-hint",role:"note","data-testid":"qi-export-connector-hint",children:(null==x?void 0:x.id)==="quality-center"?"Quality Center is preview-only. Configure a connector to enable live export.":"External target — preview only. Configure a connector to enable live export."}):null,null!==f?(0,a.jsx)("p",{className:"qi-export-success","data-testid":"qi-export-success",children:`Downloaded ${f}`}):null,null!==m?(0,a.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,a.jsx)("p",{className:"lk-alert",role:"alert","data-testid":"qi-export-error",children:u}):null]});}let cL="keiko.qi.reviewerLabel",cz="Set a reviewer label to review or edit candidates.";function cO(e){let{detail:t}=e;return(0,a.jsxs)("dl",{className:"qi-run-summary","aria-label":"Run summary",children:[(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Status"}),(0,a.jsx)("dd",{children:(0,a.jsx)(oQ,{status:t.status})})]}),(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Test cases"}),(0,a.jsx)("dd",{children:t.totals.candidates.toString()})]}),(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Findings"}),(0,a.jsx)("dd",{children:t.totals.findings.toString()})]}),(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Quality"}),(0,a.jsx)("dd",{children:(0,a.jsx)(o1,{score:t.qualityScore})})]}),(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Review"}),(0,a.jsx)("dd",{className:"qi-run-summary-review",children:oU[t.reviewState]})]}),(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Requested"}),(0,a.jsx)("dd",{children:oH(t.requestedAt)})]}),null!==t.completedAt?(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Completed"}),(0,a.jsx)("dd",{children:oH(t.completedAt)})]}):null]});}let cK={"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 cW(e){let{detail:t}=e,[n,l]=(0,i.useState)(20),r=t.findingRefs.length;if(0===r)return null;let s=t.findingRefs.slice(0,n);return(0,a.jsxs)("section",{className:"qi-run-findings","aria-label":"Findings",children:[(0,a.jsxs)("h3",{className:"qi-col-subtitle",children:["Findings",(0,a.jsx)("span",{className:"qi-col-count",children:r.toString()})]}),(0,a.jsx)("ul",{className:"qi-finding-list","aria-label":"Findings list",children:s.map(e=>{var t;return(0,a.jsxs)("li",{className:"qi-finding-item",children:[(0,a.jsxs)("div",{className:"qi-finding-header",children:[(0,a.jsx)("span",{className:"qi-finding-kind",children:null!=(t=cK[e.kind])?t:e.kind}),(0,a.jsx)(o0,{severity:e.severity})]}),(0,a.jsx)("p",{className:"qi-finding-summary",children:e.summaryRedacted})]},e.id);})}),n<r?(0,a.jsxs)("button",{type:"button",className:"qi-btn qi-btn-secondary qi-show-more",onClick:()=>{l(e=>e+20);},children:["Show more findings (",(r-n).toString()," remaining)"]}):null]});}let cB={covered:"Covered","weakly-covered":"Weakly covered",uncovered:"Uncovered"},cU={covered:"qi-cov-covered","weakly-covered":"qi-cov-weak",uncovered:"qi-cov-uncovered"},c_={uncovered:0,"weakly-covered":1,covered:2};function cV(e){let{detail:t}=e,[n,l]=(0,i.useState)(20),{total:r,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)=>c_[e.status]-c_[t.status])};},[t.coverageByAtom]);if(0===r)return null;let c=o.slice(0,n);return(0,a.jsxs)("section",{className:"qi-coverage-panel","aria-label":"Coverage",children:[(0,a.jsxs)("h3",{className:"qi-col-subtitle",children:["Coverage",(0,a.jsxs)("span",{className:"qi-badge qi-badge-default","aria-label":`Coverage: ${t.coveragePercentage.toFixed(0)} percent, ${s.toString()} of ${r.toString()} requirements covered`,"data-testid":"qi-coverage-pct",children:[t.coveragePercentage.toFixed(0),"%"]})]}),(0,a.jsx)("p",{className:"qi-coverage-summary","data-testid":"qi-coverage-summary",children:`${s.toString()} of ${r.toString()} requirements covered \xb7 ${o.length.toString()} gap${1===o.length?"":"s"}`}),o.length>0?(0,a.jsxs)("section",{className:"qi-coverage-gaps","aria-label":"Gap radar",children:[(0,a.jsx)("h4",{className:"qi-col-subtitle",children:`Gap radar (${o.length.toString()})`}),(0,a.jsx)("ul",{className:"qi-coverage-gap-list","aria-label":"Uncovered and weakly covered atoms",children:c.map(e=>{let t=cB[e.status],n=cU[e.status],l=e.requirementExcerptRedacted;return(0,a.jsxs)("li",{className:"qi-coverage-gap-item","aria-label":void 0===l?`Atom ${e.atomId}: ${t}`:`Requirement "${l}" (atom ${e.atomId}): ${t}`,children:[(0,a.jsxs)("span",{className:"qi-coverage-gap-req",children:[void 0===l?null:(0,a.jsx)("span",{className:"qi-coverage-gap-text","data-testid":"qi-coverage-gap-text",children:l}),(0,a.jsx)("span",{className:"qi-coverage-atom-id qi-monospace",children:e.atomId})]}),(0,a.jsx)("span",{className:`qi-badge ${n}`,"aria-hidden":"true",children:t}),(0,a.jsx)("span",{className:"qi-sr-only",children:t})]},e.atomId);})}),n<o.length?(0,a.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 cJ(e){let{detail:t}=e,n=(0,i.useId)();return t.drift.reCheckSupported?(0,a.jsxs)("section",{className:"qi-drift-panel","aria-label":"Drift detection",children:[(0,a.jsxs)("div",{className:"qi-drift-head",children:[(0,a.jsx)("h3",{className:"qi-col-subtitle",children:"Living tests"}),(0,a.jsx)("button",{type:"button",className:"qi-btn qi-btn-secondary","aria-disabled":"true","aria-describedby":n,"data-testid":"qi-drift-recheck-unavailable",onClick:e=>{e.preventDefault();},children:"Re-check drift"})]}),(0,a.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 cH(e){let{runId:t,connectedSources:n,onRegenerated:l,fetchDetailImpl:r=oT,reviewImpl:s=oq,editImpl:o=oL,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),[x,y]=(0,i.useState)(null),[j,w]=(0,i.useState)(""),[k,N]=(0,i.useState)(!1),S=(0,i.useId)(),C=(0,i.useId)(),[I,R]=(0,i.useState)(""),$=(0,i.useRef)(0),E=(0,i.useRef)(0),A=(0,i.useCallback)(async()=>{let e=E.current+1;E.current=e,h(!0),g(null);try{let n=await r(t);E.current===e&&p(n);}catch(t){E.current===e&&g(oJ(t));}finally{E.current===e&&h(!1);}},[r,t]);(0,i.useEffect)(()=>{A();},[A]),(0,i.useEffect)(()=>{w(function(){try{var e;return null!=(e=window.localStorage.getItem(cL))?e:"";}catch{return"";}}()),N(!0);},[]),(0,i.useEffect)(()=>{if(k)try{window.localStorage.setItem(cL,j);}catch{}},[j,k]);let F=j.trim(),T=F.length>0,D=(0,i.useCallback)((e,n)=>{T&&null===x&&(y({candidateId:e,action:n}),(async()=>{b(null);try{var l,a;await s(t,n,e,F),await A();let i=oU["approve"===n?"approved":"reject"===n?"rejected":"request-changes"===n?"changes-requested":"open"],r=null!=(l=null==u||null==(a=u.candidates.find(t=>t.id===e))?void 0:a.title)?l:e;$.current+=1,R(`Candidate "${r}" marked ${i}. (${$.current.toString()})`);}catch(e){b(oJ(e));}finally{y(null);}})());},[T,x,s,t,F,A,u]),M=(0,i.useCallback)(async(e,n)=>{if(!T)throw Error(cz);await o(t,e,n,F),await A();},[o,T,t,F,A]);return(0,a.jsxs)("div",{className:"qi-run-card","data-testid":"qi-run-card",children:[(0,a.jsx)("header",{className:"qi-run-card-head",children:(0,a.jsx)("span",{className:"qi-run-id qi-monospace",title:t,role:"heading","aria-level":2,"aria-label":`Quality Intelligence run ${t}`,children:t})}),(0,a.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,a.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite","data-testid":"qi-review-announce",children:I}),(0,a.jsx)("div",{className:"qi-run-card-body","aria-busy":m,children:m&&null===u?(0,a.jsx)(o6,{}):null!==f?(0,a.jsx)(o8,{message:f,onRetry:()=>void A()}):null===u?(0,a.jsx)("div",{className:"lk-empty",children:(0,a.jsx)("p",{className:"lk-empty-body",children:"Run not found."})}):(0,a.jsxs)(a.Fragment,{children:[null!==v?(0,a.jsxs)("div",{className:"lk-alert qi-action-error",role:"alert","data-testid":"qi-action-error",children:[v,(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>{b(null);},children:"Dismiss"})]}):null,(0,a.jsxs)("section",{className:"qi-run-governance","aria-label":"Review governance",children:[(0,a.jsxs)("label",{className:"qi-field",htmlFor:`qi-reviewer-label-${t}`,children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Reviewer label"}),(0,a.jsx)("input",{id:`qi-reviewer-label-${t}`,className:"qi-input qi-run-governance-input",value:j,placeholder:"Required for review and edit actions","aria-invalid":!T,"aria-describedby":T?S:`${S} ${C}`,onChange:e=>{w(e.target.value);}})]}),(0,a.jsx)("p",{id:S,className:"qi-run-governance-help",children:"Used for QI review and edit audit entries."}),(0,a.jsx)("p",{id:C,className:"qi-run-governance-warning",role:"status","aria-live":"polite",children:T?"":cz})]}),(0,a.jsx)(cO,{detail:u}),(0,a.jsx)(cW,{detail:u}),(0,a.jsx)(cV,{detail:u}),void 0!==n&&n.length>0?(0,a.jsx)(cT,{runId:t,connectedSources:n,onRegenerated:l,reCheckImpl:c,regenerateImpl:d}):(0,a.jsx)(cJ,{detail:u}),(0,a.jsxs)("section",{className:"qi-run-cases","aria-label":"Generated test cases",children:[(0,a.jsxs)("div",{className:"qi-run-cases-head",children:[(0,a.jsxs)("h3",{className:"qi-col-subtitle",children:["Test cases",(0,a.jsx)("span",{className:"qi-col-count",children:u.candidates.length.toString()})]}),u.candidates.length>0?(0,a.jsx)(cq,{runId:t}):null]}),(0,a.jsx)(c$,{candidates:u.candidates,onReview:D,pendingReview:x,onEdit:M,actionsDisabled:!T,actionsDisabledReason:cz})]})]})})]});}let cY={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 cX(e){let{shape:t,color:n,animated:l,highContrast:i}=e,r=["rb-edge-badge-icon",l?"rb-edge-badge-icon--processing":"",i?"rb-edge-badge-icon--high-contrast":""].filter(e=>e.length>0).join(" "),s=i?2:1.5,o={width:12,height:12,viewBox:"0 0 12 12","aria-hidden":!0,fill:"currentColor",className:r,style:{color:n}};switch(t){case"hollow-circle":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("circle",{cx:"6",cy:"6",r:"4.5",fill:"none",stroke:"currentColor",strokeWidth:s})});case"clock":return(0,a.jsxs)("svg",{...o,children:[(0,a.jsx)("circle",{cx:"6",cy:"6",r:"4.5",fill:"none",stroke:"currentColor",strokeWidth:s}),(0,a.jsx)("path",{d:"M6 3v3l2 1",stroke:"currentColor",strokeWidth:s,strokeLinecap:"round",fill:"none"})]});case"filled-circle":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("circle",{cx:"6",cy:"6",r:"5"})});case"spinning-circle":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("circle",{cx:"6",cy:"6",r:"4.5",fill:"none",stroke:"currentColor",strokeWidth:s,strokeDasharray:"8 4"})});case"check":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("path",{d:"M2 6l3 3 5-5",stroke:"currentColor",strokeWidth:i?2.2:1.8,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})});case"triangle-exclamation":return(0,a.jsxs)("svg",{...o,children:[(0,a.jsx)("path",{d:"M6 1 L11 10 L1 10 Z",fill:"currentColor"}),(0,a.jsx)("path",{d:"M6 5v2.5",stroke:"var(--card)",strokeWidth:s,strokeLinecap:"round",fill:"none"}),(0,a.jsx)("circle",{cx:"6",cy:"9",r:"0.7",fill:"var(--card)"})]});case"filled-square":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("rect",{x:"1.5",y:"1.5",width:"9",height:"9",rx:"1.5"})});case"broken-line":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("path",{d:"M1 6h2.5l1.5-2 2 4 1.5-2H11",stroke:"currentColor",strokeWidth:s,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})});case"stacked-lines":return(0,a.jsxs)("svg",{...o,children:[(0,a.jsx)("rect",{x:"2",y:"2.5",width:"8",height:"1.5",rx:"0.75"}),(0,a.jsx)("rect",{x:"2",y:"5.25",width:"8",height:"1.5",rx:"0.75"}),(0,a.jsx)("rect",{x:"2",y:"8",width:"8",height:"1.5",rx:"0.75"})]});}}function cG(e){let{state:t}=e,n={width:10,height:10,viewBox:"0 0 10 10","aria-hidden":!0,fill:"currentColor"};switch(t){case"draft":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("circle",{cx:"5",cy:"5",r:"4",fill:"none",stroke:"currentColor",strokeWidth:"1.5"})});case"active":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("circle",{cx:"5",cy:"5",r:"4.5"})});case"archived":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("rect",{x:"1",y:"1",width:"8",height:"8",rx:"1"})});case"superseded":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("path",{d:"M2 5h6M6 3l2 2-2 2",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})});case"revoked":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("path",{d:"M2 2l6 6M8 2L2 8",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",fill:"none"})});case"blocked":return(0,a.jsxs)("svg",{...n,children:[(0,a.jsx)("rect",{x:"1",y:"1",width:"8",height:"8",rx:"1"}),(0,a.jsx)("path",{d:"M5 3v3",stroke:"var(--card)",strokeWidth:"1.5",strokeLinecap:"round",fill:"none"}),(0,a.jsx)("circle",{cx:"5",cy:"7.5",r:"0.6",fill:"var(--card)"})]});case"stale":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("rect",{x:"1",y:"1",width:"8",height:"8",rx:"1",fill:"none",stroke:"currentColor",strokeWidth:"1.5"})});}}function cQ(e){var t;let{type:n,lifecycle:l,activity:r,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=cY[r])?t:cY.inactive,f=lF[n],g=null!=c?c:p,v="high-throughput"===r&&void 0!==s?`${h.label} (${String(s)})`:h.label,b=`${f.displayName} — ${h.ariaDescription}`,x=h.animated&&o,y=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,a.jsx)("span",{role:"status","aria-live":"polite","aria-atomic":"true",className:`rb-edge-badge ${u}`.trim(),"data-activity-state":r,"data-high-contrast":g?"true":void 0,children:void 0!==d?(0,a.jsxs)("button",{type:"button",className:"rb-edge-badge-btn",style:y,"aria-label":b,onClick:d,children:[(0,a.jsx)("span",{"aria-hidden":"true",children:(0,a.jsx)(cX,{shape:h.iconShape,color:h.textColor,animated:x,highContrast:g})}),(0,a.jsx)("span",{className:"visually-hidden",children:h.ariaDescription}),(0,a.jsx)("span",{"aria-hidden":"true",className:"rb-edge-badge-label",children:v}),(0,a.jsx)("span",{className:"rb-edge-badge-type",children:f.displayName}),(0,a.jsx)(cG,{state:l})]}):(0,a.jsxs)("span",{className:"rb-edge-badge-static",style:y,"aria-label":b,children:[(0,a.jsx)("span",{"aria-hidden":"true",children:(0,a.jsx)(cX,{shape:h.iconShape,color:h.textColor,animated:x,highContrast:g})}),(0,a.jsx)("span",{className:"visually-hidden",children:h.ariaDescription}),(0,a.jsx)("span",{"aria-hidden":"true",className:"rb-edge-badge-label",children:v}),(0,a.jsx)("span",{className:"rb-edge-badge-type",children:f.displayName}),(0,a.jsx)(cG,{state:l})]})});}let cZ="keiko.relationships.density",c0={minimal:5,standard:25,dense:512};function c1(){try{let e=window.localStorage.getItem(cZ);if("minimal"===e||"standard"===e||"dense"===e)return e;}catch{}return"minimal";}function c2(e,t){return void 0===e||0===e.length?[]:e.split(",").map(e=>e.trim()).filter(e=>t.includes(e));}function c4(e){return{types:c2(e.relType,lE),lifecycles:c2(e.relLifecycle,lA),activities:c2(e.relActivity,["inactive","queued","active","processing","completed","failed","blocked","degraded","high-throughput"]),srcKinds:c2(e.relSrcKind,lR),tgtKinds:c2(e.relTgtKind,lR)};}let c3={"high-throughput":0,processing:1,active:2,blocked:3,failed:4,degraded:5,queued:6,completed:7,inactive:8};function c5(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 c6(e){var t,n,l,r,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,x]=(0,i.useState)(()=>{let e=d.relDensity;return"minimal"===e||"standard"===e||"dense"===e?e:c1();}),[y,j]=(0,i.useState)(!1),[w,k]=(0,i.useState)([]),[N,S]=(0,i.useState)(!1),[C,I]=(0,i.useState)(null),[R,$]=(0,i.useState)(!1),E=(0,i.useRef)(null),A=(0,i.useRef)(null),[F,T]=(0,i.useState)(null!=(t=d.relType)?t:""),D=(0,i.useRef)(null),M=(0,i.useCallback)(e=>{x(e),m({relDensity:e});try{window.localStorage.setItem(cZ,e);}catch{}},[m]);(0,i.useEffect)(()=>{let e=d.relDensity;"minimal"===e||"standard"===e||"dense"===e?x(e):x(c1());},[d.relDensity]),(0,i.useEffect)(()=>{var e;T(null!=(e=d.relType)?e:"");},[d.relType]);let P=(0,i.useCallback)(async()=>{I(null),S(!0);try{let e=c4(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,i=await lO({lifecycle:t,type:n,sourceKind:l,targetKind:a,limit:c0[b]});k(i.entries),$(i.truncated);}catch(e){I(e instanceof lM?e.message:lD);}finally{S(!1);}},[d,b]);(0,i.useEffect)(()=>{P();},[P]),(0,i.useEffect)(()=>{let e=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(),j(e=>!e);else if("Escape"===e.key)j(!1);else if("/"===e.key){var n;e.preventDefault(),null==(n=A.current)||n.focus();}}}},[]);let q=(0,i.useCallback)(e=>{let t=e.target.value;T(t),null!==D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{m({relType:t.length>0?t:void 0});},250);},[m]),L=(0,i.useMemo)(()=>{var e;let t=c4(d),n=(null!=(e=d.relType)?e:"").split(",").map(e=>e.trim().toLowerCase()).filter(e=>e.length>0),l=0===n.length?w:w.filter(e=>n.some(t=>e.type.toLowerCase().includes(t)));return(0===t.activities.length?l:l.filter(e=>t.activities.includes(c5(e.id,e.lifecycle,h)))).slice(0,c0[b]);},[h,b,d,w]),z=L.slice(0,25),O=L.slice(25),K=O.length,W=K>0?function(e,t){let n=new Map();for(let a of e){var l;let e=c5(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=c3[e[0]])?n:Number.MAX_SAFE_INTEGER)-(null!=(l=c3[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):"",B=R?`Showing first ${String(L.length)} relationships — more available.`:`Showing ${String(L.length)} relationship${1!==L.length?"s":""}.`,U=(null!=(n=d.relType)?n:"").trim().length>0||(null!=(l=d.relActivity)?l:"").trim().length>0||(null!=(r=d.relSrcKind)?r:"").trim().length>0||(null!=(s=d.relTgtKind)?s:"").trim().length>0||(null!=(o=d.relLifecycle)?o:"").trim().length>0&&"active"!==d.relLifecycle,_=c2(d.relLifecycle,lA),V=1===_.length&&null!=(c=_[0])?c:"active";return(0,a.jsxs)("div",{ref:E,className:"tw-pad","data-testid":"relationship-list-panel","data-relationship-focus":y?"true":void 0,children:[(0,a.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,a.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,a.jsx)("button",{type:"button",className:"arun-btn","aria-pressed":y,onClick:()=>j(e=>!e),title:"Toggle focus mode (F)","aria-label":`Focus mode: ${y?"on":"off"}`,style:{minWidth:24,minHeight:24},children:"Focus"})]}),(0,a.jsxs)("div",{style:{marginBottom:8},children:[(0,a.jsx)("label",{htmlFor:"rel-type-filter",className:"rb-row-k",style:{display:"block",marginBottom:2,fontSize:11,fontWeight:600},children:"Filter by type (press / to focus)"}),(0,a.jsx)("input",{id:"rel-type-filter",ref:A,type:"text",list:"rel-type-filter-options",value:F,onChange:q,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,a.jsx)("datalist",{id:"rel-type-filter-options",children:lE.map(e=>(0,a.jsx)("option",{value:e},e))})]}),(0,a.jsxs)("div",{style:{marginBottom:8},children:[(0,a.jsx)("label",{htmlFor:"rel-lifecycle-filter",className:"rb-row-k",style:{display:"block",marginBottom:2,fontSize:11,fontWeight:600},children:"Lifecycle"}),(0,a.jsx)("select",{id:"rel-lifecycle-filter",value:V,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:lA.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]}),(0,a.jsx)("div",{"aria-live":"polite","aria-atomic":"true",className:"visually-hidden",children:B}),R&&(0,a.jsx)("div",{"data-testid":"list-truncation-note",style:{fontSize:11,color:"var(--fg-muted)",marginBottom:6},children:B}),null!==C&&(0,a.jsxs)("div",{className:"lk-alert",role:"alert","aria-live":"assertive",children:[(0,a.jsx)("span",{children:C}),(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>void P(),children:"Retry"})]}),N&&0===w.length&&(0,a.jsx)("div",{role:"status",className:"insp-empty",children:"Loading…"}),(!N||w.length>0)&&null===C&&0===L.length&&(0,a.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.'}),L.length>0&&(0,a.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=c5(e.id,e.lifecycle,h),i=y&&n,r=y&&!n;return(0,a.jsx)("div",{role:"listitem",style:{opacity:r?.4:1},children:(0,a.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":i?"true":void 0,className:"rel-row",children:[(0,a.jsx)(cQ,{type:e.type,lifecycle:e.lifecycle,activity:l,throughputCount:f.get(e.id),animateOverride:g,highContrast:v}),(0,a.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column"},children:[(0,a.jsxs)("span",{style:{fontSize:12,color:"var(--fg)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[e.source.kind," → ",e.target.kind]}),(0,a.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,a.jsx)("span",{style:{fontSize:11,color:"var(--fg-muted)",whiteSpace:"nowrap"},children:e.lifecycle})]})},e.id);}),K>0&&(0,a.jsxs)("div",{role:"listitem","aria-live":"polite",style:{fontSize:12,color:"var(--fg-muted)",padding:"4px 6px"},"data-testid":"animation-cap-aggregate",children:["+",String(K)," more: ",W]})]})]});}function c8(){return(0,a.jsx)("p",{role:"note",style:{margin:"4px 0 0",fontSize:11,color:"var(--fg-muted)",borderLeft:"2px solid var(--warn)",paddingLeft:8},children:"The walk hit a bound before the graph was fully traversed; more objects may be affected than shown."});}function c7(e){let{title:t,help:n,report:l,onSelectRelationship:i}=e;if(null===l)return(0,a.jsxs)("section",{style:{marginBottom:12},children:[(0,a.jsx)("div",{className:"rb-section-label",role:"heading","aria-level":4,children:t}),(0,a.jsx)("p",{style:{fontSize:12,color:"var(--fg-muted)",margin:0},children:"Loading…"})]});let r=l.endpoints.slice(1),s=l.relationships,o=r.slice(0,50),c=s.slice(0,50);return(0,a.jsxs)("section",{style:{marginBottom:12},"aria-label":t,children:[(0,a.jsxs)("div",{className:"rb-section-label",role:"heading","aria-level":4,children:[t,(0,a.jsx)("span",{className:"rb-count","aria-hidden":"true",children:r.length})]}),(0,a.jsx)("p",{style:{margin:"0 0 6px",fontSize:11,color:"var(--fg-muted)"},children:n}),0===r.length?(0,a.jsx)("p",{style:{fontSize:12,color:"var(--fg-muted)",margin:0},children:"No further objects are affected in this direction."}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("ul",{style:{listStyle:"none",margin:0,padding:0},children:o.map(e=>(0,a.jsx)("li",{className:"rb-row",style:{fontSize:12},children:(0,a.jsx)("span",{className:"mono",children:`${e.kind}: ${e.id}`})},`${e.kind}:${e.id}`))}),r.length>o.length&&(0,a.jsxs)("p",{role:"note",style:{margin:"4px 0 0",fontSize:11,color:"var(--fg-muted)"},children:["Showing the first ",String(50)," of ",String(r.length)," ","objects."]}),s.length>0&&(0,a.jsxs)("details",{style:{marginTop:6},children:[(0,a.jsxs)("summary",{style:{fontSize:11,color:"var(--fg-muted)",cursor:"pointer"},children:[String(s.length)," relationship",1===s.length?"":"s"," on the path"]}),(0,a.jsx)("ul",{style:{listStyle:"none",margin:"4px 0 0",padding:0},children:c.map(e=>(0,a.jsx)("li",{style:{marginBottom:2},children:(0,a.jsxs)("button",{type:"button",className:"arun-btn ghost",onClick:()=>i(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,a.jsx)("span",{className:"mono",children:e.type}),(0,a.jsxs)("span",{style:{color:"var(--fg-muted)"},children:[e.source.id," → ",e.target.id]})]})},e.id))})]})]}),l.truncated&&(0,a.jsx)(c8,{})]});}function c9(e){let{outgoing:t,incoming:n,onSelectRelationship:l}=e;return(0,a.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,a.jsx)(c7,{title:"Downstream impact",help:"Objects this relationship's target leads to. Deleting or revoking here may affect them.",report:t,onSelectRelationship:l}),(0,a.jsx)(c7,{title:"Upstream impact",help:"Objects that depend on this relationship's source.",report:n,onSelectRelationship:l})]});}let de={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)"}},dt={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 dn(e){let{lines:t=3}=e;return(0,a.jsx)("div",{className:"rb-rows","aria-hidden":"true",children:Array.from({length:t},(e,t)=>(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",style:{background:"var(--inset)",borderRadius:3,width:"40%",display:"block",height:12}}),(0,a.jsx)("span",{className:"rb-row-v",style:{background:"var(--inset)",borderRadius:3,width:"55%",display:"block",height:12}})]},t))});}function dl(e){let{children:t,style:n}=e;return(0,a.jsx)("div",{className:"rb-section-label",role:"heading","aria-level":3,style:n,children:t});}function da(e){let{rel:t}=e,n=lF[t.type],l=`${t.source.kind} ${t.type} ${t.target.kind}`;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"insp-top",children:[(0,a.jsx)("span",{className:"chip",style:{fontSize:11},children:t.type}),(0,a.jsx)("span",{className:"insp-title",children:l})]}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Semantics"}),(0,a.jsx)("span",{className:"rb-row-v",children:n.semantics})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Cardinality"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:n.cardinality})]})]})]});}function di(e){let{label:t,kind:n,id:l}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(dl,{children:[t," endpoint"]}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Kind"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:n})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Reference"}),(0,a.jsx)("span",{className:"rb-row-v mono","aria-label":`Reference id: ${l}`,children:l})]})]})]});}function dr(e){var t;let{lifecycle:n}=e,l=`lifecycle-desc-${n}`,i=null!=(t=de[n])?t:de.draft;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(dl,{children:"Lifecycle status"}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"State"}),(0,a.jsx)("span",{className:"rb-row-v",children:(0,a.jsx)("span",{className:"chip",style:{background:i.bg,color:i.fg},"aria-describedby":l,children:n})})]}),(0,a.jsx)("div",{className:"rb-row",children:(0,a.jsx)("span",{id:l,className:"rb-row-v",style:{color:"var(--fg-muted)",fontSize:12},children:dt[n]})})]})]});}function ds(e){let{type:t,lifecycle:n,activity:l,throughputCount:i,animateBadges:r,highContrast:s,transitions:o,densityMode:c}=e,d=o.slice(0,"minimal"===c?3:5);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(dl,{children:"Activity"}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Current state"}),(0,a.jsx)("span",{className:"rb-row-v",children:(0,a.jsx)(cQ,{type:t,lifecycle:n,activity:l,throughputCount:i,animateOverride:r,highContrast:s})})]}),d.length>0&&(0,a.jsxs)("div",{className:"rb-row",style:{flexDirection:"column",gap:"var(--space-2)",alignItems:"flex-start"},children:[(0,a.jsx)("span",{className:"rb-row-k",style:{marginBottom:4},children:"Recent transitions"}),d.map((e,t)=>(0,a.jsxs)("div",{style:{fontSize:12,color:"var(--fg-muted)",display:"flex",gap:"var(--space-4)"},children:[(0,a.jsxs)("span",{className:"mono",children:[e.from," → ",e.to]}),(0,a.jsx)("time",{dateTime:new Date(e.occurredAt).toISOString(),style:{color:"var(--fg-faint)"},children:new Date(e.occurredAt).toLocaleString()})]},t))]})]})]});}function dc(){return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(dl,{children:"Authority status"}),(0,a.jsx)("div",{className:"rb-rows",children:(0,a.jsx)("div",{className:"rb-row","data-testid":"authority-disclaimer",children:(0,a.jsx)("span",{className:"rb-row-v",style:{color:"var(--fg-muted)",fontStyle:"italic"},children:"Relationship: governance only. No model/tool/file/workflow authority granted."})})})]});}function dd(e){let{auditRows:t,loading:n,error:l,onRetry:i,onLoadMore:r,hasMore:s}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(dl,{children:"Audit history"}),n&&(0,a.jsx)(dn,{lines:3}),null!==l&&(0,a.jsxs)("div",{className:"lk-alert",role:"alert","aria-live":"assertive",children:[(0,a.jsx)("span",{children:l}),(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:i,children:"Retry"})]}),!n&&null===l&&0===t.length&&(0,a.jsx)("div",{className:"rb-rows",children:(0,a.jsx)("div",{className:"rb-row",children:(0,a.jsx)("span",{className:"rb-row-v",style:{color:"var(--fg-muted)"},children:"No audit events for this relationship yet."})})}),!n&&t.length>0&&(0,a.jsxs)("div",{className:"rb-rows",children:[t.map((e,t)=>(0,a.jsxs)("div",{className:"rb-row",style:{flexDirection:"column",alignItems:"flex-start",gap:"var(--space-1)"},children:[(0,a.jsxs)("span",{className:"rb-row-k mono",style:{fontSize:11},children:[e.from," → ",e.to]}),(0,a.jsx)("time",{dateTime:new Date(e.occurredAt).toISOString(),style:{color:"var(--fg-faint)",fontSize:11},children:new Date(e.occurredAt).toLocaleString()})]},t)),s&&(0,a.jsx)("div",{className:"rb-row",children:(0,a.jsx)("button",{type:"button",className:"rb-row-v",style:{color:"var(--accent)",fontSize:12,background:"none",border:"none",padding:0,cursor:"pointer",minHeight:24,minWidth:24},onClick:r,"aria-label":"Load more audit events",children:"Load more"})})]})]});}function du(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,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(dl,{children:"Evidence references"}),0===l.length?(0,a.jsx)("p",{style:{fontSize:12,color:"var(--fg-muted)",margin:"0 0 4px"},"data-testid":"evidence-empty",children:"No evidence references for this relationship."}):(0,a.jsx)("div",{className:"rb-rows",children:l.map(e=>(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Evidence run"}),(0,a.jsx)("span",{className:"rb-row-v mono","aria-label":`Evidence run reference ${e}`,title:e,children:e})]},e))})]});}function dp(e){let{relationshipId:t,forwardCount:n,reverseCount:l,outgoing:i,incoming:r,expanded:s,onToggle:o,onSelectRelationship:c}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(dl,{children:"Impact summary"}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Forward dependencies"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:null===n?"—":String(n)})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Reverse dependencies"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:null===l?"—":String(l)})]}),(0,a.jsx)("div",{className:"rb-row",children:(0,a.jsx)("button",{type:"button",className:"arun-btn",onClick:o,"aria-expanded":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,a.jsx)("div",{id:"rb-impact-detail",children:(0,a.jsx)(c9,{outgoing:i,incoming:r,onSelectRelationship:c})})]});}function dm(e){let{codes:t,messages:n,deniedAt:l}=e;return 0===t.length?null:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(dl,{children:"Denial reason"}),(0,a.jsxs)("div",{className:"lk-alert",role:"status","aria-live":"polite","data-testid":"denial-section",children:[t.map((e,l)=>{var i;return(0,a.jsxs)("div",{style:{marginBottom:8*(l<t.length-1)},children:[(0,a.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--fg-muted)",marginBottom:2},children:e}),(0,a.jsx)("div",{style:{fontSize:13,color:"var(--fg)"},children:null!=(i=n[l])?i:e})]},e);}),void 0!==l&&(0,a.jsxs)("div",{style:{fontSize:11,color:"var(--fg-faint)",marginTop:6},children:["Denied at ",(0,a.jsx)("time",{dateTime:l,children:l})]})]})]});}function dh(e){return null==e||0===e.length?null:{codes:e.map(e=>e.code),messages:e.map(e=>e.message)};}function df(e){let{rel:t,onReconnect:n,onArchive:l,onRevoke:i,onViewImpact:r,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,a.jsxs)("div",{style:{display:"flex",gap:"var(--space-3)",flexWrap:"wrap",marginTop:8},children:[(0,a.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,a.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,a.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?i:void 0,style:{color:p?"var(--danger)":void 0},children:"Revoke"}),(0,a.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?r:void 0,children:"View impact"}),(0,a.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 dg(e){var t,n,l;let{relationshipId:r,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,x]=(0,i.useState)(!1),[y,j]=(0,i.useState)(null),[w,k]=(0,i.useState)(!1),[N,S]=(0,i.useState)(null),[C,I]=(0,i.useState)(null),[R,$]=(0,i.useState)(null),[E,A]=(0,i.useState)(null),[F,T]=(0,i.useState)(!1),D=null===R?null:R.relationships.length,M=null===E?null:E.relationships.length,[P,q]=(0,i.useState)(!1),L=(0,i.useRef)(null),z=(0,i.useRef)(0),O=(0,i.useCallback)(async e=>{let t=++z.current;j(null),x(!0),I(null),$(null),A(null),T(!1);let n=setTimeout(()=>{z.current===t&&q(!0);},500);L.current=n;try{let[n,l]=await Promise.all([lK(e),l_(e)]);if(z.current!==t)return;f(n),v(l);try{let[n,l]=await Promise.all([lU(e,{direction:"outgoing",maxDepth:3,maxRelationships:512}),lU(e,{direction:"incoming",maxDepth:3,maxRelationships:512})]);if(z.current!==t)return;$(n),A(l);}catch{}}catch(e){if(z.current!==t)return;j(e instanceof lM?e.message:lD);}finally{L.current===n?(clearTimeout(n),L.current=null):clearTimeout(n),z.current===t&&(x(!1),q(!1));}},[]);(0,i.useEffect)(()=>{if(null===r){z.current+=1,null!==L.current&&(clearTimeout(L.current),L.current=null),f(null),v(null),j(null),I(null),q(!1),x(!1);return;}return O(r),()=>{null!==L.current&&(clearTimeout(L.current),L.current=null);};},[r,O]);let K=(0,i.useCallback)(async e=>{if(null!==h){k(!0),S(null),I(null);try{let t=crypto.randomUUID(),{relationship:n}=await lW(h.id,{transition:{to:e}},String(h.etag),t);f(n),v(null),await O(h.id);}catch(e){S(e instanceof lM?e.message:"Mutation failed. Please retry."),I(e instanceof lM?dh(e.reasons):null);}finally{k(!1);}}},[h,O]),W=(0,i.useCallback)(()=>void K("draft"),[K]),B=(0,i.useCallback)(()=>void K("archived"),[K]),U=(0,i.useCallback)(async()=>{if(null!==h&&window.confirm(`Revoke relationship "${h.type}"? This cannot be undone.`)){k(!0),S(null),I(null);try{let e=crypto.randomUUID(),t=await lB(h.id,String(h.etag),e);f(t);}catch(e){S(e instanceof lM?e.message:"Revoke failed. Please retry."),I(e instanceof lM?dh(e.reasons):null);}finally{k(!1);}}},[h]),_=(0,i.useCallback)(()=>{T(e=>!e);},[]),V=(0,i.useCallback)(e=>{null==c||c(e);},[c]),J=(0,i.useRef)(null),H=(0,i.useCallback)(()=>{var e,t;null==(t=J.current)||null==(e=t.scrollIntoView)||e.call(t,{block:"start"});},[]);if(null===r)return(0,a.jsxs)("div",{className:"tw-pad","data-testid":"relationship-inspector-panel",children:[(0,a.jsx)(dl,{style:{marginTop:0},children:"Relationship"}),(0,a.jsx)("div",{className:"insp-empty","data-testid":"inspector-empty",children:"Select a relationship from the list to inspect it."}),(0,a.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 Y=dh(null==g?void 0:g.decision.reasons),X=null!=Y?Y:C,G=null!==X&&((null==h?void 0:h.lifecycle)==="blocked"||(null==h?void 0:h.lifecycle)==="revoked"||null!==C),Q=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",Z=null!==h?u.get(h.id):void 0;return(0,a.jsxs)("div",{className:"tw-pad","aria-busy":b,"data-testid":"relationship-inspector-panel",children:[null!==y&&(0,a.jsxs)("div",{className:"lk-alert",role:"alert","aria-live":"assertive",children:[(0,a.jsx)("span",{children:y}),(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>void O(r),children:"Retry"})]}),null!==N&&(0,a.jsxs)("div",{className:"lk-alert",role:"alert","aria-live":"assertive",children:[(0,a.jsx)("span",{children:N}),(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>S(null),children:"Dismiss"})]}),b&&P&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(dl,{style:{marginTop:0},children:"Relationship"}),(0,a.jsx)(dn,{lines:4}),(0,a.jsx)(dn,{lines:3})]}),!b&&null===y&&null===h&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(dl,{style:{marginTop:0},children:"Relationship"}),(0,a.jsx)("div",{className:"insp-empty","data-testid":"inspector-not-found",children:"This relationship is no longer available."}),(0,a.jsx)("div",{style:{fontSize:12,color:"var(--fg-muted)",marginTop:4},children:"It may have been deleted, retired by retention, or it never existed in this workspace."}),void 0!==o&&(0,a.jsx)("button",{type:"button",className:"arun-btn",style:{marginTop:8},onClick:o,children:"Clear focus"})]}),!b&&null!==h&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(dl,{style:{marginTop:0},children:"Relationship"}),(0,a.jsx)(da,{rel:h}),(0,a.jsx)(di,{label:"Source",kind:h.source.kind,id:h.source.id}),(0,a.jsx)(di,{label:"Target",kind:h.target.kind,id:h.target.id}),(0,a.jsx)(dr,{lifecycle:h.lifecycle}),(0,a.jsx)(ds,{type:h.type,lifecycle:h.lifecycle,activity:Q,throughputCount:Z,animateBadges:p,highContrast:m,transitions:null!=(n=null==g?void 0:g.lifecycle)?n:[],densityMode:s}),(0,a.jsx)(dc,{}),(0,a.jsx)(dd,{auditRows:null!=(l=null==g?void 0:g.lifecycle)?l:[],loading:!1,error:null,onRetry:()=>void O(r),onLoadMore:()=>{},hasMore:!1}),(0,a.jsx)("div",{ref:J,children:(0,a.jsx)(du,{rel:h})}),(0,a.jsx)(dp,{relationshipId:h.id,forwardCount:D,reverseCount:M,outgoing:R,incoming:E,expanded:F,onToggle:_,onSelectRelationship:V}),G&&null!==X&&(0,a.jsx)(dm,{codes:X.codes,messages:X.messages}),(0,a.jsx)(df,{rel:h,onReconnect:W,onArchive:B,onRevoke:()=>void U(),onViewImpact:_,onViewEvidence:H,mutating:w})]})]});}let dv=new Set(["kind","id","state","timestamp","count"]);function db(e){return`${e.kind}: ${e.id}`;}function dx(e){let{category:t}=e;return(0,a.jsxs)("p",{role:"note",style:{margin:"4px 0 0",fontSize:11,color:"var(--fg-muted)",borderLeft:"2px solid var(--warn)",paddingLeft:8},children:["More ",t," exist than the bounded query returned. Resolve the listed items, then re-run the health check."]});}function dy(e){let{category:t,onSelectRelationship:n}=e;if(0===t.items.length)return null;let l=t.items.slice(0,50),i=t.items.length-l.length;return(0,a.jsxs)("section",{"aria-label":`${t.label} (${String(t.items.length)})`,style:{marginBottom:14},children:[(0,a.jsxs)("div",{className:"rb-section-label",role:"heading","aria-level":3,children:[t.label,(0,a.jsx)("span",{className:"rb-count","aria-hidden":"true",children:t.items.length})]}),(0,a.jsx)("p",{style:{margin:"0 0 6px",fontSize:11,color:"var(--fg-muted)"},children:t.help}),(0,a.jsx)("ul",{style:{listStyle:"none",margin:0,padding:0},children:l.map(e=>(0,a.jsx)("li",{style:{marginBottom:2},children:(0,a.jsxs)("button",{type:"button",className:"arun-btn ghost",onClick:()=>n(e.id),"aria-label":`Inspect ${e.type} relationship from ${db(e.source)} to ${db(e.target)}, lifecycle ${e.lifecycle}`,style:{display:"flex",width:"100%",gap:6,alignItems:"center",textAlign:"left",fontSize:12},children:[(0,a.jsx)("span",{className:"mono",style:{color:"var(--fg)"},children:e.type}),(0,a.jsxs)("span",{style:{color:"var(--fg-muted)"},children:[db(e.source)," → ",db(e.target)]}),(0,a.jsx)("span",{className:"mono",style:{marginLeft:"auto",color:"var(--fg-muted)"},children:e.lifecycle})]})},e.id))}),i>0&&(0,a.jsxs)("p",{role:"note",style:{margin:"4px 0 0",fontSize:11,color:"var(--fg-muted)"},children:["Showing the first ",String(50)," of ",String(t.items.length),"."]}),t.truncated&&(0,a.jsx)(dx,{category:t.label.toLowerCase()})]});}function dj(e){let{findings:t}=e;if(0===t.orphanedEndpoints.length)return null;let n=t.orphanedEndpoints.slice(0,50);return(0,a.jsxs)("section",{"aria-label":`Orphaned endpoints (${String(t.orphanedEndpoints.length)})`,style:{marginBottom:14},children:[(0,a.jsxs)("div",{className:"rb-section-label",role:"heading","aria-level":3,children:["Orphaned endpoints",(0,a.jsx)("span",{className:"rb-count","aria-hidden":"true",children:t.orphanedEndpoints.length})]}),(0,a.jsx)("p",{style:{margin:"0 0 6px",fontSize:11,color:"var(--fg-muted)"},children:"Endpoints that participate in no live relationship."}),(0,a.jsx)("ul",{style:{listStyle:"none",margin:0,padding:0},children:n.map(e=>(0,a.jsx)("li",{className:"rb-row",style:{fontSize:12},children:(0,a.jsx)("span",{className:"mono",children:db(e)})},`${e.kind}:${e.id}`))}),t.orphanedEndpointsTruncated&&(0,a.jsx)(dx,{category:"orphaned endpoints"})]});}function dw(e){var t,n;let{onSelectRelationship:l}=e,[r,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 lV();s(e);}catch(e){u(e instanceof lM?e.message:"Could not load the graph health check.");}finally{c(!1);}},[]);return(0,i.useEffect)(()=>{p();},[p]),(0,a.jsxs)("div",{style:{padding:12,height:"100%",overflowY:"auto"},"aria-busy":o,children:[(0,a.jsxs)("header",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:10},children:[(0,a.jsx)("h2",{style:{margin:0,fontSize:13,fontWeight:600,color:"var(--fg)",flexGrow:1},children:"Graph health"}),(0,a.jsx)("button",{type:"button",className:"arun-btn",onClick:()=>void p(),"aria-label":"Re-run the graph health check",style:{minHeight:24},children:"Refresh"})]}),o&&(0,a.jsx)("p",{style:{fontSize:12,color:"var(--fg-muted)"},"aria-live":"polite",children:"Running health check…"}),null!==d&&(0,a.jsxs)("div",{className:"lk-alert",role:"alert",children:[d,(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>void p(),children:"Retry"})]}),!o&&null===d&&null!==r&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("p",{style:{fontSize:11,color:"var(--fg-faint)",margin:"0 0 10px"},children:["Checked at"," ",(0,a.jsx)("time",{dateTime:new Date(r.checkedAt).toISOString(),children:new Date(r.checkedAt).toLocaleString()}),"."]}),(0,a.jsx)("div",{className:"rb-rows",style:{marginBottom:14},children:lA.filter(e=>{var t;return(null!=(t=r.totals[e])?t:0)>0;}).map(e=>{var t;return(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:e}),(0,a.jsx)("span",{className:"rb-row-v mono",children:String(null!=(t=r.totals[e])?t:0)})]},e);})}),0===(t=r.findings).orphanedEndpoints.length+t.staleRelationships.length+t.blockedRelationships.length+t.failedRelationships.length+t.invalidReferences.length+t.cycleParticipants.length?(0,a.jsxs)("div",{className:"lk-empty",children:[(0,a.jsx)("p",{className:"lk-empty-title",children:"Healthy"}),(0,a.jsx)("p",{className:"lk-empty-body",children:"No relationship-graph defects were found."})]}):(0,a.jsxs)(a.Fragment,{children:[[{key:"invalid",label:"Invalid references",help:"An endpoint no longer resolves to a live workspace object.",items:(n=r.findings).invalidReferences,truncated:n.invalidReferencesTruncated},{key:"blocked",label:"Blocked",help:"A policy or endpoint state is blocking this relationship.",items:n.blockedRelationships,truncated:n.blockedRelationshipsTruncated},{key:"failed",label:"Failed (revoked)",help:"The relationship reached the revoked terminal state.",items:n.failedRelationships,truncated:n.failedRelationshipsTruncated},{key:"cycle",label:"Cycle participants",help:"These relationships take part in a dependency cycle.",items:n.cycleParticipants,truncated:n.cycleScanTruncated},{key:"stale",label:"Stale",help:"A health check flagged at least one endpoint as not currently live.",items:n.staleRelationships,truncated:n.staleRelationshipsTruncated}].map(e=>(0,a.jsx)(dy,{category:e,onSelectRelationship:l},e.key)),(0,a.jsx)(dj,{findings:r.findings})]})]})]});}let dk={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 dN(e){return"object"==typeof e&&null!==e&&!Array.isArray(e);}function dS(e){return"string"==typeof e&&e.length>0;}function dC(e,t,n){return void 0===n?{code:e,message:t}:{code:e,field:n,message:t};}function dI(e,t,n){return dN(e)?dS(e.kind)?dS(e.id)?!!dS(e.workspaceId)||(n.push(dC("denied/schema-version-unsupported",`${t}.workspaceId must be a non-empty string`,`${t}.workspaceId`)),!1):(n.push(dC("denied/schema-version-unsupported",`${t}.id must be a non-empty string`,`${t}.id`)),!1):(n.push(dC("denied/schema-version-unsupported",`${t}.kind must be a non-empty string`,`${t}.kind`)),!1):(n.push(dC("denied/schema-version-unsupported",`${t} must be an object`,t)),!1);}function dR(e,t,n){dS(e[t])||n.push(dC("denied/schema-version-unsupported",`${t} must be a non-empty string`,t));}function d$(e,t){let n=e.kind;return lR.includes(n)?null:dC("denied/schema-version-unsupported",`${t}.kind is not a known object kind`,`${t}.kind`);}function dE(e,t,n){"missing"===t?n.push(dC("source"===e?"denied/non-existent-source":"denied/non-existent-target",`${e} endpoint does not exist`,e)):"tombstoned"===t?n.push(dC("denied/endpoint-tombstoned",`${e} endpoint has been tombstoned`,e)):"retired"===t?n.push(dC("denied/endpoint-retired",`${e} endpoint has been retired`,e)):"unavailable"===t&&n.push(dC("denied/endpoint-unavailable",`${e} endpoint is unavailable`,e));}function dA(e,t){let n=e.kind;return l$.includes(n)?null:dC("denied/object-kind-not-yet-supported",`${t}.kind "${n}" is reserved for a future release`,`${t}.kind`);}function dF(){return{type:"reads-context",sourceKind:"workflow-run",sourceId:"",targetKind:"memory",targetId:"",summary:""};}let dT=new Set(["denied/path-not-contained","denied/cross-workspace","denied/payload-content-not-permitted"]);function dD(e){return(null==e?void 0:e.codes.some(e=>dT.has(e)))===!0;}function dM(e){let{onClose:t}=e,[n,l]=(0,i.useState)(dF),[r,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(!dN(e))return{errors:[dC("denied/schema-version-unsupported","relationship must be an object")]};let n=[];dR(e,"id",n),dR(e,"workspaceId",n),dR(e,"createdAt",n),dR(e,"updatedAt",n),(!("number"==typeof(t=e.etag)&&Number.isInteger(t)&&Number.isFinite(t))||e.etag<0)&&n.push(dC("denied/schema-version-unsupported","etag must be a non-negative finite integer","etag"));let l=dI(e.source,"source",n),a=dI(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,i=function(e,t,n){let l,a,i="1"!==e.schemaVersion?dC("denied/schema-version-unsupported",'schemaVersion must be the literal "1"',"schemaVersion"):null;if(i)return[i];let r=dS(l=e.type)?lE.includes(l)?null:dC("denied/schema-version-unsupported","type is not a known relationship type","type"):dC("denied/schema-version-unsupported","type must be a non-empty string","type");if(r)return[r];let s=d$(t,"source"),o=d$(n,"target");if(null!==s||null!==o){let e=[];return null!==s&&e.push(s),null!==o&&e.push(o),e;}let c=dS(a=e.lifecycleState)?lA.includes(a)?null:dC("denied/schema-version-unsupported","lifecycleState is not a known lifecycle state","lifecycleState"):dC("denied/schema-version-unsupported","lifecycleState must be a non-empty string","lifecycleState");return c?[c]:null;}(n,l,a);if(i)return{ok:!1,errors:i};let r=function(e){if(!(null==e?void 0:e.endpointResolver))return null;let t=[];return"missing"===e.endpointResolver.source&&dE("source",e.endpointResolver.source,t),"missing"===e.endpointResolver.target&&dE("target",e.endpointResolver.target,t),t;}(void 0);if(null!==r&&r.length>0)return{ok:!1,errors:r};let s=function(e,t,n,l){var a,i,r,s,o;let c,d,u,p,m,h,f=[],g=e.type,v=e.lifecycleState,b=dA(t,"source");b&&f.push(b);let x=dA(n,"target");x&&f.push(x),null===b&&null===x&&(a=t.kind,i=n.kind,"denied/source-kind-not-allowed"===(d=(c=lF[g]).validSourceKinds.includes(a)?c.validTargetKinds.includes(i)?null:"denied/target-kind-not-allowed":"denied/source-kind-not-allowed")?f.push(dC("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(dC("denied/target-kind-not-allowed",`target.kind "${n.kind}" is not permitted for type "${g}"`,"target.kind")));let y=(u=null==l?void 0:l.cardinalityCounts)?"produces-evidence"===g&&"number"==typeof u.producesEvidenceForSource&&u.producesEvidenceForSource>=1?dC("denied/cardinality-exceeded","produces-evidence already exists for this source workflow-run"):"starts-workflow"===g&&"number"==typeof u.startsWorkflowForTarget&&u.startsWorkflowForTarget>=1?dC("denied/cardinality-exceeded","starts-workflow already exists for this target workflow-run"):null:null;y&&f.push(y),(p=t.kind===n.kind&&t.id===n.id?dC("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?dC("denied/cycle-forbidden","depends-on reverse edge already exists for this endpoint pair"):null)&&f.push(m);let j=(r=e.workspaceId,t.workspaceId!==r||n.workspaceId!==r?dC("denied/cross-workspace","source and target must be in the relationship's workspace"):null);j&&f.push(j);let w=void 0===(h=null==l?void 0:l.previousLifecycleState)||dk[h].includes(v)?null:dC("denied/lifecycle-illegal-transition",`transition from ${h} to ${v} is not permitted`,"lifecycleState");for(let t of(w&&f.push(w),s=l,o=f,(null==s?void 0:s.endpointResolver)&&("missing"!==s.endpointResolver.source&&dE("source",s.endpointResolver.source,o),"missing"!==s.endpointResolver.target&&dE("target",s.endpointResolver.target,o)),function(e){let t=[];if(void 0===e.metadata||null===e.metadata)return t;if(!dN(e.metadata))return t.push(dC("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 lT)if(e.includes(l)){t.push(dC("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 x=(0,i.useRef)(null),y=(0,i.useRef)(0);(0,i.useEffect)(()=>{y.current+=1;let e=y.current;return(null!==x.current&&clearTimeout(x.current),0===n.sourceId.length||0===n.targetId.length||r.length>0)?void m(!1):(x.current=setTimeout(async()=>{m(!0);try{if(await lL({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!==y.current)return;c(e=>dD(e)?e:null);}catch(t){if(e!==y.current)return;t instanceof lM&&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===y.current&&m(!1);}},250),()=>{null!==x.current&&clearTimeout(x.current);});},[n,r]),(0,i.useEffect)(()=>{c(e=>(null==e?void 0:e.source)!=="submit"||dD(e)?e:null);},[n]);let j=n.sourceId.trim().length>0&&n.targetId.trim().length>0&&0===r.length&&null===o&&!d,w=(0,i.useCallback)(async()=>{if(j){u(!0),c(null);try{let e=crypto.randomUUID(),{relationship:l}=await lz({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 lM?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:[lD]});}finally{u(!1);}}},[j,n,t]),k=(0,i.useCallback)(e=>{"Enter"===e.key&&(e.ctrlKey||e.metaKey)&&w();},[w]),S=lF[n.type],C=dD(o),I=[r.length>0?"rel-create-client-hints":null,null!==o?"rel-create-server-denial":null].filter(e=>null!==e),R=(0,a.jsx)("div",{className:"cmdk-overlay",onPointerDown:()=>t(null),"data-testid":"rel-create-overlay",children:(0,a.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,a.jsxs)("div",{className:"cmdk-input",style:{borderBottom:"1px solid var(--line)"},children:[(0,a.jsx)("span",{id:f,style:{fontWeight:600,fontSize:14,color:"var(--fg)"},children:"Create relationship"}),(0,a.jsx)("span",{id:g,className:"visually-hidden",children:"Create a new relationship between two workspace endpoints."}),(0,a.jsx)("button",{type:"button",className:"palette-x",onClick:()=>t(null),"aria-label":"Close",title:"Close",style:{marginLeft:"auto"},children:(0,a.jsx)(N.F.close,{size:16})})]}),(0,a.jsxs)("div",{style:{padding:"12px 16px",display:"flex",flexDirection:"column",gap:10},children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{htmlFor:"rel-type",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Type"}),(0,a.jsx)(nd,{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:lE.map(e=>({value:e,label:lF[e].displayName}))}],onValueChange:e=>l(t=>({...t,type:e}))}),(0,a.jsx)("div",{style:{fontSize:11,color:"var(--fg-muted)",marginTop:3},children:S.semantics})]}),(0,a.jsxs)("div",{style:{display:"flex",gap:"var(--space-3)"},children:[(0,a.jsxs)("div",{style:{flex:"0 0 140px"},children:[(0,a.jsx)("label",{htmlFor:"rel-src-kind",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Source kind"}),(0,a.jsx)("select",{id:"rel-src-kind",value:n.sourceKind,onChange:e=>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:l$.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]}),(0,a.jsxs)("div",{style:{flex:1},children:[(0,a.jsx)("label",{htmlFor:"rel-src-id",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Source ID"}),(0,a.jsx)("input",{id:"rel-src-id",type:"text",value:n.sourceId,onChange:e=>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,a.jsxs)("div",{style:{display:"flex",gap:"var(--space-3)"},children:[(0,a.jsxs)("div",{style:{flex:"0 0 140px"},children:[(0,a.jsx)("label",{htmlFor:"rel-tgt-kind",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Target kind"}),(0,a.jsx)("select",{id:"rel-tgt-kind",value:n.targetKind,onChange:e=>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:l$.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]}),(0,a.jsxs)("div",{style:{flex:1},children:[(0,a.jsx)("label",{htmlFor:"rel-tgt-id",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Target ID"}),(0,a.jsx)("input",{id:"rel-tgt-id",type:"text",value:n.targetId,onChange:e=>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,a.jsxs)("div",{children:[(0,a.jsx)("label",{htmlFor:"rel-summary",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Summary (optional, ≤240 chars)"}),(0,a.jsx)("textarea",{id:"rel-summary",value:n.summary,maxLength:240,rows:2,onChange:e=>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"})]}),r.length>0&&(0,a.jsx)("div",{id:"rel-create-client-hints",className:"lk-alert",role:"status","aria-live":"polite","data-testid":"client-validation-hints",children:r.map((e,t)=>(0,a.jsx)("div",{style:{fontSize:12},children:e},t))}),p&&(0,a.jsx)("div",{style:{fontSize:12,color:"var(--fg-muted)"},"aria-live":"polite",children:"Validating…"}),null!==o&&(0,a.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,a.jsxs)("div",{style:{marginBottom:6*(t<o.codes.length-1)},children:[(0,a.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--fg-muted)",marginBottom:2},children:e}),(0,a.jsx)("div",{style:{fontSize:13,color:"var(--fg)"},children:null!=(n=o.messages[t])?n:e})]},e);}),C&&(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>c(null),style:{marginTop:6},children:"Dismiss"})]}),(0,a.jsxs)("div",{style:{display:"flex",gap:"var(--space-4)",justifyContent:"flex-end",marginTop:4},children:[(0,a.jsx)("button",{type:"button",className:"arun-btn",onClick:()=>t(null),style:{minWidth:24,minHeight:24},children:"Cancel"}),(0,a.jsx)("button",{type:"button",className:`arun-btn${j?" primary":""}`,"aria-disabled":!j,"aria-describedby":I.length>0?I.join(" "):void 0,onClick:()=>void w(),"aria-busy":d,style:{minWidth:24,minHeight:24},children:d?"Creating…":"Create"})]})]})]})});return"u"<typeof document?R:(0,na.createPortal)(R,document.body);}let dP={};function dq(){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,i;let r=a.get(t),s=a.get(n);return"inactive"===r&&"inactive"!==s?-1:"inactive"!==r&&"inactive"===s?1:(null!=(l=e.current.get(t))?l:0)-(null!=(i=e.current.get(n))?i: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 lT.some(e=>t.includes(e));}(n)||e(t[n]))return!0;return!1;}(e))return null;let n={};for(let t of dv)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 i(){null!==l&&(clearTimeout(l),l=null);}function r(){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||(r(),s());};}}o();let c=()=>{if(t.current="visible"===document.visibilityState,!t.current){i(),r();return;}h(Date.now(),!0),null===n&&o();};return document.addEventListener("visibilitychange",c),()=>{e=!0,document.removeEventListener("visibilitychange",c),i(),r();};},[void 0,f,h]),{activityMap:n,throughputMap:a,animate:!c&&!u,disable:m};}(),[r,s]=(0,i.useState)(!1),[o,c]=(0,i.useState)(dP),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),x=(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;});},[]),y=(0,i.useCallback)(e=>{x({relFocus:e});},[x]),j=(0,i.useCallback)(()=>{x({relFocus:void 0});},[x]),w=(0,i.useCallback)(e=>{x({relFocus:e});},[x]),k=(0,i.useCallback)(e=>{f.current=!0,m(!1),null!==e&&x({relFocus:e.id});},[x]);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;j();}};return e.addEventListener("keydown",t),()=>e.removeEventListener("keydown",t);},[p,j]),(0,a.jsxs)(a.Fragment,{children:[p&&(0,a.jsx)(dM,{onClose:k}),(0,a.jsxs)("div",{ref:g,style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden",background:"var(--bg)"},children:[(0,a.jsxs)("header",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 12px",borderBottom:"1px solid var(--line)",flexShrink:0},children:[(0,a.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,a.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,a.jsxs)("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[(0,a.jsx)("div",{style:{flex:"0 0 280px",borderRight:"1px solid var(--line)",overflowY:"auto"},children:(0,a.jsx)(c6,{filters:o,selectedId:d,onSelect:y,onFilterChange:x,activityMap:t,throughputMap:n,animateBadges:l,highContrast:r})}),(0,a.jsx)("div",{style:{flex:1,overflowY:"auto"},children:v?(0,a.jsx)(dw,{onSelectRelationship:e=>{b(!1),y(e);}}):(0,a.jsx)(dg,{relationshipId:null!=d?d:null,densityMode:u,onClearFocus:j,onViewImpact:w,activityMap:t,throughputMap:n,animateBadges:l,highContrast:r})})]})]})]});}var dL=n(65587),dz=n.n(dL);let dO={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 dK(e){if(e instanceof k.hD){let t=dO[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 dW={jaccardThreshold:.85,staleConfidenceThreshold:.3,maxAgeMs:7776e6,maxClustersPerRun:100,maxRecordsPerRun:1e3};function dB(e,t){return`${e.toString()} ${1===e?t:`${t}s`}`;}function dU(e){return"completed"===e||"failed"===e||"canceled"===e||"skipped"===e;}function d_(e){return void 0===e?"—":new Date(e).toLocaleString();}function dV(e){let{id:t,onOpenDetail:n}=e;return void 0!==n?(0,a.jsx)("button",{type:"button",className:"mc-id-link mc-link-button",title:t,onClick:()=>n(t),children:t}):(0,a.jsx)(dz(),{href:`/memoriaviva/detail?id=${encodeURIComponent(t)}`,className:"mc-id-link",title:t,children:t});}function dJ(e){let{ids:t,onOpenDetail:n}=e;return(0,a.jsx)(a.Fragment,{children:t.map((e,t)=>(0,a.jsxs)(i.Fragment,{children:[t>0?", ":null,(0,a.jsx)(dV,{id:e,onOpenDetail:n})]},`${t.toString()}:${e}`))});}function dH(e){let{item:t,onOpenDetail:n}=e;return void 0===t.proposedAction?(0,a.jsx)(a.Fragment,{children:"No automatic action proposed."}):"merge"===t.proposedAction.kind?(0,a.jsxs)(a.Fragment,{children:["Merge into ",(0,a.jsx)(dV,{id:t.proposedAction.winner,onOpenDetail:n}),"; replace ",(0,a.jsx)(dJ,{ids:t.proposedAction.losers,onOpenDetail:n}),"."]}):(0,a.jsxs)(a.Fragment,{children:["Supersede ",(0,a.jsx)(dV,{id:t.proposedAction.older,onOpenDetail:n})," with"," ",(0,a.jsx)(dV,{id:t.proposedAction.newer,onOpenDetail:n}),"."]});}function dY(e){let{flag:t,onOpenDetail:n}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(dV,{id:t.memoryId,onOpenDetail:n})," — ",t.reason]});}function dX(e){let{label:t,name:n,value:l,min:r,max:s,step:o,help:c,disabled:d=!1,onChange:u}=e,p=(0,i.useId)(),m=e=>{var t;let a=null!=o?o:1,i=Number.isFinite(l)?l:null!=r?r:0,c=Math.min(function(e){let[,t=""]=e.toString().split(".");return t.length;}(a)+2,8);u(n,(t=Number((i+e*a).toFixed(c)),void 0!==r&&t<r?r:void 0!==s&&t>s?s:t));};return(0,a.jsxs)("div",{style:{display:"grid",gap:"var(--space-3)"},children:[(0,a.jsxs)("label",{style:{display:"grid",gap:"var(--space-3)"},children:[(0,a.jsx)("span",{className:"mc-dialog-label",children:t}),(0,a.jsxs)("span",{className:"number-control",children:[(0,a.jsx)("input",{type:"number",inputMode:"decimal",className:"mc-dialog-input number-control-input",name:n,value:Number.isFinite(l)?l:"",min:r,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,a.jsx)(aV,{label:t.toLowerCase(),disabled:d,onStepUp:()=>m(1),onStepDown:()=>m(-1)})]})]}),(0,a.jsx)("span",{id:p,style:{color:"var(--fg-muted)",fontSize:12},children:c})]});}function dG(e){var t,n,l,r,s,o,c,d,u,p;let{startJobImpl:m=nE,fetchJobImpl:h=nA,cancelJobImpl:f=nF,pollIntervalMs:g=2e3,onBack:v,onOpenDetail:b}=e,[x,y]=(0,i.useState)(dW),[j,w]=(0,i.useState)(null),[k,N]=(0,i.useState)(!1),[S,C]=(0,i.useState)(!1),[I,R]=(0,i.useState)(!1),[$,E]=(0,i.useState)(null),[A,F]=(0,i.useState)(null),T=null!=(t=null==j?void 0:j.job)?t:null,D=null!==T&&!dU(T.state),M=(0,i.useMemo)(()=>{var e,t,n;if(null===T)return null;let l=T.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};},[T]),P=(0,i.useCallback)((e,t)=>{y(n=>({...n,[e]:t}));},[]),q=(0,i.useCallback)(async e=>{C(!0);try{let t=await h(e);w(t.job),F(null);}catch(e){F(dK(e));}finally{C(!1);}},[h]);(0,i.useEffect)(()=>{if(null===T||dU(T.state))return;let e=window.setInterval(()=>{q(T.id);},g);return()=>{window.clearInterval(e);};},[T,g,q]);let L=(0,i.useCallback)(async e=>{if(e.preventDefault(),!k&&!D){N(!0),E(null),F(null);try{let e=await m(x);w(e.job);}catch(e){E(dK(e));}finally{N(!1);}}},[x,m,k,D]),z=(0,i.useCallback)(async()=>{if(null!==T&&!I){R(!0),F(null);try{let e=await f(T.id);w(e.job);}catch(e){F(dK(e));}finally{R(!1);}}},[T,f,I]);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("header",{className:"lk-header mc-consolidation-header",children:[(0,a.jsxs)("div",{className:"mc-consolidation-heading",style:{display:"grid",gap:"var(--space-2)"},children:[(0,a.jsx)("h1",{className:"lk-title",children:"MemoriaViva Consolidation"}),(0,a.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,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost lk-btn-lg","aria-label":"Back to MemoriaViva",onClick:v,children:"Back"}):(0,a.jsx)(dz(),{href:"/memoriaviva",className:"lk-btn lk-btn-ghost lk-btn-lg","aria-label":"Back to MemoriaViva",children:"Back"})]}),(0,a.jsxs)("div",{className:"mc-consolidation-scroll",children:[(0,a.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,a.jsxs)("form",{onSubmit:L,style:{display:"grid",gap:16},children:[(0,a.jsxs)("div",{style:{display:"grid",gap:"var(--space-5)",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))"},children:[(0,a.jsx)(dX,{label:"Jaccard threshold",name:"jaccardThreshold",value:x.jaccardThreshold,min:0,max:1,step:.01,disabled:k||D,help:"Similarity floor for near-duplicate detection.",onChange:P}),(0,a.jsx)(dX,{label:"Stale confidence threshold",name:"staleConfidenceThreshold",value:x.staleConfidenceThreshold,min:0,max:1,step:.01,disabled:k||D,help:"Memories at or below this confidence are flagged stale.",onChange:P}),(0,a.jsx)(dX,{label:"Max age (days)",name:"maxAgeMs",value:x.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,a.jsx)(dX,{label:"Max clusters per run",name:"maxClustersPerRun",value:x.maxClustersPerRun,min:0,max:1e3,step:1,disabled:k||D,help:"Hard bound on duplicate clusters inspected in one run.",onChange:P}),(0,a.jsx)(dX,{label:"Max records per run",name:"maxRecordsPerRun",value:x.maxRecordsPerRun,min:0,max:1e3,step:1,disabled:k||D,help:"Hard bound on accepted records admitted to one scan.",onChange:P})]}),null!==$?(0,a.jsx)("div",{role:"alert",className:"lk-alert",children:$}):null,(0,a.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",gap:"var(--space-5)"},children:[(0,a.jsx)("button",{type:"submit",className:"lk-btn lk-btn-primary","aria-disabled":k||D,"aria-busy":k,children:k?"Starting…":"Start consolidation"}),(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost","aria-disabled":null===T||S,"aria-busy":S,onClick:()=>{null===T||S||q(T.id);},children:S?"Refreshing…":"Refresh status"}),D?(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost","aria-disabled":I,"aria-busy":I,onClick:()=>{z();},children:I?"Canceling…":"Cancel job"}):null]})]})}),(0,a.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===T?(0,a.jsx)("p",{style:{margin:0,color:"var(--fg-muted)"},children:"No consolidation job started yet."}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{style:{display:"grid",gap:"var(--space-5)",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))"},children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{style:{color:"var(--fg-muted)",fontSize:12},children:"State"}),(0,a.jsx)("div",{role:"status","aria-live":"polite","aria-atomic":"true",style:{fontWeight:700,textTransform:"capitalize"},children:T.state})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{style:{color:"var(--fg-muted)",fontSize:12},children:"Job ID"}),(0,a.jsx)("div",{style:{wordBreak:"break-all"},children:T.id})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{style:{color:"var(--fg-muted)",fontSize:12},children:"Started"}),(0,a.jsx)("div",{children:d_(T.startedAt)})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{style:{color:"var(--fg-muted)",fontSize:12},children:"Completed"}),(0,a.jsx)("div",{children:d_(T.completedAt)})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{style:{color:"var(--fg-muted)",fontSize:12},children:"Clusters inspected"}),(0,a.jsx)("div",{style:{fontVariantNumeric:"tabular-nums"},children:null!=(n=null==(o=T.result)?void 0:o.clustersInspected)?n:0})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{style:{color:"var(--fg-muted)",fontSize:12},children:"Elapsed"}),(0,a.jsx)("div",{style:{fontVariantNumeric:"tabular-nums"},children:(p=null!=(l=null==(c=T.result)?void 0:c.elapsedMs)?l:0)<1e3?`${p.toString()} ms`:`${(p/1e3).toFixed(1)} s`})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{style:{color:"var(--fg-muted)",fontSize:12},children:"Records inspected"}),(0,a.jsxs)("div",{style:{fontVariantNumeric:"tabular-nums"},children:[null!=(r=null==(d=T.result)?void 0:d.recordsInspected)?r:0,(null==(u=T.result)?void 0:u.truncated)===!0?" (truncated)":""]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{style:{color:"var(--fg-muted)",fontSize:12},children:"Memories loaded"}),(0,a.jsx)("div",{style:{fontVariantNumeric:"tabular-nums"},children:null!=(s=null==j?void 0:j.memoryCount)?s:0})]})]}),null!==A?(0,a.jsx)("div",{role:"alert",className:"lk-alert",children:A}):null,void 0!==T.error&&T.error.length>0?(0,a.jsx)("div",{role:"alert",className:"lk-alert",children:T.error}):null,null!==M?(0,a.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",gap:"var(--space-5)"},children:[(0,a.jsx)("span",{className:"mc-badge mc-badge-default",children:dB(M.reviewCount,"review item")}),(0,a.jsx)("span",{className:"mc-badge mc-badge-default",children:dB(M.staleCount,"stale flag")}),(0,a.jsx)("span",{className:"mc-badge mc-badge-default",children:dB(M.edgeCount,"proposed edge")})]}):null]})}),(null==T?void 0:T.result)!==void 0?(0,a.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,a.jsxs)("article",{style:{display:"grid",gap:"var(--space-5)",padding:16,border:"1px solid var(--line)",borderRadius:14,background:"var(--card)"},children:[(0,a.jsx)("h2",{className:"lk-section-head",style:{margin:0},children:"Review items"}),0===T.result.reviewItems.length?(0,a.jsx)("p",{style:{margin:0,color:"var(--fg-muted)"},children:"No review items returned."}):(0,a.jsx)("ul",{style:{listStyle:"none",padding:0,margin:0,display:"grid",gap:"var(--space-5)"},children:T.result.reviewItems.map(e=>(0,a.jsxs)("li",{style:{display:"grid",gap:"var(--space-2)"},children:[(0,a.jsx)("strong",{style:{textTransform:"capitalize"},children:e.reason.replaceAll("-"," ")}),(0,a.jsx)("span",{children:(0,a.jsx)(dJ,{ids:e.relatedMemoryIds,onOpenDetail:b})}),(0,a.jsx)("span",{style:{color:"var(--fg-muted)"},children:(0,a.jsx)(dH,{item:e,onOpenDetail:b})})]},e.id))})]}),(0,a.jsxs)("article",{style:{display:"grid",gap:"var(--space-5)",padding:16,border:"1px solid var(--line)",borderRadius:14,background:"var(--card)"},children:[(0,a.jsx)("h2",{className:"lk-section-head",style:{margin:0},children:"Stale flags"}),0===T.result.staleFlags.length?(0,a.jsx)("p",{style:{margin:0,color:"var(--fg-muted)"},children:"No stale flags returned."}):(0,a.jsx)("ul",{style:{listStyle:"none",padding:0,margin:0,display:"grid",gap:"var(--space-5)"},children:T.result.staleFlags.map(e=>(0,a.jsx)("li",{children:(0,a.jsx)(dY,{flag:e,onOpenDetail:b})},`${e.memoryId}:${e.reason}`))})]}),(0,a.jsxs)("article",{style:{display:"grid",gap:"var(--space-5)",padding:16,border:"1px solid var(--line)",borderRadius:14,background:"var(--card)"},children:[(0,a.jsx)("h2",{className:"lk-section-head",style:{margin:0},children:"Proposed edges"}),0===T.result.edgesProposed.length?(0,a.jsx)("p",{style:{margin:0,color:"var(--fg-muted)"},children:"No edges proposed."}):(0,a.jsx)("ul",{style:{listStyle:"none",padding:0,margin:0,display:"grid",gap:"var(--space-5)"},children:T.result.edgesProposed.map(e=>(0,a.jsxs)("li",{style:{display:"grid",gap:"var(--space-2)"},children:[(0,a.jsx)("strong",{children:e.kind}),(0,a.jsxs)("span",{children:[(0,a.jsx)(dV,{id:e.fromMemoryId,onOpenDetail:b})," →"," ",(0,a.jsx)(dV,{id:e.toMemoryId,onOpenDetail:b})]}),void 0!==e.provenanceSummary?(0,a.jsx)("span",{style:{color:"var(--fg-muted)"},children:e.provenanceSummary}):null]},e.id))})]})]}):null]})]});}let dQ=["user","workspace","project","workflow","global"],dZ=["episodic","semantic-fact","procedural","preference","correction","decision","negative","pinned"],d0=["public","confidential","restricted"],d1=["proposed","accepted","rejected","superseded","archived","forgotten","conflicted","expired"],d2={user:"User",workspace:"Workspace",project:"Project",workflow:"Workflow",global:"Global"},d4={episodic:"Episodic","semantic-fact":"Fact",procedural:"Procedural",preference:"Preference",correction:"Correction",decision:"Decision",negative:"Negative",pinned:"Pinned"},d3={proposed:"Proposed",accepted:"Accepted",rejected:"Rejected",superseded:"Superseded",archived:"Archived",forgotten:"Forgotten",conflicted:"Conflicted",expired:"Expired"},d5={public:"Public",confidential:"Confidential",restricted:"Restricted"};function d6(e,t){return e.includes(t)?e.filter(e=>e!==t):[...e,t];}function d8(e){let{label:t,items:n,labels:l,active:i,onToggle:r}=e;return(0,a.jsxs)("div",{className:"mc-filter-row",role:"group","aria-label":`Filter by ${t}`,children:[(0,a.jsx)("span",{className:"mc-filter-label",children:t}),(0,a.jsx)("div",{className:"mc-filter-chips",children:n.map(e=>{let t=i.includes(e);return(0,a.jsx)("button",{type:"button",className:"mc-chip","data-active":String(t),"aria-pressed":t,onClick:()=>{r(e);},children:l[e]},e);})})]});}function d7(e){let{filters:t,onChange:n}=e;return(0,a.jsxs)("section",{className:"mc-filters","aria-label":"Memory filters",children:[(0,a.jsx)(d8,{label:"Scope",items:dQ,labels:d2,active:t.scope,onToggle:e=>{n({...t,scope:d6(t.scope,e)});}}),(0,a.jsx)(d8,{label:"Type",items:dZ,labels:d4,active:t.type,onToggle:e=>{n({...t,type:d6(t.type,e)});}}),(0,a.jsx)(d8,{label:"Status",items:d1,labels:d3,active:t.status,onToggle:e=>{n({...t,status:d6(t.status,e)});}}),(0,a.jsx)(d8,{label:"Sensitivity",items:d0,labels:d5,active:t.sensitivity,onToggle:e=>{n({...t,sensitivity:d6(t.sensitivity,e)});}})]});}let d9={public:"Public",confidential:"Confidential",restricted:"Restricted"};function ue(e){let{record:t,mode:n="edit",onSave:l,onClose:r,editMemoryImpl:s=nD,correctMemoryImpl:o=nO}=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),[x,y]=(0,i.useState)(!1),j=(0,i.useRef)(null),w=(0,i.useRef)(null),k=(0,i.useRef)(null),N=(0,i.useRef)(null),S=(0,i.useId)(),C=(0,i.useId)(),I="correct"===n;(0,i.useEffect)(()=>{var e;return N.current=document.activeElement instanceof HTMLElement?document.activeElement:null,null==(e=j.current)||e.focus(),()=>{var e;null==(e=N.current)||e.focus();};},[]);let R=(0,i.useCallback)(e=>{var t,n,l;if("Escape"===e.key)return void r();if("Tab"!==e.key)return;let a=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===a||0===a.length){e.preventDefault(),null==(n=k.current)||n.focus();return;}let i=a[0],s=a[a.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());},[r]),$=(0,i.useCallback)(e=>{e.target===w.current&&r();},[r]),E=(0,i.useCallback)(async()=>{let e=c.trim();if(0===e.length){var n;b("Body cannot be empty."),y(!0),null==(n=j.current)||n.focus();return;}let a=u.split(",").map(e=>e.trim()).filter(e=>e.length>0);g(!0),b(null);try{if(I){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(dK(e));}finally{g(!1);}},[c,u,m,t.id,I,o,s,l]);return(0,a.jsx)("div",{ref:w,className:"mc-dialog-backdrop",role:"presentation",onClick:$,children:(0,a.jsxs)("div",{ref:k,role:"dialog","aria-modal":"true","aria-labelledby":S,tabIndex:-1,className:"mc-dialog",onKeyDown:R,children:[(0,a.jsx)("h2",{id:S,className:"mc-dialog-title",children:I?"Correct memory":"Edit memory"}),(0,a.jsxs)("div",{className:"mc-dialog-field",children:[(0,a.jsx)("label",{htmlFor:"edit-body",className:"mc-dialog-label",children:I?"Corrected body":"Body"}),(0,a.jsx)("textarea",{id:"edit-body",ref:j,className:"mc-dialog-textarea",value:c,rows:5,onChange:e=>{d(e.target.value),x&&(y(!1),b(null));},disabled:f,"aria-required":"true","aria-invalid":x?"true":void 0,"aria-describedby":x?C:void 0})]}),I?null:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"mc-dialog-field",children:[(0,a.jsxs)("label",{htmlFor:"edit-tags",className:"mc-dialog-label",children:["Tags ",(0,a.jsx)("span",{className:"mc-dialog-hint",children:"(comma-separated)"})]}),(0,a.jsx)("input",{id:"edit-tags",type:"text",className:"mc-dialog-input",value:u,onChange:e=>{p(e.target.value);},disabled:f})]}),(0,a.jsxs)("div",{className:"mc-dialog-field",children:[(0,a.jsx)("label",{htmlFor:"edit-sensitivity",className:"mc-dialog-label",children:"Sensitivity"}),(0,a.jsx)("select",{id:"edit-sensitivity",className:"mc-dialog-select",value:m,onChange:e=>{h(e.target.value);},disabled:f,children:d0.map(e=>(0,a.jsx)("option",{value:e,children:d9[e]},e))})]})]}),null!==v?(0,a.jsx)("p",{id:C,role:"alert",className:"mc-dialog-error",children:v}):null,(0,a.jsxs)("div",{className:"mc-dialog-actions",children:[(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost",onClick:r,disabled:f,children:"Cancel"}),(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-primary",onClick:()=>{E();},disabled:f,"aria-busy":f,children:f?I?"Submitting…":"Saving…":I?"Submit correction":"Save"})]})]})});}function ut(e){let{record:t,mode:n="forget",onComplete:l,onClose:r,forgetMemoryImpl:s=nL,deleteMemoryImpl:o=nz}=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 r();if("Tab"!==e.key)return;let a=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===a||0===a.length){e.preventDefault(),null==(n=f.current)||n.focus();return;}let i=a[0],s=a[a.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());},[r]),x=(0,i.useCallback)(e=>{e.target===h.current&&r();},[r]),y=(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(dK(e)),d(!1);}},[o,s,v,l,t.id]);return(0,a.jsx)("div",{ref:h,className:"mc-dialog-backdrop",role:"presentation",onClick:x,children:(0,a.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,a.jsx)("h2",{id:"forget-dialog-title",className:"mc-dialog-title",children:v?"Delete this memory?":"Forget this memory?"}),(0,a.jsx)("p",{id:"forget-dialog-desc",className:"mc-dialog-body",children:(0,a.jsxs)(a.Fragment,{children:["This action is ",(0,a.jsx)("strong",{children:"permanent"}),". The memory will be removed and a tombstone audit record will be created. You cannot undo this."]})}),(0,a.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,a.jsx)("p",{role:"alert",className:"mc-dialog-error",children:u}):null,(0,a.jsxs)("div",{className:"mc-dialog-actions",children:[(0,a.jsx)("button",{ref:m,type:"button",className:"lk-btn lk-btn-ghost",onClick:r,disabled:c,children:"Cancel"}),(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-danger",onClick:()=>{y();},disabled:c,"aria-busy":c,children:c?v?"Deleting…":"Forgetting…":v?"Delete permanently":"Forget permanently"})]})]})});}function un(e){let{record:t,onRecordChange:n,acceptImpl:l=nK,rejectImpl:r=nW,pinImpl:s=nM,unpinImpl:o=nP,archiveImpl:c=nq,deleteImpl:d=nz,correctImpl:u=nO}=e,[p,m]=(0,i.useState)(null),[h,f]=(0,i.useState)(null),[g,v]=(0,i.useState)(null),[b,x]=(0,i.useState)(!1),[y,j]=(0,i.useState)(!1),[w,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(dK(e));}finally{m(null);}}},[p]),I=(0,i.useCallback)(()=>{C("accept",async()=>{n((await l(t.id)).memory);});},[l,n,t.id,C]),R=(0,i.useCallback)(()=>{C("reject",async()=>{n((await r(t.id,"rejected by user in MemoriaViva")).memory);});},[n,t.id,r,C]),$=(0,i.useCallback)(()=>{C("pin",async()=>{n((await s(t.id)).memory);});},[n,s,t.id,C]),E=(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]),F=(0,i.useCallback)(e=>{j(!1),v(`Correction submitted for review: ${e.body}`);},[]),T="proposed"===t.status,D="accepted"===t.status||"superseded"===t.status||"conflicted"===t.status||"expired"===t.status,M="forgotten"===t.status;return(0,a.jsxs)("div",{className:"mc-actions",role:"group","aria-label":"Memory actions",children:[T?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-primary","aria-disabled":null!==p,"aria-busy":"accept"===p,onClick:I,"aria-label":"Approve this memory proposal",children:"accept"===p?"Approving…":"Approve"}),(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost","aria-disabled":null!==p,"aria-busy":"reject"===p,onClick:R,"aria-label":"Reject this memory proposal",children:"reject"===p?"Rejecting…":"Reject"})]}):null,M?null:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost","aria-disabled":null!==p,onClick:()=>{null===p&&(f(null),v(null),x(!0));},"aria-label":"Edit memory body, tags, or sensitivity",children:"Edit"}),(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost","aria-disabled":null!==p,onClick:()=>{null===p&&(f(null),v(null),j(!0));},"aria-label":"Create a correction proposal for this memory",children:"Correct"})]}),M?null:t.pinned?(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost","aria-disabled":null!==p,"aria-busy":"unpin"===p,onClick:E,"aria-label":"Unpin this memory",children:"unpin"===p?"Unpinning…":"Unpin"}):(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost","aria-disabled":null!==p,"aria-busy":"pin"===p,onClick:$,"aria-label":"Pin this memory for priority retrieval",children:"pin"===p?"Pinning…":"Pin"}),D?(0,a.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,a.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,a.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,a.jsx)("p",{role:"alert","aria-live":"assertive",className:"mc-action-error",children:h}):null,null!==g?(0,a.jsx)("p",{role:"status","aria-live":"polite",className:"mc-action-notice",children:g}):null,b?(0,a.jsx)(ue,{record:t,onSave:e=>{x(!1),n(e);},onClose:()=>{x(!1);}}):null,y?(0,a.jsx)(ue,{mode:"correct",record:t,correctMemoryImpl:u,onSave:F,onClose:()=>{j(!1);}}):null,w?(0,a.jsx)(ut,{record:t,onComplete:()=>{k(!1),n(null);},onClose:()=>{k(!1);}}):null,N?(0,a.jsx)(ut,{mode:"delete",record:t,deleteMemoryImpl:d,onComplete:()=>{S(!1),n(null);},onClose:()=>{S(!1);}}):null]});}function ul(e){return new Date(e).toLocaleString();}function ua(e){let{label:t,value:n}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("dt",{className:"mc-meta-label",children:t}),(0,a.jsx)("dd",{className:"mc-meta-value",children:n})]});}function ui(e){let{provenance:t}=e;return(0,a.jsxs)("section",{"aria-label":"Provenance",className:"mc-section",children:[(0,a.jsx)("h2",{className:"lk-section-head",children:"Provenance"}),(0,a.jsxs)("dl",{className:"mc-meta",children:[(0,a.jsx)(ua,{label:"Source kind",value:t.sourceKind}),(0,a.jsx)(ua,{label:"Captured at",value:ul(t.capturedAt)}),(0,a.jsx)(ua,{label:"Confidence",value:`${(100*t.confidence).toFixed(0)}%`}),(0,a.jsx)(ua,{label:"Sensitivity",value:t.sensitivity}),void 0!==t.captureRationale?(0,a.jsx)(ua,{label:"Rationale",value:t.captureRationale}):null,void 0!==t.modelIdentity?(0,a.jsx)(ua,{label:"Model",value:`${t.modelIdentity.provider} / ${t.modelIdentity.modelId}`}):null]})]});}function ur(e){let{validity:t}=e;return(0,a.jsxs)("section",{"aria-label":"Validity",className:"mc-section",children:[(0,a.jsx)("h2",{className:"lk-section-head",children:"Validity"}),(0,a.jsxs)("dl",{className:"mc-meta",children:[(0,a.jsx)(ua,{label:"Valid from",value:ul(t.validFrom)}),(0,a.jsx)(ua,{label:"Valid until",value:void 0!==t.validUntil?ul(t.validUntil):"No expiry"})]})]});}function us(e){let{tags:t}=e;return 0===t.length?(0,a.jsx)("span",{className:"mc-meta-empty",children:"No tags"}):(0,a.jsx)("ul",{className:"mc-tags","aria-label":"Tags",children:t.map(e=>(0,a.jsx)("li",{className:"mc-tag",children:e},e))});}function uo(e){let{onBack:t,controlRef:n,children:l="Back to MemoriaViva"}=e;return void 0!==t?(0,a.jsx)("button",{ref:n,type:"button",className:"mc-back-link lk-btn lk-btn-ghost",onClick:t,children:l}):(0,a.jsx)(dz(),{ref:n,href:"/memoriaviva",className:"mc-back-link lk-btn lk-btn-ghost","aria-label":"Back to MemoriaViva",children:l});}function uc(e){let{record:t,onBack:n}=e;return(0,a.jsxs)("header",{className:"mc-detail-header",children:[(0,a.jsxs)("div",{className:"mc-detail-title-row",children:[(0,a.jsxs)("h1",{className:"lk-title",style:{flex:1},children:[d4[t.type]," memory"]}),(0,a.jsx)("span",{className:`mc-badge mc-badge-${t.status}`,children:t.status}),t.pinned?(0,a.jsx)("span",{"aria-label":"Pinned",className:"mc-badge mc-badge-pinned",children:"Pinned"}):null]}),(0,a.jsx)(uo,{onBack:n,children:"Back"})]});}function ud(e){let{id:t,fetchMemoryImpl:n=nT,onBack:l}=e,[r,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===r&&(null==(e=h.current)||e.focus());},[p,r]);let v=(0,i.useCallback)(async()=>{c(!0),u(null);try{let e=await n(t);s(e.memory);}catch(e){u(dK(e));}finally{c(!1);}},[t,n]);return((0,i.useEffect)(()=>{v();},[v]),o)?(0,a.jsx)("p",{role:"status","aria-live":"polite",className:"lk-loading",children:"Loading memory…"}):null!==d?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{role:"alert","aria-live":"assertive",className:"lk-alert",children:[d,(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>{v();},children:"Retry"})]}),(0,a.jsx)("p",{children:(0,a.jsx)(uo,{onBack:l})})]}):null===r?(0,a.jsx)("div",{className:"lk-empty",children:(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"lk-empty-title",children:p?"Memory removed":"Memory not found"}),(0,a.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,a.jsx)("p",{children:(0,a.jsx)(uo,{onBack:l,controlRef:f})})]})}):(0,a.jsxs)("article",{"aria-label":`Memory record: ${r.body.slice(0,60)}`,className:"mc-detail",children:[(0,a.jsx)(uc,{record:r,onBack:l}),(0,a.jsxs)("section",{"aria-label":"Memory body",className:"mc-section",children:[(0,a.jsx)("h2",{className:"lk-section-head",children:"Content"}),(0,a.jsx)("p",{className:"mc-body-text",children:r.body})]}),(0,a.jsxs)("section",{"aria-label":"Details",className:"mc-section",children:[(0,a.jsx)("h2",{className:"lk-section-head",children:"Details"}),(0,a.jsxs)("dl",{className:"mc-meta",children:[(0,a.jsx)(ua,{label:"ID",value:(0,a.jsx)("code",{className:"mc-code",children:r.id})}),(0,a.jsx)(ua,{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";}}(r.scope)}),(0,a.jsx)(ua,{label:"Type",value:d4[r.type]}),(0,a.jsx)(ua,{label:"Created",value:ul(r.createdAt)}),(0,a.jsx)(ua,{label:"Updated",value:ul(r.updatedAt)}),void 0!==r.staleReason?(0,a.jsx)(ua,{label:"Stale reason",value:(0,a.jsx)("em",{children:r.staleReason})}):null]})]}),(0,a.jsx)(ui,{provenance:r.provenance}),(0,a.jsx)(ur,{validity:r.validity}),(0,a.jsxs)("section",{"aria-label":"Tags",className:"mc-section",children:[(0,a.jsx)("h2",{className:"lk-section-head",children:"Tags"}),(0,a.jsx)(us,{tags:r.tags})]}),(0,a.jsxs)("section",{"aria-label":"Actions",className:"mc-section",children:[(0,a.jsx)("h2",{className:"lk-section-head",children:"Actions"}),(0,a.jsx)(un,{record:r,onRecordChange:g})]})]});}var uu=n(79748);let up={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 um(e){var t;let{status:n}=e,l=null!=(t=up[n])?t:"mc-badge-default";return(0,a.jsx)("span",{className:`mc-badge ${l}`,children:n});}function uh(e){var t;let{record:n,onOpenDetail:l}=e,i=(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"mc-row-main",children:[(0,a.jsx)("span",{className:"mc-row-body",title:n.body,children:n.body}),(0,a.jsxs)("div",{className:"mc-row-meta",children:[(0,a.jsx)("span",{className:"mc-row-type",children:d4[n.type]}),(0,a.jsx)("span",{className:"mc-row-scope",children:d2[n.scope.kind]}),(0,a.jsxs)("span",{className:"mc-row-source",children:["Source ",n.provenance.sourceKind]}),(0,a.jsx)("span",{className:"mc-row-confidence",children:(t=n.provenance.confidence,`${(100*t).toFixed(0)}% confidence`)}),(0,a.jsxs)("span",{className:"mc-row-sensitivity",children:["Sensitivity ",n.provenance.sensitivity]}),n.pinned?(0,a.jsx)("span",{className:"mc-badge mc-badge-pinned",children:"Pinned"}):null]})]}),(0,a.jsx)(um,{status:n.status})]});return(0,a.jsx)("li",{children:void 0!==l?(0,a.jsx)("button",{type:"button",className:"mc-row mc-row-button",onClick:()=>l(n.id),children:i}):(0,a.jsx)(dz(),{href:`/memoriaviva/detail?id=${encodeURIComponent(n.id)}`,className:"mc-row",children:i})});}function uf(e){let{hasFilters:t}=e;return(0,a.jsx)("div",{"data-testid":"memory-empty-state",className:"lk-empty",children:(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"lk-empty-title",children:"No memories found"}),(0,a.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 ug(e){let{filters:t,onFilterChange:n,fetchMemoriesImpl:l=nR,onOpenDetail:r,onOpenConsolidation:s,onOpenReviewQueue:o,policyEnabled:c,onPolicyEnabledChange:d,showWorkspaceBackLink:u=!0}=e,[p,m]=(0,i.useState)([]),[h,f]=(0,i.useState)(!0),[g,v]=(0,i.useState)(null),[b,x]=(0,i.useState)(!0),y=null!=c?c:b,j=t.scope.length>0||t.type.length>0||t.status.length>0||t.sensitivity.length>0,w=(0,i.useCallback)(async e=>{f(!0),v(null);try{let t=await l(e);m(t.memories);}catch(e){v(dK(e));}finally{f(!1);}},[l]);return(0,i.useEffect)(()=>{w(t);},[t,w]),(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("header",{className:"lk-header",children:[(0,a.jsx)("h1",{className:"lk-title",children:"MemoriaViva"}),(0,a.jsxs)("div",{className:"mc-view-actions",children:[(0,a.jsxs)("div",{className:"mc-policy-switch",children:[(0,a.jsx)(iw,{on:y,onChange:null!=d?d:x,label:"Enable MemoriaViva policy"}),(0,a.jsxs)("span",{children:["Policy ",y?"on":"off"]})]}),u?(0,a.jsx)(dz(),{href:"/",className:"lk-btn lk-btn-ghost lk-btn-lg",children:"Back to Workspace"}):null,void 0!==s?(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost lk-btn-lg",onClick:s,children:"Consolidation"}):(0,a.jsx)(dz(),{href:"/memoriaviva/consolidation",className:"lk-btn lk-btn-ghost lk-btn-lg",children:"Consolidation"}),void 0!==o?(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost lk-btn-lg mc-queue-link",onClick:o,children:"Review queue"}):(0,a.jsx)(dz(),{href:"/memoriaviva/review-queue",className:"lk-btn lk-btn-ghost lk-btn-lg mc-queue-link",children:"Review queue"})]})]}),(0,a.jsx)(d7,{filters:t,onChange:n}),(0,a.jsx)("p",{role:"status",className:"visually-hidden",children:h||null!==g?null:`${p.length.toString()} ${1===p.length?"memory":"memories"} found`}),(0,a.jsx)("section",{"aria-label":"Memory records","aria-busy":h,style:{flex:1,minHeight:0,overflowY:"auto"},children:h&&0===p.length?(0,a.jsx)("p",{role:"status","aria-live":"polite",className:"lk-loading",children:"Loading memories…"}):null!==g?(0,a.jsxs)("div",{role:"alert","aria-live":"assertive",className:"lk-alert",children:[g,(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>{w(t);},children:"Retry"})]}):0===p.length?(0,a.jsx)(uf,{hasFilters:j}):(0,a.jsx)("ul",{"aria-label":"Memory list",style:{listStyle:"none",padding:0,margin:0,display:"flex",flexDirection:"column",gap:4,opacity:h?.6:1,transition:"opacity 0.15s ease"},children:p.map(e=>(0,a.jsx)(uh,{record:e,onOpenDetail:r},e.id))})})]});}function uv(e){let{record:t,busyAction:n,rowError:l,onAccept:i,onReject:r,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,a.jsx)("li",{"data-review-row-id":t.id,children:(0,a.jsxs)("article",{className:"mc-review-row",children:[(0,a.jsxs)("div",{className:"mc-review-body",children:[(0,a.jsx)("p",{id:c,className:"mc-row-body",children:t.body}),(0,a.jsxs)("div",{className:"mc-row-meta",children:[(0,a.jsx)("span",{className:"mc-row-type",children:d4[t.type]}),(0,a.jsx)("span",{className:"mc-row-scope",children:d2[t.scope.kind]}),(0,a.jsx)("span",{className:`mc-badge mc-badge-${t.status}`,children:t.status}),u?(0,a.jsxs)("span",{className:"mc-row-stale",children:["Stale",void 0!==t.staleReason?`: ${t.staleReason}`:""]}):null,void 0!==o?(0,a.jsx)("button",{type:"button",className:"mc-row-detail-link mc-link-button","aria-label":d,onClick:()=>o(t.id),children:"View details"}):(0,a.jsx)(dz(),{href:`/memoriaviva/detail?id=${encodeURIComponent(t.id)}`,className:"mc-row-detail-link","aria-label":d,children:"View details"})]}),null!==l?(0,a.jsx)("p",{role:"alert",className:"mc-action-error",children:l}):null]}),(0,a.jsx)("div",{className:"mc-review-actions",role:"group","aria-labelledby":c,children:"proposed"===t.status?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-primary","aria-disabled":null!==n,"aria-busy":"accept"===n,onClick:()=>{null===n&&i(t);},children:"accept"===n?"Approving…":"Approve"}),(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost","aria-disabled":null!==n,"aria-busy":"reject"===n,onClick:()=>{null===n&&r(t);},children:"reject"===n?"Rejecting…":"Reject"})]}):"conflicted"===t.status?(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost","aria-disabled":null!==n,"aria-busy":"reject"===n,onClick:()=>{null===n&&r(t);},children:"reject"===n?"Rejecting…":"Reject conflict"}):(0,a.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 ub(e){let{fetchQueueImpl:t=n$,acceptImpl:n=nK,rejectImpl:l=nW,archiveImpl:r=nq,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)({}),[x,y]=(0,i.useState)(""),j=(0,i.useRef)(null),w=(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(dK(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=j.current)?void 0:t.querySelector(`[data-review-row-id="${CSS.escape(l)}"]`))?e:null,i=null===a?null:a.querySelector("button");null!==i?i.focus():null==(n=w.current)||n.focus();},[c]);let I=(0,i.useCallback)(async(e,t)=>{let a=e.id;g(e=>({...e,[a]:t})),b(e=>{let t={...e};return delete t[a],t;});try{"accept"===t?await n(a):"archive"===t?await r(a,"archived stale memory from review queue"):await l(a,"conflicted"===e.status?"rejected conflict from review queue":"rejected from review queue"),C(a),y("accept"===t?"Memory approved":"archive"===t?"Memory archived":"Memory rejected");}catch(e){b(t=>({...t,[a]:dK(e)})),g(e=>{let t={...e};return delete t[a],t;});}},[n,r,l,C]);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("header",{className:"lk-header mc-review-header",children:[(0,a.jsx)("h1",{className:"lk-title",tabIndex:-1,ref:w,children:"Review queue"}),(0,a.jsxs)("span",{role:"status","aria-live":"polite",className:"mc-badge-count",children:[c.length.toString()," awaiting review"]}),void 0!==s?(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost lk-btn-lg","aria-label":"Back to MemoriaViva",onClick:s,children:"Back"}):(0,a.jsx)(dz(),{href:"/memoriaviva",className:"lk-btn lk-btn-ghost lk-btn-lg","aria-label":"Back to MemoriaViva",children:"Back"})]}),(0,a.jsx)("p",{role:"status",className:"visually-hidden",children:x}),(0,a.jsx)("section",{"aria-label":"Memories awaiting review","aria-busy":u,style:{flex:1,minHeight:0,overflowY:"auto"},children:u?(0,a.jsx)("p",{role:"status","aria-live":"polite",className:"lk-loading",children:"Loading review queue…"}):null!==m?(0,a.jsxs)("div",{role:"alert","aria-live":"assertive",className:"lk-alert",children:[m,(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>{N();},children:"Retry"})]}):0===c.length?(0,a.jsx)("div",{"data-testid":"review-queue-empty",className:"lk-empty",children:(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"lk-empty-title",children:"Queue is clear"}),(0,a.jsx)("p",{className:"lk-empty-body",children:"No memories are waiting for review. Proposed, conflicted, and stale memories appear here."})]})}):(0,a.jsx)("ul",{ref:j,"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,a.jsx)(uv,{record:e,busyAction:null!=(t=f[e.id])?t:null,rowError:null!=(n=v[e.id])?n:null,onAccept:e=>{I(e,"accept");},onReject:e=>{I(e,"reject");},onArchive:e=>{I(e,"archive");},onOpenDetail:o},e.id);})})})]});}let ux={scope:[],type:[],status:[],sensitivity:[]};function uy(){let[e,t]=(0,i.useState)({kind:"list"}),[n,l]=(0,i.useState)(ux),[r,s]=(0,i.useState)(!0),o=(0,i.useCallback)(()=>{t({kind:"list"});},[]),c=(0,i.useCallback)(e=>{t({kind:"detail",id:e});},[]);return(0,a.jsx)("div",{className:"memoria-window",children:"list"===e.kind?(0,a.jsx)(ug,{filters:n,onFilterChange:l,onOpenDetail:c,onOpenConsolidation:()=>t({kind:"consolidation"}),onOpenReviewQueue:()=>t({kind:"reviewQueue"}),policyEnabled:r,onPolicyEnabledChange:s,showWorkspaceBackLink:!1}):"detail"===e.kind?(0,a.jsx)(ud,{id:e.id,onBack:o}):"consolidation"===e.kind?(0,a.jsx)(dG,{onBack:o,onOpenDetail:c}):(0,a.jsx)(ub,{onBack:o,onOpenDetail:c})});}var uj=n(19217),uw=n(25780),uk=n(23934);function uN(e){return Array.from(e.querySelectorAll("button:not([disabled]),input:not([disabled]),[tabindex]:not([tabindex='-1'])"));}function uS(e){let{capsule:t,checked:n,disabled:l,onToggle:i}=e;return(0,a.jsx)("li",{className:"lk-compose-member",children:(0,a.jsxs)("label",{className:"lk-compose-member-label",children:[(0,a.jsx)("input",{type:"checkbox",checked:n,disabled:l,onChange:()=>i(t.id)}),(0,a.jsx)("span",{className:"lk-compose-member-name",title:t.displayName,children:t.displayName}),(0,a.jsx)("span",{className:"lk-badge","data-state":t.lifecycleState,children:uw.Z[t.lifecycleState]})]})});}function uC(e){let t,{capsules:n,onCancel:l,onCreated:r,createImpl:s=ik.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,x]=(0,i.useState)(null);function y(e){f(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n;}),null!==b&&x(null);}async function j(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 x(n);v(!0),x(null);try{await s({displayName:p.trim(),capsuleIds:[...h]}),r();}catch(e){x((0,uk.W)(e));}finally{v(!1);}}(0,uj.i)(),(0,i.useEffect)(()=>{var e;let t=document.activeElement,n=u.current;return null!==n&&(null==(e=uN(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=uN(e);if(0===n.length)return void t.preventDefault();let a=n[0],i=n[n.length-1];t.shiftKey&&document.activeElement===a?(t.preventDefault(),null==i||i.focus()):t.shiftKey||document.activeElement!==i||(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=uN(e)[0])||n.focus();}}},[u,g]);let w="Set name is required."===b,k="Select at least one capsule to combine."===b;return(0,na.createPortal)((0,a.jsx)("div",{className:"mc-dialog-backdrop",role:"presentation",children:(0,a.jsxs)("div",{ref:u,className:"mc-dialog",role:"dialog","aria-modal":"true","aria-labelledby":o,tabIndex:-1,children:[(0,a.jsx)("h2",{id:o,className:"mc-dialog-title",children:"Combine capsules into a set"}),(0,a.jsxs)("form",{onSubmit:e=>void j(e),children:[(0,a.jsxs)("label",{className:"mc-dialog-field",htmlFor:c,children:[(0,a.jsx)("span",{className:"mc-dialog-label",children:"Set name"}),(0,a.jsx)("input",{id:c,className:"mc-dialog-input",value:p,disabled:g,autoComplete:"off","aria-invalid":w,"aria-describedby":w?d:void 0,onChange:e=>{m(e.target.value),null!==b&&x(null);}})]}),(0,a.jsxs)("fieldset",{className:"lk-compose-fieldset",disabled:g,"aria-invalid":k,"aria-describedby":k?d:void 0,children:[(0,a.jsxs)("legend",{className:"mc-dialog-label",children:["Capsules (",h.size.toString(),"/","16",")"]}),0===n.length?(0,a.jsx)("p",{className:"lkd-empty-note",children:"No capsules available to combine."}):(0,a.jsx)("ul",{className:"lk-compose-member-list","aria-label":"Selectable capsules",children:n.map(e=>(0,a.jsx)(uS,{capsule:e,checked:h.has(e.id),disabled:g,onToggle:y},e.id))})]}),null!==b?(0,a.jsx)("div",{id:d,role:"alert","aria-live":"assertive",className:"mc-dialog-error",children:b}):null,(0,a.jsxs)("div",{className:"mc-dialog-actions",children:[(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost",disabled:g,onClick:l,children:"Cancel"}),(0,a.jsx)("button",{type:"submit",className:"lk-btn lk-btn-primary",disabled:g,"aria-busy":g,children:g?"Combining…":"Combine"})]})]})]})}),document.body);}var uI=n(68835);function uR(e){let{message:t,onRetry:n,onDismiss:l}=e;return(0,a.jsxs)("div",{role:"alert","aria-live":"assertive",className:"lk-alert",children:[t,void 0!==n?(0,a.jsx)("button",{type:"button",onClick:n,"aria-label":"Retry loading capsules",className:"lk-alert-retry",children:"Retry"}):null,void 0!==l?(0,a.jsx)("button",{type:"button",onClick:l,"aria-label":"Dismiss error message",className:"lk-alert-retry",children:"Dismiss"}):null]});}function u$(e){return Array.from(e.querySelectorAll("button:not([disabled]),input:not([disabled]),textarea:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex='-1'])"));}function uE(e){let{busy:t,error:n,onCancel:l,onSubmit:r}=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,uj.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=u$(e);if(0===a.length)return void n.preventDefault();let i=a[0],r=a[a.length-1];n.shiftKey&&document.activeElement===i?(n.preventDefault(),null==r||r.focus()):n.shiftKey||document.activeElement!==r||(n.preventDefault(),null==i||i.focus());};return e.addEventListener("keydown",n),()=>e.removeEventListener("keydown",n);},[t,l]);let b=(0,i.useRef)(!1);async function x(e){e.preventDefault();let t=h.trim();0===t.length?v("Capsule display name is required."):(v(null),await r(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=u$(e)[0])||n.focus();}}},[t]);let y=null!=g?g:n;return(0,na.createPortal)((0,a.jsx)("div",{className:"mc-dialog-backdrop",role:"presentation",children:(0,a.jsxs)("div",{ref:u,className:"mc-dialog",role:"dialog","aria-modal":"true","aria-labelledby":s,"aria-describedby":o,tabIndex:-1,children:[(0,a.jsx)("h2",{id:s,className:"mc-dialog-title",children:"Create capsule"}),(0,a.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,a.jsxs)("form",{onSubmit:e=>void x(e),children:[(0,a.jsxs)("label",{className:"mc-dialog-field",htmlFor:c,children:[(0,a.jsx)("span",{className:"mc-dialog-label",children:"Capsule display name"}),(0,a.jsx)("input",{id:c,ref:p,className:"mc-dialog-input",value:h,disabled:t,autoComplete:"off","aria-invalid":null!==y,"aria-describedby":null!==y?d:void 0,onChange:e=>{f(e.target.value),null!==g&&v(null);}})]}),null!==y?(0,a.jsx)("div",{id:d,role:"alert","aria-live":"assertive",className:"mc-dialog-error",children:y}):null,(0,a.jsxs)("div",{className:"mc-dialog-actions",children:[(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost",disabled:t,onClick:l,children:"Cancel"}),(0,a.jsx)("button",{type:"submit",className:"lk-btn lk-btn-primary",disabled:t,children:t?"Creating…":"Create capsule"})]})]})]})}),document.body);}function uA(e){let{capsuleName:t,onCancel:n,onConfirm:l}=e,r=(0,i.useId)(),s=(0,i.useId)(),o=(0,i.useRef)(null);return(0,uj.i)(),(0,i.useEffect)(()=>{var e;let t=document.activeElement,n=o.current;return null!==n&&(null==(e=u$(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=u$(e);if(0===l.length)return void t.preventDefault();let a=l[0],i=l[l.length-1];t.shiftKey&&document.activeElement===a?(t.preventDefault(),null==i||i.focus()):t.shiftKey||document.activeElement!==i||(t.preventDefault(),null==a||a.focus());};return e.addEventListener("keydown",t),()=>e.removeEventListener("keydown",t);},[n]),(0,na.createPortal)((0,a.jsx)("div",{className:"mc-dialog-backdrop",role:"presentation",children:(0,a.jsxs)("div",{ref:o,className:"mc-dialog",role:"dialog","aria-modal":"true","aria-labelledby":r,"aria-describedby":s,tabIndex:-1,children:[(0,a.jsx)("h2",{id:r,className:"mc-dialog-title",children:"Disconnect capsule"}),(0,a.jsxs)("p",{id:s,className:"mc-dialog-body",children:['Disconnect "',t,'"? The capsule keeps its index, but the source link is removed.']}),(0,a.jsxs)("div",{className:"mc-dialog-actions",children:[(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-ghost",onClick:n,children:"Cancel"}),(0,a.jsx)("button",{type:"button",className:"lk-btn lk-btn-danger",onClick:l,children:"Disconnect"})]})]})}),document.body);}function uF(e){let{state:t}=e;return(0,a.jsx)("span",{className:"lk-badge","data-state":t,children:uw.Z[t]});}function uT(e){let{capsule:t,busy:n,busyKind:l,onStart:r,onCancel:s}=e,{id:o,displayName:c,lifecycleState:d,sourceCount:u}=t,p=(0,i.useId)();if("indexing"===d)return(0,a.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,a.jsxs)(a.Fragment,{children:[(0,a.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&&r(o);},className:"lk-btn lk-btn-primary",children:"index"===l?"Indexing…":"Index"}),m?null:(0,a.jsx)("span",{id:p,className:"visually-hidden",children:"Attach a source before indexing."})]});}function uD(e){let{capsule:t,busy:n,busyKind:l,onStart:i,onCancel:r,onDisconnect:s,onHealth:o,onAddToWorkspace:c}=e,{id:d,displayName:u}=t;return(0,a.jsxs)("div",{role:"group","aria-label":`Actions for capsule ${u}`,className:"lk-capsule-actions",children:[(0,a.jsx)(uT,{capsule:t,busy:n,busyKind:l,onStart:i,onCancel:r}),(0,a.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,a.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,a.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 uM(e){return e instanceof Element&&null!==e.closest(".lk-capsule-actions,a,input,select,textarea");}function uP(e,t){let n=document.elementFromPoint(e,t);return n instanceof Element&&null!==n.closest("main.workspace")&&null===n.closest(".window");}function uq(e,t){let n={payload:e,clientX:t.clientX,clientY:t.clientY};window.dispatchEvent(new CustomEvent(tU,{detail:n}));}function uL(e){let{capsule:t,busy:n,busyKind:l,onStart:r,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,uq(f,e),window.setTimeout(()=>{h.current=!1;},250));},v=(e,n)=>{m.current=!0;let l=!1,a=a=>{let i=a.clientX-e,r=a.clientY-n;!l&&6>Math.hypot(i,r)||(l=!0,document.body.style.cursor="grabbing",p({x:a.clientX,y:a.clientY,label:t.displayName,state:t.lifecycleState}));},i=e=>{window.removeEventListener("pointermove",a),window.removeEventListener("pointerup",i),window.removeEventListener("mousemove",a),window.removeEventListener("mouseup",i),m.current=!1,document.body.style.cursor="",p(null),l&&uP(e.clientX,e.clientY)&&g(e);};window.addEventListener("pointermove",a),window.addEventListener("pointerup",i),window.addEventListener("mousemove",a),window.addEventListener("mouseup",i);};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("article",{"aria-label":`Capsule: ${t.displayName}`,className:"lk-capsule-row",children:[(0,a.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=>{uM(e.target)||U(e)&&(e.preventDefault(),e.stopPropagation(),v(e.clientX,e.clientY));},onMouseDown:e=>{m.current||uM(e.target)||U(e)&&(e.preventDefault(),e.stopPropagation(),v(e.clientX,e.clientY));},onDragStart:e=>{uM(e.target)?e.preventDefault():(e.dataTransfer.effectAllowed="copy",e.dataTransfer.setData(tB,JSON.stringify(f)),e.dataTransfer.setData("text/plain",t.displayName));},onDragEnd:e=>{uP(e.clientX,e.clientY)&&g(e);},draggable:!0,children:[(0,a.jsx)("span",{"aria-hidden":"true",className:"lk-capsule-icon",children:"⬡"}),(0,a.jsxs)("span",{className:"lk-capsule-info",children:[(0,a.jsx)("span",{className:"lk-capsule-name",title:t.displayName,children:t.displayName}),(0,a.jsx)(uF,{state:t.lifecycleState})]})]}),(0,a.jsx)(uD,{capsule:t,busy:n,busyKind:l,onStart:r,onCancel:s,onDisconnect:o,onHealth:c,onAddToWorkspace:d})]}),null!==u?(0,na.createPortal)((0,a.jsxs)("div",{className:"lk-connector-drag-ghost",style:{left:u.x+14,top:u.y+14},"aria-hidden":"true",children:[(0,a.jsx)("span",{className:"lk-connector-drag-ghost-icon",children:"▣"}),(0,a.jsxs)("span",{className:"lk-connector-drag-ghost-copy",children:[(0,a.jsx)("span",{children:u.label}),(0,a.jsx)("small",{children:uw.Z[u.state]})]})]}),document.body):null]});}function uz(e){let{creating:t,onCreateCapsule:n}=e;return(0,a.jsxs)("div",{"data-testid":"empty-state",className:"lk-empty",children:[(0,a.jsx)("span",{"aria-hidden":"true",className:"lk-empty-icon",children:"⬡"}),(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"lk-empty-title",children:"No capsules yet"}),(0,a.jsx)("p",{className:"lk-empty-body",children:"Create a capsule to start indexing your local knowledge sources."})]}),(0,a.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 uO(e){let{capsules:t,isLoading:n,creating:l,actionBusy:i,actionKind:r,onCreateCapsule:s,onStartIndexing:o,onCancelIndexing:c,onDisconnect:d,onOpenHealth:u}=e;return n?(0,a.jsx)("p",{role:"status","aria-live":"polite",className:"lk-loading",children:"Loading capsules…"}):0===t.length?(0,a.jsx)(uz,{creating:l,onCreateCapsule:s}):(0,a.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,a.jsx)("li",{style:{display:"block"},children:(0,a.jsx)(uL,{capsule:e,busy:i===e.id,busyKind:i===e.id?r: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&&uq({kind:"capsule",id:e.id,label:e.displayName,lifecycleState:e.lifecycleState},t);}})},e.id))});}function uK(e){let{creating:t,createDialogOpen:n,combineDialogOpen:l,combineDisabled:r,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,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("header",{className:"lk-header",children:[(0,a.jsx)("h1",{className:"lk-title",children:"Local Knowledge Connector"}),(0,a.jsxs)("div",{className:"lk-header-actions",children:[s?(0,a.jsx)(dz(),{href:"/",className:"lk-btn lk-btn-ghost lk-btn-lg",children:"Back to Workspace"}):null,(0,a.jsx)("button",{type:"button","aria-disabled":r,"aria-describedby":r?v:void 0,"aria-label":"Combine capsules into a set","aria-haspopup":"dialog","aria-expanded":l,title:r?"Create capsules first, then combine them into a set.":void 0,onClick:()=>{r||h();},className:"lk-btn lk-btn-ghost lk-btn-lg",children:"Combine capsules"}),r?(0,a.jsx)("span",{id:v,className:"visually-hidden",children:"Create capsules first, then combine them into a set."}):null,(0,a.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,a.jsx)(uR,{message:c,onRetry:p}):null,null===u||n?null:(0,a.jsx)(uR,{message:u,onDismiss:f}),null!==d?(0,a.jsx)(uR,{message:d,onDismiss:g}):null]});}function uW(e){let t,n,{onOpenCapsule:l,showBackToWorkspace:r=!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:x,clearActionError:y,handleStartIndexing:j,handleCancelIndexing:w,handleDisconnect:k,handleOpenHealth:N,handleCreateCapsule:S}=function(e){let{fetchCapsulesImpl:t=ik.xr,createCapsuleImpl:n=ik.qY,startIndexingImpl:l=ik.r,cancelIndexingImpl:a=ik.Tq,disconnectCapsuleImpl:r=ik.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,uk.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:x}=function(e,t,n,l,a){let r=(0,uu.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,uk.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:y,createError:j,clearCreateError:w,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,uk.W)(e));}finally{l(!1);}}};}(n,u);return{capsules:o,loadStatus:c,loadError:d,actionBusy:p,actionKind:m,actionError:h,creating:y,createError:j,reload:u,clearCreateError:w,clearActionError:f,handleStartIndexing:g,handleCancelIndexing:v,handleDisconnect:b,handleOpenHealth:x,handleCreateCapsule:k};}({...e,onOpenCapsule:c}),C="loading"===u,[I,R]=(0,i.useState)(!1),[$,E]=(0,i.useState)(!1),[A,F]=(0,i.useState)(null);async function T(e){try{await S(e),R(!1);}catch{}}return null!==s&&void 0===l?(0,a.jsxs)("div",{className:"lk-page",children:[(0,a.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,a.jsx)(uI.CapsuleDetail,{capsuleId:s,onDeleted:()=>{o(null),b();}})]}):(0,a.jsxs)("div",{className:"lk-page",children:[(0,a.jsx)(uK,{creating:g,createDialogOpen:I,combineDialogOpen:$,combineDisabled:C||0===d.length,showBackToWorkspace:r,loadStatus:u,loadError:p,actionError:f,createError:v,reload:b,onCreateCapsule:()=>R(!0),onCombineCapsules:()=>E(!0),onDismissCreateError:x,onDismissActionError:y}),(0,a.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,a.jsxs)("section",{"aria-label":"Knowledge capsules","aria-busy":C,style:{flex:1,minHeight:0,overflowY:"auto"},children:[(0,a.jsx)("h2",{className:"lk-section-head",children:"Knowledge Capsules"}),(0,a.jsx)(uO,{capsules:d,isLoading:C,creating:g,actionBusy:m,actionKind:h,onCreateCapsule:()=>R(!0),onStartIndexing:j,onCancelIndexing:w,onDisconnect:e=>{var t;return F(null!=(t=d.find(t=>t.id===e))?t:null);},onOpenHealth:N})]}),I?(0,a.jsx)(uE,{busy:g,error:v,onCancel:()=>{R(!1),x();},onSubmit:T}):null,$?(0,a.jsx)(uC,{capsules:d,onCancel:()=>E(!1),onCreated:function(){E(!1),b();}}):null,null!==A?(0,a.jsx)(uA,{capsuleName:A.displayName,onCancel:()=>F(null),onConfirm:()=>{k(A.id),F(null);}}):null]});}function uB(e,t){let n=e[t];return"string"==typeof n?n:void 0;}function uU(e,t){let n=e[t];return"number"==typeof n&&Number.isFinite(n)?n:void 0;}function u_(e,t){let n=uB(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 uV(e){let{cfg:t,ctx:n}=e,l=lS({autoCreate:!1}),r=(0,i.useRef)(!1),o=uB(t,"chatId"),c=uB(t,"title"),{updateCfg:d}=n,{activeChat:u,activeProject:p,chats:m,loading:h,openChat:f,openNewChat:g}=l,v=void 0!==u&&"closed"!==u.status?u:void 0;(0,i.useEffect)(()=>{if(!h){if(void 0!==o){if((null==v?void 0:v.id)===o)return;let e=m.find(e=>e.id===o&&"closed"!==e.status);void 0!==e&&f(e);return;}r.current||(r.current=!0,g(void 0,c).then(e=>{void 0!==e&&d({chatId:e.id,title:e.title});}).finally(()=>{r.current=!1;}));}},[o,null==v?void 0:v.id,m,h,f,g,c,d]),(0,i.useEffect)(()=>{h||void 0===o||(null==v?void 0:v.id)!==o||v.title!==c&&d({title:v.title});},[null==v?void 0:v.id,null==v?void 0:v.title,o,h,c,d]);let b=void 0!==o&&!l.loading&&(null==v?void 0:v.id)!==o&&!l.chats.some(e=>e.id===o&&"closed"!==e.status),x=l.loading||void 0!==o&&(null==v?void 0:v.id)!==o,y=(0,i.useCallback)(e=>{var t;if(void 0===e.runId)return;let l={runId:e.runId},a=null!=(t=e.workflowId)?t:e.taskType;void 0!==a&&(l.workflow=a),(null==p?void 0:p.path)!==void 0&&(l.workspaceRoot=p.path),n.openWindow("agents",l);},[null==p?void 0:p.path,n]);return(0,a.jsx)(s,{value:l,children:b?(0,a.jsxs)("div",{className:"lk-empty",children:[(0,a.jsx)("p",{className:"lk-empty-title",children:"Chat not found"}),(0,a.jsx)("p",{className:"lk-empty-body",children:"This conversation was deleted or is no longer available."})]}):x?(0,a.jsx)("div",{className:"lk-loading",children:"Opening chat..."}):(0,a.jsx)(i4,{mini:!0===n.mini,minimalChat:!0===n.minimalChat,compact:!0===n.compact,controlsNarrow:!0===n.controlsNarrow,barCompact:!0===n.barCompact,workflowCompact:!0===n.workflowCompact,linkedRoot:n.linkedRoot,linkedRoots:n.linkedRoots,openEditorFile:n.openEditorFile,onOpenRunResult:y})});}$("chat",(e,t)=>(0,a.jsx)(uV,{cfg:e,ctx:t})),$("chatHistory",(e,t)=>(0,a.jsx)(i7,{openChatWindow:e=>{t.openWindow("chat",{chatId:e.id,title:e.title});}})),$("project",()=>(0,a.jsx)(i8,{})),$("promptEnhancer",(e,t)=>{var n;return(0,a.jsx)(rk,{connectedRoot:t.linkedRoot,connectedFilePath:null!=(n=t.linkedFilePath)?n:null,connectedRoots:t.linkedRoots});}),$("search",()=>(0,a.jsx)(i9,{})),$("plugins",()=>(0,a.jsx)(rI,{})),$("automations",()=>(0,a.jsx)(rF,{})),$("mobile",()=>(0,a.jsx)(rT,{})),$("inspector",()=>(0,a.jsx)(rD,{})),$("notifications",()=>(0,a.jsx)(rP,{})),$("resources",()=>(0,a.jsx)(rq,{})),$("activity",()=>(0,a.jsx)(rO,{})),$("keiko",()=>(0,a.jsx)(sK,{})),$("settings",()=>(0,a.jsx)(sQ,{})),$("localKnowledge",()=>(0,a.jsx)(uW,{showBackToWorkspace:!1})),$("quality",(e,t)=>{var n;return(0,a.jsx)(co,{openRun:(e,n)=>{var l;let a=void 0!==n?{[re]:JSON.stringify(n.filter(rl))}:ra(ro({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});}),$("qiRun",(e,t)=>{let n=uB(e,"runId");if(void 0===n||""===n)return(0,a.jsx)("div",{className:"lk-empty",children:(0,a.jsx)("p",{className:"lk-empty-body",children:"Open a run from the Quality Intelligence hub."})});let l=function(e){var t,n;let l=rt(e,re);if(void 0!==l&&l.length>0){let e=function(e){try{let t=JSON.parse(e);if(!Array.isArray(t)||!t.every(rl))return null;return t;}catch{return null;}}(l);if(null!==e)return e;}return ro({connectedFilePath:null!=(t=rt(e,"connectedFilePath"))?t:null,connectedRoot:null!=(n=rt(e,"connectedRoot"))?n:null});}(e),i=ra(l);return(0,a.jsx)(cH,{runId:n,connectedSources:l,onRegenerated:e=>{t.openWindow("qiRun",{runId:e.runId,...i});}});}),$("relationships",()=>(0,a.jsx)(dq,{})),$("files",(e,t)=>{let n=uB(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);},i=e=>{t.updateCfg({root:e,activeFilePath:void 0,activeDirectoryPath:void 0,resolvedRoot:void 0});},r=(e,n)=>{t.openWindow("editor",{root:e,file:n,openFiles:[n]});};return void 0!==n?(0,a.jsx)(rY,{root:n,onActiveFileChange:l,onRootChange:i,onOpenFile:r}):(0,a.jsx)(rY,{onActiveFileChange:l,onRootChange:i,onOpenFile:r});}),$("editor",(e,t)=>{let n=uB(e,"root"),l=uB(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"),r=uB(e,"layoutJson"),s=uU(e,"revealLineStart"),o=uU(e,"revealLineEnd"),c=uB(e,"revealRequestId"),d={};return void 0!==n&&(d.root=n),void 0!==l&&(d.file=l),void 0!==i&&(d.openFiles=i),void 0!==r&&(d.layoutJson=r),void 0!==s&&(d.revealLineStart=s),void 0!==o&&(d.revealLineEnd=o),void 0!==c&&(d.revealRequestId=c),d.linkedRoot=t.linkedRoot,d.linkedFilePath=t.linkedFilePath,d.linkedCapsuleIds=t.linkedCapsuleIds,d.linkedCapsuleSetIds=t.linkedCapsuleSetIds,d.windowId=t.windowId,d.onWorkspaceChange=e=>{t.updateCfg(e);},(0,a.jsx)(r5,{...d});}),$("browser",e=>{let t=uB(e,"url");return void 0!==t&&""!==t?(0,a.jsx)(si,{url:t}):(0,a.jsx)(si,{});}),$("terminal",e=>{let t=uB(e,"cwd"),n=uB(e,"projectPath"),l={};return void 0!==t&&(l.cwd=t),void 0!==n&&(l.projectPath=n),(0,a.jsx)(sp,{...l});}),$("review",(e,t)=>{let n=uB(e,"runId"),l=e=>{t.updateCfg({runId:e});};return void 0!==n&&""!==n?(0,a.jsx)(sw,{runId:n,onRunIdSubmit:l}):(0,a.jsx)(sw,{onRunIdSubmit:l});}),$("agents",(e,t)=>{var n;let l,i,r,s,o,c,d,u,p,m,h;return(0,a.jsx)(sR,{cfg:(r={},void 0!==(s=uB(n=e,"workflow"))&&(r.workflow=s),void 0!==(o=uB(n,"model"))&&(r.model=o),void 0!==(c=uB(n,"runId"))&&(r.runId=c),void 0!==(d=uB(n,"fingerprint"))&&(r.fingerprint=d),void 0!==(u=uB(n,"workspaceRoot"))&&(r.workspaceRoot=u),void 0!==(p=uB(n,"inputJson"))&&(r.inputJson=p),void 0!==(m="boolean"==typeof(l=n.keikoMode)?l:void 0)&&(r.keikoMode=m),void 0!==(h="ask"===(i=n.access)||"full"===i?i:void 0)&&(r.access=h),r),linkedRoot:t.linkedRoot,linkedFilePath:t.linkedFilePath});}),$("memoria",()=>(0,a.jsx)(uy,{})),$("integ",()=>(0,a.jsx)(sE,{})),$("figma",(e,t)=>{let n=uB(e,"snapshotRunId"),l=u_(e,"selectedScreenIdsJson"),i=uB(e,"selectedScreenName");return(0,a.jsx)(oR,{sourceWindowId:t.windowId,snapshotRunId:n,selectedScreenIds:l,selectedScreenName:i,openScreenSource:e=>{let{snapshotRunId:n,screenId:l,name:a}=e;t.openWindow("figmaView",{snapshotRunId:n,selectedScreenIdsJson:JSON.stringify([l]),selectedScreenName:a});},updateCfg:e=>{t.updateCfg(e);}});}),$("figmaView",(e,t)=>{let n=uB(e,"snapshotRunId"),l=u_(e,"selectedScreenIdsJson"),i=uB(e,"selectedScreenName");return(0,a.jsx)(oR,{sourceWindowId:t.windowId,snapshotRunId:n,selectedScreenIds:l,selectedScreenName:i,updateCfg:e=>{t.updateCfg(e);}});}),$("figmaJson",e=>{let t=uB(e,"snapshotRunId"),n=uB(e,"screenId"),l=uB(e,"selectedScreenName");return(0,a.jsx)(o$,{snapshotRunId:t,screenId:n,screenName:l});}),$("figmaImage",e=>{let t=uB(e,"imageSrc"),n=uB(e,"selectedScreenName");return(0,a.jsx)(oE,{imageSrc:t,screenName:n});}),$("connector",(e,t)=>{let n=uB(e,"presentation"),l=uB(e,"selectedKind"),i=uB(e,"selectedId"),r=uB(e,"selectedLabel"),s=uB(e,"selectedState");return(0,a.jsx)(s5,{presentation:n,selectedKind:l,selectedId:i,selectedLabel:r,selectedState:s,onSelect:e=>{t.updateCfg(e);},onManageConnectors:()=>{t.openWindow("localKnowledge");}});});let uJ={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 uH(){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),[r]=(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"===r&&!e||"supported"!==r&&"ios-add-to-home"!==r)return null;let u=uJ[r];return(0,a.jsx)("aside",{className:"install-banner",role:"region","aria-label":"Install Keiko",onKeyDown:d,children:(0,a.jsxs)("div",{className:"install-banner-body",children:[(0,a.jsxs)("div",{className:"install-banner-text",children:[(0,a.jsx)("span",{className:"install-banner-heading",children:u.heading}),(0,a.jsx)("span",{className:"install-banner-desc",children:u.body})]}),(0,a.jsxs)("div",{className:"install-banner-actions",children:[null!==u.install&&(0,a.jsx)("button",{ref:s,type:"button",className:"install-banner-btn-install",onClick:()=>void c(),children:u.install}),(0,a.jsx)("button",{type:"button",className:"install-banner-btn-dismiss",onClick:o,children:"Not now"})]})]})});}let uY="keiko.service-worker-update-reload-pending",uX=!1;function uG(){uX||function(){try{if("true"!==window.sessionStorage.getItem(uY))return!1;return window.sessionStorage.removeItem(uY),!0;}catch{return!0;}}()&&(uX=!0,window.location.reload());}function uQ(e){let t=e.waiting;if(null!==t){try{window.sessionStorage.setItem(uY,"true");}catch{}try{t.postMessage({type:"KEIKO_ACTIVATE_WAITING_SERVICE_WORKER"});}catch{try{window.sessionStorage.removeItem(uY);}catch{}}}}function uZ(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 u0(e){return e.trim().replace(/\\/gu,"/").replace(/\/+$/u,"");}function u1(e,t){let n=u0(e),l=u0(t);if(0===l.length)return"";if(0===n.length)return /^\/+$/u.test(e.trim().replace(/\\/gu,"/"))?l.replace(/^\/+/u,""):"";let a=n.toLowerCase(),i=l.toLowerCase();return i===a?"":i.startsWith(`${a}/`)?l.slice(n.length+1).replace(/^\/+/u,""):null;}let u2=["chat","connector","files","editor","agents"],u4=["chatHistory","memoria","settings","automations","mobile","inspector","activity","notifications","resources","localKnowledge","figma","quality","promptEnhancer","relationships"];function u3(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 u5(){var e,t,n,l,r,o,c,d,u,p;let m,{theme:h,toggle:f}=function(){let[e,t]=(0,i.useState)(lI),[n,l]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{t(function(){try{let e=window.localStorage.getItem(lC);return"light"===e||"dark"===e?e:lI;}catch{return lI;}}()),l(!0);},[]),(0,i.useEffect)(()=>{if(n){"u">typeof document&&(document.documentElement.dataset.theme=e);try{window.localStorage.setItem(lC,e);}catch{}}},[e,n]),{theme:e,toggle:(0,i.useCallback)(()=>{t(e=>"light"===e?"dark":"light");},[])};}(),g=j(),v=lS({autoCreate:!1}),b=(0,i.useRef)(null),x=(0,i.useRef)(null),[y,N]=(0,i.useState)(nH.ty);(0,i.useEffect)(()=>{(0,k.Dz)().then(e=>N(e.effectiveGroundingLimits)).catch(()=>void 0);},[]);let[S,C]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(null===S)return;let e=window.setTimeout(()=>C(null),1e4);return()=>window.clearTimeout(e);},[S]);let I=(0,i.useCallback)((e,t)=>(C(`Source limit reached — this chat already has ${String(e)} of ${String(t)} connected sources. Disconnect a source before connecting another.`),!1),[]),R=(0,i.useCallback)(e=>(C(e),!1),[]),$=(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=x.current)?void 0:n.find(t=>t.id===e));if(void 0===a)return;let i=null!=(t=v.chats.find(e=>e.id===a))?t:(null==(l=v.activeChat)?void 0:l.id)===a?v.activeChat:void 0;return(null==i?void 0:i.status)==="closed"?void 0:i;},[v.activeChat,v.chats]),A=(0,i.useCallback)(async function(e,t){var n;let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=$(e);if(void 0===a)return R("Open a ready chat window before connecting a source.");let i=null===l?tR(a):tI(tR(a),l),r=t$(a);if(i.some(e=>tk(e,t))){if(null!==l){let e=await(0,k.Mr)(a.id,i.length>0?i:null);v.replaceChat(e.chat);}return!0;}let s=tC(y);if(i.length+r.length>=s)return I(i.length+r.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=ty(t.root);if(!tx(l))return null;let a=t.relativePaths.map(tw),i={kind:t.kind,relativePaths:a,root:l,connectedAtMs:t.connectedAtMs};return e.some(e=>tk(e,i))||e.length>=n?e:[...e,i];}(i,o,y.maxConnectedSources);if(null===c)return R("Choose a local folder before connecting it to chat.");if(c===i)return I(i.length+r.length,s);try{let e=await(0,k.Mr)(a.id,c);v.replaceChat(e.chat),C(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&&lz({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 R("Keiko could not connect that source. Check that it is still available and try again.");}},[$,v,y,I,R]),T=function(e){var t,n,l,a,r,s,o,c,d;let u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},[p,m]=(0,i.useState)(null),[h,f]=(0,i.useState)(null),[g,v]=(0,i.useState)(!1),[b,x]=(0,i.useState)([]),[y,j]=(0,i.useState)(null),[w,k]=(0,i.useState)(tP),N=(0,i.useRef)(3),S=(0,i.useRef)(null),C=(0,i.useRef)([]);C.current=null!=p?p:[];let I=(0,i.useRef)([]);I.current=b;let R=(0,i.useRef)(null);R.current=y;let $=(0,i.useRef)(null),A=(0,i.useRef)(()=>void 0),{viewRef:T,worldVP:M,zoomTo:P,fitView:q,resetView:L,panBy:z,rect:O}=function(e){let{wsRef:t,view:n,winsRef:l,setView:a,setWins:r}=e,s=(0,i.useRef)(n);s.current=n;let o=(0,i.useRef)(null),c=(0,i.useRef)(null);(0,i.useEffect)(()=>{tO(tM,n);},[n]),(0,i.useEffect)(()=>()=>{null!==c.current&&"function"==typeof window.cancelAnimationFrame&&window.cancelAnimationFrame(c.current);},[]);let d=(0,i.useCallback)(e=>{var t;let n=null!=(t=o.current)?t:s.current,l="function"==typeof e?e(n):e;if(s.current=l,o.current=l,"function"!=typeof window.requestAnimationFrame||"function"!=typeof window.cancelAnimationFrame){o.current=null,a(l);return;}null===c.current&&(c.current=window.requestAnimationFrame(()=>{c.current=null;let e=o.current;o.current=null,null!==e&&a(e);}));},[a]);(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 i=(n=t.target)instanceof Element&&null!=(l=null==(a=n.closest(".window[data-window-id]"))?void 0:a.dataset.windowId)?l:null;if(null!==i)return void r(e=>null===e?e:e.map(e=>{var n,l,a;let r,s;return e.id===i?(n=e,l=t.deltaY,(s=tL((r=null!=(a=n.zoom)?a:1)*Math.exp(-(.0015*l))))===r?n:{...n,zoom:s}):e;}));let o=e.getBoundingClientRect(),c=s.current,u=tK(t),p=tq(c.zoom*Math.exp(-(.0015*u.y))),m=(t.clientX-o.left-c.x)/c.zoom,h=(t.clientY-o.top-c.y)/c.zoom;return void d({zoom:p,x:t.clientX-o.left-m*p,y:t.clientY-o.top-h*p});}let i=t.target;if(i instanceof Element&&null!==i.closest(".window"))return;t.preventDefault();let o=tK(t);d(e=>({...e,x:e.x-o.x,y:e.y-o.y}));};return e.addEventListener("wheel",n,{passive:!1}),()=>{e.removeEventListener("wheel",n);};},[t,r,d]);let u=(0,i.useCallback)(()=>null===t.current?null:t.current.getBoundingClientRect(),[t]),p=(0,i.useCallback)(()=>{let e=u();if(null===e)return null;let t=s.current;return{x:-t.x/t.zoom,y:-t.y/t.zoom,w:e.width/t.zoom,h:e.height/t.zoom};},[u]),m=(0,i.useCallback)(e=>{let t=u();if(null===t)return;let n=s.current,l=t.width/2,a=t.height/2,i=(l-n.x)/n.zoom,r=(a-n.y)/n.zoom,o=tq(e);d({zoom:o,x:l-i*o,y:a-r*o});},[u,d]),h=(0,i.useCallback)(()=>{let e=u();null!==e&&d(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,i=-1/0,r=-1/0;for(let e of n)l=Math.min(l,e.x),a=Math.min(a,e.y),i=Math.max(i,e.x+e.w),r=Math.max(r,e.y+e.h);let s=Math.max(1,i-l),o=Math.max(1,r-a),c=tq(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)};}(l.current,e));},[u,l,d]);return{viewRef:s,worldVP:p,zoomTo:m,fitView:h,resetView:(0,i.useCallback)(()=>d({zoom:1,x:0,y:0}),[d]),panBy:(0,i.useCallback)((e,t)=>d(n=>({...n,x:n.x+e,y:n.y+t})),[d]),rect:u};}({wsRef:e,view:w,winsRef:C,setView:k,setWins:m});!function(e){let{wsRef:t,setWins:n,setConns:l,zc:a}=e;(0,i.useLayoutEffect)(()=>{let e=t.current;if(null===e)return;e.getBoundingClientRect();let i=null;try{i=function(e){if(null===e)return null;try{let t=JSON.parse(e);if(!Array.isArray(t)||0===t.length)return null;let n=eV(t);return n.length>0?n:null;}catch{return null;}}(window.localStorage.getItem(tT));}catch{i=null;}null===i&&(i=[]),a.current=0===i.length?1:Math.max(1,...i.map(e=>e.z)),n(i);try{l(function(e,t){if(null===e)return[];try{let n=JSON.parse(e);if(!Array.isArray(n))return[];return eJ(n,t);}catch{return[];}}(window.localStorage.getItem(tD),i));}catch{}},[t,n,l,a]);}({wsRef:e,setWins:m,setConns:x,zc:N}),(0,i.useEffect)(()=>{null!==p&&tO(tD,eJ(b,p));},[b,p]),(0,i.useEffect)(()=>{null!==p&&x(e=>{let t=e.filter(e=>void 0!==p.find(t=>t.id===e.a)&&void 0!==p.find(t=>t.id===e.b));return t.length===e.length?e:t;});},[p,x]),(0,i.useEffect)(()=>{null!==p&&tO(tT,eV(p));},[p]),function(e){let{setWins:t,rect:n,cancelConnectRef:l}=e;(0,i.useEffect)(()=>{let e=e=>{var a,i;if("Escape"===e.key)return void l.current();if(null!==(a=document.activeElement)&&("INPUT"===a.tagName||"TEXTAREA"===a.tagName||"SELECT"===a.tagName))return;let r=tW[e.code];if((e.metaKey||e.ctrlKey)&&e.altKey&&void 0!==r){e.preventDefault(),t(e=>{var t,n;if(null===e||0===e.length)return e;let l=tz(e);if(null===l)return e;let a=(n=null!=(t=l.zoom)?t:1,"0"===r?1:"-"===r||"_"===r?tL(n-.1):tL(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&&(i={key:e.key,shift:e.shiftKey},t(e=>{let t,n,l,a,r,s,d;if(null===e||0===e.length)return e;let u=tz(e);if(null===u)return e;let p=o?(t=i.shift?1:16,n=u.w,l=u.h,"ArrowRight"===i.key?n+=t:"ArrowLeft"===i.key?n-=t:"ArrowDown"===i.key?l+=t:"ArrowUp"===i.key&&(l-=t),n=Math.max((a=E[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}):(r=i.shift?1:16,s=u.x,d=u.y,"ArrowRight"===i.key?s+=r:"ArrowLeft"===i.key?s-=r:"ArrowDown"===i.key?d+=r:"ArrowUp"===i.key&&(d-=r),{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:m,rect:O,cancelConnectRef:A}),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,i={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,i)));});return a.observe(e),()=>{a.disconnect();};},[t,n,l]);}({wsRef:e,viewRef:T,setWins:m});let{update:K,focus:W,close:B,minimize:U,restore:_,maximize:V,add:J,openEditorFile:H,toggleTool:Y}={update:(n=(t={setWins:m,zc:N,worldVP:M,winsRef:C}).setWins,(e,t)=>n(n=>{if(null===n)return n;let l=!1,a=n.map(n=>{if(n.id!==e)return n;for(let[e,a]of Object.entries(t))if(n[e]!==a)return l=!0,{...n,...t};return n;});return l?a:n;})),focus:(l=t.setWins,a=t.zc,e=>l(t=>null===t?t:t.map(t=>t.id===e?{...t,z:++a.current}:t))),close:(r=t.setWins,e=>r(t=>null===t?t:t.filter(t=>t.id!==e))),minimize:(s=t.setWins,e=>s(t=>null===t?t:t.map(t=>t.id===e?{...t,minimized:!0}:t))),restore:(o=t.setWins,c=t.zc,e=>o(t=>null===t?t:t.map(t=>t.id===e?{...t,minimized:!1,z:++c.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,i;let e,r,s,o=null!=(l=t.prev)?l:(i=t.type,r=Math.min((e=E[i]).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-r)/2)),y:a.y+Math.max(16,Math.round((a.h-s)/2)),w:r,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};});});}(t),add:function(e){let{setWins:t,zc:n,worldVP:l}=e;return(e,a)=>{let i=E[e],r="figma"===e&&"string"==typeof(null==a?void 0:a.selectedScreenIdsJson)&&a.selectedScreenIdsJson.length>0,s=r?360:i.w,o=r?360:i.h,c=r?Math.max(i.min.w,300):i.min.w,d=r?Math.max(i.min.h,260):i.min.h,u=null;return t(t=>{let r=l();if(null===r)return t;let p=null!=t?t:[];if(!0===i.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,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}=tp(r,s,o,p.length,40),v=!0===i.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;};}(t),openEditorFile:function(e){let{setWins:t,zc:n,worldVP:l,winsRef:a}=e;return e=>{var i;let{root:r,path:s,lineStart:o,lineEnd:c}=e,d=tm(r),u=th(s);if(0===d.length)return{ok:!1,message:"Select a repository source before opening file references."};if(0===u.length||u.includes(".."))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!=(i=null==a?void 0:a.current)?i:[],f=h.find(e=>"editor"===e.type&&tm("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 i,r;if(t.id!==e)return t;let s=(l=t.cfg,r=td(i=e5({root:d,file:th(null!=(a=tf(l,"file"))?a:""),openFiles:function(e,t){let n=[],l=e=>{if("string"!=typeof e)return;let t=th(e);0===t.length||n.includes(t)||n.push(t);};if(Array.isArray(e.openFiles))for(let t of e.openFiles)l(t);return l(e.file),l(t),n;}(l,u),layoutJson:tf(l,"layoutJson"),defaultSidebarWidth:260,minSidebarWidth:180,maxSidebarWidth:440}),{type:"open-file",paneId:e9(i).id,file:u}),{file:u,openFiles:tu(r),layoutJson:e6(r)});return{...t,minimized:!1,z:++n.current,cfg:{...t.cfg,root:d,...s,...m}};})),{ok:!0,windowId:e};}let g=E.editor,{x:v,y:b}=tp(p,g.w,g.h,h.length,40),x=`editor-${Date.now().toString(36)}`;return t(e=>[...(null!=e?e:[]),{id:x,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:e6(e5({root:d,file:u,openFiles:[u],defaultSidebarWidth:260,minSidebarWidth:180,maxSidebarWidth:440})),...m},max:!1,zoom:1}]),{ok:!0,windowId:x};};}(t),toggleTool:function(e){let{setWins:t,zc:n,worldVP:l}=e;return e=>{let a=E[e];t(t=>{let i=l();if(null===i)return t;let r=null!=t?t:[],s=r.find(t=>t.type===e);if(void 0!==s&&!0===s.minimized)return r.map(e=>e.id===s.id?{...e,minimized:!1,z:++n.current}:e);if(void 0!==s)return r.filter(t=>t.type!==e);let{x:o,y:c}=tp(i,a.w,a.h,r.length,28);return[...r,{id:e,type:e,x:o,y:c,w:a.w,h:a.h,z:++n.current,cfg:{},max:!1,zoom:1}];});};}(t)},{tileAll:X,splitFront:G,cascade:Q}={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)),i=Math.ceil(l/a),r=(t.w-12*(a+1))/a,s=(t.h-12*(i+1))/i;return e.map((e,n)=>{let l=Math.floor(n/a);return{...tg(e),max:!1,minimized:!1,x:t.x+12+n%a*(r+12),y:t.y+12+l*(s+12),w:r,h:s};});});}(d={setWins:m,worldVP:M}),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?{...tg(e),max:!1,minimized:!1,x:t.x,y:t.y,w:t.w/2,h:t.h}:1===n?{...tg(e),max:!1,minimized:!1,x:t.x+t.w/2,y:t.y,w:t.w/2,h:t.h}:e;});});}(d),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)=>({...tg(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}));});}(d)},{setSnap:Z,commitSnap:ee}=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(D(a)[e]);},commitSnap:e=>{let i=n.current;if(n.current=null,t(null),null===i)return;let r=l();if(null===r)return;let s={...D(r)[i],max:"maxi"===i};"maxi"===i&&(s.prev={x:r.x+40,y:r.y+40,w:480,h:360}),a(e,s);}};}({setSnapPrev:f,snapZone:S,worldVP:M,update:K}),{startConnect:et,confirmConnect:en,cancelConnect:el,removeConn:ea,connect:ei,linkedFilesRoot:er,linkedFilesContext:es,linkedAllFilesRoots:eo,linkedConnectorCapsuleIds:ec,linkedConnectorCapsuleSetIds:ed,linkedFigmaSnapshotRunIds:eu,linkedFigmaSnapshotSources:ep,linkedImageSources:em,currentFilesContext:eh}=function(e){let{wsRef:t,viewRef:n,winsRef:l,connsRef:a,connectingRef:i,connectCleanupRef:r,focus:s,setConns:o,setConnecting:c,onScopeBind:d,onScopeUnbind:u,onConnectorBind:p,onConnectorUnbind:m}=e,h=()=>{null!==r.current&&(r.current(),r.current=null),i.current=null,c(null);},f=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||!tx(l))return null;let a=e.cfg.activeFilePath;return{id:e.id,root:l,...("string"==typeof a&&a.length>0?{activeFilePath:a}:{})};},g=e=>{let t=[];for(let n of a.current){let a=n.a===e?n.b:n.b===e?n.a:null;if(null===a)continue;let i=l.current.find(e=>e.id===a);void 0!==i&&"files"===i.type&&t.push(i);}if(0===t.length)return null;let n=[...t].sort((e,t)=>t.z-e.z),i=n.find(e=>{let t=e.cfg.activeFilePath;return"string"==typeof t&&t.length>0;}),r=null!=i?i:n[0];return void 0===r?null:f(r);},v=(e,t)=>{let n=new Set(),i=[];for(let r of a.current){if(i.length>=16)break;let a=r.a===e?r.b:r.b===e?r.a:null;if(null===a)continue;let s=l.current.find(e=>e.id===a);if(void 0===s||"connector"!==s.type||s.cfg.selectedKind!==t)continue;let o=s.cfg.selectedId;"string"==typeof o&&0!==o.trim().length&&(n.has(o)||(n.add(o),i.push(o)));}return i;},b=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!==i.current&&i.current.from===e)return void h();let a=t.current;if(null===a)return;let s=a.getBoundingClientRect(),o=n.current,d=e=>(e-s.left-o.x)/o.zoom,u=e=>(e-s.top-o.y)/o.zoom;null!==r.current&&(r.current(),r.current=null);let p={from:e,x:d(l.clientX),y:u(l.clientY)};i.current=p,c(p);let m=t=>{let n={from:e,x:d(t.clientX),y:u(t.clientY)};i.current=n,c(n);};window.addEventListener("pointermove",m),r.current=()=>{window.removeEventListener("pointermove",m);};},confirmConnect:(e,t)=>{t.preventDefault(),t.stopPropagation();let n=i.current;if(null===n)return;let a=l.current,r=a.find(e=>e.id===n.from),c=a.find(t=>t.id===e);if(void 0!==r&&void 0!==c&&F(r.type,c.type)){let t,a=tN(r,c,Date.now()),i=null===a?tF(r,c):null,h=null!==a||null!==i?tb(r,c):null;try{var u,m;t=null!==a&&null!==h?null==(u=null==d?void 0:d(h,a))||u:null===i||null!==h&&(null==(m=null==p?void 0:p(h,i))||m);}catch{t=!1;}Promise.resolve(t).then(t=>{!t||l.current.some(e=>e.id===n.from)&&l.current.some(t=>t.id===e)&&(o(t=>tv(t,n.from,e)?t:[...t,{id:`${n.from}~${e}`,a:n.from,b:e,...(null!==h?{boundChatWindowId:h}:{}),...(null!==a?{boundRoot:a.root,boundScopeKind:a.kind,boundRelativePath:a.relativePaths[0]}:{}),...(null!==i?"capsule"===i.kind?{boundConnectorKind:"capsule",boundConnectorId:i.capsuleId}:{boundConnectorKind:"capsule-set",boundConnectorId:i.capsuleSetId}:{})}]),s(e));}).catch(()=>void 0);}h();},cancelConnect:h,removeConn:e=>{var t,n,i;let r=a.current.find(t=>t.id===e);if(o(t=>t.filter(t=>t.id!==e)),void 0===r)return;let s=l.current,c=s.find(e=>e.id===r.a),d=s.find(e=>e.id===r.b),p=void 0!==c&&void 0!==d,h=null!=(t=r.boundChatWindowId)?t:p?tb(c,d):null,f=null!=(n=tS(r))?n:p?tN(c,d,Date.now()):null;null!==f&&null!==h&&(null==u||u(h,f));let g=null!=(i=tA(r))?i:p?tF(c,d):null;null!==g&&null!==h&&(null==m||m(h,g));},connect:(e,t)=>{let n=l.current,a=n.find(t=>t.id===e),i=n.find(e=>e.id===t);void 0!==a&&void 0!==i&&F(a.type,i.type)&&o(n=>tv(n,e,t)?n:[...n,{id:`${e}~${t}`,a:e,b:t}]);},linkedFilesRoot:e=>{var t,n;return null!=(t=null==(n=g(e))?void 0:n.root)?t:null;},linkedFilesContext:g,linkedAllFilesRoots:e=>{let t=new Set(),n=[];for(let i of a.current){if(n.length>=16)break;let a=i.a===e?i.b:i.b===e?i.a:null;if(null===a)continue;let r=l.current.find(e=>e.id===a);if(void 0===r)continue;let s=tj(r);null===s||t.has(s)||(t.add(s),n.push(s));}return n;},linkedConnectorCapsuleIds:e=>v(e,"capsule"),linkedConnectorCapsuleSetIds:e=>v(e,"capsule-set"),linkedFigmaSnapshotRunIds:e=>{let t=new Set(),n=[];for(let i of a.current){if(n.length>=16)break;let a=i.a===e?i.b:i.b===e?i.a:null;if(null===a)continue;let r=l.current.find(e=>e.id===a);if(void 0===r||"figma"!==r.type)continue;let s=r.cfg.snapshotRunId;"string"==typeof s&&0!==s.trim().length&&(t.has(s)||(t.add(s),n.push(s)));}return n;},linkedFigmaSnapshotSources:e=>{let t=new Set(),n=[];for(let i of a.current){if(n.length>=16)break;let a=i.a===e?i.b:i.b===e?i.a:null;if(null===a)continue;let r=l.current.find(e=>e.id===a);if(void 0===r||"figma"!==r.type&&"figmaView"!==r.type&&"figmaJson"!==r.type)continue;let s=r.cfg.snapshotRunId;if("string"!=typeof s||0===s.trim().length)continue;let o=r.cfg.selectedScreenIdsJson,c=r.cfg.selectedScreenName,d=b(r);if(("figmaJson"===r.type||"figmaView"===r.type||void 0!==o||"string"==typeof c&&c.trim().length>0)&&0===d.length)continue;let u=`${s}:${d.join(",")||"*"}`;if(t.has(u))continue;t.add(u);let p=d.length>0&&"string"==typeof c&&c.trim().length>0?"figmaJson"===r.type?`JSON \xb7 ${c}`:c:s;n.push({kind:"figma-snapshot",label:p,snapshotRunId:s,...(d.length>0?{screenIds:d}:{})});}return n;},linkedImageSources:e=>{let t=new Set(),n=[];for(let i of a.current){if(n.length>=16)break;let a=i.a===e?i.b:i.b===e?i.a:null;if(null===a)continue;let r=l.current.find(e=>e.id===a);if(void 0===r||"figmaImage"!==r.type)continue;let s=r.cfg.snapshotRunId,o=r.cfg.screenId;if("string"!=typeof s||0===s.trim().length||"string"!=typeof o||0===o.trim().length)continue;let c=`${s}:${o}`;if(t.has(c))continue;t.add(c);let d=r.cfg.selectedScreenName,u="string"==typeof d&&d.trim().length>0?`Image \xb7 ${d}`:`Image \xb7 ${o}`;n.push({kind:"image",label:u,sourceKind:"figma-snapshot-screen",snapshotRunId:s,screenId:o});}return n;},currentFilesContext:()=>{var e;let t=l.current.map(e=>f(e)).filter(e=>null!==e);if(1===t.length)return null!=(e=t[0])?e:null;let n=[...l.current].filter(e=>"files"===e.type).sort((e,t)=>t.z-e.z)[0];return void 0===n?null:f(n);}};}({wsRef:e,viewRef:T,winsRef:C,connsRef:I,connectingRef:R,connectCleanupRef:$,focus:W,setConns:x,setConnecting:j,onScopeBind:u.onScopeBind,onScopeUnbind:u.onScopeUnbind,onConnectorBind:u.onConnectorBind,onConnectorUnbind:u.onConnectorUnbind});return A.current=el,(0,i.useEffect)(()=>()=>{null!==$.current&&($.current(),$.current=null);},[]),{wins:p,snapPrev:h,palOpen:g,setPalOpen:v,conns:b,connecting:y,view:w,api:{add:J,openEditorFile:H,toggleTool:Y,focus:W,close:e=>{let t=C.current.find(t=>t.id===e);if(void 0!==t)for(let s of I.current){var n,l,a,i,r;let o=s.a===e?s.b:s.b===e?s.a:null;if(null===o)continue;let c=C.current.find(e=>e.id===o);if(void 0===c)continue;let d=null!=(n=s.boundChatWindowId)?n:"chat"===t.type?t.id:"chat"===c.type?c.id:null,p=null!=(l=tS(s))?l:tN(t,c,Date.now());null!==p&&null!==d&&(null==(i=u.onScopeUnbind)||i.call(u,d,p));let m=null!=(a=tA(s))?a:tF(t,c);null!==m&&null!==d&&(null==(r=u.onConnectorUnbind)||r.call(u,d,m));}B(e);},minimize:U,restore:_,maximize:V,update:K,setSnap:Z,commitSnap:ee,tileAll:X,splitFront:G,cascade:Q,startConnect:et,confirmConnect:en,cancelConnect:el,removeConn:ea,updateConnBoundScope:(e,t)=>{x(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));},connect:ei,linkedFilesRoot:er,linkedFilesContext:es,linkedAllFilesRoots:eo,linkedConnectorCapsuleIds:ec,linkedConnectorCapsuleSetIds:ed,linkedFigmaSnapshotRunIds:eu,linkedFigmaSnapshotSources:ep,linkedImageSources:em,currentFilesContext:eh,zoomTo:P,fitView:q,resetView:L,panBy:z,rect:O}};}(b,{onScopeBind:(0,i.useCallback)(async(e,t)=>A(e,t),[A]),onScopeUnbind:(0,i.useCallback)((e,t)=>{let n=$(e);if(void 0===n)return;let l=tI(tR(n),t);(0,k.Mr)(n.id,l.length>0?l:null).then(e=>{v.replaceChat(e.chat);}).catch(e=>{console.warn("[keiko] connected-scope unbind failed",e);});},[$,v]),onConnectorBind:(0,i.useCallback)(async(e,t)=>{var n;let l,a,i=$(e);if(void 0===i)return R("Open a ready chat window before connecting a source.");let r=t$(i),s=tR(i);if(l=tE(t),r.some(e=>tE(e)===l))return!0;let o=tC(y);if(s.length+r.length>=o)return I(s.length+r.length,o);let c=(n=y.maxLocalKnowledgeSources,a=tE(t),r.some(e=>tE(e)===a)||r.length>=n?r:[...r,t]);if(c===r)return I(s.length+r.length,o);try{let e=await(0,k.Cp)(i.id,c);return v.replaceChat(e.chat),C(null),!0;}catch{return R("Keiko could not connect that knowledge source. Check that it is still available and try again.");}},[$,v,y,I,R]),onConnectorUnbind:(0,i.useCallback)((e,t)=>{var n;let l=$(e);if(void 0===l)return;let a="capsule"===t.kind?`capsule:${t.capsuleId}`:`set:${t.capsuleSetId}`,i=(n=t$(l),n.filter(e=>tE(e)!==a));(0,k.Cp)(l.id,i.length>0?i:null).then(e=>{v.replaceChat(e.chat);}).catch(()=>void 0);},[$,v])});x.current=T.wins,(0,i.useEffect)(()=>{if(null!==T.wins)for(let t of T.conns){var e;let n=T.wins.find(e=>e.id===t.a),l=T.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 i=tN(n,l,Date.now());if(null===i)continue;let r=tS(t);uZ(r)!==uZ(i)&&A(a,i,r).then(e=>{e&&T.api.updateConnBoundScope(t.id,i);});}},[A,T.api,T.conns,T.wins]);let[M,L]=(0,i.useState)(!1),[z,W]=(0,i.useState)(null),[B,U]=(0,i.useState)(!1),[_,V]=(0,i.useState)(!1),J=null!=(e=null==(n=T.wins)?void 0:n.length)?e:0,H=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;}(T.wins),Y=(0,i.useMemo)(()=>function(e){if(null===e)return new Set();let t=new Set();for(let n of e)!0===E[n.type].tool&&t.add(n.type);return t;}(T.wins),[T.wins]),X=(0,i.useMemo)(()=>{var e;return{wins:null!=(e=T.wins)?e:[],active:H,winCount:J};},[T.wins,H,J]),G=(0,i.useCallback)(()=>L(!0),[]),Q=(0,i.useCallback)(()=>L(!1),[]),Z=(0,i.useCallback)(()=>V(e=>!e),[]),ee=(0,i.useCallback)(()=>V(!1),[]),et=(0,i.useCallback)(e=>{T.api.restore(e),V(!1);},[T.api]),en=(0,i.useCallback)(e=>{if(L(!1),"connector"===e){let t=T.api.add(e);null!==t&&u3(t);return;}W(e);},[T.api]),el=(0,i.useCallback)(e=>{if(W(null),null===z)return;let{__connectFilesId:t,...n}="editor"===z?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=u1(t,n),a={...e,root:t},i=function(e,t,n){let l=[],a=t=>{let n=function(e,t){let n=t.trim();if(0===n.length)return"";let l=u1(e,n);return null!==l?l:n.startsWith("/")||n.startsWith("\\")||/^[A-Za-z]:[\\/]/u.test(n)?null:n.replace(/\\/gu,"/").replace(/^\/+/u,"");}(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:n);return null===l?n.length>0&&(a.file=n):l.length>0?a.file=l:delete a.file,i.length>0?a.openFiles=i:delete a.openFiles,a;}(e):e,l=T.api.add(z,n);"agents"===z&&null!==l&&"string"==typeof t&&t.length>0&&T.api.connect(l,t),null!==l&&u3(l);},[z,T.api]),ea=(0,i.useCallback)(()=>W(null),[]),ei=(0,i.useCallback)(()=>U(!1),[]),er=(0,i.useCallback)(()=>U(!0),[]),es=(0,i.useRef)(null),eo=(0,i.useCallback)(e=>{es.current=e;},[]),ec=function(e){var t;let{apply:n}=e,l=null!=(t=e.limit)?t:100,[a,r]=(0,i.useState)(lX),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(lX);},[]);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?lH(e):null,redoLabel:void 0!==t?lH(t):null,push:c,undo:d,redo:u,clear:p};},[a,c,d,u,p]);}({apply:(0,i.useCallback)(e=>{var t;return t=T.api,void("ui.panel.toggle"===e.kind&&e.panel in E&&t.toggleTool(e.panel));},[T.api])}),ed=(0,i.useCallback)(e=>{if(!(e in E))return;let t=Y.has(e);T.api.toggleTool(e),ec.push({kind:"ui.panel.toggle",panel:e,before:t,after:!t});},[T.api,Y,ec]),eu=(0,i.useCallback)(()=>en("chat"),[en]),ep=(0,i.useRef)(!1);(0,i.useEffect)(()=>{if(ep.current||null===T.wins)return;ep.current=!0;let e=window.location.pathname.replace(/\/+$/u,""),t="/relationships"===e?"relationships":"/local-knowledge"===e?"localKnowledge":null;null!==t&&(T.wins.some(e=>e.type===t)||ed(t),window.history.replaceState(null,"","/"));},[T.wins,ed]),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=lY(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 lJ)if(lY(e)===lY(t))return!0;return!1;}(e.chord)),[n]);if(s.length>0)throw new lG(s);if(o.length>0)throw new lQ(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:lZ,dispatch:(0,i.useCallback)(e=>{var t;"undo"===e?ec.undo():"redo"===e?ec.redo():"focus-status"===e&&(null==(t=es.current)||t.focus());},[ec])}),(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 em=(0,i.useMemo)(()=>function(e,t,n,l,a,i){let r=[];for(let e of u2){let t=E[e];r.push({id:`new-${e}`,label:`New ${t.title}`,group:"Create",icon:t.icon,run:()=>n(e)});}for(let e of u4){let n=E[e];r.push({id:`open-${e}`,label:`Open ${n.title}`,group:"Tools",icon:n.icon,run:()=>t(e)});}return r.push({id:"tile",label:"Tile all windows",group:"Layout",icon:"tile",run:e.tileAll}),r.push({id:"split",label:"Split front windows",group:"Layout",icon:"split",run:e.splitFront}),r.push({id:"cascade",label:"Cascade windows",group:"Layout",icon:"cascade",run:e.cascade}),r.push({id:"theme",label:"Toggle light / dark theme",group:"View",icon:"light"===l?"moon":"sun",run:a}),r.push({id:"undo",label:null!==i.undoLabel?`Undo: ${i.undoLabel}`:"Undo (window and panel changes only)",group:"Edit",icon:"back",shortcut:"⌘Z",run:i.undo}),r.push({id:"redo",label:null!==i.redoLabel?`Redo: ${i.redoLabel}`:"Redo (window and panel changes only)",group:"Edit",icon:"fwd",shortcut:"⇧⌘Z",run:i.redo}),r;}(T.api,ed,en,h,f,ec),[T.api,ed,en,h,f,ec]),eh=!v.loading&&void 0===v.error&&0===v.models.length,ef=(c=null==(l=v.activeProject)?void 0:l.name,v.loading?"Loading project…":void 0!==c&&c.trim().length>0?c:"No project selected"),eg=void 0!==v.activeProject,ev=(null==(r=v.activeProject)?void 0:r.available)===!0,eb=(d={loading:v.loading,error:v.error,hasProject:eg,projectAvailable:ev,noEligibleModels:v.noEligibleModels}).loading?"Loading shell…":void 0!==d.error?"Shell error":d.hasProject?d.projectAvailable?d.noEligibleModels?"Gateway setup required":"Ready":"Project unavailable":"No project selected",ex=0===(m=(null!=(u=T.wins)?u:[]).filter(e=>"review"===e.type)).length?"No review open":m.some(e=>"string"==typeof e.cfg.runId&&e.cfg.runId.length>0)?"Evidence ready":"Review window open",ey=void 0!==(p=null==(o=v.activeChat)?void 0:o.branchLabel)&&p.trim().length>0?p:"No branch selected",ej=M?(0,a.jsx)(nS,{types:E,order:u2,onAdd:en,onClose:Q}):null;return(0,a.jsx)(s,{value:v,children:(0,a.jsx)(w.Provider,{value:X,children:(0,a.jsxs)("div",{className:"app",children:[(0,a.jsx)("a",{className:"skip-link",href:"#main",children:"Skip to content"}),(0,a.jsx)("h1",{className:"visually-hidden",children:"Keiko workspace"}),(0,a.jsx)(q,{openPalette:G,openCommandPalette:er,onTileAll:T.api.tileAll,onSplitFront:T.api.splitFront,onCascade:T.api.cascade}),(0,a.jsxs)("div",{className:"mid",children:[eh?null:(0,a.jsx)(O,{openTools:Y,onTool:ed,onNewChat:eu,theme:h,onToggleTheme:f}),(0,a.jsxs)("div",{className:"stage",id:"main",tabIndex:-1,children:[(0,a.jsx)(nn,{ws:T,wsRef:b,openPalette:G,palette:ej}),null!==S&&(0,a.jsxs)("div",{className:"source-limit-alert",role:"alert",children:[(0,a.jsx)("span",{children:S}),(0,a.jsx)("button",{type:"button",className:"source-limit-alert-dismiss","aria-label":"Dismiss source connection notice",onClick:()=>C(null),children:"\xd7"})]})]}),eh?null:(0,a.jsx)(K,{openTools:Y,onTool:ed})]}),(0,a.jsx)(P,{winCount:J,windows:null!=(t=T.wins)?t:[],windowPaletteOpen:_,onToggleWindowPalette:Z,onSelectWindow:et,onCloseWindowPalette:ee,mode:g.mode,selectedModel:v.selectedModel,projectName:ef,branchLabel:ey,shellStatusLabel:eb,evidenceStatusLabel:ex,statusRef:eo}),null!==z&&(0,a.jsx)(nN,{type:z,types:E,filesContext:T.api.currentFilesContext(),onConfirm:el,onClose:ea}),B&&(0,a.jsx)(nl,{commands:em,onClose:ei}),eh?(0,a.jsx)(nr,{}):null,(0,a.jsx)(uH,{})]})})});}function u6(){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",uG),null!==e.controller&&uQ(t),t.addEventListener("updatefound",()=>{let n;n=t.installing,null!==n&&n.addEventListener("statechange",()=>{"installed"!==n.state||null!==e.controller&&uQ(t);});});}).catch(e=>{});}catch{}}();},[]),e)?(0,a.jsx)(y,{children:(0,a.jsx)(u5,{})}):(0,a.jsx)("div",{className:"app","aria-hidden":"true",children:(0,a.jsx)("div",{className:"app-boot",children:(0,a.jsx)("img",{className:"app-boot-logo",src:"/assets/keiko-logo.svg",alt:""})})});}function u8(){return(0,a.jsx)(u6,{});}},48824:(e,t,n)=>{Promise.resolve().then(n.bind(n,6123));},55176:(e,t,n)=>{"use strict";n.d(t,{o:()=>i});var l=n(54568),a=n(75571);function i(e){let t,{name:n,icon:i}=e,r=null!=i?i:"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!==r?(0,l.jsx)("img",{className:"fi-img",src:`/assets/icons/${r}.svg`,width:"15",height:"15",alt:""}):(0,l.jsx)("span",{className:"fi-fallback",children:(0,l.jsx)(a.F.file,{size:14})});}}}]);