@circuitwall/jarela 0.7.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (271) hide show
  1. package/.next/standalone/.next/BUILD_ID +1 -1
  2. package/.next/standalone/.next/build-manifest.json +6 -6
  3. package/.next/standalone/.next/prerender-manifest.json +3 -3
  4. package/.next/standalone/.next/required-server-files.json +1 -1
  5. package/.next/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  6. package/.next/standalone/.next/server/app/_global-error.html +1 -1
  7. package/.next/standalone/.next/server/app/_global-error.rsc +1 -1
  8. package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  9. package/.next/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  10. package/.next/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  11. package/.next/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  12. package/.next/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  13. package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  14. package/.next/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  15. package/.next/standalone/.next/server/app/_not-found.html +2 -2
  16. package/.next/standalone/.next/server/app/_not-found.rsc +5 -5
  17. package/.next/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +5 -5
  18. package/.next/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  19. package/.next/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +5 -5
  20. package/.next/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  21. package/.next/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  22. package/.next/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  23. package/.next/standalone/.next/server/app/index.html +2 -2
  24. package/.next/standalone/.next/server/app/index.rsc +7 -7
  25. package/.next/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +3 -3
  26. package/.next/standalone/.next/server/app/index.segments/_full.segment.rsc +7 -7
  27. package/.next/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  28. package/.next/standalone/.next/server/app/index.segments/_index.segment.rsc +5 -5
  29. package/.next/standalone/.next/server/app/index.segments/_tree.segment.rsc +3 -3
  30. package/.next/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
  31. package/.next/standalone/.next/server/app/setup/page_client-reference-manifest.js +1 -1
  32. package/.next/standalone/.next/server/app/setup.html +1 -1
  33. package/.next/standalone/.next/server/app/setup.rsc +5 -5
  34. package/.next/standalone/.next/server/app/setup.segments/_full.segment.rsc +5 -5
  35. package/.next/standalone/.next/server/app/setup.segments/_head.segment.rsc +1 -1
  36. package/.next/standalone/.next/server/app/setup.segments/_index.segment.rsc +5 -5
  37. package/.next/standalone/.next/server/app/setup.segments/_tree.segment.rsc +2 -2
  38. package/.next/standalone/.next/server/app/setup.segments/setup/__PAGE__.segment.rsc +1 -1
  39. package/.next/standalone/.next/server/app/setup.segments/setup.segment.rsc +1 -1
  40. package/.next/standalone/.next/server/middleware-build-manifest.js +20 -1
  41. package/.next/standalone/.next/server/middleware-react-loadable-manifest.js +1 -1
  42. package/.next/standalone/.next/server/next-font-manifest.js +1 -1
  43. package/.next/standalone/.next/server/pages/404.html +2 -2
  44. package/.next/standalone/.next/server/pages/500.html +1 -1
  45. package/.next/standalone/.next/server/server-reference-manifest.json +1 -1
  46. package/.next/standalone/.next/static/IauO0rNZkUVPX834k-SBa/_buildManifest.js +1 -0
  47. package/.next/standalone/.next/static/chunks/3457-5218e06617c4db2a.js +21026 -0
  48. package/.next/standalone/.next/static/chunks/3457-5218e06617c4db2a.js.map +1 -0
  49. package/.next/standalone/.next/static/chunks/4bd1b696-f4afdf0ad1d556a5.js +18276 -0
  50. package/.next/standalone/.next/static/chunks/4bd1b696-f4afdf0ad1d556a5.js.map +1 -0
  51. package/.next/standalone/.next/static/chunks/6945-269d42dc1784c71a.js +728 -0
  52. package/.next/standalone/.next/static/chunks/6945-269d42dc1784c71a.js.map +1 -0
  53. package/.next/standalone/.next/static/chunks/8657-ce5d7648903bc458.js +64051 -0
  54. package/.next/standalone/.next/static/chunks/8657-ce5d7648903bc458.js.map +1 -0
  55. package/.next/standalone/.next/static/chunks/app/_global-error/page-ef2695e78d17eafd.js +17 -0
  56. package/.next/standalone/.next/static/chunks/app/_not-found/page-1c2b53258ccc0873.js +191 -0
  57. package/.next/standalone/.next/static/chunks/app/_not-found/page-1c2b53258ccc0873.js.map +1 -0
  58. package/.next/standalone/.next/static/chunks/app/api/v1/access/[identity]/route-ef2695e78d17eafd.js +17 -0
  59. package/.next/standalone/.next/static/chunks/app/api/v1/access/route-ef2695e78d17eafd.js +17 -0
  60. package/.next/standalone/.next/static/chunks/app/api/v1/agents/[id]/compact/route-ef2695e78d17eafd.js +17 -0
  61. package/.next/standalone/.next/static/chunks/app/api/v1/agents/[id]/display-filters/route-ef2695e78d17eafd.js +17 -0
  62. package/.next/standalone/.next/static/chunks/app/api/v1/agents/[id]/route-ef2695e78d17eafd.js +17 -0
  63. package/.next/standalone/.next/static/chunks/app/api/v1/agents/[id]/thread/route-ef2695e78d17eafd.js +17 -0
  64. package/.next/standalone/.next/static/chunks/app/api/v1/agents/route-ef2695e78d17eafd.js +17 -0
  65. package/.next/standalone/.next/static/chunks/app/api/v1/bridges/[id]/chats/route-ef2695e78d17eafd.js +17 -0
  66. package/.next/standalone/.next/static/chunks/app/api/v1/bridges/[id]/lookup/route-ef2695e78d17eafd.js +17 -0
  67. package/.next/standalone/.next/static/chunks/app/api/v1/bridges/[id]/pair/route-ef2695e78d17eafd.js +17 -0
  68. package/.next/standalone/.next/static/chunks/app/api/v1/bridges/[id]/route-ef2695e78d17eafd.js +17 -0
  69. package/.next/standalone/.next/static/chunks/app/api/v1/bridges/[id]/routes/[route_id]/route-ef2695e78d17eafd.js +17 -0
  70. package/.next/standalone/.next/static/chunks/app/api/v1/bridges/[id]/routes/route-ef2695e78d17eafd.js +17 -0
  71. package/.next/standalone/.next/static/chunks/app/api/v1/bridges/[id]/status/route-ef2695e78d17eafd.js +17 -0
  72. package/.next/standalone/.next/static/chunks/app/api/v1/bridges/route-ef2695e78d17eafd.js +17 -0
  73. package/.next/standalone/.next/static/chunks/app/api/v1/builtin-tools/route-ef2695e78d17eafd.js +17 -0
  74. package/.next/standalone/.next/static/chunks/app/api/v1/documents/search/route-ef2695e78d17eafd.js +17 -0
  75. package/.next/standalone/.next/static/chunks/app/api/v1/documents/settings/route-ef2695e78d17eafd.js +17 -0
  76. package/.next/standalone/.next/static/chunks/app/api/v1/documents/sources/[id]/reindex/route-ef2695e78d17eafd.js +17 -0
  77. package/.next/standalone/.next/static/chunks/app/api/v1/documents/sources/[id]/route-ef2695e78d17eafd.js +17 -0
  78. package/.next/standalone/.next/static/chunks/app/api/v1/documents/sources/route-ef2695e78d17eafd.js +17 -0
  79. package/.next/standalone/.next/static/chunks/app/api/v1/env-sync/allowlist/route-ef2695e78d17eafd.js +17 -0
  80. package/.next/standalone/.next/static/chunks/app/api/v1/env-sync/route-ef2695e78d17eafd.js +17 -0
  81. package/.next/standalone/.next/static/chunks/app/api/v1/events/route-ef2695e78d17eafd.js +17 -0
  82. package/.next/standalone/.next/static/chunks/app/api/v1/events/test/route-ef2695e78d17eafd.js +17 -0
  83. package/.next/standalone/.next/static/chunks/app/api/v1/extensions/route-ef2695e78d17eafd.js +17 -0
  84. package/.next/standalone/.next/static/chunks/app/api/v1/extensions/tools/[name]/secrets/route-ef2695e78d17eafd.js +17 -0
  85. package/.next/standalone/.next/static/chunks/app/api/v1/files/[name]/route-ef2695e78d17eafd.js +17 -0
  86. package/.next/standalone/.next/static/chunks/app/api/v1/fs/browse/route-ef2695e78d17eafd.js +17 -0
  87. package/.next/standalone/.next/static/chunks/app/api/v1/harnesses/[id]/route-ef2695e78d17eafd.js +17 -0
  88. package/.next/standalone/.next/static/chunks/app/api/v1/harnesses/default/route-ef2695e78d17eafd.js +17 -0
  89. package/.next/standalone/.next/static/chunks/app/api/v1/harnesses/route-ef2695e78d17eafd.js +17 -0
  90. package/.next/standalone/.next/static/chunks/app/api/v1/health/route-ef2695e78d17eafd.js +17 -0
  91. package/.next/standalone/.next/static/chunks/app/api/v1/integrations/[name]/route-ef2695e78d17eafd.js +17 -0
  92. package/.next/standalone/.next/static/chunks/app/api/v1/integrations/[name]/test/route-ef2695e78d17eafd.js +17 -0
  93. package/.next/standalone/.next/static/chunks/app/api/v1/integrations/gmail/oauth/callback/route-ef2695e78d17eafd.js +17 -0
  94. package/.next/standalone/.next/static/chunks/app/api/v1/integrations/gmail/oauth/start/route-ef2695e78d17eafd.js +17 -0
  95. package/.next/standalone/.next/static/chunks/app/api/v1/integrations/gmail/oauth/status/route-ef2695e78d17eafd.js +17 -0
  96. package/.next/standalone/.next/static/chunks/app/api/v1/integrations/outlook/oauth/callback/route-ef2695e78d17eafd.js +17 -0
  97. package/.next/standalone/.next/static/chunks/app/api/v1/integrations/outlook/oauth/start/route-ef2695e78d17eafd.js +17 -0
  98. package/.next/standalone/.next/static/chunks/app/api/v1/integrations/outlook/oauth/status/route-ef2695e78d17eafd.js +17 -0
  99. package/.next/standalone/.next/static/chunks/app/api/v1/integrations/route-ef2695e78d17eafd.js +17 -0
  100. package/.next/standalone/.next/static/chunks/app/api/v1/maps/embed/route-ef2695e78d17eafd.js +17 -0
  101. package/.next/standalone/.next/static/chunks/app/api/v1/mcp-servers/[name]/route-ef2695e78d17eafd.js +17 -0
  102. package/.next/standalone/.next/static/chunks/app/api/v1/mcp-servers/registry/route-ef2695e78d17eafd.js +17 -0
  103. package/.next/standalone/.next/static/chunks/app/api/v1/mcp-servers/route-ef2695e78d17eafd.js +17 -0
  104. package/.next/standalone/.next/static/chunks/app/api/v1/memory/[namespace]/[key]/route-ef2695e78d17eafd.js +17 -0
  105. package/.next/standalone/.next/static/chunks/app/api/v1/memory/route-ef2695e78d17eafd.js +17 -0
  106. package/.next/standalone/.next/static/chunks/app/api/v1/models/[name]/route-ef2695e78d17eafd.js +17 -0
  107. package/.next/standalone/.next/static/chunks/app/api/v1/models/route-ef2695e78d17eafd.js +17 -0
  108. package/.next/standalone/.next/static/chunks/app/api/v1/page-capture/route-ef2695e78d17eafd.js +17 -0
  109. package/.next/standalone/.next/static/chunks/app/api/v1/pending-actions/[id]/approve/route-ef2695e78d17eafd.js +17 -0
  110. package/.next/standalone/.next/static/chunks/app/api/v1/pending-actions/[id]/deny/route-ef2695e78d17eafd.js +17 -0
  111. package/.next/standalone/.next/static/chunks/app/api/v1/pending-actions/route-ef2695e78d17eafd.js +17 -0
  112. package/.next/standalone/.next/static/chunks/app/api/v1/profile/location/route-ef2695e78d17eafd.js +17 -0
  113. package/.next/standalone/.next/static/chunks/app/api/v1/profile/route-ef2695e78d17eafd.js +17 -0
  114. package/.next/standalone/.next/static/chunks/app/api/v1/providers/[provider]/models/route-ef2695e78d17eafd.js +17 -0
  115. package/.next/standalone/.next/static/chunks/app/api/v1/providers/github-copilot/auth/route-ef2695e78d17eafd.js +17 -0
  116. package/.next/standalone/.next/static/chunks/app/api/v1/providers/route-ef2695e78d17eafd.js +17 -0
  117. package/.next/standalone/.next/static/chunks/app/api/v1/proxy-config/route-ef2695e78d17eafd.js +17 -0
  118. package/.next/standalone/.next/static/chunks/app/api/v1/scheduled-tasks/[id]/route-ef2695e78d17eafd.js +17 -0
  119. package/.next/standalone/.next/static/chunks/app/api/v1/scheduled-tasks/[id]/run/route-ef2695e78d17eafd.js +17 -0
  120. package/.next/standalone/.next/static/chunks/app/api/v1/scheduled-tasks/route-ef2695e78d17eafd.js +17 -0
  121. package/.next/standalone/.next/static/chunks/app/api/v1/setup/test-key/route-ef2695e78d17eafd.js +17 -0
  122. package/.next/standalone/.next/static/chunks/app/api/v1/tailscale/route-ef2695e78d17eafd.js +17 -0
  123. package/.next/standalone/.next/static/chunks/app/api/v1/tasks/[agent_id]/route-ef2695e78d17eafd.js +17 -0
  124. package/.next/standalone/.next/static/chunks/app/api/v1/tasks/route-ef2695e78d17eafd.js +17 -0
  125. package/.next/standalone/.next/static/chunks/app/api/v1/threads/[thread_id]/route-ef2695e78d17eafd.js +17 -0
  126. package/.next/standalone/.next/static/chunks/app/api/v1/threads/[thread_id]/run/route-ef2695e78d17eafd.js +17 -0
  127. package/.next/standalone/.next/static/chunks/app/api/v1/threads/route-ef2695e78d17eafd.js +17 -0
  128. package/.next/standalone/.next/static/chunks/app/api/v1/tools/route-ef2695e78d17eafd.js +17 -0
  129. package/.next/standalone/.next/static/chunks/app/api/v1/update/route-ef2695e78d17eafd.js +17 -0
  130. package/.next/standalone/.next/static/chunks/app/api/v1/voice/transcribe/route-ef2695e78d17eafd.js +17 -0
  131. package/.next/standalone/.next/static/chunks/app/api/v1/voice/tts/route-ef2695e78d17eafd.js +17 -0
  132. package/.next/standalone/.next/static/chunks/app/api/v1/watchers/[id]/route-ef2695e78d17eafd.js +17 -0
  133. package/.next/standalone/.next/static/chunks/app/api/v1/watchers/[id]/run/route-ef2695e78d17eafd.js +17 -0
  134. package/.next/standalone/.next/static/chunks/app/api/v1/watchers/reaction-scripts/route-ef2695e78d17eafd.js +17 -0
  135. package/.next/standalone/.next/static/chunks/app/api/v1/watchers/route-ef2695e78d17eafd.js +17 -0
  136. package/.next/standalone/.next/static/chunks/app/layout-0814b4dde82d031c.js +211 -0
  137. package/.next/standalone/.next/static/chunks/app/layout-0814b4dde82d031c.js.map +1 -0
  138. package/.next/standalone/.next/static/chunks/app/page-a20902703c0a4f10.js +18162 -0
  139. package/.next/standalone/.next/static/chunks/app/page-a20902703c0a4f10.js.map +1 -0
  140. package/.next/standalone/.next/static/chunks/app/setup/page-28c01e39806ffb39.js +709 -0
  141. package/.next/standalone/.next/static/chunks/app/setup/page-28c01e39806ffb39.js.map +1 -0
  142. package/.next/standalone/.next/static/chunks/framework-01304d5a84d96921.js +17321 -0
  143. package/.next/standalone/.next/static/chunks/framework-01304d5a84d96921.js.map +1 -0
  144. package/.next/standalone/.next/static/chunks/main-app-3f37bcefd1eaffaf.js +40 -0
  145. package/.next/standalone/.next/static/chunks/main-app-3f37bcefd1eaffaf.js.map +1 -0
  146. package/.next/standalone/.next/static/chunks/main-da6c99fc920e0f54.js +10973 -0
  147. package/.next/standalone/.next/static/chunks/main-da6c99fc920e0f54.js.map +1 -0
  148. package/.next/standalone/.next/static/chunks/next/dist/client/components/builtin/app-error-ef2695e78d17eafd.js +17 -0
  149. package/.next/standalone/.next/static/chunks/next/dist/client/components/builtin/forbidden-ef2695e78d17eafd.js +17 -0
  150. package/.next/standalone/.next/static/chunks/next/dist/client/components/builtin/global-error-e0f5f907bea96484.js +19 -0
  151. package/.next/standalone/.next/static/chunks/next/dist/client/components/builtin/global-error-e0f5f907bea96484.js.map +1 -0
  152. package/.next/standalone/.next/static/chunks/next/dist/client/components/builtin/not-found-ef2695e78d17eafd.js +17 -0
  153. package/.next/standalone/.next/static/chunks/next/dist/client/components/builtin/unauthorized-ef2695e78d17eafd.js +17 -0
  154. package/.next/standalone/.next/static/chunks/webpack-ff5627013a5e3842.js +330 -0
  155. package/.next/standalone/.next/static/chunks/webpack-ff5627013a5e3842.js.map +1 -0
  156. package/.next/standalone/.next/static/css/61d4279c2300e146.css +120 -0
  157. package/.next/standalone/.next/static/css/61d4279c2300e146.css.map +1 -0
  158. package/.next/standalone/.next/static/css/cc66c456aba91258.css +5 -0
  159. package/.next/standalone/.next/static/css/cc66c456aba91258.css.map +1 -0
  160. package/.next/standalone/package.json +8 -7
  161. package/.next/standalone/public/sw.js.map +1 -0
  162. package/.next/standalone/public/swe-worker-f61931bc2770d10b.js.map +1 -0
  163. package/.next/standalone/server.js +1 -1
  164. package/CHANGELOG.md +26 -0
  165. package/next.config.ts +15 -0
  166. package/package.json +8 -7
  167. package/public/sw.js.map +1 -0
  168. package/public/swe-worker-f61931bc2770d10b.js.map +1 -0
  169. package/scripts/jarela-bin.mjs +9 -0
  170. package/scripts/optimize-client-chunks.mjs +144 -0
  171. package/scripts/start-prod.mjs +10 -0
  172. package/.next/standalone/.next/static/YPyYnTKBZDNmNtxfosViy/_buildManifest.js +0 -1
  173. package/.next/standalone/.next/static/chunks/3457-33fb797ce4ab98b5.js +0 -32
  174. package/.next/standalone/.next/static/chunks/4bd1b696-d3a0b478714afd8c.js +0 -1
  175. package/.next/standalone/.next/static/chunks/6945-fe3c2c29fcc9747d.js +0 -1
  176. package/.next/standalone/.next/static/chunks/8657-4832c6fc644bc4b4.js +0 -1
  177. package/.next/standalone/.next/static/chunks/app/_global-error/page-2a40ae26adab6590.js +0 -1
  178. package/.next/standalone/.next/static/chunks/app/_not-found/page-a6e862db975a5eb0.js +0 -1
  179. package/.next/standalone/.next/static/chunks/app/api/v1/access/[identity]/route-2a40ae26adab6590.js +0 -1
  180. package/.next/standalone/.next/static/chunks/app/api/v1/access/route-2a40ae26adab6590.js +0 -1
  181. package/.next/standalone/.next/static/chunks/app/api/v1/agents/[id]/compact/route-2a40ae26adab6590.js +0 -1
  182. package/.next/standalone/.next/static/chunks/app/api/v1/agents/[id]/display-filters/route-2a40ae26adab6590.js +0 -1
  183. package/.next/standalone/.next/static/chunks/app/api/v1/agents/[id]/route-2a40ae26adab6590.js +0 -1
  184. package/.next/standalone/.next/static/chunks/app/api/v1/agents/[id]/thread/route-2a40ae26adab6590.js +0 -1
  185. package/.next/standalone/.next/static/chunks/app/api/v1/agents/route-2a40ae26adab6590.js +0 -1
  186. package/.next/standalone/.next/static/chunks/app/api/v1/bridges/[id]/chats/route-2a40ae26adab6590.js +0 -1
  187. package/.next/standalone/.next/static/chunks/app/api/v1/bridges/[id]/lookup/route-2a40ae26adab6590.js +0 -1
  188. package/.next/standalone/.next/static/chunks/app/api/v1/bridges/[id]/pair/route-2a40ae26adab6590.js +0 -1
  189. package/.next/standalone/.next/static/chunks/app/api/v1/bridges/[id]/route-2a40ae26adab6590.js +0 -1
  190. package/.next/standalone/.next/static/chunks/app/api/v1/bridges/[id]/routes/[route_id]/route-2a40ae26adab6590.js +0 -1
  191. package/.next/standalone/.next/static/chunks/app/api/v1/bridges/[id]/routes/route-2a40ae26adab6590.js +0 -1
  192. package/.next/standalone/.next/static/chunks/app/api/v1/bridges/[id]/status/route-2a40ae26adab6590.js +0 -1
  193. package/.next/standalone/.next/static/chunks/app/api/v1/bridges/route-2a40ae26adab6590.js +0 -1
  194. package/.next/standalone/.next/static/chunks/app/api/v1/builtin-tools/route-2a40ae26adab6590.js +0 -1
  195. package/.next/standalone/.next/static/chunks/app/api/v1/documents/search/route-2a40ae26adab6590.js +0 -1
  196. package/.next/standalone/.next/static/chunks/app/api/v1/documents/settings/route-2a40ae26adab6590.js +0 -1
  197. package/.next/standalone/.next/static/chunks/app/api/v1/documents/sources/[id]/reindex/route-2a40ae26adab6590.js +0 -1
  198. package/.next/standalone/.next/static/chunks/app/api/v1/documents/sources/[id]/route-2a40ae26adab6590.js +0 -1
  199. package/.next/standalone/.next/static/chunks/app/api/v1/documents/sources/route-2a40ae26adab6590.js +0 -1
  200. package/.next/standalone/.next/static/chunks/app/api/v1/env-sync/allowlist/route-2a40ae26adab6590.js +0 -1
  201. package/.next/standalone/.next/static/chunks/app/api/v1/env-sync/route-2a40ae26adab6590.js +0 -1
  202. package/.next/standalone/.next/static/chunks/app/api/v1/events/route-2a40ae26adab6590.js +0 -1
  203. package/.next/standalone/.next/static/chunks/app/api/v1/events/test/route-2a40ae26adab6590.js +0 -1
  204. package/.next/standalone/.next/static/chunks/app/api/v1/extensions/route-2a40ae26adab6590.js +0 -1
  205. package/.next/standalone/.next/static/chunks/app/api/v1/extensions/tools/[name]/secrets/route-2a40ae26adab6590.js +0 -1
  206. package/.next/standalone/.next/static/chunks/app/api/v1/files/[name]/route-2a40ae26adab6590.js +0 -1
  207. package/.next/standalone/.next/static/chunks/app/api/v1/fs/browse/route-2a40ae26adab6590.js +0 -1
  208. package/.next/standalone/.next/static/chunks/app/api/v1/harnesses/[id]/route-2a40ae26adab6590.js +0 -1
  209. package/.next/standalone/.next/static/chunks/app/api/v1/harnesses/default/route-2a40ae26adab6590.js +0 -1
  210. package/.next/standalone/.next/static/chunks/app/api/v1/harnesses/route-2a40ae26adab6590.js +0 -1
  211. package/.next/standalone/.next/static/chunks/app/api/v1/health/route-2a40ae26adab6590.js +0 -1
  212. package/.next/standalone/.next/static/chunks/app/api/v1/integrations/[name]/route-2a40ae26adab6590.js +0 -1
  213. package/.next/standalone/.next/static/chunks/app/api/v1/integrations/[name]/test/route-2a40ae26adab6590.js +0 -1
  214. package/.next/standalone/.next/static/chunks/app/api/v1/integrations/gmail/oauth/callback/route-2a40ae26adab6590.js +0 -1
  215. package/.next/standalone/.next/static/chunks/app/api/v1/integrations/gmail/oauth/start/route-2a40ae26adab6590.js +0 -1
  216. package/.next/standalone/.next/static/chunks/app/api/v1/integrations/gmail/oauth/status/route-2a40ae26adab6590.js +0 -1
  217. package/.next/standalone/.next/static/chunks/app/api/v1/integrations/outlook/oauth/callback/route-2a40ae26adab6590.js +0 -1
  218. package/.next/standalone/.next/static/chunks/app/api/v1/integrations/outlook/oauth/start/route-2a40ae26adab6590.js +0 -1
  219. package/.next/standalone/.next/static/chunks/app/api/v1/integrations/outlook/oauth/status/route-2a40ae26adab6590.js +0 -1
  220. package/.next/standalone/.next/static/chunks/app/api/v1/integrations/route-2a40ae26adab6590.js +0 -1
  221. package/.next/standalone/.next/static/chunks/app/api/v1/maps/embed/route-2a40ae26adab6590.js +0 -1
  222. package/.next/standalone/.next/static/chunks/app/api/v1/mcp-servers/[name]/route-2a40ae26adab6590.js +0 -1
  223. package/.next/standalone/.next/static/chunks/app/api/v1/mcp-servers/registry/route-2a40ae26adab6590.js +0 -1
  224. package/.next/standalone/.next/static/chunks/app/api/v1/mcp-servers/route-2a40ae26adab6590.js +0 -1
  225. package/.next/standalone/.next/static/chunks/app/api/v1/memory/[namespace]/[key]/route-2a40ae26adab6590.js +0 -1
  226. package/.next/standalone/.next/static/chunks/app/api/v1/memory/route-2a40ae26adab6590.js +0 -1
  227. package/.next/standalone/.next/static/chunks/app/api/v1/models/[name]/route-2a40ae26adab6590.js +0 -1
  228. package/.next/standalone/.next/static/chunks/app/api/v1/models/route-2a40ae26adab6590.js +0 -1
  229. package/.next/standalone/.next/static/chunks/app/api/v1/page-capture/route-2a40ae26adab6590.js +0 -1
  230. package/.next/standalone/.next/static/chunks/app/api/v1/pending-actions/[id]/approve/route-2a40ae26adab6590.js +0 -1
  231. package/.next/standalone/.next/static/chunks/app/api/v1/pending-actions/[id]/deny/route-2a40ae26adab6590.js +0 -1
  232. package/.next/standalone/.next/static/chunks/app/api/v1/pending-actions/route-2a40ae26adab6590.js +0 -1
  233. package/.next/standalone/.next/static/chunks/app/api/v1/profile/location/route-2a40ae26adab6590.js +0 -1
  234. package/.next/standalone/.next/static/chunks/app/api/v1/profile/route-2a40ae26adab6590.js +0 -1
  235. package/.next/standalone/.next/static/chunks/app/api/v1/providers/[provider]/models/route-2a40ae26adab6590.js +0 -1
  236. package/.next/standalone/.next/static/chunks/app/api/v1/providers/github-copilot/auth/route-2a40ae26adab6590.js +0 -1
  237. package/.next/standalone/.next/static/chunks/app/api/v1/providers/route-2a40ae26adab6590.js +0 -1
  238. package/.next/standalone/.next/static/chunks/app/api/v1/proxy-config/route-2a40ae26adab6590.js +0 -1
  239. package/.next/standalone/.next/static/chunks/app/api/v1/scheduled-tasks/[id]/route-2a40ae26adab6590.js +0 -1
  240. package/.next/standalone/.next/static/chunks/app/api/v1/scheduled-tasks/[id]/run/route-2a40ae26adab6590.js +0 -1
  241. package/.next/standalone/.next/static/chunks/app/api/v1/scheduled-tasks/route-2a40ae26adab6590.js +0 -1
  242. package/.next/standalone/.next/static/chunks/app/api/v1/setup/test-key/route-2a40ae26adab6590.js +0 -1
  243. package/.next/standalone/.next/static/chunks/app/api/v1/tailscale/route-2a40ae26adab6590.js +0 -1
  244. package/.next/standalone/.next/static/chunks/app/api/v1/tasks/[agent_id]/route-2a40ae26adab6590.js +0 -1
  245. package/.next/standalone/.next/static/chunks/app/api/v1/tasks/route-2a40ae26adab6590.js +0 -1
  246. package/.next/standalone/.next/static/chunks/app/api/v1/threads/[thread_id]/route-2a40ae26adab6590.js +0 -1
  247. package/.next/standalone/.next/static/chunks/app/api/v1/threads/[thread_id]/run/route-2a40ae26adab6590.js +0 -1
  248. package/.next/standalone/.next/static/chunks/app/api/v1/threads/route-2a40ae26adab6590.js +0 -1
  249. package/.next/standalone/.next/static/chunks/app/api/v1/tools/route-2a40ae26adab6590.js +0 -1
  250. package/.next/standalone/.next/static/chunks/app/api/v1/update/route-2a40ae26adab6590.js +0 -1
  251. package/.next/standalone/.next/static/chunks/app/api/v1/voice/transcribe/route-2a40ae26adab6590.js +0 -1
  252. package/.next/standalone/.next/static/chunks/app/api/v1/voice/tts/route-2a40ae26adab6590.js +0 -1
  253. package/.next/standalone/.next/static/chunks/app/api/v1/watchers/[id]/route-2a40ae26adab6590.js +0 -1
  254. package/.next/standalone/.next/static/chunks/app/api/v1/watchers/[id]/run/route-2a40ae26adab6590.js +0 -1
  255. package/.next/standalone/.next/static/chunks/app/api/v1/watchers/reaction-scripts/route-2a40ae26adab6590.js +0 -1
  256. package/.next/standalone/.next/static/chunks/app/api/v1/watchers/route-2a40ae26adab6590.js +0 -1
  257. package/.next/standalone/.next/static/chunks/app/layout-764e6d7e68bc7d35.js +0 -1
  258. package/.next/standalone/.next/static/chunks/app/page-a4f8846bc63c9c2f.js +0 -24
  259. package/.next/standalone/.next/static/chunks/app/setup/page-ed59c750c18fee42.js +0 -1
  260. package/.next/standalone/.next/static/chunks/framework-29e3791c8b7ad5e0.js +0 -1
  261. package/.next/standalone/.next/static/chunks/main-app-cb0edf855588e8f1.js +0 -1
  262. package/.next/standalone/.next/static/chunks/main-b611c7b6b84fbe95.js +0 -5
  263. package/.next/standalone/.next/static/chunks/next/dist/client/components/builtin/app-error-2a40ae26adab6590.js +0 -1
  264. package/.next/standalone/.next/static/chunks/next/dist/client/components/builtin/forbidden-2a40ae26adab6590.js +0 -1
  265. package/.next/standalone/.next/static/chunks/next/dist/client/components/builtin/global-error-23ce00bb5787d544.js +0 -1
  266. package/.next/standalone/.next/static/chunks/next/dist/client/components/builtin/not-found-2a40ae26adab6590.js +0 -1
  267. package/.next/standalone/.next/static/chunks/next/dist/client/components/builtin/unauthorized-2a40ae26adab6590.js +0 -1
  268. package/.next/standalone/.next/static/chunks/webpack-5793430421782353.js +0 -1
  269. package/.next/standalone/.next/static/css/5eacd01f773eed7f.css +0 -11
  270. package/.next/standalone/.next/static/css/a0f98435baf0fccf.css +0 -1
  271. /package/.next/standalone/.next/static/{YPyYnTKBZDNmNtxfosViy → IauO0rNZkUVPX834k-SBa}/_ssgManifest.js +0 -0
@@ -1,24 +0,0 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{737:(e,t,s)=>{"use strict";s.d(t,{D:()=>o,ThemeProvider:()=>i});var a=s(5155),r=s(2115);let n="jarela-theme",l=(0,r.createContext)(null);function i({children:e}){let[t,s]=(0,r.useState)("system");(0,r.useEffect)(()=>{s(function(){try{let e=window.localStorage.getItem(n);return"light"===e||"dark"===e||"system"===e?e:"system"}catch{return"system"}}())},[]);let o=(0,r.useCallback)(e=>{s(e),"u">typeof document&&document.documentElement.setAttribute("data-theme",e);try{window.localStorage.setItem(n,e)}catch{}},[]);return(0,a.jsx)(l.Provider,{value:{theme:t,setTheme:o},children:e})}function o(){let e=(0,r.useContext)(l);if(!e)throw Error("useTheme must be used within ThemeProvider");return e}},3639:(e,t,s)=>{"use strict";s.d(t,{AppProvider:()=>i,U:()=>o});var a=s(5155),r=s(2115);function n(e,t){switch(t.type){case"SELECT_THREAD":return{...e,activeThreadId:t.threadId,activeAgentId:t.agentId,activeTab:"chat"};case"NEW_CHAT":return{...e,activeThreadId:null,activeAgentId:null,activeTab:"chat"};case"SET_AGENT":return{...e,activeAgentId:t.agentId};case"SET_TAB":return{...e,activeTab:t.tab};case"SET_SELECTION":{let s={...e.selectedItem};return null==t.itemId?delete s[t.tab]:s[t.tab]=t.itemId,{...e,selectedItem:s}}}}let l=(0,r.createContext)(null);function i({children:e}){let[t,s]=(0,r.useReducer)(n,{activeThreadId:null,activeAgentId:null,activeTab:"chat",selectedItem:{}});return(0,a.jsx)(l.Provider,{value:{state:t,dispatch:s},children:e})}function o(){let e=(0,r.useContext)(l);if(!e)throw Error("useAppContext must be used within AppProvider");return e}},9149:(e,t,s)=>{"use strict";s.d(t,{AppShell:()=>a2});var a=s(5155),r=s(2363),n=s(4577),l=s(6304),i=s(2115),o=s(3639),c=s(1490);let d=[],u=new Set,x=new Map,m=new Set;function p(){for(let e of u)e(d)}function h(){for(let e of m)e()}function f(e){let t=`t-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,s={...e,id:t,created_at:Date.now()};d=[...d,s];let a=s.agent_id;return x.set(a,(x.get(a)??0)+1),p(),h(),s.ttl>0&&setTimeout(()=>g(t),s.ttl),t}function g(e){let t=d.length;(d=d.filter(t=>t.id!==e)).length!==t&&p()}function b(){return new Map(x)}function j(){let e=0;for(let t of x.values())e+=t;return e}function y(){let[e,t]=(0,i.useState)(()=>b());return(0,i.useEffect)(()=>{let e=()=>t(b());return m.add(e),e(),()=>{m.delete(e)}},[]),e}let v="jarela.notif.lastTs";function N(e){try{window.localStorage.setItem(v,String(e))}catch{}}let w=["chat","agents","memory","models","mcp","extensions","tools","connections","tasks","bridges","profile","harness","documents"];function k(e){let t;if(!e)return{external:!1};let s=e;if(/^[a-z][a-z0-9+.-]*:/i.test(s))return{external:!0};let a=s.indexOf("#");a>=0&&(t=s.slice(a+1)||void 0,s=s.slice(0,a));let r="",n=s.indexOf("?");n>=0&&(r=s.slice(n+1));let l=new URLSearchParams(r),i=l.get("tab");return{tab:w.includes(i)?i:void 0,item:l.get("item")??void 0,hash:t,external:!1}}let S=["chat","agents","memory","documents","models","mcp","extensions","tools","connections","tasks","bridges","profile","harness"],_=0,C=new Set;function A(){for(let e of C)e(_)}function E(e){(0,i.useEffect)(()=>{if(e){let e;return _+=1,A(),e=!1,()=>{e||(e=!0,_=Math.max(0,_-1),A())}}},[e])}var T=s(9203),$=s(4088),z=s(9005);function I(e){let t=function(e){let t=e.payload,s=e=>"string"==typeof t[e]?t[e]:void 0;switch(e.kind){case"enable_integration":{let e=s("id");return e?{href:`?tab=connections&item=${encodeURIComponent(e)}`,hrefLabel:"Open in Settings →",title:`${e} enabled`}:null}case"start_oauth":{let e=s("integration_id");return e?{href:`?tab=connections&item=${encodeURIComponent(e)}`,hrefLabel:"Open in Settings →",title:`${e} authorized`}:null}case"set_provider_key":{let e=s("name")??s("provider");return e?{href:`?tab=models&item=${encodeURIComponent(e)}`,hrefLabel:"Open in Models →",title:`${e} key saved`}:null}case"install_mcp":case"toggle_mcp":{let t=s("name")??s("registry_id");return t?{href:`?tab=mcp&item=${encodeURIComponent(t)}`,hrefLabel:"Open in MCP →",title:`MCP server ${"install_mcp"===e.kind?"installed":"updated"}`}:null}case"update_agent":case"update_agent_tools":{let e=s("agent_id");return e?{href:`?tab=agents&item=${encodeURIComponent(e)}`,hrefLabel:"Open agent →",title:"Agent updated"}:null}case"upsert_harness":{let t=e.result??null,a=(t&&"string"==typeof t.id?t.id:void 0)??s("id");return a?{href:`?tab=harness&item=${encodeURIComponent(a)}`,hrefLabel:"Open in Harness →",title:"Harness saved"}:{href:"?tab=harness",hrefLabel:"Open Harness →",title:"Harness saved"}}default:return null}}(e);t&&f({kind:"success",source:"system",sourceLabel:"Setup",title:t.title,body:e.reason??"Change applied.",agent_id:e.agent_id??null,thread_id:null,href:t.href,hrefLabel:t.hrefLabel,ttl:8e3})}function F({agentId:e,onChange:t}){let[s,l]=(0,i.useState)([]),[o,d]=(0,i.useState)(!1),[u,x]=(0,i.useState)(new Set),[m,p]=(0,i.useState)(null);async function h(){try{let t=await c.FH.pending.list("pending"),s=e?t.filter(t=>t.agent_id===e):t;l(s)}catch(e){console.error(e)}}function f(e,t){x(s=>{let a=new Set(s);return t?a.add(e):a.delete(e),a})}async function g(e){f(e.id,!0);try{await c.FH.pending.approve(e.id),I(e),await h(),t?.()}catch(e){console.error(e)}finally{f(e.id,!1)}}async function b(e){f(e.id,!0);try{await c.FH.pending.deny(e.id),await h(),t?.()}catch(e){console.error(e)}finally{f(e.id,!1)}}async function j(e){let s=e.payload.integration_id;f(e.id,!0);try{await c.FH.pending.approve(e.id);let a=null;"gmail"===s?a=await c.FH.integrations.gmailOauthStart({}):"outlook"===s&&(a=await c.FH.integrations.outlookOauthStart({})),a?.authorize_url&&window.open(a.authorize_url,"_blank","noopener,noreferrer"),I(e),await h(),t?.()}catch(e){console.error(e)}finally{f(e.id,!1)}}async function y(e){let t=e.payload.id;if(t){f(e.id,!0);try{let s=(await c.FH.integrations.list()).definitions.find(e=>e.name===t);if(!s)return void await b(e);p({action:e,fields:s.fields.map(e=>({key:e.key,label:e.label,secret:e.secret,required:e.required,placeholder:e.placeholder})),values:{},submitting:!1,error:null})}catch(e){console.error(e)}finally{f(e.id,!1)}}}async function v(){if(!m)return;let e=m.fields.filter(e=>e.required&&!m.values[e.key]?.trim()).map(e=>e.label);if(e.length>0)return void p({...m,error:`Required: ${e.join(", ")}`});p({...m,submitting:!0,error:null});try{let e={};for(let[t,s]of Object.entries(m.values))"string"==typeof s&&s.trim()&&(e[t]=s.trim());await c.FH.pending.approve(m.action.id,e),I(m.action),p(null),await h(),t?.()}catch(e){p({...m,submitting:!1,error:e instanceof Error?e.message:String(e)})}}return(0,i.useEffect)(()=>{h();let e=setInterval(h,4e3),t=()=>{document.hidden||h()};return document.addEventListener("visibilitychange",t),()=>{clearInterval(e),document.removeEventListener("visibilitychange",t)}},[e]),0!==s.length||m?(0,a.jsxs)(a.Fragment,{children:[s.length>0&&(0,a.jsxs)("div",{className:"mx-4 mb-2 rounded-lg border border-amber-700/60 bg-amber-950/30 overflow-hidden",children:[(0,a.jsxs)("button",{onClick:()=>d(e=>!e),className:"w-full flex items-center gap-2 px-3 py-2 text-xs text-amber-800 dark:text-amber-200 hover:bg-amber-900/20 transition-colors",children:[(0,a.jsx)(T.A,{size:13,className:"text-amber-700 dark:text-amber-400 shrink-0"}),(0,a.jsxs)("span",{className:"font-medium",children:[s.length," ",1===s.length?"change":"changes"," awaiting your approval"]}),(0,a.jsx)("span",{className:"ml-auto opacity-70",children:o?(0,a.jsx)($.A,{size:13}):(0,a.jsx)(r.A,{size:13})})]}),o&&(0,a.jsx)("div",{className:"border-t border-amber-700/40 divide-y divide-amber-700/30",children:s.map(e=>{let t=u.has(e.id);return(0,a.jsxs)("div",{className:"px-3 py-2.5 text-xs",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,a.jsx)("span",{className:"font-mono uppercase tracking-wide text-[10px] text-amber-700 dark:text-amber-400/80",children:e.kind}),e.reason&&(0,a.jsx)("span",{className:"text-amber-100/90",children:e.reason})]}),(0,a.jsx)("pre",{className:"text-[11px] text-amber-800 dark:text-amber-200/70 font-mono whitespace-pre-wrap break-words bg-amber-950/40 rounded p-2 mb-2",children:JSON.stringify(e.payload,null,2)}),(0,a.jsxs)("div",{className:"flex gap-1.5 justify-end",children:[(0,a.jsxs)("button",{onClick:()=>b(e),disabled:t,className:"inline-flex items-center gap-1 px-2 py-1 text-[11px] rounded border border-border text-fg-subtle hover:text-fg hover:border-fg-faint disabled:opacity-50",children:[(0,a.jsx)(z.A,{size:11})," Deny"]}),(0,a.jsxs)("button",{onClick:()=>(function(e){switch(e.kind){case"set_provider_key":return void p({action:e,fields:[{key:"api_key",label:"API key",secret:!0,required:!0,placeholder:"sk-…"},{key:"base_url",label:"Base URL (optional)",secret:!1,required:!1,placeholder:"https://…"}],values:{},submitting:!1,error:null});case"enable_integration":return y(e);case"start_oauth":return j(e);default:return g(e)}})(e),disabled:t,className:"inline-flex items-center gap-1 px-2 py-1 text-[11px] rounded bg-emerald-700 hover:bg-emerald-600 text-white disabled:opacity-50",children:[(0,a.jsx)(n.A,{size:11})," ",t?"Applying…":"Approve"]})]})]},e.id)})})]}),m&&(0,a.jsx)(L,{state:m,onChangeValue:(e,t)=>p({...m,values:{...m.values,[e]:t}}),onCancel:()=>p(null),onSubmit:()=>void v()})]}):null}function L({state:e,onChangeValue:t,onCancel:s,onSubmit:r}){let n="set_provider_key"===e.action.kind?"Provide API key":"enable_integration"===e.action.kind?"Enable integration":"Provide credentials";return(0,a.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 px-4",children:(0,a.jsxs)("div",{className:"w-full max-w-md rounded-xl border border-border bg-surface-2 shadow-xl",children:[(0,a.jsxs)("div",{className:"px-4 py-3 border-b border-border",children:[(0,a.jsx)("h2",{className:"text-sm font-semibold",children:n}),e.action.reason&&(0,a.jsx)("p",{className:"text-xs text-fg-subtle mt-1",children:e.action.reason})]}),(0,a.jsxs)("div",{className:"p-4 space-y-3",children:[(0,a.jsx)("pre",{className:"text-[11px] text-fg-subtle font-mono whitespace-pre-wrap break-words bg-surface rounded p-2 border border-border",children:JSON.stringify(e.action.payload,null,2)}),e.fields.map(s=>(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsxs)("label",{htmlFor:`sec-${s.key}`,className:"text-xs font-medium text-fg-subtle",children:[s.label,s.required?" *":""]}),(0,a.jsx)("input",{id:`sec-${s.key}`,type:s.secret?"password":"text",value:e.values[s.key]??"",onChange:e=>t(s.key,e.target.value),placeholder:s.placeholder,autoComplete:"off",spellCheck:!1,className:"w-full px-3 py-2 rounded border border-border bg-surface text-fg placeholder:text-fg-faint focus:border-emerald-500 focus:outline-none text-sm font-mono"})]},s.key)),e.error&&(0,a.jsx)("div",{className:"rounded p-2 text-xs border border-rose-700/50 bg-rose-950/30 text-rose-300",children:e.error}),(0,a.jsx)("p",{className:"text-[11px] text-fg-faint",children:"Sent only to your local Jarela database (encrypted at rest). The agent never sees these values."})]}),(0,a.jsxs)("div",{className:"px-4 py-3 border-t border-border flex justify-end gap-2",children:[(0,a.jsx)("button",{type:"button",onClick:s,disabled:e.submitting,className:"px-3 py-1.5 text-xs rounded border border-border text-fg-subtle hover:text-fg hover:border-fg-faint disabled:opacity-50",children:"Cancel"}),(0,a.jsx)("button",{type:"button",onClick:r,disabled:e.submitting,className:"px-3 py-1.5 text-xs rounded bg-emerald-700 hover:bg-emerald-600 text-white disabled:opacity-50",children:e.submitting?"Saving…":"Approve and save"})]})]})})}var R=s(5561),H=s(852),P=s(5688),O=s(9383);let M=[{name:"/new",description:"save session to memory and start fresh"}];function D(e){return new Promise((t,s)=>{let a=new FileReader;e.type.startsWith("image/")||"application/pdf"===e.type?(a.onload=()=>{let s=a.result.split(",")[1]??"";"application/pdf"===e.type?t({type:"file",name:e.name,media_type:"application/pdf",data:s}):t({type:"image",media_type:e.type,data:s})},a.onerror=()=>s(Error(`Failed to read ${e.name}`)),a.readAsDataURL(e)):(a.onload=()=>t({type:"file",name:e.name,media_type:e.type||"text/plain",data:a.result}),a.onerror=()=>s(Error(`Failed to read ${e.name}`)),a.readAsText(e))})}function U({value:e,onChange:t,attachments:s,onAttachmentsChange:r,onSubmit:n,onStop:l,streaming:o,disabled:c,placeholder:d,voiceEnabled:u,agentId:x,onVoiceTranscript:m}){let p=(0,i.useRef)(null),[h,f]=(0,i.useState)(0),[g,b]=(0,i.useState)(!1),[j,y]=(0,i.useState)(!1),[v,N]=(0,i.useState)(null),w=(0,i.useRef)(null),k=(0,i.useRef)([]);async function S(){if(u&&x&&!g&&!j){N(null);try{let e=await navigator.mediaDevices.getUserMedia({audio:!0}),t=MediaRecorder.isTypeSupported("audio/webm;codecs=opus")?"audio/webm;codecs=opus":MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":MediaRecorder.isTypeSupported("audio/mp4")?"audio/mp4":"",s=t?new MediaRecorder(e,{mimeType:t}):new MediaRecorder(e);k.current=[],s.ondataavailable=e=>{e.data.size>0&&k.current.push(e.data)},s.onstop=async()=>{e.getTracks().forEach(e=>e.stop());let t=new Blob(k.current,{type:s.mimeType||"audio/webm"});if(k.current=[],0===t.size)return void b(!1);b(!1),y(!0);try{let e=new FormData;e.append("agent_id",x),e.append("audio",t,`voice.${(s.mimeType||"audio/webm").includes("mp4")?"mp4":"webm"}`);let a=await fetch("/api/v1/voice/transcribe",{method:"POST",body:e});if(!a.ok)throw Error((await a.json().catch(()=>({}))).error??`HTTP ${a.status}`);let{text:r}=await a.json(),n=r.trim();n&&m?.(n)}catch(e){N(e instanceof Error?e.message:String(e))}finally{y(!1)}},s.start(),w.current=s,b(!0)}catch(e){N(e instanceof Error?e.message:String(e)),b(!1)}}}(0,i.useEffect)(()=>()=>{let e=w.current;if(e&&"inactive"!==e.state)try{e.stop()}catch{}e?.stream?.getTracks().forEach(e=>e.stop())},[]);let _=(0,i.useMemo)(()=>{let t=e.trimStart();if(!t.startsWith("/")||/\s/.test(t))return[];let s=t.toLowerCase();return M.filter(e=>e.name.startsWith(s))},[e]),C=_.length>0&&!o&&!c,A=Math.min(h,Math.max(_.length-1,0));function E(e){t(`${e} `),f(0)}async function T(e){let t=Array.from(e.target.files??[]);t.length&&(r([...s,...await Promise.all(t.map(D)).catch(e=>(console.error(e),[]))]),e.target.value="")}return(0,a.jsxs)("div",{className:"glass border-t border-border/60 px-3 sm:px-4 pt-2",style:{paddingBottom:"calc(0.75rem + env(safe-area-inset-bottom))"},children:[s.length>0&&(0,a.jsx)("div",{className:"flex flex-wrap gap-2 mb-2",children:s.map((e,t)=>(0,a.jsxs)("div",{className:"relative group shrink-0",children:["image"===e.type?(0,a.jsx)("img",{src:`data:${e.media_type};base64,${e.data}`,alt:"attachment",className:"h-14 w-14 object-cover rounded-lg border border-border"}):(0,a.jsxs)("div",{className:"h-10 px-2.5 flex items-center gap-1.5 rounded-lg border border-border bg-surface-3 text-[11px] text-fg-muted max-w-[140px]",children:[(0,a.jsx)(R.A,{size:11,className:"shrink-0 text-fg-faint"}),(0,a.jsx)("span",{className:"truncate",children:e.name})]}),(0,a.jsx)("button",{onClick:()=>{r(s.filter((e,s)=>s!==t))},className:"absolute -top-1.5 -right-1.5 hidden group-hover:flex w-4 h-4 rounded-full bg-surface-3 text-fg items-center justify-center",children:(0,a.jsx)(z.A,{size:9})})]},t))}),(0,a.jsxs)("div",{className:"relative flex gap-2 items-end",children:[C&&(0,a.jsxs)("div",{className:"absolute left-[52px] right-[52px] bottom-full mb-1 z-10 max-h-48 overflow-y-auto rounded-xl border border-border/60 bg-surface-2/95 shadow-lg backdrop-blur",children:[_.map((e,t)=>(0,a.jsxs)("button",{type:"button",onMouseDown:t=>{t.preventDefault(),E(e.name)},onMouseEnter:()=>f(t),className:`w-full text-left px-3 py-2 flex items-baseline gap-2 text-sm transition-colors ${t===A?"bg-surface-3 text-fg":"text-fg-muted hover:bg-surface-3/60"}`,children:[(0,a.jsx)("span",{className:"font-mono text-accent",children:e.name}),(0,a.jsx)("span",{className:"text-xs text-fg-faint truncate",children:e.description})]},e.name)),(0,a.jsx)("div",{className:"px-3 py-1 text-[10px] text-fg-faint border-t border-border/40",children:"Tab to complete \xb7 ↑↓ to navigate \xb7 Esc to clear"})]}),(0,a.jsx)("input",{ref:p,type:"file",multiple:!0,accept:"image/*,text/*,.ts,.tsx,.js,.jsx,.json,.md,.py,.go,.rs,.yaml,.yml,.toml,.sh,.sql,.pdf",className:"hidden",onChange:T,disabled:c}),(0,a.jsx)("button",{onClick:()=>p.current?.click(),disabled:c||o,className:"shrink-0 h-11 w-11 flex items-center justify-center rounded-xl text-fg-faint hover:text-fg hover:bg-surface-3 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",title:"Attach file or image",children:(0,a.jsx)(R.A,{size:16})}),u&&x&&(0,a.jsx)("button",{onClick:g?function(){let e=w.current;if(e&&"inactive"!==e.state)try{e.stop()}catch{}}:S,disabled:c||o||j,className:`shrink-0 h-11 w-11 flex items-center justify-center rounded-xl transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${g?"bg-rose-500 text-white animate-pulse":"text-fg-faint hover:text-fg hover:bg-surface-3"}`,title:g?"Stop recording":j?"Transcribing…":"Record voice message","aria-label":g?"Stop recording":"Record voice message",children:g?(0,a.jsx)(H.A,{size:14}):(0,a.jsx)(P.A,{size:16})}),(0,a.jsx)("textarea",{className:"flex-1 resize-none bg-surface-3/60 text-fg text-sm rounded-xl px-3 py-2 border border-border/60 focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent/40 placeholder:text-fg-faint max-h-48 min-h-[44px] transition-colors",placeholder:d??"Message…",rows:1,value:e,onChange:e=>{t(e.target.value),e.target.style.height="auto",e.target.style.height=`${Math.min(e.target.scrollHeight,192)}px`},onKeyDown:function(a){if(C)if("Tab"!==a.key&&("Enter"!==a.key||a.shiftKey)){if("ArrowDown"===a.key){a.preventDefault(),f(e=>(e+1)%_.length);return}else if("ArrowUp"===a.key){a.preventDefault(),f(e=>(e-1+_.length)%_.length);return}else if("Escape"===a.key){a.preventDefault(),t("");return}}else{let t=_.find(t=>t.name===e.trim());if(!("Enter"===a.key&&t)){a.preventDefault(),E(_[A].name);return}}"Enter"===a.key&&!a.shiftKey&&(a.preventDefault(),!c&&(e.trim()||s.length)&&n())},onPaste:function(e){let t=Array.from(e.clipboardData.items).filter(e=>"file"===e.kind&&e.type.startsWith("image/"));t.length&&(e.preventDefault(),t.forEach(e=>{let t=e.getAsFile();t&&D(t).then(e=>r([...s,e])).catch(console.error)}))},disabled:c}),o?(0,a.jsx)("button",{onClick:l,className:"glass-btn-stop shrink-0 h-11 w-11 flex items-center justify-center rounded-xl text-white transition-colors",title:"Stop",children:(0,a.jsx)(H.A,{size:16})}):(0,a.jsx)("button",{onClick:n,disabled:!e.trim()&&!s.length||c,className:"glass-btn-send shrink-0 h-11 w-11 flex items-center justify-center rounded-xl text-white transition-colors disabled:opacity-40 disabled:cursor-not-allowed",title:"Send",children:(0,a.jsx)(O.A,{size:16})})]}),v&&(0,a.jsx)("p",{className:"mt-1 text-[11px] text-rose-500",role:"alert",children:v}),j&&!v&&(0,a.jsx)("p",{className:"mt-1 text-[11px] text-fg-faint","aria-live":"polite",children:"Transcribing…"})]})}var J=s(9805),q=s(5182),G=s(9034),W=s(6721),B=s(6923);function V({events:e}){let[t,s]=(0,i.useState)(null),[r,n]=(0,i.useState)(e.length<=3);if(!r){let t=Array.from(new Set(e.map(e=>e.name))).filter(Boolean),s=e.filter(e=>"call"===e.phase).length,r=e.filter(e=>"result"===e.phase&&K(e.payload)).length;return(0,a.jsx)("div",{className:"my-1.5 w-full min-w-0 max-w-full overflow-hidden",children:(0,a.jsxs)("button",{onClick:()=>n(!0),className:"w-full min-w-0 flex items-center gap-1.5 text-[11px] hover:bg-surface-2/40 px-1 py-0.5 rounded-md text-left",children:[(0,a.jsx)(W.A,{size:10,className:"shrink-0 text-fg-faint"}),(0,a.jsxs)("span",{className:"inline-flex items-center gap-1.5 shrink-0 px-2 py-0.5 rounded-full bg-surface-2/60 border border-border/50 text-fg-muted",children:[(0,a.jsx)("span",{className:`w-1.5 h-1.5 rounded-full ${r>0?"bg-rose-500":"bg-emerald-500"}`,"aria-hidden":!0}),(0,a.jsxs)("span",{className:"font-medium",children:[s," tool",1===s?"":"s",r>0&&(0,a.jsxs)("span",{className:"text-rose-700 dark:text-rose-400/90",children:[" \xb7 ",r," err"]})]})]}),(0,a.jsx)("span",{className:"truncate text-fg-faint font-normal flex-1 min-w-0",children:t.join(" \xb7 ")})]})})}return(0,a.jsxs)("div",{className:"my-1.5 w-full min-w-0 max-w-full overflow-hidden",children:[e.length>3&&(0,a.jsxs)("button",{onClick:()=>n(!1),className:"w-full min-w-0 flex items-center gap-1.5 text-[11px] hover:bg-surface-2/40 px-1 py-0.5 rounded text-left text-fg-faint",children:[(0,a.jsx)(W.A,{size:10,className:"shrink-0 rotate-90 transition-transform"}),(0,a.jsx)("span",{className:"font-mono uppercase tracking-wide shrink-0",children:"collapse"})]}),e.map((e,r)=>{let n=`${e.id}-${e.phase}-${r}`,l=t===n,i=function(e){try{let t=("string"==typeof e?e:JSON.stringify(e)).replace(/\s+/g," ");return t.length>80?t.slice(0,80)+"…":t}catch{return""}}(e.payload),o=K(e.payload),c="call"===e.phase?"bg-sky-500":o?"bg-rose-500":"bg-emerald-500";return(0,a.jsxs)("div",{className:"min-w-0 max-w-full",children:[(0,a.jsxs)("button",{onClick:()=>s(l?null:n),className:"w-full min-w-0 flex items-center gap-1.5 text-[11px] hover:bg-surface-2/40 px-1 py-0.5 rounded-md text-left",children:[(0,a.jsx)(W.A,{size:10,className:`transition-transform shrink-0 ${l?"rotate-90":""} text-fg-faint`}),(0,a.jsxs)("span",{className:"inline-flex items-center gap-1.5 shrink-0 px-2 py-0.5 rounded-full bg-surface-2/60 border border-border/50 text-fg-muted",children:[(0,a.jsx)("span",{className:`w-1.5 h-1.5 rounded-full ${c}`,"aria-hidden":!0}),(0,a.jsx)("span",{className:"font-medium",children:e.name})]}),!l&&(0,a.jsx)("span",{className:"truncate text-fg-faint italic font-normal flex-1 min-w-0",children:i})]}),l&&(0,a.jsx)("pre",{className:"ml-5 mt-1 mb-1 px-2 py-1.5 text-[11px] text-fg-muted whitespace-pre font-mono bg-surface/60 rounded-lg border border-border/50 max-w-[calc(100%-1.25rem)] overflow-x-auto",children:JSON.stringify(e.payload,null,2)})]},n)})]})}function K(e){return"string"==typeof e?/error/i.test(e):!!e&&"object"==typeof e&&"error"in e}var Y=s(6804),Q=s(2957),Z=s(6182),X=s(2615),ee=s(4764),et=s(3835);s(2620);var es=s(1161),ea=s(710),er=s(3744),en=s(7465),el=s(4551),ei=s(9314),eo=s(8747),ec=s(2571),ed=s(9267),eu=s(6619);let ex=new Set;function em({href:e}){let t=/[?&]autoplay=1\b/.test(e),[s]=(0,i.useState)(()=>t&&!ex.has(e));return(0,a.jsx)("audio",{controls:!0,preload:"metadata",autoPlay:s,src:e,className:"my-2 w-full max-w-md",onPlay:()=>{t&&ex.add(e)}})}function ep({ctx:e,accent:t}){let[s,r]=(0,i.useState)(!1),n=(()=>{try{return new URL(e.url).hostname}catch{return e.url}})();return(0,a.jsxs)("div",{className:"flex flex-col gap-1.5 min-w-0",children:[(0,a.jsxs)("button",{type:"button",onClick:()=>r(e=>!e),className:`flex items-center gap-2 text-left min-w-0 ${t?"text-white/95 hover:text-white":"text-fg hover:text-fg-muted"}`,"aria-expanded":s,title:s?"Hide captured content":"Show captured content",children:[(0,a.jsx)(W.A,{size:12,className:`shrink-0 transition-transform ${s?"rotate-90":""}`}),(0,a.jsx)(R.A,{size:12,className:"shrink-0"}),(0,a.jsx)("span",{className:"text-[13px] font-medium truncate min-w-0",children:e.title||n})]}),(0,a.jsxs)("div",{className:`flex flex-wrap items-center gap-1.5 text-[10px] pl-5 ${t?"text-white/75":"text-fg-faint"}`,children:[(0,a.jsxs)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),className:"inline-flex items-center gap-1 underline decoration-dotted hover:decoration-solid truncate max-w-[18rem]",title:e.url,children:[(0,a.jsx)(es.A,{size:9,className:"shrink-0"}),(0,a.jsx)("span",{className:"truncate",children:n})]}),e.selector&&(0,a.jsx)("span",{className:`px-1.5 py-0.5 rounded font-mono ${t?"bg-white/15":"bg-surface-3"}`,title:e.selector,children:e.selector.length>36?`…${e.selector.slice(-33)}`:e.selector}),e.truncated&&(0,a.jsx)("span",{className:`px-1.5 py-0.5 rounded ${t?"bg-amber-300/25 text-amber-50":"bg-amber-900/30 text-amber-300"}`,title:e.originalBytes?`Original was ${e.originalBytes.toLocaleString()} bytes`:void 0,children:"truncated to 100KB"})]}),s&&e.body&&(0,a.jsx)("div",{className:`mt-1 pt-2 pl-5 border-t ${t?"border-white/20":"border-border/60"}`,children:(0,a.jsx)("p",{className:"whitespace-pre-wrap text-[12.5px] leading-relaxed opacity-90",children:e.body})})]})}function eh({children:e,threshold:t=480,accent:s}){let r=(0,i.useRef)(null),[n,l]=(0,i.useState)(!1),[o,c]=(0,i.useState)(!1);(0,i.useEffect)(()=>{let e=r.current;if(!e)return;let s=()=>l(e.scrollHeight>t+24);s();let a=new ResizeObserver(s);return a.observe(e),()=>a.disconnect()},[t]);let d=n&&!o;return(0,a.jsxs)("div",{className:"flex flex-col",children:[(0,a.jsxs)("div",{ref:r,className:d?"relative overflow-hidden":"",style:d?{maxHeight:t}:void 0,children:[e,d&&(0,a.jsx)("div",{className:`pointer-events-none absolute inset-x-0 bottom-0 h-16 bg-gradient-to-t ${s?"from-black/30":"from-surface-1/90"} to-transparent`})]}),n&&(0,a.jsxs)("button",{type:"button",onClick:()=>c(e=>!e),className:`mt-1.5 self-start inline-flex items-center gap-1 text-[11px] ${s?"text-white/85 hover:text-white":"text-fg-faint hover:text-fg-muted"}`,"aria-expanded":o,children:[(0,a.jsx)(W.A,{size:10,className:`transition-transform ${o?"rotate-90":""}`}),o?"Show less":"Show more"]})]})}let ef={...ee.j,tagNames:[...ee.j.tagNames??[],"details","summary","mark","kbd","sub","sup","abbr","small","aside","figure","figcaption","dl","dt","dd","audio","source"],attributes:{...ee.j.attributes??{},"*":[...(ee.j.attributes??{})["*"]??[],"className","title"],aside:["className"],abbr:["title"],details:["open"],audio:["src","controls","preload","loop","autoplay","muted"],source:["src","type"]}},eg=[Q.A],eb=[Z.A,[X.A,{detect:!0,ignoreMissing:!0}],[et.A,ef]];function ej(e){return null==e||"boolean"==typeof e?"":"string"==typeof e||"number"==typeof e?String(e):Array.isArray(e)?e.map(ej).join(""):"object"==typeof e&&"props"in e?ej(e.props.children):""}let ey=["from-violet-500 to-indigo-600","from-blue-500 to-cyan-600","from-emerald-500 to-teal-600","from-orange-500 to-amber-600","from-rose-500 to-pink-600","from-fuchsia-500 to-purple-600"];function ev({config:e}){return e?.icon?(0,a.jsx)("img",{src:e.icon,alt:e.name,className:"w-7 h-7 rounded-lg object-cover"}):e?(0,a.jsx)("div",{className:`w-7 h-7 rounded-lg bg-gradient-to-br ${function(e){let t=0;for(let s=0;s<e.length;s++)t=31*t+e.charCodeAt(s)|0;return ey[Math.abs(t)%ey.length]}(e.id)} flex items-center justify-center text-xs font-bold text-white select-none`,children:e.name.charAt(0).toUpperCase()}):(0,a.jsx)("div",{className:"w-7 h-7 rounded-lg bg-surface-3 flex items-center justify-center",children:(0,a.jsx)(ea.A,{size:13,className:"text-fg-faint"})})}function eN({profile:e}){return e?.icon?(0,a.jsx)("img",{src:e.icon,alt:e.name||"You",className:"w-7 h-7 rounded-lg object-cover"}):e?.name?(0,a.jsx)("div",{className:"w-7 h-7 rounded-lg bg-accent flex items-center justify-center text-xs font-bold text-white select-none",children:e.name.charAt(0).toUpperCase()}):(0,a.jsx)("div",{className:"w-7 h-7 rounded-lg bg-surface-3 flex items-center justify-center",children:(0,a.jsx)(er.A,{size:13,className:"text-fg-faint"})})}function ew(e){if(!e.startsWith("[bridge:"))return null;let t={},s=e.split("\n"),a=0;for(;a<s.length;a++){let e=s[a];if(""===e){a++;break}let r=/^\[([a-z_]+):([\s\S]*)\]$/.exec(e);if(!r)return null;t[r[1]]=r[2]}return t.bridge&&t.chat_jid&&t.chat_type?{bridgeId:t.bridge,chatJid:t.chat_jid,chatName:t.chat_name||t.chat_jid,isGroup:"group"===t.chat_type,senderJid:t.sender_jid||t.chat_jid,senderName:t.sender_name||t.sender_jid||"Unknown",body:s.slice(a).join("\n").trimEnd()}:null}function ek({ctx:e}){let t=e.isGroup&&e.chatName&&e.chatName!==e.senderName;return(0,a.jsxs)("div",{className:"flex flex-col gap-1.5 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-1.5 text-[11px] text-white/85 min-w-0",children:[e.isGroup?(0,a.jsx)(en.A,{size:11,className:"shrink-0"}):(0,a.jsx)(el.A,{size:11,className:"shrink-0"}),(0,a.jsx)("span",{className:"font-medium truncate",title:e.senderJid,children:e.senderName}),t&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{className:"text-white/55",children:"in"}),(0,a.jsx)("span",{className:"truncate",title:e.chatJid,children:e.chatName})]}),(0,a.jsx)("span",{className:"px-1.5 py-0.5 rounded-full bg-white/15 text-[9.5px] uppercase tracking-wide shrink-0",children:e.isGroup?"group":"dm"})]}),e.body?(0,a.jsx)("p",{className:"whitespace-pre-wrap text-[13.5px] leading-relaxed",children:e.body}):(0,a.jsx)("p",{className:"text-[12px] italic text-white/65",children:"(empty message)"})]})}function eS({src:e,alt:t}){let[s,r]=(0,i.useState)(0),[n,l]=(0,i.useState)(!1),o="string"==typeof e?e:e instanceof Blob?URL.createObjectURL(e):"",c=o?`${o}${o.includes("?")?"&":"?"}retry=${s}`:"";return o?n?(0,a.jsxs)("div",{className:"my-2 px-3 py-2 rounded border border-amber-700/50 bg-amber-900/20 text-xs text-amber-300",children:[(0,a.jsx)("div",{children:"Image failed to load."}),(0,a.jsxs)("div",{className:"mt-1 flex items-center gap-2",children:[(0,a.jsx)("button",{type:"button",className:"px-2 py-1 rounded border border-amber-500/60 hover:bg-amber-900/30",onClick:()=>{l(!1),r(e=>e+1)},children:"Retry"}),(0,a.jsx)("a",{href:o,target:"_blank",rel:"noopener noreferrer",className:"underline decoration-dotted hover:decoration-solid break-all",children:"Open image"})]})]}):(0,a.jsx)("img",{src:c,alt:t??"image",loading:"lazy",className:"rounded-lg border border-border/50",onError:()=>{0===s?r(1):l(!0)}}):(0,a.jsx)("div",{className:"my-2 px-3 py-2 rounded border border-rose-800/60 bg-rose-950/30 text-xs text-rose-700 dark:text-rose-300",children:"Invalid image URL in markdown."})}function e_({payload:e}){let[t,s]=(0,i.useState)(0),[r,n]=(0,i.useState)(!1),l=null,o=null;try{let t=JSON.parse(e),s=new URLSearchParams;for(let e of["q","center","zoom","origin","destination","search","mode"]){let a=t[e];"string"==typeof a&&a.length>0?s.set(e,a):"number"==typeof a&&s.set(e,String(a))}0==[...s.keys()].length?o="no recognized fields (q / center / origin+destination / search)":l=s}catch(e){o=e instanceof Error?e.message:String(e)}if(!l)return(0,a.jsxs)("div",{className:"my-2 px-3 py-2 rounded border border-rose-800/60 bg-rose-950/30 text-xs text-rose-700 dark:text-rose-300",children:["Invalid map block: ",o]});let c=`/api/v1/maps/embed?${l.toString()}${t>0?`&retry=${t}`:""}`;if(r){let e=l.get("q")??l.get("search")??l.get("center")??"",t=e?`https://www.google.com/maps?q=${encodeURIComponent(e)}`:"https://www.google.com/maps";return(0,a.jsxs)("div",{className:"my-2 px-3 py-2 rounded border border-amber-700/50 bg-amber-900/20 text-xs text-amber-300",children:[(0,a.jsx)("div",{children:"Map failed to load."}),(0,a.jsxs)("div",{className:"mt-1 flex items-center gap-2",children:[(0,a.jsx)("button",{type:"button",className:"px-2 py-1 rounded border border-amber-500/60 hover:bg-amber-900/30",onClick:()=>{n(!1),s(e=>e+1)},children:"Retry"}),(0,a.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"underline decoration-dotted hover:decoration-solid",children:"Open in Google Maps"})]})]})}return(0,a.jsx)("div",{className:"my-2 rounded overflow-hidden border border-border bg-surface-2",children:(0,a.jsx)("iframe",{src:c,title:"Map",width:"100%",height:"320",loading:"lazy",referrerPolicy:"no-referrer-when-downgrade",allowFullScreen:!0,style:{border:0,display:"block"},onError:()=>{0===t?s(1):n(!0)}})})}function eC({text:e,streaming:t,onInAppLink:s}){return(0,a.jsxs)("div",{className:"prose prose-invert prose-sm max-w-none jarela-rich",children:[(0,a.jsx)(Y.oz,{remarkPlugins:eg,rehypePlugins:eb,components:{a({href:e,children:t,...r}){let n=e?k(e):void 0;return e&&/^\/api\/v1\/files\/[^?#]+\.(wav|mp3|ogg|webm|m4a)(\?|#|$)/i.test(e)?(0,a.jsx)(em,{href:e}):n&&!n.external&&(n.tab||n.hash)&&e&&s?(0,a.jsx)("a",{...r,href:e,onClick:t=>{t.preventDefault(),s(e)},children:t}):(0,a.jsx)("a",{...r,href:e,target:"_blank",rel:"noopener noreferrer",children:t})},pre:({children:e})=>(0,a.jsx)(a.Fragment,{children:e}),code({className:e,children:t}){let s=/language-(\w+)/.exec(e??"");return s?.[1]==="map"?(0,a.jsx)(e_,{payload:ej(t).replace(/\n$/,"")}):s?(0,a.jsx)(eE,{language:s[1],className:e??"",children:t}):(0,a.jsx)("code",{className:"bg-surface-2 px-1 rounded text-fg-muted break-all",children:t})},img:({src:e,alt:t})=>(0,a.jsx)(eS,{src:e,alt:t})},children:e}),t&&(0,a.jsxs)("span",{className:"inline-flex items-center align-middle ml-1","aria-label":"typing",children:[(0,a.jsx)("span",{className:"jarela-typing-dot"}),(0,a.jsx)("span",{className:"jarela-typing-dot"}),(0,a.jsx)("span",{className:"jarela-typing-dot"})]})]})}function eA({refs:e}){let[t,s]=(0,i.useState)(!1);return 0===e.length?null:(0,a.jsxs)("div",{className:"mt-1.5",children:[(0,a.jsxs)("button",{onClick:()=>s(e=>!e),className:"inline-flex items-center gap-1 text-[11px] text-fg-faint hover:text-fg-muted transition-colors",children:[(0,a.jsx)(W.A,{size:10,className:`transition-transform ${t?"rotate-90":""}`}),(0,a.jsx)(es.A,{size:10}),(0,a.jsxs)("span",{children:[e.length," ",1===e.length?"reference":"references"]})]}),t&&(0,a.jsx)("ul",{className:"mt-1 space-y-0.5 pl-4",children:e.map((e,t)=>(0,a.jsx)("li",{className:"text-[11px]",children:(0,a.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",className:"text-sky-700 dark:text-sky-400 hover:text-sky-700 dark:hover:text-sky-300 hover:underline truncate inline-block max-w-full align-middle",title:e.url,children:e.title||e.url})},`${t}-${e.url}`))})]})}function eE({language:e,className:t,children:s}){let[r,l]=(0,i.useState)(!1),o=(0,i.useMemo)(()=>ej(s).replace(/\n$/,""),[s]),c=(0,i.useCallback)(()=>{navigator.clipboard.writeText(o).then(()=>{l(!0),setTimeout(()=>l(!1),1200)}).catch(console.error)},[o]);return(0,a.jsxs)("div",{className:"relative my-2 rounded-md overflow-hidden border border-border/60",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between px-2 py-1 text-[10px] bg-surface-3 text-fg-faint uppercase tracking-wide",children:[(0,a.jsx)("span",{children:e}),(0,a.jsxs)("button",{onClick:c,className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-border/60 bg-surface-2 text-fg-muted hover:text-fg transition-colors",title:"Copy code","aria-label":"Copy code",children:[r?(0,a.jsx)(n.A,{size:10}):(0,a.jsx)(ei.A,{size:10}),(0,a.jsx)("span",{children:r?"Copied":"Copy"})]})]}),(0,a.jsx)("pre",{className:"m-0 p-3 text-xs leading-relaxed overflow-x-auto bg-[#0d1117]",children:(0,a.jsx)("code",{className:t,children:s})})]})}function eT({part:e,isUser:t,onInAppLink:s}){if("text"===e.type)return t?(0,a.jsx)("p",{className:"whitespace-pre-wrap",children:e.text}):(0,a.jsx)(eC,{text:e.text,onInAppLink:s});if("image"===e.type)return(0,a.jsx)(e$,{media_type:e.media_type,data:e.data});let r=`data:${e.media_type};base64,${e.data}`,n=/^text\/|^application\/json$/.test(e.media_type)?`data:${e.media_type};charset=utf-8,${encodeURIComponent(e.data)}`:r;return e.media_type.startsWith("audio/")?(0,a.jsxs)("div",{className:"mt-1 max-w-md",children:[(0,a.jsx)("audio",{controls:!0,className:"w-full",src:r}),(0,a.jsx)("div",{className:"mt-0.5 text-[10px] text-fg-faint truncate",children:e.name})]}):e.media_type.startsWith("video/")?(0,a.jsxs)("div",{className:"mt-1 max-w-md",children:[(0,a.jsx)("video",{controls:!0,playsInline:!0,className:"w-full rounded-xl border border-border/40",style:{maxHeight:"400px"},src:r}),(0,a.jsx)("div",{className:"mt-0.5 text-[10px] text-fg-faint truncate",children:e.name})]}):(0,a.jsxs)("a",{href:n,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 px-2.5 py-1.5 mt-1 rounded-lg border border-border/60 bg-surface-3/60 hover:bg-surface-3 hover:border-border text-[11px] text-fg-muted transition-colors",title:"Open in new tab",children:[(0,a.jsx)(R.A,{size:11,className:"text-fg-faint shrink-0"}),(0,a.jsx)("span",{className:"truncate max-w-[200px]",children:e.name})]})}function e$({media_type:e,data:t}){let[s,r]=(0,i.useState)(!1),n=`data:${e};base64,${t}`;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("img",{src:n,alt:"attached image",onClick:()=>r(!0),className:"max-w-full rounded-xl mt-1 border border-border/40 cursor-zoom-in hover:border-fg-faint transition-colors",style:{maxHeight:"400px",objectFit:"contain"}}),s&&(0,a.jsxs)("div",{onClick:()=>r(!1),className:"fixed inset-0 z-[60] bg-black/85 backdrop-blur-sm flex items-center justify-center p-4 cursor-zoom-out animate-in fade-in",children:[(0,a.jsx)("img",{src:n,alt:"attached image",className:"max-w-full max-h-full object-contain rounded-lg shadow-2xl",onClick:e=>e.stopPropagation()}),(0,a.jsx)("button",{onClick:e=>{e.stopPropagation(),r(!1)},className:"absolute top-4 right-4 p-2 rounded-full bg-black/40 hover:bg-black/60 text-white","aria-label":"Close",children:(0,a.jsx)(z.A,{size:16})}),(0,a.jsx)("a",{href:n,target:"_blank",rel:"noreferrer",onClick:e=>e.stopPropagation(),className:"absolute bottom-4 right-4 px-3 py-1.5 rounded-md bg-black/40 hover:bg-black/60 text-white text-xs",children:"Open in new tab"})]})]})}let ez=(0,i.memo)(function({message:e,agentConfig:t,userProfile:s,showAvatar:r=!0,threadId:l=null,showToolEvents:c=!0}){let d,u,{dispatch:x}=(0,o.U)(),m="user"===e.role,p="streaming"in e&&e.streaming,h=function(e){if(!e.startsWith("["))return e;try{let t=JSON.parse(e);if(Array.isArray(t)&&t.length>0&&"object"==typeof t[0]&&null!==t[0]&&"type"in t[0])return t}catch{}return e}(e.content),g="id"in e?e.id:null,b=(0,i.useCallback)(e=>{let t=k(e);if(t.tab&&(x({type:"SET_TAB",tab:t.tab}),x({type:"SET_SELECTION",tab:t.tab,itemId:t.item??null})),t.hash&&1){let e=`${window.location.pathname}${window.location.search}`;window.location.hash===`#${t.hash}`&&window.history.replaceState(null,"",e),window.history.replaceState(null,"",`${e}#${t.hash}`),window.dispatchEvent(new HashChangeEvent("hashchange"))}},[x]),j=(0,i.useCallback)(()=>{if(!g)return;let e=new URLSearchParams;l&&e.set("thread",l);let t=e.toString(),s=`${window.location.origin}/${t?`?${t}`:""}#msg-${g}`;navigator.clipboard.writeText(s).then(()=>{f({kind:"success",source:"system",sourceLabel:"Chat",title:"Link copied",body:"Paste anywhere to jump back to this message.",agent_id:null,thread_id:l,ttl:2200})}).catch(console.error)},[g,l]),[y,v]=(0,i.useState)(!1),N=(0,i.useCallback)(()=>{let e="string"==typeof h?h:h.map(e=>"text"===e.type?e.text:"file"===e.type?`[File: ${e.name}]`:"image"===e.type?`[Image: ${e.media_type}]`:"").filter(Boolean).join("\n\n");e&&navigator.clipboard.writeText(e).then(()=>{v(!0),setTimeout(()=>v(!1),1200),f({kind:"success",source:"system",sourceLabel:"Chat",title:"Message copied",body:"Copied message content to clipboard.",agent_id:null,thread_id:l,ttl:2e3})}).catch(console.error)},[h,l]),w=!m&&!!t?.voice_enabled,S=m?"":function(e){let t="";if("string"==typeof e)t=e;else if(Array.isArray(e))for(let s of e)s&&"object"==typeof s&&"type"in s&&"text"===s.type&&"string"==typeof s.text&&(t+=`${s.text}
2
- `);return(t=t.replace(/<refs>[\s\S]*?<\/refs>/gi," ").replace(/```[\s\S]*?```/g," [code] ").replace(/`([^`]+)`/g,"$1").replace(/!\[[^\]]*\]\([^)]*\)/g," ").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/[#>*_~]+/g," ").replace(/\s+/g," ").trim()).length>5e3?t.slice(0,5e3):t}(e.content),_=(0,i.useRef)(null),C=(0,i.useRef)(null),[A,E]=(0,i.useState)("idle"),[T,$]=(0,i.useState)(null),z=(0,i.useCallback)(()=>{let e=_.current;if(e){try{e.pause()}catch{}e.src="",_.current=null}C.current&&(URL.revokeObjectURL(C.current),C.current=null)},[]);(0,i.useEffect)(()=>()=>z(),[z]);let I=(0,i.useCallback)(async()=>{if(w&&t&&!p&&S.trim()){if(_.current&&C.current){if("playing"===A)_.current.pause(),E("paused");else try{await _.current.play(),E("playing")}catch(e){$(e instanceof Error?e.message:String(e)),E("error")}return}$(null),E("loading");try{let e=await fetch("/api/v1/voice/tts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agent_id:t.id,text:S})});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error??`HTTP ${e.status}`)}let s=await e.blob(),a=URL.createObjectURL(s);C.current=a;let r=new Audio(a);r.onended=()=>E("idle"),r.onpause=()=>E(e=>"playing"===e?"paused":e),r.onerror=()=>{E("error"),$("playback failed")},_.current=r,await r.play(),E("playing")}catch(e){$(e instanceof Error?e.message:String(e)),E("error")}}},[w,t,p,S,A]);(0,i.useEffect)(()=>{if(w&&g)return window.addEventListener("jarela:speak-message",e),()=>window.removeEventListener("jarela:speak-message",e);function e(e){let t=e.detail;t?.messageId===g&&I()}},[w,g,I]);let F=[],L=null;if(!m&&"string"==typeof h)if(!p||/<\/refs>/i.test(h)){let e=function(e){let t,s=/<refs>([\s\S]*?)<\/refs>/i.exec(e);if(!s)return{body:e,refs:[]};let a=s[1],r=[],n=/\[([^\]]+)\]\(([^)]+)\)/g;for(;null!==(t=n.exec(a));){let e=t[2].trim();/^https?:\/\//.test(e)&&r.push({title:t[1].trim(),url:e})}if(0===r.length)for(let e of a.split("\n")){let t=e.trim().match(/^https?:\/\/\S+/);t&&r.push({title:t[0].replace(/^https?:\/\/(www\.)?/,"").slice(0,60),url:t[0]})}return{body:(e.slice(0,s.index)+e.slice(s.index+s[0].length)).trimEnd(),refs:r}}(h);L=e.body,F=e.refs}else L=h;let R="created_at"in e?e.created_at:null,H=R?new Date(R).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}):null;return(0,a.jsxs)("div",{className:`group flex ${m?"flex-row-reverse":"flex-row"} gap-2 mb-1.5 items-end`,children:[(0,a.jsx)("div",{className:"shrink-0 w-7",children:r&&(m?(0,a.jsx)(eN,{profile:s}):(0,a.jsx)(ev,{config:t}))}),(0,a.jsxs)("div",{className:`flex flex-col max-w-[88%] sm:max-w-[75%] min-w-0 ${m?"items-end":"items-start"}`,children:[(H||g)&&(0,a.jsxs)("div",{className:`flex items-center gap-1 mb-0.5 px-1 opacity-0 group-hover:opacity-100 pointer-coarse:opacity-100 transition-opacity ${m?"flex-row-reverse":""}`,children:[H&&(0,a.jsx)("span",{className:"text-[10px] text-fg-faint","aria-hidden":!0,children:H}),g&&(0,a.jsx)("button",{onClick:j,className:"text-fg-faint hover:text-fg p-0.5 rounded",title:"Copy link to this message","aria-label":"Copy link to this message",children:(0,a.jsx)(eo.A,{size:11})}),(0,a.jsx)("button",{onClick:N,className:"text-fg-faint hover:text-fg p-0.5 rounded",title:y?"Copied":"Copy message text","aria-label":"Copy message text",children:y?(0,a.jsx)(n.A,{size:11}):(0,a.jsx)(ei.A,{size:11})}),w&&!p&&S.trim()&&(0,a.jsx)("button",{onClick:()=>void I(),className:`p-0.5 rounded ${"error"===A?"text-rose-500":"text-fg-faint hover:text-fg"}`,title:T??("playing"===A?"Pause":"loading"===A?"Loading…":"Play voice"),"aria-label":"playing"===A?"Pause voice":"Play voice",disabled:"loading"===A,children:"loading"===A?(0,a.jsx)(ec.A,{size:11,className:"animate-spin"}):"playing"===A?(0,a.jsx)(ed.A,{size:11}):(0,a.jsx)(eu.A,{size:11})})]}),(0,a.jsx)("div",{className:`rounded-2xl px-4 py-3 text-sm leading-relaxed max-w-full overflow-hidden ${m?"glass-bubble-accent text-white rounded-br-sm":"glass-bubble text-fg rounded-bl-sm"}`,children:"string"==typeof h?m?(()=>{let e=ew(h);if(e)return(0,a.jsx)(ek,{ctx:e});let t=function(e){if(!e.startsWith("\uD83D\uDCCE Captured from "))return null;let t="",s="",a=e,r=/^📎 Captured from \[([^\]]+)\]\((https?:\/\/[^)]+)\)\s*\n?/.exec(e);if(r)t=r[1],s=r[2],a=e.slice(r[0].length);else{let r=/^📎 Captured from <(https?:\/\/[^>]+)>\s*\n?/.exec(e);if(!r)return null;t=s=r[1],a=e.slice(r[0].length)}let n={title:t,url:s,selector:null,truncated:!1,originalBytes:null,body:""},l=/^Element: `([^`]+)`\s*\n?/.exec(a);l&&(n.selector=l[1],a=a.slice(l[0].length));let i=/^>\s*⚠[^\n]*?\(original was ([\d,]+) bytes\)[^\n]*\n?/.exec(a);return i&&(n.truncated=!0,n.originalBytes=Number(i[1].replace(/,/g,"")),a=a.slice(i[0].length)),n.body=a=a.replace(/^\s*\n/,"").replace(/^---\s*\n?/,"").replace(/^\n+/,""),n}(h);return t?(0,a.jsx)(ep,{ctx:t,accent:!0}):(0,a.jsx)(eh,{accent:!0,children:(0,a.jsx)("p",{className:"whitespace-pre-wrap",children:h})})})():(0,a.jsx)(eh,{accent:!1,children:(0,a.jsx)(eC,{text:L??h,streaming:p,onInAppLink:b})}):(0,a.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(u=(d=m&&h[0]?.type==="text"&&"string"==typeof h[0].text?h[0].text:null)?ew(d):null)?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(ek,{ctx:u}),h.slice(1).map((e,t)=>(0,a.jsx)(eT,{part:e,isUser:m,onInAppLink:b},t+1))]}):h.map((e,t)=>(0,a.jsx)(eT,{part:e,isUser:m,onInAppLink:b},t)),p&&(0,a.jsxs)("span",{className:"inline-flex items-center align-middle ml-1","aria-label":"typing",children:[(0,a.jsx)("span",{className:"jarela-typing-dot"}),(0,a.jsx)("span",{className:"jarela-typing-dot"}),(0,a.jsx)("span",{className:"jarela-typing-dot"})]})]})}),!m&&!p&&c&&"tool_events"in e&&Array.isArray(e.tool_events)&&e.tool_events.length>0&&(0,a.jsx)(V,{events:e.tool_events}),F.length>0&&(0,a.jsx)(eA,{refs:F})]})]})}),eI=["scheduled_task","watcher","bridge","synthetic","tool_use","thinking"],eF="jarela:msg-category-filters",eL="jarela:msg-filters:",eR="jarela:msg-filters:legacy-migrated",eH={scheduled_task:!0,watcher:!0,bridge:!0,synthetic:!0,tool_use:!0,thinking:!0};function eP(e){try{let t=window.localStorage.getItem(eL+e);if(!t)return null;let s=JSON.parse(t);return{...eH,...s}}catch{return null}}function eO(e,t){try{window.localStorage.setItem(eL+e,JSON.stringify(t))}catch{}}function eM({threadId:e,messages:t,notices:s,agentConfig:r,userProfile:n,streamingContent:l,thinkingContent:o,toolEvents:c,hasMore:d,loadingMore:u,onLoadMore:x,queuedMessages:m,onRemoveQueued:p}){let h=(0,i.useRef)(null),{filters:f,toggle:g,reset:b}=function(e){let[t,s]=(0,i.useState)(()=>e?eP(e)??eH:eH),a=(0,i.useRef)(0);return(0,i.useEffect)(()=>{if(!e)return void s(eH);let t=eP(e);t?s(t):s(eH);let r=++a.current,n=!1;return(async()=>{try{let t=window.localStorage.getItem(eR)?null:function(){try{let e=window.localStorage.getItem(eF);if(!e)return null;return JSON.parse(e)}catch{return null}}();if(t){await fetch(`/api/v1/agents/${encodeURIComponent(e)}/display-filters`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({filters:t})}).catch(()=>{});try{window.localStorage.setItem(eR,"1"),window.localStorage.removeItem(eF)}catch{}}let l=await fetch(`/api/v1/agents/${encodeURIComponent(e)}/display-filters`,{method:"GET"});if(!l.ok)return;let i=await l.json();if(n||r!==a.current)return;let o={...eH,...i.filters};s(o),eO(e,o)}catch{}})(),()=>{n=!0}},[e]),{filters:t,toggle:(0,i.useCallback)(t=>{s(s=>{let r={...s,[t]:!s[t]};return e&&(eO(e,r),a.current++,fetch(`/api/v1/agents/${encodeURIComponent(e)}/display-filters`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({filters:{[t]:r[t]}})}).catch(()=>{})),r})},[e]),reset:(0,i.useCallback)(()=>{e?(s(eH),eO(e,eH),a.current++,fetch(`/api/v1/agents/${encodeURIComponent(e)}/display-filters`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({filters:null})}).catch(()=>{})):s(eH)},[e])}}(r?.id??null),j=(0,i.useRef)(null),y=(0,i.useMemo)(()=>t.filter(e=>{let t=e.category;return!t||("scheduled_task"===t?f.scheduled_task:"watcher"===t?f.watcher:"bridge"===t?f.bridge:"synthetic"!==t||f.synthetic)}),[t,f.scheduled_task,f.watcher,f.bridge,f.synthetic]),v=t.length-y.length;(0,i.useEffect)(()=>{if(0===t.length||l||y.length>0||v!==t.length)return;let s=t[t.length-1]?.id??"none",a=`${e??"no-thread"}:${t.length}:${s}`;j.current!==a&&(j.current=a,b())},[e,t,y.length,v,l,b]);let N=(0,i.useMemo)(()=>{let e=new Set;for(let s of t)"scheduled_task"===s.category?e.add("scheduled_task"):"watcher"===s.category?e.add("watcher"):"bridge"===s.category?e.add("bridge"):"synthetic"===s.category&&e.add("synthetic"),s.tool_events&&s.tool_events.length>0&&e.add("tool_use");return o&&e.add("thinking"),c&&c.length>0&&e.add("tool_use"),eI.filter(t=>e.has(t))},[t,o,c]),w=(0,i.useRef)(!0),[k,S]=(0,i.useState)(!1),_=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=h.current;e&&!_.current&&w.current&&(e.scrollTop=e.scrollHeight)}),(0,i.useLayoutEffect)(()=>{let e=h.current,t=_.current;if(!e||!t||u)return;let s=e.scrollHeight-t.scrollHeight;s>0&&(e.scrollTop=t.scrollTop+s,w.current=!1),_.current=null},[t,u]),(0,i.useEffect)(()=>{function e(){let e=window.location.hash;if(!e.startsWith("#msg-"))return;let t=decodeURIComponent(e.slice(5)),s=h.current;s&&requestAnimationFrame(()=>{let e=t.replace(/"/g,'\\"'),a=s.querySelector(`[data-message-id="${e}"]`);a&&(w.current=!1,a.scrollIntoView({behavior:"smooth",block:"center"}),a.classList.add("jarela-deep-link-flash"),setTimeout(()=>a.classList.remove("jarela-deep-link-flash"),1600))})}return e(),window.addEventListener("hashchange",e),()=>window.removeEventListener("hashchange",e)},[t.length]),(0,i.useEffect)(()=>{function e(){let e=h.current;e&&w.current&&requestAnimationFrame(()=>{e.scrollTop=e.scrollHeight})}return window.addEventListener("resize",e),window.addEventListener("orientationchange",e),()=>{window.removeEventListener("resize",e),window.removeEventListener("orientationchange",e)}},[]);let C=(0,i.useRef)(null),[A,E]=(0,i.useState)(0);return(0,i.useEffect)(()=>{let e=C.current;if(!e)return void E(0);let t=new ResizeObserver(e=>{E(e[0]?.contentRect.height??0)});return t.observe(e),()=>t.disconnect()},[N.length]),(0,a.jsxs)("div",{className:"flex-1 flex flex-col min-h-0 relative",children:[N.length>0&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{ref:C,className:"fixed left-0 right-0 z-30",style:{top:"calc(3rem + var(--app-safe-top))"},children:(0,a.jsx)(eU,{chips:N,filters:f,onToggle:g,hiddenCount:v})}),(0,a.jsx)("div",{className:"shrink-0","aria-hidden":!0,style:{height:A}})]}),(0,a.jsxs)("div",{ref:h,onScroll:function(e){let s=e.currentTarget;d&&!u&&x&&s.scrollTop<60&&(_.current={scrollHeight:s.scrollHeight,scrollTop:s.scrollTop},x());let a=s.scrollHeight-s.scrollTop-s.clientHeight<100;w.current=a,S(!a&&t.length>0)},className:"flex-1 overflow-y-auto px-4 py-4",style:{WebkitMaskImage:"linear-gradient(180deg, transparent 0, #000 24px, #000 calc(100% - 24px), transparent 100%)",maskImage:"linear-gradient(180deg, transparent 0, #000 24px, #000 calc(100% - 24px), transparent 100%)"},children:[d&&(0,a.jsx)("div",{className:"text-center py-1.5 text-[11px] text-fg-faint select-none",children:u?"Loading earlier messages…":"Scroll up for earlier messages"}),0===y.length&&!l&&(0,a.jsx)("div",{className:"flex items-center justify-center h-full text-fg-faint text-sm select-none",children:0===t.length?(0,a.jsx)("span",{children:"Send a message to begin"}):(0,a.jsxs)("div",{className:"flex flex-col items-center gap-2 text-center px-4",children:[(0,a.jsxs)("span",{children:[v," message",1===v?" is":"s are"," hidden by filters"]}),(0,a.jsx)("button",{type:"button",onClick:b,className:"text-xs px-2.5 py-1 rounded-md border border-border bg-surface-2 text-fg-muted hover:text-fg hover:bg-surface-3 transition-colors",children:"Show all messages"})]})}),y.map((t,s)=>{let l=0===s||y[s-1].role!==t.role;return(0,a.jsx)("div",{id:`msg-${t.id}`,"data-message-id":t.id,className:l&&s>0?"mt-3":void 0,children:(0,a.jsx)(ez,{message:t,threadId:e??null,agentConfig:r,userProfile:n,showAvatar:l,showToolEvents:f.tool_use})},t.id)}),o&&f.thinking&&(0,a.jsx)(eJ,{text:o}),c&&c.length>0&&f.tool_use&&(0,a.jsx)(V,{events:c}),l&&(0,a.jsx)(ez,{message:{role:"assistant",content:l,streaming:!0},threadId:e??null,agentConfig:r,showAvatar:0===t.length||"assistant"!==t[t.length-1].role}),m&&m.length>0&&(0,a.jsx)("div",{className:"flex flex-col gap-1 mt-2 mb-1",children:m.map(e=>(0,a.jsx)(eq,{item:e,onRemove:p},e.id))}),s?.map(e=>(0,a.jsx)("div",{className:"flex justify-center my-3",children:(0,a.jsx)("span",{className:"text-xs italic text-fg-faint bg-surface-2 px-3 py-1 rounded-full border border-border",children:e.text})},e.id))]}),k&&(0,a.jsx)("button",{onClick:function(){let e=h.current;e&&(w.current=!0,e.scrollTop=e.scrollHeight,S(!1))},style:{top:`calc(${A}px + 0.75rem)`},className:"absolute left-1/2 -translate-x-1/2 p-2 rounded-full bg-accent/40 hover:bg-accent/80 text-white backdrop-blur-sm shadow-md transition-all animate-in fade-in slide-in-from-top-2 duration-200 z-20",title:"Scroll to latest message","aria-label":"Scroll to latest message",children:(0,a.jsx)(J.A,{size:18})})]})}let eD={scheduled_task:"scheduled",watcher:"watcher",bridge:"bridge",synthetic:"captures",tool_use:"tools",thinking:"thinking"};function eU({chips:e,filters:t,onToggle:s,hiddenCount:r}){return(0,a.jsxs)("div",{className:"px-4 py-1.5 flex items-center gap-1.5 flex-wrap bg-surface/80 backdrop-blur border-b border-border/40 text-[11px]",children:[(0,a.jsx)("span",{className:"text-fg-faint mr-0.5 select-none",children:"show:"}),e.map(e=>{let r=t[e],n=r?q.A:G.A;return(0,a.jsxs)("button",{onClick:()=>s(e),className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full border transition-colors ${r?"bg-surface-2 border-border text-fg-muted hover:text-fg":"bg-transparent border-border/40 text-fg-faint hover:text-fg-muted line-through decoration-fg-faint/60"}`,title:r?`Hide ${eD[e]} messages`:`Show ${eD[e]} messages`,"aria-pressed":r,children:[(0,a.jsx)(n,{size:10}),(0,a.jsx)("span",{children:eD[e]})]},e)}),r>0&&(0,a.jsxs)("span",{className:"ml-auto text-fg-faint select-none","aria-live":"polite",children:[r," hidden"]})]})}function eJ({text:e}){let[t,s]=(0,i.useState)(!1),r=e.replace(/\s+/g," ").trim(),n=r.length>60?r.slice(-60):r;return(0,a.jsxs)("div",{className:"my-1.5",children:[(0,a.jsxs)("button",{onClick:()=>s(e=>!e),className:"w-full flex items-center gap-1.5 text-[11px] text-amber-700 dark:text-amber-400/70 hover:text-amber-700 dark:hover:text-amber-300 px-1 py-0.5",children:[(0,a.jsx)(W.A,{size:10,className:`transition-transform shrink-0 ${t?"rotate-90":""}`}),(0,a.jsx)("span",{className:"font-medium",children:"thinking"}),!t&&(0,a.jsx)("span",{className:"truncate text-amber-700 dark:text-amber-300/40 italic font-normal flex-1 text-left",children:n})]}),t&&(0,a.jsx)("pre",{className:"ml-5 mt-1 px-2 py-1.5 text-[11px] text-amber-900 dark:text-amber-100/90 whitespace-pre-wrap break-words font-mono bg-amber-100/60 dark:bg-amber-950/30 rounded border border-amber-300 dark:border-amber-900/30",children:e})]})}function eq({item:e,onRemove:t}){return(0,a.jsxs)("div",{className:"flex flex-row-reverse gap-2 items-end opacity-60 group",children:[(0,a.jsx)("div",{className:"shrink-0 w-7"}),(0,a.jsxs)("div",{className:"max-w-[75%] rounded-2xl rounded-br-sm px-4 py-2.5 text-sm leading-relaxed bg-accent/40 border border-accent/40 border-dashed text-fg relative",children:[(0,a.jsxs)("div",{className:"flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-accent/80 mb-1",children:[(0,a.jsx)(B.A,{size:10}),(0,a.jsx)("span",{children:"queued"}),e.attachmentCount>0&&(0,a.jsxs)("span",{className:"text-fg-muted/70 normal-case tracking-normal",children:["\xb7 ",e.attachmentCount," attachment",1===e.attachmentCount?"":"s"]})]}),(0,a.jsx)("p",{className:"whitespace-pre-wrap break-words",children:e.text}),t&&(0,a.jsx)("button",{onClick:()=>t(e.id),className:"absolute -top-2 -right-2 w-5 h-5 rounded-full bg-surface-3 border border-border text-fg-muted hover:text-rose-700 dark:hover:text-rose-400 hover:border-rose-700 hidden group-hover:flex items-center justify-center",title:"Remove from queue",children:(0,a.jsx)(z.A,{size:11})})]})]})}let eG=["from-violet-500 to-indigo-600","from-blue-500 to-cyan-600","from-emerald-500 to-teal-600","from-orange-500 to-amber-600","from-rose-500 to-pink-600","from-fuchsia-500 to-purple-600"];function eW(e){let t=0;for(let s=0;s<e.length;s++)t=31*t+e.charCodeAt(s)|0;return eG[Math.abs(t)%eG.length]}function eB({threadId:e,agentId:t,sessionLoading:s,sessionError:r,showTools:n,showThinking:l,onMessageSent:o,onSelectAgent:d}){let[u,x]=(0,i.useState)([]),[m,p]=(0,i.useState)([]),[h,f]=(0,i.useState)(""),[g,b]=(0,i.useState)([]),[j,v]=(0,i.useState)(!1),[N,w]=(0,i.useState)(null),[k,S]=(0,i.useState)(null),[_,C]=(0,i.useState)(null),[A,T]=(0,i.useState)([]),$=y(),[z,I]=(0,i.useState)(!1),[L,R]=(0,i.useState)(!1),[H,P]=(0,i.useState)(!1),[O,M]=(0,i.useState)(!0),[D,J]=(0,i.useState)(!1),q=e=>p(t=>[...t,{id:`notice-${Date.now()}`,text:e}]);function G(e,t){if(0===t.length)return e;let s=new Set(e.map(e=>e.id)),a=t.filter(e=>!s.has(e.id));return 0===a.length?e:e.concat(a)}(0,i.useEffect)(()=>{M(!0),c.FH.profile.get().then(S).catch(console.error).finally(()=>M(!1))},[]),(0,i.useEffect)(()=>{if(!t){w(null),J(!1),c.FH.agents.list().then(e=>{let t=e.find(e=>e.is_default)??null,s=e.filter(e=>!e.is_default).sort((e,t)=>t.updated_at.localeCompare(e.updated_at)).slice(0,3);C(t),T(s)}).catch(console.error);return}T([]),J(!0),c.FH.agents.get(t).then(w).catch(console.error).finally(()=>J(!1))},[t]);let[W,B]=(0,i.useState)([]),V=(0,i.useRef)([]);V.current=W;let K=(0,i.useRef)([]);K.current=u;let Y=(0,i.useRef)(()=>{}),Q=(0,i.useRef)(()=>{}),Z=(0,i.useRef)(!1),{streaming:X,streamingContent:ee,thinkingContent:et,toolEvents:es,error:ea,start:er,stop:en,attach:el,clearStreamingContent:ei}=function(e){let[t,s]=(0,i.useState)(!1),[a,r]=(0,i.useState)(""),[n,l]=(0,i.useState)(""),[o,d]=(0,i.useState)([]),[u,x]=(0,i.useState)(null),m=(0,i.useRef)(null),p=(0,i.useRef)(null),h=(0,i.useCallback)(async t=>{for await(let a of t){let t=JSON.parse(a);if("text_delta"===t.type)r(e=>e+t.delta);else if("thinking_delta"===t.type)l(e=>e+t.delta);else if("tool_call"===t.type)d(e=>[...e,{id:t.id,phase:"call",name:t.name,payload:t.arguments}]);else if("tool_result"===t.type)d(e=>[...e,{id:t.id,phase:"result",name:t.name,payload:t.result}]);else if("done"===t.type){s(!1),e?.();break}else if("error"===t.type){s(!1),r(""),l(""),x(t.message);break}}},[e]),f=(0,i.useCallback)(async(e,t,a,n)=>{m.current?.abort();let i=new AbortController;m.current=i,p.current=e,s(!0),r(""),l(""),d([]),x(null);try{let s=await (0,c.AU)(e,t,i.signal,a,n);return await h((0,c._C)(e,i.signal,a)),{accepted:s.accepted}}catch(e){return"AbortError"!==e.name&&x(String(e)),s(!1),r(""),l(""),{accepted:!1}}},[h]),g=(0,i.useCallback)(()=>{let t=p.current;t&&c.FH.threads.abortRun(t).catch(()=>{}),s(!1),m.current?.abort(),e?.()},[e]);return{streaming:t,streamingContent:a,thinkingContent:n,toolEvents:o,error:u,start:f,stop:g,attach:(0,i.useCallback)(async t=>{m.current?.abort();let a=new AbortController;m.current=a,p.current=t,s(!0),r(""),l(""),d([]),x(null);try{await h((0,c._C)(t,a.signal))}catch(t){s(!1),"AbortError"!==t.name&&e?.()}},[h,e]),clearStreamingContent:(0,i.useCallback)(()=>{r("")},[])}}((0,i.useCallback)(()=>{if(!e)return;let t=K.current.filter(e=>!e.id.startsWith("opt-")),s=t.length>0?t[t.length-1].created_at:void 0;(s?c.FH.threads.get(e,{after:s}):c.FH.threads.get(e)).then(e=>{if(s?x(t=>G(t.filter(e=>!e.id.startsWith("opt-")),e.messages)):(x(e.messages),I(e.has_more)),Q.current(),Z.current){Z.current=!1;let t=[...e.messages].reverse().find(e=>"assistant"===e.role&&e.id);t?.id&&requestAnimationFrame(()=>{window.dispatchEvent(new CustomEvent("jarela:speak-message",{detail:{messageId:t.id}}))})}}).catch(console.error).finally(()=>{Y.current()}),o()},[e,o]));Q.current=ei;let eo=(0,i.useRef)(!1);eo.current=X,(0,i.useEffect)(()=>{if(e)return window.addEventListener("jarela:thread-updated",t),()=>window.removeEventListener("jarela:thread-updated",t);function t(t){let s=t.detail;if(!s||s.thread_id!==e||eo.current)return;let a=K.current,r=a.length>0?a[a.length-1].created_at:void 0;(r?c.FH.threads.get(e,{after:r}):c.FH.threads.get(e)).then(e=>{r?0!==e.messages.length&&x(t=>G(t,e.messages)):(x(e.messages),I(e.has_more))}).catch(console.error)}},[e]),E(!!s),E(X),E(j),E(L),E(H),E(D),(0,i.useEffect)(()=>{if(!e){x([]),p([]),I(!1),P(!1);return}let t=!1;return P(!0),x([]),I(!1),c.FH.threads.get(e).then(e=>{t||(x(e.messages),I(e.has_more))}).catch(e=>{t||console.error(e)}).finally(()=>{t||(P(!1),el(e).catch(()=>{}))}),()=>{t=!0}},[e,el]);let ec=(0,i.useCallback)(async()=>{if(e&&!L&&z&&0!==u.length){R(!0);try{let t=u[0].created_at,s=await c.FH.threads.get(e,{before:t,limit:50});x(e=>[...s.messages,...e]),I(s.has_more)}catch(e){console.error(e)}finally{R(!1)}}},[e,L,z,u]);async function ed(){if(t){v(!0);try{let e=await c.FH.agents.compact(t);x([]),p([]),e.compacted?q(`Session saved to memory (${e.message_count} msgs, ~${Math.round((e.context_chars||0)/1e3)}k chars). Starting fresh.`):q("Nothing to compact yet — send some messages first.")}catch(e){q(`Compaction failed: ${String(e)}`)}finally{v(!1),Y.current()}}}async function eu(t,s){if(!e)return;let a=s.length?JSON.stringify([{type:"text",text:t},...s]):t,r=`opt-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;x(e=>[...e,{id:r,role:"user",content:a,created_at:new Date().toISOString()}]);let{accepted:i}=await er(e,t,{filters:{include_tools:n,include_thinking:l}},s.length?s:void 0);i||(x(e=>e.filter(e=>e.id!==r)),B(e=>[{id:`q-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,text:t,attachments:s},...e]))}async function ex(){let s=h.trim();if(s&&t){if("/new"===s.toLowerCase()){f(""),await ed();return}r?p([{id:`notice-${Date.now()}`,text:`Session failed to load: ${r}`}]):(f(""),b([]),X||j||!e||0!==V.current.length)?B(e=>[...e,{id:`q-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,text:s,attachments:g}]):await eu(s,g)}}return Y.current=()=>{X||j||!e||B(e=>{if(0===e.length)return e;let t=e.map(e=>e.text).join("\n\n"),s=e.flatMap(e=>e.attachments);return Promise.resolve().then(()=>{eu(t,s)}),[]})},(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[(0,a.jsx)(eM,{threadId:e,messages:u,notices:m,agentConfig:N,userProfile:k,streamingContent:ee||void 0,thinkingContent:et||void 0,toolEvents:X?es:void 0,hasMore:z,loadingMore:L,onLoadMore:ec,queuedMessages:W.map(e=>({id:e.id,text:e.text,attachmentCount:e.attachments.length})),onRemoveQueued:function(e){B(t=>t.filter(t=>t.id!==e))}}),ea&&(0,a.jsx)("div",{className:"mx-4 mb-2 px-3 py-2 rounded bg-red-900/40 border border-red-700 text-red-700 dark:text-red-300 text-xs max-h-48 overflow-y-auto",children:(0,a.jsx)("pre",{className:"whitespace-pre-wrap break-all font-mono",children:ea})}),!t&&(_||A.length>0)&&(0,a.jsxs)("div",{className:"mx-4 mb-4 flex flex-col items-center gap-3",children:[_&&(0,a.jsxs)("button",{onClick:()=>d?.(_.id),className:"group flex flex-col items-center gap-2 px-5 py-4 rounded-2xl border border-accent/40 bg-gradient-to-br from-accent/10 to-surface-2 hover:from-accent/15 hover:border-accent/60 transition-all w-[260px] shadow-lg shadow-accent/10",children:[(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)("div",{className:`w-14 h-14 rounded-2xl bg-gradient-to-br ${eW(_.id)} flex items-center justify-center text-xl font-bold text-white select-none overflow-hidden ring-2 ring-accent/30 ring-offset-2 ring-offset-surface group-hover:ring-accent/50 transition-all`,children:_.icon?(0,a.jsx)("img",{src:_.icon,alt:_.name,className:"w-full h-full object-cover"}):_.name.charAt(0).toUpperCase()}),($.get(_.id)??0)>0&&(0,a.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[20px] h-[20px] px-1.5 rounded-full bg-rose-500 border-2 border-surface text-[11px] font-bold text-white flex items-center justify-center leading-none",children:($.get(_.id)??0)>9?"9+":$.get(_.id)})]}),(0,a.jsxs)("div",{className:"text-center min-w-0 w-full",children:[(0,a.jsxs)("div",{className:"flex items-center justify-center gap-1.5",children:[(0,a.jsx)("p",{className:"text-base font-semibold text-fg truncate",children:_.name}),(0,a.jsx)("span",{className:"text-[9px] uppercase tracking-wider px-1.5 py-px rounded text-accent bg-accent/15 border border-accent/30",children:"default"})]}),_.identity&&(0,a.jsx)("p",{className:"text-xs text-fg-subtle mt-0.5 line-clamp-2 px-2",children:_.identity})]})]}),A.length>0&&(0,a.jsxs)("div",{className:"flex flex-col items-center gap-1.5",children:[(0,a.jsx)("p",{className:"text-[10px] text-fg-faint uppercase tracking-wider",children:"Recent"}),(0,a.jsx)("div",{className:"flex gap-1.5 justify-center flex-wrap",children:A.map(e=>{let t=$.get(e.id)??0;return(0,a.jsxs)("button",{onClick:()=>d?.(e.id),title:e.identity||e.name,className:"relative flex items-center gap-2 px-2.5 py-1.5 rounded-lg border border-border bg-surface-2 hover:bg-surface-3 hover:border-border transition-colors text-left max-w-[150px]",children:[(0,a.jsx)("div",{className:`w-6 h-6 shrink-0 rounded-md bg-gradient-to-br ${eW(e.id)} flex items-center justify-center text-xs font-bold text-white select-none overflow-hidden`,children:e.icon?(0,a.jsx)("img",{src:e.icon,alt:e.name,className:"w-full h-full object-cover"}):e.name.charAt(0).toUpperCase()}),(0,a.jsx)("p",{className:"text-xs text-fg-muted truncate",children:e.name}),t>0&&(0,a.jsx)("span",{className:"absolute -top-1.5 -right-1.5 min-w-[16px] h-[16px] px-1 rounded-full bg-rose-500 border border-surface text-[10px] font-bold text-white flex items-center justify-center leading-none",children:t>9?"9+":t})]},e.id)})})]})]}),!t&&!_&&0===A.length&&(0,a.jsx)("div",{className:"mx-4 mb-2 px-3 py-2 rounded bg-surface-3 border border-border text-fg-subtle text-xs text-center",children:"No agent selected — open the menu and pick an agent to start chatting."}),(0,a.jsx)(F,{agentId:t}),(0,a.jsx)(U,{value:h,onChange:f,attachments:g,onAttachmentsChange:b,onSubmit:ex,onStop:en,streaming:X,voiceEnabled:!!N?.voice_enabled,agentId:t,onVoiceTranscript:s=>{let a=s.trim();a&&t&&(N?.voice_auto_speak!==!1&&(Z.current=!0),X||j||!e||0!==V.current.length?B(e=>[...e,{id:`q-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,text:a,attachments:[]}]):eu(a,[]))},disabled:!t||!!r,placeholder:j?"Compacting session… your messages will queue":s?"Loading session… your messages will queue":H?"Loading chat history…":D?"Loading agent…":O?"Loading profile…":void 0})]})}var eV=s(2125),eK=s(5377),eY=s(8986),eQ=s(5738);let eZ="jarela-deep-link-flash";function eX(e,t,s){let{state:a}=(0,o.U)(),r=a.selectedItem[e],n=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(!r){n.current=null;return}if(n.current===r)return;let e=s.current??document,t=requestAnimationFrame(()=>{let t=r.replace(/"/g,'\\"'),s=e.querySelector(`[data-deep-link-id="${t}"]`);s&&(n.current=r,s.scrollIntoView({behavior:"smooth",block:"center"}),s.classList.add(eZ),setTimeout(()=>s.classList.remove(eZ),1600))});return()=>cancelAnimationFrame(t)},[r,e])}var e0=s(7920),e1=s(9304).hp;function e2(e){if(null==e)return"(no error provided)";if(e instanceof Error)return e.stack??e.message??e.name??"Error";if("string"==typeof e)return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}let e5=null,e3=null;async function e4(){return e5||e3||(e3=(async()=>{try{let e=await fetch("/api/v1/update",{method:"GET"});if(!e.ok)return"unknown";return e5=(await e.json()).version??"unknown"}catch{return"unknown"}finally{e3=null}})())}function e6(e){let t=e2(e.error);return e4(),f({kind:"error",source:"system",sourceLabel:"Error",title:e.title,body:e.summary??"Click to expand for details",agent_id:null,thread_id:null,ttl:0,details:t,reportInput:e})}async function e7(e){var t;let s,a,r,n=(t=e5??await e4(),{appVersion:t,userAgent:"u">typeof navigator&&"string"==typeof navigator.userAgent?navigator.userAgent:"unknown",url:window.location?window.location.pathname:"/",ts:new Date().toISOString()}),l=(s=e.summary??e.title,a=e2(e.error),r=`**What failed:** ${s}
3
-
4
- **Error:**
5
- \`\`\`
6
- ${a}
7
- \`\`\`
8
-
9
- `+function(e){if(!e)return"";let t=Object.keys(e);if(0===t.length)return"";let s=t.map(t=>{let s,a=e[t];if(null==a)s=String(a);else if("string"==typeof a||"number"==typeof a||"boolean"==typeof a)s=String(a);else try{s=JSON.stringify(a)}catch{s=String(a)}return`- ${t}: ${s}`});return`**Context:**
10
- ${s.join("\n")}
11
-
12
- `}(e.context)+`**Environment:**
13
- `+`- App version: ${n.appVersion}
14
- `+`- User agent: ${n.userAgent}
15
- `+`- URL: ${n.url}
16
- `+`- Timestamp: ${n.ts}
17
-
18
- `+`---
19
- `+`<!-- Anything else about what you were doing when this happened? -->
20
- `,{title:e.title,body:r});return{...l,url:function(e){let t=e.body;if(e1.byteLength(t,"utf8")>7e3){let e="\n\n_(report truncated — paste the full version from your clipboard)_\n",s=7e3-e1.byteLength(e,"utf8"),a=t.slice(0,Math.max(s,0));for(;e1.byteLength(a,"utf8")>s&&a.length>0;)a=a.slice(0,-1);t=a+e}let s=new URLSearchParams({title:e.title,body:t,labels:"user-report"});return`${(0,e0.SN)()}?${s.toString()}`}(l)}}function e9({item:e,onSave:t,onClose:s}){let[r,n]=(0,i.useState)(e?.namespace??""),[l,o]=(0,i.useState)(e?.key??""),[c,d]=(0,i.useState)(e?JSON.stringify(e.value,null,2):""),[u,x]=(0,i.useState)(null),[m,p]=(0,i.useState)(!1),h=!!e;async function f(){let e;x(null);try{e=JSON.parse(c)}catch{x("Value must be valid JSON");return}if(!r.trim()||!l.trim())return void x("Namespace and key are required");p(!0);try{await t(r.trim(),l.trim(),e),s()}catch(e){e6({title:"Couldn't save memory entry",error:e,context:{panel:"memory",action:"memory.save",namespace:r.trim(),key:l.trim()}})}finally{p(!1)}}return(0,i.useEffect)(()=>{let e=e=>{"Escape"===e.key&&s()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[s]),(0,a.jsx)("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4",children:(0,a.jsxs)("div",{className:"bg-surface-2 border border-border rounded-2xl w-full max-w-md shadow-xl",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,a.jsx)("h3",{className:"text-sm font-semibold text-fg",children:h?"Edit memory":"New memory"}),(0,a.jsx)("button",{onClick:s,className:"text-fg-subtle hover:text-fg transition-colors",children:(0,a.jsx)(z.A,{size:16})})]}),(0,a.jsxs)("div",{className:"p-4 space-y-3",children:[["Namespace","Key"].map(e=>(0,a.jsxs)("label",{className:"block",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:e}),(0,a.jsx)("input",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent disabled:opacity-50",value:"Namespace"===e?r:l,onChange:t=>"Namespace"===e?n(t.target.value):o(t.target.value),placeholder:"Namespace"===e?"e.g. user/preferences":"e.g. theme",disabled:h})]},e)),(0,a.jsxs)("label",{className:"block",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"Value (JSON)"}),(0,a.jsx)("textarea",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent font-mono h-28 resize-none",value:c,onChange:e=>d(e.target.value),placeholder:'{"key": "value"}'})]}),u&&(0,a.jsx)("p",{className:"text-red-700 dark:text-red-400 text-xs",children:u})]}),(0,a.jsxs)("div",{className:"flex justify-end gap-2 px-4 pb-4",children:[(0,a.jsx)("button",{onClick:s,className:"px-3 py-1.5 text-sm text-fg-subtle hover:text-fg transition-colors",children:"Cancel"}),(0,a.jsx)("button",{onClick:f,disabled:m,className:"px-4 py-1.5 text-sm bg-accent hover:bg-accent-hover text-white rounded-lg transition-colors disabled:opacity-50",children:m?"Saving…":"Save"})]})]})})}let e8=/(^|_)(token|secret|password|passwd|api_?key|client_secret|refresh_token|access_token|private_?key|auth)($|_)/i,te="********";function tt(e,t){return e.length<=t?e:e.slice(0,t-1)+"…"}function ts(e,t){if(t&&"string"==typeof e&&e8.test(t))return te;if(null===e)return"null";if("string"==typeof e)return tt(e,80);if("number"==typeof e||"boolean"==typeof e)return String(e);if(Array.isArray(e))return 0===e.length?"[]":`${e.length} item${1===e.length?"":"s"}`;if("object"==typeof e){let t=Object.keys(e);return 0===t.length?"{}":`${t.length} field${1===t.length?"":"s"}`}return tt(JSON.stringify(e),80)}function ta({value:e}){let[t,s]=(0,i.useState)(!1);if(null===e)return(0,a.jsx)("p",{className:"text-xs text-fg-subtle italic",children:"null"});if("string"==typeof e)return e.includes("\n")?(0,a.jsx)("pre",{className:"text-xs text-fg-subtle whitespace-pre-wrap font-mono leading-snug max-h-32 overflow-y-auto",children:e}):(0,a.jsx)("p",{className:"text-xs text-fg-subtle truncate",children:e});if("number"==typeof e||"boolean"==typeof e)return(0,a.jsx)("p",{className:"text-xs text-fg-subtle font-mono",children:String(e)});if(Array.isArray(e)){if(0===e.length)return(0,a.jsx)("p",{className:"text-xs text-fg-faint italic",children:"empty list"});let r=e.slice(0,4).map(e=>ts(e));return(0,a.jsx)(tr,{expanded:t,onToggle:()=>s(e=>!e),summary:(0,a.jsxs)("span",{className:"text-xs text-fg-subtle truncate",children:[(0,a.jsxs)("span",{className:"text-fg-faint",children:["[",e.length,"]"]})," ",r.join(", "),e.length>4&&(0,a.jsxs)("span",{className:"text-fg-faint",children:[" \xb7 +",e.length-4," more"]})]}),full:e})}if("object"==typeof e){let r=Object.entries(e);if(0===r.length)return(0,a.jsx)("p",{className:"text-xs text-fg-faint italic",children:"empty object"});let n=r.slice(0,4),l=r.length-n.length;return(0,a.jsx)(tr,{expanded:t,onToggle:()=>s(e=>!e),summary:(0,a.jsxs)("div",{className:"flex flex-wrap gap-x-2 gap-y-0.5 text-xs",children:[n.map(([e,t])=>(0,a.jsxs)("span",{className:"text-fg-subtle truncate max-w-full",children:[(0,a.jsxs)("span",{className:"text-fg-faint",children:[e,":"]})," ",(0,a.jsx)("span",{className:"font-mono",children:ts(t,e)})]},e)),l>0&&(0,a.jsxs)("span",{className:"text-fg-faint",children:["+",l," more"]})]}),full:e})}return(0,a.jsx)("p",{className:"text-xs text-fg-subtle truncate",children:String(e)})}function tr({expanded:e,onToggle:t,summary:s,full:r}){return(0,a.jsxs)("div",{children:[(0,a.jsxs)("button",{type:"button",onClick:t,"aria-expanded":e,className:"w-full text-left flex items-start gap-1 group/expand",title:e?"Collapse":"Show full value",children:[(0,a.jsx)(W.A,{size:11,className:`mt-0.5 shrink-0 text-fg-faint transition-transform ${e?"rotate-90":""}`}),(0,a.jsx)("span",{className:"flex-1 min-w-0",children:s})]}),e&&(0,a.jsx)("pre",{className:"mt-1 ml-3.5 text-[11px] text-fg-subtle whitespace-pre-wrap font-mono leading-snug bg-surface-3/60 border border-border rounded p-2 max-h-64 overflow-y-auto",children:JSON.stringify(r,(e,t)=>"string"==typeof t&&e8.test(e)?te:t,2)})]})}function tn(){let[e,t]=(0,i.useState)(""),[s,r]=(0,i.useState)(""),{items:n,loading:l,create:o,update:d,remove:u,refresh:x}=function(e,t){let[s,a]=(0,i.useState)([]),[r,n]=(0,i.useState)(!1),l=(0,i.useCallback)(async()=>{n(!0);try{a(await c.FH.memory.list(e,t))}finally{n(!1)}},[e,t]);(0,i.useEffect)(()=>{l()},[l]);let o=(0,i.useCallback)(async(e,t,s)=>{let r=await c.FH.memory.create(e,t,s);return a(e=>[r,...e]),r},[]);return{items:s,loading:r,refresh:l,create:o,update:(0,i.useCallback)(async(e,t,s)=>{let r=await c.FH.memory.update(e,t,s);return a(s=>s.map(s=>s.namespace===e&&s.key===t?r:s)),r},[]),remove:(0,i.useCallback)(async(e,t)=>{await c.FH.memory.delete(e,t),a(s=>s.filter(s=>s.namespace!==e||s.key!==t))},[])}}(e||void 0,function(e){let[t,s]=(0,i.useState)(e);return(0,i.useEffect)(()=>{let t=setTimeout(()=>s(e),300);return()=>clearTimeout(t)},[e,300]),t}(s)||void 0),[m,p]=(0,i.useState)(null),h=(0,i.useRef)(null);eX("memory","memory",h);let f=(0,i.useCallback)(async(e,t,s)=>{"new"===m?await o(e,t,s):m&&await d(e,t,s)},[m,o,d]),g=[...new Set(n.map(e=>e.namespace))].sort();return(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[(0,a.jsxs)("div",{className:"border-b border-border px-4 py-3 flex items-center gap-2",children:[(0,a.jsx)("h2",{className:"text-sm font-semibold text-fg mr-auto",children:"Memory Store"}),(0,a.jsxs)("button",{onClick:()=>p("new"),className:"flex items-center gap-1 text-xs text-accent hover:text-accent-hover transition-colors",children:[(0,a.jsx)(eV.A,{size:14})," New"]})]}),(0,a.jsx)("div",{className:"px-4 py-2 space-y-2 border-b border-border",children:(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsxs)("div",{className:"relative flex-1",children:[(0,a.jsx)(eK.A,{size:13,className:"absolute left-2 top-1/2 -translate-y-1/2 text-fg-faint pointer-events-none"}),(0,a.jsx)("input",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 pl-7 border border-border focus:outline-none focus:ring-1 focus:ring-accent",placeholder:"Search…",value:s,onChange:e=>r(e.target.value)})]}),(0,a.jsxs)("select",{className:"bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent",value:e,onChange:e=>t(e.target.value),children:[(0,a.jsx)("option",{value:"",children:"All namespaces"}),g.map(e=>(0,a.jsx)("option",{value:e,children:e},e))]})]})}),(0,a.jsxs)("div",{ref:h,className:"flex-1 overflow-y-auto px-4 py-2",children:[l&&0===n.length&&(0,a.jsx)("p",{className:"text-fg-faint text-sm text-center py-8",children:"Loading…"}),!l&&0===n.length&&(0,a.jsx)("p",{className:"text-fg-faint text-sm text-center py-8",children:"No memory items yet"}),n.map(e=>(0,a.jsxs)("div",{"data-deep-link-id":`${e.namespace}/${e.key}`,className:"flex items-start gap-2 py-2.5 border-b border-border/60 group",children:[(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[(0,a.jsx)("span",{className:"text-[10px] uppercase tracking-wide text-fg-faint",children:e.namespace}),(0,a.jsx)("span",{className:"text-fg-faint",children:"/"}),(0,a.jsx)("span",{className:"text-xs font-medium text-fg truncate",children:e.key})]}),(0,a.jsx)(ta,{value:e.value})]}),(0,a.jsxs)("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 pointer-coarse:opacity-100 transition-opacity shrink-0",children:[(0,a.jsx)("button",{onClick:()=>p(e),className:"p-1 text-fg-subtle hover:text-fg transition-colors",title:"Edit",children:(0,a.jsx)(eY.A,{size:13})}),(0,a.jsx)("button",{onClick:()=>u(e.namespace,e.key),className:"p-1 text-fg-subtle hover:text-red-700 dark:hover:text-red-400 transition-colors",title:"Delete",children:(0,a.jsx)(eQ.A,{size:13})})]})]},`${e.namespace}/${e.key}`))]}),null!==m&&(0,a.jsx)(e9,{item:"new"===m?void 0:m,onSave:f,onClose:()=>{p(null),x()}})]})}var tl=s(2651),ti=s(5697);function to(){let[e,t]=(0,i.useState)([]),[s,a]=(0,i.useState)([]),[r,n]=(0,i.useState)(!1),l=(0,i.useCallback)(async()=>{n(!0);try{let[e,s]=await Promise.all([c.FH.models.list(),c.FH.tasks.list()]);t(e),a(s)}finally{n(!1)}},[]);(0,i.useEffect)(()=>{l()},[l]);let o=(0,i.useCallback)(async(e,s)=>{let a=await c.FH.models.create(e,s);return t(e=>[...e,a]),a},[]),d=(0,i.useCallback)(async(e,s)=>{let a=await c.FH.models.update(e,s);return t(t=>t.map(t=>t.name===e?a:t)),a},[]),u=(0,i.useCallback)(async e=>{await c.FH.models.delete(e),t(t=>t.filter(t=>t.name!==e)),a(t=>t.filter(t=>t.model_config_name!==e))},[]);return{models:e,assignments:s,loading:r,refresh:l,create:o,update:d,remove:u,assign:(0,i.useCallback)(async(e,t,s)=>{let r=await c.FH.tasks.assign(e,t,s);return a(t=>t.find(t=>t.agent_id===e)?t.map(t=>t.agent_id===e?r:t):[...t,r]),r},[]),unassign:(0,i.useCallback)(async e=>{await c.FH.tasks.unassign(e),a(t=>t.filter(t=>t.agent_id!==e))},[])}}var tc=s(557),td=s(6483),tu=s(7990),tx=s(626),tm=s(8777),tp=s(9804);let th={openai:[/^gpt-4o/i,/^gpt-4\.1/i,/^gpt-4-turbo/i,/^gpt-4-vision/i,/^gpt-5/i,/^chatgpt-4o/i,/^o[134](?:-|$)/i],anthropic:[/^claude-3/i,/^claude-sonnet/i,/^claude-opus/i,/^claude-haiku-4/i,/^claude-[45](?:-|$)/i],gemini:[/^gemini-(1\.5|2|3)/i,/^gemini-pro-vision/i],"github-copilot":[/^gpt-4o/i,/^gpt-4\.1/i,/^gpt-5/i,/^o[134](?:-|$)/i,/^claude-3/i,/^claude-sonnet/i,/^claude-opus/i,/^claude-haiku-4/i,/^claude-[45](?:-|$)/i,/^gemini-(1\.5|2|3)/i],deepseek:[],cohere:[],langchain:[],mock:[/.*/]};function tf(e,t){return(th[e.toLowerCase()]??[]).some(e=>e.test(t))}function tg(e){return e.toLowerCase()in th}let tb={openai:[/audio/i,/realtime/i],gemini:[/^gemini-(1\.5|2|3)/i],anthropic:[],"github-copilot":[/audio/i,/realtime/i,/^gemini-(1\.5|2|3)/i],deepseek:[],cohere:[],langchain:[],mock:[/.*/]},tj={openai:[/^gpt-4o/i,/^gpt-4\.1/i,/^gpt-4-turbo/i,/^gpt-5/i,/^o[134](?:-|$)/i,/^chatgpt-4o/i],anthropic:[/^claude-3/i,/^claude-sonnet/i,/^claude-opus/i,/^claude-haiku-4/i,/^claude-[45](?:-|$)/i],gemini:[/^gemini-(1\.5|2|3)/i],"github-copilot":[/^gpt-4o/i,/^gpt-4\.1/i,/^gpt-5/i,/^o[134](?:-|$)/i,/^claude-3/i,/^claude-sonnet/i,/^claude-opus/i,/^claude-haiku-4/i,/^claude-[45](?:-|$)/i,/^gemini-(1\.5|2|3)/i],deepseek:[],cohere:[],langchain:[],mock:[/.*/]},ty={anthropic:[/^claude-3\.5/i,/^claude-3\.7/i,/^claude-sonnet/i,/^claude-opus/i,/^claude-haiku-4/i,/^claude-[45](?:-|$)/i],openai:[],gemini:[],"github-copilot":[],deepseek:[],cohere:[],langchain:[],mock:[]},tv=new Set(["openai","gemini","deepseek","mock"]);function tN(e,t,s){return(e[t.toLowerCase()]??[]).some(e=>e.test(s))}let tw={vision:{icon:q.A,label:"Vision (image input)"},files:{icon:td.A,label:"File / document input"},audio:{icon:P.A,label:"Audio / voice input"},tools:{icon:tu.A,label:"Tool calling"},web_search:{icon:tx.A,label:"Built-in web search"},json_mode:{icon:tm.A,label:"Structured JSON output"},streaming:{icon:tp.A,label:"Streaming responses"}},tk=["vision","files","audio","tools","web_search","json_mode","streaming"];function tS({caps:e,provider:t,modelId:s,size:r="xs"}){let n,l,i=e??(t&&s?(n=t.toLowerCase(),l=/^deepseek-reasoner/i.test(s),{vision:tf(t,s),tools:tg(n)&&!l,streaming:!0,json_mode:tv.has(n),web_search:tN(ty,t,s),audio:tN(tb,t,s),files:tN(tj,t,s)}):null);if(!i)return null;let o=tk.filter(e=>i[e]);if(!o.length)return null;let c="sm"===r?"w-5 h-5":"w-4 h-4",d="sm"===r?"w-3 h-3":"w-2.5 h-2.5";return(0,a.jsx)("span",{className:"inline-flex flex-wrap gap-0.5 align-middle",children:o.map(e=>{let{icon:t,label:s}=tw[e];return(0,a.jsx)("span",{title:s,"aria-label":s,className:`inline-flex items-center justify-center ${c} rounded bg-surface text-fg-subtle border border-border`,children:(0,a.jsx)(t,{className:d,strokeWidth:2,"aria-hidden":!0})},e)})})}let t_=["anthropic","openai","github-copilot","deepseek","gemini","langchain"],tC=new Set(["openai","github-copilot","anthropic","gemini","deepseek"]);function tA({model:e,onSave:t,onClose:s}){let r=!!e,[n,l]=(0,i.useState)(e?.name??""),[o,d]=(0,i.useState)(e?.provider??"anthropic"),[u,x]=(0,i.useState)(t_),[m,p]=(0,i.useState)(e?.model_id??""),[h,f]=(0,i.useState)(e?.params.api_key??""),[g,b]=(0,i.useState)(e?.params.base_url??""),[j,y]=(0,i.useState)(e?.params.extra_headers?JSON.stringify(e.params.extra_headers,null,2):""),[v,N]=(0,i.useState)(String(e?.params.temperature??"")),[w,k]=(0,i.useState)(String(e?.params.max_tokens??"")),[S,_]=(0,i.useState)(e?.is_default??!1),[C,A]=(0,i.useState)(null),[E,T]=(0,i.useState)(!1),[$,I]=(0,i.useState)(!1),[F,L]=(0,i.useState)(null),[R,H]=(0,i.useState)(!1),[P,O]=(0,i.useState)(null),[M,D]=(0,i.useState)("");async function U(){if(tC.has(o)){H(!0),O(null);try{let e=await c.FH.models.catalog(o);L(e),I(!0)}catch(e){O(String(e)),e6({title:"Couldn't load model catalog",error:e,context:{panel:"models",action:"catalog.load",provider:o}})}finally{H(!1)}}}async function J(){let e;if(A(null),!n.trim()||!m.trim())return void A("Name and model ID are required");if(j.trim())try{e=JSON.parse(j)}catch{A("Extra headers must be valid JSON");return}T(!0);try{let a={};h&&(a.api_key=h),g&&(a.base_url=g),e&&(a.extra_headers=e),v&&(a.temperature=Number(v)),w&&(a.max_tokens=Number(w)),await t(n.trim(),{provider:o,model_id:m.trim(),params:a,is_default:S}),s()}catch(e){e6({title:"Couldn't save model",error:e,context:{panel:"models",action:"model.save",name:n.trim(),provider:o,model_id:m.trim()}})}finally{T(!1)}}(0,i.useEffect)(()=>{let e=e=>{"Escape"===e.key&&s()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[s]),(0,i.useEffect)(()=>{let e=!0;return c.FH.models.providers().then(t=>{e&&Array.isArray(t)&&0!==t.length&&x(t)}).catch(()=>{}),()=>{e=!1}},[]),(0,i.useEffect)(()=>{L(null),O(null),I(!1)},[o]);let q="github-copilot"===o,G=F?.filter(e=>!M||e.id.toLowerCase().includes(M.toLowerCase()))??[];return(0,a.jsx)("div",{className:"fixed inset-0 bg-black/60 flex items-start justify-center z-50 p-2 sm:p-4 overflow-y-auto",children:(0,a.jsxs)("div",{className:"bg-surface-2 border border-border rounded-2xl w-full max-w-lg shadow-xl my-2 sm:my-4",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,a.jsx)("h3",{className:"text-sm font-semibold text-fg",children:r?"Edit model config":"New model config"}),(0,a.jsx)("button",{onClick:s,className:"text-fg-subtle hover:text-fg transition-colors",children:(0,a.jsx)(z.A,{size:16})})]}),(0,a.jsxs)("div",{className:"p-4 space-y-3",children:[(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,a.jsxs)("label",{className:"block",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"Config name"}),(0,a.jsx)("input",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent disabled:opacity-50",value:n,onChange:e=>l(e.target.value),placeholder:"e.g. work-claude",disabled:r})]}),(0,a.jsxs)("label",{className:"block",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"Provider"}),(0,a.jsx)("select",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent",value:o,onChange:e=>d(e.target.value),children:u.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]})]}),(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle",children:"Model ID"}),tC.has(o)&&(0,a.jsxs)("button",{onClick:()=>$?I(!1):U(),disabled:R,className:"flex items-center gap-1 text-[11px] text-accent hover:text-accent/80 transition-colors disabled:opacity-50",children:[(0,a.jsx)(tc.A,{size:11}),R?"Loading…":$?"Hide catalog":"Browse catalog"]})]}),(0,a.jsx)("input",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent",value:m,onChange:e=>p(e.target.value),placeholder:"e.g. claude-sonnet-4-6"}),P&&(0,a.jsx)("p",{className:"text-red-700 dark:text-red-400 text-xs",children:P}),$&&F&&(0,a.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden bg-surface-3",children:[(0,a.jsx)("div",{className:"px-2 py-1.5 border-b border-border",children:(0,a.jsx)("input",{className:"w-full bg-surface text-fg text-xs rounded px-2 py-1 border border-border focus:outline-none focus:ring-1 focus:ring-accent placeholder-fg-faint",placeholder:"Filter models…",value:M,onChange:e=>D(e.target.value)})}),(0,a.jsxs)("div",{className:"max-h-52 overflow-y-auto divide-y divide-border",children:[0===G.length&&(0,a.jsx)("p",{className:"text-xs text-fg-faint text-center py-3",children:"No models match"}),G.map(e=>{var t;return(0,a.jsxs)("button",{onClick:()=>{p(e.id),I(!1)},className:`w-full text-left px-3 py-2 hover:bg-surface-2 transition-colors ${e.id===m?"bg-accent/10 border-l-2 border-accent":""}`,children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 mb-0.5",children:[(0,a.jsx)("span",{className:"text-xs font-mono text-fg truncate",children:e.id}),e.context_length&&(0,a.jsxs)("span",{className:"text-[10px] text-fg-faint shrink-0",children:[(t=e.context_length)?t>=1e6?`${t/1e6}M`:t>=1e3?`${Math.round(t/1e3)}k`:String(t):null," ctx"]}),e.hosted_on&&(0,a.jsx)("span",{className:"text-[10px] text-fg-faint shrink-0 truncate",children:e.hosted_on})]}),(0,a.jsx)(tS,{caps:e.capabilities})]},e.id)})]})]})]}),q&&(0,a.jsx)(tE,{}),(0,a.jsxs)("label",{className:"block",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"API Key"}),(0,a.jsx)("input",{type:"password",className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent",value:h,onChange:e=>f(e.target.value),placeholder:"••••••••"})]}),(0,a.jsxs)("label",{className:"block",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"Base URL (optional override)"}),(0,a.jsx)("input",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent",value:g,onChange:e=>b(e.target.value),placeholder:"https://custom-endpoint"})]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,a.jsxs)("label",{className:"block",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"Temperature"}),(0,a.jsx)("input",{type:"number",min:"0",max:"2",step:"0.1",className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent",value:v,onChange:e=>N(e.target.value),placeholder:"0.7"})]}),(0,a.jsxs)("label",{className:"block",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"Max tokens"}),(0,a.jsx)("input",{type:"number",className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent",value:w,onChange:e=>k(e.target.value),placeholder:"4096"})]})]}),(0,a.jsxs)("label",{className:"block",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"Extra headers (JSON, optional)"}),(0,a.jsx)("textarea",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent font-mono h-20 resize-none",value:j,onChange:e=>y(e.target.value),placeholder:'{"X-Custom": "value"}'})]}),(0,a.jsxs)("label",{className:"flex items-center gap-2 cursor-pointer",children:[(0,a.jsx)("input",{type:"checkbox",className:"rounded border-border",checked:S,onChange:e=>_(e.target.checked)}),(0,a.jsx)("span",{className:"text-xs text-fg-muted",children:"Set as default model"})]}),C&&(0,a.jsx)("p",{className:"text-red-700 dark:text-red-400 text-xs",children:C})]}),(0,a.jsxs)("div",{className:"flex justify-end gap-2 px-4 pb-4",children:[(0,a.jsx)("button",{onClick:s,className:"px-3 py-1.5 text-sm text-fg-subtle hover:text-fg transition-colors",children:"Cancel"}),(0,a.jsx)("button",{onClick:J,disabled:E,className:"px-4 py-1.5 text-sm bg-accent hover:bg-accent-hover text-white rounded-lg transition-colors disabled:opacity-50",children:E?"Saving…":"Save"})]})]})})}function tE(){let[e,t]=(0,i.useState)(null),[s,r]=(0,i.useState)(null),[n,l]=(0,i.useState)(!1),[o,d]=(0,i.useState)(null),[u,x]=(0,i.useState)(null);async function m(){x(null),d(null);try{let e=await c.FH.githubCopilotAuth.start();r({user_code:e.user_code,verification_uri:e.verification_uri,device_code:e.device_code,interval:e.interval||5}),l(!0),p(e.device_code,e.interval||5,e.expires_in||900)}catch(e){x(e instanceof Error?e.message:String(e))}}async function p(e,s,a){let n=Date.now()+1e3*a,i=s;for(;Date.now()<n;){await new Promise(e=>setTimeout(e,1e3*i));try{let s=await c.FH.githubCopilotAuth.poll(e);if("success"===s.status){d("Signed in to GitHub Copilot."),r(null),l(!1);let e=await c.FH.githubCopilotAuth.status();t(e);return}if("slow_down"===s.status){i+=5;continue}if("pending"===s.status)continue;x(`Sign-in failed: ${s.status}${s.error?` (${s.error})`:""}`),r(null),l(!1);return}catch(e){x(e instanceof Error?e.message:String(e)),l(!1);return}}x("Sign-in timed out. Try again."),r(null),l(!1)}async function h(){x(null),d(null);try{await c.FH.githubCopilotAuth.signOut();let e=await c.FH.githubCopilotAuth.status();t(e),d("Signed out.")}catch(e){x(e instanceof Error?e.message:String(e))}}async function f(e){try{await navigator.clipboard.writeText(e)}catch{}}return(0,i.useEffect)(()=>{c.FH.githubCopilotAuth.status().then(t).catch(()=>t({signed_in:!1,stored_at:null}))},[]),(0,a.jsxs)("div",{className:"p-2.5 rounded-lg bg-surface-3 border border-border text-xs space-y-2",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,a.jsxs)("div",{className:"text-fg-muted",children:[(0,a.jsx)("strong",{children:"GitHub Copilot sign-in"}),(0,a.jsx)("p",{className:"text-fg-faint mt-0.5",children:"Unlocks full model context windows (vs. the 8k cap on raw PATs via GitHub Models)."})]}),e?.signed_in?(0,a.jsx)("button",{onClick:h,className:"px-2 py-1 text-[11px] bg-surface text-fg-muted hover:text-red-700 dark:hover:text-red-300 rounded border border-border whitespace-nowrap",children:"Sign out"}):(0,a.jsx)("button",{onClick:m,disabled:n,className:"px-2 py-1 text-[11px] bg-accent hover:bg-accent-hover text-white rounded whitespace-nowrap disabled:opacity-50",children:n?"Waiting…":"Sign in"})]}),e?.signed_in&&!s&&(0,a.jsxs)("p",{className:"text-emerald-700 dark:text-emerald-400",children:["Connected",e.stored_at?` \xb7 ${new Date(e.stored_at).toLocaleString()}`:""]}),s&&(0,a.jsxs)("div",{className:"rounded bg-surface p-2 border border-border space-y-1.5",children:[(0,a.jsxs)("p",{className:"text-fg-subtle",children:["1. Open"," ",(0,a.jsx)("a",{href:s.verification_uri,target:"_blank",rel:"noreferrer",className:"text-accent underline",children:s.verification_uri})]}),(0,a.jsx)("p",{className:"text-fg-subtle",children:"2. Enter this code:"}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("code",{className:"px-2 py-1 bg-surface-2 rounded font-mono text-fg text-sm tracking-wider",children:s.user_code}),(0,a.jsx)("button",{onClick:()=>f(s.user_code),className:"text-[10px] text-fg-subtle hover:text-fg",children:"Copy"})]})]}),o&&(0,a.jsx)("p",{className:"text-emerald-700 dark:text-emerald-400",children:o}),u&&(0,a.jsx)("p",{className:"text-red-700 dark:text-red-400",children:u})]})}let tT={anthropic:"bg-orange-900/40 text-orange-700 dark:text-orange-300 border-orange-700",openai:"bg-green-900/40 text-green-700 dark:text-green-300 border-green-700","github-copilot":"bg-purple-900/40 text-purple-300 border-purple-700"};function t$(){let{models:e,assignments:t,loading:s,create:r,update:n,remove:l,refresh:o}=to(),[c,d]=(0,i.useState)(null),[u,x]=(0,i.useState)(null),m=(0,i.useRef)(null);async function p(e,t){"new"===c?await r(e,t):c&&await n(e,t),o()}async function h(e){await n(e.name,{provider:e.provider,model_id:e.model_id,params:e.params,is_default:!0})}async function f(e){x(null);try{await l(e)}catch(t){x(`Could not delete "${e}": ${t instanceof Error?t.message:String(t)}`)}}return eX("models","model",m),(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[(0,a.jsxs)("div",{className:"border-b border-border px-4 py-3 flex items-center gap-2",children:[(0,a.jsx)(tl.A,{size:14,className:"text-fg-subtle"}),(0,a.jsx)("h2",{className:"text-sm font-semibold text-fg mr-auto",children:"Model Configs"}),(0,a.jsxs)("button",{onClick:()=>d("new"),className:"flex items-center gap-1 text-xs text-accent hover:text-accent-hover transition-colors",children:[(0,a.jsx)(eV.A,{size:14})," New"]})]}),(0,a.jsx)("div",{ref:m,className:"flex-1 overflow-y-auto",children:(0,a.jsxs)("div",{className:"px-4 py-2",children:[s&&0===e.length&&(0,a.jsx)("p",{className:"text-fg-faint text-sm py-6 text-center",children:"Loading…"}),!s&&0===e.length&&(0,a.jsx)("p",{className:"text-fg-faint text-sm py-6 text-center",children:"No model configs yet"}),u&&(0,a.jsx)("p",{className:"text-red-700 dark:text-red-400 text-xs mb-2 px-1",children:u}),e.map(e=>{let s=t.some(t=>t.model_config_name===e.name);return(0,a.jsxs)("div",{"data-deep-link-id":e.name,className:"flex items-center gap-3 py-2.5 border-b border-border/60 group",children:[(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 mb-0.5",children:[(0,a.jsx)("span",{className:"text-sm font-medium text-fg",children:e.name}),e.is_default&&(0,a.jsx)(ti.A,{size:11,className:"text-yellow-700 dark:text-yellow-400 fill-yellow-400 shrink-0"}),(0,a.jsx)("span",{className:`text-xs px-1.5 py-0.5 rounded border ${tT[e.provider]??"bg-surface-2 text-fg-muted border-border"}`,children:e.provider})]}),(0,a.jsx)("p",{className:"text-xs text-fg-subtle truncate",children:e.model_id}),(0,a.jsx)("div",{className:"mt-1",children:(0,a.jsx)(tS,{provider:e.provider,modelId:e.model_id})})]}),(0,a.jsxs)("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 pointer-coarse:opacity-100 transition-opacity shrink-0",children:[!e.is_default&&(0,a.jsx)("button",{onClick:()=>h(e),className:"p-1 text-fg-subtle hover:text-yellow-700 dark:hover:text-yellow-400 transition-colors",title:"Set as default",children:(0,a.jsx)(ti.A,{size:13})}),(0,a.jsx)("button",{onClick:()=>d(e),className:"p-1 text-fg-subtle hover:text-fg transition-colors",title:"Edit",children:(0,a.jsx)(eY.A,{size:13})}),(0,a.jsx)("button",{onClick:()=>f(e.name),disabled:s,className:"p-1 text-fg-subtle hover:text-red-700 dark:hover:text-red-400 transition-colors disabled:opacity-30 disabled:cursor-not-allowed",title:s?"Unassign from agents first":"Delete",children:(0,a.jsx)(eQ.A,{size:13})})]})]},e.name)})]})}),null!==c&&(0,a.jsx)(tA,{model:"new"===c?void 0:c,onSave:p,onClose:()=>{d(null),o()}})]})}var tz=s(7708),tI=s(2749),tF=s(5660),tL=s(5484),tR=s(8426),tH=s(5425),tP=s(8158),tO=s(4225);function tM({initialPath:e,onSelect:t,onClose:s}){let[r,l]=(0,i.useState)(e??""),[o,d]=(0,i.useState)(null),[u,x]=(0,i.useState)(""),[m,p]=(0,i.useState)([]),[h,f]=(0,i.useState)(!0),[g,b]=(0,i.useState)(null),[j,y]=(0,i.useState)(e??""),v=(0,i.useCallback)(async e=>{f(!0),b(null);try{let t=await c.FH.fs.browse(e);l(t.path),d(t.parent),x(t.home),p(t.entries),y(t.path)}catch(e){b(e instanceof Error?e.message:String(e))}finally{f(!1)}},[]);return(0,i.useEffect)(()=>{v(e)},[e,v]),(0,i.useEffect)(()=>{let e=e=>{"Escape"===e.key&&s()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[s]),(0,a.jsx)("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4",children:(0,a.jsxs)("div",{className:"bg-surface-2 border border-border rounded-2xl w-full max-w-lg shadow-xl flex flex-col",style:{maxHeight:"80vh"},children:[(0,a.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,a.jsxs)("h3",{className:"text-sm font-semibold text-fg flex items-center gap-2",children:[(0,a.jsx)(tF.A,{size:14})," Pick a folder"]}),(0,a.jsx)("button",{onClick:s,className:"text-fg-subtle hover:text-fg transition-colors",children:(0,a.jsx)(z.A,{size:16})})]}),(0,a.jsx)("div",{className:"px-4 py-3 border-b border-border space-y-2",children:(0,a.jsxs)("form",{onSubmit:function(e){e.preventDefault(),j.trim()&&v(j.trim())},className:"flex items-center gap-1.5",children:[(0,a.jsx)("button",{type:"button",onClick:()=>void v(u),title:"Go to home",className:"p-1.5 rounded-md text-fg-subtle hover:text-fg hover:bg-surface-3",children:(0,a.jsx)(tH.A,{size:14})}),(0,a.jsx)("button",{type:"button",onClick:()=>o&&void v(o),disabled:!o,title:"Go up",className:"p-1.5 rounded-md text-fg-subtle hover:text-fg hover:bg-surface-3 disabled:opacity-30 disabled:hover:bg-transparent",children:(0,a.jsx)(tP.A,{size:14})}),(0,a.jsx)("input",{type:"text",value:j,onChange:e=>y(e.target.value),className:"flex-1 min-w-0 px-2 py-1 rounded-md bg-surface-3 border border-border text-xs text-fg font-mono focus:outline-none focus:ring-1 focus:ring-accent"})]})}),(0,a.jsxs)("div",{className:"flex-1 overflow-y-auto px-2 py-1.5",children:[h&&(0,a.jsx)("p",{className:"text-fg-faint text-sm py-6 text-center",children:"Loading…"}),!h&&g&&(0,a.jsx)("p",{className:"text-red-600 dark:text-red-400 text-xs px-2 py-3",children:g}),!h&&!g&&0===m.length&&(0,a.jsx)("p",{className:"text-fg-faint text-xs italic px-2 py-3",children:"No subfolders here."}),!h&&!g&&m.map(e=>(0,a.jsxs)("button",{type:"button",onDoubleClick:()=>void v(e.path),onClick:()=>void v(e.path),className:"flex items-center gap-2 w-full px-2 py-1.5 rounded-md text-left text-xs text-fg hover:bg-surface-3",title:e.path,children:[(0,a.jsx)(tO.A,{size:13,className:"text-accent shrink-0"}),(0,a.jsx)("span",{className:"truncate",children:e.name})]},e.path))]}),(0,a.jsxs)("div",{className:"flex justify-between items-center gap-2 px-4 py-3 border-t border-border",children:[(0,a.jsx)("span",{className:"text-[11px] text-fg-faint font-mono truncate flex-1",title:r,children:r}),(0,a.jsx)("button",{onClick:s,className:"px-3 py-1.5 text-sm text-fg-subtle hover:text-fg transition-colors",children:"Cancel"}),(0,a.jsxs)("button",{onClick:()=>t(r),disabled:!r||h,className:"flex items-center gap-1.5 px-4 py-1.5 text-sm bg-accent hover:bg-accent-hover text-white rounded-lg transition-colors disabled:opacity-50",children:[(0,a.jsx)(n.A,{size:13})," Use this folder"]})]})]})})}let tD=[{value:"local_folder",label:"Local folder"},{value:"jira_project",label:"Jira project"},{value:"jira_jql",label:"Jira JQL"},{value:"confluence_space",label:"Confluence space"},{value:"confluence_cql",label:"Confluence CQL"},{value:"github_pulls",label:"GitHub pull requests"},{value:"github_repo",label:"GitHub repo files"},{value:"gmail_mail",label:"Gmail mail"},{value:"outlook_mail",label:"Outlook mail"}];function tU(e){return"github_pulls"===e||"github_repo"===e}function tJ(e){return"gmail_mail"===e||"outlook_mail"===e}function tq(e){let t=e.config??{};switch(e.kind){case"jira_project":return`Jira project: ${String(t.project_key??"?")}`;case"jira_jql":return`Jira JQL: ${String(t.jql??"?")}`;case"confluence_space":return`Confluence space: ${String(t.space_key??"?")}`;case"confluence_cql":return`Confluence CQL: ${String(t.cql??"?")}`;case"github_pulls":{let e=`${String(t.owner??"?")}/${String(t.repo??"?")}`;return`GitHub PRs: ${e}`}case"github_repo":{let e=`${String(t.owner??"?")}/${String(t.repo??"?")}`,s=t.ref?`@${String(t.ref)}`:"",a=t.path_prefix?` /${String(t.path_prefix).replace(/^\/+|\/+$/g,"")}`:"";return`GitHub repo: ${e}${s}${a}`}case"gmail_mail":return`Gmail: ${String(t.query??"?")}`;case"outlook_mail":return`Outlook: ${String(t.query??"?")}`;default:return e.path}}function tG(){let[e,t]=(0,i.useState)([]),[s,r]=(0,i.useState)(!0),[n,l]=(0,i.useState)(null),[o,d]=(0,i.useState)([]),[u,x]=(0,i.useState)("__auto__"),[m,p]=(0,i.useState)(!1),[h,f]=(0,i.useState)(null),[g,b]=(0,i.useState)("local_folder"),[j,y]=(0,i.useState)(""),[v,N]=(0,i.useState)(""),[w,k]=(0,i.useState)(""),[S,_]=(0,i.useState)(""),[C,A]=(0,i.useState)(""),[E,T]=(0,i.useState)(""),[$,z]=(0,i.useState)(""),[I,F]=(0,i.useState)(""),[L,R]=(0,i.useState)(""),[H,P]=(0,i.useState)(""),[O,M]=(0,i.useState)(""),[D,U]=(0,i.useState)(""),[J,q]=(0,i.useState)(""),[G,W]=(0,i.useState)("all"),[B,V]=(0,i.useState)(!1),[K,Y]=(0,i.useState)(!1),[Q,Z]=(0,i.useState)({}),[X,ee]=(0,i.useState)(""),[et,es]=(0,i.useState)([]),[ea,er]=(0,i.useState)(!1),en=(0,i.useRef)(null);async function el(){r(!0),l(null);try{let[e,s,a]=await Promise.all([c.FH.documents.listSources(),c.FH.models.list(),c.FH.documents.getSettings()]);t(e),d(s),x(a.embedding_model_config??"__auto__"),f(a.embedding_probe??null)}catch(e){l(e instanceof Error?e.message:String(e))}finally{r(!1)}}async function ei(e){x(e),p(!0),f(null);try{let t=await c.FH.documents.setSettings({embedding_model_config:"__auto__"===e?null:e});x(t.embedding_model_config??"__auto__"),f(t.embedding_probe??null)}catch(e){l(e instanceof Error?e.message:String(e))}finally{p(!1)}}function eo(){let e=v.trim();if("local_folder"===g){let t=j.trim();return t?{path:t,label:e||null}:null}let t={};if("jira_project"===g){let e=w.trim();if(!e)return null;t.project_key=e}else if("confluence_space"===g){let e=S.trim();if(!e)return null;t.space_key=e}else if("jira_jql"===g){let e=C.trim();if(!e)return null;t.jql=e}else if("confluence_cql"===g){let e=C.trim();if(!e)return null;t.cql=e}else if("github_pulls"===g){let e=H.trim(),s=O.trim();if(!e||!s)return null;t.owner=e,t.repo=s,t.state=G}else if("github_repo"===g){let e=H.trim(),s=O.trim();if(!e||!s)return null;t.owner=e,t.repo=s;let a=D.trim();a&&(t.ref=a);let r=J.trim().replace(/^\/+|\/+$/g,"");r&&(t.path_prefix=r)}else if(tJ(g)){let e=E.trim();if(!e)return null;t.query=e;let s=parseInt($,10);Number.isFinite(s)&&s>0&&(t.max_results=s);let a=parseInt(I,10);Number.isFinite(a)&&a>0&&(t.page_size=a)}let s=parseInt(L,10);return(Number.isFinite(s)&&s>0&&(t.recency_days=s),e)?{kind:g,label:e,config:t}:null}function ec(){y(""),N(""),k(""),_(""),A(""),T(""),z(""),F(""),R(""),P(""),M(""),U(""),q(""),W("all")}async function ed(){let e=eo();if(e){V(!0),l(null);try{await c.FH.documents.createSource(e),ec(),await el()}catch(e){l(e instanceof Error?e.message:String(e))}finally{V(!1)}}}async function eu(e){Z(t=>({...t,[e]:!0}));try{let t=await c.FH.documents.reindex(e);(t.stats.embed_failed??0)>0&&l(`Embedding degraded: ${t.stats.embed_failed} chunk${1===t.stats.embed_failed?"":"s"} failed to embed`+(t.stats.embed_error?` (${t.stats.embed_error})`:"")),await el()}catch(e){l(e instanceof Error?e.message:String(e))}finally{Z(t=>({...t,[e]:!1}))}}async function ex(e,t,s){let a="local_folder"===s?"Files on disk are untouched.":tJ(s)?"The upstream mailbox is untouched.":"The upstream content is untouched.";if(confirm(`Stop indexing ${t}? This deletes all chunks for this source. ${a}`))try{await c.FH.documents.deleteSource(e),await el()}catch(e){l(e instanceof Error?e.message:String(e))}}async function em(e){try{await c.FH.documents.updateSource(e.id,{enabled:!e.enabled}),await el()}catch(e){l(e instanceof Error?e.message:String(e))}}async function ep(){let e=X.trim();if(!e)return void es([]);er(!0);try{let t=await c.FH.documents.search(e,{limit:8});es(t.hits)}catch(e){l(e instanceof Error?e.message:String(e))}finally{er(!1)}}return(0,i.useEffect)(()=>{el()},[]),(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[(0,a.jsxs)("div",{className:"border-b border-border px-4 py-3 flex items-center gap-2",children:[(0,a.jsx)(tz.A,{size:14,className:"text-fg-subtle"}),(0,a.jsx)("h2",{className:"text-sm font-semibold text-fg mr-auto",children:"Documents"}),(0,a.jsxs)("button",{onClick:()=>void el(),className:"flex items-center gap-1 text-xs text-accent hover:text-accent-hover transition-colors",title:"Refresh source list",children:[(0,a.jsx)(tI.A,{size:13})," Refresh"]})]}),(0,a.jsxs)("div",{ref:en,className:"flex-1 overflow-y-auto px-4 py-3 space-y-5",children:[(0,a.jsxs)("p",{className:"text-xs text-fg-faint leading-relaxed",children:["Sources listed here are indexed in the background. Text files in folders are chunked, embedded, and made available to agents via the ",(0,a.jsx)("code",{className:"font-mono text-fg-muted",children:"documents_search"})," tool. Remote sources reuse credentials configured in ",(0,a.jsx)("em",{children:"Connections"}),": Jira/Confluence under"," ",(0,a.jsx)("em",{children:"Atlassian"}),", GitHub PRs/repos under ",(0,a.jsx)("em",{children:"GitHub"}),", and mail under ",(0,a.jsx)("em",{children:"Gmail"}),"/",(0,a.jsx)("em",{children:"Outlook"}),". Embedding uses your default model provider; without one, search falls back to substring match."]}),(0,a.jsxs)("section",{className:"space-y-2",children:[(0,a.jsx)("label",{className:"text-xs font-semibold text-fg-muted uppercase tracking-wide",children:"Embedding model"}),(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center",children:[(0,a.jsxs)("select",{value:u,onChange:e=>{ei(e.target.value)},disabled:m,className:"px-2 py-1.5 rounded-md bg-surface-2 border border-border text-xs text-fg disabled:opacity-60",children:[(0,a.jsx)("option",{value:"__auto__",children:"Auto (best available)"}),o.map(e=>(0,a.jsxs)("option",{value:e.name,children:[e.name," (",e.provider,")"]},e.name))]}),(0,a.jsx)("span",{className:"text-[11px] text-fg-faint",children:"Used for document chunk embeddings. Rescan applies this to all eligible chunks."})]}),m&&(0,a.jsx)("p",{className:"text-[11px] text-fg-faint",children:"Testing embedding model..."}),!m&&h&&(0,a.jsx)("p",{className:`text-[11px] ${h.ok?"text-emerald-500":"text-red-400"}`,children:h.ok?`Usable: ${h.provider}/${h.model_id}`+(h.dimension?` (${h.dimension} dims)`:""):`Not usable: ${h.error??"embedding probe failed"}`})]}),(0,a.jsxs)("section",{className:"space-y-2",children:[(0,a.jsx)("label",{className:"text-xs font-semibold text-fg-muted uppercase tracking-wide",children:"Add a source"}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("select",{value:g,onChange:e=>{b(e.target.value),ec()},className:"px-2 py-1.5 rounded-md bg-surface-2 border border-border text-xs text-fg",children:tD.map(e=>(0,a.jsx)("option",{value:e.value,children:e.label},e.value))}),(0,a.jsx)("span",{className:"text-[11px] text-fg-faint",children:"local_folder"===g?"Pick a folder on this machine.":tJ(g)?"gmail_mail"===g?"Requires Gmail credentials (Connections → Gmail).":"Requires Outlook credentials (Connections → Outlook).":tU(g)?"Requires GitHub credentials (Connections → GitHub).":"Requires Atlassian credentials (Connections → Atlassian)."})]}),"local_folder"===g&&(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row",children:[(0,a.jsxs)("div",{className:"flex flex-1 min-w-0 gap-1",children:[(0,a.jsx)("input",{type:"text",value:j,onChange:e=>y(e.target.value),placeholder:"Pick or paste an absolute path",className:"flex-1 min-w-0 px-2.5 py-1.5 rounded-md bg-surface-2 border border-border text-sm text-fg font-mono"}),(0,a.jsxs)("button",{type:"button",onClick:()=>Y(!0),title:"Browse for a folder",className:"flex items-center gap-1 px-2 py-1.5 rounded-md bg-surface-3 border border-border text-xs text-fg hover:bg-surface-2 transition-colors",children:[(0,a.jsx)(tF.A,{size:13})," Browse"]})]}),(0,a.jsx)("input",{type:"text",value:v,onChange:e=>N(e.target.value),placeholder:"Label (optional)",className:"sm:w-40 px-2.5 py-1.5 rounded-md bg-surface-2 border border-border text-sm text-fg"}),(0,a.jsxs)("button",{onClick:()=>void ed(),disabled:B||!eo(),className:"flex items-center justify-center gap-1.5 px-3 py-1.5 rounded-md bg-accent text-white text-xs font-medium disabled:opacity-50 hover:bg-accent-hover transition-colors",children:[(0,a.jsx)(eV.A,{size:13})," Add"]})]}),"local_folder"!==g&&(0,a.jsxs)("div",{className:"space-y-2",children:["jira_project"===g&&(0,a.jsx)("input",{type:"text",value:w,onChange:e=>k(e.target.value),placeholder:'Project key (e.g. "ACME")',className:"w-full px-2.5 py-1.5 rounded-md bg-surface-2 border border-border text-sm text-fg font-mono"}),"confluence_space"===g&&(0,a.jsx)("input",{type:"text",value:S,onChange:e=>_(e.target.value),placeholder:'Space key (e.g. "ENG")',className:"w-full px-2.5 py-1.5 rounded-md bg-surface-2 border border-border text-sm text-fg font-mono"}),("jira_jql"===g||"confluence_cql"===g)&&(0,a.jsx)("textarea",{value:C,onChange:e=>A(e.target.value),placeholder:"jira_jql"===g?"JQL — e.g. assignee = currentUser() AND resolution = Unresolved":"CQL — e.g. label = onboarding",rows:2,className:"w-full px-2.5 py-1.5 rounded-md bg-surface-2 border border-border text-sm text-fg font-mono resize-y"}),tJ(g)&&(0,a.jsx)("textarea",{value:E,onChange:e=>T(e.target.value),placeholder:"gmail_mail"===g?"Gmail query — e.g. is:unread newer_than:7d":"KQL — e.g. isRead:false received>=2026-05-01",rows:2,className:"w-full px-2.5 py-1.5 rounded-md bg-surface-2 border border-border text-sm text-fg font-mono resize-y"}),tU(g)&&(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row",children:[(0,a.jsx)("input",{type:"text",value:H,onChange:e=>P(e.target.value),placeholder:'Owner (e.g. "octocat")',className:"flex-1 min-w-0 px-2.5 py-1.5 rounded-md bg-surface-2 border border-border text-sm text-fg font-mono"}),(0,a.jsx)("input",{type:"text",value:O,onChange:e=>M(e.target.value),placeholder:'Repo (e.g. "hello-world")',className:"flex-1 min-w-0 px-2.5 py-1.5 rounded-md bg-surface-2 border border-border text-sm text-fg font-mono"})]}),"github_pulls"===g&&(0,a.jsxs)("select",{value:G,onChange:e=>W(e.target.value),className:"w-full sm:w-44 px-2 py-1.5 rounded-md bg-surface-2 border border-border text-sm text-fg",title:"Which PRs to index",children:[(0,a.jsx)("option",{value:"all",children:"All PRs"}),(0,a.jsx)("option",{value:"open",children:"Open PRs only"}),(0,a.jsx)("option",{value:"closed",children:"Closed PRs only"})]}),"github_repo"===g&&(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row",children:[(0,a.jsx)("input",{type:"text",value:D,onChange:e=>U(e.target.value),placeholder:"Ref (optional, default branch)",className:"flex-1 min-w-0 px-2.5 py-1.5 rounded-md bg-surface-2 border border-border text-sm text-fg font-mono"}),(0,a.jsx)("input",{type:"text",value:J,onChange:e=>q(e.target.value),placeholder:"Path prefix (optional, e.g. docs)",className:"flex-1 min-w-0 px-2.5 py-1.5 rounded-md bg-surface-2 border border-border text-sm text-fg font-mono"})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row",children:[(0,a.jsx)("input",{type:"text",value:v,onChange:e=>N(e.target.value),placeholder:"Label (required)",className:"flex-1 min-w-0 px-2.5 py-1.5 rounded-md bg-surface-2 border border-border text-sm text-fg"}),tJ(g)?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("input",{type:"number",min:1,value:$,onChange:e=>z(e.target.value),placeholder:"Max results (optional)",className:"sm:w-44 px-2.5 py-1.5 rounded-md bg-surface-2 border border-border text-sm text-fg"}),(0,a.jsx)("input",{type:"number",min:1,value:I,onChange:e=>F(e.target.value),placeholder:"Page size (optional)",className:"sm:w-40 px-2.5 py-1.5 rounded-md bg-surface-2 border border-border text-sm text-fg"})]}):(0,a.jsx)("input",{type:"number",min:1,value:L,onChange:e=>R(e.target.value),placeholder:"Recency days (optional)",className:"sm:w-44 px-2.5 py-1.5 rounded-md bg-surface-2 border border-border text-sm text-fg"}),(0,a.jsxs)("button",{onClick:()=>void ed(),disabled:B||!eo(),className:"flex items-center justify-center gap-1.5 px-3 py-1.5 rounded-md bg-accent text-white text-xs font-medium disabled:opacity-50 hover:bg-accent-hover transition-colors",children:[(0,a.jsx)(eV.A,{size:13})," Add"]})]})]})]}),K&&(0,a.jsx)(tM,{initialPath:j.trim()||void 0,onClose:()=>Y(!1),onSelect:e=>{y(e),Y(!1)}}),n&&(0,a.jsxs)("div",{className:"flex items-start gap-2 text-xs text-red-600 dark:text-red-400 px-2 py-1.5 rounded-md bg-red-500/10 border border-red-500/20",children:[(0,a.jsx)(tL.A,{size:13,className:"mt-0.5 shrink-0"}),(0,a.jsx)("span",{className:"break-words",children:n})]}),(0,a.jsxs)("section",{className:"space-y-2",children:[(0,a.jsx)("label",{className:"text-xs font-semibold text-fg-muted uppercase tracking-wide",children:"Indexed sources"}),s&&0===e.length&&(0,a.jsx)("p",{className:"text-fg-faint text-sm py-3 text-center",children:"Loading…"}),!s&&0===e.length&&(0,a.jsx)("p",{className:"text-fg-faint text-xs italic",children:"No sources yet. Add one above to start indexing."}),e.map(e=>(0,a.jsxs)("div",{className:"rounded-lg border border-border bg-surface-2 px-3 py-2.5 space-y-1.5",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:["local_folder"===e.kind?(0,a.jsx)(tF.A,{size:13,className:"text-fg-subtle shrink-0"}):(0,a.jsx)(tR.A,{size:13,className:"text-fg-subtle shrink-0"}),(0,a.jsxs)("span",{className:"font-mono text-xs text-fg break-all flex-1",children:[e.label?(0,a.jsx)("strong",{children:e.label}):null,e.label?(0,a.jsx)("span",{className:"text-fg-faint",children:" — "}):null,"local_folder"===e.kind?e.path:tq(e)]}),(0,a.jsxs)("label",{className:"text-[11px] text-fg-faint flex items-center gap-1 select-none",children:[(0,a.jsx)("input",{type:"checkbox",checked:e.enabled,onChange:()=>void em(e)}),"enabled"]}),(0,a.jsx)("button",{onClick:()=>void eu(e.id),disabled:Q[e.id],title:"Re-scan now",className:"p-1 text-fg-subtle hover:text-fg disabled:opacity-40",children:(0,a.jsx)(tI.A,{size:13,className:Q[e.id]?"animate-spin":""})}),(0,a.jsx)("button",{onClick:()=>void ex(e.id,"local_folder"===e.kind?e.path:tq(e),e.kind),title:"Remove source",className:"p-1 text-fg-faint hover:text-red-600 dark:hover:text-red-400",children:(0,a.jsx)(eQ.A,{size:13})})]}),(0,a.jsxs)("div",{className:"text-[11px] text-fg-faint flex flex-wrap gap-x-3 gap-y-0.5",children:[(0,a.jsxs)("span",{children:[e.stats.document_count," files"]}),(0,a.jsxs)("span",{children:[e.stats.chunk_count," chunks"]}),(0,a.jsxs)("span",{children:[e.stats.embedded_chunk_count," embedded"]}),e.last_scan_at&&(0,a.jsxs)("span",{children:["last scan: ",new Date(e.last_scan_at).toLocaleString()]})]}),!e.last_error&&e.stats.chunk_count>0&&0===e.stats.embedded_chunk_count&&(0,a.jsx)("div",{className:"text-[11px] text-amber-700 dark:text-amber-400 break-words",children:"Warning: this source has chunks but zero embeddings. Semantic recall is degraded; check default model/provider embedding support."}),e.last_error&&(0,a.jsxs)("div",{className:"text-[11px] text-red-600 dark:text-red-400 break-words",children:["Last error: ",e.last_error]})]},e.id))]}),(0,a.jsxs)("section",{className:"space-y-2",children:[(0,a.jsx)("label",{className:"text-xs font-semibold text-fg-muted uppercase tracking-wide",children:"Try a search"}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)("input",{type:"text",value:X,onChange:e=>ee(e.target.value),onKeyDown:e=>{"Enter"===e.key&&ep()},placeholder:"Ask something the docs would know…",className:"flex-1 min-w-0 px-2.5 py-1.5 rounded-md bg-surface-2 border border-border text-sm text-fg"}),(0,a.jsxs)("button",{onClick:()=>void ep(),disabled:ea||!X.trim(),className:"flex items-center justify-center gap-1.5 px-3 py-1.5 rounded-md bg-accent text-white text-xs font-medium disabled:opacity-50 hover:bg-accent-hover transition-colors",children:[(0,a.jsx)(eK.A,{size:13})," Search"]})]}),et.length>0&&(0,a.jsx)("div",{className:"space-y-2",children:et.map(e=>(0,a.jsxs)("div",{className:"rounded-md border border-border bg-surface px-3 py-2 text-xs",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,a.jsxs)("span",{className:"font-mono text-fg-muted truncate flex-1",children:[e.source_label?`${e.source_label} / `:"",e.rel_path]}),(0,a.jsxs)("span",{className:"text-[10px] uppercase tracking-wide text-fg-faint shrink-0",children:[e.match," \xb7 ",e.score.toFixed(2)]})]}),(0,a.jsx)("pre",{className:"whitespace-pre-wrap text-fg-muted text-[11px] leading-relaxed font-sans line-clamp-6",children:e.text})]},`${e.document_id}-${e.chunk_index}`))}),!ea&&X.trim()&&0===et.length&&(0,a.jsx)("p",{className:"text-fg-faint text-xs italic",children:"No hits — try different terms or add more folders above."})]})]})]})}var tW=s(8562);let tB={INTJ:{label:"Architect",strength:55,empathy:35,expressiveness:30,verbosity:45},INTP:{label:"Logician",strength:50,empathy:35,expressiveness:30,verbosity:55},ENTJ:{label:"Commander",strength:65,empathy:30,expressiveness:45,verbosity:40},ENTP:{label:"Debater",strength:60,empathy:40,expressiveness:60,verbosity:50},INFJ:{label:"Advocate",strength:55,empathy:75,expressiveness:50,verbosity:55},INFP:{label:"Mediator",strength:50,empathy:80,expressiveness:55,verbosity:60},ENFJ:{label:"Protagonist",strength:65,empathy:80,expressiveness:70,verbosity:55},ENFP:{label:"Campaigner",strength:60,empathy:75,expressiveness:75,verbosity:60},ISTJ:{label:"Logistician",strength:50,empathy:30,expressiveness:25,verbosity:40},ISFJ:{label:"Defender",strength:50,empathy:70,expressiveness:40,verbosity:50},ESTJ:{label:"Executive",strength:60,empathy:35,expressiveness:45,verbosity:40},ESFJ:{label:"Consul",strength:60,empathy:80,expressiveness:65,verbosity:50},ISTP:{label:"Virtuoso",strength:50,empathy:30,expressiveness:30,verbosity:35},ISFP:{label:"Adventurer",strength:50,empathy:65,expressiveness:55,verbosity:45},ESTP:{label:"Entrepreneur",strength:60,empathy:40,expressiveness:70,verbosity:40},ESFP:{label:"Entertainer",strength:60,empathy:70,expressiveness:80,verbosity:50}},tV=Object.keys(tB),tK=[{id:"Zephyr",label:"Zephyr \xb7 bright"},{id:"Puck",label:"Puck \xb7 upbeat"},{id:"Charon",label:"Charon \xb7 informative"},{id:"Kore",label:"Kore \xb7 firm"},{id:"Fenrir",label:"Fenrir \xb7 excitable"},{id:"Leda",label:"Leda \xb7 youthful"},{id:"Orus",label:"Orus \xb7 firm"},{id:"Aoede",label:"Aoede \xb7 breezy"},{id:"Callirrhoe",label:"Callirrhoe \xb7 easy-going"},{id:"Autonoe",label:"Autonoe \xb7 bright"},{id:"Enceladus",label:"Enceladus \xb7 breathy"},{id:"Iapetus",label:"Iapetus \xb7 clear"},{id:"Umbriel",label:"Umbriel \xb7 easy-going"},{id:"Algieba",label:"Algieba \xb7 smooth"},{id:"Despina",label:"Despina \xb7 smooth"},{id:"Erinome",label:"Erinome \xb7 clear"},{id:"Algenib",label:"Algenib \xb7 gravelly"},{id:"Rasalgethi",label:"Rasalgethi \xb7 informative"},{id:"Laomedeia",label:"Laomedeia \xb7 upbeat"},{id:"Achernar",label:"Achernar \xb7 soft"},{id:"Alnilam",label:"Alnilam \xb7 firm"},{id:"Schedar",label:"Schedar \xb7 even"},{id:"Gacrux",label:"Gacrux \xb7 mature"},{id:"Pulcherrima",label:"Pulcherrima \xb7 forward"},{id:"Achird",label:"Achird \xb7 friendly"},{id:"Zubenelgenubi",label:"Zubenelgenubi \xb7 casual"},{id:"Vindemiatrix",label:"Vindemiatrix \xb7 gentle"},{id:"Sadachbia",label:"Sadachbia \xb7 lively"},{id:"Sadaltager",label:"Sadaltager \xb7 knowledgeable"},{id:"Sulafat",label:"Sulafat \xb7 warm"}],tY=[{id:"gemini-2.5-flash-preview-tts",label:"Flash TTS (fast, cheap)"},{id:"gemini-2.5-pro-preview-tts",label:"Pro TTS (higher quality)"}],tQ=[{id:"gemini-2.5-flash",label:"Flash (fast, multilingual)"},{id:"gemini-2.5-pro",label:"Pro (slower, more accurate)"}];function tZ({step:e,title:t,children:s}){return(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"w-5 h-5 rounded-full bg-accent text-white text-[10px] font-bold flex items-center justify-center shrink-0",children:e}),(0,a.jsx)("span",{className:"text-xs font-semibold text-fg-muted uppercase tracking-wide",children:t})]}),(0,a.jsx)("div",{className:"ml-7 space-y-2",children:s})]})}function tX({agent:e,models:t,onSave:s,onClose:r}){let n,l=!!e,{tools:o}=function(){let[e,t]=(0,i.useState)([]),[s,a]=(0,i.useState)(!0),[r,n]=(0,i.useState)(null);return(0,i.useEffect)(()=>{c.FH.tools.list().then(t).catch(e=>n(String(e))).finally(()=>a(!1))},[]),{tools:e,loading:s,error:r}}(),d=(0,i.useRef)(null),[u,x]=(0,i.useState)(e?.name??""),[m,p]=(0,i.useState)(e?.icon??null),[h,f]=(0,i.useState)(e?.model_config_name??""),[g,b]=(0,i.useState)(e?.identity??""),[j,y]=(0,i.useState)(e?.instructions??""),[v,N]=(0,i.useState)(e?.tools??[]),[w,k]=(0,i.useState)(e?.is_default??!1),[S,_]=(0,i.useState)(e?.adaptive_persona_enabled??!1),[C,A]=(0,i.useState)((e?.adaptive_mbti??"INTJ")in tB?e?.adaptive_mbti??"INTJ":"INTJ"),[E,T]=(0,i.useState)(e?.voice_enabled??!1),[$,I]=(0,i.useState)(e?.voice_model??"gemini-2.5-flash-preview-tts"),[F,L]=(0,i.useState)(e?.voice_name??"Kore"),[R,H]=(0,i.useState)(e?.voice_stt_model??"gemini-2.5-flash"),[P,O]=(0,i.useState)(e?.voice_auto_speak??!0),[M,D]=(0,i.useState)(e?.harness_id??""),[U,J]=(0,i.useState)([]),[q,G]=(0,i.useState)("builtin:default"),[W,B]=(0,i.useState)(!1),[V,K]=(0,i.useState)(null);function Y(e){N(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}(0,i.useEffect)(()=>{let e=!1;return c.FH.harnesses.list().then(t=>{e||(J(t.harnesses),G(t.default_harness_id))}).catch(()=>{}),()=>{e=!0}},[]),(0,i.useEffect)(()=>{let e=e=>{"Escape"===e.key&&r()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[r]);let Q=(0,i.useMemo)(()=>{let e=new Map,t=new Map;for(let s of o){let a=s.category??"Other",r=e.get(a)??[];r.push(s),e.set(a,r),t.has(a)||t.set(a,s.group??null)}let s=["Memory","Documents","Files","Shell","Web","Images","Voice","Schedule","Atlassian","GitHub","Mail","Calendar","Config","Other","MCP"],a=e=>{let t=s.indexOf(e);return -1===t?999:t},r=new Map,n=new Map;for(let[s,l]of e){let e=t.get(s)??null,i=r.get(e)??[];i.push([s,l]),r.set(e,i);let o=n.get(e),c=a(s);(void 0===o||c<o)&&n.set(e,c)}for(let e of r.values())e.sort((e,t)=>a(e[0])-a(t[0]));for(let e of r.values())for(let t of e)t[1].sort((e,t)=>{let s=(t.stats?.score??0)-(e.stats?.score??0);return 0!==s?s:e.name.localeCompare(t.name)});return[...r.entries()].sort((e,t)=>(n.get(e[0])??999)-(n.get(t[0])??999)).map(([e,t])=>({group:e,categories:t}))},[o]),Z=(0,i.useMemo)(()=>Q.flatMap(e=>e.categories),[Q]);function X(e,t){let s=Z.find(([t])=>t===e)?.[1].map(e=>e.name)??[];0!==s.length&&N(e=>{if(t){let t=new Set(e);for(let e of s)t.add(e);return[...t]}let a=new Set(s);return e.filter(e=>!a.has(e))})}function ee(e,t){let s=(Q.find(t=>t.group===e)?.categories??[]).flatMap(([,e])=>e.map(e=>e.name));0!==s.length&&N(e=>{if(t){let t=new Set(e);for(let e of s)t.add(e);return[...t]}let a=new Set(s);return e.filter(e=>!a.has(e))})}async function et(){if(K(null),!u.trim())return void K("Name is required");B(!0);try{await s({name:u.trim(),icon:m??null,identity:g.trim(),instructions:j.trim(),tools:v,model_config_name:h||null,is_default:w,adaptive_persona_enabled:S,adaptive_mbti:C,voice_enabled:E,voice_model:$,voice_name:F,voice_stt_model:R,voice_auto_speak:P,harness_id:M||null}),r()}catch(e){e6({title:"Couldn't save agent",error:e,context:{panel:"agents",action:"agent.save",agent_name:u.trim()}})}finally{B(!1)}}let es=t.find(e=>e.name===h),ea=t.find(e=>e.is_default),er=tB[C];return(0,a.jsx)("div",{className:"fixed inset-0 bg-black/60 flex items-start justify-center z-50 p-2 sm:p-4 overflow-y-auto",children:(0,a.jsxs)("div",{className:"bg-surface-2 border border-border rounded-2xl w-full max-w-lg shadow-xl my-2 sm:my-4",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,a.jsx)("h3",{className:"text-sm font-semibold text-fg",children:l?"Edit agent":"New agent"}),(0,a.jsx)("button",{onClick:r,className:"text-fg-subtle hover:text-fg transition-colors",children:(0,a.jsx)(z.A,{size:16})})]}),(0,a.jsxs)("div",{className:"p-4 space-y-5",children:[(0,a.jsxs)(tZ,{step:1,title:"Identity",children:[(0,a.jsxs)("div",{className:"flex items-end gap-3",children:[(0,a.jsxs)("div",{className:"shrink-0",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"Icon"}),(0,a.jsx)("button",{onClick:()=>d.current?.click(),className:"w-12 h-12 rounded-lg border-2 border-dashed border-border bg-surface-3 flex items-center justify-center hover:border-accent transition-colors overflow-hidden group",title:"Upload image",children:m?(0,a.jsx)("img",{src:m,alt:"icon",className:"w-full h-full object-cover"}):(0,a.jsx)(tW.A,{size:14,className:"text-fg-faint group-hover:text-accent transition-colors"})}),(0,a.jsx)("input",{ref:d,type:"file",accept:"image/*",className:"hidden",onChange:function(e){let t=e.target.files?.[0];if(!t)return;let s=new FileReader;s.onload=()=>p(s.result),s.readAsDataURL(t)}}),m&&(0,a.jsx)("button",{onClick:()=>p(null),className:"text-[10px] text-fg-faint hover:text-red-700 dark:hover:text-red-400 mt-0.5 block",children:"Remove"})]}),(0,a.jsxs)("label",{className:"flex-1 block",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"Name"}),(0,a.jsx)("input",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent",value:u,onChange:e=>x(e.target.value),placeholder:"e.g. Code Reviewer",autoFocus:!0})]})]}),(0,a.jsxs)("label",{className:"block",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"Persona"}),(0,a.jsx)("textarea",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent h-16 resize-none",value:g,onChange:e=>b(e.target.value),placeholder:"You are a senior TypeScript engineer with deep expertise in React and Next.js…"})]}),(0,a.jsxs)("label",{className:"block",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"Instructions"}),(0,a.jsx)("textarea",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent h-16 resize-none",value:j,onChange:e=>y(e.target.value),placeholder:"Focus on code review, suggest best practices, and explain your reasoning…"})]})]}),(0,a.jsx)("hr",{className:"border-border"}),(0,a.jsxs)(tZ,{step:2,title:"Model",children:[(0,a.jsxs)("select",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent",value:h,onChange:e=>f(e.target.value),children:[(0,a.jsx)("option",{value:"",children:ea?`Default (${ea.name} \xb7 ${ea.model_id})${tf(ea.provider,ea.model_id)?" \uD83D\uDCF7":""}`:"(no default configured)"}),t.map(e=>{let t=tf(e.provider,e.model_id);return(0,a.jsxs)("option",{value:e.name,children:[t?"\uD83D\uDCF7 ":"",e.name," \xb7 ",e.provider," / ",e.model_id]},e.name)})]}),es&&(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsxs)("p",{className:"text-[11px] text-fg-faint",children:["Using ",(0,a.jsx)("span",{className:"text-fg-subtle",children:es.provider})," / ",(0,a.jsx)("span",{className:"font-mono text-fg-muted",children:es.model_id}),!tf(es.provider,es.model_id)&&(tg(es.provider)?(0,a.jsx)("span",{className:"ml-1 text-amber-700 dark:text-amber-300",children:"\xb7 no image input"}):(0,a.jsx)("span",{className:"ml-1 text-fg-faint",children:"\xb7 capabilities unknown"}))]}),(0,a.jsx)(tS,{provider:es.provider,modelId:es.model_id})]}),0===t.length&&(0,a.jsx)("p",{className:"text-[11px] text-amber-700 dark:text-amber-400",children:"No model configs yet — go to the Models panel to add one first."})]}),(0,a.jsx)("hr",{className:"border-border"}),(0,a.jsx)(tZ,{step:3,title:"Tools",children:0===o.length?(0,a.jsx)("p",{className:"text-xs text-fg-faint",children:"No tools available."}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("span",{className:"text-[11px] text-fg-faint",children:[v.length," of ",o.length," enabled"]}),(0,a.jsx)("button",{onClick:function(){N(e=>e.length===o.length?[]:o.map(e=>e.name))},className:"text-[11px] text-fg-faint hover:text-fg-muted transition-colors",children:v.length===o.length?"Deselect all":"Select all"})]}),(0,a.jsx)("div",{className:"space-y-1.5",children:Q.map(({group:e,categories:t})=>e?(0,a.jsx)(t0,{group:e,categories:t,selected:v,onToggleTool:Y,onToggleCategory:X,onToggleGroup:ee},e):t.map(([e,t])=>(0,a.jsx)(t1,{category:e,tools:t,selected:v,onToggleTool:Y,onToggleCategory:X},e)))})]})}),(0,a.jsx)("hr",{className:"border-border"}),(0,a.jsxs)(tZ,{step:4,title:"Advanced settings",children:[(0,a.jsxs)("label",{className:"block",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"Harness"}),(0,a.jsxs)("select",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent",value:M,onChange:e=>D(e.target.value),children:[(0,a.jsxs)("option",{value:"",children:["Use global default",(n=U.find(e=>e.id===q))?` (${n.name})`:""]}),U.map(e=>(0,a.jsxs)("option",{value:e.id,children:[e.name,e.builtin?" (built-in)":""]},e.id))]})]}),(0,a.jsx)("p",{className:"text-[11px] text-fg-faint",children:"Behavioral scaffolding (output formatting, citation rules, anti-fabrication, self-config) injected into this agent's system prompt."}),(0,a.jsx)("hr",{className:"border-border/60 my-2"}),(0,a.jsxs)("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[(0,a.jsx)("input",{type:"checkbox",className:"rounded border-border",checked:S,onChange:e=>_(e.target.checked)}),(0,a.jsx)("span",{className:"text-xs text-fg-subtle",children:"Enable adaptive personality and emotion mirroring"})]}),(0,a.jsxs)("label",{className:"block",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"MBTI preset"}),(0,a.jsx)("select",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent",value:C,onChange:e=>A(e.target.value),disabled:!S,children:tV.map(e=>(0,a.jsxs)("option",{value:e,children:[e," - ",tB[e].label]},e))})]}),(0,a.jsxs)("p",{className:"text-[11px] text-fg-faint",children:["Hidden preset values: strength ",er.strength,", empathy ",er.empathy,", expressiveness ",er.expressiveness,", verbosity ",er.verbosity,"."]}),(0,a.jsx)("hr",{className:"border-border/60 my-2"}),(0,a.jsxs)("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[(0,a.jsx)("input",{type:"checkbox",className:"rounded border-border",checked:E,onChange:e=>T(e.target.checked)}),(0,a.jsx)("span",{className:"text-xs text-fg-subtle",children:"Enable voice (Gemini TTS + STT)"})]}),(0,a.jsx)("p",{className:"text-[11px] text-fg-faint",children:"When on, the chat input shows a microphone and assistant replies show a play button. Requires the Google integration api_key."}),(0,a.jsxs)("label",{className:"block",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"TTS model"}),(0,a.jsx)("select",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent",value:$,onChange:e=>I(e.target.value),disabled:!E,children:tY.map(e=>(0,a.jsxs)("option",{value:e.id,children:[e.id," — ",e.label]},e.id))})]}),(0,a.jsxs)("label",{className:"block",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"Voice"}),(0,a.jsx)("select",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent",value:F,onChange:e=>L(e.target.value),disabled:!E,children:tK.map(e=>(0,a.jsx)("option",{value:e.id,children:e.label},e.id))})]}),(0,a.jsxs)("label",{className:"block",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"Transcription model"}),(0,a.jsx)("select",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent",value:R,onChange:e=>H(e.target.value),disabled:!E,children:tQ.map(e=>(0,a.jsxs)("option",{value:e.id,children:[e.id," — ",e.label]},e.id))})]}),(0,a.jsxs)("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[(0,a.jsx)("input",{type:"checkbox",className:"rounded border-border",checked:P,onChange:e=>O(e.target.checked),disabled:!E}),(0,a.jsx)("span",{className:"text-xs text-fg-subtle",children:"Auto-speak reply when I send a voice message"})]})]}),V&&(0,a.jsx)("p",{className:"text-red-700 dark:text-red-400 text-xs",children:V})]}),(0,a.jsxs)("div",{className:"flex items-center justify-between px-4 pb-4",children:[(0,a.jsx)("div",{className:"flex flex-col gap-1.5",children:(0,a.jsxs)("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[(0,a.jsx)("input",{type:"checkbox",className:"rounded border-border",checked:w,onChange:e=>k(e.target.checked)}),(0,a.jsx)("span",{className:"text-xs text-fg-subtle",children:"Set as default agent"})]})}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)("button",{onClick:r,className:"px-3 py-1.5 text-sm text-fg-subtle hover:text-fg transition-colors",children:"Cancel"}),(0,a.jsx)("button",{onClick:et,disabled:W,className:"px-4 py-1.5 text-sm bg-accent hover:bg-accent-hover text-white rounded-lg transition-colors disabled:opacity-50",children:W?"Saving…":"Save"})]})]})]})})}function t0({group:e,categories:t,selected:s,onToggleTool:r,onToggleCategory:n,onToggleGroup:l}){let o=t.flatMap(([,e])=>e),c=o.filter(e=>s.includes(e.name)).length,d=c===o.length,u=c>0&&!d,[x,m]=(0,i.useState)(c>0),p=(0,i.useRef)(null);return(0,i.useEffect)(()=>{p.current&&(p.current.indeterminate=u)},[u]),(0,a.jsx)(t2,{label:e,open:x,setOpen:m,selectedCount:c,totalCount:o.length,allOn:d,onToggleAll:t=>l(e,t),headerRef:p,bodyClassName:"space-y-1.5 px-2 pb-2 pt-0.5 border-t border-border/60",children:t.map(([e,t])=>(0,a.jsx)(t1,{category:e,tools:t,selected:s,onToggleTool:r,onToggleCategory:n},e))})}function t1({category:e,tools:t,selected:s,onToggleTool:r,onToggleCategory:n}){let l=t.filter(e=>s.includes(e.name)).length,o=l===t.length,c=l>0&&!o,[d,u]=(0,i.useState)(l>0),x=(0,i.useRef)(null);return(0,i.useEffect)(()=>{x.current&&(x.current.indeterminate=c)},[c]),(0,a.jsx)(t2,{label:e,open:d,setOpen:u,selectedCount:l,totalCount:t.length,allOn:o,onToggleAll:t=>n(e,t),headerRef:x,bodyClassName:"grid grid-cols-2 gap-1.5 px-3 pb-2 pt-0.5 border-t border-border/60",children:t.map(e=>{var t;return(0,a.jsxs)("label",{className:"flex items-center gap-1.5 cursor-pointer",title:e.description,children:[(0,a.jsx)("input",{type:"checkbox",className:"rounded border-border",checked:s.includes(e.name),onChange:()=>r(e.name)}),(0,a.jsxs)("span",{className:"min-w-0 flex-1 flex items-center gap-1.5",children:[(0,a.jsx)("span",{className:"font-mono text-[11px] text-fg-muted truncate",children:e.name}),(0,a.jsxs)("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] border ${(t=e.stats?.score??1)>=.75?"border-emerald-500/30 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300":t>=.5?"border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300":"border-rose-500/30 bg-rose-500/10 text-rose-700 dark:text-rose-300"}`,children:[Math.round((e.stats?.score??1)*100),"%"]})]})]},e.name)})})}function t2({label:e,open:t,setOpen:s,selectedCount:n,totalCount:l,allOn:i,onToggleAll:o,headerRef:c,bodyClassName:d,children:u}){return(0,a.jsxs)("div",{className:"rounded-lg border border-border bg-surface-1/40",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1.5",children:[(0,a.jsx)("button",{type:"button",onClick:()=>s(e=>!e),className:"text-fg-subtle hover:text-fg transition-colors","aria-label":t?"Collapse":"Expand",children:t?(0,a.jsx)(r.A,{size:14}):(0,a.jsx)(W.A,{size:14})}),(0,a.jsxs)("label",{className:"flex items-center gap-1.5 cursor-pointer flex-1 min-w-0",children:[(0,a.jsx)("input",{ref:c,type:"checkbox",className:"rounded border-border",checked:i,onChange:e=>o(e.target.checked)}),(0,a.jsx)("span",{className:"text-[12px] font-semibold text-fg truncate",children:e})]}),(0,a.jsxs)("span",{className:"text-[10px] text-fg-faint shrink-0",children:[n,"/",l]})]}),t&&(0,a.jsx)("div",{className:d,children:u})]})}let t5=["from-violet-500 to-indigo-600","from-blue-500 to-cyan-600","from-emerald-500 to-teal-600","from-orange-500 to-amber-600","from-rose-500 to-pink-600","from-fuchsia-500 to-purple-600"];function t3({icon:e,name:t,id:s}){return e?(0,a.jsx)("img",{src:e,alt:t,className:"w-8 h-8 rounded-lg object-cover shrink-0"}):(0,a.jsx)("div",{className:`w-8 h-8 rounded-lg bg-gradient-to-br ${function(e){let t=0;for(let s=0;s<e.length;s++)t=31*t+e.charCodeAt(s)|0;return t5[Math.abs(t)%t5.length]}(s)} flex items-center justify-center text-white text-sm font-bold shrink-0 select-none shadow-sm`,children:t.charAt(0).toUpperCase()})}function t4(){let{agents:e,loading:t,create:s,update:r,remove:n}=function(){let[e,t]=(0,i.useState)([]),[s,a]=(0,i.useState)(!1),r=(0,i.useCallback)(async()=>{a(!0);try{t(await c.FH.agents.list())}finally{a(!1)}},[]);(0,i.useEffect)(()=>{function e(){r()}return r(),window.addEventListener("jarela:agents-changed",e),()=>window.removeEventListener("jarela:agents-changed",e)},[r]);let n=(0,i.useCallback)(async e=>{let s=await c.FH.agents.create(e);return t(e=>[...e,s]),s},[]);return{agents:e,loading:s,refresh:r,create:n,update:(0,i.useCallback)(async(e,s)=>{let a=await c.FH.agents.update(e,s);return t(t=>t.map(t=>t.id===e?a:t)),a},[]),remove:(0,i.useCallback)(async e=>{await c.FH.agents.delete(e),t(t=>t.filter(t=>t.id!==e))},[])}}(),{models:l}=to(),[o,d]=(0,i.useState)(null),[u,x]=(0,i.useState)(null),m=(0,i.useRef)(null);async function p(e){"new"===o?await s(e):o&&await r(o.id,e)}async function h(e){if(confirm(`Delete agent "${e.name}"? This cannot be undone.`)){x(e.id);try{await n(e.id)}finally{x(null)}}}return eX("agents","agent",m),(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between px-3 pt-3 pb-2 shrink-0",children:[(0,a.jsx)("span",{className:"text-[11px] text-fg-faint font-medium uppercase tracking-wide",children:"Agents"}),(0,a.jsxs)("button",{onClick:()=>d("new"),className:"flex items-center gap-1 px-2 py-1 text-xs bg-accent hover:bg-accent-hover text-white rounded-md transition-colors",children:[(0,a.jsx)(eV.A,{size:11})," New"]})]}),(0,a.jsxs)("div",{ref:m,className:"flex-1 overflow-y-auto px-2 pb-2",children:[t&&(0,a.jsx)("p",{className:"text-fg-faint text-xs text-center py-4",children:"Loading…"}),!t&&0===e.length&&(0,a.jsx)("p",{className:"text-fg-faint text-xs text-center py-4 select-none",children:"No agents yet. Create one to start chatting."}),e.map(e=>(0,a.jsxs)("div",{"data-deep-link-id":e.id,className:"group flex items-center gap-2.5 px-2 py-2 rounded-lg hover:bg-surface-3 transition-colors",children:[(0,a.jsx)(t3,{icon:e.icon,name:e.name,id:e.id}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("p",{className:"text-xs text-fg font-medium truncate",children:e.name}),e.identity&&(0,a.jsx)("p",{className:"text-[11px] text-fg-faint truncate",children:e.identity})]}),(0,a.jsxs)("div",{className:"flex items-center gap-0.5 opacity-0 group-hover:opacity-100 focus-within:opacity-100 pointer-coarse:opacity-100 transition-opacity shrink-0",children:[(0,a.jsx)("button",{onClick:()=>d(e),className:"p-1 text-fg-muted hover:text-fg transition-colors",title:"Edit",children:(0,a.jsx)(eY.A,{size:12})}),(0,a.jsx)("button",{onClick:()=>void h(e),disabled:u===e.id,className:"p-1 text-fg-muted hover:text-red-700 dark:hover:text-red-400 transition-colors disabled:opacity-50",title:"Delete",children:(0,a.jsx)(eQ.A,{size:12})})]})]},e.id))]}),null!==o&&(0,a.jsx)(tX,{agent:"new"===o?void 0:o,models:l,onSave:p,onClose:()=>d(null)})]})}var t6=s(7033),t7=s(4018);function t9(e){return"number"==typeof e?e:e instanceof Date?e.getTime():Date.parse(e)}function t8(e,t={}){let s,{signed:a=!0,collapseSeconds:r=!1}=t,n=t9(e)-Date.now(),l=Math.abs(n);return(s=l<6e4?r?"<1m":`${Math.max(1,Math.round(l/1e3))}s`:l<36e5?`${Math.round(l/6e4)}m`:l<1728e5?`${Math.round(l/36e5)}h`:`${Math.round(l/864e5)}d`,a)?n<=0?`${s} ago`:`in ${s}`:s}function se(){let e=(0,i.useRef)(null),[t,s]=(0,i.useState)(null),[r,n]=(0,i.useState)(""),[l,o]=(0,i.useState)(null),[d,u]=(0,i.useState)(""),[x,m]=(0,i.useState)(null),[p,h]=(0,i.useState)(!1),[f,g]=(0,i.useState)(!1);async function b(){h(!0),g(!1);try{let e=await c.FH.profile.update({name:r,icon:l,about:d,preset:x});s(e),g(!0),setTimeout(()=>g(!1),2e3)}catch(e){console.error(e)}finally{h(!1)}}(0,i.useEffect)(()=>{c.FH.profile.get().then(e=>{s(e),n(e.name),o(e.icon),u(e.about),m(e.preset??null)}).catch(console.error)},[]);let j=!!t&&(r!==t.name||l!==t.icon||d!==t.about||(x??null)!==(t.preset??null));return(0,a.jsxs)("div",{className:"p-4 space-y-4",children:[(0,a.jsxs)("div",{className:"flex items-end gap-3",children:[(0,a.jsxs)("div",{className:"shrink-0",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"Icon"}),(0,a.jsx)("button",{onClick:()=>e.current?.click(),className:"w-14 h-14 rounded-xl border-2 border-dashed border-border bg-surface-3 flex items-center justify-center hover:border-accent transition-colors overflow-hidden group",title:"Upload avatar",children:l?(0,a.jsx)("img",{src:l,alt:"avatar",className:"w-full h-full object-cover"}):(0,a.jsx)(tW.A,{size:14,className:"text-fg-faint group-hover:text-accent transition-colors"})}),(0,a.jsx)("input",{ref:e,type:"file",accept:"image/*",className:"hidden",onChange:function(e){let t=e.target.files?.[0];if(!t)return;let s=new FileReader;s.onload=()=>o(s.result),s.readAsDataURL(t)}}),l&&(0,a.jsx)("button",{onClick:()=>o(null),className:"text-[10px] text-fg-faint hover:text-red-700 dark:hover:text-red-400 mt-0.5 block",children:"Remove"})]}),(0,a.jsxs)("label",{className:"flex-1 block",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"Name"}),(0,a.jsx)("input",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent",value:r,onChange:e=>n(e.target.value),placeholder:"Your name"})]})]}),(0,a.jsxs)("label",{className:"block",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"About me"}),(0,a.jsx)("textarea",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent h-28 resize-none",value:d,onChange:e=>u(e.target.value),placeholder:"Senior engineer at Acme Corp. Prefers concise answers. Working on a payments platform\xe2€\xa6"})]}),(0,a.jsx)("p",{className:"text-[11px] text-fg-faint",children:"This information is appended to every agent's context so they know who they're talking to."}),(0,a.jsx)(ss,{value:x,onChange:m}),(0,a.jsx)("button",{onClick:b,disabled:p||!j,className:"w-full py-1.5 text-sm bg-accent hover:bg-accent-hover text-white rounded-lg transition-colors disabled:opacity-40",children:p?"Saving\xe2€\xa6":f?"Saved":"Save profile"}),(0,a.jsx)(sa,{profile:t,onChange:s}),(0,a.jsx)(sn,{}),(0,a.jsx)(sr,{})]})}let st=[{value:"home",label:"Home",hint:"LLMs, mail, calendar, chat"},{value:"work",label:"Work",hint:"Office toolbelt + issue trackers"},{value:"dev",label:"Developer",hint:"Everything, incl. infrastructure"},{value:"custom",label:"Everything",hint:"No filter — show every integration"}];function ss({value:e,onChange:t}){return(0,a.jsxs)("div",{className:"block",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"Persona"}),(0,a.jsx)("p",{className:"text-[11px] text-fg-faint mb-2",children:'Filters the Connections panel so you only see integrations relevant to how you use Jarela. Pick "Everything" to see them all.'}),(0,a.jsx)("div",{className:"grid grid-cols-2 gap-1.5",children:st.map(s=>{let r=(e??"custom")===s.value;return(0,a.jsxs)("button",{type:"button",onClick:()=>t(s.value),"aria-pressed":r,className:`text-left px-2.5 py-2 rounded-lg border transition-colors ${r?"border-accent/60 bg-accent/10 text-fg":"border-border bg-surface-3 text-fg-muted hover:text-fg hover:border-border-strong"}`,children:[(0,a.jsx)("div",{className:"text-xs font-medium",children:s.label}),(0,a.jsx)("div",{className:"text-[10px] text-fg-faint leading-tight mt-0.5",children:s.hint})]},s.value)})})]})}function sa({profile:e,onChange:t}){let s,r=e?.location_consent===1,[n,l]=(0,i.useState)(!1),[o,d]=(0,i.useState)(null);async function u(){if(!n){l(!0),d(null);try{if(!r&&"u">typeof navigator&&!navigator.geolocation)throw Error("Geolocation is not supported in this browser.");let e=await c.FH.profile.setLocationConsent(!r);t(e)}catch(e){d(e instanceof Error?e.message:String(e))}finally{l(!1)}}}s=(0,i.useRef)(0),(0,i.useEffect)(()=>{if(!r||"u"<typeof navigator||!navigator.geolocation)return;let e=async e=>{let t=Date.now();if(!(t-s.current<3e4)){s.current=t;try{await c.FH.profile.updateLocation({lat:e.coords.latitude,lng:e.coords.longitude,accuracy_m:e.coords.accuracy})}catch(e){console.warn("[location] post failed:",e)}}},t=e=>{console.warn("[location] geolocation error:",e.code,e.message)};navigator.geolocation.getCurrentPosition(e,t,{enableHighAccuracy:(void 0)??!1,maximumAge:6e4,timeout:15e3});let a=navigator.geolocation.watchPosition(e,t,{enableHighAccuracy:(void 0)??!1,maximumAge:6e4});return()=>navigator.geolocation.clearWatch(a)},[r,void 0]),(0,i.useEffect)(()=>{if(!r)return;let e=setInterval(()=>{c.FH.profile.get().then(t).catch(()=>{})},5e3);return()=>clearInterval(e)},[r,t]);let x=r&&"number"==typeof e?.location_lat&&"number"==typeof e?.location_lng,m=e?.location_updated_at;return(0,a.jsxs)("div",{className:"pt-4 border-t border-border space-y-2",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(t6.A,{size:14,className:"text-fg-subtle"}),(0,a.jsx)("h3",{className:"text-sm font-semibold text-fg mr-auto",children:"Share my location"}),(0,a.jsx)("button",{onClick:u,disabled:n,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${r?"bg-accent":"bg-surface-3 border border-border"} disabled:opacity-40`,title:r?"Stop sharing":"Start sharing","aria-pressed":r,children:(0,a.jsx)("span",{className:`inline-block h-3.5 w-3.5 transform rounded-full bg-white transition-transform ${r?"translate-x-5":"translate-x-1"}`})})]}),(0,a.jsx)("p",{className:"text-[11px] text-fg-faint",children:"When enabled, your browser sends your current coordinates to Jarela so the agent can answer location-aware questions (weather, nearby places, directions). Stored locally only; never sent to any third party other than the LLM/MCP services you've configured."}),r&&(0,a.jsx)("div",{className:"text-[11px] text-fg-subtle px-2 py-1.5 rounded bg-surface-3/40 border border-border",children:x?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("span",{className:"font-mono",children:[e.location_lat.toFixed(5),", ",e.location_lng.toFixed(5)]}),e?.location_accuracy_m!=null&&(0,a.jsxs)("span",{className:"text-fg-faint",children:[" \xc2\xb7 \xc2\xb1",Math.round(e.location_accuracy_m),"m"]}),m&&(0,a.jsxs)("span",{className:"text-fg-faint",children:[" \xc2\xb7 ",t8(m)]})]}):(0,a.jsx)("span",{className:"text-fg-faint",children:"Waiting for browser fix\xe2€\xa6 (allow location when prompted)"})}),o&&(0,a.jsx)("p",{className:"text-rose-700 dark:text-rose-400 text-[11px]",children:o})]})}function sr(){let[e,t]=(0,i.useState)(null),[s,r]=(0,i.useState)(""),[n,l]=(0,i.useState)(""),[o,d]=(0,i.useState)(!1),[u,x]=(0,i.useState)(null);async function m(){try{t(await c.FH.access.list())}catch(e){x(e instanceof Error?e.message:String(e))}}async function p(){if(x(null),s.trim()){d(!0);try{await c.FH.access.add(s.trim(),n.trim()||null),r(""),l(""),await m()}catch(e){x(e instanceof Error?e.message:String(e))}finally{d(!1)}}}async function h(e){x(null),d(!0);try{await c.FH.access.remove(e),await m()}catch(e){x(e instanceof Error?e.message:String(e))}finally{d(!1)}}return(0,i.useEffect)(()=>{m()},[]),(0,a.jsxs)("div",{className:"pt-4 border-t border-border space-y-2",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(t7.A,{size:14,className:"text-fg-subtle"}),(0,a.jsx)("h3",{className:"text-sm font-semibold text-fg",children:"Tailscale access whitelist"})]}),(0,a.jsxs)("p",{className:"text-[11px] text-fg-faint",children:["Identities allowed to reach Jarela through ",(0,a.jsx)("code",{className:"text-fg-subtle",children:"tailscale serve"}),". Local access (",(0,a.jsx)("code",{className:"text-fg-subtle",children:"localhost"}),") is always allowed. Tailscale passes the identity via the ",(0,a.jsx)("code",{className:"text-fg-subtle",children:"Tailscale-User-Login"})," header."]}),(0,a.jsxs)("div",{className:"flex gap-2 items-end",children:[(0,a.jsxs)("label",{className:"flex-1 block",children:[(0,a.jsx)("span",{className:"text-[10px] text-fg-faint mb-0.5 block",children:"Identity (email)"}),(0,a.jsx)("input",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent",value:s,onChange:e=>r(e.target.value),placeholder:"you@example.com",onKeyDown:e=>{"Enter"===e.key&&p()}})]}),(0,a.jsxs)("label",{className:"w-32 block",children:[(0,a.jsx)("span",{className:"text-[10px] text-fg-faint mb-0.5 block",children:"Label (optional)"}),(0,a.jsx)("input",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent",value:n,onChange:e=>l(e.target.value),placeholder:"iPhone",onKeyDown:e=>{"Enter"===e.key&&p()}})]}),(0,a.jsxs)("button",{onClick:p,disabled:o||!s.trim(),className:"px-3 py-1.5 text-xs bg-accent hover:bg-accent-hover text-white rounded transition-colors disabled:opacity-40 flex items-center gap-1",children:[(0,a.jsx)(eV.A,{size:12})," Add"]})]}),u&&(0,a.jsx)("p",{className:"text-red-700 dark:text-red-400 text-xs",children:u}),(0,a.jsxs)("ul",{className:"divide-y divide-border border border-border rounded",children:[null===e&&(0,a.jsx)("li",{className:"px-3 py-2 text-xs text-fg-faint",children:"Loading\xe2€\xa6"}),e&&0===e.length&&(0,a.jsx)("li",{className:"px-3 py-2 text-xs text-fg-faint",children:"No remote identities allowed yet."}),e?.map(e=>(0,a.jsxs)("li",{className:"px-3 py-2 flex items-center gap-2 text-xs",children:[(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("div",{className:"font-mono text-fg truncate",children:e.identity}),(0,a.jsxs)("div",{className:"text-[10px] text-fg-faint",children:[e.display_name?`${e.display_name} \xc2\xb7 `:"","added ",new Date(e.added_at).toLocaleString(),e.last_seen_at?` \xc2\xb7 last seen ${new Date(e.last_seen_at).toLocaleString()}`:" \xc2\xb7 never seen"]})]}),(0,a.jsx)("button",{onClick:()=>h(e.identity),disabled:o,className:"p-1 text-fg-faint hover:text-red-700 dark:hover:text-red-400 disabled:opacity-40",title:"Remove",children:(0,a.jsx)(eQ.A,{size:12})})]},e.identity))]})]})}function sn(){let[e,t]=(0,i.useState)(null),[s,r]=(0,i.useState)(null),[l,o]=(0,i.useState)(!1);async function d(){if(e)try{await navigator.clipboard.writeText(e.serve_recipe),o(!0),setTimeout(()=>o(!1),1500)}catch{}}(0,i.useEffect)(()=>{c.FH.tailscale.status().then(t).catch(e=>r(e instanceof Error?e.message:String(e)))},[]);let u=e?.fqdn?`https://${e.fqdn}/`:null;return(0,a.jsxs)("div",{className:"pt-4 border-t border-border space-y-2",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(tx.A,{size:14,className:"text-fg-subtle"}),(0,a.jsx)("h3",{className:"text-sm font-semibold text-fg mr-auto",children:"Tailscale serve"}),e&&(0,a.jsx)("span",{className:`text-[10px] uppercase tracking-wide font-semibold px-1.5 py-0.5 rounded ${e.serving?"bg-emerald-500/15 text-emerald-700 dark:text-emerald-400":e.installed?"bg-amber-500/15 text-amber-700 dark:text-amber-400":"bg-surface-3 text-fg-faint"}`,children:e.installed?e.serving?"serving":e.logged_in?"idle":"logged out":"not installed"})]}),(0,a.jsx)("p",{className:"text-[11px] text-fg-faint",children:"Expose this Jarela on your tailnet so phones (iOS PWA included) can reach it over a trusted HTTPS path. Run the recipe once, then add identities to the whitelist below."}),e?.serving&&u&&(0,a.jsxs)("div",{className:"text-[11px] px-2 py-1.5 rounded bg-surface-3/40 border border-border",children:[(0,a.jsx)("span",{className:"text-fg-faint",children:"Reachable at "}),(0,a.jsx)("a",{href:u,target:"_blank",rel:"noreferrer",className:"font-mono text-accent hover:underline break-all",children:u})]}),e&&(0,a.jsxs)("div",{className:"flex items-stretch gap-1.5",children:[(0,a.jsx)("code",{className:"flex-1 text-[11px] font-mono bg-surface-3 text-fg-muted px-2 py-1.5 rounded border border-border break-all leading-snug",children:e.serve_recipe}),(0,a.jsx)("button",{onClick:d,className:"px-2 text-xs bg-surface-3 hover:bg-surface text-fg-muted border border-border rounded transition-colors flex items-center gap-1",title:"Copy recipe",children:l?(0,a.jsx)(n.A,{size:12,className:"text-emerald-600"}):(0,a.jsx)(ei.A,{size:12})})]}),e&&!e.installed&&(0,a.jsxs)("p",{className:"text-[11px] text-fg-faint",children:["Tailscale isn't installed on this host. Install from"," ",(0,a.jsx)("a",{href:"https://tailscale.com/download/windows",target:"_blank",rel:"noreferrer",className:"text-accent hover:underline",children:"tailscale.com"})," ","and run ",(0,a.jsx)("code",{className:"text-fg-subtle",children:"tailscale up"})," first."]}),e?.installed&&!e.logged_in&&(0,a.jsxs)("p",{className:"text-[11px] text-fg-faint",children:["Tailscale is installed but not logged in. Run ",(0,a.jsx)("code",{className:"text-fg-subtle",children:"tailscale up"})," in a terminal."]}),e&&(0,a.jsxs)("p",{className:"text-[11px] text-fg-faint",children:["Or run the helper script:"," ",(0,a.jsx)("code",{className:"text-fg-subtle",children:e.install_script})," \xe2€” ",(0,a.jsx)("code",{className:"text-fg-subtle",children:e.uninstall_script})," to reverse."]}),s&&(0,a.jsx)("p",{className:"text-red-700 dark:text-red-400 text-xs",children:s})]})}function sl(){let e=(0,i.useRef)(null);return eX("profile","profile",e),(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[(0,a.jsxs)("div",{className:"border-b border-border px-4 py-3 flex items-center gap-2",children:[(0,a.jsx)(er.A,{size:14,className:"text-fg-subtle"}),(0,a.jsx)("h2",{className:"text-sm font-semibold text-fg",children:"User Profile"})]}),(0,a.jsx)("div",{ref:e,className:"flex-1 overflow-y-auto max-w-lg mx-auto w-full",children:(0,a.jsx)(se,{})})]})}var si=s(5737),so=s(4962),sc=s(8780),sd=s(1275),su=s(6272);function sx(){let[e,t]=(0,i.useState)([]),[s,r]=(0,i.useState)(!0),[n,l]=(0,i.useState)(null),o=(0,i.useRef)(null);async function d(){r(!0);try{t(await c.FH.mcp.list())}catch(e){console.error(e)}finally{r(!1)}}async function u(e){await c.FH.mcp.update(e.name,{enabled:!e.enabled}),d()}async function x(e){confirm(`Remove MCP server "${e}"?`)&&(await c.FH.mcp.delete(e),d())}return eX("mcp","mcp",o),(0,i.useEffect)(()=>{d()},[]),(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[(0,a.jsxs)("div",{className:"border-b border-border px-4 py-3 flex items-center gap-2",children:[(0,a.jsx)(si.A,{size:14,className:"text-fg-subtle"}),(0,a.jsx)("h2",{className:"text-sm font-semibold text-fg mr-auto",children:"MCP Servers"}),(0,a.jsxs)("button",{onClick:()=>l({mode:"picker"}),className:"flex items-center gap-1 text-xs text-accent hover:text-accent-hover transition-colors",children:[(0,a.jsx)(eV.A,{size:14})," New"]})]}),(0,a.jsx)("div",{ref:o,className:"flex-1 overflow-y-auto",children:(0,a.jsxs)("div",{className:"px-4 py-2",children:[s&&0===e.length&&(0,a.jsx)("p",{className:"text-fg-faint text-sm py-6 text-center",children:"Loading…"}),!s&&0===e.length&&(0,a.jsxs)("div",{className:"text-fg-faint text-sm py-8 text-center space-y-2",children:[(0,a.jsx)("p",{children:"No MCP servers configured."}),(0,a.jsx)("p",{className:"text-xs text-fg-faint",children:"MCP servers expose tools (filesystem, GitHub, Postgres, …) that the agent can call alongside built-ins."})]}),e.map(e=>(0,a.jsxs)("div",{"data-deep-link-id":e.name,className:"flex items-center gap-3 py-2.5 border-b border-border/60 group",children:[(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 mb-0.5",children:[(0,a.jsx)("button",{onClick:()=>u(e),className:e.enabled?"text-emerald-700 dark:text-emerald-400":"text-fg-faint hover:text-fg-subtle",title:e.enabled?"Disable":"Enable",children:e.enabled?(0,a.jsx)(so.A,{size:13}):(0,a.jsx)(tL.A,{size:13})}),(0,a.jsx)("span",{className:"text-sm font-medium text-fg",children:e.name}),(0,a.jsx)("span",{className:"text-[10px] uppercase tracking-wide px-1.5 py-0.5 rounded border bg-surface-2 text-fg-subtle border-border",children:e.transport})]}),(0,a.jsx)("p",{className:"text-xs text-fg-faint truncate font-mono",children:"stdio"===e.transport?`${e.spec.command??"?"} ${(e.spec.args??[]).join(" ")}`:`${e.spec.url??"?"}`}),e.last_error&&(0,a.jsxs)("p",{className:"text-xs text-rose-700 dark:text-rose-400 mt-0.5 truncate",title:e.last_error,children:["error: ",e.last_error]})]}),(0,a.jsxs)("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 pointer-coarse:opacity-100 transition-opacity shrink-0",children:[(0,a.jsx)("button",{onClick:()=>l({mode:"form",existing:e}),className:"p-1 text-fg-subtle hover:text-fg transition-colors",title:"Edit",children:(0,a.jsx)("span",{className:"text-xs",children:"edit"})}),(0,a.jsx)("button",{onClick:()=>x(e.name),className:"p-1 text-fg-subtle hover:text-red-700 dark:hover:text-red-400 transition-colors",title:"Delete",children:(0,a.jsx)(eQ.A,{size:13})})]})]},e.name))]})}),n?.mode==="picker"&&(0,a.jsx)(sp,{existingNames:new Set(e.map(e=>e.name)),onPick:e=>l({mode:"form",existing:null,registryEntry:e}),onCustom:()=>l({mode:"form",existing:null}),onClose:()=>l(null)}),n?.mode==="form"&&(0,a.jsx)(sm,{server:n.existing,registryEntry:n.registryEntry,onBack:n.existing?void 0:()=>l({mode:"picker"}),onClose:()=>{l(null),d()}})]})}function sm({server:e,registryEntry:t,onClose:s,onBack:r}){let[n,l]=(0,i.useState)(e?.name??t?.id??""),[o,d]=(0,i.useState)(e?.transport??t?.transport??"stdio"),[u,x]=(0,i.useState)(()=>{let e={};for(let s of t?.variables??[])e[s.key]=s.default??"";return e}),m=(0,i.useMemo)(()=>e?JSON.stringify(e.spec,null,2):t?JSON.stringify(t.spec,null,2):JSON.stringify("stdio"===o?{command:"npx",args:["-y","@modelcontextprotocol/server-filesystem","/tmp"]}:{url:"https://example.com/mcp",headers:{}},null,2),[]),[p,h]=(0,i.useState)(m),[f,g]=(0,i.useState)(e?.enabled??!0),[b,j]=(0,i.useState)(null),[y,v]=(0,i.useState)(!1);async function N(){let a;if(j(null),!n.trim())return void j("name is required");try{a=JSON.parse(p)}catch(e){j(`spec is not valid JSON: ${e instanceof Error?e.message:String(e)}`);return}if(t?.variables?.length){var r,l;let e=t.variables.filter(e=>!u[e.key]?.trim());if(e.length>0)return void j(`Fill in: ${e.map(e=>e.label).join(", ")}`);r=a,l=u,a=function e(t){if("string"==typeof t)return t.replace(/\$\{(\w+)\}/g,(e,t)=>l[t]??`\${${t}}`);if(Array.isArray(t))return t.map(e);if(t&&"object"==typeof t){let s={};for(let[a,r]of Object.entries(t))s[a]=e(r);return s}return t}(r)}v(!0);try{e?await c.FH.mcp.update(e.name,{transport:o,spec:a,enabled:f}):await c.FH.mcp.create({name:n.trim(),transport:o,spec:a,enabled:f}),s()}catch(t){e6({title:e?"Couldn't update MCP server":"Couldn't create MCP server",error:t,context:{panel:"mcp",action:e?"mcp.update":"mcp.create",name:n.trim(),transport:o}})}finally{v(!1)}}return(0,a.jsx)("div",{className:"absolute inset-0 bg-black/60 z-30 flex items-center justify-center p-4",onClick:s,children:(0,a.jsxs)("div",{className:"bg-surface-2 border border-border rounded-xl w-full max-w-md shadow-2xl max-h-[90vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,a.jsxs)("div",{className:"px-4 py-3 border-b border-border flex items-center gap-1",children:[r&&(0,a.jsx)("button",{onClick:r,className:"p-1 text-fg-subtle hover:text-fg",title:"Back to picker",children:(0,a.jsx)(sc.A,{size:14})}),(0,a.jsx)("h3",{className:"text-sm font-semibold text-fg mr-auto",children:e?`Edit ${e.name}`:t?`Install ${t.name}`:"New MCP server"}),(0,a.jsx)("button",{onClick:s,className:"p-1 text-fg-subtle hover:text-fg",children:(0,a.jsx)(z.A,{size:14})})]}),(0,a.jsxs)("div",{className:"p-4 space-y-3 overflow-y-auto",children:[t&&(0,a.jsxs)("div",{className:"px-3 py-2 rounded bg-surface-3/40 border border-border text-[11px] text-fg-subtle",children:[t.description,t.url&&(0,a.jsxs)("a",{href:t.url,target:"_blank",rel:"noreferrer",className:"ml-1 inline-flex items-center gap-0.5 text-sky-700 dark:text-sky-400 hover:text-sky-700 dark:hover:text-sky-300",children:["docs ",(0,a.jsx)(sd.A,{size:10})]})]}),t?.variables?.length?(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)("p",{className:"text-xs text-fg-subtle font-medium",children:"Configure"}),t.variables.map(e=>(0,a.jsxs)("label",{className:"block text-xs text-fg-subtle",children:[e.label,(0,a.jsx)("input",{type:e.secret?"password":"text",value:u[e.key]??"",onChange:t=>x(s=>({...s,[e.key]:t.target.value})),placeholder:e.placeholder,className:"mt-1 w-full px-2 py-1.5 text-sm rounded border border-border bg-surface-3 text-fg font-mono"})]},e.key))]}):null,(0,a.jsxs)("label",{className:"block text-xs text-fg-subtle",children:["Name",(0,a.jsx)("input",{value:n,onChange:e=>l(e.target.value),disabled:!!e,className:"mt-1 w-full px-2 py-1.5 text-sm rounded border border-border bg-surface-3 text-fg disabled:opacity-50",placeholder:"filesystem"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-xs text-fg-subtle mb-1",children:"Transport"}),(0,a.jsx)("div",{className:"flex gap-1",children:["stdio","http"].map(e=>(0,a.jsx)("button",{onClick:()=>{d(e),h(JSON.stringify("stdio"===e?{command:"npx",args:["-y","@modelcontextprotocol/server-filesystem","/tmp"]}:{url:"https://example.com/mcp",headers:{}},null,2))},className:`px-3 py-1 text-xs rounded border ${o===e?"bg-accent/20 border-accent text-accent":"bg-surface-3 border-border text-fg-subtle hover:text-fg"}`,children:e},e))})]}),(0,a.jsxs)("label",{className:"block text-xs text-fg-subtle",children:["Spec (JSON)",(0,a.jsx)("p",{className:"mt-0.5 mb-1 text-[11px] text-fg-faint",children:"stdio"===o?(0,a.jsxs)(a.Fragment,{children:["Keys: ",(0,a.jsx)("code",{children:"command"}),", ",(0,a.jsx)("code",{children:"args[]"}),", ",(0,a.jsx)("code",{children:"env"})]}):(0,a.jsxs)(a.Fragment,{children:["Keys: ",(0,a.jsx)("code",{children:"url"}),", ",(0,a.jsx)("code",{children:"headers"})]})}),(0,a.jsx)("textarea",{value:p,onChange:e=>h(e.target.value),rows:8,className:"w-full px-2 py-1.5 text-xs font-mono rounded border border-border bg-surface-3 text-fg"})]}),(0,a.jsxs)("label",{className:"inline-flex items-center gap-2 text-xs text-fg-muted",children:[(0,a.jsx)("input",{type:"checkbox",checked:f,onChange:e=>g(e.target.checked)}),"Enabled"]}),b&&(0,a.jsx)("div",{className:"px-2 py-1.5 rounded bg-rose-950/40 border border-rose-800 text-xs text-rose-700 dark:text-rose-300",children:b})]}),(0,a.jsxs)("div",{className:"px-4 py-3 border-t border-border flex justify-end gap-2",children:[(0,a.jsx)("button",{onClick:s,className:"px-3 py-1.5 text-xs text-fg-subtle hover:text-fg",children:"Cancel"}),(0,a.jsx)("button",{onClick:N,disabled:y,className:"px-3 py-1.5 text-xs rounded bg-accent text-white hover:bg-accent-hover disabled:opacity-50",children:y?"Saving…":"Save"})]})]})})}function sp({existingNames:e,onPick:t,onCustom:s,onClose:r}){let[n,l]=(0,i.useState)(""),[o,d]=(0,i.useState)(""),[u,x]=(0,i.useState)([]),[m,p]=(0,i.useState)(void 0),[h,f]=(0,i.useState)(!0),[g,b]=(0,i.useState)(!1),[j,y]=(0,i.useState)(null);(0,i.useEffect)(()=>{let e=setTimeout(()=>d(n.trim()),250);return()=>clearTimeout(e)},[n]);let v=(0,i.useCallback)(async(e,t=!1)=>{f(!0),y(null);try{let s=await c.FH.mcp.registry({q:e||void 0,fresh:t});x(s.entries),p(s.nextCursor)}catch(t){x([]),p(void 0),y(t instanceof Error?t.message:String(t)),e6({title:"Couldn't search MCP registry",error:t,context:{panel:"mcp",action:"registry.search",query:e||null}})}finally{f(!1)}},[]);async function N(){if(m&&!g){b(!0);try{let e=await c.FH.mcp.registry({q:o||void 0,cursor:m});x(t=>[...t,...e.entries]),p(e.nextCursor)}catch(e){y(e instanceof Error?e.message:String(e)),e6({title:"Couldn't load more registry entries",error:e,context:{panel:"mcp",action:"registry.loadMore",cursor:m??null}})}finally{b(!1)}}}return(0,i.useEffect)(()=>{v(o)},[o,v]),(0,a.jsx)("div",{className:"absolute inset-0 bg-black/60 z-30 flex items-center justify-center p-4",onClick:r,children:(0,a.jsxs)("div",{className:"bg-surface-2 border border-border rounded-xl w-full max-w-lg shadow-2xl max-h-[85vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,a.jsxs)("div",{className:"px-4 py-3 border-b border-border flex items-center gap-2",children:[(0,a.jsx)(su.A,{size:14,className:"text-amber-700 dark:text-amber-400"}),(0,a.jsx)("h3",{className:"text-sm font-semibold text-fg mr-auto",children:"Add MCP server"}),(0,a.jsx)("button",{onClick:r,className:"p-1 text-fg-subtle hover:text-fg",children:(0,a.jsx)(z.A,{size:14})})]}),(0,a.jsx)("div",{className:"px-4 py-2 border-b border-border",children:(0,a.jsx)("input",{value:n,onChange:e=>l(e.target.value),placeholder:"Search the MCP registry…",className:"w-full px-2 py-1.5 text-sm rounded border border-border bg-surface-3 text-fg",autoFocus:!0})}),(0,a.jsxs)("div",{className:"flex-1 overflow-y-auto px-4 py-2",children:[h&&0===u.length&&(0,a.jsx)("p",{className:"text-fg-faint text-sm py-6 text-center",children:"Loading…"}),j&&(0,a.jsxs)("div",{className:"my-3 px-3 py-2 rounded border border-rose-800 bg-rose-950/40 text-xs text-rose-700 dark:text-rose-300",children:[(0,a.jsx)("p",{className:"mb-1",children:"Couldn’t reach registry.modelcontextprotocol.io."}),(0,a.jsx)("button",{onClick:()=>void v(o,!0),className:"underline hover:text-rose-200",children:"Retry"})]}),!h&&!j&&0===u.length&&(0,a.jsx)("p",{className:"text-fg-faint text-sm py-6 text-center",children:"No matches."}),(0,a.jsx)("div",{className:"space-y-1",children:u.map(s=>{let r=e.has(s.id);return(0,a.jsxs)("button",{onClick:()=>t(s),disabled:r,className:`w-full text-left px-3 py-2 rounded-lg border transition-colors group ${r?"bg-surface-3/30 border-border/40 cursor-not-allowed":"bg-surface-3/60 hover:bg-surface-3 border-border hover:border-border"}`,children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 mb-0.5",children:[(0,a.jsx)("span",{className:`text-sm font-medium ${r?"text-fg-faint":"text-fg"}`,children:s.name}),(0,a.jsx)("span",{className:"text-[9px] uppercase tracking-wider px-1 py-px rounded border border-border text-fg-faint",children:s.transport}),(0,a.jsx)("span",{className:`text-[9px] uppercase tracking-wider px-1 py-px rounded border ${"Official"===s.source?"border-emerald-700/60 text-emerald-600 dark:text-emerald-400 bg-emerald-500/10":"Vendor"===s.source?"border-sky-700/60 text-sky-600 dark:text-sky-400 bg-sky-500/10":"border-border text-fg-faint"}`,children:s.source}),r&&(0,a.jsx)("span",{className:"text-[10px] text-emerald-500 ml-auto",children:"installed"})]}),(0,a.jsx)("p",{className:`text-xs ${r?"text-fg-faint":"text-fg-subtle"}`,children:s.description})]},`${s.id}-${s.name}`)})}),m&&!j&&(0,a.jsx)("div",{className:"text-center my-3",children:(0,a.jsx)("button",{onClick:N,disabled:g,className:"text-xs text-fg-subtle hover:text-fg disabled:opacity-50",children:g?"Loading…":"Load more"})})]}),(0,a.jsxs)("div",{className:"px-4 py-3 border-t border-border flex items-center justify-between",children:[(0,a.jsx)("button",{onClick:s,className:"text-xs text-fg-subtle hover:text-fg",children:"…or set up a custom server"}),(0,a.jsx)("button",{onClick:r,className:"px-3 py-1.5 text-xs text-fg-subtle hover:text-fg",children:"Cancel"})]})]})})}var sh=s(2061),sf=s(1499);let sg="********";function sb(){let[e,t]=(0,i.useState)(null),[s,r]=(0,i.useState)(!0),n=(0,i.useRef)(null);async function l(){r(!0);try{t(await c.FH.extensions.list())}catch(e){console.error(e)}finally{r(!1)}}return eX("extensions","extension",n),(0,i.useEffect)(()=>{l()},[]),(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[(0,a.jsxs)("div",{className:"border-b border-border px-4 py-3 flex items-center gap-2",children:[(0,a.jsx)(sh.A,{size:14,className:"text-fg-subtle"}),(0,a.jsx)("h2",{className:"text-sm font-semibold text-fg mr-auto",children:"Extensions"}),(0,a.jsxs)("button",{onClick:()=>void l(),className:"flex items-center gap-1 text-xs text-accent hover:text-accent-hover transition-colors",title:"Re-scan extension directories",children:[(0,a.jsx)(tI.A,{size:13})," Refresh"]})]}),(0,a.jsxs)("div",{ref:n,className:"flex-1 overflow-y-auto px-4 py-3 space-y-5",children:[s&&!e&&(0,a.jsx)("p",{className:"text-fg-faint text-sm py-6 text-center",children:"Loading…"}),e&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(sj,{title:"External providers",dir:e.directories.providers,children:0===e.providers.length?(0,a.jsx)(sN,{dir:e.directories.providers,what:"provider",template:"lib/providers/template-external.cjs.example"}):e.providers.map(e=>(0,a.jsx)(sy,{name:e.name,file:e.file},e.name))}),(0,a.jsx)(sj,{title:"External tools",dir:e.directories.tools,children:0===e.tools.length?(0,a.jsx)(sN,{dir:e.directories.tools,what:"tool",template:"lib/tools/template-external.cjs.example"}):e.tools.map(e=>(0,a.jsx)(sv,{tool:e,onSaved:()=>void l()},e.name))}),e.errors.length>0&&(0,a.jsx)(sj,{title:"Validation errors",children:e.errors.map((e,t)=>(0,a.jsxs)("div",{className:"flex gap-2 py-2 border-b border-border/60",children:[(0,a.jsx)(tL.A,{size:13,className:"text-rose-700 dark:text-rose-400 mt-0.5 shrink-0"}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsxs)("p",{className:"text-xs text-fg",children:[(0,a.jsx)("span",{className:"text-fg-subtle uppercase tracking-wide",children:e.kind})," ",(0,a.jsx)("span",{className:"font-mono",children:e.file})]}),(0,a.jsx)("p",{className:"text-xs text-rose-700 dark:text-rose-400 break-words",children:e.error})]})]},`${e.kind}-${e.file}-${t}`))})]})]})]})}function sj({title:e,dir:t,children:s}){return(0,a.jsxs)("section",{children:[(0,a.jsxs)("div",{className:"flex items-baseline justify-between mb-1.5",children:[(0,a.jsx)("h3",{className:"text-[11px] uppercase tracking-wide text-fg-faint font-semibold",children:e}),t&&(0,a.jsx)("span",{className:"text-[10px] text-fg-faint font-mono truncate max-w-[60%]",title:t,children:t})]}),(0,a.jsx)("div",{children:s})]})}function sy({name:e,file:t,badge:s,sub:r}){return(0,a.jsx)("div",{"data-deep-link-id":e,className:"flex items-center gap-3 py-2 border-b border-border/60",children:(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"text-sm font-medium text-fg",children:e}),s&&(0,a.jsx)("span",{className:"text-[10px] uppercase tracking-wide px-1.5 py-0.5 rounded border bg-surface-2 text-fg-subtle border-border",children:s})]}),r&&(0,a.jsx)("p",{className:"text-xs text-fg-faint mt-0.5 line-clamp-2",children:r}),t&&(0,a.jsx)("p",{className:"text-[11px] text-fg-faint mt-0.5 font-mono truncate",children:t})]})})}function sv({tool:e,onSaved:t}){let[s,r]=(0,i.useState)(!1),[n,l]=(0,i.useState)(()=>Object.fromEntries(e.secrets.map(e=>[e.key,e.is_set?sg:""]))),[o,d]=(0,i.useState)(!1),[u,x]=(0,i.useState)(null);(0,i.useEffect)(()=>{l(Object.fromEntries(e.secrets.map(e=>[e.key,e.is_set?sg:""])))},[e.name,e.secrets]);let m=e.secrets.length>0,p=e.secrets.filter(e=>e.is_set).length,h=e.secrets.some(e=>e.required&&!e.is_set);async function f(){d(!0),x(null);try{let s={};for(let t of e.secrets){let e=n[t.key];void 0!==e&&e!==sg&&(s[t.key]=e)}await c.FH.extensions.saveToolSecrets(e.name,s),t()}catch(e){x(e instanceof Error?e.message:String(e))}finally{d(!1)}}return(0,a.jsxs)("div",{"data-deep-link-id":e.name,className:"py-2 border-b border-border/60",children:[(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"text-sm font-medium text-fg",children:e.name}),e.category&&(0,a.jsx)("span",{className:"text-[10px] uppercase tracking-wide px-1.5 py-0.5 rounded border bg-surface-2 text-fg-subtle border-border",children:e.category}),m&&(0,a.jsxs)("span",{className:`text-[10px] uppercase tracking-wide px-1.5 py-0.5 rounded border ${h?"bg-amber-50 dark:bg-amber-950/40 text-amber-800 dark:text-amber-300 border-amber-200 dark:border-amber-900":"bg-emerald-50 dark:bg-emerald-950/40 text-emerald-800 dark:text-emerald-300 border-emerald-200 dark:border-emerald-900"}`,title:h?"Required secrets are missing":"Configured",children:[p,"/",e.secrets.length," secrets"]})]}),e.description&&(0,a.jsx)("p",{className:"text-xs text-fg-faint mt-0.5 line-clamp-2",children:e.description}),e.file&&(0,a.jsx)("p",{className:"text-[11px] text-fg-faint mt-0.5 font-mono truncate",children:e.file})]}),m&&(0,a.jsxs)("button",{onClick:()=>r(e=>!e),className:"flex items-center gap-1 text-xs text-accent hover:text-accent-hover transition-colors shrink-0",title:"Edit secrets",children:[(0,a.jsx)(sf.A,{size:13})," ",s?"Hide":"Edit"]})]}),s&&m&&(0,a.jsxs)("div",{className:"mt-2 ml-1 pl-3 border-l border-border/60 space-y-2",children:[e.secrets.map(e=>(0,a.jsxs)("label",{className:"block",children:[(0,a.jsxs)("span",{className:"text-xs text-fg-subtle",children:[e.label??e.key,e.required&&(0,a.jsx)("span",{className:"text-rose-600 dark:text-rose-400 ml-0.5",children:"*"})]}),e.description&&(0,a.jsx)("span",{className:"block text-[11px] text-fg-faint",children:e.description}),(0,a.jsx)("input",{type:"password",autoComplete:"off",value:n[e.key]??"",onChange:t=>l(s=>({...s,[e.key]:t.target.value})),onFocus:e=>{e.currentTarget.value===sg&&e.currentTarget.select()},placeholder:e.is_set?"":"not configured",className:"mt-0.5 w-full px-2 py-1 text-sm bg-surface border border-border rounded font-mono"})]},e.key)),u&&(0,a.jsx)("p",{className:"text-xs text-rose-700 dark:text-rose-400",children:u}),(0,a.jsxs)("div",{className:"flex items-center gap-2 pt-1",children:[(0,a.jsx)("button",{onClick:()=>void f(),disabled:o,className:"text-xs px-2 py-1 rounded bg-accent text-white hover:bg-accent-hover disabled:opacity-50",children:o?"Saving…":"Save"}),(0,a.jsx)("span",{className:"text-[11px] text-fg-faint",children:"Leave a field empty to clear it. Stored encrypted at rest."})]})]})]})}function sN({dir:e,what:t,template:s}){return(0,a.jsxs)("div",{className:"text-fg-faint text-xs py-4 space-y-1.5",children:[(0,a.jsxs)("p",{children:["No external ",t,"s loaded."]}),(0,a.jsxs)("p",{children:["Drop a ",(0,a.jsx)("code",{className:"text-fg-subtle",children:".cjs"})," file into"," ",(0,a.jsx)("span",{className:"font-mono text-fg-subtle",children:e}),". Hot-reload is automatic on the next request."]}),(0,a.jsxs)("p",{children:["Template: ",(0,a.jsx)("span",{className:"font-mono text-fg-subtle",children:s})]})]})}let sw={Memory:"Long-term recall: remember/recall facts across sessions.",Documents:"Semantic search over folders you indexed (RAG).",Files:"Read / write / list files in the workspace.",Shell:"Execute shell commands locally.",Web:"Fetch URLs and run web searches.",Images:"Generate images via configured providers.",Voice:"Synthesize speech via TTS.",Schedule:"Create one-off and recurring scheduled tasks.",Atlassian:"Jira and Confluence read/write.",JiraAlign:"Jira Align portfolio-level read/write.",GitHub:"Issues, pull requests, code search via the GitHub API.",Mail:"Read and send email via Gmail / Outlook.",Calendar:"Read and write calendar events.",Config:"Read/write Jarela's own settings."};function sk(){var e;let t,[s,r]=(0,i.useState)([]),[n,l]=(0,i.useState)([]),[o,d]=(0,i.useState)(!0),[u,x]=(0,i.useState)({}),[m,p]=(0,i.useState)(""),[h,f]=(0,i.useState)("all"),[g,b]=(0,i.useState)("all");async function j(e){let t=!e.enabled;x(t=>({...t,[e.category]:!0}));try{await c.FH.builtinTools.setEnabled(e.category,t),r(s=>s.map(s=>s.category===e.category?{...s,enabled:t}:s)),l(await c.FH.tools.list())}catch(s){e6({title:"Couldn't toggle built-in tool",error:s,context:{panel:"tools",action:"toggle",category:e.category,target_enabled:t}})}finally{x(t=>({...t,[e.category]:!1}))}}(0,i.useEffect)(()=>{Promise.all([c.FH.builtinTools.list(),c.FH.tools.list()]).then(([e,t])=>{r(e),l(t)}).catch(e=>{e6({title:"Couldn't load tool catalog",error:e,context:{panel:"tools",action:"list"}})}).finally(()=>d(!1))},[]);let y=n.filter(e=>{let t=m.trim().toLowerCase();if(t&&!`${e.name} ${e.category??""} ${e.description??""}`.toLowerCase().includes(t)||"all"!==h&&e.source!==h)return!1;let s=e.stats;return!("new"===g&&!s?.never_used||"healthy"===g&&(s?.never_used||(s?.score??0)<.75)||"attention"===g&&(s?.never_used||(s?.score??0)>=.75))}),v=(e=m,(t=new URL("https://github.com/CircuitWall/jarela/issues/new")).searchParams.set("title",e.trim()?`tool issue: ${e.trim()}`:"tool issue: describe the failing tool"),t.searchParams.set("body",["## What happened\n\nDescribe the tool, MCP server, or documents/RAG issue.\n\n## Tool name / filter",e.trim()||"(fill in)","\n## Expected result\n\n## Actual result\n\n## Additional context\n"].join("\n")),t.toString());return(0,a.jsxs)("div",{className:"p-4 space-y-3",children:[(0,a.jsxs)("header",{className:"space-y-1",children:[(0,a.jsx)("h2",{className:"text-sm font-semibold text-fg",children:"Built-in tools"}),(0,a.jsx)("p",{className:"text-xs text-fg-faint",children:"Turn whole categories of built-in tools on or off. Disabled categories disappear from the agent permission editor and cannot be invoked even if an older agent still has them in its allow-list."})]}),o&&(0,a.jsx)("p",{className:"text-fg-faint text-sm py-3 text-center",children:"Loading…"}),(0,a.jsx)("ul",{className:"space-y-2",children:s.map(e=>(0,a.jsx)("li",{className:"rounded-lg border border-border bg-surface-2 px-3 py-2.5",children:(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,a.jsx)("span",{className:"text-sm font-semibold text-fg",children:e.category}),(0,a.jsxs)("span",{className:"text-[11px] text-fg-faint",children:[e.toolCount," tool",1===e.toolCount?"":"s"]})]}),(0,a.jsx)("p",{className:"text-xs text-fg-muted mt-0.5",children:sw[e.category]??""}),(0,a.jsxs)("details",{className:"mt-1.5",children:[(0,a.jsx)("summary",{className:"text-[11px] text-fg-faint cursor-pointer select-none hover:text-fg-muted",children:"Tools"}),(0,a.jsx)("ul",{className:"mt-1 ml-2 flex flex-wrap gap-1",children:e.toolNames.map(e=>(0,a.jsx)("li",{className:"font-mono text-[10px] px-1.5 py-0.5 rounded bg-surface-3 text-fg-muted",children:e},e))})]})]}),(0,a.jsxs)("label",{className:"text-[11px] text-fg-faint flex items-center gap-1 select-none shrink-0 pt-0.5",children:[(0,a.jsx)("input",{type:"checkbox",checked:e.enabled,disabled:u[e.category],onChange:()=>void j(e)}),"enabled"]})]})},e.category))}),(0,a.jsxs)("section",{className:"pt-3 border-t border-border space-y-3",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("h3",{className:"text-sm font-semibold text-fg",children:"Ranked tool catalog"}),(0,a.jsx)("p",{className:"text-xs text-fg-faint",children:"Success rate tracks completed calls without errors. Usefulness tracks results whose content appears in the final assistant answer."})]}),(0,a.jsx)("a",{href:v,target:"_blank",rel:"noreferrer",className:"shrink-0 rounded-md border border-border px-2.5 py-1.5 text-xs text-fg-muted hover:text-fg hover:bg-surface-2",children:"Report issue"})]}),(0,a.jsxs)("div",{className:"grid gap-2 md:grid-cols-[minmax(0,1fr)_140px_140px]",children:[(0,a.jsx)("input",{value:m,onChange:e=>p(e.target.value),placeholder:"Filter by name, category, or description",className:"rounded-md border border-border bg-surface-2 px-3 py-2 text-sm text-fg outline-none focus:border-fg-faint"}),(0,a.jsxs)("select",{value:h,onChange:e=>f(e.target.value),className:"rounded-md border border-border bg-surface-2 px-3 py-2 text-sm text-fg outline-none focus:border-fg-faint",children:[(0,a.jsx)("option",{value:"all",children:"All sources"}),(0,a.jsx)("option",{value:"builtin",children:"Built-in + RAG"}),(0,a.jsx)("option",{value:"mcp",children:"MCP"})]}),(0,a.jsxs)("select",{value:g,onChange:e=>b(e.target.value),className:"rounded-md border border-border bg-surface-2 px-3 py-2 text-sm text-fg outline-none focus:border-fg-faint",children:[(0,a.jsx)("option",{value:"all",children:"All health states"}),(0,a.jsx)("option",{value:"new",children:"New: 100%"}),(0,a.jsx)("option",{value:"healthy",children:"Healthy"}),(0,a.jsx)("option",{value:"attention",children:"Needs attention"})]})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[0===y.length&&(0,a.jsx)("p",{className:"rounded-lg border border-border bg-surface-2 px-3 py-4 text-sm text-fg-faint text-center",children:"No tools match the current filters."}),y.map(e=>{let t=e.stats,s=Math.round((t?.score??1)*100),r=Math.round((t?.success_rate??1)*100),n=Math.round((t?.usefulness_rate??1)*100);return(0,a.jsxs)("article",{className:"rounded-lg border border-border bg-surface-2 px-3 py-3",children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-start gap-2",children:[(0,a.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,a.jsx)("span",{className:"font-mono text-sm text-fg",children:e.name}),(0,a.jsx)("span",{className:"rounded-full bg-surface-3 px-2 py-0.5 text-[11px] text-fg-faint border border-border",children:e.category??"Other"}),(0,a.jsx)("span",{className:"rounded-full bg-surface-3 px-2 py-0.5 text-[11px] text-fg-faint border border-border uppercase",children:e.source??"builtin"}),t?.never_used&&(0,a.jsx)("span",{className:"rounded-full border border-emerald-500/30 bg-emerald-500/10 px-2 py-0.5 text-[11px] text-emerald-700 dark:text-emerald-300",children:"new 100%"})]}),(0,a.jsx)("p",{className:"mt-1 text-xs text-fg-muted",children:e.description})]}),(0,a.jsxs)("div",{className:"rounded-lg border border-border bg-surface-1 px-3 py-2 text-right min-w-[120px]",children:[(0,a.jsxs)("div",{className:`text-lg font-semibold ${s>=75?"text-emerald-700 dark:text-emerald-300":"text-amber-700 dark:text-amber-300"}`,children:[s,"%"]}),(0,a.jsx)("div",{className:"text-[11px] text-fg-faint",children:"rank score"})]})]}),(0,a.jsxs)("div",{className:"mt-3 grid gap-2 sm:grid-cols-4",children:[(0,a.jsx)(sS,{label:"Calls",value:String(t?.call_count??0)}),(0,a.jsx)(sS,{label:"Success",value:`${r}%`}),(0,a.jsx)(sS,{label:"Used",value:`${n}%`}),(0,a.jsx)(sS,{label:"Errors",value:String(t?.error_count??0)})]})]},e.name)})]})]})]})}function sS({label:e,value:t}){return(0,a.jsxs)("div",{className:"rounded-md border border-border bg-surface-1 px-2.5 py-2",children:[(0,a.jsx)("div",{className:"text-[11px] text-fg-faint uppercase tracking-wide",children:e}),(0,a.jsx)("div",{className:"text-sm text-fg font-medium",children:t})]})}let s_={builtin:"Built-in",extensions:"Browser extension"};function sC(){let{state:e,dispatch:t}=(0,o.U)(),s="extensions"===e.selectedItem.tools?"extensions":"builtin";return(0,a.jsxs)("div",{className:"flex flex-col h-full min-h-0",children:[(0,a.jsx)("div",{role:"tablist","aria-label":"Tools sub-section",className:"flex gap-1 border-b border-[var(--border)] bg-[var(--bg-secondary)] px-3 pt-2",children:["builtin","extensions"].map(e=>{let r=e===s;return(0,a.jsx)("button",{role:"tab",type:"button","aria-selected":r,onClick:()=>t({type:"SET_SELECTION",tab:"tools",itemId:e}),className:"px-3 py-1.5 text-sm rounded-t-md border-b-2 -mb-px transition-colors "+(r?"border-[var(--accent)] text-[var(--text-primary)] bg-[var(--bg-primary)]":"border-transparent text-[var(--text-secondary)] hover:text-[var(--text-primary)]"),children:s_[e]},e)})}),(0,a.jsx)("div",{className:"flex-1 min-h-0 overflow-auto",children:"builtin"===s?(0,a.jsx)(sk,{}):(0,a.jsx)(sb,{})})]})}var sA=s(6844),sE=s(233),sT=s(6763),s$=s(6449),sz=s(4890);let sI={home:new Set(["llm","mail","calendar","chat","other"]),work:new Set(["llm","mail","calendar","issue-tracker","infrastructure","other"]),dev:null,custom:null};var sF=s(981),sL=s(1402);function sR(){let[e,t]=(0,i.useState)(null),[s,r]=(0,i.useState)(!0),[n,l]=(0,i.useState)(!1),[o,d]=(0,i.useState)(null),[u,x]=(0,i.useState)(null),[m,p]=(0,i.useState)("off"),[h,f]=(0,i.useState)("http"),[g,b]=(0,i.useState)(""),[j,y]=(0,i.useState)(""),[v,N]=(0,i.useState)(""),[w,k]=(0,i.useState)(""),[S,_]=(0,i.useState)(""),[C,A]=(0,i.useState)(null),[E,T]=(0,i.useState)(null),$=(0,i.useRef)(null),z=(0,i.useCallback)(e=>{var t;let s=e.config;p(s.mode),f(s.scheme),b(s.host??""),y(null!=s.port?String(s.port):""),N(s.username??""),k(s.password??""),_(s.no_proxy??""),A(s.ca_bundle??null),T(s.ca_bundle?`Saved CA bundle (${(t=s.ca_bundle.length)<1024?`${t} B`:t<1048576?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`})`:null)},[]),I=(0,i.useCallback)(async()=>{r(!0);try{let e=await c.FH.proxy.get();t(e),z(e)}catch(e){d(e instanceof Error?e.message:String(e))}finally{r(!1)}},[z]);async function F(){d(null),l(!0);try{let e=await c.FH.proxy.save({mode:m,scheme:h,host:g.trim()||null,port:j.trim()?Number.parseInt(j,10):null,username:v.trim()||null,password:w.length>0?w:null,no_proxy:S.trim()||null,ca_bundle:C&&C.length>0?C:null});t(e),z(e),x(e.applied??null)}catch(e){d(e instanceof Error?e.message:String(e))}finally{l(!1)}}async function L(){if(confirm("Clear saved proxy configuration?")){d(null);try{let e=await c.FH.proxy.clear();t(e),z(e),x(e.applied??null)}catch(e){d(e instanceof Error?e.message:String(e))}}}async function R(e){let t=e.target.files?.[0];if(t)try{let e=await t.text();if(!e.includes("-----BEGIN CERTIFICATE-----"))return void d(`${t.name} does not contain a PEM certificate (no BEGIN CERTIFICATE block).`);A(e),T(`Loaded: ${t.name}`),d(null)}catch(e){d(e instanceof Error?e.message:String(e))}finally{$.current&&($.current.value="")}}(0,i.useEffect)(()=>{I()},[I]);let H=e?.env_override??!1,P=e?.config.mode!=="off"&&e?.config.updated_at!=null;return(0,a.jsxs)("div",{className:"mb-3 rounded-lg border border-border bg-surface-2 overflow-hidden",children:[(0,a.jsxs)("div",{className:"px-3 py-2.5 border-b border-border/60 flex items-start gap-2",children:[(0,a.jsx)(tx.A,{size:14,className:"text-fg-subtle mt-0.5"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("h3",{className:"text-sm font-medium text-fg",children:"Network proxy"}),(0,a.jsx)("p",{className:"text-[11px] text-fg-faint mt-0.5 leading-snug",children:"HTTP proxy for outbound calls (LLM providers, MCP servers, integrations). Stored encrypted. Changes apply to new requests immediately; in-flight streams finish on the previous proxy."})]})]}),(0,a.jsxs)("div",{className:"px-3 py-3 space-y-2",children:[s&&(0,a.jsx)("p",{className:"text-fg-faint text-xs py-2",children:"Loading…"}),H&&(0,a.jsxs)("div",{className:"px-2 py-1.5 rounded bg-amber-950/30 border border-amber-800 text-[11px] text-amber-700 dark:text-amber-300",children:[(0,a.jsx)("code",{children:"HTTPS_PROXY"})," is set in the process environment. The in-app config is saved but not applied while the env var is present."]}),!s&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"block text-xs text-fg-subtle",children:["Mode",(0,a.jsxs)("select",{value:m,onChange:e=>p(e.target.value),className:"mt-1 w-full px-2 py-1.5 text-sm rounded border border-border bg-surface-3 text-fg",children:[(0,a.jsx)("option",{value:"off",children:"Off — direct connection"}),(0,a.jsx)("option",{value:"manual",children:"Manual — host / port below"}),(0,a.jsx)("option",{value:"system",children:"System (macOS) — import from scutil --proxy"})]})]}),"manual"===m&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"grid grid-cols-4 gap-2",children:[(0,a.jsxs)("label",{className:"col-span-2 block text-xs text-fg-subtle",children:["Host",(0,a.jsx)("input",{type:"text",value:g,onChange:e=>b(e.target.value),placeholder:"proxy.corp.example",className:"mt-1 w-full px-2 py-1.5 text-sm rounded border border-border bg-surface-3 text-fg font-mono"})]}),(0,a.jsxs)("label",{className:"block text-xs text-fg-subtle",children:["Port",(0,a.jsx)("input",{type:"number",value:j,onChange:e=>y(e.target.value),placeholder:"8080",className:"mt-1 w-full px-2 py-1.5 text-sm rounded border border-border bg-surface-3 text-fg font-mono"})]}),(0,a.jsxs)("label",{className:"block text-xs text-fg-subtle",children:["Scheme",(0,a.jsxs)("select",{value:h,onChange:e=>f(e.target.value),className:"mt-1 w-full px-2 py-1.5 text-sm rounded border border-border bg-surface-3 text-fg",children:[(0,a.jsx)("option",{value:"http",children:"http"}),(0,a.jsx)("option",{value:"https",children:"https"})]})]})]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,a.jsxs)("label",{className:"block text-xs text-fg-subtle",children:["Username (optional)",(0,a.jsx)("input",{type:"text",value:v,onChange:e=>N(e.target.value),placeholder:"",className:"mt-1 w-full px-2 py-1.5 text-sm rounded border border-border bg-surface-3 text-fg font-mono"})]}),(0,a.jsxs)("label",{className:"block text-xs text-fg-subtle",children:["Password (optional)",(0,a.jsx)("input",{type:"password",value:w,onChange:e=>k(e.target.value),onFocus:e=>{"********"===e.target.value&&k("")},placeholder:"",className:"mt-1 w-full px-2 py-1.5 text-sm rounded border border-border bg-surface-3 text-fg font-mono"})]})]})]}),"off"!==m&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"block text-xs text-fg-subtle",children:["No proxy (comma-separated, optional)",(0,a.jsx)("input",{type:"text",value:S,onChange:e=>_(e.target.value),placeholder:"localhost,127.0.0.1,.internal",className:"mt-1 w-full px-2 py-1.5 text-sm rounded border border-border bg-surface-3 text-fg font-mono"})]}),"system"!==m&&(0,a.jsxs)("div",{className:"block text-xs text-fg-subtle",children:["CA bundle (optional — for proxies that intercept TLS with an internal CA)",(0,a.jsxs)("div",{className:"mt-1 flex items-center gap-2 flex-wrap",children:[(0,a.jsx)("input",{ref:$,type:"file",accept:".pem,.crt,.cer,.cert,application/x-x509-ca-cert,application/x-pem-file",onChange:R,className:"text-[11px] text-fg-faint file:mr-2 file:px-2 file:py-1 file:rounded file:border-0 file:bg-surface-3 file:text-fg file:text-[11px] file:cursor-pointer"}),E&&(0,a.jsxs)("span",{className:"inline-flex items-center gap-2 text-[11px] text-fg-muted",children:[(0,a.jsx)("code",{className:"text-fg",children:E}),(0,a.jsx)("button",{onClick:function(){A(null),T(null),$.current&&($.current.value="")},className:"text-rose-700 dark:text-rose-400 hover:underline",children:"remove"})]})]})]}),"system"===m&&(0,a.jsx)("p",{className:"text-[11px] text-fg-faint leading-snug",children:"Trust store comes from the macOS keychain (System + login). MDM-pushed corporate roots are picked up automatically. Use “Refresh trust store” after a cert rotation."})]}),o&&(0,a.jsx)("div",{className:"px-2 py-1.5 rounded bg-rose-950/40 border border-rose-800 text-xs text-rose-700 dark:text-rose-300",children:o}),u&&(0,a.jsxs)("div",{className:"px-2 py-1.5 rounded bg-surface-3 border border-border text-[11px] text-fg-muted",children:["Applied: ",(0,a.jsx)("code",{className:"text-fg",children:u.source}),u.proxyUrl&&(0,a.jsxs)(a.Fragment,{children:[" → ",(0,a.jsx)("code",{className:"text-fg",children:u.proxyUrl})]}),u.note&&(0,a.jsxs)("span",{className:"text-fg-faint",children:[" — ",u.note]})]}),u?.caBundlePath&&(0,a.jsxs)("div",{className:"px-2 py-1.5 rounded bg-emerald-950/30 border border-emerald-800 text-[11px] text-emerald-700 dark:text-emerald-300 inline-flex items-start gap-1.5",children:[(0,a.jsx)(sF.A,{size:12,className:"mt-0.5 shrink-0"}),(0,a.jsxs)("span",{children:["System trust: ",(0,a.jsx)("strong",{children:u.caBundleCertCount})," certs from the macOS keychain →"," ",(0,a.jsx)("code",{className:"text-emerald-700 dark:text-emerald-200",children:u.caBundlePath})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 pt-1",children:[(0,a.jsxs)("button",{onClick:F,disabled:n,className:"inline-flex items-center gap-1 px-3 py-1.5 text-xs rounded bg-accent text-white hover:bg-accent-hover disabled:opacity-50",children:[n?(0,a.jsx)(ec.A,{size:11,className:"animate-spin"}):(0,a.jsx)(sL.A,{size:11}),n?"Saving…":"Save & apply"]}),"system"===m&&(0,a.jsxs)("button",{onClick:F,disabled:n,className:"inline-flex items-center gap-1 px-2 py-1.5 text-xs rounded border border-border text-fg-muted hover:text-fg disabled:opacity-50",title:"Re-extract the macOS keychain trust store",children:[(0,a.jsx)(tI.A,{size:11})," Refresh trust store"]}),P&&(0,a.jsxs)("button",{onClick:L,className:"ml-auto inline-flex items-center gap-1 px-2 py-1.5 text-xs text-fg-faint hover:text-rose-700 dark:hover:text-rose-400",title:"Clear saved proxy configuration",children:[(0,a.jsx)(eQ.A,{size:11})," Clear"]})]})]})]})]})}let sH=(e,t)=>`${e}:${t}`;function sP({onClose:e,onSaved:t}){let[s,r]=(0,i.useState)(null),[n,l]=(0,i.useState)({}),[o,d]=(0,i.useState)(null),[u,x]=(0,i.useState)(null);async function m(e){let s=sH(e.integration,e.field),a=n[s].split(",").map(e=>e.trim()).filter(Boolean);d(s),x(null);try{let n=await c.FH.envSync.allowlist.set(e.integration,e.field,a);r(n),l(e=>({...e,[s]:(n.overrides[s]??[]).join(", ")})),t()}catch(e){x(e instanceof Error?e.message:String(e))}finally{d(null)}}return(0,i.useEffect)(()=>{c.FH.envSync.allowlist.get().then(e=>{r(e);let t={};for(let s of e.defaults)t[sH(s.integration,s.field)]=(e.overrides[sH(s.integration,s.field)]??[]).join(", ");l(t)}).catch(e=>x(e instanceof Error?e.message:String(e)))},[]),(0,a.jsxs)("div",{className:"mb-3 px-3 py-3 rounded border border-border bg-surface-2 text-[11px]",children:[(0,a.jsxs)("div",{className:"flex items-start gap-2 mb-2",children:[(0,a.jsx)("span",{className:"font-semibold text-fg flex-1",children:"Env-sync aliases"}),(0,a.jsx)("button",{onClick:e,className:"text-fg-faint hover:text-fg","aria-label":"Close alias editor",children:(0,a.jsx)(z.A,{size:12})})]}),(0,a.jsx)("p",{className:"text-fg-faint mb-3",children:"Default names are always checked. Add your own aliases (comma-separated) per row when your dotfile uses a different name."}),u&&(0,a.jsx)("div",{className:"mb-2 px-2 py-1 rounded border border-border bg-surface-3 text-fg",children:u}),null===s?(0,a.jsx)("p",{className:"text-fg-faint",children:"Loading…"}):(0,a.jsx)("div",{className:"flex flex-col gap-2",children:s.defaults.map(e=>{let t=sH(e.integration,e.field);return(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,a.jsxs)("span",{className:"text-fg-muted min-w-[120px]",children:[e.integration,".",e.field]}),(0,a.jsx)("span",{className:"flex flex-wrap gap-1",children:e.envVars.map(e=>(0,a.jsx)("span",{className:"px-1.5 py-0.5 rounded bg-surface-3 text-fg-faint border border-border",children:e},e))}),(0,a.jsx)("input",{type:"text",value:n[t]??"",onChange:e=>l(s=>({...s,[t]:e.target.value})),placeholder:"MY_OTHER_NAME, SOMETHING_ELSE",className:"flex-1 min-w-[160px] px-2 py-1 rounded border border-border bg-surface text-fg"}),(0,a.jsxs)("button",{onClick:()=>m(e),disabled:o===t,className:"inline-flex items-center gap-1 px-2 py-1 rounded border border-border text-fg-muted hover:bg-surface-3 disabled:opacity-50",children:[o===t?(0,a.jsx)(ec.A,{size:11,className:"animate-spin"}):(0,a.jsx)(sL.A,{size:11}),"Save"]})]},t)})})]})}let sO={home:"Home",work:"Work",dev:"Developer",custom:"Everything"};function sM(){let{dispatch:e}=(0,o.U)(),[t,s]=(0,i.useState)([]),[r,n]=(0,i.useState)({}),[l,d]=(0,i.useState)(!0),[u,x]=(0,i.useState)(!1),[m,p]=(0,i.useState)(null),[h,f]=(0,i.useState)(!1),[g,b]=(0,i.useState)(null),j=(0,i.useRef)(null);async function y(){d(!0);try{let[e,t]=await Promise.all([c.FH.integrations.list(),c.FH.profile.get().catch(()=>null)]);s(e.definitions),n(Object.fromEntries(e.statuses.map(e=>[e.name,e]))),b(t?.preset??null)}catch(e){console.error(e)}finally{d(!1)}}eX("connections","integration",j),(0,i.useEffect)(()=>{y()},[]);let v=(0,i.useMemo)(()=>{if(!g)return t;let e=sI[g];return null===e?t:t.filter(t=>!!(!t.category||e.has(t.category))||r[t.name]?.configured===!0)},[t,g,r]),N=t.length-v.length;async function w(){x(!0),p(null);try{let e=await c.FH.envSync.apply(),t="shell-rc"===e.discovered.source?`your ${e.discovered.shell??"shell"} rc`:"windows-registry"===e.discovered.source?"your Windows User env":"the process env";if(e.applied_count>0)p(`Synced ${e.applied_count} field(s) from ${t}.`);else{let s=e.candidates.filter(e=>"skipped-user"===e.action).length,a=e.candidates.filter(e=>"skipped-equal"===e.action).length,r=e.candidates.filter(e=>"absent"===e.action).length;s>0?p(`Nothing to write — ${s} field(s) were edited here and won't be overwritten.`):a>0&&r===e.candidates.length-a?p(`Already up to date with ${t}.`):p(`No matching env vars set in ${t}.`)}await y()}catch(e){p(e instanceof Error?e.message:String(e))}finally{x(!1)}}return(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[(0,a.jsxs)("div",{className:"border-b border-border px-4 py-3 flex items-center gap-2",children:[(0,a.jsx)(sA.A,{size:14,className:"text-fg-subtle"}),(0,a.jsx)("h2",{className:"text-sm font-semibold text-fg mr-auto",children:"Credentials"}),g&&"custom"!==g&&(0,a.jsxs)("button",{type:"button",onClick:()=>e({type:"SET_TAB",tab:"profile"}),title:`Filtered to "${sO[g]}" preset. Click to change in Profile.`,className:"inline-flex items-center gap-1 px-2 py-1 text-[11px] rounded-full border border-border bg-surface-2 text-fg-muted hover:bg-surface-3",children:[(0,a.jsx)(sE.A,{size:11}),(0,a.jsx)("span",{children:sO[g]}),N>0&&(0,a.jsxs)("span",{className:"text-fg-faint",children:["\xb7 ",N," hidden"]})]}),(0,a.jsxs)("button",{onClick:()=>f(e=>!e),title:"Add additional env-var name aliases that env-sync should look for, per integration field.",className:"inline-flex items-center gap-1 px-2 py-1 text-[11px] rounded border border-border text-fg-muted hover:bg-surface-3",children:[(0,a.jsx)(sT.A,{size:11}),"Aliases"]}),(0,a.jsxs)("button",{onClick:w,disabled:u,title:"Pull standard credential env vars (GITHUB_TOKEN, ATLASSIAN_API_TOKEN, …) from your shell rc / Windows User env. Fields you've edited here are never overwritten.",className:"inline-flex items-center gap-1 px-2 py-1 text-[11px] rounded border border-border text-fg-muted hover:bg-surface-3 disabled:opacity-50",children:[u?(0,a.jsx)(ec.A,{size:11,className:"animate-spin"}):(0,a.jsx)(tI.A,{size:11}),"Sync from environment"]})]}),(0,a.jsxs)("div",{ref:j,className:"flex-1 overflow-y-auto px-4 py-3",children:[m&&(0,a.jsxs)("div",{className:"mb-3 px-3 py-2 rounded border border-border bg-surface-2 text-[11px] text-fg-muted flex items-start gap-2",children:[(0,a.jsx)(s$.A,{size:12,className:"mt-0.5 text-fg-subtle shrink-0"}),(0,a.jsx)("span",{className:"flex-1",children:m}),(0,a.jsx)("button",{onClick:()=>p(null),className:"text-fg-faint hover:text-fg",children:(0,a.jsx)(sz.A,{size:12})})]}),h&&(0,a.jsx)(sP,{onClose:()=>f(!1),onSaved:()=>{}}),(0,a.jsx)(sR,{}),l&&0===t.length&&(0,a.jsx)("p",{className:"text-fg-faint text-sm py-6 text-center",children:"Loading…"}),!l&&0===t.length&&(0,a.jsx)("p",{className:"text-fg-faint text-sm py-6 text-center",children:"No integrations available."}),v.map(e=>(0,a.jsx)(sD,{definition:e,status:r[e.name],onChanged:y},e.name))]})]})}function sD({definition:e,status:t,onChanged:s}){let[r,n]=(0,i.useState)(()=>({...t?.values??{}})),[l,o]=(0,i.useState)(!1),[d,u]=(0,i.useState)(!1),[x,m]=(0,i.useState)(null),[p,h]=(0,i.useState)(null),[f,g]=(0,i.useState)(!1),b=(0,i.useRef)(null),j=(0,i.useRef)(null);async function y(e){h(null),m(null);let a=r.client_id?.trim(),n=r.client_secret?.trim();if(!t?.configured&&(!a||!n))return void h("Enter the OAuth client ID and client secret first.");g(!0);try{let t="gmail"===e?c.FH.integrations.gmailOauthStart:c.FH.integrations.outlookOauthStart,r="gmail"===e?c.FH.integrations.gmailOauthStatus:c.FH.integrations.outlookOauthStatus,l="gmail"===e?"Gmail":"Outlook",i=await t({client_id:a,client_secret:n});if(b.current=window.open(i.authorize_url,`jarela-${e}-oauth`,"width=560,height=720"),!b.current){h("Browser blocked the OAuth popup. Allow popups for this site and retry."),g(!1);return}let o=Date.now();j.current&&clearInterval(j.current),j.current=setInterval(async()=>{if(Date.now()-o>6e5){j.current&&clearInterval(j.current),g(!1),h("Timed out waiting for authorization.");return}try{let e=await r(i.state);if("done"===e.status){j.current&&clearInterval(j.current),g(!1),m({ok:!0,message:`Connected to ${l}. Refresh token saved.`});try{b.current?.close()}catch{}s()}else"error"===e.status?(j.current&&clearInterval(j.current),g(!1),h(e.error??"Authorization failed.")):"unknown"===e.status&&(j.current&&clearInterval(j.current),g(!1),h("Authorization session expired."))}catch(e){j.current&&clearInterval(j.current),g(!1),h(e instanceof Error?e.message:String(e))}},1500)}catch(e){g(!1),h(e instanceof Error?e.message:String(e))}}async function v(){h(null),o(!0);try{let t=await c.FH.integrations.save(e.name,r);m(null),n({...t.values}),s()}catch(e){h(e instanceof Error?e.message:String(e))}finally{o(!1)}}async function N(){u(!0),m(null);try{let t=await c.FH.integrations.test(e.name);if(t.ok){let e=t.detail;m({ok:!0,message:e?.displayName?`Connected as ${e.displayName}`:"Connection ok"})}else m({ok:!1,message:t.error??"Test failed"})}catch(e){m({ok:!1,message:e instanceof Error?e.message:String(e)})}finally{u(!1)}}async function w(){confirm(`Remove saved credentials for ${e.label}?`)&&(await c.FH.integrations.delete(e.name),n({}),m(null),s())}(0,i.useEffect)(()=>()=>{j.current&&clearInterval(j.current)},[]),(0,i.useEffect)(()=>{n({...t?.values??{}})},[t?.updated_at]);let k=t?.configured;return(0,a.jsxs)("div",{"data-deep-link-id":e.name,className:"mb-3 rounded-lg border border-border bg-surface-2 overflow-hidden",children:[(0,a.jsxs)("div",{className:"px-3 py-2.5 border-b border-border/60 flex items-start gap-2",children:[(0,a.jsx)("div",{className:`w-1.5 h-1.5 rounded-full mt-1.5 ${k?"bg-emerald-500":"bg-fg-faint"}`}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("h3",{className:"text-sm font-medium text-fg",children:e.label}),(0,a.jsx)("p",{className:"text-[11px] text-fg-faint mt-0.5 leading-snug",children:e.description})]})]}),(0,a.jsxs)("div",{className:"px-3 py-3 space-y-2",children:["gmail"===e.name&&(0,a.jsx)(sU,{}),"outlook"===e.name&&(0,a.jsx)(sG,{}),e.fields.map(e=>{let s=t?.source?.[e.key];return(0,a.jsxs)("label",{className:"block text-xs text-fg-subtle",children:[(0,a.jsxs)("span",{className:"flex items-center gap-1.5",children:[e.label,e.required&&(0,a.jsx)("span",{className:"text-rose-700 dark:text-rose-400 ml-0.5",children:"*"}),"rc"===s&&(0,a.jsxs)("span",{title:"Value pulled from your shell rc / Windows User env. Editing here will switch this field to manual mode.",className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[9px] font-medium uppercase tracking-wide bg-sky-500/10 text-sky-700 dark:text-sky-300 border border-sky-500/30",children:[(0,a.jsx)(s$.A,{size:9})," from shell"]})]}),(0,a.jsx)("input",{type:e.secret?"password":"text",value:r[e.key]??"",onChange:t=>n(s=>({...s,[e.key]:t.target.value})),onFocus:t=>{e.secret&&"********"===t.target.value&&n(t=>({...t,[e.key]:""}))},placeholder:e.placeholder,className:"mt-1 w-full px-2 py-1.5 text-sm rounded border border-border bg-surface-3 text-fg font-mono"})]},e.key)}),p&&(0,a.jsx)("div",{className:"px-2 py-1.5 rounded bg-rose-950/40 border border-rose-800 text-xs text-rose-700 dark:text-rose-300",children:p}),x&&(0,a.jsxs)("div",{className:`px-2 py-1.5 rounded border text-xs flex items-center gap-1.5 ${x.ok?"bg-emerald-950/30 border-emerald-800 text-emerald-700 dark:text-emerald-300":"bg-rose-950/30 border-rose-800 text-rose-700 dark:text-rose-300"}`,children:[x.ok?(0,a.jsx)(so.A,{size:12}):(0,a.jsx)(sz.A,{size:12}),(0,a.jsx)("span",{className:"truncate",children:x.message})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 pt-1",children:[(0,a.jsx)("button",{onClick:v,disabled:l,className:"px-3 py-1.5 text-xs rounded bg-accent text-white hover:bg-accent-hover disabled:opacity-50",children:l?"Saving…":"Save"}),(0,a.jsxs)("button",{onClick:N,disabled:d||!k,title:k?"Test the connection":"Save credentials first",className:"inline-flex items-center gap-1 px-3 py-1.5 text-xs rounded border border-border text-fg-muted hover:bg-surface-3 disabled:opacity-40 disabled:cursor-not-allowed",children:[d?(0,a.jsx)(ec.A,{size:11,className:"animate-spin"}):(0,a.jsx)(sd.A,{size:11}),"Test"]}),"gmail"===e.name&&(0,a.jsxs)("button",{onClick:()=>y("gmail"),disabled:f,title:"Authorize Gmail + Calendar via Google OAuth — opens a browser window",className:"inline-flex items-center gap-1 px-3 py-1.5 text-xs rounded border border-border text-fg-muted hover:bg-surface-3 disabled:opacity-40 disabled:cursor-not-allowed",children:[f?(0,a.jsx)(ec.A,{size:11,className:"animate-spin"}):(0,a.jsx)(es.A,{size:11}),f?"Waiting…":"Connect Gmail"]}),"outlook"===e.name&&(0,a.jsxs)("button",{onClick:()=>y("outlook"),disabled:f,title:"Authorize Outlook + Calendar via Microsoft OAuth — opens a browser window",className:"inline-flex items-center gap-1 px-3 py-1.5 text-xs rounded border border-border text-fg-muted hover:bg-surface-3 disabled:opacity-40 disabled:cursor-not-allowed",children:[f?(0,a.jsx)(ec.A,{size:11,className:"animate-spin"}):(0,a.jsx)(es.A,{size:11}),f?"Waiting…":"Connect Outlook"]}),k&&(0,a.jsxs)("button",{onClick:w,className:"ml-auto inline-flex items-center gap-1 px-2 py-1.5 text-xs text-fg-faint hover:text-rose-700 dark:hover:text-rose-400",title:"Remove saved credentials",children:[(0,a.jsx)(eQ.A,{size:11})," Clear"]})]})]})]})}function sU(){return(0,a.jsxs)("details",{className:"rounded border border-border/60 bg-surface-3/40 text-xs text-fg-muted",children:[(0,a.jsx)("summary",{className:"cursor-pointer select-none px-2.5 py-1.5 text-fg hover:bg-surface-3",children:"Setup guide (first-time only)"}),(0,a.jsxs)("div",{className:"px-3 py-2.5 space-y-3 border-t border-border/60 leading-relaxed",children:[(0,a.jsxs)("p",{className:"text-amber-700 dark:text-amber-300/90 text-[11px] border border-amber-400/30 bg-amber-400/5 rounded px-2 py-1.5",children:[(0,a.jsx)("strong",{children:"Upgrading from an earlier version?"})," Click ",(0,a.jsx)("strong",{children:"Connect Gmail"}),"again so Google can grant the new Calendar scope — otherwise calendar tools will fail with a 403."]}),(0,a.jsxs)("p",{className:"text-fg-subtle",children:["You only need to do this once per Google account. The end result is a ",(0,a.jsx)("code",{className:"text-fg",children:"client_id"}),","," ",(0,a.jsx)("code",{className:"text-fg",children:"client_secret"})," pair you paste below. Then click"," ",(0,a.jsx)("strong",{className:"text-fg",children:"Connect Gmail"})," to authorize Gmail + Calendar access."]}),(0,a.jsxs)(sJ,{n:1,title:"Create or pick a Google Cloud project",children:["Open ",(0,a.jsx)(sq,{href:"https://console.cloud.google.com/projectcreate",children:"console.cloud.google.com/projectcreate"})," ","and create a project (any name). If you already have one, just select it in the top bar."]}),(0,a.jsxs)(sJ,{n:2,title:"Enable the Gmail and Calendar APIs",children:["Enable ",(0,a.jsx)(sq,{href:"https://console.cloud.google.com/apis/library/gmail.googleapis.com",children:"Gmail API"})," ",(0,a.jsx)("strong",{children:"and"})," ",(0,a.jsx)(sq,{href:"https://console.cloud.google.com/apis/library/calendar-json.googleapis.com",children:"Google Calendar API"}),". Click ",(0,a.jsx)("strong",{children:"Enable"})," on each and wait a few seconds for them to activate."]}),(0,a.jsxs)(sJ,{n:3,title:"Configure the OAuth consent screen",children:["Go to ",(0,a.jsx)(sq,{href:"https://console.cloud.google.com/auth/branding",children:"Auth Platform → Branding"}),". Set ",(0,a.jsx)("strong",{children:"User type: External"}),", fill in an app name and your email, save. Then in ",(0,a.jsx)(sq,{href:"https://console.cloud.google.com/auth/scopes",children:"Data Access → Scopes"})," ","click ",(0,a.jsx)("strong",{children:"Add or remove scopes"})," and add all three:",(0,a.jsxs)("ul",{className:"list-disc ml-5 mt-1 text-fg-subtle",children:[(0,a.jsx)("li",{children:(0,a.jsx)("code",{className:"text-fg",children:".../auth/gmail.modify"})}),(0,a.jsx)("li",{children:(0,a.jsx)("code",{className:"text-fg",children:".../auth/gmail.compose"})}),(0,a.jsx)("li",{children:(0,a.jsx)("code",{className:"text-fg",children:".../auth/calendar.events"})}),(0,a.jsx)("li",{children:(0,a.jsx)("code",{className:"text-fg",children:".../auth/calendar.readonly"})})]}),"Finally, in ",(0,a.jsx)(sq,{href:"https://console.cloud.google.com/auth/audience",children:"Audience"})," ","add your own Gmail address as a ",(0,a.jsx)("strong",{children:"Test user"}),". (Leaving the app in Testing mode is fine — you don't need to publish or verify it for personal use.)"]}),(0,a.jsxs)(sJ,{n:4,title:"Create the OAuth client (Desktop type)",children:["Go to ",(0,a.jsx)(sq,{href:"https://console.cloud.google.com/auth/clients",children:"Clients"})," →"," ",(0,a.jsx)("strong",{children:"Create client"}),".",(0,a.jsxs)("ul",{className:"list-disc ml-5 mt-1 text-fg-subtle",children:[(0,a.jsxs)("li",{children:[(0,a.jsx)("strong",{children:"Application type:"})," ",(0,a.jsx)("span",{className:"text-fg",children:"Desktop app"})," ","(this matters — Web app types require pre-registering redirect URIs and will fail with",(0,a.jsx)("code",{className:"text-fg",children:" redirect_uri_mismatch"}),")."]}),(0,a.jsxs)("li",{children:[(0,a.jsx)("strong",{children:"Name:"})," anything, e.g. ",(0,a.jsx)("code",{className:"text-fg",children:"Jarela"}),"."]})]}),"After it's created, copy the ",(0,a.jsx)("strong",{children:"Client ID"})," and ",(0,a.jsx)("strong",{children:"Client secret"})," ","shown in the popup (or click the download icon to get the JSON — the values are under"," ",(0,a.jsx)("code",{className:"text-fg",children:"installed.client_id"})," /"," ",(0,a.jsx)("code",{className:"text-fg",children:"installed.client_secret"}),")."]}),(0,a.jsxs)(sJ,{n:5,title:"Paste and connect",children:["Paste them into the two fields below, click ",(0,a.jsx)("strong",{children:"Save"}),", then"," ",(0,a.jsx)("strong",{children:"Connect Gmail"}),". A Google consent window opens — approve it and the tab will close itself. Hit ",(0,a.jsx)("strong",{children:"Test"})," to confirm."]}),(0,a.jsxs)("div",{className:"mt-2 pt-2 border-t border-border/60 text-[11px] text-fg-faint",children:[(0,a.jsx)("strong",{className:"text-fg-subtle",children:"Troubleshooting:"}),(0,a.jsxs)("ul",{className:"list-disc ml-5 mt-1 space-y-0.5",children:[(0,a.jsxs)("li",{children:[(0,a.jsx)("code",{children:"redirect_uri_mismatch"})," → your client is a ",(0,a.jsx)("em",{children:"Web"})," app. Create a fresh one as ",(0,a.jsx)("em",{children:"Desktop app"})," instead, or add"," ",(0,a.jsx)("code",{className:"text-fg-muted",children:"http://localhost:4312/api/v1/integrations/gmail/oauth/callback"})," ","to its Authorized redirect URIs."]}),(0,a.jsxs)("li",{children:[(0,a.jsx)("code",{children:"access_denied"}),"→ your Gmail address isn't in the Test users list (step 3, last paragraph)."]}),(0,a.jsxs)("li",{children:['"Google did not return a refresh_token" → you previously authorized this client. Revoke it at'," ",(0,a.jsx)(sq,{href:"https://myaccount.google.com/permissions",children:"myaccount.google.com/permissions"})," ","and click Connect Gmail again."]}),(0,a.jsx)("li",{children:"Token works for ~6 months of inactivity, then Google may revoke it. Just click Connect Gmail again to refresh."})]})]})]})]})}function sJ({n:e,title:t,children:s}){return(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)("div",{className:"flex-none w-5 h-5 rounded-full bg-surface-3 border border-border text-[10px] text-fg-muted flex items-center justify-center font-mono",children:e}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("div",{className:"text-fg font-medium",children:t}),(0,a.jsx)("div",{className:"text-fg-subtle mt-0.5",children:s})]})]})}function sq({href:e,children:t}){return(0,a.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"text-sky-700 dark:text-sky-400 hover:text-sky-700 dark:hover:text-sky-300 underline decoration-dotted underline-offset-2",children:t})}function sG(){return(0,a.jsxs)("details",{className:"rounded border border-border/60 bg-surface-3/40 text-xs text-fg-muted",children:[(0,a.jsx)("summary",{className:"cursor-pointer select-none px-2.5 py-1.5 text-fg hover:bg-surface-3",children:"Setup guide (first-time only)"}),(0,a.jsxs)("div",{className:"px-3 py-2.5 space-y-3 border-t border-border/60 leading-relaxed",children:[(0,a.jsxs)("p",{className:"text-fg-subtle",children:["You only need to do this once per Microsoft account. The end result is an"," ",(0,a.jsx)("code",{className:"text-fg",children:"Application (client) ID"})," +"," ",(0,a.jsx)("code",{className:"text-fg",children:"client secret value"})," pair you paste below. Then click"," ",(0,a.jsx)("strong",{className:"text-fg",children:"Connect Outlook"}),"to authorize Mail + Calendar access. Free — no Azure subscription required."]}),(0,a.jsxs)(sJ,{n:1,title:"Sign in to the Azure portal",children:["Open ",(0,a.jsx)(sq,{href:"https://portal.azure.com",children:"portal.azure.com"})," with the Microsoft account whose Outlook data you want to access. If a banner asks you to start a free Azure subscription, ",(0,a.jsx)("strong",{children:"skip it"}),"— app registrations live under the free identity tier."]}),(0,a.jsxs)(sJ,{n:2,title:"Create the app registration",children:["Open ",(0,a.jsx)(sq,{href:"https://entra.microsoft.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade",children:"Microsoft Entra → App registrations"})," ","(or the same blade in the ",(0,a.jsx)(sq,{href:"https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade",children:"Azure portal"}),"), then click ",(0,a.jsx)("strong",{children:"+ New registration"})," in the toolbar.",(0,a.jsxs)("ul",{className:"list-disc ml-5 mt-1 text-fg-subtle",children:[(0,a.jsxs)("li",{children:[(0,a.jsx)("strong",{children:"Name:"})," anything, e.g. ",(0,a.jsx)("code",{className:"text-fg",children:"Jarela"}),"."]}),(0,a.jsxs)("li",{children:[(0,a.jsx)("strong",{children:"Supported account types:"})," ",(0,a.jsx)("span",{className:"text-fg",children:"Accounts in any organizational directory (Any Microsoft Entra ID tenant - Multitenant) and personal Microsoft accounts"})," ","— this is the broadest option and works for both ",(0,a.jsx)("code",{children:"@outlook.com"})," and work/school accounts."]}),(0,a.jsxs)("li",{children:[(0,a.jsx)("strong",{children:"Redirect URI:"})," select ",(0,a.jsx)("strong",{children:"Web"})," and paste"," ",(0,a.jsxs)("code",{className:"text-fg",children:[window.location.origin,"/api/v1/integrations/outlook/oauth/callback"]}),"."," ","Microsoft will reject the auth flow with ",(0,a.jsx)("code",{children:"redirect_uri_mismatch"}),"if this doesn't match exactly."]})]}),"Click ",(0,a.jsx)("strong",{children:"Register"}),". Copy the ",(0,a.jsx)("strong",{children:"Application (client) ID"})," from the overview page."]}),(0,a.jsxs)(sJ,{n:3,title:"Create a client secret",children:["On the app's page, open ",(0,a.jsx)("strong",{children:"Certificates & secrets"})," →"," ",(0,a.jsx)("strong",{children:"Client secrets"})," → ",(0,a.jsx)("strong",{children:"New client secret"}),". Pick a description and expiration (24 months is reasonable). Click ",(0,a.jsx)("strong",{children:"Add"}),"."," ",(0,a.jsx)("strong",{className:"text-fg",children:'Immediately copy the "Value" column'})," ",'— it\'s only shown once. (The "Secret ID" column is NOT the secret; ignore it.)']}),(0,a.jsxs)(sJ,{n:4,title:"Add API permissions",children:["Open ",(0,a.jsx)("strong",{children:"API permissions"})," → ",(0,a.jsx)("strong",{children:"Add a permission"})," →"," ",(0,a.jsx)("strong",{children:"Microsoft Graph"})," → ",(0,a.jsx)("strong",{children:"Delegated permissions"}),". Tick all four:",(0,a.jsxs)("ul",{className:"list-disc ml-5 mt-1 text-fg-subtle",children:[(0,a.jsxs)("li",{children:[(0,a.jsx)("code",{className:"text-fg",children:"offline_access"})," — required for refresh tokens."]}),(0,a.jsxs)("li",{children:[(0,a.jsx)("code",{className:"text-fg",children:"User.Read"})," — basic profile for the Test button."]}),(0,a.jsxs)("li",{children:[(0,a.jsx)("code",{className:"text-fg",children:"Mail.ReadWrite"})," — search/read/draft/move mail."]}),(0,a.jsxs)("li",{children:[(0,a.jsx)("code",{className:"text-fg",children:"Calendars.ReadWrite"})," — manage calendar events."]})]}),"Click ",(0,a.jsx)("strong",{children:"Add permissions"}),". Personal accounts grant these themselves at the consent screen. Work/school accounts may require admin consent — if you're not the tenant admin, ask IT."]}),(0,a.jsxs)(sJ,{n:5,title:"Paste and connect",children:["Paste the ",(0,a.jsx)("strong",{children:"Application (client) ID"})," and the secret ",(0,a.jsx)("strong",{children:"Value"})," ","from step 3 into the two fields below, click ",(0,a.jsx)("strong",{children:"Save"}),", then"," ",(0,a.jsx)("strong",{children:"Connect Outlook"}),". A Microsoft consent window opens — approve it and the tab will close itself. Hit ",(0,a.jsx)("strong",{children:"Test"})," to confirm."]}),(0,a.jsxs)("div",{className:"mt-2 pt-2 border-t border-border/60 text-[11px] text-fg-faint",children:[(0,a.jsx)("strong",{className:"text-fg-subtle",children:"Troubleshooting:"}),(0,a.jsxs)("ul",{className:"list-disc ml-5 mt-1 space-y-0.5",children:[(0,a.jsxs)("li",{children:[(0,a.jsx)("code",{children:"redirect_uri_mismatch"})," / ",(0,a.jsx)("code",{children:"AADSTS50011"}),"→ the redirect URI on your Azure app doesn't exactly match the one Jarela sent. Compare character-for-character (trailing slash, http vs https, port)."]}),(0,a.jsxs)("li",{children:[(0,a.jsx)("code",{children:"invalid_client"})," / ",(0,a.jsx)("code",{children:"AADSTS7000215"}),"→ you pasted the Secret ID instead of the Secret Value. Regenerate the secret and copy the Value column."]}),(0,a.jsxs)("li",{children:[(0,a.jsx)("code",{children:"AADSTS65001"}),"→ admin consent required. For work/school accounts ask your IT admin to grant tenant consent on your app."]}),(0,a.jsxs)("li",{children:[(0,a.jsx)("code",{children:"AADSTS900144"})," → missing scope on the token call. Update Jarela."]}),(0,a.jsx)("li",{children:"Tokens are tied to the client secret's expiration. When the secret expires, create a new one in Azure and reconnect."})]})]})]})]})}let sW={builtin:"Built-in integrations",mcp:"MCP servers"};function sB(){let{state:e,dispatch:t}=(0,o.U)(),s="mcp"===e.selectedItem.connections?"mcp":"builtin";return(0,a.jsxs)("div",{className:"flex flex-col h-full min-h-0",children:[(0,a.jsx)("div",{role:"tablist","aria-label":"Connections sub-section",className:"flex gap-1 border-b border-[var(--border)] bg-[var(--bg-secondary)] px-3 pt-2",children:["builtin","mcp"].map(e=>{let r=e===s;return(0,a.jsx)("button",{role:"tab",type:"button","aria-selected":r,onClick:()=>t({type:"SET_SELECTION",tab:"connections",itemId:e}),className:"px-3 py-1.5 text-sm rounded-t-md border-b-2 -mb-px transition-colors "+(r?"border-[var(--accent)] text-[var(--text-primary)] bg-[var(--bg-primary)]":"border-transparent text-[var(--text-secondary)] hover:text-[var(--text-primary)]"),children:sW[e]},e)})}),(0,a.jsx)("div",{className:"flex-1 min-h-0 overflow-auto",children:"builtin"===s?(0,a.jsx)(sM,{}):(0,a.jsx)(sx,{})})]})}var sV=s(4539),sK=s(8912),sY=s(966),sQ=s(5298);function sZ({active:e,onClick:t,disabled:s,title:r,children:n}){return(0,a.jsx)("button",{type:"button",onClick:t,disabled:s,title:r,className:"px-2 py-0.5 text-[10px] rounded border transition-colors disabled:opacity-50 "+(e?"border-fg-muted bg-surface-3 text-fg":"border-border text-fg-faint hover:text-fg hover:border-fg-muted"),children:n})}function sX({initialScript:e,initialArgs:t,onSave:s,errorContext:r,diffContext:n}){let[l,o]=(0,i.useState)(null),d=(0,i.useMemo)(()=>{if(null==t)return"";try{return JSON.stringify(t,null,2)}catch{return""}},[t]),[u,x]=(0,i.useState)(e??""),[m,p]=(0,i.useState)(d),[h,f]=(0,i.useState)(!1),[g,b]=(0,i.useState)(null);(0,i.useEffect)(()=>{x(e??"")},[e]),(0,i.useEffect)(()=>{p(d)},[d]),(0,i.useEffect)(()=>{let e=!0;return c.FH.watchers.listReactionScripts().then(t=>{e&&o(t.scripts)}).catch(t=>{e&&(console.error(t),o([]))}),()=>{e=!1}},[]);let j=u!==(e??"")||m.trim()!==d.trim();async function y(){let{value:e,error:t}=function(e){let t=e.trim();if(!t)return{value:null,error:null};if(t.length>4e3)return{value:null,error:`Args JSON too long (${t.length}/4000 chars)`};try{let e=JSON.parse(t);if(!e||"object"!=typeof e||Array.isArray(e))return{value:null,error:"Args must be a JSON object"};return{value:e,error:null}}catch(e){return{value:null,error:e instanceof Error?e.message:"Invalid JSON"}}}(m);if(t)return void b(t);if(b(null),!u.trim())return void b("Pick a reaction script first.");f(!0);try{await s({script:u,args:e})}catch(e){e6({title:"Couldn't save reaction script",error:e,context:{...r,script:u}})}finally{f(!1)}}return(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsxs)("select",{value:u,onChange:e=>x(e.target.value),className:"w-full text-[11px] font-mono rounded border border-border bg-surface-1 px-2 py-1 text-fg-muted focus:outline-none focus:border-fg-muted",children:[(0,a.jsx)("option",{value:"",children:"— pick a reaction script —"}),l?.map(e=>(0,a.jsx)("option",{value:e,children:e},e))]}),(0,a.jsx)("textarea",{value:m,onChange:e=>{p(e.target.value),g&&b(null)},rows:3,placeholder:'Optional args JSON, e.g. { "title": "Trigger fired", "level": "warning" }',className:"w-full text-[11px] font-mono rounded border border-border bg-surface-1 px-2 py-1 text-fg-muted focus:outline-none focus:border-fg-muted resize-y"}),(0,a.jsxs)("div",{className:"flex items-center gap-2 text-[10px] text-fg-faint",children:[g?(0,a.jsx)("span",{className:"text-rose-700 dark:text-rose-400",children:g}):n?(0,a.jsxs)("span",{children:["Diff context (",(0,a.jsx)("code",{children:"watcher"}),", ",(0,a.jsx)("code",{children:"previous"}),", ",(0,a.jsx)("code",{children:"current"}),") is auto-merged."]}):(0,a.jsxs)("span",{children:["A ",(0,a.jsx)("code",{children:"task"})," descriptor is auto-merged. Diff context (",(0,a.jsx)("code",{children:"previous"}),"/",(0,a.jsx)("code",{children:"current"}),") is watcher-only."]}),(0,a.jsx)("button",{onClick:()=>void y(),disabled:h||!j,className:"ml-auto px-2 py-0.5 rounded border border-border hover:text-emerald-700 dark:hover:text-emerald-400 hover:border-emerald-700 disabled:opacity-50",children:h?"Saving…":"Save"})]})]})}function s0({agents:e}){let[t,s]=(0,i.useState)([]),[r,n]=(0,i.useState)(!0);async function l(){n(!0);try{s(await c.FH.watchers.list())}catch(e){console.error(e),f({kind:"error",source:"system",sourceLabel:"Watchers",title:"Couldn't load watchers",body:e instanceof Error?e.message:String(e),agent_id:null,thread_id:null,ttl:6e3})}finally{n(!1)}}async function o(e){confirm(`Cancel watcher "${e.label}"?`)&&(await c.FH.watchers.cancel(e.id),l())}async function d(e){try{await c.FH.watchers.runNow(e.id)}catch(t){e6({title:"Couldn't run watcher",error:t,context:{panel:"scheduled-tasks",action:"watcher.runNow",watcher_id:e.id,label:e.label}})}finally{l()}}(0,i.useEffect)(()=>{l()},[]),(0,i.useEffect)(()=>{let e=setInterval(()=>void l(),15e3);return()=>clearInterval(e)},[]);let u=(0,i.useMemo)(()=>[...t].sort((e,t)=>e.next_run_at.localeCompare(t.next_run_at)),[t]);return(0,a.jsxs)("div",{className:"mt-4",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 px-1 py-2 border-b border-border/60",children:[(0,a.jsx)(tp.A,{size:14,className:"text-fg-subtle"}),(0,a.jsx)("h3",{className:"text-xs font-semibold text-fg mr-auto",children:"Event-driven Tasks"}),t.length>0&&(0,a.jsx)("span",{className:"text-[11px] text-fg-faint",children:t.length})]}),r&&0===t.length&&(0,a.jsx)("p",{className:"text-fg-faint text-sm py-6 text-center",children:"Loading…"}),!r&&0===t.length&&(0,a.jsxs)("div",{className:"text-fg-faint text-sm py-6 text-center space-y-2",children:[(0,a.jsx)("p",{children:"No watchers."}),(0,a.jsxs)("p",{className:"text-xs text-fg-faint leading-relaxed",children:["Ask any agent “watch Jira issue ABC-123 and tell me when it changes” or “poll my inbox every 5 minutes”. The agent will register a watcher via its ",(0,a.jsx)("code",{className:"px-1 rounded bg-surface-3 text-fg-subtle",children:"schedule_watcher"})," tool and it will only fire when the underlying tool result actually changes."]})]}),(0,a.jsx)("div",{className:"mt-2",children:u.map(t=>(0,a.jsx)(s1,{watcher:t,agent:e[t.agent_id],onCancel:()=>o(t),onRunNow:()=>d(t),onChanged:()=>void l()},t.id))})]})}function s1({watcher:e,agent:t,onCancel:s,onRunNow:r,onChanged:n}){let[l,o]=(0,i.useState)(!1),[d,u]=(0,i.useState)(!1),x=t8(e.next_run_at,{collapseSeconds:!0}),m=e.last_run_at?t8(e.last_run_at,{collapseSeconds:!0}):null,p=e.last_fired_at?t8(e.last_fired_at,{collapseSeconds:!0}):null,h=!e.last_error&&new Date(e.next_run_at).getTime()<Date.now()-6e4;return(0,a.jsxs)("div",{"data-deep-link-id":e.id,className:"mb-2 rounded-lg border border-border bg-surface-2 overflow-hidden",children:[(0,a.jsx)("button",{onClick:()=>o(e=>!e),className:"w-full text-left px-3 py-2 hover:bg-surface-3/40 transition-colors",children:(0,a.jsxs)("div",{className:"flex items-start gap-2",children:[(0,a.jsx)(sQ.A,{size:12,className:"mt-1 text-amber-700 dark:text-amber-400 shrink-0"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("p",{className:"text-sm text-fg truncate",children:e.label}),(0,a.jsxs)("div",{className:"flex items-center gap-2 mt-1 text-[11px] text-fg-faint flex-wrap",children:[(0,a.jsx)("span",{className:"font-mono",children:e.tool}),(0,a.jsx)("span",{children:"\xb7"}),(0,a.jsxs)("span",{children:["every ",s4(e.interval_seconds)]}),(0,a.jsx)("span",{children:"\xb7"}),(0,a.jsx)("span",{className:h?"text-amber-700 dark:text-amber-400":"",children:h?"overdue":`next: ${x}`}),t&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{children:"\xb7"}),(0,a.jsx)("span",{className:"truncate",children:t.name})]}),e.silent&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{children:"\xb7"}),(0,a.jsxs)("span",{className:"inline-flex items-center gap-0.5 text-fg-faint",title:"Silent: suppresses the task_completed notification and tells the agent to reply only on material diffs. Errors still notify.",children:[(0,a.jsx)(G.A,{size:10})," silent"]})]})]})]})]})}),l&&(0,a.jsxs)("div",{className:"px-3 py-2 border-t border-border/60 text-[11px] text-fg-subtle space-y-2",children:[(0,a.jsx)(s2,{label:"Tool",children:(0,a.jsx)("span",{className:"font-mono",children:e.tool})}),(0,a.jsx)(s2,{label:"Args",children:(0,a.jsx)("pre",{className:"whitespace-pre-wrap break-words font-mono text-fg-muted",children:JSON.stringify(e.args??{},null,2)})}),(0,a.jsx)(s2,{label:"Reaction",children:(0,a.jsx)(s5,{watcher:e,onSaved:n})}),(0,a.jsx)(s2,{label:"Interval",children:(0,a.jsx)("span",{children:s4(e.interval_seconds)})}),(0,a.jsxs)(s2,{label:"Next poll",children:[(0,a.jsx)("span",{children:new Date(e.next_run_at).toLocaleString()}),(0,a.jsxs)("span",{className:"ml-1 text-fg-faint",children:["(",x,")"]})]}),m&&(0,a.jsxs)(s2,{label:"Last poll",children:[(0,a.jsx)("span",{children:new Date(e.last_run_at).toLocaleString()}),(0,a.jsxs)("span",{className:"ml-1 text-fg-faint",children:["(",m,")"]})]}),p&&(0,a.jsxs)(s2,{label:"Last fire",children:[(0,a.jsx)("span",{children:new Date(e.last_fired_at).toLocaleString()}),(0,a.jsxs)("span",{className:"ml-1 text-fg-faint",children:["(",p,")"]})]}),(0,a.jsx)(s2,{label:"Status",children:e.last_error?(0,a.jsxs)("span",{className:"inline-flex items-center gap-1 text-rose-700 dark:text-rose-400",children:[(0,a.jsx)(tL.A,{size:11})," error"]}):e.enabled?(0,a.jsxs)("span",{className:"inline-flex items-center gap-1 text-emerald-700 dark:text-emerald-400",children:[(0,a.jsx)(so.A,{size:11})," active"]}):(0,a.jsx)("span",{className:"text-fg-faint",children:"disabled"})}),e.last_error&&(0,a.jsx)(s2,{label:"Error",children:(0,a.jsx)("pre",{className:"whitespace-pre-wrap break-words text-rose-700 dark:text-rose-300/90",children:e.last_error})}),(0,a.jsxs)("div",{className:"flex justify-end pt-1 gap-2",children:[(0,a.jsxs)("button",{onClick:async()=>{try{await c.FH.watchers.update(e.id,{enabled:!e.enabled}),n()}catch(t){e6({title:"Couldn't toggle watcher",error:t,context:{panel:"scheduled-tasks",action:"watcher.toggle",watcher_id:e.id,target_enabled:!e.enabled}})}},className:"inline-flex items-center gap-1 px-2 py-1 text-[11px] rounded border border-border text-fg-muted hover:text-fg hover:border-fg-muted",title:e.enabled?"Pause this watcher":"Resume this watcher",children:[(0,a.jsx)(sY.A,{size:11})," ",e.enabled?"Pause":"Resume"]}),(0,a.jsxs)("button",{onClick:async()=>{if(!d){u(!0);try{await r()}finally{u(!1)}}},disabled:d,className:"inline-flex items-center gap-1 px-2 py-1 text-[11px] rounded border border-border text-fg-muted hover:text-emerald-700 dark:hover:text-emerald-400 hover:border-emerald-700 disabled:opacity-50",title:"Poll the tool right now. If the result differs from the last poll, the agent fires.",children:[(0,a.jsx)(eu.A,{size:11})," ",d?"Polling…":"Poll now"]}),(0,a.jsxs)("button",{onClick:s,className:"inline-flex items-center gap-1 px-2 py-1 text-[11px] rounded border border-border text-fg-subtle hover:text-rose-700 dark:hover:text-rose-400 hover:border-rose-700",children:[(0,a.jsx)(eQ.A,{size:11})," Cancel watcher"]})]})]})]})}function s2({label:e,children:t}){return(0,a.jsxs)("div",{className:"flex items-start gap-2",children:[(0,a.jsx)("span",{className:"w-20 shrink-0 text-fg-faint",children:e}),(0,a.jsx)("div",{className:"flex-1 min-w-0",children:t})]})}function s5({watcher:e,onSaved:t}){let[s,r]=(0,i.useState)(!1);async function n(s,a){r(!0);try{"script"===s?await c.FH.watchers.update(e.id,{reaction_kind:"script",reaction_script:a??null,reaction_script_args:null}):await c.FH.watchers.update(e.id,{reaction_kind:"agent_prompt",reaction_prompt:null}),t()}catch(t){e6({title:"Couldn't switch reaction kind",error:t,context:{panel:"scheduled-tasks",action:"watcher.reaction_kind",watcher_id:e.id,target_kind:s}})}finally{r(!1)}}return(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)(sZ,{active:"agent_prompt"===e.reaction_kind,onClick:()=>"agent_prompt"!==e.reaction_kind&&void n("agent_prompt"),disabled:s,title:"On change, run this watcher's agent with a custom prompt (default behaviour).",children:"Agent prompt"}),(0,a.jsx)(sZ,{active:"script"===e.reaction_kind,onClick:()=>"script"!==e.reaction_kind&&void n("script"),disabled:s,title:"On change, run a built-in reaction.* script with no LLM round-trip.",children:"Script"})]}),"script"===e.reaction_kind?(0,a.jsx)(sX,{initialScript:e.reaction_script,initialArgs:e.reaction_script_args,onSave:async({script:s,args:a})=>{await c.FH.watchers.update(e.id,{reaction_script:s,reaction_script_args:a}),t()},errorContext:{panel:"scheduled-tasks",action:"watcher.reaction_script",watcher_id:e.id},diffContext:!0}):(0,a.jsx)(s3,{watcher:e,onSaved:t})]})}function s3({watcher:e,onSaved:t}){let s=e.reaction_prompt??"",[r,n]=(0,i.useState)(s),[l,o]=(0,i.useState)(!1);(0,i.useEffect)(()=>{n(e.reaction_prompt??"")},[e.reaction_prompt]);let d=r.trim()!==s.trim(),u=r.length>4e3;async function x(s){o(!0);try{await c.FH.watchers.update(e.id,{reaction_prompt:s}),t()}catch(t){e6({title:"Couldn't save reaction",error:t,context:{panel:"scheduled-tasks",action:"watcher.reaction_prompt",watcher_id:e.id}})}finally{o(!1)}}return(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("textarea",{value:r,onChange:e=>n(e.target.value),rows:3,placeholder:"Default: summarise what changed and decide whether the user needs to know.",className:"w-full text-[11px] font-mono rounded border border-border bg-surface-1 px-2 py-1 text-fg-muted focus:outline-none focus:border-fg-muted resize-y"}),(0,a.jsxs)("div",{className:"flex items-center gap-2 text-[10px] text-fg-faint",children:[(0,a.jsxs)("span",{className:u?"text-rose-700 dark:text-rose-400":"",children:[r.length,"/",4e3]}),(0,a.jsxs)("span",{className:"ml-auto flex gap-2",children:[null!==e.reaction_prompt&&(0,a.jsx)("button",{onClick:()=>{n(""),x(null)},disabled:l,className:"px-2 py-0.5 rounded border border-border hover:text-fg hover:border-fg-muted disabled:opacity-50",title:"Clear the custom instruction; fall back to the default directive.",children:"Reset to default"}),(0,a.jsx)("button",{onClick:()=>void x(r.trim()?r:null),disabled:l||!d||u,className:"px-2 py-0.5 rounded border border-border hover:text-emerald-700 dark:hover:text-emerald-400 hover:border-emerald-700 disabled:opacity-50",children:l?"Saving…":"Save"})]})]})]})}function s4(e){return e<60?`${e}s`:e<3600?`${Math.round(e/60)}m`:e<86400?`${Math.round(e/3600)}h`:`${Math.round(e/86400)}d`}function s6(){let[e,t]=(0,i.useState)([]),[s,r]=(0,i.useState)({}),[n,l]=(0,i.useState)(!0),o=(0,i.useRef)(null);async function d(){l(!0);try{let[e,s]=await Promise.all([c.FH.scheduledTasks.list(),c.FH.agents.list()]);t(e),r(Object.fromEntries(s.map(e=>[e.id,e])))}catch(e){console.error(e)}finally{l(!1)}}async function u(e){confirm(`Cancel scheduled task?
21
-
22
- ${e.prompt.slice(0,200)}${e.prompt.length>200?"…":""}`)&&(await c.FH.scheduledTasks.cancel(e.id),d())}async function x(e){try{await c.FH.scheduledTasks.runNow(e.id)}catch(t){e6({title:"Couldn't run scheduled task",error:t,context:{panel:"scheduled-tasks",action:"task.runNow",task_id:e.id}})}finally{d()}}eX("tasks","task",o),(0,i.useEffect)(()=>{d()},[]),(0,i.useEffect)(()=>{let e=setInterval(()=>void d(),15e3);return()=>clearInterval(e)},[]);let m=(0,i.useMemo)(()=>[...e].sort((e,t)=>e.next_run_at.localeCompare(t.next_run_at)),[e]);return(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[(0,a.jsxs)("div",{className:"border-b border-border px-4 py-3 flex items-center gap-2",children:[(0,a.jsx)(sV.A,{size:14,className:"text-fg-subtle"}),(0,a.jsx)("h2",{className:"text-sm font-semibold text-fg mr-auto",children:"Scheduled Tasks"}),e.length>0&&(0,a.jsx)("span",{className:"text-[11px] text-fg-faint",children:e.length})]}),(0,a.jsxs)("div",{ref:o,className:"flex-1 overflow-y-auto px-4 py-3",children:[n&&0===e.length&&(0,a.jsx)("p",{className:"text-fg-faint text-sm py-6 text-center",children:"Loading…"}),!n&&0===e.length&&(0,a.jsxs)("div",{className:"text-fg-faint text-sm py-8 text-center space-y-2",children:[(0,a.jsx)("p",{children:"No scheduled tasks."}),(0,a.jsxs)("p",{className:"text-xs text-fg-faint leading-relaxed",children:["Ask any agent “remind me to X in 30 minutes” or “every weekday at 9am, do Y”. The agent will use its ",(0,a.jsx)("code",{className:"px-1 rounded bg-surface-3 text-fg-subtle",children:"schedule_task"})," tool and the run will appear here."]})]}),m.map(e=>(0,a.jsx)(s7,{task:e,agent:s[e.agent_id],onCancel:()=>u(e),onRunNow:()=>x(e),onChanged:()=>void d()},e.id)),(0,a.jsx)(s0,{agents:s})]})]})}function s7({task:e,agent:t,onCancel:s,onRunNow:r,onChanged:n}){let[l,o]=(0,i.useState)(!1),[d,u]=(0,i.useState)(!1),[x,m]=(0,i.useState)(!1),p="cron"===e.kind,h=ae(e.next_run_at),f=e.last_run_at?ae(e.last_run_at):null,g=!e.last_error&&new Date(e.next_run_at).getTime()<Date.now()-6e4;return(0,a.jsxs)("div",{"data-deep-link-id":e.id,className:"mb-2 rounded-lg border border-border bg-surface-2 overflow-hidden",children:[(0,a.jsx)("button",{onClick:()=>o(e=>!e),className:"w-full text-left px-3 py-2 hover:bg-surface-3/40 transition-colors",children:(0,a.jsxs)("div",{className:"flex items-start gap-2",children:[p?(0,a.jsx)(sK.A,{size:12,className:"mt-1 text-violet-700 dark:text-violet-400 shrink-0"}):(0,a.jsx)(B.A,{size:12,className:"mt-1 text-sky-700 dark:text-sky-400 shrink-0"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("p",{className:"text-sm text-fg truncate",children:e.prompt}),(0,a.jsxs)("div",{className:"flex items-center gap-2 mt-1 text-[11px] text-fg-faint flex-wrap",children:[(0,a.jsx)("span",{className:"font-mono",children:p?e.schedule:new Date(e.schedule).toLocaleString()}),(0,a.jsx)("span",{children:"\xb7"}),(0,a.jsx)("span",{className:g?"text-amber-700 dark:text-amber-400":"",children:g?"overdue":`next: ${h}`}),t&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{children:"\xb7"}),(0,a.jsx)("span",{className:"truncate",children:t.name})]}),e.silent&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{children:"\xb7"}),(0,a.jsxs)("span",{className:"inline-flex items-center gap-0.5 text-fg-faint",title:"Silent: suppresses the task_completed notification and tells the agent to reply only when something material surfaces. Errors still notify.",children:[(0,a.jsx)(G.A,{size:10})," silent"]})]})]})]})]})}),l&&(0,a.jsx)("div",{className:"px-3 py-2 border-t border-border/60 text-[11px] text-fg-subtle space-y-2",children:x?(0,a.jsx)(at,{task:e,onCancel:()=>m(!1),onSaved:()=>{m(!1),n()}}):(0,a.jsxs)(a.Fragment,{children:["agent_prompt"===e.reaction_kind&&(0,a.jsx)(s8,{label:"Prompt",children:(0,a.jsx)("pre",{className:"whitespace-pre-wrap break-words font-mono text-fg-muted",children:e.prompt})}),"script"===e.reaction_kind&&(0,a.jsx)(s8,{label:"Prompt",children:(0,a.jsxs)("span",{className:"text-fg-faint italic",children:["(running script: ",(0,a.jsx)("span",{className:"font-mono",children:e.reaction_script})," — no agent prompt)"]})}),(0,a.jsx)(s8,{label:"Reaction",children:(0,a.jsx)(s9,{task:e,onChanged:n})}),e.description&&(0,a.jsx)(s8,{label:"Description",children:e.description}),(0,a.jsx)(s8,{label:"Kind",children:(0,a.jsx)("span",{className:"font-mono",children:e.kind})}),(0,a.jsxs)(s8,{label:p?"Cron":"When",children:[(0,a.jsx)("span",{className:"font-mono",children:e.schedule}),!p&&(0,a.jsxs)("span",{className:"ml-1 text-fg-faint",children:["(",new Date(e.schedule).toLocaleString(),")"]})]}),(0,a.jsxs)(s8,{label:"Next run",children:[(0,a.jsx)("span",{children:new Date(e.next_run_at).toLocaleString()}),(0,a.jsxs)("span",{className:"ml-1 text-fg-faint",children:["(",h,")"]})]}),f&&(0,a.jsxs)(s8,{label:"Last run",children:[(0,a.jsx)("span",{children:new Date(e.last_run_at).toLocaleString()}),(0,a.jsxs)("span",{className:"ml-1 text-fg-faint",children:["(",f,")"]})]}),(0,a.jsx)(s8,{label:"Status",children:e.last_error?(0,a.jsxs)("span",{className:"inline-flex items-center gap-1 text-rose-700 dark:text-rose-400",children:[(0,a.jsx)(tL.A,{size:11})," error"]}):e.enabled?(0,a.jsxs)("span",{className:"inline-flex items-center gap-1 text-emerald-700 dark:text-emerald-400",children:[(0,a.jsx)(so.A,{size:11})," active"]}):(0,a.jsx)("span",{className:"text-fg-faint",children:"disabled"})}),e.last_error&&(0,a.jsx)(s8,{label:"Error",children:(0,a.jsx)("pre",{className:"whitespace-pre-wrap break-words text-rose-700 dark:text-rose-300/90",children:e.last_error})}),(0,a.jsxs)("div",{className:"flex justify-end pt-1 gap-2",children:[(0,a.jsxs)("button",{onClick:async()=>{try{await c.FH.scheduledTasks.update(e.id,{enabled:!e.enabled}),n()}catch(t){e6({title:"Couldn't toggle scheduled task",error:t,context:{panel:"scheduled-tasks",action:"task.toggle",task_id:e.id,target_enabled:!e.enabled}})}},className:"inline-flex items-center gap-1 px-2 py-1 text-[11px] rounded border border-border text-fg-muted hover:text-fg hover:border-fg-muted",title:e.enabled?"Pause this task (scheduler will skip it)":"Resume this task",children:[(0,a.jsx)(sY.A,{size:11})," ",e.enabled?"Pause":"Resume"]}),(0,a.jsxs)("button",{onClick:()=>m(!0),className:"inline-flex items-center gap-1 px-2 py-1 text-[11px] rounded border border-border text-fg-muted hover:text-sky-700 dark:hover:text-sky-400 hover:border-sky-700",children:[(0,a.jsx)(eY.A,{size:11})," Edit"]}),(0,a.jsxs)("button",{onClick:async()=>{if(!d){u(!0);try{await r()}finally{u(!1)}}},disabled:d,className:"inline-flex items-center gap-1 px-2 py-1 text-[11px] rounded border border-border text-fg-muted hover:text-emerald-700 dark:hover:text-emerald-400 hover:border-emerald-700 disabled:opacity-50",title:"Trigger this task now to preview the notification + content. Cron tasks still continue on their normal schedule.",children:[(0,a.jsx)(eu.A,{size:11})," ",d?"Running…":"Run now"]}),(0,a.jsxs)("button",{onClick:s,className:"inline-flex items-center gap-1 px-2 py-1 text-[11px] rounded border border-border text-fg-subtle hover:text-rose-700 dark:hover:text-rose-400 hover:border-rose-700",children:[(0,a.jsx)(eQ.A,{size:11})," Cancel task"]})]})]})})]})}function s9({task:e,onChanged:t}){let[s,r]=(0,i.useState)(!1);async function n(s){if(s!==e.reaction_kind){r(!0);try{"script"===s?await c.FH.scheduledTasks.update(e.id,{reaction_kind:"script",reaction_script:null,reaction_script_args:null}):await c.FH.scheduledTasks.update(e.id,{reaction_kind:"agent_prompt",prompt:e.prompt&&e.prompt.trim()?e.prompt:"(edit me)"}),t()}catch(t){e6({title:"Couldn't switch reaction kind",error:t,context:{panel:"scheduled-tasks",action:"task.reaction_kind",task_id:e.id,target_kind:s}})}finally{r(!1)}}}return(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)(sZ,{active:"agent_prompt"===e.reaction_kind,onClick:()=>void n("agent_prompt"),disabled:s,title:"On firing, run this task's agent with the prompt above (default).",children:"Agent prompt"}),(0,a.jsx)(sZ,{active:"script"===e.reaction_kind,onClick:()=>void n("script"),disabled:s,title:"On firing, run a built-in reaction.* script with no LLM round-trip.",children:"Script"})]}),"script"===e.reaction_kind&&(0,a.jsx)(sX,{initialScript:e.reaction_script,initialArgs:e.reaction_script_args,onSave:async({script:s,args:a})=>{await c.FH.scheduledTasks.update(e.id,{reaction_script:s,reaction_script_args:a}),t()},errorContext:{panel:"scheduled-tasks",action:"task.reaction_script",task_id:e.id},diffContext:!1})]})}function s8({label:e,children:t}){return(0,a.jsxs)("div",{className:"flex items-start gap-2",children:[(0,a.jsx)("span",{className:"w-20 shrink-0 text-fg-faint",children:e}),(0,a.jsx)("div",{className:"flex-1 min-w-0",children:t})]})}function ae(e){return t8(e,{collapseSeconds:!0})}function at({task:e,onCancel:t,onSaved:s}){let[r,n]=(0,i.useState)(e.prompt),[l,o]=(0,i.useState)(e.description??""),[d,u]=(0,i.useState)(e.kind),[x,m]=(0,i.useState)(()=>"once"===e.kind?as(e.schedule):e.schedule),[p,h]=(0,i.useState)(e.enabled),[f,g]=(0,i.useState)(e.silent??!1),[b,j]=(0,i.useState)(!1),[y,v]=(0,i.useState)(null);async function N(){if(b)return;v(null);let t=r.trim();if(!t)return void v("Prompt cannot be empty.");let a=x.trim();if(!a)return void v("Schedule cannot be empty.");let n=a;if("once"===d){let e=new Date(a);if(Number.isNaN(e.getTime()))return void v("Invalid date/time.");n=e.toISOString()}j(!0);try{await c.FH.scheduledTasks.update(e.id,{prompt:t,description:l.trim()?l.trim():null,kind:d,schedule:n,enabled:p,silent:f}),s()}catch(t){e6({title:"Couldn't save scheduled task",error:t,context:{panel:"scheduled-tasks",action:"task.save",task_id:e.id}})}finally{j(!1)}}return(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(s8,{label:"Prompt",children:(0,a.jsx)("textarea",{value:r,onChange:e=>n(e.target.value),rows:3,className:"w-full rounded border border-border bg-surface-1 px-2 py-1 text-[12px] text-fg font-mono"})}),(0,a.jsx)(s8,{label:"Description",children:(0,a.jsx)("input",{value:l,onChange:e=>o(e.target.value),placeholder:"optional",className:"w-full rounded border border-border bg-surface-1 px-2 py-1 text-[12px] text-fg"})}),(0,a.jsx)(s8,{label:"Kind",children:(0,a.jsx)("div",{className:"inline-flex rounded border border-border overflow-hidden",children:["once","cron"].map(t=>(0,a.jsx)("button",{type:"button",onClick:()=>{u(t),"once"===t&&"once"!==e.kind&&m(as(new Date(Date.now()+36e5).toISOString())),"cron"===t&&"cron"!==e.kind&&m("0 9 * * *")},className:`px-2 py-0.5 text-[11px] ${d===t?"bg-surface-3 text-fg":"text-fg-faint hover:text-fg"}`,children:t},t))})}),(0,a.jsx)(s8,{label:"cron"===d?"Cron":"When",children:"cron"===d?(0,a.jsx)("input",{value:x,onChange:e=>m(e.target.value),placeholder:"0 9 * * *",className:"w-full rounded border border-border bg-surface-1 px-2 py-1 text-[12px] text-fg font-mono"}):(0,a.jsx)("input",{type:"datetime-local",value:x,onChange:e=>m(e.target.value),className:"rounded border border-border bg-surface-1 px-2 py-1 text-[12px] text-fg"})}),(0,a.jsx)(s8,{label:"Enabled",children:(0,a.jsxs)("label",{className:"inline-flex items-center gap-1 cursor-pointer",children:[(0,a.jsx)("input",{type:"checkbox",checked:p,onChange:e=>h(e.target.checked),className:"accent-emerald-600"}),(0,a.jsx)("span",{className:"text-[11px]",children:p?"active":"paused"})]})}),(0,a.jsx)(s8,{label:"Silent",children:(0,a.jsxs)("label",{className:"inline-flex items-center gap-1 cursor-pointer",title:"When silent: suppresses the task_completed notification AND tells the agent to reply only when something material surfaces (NO_REPLY answers are dropped). Errors still notify so failures aren't hidden. Firings remain visible in chat tagged 'scheduled' — use the filter toolbar to hide them.",children:[(0,a.jsx)("input",{type:"checkbox",checked:f,onChange:e=>g(e.target.checked),className:"accent-sky-600"}),(0,a.jsx)("span",{className:"text-[11px]",children:f?"muted (no notification)":"always notify"})]})}),y&&(0,a.jsx)("p",{className:"text-[11px] text-rose-700 dark:text-rose-400",children:y}),(0,a.jsxs)("div",{className:"flex justify-end gap-2 pt-1",children:[(0,a.jsxs)("button",{onClick:t,disabled:b,className:"inline-flex items-center gap-1 px-2 py-1 text-[11px] rounded border border-border text-fg-subtle hover:text-fg disabled:opacity-50",children:[(0,a.jsx)(z.A,{size:11})," Cancel"]}),(0,a.jsxs)("button",{onClick:()=>void N(),disabled:b,className:"inline-flex items-center gap-1 px-2 py-1 text-[11px] rounded border border-emerald-700 text-emerald-700 dark:text-emerald-400 hover:bg-emerald-700/10 disabled:opacity-50",children:[(0,a.jsx)(sL.A,{size:11})," ",b?"Saving…":"Save"]})]})]})}function as(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return"";let s=e=>String(e).padStart(2,"0");return`${t.getFullYear()}-${s(t.getMonth()+1)}-${s(t.getDate())}T${s(t.getHours())}:${s(t.getMinutes())}`}var aa=s(5e3),ar=s(5964),an=s(9585),al=s(908),ai=s(9572);function ao({bridge:e,onBack:t,onRename:s,onToggleEnabled:r}){let[n,l]=(0,i.useState)(e.name),[o,d]=(0,i.useState)(!1),[u,x]=(0,i.useState)(null),[m,p]=(0,i.useState)(!1);async function h(){if(n.trim()!==e.name&&n.trim()){d(!0);try{await s(n.trim())}finally{d(!1)}}}async function f(){if(confirm("Re-pair this bridge? This wipes the current WhatsApp session and shows a new QR code.")){p(!0);try{await c.FH.bridges.pair(e.id),e.enabled||await r()}catch(t){e6({title:"Couldn't re-pair bridge",error:t,context:{panel:"bridges",action:"bridge.rePair",bridge_id:e.id}})}finally{p(!1)}}}return(0,i.useEffect)(()=>{let t,s=!0;async function a(){if(s)try{let r=await c.FH.bridges.status(e.id);if(!s)return;x(r),t=setTimeout(a,"pairing"===r.status?1500:5e3)}catch{t=setTimeout(a,5e3)}}return a(),()=>{s=!1,clearTimeout(t)}},[e.id]),(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[(0,a.jsxs)("div",{className:"border-b border-border px-4 py-3 flex items-center gap-2",children:[(0,a.jsx)("button",{onClick:t,className:"p-1 rounded hover:bg-surface-3 text-fg-subtle",children:(0,a.jsx)(an.A,{size:14})}),(0,a.jsx)("input",{value:n,onChange:e=>l(e.target.value),onBlur:h,onKeyDown:e=>{"Enter"===e.key&&e.target.blur()},className:"flex-1 bg-transparent text-sm font-semibold text-fg outline-none border-b border-transparent focus:border-accent",disabled:o}),(0,a.jsx)(am,{status:u?.status??e.status})]}),(0,a.jsxs)("div",{className:"flex-1 overflow-y-auto px-4 py-3 space-y-4",children:[(0,a.jsxs)("section",{className:"rounded-lg border border-border bg-surface-2 p-3 space-y-3",children:[(0,a.jsxs)("header",{className:"flex items-center gap-2",children:[(0,a.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wide text-fg-subtle",children:"Connection"}),(0,a.jsx)("span",{className:"text-[11px] text-fg-faint ml-auto",children:u?.paired_id??e.paired_id??"Not paired"})]}),(u?.status==="pairing"||!u&&"pairing"===e.status)&&u?.qr_data_url&&(0,a.jsxs)("div",{className:"flex flex-col items-center gap-2 py-2",children:[(0,a.jsx)("div",{className:"bg-white p-3 rounded-lg",children:(0,a.jsx)("img",{src:u.qr_data_url,alt:"WhatsApp pairing QR",className:"w-48 h-48 block"})}),(0,a.jsx)("p",{className:"text-[11px] text-fg-faint text-center max-w-xs",children:"Open WhatsApp on your phone → Settings → Linked Devices → Link a device → scan this code."})]}),(u?.last_error||e.last_error)&&(0,a.jsx)("p",{className:"text-[11px] text-rose-700 dark:text-rose-300 bg-rose-500/10 border border-rose-500/30 rounded px-2 py-1",children:u?.last_error??e.last_error}),(0,a.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,a.jsxs)("label",{className:"flex items-center gap-1.5 text-xs text-fg-muted cursor-pointer select-none",children:[(0,a.jsx)("input",{type:"checkbox",checked:e.enabled,onChange:()=>void r(),className:"accent-accent"}),"Enabled"]}),(0,a.jsxs)("button",{onClick:f,disabled:m,className:"ml-auto px-2 py-1 text-xs rounded bg-surface-3 hover:bg-surface-3/70 text-fg-muted flex items-center gap-1 disabled:opacity-50",children:[m?(0,a.jsx)(tI.A,{size:11,className:"animate-spin"}):(0,a.jsx)(al.A,{size:11}),"Re-pair"]})]})]}),(0,a.jsx)(ac,{bridge_id:e.id}),(0,a.jsxs)("section",{className:"rounded-lg border border-border bg-surface-2 p-3 text-[11px] text-fg-faint leading-relaxed space-y-2",children:[(0,a.jsxs)("p",{children:[(0,a.jsx)("strong",{className:"text-fg-muted",children:"Unrouted messages are ignored (unless catch-all exists)."})," ","If a WhatsApp chat isn't mapped to an agent below, incoming messages are silently dropped unless you add a ",(0,a.jsx)("em",{children:"catch-all"})," route (`*`). Each agent can still have only one route, but a catch-all route can intentionally aggregate many chats into one agent thread."]}),(0,a.jsxs)("p",{children:[(0,a.jsx)("strong",{className:"text-fg-muted",children:"What gets forwarded."})," ","Text, image captions, and image / sticker payloads (as vision input) reach the agent. Voice notes, audio, video and documents are forwarded as attachments — agents can see their filename and mime type, but only models with native audio / video / PDF support interpret the contents. Location and contact-card messages are flattened into the text body. The ",(0,a.jsx)(ai.A,{className:"inline -mt-0.5",size:11})," badge above marks agents whose model can read images."]})]})]})]})}function ac({bridge_id:e}){let{routes:t,create:s,update:r,remove:n}=function(e){let[t,s]=(0,i.useState)([]),[a,r]=(0,i.useState)(!1),n=(0,i.useCallback)(async()=>{if(!e)return void s([]);r(!0);try{s(await c.FH.bridges.routes.list(e))}finally{r(!1)}},[e]);(0,i.useEffect)(()=>{n()},[n]);let l=(0,i.useCallback)(async t=>{if(!e)throw Error("No bridge selected");let a=await c.FH.bridges.routes.create(e,t);return s(e=>[...e,a]),a},[e]);return{routes:t,loading:a,refresh:n,create:l,update:(0,i.useCallback)(async(t,a)=>{if(!e)throw Error("No bridge selected");let r=await c.FH.bridges.routes.update(e,t,a);return s(e=>e.map(e=>e.id===t?r:e)),r},[e]),remove:(0,i.useCallback)(async t=>{if(!e)throw Error("No bridge selected");await c.FH.bridges.routes.delete(e,t),s(e=>e.filter(e=>e.id!==t))},[e])}}(e),[l,o]=(0,i.useState)([]),[d,u]=(0,i.useState)([]),[x,m]=(0,i.useState)(!0),[p,h]=(0,i.useState)(!1),[f,g]=(0,i.useState)(!1),[b,j]=(0,i.useState)(!1),[y,v]=(0,i.useState)({remote_jid:"",agent_id:"",label:""}),[N,w]=(0,i.useState)(null),[k,S]=(0,i.useState)(""),[_,C]=(0,i.useState)(!1),[A,E]=(0,i.useState)(null),[T,$]=(0,i.useState)([]),[z,I]=(0,i.useState)([]);function F(e){let t,s=(t=z.find(e=>e.is_default)??null,e?.model_config_name?z.find(t=>t.name===e.model_config_name)??t:t);return s?{supported:tf(s.provider,s.model_id),classified:tg(s.provider),modelLabel:`${s.provider} / ${s.model_id}`}:{supported:!1,classified:!1,modelLabel:null}}(0,i.useEffect)(()=>{c.FH.agents.list().then(o).catch(()=>{})},[]),(0,i.useEffect)(()=>{c.FH.models.list().then(I).catch(()=>{})},[]),(0,i.useEffect)(()=>{if(!b)return;let t=!0;async function s(){h(!0);try{let s=await c.FH.bridges.chats(e);if(!t)return;u(s.chats),m(s.running)}catch{}finally{t&&h(!1)}}s();let a=setInterval(()=>void s(),4e3);return()=>{t=!1,clearInterval(a)}},[b,e]);let L=new Set(t.map(e=>e.agent_id)),R=l.filter(e=>!L.has(e.id)),H=t.some(e=>"*"===e.remote_jid),P="*"===y.remote_jid,O=(0,i.useMemo)(()=>new Set(t.map(e=>e.remote_jid)),[t]),M=(0,i.useMemo)(()=>{let e=new Map;for(let t of T)e.set(t.remote_jid,t);for(let t of d)e.set(t.remote_jid,t);return Array.from(e.values()).filter(e=>!O.has(e.remote_jid))},[d,T,O]);async function D(){E(null);let t=k.trim();if(t){C(!0);try{let s=await c.FH.bridges.lookup(e,t);if(!s.chat)return void E("That number isn't on WhatsApp.");if(O.has(s.chat.remote_jid))return void E("That chat already has a route.");$(e=>e.some(e=>e.remote_jid===s.chat.remote_jid)?e:[...e,s.chat]),v(e=>({remote_jid:s.chat.remote_jid,agent_id:e.agent_id,label:e.label.trim()?e.label:s.chat.name??e.label})),S("")}catch(e){E(e instanceof Error?e.message:String(e))}finally{C(!1)}}}async function U(){w(null);let e=y.remote_jid.trim(),t=y.agent_id.trim();if(!e||!t)return void w("Pick a chat and an agent");try{await s({remote_jid:e,agent_id:t,label:y.label.trim()||null}),j(!1),g(!1),v({remote_jid:"",agent_id:"",label:""})}catch(e){w(e instanceof Error?e.message:String(e))}}return(0,a.jsxs)("section",{className:"rounded-lg border border-border bg-surface-2 p-3 space-y-2",children:[(0,a.jsxs)("header",{className:"flex items-center gap-2",children:[(0,a.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wide text-fg-subtle",children:"Routes"}),(0,a.jsx)("span",{className:"text-[11px] text-fg-faint",children:t.length}),(0,a.jsxs)("button",{onClick:()=>{j(!0),w(null)},className:"ml-auto px-2 py-0.5 text-[11px] rounded bg-accent/15 hover:bg-accent/25 text-accent flex items-center gap-1",children:[(0,a.jsx)(eV.A,{size:10})," Add"]})]}),b&&(0,a.jsxs)("div",{className:"rounded border border-accent/30 bg-surface-3/30 p-2 space-y-2",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("label",{className:"text-[11px] text-fg-subtle flex items-center gap-2 cursor-pointer select-none",children:[(0,a.jsx)("input",{type:"checkbox",checked:P,onChange:e=>{let t=e.target.checked;v(e=>({...e,remote_jid:t?"*":"",label:t?e.label.trim()?e.label:"Catch-all":e.label})),t&&(g(!1),w(null))},disabled:H&&!P}),"Catch everything else (fallback route)"]}),H&&!P&&(0,a.jsx)("span",{className:"text-[10px] text-fg-faint",children:"Catch-all already exists"})]}),P&&(0,a.jsx)("p",{className:"text-[11px] text-fg-faint leading-snug",children:"This route matches any inbound chat without an explicit route. The agent will receive chat metadata (name + JID) in each message so it can distinguish sources."}),!P&&(f?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("label",{className:"text-[10px] uppercase tracking-wide text-fg-faint font-semibold",children:"JID"}),(0,a.jsx)("button",{type:"button",onClick:()=>g(!1),className:"ml-auto text-[10px] text-fg-faint hover:text-accent underline-offset-2 hover:underline",children:"Pick from chat list"})]}),(0,a.jsx)("input",{autoFocus:!0,value:y.remote_jid,onChange:e=>v(t=>({...t,remote_jid:e.target.value})),placeholder:"5511999990000@s.whatsapp.net or <group-id>@g.us",className:"w-full px-2 py-1 text-xs bg-surface-3 rounded border border-border focus:border-accent outline-none font-mono"})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("label",{className:"text-[10px] uppercase tracking-wide text-fg-faint font-semibold",children:"Chat"}),p&&(0,a.jsx)(tI.A,{size:10,className:"animate-spin text-fg-faint"}),(0,a.jsx)("button",{type:"button",onClick:()=>g(!0),className:"ml-auto text-[10px] text-fg-faint hover:text-accent underline-offset-2 hover:underline",children:"Enter JID manually"})]}),!x&&(0,a.jsx)("p",{className:"text-[11px] text-amber-700 dark:text-amber-300 bg-amber-500/10 border border-amber-500/30 rounded px-2 py-1",children:"Bridge isn't running — enable it to load your WhatsApp chats."}),x&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,a.jsxs)("div",{className:"flex-1 flex items-center gap-1.5 rounded border border-border bg-surface-3/60 px-2 py-1 focus-within:border-accent/60",children:[(0,a.jsx)(eK.A,{size:11,className:"text-fg-faint shrink-0"}),(0,a.jsx)("input",{type:"tel",inputMode:"tel",placeholder:"Find by phone (e.g. +1 555 123 4567)",value:k,onChange:e=>{S(e.target.value),E(null)},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),D())},className:"flex-1 bg-transparent text-xs outline-none placeholder:text-fg-faint",disabled:_})]}),(0,a.jsx)("button",{type:"button",onClick:()=>void D(),disabled:_||!k.trim(),className:"text-[11px] px-2 py-1 rounded border border-border bg-surface-3 hover:bg-surface-2 disabled:opacity-40",children:_?"…":"Find"})]}),(0,a.jsx)("p",{className:"text-[10px] text-fg-faint leading-snug",children:"WhatsApp only auto-syncs your recent chats. Use search to find any contact (including yourself) by phone number — country code + digits, no spaces required."}),A&&(0,a.jsx)("p",{className:"text-[11px] text-amber-700 dark:text-amber-300",children:A})]}),x&&0===M.length&&!p&&(0,a.jsxs)("p",{className:"text-[11px] text-fg-faint px-1 py-2 leading-relaxed",children:["No chats synced yet. WhatsApp delivers your chat list a few seconds after pairing, and any chat you receive a message in will also appear here. If you can't wait, you can"," ",(0,a.jsx)("button",{type:"button",onClick:()=>g(!0),className:"text-accent hover:underline",children:"enter the JID manually"}),"."]}),M.length>0&&(0,a.jsx)("div",{className:"max-h-56 overflow-y-auto rounded border border-border bg-surface-3/40 divide-y divide-border",children:M.map(e=>{var t;let s;return(0,a.jsxs)("button",{type:"button",onClick:()=>{var t;let s;return t=e.remote_jid,s=M.find(e=>e.remote_jid===t),void v(e=>({remote_jid:t,agent_id:e.agent_id,label:e.label.trim()?e.label:s?.name??e.label}))},className:`w-full flex items-center gap-2 px-2 py-1.5 text-left text-xs transition-colors ${y.remote_jid===e.remote_jid?"bg-accent/20 text-fg":"hover:bg-surface-3 text-fg"}`,children:[(0,a.jsx)("span",{className:`w-5 h-5 rounded shrink-0 flex items-center justify-center ${e.is_group?"bg-violet-500/20 text-violet-700 dark:text-violet-300":"bg-emerald-500/20 text-emerald-700 dark:text-emerald-300"}`,children:e.is_group?(0,a.jsx)(en.A,{size:10}):(0,a.jsx)("span",{className:"text-[10px] font-bold",children:(e.name??"?").charAt(0).toUpperCase()})}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("div",{className:"truncate",children:e.name??(0,a.jsx)("span",{className:"text-fg-faint italic",children:"Unnamed"})}),(0,a.jsx)("div",{className:"text-[10px] text-fg-faint truncate font-mono",children:e.remote_jid})]}),e.last_message_at&&(0,a.jsx)("span",{className:"text-[9px] text-fg-faint shrink-0",children:(t=e.last_message_at,(s=Date.now()-t)<6e4?"just now":s>6048e5?new Date(t).toLocaleDateString():(function(e,t=7){let s=t9(e);return Math.abs(s-Date.now())>864e5*t?new Date(s).toLocaleDateString():t8(e)})(t).replace(/\sago$/,""))})]},e.remote_jid)})})]})),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)("label",{className:"block text-[10px] uppercase tracking-wide text-fg-faint font-semibold",children:"Agent"}),(0,a.jsxs)("select",{value:y.agent_id,onChange:e=>v(t=>({...t,agent_id:e.target.value})),className:"w-full px-2 py-1 text-xs bg-surface-3 rounded border border-border focus:border-accent outline-none",children:[(0,a.jsx)("option",{value:"",children:"Select agent…"}),R.map(e=>{let t=F(e),s=t.supported?"\uD83D\uDCF7 ":(t.classified," ");return(0,a.jsxs)("option",{value:e.id,children:[s,e.name]},e.id)})]}),(()=>{let e=R.find(e=>e.id===y.agent_id);if(!e)return null;let t=F(e);return t.supported?(0,a.jsxs)("p",{className:"text-[10px] text-emerald-700 dark:text-emerald-300 flex items-center gap-1",children:[(0,a.jsx)(ai.A,{size:10})," Vision-capable — WhatsApp images, stickers and image captions will be read by this agent."]}):t.classified?(0,a.jsxs)("p",{className:"text-[10px] text-amber-700 dark:text-amber-300",children:["This agent's model (",t.modelLabel??"none",") doesn't accept images. Text and image ",(0,a.jsx)("em",{children:"captions"}),"still reach it, but the image itself will be ignored. Switch the agent's model to a vision-capable one (e.g. gpt-4o, claude-3.5/4, gemini-1.5+) to enable image understanding."]}):(0,a.jsxs)("p",{className:"text-[10px] text-fg-faint",children:["Unknown model capabilities (",t.modelLabel??"no model",") — images will be forwarded; whether the model can interpret them depends on the upstream provider."]})})(),(0,a.jsx)("label",{className:"block text-[10px] uppercase tracking-wide text-fg-faint font-semibold",children:"Label (optional)"}),(0,a.jsx)("input",{value:y.label,onChange:e=>v(t=>({...t,label:e.target.value})),placeholder:P?"e.g. Catch-all triage":"e.g. Mom, Support Group",className:"w-full px-2 py-1 text-xs bg-surface-3 rounded border border-border focus:border-accent outline-none"})]}),N&&(0,a.jsx)("p",{className:"text-[11px] text-rose-700 dark:text-rose-300",children:N}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)("button",{onClick:U,disabled:!y.remote_jid||!y.agent_id,className:"px-3 py-1 text-xs rounded bg-accent text-white hover:bg-accent/90 disabled:opacity-40 disabled:cursor-not-allowed",children:"Add route"}),(0,a.jsx)("button",{onClick:()=>{j(!1),g(!1),w(null),v({remote_jid:"",agent_id:"",label:""})},className:"px-3 py-1 text-xs rounded text-fg-subtle hover:bg-surface-3",children:"Cancel"})]})]}),0===t.length&&!b&&(0,a.jsx)("p",{className:"text-[11px] text-fg-faint py-2",children:"No routes. Inbound messages will be ignored unless you add a catch-all route."}),t.map(e=>{let t=l.find(t=>t.id===e.agent_id)??null;return(0,a.jsx)(ad,{route:e,chatName:d.find(t=>t.remote_jid===e.remote_jid)?.name??null,agent:t,agentVision:t?F(t):null,onChangeAgent:async t=>{try{await r(e.id,{agent_id:t})}catch(s){e6({title:"Couldn't change route's agent",error:s,context:{panel:"bridges",action:"route.changeAgent",route_id:e.id,agent_id:t}})}},onToggleSilent:async t=>{try{await r(e.id,{silent_mode:t})}catch(s){e6({title:"Couldn't toggle silent mode",error:s,context:{panel:"bridges",action:"route.toggleSilent",route_id:e.id,silent_mode:t}})}},onChangeRespondTo:async t=>{try{await r(e.id,{respond_to:t})}catch(s){e6({title:"Couldn't change reply trigger",error:s,context:{panel:"bridges",action:"route.changeRespondTo",route_id:e.id,respond_to:t}})}},agents:l.filter(t=>t.id===e.agent_id||!L.has(t.id)),visionForAgent:e=>F(e),onDelete:async()=>{confirm("Delete this route? Incoming messages from this chat will be ignored.")&&await n(e.id)}},e.id)})]})}function ad({route:e,chatName:t,agent:s,agentVision:r,agents:n,visionForAgent:l,onChangeAgent:i,onToggleSilent:o,onChangeRespondTo:c,onDelete:d}){let u=e.label?.trim()||t||e.remote_jid,x="*"===e.remote_jid,m=u!==e.remote_jid,p=e.remote_jid.endsWith("@g.us");return(0,a.jsxs)("div",{className:"py-1.5 border-t border-border first:border-t-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("p",{className:"text-xs text-fg truncate",children:x?"Catch-all (everything else)":u}),m&&(0,a.jsx)("p",{className:"text-[10px] font-mono text-fg-faint truncate",children:e.remote_jid}),x&&(0,a.jsx)("p",{className:"text-[10px] text-fg-faint",children:"Matches any chat without an explicit route."})]}),(0,a.jsxs)("select",{value:s?.id??"",onChange:e=>void i(e.target.value),className:"px-1.5 py-0.5 text-[11px] bg-surface-3 rounded border border-border focus:border-accent outline-none max-w-[40%]",children:[!s&&(0,a.jsx)("option",{value:"",children:"(missing agent)"}),n.map(e=>{let t=l(e).supported?"\uD83D\uDCF7 ":"";return(0,a.jsxs)("option",{value:e.id,children:[t,e.name]},e.id)})]}),r&&(0,a.jsx)("span",{title:r.supported?`Vision-capable model (${r.modelLabel}) — reads images & stickers.`:r.classified?`Model ${r.modelLabel??""} doesn't accept images. Captions still reach the agent; the image itself is ignored.`:`Unknown capabilities for ${r.modelLabel??"this model"} — image handling depends on the upstream provider.`,className:`shrink-0 inline-flex items-center justify-center w-5 h-5 rounded ${r.supported?"text-emerald-600 dark:text-emerald-400":r.classified?"text-amber-600 dark:text-amber-400":"text-fg-faint"}`,children:(0,a.jsx)(ai.A,{size:11})}),(0,a.jsx)("button",{onClick:()=>void d(),className:"p-1 rounded text-fg-faint hover:text-rose-700 dark:hover:text-rose-400 hover:bg-surface-3",title:"Delete route",children:(0,a.jsx)(eQ.A,{size:11})})]}),(0,a.jsxs)("label",{className:"mt-1 flex items-start gap-2 cursor-pointer select-none px-0.5",children:[(0,a.jsx)("input",{type:"checkbox",className:"mt-0.5 rounded border-border",checked:e.silent_mode,onChange:e=>void o(e.target.checked)}),(0,a.jsxs)("span",{className:"text-[11px] text-fg-subtle leading-snug",children:[(0,a.jsx)("span",{className:"text-fg-muted font-medium",children:"Silent mode"})," — listen only, never auto-reply.",(0,a.jsxs)("span",{className:"block text-[10px] text-fg-faint",children:["The agent still receives every message and can run tools / update memory",p?" (with the sender's name prepended so it can tell group members apart)":"",", but nothing is sent back to ",p?"the group":"this chat",". Overrides the reply-trigger below."]})]})]}),(0,a.jsxs)("div",{className:`mt-1 flex items-start gap-2 px-0.5 ${e.silent_mode?"opacity-50":""}`,children:[(0,a.jsxs)("span",{className:"text-[11px] text-fg-subtle leading-snug flex-1",children:[(0,a.jsx)("span",{className:"text-fg-muted font-medium",children:"Reply trigger"})," — auto-reply when…",(0,a.jsx)("span",{className:"block text-[10px] text-fg-faint",children:"counterpart"===e.respond_to?p?"Another group member sends a message. The agent stays quiet on your own messages.":"Your counterpart sends a message. The agent stays quiet on your own messages.":"You send a message yourself (e.g. expand-my-draft assistant). The agent stays quiet on others'."})]}),(0,a.jsxs)("select",{value:e.respond_to,disabled:e.silent_mode,onChange:e=>void c(e.target.value),className:"px-1.5 py-0.5 text-[11px] bg-surface-3 rounded border border-border focus:border-accent outline-none disabled:cursor-not-allowed",children:[(0,a.jsx)("option",{value:"counterpart",children:p?"Group members":"Counterpart"}),(0,a.jsx)("option",{value:"user",children:"Me"})]})]})]})}function au(){let{bridges:e,loading:t,refresh:s,create:r,update:n,remove:l}=function(){let[e,t]=(0,i.useState)([]),[s,a]=(0,i.useState)(!1),r=(0,i.useCallback)(async()=>{a(!0);try{t(await c.FH.bridges.list())}finally{a(!1)}},[]);(0,i.useEffect)(()=>{r()},[r]);let n=(0,i.useCallback)(async e=>{let s=await c.FH.bridges.create(e);return t(e=>[...e,s]),s},[]),l=(0,i.useCallback)(async(e,s)=>{let a=await c.FH.bridges.update(e,s);return t(t=>t.map(t=>t.id===e?a:t)),a},[]);return{bridges:e,loading:s,refresh:r,create:n,update:l,remove:(0,i.useCallback)(async e=>{await c.FH.bridges.delete(e),t(t=>t.filter(t=>t.id!==e))},[]),pair:(0,i.useCallback)(async e=>{await c.FH.bridges.pair(e)},[])}}(),[o,d]=(0,i.useState)(null),[u,x]=(0,i.useState)(!1),[m,p]=(0,i.useState)(""),h=(0,i.useRef)(null);async function f(){let e=m.trim();if(!e)return;let t=await r({kind:"whatsapp",name:e});p(""),x(!1),d(t.id)}async function g(e){confirm(`Delete bridge "${e.name}"? This also removes its WhatsApp auth and all routes.`)&&(o===e.id&&d(null),await l(e.id))}async function b(e){await n(e.id,{enabled:!e.enabled})}if(eX("bridges","bridge",h),(0,i.useEffect)(()=>{let e=setInterval(()=>void s(),5e3);return()=>clearInterval(e)},[s]),o){let t=e.find(e=>e.id===o);return t?(0,a.jsx)(ao,{bridge:t,onBack:()=>{d(null),s()},onRename:e=>n(t.id,{name:e}),onToggleEnabled:()=>b(t)}):(d(null),null)}return(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[(0,a.jsxs)("div",{className:"border-b border-border px-4 py-3 flex items-center gap-2",children:[(0,a.jsx)(aa.A,{size:14,className:"text-fg-subtle"}),(0,a.jsx)("h2",{className:"text-sm font-semibold text-fg mr-auto",children:"Bridges"}),(0,a.jsxs)("button",{onClick:()=>x(!0),className:"px-2 py-1 text-xs rounded bg-accent/15 hover:bg-accent/25 text-accent flex items-center gap-1",children:[(0,a.jsx)(eV.A,{size:12})," New"]})]}),(0,a.jsxs)("div",{ref:h,className:"flex-1 overflow-y-auto px-4 py-3",children:[u&&(0,a.jsxs)("div",{className:"mb-3 rounded-lg border border-accent/30 bg-surface-2 p-3 space-y-2",children:[(0,a.jsx)("p",{className:"text-xs text-fg-subtle",children:"Create a WhatsApp bridge. After creating, enable it and scan the QR with WhatsApp → Linked Devices."}),(0,a.jsx)("input",{autoFocus:!0,value:m,onChange:e=>p(e.target.value),placeholder:"Name (e.g. Personal, Support)",className:"w-full px-2 py-1.5 text-sm bg-surface-3 rounded border border-border focus:border-accent outline-none",onKeyDown:e=>{"Enter"===e.key&&f(),"Escape"===e.key&&x(!1)}}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)("button",{onClick:f,className:"px-3 py-1 text-xs rounded bg-accent hover:bg-accent/90 text-white",children:"Create"}),(0,a.jsx)("button",{onClick:()=>{x(!1),p("")},className:"px-3 py-1 text-xs rounded text-fg-subtle hover:bg-surface-3",children:"Cancel"})]})]}),t&&0===e.length&&(0,a.jsx)("p",{className:"text-fg-faint text-sm py-6 text-center",children:"Loading…"}),!t&&0===e.length&&!u&&(0,a.jsxs)("div",{className:"text-fg-faint text-sm py-8 text-center space-y-2",children:[(0,a.jsx)("p",{children:"No bridges yet."}),(0,a.jsx)("p",{className:"text-xs text-fg-faint leading-relaxed",children:"A bridge connects an external comm channel (WhatsApp) to one of your agents. Each WhatsApp chat is routed to exactly one agent — unrouted messages are silently ignored."})]}),e.map(e=>(0,a.jsx)(ax,{bridge:e,onSelect:()=>d(e.id),onToggleEnabled:()=>b(e),onDelete:()=>g(e)},e.id))]})]})}function ax({bridge:e,onSelect:t,onToggleEnabled:s,onDelete:r}){return(0,a.jsx)("div",{"data-deep-link-id":e.id,className:"mb-2 rounded-lg border border-border bg-surface-2 hover:bg-surface-2/70 transition-colors",children:(0,a.jsxs)("div",{className:"flex items-center gap-3 px-3 py-2.5",children:[(0,a.jsx)("div",{className:"w-8 h-8 rounded-lg bg-gradient-to-br from-emerald-500 to-teal-600 flex items-center justify-center shrink-0",children:(0,a.jsx)(ar.A,{size:16,className:"text-white"})}),(0,a.jsxs)("button",{onClick:t,className:"flex-1 min-w-0 text-left",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"text-sm font-medium text-fg truncate",children:e.name}),(0,a.jsx)(am,{status:e.status})]}),(0,a.jsxs)("p",{className:"text-[11px] text-fg-faint truncate mt-0.5",children:[e.paired_id??"Not paired",e.last_error?` \xb7 ${e.last_error}`:""]})]}),(0,a.jsxs)("label",{className:"flex items-center gap-1.5 text-[11px] text-fg-subtle cursor-pointer select-none",children:[(0,a.jsx)("input",{type:"checkbox",checked:e.enabled,onChange:s,className:"accent-accent"}),e.enabled?"On":"Off"]}),(0,a.jsx)("button",{onClick:e=>{e.stopPropagation(),r()},className:"p-1.5 rounded text-fg-faint hover:text-rose-700 dark:hover:text-rose-400 hover:bg-surface-3",title:"Delete",children:(0,a.jsx)(eQ.A,{size:13})})]})})}function am({status:e}){let t={connected:{label:"connected",cls:"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300 border-emerald-500/30",icon:(0,a.jsx)(so.A,{size:9})},pairing:{label:"pairing",cls:"bg-sky-500/15 text-sky-700 dark:text-sky-300 border-sky-500/30",icon:(0,a.jsx)(ec.A,{size:9,className:"animate-spin"})},disconnected:{label:"disconnected",cls:"bg-fg-faint/15 text-fg-subtle border-fg-faint/30",icon:(0,a.jsx)(tI.A,{size:9})},error:{label:"error",cls:"bg-rose-500/15 text-rose-700 dark:text-rose-300 border-rose-500/30",icon:(0,a.jsx)(tL.A,{size:9})}}[e];return(0,a.jsxs)("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full border text-[9px] uppercase tracking-wide font-semibold ${t.cls}`,children:[t.icon,t.label]})}var ap=s(5736);let ah=["capabilities","plan_first","presentation","citation","self_config"],af="builtin:default";function ag(e){return e.startsWith("builtin:")}let ab={capabilities:{title:"Host capabilities",hint:"What the surrounding app can do — notifications, scheduling, watchers, document indexing."},plan_first:{title:"Plan-first acknowledgment",hint:"Acknowledge-before-acting rules, action principle, anti-fabrication, follow-through."},presentation:{title:"Output formatting",hint:"Markdown / HTML extras, code fences, images, maps, citation refs block."},citation:{title:"Source attribution",hint:"Anti-hallucination rules: every substantive claim must be tagged with its source."},self_config:{title:"Self-configuration proposals",hint:"Lets the agent propose config changes (install MCP, edit agent, set keys) for user approval."}};var aj=s(2298);function ay({harness:e,builtins:t,onSave:s,onClose:n}){let l=!!e,[o,c]=(0,i.useState)(e?.name??""),[d,u]=(0,i.useState)(e?.description??""),[x,m]=(0,i.useState)(()=>{if(!e){let e=t.find(e=>e.id===af)??t[0];return e?Object.fromEntries(ah.map(t=>[t,{...e.sections[t]}])):Object.fromEntries(ah.map(e=>[e,{enabled:!0,body:""}]))}return Object.fromEntries(ah.map(t=>[t,{...e.sections[t]}]))}),[p,h]=(0,i.useState)(null),[f,g]=(0,i.useState)(null),[b,j]=(0,i.useState)(!1),y=(0,i.useMemo)(()=>t.find(e=>e.id===af),[t]);function v(e,t){m(s=>({...s,[e]:{...s[e],...t}}))}async function N(){if(g(null),!o.trim())return void g("Name is required");j(!0);try{let t={name:o.trim(),description:d.trim()||void 0,sections:x};await s(t,e?.id),n()}catch(e){g(e instanceof Error?e.message:String(e))}finally{j(!1)}}return(0,i.useEffect)(()=>{let e=e=>{"Escape"===e.key&&n()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[n]),(0,a.jsx)("div",{className:"fixed inset-0 bg-black/60 flex items-start justify-center z-50 p-2 sm:p-4 overflow-y-auto",children:(0,a.jsxs)("div",{className:"bg-surface-2 border border-border rounded-2xl w-full max-w-2xl shadow-xl my-2 sm:my-4",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,a.jsx)("h3",{className:"text-sm font-semibold text-fg",children:l?`Edit harness — ${e?.name}`:"New harness"}),(0,a.jsx)("button",{onClick:n,className:"text-fg-subtle hover:text-fg transition-colors",children:(0,a.jsx)(z.A,{size:16})})]}),(0,a.jsxs)("div",{className:"p-4 space-y-3",children:[(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-3",children:[(0,a.jsxs)("label",{className:"block",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"Name"}),(0,a.jsx)("input",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent",value:o,onChange:e=>c(e.target.value),placeholder:"e.g. strict-citation",maxLength:120})]}),(0,a.jsxs)("label",{className:"block",children:[(0,a.jsx)("span",{className:"text-xs text-fg-subtle mb-1 block",children:"Description"}),(0,a.jsx)("input",{className:"w-full bg-surface-3 text-fg text-sm rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent",value:d,onChange:e=>u(e.target.value),placeholder:"Shown in the picker",maxLength:500})]})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)("p",{className:"text-xs text-fg-subtle",children:"Sections"}),ah.map(e=>{let t=x[e],s=ab[e],n=p===e;return(0,a.jsxs)("div",{className:"border border-border rounded-lg bg-surface-3 overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2",children:[(0,a.jsx)("input",{type:"checkbox",className:"rounded border-border",checked:t.enabled,onChange:t=>v(e,{enabled:t.target.checked}),onClick:e=>e.stopPropagation()}),(0,a.jsxs)("button",{type:"button",onClick:()=>h(n?null:e),className:"flex-1 flex items-center gap-2 text-left min-w-0",children:[(0,a.jsx)(r.A,{size:12,className:`shrink-0 transition-transform ${n?"rotate-0":"-rotate-90"}`}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsx)("p",{className:"text-xs font-medium text-fg truncate",children:s.title}),(0,a.jsx)("p",{className:"text-[11px] text-fg-faint truncate",children:s.hint})]})]}),y&&(0,a.jsx)("button",{type:"button",onClick:()=>{y&&v(e,{...y.sections[e]})},title:"Reset to built-in default",className:"p-1 text-fg-subtle hover:text-fg transition-colors shrink-0",children:(0,a.jsx)(aj.A,{size:11})})]}),n&&(0,a.jsx)("div",{className:"px-3 pb-3",children:(0,a.jsx)("textarea",{className:"w-full bg-surface text-fg text-xs rounded px-2 py-1.5 border border-border focus:outline-none focus:ring-1 focus:ring-accent font-mono resize-y",value:t.body,onChange:t=>v(e,{body:t.target.value}),rows:10,placeholder:"Section body…"})})]},e)})]}),f&&(0,a.jsx)("p",{className:"text-red-700 dark:text-red-400 text-xs",children:f})]}),(0,a.jsxs)("div",{className:"flex justify-end gap-2 px-4 pb-4",children:[(0,a.jsx)("button",{onClick:n,className:"px-3 py-1.5 text-sm text-fg-subtle hover:text-fg transition-colors",children:"Cancel"}),(0,a.jsx)("button",{onClick:N,disabled:b,className:"px-4 py-1.5 text-sm bg-accent hover:bg-accent-hover text-white rounded-lg transition-colors disabled:opacity-50",children:b?"Saving…":"Save"})]})]})})}function av(){let[e,t]=(0,i.useState)([]),[s,r]=(0,i.useState)("builtin:default"),[n,l]=(0,i.useState)(!0),[o,d]=(0,i.useState)(null),[u,x]=(0,i.useState)(null),m=(0,i.useCallback)(async()=>{l(!0),d(null);try{let e=await c.FH.harnesses.list();t(e.harnesses),r(e.default_harness_id)}catch(e){d(e instanceof Error?e.message:String(e))}finally{l(!1)}},[]);async function p(e){try{await c.FH.harnesses.setDefault(e),r(e)}catch(e){d(e instanceof Error?e.message:String(e))}}async function h(e){if(confirm("Delete this harness? Agents pointing at it will fall back to the global default."))try{await c.FH.harnesses.delete(e),await m()}catch(e){d(e instanceof Error?e.message:String(e))}}async function f(e){let t={name:`${e.name} (copy)`,description:e.description,sections:Object.fromEntries(ah.map(t=>[t,{...e.sections[t]}]))};try{let e=await c.FH.harnesses.create(t);await m(),x(e)}catch(e){d(e instanceof Error?e.message:String(e))}}async function g(e,t){t?await c.FH.harnesses.update(t,e):await c.FH.harnesses.create(e),await m()}return(0,i.useEffect)(()=>{m()},[m]),(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[(0,a.jsxs)("div",{className:"border-b border-border px-4 py-3 flex items-center gap-2",children:[(0,a.jsx)(tu.A,{size:14,className:"text-fg-subtle"}),(0,a.jsx)("h2",{className:"text-sm font-semibold text-fg mr-auto",children:"Harnesses"}),(0,a.jsxs)("button",{onClick:()=>x("new"),className:"flex items-center gap-1 text-xs text-accent hover:text-accent-hover transition-colors",children:[(0,a.jsx)(eV.A,{size:14})," New"]})]}),(0,a.jsx)("div",{className:"px-4 py-2 border-b border-border bg-surface-2/50 text-xs text-fg-muted",children:"Harnesses control the behavioral scaffolding (formatting rules, anti-fabrication, citation, self-config) wrapped around every agent's system prompt. Built-in presets are read-only — clone one to customize."}),(0,a.jsxs)("div",{className:"flex-1 overflow-y-auto px-4 py-2",children:[n&&0===e.length&&(0,a.jsx)("p",{className:"text-fg-faint text-sm py-6 text-center",children:"Loading…"}),o&&(0,a.jsx)("p",{className:"text-red-700 dark:text-red-400 text-xs mb-2 px-1",children:o}),!n&&0===e.length&&(0,a.jsx)("p",{className:"text-fg-faint text-sm py-6 text-center",children:"No harnesses yet"}),e.map(e=>{let t=ag(e.id),r=e.id===s,n=ah.filter(t=>e.sections[t]?.enabled).length;return(0,a.jsxs)("div",{className:"flex items-center gap-3 py-2.5 border-b border-border/60 group",children:[(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 mb-0.5",children:[(0,a.jsx)("span",{className:"text-sm font-medium text-fg truncate",children:e.name}),t&&(0,a.jsx)(ap.A,{size:10,className:"text-fg-faint shrink-0"}),r&&(0,a.jsx)(ti.A,{size:11,className:"text-yellow-700 dark:text-yellow-400 fill-yellow-400 shrink-0"}),(0,a.jsxs)("span",{className:"text-[10px] text-fg-faint shrink-0",children:[n,"/",ah.length," sections"]})]}),e.description&&(0,a.jsx)("p",{className:"text-xs text-fg-subtle truncate",children:e.description})]}),(0,a.jsxs)("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 pointer-coarse:opacity-100 transition-opacity shrink-0",children:[!r&&(0,a.jsx)("button",{onClick:()=>p(e.id),className:"p-1 text-fg-subtle hover:text-yellow-700 dark:hover:text-yellow-400 transition-colors",title:"Set as global default",children:(0,a.jsx)(ti.A,{size:13})}),t?(0,a.jsx)("button",{onClick:()=>f(e),className:"px-2 py-0.5 text-[11px] text-accent hover:text-accent-hover transition-colors",title:"Clone to edit",children:"Clone"}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{onClick:()=>x(e),className:"p-1 text-fg-subtle hover:text-fg transition-colors",title:"Edit",children:(0,a.jsx)(eY.A,{size:13})}),(0,a.jsx)("button",{onClick:()=>h(e.id),className:"p-1 text-fg-subtle hover:text-red-700 dark:hover:text-red-400 transition-colors",title:"Delete",children:(0,a.jsx)(eQ.A,{size:13})})]})]})]},e.id)})]}),null!==u&&(0,a.jsx)(ay,{harness:"new"===u?void 0:u,builtins:e.filter(e=>ag(e.id)),onSave:g,onClose:()=>x(null)})]})}function aN(){let e=function(){let[e,t]=(0,i.useState)(_);return(0,i.useEffect)(()=>{let e=e=>t(e);return C.add(e),t(_),()=>{C.delete(e)}},[]),e}(),[t,s]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{if(e>0)return void s(!0);let t=setTimeout(()=>s(!1),200);return()=>clearTimeout(t)},[e]),(0,a.jsx)("div",{className:`pointer-events-none fixed top-0 left-0 right-0 h-[2px] z-50 transition-opacity duration-150 ${t?"opacity-100":"opacity-0"}`,"aria-hidden":!t,children:(0,a.jsx)("div",{className:"jarela-progress h-full w-full"})})}var aw=s(4526),ak=s(6395);function aS(){return"u"<typeof Notification?"unsupported":Notification.permission}let a_="jarela:notif-banner-dismissed";function aC(){let[e,t]=(0,i.useState)("default"),[s,r]=(0,i.useState)(!0),[n,l]=(0,i.useState)(!1);async function o(){if("u">typeof Notification)try{let e=await Notification.requestPermission();t(e),"granted"===e&&new Notification("Jarela notifications enabled",{body:"You'll see a ping when an agent finishes a turn while you're away.",icon:"/icon-192.png",tag:"jarela-enable"})}catch(e){console.warn("[notifications] permission request failed:",e)}}return((0,i.useEffect)(()=>{t(aS()),r("u">typeof localStorage&&"1"===localStorage.getItem(a_));let e=()=>t(aS());return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)},[]),"unsupported"===e||"granted"===e||s)?null:(0,a.jsx)("div",{className:"absolute top-9 left-0 right-0 z-30 mx-auto max-w-2xl px-4 mt-2 pointer-events-none",children:(0,a.jsxs)("div",{className:"pointer-events-auto rounded-lg border border-amber-700/60 bg-amber-950/40 backdrop-blur px-3 py-2 flex items-center gap-2 shadow-lg",children:["denied"===e?(0,a.jsx)(aw.A,{size:14,className:"text-rose-700 dark:text-rose-400 shrink-0"}):(0,a.jsx)(sQ.A,{size:14,className:"text-amber-700 dark:text-amber-400 shrink-0"}),(0,a.jsx)("p",{className:"text-xs text-fg mr-auto",children:"denied"===e?"OS notifications are blocked. In-app pop-ups still work; for system-level alerts when Jarela isn't focused, allow Notifications via the lock icon in the URL bar.":"Enable OS notifications to also get pinged when Jarela isn't focused (in-app pop-ups already work)."}),"default"===e&&(0,a.jsxs)("button",{onClick:o,className:"inline-flex items-center gap-1 px-2.5 py-1 text-xs rounded bg-amber-600 hover:bg-amber-500 text-white",children:[(0,a.jsx)(ak.A,{size:11})," Enable"]}),n&&(0,a.jsx)("span",{className:"text-[10px] text-emerald-700 dark:text-emerald-400",children:"test sent"}),(0,a.jsx)("button",{onClick:function(){r(!0),localStorage.setItem(a_,"1")},className:"p-1 text-fg-subtle hover:text-fg",title:"Dismiss",children:(0,a.jsx)(z.A,{size:12})})]})})}function aA(){let[e,t]=(0,i.useState)("default");return(0,i.useEffect)(()=>{t(aS())},[]),(0,a.jsxs)("button",{onClick:function(){if(f({kind:"info",source:"system",sourceLabel:"Test",title:"Test notification",body:"If you see this card slide in, in-app pop-ups are working.",agent_id:null,thread_id:null,ttl:6e3}),"u">typeof Notification&&"granted"===Notification.permission)try{new Notification("Jarela test",{body:"If you see this, OS notifications are wired correctly.",icon:"/icon-192.png",tag:"jarela-test"})}catch{}},title:"granted"===e?"Fires both an in-app toast and an OS notification":"Fires an in-app toast (OS notifications require permission)",className:"inline-flex items-center gap-1 px-2 py-1 text-[11px] rounded border border-border text-fg-subtle hover:text-fg hover:bg-surface-3",children:[(0,a.jsx)(sQ.A,{size:11})," Test notification"]})}let aE="jarela:crypto-fallback-banner-dismissed";function aT(){let[e,t]=(0,i.useState)(!1),[s,r]=(0,i.useState)(!0);return((0,i.useEffect)(()=>{r("u">typeof localStorage&&"1"===localStorage.getItem(aE));let e=!1;return fetch("/api/v1/health").then(e=>e.json()).then(s=>{e||s?.crypto?.source==="keyfile"&&t(!0)}).catch(()=>{}),()=>{e=!0}},[]),!e||s)?null:(0,a.jsx)("div",{className:"fixed left-0 right-0 z-30 px-3 pt-2 pointer-events-none",style:{top:"calc(3rem + var(--app-safe-top))"},children:(0,a.jsxs)("div",{className:"mx-auto max-w-4xl pointer-events-auto flex items-start gap-2 border border-amber-900/40 rounded-lg bg-amber-950/60 backdrop-blur px-3 py-2 text-xs text-amber-800 dark:text-amber-200",children:[(0,a.jsx)(T.A,{size:14,className:"mt-0.5 shrink-0"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("span",{className:"font-medium",children:"At-rest encryption is using the keyfile fallback."})," ","The master key lives next to the database because the OS keychain was unavailable. Protect the data directory like you would the secrets it contains."," ",(0,a.jsx)("a",{href:"https://github.com/Pcordeironeto/langGUI/blob/main/docs/adr/0005-encrypt-secrets-at-rest.md",target:"_blank",rel:"noreferrer",className:"underline",children:"Why?"})]}),(0,a.jsx)("button",{type:"button",onClick:()=>{localStorage.setItem(aE,"1"),r(!0)},className:"shrink-0 rounded p-0.5 hover:bg-amber-900/40","aria-label":"Dismiss warning",children:(0,a.jsx)(z.A,{size:14})})]})})}var a$=s(825);let az="jarela:update-banner-dismissed-for";function aI(){let[e,t]=(0,i.useState)(null),[s,r]=(0,i.useState)(!1);if((0,i.useEffect)(()=>{let e=!1;return fetch("/api/v1/update").then(e=>e.json()).then(s=>{if(e||!s?.behind||!s.latest)return;let a="main"===s.channel&&s.latestCommit?.sha?`${s.latest}@${s.latestCommit.sha}`:s.latest;("u">typeof localStorage?localStorage.getItem(az):null)===a&&r(!0),t(s)}).catch(()=>{}),()=>{e=!0}},[]),!e||!e.behind||!e.latest||s)return null;let n="main"===e.channel,l=e.latestCommit?.sha?.slice(0,7),o=e.currentCommit?.slice(0,7);return(0,a.jsx)("div",{className:"fixed left-0 right-0 z-30 px-3 pt-2 pointer-events-none",style:{top:"calc(3rem + var(--app-safe-top))"},children:(0,a.jsxs)("div",{className:"mx-auto max-w-4xl pointer-events-auto flex items-start gap-2 border border-emerald-900/40 rounded-lg bg-emerald-950/60 backdrop-blur px-3 py-2 text-xs text-emerald-800 dark:text-emerald-200",children:[(0,a.jsx)(a$.A,{size:14,className:"mt-0.5 shrink-0"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("span",{className:"font-medium",children:n?"Experimental update available:":"Update available:"})," ",n&&l?(0,a.jsxs)(a.Fragment,{children:[o??e.current," → ",l," (",e.latest,")."]}):(0,a.jsxs)(a.Fragment,{children:[e.current," → ",e.latest,"."]})," ","Run ",(0,a.jsx)("code",{className:"font-mono text-[11px]",children:"jarela update"})," ","(or ",(0,a.jsx)("code",{className:"font-mono text-[11px]",children:n?"npm i -g github:CircuitWall/jarela#main":"npm i -g @circuitwall/jarela@latest"}),") and restart."]}),(0,a.jsx)("button",{type:"button",onClick:()=>{let t=n&&e.latestCommit?.sha?`${e.latest}@${e.latestCommit.sha}`:e.latest;t&&localStorage.setItem(az,t),r(!0)},className:"shrink-0 rounded p-0.5 hover:bg-emerald-900/40","aria-label":"Dismiss update notice",children:(0,a.jsx)(z.A,{size:14})})]})})}var aF=s(7606);async function aL(){let e=new AbortController,t=setTimeout(()=>e.abort(),8e3);try{return(await fetch("/api/v1/health",{cache:"no-store",signal:e.signal})).ok}catch{return!1}finally{clearTimeout(t)}}function aR(){let[e,t]=(0,i.useState)(!1),s=(0,i.useRef)(!1),r=(0,i.useRef)(0);return((0,i.useEffect)(()=>{let e=!1,a=null,n=async()=>{let l=await aL();if(!e){if(!l){r.current+=1,r.current>=3?(s.current=!0,t(!0),a=setTimeout(n,2e3)):a=setTimeout(n,3e3);return}if(r.current=0,s.current)return void window.location.reload();t(!1),a=setTimeout(n,2e4)}};n();let l=()=>{"visible"===document.visibilityState&&(a&&clearTimeout(a),n())};return document.addEventListener("visibilitychange",l),()=>{e=!0,a&&clearTimeout(a),document.removeEventListener("visibilitychange",l)}},[]),e)?(0,a.jsx)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-black/50 backdrop-blur-sm",children:(0,a.jsxs)("div",{className:"mx-4 max-w-sm w-full flex flex-col items-center gap-3 rounded-xl border border-border bg-surface text-fg px-6 py-5 text-center shadow-lg",children:[(0,a.jsx)(aF.A,{size:28,className:"text-amber-500"}),(0,a.jsx)("div",{className:"text-sm font-medium",children:"Server unavailable"}),(0,a.jsx)("div",{className:"text-xs text-fg-muted",children:"Lost connection to Jarela. Retrying…"}),(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-fg-subtle",children:[(0,a.jsx)(ec.A,{size:14,className:"animate-spin"}),(0,a.jsx)("span",{children:"Reconnecting"})]}),(0,a.jsx)("button",{type:"button",onClick:()=>window.location.reload(),className:"mt-1 text-xs underline text-fg-subtle hover:text-fg",children:"Reload now"})]})}):null}let aH=["from-violet-500 to-indigo-600","from-blue-500 to-cyan-600","from-emerald-500 to-teal-600","from-orange-500 to-amber-600","from-rose-500 to-pink-600","from-fuchsia-500 to-purple-600"];function aP(){let e=(function(){let[e,t]=(0,i.useState)(d);return(0,i.useEffect)(()=>{let e=e=>t(e);return u.add(e),t(d),()=>{u.delete(e)}},[]),e})().slice(-4);return(0,a.jsx)("div",{className:"fixed bottom-4 right-4 z-50 flex flex-col-reverse gap-2 pointer-events-none w-[360px] max-w-[calc(100vw-2rem)]","aria-live":"polite",children:e.map(e=>(0,a.jsx)(aO,{toast:e},e.id))})}function aO({toast:e}){let{dispatch:t}=(0,o.U)(),[s,n]=(0,i.useState)(!1),[l,c]=(0,i.useState)(!1),d=(0,i.useRef)(null),u=(0,i.useRef)(e.ttl),[x]=(0,i.useState)(()=>Date.now()),m=(0,i.useRef)(x);function p(){c(!0),setTimeout(()=>g(e.id),200)}function h(){if(e.href){let s=k(e.href);s.tab&&(t({type:"SET_TAB",tab:s.tab}),t({type:"SET_SELECTION",tab:s.tab,itemId:s.item??null})),s.hash&&(window.history.replaceState(null,"",`${window.location.pathname}${window.location.search}#${s.hash}`),window.dispatchEvent(new HashChangeEvent("hashchange")))}else e.thread_id&&e.agent_id?t({type:"SELECT_THREAD",threadId:e.thread_id,agentId:e.agent_id}):e.agent_id&&(t({type:"SET_AGENT",agentId:e.agent_id}),t({type:"SET_TAB",tab:"chat"}));p()}(0,i.useEffect)(()=>{if(!(e.ttl<=0)){if(s){d.current&&clearTimeout(d.current),u.current-=Date.now()-m.current;return}return m.current=Date.now(),d.current=setTimeout(()=>{c(!0),setTimeout(()=>g(e.id),200)},Math.max(u.current,0)),()=>{d.current&&clearTimeout(d.current)}}},[s,e.id,e.ttl]);let f="error"===e.kind,b=f&&(null!=e.details||null!=e.reportInput),[j,y]=(0,i.useState)(!1),[v,N]=(0,i.useState)(!1);async function w(t){if(t.stopPropagation(),!e.reportInput)return;let{body:s}=await e7(e.reportInput);try{await navigator.clipboard.writeText(s),N(!0),setTimeout(()=>N(!1),1500)}catch{let e=window.open("","_blank","noopener,noreferrer,width=600,height=400");e&&(e.document.body.innerText=s)}}async function S(t){if(t.stopPropagation(),!e.reportInput)return;let{url:s}=await e7(e.reportInput);window.open(s,"_blank","noopener,noreferrer")}let _=e.agent_id?(0,a.jsx)("div",{className:`w-9 h-9 rounded-lg bg-gradient-to-br ${function(e){let t=0;for(let s=0;s<e.length;s++)t=31*t+e.charCodeAt(s)|0;return aH[Math.abs(t)%aH.length]}(e.agent_id)} flex items-center justify-center text-sm font-bold text-white shrink-0`,children:e.title.charAt(0).toUpperCase()}):(0,a.jsx)("div",{className:"w-9 h-9 rounded-lg bg-surface-3 flex items-center justify-center shrink-0",children:f?(0,a.jsx)(tL.A,{size:16,className:"text-rose-700 dark:text-rose-400"}):(0,a.jsx)(ea.A,{size:16,className:"text-fg-muted"})});return(0,a.jsxs)("div",{onMouseEnter:()=>n(!0),onMouseLeave:()=>n(!1),onClick:h,role:"button",tabIndex:0,onKeyDown:e=>{"Enter"===e.key&&h()},className:`pointer-events-auto group relative cursor-pointer rounded-xl border bg-surface-2/95 backdrop-blur shadow-2xl transition-all duration-200 ${l?"opacity-0 translate-x-2":"opacity-100 translate-x-0"} ${f?"border-rose-700/60":"border-border hover:border-border"}`,children:[(0,a.jsxs)("div",{className:"flex items-start gap-3 px-3 py-2.5",children:[_,(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("p",{className:"text-[10px] uppercase tracking-wider text-fg-faint font-semibold truncate",children:e.sourceLabel}),(0,a.jsx)("p",{className:"text-sm font-medium text-fg truncate",children:e.title}),e.preview?(0,a.jsxs)("p",{className:`text-xs ${f?"text-rose-700 dark:text-rose-300/90":"text-fg-muted"} line-clamp-2 mt-0.5 italic`,children:["“",e.preview,"”"]}):(0,a.jsx)("p",{className:`text-xs ${f?"text-rose-700 dark:text-rose-300/90":"text-fg-subtle"} line-clamp-2 mt-0.5`,children:e.body}),e.href?(0,a.jsx)("p",{className:"text-[10px] text-accent/80 mt-1",children:e.hrefLabel??"Open →"}):e.agent_id||e.thread_id?(0,a.jsx)("p",{className:"text-[10px] text-accent/80 mt-1",children:"Open chat →"}):null,b&&(0,a.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),y(e=>!e)},className:"mt-1.5 inline-flex items-center gap-1 text-[10px] text-rose-700 dark:text-rose-300/90 hover:text-rose-900 dark:hover:text-rose-200","aria-expanded":j,children:[j?(0,a.jsx)(r.A,{size:11}):(0,a.jsx)(W.A,{size:11}),j?"Hide details":"Show details"]})]}),(0,a.jsx)("button",{onClick:e=>{e.stopPropagation(),p()},className:"opacity-0 group-hover:opacity-100 pointer-coarse:opacity-100 transition-opacity p-0.5 -mr-1 -mt-0.5 text-fg-faint hover:text-fg","aria-label":"Dismiss",children:(0,a.jsx)(z.A,{size:13})})]}),b&&j&&(0,a.jsxs)("div",{className:"border-t border-rose-700/30 bg-rose-50/40 dark:bg-rose-950/20 px-3 py-2 space-y-2",onClick:e=>e.stopPropagation(),children:[e.details&&(0,a.jsx)("pre",{className:"text-[10px] leading-snug text-rose-900 dark:text-rose-200/90 max-h-40 overflow-auto whitespace-pre-wrap break-words font-mono bg-surface-3/60 rounded p-2",children:e.details}),e.reportInput&&(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)("button",{type:"button",onClick:w,className:"inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded-md bg-surface-3 hover:bg-surface-4 text-fg border border-border",children:[(0,a.jsx)(ei.A,{size:11}),v?"Copied":"Copy report"]}),(0,a.jsxs)("button",{type:"button",onClick:S,className:"inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded-md bg-rose-600 hover:bg-rose-700 text-white",title:"Opens a pre-filled GitHub issue",children:[(0,a.jsx)(sd.A,{size:11}),"Report this issue"]})]})]}),e.ttl>0&&!l&&(0,a.jsx)("div",{className:"absolute bottom-0 left-0 right-0 h-[2px] origin-left rounded-bl-xl",style:{backgroundColor:f?"#fb7185":"#3b82f6",animation:s?"none":`jarela-toast-shrink ${e.ttl}ms linear forwards`}})]})}var aM=s(5494),aD=s(5045),aU=s(1827),aJ=s(7603),aq=s(8890),aG=s(299),aW=s(737);let aB={chat:(0,a.jsx)(aM.A,{size:13}),agents:(0,a.jsx)(ea.A,{size:13}),memory:(0,a.jsx)(aD.A,{size:13}),documents:(0,a.jsx)(tz.A,{size:13}),models:(0,a.jsx)(tl.A,{size:13}),mcp:(0,a.jsx)(tu.A,{size:13}),extensions:(0,a.jsx)(tu.A,{size:13}),tools:(0,a.jsx)(tu.A,{size:13}),connections:(0,a.jsx)(sA.A,{size:13}),tasks:(0,a.jsx)(sV.A,{size:13}),bridges:(0,a.jsx)(aa.A,{size:13}),profile:(0,a.jsx)(er.A,{size:13}),harness:(0,a.jsx)(aU.A,{size:13})},aV={chat:"Chat",agents:"Agents",memory:"Memory",documents:"Documents",models:"Models",mcp:"MCP",extensions:"Extensions",tools:"Tools",connections:"Connections",tasks:"Tasks",bridges:"Bridges",profile:"Profile",harness:"Harness"},aK=["chat","agents","memory","documents","tasks","bridges","profile"],aY=["connections","models","tools","harness"],aQ="jarela.menu.advanced",aZ=["from-violet-500 to-indigo-600","from-blue-500 to-cyan-600","from-emerald-500 to-teal-600","from-orange-500 to-amber-600","from-rose-500 to-pink-600","from-fuchsia-500 to-purple-600"];function aX({activeAgentId:e,onSelect:t}){let[s,r]=(0,i.useState)([]),n=y();return((0,i.useEffect)(()=>{let e=!1,t=()=>c.FH.agents.list().then(t=>{e||r(t)}).catch(console.error);function s(){t()}return t(),window.addEventListener("jarela:agents-changed",s),()=>{e=!0,window.removeEventListener("jarela:agents-changed",s)}},[]),0===s.length)?(0,a.jsx)("p",{className:"text-fg-faint text-xs text-center py-6 select-none px-3",children:"No agents yet — create one in the Agents tab."}):(0,a.jsx)("div",{className:"py-1.5 space-y-0.5 px-2",children:s.map(s=>{let r=s.id===e,l=n.get(s.id)??0;return(0,a.jsxs)("button",{onClick:()=>t(s.id),className:`w-full flex items-center gap-3 px-2.5 py-2.5 rounded-xl transition-colors text-left ${r?"bg-accent/15 border border-accent/30":"hover:bg-surface-3 border border-transparent"}`,children:[(0,a.jsxs)("div",{className:"relative shrink-0",children:[s.icon?(0,a.jsx)("img",{src:s.icon,alt:s.name,className:"w-9 h-9 rounded-lg object-cover"}):(0,a.jsx)("div",{className:`w-9 h-9 rounded-lg flex items-center justify-center text-sm font-bold text-white bg-gradient-to-br select-none ${function(e){let t=0;for(let s=0;s<e.length;s++)t=31*t+e.charCodeAt(s)|0;return aZ[Math.abs(t)%aZ.length]}(s.id)}`,children:s.name.charAt(0).toUpperCase()}),l>0&&(0,a.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[16px] h-[16px] px-1 rounded-full bg-rose-500 border border-surface-2 text-[10px] font-bold text-white flex items-center justify-center leading-none",children:l>9?"9+":l})]}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,a.jsx)("span",{className:"text-sm font-medium truncate text-fg",children:s.name}),s.is_default&&(0,a.jsx)("span",{className:"text-[9px] uppercase tracking-wide text-accent font-semibold shrink-0",children:"default"})]}),s.identity?(0,a.jsx)("p",{className:"text-[11px] text-fg-faint truncate leading-tight mt-0.5",children:s.identity}):(0,a.jsx)("p",{className:"text-[11px] text-fg-faint italic leading-tight mt-0.5",children:"No persona"})]}),r&&(0,a.jsx)("div",{className:"w-1.5 h-1.5 rounded-full bg-accent shrink-0"})]},s.id)})})}function a0({activeTab:e,agentId:t,showTools:s,showThinking:n,onClose:l,onAgentChange:o,onSetTab:c,onShowToolsChange:d,onShowThinkingChange:u}){let[x,m]=(0,i.useState)(!0);(0,i.useEffect)(()=>{try{let e=window.localStorage.getItem(aQ);null!=e&&m("1"===e)}catch{}},[]),(0,i.useEffect)(()=>{if(aY.includes(e)&&!x){m(!0);try{window.localStorage.setItem(aQ,"1")}catch{}}},[e]);let p=t=>(0,a.jsxs)("button",{onClick:()=>c(t),title:aV[t],"aria-label":aV[t],className:`min-w-0 flex flex-col items-center justify-center gap-1 rounded-lg py-2 px-1 transition-colors ${e===t?"bg-surface-3 text-fg ring-1 ring-border":"text-fg-faint hover:text-fg-muted hover:bg-surface-3/50"}`,children:[(0,a.jsx)("span",{className:"shrink-0",children:aB[t]}),(0,a.jsx)("span",{className:"text-[10px] leading-none truncate max-w-full",children:aV[t]})]},t);return(0,a.jsxs)("div",{className:"glass-elevated fixed right-0 bottom-0 w-full sm:w-[26rem] max-w-full border-l border-border/60 z-40 flex flex-col pb-safe",style:{top:"calc(3rem + var(--app-safe-top))"},children:[(0,a.jsx)("div",{className:"grid grid-cols-4 sm:grid-cols-6 gap-1.5 px-2 py-2 border-b border-border shrink-0",children:aK.map(p)}),(0,a.jsxs)("div",{className:"border-b border-border shrink-0",children:[(0,a.jsxs)("button",{type:"button",onClick:()=>{m(e=>{let t=!e;try{window.localStorage.setItem(aQ,t?"1":"0")}catch{}return t})},"aria-expanded":x,className:"w-full flex items-center justify-between px-3 py-2 text-[11px] uppercase tracking-wide text-fg-faint hover:text-fg-muted transition-colors",children:[(0,a.jsx)("span",{className:"font-medium",children:"Advanced"}),(0,a.jsx)(r.A,{size:12,className:`transition-transform ${x?"rotate-0":"-rotate-90"}`})]}),x&&(0,a.jsx)("div",{className:"grid grid-cols-4 gap-1.5 px-2 pb-2",children:aY.map(p)})]}),(0,a.jsx)("div",{className:"flex-1 overflow-y-auto min-h-0",children:(0,a.jsx)(aX,{activeAgentId:t,onSelect:e=>{o(e),c("chat"),l()}})}),(0,a.jsxs)("div",{className:"border-t border-border px-3 py-3 shrink-0",children:[(0,a.jsx)("p",{className:"text-[11px] text-fg-faint mb-1.5 font-medium uppercase tracking-wide",children:"Display"}),(0,a.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,a.jsx)(a1,{}),(0,a.jsxs)("label",{className:"inline-flex items-center gap-2 cursor-pointer text-xs text-fg-muted",children:[(0,a.jsx)("input",{type:"checkbox",className:"rounded border-border",checked:s,onChange:e=>d(e.target.checked)}),"Show tool events"]}),(0,a.jsxs)("label",{className:"inline-flex items-center gap-2 cursor-pointer text-xs text-fg-muted",children:[(0,a.jsx)("input",{type:"checkbox",className:"rounded border-border",checked:n,onChange:e=>u(e.target.checked)}),"Show thinking"]}),(0,a.jsx)("div",{className:"pt-1.5",children:(0,a.jsx)(aA,{})})]})]})]})}function a1(){let{theme:e,setTheme:t}=(0,aW.D)(),s=[{value:"light",label:"Light",icon:(0,a.jsx)(aJ.A,{size:12})},{value:"dark",label:"Dark",icon:(0,a.jsx)(aq.A,{size:12})},{value:"system",label:"System",icon:(0,a.jsx)(aG.A,{size:12})}];return(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-fg-muted",children:[(0,a.jsx)("span",{className:"shrink-0",children:"Theme"}),(0,a.jsx)("div",{className:"flex flex-1 rounded-md border border-border overflow-hidden",children:s.map(s=>(0,a.jsxs)("button",{onClick:()=>t(s.value),title:s.label,className:`flex-1 inline-flex items-center justify-center gap-1 py-1 text-[11px] transition-colors ${e===s.value?"bg-surface-3 text-fg":"text-fg-faint hover:text-fg-muted hover:bg-surface-3/50"}`,children:[s.icon,(0,a.jsx)("span",{children:s.label})]},s.value))})]})}function a2(){var e;let t,s,{state:d,dispatch:u}=(0,o.U)();!function(){let{state:e,dispatch:t}=(0,o.U)(),s=(0,i.useRef)(null);(0,i.useEffect)(()=>{function e(){let e=k(`${window.location.search}${window.location.hash}`),s=e.tab??"chat";S.includes(s)&&(t({type:"SET_TAB",tab:s}),t({type:"SET_SELECTION",tab:s,itemId:e.item??null}))}return e(),window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[]),(0,i.useEffect)(()=>{var t;let a,r,n,l=e.selectedItem[e.activeTab]??null,i=window.location.hash.replace(/^#/,"")||null,o=(t=e.activeTab,a=new URLSearchParams,"chat"!==t&&a.set("tab",t),l&&a.set("item",l),r=a.toString(),n=i?`#${i.replace(/^#/,"")}`:"",`/${r?`?${r}`:""}${n}`);`${window.location.pathname}${window.location.search}${window.location.hash}`!==o&&s.current!==o&&(s.current=o,window.history.replaceState(null,"",o))},[e.activeTab,e.selectedItem])}();let{threadId:p,loading:g,error:b}=function(e,t){let[s,a]=(0,i.useState)(null),[r,n]=(0,i.useState)(!1),[l,o]=(0,i.useState)(null);return(0,i.useEffect)(()=>{if(a(null),o(null),!e)return void n(!1);n(!0);let s=!1;return(async()=>{try{if(t)try{let r=await c.FH.threads.get(t,{limit:1});if(s)return;if(r.agent_id===e)return void a(t)}catch{}let r=await c.FH.agents.getThread(e);if(s)return;a(r.thread_id)}catch(e){if(s)return;o(String(e)),console.error(e)}finally{if(s)return;n(!1)}})(),()=>{s=!0}},[e,t]),{threadId:s,loading:r,error:l}}(d.activeAgentId,d.activeThreadId),[y,w]=(0,i.useState)(!1),[_,C]=(0,i.useState)(!1),[A,E]=(0,i.useState)(!0),[T,$]=(0,i.useState)(!0),z=(0,i.useRef)(null),[I,F]=(0,i.useState)(()=>new Set([d.activeTab]));(0,i.useEffect)(()=>{F(e=>e.has(d.activeTab)?e:new Set(e).add(d.activeTab))},[d.activeTab]);let L=function(){let[e,t]=(0,i.useState)(()=>j());return(0,i.useEffect)(()=>{let e=()=>t(j());return m.add(e),e(),()=>{m.delete(e)}},[]),e}(),[R,H]=(0,i.useState)([]);(0,i.useEffect)(()=>{let e=!1,t=()=>c.FH.agents.list().then(t=>{e||H(t)}).catch(()=>{});function s(){t()}return t(),window.addEventListener("jarela:agents-changed",s),()=>{e=!0,window.removeEventListener("jarela:agents-changed",s)}},[]);let P=(0,i.useRef)([]);P.current=R;let O=(0,i.useRef)(d);O.current=d;let M=(0,i.useCallback)(()=>{},[]),D=(0,i.useCallback)(e=>{u({type:"SET_AGENT",agentId:e})},[u]);(0,i.useEffect)(()=>{function e(e){let t=e.detail;t?.agentId&&(t.threadId?u({type:"SELECT_THREAD",threadId:t.threadId,agentId:t.agentId}):(u({type:"SET_AGENT",agentId:t.agentId}),u({type:"SET_TAB",tab:"chat"})))}return window.addEventListener("jarela:focus-agent",e),()=>window.removeEventListener("jarela:focus-agent",e)},[u]),(0,i.useEffect)(()=>{var e;"chat"===d.activeTab&&d.activeAgentId&&(e=d.activeAgentId,x.has(e)&&(x.delete(e),h()))},[d.activeTab,d.activeAgentId]),e={shouldNotify:e=>{if("task_completed"===e.type)return!0;let t="u">typeof document&&(document.hidden||!document.hasFocus()),s=e.agent_id,a="chat"===O.current.activeTab&&null!==s&&s===O.current.activeAgentId;return t||!a},resolveAgentName:e=>{if(!e)return(0,e0.fj)();let t=P.current.find(t=>t.id===e);return t?.name??(0,e0.fj)()},resolveAgentIcon:e=>{if(!e)return null;let t=P.current.find(t=>t.id===e);return t?.icon??null}},t=(0,i.useRef)(function(){try{let e=window.localStorage.getItem(v),t=e?Number(e):0;if(!Number.isFinite(t)||t<=0)return 0;return Math.max(t,Date.now()-216e5)}catch{return 0}}()),(s=(0,i.useRef)(e)).current=e,(0,i.useEffect)(()=>{if("u"<typeof EventSource)return;let e=null,a=!1,r=500,n=null;function l(){a||((e=new EventSource(`/api/v1/events?since=${t.current}`)).onmessage=e=>{let a;r=500;try{a=JSON.parse(e.data)}catch{return}if(!a.ts)return;if("thread_message_added"===a.type){t.current=Math.max(t.current,a.ts),N(t.current),window.dispatchEvent(new CustomEvent("jarela:thread-updated",{detail:{thread_id:a.thread_id,agent_id:a.agent_id}}));let e=s.current.resolveAgentName(a.agent_id);f({kind:"info",source:"system",sourceLabel:"Page capture",title:`📎 Captured to ${e}`,body:"A page snippet was added to the most recent thread. Open Jarela to follow up.",agent_id:a.agent_id,thread_id:a.thread_id,ttl:5e3});return}if("run_completed"!==a.type&&"task_completed"!==a.type&&"bridge_message_received"!==a.type||"task_completed"===a.type&&"skipped"===a.status)return;t.current=Math.max(t.current,a.ts),N(t.current);let n=a.thread_id;n&&window.dispatchEvent(new CustomEvent("jarela:thread-updated",{detail:{thread_id:n,agent_id:a.agent_id??null}})),function(e){if(!s.current.shouldNotify(e))return;let{title:t,body:a,kind:r,source:n,sourceLabel:l}=function(e,t){let s=t(e.agent_id);if("run_completed"===e.type)return"error"===e.status?{title:`${s} — error`,body:e.preview||"Run failed.",kind:"error",source:"run",sourceLabel:"Reply"}:{title:`${s} replied`,body:e.preview||"Response ready.",kind:"info",source:"run",sourceLabel:"Reply"};if("task_completed"===e.type)return"error"===e.status?{title:`${s} — scheduled task failed`,body:e.error??"Task failed.",kind:"error",source:"task",sourceLabel:"Scheduled task"}:{title:`${s} — scheduled task completed`,body:e.preview||"(no output)",kind:"success",source:"task",sourceLabel:"Scheduled task"};let a=e.push_name||e.remote_jid,r=e.is_group?`${a} (group)`:a,n=e.is_group?"WhatsApp group":"WhatsApp";return{title:`${r} → ${s}`,body:e.preview||"(no reply)",kind:"info",source:"bridge",sourceLabel:n}}(e,s.current.resolveAgentName);if(f({kind:r,source:n,sourceLabel:l,title:t,body:a,preview:e.preview||void 0,agent_id:e.agent_id,thread_id:e.thread_id||null,ttl:6e3}),"u">typeof Notification&&"granted"===Notification.permission)try{let r=s.current.resolveAgentIcon?.(e.agent_id)??null,n="run_completed"===e.type?`run:${e.thread_id}`:"task_completed"===e.type?`task:${e.task_id}`:`bridge:${e.bridge_id}:${e.remote_jid}`,l=new Notification(t,{body:e.preview?`${a}
23
-
24
- ${e.preview}`:a,tag:n,icon:r||"/icon-192.png"});l.onclick=()=>{window.focus();let t=e.agent_id,s=e.thread_id??null;t&&window.dispatchEvent(new CustomEvent("jarela:focus-agent",{detail:{agentId:t,threadId:s}})),l.close()}}catch{}}(a)},e.onerror=()=>{e?.close(),e=null,a||(n=setTimeout(l,Math.min(r,3e4)),r=Math.min(2*r,3e4))})}l();let i=()=>{if("visible"===document.visibilityState){n&&(clearTimeout(n),n=null);try{e?.close()}catch{}e=null,r=500,l()}};return document.addEventListener("visibilitychange",i),()=>{a=!0,n&&(clearTimeout(n),n=null),document.removeEventListener("visibilitychange",i),e?.close()}},[]),(0,i.useEffect)(()=>{if(_)return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)};function e(e){let t=z.current;t&&(t.contains(e.target)||C(!1))}function t(e){"Escape"===e.key&&C(!1)}},[_]);let U=d.activeAgentId?R.find(e=>e.id===d.activeAgentId)??null:null;return(0,a.jsxs)("div",{className:"h-screen h-[100dvh] flex flex-col text-fg overflow-hidden px-safe",children:[(0,a.jsx)(aN,{}),(0,a.jsx)(aC,{}),(0,a.jsx)(aP,{}),(0,a.jsx)(aR,{}),(0,a.jsx)("div",{className:"shrink-0","aria-hidden":!0,style:{height:"calc(3rem + var(--app-safe-top))"}}),(0,a.jsx)(aT,{}),(0,a.jsx)(aI,{}),(0,a.jsxs)("header",{className:"glass fixed top-0 left-0 right-0 z-40 flex items-center px-4 border-b border-border/60",style:{paddingTop:"var(--app-safe-top)",paddingLeft:"calc(env(safe-area-inset-left) + 1rem)",paddingRight:"calc(env(safe-area-inset-right) + 1rem)",height:"calc(3rem + var(--app-safe-top))"},children:[(0,a.jsxs)("div",{className:"relative flex items-center gap-2 select-none",ref:z,children:[(0,a.jsxs)("button",{type:"button",onClick:()=>C(e=>!e),className:"inline-flex items-center gap-2 rounded-lg px-1.5 py-1 hover:bg-surface-3/60 transition-colors",title:"Select active agent","aria-haspopup":"menu","aria-expanded":_,children:[(0,a.jsx)("img",{src:"/logo-mark-transparent.png",alt:"",className:"h-6 w-auto dark:brightness-0 dark:invert"}),(0,a.jsx)("span",{className:"text-fg font-semibold tracking-tight",children:(0,e0.fj)()}),(0,a.jsx)("span",{className:"text-xs text-fg-faint max-w-[11rem] truncate hidden sm:inline",children:U?.name??"select agent"}),(0,a.jsx)(r.A,{size:14,className:`text-fg-faint transition-transform ${_?"rotate-180":""}`})]}),_&&(0,a.jsx)("div",{role:"menu",className:"absolute top-full left-0 mt-2 w-[min(24rem,calc(100vw-2rem))] max-h-[55vh] overflow-y-auto rounded-xl border border-border bg-surface-2/95 backdrop-blur-md shadow-2xl p-1.5",children:0===R.length?(0,a.jsx)("p",{className:"text-xs text-fg-faint px-2 py-2",children:"No agents available yet."}):R.map(e=>{let t=e.id===d.activeAgentId;return(0,a.jsxs)("button",{type:"button",role:"menuitemradio","aria-checked":t,onClick:()=>{u({type:"SET_AGENT",agentId:e.id}),u({type:"SET_TAB",tab:"chat"}),C(!1)},className:`w-full flex items-center gap-2 px-2 py-1.5 rounded-lg text-left text-sm transition-colors ${t?"bg-surface-3 text-fg":"text-fg-muted hover:bg-surface-3/60 hover:text-fg"}`,children:[(0,a.jsx)("span",{className:"w-4 h-4 shrink-0 inline-flex items-center justify-center text-accent",children:t?(0,a.jsx)(n.A,{size:14}):null}),e.icon?(0,a.jsx)("img",{src:e.icon,alt:"",className:"w-5 h-5 rounded-md object-cover shrink-0"}):(0,a.jsx)("span",{className:"w-5 h-5 rounded-md bg-surface-3 text-[10px] font-semibold text-fg-subtle inline-flex items-center justify-center shrink-0",children:e.name.charAt(0).toUpperCase()}),(0,a.jsx)("span",{className:"truncate flex-1",children:e.name})]},e.id)})})]}),(0,a.jsxs)("button",{onClick:()=>{w(e=>!e)},className:`ml-auto relative p-2.5 rounded transition-colors ${y?"text-fg bg-surface-3":"text-fg-faint hover:text-fg-muted hover:bg-surface-3/50"}`,title:L>0?`${L} new ${1===L?"alert":"alerts"}`:"Menu",children:[(0,a.jsx)(l.A,{size:21}),L>0&&(0,a.jsx)("span",{className:"absolute top-1 right-1 min-w-[14px] h-[14px] px-1 rounded-full bg-rose-500 border border-surface-2 text-[9px] font-bold text-white flex items-center justify-center leading-none animate-pulse",children:L>9?"9+":L})]})]}),(0,a.jsxs)("div",{className:"flex-1 relative overflow-hidden",children:[I.has("chat")&&(0,a.jsx)(i.Activity,{mode:"chat"===d.activeTab?"visible":"hidden",children:(0,a.jsx)(eB,{threadId:p,agentId:d.activeAgentId,sessionLoading:g,sessionError:b,showTools:A,showThinking:T,onMessageSent:M,onSelectAgent:D},d.activeAgentId??"no-agent")}),I.has("agents")&&(0,a.jsx)(i.Activity,{mode:"agents"===d.activeTab?"visible":"hidden",children:(0,a.jsx)(t4,{})}),I.has("memory")&&(0,a.jsx)(i.Activity,{mode:"memory"===d.activeTab?"visible":"hidden",children:(0,a.jsx)(tn,{})}),I.has("documents")&&(0,a.jsx)(i.Activity,{mode:"documents"===d.activeTab?"visible":"hidden",children:(0,a.jsx)(tG,{})}),I.has("models")&&(0,a.jsx)(i.Activity,{mode:"models"===d.activeTab?"visible":"hidden",children:(0,a.jsx)(t$,{})}),I.has("mcp")&&(0,a.jsx)(i.Activity,{mode:"mcp"===d.activeTab?"visible":"hidden",children:(0,a.jsx)(sx,{})}),I.has("extensions")&&(0,a.jsx)(i.Activity,{mode:"extensions"===d.activeTab?"visible":"hidden",children:(0,a.jsx)(sb,{})}),I.has("tools")&&(0,a.jsx)(i.Activity,{mode:"tools"===d.activeTab?"visible":"hidden",children:(0,a.jsx)(sC,{})}),I.has("connections")&&(0,a.jsx)(i.Activity,{mode:"connections"===d.activeTab?"visible":"hidden",children:(0,a.jsx)(sB,{})}),I.has("tasks")&&(0,a.jsx)(i.Activity,{mode:"tasks"===d.activeTab?"visible":"hidden",children:(0,a.jsx)(s6,{})}),I.has("bridges")&&(0,a.jsx)(i.Activity,{mode:"bridges"===d.activeTab?"visible":"hidden",children:(0,a.jsx)(au,{})}),I.has("profile")&&(0,a.jsx)(i.Activity,{mode:"profile"===d.activeTab?"visible":"hidden",children:(0,a.jsx)(sl,{})}),I.has("harness")&&(0,a.jsx)(i.Activity,{mode:"harness"===d.activeTab?"visible":"hidden",children:(0,a.jsx)(av,{})}),y&&(0,a.jsx)("div",{className:"fixed left-0 right-0 bottom-0 bg-black/30 backdrop-blur-sm z-30",style:{top:"calc(3rem + var(--app-safe-top))"},onClick:()=>w(!1)}),y&&(0,a.jsx)(a0,{activeTab:d.activeTab,agentId:d.activeAgentId,showTools:A,showThinking:T,onClose:()=>w(!1),onAgentChange:e=>u({type:"SET_AGENT",agentId:e}),onSetTab:e=>{u({type:"SET_TAB",tab:e}),w(!1)},onShowToolsChange:E,onShowThinkingChange:$})]})]})}},9469:(e,t,s)=>{Promise.resolve().then(s.bind(s,9149))}},e=>{e.O(0,[1973,8657,6945,8441,3457,7358],()=>e(e.s=9469)),_N_E=e.O()}]);