@nextclaw/ui 0.12.11 → 0.12.13

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 (517) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/dist/assets/api-C51456xV.js +15 -0
  3. package/dist/assets/app-manager-provider-D_cKqqRG.js +1 -0
  4. package/dist/assets/app-navigation.config-Dve1W20Y.js +1 -0
  5. package/dist/assets/{book-open-BE8M56IM.js → book-open-B4mOKdz8.js} +1 -1
  6. package/dist/assets/channels-list-page-WJ7d4zMI.js +8 -0
  7. package/dist/assets/chat-DCi1-y8U.js +58 -0
  8. package/dist/assets/chat-page-CHKwiqPY.js +1 -0
  9. package/dist/assets/chunk-JZWAC4HX-ptDyT_1C.js +3 -0
  10. package/dist/assets/config-split-page-B3PRA_AV.js +1 -0
  11. package/dist/assets/{createLucideIcon-CCiTGX8L.js → createLucideIcon-C_GFKVuW.js} +1 -1
  12. package/dist/assets/desktop-update-config-gnna2NaS.js +1 -0
  13. package/dist/assets/{dialog-BghZFPch.js → dialog-BHcaU6NE.js} +1 -1
  14. package/dist/assets/{dist-Dd9cr-kz.js → dist-DtBFqZ6_.js} +1 -1
  15. package/dist/assets/doc-browser-CoKIUCJj.js +1 -0
  16. package/dist/assets/doc-browser-CwgI7ipB.js +1 -0
  17. package/dist/assets/doc-browser-DYKpRqe-.js +1 -0
  18. package/dist/assets/doc-browser-context-Dib9sS83.js +1 -0
  19. package/dist/assets/{es2015-CEAreese.js → es2015-BlNhrQUG.js} +1 -1
  20. package/dist/assets/{external-link-qsnCMhw1.js → external-link-DP2IJ7AM.js} +1 -1
  21. package/dist/assets/folder-BPwc278w.js +1 -0
  22. package/dist/assets/{hash-0zjWsNl-.js → hash-CvcvtMBq.js} +1 -1
  23. package/dist/assets/i18n-BnNAQpVM.js +1 -0
  24. package/dist/assets/index-CxzW1dQ9.js +2 -0
  25. package/dist/assets/index-mRmSAB-e.css +1 -0
  26. package/dist/assets/{key-round-BLe9D8ND.js → key-round-BQXmPSxD.js} +1 -1
  27. package/dist/assets/loader-circle-C6gg2m2a.js +1 -0
  28. package/dist/assets/{LogoBadge-DP8Ye7wJ.js → logo-badge-uB4SwANR.js} +1 -1
  29. package/dist/assets/{logos-_v5b2SdG.js → logos-BcELLmYh.js} +1 -1
  30. package/dist/assets/marketplace-page-0sEdt5sA.js +1 -0
  31. package/dist/assets/marketplace-page-DiqqX25V.js +49 -0
  32. package/dist/assets/mcp-marketplace-page-B8vmu9xe.js +1 -0
  33. package/dist/assets/mcp-marketplace-page-C_akqPwv.js +40 -0
  34. package/dist/assets/message-square-CLVODA23.js +1 -0
  35. package/dist/assets/model-config-B0L43HTL.js +1 -0
  36. package/dist/assets/notice-card-C9PFAR67.js +1 -0
  37. package/dist/assets/play-DeNVUA5C.js +1 -0
  38. package/dist/assets/plus-BptLViq1.js +1 -0
  39. package/dist/assets/popover-B8msg2FQ.js +1 -0
  40. package/dist/assets/provider-scoped-model-input-DeAo2Y65.js +1 -0
  41. package/dist/assets/providers-list-5_VShcn7.js +1 -0
  42. package/dist/assets/refresh-ccw-CeG203yU.js +1 -0
  43. package/dist/assets/remote-pzp4oLcL.js +1 -0
  44. package/dist/assets/rotate-cw-F7aThvYj.js +1 -0
  45. package/dist/assets/runtime-config-page-BuWmH7fe.js +1 -0
  46. package/dist/assets/{save-D4bObrmH.js → save-7ztImRj7.js} +1 -1
  47. package/dist/assets/search-DZSNKEGp.js +1 -0
  48. package/dist/assets/search-config-DJTm9Fno.js +1 -0
  49. package/dist/assets/secrets-config-DKFeFii1.js +3 -0
  50. package/dist/assets/{select-BILPf7zs.js → select-DRDejPLk.js} +1 -1
  51. package/dist/assets/sessions-config-page-DZrdd2zT.js +2 -0
  52. package/dist/assets/{setting-row-BATDgg4r.js → setting-row-BcF6eTW0.js} +1 -1
  53. package/dist/assets/settings-DjvNMJde.js +1 -0
  54. package/dist/assets/skeleton-5Mg6vZHN.js +1 -0
  55. package/dist/assets/sparkles-CyDTgTM4.js +1 -0
  56. package/dist/assets/status-dot-aQU9Mia4.js +1 -0
  57. package/dist/assets/{tabs-custom-Bx3cNhD-.js → tabs-custom-C4P7g4vR.js} +1 -1
  58. package/dist/assets/{tag-chip-zUaDE2-H.js → tag-chip-CVIqyMv7.js} +1 -1
  59. package/dist/assets/theme-provider-dHqcWU-j.js +1 -0
  60. package/dist/assets/tooltip-C6VPreZ7.js +1 -0
  61. package/dist/assets/{trash-2-CQUgYyRn.js → trash-2-C1cdqL6V.js} +1 -1
  62. package/dist/assets/use-config-DFja1sda.js +1 -0
  63. package/dist/assets/{useConfirmDialog-patAnl1g.js → use-confirm-dialog-DvIbSUX3.js} +1 -1
  64. package/dist/assets/use-infinite-scroll-loader-D8h0k-iL.js +1 -0
  65. package/dist/assets/use-viewport-layout-D-pjxsyz.js +1 -0
  66. package/dist/assets/x-BjMO7v8q.js +1 -0
  67. package/dist/index.html +39 -22
  68. package/module-structure.config.json +1 -1
  69. package/package.json +6 -6
  70. package/src/{components/providers/I18nProvider.tsx → app/components/i18n-provider.tsx} +1 -1
  71. package/src/{components → app/components}/layout/app-layout.test.tsx +50 -3
  72. package/src/app/components/layout/app-layout.tsx +54 -0
  73. package/src/{components → app/components}/layout/page-layout.tsx +1 -1
  74. package/src/{components → app/components}/layout/runtime-status-entry.test.tsx +2 -2
  75. package/src/{components → app/components}/layout/runtime-status-entry.tsx +3 -3
  76. package/src/app/components/layout/settings-entry-page.test.tsx +65 -0
  77. package/src/app/components/layout/settings-entry-page.tsx +13 -0
  78. package/src/{components → app/components}/layout/sidebar-items.tsx +2 -2
  79. package/src/{components → app/components}/layout/sidebar.layout.test.tsx +8 -7
  80. package/src/{components/layout/Sidebar.tsx → app/components/layout/sidebar.tsx} +21 -85
  81. package/src/{components/providers/ThemeProvider.tsx → app/components/theme-provider.tsx} +2 -2
  82. package/src/app/configs/app-navigation.config.ts +246 -0
  83. package/src/{hooks → app/hooks}/use-realtime-query-bridge.ts +2 -2
  84. package/src/app/hooks/use-viewport-layout.ts +15 -0
  85. package/src/{app.tsx → app/index.tsx} +138 -148
  86. package/src/app/managers/viewport-layout.manager.ts +73 -0
  87. package/src/app/stores/viewport-layout.store.ts +32 -0
  88. package/src/{test/setup.ts → app/test/vitest-setup.ts} +3 -3
  89. package/src/features/account/components/account-panel.tsx +6 -6
  90. package/src/{components/auth → features/account/components}/login-page.tsx +4 -4
  91. package/src/{hooks → features/account/hooks}/use-auth.test.ts +1 -1
  92. package/src/{hooks → features/account/hooks}/use-auth.ts +3 -3
  93. package/src/features/account/index.ts +1 -0
  94. package/src/features/account/managers/account.manager.ts +3 -3
  95. package/src/{components/agents → features/agents/components}/agent-dialogs.tsx +11 -11
  96. package/src/{components/agents → features/agents/components}/agents-page.test.tsx +12 -9
  97. package/src/{components/agents → features/agents/components}/agents-page.tsx +17 -17
  98. package/src/features/agents/index.ts +1 -0
  99. package/src/{components/config → features/channels/components}/channel-form-fields-section.tsx +11 -32
  100. package/src/{components/config/ChannelForm.test.tsx → features/channels/components/config/channel-form.test.tsx} +4 -4
  101. package/src/features/channels/components/config/channel-form.tsx +382 -0
  102. package/src/{components → features/channels/components}/config/weixin-channel-auth-section.test.tsx +6 -3
  103. package/src/features/channels/components/config/weixin-channel-auth-section.tsx +245 -0
  104. package/src/{hooks → features/channels/hooks}/use-channel-auth.ts +1 -1
  105. package/src/features/channels/index.ts +5 -0
  106. package/src/features/channels/pages/channels-list-page.test.tsx +288 -0
  107. package/src/{components/config/ChannelsList.tsx → features/channels/pages/channels-list-page.tsx} +57 -83
  108. package/src/{components/config/channel-form-fields.test.ts → features/channels/utils/channel-form-fields.utils.test.ts} +1 -1
  109. package/src/{components/config/channel-form-fields.ts → features/channels/utils/channel-form-fields.utils.ts} +1 -1
  110. package/src/{lib/channel-tutorials.ts → features/channels/utils/channel-tutorials.utils.ts} +2 -2
  111. package/src/{components/chat → features/chat/components}/chat-session-type-option-item.test.tsx +1 -1
  112. package/src/{components/chat → features/chat/components}/chat-session-type-option-item.tsx +4 -4
  113. package/src/{components/chat → features/chat/components}/chat-session-workspace-file-preview.test.tsx +4 -4
  114. package/src/{components/chat → features/chat/components}/chat-session-workspace-file-preview.tsx +12 -32
  115. package/src/{components/chat → features/chat/components}/chat-session-workspace-panel-nav.tsx +8 -20
  116. package/src/{components/chat → features/chat/components}/chat-session-workspace-panel.tsx +105 -65
  117. package/src/features/chat/components/chat-sidebar-list-mode-switch.tsx +28 -0
  118. package/src/{components/chat → features/chat/components}/chat-sidebar-project-groups.tsx +6 -6
  119. package/src/{components/chat → features/chat/components}/chat-sidebar-session-item.tsx +10 -10
  120. package/src/{components/chat/ChatWelcome.test.tsx → features/chat/components/chat-welcome.test.tsx} +1 -1
  121. package/src/{components/chat/ChatWelcome.tsx → features/chat/components/chat-welcome.tsx} +5 -10
  122. package/src/features/chat/components/config/sessions-config-detail-pane.tsx +244 -0
  123. package/src/{components/chat → features/chat/components/conversation}/chat-attachment-upload-limit.test.ts +1 -4
  124. package/src/features/chat/components/conversation/chat-conversation-header.tsx +146 -0
  125. package/src/{components/chat → features/chat/components/conversation}/chat-conversation-panel.test.tsx +31 -19
  126. package/src/{components/chat → features/chat/components/conversation}/chat-conversation-panel.tsx +28 -140
  127. package/src/{components/chat/containers → features/chat/components/conversation}/chat-input-bar.container.tsx +130 -133
  128. package/src/{components/chat/containers → features/chat/components/conversation}/chat-message-list.container.test.tsx +2 -2
  129. package/src/{components/chat/containers → features/chat/components/conversation}/chat-message-list.container.tsx +6 -6
  130. package/src/{components/chat → features/chat/components/conversation}/session-header/chat-session-header-actions.test.tsx +3 -3
  131. package/src/{components/chat → features/chat/components/conversation}/session-header/chat-session-header-actions.tsx +6 -6
  132. package/src/{components/chat → features/chat/components/conversation}/session-header/chat-session-header-menu-item.tsx +1 -1
  133. package/src/{components/chat → features/chat/components/conversation}/session-header/chat-session-project-badge.test.tsx +3 -3
  134. package/src/{components/chat → features/chat/components/conversation}/session-header/chat-session-project-badge.tsx +5 -5
  135. package/src/{components/chat → features/chat/components/conversation}/session-header/chat-session-project-dialog.tsx +2 -2
  136. package/src/features/chat/components/layout/chat-page-shell.test.tsx +61 -0
  137. package/src/{components/chat → features/chat/components/layout}/chat-page-shell.tsx +14 -17
  138. package/src/features/chat/components/layout/chat-sidebar-session-entry.tsx +82 -0
  139. package/src/features/chat/components/layout/chat-sidebar-toolbar.tsx +205 -0
  140. package/src/{components/chat/containers → features/chat/components/layout}/chat-sidebar.test.tsx +55 -13
  141. package/src/{components/chat/containers → features/chat/components/layout}/chat-sidebar.tsx +151 -198
  142. package/src/{components/chat/presenter/chat-presenter-context.tsx → features/chat/components/providers/chat-presenter.provider.tsx} +10 -31
  143. package/src/{components/common → features/chat/components/session}/session-context-icon.tsx +5 -5
  144. package/src/{components/common/SessionRunBadge.tsx → features/chat/components/session/session-run-badge.tsx} +3 -3
  145. package/src/{components/chat → features/chat/components}/workspace/chat-session-workspace-file-breadcrumbs.tsx +5 -15
  146. package/src/{components/chat/chat-input/chat-input-bar.controller.test.tsx → features/chat/hooks/use-chat-input-bar-controller.test.tsx} +1 -1
  147. package/src/{components → features}/chat/hooks/use-chat-session-label.ts +3 -4
  148. package/src/{components → features}/chat/hooks/use-chat-session-project.test.tsx +19 -19
  149. package/src/features/chat/hooks/use-chat-session-project.ts +34 -0
  150. package/src/{components/chat/useChatSessionTypeState.test.tsx → features/chat/hooks/use-chat-session-type-state.test.tsx} +2 -2
  151. package/src/{components/chat/useChatSessionTypeState.ts → features/chat/hooks/use-chat-session-type-state.ts} +3 -16
  152. package/src/{components → features}/chat/hooks/use-chat-session-update.test.tsx +19 -21
  153. package/src/{components → features}/chat/hooks/use-chat-session-update.ts +5 -7
  154. package/src/{components → features}/chat/hooks/use-chat-sidebar-session-label-editor.ts +4 -4
  155. package/src/{components/chat/useHydratedNcpAgent.test.tsx → features/chat/hooks/use-hydrated-ncp-agent.test.tsx} +2 -2
  156. package/src/{components/chat/useNcpAgentRuntime.test.tsx → features/chat/hooks/use-ncp-agent-runtime.test.tsx} +1 -1
  157. package/src/{components/chat/ncp/page/ncp-chat-derived-state.ts → features/chat/hooks/use-ncp-chat-derived-state.ts} +8 -8
  158. package/src/{components/chat/ncp/ncp-chat-page-data.ts → features/chat/hooks/use-ncp-chat-page-data.ts} +137 -80
  159. package/src/{hooks → features/chat/hooks}/use-ncp-chat-session-types.ts +1 -1
  160. package/src/{components/chat/ncp/session-conversation → features/chat/hooks}/use-ncp-child-session-tabs-view.ts +7 -7
  161. package/src/{components/chat/ncp/session-conversation → features/chat/hooks}/use-ncp-session-conversation.test.tsx +7 -3
  162. package/src/{components/chat/ncp/session-conversation → features/chat/hooks}/use-ncp-session-conversation.ts +33 -22
  163. package/src/{components/chat/ncp → features/chat/hooks}/use-ncp-session-list-view.ts +6 -6
  164. package/src/features/chat/index.ts +6 -0
  165. package/src/{components/chat → features/chat/managers}/chat-recent-models.manager.ts +1 -1
  166. package/src/{components/chat → features/chat/managers}/chat-recent-skills.manager.ts +1 -1
  167. package/src/{components → features}/chat/managers/chat-session-list.manager.test.ts +11 -7
  168. package/src/{components → features}/chat/managers/chat-session-list.manager.ts +8 -10
  169. package/src/{components/chat/chat-session-preference-sync.test.ts → features/chat/managers/chat-session-preference-sync.manager.test.ts} +18 -14
  170. package/src/{components/chat/chat-session-preference-sync.ts → features/chat/managers/chat-session-preference-sync.manager.ts} +7 -14
  171. package/src/{components → features}/chat/managers/chat-stream-actions.manager.ts +3 -2
  172. package/src/{components → features}/chat/managers/chat-ui.manager.ts +11 -3
  173. package/src/{components/chat/ncp/tests → features/chat/managers}/ncp-chat-input.manager.test.ts +4 -4
  174. package/src/{components/chat/ncp → features/chat/managers}/ncp-chat-input.manager.ts +16 -16
  175. package/src/{components/chat/ncp/ncp-chat.presenter.ts → features/chat/managers/ncp-chat-presenter.manager.ts} +5 -5
  176. package/src/{components/chat/ncp/tests → features/chat/managers}/ncp-chat-thread.manager.test.ts +11 -10
  177. package/src/{components/chat/ncp → features/chat/managers}/ncp-chat-thread.manager.ts +11 -13
  178. package/src/{lib → features/chat/managers}/recent-selection.manager.test.ts +1 -1
  179. package/src/{lib → features/chat/managers}/recent-selection.manager.ts +14 -14
  180. package/src/features/chat/pages/chat-page.tsx +6 -0
  181. package/src/{components/chat/chat-page-runtime.test.ts → features/chat/pages/ncp-chat-page.test.ts} +69 -4
  182. package/src/{components/chat/ncp → features/chat/pages}/ncp-chat-page.tsx +169 -117
  183. package/src/features/chat/pages/sessions-config-page.test.tsx +152 -0
  184. package/src/features/chat/pages/sessions-config-page.tsx +192 -0
  185. package/src/{components → features}/chat/stores/chat-input.store.ts +3 -3
  186. package/src/{components → features}/chat/stores/chat-session-list.store.ts +2 -4
  187. package/src/{components → features}/chat/stores/chat-thread.store.ts +3 -3
  188. package/src/features/chat/types/chat-input-bar.types.ts +44 -0
  189. package/src/{components/chat → features/chat/types}/chat-input.types.ts +1 -1
  190. package/src/features/chat/types/chat-message.types.ts +58 -0
  191. package/src/{components/chat/chat-stream/types.ts → features/chat/types/chat-stream.types.ts} +1 -1
  192. package/src/{components/chat/chat-composer-state.test.ts → features/chat/utils/chat-composer-state.utils.test.ts} +1 -1
  193. package/src/{components/chat/chat-composer-state.ts → features/chat/utils/chat-composer-state.utils.ts} +17 -19
  194. package/src/features/chat/utils/chat-inline-token.utils.test.ts +87 -0
  195. package/src/{components/chat → features/chat/utils}/chat-inline-token.utils.ts +22 -39
  196. package/src/{components/chat/adapters/chat-input-bar.adapter.test.ts → features/chat/utils/chat-input-bar.utils.test.ts} +2 -2
  197. package/src/{components/chat/adapters/chat-input-bar.adapter.ts → features/chat/utils/chat-input-bar.utils.ts} +18 -196
  198. package/src/features/chat/utils/chat-input-toolbar.utils.ts +191 -0
  199. package/src/{lib/chat-message.ts → features/chat/utils/chat-message-core.utils.ts} +1 -1
  200. package/src/{components/chat/adapters/chat-message-inline-content.adapter.ts → features/chat/utils/chat-message-inline-content.utils.ts} +2 -2
  201. package/src/features/chat/utils/chat-message-part.utils.ts +233 -0
  202. package/src/{components/chat/adapters/chat-message.session-request-tool-card.ts → features/chat/utils/chat-message-session-request-tool-card.utils.ts} +2 -2
  203. package/src/{components/chat/adapters/chat-message.session-spawn-tool-card.test.ts → features/chat/utils/chat-message-session-spawn-tool-card.utils.test.ts} +2 -2
  204. package/src/{components/chat/adapters/chat-message.summary-truncation.test.ts → features/chat/utils/chat-message-summary-truncation.utils.test.ts} +2 -2
  205. package/src/{components/chat/adapters/chat-message-tool-agent-id.test.ts → features/chat/utils/chat-message-tool-agent-id.utils.test.ts} +1 -1
  206. package/src/features/chat/utils/chat-message-tool-card.utils.ts +216 -0
  207. package/src/{components/chat/adapters/chat-message.adapter.test.ts → features/chat/utils/chat-message.utils.test.ts} +2 -2
  208. package/src/{components/chat/adapters/chat-message.adapter.ts → features/chat/utils/chat-message.utils.ts} +4 -4
  209. package/src/features/chat/utils/chat-runtime.utils.ts +235 -0
  210. package/src/{components/chat/chat-session-display.test.ts → features/chat/utils/chat-session-display.utils.test.ts} +2 -2
  211. package/src/{components/chat/chat-session-display.ts → features/chat/utils/chat-session-display.utils.ts} +5 -9
  212. package/src/{components/chat/chat-session-preference-governance.ts → features/chat/utils/chat-session-preference-governance.utils.ts} +51 -64
  213. package/src/{components/chat/chat-session-route.ts → features/chat/utils/chat-session-route.utils.ts} +1 -1
  214. package/src/{components/chat/adapters/file-operation/card.ts → features/chat/utils/file-operation/card.utils.ts} +3 -3
  215. package/src/{components/chat/adapters/file-operation/diff.ts → features/chat/utils/file-operation/diff.utils.ts} +9 -99
  216. package/src/features/chat/utils/file-operation/parsed-block.utils.ts +98 -0
  217. package/src/{components/chat/adapters/file-operation/record-readers.ts → features/chat/utils/file-operation/record-readers.utils.ts} +1 -1
  218. package/src/{components/chat/ncp/ncp-app-client-fetch.test.ts → features/chat/utils/ncp-app-client-fetch.utils.test.ts} +1 -1
  219. package/src/{components/chat/chat-input → features/chat/utils}/ncp-chat-input-availability.utils.test.ts +2 -2
  220. package/src/{components/chat/chat-input → features/chat/utils}/ncp-chat-input-availability.utils.ts +1 -1
  221. package/src/{components/chat/ncp/__tests__/ncp-session-adapter.cancelled-tool.test.ts → features/chat/utils/ncp-session-adapter.utils.cancelled-tool.test.ts} +2 -2
  222. package/src/{components/chat/ncp/ncp-session-adapter.test.ts → features/chat/utils/ncp-session-adapter.utils.test.ts} +3 -3
  223. package/src/{components/chat/ncp/ncp-session-adapter.ts → features/chat/utils/ncp-session-adapter.utils.ts} +3 -3
  224. package/src/{lib → features/chat/utils}/session-context.utils.test.ts +3 -3
  225. package/src/{lib → features/chat/utils}/session-context.utils.ts +3 -3
  226. package/src/{components/marketplace → features/marketplace/components}/marketplace-list-card.tsx +69 -124
  227. package/src/{components/marketplace → features/marketplace/components}/marketplace-localization.ts +1 -1
  228. package/src/{components/marketplace → features/marketplace/components}/marketplace-page-data.ts +2 -2
  229. package/src/features/marketplace/components/marketplace-page-detail.test.tsx +336 -0
  230. package/src/features/marketplace/components/marketplace-page-parts.tsx +121 -0
  231. package/src/{components/marketplace → features/marketplace/components}/marketplace-page.test.tsx +6 -6
  232. package/src/{components/marketplace → features/marketplace/components}/marketplace-page.tsx +92 -91
  233. package/src/{components/marketplace → features/marketplace/components}/mcp/mcp-marketplace-card.tsx +4 -4
  234. package/src/{components/marketplace → features/marketplace/components}/mcp/mcp-marketplace-dialogs.tsx +7 -7
  235. package/src/{components/marketplace → features/marketplace/components}/mcp/mcp-marketplace-doc.ts +3 -3
  236. package/src/{components/marketplace → features/marketplace/components}/mcp/mcp-marketplace-page.test.tsx +13 -9
  237. package/src/features/marketplace/components/mcp/mcp-marketplace-page.tsx +446 -0
  238. package/src/{hooks/useMarketplace.ts → features/marketplace/hooks/use-marketplace.ts} +5 -5
  239. package/src/{hooks/useMcpMarketplace.ts → features/marketplace/hooks/use-mcp-marketplace.ts} +3 -3
  240. package/src/features/marketplace/index.ts +26 -0
  241. package/src/{components/marketplace/marketplace-installed-cache.test.ts → features/marketplace/utils/marketplace-installed-cache.utils.test.ts} +2 -2
  242. package/src/{components/marketplace/marketplace-installed-cache.ts → features/marketplace/utils/marketplace-installed-cache.utils.ts} +1 -1
  243. package/src/{hooks/marketplace-list-pages.ts → features/marketplace/utils/marketplace-list-pages.utils.ts} +1 -1
  244. package/src/{pwa → features/pwa}/components/pwa-install-entry.test.tsx +2 -2
  245. package/src/{pwa → features/pwa}/components/pwa-install-entry.tsx +7 -7
  246. package/src/features/pwa/index.ts +4 -0
  247. package/src/{pwa/register-pwa.ts → features/pwa/managers/pwa-bootstrap.manager.ts} +2 -2
  248. package/src/{pwa → features/pwa}/managers/pwa-install.manager.test.ts +3 -3
  249. package/src/{pwa → features/pwa}/managers/pwa-install.manager.ts +5 -5
  250. package/src/{pwa → features/pwa}/managers/pwa-runtime.manager.ts +1 -1
  251. package/src/{pwa → features/pwa}/managers/pwa-shell-theme.manager.test.ts +1 -1
  252. package/src/{pwa → features/pwa}/managers/pwa-shell-theme.manager.ts +1 -1
  253. package/src/{pwa → features/pwa}/stores/pwa.store.ts +2 -2
  254. package/src/features/remote/components/remote-access-page.test.tsx +1 -1
  255. package/src/features/remote/components/remote-access-page.tsx +6 -6
  256. package/src/features/remote/hooks/use-remote-access.ts +2 -2
  257. package/src/features/remote/managers/remote-access.manager.ts +3 -3
  258. package/src/features/remote/services/remote-access-feedback.service.test.ts +2 -2
  259. package/src/features/remote/services/remote-access-feedback.service.ts +2 -2
  260. package/src/features/remote/services/remote-access-query.service.ts +2 -2
  261. package/src/features/remote/stores/remote-access.store.ts +1 -1
  262. package/src/features/settings/hooks/use-language-preference.ts +30 -0
  263. package/src/features/settings/index.ts +2 -0
  264. package/src/features/settings/pages/language-settings-page.test.tsx +36 -0
  265. package/src/features/settings/pages/language-settings-page.tsx +56 -0
  266. package/src/features/system-status/components/config/runtime-agent-list-card.tsx +72 -0
  267. package/src/features/system-status/components/config/runtime-binding-list-card.tsx +85 -0
  268. package/src/features/system-status/components/config/runtime-config-editor.tsx +131 -0
  269. package/src/features/system-status/components/config/runtime-config-overview.tsx +16 -0
  270. package/src/features/system-status/components/config/runtime-entry-list-card.tsx +58 -0
  271. package/src/features/system-status/components/config/runtime-settings-card.tsx +73 -0
  272. package/src/{components/config → features/system-status/components}/desktop-update-config.test.tsx +2 -2
  273. package/src/features/system-status/components/desktop-update-config.tsx +219 -0
  274. package/src/{components/config → features/system-status/components}/runtime-control-card.test.tsx +34 -54
  275. package/src/{components/config → features/system-status/components}/runtime-control-card.tsx +62 -78
  276. package/src/{components/config → features/system-status/components}/runtime-presence-card.test.tsx +2 -2
  277. package/src/{components/config → features/system-status/components}/runtime-presence-card.tsx +31 -46
  278. package/src/features/system-status/components/runtime-security-card.tsx +263 -0
  279. package/src/{components/config → features/system-status/components}/security-config.tsx +3 -3
  280. package/src/features/system-status/hooks/use-system-status.ts +2 -2
  281. package/src/features/system-status/index.ts +3 -11
  282. package/src/features/system-status/managers/system-status.manager.test.ts +28 -2
  283. package/src/features/system-status/managers/system-status.manager.ts +5 -7
  284. package/src/features/system-status/pages/runtime-config-page.test.tsx +140 -0
  285. package/src/features/system-status/pages/runtime-config-page.tsx +15 -0
  286. package/src/features/system-status/types/system-status.types.ts +2 -2
  287. package/src/features/system-status/utils/runtime-config-agent.utils.ts +152 -0
  288. package/src/features/system-status/utils/system-status.utils.test.ts +1 -1
  289. package/src/features/system-status/utils/system-status.utils.ts +2 -2
  290. package/src/index.css +1 -1
  291. package/src/platforms/desktop/components/desktop-app-shell.tsx +52 -0
  292. package/src/platforms/desktop/index.ts +1 -0
  293. package/src/platforms/desktop/managers/desktop-presence.manager.ts +1 -1
  294. package/src/platforms/desktop/managers/desktop-update.manager.ts +1 -1
  295. package/src/platforms/desktop/types/desktop-update.types.ts +4 -0
  296. package/src/platforms/mobile/components/chat-mobile-shell.tsx +20 -0
  297. package/src/platforms/mobile/components/mobile-app-shell.test.tsx +42 -0
  298. package/src/platforms/mobile/components/mobile-app-shell.tsx +48 -0
  299. package/src/platforms/mobile/components/mobile-bottom-nav.test.tsx +45 -0
  300. package/src/platforms/mobile/components/mobile-bottom-nav.tsx +71 -0
  301. package/src/platforms/mobile/components/mobile-settings-shell.tsx +39 -0
  302. package/src/platforms/mobile/components/mobile-topbar.tsx +41 -0
  303. package/src/platforms/mobile/index.ts +3 -0
  304. package/src/shared/components/__tests__/config-split-page.test.tsx +47 -0
  305. package/src/{components/common/AgentAvatar.tsx → shared/components/common/agent-avatar.tsx} +1 -1
  306. package/src/{components → shared/components}/common/agent-identity/agent-identity-avatar.tsx +2 -2
  307. package/src/shared/components/common/agent-identity/index.ts +3 -0
  308. package/src/{components → shared/components}/common/agent-identity/use-agent-identity.ts +3 -3
  309. package/src/{components/common/BrandHeader.tsx → shared/components/common/brand-header.tsx} +2 -2
  310. package/src/{components/common/KeyValueEditor.tsx → shared/components/common/key-value-editor.tsx} +4 -4
  311. package/src/{components/common/LogoBadge.tsx → shared/components/common/logo-badge.tsx} +1 -1
  312. package/src/{components/common/MaskedInput.tsx → shared/components/common/masked-input.tsx} +3 -3
  313. package/src/{components/common/ProviderScopedModelInput.tsx → shared/components/common/provider-scoped-model-input.tsx} +6 -6
  314. package/src/{components/common/SearchableModelInput.tsx → shared/components/common/searchable-model-input.tsx} +2 -2
  315. package/src/{components/common/StatusBadge.tsx → shared/components/common/status-badge.tsx} +3 -3
  316. package/src/{components → shared/components}/common/tag-input.tsx +3 -3
  317. package/src/{components → shared/components}/config/provider-form-support.ts +3 -3
  318. package/src/{components/config/ProviderForm.tsx → shared/components/config/provider-form.tsx} +14 -14
  319. package/src/{components → shared/components}/config/provider-models-section.tsx +7 -7
  320. package/src/{components → shared/components}/config/providers-list.test.tsx +19 -19
  321. package/src/{components/config/ProvidersList.tsx → shared/components/config/providers-list.tsx} +56 -54
  322. package/src/shared/components/config/secrets-config-form.tsx +407 -0
  323. package/src/shared/components/config/secrets-config.test.tsx +90 -0
  324. package/src/shared/components/config/secrets-config.tsx +25 -0
  325. package/src/{components/config → shared/components}/config-split-page.tsx +55 -9
  326. package/src/{components/config/CronConfig.tsx → shared/components/cron-config.tsx} +63 -96
  327. package/src/shared/components/doc-browser/doc-browser-context.test.tsx +102 -0
  328. package/src/{components/doc-browser/DocBrowserContext.tsx → shared/components/doc-browser/doc-browser-context.tsx} +98 -45
  329. package/src/shared/components/doc-browser/doc-browser.test.tsx +72 -0
  330. package/src/{components/doc-browser/DocBrowser.tsx → shared/components/doc-browser/doc-browser.tsx} +60 -34
  331. package/src/shared/components/doc-browser/index.ts +3 -0
  332. package/src/{components/doc-browser/useDocLinkInterceptor.ts → shared/components/doc-browser/use-doc-link-interceptor.ts} +1 -1
  333. package/src/{components/config/ModelConfig.test.tsx → shared/components/model-config.test.tsx} +4 -4
  334. package/src/shared/components/model-config.tsx +151 -0
  335. package/src/{components → shared/components}/path-picker/server-path-picker-dialog.test.tsx +3 -3
  336. package/src/{components → shared/components}/path-picker/server-path-picker-dialog.tsx +7 -7
  337. package/src/{components/config → shared/components}/provider-advanced-settings-section.tsx +5 -18
  338. package/src/{components/config → shared/components}/provider-auth-section.tsx +7 -24
  339. package/src/{components/config → shared/components}/provider-enabled-field.tsx +4 -8
  340. package/src/{components/config → shared/components}/provider-pill-selector.tsx +3 -15
  341. package/src/{components/config → shared/components}/provider-status-badge.tsx +3 -9
  342. package/src/{components/config/SearchConfig.test.tsx → shared/components/search-config.test.tsx} +3 -3
  343. package/src/shared/components/search-config.tsx +496 -0
  344. package/src/{components → shared/components}/ui/action-link.tsx +1 -1
  345. package/src/{components → shared/components}/ui/button.tsx +1 -1
  346. package/src/{components → shared/components}/ui/card.tsx +1 -1
  347. package/src/{components → shared/components}/ui/config-card.tsx +1 -1
  348. package/src/{components → shared/components}/ui/confirm-dialog.tsx +3 -3
  349. package/src/{components → shared/components}/ui/dialog.tsx +1 -1
  350. package/src/{components/ui/HighlightCard.tsx → shared/components/ui/highlight-card.tsx} +1 -1
  351. package/src/{components → shared/components}/ui/input.tsx +1 -1
  352. package/src/{components → shared/components}/ui/label.tsx +1 -1
  353. package/src/{components → shared/components}/ui/notice-card.tsx +1 -1
  354. package/src/{components → shared/components}/ui/popover.tsx +1 -1
  355. package/src/{components → shared/components}/ui/scroll-area.tsx +1 -1
  356. package/src/{components → shared/components}/ui/select.tsx +1 -1
  357. package/src/{components → shared/components}/ui/setting-row.tsx +1 -1
  358. package/src/{components → shared/components}/ui/skeleton.tsx +1 -1
  359. package/src/{components → shared/components}/ui/status-dot.tsx +1 -1
  360. package/src/{components → shared/components}/ui/switch.tsx +1 -1
  361. package/src/{components → shared/components}/ui/tabs-custom.tsx +2 -2
  362. package/src/{components → shared/components}/ui/tabs.tsx +1 -1
  363. package/src/{components → shared/components}/ui/tag-chip.tsx +1 -1
  364. package/src/{components → shared/components}/ui/textarea.tsx +1 -1
  365. package/src/{components → shared/components}/ui/tooltip.tsx +1 -1
  366. package/src/{hooks/agents/useAgents.ts → shared/hooks/use-agents.ts} +2 -2
  367. package/src/{hooks/useConfig.ts → shared/hooks/use-config.ts} +4 -4
  368. package/src/{hooks/useConfirmDialog.tsx → shared/hooks/use-confirm-dialog.tsx} +2 -2
  369. package/src/{hooks/server-path → shared/hooks}/use-server-path-browse.ts +1 -1
  370. package/src/{hooks/server-path → shared/hooks}/use-server-path-read.ts +1 -1
  371. package/src/{api → shared/lib/api}/api-base.test.ts +2 -2
  372. package/src/{api → shared/lib/api}/client.test.ts +2 -2
  373. package/src/{api → shared/lib/api}/client.ts +1 -1
  374. package/src/shared/lib/api/index.ts +20 -0
  375. package/src/{api → shared/lib/api}/ncp-session-query-cache.test.ts +2 -2
  376. package/src/{api → shared/lib/api}/ncp-session-query-cache.ts +1 -1
  377. package/src/{api → shared/lib/api}/ncp-session.test.ts +3 -3
  378. package/src/{lib → shared/lib/app-resource-uri}/app-resource-uri.test.ts +1 -1
  379. package/src/{lib/config-hints.ts → shared/lib/config-hints/index.ts} +1 -1
  380. package/src/{lib/i18n.ts → shared/lib/i18n/index.ts} +11 -11
  381. package/src/shared/lib/i18n/runtime/i18n-language-owner.test.ts +94 -0
  382. package/src/{lib/i18n-runtime → shared/lib/i18n/runtime}/i18n-language-owner.ts +15 -1
  383. package/src/{lib/provider-models.ts → shared/lib/provider-models/index.ts} +1 -1
  384. package/src/shared/lib/session-project/index.ts +2 -0
  385. package/src/{lib → shared/lib}/session-project/workspace-file-breadcrumb.test.ts +1 -1
  386. package/src/{lib → shared/lib}/session-project/workspace-file-breadcrumb.ts +1 -1
  387. package/src/{transport → shared/lib/transport}/app-client.service.ts +2 -3
  388. package/src/{transport → shared/lib/transport}/app-client.test.ts +8 -2
  389. package/src/{transport → shared/lib/transport}/local-transport.service.ts +6 -8
  390. package/src/{transport/remote.transport.ts → shared/lib/transport/remote-transport.service.ts} +14 -15
  391. package/src/{transport → shared/lib/transport}/remote.transport.test.ts +5 -5
  392. package/src/{transport → shared/lib/transport}/sse-stream.test.ts +2 -2
  393. package/src/{transport/sse-stream.ts → shared/lib/transport/sse-stream.utils.ts} +13 -11
  394. package/src/{transport → shared/lib/transport}/transport.types.ts +1 -1
  395. package/src/{lib/ui-document-title.ts → shared/lib/ui-document-title/index.ts} +1 -1
  396. package/tsconfig.json +20 -0
  397. package/vite.config.ts +20 -0
  398. package/vitest.config.ts +21 -1
  399. package/dist/assets/ChannelsList-SQ7Oxotv.js +0 -8
  400. package/dist/assets/DocBrowser-BCO2k6XD.js +0 -1
  401. package/dist/assets/DocBrowser-rDOjI3ga.js +0 -1
  402. package/dist/assets/DocBrowserContext-BUq3Wo8O.js +0 -1
  403. package/dist/assets/ModelConfig-C77Ae9ru.js +0 -1
  404. package/dist/assets/ProviderScopedModelInput-CEnK61uo.js +0 -1
  405. package/dist/assets/ProvidersList-BCupBayq.js +0 -1
  406. package/dist/assets/RuntimeConfig-Ad-CAcmy.js +0 -1
  407. package/dist/assets/SearchConfig-BfCz4wJ4.js +0 -1
  408. package/dist/assets/SecretsConfig-DjmBIhyy.js +0 -3
  409. package/dist/assets/SessionsConfig-CvjxU40H.js +0 -2
  410. package/dist/assets/chat-page-JKC6ln-y.js +0 -58
  411. package/dist/assets/chat-session-display-YcRMrAMa.js +0 -1
  412. package/dist/assets/chunk-JZWAC4HX-erTUn3b8.js +0 -3
  413. package/dist/assets/client-CszWMVKi.js +0 -7
  414. package/dist/assets/config-split-page-BAGSzUR3.js +0 -1
  415. package/dist/assets/desktop-DfkLlkG2.js +0 -1
  416. package/dist/assets/desktop-update-config-BXeGlqHD.js +0 -1
  417. package/dist/assets/dist-ZwoAXs46.js +0 -9
  418. package/dist/assets/download-D7LOizcW.js +0 -1
  419. package/dist/assets/i18n-DvzXOGQX.js +0 -1
  420. package/dist/assets/index-DvVTC9FF.css +0 -1
  421. package/dist/assets/index-lr6rQUSd.js +0 -2
  422. package/dist/assets/loader-circle-wj7kARHv.js +0 -1
  423. package/dist/assets/marketplace-page-CAAk1Khc.js +0 -1
  424. package/dist/assets/marketplace-page-CfCiq90S.js +0 -49
  425. package/dist/assets/mcp-marketplace-page-D0Pp9Hs-.js +0 -40
  426. package/dist/assets/play-o6NmwGTi.js +0 -1
  427. package/dist/assets/plus-I9pBS4Fl.js +0 -1
  428. package/dist/assets/refresh-cw-MNqgR3LZ.js +0 -1
  429. package/dist/assets/remote-C9fXm4V5.js +0 -1
  430. package/dist/assets/search-DxmL3IWE.js +0 -1
  431. package/dist/assets/security-config-BUm6FFfl.js +0 -1
  432. package/dist/assets/skeleton-COKMAnJy.js +0 -1
  433. package/dist/assets/switch-CBOzecWS.js +0 -1
  434. package/dist/assets/use-infinite-scroll-loader-B5V2Klve.js +0 -1
  435. package/dist/assets/useMutation-__AYv-Pz.js +0 -1
  436. package/dist/assets/x-BHUGQIUv.js +0 -1
  437. package/src/components/chat/README.md +0 -2
  438. package/src/components/chat/adapters/chat-message-part.adapter.ts +0 -472
  439. package/src/components/chat/chat-inline-token.utils.test.ts +0 -87
  440. package/src/components/chat/chat-page.tsx +0 -6
  441. package/src/components/chat/chat-sidebar-list-mode-switch.tsx +0 -43
  442. package/src/components/chat/hooks/use-chat-session-project.ts +0 -35
  443. package/src/components/chat/index.ts +0 -1
  444. package/src/components/chat/ncp/README.md +0 -3
  445. package/src/components/chat/ncp/ncp-chat-page-data.test.ts +0 -79
  446. package/src/components/chat/nextclaw/index.ts +0 -23
  447. package/src/components/common/agent-identity/index.ts +0 -3
  448. package/src/components/config/ChannelForm.tsx +0 -338
  449. package/src/components/config/ChannelsList.test.tsx +0 -309
  450. package/src/components/config/ModelConfig.tsx +0 -156
  451. package/src/components/config/README.md +0 -2
  452. package/src/components/config/RuntimeConfig.tsx +0 -588
  453. package/src/components/config/SearchConfig.tsx +0 -513
  454. package/src/components/config/SecretsConfig.tsx +0 -469
  455. package/src/components/config/SessionsConfig.tsx +0 -437
  456. package/src/components/config/desktop-update-config.tsx +0 -273
  457. package/src/components/config/runtime-config-agent.utils.ts +0 -96
  458. package/src/components/config/runtime-security-card.tsx +0 -276
  459. package/src/components/config/weixin-channel-auth-section.tsx +0 -305
  460. package/src/components/doc-browser/index.ts +0 -3
  461. package/src/components/layout/AppLayout.tsx +0 -82
  462. package/src/components/marketplace/marketplace-page-parts.tsx +0 -94
  463. package/src/components/marketplace/mcp/mcp-marketplace-page.tsx +0 -414
  464. package/src/hooks/README.md +0 -3
  465. package/src/hooks/useObservable.ts +0 -20
  466. package/src/lib/chat-runtime-utils.ts +0 -250
  467. package/src/stores/ui.store.ts +0 -14
  468. /package/dist/assets/{config-hints-DSQQbeOA.js → config-hints-CPNzbMEp.js} +0 -0
  469. /package/src/{components/layout/Header.tsx → app/components/layout/header.tsx} +0 -0
  470. /package/src/{styles → app/styles}/design-system.css +0 -0
  471. /package/src/{components/chat/chat-input/chat-input-bar.controller.ts → features/chat/hooks/use-chat-input-bar-controller.ts} +0 -0
  472. /package/src/{lib/session-run-status.ts → features/chat/types/session-run-status.types.ts} +0 -0
  473. /package/src/{components/chat/adapters/chat-message.partial-json.ts → features/chat/utils/chat-message-partial-json.utils.ts} +0 -0
  474. /package/src/{components/chat/adapters/chat-message-tool-agent-id.ts → features/chat/utils/chat-message-tool-agent-id.utils.ts} +0 -0
  475. /package/src/{components/chat/adapters/file-operation/line-builder.ts → features/chat/utils/file-operation/line-builder.utils.ts} +0 -0
  476. /package/src/{components/chat/ncp/ncp-app-client-fetch.ts → features/chat/utils/ncp-app-client-fetch.utils.ts} +0 -0
  477. /package/src/{components/marketplace → features/marketplace/components}/marketplace-detail-doc.ts +0 -0
  478. /package/src/{pwa → features/pwa/types}/pwa.types.ts +0 -0
  479. /package/src/{pwa/pwa-install-banner.storage.ts → features/pwa/utils/pwa-install-banner.utils.ts} +0 -0
  480. /package/src/{hooks → shared/hooks}/use-infinite-scroll-loader.ts +0 -0
  481. /package/src/{api → shared/lib/api}/agents.ts +0 -0
  482. /package/src/{api → shared/lib/api}/api-base.ts +0 -0
  483. /package/src/{api → shared/lib/api}/auth.types.ts +0 -0
  484. /package/src/{api → shared/lib/api}/channel-auth.ts +0 -0
  485. /package/src/{api → shared/lib/api}/channel-auth.types.ts +0 -0
  486. /package/src/{api → shared/lib/api}/chat-session-type.types.ts +0 -0
  487. /package/src/{api → shared/lib/api}/config.ts +0 -0
  488. /package/src/{api → shared/lib/api}/marketplace.ts +0 -0
  489. /package/src/{api → shared/lib/api}/mcp-marketplace.ts +0 -0
  490. /package/src/{api → shared/lib/api}/ncp-attachments.ts +0 -0
  491. /package/src/{api → shared/lib/api}/ncp-session.ts +0 -0
  492. /package/src/{api → shared/lib/api}/raw-client.test.ts +0 -0
  493. /package/src/{api → shared/lib/api}/raw-client.utils.ts +0 -0
  494. /package/src/{api → shared/lib/api}/remote.ts +0 -0
  495. /package/src/{api → shared/lib/api}/remote.types.ts +0 -0
  496. /package/src/{api → shared/lib/api}/runtime-control.ts +0 -0
  497. /package/src/{api → shared/lib/api}/runtime-control.types.ts +0 -0
  498. /package/src/{api → shared/lib/api}/server-path.ts +0 -0
  499. /package/src/{api → shared/lib/api}/types.ts +0 -0
  500. /package/src/{lib/app-resource-uri.ts → shared/lib/app-resource-uri/index.ts} +0 -0
  501. /package/src/{lib/i18n.agents.ts → shared/lib/i18n/agents.ts} +0 -0
  502. /package/src/{lib/i18n.channel-auth.ts → shared/lib/i18n/channel-auth.ts} +0 -0
  503. /package/src/{lib/i18n.channels.ts → shared/lib/i18n/channels.ts} +0 -0
  504. /package/src/{lib/i18n.chat.ts → shared/lib/i18n/chat.ts} +0 -0
  505. /package/src/{lib → shared/lib/i18n}/desktop-update-labels.utils.ts +0 -0
  506. /package/src/{lib/i18n.marketplace.ts → shared/lib/i18n/marketplace.ts} +0 -0
  507. /package/src/{lib/i18n.pwa.ts → shared/lib/i18n/pwa.ts} +0 -0
  508. /package/src/{lib/i18n.remote.ts → shared/lib/i18n/remote.ts} +0 -0
  509. /package/src/{lib/i18n-runtime → shared/lib/i18n/runtime}/i18n.path-picker.ts +0 -0
  510. /package/src/{lib/i18n.runtime-control.ts → shared/lib/i18n/runtime-control.ts} +0 -0
  511. /package/src/{lib/i18n.search.ts → shared/lib/i18n/search.ts} +0 -0
  512. /package/src/{lib/logos.ts → shared/lib/logos/index.ts} +0 -0
  513. /package/src/{lib → shared/lib}/session-project/session-project.utils.ts +0 -0
  514. /package/src/{lib/theme.ts → shared/lib/theme/index.ts} +0 -0
  515. /package/src/{transport → shared/lib/transport}/index.ts +0 -0
  516. /package/src/{transport/transport-websocket-url.ts → shared/lib/transport/transport-websocket-url.utils.ts} +0 -0
  517. /package/src/{lib/utils.ts → shared/lib/utils/index.ts} +0 -0
@@ -0,0 +1,382 @@
1
+ import { useMemo, useState, useSyncExternalStore } from 'react';
2
+ import type { Dispatch, FormEvent, SetStateAction } from 'react';
3
+ import { BookOpen, ChevronDown } from 'lucide-react';
4
+ import { toast } from 'sonner';
5
+ import { LogoBadge } from '@/shared/components/common/logo-badge';
6
+ import { Button } from '@/shared/components/ui/button';
7
+ import { StatusDot } from '@/shared/components/ui/status-dot';
8
+ import { appClient } from '@/shared/lib/transport';
9
+ import { useConfig, useConfigMeta, useConfigSchema, useExecuteConfigAction, useUpdateChannel } from '@/shared/hooks/use-config';
10
+ import type { ConfigActionManifest, ConfigUiHints } from '@/shared/lib/api';
11
+ import { ChannelFormFieldsSection } from '@/features/channels/components/channel-form-fields-section';
12
+ import { WeixinChannelAuthSection } from '@/features/channels/components/config/weixin-channel-auth-section';
13
+ import { buildChannelFormDefinitions, type ChannelField, type ChannelFormBlock, type ChannelFormFieldSection } from '@/features/channels/utils/channel-form-fields.utils';
14
+ import { ConfigSplitDetailPane, ConfigSplitEmptyPane, ConfigSplitPaneBody, ConfigSplitPaneFooter, ConfigSplitPaneHeader } from '@/shared/components/config-split-page';
15
+ import { hintForPath } from '@/shared/lib/config-hints';
16
+ import { resolveChannelTutorialUrl } from '@/features/channels/utils/channel-tutorials.utils';
17
+ import { t } from '@/shared/lib/i18n';
18
+ import { getChannelLogo } from '@/shared/lib/logos';
19
+ import { cn } from '@/shared/lib/utils';
20
+
21
+ type ChannelFormProps = { channelName?: string };
22
+ type ChannelApplyState = { status: 'applying' | 'applied' | 'failed'; message?: string } | null;
23
+ type ChannelFormEditorProps = {
24
+ actions: ConfigActionManifest[];
25
+ channelConfig: Record<string, unknown>;
26
+ channelLabel?: string;
27
+ channelName: string;
28
+ fields: ChannelField[];
29
+ layoutBlocks: ChannelFormBlock[];
30
+ tutorialUrl?: string;
31
+ uiHints?: ConfigUiHints;
32
+ };
33
+
34
+ const EMPTY_CHANNEL_FIELDS: ChannelField[] = [];
35
+ const DEFAULT_CHANNEL_LAYOUT_BLOCKS: ChannelFormBlock[] = [{ type: 'fields', section: 'all' }];
36
+ const channelApplyListeners = new Set<() => void>();
37
+ const channelApplySnapshots = new Map<string, ChannelApplyState>();
38
+ let channelApplyUnsubscribe: null | (() => void) = null;
39
+
40
+ function isRecord(value: unknown): value is Record<string, unknown> {
41
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
42
+ }
43
+
44
+ function deepMergeRecords(base: Record<string, unknown>, patch: Record<string, unknown>): Record<string, unknown> {
45
+ const next: Record<string, unknown> = { ...base };
46
+ for (const [key, value] of Object.entries(patch)) {
47
+ next[key] = isRecord(next[key]) && isRecord(value) ? deepMergeRecords(next[key] as Record<string, unknown>, value) : value;
48
+ }
49
+ return next;
50
+ }
51
+
52
+ function buildScopeDraft(scope: string, value: Record<string, unknown>) {
53
+ const output: Record<string, unknown> = {};
54
+ let cursor = output;
55
+ const segments = scope.split('.');
56
+ for (let index = 0; index < segments.length - 1; index += 1) {
57
+ cursor[segments[index]] = {};
58
+ cursor = cursor[segments[index]] as Record<string, unknown>;
59
+ }
60
+ cursor[segments[segments.length - 1]] = value;
61
+ return output;
62
+ }
63
+
64
+ function resolveFieldsForSection(fields: ChannelField[], section: ChannelFormFieldSection) {
65
+ return section === 'all' ? fields : fields.filter((field) => section === 'primary' ? field.section === 'primary' : field.section !== 'primary');
66
+ }
67
+
68
+ function buildJsonDrafts(channelConfig: Record<string, unknown>, fields: ChannelField[]) {
69
+ const nextDrafts: Record<string, string> = {};
70
+ fields.filter((field) => field.type === 'json').forEach((field) => {
71
+ nextDrafts[field.name] = JSON.stringify(channelConfig[field.name] ?? {}, null, 2);
72
+ });
73
+ return nextDrafts;
74
+ }
75
+
76
+ function ensureChannelApplySubscription() {
77
+ if (channelApplyUnsubscribe) {
78
+ return;
79
+ }
80
+ channelApplyUnsubscribe = appClient.subscribe((event) => {
81
+ if (event.type !== 'channel.config.apply-status') {
82
+ return;
83
+ }
84
+ channelApplySnapshots.set(
85
+ event.payload.channel,
86
+ event.payload.status === 'started'
87
+ ? { status: 'applying' }
88
+ : event.payload.status === 'succeeded'
89
+ ? { status: 'applied' }
90
+ : { status: 'failed', message: event.payload.message }
91
+ );
92
+ channelApplyListeners.forEach((listener) => listener());
93
+ });
94
+ }
95
+
96
+ function subscribeChannelApplyStore(listener: () => void) {
97
+ channelApplyListeners.add(listener);
98
+ ensureChannelApplySubscription();
99
+ return () => {
100
+ channelApplyListeners.delete(listener);
101
+ if (!channelApplyListeners.size && channelApplyUnsubscribe) {
102
+ channelApplyUnsubscribe();
103
+ channelApplyUnsubscribe = null;
104
+ channelApplySnapshots.clear();
105
+ }
106
+ };
107
+ }
108
+
109
+ function useChannelApplyState(channelName: string | undefined) {
110
+ return useSyncExternalStore(subscribeChannelApplyStore, () => channelName ? channelApplySnapshots.get(channelName) ?? null : null, () => null);
111
+ }
112
+
113
+ function buildChannelApplyStatusView(channelApplyState: ChannelApplyState) {
114
+ if (!channelApplyState) {
115
+ return null;
116
+ }
117
+ if (channelApplyState.status === 'applying') {
118
+ return { className: 'text-amber-600', label: t('channelConfigApplying') };
119
+ }
120
+ if (channelApplyState.status === 'applied') {
121
+ return { className: 'text-emerald-600', label: t('channelConfigApplied') };
122
+ }
123
+ return { className: 'text-red-600', label: `${t('channelConfigApplyFailed')}${channelApplyState.message ? `: ${channelApplyState.message}` : ''}` };
124
+ }
125
+
126
+ function ChannelFormHeader(props: {
127
+ channelApplyStatus: ReturnType<typeof buildChannelApplyStatusView>;
128
+ channelLabel?: string;
129
+ channelName: string;
130
+ enabled: boolean;
131
+ tutorialUrl?: string;
132
+ }) {
133
+ return (
134
+ <ConfigSplitPaneHeader className="px-6 py-5">
135
+ <div className="flex flex-wrap items-center justify-between gap-3">
136
+ <div className="min-w-0">
137
+ <div className="flex items-center gap-3">
138
+ <LogoBadge
139
+ name={props.channelName}
140
+ src={getChannelLogo(props.channelName)}
141
+ className={cn('h-9 w-9 rounded-lg border', props.enabled ? 'border-primary/30 bg-white' : 'border-gray-200/70 bg-white')}
142
+ imgClassName="h-5 w-5 object-contain"
143
+ fallback={<span className="text-sm font-semibold uppercase text-gray-500">{props.channelName[0]}</span>}
144
+ />
145
+ <h3 className="truncate text-lg font-semibold text-gray-900 capitalize">{props.channelLabel}</h3>
146
+ </div>
147
+ <p className="mt-2 text-sm text-gray-500">{t('channelsFormDescription')}</p>
148
+ {props.channelApplyStatus ? <p className={cn('mt-2 text-xs font-medium', props.channelApplyStatus.className)}>{props.channelApplyStatus.label}</p> : null}
149
+ {props.tutorialUrl ? (
150
+ <a href={props.tutorialUrl} className="mt-2 inline-flex items-center gap-1.5 text-xs text-primary transition-colors hover:text-primary-hover">
151
+ <BookOpen className="h-3.5 w-3.5" />
152
+ {t('channelsGuideTitle')}
153
+ </a>
154
+ ) : null}
155
+ </div>
156
+ <StatusDot status={props.enabled ? 'active' : 'inactive'} label={props.enabled ? t('statusActive') : t('statusInactive')} />
157
+ </div>
158
+ </ConfigSplitPaneHeader>
159
+ );
160
+ }
161
+
162
+ function ChannelFormBlocks(props: {
163
+ channelConfig: Record<string, unknown>;
164
+ channelName: string;
165
+ enabled: boolean;
166
+ fields: ChannelField[];
167
+ formData: Record<string, unknown>;
168
+ jsonDrafts: Record<string, string>;
169
+ layoutBlocks: ChannelFormBlock[];
170
+ setJsonDrafts: Dispatch<SetStateAction<Record<string, string>>>;
171
+ uiHints?: ConfigUiHints;
172
+ updateField: (name: string, value: unknown) => void;
173
+ disabled: boolean;
174
+ }) {
175
+ return (
176
+ <>
177
+ {props.layoutBlocks.map((block, index) => {
178
+ if (block.type === 'fields') {
179
+ const blockFields = resolveFieldsForSection(props.fields, block.section);
180
+ if (blockFields.length === 0) {
181
+ return null;
182
+ }
183
+ const content = (
184
+ <ChannelFormFieldsSection
185
+ channelName={props.channelName}
186
+ fields={blockFields}
187
+ formData={props.formData}
188
+ jsonDrafts={props.jsonDrafts}
189
+ setJsonDrafts={props.setJsonDrafts}
190
+ updateField={props.updateField}
191
+ uiHints={props.uiHints}
192
+ />
193
+ );
194
+ if (!block.collapsible) {
195
+ return <div key={`${block.type}-${block.section}-${index}`}>{content}</div>;
196
+ }
197
+ return (
198
+ <details key={`${block.type}-${block.section}-${index}`} className="group rounded-2xl border border-gray-200/80 bg-white">
199
+ <summary className="flex cursor-pointer list-none items-center justify-between gap-3 px-5 py-4 text-sm font-medium text-gray-900">
200
+ <div>
201
+ <p>{block.collapsible.title}</p>
202
+ {block.collapsible.description ? <p className="mt-1 text-xs font-normal text-gray-500">{block.collapsible.description}</p> : null}
203
+ </div>
204
+ <ChevronDown className="h-4 w-4 text-gray-400 transition-transform group-open:rotate-180" />
205
+ </summary>
206
+ <div className="space-y-6 border-t border-gray-100 px-5 py-5">{content}</div>
207
+ </details>
208
+ );
209
+ }
210
+ return block.sectionId === 'weixin-auth' ? (
211
+ <WeixinChannelAuthSection
212
+ key={`${block.type}-${block.sectionId}-${index}`}
213
+ channelConfig={props.channelConfig}
214
+ formData={props.formData}
215
+ channelEnabled={props.enabled}
216
+ disabled={props.disabled}
217
+ />
218
+ ) : null;
219
+ })}
220
+ </>
221
+ );
222
+ }
223
+
224
+ function ChannelFormEditor(props: ChannelFormEditorProps) {
225
+ const updateChannel = useUpdateChannel();
226
+ const executeAction = useExecuteConfigAction();
227
+ const [formData, setFormData] = useState<Record<string, unknown>>(() => ({ ...props.channelConfig }));
228
+ const [jsonDrafts, setJsonDrafts] = useState<Record<string, string>>(() => buildJsonDrafts(props.channelConfig, props.fields));
229
+ const [runningActionId, setRunningActionId] = useState<string | null>(null);
230
+ const channelApplyStatus = buildChannelApplyStatusView(useChannelApplyState(props.channelName));
231
+ const enabled = typeof formData.enabled === 'boolean' ? formData.enabled : Boolean(props.channelConfig.enabled);
232
+ const disabled = updateChannel.isPending || Boolean(runningActionId);
233
+
234
+ const updateField = (name: string, value: unknown) => setFormData((prev) => ({ ...prev, [name]: value }));
235
+
236
+ const handleSubmit = (event: FormEvent) => {
237
+ event.preventDefault();
238
+ const payload: Record<string, unknown> = { ...formData };
239
+ for (const field of props.fields) {
240
+ if (field.type === 'password') {
241
+ const value = payload[field.name];
242
+ if (typeof value !== 'string' || value.length === 0) {
243
+ delete payload[field.name];
244
+ }
245
+ }
246
+ if (field.type === 'json') {
247
+ try {
248
+ payload[field.name] = (jsonDrafts[field.name] ?? '').trim() ? JSON.parse(jsonDrafts[field.name]) : {};
249
+ } catch {
250
+ toast.error(`${t('invalidJson')}: ${field.name}`);
251
+ return;
252
+ }
253
+ }
254
+ }
255
+ updateChannel.mutate({ channel: props.channelName, data: payload });
256
+ };
257
+
258
+ const applyActionPatchToForm = (patch?: Record<string, unknown>) => {
259
+ if (!isRecord(patch?.channels) || !isRecord(patch.channels[props.channelName])) {
260
+ return;
261
+ }
262
+ const channelPatch = patch.channels[props.channelName] as Record<string, unknown>;
263
+ setFormData((prev) => deepMergeRecords(prev, channelPatch));
264
+ setJsonDrafts((prev) => {
265
+ const nextDrafts = { ...prev };
266
+ let changed = false;
267
+ for (const field of props.fields) {
268
+ if (field.type !== 'json' || !Object.prototype.hasOwnProperty.call(channelPatch, field.name)) {
269
+ continue;
270
+ }
271
+ nextDrafts[field.name] = JSON.stringify(channelPatch[field.name] ?? {}, null, 2);
272
+ changed = true;
273
+ }
274
+ return changed ? nextDrafts : prev;
275
+ });
276
+ };
277
+
278
+ const handleManualAction = async (action: ConfigActionManifest) => {
279
+ setRunningActionId(action.id);
280
+ try {
281
+ const scope = `channels.${props.channelName}`;
282
+ let nextData = { ...formData };
283
+ if (action.saveBeforeRun) {
284
+ nextData = { ...nextData, ...(action.savePatch ?? {}) };
285
+ setFormData(nextData);
286
+ await updateChannel.mutateAsync({ channel: props.channelName, data: nextData });
287
+ }
288
+ const result = await executeAction.mutateAsync({ actionId: action.id, data: { scope, draftConfig: buildScopeDraft(scope, nextData) } });
289
+ applyActionPatchToForm(result.patch);
290
+ result.ok ? toast.success(result.message || t('success')) : toast.error(result.message || t('error'));
291
+ } catch (error) {
292
+ toast.error(`${t('error')}: ${error instanceof Error ? error.message : String(error)}`);
293
+ } finally {
294
+ setRunningActionId(null);
295
+ }
296
+ };
297
+
298
+ return (
299
+ <ConfigSplitDetailPane>
300
+ <ChannelFormHeader
301
+ channelName={props.channelName}
302
+ channelLabel={props.channelLabel}
303
+ enabled={enabled}
304
+ tutorialUrl={props.tutorialUrl}
305
+ channelApplyStatus={channelApplyStatus}
306
+ />
307
+
308
+ <form onSubmit={handleSubmit} className="flex min-h-0 flex-1 flex-col">
309
+ <ConfigSplitPaneBody className="space-y-6 px-6 py-5">
310
+ <ChannelFormBlocks
311
+ channelConfig={props.channelConfig}
312
+ channelName={props.channelName}
313
+ enabled={enabled}
314
+ fields={props.fields}
315
+ formData={formData}
316
+ jsonDrafts={jsonDrafts}
317
+ layoutBlocks={props.layoutBlocks}
318
+ setJsonDrafts={setJsonDrafts}
319
+ uiHints={props.uiHints}
320
+ updateField={updateField}
321
+ disabled={disabled}
322
+ />
323
+ </ConfigSplitPaneBody>
324
+
325
+ <ConfigSplitPaneFooter className="flex flex-wrap items-center justify-between gap-3 px-6 py-4">
326
+ <div className="flex flex-wrap items-center gap-2">
327
+ {props.actions.filter((action) => action.trigger === 'manual').map((action) => (
328
+ <Button key={action.id} type="button" onClick={() => void handleManualAction(action)} disabled={disabled} variant="secondary">
329
+ {runningActionId === action.id ? t('connecting') : action.title}
330
+ </Button>
331
+ ))}
332
+ </div>
333
+ <Button type="submit" disabled={disabled}>
334
+ {updateChannel.isPending ? t('saving') : t('save')}
335
+ </Button>
336
+ </ConfigSplitPaneFooter>
337
+ </form>
338
+ </ConfigSplitDetailPane>
339
+ );
340
+ }
341
+
342
+ export function ChannelForm({ channelName }: ChannelFormProps) {
343
+ const { data: config } = useConfig();
344
+ const { data: meta } = useConfigMeta();
345
+ const { data: schema } = useConfigSchema();
346
+ const channelConfig = channelName ? config?.channels[channelName] ?? null : null;
347
+ const channelMeta = meta?.channels.find((item) => item.name === channelName);
348
+ const channelDefinition = useMemo(() => buildChannelFormDefinitions()[channelName || ''], [channelName]);
349
+
350
+ if (!channelName || !channelMeta || !channelConfig) {
351
+ return (
352
+ <ConfigSplitEmptyPane>
353
+ <div>
354
+ <h3 className="text-base font-semibold text-gray-900">{t('channelsSelectTitle')}</h3>
355
+ <p className="mt-2 text-sm text-gray-500">{t('channelsSelectDescription')}</p>
356
+ </div>
357
+ </ConfigSplitEmptyPane>
358
+ );
359
+ }
360
+
361
+ const fields = channelDefinition?.fields ?? EMPTY_CHANNEL_FIELDS;
362
+ const layoutBlocks = channelDefinition?.layout ?? DEFAULT_CHANNEL_LAYOUT_BLOCKS;
363
+ const uiHints = schema?.uiHints;
364
+ const channelLabel = hintForPath(`channels.${channelName}`, uiHints)?.label ?? channelName;
365
+ const tutorialUrl = resolveChannelTutorialUrl(channelMeta);
366
+ const formKey = JSON.stringify({ channelName, channelConfig, jsonFields: fields.filter((field) => field.type === 'json').map((field) => field.name) });
367
+ const actions = schema?.actions?.filter((action) => action.scope === `channels.${channelName}`) ?? [];
368
+
369
+ return (
370
+ <ChannelFormEditor
371
+ key={formKey}
372
+ actions={actions}
373
+ channelConfig={channelConfig}
374
+ channelLabel={channelLabel}
375
+ channelName={channelName}
376
+ fields={fields}
377
+ layoutBlocks={layoutBlocks}
378
+ tutorialUrl={tutorialUrl}
379
+ uiHints={uiHints}
380
+ />
381
+ );
382
+ }
@@ -1,7 +1,7 @@
1
1
  import { render, screen, waitFor } from '@testing-library/react';
2
2
  import userEvent from '@testing-library/user-event';
3
3
  import type * as ReactQueryModule from '@tanstack/react-query';
4
- import { WeixinChannelAuthSection } from './weixin-channel-auth-section';
4
+ import { WeixinChannelAuthSection } from '@/features/channels/components/config/weixin-channel-auth-section';
5
5
 
6
6
  const mocks = vi.hoisted(() => ({
7
7
  startChannelAuthMutateAsync: vi.fn(),
@@ -15,6 +15,9 @@ vi.mock('@tanstack/react-query', async () => {
15
15
  ...actual,
16
16
  useQueryClient: () => ({
17
17
  invalidateQueries: mocks.invalidateQueries
18
+ }),
19
+ useQuery: () => ({
20
+ data: 'data:image/png;base64,weixin-qr'
18
21
  })
19
22
  };
20
23
  });
@@ -23,7 +26,7 @@ vi.mock('qrcode', () => ({
23
26
  toDataURL: vi.fn().mockResolvedValue('data:image/png;base64,weixin-qr')
24
27
  }));
25
28
 
26
- vi.mock('@/hooks/use-channel-auth', () => ({
29
+ vi.mock('@/features/channels/hooks/use-channel-auth', () => ({
27
30
  useStartChannelAuth: () => ({
28
31
  mutateAsync: mocks.startChannelAuthMutateAsync,
29
32
  isPending: false
@@ -91,7 +94,7 @@ describe('WeixinChannelAuthSection', () => {
91
94
  });
92
95
  });
93
96
 
94
- it('shows connected-but-inactive state when account is authorized but channel is disabled', async () => {
97
+ it('shows connected-but-inactive state when account is authorized but channel is disabled', () => {
95
98
  render(
96
99
  <WeixinChannelAuthSection
97
100
  channelConfig={{
@@ -0,0 +1,245 @@
1
+ import { useEffect, useMemo, useState } from 'react';
2
+ import { useQuery, useQueryClient } from '@tanstack/react-query';
3
+ import { toDataURL } from 'qrcode';
4
+ import { ExternalLink, Loader2, MessageCircleMore, QrCode } from 'lucide-react';
5
+ import { toast } from 'sonner';
6
+ import { Button } from '@/shared/components/ui/button';
7
+ import { usePollChannelAuth, useStartChannelAuth } from '@/features/channels/hooks/use-channel-auth';
8
+ import { formatDateTime, t } from '@/shared/lib/i18n';
9
+ import { cn } from '@/shared/lib/utils';
10
+ import type { ChannelAuthPollResult, ChannelAuthStartResult } from '@/shared/lib/api';
11
+
12
+ type WeixinChannelAuthSectionProps = {
13
+ channelConfig: Record<string, unknown>;
14
+ formData: Record<string, unknown>;
15
+ channelEnabled: boolean;
16
+ disabled?: boolean;
17
+ };
18
+
19
+ function resolveConnectedAccountIds(channelConfig: Record<string, unknown>): string[] {
20
+ const accounts = channelConfig.accounts;
21
+ const ids = new Set<string>();
22
+ if (typeof channelConfig.defaultAccountId === 'string' && channelConfig.defaultAccountId.trim()) {
23
+ ids.add(channelConfig.defaultAccountId.trim());
24
+ }
25
+ if (accounts && typeof accounts === 'object' && !Array.isArray(accounts)) {
26
+ for (const accountId of Object.keys(accounts)) {
27
+ const trimmed = accountId.trim();
28
+ if (trimmed) {
29
+ ids.add(trimmed);
30
+ }
31
+ }
32
+ }
33
+ return [...ids];
34
+ }
35
+
36
+ function resolveBaseUrl(formData: Record<string, unknown>, channelConfig: Record<string, unknown>): string | undefined {
37
+ if (typeof formData.baseUrl === 'string' && formData.baseUrl.trim()) {
38
+ return formData.baseUrl.trim();
39
+ }
40
+ if (typeof channelConfig.baseUrl === 'string' && channelConfig.baseUrl.trim()) {
41
+ return channelConfig.baseUrl.trim();
42
+ }
43
+ return undefined;
44
+ }
45
+
46
+ function useWeixinQrDataUrl(qrCodeUrl: string | undefined) {
47
+ return useQuery({
48
+ queryKey: ['weixin-channel-qr', qrCodeUrl],
49
+ enabled: Boolean(qrCodeUrl),
50
+ queryFn: () => toDataURL(qrCodeUrl!, { errorCorrectionLevel: 'M', margin: 1, width: 480 })
51
+ }).data ?? null;
52
+ }
53
+
54
+ function WeixinAuthSummary(props: {
55
+ activeSession: ChannelAuthStartResult | null;
56
+ baseUrl?: string;
57
+ channelEnabled: boolean;
58
+ connectButtonLabel: string;
59
+ connectedAccountIds: string[];
60
+ disabled: boolean;
61
+ handleStartAuth: () => Promise<void>;
62
+ hasConnectedAccount: boolean;
63
+ primaryAccountId?: string;
64
+ statusLabel: string;
65
+ }) {
66
+ return (
67
+ <div className="space-y-3">
68
+ <div className="inline-flex items-center gap-2 rounded-full bg-white/90 px-3 py-1 text-xs font-medium text-primary shadow-sm">
69
+ <QrCode className="h-3.5 w-3.5" />
70
+ {t('weixinAuthTitle')}
71
+ </div>
72
+ <div>
73
+ <h4 className="text-base font-semibold text-gray-900">{t('weixinAuthDescription')}</h4>
74
+ <p className="mt-1 text-sm text-gray-600">{t('weixinAuthHint')}</p>
75
+ </div>
76
+ <div
77
+ className={cn(
78
+ 'inline-flex w-fit items-center gap-2 rounded-full px-3 py-1 text-xs font-medium',
79
+ props.activeSession ? 'bg-amber-50 text-amber-700' : props.hasConnectedAccount ? 'bg-emerald-50 text-emerald-700' : 'bg-gray-100 text-gray-600'
80
+ )}
81
+ >
82
+ {props.activeSession ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <MessageCircleMore className="h-3.5 w-3.5" />}
83
+ {props.statusLabel}
84
+ </div>
85
+ <div className="space-y-1 text-sm text-gray-600">
86
+ <p>{props.channelEnabled || !props.hasConnectedAccount ? t('weixinAuthCapabilityHint') : t('weixinAuthDisabledHint')}</p>
87
+ {props.primaryAccountId ? <p>{t('weixinAuthPrimaryAccount')}: <span className="font-mono text-xs text-gray-900">{props.primaryAccountId}</span></p> : null}
88
+ {props.connectedAccountIds.length > 1 ? <p>{t('weixinAuthConnectedAccounts')}: <span className="font-mono text-xs text-gray-900">{props.connectedAccountIds.join(', ')}</span></p> : null}
89
+ {props.baseUrl ? <p>{t('weixinAuthBaseUrl')}: <span className="font-mono text-xs text-gray-900">{props.baseUrl}</span></p> : null}
90
+ </div>
91
+ <Button type="button" onClick={() => void props.handleStartAuth()} disabled={props.disabled} className="rounded-xl">
92
+ {props.connectButtonLabel}
93
+ </Button>
94
+ </div>
95
+ );
96
+ }
97
+
98
+ function WeixinAuthQrPanel(props: {
99
+ activeSession: ChannelAuthStartResult | null;
100
+ authMessage?: string;
101
+ qrDataUrl: string | null;
102
+ }) {
103
+ return (
104
+ <div className="w-full max-w-sm rounded-2xl border border-dashed border-primary/25 bg-white/85 p-4 shadow-sm">
105
+ {props.activeSession ? (
106
+ <div className="space-y-3">
107
+ <div className="overflow-hidden rounded-2xl border border-gray-100 bg-white p-3">
108
+ {props.qrDataUrl ? (
109
+ <img src={props.qrDataUrl} alt={t('weixinAuthQrAlt')} className="mx-auto aspect-square w-full max-w-[240px] object-contain" />
110
+ ) : (
111
+ <div className="flex aspect-square w-full items-center justify-center rounded-xl bg-gray-50 text-gray-500">
112
+ <div className="flex flex-col items-center gap-2 text-center">
113
+ <Loader2 className="h-5 w-5 animate-spin" />
114
+ <p className="text-xs">{t('weixinAuthStarting')}</p>
115
+ </div>
116
+ </div>
117
+ )}
118
+ </div>
119
+ <div className="space-y-1 text-xs text-gray-500">
120
+ <p>{props.authMessage || props.activeSession.note || t('weixinAuthScanPrompt')}</p>
121
+ <p>{t('weixinAuthExpiresAt')}: {formatDateTime(props.activeSession.expiresAt)}</p>
122
+ </div>
123
+ <a href={props.activeSession.qrCodeUrl} target="_blank" rel="noreferrer" className="inline-flex items-center gap-1.5 text-xs text-primary transition-colors hover:text-primary-hover">
124
+ <ExternalLink className="h-3.5 w-3.5" />
125
+ {t('weixinAuthOpenQr')}
126
+ </a>
127
+ </div>
128
+ ) : (
129
+ <div className="flex min-h-[280px] flex-col items-center justify-center rounded-2xl bg-gray-50/80 px-6 text-center">
130
+ <QrCode className="h-9 w-9 text-gray-300" />
131
+ <p className="mt-3 text-sm font-medium text-gray-700">{t('weixinAuthReadyTitle')}</p>
132
+ <p className="mt-1 text-xs leading-5 text-gray-500">{t('weixinAuthReadyDescription')}</p>
133
+ </div>
134
+ )}
135
+ </div>
136
+ );
137
+ }
138
+
139
+ export function WeixinChannelAuthSection(props: WeixinChannelAuthSectionProps) {
140
+ const queryClient = useQueryClient();
141
+ const startChannelAuth = useStartChannelAuth();
142
+ const pollChannelAuth = usePollChannelAuth();
143
+ const [activeSession, setActiveSession] = useState<ChannelAuthStartResult | null>(null);
144
+ const [authState, setAuthState] = useState<ChannelAuthPollResult | null>(null);
145
+ const [sessionStartedWhileConnected, setSessionStartedWhileConnected] = useState(false);
146
+ const connectedAccountIds = useMemo(() => resolveConnectedAccountIds(props.channelConfig), [props.channelConfig]);
147
+ const primaryAccountId = connectedAccountIds[0];
148
+ const baseUrl = resolveBaseUrl(props.formData, props.channelConfig);
149
+ const hasConnectedAccount = connectedAccountIds.length > 0;
150
+ const effectiveActiveSession = hasConnectedAccount && !sessionStartedWhileConnected ? null : activeSession;
151
+ const qrDataUrl = useWeixinQrDataUrl(effectiveActiveSession?.qrCodeUrl);
152
+
153
+ useEffect(() => {
154
+ if (!effectiveActiveSession) {
155
+ return;
156
+ }
157
+ let cancelled = false;
158
+ let timer: ReturnType<typeof setTimeout> | null = null;
159
+ const runPoll = async () => {
160
+ try {
161
+ const result = await pollChannelAuth.mutateAsync({ channel: 'weixin', data: { sessionId: effectiveActiveSession.sessionId } });
162
+ if (cancelled) {
163
+ return;
164
+ }
165
+ setAuthState(result);
166
+ if (result.status === 'authorized') {
167
+ await queryClient.invalidateQueries({ queryKey: ['config'] });
168
+ await queryClient.invalidateQueries({ queryKey: ['config-meta'] });
169
+ toast.success(result.message || t('weixinAuthAuthorized'));
170
+ setActiveSession(null);
171
+ return;
172
+ }
173
+ if (result.status === 'expired' || result.status === 'error') {
174
+ toast.error(result.message || t('weixinAuthRetryRequired'));
175
+ setActiveSession(null);
176
+ return;
177
+ }
178
+ timer = setTimeout(runPoll, result.nextPollMs ?? effectiveActiveSession.intervalMs);
179
+ } catch (error) {
180
+ if (!cancelled) {
181
+ toast.error(`${t('error')}: ${error instanceof Error ? error.message : String(error)}`);
182
+ setActiveSession(null);
183
+ }
184
+ }
185
+ };
186
+ timer = setTimeout(runPoll, effectiveActiveSession.intervalMs);
187
+ return () => {
188
+ cancelled = true;
189
+ if (timer) {
190
+ clearTimeout(timer);
191
+ }
192
+ };
193
+ }, [effectiveActiveSession, pollChannelAuth, queryClient]);
194
+
195
+ const handleStartAuth = async () => {
196
+ try {
197
+ const result = await startChannelAuth.mutateAsync({
198
+ channel: 'weixin',
199
+ data: {
200
+ baseUrl,
201
+ accountId: typeof props.formData.defaultAccountId === 'string' && props.formData.defaultAccountId.trim() ? props.formData.defaultAccountId.trim() : undefined
202
+ }
203
+ });
204
+ setSessionStartedWhileConnected(hasConnectedAccount);
205
+ setActiveSession(result);
206
+ setAuthState({ channel: 'weixin', status: 'pending', message: result.note, nextPollMs: result.intervalMs });
207
+ } catch (error) {
208
+ toast.error(`${t('error')}: ${error instanceof Error ? error.message : String(error)}`);
209
+ }
210
+ };
211
+
212
+ const statusLabel = effectiveActiveSession
213
+ ? authState?.status === 'scanned' ? t('weixinAuthScanned') : t('weixinAuthWaiting')
214
+ : hasConnectedAccount
215
+ ? props.channelEnabled ? t('weixinAuthAuthorized') : t('weixinAuthConnectedDisabled')
216
+ : t('weixinAuthNotConnected');
217
+ const connectButtonLabel = startChannelAuth.isPending
218
+ ? t('weixinAuthStarting')
219
+ : effectiveActiveSession
220
+ ? t('weixinAuthWaiting')
221
+ : hasConnectedAccount
222
+ ? t('weixinAuthReconnect')
223
+ : t('weixinAuthConnect');
224
+ const authMessage = hasConnectedAccount ? t('weixinAuthAuthorized') : authState?.message;
225
+
226
+ return (
227
+ <section className="rounded-2xl border border-primary/20 bg-gradient-to-br from-primary-50/70 via-white to-emerald-50/60 p-5">
228
+ <div className="flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between">
229
+ <WeixinAuthSummary
230
+ activeSession={effectiveActiveSession}
231
+ baseUrl={baseUrl}
232
+ channelEnabled={props.channelEnabled}
233
+ connectButtonLabel={connectButtonLabel}
234
+ connectedAccountIds={connectedAccountIds}
235
+ disabled={props.disabled || startChannelAuth.isPending || Boolean(effectiveActiveSession)}
236
+ handleStartAuth={handleStartAuth}
237
+ hasConnectedAccount={hasConnectedAccount}
238
+ primaryAccountId={primaryAccountId}
239
+ statusLabel={statusLabel}
240
+ />
241
+ <WeixinAuthQrPanel activeSession={effectiveActiveSession} authMessage={authMessage} qrDataUrl={qrDataUrl} />
242
+ </div>
243
+ </section>
244
+ );
245
+ }
@@ -1,5 +1,5 @@
1
1
  import { useMutation } from '@tanstack/react-query';
2
- import { pollChannelAuth, startChannelAuth } from '@/api/channel-auth';
2
+ import { pollChannelAuth, startChannelAuth } from '@/shared/lib/api';
3
3
 
4
4
  export function useStartChannelAuth() {
5
5
  return useMutation({
@@ -0,0 +1,5 @@
1
+ export { ChannelForm } from './components/config/channel-form';
2
+ export { ChannelFormFieldsSection } from './components/channel-form-fields-section';
3
+ export { WeixinChannelAuthSection } from './components/config/weixin-channel-auth-section';
4
+ export { ChannelsList } from './pages/channels-list-page';
5
+ export { buildChannelFields, buildChannelFormDefinitions, type ChannelField, type ChannelFieldType, type ChannelFormBlock, type ChannelFormDefinition, type ChannelFormFieldSection, type ChannelOption } from './utils/channel-form-fields.utils';