@nextclaw/ui 0.15.2 → 0.15.4

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 (212) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/assets/aiden0z-pptx-renderer.es-Bd99vut2.js +94 -0
  3. package/dist/assets/api-BOXOrpcJ.js +13 -0
  4. package/dist/assets/app-presenter-provider-CkHLbvZQ.js +106 -0
  5. package/dist/assets/app-presenter-provider-D3BuuOyZ.css +1 -0
  6. package/dist/assets/appearance-settings-page-fLIJbx1C.js +1 -0
  7. package/dist/assets/{book-open-Ba2f7YiG.js → book-open-DWUjS6aW.js} +1 -1
  8. package/dist/assets/channels-list-page-CvCTJraa.js +8 -0
  9. package/dist/assets/chat-page-B42UUIFR.js +1 -0
  10. package/dist/assets/chunk-DseTPa7n.js +1 -0
  11. package/dist/assets/config-split-page-DBgt9S8b.js +1 -0
  12. package/dist/assets/confirm-dialog-GSXIvoRU.js +5 -0
  13. package/dist/assets/desktop-update-config-7bmNeWIC.js +1 -0
  14. package/dist/assets/dist-DC7f4TJH.js +41 -0
  15. package/dist/assets/doc-browser-CgdoLUT92.js +1 -0
  16. package/dist/assets/doc-browser-D0monHjG.js +1 -0
  17. package/dist/assets/doc-browser-context-CGwEOhBy.js +1 -0
  18. package/dist/assets/docx-preview-eFH9DRsS.js +20 -0
  19. package/dist/assets/download-DiP9zx-J.js +1 -0
  20. package/dist/assets/{external-link-DxuPaDoK.js → external-link-C6ZeSPef.js} +1 -1
  21. package/dist/assets/eye-suvKmtwn.js +1 -0
  22. package/dist/assets/folder-CMELbQGG.js +1 -0
  23. package/dist/assets/{form-actions-BztL7P_T.js → form-actions-CUAzpNe_.js} +1 -1
  24. package/dist/assets/index-BFeNDQ4R.css +1 -0
  25. package/dist/assets/index-D_6U-M94.js +2 -0
  26. package/dist/assets/jszip.min-Das2IAnb.js +2 -0
  27. package/dist/assets/loader-circle-tYHStefV.js +1 -0
  28. package/dist/assets/logo-badge-Cu5UGH_4.js +1 -0
  29. package/dist/assets/mcp-marketplace-page-BUzHDwW6.js +9 -0
  30. package/dist/assets/mcp-marketplace-page-ohUAdfqJ.js +1 -0
  31. package/dist/assets/model-config-page-CWP6pyBm.js +1 -0
  32. package/dist/assets/plus-tywizkeY.js +1 -0
  33. package/dist/assets/popover-DImguRok.js +1 -0
  34. package/dist/assets/provider-models-C_yOh6DE.js +1 -0
  35. package/dist/assets/provider-scoped-model-input-CE7p4SbJ.js +1 -0
  36. package/dist/assets/providers-config-page-BKPo8SjH.js +1 -0
  37. package/dist/assets/react-5sjAT_6d.js +8 -0
  38. package/dist/assets/{refresh-cw-eT8BF-8B.js → refresh-cw-CHLBzWWj.js} +1 -1
  39. package/dist/assets/remote-DXJryUxB.js +1 -0
  40. package/dist/assets/rotate-cw-BefO5brU.js +1 -0
  41. package/dist/assets/runtime-config-page-1Axv4QGu.js +1 -0
  42. package/dist/assets/{save-Cb2g0BOi.js → save-BABzyrjB.js} +1 -1
  43. package/dist/assets/{search-BcHjwdsb.js → search-BTqxG3ZG.js} +1 -1
  44. package/dist/assets/search-config-page-BkKKmxmS.js +1 -0
  45. package/dist/assets/secrets-config-page-CWJMyu-k.js +3 -0
  46. package/dist/assets/security-config-DeQUIXfi.js +1 -0
  47. package/dist/assets/select-TYZDBNmq.js +1 -0
  48. package/dist/assets/setting-row-DR23Z_5I.js +1 -0
  49. package/dist/assets/{settings-2-2DWauOjY.js → settings-2-D8WWcBnw.js} +1 -1
  50. package/dist/assets/{skeleton-P5oM14E1.js → skeleton-CloHeg0S.js} +1 -1
  51. package/dist/assets/tabs-CX-ckWoo.js +1 -0
  52. package/dist/assets/tag-chip-mCc23Rhb.js +1 -0
  53. package/dist/assets/trash-2-SAW1Z4Po.js +1 -0
  54. package/dist/assets/use-config-BucdaK23.js +1 -0
  55. package/dist/assets/use-confirm-dialog-C95F6sT1.js +1 -0
  56. package/dist/assets/use-viewport-layout-C6m3Nte7.js +1 -0
  57. package/dist/assets/x-DtCPHwCu.js +1 -0
  58. package/dist/assets/xlsx-B6zVt1RK.js +64 -0
  59. package/dist/index.html +34 -28
  60. package/package.json +14 -9
  61. package/src/app/components/layout/sidebar-items.tsx +3 -3
  62. package/src/app/components/layout/sidebar-rail.styles.ts +2 -2
  63. package/src/app/components/layout/sidebar.tsx +1 -1
  64. package/src/app/styles/design-system.css +17 -4
  65. package/src/features/chat/components/__tests__/chat-popover-content.test.tsx +41 -0
  66. package/src/features/chat/components/chat-popover-content.tsx +26 -0
  67. package/src/features/chat/components/conversation/__tests__/chat-conversation-content.test.tsx +13 -0
  68. package/src/features/chat/components/conversation/__tests__/chat-conversation-header-section.test.tsx +21 -11
  69. package/src/features/chat/components/conversation/__tests__/chat-conversation-header.test.tsx +2 -2
  70. package/src/features/chat/components/conversation/__tests__/chat-conversation-workspace-section.test.tsx +28 -1
  71. package/src/features/chat/components/conversation/chat-conversation-content.tsx +5 -4
  72. package/src/features/chat/components/conversation/chat-conversation-header-section.tsx +9 -18
  73. package/src/features/chat/components/conversation/chat-conversation-track.tsx +35 -0
  74. package/src/features/chat/components/conversation/chat-conversation-workspace-section.tsx +1 -0
  75. package/src/features/chat/components/layout/chat-sidebar-toolbar.tsx +7 -7
  76. package/src/features/chat/components/layout/chat-sidebar-utility-menu.tsx +4 -15
  77. package/src/features/chat/features/conversation/components/__tests__/session-conversation-input.streaming.test.tsx +20 -1
  78. package/src/features/chat/features/conversation/components/session-conversation-input.tsx +69 -54
  79. package/src/features/chat/features/conversation/components/session-queued-input-rows.tsx +1 -1
  80. package/src/features/chat/features/message/components/__tests__/chat-message-list.container.test.tsx +62 -1
  81. package/src/features/chat/features/message/components/chat-message-list.container.tsx +63 -2
  82. package/src/features/chat/features/message/utils/__tests__/chat-message-file-operation.utils.test.ts +30 -0
  83. package/src/features/chat/features/message/utils/__tests__/chat-message-process-summary.utils.test.ts +11 -1
  84. package/src/features/chat/features/message/utils/__tests__/chat-message-texts.utils.test.ts +23 -0
  85. package/src/features/chat/features/message/utils/chat-message-process-summary.utils.ts +5 -0
  86. package/src/features/chat/features/message/utils/chat-message-texts.utils.ts +138 -0
  87. package/src/features/chat/features/session/components/__tests__/chat-sidebar-session-item.test.tsx +37 -0
  88. package/src/features/chat/features/session/components/chat-sidebar-project-groups.tsx +5 -4
  89. package/src/features/chat/features/session/components/chat-sidebar-session-item.tsx +3 -8
  90. package/src/features/chat/features/session/components/session-header/__tests__/chat-session-header-actions.test.tsx +65 -20
  91. package/src/features/chat/features/session/components/session-header/chat-session-header-actions.tsx +26 -28
  92. package/src/features/chat/features/session/components/session-header/chat-session-project-badge.tsx +3 -3
  93. package/src/features/chat/features/session/components/session-header/chat-session-title-switcher.tsx +5 -5
  94. package/src/features/chat/features/welcome/components/chat-welcome-project-picker.tsx +4 -4
  95. package/src/features/chat/features/welcome/components/chat-welcome-session-type-picker.tsx +4 -4
  96. package/src/features/chat/features/workspace/components/__tests__/chat-session-workspace-file-preview.test.tsx +463 -99
  97. package/src/features/chat/features/workspace/components/__tests__/chat-session-workspace-panel-content.test.tsx +113 -2
  98. package/src/features/chat/features/workspace/components/__tests__/chat-session-workspace-panel.test.tsx +1 -0
  99. package/src/features/chat/features/workspace/components/chat-session-workspace-directory-browser.tsx +197 -44
  100. package/src/features/chat/features/workspace/components/chat-session-workspace-file-breadcrumb-browser.tsx +11 -5
  101. package/src/features/chat/features/workspace/components/chat-session-workspace-file-breadcrumbs.tsx +8 -6
  102. package/src/features/chat/features/workspace/components/chat-session-workspace-file-preview.tsx +99 -67
  103. package/src/features/chat/features/workspace/components/chat-session-workspace-panel-content.tsx +239 -1
  104. package/src/features/chat/features/workspace/components/chat-session-workspace-panel-nav.tsx +56 -6
  105. package/src/features/chat/features/workspace/components/chat-session-workspace-panel.tsx +29 -7
  106. package/src/features/chat/features/workspace/components/file-content-preview/use-workspace-file-buffer.ts +42 -0
  107. package/src/features/chat/features/workspace/components/file-content-preview/workspace-document-preview-state.tsx +18 -0
  108. package/src/features/chat/features/workspace/components/file-content-preview/workspace-docx-preview.css +89 -0
  109. package/src/features/chat/features/workspace/components/file-content-preview/workspace-docx-preview.tsx +87 -0
  110. package/src/features/chat/features/workspace/components/file-content-preview/workspace-presentation-preview.tsx +82 -0
  111. package/src/features/chat/features/workspace/components/file-content-preview/workspace-spreadsheet-preview.tsx +180 -0
  112. package/src/features/chat/features/workspace/components/workspace-file-content-preview.tsx +191 -0
  113. package/src/features/chat/features/workspace/hooks/use-chat-conversation-workspace-state.ts +1 -4
  114. package/src/features/chat/features/workspace/utils/__tests__/chat-workspace-panel-view-model.utils.test.ts +53 -10
  115. package/src/features/chat/features/workspace/utils/chat-thread-workspace-session.utils.ts +68 -2
  116. package/src/features/chat/features/workspace/utils/chat-workspace-file-tab-persistence.utils.ts +21 -0
  117. package/src/features/chat/features/workspace/utils/chat-workspace-file-tab.utils.ts +63 -0
  118. package/src/features/chat/features/workspace/utils/chat-workspace-file-viewer.utils.ts +49 -0
  119. package/src/features/chat/features/workspace/utils/chat-workspace-panel-layout.utils.ts +13 -0
  120. package/src/features/chat/features/workspace/utils/chat-workspace-panel-view-model.utils.ts +120 -38
  121. package/src/features/chat/index.ts +1 -0
  122. package/src/features/chat/managers/__tests__/chat-thread-workspace.manager.test.ts +76 -0
  123. package/src/features/chat/managers/__tests__/chat-thread.manager.test.ts +44 -60
  124. package/src/features/chat/managers/chat-thread.manager.ts +123 -124
  125. package/src/features/chat/pages/ncp-chat-page.tsx +1 -2
  126. package/src/features/chat/stores/__tests__/chat-thread.store.test.ts +78 -1
  127. package/src/features/chat/stores/chat-message-layout.store.test.ts +37 -0
  128. package/src/features/chat/stores/chat-message-layout.store.ts +41 -0
  129. package/src/features/chat/stores/chat-thread.store.ts +73 -13
  130. package/src/features/cron/components/cron-config.tsx +63 -80
  131. package/src/features/marketplace/components/detail-doc/__tests__/marketplace-detail-doc.test.tsx +44 -6
  132. package/src/features/marketplace/components/marketplace-detail-doc.tsx +8 -4
  133. package/src/features/marketplace/components/marketplace-page-parts.tsx +1 -1
  134. package/src/features/marketplace/hooks/use-marketplace-detail-doc-entry.ts +84 -0
  135. package/src/features/panel-apps/components/panel-apps-list.tsx +2 -2
  136. package/src/features/right-panel-resources/components/right-panel-resource-home-page.tsx +1 -1
  137. package/src/features/settings/pages/__tests__/appearance-settings-page.test.tsx +25 -8
  138. package/src/features/settings/pages/appearance-settings-page.tsx +92 -13
  139. package/src/features/side-dock/components/side-dock.tsx +3 -3
  140. package/src/index.css +275 -15
  141. package/src/shared/components/__tests__/file-type-icon.test.tsx +61 -0
  142. package/src/shared/components/actions/action-link.tsx +1 -1
  143. package/src/shared/components/doc-browser/__tests__/doc-browser-context.test.tsx +19 -0
  144. package/src/shared/components/doc-browser/__tests__/doc-browser.test.tsx +16 -0
  145. package/src/shared/components/doc-browser/doc-browser-context.tsx +1 -0
  146. package/src/shared/components/doc-browser/doc-browser-panel-parts.tsx +1 -1
  147. package/src/shared/components/doc-browser/doc-browser.tsx +11 -3
  148. package/src/shared/components/doc-browser/managers/doc-browser.manager.ts +5 -0
  149. package/src/shared/components/doc-browser/stores/doc-browser.store.ts +6 -1
  150. package/src/shared/components/doc-browser/types/doc-browser.types.ts +2 -0
  151. package/src/shared/components/doc-browser/utils/doc-browser-state.utils.ts +11 -0
  152. package/src/shared/components/file-type-icon.tsx +272 -0
  153. package/src/shared/components/resizable-right-panel/__tests__/resizable-right-panel.test.tsx +22 -0
  154. package/src/shared/components/resizable-right-panel/resizable-right-panel.tsx +17 -2
  155. package/src/shared/components/ui/actions/icon-action-button.tsx +1 -1
  156. package/src/shared/components/ui/button.tsx +1 -1
  157. package/src/shared/components/ui/dialog.tsx +1 -1
  158. package/src/shared/components/ui/input.tsx +1 -1
  159. package/src/shared/components/ui/select.tsx +1 -1
  160. package/src/shared/components/ui/switch.tsx +1 -1
  161. package/src/shared/components/ui/tab-strip/__tests__/compact-tab-strip.test.tsx +38 -0
  162. package/src/shared/components/ui/tab-strip/compact-tab-strip.tsx +82 -2
  163. package/src/shared/components/ui/tabs.tsx +1 -1
  164. package/src/shared/components/ui/textarea.tsx +1 -1
  165. package/src/shared/lib/api/__tests__/server-path.utils.test.ts +28 -0
  166. package/src/shared/lib/api/utils/server-path.utils.ts +19 -20
  167. package/src/shared/lib/i18n/locales/en-US/chat.json +99 -0
  168. package/src/shared/lib/i18n/locales/en-US/core.json +6 -0
  169. package/src/shared/lib/i18n/locales/zh-CN/chat.json +99 -0
  170. package/src/shared/lib/i18n/locales/zh-CN/core.json +6 -0
  171. package/dist/assets/api-B7Qigvtm.js +0 -13
  172. package/dist/assets/appearance-settings-page-CuE0Iiqj.js +0 -1
  173. package/dist/assets/channels-list-page-CTsM6TcP.js +0 -8
  174. package/dist/assets/chat-page-C_5dcuE3.js +0 -1
  175. package/dist/assets/config-split-page-Fbb4PtTf.js +0 -1
  176. package/dist/assets/confirm-dialog-D2EG3nqE.js +0 -5
  177. package/dist/assets/desktop-update-config-BGR3HUi1.js +0 -1
  178. package/dist/assets/dist-7JTjycxE.js +0 -1
  179. package/dist/assets/dist-wXLhk4hl.js +0 -1
  180. package/dist/assets/doc-browser-bHyXnxlj.js +0 -1
  181. package/dist/assets/doc-browser-context-CYAGm5d5.js +0 -1
  182. package/dist/assets/doc-browser-gTrQ3jCF.js +0 -1
  183. package/dist/assets/es2015-j1SRCIX5.js +0 -41
  184. package/dist/assets/i18n-provider-B4oMxOFx.js +0 -1
  185. package/dist/assets/index-CvrvblgX.css +0 -1
  186. package/dist/assets/index-Obd4JYU2.js +0 -104
  187. package/dist/assets/loader-circle-CdzgK4eH.js +0 -1
  188. package/dist/assets/mcp-marketplace-page-Bt7CuOoq.js +0 -9
  189. package/dist/assets/mcp-marketplace-page-Ck3t78_n.js +0 -1
  190. package/dist/assets/model-config-page-DeKk9gvE.js +0 -1
  191. package/dist/assets/plus-Bx7wQbhG.js +0 -1
  192. package/dist/assets/provider-scoped-model-input-DsH2LF1q.js +0 -1
  193. package/dist/assets/providers-config-page-BFnGp68F.js +0 -1
  194. package/dist/assets/react-UirzUuST.js +0 -8
  195. package/dist/assets/remote-CDkHZtA8.js +0 -1
  196. package/dist/assets/rotate-cw-1JqxHTuw.js +0 -1
  197. package/dist/assets/runtime-config-page-BelAqiNG.js +0 -1
  198. package/dist/assets/search-config-page-zPm6--Ig.js +0 -1
  199. package/dist/assets/secrets-config-page-Cxyp-KuQ.js +0 -3
  200. package/dist/assets/security-config-B_gCq9fn.js +0 -1
  201. package/dist/assets/select-CdSEOwVM.js +0 -1
  202. package/dist/assets/setting-row-CTAtGexr.js +0 -1
  203. package/dist/assets/side-dock-DPvakJ0a.js +0 -3
  204. package/dist/assets/switch-BU_UEULb.js +0 -1
  205. package/dist/assets/tag-chip-D-WsKoT1.js +0 -1
  206. package/dist/assets/tooltip-CjkOaHW7.js +0 -1
  207. package/dist/assets/use-config--hx5oxQn.js +0 -1
  208. package/dist/assets/use-confirm-dialog-CD9a_SK1.js +0 -1
  209. package/dist/assets/x-DT5x45JU.js +0 -1
  210. /package/dist/assets/{config-hints-C_iP1zl_.js → config-hints-fDrYfl0l.js} +0 -0
  211. /package/dist/assets/{host-capabilities-9bB_998Z.js → host-capabilities-zZvY9U63.js} +0 -0
  212. /package/dist/assets/{middleware-BILWbJE4.js → middleware-BLMHv9YF.js} +0 -0
@@ -16,12 +16,15 @@ import type {
16
16
  ChatChildSessionTab,
17
17
  ChatThreadSnapshot,
18
18
  ChatWorkspaceNavigationEntry,
19
+ ChatWorkspacePanelKind,
19
20
  ChatWorkspaceFileTab,
20
21
  } from '@/features/chat/stores/chat-thread.store';
21
22
  import { useChatThreadStore } from '@/features/chat/stores/chat-thread.store';
23
+ import { normalizeChatWorkspacePanelWidth } from '@/features/chat/features/workspace/utils/chat-workspace-panel-layout.utils';
22
24
  import { t } from '@/shared/lib/i18n';
23
25
  import {
24
26
  areWorkspaceNavigationEntriesEqual,
27
+ createWorkspaceSelectionPatch,
25
28
  createSideChatDraft,
26
29
  materializeSideChatDraftSnapshot,
27
30
  upsertChildSessionTab,
@@ -31,11 +34,19 @@ import {
31
34
  pushNavigationHistoryEntry,
32
35
  stepNavigationHistory,
33
36
  } from '@/shared/lib/navigation-history';
37
+ import {
38
+ resolveAlternateWorkspaceFileViewer,
39
+ type ChatWorkspaceFileViewer,
40
+ } from '@/features/chat/features/workspace/utils/chat-workspace-file-viewer.utils';
41
+ import {
42
+ createWorkspaceFileTab,
43
+ upsertWorkspaceFileTab,
44
+ } from '@/features/chat/features/workspace/utils/chat-workspace-file-tab.utils';
34
45
 
35
46
  type WorkspaceChildReadState = Parameters<ChatSessionListManager['markVisibleWorkspaceChildRead']>[0];
36
47
  export type ChatVisibleWorkspaceSelection =
37
48
  | { kind: 'child-session'; tab: WorkspaceChildReadState }
38
- | { kind: 'file' | 'side-chat-draft' | 'cron' }
49
+ | { kind: Exclude<ChatWorkspacePanelKind, 'child-session'> }
39
50
  | null;
40
51
 
41
52
  export class ChatThreadManager {
@@ -102,54 +113,29 @@ export class ChatThreadManager {
102
113
  return useChatSessionListStore.getState().snapshot.selectedSessionKey ?? null;
103
114
  };
104
115
 
105
- private buildWorkspaceFileTab = (
106
- action: ChatFileOpenActionViewModel,
107
- parentSessionKey: string | null,
108
- ): ChatWorkspaceFileTab | null => {
109
- const normalizedPath = action.path.trim();
110
- if (!normalizedPath) {
111
- return null;
112
- }
113
- const normalizedParentSessionKey = parentSessionKey?.trim() || null;
114
- const previewViewer =
115
- action.viewMode === 'preview' &&
116
- action.previewViewer !== 'rendered' &&
117
- (action.previewViewer === 'auto' || action.previewViewer === 'source' || /\.html?$/i.test(normalizedPath))
118
- ? 'source'
119
- : action.previewViewer ?? null;
120
- const tabViewIdentity = action.viewMode === 'preview' && previewViewer === 'rendered' ? 'preview:rendered' : action.viewMode;
121
- return {
122
- key: `${normalizedParentSessionKey ?? 'draft'}::${tabViewIdentity}::${normalizedPath}`,
123
- parentSessionKey: normalizedParentSessionKey,
124
- path: normalizedPath,
125
- label: action.label?.trim() || null,
126
- viewMode: action.viewMode,
127
- previewViewer,
128
- line: action.line ?? null,
129
- column: action.column ?? null,
130
- rawText: action.rawText ?? null,
131
- beforeText: action.beforeText ?? null,
132
- afterText: action.afterText ?? null,
133
- patchText: action.patchText ?? null,
134
- oldStartLine: action.oldStartLine ?? null,
135
- newStartLine: action.newStartLine ?? null,
136
- fullLines: action.fullLines,
137
- };
138
- };
139
-
140
- private upsertWorkspaceFileTab = (nextTab: ChatWorkspaceFileTab): ChatWorkspaceFileTab[] => {
116
+ private activateWorkspaceFileTab = (
117
+ nextTab: ChatWorkspaceFileTab,
118
+ adjacentToKey?: string,
119
+ ) => {
120
+ const { parentSessionKey } = nextTab;
141
121
  const { workspaceFileTabs } = useChatThreadStore.getState().snapshot;
142
- const existingIndex = workspaceFileTabs.findIndex((tab) => tab.key === nextTab.key);
143
- if (existingIndex === -1) {
144
- return [nextTab, ...workspaceFileTabs];
145
- }
146
- const nextTabs = [...workspaceFileTabs];
147
- nextTabs.splice(existingIndex, 1);
148
- nextTabs.unshift({
149
- ...workspaceFileTabs[existingIndex],
150
- ...nextTab,
122
+ this.setWorkspaceSelection({
123
+ workspacePanelParentKey: parentSessionKey,
124
+ activeWorkspacePanelKind: 'file',
125
+ workspaceFileTabs: upsertWorkspaceFileTab(
126
+ workspaceFileTabs,
127
+ nextTab,
128
+ adjacentToKey,
129
+ ),
130
+ activeWorkspaceFileKey: nextTab.key,
131
+ activeChildSessionKey: null,
132
+ activeSideChatDraft: null,
133
+ }, {
134
+ kind: 'file',
135
+ key: nextTab.key,
151
136
  });
152
- return nextTabs;
137
+ this.ensureWorkspaceParentRoute(parentSessionKey);
138
+ this.onWorkspacePanelOpened?.();
153
139
  };
154
140
 
155
141
  private ensureWorkspaceParentRoute = (parentSessionKey: string | null) => {
@@ -164,52 +150,6 @@ export class ChatThreadManager {
164
150
  }
165
151
  };
166
152
 
167
- private createWorkspaceSelectionPatch = (
168
- entry: ChatWorkspaceNavigationEntry,
169
- snapshot: ChatThreadSnapshot,
170
- ): Partial<ChatThreadSnapshot> | null => {
171
- if (entry.kind === 'cron') {
172
- return {
173
- activeWorkspacePanelKind: 'cron',
174
- activeChildSessionKey: null,
175
- activeSideChatDraft: null,
176
- activeWorkspaceFileKey: null,
177
- };
178
- }
179
- if (entry.kind === 'file') {
180
- if (!snapshot.workspaceFileTabs.some((tab) => tab.key === entry.key)) {
181
- return null;
182
- }
183
- return {
184
- activeWorkspacePanelKind: 'file',
185
- activeChildSessionKey: null,
186
- activeSideChatDraft: null,
187
- activeWorkspaceFileKey: entry.key,
188
- };
189
- }
190
- if (entry.kind === 'side-chat-draft') {
191
- const { activeSideChatDraft } = snapshot;
192
- if (activeSideChatDraft?.draftKey !== entry.key) {
193
- return null;
194
- }
195
- return {
196
- activeWorkspacePanelKind: 'side-chat-draft',
197
- activeChildSessionKey: null,
198
- activeSideChatDraft,
199
- activeWorkspaceFileKey: null,
200
- };
201
- }
202
- if (!entry.key) {
203
- return null;
204
- }
205
- return {
206
- activeWorkspacePanelKind: 'child-session',
207
- activeChildSessionKey: entry.key,
208
- activeSideChatDraft: null,
209
- activeWorkspaceFileKey: null,
210
- };
211
- };
212
-
213
153
  private setWorkspaceSelection = (
214
154
  patch: Partial<ChatThreadSnapshot>,
215
155
  entry: ChatWorkspaceNavigationEntry,
@@ -230,6 +170,59 @@ export class ChatThreadManager {
230
170
  });
231
171
  };
232
172
 
173
+ private openWorkspacePage = (
174
+ rawParentSessionKey: string,
175
+ kind: 'overview' | 'child-sessions' | 'project-files' | 'cron',
176
+ ) => {
177
+ const parentSessionKey = rawParentSessionKey.trim();
178
+ if (!parentSessionKey) {
179
+ return;
180
+ }
181
+ this.setWorkspaceSelection({
182
+ workspacePanelParentKey: parentSessionKey,
183
+ activeWorkspacePanelKind: kind,
184
+ activeChildSessionKey: null,
185
+ activeSideChatDraft: null,
186
+ activeWorkspaceFileKey: null,
187
+ }, { kind });
188
+ this.ensureWorkspaceParentRoute(parentSessionKey);
189
+ this.onWorkspacePanelOpened?.();
190
+ };
191
+
192
+ openWorkspaceOverview = (sessionKey: string) => {
193
+ this.openWorkspacePage(sessionKey, 'overview');
194
+ };
195
+
196
+ toggleWorkspacePanel = (sessionKey: string) => {
197
+ const normalizedSessionKey = sessionKey.trim();
198
+ if (!normalizedSessionKey) {
199
+ return;
200
+ }
201
+ const { snapshot } = useChatThreadStore.getState();
202
+ if (
203
+ snapshot.workspacePanelParentKey === normalizedSessionKey &&
204
+ snapshot.activeWorkspacePanelKind
205
+ ) {
206
+ this.closeWorkspacePanel();
207
+ return;
208
+ }
209
+ this.openWorkspaceOverview(normalizedSessionKey);
210
+ };
211
+
212
+ setWorkspacePanelWidth = (width: number) => {
213
+ this.syncSnapshot({
214
+ workspacePanelWidth: normalizeChatWorkspacePanelWidth(width),
215
+ });
216
+ };
217
+
218
+ openChildSessions = (sessionKey: string) => {
219
+ this.openWorkspacePage(sessionKey, 'child-sessions');
220
+ };
221
+
222
+ openProjectFiles = (sessionKey: string) => {
223
+ this.openWorkspacePage(sessionKey, 'project-files');
224
+ };
225
+
233
226
  openChildSessionPanel = (params: {
234
227
  parentSessionKey: string;
235
228
  activeChildSessionKey?: string | null;
@@ -315,23 +308,43 @@ export class ChatThreadManager {
315
308
 
316
309
  openFilePreview = (action: ChatFileOpenActionViewModel) => {
317
310
  const parentSessionKey = this.resolveWorkspaceParentSessionKey();
318
- const nextTab = this.buildWorkspaceFileTab(action, parentSessionKey);
311
+ const nextTab = createWorkspaceFileTab(action, parentSessionKey);
319
312
  if (!nextTab) {
320
313
  return;
321
314
  }
322
- this.setWorkspaceSelection({
323
- workspacePanelParentKey: parentSessionKey,
324
- activeWorkspacePanelKind: 'file',
325
- workspaceFileTabs: this.upsertWorkspaceFileTab(nextTab),
326
- activeWorkspaceFileKey: nextTab.key,
327
- activeChildSessionKey: null,
328
- activeSideChatDraft: null,
329
- }, {
330
- kind: 'file',
331
- key: nextTab.key,
332
- });
333
- this.ensureWorkspaceParentRoute(parentSessionKey);
334
- this.onWorkspacePanelOpened?.();
315
+ this.activateWorkspaceFileTab(nextTab);
316
+ };
317
+
318
+ openWorkspaceFileViewer = (
319
+ fileKey: string,
320
+ viewer?: ChatWorkspaceFileViewer,
321
+ ) => {
322
+ const sourceTab = useChatThreadStore.getState().snapshot.workspaceFileTabs
323
+ .find((tab) => tab.key === fileKey.trim());
324
+ if (!sourceTab || sourceTab.viewMode !== 'preview') {
325
+ return;
326
+ }
327
+ const nextViewer = viewer ?? resolveAlternateWorkspaceFileViewer(
328
+ sourceTab.path,
329
+ sourceTab.previewViewer,
330
+ );
331
+ if (!nextViewer) {
332
+ return;
333
+ }
334
+ const nextTab = createWorkspaceFileTab({
335
+ path: sourceTab.path,
336
+ label: sourceTab.label ?? undefined,
337
+ viewMode: 'preview',
338
+ previewViewer: nextViewer,
339
+ line: sourceTab.line ?? undefined,
340
+ column: sourceTab.column ?? undefined,
341
+ rawText: sourceTab.rawText ?? undefined,
342
+ contentUrl: sourceTab.contentUrl ?? undefined,
343
+ mimeType: sourceTab.mimeType ?? undefined,
344
+ }, sourceTab.parentSessionKey);
345
+ if (nextTab) {
346
+ this.activateWorkspaceFileTab(nextTab, sourceTab.key);
347
+ }
335
348
  };
336
349
 
337
350
  private openSessionFromToolAction = (action: ChatToolActionViewModel) => {
@@ -477,7 +490,7 @@ export class ChatThreadManager {
477
490
  };
478
491
  const restoreEntry = history.entries[history.index];
479
492
  const restorePatch = restoreEntry
480
- ? this.createWorkspaceSelectionPatch(restoreEntry, nextSnapshot)
493
+ ? createWorkspaceSelectionPatch(restoreEntry, nextSnapshot)
481
494
  : null;
482
495
  Object.assign(nextPatch, restorePatch ?? {
483
496
  activeWorkspacePanelKind: null,
@@ -501,21 +514,7 @@ export class ChatThreadManager {
501
514
  };
502
515
 
503
516
  openSessionCronPanel = (sessionKey: string) => {
504
- const parentSessionKey = sessionKey.trim();
505
- if (!parentSessionKey) {
506
- return;
507
- }
508
- this.setWorkspaceSelection({
509
- workspacePanelParentKey: parentSessionKey,
510
- activeWorkspacePanelKind: 'cron',
511
- activeChildSessionKey: null,
512
- activeSideChatDraft: null,
513
- activeWorkspaceFileKey: null,
514
- }, {
515
- kind: 'cron',
516
- });
517
- this.ensureWorkspaceParentRoute(parentSessionKey);
518
- this.onWorkspacePanelOpened?.();
517
+ this.openWorkspacePage(sessionKey, 'cron');
519
518
  };
520
519
 
521
520
  goBackWorkspacePanel = () => {
@@ -538,7 +537,7 @@ export class ChatThreadManager {
538
537
  if (!step) {
539
538
  return;
540
539
  }
541
- const selectionPatch = this.createWorkspaceSelectionPatch(step.entry, snapshot);
540
+ const selectionPatch = createWorkspaceSelectionPatch(step.entry, snapshot);
542
541
  if (!selectionPatch) {
543
542
  return;
544
543
  }
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  useEffect,
3
3
  useMemo,
4
- useState,
5
4
  } from "react";
6
5
  import { useLocation, useNavigate, useParams } from "react-router-dom";
7
6
  import {
@@ -51,7 +50,7 @@ function useNcpChatUiBindings() {
51
50
 
52
51
  export function NcpChatPage({ view }: ChatPageProps) {
53
52
  const appPresenter = useAppPresenter();
54
- const [presenter] = useState(() => new ChatPresenter(appPresenter));
53
+ const presenter = useMemo(() => new ChatPresenter(appPresenter), [appPresenter]);
55
54
  return (
56
55
  <ChatPresenterProvider presenter={presenter}>
57
56
  <NcpChatPageContent view={view} />
@@ -1,5 +1,8 @@
1
1
  import { beforeEach, describe, expect, it } from 'vitest';
2
- import { useChatThreadStore } from '@/features/chat/stores/chat-thread.store';
2
+ import {
3
+ useChatThreadStore,
4
+ } from '@/features/chat/stores/chat-thread.store';
5
+ import { CHAT_WORKSPACE_PANEL_DEFAULT_WIDTH } from '@/features/chat/features/workspace/utils/chat-workspace-panel-layout.utils';
3
6
 
4
7
  const chatThreadWorkspaceStorageKey = 'nextclaw.chat.workspace-panel.state';
5
8
 
@@ -27,6 +30,7 @@ function resetChatThreadStore() {
27
30
  activeWorkspaceFileKey: null,
28
31
  workspaceNavigationHistory: [],
29
32
  workspaceNavigationHistoryIndex: 0,
33
+ workspacePanelWidth: CHAT_WORKSPACE_PANEL_DEFAULT_WIDTH,
30
34
  },
31
35
  });
32
36
  }
@@ -118,6 +122,79 @@ describe('chat thread workspace panel persistence', () => {
118
122
  expect(persisted.state.snapshot.activeSideChatDraft).toBeUndefined();
119
123
  });
120
124
 
125
+ it('persists the stable workspace pages', async () => {
126
+ useChatThreadStore.getState().setSnapshot({
127
+ workspacePanelParentKey: 'session-1',
128
+ activeWorkspacePanelKind: 'project-files',
129
+ workspaceNavigationHistory: [
130
+ { kind: 'overview' },
131
+ { kind: 'child-sessions' },
132
+ { kind: 'project-files' },
133
+ ],
134
+ workspaceNavigationHistoryIndex: 2,
135
+ workspacePanelWidth: 620,
136
+ });
137
+
138
+ const persisted = window.localStorage.getItem(chatThreadWorkspaceStorageKey);
139
+ resetChatThreadStore();
140
+ if (persisted) {
141
+ window.localStorage.setItem(chatThreadWorkspaceStorageKey, persisted);
142
+ }
143
+ await useChatThreadStore.persist.rehydrate();
144
+
145
+ expect(useChatThreadStore.getState().snapshot).toMatchObject({
146
+ workspacePanelParentKey: 'session-1',
147
+ activeWorkspacePanelKind: 'project-files',
148
+ workspaceNavigationHistory: [
149
+ { kind: 'overview' },
150
+ { kind: 'child-sessions' },
151
+ { kind: 'project-files' },
152
+ ],
153
+ workspaceNavigationHistoryIndex: 2,
154
+ workspacePanelWidth: 620,
155
+ });
156
+ });
157
+
158
+ it('keeps the active file tab when persistence trims older workspace tabs', async () => {
159
+ const workspaceFileTabs = Array.from({ length: 9 }, (_, index) => ({
160
+ key: `session-1::preview::file-${index}.txt`,
161
+ parentSessionKey: 'session-1',
162
+ path: `file-${index}.txt`,
163
+ viewMode: 'preview' as const,
164
+ previewViewer: 'source' as const,
165
+ }));
166
+ const activeWorkspaceFileKey = workspaceFileTabs[8]!.key;
167
+ useChatThreadStore.getState().setSnapshot({
168
+ workspacePanelParentKey: 'session-1',
169
+ activeWorkspacePanelKind: 'file',
170
+ workspaceFileTabs,
171
+ activeWorkspaceFileKey,
172
+ workspaceNavigationHistory: [
173
+ { kind: 'file', key: activeWorkspaceFileKey },
174
+ ],
175
+ workspaceNavigationHistoryIndex: 0,
176
+ });
177
+
178
+ const persisted = window.localStorage.getItem(chatThreadWorkspaceStorageKey);
179
+ resetChatThreadStore();
180
+ if (persisted) {
181
+ window.localStorage.setItem(chatThreadWorkspaceStorageKey, persisted);
182
+ }
183
+ await useChatThreadStore.persist.rehydrate();
184
+
185
+ expect(useChatThreadStore.getState().snapshot).toMatchObject({
186
+ workspacePanelParentKey: 'session-1',
187
+ activeWorkspacePanelKind: 'file',
188
+ activeWorkspaceFileKey,
189
+ });
190
+ expect(useChatThreadStore.getState().snapshot.workspaceFileTabs).toHaveLength(8);
191
+ expect(
192
+ useChatThreadStore.getState().snapshot.workspaceFileTabs.some(
193
+ (tab) => tab.key === activeWorkspaceFileKey,
194
+ ),
195
+ ).toBe(true);
196
+ });
197
+
121
198
  it('hydrates the workspace panel state and repairs stale active file keys', async () => {
122
199
  window.localStorage.setItem(
123
200
  chatThreadWorkspaceStorageKey,
@@ -0,0 +1,37 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+ import {
3
+ DEFAULT_CHAT_MESSAGE_LAYOUT,
4
+ useChatMessageLayoutStore,
5
+ } from "@/features/chat/stores/chat-message-layout.store";
6
+
7
+ const STORAGE_KEY = "nextclaw.chat.message-layout";
8
+
9
+ describe("chat message layout store", () => {
10
+ beforeEach(() => {
11
+ window.localStorage.clear();
12
+ useChatMessageLayoutStore.setState({
13
+ layout: DEFAULT_CHAT_MESSAGE_LAYOUT,
14
+ });
15
+ });
16
+
17
+ it("preserves an existing card layout preference", async () => {
18
+ window.localStorage.setItem(
19
+ STORAGE_KEY,
20
+ JSON.stringify({ state: { layout: "card" }, version: 1 }),
21
+ );
22
+
23
+ await useChatMessageLayoutStore.persist.rehydrate();
24
+ expect(useChatMessageLayoutStore.getState().layout).toBe("card");
25
+ });
26
+
27
+ it("falls back to the flat layout for an invalid persisted layout", async () => {
28
+ window.localStorage.setItem(
29
+ STORAGE_KEY,
30
+ JSON.stringify({ state: { layout: "unknown" }, version: 1 }),
31
+ );
32
+
33
+ await useChatMessageLayoutStore.persist.rehydrate();
34
+
35
+ expect(useChatMessageLayoutStore.getState().layout).toBe("flat");
36
+ });
37
+ });
@@ -0,0 +1,41 @@
1
+ import type { ChatMessageLayout } from "@nextclaw/agent-chat-ui";
2
+ import { create } from "zustand";
3
+ import { createJSONStorage, persist } from "zustand/middleware";
4
+
5
+ const CHAT_MESSAGE_LAYOUT_STORAGE_KEY = "nextclaw.chat.message-layout";
6
+ const CHAT_MESSAGE_LAYOUT_STORAGE_VERSION = 1;
7
+ export const DEFAULT_CHAT_MESSAGE_LAYOUT: ChatMessageLayout = "flat";
8
+
9
+ type ChatMessageLayoutStore = {
10
+ layout: ChatMessageLayout;
11
+ setLayout: (layout: ChatMessageLayout) => void;
12
+ };
13
+
14
+ function resolvePersistedLayout(persistedState: unknown): ChatMessageLayout {
15
+ if (!persistedState || typeof persistedState !== "object") {
16
+ return DEFAULT_CHAT_MESSAGE_LAYOUT;
17
+ }
18
+ const { layout } = persistedState as { layout?: unknown };
19
+ return layout === "flat" || layout === "card"
20
+ ? layout
21
+ : DEFAULT_CHAT_MESSAGE_LAYOUT;
22
+ }
23
+
24
+ export const useChatMessageLayoutStore = create<ChatMessageLayoutStore>()(
25
+ persist(
26
+ (set) => ({
27
+ layout: DEFAULT_CHAT_MESSAGE_LAYOUT,
28
+ setLayout: (layout) => set({ layout }),
29
+ }),
30
+ {
31
+ name: CHAT_MESSAGE_LAYOUT_STORAGE_KEY,
32
+ version: CHAT_MESSAGE_LAYOUT_STORAGE_VERSION,
33
+ storage: createJSONStorage(() => window.localStorage),
34
+ partialize: (state) => ({ layout: state.layout }),
35
+ merge: (persistedState, currentState) => ({
36
+ ...currentState,
37
+ layout: resolvePersistedLayout(persistedState),
38
+ }),
39
+ },
40
+ ),
41
+ );