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,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};
@@ -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{At as r,Et as i,It as a,J as o,Jt as s,Ot as c,Qt as l,St as u,W as d,Xt as f,Y as p,an as m,ct as h,dt as g,en as _,it as v,nn as y,nt as b,q as x,qt as S,rn as C,rt as w,st as T,tn as E,tt as D,vt as O,xt as k,zt as A}from"./ui-vendor-C5pJa8N7.js";import{A as j,G as M,J as ee,K as N,M as P,W as te,Y as F,Z as ne,_ as re,c as I,ct as ie,ft as L,g as ae,h as oe,ht as R,j as z,lt as se,m as ce,mt as B,p as le,q as ue,ut as V,v as de}from"./index-C9HuekJm.js";import{n as fe,t as pe}from"./markdown-vendor-C9RtvaJh.js";import{n as H}from"./surface-pWwG5ogx.js";function me(e){return`/api/image-assets/${encodeURIComponent(e)}`}async function he(e){let t=new FormData;return t.append(`file`,e),F(`/api/image-assets`,{method:`POST`,body:t,errorMessage:`Failed to upload image`})}var U=e(t(),1),W=n();function ge({assetId:e,alt:t,mimeType:n,width:r,height:i,compact:a=!1}){let{openImage:o}=ne(),s=me(e),c=typeof r==`number`&&r>0&&typeof i==`number`&&i>0?`${r} / ${i}`:void 0,l=`${n||`image asset`}${r&&i?` · ${r}x${i}`:``}`;return(0,W.jsx)(W.Fragment,{children:(0,W.jsxs)(V,{type:`button`,variant:`ghost`,onClick:()=>o({src:s,alt:t,meta:l,width:r,height:i}),className:L(`group h-auto w-full flex-col items-stretch overflow-hidden rounded-xl border border-border bg-accent/20 p-0 text-left transition-colors hover:bg-accent/30 hover:text-inherit`,a?`max-w-[240px]`:`max-w-[360px]`),children:[(0,W.jsx)(`div`,{style:c?{aspectRatio:c}:void 0,className:L(`relative overflow-hidden bg-background/45`,a?`min-h-[132px]`:`min-h-[180px]`),children:(0,W.jsx)(`img`,{alt:t||`Image`,className:`h-full w-full object-cover`,loading:`lazy`,src:s})}),(0,W.jsxs)(`div`,{className:`space-y-1 px-3 py-2.5`,children:[(0,W.jsx)(`div`,{className:`text-[12px] font-medium text-foreground`,children:t||`Image`}),(0,W.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:l})]})]})})}function _e({content:e,className:t}){return(0,W.jsx)(`div`,{className:L(`min-w-0 max-w-full select-text overflow-hidden break-words [overflow-wrap:anywhere]`,t),children:(0,W.jsx)(fe,{remarkPlugins:[pe],components:{p:({children:e})=>(0,W.jsx)(`p`,{className:`mb-1.5 last:mb-0 whitespace-pre-wrap`,children:e}),code:({children:e,className:t})=>t?(0,W.jsx)(`code`,{className:`block font-mono text-[0.9em] text-foreground/80`,children:e}):(0,W.jsx)(`code`,{className:`rounded bg-surface-3 px-1 py-0.5 font-mono text-[0.9em] text-foreground/90 break-all`,children:e}),pre:({children:e})=>(0,W.jsx)(`pre`,{className:`mb-1.5 max-w-full overflow-x-auto rounded bg-surface-1 p-2 text-[0.9em] leading-relaxed`,children:e}),a:({href:e,children:t})=>(0,W.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:`text-primary underline hover:text-primary/80`,children:t}),ul:({children:e})=>(0,W.jsx)(`ul`,{className:`mb-1.5 list-disc pl-4 space-y-0.5`,children:e}),ol:({children:e})=>(0,W.jsx)(`ol`,{className:`mb-1.5 list-decimal pl-4 space-y-0.5`,children:e}),li:({children:e})=>(0,W.jsx)(`li`,{className:`leading-relaxed`,children:e}),strong:({children:e})=>(0,W.jsx)(`strong`,{className:`font-semibold text-foreground`,children:e}),em:({children:e})=>(0,W.jsx)(`em`,{className:`italic text-foreground/80`,children:e}),blockquote:({children:e})=>(0,W.jsx)(`blockquote`,{className:`mb-1.5 border-l-2 border-muted-foreground pl-3 text-muted-foreground italic`,children:e}),table:({children:e})=>(0,W.jsx)(`div`,{className:`mb-1.5 overflow-x-auto`,children:(0,W.jsx)(`table`,{className:`w-full border-collapse text-xs`,children:e})}),th:({children:e})=>(0,W.jsx)(`th`,{className:`border border-border bg-surface-2 px-2 py-1 text-left font-semibold text-foreground`,children:e}),td:({children:e})=>(0,W.jsx)(`td`,{className:`border border-border px-2 py-1 text-foreground/80`,children:e}),h1:({children:e})=>(0,W.jsx)(`h1`,{className:`mb-1.5 text-base font-bold text-foreground`,children:e}),h2:({children:e})=>(0,W.jsx)(`h2`,{className:`mb-1.5 text-sm font-bold text-foreground`,children:e}),h3:({children:e})=>(0,W.jsx)(`h3`,{className:`mb-1.5 text-xs font-bold text-foreground/90`,children:e})},children:e})})}function G(e){if(e==null)return null;if(typeof e==`string`){let t=e.trim();if(!t||!t.startsWith(`{`)&&!t.startsWith(`[`))return null;try{return JSON.stringify(JSON.parse(t),null,4)}catch{return null}}if(typeof e==`object`)try{return JSON.stringify(e,null,4)}catch{return String(e)}return null}function K({content:e,layout:t=`parts-order`,parts:n,streaming:r,markdownClassName:i,preClassName:a}){let o=P(n,e),s=o.some(e=>e.type===`image`),c=z(o,e),l=G(c);if(t===`human-attachments-top`&&s){let e=o.filter(e=>e.type===`text`);return(0,W.jsxs)(`div`,{className:`space-y-3`,children:[(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2.5`,children:o.filter(e=>e.type===`image`).map((e,t)=>(0,W.jsx)(ge,{alt:e.alt,assetId:e.asset_id,compact:!0,height:e.height,mimeType:e.mime_type,width:e.width},`${t}-attachment-${e.asset_id}`))}),e.length>0?(0,W.jsx)(K,{content:z(e),markdownClassName:i,preClassName:a,parts:e,streaming:r}):null]})}return l?(0,W.jsx)(`pre`,{className:L(`select-text whitespace-pre-wrap break-words rounded-xl border border-border bg-background/40 px-3.5 py-3 text-[11px] font-mono leading-relaxed text-foreground/80`,a),children:(0,W.jsx)(ve,{text:l,streaming:r})}):o.length>0&&s?(0,W.jsx)(`div`,{className:`space-y-3`,children:o.map((e,t)=>e.type===`text`?(0,W.jsx)(K,{content:e.text,markdownClassName:i,preClassName:a},`${t}-text`):(0,W.jsx)(ge,{alt:e.alt,assetId:e.asset_id,height:e.height,mimeType:e.mime_type,width:e.width},`${t}-image-${e.asset_id}`))}):r?(0,W.jsx)(`div`,{className:L(`min-w-0 select-text whitespace-pre-wrap break-words [overflow-wrap:anywhere]`,i),children:(0,W.jsx)(ve,{text:c,streaming:!0})}):(0,W.jsx)(`div`,{className:`min-w-0`,children:(0,W.jsx)(_e,{content:c,className:i})})}function ve({text:e,streaming:t}){return(0,W.jsxs)(W.Fragment,{children:[e,t?(0,W.jsx)(`span`,{className:`streaming-cursor`}):null]})}var q=[{name:`/clear`,description:`Clear the current chat.`,usage:`/clear`},{name:`/compact`,description:`Compress this chat for future replies.`,usage:`/compact [focus]`},{name:`/help`,description:`Show available commands and usage.`,usage:`/help`}],ye=/^\/\S*/;function be(e){let t=e.trimStart(),n=e.slice(0,e.length-t.length),r=t.match(ye)?.[0]??`/`;return{leadingWhitespace:n,trimmedStart:t,token:r,suffix:t.slice(r.length)}}function J(e,t){return t<=0?0:Math.min(e,t-1)}function Y(e){let{trimmedStart:t,token:n}=be(e);return t.startsWith(`/`)?{filtered:n===`/`?q:q.filter(e=>e.name.startsWith(n)),isCommandInput:!0,token:n}:{filtered:[],isCommandInput:!1,token:``}}function X(e,t,n){let r=t.token===n?J(t.index,e.length):0;return{selectedCommand:e[Math.min(r,Math.max(e.length-1,0))]??null,selectedCommandIndex:r}}function xe(e,t,n,r){if(e.length===0)return{index:0,token:n};let{selectedCommandIndex:i}=X(e,t,n);return{index:(i+r+e.length)%e.length,token:n}}function Se(e,t){let{trimmedStart:n,token:r}=be(e);return r===t&&(n===t||n.startsWith(`${t} `))}function Ce(e,t){let{leadingWhitespace:n,suffix:r}=be(e);return r?`${n}${t.name}${r.startsWith(` `)?r:` ${r}`}`:`${n}${t.name} `}function Z({busy:e=!1,commandsEnabled:t=!0,disabled:n,images:r=[],imageInputEnabled:i=!0,input:o,onAddImages:s=()=>{},onChange:c,onNavigateHistory:l,onKeyDown:u,onRemoveImage:d=()=>{},onSend:f,onStop:p,overlay:m=!1,placeholder:h,targetLabel:g=`Assistant`,stopping:_=!1,suppressCommandNavigation:v=!1}){let y=(0,U.useRef)(null),x=(0,U.useRef)(null),S=e?_?`Stopping...`:`Stop`:`Send`,w=e?_||!p:n,{filtered:T,isCommandInput:E,token:D}=t?Y(o):{filtered:[],isCommandInput:!1,token:``},[O,k]=(0,U.useState)({index:0,token:``}),[A,j]=(0,U.useState)(null),M=t&&r.length===0&&E&&A!==D,{selectedCommand:ee,selectedCommandIndex:N}=X(T,O,D);(0,U.useLayoutEffect)(()=>{let e=y.current;if(!e)return;let t=window.getComputedStyle(e),n=Number.parseFloat(t.lineHeight)||20,r=Number.parseFloat(t.paddingTop)||0,i=Number.parseFloat(t.paddingBottom)||0,a=n+r+i,o=n*8+r+i;e.style.height=`0px`;let s=Math.min(Math.max(e.scrollHeight,a),o);e.style.height=`${s}px`,e.style.overflowY=e.scrollHeight>o?`auto`:`hidden`},[o]);let P=e=>{let n=t?Y(e):{isCommandInput:!1,token:``};n.isCommandInput?n.token!==D&&(k({index:0,token:n.token}),A&&A!==n.token&&j(null)):(j(null),k({index:0,token:``})),c(e)},te=e=>{c(Ce(o,e)),k({index:0,token:e.name}),j(null),y.current?.focus()},F=()=>{j(null),k({index:0,token:``})};return(0,W.jsxs)(`div`,{className:L(m?`w-full pointer-events-auto`:`border-t border-border p-2.5`),children:[M?(0,W.jsx)(`div`,{role:`listbox`,"aria-label":`Available commands`,className:`pointer-events-auto mb-2 overflow-hidden rounded-xl border border-border bg-surface-overlay shadow-sm`,children:T.length>0?T.map((e,t)=>{let n=t===N;return(0,W.jsxs)(V,{type:`button`,variant:`ghost`,role:`option`,"aria-selected":n,onMouseDown:t=>{t.preventDefault(),te(e)},className:L(`h-auto w-full items-start justify-start gap-3 rounded-none px-3 py-2.5 text-left whitespace-normal transition-colors`,n?`bg-accent/60 hover:bg-accent/60`:`hover:bg-accent/35`),children:[(0,W.jsx)(`span`,{className:`mt-0.5 shrink-0 rounded-full border border-border bg-accent/45 px-2 py-0.5 font-mono text-[11px] text-foreground`,children:e.name}),(0,W.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,W.jsx)(`span`,{className:`block text-[12px] font-medium text-foreground`,children:e.description}),(0,W.jsx)(`span`,{className:`mt-1 block font-mono text-[11px] text-muted-foreground`,children:e.usage})]})]},e.name)}):(0,W.jsx)(`div`,{className:`px-3 py-3 text-[12px] text-muted-foreground`,children:`No matching commands.`})}):null,(0,W.jsxs)(`div`,{className:`rounded-md border border-border bg-background/30 px-2 py-1 shadow-sm transition-[border-color,background-color,box-shadow] duration-200 hover:border-ring/35 focus-within:border-ring/45 focus-within:ring-[3px] focus-within:ring-ring/35`,children:[r.length>0?(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2 border-b border-border px-0.5 py-2`,children:r.map(e=>(0,W.jsx)(Te,{image:e,onRemove:()=>d(e.id)},e.id))}):null,(0,W.jsxs)(`div`,{className:`grid grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-1`,children:[(0,W.jsx)(se,{ref:x,accept:`image/png,image/jpeg,image/gif,image/webp`,className:`hidden`,multiple:!0,onChange:e=>{e.target.files&&e.target.files.length>0&&(F(),s(e.target.files)),e.currentTarget.value=``},type:`file`}),(0,W.jsx)(V,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":i?`Add images`:`Current model does not support image input`,disabled:!i,onClick:()=>x.current?.click(),className:L(`shrink-0 rounded-full transition-colors disabled:opacity-35`,i?`bg-accent/55 text-foreground hover:bg-accent`:`bg-accent/20 text-muted-foreground`),children:(0,W.jsx)(a,{className:`size-4`})}),(0,W.jsx)(ie,{ref:y,value:o,onChange:e=>P(e.target.value),onKeyDown:e=>{if((e.key===`ArrowUp`||e.key===`ArrowDown`)&&l&&l(e.key===`ArrowUp`?-1:1,{start:e.currentTarget.selectionStart,end:e.currentTarget.selectionEnd})){e.preventDefault();return}if(v&&M&&(e.key===`ArrowUp`||e.key===`ArrowDown`)){u(e);return}if(M){let t=T.length>0&&ee&&!Se(o,ee.name)?ee:null;if(e.key===`Escape`){e.preventDefault(),j(D);return}if(T.length>0&&e.key===`ArrowDown`){e.preventDefault(),k(xe(T,O,D,1));return}if(T.length>0&&e.key===`ArrowUp`){e.preventDefault(),k(xe(T,O,D,-1));return}if(t&&e.key===`Tab`&&!e.shiftKey){e.preventDefault(),te(t);return}if(t&&e.key===`Enter`&&!e.shiftKey){e.preventDefault(),te(t);return}}u(e)},onPaste:e=>{let t=we(e.clipboardData?.items);t.length===0||!i||(e.preventDefault(),F(),s(t))},placeholder:h??(t?`Do anything`:`Message ${g}`),rows:1,className:L(`min-h-5 w-full resize-none self-center border-0 bg-transparent px-0.5 py-0 text-[13px] leading-5 text-foreground shadow-none placeholder:text-muted-foreground focus-visible:border-transparent focus-visible:ring-0`,`rounded-sm`,o.length===0&&`truncate`)}),(0,W.jsxs)(V,{type:`button`,variant:e?`destructive`:`default`,size:`sm`,onClick:e?p:f,disabled:w,"aria-label":e?`Stop ${g}`:`Send ${g} message`,className:L(`shrink-0 rounded-full transition-all duration-300 active:scale-[0.96] disabled:opacity-30`,`h-8 gap-1.5 px-3.5`),children:[e?(0,W.jsx)(b,{className:`size-3.5 fill-current`,strokeWidth:2.4}):(0,W.jsx)(C,{className:`size-4`,strokeWidth:2.5}),(0,W.jsx)(`span`,{className:`text-[11px] font-medium`,children:S})]})]})]}),i?null:(0,W.jsx)(`div`,{className:`px-1.5 pt-2 text-[11px] text-muted-foreground`,children:`Current model does not support image input.`})]})}function we(e){return e?Array.from(e).filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).flatMap(e=>{let t=e.getAsFile();return t?[t]:[]}):[]}function Te({image:e,onRemove:t}){let{openImage:n}=ne(),r=e.status===`uploading`?`Uploading...`:e.width&&e.height?`${e.width}x${e.height}`:`Ready`;return(0,W.jsxs)(`div`,{className:`relative overflow-hidden rounded-lg border border-border bg-background/35 transition-colors hover:border-ring/35`,children:[(0,W.jsxs)(V,{"aria-label":`Preview ${e.name}`,type:`button`,variant:`ghost`,className:`h-auto w-auto items-start justify-start rounded-none p-0 text-left hover:bg-transparent hover:text-inherit`,onClick:()=>n({src:e.previewUrl,alt:e.name,meta:r,width:e.width,height:e.height}),children:[(0,W.jsx)(`img`,{alt:e.name,className:`h-20 w-20 object-cover`,src:e.previewUrl}),(0,W.jsxs)(`div`,{className:`absolute inset-x-0 bottom-0 bg-background/80 px-2 py-1 text-[10px] text-foreground/84`,children:[(0,W.jsx)(`div`,{className:`truncate`,children:e.name}),(0,W.jsx)(`div`,{className:`text-muted-foreground`,children:r})]})]}),(0,W.jsx)(V,{"aria-label":`Remove ${e.name}`,type:`button`,variant:`ghost`,size:`icon-xs`,className:`absolute right-1 top-1 z-10 rounded-full bg-background/72 text-muted-foreground hover:bg-background/90 hover:text-foreground`,onClick:t,children:(0,W.jsx)(o,{className:`size-3.5`})})]})}function Q({text:e,className:t,iconClassName:n,copiedClassName:r}){let[i,a]=(0,U.useState)(!1),o=(0,U.useRef)(null),s=(0,U.useRef)(!0);return(0,U.useEffect)(()=>()=>{s.current=!1,o.current&&clearTimeout(o.current)},[]),(0,W.jsx)(V,{type:`button`,variant:`ghost`,size:`icon-xs`,onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(e).then(()=>{s.current&&(a(!0),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{s.current&&a(!1)},1500))})},"aria-label":`Copy`,className:L(`size-5 rounded p-0.5 text-muted-foreground opacity-0 transition-all hover:bg-accent/45 hover:text-foreground group-hover:opacity-100`,t),title:`Copy`,children:i?(0,W.jsx)(_,{className:L(`size-3 text-foreground`,r)}):(0,W.jsx)(S,{className:L(`size-3`,n)})})}var Ee=(0,U.memo)(function({allowHumanMessageRetry:e=!0,bottomInset:t=0,scrollRef:n,items:r,nodes:i,onRetryHumanMessage:a,onCancelPendingSend:o,onSendPendingSend:s,onScroll:c,retryImageInputEnabled:l=!0,retryingMessageId:u=null,runningHint:d=null}){let f=r.filter(e=>e.type!==`SystemEntry`);return(0,W.jsx)(`div`,{ref:n,onScroll:c,style:{paddingBottom:`${14+t}px`,scrollPaddingBottom:`${14+t}px`},className:`flex-1 overflow-y-auto px-3 pt-3`,children:(0,W.jsxs)(`div`,{className:`mx-auto flex min-h-full w-full max-w-3xl flex-col space-y-2.5`,children:[f.length===0&&!d?(0,W.jsx)(Be,{}):null,f.map((t,n)=>(0,W.jsx)(`div`,{className:`[content-visibility:auto] [contain-intrinsic-size:auto_100px]`,children:(0,W.jsx)(Oe,{allowHumanMessageRetry:e,item:t,nodes:i,onRetryHumanMessage:a,onCancelPendingSend:o,onSendPendingSend:s,retryImageInputEnabled:l,retryingMessageId:u})},ze(t,n))),d?(0,W.jsx)(`div`,{children:(0,W.jsx)(De,{label:d.label,toolName:d.toolName})}):null]})})});function De({label:e,toolName:t}){return(0,W.jsx)(`div`,{className:`flex min-w-0 items-center`,children:(0,W.jsxs)(`div`,{className:`inline-flex max-w-full items-center gap-2 rounded-full border border-border bg-accent/25 px-3 py-1.5 text-[11px] text-muted-foreground/82`,children:[(0,W.jsx)(`span`,{className:`flex items-center gap-1.5`,children:[0,1,2].map(e=>(0,W.jsx)(`span`,{className:`size-1.5 animate-pulse rounded-full bg-muted-foreground/80`,style:{animationDelay:`${e*140}ms`}},e))}),(0,W.jsx)(`span`,{children:e}),t?(0,W.jsx)(`span`,{className:`truncate rounded-full border border-border bg-background/40 px-2 py-0.5 font-mono text-[10px] text-foreground/80`,children:t}):null]})})}var Oe=(0,U.memo)(function({allowHumanMessageRetry:e,item:t,nodes:n,onRetryHumanMessage:r,onCancelPendingSend:a,onSendPendingSend:o,retryImageInputEnabled:s,retryingMessageId:c}){if(t.type===`PendingHumanMessage`)return(0,W.jsx)(Ae,{content:t.content,parts:t.parts,retrying:!1,pending:!0});if(t.type===`PendingSendMessage`)return(0,W.jsx)(ke,{content:t.content,onCancel:a?()=>a(t.id):void 0,onSend:o?()=>o(t.id):void 0,parts:t.parts,sendFailed:t.send_failed,targetState:t.target_state});switch(t.type){case`ReceivedMessage`:if(P(t.parts,t.content).length===0)return null;if(t.from_id===`human`){let n=P(t.parts,t.content).some(e=>e.type===`image`)&&!s;return(0,W.jsx)(Ae,{allowRetry:e,content:z(t.parts,t.content),retryDisabled:n,retryDisabledReason:n?`Current model does not support image input`:void 0,messageId:t.message_id??null,onRetry:t.message_id&&r&&!n?()=>r(t.message_id):void 0,parts:t.parts,retrying:c===t.message_id})}return(0,W.jsx)(Me,{content:z(t.parts,t.content),parts:t.parts,icon:(0,W.jsx)(i,{className:`size-3.5 text-foreground/68`}),label:`From ${I(t.from_id??``,n)}`,tone:`received`,streaming:t.streaming});case`AssistantText`:return P(t.parts,t.content).length===0?null:(0,W.jsx)(je,{content:z(t.parts,t.content),parts:t.parts,streaming:t.streaming});case`SentMessage`:return P(t.parts,t.content).length===0?null:(0,W.jsx)(Me,{content:z(t.parts,t.content),parts:t.parts,icon:(0,W.jsx)(T,{className:`size-3.5 text-foreground/58`}),label:`To ${(t.to_id?[t.to_id]:(t.to_ids??[]).filter(e=>!!e)).map(e=>I(e,n)).join(`, `)||`Unknown`}`,tone:`sent`,streaming:t.streaming});case`AssistantThinking`:return(0,W.jsx)(Ne,{item:t});case`ToolCall`:return(0,W.jsx)(Pe,{item:t});case`CommandResultEntry`:return(0,W.jsx)(Fe,{item:t});case`ErrorEntry`:return(0,W.jsx)(Ie,{content:t.content??``});default:return null}});function ke({content:e,onCancel:t,onSend:n,parts:r,sendFailed:i,targetState:a}){let o=i||a===`error`||a===`terminated`,s=!!n&&a===`error`,c=o?`Needs attention`:a===`sleeping`?`Waiting for wake-up`:`Waiting to send`;return(0,W.jsx)(`div`,{className:`group mt-2 flex min-w-0 flex-col items-end`,children:(0,W.jsx)(`div`,{className:L(`min-w-0 overflow-hidden px-2.5 py-1.5 text-[13px] [overflow-wrap:anywhere]`,`max-w-[84%] rounded-lg border bg-background/50 text-foreground`,o?`border-destructive/45`:`border-ring/35`),children:(0,W.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,W.jsx)(K,{content:e,layout:`human-attachments-top`,markdownClassName:`text-sm text-foreground`,parts:r,preClassName:`text-foreground/90`}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,W.jsxs)(`span`,{className:L(`inline-flex shrink-0 items-center gap-1 rounded-full border px-2 py-0.5 text-[10px] font-medium`,o?`border-destructive/35 bg-destructive/10 text-destructive`:`border-ring/25 bg-ring/10 text-foreground/80`),children:[(0,W.jsx)(h,{className:`size-3`}),c]}),s?(0,W.jsxs)(V,{type:`button`,variant:`outline`,size:`xs`,onClick:n,className:`h-auto rounded-full border-border bg-background/40 px-2.5 py-1 text-[11px] text-foreground hover:bg-accent/45`,children:[(0,W.jsx)(T,{className:`size-3`}),`Send now`]}):null,t?(0,W.jsx)(V,{type:`button`,variant:`ghost`,size:`xs`,onClick:t,className:`h-auto rounded-full border border-border bg-accent/35 px-2.5 py-1 text-[11px] text-muted-foreground hover:bg-accent/45 hover:text-foreground`,children:`Cancel`}):null]})]})})})}function Ae({allowRetry:e=!0,content:t,messageId:n,onRetry:i,parts:a,retryDisabled:o,retryDisabledReason:s,retrying:c,pending:l=!1}){let u=e&&!l&&!!n&&(!!i||o);return(0,W.jsxs)(`div`,{className:`group mt-2 flex min-w-0 flex-col items-end`,children:[(0,W.jsx)(`div`,{className:L(`min-w-0 overflow-hidden px-2.5 py-1.5 text-[13px] [overflow-wrap:anywhere]`,`max-w-[84%] rounded-lg border border-border bg-accent/80 text-accent-foreground`,l&&`opacity-80`),children:(0,W.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,W.jsx)(K,{content:t,layout:`human-attachments-top`,parts:a,markdownClassName:`text-sm text-accent-foreground`,preClassName:`text-accent-foreground/90`}),l?(0,W.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1 rounded-full bg-accent/70 px-2 py-0.5 text-[10px] font-medium text-accent-foreground`,children:[(0,W.jsx)(r,{className:`size-3 animate-spin`}),`Sending`]}):null]})}),(0,W.jsxs)(`div`,{className:`mt-1 flex items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100`,children:[(0,W.jsx)(Q,{text:t}),u?(0,W.jsxs)(V,{type:`button`,variant:`ghost`,size:`xs`,onClick:i,disabled:c||o,title:s,className:L(`h-auto rounded-full border border-border px-2.5 py-1 text-[11px] text-muted-foreground hover:bg-accent/45 hover:text-foreground disabled:opacity-45`,`bg-accent/35`),children:[c?(0,W.jsx)(r,{className:`size-3 animate-spin`}):(0,W.jsx)(g,{className:`size-3`}),(0,W.jsx)(`span`,{children:c?`Retrying...`:`Retry`})]}):null]})]})}function je({content:e,parts:t,streaming:n}){return(0,W.jsxs)(`div`,{className:`group min-w-0 w-full`,children:[(0,W.jsx)(K,{content:e,parts:t,streaming:n,markdownClassName:`text-sm text-foreground`,preClassName:`text-foreground/90`}),(0,W.jsx)(`div`,{className:`mt-1 opacity-0 transition-opacity group-hover:opacity-100`,children:(0,W.jsx)(Q,{text:e})})]})}function Me({content:e,parts:t,icon:n,label:r,tone:i,streaming:a}){let[o,s]=(0,U.useState)(!!a);return(0,W.jsxs)(`div`,{className:L(`min-w-0 w-full px-2 py-1.5`,`border-l border-border pl-3`,i===`received`&&`border-border bg-accent/20`,i===`sent`&&`border-border bg-background/24`),children:[(0,W.jsxs)(`div`,{className:`flex w-full items-center gap-2 text-left`,children:[(0,W.jsxs)(V,{type:`button`,variant:`ghost`,"aria-expanded":o,onClick:()=>s(e=>!e),className:`h-auto min-w-0 flex-1 justify-start gap-2 rounded-md bg-transparent px-0 py-0 text-left text-inherit shadow-none hover:bg-transparent hover:text-inherit focus-visible:ring-2 focus-visible:ring-ring/50`,children:[(0,W.jsx)(`span`,{className:`flex size-5 shrink-0 translate-y-px items-center justify-center text-current`,children:n}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[11px] font-semibold leading-none text-foreground/88`,children:r}),a?(0,W.jsxs)(`span`,{className:`inline-flex size-5 items-center justify-center`,children:[(0,W.jsxs)(`span`,{className:`relative flex size-2.5 items-center justify-center`,children:[(0,W.jsx)(`span`,{className:`absolute inline-flex size-2.5 animate-ping rounded-full bg-ring/28`}),(0,W.jsx)(`span`,{className:`relative inline-flex size-2 rounded-full bg-ring/82`})]}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Live`})]}):null,(0,W.jsx)(l,{className:L(`size-4 shrink-0 text-muted-foreground transition-transform`,o&&`rotate-90`)})]}),(0,W.jsx)(`span`,{className:`shrink-0`,children:(0,W.jsx)(Q,{text:e})})]}),o?(0,W.jsx)(`div`,{className:`mt-2 min-w-0`,children:(0,W.jsx)(K,{content:e,parts:t,streaming:a,markdownClassName:`text-[12px] text-foreground/78`,preClassName:`text-foreground/74`})}):null]})}function Ne({item:e}){return(0,W.jsx)(Le,{label:`Thinking`,icon:(0,W.jsx)(E,{className:`size-3.5 text-foreground/72`}),streaming:e.streaming,defaultOpen:e.streaming??!1,children:(0,W.jsx)(K,{content:e.content,streaming:e.streaming,markdownClassName:`text-[13px] text-foreground/80`,preClassName:`text-foreground/75`})})}function Pe({item:e}){let t=e.tool_name===`idle`,n=!!e.streaming&&!t,r=G(e.arguments)??``,i=G(e.result);return(0,W.jsx)(Le,{label:Re(e.tool_name),icon:(0,W.jsx)(p,{className:`size-3.5 text-muted-foreground`}),streaming:n,defaultOpen:n,children:(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,W.jsx)(`div`,{className:`text-[10px] font-medium text-muted-foreground/80`,children:`Arguments`}),(0,W.jsx)(`pre`,{className:`select-text whitespace-pre-wrap break-words rounded-xl border border-border bg-background/40 px-3.5 py-3 text-[11px] font-mono leading-relaxed text-foreground/78`,children:r})]}),e.result||!t?(0,W.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,W.jsx)(`div`,{className:`text-[10px] font-medium text-muted-foreground/80`,children:`Result`}),e.result?(0,W.jsx)(K,{content:i??e.result,streaming:n,markdownClassName:`text-[12px] leading-relaxed text-foreground/80`,preClassName:`text-foreground/74`}):(0,W.jsx)(`div`,{className:`rounded-xl border border-border bg-accent/15 px-3.5 py-3 text-[12px] italic text-muted-foreground`,children:n?`Running...`:`No result`})]}):null]})})}function Fe({item:e}){return(0,W.jsxs)(`div`,{className:`min-w-0 w-full space-y-3 border-l border-graph-status-running/30 bg-graph-status-running/[0.08] px-3 py-2.5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(w,{className:`size-4 text-graph-status-running`}),(0,W.jsx)(`span`,{className:`text-[11px] font-medium text-graph-status-running/90`,children:`Command Result`}),e.command_name?(0,W.jsx)(`span`,{className:`rounded-full border border-graph-status-running/14 bg-background/35 px-2 py-0.5 font-mono text-[10px] text-graph-status-running/80`,children:e.command_name}):null,(0,W.jsx)(`span`,{className:`ml-auto`,children:(0,W.jsx)(Q,{text:e.content??``,className:`text-graph-status-running/72 hover:bg-graph-status-running/[0.1] hover:text-graph-status-running`,iconClassName:`text-current`,copiedClassName:`text-graph-status-running`})})]}),(0,W.jsx)(K,{content:e.content,markdownClassName:`text-[13px] text-foreground`,preClassName:`text-foreground/90`})]})}function Ie({content:e}){return(0,W.jsxs)(`div`,{className:`min-w-0 w-full space-y-3 border-l-2 border-graph-status-error/40 bg-graph-status-error/[0.1] px-3 py-2.5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(f,{className:`size-4 text-graph-status-error`}),(0,W.jsx)(`span`,{className:`text-[11px] font-medium text-graph-status-error`,children:`Error`}),(0,W.jsx)(`span`,{className:`ml-auto`,children:(0,W.jsx)(Q,{text:e,className:`text-graph-status-error/72 hover:bg-graph-status-error/[0.1] hover:text-graph-status-error`,iconClassName:`text-current`,copiedClassName:`text-graph-status-error`})})]}),(0,W.jsx)(`p`,{className:`select-text whitespace-pre-wrap break-words text-[13px] leading-relaxed text-graph-status-error/82`,children:e})]})}function Le({label:e,icon:t,streaming:n,defaultOpen:r,children:i}){let[a,o]=(0,U.useState)(r);return(0,W.jsxs)(`div`,{className:`min-w-0 w-full border-l border-border py-1.5 pl-3 transition-all duration-300`,children:[(0,W.jsxs)(V,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>o(e=>!e),className:`h-auto w-full justify-start gap-2 px-0 py-0 text-left hover:bg-transparent hover:text-inherit`,children:[(0,W.jsx)(`span`,{className:`flex size-5 shrink-0 translate-y-px items-center justify-center text-muted-foreground`,children:t}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,W.jsx)(`span`,{className:`block truncate text-[11px] font-medium text-muted-foreground`,children:e})}),n?(0,W.jsxs)(`span`,{className:`ml-auto inline-flex size-5 items-center justify-center`,children:[(0,W.jsxs)(`span`,{className:`relative flex size-2.5 items-center justify-center`,children:[(0,W.jsx)(`span`,{className:`absolute inline-flex size-2.5 animate-ping rounded-full bg-ring/30`}),(0,W.jsx)(`span`,{className:`relative inline-flex size-2 rounded-full bg-ring/82`})]}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Live`})]}):null,(0,W.jsx)(l,{className:L(`size-3.5 shrink-0 text-muted-foreground/70 transition-transform duration-200`,a&&`rotate-90`)})]}),a?(0,W.jsx)(`div`,{className:`mt-3 min-w-0`,children:i}):null]})}function Re(e){return e?e.split(`_`).map(e=>e.length>0?`${e[0].toUpperCase()}${e.slice(1)}`:e).join(` `):`Tool Call`}function ze(e,t){return e.type===`PendingHumanMessage`||e.type===`PendingSendMessage`?e.id:`${e.type}-${e.timestamp}-${e.message_id??``}-${e.tool_call_id??``}-${t}`}function Be(){return(0,W.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center px-4 py-8`,children:(0,W.jsxs)(`div`,{className:`max-w-[220px] space-y-3 text-center`,children:[(0,W.jsx)(`div`,{className:`mx-auto flex size-11 items-center justify-center`,children:(0,W.jsx)(i,{className:`size-5 text-primary`})}),(0,W.jsx)(`div`,{className:`space-y-1`,children:(0,W.jsx)(`p`,{className:`text-sm font-medium`,children:`Start a conversation`})})]})})}function Ve(){let e=(0,U.useRef)(null),[t,n]=(0,U.useState)(0);return(0,U.useLayoutEffect)(()=>{let t=e.current;if(!t)return;let r=()=>{n(Math.ceil(t.getBoundingClientRect().height))};if(r(),typeof ResizeObserver>`u`)return;let i=new ResizeObserver(()=>{r()});return i.observe(t),()=>{i.disconnect()}},[]),{height:t,ref:e}}function He(e){return e.filter(e=>e.type===`SystemEntry`)}function Ue(e){return e>0xe8d4a51000?e:Math.round(e*1e3)}function We(e){let t=``,n=``,r=new Map,i=new Map,a=new Map,o=[];for(let s of e)switch(s.type){case`ContentDelta`:t+=s.text;break;case`ThinkingDelta`:n+=s.text;break;case`ToolResultDelta`:r.set(s.tool_call_id,(r.get(s.tool_call_id)??``)+s.text);break;case`SentMessageDelta`:i.has(s.message_id)||o.push({kind:`sent`,messageId:s.message_id}),i.set(s.message_id,{toId:s.to_id,text:(i.get(s.message_id)?.text??``)+s.text});break;case`ReceivedMessageDelta`:a.has(s.message_id)||o.push({kind:`received`,messageId:s.message_id}),a.set(s.message_id,{fromId:s.from_id,text:(a.get(s.message_id)?.text??``)+s.text});break}return{content:t,thinking:n,toolResults:r,sentMessages:i,receivedMessages:a,messageOrder:o}}function Ge(e){if(e==null)return``;if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}function Ke(e){let t=Ue(e.timestamp);switch(e.type){case`ReceivedMessage`:return e.message_id?`${e.type}:${e.message_id}`:[e.type,t,e.from_id??``,z(e.parts,e.content)].join(`:`);case`SentMessage`:return e.message_id?`${e.type}:${e.message_id}`:[e.type,t,e.to_id??e.to_ids?.[0]??``,z(e.parts,e.content)].join(`:`);case`ToolCall`:return e.tool_call_id?`${e.type}:${e.tool_call_id}`:[e.type,t,e.tool_name??``,Ge(e.arguments),e.result??``,e.streaming?`streaming`:`final`].join(`:`);default:return[e.type,t,e.content??``].join(`:`)}}function qe(e,t){return e.type!==`ToolCall`||t.type!==`ToolCall`?!1:e.streaming&&!t.streaming?!0:!e.result&&!!t.result}function Je(e){let t=[],n=new Map;for(let r of e){let e=Ke(r),i=n.get(e);if(i===void 0){n.set(e,t.length),t.push(r);continue}let a=t[i];qe(a,r)&&(t[i]=r)}return t}function Ye({history:e,incremental:t,deltas:n,fetchedAt:r}){let i=Je(t&&t.length>0?[...e,...t]:[...e]);if(!n||n.length===0)return i;let{content:a,thinking:o,toolResults:s,sentMessages:c,receivedMessages:l,messageOrder:u}=We(n),d=r/1e3;if(o&&i.push({type:`AssistantThinking`,content:o,timestamp:d,streaming:!0}),a&&i.push({type:`AssistantText`,content:a,timestamp:d,streaming:!0}),s.size>0)for(let[e,t]of s)for(let n=i.length-1;n>=0;--n){let r=i[n];if(r.type===`ToolCall`&&r.tool_call_id===e&&r.streaming){i[n]={...r,result:t};break}}for(let e of u){if(e.kind===`sent`){let t=c.get(e.messageId);if(!t||i.some(t=>t.type===`SentMessage`&&t.message_id===e.messageId))continue;i.push({type:`SentMessage`,message_id:e.messageId,to_id:t.toId,content:t.text,parts:[{type:`text`,text:t.text}],timestamp:d,streaming:!0});continue}let t=l.get(e.messageId);t&&(i.some(t=>t.type===`ReceivedMessage`&&t.message_id===e.messageId)||i.push({type:`ReceivedMessage`,message_id:e.messageId,from_id:t.fromId,content:t.text,parts:[{type:`text`,text:t.text}],timestamp:d,streaming:!0}))}return i}var Xe=`flowent.chatInputHistory`,Ze=50,Qe=new Set,$e=new Map,et=new Map;function tt(e){return`${Xe}.${e}`}function nt(e){return e.trim().length>0}function rt(e){if(!e||typeof e!=`object`)return null;let t=typeof e.text==`string`?e.text:null,n=typeof e.timestamp==`number`?e.timestamp:null;return t===null||n===null||!nt(t)?null:{text:t,images:[],timestamp:n}}function it(e){if(typeof window>`u`)return[];try{let t=window.localStorage.getItem(tt(e));if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n.map(e=>rt(e)).filter(e=>e!==null).slice(-Ze):[]}catch{return[]}}function at(e,t){if(!(typeof window>`u`))try{let n=t.filter(({text:e})=>nt(e)).map(({text:e,timestamp:t})=>({text:e,timestamp:t}));window.localStorage.setItem(tt(e),JSON.stringify(n))}catch{return}}function ot(e){Qe.has(e)||($e.set(e,it(e)),Qe.add(e))}function st(e){let t=et.get(e);if(t)for(let e of t)e()}function ct(e){return ot(e),$e.get(e)??[]}function lt(e,t){ot(e);let n=et.get(e)??new Set;return n.add(t),et.set(e,n),()=>{let n=et.get(e);n?.delete(t),n&&n.size===0&&et.delete(e)}}function ut(e,t){ot(e);let n=[...$e.get(e)??[],t].slice(-Ze);$e.set(e,n),at(e,n),st(e)}var dt=10;function ft(e){return Math.max(0,e.scrollHeight-e.clientHeight)-e.scrollTop<=dt}function pt(){return globalThis.crypto?.randomUUID?.()??`draft-${Date.now()}-${Math.random()}`}function mt(e){return e.status===`ready`&&!!e.assetId}function ht(e){e.previewUrl.startsWith(`blob:`)&&URL.revokeObjectURL(e.previewUrl)}function gt(e){for(let t of e)ht(t)}function _t(e){return e.filter(mt).map(e=>({assetId:e.assetId,mimeType:e.mimeType,width:e.width,height:e.height,name:e.name}))}function vt(e){return e.images.map((t,n)=>({id:`history-${e.timestamp}-${n}`,assetId:t.assetId,previewUrl:me(t.assetId),mimeType:t.mimeType,width:t.width,height:t.height,name:t.name,status:`ready`}))}function yt(e,t){return e.length===t.images.length?t.images.every((t,n)=>{let r=e[n];return!!r&&r?.status===`ready`&&r.assetId===t.assetId&&r.mimeType===t.mimeType&&r.width===t.width&&r.height===t.height&&r.name===t.name}):!1}function bt(e,t){let n=[];e&&n.push({type:`text`,text:e});for(let e of t)n.push({type:`image`,asset_id:e.assetId,mime_type:e.mimeType,width:e.width,height:e.height,alt:e.name});return n}function xt(e,t,n){return{id:`pending-${n}-${Math.random().toString(36).slice(2,8)}`,type:`PendingHumanMessage`,from:`human`,content:e,parts:t,timestamp:n,message_id:null}}function St(e){return{id:`pending-send-${e.timestamp}-${Math.random().toString(36).slice(2,8)}`,type:`PendingSendMessage`,from:`human`,content:e.content,parts:e.parts,timestamp:e.timestamp,message_id:null,target_id:e.targetId,target_state:e.targetState??null,history_entry:e.historyEntry,history_entry_scope:e.historyScope,send_failed:e.sendFailed}}async function Ct(e){return new Promise(t=>{let n=URL.createObjectURL(e),r=new Image;r.onload=()=>{let e=r.naturalWidth,i=r.naturalHeight;URL.revokeObjectURL(n),t(e>0&&i>0?{width:e,height:i}:null)},r.onerror=()=>{URL.revokeObjectURL(n),t(null)},r.src=n})}async function wt(e){return Promise.all(e.map(async e=>{let t=await Ct(e);return{id:pt(),assetId:null,previewUrl:URL.createObjectURL(e),mimeType:e.type||null,width:t?.width??null,height:t?.height??null,name:e.name,status:`uploading`}}))}var Tt=(0,U.memo)(function({agentLabel:e=`Agent`,history:t,nodes:n}){return(0,W.jsx)(`div`,{className:`space-y-1.5 p-2.5`,children:t.map((t,r)=>(0,W.jsx)(`div`,{className:`[content-visibility:auto] [contain-intrinsic-size:auto_100px]`,children:(0,W.jsx)(jt,{agentLabel:e,entry:t,nodes:n})},`${r}-${t.timestamp}-${t.type}-${t.message_id??``}-${t.tool_call_id??``}`))})});function Et({content:e,markdownClassName:t,preClassName:n,streaming:r}){let i=G(e);return i?(0,W.jsx)(`pre`,{className:L(`select-text text-[11px] whitespace-pre-wrap break-words leading-relaxed`,n),children:(0,W.jsx)(Dt,{text:i,streaming:r})}):r?(0,W.jsx)(`pre`,{className:L(`select-text text-[11px] whitespace-pre-wrap break-words leading-relaxed`,n),children:(0,W.jsx)(Dt,{text:e??``,streaming:!0})}):(0,W.jsx)(_e,{content:e??``,className:L(`text-[11px] leading-relaxed`,t)})}function Dt({text:e,streaming:t}){return(0,W.jsxs)(W.Fragment,{children:[e,t&&(0,W.jsx)(`span`,{className:`streaming-cursor`})]})}function Ot({entry:e,markdownClassName:t,preClassName:n}){let r=P(e.parts,e.content);return r.length===0?null:r.every(e=>e.type===`text`)?(0,W.jsx)(Et,{content:z(r),streaming:e.streaming,markdownClassName:t,preClassName:n}):(0,W.jsx)(`div`,{className:`space-y-2`,children:r.map((e,r)=>e.type===`text`?(0,W.jsx)(Et,{content:e.text,markdownClassName:t,preClassName:n},`${r}-${e.type}`):(0,W.jsx)(ge,{alt:e.alt,assetId:e.asset_id,compact:!0,height:e.height,mimeType:e.mime_type,width:e.width},`${r}-${e.type}-${e.asset_id}`))})}function kt(e){return!e.from_output_port_key||!e.to_input_port_key?``:` · ${e.from_output_port_key} to ${e.to_input_port_key}`}function At(e){if(e.value_summary)return e.value_summary;if(e.content)return e.content;if(e.value===void 0)return``;if(typeof e.value==`string`)return e.value;try{return JSON.stringify(e.value)}catch{return String(e.value)}}var jt=(0,U.memo)(function({agentLabel:e,entry:t,nodes:n}){switch(t.type){case`SystemEntry`:return(0,W.jsx)($,{label:`System`,icon:(0,W.jsx)(D,{className:`size-3 text-muted-foreground`}),className:`border-border/40 bg-surface-1/24`,defaultOpen:!1,children:(0,W.jsx)(Et,{content:t.content,markdownClassName:`text-muted-foreground`,preClassName:`text-muted-foreground leading-relaxed`})});case`ReceivedMessage`:return(0,W.jsx)($,{label:`From ${I(t.from_id??``,n)}${kt(t)}`,icon:(0,W.jsx)(i,{className:`size-3 text-foreground/70`}),className:`border-border bg-accent/20`,labelClassName:`text-foreground/70`,actions:(0,W.jsx)(Q,{text:z(t.parts,t.content)}),defaultOpen:t.streaming??!1,children:(0,W.jsx)(Ot,{entry:t,markdownClassName:`text-foreground/90`,preClassName:`text-foreground/90 leading-relaxed`})});case`AssistantThinking`:return(0,W.jsx)($,{label:`Thinking`,icon:(0,W.jsx)(E,{className:`size-3 text-foreground/72`}),className:`border-border bg-surface-1/28`,labelClassName:`text-foreground/72`,defaultOpen:!1,children:(0,W.jsx)(Et,{content:t.content,streaming:t.streaming,markdownClassName:`text-foreground/82`,preClassName:`text-foreground/82 leading-relaxed`})});case`SentMessage`:return(0,W.jsx)($,{label:`To ${(t.to_id==null?(t.to_ids??[]).filter(e=>!!e):[t.to_id]).map(e=>I(e,n)).join(`, `)||`Unknown`}${kt(t)}`,icon:(0,W.jsx)(T,{className:`size-3 text-foreground/58`}),className:`border-border bg-background/24`,labelClassName:`text-foreground/72`,actions:(0,W.jsx)(Q,{text:z(t.parts,t.content)}),defaultOpen:t.streaming??!1,children:(0,W.jsx)(Ot,{entry:t,markdownClassName:`text-foreground/86`,preClassName:`text-foreground/86 leading-relaxed`})});case`PortInboundEntry`:return(0,W.jsx)($,{label:`Input from ${t.source_label||I(t.from_id??``,n)}${kt(t)}`,icon:(0,W.jsx)(A,{className:`size-3 text-foreground/66`}),className:`border-border bg-surface-1/24`,labelClassName:`text-foreground/72`,actions:(0,W.jsx)(Q,{text:At(t)}),defaultOpen:!1,children:(0,W.jsxs)(`div`,{className:`space-y-2`,children:[t.port_type?(0,W.jsx)(`span`,{className:`inline-flex rounded-md border border-border bg-background/40 px-2 py-0.5 font-mono text-[10px] text-muted-foreground`,children:t.port_type}):null,(0,W.jsx)(Et,{content:At(t),markdownClassName:`text-foreground/86`,preClassName:`text-foreground/86 leading-relaxed`})]})});case`AssistantText`:return(0,W.jsx)($,{label:e,icon:(0,W.jsx)(y,{className:`size-3 text-foreground/84`}),className:`border-border bg-surface-2/62`,labelClassName:`text-foreground/84`,actions:(0,W.jsx)(Q,{text:t.content??``}),defaultOpen:!1,children:(0,W.jsx)(Ot,{entry:t,markdownClassName:`text-foreground/88`,preClassName:`text-foreground/88 leading-relaxed`})});case`ToolCall`:{let e=G(t.arguments)??``,n=G(t.result);return(0,W.jsx)($,{label:t.tool_name??`tool`,icon:(0,W.jsx)(p,{className:`size-3 text-foreground/66`}),className:`border-border bg-surface-1/20`,labelClassName:`text-foreground/72`,defaultOpen:!1,children:(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-1`,children:`Arguments`}),(0,W.jsx)(`pre`,{className:`select-text text-[11px] whitespace-pre-wrap break-words leading-relaxed text-foreground/78`,children:e})]}),t.result&&(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-1`,children:`Result`}),(0,W.jsx)(Et,{content:n??t.result,streaming:t.streaming,markdownClassName:`text-muted-foreground`,preClassName:`text-muted-foreground leading-relaxed`})]})]})})}case`ErrorEntry`:return(0,W.jsx)($,{label:`Error`,icon:(0,W.jsx)(f,{className:`size-3 text-graph-status-error/84`}),className:`border-graph-status-error/16 bg-graph-status-error/[0.038]`,labelClassName:`text-graph-status-error/78`,actions:(0,W.jsx)(Q,{text:t.content??``,className:`text-graph-status-error/84 hover:text-graph-status-error/84`,iconClassName:`text-graph-status-error/84`,copiedClassName:`text-graph-status-error/84`}),defaultOpen:!1,children:(0,W.jsx)(Et,{content:t.content,markdownClassName:`text-graph-status-error/84`,preClassName:`text-graph-status-error/84 leading-relaxed`})});default:return null}});function $({actions:e,label:t,labelClassName:n,icon:r,className:i,contentClassName:a,defaultOpen:o=!1,children:s}){let[c,u]=(0,U.useState)(o),d=(0,U.useCallback)(()=>u(e=>!e),[]);return(0,W.jsxs)(`div`,{className:L(`rounded-xl border transition-colors hover:bg-accent/20`,i),children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 select-none`,children:[(0,W.jsxs)(V,{type:`button`,variant:`ghost`,"aria-expanded":c,onClick:d,className:`h-auto min-w-0 flex-1 justify-start gap-2 rounded-md bg-transparent px-0 py-0 text-left text-inherit shadow-none hover:bg-transparent hover:text-inherit focus-visible:ring-2 focus-visible:ring-ring/50`,children:[(0,W.jsx)(`span`,{className:`shrink-0 flex items-center justify-center`,children:r}),(0,W.jsx)(`span`,{className:L(`min-w-0 flex-1 truncate text-[11px] font-medium`,n||`text-muted-foreground`),children:t}),(0,W.jsx)(l,{className:L(`ml-2 size-3.5 shrink-0 text-muted-foreground/70 transition-transform duration-200`,c&&`rotate-90`)})]}),e?(0,W.jsx)(`span`,{className:`shrink-0 flex items-center leading-none`,children:e}):null]}),(0,W.jsx)(R,{initial:!1,children:c?(0,W.jsx)(m.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`,children:(0,W.jsx)(`div`,{className:L(`px-3 pb-3 pt-1`,a),children:s})}):null})]})}var Mt=B(`inline-flex h-5 items-center justify-center rounded-full border border-transparent px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden`,{variants:{variant:{default:`bg-primary text-primary-foreground [a&]:hover:bg-primary/90`,secondary:`bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90`,destructive:`bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60`,outline:`border-border text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground`,ghost:`[a&]:hover:bg-accent [a&]:hover:text-accent-foreground`,link:`text-primary underline-offset-4 [a&]:hover:underline`}},defaultVariants:{variant:`default`}});function Nt({className:e,variant:t=`default`,asChild:n=!1,...r}){return(0,W.jsx)(n?d:`span`,{"data-slot":`badge`,"data-variant":t,className:L(Mt({variant:t}),e),...r})}function Pt(e,t=!1){let[n,r]=(0,U.useState)(null),[i,a]=(0,U.useState)(!1),[o,s]=(0,U.useState)(null),[c,l]=(0,U.useState)(0),{agents:u}=ae(),{agentHistories:d,clearAgentHistory:f,clearHistorySnapshot:p,historyInvalidatedAt:m,historyClearedAt:h,historySnapshots:g,streamingDeltas:_}=oe(),v=e?h.get(e)??0:0,y=e?m.get(e)??0:0,b=e?g.get(e)??null:null;return(0,U.useEffect)(()=>{v&&(r(e=>e&&{...e,history:He(e.history)}),l(Date.now()))},[v]),(0,U.useEffect)(()=>{!y||!b||(r(e=>e&&{...e,history:b}),l(Date.now()))},[y,b]),(0,U.useEffect)(()=>{if(!e){r(null),a(!1),s(null);return}let n=new AbortController,i=!1;return(async()=>{a(!0),s(null),t||f(e);try{let t=await N(e,n.signal);if(i)return;r(t),l(Date.now()),p(e)}catch(e){if(i||n.signal.aborted)return;r(null),s(e instanceof Error?e.message:`Failed to fetch node detail`)}finally{i||a(!1)}})(),()=>{i=!0,n.abort()}},[e,f,p,y,t]),{detail:(0,U.useMemo)(()=>{if(!n||!e)return null;let t=d.get(e),r=_.get(e),i=Ye({history:b??n.history,incremental:t,deltas:r,fetchedAt:c}),a=e?u.get(e):void 0,o={...n,history:i};return a&&(o.state=a.state,o.todos=a.todos),o},[n,e,d,b,_,u,c]),loading:i,error:o,fetchedAt:c}}function Ft(e,t){return t?.leader_id?e.get(t.leader_id)??null:null}function It(e={}){let{bottomInset:t=0}=e,{agents:n}=ae(),{tabs:r}=re(),{connected:i}=ce(),{agentHistories:a,clearAgentHistory:o,clearHistorySnapshot:s,historyInvalidatedAt:c,historyClearedAt:l,historySnapshots:u,streamingDeltas:d}=oe(),{activeToolCalls:f}=le(),{activeTabId:p}=de(),m=p?r.get(p)??null:null,h=(0,U.useMemo)(()=>Ft(n,m),[m,n]),g=h?.id??m?.leader_id??null,_=p?`leader:${p}`:`leader:none`,[v,y]=(0,U.useState)(null),[b,S]=(0,U.useState)(0),[C,w]=(0,U.useState)(``),[T,E]=(0,U.useState)([]),[D,O]=(0,U.useState)(null),[k,A]=(0,U.useState)(!1),[F,ne]=(0,U.useState)(!1),[I,ie]=(0,U.useState)(null),[L,R]=(0,U.useState)([]),[se,B]=(0,U.useState)(()=>new Map),V=(0,U.useRef)(null),fe=(0,U.useRef)(!0),pe=(0,U.useRef)([]),H=(0,U.useRef)(new Map),me=(0,U.useRef)(new Set),W=h?.capabilities?.input_image??!1,ge=g?l.get(g)??0:0,_e=g?c.get(g)??0:0,G=g?u.get(g)??null:null,K=T.some(e=>e.status===`uploading`),ve=T.filter(mt),q=(0,U.useSyncExternalStore)(e=>lt(_,e),()=>ct(_),()=>ct(_)),ye=D===null?null:q[D]??null,be=ye!==null&&C===ye.text&&yt(T,ye),J=h?.state??v?.state??null,Y=(0,U.useCallback)(async e=>{let t=e.pendingMessageTimestamp??Date.now(),n=xt(e.content,e.parts,t),r=e.visiblePending??!0;ne(!0),r&&R(e=>[...e,n]);try{let i=await M(e.targetId,{content:e.content,parts:e.parts});return r&&i.status===`command_executed`?R(n=>j(n,{content:e.content,timestamp:t})):r&&R(e=>e.map(e=>e.id===n.id?{...e,message_id:i.message_id??null}:e)),ut(e.history.scope,e.history.entry),e.restoreDraft&&gt(e.restoreDraft.images),!0}catch(t){return r&&R(e=>e.filter(e=>e.id!==n.id)),e.restoreDraft&&(w(e.restoreDraft.input),E(e.restoreDraft.images),O(e.restoreDraft.historyCursor)),x.error(t instanceof Error?t.message:`Failed to send message`),!1}finally{ne(!1)}},[]),X=(0,U.useCallback)((e,t)=>{O(t),w(e?.text??``),E(e?vt(e):[])},[]),xe=(0,U.useCallback)(e=>{O(null),w(e)},[]);(0,U.useEffect)(()=>{pe.current=T},[T]),(0,U.useEffect)(()=>{H.current=se},[se]),(0,U.useEffect)(()=>()=>{gt(pe.current)},[]),(0,U.useEffect)(()=>{gt(pe.current),w(``),E([]),O(null),R([]),ie(null)},[_]),(0,U.useEffect)(()=>{ge&&(R([]),g&&B(e=>{if(!e.has(g))return e;let t=new Map(e);return t.delete(g),t}),y(e=>e&&{...e,history:He(e.history)}),S(Date.now()))},[ge,g]),(0,U.useEffect)(()=>{!_e||!G||(y(e=>e&&{...e,history:G}),S(Date.now()))},[_e,G]),(0,U.useEffect)(()=>{H.current.size!==0&&B(e=>{let t=null;for(let[r,i]of e){if(i.send_failed)continue;let a=r===g?J:n.get(r)?.state??i.target_state??null;i.target_state!==a&&(t??=new Map(e),t.set(r,{...i,target_state:a}))}return t??e})},[n,g,J,se]),(0,U.useEffect)(()=>{if(!(H.current.size===0||F))for(let[e,t]of H.current)t.send_failed||(e===g?J:n.get(e)?.state??t.target_state??null)!==`idle`||me.current.has(e)||(me.current.add(e),B(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n}),Y({content:t.content,parts:t.parts??[],targetId:e,visiblePending:e===g,history:{scope:t.history_entry_scope,entry:t.history_entry},pendingMessageTimestamp:t.timestamp}).then(n=>{me.current.delete(e),n||B(n=>{let r=new Map(n);return r.set(e,{...t,send_failed:!0,target_state:`error`}),r})}).catch(()=>{me.current.delete(e),B(n=>{let r=new Map(n);return r.set(e,{...t,send_failed:!0,target_state:`error`}),r})}))},[n,g,J,se,F,Y]),(0,U.useEffect)(()=>{if(!i||!g){y(null);return}let e=new AbortController,t=!1;return(async()=>{o(g);try{let n=await N(g,e.signal);if(t||!n)return;y(n),S(Date.now()),s(g)}catch{!t&&!e.signal.aborted&&x.error(`Failed to load Leader history`)}})(),()=>{t=!0,e.abort()}},[o,s,i,ge,_e,g]);let Se=(0,U.useMemo)(()=>g?Ye({history:G??v?.history??[],incremental:a.get(g),deltas:d.get(g),fetchedAt:b||Date.now()}):[],[a,v,b,G,g,d]);(0,U.useEffect)(()=>{if(!g||L.length===0)return;let e=new Set(Se.filter(e=>e.type===`ReceivedMessage`&&e.from_id===`human`&&typeof e.message_id==`string`).map(e=>e.message_id));e.size!==0&&R(t=>t.filter(t=>!t.message_id||!e.has(t.message_id)))},[g,Se,L.length]);let Ce=g?se.get(g)??null:null,Z=(0,U.useMemo)(()=>[...Se,...Ce?[{...Ce}]:[],...L.map(e=>({...e}))],[Ce,Se,L]),we=(0,U.useMemo)(()=>{let e=L.length+ +!!Ce,t=g?d.get(g)??[]:[],n=i&&!!(g&&(e>0||h?.state===`running`||h?.state===`sleeping`||f.has(g)||t.length>0)),r=[...Z].map((e,t)=>({item:e,index:t})).reverse().find(({item:e})=>e.type===`PendingHumanMessage`?!0:e.type===`ReceivedMessage`&&e.from_id===`human`&&P(e.parts,e.content).length>0)?.index,a=r===void 0?[]:Z.slice(r+1),o=a.some(e=>e.type===`AssistantText`&&P(e.parts,e.content).length>0),s=[...a].reverse().find(e=>e.type===`ToolCall`&&e.streaming===!0),c=(g?f.get(g)??null:null)??s?.tool_name??null;return{running:n,runningHint:n&&r!==void 0&&!o?{label:c?`Running tools...`:`Thinking...`,toolName:c}:null}},[f,i,g,h?.state,Ce,L.length,d,Z]);(0,U.useLayoutEffect)(()=>{let e=V.current;!e||!fe.current||(e.scrollTop=e.scrollHeight)},[t,we.runningHint?`${we.runningHint.label}:${we.runningHint.toolName??``}`:``,Z]),(0,U.useLayoutEffect)(()=>{let e=V.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{fe.current&&(e.scrollTop=e.scrollHeight)});return t.observe(e),()=>{t.disconnect()}},[]);let Te=e=>{fe.current=ft(e.currentTarget)},Q=async(e={})=>{if(!g)return;let t=C.trim();if(!t&&ve.length===0||K||F)return;let n=bt(t,ve),r=C,i=T,a=D,o=Date.now(),s=t||z(n),c={text:r,images:_t(i),timestamp:o},l=e.deferWhenBusy&&H.current.has(g)&&(J===`error`||J===`terminated`);if(e.deferWhenBusy&&(J===`running`||J===`sleeping`||l)){B(e=>{let t=new Map(e);return t.set(g,St({content:s,historyEntry:c,historyScope:_,parts:n,targetId:g,targetState:J,timestamp:o})),t}),O(null),w(``),E([]),gt(i);return}if(J===`terminated`){x.error(`Resolve the current chat before sending`);return}O(null),w(``),E([]),await Y({content:s,parts:n,targetId:g,history:{scope:_,entry:c},pendingMessageTimestamp:o,restoreDraft:{input:r,images:i,historyCursor:a}})},Ee=(0,U.useCallback)(async e=>{if(O(null),!W){x.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 wt(t);E(e=>[...e,...n]),await Promise.all(n.map(async(e,n)=>{let r=t[n];if(r)try{let t=await he(r);E(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){ht(e),E(t=>t.filter(t=>t.id!==e.id)),x.error(t instanceof Error?t.message:`Failed to upload image`)}}))},[W]),De=(0,U.useCallback)(e=>{O(null),E(t=>{let n=t.find(t=>t.id===e);return n&&ht(n),t.filter(t=>t.id!==e)})},[]),Oe=(0,U.useCallback)((e,t)=>{if(q.length===0)return!1;let n=t.start,r=t.end,i=C.length===0&&T.length===0,a=typeof n==`number`&&typeof r==`number`&&n===r&&(n===0||n===C.length);if(!i&&!(ye!==null&&be&&a))return!1;if(D===null){if(e!==-1)return!1;let t=q.length-1;return X(q[t]??null,t),!0}if(e===-1){let e=Math.max(D-1,0);return X(q[e]??null,e),!0}if(D>=q.length-1)return X(null,null),!0;let o=D+1;return X(q[o]??null,o),!0},[ye,T,D,C,q,be,X]),ke=(0,U.useCallback)(async()=>{if(g&&!(h?.state!==`running`&&h?.state!==`sleeping`)){await ue(g);for(let e=0;e<25;e+=1){let e=await N(g);if(!e)break;if(y(e),S(Date.now()),e.state!==`running`&&e.state!==`sleeping`)return;await new Promise(e=>window.setTimeout(e,120))}throw Error(`Leader did not stop in time`)}},[g,h?.state]),Ae=async()=>{if(!(!g||k)){A(!0);try{await te(g),R([]),B(e=>{if(!e.has(g))return e;let t=new Map(e);return t.delete(g),t}),o(g);let e=await N(g);e&&(y(e),S(Date.now()),s(g))}catch(e){x.error(e instanceof Error?e.message:`Failed to clear chat`)}finally{A(!1)}}},je=(0,U.useCallback)(async e=>{if(!(!g||!e||I)){ie(e);try{try{await ke(),await ee(g,e)}catch(e){x.error(e instanceof Error?e.message:`Failed to retry Leader message`);return}o(g);try{let e=await N(g);e&&(y(e),S(Date.now()),s(g))}catch{return}}finally{ie(null)}}},[o,s,g,I,ke]);return{activeTab:m,addImages:Ee,cancelPendingSend:(0,U.useCallback)(e=>{B(t=>{let n=Array.from(t.entries()).find(([,t])=>t.id===e);if(!n)return t;let r=new Map(t);return r.delete(n[0]),r})},[]),connected:i,clearChat:Ae,clearing:k,draftImages:T,handleKeyDown:e=>{if(e.key===`Tab`&&!e.shiftKey){(C.trim()||ve.length>0)&&(e.preventDefault(),Q({deferWhenBusy:!0}));return}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Q())},hasUploadingImages:K,input:C,isBrowsingInputHistory:be,leaderActivity:we,leaderNode:h,navigateInputHistory:Oe,onMessagesScroll:Te,removeImage:De,retryMessage:je,retryingMessageId:I,scrollRef:V,sendMessage:Q,sendPendingSend:(0,U.useCallback)(async e=>{let t=Array.from(H.current.entries()).find(([,t])=>t.id===e);if(!t||F||me.current.has(t[0]))return;let[r,i]=t;(r===g?J:n.get(r)?.state??i.target_state??null)!==`terminated`&&(B(e=>{if(!e.has(r))return e;let t=new Map(e);return t.delete(r),t}),await Y({content:i.content,parts:i.parts??[],targetId:r,visiblePending:r===g,history:{scope:i.history_entry_scope,entry:i.history_entry},pendingMessageTimestamp:i.timestamp})||B(e=>{let t=new Map(e);return t.set(r,{...i,send_failed:!0,target_state:`error`}),t}))},[n,g,J,F,Y]),sending:F,setInput:xe,stopLeader:ke,supportsInputImage:W,timelineItems:Z}}var Lt={assistant:v,agent:y,trigger:O,llm:w,code:s,if:A,merge:c};function Rt({name:e,roleName:t,nodeType:n,isLeader:r=!1}){return e??t??(n===`assistant`?`Assistant`:n===`trigger`?`Trigger`:n===`llm`?`Model`:n===`code`?`Code`:n===`if`?`If`:n===`merge`?`Merge`:r?`Leader`:`Agent`)}var zt={running:`bg-graph-status-running`,idle:`bg-graph-status-idle`,sleeping:`bg-graph-status-sleeping`,initializing:`bg-graph-status-initializing`,error:`bg-graph-status-error`,terminated:`bg-graph-status-terminated`},Bt={running:`agent-state-ring-running`,idle:`agent-state-ring-idle`,sleeping:`agent-state-ring-sleeping`,initializing:`agent-state-ring-initializing`,error:`agent-state-ring-error`,terminated:`agent-state-ring-terminated`},Vt=`rounded-md bg-accent/45 px-2 py-1 text-xs text-foreground`,Ht={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 Ut({children:e,disabled:t=!1,active:n=!1,onClick:r}){return(0,W.jsx)(V,{type:`button`,variant:`ghost`,size:`xs`,onClick:r,disabled:t,className:L(`flex shrink-0 items-center gap-1.5 whitespace-nowrap rounded-md border border-transparent bg-transparent px-3 py-1.75 text-[11px] font-medium text-muted-foreground transition-[background-color,border-color,color] duration-150 hover:border-border hover:bg-accent/45 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:border-transparent disabled:text-muted-foreground/50 disabled:hover:bg-transparent`,n&&`border-border bg-accent/70 text-foreground`),children:e})}function Wt(){return(0,W.jsx)(`div`,{"aria-hidden":`true`,className:`h-4 w-px shrink-0 bg-border`})}function Gt({children:e,tone:t=`default`}){return(0,W.jsx)(`div`,{className:L(`pointer-events-auto relative isolate flex items-center gap-1.5 rounded-full border border-border bg-surface-overlay/80 px-2.5 py-1 text-[11px] font-medium text-muted-foreground backdrop-blur-sm`,t===`primary`?`border-border bg-accent/60 text-foreground`:``),children:e})}function Kt({agent:e,onClose:t}){let[n,r]=(0,U.useState)(!1),{agents:i}=ae(),{tabs:a}=re(),s=e.node_type!==`assistant`&&e.node_type!==`agent`,{detail:c,error:l,loading:u}=Pt(s?null:e.id,e.node_type===`assistant`),d=c?.state??e.state,f=c?.is_leader??e.is_leader,p=c?.contacts??[],m=c?.connections??e.connections,h=c?.todos??e.todos,g=c?.history??[],_=c?.role_name??e.role_name,v=c?.tools??[],y=c?.write_dirs??[],b=c?.allow_network??!1,S=c?.tab_id??e.tab_id??null,C=S?a.get(S)??null:null,w=e.node_type===`assistant`,T=c?.workflow_permissions??null,E=w?b:C?.allow_network??T?.allow_network??b??!1,D=w?y:C?.write_dirs??T?.write_dirs??y,O=w?`Permissions`:`Workflow Permissions`,k=Rt({name:e.name,roleName:e.role_name,nodeType:e.node_type,isLeader:e.is_leader}),A=Lt[e.node_type],j=m.map(e=>{let t=i.get(e);return{id:e,label:t?Rt({name:t.name,roleName:t.role_name,nodeType:t.node_type,isLeader:t.is_leader}):e.slice(0,8)}}),M=p.filter(qt),ee=p.filter(e=>!qt(e)).map(e=>{let t=typeof e==`string`?e:e.id;return{id:t,label:Jt(e,i.get(t))}}),N=M.length>0?`reachable paths`:`reachable contacts`;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border px-3.5 py-2.5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`div`,{className:`flex size-7 items-center justify-center rounded-md bg-primary/8`,children:(0,W.jsx)(A,{className:`size-3.5 text-primary`})}),(0,W.jsxs)(`div`,{className:`min-w-0 flex flex-wrap items-center gap-2`,children:[(0,W.jsx)(`p`,{className:`text-[13px] font-semibold`,children:k}),f?(0,W.jsx)(`span`,{className:`rounded-full border border-accent bg-accent/45 px-2 py-0.5 text-[10px] font-semibold text-accent-foreground`,children:`Leader`}):null,(0,W.jsx)(`span`,{className:`rounded-full border border-border bg-accent/35 px-2 py-0.5 font-mono text-[10px] text-muted-foreground/78`,children:e.id.slice(0,8)})]})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[d===`running`||d===`sleeping`?(0,W.jsx)(V,{type:`button`,size:`sm`,variant:`destructive`,disabled:n,onClick:()=>{r(!0),ue(e.id).catch(()=>{x.error(`Failed to interrupt node`)}).finally(()=>{r(!1)})},children:n?`Interrupting...`:`Interrupt`}):null,(0,W.jsx)($t,{title:`Close details`,onClick:t,children:(0,W.jsx)(o,{className:`size-4`})})]})]}),(0,W.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3.5`,children:(0,W.jsxs)(`div`,{className:`space-y-3.5`,children:[(0,W.jsxs)(`div`,{className:`grid gap-3.5 border-b border-border pb-3.5 sm:grid-cols-3`,children:[(0,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsx)(`p`,{className:`text-[10px] font-semibold text-muted-foreground`,children:`Status`}),(0,W.jsx)(`div`,{className:`mt-2`,children:(0,W.jsx)(Nt,{variant:`outline`,className:Ht[d],children:d.toUpperCase()})})]}),(0,W.jsxs)(`div`,{className:`min-w-0 sm:border-l sm:border-border sm:pl-3.5`,children:[(0,W.jsx)(`p`,{className:`text-[10px] font-semibold text-muted-foreground`,children:`Contacts`}),(0,W.jsxs)(`p`,{className:`mt-2 select-text text-sm text-foreground`,children:[p.length,` `,N]})]}),(0,W.jsxs)(`div`,{className:`min-w-0 sm:border-l sm:border-border sm:pl-3.5`,children:[(0,W.jsx)(`p`,{className:`text-[10px] font-semibold text-muted-foreground`,children:`Workflow`}),(0,W.jsx)(`p`,{className:`mt-2 select-text text-sm text-foreground`,children:C?.title??S?.slice(0,8)??`None`})]})]}),(0,W.jsx)(H,{title:`Workflow Context`,children:S?(0,W.jsxs)(`div`,{className:`grid gap-3 text-sm sm:grid-cols-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`p`,{className:`text-[10px] font-semibold text-muted-foreground`,children:`ID`}),(0,W.jsx)(`p`,{className:`mt-1 select-text font-mono text-[11px] text-foreground`,children:S??`None`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`p`,{className:`text-[10px] font-semibold text-muted-foreground`,children:`Title`}),(0,W.jsx)(`p`,{className:`mt-1 select-text text-foreground`,children:C?.title??`Unknown`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`p`,{className:`text-[10px] font-semibold text-muted-foreground`,children:`Role`}),(0,W.jsx)(`p`,{className:`mt-1 select-text text-foreground`,children:_??`None`})]})]}):(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No workflow metadata`})}),s?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(H,{title:`Workflow Permissions`,children:(0,W.jsx)(en,{allowNetwork:E,writeDirs:D,inherited:!w})}),(0,W.jsx)(H,{title:`Ports`,children:[...e.inputs??[],...e.outputs??[]].length===0?(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No ports`}):(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:[...e.inputs??[],...e.outputs??[]].map(e=>(0,W.jsxs)(`span`,{className:L(Vt,`select-text`),children:[e.direction===`in`?`Input`:`Output`,` ·`,` `,e.key,` · `,e.type]},`${e.direction}-${e.key}`))})}),(0,W.jsx)(H,{title:`Settings`,children:Object.keys(e.config??{}).length===0?(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No settings`}):(0,W.jsx)(`pre`,{className:`max-h-56 overflow-auto rounded-md border border-border bg-background/40 p-3 text-[11px] leading-5 text-foreground`,children:JSON.stringify(e.config,null,2)})})]}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(H,{title:`Contacts`,children:M.length===0&&ee.length===0?(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No direct contacts`}):M.length>0?(0,W.jsx)(`div`,{className:`space-y-2`,children:M.map(e=>(0,W.jsxs)(`div`,{className:`rounded-md border border-border bg-accent/25 px-3 py-2`,children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-3`,children:[(0,W.jsx)(`p`,{className:`min-w-0 select-text truncate text-sm font-medium text-foreground`,children:Jt(e,i.get(e.target_id))}),(0,W.jsx)(Nt,{variant:`outline`,className:`shrink-0 border-border bg-background/40 font-mono text-[10px] text-muted-foreground`,children:e.port_type})]}),(0,W.jsxs)(`div`,{className:`mt-2 flex min-w-0 flex-wrap items-center gap-1.5 text-[11px] text-muted-foreground`,children:[(0,W.jsx)(`span`,{className:`select-text rounded-md bg-background/45 px-1.5 py-0.5 font-mono text-foreground/80`,children:e.from_output_port_key}),(0,W.jsx)(`span`,{"aria-hidden":`true`,children:`to`}),(0,W.jsx)(`span`,{className:`select-text rounded-md bg-background/45 px-1.5 py-0.5 font-mono text-foreground/80`,children:e.to_input_port_key})]})]},e.edge_id))}):(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:ee.map(e=>(0,W.jsx)(`span`,{className:L(Vt,`select-text`),children:e.label},e.id))})}),(0,W.jsx)(H,{title:`Workflow Graph`,children:j.length===0?(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No graph edges`}):(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:j.map(e=>(0,W.jsx)(`span`,{className:L(Vt,`select-text`),children:e.label},e.id))})}),(0,W.jsx)(H,{title:`Tools`,children:v.length===0?(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No tools configured`}):(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:v.map(e=>(0,W.jsx)(`span`,{className:L(Vt,`select-text font-mono`),children:e},e))})}),(0,W.jsx)(H,{title:O,children:(0,W.jsx)(en,{allowNetwork:E,writeDirs:D,inherited:!w})}),(0,W.jsx)(H,{title:`Todos`,children:(0,W.jsx)(`div`,{className:`space-y-2`,children:h.length===0?(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No todos`}):h.slice(0,6).map(e=>(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-sm text-foreground`,children:[(0,W.jsx)(`span`,{className:`size-2 rounded-full bg-border`}),(0,W.jsx)(`span`,{className:`min-w-0 break-words [overflow-wrap:anywhere]`,children:e.text})]},e.text))})}),(0,W.jsxs)(`div`,{className:`border-t border-border pt-4`,children:[(0,W.jsx)(`div`,{className:`px-0 pb-2`,children:(0,W.jsx)(`p`,{className:`text-[10px] font-semibold text-muted-foreground`,children:`History`})}),u?(0,W.jsx)(`div`,{className:`space-y-2`,children:[...[,,,,]].map((e,t)=>(0,W.jsx)(`div`,{className:`h-12 rounded-md skeleton-shimmer`},t))}):l?(0,W.jsx)(`div`,{className:`text-sm text-destructive`,children:l}):g.length===0?(0,W.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`No history yet.`}):(0,W.jsx)(Tt,{history:g,agentLabel:k,nodes:i})]})]})]})})]})}function qt(e){return typeof e==`object`&&!!e&&`from_output_port_key`in e&&`to_input_port_key`in e}function Jt(e,t){return t?Rt({name:t.name,roleName:t.role_name,nodeType:t.node_type,isLeader:t.is_leader}):typeof e==`string`?e.slice(0,8):Rt({name:e.name,roleName:e.role_name,nodeType:e.node_type,isLeader:e.is_leader})}function Yt({onOpenDetails:e}){let{agents:t}=ae(),[n,r]=(0,U.useState)(!1),{height:i,ref:a}=Ve(),{activeTab:o,addImages:s=async()=>{},cancelPendingSend:c,clearChat:l,clearing:u=!1,connected:d,draftImages:f=[],handleKeyDown:p,hasUploadingImages:m=!1,input:h,isBrowsingInputHistory:g,leaderActivity:_,leaderNode:v,navigateInputHistory:y,onMessagesScroll:b,removeImage:S=()=>{},retryMessage:C,retryingMessageId:w,scrollRef:T,sending:E,sendMessage:D,sendPendingSend:O,setInput:k,stopLeader:A,supportsInputImage:j=!1,timelineItems:M}=It({bottomInset:i});return o?v?(0,W.jsxs)(`div`,{className:`relative flex h-full flex-col`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5 border-b border-border px-3.5 py-2.5`,children:[(0,W.jsxs)(`div`,{className:`flex min-w-[220px] flex-1 items-center gap-2`,children:[(0,W.jsx)(`p`,{className:`shrink-0 text-[14px] font-semibold leading-6`,children:`Workflow chat`}),v.role_name?(0,W.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: `,v.role_name]}):null,(0,W.jsx)(`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:o.title}),(0,W.jsx)(`span`,{className:L(`rounded-full border px-2.5 py-0.5 text-[9px] font-medium transition-colors`,d?`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:d?`Online`:`Connecting...`}),(0,W.jsx)(`span`,{className:`rounded-full border border-border bg-accent/35 px-2 py-0.5 text-[10px] font-medium leading-4 text-muted-foreground/78`,children:o.activation_state===`active`?`Active`:`Inactive`})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,W.jsx)(V,{type:`button`,size:`sm`,variant:`outline`,disabled:u,onClick:()=>void l(),children:u?`Clearing...`:`Clear Chat`}),(0,W.jsx)(V,{type:`button`,size:`sm`,variant:`outline`,onClick:e,children:`Leader Details`})]})]}),(0,W.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 flex-col`,children:[(0,W.jsx)(Ee,{allowHumanMessageRetry:!0,bottomInset:i,items:M,nodes:t,onRetryHumanMessage:e=>void C(e),onCancelPendingSend:c,onSendPendingSend:e=>void O(e),onScroll:b,retryImageInputEnabled:j,retryingMessageId:w,runningHint:_.runningHint,scrollRef:T}),(0,W.jsx)(`div`,{ref:a,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,W.jsx)(Z,{busy:_.running,commandsEnabled:!0,disabled:!h.trim()&&f.length===0||m||E,images:f,imageInputEnabled:j,input:h,onAddImages:e=>void s(e),onChange:k,onNavigateHistory:y,onKeyDown:p,onRemoveImage:S,onSend:()=>void D(),onStop:()=>{r(!0),A().catch(e=>{x.error(e instanceof Error?e.message:`Failed to interrupt leader`)}).finally(()=>{r(!1)})},overlay:!0,suppressCommandNavigation:g,targetLabel:`this workflow`,stopping:n})})]})]}):(0,W.jsx)(Zt,{}):(0,W.jsx)(Xt,{})}function Xt(){return(0,W.jsx)(`div`,{className:`flex h-full items-center justify-center px-6`,children:(0,W.jsxs)(`div`,{className:`max-w-sm rounded-xl border border-border bg-accent/20 px-5 py-6 text-center`,children:[(0,W.jsx)(`p`,{className:`text-[13px] font-semibold text-foreground`,children:`No workflow selected`}),(0,W.jsx)(`p`,{className:`mt-2 text-[12px] leading-6 text-muted-foreground`,children:`Create a workflow or switch to an existing one to open its workflow chat.`})]})})}function Zt(){return(0,W.jsx)(`div`,{className:`flex h-full items-center justify-center px-6`,children:(0,W.jsxs)(`div`,{className:`max-w-sm rounded-xl border border-border bg-accent/20 px-5 py-6 text-center`,children:[(0,W.jsx)(`p`,{className:`text-[13px] font-semibold text-foreground`,children:`Loading workflow context`}),(0,W.jsx)(`p`,{className:`mt-2 text-[12px] leading-6 text-muted-foreground`,children:`Restoring the current workflow chat.`})]})})}function Qt({expanded:e,onClick:t,className:n}){let r=e?`Hide panel`:`Show panel`;return(0,W.jsx)(V,{type:`button`,variant:`ghost`,size:`icon`,onClick:t,title:r,"aria-label":r,className:L(`pointer-events-auto relative isolate flex size-9 items-center justify-center rounded-md border border-border bg-surface-overlay/80 text-muted-foreground shadow-sm transition-[background-color,color] duration-150 hover:bg-accent/60 hover:text-foreground [contain:paint]`,n),children:(0,W.jsx)(`span`,{className:`flex transition-transform duration-200`,children:e?(0,W.jsx)(u,{className:`size-4`}):(0,W.jsx)(k,{className:`size-4`})})})}function $t({children:e,onClick:t,title:n}){return(0,W.jsx)(V,{type:`button`,variant:`ghost`,size:`icon-xs`,onClick:t,title:n,"aria-label":n,className:`flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors duration-150 hover:bg-accent/45 hover:text-foreground`,children:e})}function en({allowNetwork:e,inherited:t,writeDirs:n}){return(0,W.jsxs)(`div`,{className:`space-y-3`,children:[t?(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Set by this workflow.`}):null,(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`p`,{className:`text-[10px] font-semibold text-muted-foreground`,children:`Network`}),(0,W.jsx)(`p`,{className:`mt-1 select-text text-sm text-foreground`,children:e?`Enabled`:`Disabled`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`p`,{className:`text-[10px] font-semibold text-muted-foreground`,children:`Writable Folders`}),n.length===0?(0,W.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`No write access`}):(0,W.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:n.map(e=>(0,W.jsx)(`span`,{className:L(Vt,`select-text font-mono text-[11px]`),children:e},e))})]})]})}export{Ve as A,vt as C,lt as D,ct as E,Z as M,he as N,He as O,gt as S,ut as T,wt as _,Ut as a,ft as b,Rt as c,Bt as d,Ft as f,St as g,xt as h,Qt as i,Ee as j,Ye as k,Lt as l,bt as m,Gt as n,Wt as o,Nt as p,Yt as r,Xt as s,Kt as t,zt as u,yt as v,_t as w,ht as x,mt as y};
@@ -1 +1 @@
1
- import"./rolldown-runtime-BYbx6iT9.js";import{d as e,l as t}from"./graph-vendor-DRq_-6fV.js";import{A as n,F as r,M as i,N as a,O as o,P as s,j as c,k as l}from"./ui-vendor-UazN8rcv.js";import{nt as u,rt as d}from"./index-Biio-CoI.js";e();var f=t();function p({...e}){return(0,f.jsx)(s,{"data-slot":`alert-dialog`,...e})}function m({...e}){return(0,f.jsx)(a,{"data-slot":`alert-dialog-portal`,...e})}function h({className:e,...t}){return(0,f.jsx)(i,{"data-slot":`alert-dialog-overlay`,className:d(`bg-background/88 fixed inset-0 z-50`,`data-[state=open]:animate-in data-[state=closed]:animate-out`,`data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,e),...t})}function g({className:e,...t}){return(0,f.jsxs)(m,{children:[(0,f.jsx)(h,{}),(0,f.jsx)(n,{"data-slot":`alert-dialog-content`,className:d(`fixed top-1/2 left-1/2 z-50 w-full max-w-[calc(100%-2rem)] sm:max-w-lg -translate-x-1/2 -translate-y-1/2 grid gap-4 rounded-xl border border-border bg-popover text-popover-foreground p-6 shadow-lg`,`data-[state=open]:animate-in data-[state=closed]:animate-out`,`data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,`data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95`,e),...t})]})}function _({className:e,...t}){return(0,f.jsx)(`div`,{"data-slot":`alert-dialog-header`,className:d(`flex flex-col gap-2 text-left`,e),...t})}function v({className:e,...t}){return(0,f.jsx)(`div`,{"data-slot":`alert-dialog-footer`,className:d(`flex flex-col-reverse gap-2 sm:flex-row sm:justify-end`,e),...t})}function y({className:e,...t}){return(0,f.jsx)(r,{"data-slot":`alert-dialog-title`,className:d(`text-lg font-semibold`,e),...t})}function b({className:e,...t}){return(0,f.jsx)(c,{"data-slot":`alert-dialog-description`,className:d(`text-sm text-muted-foreground`,e),...t})}function x({className:e,...t}){return(0,f.jsx)(o,{"data-slot":`alert-dialog-action`,className:d(u(),e),...t})}function S({className:e,...t}){return(0,f.jsx)(l,{"data-slot":`alert-dialog-cancel`,className:d(u({variant:`outline`}),e),...t})}export{b as a,y as c,g as i,x as n,v as o,S as r,_ as s,p as t};
1
+ import"./rolldown-runtime-BYbx6iT9.js";import{d as e,l as t}from"./graph-vendor-DRq_-6fV.js";import{A as n,F as r,M as i,N as a,O as o,P as s,j as c,k as l}from"./ui-vendor-C5pJa8N7.js";import{dt as u,ft as d}from"./index-C9HuekJm.js";e();var f=t();function p({...e}){return(0,f.jsx)(s,{"data-slot":`alert-dialog`,...e})}function m({...e}){return(0,f.jsx)(a,{"data-slot":`alert-dialog-portal`,...e})}function h({className:e,...t}){return(0,f.jsx)(i,{"data-slot":`alert-dialog-overlay`,className:d(`bg-background/88 fixed inset-0 z-50`,`data-[state=open]:animate-in data-[state=closed]:animate-out`,`data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,e),...t})}function g({className:e,...t}){return(0,f.jsxs)(m,{children:[(0,f.jsx)(h,{}),(0,f.jsx)(n,{"data-slot":`alert-dialog-content`,className:d(`fixed top-1/2 left-1/2 z-50 w-full max-w-[calc(100%-2rem)] sm:max-w-lg -translate-x-1/2 -translate-y-1/2 grid gap-4 rounded-xl border border-border bg-popover text-popover-foreground p-6 shadow-lg`,`data-[state=open]:animate-in data-[state=closed]:animate-out`,`data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,`data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95`,e),...t})]})}function _({className:e,...t}){return(0,f.jsx)(`div`,{"data-slot":`alert-dialog-header`,className:d(`flex flex-col gap-2 text-left`,e),...t})}function v({className:e,...t}){return(0,f.jsx)(`div`,{"data-slot":`alert-dialog-footer`,className:d(`flex flex-col-reverse gap-2 sm:flex-row sm:justify-end`,e),...t})}function y({className:e,...t}){return(0,f.jsx)(r,{"data-slot":`alert-dialog-title`,className:d(`text-lg font-semibold`,e),...t})}function b({className:e,...t}){return(0,f.jsx)(c,{"data-slot":`alert-dialog-description`,className:d(`text-sm text-muted-foreground`,e),...t})}function x({className:e,...t}){return(0,f.jsx)(o,{"data-slot":`alert-dialog-action`,className:d(u(),e),...t})}function S({className:e,...t}){return(0,f.jsx)(l,{"data-slot":`alert-dialog-cancel`,className:d(u({variant:`outline`}),e),...t})}export{b as a,y as c,g as i,x as n,v as o,S as r,_ as s,p as t};