vzcode 2.0.0 → 2.3.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 (218) hide show
  1. package/dist/assets/{buildWorker-Dsx6rOdK.js → buildWorker-wLkQ0yz1.js} +64 -64
  2. package/dist/assets/{index-BM8tDh6M.css → index-BoFeK4GL.css} +1 -1
  3. package/dist/assets/{index-BgqNq-ww.js → index-DuUjtrt6.js} +107 -107
  4. package/dist/assets/{worker-BeBZGG1n.js → worker-DHxSPM7N.js} +78 -78
  5. package/dist/cli.js +113 -0
  6. package/dist/index.html +2 -2
  7. package/{src/ot.ts → dist/ot.js} +2 -14
  8. package/{src/randomId.ts → dist/randomId.js} +5 -6
  9. package/dist/runCode.js +20 -0
  10. package/dist/server/aiChatHandler/aiEditing.js +89 -0
  11. package/dist/server/aiChatHandler/chatOperations.js +360 -0
  12. package/dist/server/aiChatHandler/errorHandling.js +49 -0
  13. package/dist/server/aiChatHandler/index.js +112 -0
  14. package/dist/server/aiChatHandler/llmStreaming.js +284 -0
  15. package/dist/server/aiChatHandler/validation.js +19 -0
  16. package/dist/server/computeInitialDocument.js +146 -0
  17. package/{src/server/config.ts → dist/server/config.js} +4 -7
  18. package/{src/server/featureFlags.ts → dist/server/featureFlags.js} +0 -3
  19. package/dist/server/generateAIResponse.js +129 -0
  20. package/dist/server/handleAIAssist.js +39 -0
  21. package/dist/server/handleAICopilot.js +81 -0
  22. package/dist/server/index.js +297 -0
  23. package/dist/server/livekit.js +17 -0
  24. package/dist/server/prettier.js +90 -0
  25. package/{src/server/setupEnv.ts → dist/server/setupEnv.js} +1 -2
  26. package/dist/submitOperation.js +14 -0
  27. package/dist/types.js +1 -0
  28. package/dist/utils/fileDiff.js +66 -0
  29. package/package.json +23 -22
  30. package/src/client/AIAssist/AIAssistCodeMirrorKeyMap.ts +0 -42
  31. package/src/client/AIAssist/AIAssistWidget/index.tsx +0 -135
  32. package/src/client/AIAssist/AIAssistWidget/style.scss +0 -47
  33. package/src/client/AIAssist/Spinner.jsx +0 -76
  34. package/src/client/AIAssist/formatFile.ts +0 -27
  35. package/src/client/AIAssist/generateFilesContext.ts +0 -25
  36. package/src/client/AIAssist/index.ts +0 -2
  37. package/src/client/AIAssist/startAIAssist.ts +0 -95
  38. package/src/client/App/index.tsx +0 -153
  39. package/src/client/App/style.scss +0 -82
  40. package/src/client/App/usePending.ts +0 -51
  41. package/src/client/App/useShareDB.ts +0 -161
  42. package/src/client/CodeEditor/Copilot/index.ts +0 -74
  43. package/src/client/CodeEditor/InteractiveWidgets/boolToggler.ts +0 -12
  44. package/src/client/CodeEditor/InteractiveWidgets/colorPicker.ts +0 -68
  45. package/src/client/CodeEditor/InteractiveWidgets/colorsInTextPlugin.ts +0 -174
  46. package/src/client/CodeEditor/InteractiveWidgets/highlightWidgets.ts +0 -79
  47. package/src/client/CodeEditor/InteractiveWidgets/index.ts +0 -44
  48. package/src/client/CodeEditor/InteractiveWidgets/markdownCheckboxToggler.ts +0 -12
  49. package/src/client/CodeEditor/InteractiveWidgets/numberDragger.ts +0 -20
  50. package/src/client/CodeEditor/InteractiveWidgets/rotateWidget.ts +0 -143
  51. package/src/client/CodeEditor/InteractiveWidgets/urlClicker.test.ts +0 -48
  52. package/src/client/CodeEditor/InteractiveWidgets/urlClicker.ts +0 -12
  53. package/src/client/CodeEditor/InteractiveWidgets/vec2Slider.ts +0 -25
  54. package/src/client/CodeEditor/basicSetup.ts +0 -73
  55. package/src/client/CodeEditor/getOrCreateEditor.tsx +0 -615
  56. package/src/client/CodeEditor/index.tsx +0 -202
  57. package/src/client/CodeEditor/json1PresenceBroadcast.ts +0 -41
  58. package/src/client/CodeEditor/json1PresenceDisplay.ts +0 -350
  59. package/src/client/CodeEditor/rainbowBrackets.ts +0 -122
  60. package/src/client/CodeEditor/style.scss +0 -156
  61. package/src/client/CodeEditor/typescriptExtension/worker.ts +0 -32
  62. package/src/client/CodeErrorOverlay/index.tsx +0 -77
  63. package/src/client/CodeErrorOverlay/style.scss +0 -33
  64. package/src/client/Fonts/fonts.ts +0 -8
  65. package/src/client/Icons/AdjustmentSVG.tsx +0 -19
  66. package/src/client/Icons/BugSVG.tsx +0 -20
  67. package/src/client/Icons/CloseSVG.tsx +0 -19
  68. package/src/client/Icons/CssSVG.tsx +0 -16
  69. package/src/client/Icons/DirectoryArrowSVG.tsx +0 -19
  70. package/src/client/Icons/EditSVG.tsx +0 -19
  71. package/src/client/Icons/FileSVG.tsx +0 -19
  72. package/src/client/Icons/FolderSVG.tsx +0 -20
  73. package/src/client/Icons/GearSVG.tsx +0 -16
  74. package/src/client/Icons/HtmlSVG.tsx +0 -16
  75. package/src/client/Icons/JavaScriptSVG.tsx +0 -16
  76. package/src/client/Icons/JsonSVG.tsx +0 -16
  77. package/src/client/Icons/MarkdownSVG.tsx +0 -16
  78. package/src/client/Icons/MicSVG.tsx +0 -25
  79. package/src/client/Icons/NewSVG.tsx +0 -19
  80. package/src/client/Icons/PinSVG.tsx +0 -14
  81. package/src/client/Icons/PlaySVG.tsx +0 -16
  82. package/src/client/Icons/QuestionMarkSVG.tsx +0 -18
  83. package/src/client/Icons/ReactSVG.tsx +0 -16
  84. package/src/client/Icons/SearchSVG.tsx +0 -20
  85. package/src/client/Icons/SparklesSVG.tsx +0 -23
  86. package/src/client/Icons/SplitEditorSVG.tsx +0 -34
  87. package/src/client/Icons/StopSVG.tsx +0 -15
  88. package/src/client/Icons/SvelteSVG.tsx +0 -16
  89. package/src/client/Icons/TrashSVG.tsx +0 -19
  90. package/src/client/Icons/TypeScriptSVG.tsx +0 -16
  91. package/src/client/Icons/index.tsx +0 -24
  92. package/src/client/ImageViewer/index.tsx +0 -91
  93. package/src/client/ImageViewer/style.scss +0 -41
  94. package/src/client/PresenceNotifications/PresenceNotifications.test.ts +0 -134
  95. package/src/client/PresenceNotifications/index.tsx +0 -158
  96. package/src/client/PresenceNotifications/style.scss +0 -17
  97. package/src/client/RunCodeWidget/index.tsx +0 -117
  98. package/src/client/RunCodeWidget/style.scss +0 -24
  99. package/src/client/SplitPaneResizeContext.tsx +0 -159
  100. package/src/client/TabList/Tab.tsx +0 -73
  101. package/src/client/TabList/index.tsx +0 -35
  102. package/src/client/TabList/style.scss +0 -51
  103. package/src/client/VZCodeContext/index.tsx +0 -29
  104. package/src/client/VZCodeContext/types.ts +0 -249
  105. package/src/client/VZCodeContext/useVZCodeState.ts +0 -584
  106. package/src/client/VZKeyboardShortcutsDoc.tsx +0 -148
  107. package/src/client/VZLeft.tsx +0 -28
  108. package/src/client/VZMiddle.tsx +0 -172
  109. package/src/client/VZResizer/index.tsx +0 -128
  110. package/src/client/VZResizer/styles.scss +0 -33
  111. package/src/client/VZRight.tsx +0 -113
  112. package/src/client/VZSettings.tsx +0 -275
  113. package/src/client/VZSidebar/AIChat/ChatInput.tsx +0 -196
  114. package/src/client/VZSidebar/AIChat/DiffView.scss +0 -136
  115. package/src/client/VZSidebar/AIChat/DiffView.tsx +0 -176
  116. package/src/client/VZSidebar/AIChat/Message.tsx +0 -143
  117. package/src/client/VZSidebar/AIChat/MessageList.tsx +0 -205
  118. package/src/client/VZSidebar/AIChat/StreamingMessage.tsx +0 -35
  119. package/src/client/VZSidebar/AIChat/ThinkingScratchpad.tsx +0 -156
  120. package/src/client/VZSidebar/AIChat/TypingIndicator.tsx +0 -19
  121. package/src/client/VZSidebar/AIChat/index.tsx +0 -273
  122. package/src/client/VZSidebar/AIChat/styles.scss +0 -627
  123. package/src/client/VZSidebar/CreateDirModal.tsx +0 -111
  124. package/src/client/VZSidebar/CreateFileModal.tsx +0 -111
  125. package/src/client/VZSidebar/DeleteConfirmationModal.tsx +0 -76
  126. package/src/client/VZSidebar/DirectoryListing.tsx +0 -89
  127. package/src/client/VZSidebar/EmptyState.tsx +0 -11
  128. package/src/client/VZSidebar/FileListing.tsx +0 -91
  129. package/src/client/VZSidebar/FileTypeIcon.tsx +0 -49
  130. package/src/client/VZSidebar/Item.tsx +0 -237
  131. package/src/client/VZSidebar/Listing.tsx +0 -47
  132. package/src/client/VZSidebar/Search.tsx +0 -527
  133. package/src/client/VZSidebar/VisualEditor.tsx +0 -295
  134. package/src/client/VZSidebar/VoiceChatModal.tsx +0 -121
  135. package/src/client/VZSidebar/aiCopyPaste.ts +0 -199
  136. package/src/client/VZSidebar/index.tsx +0 -728
  137. package/src/client/VZSidebar/styles.scss +0 -612
  138. package/src/client/VZSidebar/useDragAndDrop.tsx +0 -408
  139. package/src/client/bootstrap.ts +0 -26
  140. package/src/client/buildWorker.ts +0 -3
  141. package/src/client/featureFlags.ts +0 -8
  142. package/src/client/generateRequestId.ts +0 -6
  143. package/src/client/getFileTree.ts +0 -53
  144. package/src/client/index.ts +0 -19
  145. package/src/client/main.jsx +0 -10
  146. package/src/client/presenceColor.ts +0 -8
  147. package/src/client/shouldTriggerRun.ts +0 -31
  148. package/src/client/sortFileTree.ts +0 -21
  149. package/src/client/tabsSearchParameters.test.ts +0 -79
  150. package/src/client/tabsSearchParameters.ts +0 -137
  151. package/src/client/themes/index.ts +0 -7
  152. package/src/client/themes/themes.ts +0 -77
  153. package/src/client/themes/uiwImports.ts +0 -32
  154. package/src/client/themes/useDynamicTheme.ts +0 -29
  155. package/src/client/themes/vizhubTheme/colors.ts +0 -80
  156. package/src/client/themes/vizhubTheme/index.ts +0 -193
  157. package/src/client/useActions.ts +0 -288
  158. package/src/client/useESLint/index.ts +0 -72
  159. package/src/client/useESLint/worker.ts +0 -113
  160. package/src/client/useEditorCache.ts +0 -35
  161. package/src/client/useFileCRUD.ts +0 -228
  162. package/src/client/useKeyboardShortcuts.ts +0 -451
  163. package/src/client/useOpenDirectories.ts +0 -99
  164. package/src/client/usePresenceAutoFollow.ts +0 -85
  165. package/src/client/usePrettier/index.ts +0 -178
  166. package/src/client/usePrettier/worker.ts +0 -109
  167. package/src/client/useRunCode.tsx +0 -15
  168. package/src/client/useRuntimeError.ts +0 -32
  169. package/src/client/useSubmitOperation.ts +0 -15
  170. package/src/client/useURLSync.ts +0 -137
  171. package/src/client/usernameLocalStorage.ts +0 -43
  172. package/src/client/utils/fileExtension.ts +0 -10
  173. package/src/client/utils/isImageFile.ts +0 -12
  174. package/src/client/vzReducer/aiChatReducer.ts +0 -44
  175. package/src/client/vzReducer/closeTabReducer.test.ts +0 -205
  176. package/src/client/vzReducer/closeTabsReducer.ts +0 -96
  177. package/src/client/vzReducer/createInitialState.ts +0 -38
  178. package/src/client/vzReducer/editorNoLongerWantsFocusReducer.ts +0 -9
  179. package/src/client/vzReducer/findPane.ts +0 -19
  180. package/src/client/vzReducer/index.ts +0 -250
  181. package/src/client/vzReducer/openTabReducer.test.ts +0 -127
  182. package/src/client/vzReducer/openTabReducer.ts +0 -74
  183. package/src/client/vzReducer/searchReducer.test.ts +0 -292
  184. package/src/client/vzReducer/searchReducer.ts +0 -181
  185. package/src/client/vzReducer/setActiveFileIdReducer.ts +0 -28
  186. package/src/client/vzReducer/setActiveFileLeftRightReducer.ts +0 -76
  187. package/src/client/vzReducer/setIsDocOpenReducer.ts +0 -9
  188. package/src/client/vzReducer/setIsSettingsOpenReducer.ts +0 -9
  189. package/src/client/vzReducer/setThemeReducer.ts +0 -9
  190. package/src/client/vzReducer/setUsernameReducer.ts +0 -9
  191. package/src/client/vzReducer/splitCurrentPaneReducer.ts +0 -66
  192. package/src/client/vzReducer/toggleAutoFollowReducer.ts +0 -12
  193. package/src/client/vzReducer/updatePane.ts +0 -40
  194. package/src/client/vzReducer/updatePresenceIndicatorReducer.ts +0 -30
  195. package/src/client/vzReducer/visualEditorReducer.ts +0 -9
  196. package/src/reactRouterExports.ts +0 -15
  197. package/src/runCode.ts +0 -27
  198. package/src/server/aiChatHandler/aiEditing.ts +0 -152
  199. package/src/server/aiChatHandler/chatOperations.ts +0 -510
  200. package/src/server/aiChatHandler/errorHandling.ts +0 -66
  201. package/src/server/aiChatHandler/index.ts +0 -200
  202. package/src/server/aiChatHandler/llmStreaming.ts +0 -419
  203. package/src/server/aiChatHandler/undoHandler.ts +0 -97
  204. package/src/server/aiChatHandler/validation.ts +0 -24
  205. package/src/server/computeInitialDocument.ts +0 -220
  206. package/src/server/generateAIResponse.ts +0 -188
  207. package/src/server/handleAIAssist.ts +0 -53
  208. package/src/server/handleAIChatUndo.ts +0 -2
  209. package/src/server/handleAICopilot.ts +0 -97
  210. package/src/server/index.ts +0 -388
  211. package/src/server/livekit.ts +0 -24
  212. package/src/server/prettier.ts +0 -115
  213. package/src/submitOperation.ts +0 -25
  214. package/src/types.ts +0 -205
  215. package/src/utils/fileDiff.ts +0 -117
  216. package/src/vite-env.d.ts +0 -10
  217. /package/{src/server/handleAIChatMessage.ts → dist/server/handleAIChatMessage.js} +0 -0
  218. /package/{src/server/isDirectory.ts → dist/server/isDirectory.js} +0 -0
@@ -1,176 +0,0 @@
1
- import React, {
2
- useContext,
3
- useEffect,
4
- useMemo,
5
- useRef,
6
- } from 'react';
7
- import {
8
- UnifiedFilesDiff,
9
- parseUnifiedDiffStats,
10
- combineUnifiedDiffs,
11
- } from '../../../utils/fileDiff';
12
- import * as Diff2Html from 'diff2html';
13
- import 'diff2html/bundles/css/diff2html.min.css';
14
- import './DiffView.scss';
15
- import { VZCodeContext } from '../../VZCodeContext';
16
- import { VizFileId, VizFiles } from '@vizhub/viz-types';
17
-
18
- interface DiffViewProps {
19
- diffData: UnifiedFilesDiff;
20
- }
21
-
22
- export const DiffView: React.FC<DiffViewProps> = ({
23
- diffData,
24
- }) => {
25
- const { content, openTab, setIsAIChatOpen } =
26
- useContext(VZCodeContext);
27
- const diffContainerRef = useRef<HTMLDivElement>(null);
28
-
29
- const unifiedDiffs = Object.values(diffData).filter(
30
- (diff) => diff.length > 0,
31
- );
32
-
33
- if (unifiedDiffs.length === 0) {
34
- return null;
35
- }
36
-
37
- // Calculate statistics from all unified diffs
38
- let totalAdditions = 0;
39
- let totalDeletions = 0;
40
-
41
- for (const unifiedDiff of unifiedDiffs) {
42
- const stats = parseUnifiedDiffStats(unifiedDiff);
43
- totalAdditions += stats.additions;
44
- totalDeletions += stats.deletions;
45
- }
46
-
47
- // Combine all unified diffs and convert to HTML using diff2html
48
- const combinedUnifiedDiff = combineUnifiedDiffs(diffData);
49
- const diffHtml = Diff2Html.html(combinedUnifiedDiff, {
50
- drawFileList: false,
51
- matching: 'words',
52
- diffStyle: 'word',
53
- outputFormat: 'line-by-line',
54
- });
55
-
56
- // Create a mapping from file name to file ID for click handling
57
- const fileNameToIdMap = useMemo(() => {
58
- const map = new Map<string, VizFileId>();
59
- Object.entries(diffData).forEach(([fileId, diff]) => {
60
- // Extract file name from the unified diff
61
- // The diff contains lines like "--- a/filename" and "+++ b/filename"
62
- const lines = diff.split('\n');
63
- for (const line of lines) {
64
- if (
65
- line.startsWith('--- a/') ||
66
- line.startsWith('+++ b/')
67
- ) {
68
- const fileName = line.substring(6); // Remove "--- a/" or "+++ b/"
69
- map.set(fileName, fileId as VizFileId);
70
- break;
71
- }
72
- }
73
- });
74
- return map;
75
- }, [diffData]);
76
-
77
- // Add click handlers to file names after HTML is rendered
78
- useEffect(() => {
79
- if (!diffContainerRef.current) return;
80
-
81
- const handleFileNameClick = (event: MouseEvent) => {
82
- const target = event.target as HTMLElement;
83
- if (target.classList.contains('d2h-file-name')) {
84
- event.preventDefault();
85
- event.stopPropagation();
86
-
87
- console.log('File name clicked');
88
-
89
- const fileName = target.textContent?.trim();
90
-
91
- console.log('Clicked file name:', fileName);
92
- if (fileName) {
93
- const files: VizFiles = content?.files;
94
- if (files) {
95
- // export type VizFiles = {
96
- // [fileId: VizFileId]: VizFile;
97
- // };
98
- // export type VizFileId = string;
99
- // export type VizFile = {
100
- // name: string;
101
- // text: string;
102
- // };
103
-
104
- // TODO get fileId from content.files
105
- const fileId = Object.entries(files).find(
106
- ([id, file]) => file.name === fileName,
107
- )?.[0];
108
- console.log('Mapped file ID:', fileId);
109
-
110
- if (fileId) {
111
- // Open the file tab and switch to files view
112
- openTab({ fileId, isTransient: false });
113
- setIsAIChatOpen(false);
114
- }
115
- }
116
- }
117
- }
118
- };
119
-
120
- const container = diffContainerRef.current;
121
- const fileNameElements = container.querySelectorAll(
122
- '.d2h-file-name',
123
- );
124
-
125
- // Add click event listeners and cursor pointer style
126
- fileNameElements.forEach((element) => {
127
- element.addEventListener(
128
- 'click',
129
- handleFileNameClick,
130
- );
131
- (element as HTMLElement).style.cursor = 'pointer';
132
- (element as HTMLElement).style.textDecoration =
133
- 'underline';
134
- (element as HTMLElement).style.color = '#58a6ff'; // GitHub blue link color
135
- });
136
-
137
- return () => {
138
- // Cleanup event listeners
139
- fileNameElements.forEach((element) => {
140
- element.removeEventListener(
141
- 'click',
142
- handleFileNameClick,
143
- );
144
- });
145
- };
146
- }, [diffHtml, content, openTab, setIsAIChatOpen]);
147
-
148
- return (
149
- <div className="diff-view">
150
- <div className="diff-summary">
151
- <div className="diff-stats">
152
- <span className="files-changed">
153
- {unifiedDiffs.length} file
154
- {unifiedDiffs.length !== 1 ? 's' : ''} changed
155
- </span>
156
- {totalAdditions > 0 && (
157
- <span className="additions">
158
- +{totalAdditions}
159
- </span>
160
- )}
161
- {totalDeletions > 0 && (
162
- <span className="deletions">
163
- -{totalDeletions}
164
- </span>
165
- )}
166
- </div>
167
- </div>
168
-
169
- <div
170
- className="diff-files"
171
- ref={diffContainerRef}
172
- dangerouslySetInnerHTML={{ __html: diffHtml }}
173
- />
174
- </div>
175
- );
176
- };
@@ -1,143 +0,0 @@
1
- import { timestampToDate } from '@vizhub/viz-utils';
2
- import Markdown from 'react-markdown';
3
- import remarkGfm from 'remark-gfm';
4
- import React, {
5
- useMemo,
6
- memo,
7
- useState,
8
- useContext,
9
- } from 'react';
10
- import { DiffView } from './DiffView';
11
- import { UnifiedFilesDiff } from '../../../utils/fileDiff';
12
- import { enableDiffView } from '../../featureFlags';
13
- import { VZCodeContext } from '../../VZCodeContext';
14
-
15
- interface MessageProps {
16
- id: string;
17
- role: 'user' | 'assistant';
18
- content: string;
19
- timestamp: number;
20
- isStreaming?: boolean;
21
- diffData?: UnifiedFilesDiff;
22
- beforeFiles?: any;
23
- chatId?: string;
24
- canUndo?: boolean;
25
- }
26
-
27
- const MessageComponent = ({
28
- id,
29
- role,
30
- content,
31
- timestamp,
32
- isStreaming,
33
- diffData,
34
- beforeFiles,
35
- chatId,
36
- canUndo,
37
- }: MessageProps) => {
38
- const [isUndoing, setIsUndoing] = useState(false);
39
- const {
40
- aiChatUndoEndpoint,
41
- aiChatOptions = {},
42
- additionalWidgets,
43
- handleSendMessage,
44
- } = useContext(VZCodeContext);
45
-
46
- // Memoize date formatting to avoid repeated computation
47
- const formattedTime = useMemo(() => {
48
- return timestampToDate(timestamp).toLocaleTimeString(
49
- [],
50
- {
51
- hour: '2-digit',
52
- minute: '2-digit',
53
- },
54
- );
55
- }, [timestamp]);
56
-
57
- // Memoize the className string to avoid recreation
58
- const messageClassName = useMemo(() => {
59
- return `ai-chat-message ${role}${isStreaming ? ' streaming' : ''}`;
60
- }, [role, isStreaming]);
61
-
62
- const handleUndo = async () => {
63
- if (
64
- !id ||
65
- !chatId ||
66
- !beforeFiles ||
67
- isUndoing ||
68
- !aiChatUndoEndpoint
69
- ) {
70
- return;
71
- }
72
-
73
- setIsUndoing(true);
74
- try {
75
- const response = await fetch(aiChatUndoEndpoint, {
76
- method: 'POST',
77
- headers: {
78
- 'Content-Type': 'application/json',
79
- },
80
- body: JSON.stringify({
81
- vizId: aiChatOptions.vizId,
82
- chatId,
83
- messageId: id,
84
- }),
85
- });
86
-
87
- if (!response.ok) {
88
- throw new Error(
89
- `HTTP error! status: ${response.status}`,
90
- );
91
- }
92
-
93
- // The server will handle the ShareDB operations to undo the changes
94
- // The UI will update automatically via ShareDB
95
- } catch (error) {
96
- console.error('Error undoing AI edit:', error);
97
- // TODO: Show user-friendly error message
98
- } finally {
99
- setIsUndoing(false);
100
- }
101
- };
102
-
103
- return (
104
- <div className={messageClassName}>
105
- <div className="ai-chat-message-content">
106
- <Markdown remarkPlugins={[remarkGfm]}>
107
- {content}
108
- </Markdown>
109
- {enableDiffView &&
110
- diffData &&
111
- Object.keys(diffData).length > 0 && (
112
- <DiffView diffData={diffData} />
113
- )}
114
- {additionalWidgets &&
115
- canUndo &&
116
- chatId &&
117
- React.createElement(additionalWidgets, {
118
- messageId: id,
119
- chatId: chatId,
120
- canUndo: canUndo,
121
- handleSendMessage,
122
- })}
123
- {!additionalWidgets && canUndo && beforeFiles && (
124
- <div className="undo-button-container">
125
- <button
126
- className="undo-button"
127
- onClick={handleUndo}
128
- disabled={isUndoing}
129
- title="Undo this AI edit"
130
- >
131
- {isUndoing ? 'Undoing...' : 'Undo'}
132
- </button>
133
- </div>
134
- )}
135
- </div>
136
- <div className="ai-chat-message-time">
137
- {formattedTime}
138
- </div>
139
- </div>
140
- );
141
- };
142
-
143
- export const Message = memo(MessageComponent);
@@ -1,205 +0,0 @@
1
- import {
2
- useRef,
3
- useEffect,
4
- useCallback,
5
- memo,
6
- useState,
7
- } from 'react';
8
- import { Message } from './Message';
9
- import { TypingIndicator } from './TypingIndicator';
10
- import { ThinkingScratchpad } from './ThinkingScratchpad';
11
- import { VizChatMessage } from '@vizhub/viz-types';
12
-
13
- const MessageListComponent = ({
14
- messages,
15
- isLoading,
16
- chatId, // Add chatId prop
17
- aiScratchpad, // Add aiScratchpad prop
18
- aiStatus, // Add aiStatus prop
19
- }: {
20
- messages: VizChatMessage[];
21
- isLoading: boolean;
22
- chatId?: string; // Add chatId to the type
23
- aiScratchpad?: string; // Add aiScratchpad to the type
24
- aiStatus?: string; // Add aiStatus to the type
25
- }) => {
26
- const messagesEndRef = useRef<HTMLDivElement>(null);
27
- const messagesContainerRef = useRef<HTMLDivElement>(null);
28
- const [isUserScrolled, setIsUserScrolled] =
29
- useState(false);
30
- const [autoScrollEnabled, setAutoScrollEnabled] =
31
- useState(true);
32
- const scrollTimeoutRef =
33
- useRef<ReturnType<typeof setTimeout>>();
34
-
35
- // Check if the user is scrolled to the bottom
36
- const isScrolledToBottom = useCallback(() => {
37
- const container = messagesContainerRef.current;
38
- if (!container) return true;
39
-
40
- const threshold = 50; // Allow 50px tolerance for "at bottom"
41
- const { scrollTop, scrollHeight, clientHeight } =
42
- container;
43
- return (
44
- scrollHeight - scrollTop - clientHeight < threshold
45
- );
46
- }, []);
47
-
48
- // Smooth scroll to bottom with linear transition
49
- const scrollToBottom = useCallback(() => {
50
- if (!autoScrollEnabled) return;
51
-
52
- messagesEndRef.current?.scrollIntoView({
53
- behavior: 'smooth',
54
- block: 'end',
55
- });
56
- }, [autoScrollEnabled]);
57
-
58
- // Handle scroll events to detect user manual scrolling
59
- const handleScroll = useCallback(() => {
60
- const container = messagesContainerRef.current;
61
- if (!container) return;
62
-
63
- const isAtBottom = isScrolledToBottom();
64
-
65
- // Clear any existing timeout
66
- if (scrollTimeoutRef.current) {
67
- clearTimeout(scrollTimeoutRef.current);
68
- }
69
-
70
- // If user scrolled up from bottom, disable auto-scroll
71
- if (!isAtBottom && !isUserScrolled) {
72
- setIsUserScrolled(true);
73
- setAutoScrollEnabled(false);
74
- }
75
-
76
- // If user scrolled back to bottom, re-enable auto-scroll after a brief delay
77
- if (isAtBottom && isUserScrolled) {
78
- scrollTimeoutRef.current = setTimeout(() => {
79
- setIsUserScrolled(false);
80
- setAutoScrollEnabled(true);
81
- }, 500); // 500ms delay to prevent flickering
82
- }
83
- }, [isUserScrolled, isScrolledToBottom]);
84
-
85
- // Auto-scroll when messages change, but only if auto-scroll is enabled
86
- useEffect(() => {
87
- if (autoScrollEnabled && !isUserScrolled) {
88
- // Use a short debounce to prevent multiple scroll calls during rapid updates
89
- if (scrollTimeoutRef.current) {
90
- clearTimeout(scrollTimeoutRef.current);
91
- }
92
-
93
- scrollTimeoutRef.current = setTimeout(() => {
94
- scrollToBottom();
95
- }, 100); // 100ms debounce
96
- }
97
-
98
- return () => {
99
- if (scrollTimeoutRef.current) {
100
- clearTimeout(scrollTimeoutRef.current);
101
- }
102
- };
103
- }, [
104
- messages,
105
- autoScrollEnabled,
106
- isUserScrolled,
107
- scrollToBottom,
108
- ]);
109
-
110
- // Track previous loading state to detect when AI generation completes
111
- const [prevIsLoading, setPrevIsLoading] =
112
- useState(isLoading);
113
-
114
- // Scroll to bottom when AI generation completes (loading changes from true to false)
115
- useEffect(() => {
116
- // If AI was generating and now it's finished, scroll to bottom
117
- if (prevIsLoading && !isLoading) {
118
- // Force scroll to bottom regardless of user scroll state
119
- // This ensures we always scroll to bottom when generation completes
120
- messagesEndRef.current?.scrollIntoView({
121
- behavior: 'smooth',
122
- block: 'end',
123
- });
124
-
125
- // Re-enable auto-scroll for future messages
126
- setIsUserScrolled(false);
127
- setAutoScrollEnabled(true);
128
- }
129
-
130
- setPrevIsLoading(isLoading);
131
- }, [isLoading, prevIsLoading]);
132
-
133
- // Clean up timeout on unmount
134
- useEffect(() => {
135
- return () => {
136
- if (scrollTimeoutRef.current) {
137
- clearTimeout(scrollTimeoutRef.current);
138
- }
139
- };
140
- }, []);
141
-
142
- // Check if AI generation has started (last message is from assistant)
143
- const lastMessage = messages[messages.length - 1];
144
- const aiGenerationStarted =
145
- lastMessage?.role === 'assistant' &&
146
- lastMessage.content !== '';
147
-
148
- // Show typing indicator only when loading and AI generation hasn't started yet
149
- const showTypingIndicator =
150
- isLoading && !aiGenerationStarted;
151
-
152
- // Show thinking scratchpad when AI is thinking (has scratchpad content)
153
- const showThinkingScratchpad = Boolean(
154
- aiScratchpad && aiScratchpad.trim(),
155
- );
156
-
157
- return (
158
- <div
159
- className="ai-chat-messages"
160
- ref={messagesContainerRef}
161
- onScroll={handleScroll}
162
- >
163
- {messages.map((msg, index) => {
164
- // Only the most recent assistant message with diffData can be undone
165
- const isLastAssistantMessage =
166
- msg.role === 'assistant' &&
167
- index === messages.length - 1 &&
168
- !isLoading; // Can't undo while AI is still generating
169
-
170
- const canUndo =
171
- isLastAssistantMessage &&
172
- (msg as any).diffData &&
173
- (msg as any).beforeFiles &&
174
- Object.keys((msg as any).diffData || {}).length >
175
- 0;
176
-
177
- return (
178
- <Message
179
- key={msg.id}
180
- id={msg.id}
181
- role={msg.role}
182
- content={msg.content}
183
- timestamp={msg.timestamp}
184
- diffData={(msg as any).diffData}
185
- beforeFiles={(msg as any).beforeFiles}
186
- chatId={chatId}
187
- canUndo={canUndo}
188
- />
189
- );
190
- })}
191
-
192
- {showThinkingScratchpad && (
193
- <ThinkingScratchpad
194
- content={aiScratchpad || ''}
195
- isVisible={showThinkingScratchpad}
196
- />
197
- )}
198
-
199
- {showTypingIndicator && <TypingIndicator />}
200
- <div ref={messagesEndRef} />
201
- </div>
202
- );
203
- };
204
-
205
- export const MessageList = memo(MessageListComponent);
@@ -1,35 +0,0 @@
1
- import Markdown from 'react-markdown';
2
- import remarkGfm from 'remark-gfm';
3
- import { memo } from 'react';
4
-
5
- interface StreamingMessageProps {
6
- content: string;
7
- status?: string;
8
- }
9
-
10
- const StreamingMessageComponent = ({
11
- content,
12
- status,
13
- }: StreamingMessageProps) => {
14
- // Don't render if there's no content and no status
15
- if (!content.trim()) {
16
- return null;
17
- }
18
-
19
- return (
20
- <div className="ai-chat-message assistant streaming">
21
- {status && (
22
- <div className="ai-chat-status">{status}</div>
23
- )}
24
- <div className="ai-chat-message-content">
25
- <Markdown remarkPlugins={[remarkGfm]}>
26
- {content}
27
- </Markdown>
28
- </div>
29
- </div>
30
- );
31
- };
32
-
33
- export const StreamingMessage = memo(
34
- StreamingMessageComponent,
35
- );
@@ -1,156 +0,0 @@
1
- import {
2
- memo,
3
- useRef,
4
- useEffect,
5
- useCallback,
6
- useState,
7
- } from 'react';
8
- import Markdown from 'react-markdown';
9
- import remarkGfm from 'remark-gfm';
10
-
11
- interface ThinkingScratchpadProps {
12
- content: string;
13
- isVisible: boolean;
14
- }
15
-
16
- const ThinkingScratchpadComponent = ({
17
- content,
18
- isVisible,
19
- }: ThinkingScratchpadProps) => {
20
- const contentRef = useRef<HTMLDivElement>(null);
21
- const [isUserScrolled, setIsUserScrolled] =
22
- useState(false);
23
- const [autoScrollEnabled, setAutoScrollEnabled] =
24
- useState(true);
25
- const scrollTimeoutRef =
26
- useRef<ReturnType<typeof setTimeout>>();
27
-
28
- // Check if the user is scrolled to the bottom
29
- const isScrolledToBottom = useCallback(() => {
30
- const container = contentRef.current;
31
- if (!container) return true;
32
-
33
- const threshold = 10; // Allow 10px tolerance for "at bottom"
34
- const { scrollTop, scrollHeight, clientHeight } =
35
- container;
36
- return (
37
- scrollHeight - scrollTop - clientHeight < threshold
38
- );
39
- }, []);
40
-
41
- // Smooth scroll to bottom
42
- const scrollToBottom = useCallback(() => {
43
- if (!autoScrollEnabled) return;
44
-
45
- const container = contentRef.current;
46
- if (container) {
47
- container.scrollTo({
48
- top: container.scrollHeight,
49
- behavior: 'smooth',
50
- });
51
- }
52
- }, [autoScrollEnabled]);
53
-
54
- // Handle scroll events to detect user manual scrolling
55
- const handleScroll = useCallback(() => {
56
- const container = contentRef.current;
57
- if (!container) return;
58
-
59
- const isAtBottom = isScrolledToBottom();
60
-
61
- // Clear any existing timeout
62
- if (scrollTimeoutRef.current) {
63
- clearTimeout(scrollTimeoutRef.current);
64
- }
65
-
66
- // If user scrolled up from bottom, disable auto-scroll
67
- if (!isAtBottom && !isUserScrolled) {
68
- setIsUserScrolled(true);
69
- setAutoScrollEnabled(false);
70
- }
71
-
72
- // If user scrolled back to bottom, re-enable auto-scroll after a brief delay
73
- if (isAtBottom && isUserScrolled) {
74
- scrollTimeoutRef.current = setTimeout(() => {
75
- setIsUserScrolled(false);
76
- setAutoScrollEnabled(true);
77
- }, 300); // 300ms delay to prevent flickering
78
- }
79
- }, [isUserScrolled, isScrolledToBottom]);
80
-
81
- // Auto-scroll when content changes, but only if auto-scroll is enabled
82
- useEffect(() => {
83
- if (
84
- autoScrollEnabled &&
85
- !isUserScrolled &&
86
- isVisible &&
87
- content
88
- ) {
89
- // Use a short debounce to prevent multiple scroll calls during rapid updates
90
- if (scrollTimeoutRef.current) {
91
- clearTimeout(scrollTimeoutRef.current);
92
- }
93
-
94
- scrollTimeoutRef.current = setTimeout(() => {
95
- scrollToBottom();
96
- }, 50); // 50ms debounce
97
- }
98
-
99
- return () => {
100
- if (scrollTimeoutRef.current) {
101
- clearTimeout(scrollTimeoutRef.current);
102
- }
103
- };
104
- }, [
105
- content,
106
- autoScrollEnabled,
107
- isUserScrolled,
108
- isVisible,
109
- scrollToBottom,
110
- ]);
111
-
112
- // Clean up timeout on unmount
113
- useEffect(() => {
114
- return () => {
115
- if (scrollTimeoutRef.current) {
116
- clearTimeout(scrollTimeoutRef.current);
117
- }
118
- };
119
- }, []);
120
-
121
- // Reset scroll state when component becomes visible
122
- useEffect(() => {
123
- if (isVisible) {
124
- setIsUserScrolled(false);
125
- setAutoScrollEnabled(true);
126
- }
127
- }, [isVisible]);
128
-
129
- if (!isVisible || !content) {
130
- return null;
131
- }
132
-
133
- return (
134
- <div className="thinking-scratchpad">
135
- <div className="thinking-scratchpad-header">
136
- <span className="thinking-scratchpad-icon">🧠</span>
137
- <span className="thinking-scratchpad-title">
138
- AI is thinking...
139
- </span>
140
- </div>
141
- <div
142
- className="thinking-scratchpad-content"
143
- ref={contentRef}
144
- onScroll={handleScroll}
145
- >
146
- <Markdown remarkPlugins={[remarkGfm]}>
147
- {content}
148
- </Markdown>
149
- </div>
150
- </div>
151
- );
152
- };
153
-
154
- export const ThinkingScratchpad = memo(
155
- ThinkingScratchpadComponent,
156
- );