@micha.bigler/ui-core-micha 3.14.3 → 4.0.0

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 (367) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +7 -0
  3. package/dist/auth/UserMenu.js +1 -1
  4. package/dist/auth/apiClient.js +7 -6
  5. package/dist/chat/ChatList.js +1 -1
  6. package/dist/chat/ChatThread.js +2 -1
  7. package/dist/chat/ChatWorkspace.js +1 -1
  8. package/dist/chat/ModelPicker.js +2 -5
  9. package/dist/chat/kitSxRegistry.js +9 -0
  10. package/dist/chat/useChatSocket.js +1 -1
  11. package/dist/components/LoginForm.js +1 -1
  12. package/dist/components/SecurityComponent.js +1 -1
  13. package/dist/components/UserListComponent.js +2 -8
  14. package/dist/components/charts/ChartFrame.js +1 -1
  15. package/dist/components/charts/ScatterChart.js +2 -1
  16. package/dist/components/charts/kitSxRegistry.js +6 -0
  17. package/dist/entries/charts.js +6 -0
  18. package/dist/entries/chat.js +8 -0
  19. package/dist/entries/markdown.js +1 -0
  20. package/dist/index.js +0 -14
  21. package/dist/layout/SectionNav.js +1 -1
  22. package/dist/messaging/AttachmentList.js +2 -2
  23. package/dist/messaging/Composer.js +2 -1
  24. package/dist/messaging/ConversationLaunchers.js +1 -4
  25. package/dist/messaging/ConversationList.js +1 -1
  26. package/dist/messaging/DirectMessageLauncher.js +1 -1
  27. package/dist/messaging/MessagingProvider.js +0 -0
  28. package/dist/messaging/PollCard.js +7 -5
  29. package/dist/messaging/ReadTicks.js +2 -2
  30. package/dist/messaging/Thread.js +5 -3
  31. package/dist/notifications/NotificationBell.js +4 -7
  32. package/dist/notifications/NotificationSettings.js +1 -1
  33. package/dist/onboarding/OnboardingProvider.js +3 -6
  34. package/dist/pages/AccountPage.js +1 -2
  35. package/dist/pages/LoginPage.js +2 -3
  36. package/dist/pages/PasswordChangePage.js +2 -3
  37. package/dist/pages/PasswordInvitePage.js +2 -3
  38. package/dist/pages/PasswordResetRequestPage.js +2 -3
  39. package/dist/pages/SignUpPage.js +2 -3
  40. package/dist/pages/SignupConfirmPage.js +2 -3
  41. package/dist/theme/createAppTheme.js +5 -4
  42. package/dist/theme/kitSxEntry.js +11 -0
  43. package/dist/theme/kitSxRegistry.js +2 -15
  44. package/dist/theme/themeCompleteness.js +3 -12
  45. package/dist/utils/auth-errors.js +4 -3
  46. package/package.json +41 -16
  47. package/.github/workflows/publish.yml +0 -126
  48. package/DESIGN.md +0 -60
  49. package/WORK_ORDERS.md +0 -148
  50. package/dev/entries.jsx +0 -721
  51. package/dev/fixtures.js +0 -26
  52. package/dev/main.jsx +0 -75
  53. package/dev/mockTransport.jsx +0 -128
  54. package/docs/CHART-LAYOUT.md +0 -157
  55. package/docs/DARK-TOKENS.md +0 -140
  56. package/docs/TYPE-SCALE.md +0 -111
  57. package/docs/messaging-deviations.md +0 -118
  58. package/index.html +0 -12
  59. package/renovate.json +0 -10
  60. package/scripts/chart-api-census.mjs +0 -415
  61. package/src/auth/AuthContext.jsx +0 -158
  62. package/src/auth/ReauthModal.jsx +0 -82
  63. package/src/auth/UserMenu.jsx +0 -121
  64. package/src/auth/apiClient.jsx +0 -232
  65. package/src/auth/authApi.jsx +0 -539
  66. package/src/auth/authConfig.jsx +0 -34
  67. package/src/auth/reauth.js +0 -47
  68. package/src/chat/ChatComposer.jsx +0 -36
  69. package/src/chat/ChatList.jsx +0 -87
  70. package/src/chat/ChatThread.jsx +0 -128
  71. package/src/chat/ChatWorkspace.jsx +0 -244
  72. package/src/chat/MarkdownReply.jsx +0 -22
  73. package/src/chat/ModelPicker.jsx +0 -85
  74. package/src/chat/api.js +0 -18
  75. package/src/chat/useChatSocket.js +0 -32
  76. package/src/chat/wire.js +0 -7
  77. package/src/components/AccessCodeManager.jsx +0 -288
  78. package/src/components/AccessCodeSingleUseToggle.jsx +0 -92
  79. package/src/components/AllowedEmailDomainsManager.jsx +0 -92
  80. package/src/components/AuthFactorRequirementCard.jsx +0 -95
  81. package/src/components/BulkInviteCsvTab.jsx +0 -198
  82. package/src/components/EmptyState.jsx +0 -38
  83. package/src/components/LoginForm.jsx +0 -159
  84. package/src/components/MFAComponent.jsx +0 -350
  85. package/src/components/MfaLoginComponent.jsx +0 -252
  86. package/src/components/MobileBottomNav.jsx +0 -82
  87. package/src/components/PasskeysComponent.jsx +0 -252
  88. package/src/components/PasswordChangeForm.jsx +0 -87
  89. package/src/components/PasswordResetRequestForm.jsx +0 -43
  90. package/src/components/PasswordSetForm.jsx +0 -97
  91. package/src/components/ProfileComponent.jsx +0 -348
  92. package/src/components/QrSignupManager.jsx +0 -404
  93. package/src/components/QrSignupValidityManager.jsx +0 -106
  94. package/src/components/RegistrationMethodsManager.jsx +0 -150
  95. package/src/components/SecurityComponent.jsx +0 -141
  96. package/src/components/SocialLoginButtons.jsx +0 -83
  97. package/src/components/SoftChip.jsx +0 -93
  98. package/src/components/StatTile.jsx +0 -39
  99. package/src/components/SupportRecoveryRequestsTab.jsx +0 -482
  100. package/src/components/TurnstileWidget.jsx +0 -99
  101. package/src/components/UserInviteComponent.jsx +0 -76
  102. package/src/components/UserListComponent.jsx +0 -618
  103. package/src/components/charts/BarChart.jsx +0 -102
  104. package/src/components/charts/ChartFrame.jsx +0 -214
  105. package/src/components/charts/LineChart.jsx +0 -126
  106. package/src/components/charts/ScatterChart.jsx +0 -299
  107. package/src/components/charts/TimeSeriesChart.jsx +0 -300
  108. package/src/components/charts/chartDefaults.js +0 -644
  109. package/src/components/charts/chartLabels.js +0 -36
  110. package/src/components/charts/exportChart.js +0 -258
  111. package/src/components/charts/formatters.js +0 -39
  112. package/src/components/charts/palette.js +0 -33
  113. package/src/components/charts/yearTickInterval.js +0 -7
  114. package/src/i18n/authTranslations.ts +0 -2651
  115. package/src/i18n/chartsTranslations.ts +0 -91
  116. package/src/i18n/chatTranslations.ts +0 -55
  117. package/src/i18n/messagingTranslations.ts +0 -120
  118. package/src/i18n/notificationsTranslations.ts +0 -32
  119. package/src/i18n/onboardingTranslations.ts +0 -29
  120. package/src/i18n/sectionNavTranslations.ts +0 -20
  121. package/src/i18n/uiCoreTranslations.js +0 -29
  122. package/src/i18n/userMenuTranslations.ts +0 -5
  123. package/src/index.js +0 -158
  124. package/src/layout/PageLayout.jsx +0 -36
  125. package/src/layout/SectionNav.jsx +0 -320
  126. package/src/messaging/AttachmentList.jsx +0 -145
  127. package/src/messaging/Composer.jsx +0 -197
  128. package/src/messaging/ConversationLaunchers.jsx +0 -51
  129. package/src/messaging/ConversationList.jsx +0 -109
  130. package/src/messaging/DirectMessageLauncher.jsx +0 -112
  131. package/src/messaging/MessageBubble.jsx +0 -183
  132. package/src/messaging/MessagingProvider.jsx +0 -0
  133. package/src/messaging/MessagingScopeConfig.jsx +0 -24
  134. package/src/messaging/PollCard.jsx +0 -163
  135. package/src/messaging/ReactionBar.jsx +0 -43
  136. package/src/messaging/ReadTicks.jsx +0 -82
  137. package/src/messaging/Thread.jsx +0 -195
  138. package/src/messaging/api.js +0 -48
  139. package/src/messaging/composerImageCompression.js +0 -35
  140. package/src/messaging/linkifyText.jsx +0 -37
  141. package/src/notifications/NotificationBell.jsx +0 -84
  142. package/src/notifications/NotificationSettings.jsx +0 -330
  143. package/src/notifications/NotificationsProvider.jsx +0 -224
  144. package/src/notifications/PopupSurface.jsx +0 -105
  145. package/src/notifications/api.js +0 -55
  146. package/src/notifications/feedApi.js +0 -18
  147. package/src/notifications/realtime.jsx +0 -138
  148. package/src/notifications/serviceWorker/sw.js +0 -50
  149. package/src/onboarding/OnboardingProvider.jsx +0 -326
  150. package/src/onboarding/OnboardingWizard.jsx +0 -61
  151. package/src/onboarding/WizardDialogShell.jsx +0 -51
  152. package/src/onboarding/api.js +0 -13
  153. package/src/onboarding/stepSelection.js +0 -16
  154. package/src/onboarding/steps/BrowserPushStep.jsx +0 -121
  155. package/src/onboarding/steps/CompleteNameStep.jsx +0 -46
  156. package/src/onboarding/steps/CookieConsentStep.jsx +0 -133
  157. package/src/onboarding/steps/PwaInstallStep.jsx +0 -47
  158. package/src/pages/AccountPage.jsx +0 -394
  159. package/src/pages/LoginPage.jsx +0 -343
  160. package/src/pages/PasswordChangePage.jsx +0 -62
  161. package/src/pages/PasswordInvitePage.jsx +0 -177
  162. package/src/pages/PasswordResetRequestPage.jsx +0 -68
  163. package/src/pages/SignUpPage.jsx +0 -268
  164. package/src/pages/SignupConfirmPage.jsx +0 -155
  165. package/src/testing/checkKitIntegration.js +0 -233
  166. package/src/theme/createAppTheme.js +0 -423
  167. package/src/theme/fonts.js +0 -3
  168. package/src/theme/index.js +0 -21
  169. package/src/theme/kitSxRegistry.js +0 -285
  170. package/src/theme/themeCompleteness.js +0 -1045
  171. package/src/theme/tokens.js +0 -478
  172. package/src/utils/auth-errors.js +0 -76
  173. package/src/utils/authService.js +0 -223
  174. package/src/utils/resolveErrorText.js +0 -28
  175. package/src/utils/webauthn.js +0 -51
  176. package/tests/AccountPage.profileStatements.test.jsx +0 -162
  177. package/tests/AccountPage.test.jsx +0 -200
  178. package/tests/AuthContext.test.jsx +0 -129
  179. package/tests/BarChart.test.jsx +0 -112
  180. package/tests/BrowserPushStep.test.jsx +0 -110
  181. package/tests/ChartFrame.test.jsx +0 -336
  182. package/tests/ConversationList.test.jsx +0 -144
  183. package/tests/CookieConsentStep.test.jsx +0 -69
  184. package/tests/EmptyState.test.jsx +0 -62
  185. package/tests/LineChart.test.jsx +0 -80
  186. package/tests/MessagingProvider.test.jsx +0 -50
  187. package/tests/MobileBottomNav.test.jsx +0 -319
  188. package/tests/NotificationBell.test.jsx +0 -60
  189. package/tests/NotificationSettings.test.jsx +0 -276
  190. package/tests/NotificationsProvider.test.jsx +0 -240
  191. package/tests/OnboardingProvider.test.jsx +0 -294
  192. package/tests/OnboardingWizard.test.jsx +0 -143
  193. package/tests/PasswordChangeForm.test.jsx +0 -70
  194. package/tests/PasswordInvitePage.test.jsx +0 -142
  195. package/tests/PasswordSetForm.test.jsx +0 -70
  196. package/tests/PopupSurface.test.jsx +0 -142
  197. package/tests/ProfileComponent.refresh.test.jsx +0 -194
  198. package/tests/QrSignupManager.registrationContext.test.jsx +0 -106
  199. package/tests/QrSignupManagerInfoBox.test.jsx +0 -49
  200. package/tests/ScatterChart.test.jsx +0 -270
  201. package/tests/SectionNav.test.jsx +0 -363
  202. package/tests/SignUpPage.test.jsx +0 -208
  203. package/tests/SoftChip.test.jsx +0 -105
  204. package/tests/StatTile.test.jsx +0 -57
  205. package/tests/Thread.test.jsx +0 -151
  206. package/tests/TimeSeriesChart.test.jsx +0 -367
  207. package/tests/UserListComponent.test.jsx +0 -192
  208. package/tests/UserMenu.test.jsx +0 -171
  209. package/tests/apiClientLanguage.test.js +0 -33
  210. package/tests/apiClientPublicPaths.test.js +0 -178
  211. package/tests/authApiLogin.test.js +0 -42
  212. package/tests/authApiRegistration.test.js +0 -31
  213. package/tests/authErrorCodeRendering.test.jsx +0 -77
  214. package/tests/authErrors.test.js +0 -74
  215. package/tests/authTranslations.test.js +0 -74
  216. package/tests/chart-api-census.test.js +0 -366
  217. package/tests/chartAxisTickBand.test.jsx +0 -95
  218. package/tests/chartDefaults.test.js +0 -902
  219. package/tests/chartLabels.test.js +0 -50
  220. package/tests/chartsPalette.test.js +0 -99
  221. package/tests/chatApi.test.js +0 -48
  222. package/tests/chatDriverNames.test.jsx +0 -71
  223. package/tests/chatExports.test.js +0 -3
  224. package/tests/chatList.test.jsx +0 -84
  225. package/tests/chatPicker.test.jsx +0 -82
  226. package/tests/chatSocket.test.jsx +0 -26
  227. package/tests/chatThread.test.jsx +0 -116
  228. package/tests/chatTranslations.test.js +0 -47
  229. package/tests/chatWorkspace.test.jsx +0 -234
  230. package/tests/checkKitIntegration.test.jsx +0 -219
  231. package/tests/createAppTheme.test.js +0 -132
  232. package/tests/createAppThemeDark.test.js +0 -127
  233. package/tests/createAppThemeLightGuard.test.js +0 -40
  234. package/tests/createAppThemePageContrast.test.js +0 -108
  235. package/tests/createAppThemeTypography.test.js +0 -53
  236. package/tests/errorCallSiteGuard.test.js +0 -32
  237. package/tests/exportChart.test.js +0 -313
  238. package/tests/feedApi.test.js +0 -46
  239. package/tests/fixtures/light-theme-baseline.json +0 -2234
  240. package/tests/i18nAggregate.test.js +0 -120
  241. package/tests/i18nGermanVariant.test.js +0 -65
  242. package/tests/loginPageErrorResolution.test.jsx +0 -102
  243. package/tests/messagingApi.test.js +0 -32
  244. package/tests/messagingChunk6.test.jsx +0 -116
  245. package/tests/messagingCompactBubble.test.jsx +0 -64
  246. package/tests/messagingComposer.test.jsx +0 -136
  247. package/tests/messagingComposerChunk5.test.jsx +0 -113
  248. package/tests/messagingContractConformance.test.js +0 -69
  249. package/tests/messagingDirectMessageLauncher.test.jsx +0 -151
  250. package/tests/messagingExports.test.js +0 -21
  251. package/tests/messagingInteractions.test.jsx +0 -136
  252. package/tests/messagingLastMessagePreview.test.jsx +0 -93
  253. package/tests/messagingLinkify.test.jsx +0 -51
  254. package/tests/messagingMessageActions.test.jsx +0 -163
  255. package/tests/messagingMsg6.test.jsx +0 -105
  256. package/tests/messagingMsg6f.test.jsx +0 -155
  257. package/tests/messagingMsg6g.test.jsx +0 -166
  258. package/tests/messagingMsg6h.test.jsx +0 -136
  259. package/tests/messagingMsg6i.test.jsx +0 -129
  260. package/tests/messagingPollRendering.test.jsx +0 -142
  261. package/tests/messagingReactionMerge.test.jsx +0 -77
  262. package/tests/messagingReadTicksTooltip.test.jsx +0 -36
  263. package/tests/messagingThreadReceipts.test.jsx +0 -178
  264. package/tests/messagingThreadingQuoting.test.jsx +0 -87
  265. package/tests/messagingUnreadLifecycle.test.jsx +0 -78
  266. package/tests/notificationsApi.test.js +0 -41
  267. package/tests/notificationsExports.test.js +0 -34
  268. package/tests/onboardingDescriptors.test.js +0 -132
  269. package/tests/packageTreeShaking.test.js +0 -126
  270. package/tests/realtime.test.jsx +0 -219
  271. package/tests/resolveErrorText.test.js +0 -72
  272. package/tests/stepSelection.test.js +0 -53
  273. package/tests/themeCompleteness.test.js +0 -626
  274. package/tests/timeSeriesLegend.test.js +0 -99
  275. package/tests/userScreenTranslations.test.jsx +0 -218
  276. package/tsconfig.build.json +0 -18
  277. package/vite.config.mjs +0 -6
  278. package/work-orders/AUTH-1.md +0 -74
  279. package/work-orders/AUTH-2.md +0 -74
  280. package/work-orders/AUTH-4.md +0 -183
  281. package/work-orders/AUTH-5.md +0 -154
  282. package/work-orders/AUTH-7.md +0 -181
  283. package/work-orders/AUTH-8.md +0 -184
  284. package/work-orders/CHART-1.md +0 -285
  285. package/work-orders/CHART-2.md +0 -222
  286. package/work-orders/CHART-3.md +0 -163
  287. package/work-orders/CHART-4.md +0 -203
  288. package/work-orders/CHART-5.md +0 -226
  289. package/work-orders/CHART-6.md +0 -428
  290. package/work-orders/CHART-7.md +0 -175
  291. package/work-orders/DX-1.md +0 -169
  292. package/work-orders/DX-2.md +0 -188
  293. package/work-orders/DX-3.md +0 -195
  294. package/work-orders/I18N-1.md +0 -254
  295. package/work-orders/I18N-3.md +0 -207
  296. package/work-orders/MSG-3.md +0 -375
  297. package/work-orders/MSG-3b.md +0 -1002
  298. package/work-orders/MSG-3c.md +0 -378
  299. package/work-orders/MSG-3d.md +0 -268
  300. package/work-orders/MSG-3e.md +0 -164
  301. package/work-orders/MSG-3f.md +0 -391
  302. package/work-orders/MSG-6e.md +0 -308
  303. package/work-orders/MSG-6f.md +0 -214
  304. package/work-orders/MSG-6g.md +0 -244
  305. package/work-orders/MSG-6h.md +0 -238
  306. package/work-orders/MSG-6i.md +0 -271
  307. package/work-orders/MSG-6j.md +0 -117
  308. package/work-orders/NOTIF-12.md +0 -214
  309. package/work-orders/NOTIF-13.md +0 -142
  310. package/work-orders/NOTIF-14.md +0 -151
  311. package/work-orders/PRIM-1.md +0 -177
  312. package/work-orders/SHELL-1.md +0 -255
  313. package/work-orders/SHELL-2.md +0 -197
  314. package/work-orders/SHELL-3.md +0 -359
  315. package/work-orders/SHELL-4.md +0 -351
  316. package/work-orders/SHELL-5.md +0 -345
  317. package/work-orders/SHELL-6.md +0 -210
  318. package/work-orders/THEME-1.md +0 -587
  319. package/work-orders/THEME-10.md +0 -303
  320. package/work-orders/THEME-11.md +0 -208
  321. package/work-orders/THEME-2.md +0 -339
  322. package/work-orders/THEME-3.md +0 -210
  323. package/work-orders/THEME-4.md +0 -271
  324. package/work-orders/THEME-5.md +0 -341
  325. package/work-orders/THEME-6.md +0 -247
  326. package/work-orders/THEME-7.md +0 -82
  327. package/work-orders/THEME-8.md +0 -211
  328. package/work-orders/THEME-9.md +0 -194
  329. package/work-orders/UCM-AUTH-10.md +0 -490
  330. package/work-orders/UCM-AUTH-11.md +0 -185
  331. package/work-orders/UCM-AUTH-12.md +0 -98
  332. package/work-orders/UCM-AUTH-13.md +0 -47
  333. package/work-orders/UCM-AUTH-9.md +0 -207
  334. package/work-orders/UCM-CHART-10.md +0 -150
  335. package/work-orders/UCM-CHART-11.md +0 -132
  336. package/work-orders/UCM-CHART-12.md +0 -348
  337. package/work-orders/UCM-CHART-13.md +0 -122
  338. package/work-orders/UCM-CHART-14.md +0 -198
  339. package/work-orders/UCM-CHART-15.md +0 -187
  340. package/work-orders/UCM-CHART-16.md +0 -169
  341. package/work-orders/UCM-CHART-17.md +0 -195
  342. package/work-orders/UCM-CHART-18.md +0 -200
  343. package/work-orders/UCM-CHART-8.md +0 -147
  344. package/work-orders/UCM-CHART-9.md +0 -265
  345. package/work-orders/UCM-CHAT-1.md +0 -190
  346. package/work-orders/UCM-CHAT-2.md +0 -75
  347. package/work-orders/UCM-DEP-1.md +0 -63
  348. package/work-orders/UCM-I18N-4.md +0 -226
  349. package/work-orders/UCM-I18N-5.md +0 -211
  350. package/work-orders/UCM-MSG-20.md +0 -192
  351. package/work-orders/UCM-PRIM-2.md +0 -114
  352. package/work-orders/UCM-SHELL-7.md +0 -134
  353. package/work-orders/UCM-SHELL-8.md +0 -125
  354. package/work-orders/UCM-TEST-1.md +0 -304
  355. package/work-orders/UCM-THEME-13.md +0 -69
  356. package/work-orders/UCM-THEME-14.md +0 -312
  357. package/work-orders/UCM-THEME-15.md +0 -356
  358. package/work-orders/UCM-THEME-16.md +0 -80
  359. package/work-orders/UCM-THEME-17.md +0 -111
  360. package/work-orders/UCM-THEME-18.md +0 -184
  361. package/work-orders/assets/AUTH-4-user-list-card.html +0 -407
  362. package/work-orders/assets/PRIM-1-dashboard-primitives.html +0 -624
  363. package/work-orders/assets/SHELL-2-account-navigation.html +0 -1159
  364. package/work-orders/assets/THEME-1-baseline-reference-sheet.html +0 -1352
  365. package/work-orders/assets/UCM-CHAT-1-ai-chat.html +0 -447
  366. package/work-orders/assets/UCM-THEME-13-dark-prototype.html +0 -390
  367. package/work-orders/assets/UCM-THEME-17-type-scale.html +0 -391
@@ -1,87 +0,0 @@
1
- import React, { useState } from 'react';
2
- import { Badge, Box, Button, Collapse, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, IconButton, List, ListItem, ListItemButton, ListItemText, Menu, MenuItem, Stack, TextField } from '@mui/material';
3
- import { MoreVert } from '@mui/icons-material';
4
- import { useTranslation } from 'react-i18next';
5
-
6
- export const CHAT_LIST_ROW_ACTION_SX = { width: 40, height: 40 };
7
- export const CHAT_LIST_ARCHIVED_ACTION_SX = { justifyContent: 'space-between', px: 2 };
8
-
9
- /**
10
- * The chat list: active chats, then an "Archived" entry that expands the archived ones (read-only, restorable).
11
- * Rename, Archive/Restore and Delete sit in each row's overflow menu; Delete asks for confirmation first.
12
- */
13
- export function ChatList({ chats = [], archivedChats = [], activeId, hasMore = false, onSelect, onNew, onRename, onArchive, onRestore, onDelete, onLoadMore, sx }) {
14
- const { t } = useTranslation();
15
- const [menu, setMenu] = useState(null); // { anchor, chat, archived }
16
- const [dialog, setDialog] = useState(null); // { kind: 'rename' | 'delete', chat }
17
- const [title, setTitle] = useState('');
18
- const [showArchived, setShowArchived] = useState(false);
19
-
20
- const openMenu = (event, chat, archived) => { event.stopPropagation(); setMenu({ anchor: event.currentTarget, chat, archived }); };
21
- const closeMenu = () => setMenu(null);
22
- const startRename = () => { setTitle(menu.chat.title || ''); setDialog({ kind: 'rename', chat: menu.chat }); closeMenu(); };
23
- const startDelete = () => { setDialog({ kind: 'delete', chat: menu.chat }); closeMenu(); };
24
- const toggleArchive = () => { (menu.archived ? onRestore : onArchive)?.(menu.chat); closeMenu(); };
25
- const closeDialog = () => setDialog(null);
26
- const confirmRename = () => { onRename?.(dialog.chat, title.trim()); closeDialog(); };
27
- const confirmDelete = () => { onDelete?.(dialog.chat); closeDialog(); };
28
-
29
- const row = (chat, archived) => (
30
- <ListItem
31
- key={chat.id}
32
- disablePadding
33
- secondaryAction={<IconButton edge="end" aria-label={t('Chat.actions')} onClick={(event) => openMenu(event, chat, archived)} sx={CHAT_LIST_ROW_ACTION_SX}><MoreVert fontSize="small" /></IconButton>}
34
- >
35
- <ListItemButton selected={chat.id === activeId} onClick={() => onSelect?.(chat)} sx={{ minHeight: 48, pr: 6 }}>
36
- <ListItemText primary={chat.title || t('Chat.untitled')} slotProps={{ primary: { noWrap: true } }} />
37
- </ListItemButton>
38
- </ListItem>
39
- );
40
-
41
- return (
42
- <Stack sx={{ minWidth: 0, height: '100%', overflowY: 'auto', ...sx }} component="nav" aria-label={t('Chat.chats')}>
43
- <Box sx={{ p: 1.5 }}>
44
- <Button fullWidth variant="contained" onClick={onNew}>{t('Chat.newChat')}</Button>
45
- </Box>
46
- <List disablePadding>{chats.map((chat) => row(chat, false))}</List>
47
- {hasMore ? <Button onClick={onLoadMore}>{t('Chat.loadMore')}</Button> : null}
48
- {archivedChats.length > 0 ? (
49
- <>
50
- <Button color="inherit" onClick={() => setShowArchived((value) => !value)} aria-expanded={showArchived} sx={CHAT_LIST_ARCHIVED_ACTION_SX}>
51
- {t('Chat.archived')}
52
- <Badge color="default" badgeContent={archivedChats.length} sx={{ mr: 1.5 }} />
53
- </Button>
54
- <Collapse in={showArchived} unmountOnExit><List disablePadding>{archivedChats.map((chat) => row(chat, true))}</List></Collapse>
55
- </>
56
- ) : null}
57
-
58
- <Menu anchorEl={menu?.anchor} open={Boolean(menu)} onClose={closeMenu}>
59
- <MenuItem onClick={startRename}>{t('Chat.rename')}</MenuItem>
60
- <MenuItem onClick={toggleArchive}>{menu?.archived ? t('Chat.restore') : t('Chat.archive')}</MenuItem>
61
- <MenuItem onClick={startDelete}>{t('Chat.delete')}</MenuItem>
62
- </Menu>
63
-
64
- <Dialog open={dialog?.kind === 'rename'} onClose={closeDialog} fullWidth maxWidth="xs">
65
- <DialogTitle>{t('Chat.rename')}</DialogTitle>
66
- <DialogContent>
67
- <TextField autoFocus fullWidth margin="dense" value={title} onChange={(event) => setTitle(event.target.value)} slotProps={{ htmlInput: { 'aria-label': t('Chat.renameLabel'), maxLength: 120 } }} onKeyDown={(event) => { if (event.key === 'Enter' && title.trim()) confirmRename(); }} />
68
- </DialogContent>
69
- <DialogActions>
70
- <Button onClick={closeDialog}>{t('Chat.cancel')}</Button>
71
- <Button variant="contained" disabled={!title.trim()} onClick={confirmRename}>{t('Chat.save')}</Button>
72
- </DialogActions>
73
- </Dialog>
74
-
75
- <Dialog open={dialog?.kind === 'delete'} onClose={closeDialog} fullWidth maxWidth="xs">
76
- <DialogTitle>{t('Chat.delete')}</DialogTitle>
77
- <DialogContent><DialogContentText>{t('Chat.deleteConfirm')}</DialogContentText></DialogContent>
78
- <DialogActions>
79
- <Button onClick={closeDialog}>{t('Chat.cancel')}</Button>
80
- <Button color="error" variant="contained" onClick={confirmDelete}>{t('Chat.delete')}</Button>
81
- </DialogActions>
82
- </Dialog>
83
- </Stack>
84
- );
85
- }
86
-
87
- export default ChatList;
@@ -1,128 +0,0 @@
1
- import React, { useEffect, useLayoutEffect, useRef } from 'react';
2
- import { Alert, Box, Button, Chip, Stack, Tooltip, Typography } from '@mui/material';
3
- import { useTranslation } from 'react-i18next';
4
- import MarkdownReply from './MarkdownReply';
5
-
6
- export const CHAT_THREAD_TOOL_CHIP_SX = { alignSelf: 'flex-start' };
7
- export const CHAT_THREAD_NOTICE_SX = { mb: 2 };
8
-
9
- const selectionLine = (turn, t) => [turn.model, turn.effort && t(`Chat.effort.${turn.effort}`)].filter(Boolean).join(' · ');
10
- const sameSelection = (a, b) => a.driver === b.driver && a.model === b.model && a.effort === b.effort;
11
-
12
- function SourceChips({ sources }) {
13
- const { t } = useTranslation();
14
- if (!sources?.length) return null;
15
- return (
16
- <Stack direction="row" flexWrap="wrap" gap={0.75} role="list" aria-label={t('Chat.sources')}>
17
- {sources.map((source, index) => (
18
- <Tooltip key={`${source.label}-${index}`} title={source.reference || ''} describeChild>
19
- <Chip role="listitem" size="small" variant="outlined" label={source.label} />
20
- </Tooltip>
21
- ))}
22
- </Stack>
23
- );
24
- }
25
-
26
- function Answer({ turn, tool, onRetry }) {
27
- const { t } = useTranslation();
28
- const generating = turn.state === 'generating';
29
- const failed = ['failed', 'cancelled'].includes(turn.state) && turn.error_code;
30
- return (
31
- <Stack spacing={1} aria-busy={generating}>
32
- {turn.assistant_text ? <MarkdownReply text={turn.assistant_text} /> : null}
33
- {generating && !turn.assistant_text && !tool ? <Typography variant="body2" color="text.secondary">{t('Chat.typing')}</Typography> : null}
34
- {generating && tool ? <Chip size="small" color="primary" variant="outlined" label={tool.label} sx={CHAT_THREAD_TOOL_CHIP_SX} /> : null}
35
- <SourceChips sources={turn.sources} />
36
- {!generating && selectionLine(turn, t) ? <Typography variant="caption" color="text.secondary">{selectionLine(turn, t)}</Typography> : null}
37
- {turn.state === 'interrupted' ? (
38
- <Stack direction="row" alignItems="center" gap={1}>
39
- <Chip size="small" color="warning" label={t('Chat.interrupted')} />
40
- {onRetry ? <Button size="small" onClick={() => onRetry(turn)}>{t('Chat.retry')}</Button> : null}
41
- </Stack>
42
- ) : null}
43
- {failed ? (
44
- <Alert severity="error" action={onRetry ? <Button color="inherit" size="small" onClick={() => onRetry(turn)}>{t('Chat.retry')}</Button> : null}>
45
- {t('Chat.answerIncomplete')}
46
- </Alert>
47
- ) : null}
48
- </Stack>
49
- );
50
- }
51
-
52
- /**
53
- * The turns of one chat. The streaming answer is simply the last turn in state `generating`; the caller keeps its text
54
- * up to date. `notice` is a connection or limit message shown under the last turn. `readOnly` (an archived chat) hides Retry.
55
- */
56
- export function ChatThread({ turns = [], tool = null, notice = null, hasOlder = false, olderBusy = false, onLoadOlder, onRetry, readOnly = false, sx }) {
57
- const { t } = useTranslation();
58
- const end = useRef(null);
59
- const scroller = useRef(null);
60
- const heightBeforeOlder = useRef(null);
61
- const pinned = useRef(true); // follow the stream only while the reader is at the bottom
62
- const last = turns[turns.length - 1];
63
- // Follow the stream, but only when new content arrives at the end (not when older turns are prepended).
64
- useEffect(() => { if (pinned.current) end.current?.scrollIntoView?.({ block: 'end' }); }, [last?.id, last?.assistant_text, last?.state]);
65
-
66
- // Keep the reader's position when older turns are prepended.
67
- useLayoutEffect(() => {
68
- const el = scroller.current;
69
- if (el && heightBeforeOlder.current !== null) el.scrollTop += el.scrollHeight - heightBeforeOlder.current;
70
- heightBeforeOlder.current = null;
71
- }, [turns[0]?.id]);
72
- const loadingOlder = useRef(false); // one request at a time, also across rapid scroll events
73
- const loadOlder = async () => {
74
- if (loadingOlder.current) return;
75
- loadingOlder.current = true;
76
- heightBeforeOlder.current = scroller.current?.scrollHeight ?? null;
77
- try { await onLoadOlder?.(); } finally { loadingOlder.current = false; }
78
- };
79
-
80
- return (
81
- <Box ref={scroller} onScroll={(event) => {
82
- const el = event.currentTarget;
83
- pinned.current = el.scrollHeight - el.scrollTop - el.clientHeight < 80;
84
- if (hasOlder && !olderBusy && el.scrollTop <= 40) loadOlder();
85
- }} role="log" aria-live="polite" aria-label={t('Chat.thread')} sx={{ minHeight: 0, flex: 1, overflowY: 'auto', p: { xs: 1.5, md: 2.5 }, ...sx }}>
86
- {hasOlder ? (
87
- <Box sx={{ textAlign: 'center', mb: 2 }}>
88
- <Button size="small" onClick={loadOlder} disabled={olderBusy}>{t('Chat.loadOlder')}</Button>
89
- </Box>
90
- ) : null}
91
- {turns.length === 0 ? (
92
- <Typography variant="h6" color="text.secondary" align="center" sx={{ mt: 6 }}>{t('Chat.emptyTitle')}</Typography>
93
- ) : null}
94
- {turns.map((turn, index) => {
95
- const previous = turns[index - 1];
96
- return (
97
- <Box key={turn.id ?? index} sx={{ mb: 3 }}>
98
- {previous && !sameSelection(previous, turn) ? (
99
- <Stack direction="row" alignItems="center" gap={1} sx={{ mb: 2, color: 'text.secondary' }} role="separator">
100
- <Box sx={{ flex: 1, borderTop: 1, borderColor: 'divider' }} />
101
- <Typography variant="caption">{t('Chat.modelChanged', { model: selectionLine(turn, t) })}</Typography>
102
- <Box sx={{ flex: 1, borderTop: 1, borderColor: 'divider' }} />
103
- </Stack>
104
- ) : null}
105
- <Box sx={{ display: 'flex', justifyContent: 'flex-end', mb: 1.5 }}>
106
- <Typography sx={{ maxWidth: '85%', whiteSpace: 'pre-wrap', overflowWrap: 'anywhere', bgcolor: 'action.hover', borderRadius: 2, px: 1.5, py: 1 }}>
107
- {turn.user_text}
108
- </Typography>
109
- </Box>
110
- <Answer turn={turn} tool={index === turns.length - 1 ? tool : null} onRetry={readOnly ? undefined : onRetry} />
111
- </Box>
112
- );
113
- })}
114
- {notice ? (
115
- <Alert
116
- severity={notice.severity || 'warning'}
117
- sx={CHAT_THREAD_NOTICE_SX}
118
- action={notice.action ? <Button color="inherit" size="small" onClick={notice.action.onClick}>{notice.action.label}</Button> : null}
119
- >
120
- {notice.text}
121
- </Alert>
122
- ) : null}
123
- <div ref={end} />
124
- </Box>
125
- );
126
- }
127
-
128
- export default ChatThread;
@@ -1,244 +0,0 @@
1
- import React, { useCallback, useEffect, useMemo, useState } from 'react';
2
- import { Alert, Box, Button, Chip, Drawer, Stack, Typography, useMediaQuery, useTheme } from '@mui/material';
3
- import { useTranslation } from 'react-i18next';
4
- import { createChatApi } from './api';
5
- import { useChatSocket } from './useChatSocket';
6
- import ChatList from './ChatList';
7
- import ChatThread from './ChatThread';
8
- import ChatComposer from './ChatComposer';
9
- import ModelPicker from './ModelPicker';
10
-
11
- const PENDING_ID = 'pending';
12
- const bySeq = (a, b) => (a.seq ?? Number.MAX_SAFE_INTEGER) - (b.seq ?? Number.MAX_SAFE_INTEGER);
13
- const chronological = (turns) => [...(turns || [])].sort(bySeq);
14
- const isGenerating = (turn) => turn.state === 'generating';
15
-
16
- /** Replaces the turn that was generating (or has the same id) with the final one; appends it when neither exists. */
17
- const settleTurn = (turns, final) => {
18
- const index = turns.findIndex((turn) => turn.id === final.id || isGenerating(turn));
19
- if (index < 0) return chronological([...turns, final]);
20
- return [...turns.slice(0, index), final, ...turns.slice(index + 1)];
21
- };
22
- const failGenerating = (turns, code) => turns.map((turn) => (isGenerating(turn)
23
- ? { ...turn, state: 'failed', error_code: code === 'quota_exceeded' ? null : code }
24
- : turn));
25
- const appendDelta = (turns, text) => {
26
- const index = turns.findLastIndex(isGenerating);
27
- if (index < 0) return turns;
28
- return turns.map((turn, i) => (i === index ? { ...turn, assistant_text: `${turn.assistant_text || ''}${text}` } : turn));
29
- };
30
-
31
- /**
32
- * The complete chat surface: chat list, thread, composer and model picker for one user.
33
- *
34
- * Props: `apiBase` and `wsUrl` (where the app mounted the chat routes), `api` (partial overrides of the REST
35
- * calls; every function not given keeps its default), `scope` (passed when creating a chat), `sx`.
36
- */
37
- export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, sx }) {
38
- const { t } = useTranslation();
39
- const theme = useTheme();
40
- const narrow = useMediaQuery(theme.breakpoints.down('md'));
41
- const api = useMemo(() => createChatApi(apiOverrides, { apiBase }), [apiOverrides, apiBase]);
42
-
43
- const [status, setStatus] = useState('loading'); // loading | available | not_configured | error
44
- const [catalogue, setCatalogue] = useState({ entries: [], default: null });
45
- const [chats, setChats] = useState([]);
46
- const [archived, setArchived] = useState([]);
47
- const [nextChats, setNextChats] = useState(null);
48
- const [chat, setChat] = useState(null);
49
- const [turns, setTurns] = useState([]);
50
- const [olderCursor, setOlderCursor] = useState(null);
51
- const [olderBusy, setOlderBusy] = useState(false);
52
- const [tool, setTool] = useState(null);
53
- const [draft, setDraft] = useState('');
54
- const [problem, setProblem] = useState(null); // an error code or close reason, shown as a notice
55
- const [listOpen, setListOpen] = useState(false);
56
- const [pickerOpen, setPickerOpen] = useState(false);
57
- const [openedOnce, setOpenedOnce] = useState(false); // distinguishes a reconnect from the first connect
58
-
59
- const running = turns.some(isGenerating);
60
- const isArchived = Boolean(chat?.archived_at);
61
- const selection = chat?.selection || catalogue.default;
62
- const activeEntry = catalogue.entries.find((entry) => entry.id === selection?.entry);
63
-
64
- const loadLists = useCallback(async () => {
65
- const [active, old] = await Promise.all([api.listChats(), api.listChats({ archived: true })]);
66
- setChats(active.results || []);
67
- setNextChats(active.next || null);
68
- setArchived(old.results || []);
69
- }, [api]);
70
-
71
- useEffect(() => {
72
- let live = true;
73
- api.getStatus()
74
- .then(async (state) => {
75
- if (state.status !== 'available') { if (live) setStatus(state.status); return; }
76
- const [entries] = await Promise.all([api.getCatalogue(), loadLists()]);
77
- if (live) { setStatus(state.status); setCatalogue(entries); }
78
- })
79
- .catch(() => { if (live) setStatus('error'); });
80
- return () => { live = false; };
81
- }, [api, loadLists]);
82
-
83
- useEffect(() => {
84
- setTurns([]); setOlderCursor(null); setTool(null); setProblem(null); setDraft(''); setOpenedOnce(false);
85
- if (!chat?.id) return undefined;
86
- let live = true;
87
- api.listTurns(chat.id)
88
- .then((page) => { if (live) { setTurns(chronological(page.results)); setOlderCursor(page.next || null); } })
89
- .catch(() => { if (live) setProblem('load_error'); });
90
- return () => { live = false; };
91
- }, [api, chat?.id]);
92
-
93
- const onFrame = useCallback((frame, chatId) => {
94
- if (chatId !== chat?.id) return;
95
- if (frame.type === 'history') setTurns(chronological(frame.turns));
96
- else if (frame.type === 'delta') setTurns((current) => appendDelta(current, frame.text || ''));
97
- else if (frame.type === 'tool') setTool(frame.phase === 'start' ? { label: frame.label, name: frame.name } : null);
98
- else if (frame.type === 'turn' && frame.turn) {
99
- setTool(null);
100
- setTurns((current) => settleTurn(current, frame.turn));
101
- if (frame.turn.error_code === 'quota_exceeded') setProblem('quota_exceeded');
102
- } else if (frame.type === 'error') {
103
- setTool(null);
104
- setTurns((current) => failGenerating(current, frame.code));
105
- setProblem(frame.code);
106
- }
107
- }, [chat?.id]);
108
- const onOpen = useCallback(() => { setOpenedOnce(true); setProblem((current) => (current === 'connection_lost' ? null : current)); }, []);
109
- const onClose = useCallback(({ reason, retrying }) => { if (!retrying) setProblem(reason); }, []);
110
- const socket = useChatSocket(chat?.id, { wsUrl, onFrame, onOpen, onClose });
111
-
112
- const guarded = (action) => async (...args) => {
113
- try { return await action(...args); } catch { setProblem('action_error'); return null; }
114
- };
115
-
116
- const selectChat = (next) => { setChat(next); setListOpen(false); };
117
- const createChat = guarded(async () => {
118
- const created = await api.createChat(scope ? { scope } : {});
119
- setChats((current) => [created, ...current]);
120
- selectChat(created);
121
- });
122
- const updateChat = guarded(async (target, patch) => {
123
- const updated = await api.updateChat(target.id, patch);
124
- if (chat?.id === target.id) setChat(updated);
125
- await loadLists();
126
- });
127
- const deleteChat = guarded(async (target) => {
128
- await api.deleteChat(target.id);
129
- setChats((current) => current.filter((item) => item.id !== target.id));
130
- setArchived((current) => current.filter((item) => item.id !== target.id));
131
- if (chat?.id === target.id) setChat(null);
132
- });
133
- const loadMoreChats = guarded(async () => {
134
- const page = await api.listChats({ cursor: nextChats });
135
- setChats((current) => [...current, ...(page.results || [])]);
136
- setNextChats(page.next || null);
137
- });
138
- const loadOlder = guarded(async () => {
139
- setOlderBusy(true);
140
- try {
141
- const page = await api.listTurns(chat.id, { cursor: olderCursor });
142
- setTurns((current) => chronological([...(page.results || []), ...current]));
143
- setOlderCursor(page.next || null);
144
- } finally { setOlderBusy(false); }
145
- });
146
-
147
- const startTurn = (message) => {
148
- if (!socket.send({ type: 'send', message })) return false;
149
- setProblem(null);
150
- setTurns((current) => [...current, {
151
- id: PENDING_ID, user_text: message, assistant_text: '', state: 'generating', sources: [],
152
- driver: activeEntry?.driver, model: activeEntry?.label || activeEntry?.model, effort: selection?.effort,
153
- }]);
154
- return true;
155
- };
156
- const send = () => { if (startTurn(draft)) setDraft(''); };
157
- const retry = (turn) => {
158
- if (!socket.connected) return;
159
- setTurns((current) => current.filter((item) => item.id !== turn.id));
160
- startTurn(turn.user_text);
161
- };
162
-
163
- const noticeFor = () => {
164
- const texts = {
165
- session_ended: 'Chat.sessionEnded', access_lost: 'Chat.accessLost', rate_limited: 'Chat.rateLimited',
166
- load_error: 'Chat.loadError', action_error: 'Chat.actionError',
167
- };
168
- if (problem === 'quota_exceeded') {
169
- return { text: t('Chat.usageLimit', { model: activeEntry?.label || activeEntry?.model || '' }), action: { label: t('Chat.changeModel'), onClick: () => setPickerOpen(true) } };
170
- }
171
- if (problem === 'connection_lost') return { text: t('Chat.connectionLost'), action: { label: t('Chat.reconnect'), onClick: socket.reconnect } };
172
- if (problem === 'not_configured') return null;
173
- if (texts[problem]) return { text: t(texts[problem]), severity: 'warning' };
174
- return null;
175
- };
176
-
177
- const list = (
178
- <ChatList
179
- chats={chats}
180
- archivedChats={archived}
181
- activeId={chat?.id}
182
- hasMore={Boolean(nextChats)}
183
- onSelect={selectChat}
184
- onNew={createChat}
185
- onRename={(target, title) => updateChat(target, { title })}
186
- onArchive={(target) => updateChat(target, { archived: true })}
187
- onRestore={(target) => updateChat(target, { archived: false })}
188
- onDelete={deleteChat}
189
- onLoadMore={loadMoreChats}
190
- />
191
- );
192
-
193
- const unavailable = status === 'not_configured' || problem === 'not_configured';
194
- if (status === 'loading') return <Box sx={sx} aria-busy="true" />;
195
- if (status === 'error') return <Box sx={sx}><Alert severity="error">{t('Chat.loadError')}</Alert></Box>;
196
- if (unavailable) {
197
- return (
198
- <Stack alignItems="center" justifyContent="center" spacing={1} sx={{ minHeight: 320, p: 3, textAlign: 'center', ...sx }}>
199
- <Typography variant="h6">{t('Chat.unavailable')}</Typography>
200
- <Typography color="text.secondary">{t('Chat.noModel')}</Typography>
201
- </Stack>
202
- );
203
- }
204
-
205
- return (
206
- <Box sx={{ display: 'grid', gridTemplateColumns: narrow ? 'minmax(0, 1fr)' : 'minmax(240px, 320px) minmax(0, 1fr)', height: '100%', minHeight: 480, border: 1, borderColor: 'divider', borderRadius: 1, overflow: 'hidden', bgcolor: 'background.paper', ...sx }}>
207
- {narrow ? null : <Box sx={{ borderRight: 1, borderColor: 'divider', minHeight: 0 }}>{list}</Box>}
208
- <Stack sx={{ minWidth: 0, minHeight: 0 }}>
209
- <Stack direction="row" alignItems="center" gap={1} sx={{ px: 1.5, py: 0.5, borderBottom: 1, borderColor: 'divider', minHeight: 56 }}>
210
- {narrow ? <Button color="inherit" onClick={() => setListOpen(true)}>{t('Chat.chats')}</Button> : null}
211
- <Typography noWrap sx={{ flex: 1, fontWeight: 600 }}>{chat ? (chat.title || t('Chat.untitled')) : ''}</Typography>
212
- {socket.status === 'connecting' && openedOnce ? <Chip size="small" color="warning" variant="outlined" label={t('Chat.reconnecting')} /> : null}
213
- {isArchived ? <Chip size="small" label={t('Chat.archived')} /> : null}
214
- {isArchived ? <Button size="small" onClick={() => updateChat(chat, { archived: false })}>{t('Chat.restore')}</Button> : null}
215
- {chat ? (
216
- <ModelPicker
217
- entries={catalogue.entries}
218
- selection={selection}
219
- disabled={isArchived || running}
220
- open={pickerOpen}
221
- onOpenChange={setPickerOpen}
222
- onChange={(next) => updateChat(chat, { selection: next })}
223
- />
224
- ) : null}
225
- </Stack>
226
- {chat ? (
227
- <>
228
- <ChatThread turns={turns} tool={tool} notice={noticeFor()} hasOlder={Boolean(olderCursor)} olderBusy={olderBusy} onLoadOlder={loadOlder} onRetry={retry} readOnly={isArchived} />
229
- {isArchived ? <Typography variant="caption" color="text.secondary" sx={{ px: 2, pb: 1 }}>{t('Chat.archivedReadOnly')}</Typography> : null}
230
- <ChatComposer value={draft} onChange={setDraft} onSend={send} onStop={() => socket.send({ type: 'stop' })} running={running} archived={isArchived} connected={socket.connected} />
231
- </>
232
- ) : (
233
- <Stack alignItems="center" justifyContent="center" spacing={2} sx={{ flex: 1, p: 3 }}>
234
- <Typography color="text.secondary" align="center">{t('Chat.selectChat')}</Typography>
235
- <Button variant="contained" onClick={createChat}>{t('Chat.newChat')}</Button>
236
- </Stack>
237
- )}
238
- </Stack>
239
- {narrow ? <Drawer open={listOpen} onClose={() => setListOpen(false)} slotProps={{ paper: { sx: { width: 'min(320px, 86vw)' } } }}>{list}</Drawer> : null}
240
- </Box>
241
- );
242
- }
243
-
244
- export default ChatWorkspace;
@@ -1,22 +0,0 @@
1
- import React, { memo } from 'react';
2
- import { Box } from '@mui/material';
3
- import { useTranslation } from 'react-i18next';
4
- import ReactMarkdown from 'react-markdown';
5
- import remarkGfm from 'remark-gfm';
6
-
7
- export const MARKDOWN_LIMIT = 200000;
8
- const allowed = ['p','br','hr','h1','h2','h3','h4','h5','h6','strong','em','del','ul','ol','li','blockquote','code','pre','table','thead','tbody','tr','th','td','a','img'];
9
- const plainText = (children) => (Array.isArray(children) ? children : [children]).map((child) => typeof child === 'string' ? child : '').join('');
10
- function MarkdownReply({ text = '' }) {
11
- const { t } = useTranslation();
12
- if (text.length > MARKDOWN_LIMIT) return <Box sx={{ whiteSpace: 'pre-wrap', overflowWrap: 'anywhere' }}>{text}</Box>;
13
- return <Box sx={{ minWidth: 0, overflowWrap: 'anywhere', '& p': { my: 1 }, '& table': { borderCollapse: 'collapse' }, '& th,& td': { border: 1, borderColor: 'divider', p: 1 }, '& pre': { overflowX: 'auto', bgcolor: 'action.hover', p: 1, borderRadius: 1 }, '& blockquote': { borderLeft: 2, borderColor: 'divider', pl: 1, color: 'text.secondary' } }}>
14
- <ReactMarkdown remarkPlugins={[remarkGfm]} allowedElements={allowed} unwrapDisallowed components={{
15
- a: ({ href, children }) => { const label = plainText(children); return <span>{children}{href && href !== label ? ' (' + href + ')' : ''}</span>; },
16
- img: ({ alt, src }) => <span>{alt || src || ''}</span>,
17
- table: ({ children }) => <Box role="region" tabIndex={0} aria-label={t('Chat.markdownTable')} sx={{ overflowX: 'auto', maxWidth: '100%' }}><table>{children}</table></Box>,
18
- pre: ({ children }) => <pre tabIndex={0} aria-label={t('Chat.markdownCode')}>{children}</pre>,
19
- }}>{text}</ReactMarkdown>
20
- </Box>;
21
- }
22
- export default memo(MarkdownReply);
@@ -1,85 +0,0 @@
1
- import React, { useMemo, useRef, useState } from 'react';
2
- import { Box, Button, Chip, Drawer, List, ListItemButton, ListItemText, Popover, Stack, ToggleButton, ToggleButtonGroup, Typography, useMediaQuery, useTheme } from '@mui/material';
3
- import { useTranslation } from 'react-i18next';
4
-
5
- export const EFFORT_LEVELS = ['low', 'medium', 'high', 'max'];
6
- export const driverName = (t, id) => t(`Chat.driver.${id}`, { defaultValue: id });
7
-
8
- const groupByDriver = (entries) => entries.reduce((groups, entry) => {
9
- (groups[entry.driver] = groups[entry.driver] || []).push(entry);
10
- return groups;
11
- }, {});
12
-
13
- /**
14
- * Model and effort of one chat. A popover at wide widths, a bottom sheet at narrow widths. `onChange` receives
15
- * `{ entry, effort }`; the caller persists it (the change applies from the next turn). Can be controlled with `open`.
16
- */
17
- export function ModelPicker({ entries = [], selection, onChange, disabled = false, open, onOpenChange }) {
18
- const { t } = useTranslation();
19
- const theme = useTheme();
20
- const narrow = useMediaQuery(theme.breakpoints.down('md'));
21
- const anchor = useRef(null);
22
- const [innerOpen, setInnerOpen] = useState(false);
23
- const isOpen = open ?? innerOpen;
24
- const setOpen = (value) => { setInnerOpen(value); onOpenChange?.(value); };
25
- const groups = useMemo(() => groupByDriver(entries), [entries]);
26
- const active = entries.find((entry) => entry.id === selection?.entry);
27
-
28
- const pickEntry = (entry) => {
29
- const effort = entry.efforts?.includes(selection?.effort) ? selection.effort : entry.efforts?.[0];
30
- onChange?.({ entry: entry.id, effort });
31
- };
32
-
33
- const content = (
34
- <Box sx={{ p: 2, minWidth: narrow ? 0 : 320, maxWidth: '100%' }}>
35
- <Stack spacing={1.5}>
36
- {Object.entries(groups).map(([driver, items]) => (
37
- <Box key={driver} role="group" aria-label={driverName(t, driver)}>
38
- <Typography variant="overline" color="text.secondary">{driverName(t, driver)}</Typography>
39
- <List dense disablePadding>
40
- {items.map((entry) => (
41
- <ListItemButton key={entry.id} selected={entry.id === selection?.entry} onClick={() => pickEntry(entry)} sx={{ minHeight: 40, borderRadius: 1 }}>
42
- <ListItemText primary={entry.label || entry.model} />
43
- {entry.billing === 'pay_per_use' ? <Chip size="small" variant="outlined" label={t('Chat.payPerUse')} /> : null}
44
- </ListItemButton>
45
- ))}
46
- </List>
47
- </Box>
48
- ))}
49
- <Box>
50
- <Typography variant="overline" color="text.secondary">{t('Chat.effortLabel')}</Typography>
51
- <ToggleButtonGroup
52
- exclusive
53
- fullWidth
54
- size="small"
55
- aria-label={t('Chat.effortLabel')}
56
- value={selection?.effort || null}
57
- onChange={(_event, effort) => { if (effort && active) onChange?.({ entry: active.id, effort }); }}
58
- >
59
- {EFFORT_LEVELS.map((effort) => (
60
- <ToggleButton key={effort} value={effort} disabled={!active?.efforts?.includes(effort)} sx={{ minHeight: 40 }}>
61
- {t(`Chat.effort.${effort}`)}
62
- </ToggleButton>
63
- ))}
64
- </ToggleButtonGroup>
65
- </Box>
66
- </Stack>
67
- </Box>
68
- );
69
-
70
- const label = active ? [active.label || active.model, selection?.effort && t(`Chat.effort.${selection.effort}`)].filter(Boolean).join(' · ') : t('Chat.chooseModel');
71
- return (
72
- <>
73
- <Button ref={anchor} size="small" color="inherit" disabled={disabled || entries.length === 0} onClick={() => setOpen(true)} aria-haspopup="dialog">
74
- {label}
75
- </Button>
76
- {narrow ? (
77
- <Drawer anchor="bottom" open={isOpen} onClose={() => setOpen(false)}>{content}</Drawer>
78
- ) : (
79
- <Popover open={isOpen} anchorEl={anchor.current} onClose={() => setOpen(false)} anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }}>{content}</Popover>
80
- )}
81
- </>
82
- );
83
- }
84
-
85
- export default ModelPicker;
package/src/chat/api.js DELETED
@@ -1,18 +0,0 @@
1
- import apiClient from '../auth/apiClient';
2
- import { chatApiUrls } from './wire';
3
-
4
- export function createChatApi(overrides = {}, { apiBase = '/api/assistant/' } = {}) {
5
- const urls = chatApiUrls(apiBase);
6
- const data = (request) => request.then((response) => response.data);
7
- const defaults = {
8
- getCatalogue: () => data(apiClient.get(urls.catalogue)),
9
- listChats: ({ archived = false, cursor } = {}) => data(apiClient.get(urls.chats, { params: { archived, ...(cursor ? { cursor } : {}) } })),
10
- createChat: (payload = {}) => data(apiClient.post(urls.chats, payload)),
11
- updateChat: (id, patch) => data(apiClient.patch(urls.chat(id), patch)),
12
- deleteChat: (id) => data(apiClient.delete(urls.chat(id))),
13
- listTurns: (id, { cursor } = {}) => data(apiClient.get(urls.turns(id), { params: cursor ? { cursor } : {} })),
14
- getStatus: () => data(apiClient.get(urls.status)),
15
- };
16
- return { ...defaults, ...overrides };
17
- }
18
- export const defaultChatApi = createChatApi();
@@ -1,32 +0,0 @@
1
- import { useCallback, useEffect, useRef, useState } from 'react';
2
- import { CHAT_CLOSE_CODES, defaultChatWsUrl } from './wire';
3
-
4
- const delays = [1000, 2000, 4000];
5
- export function useChatSocket(chatId, { wsUrl = defaultChatWsUrl, onFrame, onOpen, onClose } = {}) {
6
- const socket = useRef(null); const callbacks = useRef({ onFrame, onOpen, onClose }); callbacks.current = { onFrame, onOpen, onClose };
7
- // The URL builder is read at connect time only: an inline arrow from the caller must not reopen the socket on every render.
8
- const urlBuilder = useRef(wsUrl); urlBuilder.current = wsUrl;
9
- const [status, setStatus] = useState('idle'); const [generation, setGeneration] = useState(0);
10
- const reconnect = useCallback(() => setGeneration((n) => n + 1), []);
11
- useEffect(() => {
12
- if (!chatId || typeof WebSocket === 'undefined') { setStatus('idle'); return undefined; }
13
- let alive = true; let tries = 0; let timer; let wasOpened = false;
14
- const connect = () => {
15
- setStatus('connecting'); const ws = new WebSocket(typeof urlBuilder.current === 'function' ? urlBuilder.current(chatId) : urlBuilder.current); socket.current = ws;
16
- ws.onopen = () => { if (!alive) return; tries = 0; setStatus('open'); callbacks.current.onOpen?.(chatId, wasOpened); wasOpened = true; };
17
- ws.onmessage = (event) => { if (!alive) return; try { const frame = JSON.parse(event.data); if (frame && typeof frame === 'object') callbacks.current.onFrame?.(frame, chatId); } catch { /* Ignore malformed frames. */ } };
18
- ws.onclose = (event) => {
19
- if (!alive || socket.current !== ws) return; socket.current = null;
20
- const reason = CHAT_CLOSE_CODES[event.code];
21
- if (reason) { setStatus('closed'); callbacks.current.onClose?.({ reason, chatId, retrying: false }); return; }
22
- if (tries < delays.length) { setStatus('connecting'); callbacks.current.onClose?.({ reason: 'connection_lost', chatId, retrying: true }); timer = setTimeout(connect, delays[tries++]); }
23
- else { setStatus('closed'); callbacks.current.onClose?.({ reason: 'connection_lost', chatId, retrying: false }); }
24
- };
25
- };
26
- connect();
27
- return () => { alive = false; clearTimeout(timer); const ws = socket.current; socket.current = null; if (ws) { ws.onopen = ws.onmessage = ws.onclose = null; ws.close(); } };
28
- }, [chatId, generation]);
29
- const send = useCallback((frame) => { const ws = socket.current; if (!ws || ws.readyState !== WebSocket.OPEN) return false; ws.send(JSON.stringify(frame)); return true; }, []);
30
- return { status, connected: status === 'open', send, reconnect };
31
- }
32
- export default useChatSocket;
package/src/chat/wire.js DELETED
@@ -1,7 +0,0 @@
1
- export const CHAT_CLOSE_CODES = { 4401: 'session_ended', 4403: 'access_lost', 4429: 'rate_limited' };
2
- export const CHAT_ERROR_CODES = ['quota_exceeded', 'provider_error', 'timeout', 'prompt_too_long', 'invalid_output', 'security_violation', 'not_configured', 'rate_limited', 'invalid_selection', 'archived', 'turn_active', 'invalid_frame'];
3
- export const chatApiUrls = (base = '/api/assistant/') => {
4
- const root = base.replace(/\/$/, '') + '/';
5
- return { catalogue: root + 'catalogue/', chats: root + 'chats/', chat: (id) => root + 'chats/' + encodeURIComponent(id) + '/', turns: (id) => root + 'chats/' + encodeURIComponent(id) + '/turns/', status: root + 'status/' };
6
- };
7
- export const defaultChatWsUrl = (chatId) => (window.location.protocol === 'https:' ? 'wss:' : 'ws:') + '//' + window.location.host + '/ws/assistant/chats/' + encodeURIComponent(chatId) + '/';