@xopcai/xopc 0.0.122 → 0.0.124

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 (273) hide show
  1. package/README.md +28 -11
  2. package/README.zh-CN.md +28 -11
  3. package/dist/browser-ext/manifest.json +1 -1
  4. package/dist/extensions/telegram/xopc.extension.json +1 -1
  5. package/dist/gateway/static/root/assets/{agent-avatar-dicebear-CK3s5cJo.js → agent-avatar-dicebear-B5uSVAyJ.js} +1 -1
  6. package/dist/gateway/static/root/assets/agents-BjIxt67Z.js +2 -0
  7. package/dist/gateway/static/root/assets/{app-management-settings-panel-CWsNHtTs.js → app-management-settings-panel-CYCONLIL.js} +1 -1
  8. package/dist/gateway/static/root/assets/{appearance-settings-C4b8y6iZ.js → appearance-settings-Clw3ryKg.js} +1 -1
  9. package/dist/gateway/static/root/assets/apps-page-QICTeGjX.js +1 -0
  10. package/dist/gateway/static/root/assets/{archive-plugin-DAtNW3Ia.js → archive-plugin-CXUGRp2i.js} +1 -1
  11. package/dist/gateway/static/root/assets/{attachment-load-Dm-RY54y.js → attachment-load-Cmiub3Wg.js} +1 -1
  12. package/dist/gateway/static/root/assets/{automation-suggestion-card-BKHewSVT.js → automation-suggestion-card-CU0-4nQ-.js} +1 -1
  13. package/dist/gateway/static/root/assets/automations-page-Car-jtiz.js +1 -0
  14. package/dist/gateway/static/root/assets/{binary-plugins-BG6Xnk71.js → binary-plugins-0Izz-N3p.js} +1 -1
  15. package/dist/gateway/static/root/assets/{block-editor-DfndiO3h.js → block-editor-C1Kv0IkJ.js} +28 -28
  16. package/dist/gateway/static/root/assets/browser-settings-page-CMeBJzlS.js +8 -0
  17. package/dist/gateway/static/root/assets/{capability-presets-api-Cx93GLdw.js → capability-presets-api-BmQTM9Il.js} +1 -1
  18. package/dist/gateway/static/root/assets/capability-presets-settings-panel-DZEJEoCF.js +1 -0
  19. package/dist/gateway/static/root/assets/{channel-recipient-api-DdPTtEs8.js → channel-recipient-api-BeA2aVor.js} +1 -1
  20. package/dist/gateway/static/root/assets/channels-settings-kkW-xFau.js +1 -0
  21. package/dist/gateway/static/root/assets/connectors-page-BvaQvO5F.js +2 -0
  22. package/dist/gateway/static/root/assets/{directory-picker-path-field-D835EHJd.js → directory-picker-path-field-2rjzUu57.js} +1 -1
  23. package/dist/gateway/static/root/assets/{dreaming-settings-CCa1F7Fg.js → dreaming-settings-DnHO686d.js} +1 -1
  24. package/dist/gateway/static/root/assets/{extension-debug-page-W2ITCPSA.js → extension-debug-page-BGLRuWVN.js} +1 -1
  25. package/dist/gateway/static/root/assets/{extension-page-DrvUytvn.js → extension-page-D978ePp9.js} +1 -1
  26. package/dist/gateway/static/root/assets/{extension-settings-page-qM8aLT5u.js → extension-settings-page-B6Ih4Swx.js} +1 -1
  27. package/dist/gateway/static/root/assets/{fetch-ovkvM8KQ.js → fetch-BU5S0Sn7.js} +1 -1
  28. package/dist/gateway/static/root/assets/{gateway-config-api-BB3biuD0.js → gateway-config-api-BIPGwrl1.js} +1 -1
  29. package/dist/gateway/static/root/assets/gateway-settings-CMEA3r5u.js +1 -0
  30. package/dist/gateway/static/root/assets/{gateway-startup-retry-CanQ8UcR.js → gateway-startup-retry-Cd0Zz30N.js} +1 -1
  31. package/dist/gateway/static/root/assets/{goal-create-dialog-CNqNdEkQ.js → goal-create-dialog-B-KHKeXN.js} +1 -1
  32. package/dist/gateway/static/root/assets/goal-detail-page-BxrSoWdj.js +1 -0
  33. package/dist/gateway/static/root/assets/{goals-config-api-BBOX6mUl.js → goals-config-api-B95KdGMj.js} +1 -1
  34. package/dist/gateway/static/root/assets/{goals-page-BP1kfvWv.js → goals-page-BTJzIl28.js} +2 -2
  35. package/dist/gateway/static/root/assets/{goals-settings-Bh3A7OZV.js → goals-settings-BJyEuLLm.js} +1 -1
  36. package/dist/gateway/static/root/assets/heartbeat-settings-wkOjYNQT.js +1 -0
  37. package/dist/gateway/static/root/assets/index-BLaXr6Ev.css +1 -0
  38. package/dist/gateway/static/root/assets/index-c_9TVr_C.js +191 -0
  39. package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-B4TKJHla.js → keyboard-shortcuts-settings-BT8T4DyC.js} +1 -1
  40. package/dist/gateway/static/root/assets/logs-page-CrxBJUgI.js +2 -0
  41. package/dist/gateway/static/root/assets/{markdown-split-DcFtdLci.js → markdown-split-Dv66bO2b.js} +1 -1
  42. package/dist/gateway/static/root/assets/{media-plugins-B6SmeLVB.js → media-plugins-BhIQU5yS.js} +1 -1
  43. package/dist/gateway/static/root/assets/messages-O6TAtdFC.js +3 -0
  44. package/dist/gateway/static/root/assets/models-hub-panel-DOOpz6y1.js +2 -0
  45. package/dist/gateway/static/root/assets/notes-page-Br16pK9v.js +1 -0
  46. package/dist/gateway/static/root/assets/notes-workbench-PSJAi0ZC.js +2 -0
  47. package/dist/gateway/static/root/assets/{preview-open-alternatives-C29O19s7.js → preview-open-alternatives-DGzet1d7.js} +1 -1
  48. package/dist/gateway/static/root/assets/project-detail-page-CIGGgKuw.js +1 -0
  49. package/dist/gateway/static/root/assets/projects-page-B2grhsBt.js +1 -0
  50. package/dist/gateway/static/root/assets/remote-access-hub-CXMORxBD.js +1 -0
  51. package/dist/gateway/static/root/assets/{save-bar-controls-B4ad9GfB.js → save-bar-controls-Cqgb-jqa.js} +1 -1
  52. package/dist/gateway/static/root/assets/{schedule-field-DdYncfLR.js → schedule-field-DVZcI8Yt.js} +1 -1
  53. package/dist/gateway/static/root/assets/{schema-form-BMTrDE-7.js → schema-form-Bj7sOxC8.js} +1 -1
  54. package/dist/gateway/static/root/assets/sessions-page-Bi2wkBzU.js +1 -0
  55. package/dist/gateway/static/root/assets/settings-advanced-gate-B1L3G4IA.js +1 -0
  56. package/dist/gateway/static/root/assets/{settings-collapsible-section-MwTW2eK4.js → settings-collapsible-section-BmXn-8N6.js} +1 -1
  57. package/dist/gateway/static/root/assets/{settings-form-section-Dg6LBbcr.js → settings-form-section-BnqYMWHR.js} +1 -1
  58. package/dist/gateway/static/root/assets/settings-page-BfRSHJmO.js +1 -0
  59. package/dist/gateway/static/root/assets/{settings-page-layout-BX4T-OLF.js → settings-page-layout-CdWZU1hd.js} +1 -1
  60. package/dist/gateway/static/root/assets/{setup-status-panel-Ce1pcFtR.js → setup-status-panel-CWtPM7RK.js} +1 -1
  61. package/dist/gateway/static/root/assets/{share-preview-page-DWE-dUFh.js → share-preview-page-IB1v8i86.js} +1 -1
  62. package/dist/gateway/static/root/assets/shares-settings-ngbsBgij.js +1 -0
  63. package/dist/gateway/static/root/assets/skill-reload-api-BIe442Gv.js +1 -0
  64. package/dist/gateway/static/root/assets/skills-page-BfchZRVa.js +2 -0
  65. package/dist/gateway/static/root/assets/{system-settings-panel-Dd6Y35Cm.js → system-settings-panel-BxQ384RC.js} +1 -1
  66. package/dist/gateway/static/root/assets/{typed-models-lib-Cx6XV5A2.js → typed-models-lib-BkcpvFYO.js} +1 -1
  67. package/dist/gateway/static/root/assets/{use-channel-catalog-D4sMbmy7.js → use-channel-catalog-Cd0FaEQ4.js} +1 -1
  68. package/dist/gateway/static/root/assets/{user-profile-settings-panel-Bx-hjMQc.js → user-profile-settings-panel-DQ7NnRSY.js} +1 -1
  69. package/dist/gateway/static/root/assets/{utils-D7b_vZnv.js → utils-YKhVf7Ka.js} +1 -1
  70. package/dist/gateway/static/root/assets/voice-api-key-field-C5Ov8Uk_.js +1 -0
  71. package/dist/gateway/static/root/assets/{workflow-run-setup-panel--TdohF5N.js → workflow-run-setup-panel-BYD9BtOq.js} +2 -2
  72. package/dist/gateway/static/root/assets/{workflow-start-dialog-B0lavx_o.js → workflow-start-dialog-BNJVCWoS.js} +1 -1
  73. package/dist/gateway/static/root/assets/workflows-page-BYF29ANm.js +18 -0
  74. package/dist/gateway/static/root/index.html +5 -5
  75. package/dist/package.js +1 -1
  76. package/dist/src/agent/agent-manager.d.ts +6 -1
  77. package/dist/src/agent/agent-manager.js +28 -12
  78. package/dist/src/agent/agent-manager.js.map +1 -1
  79. package/dist/src/agent/context/workspace-templates/AGENTS.md +1 -1
  80. package/dist/src/agent/embedded/xopc-tools-bridge.js +11 -7
  81. package/dist/src/agent/embedded/xopc-tools-bridge.js.map +1 -1
  82. package/dist/src/agent/lifecycle/progress.js +3 -1
  83. package/dist/src/agent/lifecycle/progress.js.map +1 -1
  84. package/dist/src/agent/lifecycle/timeout-wrapper.d.ts +2 -2
  85. package/dist/src/agent/lifecycle/timeout-wrapper.js +4 -4
  86. package/dist/src/agent/lifecycle/timeout-wrapper.js.map +1 -1
  87. package/dist/src/agent/memory/summary-generator.d.ts +1 -1
  88. package/dist/src/agent/memory/summary-generator.js +1 -2
  89. package/dist/src/agent/memory/summary-generator.js.map +1 -1
  90. package/dist/src/agent/middleware/index.d.ts +1 -1
  91. package/dist/src/agent/middleware/self-verify.d.ts +44 -14
  92. package/dist/src/agent/middleware/self-verify.js +214 -44
  93. package/dist/src/agent/middleware/self-verify.js.map +1 -1
  94. package/dist/src/agent/orchestration/agent-event-handler.js +57 -15
  95. package/dist/src/agent/orchestration/agent-event-handler.js.map +1 -1
  96. package/dist/src/agent/prompt/sections/tooling.js +18 -13
  97. package/dist/src/agent/prompt/sections/tooling.js.map +1 -1
  98. package/dist/src/agent/prompt/system-reminder.js +2 -2
  99. package/dist/src/agent/prompt/system-reminder.js.map +1 -1
  100. package/dist/src/agent/sandbox/sanitize-env-vars.d.ts +2 -2
  101. package/dist/src/agent/sandbox/sanitize-env-vars.js +2 -2
  102. package/dist/src/agent/sandbox/sanitize-env-vars.js.map +1 -1
  103. package/dist/src/agent/sandbox/types.d.ts +2 -2
  104. package/dist/src/agent/sandbox/types.js.map +1 -1
  105. package/dist/src/agent/service/btw-query.js +1 -1
  106. package/dist/src/agent/service/btw-query.js.map +1 -1
  107. package/dist/src/agent/service/process-direct-one-shot.js +6 -2
  108. package/dist/src/agent/service/process-direct-one-shot.js.map +1 -1
  109. package/dist/src/agent/service/process-direct-streaming.js +12 -7
  110. package/dist/src/agent/service/process-direct-streaming.js.map +1 -1
  111. package/dist/src/agent/service.js +2 -1
  112. package/dist/src/agent/service.js.map +1 -1
  113. package/dist/src/agent/skills/skill-tool-gating.js +1 -1
  114. package/dist/src/agent/skills/skill-tool-gating.js.map +1 -1
  115. package/dist/src/agent/starter-agents.js +9 -9
  116. package/dist/src/agent/starter-agents.js.map +1 -1
  117. package/dist/src/agent/tools/apply-patch.d.ts +25 -0
  118. package/dist/src/agent/tools/apply-patch.js +256 -0
  119. package/dist/src/agent/tools/apply-patch.js.map +1 -0
  120. package/dist/src/agent/tools/delegate-tool.d.ts +1 -1
  121. package/dist/src/agent/tools/delegate-tool.js +3 -3
  122. package/dist/src/agent/tools/delegate-tool.js.map +1 -1
  123. package/dist/src/agent/tools/exec-command.d.ts +30 -0
  124. package/dist/src/agent/tools/exec-command.js +224 -0
  125. package/dist/src/agent/tools/exec-command.js.map +1 -0
  126. package/dist/src/agent/tools/execute-code-tool.js +7 -4
  127. package/dist/src/agent/tools/execute-code-tool.js.map +1 -1
  128. package/dist/src/agent/tools/factory.d.ts +3 -3
  129. package/dist/src/agent/tools/factory.js +8 -9
  130. package/dist/src/agent/tools/factory.js.map +1 -1
  131. package/dist/src/agent/tools/goal-tool.d.ts +5 -1
  132. package/dist/src/agent/tools/goal-tool.js +8 -2
  133. package/dist/src/agent/tools/goal-tool.js.map +1 -1
  134. package/dist/src/agent/tools/index.d.ts +4 -3
  135. package/dist/src/agent/tools/index.js +5 -4
  136. package/dist/src/agent/tools/skills-tools.d.ts +1 -1
  137. package/dist/src/agent/tools/skills-tools.js.map +1 -1
  138. package/dist/src/agent/tools/update-plan-tool.d.ts +11 -0
  139. package/dist/src/agent/tools/update-plan-tool.js +72 -0
  140. package/dist/src/agent/tools/update-plan-tool.js.map +1 -0
  141. package/dist/src/agent/workflow/builtins/debug-incident.d.ts +1 -1
  142. package/dist/src/agent/workflow/builtins/debug-incident.js +1 -1
  143. package/dist/src/agent/workflow/builtins/debug-incident.js.map +1 -1
  144. package/dist/src/agent/workflow/builtins/pr-review.d.ts +1 -1
  145. package/dist/src/agent/workflow/builtins/pr-review.js +1 -1
  146. package/dist/src/agent/workflow/builtins/pr-review.js.map +1 -1
  147. package/dist/src/agent/workflow/builtins/release-check.d.ts +1 -1
  148. package/dist/src/agent/workflow/builtins/release-check.js +1 -1
  149. package/dist/src/agent/workflow/builtins/release-check.js.map +1 -1
  150. package/dist/src/agent/workflow/step-labels.js +7 -3
  151. package/dist/src/agent/workflow/step-labels.js.map +1 -1
  152. package/dist/src/chat-commands/agent-edit.js +1 -1
  153. package/dist/src/chat-commands/agent-edit.js.map +1 -1
  154. package/dist/src/chat-commands/builtins/goal.js +4 -1
  155. package/dist/src/chat-commands/builtins/goal.js.map +1 -1
  156. package/dist/src/chat-commands/builtins/review.d.ts +1 -0
  157. package/dist/src/chat-commands/builtins/review.js +167 -0
  158. package/dist/src/chat-commands/builtins/review.js.map +1 -0
  159. package/dist/src/chat-commands/index.d.ts +1 -0
  160. package/dist/src/chat-commands/index.js +3 -1
  161. package/dist/src/chat-commands/index.js.map +1 -1
  162. package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
  163. package/dist/src/cli/commands/gateway/lifecycle.js +1 -1
  164. package/dist/src/config/agent-profile.js +1 -1
  165. package/dist/src/gateway/agent-builtin-tools.d.ts +1 -1
  166. package/dist/src/gateway/agent-builtin-tools.js +3 -2
  167. package/dist/src/gateway/agent-builtin-tools.js.map +1 -1
  168. package/dist/src/gateway/agents-admin.js +1 -1
  169. package/dist/src/gateway/chat-stream/mapper.d.ts +6 -0
  170. package/dist/src/gateway/chat-stream/mapper.js +149 -6
  171. package/dist/src/gateway/chat-stream/mapper.js.map +1 -1
  172. package/dist/src/gateway/chat-stream/protocol.d.ts +51 -1
  173. package/dist/src/gateway/hono/routes/commands-skills.js +21 -0
  174. package/dist/src/gateway/hono/routes/commands-skills.js.map +1 -1
  175. package/dist/src/gateway/hono/routes/index.js +2 -0
  176. package/dist/src/gateway/hono/routes/index.js.map +1 -1
  177. package/dist/src/gateway/hono/routes/lazy-bundles.js +1 -0
  178. package/dist/src/gateway/hono/routes/lazy-bundles.js.map +1 -1
  179. package/dist/src/gateway/hono/routes/projects.js +136 -14
  180. package/dist/src/gateway/hono/routes/projects.js.map +1 -1
  181. package/dist/src/gateway/hono/routes/search.d.ts +3 -0
  182. package/dist/src/gateway/hono/routes/search.js +47 -0
  183. package/dist/src/gateway/hono/routes/search.js.map +1 -0
  184. package/dist/src/gateway/security/dangerous-tools.js +1 -1
  185. package/dist/src/gateway/security/dangerous-tools.js.map +1 -1
  186. package/dist/src/infra/update-restart.js +1 -1
  187. package/dist/src/projects/index.d.ts +3 -0
  188. package/dist/src/projects/index.js +4 -1
  189. package/dist/src/projects/project-agent-suggestion.d.ts +14 -0
  190. package/dist/src/projects/project-agent-suggestion.js +19 -0
  191. package/dist/src/projects/project-agent-suggestion.js.map +1 -0
  192. package/dist/src/projects/project-kind.d.ts +13 -0
  193. package/dist/src/projects/project-kind.js +147 -0
  194. package/dist/src/projects/project-kind.js.map +1 -0
  195. package/dist/src/projects/project-service.d.ts +15 -0
  196. package/dist/src/projects/project-service.js +96 -3
  197. package/dist/src/projects/project-service.js.map +1 -1
  198. package/dist/src/projects/project-store.js +32 -8
  199. package/dist/src/projects/project-store.js.map +1 -1
  200. package/dist/src/projects/types.d.ts +4 -1
  201. package/dist/src/projects/workspace-project.d.ts +22 -0
  202. package/dist/src/projects/workspace-project.js +143 -0
  203. package/dist/src/projects/workspace-project.js.map +1 -0
  204. package/dist/src/review/review-git.d.ts +48 -0
  205. package/dist/src/review/review-git.js +333 -0
  206. package/dist/src/review/review-git.js.map +1 -0
  207. package/dist/src/review/review-types.d.ts +22 -0
  208. package/dist/src/review/review-types.js +29 -0
  209. package/dist/src/review/review-types.js.map +1 -0
  210. package/dist/src/session/session-context-for-llm.js +151 -0
  211. package/dist/src/session/session-context-for-llm.js.map +1 -1
  212. package/dist/src/storage/sqlite/migrations/021_projects_fts.sql +21 -0
  213. package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
  214. package/dist/src/storage/sqlite/migrations/runner.js +3 -3
  215. package/dist/src/storage/sqlite/migrations/runner.js.map +1 -1
  216. package/dist/src/storage/sqlite/migrations/runner.ts +1 -1
  217. package/dist/src/storage/sqlite/schema.js +1 -1
  218. package/dist/src/tui/backends/embedded-backend.d.ts +8 -1
  219. package/dist/src/tui/backends/embedded-backend.js +60 -1
  220. package/dist/src/tui/backends/embedded-backend.js.map +1 -1
  221. package/dist/src/tui/backends/gateway-sse-backend.d.ts +9 -1
  222. package/dist/src/tui/backends/gateway-sse-backend.js +29 -0
  223. package/dist/src/tui/backends/gateway-sse-backend.js.map +1 -1
  224. package/dist/src/tui/components/assistant-message.js +35 -0
  225. package/dist/src/tui/components/assistant-message.js.map +1 -1
  226. package/dist/src/tui/tui-agent-events.js +25 -0
  227. package/dist/src/tui/tui-agent-events.js.map +1 -1
  228. package/dist/src/tui/tui-backend.d.ts +20 -0
  229. package/dist/src/tui/tui-commands.d.ts +1 -0
  230. package/dist/src/tui/tui-commands.js +110 -4
  231. package/dist/src/tui/tui-commands.js.map +1 -1
  232. package/dist/src/tui/tui-picker-overlay.d.ts +2 -0
  233. package/dist/src/tui/tui-picker-overlay.js +153 -1
  234. package/dist/src/tui/tui-picker-overlay.js.map +1 -1
  235. package/dist/src/tui/tui.js +36 -2
  236. package/dist/src/tui/tui.js.map +1 -1
  237. package/dist/src/workflows/service/workflow-run-service.js +1 -1
  238. package/dist/src/workflows/service/workflow-run-service.js.map +1 -1
  239. package/package.json +1 -1
  240. package/dist/gateway/static/root/assets/agents-SsQrj9B-.js +0 -2
  241. package/dist/gateway/static/root/assets/apps-page-CYb6fame.js +0 -1
  242. package/dist/gateway/static/root/assets/automations-page-DpOOq1nk.js +0 -1
  243. package/dist/gateway/static/root/assets/browser-settings-page-9nXxgh4u.js +0 -8
  244. package/dist/gateway/static/root/assets/capability-presets-settings-panel-D528_YFy.js +0 -1
  245. package/dist/gateway/static/root/assets/channels-settings-Ck-3h5lI.js +0 -1
  246. package/dist/gateway/static/root/assets/connectors-page-DL-fAqE_.js +0 -2
  247. package/dist/gateway/static/root/assets/gateway-settings-mmmnIH27.js +0 -1
  248. package/dist/gateway/static/root/assets/goal-detail-page-Ceu5zrN6.js +0 -1
  249. package/dist/gateway/static/root/assets/heartbeat-settings-YoYgKlfX.js +0 -1
  250. package/dist/gateway/static/root/assets/index-DdqSO9R2.js +0 -191
  251. package/dist/gateway/static/root/assets/index-jGB-2nI-.css +0 -1
  252. package/dist/gateway/static/root/assets/logs-page-BgVk5DvZ.js +0 -2
  253. package/dist/gateway/static/root/assets/messages-B5O4OIEo.js +0 -3
  254. package/dist/gateway/static/root/assets/models-hub-panel-BU0x8PGP.js +0 -2
  255. package/dist/gateway/static/root/assets/notes-page-D6JYVP4I.js +0 -1
  256. package/dist/gateway/static/root/assets/notes-workbench-mqRJYnJS.js +0 -2
  257. package/dist/gateway/static/root/assets/project-detail-page-DOTgzoeh.js +0 -1
  258. package/dist/gateway/static/root/assets/projects-page-DGUIb4y5.js +0 -1
  259. package/dist/gateway/static/root/assets/remote-access-hub-DVKKUj3u.js +0 -1
  260. package/dist/gateway/static/root/assets/sessions-page-BVbzUWxW.js +0 -1
  261. package/dist/gateway/static/root/assets/settings-advanced-gate-DrNNoSqE.js +0 -1
  262. package/dist/gateway/static/root/assets/settings-page-CMDqgeMR.js +0 -1
  263. package/dist/gateway/static/root/assets/shares-settings-aKSraR8l.js +0 -1
  264. package/dist/gateway/static/root/assets/skill-reload-api-CS-FU_B-.js +0 -1
  265. package/dist/gateway/static/root/assets/skills-page-BaF3u0LA.js +0 -2
  266. package/dist/gateway/static/root/assets/voice-api-key-field-CkhbRt1q.js +0 -1
  267. package/dist/gateway/static/root/assets/workflows-page-CZR05Bu_.js +0 -18
  268. package/dist/src/agent/tools/edit.d.ts +0 -14
  269. package/dist/src/agent/tools/edit.js +0 -132
  270. package/dist/src/agent/tools/edit.js.map +0 -1
  271. package/dist/src/agent/tools/shell.d.ts +0 -15
  272. package/dist/src/agent/tools/shell.js +0 -158
  273. package/dist/src/agent/tools/shell.js.map +0 -1
@@ -49,7 +49,7 @@ var WorkflowRunService = class {
49
49
  };
50
50
  const runId = randomUUID();
51
51
  const goal = params.goal ?? "";
52
- const projectId = params.projectId?.trim() || (params.goalId ? new GoalService().get(params.goalId)?.projectId : void 0);
52
+ const projectId = params.projectId?.trim() || (params.goalId ? new GoalService().get(params.goalId)?.projectId : void 0) || (params.parentSessionKey?.trim() ? (await this.options.service.sessionIndexInstance.getStore().getMetadata(params.parentSessionKey.trim()))?.projectId : void 0);
53
53
  const { sessionKey } = await this.options.sessionBridge.prepareRunSession({
54
54
  runId,
55
55
  agentId: params.agentId,
@@ -1 +1 @@
1
- {"version":3,"file":"workflow-run-service.js","names":["resolveModelById"],"sources":["../../../../src/workflows/service/workflow-run-service.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport type { AgentTool } from '@earendil-works/pi-agent-core';\n\nimport type { BuildChildToolsOptions } from '../../agent/child-agent-factory.js';\nimport { publishAutomationProductEvent } from '../../automations/product-events.js';\nimport { extractProfileAgentId } from '../../config/agent-profile.js';\nimport { resolveModelRef } from '../../config/agent-typed-models.js';\nimport type { GatewayWorkflowHost } from '../../gateway/gateway-workflow-host.types.js';\nimport { GoalService } from '../../goals/index.js';\nimport { resolveModel as resolveModelById } from '../../providers/index.js';\nimport { DelegateSubagentRunner } from '../../agent/workflow/subagent-runner.js';\nimport { CatalogWorkflowDefinitionRegistry } from '../registry/catalog-workflow-definition-registry.js';\nimport type { WorkflowDefinitionRegistry } from '../registry/workflow-definition-registry.js';\nimport { validateWorkflowJsonSchema } from '../domain/schema-validation.js';\nimport type {\n WorkflowDefinition,\n WorkflowRunDefinitionSnapshot,\n WorkflowRunInputEnvelope,\n WorkflowRunMetadata,\n WorkflowRunSource,\n} from '../domain/index.js';\nimport { isTerminalWorkflowRunStatus } from '../domain/index.js';\nimport { WorkflowEngine } from '../engine/index.js';\nimport { WorkflowEventStore } from '../store/event-store.js';\nimport { WorkflowRunStore } from '../store/run-store.js';\nimport type { WorkflowSessionBridge } from './workflow-session-bridge.js';\nexport type {\n CancelWorkflowRunResult,\n CancelWorkflowRunServiceParams,\n CancelWorkflowRunServiceResult,\n ReplayWorkflowRunServiceParams,\n RetryWorkflowRunServiceParams,\n StartWorkflowRunServiceParams,\n StartWorkflowRunServiceResult,\n WorkflowRunServiceErrorCode,\n WorkflowRunServiceErrorResult,\n WorkflowRunServiceResult,\n} from './workflow-run-service.types.js';\n\nimport type {\n CancelWorkflowRunResult,\n CancelWorkflowRunServiceParams,\n ReplayWorkflowRunServiceParams,\n RetryWorkflowRunServiceParams,\n StartWorkflowRunServiceParams,\n WorkflowRunServiceResult,\n} from './workflow-run-service.types.js';\nimport type { WorkflowRunReplayMetadata, WorkflowRunReplayScope, WorkflowRunView } from '../domain/run.js';\nimport type { WorkflowReplayAgentTarget } from '../engine/index.js';\n\nexport interface WorkflowRunServiceOptions {\n service: GatewayWorkflowHost;\n sessionBridge: WorkflowSessionBridge;\n buildChildTools: (childOptions: BuildChildToolsOptions) => AgentTool<any, any>[];\n definitionRegistry?: WorkflowDefinitionRegistry;\n}\n\nexport class WorkflowRunService {\n private readonly activeRuns = new Map<string, AbortController>();\n private readonly timeoutHandles = new Map<string, ReturnType<typeof setTimeout>>();\n private readonly definitionRegistry: WorkflowDefinitionRegistry;\n private readonly emittedTerminalAutomationEvents = new Set<string>();\n\n constructor(private readonly options: WorkflowRunServiceOptions) {\n this.definitionRegistry = options.definitionRegistry ?? new CatalogWorkflowDefinitionRegistry();\n }\n\n async startWorkflowRun(params: StartWorkflowRunServiceParams): Promise<WorkflowRunServiceResult> {\n const definition = await this.loadDefinition(params.definitionId);\n if (!definition) {\n return {\n ok: false,\n code: 'definition_not_found',\n message: 'Workflow definition not found',\n httpStatus: 404,\n };\n }\n\n const inputEnvelope = params.inputEnvelope ?? buildWorkflowRunInputEnvelope(params.input, params.goal);\n const inputValidation = validateWorkflowJsonSchema(definition.inputSchema, inputEnvelope.payload);\n if (!inputValidation.ok) {\n return {\n ok: false,\n code: 'invalid_input',\n message: inputValidation.message ?? 'Workflow input did not match input schema',\n httpStatus: 400,\n };\n }\n\n const existingRun = params.idempotencyKey\n ? await this.findRunByIdempotencyKey(params.agentId, params.idempotencyKey)\n : null;\n if (existingRun) {\n return {\n ok: true,\n runId: existingRun.run.id,\n sessionKey: existingRun.run.metadata?.sessionKey ?? '',\n };\n }\n\n const runId = randomUUID();\n const goal = params.goal ?? '';\n const projectId =\n params.projectId?.trim() ||\n (params.goalId ? new GoalService().get(params.goalId)?.projectId : undefined);\n const { sessionKey } = await this.options.sessionBridge.prepareRunSession({\n runId,\n agentId: params.agentId,\n definitionId: params.definitionId,\n definitionTitle: definition.title,\n goal,\n parentSessionKey: params.parentSessionKey,\n projectId,\n });\n const source = normalizeWorkflowRunSourceForSession(params.source, sessionKey, params.parentSessionKey);\n const abortController = new AbortController();\n const eventStore = new WorkflowEventStore(this.options.service.currentConfig, params.agentId);\n const runStore = new WorkflowRunStore(this.options.service.currentConfig, params.agentId, eventStore);\n const engine = this.createWorkflowEngine({\n eventStore,\n runStore,\n sessionKey,\n });\n const limits = resolveWorkflowRunLimits({\n config: this.options.service.currentConfig,\n definition,\n concurrency: params.concurrency,\n maxSubagents: params.maxSubagents,\n });\n\n this.activeRuns.set(runId, abortController);\n const timeoutHandle = setTimeout(() => {\n abortController.abort(new Error(`workflow timed out after ${limits.timeoutSec}s`));\n }, limits.timeoutSec * 1000);\n this.timeoutHandles.set(runId, timeoutHandle);\n void engine.startRun(definition, {\n runId,\n input: inputEnvelope.payload,\n goal: inputEnvelope.goal ?? params.goal,\n source,\n metadata: buildWorkflowRunMetadata({\n definition,\n agentId: params.agentId,\n goalId: params.goalId,\n projectId,\n sessionKey,\n source,\n input: inputEnvelope,\n retryOfRunId: params.retryOfRunId,\n idempotencyKey: params.idempotencyKey,\n }),\n signal: abortController.signal,\n concurrency: limits.concurrency,\n maxSubagents: limits.maxSubagents,\n tokenBudget: params.tokenBudget,\n timeoutSec: limits.timeoutSec,\n }).catch((err) => {\n this.options.service.emit('workflow.run.error', {\n runId,\n error: err instanceof Error ? err.message : String(err),\n });\n }).finally(() => {\n this.activeRuns.delete(runId);\n const handle = this.timeoutHandles.get(runId);\n if (handle) clearTimeout(handle);\n this.timeoutHandles.delete(runId);\n });\n\n return { ok: true, runId, sessionKey };\n }\n\n async retryWorkflowRun(params: RetryWorkflowRunServiceParams): Promise<WorkflowRunServiceResult> {\n const runStore = this.createRunStore(params.agentId);\n const existing = await runStore.readRunView(params.runId);\n if (!existing) {\n return {\n ok: false,\n code: 'run_not_found',\n message: 'Workflow run not found',\n httpStatus: 404,\n };\n }\n\n const parentSessionKey =\n existing.run.source.kind === 'chat' ? existing.run.source.sessionKey : undefined;\n const projectId = params.projectId?.trim() || existing.run.metadata?.projectId;\n\n return this.startWorkflowRun({\n agentId: params.agentId,\n definitionId: existing.run.definitionId,\n goalId: existing.run.metadata?.goalId,\n projectId,\n input: existing.run.metadata?.input ? undefined : existing.run.input,\n inputEnvelope: existing.run.metadata?.input,\n goal: existing.run.goal,\n source: existing.run.source,\n parentSessionKey,\n retryOfRunId: existing.run.id,\n });\n }\n\n async replayWorkflowRun(params: ReplayWorkflowRunServiceParams): Promise<WorkflowRunServiceResult> {\n const runStore = this.createRunStore(params.agentId);\n const existing = await runStore.readRunView(params.runId);\n if (!existing) {\n return {\n ok: false,\n code: 'run_not_found',\n message: 'Workflow run not found',\n httpStatus: 404,\n };\n }\n\n const definition = await this.loadDefinition(existing.run.definitionId);\n if (!definition) {\n return {\n ok: false,\n code: 'definition_not_found',\n message: 'Workflow definition not found',\n httpStatus: 404,\n };\n }\n\n const targets = resolveWorkflowReplayTargets(existing, params.scope);\n if (targets.targets.length === 0) {\n return {\n ok: false,\n code: 'invalid_state',\n message: params.scope === 'failed_phases'\n ? 'No failed workflow phase is available to replay'\n : 'No failed workflow agent is available to replay',\n httpStatus: 409,\n };\n }\n\n const replayRunId = randomUUID();\n const goal = buildReplayGoal(existing, params.scope, targets.targets.length);\n const parentSessionKey =\n existing.run.source.kind === 'chat' ? existing.run.source.sessionKey : undefined;\n const projectId = existing.run.metadata?.projectId;\n const { sessionKey } = await this.options.sessionBridge.prepareRunSession({\n runId: replayRunId,\n agentId: params.agentId,\n definitionId: existing.run.definitionId,\n definitionTitle: `${definition.title} replay`,\n goal,\n parentSessionKey,\n projectId,\n });\n const source = normalizeWorkflowRunSourceForSession(existing.run.source, sessionKey, parentSessionKey);\n const abortController = new AbortController();\n const eventStore = new WorkflowEventStore(this.options.service.currentConfig, params.agentId);\n const replayRunStore = new WorkflowRunStore(this.options.service.currentConfig, params.agentId, eventStore);\n const engine = this.createWorkflowEngine({\n eventStore,\n runStore: replayRunStore,\n sessionKey,\n });\n const limits = resolveWorkflowRunLimits({\n config: this.options.service.currentConfig,\n definition,\n });\n const inputEnvelope = existing.run.metadata?.input ?? buildWorkflowRunInputEnvelope(existing.run.input, existing.run.goal);\n\n this.activeRuns.set(replayRunId, abortController);\n const timeoutHandle = setTimeout(() => {\n abortController.abort(new Error(`workflow timed out after ${limits.timeoutSec}s`));\n }, limits.timeoutSec * 1000);\n this.timeoutHandles.set(replayRunId, timeoutHandle);\n void engine.startReplayRun(definition, {\n runId: replayRunId,\n input: inputEnvelope.payload,\n goal,\n source,\n metadata: buildWorkflowRunMetadata({\n definition,\n agentId: params.agentId,\n goalId: existing.run.metadata?.goalId,\n projectId,\n sessionKey,\n source,\n input: inputEnvelope,\n retryOfRunId: existing.run.id,\n replay: {\n sourceRunId: existing.run.id,\n scope: params.scope,\n phaseIds: targets.phaseIds,\n agentIds: targets.targets.map((target) => target.agentId),\n targetCount: targets.targets.length,\n createdAtMs: Date.now(),\n },\n }),\n signal: abortController.signal,\n concurrency: limits.concurrency,\n maxSubagents: limits.maxSubagents,\n timeoutSec: limits.timeoutSec,\n sourceRunId: existing.run.id,\n replayScope: params.scope,\n targets: targets.targets,\n }).catch((err) => {\n this.options.service.emit('workflow.run.error', {\n runId: replayRunId,\n error: err instanceof Error ? err.message : String(err),\n });\n }).finally(() => {\n this.activeRuns.delete(replayRunId);\n const handle = this.timeoutHandles.get(replayRunId);\n if (handle) clearTimeout(handle);\n this.timeoutHandles.delete(replayRunId);\n });\n\n return { ok: true, runId: replayRunId, sessionKey };\n }\n\n async cancelWorkflowRun(params: CancelWorkflowRunServiceParams): Promise<CancelWorkflowRunResult> {\n const controller = this.activeRuns.get(params.runId);\n if (controller) {\n controller.abort();\n this.activeRuns.delete(params.runId);\n const handle = this.timeoutHandles.get(params.runId);\n if (handle) clearTimeout(handle);\n this.timeoutHandles.delete(params.runId);\n return { ok: true, cancelled: true };\n }\n\n const runStore = this.createRunStore(params.agentId);\n const view = await runStore.readRunView(params.runId);\n if (!view) {\n return {\n ok: false,\n code: 'run_not_found',\n message: 'Workflow run not found',\n httpStatus: 404,\n };\n }\n\n if (isTerminalWorkflowRunStatus(view.run.status)) {\n return { ok: true, cancelled: true, alreadyFinished: true };\n }\n\n const eventStore = new WorkflowEventStore(this.options.service.currentConfig, params.agentId);\n await eventStore.append({\n runId: params.runId,\n type: 'run_cancelled',\n payload: { reason: params.reason ?? 'Cancelled by user' },\n });\n const updated = await runStore.rebuildRunView(params.runId);\n if (updated) {\n this.options.service.emit('workflow.run.updated', { runId: params.runId, view: updated });\n void this.options.sessionBridge.handleRunViewUpdated(updated);\n }\n return { ok: true, cancelled: true };\n }\n\n createRunStore(agentId: string): WorkflowRunStore {\n const eventStore = new WorkflowEventStore(this.options.service.currentConfig, agentId);\n return new WorkflowRunStore(this.options.service.currentConfig, agentId, eventStore);\n }\n\n async readWorkflowRunView(agentId: string, runId: string) {\n return this.createRunStore(agentId).readRunView(runId);\n }\n\n async reconcileInterruptedRuns(agentId: string): Promise<number> {\n const runStore = this.createRunStore(agentId);\n const summaries = await runStore.listRunSummaries(500);\n let reconciled = 0;\n\n for (const summary of summaries) {\n if (isTerminalWorkflowRunStatus(summary.status) || this.activeRuns.has(summary.id)) {\n continue;\n }\n\n const eventStore = new WorkflowEventStore(this.options.service.currentConfig, agentId);\n await eventStore.append({\n runId: summary.id,\n type: 'run_failed',\n payload: {\n error: {\n code: 'runtime_error',\n message: 'Workflow run interrupted by gateway restart',\n recoverable: true,\n },\n },\n });\n const updated = await runStore.rebuildRunView(summary.id);\n if (updated) {\n this.options.service.emit('workflow.run.updated', { runId: summary.id, view: updated });\n void this.options.sessionBridge.handleRunViewUpdated(updated);\n }\n reconciled += 1;\n }\n\n return reconciled;\n }\n\n private loadDefinition(definitionId: string): Promise<WorkflowDefinition | null> {\n return this.definitionRegistry.get(definitionId);\n }\n\n private async findRunByIdempotencyKey(agentId: string, idempotencyKey: string) {\n const runStore = this.createRunStore(agentId);\n const summaries = await runStore.listRunSummaries(500);\n for (const summary of summaries) {\n if (summary.metadata?.correlation?.idempotencyKey !== idempotencyKey) {\n continue;\n }\n return runStore.readRunView(summary.id);\n }\n return null;\n }\n\n private createWorkflowEngine(params: {\n eventStore: WorkflowEventStore;\n runStore: WorkflowRunStore;\n sessionKey: string;\n }): WorkflowEngine {\n const gatewayService = this.options.service;\n const runner = new DelegateSubagentRunner({\n workspace: gatewayService.currentWorkspacePath,\n bus: gatewayService.messageBusInstance,\n getDefaultModel: () => resolveModelById(gatewayService.agentService.getModelForSession(params.sessionKey)),\n getConfig: () => gatewayService.currentConfig,\n sessionStore: gatewayService.sessionIndexInstance.getStore(),\n buildChildTools: (childOptions) => this.options.buildChildTools(childOptions),\n });\n\n return new WorkflowEngine({\n cwd: gatewayService.currentWorkspacePath,\n eventStore: params.eventStore,\n runStore: params.runStore,\n runner,\n resolveModelId: (modelId) => {\n const agentId = extractProfileAgentId(params.sessionKey, gatewayService.currentConfig);\n return resolveModelById(resolveModelRef(gatewayService.currentConfig, agentId, modelId));\n },\n parentSessionKey: params.sessionKey,\n subagentSessionKeyFactory: ({ runId, agentId }) => {\n const profileAgentId = extractProfileAgentId(params.sessionKey, gatewayService.currentConfig);\n return `agent:${profileAgentId}:workflow:${runId}:subagent:${agentId}`;\n },\n onEventAppended: (event) => {\n gatewayService.emit('workflow.event.appended', { runId: event.runId, event });\n },\n onRunViewUpdated: (view) => {\n gatewayService.emit('workflow.run.updated', { runId: view.run.id, view });\n this.publishTerminalWorkflowAutomationEvent(view);\n void this.options.sessionBridge.handleRunViewUpdated(view);\n },\n });\n }\n\n private publishTerminalWorkflowAutomationEvent(view: WorkflowRunView): void {\n if (!isTerminalWorkflowRunStatus(view.run.status)) return;\n if (this.emittedTerminalAutomationEvents.has(view.run.id)) return;\n this.emittedTerminalAutomationEvents.add(view.run.id);\n publishAutomationProductEvent({\n type: 'workflow.run.completed',\n source: 'workflows',\n payload: {\n runId: view.run.id,\n status: view.run.status,\n definitionId: view.run.definitionId,\n title: view.run.title,\n sessionKey: view.run.metadata?.sessionKey,\n sourceKind: view.run.source.kind,\n },\n occurredAtMs: view.run.completedAtMs ?? Date.now(),\n });\n }\n}\n\nfunction normalizeWorkflowRunSourceForSession(\n source: WorkflowRunSource,\n workflowSessionKey: string,\n parentSessionKey?: string,\n): WorkflowRunSource {\n if (parentSessionKey?.trim()) {\n return { kind: 'chat', sessionKey: parentSessionKey.trim() };\n }\n if (source.kind === 'webui') {\n return { ...source, sessionKey: workflowSessionKey };\n }\n if (source.kind === 'chat') {\n return source;\n }\n return source;\n}\n\nexport function buildWorkflowRunInputEnvelope(input: unknown, goal?: string): WorkflowRunInputEnvelope {\n if (isWorkflowRunInputEnvelope(input)) {\n return input;\n }\n return {\n payload: input ?? {},\n goal,\n };\n}\n\nexport function buildWorkflowRunMetadata(params: {\n definition: WorkflowDefinition;\n agentId: string;\n goalId?: string;\n projectId?: string;\n sessionKey: string;\n source: WorkflowRunSource;\n input: WorkflowRunInputEnvelope;\n retryOfRunId?: string;\n idempotencyKey?: string;\n replay?: WorkflowRunReplayMetadata;\n}): WorkflowRunMetadata {\n const goalId = params.goalId?.trim() || undefined;\n const projectId = params.projectId?.trim() || undefined;\n return {\n sessionKey: params.sessionKey,\n triggerSource: params.source.kind,\n agentId: params.agentId,\n projectId,\n retryOfRunId: params.retryOfRunId,\n replay: params.replay,\n definition: buildWorkflowRunDefinitionSnapshot(params.definition),\n input: params.input,\n correlation: {\n idempotencyKey: params.idempotencyKey,\n },\n origin: buildWorkflowRunOrigin(params.source),\n schedule: params.source.kind === 'automation'\n ? { automationId: params.source.automationId, runId: params.source.runId, scheduledAtMs: params.source.scheduledAtMs }\n : undefined,\n goalId,\n };\n}\n\nexport function resolveWorkflowReplayTargets(\n view: WorkflowRunView,\n scope: WorkflowRunReplayScope,\n): { targets: WorkflowReplayAgentTarget[]; phaseIds?: string[] } {\n const phaseTitleById = new Map(view.phases.map((phase) => [phase.id, phase.title]));\n const failedStatuses = new Set(['error', 'skipped']);\n\n if (scope === 'failed_agents') {\n return {\n targets: view.agents\n .filter((agent) => failedStatuses.has(agent.status) && workflowAgentReplayPrompt(agent))\n .map((agent) => ({\n agentId: agent.id,\n label: agent.label,\n phaseId: agent.phaseId,\n phaseTitle: agent.phaseId ? phaseTitleById.get(agent.phaseId) : undefined,\n prompt: workflowAgentReplayPrompt(agent) ?? '',\n invocation: agent.invocation,\n })),\n };\n }\n\n const failedPhaseIds = view.phases\n .filter((phase) => phase.status === 'failed')\n .map((phase) => phase.id);\n const phaseIds = failedPhaseIds.length > 0\n ? failedPhaseIds\n : [...new Set(view.agents.filter((agent) => failedStatuses.has(agent.status) && agent.phaseId).map((agent) => agent.phaseId as string))];\n const phaseIdSet = new Set(phaseIds);\n\n return {\n phaseIds,\n targets: view.agents\n .filter((agent) => agent.phaseId && phaseIdSet.has(agent.phaseId) && workflowAgentReplayPrompt(agent))\n .map((agent) => ({\n agentId: agent.id,\n label: agent.label,\n phaseId: agent.phaseId,\n phaseTitle: agent.phaseId ? phaseTitleById.get(agent.phaseId) : undefined,\n prompt: workflowAgentReplayPrompt(agent) ?? '',\n invocation: agent.invocation,\n })),\n };\n}\n\nfunction workflowAgentReplayPrompt(agent: WorkflowRunView['agents'][number]): string | undefined {\n const invocationPrompt = agent.invocation?.prompt?.trim();\n if (invocationPrompt) return invocationPrompt;\n const prompt = agent.prompt?.trim();\n return prompt || undefined;\n}\n\nexport function buildWorkflowRunDefinitionSnapshot(definition: WorkflowDefinition): WorkflowRunDefinitionSnapshot {\n const snapshot: WorkflowRunDefinitionSnapshot = {\n id: definition.id,\n name: definition.name,\n title: definition.title,\n version: definition.version,\n source: definition.metadata.source,\n tags: [...definition.metadata.tags],\n phaseCount: definition.phases.length,\n defaults: { ...definition.defaults },\n estimatedAgents: definition.metadata.estimatedAgents,\n };\n if (definition.contentHash) snapshot.contentHash = definition.contentHash;\n if (definition.runtimeHash) snapshot.runtimeHash = definition.runtimeHash;\n if (definition.permissions) snapshot.permissions = structuredClone(definition.permissions);\n if (definition.resources) snapshot.resources = structuredClone(definition.resources);\n return snapshot;\n}\n\nfunction resolveWorkflowRunLimits(params: {\n config: import('../../config/schema.js').Config;\n definition: WorkflowDefinition;\n concurrency?: number;\n maxSubagents?: number;\n}): { concurrency: number; maxSubagents: number; timeoutSec: number } {\n const configuredMaxConcurrency = normalizePositiveInt(\n undefined,\n params.definition.defaults.concurrency,\n );\n const configuredMaxSubagents = normalizePositiveInt(\n undefined,\n params.definition.defaults.maxSubagents,\n );\n const configuredTimeoutSec = normalizePositiveInt(\n undefined,\n params.definition.defaults.timeoutSec,\n );\n\n return {\n concurrency: Math.max(\n 1,\n Math.min(\n normalizePositiveInt(params.concurrency, params.definition.defaults.concurrency),\n configuredMaxConcurrency,\n ),\n ),\n maxSubagents: Math.max(\n 1,\n Math.min(\n normalizePositiveInt(params.maxSubagents, params.definition.defaults.maxSubagents),\n configuredMaxSubagents,\n ),\n ),\n timeoutSec: Math.max(1, Math.min(params.definition.defaults.timeoutSec, configuredTimeoutSec)),\n };\n}\n\nfunction normalizePositiveInt(value: number | undefined, fallback: number): number {\n if (typeof value !== 'number' || !Number.isFinite(value) || value < 1) {\n return fallback;\n }\n return Math.floor(value);\n}\n\nfunction buildReplayGoal(view: WorkflowRunView, scope: WorkflowRunReplayScope, targetCount: number): string {\n const scopeLabel = scope === 'failed_phases' ? 'failed phase' : 'failed agent';\n return `Replay ${targetCount} ${scopeLabel}${targetCount === 1 ? '' : 's'} from workflow run ${view.run.id}: ${view.run.goal}`;\n}\n\nexport function extractWorkflowRunSessionKey(source: WorkflowRunSource): string | null {\n if ('sessionKey' in source && typeof source.sessionKey === 'string' && source.sessionKey.trim()) {\n return source.sessionKey.trim();\n }\n return null;\n}\n\nfunction buildWorkflowRunOrigin(source: WorkflowRunSource): WorkflowRunMetadata['origin'] {\n switch (source.kind) {\n case 'chat':\n return { channel: 'chat', sessionKey: source.sessionKey, messageId: source.messageId };\n case 'webui':\n return { channel: 'webui', sessionKey: source.sessionKey };\n case 'automation':\n return { channel: 'automation', automationId: source.automationId, runId: source.runId };\n case 'api':\n return { channel: 'api', requestId: source.requestId };\n case 'im':\n return { channel: source.channel, chatId: source.chatId, messageId: source.messageId };\n }\n}\n\nfunction isWorkflowRunInputEnvelope(input: unknown): input is WorkflowRunInputEnvelope {\n if (!input || typeof input !== 'object' || Array.isArray(input)) {\n return false;\n }\n return 'payload' in input || 'variables' in input || 'context' in input;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;gBAU4E;AAgD5E,IAAa,qBAAb,MAAgC;CAC9B,6BAA8B,IAAI,KAA8B;CAChE,iCAAkC,IAAI,KAA4C;CAClF;CACA,kDAAmD,IAAI,KAAa;CAEpE,YAAY,SAAqD;AAApC,OAAA,UAAA;AAC3B,OAAK,qBAAqB,QAAQ,sBAAsB,IAAI,mCAAmC;;CAGjG,MAAM,iBAAiB,QAA0E;EAC/F,MAAM,aAAa,MAAM,KAAK,eAAe,OAAO,aAAa;AACjE,MAAI,CAAC,WACH,QAAO;GACL,IAAI;GACJ,MAAM;GACN,SAAS;GACT,YAAY;GACb;EAGH,MAAM,gBAAgB,OAAO,iBAAiB,8BAA8B,O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,aACH,QAAO;GAAE,SAAS;GAAc,cAAc,OAAO;GAAc,OAAO,OAAO;GAAO;EAC1F,KAAK,MACH,QAAO;GAAE,SAAS;GAAO,WAAW,OAAO;GAAW;EACxD,KAAK,KACH,QAAO;GAAE,SAAS,OAAO;GAAS,QAAQ,OAAO;GAAQ,WAAW,OAAO;GAAW;;;AAI5F,SAAS,2BAA2B,OAAmD;AACrF,KAAI,CAAC,SAAS,OAAO,UAAU,YAAY,MAAM,QAAQ,MAAM,CAC7D,QAAO;AAET,QAAO,aAAa,SAAS,eAAe,SAAS,aAAa"}
1
+ {"version":3,"file":"workflow-run-service.js","names":["resolveModelById"],"sources":["../../../../src/workflows/service/workflow-run-service.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport type { AgentTool } from '@earendil-works/pi-agent-core';\n\nimport type { BuildChildToolsOptions } from '../../agent/child-agent-factory.js';\nimport { publishAutomationProductEvent } from '../../automations/product-events.js';\nimport { extractProfileAgentId } from '../../config/agent-profile.js';\nimport { resolveModelRef } from '../../config/agent-typed-models.js';\nimport type { GatewayWorkflowHost } from '../../gateway/gateway-workflow-host.types.js';\nimport { GoalService } from '../../goals/index.js';\nimport { resolveModel as resolveModelById } from '../../providers/index.js';\nimport { DelegateSubagentRunner } from '../../agent/workflow/subagent-runner.js';\nimport { CatalogWorkflowDefinitionRegistry } from '../registry/catalog-workflow-definition-registry.js';\nimport type { WorkflowDefinitionRegistry } from '../registry/workflow-definition-registry.js';\nimport { validateWorkflowJsonSchema } from '../domain/schema-validation.js';\nimport type {\n WorkflowDefinition,\n WorkflowRunDefinitionSnapshot,\n WorkflowRunInputEnvelope,\n WorkflowRunMetadata,\n WorkflowRunSource,\n} from '../domain/index.js';\nimport { isTerminalWorkflowRunStatus } from '../domain/index.js';\nimport { WorkflowEngine } from '../engine/index.js';\nimport { WorkflowEventStore } from '../store/event-store.js';\nimport { WorkflowRunStore } from '../store/run-store.js';\nimport type { WorkflowSessionBridge } from './workflow-session-bridge.js';\nexport type {\n CancelWorkflowRunResult,\n CancelWorkflowRunServiceParams,\n CancelWorkflowRunServiceResult,\n ReplayWorkflowRunServiceParams,\n RetryWorkflowRunServiceParams,\n StartWorkflowRunServiceParams,\n StartWorkflowRunServiceResult,\n WorkflowRunServiceErrorCode,\n WorkflowRunServiceErrorResult,\n WorkflowRunServiceResult,\n} from './workflow-run-service.types.js';\n\nimport type {\n CancelWorkflowRunResult,\n CancelWorkflowRunServiceParams,\n ReplayWorkflowRunServiceParams,\n RetryWorkflowRunServiceParams,\n StartWorkflowRunServiceParams,\n WorkflowRunServiceResult,\n} from './workflow-run-service.types.js';\nimport type { WorkflowRunReplayMetadata, WorkflowRunReplayScope, WorkflowRunView } from '../domain/run.js';\nimport type { WorkflowReplayAgentTarget } from '../engine/index.js';\n\nexport interface WorkflowRunServiceOptions {\n service: GatewayWorkflowHost;\n sessionBridge: WorkflowSessionBridge;\n buildChildTools: (childOptions: BuildChildToolsOptions) => AgentTool<any, any>[];\n definitionRegistry?: WorkflowDefinitionRegistry;\n}\n\nexport class WorkflowRunService {\n private readonly activeRuns = new Map<string, AbortController>();\n private readonly timeoutHandles = new Map<string, ReturnType<typeof setTimeout>>();\n private readonly definitionRegistry: WorkflowDefinitionRegistry;\n private readonly emittedTerminalAutomationEvents = new Set<string>();\n\n constructor(private readonly options: WorkflowRunServiceOptions) {\n this.definitionRegistry = options.definitionRegistry ?? new CatalogWorkflowDefinitionRegistry();\n }\n\n async startWorkflowRun(params: StartWorkflowRunServiceParams): Promise<WorkflowRunServiceResult> {\n const definition = await this.loadDefinition(params.definitionId);\n if (!definition) {\n return {\n ok: false,\n code: 'definition_not_found',\n message: 'Workflow definition not found',\n httpStatus: 404,\n };\n }\n\n const inputEnvelope = params.inputEnvelope ?? buildWorkflowRunInputEnvelope(params.input, params.goal);\n const inputValidation = validateWorkflowJsonSchema(definition.inputSchema, inputEnvelope.payload);\n if (!inputValidation.ok) {\n return {\n ok: false,\n code: 'invalid_input',\n message: inputValidation.message ?? 'Workflow input did not match input schema',\n httpStatus: 400,\n };\n }\n\n const existingRun = params.idempotencyKey\n ? await this.findRunByIdempotencyKey(params.agentId, params.idempotencyKey)\n : null;\n if (existingRun) {\n return {\n ok: true,\n runId: existingRun.run.id,\n sessionKey: existingRun.run.metadata?.sessionKey ?? '',\n };\n }\n\n const runId = randomUUID();\n const goal = params.goal ?? '';\n const projectId =\n params.projectId?.trim() ||\n (params.goalId ? new GoalService().get(params.goalId)?.projectId : undefined) ||\n (params.parentSessionKey?.trim()\n ? (await this.options.service.sessionIndexInstance.getStore().getMetadata(params.parentSessionKey.trim()))?.projectId\n : undefined);\n const { sessionKey } = await this.options.sessionBridge.prepareRunSession({\n runId,\n agentId: params.agentId,\n definitionId: params.definitionId,\n definitionTitle: definition.title,\n goal,\n parentSessionKey: params.parentSessionKey,\n projectId,\n });\n const source = normalizeWorkflowRunSourceForSession(params.source, sessionKey, params.parentSessionKey);\n const abortController = new AbortController();\n const eventStore = new WorkflowEventStore(this.options.service.currentConfig, params.agentId);\n const runStore = new WorkflowRunStore(this.options.service.currentConfig, params.agentId, eventStore);\n const engine = this.createWorkflowEngine({\n eventStore,\n runStore,\n sessionKey,\n });\n const limits = resolveWorkflowRunLimits({\n config: this.options.service.currentConfig,\n definition,\n concurrency: params.concurrency,\n maxSubagents: params.maxSubagents,\n });\n\n this.activeRuns.set(runId, abortController);\n const timeoutHandle = setTimeout(() => {\n abortController.abort(new Error(`workflow timed out after ${limits.timeoutSec}s`));\n }, limits.timeoutSec * 1000);\n this.timeoutHandles.set(runId, timeoutHandle);\n void engine.startRun(definition, {\n runId,\n input: inputEnvelope.payload,\n goal: inputEnvelope.goal ?? params.goal,\n source,\n metadata: buildWorkflowRunMetadata({\n definition,\n agentId: params.agentId,\n goalId: params.goalId,\n projectId,\n sessionKey,\n source,\n input: inputEnvelope,\n retryOfRunId: params.retryOfRunId,\n idempotencyKey: params.idempotencyKey,\n }),\n signal: abortController.signal,\n concurrency: limits.concurrency,\n maxSubagents: limits.maxSubagents,\n tokenBudget: params.tokenBudget,\n timeoutSec: limits.timeoutSec,\n }).catch((err) => {\n this.options.service.emit('workflow.run.error', {\n runId,\n error: err instanceof Error ? err.message : String(err),\n });\n }).finally(() => {\n this.activeRuns.delete(runId);\n const handle = this.timeoutHandles.get(runId);\n if (handle) clearTimeout(handle);\n this.timeoutHandles.delete(runId);\n });\n\n return { ok: true, runId, sessionKey };\n }\n\n async retryWorkflowRun(params: RetryWorkflowRunServiceParams): Promise<WorkflowRunServiceResult> {\n const runStore = this.createRunStore(params.agentId);\n const existing = await runStore.readRunView(params.runId);\n if (!existing) {\n return {\n ok: false,\n code: 'run_not_found',\n message: 'Workflow run not found',\n httpStatus: 404,\n };\n }\n\n const parentSessionKey =\n existing.run.source.kind === 'chat' ? existing.run.source.sessionKey : undefined;\n const projectId = params.projectId?.trim() || existing.run.metadata?.projectId;\n\n return this.startWorkflowRun({\n agentId: params.agentId,\n definitionId: existing.run.definitionId,\n goalId: existing.run.metadata?.goalId,\n projectId,\n input: existing.run.metadata?.input ? undefined : existing.run.input,\n inputEnvelope: existing.run.metadata?.input,\n goal: existing.run.goal,\n source: existing.run.source,\n parentSessionKey,\n retryOfRunId: existing.run.id,\n });\n }\n\n async replayWorkflowRun(params: ReplayWorkflowRunServiceParams): Promise<WorkflowRunServiceResult> {\n const runStore = this.createRunStore(params.agentId);\n const existing = await runStore.readRunView(params.runId);\n if (!existing) {\n return {\n ok: false,\n code: 'run_not_found',\n message: 'Workflow run not found',\n httpStatus: 404,\n };\n }\n\n const definition = await this.loadDefinition(existing.run.definitionId);\n if (!definition) {\n return {\n ok: false,\n code: 'definition_not_found',\n message: 'Workflow definition not found',\n httpStatus: 404,\n };\n }\n\n const targets = resolveWorkflowReplayTargets(existing, params.scope);\n if (targets.targets.length === 0) {\n return {\n ok: false,\n code: 'invalid_state',\n message: params.scope === 'failed_phases'\n ? 'No failed workflow phase is available to replay'\n : 'No failed workflow agent is available to replay',\n httpStatus: 409,\n };\n }\n\n const replayRunId = randomUUID();\n const goal = buildReplayGoal(existing, params.scope, targets.targets.length);\n const parentSessionKey =\n existing.run.source.kind === 'chat' ? existing.run.source.sessionKey : undefined;\n const projectId = existing.run.metadata?.projectId;\n const { sessionKey } = await this.options.sessionBridge.prepareRunSession({\n runId: replayRunId,\n agentId: params.agentId,\n definitionId: existing.run.definitionId,\n definitionTitle: `${definition.title} replay`,\n goal,\n parentSessionKey,\n projectId,\n });\n const source = normalizeWorkflowRunSourceForSession(existing.run.source, sessionKey, parentSessionKey);\n const abortController = new AbortController();\n const eventStore = new WorkflowEventStore(this.options.service.currentConfig, params.agentId);\n const replayRunStore = new WorkflowRunStore(this.options.service.currentConfig, params.agentId, eventStore);\n const engine = this.createWorkflowEngine({\n eventStore,\n runStore: replayRunStore,\n sessionKey,\n });\n const limits = resolveWorkflowRunLimits({\n config: this.options.service.currentConfig,\n definition,\n });\n const inputEnvelope = existing.run.metadata?.input ?? buildWorkflowRunInputEnvelope(existing.run.input, existing.run.goal);\n\n this.activeRuns.set(replayRunId, abortController);\n const timeoutHandle = setTimeout(() => {\n abortController.abort(new Error(`workflow timed out after ${limits.timeoutSec}s`));\n }, limits.timeoutSec * 1000);\n this.timeoutHandles.set(replayRunId, timeoutHandle);\n void engine.startReplayRun(definition, {\n runId: replayRunId,\n input: inputEnvelope.payload,\n goal,\n source,\n metadata: buildWorkflowRunMetadata({\n definition,\n agentId: params.agentId,\n goalId: existing.run.metadata?.goalId,\n projectId,\n sessionKey,\n source,\n input: inputEnvelope,\n retryOfRunId: existing.run.id,\n replay: {\n sourceRunId: existing.run.id,\n scope: params.scope,\n phaseIds: targets.phaseIds,\n agentIds: targets.targets.map((target) => target.agentId),\n targetCount: targets.targets.length,\n createdAtMs: Date.now(),\n },\n }),\n signal: abortController.signal,\n concurrency: limits.concurrency,\n maxSubagents: limits.maxSubagents,\n timeoutSec: limits.timeoutSec,\n sourceRunId: existing.run.id,\n replayScope: params.scope,\n targets: targets.targets,\n }).catch((err) => {\n this.options.service.emit('workflow.run.error', {\n runId: replayRunId,\n error: err instanceof Error ? err.message : String(err),\n });\n }).finally(() => {\n this.activeRuns.delete(replayRunId);\n const handle = this.timeoutHandles.get(replayRunId);\n if (handle) clearTimeout(handle);\n this.timeoutHandles.delete(replayRunId);\n });\n\n return { ok: true, runId: replayRunId, sessionKey };\n }\n\n async cancelWorkflowRun(params: CancelWorkflowRunServiceParams): Promise<CancelWorkflowRunResult> {\n const controller = this.activeRuns.get(params.runId);\n if (controller) {\n controller.abort();\n this.activeRuns.delete(params.runId);\n const handle = this.timeoutHandles.get(params.runId);\n if (handle) clearTimeout(handle);\n this.timeoutHandles.delete(params.runId);\n return { ok: true, cancelled: true };\n }\n\n const runStore = this.createRunStore(params.agentId);\n const view = await runStore.readRunView(params.runId);\n if (!view) {\n return {\n ok: false,\n code: 'run_not_found',\n message: 'Workflow run not found',\n httpStatus: 404,\n };\n }\n\n if (isTerminalWorkflowRunStatus(view.run.status)) {\n return { ok: true, cancelled: true, alreadyFinished: true };\n }\n\n const eventStore = new WorkflowEventStore(this.options.service.currentConfig, params.agentId);\n await eventStore.append({\n runId: params.runId,\n type: 'run_cancelled',\n payload: { reason: params.reason ?? 'Cancelled by user' },\n });\n const updated = await runStore.rebuildRunView(params.runId);\n if (updated) {\n this.options.service.emit('workflow.run.updated', { runId: params.runId, view: updated });\n void this.options.sessionBridge.handleRunViewUpdated(updated);\n }\n return { ok: true, cancelled: true };\n }\n\n createRunStore(agentId: string): WorkflowRunStore {\n const eventStore = new WorkflowEventStore(this.options.service.currentConfig, agentId);\n return new WorkflowRunStore(this.options.service.currentConfig, agentId, eventStore);\n }\n\n async readWorkflowRunView(agentId: string, runId: string) {\n return this.createRunStore(agentId).readRunView(runId);\n }\n\n async reconcileInterruptedRuns(agentId: string): Promise<number> {\n const runStore = this.createRunStore(agentId);\n const summaries = await runStore.listRunSummaries(500);\n let reconciled = 0;\n\n for (const summary of summaries) {\n if (isTerminalWorkflowRunStatus(summary.status) || this.activeRuns.has(summary.id)) {\n continue;\n }\n\n const eventStore = new WorkflowEventStore(this.options.service.currentConfig, agentId);\n await eventStore.append({\n runId: summary.id,\n type: 'run_failed',\n payload: {\n error: {\n code: 'runtime_error',\n message: 'Workflow run interrupted by gateway restart',\n recoverable: true,\n },\n },\n });\n const updated = await runStore.rebuildRunView(summary.id);\n if (updated) {\n this.options.service.emit('workflow.run.updated', { runId: summary.id, view: updated });\n void this.options.sessionBridge.handleRunViewUpdated(updated);\n }\n reconciled += 1;\n }\n\n return reconciled;\n }\n\n private loadDefinition(definitionId: string): Promise<WorkflowDefinition | null> {\n return this.definitionRegistry.get(definitionId);\n }\n\n private async findRunByIdempotencyKey(agentId: string, idempotencyKey: string) {\n const runStore = this.createRunStore(agentId);\n const summaries = await runStore.listRunSummaries(500);\n for (const summary of summaries) {\n if (summary.metadata?.correlation?.idempotencyKey !== idempotencyKey) {\n continue;\n }\n return runStore.readRunView(summary.id);\n }\n return null;\n }\n\n private createWorkflowEngine(params: {\n eventStore: WorkflowEventStore;\n runStore: WorkflowRunStore;\n sessionKey: string;\n }): WorkflowEngine {\n const gatewayService = this.options.service;\n const runner = new DelegateSubagentRunner({\n workspace: gatewayService.currentWorkspacePath,\n bus: gatewayService.messageBusInstance,\n getDefaultModel: () => resolveModelById(gatewayService.agentService.getModelForSession(params.sessionKey)),\n getConfig: () => gatewayService.currentConfig,\n sessionStore: gatewayService.sessionIndexInstance.getStore(),\n buildChildTools: (childOptions) => this.options.buildChildTools(childOptions),\n });\n\n return new WorkflowEngine({\n cwd: gatewayService.currentWorkspacePath,\n eventStore: params.eventStore,\n runStore: params.runStore,\n runner,\n resolveModelId: (modelId) => {\n const agentId = extractProfileAgentId(params.sessionKey, gatewayService.currentConfig);\n return resolveModelById(resolveModelRef(gatewayService.currentConfig, agentId, modelId));\n },\n parentSessionKey: params.sessionKey,\n subagentSessionKeyFactory: ({ runId, agentId }) => {\n const profileAgentId = extractProfileAgentId(params.sessionKey, gatewayService.currentConfig);\n return `agent:${profileAgentId}:workflow:${runId}:subagent:${agentId}`;\n },\n onEventAppended: (event) => {\n gatewayService.emit('workflow.event.appended', { runId: event.runId, event });\n },\n onRunViewUpdated: (view) => {\n gatewayService.emit('workflow.run.updated', { runId: view.run.id, view });\n this.publishTerminalWorkflowAutomationEvent(view);\n void this.options.sessionBridge.handleRunViewUpdated(view);\n },\n });\n }\n\n private publishTerminalWorkflowAutomationEvent(view: WorkflowRunView): void {\n if (!isTerminalWorkflowRunStatus(view.run.status)) return;\n if (this.emittedTerminalAutomationEvents.has(view.run.id)) return;\n this.emittedTerminalAutomationEvents.add(view.run.id);\n publishAutomationProductEvent({\n type: 'workflow.run.completed',\n source: 'workflows',\n payload: {\n runId: view.run.id,\n status: view.run.status,\n definitionId: view.run.definitionId,\n title: view.run.title,\n sessionKey: view.run.metadata?.sessionKey,\n sourceKind: view.run.source.kind,\n },\n occurredAtMs: view.run.completedAtMs ?? Date.now(),\n });\n }\n}\n\nfunction normalizeWorkflowRunSourceForSession(\n source: WorkflowRunSource,\n workflowSessionKey: string,\n parentSessionKey?: string,\n): WorkflowRunSource {\n if (parentSessionKey?.trim()) {\n return { kind: 'chat', sessionKey: parentSessionKey.trim() };\n }\n if (source.kind === 'webui') {\n return { ...source, sessionKey: workflowSessionKey };\n }\n if (source.kind === 'chat') {\n return source;\n }\n return source;\n}\n\nexport function buildWorkflowRunInputEnvelope(input: unknown, goal?: string): WorkflowRunInputEnvelope {\n if (isWorkflowRunInputEnvelope(input)) {\n return input;\n }\n return {\n payload: input ?? {},\n goal,\n };\n}\n\nexport function buildWorkflowRunMetadata(params: {\n definition: WorkflowDefinition;\n agentId: string;\n goalId?: string;\n projectId?: string;\n sessionKey: string;\n source: WorkflowRunSource;\n input: WorkflowRunInputEnvelope;\n retryOfRunId?: string;\n idempotencyKey?: string;\n replay?: WorkflowRunReplayMetadata;\n}): WorkflowRunMetadata {\n const goalId = params.goalId?.trim() || undefined;\n const projectId = params.projectId?.trim() || undefined;\n return {\n sessionKey: params.sessionKey,\n triggerSource: params.source.kind,\n agentId: params.agentId,\n projectId,\n retryOfRunId: params.retryOfRunId,\n replay: params.replay,\n definition: buildWorkflowRunDefinitionSnapshot(params.definition),\n input: params.input,\n correlation: {\n idempotencyKey: params.idempotencyKey,\n },\n origin: buildWorkflowRunOrigin(params.source),\n schedule: params.source.kind === 'automation'\n ? { automationId: params.source.automationId, runId: params.source.runId, scheduledAtMs: params.source.scheduledAtMs }\n : undefined,\n goalId,\n };\n}\n\nexport function resolveWorkflowReplayTargets(\n view: WorkflowRunView,\n scope: WorkflowRunReplayScope,\n): { targets: WorkflowReplayAgentTarget[]; phaseIds?: string[] } {\n const phaseTitleById = new Map(view.phases.map((phase) => [phase.id, phase.title]));\n const failedStatuses = new Set(['error', 'skipped']);\n\n if (scope === 'failed_agents') {\n return {\n targets: view.agents\n .filter((agent) => failedStatuses.has(agent.status) && workflowAgentReplayPrompt(agent))\n .map((agent) => ({\n agentId: agent.id,\n label: agent.label,\n phaseId: agent.phaseId,\n phaseTitle: agent.phaseId ? phaseTitleById.get(agent.phaseId) : undefined,\n prompt: workflowAgentReplayPrompt(agent) ?? '',\n invocation: agent.invocation,\n })),\n };\n }\n\n const failedPhaseIds = view.phases\n .filter((phase) => phase.status === 'failed')\n .map((phase) => phase.id);\n const phaseIds = failedPhaseIds.length > 0\n ? failedPhaseIds\n : [...new Set(view.agents.filter((agent) => failedStatuses.has(agent.status) && agent.phaseId).map((agent) => agent.phaseId as string))];\n const phaseIdSet = new Set(phaseIds);\n\n return {\n phaseIds,\n targets: view.agents\n .filter((agent) => agent.phaseId && phaseIdSet.has(agent.phaseId) && workflowAgentReplayPrompt(agent))\n .map((agent) => ({\n agentId: agent.id,\n label: agent.label,\n phaseId: agent.phaseId,\n phaseTitle: agent.phaseId ? phaseTitleById.get(agent.phaseId) : undefined,\n prompt: workflowAgentReplayPrompt(agent) ?? '',\n invocation: agent.invocation,\n })),\n };\n}\n\nfunction workflowAgentReplayPrompt(agent: WorkflowRunView['agents'][number]): string | undefined {\n const invocationPrompt = agent.invocation?.prompt?.trim();\n if (invocationPrompt) return invocationPrompt;\n const prompt = agent.prompt?.trim();\n return prompt || undefined;\n}\n\nexport function buildWorkflowRunDefinitionSnapshot(definition: WorkflowDefinition): WorkflowRunDefinitionSnapshot {\n const snapshot: WorkflowRunDefinitionSnapshot = {\n id: definition.id,\n name: definition.name,\n title: definition.title,\n version: definition.version,\n source: definition.metadata.source,\n tags: [...definition.metadata.tags],\n phaseCount: definition.phases.length,\n defaults: { ...definition.defaults },\n estimatedAgents: definition.metadata.estimatedAgents,\n };\n if (definition.contentHash) snapshot.contentHash = definition.contentHash;\n if (definition.runtimeHash) snapshot.runtimeHash = definition.runtimeHash;\n if (definition.permissions) snapshot.permissions = structuredClone(definition.permissions);\n if (definition.resources) snapshot.resources = structuredClone(definition.resources);\n return snapshot;\n}\n\nfunction resolveWorkflowRunLimits(params: {\n config: import('../../config/schema.js').Config;\n definition: WorkflowDefinition;\n concurrency?: number;\n maxSubagents?: number;\n}): { concurrency: number; maxSubagents: number; timeoutSec: number } {\n const configuredMaxConcurrency = normalizePositiveInt(\n undefined,\n params.definition.defaults.concurrency,\n );\n const configuredMaxSubagents = normalizePositiveInt(\n undefined,\n params.definition.defaults.maxSubagents,\n );\n const configuredTimeoutSec = normalizePositiveInt(\n undefined,\n params.definition.defaults.timeoutSec,\n );\n\n return {\n concurrency: Math.max(\n 1,\n Math.min(\n normalizePositiveInt(params.concurrency, params.definition.defaults.concurrency),\n configuredMaxConcurrency,\n ),\n ),\n maxSubagents: Math.max(\n 1,\n Math.min(\n normalizePositiveInt(params.maxSubagents, params.definition.defaults.maxSubagents),\n configuredMaxSubagents,\n ),\n ),\n timeoutSec: Math.max(1, Math.min(params.definition.defaults.timeoutSec, configuredTimeoutSec)),\n };\n}\n\nfunction normalizePositiveInt(value: number | undefined, fallback: number): number {\n if (typeof value !== 'number' || !Number.isFinite(value) || value < 1) {\n return fallback;\n }\n return Math.floor(value);\n}\n\nfunction buildReplayGoal(view: WorkflowRunView, scope: WorkflowRunReplayScope, targetCount: number): string {\n const scopeLabel = scope === 'failed_phases' ? 'failed phase' : 'failed agent';\n return `Replay ${targetCount} ${scopeLabel}${targetCount === 1 ? '' : 's'} from workflow run ${view.run.id}: ${view.run.goal}`;\n}\n\nexport function extractWorkflowRunSessionKey(source: WorkflowRunSource): string | null {\n if ('sessionKey' in source && typeof source.sessionKey === 'string' && source.sessionKey.trim()) {\n return source.sessionKey.trim();\n }\n return null;\n}\n\nfunction buildWorkflowRunOrigin(source: WorkflowRunSource): WorkflowRunMetadata['origin'] {\n switch (source.kind) {\n case 'chat':\n return { channel: 'chat', sessionKey: source.sessionKey, messageId: source.messageId };\n case 'webui':\n return { channel: 'webui', sessionKey: source.sessionKey };\n case 'automation':\n return { channel: 'automation', automationId: source.automationId, runId: source.runId };\n case 'api':\n return { channel: 'api', requestId: source.requestId };\n case 'im':\n return { channel: source.channel, chatId: source.chatId, messageId: source.messageId };\n }\n}\n\nfunction isWorkflowRunInputEnvelope(input: unknown): input is WorkflowRunInputEnvelope {\n if (!input || typeof input !== 'object' || Array.isArray(input)) {\n return false;\n }\n return 'payload' in input || 'variables' in input || 'context' in input;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;gBAU4E;AAgD5E,IAAa,qBAAb,MAAgC;CAC9B,6BAA8B,IAAI,KAA8B;CAChE,iCAAkC,IAAI,KAA4C;CAClF;CACA,kDAAmD,IAAI,KAAa;CAEpE,YAAY,SAAqD;AAApC,OAAA,UAAA;AAC3B,OAAK,qBAAqB,QAAQ,sBAAsB,IAAI,mCAAmC;;CAGjG,MAAM,iBAAiB,QAA0E;EAC/F,MAAM,aAAa,MAAM,KAAK,eAAe,OAAO,aAAa;AACjE,MAAI,CAAC,WACH,QAAO;GACL,IAAI;GACJ,MAAM;GACN,SAAS;GACT,YAAY;GACb;EAGH,MAAM,gBAAgB,OAAO,iBAAiB,8BAA8B,OAAO,OAAO,OA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AS;GAAQ,YAAY,OAAO;GAAY,WAAW,OAAO;GAAW;EACxF,KAAK,QACH,QAAO;GAAE,SAAS;GAAS,YAAY,OAAO;GAAY;EAC5D,KAAK,aACH,QAAO;GAAE,SAAS;GAAc,cAAc,OAAO;GAAc,OAAO,OAAO;GAAO;EAC1F,KAAK,MACH,QAAO;GAAE,SAAS;GAAO,WAAW,OAAO;GAAW;EACxD,KAAK,KACH,QAAO;GAAE,SAAS,OAAO;GAAS,QAAQ,OAAO;GAAQ,WAAW,OAAO;GAAW;;;AAI5F,SAAS,2BAA2B,OAAmD;AACrF,KAAI,CAAC,SAAS,OAAO,UAAU,YAAY,MAAM,QAAQ,MAAM,CAC7D,QAAO;AAET,QAAO,aAAa,SAAS,eAAe,SAAS,aAAa"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xopcai/xopc",
3
- "version": "0.0.122",
3
+ "version": "0.0.124",
4
4
  "description": "Local-first AI system that remembers context, coordinates AI, and sustains long-term progress.",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",
@@ -1,2 +0,0 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{t as i}from"./cn-BQ_8x0bT.js";import{t as a}from"./messages-B5O4OIEo.js";import{n as o}from"./locale-store-Ba72bFmP.js";import{i as s}from"./theme-store-Bt6vAkSB.js";import{c,i as l,n as u}from"./fetch-ovkvM8KQ.js";import{i as d}from"./vendor-swr-BIWyz7Rc.js";import{$a as f,$i as p,Ar as m,Ba as h,Bn as g,Bo as _,Ca as v,Ct as y,Ec as b,Fc as x,Fn as S,Gn as C,H as w,Ha as T,Hn as E,Ic as D,In as O,Ja as k,Jn as A,Ka as j,Ln as M,Lr as N,Mi as P,Mn as F,Mr as I,Na as L,Nn as R,Nr as z,Oo as B,Or as ee,Pa as V,Pc as te,Pn as ne,Po as H,Pr as U,Qa as re,Qo as ie,Ra as W,Rn as G,Rs as ae,Sa as K,So as q,St as J,Ta as oe,Ti as se,Tt as ce,Ua as le,Un as ue,Va as de,Wn as fe,Ya as pe,_t as me,aa as he,ai as ge,ba as _e,bc as ve,ci as ye,cs as be,d as xe,di as Se,ea as Ce,fa as Y,fo as we,ga as Te,gc as Ee,gt as De,hc as Oe,ht as ke,ia as Ae,ii as je,jc as Me,jn as Ne,jr as Pe,js as Fe,kr as Ie,ks as Le,li as Re,ls as ze,mo as Be,ms as X,n as Ve,na as He,oa as Ue,oi as We,pt as Ge,qn as Ke,qs as qe,ra as Je,ri as Ye,sa as Xe,si as Ze,t as Qe,ta as $e,u as et,ui as tt,uo as nt,va as rt,vc as it,wa as at,wc as ot,xa as st,ya as ct,yt as lt,zn as ut,zs as dt}from"./index-DdqSO9R2.js";import{t as ft}from"./markdown-editor-AssmZFx4.js";import{n as pt,t as mt}from"./settings-form-section-Dg6LBbcr.js";import{n as ht,t as gt}from"./settings-page-layout-BX4T-OLF.js";import{n as _t}from"./agent-avatar-dicebear-CK3s5cJo.js";import{n as vt,r as yt,t as bt}from"./channel-recipient-api-DdPTtEs8.js";import{n as xt,r as St,t as Ct}from"./utils-D7b_vZnv.js";import{a as wt,i as Tt,n as Et,o as Dt,t as Ot}from"./typed-models-lib-Cx6XV5A2.js";import{a as kt,o as At,r as jt,s as Mt}from"./capability-presets-api-Cx93GLdw.js";import{t as Nt}from"./directory-picker-path-field-D835EHJd.js";var Z=n(),Q=r();function Pt(e){let t=(0,Z.c)(40),{open:n,onOpenChange:r,busy:a,deletePurge:o,deleteTarget:s,deleteConfirmText:c,onDeleteConfirmTextChange:l,onConfirm:u,onCancel:d,a:f}=e,p;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,Q.jsx)(Je,{className:`fixed inset-0 z-[80] bg-scrim backdrop-blur-[2px]`}),t[0]=p):p=t[0];let m;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(m=i(`fixed left-1/2 top-1/2 z-[81] w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2 rounded-xl border border-edge bg-surface-panel p-4 shadow-popover`,`dark:border-edge`),t[1]=m):m=t[1];let g=o?f.purgeDisk:f.removeFromConfig,_;t[2]===g?_=t[3]:(_=(0,Q.jsx)(Ue,{className:`text-base font-semibold text-fg`,children:g}),t[2]=g,t[3]=_);let v=o?f.confirmDeletePurge:f.confirmDelete,y;t[4]===v?y=t[5]:(y=(0,Q.jsx)(He,{className:`mt-2 whitespace-pre-wrap text-sm leading-relaxed text-fg-muted`,children:v}),t[4]=v,t[5]=y);let b;t[6]!==f.purgeConfirmHint||t[7]!==f.purgeConfirmLabel||t[8]!==f.purgeConfirmPlaceholder||t[9]!==c||t[10]!==o||t[11]!==s||t[12]!==l?(b=o&&s?(0,Q.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[(0,Q.jsx)(`label`,{className:`mb-2 block text-sm font-medium text-fg`,htmlFor:`agent-delete-confirm`,children:f.purgeConfirmLabel}),(0,Q.jsx)(`input`,{id:`agent-delete-confirm`,type:`text`,autoComplete:`off`,spellCheck:!1,className:i(`w-full rounded-md border border-edge bg-surface-panel px-3 py-1.5 font-mono text-xs text-fg`,`placeholder:text-fg-subtle`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-panel`,`dark:border-edge`),placeholder:f.purgeConfirmPlaceholder.replace(`{{agentId}}`,s.id),value:c,onChange:e=>l(e.target.value)}),(0,Q.jsx)(`p`,{className:`pt-0.5 text-xs text-fg-muted`,children:f.purgeConfirmHint.replace(`{{agentId}}`,s.id)})]}):null,t[6]=f.purgeConfirmHint,t[7]=f.purgeConfirmLabel,t[8]=f.purgeConfirmPlaceholder,t[9]=c,t[10]=o,t[11]=s,t[12]=l,t[13]=b):b=t[13];let x;t[14]!==f.createModalCancel||t[15]!==a||t[16]!==d?(x=(0,Q.jsx)(h,{type:`button`,variant:`ghost`,disabled:a,onClick:d,children:f.createModalCancel}),t[14]=f.createModalCancel,t[15]=a,t[16]=d,t[17]=x):x=t[17];let S=o?`border-red-200 text-red-700 hover:bg-red-50 dark:border-red-900/60 dark:text-red-300 dark:hover:bg-red-950/40`:void 0,C;t[18]!==a||t[19]!==c||t[20]!==o||t[21]!==s?(C=a||!s||o&&c.trim().toLowerCase()!==s.id.toLowerCase(),t[18]=a,t[19]=c,t[20]=o,t[21]=s,t[22]=C):C=t[22];let w=o?f.purgeDisk:f.removeFromConfig,T;t[23]!==u||t[24]!==C||t[25]!==w||t[26]!==S?(T=(0,Q.jsx)(h,{type:`button`,variant:`secondary`,className:S,disabled:C,onClick:u,children:w}),t[23]=u,t[24]=C,t[25]=w,t[26]=S,t[27]=T):T=t[27];let E;t[28]!==T||t[29]!==x?(E=(0,Q.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center justify-end gap-2 border-t border-edge-subtle/60 pt-3`,children:[x,T]}),t[28]=T,t[29]=x,t[30]=E):E=t[30];let D;t[31]!==E||t[32]!==_||t[33]!==y||t[34]!==b?(D=(0,Q.jsxs)(Ae,{children:[p,(0,Q.jsxs)($e,{className:m,onOpenAutoFocus:Ft,children:[_,y,b,E]})]}),t[31]=E,t[32]=_,t[33]=y,t[34]=b,t[35]=D):D=t[35];let O;return t[36]!==r||t[37]!==n||t[38]!==D?(O=(0,Q.jsx)(he,{open:n,onOpenChange:r,children:D}),t[36]=r,t[37]=n,t[38]=D,t[39]=O):O=t[39],O}function Ft(e){return e.preventDefault()}var It=[{id:`overview`,labelKey:`navOverview`,icon:Le},{id:`behavior`,labelKey:`navBehavior`,icon:we},{id:`tools`,labelKey:`navTools`,icon:le},{id:`skills`,labelKey:`navSkills`,icon:de},{id:`memory`,labelKey:`navMemory`,icon:Ee},{id:`connections`,labelKey:`navConnections`,icon:Oe},{id:`config`,labelKey:`navConfig`,icon:Be},{id:`dangerZone`,labelKey:`navDangerZone`,icon:re}];function Lt(e){let t=(0,Z.c)(11),{a:n,panel:r,onPanelChange:a}=e,o;t[0]!==a||t[1]!==r?(o=(e,t,n)=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>a(e),className:i(`flex w-full items-center gap-2.5 rounded-lg px-3 py-2 text-left text-sm font-medium transition-colors`,V.press,r===e?`bg-accent-soft text-accent-fg`:`text-fg-muted hover:bg-surface-hover hover:text-fg`),children:[(0,Q.jsx)(n,{className:`size-4 shrink-0 opacity-90`,strokeWidth:2,"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate`,children:t})]},e),t[0]=a,t[1]=r,t[2]=o):o=t[2];let s=o,c=n.editorNavAria,l;t[3]!==n||t[4]!==s?(l=It.map(e=>{let{id:t,labelKey:r,icon:i}=e;return s(t,n[r],i)}),t[3]=n,t[4]=s,t[5]=l):l=t[5];let u;t[6]===l?u=t[7]:(u=(0,Q.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:l}),t[6]=l,t[7]=u);let d;return t[8]!==n.editorNavAria||t[9]!==u?(d=(0,Q.jsx)(`nav`,{className:`flex w-full flex-col gap-1`,"aria-label":c,children:u}),t[8]=n.editorNavAria,t[9]=u,t[10]=d):d=t[10],d}function Rt(e){let t=(0,Z.c)(44),{open:n,onOpenChange:r,a,title:o,subtitle:s,panel:c,onPanelChange:l,onFooterSave:u,footerSaveDisabled:d,footerSavedFlash:f,showFooter:p,busy:m,children:g}=e,_=p===void 0?!0:p,v;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,Q.jsx)(Je,{className:i(`xopc-dialog-overlay fixed inset-0 bg-scrim`,_e)}),t[0]=v):v=t[0];let y;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(y=i(`xopc-dialog-content fixed flex flex-col overflow-hidden rounded-xl border border-edge bg-surface-panel shadow-popover dark:border-edge`,ct,`inset-4 h-[calc(100dvh-2rem)] max-h-[calc(100dvh-2rem)] min-h-0`,`sm:inset-auto sm:left-1/2 sm:top-1/2 sm:h-[min(88vh,48rem)] sm:max-h-[min(88vh,48rem)] sm:min-h-[32rem] sm:w-[min(100%-2rem,58rem)] sm:-translate-x-1/2 sm:-translate-y-1/2`),t[1]=y):y=t[1];let b;t[2]===o?b=t[3]:(b=(0,Q.jsx)(Ue,{className:`text-base font-semibold leading-snug text-fg`,children:o}),t[2]=o,t[3]=b);let x;t[4]===s?x=t[5]:(x=(0,Q.jsx)(He,{className:`mt-1 font-mono text-xs text-fg-muted`,children:s}),t[4]=s,t[5]=x);let S;t[6]!==b||t[7]!==x?(S=(0,Q.jsxs)(`div`,{className:`min-w-0 pr-2`,children:[b,x]}),t[6]=b,t[7]=x,t[8]=S):S=t[8];let C;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(C=i(L,`shrink-0 p-1.5 hover:bg-surface-base`),t[9]=C):C=t[9];let w;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,Q.jsx)(T,{className:`size-4`,"aria-hidden":!0}),t[10]=w):w=t[10];let E;t[11]===a.closeDialogAria?E=t[12]:(E=(0,Q.jsx)(Ce,{asChild:!0,children:(0,Q.jsx)(`button`,{type:`button`,className:C,"aria-label":a.closeDialogAria,children:w})}),t[11]=a.closeDialogAria,t[12]=E);let D;t[13]!==S||t[14]!==E?(D=(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-edge-subtle px-4 pb-3 pt-4 dark:border-edge`,children:[S,E]}),t[13]=S,t[14]=E,t[15]=D):D=t[15];let O;t[16]!==a||t[17]!==l||t[18]!==c?(O=(0,Q.jsx)(`div`,{className:`shrink-0 border-b border-edge-subtle px-4 py-3 dark:border-edge sm:flex sm:w-56 sm:shrink-0 sm:flex-col sm:overflow-y-auto sm:border-b-0 sm:border-r sm:px-0 sm:py-4 sm:pl-4 sm:pr-3`,children:(0,Q.jsx)(Lt,{a,panel:c,onPanelChange:l})}),t[16]=a,t[17]=l,t[18]=c,t[19]=O):O=t[19];let k;t[20]===g?k=t[21]:(k=(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden p-4 sm:pl-2 sm:pr-5`,children:g}),t[20]=g,t[21]=k);let A;t[22]!==a.footerSaveNotApplicable||t[23]!==a.personaSaved||t[24]!==a.save||t[25]!==m||t[26]!==d||t[27]!==f||t[28]!==u||t[29]!==_?(A=_?(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-1 border-t border-edge-subtle px-4 py-3 dark:border-edge sm:flex-row sm:items-center sm:justify-end sm:gap-3`,children:[f?(0,Q.jsxs)(`p`,{className:`order-2 text-center text-xs font-medium text-green-600 sm:order-1 sm:mr-auto sm:text-left dark:text-green-400`,children:[`✓ `,a.personaSaved]}):d?(0,Q.jsx)(`p`,{className:`order-2 text-center text-xs text-fg-muted sm:order-1 sm:mr-auto sm:text-left`,children:a.footerSaveNotApplicable}):null,(0,Q.jsx)(h,{type:`button`,className:`order-1 w-full sm:order-2 sm:w-auto`,disabled:m||d,onClick:()=>void u(),children:a.save})]}):null,t[22]=a.footerSaveNotApplicable,t[23]=a.personaSaved,t[24]=a.save,t[25]=m,t[26]=d,t[27]=f,t[28]=u,t[29]=_,t[30]=A):A=t[30];let j;t[31]!==k||t[32]!==A?(j=(0,Q.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[k,A]}),t[31]=k,t[32]=A,t[33]=j):j=t[33];let M;t[34]!==O||t[35]!==j?(M=(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col sm:flex-row sm:overflow-hidden`,children:[O,j]}),t[34]=O,t[35]=j,t[36]=M):M=t[36];let N;t[37]!==M||t[38]!==D?(N=(0,Q.jsxs)(Ae,{children:[v,(0,Q.jsx)($e,{className:y,onOpenAutoFocus:zt,children:(0,Q.jsxs)(ke,{layer:`modal`,children:[D,M]})})]}),t[37]=M,t[38]=D,t[39]=N):N=t[39];let P;return t[40]!==r||t[41]!==n||t[42]!==N?(P=(0,Q.jsx)(he,{open:n,onOpenChange:r,children:N}),t[40]=r,t[41]=n,t[42]=N,t[43]=P):P=t[43],P}function zt(e){return e.preventDefault()}var $=e(t(),1),Bt=e=>u(e);function Vt(e){return!e||e.total<=0?null:Math.round(e.helpful/e.total*100)}function Ht(e){let t=Vt(e);return t==null?`border-edge bg-surface-panel text-fg-muted`:t>=70?`border-success/30 bg-success-soft text-fg`:t>=40?`border-warning/40 bg-warning-soft text-fg`:`border-danger/30 bg-danger-soft text-fg`}function Ut({embedded:e=!1,agentId:t}){let n=a(o(e=>e.language)).agentsSettings.memoryPanel,[r,i]=(0,$.useState)(``),[s,c]=(0,$.useState)(``),[f,p]=(0,$.useState)(``),[m,g]=(0,$.useState)({}),[_,v]=(0,$.useState)({searchStrategy:`fanout`,writeStrategy:`local-first`,allowExternalWrites:!1,allowedProviderIds:[],autoWriteKinds:[]}),{data:y}=d(l(`/api/memory/providers`),Bt),{data:b,mutate:x}=d(l(`/api/memory/records?status=active&limit=80`),Bt),{data:S,mutate:C}=d(l(`/api/memory/records?status=candidate&limit=80`),Bt),{data:w}=d(l(`/api/memory/signals?limit=50`),Bt),{data:T,mutate:E}=d(l(`/api/memory/traces?limit=80`),Bt),{data:D}=d(l(`/api/memory/feedback-summary?limit=1000`),Bt),{data:O,mutate:k}=d(l(`/api/memory/config${t?`?agentId=${encodeURIComponent(t)}`:``}`),Bt),{data:A,isLoading:j}=d(s?l(`/api/memory/search`):null,e=>u(e,{method:`POST`,body:JSON.stringify({query:s,maxResults:20})})),M=A?.results.map(e=>({...e.record,score:e.score}))??b?.records??[],N=y?.providers.length??0,P=b?.records.length??0,F=S?.records.length??0,I=w?.signals.length??0,L=T?.traces.length??0,R=D?.summaries??[],z=(0,$.useMemo)(()=>new Map(R.map(e=>[e.recordId,e])),[R]),B=R.reduce((e,t)=>e+t.total,0),ee=R.reduce((e,t)=>e+t.helpful,0),V=B>0?Math.round(ee/B*100):null,te=(0,$.useMemo)(()=>[{label:n.providers,value:N},{label:n.records,value:P},{label:n.inbox,value:F},{label:n.signals,value:I},{label:n.traceEvents,value:L},{label:n.recallQuality,value:V==null?`—`:`${V}%`}],[F,V,N,P,I,n.inbox,n.providers,n.recallQuality,n.records,n.signals,n.traceEvents,L]);(0,$.useEffect)(()=>{let e=O?.memory.providerRouting;e&&v({searchStrategy:e.searchStrategy??`fanout`,writeStrategy:e.writeStrategy??`local-first`,allowExternalWrites:e.allowExternalWrites??!1,allowedProviderIds:e.allowedProviderIds??[],autoWriteKinds:e.autoWriteKinds??[]})},[O]);async function ne(){if(O){p(n.saving);try{await u(l(`/api/memory/config`),{method:`PATCH`,body:JSON.stringify({agentId:O.agentId,memory:{...O.memory,providerRouting:_}})}),await k(),p(n.saved)}catch(e){p(e instanceof Error?e.message:n.saveFailed)}}}async function H(e){g(t=>({...t,[e]:n.testing}));try{let t=(await u(l(`/api/memory/providers/${encodeURIComponent(e)}/test`),{method:`POST`})).checks.find(e=>!e.ok);g(r=>({...r,[e]:t?`${t.name}: ${t.message??n.checkFailed}`:n.testPassed})),E()}catch(t){g(r=>({...r,[e]:t instanceof Error?t.message:n.testFailed}))}}async function U(e,t){await u(l(`/api/memory/records/${encodeURIComponent(e)}`),{method:`PATCH`,body:JSON.stringify({status:t})}),await Promise.all([C(),x()])}return(0,Q.jsxs)(`div`,{className:e?`flex min-h-0 w-full flex-1 flex-col gap-5 overflow-y-auto overscroll-contain pr-1`:`flex w-full flex-1 flex-col gap-5 px-3 py-6 sm:px-5 xl:px-6`,children:[e?null:(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h1`,{className:`text-xl font-semibold text-fg`,children:n.title}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle})]}),(0,Q.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-6`,children:te.map(e=>(0,Q.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface px-4 py-3`,children:[(0,Q.jsx)(`div`,{className:`text-xs text-fg-muted`,children:e.label}),(0,Q.jsx)(`div`,{className:`mt-1 text-2xl font-semibold text-fg`,children:e.value})]},e.label))}),(0,Q.jsxs)(`section`,{className:`rounded-lg border border-edge bg-surface`,children:[(0,Q.jsx)(`div`,{className:`border-b border-edge px-4 py-3 text-sm font-semibold text-fg`,children:n.providerPolicy}),(0,Q.jsxs)(`div`,{className:`grid gap-3 p-4 md:grid-cols-2`,children:[(0,Q.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[n.searchStrategy,(0,Q.jsx)(Te,{className:`mt-1 min-h-10 w-full rounded-md border border-edge bg-surface-panel px-3 text-sm text-fg`,value:_.searchStrategy,onChange:e=>v(t=>({...t,searchStrategy:e.target.value})),children:[`fanout`,`local-first`,`external-first`,`local-only`,`external-only`].map(e=>(0,Q.jsx)(rt,{value:e,children:e},e))})]}),(0,Q.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[n.writeStrategy,(0,Q.jsx)(Te,{className:`mt-1 min-h-10 w-full rounded-md border border-edge bg-surface-panel px-3 text-sm text-fg`,value:_.writeStrategy,onChange:e=>v(t=>({...t,writeStrategy:e.target.value})),children:[`local-first`,`write-through`,`external-first`,`local-only`,`external-only`].map(e=>(0,Q.jsx)(rt,{value:e,children:e},e))})]}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-fg md:col-span-2`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:_.allowExternalWrites,onChange:e=>v(t=>({...t,allowExternalWrites:e.target.checked}))}),n.allowExternalWrites]}),(0,Q.jsxs)(`div`,{className:`md:col-span-2`,children:[(0,Q.jsx)(`div`,{className:`mb-2 text-xs font-medium text-fg-muted`,children:n.writableProviders}),(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:(y?.providers??[]).filter(e=>!e.capabilities.local).map(e=>(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 rounded-md border border-edge px-3 py-2 text-sm text-fg`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:_.allowedProviderIds?.includes(e.id)??!1,onChange:t=>v(n=>({...n,allowedProviderIds:t.target.checked?[...n.allowedProviderIds??[],e.id]:(n.allowedProviderIds??[]).filter(t=>t!==e.id)}))}),e.displayName]},e.id))})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 md:col-span-2`,children:[(0,Q.jsx)(h,{type:`button`,variant:`primary`,onClick:ne,children:n.savePolicy}),f?(0,Q.jsx)(`span`,{className:`text-sm text-fg-muted`,children:f}):null]})]})]}),(0,Q.jsxs)(`section`,{className:`rounded-lg border border-edge bg-surface`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-edge px-4 py-3`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:n.inbox}),(0,Q.jsx)(`div`,{className:`mt-0.5 text-xs text-fg-muted`,children:n.inboxHint})]}),(0,Q.jsx)(`div`,{className:`text-xs text-fg-muted`,children:F})]}),(0,Q.jsxs)(`div`,{className:`divide-y divide-edge`,children:[(S?.records??[]).map(e=>(0,Q.jsxs)(`article`,{className:`px-4 py-3`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-xs text-fg-muted`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-fg`,children:e.kind}),(0,Q.jsx)(`span`,{children:e.sensitivity??`normal`}),(0,Q.jsx)(`span`,{children:e.source.provider??`local`}),e.confidence==null?null:(0,Q.jsxs)(`span`,{children:[Math.round(e.confidence*100),`%`]})]}),(0,Q.jsx)(`p`,{className:`mt-2 whitespace-pre-wrap text-sm leading-6 text-fg`,children:e.content}),e.evidence?.[0]?.sourceText?(0,Q.jsx)(`p`,{className:`mt-2 line-clamp-2 text-xs leading-5 text-fg-muted`,children:e.evidence[0].sourceText}):null,(0,Q.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(h,{type:`button`,variant:`primary`,onClick:()=>U(e.id,`active`),children:n.approve}),(0,Q.jsx)(h,{type:`button`,variant:`secondary`,onClick:()=>U(e.id,`rejected`),children:n.reject}),(0,Q.jsx)(h,{type:`button`,variant:`secondary`,onClick:()=>U(e.id,`needs_review`),children:n.needsReview})]})]},e.id)),F===0?(0,Q.jsx)(`div`,{className:`px-4 py-8 text-sm text-fg-muted`,children:n.noInbox}):null]})]}),(0,Q.jsxs)(`form`,{className:`flex gap-2`,onSubmit:e=>{e.preventDefault(),c(r.trim())},children:[(0,Q.jsx)(`input`,{className:`min-h-10 flex-1 rounded-md border border-edge bg-surface px-3 text-sm text-fg outline-none focus:border-accent`,value:r,onChange:e=>i(e.target.value),placeholder:n.searchPlaceholder}),(0,Q.jsx)(h,{className:`min-h-10 rounded-md px-4`,type:`submit`,variant:`primary`,children:n.search})]}),(0,Q.jsxs)(`section`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_20rem]`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 rounded-lg border border-edge bg-surface`,children:[(0,Q.jsx)(`div`,{className:`border-b border-edge px-4 py-3 text-sm font-semibold text-fg`,children:s?`${n.searchResults}${j?`…`:``}`:n.recentRecords}),(0,Q.jsxs)(`div`,{className:`divide-y divide-edge`,children:[M.map(e=>{let t=z.get(e.id),r=Vt(t);return(0,Q.jsxs)(`article`,{className:`px-4 py-3`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-xs text-fg-muted`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-fg`,children:e.kind}),e.status?(0,Q.jsx)(`span`,{children:e.status}):null,e.sensitivity?(0,Q.jsx)(`span`,{children:e.sensitivity}):null,(0,Q.jsx)(`span`,{children:e.source.provider??`local`}),e.source.path?(0,Q.jsx)(`span`,{children:e.source.path}):null,(0,Q.jsx)(`span`,{className:`rounded-full border px-2 py-0.5 ${Ht(t)}`,children:r==null?n.noRecallFeedback:`${n.recallQuality} ${r}% · ${t?.total??0}`})]}),(0,Q.jsx)(`p`,{className:`mt-2 whitespace-pre-wrap text-sm leading-6 text-fg`,children:e.content}),t?(0,Q.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-2 text-xs text-fg-muted`,children:[(0,Q.jsxs)(`span`,{children:[n.helpful,`: `,t.helpful]}),(0,Q.jsxs)(`span`,{children:[n.notHelpful,`: `,t.notHelpful]}),t.mixed?(0,Q.jsxs)(`span`,{children:[n.mixed,`: `,t.mixed]}):null,t.irrelevant?(0,Q.jsxs)(`span`,{children:[n.irrelevant,`: `,t.irrelevant]}):null]}):null]},e.id)}),M.length===0?(0,Q.jsx)(`div`,{className:`px-4 py-8 text-sm text-fg-muted`,children:n.noRecords}):null]})]}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface`,children:[(0,Q.jsx)(`div`,{className:`border-b border-edge px-4 py-3 text-sm font-semibold text-fg`,children:n.providers}),(0,Q.jsx)(`div`,{className:`divide-y divide-edge`,children:(y?.providers??[]).map(e=>(0,Q.jsxs)(`div`,{className:`px-4 py-3`,children:[(0,Q.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.displayName}),(0,Q.jsxs)(`div`,{className:`mt-1 text-xs text-fg-muted`,children:[e.id,` · `,e.available?n.available:n.unavailable]}),(0,Q.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[(0,Q.jsx)(h,{type:`button`,variant:`secondary`,onClick:()=>H(e.id),children:n.test}),m[e.id]?(0,Q.jsx)(`span`,{className:`text-xs text-fg-muted`,children:m[e.id]}):null]})]},e.id))})]}),(0,Q.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface`,children:[(0,Q.jsx)(`div`,{className:`border-b border-edge px-4 py-3 text-sm font-semibold text-fg`,children:n.recallQuality}),(0,Q.jsxs)(`div`,{className:`divide-y divide-edge`,children:[R.slice(0,8).map(e=>{let t=(b?.records??[]).find(t=>t.id===e.recordId),r=Vt(e);return(0,Q.jsxs)(`div`,{className:`px-4 py-3 text-xs text-fg-muted`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Q.jsx)(`div`,{className:`min-w-0 font-medium text-fg`,children:t?.kind??n.record}),(0,Q.jsxs)(`span`,{className:`shrink-0 rounded-full border px-2 py-0.5 ${Ht(e)}`,children:[r??0,`%`]})]}),(0,Q.jsx)(`div`,{className:`mt-1 line-clamp-2 text-fg-muted`,children:t?.content??e.recordId}),(0,Q.jsxs)(`div`,{className:`mt-2`,children:[e.helpful,` `,n.helpful,` · `,e.notHelpful,` `,n.notHelpful,` · `,e.total,` `,n.feedback]})]},e.recordId)}),R.length===0?(0,Q.jsx)(`div`,{className:`px-4 py-8 text-sm text-fg-muted`,children:n.noRecallFeedback}):null]})]}),(0,Q.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface`,children:[(0,Q.jsx)(`div`,{className:`border-b border-edge px-4 py-3 text-sm font-semibold text-fg`,children:n.signals}),(0,Q.jsx)(`div`,{className:`divide-y divide-edge`,children:(w?.signals??[]).map(e=>(0,Q.jsxs)(`div`,{className:`px-4 py-3 text-xs text-fg-muted`,children:[(0,Q.jsx)(`div`,{className:`font-medium text-fg`,children:e.source}),(0,Q.jsxs)(`div`,{children:[e.providerId??`local`,` · `,new Date(e.createdAt).toLocaleString()]})]},e.signalId))})]}),(0,Q.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface`,children:[(0,Q.jsx)(`div`,{className:`border-b border-edge px-4 py-3 text-sm font-semibold text-fg`,children:n.trace}),(0,Q.jsx)(`div`,{className:`divide-y divide-edge`,children:(T?.traces??[]).slice(0,20).map(e=>(0,Q.jsxs)(`div`,{className:`px-4 py-3 text-xs text-fg-muted`,children:[(0,Q.jsxs)(`div`,{className:`font-medium text-fg`,children:[e.phase,` · `,e.providerId]}),(0,Q.jsxs)(`div`,{children:[e.resultCount??0,` `,(e.resultCount??0)===1?n.result:n.results,` · `,e.durationMs,` ms`]}),e.skippedReason?(0,Q.jsxs)(`div`,{children:[n.skipped,`: `,e.skippedReason]}):null,e.error?(0,Q.jsx)(`div`,{className:`text-danger`,children:e.error}):null]},e.traceId))})]})]})]})]})}function Wt(e){let t=(0,Z.c)(28),{label:n,mode:r,value:a,inheritedFrom:o,inheritLabel:s,overrideLabel:c,onClick:l}=e,u;t[0]===n?u=t[1]:(u=(0,Q.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:n}),t[0]=n,t[1]=u);let d=a||`—`,f;t[2]===d?f=t[3]:(f=(0,Q.jsx)(`p`,{className:`mt-1 truncate text-sm font-medium text-fg`,children:d}),t[2]=d,t[3]=f);let p;t[4]!==o||t[5]!==r?(p=r===`inherit`&&o?(0,Q.jsx)(`p`,{className:`mt-0.5 truncate text-xs text-fg-muted`,children:o}):null,t[4]=o,t[5]=r,t[6]=p):p=t[6];let m;t[7]!==u||t[8]!==f||t[9]!==p?(m=(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[u,f,p]}),t[7]=u,t[8]=f,t[9]=p,t[10]=m):m=t[10];let h=r===`inherit`?`bg-surface-hover text-fg-muted`:`bg-accent-soft text-accent-fg`,g;t[11]===h?g=t[12]:(g=i(`mt-2 inline-flex shrink-0 self-start rounded-full px-2.5 py-0.5 text-xs font-medium sm:mt-0`,h),t[11]=h,t[12]=g);let _=r===`inherit`?s:c,v;t[13]!==g||t[14]!==_?(v=(0,Q.jsx)(`span`,{className:g,children:_}),t[13]=g,t[14]=_,t[15]=v):v=t[15];let y;t[16]!==m||t[17]!==v?(y=(0,Q.jsxs)(Q.Fragment,{children:[m,v]}),t[16]=m,t[17]=v,t[18]=y):y=t[18];let b=y,x=l?`w-full text-left transition-colors hover:border-edge hover:bg-surface-hover/45 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 active:scale-[0.995] motion-reduce:active:scale-100`:void 0,S;t[19]===x?S=t[20]:(S=i(`flex flex-col gap-1 rounded-xl border border-edge-subtle bg-surface-panel px-4 py-3 sm:flex-row sm:items-center sm:justify-between`,x),t[19]=x,t[20]=S);let C=S;if(l){let e;return t[21]!==C||t[22]!==b||t[23]!==l?(e=(0,Q.jsx)(`button`,{type:`button`,className:C,onClick:l,children:b}),t[21]=C,t[22]=b,t[23]=l,t[24]=e):e=t[24],e}let w;return t[25]!==C||t[26]!==b?(w=(0,Q.jsx)(`div`,{className:C,children:b}),t[25]=C,t[26]=b,t[27]=w):w=t[27],w}function Gt(e){let t=(0,Z.c)(38),{a:n,defaultModel:r,defaultWorkspace:i,agentModel:a,agentWorkspace:o,onEditModelStrategy:s,onEditWorkspace:c}=e,l=n.inheritance,u;t[0]===a?u=t[1]:(u=a.trim(),t[0]=a,t[1]=u);let d=!u,f;t[2]!==o||t[3]!==i?(f=!o.trim()||i.trim().length>0&&o.trim()===i.trim(),t[2]=o,t[3]=i,t[4]=f):f=t[4];let p=f,m=d?r||l.unset:a,h=p?i||l.unset:o,g;t[5]!==l.subtitle||t[6]!==l.title?(g=(0,Q.jsx)(pt,{icon:ze,title:l.title,subtitle:l.subtitle}),t[5]=l.subtitle,t[6]=l.title,t[7]=g):g=t[7];let _=d?`inherit`:`override`,v;t[8]!==r||t[9]!==l.inheritsValue||t[10]!==d?(v=d&&r?l.inheritsValue.replace(`{{value}}`,r):void 0,t[8]=r,t[9]=l.inheritsValue,t[10]=d,t[11]=v):v=t[11];let y;t[12]!==m||t[13]!==l.badgeInherit||t[14]!==l.badgeOverride||t[15]!==l.modelLabel||t[16]!==s||t[17]!==_||t[18]!==v?(y=(0,Q.jsx)(Wt,{label:l.modelLabel,mode:_,value:m,inheritedFrom:v,inheritLabel:l.badgeInherit,overrideLabel:l.badgeOverride,onClick:s}),t[12]=m,t[13]=l.badgeInherit,t[14]=l.badgeOverride,t[15]=l.modelLabel,t[16]=s,t[17]=_,t[18]=v,t[19]=y):y=t[19];let b=p?`inherit`:`override`,x;t[20]!==i||t[21]!==l.inheritsValue||t[22]!==p?(x=p&&i?l.inheritsValue.replace(`{{value}}`,i):void 0,t[20]=i,t[21]=l.inheritsValue,t[22]=p,t[23]=x):x=t[23];let S;t[24]!==h||t[25]!==l.badgeInherit||t[26]!==l.badgeOverride||t[27]!==l.workspaceLabel||t[28]!==c||t[29]!==b||t[30]!==x?(S=(0,Q.jsx)(Wt,{label:l.workspaceLabel,mode:b,value:h,inheritedFrom:x,inheritLabel:l.badgeInherit,overrideLabel:l.badgeOverride,onClick:c}),t[24]=h,t[25]=l.badgeInherit,t[26]=l.badgeOverride,t[27]=l.workspaceLabel,t[28]=c,t[29]=b,t[30]=x,t[31]=S):S=t[31];let C;t[32]!==y||t[33]!==S?(C=(0,Q.jsxs)(`div`,{className:`mt-4 grid gap-3 sm:grid-cols-2`,children:[y,S]}),t[32]=y,t[33]=S,t[34]=C):C=t[34];let w;return t[35]!==g||t[36]!==C?(w=(0,Q.jsxs)(mt,{children:[g,C]}),t[35]=g,t[36]=C,t[37]=w):w=t[37],w}function Kt(e,t){for(let n of t){let t=e[n];if(t)return t}return`default`}function qt(e){let t=(0,Z.c)(5),{source:n}=e,r;if(t[0]!==n){let e=n.startsWith(`preset:`),a=n.startsWith(`agent:`);r=i(`shrink-0 rounded-full border px-2 py-0.5 text-[11px] font-medium`,e&&`border-accent/25 bg-accent/10 text-accent`,a&&`border-edge bg-surface-base text-fg-muted`,!e&&!a&&`border-edge-subtle bg-surface-panel text-fg-subtle`),t[0]=n,t[1]=r}else r=t[1];let a;return t[2]!==n||t[3]!==r?(a=(0,Q.jsx)(`span`,{className:r,children:n}),t[2]=n,t[3]=r,t[4]=a):a=t[4],a}function Jt(e){let t=(0,Z.c)(13),n;t[0]===e.name?n=t[1]:(n=(0,Q.jsx)(`div`,{className:`min-w-0 truncate font-mono text-xs font-medium text-fg`,children:e.name}),t[0]=e.name,t[1]=n);let r=e.monoValue&&`font-mono text-xs`,a;t[2]===r?a=t[3]:(a=i(`min-w-0 truncate text-sm text-fg`,r),t[2]=r,t[3]=a);let o;t[4]!==e.value||t[5]!==a?(o=(0,Q.jsx)(`div`,{className:a,children:e.value}),t[4]=e.value,t[5]=a,t[6]=o):o=t[6];let s;t[7]===e.source?s=t[8]:(s=(0,Q.jsx)(qt,{source:e.source}),t[7]=e.source,t[8]=s);let c;return t[9]!==n||t[10]!==o||t[11]!==s?(c=(0,Q.jsxs)(`div`,{className:`grid gap-2 rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2 sm:grid-cols-[minmax(0,10rem)_minmax(0,1fr)_auto] sm:items-center`,children:[n,o,s]}),t[9]=n,t[10]=o,t[11]=s,t[12]=c):c=t[12],c}function Yt(e,t){return e&&e.length>0?e.join(`, `):t}function Xt(e){let t=(0,Z.c)(30),{a:n,selected:r}=e,i;t[0]===r.id?i=t[1]:(i=r.id?[`agent-effective-manifest`,r.id]:null,t[0]=r.id,t[1]=i);let a;t[2]===r.id?a=t[3]:(a=()=>G(r.id),t[2]=r.id,t[3]=a);let o;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(o={revalidateOnFocus:!1},t[4]=o):o=t[4];let{data:s,error:c,isLoading:l}=d(i,a,o),u=s?.manifest,f;t[5]!==s?.presetChain||t[6]!==u?.extends?(f=s?.presetChain??u?.extends??[],t[5]=s?.presetChain,t[6]=u?.extends,t[7]=f):f=t[7];let p=f,m;if(t[8]!==n.effectiveBoundariesTitle||t[9]!==n.effectiveEmpty||t[10]!==n.effectiveError||t[11]!==n.effectiveHint||t[12]!==n.effectiveLoading||t[13]!==n.effectiveMemoryTitle||t[14]!==n.effectiveModelsTitle||t[15]!==n.effectiveNoPresets||t[16]!==n.effectiveNoToolPolicies||t[17]!==n.effectivePresetChain||t[18]!==n.effectiveSkillsTitle||t[19]!==n.effectiveTitle||t[20]!==n.effectiveToolsTitle||t[21]!==s?.sources||t[22]!==c||t[23]!==l||t[24]!==u||t[25]!==p){let e=s?.sources??{},r=Object.entries(u?.models?.roles??{}).sort(Qt),i=Object.entries(u?.tools?.builtin??{}).sort(Zt),a=u?.skills,o=u?.memory,d=u?.boundaries,f;t[27]!==n.effectiveHint||t[28]!==n.effectiveTitle?(f=(0,Q.jsx)(pt,{icon:be,title:n.effectiveTitle,subtitle:n.effectiveHint}),t[27]=n.effectiveHint,t[28]=n.effectiveTitle,t[29]=f):f=t[29],m=(0,Q.jsxs)(mt,{children:[f,l?(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.effectiveLoading}):c?(0,Q.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:c instanceof Error?c.message:n.effectiveError}):u?(0,Q.jsx)(`div`,{children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-fg-muted`,children:n.effectivePresetChain}),(0,Q.jsx)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2 text-sm text-fg`,children:p.length?p.join(` -> `):n.effectiveNoPresets})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-fg-muted`,children:n.effectiveModelsTitle}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(Jt,{name:`defaultRole`,value:u.models?.defaultRole??`—`,source:Kt(e,[`models.defaultRole`])}),r.map(t=>{let[n,r]=t;return(0,Q.jsx)(Jt,{name:n,value:r.model,monoValue:!0,source:Kt(e,[`models.roles.${n}.model`,`models.roles.${n}`])},n)})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-fg-muted`,children:n.effectiveToolsTitle}),i.length>0?(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:i.map(t=>{let[n,r]=t;return(0,Q.jsx)(Jt,{name:n,value:r.mode,source:Kt(e,[`tools.builtin.${n}.mode`,`tools.builtin.${n}`])},n)})}):(0,Q.jsx)(`p`,{className:`rounded-lg border border-dashed border-edge-subtle px-3 py-2 text-sm text-fg-muted`,children:n.effectiveNoToolPolicies})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-fg-muted`,children:n.effectiveSkillsTitle}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(Jt,{name:`mode`,value:a?.mode??`all`,source:Kt(e,[`skills.mode`,`skills`])}),a?.mode===`allowlist`?(0,Q.jsx)(Jt,{name:`allow`,value:Yt(a.allow,`—`),source:Kt(e,[`skills.allow`,`skills`])}):null,a?.mode===`denylist`?(0,Q.jsx)(Jt,{name:`deny`,value:Yt(a.deny,`—`),source:Kt(e,[`skills.deny`,`skills`])}):null]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-fg-muted`,children:n.effectiveMemoryTitle}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(Jt,{name:`mode`,value:o?.mode??`off`,source:Kt(e,[`memory.mode`,`memory`])}),(0,Q.jsx)(Jt,{name:`sources`,value:Yt(o?.sources,`—`),source:Kt(e,[`memory.sources`,`memory`])})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-fg-muted`,children:n.effectiveBoundariesTitle}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(Jt,{name:`requiresConfirmation`,value:Yt(d?.requiresConfirmation,`—`),source:Kt(e,[`boundaries.requiresConfirmation`,`boundaries`])}),(0,Q.jsx)(Jt,{name:`forbidden`,value:Yt(d?.forbidden,`—`),source:Kt(e,[`boundaries.forbidden`,`boundaries`])}),(0,Q.jsx)(Jt,{name:`escalation`,value:Yt(d?.escalation,`—`),source:Kt(e,[`boundaries.escalation`,`boundaries`])})]})]})]})}):(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.effectiveEmpty})]}),t[8]=n.effectiveBoundariesTitle,t[9]=n.effectiveEmpty,t[10]=n.effectiveError,t[11]=n.effectiveHint,t[12]=n.effectiveLoading,t[13]=n.effectiveMemoryTitle,t[14]=n.effectiveModelsTitle,t[15]=n.effectiveNoPresets,t[16]=n.effectiveNoToolPolicies,t[17]=n.effectivePresetChain,t[18]=n.effectiveSkillsTitle,t[19]=n.effectiveTitle,t[20]=n.effectiveToolsTitle,t[21]=s?.sources,t[22]=c,t[23]=l,t[24]=u,t[25]=p,t[26]=m}else m=t[26];return m}function Zt(e,t){let[n]=e,[r]=t;return n.localeCompare(r)}function Qt(e,t){let[n]=e,[r]=t;return n.localeCompare(r)}function $t(e){let t=(0,Z.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain pr-1`,children:(0,Q.jsx)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-5 pb-6`,children:n})}),t[0]=n,t[1]=r),r}function en(e){let t=(0,Z.c)(4),{active:n,children:r,onClick:i}=e,a=n?`rounded-md bg-accent-soft px-3 py-1.5 text-sm font-medium text-accent-fg`:`rounded-md px-3 py-1.5 text-sm font-medium text-fg-muted hover:bg-surface-hover hover:text-fg`,o;return t[0]!==r||t[1]!==i||t[2]!==a?(o=(0,Q.jsx)(`button`,{type:`button`,onClick:i,className:a,children:r}),t[0]=r,t[1]=i,t[2]=a,t[3]=o):o=t[3],o}function tn(e){let t=(0,Z.c)(41),{a:n,selected:r,busy:i,defaultModel:a,defaultWorkspace:o,agentModel:s,agentWorkspace:c,capabilityPresets:l,defaultPresetId:u,onUpdateAgentExtends:d,onOpenCapabilityPreset:f}=e,[p,m]=(0,$.useState)(`sources`),h=p===`sources`,g;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>m(`sources`),t[0]=g):g=t[0];let _;t[1]!==n.configSubtabSources||t[2]!==h?(_=(0,Q.jsx)(en,{active:h,onClick:g,children:n.configSubtabSources}),t[1]=n.configSubtabSources,t[2]=h,t[3]=_):_=t[3];let v=p===`shared`,y;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(y=()=>m(`shared`),t[4]=y):y=t[4];let b;t[5]!==n.configSubtabShared||t[6]!==v?(b=(0,Q.jsx)(en,{active:v,onClick:y,children:n.configSubtabShared}),t[5]=n.configSubtabShared,t[6]=v,t[7]=b):b=t[7];let x=p===`effective`,S;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(S=()=>m(`effective`),t[8]=S):S=t[8];let C;t[9]!==n.configSubtabEffective||t[10]!==x?(C=(0,Q.jsx)(en,{active:x,onClick:S,children:n.configSubtabEffective}),t[9]=n.configSubtabEffective,t[10]=x,t[11]=C):C=t[11];let w;t[12]!==_||t[13]!==b||t[14]!==C?(w=(0,Q.jsx)(`div`,{className:`shrink-0 rounded-lg border border-edge bg-surface-panel p-1`,children:(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[_,b,C]})}),t[12]=_,t[13]=b,t[14]=C,t[15]=w):w=t[15];let T;t[16]!==n||t[17]!==s||t[18]!==c||t[19]!==a||t[20]!==o||t[21]!==p?(T=p===`sources`?(0,Q.jsx)(nn,{a:n,defaultModel:a,defaultWorkspace:o,agentModel:s,agentWorkspace:c}):null,t[16]=n,t[17]=s,t[18]=c,t[19]=a,t[20]=o,t[21]=p,t[22]=T):T=t[22];let E;t[23]!==n||t[24]!==i||t[25]!==l||t[26]!==u||t[27]!==f||t[28]!==d||t[29]!==r||t[30]!==p?(E=p===`shared`?(0,Q.jsx)(rn,{a:n,selected:r,busy:i,capabilityPresets:l,defaultPresetId:u,onUpdateAgentExtends:d,onOpenCapabilityPreset:f}):null,t[23]=n,t[24]=i,t[25]=l,t[26]=u,t[27]=f,t[28]=d,t[29]=r,t[30]=p,t[31]=E):E=t[31];let D;t[32]!==n||t[33]!==r||t[34]!==p?(D=p===`effective`?(0,Q.jsx)(sn,{a:n,selected:r}):null,t[32]=n,t[33]=r,t[34]=p,t[35]=D):D=t[35];let O;return t[36]!==w||t[37]!==T||t[38]!==E||t[39]!==D?(O=(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-hidden`,children:[w,T,E,D]}),t[36]=w,t[37]=T,t[38]=E,t[39]=D,t[40]=O):O=t[40],O}function nn(e){let t=(0,Z.c)(7),{a:n,defaultModel:r,defaultWorkspace:i,agentModel:a,agentWorkspace:o,onEditWorkspace:s}=e,c;return t[0]!==n||t[1]!==a||t[2]!==o||t[3]!==r||t[4]!==i||t[5]!==s?(c=(0,Q.jsx)($t,{children:(0,Q.jsx)(Gt,{a:n,defaultModel:r,defaultWorkspace:i,agentModel:a,agentWorkspace:o,onEditWorkspace:s})}),t[0]=n,t[1]=a,t[2]=o,t[3]=r,t[4]=i,t[5]=s,t[6]=c):c=t[6],c}function rn(e){let t=(0,Z.c)(72),{a:n,selected:r,busy:i,capabilityPresets:a,defaultPresetId:o,onUpdateAgentExtends:s,onOpenCapabilityPreset:c}=e,l=o===void 0?`default`:o,u;t[0]===a?u=t[1]:(u=new Map(a.map(on)),t[0]=a,t[1]=u);let d=u,p;t[2]!==n.capabilityPresetsGlobalDefault||t[3]!==n.capabilityPresetsGlobalDefaultHint||t[4]!==l||t[5]!==d?(p=d.get(l)??{id:l,name:n.capabilityPresetsGlobalDefault,description:n.capabilityPresetsGlobalDefaultHint},t[2]=n.capabilityPresetsGlobalDefault,t[3]=n.capabilityPresetsGlobalDefaultHint,t[4]=l,t[5]=d,t[6]=p):p=t[6];let m=p,g,_,v,y,x;if(t[7]!==n.capabilityPresetAdd||t[8]!==n.capabilityPresetMoveDown||t[9]!==n.capabilityPresetMoveUp||t[10]!==n.capabilityPresetRemove||t[11]!==n.capabilityPresetsEmptyAdditional||t[12]!==n.capabilityPresetsGlobalDefault||t[13]!==n.capabilityPresetsGlobalDefaultHint||t[14]!==n.capabilityPresetsHint||t[15]!==n.capabilityPresetsManage||t[16]!==n.capabilityPresetsTitle||t[17]!==i||t[18]!==a||t[19]!==l||t[20]!==m.description||t[21]!==m.id||t[22]!==m.name||t[23]!==c||t[24]!==s||t[25]!==d||t[26]!==r.extends){let e;t[32]===l?e=t[33]:(e=e=>e!==l,t[32]=l,t[33]=e);let o=r.extends.filter(e),u=a.map(an).filter(e=>e!==l&&!o.includes(e)),p=u[0]??``;_=$t,g=mt;let S;t[34]===c?S=t[35]:(S=()=>c(``),t[34]=c,t[35]=S);let C;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,Q.jsx)(dt,{className:`size-3.5`,"aria-hidden":!0}),t[36]=C):C=t[36];let w;t[37]!==n.capabilityPresetsManage||t[38]!==i||t[39]!==S?(w=(0,Q.jsxs)(h,{type:`button`,variant:`secondary`,className:`text-xs`,disabled:i,onClick:S,children:[C,n.capabilityPresetsManage]}),t[37]=n.capabilityPresetsManage,t[38]=i,t[39]=S,t[40]=w):w=t[40],t[41]!==n.capabilityPresetsHint||t[42]!==n.capabilityPresetsTitle||t[43]!==w?(v=(0,Q.jsx)(pt,{icon:we,title:n.capabilityPresetsTitle,subtitle:n.capabilityPresetsHint,trailing:w}),t[41]=n.capabilityPresetsHint,t[42]=n.capabilityPresetsTitle,t[43]=w,t[44]=v):v=t[44];let T;t[45]!==m.id||t[46]!==c?(T=()=>c(m.id),t[45]=m.id,t[46]=c,t[47]=T):T=t[47];let E=m.name||n.capabilityPresetsGlobalDefault,D;t[48]===E?D=t[49]:(D=(0,Q.jsx)(`div`,{className:`truncate text-sm font-medium text-fg`,children:E}),t[48]=E,t[49]=D);let O;t[50]===n.capabilityPresetsGlobalDefault?O=t[51]:(O=(0,Q.jsx)(`span`,{className:`shrink-0 rounded-full border border-accent/25 bg-accent/10 px-2 py-0.5 text-[11px] font-medium text-accent`,children:n.capabilityPresetsGlobalDefault}),t[50]=n.capabilityPresetsGlobalDefault,t[51]=O);let k;t[52]!==D||t[53]!==O?(k=(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[D,O]}),t[52]=D,t[53]=O,t[54]=k):k=t[54];let A;t[55]===m.id?A=t[56]:(A=(0,Q.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-[11px] text-fg-muted`,children:m.id}),t[55]=m.id,t[56]=A);let j=m.description||n.capabilityPresetsGlobalDefaultHint,M;t[57]===j?M=t[58]:(M=(0,Q.jsx)(`div`,{className:`mt-1 line-clamp-2 text-xs text-fg-muted`,children:j}),t[57]=j,t[58]=M);let N;t[59]!==T||t[60]!==k||t[61]!==A||t[62]!==M?(N=(0,Q.jsx)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-accent/25 bg-accent-soft/20 px-3 py-2 sm:flex-row sm:items-center sm:justify-between`,children:(0,Q.jsxs)(`button`,{type:`button`,className:`min-w-0 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,onClick:T,children:[k,A,M]})}),t[59]=T,t[60]=k,t[61]=A,t[62]=M,t[63]=N):N=t[63],y=(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[N,o.length>0?o.map((e,t)=>{let r=d.get(e);return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:`min-w-0 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,onClick:()=>c(e),children:[(0,Q.jsx)(`div`,{className:`truncate text-sm font-medium text-fg`,children:r?.name??e}),(0,Q.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-[11px] text-fg-muted`,children:e}),r?.description?(0,Q.jsx)(`div`,{className:`mt-1 line-clamp-2 text-xs text-fg-muted`,children:r.description}):null]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-1.5`,children:[(0,Q.jsx)(h,{type:`button`,variant:`secondary`,className:`size-8 rounded-lg p-0`,disabled:i||t===0,"aria-label":n.capabilityPresetMoveUp,onClick:()=>{let e=[...o],[n,r]=[e[t],e[t-1]];e[t-1]=n,e[t]=r,s(e)},children:(0,Q.jsx)(ot,{className:`size-3.5`,"aria-hidden":!0})}),(0,Q.jsx)(h,{type:`button`,variant:`secondary`,className:`size-8 rounded-lg p-0`,disabled:i||t===o.length-1,"aria-label":n.capabilityPresetMoveDown,onClick:()=>{let e=[...o],[n,r]=[e[t+1],e[t]];e[t]=n,e[t+1]=r,s(e)},children:(0,Q.jsx)(b,{className:`size-3.5`,"aria-hidden":!0})}),(0,Q.jsx)(h,{type:`button`,variant:`secondary`,className:`size-8 rounded-lg p-0`,disabled:i,"aria-label":n.capabilityPresetRemove,onClick:()=>s(o.filter(t=>t!==e)),children:(0,Q.jsx)(f,{className:`size-3.5`,"aria-hidden":!0})})]})]},e)}):(0,Q.jsx)(`div`,{className:`rounded-lg border border-dashed border-edge-subtle px-3 py-3 text-sm text-fg-muted`,children:n.capabilityPresetsEmptyAdditional})]}),x=u.length>0?(0,Q.jsxs)(`div`,{className:`mt-3 flex flex-col gap-2 sm:flex-row sm:items-center`,children:[(0,Q.jsx)(Te,{className:`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg focus:border-edge-strong focus:outline-none`,disabled:i,defaultValue:p,children:u.map(e=>(0,Q.jsx)(rt,{value:e,children:d.get(e)?.name??e},e))}),(0,Q.jsxs)(h,{type:`button`,variant:`secondary`,disabled:i||!p,onClick:e=>{let t=e.currentTarget.parentElement?.querySelector(`select`)?.value||p;t&&s([...o,t])},children:[(0,Q.jsx)(H,{className:`size-4`,"aria-hidden":!0}),n.capabilityPresetAdd]})]}):null,t[7]=n.capabilityPresetAdd,t[8]=n.capabilityPresetMoveDown,t[9]=n.capabilityPresetMoveUp,t[10]=n.capabilityPresetRemove,t[11]=n.capabilityPresetsEmptyAdditional,t[12]=n.capabilityPresetsGlobalDefault,t[13]=n.capabilityPresetsGlobalDefaultHint,t[14]=n.capabilityPresetsHint,t[15]=n.capabilityPresetsManage,t[16]=n.capabilityPresetsTitle,t[17]=i,t[18]=a,t[19]=l,t[20]=m.description,t[21]=m.id,t[22]=m.name,t[23]=c,t[24]=s,t[25]=d,t[26]=r.extends,t[27]=g,t[28]=_,t[29]=v,t[30]=y,t[31]=x}else g=t[27],_=t[28],v=t[29],y=t[30],x=t[31];let S;t[64]!==g||t[65]!==v||t[66]!==y||t[67]!==x?(S=(0,Q.jsxs)(g,{children:[v,y,x]}),t[64]=g,t[65]=v,t[66]=y,t[67]=x,t[68]=S):S=t[68];let C;return t[69]!==_||t[70]!==S?(C=(0,Q.jsx)(_,{children:S}),t[69]=_,t[70]=S,t[71]=C):C=t[71],C}function an(e){return e.id}function on(e){return[e.id,e]}function sn(e){let t=(0,Z.c)(3),{a:n,selected:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,Q.jsx)($t,{children:(0,Q.jsx)(Xt,{a:n,selected:r})}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i}function cn(e){let t=(0,Z.c)(10),{a:n,selected:r,busy:i,onDelete:a}=e,o;return t[0]!==n.dangerZoneBody||t[1]!==n.dangerZoneHint||t[2]!==n.dangerZoneMainUnavailable||t[3]!==n.dangerZoneTitle||t[4]!==n.purgeDisk||t[5]!==n.removeFromConfig||t[6]!==i||t[7]!==a||t[8]!==r.id?(o=(0,Q.jsx)($t,{children:r.id===`main`?(0,Q.jsx)(mt,{children:(0,Q.jsx)(pt,{icon:re,title:n.dangerZoneTitle,subtitle:n.dangerZoneMainUnavailable})}):(0,Q.jsxs)(mt,{className:`border border-red-200/70 bg-red-50/60 dark:border-red-900/50 dark:bg-red-950/25`,children:[(0,Q.jsx)(pt,{icon:re,title:n.dangerZoneTitle,subtitle:n.dangerZoneHint}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Q.jsx)(`p`,{className:`max-w-xl text-sm text-red-800 dark:text-red-200`,children:n.dangerZoneBody}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-2`,children:[(0,Q.jsxs)(h,{type:`button`,variant:`secondary`,disabled:i,onClick:()=>void a(!1),children:[(0,Q.jsx)(f,{className:`mr-1 size-4`,"aria-hidden":!0}),n.removeFromConfig]}),(0,Q.jsx)(h,{type:`button`,variant:`secondary`,className:`border-red-200 text-red-700 hover:bg-red-100 dark:border-red-900/60 dark:text-red-300 dark:hover:bg-red-950/50`,disabled:i,onClick:()=>void a(!0),children:n.purgeDisk})]})]})]})}),t[0]=n.dangerZoneBody,t[1]=n.dangerZoneHint,t[2]=n.dangerZoneMainUnavailable,t[3]=n.dangerZoneTitle,t[4]=n.purgeDisk,t[5]=n.removeFromConfig,t[6]=i,t[7]=a,t[8]=r.id,t[9]=o):o=t[9],o}var ln=i(W,`w-full text-xs sm:w-auto sm:min-w-[11rem] sm:max-w-[17rem] sm:shrink-0`);function un(e){let t=(0,Z.c)(62),{a:n,busy:r,bindingsLoading:a,agentBindings:o,onRemoveBinding:s,onAddBinding:c,channelStatuses:l,channelsStatusLoading:u,useManualChannel:d,newBindChannel:f,setNewBindChannel:p,bindSessionChats:m,sessionsLoading:g,newBindSessionIdx:_,setNewBindSessionIdx:v,newBindCustomPeer:y,setNewBindCustomPeer:b,onRefreshSessions:x,lastActiveLabels:S,selectRecipient:C}=e,w=!u&&(d||l.length>0),T;t[0]!==n.channelsHint||t[1]!==n.channelsTitle?(T=(0,Q.jsx)(pt,{className:`shrink-0`,icon:ze,title:n.channelsTitle,subtitle:n.channelsHint}),t[0]=n.channelsHint,t[1]=n.channelsTitle,t[2]=T):T=t[2];let E;t[3]!==n.channelsLoading||t[4]!==n.channelsNone||t[5]!==n.removeBinding||t[6]!==o||t[7]!==a||t[8]!==r||t[9]!==s?(E=a?(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.channelsLoading}):o.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.channelsNone}):(0,Q.jsx)(`ul`,{className:`flex flex-col gap-2 text-sm`,children:o.map(e=>(0,Q.jsxs)(`li`,{className:`flex flex-wrap items-center justify-between gap-2 rounded-lg border border-edge bg-surface-panel px-3 py-2`,children:[(0,Q.jsx)(`span`,{className:`font-mono text-xs`,children:St(e.match)}),(0,Q.jsx)(h,{type:`button`,variant:`secondary`,disabled:r,onClick:()=>void s(e),children:n.removeBinding})]},`${e.match.channel}-${St(e.match)}`))}),t[3]=n.channelsLoading,t[4]=n.channelsNone,t[5]=n.removeBinding,t[6]=o,t[7]=a,t[8]=r,t[9]=s,t[10]=E):E=t[10];let D;t[11]!==n.channelLabel||t[12]!==n.channelsDisabledSuffix||t[13]!==n.channelsLoadingChannels||t[14]!==n.channelsManualChannelHint||t[15]!==l||t[16]!==u||t[17]!==f||t[18]!==p||t[19]!==b||t[20]!==v||t[21]!==d?(D=u?(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.channelsLoadingChannels}):d?(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm`,children:[(0,Q.jsx)(`span`,{className:`text-fg-muted`,children:n.channelLabel}),(0,Q.jsx)(`input`,{className:Ct(),value:f,onChange:e=>p(e.target.value),placeholder:`telegram`,autoComplete:`off`}),(0,Q.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.channelsManualChannelHint})]}):(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm`,children:[(0,Q.jsx)(`span`,{className:`text-fg-muted`,children:n.channelLabel}),(0,Q.jsx)(Te,{className:i(Ct(),`py-2`),value:f,onChange:e=>{p(e.target.value),v(null),b(``)},children:l.map(e=>(0,Q.jsxs)(rt,{value:e.name,disabled:!e.enabled,children:[e.name,` `,e.enabled?``:n.channelsDisabledSuffix]},e.name))})]}),t[11]=n.channelLabel,t[12]=n.channelsDisabledSuffix,t[13]=n.channelsLoadingChannels,t[14]=n.channelsManualChannelHint,t[15]=l,t[16]=u,t[17]=f,t[18]=p,t[19]=b,t[20]=v,t[21]=d,t[22]=D):D=t[22];let O;t[23]!==n.channelsCustomPeerHint||t[24]!==n.channelsCustomPeerPlaceholder||t[25]!==n.channelsLoadingSessions||t[26]!==n.channelsNoSessionsHint||t[27]!==n.channelsPeerAny||t[28]!==n.channelsPeerFromSessions||t[29]!==n.channelsRefreshSessions||t[30]!==n.channelsRefreshSessionsHint||t[31]!==n.channelsSessionLabel||t[32]!==n.peerIdLabel||t[33]!==m||t[34]!==r||t[35]!==S||t[36]!==f||t[37]!==y||t[38]!==_||t[39]!==x||t[40]!==C||t[41]!==g||t[42]!==b||t[43]!==v||t[44]!==w?(O=w&&f.trim()?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 border-t border-edge-subtle pt-3 text-sm`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-fg-muted`,children:n.channelsSessionLabel}),(0,Q.jsxs)(h,{type:`button`,variant:`ghost`,className:`h-7 gap-1 px-2 text-xs`,disabled:r||g||!f.trim(),title:n.channelsRefreshSessionsHint,onClick:()=>x(),children:[(0,Q.jsx)(B,{className:i(`size-3.5`,g&&`animate-spin`),strokeWidth:1.75}),n.channelsRefreshSessions]})]}),g&&m.length===0?(0,Q.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.channelsLoadingSessions}):null,(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:`text-fg-muted`,children:n.channelsPeerFromSessions}),(0,Q.jsxs)(Te,{className:i(Ct(),`py-2`),value:_==null?``:String(_),disabled:r||!f.trim()||!!y.trim(),onChange:e=>{let t=e.target.value;v(t===``?null:Number(t))},children:[(0,Q.jsx)(rt,{value:``,children:n.channelsPeerAny}),m.map((e,t)=>(0,Q.jsx)(rt,{value:String(t),children:bt(e,S)},`${e.channel}-${e.chatId}`))]})]}),m.length===0&&f.trim()&&!g?(0,Q.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.channelsNoSessionsHint}):null,(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:`text-fg-muted`,children:n.peerIdLabel}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-stretch sm:gap-2`,children:[(0,Q.jsx)(`input`,{type:`text`,className:i(Ct(),`min-w-0 w-full sm:flex-1`),value:y,onChange:e=>{b(e.target.value),e.target.value.trim()&&v(null)},placeholder:n.channelsCustomPeerPlaceholder,autoComplete:`off`}),(0,Q.jsxs)(Te,{className:ln,value:y,onChange:e=>{let t=e.target.value;b(t||``),v(null)},children:[(0,Q.jsx)(rt,{value:``,children:C}),m.map(e=>(0,Q.jsx)(rt,{value:e.chatId,children:bt(e,S)},`${e.channel}-${e.chatId}`))]})]}),(0,Q.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.channelsCustomPeerHint})]})]}):null,t[23]=n.channelsCustomPeerHint,t[24]=n.channelsCustomPeerPlaceholder,t[25]=n.channelsLoadingSessions,t[26]=n.channelsNoSessionsHint,t[27]=n.channelsPeerAny,t[28]=n.channelsPeerFromSessions,t[29]=n.channelsRefreshSessions,t[30]=n.channelsRefreshSessionsHint,t[31]=n.channelsSessionLabel,t[32]=n.peerIdLabel,t[33]=m,t[34]=r,t[35]=S,t[36]=f,t[37]=y,t[38]=_,t[39]=x,t[40]=C,t[41]=g,t[42]=b,t[43]=v,t[44]=w,t[45]=O):O=t[45];let k;t[46]!==r||t[47]!==u||t[48]!==f?(k=r||!f.trim()||u,t[46]=r,t[47]=u,t[48]=f,t[49]=k):k=t[49];let A;t[50]!==n.addBinding||t[51]!==k?(A=(0,Q.jsx)(`div`,{children:(0,Q.jsx)(h,{type:`submit`,disabled:k,children:n.addBinding})}),t[50]=n.addBinding,t[51]=k,t[52]=A):A=t[52];let j;t[53]!==c||t[54]!==D||t[55]!==O||t[56]!==A?(j=(0,Q.jsxs)(`form`,{className:`mt-4 flex flex-col gap-3`,onSubmit:c,children:[D,O,A]}),t[53]=c,t[54]=D,t[55]=O,t[56]=A,t[57]=j):j=t[57];let M;return t[58]!==T||t[59]!==E||t[60]!==j?(M=(0,Q.jsxs)(mt,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:[T,E,j]}),t[58]=T,t[59]=E,t[60]=j,t[61]=M):M=t[61],M}function dn(e){let t=(0,Z.c)(32),{a:n,filesLoading:r,files:a,activeFile:o,setActiveFile:c,filesViewMode:l,setFilesViewMode:u,fileDraft:d,setFileDraft:f,fileSaving:p,profileFileLoading:m,profileEditorNonce:g,onTryInChat:_}=e,v=s(fn),y;t[0]!==n.missing||t[1]!==a?.files?(y=a?.files.map(e=>({id:e.name,label:e.missing?`${e.name} (${n.missing})`:e.name,title:e.name}))??[],t[0]=n.missing,t[1]=a?.files,t[2]=y):y=t[2];let b=y,x;t[3]===n.filesHint?x=t[4]:(x=(0,Q.jsx)(`p`,{className:`shrink-0 text-sm text-fg-muted`,children:n.filesHint}),t[3]=n.filesHint,t[4]=x);let S;t[5]!==n.filesAutoSaveHint||t[6]!==n.filesEmpty||t[7]!==n.filesLoading||t[8]!==n.filesMarkdownEdit||t[9]!==n.filesMarkdownPreview||t[10]!==n.filesNavAria||t[11]!==n.filesSavingStatus||t[12]!==n.pickFile||t[13]!==n.tryInChat||t[14]!==o||t[15]!==d||t[16]!==p||t[17]!==b||t[18]!==a||t[19]!==r||t[20]!==l||t[21]!==v||t[22]!==_||t[23]!==g||t[24]!==m||t[25]!==c||t[26]!==f||t[27]!==u?(S=r?(0,Q.jsx)(`p`,{className:`shrink-0 text-sm text-fg-muted`,children:n.filesLoading}):a?(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden`,children:[(0,Q.jsx)(w,{items:b,activeTab:o??``,onChange:c,ariaLabel:n.filesNavAria,tabIdPrefix:`agent-files-tab`,panelIdPrefix:`agent-files-panel`,className:`shrink-0 flex-wrap`,buttonClassName:`font-mono text-xs whitespace-nowrap`}),(0,Q.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col gap-2 overflow-hidden`,children:o?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-between gap-2`,children:[(0,Q.jsxs)(`div`,{className:`inline-flex rounded-lg border border-edge bg-surface-panel p-0.5`,role:`group`,"aria-label":`${n.filesMarkdownEdit} / ${n.filesMarkdownPreview}`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:i(`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1.5 text-xs font-medium`,V.press,l===`edit`?`bg-accent-soft text-accent-fg`:`text-fg-muted hover:bg-surface-hover`),onClick:()=>u(`edit`),children:[(0,Q.jsx)(nt,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),n.filesMarkdownEdit]}),(0,Q.jsxs)(`button`,{type:`button`,className:i(`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1.5 text-xs font-medium`,V.press,l===`preview`?`bg-accent-soft text-accent-fg`:`text-fg-muted hover:bg-surface-hover`),onClick:()=>u(`preview`),children:[(0,Q.jsx)(ae,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),n.filesMarkdownPreview]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-xs text-fg-muted`,children:[p?(0,Q.jsx)(`span`,{children:n.filesSavingStatus}):null,(0,Q.jsx)(`span`,{children:n.filesAutoSaveHint}),_?(0,Q.jsxs)(h,{type:`button`,variant:`secondary`,className:`ml-auto text-xs`,onClick:_,children:[(0,Q.jsx)(ie,{className:`mr-1 size-3.5`,"aria-hidden":!0}),n.tryInChat]}):null]})]}),l===`edit`?(0,Q.jsx)(`div`,{className:i(Ct(),`flex min-h-0 flex-1 flex-col overflow-hidden p-0`,m&&`pointer-events-none opacity-60`),children:(0,Q.jsx)(ft,{initialContent:d,onChange:f,isDark:v,className:`min-h-0 flex-1`},`${o??`file`}-${g}`)}):(0,Q.jsx)(`div`,{className:i(Ct(),`min-h-0 flex-1 overflow-y-auto text-sm`,m&&`pointer-events-none opacity-60`),children:(0,Q.jsx)(N,{content:d,className:`text-sm`})})]}):(0,Q.jsx)(`p`,{className:`shrink-0 text-sm text-fg-muted`,children:n.pickFile})})]}):(0,Q.jsx)(`p`,{className:`shrink-0 text-sm text-fg-muted`,children:n.filesEmpty}),t[5]=n.filesAutoSaveHint,t[6]=n.filesEmpty,t[7]=n.filesLoading,t[8]=n.filesMarkdownEdit,t[9]=n.filesMarkdownPreview,t[10]=n.filesNavAria,t[11]=n.filesSavingStatus,t[12]=n.pickFile,t[13]=n.tryInChat,t[14]=o,t[15]=d,t[16]=p,t[17]=b,t[18]=a,t[19]=r,t[20]=l,t[21]=v,t[22]=_,t[23]=g,t[24]=m,t[25]=c,t[26]=f,t[27]=u,t[28]=S):S=t[28];let C;return t[29]!==x||t[30]!==S?(C=(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-hidden`,children:[x,S]}),t[29]=x,t[30]=S,t[31]=C):C=t[31],C}function fn(e){return e.resolved===`dark`}function pn(e){let t=(0,Z.c)(66),{a:n,chat:r,selected:i,busy:a,modelRows:o,setModelRows:s,onSaveModels:c,onClearModelsEntry:l,hideInlineSave:u}=e,d;t[0]!==n.modelsTabHint||t[1]!==n.modelsTabTitle?(d=(0,Q.jsx)(pt,{className:`shrink-0`,icon:X,title:n.modelsTabTitle,subtitle:n.modelsTabHint}),t[0]=n.modelsTabHint,t[1]=n.modelsTabTitle,t[2]=d):d=t[2];let f;t[3]===n.modelsPresetLabel?f=t[4]:(f=(0,Q.jsx)(`span`,{className:`font-medium text-fg`,children:n.modelsPresetLabel}),t[3]=n.modelsPresetLabel,t[4]=f);let p;t[5]===i.typedModels.preset?p=t[6]:(p=Et(i.typedModels.preset),t[5]=i.typedModels.preset,t[6]=p);let m;t[7]!==f||t[8]!==p?(m=(0,Q.jsxs)(`div`,{children:[f,` `,p]}),t[7]=f,t[8]=p,t[9]=m):m=t[9];let g;t[10]===n.modelsEffectiveLabel?g=t[11]:(g=(0,Q.jsx)(`span`,{className:`font-medium text-fg`,children:n.modelsEffectiveLabel}),t[10]=n.modelsEffectiveLabel,t[11]=g);let _;t[12]===i.typedModels.effective?_=t[13]:(_=Et(i.typedModels.effective),t[12]=i.typedModels.effective,t[13]=_);let v;t[14]!==g||t[15]!==_?(v=(0,Q.jsxs)(`div`,{children:[g,` `,_]}),t[14]=g,t[15]=_,t[16]=v):v=t[16];let y;t[17]!==m||t[18]!==v?(y=(0,Q.jsxs)(`div`,{className:`mb-4 grid gap-2 rounded-lg border border-edge-subtle bg-surface-base/60 p-3 text-xs text-fg-muted dark:border-edge`,children:[m,v]}),t[17]=m,t[18]=v,t[19]=y):y=t[19];let b;t[20]!==n.addTypedModel||t[21]!==n.addTypedModelPurpose||t[22]!==n.removeTypedModel||t[23]!==n.typedModelAddFallback||t[24]!==n.typedModelCustomTitle||t[25]!==n.typedModelDefaultBadge||t[26]!==n.typedModelDescriptionLabel||t[27]!==n.typedModelDescriptionPlaceholder||t[28]!==n.typedModelFallbackEmptyHint||t[29]!==n.typedModelFallbackModelsLabel||t[30]!==n.typedModelFallbackPlaceholder||t[31]!==n.typedModelIdLabel||t[32]!==n.typedModelIdPlaceholder||t[33]!==n.typedModelNoCustomRoles||t[34]!==n.typedModelPrimaryModelLabel||t[35]!==n.typedModelRecommendedTitle||t[36]!==n.typedModelRemoveFallback||t[37]!==n.typedModelRoleDescriptions||t[38]!==n.typedModelRoleNames?(b={id:n.typedModelIdLabel,description:n.typedModelDescriptionLabel,primaryModel:n.typedModelPrimaryModelLabel,fallbackModels:n.typedModelFallbackModelsLabel,addFallback:n.typedModelAddFallback,removeFallback:n.typedModelRemoveFallback,fallbackPlaceholder:n.typedModelFallbackPlaceholder,fallbackEmptyHint:n.typedModelFallbackEmptyHint,add:n.addTypedModel,remove:n.removeTypedModel,recommendedTitle:n.typedModelRecommendedTitle,customTitle:n.typedModelCustomTitle,defaultBadge:n.typedModelDefaultBadge,addPurpose:n.addTypedModelPurpose,noCustomRoles:n.typedModelNoCustomRoles,idPlaceholder:n.typedModelIdPlaceholder,descriptionPlaceholder:n.typedModelDescriptionPlaceholder,roleNames:n.typedModelRoleNames,roleDescriptions:n.typedModelRoleDescriptions},t[20]=n.addTypedModel,t[21]=n.addTypedModelPurpose,t[22]=n.removeTypedModel,t[23]=n.typedModelAddFallback,t[24]=n.typedModelCustomTitle,t[25]=n.typedModelDefaultBadge,t[26]=n.typedModelDescriptionLabel,t[27]=n.typedModelDescriptionPlaceholder,t[28]=n.typedModelFallbackEmptyHint,t[29]=n.typedModelFallbackModelsLabel,t[30]=n.typedModelFallbackPlaceholder,t[31]=n.typedModelIdLabel,t[32]=n.typedModelIdPlaceholder,t[33]=n.typedModelNoCustomRoles,t[34]=n.typedModelPrimaryModelLabel,t[35]=n.typedModelRecommendedTitle,t[36]=n.typedModelRemoveFallback,t[37]=n.typedModelRoleDescriptions,t[38]=n.typedModelRoleNames,t[39]=b):b=t[39];let x;t[40]!==a||t[41]!==r||t[42]!==o||t[43]!==i.typedModels.defaultRole||t[44]!==s||t[45]!==b?(x=(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,children:(0,Q.jsx)(Mt,{rows:o,onChange:s,disabled:a,defaultRole:i.typedModels.defaultRole,chat:r,labels:b})}),t[40]=a,t[41]=r,t[42]=o,t[43]=i.typedModels.defaultRole,t[44]=s,t[45]=b,t[46]=x):x=t[46];let S;t[47]!==n.modelsSave||t[48]!==a||t[49]!==u||t[50]!==c?(S=u?null:(0,Q.jsx)(h,{type:`button`,disabled:a,onClick:()=>void c(),children:n.modelsSave}),t[47]=n.modelsSave,t[48]=a,t[49]=u,t[50]=c,t[51]=S):S=t[51];let C;t[52]===l?C=t[53]:(C=()=>void l(),t[52]=l,t[53]=C);let w;t[54]!==n.modelsResetInherit||t[55]!==a||t[56]!==C?(w=(0,Q.jsx)(h,{type:`button`,variant:`secondary`,disabled:a,onClick:C,children:n.modelsResetInherit}),t[54]=n.modelsResetInherit,t[55]=a,t[56]=C,t[57]=w):w=t[57];let T;t[58]!==S||t[59]!==w?(T=(0,Q.jsxs)(`div`,{className:`mt-4 flex shrink-0 flex-wrap gap-2`,children:[S,w]}),t[58]=S,t[59]=w,t[60]=T):T=t[60];let E;return t[61]!==d||t[62]!==T||t[63]!==y||t[64]!==x?(E=(0,Q.jsxs)(mt,{className:`flex min-h-0 flex-1 flex-col`,children:[d,y,x,T]}),t[61]=d,t[62]=T,t[63]=y,t[64]=x,t[65]=E):E=t[65],E}function mn(e,t){switch(e){case`adventurer`:return t.avatarStyleAdventurer;case`bottts`:return t.avatarStyleRobot;case`lorelei`:return t.avatarStyleLorelei;case`thumbs`:return t.avatarStyleThumbs;case`fun-emoji`:return t.avatarStyleFunEmoji;default:return e}}function hn(e){let{agentId:t,value:n,onChange:r,a,id:o}=e,s=(0,$.useRef)(null),[c,l]=(0,$.useState)(!1),[u,d]=(0,$.useState)(null),[f,p]=(0,$.useState)(!1),m=(0,$.useMemo)(()=>{let e=tt(n.trim());return e&&Re(e.styleId)?e.styleId:We[0]??`adventurer`},[n]),g=(0,$.useCallback)(async(e,n)=>{try{await ne(t)}catch{}r(ye(e,n)),p(!1)},[t,r]),_=(0,$.useCallback)(async e=>{let n=e.target.files?.[0];if(e.target.value=``,n){d(null),l(!0);try{await A(t,n),Se(t),r(Ze)}catch(e){let t=e instanceof Error?e.message:``;d(t===`avatar_too_large`?a.avatarTooLarge:t===`unsupported_image_type`||t===`empty_file`?a.avatarInvalidImage:a.avatarUploadFailed)}finally{l(!1)}}},[a,t,r]),y=(e,t)=>{let r=tt(n.trim());return!!(r&&r.styleId===e&&r.seed===t)};return(0,Q.jsxs)(`div`,{...o?{id:o}:{},className:`flex flex-col gap-3 sm:col-span-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:a.avatarPickerTitle}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`input`,{ref:s,type:`file`,accept:`image/png,image/jpeg,image/webp,.png,.jpg,.jpeg,.webp`,className:`hidden`,onChange:e=>void _(e)}),(0,Q.jsxs)(h,{type:`button`,variant:`secondary`,className:`gap-1.5 px-2.5 py-1.5 text-xs`,disabled:c,onClick:()=>s.current?.click(),children:[(0,Q.jsx)(pe,{className:`size-3.5 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),c?a.avatarUploading:a.avatarUploadCustom]})]})]}),u?(0,Q.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:u}):null,(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:We.map(e=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>void g(e,ge[0]??t),className:i(`rounded-full border px-3 py-1.5 text-xs font-medium transition-colors`,V.press,m===e?`border-fg bg-fg text-surface-base`:`border-edge-subtle bg-surface-panel text-fg hover:border-edge`),children:mn(e,a)},e))}),(0,Q.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel/50 p-3`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[ge.map(e=>(0,Q.jsx)(`button`,{type:`button`,title:e,onClick:()=>void g(m,e),className:i(`flex size-12 shrink-0 items-center justify-center rounded-full border-2 transition-colors`,V.press,y(m,e)?`border-accent ring-2 ring-accent/30`:`border-transparent hover:border-edge`),children:(0,Q.jsx)(`img`,{src:_t(m,e,96),alt:``,width:44,height:44,className:`size-11 rounded-full object-cover`,draggable:!1})},e)),(0,Q.jsxs)(at,{open:f,onOpenChange:p,children:[(0,Q.jsx)(oe,{asChild:!0,children:(0,Q.jsx)(`button`,{type:`button`,className:i(`flex size-12 shrink-0 items-center justify-center rounded-xl border border-edge-subtle bg-surface-base text-xs font-medium text-fg-muted hover:border-edge hover:text-fg`,V.press),children:a.avatarMore})}),(0,Q.jsx)(v,{children:(0,Q.jsxs)(K,{className:`z-[80] max-h-72 w-[min(22rem,calc(100vw-2rem))] overflow-y-auto rounded-xl border border-edge-subtle bg-surface-panel p-3 shadow-lg`,sideOffset:6,align:`end`,children:[(0,Q.jsx)(`p`,{className:`mb-2 text-xs font-medium text-fg-muted`,children:mn(m,a)}),(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:je.map(e=>(0,Q.jsx)(`button`,{type:`button`,title:e,onClick:()=>void g(m,e),className:i(`flex size-11 shrink-0 items-center justify-center rounded-full border-2 transition-colors`,V.press,y(m,e)?`border-accent ring-2 ring-accent/30`:`border-transparent hover:border-edge`),children:(0,Q.jsx)(`img`,{src:_t(m,e,88),alt:``,width:40,height:40,className:`size-10 rounded-full object-cover`,draggable:!1})},e))})]})})]})]}),(0,Q.jsxs)(`div`,{className:`mt-3 flex items-center gap-2 border-t border-edge-subtle pt-3`,children:[(0,Q.jsx)(`span`,{className:`text-xs text-fg-muted`,children:a.personaAvatar}),(0,Q.jsx)(Ye,{agentId:t,avatar:n,size:40}),n.trim()&&!tt(n.trim())&&n.trim()!==`xopc:custom`?(0,Q.jsx)(`span`,{className:`truncate font-mono text-[10px] text-fg-muted`,title:n,children:n}):null]})]})]})}function gn(e){let t=(0,Z.c)(207),{a:n,chat:r,selected:a,busy:c,editName:l,setEditName:u,editDescription:d,setEditDescription:f,editWorkspace:p,setEditWorkspace:m,editModel:g,setEditModel:v,onSetDefault:y,onSetTuiDefault:b,isTuiDefault:x,isTuiDefaultInherited:S,onSaveAgentEdits:C,hideInlineSave:w,profileMarkdownLoading:E,profileDraft:D,updateIdentity:O,handleSoulTemplateChange:k,handleSoulContentChange:A,setAvatarDialogOpen:M,toggleSoulPreviewMode:P,onTryInChat:F}=e,I=o(yn),R=s(vn),z;t[0]===D?.identity?z=t[1]:(z=D?.identity??{name:``,description:``,language:``,creature:``,emoji:``,avatar:``},t[0]=D?.identity,t[1]=z);let B=z,ee=D?.soulTemplate??`professional`,te=D?.soulCustomContent??``,ne=D?.soulEditorNonce??0,H=D?.soulPreviewMode??!1,U=D?.avatarDialogOpen??!1,re;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(re=Ct(),t[2]=re):re=t[2];let W=re,G;t[3]===I?G=t[4]:(G=(e,t)=>I===`zh`?t:e,t[3]=I,t[4]=G);let K=G;if(!a){let e;return t[5]===n.selectAgentHint?e=t[6]:(e=(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.selectAgentHint}),t[5]=n.selectAgentHint,t[6]=e),e}let q;t[7]!==B.avatar||t[8]!==a.id?(q=(0,Q.jsx)(Ye,{agentId:a.id,avatar:B.avatar,size:36,className:`size-9 rounded-lg`}),t[7]=B.avatar,t[8]=a.id,t[9]=q):q=t[9];let J;t[10]===M?J=t[11]:(J=()=>M(!0),t[10]=M,t[11]=J);let oe;t[12]!==n.avatarOpenSettingsAria||t[13]!==J?(oe={onClick:J,ariaLabel:n.avatarOpenSettingsAria,id:`agent-avatar-settings`},t[12]=n.avatarOpenSettingsAria,t[13]=J,t[14]=oe):oe=t[14];let se;t[15]!==n.globalDefaultBadge||t[16]!==n.tuiDefaultBadge||t[17]!==n.tuiDefaultInheritedBadge||t[18]!==x||t[19]!==S||t[20]!==a.isDefault?(se=a.isDefault||x?(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[a.isDefault?(0,Q.jsx)(`span`,{className:`rounded-full bg-accent-soft px-2 py-0.5 text-xs font-medium text-accent`,children:n.globalDefaultBadge}):null,x?(0,Q.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-xs font-medium text-fg`,children:S?n.tuiDefaultInheritedBadge:n.tuiDefaultBadge}):null]}):null,t[15]=n.globalDefaultBadge,t[16]=n.tuiDefaultBadge,t[17]=n.tuiDefaultInheritedBadge,t[18]=x,t[19]=S,t[20]=a.isDefault,t[21]=se):se=t[21];let ce;t[22]!==n.setDefault||t[23]!==n.setTuiDefault||t[24]!==c||t[25]!==x||t[26]!==y||t[27]!==b||t[28]!==a.isDefault?(ce=!a.isDefault||!x?(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[a.isDefault?null:(0,Q.jsx)(h,{type:`button`,variant:`secondary`,className:`text-xs`,disabled:c,onClick:()=>void y(),children:n.setDefault}),x?null:(0,Q.jsx)(h,{type:`button`,variant:`secondary`,className:`text-xs`,disabled:c,onClick:()=>void b(),children:n.setTuiDefault})]}):null,t[22]=n.setDefault,t[23]=n.setTuiDefault,t[24]=c,t[25]=x,t[26]=y,t[27]=b,t[28]=a.isDefault,t[29]=ce):ce=t[29];let le;t[30]!==n.personaSectionIdentity||t[31]!==n.personaSectionIdentityHint||t[32]!==q||t[33]!==oe||t[34]!==se||t[35]!==ce?(le=(0,Q.jsx)(pt,{icon:we,title:n.personaSectionIdentity,subtitle:n.personaSectionIdentityHint,iconLeading:q,iconInteractive:oe,titleAccessory:se,trailing:ce}),t[30]=n.personaSectionIdentity,t[31]=n.personaSectionIdentityHint,t[32]=q,t[33]=oe,t[34]=se,t[35]=ce,t[36]=le):le=t[36];let ue;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(ue=(0,Q.jsx)(Je,{className:i(`fixed inset-0 bg-scrim backdrop-blur-[2px]`,_e)}),t[37]=ue):ue=t[37];let de;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(de=i(`fixed left-1/2 top-1/2 w-[min(calc(100vw-2rem),26rem)] max-h-[min(90dvh,36rem)] -translate-x-1/2 -translate-y-1/2 overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`,ct),t[38]=de):de=t[38];let fe;t[39]===n.avatarPickerTitle?fe=t[40]:(fe=(0,Q.jsx)(Ue,{className:`text-base font-semibold text-fg`,children:n.avatarPickerTitle}),t[39]=n.avatarPickerTitle,t[40]=fe);let pe;t[41]===Symbol.for(`react.memo_cache_sentinel`)?(pe=i(L,`shrink-0 p-1.5 hover:bg-surface-base`),t[41]=pe):pe=t[41];let ge;t[42]===Symbol.for(`react.memo_cache_sentinel`)?(ge=(0,Q.jsx)(T,{className:`size-4`,"aria-hidden":!0}),t[42]=ge):ge=t[42];let ve;t[43]===n.closeDialogAria?ve=t[44]:(ve=(0,Q.jsx)(Ce,{asChild:!0,children:(0,Q.jsx)(`button`,{type:`button`,className:pe,"aria-label":n.closeDialogAria,children:ge})}),t[43]=n.closeDialogAria,t[44]=ve);let ye;t[45]!==fe||t[46]!==ve?(ye=(0,Q.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[fe,ve]}),t[45]=fe,t[46]=ve,t[47]=ye):ye=t[47];let be;t[48]===n.avatarRowHint?be=t[49]:(be=(0,Q.jsx)(He,{className:`sr-only`,children:n.avatarRowHint}),t[48]=n.avatarRowHint,t[49]=be);let xe;t[50]===O?xe=t[51]:(xe=e=>O({avatar:e}),t[50]=O,t[51]=xe);let Se;t[52]!==n||t[53]!==B.avatar||t[54]!==a.id||t[55]!==xe?(Se=(0,Q.jsx)(hn,{agentId:a.id,value:B.avatar,onChange:xe,a:n}),t[52]=n,t[53]=B.avatar,t[54]=a.id,t[55]=xe,t[56]=Se):Se=t[56];let Y;t[57]!==ye||t[58]!==be||t[59]!==Se?(Y=(0,Q.jsxs)(Ae,{children:[ue,(0,Q.jsxs)($e,{className:de,onOpenAutoFocus:_n,children:[ye,be,Se]})]}),t[57]=ye,t[58]=be,t[59]=Se,t[60]=Y):Y=t[60];let Ee;t[61]!==U||t[62]!==M||t[63]!==Y?(Ee=(0,Q.jsx)(he,{open:U,onOpenChange:M,children:Y}),t[61]=U,t[62]=M,t[63]=Y,t[64]=Ee):Ee=t[64];let De;t[65]===n.displayName?De=t[66]:(De=(0,Q.jsx)(`span`,{className:`font-medium text-fg`,children:n.displayName}),t[65]=n.displayName,t[66]=De);let Oe;t[67]!==u||t[68]!==O?(Oe=e=>{u(e.target.value),O({name:e.target.value})},t[67]=u,t[68]=O,t[69]=Oe):Oe=t[69];let ke;t[70]!==n.personaNamePlaceholder||t[71]!==l||t[72]!==Oe?(ke=(0,Q.jsx)(`input`,{className:W,value:l,onChange:Oe,placeholder:n.personaNamePlaceholder,autoComplete:`off`}),t[70]=n.personaNamePlaceholder,t[71]=l,t[72]=Oe,t[73]=ke):ke=t[73];let je;t[74]!==De||t[75]!==ke?(je=(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[De,ke]}),t[74]=De,t[75]=ke,t[76]=je):je=t[76];let Me;t[77]===n.personaEmoji?Me=t[78]:(Me=(0,Q.jsx)(`span`,{className:`font-medium text-fg`,children:n.personaEmoji}),t[77]=n.personaEmoji,t[78]=Me);let Ne;t[79]===O?Ne=t[80]:(Ne=e=>O({emoji:e.target.value}),t[79]=O,t[80]=Ne);let Pe;t[81]!==n.personaEmojiPlaceholder||t[82]!==B.emoji||t[83]!==Ne?(Pe=(0,Q.jsx)(`input`,{className:W,value:B.emoji,onChange:Ne,placeholder:n.personaEmojiPlaceholder,autoComplete:`off`}),t[81]=n.personaEmojiPlaceholder,t[82]=B.emoji,t[83]=Ne,t[84]=Pe):Pe=t[84];let Fe;t[85]!==Me||t[86]!==Pe?(Fe=(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[Me,Pe]}),t[85]=Me,t[86]=Pe,t[87]=Fe):Fe=t[87];let Ie;t[88]===n.agentDescription?Ie=t[89]:(Ie=(0,Q.jsx)(`span`,{className:`font-medium text-fg`,children:n.agentDescription}),t[88]=n.agentDescription,t[89]=Ie);let Le;t[90]===Symbol.for(`react.memo_cache_sentinel`)?(Le=i(W,`min-h-16 resize-y text-sm leading-relaxed`),t[90]=Le):Le=t[90];let Re;t[91]!==f||t[92]!==O?(Re=e=>{f(e.target.value),O({description:e.target.value})},t[91]=f,t[92]=O,t[93]=Re):Re=t[93];let ze;t[94]!==n.agentDescriptionPlaceholder||t[95]!==d||t[96]!==Re?(ze=(0,Q.jsx)(`textarea`,{className:Le,value:d,onChange:Re,placeholder:n.agentDescriptionPlaceholder,maxLength:4e3,rows:3,spellCheck:!0}),t[94]=n.agentDescriptionPlaceholder,t[95]=d,t[96]=Re,t[97]=ze):ze=t[97];let Be;t[98]!==Ie||t[99]!==ze?(Be=(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[Ie,ze]}),t[98]=Ie,t[99]=ze,t[100]=Be):Be=t[100];let X;t[101]===n.personaCreature?X=t[102]:(X=(0,Q.jsx)(`span`,{className:`font-medium text-fg`,children:n.personaCreature}),t[101]=n.personaCreature,t[102]=X);let Ve;t[103]===B.creature?Ve=t[104]:(Ve=me.some(e=>e.value===B.creature)?B.creature:`__custom__`,t[103]=B.creature,t[104]=Ve);let We;t[105]===O?We=t[106]:(We=e=>{if(e.target.value===`__custom__`){O({creature:``});return}O({creature:e.target.value})},t[105]=O,t[106]=We);let Ke;t[107]===K?Ke=t[108]:(Ke=me.map(e=>(0,Q.jsx)(rt,{value:e.value,children:K(e.labelEn,e.labelZh)},e.value)),t[107]=K,t[108]=Ke);let Xe;t[109]===K?Xe=t[110]:(Xe=K(`Custom…`,`自定义…`),t[109]=K,t[110]=Xe);let Ze;t[111]===Xe?Ze=t[112]:(Ze=(0,Q.jsx)(rt,{value:`__custom__`,children:Xe}),t[111]=Xe,t[112]=Ze);let Qe;t[113]!==Ve||t[114]!==We||t[115]!==Ke||t[116]!==Ze?(Qe=(0,Q.jsxs)(Te,{className:W,value:Ve,onChange:We,children:[Ke,Ze]}),t[113]=Ve,t[114]=We,t[115]=Ke,t[116]=Ze,t[117]=Qe):Qe=t[117];let et;t[118]!==n.personaCreaturePlaceholder||t[119]!==B.creature||t[120]!==O?(et=me.some(e=>e.value===B.creature)?null:(0,Q.jsx)(`input`,{className:i(W,`mt-1 text-xs`),value:B.creature,onChange:e=>O({creature:e.target.value}),placeholder:n.personaCreaturePlaceholder,autoComplete:`off`}),t[118]=n.personaCreaturePlaceholder,t[119]=B.creature,t[120]=O,t[121]=et):et=t[121];let tt;t[122]!==X||t[123]!==Qe||t[124]!==et?(tt=(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5 text-sm`,children:[X,Qe,et]}),t[122]=X,t[123]=Qe,t[124]=et,t[125]=tt):tt=t[125];let nt;t[126]!==je||t[127]!==Fe||t[128]!==Be||t[129]!==tt?(nt=(0,Q.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[je,Fe,Be,tt]}),t[126]=je,t[127]=Fe,t[128]=Be,t[129]=tt,t[130]=nt):nt=t[130];let it;t[131]!==Ee||t[132]!==nt||t[133]!==le?(it=(0,Q.jsxs)(mt,{children:[le,Ee,nt]}),t[131]=Ee,t[132]=nt,t[133]=le,t[134]=it):it=t[134];let at;t[135]!==n.editAgent||t[136]!==n.editAgentHint?(at=(0,Q.jsx)(pt,{icon:qe,title:n.editAgent,subtitle:n.editAgentHint}),t[135]=n.editAgent,t[136]=n.editAgentHint,t[137]=at):at=t[137];let ot;t[138]===n.modelPrimary?ot=t[139]:(ot=(0,Q.jsx)(`span`,{className:`font-medium text-fg`,children:n.modelPrimary}),t[138]=n.modelPrimary,t[139]=ot);let st;t[140]===v?st=t[141]:(st=e=>v(e),t[140]=v,t[141]=st);let ut;t[142]!==c||t[143]!==r.modelNoMatches||t[144]!==r.modelPlaceholder||t[145]!==r.modelSearchPlaceholder||t[146]!==g||t[147]!==st?(ut=(0,Q.jsx)(Ge,{className:`min-w-0 flex-1`,value:g,disabled:c,placeholder:r.modelPlaceholder,searchPlaceholder:r.modelSearchPlaceholder,noMatches:r.modelNoMatches,onChange:st}),t[142]=c,t[143]=r.modelNoMatches,t[144]=r.modelPlaceholder,t[145]=r.modelSearchPlaceholder,t[146]=g,t[147]=st,t[148]=ut):ut=t[148];let dt;t[149]!==n.modelClear||t[150]!==c||t[151]!==g||t[152]!==v?(dt=g.trim()?(0,Q.jsx)(h,{type:`button`,variant:`secondary`,className:`shrink-0`,disabled:c,onClick:()=>v(``),children:n.modelClear}):null,t[149]=n.modelClear,t[150]=c,t[151]=g,t[152]=v,t[153]=dt):dt=t[153];let ht;t[154]!==ut||t[155]!==dt?(ht=(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-stretch gap-2`,children:[ut,dt]}),t[154]=ut,t[155]=dt,t[156]=ht):ht=t[156];let gt;t[157]!==ot||t[158]!==ht?(gt=(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[ot,ht]}),t[157]=ot,t[158]=ht,t[159]=gt):gt=t[159];let _t;t[160]===n.workspacePath?_t=t[161]:(_t=(0,Q.jsx)(`span`,{className:`font-medium text-fg`,children:n.workspacePath}),t[160]=n.workspacePath,t[161]=_t);let vt=r.workingDirectory,yt=r.workingDirectory.notSet,bt;t[162]===Symbol.for(`react.memo_cache_sentinel`)?(bt=i(W,`font-mono text-xs`),t[162]=bt):bt=t[162];let xt;t[163]!==c||t[164]!==r.workingDirectory||t[165]!==p||t[166]!==m?(xt=(0,Q.jsx)(Nt,{value:p,onChange:m,disabled:c,wd:vt,placeholder:yt,inputClassName:bt}),t[163]=c,t[164]=r.workingDirectory,t[165]=p,t[166]=m,t[167]=xt):xt=t[167];let St;t[168]!==_t||t[169]!==xt?(St=(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[_t,xt]}),t[168]=_t,t[169]=xt,t[170]=St):St=t[170];let wt;t[171]!==gt||t[172]!==St?(wt=(0,Q.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[gt,St]}),t[171]=gt,t[172]=St,t[173]=wt):wt=t[173];let Tt;t[174]!==n.save||t[175]!==n.tryInChat||t[176]!==c||t[177]!==w||t[178]!==C||t[179]!==F?(Tt=w?null:(0,Q.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(h,{type:`button`,disabled:c,onClick:()=>void C(),children:n.save}),F?(0,Q.jsxs)(h,{type:`button`,variant:`secondary`,disabled:c,onClick:F,children:[(0,Q.jsx)(ie,{className:`mr-1.5 size-4`,"aria-hidden":!0}),n.tryInChat]}):null]}),t[174]=n.save,t[175]=n.tryInChat,t[176]=c,t[177]=w,t[178]=C,t[179]=F,t[180]=Tt):Tt=t[180];let Et;t[181]!==at||t[182]!==wt||t[183]!==Tt?(Et=(0,Q.jsxs)(mt,{children:[at,wt,Tt]}),t[181]=at,t[182]=wt,t[183]=Tt,t[184]=Et):Et=t[184];let Dt;t[185]!==n.loading||t[186]!==n.personaSectionSoul||t[187]!==n.personaSectionSoulHint||t[188]!==n.personaSoulCustomEdit||t[189]!==n.personaSoulEdit||t[190]!==n.personaSoulPreview||t[191]!==n.personaSoulTemplate||t[192]!==A||t[193]!==k||t[194]!==R||t[195]!==K||t[196]!==E||t[197]!==te||t[198]!==ne||t[199]!==H||t[200]!==ee||t[201]!==P?(Dt=E?(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.loading}):(0,Q.jsxs)(mt,{children:[(0,Q.jsx)(pt,{icon:j,title:n.personaSectionSoul,subtitle:n.personaSectionSoulHint}),(0,Q.jsxs)(`div`,{className:`mb-4 flex flex-col gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:n.personaSoulTemplate}),(0,Q.jsx)(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-4`,children:lt.map(e=>(0,Q.jsxs)(`button`,{type:`button`,className:i(`flex flex-col items-center gap-1.5 rounded-xl border-2 p-3 text-center transition-all`,V.pressCard,ee===e.id?`border-accent bg-accent-soft/40 shadow-sm`:`border-edge hover:border-accent/40 hover:bg-surface-hover`),onClick:()=>k(e.id),children:[(0,Q.jsx)(`span`,{className:`text-xl`,children:e.emoji}),(0,Q.jsx)(`span`,{className:`text-xs font-medium text-fg`,children:K(e.labelEn,e.labelZh)})]},e.id))})]}),ee===`custom`?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:n.personaSoulCustomEdit}),(0,Q.jsx)(`button`,{type:`button`,className:i(L,`inline-flex size-9 shrink-0 items-center justify-center rounded-md p-0 hover:bg-surface-hover`),title:H?n.personaSoulEdit:n.personaSoulPreview,"aria-label":H?n.personaSoulEdit:n.personaSoulPreview,onClick:P,children:H?(0,Q.jsx)(_,{className:`size-4`,"aria-hidden":!0}):(0,Q.jsx)(ae,{className:`size-4`,"aria-hidden":!0})})]}),(0,Q.jsx)(`div`,{className:i(W,`flex min-h-64 flex-col overflow-hidden p-0`),children:H?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 py-3`,children:(0,Q.jsx)(N,{content:te})}):(0,Q.jsx)(ft,{initialContent:te,onChange:A,isDark:R,className:`min-h-0 flex-1`},`soul-${ne}`)})]}):null]}),t[185]=n.loading,t[186]=n.personaSectionSoul,t[187]=n.personaSectionSoulHint,t[188]=n.personaSoulCustomEdit,t[189]=n.personaSoulEdit,t[190]=n.personaSoulPreview,t[191]=n.personaSoulTemplate,t[192]=A,t[193]=k,t[194]=R,t[195]=K,t[196]=E,t[197]=te,t[198]=ne,t[199]=H,t[200]=ee,t[201]=P,t[202]=Dt):Dt=t[202];let Ot;return t[203]!==it||t[204]!==Et||t[205]!==Dt?(Ot=(0,Q.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[it,Et,Dt]}),t[203]=it,t[204]=Et,t[205]=Dt,t[206]=Ot):Ot=t[206],Ot}function _n(e){return e.preventDefault()}function vn(e){return e.resolved===`dark`}function yn(e){return e.language}function bn(e){let t=(0,Z.c)(13),{label:n,value:r,badge:i,mono:a}=e,o;t[0]===n?o=t[1]:(o=(0,Q.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:n}),t[0]=n,t[1]=o);let s;t[2]===i?s=t[3]:(s=(0,Q.jsx)(`span`,{className:`shrink-0 rounded-full bg-surface-hover px-2 py-0.5 text-xs font-medium text-fg-muted`,children:i}),t[2]=i,t[3]=s);let c;t[4]!==o||t[5]!==s?(c=(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[o,s]}),t[4]=o,t[5]=s,t[6]=c):c=t[6];let l=a?`mt-2 truncate font-mono text-xs text-fg`:`mt-2 truncate text-sm font-medium text-fg`,u;t[7]!==l||t[8]!==r?(u=(0,Q.jsx)(`p`,{className:l,children:r}),t[7]=l,t[8]=r,t[9]=u):u=t[9];let d;return t[10]!==c||t[11]!==u?(d=(0,Q.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel px-4 py-3`,children:[c,u]}),t[10]=c,t[11]=u,t[12]=d):d=t[12],d}function xn(e){let t=(0,Z.c)(12),{icon:n,label:r,value:i}=e,a;t[0]===n?a=t[1]:(a=(0,Q.jsx)(`div`,{className:`flex size-9 shrink-0 items-center justify-center rounded-lg bg-surface-hover text-fg-muted`,children:(0,Q.jsx)(n,{className:`size-4`,strokeWidth:1.8,"aria-hidden":!0})}),t[0]=n,t[1]=a);let o;t[2]===r?o=t[3]:(o=(0,Q.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:r}),t[2]=r,t[3]=o);let s;t[4]===i?s=t[5]:(s=(0,Q.jsx)(`p`,{className:`mt-1 truncate text-sm font-medium text-fg`,children:i}),t[4]=i,t[5]=s);let c;t[6]!==o||t[7]!==s?(c=(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[o,s]}),t[6]=o,t[7]=s,t[8]=c):c=t[8];let l;return t[9]!==a||t[10]!==c?(l=(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 rounded-xl border border-edge-subtle bg-surface-panel px-4 py-3`,children:[a,c]}),t[9]=a,t[10]=c,t[11]=l):l=t[11],l}function Sn(e){let t=(0,Z.c)(121),{a:n,selected:r,defaultModel:i,defaultWorkspace:a,isTuiDefault:o,isTuiDefaultInherited:s,busy:c,onSetDefault:l,onSetTuiDefault:u,onTryInChat:d}=e,f;t[0]!==n||t[1]!==r?(f=F(r,n),t[0]=n,t[1]=r,t[2]=f):f=t[2];let p=f,m;t[3]!==n||t[4]!==r?(m=Ne(r,n)||n.listNoDescription,t[3]=n,t[4]=r,t[5]=m):m=t[5];let g=m,_;t[6]!==n.listUnsetValue||t[7]!==i||t[8]!==r.model?.primary?(_=r.model?.primary?.trim()||i||n.listUnsetValue,t[6]=n.listUnsetValue,t[7]=i,t[8]=r.model?.primary,t[9]=_):_=t[9];let v=_,y;t[10]!==n.listUnsetValue||t[11]!==a||t[12]!==r.workspace?(y=r.workspace?.trim()||a||n.listUnsetValue,t[10]=n.listUnsetValue,t[11]=a,t[12]=r.workspace,t[13]=y):y=t[13];let b=y,x=r.model?.primary?.trim()?n.inheritance.badgeOverride:n.inheritance.badgeInherit,S=r.workspace?.trim()&&r.workspace.trim()!==a.trim()?n.inheritance.badgeOverride:n.inheritance.badgeInherit,C=r.tools.effectiveDisable.length,w=r.skills.effectiveAllowlist?.length,T;t[14]!==r.avatar||t[15]!==r.id?(T=(0,Q.jsx)(`div`,{className:`flex size-14 shrink-0 items-center justify-center overflow-hidden rounded-2xl bg-surface-base ring-1 ring-edge-subtle/50`,children:(0,Q.jsx)(Ye,{agentId:r.id,avatar:r.avatar,size:56,className:`size-full`})}),t[14]=r.avatar,t[15]=r.id,t[16]=T):T=t[16];let E;t[17]===p?E=t[18]:(E=(0,Q.jsx)(`h2`,{className:`truncate text-lg font-semibold text-fg`,children:p}),t[17]=p,t[18]=E);let D;t[19]!==n.globalDefaultBadge||t[20]!==r.isDefault?(D=r.isDefault?(0,Q.jsx)(`span`,{className:`rounded-full bg-accent-soft px-2 py-0.5 text-xs font-medium text-accent`,children:n.globalDefaultBadge}):null,t[19]=n.globalDefaultBadge,t[20]=r.isDefault,t[21]=D):D=t[21];let O;t[22]!==n.tuiDefaultBadge||t[23]!==n.tuiDefaultInheritedBadge||t[24]!==o||t[25]!==s?(O=o?(0,Q.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-xs font-medium text-fg`,children:s?n.tuiDefaultInheritedBadge:n.tuiDefaultBadge}):null,t[22]=n.tuiDefaultBadge,t[23]=n.tuiDefaultInheritedBadge,t[24]=o,t[25]=s,t[26]=O):O=t[26];let k;t[27]!==E||t[28]!==D||t[29]!==O?(k=(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[E,D,O]}),t[27]=E,t[28]=D,t[29]=O,t[30]=k):k=t[30];let A;t[31]===r.id?A=t[32]:(A=(0,Q.jsx)(`p`,{className:`mt-1 truncate font-mono text-xs text-fg-muted`,children:r.id}),t[31]=r.id,t[32]=A);let j;t[33]!==A||t[34]!==k?(j=(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[k,A]}),t[33]=A,t[34]=k,t[35]=j):j=t[35];let M;t[36]!==j||t[37]!==T?(M=(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-start gap-4`,children:[T,j]}),t[36]=j,t[37]=T,t[38]=M):M=t[38];let N;t[39]!==n.tryInChat||t[40]!==c||t[41]!==d?(N=d?(0,Q.jsxs)(h,{type:`button`,disabled:c,onClick:d,children:[(0,Q.jsx)(ie,{className:`size-4`,"aria-hidden":!0}),n.tryInChat]}):null,t[39]=n.tryInChat,t[40]=c,t[41]=d,t[42]=N):N=t[42];let P;t[43]!==n.setDefault||t[44]!==c||t[45]!==l||t[46]!==r.isDefault?(P=r.isDefault?null:(0,Q.jsx)(h,{type:`button`,variant:`secondary`,disabled:c,onClick:l,children:n.setDefault}),t[43]=n.setDefault,t[44]=c,t[45]=l,t[46]=r.isDefault,t[47]=P):P=t[47];let I;t[48]!==n.setTuiDefault||t[49]!==c||t[50]!==o||t[51]!==u?(I=o?null:(0,Q.jsx)(h,{type:`button`,variant:`secondary`,disabled:c,onClick:u,children:n.setTuiDefault}),t[48]=n.setTuiDefault,t[49]=c,t[50]=o,t[51]=u,t[52]=I):I=t[52];let L;t[53]!==N||t[54]!==P||t[55]!==I?(L=(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-2`,children:[N,P,I]}),t[53]=N,t[54]=P,t[55]=I,t[56]=L):L=t[56];let R;t[57]!==M||t[58]!==L?(R=(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between`,children:[M,L]}),t[57]=M,t[58]=L,t[59]=R):R=t[59];let z;t[60]===g?z=t[61]:(z=(0,Q.jsx)(`p`,{className:`w-full text-sm leading-6 text-fg-muted`,children:g}),t[60]=g,t[61]=z);let B;t[62]!==R||t[63]!==z?(B=(0,Q.jsx)(mt,{children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[R,z]})}),t[62]=R,t[63]=z,t[64]=B):B=t[64];let ee;t[65]!==n.overviewRuntimeHint||t[66]!==n.overviewRuntimeTitle?(ee=(0,Q.jsx)(pt,{icon:we,title:n.overviewRuntimeTitle,subtitle:n.overviewRuntimeHint}),t[65]=n.overviewRuntimeHint,t[66]=n.overviewRuntimeTitle,t[67]=ee):ee=t[67];let V;t[68]!==n.modelPrimary||t[69]!==x||t[70]!==v?(V=(0,Q.jsx)(bn,{label:n.modelPrimary,value:v,badge:x,mono:!0}),t[68]=n.modelPrimary,t[69]=x,t[70]=v,t[71]=V):V=t[71];let te;t[72]!==n.workspacePath||t[73]!==S||t[74]!==b?(te=(0,Q.jsx)(bn,{label:n.workspacePath,value:b,badge:S,mono:!0}),t[72]=n.workspacePath,t[73]=S,t[74]=b,t[75]=te):te=t[75];let ne;t[76]!==V||t[77]!==te?(ne=(0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[V,te]}),t[76]=V,t[77]=te,t[78]=ne):ne=t[78];let H;t[79]!==ee||t[80]!==ne?(H=(0,Q.jsxs)(mt,{children:[ee,ne]}),t[79]=ee,t[80]=ne,t[81]=H):H=t[81];let U;t[82]!==n.overviewCapabilitiesHint||t[83]!==n.overviewCapabilitiesTitle?(U=(0,Q.jsx)(pt,{icon:it,title:n.overviewCapabilitiesTitle,subtitle:n.overviewCapabilitiesHint}),t[82]=n.overviewCapabilitiesHint,t[83]=n.overviewCapabilitiesTitle,t[84]=U):U=t[84];let re;t[85]!==n.listToolsAllEnabled||t[86]!==n.listToolsDisabledCount||t[87]!==C?(re=C>0?n.listToolsDisabledCount.replace(`{{count}}`,String(C)):n.listToolsAllEnabled,t[85]=n.listToolsAllEnabled,t[86]=n.listToolsDisabledCount,t[87]=C,t[88]=re):re=t[88];let W;t[89]!==n.listToolsLabel||t[90]!==re?(W=(0,Q.jsx)(xn,{icon:le,label:n.listToolsLabel,value:re}),t[89]=n.listToolsLabel,t[90]=re,t[91]=W):W=t[91];let G;t[92]!==n.listInheritedValue||t[93]!==n.listSkillsCount||t[94]!==w?(G=w?n.listSkillsCount.replace(`{{count}}`,String(w)):n.listInheritedValue,t[92]=n.listInheritedValue,t[93]=n.listSkillsCount,t[94]=w,t[95]=G):G=t[95];let ae;t[96]!==n.listSkillsLabel||t[97]!==G?(ae=(0,Q.jsx)(xn,{icon:we,label:n.listSkillsLabel,value:G}),t[96]=n.listSkillsLabel,t[97]=G,t[98]=ae):ae=t[98];let K;t[99]!==n.memoryTitle||t[100]!==n.overviewMemoryManaged?(K=(0,Q.jsx)(xn,{icon:Ee,label:n.memoryTitle,value:n.overviewMemoryManaged}),t[99]=n.memoryTitle,t[100]=n.overviewMemoryManaged,t[101]=K):K=t[101];let q;t[102]!==n.connectionsTitle||t[103]!==n.overviewConnectionsManaged?(q=(0,Q.jsx)(xn,{icon:Oe,label:n.connectionsTitle,value:n.overviewConnectionsManaged}),t[102]=n.connectionsTitle,t[103]=n.overviewConnectionsManaged,t[104]=q):q=t[104];let J;t[105]!==n.listWorkspaceLabel||t[106]!==b?(J=(0,Q.jsx)(xn,{icon:Fe,label:n.listWorkspaceLabel,value:b}),t[105]=n.listWorkspaceLabel,t[106]=b,t[107]=J):J=t[107];let oe;t[108]!==W||t[109]!==ae||t[110]!==K||t[111]!==q||t[112]!==J?(oe=(0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[W,ae,K,q,J]}),t[108]=W,t[109]=ae,t[110]=K,t[111]=q,t[112]=J,t[113]=oe):oe=t[113];let se;t[114]!==U||t[115]!==oe?(se=(0,Q.jsxs)(mt,{children:[U,oe]}),t[114]=U,t[115]=oe,t[116]=se):se=t[116];let ce;return t[117]!==B||t[118]!==H||t[119]!==se?(ce=(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-5 overflow-y-auto`,children:[B,H,se]}),t[117]=B,t[118]=H,t[119]=se,t[120]=ce):ce=t[120],ce}function Cn(e){let t=(0,Z.c)(66),{a:n,selected:r,busy:a,skillsCatalogLoading:o,catalogForPick:s,skillsInherit:c,setSkillsInherit:l,skillsPick:u,setSkillsPick:d,onSaveSkills:f,hideInlineSave:p}=e,m;t[0]===r.skills.effectiveAllowlist?m=t[1]:(m=function(e){let t=r.skills.effectiveAllowlist;return t===void 0?!0:t.length===0?!1:t.includes(e)},t[0]=r.skills.effectiveAllowlist,t[1]=m);let g=m,_;t[2]!==s||t[3]!==r.skills.effectiveAllowlist?(_=function(){let e=r.skills.effectiveAllowlist;return e===void 0?new Set(s.map(wn)):new Set(e)},t[2]=s,t[3]=r.skills.effectiveAllowlist,t[4]=_):_=t[4];let v=_,y;t[5]!==n.skillsHint||t[6]!==n.skillsTitle?(y=(0,Q.jsx)(pt,{className:`shrink-0`,icon:ve,title:n.skillsTitle,subtitle:n.skillsHint}),t[5]=n.skillsHint,t[6]=n.skillsTitle,t[7]=y):y=t[7];let b;t[8]===l?b=t[9]:(b=()=>l(!0),t[8]=l,t[9]=b);let x;t[10]!==n.skillsInherit||t[11]!==a||t[12]!==b?(x=(0,Q.jsx)(h,{type:`button`,variant:`secondary`,disabled:a,onClick:b,children:n.skillsInherit}),t[10]=n.skillsInherit,t[11]=a,t[12]=b,t[13]=x):x=t[13];let S;t[14]!==v||t[15]!==l||t[16]!==d?(S=()=>{l(!1),d(v())},t[14]=v,t[15]=l,t[16]=d,t[17]=S):S=t[17];let C;t[18]!==n.skillsCustomize||t[19]!==a||t[20]!==S?(C=(0,Q.jsx)(h,{type:`button`,variant:`secondary`,disabled:a,onClick:S,children:n.skillsCustomize}),t[18]=n.skillsCustomize,t[19]=a,t[20]=S,t[21]=C):C=t[21];let w;t[22]!==x||t[23]!==C?(w=(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[x,C]}),t[22]=x,t[23]=C,t[24]=w):w=t[24];let T;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(T=Y(`skills`),t[25]=T):T=t[25];let E;t[26]===n.skillsLibraryLink?E=t[27]:(E=(0,Q.jsx)(Me,{to:T,className:`shrink-0 text-xs font-medium text-accent-fg hover:underline`,children:n.skillsLibraryLink}),t[26]=n.skillsLibraryLink,t[27]=E);let D;t[28]!==w||t[29]!==E?(D=(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-between gap-3`,children:[w,E]}),t[28]=w,t[29]=E,t[30]=D):D=t[30];let O;t[31]===r.skills.preset?O=t[32]:(O=r.skills.preset.length?r.skills.preset.join(`, `):`—`,t[31]=r.skills.preset,t[32]=O);let k;t[33]!==n.skillsPresetLabel||t[34]!==O?(k=(0,Q.jsxs)(`p`,{className:`mt-2 shrink-0 text-xs text-fg-muted`,children:[n.skillsPresetLabel,` `,O]}),t[33]=n.skillsPresetLabel,t[34]=O,t[35]=k):k=t[35];let A;t[36]!==n.skillsInherit||t[37]!==r.skills.effectiveAllowlist||t[38]!==c?(A=r.skills.effectiveAllowlist?.length?r.skills.effectiveAllowlist.join(`, `):c?n.skillsInherit:`—`,t[36]=n.skillsInherit,t[37]=r.skills.effectiveAllowlist,t[38]=c,t[39]=A):A=t[39];let j;t[40]!==n.skillsEffectiveLabel||t[41]!==A?(j=(0,Q.jsxs)(`p`,{className:`shrink-0 text-xs text-fg-muted`,children:[n.skillsEffectiveLabel,` `,A]}),t[40]=n.skillsEffectiveLabel,t[41]=A,t[42]=j):j=t[42];let M;t[43]!==n.skillsCatalogLoading||t[44]!==n.skillsEmptyCatalog||t[45]!==n.skillsNoDescription||t[46]!==a||t[47]!==s||t[48]!==g||t[49]!==d||t[50]!==o||t[51]!==c||t[52]!==u?(M=o?(0,Q.jsx)(`p`,{className:`shrink-0 text-sm text-fg-muted`,children:n.skillsCatalogLoading}):s.length===0?(0,Q.jsx)(`p`,{className:`shrink-0 text-sm text-fg-muted`,children:n.skillsEmptyCatalog}):(0,Q.jsx)(`div`,{className:i(`mt-3 min-h-0 flex-1 overflow-y-auto overscroll-contain pr-0.5`,c&&`opacity-50`),children:(0,Q.jsx)(`ul`,{className:`flex flex-col gap-2.5 text-sm`,children:s.map(e=>{let t=e.name||e.directoryId,r=c?g(t):u.has(t),o=typeof e.description==`string`?e.description.trim():``,s=o||n.skillsNoDescription;return(0,Q.jsx)(`li`,{className:`h-16 shrink-0 overflow-hidden rounded-xl border border-edge-subtle bg-surface-panel/60 px-3 dark:border-edge-subtle`,children:(0,Q.jsxs)(`label`,{className:`flex h-full cursor-pointer items-center gap-3 text-sm`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,className:`shrink-0 rounded border-edge`,checked:r,disabled:c||a,onChange:()=>{d(e=>{let n=new Set(e);return r?n.delete(t):n.add(t),n})},"aria-label":t}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1 overflow-hidden`,children:[(0,Q.jsx)(`div`,{className:`truncate font-mono text-xs font-medium text-fg`,title:t,children:t}),(0,Q.jsx)(`p`,{className:i(`mt-0.5 truncate text-xs leading-tight text-fg-muted`,!o&&`italic text-fg-subtle`),title:s,children:s})]})]})},t)})})}),t[43]=n.skillsCatalogLoading,t[44]=n.skillsEmptyCatalog,t[45]=n.skillsNoDescription,t[46]=a,t[47]=s,t[48]=g,t[49]=d,t[50]=o,t[51]=c,t[52]=u,t[53]=M):M=t[53];let N;t[54]!==n.skillsSave||t[55]!==a||t[56]!==p||t[57]!==f?(N=p?null:(0,Q.jsx)(`div`,{className:`mt-4 shrink-0`,children:(0,Q.jsx)(h,{type:`button`,disabled:a,onClick:()=>void f(),children:n.skillsSave})}),t[54]=n.skillsSave,t[55]=a,t[56]=p,t[57]=f,t[58]=N):N=t[58];let P;return t[59]!==D||t[60]!==k||t[61]!==j||t[62]!==M||t[63]!==N||t[64]!==y?(P=(0,Q.jsxs)(mt,{className:`flex min-h-0 flex-1 flex-col`,children:[y,D,k,j,M,N]}),t[59]=D,t[60]=k,t[61]=j,t[62]=M,t[63]=N,t[64]=y,t[65]=P):P=t[65],P}function wn(e){return e.name||e.directoryId}var Tn=[`write_file`,`edit_file`,`shell`],En=[`shell`,`image_generate`,`extensions`],Dn=[`send_message`,`send_media`];function On(e){let t=(0,Z.c)(88),{mode:n,builtinToolIds:r,loading:a,disableSet:o,onDisableSetChange:s,defaultsDisableSet:c,unknownDisabledIds:l,getToolDescription:u,getGroupTitle:d,labels:f,quickActionsDisabled:p}=e,m;t[0]===l?m=t[1]:(m=l===void 0?[]:l,t[0]=l,t[1]=m);let g=m,_=p===void 0?!1:p,v;t[2]===r?v=t[3]:(v=new Set(r),t[2]=r,t[3]=v);let y=v,b;t[4]===c?b=t[5]:(b=c??new Set,t[4]=c,t[5]=b);let x=b,S;t[6]!==x||t[7]!==o||t[8]!==n||t[9]!==s?(S=(e,t)=>{if(n===`agentEntry`&&t&&x.has(e))return;let r=new Set(o);t?r.delete(e):r.add(e),s(r)},t[6]=x,t[7]=o,t[8]=n,t[9]=s,t[10]=S):S=t[10];let C=S,w;t[11]!==y||t[12]!==s?(w=e=>{let t=new Set;for(let n of e)y.has(n)&&t.add(n);s(t)},t[11]=y,t[12]=s,t[13]=w):w=t[13];let T=w,E;t[14]===s?E=t[15]:(E=()=>{s(new Set)},t[14]=s,t[15]=E);let D=E,O;t[16]!==r||t[17]!==s||t[18]!==g?(O=()=>{s(new Set([...r,...g]))},t[16]=r,t[17]=s,t[18]=g,t[19]=O):O=t[19];let k=O,A;t[20]===r?A=t[21]:(A=At(r),t[20]=r,t[21]=A);let j=A,M;if(t[22]!==y||t[23]!==j||t[24]!==n||t[25]!==g){if(M=[],n===`defaults`&&g.length>0){let e;t[27]===g?e=t[28]:(e=g.toSorted(An),t[27]=g,t[28]=e);let n;t[29]===e?n=t[30]:(n={key:`unknown`,ids:e},t[29]=e,t[30]=n),M.push(n)}for(let e of kt){let t=e.toolIds.filter(e=>y.has(e));t.length>0&&M.push({key:e.key,ids:[...t]})}if(j.length>0){let e;t[31]===j?e=t[32]:(e={key:`misc`,ids:j},t[31]=j,t[32]=e),M.push(e)}t[22]=y,t[23]=j,t[24]=n,t[25]=g,t[26]=M}else M=t[26];let N=M,P=N.some(kn),F=_||a,I;t[33]===f.quickActionsLabel?I=t[34]:(I=(0,Q.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:f.quickActionsLabel}),t[33]=f.quickActionsLabel,t[34]=I);let L=F||r.length===0&&g.length===0,R;t[35]!==D||t[36]!==f.quickEnableAll||t[37]!==L?(R=(0,Q.jsx)(h,{type:`button`,variant:`secondary`,className:Dt,disabled:L,onClick:D,children:f.quickEnableAll}),t[35]=D,t[36]=f.quickEnableAll,t[37]=L,t[38]=R):R=t[38];let z=F||r.length===0&&g.length===0,B;t[39]!==k||t[40]!==f.quickDisableAll||t[41]!==z?(B=(0,Q.jsx)(h,{type:`button`,variant:`secondary`,className:Dt,disabled:z,onClick:k,children:f.quickDisableAll}),t[39]=k,t[40]=f.quickDisableAll,t[41]=z,t[42]=B):B=t[42];let ee=F||r.length===0,V;t[43]===T?V=t[44]:(V=()=>T(Tn),t[43]=T,t[44]=V);let te;t[45]!==f.quickReadOnlyWorkspace||t[46]!==ee||t[47]!==V?(te=(0,Q.jsx)(h,{type:`button`,variant:`secondary`,className:Dt,disabled:ee,onClick:V,children:f.quickReadOnlyWorkspace}),t[45]=f.quickReadOnlyWorkspace,t[46]=ee,t[47]=V,t[48]=te):te=t[48];let ne=F||r.length===0,H;t[49]===T?H=t[50]:(H=()=>T(En),t[49]=T,t[50]=H);let U;t[51]!==f.quickHighRiskOff||t[52]!==ne||t[53]!==H?(U=(0,Q.jsx)(h,{type:`button`,variant:`secondary`,className:Dt,disabled:ne,onClick:H,children:f.quickHighRiskOff}),t[51]=f.quickHighRiskOff,t[52]=ne,t[53]=H,t[54]=U):U=t[54];let re=F||r.length===0,ie;t[55]===T?ie=t[56]:(ie=()=>T(Dn),t[55]=T,t[56]=ie);let W;t[57]!==f.quickNoOutbound||t[58]!==re||t[59]!==ie?(W=(0,Q.jsx)(h,{type:`button`,variant:`secondary`,className:Dt,disabled:re,onClick:ie,children:f.quickNoOutbound}),t[57]=f.quickNoOutbound,t[58]=re,t[59]=ie,t[60]=W):W=t[60];let G;t[61]!==R||t[62]!==B||t[63]!==te||t[64]!==U||t[65]!==W?(G=(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[R,B,te,U,W]}),t[61]=R,t[62]=B,t[63]=te,t[64]=U,t[65]=W,t[66]=G):G=t[66];let ae;t[67]!==I||t[68]!==G?(ae=(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[I,G]}),t[67]=I,t[68]=G,t[69]=ae):ae=t[69];let K;t[70]!==x||t[71]!==o||t[72]!==d||t[73]!==u||t[74]!==N||t[75]!==P||t[76]!==f.emptyBuiltin||t[77]!==f.loadingBuiltin||t[78]!==f.lockedByDefaults||t[79]!==f.notInBuiltin||t[80]!==a||t[81]!==n||t[82]!==F||t[83]!==C?(K=a?(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:f.loadingBuiltin}):P?(0,Q.jsx)(`div`,{className:`max-h-[min(50vh,22rem)] overflow-y-auto overscroll-contain pr-0.5`,children:(0,Q.jsx)(`div`,{className:`flex flex-col gap-5 pr-1`,children:N.map(e=>{let{key:t,ids:r}=e;return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-fg-muted`,children:d(t)}),(0,Q.jsx)(`ul`,{className:`flex flex-col gap-2.5`,children:r.map(e=>{let r=n===`defaults`&&t===`unknown`,a=n===`agentEntry`&&x.has(e),s=o.has(e),c=a?!1:!s,l=u(e);return(0,Q.jsx)(`li`,{className:i(`rounded-xl border border-edge-subtle bg-surface-panel/60 px-3 py-2.5 dark:border-edge-subtle`,r&&`border-dashed`,a&&`opacity-60`),children:(0,Q.jsxs)(`label`,{className:i(`flex gap-3 text-sm`,a?`cursor-not-allowed`:`cursor-pointer`),children:[(0,Q.jsx)(`input`,{type:`checkbox`,className:`mt-1 shrink-0 rounded border-edge`,checked:c,disabled:a||F,onChange:()=>C(e,!c)}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5`,children:[(0,Q.jsx)(`span`,{className:`font-mono text-xs font-medium text-fg`,children:e}),r?(0,Q.jsxs)(`span`,{className:`text-xs text-fg-muted`,children:[`(`,f.notInBuiltin,`)`]}):null,a?(0,Q.jsxs)(`span`,{className:`text-xs text-fg-muted`,children:[`(`,f.lockedByDefaults,`)`]}):null]}),l?(0,Q.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:l}):null]})]})},e)})})]},t)})})}):(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:f.emptyBuiltin}),t[70]=x,t[71]=o,t[72]=d,t[73]=u,t[74]=N,t[75]=P,t[76]=f.emptyBuiltin,t[77]=f.loadingBuiltin,t[78]=f.lockedByDefaults,t[79]=f.notInBuiltin,t[80]=a,t[81]=n,t[82]=F,t[83]=C,t[84]=K):K=t[84];let q;return t[85]!==ae||t[86]!==K?(q=(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[ae,K]}),t[85]=ae,t[86]=K,t[87]=q):q=t[87],q}function kn(e){return e.ids.length>0}function An(e,t){return e.localeCompare(t)}function jn(e){let t=(0,Z.c)(51),{a:n,data:r,selected:i,busy:s,toolEntryDisable:c,setToolEntryDisable:l,onSaveTools:u,onClearToolsEntry:d,hideInlineSave:f}=e,p=o(Nn),m;t[0]===p?m=t[1]:(m=a(p),t[0]=p,t[1]=m);let g=m.agentSettings.advanced,_;t[2]===i.tools.presetDenied?_=t[3]:(_=new Set(i.tools.presetDenied.flatMap(Mn)),t[2]=i.tools.presetDenied,t[3]=_);let v=_,y;t[4]===l?y=t[5]:(y=e=>{l(e)},t[4]=l,t[5]=y);let b=y,x=n.toolsDisableGroups,S;t[6]===x?S=t[7]:(S=e=>x[e],t[6]=x,t[7]=S);let C=S,w;t[8]===n.toolDescriptions?w=t[9]:(w=e=>e in n.toolDescriptions?n.toolDescriptions[e]:``,t[8]=n.toolDescriptions,t[9]=w);let T=w,E;t[10]!==n.toolsHint||t[11]!==n.toolsTitle?(E=(0,Q.jsx)(pt,{className:`shrink-0`,icon:le,title:n.toolsTitle,subtitle:n.toolsHint}),t[10]=n.toolsHint,t[11]=n.toolsTitle,t[12]=E):E=t[12];let D;t[13]!==n.toolsLockedByPreset||t[14]!==g.toolsDisableEmptyBuiltin||t[15]!==g.toolsDisableLoadingBuiltin||t[16]!==g.toolsDisableNotInBuiltin||t[17]!==g.toolsDisableQuickActionsLabel||t[18]!==g.toolsDisableQuickDisableAll||t[19]!==g.toolsDisableQuickEnableAll||t[20]!==g.toolsDisableQuickHighRiskOff||t[21]!==g.toolsDisableQuickNoOutbound||t[22]!==g.toolsDisableQuickReadOnlyWorkspace?(D={loadingBuiltin:g.toolsDisableLoadingBuiltin,emptyBuiltin:g.toolsDisableEmptyBuiltin,quickActionsLabel:g.toolsDisableQuickActionsLabel,quickEnableAll:g.toolsDisableQuickEnableAll,quickDisableAll:g.toolsDisableQuickDisableAll,quickReadOnlyWorkspace:g.toolsDisableQuickReadOnlyWorkspace,quickHighRiskOff:g.toolsDisableQuickHighRiskOff,quickNoOutbound:g.toolsDisableQuickNoOutbound,notInBuiltin:g.toolsDisableNotInBuiltin,lockedByDefaults:n.toolsLockedByPreset},t[13]=n.toolsLockedByPreset,t[14]=g.toolsDisableEmptyBuiltin,t[15]=g.toolsDisableLoadingBuiltin,t[16]=g.toolsDisableNotInBuiltin,t[17]=g.toolsDisableQuickActionsLabel,t[18]=g.toolsDisableQuickDisableAll,t[19]=g.toolsDisableQuickEnableAll,t[20]=g.toolsDisableQuickHighRiskOff,t[21]=g.toolsDisableQuickNoOutbound,t[22]=g.toolsDisableQuickReadOnlyWorkspace,t[23]=D):D=t[23];let O;t[24]!==s||t[25]!==r.builtinToolIds||t[26]!==C||t[27]!==T||t[28]!==b||t[29]!==v||t[30]!==D||t[31]!==c?(O=(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,children:(0,Q.jsx)(On,{mode:`agentEntry`,builtinToolIds:r.builtinToolIds,loading:!1,disableSet:c,onDisableSetChange:b,defaultsDisableSet:v,getToolDescription:T,getGroupTitle:C,quickActionsDisabled:s,labels:D})}),t[24]=s,t[25]=r.builtinToolIds,t[26]=C,t[27]=T,t[28]=b,t[29]=v,t[30]=D,t[31]=c,t[32]=O):O=t[32];let k;t[33]!==n.toolsSave||t[34]!==s||t[35]!==f||t[36]!==u?(k=f?null:(0,Q.jsx)(h,{type:`button`,disabled:s,onClick:()=>void u(),children:n.toolsSave}),t[33]=n.toolsSave,t[34]=s,t[35]=f,t[36]=u,t[37]=k):k=t[37];let A;t[38]===d?A=t[39]:(A=()=>void d(),t[38]=d,t[39]=A);let j;t[40]!==n.toolsClearEntry||t[41]!==s||t[42]!==A?(j=(0,Q.jsx)(h,{type:`button`,variant:`secondary`,disabled:s,onClick:A,children:n.toolsClearEntry}),t[40]=n.toolsClearEntry,t[41]=s,t[42]=A,t[43]=j):j=t[43];let M;t[44]!==j||t[45]!==k?(M=(0,Q.jsxs)(`div`,{className:`mt-4 flex shrink-0 flex-wrap gap-2`,children:[k,j]}),t[44]=j,t[45]=k,t[46]=M):M=t[46];let N;return t[47]!==M||t[48]!==E||t[49]!==O?(N=(0,Q.jsxs)(mt,{className:`flex min-h-0 flex-1 flex-col`,children:[E,O,M]}),t[47]=M,t[48]=E,t[49]=O,t[50]=N):N=t[50],N}function Mn(e){let t=String(e).trim();return t?[t]:[]}function Nn(e){return e.language}function Pn(e){let t=(0,Z.c)(128),{a:n,chat:r,cCron:i,selected:a,panel:o,data:s,busy:c,editName:l,setEditName:u,editDescription:d,setEditDescription:f,editWorkspace:p,setEditWorkspace:m,editModel:h,setEditModel:g,defaultModel:_,defaultWorkspace:v,onSetDefault:y,onSetTuiDefault:b,isTuiDefault:x,isTuiDefaultInherited:S,onSaveAgentEdits:C,onDelete:w,capabilityPresets:T,defaultPresetId:E,onUpdateAgentExtends:D,onOpenCapabilityPreset:O,overviewProfile:k,filesLoading:A,files:j,activeFile:M,setActiveFile:N,filesViewMode:P,setFilesViewMode:F,fileDraft:I,setFileDraft:L,fileSaving:R,profileFileLoading:z,profileEditorNonce:B,toolEntryDisable:ee,setToolEntryDisable:V,onSaveTools:te,onClearToolsEntry:ne,modelRows:H,setModelRows:U,onSaveModels:re,onClearModelsEntry:ie,skillsCatalogLoading:W,catalogForPick:G,skillsInherit:ae,setSkillsInherit:K,skillsPick:q,setSkillsPick:J,onSaveSkills:oe,bindingsLoading:se,agentBindings:ce,bindChannelStatuses:le,bindChannelsLoading:ue,useManualChannel:de,newBindChannel:fe,setNewBindChannel:pe,bindSessionChats:me,bindSessionsLoading:he,newBindSessionIdx:ge,setNewBindSessionIdx:_e,newBindCustomPeer:ve,setNewBindCustomPeer:ye,refreshBindSessions:be,onRemoveBinding:xe,onAddBinding:Se,onTryInChat:Ce}=e;if(!a){let e;return t[0]===n.selectAgentHint?e=t[1]:(e=(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.selectAgentHint}),t[0]=n.selectAgentHint,t[1]=e),e}if(o===`overview`){let e;return t[2]!==n||t[3]!==c||t[4]!==_||t[5]!==v||t[6]!==x||t[7]!==S||t[8]!==y||t[9]!==b||t[10]!==Ce||t[11]!==a?(e=(0,Q.jsx)(Sn,{a:n,selected:a,defaultModel:_,defaultWorkspace:v,isTuiDefault:x,isTuiDefaultInherited:S,busy:c,onSetDefault:y,onSetTuiDefault:b,onTryInChat:Ce}),t[2]=n,t[3]=c,t[4]=_,t[5]=v,t[6]=x,t[7]=S,t[8]=y,t[9]=b,t[10]=Ce,t[11]=a,t[12]=e):e=t[12],e}if(o===`behavior`){let e;t[13]!==n||t[14]!==c||t[15]!==r||t[16]!==d||t[17]!==h||t[18]!==l||t[19]!==p||t[20]!==x||t[21]!==S||t[22]!==C||t[23]!==y||t[24]!==b||t[25]!==Ce||t[26]!==k.draft||t[27]!==k.handleSoulContentChange||t[28]!==k.handleSoulTemplateChange||t[29]!==k.profileMarkdownLoading||t[30]!==k.setAvatarDialogOpen||t[31]!==k.toggleSoulPreviewMode||t[32]!==k.updateIdentity||t[33]!==a||t[34]!==f||t[35]!==g||t[36]!==u||t[37]!==m?(e=(0,Q.jsx)(gn,{a:n,chat:r,selected:a,busy:c,editName:l,setEditName:u,editDescription:d,setEditDescription:f,editWorkspace:p,setEditWorkspace:m,editModel:h,setEditModel:g,onSetDefault:y,onSetTuiDefault:b,isTuiDefault:x,isTuiDefaultInherited:S,onSaveAgentEdits:C,hideInlineSave:!0,profileMarkdownLoading:k.profileMarkdownLoading,profileDraft:k.draft,updateIdentity:k.updateIdentity,handleSoulTemplateChange:k.handleSoulTemplateChange,handleSoulContentChange:k.handleSoulContentChange,setAvatarDialogOpen:k.setAvatarDialogOpen,toggleSoulPreviewMode:k.toggleSoulPreviewMode,onTryInChat:Ce}),t[13]=n,t[14]=c,t[15]=r,t[16]=d,t[17]=h,t[18]=l,t[19]=p,t[20]=x,t[21]=S,t[22]=C,t[23]=y,t[24]=b,t[25]=Ce,t[26]=k.draft,t[27]=k.handleSoulContentChange,t[28]=k.handleSoulTemplateChange,t[29]=k.profileMarkdownLoading,t[30]=k.setAvatarDialogOpen,t[31]=k.toggleSoulPreviewMode,t[32]=k.updateIdentity,t[33]=a,t[34]=f,t[35]=g,t[36]=u,t[37]=m,t[38]=e):e=t[38];let i;t[39]!==n||t[40]!==c||t[41]!==r||t[42]!==H||t[43]!==ie||t[44]!==re||t[45]!==a||t[46]!==U?(i=(0,Q.jsx)(`section`,{className:`min-h-[34rem]`,children:(0,Q.jsx)(pn,{a:n,chat:r,selected:a,busy:c,modelRows:H,setModelRows:U,onSaveModels:re,onClearModelsEntry:ie})}),t[39]=n,t[40]=c,t[41]=r,t[42]=H,t[43]=ie,t[44]=re,t[45]=a,t[46]=U,t[47]=i):i=t[47];let o;t[48]!==n||t[49]!==M||t[50]!==I||t[51]!==R||t[52]!==j||t[53]!==A||t[54]!==P||t[55]!==Ce||t[56]!==B||t[57]!==z||t[58]!==N||t[59]!==L||t[60]!==F?(o=(0,Q.jsx)(`section`,{className:`min-h-[34rem]`,children:(0,Q.jsx)(dn,{a:n,filesLoading:A,files:j,activeFile:M,setActiveFile:N,filesViewMode:P,setFilesViewMode:F,fileDraft:I,setFileDraft:L,fileSaving:R,profileFileLoading:z,profileEditorNonce:B,onTryInChat:Ce})}),t[48]=n,t[49]=M,t[50]=I,t[51]=R,t[52]=j,t[53]=A,t[54]=P,t[55]=Ce,t[56]=B,t[57]=z,t[58]=N,t[59]=L,t[60]=F,t[61]=o):o=t[61];let s;return t[62]!==e||t[63]!==i||t[64]!==o?(s=(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-6 overflow-y-auto`,children:[e,i,o]}),t[62]=e,t[63]=i,t[64]=o,t[65]=s):s=t[65],s}if(o===`tools`){let e;return t[66]!==n||t[67]!==c||t[68]!==s||t[69]!==ne||t[70]!==te||t[71]!==a||t[72]!==V||t[73]!==ee?(e=(0,Q.jsx)(jn,{a:n,data:s,selected:a,busy:c,toolEntryDisable:ee,setToolEntryDisable:V,onSaveTools:te,onClearToolsEntry:ne}),t[66]=n,t[67]=c,t[68]=s,t[69]=ne,t[70]=te,t[71]=a,t[72]=V,t[73]=ee,t[74]=e):e=t[74],e}if(o===`skills`){let e;return t[75]!==n||t[76]!==c||t[77]!==G||t[78]!==oe||t[79]!==a||t[80]!==K||t[81]!==J||t[82]!==W||t[83]!==ae||t[84]!==q?(e=(0,Q.jsx)(Cn,{a:n,selected:a,busy:c,skillsCatalogLoading:W,catalogForPick:G,skillsInherit:ae,setSkillsInherit:K,skillsPick:q,setSkillsPick:J,onSaveSkills:oe}),t[75]=n,t[76]=c,t[77]=G,t[78]=oe,t[79]=a,t[80]=K,t[81]=J,t[82]=W,t[83]=ae,t[84]=q,t[85]=e):e=t[85],e}if(o===`memory`){let e;return t[86]===a.id?e=t[87]:(e=(0,Q.jsx)(Ut,{embedded:!0,agentId:a.id}),t[86]=a.id,t[87]=e),e}if(o===`connections`){let e;return t[88]!==n||t[89]!==ce||t[90]!==le||t[91]!==ue||t[92]!==me||t[93]!==he||t[94]!==se||t[95]!==c||t[96]!==i.lastActiveLabels||t[97]!==i.selectRecipient||t[98]!==fe||t[99]!==ve||t[100]!==ge||t[101]!==Se||t[102]!==xe||t[103]!==be||t[104]!==pe||t[105]!==ye||t[106]!==_e||t[107]!==de?(e=(0,Q.jsx)(un,{a:n,busy:c,bindingsLoading:se,agentBindings:ce,channelStatuses:le,channelsStatusLoading:ue,useManualChannel:de,newBindChannel:fe,setNewBindChannel:pe,bindSessionChats:me,sessionsLoading:he,newBindSessionIdx:ge,setNewBindSessionIdx:_e,newBindCustomPeer:ve,setNewBindCustomPeer:ye,onRefreshSessions:be,lastActiveLabels:i.lastActiveLabels,selectRecipient:i.selectRecipient,onRemoveBinding:xe,onAddBinding:Se}),t[88]=n,t[89]=ce,t[90]=le,t[91]=ue,t[92]=me,t[93]=he,t[94]=se,t[95]=c,t[96]=i.lastActiveLabels,t[97]=i.selectRecipient,t[98]=fe,t[99]=ve,t[100]=ge,t[101]=Se,t[102]=xe,t[103]=be,t[104]=pe,t[105]=ye,t[106]=_e,t[107]=de,t[108]=e):e=t[108],e}if(o===`config`){let e;return t[109]!==n||t[110]!==c||t[111]!==T||t[112]!==_||t[113]!==E||t[114]!==v||t[115]!==h||t[116]!==p||t[117]!==O||t[118]!==D||t[119]!==a?(e=(0,Q.jsx)(tn,{a:n,selected:a,busy:c,defaultModel:_,defaultWorkspace:v,agentModel:h,agentWorkspace:p,capabilityPresets:T,defaultPresetId:E,onUpdateAgentExtends:D,onOpenCapabilityPreset:O}),t[109]=n,t[110]=c,t[111]=T,t[112]=_,t[113]=E,t[114]=v,t[115]=h,t[116]=p,t[117]=O,t[118]=D,t[119]=a,t[120]=e):e=t[120],e}if(o===`dangerZone`){let e;return t[121]!==n||t[122]!==c||t[123]!==w||t[124]!==a?(e=(0,Q.jsx)(cn,{a:n,selected:a,busy:c,onDelete:w}),t[121]=n,t[122]=c,t[123]=w,t[124]=a,t[125]=e):e=t[125],e}let Y;return t[126]===n.selectAgentHint?Y=t[127]:(Y=(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.selectAgentHint}),t[126]=n.selectAgentHint,t[127]=Y),Y}function Fn(e,t,n){let r=t.trim().toLowerCase();return r?e.filter(e=>{let t=F(e,n).toLowerCase(),i=e.id.toLowerCase(),a=e.workspace.toLowerCase(),o=Ne(e,n).toLowerCase();return t.includes(r)||i.includes(r)||a.includes(r)||o.includes(r)}):e}function In(e,t){return e.replace(`{{count}}`,String(t))}function Ln(e,t){let n=e.tools.effectiveDisable.length,r=e.skills.effectiveAllowlist?.length??0,i=n>0?In(t.listToolsDisabledCount,n):t.listToolsAllEnabled,a=r>0?In(t.listSkillsCount,r):t.listInheritedValue;return`${t.listToolsLabel} ${i} · ${t.listSkillsLabel} ${a}`}function Rn(e,t){let n=e.tools.effectiveDisable.length,r=e.skills.effectiveAllowlist?.length??0,i=n>0?In(t.listToolsDisabledCount,n):t.listToolsAllEnabled,a=r>0?In(t.listSkillsCount,r):t.listInheritedValue;return[`${t.listToolsLabel} ${i}`,`${t.listSkillsLabel} ${a}`]}function zn(e){let t=(0,Z.c)(11),{text:n,children:r,className:a}=e,o;t[0]!==r||t[1]!==a||t[2]!==n?(o=(0,Q.jsx)(z,{asChild:!0,children:(0,Q.jsx)(`span`,{className:a,title:n,children:r})}),t[0]=r,t[1]=a,t[2]=n,t[3]=o):o=t[3];let s;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(s=i(`max-w-[min(28rem,calc(100vw-2rem))] rounded-lg border border-edge bg-surface-panel px-2.5 py-2`,`text-left text-xs leading-snug text-fg shadow-popover`,st),t[4]=s):s=t[4];let c;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Q.jsx)(ee,{className:`fill-surface-panel`}),t[5]=c):c=t[5];let l;t[6]===n?l=t[7]:(l=(0,Q.jsx)(m,{children:(0,Q.jsxs)(Ie,{side:`top`,align:`start`,sideOffset:6,className:s,children:[n,c]})}),t[6]=n,t[7]=l);let u;return t[8]!==o||t[9]!==l?(u=(0,Q.jsx)(Pe,{delayDuration:300,skipDelayDuration:100,children:(0,Q.jsxs)(I,{children:[o,l]})}),t[8]=o,t[9]=l,t[10]=u):u=t[10],u}function Bn(e){let t=(0,Z.c)(34),{a:n,agents:r,defaultAgentId:a,tuiDefaultAgentId:o,tuiDefaultInherited:s,searchQuery:c,onOpenAgent:l,onChatWithAgent:u,busy:d}=e,f,p,m,g,_;if(t[0]!==n||t[1]!==r||t[2]!==d||t[3]!==a||t[4]!==u||t[5]!==l||t[6]!==c||t[7]!==o||t[8]!==s){_=Symbol.for(`react.early_return_sentinel`);bb0:{let e=Fn(r,c,n),v=r.length>0&&e.length===0&&c.trim().length>0;if(r.length===0){let e;t[14]===n.listNoAgentsYet?e=t[15]:(e=(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.listNoAgentsYet}),t[14]=n.listNoAgentsYet,t[15]=e),_=e;break bb0}m=`flex flex-col gap-4`,t[16]!==n||t[17]!==v?(g=v?(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.listEmpty}):null,t[16]=n,t[17]=v,t[18]=g):g=t[18],f=`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3`;let y;t[19]!==n||t[20]!==d||t[21]!==a||t[22]!==u||t[23]!==l||t[24]!==o||t[25]!==s?(y=e=>{let t=F(e,n),r=e.id,c=Ne(e,n),f=Ln(e,n),p=Rn(e,n),m=e.id===a||e.isDefault,g=e.id===o,_=g&&s,v=g&&!s;return(0,Q.jsx)(`li`,{className:`h-full min-h-0`,children:(0,Q.jsxs)(`article`,{role:`button`,tabIndex:d?-1:0,"aria-disabled":d,"aria-label":`${t} ${r}`,onClick:()=>{d||l(e.id)},onKeyDown:t=>{d||t.key!==`Enter`&&t.key!==` `||(t.preventDefault(),l(e.id))},className:i(`flex min-h-[15.5rem] cursor-pointer flex-col rounded-xl border border-edge-subtle bg-surface-panel p-4 shadow-surface`,`transition-[border-color,transform,box-shadow] duration-150 ease-out`,`hover:border-edge-strong`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-base`,`aria-disabled:pointer-events-none aria-disabled:cursor-not-allowed aria-disabled:opacity-60`,V.pressCard),children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3 text-left`,children:[(0,Q.jsx)(`div`,{className:`flex size-12 shrink-0 items-center justify-center overflow-hidden rounded-2xl bg-surface-base text-fg ring-1 ring-edge-subtle/40`,"aria-hidden":!0,children:(0,Q.jsx)(Ye,{agentId:e.id,avatar:e.avatar,size:48,className:`size-full`})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:t}),(0,Q.jsx)(`p`,{className:`mt-1 truncate font-mono text-xs text-fg-muted`,title:r,children:r})]})]}),(0,Q.jsxs)(`div`,{className:`flex max-w-[9rem] shrink-0 flex-wrap justify-end gap-1.5`,children:[m?(0,Q.jsx)(`span`,{className:`rounded-full bg-accent-soft px-2 py-0.5 text-xs font-medium text-accent`,children:n.globalDefaultBadge}):null,v?(0,Q.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-xs font-medium text-fg`,children:n.tuiDefaultBadge}):null,_?(0,Q.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-xs font-medium text-fg`,children:n.tuiDefaultInheritedBadge}):null,!m&&!g?(0,Q.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-xs font-medium text-fg-muted`,children:n.listCustomBadge}):null]})]}),(0,Q.jsxs)(`div`,{className:`mt-5 min-h-[6.25rem] text-left`,children:[(0,Q.jsx)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-base px-3 py-3`,children:(0,Q.jsx)(`p`,{className:i(`line-clamp-2 text-sm leading-5`,c?`text-fg`:`text-fg-muted`),title:c||void 0,children:c||n.listNoDescription})}),(0,Q.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,title:f,children:p.map(Vn)})]}),(0,Q.jsx)(`div`,{className:`mt-auto pt-4`,children:(0,Q.jsxs)(h,{type:`button`,variant:`secondary`,disabled:d,onClick:t=>{t.stopPropagation(),u(e.id)},className:`w-full rounded-2xl py-2.5`,children:[(0,Q.jsx)(ie,{className:`size-4 shrink-0`,strokeWidth:2,"aria-hidden":!0}),n.listChatWithAgent]})})]})},e.id)},t[19]=n,t[20]=d,t[21]=a,t[22]=u,t[23]=l,t[24]=o,t[25]=s,t[26]=y):y=t[26],p=e.map(y)}t[0]=n,t[1]=r,t[2]=d,t[3]=a,t[4]=u,t[5]=l,t[6]=c,t[7]=o,t[8]=s,t[9]=f,t[10]=p,t[11]=m,t[12]=g,t[13]=_}else f=t[9],p=t[10],m=t[11],g=t[12],_=t[13];if(_!==Symbol.for(`react.early_return_sentinel`))return _;let v;t[27]!==f||t[28]!==p?(v=(0,Q.jsx)(`ul`,{className:f,children:p}),t[27]=f,t[28]=p,t[29]=v):v=t[29];let y;return t[30]!==m||t[31]!==g||t[32]!==v?(y=(0,Q.jsxs)(`div`,{className:m,children:[g,v]}),t[30]=m,t[31]=g,t[32]=v,t[33]=y):y=t[33],y}function Vn(e){return(0,Q.jsx)(zn,{text:e,className:`rounded-full bg-surface-hover px-2 py-0.5 text-xs text-fg-muted`,children:e},e)}function Hn(e){let t=(0,Z.c)(130),{open:n,onOpenChange:r,a,chat:o,busy:s,modalError:c,profileLanguageLabel:l,createDisplayName:u,setCreateDisplayName:d,createAgentId:f,setCreateAgentId:p,createDescription:m,setCreateDescription:g,createWorkspace:_,setCreateWorkspace:v,createModel:y,setCreateModel:b,onCreate:x,onSuggestWorkspace:S,agents:C,duplicateSourceId:w,onSelectDuplicateSource:E}=e,D;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,Q.jsx)(Je,{className:i(`xopc-dialog-overlay fixed inset-0 bg-scrim`,_e)}),t[0]=D):D=t[0];let O;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(O=i(`xopc-dialog-content fixed left-1/2 top-1/2 max-h-[min(90vh,640px)] w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,ct,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),t[1]=O):O=t[1];let A;t[2]===a.addAgent?A=t[3]:(A=(0,Q.jsx)(Ue,{className:`text-base font-semibold text-fg`,children:a.addAgent}),t[2]=a.addAgent,t[3]=A);let j;t[4]===a.addAgentHint?j=t[5]:(j=(0,Q.jsx)(He,{className:`mt-0.5 text-xs text-fg-muted`,children:a.addAgentHint}),t[4]=a.addAgentHint,t[5]=j);let M;t[6]!==A||t[7]!==j?(M=(0,Q.jsxs)(`div`,{className:`min-w-0 pr-2`,children:[A,j]}),t[6]=A,t[7]=j,t[8]=M):M=t[8];let N;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(N=i(L,`shrink-0 p-1.5 hover:bg-surface-base`),t[9]=N):N=t[9];let P;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(P=(0,Q.jsx)(T,{className:`size-4`,"aria-hidden":!0}),t[10]=P):P=t[10];let I;t[11]===a.closeDialogAria?I=t[12]:(I=(0,Q.jsx)(Ce,{asChild:!0,children:(0,Q.jsx)(`button`,{type:`button`,className:N,"aria-label":a.closeDialogAria,children:P})}),t[11]=a.closeDialogAria,t[12]=I);let R;t[13]!==M||t[14]!==I?(R=(0,Q.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[M,I]}),t[13]=M,t[14]=I,t[15]=R):R=t[15];let z;t[16]!==a||t[17]!==C||t[18]!==w||t[19]!==E?(z=C.length>0?(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm`,children:[(0,Q.jsx)(`span`,{className:`text-fg-muted`,children:a.copyFromExistingAgent}),(0,Q.jsxs)(Te,{className:i(Ct(),`bg-surface-panel`),value:w??``,onChange:e=>E(e.target.value||null),children:[(0,Q.jsx)(rt,{value:``,children:a.copyFromExistingAgentNone}),C.map(e=>(0,Q.jsxs)(rt,{value:e.id,children:[F(e,a),` · `,e.id]},e.id))]}),(0,Q.jsx)(`span`,{className:`text-xs text-fg-muted`,children:a.duplicateAgentHint})]}):null,t[16]=a,t[17]=C,t[18]=w,t[19]=E,t[20]=z):z=t[20];let B;t[21]===c?B=t[22]:(B=c?(0,Q.jsx)(`div`,{role:`alert`,className:`rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-800 dark:border-red-900/50 dark:bg-red-950/40 dark:text-red-200`,children:c}):null,t[21]=c,t[22]=B);let ee;t[23]!==a.newAgentLabel||t[24]!==l?(ee=(0,Q.jsxs)(`span`,{className:`text-fg-muted`,children:[a.newAgentLabel,` (`,l,`)`]}),t[23]=a.newAgentLabel,t[24]=l,t[25]=ee):ee=t[25];let V;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(V=Ct(),t[26]=V):V=t[26];let te;t[27]===d?te=t[28]:(te=e=>d(e.target.value),t[27]=d,t[28]=te);let ne;t[29]===S?ne=t[30]:(ne=()=>S(),t[29]=S,t[30]=ne);let H;t[31]!==u||t[32]!==te||t[33]!==ne?(H=(0,Q.jsx)(`input`,{className:V,value:u,onChange:te,onBlur:ne,required:!0,autoComplete:`off`}),t[31]=u,t[32]=te,t[33]=ne,t[34]=H):H=t[34];let U;t[35]!==ee||t[36]!==H?(U=(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm`,children:[ee,H]}),t[35]=ee,t[36]=H,t[37]=U):U=t[37];let re;t[38]===a.newAgentIdOptional?re=t[39]:(re=(0,Q.jsx)(`span`,{className:`text-fg-muted`,children:a.newAgentIdOptional}),t[38]=a.newAgentIdOptional,t[39]=re);let ie;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(ie=i(Ct(),`font-mono text-xs`),t[40]=ie):ie=t[40];let W;t[41]===p?W=t[42]:(W=e=>p(e.target.value),t[41]=p,t[42]=W);let G;t[43]===S?G=t[44]:(G=()=>S(),t[43]=S,t[44]=G);let ae;t[45]!==a.newAgentIdPlaceholder||t[46]!==a.newAgentIdRules||t[47]!==f||t[48]!==W||t[49]!==G?(ae=(0,Q.jsx)(`input`,{className:ie,value:f,onChange:W,onBlur:G,placeholder:a.newAgentIdPlaceholder,autoComplete:`off`,spellCheck:!1,maxLength:64,pattern:`[A-Za-z0-9][A-Za-z0-9_-]{0,63}`,title:a.newAgentIdRules}),t[45]=a.newAgentIdPlaceholder,t[46]=a.newAgentIdRules,t[47]=f,t[48]=W,t[49]=G,t[50]=ae):ae=t[50];let K;t[51]===a.newAgentIdRules?K=t[52]:(K=(0,Q.jsx)(`span`,{className:`text-xs text-fg-muted`,children:a.newAgentIdRules}),t[51]=a.newAgentIdRules,t[52]=K);let q;t[53]!==re||t[54]!==ae||t[55]!==K?(q=(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm`,children:[re,ae,K]}),t[53]=re,t[54]=ae,t[55]=K,t[56]=q):q=t[56];let J;t[57]!==a.agentDescription||t[58]!==l?(J=(0,Q.jsxs)(`span`,{className:`text-fg-muted`,children:[a.agentDescription,` (`,l,`)`]}),t[57]=a.agentDescription,t[58]=l,t[59]=J):J=t[59];let oe;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(oe=i(Ct(),`min-h-18 resize-y font-sans text-sm leading-relaxed`),t[60]=oe):oe=t[60];let se;t[61]===g?se=t[62]:(se=e=>g(e.target.value),t[61]=g,t[62]=se);let ce;t[63]!==a.agentDescriptionPlaceholder||t[64]!==m||t[65]!==se?(ce=(0,Q.jsx)(`textarea`,{className:oe,value:m,onChange:se,placeholder:a.agentDescriptionPlaceholder,maxLength:4e3,rows:3,spellCheck:!0}),t[63]=a.agentDescriptionPlaceholder,t[64]=m,t[65]=se,t[66]=ce):ce=t[66];let le;t[67]!==J||t[68]!==ce?(le=(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm`,children:[J,ce]}),t[67]=J,t[68]=ce,t[69]=le):le=t[69];let ue;t[70]===a.newWorkspace?ue=t[71]:(ue=(0,Q.jsx)(`span`,{className:`text-fg-muted`,children:a.newWorkspace}),t[70]=a.newWorkspace,t[71]=ue);let de;t[72]===Symbol.for(`react.memo_cache_sentinel`)?(de=i(Ct(),`font-mono text-xs`),t[72]=de):de=t[72];let fe;t[73]===v?fe=t[74]:(fe=e=>v(e.target.value),t[73]=v,t[74]=fe);let pe;t[75]!==_||t[76]!==fe?(pe=(0,Q.jsx)(`input`,{className:de,value:_,onChange:fe,required:!0,autoComplete:`off`}),t[75]=_,t[76]=fe,t[77]=pe):pe=t[77];let me;t[78]!==ue||t[79]!==pe?(me=(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm`,children:[ue,pe]}),t[78]=ue,t[79]=pe,t[80]=me):me=t[80];let ge;t[81]===a.newModelOptional?ge=t[82]:(ge=(0,Q.jsx)(`span`,{className:`text-fg-muted`,children:a.newModelOptional}),t[81]=a.newModelOptional,t[82]=ge);let ve;t[83]===b?ve=t[84]:(ve=e=>b(e),t[83]=b,t[84]=ve);let ye;t[85]!==s||t[86]!==o.modelNoMatches||t[87]!==o.modelPlaceholder||t[88]!==o.modelSearchPlaceholder||t[89]!==y||t[90]!==ve?(ye=(0,Q.jsx)(Ge,{className:`min-w-0 flex-1`,value:y,disabled:s,placeholder:o.modelPlaceholder,searchPlaceholder:o.modelSearchPlaceholder,noMatches:o.modelNoMatches,onChange:ve}),t[85]=s,t[86]=o.modelNoMatches,t[87]=o.modelPlaceholder,t[88]=o.modelSearchPlaceholder,t[89]=y,t[90]=ve,t[91]=ye):ye=t[91];let be;t[92]!==a.modelClear||t[93]!==s||t[94]!==y||t[95]!==b?(be=y.trim()?(0,Q.jsx)(h,{type:`button`,variant:`secondary`,className:`shrink-0`,disabled:s,onClick:()=>b(``),children:a.modelClear}):null,t[92]=a.modelClear,t[93]=s,t[94]=y,t[95]=b,t[96]=be):be=t[96];let xe;t[97]!==ye||t[98]!==be?(xe=(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-stretch gap-2`,children:[ye,be]}),t[97]=ye,t[98]=be,t[99]=xe):xe=t[99];let Se;t[100]!==ge||t[101]!==xe?(Se=(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[ge,xe]}),t[100]=ge,t[101]=xe,t[102]=Se):Se=t[102];let Y;t[103]!==a.createModalCancel||t[104]!==s?(Y=(0,Q.jsx)(Ce,{asChild:!0,children:(0,Q.jsx)(h,{type:`button`,variant:`secondary`,disabled:s,children:a.createModalCancel})}),t[103]=a.createModalCancel,t[104]=s,t[105]=Y):Y=t[105];let we;t[106]===Symbol.for(`react.memo_cache_sentinel`)?(we=(0,Q.jsx)(k,{className:`mr-1 size-4`,"aria-hidden":!0}),t[106]=we):we=t[106];let Ee;t[107]!==a.create||t[108]!==s?(Ee=(0,Q.jsxs)(h,{type:`submit`,disabled:s,children:[we,a.create]}),t[107]=a.create,t[108]=s,t[109]=Ee):Ee=t[109];let De;t[110]!==Y||t[111]!==Ee?(De=(0,Q.jsxs)(`div`,{className:`mt-1 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[Y,Ee]}),t[110]=Y,t[111]=Ee,t[112]=De):De=t[112];let Oe;t[113]!==x||t[114]!==B||t[115]!==U||t[116]!==q||t[117]!==le||t[118]!==me||t[119]!==Se||t[120]!==De||t[121]!==z?(Oe=(0,Q.jsxs)(`form`,{className:`grid gap-3`,onSubmit:x,children:[z,B,U,q,le,me,Se,De]}),t[113]=x,t[114]=B,t[115]=U,t[116]=q,t[117]=le,t[118]=me,t[119]=Se,t[120]=De,t[121]=z,t[122]=Oe):Oe=t[122];let je;t[123]!==Oe||t[124]!==R?(je=(0,Q.jsxs)(Ae,{children:[D,(0,Q.jsx)($e,{className:O,onOpenAutoFocus:Un,children:(0,Q.jsxs)(ke,{layer:`modal`,children:[R,Oe]})})]}),t[123]=Oe,t[124]=R,t[125]=je):je=t[125];let Me;return t[126]!==r||t[127]!==n||t[128]!==je?(Me=(0,Q.jsx)(he,{open:n,onOpenChange:r,children:je}),t[126]=r,t[127]=n,t[128]=je,t[129]=Me):Me=t[129],Me}function Un(e){return e.preventDefault()}var Wn=`~/.xopc/workspace`;function Gn(e){let t=e.trim();return t?`${Wn}/${et(t)}`:``}function Kn(e){let t=(0,Z.c)(18),{a:n,busy:r,listSearchQuery:i,onListSearchQueryChange:a,onAddAgent:o}=e,s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,Q.jsx)(q,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-fg-disabled`,strokeWidth:1.75,"aria-hidden":!0}),t[0]=s):s=t[0];let c;t[1]===a?c=t[2]:(c=e=>a(e.target.value),t[1]=a,t[2]=c);let l;t[3]!==n.listSearchPlaceholder||t[4]!==i||t[5]!==c?(l=(0,Q.jsxs)(`label`,{className:`relative flex min-h-9 min-w-0 max-w-sm cursor-text items-center rounded-pill border border-edge bg-surface-base py-1.5 pl-9 pr-3 shadow-surface dark:bg-surface-hover/40 sm:max-w-md`,children:[s,(0,Q.jsx)(`input`,{type:`search`,enterKeyHint:`search`,value:i,onChange:c,placeholder:n.listSearchPlaceholder,autoComplete:`off`,spellCheck:!1,"aria-label":n.listSearchPlaceholder,className:`min-w-0 flex-1 appearance-none border-0 bg-transparent py-0.5 text-sm leading-normal text-fg caret-current placeholder:text-fg-disabled focus:border-0 focus:shadow-none focus:outline-none focus:ring-0 focus-visible:outline-none`})]}),t[3]=n.listSearchPlaceholder,t[4]=i,t[5]=c,t[6]=l):l=t[6];let u;t[7]===o?u=t[8]:(u=()=>o(),t[7]=o,t[8]=u);let d;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,Q.jsx)(H,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),t[9]=d):d=t[9];let f;t[10]!==n.addAgent||t[11]!==n.addAgentAria||t[12]!==r||t[13]!==u?(f=(0,Q.jsxs)(h,{type:`button`,variant:`primary`,className:`shrink-0 gap-2`,"aria-label":n.addAgentAria,disabled:r,onClick:u,children:[d,n.addAgent]}),t[10]=n.addAgent,t[11]=n.addAgentAria,t[12]=r,t[13]=u,t[14]=f):f=t[14];let p;return t[15]!==l||t[16]!==f?(p=(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center justify-end gap-2`,children:[l,f]}),t[15]=l,t[16]=f,t[17]=p):p=t[17],p}function qn(e){return{...e,soulEditorNonce:0,soulPreviewMode:!1,avatarDialogOpen:!1}}function Jn(e){let{agentId:t,enabled:n,saveRef:r}=e,i=p(async()=>{if(!t)return null;let[e,n]=await Promise.all([O(t,`IDENTITY.md`).catch(()=>``),O(t,`SOUL.md`).catch(()=>``)]),r=y(e);return{identity:r,soulTemplate:J(n),soulCustomContent:n,identityBaseline:JSON.stringify(r),soulBaseline:n}},[t],{enabled:n&&!!t,initial:null,errorData:null}),a=i.data,o=i.loading,s=(0,$.useRef)(!1),[c,l]=(0,$.useState)(null),u=t??``,d=(0,$.useRef)(u);d.current!==u&&(d.current=u,s.current=!1,l(null));let f=c??(a?qn(a):null),m=(0,$.useMemo)(()=>f?JSON.stringify(f.identity)!==f.identityBaseline||f.soulCustomContent!==f.soulBaseline:!1,[f]),h=(0,$.useRef)(t);h.current=t;let g=(0,$.useCallback)(e=>{s.current=!0,l(t=>{let n=t??(a?qn(a):null);return n?e(n):null})},[a]),_=(0,$.useCallback)(e=>{g(t=>({...t,identity:{...t.identity,...e}}))},[g]),v=(0,$.useCallback)(e=>{g(t=>{if(e===`custom`)return{...t,soulTemplate:`custom`};let n=lt.find(t=>t.id===e);return n?.content?{...t,soulTemplate:e,soulCustomContent:n.content,soulEditorNonce:t.soulEditorNonce+1}:{...t,soulTemplate:e}})},[g]),b=(0,$.useCallback)(e=>{g(t=>({...t,soulCustomContent:e,soulTemplate:`custom`}))},[g]),x=(0,$.useCallback)(e=>{g(t=>({...t,avatarDialogOpen:e}))},[g]),S=(0,$.useCallback)(()=>{g(e=>({...e,soulPreviewMode:!e.soulPreviewMode}))},[g]),w=(0,$.useCallback)(async()=>{let e=h.current;!e||!f||(await Promise.all([C(e,`IDENTITY.md`,ce(f.identity)),C(e,`SOUL.md`,f.soulCustomContent)]),s.current=!1,l(e=>{let t=e??f;return{...t,identityBaseline:JSON.stringify(t.identity),soulBaseline:t.soulCustomContent}}))},[f]);return(0,$.useLayoutEffect)(()=>{if(r)return r.current=w,()=>{r.current=null}},[w,r]),{profileMarkdownLoading:o,draft:f,dirty:m,updateIdentity:_,handleSoulTemplateChange:v,handleSoulContentChange:b,setAvatarDialogOpen:x,toggleSoulPreviewMode:S}}var Yn={draft:``,editorNonce:0,loadedKey:``};function Xn(e,t){switch(t.type){case`load`:return{draft:t.content,editorNonce:e.editorNonce+1,loadedKey:t.key};case`setDraft`:return{...e,draft:t.value};case`clear`:return{draft:``,editorNonce:e.editorNonce,loadedKey:``};case`resetViewMode`:return e}}function Zn(e){let{panel:t,selectedId:n,hasToken:r,dataAgentsLength:i,saveErrorMessage:a,setError:o}=e,s=p(()=>n?M(n):Promise.resolve(null),[t,n,r,i],{enabled:t===`behavior`&&!!n&&r,initial:null,errorData:null}),c=s.data,l=s.setData,u=s.loading,[d,f]=(0,$.useState)(null),[m,h]=(0,$.useReducer)(Xn,Yn),[g,_]=(0,$.useState)(!1),[v,y]=(0,$.useState)(`edit`),b=(0,$.useRef)(n);(0,$.useEffect)(()=>{n!==b.current&&(b.current=n,f(null))},[n]),(0,$.useEffect)(()=>{if(c&&c.files.length>0&&!d){let e=c.files.find(e=>e.name===`AGENTS.md`);f(e?e.name:c.files[0].name)}},[c,d]);let x=m.draft,S=m.editorNonce,w=(0,$.useRef)(x);w.current=x;let T=(0,$.useRef)(n);T.current=n;let E=(0,$.useRef)(d);E.current=d;let D=(0,$.useRef)(null),k=(0,$.useRef)(``),A=(0,$.useRef)(``),j=(0,$.useRef)(``),N=(0,$.useRef)(()=>{}),P=p(()=>d&&n?O(n,d).catch(()=>``):Promise.resolve(``),[d,n,r],{enabled:!!(d&&n&&r),initial:``,errorData:``}),F=P.loading,I=U(async()=>{let e=T.current,t=E.current;if(!e||!t||`${e}:${t}`!==k.current)return;let n=w.current;if(n!==A.current){_(!0),o(null);try{await C(e,t,n),A.current=n,l(n=>!n||n.agentId!==e?n:{...n,files:n.files.map(e=>e.name===t?{...e,missing:!1}:e)})}catch(e){o(e instanceof Error?e.message:a)}finally{_(!1)}}},800);N.current=I.flush,(0,$.useEffect)(()=>()=>{N.current()},[]);let L=(0,$.useRef)(t);L.current!==t&&(L.current===`behavior`&&N.current(),L.current=t);let R=d&&n?`${n}:${d}`:``;(0,$.useEffect)(()=>{R!==j.current&&(N.current(),j.current=R)},[R]),(0,$.useEffect)(()=>{if(!R){h({type:`clear`});return}F||(k.current=R,A.current=P.data,h({type:`load`,key:R,content:P.data}))},[R,F,P.data]);let z=(0,$.useRef)({activeFile:d,selectedId:n});return(z.current.activeFile!==d||z.current.selectedId!==n)&&(z.current={activeFile:d,selectedId:n},y(`edit`)),{files:c,setFiles:l,filesLoading:u,activeFile:d,setActiveFile:(0,$.useCallback)(e=>{N.current(),f(e)},[]),fileDraft:x,setFileDraft:(0,$.useCallback)(e=>{h({type:`setDraft`,value:typeof e==`function`?e(w.current):e}),I()},[I]),fileSaving:g,filesViewMode:v,setFilesViewMode:y,profileFileLoading:F,profileEditorNonce:S,overviewSaveProfileMarkdownRef:D,saveProfileMarkdownDebounced:I}}function Qn(e){let{panel:t,hasToken:n,bindingsFromConfig:r,gatewayCfgLoading:i,selected:a,saveErrorMessage:o,setBusy:s,setError:c}=e,l=(0,$.useRef)(!1),[u,d]=(0,$.useState)(null),f=(0,$.useRef)(r);t===`connections`&&n&&!l.current&&f.current!==r&&(f.current=r,d(r));let m=u??r,h=t===`connections`&&n,g=p(()=>vt(),[t,n],{enabled:h,initial:[],errorData:[]}),_=g.data,v=g.loading,y=(0,$.useMemo)(()=>v||_.length===0?``:_[0]?.name??``,[_,v]),[b,x]=(0,$.useState)(``),S=(0,$.useRef)(y);t===`connections`&&!v&&y&&S.current!==y&&(!b||!_.some(e=>e.name===b))&&(S.current=y,x(y)),S.current=y;let C=b.trim(),w=h&&C.length>0,T=p(()=>yt(C),[t,n,C],{enabled:w,initial:[],errorData:[]}),E=T.data,D=T.loading,O=T.setData,[k,A]=(0,$.useState)(null),[j,M]=(0,$.useState)(``),N=(0,$.useRef)(C);N.current!==C&&(N.current=C,A(null));let P=(0,$.useMemo)(()=>a?m.filter(e=>e.agentId.toLowerCase()===a.id.toLowerCase()):[],[m,a?.id]),F=(0,$.useCallback)(()=>{let e=b.trim();e&&yt(e).then(e=>{O(e),A(t=>t!=null&&t<e.length?t:null)}).catch(()=>{O([]),A(null)})},[b,O]),I=!v&&_.length===0,L=t===`connections`&&n&&i,R=(0,$.useCallback)(async e=>{s(!0),c(null);try{let t=m.filter(t=>t!==e);await ue(t),l.current=!0,d(t)}catch(e){c(e instanceof Error?e.message:o)}finally{s(!1)}},[m,o,s,c]);return{agentBindings:P,allBindings:m,bindChannelStatuses:_,bindChannelsLoading:v,bindSessionChats:E,bindSessionsLoading:D,bindingsLoading:L,newBindChannel:b,setNewBindChannel:x,newBindSessionIdx:k,setNewBindSessionIdx:A,newBindCustomPeer:j,setNewBindCustomPeer:M,onAddBinding:(0,$.useCallback)(async e=>{if(e.preventDefault(),!a||!b.trim())return;let t=xt(b,j,k,E),n=[...m,{agentId:a.id,priority:100,enabled:!0,match:t}];s(!0),c(null);try{await ue(n),l.current=!0,d(n),A(null),M(``)}catch(e){c(e instanceof Error?e.message:o)}finally{s(!1)}},[m,E,b,j,k,o,a,s,c]),onRemoveBinding:R,refreshBindSessions:F,useManualChannel:I}}function $n(e,t){let n=(0,Z.c)(16),[r,i]=(0,$.useState)(0),a,o;n[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=()=>{let e=e=>{let t=e.detail;t&&typeof t==`object`&&`section`in t&&t.section===`skills`&&i(nr)};return window.addEventListener(`config-reload`,e),()=>window.removeEventListener(`config-reload`,e)},o=[],n[0]=a,n[1]=o):(a=n[0],o=n[1]),(0,$.useEffect)(a,o);let s;n[2]!==r||n[3]!==e||n[4]!==t?(s=[e,t,r],n[2]=r,n[3]=e,n[4]=t,n[5]=s):s=n[5];let c=e&&t,l;n[6]===Symbol.for(`react.memo_cache_sentinel`)?(l=[],n[6]=l):l=n[6];let u;n[7]===Symbol.for(`react.memo_cache_sentinel`)?(u=[],n[7]=u):u=n[7];let d;n[8]===c?d=n[9]:(d={enabled:c,initial:l,errorData:u},n[8]=c,n[9]=d);let{data:f,loading:m}=p(tr,s,d),h;n[10]===f?h=n[11]:(h=f.filter(er),n[10]=f,n[11]=h);let g=h,_;return n[12]!==g||n[13]!==f||n[14]!==m?(_={catalogForPick:g,skillCatalog:f,skillsCatalogLoading:m},n[12]=g,n[13]=f,n[14]=m,n[15]=_):_=n[15],_}function er(e){return e.enabled!==!1}function tr(){return g()}function nr(e){return e+1}function rr(e){return $n(e.panel===`skills`,e.hasToken)}function ir(e){return new Set(e.tools.entryDisable)}function ar(e){return e.skills.entry===void 0?{inherit:!0,pick:new Set(e.skills.effectiveAllowlist??[])}:{inherit:!1,pick:new Set(e.skills.entry??[])}}function or(e){let{panel:t,selected:n}=e,r=`${t}:${n?.id??``}`,i=(0,$.useRef)(r),[a,o]=(0,$.useState)(()=>new Set),[s,c]=(0,$.useState)(()=>new Set),[l,u]=(0,$.useState)(!0),[d,f]=(0,$.useState)(()=>[]);if(i.current!==r){if(i.current=r,n&&t===`tools`&&o(ir(n)),n&&t===`skills`){let e=ar(n);u(e.inherit),c(e.pick)}n&&t===`behavior`&&f(Tt(n.typedModels.effective))}return{toolEntryDisable:a,setToolEntryDisable:o,skillsPick:s,setSkillsPick:c,skillsInherit:l,setSkillsInherit:u,modelRows:d,setModelRows:f}}function sr(e,t){let n=e.typedModels.defaultRole;return{defaultRole:n,roles:{[n]:{model:t}}}}function cr(e){let t=Tt(e.typedModels.preset);return t.some(t=>t.id===e.typedModels.defaultRole)?t:Tt(e.typedModels.effective)}function lr(e){return Object.fromEntries(Array.from(e).map(e=>e.trim()).filter(Boolean).toSorted((e,t)=>e.localeCompare(t)).map(e=>[e,{mode:`deny`}]))}function ur(){let e=o(e=>e.language),t=a(e),n=t.agentsSettings,[r,i]=(0,$.useState)(!1),[s,l]=(0,$.useState)(null),[u,f]=(0,$.useState)(!1),[p,m]=(0,$.useState)(``),h=t.cron,g=t.chat,_=!!c(e=>e.token),[v,y]=D(),b=te(),{agentId:C}=x(),w=Xe(e=>e.setPageHeader),T=Xe(e=>e.clearPageHeader),{data:O,error:k,isLoading:A,mutate:j}=d(_?`settings-gateway-agents`:null,ut,{revalidateOnFocus:!1}),{data:M,mutate:N}=d(_?`settings-capability-presets`:null,jt,{revalidateOnFocus:!1}),I=P(_),{data:L}=I,z=(0,$.useMemo)(()=>E(L?.payload?.config??{}),[L]),B=O??null,ee=(0,$.useMemo)(()=>B?B.agents.find(e=>e.id===B.defaultId)??B.agents[0]??null:null,[B]),V=!!(_&&A),[ne,H]=(0,$.useState)(null),U=k instanceof Error?k.message:k?n.loadError:null,re=ne??U,[ie,W]=(0,$.useState)(null),[G,ae]=(0,$.useState)(`overview`),[K,q]=(0,$.useState)(``),[J,oe]=(0,$.useState)(``),[ce,le]=(0,$.useState)(``),[ue,de]=(0,$.useState)(``),[pe,me]=(0,$.useState)(``),[he,ge]=(0,$.useState)(null),[_e,ve]=(0,$.useState)(!1),ye=(0,$.useRef)(``),[be,Se]=(0,$.useState)(null),[Ce,Y]=(0,$.useState)(!1),[we,Te]=(0,$.useState)(``),[Ee,Oe]=(0,$.useState)(``),[ke,Ae]=(0,$.useState)(``),[je,Me]=(0,$.useState)(``),[Ne,Pe]=(0,$.useState)(``),[Fe,Ie]=(0,$.useState)(``),Le=(0,$.useRef)(null),[Re,ze]=(0,$.useState)(!1),Be=(0,$.useRef)({data:null,routeAgentId:void 0});B&&(B!==Be.current.data||C!==Be.current.routeAgentId)&&(Be.current={data:B,routeAgentId:C},C&&B.agents.some(e=>e.id===C)?W(C):W(e=>e&&B.agents.some(t=>t.id===e)?e:B.defaultId)),(0,$.useEffect)(()=>{!B||!C||B.agents.some(e=>e.id===C)||b(Qe,{replace:!0})},[B,C,b]),(0,$.useEffect)(()=>{C&&ae(`overview`)},[C]),(0,$.useEffect)(()=>{v.get(`panel`)===`defaults`&&b(C?Ve(C):Qe,{replace:!0,state:{[De]:C?Ve(C):Qe}})},[v,C,b]),(0,$.useEffect)(()=>{if(v.get(`focus`)!==`avatar`||!C||(ae(`overview`),V||!B?.agents.some(e=>e.id===C)))return;let e=window.setTimeout(()=>{document.getElementById(`agent-avatar-settings`)?.scrollIntoView({behavior:`smooth`,block:`center`}),y(e=>{let t=new URLSearchParams(e);return t.delete(`focus`),t},{replace:!0})},220);return()=>window.clearTimeout(e)},[v,C,V,B,y]);let X=(0,$.useMemo)(()=>B?.agents.find(e=>e.id===ie)??null,[B,ie]),He=(0,$.useMemo)(()=>{let e=L?.payload?.config;if(!e||typeof e!=`object`||Array.isArray(e))return``;let t=e.tui;if(!t||typeof t!=`object`||Array.isArray(t))return``;let n=t.defaultAgent;return typeof n==`string`?n.trim().toLowerCase():``},[L]),Ue=(0,$.useMemo)(()=>!B||He&&B.agents.some(e=>e.id===He)?He:B.defaultId||B.agents[0]?.id||He,[B,He]),We=!!(B&&He&&!B.agents.some(e=>e.id===He));(0,$.useEffect)(()=>{Oe(We?``:He)},[He,We]);let Ge=(0,$.useRef)(null),qe=X?X.id:null;X&&Ge.current!==qe?(Ge.current=qe,Ae(X.workspace),Me(X.model?.primary??``),Pe(F(X,a(e).agentsSettings)),Ie(X.description??``)):!X&&Ge.current!==null&&(Ge.current=null,Ae(``),Me(``),Pe(``),Ie(``));let Je=Jn({agentId:X?.id??null,enabled:G===`behavior`&&!!X,saveRef:Le}),Ye=Zn({panel:G,selectedId:ie,hasToken:_,dataAgentsLength:B?.agents.length,saveErrorMessage:n.saveError,setError:H}),Ze=or({panel:G,selected:X}),$e=Qn({panel:G,hasToken:_,bindingsFromConfig:z,gatewayCfgLoading:L===void 0,selected:X,saveErrorMessage:n.saveError,setBusy:Y,setError:H}),et=rr({panel:G,hasToken:_}),tt=(0,$.useCallback)(()=>{let e=Gn(J.trim()||K);de(t=>t===``||t===ye.current?(ye.current=e,e):t)},[J,K]),nt=(0,$.useCallback)(()=>{ye.current=``,q(``),oe(``),le(``),de(``),me(``),ge(null),Se(null),ve(!0)},[]),rt=(0,$.useCallback)(e=>{let t=new Set(B?.agents.map(e=>e.id.toLowerCase())??[]),r=e.trim();if(!t.has(r.toLowerCase()))return r;let i=`${r}${n.duplicateIdSuffix}`;if(!t.has(i.toLowerCase()))return i;for(let e=2;e<1e3;e+=1){let n=`${i}-${e}`;if(!t.has(n.toLowerCase()))return n}return i},[n.duplicateIdSuffix,B]),it=(0,$.useCallback)(e=>{if(Se(e),!e)return;let t=B?.agents.find(t=>t.id===e);if(!t)return;let r=t.name?.trim()??t.id,i=n.duplicateName.replace(`{{name}}`,r),a=rt(t.id),o=t.description??``;ye.current=``,q(i),oe(a),le(o),de(t.workspace),me(t.model?.primary??``),ge(null)},[n.duplicateName,B,rt]),at=(0,$.useCallback)(e=>{it(e),ve(!0)},[it]),ot=(0,$.useMemo)(()=>(0,Q.jsx)(Kn,{a:n,busy:Ce,listSearchQuery:we,onListSearchQueryChange:Te,onAddAgent:()=>nt()}),[n,Ce,we,nt]);(0,$.useLayoutEffect)(()=>_?(w({startExtra:null,main:(0,Q.jsx)(`div`,{className:`min-w-0`,children:(0,Q.jsx)(`h1`,{className:`truncate text-base font-semibold tracking-tight text-fg`,children:n.title})}),end:ot}),()=>T()):(T(),()=>T()),[n.title,ot,T,_,w]);async function st(t){t.preventDefault();let r=K.trim();if(!r)return;let i=xe(J,r);if(i.ok===!1){ge(i.error);return}let a=ue.trim()||Gn(J.trim()||r);if(a){Y(!0),ge(null);try{let t=[`# IDENTITY.md - Who Am I?`,``,`- **Name:** ${r}`,`- **Description:** ${ce.trim()}`,`- **Language:** ${e}`,`- **Creature:** assistant`,`- **Emoji:**`,`- **Avatar:**`,``].join(`
2
- `),{createdAgentId:n,...i}=await R({workspace:a,...J.trim()?{id:J.trim()}:{},...pe.trim()?{models:{defaultRole:`deep`,roles:{deep:{model:pe.trim()}}}}:{},profileFiles:{"IDENTITY.md":t},...be?{cloneFrom:be}:{}});j(i,{revalidate:!1}),q(``),oe(``),le(``),de(``),me(``),ge(null),ve(!1),W(n),b(Ve(n))}catch(e){ge(e instanceof Error?e.message:n.saveError)}finally{Y(!1)}}}async function ct(){if(X){Y(!0),H(null);try{j(await Ke(X.id,{workspace:ke.trim()||void 0,...je.trim()?{models:sr(X,je.trim())}:{}}),{revalidate:!1})}catch(e){H(e instanceof Error?e.message:n.saveError)}finally{Y(!1)}}}async function lt(e){Y(!0),H(null);try{j(await Ke(e.id,{setDefault:!0}),{revalidate:!1}),W(e.id)}catch(e){H(e instanceof Error?e.message:n.saveError)}finally{Y(!1)}}async function dt(){let e=Ee.trim().toLowerCase();if(e&&!B?.agents.some(t=>t.id===e)){H(n.tuiDefaultAgentInvalid);return}Y(!0),H(null);try{await fe(e||null),await I.mutate()}catch(e){H(e instanceof Error?e.message:n.saveError)}finally{Y(!1)}}async function ft(e){Y(!0),H(null);try{await fe(e.id),Oe(e.id),await I.mutate()}catch(e){H(e instanceof Error?e.message:n.saveError)}finally{Y(!1)}}async function pt(){Y(!0),H(null);try{await fe(null),Oe(``),await I.mutate()}catch(e){H(e instanceof Error?e.message:n.saveError)}finally{Y(!1)}}async function mt(e,t){Y(!0),H(null);try{let n=await S(e.id,t);j(n,{revalidate:!1}),W(n.defaultId),ae(`overview`),C===e.id&&b(Qe,{replace:!0}),i(!1),l(null),m(``)}catch(e){H(e instanceof Error?e.message:n.saveError)}finally{Y(!1)}}function ht(e,t){e.id!==`main`&&(l(e),f(t),m(``),i(!0))}async function gt(){if(X){Y(!0),H(null);try{j(await Ke(X.id,{tools:{builtin:lr(Ze.toolEntryDisable)}}),{revalidate:!1})}catch(e){H(e instanceof Error?e.message:n.saveError)}finally{Y(!1)}}}async function _t(){if(X){Y(!0),H(null);try{j(await Ke(X.id,{tools:null}),{revalidate:!1}),Ze.setToolEntryDisable(new Set)}catch(e){H(e instanceof Error?e.message:n.saveError)}finally{Y(!1)}}}async function vt(){if(!X)return;let e=wt(Ze.modelRows,{invalidId:n.typedModelsInvalidId,duplicateId:n.typedModelsDuplicateId,invalidModel:n.typedModelsInvalidModel});if(e){H(e);return}Y(!0),H(null);try{j(await Ke(X.id,{models:{roles:Ot(Ze.modelRows)?.roles??{}}}),{revalidate:!1})}catch(e){H(e instanceof Error?e.message:n.saveError)}finally{Y(!1)}}async function yt(){if(!X)return;let e=cr(X),t=Ot(e);if(!t?.roles?.[X.typedModels.defaultRole]){H(n.typedModelsInvalidModel);return}Y(!0),H(null);try{j(await Ke(X.id,{models:{defaultRole:X.typedModels.defaultRole,roles:t.roles}}),{revalidate:!1}),Ze.setModelRows(e)}catch(e){H(e instanceof Error?e.message:n.saveError)}finally{Y(!1)}}async function bt(){if(X){Y(!0),H(null);try{j(await Ke(X.id,{skills:Ze.skillsInherit?null:[...Ze.skillsPick].toSorted((e,t)=>e.localeCompare(t))}),{revalidate:!1})}catch(e){H(e instanceof Error?e.message:n.saveError)}finally{Y(!1)}}}async function xt(e){if(X){Y(!0),H(null);try{j(await Ke(X.id,{extends:e}),{revalidate:!1}),N()}catch(e){H(e instanceof Error?e.message:n.saveError)}finally{Y(!1)}}}let St=G!==`behavior`,Ct=(()=>{if(!X||G!==`behavior`)return!1;let e=X.workspace,t=X.model?.primary??``;return ke.trim()!==e||je.trim()!==t})(),Tt=(()=>{if(St||!X)return!1;switch(G){case`behavior`:return Ct||Je.dirty;default:return!0}})(),Et=St||!Tt;function Dt(){ze(!0),setTimeout(()=>ze(!1),2e3)}async function kt(){switch(G){case`behavior`:await Promise.all([ct(),Le.current?.()??Promise.resolve()]),Dt();break;default:break}}function At(e){e||b(Qe)}let Mt=X?Ne.trim()||F(X,n):C??``,Nt=X?.id??C??``,Z=(0,$.useCallback)(async()=>{if(X){await kt(),Ye.saveProfileMarkdownDebounced.flush();try{globalThis.localStorage?.setItem(se,X.id)}catch{}b(`/chat/new`,{state:{agentId:X.id,fromAgentEditor:!0}})}},[X,kt,Ye.saveProfileMarkdownDebounced,b]),Pt={a:n,chat:g,cCron:h,selected:X,panel:G,data:B,busy:Ce,editName:Ne,setEditName:Pe,editDescription:Fe,setEditDescription:Ie,editWorkspace:ke,setEditWorkspace:Ae,editModel:je,setEditModel:Me,defaultModel:ee?.model?.primary??``,defaultWorkspace:ee?.workspace??``,onSetDefault:()=>{X&&lt(X)},onSetTuiDefault:()=>{X&&ft(X)},isTuiDefault:!!(X&&X.id===Ue),isTuiDefaultInherited:!!(X&&X.id===Ue&&(!He||We)),onSaveAgentEdits:()=>void ct(),onDelete:e=>{X&&ht(X,e)},onTryInChat:()=>void Z(),capabilityPresets:M?.presets??[],defaultPresetId:M?.defaultPresetId,onUpdateAgentExtends:e=>void xt(e),onOpenCapabilityPreset:e=>{b(e?`/settings/capability-presets?preset=${encodeURIComponent(e)}`:`/settings/capability-presets`)},overviewSaveProfileMarkdownRef:Le,overviewProfile:Je,filesLoading:Ye.filesLoading,files:Ye.files,activeFile:Ye.activeFile,setActiveFile:Ye.setActiveFile,filesViewMode:Ye.filesViewMode,setFilesViewMode:Ye.setFilesViewMode,fileDraft:Ye.fileDraft,setFileDraft:Ye.setFileDraft,fileSaving:Ye.fileSaving,profileFileLoading:Ye.profileFileLoading,profileEditorNonce:Ye.profileEditorNonce,toolEntryDisable:Ze.toolEntryDisable,setToolEntryDisable:Ze.setToolEntryDisable,onSaveTools:()=>void gt(),onClearToolsEntry:()=>void _t(),modelRows:Ze.modelRows,setModelRows:Ze.setModelRows,onSaveModels:()=>void vt(),onClearModelsEntry:()=>void yt(),skillsCatalogLoading:et.skillsCatalogLoading,catalogForPick:et.catalogForPick,skillsInherit:Ze.skillsInherit,setSkillsInherit:Ze.setSkillsInherit,skillsPick:Ze.skillsPick,setSkillsPick:Ze.setSkillsPick,onSaveSkills:()=>void bt(),bindingsLoading:$e.bindingsLoading,agentBindings:$e.agentBindings,bindChannelStatuses:$e.bindChannelStatuses,bindChannelsLoading:$e.bindChannelsLoading,useManualChannel:$e.useManualChannel,newBindChannel:$e.newBindChannel,setNewBindChannel:$e.setNewBindChannel,bindSessionChats:$e.bindSessionChats,bindSessionsLoading:$e.bindSessionsLoading,newBindSessionIdx:$e.newBindSessionIdx,setNewBindSessionIdx:$e.setNewBindSessionIdx,newBindCustomPeer:$e.newBindCustomPeer,setNewBindCustomPeer:$e.setNewBindCustomPeer,refreshBindSessions:$e.refreshBindSessions,onRemoveBinding:e=>void $e.onRemoveBinding(e),onAddBinding:$e.onAddBinding};return{hasToken:_,a:n,chat:g,language:e,data:B,savedTuiDefaultAgentId:He,effectiveTuiDefaultAgentId:Ue,tuiDefaultAgentDraft:Ee,setTuiDefaultAgentDraft:Oe,tuiDefaultAgentUnavailable:We,onSaveTuiDefaultAgent:dt,onSetTuiDefaultAgent:ft,onClearTuiDefaultAgent:pt,onSetDefaultAgent:lt,loading:V,displayError:re,navigate:b,routeAgentId:C,busy:Ce,listSearchQuery:we,openAddAgentModal:nt,openDuplicateAgentModal:at,duplicateSourceId:be,onSelectDuplicateSource:it,panel:G,setPanel:ae,modalTitle:Mt,modalSubtitle:Nt,footerSaveDisabled:Et,savedFlash:Re,handleModalFooterSave:kt,onAgentModalOpenChange:At,addAgentModalOpen:_e,setAddAgentModalOpen:ve,createWorkspaceSuggestedRef:ye,createModalError:he,setCreateModalError:ge,createDisplayName:K,setCreateDisplayName:q,createAgentId:J,setCreateAgentId:oe,createDescription:ce,setCreateDescription:le,createWorkspace:ue,setCreateWorkspace:de,createModel:pe,setCreateModel:me,onCreate:st,currentLanguageLabel:e===`zh`?`中文`:`English`,applyCreateWorkspaceSuggestion:tt,deleteDialogOpen:r,setDeleteDialogOpen:i,deletePurge:u,deleteTarget:s,setDeleteTarget:l,deleteConfirmText:p,setDeleteConfirmText:m,performDelete:mt,editorPanelProps:Pt}}function dr(){let e=ur();return e.hasToken?(0,Q.jsxs)(gt,{gap:`gap-6`,padding:`px-3 py-8 sm:px-5 xl:px-6`,children:[e.displayError?(0,Q.jsx)(`div`,{className:`rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-800 dark:border-red-900/50 dark:bg-red-950/40 dark:text-red-200`,children:e.displayError}):null,e.loading?(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.a.loading}):e.data?(0,Q.jsx)(`div`,{className:`flex flex-col gap-4`,children:(0,Q.jsx)(Bn,{a:e.a,agents:e.data.agents,defaultAgentId:e.data.defaultId,tuiDefaultAgentId:e.effectiveTuiDefaultAgentId,tuiDefaultInherited:!e.savedTuiDefaultAgentId||e.tuiDefaultAgentUnavailable,searchQuery:e.listSearchQuery,onOpenAgent:t=>e.navigate(Ve(t)),onChatWithAgent:t=>{let n=t.trim().toLowerCase();try{globalThis.localStorage?.setItem(se,n)}catch{}e.navigate(`/chat/new`,{state:{agentId:n}})},busy:e.busy})}):null,e.routeAgentId&&e.hasToken?(0,Q.jsx)(Rt,{open:!!e.routeAgentId,onOpenChange:e.onAgentModalOpenChange,a:e.a,title:e.modalTitle,subtitle:e.modalSubtitle,panel:e.panel,onPanelChange:e.setPanel,onFooterSave:()=>void e.handleModalFooterSave(),footerSaveDisabled:e.footerSaveDisabled,footerSavedFlash:e.savedFlash,showFooter:e.panel===`behavior`,busy:e.busy,children:e.loading||!e.data?(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.a.loading}):(0,Q.jsx)(Pn,{...e.editorPanelProps})}):null,(0,Q.jsx)(Hn,{open:e.addAgentModalOpen,onOpenChange:t=>{e.setAddAgentModalOpen(t),t||(e.createWorkspaceSuggestedRef.current=``,e.setCreateDisplayName(``),e.setCreateAgentId(``),e.setCreateDescription(``),e.setCreateWorkspace(``),e.setCreateModel(``),e.setCreateModalError(null),e.onSelectDuplicateSource(null))},a:e.a,chat:e.chat,busy:e.busy,modalError:e.createModalError,profileLanguageLabel:e.currentLanguageLabel,createDisplayName:e.createDisplayName,setCreateDisplayName:e.setCreateDisplayName,createAgentId:e.createAgentId,setCreateAgentId:e.setCreateAgentId,createDescription:e.createDescription,setCreateDescription:e.setCreateDescription,createWorkspace:e.createWorkspace,setCreateWorkspace:e.setCreateWorkspace,createModel:e.createModel,setCreateModel:e.setCreateModel,onCreate:e.onCreate,onSuggestWorkspace:()=>e.applyCreateWorkspaceSuggestion(),agents:e.data?.agents??[],duplicateSourceId:e.duplicateSourceId,onSelectDuplicateSource:e.onSelectDuplicateSource}),(0,Q.jsx)(Pt,{open:e.deleteDialogOpen,onOpenChange:t=>{e.setDeleteDialogOpen(t),t||(e.setDeleteTarget(null),e.setDeleteConfirmText(``))},busy:e.busy,deletePurge:e.deletePurge,deleteTarget:e.deleteTarget,deleteConfirmText:e.deleteConfirmText,onDeleteConfirmTextChange:e.setDeleteConfirmText,onConfirm:()=>{e.deleteTarget&&e.performDelete(e.deleteTarget,e.deletePurge)},onCancel:()=>e.setDeleteDialogOpen(!1),a:e.a})]}):(0,Q.jsxs)(gt,{gap:`gap-3`,padding:`px-3 py-8 sm:px-5 xl:px-6`,children:[(0,Q.jsx)(ht,{title:e.a.title}),(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.a.needToken})]})}export{dr as AgentsSettingsPanel};