flowent 0.0.5 → 0.0.7

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 (265) hide show
  1. package/README.md +1 -1
  2. package/backend/README.md +1 -1
  3. package/backend/pyproject.toml +1 -1
  4. package/backend/src/flowent/__pycache__/__init__.cpython-313.pyc +0 -0
  5. package/backend/src/flowent/__pycache__/_version.cpython-313.pyc +0 -0
  6. package/backend/src/flowent/__pycache__/access.cpython-313.pyc +0 -0
  7. package/backend/src/flowent/__pycache__/agent.cpython-313.pyc +0 -0
  8. package/backend/src/flowent/__pycache__/assistant_commands.cpython-313.pyc +0 -0
  9. package/backend/src/flowent/__pycache__/cli.cpython-313.pyc +0 -0
  10. package/backend/src/flowent/__pycache__/config.cpython-313.pyc +0 -0
  11. package/backend/src/flowent/__pycache__/events.cpython-313.pyc +0 -0
  12. package/backend/src/flowent/__pycache__/graph_runtime.cpython-313.pyc +0 -0
  13. package/backend/src/flowent/__pycache__/graph_service.cpython-313.pyc +0 -0
  14. package/backend/src/flowent/__pycache__/image_assets.cpython-313.pyc +0 -0
  15. package/backend/src/flowent/__pycache__/logging.cpython-313.pyc +0 -0
  16. package/backend/src/flowent/__pycache__/main.cpython-313.pyc +0 -0
  17. package/backend/src/flowent/__pycache__/model_metadata.cpython-313.pyc +0 -0
  18. package/backend/src/flowent/__pycache__/network.cpython-313.pyc +0 -0
  19. package/backend/src/flowent/__pycache__/observability_service.cpython-313.pyc +0 -0
  20. package/backend/src/flowent/__pycache__/registry.cpython-313.pyc +0 -0
  21. package/backend/src/flowent/__pycache__/role_management.cpython-313.pyc +0 -0
  22. package/backend/src/flowent/__pycache__/runtime.cpython-313.pyc +0 -0
  23. package/backend/src/flowent/__pycache__/sandbox.cpython-313.pyc +0 -0
  24. package/backend/src/flowent/__pycache__/security.cpython-313.pyc +0 -0
  25. package/backend/src/flowent/__pycache__/settings.cpython-313.pyc +0 -0
  26. package/backend/src/flowent/__pycache__/settings_management.cpython-313.pyc +0 -0
  27. package/backend/src/flowent/__pycache__/state_db.cpython-313.pyc +0 -0
  28. package/backend/src/flowent/__pycache__/workspace_store.cpython-313.pyc +0 -0
  29. package/backend/src/flowent/agent.py +91 -8
  30. package/backend/src/flowent/channels/__pycache__/__init__.cpython-313.pyc +0 -0
  31. package/backend/src/flowent/channels/__pycache__/telegram.cpython-313.pyc +0 -0
  32. package/backend/src/flowent/graph_service.py +3 -110
  33. package/backend/src/flowent/models/__pycache__/__init__.cpython-313.pyc +0 -0
  34. package/backend/src/flowent/models/__pycache__/agent.cpython-313.pyc +0 -0
  35. package/backend/src/flowent/models/__pycache__/base.cpython-313.pyc +0 -0
  36. package/backend/src/flowent/models/__pycache__/blueprint.cpython-313.pyc +0 -0
  37. package/backend/src/flowent/models/__pycache__/content.cpython-313.pyc +0 -0
  38. package/backend/src/flowent/models/__pycache__/delta.cpython-313.pyc +0 -0
  39. package/backend/src/flowent/models/__pycache__/event.cpython-313.pyc +0 -0
  40. package/backend/src/flowent/models/__pycache__/graph.cpython-313.pyc +0 -0
  41. package/backend/src/flowent/models/__pycache__/history.cpython-313.pyc +0 -0
  42. package/backend/src/flowent/models/__pycache__/llm.cpython-313.pyc +0 -0
  43. package/backend/src/flowent/models/__pycache__/message.cpython-313.pyc +0 -0
  44. package/backend/src/flowent/models/__pycache__/tab.cpython-313.pyc +0 -0
  45. package/backend/src/flowent/models/__pycache__/todo.cpython-313.pyc +0 -0
  46. package/backend/src/flowent/prompts/__pycache__/__init__.cpython-313.pyc +0 -0
  47. package/backend/src/flowent/prompts/__pycache__/common.cpython-313.pyc +0 -0
  48. package/backend/src/flowent/prompts/__pycache__/steward.cpython-313.pyc +0 -0
  49. package/backend/src/flowent/providers/__pycache__/__init__.cpython-313.pyc +0 -0
  50. package/backend/src/flowent/providers/__pycache__/anthropic.cpython-313.pyc +0 -0
  51. package/backend/src/flowent/providers/__pycache__/base_url.cpython-313.pyc +0 -0
  52. package/backend/src/flowent/providers/__pycache__/configuration.cpython-313.pyc +0 -0
  53. package/backend/src/flowent/providers/__pycache__/content.cpython-313.pyc +0 -0
  54. package/backend/src/flowent/providers/__pycache__/errors.cpython-313.pyc +0 -0
  55. package/backend/src/flowent/providers/__pycache__/gateway.cpython-313.pyc +0 -0
  56. package/backend/src/flowent/providers/__pycache__/headers.cpython-313.pyc +0 -0
  57. package/backend/src/flowent/providers/__pycache__/management.cpython-313.pyc +0 -0
  58. package/backend/src/flowent/providers/__pycache__/openai.cpython-313.pyc +0 -0
  59. package/backend/src/flowent/providers/__pycache__/openai_responses.cpython-313.pyc +0 -0
  60. package/backend/src/flowent/providers/__pycache__/registry.cpython-313.pyc +0 -0
  61. package/backend/src/flowent/providers/__pycache__/sse.cpython-313.pyc +0 -0
  62. package/backend/src/flowent/providers/__pycache__/thinking.cpython-313.pyc +0 -0
  63. package/backend/src/flowent/role_management.py +9 -6
  64. package/backend/src/flowent/routes/__init__.py +0 -2
  65. package/backend/src/flowent/routes/__pycache__/__init__.cpython-313.pyc +0 -0
  66. package/backend/src/flowent/routes/__pycache__/access.cpython-313.pyc +0 -0
  67. package/backend/src/flowent/routes/__pycache__/assistant.cpython-313.pyc +0 -0
  68. package/backend/src/flowent/routes/__pycache__/image_assets.cpython-313.pyc +0 -0
  69. package/backend/src/flowent/routes/__pycache__/meta.cpython-313.pyc +0 -0
  70. package/backend/src/flowent/routes/__pycache__/nodes.cpython-313.pyc +0 -0
  71. package/backend/src/flowent/routes/__pycache__/prompts.cpython-313.pyc +0 -0
  72. package/backend/src/flowent/routes/__pycache__/providers_route.cpython-313.pyc +0 -0
  73. package/backend/src/flowent/routes/__pycache__/roles.cpython-313.pyc +0 -0
  74. package/backend/src/flowent/routes/__pycache__/settings.cpython-313.pyc +0 -0
  75. package/backend/src/flowent/routes/__pycache__/tabs.cpython-313.pyc +0 -0
  76. package/backend/src/flowent/routes/__pycache__/ws.cpython-313.pyc +0 -0
  77. package/backend/src/flowent/routes/assistant.py +3 -0
  78. package/backend/src/flowent/routes/nodes.py +11 -1
  79. package/backend/src/flowent/routes/settings.py +169 -118
  80. package/backend/src/flowent/routes/tabs.py +0 -12
  81. package/backend/src/flowent/runtime.py +0 -5
  82. package/backend/src/flowent/security.py +1 -21
  83. package/backend/src/flowent/settings.py +15 -421
  84. package/backend/src/flowent/settings_management.py +260 -164
  85. package/backend/src/flowent/state_db.py +2 -14
  86. package/backend/src/flowent/static/assets/AssistantPage-BW7XAd9I.js +1 -0
  87. package/backend/src/flowent/static/assets/ChannelsPage-tCJHgt6m.js +1 -0
  88. package/backend/src/flowent/static/assets/{PageScaffold-DteOA8V7.js → PageScaffold-f6g2l7XN.js} +1 -1
  89. package/backend/src/flowent/static/assets/PromptsPage-C3Sxn2D7.js +1 -0
  90. package/backend/src/flowent/static/assets/ProvidersPage-BfmdXmNt.js +3 -0
  91. package/backend/src/flowent/static/assets/RolesPage-DET8wO4r.js +1 -0
  92. package/backend/src/flowent/static/assets/SettingsPage-D-g3deMm.js +3 -0
  93. package/backend/src/flowent/static/assets/ToolsPage-CDmtE2g4.js +1 -0
  94. package/backend/src/flowent/static/assets/WorkspacePage-AZsJ0sD0.js +3 -0
  95. package/backend/src/flowent/static/assets/WorkspacePanels-CteCjolX.js +1 -0
  96. package/backend/src/flowent/static/assets/{alert-dialog-DIBUCmqM.js → alert-dialog-Duorp_S-.js} +1 -1
  97. package/backend/src/flowent/static/assets/{dialog-BOvHIBrg.js → dialog-C3ixjGjN.js} +1 -1
  98. package/backend/src/flowent/static/assets/index--o_0fv0N.css +1 -0
  99. package/backend/src/flowent/static/assets/index-C9HuekJm.js +10 -0
  100. package/backend/src/flowent/static/assets/{modelParams-DcEhGnu0.js → modelParams-DmnF2hwR.js} +1 -1
  101. package/backend/src/flowent/static/assets/providerTypes-DT3Ahwl_.js +1 -0
  102. package/backend/src/flowent/static/assets/roles-CuRT_chR.js +1 -0
  103. package/{dist/frontend/assets/select-D9SwnlXF.js → backend/src/flowent/static/assets/select-DCfeNu-F.js} +1 -1
  104. package/backend/src/flowent/static/assets/surface-pWwG5ogx.js +1 -0
  105. package/backend/src/flowent/static/assets/{ui-vendor-UazN8rcv.js → ui-vendor-C5pJa8N7.js} +15 -15
  106. package/backend/src/flowent/static/assets/useAppRoute-FgSHBKhV.js +1 -0
  107. package/backend/src/flowent/static/index.html +3 -3
  108. package/backend/src/flowent/tools/__init__.py +2 -101
  109. package/backend/src/flowent/tools/__pycache__/__init__.cpython-313.pyc +0 -0
  110. package/backend/src/flowent/tools/__pycache__/connect.cpython-313.pyc +0 -0
  111. package/backend/src/flowent/tools/__pycache__/contacts.cpython-313.pyc +0 -0
  112. package/backend/src/flowent/tools/__pycache__/create_agent.cpython-313.pyc +0 -0
  113. package/backend/src/flowent/tools/__pycache__/create_tab.cpython-313.pyc +0 -0
  114. package/backend/src/flowent/tools/__pycache__/delete_tab.cpython-313.pyc +0 -0
  115. package/backend/src/flowent/tools/__pycache__/edit.cpython-313.pyc +0 -0
  116. package/backend/src/flowent/tools/__pycache__/exec.cpython-313.pyc +0 -0
  117. package/backend/src/flowent/tools/__pycache__/fetch.cpython-313.pyc +0 -0
  118. package/backend/src/flowent/tools/__pycache__/idle.cpython-313.pyc +0 -0
  119. package/backend/src/flowent/tools/__pycache__/list_roles.cpython-313.pyc +0 -0
  120. package/backend/src/flowent/tools/__pycache__/list_tabs.cpython-313.pyc +0 -0
  121. package/backend/src/flowent/tools/__pycache__/list_tools.cpython-313.pyc +0 -0
  122. package/backend/src/flowent/tools/__pycache__/manage_prompts.cpython-313.pyc +0 -0
  123. package/backend/src/flowent/tools/__pycache__/manage_providers.cpython-313.pyc +0 -0
  124. package/backend/src/flowent/tools/__pycache__/manage_roles.cpython-313.pyc +0 -0
  125. package/backend/src/flowent/tools/__pycache__/manage_settings.cpython-313.pyc +0 -0
  126. package/backend/src/flowent/tools/__pycache__/read.cpython-313.pyc +0 -0
  127. package/backend/src/flowent/tools/__pycache__/send.cpython-313.pyc +0 -0
  128. package/backend/src/flowent/tools/__pycache__/set_permissions.cpython-313.pyc +0 -0
  129. package/backend/src/flowent/tools/__pycache__/sleep.cpython-313.pyc +0 -0
  130. package/backend/src/flowent/tools/__pycache__/todo.cpython-313.pyc +0 -0
  131. package/backend/src/flowent/tools/list_roles.py +2 -9
  132. package/backend/src/flowent/tools/manage_settings.py +134 -172
  133. package/backend/tests/__pycache__/__init__.cpython-313.pyc +0 -0
  134. package/backend/tests/__pycache__/conftest.cpython-313-pytest-9.0.3.pyc +0 -0
  135. package/backend/tests/integration/api/__pycache__/conftest.cpython-313-pytest-9.0.3.pyc +0 -0
  136. package/backend/tests/integration/api/__pycache__/test_access_api.cpython-313-pytest-9.0.3.pyc +0 -0
  137. package/backend/tests/integration/api/__pycache__/test_assistant_api.cpython-313-pytest-9.0.3.pyc +0 -0
  138. package/backend/tests/integration/api/__pycache__/test_frontend_mounting.cpython-313-pytest-9.0.3.pyc +0 -0
  139. package/backend/tests/integration/api/__pycache__/test_meta_api.cpython-313-pytest-9.0.3.pyc +0 -0
  140. package/backend/tests/integration/api/__pycache__/test_nodes_api.cpython-313-pytest-9.0.3.pyc +0 -0
  141. package/backend/tests/integration/api/__pycache__/test_prompts_api.cpython-313-pytest-9.0.3.pyc +0 -0
  142. package/backend/tests/integration/api/__pycache__/test_roles_api.cpython-313-pytest-9.0.3.pyc +0 -0
  143. package/backend/tests/integration/api/__pycache__/test_tabs_api.cpython-313-pytest-9.0.3.pyc +0 -0
  144. package/backend/tests/integration/api/test_assistant_api.py +68 -0
  145. package/backend/tests/integration/api/test_meta_api.py +0 -1
  146. package/backend/tests/integration/api/test_nodes_api.py +73 -8
  147. package/backend/tests/integration/api/test_tabs_api.py +0 -114
  148. package/backend/tests/unit/__pycache__/test_access.cpython-313-pytest-9.0.3.pyc +0 -0
  149. package/backend/tests/unit/__pycache__/test_cli.cpython-313-pytest-9.0.3.pyc +0 -0
  150. package/backend/tests/unit/__pycache__/test_graph_runtime.cpython-313-pytest-9.0.3.pyc +0 -0
  151. package/backend/tests/unit/__pycache__/test_network.cpython-313-pytest-9.0.3.pyc +0 -0
  152. package/backend/tests/unit/__pycache__/test_state_sqlite_storage.cpython-313-pytest-9.0.3.pyc +0 -0
  153. package/backend/tests/unit/__pycache__/test_workspace_store.cpython-313-pytest-9.0.3.pyc +0 -0
  154. package/backend/tests/unit/agent/__pycache__/test_agent_public_api.cpython-313-pytest-9.0.3.pyc +0 -0
  155. package/backend/tests/unit/agent/__pycache__/test_agent_runtime.cpython-313-pytest-9.0.3.pyc +0 -0
  156. package/backend/tests/unit/agent/test_agent_public_api.py +0 -15
  157. package/backend/tests/unit/agent/test_agent_runtime.py +148 -2
  158. package/backend/tests/unit/channels/__pycache__/test_telegram_channel.cpython-313-pytest-9.0.3.pyc +0 -0
  159. package/backend/tests/unit/logging/__pycache__/test_logging.cpython-313-pytest-9.0.3.pyc +0 -0
  160. package/backend/tests/unit/prompts/__pycache__/test_prompts.cpython-313-pytest-9.0.3.pyc +0 -0
  161. package/backend/tests/unit/providers/__pycache__/test_anthropic_provider.cpython-313-pytest-9.0.3.pyc +0 -0
  162. package/backend/tests/unit/providers/__pycache__/test_errors.cpython-313-pytest-9.0.3.pyc +0 -0
  163. package/backend/tests/unit/providers/__pycache__/test_extract_delta_parts.cpython-313-pytest-9.0.3.pyc +0 -0
  164. package/backend/tests/unit/providers/__pycache__/test_openai_provider.cpython-313-pytest-9.0.3.pyc +0 -0
  165. package/backend/tests/unit/providers/__pycache__/test_openai_responses.cpython-313-pytest-9.0.3.pyc +0 -0
  166. package/backend/tests/unit/providers/__pycache__/test_provider_gateway.cpython-313-pytest-9.0.3.pyc +0 -0
  167. package/backend/tests/unit/providers/__pycache__/test_think_tag_parser.cpython-313-pytest-9.0.3.pyc +0 -0
  168. package/backend/tests/unit/routes/__pycache__/test_prompts_routes.cpython-313-pytest-9.0.3.pyc +0 -0
  169. package/backend/tests/unit/routes/__pycache__/test_providers_route.cpython-313-pytest-9.0.3.pyc +0 -0
  170. package/backend/tests/unit/routes/__pycache__/test_roles_routes.cpython-313-pytest-9.0.3.pyc +0 -0
  171. package/backend/tests/unit/routes/__pycache__/test_settings_routes.cpython-313-pytest-9.0.3.pyc +0 -0
  172. package/backend/tests/unit/routes/test_prompts_routes.py +0 -22
  173. package/backend/tests/unit/routes/test_roles_routes.py +6 -2
  174. package/backend/tests/unit/routes/test_settings_routes.py +0 -19
  175. package/backend/tests/unit/runtime/__pycache__/test_bootstrap_runtime.cpython-313-pytest-9.0.3.pyc +0 -0
  176. package/backend/tests/unit/sandbox/__pycache__/test_sandbox_tools.cpython-313-pytest-9.0.3.pyc +0 -0
  177. package/backend/tests/unit/security/__pycache__/test_security.cpython-313-pytest-9.0.3.pyc +0 -0
  178. package/backend/tests/unit/settings/__pycache__/test_settings_roles.cpython-313-pytest-9.0.3.pyc +0 -0
  179. package/backend/tests/unit/settings/test_settings_roles.py +3 -51
  180. package/backend/tests/unit/test_cli.py +0 -22
  181. package/backend/tests/unit/test_state_sqlite_storage.py +27 -99
  182. package/backend/tests/unit/test_workspace_store.py +0 -3
  183. package/backend/tests/unit/tools/__pycache__/test_connect_tool.cpython-313-pytest-9.0.3.pyc +0 -0
  184. package/backend/tests/unit/tools/__pycache__/test_create_agent_tool.cpython-313-pytest-9.0.3.pyc +0 -0
  185. package/backend/tests/unit/tools/__pycache__/test_delete_tab_tool.cpython-313-pytest-9.0.3.pyc +0 -0
  186. package/backend/tests/unit/tools/__pycache__/test_edit_tool.cpython-313-pytest-9.0.3.pyc +0 -0
  187. package/backend/tests/unit/tools/__pycache__/test_exec_tool.cpython-313-pytest-9.0.3.pyc +0 -0
  188. package/backend/tests/unit/tools/__pycache__/test_fetch_tool.cpython-313-pytest-9.0.3.pyc +0 -0
  189. package/backend/tests/unit/tools/__pycache__/test_manage_prompts_tool.cpython-313-pytest-9.0.3.pyc +0 -0
  190. package/backend/tests/unit/tools/__pycache__/test_manage_providers_tool.cpython-313-pytest-9.0.3.pyc +0 -0
  191. package/backend/tests/unit/tools/__pycache__/test_manage_roles_tool.cpython-313-pytest-9.0.3.pyc +0 -0
  192. package/backend/tests/unit/tools/__pycache__/test_manage_settings_tool.cpython-313-pytest-9.0.3.pyc +0 -0
  193. package/backend/tests/unit/tools/__pycache__/test_read_tool.cpython-313-pytest-9.0.3.pyc +0 -0
  194. package/backend/tests/unit/tools/__pycache__/test_set_permissions_tool.cpython-313-pytest-9.0.3.pyc +0 -0
  195. package/backend/tests/unit/tools/__pycache__/test_todo_tool.cpython-313-pytest-9.0.3.pyc +0 -0
  196. package/backend/tests/unit/tools/__pycache__/test_tool_registry.cpython-313-pytest-9.0.3.pyc +0 -0
  197. package/backend/tests/unit/tools/test_create_agent_tool.py +0 -32
  198. package/backend/tests/unit/tools/test_manage_prompts_tool.py +5 -30
  199. package/backend/tests/unit/tools/test_tool_registry.py +45 -40
  200. package/backend/uv.lock +1 -1
  201. package/dist/frontend/assets/AssistantPage-BW7XAd9I.js +1 -0
  202. package/dist/frontend/assets/ChannelsPage-tCJHgt6m.js +1 -0
  203. package/dist/frontend/assets/{PageScaffold-DteOA8V7.js → PageScaffold-f6g2l7XN.js} +1 -1
  204. package/dist/frontend/assets/PromptsPage-C3Sxn2D7.js +1 -0
  205. package/dist/frontend/assets/ProvidersPage-BfmdXmNt.js +3 -0
  206. package/dist/frontend/assets/RolesPage-DET8wO4r.js +1 -0
  207. package/dist/frontend/assets/SettingsPage-D-g3deMm.js +3 -0
  208. package/dist/frontend/assets/ToolsPage-CDmtE2g4.js +1 -0
  209. package/dist/frontend/assets/WorkspacePage-AZsJ0sD0.js +3 -0
  210. package/dist/frontend/assets/WorkspacePanels-CteCjolX.js +1 -0
  211. package/dist/frontend/assets/{alert-dialog-DIBUCmqM.js → alert-dialog-Duorp_S-.js} +1 -1
  212. package/dist/frontend/assets/{dialog-BOvHIBrg.js → dialog-C3ixjGjN.js} +1 -1
  213. package/dist/frontend/assets/index--o_0fv0N.css +1 -0
  214. package/dist/frontend/assets/index-C9HuekJm.js +10 -0
  215. package/dist/frontend/assets/{modelParams-DcEhGnu0.js → modelParams-DmnF2hwR.js} +1 -1
  216. package/dist/frontend/assets/providerTypes-DT3Ahwl_.js +1 -0
  217. package/dist/frontend/assets/roles-CuRT_chR.js +1 -0
  218. package/{backend/src/flowent/static/assets/select-D9SwnlXF.js → dist/frontend/assets/select-DCfeNu-F.js} +1 -1
  219. package/dist/frontend/assets/surface-pWwG5ogx.js +1 -0
  220. package/dist/frontend/assets/{ui-vendor-UazN8rcv.js → ui-vendor-C5pJa8N7.js} +15 -15
  221. package/dist/frontend/assets/useAppRoute-FgSHBKhV.js +1 -0
  222. package/dist/frontend/index.html +3 -3
  223. package/package.json +1 -1
  224. package/backend/src/flowent/__pycache__/mcp_service.cpython-313.pyc +0 -0
  225. package/backend/src/flowent/mcp_service.py +0 -1918
  226. package/backend/src/flowent/routes/__pycache__/mcp.cpython-313.pyc +0 -0
  227. package/backend/src/flowent/routes/mcp.py +0 -125
  228. package/backend/src/flowent/static/assets/AssistantPage-VBohhz4d.js +0 -1
  229. package/backend/src/flowent/static/assets/ChannelsPage-CIydPZA_.js +0 -1
  230. package/backend/src/flowent/static/assets/McpPage-CHPm2TPY.js +0 -7
  231. package/backend/src/flowent/static/assets/PromptsPage-CSmJ3sZg.js +0 -1
  232. package/backend/src/flowent/static/assets/ProvidersPage-sl2jeG4e.js +0 -3
  233. package/backend/src/flowent/static/assets/RolesPage-DCe7W6Km.js +0 -1
  234. package/backend/src/flowent/static/assets/SettingsPage-Bix9e63E.js +0 -3
  235. package/backend/src/flowent/static/assets/ToolsPage-favNkj5C.js +0 -1
  236. package/backend/src/flowent/static/assets/WorkspaceCommandDialog-DRS6wiD6.js +0 -1
  237. package/backend/src/flowent/static/assets/WorkspacePage-KuaDjt_D.js +0 -3
  238. package/backend/src/flowent/static/assets/WorkspacePanels-BZxBw8M5.js +0 -1
  239. package/backend/src/flowent/static/assets/datetime-eJqd0V2S.js +0 -1
  240. package/backend/src/flowent/static/assets/index-Biio-CoI.js +0 -10
  241. package/backend/src/flowent/static/assets/index-CmQvO7sl.css +0 -1
  242. package/backend/src/flowent/static/assets/roles-BbIEIMeG.js +0 -1
  243. package/backend/src/flowent/static/assets/surface-Bzr1FRG4.js +0 -1
  244. package/backend/src/flowent/static/assets/triState-DgLlKdRR.js +0 -1
  245. package/backend/src/flowent/tools/__pycache__/mcp.cpython-313.pyc +0 -0
  246. package/backend/src/flowent/tools/mcp.py +0 -199
  247. package/backend/tests/integration/api/__pycache__/test_mcp_api.cpython-313-pytest-9.0.3.pyc +0 -0
  248. package/backend/tests/integration/api/test_mcp_api.py +0 -116
  249. package/dist/frontend/assets/AssistantPage-VBohhz4d.js +0 -1
  250. package/dist/frontend/assets/ChannelsPage-CIydPZA_.js +0 -1
  251. package/dist/frontend/assets/McpPage-CHPm2TPY.js +0 -7
  252. package/dist/frontend/assets/PromptsPage-CSmJ3sZg.js +0 -1
  253. package/dist/frontend/assets/ProvidersPage-sl2jeG4e.js +0 -3
  254. package/dist/frontend/assets/RolesPage-DCe7W6Km.js +0 -1
  255. package/dist/frontend/assets/SettingsPage-Bix9e63E.js +0 -3
  256. package/dist/frontend/assets/ToolsPage-favNkj5C.js +0 -1
  257. package/dist/frontend/assets/WorkspaceCommandDialog-DRS6wiD6.js +0 -1
  258. package/dist/frontend/assets/WorkspacePage-KuaDjt_D.js +0 -3
  259. package/dist/frontend/assets/WorkspacePanels-BZxBw8M5.js +0 -1
  260. package/dist/frontend/assets/datetime-eJqd0V2S.js +0 -1
  261. package/dist/frontend/assets/index-Biio-CoI.js +0 -10
  262. package/dist/frontend/assets/index-CmQvO7sl.css +0 -1
  263. package/dist/frontend/assets/roles-BbIEIMeG.js +0 -1
  264. package/dist/frontend/assets/surface-Bzr1FRG4.js +0 -1
  265. package/dist/frontend/assets/triState-DgLlKdRR.js +0 -1
@@ -0,0 +1 @@
1
+ import{a as e}from"./rolldown-runtime-BYbx6iT9.js";import{d as t,l as n}from"./graph-vendor-DRq_-6fV.js";import{q as r}from"./ui-vendor-C5pJa8N7.js";import{A as i,C as a,D as o,E as s,M as c,N as l,O as u,S as d,T as ee,_ as te,b as ne,g as re,h as ie,j as ae,k as oe,m as f,t as p,v as se,w as ce,x as m,y as le}from"./WorkspacePanels-CteCjolX.js";import{A as h,K as g,M as ue,U as de,Y as _,ft as v,g as y,h as fe,j as b,m as pe,p as me,q as he,ut as x}from"./index-C9HuekJm.js";async function ge(e){return _(`/api/assistant/message`,{method:`POST`,body:e,errorMessage:`Failed to send Assistant message`})}async function _e(e){return _(`/api/assistant/messages/${e}/retry`,{method:`POST`,errorMessage:`Failed to retry Assistant message`})}var S=e(t(),1);function C(e){for(let t of e.values())if(t.node_type===`assistant`)return t;return null}function ve(e){return C(e)?.id??null}var w=`assistant`;function ye(){return s(w)}function be(e){return o(w,e)}function xe(e){ee(w,e)}function T(e={}){let{bottomInset:t=0}=e,{agents:n}=y(),{connected:i}=pe(),{agentHistories:o,clearAgentHistory:s,clearHistorySnapshot:c,historyInvalidatedAt:ee,historyClearedAt:ae,historySnapshots:p,streamingDeltas:_}=fe(),{activeToolCalls:v}=me(),[x,C]=(0,S.useState)(null),[w,T]=(0,S.useState)(0),[E,D]=(0,S.useState)(``),[O,k]=(0,S.useState)([]),[A,j]=(0,S.useState)(null),[Se,Ce]=(0,S.useState)(!1),[we,Te]=(0,S.useState)(null),[M,Ee]=(0,S.useState)(!1),[N,P]=(0,S.useState)([]),[F,I]=(0,S.useState)(null),De=(0,S.useRef)(null),Oe=(0,S.useRef)(!0),ke=(0,S.useRef)([]),L=(0,S.useRef)(null),R=(0,S.useRef)(!1),z=(0,S.useMemo)(()=>ve(n),[n]),B=(0,S.useMemo)(()=>z?n.get(z)??null:null,[n,z]),V=B?.capabilities?.input_image??!1,H=z?ae.get(z)??0:0,U=z?ee.get(z)??0:0,W=z?p.get(z)??null:null,Ae=O.some(e=>e.status===`uploading`),je=O.filter(le),G=(0,S.useSyncExternalStore)(be,ye,ye),K=A===null?null:G[A]??null,q=K!==null&&E===K.text&&se(O,K),J=B?.state??x?.state??null,Y=(0,S.useCallback)(async e=>{let t=e.pendingMessageTimestamp??Date.now(),n=ie(e.content,e.parts,t);Ee(!0),P(e=>[...e,n]);try{let n=await ge({content:e.content,parts:e.parts});return n.status===`command_executed`?P(n=>h(n,{content:e.content,timestamp:t})):n.message_id&&P(r=>r.map(r=>r.timestamp===t&&r.content===e.content?{...r,message_id:n.message_id}:r)),xe(e.history),e.restoreDraft&&d(e.restoreDraft.images),!0}catch(n){return P(n=>h(n,{content:e.content,timestamp:t})),e.restoreDraft&&(D(e.restoreDraft.input),k(e.restoreDraft.images),j(e.restoreDraft.historyCursor)),r.error(n instanceof Error?n.message:`Failed to send message`),!1}finally{Ee(!1)}},[]),X=(0,S.useCallback)((e,t)=>{j(t),D(e?.text??``),k(e?a(e):[])},[]),Me=(0,S.useCallback)(e=>{j(null),D(e)},[]);(0,S.useEffect)(()=>{ke.current=O},[O]),(0,S.useEffect)(()=>{L.current=F},[F]),(0,S.useEffect)(()=>()=>{d(ke.current)},[]),(0,S.useEffect)(()=>{H&&(P([]),I(null),C(e=>e&&{...e,history:u(e.history)}),T(Date.now()))},[H]),(0,S.useEffect)(()=>{U&&(P([]),W&&(C(e=>e&&{...e,history:W}),T(Date.now())))},[U,W]),(0,S.useEffect)(()=>{let e=L.current;!e||e.send_failed||e.target_id!==z||J!==e.target_state&&I({...e,target_state:J})},[z,J]),(0,S.useEffect)(()=>{let e=L.current;!e||e.send_failed||!z||e.target_id!==z||J!==`idle`||M||R.current||(R.current=!0,I(null),Y({content:e.content,parts:e.parts??[],history:e.history_entry,pendingMessageTimestamp:e.timestamp}).then(t=>{R.current=!1,t||I({...e,send_failed:!0,target_state:`error`})}).catch(()=>{R.current=!1,I({...e,send_failed:!0,target_state:`error`})}))},[z,J,M,Y]),(0,S.useEffect)(()=>{if(!i||!z){C(null);return}let e=new AbortController,t=!1;return(async()=>{s(z);try{let n=await g(z,e.signal);if(t||!n)return;C(n),T(Date.now()),c(z)}catch{!t&&!e.signal.aborted&&r.error(`Failed to load Assistant history`)}})(),()=>{t=!0,e.abort()}},[H,U,z,s,c,i]);let Z=(0,S.useMemo)(()=>z?oe({history:W??x?.history??[],incremental:o.get(z),deltas:_.get(z),fetchedAt:w||Date.now()}):[],[o,W,x,w,_,z]);(0,S.useEffect)(()=>{if(!z||N.length===0)return;let e=Z.filter(e=>e.type===`ReceivedMessage`&&e.from_id===`human`&&(!!e.content||!!e.message_id||!!e.parts?.length));e.length!==0&&P(t=>e.reduce((e,t)=>h(e,{content:t.content??b(t.parts,t.content),messageId:t.message_id}),t))},[z,Z,N.length]);let Q=(0,S.useMemo)(()=>[...Z,...F?[{...F}]:[],...N.map(e=>({...e}))],[Z,N,F]),$=(0,S.useMemo)(()=>{let e=N.length+ +!!F,t=z?_.get(z)??[]:[],n=i&&(e>0||B?.state===`running`||B?.state===`sleeping`||v.has(z??``)||t.length>0),r=[...Q].map((e,t)=>({item:e,index:t})).reverse().find(({item:e})=>e.type===`PendingHumanMessage`?!0:e.type===`ReceivedMessage`&&e.from_id===`human`&&ue(e.parts,e.content).length>0)?.index,a=r===void 0?[]:Q.slice(r+1),o=a.some(e=>e.type===`AssistantText`&&ue(e.parts,e.content).length>0),s=[...a].reverse().find(e=>e.type===`ToolCall`&&e.streaming===!0),c=(z?v.get(z)??null:null)??s?.tool_name??null;return{running:n,runningHint:n&&r!==void 0&&!o?{label:c?`Running tools...`:`Thinking...`,toolName:c}:null}},[v,z,B?.state,i,N.length,F,_,Q]);(0,S.useLayoutEffect)(()=>{let e=De.current;!e||!Oe.current||(e.scrollTop=e.scrollHeight)},[t,$.runningHint?`${$.runningHint.label}:${$.runningHint.toolName??``}`:``,Q]),(0,S.useLayoutEffect)(()=>{let e=De.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{Oe.current&&(e.scrollTop=e.scrollHeight)});return t.observe(e),()=>{t.disconnect()}},[]);let Ne=e=>{Oe.current=ne(e.currentTarget)},Pe=async(e={})=>{let t=E.trim();if(!t&&je.length===0||Ae||M)return;let n=f(t,je),i=E,a=O,o=A,s=Date.now(),c=t||b(n),l={text:i,images:ce(a),timestamp:s},u=e.deferWhenBusy&&z&&L.current?.target_id===z&&(J===`error`||J===`terminated`);if(e.deferWhenBusy&&z&&(J===`running`||J===`sleeping`||u)){I(re({content:c,historyEntry:l,historyScope:`assistant`,parts:n,targetId:z,targetState:J,timestamp:s})),j(null),D(``),k([]),d(a);return}if(J===`terminated`){r.error(`Resolve the current chat before sending`);return}j(null),D(``),k([]),await Y({content:c,parts:n,history:l,pendingMessageTimestamp:s,restoreDraft:{input:i,images:a,historyCursor:o}})},Fe=(0,S.useCallback)(async e=>{if(j(null),!V){r.error(`Current model does not support image input`);return}let t=Array.from(e).filter(e=>e.type.startsWith(`image/`));if(t.length===0)return;let n=await te(t);k(e=>[...e,...n]),await Promise.all(n.map(async(e,n)=>{let i=t[n];if(i)try{let t=await l(i);k(n=>n.map(n=>n.id===e.id?{...n,assetId:t.id,mimeType:t.mime_type,width:typeof t.width==`number`?t.width:n.width,height:typeof t.height==`number`?t.height:n.height,status:`ready`}:n))}catch(t){m(e),k(t=>t.filter(t=>t.id!==e.id)),r.error(t instanceof Error?t.message:`Failed to upload image`)}}))},[V]),Ie=(0,S.useCallback)(e=>{j(null),k(t=>{let n=t.find(t=>t.id===e);return n&&m(n),t.filter(t=>t.id!==e)})},[]),Le=(0,S.useCallback)((e,t)=>{if(G.length===0)return!1;let n=t.start,r=t.end,i=E.length===0&&O.length===0,a=typeof n==`number`&&typeof r==`number`&&n===r&&(n===0||n===E.length);if(!i&&!(K!==null&&q&&a))return!1;if(A===null){if(e!==-1)return!1;let t=G.length-1;return X(G[t]??null,t),!0}if(e===-1){let e=Math.max(A-1,0);return X(G[e]??null,e),!0}if(A>=G.length-1)return X(null,null),!0;let o=A+1;return X(G[o]??null,o),!0},[K,O,A,E,G,q,X]),Re=async()=>{if(!(!z||Se)){Ce(!0);try{await de(z),P([]),I(null),s(z),C(await g(z)),T(Date.now()),c(z)}catch(e){r.error(e instanceof Error?e.message:`Failed to clear assistant chat`)}finally{Ce(!1)}}},ze=(0,S.useCallback)(async()=>{if(z&&!(B?.state!==`running`&&B?.state!==`sleeping`)){await he(z);for(let e=0;e<25;e+=1){let e=await g(z);if(!e)break;if(C(e),T(Date.now()),e.state!==`running`&&e.state!==`sleeping`)return;await new Promise(e=>window.setTimeout(e,120))}throw Error(`Assistant did not stop in time`)}},[z,B?.state]),Be=async e=>{if(!(!z||!e||we)){Te(e);try{try{await ze(),await _e(e)}catch(e){r.error(e instanceof Error?e.message:`Failed to retry Assistant message`);return}s(z);try{let e=await g(z);e&&(C(e),T(Date.now()),c(z))}catch{return}}finally{Te(null)}}},Ve=(0,S.useCallback)(async()=>{if(!z)return;await he(z),P([]),s(z);let e=await g(z);e&&(C(e),T(Date.now()),c(z))},[z,s,c]);return{addImages:Fe,connected:i,draftImages:O,handleKeyDown:e=>{if(e.key===`Tab`&&!e.shiftKey){(E.trim()||je.length>0)&&(e.preventDefault(),Pe({deferWhenBusy:!0}));return}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Pe())},hasUploadingImages:Ae,input:E,isBrowsingInputHistory:q,navigateInputHistory:Le,onMessagesScroll:Ne,removeImage:Ie,retryMessage:Be,retryingMessageId:we,scrollRef:De,clearing:Se,sending:M,clearChat:Re,cancelPendingSend:(0,S.useCallback)(e=>{I(t=>t?.id===e?null:t)},[]),sendPendingSend:(0,S.useCallback)(async e=>{let t=L.current;!t||t.id!==e||!z||t.target_id!==z||M||R.current||J===`terminated`||(I(null),await Y({content:t.content,parts:t.parts??[],history:t.history_entry,pendingMessageTimestamp:t.timestamp})||I({...t,send_failed:!0,target_state:`error`}))},[z,J,M,Y]),sendMessage:Pe,setInput:Me,stopAssistant:Ve,supportsInputImage:V,timelineItems:Q,assistantActivity:$}}var E=n();function D({onOpenDetails:e}){let{agents:t}=y(),[n,a]=(0,S.useState)(!1),{height:o,ref:s}=i(),{addImages:l=async()=>{},assistantActivity:u={running:!1,runningHint:null},clearChat:d,cancelPendingSend:ee,clearing:te=!1,connected:ne,draftImages:re=[],handleKeyDown:ie,hasUploadingImages:oe=!1,input:f,isBrowsingInputHistory:p,navigateInputHistory:se,onMessagesScroll:ce,removeImage:m=()=>{},retryMessage:le,retryingMessageId:h,scrollRef:g,sending:ue,sendMessage:de,sendPendingSend:_,setInput:fe,stopAssistant:b,supportsInputImage:pe=!1,timelineItems:me}=T({bottomInset:o}),he=Array.from(t.values()).find(e=>e.node_type===`assistant`)?.role_name??null;return(0,E.jsxs)(`div`,{className:v(`relative flex h-full flex-col overflow-hidden bg-surface-overlay text-foreground`),children:[(0,E.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-0`,style:{background:`var(--shell-surface-sweep)`}}),(0,E.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-x-0 top-0 h-px`,style:{background:`var(--shell-hairline)`}}),(0,E.jsx)(`div`,{"aria-hidden":`true`,className:v(`pointer-events-none absolute inset-0 z-20 border transition-[opacity,border-color,box-shadow] duration-300`,u.running?`animate-pulse shadow-lg shadow-ring/5`:`opacity-0`,u.running&&`border-ring/25 opacity-100 shadow-ring/10`)}),(0,E.jsx)(O,{connected:ne,onClearChat:()=>void d(),onOpenDetails:e,roleName:he,clearing:te}),(0,E.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 flex-col`,children:[(0,E.jsx)(ae,{allowHumanMessageRetry:!0,bottomInset:o,items:me,nodes:t,onRetryHumanMessage:e=>void le(e),onCancelPendingSend:ee,onSendPendingSend:e=>void _(e),onScroll:ce,retryImageInputEnabled:pe,retryingMessageId:h,runningHint:u.runningHint,scrollRef:g}),(0,E.jsx)(`div`,{ref:s,style:{paddingBottom:`calc(10px + env(safe-area-inset-bottom, 0px))`},className:`pointer-events-none absolute inset-x-0 bottom-0 z-10 bg-gradient-to-b from-transparent via-background/70 to-background/95 px-2.5 pt-8`,children:(0,E.jsx)(`div`,{className:`mx-auto w-full max-w-3xl`,children:(0,E.jsx)(c,{busy:u.running,disabled:!f.trim()&&re.length===0||oe||ue,commandsEnabled:!0,images:re,imageInputEnabled:pe,input:f,onAddImages:e=>void l(e),onChange:fe,onNavigateHistory:se,onKeyDown:ie,onRemoveImage:m,onSend:()=>void de(),onStop:()=>{a(!0),b().catch(e=>{r.error(e instanceof Error?e.message:`Failed to stop Assistant`)}).finally(()=>{a(!1)})},overlay:!0,stopping:n,suppressCommandNavigation:p,targetLabel:`Assistant`})})})]})]})}function O({clearing:e,connected:t,onClearChat:n,onOpenDetails:r,roleName:i}){return(0,E.jsxs)(`div`,{className:`relative z-10 flex flex-wrap items-center gap-2.5 border-b border-border px-3.5 py-2.5`,children:[(0,E.jsxs)(`div`,{className:`flex min-w-[220px] flex-1 items-center gap-2`,children:[(0,E.jsx)(`div`,{className:`shrink-0 text-[14px] font-semibold leading-6 text-foreground`,children:`Assistant`}),i?(0,E.jsxs)(`span`,{className:`min-w-0 truncate rounded-full border border-border bg-accent/35 px-2 py-0.5 text-[10px] font-medium leading-4 text-muted-foreground/78`,children:[`Role: `,i]}):null,(0,E.jsx)(k,{connected:t})]}),(0,E.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,E.jsx)(x,{type:`button`,size:`sm`,variant:`outline`,disabled:e,onClick:n,children:e?`Clearing...`:`Clear Chat`}),(0,E.jsx)(x,{type:`button`,size:`sm`,variant:`outline`,disabled:!r,onClick:r,children:`Assistant Details`})]})]})}function k({connected:e}){return(0,E.jsx)(`span`,{className:v(`rounded-full border px-2.5 py-0.5 text-[9px] font-medium transition-colors`,e?`border-graph-status-running/18 bg-graph-status-running/[0.12] text-graph-status-running`:`border-graph-status-idle/18 bg-graph-status-idle/[0.12] text-graph-status-idle`),children:e?`Online`:`Connecting...`})}function A(){let{agents:e}=y(),t=C(e),[n,r]=(0,S.useState)(!1);return(0,E.jsx)(`div`,{className:`flex h-full flex-col min-h-0`,children:n&&t?(0,E.jsx)(`div`,{className:`h-full overflow-hidden p-6`,children:(0,E.jsx)(`div`,{className:`h-full overflow-hidden rounded-xl border border-border bg-surface-overlay/90 shadow-md`,children:(0,E.jsx)(p,{agent:t,onClose:()=>r(!1)})})}):(0,E.jsx)(D,{onOpenDetails:t?()=>r(!0):void 0})})}export{A as AssistantPage};
@@ -0,0 +1 @@
1
+ import{a as e}from"./rolldown-runtime-BYbx6iT9.js";import{d as t,l as n}from"./graph-vendor-DRq_-6fV.js";import{en as r,et as i,q as a,ut as o}from"./ui-vendor-C5pJa8N7.js";import{Y as s,r as c,rt as l,ut as u}from"./index-C9HuekJm.js";import{a as d,o as f}from"./surface-pWwG5ogx.js";import{c as p,n as m,r as h,s as g}from"./PageScaffold-f6g2l7XN.js";async function _(){return s(`/api/settings/telegram`,{errorMessage:`Failed to fetch Telegram settings`})}async function v(e){return s(`/api/settings/telegram`,{method:`PATCH`,body:e,errorMessage:`Failed to save Telegram settings`})}async function y(e){return s(`/api/settings/telegram/approve/${e}`,{method:`POST`,errorMessage:`Failed to approve Telegram chat`})}async function b(e){return s(`/api/settings/telegram/pending/${e}`,{method:`DELETE`,errorMessage:`Failed to remove pending Telegram chat`})}async function x(e){return s(`/api/settings/telegram/chat/${e}`,{method:`DELETE`,errorMessage:`Failed to remove Telegram chat`})}var S=e(t(),1);function C(e,t=`auto`){return typeof e!=`number`||!Number.isFinite(e)?null:t===`milliseconds`?e:t===`seconds`?e*1e3:e>0xe8d4a51000?e:e*1e3}function w(e,t={}){let{fallback:n=`Unknown`,format:r,unit:i=`auto`}=t,a=C(e,i);if(a===null)return n;let o=new Date(a);return r?new Intl.DateTimeFormat(void 0,r).format(o):o.toLocaleString()}var T=n();function E(e){return e?w(e,{fallback:`—`,unit:`seconds`}):`—`}function D(e){return e.display_name.trim()?e.display_name.trim():e.username?.trim()?`@${e.username.trim()}`:`Unknown chat`}function O(){let{data:e,isLoading:t,mutate:n}=p(`telegramSettings`,_),[s,C]=(0,S.useState)(!1),[w,O]=(0,S.useState)(``),[k,A]=(0,S.useState)(!1),j=(0,S.useMemo)(()=>!!e?.bot_token,[e?.bot_token]),M=async()=>{if(e){C(!0);try{let e={};k&&(e.bot_token=w.trim()),n((await v(e)).telegram,!1),O(``),A(!1),a.success(`Telegram settings saved`)}catch{a.error(`Failed to save Telegram settings`)}finally{C(!1)}}},N=async e=>{try{n((await y(e)).telegram,!1),a.success(`Telegram chat approved`)}catch{a.error(`Failed to approve Telegram chat`)}},P=async e=>{try{n((await b(e)).telegram,!1),a.success(`Pending Telegram chat removed`)}catch{a.error(`Failed to remove pending Telegram chat`)}},F=async e=>{try{n((await x(e)).telegram,!1),a.success(`Approved Telegram chat removed`)}catch{a.error(`Failed to remove approved Telegram chat`)}};return t||!e?(0,T.jsx)(c,{label:`Loading channels...`,textClassName:`text-[13px]`}):(0,T.jsx)(m,{children:(0,T.jsx)(`div`,{className:`h-full min-h-0 overflow-y-auto pr-2 scrollbar-none pt-6`,children:(0,T.jsxs)(`div`,{className:`mx-auto max-w-[680px] pb-10`,children:[(0,T.jsx)(h,{title:`Channels`}),(0,T.jsxs)(g,{className:`mt-6 space-y-8`,children:[(0,T.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,T.jsx)(`div`,{children:(0,T.jsx)(`h2`,{className:`text-lg font-medium text-foreground`,children:`Telegram`})}),(0,T.jsx)(f,{tone:j?`running`:`idle`,children:j?`Configured`:`Not configured`})]}),(0,T.jsxs)(`section`,{children:[(0,T.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,T.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/80`,children:`Bot Token`}),(0,T.jsx)(f,{tone:j?`running`:`idle`,children:j?`Saved`:`Missing`})]}),(0,T.jsxs)(`div`,{className:`mt-3`,children:[(0,T.jsx)(l,{value:w,onChange:e=>{O(e.target.value),A(!0)},placeholder:e.bot_token||`Enter Telegram bot token`,mono:!0,showLabel:`Show Telegram bot token`,hideLabel:`Hide Telegram bot token`}),j&&!k?(0,T.jsx)(`p`,{className:`mt-2 text-[11px] text-muted-foreground`,children:`Leave empty to keep the current token.`}):null]})]}),(0,T.jsxs)(`section`,{className:`border-t border-border pt-8`,children:[(0,T.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,T.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/80`,children:`Pending Private Chats`}),(0,T.jsxs)(f,{tone:`muted`,className:`px-2 py-0.5`,children:[e.pending_chats.length,` waiting`]})]}),e.pending_chats.length===0?(0,T.jsx)(`p`,{className:`mt-4 text-[13px] text-muted-foreground`,children:`No pending chats.`}):(0,T.jsx)(`div`,{className:`mt-4 space-y-2`,children:e.pending_chats.map(e=>(0,T.jsx)(d,{as:`div`,padding:`sm`,className:`px-4 py-3.5 transition-colors hover:bg-accent/20`,children:(0,T.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsx)(`p`,{className:`text-[13px] font-medium text-foreground`,children:D(e)}),(0,T.jsxs)(`div`,{className:`mt-1 flex items-center gap-3 text-[11px] text-muted-foreground`,children:[(0,T.jsxs)(`span`,{className:`font-mono`,children:[`ID: `,e.chat_id]}),e.username?(0,T.jsxs)(`span`,{children:[`@`,e.username]}):null,(0,T.jsxs)(`span`,{children:[`First seen: `,E(e.first_seen_at)]})]})]}),(0,T.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[(0,T.jsxs)(u,{type:`button`,variant:`outline`,size:`xs`,onClick:()=>void N(e.chat_id),children:[(0,T.jsx)(r,{className:`size-3.5`}),`Approve`]}),(0,T.jsx)(u,{type:`button`,variant:`ghost`,size:`icon-xs`,onClick:()=>void P(e.chat_id),className:`text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,children:(0,T.jsx)(i,{className:`size-3.5`})})]})]})},e.chat_id))})]}),(0,T.jsxs)(`section`,{className:`border-t border-border pt-8`,children:[(0,T.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,T.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/80`,children:`Approved Private Chats`}),(0,T.jsxs)(f,{tone:`muted`,className:`px-2 py-0.5`,children:[e.approved_chats.length,` active`]})]}),e.approved_chats.length===0?(0,T.jsx)(`p`,{className:`mt-4 text-[13px] text-muted-foreground`,children:`No approved chats yet.`}):(0,T.jsx)(`div`,{className:`mt-4 space-y-2`,children:e.approved_chats.map(e=>(0,T.jsx)(d,{as:`div`,padding:`sm`,className:`group px-4 py-3.5 transition-colors hover:bg-accent/20`,children:(0,T.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsx)(`p`,{className:`text-[13px] font-medium text-foreground`,children:D(e)}),(0,T.jsxs)(`div`,{className:`mt-1 flex items-center gap-3 text-[11px] text-muted-foreground`,children:[(0,T.jsxs)(`span`,{className:`font-mono`,children:[`ID: `,e.chat_id]}),e.username?(0,T.jsxs)(`span`,{children:[`@`,e.username]}):null,(0,T.jsxs)(`span`,{children:[`Approved: `,E(e.approved_at)]})]})]}),(0,T.jsx)(u,{type:`button`,variant:`ghost`,size:`icon-xs`,onClick:()=>void F(e.chat_id),className:`shrink-0 text-muted-foreground opacity-0 transition-all hover:bg-destructive/10 hover:text-destructive group-hover:opacity-100 focus:opacity-100`,children:(0,T.jsx)(i,{className:`size-3.5`})})]})},e.chat_id))})]}),(0,T.jsx)(`div`,{className:`flex justify-end border-t border-border pt-6`,children:(0,T.jsxs)(u,{type:`button`,size:`sm`,onClick:()=>void M(),disabled:s,className:`text-[13px]`,children:[(0,T.jsx)(o,{className:`size-4`}),s?`Saving...`:`Save Changes`]})})]})]})})})}export{O as ChannelsPage};
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-BYbx6iT9.js";import{c as t,d as n,l as r}from"./graph-vendor-DRq_-6fV.js";import{Lt as i}from"./ui-vendor-UazN8rcv.js";import{a,i as o,n as s,r as c,rt as l,tt as u}from"./index-Biio-CoI.js";import{s as d}from"./surface-Bzr1FRG4.js";var f=e(n(),1),p=t(),m=Object.prototype.hasOwnProperty;function h(e,t){var n,r;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((r=e.length)===t.length)for(;r--&&h(e[r],t[r]););return r===-1}if(!n||typeof e==`object`){for(n in r=0,e)if(m.call(e,n)&&++r&&!m.call(t,n)||!(n in t)||!h(e[n],t[n]))return!1;return Object.keys(t).length===r}}return e!==e&&t!==t}var g=new WeakMap,_=()=>{},v=void 0,y=Object,b=e=>e===v,x=e=>typeof e==`function`,S=(e,t)=>({...e,...t}),ee=e=>x(e.then),C={},w={},T=`undefined`,E=typeof window!=T,D=typeof document!=T,O=E&&`Deno`in window,k=()=>E&&typeof window.requestAnimationFrame!=T,te=(e,t)=>{let n=g.get(e);return[()=>!b(t)&&e.get(t)||C,r=>{if(!b(t)){let i=e.get(t);t in w||(w[t]=i),n[5](t,S(i,r),i||C)}},n[6],()=>!b(t)&&t in w?w[t]:!b(t)&&e.get(t)||C]},A=!0,j=()=>A,[M,N]=E&&window.addEventListener?[window.addEventListener.bind(window),window.removeEventListener.bind(window)]:[_,_],P=()=>{let e=D&&document.visibilityState;return b(e)||e!==`hidden`},ne=e=>(D&&document.addEventListener(`visibilitychange`,e),M(`focus`,e),()=>{D&&document.removeEventListener(`visibilitychange`,e),N(`focus`,e)}),re=e=>{let t=()=>{A=!0,e()},n=()=>{A=!1};return M(`online`,t),M(`offline`,n),()=>{N(`online`,t),N(`offline`,n)}},ie={isOnline:j,isVisible:P},F={initFocus:ne,initReconnect:re},ae=!f.useId,I=!E||O,oe=e=>k()?window.requestAnimationFrame(e):setTimeout(e,1),L=I?f.useEffect:f.useLayoutEffect,R=typeof navigator<`u`&&navigator.connection,z=!I&&R&&([`slow-2g`,`2g`].includes(R.effectiveType)||R.saveData),B=new WeakMap,se=e=>y.prototype.toString.call(e),V=(e,t)=>e===`[object ${t}]`,ce=0,H=e=>{let t=typeof e,n=se(e),r=V(n,`Date`),i=V(n,`RegExp`),a=V(n,`Object`),o,s;if(y(e)===e&&!r&&!i){if(o=B.get(e),o)return o;if(o=++ce+`~`,B.set(e,o),Array.isArray(e)){for(o=`@`,s=0;s<e.length;s++)o+=H(e[s])+`,`;B.set(e,o)}if(a){o=`#`;let t=y.keys(e).sort();for(;!b(s=t.pop());)b(e[s])||(o+=s+`:`+H(e[s])+`,`);B.set(e,o)}}else o=r?e.toJSON():t==`symbol`?e.toString():t==`string`?JSON.stringify(e):``+e;return o},le=e=>{if(x(e))try{e=e()}catch{e=``}let t=e;return e=typeof e==`string`?e:(Array.isArray(e)?e.length:e)?H(e):``,[e,t]},U=0,ue=()=>++U;async function de(...e){let[t,n,r,i]=e,a=S({populateCache:!0,throwOnError:!0},typeof i==`boolean`?{revalidate:i}:i||{}),o=a.populateCache,s=a.rollbackOnError,c=a.optimisticData,l=e=>typeof s==`function`?s(e):s!==!1,u=a.throwOnError;if(x(n)){let e=n,r=[],i=t.keys();for(let n of i)!/^\$(inf|sub)\$/.test(n)&&e(t.get(n)._k)&&r.push(n);return Promise.all(r.map(d))}return d(n);async function d(n){let[i]=le(n);if(!i)return;let[s,d]=te(t,i),[f,p,m,h]=g.get(t),_=()=>{let e=f[i];return(x(a.revalidate)?a.revalidate(s().data,n):a.revalidate!==!1)&&(delete m[i],delete h[i],e&&e[0])?e[0](2).then(()=>s().data):s().data};if(e.length<3)return _();let y=r,S,C=!1,w=ue();p[i]=[w,0];let T=!b(c),E=s(),D=E.data,O=E._c,k=b(O)?D:O;if(T&&(c=x(c)?c(k,D):c,d({data:c,_c:k})),x(y))try{y=y(k)}catch(e){S=e,C=!0}if(y&&ee(y))if(y=await y.catch(e=>{S=e,C=!0}),w!==p[i][0]){if(C)throw S;return y}else C&&T&&l(S)&&(o=!0,d({data:k,_c:v}));if(o&&(C||(x(o)?d({data:o(y,k),error:v,_c:v}):d({data:y,error:v,_c:v}))),p[i][1]=ue(),Promise.resolve(_()).then(()=>{d({_c:v})}),C){if(u)throw S;return}return y}}var W=(e,t)=>{for(let n in e)e[n][0]&&e[n][0](t)},G=(e,t)=>{if(!g.has(e)){let n=S(F,t),r=Object.create(null),i=de.bind(v,e),a=_,o=Object.create(null),s=(e,t)=>{let n=o[e]||[];return o[e]=n,n.push(t),()=>n.splice(n.indexOf(t),1)},c=(t,n,r)=>{e.set(t,n);let i=o[t];if(i)for(let e of i)e(n,r)},l=()=>{if(!g.has(e)&&(g.set(e,[r,Object.create(null),Object.create(null),Object.create(null),i,c,s]),!I)){let t=n.initFocus(setTimeout.bind(v,W.bind(v,r,0))),i=n.initReconnect(setTimeout.bind(v,W.bind(v,r,1)));a=()=>{t&&t(),i&&i(),g.delete(e)}}};return l(),[e,i,l,a]}return[e,g.get(e)[4]]},K=(e,t,n,r,i)=>{let a=n.errorRetryCount,o=i.retryCount,s=~~((Math.random()+.5)*(1<<(o<8?o:8)))*n.errorRetryInterval;!b(a)&&o>a||setTimeout(r,s,i)},q=h,[J,fe]=G(new Map),Y=S({onLoadingSlow:_,onSuccess:_,onError:_,onErrorRetry:K,onDiscarded:_,revalidateOnFocus:!0,revalidateOnReconnect:!0,revalidateIfStale:!0,shouldRetryOnError:!0,errorRetryInterval:z?1e4:5e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:z?5e3:3e3,compare:q,isPaused:()=>!1,cache:J,mutate:fe,fallback:{}},ie),X=(e,t)=>{let n=S(e,t);if(t){let{use:r,fallback:i}=e,{use:a,fallback:o}=t;r&&a&&(n.use=r.concat(a)),i&&o&&(n.fallback=S(i,o))}return n},Z=(0,f.createContext)({}),pe=e=>{let{value:t}=e,n=(0,f.useContext)(Z),r=x(t),i=(0,f.useMemo)(()=>r?t(n):t,[r,n,t]),a=(0,f.useMemo)(()=>r?i:X(n,i),[r,n,i]),o=i&&i.provider,s=(0,f.useRef)(v);o&&!s.current&&(s.current=G(o(a.cache||J),i));let c=s.current;return c&&(a.cache=c[0],a.mutate=c[1]),L(()=>{if(c)return c[2]&&c[2](),c[3]},[]),(0,f.createElement)(Z.Provider,S(e,{value:a}))},Q=E&&window.__SWR_DEVTOOLS_USE__,me=Q?window.__SWR_DEVTOOLS_USE__:[],he=()=>{Q&&(window.__SWR_DEVTOOLS_REACT__=f.default)},ge=e=>x(e[1])?[e[0],e[1],e[2]||{}]:[e[0],null,(e[1]===null?e[2]:e[1])||{}],_e=()=>{let e=(0,f.useContext)(Z);return(0,f.useMemo)(()=>S(Y,e),[e])},ve=me.concat(e=>(t,n,r)=>e(t,n&&((...e)=>{let[r]=le(t),[,,,i]=g.get(J);if(r.startsWith(`$inf$`))return n(...e);let a=i[r];return b(a)?n(...e):(delete i[r],a)}),r)),ye=e=>function(...t){let n=_e(),[r,i,a]=ge(t),o=X(n,a),s=e,{use:c}=o,l=(c||[]).concat(ve);for(let e=l.length;e--;)s=l[e](s);return s(r,i||o.fetcher||null,o)},be=(e,t,n)=>{let r=t[e]||(t[e]=[]);return r.push(n),()=>{let e=r.indexOf(n);e>=0&&(r[e]=r[r.length-1],r.pop())}};he();var xe=f.use||(e=>{switch(e.status){case`pending`:throw e;case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:throw e.status=`pending`,e.then(t=>{e.status=`fulfilled`,e.value=t},t=>{e.status=`rejected`,e.reason=t}),e}}),Se={dedupe:!0},Ce=Promise.resolve(v),we=()=>_,Te=(e,t,n)=>{let{cache:r,compare:i,suspense:a,fallbackData:o,revalidateOnMount:s,revalidateIfStale:c,refreshInterval:l,refreshWhenHidden:u,refreshWhenOffline:d,keepPreviousData:m,strictServerPrefetchWarning:h}=n,[_,y,C,w]=g.get(r),[T,E]=le(e),D=(0,f.useRef)(!1),O=(0,f.useRef)(!1),k=(0,f.useRef)(T),A=(0,f.useRef)(t),j=(0,f.useRef)(n),M=()=>j.current,N=()=>M().isVisible()&&M().isOnline(),[P,ne,re,ie]=te(r,T),F=(0,f.useRef)({}).current,R=b(o)?b(n.fallback)?v:n.fallback[T]:o,z=(e,t)=>{for(let n in F){let r=n;if(r===`data`){if(!i(e[r],t[r])&&(!b(e[r])||!i(K,t[r])))return!1}else if(t[r]!==e[r])return!1}return!0},B=!D.current,se=(0,f.useMemo)(()=>{let e=P(),n=ie(),r=e=>{let n=S(e);return delete n._k,!(!T||!t||M().isPaused())&&(B&&!b(s)?s:b(b(R)?n.data:R)||c)?{isValidating:!0,isLoading:!0,...n}:n},i=r(e),a=e===n?i:r(n),o=i;return[()=>{let e=r(P());return z(e,o)?(o.data=e.data,o.isLoading=e.isLoading,o.isValidating=e.isValidating,o.error=e.error,o):(o=e,e)},()=>a]},[r,T]),V=(0,p.useSyncExternalStore)((0,f.useCallback)(e=>re(T,(t,n)=>{z(n,t)||e()}),[r,T]),se[0],se[1]),ce=_[T]&&_[T].length>0,H=V.data,U=b(H)?R&&ee(R)?xe(R):R:H,W=V.error,G=(0,f.useRef)(U),K=m?b(H)?b(G.current)?U:G.current:H:U,q=T&&b(U),J=(0,f.useRef)(null);!I&&(0,p.useSyncExternalStore)(we,()=>(J.current=!1,J),()=>(J.current=!0,J));let fe=J.current;h&&fe&&!a&&q&&console.warn(`Missing pre-initiated data for serialized key "${T}" during server-side rendering. Data fetching should be initiated on the server and provided to SWR via fallback data. You can set "strictServerPrefetchWarning: false" to disable this warning.`);let Y=!T||!t||M().isPaused()||ce&&!b(W)?!1:B&&!b(s)?s:a?b(U)?!1:c:b(U)||c,X=B&&Y,Z=b(V.isValidating)?X:V.isValidating,pe=b(V.isLoading)?X:V.isLoading,Q=(0,f.useCallback)(async e=>{let t=A.current;if(!T||!t||O.current||M().isPaused())return!1;let r,a,o=!0,s=e||{},c=!C[T]||!s.dedupe,l=()=>ae?!O.current&&T===k.current&&D.current:T===k.current,u={isValidating:!1,isLoading:!1},d=()=>{ne(u)},f=()=>{let e=C[T];e&&e[1]===a&&delete C[T]},p={isValidating:!0};b(P().data)&&(p.isLoading=!0);try{if(c&&(ne(p),n.loadingTimeout&&b(P().data)&&setTimeout(()=>{o&&l()&&M().onLoadingSlow(T,n)},n.loadingTimeout),C[T]=[t(E),ue()]),[r,a]=C[T],r=await r,c&&setTimeout(f,n.dedupingInterval),!C[T]||C[T][1]!==a)return c&&l()&&M().onDiscarded(T),!1;u.error=v;let e=y[T];if(!b(e)&&(a<=e[0]||a<=e[1]||e[1]===0))return d(),c&&l()&&M().onDiscarded(T),!1;let s=P().data;u.data=i(s,r)?s:r,c&&l()&&M().onSuccess(r,T,n)}catch(e){f();let t=M(),{shouldRetryOnError:n}=t;t.isPaused()||(u.error=e,c&&l()&&(t.onError(e,T,t),(n===!0||x(n)&&n(e))&&(!M().revalidateOnFocus||!M().revalidateOnReconnect||N())&&t.onErrorRetry(e,T,t,e=>{let t=_[T];t&&t[0]&&t[0](3,e)},{retryCount:(s.retryCount||0)+1,dedupe:!0})))}return o=!1,d(),!0},[T,r]),me=(0,f.useCallback)((...e)=>de(r,k.current,...e),[]);if(L(()=>{A.current=t,j.current=n,b(H)||(G.current=H)}),L(()=>{if(!T)return;let e=Q.bind(v,Se),t=0;M().revalidateOnFocus&&(t=Date.now()+M().focusThrottleInterval);let n=be(T,_,(n,r={})=>{if(n==0){let n=Date.now();M().revalidateOnFocus&&n>t&&N()&&(t=n+M().focusThrottleInterval,e())}else if(n==1)M().revalidateOnReconnect&&N()&&e();else if(n==2)return Q();else if(n==3)return Q(r)});return O.current=!1,k.current=T,D.current=!0,ne({_k:E}),Y&&(C[T]||(b(U)||I?e():oe(e))),()=>{O.current=!0,n()}},[T]),L(()=>{let e;function t(){let t=x(l)?l(P().data):l;t&&e!==-1&&(e=setTimeout(n,t))}function n(){!P().error&&(u||M().isVisible())&&(d||M().isOnline())?Q(Se).then(t):t()}return t(),()=>{e&&=(clearTimeout(e),-1)}},[l,u,d,T]),(0,f.useDebugValue)(K),a){if(!ae&&I&&q)throw Error(`Fallback data is required when using Suspense in SSR.`);q&&(A.current=t,j.current=n,O.current=!1);let e=w[T];if(xe(!b(e)&&q?me(e):Ce),!b(W)&&q)throw W;let r=q?Q(Se):Ce;!b(K)&&q&&(r.status=`fulfilled`,r.value=!0),xe(r)}return{mutate:me,get data(){return F.data=!0,K},get error(){return F.error=!0,W},get isValidating(){return F.isValidating=!0,Z},get isLoading(){return F.isLoading=!0,pe}}};y.defineProperty(pe,`defaultValue`,{value:Y});var Ee=ye(Te),$=r();function De({children:e,className:t}){return(0,$.jsx)(`div`,{className:l(`flex h-full flex-col min-h-0 overflow-hidden`,t),children:e})}function Oe({children:e,className:t}){return(0,$.jsx)(d,{as:`section`,padding:`md`,className:l(`border-transparent bg-card/[0.18] ring-1 ring-white/[0.04]`,t),children:e})}function ke({actions:e,className:t,hint:n,title:r}){return(0,$.jsx)(`div`,{className:l(`border-b border-border/70 pb-4`,t),children:(0,$.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(`h1`,{className:`text-[28px] font-medium tracking-[-0.04em] text-foreground`,children:r}),n?(0,$.jsx)(o,{delayDuration:150,children:(0,$.jsxs)(s,{children:[(0,$.jsx)(a,{asChild:!0,children:(0,$.jsx)(u,{type:`button`,variant:`ghost`,size:`icon-sm`,className:`inline-flex size-7 items-center justify-center rounded-full border border-border/70 bg-card/20 text-muted-foreground transition-colors hover:bg-accent/35 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50`,"aria-label":`${r} details`,children:(0,$.jsx)(i,{className:`size-3.5`})})}),(0,$.jsx)(c,{side:`right`,className:`max-w-xs px-3 py-2`,children:n})]})}):null]}),e?(0,$.jsx)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:e}):null]})})}function Ae({title:e}){return(0,$.jsx)(`div`,{className:`mb-4`,children:(0,$.jsx)(`h2`,{className:`text-[14px] font-medium tracking-tight text-foreground/90`,children:e})})}function je({children:e,className:t,contentClassName:n,separated:r=!1,title:i}){return(0,$.jsxs)(`section`,{className:l(r?`border-t border-border pt-8`:`mb-10`,t),children:[(0,$.jsx)(Ae,{title:i}),(0,$.jsx)(`div`,{className:l(`rounded-xl border border-white/[0.04] bg-card/[0.03] shadow-sm px-5 transition-colors`,n),children:e})]})}function Me({label:e,description:t,children:n,valueClassName:r}){return(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 border-b border-border/40 py-5 last:border-b-0 md:flex-row md:items-start md:justify-between md:gap-8 hover:bg-muted/10 transition-colors`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 shrink-0 md:w-[35%] pt-1`,children:[(0,$.jsx)(`label`,{className:`block text-[13px] font-medium text-foreground/80 tracking-tight`,children:e}),t&&(0,$.jsx)(`p`,{className:`mt-1 text-[12px] text-muted-foreground/70 leading-relaxed pr-4`,children:t})]}),(0,$.jsx)(`div`,{className:l(`w-full min-w-0 flex-1 md:w-[65%] flex md:justify-end`,r),children:(0,$.jsx)(`div`,{className:`w-full md:max-w-md space-y-3`,children:n})})]})}function Ne({label:e,description:t,children:n}){return(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 border-b border-border/40 py-5 last:border-b-0 hover:bg-muted/10 transition-colors`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 pt-1`,children:[(0,$.jsx)(`label`,{className:`block text-[13px] font-medium text-foreground/80 tracking-tight`,children:e}),t&&(0,$.jsx)(`p`,{className:`mt-1.5 text-[12px] text-muted-foreground/70 leading-relaxed max-w-2xl`,children:t})]}),(0,$.jsx)(`div`,{className:`w-full mt-1`,children:n})]})}function Pe({children:e,className:t}){return(0,$.jsx)(`div`,{className:l(`mt-3 flex flex-col gap-3 rounded-lg border border-border/40 bg-background/30 p-4`,t),children:e})}export{Me as a,Ee as c,Pe as i,De as n,Ne as o,ke as r,Oe as s,je as t};
1
+ import{a as e}from"./rolldown-runtime-BYbx6iT9.js";import{c as t,d as n,l as r}from"./graph-vendor-DRq_-6fV.js";import{Ft as i}from"./ui-vendor-C5pJa8N7.js";import{a,ft as o,i as s,o as c,s as l,ut as u}from"./index-C9HuekJm.js";import{a as d}from"./surface-pWwG5ogx.js";var f=e(n(),1),p=t(),m=Object.prototype.hasOwnProperty;function h(e,t){var n,r;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((r=e.length)===t.length)for(;r--&&h(e[r],t[r]););return r===-1}if(!n||typeof e==`object`){for(n in r=0,e)if(m.call(e,n)&&++r&&!m.call(t,n)||!(n in t)||!h(e[n],t[n]))return!1;return Object.keys(t).length===r}}return e!==e&&t!==t}var g=new WeakMap,_=()=>{},v=void 0,y=Object,b=e=>e===v,x=e=>typeof e==`function`,S=(e,t)=>({...e,...t}),ee=e=>x(e.then),C={},w={},T=`undefined`,E=typeof window!=T,D=typeof document!=T,O=E&&`Deno`in window,k=()=>E&&typeof window.requestAnimationFrame!=T,te=(e,t)=>{let n=g.get(e);return[()=>!b(t)&&e.get(t)||C,r=>{if(!b(t)){let i=e.get(t);t in w||(w[t]=i),n[5](t,S(i,r),i||C)}},n[6],()=>!b(t)&&t in w?w[t]:!b(t)&&e.get(t)||C]},A=!0,j=()=>A,[M,N]=E&&window.addEventListener?[window.addEventListener.bind(window),window.removeEventListener.bind(window)]:[_,_],P=()=>{let e=D&&document.visibilityState;return b(e)||e!==`hidden`},ne=e=>(D&&document.addEventListener(`visibilitychange`,e),M(`focus`,e),()=>{D&&document.removeEventListener(`visibilitychange`,e),N(`focus`,e)}),re=e=>{let t=()=>{A=!0,e()},n=()=>{A=!1};return M(`online`,t),M(`offline`,n),()=>{N(`online`,t),N(`offline`,n)}},ie={isOnline:j,isVisible:P},F={initFocus:ne,initReconnect:re},ae=!f.useId,I=!E||O,oe=e=>k()?window.requestAnimationFrame(e):setTimeout(e,1),L=I?f.useEffect:f.useLayoutEffect,R=typeof navigator<`u`&&navigator.connection,z=!I&&R&&([`slow-2g`,`2g`].includes(R.effectiveType)||R.saveData),B=new WeakMap,se=e=>y.prototype.toString.call(e),V=(e,t)=>e===`[object ${t}]`,ce=0,H=e=>{let t=typeof e,n=se(e),r=V(n,`Date`),i=V(n,`RegExp`),a=V(n,`Object`),o,s;if(y(e)===e&&!r&&!i){if(o=B.get(e),o)return o;if(o=++ce+`~`,B.set(e,o),Array.isArray(e)){for(o=`@`,s=0;s<e.length;s++)o+=H(e[s])+`,`;B.set(e,o)}if(a){o=`#`;let t=y.keys(e).sort();for(;!b(s=t.pop());)b(e[s])||(o+=s+`:`+H(e[s])+`,`);B.set(e,o)}}else o=r?e.toJSON():t==`symbol`?e.toString():t==`string`?JSON.stringify(e):``+e;return o},le=e=>{if(x(e))try{e=e()}catch{e=``}let t=e;return e=typeof e==`string`?e:(Array.isArray(e)?e.length:e)?H(e):``,[e,t]},U=0,ue=()=>++U;async function de(...e){let[t,n,r,i]=e,a=S({populateCache:!0,throwOnError:!0},typeof i==`boolean`?{revalidate:i}:i||{}),o=a.populateCache,s=a.rollbackOnError,c=a.optimisticData,l=e=>typeof s==`function`?s(e):s!==!1,u=a.throwOnError;if(x(n)){let e=n,r=[],i=t.keys();for(let n of i)!/^\$(inf|sub)\$/.test(n)&&e(t.get(n)._k)&&r.push(n);return Promise.all(r.map(d))}return d(n);async function d(n){let[i]=le(n);if(!i)return;let[s,d]=te(t,i),[f,p,m,h]=g.get(t),_=()=>{let e=f[i];return(x(a.revalidate)?a.revalidate(s().data,n):a.revalidate!==!1)&&(delete m[i],delete h[i],e&&e[0])?e[0](2).then(()=>s().data):s().data};if(e.length<3)return _();let y=r,S,C=!1,w=ue();p[i]=[w,0];let T=!b(c),E=s(),D=E.data,O=E._c,k=b(O)?D:O;if(T&&(c=x(c)?c(k,D):c,d({data:c,_c:k})),x(y))try{y=y(k)}catch(e){S=e,C=!0}if(y&&ee(y))if(y=await y.catch(e=>{S=e,C=!0}),w!==p[i][0]){if(C)throw S;return y}else C&&T&&l(S)&&(o=!0,d({data:k,_c:v}));if(o&&(C||(x(o)?d({data:o(y,k),error:v,_c:v}):d({data:y,error:v,_c:v}))),p[i][1]=ue(),Promise.resolve(_()).then(()=>{d({_c:v})}),C){if(u)throw S;return}return y}}var W=(e,t)=>{for(let n in e)e[n][0]&&e[n][0](t)},G=(e,t)=>{if(!g.has(e)){let n=S(F,t),r=Object.create(null),i=de.bind(v,e),a=_,o=Object.create(null),s=(e,t)=>{let n=o[e]||[];return o[e]=n,n.push(t),()=>n.splice(n.indexOf(t),1)},c=(t,n,r)=>{e.set(t,n);let i=o[t];if(i)for(let e of i)e(n,r)},l=()=>{if(!g.has(e)&&(g.set(e,[r,Object.create(null),Object.create(null),Object.create(null),i,c,s]),!I)){let t=n.initFocus(setTimeout.bind(v,W.bind(v,r,0))),i=n.initReconnect(setTimeout.bind(v,W.bind(v,r,1)));a=()=>{t&&t(),i&&i(),g.delete(e)}}};return l(),[e,i,l,a]}return[e,g.get(e)[4]]},K=(e,t,n,r,i)=>{let a=n.errorRetryCount,o=i.retryCount,s=~~((Math.random()+.5)*(1<<(o<8?o:8)))*n.errorRetryInterval;!b(a)&&o>a||setTimeout(r,s,i)},q=h,[J,fe]=G(new Map),Y=S({onLoadingSlow:_,onSuccess:_,onError:_,onErrorRetry:K,onDiscarded:_,revalidateOnFocus:!0,revalidateOnReconnect:!0,revalidateIfStale:!0,shouldRetryOnError:!0,errorRetryInterval:z?1e4:5e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:z?5e3:3e3,compare:q,isPaused:()=>!1,cache:J,mutate:fe,fallback:{}},ie),X=(e,t)=>{let n=S(e,t);if(t){let{use:r,fallback:i}=e,{use:a,fallback:o}=t;r&&a&&(n.use=r.concat(a)),i&&o&&(n.fallback=S(i,o))}return n},Z=(0,f.createContext)({}),pe=e=>{let{value:t}=e,n=(0,f.useContext)(Z),r=x(t),i=(0,f.useMemo)(()=>r?t(n):t,[r,n,t]),a=(0,f.useMemo)(()=>r?i:X(n,i),[r,n,i]),o=i&&i.provider,s=(0,f.useRef)(v);o&&!s.current&&(s.current=G(o(a.cache||J),i));let c=s.current;return c&&(a.cache=c[0],a.mutate=c[1]),L(()=>{if(c)return c[2]&&c[2](),c[3]},[]),(0,f.createElement)(Z.Provider,S(e,{value:a}))},Q=E&&window.__SWR_DEVTOOLS_USE__,me=Q?window.__SWR_DEVTOOLS_USE__:[],he=()=>{Q&&(window.__SWR_DEVTOOLS_REACT__=f.default)},ge=e=>x(e[1])?[e[0],e[1],e[2]||{}]:[e[0],null,(e[1]===null?e[2]:e[1])||{}],_e=()=>{let e=(0,f.useContext)(Z);return(0,f.useMemo)(()=>S(Y,e),[e])},ve=me.concat(e=>(t,n,r)=>e(t,n&&((...e)=>{let[r]=le(t),[,,,i]=g.get(J);if(r.startsWith(`$inf$`))return n(...e);let a=i[r];return b(a)?n(...e):(delete i[r],a)}),r)),ye=e=>function(...t){let n=_e(),[r,i,a]=ge(t),o=X(n,a),s=e,{use:c}=o,l=(c||[]).concat(ve);for(let e=l.length;e--;)s=l[e](s);return s(r,i||o.fetcher||null,o)},be=(e,t,n)=>{let r=t[e]||(t[e]=[]);return r.push(n),()=>{let e=r.indexOf(n);e>=0&&(r[e]=r[r.length-1],r.pop())}};he();var xe=f.use||(e=>{switch(e.status){case`pending`:throw e;case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:throw e.status=`pending`,e.then(t=>{e.status=`fulfilled`,e.value=t},t=>{e.status=`rejected`,e.reason=t}),e}}),Se={dedupe:!0},Ce=Promise.resolve(v),we=()=>_,Te=(e,t,n)=>{let{cache:r,compare:i,suspense:a,fallbackData:o,revalidateOnMount:s,revalidateIfStale:c,refreshInterval:l,refreshWhenHidden:u,refreshWhenOffline:d,keepPreviousData:m,strictServerPrefetchWarning:h}=n,[_,y,C,w]=g.get(r),[T,E]=le(e),D=(0,f.useRef)(!1),O=(0,f.useRef)(!1),k=(0,f.useRef)(T),A=(0,f.useRef)(t),j=(0,f.useRef)(n),M=()=>j.current,N=()=>M().isVisible()&&M().isOnline(),[P,ne,re,ie]=te(r,T),F=(0,f.useRef)({}).current,R=b(o)?b(n.fallback)?v:n.fallback[T]:o,z=(e,t)=>{for(let n in F){let r=n;if(r===`data`){if(!i(e[r],t[r])&&(!b(e[r])||!i(K,t[r])))return!1}else if(t[r]!==e[r])return!1}return!0},B=!D.current,se=(0,f.useMemo)(()=>{let e=P(),n=ie(),r=e=>{let n=S(e);return delete n._k,!(!T||!t||M().isPaused())&&(B&&!b(s)?s:b(b(R)?n.data:R)||c)?{isValidating:!0,isLoading:!0,...n}:n},i=r(e),a=e===n?i:r(n),o=i;return[()=>{let e=r(P());return z(e,o)?(o.data=e.data,o.isLoading=e.isLoading,o.isValidating=e.isValidating,o.error=e.error,o):(o=e,e)},()=>a]},[r,T]),V=(0,p.useSyncExternalStore)((0,f.useCallback)(e=>re(T,(t,n)=>{z(n,t)||e()}),[r,T]),se[0],se[1]),ce=_[T]&&_[T].length>0,H=V.data,U=b(H)?R&&ee(R)?xe(R):R:H,W=V.error,G=(0,f.useRef)(U),K=m?b(H)?b(G.current)?U:G.current:H:U,q=T&&b(U),J=(0,f.useRef)(null);!I&&(0,p.useSyncExternalStore)(we,()=>(J.current=!1,J),()=>(J.current=!0,J));let fe=J.current;h&&fe&&!a&&q&&console.warn(`Missing pre-initiated data for serialized key "${T}" during server-side rendering. Data fetching should be initiated on the server and provided to SWR via fallback data. You can set "strictServerPrefetchWarning: false" to disable this warning.`);let Y=!T||!t||M().isPaused()||ce&&!b(W)?!1:B&&!b(s)?s:a?b(U)?!1:c:b(U)||c,X=B&&Y,Z=b(V.isValidating)?X:V.isValidating,pe=b(V.isLoading)?X:V.isLoading,Q=(0,f.useCallback)(async e=>{let t=A.current;if(!T||!t||O.current||M().isPaused())return!1;let r,a,o=!0,s=e||{},c=!C[T]||!s.dedupe,l=()=>ae?!O.current&&T===k.current&&D.current:T===k.current,u={isValidating:!1,isLoading:!1},d=()=>{ne(u)},f=()=>{let e=C[T];e&&e[1]===a&&delete C[T]},p={isValidating:!0};b(P().data)&&(p.isLoading=!0);try{if(c&&(ne(p),n.loadingTimeout&&b(P().data)&&setTimeout(()=>{o&&l()&&M().onLoadingSlow(T,n)},n.loadingTimeout),C[T]=[t(E),ue()]),[r,a]=C[T],r=await r,c&&setTimeout(f,n.dedupingInterval),!C[T]||C[T][1]!==a)return c&&l()&&M().onDiscarded(T),!1;u.error=v;let e=y[T];if(!b(e)&&(a<=e[0]||a<=e[1]||e[1]===0))return d(),c&&l()&&M().onDiscarded(T),!1;let s=P().data;u.data=i(s,r)?s:r,c&&l()&&M().onSuccess(r,T,n)}catch(e){f();let t=M(),{shouldRetryOnError:n}=t;t.isPaused()||(u.error=e,c&&l()&&(t.onError(e,T,t),(n===!0||x(n)&&n(e))&&(!M().revalidateOnFocus||!M().revalidateOnReconnect||N())&&t.onErrorRetry(e,T,t,e=>{let t=_[T];t&&t[0]&&t[0](3,e)},{retryCount:(s.retryCount||0)+1,dedupe:!0})))}return o=!1,d(),!0},[T,r]),me=(0,f.useCallback)((...e)=>de(r,k.current,...e),[]);if(L(()=>{A.current=t,j.current=n,b(H)||(G.current=H)}),L(()=>{if(!T)return;let e=Q.bind(v,Se),t=0;M().revalidateOnFocus&&(t=Date.now()+M().focusThrottleInterval);let n=be(T,_,(n,r={})=>{if(n==0){let n=Date.now();M().revalidateOnFocus&&n>t&&N()&&(t=n+M().focusThrottleInterval,e())}else if(n==1)M().revalidateOnReconnect&&N()&&e();else if(n==2)return Q();else if(n==3)return Q(r)});return O.current=!1,k.current=T,D.current=!0,ne({_k:E}),Y&&(C[T]||(b(U)||I?e():oe(e))),()=>{O.current=!0,n()}},[T]),L(()=>{let e;function t(){let t=x(l)?l(P().data):l;t&&e!==-1&&(e=setTimeout(n,t))}function n(){!P().error&&(u||M().isVisible())&&(d||M().isOnline())?Q(Se).then(t):t()}return t(),()=>{e&&=(clearTimeout(e),-1)}},[l,u,d,T]),(0,f.useDebugValue)(K),a){if(!ae&&I&&q)throw Error(`Fallback data is required when using Suspense in SSR.`);q&&(A.current=t,j.current=n,O.current=!1);let e=w[T];if(xe(!b(e)&&q?me(e):Ce),!b(W)&&q)throw W;let r=q?Q(Se):Ce;!b(K)&&q&&(r.status=`fulfilled`,r.value=!0),xe(r)}return{mutate:me,get data(){return F.data=!0,K},get error(){return F.error=!0,W},get isValidating(){return F.isValidating=!0,Z},get isLoading(){return F.isLoading=!0,pe}}};y.defineProperty(pe,`defaultValue`,{value:Y});var Ee=ye(Te),$=r();function De({children:e,className:t}){return(0,$.jsx)(`div`,{className:o(`flex h-full flex-col min-h-0 overflow-hidden`,t),children:e})}function Oe({children:e,className:t}){return(0,$.jsx)(d,{as:`section`,padding:`md`,className:o(`border-transparent bg-card/[0.18] ring-1 ring-white/[0.04]`,t),children:e})}function ke({actions:e,className:t,hint:n,title:r}){return(0,$.jsx)(`div`,{className:o(`border-b border-border/70 pb-4`,t),children:(0,$.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(`h1`,{className:`text-[28px] font-medium tracking-[-0.04em] text-foreground`,children:r}),n?(0,$.jsx)(c,{delayDuration:150,children:(0,$.jsxs)(s,{children:[(0,$.jsx)(l,{asChild:!0,children:(0,$.jsx)(u,{type:`button`,variant:`ghost`,size:`icon-sm`,className:`inline-flex size-7 items-center justify-center rounded-full border border-border/70 bg-card/20 text-muted-foreground transition-colors hover:bg-accent/35 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50`,"aria-label":`${r} details`,children:(0,$.jsx)(i,{className:`size-3.5`})})}),(0,$.jsx)(a,{side:`right`,className:`max-w-xs px-3 py-2`,children:n})]})}):null]}),e?(0,$.jsx)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:e}):null]})})}function Ae({title:e}){return(0,$.jsx)(`div`,{className:`mb-4`,children:(0,$.jsx)(`h2`,{className:`text-[14px] font-medium tracking-tight text-foreground/90`,children:e})})}function je({children:e,className:t,contentClassName:n,separated:r=!1,title:i}){return(0,$.jsxs)(`section`,{className:o(r?`border-t border-border pt-8`:`mb-10`,t),children:[(0,$.jsx)(Ae,{title:i}),(0,$.jsx)(`div`,{className:o(`rounded-xl border border-white/[0.04] bg-card/[0.03] shadow-sm px-5 transition-colors`,n),children:e})]})}function Me({label:e,description:t,children:n,valueClassName:r}){return(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 border-b border-border/40 py-5 last:border-b-0 md:flex-row md:items-start md:justify-between md:gap-8 hover:bg-muted/10 transition-colors`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 shrink-0 md:w-[35%] pt-1`,children:[(0,$.jsx)(`label`,{className:`block text-[13px] font-medium text-foreground/80 tracking-tight`,children:e}),t&&(0,$.jsx)(`p`,{className:`mt-1 text-[12px] text-muted-foreground/70 leading-relaxed pr-4`,children:t})]}),(0,$.jsx)(`div`,{className:o(`w-full min-w-0 flex-1 md:w-[65%] flex md:justify-end`,r),children:(0,$.jsx)(`div`,{className:`w-full md:max-w-md space-y-3`,children:n})})]})}function Ne({label:e,description:t,children:n}){return(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 border-b border-border/40 py-5 last:border-b-0 hover:bg-muted/10 transition-colors`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 pt-1`,children:[(0,$.jsx)(`label`,{className:`block text-[13px] font-medium text-foreground/80 tracking-tight`,children:e}),t&&(0,$.jsx)(`p`,{className:`mt-1.5 text-[12px] text-muted-foreground/70 leading-relaxed max-w-2xl`,children:t})]}),(0,$.jsx)(`div`,{className:`w-full mt-1`,children:n})]})}function Pe({children:e,className:t}){return(0,$.jsx)(`div`,{className:o(`mt-3 flex flex-col gap-3 rounded-lg border border-border/40 bg-background/30 p-4`,t),children:e})}export{Me as a,Ee as c,Pe as i,De as n,Ne as o,ke as r,Oe as s,je as t};
@@ -0,0 +1 @@
1
+ import{a as e}from"./rolldown-runtime-BYbx6iT9.js";import{d as t,l as n}from"./graph-vendor-DRq_-6fV.js";import{Ft as r,q as i,ut as a}from"./ui-vendor-C5pJa8N7.js";import{Y as o,a as s,i as c,nt as l,o as u,r as d,s as f,ut as p}from"./index-C9HuekJm.js";import{a as m,o as h}from"./surface-pWwG5ogx.js";import{c as g,n as _,r as v}from"./PageScaffold-f6g2l7XN.js";async function y(){return o(`/api/prompts`,{errorMessage:`Failed to fetch prompts`})}async function b(e){return o(`/api/prompts`,{method:`PUT`,body:e,errorMessage:`Failed to save prompts`})}var x=e(t(),1),S=n(),C=`min-h-0 w-full flex-1 resize-none select-text rounded-md bg-transparent p-3 font-mono text-[13px] leading-relaxed text-foreground placeholder:text-muted-foreground transition-colors focus:bg-background/35 focus:outline-none scrollbar-none`;function w(){let{data:e,isLoading:t,mutate:n}=g(`promptSettings`,y),[r,o]=(0,x.useState)(``),[s,c]=(0,x.useState)(``),[u,f]=(0,x.useState)(!1);(0,x.useEffect)(()=>{e&&(o(e.custom_prompt),c(e.custom_post_prompt))},[e]);let w=async()=>{f(!0);try{n(await b({custom_prompt:r,custom_post_prompt:s}),!1),i.success(`Prompts saved`)}catch{i.error(`Failed to save prompts`)}finally{f(!1)}};return t?(0,S.jsx)(d,{label:`Loading prompts...`,textClassName:`text-[13px]`}):(0,S.jsx)(_,{children:(0,S.jsxs)(`div`,{className:`mx-auto flex h-full w-full max-w-[800px] flex-col px-4 pb-10 pt-6`,children:[(0,S.jsx)(v,{title:`Prompts`,hint:`Custom Prompt is appended to the global system prompt layer. Custom Post Prompt is appended after the built-in runtime post prompt.`,actions:(0,S.jsxs)(p,{type:`button`,onClick:()=>void w(),disabled:u,size:`sm`,className:`text-[13px]`,children:[(0,S.jsx)(a,{className:`size-4`}),u?`Saving...`:`Save Changes`]})}),(0,S.jsxs)(`div`,{className:`grid min-h-0 flex-1 gap-8 pt-6`,children:[(0,S.jsxs)(`div`,{className:`flex min-h-0 flex-col`,children:[(0,S.jsx)(`div`,{className:`mb-3 flex items-center justify-between px-1`,children:(0,S.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,S.jsx)(`h2`,{className:`text-[15px] font-medium text-foreground`,children:`Custom Prompt`}),T(`Custom Prompt details`,`Appended to every node's system prompt.`),(0,S.jsxs)(h,{tone:`neutral`,className:`px-2 py-0.5`,children:[r.length,` chars`]})]})}),(0,S.jsx)(m,{as:`div`,padding:`none`,className:`relative flex min-h-0 flex-1 p-1`,children:(0,S.jsx)(l,{"aria-label":`Custom Prompt`,value:r,onChange:e=>o(e.target.value),placeholder:`Appended to every node's system prompt...`,className:C,mono:!0})})]}),(0,S.jsxs)(`div`,{className:`flex min-h-0 flex-col`,children:[(0,S.jsx)(`div`,{className:`mb-3 flex items-center justify-between px-1`,children:(0,S.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,S.jsx)(`h2`,{className:`text-[15px] font-medium text-foreground`,children:`Custom Post Prompt`}),T(`Custom Post Prompt details`,`Appended after the built-in runtime post prompt.`),(0,S.jsxs)(h,{tone:`neutral`,className:`px-2 py-0.5`,children:[s.length,` chars`]})]})}),(0,S.jsx)(m,{as:`div`,padding:`none`,className:`relative flex min-h-0 flex-1 p-1`,children:(0,S.jsx)(l,{"aria-label":`Custom Post Prompt`,value:s,onChange:e=>c(e.target.value),placeholder:`Appended after the built-in runtime post prompt...`,className:C,mono:!0})})]})]})]})})}var T=(e,t)=>(0,S.jsx)(u,{delayDuration:150,children:(0,S.jsxs)(c,{children:[(0,S.jsx)(f,{asChild:!0,children:(0,S.jsx)(p,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":e,className:`rounded-full text-muted-foreground hover:bg-accent/35 hover:text-foreground`,children:(0,S.jsx)(r,{className:`size-3.5`})})}),(0,S.jsx)(s,{className:`max-w-xs`,children:t})]})});export{w as PromptsPage};
@@ -0,0 +1,3 @@
1
+ import{a as e}from"./rolldown-runtime-BYbx6iT9.js";import{d as t,l as n}from"./graph-vendor-DRq_-6fV.js";import{an as r,en as i,et as a,ft as o,gt as s,ot as c,q as l,vt as u,yt as d}from"./ui-vendor-C5pJa8N7.js";import{$ as f,C as p,O as m,S as h,X as g,Y as _,d as v,et as y,f as b,ft as x,k as S,l as C,nt as w,rt as T,st as E,ut as D}from"./index-C9HuekJm.js";import{a as O,i as k,o as A}from"./surface-pWwG5ogx.js";import{a as j,c as ee,n as M,r as te,t as N}from"./PageScaffold-f6g2l7XN.js";import{a as P,c as F,i as I,n as L,o as R,r as z,s as B,t as V}from"./alert-dialog-Duorp_S-.js";import{i as H,n as ne,r as U,t as re}from"./providerTypes-DT3Ahwl_.js";import{a as W,i as G,n as K,r as q,t as J}from"./select-DCfeNu-F.js";import{a as Y,i as ie,o as ae,r as oe,s as se,t as ce}from"./dialog-C3ixjGjN.js";import{t as le}from"./useAppRoute-FgSHBKhV.js";async function ue(){return _(`/api/providers`,{errorMessage:`Failed to fetch providers`,fallback:[],map:e=>e?.providers??[]})}async function de(e){return _(`/api/providers`,{method:`POST`,body:e,errorMessage:`Failed to create provider`})}async function fe(e,t){return _(`/api/providers/${e}`,{method:`PUT`,body:t,errorMessage:`Failed to update provider`})}async function pe(e){await g(`/api/providers/${e}`,{method:`DELETE`,errorMessage:`Failed to delete provider`})}async function me(e){return _(`/api/providers/models`,{method:`POST`,body:e,errorMessage:`Failed to fetch provider models`,fallback:[],map:e=>e?.models??[]})}async function he(e){return _(`/api/providers/models/test`,{method:`POST`,body:e,errorMessage:`Failed to test provider model`})}var X=n();function ge({clearModelsConfirmOpen:e,onCancelClearModels:t,onCancelDeleteProvider:n,onClearModels:r,onDeleteProvider:i,providerToDelete:a}){return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(V,{open:e,onOpenChange:e=>{e||t()},children:(0,X.jsxs)(I,{children:[(0,X.jsxs)(B,{children:[(0,X.jsx)(F,{children:`Clear all models?`}),(0,X.jsx)(P,{children:`This removes every model from this provider, including discovered and manual entries. Save the provider to keep the cleared list.`})]}),(0,X.jsxs)(R,{children:[(0,X.jsx)(z,{asChild:!0,children:(0,X.jsx)(D,{type:`button`,variant:`ghost`,children:`Cancel`})}),(0,X.jsx)(L,{asChild:!0,children:(0,X.jsx)(D,{type:`button`,variant:`destructive`,onClick:r,children:`Clear Models`})})]})]})}),(0,X.jsx)(V,{open:a!==null,onOpenChange:e=>{e||n()},children:(0,X.jsxs)(I,{children:[(0,X.jsxs)(B,{children:[(0,X.jsx)(F,{children:`Delete provider?`}),(0,X.jsx)(P,{children:a?`This will permanently remove ${a.name}.`:`This will permanently remove the selected provider.`})]}),(0,X.jsxs)(R,{children:[(0,X.jsx)(z,{asChild:!0,children:(0,X.jsx)(D,{variant:`ghost`,children:`Cancel`})}),(0,X.jsx)(L,{asChild:!0,children:(0,X.jsx)(D,{variant:`destructive`,onClick:i,children:`Delete`})})]})]})})]})}function _e(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ve(e){return!e||Object.keys(e).length===0?``:JSON.stringify(e,null,2)}function ye(e){if(!e.trim())return{headers:{},error:null};let t;try{t=JSON.parse(e)}catch{return{headers:{},error:`Headers must be valid JSON`}}if(!_e(t))return{headers:{},error:`Headers must be a JSON object`};let n={};for(let[e,r]of Object.entries(t)){if(typeof r!=`string`)return{headers:{},error:`Headers values must all be strings`};n[e]=r}return{headers:n,error:null}}function Z(e){return e?{name:e.name,type:e.type,base_url:e.base_url,api_key:e.api_key,headers_text:ve(e.headers),retry_429_delay_seconds:e.retry_429_delay_seconds,models:e.models.map(e=>({...e}))}:{name:``,type:`openai_compatible`,base_url:``,api_key:``,headers_text:``,retry_429_delay_seconds:0,models:[]}}function Q(e){return{model:e?.model??``,context_window_tokens:e?.context_window_tokens===null||e?.context_window_tokens===void 0?``:String(e.context_window_tokens),input_image:H(e?.input_image??null),output_image:H(e?.output_image??null),structured_output:H(e?.structured_output??null),source:e?.source??`manual`}}function be(e){return JSON.stringify({name:e.name,type:e.type,base_url:e.base_url,api_key:e.api_key,headers_text:e.headers_text,retry_429_delay_seconds:e.retry_429_delay_seconds,models:e.models})}function xe(e,t){return{name:e.name,type:e.type,base_url:e.base_url,api_key:e.api_key,headers:t,retry_429_delay_seconds:e.retry_429_delay_seconds,models:e.models}}function Se(e,t,n){return{provider_id:n,name:e.name,type:e.type,base_url:e.base_url,api_key:e.api_key,headers:t,retry_429_delay_seconds:e.retry_429_delay_seconds}}function Ce(e,t){let n=new Map(e.map(e=>[e.model,e])),r=new Map(t.map(e=>[e.model,e])),i=[];for(let t of e){let e=r.get(t.model);if(!e){i.push(t);continue}if(t.source===`manual`){i.push({...t,context_window_tokens:t.context_window_tokens??e.context_window_tokens,input_image:t.input_image??e.input_image,output_image:t.output_image??e.output_image,structured_output:t.structured_output??e.structured_output}),r.delete(t.model);continue}i.push(e),r.delete(t.model)}for(let e of t)n.has(e.model)||i.push(e);return i}function we(e){let t=[];return e.context_window_tokens!==null&&t.push(`${e.context_window_tokens.toLocaleString()} tokens`),e.input_image!==null&&t.push(e.input_image?`Image input`:`No image input`),e.output_image!==null&&t.push(e.output_image?`Image output`:`No image output`),e.structured_output!==null&&e.structured_output!==void 0&&t.push(e.structured_output?`Structured output`:`No structured output`),t.length>0?t.join(` · `):`No capability metadata`}function Te(e){let t=new Set;for(let n of e){let e=n.model.trim();if(t.has(e))return e;t.add(e)}return null}function Ee(e){let t=e.trim();if(!/^\d+$/.test(t))return null;let n=Number.parseInt(t,10);return Number.isSafeInteger(n)&&n>=0?n:null}function De(e){return e.model.trim()?e.context_window_tokens&&!/^\d+$/.test(e.context_window_tokens)?`Context Window must be a positive integer`:null:`Model ID is required`}function Oe(e){let t=U(e.structured_output??`auto`);return{model:e.model.trim(),source:e.source,context_window_tokens:e.context_window_tokens?Number.parseInt(e.context_window_tokens,10):null,input_image:U(e.input_image),output_image:U(e.output_image),...t===null?{}:{structured_output:t}}}function ke({draft:e,endpointPreview:t,onUpdateDraft:n,parsedHeaders:r}){return(0,X.jsxs)(N,{title:`Connection`,separated:!0,contentClassName:`rounded-lg border-dashed bg-card/30`,children:[(0,X.jsx)(j,{label:`Base URL`,children:(0,X.jsx)(y,{value:e.base_url,onChange:t=>n({...e,base_url:t.target.value}),placeholder:`https://api.openai.com/v1`})}),(0,X.jsx)(j,{label:`Request Preview`,children:(0,X.jsx)(`div`,{className:x(`w-full select-text rounded-md border px-3 py-2 text-[12px]`,t.error?`border-destructive/20 bg-destructive/8 text-destructive`:`border-border bg-card/30 text-foreground/80`),children:t.error?t.error:t.previewUrl?(0,X.jsx)(`code`,{className:`select-text font-mono`,children:t.previewUrl}):(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Enter a base URL to preview`})})}),(0,X.jsx)(j,{label:`Access Key`,children:(0,X.jsx)(T,{value:e.api_key,onChange:t=>n({...e,api_key:t.target.value}),placeholder:`sk-...`,mono:!0,showLabel:`Show access key`,hideLabel:`Hide access key`})}),(0,X.jsx)(j,{label:`Headers`,children:(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(w,{value:e.headers_text,onChange:t=>n({...e,headers_text:t.target.value}),placeholder:`{
2
+ "Authorization": "Bearer ..."
3
+ }`,spellCheck:!1,className:x(`min-h-[140px]`,r.error?`border-destructive/30 text-destructive focus-visible:border-destructive/50 focus-visible:ring-destructive/20`:``),mono:!0}),r.error?(0,X.jsx)(`p`,{className:`text-[11px] text-destructive`,children:r.error}):null]})}),(0,X.jsx)(j,{label:`429 Retry Delay`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(y,{"aria-label":`429 Retry Delay`,inputMode:`numeric`,pattern:`[0-9]*`,value:String(e.retry_429_delay_seconds),onChange:t=>{let r=Ee(t.target.value);r!==null&&n({...e,retry_429_delay_seconds:r})},mono:!0}),(0,X.jsx)(`span`,{className:`text-[13px] font-medium text-muted-foreground`,children:`s`})]})})]})}function Ae({draft:e,onUpdateDraft:t}){return(0,X.jsxs)(N,{title:`Identity`,className:`mb-10`,contentClassName:`rounded-lg border-dashed bg-card/30`,children:[(0,X.jsx)(j,{label:`Name`,children:(0,X.jsx)(y,{value:e.name,onChange:n=>t({...e,name:n.target.value}),placeholder:`e.g., OpenAI Production`})}),(0,X.jsx)(j,{label:`Type`,children:(0,X.jsxs)(J,{value:e.type,onValueChange:n=>t({...e,type:n}),children:[(0,X.jsx)(G,{className:E,children:(0,X.jsx)(W,{})}),(0,X.jsx)(K,{className:`rounded-xl border-border bg-popover`,children:ne.map(e=>(0,X.jsx)(q,{value:e.value,className:`text-[13px]`,children:e.label},e.value))})]})})]})}function je({fetchingModels:e,modelTestResults:t,models:n,onAddModel:r,onClearModels:i,onDeleteModel:c,onEditModel:l,onFetchModels:u,onTestModel:d}){return(0,X.jsx)(`div`,{className:`border-t border-border pt-8`,children:(0,X.jsxs)(N,{title:`Models`,contentClassName:`space-y-4 bg-card/30 p-5`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,X.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/80`,children:[n.length,` model`,n.length===1?``:`s`]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(D,{type:`button`,variant:`ghost`,size:`sm`,disabled:e,onClick:u,children:[(0,X.jsx)(o,{className:x(`size-3.5`,e&&`animate-spin`)}),`Fetch Models`]}),(0,X.jsxs)(D,{type:`button`,variant:`outline`,size:`sm`,onClick:r,children:[(0,X.jsx)(s,{className:`size-3.5`}),`Add Model`]}),(0,X.jsxs)(D,{type:`button`,variant:`ghost`,size:`sm`,disabled:n.length===0||e,onClick:i,children:[(0,X.jsx)(a,{className:`size-3.5`}),`Clear Models`]})]})]}),n.length===0?(0,X.jsxs)(O,{as:`div`,padding:`sm`,className:`border-dashed bg-background/35 py-5 text-center`,children:[(0,X.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/80`,children:`No models in this provider draft`}),(0,X.jsx)(`p`,{className:`mt-1 text-[11px] leading-relaxed text-muted-foreground`,children:`Fetch models or add a manual entry.`})]}):(0,X.jsx)(`div`,{className:`space-y-2`,children:n.map(e=>(0,X.jsx)(Me,{model:e,onDeleteModel:c,onEditModel:l,onTestModel:d,testResult:t[e.model]},e.model))})]})})}function Me({model:e,onDeleteModel:t,onEditModel:n,onTestModel:r,testResult:i}){return(0,X.jsx)(O,{as:`div`,padding:`sm`,className:`bg-background/35`,children:(0,X.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(`p`,{className:`truncate select-text font-mono text-[13px] text-foreground/85`,children:e.model}),(0,X.jsx)(A,{tone:e.source===`manual`?`idle`:`running`,className:`px-2 py-0.5`,children:e.source===`manual`?`Manual`:`Discovered`})]}),(0,X.jsx)(`p`,{className:`mt-1 select-text text-[11px] leading-relaxed text-muted-foreground`,children:we(e)}),(0,X.jsx)(Ne,{testResult:i})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[(0,X.jsxs)(D,{type:`button`,variant:`ghost`,size:`sm`,disabled:i?.state===`running`,onClick:()=>r(e),children:[(0,X.jsx)(u,{className:`size-3.5`}),`Test`]}),(0,X.jsxs)(D,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>n(e),children:[(0,X.jsx)(d,{className:`size-3.5`}),`Edit`]}),(0,X.jsxs)(D,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>t(e.model),children:[(0,X.jsx)(a,{className:`size-3.5`}),`Delete`]})]})]})})}function Ne({testResult:e}){return e?.state===`running`?(0,X.jsx)(`p`,{className:`mt-2 select-text text-[11px] text-muted-foreground`,children:`Testing this model against the current draft provider...`}):e?.state===`success`?(0,X.jsxs)(`p`,{className:`mt-2 select-text text-[11px] text-graph-status-running`,children:[`Test succeeded in `,e.duration_ms,`ms`]}):e?.state===`error`?(0,X.jsx)(`p`,{className:`mt-2 select-text text-[11px] text-destructive`,children:e.error_summary}):null}function Pe({draft:e,endpointPreview:t,fetchingModels:n,hasChanges:a,isCreating:o,modelTestResults:s,onAddModel:l,onCancelChanges:u,onClearModels:d,onDeleteModel:f,onEditModel:p,onFetchModels:m,onSaveProvider:h,onTestModel:g,onUpdateDraft:_,parsedHeaders:v,saving:y,selectedProvider:b}){return!o&&!b?(0,X.jsx)(r.div,{initial:{opacity:0},animate:{opacity:1},className:`flex h-full flex-col items-center justify-center px-6 text-center`,children:(0,X.jsx)(k,{icon:c,title:`No provider selected`,className:`border-transparent bg-transparent`})}):(0,X.jsxs)(`div`,{className:`flex min-h-full flex-col px-8 py-8 md:px-12 md:py-10`,children:[(0,X.jsxs)(`div`,{className:`mb-8 flex items-center justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{className:`text-xl font-medium text-foreground`,children:o?`New Provider`:b?.name}),o?null:(0,X.jsx)(`p`,{className:`mt-1 select-text font-mono text-[12px] text-muted-foreground`,children:b?.id})]}),a?(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(D,{type:`button`,variant:`ghost`,size:`sm`,onClick:u,disabled:y,children:`Cancel`}),(0,X.jsxs)(D,{type:`button`,size:`sm`,onClick:h,disabled:y,children:[(0,X.jsx)(i,{className:`size-3.5`}),y?`Saving...`:`Save Provider`]})]}):null]}),(0,X.jsxs)(`div`,{className:`mx-auto w-full max-w-[720px] flex-1`,children:[(0,X.jsx)(Ae,{draft:e,onUpdateDraft:_}),(0,X.jsx)(ke,{draft:e,endpointPreview:t,onUpdateDraft:_,parsedHeaders:v}),(0,X.jsx)(je,{fetchingModels:n,modelTestResults:s,models:e.models,onAddModel:l,onClearModels:d,onDeleteModel:f,onEditModel:p,onFetchModels:m,onTestModel:g}),!o&&b?(0,X.jsx)(`div`,{className:`border-t border-border pt-8`,children:(0,X.jsx)(N,{title:`Provider`,contentClassName:`rounded-lg border-dashed bg-card/30`,children:(0,X.jsx)(j,{label:`Provider ID`,children:(0,X.jsx)(`div`,{className:`select-text rounded-md border border-border bg-card/30 px-3 py-2 font-mono text-[12px] text-foreground/80`,children:b.id})})})}):null]})]})}function Fe({draft:e,onClose:t,onDraftChange:n,onSave:r,state:i}){return(0,X.jsx)(ce,{open:i!==null,onOpenChange:e=>{e||t()},children:(0,X.jsxs)(oe,{children:[(0,X.jsxs)(ae,{children:[(0,X.jsx)(se,{children:i?.mode===`edit`?`Edit Model`:`Add Model`}),(0,X.jsx)(ie,{className:`sr-only`,children:i?.mode===`edit`?`Edit Model`:`Add Model`})]}),(0,X.jsxs)(`div`,{className:`space-y-4 px-5 py-4`,children:[(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/80`,children:`Model ID`}),(0,X.jsx)(y,{"aria-label":`Model ID`,value:e.model,onChange:t=>n({...e,model:t.target.value}),placeholder:`gpt-5`,mono:!0})]}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/80`,children:`Source`}),(0,X.jsx)(`div`,{className:`rounded-md border border-border bg-card/30 px-3 py-2 text-[13px] text-foreground/80`,children:e.source===`manual`?`Manual`:`Discovered`})]}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/80`,children:`Context Window`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(y,{"aria-label":`Context Window`,inputMode:`numeric`,pattern:`[0-9]*`,value:e.context_window_tokens,onChange:t=>{let r=t.target.value.trim();/^\d*$/.test(r)&&n({...e,context_window_tokens:r})},placeholder:`Optional`,mono:!0}),(0,X.jsx)(`span`,{className:`text-[13px] font-medium text-muted-foreground`,children:`tokens`})]})]}),(0,X.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-3`,children:[(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/80`,children:`Input Image`}),(0,X.jsxs)(J,{value:e.input_image,onValueChange:t=>n({...e,input_image:t}),children:[(0,X.jsx)(G,{className:E,children:(0,X.jsx)(W,{})}),(0,X.jsxs)(K,{className:`rounded-xl border-border bg-popover`,children:[(0,X.jsx)(q,{value:`auto`,children:`Auto`}),(0,X.jsx)(q,{value:`enabled`,children:`Enabled`}),(0,X.jsx)(q,{value:`disabled`,children:`Disabled`})]})]})]}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/80`,children:`Output Image`}),(0,X.jsxs)(J,{value:e.output_image,onValueChange:t=>n({...e,output_image:t}),children:[(0,X.jsx)(G,{className:E,children:(0,X.jsx)(W,{})}),(0,X.jsxs)(K,{className:`rounded-xl border-border bg-popover`,children:[(0,X.jsx)(q,{value:`auto`,children:`Auto`}),(0,X.jsx)(q,{value:`enabled`,children:`Enabled`}),(0,X.jsx)(q,{value:`disabled`,children:`Disabled`})]})]})]}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/80`,children:`Structured Output`}),(0,X.jsxs)(J,{value:e.structured_output??`auto`,onValueChange:t=>n({...e,structured_output:t}),children:[(0,X.jsx)(G,{className:E,children:(0,X.jsx)(W,{})}),(0,X.jsxs)(K,{className:`rounded-xl border-border bg-popover`,children:[(0,X.jsx)(q,{value:`auto`,children:`Auto`}),(0,X.jsx)(q,{value:`enabled`,children:`Enabled`}),(0,X.jsx)(q,{value:`disabled`,children:`Disabled`})]})]})]})]})]}),(0,X.jsxs)(Y,{className:`px-5 pb-5`,children:[(0,X.jsx)(D,{variant:`ghost`,onClick:t,children:`Cancel`}),(0,X.jsx)(D,{onClick:r,children:i?.mode===`edit`?`Save Model`:`Add Model`})]})]})})}function Ie({isDragging:e,loading:t,onCreate:n,onDelete:i,onRefresh:l,onResizeStart:u,onSelect:d,panelWidth:p,providers:m,selectedId:h}){return(0,X.jsxs)(`div`,{style:{width:`${p}px`},className:`relative flex shrink-0 flex-col border-r border-border bg-card/20 pt-8 pl-8`,children:[(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between px-5 py-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(c,{className:`size-4 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-[13px] font-medium text-foreground/80`,children:`Providers`})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(f,{onClick:l,disabled:t,className:`size-7`,children:(0,X.jsx)(o,{className:x(`size-3.5`,t&&`animate-spin`)})}),(0,X.jsx)(f,{onClick:n,className:`size-7`,children:(0,X.jsx)(s,{className:`size-3.5`})})]})]}),(0,X.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-3 pb-4`,children:t?(0,X.jsx)(`div`,{className:`space-y-1`,children:[...[,,,]].map((e,t)=>(0,X.jsx)(`div`,{className:`h-10 w-full animate-pulse rounded-lg bg-accent/20`},t))}):m.length===0?(0,X.jsxs)(r.div,{initial:{opacity:0},animate:{opacity:1},className:`py-10 text-center`,children:[(0,X.jsx)(`p`,{className:`text-[13px] text-muted-foreground`,children:`No providers`}),(0,X.jsxs)(D,{type:`button`,size:`sm`,onClick:n,className:`mt-4`,children:[(0,X.jsx)(s,{className:`size-3`}),`Add your first provider`]})]}):(0,X.jsx)(`div`,{className:`space-y-0.5`,children:m.map((e,t)=>(0,X.jsxs)(r.div,{initial:{opacity:0,x:-4},animate:{opacity:1,x:0},transition:{delay:t*.03},className:x(`group relative flex w-full items-center justify-between rounded-lg transition-all`,h===e.id?`bg-accent/55 text-foreground`:`text-muted-foreground hover:bg-accent/30 hover:text-foreground`),children:[(0,X.jsx)(`div`,{className:x(`absolute inset-y-1 left-0 w-px rounded-full bg-ring/60 transition-opacity`,h===e.id?`opacity-100`:`opacity-0`)}),(0,X.jsx)(D,{type:`button`,variant:`ghost`,onClick:()=>d(e),className:`h-auto min-w-0 flex-1 justify-start rounded-lg bg-transparent px-3 py-2.5 text-left text-inherit shadow-none hover:bg-transparent hover:text-inherit focus-visible:ring-2 focus-visible:ring-ring/50`,children:(0,X.jsxs)(`span`,{className:`min-w-0 flex-1 pl-2`,children:[(0,X.jsx)(`span`,{className:`block truncate text-[13px] font-medium`,children:e.name}),(0,X.jsx)(`span`,{className:`block truncate text-[11px] text-muted-foreground`,children:re(e.type)})]})}),(0,X.jsx)(f,{onClick:()=>{i(e)},className:`mr-2 size-6 shrink-0 border-transparent bg-transparent opacity-0 transition-opacity hover:bg-destructive/10 hover:text-destructive group-hover:opacity-100`,children:(0,X.jsx)(a,{className:`size-3`})})]},e.id))})}),(0,X.jsx)(C,{position:`right`,isDragging:e,onMouseDown:u})]})}var $=e(t(),1),Le={openai_compatible:`/v1`,openai_responses:`/v1`,anthropic:`/v1`,gemini:`/v1beta`},Re={openai_compatible:`/chat/completions`,openai_responses:`/responses`,anthropic:`/messages`,gemini:`/models/{model}:streamGenerateContent`},ze=Array.from(new Set(Object.values(Le))).sort((e,t)=>t.length-e.length);function Be(e){return e.trim().toLowerCase()}function Ve(e){return e.trim().replace(/\/+$/,``)}function He(e,t){let n=Be(e),r=Le[n],i=Ve(t);if(!r||!i)return{resolvedBaseUrl:null,error:null};let a=i.toLowerCase();for(let e of ze)if(a.endsWith(e))return e===r?{resolvedBaseUrl:i,error:null}:{resolvedBaseUrl:null,error:`Base URL suffix '${e}' does not match type '${n}' (expected '${r}')`};return{resolvedBaseUrl:`${i}${r}`,error:null}}function Ue(e,t){let n=Be(e),r=Re[n],{resolvedBaseUrl:i,error:a}=He(n,t);return a?{previewUrl:null,error:a}:!i||!r?{previewUrl:null,error:null}:{previewUrl:`${i}${r}`,error:null}}function We(){let e=le(),[t,n]=(0,$.useState)(e.providerId),[r,i]=(0,$.useState)(e.providerMode===`create`),[a,o]=(0,$.useState)(()=>Z()),[s,c]=(0,$.useState)(!1),[u,d]=(0,$.useState)(null),[f,g]=(0,$.useState)(!1),[_,y]=(0,$.useState)(!1),[x,C]=(0,$.useState)(null),[w,T]=(0,$.useState)(Q()),[E,D]=(0,$.useState)({}),O=(0,$.useRef)(null),{data:k=[],isLoading:A,mutate:j}=ee(`providers`,ue,{onSuccess:e=>{!t||e.find(e=>e.id===t)||(n(null),i(!1),o(Z()),D({}),g(!1))}}),[M,te]=b(`providers-panel-width`,300,200,500),{isDragging:N,startDrag:P}=v(M,te,`right`),F=(0,$.useMemo)(()=>k.find(e=>e.id===t),[k,t]);(0,$.useEffect)(()=>{if(e.page!==`providers`)return;let t=e.providerMode===`create`?`create`:e.providerId?`detail:${e.providerId}`:`list`;if(O.current!==t){if(e.providerMode===`create`){O.current=t,i(!0),n(null),o(Z()),D({}),C(null),g(!1);return}if(e.providerId){let r=k.find(t=>t.id===e.providerId);if(!r){A||(O.current=`list`,n(null),i(!1),o(Z()),D({}),C(null),g(!1),S(h(null)));return}O.current=t,n(r.id),i(!1),o(Z(r)),D({}),C(null),g(!1);return}O.current=t,n(null),i(!1),o(Z()),D({}),C(null),g(!1)}},[A,k,e.page,e.providerId,e.providerMode]);let I=(0,$.useMemo)(()=>Ue(a.type,a.base_url),[a.base_url,a.type]),L=(0,$.useMemo)(()=>ye(a.headers_text),[a.headers_text]),R=(0,$.useMemo)(()=>{let e=r?Z():Z(F);return be(a)!==be(e)},[a,r,F]),z=(0,$.useCallback)(e=>{o(e)},[]),B=(0,$.useCallback)(e=>{T(e)},[]),V=(0,$.useCallback)(e=>{d(e)},[]),H=(0,$.useCallback)(()=>{d(null)},[]),ne=(0,$.useCallback)(async()=>{await j()},[j]),U=(0,$.useCallback)(e=>{O.current=`detail:${e.id}`,n(e.id),i(!1),o(Z(e)),D({}),C(null),g(!1),m(h(e.id))},[]),re=(0,$.useCallback)(()=>{O.current=`create`,i(!0),n(null),o(Z()),D({}),C(null),g(!1),m(p())},[]),W=(0,$.useCallback)(()=>{r?(O.current=`list`,i(!1),o(Z()),m(h(null))):o(Z(F)),D({}),C(null),g(!1)},[r,F]),G=(0,$.useCallback)(async()=>{if(!a.name.trim()){l.error(`Provider name is required`);return}if(!a.base_url.trim()){l.error(`Provider base URL is required`);return}if(I.error){l.error(I.error);return}if(L.error){l.error(L.error);return}let e=Te(a.models);if(e){l.error(`Model ID '${e}' is duplicated`);return}let s=xe(a,L.headers);c(!0);try{if(r){let e=await de(s);j([...k,e],!1),O.current=`detail:${e.id}`,i(!1),n(e.id),o(Z(e)),S(h(e.id)),l.success(`Provider created`)}else if(t){let e=await fe(t,s);j(k.map(n=>n.id===t?e:n),!1),o(Z(e)),l.success(`Provider updated`)}D({}),g(!1)}catch{l.error(r?`Failed to create provider`:`Failed to update provider`)}finally{c(!1)}},[a,I.error,r,j,L.error,L.headers,k,t]),K=(0,$.useCallback)(async()=>{if(!u)return;let e=u.id;d(null),g(!1);try{await pe(e),j(k.filter(t=>t.id!==e),!1),t===e&&(O.current=`list`,n(null),o(Z()),S(h(null))),D({}),l.success(`Provider deleted`)}catch{l.error(`Failed to delete provider`)}},[j,u,k,t]),q=(0,$.useCallback)(()=>{C({mode:`create`,originalModel:null}),T(Q())},[]),J=(0,$.useCallback)(e=>{C({mode:`edit`,originalModel:e.model}),T(Q(e))},[]),Y=(0,$.useCallback)(()=>{C(null),T(Q())},[]),ie=(0,$.useCallback)(()=>{let e=De(w);if(e){l.error(e);return}let t=w.model.trim();if(a.models.some(e=>e.model===t&&e.model!==x?.originalModel)){l.error(`Model ID '${t}' already exists in this provider`);return}let n=Oe(w);o(e=>x?.mode===`edit`&&x.originalModel?{...e,models:e.models.map(e=>e.model===x.originalModel?n:e)}:{...e,models:[...e.models,n]}),D(e=>{let n={...e};return x?.originalModel&&x.originalModel!==t&&delete n[x.originalModel],n}),Y()},[Y,a.models,w,x]),ae=(0,$.useCallback)(e=>{o(t=>({...t,models:t.models.filter(t=>t.model!==e)})),D(t=>{let n={...t};return delete n[e],n})},[]),oe=(0,$.useCallback)(()=>{a.models.length!==0&&g(!0)},[a.models.length]);return{cancelClearModels:(0,$.useCallback)(()=>{g(!1)},[]),clearModelsConfirmOpen:f,draft:a,endpointPreview:I,fetchingModels:_,handleCancel:W,handleClearModels:(0,$.useCallback)(()=>{o(e=>({...e,models:[]})),D({}),g(!1)},[]),handleCreateNew:re,handleDelete:K,handleDeleteModel:ae,handleFetchModels:(0,$.useCallback)(async()=>{if(!a.type.trim()||!a.base_url.trim()){l.error(`Provider type and base URL are required before fetching models`);return}if(I.error){l.error(I.error);return}if(L.error){l.error(L.error);return}y(!0);try{let e=await me(Se(a,L.headers,t??void 0));o(t=>({...t,models:Ce(t.models,e)})),l.success(`Provider models fetched`)}catch(e){l.error(e instanceof Error?e.message:`Failed to fetch provider models`)}finally{y(!1)}},[a,I.error,L.error,L.headers,t]),handleSave:G,handleSaveModel:ie,handleSelect:U,handleTestModel:(0,$.useCallback)(async e=>{if(I.error){l.error(I.error);return}if(L.error){l.error(L.error);return}D(t=>({...t,[e.model]:{state:`running`}}));try{let n=await he({...Se(a,L.headers,t??void 0),model:e.model});D(t=>({...t,[e.model]:n.ok?{state:`success`,duration_ms:n.duration_ms??0}:{state:`error`,error_summary:n.error_summary??`Provider test failed`}}))}catch(t){D(n=>({...n,[e.model]:{state:`error`,error_summary:t instanceof Error?t.message:`Provider test failed`}}))}},[a,I.error,L.error,L.headers,t]),hasChanges:R,isCreating:r,isDragging:N,loading:A,modelEditorDraft:w,modelEditorState:x,modelTestResults:E,openCreateModelDialog:q,openEditModelDialog:J,panelWidth:M,parsedHeaders:L,providerToDelete:u,providers:k,refreshProviders:ne,requestClearModels:oe,saving:s,selectedId:t,selectedProvider:F,updateProviderDraft:z,updateProviderModelDraft:B,requestDeleteProvider:V,cancelDeleteProvider:H,startDrag:P,closeModelDialog:Y}}function Ge(){let{cancelClearModels:e,cancelDeleteProvider:t,clearModelsConfirmOpen:n,draft:r,endpointPreview:i,fetchingModels:a,handleCancel:o,handleClearModels:s,handleCreateNew:c,handleDelete:l,handleDeleteModel:u,handleFetchModels:d,handleSave:f,handleSaveModel:p,handleSelect:m,handleTestModel:h,hasChanges:g,isCreating:_,isDragging:v,loading:y,modelEditorDraft:b,modelEditorState:x,modelTestResults:S,openCreateModelDialog:C,openEditModelDialog:w,panelWidth:T,parsedHeaders:E,providerToDelete:D,providers:k,refreshProviders:A,requestClearModels:j,requestDeleteProvider:ee,saving:N,selectedId:P,selectedProvider:F,updateProviderDraft:I,updateProviderModelDraft:L,startDrag:R,closeModelDialog:z}=We();return(0,X.jsx)(M,{className:`overflow-hidden px-4 pt-6 sm:px-5`,children:(0,X.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,X.jsx)(te,{title:`Providers`}),(0,X.jsxs)(O,{as:`div`,padding:`none`,className:`mt-6 flex min-h-0 flex-1 overflow-hidden border-border/60 bg-card/[0.14]`,children:[(0,X.jsx)(Ie,{isDragging:v,loading:y,onCreate:c,onDelete:ee,onRefresh:()=>{A()},onResizeStart:R,onSelect:m,panelWidth:T,providers:k,selectedId:P}),(0,X.jsx)(`div`,{className:`min-w-0 flex-1 overflow-y-auto bg-transparent`,children:(0,X.jsx)(Pe,{draft:r,endpointPreview:i,fetchingModels:a,hasChanges:g,isCreating:_,modelTestResults:S,onAddModel:C,onCancelChanges:o,onClearModels:j,onDeleteModel:u,onEditModel:w,onFetchModels:()=>{d()},onSaveProvider:()=>{f()},onTestModel:e=>{h(e)},onUpdateDraft:I,parsedHeaders:E,saving:N,selectedProvider:F})})]}),(0,X.jsx)(Fe,{draft:b,onClose:z,onDraftChange:L,onSave:p,state:x}),(0,X.jsx)(ge,{clearModelsConfirmOpen:n,onCancelClearModels:e,onCancelDeleteProvider:t,onClearModels:s,onDeleteProvider:()=>{l()},providerToDelete:D})]})})}export{Ge as ProvidersPage};
@@ -0,0 +1 @@
1
+ import{a as e}from"./rolldown-runtime-BYbx6iT9.js";import{d as t,l as n}from"./graph-vendor-DRq_-6fV.js";import{Ft as r,Gt as i,J as a,X as o,an as s,bt as c,et as l,ft as u,gt as d,q as f}from"./ui-vendor-C5pJa8N7.js";import{a as p,i as m,n as h,t as g}from"./roles-CuRT_chR.js";import{$ as _,O as v,T as y,a as b,et as x,ft as S,i as C,k as w,nt as T,o as ee,ot as E,r as D,s as O,st as k,ut as A,w as j,x as M,y as N}from"./index-C9HuekJm.js";import{a as P,i as te,o as F}from"./surface-pWwG5ogx.js";import{a as I,c as ne,n as re,r as ie,t as L}from"./PageScaffold-f6g2l7XN.js";import{a as ae,c as oe,i as R,n as z,o as B,r as V,s as H,t as U}from"./alert-dialog-Duorp_S-.js";import{a as W,i as G,n as K,r as q,t as J}from"./select-DCfeNu-F.js";import{t as se}from"./useAppRoute-FgSHBKhV.js";import{i as ce,n as le,r as ue,t as Y}from"./modelParams-DmnF2hwR.js";var X=n();function de({onConfirmDelete:e,onOpenChange:t,roleToDelete:n}){return(0,X.jsx)(U,{open:n!==null,onOpenChange:t,children:(0,X.jsxs)(R,{children:[(0,X.jsxs)(H,{children:[(0,X.jsx)(oe,{children:`Delete role?`}),(0,X.jsx)(ae,{children:n?`This will permanently remove ${n.name}.`:`This will permanently remove the selected role.`})]}),(0,X.jsxs)(B,{children:[(0,X.jsx)(V,{asChild:!0,children:(0,X.jsx)(A,{variant:`ghost`,children:`Cancel`})}),(0,X.jsx)(z,{asChild:!0,children:(0,X.jsx)(A,{variant:`destructive`,onClick:()=>void e(),children:`Delete`})})]})]})})}function fe({activeRole:e,draft:t,isReadOnly:n,onUpdateDraft:r,shouldLockIdentityFields:i}){let a=n||i;return(0,X.jsxs)(L,{title:`Identity`,className:`mb-10`,contentClassName:`rounded-lg border-dashed bg-card/30`,children:[(0,X.jsx)(I,{label:`Role Name`,children:(0,X.jsx)(x,{value:t.name,onChange:e=>r(t=>({...t,name:e.target.value})),readOnly:a,placeholder:`e.g., Code Reviewer`,className:S(a?E:``)})}),(0,X.jsx)(I,{label:`Description`,children:(0,X.jsx)(T,{value:t.description,onChange:e=>r(t=>({...t,description:e.target.value})),readOnly:a,placeholder:`Briefly explain what this role is best suited for`,rows:3,className:S(`resize-y`,a?E:``)})}),(0,X.jsx)(I,{label:`System Prompt`,children:(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(T,{value:t.system_prompt,onChange:e=>r(t=>({...t,system_prompt:e.target.value})),readOnly:a,placeholder:`You are a helpful assistant that...`,rows:12,className:S(`resize-y`,a?E:``),mono:!0}),a?(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:e?.is_builtin||i?`Built-in role fields are locked.`:`View only.`}):null]})})]})}function pe({disabled:e,isDefaultSelected:t,onSelectDefault:n,onSelectOverride:r,overrideLabel:i}){return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(A,{type:`button`,variant:`ghost`,size:`sm`,disabled:e,onClick:n,className:S(`h-8 rounded-md border px-3 text-[13px] font-medium transition-colors`,t?`border-border bg-accent/45 text-foreground`:`border-transparent bg-card/20 text-muted-foreground hover:bg-accent/25`,e&&`cursor-default`),children:`Use Settings Default`}),(0,X.jsx)(A,{type:`button`,variant:`ghost`,size:`sm`,disabled:e,onClick:r,className:S(`h-8 rounded-md border px-3 text-[13px] font-medium transition-colors`,t?`border-transparent bg-card/20 text-muted-foreground hover:bg-accent/25`:`border-border bg-accent/45 text-foreground`,e&&`cursor-default`),children:i}),t?(0,X.jsx)(F,{tone:`muted`,children:`Settings default`}):null]})}function me({draft:e,isReadOnly:t,onModelParamsModeChange:n,onUpdateDraft:r}){let i=!le(e.model_params);return(0,X.jsx)(L,{title:`Model Parameters`,className:`mb-10`,separated:!0,contentClassName:`border-transparent bg-transparent p-0 shadow-none`,children:(0,X.jsxs)(`div`,{className:`space-y-6`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,X.jsx)(pe,{disabled:t,isDefaultSelected:!i,onSelectDefault:()=>n(!1),onSelectOverride:()=>n(!0),overrideLabel:`Set Parameter Overrides`}),i?null:(0,X.jsx)(he,{})]}),i?(0,X.jsx)(P,{children:(0,X.jsx)(ce,{value:Y(e.model_params),onChange:e=>r(t=>({...t,model_params:e})),disabled:t,emptyLabel:`Inherit settings default`,numberPlaceholder:`Inherit settings default`,reasoningDisableLabel:`Disable`})}):(0,X.jsx)(F,{tone:`muted`,children:`Settings default`})]})})}function he(){return(0,X.jsx)(ee,{delayDuration:150,children:(0,X.jsxs)(C,{children:[(0,X.jsx)(O,{asChild:!0,children:(0,X.jsx)(A,{type:`button`,variant:`ghost`,size:`icon-xs`,className:`rounded-full text-muted-foreground hover:bg-accent/35 hover:text-foreground`,"aria-label":`Parameter override details`,children:(0,X.jsx)(r,{className:`size-3.5`})})}),(0,X.jsx)(b,{className:`max-w-xs`,children:`Overrides affect this role only. Unsupported fields may be ignored.`})]})})}function ge({availableProviderModels:e,draft:t,isReadOnly:n,onModelModeChange:r,onOpenProvidersPage:i,onProviderChange:a,onUpdateDraft:o,providers:s}){return(0,X.jsx)(L,{title:`Model Configuration`,className:`mb-10`,separated:!0,contentClassName:`border-transparent bg-transparent p-0 shadow-none`,children:(0,X.jsxs)(`div`,{className:`space-y-6`,children:[(0,X.jsx)(pe,{disabled:n,isDefaultSelected:t.model===null,onSelectDefault:()=>r(!1),onSelectOverride:()=>r(!0),overrideLabel:`Set Role Override`}),t.model?(0,X.jsx)(P,{children:(0,X.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-2`,children:[(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/80`,children:`Provider`}),(0,X.jsxs)(J,{value:t.model.provider_id||void 0,onValueChange:a,disabled:n,children:[(0,X.jsx)(G,{className:k,children:(0,X.jsx)(W,{placeholder:`Select a provider`})}),(0,X.jsx)(K,{className:`rounded-xl border-border bg-popover`,children:s.map(e=>(0,X.jsx)(q,{value:e.id,className:`text-[13px]`,children:e.name},e.id))})]})]}),(0,X.jsx)(_e,{availableProviderModels:e,draft:t,isReadOnly:n,onOpenProvidersPage:i,onUpdateDraft:o}),(0,X.jsxs)(`div`,{className:`space-y-2 md:col-span-2`,children:[(0,X.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/80`,children:`Model ID`}),(0,X.jsx)(x,{value:t.model.model,onChange:e=>o(t=>({...t,model:t.model?{...t.model,model:e.target.value}:null})),readOnly:n,placeholder:`e.g., gpt-4o-mini`,className:S(n?E:``),mono:!0}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Catalog or manual ID`})]})]})}):(0,X.jsx)(F,{tone:`muted`,children:`Settings default`})]})})}function _e({availableProviderModels:e,draft:t,isReadOnly:n,onOpenProvidersPage:r,onUpdateDraft:i}){let a=e.some(e=>e.model===t.model?.model)?t.model?.model:void 0;return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/80`,children:`Provider Models`}),(0,X.jsxs)(J,{value:a,onValueChange:e=>i(t=>({...t,model:t.model?{...t.model,model:e}:null})),disabled:n||!t.model?.provider_id||e.length===0,children:[(0,X.jsx)(G,{className:k,children:(0,X.jsx)(W,{placeholder:e.length>0?`Pick a provider model`:`No saved provider models`})}),(0,X.jsx)(K,{className:`max-h-[300px] rounded-xl border-border bg-popover`,children:e.map(e=>(0,X.jsx)(q,{value:e.model,className:`text-[13px]`,children:e.model},e.model))})]}),e.length===0?(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px] text-muted-foreground`,children:[(0,X.jsx)(`span`,{children:`No saved provider models.`}),(0,X.jsx)(A,{type:`button`,variant:`outline`,size:`xs`,onClick:r,children:`Open Providers`})]}):null]})}function ve({configurableTools:e,getToolState:t,isReadOnly:n,onToolStateCycle:r,shouldLockIdentityFields:i}){return(0,X.jsx)(L,{title:`Tool Configuration`,className:`mb-10`,separated:!0,contentClassName:`bg-card/30`,children:e.map(e=>(0,X.jsx)(ye,{isDisabled:n||i,onToolStateCycle:r,state:t(e.name),tool:e},e.name))})}function ye({isDisabled:e,onToolStateCycle:t,state:n,tool:r}){return(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-4 border-b border-border px-5 py-4 last:border-b-0`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,title:r.description,children:[(0,X.jsx)(`p`,{className:`font-mono text-[13px] text-foreground/80`,children:r.name}),(0,X.jsx)(`p`,{className:`mt-1 truncate text-[12px] text-muted-foreground`,children:r.description})]}),(0,X.jsx)(A,{type:`button`,variant:`ghost`,size:`xs`,onClick:()=>t(r.name),disabled:e,className:S(`shrink-0 rounded-full px-3 py-1 text-xs font-medium transition-colors`,n===`included`&&`bg-accent/50 text-foreground`,n===`excluded`&&`bg-transparent text-muted-foreground line-through`,n===`allowed`&&`bg-accent/20 text-muted-foreground hover:bg-accent/35`,e&&`cursor-default hover:bg-inherit opacity-60`),children:n===`allowed`?`Allowed`:n===`included`?`Included`:`Excluded`})]})}function be({activeRole:e,availableProviderModels:t,canSave:n,configurableTools:r,draft:i,getToolState:a,isReadOnly:o,onClosePanel:s,onEditRole:c,onModelModeChange:l,onModelParamsModeChange:u,onOpenProvidersPage:d,onProviderChange:f,onSaveRole:p,onToolStateCycle:m,onUpdateDraft:h,panelBadgeLabel:g,panelMode:_,panelTitle:v,providers:y,saving:b,shouldLockIdentityFields:x}){return(0,X.jsx)(`div`,{className:`h-full min-h-0 overflow-y-auto pr-2 scrollbar-none`,children:(0,X.jsxs)(`div`,{className:`mx-auto max-w-3xl pb-10`,children:[(0,X.jsx)(xe,{badgeLabel:g,onClosePanel:s,title:v}),(0,X.jsx)(fe,{activeRole:e,draft:i,isReadOnly:o,onUpdateDraft:h,shouldLockIdentityFields:x}),(0,X.jsx)(ge,{availableProviderModels:t,draft:i,isReadOnly:o,onModelModeChange:l,onOpenProvidersPage:d,onProviderChange:f,onUpdateDraft:h,providers:y}),(0,X.jsx)(me,{draft:i,isReadOnly:o,onModelParamsModeChange:u,onUpdateDraft:h}),(0,X.jsx)(ve,{configurableTools:r,getToolState:a,isReadOnly:o,onToolStateCycle:m,shouldLockIdentityFields:x}),(0,X.jsx)(Se,{activeRole:e,canSave:n,isReadOnly:o,onClosePanel:s,onEditRole:c,onSaveRole:p,panelMode:_,saving:b})]})})}function xe({badgeLabel:e,onClosePanel:t,title:n}){return(0,X.jsxs)(P,{as:`div`,padding:`sm`,className:`mb-8 flex items-center justify-between px-5 py-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(F,{tone:`neutral`,className:`py-0.5 text-[11px]`,children:e}),(0,X.jsx)(`h2`,{className:`text-[15px] font-medium text-foreground`,children:n})]}),(0,X.jsx)(A,{type:`button`,variant:`ghost`,size:`icon-xs`,onClick:t,className:`text-muted-foreground hover:bg-accent/45 hover:text-foreground`,children:(0,X.jsx)(a,{className:`size-3.5`})})]})}function Se({activeRole:e,canSave:t,isReadOnly:n,onClosePanel:r,onEditRole:i,onSaveRole:a,panelMode:o,saving:s}){return(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-3 border-t border-border pt-6`,children:[(0,X.jsx)(A,{type:`button`,variant:`ghost`,size:`sm`,onClick:r,disabled:s,children:`Cancel`}),n?null:(0,X.jsx)(A,{type:`button`,size:`sm`,onClick:()=>void a(),disabled:!t,children:s?`Saving...`:o===`create`?`Create Role`:`Save Changes`}),n&&e&&!e.is_builtin?(0,X.jsx)(A,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>i(e),children:`Edit Role`}):null]})}var Ce=new Set([`idle`,`sleep`,`todo`,`contacts`]);function Z(){return{name:``,description:``,system_prompt:``,model:null,model_params:null,included_tools:[],excluded_tools:[]}}function Q(e){return e?{name:e.name,description:e.description,system_prompt:e.system_prompt,model:e.model?{provider_id:e.model.provider_id,model:e.model.model}:null,model_params:e.model_params?Y(e.model_params):null,included_tools:[...e.included_tools],excluded_tools:[...e.excluded_tools]}:Z()}function we(e){return e.filter(e=>!Ce.has(e.name))}function Te(e){return Object.fromEntries(e.map(e=>[e.id,e]))}function Ee(e,t){return e.included_tools.includes(t)?`included`:e.excluded_tools.includes(t)?`excluded`:`allowed`}function De(e,t){let n=Ee(e,t);return n===`allowed`?{...e,included_tools:[...e.included_tools,t],excluded_tools:e.excluded_tools.filter(e=>e!==t)}:n===`included`?{...e,included_tools:e.included_tools.filter(e=>e!==t),excluded_tools:[...e.excluded_tools,t]}:{...e,included_tools:e.included_tools.filter(e=>e!==t),excluded_tools:e.excluded_tools.filter(e=>e!==t)}}function Oe(e){return e.length===0?null:{provider_id:e[0]?.id??``,model:``}}function ke(e){let{activeRoleName:t,draft:n,roles:r}=e,i=n.name.trim();if(!i)return`Role name is required`;if(!n.description.trim())return`Role description is required`;if(!n.system_prompt.trim())return`System prompt is required`;if(n.model){if(!n.model.provider_id.trim())return`Provider is required for a role model override`;if(!n.model.model.trim())return`Model is required for a role model override`}return r.some(e=>e.name===i&&e.name!==t)?`Role name already exists`:null}function Ae(e){return{name:e.name.trim(),description:e.description.trim(),system_prompt:e.system_prompt,model:e.model?{provider_id:e.model.provider_id.trim(),model:e.model.model.trim()}:null,model_params:ue(e.model_params),included_tools:e.included_tools,excluded_tools:e.excluded_tools}}function je(e){return e===`view`}function Me(e,t){return e!==`create`&&e!==null&&t?.is_builtin===!0}function Ne(e,t){return e===`create`?`New Role`:t?.is_builtin?`Built-in`:`Custom`}function Pe(e,t){return e===`create`?`Create Role`:t?.is_builtin?`Role Details`:t?.name??`Role Details`}function Fe(e,t){return!(t||!e.name.trim()||!e.description.trim()||!e.system_prompt.trim())}function Ie(e,t){return e.model?`${t[e.model.provider_id]?.name??e.model.provider_id} / ${e.model.model}`:`Settings default`}function Le(e){let t=e.included_tools.length,n=e.excluded_tools.length;return t===0&&n===0?`Default`:[t>0?`+${t}`:null,n>0?`-${n}`:null].filter(Boolean).join(` `)}function Re({activeRole:e,onCreateRole:t,onDeleteRole:n,onEditRole:r,onViewRole:i,providersById:a,roles:c}){return c.length===0?(0,X.jsx)(s.div,{initial:{opacity:0},animate:{opacity:1},className:`flex h-full flex-col items-center justify-center text-center`,children:(0,X.jsx)(te,{icon:o,title:`No roles yet`,action:(0,X.jsxs)(A,{type:`button`,size:`sm`,onClick:t,children:[(0,X.jsx)(d,{className:`size-4`}),`New Role`]}),className:`border-transparent bg-transparent`})}):(0,X.jsx)(`div`,{className:`h-full min-h-0 overflow-y-auto pr-2 scrollbar-none`,children:(0,X.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl`,children:[(0,X.jsxs)(`div`,{className:`mb-2 grid grid-cols-[260px_1fr_120px_100px] gap-4 px-4 pb-3`,children:[(0,X.jsx)(`span`,{className:`text-[11px] font-medium text-muted-foreground`,children:`Name`}),(0,X.jsx)(`span`,{className:`text-[11px] font-medium text-muted-foreground`,children:`Model`}),(0,X.jsx)(`span`,{className:`text-[11px] font-medium text-muted-foreground`,children:`Tools`}),(0,X.jsx)(`span`,{})]}),(0,X.jsx)(`div`,{className:`space-y-1`,children:c.map((t,o)=>(0,X.jsx)(ze,{activeRoleName:e?.name??null,index:o,onDeleteRole:n,onEditRole:r,onViewRole:i,providersById:a,role:t},t.name))})]})})}function ze({activeRoleName:e,index:t,onDeleteRole:n,onEditRole:r,onViewRole:a,providersById:o,role:u}){return(0,X.jsxs)(s.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{delay:t*.03},className:S(`group grid grid-cols-[220px_1fr_100px_80px] items-center gap-4 rounded-xl px-4 py-3.5 transition-colors`,e===u.name?`bg-accent/25`:`hover:bg-accent/15`),children:[(0,X.jsxs)(`div`,{className:`min-w-0 pr-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:u.name}),u.is_builtin?(0,X.jsx)(F,{tone:`muted`,className:`px-1.5 py-0.5 text-[9px]`,children:`Built-in`}):null]}),(0,X.jsx)(`p`,{className:`mt-1 line-clamp-2 text-[12px] leading-relaxed text-muted-foreground`,children:u.description})]}),(0,X.jsx)(`div`,{className:`min-w-0 pr-2`,children:(0,X.jsx)(`span`,{className:`block truncate text-[13px] text-muted-foreground`,children:Ie(u,o)})}),(0,X.jsx)(`div`,{className:`pr-2`,children:(0,X.jsx)(`span`,{className:`font-mono text-[13px] text-muted-foreground`,children:Le(u)})}),(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 focus-within:opacity-100`,children:[(0,X.jsx)(_,{onClick:()=>a(u),"aria-label":`View ${u.name}`,title:`View ${u.name}`,className:`size-7`,children:(0,X.jsx)(i,{className:`size-3.5`})}),(0,X.jsx)(_,{onClick:()=>r(u),"aria-label":`Edit ${u.name}`,title:`Edit ${u.name}`,className:`size-7`,children:(0,X.jsx)(c,{className:`size-3.5`})}),u.is_builtin?null:(0,X.jsx)(_,{onClick:()=>n(u),"aria-label":`Delete ${u.name}`,title:`Delete ${u.name}`,className:`flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive`,children:(0,X.jsx)(l,{className:`size-3.5`})})]})]})}var $=e(t(),1);function Be(){let e=se(),[t,n]=(0,$.useState)(e.roleMode),[r,i]=(0,$.useState)(e.roleName),[a,o]=(0,$.useState)(Z()),[s,c]=(0,$.useState)(!1),[l,u]=(0,$.useState)(null),d=(0,$.useRef)(null),{data:_,isLoading:b,mutate:x}=ne(`rolesBootstrap`,m),S=(0,$.useMemo)(()=>_?.roles??[],[_?.roles]),C=(0,$.useMemo)(()=>_?.tools??[],[_?.tools]),T=(0,$.useMemo)(()=>_?.providers??[],[_?.providers]),ee=(0,$.useMemo)(()=>we(C),[C]),E=(0,$.useMemo)(()=>Te(T),[T]),D=(0,$.useMemo)(()=>r?S.find(e=>e.name===r)??null:null,[r,S]),O=a.model?.provider_id??``,k=(0,$.useMemo)(()=>O?E[O]?.models??[]:[],[O,E]),A=t!==null,M=je(t),N=Me(t,D),P=Ne(t,D),te=Pe(t,D),F=Fe(a,s);(0,$.useEffect)(()=>{if(e.page!==`roles`)return;let t=e.roleMode===`create`?`create`:e.roleName?`${e.roleMode??`view`}:${e.roleName}`:`list`;if(d.current!==t){if(e.roleMode===`create`){d.current=t,n(`create`),i(null),o(Z());return}if(e.roleName){let r=S.find(t=>t.name===e.roleName);if(!r){b||(d.current=`list`,n(null),i(null),o(Z()),w(j(null)));return}d.current=t,n(e.roleMode===`edit`?`edit`:`view`),i(r.name),o(Q(r));return}d.current=t,n(null),i(null),o(Z())}},[b,S,e.page,e.roleMode,e.roleName]);let I=(0,$.useCallback)(e=>{x({roles:e,tools:C,providers:T},!1)},[x,T,C]),re=(0,$.useCallback)(async()=>{await x()},[x]),ie=(0,$.useCallback)(()=>{d.current=`list`,n(null),i(null),o(Z()),v(j(null))},[]),L=(0,$.useCallback)(()=>{d.current=`create`,n(`create`),i(null),o(Z()),v(y())},[]),ae=(0,$.useCallback)(e=>{d.current=`view:${e.name}`,n(`view`),i(e.name),o(Q(e)),v(j(e.name,`view`))},[]),oe=(0,$.useCallback)(e=>{d.current=`edit:${e.name}`,n(`edit`),i(e.name),o(Q(e)),v(j(e.name,`edit`))},[]),R=(0,$.useCallback)(e=>{o(t=>e(t))},[]),z=(0,$.useCallback)(e=>{if(!e){R(e=>({...e,model:null}));return}if(T.length===0){f.error(`Create a provider before setting a role model`);return}R(e=>({...e,model:e.model??Oe(T)}))},[T,R]),B=(0,$.useCallback)(e=>{R(t=>({...t,model:t.model?{provider_id:e,model:``}:null}))},[R]),V=(0,$.useCallback)(e=>{R(t=>({...t,model_params:e?Y(t.model_params):null}))},[R]),H=(0,$.useCallback)(async()=>{let e=ke({activeRoleName:r,draft:a,roles:S});if(e){f.error(e);return}c(!0);try{let e=Ae(a);if(t===`edit`&&r){let t=await p(r,D?.is_builtin?{model:e.model,model_params:e.model_params}:e);I(S.map(e=>e.name===r?t:e)),d.current=`view:${t.name}`,n(`view`),i(t.name),o(Q(t)),w(j(t.name,`view`)),f.success(`Role updated`)}else{let t=await g(e);I([t,...S]),d.current=`view:${t.name}`,n(`view`),i(t.name),o(Q(t)),w(j(t.name,`view`)),f.success(`Role created`)}}catch(e){f.error(e instanceof Error?e.message:`Failed to save role`)}finally{c(!1)}},[D,r,a,t,S,I]),U=(0,$.useCallback)(e=>{u(e)},[]),W=(0,$.useCallback)(()=>{u(null)},[]),G=(0,$.useCallback)(async()=>{if(!l)return;let e=l.name;u(null);try{await h(e),I(S.filter(t=>t.name!==e)),r===e&&(d.current=`list`,n(null),i(null),o(Z()),w(j(null))),f.success(`Role deleted`)}catch(e){f.error(e instanceof Error?e.message:`Failed to delete role`)}},[r,l,S,I]);return{activeRole:D,activeRoleName:r,availableActiveProviderModelOptions:k,canSave:F,configurableTools:ee,draft:a,isPanelOpen:A,isReadOnly:M,loading:b,panelBadgeLabel:P,panelMode:t,panelTitle:te,providers:T,providersById:E,refreshRoles:re,roleToDelete:l,roles:S,saving:s,shouldLockIdentityFields:N,actions:{clearRoleToDelete:W,closePanel:ie,cycleRoleToolState:(0,$.useCallback)(e=>{R(t=>De(t,e))},[R]),handleDelete:G,handleModelModeChange:z,handleModelParamsModeChange:V,handleProviderChange:B,handleSave:H,openCreate:L,openEdit:oe,openView:ae,requestDeleteRole:U,updateDraft:R},getToolState:e=>Ee(a,e)}}function Ve(){let e=N(),{activeRole:t,availableActiveProviderModelOptions:n,canSave:r,configurableTools:i,draft:a,getToolState:o,isPanelOpen:s,isReadOnly:c,loading:l,panelBadgeLabel:f,panelMode:p,panelTitle:m,providers:h,providersById:g,refreshRoles:_,roleToDelete:y,roles:b,saving:x,shouldLockIdentityFields:C,actions:w}=Be(),T={...w,openProvidersPage:()=>{e?.navigateToPage(`providers`),e||v(M(`providers`))}};return l&&!s?(0,X.jsx)(D,{label:`Loading roles...`}):(0,X.jsxs)(re,{className:`px-4 pt-6 sm:px-5`,children:[(0,X.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,X.jsx)(ie,{title:`Roles`,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(A,{type:`button`,variant:`outline`,size:`icon-sm`,onClick:()=>void _(),disabled:l,className:`bg-accent/20 text-muted-foreground hover:bg-accent/45 hover:text-foreground`,children:(0,X.jsx)(u,{className:S(`size-4`,l&&`animate-spin`)})}),s?null:(0,X.jsxs)(A,{type:`button`,size:`sm`,onClick:w.openCreate,children:[(0,X.jsx)(d,{className:`size-4`}),`New Role`]})]})}),(0,X.jsx)(`div`,{className:`mt-6 min-h-0 flex-1`,children:s?(0,X.jsx)(be,{activeRole:t,availableProviderModels:n,canSave:r,configurableTools:i,draft:a,getToolState:o,isReadOnly:c,onClosePanel:w.closePanel,onEditRole:w.openEdit,onModelModeChange:w.handleModelModeChange,onModelParamsModeChange:w.handleModelParamsModeChange,onOpenProvidersPage:T.openProvidersPage,onProviderChange:w.handleProviderChange,onSaveRole:w.handleSave,onToolStateCycle:w.cycleRoleToolState,onUpdateDraft:w.updateDraft,panelBadgeLabel:f,panelMode:p,panelTitle:m,providers:h,saving:x,shouldLockIdentityFields:C}):(0,X.jsx)(Re,{activeRole:t,onCreateRole:w.openCreate,onDeleteRole:w.requestDeleteRole,onEditRole:w.openEdit,onViewRole:w.openView,providersById:g,roles:b})})]}),(0,X.jsx)(de,{roleToDelete:y,onConfirmDelete:w.handleDelete,onOpenChange:e=>{e||w.clearRoleToDelete()}})]})}export{Ve as RolesPage};
@@ -0,0 +1,3 @@
1
+ import{a as e}from"./rolldown-runtime-BYbx6iT9.js";import{d as t,l as n}from"./graph-vendor-DRq_-6fV.js";import{c as r,d as i,l as a,q as o,u as s,ut as c}from"./ui-vendor-C5pJa8N7.js";import{E as l,O as u,Q as d,Y as f,at as p,et as m,ft as h,it as g,nt as _,r as v,rt as y,st as b,tt as x,ut as S}from"./index-C9HuekJm.js";import{a as C,c as w,i as T,n as E,o as D,r as O,t as k}from"./PageScaffold-f6g2l7XN.js";import{i as A,r as j,t as M}from"./providerTypes-DT3Ahwl_.js";import{a as N,i as P,n as F,r as I,t as L}from"./select-DCfeNu-F.js";import{t as R}from"./useAppRoute-FgSHBKhV.js";import{i as z,t as B}from"./modelParams-DmnF2hwR.js";async function V(){return f(`/api/settings/bootstrap`,{errorMessage:`Failed to fetch settings bootstrap`})}async function ee(e){return f(`/api/settings`,{method:`POST`,body:e,errorMessage:`Failed to save settings`,map:e=>{if(!e)throw Error(`Failed to save settings`);return{settings:e.settings,reauthRequired:e.reauth_required===!0}}})}var H=e(t(),1),U=n(),W=s,G=H.forwardRef(({className:e,...t},n)=>(0,U.jsx)(a,{ref:n,className:h(`inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground`,e),...t}));G.displayName=a.displayName;var K=H.forwardRef(({className:e,...t},n)=>(0,U.jsx)(i,{ref:n,className:h(`inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow`,e),...t}));K.displayName=i.displayName;var q=H.forwardRef(({className:e,...t},n)=>(0,U.jsx)(r,{ref:n,className:h(`mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,e),...t}));q.displayName=r.displayName;var J=1024;function Y(e){let t=[],n=new Set;for(let r of e){let e=r.trim();if(!e)continue;let i=e.replace(/\/+$/u,``)||`/`;n.has(i)||(n.add(i),t.push(i))}return t}function X(e,t){return e.find(e=>e.id===t)??null}function Z(e,t){return e.find(e=>e.name===t)??null}function Q(e){return e?.models??[]}function te(e,t){return t?e.find(e=>e.model===t)??null:null}function ne(e,t){return e.model.context_window_tokens??t?.context_window_tokens??e.model.resolved_context_window_tokens??null}function re(e,t){return{input_image:e.model.input_image??t?.input_image??e.model.capabilities?.input_image??!1,output_image:e.model.output_image??t?.output_image??e.model.capabilities?.output_image??!1,structured_output:e.model.structured_output??t?.structured_output??e.model.capabilities?.structured_output??!1}}function ie(e,t){if(!e)return null;let n=t.max_output_tokens??1024;return Math.max(1,e-n-J)}function ae(e,t){return e!==null&&t!==null&&e>=t?`Automatic Compact token limit must stay below the known safe input window`:null}function oe(e,t){let n=t&&(t.newCode||t.confirmCode)?{new_code:t.newCode,confirm_code:t.confirmCode}:void 0;return{...n?{access:n}:{},working_dir:e.working_dir.trim(),assistant:{role_name:e.assistant.role_name,allow_network:e.assistant.allow_network,write_dirs:Y(e.assistant.write_dirs)},leader:e.leader,model:{active_provider_id:e.model.active_provider_id,active_model:e.model.active_model,input_image:e.model.input_image,output_image:e.model.output_image,structured_output:e.model.structured_output,context_window_tokens:e.model.context_window_tokens,timeout_ms:e.model.timeout_ms,retry_policy:e.model.retry_policy,max_retries:e.model.max_retries,retry_initial_delay_seconds:e.model.retry_initial_delay_seconds,retry_max_delay_seconds:e.model.retry_max_delay_seconds,retry_backoff_cap_retries:e.model.retry_backoff_cap_retries,auto_compact_token_limit:e.model.auto_compact_token_limit,params:e.model.params}}}var $=[{value:`no_retry`,label:`No retry`},{value:`limited`,label:`Limited`},{value:`unlimited`,label:`Unlimited`}];function se({accessDraftError:e,onSave:t,saving:n,settings:r}){return(0,U.jsx)(O,{title:`Settings`,actions:(0,U.jsxs)(S,{type:`button`,size:`sm`,onClick:t,disabled:n||!!e||!r.working_dir.trim(),className:`text-[13px]`,children:[(0,U.jsx)(c,{className:`size-4`}),n?`Saving...`:`Save Changes`]}),className:`mb-8`})}function ce({accessDraft:e,accessDraftError:t,onAccessDraftChange:n}){let r=!!(e.newCode.trim()||e.confirmCode.trim());return(0,U.jsxs)(k,{title:`Access Configuration`,className:`mt-8 first:mt-0`,children:[(0,U.jsx)(D,{label:`New Access Code`,children:(0,U.jsxs)(`div`,{className:`space-y-2 w-full max-w-lg`,children:[(0,U.jsx)(y,{id:`new-access-code`,value:e.newCode,onChange:e=>n(t=>({...t,newCode:e.target.value})),placeholder:`Leave empty to keep`,showLabel:`Show new access code`,hideLabel:`Hide new access code`,buttonSize:`default`}),r?(0,U.jsx)(`p`,{className:g,children:`Saving signs you out; use the new code to return.`}):null]})}),(0,U.jsx)(D,{label:`Confirm Access Code`,children:(0,U.jsxs)(`div`,{className:`space-y-2 w-full max-w-lg`,children:[(0,U.jsx)(y,{id:`confirm-access-code`,value:e.confirmCode,onChange:e=>n(t=>({...t,confirmCode:e.target.value})),placeholder:`Repeat the new access code`,showLabel:`Show confirmed access code`,hideLabel:`Hide confirmed access code`,buttonSize:`default`}),t?(0,U.jsx)(`p`,{className:h(`text-destructive font-medium pt-1`,g),children:t}):null]})})]})}function le({onSettingsChange:e,settings:t}){return(0,U.jsxs)(k,{title:`Path Configuration`,className:`mt-10`,children:[(0,U.jsx)(D,{label:`App Data Directory`,children:(0,U.jsxs)(`div`,{className:`space-y-2 max-w-lg`,children:[(0,U.jsx)(m,{"aria-label":`App Data Directory`,value:t.app_data_dir,readOnly:!0,mono:!0}),(0,U.jsx)(`p`,{className:g,children:`Read-only while Flowent is running.`})]})}),(0,U.jsx)(D,{label:`Working Directory`,children:(0,U.jsxs)(`div`,{className:`space-y-2 max-w-lg`,children:[(0,U.jsx)(m,{"aria-label":`Working Directory`,value:t.working_dir,onChange:t=>e(e=>({...e,working_dir:t.target.value})),placeholder:`/workspace/project`,mono:!0}),(0,U.jsx)(`p`,{className:g,children:`Changing this does not expand saved allowed folders.`}),(0,U.jsx)(`div`,{className:h(`space-y-2`,g),children:t.working_dir.trim()?null:(0,U.jsx)(`p`,{className:`text-destructive`,children:`Working Directory must not be empty.`})})]})})]})}function ue({assistantRole:e,onSettingsChange:t,roles:n,settings:r}){return(0,U.jsxs)(k,{title:`Assistant Configuration`,children:[(0,U.jsx)(C,{label:`Assistant Role`,children:(0,U.jsxs)(`div`,{className:`w-full`,children:[(0,U.jsxs)(L,{value:r.assistant.role_name,onValueChange:e=>t(t=>({...t,assistant:{...t.assistant,role_name:e}})),children:[(0,U.jsx)(P,{className:b,children:(0,U.jsx)(N,{placeholder:`Select a role`})}),(0,U.jsx)(F,{children:n.map(e=>(0,U.jsx)(I,{value:e.name,children:(0,U.jsxs)(`div`,{className:`flex min-w-0 flex-col items-start`,children:[(0,U.jsx)(`span`,{children:e.name}),(0,U.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:e.description})]})},e.name))})]}),e?(0,U.jsx)(`div`,{"data-testid":`assistant-role-guidance`,className:h(`mt-2`,g),children:(0,U.jsx)(`p`,{children:e.description})}):null]})}),(0,U.jsx)(C,{label:`Network Access`,children:(0,U.jsxs)(`div`,{className:`space-y-2`,children:[(0,U.jsx)(x,{checked:r.assistant.allow_network,label:`Network Access`,onCheckedChange:e=>t(t=>({...t,assistant:{...t.assistant,allow_network:e}})),showStateText:!0}),r.assistant.allow_network?null:(0,U.jsx)(`p`,{className:g,children:`Assistant cannot connect to the web.`})]})}),(0,U.jsx)(D,{label:`Write Directories`,children:(0,U.jsxs)(`div`,{className:`space-y-2 max-w-xl`,children:[(0,U.jsx)(_,{"aria-label":`Write Dirs`,value:r.assistant.write_dirs.join(`
2
+ `),onChange:e=>t(t=>({...t,assistant:{...t.assistant,write_dirs:e.target.value.split(`
3
+ `)}})),rows:4,spellCheck:!1,placeholder:`/workspace/output`,className:`min-h-[108px]`,mono:!0}),(0,U.jsx)(`p`,{className:g,children:`One absolute folder path per line.`})]})})]})}function de({leaderRole:e,onSettingsChange:t,roles:n,settings:r}){return(0,U.jsx)(k,{title:`Leader Configuration`,className:`mt-10`,children:(0,U.jsx)(C,{label:`Leader Role`,children:(0,U.jsxs)(`div`,{className:`w-full`,children:[(0,U.jsxs)(L,{value:r.leader.role_name,onValueChange:e=>t(t=>({...t,leader:{role_name:e}})),children:[(0,U.jsx)(P,{className:b,children:(0,U.jsx)(N,{placeholder:`Select a role`})}),(0,U.jsx)(F,{children:n.map(e=>(0,U.jsx)(I,{value:e.name,children:(0,U.jsxs)(`div`,{className:`flex min-w-0 flex-col items-start`,children:[(0,U.jsx)(`span`,{children:e.name}),(0,U.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:e.description})]})},e.name))})]}),e?(0,U.jsx)(`p`,{className:h(`mt-2`,g),children:e.description}):null]})})})}function fe({activeProvider:e,activeProviderModels:t,availableActiveProviderModels:n,effectiveContextWindowTokens:r,effectiveModelCapabilities:i,knownSafeInputTokens:a,onSettingsChange:o,providers:s,settings:c}){return(0,U.jsxs)(k,{title:`Model Configuration`,className:`mt-10`,children:[(0,U.jsxs)(C,{label:`Active Provider`,children:[(0,U.jsxs)(L,{value:c.model.active_provider_id,onValueChange:e=>{o(t=>({...t,model:{...t.model,active_provider_id:e,active_model:``}}))},children:[(0,U.jsx)(P,{className:b,children:(0,U.jsx)(N,{placeholder:`Select a provider`})}),(0,U.jsx)(F,{children:s.map(e=>(0,U.jsxs)(I,{value:e.id,children:[e.name,` (`,M(e.type),`)`]},e.id))})]}),e?(0,U.jsxs)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:[`Using `,e.name,` (`,e.base_url,`)`]}):null]}),(0,U.jsxs)(C,{label:`Model`,children:[(0,U.jsxs)(`div`,{className:`space-y-3`,children:[c.model.active_provider_id?t.length>0?(0,U.jsxs)(`div`,{className:`space-y-2`,children:[(0,U.jsx)(`label`,{className:p,children:`Provider Models`}),(0,U.jsxs)(L,{value:n.some(e=>e.model===c.model.active_model)?c.model.active_model:void 0,onValueChange:e=>o(t=>({...t,model:{...t.model,active_model:e}})),children:[(0,U.jsx)(P,{className:b,children:(0,U.jsx)(N,{placeholder:`Select a provider model`})}),(0,U.jsx)(F,{children:n.map(e=>(0,U.jsx)(I,{value:e.model,children:e.model},e.model))})]})]}):(0,U.jsx)(`p`,{className:g,children:`No saved provider models.`}):null,(0,U.jsx)(m,{value:c.model.active_model,onChange:e=>o(t=>({...t,model:{...t.model,active_model:e.target.value}})),placeholder:c.model.active_provider_id?`Enter model ID manually`:`Select a provider first`})]}),c.model.active_model?(0,U.jsxs)(`div`,{className:h(`mt-2 space-y-1`,g),children:[(0,U.jsxs)(`p`,{children:[`Context window:`,` `,r?r.toLocaleString():`Not resolved`]}),(0,U.jsxs)(`p`,{children:[`Capabilities: input_image=`,i.input_image?`true`:`false`,`, output_image=`,i.output_image?`true`:`false`,`, structured_output=`,i.structured_output?`true`:`false`]})]}):null]}),(0,U.jsx)(D,{label:`Model Metadata Overrides`,children:(0,U.jsx)(`div`,{className:`space-y-3 w-full`,children:(0,U.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-4`,children:[(0,U.jsxs)(`div`,{className:`space-y-1`,children:[(0,U.jsx)(`label`,{htmlFor:`model-context-window`,className:p,children:`Context Window`}),(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(m,{id:`model-context-window`,"aria-label":`Context Window`,inputMode:`numeric`,pattern:`[0-9]*`,value:c.model.context_window_tokens===null?``:String(c.model.context_window_tokens),onChange:e=>{let t=e.target.value.trim();/^\d*$/.test(t)&&(t&&Number.parseInt(t,10)<=0||o(e=>({...e,model:{...e.model,context_window_tokens:t?Number.parseInt(t,10):null}})))},placeholder:`Auto`,mono:!0}),(0,U.jsx)(`span`,{className:`text-[13px] font-medium text-muted-foreground`,children:`tokens`})]})]}),(0,U.jsxs)(`div`,{className:`space-y-1`,children:[(0,U.jsx)(`label`,{className:p,children:`Input Image`}),(0,U.jsxs)(L,{value:A(c.model.input_image),onValueChange:e=>o(t=>({...t,model:{...t.model,input_image:j(e)}})),children:[(0,U.jsx)(P,{"aria-label":`Input Image`,className:b,children:(0,U.jsx)(N,{placeholder:`Auto`})}),(0,U.jsxs)(F,{children:[(0,U.jsx)(I,{value:`auto`,children:`Auto`}),(0,U.jsx)(I,{value:`enabled`,children:`Enabled`}),(0,U.jsx)(I,{value:`disabled`,children:`Disabled`})]})]})]}),(0,U.jsxs)(`div`,{className:`space-y-1`,children:[(0,U.jsx)(`label`,{className:p,children:`Output Image`}),(0,U.jsxs)(L,{value:A(c.model.output_image),onValueChange:e=>o(t=>({...t,model:{...t.model,output_image:j(e)}})),children:[(0,U.jsx)(P,{"aria-label":`Output Image`,className:b,children:(0,U.jsx)(N,{placeholder:`Auto`})}),(0,U.jsxs)(F,{children:[(0,U.jsx)(I,{value:`auto`,children:`Auto`}),(0,U.jsx)(I,{value:`enabled`,children:`Enabled`}),(0,U.jsx)(I,{value:`disabled`,children:`Disabled`})]})]})]}),(0,U.jsxs)(`div`,{className:`space-y-1`,children:[(0,U.jsx)(`label`,{className:p,children:`Structured Output`}),(0,U.jsxs)(L,{value:A(c.model.structured_output??null),onValueChange:e=>o(t=>({...t,model:{...t.model,structured_output:j(e)}})),children:[(0,U.jsx)(P,{"aria-label":`Structured Output`,className:b,children:(0,U.jsx)(N,{placeholder:`Auto`})}),(0,U.jsxs)(F,{children:[(0,U.jsx)(I,{value:`auto`,children:`Auto`}),(0,U.jsx)(I,{value:`enabled`,children:`Enabled`}),(0,U.jsx)(I,{value:`disabled`,children:`Disabled`})]})]})]})]})})}),(0,U.jsx)(D,{label:`Default Model Parameters`,children:(0,U.jsx)(`div`,{className:`rounded-xl border border-border bg-card/30 p-5`,children:(0,U.jsx)(z,{className:`w-full`,value:B(c.model.params),onChange:e=>o(t=>({...t,model:{...t.model,params:e}})),emptyLabel:`Not set`,numberPlaceholder:`Not set`,reasoningDisableLabel:null})})}),(0,U.jsx)(C,{label:`Request Timeout`,children:(0,U.jsx)(`div`,{className:`space-y-2 w-full max-w-xs`,children:(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(m,{"aria-label":`Request Timeout`,inputMode:`numeric`,pattern:`[0-9]*`,value:String(c.model.timeout_ms),onChange:e=>{let t=e.target.value.trim();if(!/^\d+$/.test(t))return;let n=Number.parseInt(t,10);!Number.isSafeInteger(n)||n<=0||o(e=>({...e,model:{...e.model,timeout_ms:n}}))},mono:!0}),(0,U.jsx)(`span`,{className:`text-[13px] font-medium text-muted-foreground`,children:`ms`})]})})}),(0,U.jsx)(D,{label:`Retry Strategy`,children:(0,U.jsxs)(T,{className:`max-w-3xl`,children:[(0,U.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-[1fr_2fr]`,children:[(0,U.jsxs)(`div`,{className:`space-y-1`,children:[(0,U.jsx)(`label`,{className:p,children:`Policy`}),(0,U.jsxs)(L,{value:c.model.retry_policy,onValueChange:e=>o(t=>({...t,model:{...t.model,retry_policy:e}})),children:[(0,U.jsx)(P,{className:b,children:(0,U.jsx)(N,{placeholder:`Select a retry policy`})}),(0,U.jsx)(F,{children:$.map(e=>(0,U.jsx)(I,{value:e.value,children:e.label},e.value))})]})]}),c.model.retry_policy===`limited`?(0,U.jsxs)(`div`,{className:`space-y-1`,children:[(0,U.jsx)(`label`,{htmlFor:`retry-attempts`,className:p,children:`Max Attempts`}),(0,U.jsx)(m,{id:`retry-attempts`,"aria-label":`Retry Attempts`,inputMode:`numeric`,pattern:`[0-9]*`,value:String(c.model.max_retries),onChange:e=>{let t=e.target.value.trim();if(!/^\d+$/.test(t))return;let n=Number.parseInt(t,10);!Number.isSafeInteger(n)||n<=0||o(e=>({...e,model:{...e.model,max_retries:n}}))},mono:!0})]}):(0,U.jsx)(`div`,{})]}),(0,U.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-3 mt-2 border-t border-border/40 pt-4`,children:[(0,U.jsxs)(`div`,{className:`space-y-1`,children:[(0,U.jsx)(`label`,{htmlFor:`retry-initial-delay`,className:p,children:`Initial Delay`}),(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(m,{id:`retry-initial-delay`,"aria-label":`Initial Delay`,inputMode:`decimal`,value:String(c.model.retry_initial_delay_seconds),onChange:e=>{let t=e.target.value.trim();if(!/^\d+(\.\d+)?$/.test(t))return;let n=Number.parseFloat(t);!Number.isFinite(n)||n<=0||o(e=>({...e,model:{...e.model,retry_initial_delay_seconds:n}}))},mono:!0}),(0,U.jsx)(`span`,{className:`text-[13px] font-medium text-muted-foreground`,children:`s`})]})]}),(0,U.jsxs)(`div`,{className:`space-y-1`,children:[(0,U.jsx)(`label`,{htmlFor:`retry-max-delay`,className:p,children:`Max Delay`}),(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(m,{id:`retry-max-delay`,"aria-label":`Max Delay`,inputMode:`decimal`,value:String(c.model.retry_max_delay_seconds),onChange:e=>{let t=e.target.value.trim();if(!/^\d+(\.\d+)?$/.test(t))return;let n=Number.parseFloat(t);!Number.isFinite(n)||n<=0||o(e=>({...e,model:{...e.model,retry_max_delay_seconds:n}}))},mono:!0}),(0,U.jsx)(`span`,{className:`text-[13px] font-medium text-muted-foreground`,children:`s`})]})]}),(0,U.jsxs)(`div`,{className:`space-y-1`,children:[(0,U.jsx)(`label`,{htmlFor:`retry-backoff-cap-retries`,className:p,children:`Cap Retries`}),(0,U.jsx)(m,{id:`retry-backoff-cap-retries`,"aria-label":`Cap Retries`,inputMode:`numeric`,pattern:`[0-9]*`,value:String(c.model.retry_backoff_cap_retries),onChange:e=>{let t=e.target.value.trim();if(!/^\d+$/.test(t))return;let n=Number.parseInt(t,10);!Number.isSafeInteger(n)||n<=0||o(e=>({...e,model:{...e.model,retry_backoff_cap_retries:n}}))},mono:!0})]})]})]})}),(0,U.jsx)(D,{label:`Automatic Compact`,children:(0,U.jsxs)(`div`,{className:`space-y-3 w-full max-w-sm`,children:[(0,U.jsxs)(`div`,{className:`space-y-1`,children:[(0,U.jsx)(`label`,{htmlFor:`auto-compact-token-limit`,className:p,children:`Token Limit`}),(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(m,{id:`auto-compact-token-limit`,"aria-label":`Automatic Compact Token Limit`,inputMode:`numeric`,pattern:`[0-9]*`,value:c.model.auto_compact_token_limit===null?``:String(c.model.auto_compact_token_limit),onChange:e=>{let t=e.target.value.trim();/^\d*$/.test(t)&&(t&&Number.parseInt(t,10)<=0||o(e=>({...e,model:{...e.model,auto_compact_token_limit:t?Number.parseInt(t,10):null}})))},placeholder:`Disabled`,mono:!0}),(0,U.jsx)(`span`,{className:`text-[13px] font-medium text-muted-foreground`,children:`tokens`})]})]}),a===null?c.model.auto_compact_token_limit===null?null:(0,U.jsx)(`p`,{className:`text-[11px] leading-relaxed text-graph-status-idle`,children:`The current model window is not resolved, so this token limit can be saved but cannot be fully validated yet.`}):(0,U.jsxs)(`p`,{className:g,children:[`Known safe input window: `,a.toLocaleString(),` `,`tokens.`,c.model.auto_compact_token_limit!==null&&c.model.auto_compact_token_limit>=a?` Save is blocked until the token limit is lower than this window.`:null]})]})})]})}function pe({appVersion:e}){return(0,U.jsx)(`div`,{className:`mt-12 flex flex-col items-center pt-2 pb-6 text-center`,children:(0,U.jsxs)(`p`,{className:`text-[11px] font-medium text-muted-foreground`,children:[`Flowent Agent Studio v`,e??`—`]})})}function me(){let{requireReauth:e}=d(),{data:t,isLoading:n,mutate:r}=w(`settingsBootstrap`,()=>V()),[i,a]=(0,H.useState)(null),[s,c]=(0,H.useState)(!1),[l,u]=(0,H.useState)({newCode:``,confirmCode:``}),f=(0,H.useMemo)(()=>t?.providers??[],[t?.providers]),p=(0,H.useMemo)(()=>t?.roles??[],[t?.roles]),m=t?.version??null;(0,H.useEffect)(()=>{t?.settings&&!i&&a(t.settings)},[t?.settings,i]);let h=i??t?.settings??null,g=(0,H.useCallback)(e=>{a(n=>{let r=n??t?.settings??null;return r?e(r):n})},[t?.settings]),_=(0,H.useCallback)(e=>{u(t=>e(t))},[]),v=(0,H.useMemo)(()=>h?X(f,h.model.active_provider_id):null,[f,h]),y=(0,H.useMemo)(()=>h?Z(p,h.assistant.role_name):null,[p,h]),b=(0,H.useMemo)(()=>Q(v),[v]),x=b,S=(0,H.useMemo)(()=>h?te(b,h.model.active_model):null,[b,h]),C=(0,H.useMemo)(()=>h?ne(h,S):null,[S,h]),T=(0,H.useMemo)(()=>h?re(h,S):{input_image:!1,output_image:!1,structured_output:!1},[S,h]),E=(0,H.useMemo)(()=>h?ie(C,h.model.params):null,[C,h]),D=(0,H.useMemo)(()=>h?Z(p,h.leader.role_name):null,[p,h]),O=(0,H.useMemo)(()=>!l.newCode&&!l.confirmCode?null:l.newCode.trim()?l.confirmCode===l.newCode?null:`Confirm Access Code must exactly match New Access Code.`:`New Access Code must not be empty.`,[l.confirmCode,l.newCode]);return{accessDraft:l,accessDraftError:O,activeProvider:v,activeProviderModels:b,availableActiveProviderModels:x,appVersion:m,assistantRole:y,effectiveContextWindowTokens:C,effectiveModelCapabilities:T,handleSave:(0,H.useCallback)(async()=>{if(!h)return;if(O){o.error(O);return}if(!h.working_dir.trim()){o.error(`Working Directory must not be empty`);return}if(h.model.retry_max_delay_seconds<h.model.retry_initial_delay_seconds){o.error(`Max Delay must be greater than or equal to Initial Delay`);return}let t=ae(h.model.auto_compact_token_limit,E);if(t){o.error(t);return}c(!0);try{let t=await ee(oe(h,l)),n=t.settings;if(a(n),u({newCode:``,confirmCode:``}),r(e=>e&&{...e,settings:n},!1),t.reauthRequired){o.success(`Access code updated. Sign in again with the new code.`),e();return}o.success(`Settings saved`)}catch(e){o.error(e instanceof Error?e.message:`Failed to save settings`)}finally{c(!1)}},[l,O,E,r,e,h]),knownSafeInputTokens:E,leaderRole:D,loading:n,providers:f,roles:p,saving:s,settings:h,updateAccessDraft:_,updateSettings:g}}var he=[`model`,`assistant`,`leader`,`access`,`path`];function ge(){let e=R(),{accessDraft:t,accessDraftError:n,activeProvider:r,activeProviderModels:i,availableActiveProviderModels:a,appVersion:o,assistantRole:s,effectiveContextWindowTokens:c,effectiveModelCapabilities:d,handleSave:f,knownSafeInputTokens:p,leaderRole:m,loading:h,providers:g,roles:_,saving:y,settings:b,updateAccessDraft:x,updateSettings:S}=me();return h||!b?(0,U.jsx)(v,{label:`Loading settings...`,textClassName:`text-[13px]`}):(0,U.jsx)(E,{children:(0,U.jsx)(`div`,{className:`h-full min-h-0 overflow-y-auto pr-2 scrollbar-none pb-20`,children:(0,U.jsxs)(`div`,{className:`mx-auto max-w-[680px] pb-10 pt-6`,children:[(0,U.jsx)(se,{accessDraftError:n,onSave:()=>{f()},saving:y,settings:b}),(0,U.jsxs)(W,{value:e.settingsSection,onValueChange:e=>{u(l(e))},className:`w-full`,children:[(0,U.jsx)(G,{className:`mb-8 w-full justify-start h-auto flex-wrap bg-transparent p-0 gap-6 border-b border-border/40 rounded-none`,children:he.map(e=>(0,U.jsx)(K,{value:e,className:`data-[state=active]:bg-transparent data-[state=active]:shadow-none bg-transparent border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:text-foreground text-muted-foreground rounded-none px-1 pb-2.5 pt-2 hover:text-foreground transition-colors`,children:e.charAt(0).toUpperCase()+e.slice(1)},e))}),(0,U.jsx)(q,{value:`model`,className:`mt-0`,children:(0,U.jsx)(fe,{activeProvider:r,activeProviderModels:i,availableActiveProviderModels:a,effectiveContextWindowTokens:c,effectiveModelCapabilities:d,knownSafeInputTokens:p,onSettingsChange:S,providers:g,settings:b})}),(0,U.jsx)(q,{value:`assistant`,className:`mt-0`,children:(0,U.jsx)(ue,{assistantRole:s,onSettingsChange:S,roles:_,settings:b})}),(0,U.jsx)(q,{value:`leader`,className:`mt-0`,children:(0,U.jsx)(de,{leaderRole:m,onSettingsChange:S,roles:_,settings:b})}),(0,U.jsx)(q,{value:`access`,className:`mt-0`,children:(0,U.jsx)(ce,{accessDraft:t,accessDraftError:n,onAccessDraftChange:x})}),(0,U.jsx)(q,{value:`path`,className:`mt-0`,children:(0,U.jsx)(le,{onSettingsChange:S,settings:b})})]}),(0,U.jsx)(pe,{appVersion:o})]})})})}export{ge as SettingsPage};
@@ -0,0 +1 @@
1
+ import{a as e}from"./rolldown-runtime-BYbx6iT9.js";import{d as t,l as n}from"./graph-vendor-DRq_-6fV.js";import{Bt as r,Ht as i,J as a,Lt as o,Mt as s,Pt as c,Q as l,Tt as u,Ut as d,Vt as f,X as p,Y as m,Yt as h,_t as g,an as _,at as v,it as y,jt as b,lt as x,st as S,tt as C,zt as w}from"./ui-vendor-C5pJa8N7.js";import{Y as T,ft as E,ht as D,lt as O,ut as k}from"./index-C9HuekJm.js";import{a as A,i as j,o as M,r as N,t as P}from"./surface-pWwG5ogx.js";import{c as F,n as I,r as L}from"./PageScaffold-f6g2l7XN.js";async function R(){return T(`/api/tools`,{errorMessage:`Failed to fetch tools`,fallback:[],map:e=>e?.tools??[]})}var z=e(t(),1),B=n(),V={send:S,idle:h,sleep:h,todo:b,contacts:u,list_tools:m,list_roles:p,list_workflows:c,exec:C,read:f,edit:i,fetch:o,create_workflow:r,create_agent:w,connect:s,set_permissions:y,manage_providers:g,manage_roles:l,manage_settings:v,manage_prompts:d};function H(e){let t=e.trim();return t.length<=96?t:`${t.slice(0,93).trimEnd()}...`}function U({expanded:e,onToggle:t,tool:n}){let r=V[n.name]??m;return(0,B.jsxs)(A,{as:`div`,padding:`md`,onClick:t,className:E(`group cursor-pointer transition-colors duration-300 hover:border-ring/25 hover:bg-accent/20 hover:shadow-sm`,e&&`border-border bg-accent/20 shadow-sm`),children:[(0,B.jsx)(N,{icon:r,size:`sm`,className:`mb-4 transition-colors group-hover:bg-accent/40`}),(0,B.jsx)(`code`,{className:`block text-[13px] font-mono font-medium text-foreground`,children:n.name}),(0,B.jsx)(`p`,{className:`mt-2 text-[10px] text-muted-foreground/75`,children:`Built-in`}),(0,B.jsx)(`p`,{className:`mt-2 line-clamp-1 text-[12px] leading-relaxed text-muted-foreground`,children:H(n.description)}),(0,B.jsx)(D,{initial:!1,children:e?(0,B.jsx)(_.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},transition:{duration:.2,ease:[.22,1,.36,1]},className:`overflow-hidden`,onClick:e=>e.stopPropagation(),children:(0,B.jsxs)(`div`,{className:`mt-4 border-t border-border pt-4`,children:[(0,B.jsx)(`p`,{className:`mb-2 text-[10px] font-medium text-muted-foreground/75`,children:`Parameters`}),(0,B.jsx)(P,{className:`max-h-48 p-3.5 text-foreground/70`,children:JSON.stringify(n.parameters??{},null,2)})]})}):null})]})}function W(){let{data:e=[],isLoading:t}=F(`tools`,R),[n,r]=(0,z.useState)(new Set),[i,o]=(0,z.useState)(``),s=i.trim().toLowerCase(),c=(0,z.useMemo)(()=>s?e.filter(e=>[e.name,e.description,e.source??``].join(` `).toLowerCase().includes(s)):e,[s,e]),l=e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,B.jsx)(I,{children:(0,B.jsxs)(`div`,{className:`flex h-full flex-col px-8 pt-6`,children:[(0,B.jsx)(L,{title:`Tools`}),(0,B.jsxs)(`div`,{className:`mb-6 mt-6 flex items-center justify-between gap-4`,children:[(0,B.jsxs)(`div`,{className:`relative w-full max-w-sm`,children:[(0,B.jsx)(x,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground`}),(0,B.jsx)(O,{value:i,onChange:e=>o(e.target.value),placeholder:`Search tools`,className:`h-9 rounded-full bg-background/45 pl-9 pr-9 text-[13px]`}),i?(0,B.jsx)(k,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`Clear search`,className:`absolute right-2 top-1/2 -translate-y-1/2 rounded-full text-muted-foreground hover:bg-accent/35 hover:text-foreground`,onClick:()=>o(``),children:(0,B.jsx)(a,{className:`size-3.5`})}):null]}),(0,B.jsxs)(M,{tone:`neutral`,className:`h-5 text-[11px]`,children:[c.length,` tools`]})]}),(0,B.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto pr-2 scrollbar-none`,children:t?(0,B.jsx)(`div`,{className:`grid grid-cols-2 gap-4 lg:grid-cols-3`,children:[...[,,,,,,]].map((e,t)=>(0,B.jsx)(A,{as:`div`,className:`h-36 animate-pulse bg-accent/20`},t))}):e.length===0?(0,B.jsx)(_.div,{initial:{opacity:0},animate:{opacity:1},className:`flex h-full flex-col items-center justify-center text-center`,children:(0,B.jsx)(j,{icon:m,title:`No tools available`,className:`border-transparent bg-transparent`})}):c.length===0?(0,B.jsx)(_.div,{initial:{opacity:0},animate:{opacity:1},className:`flex h-full flex-col items-center justify-center text-center`,children:(0,B.jsx)(j,{icon:x,title:`No tools found`,action:(0,B.jsxs)(k,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>o(``),children:[(0,B.jsx)(a,{className:`size-4`}),`Clear Search`]}),className:`border-transparent bg-transparent`})}):(0,B.jsx)(`div`,{className:`grid grid-cols-2 gap-4 lg:grid-cols-3 pb-8`,children:c.map((e,t)=>(0,B.jsx)(_.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:t*.03},children:(0,B.jsx)(U,{tool:e,expanded:n.has(e.name),onToggle:()=>l(e.name)})},e.name))})})]})})}export{W as ToolsPage};
@@ -0,0 +1,3 @@
1
+ import{a as e}from"./rolldown-runtime-BYbx6iT9.js";import{a as t,d as n,i as r,l as i,n as a,o,r as s,s as c,t as l,u}from"./graph-vendor-DRq_-6fV.js";import{$ as d,B as f,G as p,J as m,L as h,Nt as g,Rt as _,Tt as v,U as y,V as b,Wt as x,Z as S,an as C,en as w,et as T,gt as ee,ht as te,lt as E,mt as ne,pt as re,q as D,t as O,ut as k,z as A}from"./ui-vendor-C5pJa8N7.js";import{r as j}from"./roles-CuRT_chR.js";import{a as M,c as ie,d as N,f as P,i as ae,l as F,n as I,o as L,p as R,r as oe,s as z,t as se,u as ce}from"./WorkspacePanels-CteCjolX.js";import{B,F as V,H as le,I as ue,L as de,N as H,P as fe,R as pe,V as me,_ as he,ct as ge,d as _e,f as ve,ft as U,g as ye,h as be,ht as W,l as G,lt as xe,m as Se,n as Ce,p as we,pt as Te,t as Ee,tt as De,u as Oe,ut as K,v as ke,z as Ae}from"./index-C9HuekJm.js";import{a as je,c as Me,i as Ne,n as q,o as Pe,r as Fe,s as Ie,t as Le}from"./alert-dialog-Duorp_S-.js";import{a as Re,i as ze,n as J,r as Y,t as Be}from"./select-DCfeNu-F.js";import{a as X,i as Z,n as Ve,o as He,r as Ue,s as We,t as Ge}from"./dialog-C3ixjGjN.js";var Q=i();function Ke({open:e,onOpenChange:t,title:n,children:r,footer:i,className:a}){return(0,Q.jsx)(Ge,{open:e,onOpenChange:t,children:(0,Q.jsx)(Ue,{className:U(`flex max-h-[calc(100svh-2rem)] flex-col p-0`,a),children:(0,Q.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 flex-col overflow-hidden p-6`,children:[(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-0 bg-gradient-to-b from-foreground/[0.04] to-transparent opacity-50`}),(0,Q.jsx)(Ve,{asChild:!0,children:(0,Q.jsx)(K,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":`Close dialog`,className:`absolute right-4 top-4 z-20 size-7 rounded-md bg-accent/45 text-muted-foreground hover:bg-accent/65 hover:text-accent-foreground`,children:(0,Q.jsx)(m,{className:`size-3.5`})})}),(0,Q.jsxs)(He,{className:`relative z-10 shrink-0 pr-8`,children:[(0,Q.jsx)(We,{className:`text-[1.1rem] font-medium text-foreground`,children:n}),(0,Q.jsx)(Z,{className:`sr-only`,children:n})]}),(0,Q.jsx)(`div`,{className:`relative z-10 mt-6 min-h-0 flex-1 space-y-4 overflow-y-auto pr-1 scrollbar-none`,"data-testid":`workspace-command-dialog-body`,children:r}),(0,Q.jsx)(X,{className:`relative z-10 mt-6 shrink-0 border-t border-border pt-4`,children:i})]})})})}function qe({label:e,hint:t,children:n}){return(0,Q.jsxs)(`label`,{className:`block space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium text-foreground/80`,children:e}),t?(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t}):null]}),n]})}function Je({children:e}){return(0,Q.jsx)(`div`,{className:`rounded-lg border border-border bg-accent/35 px-3.5 py-2.5 text-xs text-muted-foreground`,children:e})}var $=e(n(),1),Ye=1,Xe=.9,Ze=.8,Qe=.17,$e=.1,et=.999,tt=.9999,nt=.99,rt=/[\\\/_+.#"@\[\(\{&]/,it=/[\\\/_+.#"@\[\(\{&]/g,at=/[\s-]/,ot=/[\s-]/g;function st(e,t,n,r,i,a,o){if(a===t.length)return i===e.length?Ye:nt;var s=`${i},${a}`;if(o[s]!==void 0)return o[s];for(var c=r.charAt(a),l=n.indexOf(c,i),u=0,d,f,p,m;l>=0;)d=st(e,t,n,r,l+1,a+1,o),d>u&&(l===i?d*=Ye:rt.test(e.charAt(l-1))?(d*=Ze,p=e.slice(i,l-1).match(it),p&&i>0&&(d*=et**+p.length)):at.test(e.charAt(l-1))?(d*=Xe,m=e.slice(i,l-1).match(ot),m&&i>0&&(d*=et**+m.length)):(d*=Qe,i>0&&(d*=et**+(l-i))),e.charAt(l)!==t.charAt(a)&&(d*=tt)),(d<$e&&n.charAt(l-1)===r.charAt(a+1)||r.charAt(a+1)===r.charAt(a)&&n.charAt(l-1)!==r.charAt(a))&&(f=st(e,t,n,r,l+1,a+2,o),f*$e>d&&(d=f*$e)),d>u&&(u=d),l=n.indexOf(c,l+1);return o[s]=u,u}function ct(e){return e.toLowerCase().replace(ot,` `)}function lt(e,t,n){return e=n&&n.length>0?`${e+` `+n.join(` `)}`:e,st(e,t,ct(e),ct(t),0,0,{})}var ut=`[cmdk-group=""]`,dt=`[cmdk-group-items=""]`,ft=`[cmdk-group-heading=""]`,pt=`[cmdk-item=""]`,mt=`${pt}:not([aria-disabled="true"])`,ht=`cmdk-item-select`,gt=`data-value`,_t=(e,t,n)=>lt(e,t,n),vt=$.createContext(void 0),yt=()=>$.useContext(vt),bt=$.createContext(void 0),xt=()=>$.useContext(bt),St=$.createContext(void 0),Ct=$.forwardRef((e,t)=>{let n=Lt(()=>({search:``,value:e.value??e.defaultValue??``,selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}})),r=Lt(()=>new Set),i=Lt(()=>new Map),a=Lt(()=>new Map),o=Lt(()=>new Set),s=Ft(e),{label:c,children:l,value:u,onValueChange:d,filter:f,shouldFilter:p,loop:m,disablePointerSelection:h=!1,vimBindings:g=!0,..._}=e,v=y(),b=y(),x=y(),S=$.useRef(null),C=Bt();It(()=>{if(u!==void 0){let e=u.trim();n.current.value=e,w.emit()}},[u]),It(()=>{C(6,re)},[]);let w=$.useMemo(()=>({subscribe:e=>(o.current.add(e),()=>o.current.delete(e)),snapshot:()=>n.current,setState:(e,t,r)=>{var i,a,o;if(!Object.is(n.current[e],t)){if(n.current[e]=t,e===`search`)ne(),te(),C(1,E);else if(e===`value`){if(document.activeElement.hasAttribute(`cmdk-input`)||document.activeElement.hasAttribute(`cmdk-root`)){let e=document.getElementById(x);e?e.focus():(i=document.getElementById(v))==null||i.focus()}if(C(7,()=>{n.current.selectedItemId=D()?.id,w.emit()}),r||C(5,re),s.current?.value!==void 0){let e=t??``;(o=(a=s.current).onValueChange)==null||o.call(a,e);return}}w.emit()}},emit:()=>{o.current.forEach(e=>e())}}),[]),T=$.useMemo(()=>({value:(e,t,r)=>{t!==a.current.get(e)?.value&&(a.current.set(e,{value:t,keywords:r}),n.current.filtered.items.set(e,ee(t,r)),C(2,()=>{te(),w.emit()}))},item:(e,t)=>(r.current.add(e),t&&(i.current.has(t)?i.current.get(t).add(e):i.current.set(t,new Set([e]))),C(3,()=>{ne(),te(),n.current.value||E(),w.emit()}),()=>{a.current.delete(e),r.current.delete(e),n.current.filtered.items.delete(e);let t=D();C(4,()=>{ne(),t?.getAttribute(`id`)===e&&E(),w.emit()})}),group:e=>(i.current.has(e)||i.current.set(e,new Set),()=>{a.current.delete(e),i.current.delete(e)}),filter:()=>s.current.shouldFilter,label:c||e[`aria-label`],getDisablePointerSelection:()=>s.current.disablePointerSelection,listId:v,inputId:x,labelId:b,listInnerRef:S}),[]);function ee(e,t){let r=s.current?.filter??_t;return e?r(e,n.current.search,t):0}function te(){if(!n.current.search||s.current.shouldFilter===!1)return;let e=n.current.filtered.items,t=[];n.current.filtered.groups.forEach(n=>{let r=i.current.get(n),a=0;r.forEach(t=>{let n=e.get(t);a=Math.max(n,a)}),t.push([n,a])});let r=S.current;k().sort((t,n)=>{let r=t.getAttribute(`id`),i=n.getAttribute(`id`);return(e.get(i)??0)-(e.get(r)??0)}).forEach(e=>{let t=e.closest(dt);t?t.appendChild(e.parentElement===t?e:e.closest(`${dt} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${dt} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{let t=S.current?.querySelector(`${ut}[${gt}="${encodeURIComponent(e[0])}"]`);t?.parentElement.appendChild(t)})}function E(){let e=k().find(e=>e.getAttribute(`aria-disabled`)!==`true`)?.getAttribute(gt);w.setState(`value`,e||void 0)}function ne(){if(!n.current.search||s.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let e=0;for(let t of r.current){let r=ee(a.current.get(t)?.value??``,a.current.get(t)?.keywords??[]);n.current.filtered.items.set(t,r),r>0&&e++}for(let[e,t]of i.current)for(let r of t)if(n.current.filtered.items.get(r)>0){n.current.filtered.groups.add(e);break}n.current.filtered.count=e}function re(){var e;let t=D();t&&(t.parentElement?.firstChild===t&&((e=t.closest(ut)?.querySelector(ft))==null||e.scrollIntoView({block:`nearest`})),t.scrollIntoView({block:`nearest`}))}function D(){return S.current?.querySelector(`${pt}[aria-selected="true"]`)}function k(){return Array.from(S.current?.querySelectorAll(mt)||[])}function A(e){let t=k()[e];t&&w.setState(`value`,t.getAttribute(gt))}function j(e){var t;let n=D(),r=k(),i=r.findIndex(e=>e===n),a=r[i+e];(t=s.current)!=null&&t.loop&&(a=i+e<0?r[r.length-1]:i+e===r.length?r[0]:r[i+e]),a&&w.setState(`value`,a.getAttribute(gt))}function M(e){let t=D()?.closest(ut),n;for(;t&&!n;)t=e>0?Nt(t,ut):Pt(t,ut),n=t?.querySelector(mt);n?w.setState(`value`,n.getAttribute(gt)):j(e)}let ie=()=>A(k().length-1),N=e=>{e.preventDefault(),e.metaKey?ie():e.altKey?M(1):j(1)},P=e=>{e.preventDefault(),e.metaKey?A(0):e.altKey?M(-1):j(-1)};return $.createElement(O.div,{ref:t,tabIndex:-1,..._,"cmdk-root":``,onKeyDown:e=>{var t;(t=_.onKeyDown)==null||t.call(_,e);let n=e.nativeEvent.isComposing||e.keyCode===229;if(!(e.defaultPrevented||n))switch(e.key){case`n`:case`j`:g&&e.ctrlKey&&N(e);break;case`ArrowDown`:N(e);break;case`p`:case`k`:g&&e.ctrlKey&&P(e);break;case`ArrowUp`:P(e);break;case`Home`:e.preventDefault(),A(0);break;case`End`:e.preventDefault(),ie();break;case`Enter`:{e.preventDefault();let t=D();if(t){let e=new Event(ht);t.dispatchEvent(e)}}}}},$.createElement(`label`,{"cmdk-label":``,htmlFor:T.inputId,id:T.labelId,style:Ut},c),Ht(e,e=>$.createElement(bt.Provider,{value:w},$.createElement(vt.Provider,{value:T},e))))}),wt=$.forwardRef((e,t)=>{let n=y(),r=$.useRef(null),i=$.useContext(St),a=yt(),o=Ft(e),s=o.current?.forceMount??i?.forceMount;It(()=>{if(!s)return a.item(n,i?.id)},[s]);let c=zt(n,r,[e.value,e.children,r],e.keywords),l=xt(),u=Rt(e=>e.value&&e.value===c.current),d=Rt(e=>s||a.filter()===!1?!0:e.search?e.filtered.items.get(n)>0:!0);$.useEffect(()=>{let t=r.current;if(!(!t||e.disabled))return t.addEventListener(ht,f),()=>t.removeEventListener(ht,f)},[d,e.onSelect,e.disabled]);function f(){var e,t;m(),(t=(e=o.current).onSelect)==null||t.call(e,c.current)}function m(){l.setState(`value`,c.current,!0)}if(!d)return null;let{disabled:h,value:g,onSelect:_,forceMount:v,keywords:b,...x}=e;return $.createElement(O.div,{ref:p(r,t),...x,id:n,"cmdk-item":``,role:`option`,"aria-disabled":!!h,"aria-selected":!!u,"data-disabled":!!h,"data-selected":!!u,onPointerMove:h||a.getDisablePointerSelection()?void 0:m,onClick:h?void 0:f},e.children)}),Tt=$.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:i,...a}=e,o=y(),s=$.useRef(null),c=$.useRef(null),l=y(),u=yt(),d=Rt(e=>i||u.filter()===!1?!0:e.search?e.filtered.groups.has(o):!0);It(()=>u.group(o),[]),zt(o,s,[e.value,e.heading,c]);let f=$.useMemo(()=>({id:o,forceMount:i}),[i]);return $.createElement(O.div,{ref:p(s,t),...a,"cmdk-group":``,role:`presentation`,hidden:d?void 0:!0},n&&$.createElement(`div`,{ref:c,"cmdk-group-heading":``,"aria-hidden":!0,id:l},n),Ht(e,e=>$.createElement(`div`,{"cmdk-group-items":``,role:`group`,"aria-labelledby":n?l:void 0},$.createElement(St.Provider,{value:f},e))))}),Et=$.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,i=$.useRef(null),a=Rt(e=>!e.search);return!n&&!a?null:$.createElement(O.div,{ref:p(i,t),...r,"cmdk-separator":``,role:`separator`})}),Dt=$.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,i=e.value!=null,a=xt(),o=Rt(e=>e.search),s=Rt(e=>e.selectedItemId),c=yt();return $.useEffect(()=>{e.value!=null&&a.setState(`search`,e.value)},[e.value]),$.createElement(O.input,{ref:t,...r,"cmdk-input":``,autoComplete:`off`,autoCorrect:`off`,spellCheck:!1,"aria-autocomplete":`list`,role:`combobox`,"aria-expanded":!0,"aria-controls":c.listId,"aria-labelledby":c.labelId,"aria-activedescendant":s,id:c.inputId,type:`text`,value:i?e.value:o,onChange:e=>{i||a.setState(`search`,e.target.value),n?.(e.target.value)}})}),Ot=$.forwardRef((e,t)=>{let{children:n,label:r=`Suggestions`,...i}=e,a=$.useRef(null),o=$.useRef(null),s=Rt(e=>e.selectedItemId),c=yt();return $.useEffect(()=>{if(o.current&&a.current){let e=o.current,t=a.current,n,r=new ResizeObserver(()=>{n=requestAnimationFrame(()=>{let n=e.offsetHeight;t.style.setProperty(`--cmdk-list-height`,n.toFixed(1)+`px`)})});return r.observe(e),()=>{cancelAnimationFrame(n),r.unobserve(e)}}},[]),$.createElement(O.div,{ref:p(a,t),...i,"cmdk-list":``,role:`listbox`,tabIndex:-1,"aria-activedescendant":s,"aria-label":r,id:c.listId},Ht(e,e=>$.createElement(`div`,{ref:p(o,c.listInnerRef),"cmdk-list-sizer":``},e)))}),kt=$.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:a,container:o,...s}=e;return $.createElement(b,{open:n,onOpenChange:r},$.createElement(f,{container:o},$.createElement(A,{"cmdk-overlay":``,className:i}),$.createElement(h,{"aria-label":e.label,"cmdk-dialog":``,className:a},$.createElement(Ct,{ref:t,...s}))))}),At=$.forwardRef((e,t)=>Rt(e=>e.filtered.count===0)?$.createElement(O.div,{ref:t,...e,"cmdk-empty":``,role:`presentation`}):null),jt=$.forwardRef((e,t)=>{let{progress:n,children:r,label:i=`Loading...`,...a}=e;return $.createElement(O.div,{ref:t,...a,"cmdk-loading":``,role:`progressbar`,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i},Ht(e,e=>$.createElement(`div`,{"aria-hidden":!0},e)))}),Mt=Object.assign(Ct,{List:Ot,Item:wt,Input:Dt,Group:Tt,Separator:Et,Dialog:kt,Empty:At,Loading:jt});function Nt(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function Pt(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function Ft(e){let t=$.useRef(e);return It(()=>{t.current=e}),t}var It=typeof window>`u`?$.useEffect:$.useLayoutEffect;function Lt(e){let t=$.useRef();return t.current===void 0&&(t.current=e()),t}function Rt(e){let t=xt(),n=()=>e(t.snapshot());return $.useSyncExternalStore(t.subscribe,n,n)}function zt(e,t,n,r=[]){let i=$.useRef(),a=yt();return It(()=>{var o;let s=(()=>{for(let e of n){if(typeof e==`string`)return e.trim();if(typeof e==`object`&&`current`in e)return e.current?e.current.textContent?.trim():i.current}})(),c=r.map(e=>e.trim());a.value(e,s,c),(o=t.current)==null||o.setAttribute(gt,s),i.current=s}),i}var Bt=()=>{let[e,t]=$.useState(),n=Lt(()=>new Map);return It(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function Vt(e){let t=e.type;return typeof t==`function`?t(e.props):`render`in t?t.render(e.props):e}function Ht({asChild:e,children:t},n){return e&&$.isValidElement(t)?$.cloneElement(Vt(t),{ref:t.ref},n(t.props.children)):n(t)}var Ut={position:`absolute`,width:`1px`,height:`1px`,padding:`0`,margin:`-1px`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,borderWidth:`0`};function Wt({className:e,...t}){return(0,Q.jsx)(Mt,{"data-slot":`command`,className:U(`flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground`,e),...t})}function Gt({className:e,...t}){return(0,Q.jsxs)(`div`,{"data-slot":`command-input-wrapper`,className:`flex h-9 items-center gap-2 border-b px-3`,children:[(0,Q.jsx)(E,{className:`size-4 shrink-0 opacity-50`}),(0,Q.jsx)(Mt.Input,{"data-slot":`command-input`,className:U(`flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50`,e),...t})]})}function Kt({className:e,...t}){return(0,Q.jsx)(Mt.List,{"data-slot":`command-list`,className:U(`max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto`,e),...t})}function qt({...e}){return(0,Q.jsx)(Mt.Empty,{"data-slot":`command-empty`,className:`py-6 text-center text-sm`,...e})}function Jt({className:e,...t}){return(0,Q.jsx)(Mt.Group,{"data-slot":`command-group`,className:U(`overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground`,e),...t})}function Yt({className:e,...t}){return(0,Q.jsx)(Mt.Item,{"data-slot":`command-item`,className:U(`relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground`,e),...t})}function Xt({roles:e,loadingRoles:t,selectedRoleName:n,onRoleNameChange:r,className:i}){let a=(0,$.useMemo)(()=>e.find(e=>e.name===n)??null,[e,n]),o=!!n&&!t&&!a;return(0,Q.jsxs)(`div`,{className:U(`grid min-h-0 gap-3 md:grid-cols-[minmax(0,1fr)_16rem]`,i),children:[(0,Q.jsxs)(Wt,{className:`min-h-[17rem] rounded-xl border border-border bg-background/35`,children:[(0,Q.jsx)(Gt,{"aria-label":`Search roles`,placeholder:`Search roles...`,disabled:t||e.length===0}),(0,Q.jsx)(Kt,{className:`max-h-[18rem]`,children:t?(0,Q.jsx)(`div`,{className:`px-3 py-6 text-center text-sm text-muted-foreground`,children:`Loading roles...`}):e.length===0?(0,Q.jsx)(`div`,{className:`px-3 py-6 text-center text-sm text-muted-foreground`,children:`No roles available.`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(qt,{children:`No matching roles.`}),(0,Q.jsx)(Jt,{heading:`Roles`,children:e.map(e=>{let t=n===e.name;return(0,Q.jsxs)(Yt,{value:`${e.name} ${e.description}`,onSelect:()=>r(e.name),className:U(`items-start gap-3 rounded-md px-3 py-2.5`,t&&`bg-accent/60 text-accent-foreground`),children:[(0,Q.jsx)(`span`,{className:U(`mt-0.5 flex size-5 shrink-0 items-center justify-center rounded-full border`,t?`border-primary bg-primary text-primary-foreground`:`border-border text-transparent`),children:(0,Q.jsx)(w,{className:`size-3`})}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block truncate text-[13px] font-medium text-foreground`,children:e.name}),(0,Q.jsx)(`span`,{className:`mt-1 line-clamp-2 block text-[12px] leading-relaxed text-muted-foreground`,children:e.description})]})]},e.name)})})]})})]}),(0,Q.jsxs)(`div`,{className:`min-h-[10rem] rounded-xl border border-border bg-card/35 p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-[12px] font-medium text-muted-foreground`,children:[(0,Q.jsx)(S,{className:`size-4`}),`Selected role`]}),a?(0,Q.jsxs)(`div`,{className:`mt-4 min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(`p`,{className:`truncate text-[15px] font-semibold text-foreground`,children:a.name}),a.is_builtin?(0,Q.jsx)(R,{variant:`outline`,className:`h-5 shrink-0`,children:`Built-in`}):null]}),(0,Q.jsx)(`p`,{className:`mt-2 line-clamp-5 text-[12px] leading-relaxed text-muted-foreground`,children:a.description})]}):(0,Q.jsx)(`p`,{className:`mt-4 text-[13px] leading-relaxed text-muted-foreground`,children:o?`Selected role is not available.`:`Choose a role to continue.`})]})]})}var Zt=`bg-background/40 text-foreground shadow-xs placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50`;function Qt({allowNetwork:e,onAllowNetworkChange:t,onOpenChange:n,onSubmit:r,onTitleChange:i,onWriteDirsChange:a,open:o,pending:s,title:c,writeDirs:l}){return(0,Q.jsxs)(Ke,{open:o,onOpenChange:n,title:`Create Workflow`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(K,{variant:`outline`,onClick:()=>n(!1),disabled:s,children:`Cancel`}),(0,Q.jsx)(K,{onClick:r,disabled:!c.trim()||s,children:s?`Creating...`:`Create Workflow`})]}),children:[(0,Q.jsx)(qe,{label:`Title`,hint:`Shown in the workflow strip`,children:(0,Q.jsx)(xe,{autoFocus:!0,"aria-label":`Workflow title`,value:c,onChange:e=>i(e.target.value),placeholder:`Release checklist`,className:U(`h-10 rounded-md`,Zt)})}),(0,Q.jsx)(qe,{label:`Network Access`,hint:`Allow this workflow to reach external services`,children:(0,Q.jsx)(De,{checked:e,label:`Network Access`,onCheckedChange:t})}),(0,Q.jsx)(qe,{label:`Writable Folders`,hint:`One absolute folder path per line`,children:(0,Q.jsx)(ge,{value:l,"aria-label":`Writable folders`,onChange:e=>a(e.target.value),placeholder:`/workspace/output
2
+ /workspace/cache`,className:U(`min-h-[80px] rounded-md font-mono text-[13px]`,Zt)})})]})}var $t={agent:`Agent`,trigger:`Trigger`,llm:`Model`,code:`Code`,if:`If`,merge:`Merge`};function en({activeTabTitle:e,nodeName:t,nodeType:n,roles:r,loadingRoles:i,onNodeNameChange:a,onNodeTypeChange:o,onOpenChange:s,onRoleNameChange:c,onSubmit:l,open:u,pending:d,selectedRoleName:f,submitDisabled:p}){return(0,Q.jsxs)(Ke,{open:u,onOpenChange:s,title:`Add Node`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(K,{variant:`outline`,onClick:()=>s(!1),disabled:d,children:`Cancel`}),(0,Q.jsx)(K,{onClick:l,disabled:p,children:d?`Adding...`:`Add Node`})]}),children:[(0,Q.jsxs)(Je,{children:[`Adding a node to`,` `,(0,Q.jsx)(`span`,{className:`font-semibold text-foreground`,children:e??`No active workflow`})]}),(0,Q.jsx)(qe,{label:`Node Type`,hint:`Required`,children:(0,Q.jsxs)(Be,{value:n,onValueChange:e=>o(e),children:[(0,Q.jsx)(ze,{"aria-label":`Node Type`,className:U(`h-10 rounded-md data-[placeholder]:text-muted-foreground`,Zt),children:(0,Q.jsx)(Re,{placeholder:`Choose node type`})}),(0,Q.jsx)(J,{className:`rounded-md border-border bg-popover text-popover-foreground`,children:Object.entries($t).map(([e,t])=>(0,Q.jsx)(Y,{value:e,children:t},e))})]})}),n===`agent`?(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium text-foreground/80`,children:`Role`}),(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Required`})]}),(0,Q.jsx)(Xt,{roles:r,loadingRoles:i,selectedRoleName:f,onRoleNameChange:c})]}):null,(0,Q.jsx)(qe,{label:`Display Name`,hint:`Optional`,children:(0,Q.jsx)(xe,{value:t,"aria-label":`Node display name`,onChange:e=>a(e.target.value),placeholder:n===`agent`?`Docs Worker`:`${$t[n]} Node`,className:U(`h-10 rounded-md`,Zt)})})]})}function tn({activeTabTitle:e,nodeOptions:t,onFromNodeChange:n,onFromPortChange:r,onOpenChange:i,onSubmit:a,onToNodeChange:o,onToPortChange:s,open:c,pending:l,fromNodeId:u,fromPortKey:d,toNodeId:f,toPortKey:p,fromPortOptions:m,toPortOptions:h}){return(0,Q.jsxs)(Ke,{open:c,onOpenChange:i,title:`Connect Ports`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(K,{variant:`outline`,onClick:()=>i(!1),disabled:l,children:`Cancel`}),(0,Q.jsx)(K,{onClick:a,disabled:!u||!d||!f||!p||l,children:l?`Connecting...`:`Create Edge`})]}),children:[(0,Q.jsx)(Je,{children:e?(0,Q.jsxs)(Q.Fragment,{children:[`Workflow`,` `,(0,Q.jsx)(`span`,{className:`font-semibold text-foreground`,children:e}),` `,`· `,t.length,` nodes available`]}):`No active workflow`}),(0,Q.jsx)(qe,{label:`From Node`,hint:`Source node`,children:(0,Q.jsxs)(Be,{value:u,onValueChange:n,children:[(0,Q.jsx)(ze,{"aria-label":`From Node`,className:U(`h-10 rounded-md data-[placeholder]:text-muted-foreground`,Zt),children:(0,Q.jsx)(Re,{placeholder:`Choose source node`})}),(0,Q.jsx)(J,{className:`rounded-md border-border bg-popover text-popover-foreground`,children:t.map(e=>(0,Q.jsx)(Y,{value:e.id,children:e.label},e.id))})]})}),(0,Q.jsx)(qe,{label:`From Port`,hint:`Output port`,children:(0,Q.jsxs)(Be,{value:d,onValueChange:r,children:[(0,Q.jsx)(ze,{"aria-label":`From Port`,className:U(`h-10 rounded-md data-[placeholder]:text-muted-foreground`,Zt),children:(0,Q.jsx)(Re,{placeholder:`Choose output port`})}),(0,Q.jsx)(J,{className:`rounded-md border-border bg-popover text-popover-foreground`,children:m.map(e=>(0,Q.jsx)(Y,{value:e.key,children:e.label},e.key))})]})}),(0,Q.jsx)(qe,{label:`To Node`,hint:`Target node`,children:(0,Q.jsxs)(Be,{value:f,onValueChange:o,children:[(0,Q.jsx)(ze,{"aria-label":`To Node`,className:U(`h-10 rounded-md data-[placeholder]:text-muted-foreground`,Zt),children:(0,Q.jsx)(Re,{placeholder:`Choose target node`})}),(0,Q.jsx)(J,{className:`rounded-md border-border bg-popover text-popover-foreground`,children:t.filter(e=>e.id!==u).map(e=>(0,Q.jsx)(Y,{value:e.id,children:e.label},e.id))})]})}),(0,Q.jsx)(qe,{label:`To Port`,hint:`Input port`,children:(0,Q.jsxs)(Be,{value:p,onValueChange:s,children:[(0,Q.jsx)(ze,{"aria-label":`To Port`,className:U(`h-10 rounded-md data-[placeholder]:text-muted-foreground`,Zt),children:(0,Q.jsx)(Re,{placeholder:`Choose input port`})}),(0,Q.jsx)(J,{className:`rounded-md border-border bg-popover text-popover-foreground`,children:h.map(e=>(0,Q.jsx)(Y,{value:e.key,children:e.label},e.key))})]})})]})}function nn({onDelete:e,onOpenChange:t,open:n,pending:r,target:i}){return(0,Q.jsx)(Le,{open:n,onOpenChange:t,children:(0,Q.jsxs)(Ne,{className:`max-w-[30rem]`,children:[(0,Q.jsxs)(Ie,{className:`gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(`div`,{className:`flex size-11 items-center justify-center rounded-xl border border-border bg-accent/45 text-foreground shadow-xs`,children:(0,Q.jsx)(T,{className:`size-5`})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-[10px] font-semibold text-muted-foreground`,children:`Destructive Action`}),(0,Q.jsx)(Me,{className:`mt-1 text-foreground`,children:`Delete workflow?`})]})]}),(0,Q.jsx)(je,{className:`text-muted-foreground`,children:i?(0,Q.jsxs)(Q.Fragment,{children:[`Remove`,` `,(0,Q.jsx)(`span`,{className:`font-semibold text-foreground`,children:i.title}),` `,`and clean up its persisted workflow graph.`,typeof i.nodeCount==`number`?` ${i.nodeCount} node${i.nodeCount===1?``:`s`} will be removed with it.`:``]}):`This action cannot be undone.`})]}),(0,Q.jsxs)(Pe,{children:[(0,Q.jsx)(Fe,{asChild:!0,children:(0,Q.jsx)(K,{variant:`outline`,children:`Cancel`})}),(0,Q.jsx)(q,{asChild:!0,children:(0,Q.jsx)(K,{variant:`destructive`,onClick:e,disabled:r,children:r?`Deleting...`:`Delete Workflow`})})]})]})})}var rn=(0,$.memo)(function(e){let{sourceX:t,sourceY:n,targetX:r,targetY:i,sourcePosition:o,targetPosition:s,id:l,data:u}=e,[d]=c({sourceX:t,sourceY:n,sourcePosition:o,targetX:r,targetY:i,targetPosition:s}),f=u??{},p=!!f.active,m=!!f.leaving,h=f.flowDirection===`reverse`?-1:1,g=f.selected===!0,_=h===1?`48`:`0`,v=h===1?`0`:`48`;return(0,Q.jsxs)(C.g,{className:`agent-graph-edge-shell`,initial:{opacity:0},animate:{opacity:+!m},transition:{duration:m?.2:.3,ease:`easeInOut`},children:[(0,Q.jsx)(a,{id:l,path:d,style:{stroke:p?`var(--graph-edge-active)`:g?`var(--graph-selection)`:`var(--graph-edge)`,strokeWidth:p?2.5:g?2.4:1.5,transition:`stroke 300ms ease, stroke-width 300ms ease, opacity 300ms ease`}}),g&&!p?(0,Q.jsx)(C.path,{d,fill:`none`,stroke:`var(--graph-selection)`,strokeWidth:`7`,strokeLinecap:`round`,filter:`url(#agent-graph-edge-glow)`,initial:{opacity:0},animate:{opacity:.16},transition:{duration:.18}}):null,p&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(C.path,{d,fill:`none`,stroke:`var(--graph-edge-active)`,strokeWidth:`8`,strokeLinecap:`round`,filter:`url(#agent-graph-edge-glow)`,initial:{opacity:0},animate:{opacity:[.1,.3,.1]},transition:{duration:2,repeat:1/0,ease:`easeInOut`}}),(0,Q.jsx)(C.path,{d,fill:`none`,stroke:`url(#agent-graph-edge-flow)`,strokeWidth:`3.5`,strokeLinecap:`round`,strokeDasharray:`12 12`,opacity:`0.8`,filter:`url(#agent-graph-edge-glow)`,initial:{opacity:0},animate:{opacity:.8},transition:{duration:.4},children:(0,Q.jsx)(`animate`,{attributeName:`stroke-dashoffset`,from:_,to:v,dur:`0.8s`,repeatCount:`indefinite`})}),(0,Q.jsx)(C.path,{d,fill:`none`,stroke:`var(--graph-edge-active)`,strokeWidth:`5`,strokeLinecap:`round`,filter:`url(#agent-graph-edge-glow)`,initial:{pathLength:.15,pathOffset:h===1?-.2:1.2,opacity:0},animate:{pathOffset:h===1?1.2:-.2,opacity:[0,1,1,0]},transition:{duration:1.5,ease:`easeInOut`,repeat:1/0,repeatType:`loop`,times:[0,.1,.9,1]}}),(0,Q.jsx)(C.path,{d,fill:`none`,stroke:`var(--graph-attention)`,strokeWidth:`2.5`,strokeLinecap:`round`,filter:`url(#agent-graph-edge-glow)`,initial:{pathLength:.08,pathOffset:h===1?-.23:1.23,opacity:0},animate:{pathOffset:h===1?1.17:-.17,opacity:[0,.9,.9,0]},transition:{duration:1.5,ease:`easeInOut`,repeat:1/0,repeatType:`loop`,times:[0,.1,.9,1],delay:.03}})]})]})}),an=.3,on=.05,sn=`rounded-md border border-border bg-popover px-3 py-1 text-[11px] font-medium text-popover-foreground shadow-sm`,cn=`__node-body-source`,ln=`__node-body-target`;function un(e){return e.kind===`standalone`?`Add Agent`:e.kind===`between`?`Insert Agent Between`:`Add Agent After`}function dn(e){if(`clientX`in e)return{x:e.clientX,y:e.clientY};let t=e.changedTouches[0]??e.touches[0];return t?{x:t.clientX,y:t.clientY}:null}var fn={running:`border-graph-status-running/28`,idle:`border-graph-node-border`,sleeping:`border-graph-status-sleeping/26`,initializing:`border-border border-dashed`,error:`border-graph-status-error/28 border-double`,terminated:`border-border/70`};function pn(e,t=!1){return e===`assistant`?`rounded-sm border-graph-node-border bg-accent/60 text-foreground`:U(`rounded-sm border-graph-node-border bg-surface-3`,t?`text-primary`:`text-foreground/80`)}var mn=(0,$.memo)(function({data:e}){let{label:t,node_type:n,is_leader:r,state:i,latestTodo:a,selected:c,toolCall:l,canConnect:u,showConnectionEntryHint:d,connectionState:f,inputPorts:p,outputPorts:m}=e,h=!!e.leaving,g=F[n],_=(0,$.useRef)(null),v=(e,t)=>{if(!_.current)return;let n=_.current.getBoundingClientRect(),r=n.left+n.width/2,i=n.top+n.height/2,a=e-r,o=t-i,s=Math.sqrt(a*a+o*o),c=Math.max(0,1-s/240),l=Math.atan2(o,a)*180/Math.PI+90;_.current.style.setProperty(`--mouse-angle`,`${l}deg`),_.current.style.setProperty(`--mouse-intensity`,c.toString())},y=()=>{_.current&&(_.current.style.setProperty(`--mouse-angle`,`135deg`),_.current.style.setProperty(`--mouse-intensity`,`0`))},b=!!l,x=i===`running`,S=b?`border-graph-attention/70`:fn[i],w=c?`ring-1 ring-graph-selection/25 border-graph-selection/80`:U(S,`hover:border-graph-node-border-hover`),T=f===`source`?`ring-2 ring-graph-selection/35 border-graph-selection/90`:f===`valid-target`?`border-graph-selection/55 shadow-[0_0_0_1px_var(--graph-glow)]`:f===`invalid-target`?`opacity-45`:``,ee=d||f===`source`,te=u&&f===null,E=u&&(f===`valid-target`||f===`invalid-target`),ne=f===`source`?`border-graph-selection/75 bg-graph-selection/14 shadow-[0_0_0_1px_var(--graph-glow),0_0_24px_var(--graph-glow)]`:f===`valid-target`?`border-graph-selection/45 bg-graph-selection/10 shadow-[0_0_0_1px_var(--graph-glow),0_0_18px_var(--graph-glow)]`:f===`invalid-target`?`border-graph-node-border bg-graph-node-bg/50`:`border-graph-node-border bg-graph-node-bg/72`;return(0,Q.jsxs)(C.div,{ref:_,initial:{opacity:0,scale:.92,filter:`blur(6px) grayscale(0%)`},animate:{opacity:h?0:i===`terminated`?.4:1,scale:h?.9:1,y:h?8:0,filter:h?`blur(8px) grayscale(100%)`:i===`terminated`?`blur(0px) grayscale(100%)`:`blur(0px) grayscale(0%)`},transition:{duration:h?.28:.35,ease:[.23,1,.32,1]},onMouseEnter:e=>v(e.clientX,e.clientY),onMouseMove:e=>v(e.clientX,e.clientY),onMouseLeave:y,className:U(`relative isolate flex h-14 w-max min-w-[100px] max-w-[300px] items-center gap-2 overflow-visible rounded-[10px] border px-2.5 py-2.5`,`shadow-[0_10px_24px_var(--shell-scrim)]`,`bg-graph-node-bg`,`transition-[border-color] duration-300`,h&&`pointer-events-none`,w,T),style:{"--mouse-angle":`135deg`,"--mouse-intensity":`0`},children:[(0,Q.jsx)(`div`,{"aria-hidden":`true`,className:U(`agent-state-ring`,N[i])}),(0,Q.jsx)(`div`,{"aria-hidden":`true`,className:U(`agent-loading-border`,x&&`agent-loading-border-active`)}),p.map((e,t)=>(0,Q.jsx)(s,{id:e.key,type:`target`,position:o.Left,isConnectable:u,isConnectableEnd:u,className:U(`!z-10 !h-[72%] !w-5 !-translate-y-1/2 !border-0 !bg-transparent !opacity-0 after:absolute after:-inset-3 after:content-['']`),style:{top:`${(t+1)*100/(p.length+1)}%`}},`input-${e.key}`)),m.map((e,t)=>(0,Q.jsx)(s,{id:e.key,type:`source`,position:o.Right,isConnectable:u,isConnectableStart:u,className:U(`!z-10 !h-[72%] !w-5 !-translate-y-1/2 !border-0 !bg-transparent !opacity-0 after:absolute after:-inset-3 after:content-['']`),style:{top:`${(t+1)*100/(m.length+1)}%`}},`output-${e.key}`)),(0,Q.jsx)(s,{id:cn,type:`source`,position:o.Right,isConnectable:u,isConnectableStart:u,isConnectableEnd:!1,className:U(`!absolute !h-full !w-full !border-0 !bg-transparent !opacity-0`,te?`!z-30 !pointer-events-auto`:`!z-0 !pointer-events-none`),style:{left:0,top:0,right:`auto`,bottom:`auto`,transform:`none`}}),(0,Q.jsx)(s,{id:ln,type:`target`,position:o.Left,isConnectable:u,isConnectableStart:!1,isConnectableEnd:u,className:U(`!absolute !h-full !w-full !border-0 !bg-transparent !opacity-0`,E?`!z-30 !pointer-events-auto`:`!z-0 !pointer-events-none`),style:{left:0,top:0,right:`auto`,bottom:`auto`,transform:`none`}}),ee?[(0,Q.jsx)(`div`,{"aria-hidden":`true`,"data-testid":`connection-entry-left`,className:U(`pointer-events-none absolute top-1/2 z-10 h-[72%] w-2.5 -translate-y-1/2 rounded-full border transition-[opacity,transform,box-shadow] duration-150`,`-left-1.5`,ne)},`left-entry`),(0,Q.jsx)(`div`,{"aria-hidden":`true`,"data-testid":`connection-entry-right`,className:U(`pointer-events-none absolute top-1/2 z-10 h-[72%] w-2.5 -translate-y-1/2 rounded-full border transition-[opacity,transform,box-shadow] duration-150`,`-right-1.5`,ne)},`right-entry`)]:null,(0,Q.jsx)(`div`,{className:U(`relative z-10 flex size-8 shrink-0 items-center justify-center border`,pn(n,r)),children:(0,Q.jsx)(g,{className:`size-4.5`})}),(0,Q.jsxs)(`div`,{className:`relative z-10 flex min-w-0 flex-1 items-center justify-between gap-2`,children:[(0,Q.jsx)(`span`,{className:`truncate text-[13px] font-semibold text-foreground -translate-y-[0.7px]`,title:a??void 0,children:t}),(0,Q.jsx)(`div`,{className:`relative flex items-center pr-0.5`,title:b?`Active`:i,children:(0,Q.jsxs)(`span`,{className:`relative flex size-2.5`,children:[(x||b)&&(0,Q.jsx)(`span`,{className:U(`absolute inline-flex size-full animate-ping rounded-full opacity-40`,b?`bg-graph-attention`:ce[i])}),(0,Q.jsx)(`span`,{className:U(`relative inline-flex size-2.5 rounded-full border border-card shadow-sm`,b?`bg-graph-attention`:ce[i])})]})})]}),b&&(0,Q.jsx)(C.div,{initial:{opacity:0,y:5},animate:{opacity:1,y:0},className:`absolute -bottom-6 left-1/2 z-20 -translate-x-1/2 whitespace-nowrap`,children:(0,Q.jsx)(`span`,{className:`rounded-sm border border-graph-attention/24 bg-surface-2/92 px-1.5 py-0.5 text-[9px] font-mono text-graph-attention-text shadow-lg backdrop-blur-sm`,children:l})})]})}),hn=e(u(),1);function gn({children:e}){return typeof document>`u`||!document.body?null:(0,hn.createPortal)(e,document.body)}function _n({x:e,y:t,items:n,onClose:r}){let i=(0,$.useRef)(null),[a,o]=(0,$.useState)(()=>({left:e,top:t}));return(0,$.useEffect)(()=>{let n=i.current;if(!n)return;let r=requestAnimationFrame(()=>{let r=n.getBoundingClientRect(),i=window.innerWidth-8-r.width,a=window.innerHeight-8-r.height,s=Math.max(8,Math.min(e,i)),c=Math.max(8,Math.min(t,a));o(e=>e.left===s&&e.top===c?e:{left:s,top:c})});return()=>cancelAnimationFrame(r)},[e,t,n.length]),(0,$.useEffect)(()=>{let e=e=>{i.current&&!i.current.contains(e.target)&&r()};return document.addEventListener(`mousedown`,e,!0),()=>document.removeEventListener(`mousedown`,e,!0)},[r]),(0,$.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r()};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[r]),n.length===0?null:(0,Q.jsx)(gn,{children:(0,Q.jsx)(C.div,{ref:i,initial:{opacity:0,scale:.96,y:-4},animate:{opacity:1,scale:1,y:0},transition:{duration:.12,ease:`easeOut`},className:`fixed z-[200] min-w-[160px] rounded-md border border-border bg-popover py-1 shadow-md`,style:{left:a.left,top:a.top},children:n.map((e,t)=>e===`divider`?(0,Q.jsx)(`div`,{className:`my-1 border-t border-border`},t):(0,Q.jsx)(K,{type:`button`,variant:`ghost`,disabled:e.disabled,onClick:()=>{e.disabled||(e.onClick(),r())},className:`h-auto w-full justify-start rounded-none px-3 py-1.5 text-left text-[11px] hover:text-inherit disabled:opacity-40 ${e.danger?`text-graph-status-error/90 hover:bg-destructive/10 hover:text-graph-status-error`:`text-popover-foreground/90 hover:bg-accent/30 hover:text-popover-foreground`}`,children:e.label},t))})})}var vn=/^[il1.,!|:;]$/,yn=/^[fjrt\-[\]()]$/,bn=/^[wmMWOQ@]$/,xn=/^[A-Z]$/;function Sn(e){let t=Array.from(e).reduce((e,t)=>t===` `?e+4:t.charCodeAt(0)>255?e+13:vn.test(t)?e+4:yn.test(t)?e+5.5:bn.test(t)?e+10.5:xn.test(t)?e+8.5:e+7,0);return Math.max(100,Math.min(300,t+76))}function Cn(e){return!e||e===`__node-body-source`}function wn(e){return!e||e===`__node-body-target`}function Tn(e){return e instanceof Element?e.closest(`.react-flow__node`)?.getAttribute(`data-id`)??null:null}function En(e){return e instanceof Element&&!!e.closest(`.react-flow__pane`)}function Dn(e){if(typeof document>`u`||typeof document.elementFromPoint!=`function`)return null;let t=dn(e);return t?document.elementFromPoint(t.x,t.y):null}function On(e){return`${e.key} · ${e.type}`}function kn(e,t){let[n,r]=(0,$.useState)(e),[i,a]=(0,$.useState)(t),o=(0,$.useRef)(new Map),s=(0,$.useRef)(new Map);return(0,$.useEffect)(()=>{r(t=>{let n=new Set(e.map(e=>e.id)),i=new Map(t.map(e=>[e.id,e])),a=e.map(e=>{let t=o.current.get(e.id);t&&(clearTimeout(t),o.current.delete(e.id));let n=i.get(e.id);return{...n,...e,className:U(e.className,`agent-graph-node-present`),data:{...n?.data??{},...e.data??{},leaving:!1}}});for(let e of t)if(!n.has(e.id)){if(!o.current.has(e.id)){let t=setTimeout(()=>{r(t=>t.filter(t=>t.id!==e.id)),o.current.delete(e.id)},320);o.current.set(e.id,t)}a.push({...e,className:U(e.className,`agent-graph-node-leaving`),data:{...e.data??{},leaving:!0}})}return a})},[e]),(0,$.useEffect)(()=>{a(e=>{let n=new Set;for(let e=0;e<t.length;e++)n.add(t[e].id);let r=new Map;for(let t=0;t<e.length;t++)r.set(e[t].id,e[t]);let i=t.map(e=>{let t=s.current.get(e.id);t&&(clearTimeout(t),s.current.delete(e.id));let n=r.get(e.id);return{...n,...e,data:{...n?.data??{},...e.data??{},leaving:!1}}});for(let t of e)if(!n.has(t.id)){if(!s.current.has(t.id)){let e=setTimeout(()=>{a(e=>e.filter(e=>e.id!==t.id)),s.current.delete(t.id)},220);s.current.set(t.id,e)}i.push({...t,data:{...t.data??{},leaving:!0}})}return i})},[t]),(0,$.useEffect)(()=>{let e=o.current,t=s.current;return()=>{for(let t of e.values())clearTimeout(t);for(let e of t.values())clearTimeout(e)}},[]),{nodes:n,edges:i}}function An({roles:e=[],loadingRoles:t=!1,onConnectModeChange:n,onCreateConnection:r=async()=>void 0,onDeleteConnection:i=async()=>void 0,onCreateStandaloneAgent:a=async()=>void 0,onCreateLinkedAgent:o=async()=>void 0,onDeleteAgent:s=async()=>void 0,onInsertAgentBetween:c=async()=>void 0,readOnly:l=!1}){let{agents:u}=ye(),{tabs:d}=he(),{activeToolCalls:f}=we(),{activeTabId:p,selectedAgentId:m,selectAgent:h}=ke(),[g,_]=(0,$.useState)(null),[v,y]=(0,$.useState)(null),[b,x]=(0,$.useState)(null),[S,C]=(0,$.useState)(``),[w,T]=(0,$.useState)(``),[ee,te]=(0,$.useState)(!1),[E,ne]=(0,$.useState)(null),[re,O]=(0,$.useState)(1),[k,A]=(0,$.useState)(null),[j,M]=(0,$.useState)(!1),[N,P]=(0,$.useState)(null),[ae,F]=(0,$.useState)(null),[I,L]=(0,$.useState)(null),[R,oe]=(0,$.useState)(!1),z=(0,$.useRef)(null),se=(0,$.useRef)(!1),ce=(0,$.useRef)(!1),B=(0,$.useRef)(null),V=(0,$.useRef)(``),le=(0,$.useRef)(new Map),[ue,de]=(0,$.useState)(0),[H,fe]=(0,$.useState)({key:``,positions:new Map}),pe=(0,$.useRef)(null),me=(0,$.useRef)(null),ge=(0,$.useRef)(null),[_e,ve]=(0,$.useState)(null),U=p?d.get(p)??null:null,be=(0,$.useMemo)(()=>U?.definition.nodes??[],[U?.definition.nodes]),W=(0,$.useMemo)(()=>U?.definition.edges??[],[U?.definition.edges]),G=(0,$.useMemo)(()=>new Map(be.map(e=>[e.id,e])),[be]),xe=(0,$.useCallback)((e,t,n)=>{V.current=``,console.error(t,n);let r=le.current.get(e)??0;r>=1||(le.current.set(e,r+1),de(e=>e+1))},[]);(0,$.useEffect)(()=>{let e=new Worker(new URL(`/assets/layout.worker-jMHqAFbP.js`,``+import.meta.url),{type:`module`}),t=le.current;return e.onerror=e=>{let t=V.current;t&&xe(t,`AgentGraph layout worker error`,e)},e.onmessageerror=e=>{let t=V.current;t&&xe(t,`AgentGraph layout worker message error`,e)},e.onmessage=e=>{let{positions:t,key:n,error:r}=e.data;if(n!==V.current)return;if(r||!t){xe(n,`AgentGraph layout worker rejected request`,r);return}le.current.delete(n);let i=new Map;for(let e of t)i.set(e.id,e.position);fe({key:n,positions:i})},B.current=e,()=>{V.current=``,t.clear(),B.current=null,e.terminate()}},[xe]),(0,$.useEffect)(()=>{n?.(j)},[j,n]),(0,$.useEffect)(()=>{l&&(M(!1),P(null),F(null),L(null),oe(!1),x(null),y(null))},[l]);let Se=(0,$.useCallback)(e=>{!Number.isFinite(e)||e<=0||O(e)},[]),Ce=(0,$.useCallback)(e=>{e&&Se(e.getZoom())},[Se]),Te=(0,$.useCallback)(async e=>{if(!E)return!1;try{let t=await E.fitView(e);return Ce(E),t}catch{return!1}},[E,Ce]),Ee=(0,$.useCallback)(e=>{ne(e),Ce(e)},[Ce]),De=(0,$.useCallback)((e,t)=>{Se(t.zoom)},[Se]),Oe=(0,$.useCallback)(()=>{l||M(e=>!e)},[l]),K=(0,$.useMemo)(()=>new Map(Array.from(u.entries())),[u]),Ae=(0,$.useCallback)(e=>{let t=G.get(e);return t?{id:t.id,node_type:t.type,tab_id:p,is_leader:!1,state:`idle`,connections:W.filter(e=>e.from_node_id===t.id).map(e=>e.to_node_id),name:typeof t.config.name==`string`?t.config.name:null,todos:[],role_name:typeof t.config.role_name==`string`?t.config.role_name:null,config:t.config,inputs:t.inputs,outputs:t.outputs}:null},[p,W,G]),je=(0,$.useCallback)(e=>K.get(e)??Ae(e),[Ae,K]),Me=(0,$.useMemo)(()=>be.flatMap(e=>{let t=K.get(e.id);if(t)return[t];let n=Ae(e.id);return n?[n]:[]}),[Ae,K,be]),Ne=(0,$.useCallback)(e=>{let t=G.get(e);return t?ie({name:typeof t.config.name==`string`?t.config.name:null,roleName:typeof t.config.role_name==`string`?t.config.role_name:null,nodeType:t.type,isLeader:!1}):e.slice(0,8)},[G]),q=(0,$.useCallback)((e,t,n={})=>{if(e===t)return[];let r=G.get(e),i=G.get(t);if(!r||!i)return[];let a=n.sourcePortKey?r.outputs.filter(e=>e.key===n.sourcePortKey):r.outputs,o=n.targetPortKey?i.inputs.filter(e=>e.key===n.targetPortKey):i.inputs,s=[];for(let n of a)for(let r of o)n.type===r.type&&(!r.multiple&&W.some(e=>e.to_node_id===t&&e.to_port_key===r.key)||W.some(i=>i.from_node_id===e&&i.from_port_key===n.key&&i.to_node_id===t&&i.to_port_key===r.key)||s.push({sourcePortKey:n.key,sourcePortLabel:On(n),targetPortKey:r.key,targetPortLabel:On(r),type:n.type}));return s},[W,G]),Pe=(0,$.useCallback)((e,t)=>q(e,t).length>0,[q]),Fe=ae??N,Ie=(0,$.useMemo)(()=>{let e=new Map;for(let t of be){let n=K.get(t.id)??null,r=ie({name:typeof t.config.name==`string`?t.config.name:null,roleName:typeof t.config.role_name==`string`?t.config.role_name:null,nodeType:t.type,isLeader:!1});e.set(t.id,{label:r,width:Sn(r),node_type:t.type,is_leader:!1,state:n?.state??`idle`,shortId:t.id.slice(0,8),name:typeof t.config.name==`string`?t.config.name:null,role_name:typeof t.config.role_name==`string`?t.config.role_name:null,latestTodo:n?.todos[n.todos.length-1]?.text??null,selected:t.id===m&&k===null,toolCall:n?f.get(t.id)??null:null,leaving:!1,canConnect:!!p&&!l,showConnectionEntryHint:j||!!Fe,connectionState:Fe===t.id?`source`:Fe?Pe(Fe,t.id)?`valid-target`:`invalid-target`:null,inputPorts:t.inputs,outputPorts:t.outputs})}return e},[p,f,Fe,j,Pe,l,K,m,k,be]),{rawNodes:Le,baseEdges:Re,structureKey:ze}=(0,$.useMemo)(()=>({rawNodes:be.flatMap(e=>{let t=Ie.get(e.id);return t?[{id:e.id,type:`agent`,position:{x:0,y:0},width:t.width,height:56,data:t,className:`agent-graph-node-shell`}]:[]}),baseEdges:W.map(e=>({id:e.id,source:e.from_node_id,sourceHandle:e.from_port_key,target:e.to_node_id,targetHandle:e.to_port_key,type:`animated`,data:{sourcePortKey:e.from_port_key,targetPortKey:e.to_port_key}})),structureKey:`${p??`unassigned`}:${be.map(e=>`${e.id}:${e.type}:${JSON.stringify(e.config)}`).sort().join(`|`)}:${W.map(e=>`${e.id}:${e.from_node_id}:${e.from_port_key}:${e.to_node_id}:${e.to_port_key}:${e.kind}`).sort().join(`|`)}`}),[p,Ie,W,be]);(0,$.useEffect)(()=>{if(Le.length===0){V.current=``,le.current.clear();return}if(H.key===ze||V.current===ze)return;let e=B.current;e&&(e.postMessage({nodes:Le,edges:Re,key:ze}),V.current=ze)},[Re,ue,H.key,Le,ze]);let J=(0,$.useMemo)(()=>{let e=H.positions;return{nodes:Le.map(t=>({...t,position:e.get(t.id)??{x:0,y:0}})),edges:Re.map(e=>({...e,data:{active:!1,flowDirection:null,leaving:!1,selected:e.id===k},animated:!1})),structureKey:ze}},[Re,H.positions,Le,k,ze]),{nodes:Y,edges:Be}=kn(J.nodes,J.edges),X=(0,$.useCallback)(()=>{x(null),C(``),T(``),te(!1)},[]),Z=(0,$.useCallback)(()=>{L(null),oe(!1)},[]),Ve=(0,$.useCallback)(e=>{x(e),C(``),T(``),te(!1),L(null),oe(!1),y(null),_(null)},[]),He=(0,$.useCallback)(()=>{z.current=null,se.current=!1,F(null)},[]),Ue=(0,$.useCallback)((e,t,n,i)=>r(e,t,n,i.sourcePortKey,i.targetPortKey).then(()=>{M(!1),P(null),F(null),L(null),oe(!1),A(null)}).catch(e=>{oe(!1),D.error(e instanceof Error?e.message:`Failed to connect nodes`)}),[r]),We=(0,$.useCallback)((e,t,n={})=>{if(!p)return;if(l){D.error(`Deactivate workflow before editing`);return}if(e===t)return;let r=q(e,t,n);if(r.length===0){D.error(`This connection is not available`);return}if(r.length===1){Ue(p,e,t,r[0]);return}L({tabId:p,sourceNodeId:e,sourceNodeLabel:Ne(e),targetNodeId:t,targetNodeLabel:Ne(t),choices:r}),x(null),C(``),T(``),te(!1),P(null),F(null),M(!1),A(null),y(null),_(null)},[p,Ue,q,Ne,l]),Ge=(0,$.useCallback)((e,t)=>{if(N&&p){if(t.id===N)return;We(N,t.id);return}A(null),je(t.id)?h(t.id):h(null)},[p,je,We,h,N]),Q=(0,$.useCallback)((e,t)=>{if(!K.has(t.id))return;let n=e;_({agentId:t.id,x:n.clientX,y:n.clientY})},[K]),Ke=(0,$.useCallback)((e,t)=>{if(!K.has(t.id))return;let n=e;_({agentId:t.id,x:n.clientX,y:n.clientY})},[K]),qe=(0,$.useCallback)(()=>{_(null)},[]),Je=(0,$.useCallback)(()=>{if(ce.current){ce.current=!1;return}A(null),_(null),y(null),P(null),F(null),Z(),X(),h(null)},[Z,X,h]),Ye=(0,$.useCallback)(e=>{e.preventDefault();let t=e;A(null),_(null),P(null),F(null),Z(),X(),h(null),y({kind:`pane`,x:t.clientX,y:t.clientY})},[Z,X,h]),Xe=(0,$.useCallback)((e,t)=>{let n=je(t.id),r=e;if(r.preventDefault(),r.stopPropagation(),!n||!p){y(null);return}h(t.id),A(null),P(null),F(null),Z(),_(null),X(),y({kind:`node`,x:r.clientX,y:r.clientY,agentId:t.id})},[p,Z,X,je,h]),Ze=(0,$.useCallback)(e=>{if(!p||!e.source||!e.target)return;if(l){D.error(`Deactivate workflow before editing`);return}se.current=!0;let t={};Cn(e.sourceHandle)||(t.sourcePortKey=e.sourceHandle??void 0),wn(e.targetHandle)||(t.targetPortKey=e.targetHandle??void 0),We(e.source,e.target,t)},[p,l,We]),Qe=(0,$.useCallback)((e,t)=>{if(l||t?.handleType===`target`)return;let n=t?.nodeId??Tn(e.target);!n||!G.has(n)||t?.handleId&&!Cn(t.handleId)||(z.current=n,se.current=!1,F(n),P(null),L(null),oe(!1),y(null),_(null))},[l,G]),$e=(0,$.useCallback)(e=>{let t=z.current,n=se.current;if(He(),!t||n||!e||l){j||M(!1);return}let r=Dn(e),i=Tn(e.target)??Tn(r);if(i){We(t,i);return}if(En(e.target)||En(r)){let n=dn(e);n&&(ce.current=!0,Ve({kind:`linked`,x:n.x,y:n.y,anchorNodeId:t}))}j||M(!1)},[He,j,Ve,l,We]),et=(0,$.useCallback)((e,t)=>{A(t.id),_(null),y(null),P(null),F(null),Z(),X(),h(null)},[Z,X,h]),tt=(0,$.useCallback)((e,t)=>{let n=e;n.preventDefault(),n.stopPropagation(),A(t.id),_(null),P(null),F(null),Z(),X(),h(null),y({kind:`edge`,x:n.clientX,y:n.clientY,sourceId:t.source,targetId:t.target,sourcePortKey:t.sourceHandle,targetPortKey:t.targetHandle})},[Z,X,h]),nt=(0,$.useCallback)(()=>{y(null)},[]),rt=(0,$.useMemo)(()=>{if(!v)return[];if(v.kind===`node`){let e=je(v.agentId);return!e||!p?[]:l?[{label:`Clear Selection`,onClick:()=>{h(null)}}]:[{label:`Add Agent After`,onClick:()=>{Ve({kind:`linked`,x:v.x,y:v.y,anchorNodeId:e.id})}},{label:`Connect to...`,onClick:()=>{x(null),C(``),T(``),Z(),M(!1),P(e.id),F(null),A(null),h(e.id)}},`divider`,{label:`Delete Node`,danger:!0,onClick:()=>{s({tabId:p,node:e,tabAgents:Me}).catch(e=>{D.error(e instanceof Error?e.message:`Failed to delete agent`)})}}]}return v.kind===`edge`?!p||l?[]:[{label:`Insert Agent Between`,onClick:()=>{Ve({kind:`between`,x:v.x,y:v.y,sourceNodeId:v.sourceId,targetNodeId:v.targetId})}},{label:`Delete Edge`,danger:!0,onClick:()=>{i(p,v.sourceId,v.targetId,v.sourcePortKey??void 0,v.targetPortKey??void 0).catch(e=>{D.error(e instanceof Error?e.message:`Failed to delete edge`)})}}]:[{label:`Add Agent`,disabled:!p||l,onClick:()=>{Ve({kind:`standalone`,x:v.x,y:v.y})}}]},[p,v,s,i,Ve,l,Z,je,h,Me]),it=(0,$.useCallback)(()=>{if(!p||!b||!w||ee)return;let e=S.trim()||void 0;te(!0),(b.kind===`standalone`?a({tabId:p,roleName:w,name:e}):b.kind===`linked`?o({tabId:p,anchorNodeId:b.anchorNodeId,roleName:w,name:e}):c({tabId:p,sourceNodeId:b.sourceNodeId,targetNodeId:b.targetNodeId,roleName:w,name:e})).then(()=>{X(),A(null),P(null)}).catch(e=>{te(!1),D.error(e instanceof Error?e.message:`Failed to add agent`)})},[p,X,o,a,c,b,S,w,ee]),at=(0,$.useCallback)(e=>{!I||R||(oe(!0),Ue(I.tabId,I.sourceNodeId,I.targetNodeId,e))},[I,Ue,R]),ot=g?K.get(g.agentId)??null:null,st=g&&g.agentId?f.get(g.agentId)??null:null;(0,$.useEffect)(()=>{if(!g||!ot)return;let e=requestAnimationFrame(()=>{let e=pe.current;if(!e)return;let t=e.getBoundingClientRect();ve(e=>e&&Math.abs(e.width-t.width)<.5&&Math.abs(e.height-t.height)<.5?e:{width:t.width,height:t.height})});return()=>cancelAnimationFrame(e)},[g,ot]),(0,$.useEffect)(()=>{if(!E||Y.length===0||ge.current===J.structureKey)return;let e=ge.current===null;ge.current=J.structureKey;let t=requestAnimationFrame(()=>{Te({padding:an,maxZoom:1,duration:e?0:250})});return()=>cancelAnimationFrame(t)},[Y.length,Te,E,J.structureKey]),(0,$.useEffect)(()=>{if(!E||!me.current||Y.length===0)return;let e=0,t=new ResizeObserver(()=>{cancelAnimationFrame(e),e=requestAnimationFrame(()=>{Te({padding:an,maxZoom:1,duration:250})})});return t.observe(me.current),()=>{cancelAnimationFrame(e),t.disconnect()}},[Y.length,Te,E]);let ct=(0,$.useMemo)(()=>{if(!g||typeof window>`u`)return;let e=_e?.width??280,t=_e?.height??120,n=window.innerWidth-8-e,r=window.innerHeight-8-t;return{left:Math.max(8,Math.min(g.x+12,n)),top:Math.max(8,Math.min(g.y+12,r))}},[g,_e]),lt=(0,$.useMemo)(()=>d.size===0?{title:`No workflows yet`}:U?null:{title:`Select a workflow`},[U,d.size]);return{activeTabId:p,animatedEdges:Be,animatedNodes:Y,availableRoles:e,closeConnectionChoice:Z,closeContextMenu:nt,closeQuickCreate:X,connectHintLabel:N?`Choose target node`:j?`Connect nodes`:null,connectionChoice:I,containerRef:me,contextMenu:v,contextMenuItems:rt,emptyState:lt,enterConnectMode:Oe,handleFlowInit:Ee,handleViewportMove:De,isValidConnection:(0,$.useCallback)(e=>{if(l||!e.source||!e.target||e.source===e.target)return!1;let t={};return Cn(e.sourceHandle)||(t.sourcePortKey=e.sourceHandle??void 0),wn(e.targetHandle)||(t.targetPortKey=e.targetHandle??void 0),q(e.source,e.target,t).length>0},[q,l]),loadingRoles:t,onConnect:Ze,onConnectEnd:$e,onConnectStart:Qe,onEdgeClick:et,onEdgeContextMenu:tt,onNodeClick:Ge,onNodeContextMenu:Xe,onNodeMouseEnter:Q,onNodeMouseLeave:qe,onNodeMouseMove:Ke,onPaneClick:Je,onPaneContextMenu:Ye,quickCreate:b,quickCreateName:S,quickCreateRoleName:w,readOnly:l,setQuickCreateName:C,setQuickCreateRoleName:T,submitConnectionChoice:at,submittingConnectionChoice:R,submitQuickCreate:it,submittingQuickCreate:ee,tooltip:g,tooltipAgent:ot,tooltipRef:pe,tooltipStyle:ct,tooltipToolCall:st,viewportZoom:re}}var jn={running:`border-graph-status-running/18 bg-graph-status-running/[0.12] text-graph-status-running`,idle:`border-graph-status-idle/12 bg-graph-status-idle/[0.06] text-graph-status-idle/78`,sleeping:`border-graph-status-sleeping/18 bg-graph-status-sleeping/[0.12] text-graph-status-sleeping`,initializing:`border-graph-status-initializing/16 bg-graph-status-initializing/[0.08] text-graph-status-initializing/84`,error:`border-graph-status-error/20 bg-graph-status-error/[0.09] text-graph-status-error`,terminated:`border-border bg-accent/35 text-muted-foreground`};function Mn({agent:e,agentId:t,activeToolCall:n,style:r,tooltipRef:i}){let a=e?ie({name:e.name,roleName:e.role_name,nodeType:e.node_type,isLeader:e.is_leader}):null;return(0,Q.jsx)(gn,{children:(0,Q.jsx)(W,{children:e&&t&&a?(0,Q.jsxs)(C.div,{ref:i,initial:{opacity:0,y:4,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:2,scale:.98},transition:{duration:.15},className:`pointer-events-none fixed z-[100] max-w-[320px] rounded-md border border-border bg-popover px-2 py-1 text-popover-foreground shadow-md`,style:r,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-[11px] font-medium`,children:a}),(0,Q.jsx)(R,{variant:`outline`,className:`text-[10px] ${jn[e.state]}`,children:e.state.toUpperCase()}),e.role_name?(0,Q.jsx)(R,{variant:`outline`,className:`text-[10px]`,children:e.role_name}):null,e.is_leader?(0,Q.jsx)(R,{variant:`outline`,className:`border-accent bg-accent/45 text-[10px] text-accent-foreground`,children:`Leader`}):null]}),(0,Q.jsxs)(`div`,{className:`mt-1.5 grid grid-cols-[auto_1fr] gap-x-2 gap-y-1 text-[10px] text-muted-foreground`,children:[(0,Q.jsx)(`span`,{children:`ID`}),(0,Q.jsx)(`span`,{className:`font-mono text-foreground/80`,children:t.slice(0,8)}),(0,Q.jsx)(`span`,{children:`Connections`}),(0,Q.jsx)(`span`,{className:`text-foreground/80`,children:e.connections.length}),(0,Q.jsx)(`span`,{children:`Workflow`}),(0,Q.jsx)(`span`,{className:`font-mono text-foreground/80`,children:e.tab_id?.slice(0,8)??`—`}),n?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{children:`Tool`}),(0,Q.jsx)(`span`,{className:`font-mono text-foreground/80`,children:n})]}):null]}),(0,Q.jsxs)(`div`,{className:`mt-1.5 space-y-1`,children:[(0,Q.jsx)(`div`,{className:`text-[10px] font-medium text-muted-foreground`,children:`Todos`}),e.todos.length===0?(0,Q.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:`No todos`}):(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[e.todos.slice(Math.max(e.todos.length-3,0)).reverse().map(e=>(0,Q.jsx)(`div`,{className:`text-[11px] leading-relaxed text-foreground/85`,children:e.text},`${t}-${e.text}`)),e.todos.length>3?(0,Q.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`+`,e.todos.length-3,` more`]}):null]})]})]}):null})})}var Nn={agent:mn},Pn={animated:rn},Fn=(0,$.forwardRef)(function(e,n){let{activeTabId:i,animatedEdges:a,animatedNodes:o,availableRoles:s,closeContextMenu:c,closeConnectionChoice:u,closeQuickCreate:d,connectHintLabel:f,connectionChoice:p,containerRef:m,contextMenu:h,contextMenuItems:g,emptyState:_,enterConnectMode:y,handleFlowInit:b,handleViewportMove:x,isValidConnection:S,loadingRoles:C,onConnect:w,onConnectEnd:T,onConnectStart:ee,onEdgeClick:te,onEdgeContextMenu:E,onNodeClick:ne,onNodeContextMenu:re,onNodeMouseEnter:D,onNodeMouseLeave:O,onNodeMouseMove:k,onPaneClick:A,onPaneContextMenu:j,quickCreate:M,quickCreateName:ie,quickCreateRoleName:N,readOnly:P,setQuickCreateName:ae,setQuickCreateRoleName:F,submitConnectionChoice:I,submittingConnectionChoice:L,submitQuickCreate:R,submittingQuickCreate:oe,tooltip:z,tooltipAgent:se,tooltipRef:ce,tooltipStyle:B,tooltipToolCall:V,viewportZoom:le}=An(e);return(0,$.useImperativeHandle)(n,()=>({enterConnectMode:y}),[y]),(0,Q.jsxs)(`div`,{ref:m,className:`relative flex h-full flex-col`,children:[(0,Q.jsx)(`div`,{className:`relative flex-1 overflow-hidden`,children:_?(0,Q.jsx)(`div`,{className:`flex h-full items-center justify-center px-5 py-8`,children:(0,Q.jsxs)(`div`,{className:`w-full max-w-[22rem] rounded-xl border border-border bg-surface-overlay/60 px-5 py-5 text-center shadow-md backdrop-blur-sm`,children:[(0,Q.jsx)(`div`,{className:`mx-auto flex size-10 items-center justify-center rounded-lg border border-border bg-accent/35 text-muted-foreground`,children:(0,Q.jsx)(v,{className:`size-4.5`})}),(0,Q.jsx)(`p`,{className:`mt-3.5 text-[18px] font-semibold leading-tight text-foreground`,children:_.title})]})}):(0,Q.jsxs)(r,{nodes:o,edges:a,nodeTypes:Nn,edgeTypes:Pn,colorMode:`dark`,onInit:b,onNodeClick:ne,onNodeMouseEnter:D,onNodeMouseMove:k,onNodeMouseLeave:O,onPaneClick:A,onPaneContextMenu:j,onNodeContextMenu:re,onEdgeClick:te,onEdgeContextMenu:E,onConnect:w,onConnectStart:ee,onConnectEnd:T,onMove:x,isValidConnection:S,connectionMode:t.Strict,connectOnClick:!1,proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!!i&&!P,panOnDrag:!0,zoomOnScroll:!0,zoomOnPinch:!0,minZoom:on,maxZoom:6,className:`bg-graph-bg`,children:[(0,Q.jsx)(l,{color:`var(--graph-grid)`,gap:28,size:.72}),(0,Q.jsx)(`svg`,{"aria-hidden":`true`,focusable:`false`,children:(0,Q.jsxs)(`defs`,{children:[(0,Q.jsxs)(`linearGradient`,{id:`agent-graph-edge-flow`,x1:`0`,y1:`0`,x2:`1`,y2:`0`,children:[(0,Q.jsx)(`stop`,{offset:`0%`,stopColor:`var(--graph-edge)`,stopOpacity:`0.2`}),(0,Q.jsx)(`stop`,{offset:`50%`,stopColor:`var(--graph-edge-active)`,stopOpacity:`0.94`}),(0,Q.jsx)(`stop`,{offset:`100%`,stopColor:`var(--graph-edge)`,stopOpacity:`0.2`})]}),(0,Q.jsxs)(`radialGradient`,{id:`agent-graph-edge-pulse`,cx:`50%`,cy:`50%`,r:`50%`,children:[(0,Q.jsx)(`stop`,{offset:`0%`,stopColor:`var(--graph-edge-active)`,stopOpacity:`1`}),(0,Q.jsx)(`stop`,{offset:`100%`,stopColor:`var(--graph-edge-active)`,stopOpacity:`0.2`})]}),(0,Q.jsx)(`filter`,{id:`agent-graph-edge-glow`,x:`-50%`,y:`-50%`,width:`200%`,height:`200%`,children:(0,Q.jsx)(`feGaussianBlur`,{stdDeviation:`2.6`})})]})})]})}),o.length>0?(0,Q.jsx)(`div`,{className:`pointer-events-none absolute bottom-4 left-4 z-30`,children:(0,Q.jsx)(`div`,{className:sn,"data-testid":`agent-graph-zoom-indicator`,children:Te(le)})}):null,f?(0,Q.jsx)(`div`,{className:`pointer-events-none absolute right-4 top-4 z-30`,children:(0,Q.jsx)(`div`,{className:sn,children:f})}):null,(0,Q.jsx)(Mn,{agent:se,agentId:z?.agentId??null,activeToolCall:V,style:B,tooltipRef:ce}),h?(0,Q.jsx)(_n,{x:h.x,y:h.y,items:g,onClose:c}):null,M?(0,Q.jsx)(Ln,{displayName:ie,roles:s,loadingRoles:C,onClose:d,onDisplayNameChange:ae,onSelectRole:F,onSubmit:R,selectedRoleName:N,submitting:oe,title:un(M)}):null,p?(0,Q.jsx)(In,{state:p,onClose:u,onSelect:I,submitting:L}):null]})});function In({state:e,submitting:t,onClose:n,onSelect:r}){return(0,Q.jsxs)(Ke,{open:!0,onOpenChange:e=>{e||n()},title:`Choose Connection`,className:`max-w-[34rem]`,footer:(0,Q.jsx)(K,{type:`button`,variant:`outline`,onClick:n,disabled:t,children:`Cancel`}),children:[(0,Q.jsxs)(Je,{children:[`Choose how`,` `,(0,Q.jsx)(`span`,{className:`font-semibold text-foreground`,children:e.sourceNodeLabel}),` `,`should connect to`,` `,(0,Q.jsx)(`span`,{className:`font-semibold text-foreground`,children:e.targetNodeLabel}),`.`]}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:e.choices.map(e=>(0,Q.jsxs)(K,{type:`button`,variant:`outline`,className:`h-auto w-full justify-between gap-4 rounded-md border-border bg-background/40 px-3 py-2.5 text-left hover:bg-accent/45`,disabled:t,onClick:()=>r(e),children:[(0,Q.jsxs)(`span`,{className:`min-w-0`,children:[(0,Q.jsxs)(`span`,{className:`block truncate text-[13px] font-semibold text-foreground`,children:[e.sourcePortLabel,` -> `,e.targetPortLabel]}),(0,Q.jsx)(`span`,{className:`mt-0.5 block text-[11px] text-muted-foreground`,children:e.type})]}),(0,Q.jsx)(`span`,{className:`shrink-0 text-[12px] text-muted-foreground`,children:t?`Connecting...`:`Connect`})]},`${e.sourcePortKey}->${e.targetPortKey}`))})]})}function Ln({title:e,selectedRoleName:t,displayName:n,roles:r,loadingRoles:i,submitting:a,onSelectRole:o,onDisplayNameChange:s,onSubmit:c,onClose:l}){return(0,Q.jsxs)(Ke,{open:!0,onOpenChange:e=>{e||l()},title:e,className:`max-w-[44rem]`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(K,{type:`button`,variant:`outline`,onClick:l,disabled:a,children:`Cancel`}),(0,Q.jsx)(K,{type:`button`,disabled:!t||a,onClick:c,children:a?`Saving...`:e})]}),children:[(0,Q.jsx)(Je,{children:`Choose a role and set how this agent appears in the workflow.`}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium text-foreground/80`,children:`Role`}),(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Required`})]}),(0,Q.jsx)(Xt,{roles:r,loadingRoles:i,selectedRoleName:t,onRoleNameChange:o})]}),(0,Q.jsx)(qe,{label:`Display Name`,hint:`Optional`,children:(0,Q.jsx)(xe,{"aria-label":`Display Name`,value:n,onChange:e=>s(e.target.value),placeholder:`Optional display name`,className:`h-10 rounded-md bg-background/40 text-foreground shadow-xs placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50`})})]})}function Rn({activeTabId:e,connected:t,definitionDraft:n,editorMode:r,graphConnectMode:i,graphHistory:a,graphRef:o,isCompactWorkspace:s,isDragging:c,leaderDetailVisible:l,leaderNode:u,leaderPanelRunning:f,loadingRoles:p,onCloseLeaderDetails:h,onConnectModeChange:v,onCreateNode:y,onCreateTab:b,onDefinitionDraftChange:S,onDeleteTab:w,onEditorModeChange:T,onOpenLeaderDetails:E,onOpenConnectDialog:D,onSaveDefinition:O,onToggleActivation:A,panelVisible:j,pendingAction:ie,resolvedPanelWidth:N,roles:P,selectAgent:F,selectedAgent:R,setActiveTabId:ce,startDrag:B,tabs:V,togglePanel:le,workflowNodeOptions:ue,workspaceRef:de,workflowLocked:H}){let fe=()=>l&&u?(0,Q.jsx)(se,{agent:u,onClose:h}):e?(0,Q.jsx)(oe,{onOpenDetails:E}):(0,Q.jsx)(z,{}),pe=e?V.get(e)??null:null;return(0,Q.jsxs)(`div`,{ref:de,className:`relative isolate flex h-full overflow-hidden rounded-xl border border-border bg-surface-overlay shadow-md [contain:paint]`,children:[(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-0`,style:{background:`var(--shell-surface-sweep)`}}),(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 top-0 h-px`,style:{background:`var(--shell-hairline)`}}),(0,Q.jsxs)(`div`,{className:`relative flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsx)(`div`,{className:`relative z-30 border-b border-border bg-background/45 backdrop-blur-md`,children:(0,Q.jsxs)(`div`,{className:`pointer-events-auto relative z-10 flex items-center gap-1.5 overflow-x-auto px-3 py-2.5 pr-14 scrollbar-none`,children:[Array.from(V.values()).map(t=>(0,Q.jsxs)(`div`,{className:`group relative min-w-[120px] max-w-[220px] shrink-0`,children:[(0,Q.jsx)(K,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>ce(t.id),onAuxClick:e=>{e.button===1&&(e.preventDefault(),w(t.id,t.title,t.node_count))},className:U(`relative h-8 w-full justify-start rounded-md border-b-2 px-3 pr-12 text-left text-[13px] font-medium transition-[color,border-color,background-color] duration-200`,e===t.id?`border-primary text-foreground`:`border-transparent text-muted-foreground hover:bg-accent/25 hover:text-foreground`),children:(0,Q.jsx)(`div`,{className:`truncate leading-tight`,children:t.title})}),(0,Q.jsx)(K,{type:`button`,variant:`ghost`,size:`icon-xs`,title:`Delete workflow`,"aria-label":`Delete ${t.title}`,onClick:e=>{e.stopPropagation(),w(t.id,t.title,t.node_count)},className:U(`absolute right-1.5 top-1/2 z-20 size-5 -translate-y-1/2 rounded-sm p-1 transition-all duration-200 hover:bg-accent/45 hover:text-foreground`,e===t.id?`text-foreground/70 opacity-100`:`text-muted-foreground/60 opacity-0 group-hover:opacity-100`),children:(0,Q.jsx)(m,{className:`size-3`})})]},t.id)),(0,Q.jsx)(K,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Create workflow`,onClick:b,className:`shrink-0 rounded-md text-muted-foreground transition-all duration-200 hover:bg-accent/45 hover:text-foreground`,children:(0,Q.jsx)(ee,{className:`size-4`})})]})}),(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-0 z-0`,style:{background:`radial-gradient(circle at 14% 10%, var(--shell-spotlight-primary), transparent 24%), linear-gradient(180deg, color-mix(in srgb, var(--foreground) 1%, transparent), transparent 22%)`}}),(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-y-0 right-0 z-10 w-12 bg-gradient-to-l from-background/28 to-transparent`}),(0,Q.jsxs)(`div`,{className:`relative flex-1`,children:[r===`graph`?(0,Q.jsx)(Fn,{ref:o,loadingRoles:p,onConnectModeChange:v,onCreateConnection:a.createConnection,onCreateLinkedAgent:a.createLinkedAgent,onCreateStandaloneAgent:a.createStandaloneAgent,onDeleteAgent:a.deleteAgent,onDeleteConnection:a.deleteConnection,onInsertAgentBetween:a.insertAgentBetween,onOpenConnectDialog:D,readOnly:H,roles:P}):(0,Q.jsxs)(`div`,{className:`flex h-full flex-col p-4`,children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-[11px] font-semibold text-muted-foreground`,children:`Workflow JSON`}),(0,Q.jsx)(`p`,{className:`mt-1 text-[13px] text-muted-foreground`,children:`Review the graph structure and saved workflow settings.`})]}),(0,Q.jsxs)(K,{onClick:O,disabled:!e||H||ie===`save-definition`,children:[(0,Q.jsx)(k,{className:`mr-1 size-4`}),ie===`save-definition`?`Saving...`:`Save JSON`]})]}),(0,Q.jsx)(ge,{value:n,onChange:e=>S(e.target.value),readOnly:H,className:`h-full min-h-0 w-full resize-none rounded-xl border border-border bg-background/40 p-4 font-mono text-[12px] leading-6 text-foreground outline-none transition-[border-color,box-shadow] focus:border-ring focus:ring-[3px] focus:ring-ring/50`,spellCheck:!1})]}),(0,Q.jsxs)(`div`,{className:U(`absolute top-4 z-40 flex max-w-[calc(100%-2.5rem)] flex-wrap items-center gap-1.5`,s?`left-14`:`left-4`),children:[(0,Q.jsxs)(I,{tone:`primary`,children:[(0,Q.jsx)(ne,{className:U(`size-3.5 shrink-0`,t?`text-graph-status-idle/88`:`text-graph-status-initializing/38`)}),(0,Q.jsx)(`span`,{className:`whitespace-nowrap`,children:t?`Live`:`Reconnecting`})]}),pe?(0,Q.jsxs)(I,{children:[pe.node_count??pe.definition.nodes.length,` `,`nodes`]}):null]}),(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-x-3 bottom-4 z-40 flex justify-center`,children:(0,Q.jsxs)(`div`,{"data-testid":`workspace-toolbar`,className:`pointer-events-auto inline-flex max-w-full items-center overflow-x-auto rounded-xl border border-border bg-surface-overlay/92 p-0.5 shadow-sm scrollbar-none`,children:[(0,Q.jsxs)(M,{disabled:!e||H||!a.canUndo(e),onClick:()=>{a.undo(e)},children:[(0,Q.jsx)(d,{className:`size-4 opacity-70`}),`Undo`]}),(0,Q.jsx)(L,{}),(0,Q.jsxs)(M,{disabled:!e||H||!a.canRedo(e),onClick:()=>{a.redo(e)},children:[(0,Q.jsx)(re,{className:`size-4 opacity-70`}),`Redo`]}),(0,Q.jsx)(L,{}),(0,Q.jsxs)(M,{disabled:!e||ie===`activate-workflow`||ie===`deactivate-workflow`,active:H,onClick:A,children:[(0,Q.jsx)(te,{className:`size-4 opacity-70`}),H?`Deactivate`:`Activate`]}),(0,Q.jsx)(L,{}),(0,Q.jsxs)(M,{disabled:!e,active:r===`graph`,onClick:()=>T(`graph`),children:[(0,Q.jsx)(_,{className:`size-4 opacity-70`}),`Graph`]}),(0,Q.jsx)(L,{}),(0,Q.jsxs)(M,{disabled:!e,active:r===`json`,onClick:()=>T(`json`),children:[(0,Q.jsx)(x,{className:`size-4 opacity-70`}),`JSON`]}),(0,Q.jsx)(L,{}),(0,Q.jsxs)(M,{disabled:!e||H,onClick:y,children:[(0,Q.jsx)(ee,{className:`size-4 opacity-70`}),`Add Node`]}),(0,Q.jsx)(L,{}),(0,Q.jsxs)(M,{disabled:!e||H||ue.length<2,active:i,onClick:D,children:[(0,Q.jsx)(g,{className:`size-4 opacity-70`}),`Connect Ports`]})]})})]}),(0,Q.jsx)(`div`,{className:`absolute bottom-4 right-4 z-30 sm:bottom-5 sm:right-5`,children:(0,Q.jsx)(ae,{expanded:j,onClick:le})})]}),(0,Q.jsx)(W,{initial:!1,children:j?s?[(0,Q.jsx)(Ce,{type:`button`,variant:`ghost`,"aria-label":`Close workspace panel`,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.18},className:`absolute inset-0 z-10 h-auto w-auto rounded-none border-0 bg-background/40 p-0 shadow-none backdrop-blur-[1px] hover:bg-background/40 focus-visible:ring-0`,onClick:le},`workspace-panel-backdrop`),(0,Q.jsxs)(C.aside,{initial:{opacity:0,x:18},animate:{opacity:1,x:0},exit:{opacity:0,x:18},transition:{duration:.22,ease:[.16,1,.3,1]},className:`absolute inset-y-2.5 right-2.5 z-20 shrink-0 overflow-hidden rounded-xl border border-border bg-surface-overlay shadow-md`,style:{width:`${N}px`},children:[(0,Q.jsx)(`div`,{"aria-hidden":`true`,className:U(`pointer-events-none absolute inset-0 z-20 border transition-[opacity,border-color,box-shadow] duration-300`,!R&&f?`animate-pulse border-ring/25 opacity-100 shadow-lg shadow-ring/10`:`border-transparent opacity-0`)}),(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-0`,style:{background:`var(--shell-surface-sweep)`}}),(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 top-0 h-px`,style:{background:`var(--shell-hairline)`}}),(0,Q.jsx)(`div`,{className:`flex h-full flex-col overflow-hidden`,children:(0,Q.jsxs)(`div`,{className:`relative flex-1 overflow-hidden`,children:[(0,Q.jsx)(C.div,{animate:{opacity:+!R,x:R?-8:0},transition:{duration:.15},className:U(`absolute inset-0 flex h-full flex-col`,R&&`pointer-events-none`),"aria-hidden":R?!0:void 0,children:fe()}),(0,Q.jsx)(W,{children:R?(0,Q.jsx)(C.div,{initial:{opacity:0,x:10},animate:{opacity:1,x:0},exit:{opacity:0,x:10},transition:{duration:.15},className:`absolute inset-0 flex h-full flex-col bg-background/42`,children:(0,Q.jsx)(se,{agent:R,onClose:()=>F(null)})},R.id):null})]})})]},`workspace-panel-sheet`)]:(0,Q.jsxs)(C.aside,{initial:{width:0,opacity:0},animate:{width:N,opacity:1},exit:{width:0,opacity:0},transition:{duration:.25,ease:[.16,1,.3,1]},className:`relative z-20 shrink-0 border-l border-border bg-surface-overlay shadow-md`,children:[(0,Q.jsx)(`div`,{"aria-hidden":`true`,className:U(`pointer-events-none absolute inset-0 z-20 border transition-[opacity,border-color,box-shadow] duration-300`,!R&&f?`animate-pulse border-ring/25 opacity-100 shadow-lg shadow-ring/10`:`border-transparent opacity-0`)}),(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-0`,style:{background:`var(--shell-surface-sweep)`}}),(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 top-0 h-px`,style:{background:`var(--shell-hairline)`}}),(0,Q.jsx)(G,{position:`left`,isDragging:c,onMouseDown:B}),(0,Q.jsx)(`div`,{className:`flex h-full flex-col overflow-hidden`,style:{width:`${N}px`},children:(0,Q.jsxs)(`div`,{className:`relative flex-1 overflow-hidden`,children:[(0,Q.jsx)(C.div,{animate:{opacity:+!R,x:R?-8:0},transition:{duration:.15},className:U(`absolute inset-0 flex h-full flex-col`,R&&`pointer-events-none`),"aria-hidden":R?!0:void 0,children:fe()}),(0,Q.jsx)(W,{children:R?(0,Q.jsx)(C.div,{initial:{opacity:0,x:10},animate:{opacity:1,x:0},exit:{opacity:0,x:10},transition:{duration:.15},className:`absolute inset-0 flex h-full flex-col bg-background/42`,children:(0,Q.jsx)(se,{agent:R,onClose:()=>F(null)})},R.id):null})]})})]},`workspace-panel-docked`):null})]})}function zn(e){return{undo:[...e?.undo??[]],redo:[...e?.redo??[]]}}function Bn(e){let t=e?.trim()??``;return t.length>0?t:void 0}function Vn(){let e=(0,$.useRef)(new Map),[t,n]=(0,$.useState)(0),r=(0,$.useCallback)(()=>{n(e=>e+1)},[]),i=(0,$.useCallback)((t,n)=>{let i=zn(e.current.get(t));i.undo.push(n),i.redo=[],e.current.set(t,i),r()},[r]),a=(0,$.useCallback)(async({tabId:e,nodeType:t=`agent`,roleName:n,name:r})=>{let a=Bn(r),o=(await ue(e,{node_type:t,role_name:n,name:a})).id;return i(e,{undo:async()=>{await B(e,o)},redo:async()=>{o=(await ue(e,{node_type:t,role_name:n,name:a})).id}}),o},[i]),o=(0,$.useCallback)(async({tabId:e,anchorNodeId:t,roleName:n,name:r})=>{let a=Bn(r),o=(await ue(e,{node_type:`agent`,role_name:n,name:a})).id;try{await V(e,{fromNodeId:t,toNodeId:o})}catch(t){throw await B(e,o).catch(()=>void 0),t}return i(e,{undo:async()=>{await B(e,o)},redo:async()=>{o=(await ue(e,{node_type:`agent`,role_name:n,name:a})).id,await V(e,{fromNodeId:t,toNodeId:o})}}),o},[i]),s=(0,$.useCallback)(async(e,t,n,r=`out`,a=`in`)=>{let o=await V(e,{fromNodeId:t,fromPortKey:r,toNodeId:n,toPortKey:a});i(e,{undo:async()=>{await Ae(e,{edgeId:o.id})},redo:async()=>{await V(e,{fromNodeId:t,fromPortKey:r,toNodeId:n,toPortKey:a})}})},[i]),c=(0,$.useCallback)(async(e,t,n,r=`out`,a=`in`)=>{await Ae(e,{fromNodeId:t,fromPortKey:r,toNodeId:n,toPortKey:a}),i(e,{undo:async()=>{await V(e,{fromNodeId:t,fromPortKey:r,toNodeId:n,toPortKey:a})},redo:async()=>{await Ae(e,{fromNodeId:t,fromPortKey:r,toNodeId:n,toPortKey:a})}})},[i]),l=(0,$.useCallback)(async({tabId:e,node:t,tabAgents:n})=>{let r=Array.from(new Set([...t.connections].filter(e=>n.some(t=>t.id===e)))),a=Bn(t.name),o=t.role_name?.trim()??``,s=t.id;await B(e,s),i(e,{undo:async()=>{s=(await ue(e,{node_type:t.node_type,role_name:o||void 0,name:a})).id;for(let t of r)await V(e,{fromNodeId:t,toNodeId:s})},redo:async()=>{await B(e,s)}})},[i]),u=(0,$.useCallback)(async({tabId:e,sourceNodeId:t,targetNodeId:n,roleName:r,name:a})=>{let o=Bn(a),s=null;await Ae(e,{fromNodeId:t,toNodeId:n});try{s=(await ue(e,{node_type:`agent`,role_name:r,name:o})).id,await V(e,{fromNodeId:t,toNodeId:s}),await V(e,{fromNodeId:s,toNodeId:n})}catch(r){throw s&&await B(e,s).catch(()=>void 0),await V(e,{fromNodeId:t,toNodeId:n}).catch(()=>void 0),r}return i(e,{undo:async()=>{s&&(await B(e,s),await V(e,{fromNodeId:t,toNodeId:n}))},redo:async()=>{await Ae(e,{fromNodeId:t,toNodeId:n}),s=(await ue(e,{node_type:`agent`,role_name:r,name:o})).id,await V(e,{fromNodeId:t,toNodeId:s}),await V(e,{fromNodeId:s,toNodeId:n})}}),s},[i]),d=(0,$.useCallback)(t=>!!(t&&(e.current.get(t)?.undo.length??0)>0),[]),f=(0,$.useCallback)(t=>!!(t&&(e.current.get(t)?.redo.length??0)>0),[]),p=(0,$.useCallback)(async t=>{if(!t)return!1;let n=zn(e.current.get(t)),i=n.undo.pop();return i?(await i.undo(),n.redo.push(i),e.current.set(t,n),r(),!0):!1},[r]),m=(0,$.useCallback)(async t=>{if(!t)return!1;let n=zn(e.current.get(t)),i=n.redo.pop();return i?(await i.redo(),n.undo.push(i),e.current.set(t,n),r(),!0):!1},[r]);return(0,$.useMemo)(()=>({canRedo:f,canUndo:d,createConnection:s,createLinkedAgent:o,createStandaloneAgent:e=>a({tabId:e.tabId,nodeType:`agent`,roleName:e.roleName,name:e.name}),createStandaloneNode:a,deleteAgent:l,deleteConnection:c,insertAgentBetween:u,redo:m,revision:t,undo:p}),[f,d,s,o,a,c,l,u,m,t,p])}var Hn=`workspace-panel-width`,Un=296,Wn=300,Gn=960,Kn=.34,qn=448,Jn=300;function Yn(e){return`${e.key} · ${e.type}`}function Xn(){let{agents:e}=ye(),{tabs:t}=he(),{connected:n}=Se(),{activeToolCalls:r}=we(),{streamingDeltas:i}=be(),{activeTabId:a,selectedAgentId:o,selectAgent:s,setActiveTabId:c}=ke(),[l,u]=(0,$.useState)(!0),[d,f]=(0,$.useState)(`chat`),[p,m]=(0,$.useState)(`graph`),h=Ee(`(max-width: 1180px)`),[g,_]=(0,$.useState)(null),[v,y]=(0,$.useState)(null),[b,x]=(0,$.useState)(``),[S,C]=(0,$.useState)(!1),[w,T]=(0,$.useState)(``),[ee,te]=(0,$.useState)([]),[E,ne]=(0,$.useState)(!1),[re,O]=(0,$.useState)(`agent`),[k,A]=(0,$.useState)(`Worker`),[M,N]=(0,$.useState)(``),[ae,F]=(0,$.useState)(``),[I,L]=(0,$.useState)(``),[R,oe]=(0,$.useState)(``),[z,se]=(0,$.useState)(``),[ce,B]=(0,$.useState)(null),[V,ue]=(0,$.useState)(JSON.stringify(H,null,2)),ge=(0,$.useRef)(null),U=(0,$.useRef)(null),W=(0,$.useRef)(null),G=Vn(),[xe,Ce]=(0,$.useState)(!1),[Te,De]=ve(Hn,qn,Un,Gn),K=(0,$.useCallback)(e=>{let t=W.current?.clientWidth??(typeof window>`u`?e:window.innerWidth),n=Math.max(Un,t-Wn);De(Math.min(e,n))},[De]),{isDragging:Ae,startDrag:je}=_e(Te,K,`left`);(0,$.useLayoutEffect)(()=>{if(Oe(Hn))return;let e=W.current?.clientWidth;e&&K(e*Kn)},[K]),(0,$.useEffect)(()=>{let e=W.current;if(!e)return;let t=new ResizeObserver(()=>{K(Te)});return t.observe(e),()=>{t.disconnect()}},[Te,K]),(0,$.useEffect)(()=>{let e=ge.current;ge.current=h,e!==null&&!e&&h&&u(!1)},[h]),(0,$.useEffect)(()=>{let e=!1;return ne(!0),j().then(t=>{e||te(t)}).catch(()=>{e||D.error(`Failed to load roles`)}).finally(()=>{e||ne(!1)}),()=>{e=!0}},[]);let Me=o?e.get(o)??null:null,Ne=a?t.get(a)??null:null,q=(Ne?.activation_state??`inactive`)===`active`,Pe=(0,$.useMemo)(()=>Array.from(e.values()).filter(e=>e.node_type!==`assistant`&&e.tab_id===a),[a,e]),Fe=(0,$.useMemo)(()=>Pe.filter(e=>!e.is_leader),[Pe]),Ie=(0,$.useMemo)(()=>Ne?.definition.nodes??[],[Ne?.definition.nodes]),Le=(0,$.useMemo)(()=>Ie.map(e=>({id:e.id,label:ie({name:typeof e.config.name==`string`?e.config.name:null,roleName:typeof e.config.role_name==`string`?e.config.role_name:null,nodeType:e.type,isLeader:!1})})),[Ie]),Re=(0,$.useMemo)(()=>Ie.find(e=>e.id===ae)??null,[ae,Ie]),ze=(0,$.useMemo)(()=>Ie.find(e=>e.id===R)??null,[R,Ie]),J=(0,$.useMemo)(()=>(Re?.outputs??[]).map(e=>({key:e.key,label:Yn(e)})),[Re]),Y=(0,$.useMemo)(()=>(ze?.inputs??[]).map(e=>({key:e.key,label:Yn(e)})),[ze]),Be=(0,$.useMemo)(()=>ee.find(e=>e.name===k)??null,[k,ee]),X=l||!!Me,Z=(0,$.useMemo)(()=>{if(!h)return Te;let e=W.current?.clientWidth??(typeof window>`u`?Te:window.innerWidth);return Math.min(Te,Math.max(Jn,e-24))},[h,Te]),Ve=(0,$.useMemo)(()=>P(e,Ne),[Ne,e]),He=Ve?.id??Ne?.leader_id??null,Ue=d===`detail`&&Ve!==null,We=(0,$.useMemo)(()=>{let e=He?i.get(He)??[]:[];return n&&!!(He&&(Ve?.state===`running`||Ve?.state===`sleeping`||r.has(He)||e.length>0))},[r,n,He,Ve,i]);(0,$.useEffect)(()=>{Me&&Me.tab_id!==null&&Me.tab_id!==a&&s(null)},[a,s,Me]),(0,$.useEffect)(()=>{ue(JSON.stringify(Ne?.definition??H,null,2))},[Ne?.definition]),(0,$.useEffect)(()=>{J.some(e=>e.key===I)||L(J[0]?.key??``)},[I,J]),(0,$.useEffect)(()=>{Y.some(e=>e.key===z)||se(Y[0]?.key??``)},[z,Y]),(0,$.useEffect)(()=>{let e=e=>{if(!(e.metaKey||e.ctrlKey)||e.key.toLowerCase()!==`z`)return;let t=e.target;if(!(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement||t?.isContentEditable||g!==null)){if(e.preventDefault(),e.shiftKey){if(q)return;G.redo(a).catch(()=>void 0);return}q||G.undo(a).catch(()=>void 0)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[g,a,G,q]);let Ge=(0,$.useCallback)(()=>{u(!0),f(`detail`)},[]),Q=(0,$.useCallback)(()=>{f(`chat`)},[]),Ke=(0,$.useCallback)(()=>{if(X){o&&s(null),u(!1);return}u(!0)},[X,s,o]),qe=(0,$.useCallback)(()=>{x(``),C(!1),T(``),_(`create-tab`)},[]),Je=(0,$.useCallback)(async()=>{let e=b.trim();if(e){y(`create-tab`);try{c((await de(e,S,w.split(`
3
+ `).map(e=>e.trim()).filter(Boolean))).id),_(null),x(``),C(!1),T(``)}catch(e){D.error(e instanceof Error?e.message:`Failed to create workflow`)}finally{y(null)}}},[S,b,w,c]),Ye=(0,$.useCallback)(async()=>{if(!a){D.error(`Create or select a workflow first`);return}y(q?`deactivate-workflow`:`activate-workflow`);try{q?(await pe(a),D.success(`Workflow deactivated`)):(await fe(a),D.success(`Workflow activated`))}catch(e){D.error(e instanceof Error?e.message:q?`Failed to deactivate workflow`:`Failed to activate workflow`)}finally{y(null)}},[a,q]),Xe=(0,$.useCallback)(()=>{if(!a){D.error(`Create or select a workflow first`);return}if(q){D.error(`Deactivate workflow before editing`);return}O(`agent`),A(`Worker`),N(``),_(`create-node`)},[a,q]),Ze=(0,$.useCallback)(async()=>{if(!a)return;if(q){D.error(`Deactivate workflow before editing`);return}let e=M.trim()||void 0;y(`create-node`);try{if(re===`agent`){let t=Be?.name??``;if(!t)return;await G.createStandaloneNode({tabId:a,nodeType:`agent`,roleName:t,name:e})}else await G.createStandaloneNode({tabId:a,nodeType:re,name:e});_(null),O(`agent`),A(`Worker`),N(``)}catch(e){D.error(e instanceof Error?e.message:`Failed to create node`)}finally{y(null)}},[a,M,re,G,Be?.name,q]),Qe=(0,$.useCallback)((e,t,n)=>{B({id:e,title:t,nodeCount:n})},[]),$e=(0,$.useCallback)(async()=>{if(ce){y(`delete-tab`);try{await me(ce.id),B(null)}catch(e){D.error(e instanceof Error?e.message:`Failed to delete workflow`)}finally{y(null)}}},[ce]),et=(0,$.useCallback)(()=>{if(!a){D.error(`Create or select a workflow first`);return}if(q){D.error(`Deactivate workflow before editing`);return}if(Le.length<2){D.error(`Add at least two nodes before creating an edge`);return}let e=Le[0]?.id??``,t=Le.find(t=>t.id!==e)?.id??``;!e||!t||(F(e),oe(t),_(`connect-ports`))},[a,q,Le]);return{activeDialog:g,activeTab:Ne,activeTabId:a,connected:n,connectSourceId:ae,connectSourcePortKey:I,connectTargetId:R,connectTargetPortKey:z,createNodeName:M,createNodeRoleName:k,createNodeType:re,createTabAllowNetwork:S,createTabTitle:b,createTabWriteDirs:w,definitionDraft:V,deleteTabTarget:ce,editorMode:p,graphConnectMode:xe,graphHistory:G,graphRef:U,handleCloseLeaderDetails:Q,handleConnectPorts:(0,$.useCallback)(async()=>{if(!(!a||!ae||!I||!R||!z)){if(q){D.error(`Deactivate workflow before editing`);return}y(`connect-ports`);try{await G.createConnection(a,ae,R,I,z),_(null)}catch(e){D.error(e instanceof Error?e.message:`Failed to connect ports`)}finally{y(null)}}},[a,ae,I,R,z,G,q]),handleCreateNode:Ze,handleCreateTab:Je,handleDeleteTab:$e,handleOpenLeaderDetails:Ge,handleSaveDefinition:(0,$.useCallback)(async()=>{if(!a)return;if(q){D.error(`Deactivate workflow before editing`);return}let e;try{e=JSON.parse(V)}catch{D.error(`Workflow JSON is invalid`);return}if(!e||typeof e!=`object`){D.error(`Workflow JSON must be an object`);return}y(`save-definition`);try{await le(a,e),D.success(`Workflow JSON saved`)}catch(e){D.error(e instanceof Error?e.message:`Failed to save workflow definition`)}finally{y(null)}},[a,V,q]),handleToggleActivation:Ye,isCompactWorkspace:h,isDragging:Ae,leaderDetailVisible:Ue,leaderNode:Ve,leaderPanelRunning:We,loadingRoles:E,openConnectDialog:et,openCreateNodeDialog:Xe,openCreateTabDialog:qe,panelVisible:X,pendingAction:v,regularTabAgents:Fe,requestDeleteTab:Qe,resolvedPanelWidth:Z,roles:ee,selectAgent:s,selectedAgent:Me,selectedCreateNodeRole:Be,setActiveDialog:_,setActiveTabId:c,setConnectSourceId:F,setConnectSourcePortKey:L,setConnectTargetId:oe,setConnectTargetPortKey:se,setCreateNodeName:N,setCreateNodeRoleName:A,setCreateNodeType:O,setCreateTabAllowNetwork:C,setCreateTabTitle:x,setCreateTabWriteDirs:T,setDefinitionDraft:ue,setDeleteTabTarget:B,setEditorMode:m,setGraphConnectMode:Ce,sourcePortOptions:J,startDrag:je,tabs:t,targetPortOptions:Y,togglePanel:Ke,workflowNodeOptions:Le,workspaceRef:W,workflowLocked:q}}function Zn(){let{activeDialog:e,activeTab:t,activeTabId:n,connected:r,connectSourceId:i,connectSourcePortKey:a,connectTargetId:o,connectTargetPortKey:s,createNodeName:c,createNodeRoleName:l,createNodeType:u,createTabAllowNetwork:d,createTabTitle:f,createTabWriteDirs:p,definitionDraft:m,deleteTabTarget:h,editorMode:g,graphConnectMode:_,graphHistory:v,graphRef:y,handleCloseLeaderDetails:b,handleConnectPorts:x,handleCreateNode:S,handleCreateTab:C,handleDeleteTab:w,handleOpenLeaderDetails:T,handleSaveDefinition:ee,handleToggleActivation:te,isCompactWorkspace:E,isDragging:ne,leaderDetailVisible:re,leaderNode:D,leaderPanelRunning:O,loadingRoles:k,openConnectDialog:A,openCreateNodeDialog:j,openCreateTabDialog:M,panelVisible:ie,pendingAction:N,regularTabAgents:P,requestDeleteTab:ae,resolvedPanelWidth:F,roles:I,selectAgent:L,selectedAgent:R,selectedCreateNodeRole:oe,setActiveDialog:z,setActiveTabId:se,setConnectSourceId:ce,setConnectSourcePortKey:B,setConnectTargetId:V,setConnectTargetPortKey:le,setCreateNodeName:ue,setCreateNodeRoleName:de,setCreateNodeType:H,setCreateTabAllowNetwork:fe,setCreateTabTitle:pe,setCreateTabWriteDirs:me,setDefinitionDraft:he,setDeleteTabTarget:ge,setEditorMode:_e,setGraphConnectMode:ve,sourcePortOptions:U,startDrag:ye,tabs:be,targetPortOptions:W,togglePanel:G,workflowNodeOptions:xe,workspaceRef:Se,workflowLocked:Ce}=Xn();return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Rn,{activeTabId:n,connected:r,definitionDraft:m,editorMode:g,graphConnectMode:_,graphHistory:v,graphRef:y,isCompactWorkspace:E,isDragging:ne,leaderDetailVisible:re,leaderNode:D,leaderPanelRunning:O,loadingRoles:k,onCloseLeaderDetails:b,onConnectModeChange:ve,onCreateNode:j,onCreateTab:M,onDefinitionDraftChange:he,onDeleteTab:ae,onEditorModeChange:_e,onOpenLeaderDetails:T,onOpenConnectDialog:A,onSaveDefinition:ee,onToggleActivation:te,panelVisible:ie,pendingAction:N,regularTabAgents:P,resolvedPanelWidth:F,roles:I,selectAgent:L,selectedAgent:R,setActiveTabId:se,startDrag:ye,tabs:be,togglePanel:G,workflowNodeOptions:xe,sourcePortOptions:U,targetPortOptions:W,workspaceRef:Se,workflowLocked:Ce}),(0,Q.jsx)(Qt,{open:e===`create-tab`,onOpenChange:e=>{e||z(null)},pending:N===`create-tab`,title:f,onTitleChange:pe,allowNetwork:d,onAllowNetworkChange:fe,writeDirs:p,onWriteDirsChange:me,onSubmit:()=>void C()}),(0,Q.jsx)(en,{open:e===`create-node`,onOpenChange:e=>{e||z(null)},pending:N===`create-node`,activeTabTitle:t?.title??null,nodeType:u,onNodeTypeChange:H,selectedRoleName:l,onRoleNameChange:de,roles:I,loadingRoles:k,nodeName:c,onNodeNameChange:ue,onSubmit:()=>void S(),submitDisabled:!n||N===`create-node`||Ce||u===`agent`&&!oe}),(0,Q.jsx)(tn,{open:e===`connect-ports`,onOpenChange:e=>{e||z(null)},pending:N===`connect-ports`,activeTabTitle:t?.title??null,nodeOptions:xe,fromNodeId:i,fromPortKey:a,toNodeId:o,toPortKey:s,fromPortOptions:U,toPortOptions:W,onFromNodeChange:ce,onFromPortChange:B,onToNodeChange:V,onToPortChange:le,onSubmit:()=>void x()}),(0,Q.jsx)(nn,{open:!!h,onOpenChange:e=>{e||ge(null)},pending:N===`delete-tab`,target:h,onDelete:()=>void w()})]})}export{Zn as WorkspacePage};