vzcode 1.32.0 → 1.33.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.
- package/README.md +0 -1
- package/dist/assets/index-DPIrco_g.js +235 -0
- package/dist/assets/index-DnunmWjy.css +1 -0
- package/dist/assets/worker-BrwN8AXx.js +330 -0
- package/dist/assets/worker-CkHcCP1n.js +136 -0
- package/dist/assets/worker-DkYJN5WQ.js +453 -0
- package/dist/index.html +2 -2
- package/package.json +37 -37
- package/src/client/CodeEditor/getOrCreateEditor.ts +18 -5
- package/src/client/Icons/MicSVG.tsx +1 -1
- package/src/client/VZCodeContext.tsx +18 -2
- package/src/client/VZSidebar/AIChat.tsx +142 -0
- package/src/client/VZSidebar/index.tsx +53 -8
- package/src/client/VZSidebar/styles.scss +178 -1
- package/src/client/featureFlags.ts +2 -0
- package/src/client/useActions.ts +20 -0
- package/src/client/useEditorCache.ts +1 -0
- package/src/client/useFileCRUD.ts +47 -0
- package/src/client/useOpenDirectories.ts +43 -12
- package/src/client/utils/fileExtension.ts +10 -0
- package/src/client/vzReducer/aiChatReducer.ts +31 -0
- package/src/client/vzReducer/createInitialState.ts +2 -0
- package/src/client/vzReducer/index.ts +20 -0
- package/dist/assets/index-DTtcN2MP.css +0 -1
- package/dist/assets/index-sreAszZh.js +0 -240
- package/dist/assets/worker-BKfYWklR.js +0 -136
- package/dist/assets/worker-COyDRdqW.js +0 -453
- package/dist/assets/worker-CWsWXMyk.js +0 -335
|
@@ -66,7 +66,8 @@
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
.sidebar-files,
|
|
69
|
-
.sidebar-search
|
|
69
|
+
.sidebar-search,
|
|
70
|
+
.sidebar-ai-chat {
|
|
70
71
|
width: 100%;
|
|
71
72
|
}
|
|
72
73
|
|
|
@@ -76,6 +77,182 @@
|
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
|
|
80
|
+
.sidebar-ai-chat {
|
|
81
|
+
height: 100%;
|
|
82
|
+
display: flex;
|
|
83
|
+
flex-direction: column;
|
|
84
|
+
|
|
85
|
+
.ai-chat-container {
|
|
86
|
+
height: 100%;
|
|
87
|
+
display: flex;
|
|
88
|
+
flex-direction: column;
|
|
89
|
+
padding: 10px;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.ai-chat-messages {
|
|
93
|
+
flex: 1;
|
|
94
|
+
overflow-y: auto;
|
|
95
|
+
margin-bottom: 10px;
|
|
96
|
+
padding-right: 5px;
|
|
97
|
+
|
|
98
|
+
&::-webkit-scrollbar {
|
|
99
|
+
width: 6px;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
&::-webkit-scrollbar-track {
|
|
103
|
+
background: var(--vh-color-neutral-02);
|
|
104
|
+
border-radius: 3px;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
&::-webkit-scrollbar-thumb {
|
|
108
|
+
background: var(--vh-color-neutral-04);
|
|
109
|
+
border-radius: 3px;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.ai-chat-message {
|
|
114
|
+
margin-bottom: 15px;
|
|
115
|
+
|
|
116
|
+
&.user {
|
|
117
|
+
.ai-chat-message-content {
|
|
118
|
+
background: var(--vh-color-primary-01);
|
|
119
|
+
color: white;
|
|
120
|
+
margin-left: 20px;
|
|
121
|
+
border-radius: 12px 12px 4px 12px;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.ai-chat-message-time {
|
|
125
|
+
text-align: right;
|
|
126
|
+
margin-right: 5px;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
&.assistant {
|
|
131
|
+
.ai-chat-message-content {
|
|
132
|
+
background: var(--vh-color-neutral-02);
|
|
133
|
+
color: var(--vh-color-neutral-04);
|
|
134
|
+
margin-right: 20px;
|
|
135
|
+
border-radius: 12px 12px 12px 4px;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.ai-chat-message-time {
|
|
139
|
+
text-align: left;
|
|
140
|
+
margin-left: 5px;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.ai-chat-message-content {
|
|
146
|
+
padding: 10px 12px;
|
|
147
|
+
font-size: 14px;
|
|
148
|
+
line-height: 1.4;
|
|
149
|
+
word-wrap: break-word;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.ai-chat-message-time {
|
|
153
|
+
font-size: 11px;
|
|
154
|
+
color: var(--vh-color-neutral-03);
|
|
155
|
+
margin-top: 4px;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.ai-chat-typing {
|
|
159
|
+
display: flex;
|
|
160
|
+
gap: 4px;
|
|
161
|
+
align-items: center;
|
|
162
|
+
|
|
163
|
+
span {
|
|
164
|
+
width: 6px;
|
|
165
|
+
height: 6px;
|
|
166
|
+
background: var(--vh-color-neutral-03);
|
|
167
|
+
border-radius: 50%;
|
|
168
|
+
animation: typing 1.4s infinite ease-in-out;
|
|
169
|
+
|
|
170
|
+
&:nth-child(1) {
|
|
171
|
+
animation-delay: -0.32s;
|
|
172
|
+
}
|
|
173
|
+
&:nth-child(2) {
|
|
174
|
+
animation-delay: -0.16s;
|
|
175
|
+
}
|
|
176
|
+
&:nth-child(3) {
|
|
177
|
+
animation-delay: 0s;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.ai-chat-input-container {
|
|
183
|
+
border-top: 1px solid var(--vh-color-neutral-02);
|
|
184
|
+
padding-top: 10px;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.ai-chat-input-group {
|
|
188
|
+
display: flex;
|
|
189
|
+
gap: 8px;
|
|
190
|
+
margin-bottom: 0;
|
|
191
|
+
|
|
192
|
+
textarea {
|
|
193
|
+
flex: 1;
|
|
194
|
+
background: var(--vh-color-neutral-02);
|
|
195
|
+
border: 1px solid var(--vh-color-neutral-03);
|
|
196
|
+
color: var(--vh-color-neutral-04);
|
|
197
|
+
border-radius: 8px;
|
|
198
|
+
padding: 8px 10px;
|
|
199
|
+
font-size: 14px;
|
|
200
|
+
font-family: var(--vzcode-font-family);
|
|
201
|
+
resize: none;
|
|
202
|
+
min-height: 36px;
|
|
203
|
+
|
|
204
|
+
&:focus {
|
|
205
|
+
outline: none;
|
|
206
|
+
border-color: var(--vh-color-primary-01);
|
|
207
|
+
box-shadow: 0 0 0 2px rgba(38, 67, 153, 0.2);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
&::placeholder {
|
|
211
|
+
color: var(--vh-color-neutral-03);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
&:disabled {
|
|
215
|
+
opacity: 0.6;
|
|
216
|
+
cursor: not-allowed;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
.ai-chat-send-button {
|
|
221
|
+
background: var(--vh-color-primary-01);
|
|
222
|
+
border: none;
|
|
223
|
+
color: white;
|
|
224
|
+
border-radius: 8px;
|
|
225
|
+
padding: 8px 16px;
|
|
226
|
+
font-size: 14px;
|
|
227
|
+
font-weight: 500;
|
|
228
|
+
cursor: pointer;
|
|
229
|
+
transition: background-color 0.2s ease;
|
|
230
|
+
|
|
231
|
+
&:hover:not(:disabled) {
|
|
232
|
+
background: var(--vh-color-primary-02);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
&:disabled {
|
|
236
|
+
background: var(--vh-color-neutral-03);
|
|
237
|
+
cursor: not-allowed;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
@keyframes typing {
|
|
244
|
+
0%,
|
|
245
|
+
80%,
|
|
246
|
+
100% {
|
|
247
|
+
transform: scale(0.8);
|
|
248
|
+
opacity: 0.5;
|
|
249
|
+
}
|
|
250
|
+
40% {
|
|
251
|
+
transform: scale(1);
|
|
252
|
+
opacity: 1;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
79
256
|
.sidebar-search .arrow-wrapper {
|
|
80
257
|
cursor: pointer;
|
|
81
258
|
}
|
package/src/client/useActions.ts
CHANGED
|
@@ -150,6 +150,24 @@ export const useActions = (
|
|
|
150
150
|
});
|
|
151
151
|
}, [dispatch]);
|
|
152
152
|
|
|
153
|
+
// True to show the AI chat instead of files
|
|
154
|
+
const setIsAIChatOpen = useCallback(
|
|
155
|
+
(value: boolean) => {
|
|
156
|
+
dispatch({
|
|
157
|
+
type: 'set_is_ai_chat_open',
|
|
158
|
+
value: value,
|
|
159
|
+
});
|
|
160
|
+
},
|
|
161
|
+
[dispatch],
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
// Toggle the focused variable, which should focus the AI chat input
|
|
165
|
+
const toggleAIChatFocused = useCallback(() => {
|
|
166
|
+
dispatch({
|
|
167
|
+
type: 'toggle_ai_chat_focused',
|
|
168
|
+
});
|
|
169
|
+
}, [dispatch]);
|
|
170
|
+
|
|
153
171
|
// True to show the settings modal.
|
|
154
172
|
const setIsSettingsOpen = useCallback(
|
|
155
173
|
(value: boolean) => {
|
|
@@ -231,6 +249,8 @@ export const useActions = (
|
|
|
231
249
|
setSearchLineVisibility,
|
|
232
250
|
setSearchFocusedIndex,
|
|
233
251
|
toggleSearchFocused,
|
|
252
|
+
setIsAIChatOpen,
|
|
253
|
+
toggleAIChatFocused,
|
|
234
254
|
setIsSettingsOpen,
|
|
235
255
|
setIsDocOpen,
|
|
236
256
|
closeSettings,
|
|
@@ -2,6 +2,10 @@ import { useCallback } from 'react';
|
|
|
2
2
|
import { FileTreePath } from '../types';
|
|
3
3
|
import { VizFileId, VizContent } from '@vizhub/viz-types';
|
|
4
4
|
import { randomId } from '../randomId';
|
|
5
|
+
import { EditorCache } from './useEditorCache';
|
|
6
|
+
import { getFileExtension } from './utils/fileExtension';
|
|
7
|
+
import { getLanguageExtension } from './CodeEditor/getOrCreateEditor';
|
|
8
|
+
import { editorCacheKey } from './useEditorCache';
|
|
5
9
|
|
|
6
10
|
// CRUD operations for files and directories
|
|
7
11
|
// CRUD = Create, Read, Update, Delete
|
|
@@ -9,6 +13,8 @@ export const useFileCRUD = ({
|
|
|
9
13
|
submitOperation,
|
|
10
14
|
closeTabs,
|
|
11
15
|
openTab,
|
|
16
|
+
editorCache,
|
|
17
|
+
content,
|
|
12
18
|
}: {
|
|
13
19
|
submitOperation: (
|
|
14
20
|
operation: (document: VizContent) => VizContent,
|
|
@@ -21,6 +27,8 @@ export const useFileCRUD = ({
|
|
|
21
27
|
fileId: VizFileId;
|
|
22
28
|
isTransient: boolean;
|
|
23
29
|
}) => void;
|
|
30
|
+
editorCache: EditorCache;
|
|
31
|
+
content: VizContent;
|
|
24
32
|
}) => {
|
|
25
33
|
// Create a new file
|
|
26
34
|
const createFile = useCallback(
|
|
@@ -78,6 +86,45 @@ export const useFileCRUD = ({
|
|
|
78
86
|
},
|
|
79
87
|
},
|
|
80
88
|
}));
|
|
89
|
+
|
|
90
|
+
const oldName = content.files[fileId].name;
|
|
91
|
+
const oldExtension = getFileExtension(oldName);
|
|
92
|
+
|
|
93
|
+
const newExtension = getFileExtension(newName);
|
|
94
|
+
|
|
95
|
+
const didExtensionChange =
|
|
96
|
+
newExtension !== oldExtension;
|
|
97
|
+
if (didExtensionChange) {
|
|
98
|
+
// Update the language compartment of the corresponding CodeMirror editor
|
|
99
|
+
// with the new language, based on the new extension, only if it changed.
|
|
100
|
+
// Search through all cached editors for this file ID
|
|
101
|
+
for (const [
|
|
102
|
+
cacheKey,
|
|
103
|
+
cachedEditor,
|
|
104
|
+
] of editorCache.entries()) {
|
|
105
|
+
// Check if this cache entry is for the current file
|
|
106
|
+
if (cacheKey.startsWith(fileId + '|')) {
|
|
107
|
+
if (
|
|
108
|
+
cachedEditor &&
|
|
109
|
+
cachedEditor.languageCompartment
|
|
110
|
+
) {
|
|
111
|
+
const newLanguageExtension =
|
|
112
|
+
getLanguageExtension(newExtension);
|
|
113
|
+
|
|
114
|
+
// Reconfigure the language compartment with the new language extension
|
|
115
|
+
cachedEditor.editor.dispatch({
|
|
116
|
+
effects:
|
|
117
|
+
cachedEditor.languageCompartment.reconfigure(
|
|
118
|
+
newLanguageExtension
|
|
119
|
+
? [newLanguageExtension]
|
|
120
|
+
: [],
|
|
121
|
+
),
|
|
122
|
+
});
|
|
123
|
+
// Continue to update all instances of this file in different panes
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
81
128
|
},
|
|
82
129
|
[submitOperation],
|
|
83
130
|
);
|
|
@@ -1,26 +1,36 @@
|
|
|
1
|
-
import { useState, useCallback } from 'react';
|
|
1
|
+
import { useState, useCallback, useEffect } from 'react';
|
|
2
|
+
import type { Pane } from '../types';
|
|
3
|
+
import { VizContent } from '@vizhub/viz-types';
|
|
2
4
|
|
|
3
5
|
// TODO bring this feature back
|
|
4
6
|
// When a page is opened with an active file,
|
|
5
7
|
// make sure all the directories leading to that file
|
|
6
8
|
// are opened automatically.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
export const initialOpenDirectories = (
|
|
10
|
+
activeFile: string | null,
|
|
11
|
+
): Set<VZPath> => {
|
|
12
|
+
const openDirectories = new Set<VZPath>();
|
|
13
|
+
if (activeFile) {
|
|
14
|
+
const path = activeFile.split('/');
|
|
15
|
+
for (let i = 1; i < path.length; i++) {
|
|
16
|
+
openDirectories.add(path.slice(0, i).join('/'));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return openDirectories;
|
|
20
|
+
};
|
|
17
21
|
|
|
18
22
|
type VZPath = string;
|
|
19
23
|
|
|
20
24
|
// Inspired by
|
|
21
25
|
// https://github.com/vizhub-core/vizhub/blob/main/vizhub-v2/packages/neoFrontend/src/pages/VizPage/Body/Editor/FilesSection/useOpenDirectories.js
|
|
22
26
|
// TODO move this into reducer
|
|
23
|
-
export const useOpenDirectories = (
|
|
27
|
+
export const useOpenDirectories = ({
|
|
28
|
+
activePane,
|
|
29
|
+
content,
|
|
30
|
+
}: {
|
|
31
|
+
activePane: Pane;
|
|
32
|
+
content: VizContent;
|
|
33
|
+
}): {
|
|
24
34
|
isDirectoryOpen: (path: VZPath) => boolean;
|
|
25
35
|
toggleDirectory: (path: VZPath) => void;
|
|
26
36
|
} => {
|
|
@@ -29,6 +39,27 @@ export const useOpenDirectories = (): {
|
|
|
29
39
|
Set<VZPath>
|
|
30
40
|
>(new Set());
|
|
31
41
|
|
|
42
|
+
// (client-side only) initialize the open directories
|
|
43
|
+
// based on the open files from the URL params.
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (
|
|
46
|
+
activePane.type === 'leafPane' &&
|
|
47
|
+
activePane?.activeFileId &&
|
|
48
|
+
content.files[activePane.activeFileId]
|
|
49
|
+
) {
|
|
50
|
+
const activeFileId = activePane.activeFileId;
|
|
51
|
+
const fileName = content.files[activeFileId].name;
|
|
52
|
+
const dirsToOpen = initialOpenDirectories(fileName);
|
|
53
|
+
setOpenDirectories((prev) => {
|
|
54
|
+
const updated = new Set(prev);
|
|
55
|
+
for (const dir of dirsToOpen) {
|
|
56
|
+
updated.add(dir);
|
|
57
|
+
}
|
|
58
|
+
return updated;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}, [activePane]);
|
|
62
|
+
|
|
32
63
|
// Whether a directory is open.
|
|
33
64
|
const isDirectoryOpen: (path: VZPath) => boolean =
|
|
34
65
|
useCallback(
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility function to extract file extension from a file name.
|
|
3
|
+
* @param fileName - The name of the file (e.g., "index.html", "script.js")
|
|
4
|
+
* @returns The file extension without the dot (e.g., "html", "js") or undefined if no extension
|
|
5
|
+
*/
|
|
6
|
+
export const getFileExtension = (
|
|
7
|
+
fileName: string,
|
|
8
|
+
): string | undefined => {
|
|
9
|
+
return fileName.split('.').pop();
|
|
10
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { VZState, VZAction } from '.';
|
|
2
|
+
|
|
3
|
+
export const setIsAIChatOpenReducer = (
|
|
4
|
+
state: VZState,
|
|
5
|
+
action: VZAction,
|
|
6
|
+
): VZState => {
|
|
7
|
+
if (action.type === 'set_is_ai_chat_open') {
|
|
8
|
+
return {
|
|
9
|
+
...state,
|
|
10
|
+
isAIChatOpen: action.value,
|
|
11
|
+
// When opening AI chat, close search
|
|
12
|
+
isSearchOpen: action.value
|
|
13
|
+
? false
|
|
14
|
+
: state.isSearchOpen,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return state;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const toggleAIChatFocusedReducer = (
|
|
21
|
+
state: VZState,
|
|
22
|
+
action: VZAction,
|
|
23
|
+
): VZState => {
|
|
24
|
+
if (action.type === 'toggle_ai_chat_focused') {
|
|
25
|
+
return {
|
|
26
|
+
...state,
|
|
27
|
+
aiChatFocused: !state.aiChatFocused,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return state;
|
|
31
|
+
};
|
|
@@ -30,6 +30,10 @@ import {
|
|
|
30
30
|
setSearchFocusedIndexReducer,
|
|
31
31
|
toggleSearchFocusedReducer,
|
|
32
32
|
} from './searchReducer';
|
|
33
|
+
import {
|
|
34
|
+
setIsAIChatOpenReducer,
|
|
35
|
+
toggleAIChatFocusedReducer,
|
|
36
|
+
} from './aiChatReducer';
|
|
33
37
|
import { toggleAutoFollowReducer } from './toggleAutoFollowReducer';
|
|
34
38
|
import { updatePresenceIndicatorReducer } from './updatePresenceIndicatorReducer';
|
|
35
39
|
import { splitCurrentPaneReducer } from './splitCurrentPaneReducer';
|
|
@@ -52,6 +56,12 @@ export type VZState = {
|
|
|
52
56
|
// True to show the search instead of files
|
|
53
57
|
isSearchOpen: boolean;
|
|
54
58
|
|
|
59
|
+
// True to show the AI chat instead of files
|
|
60
|
+
isAIChatOpen: boolean;
|
|
61
|
+
|
|
62
|
+
// True if the AI chat input should focus on the next render.
|
|
63
|
+
aiChatFocused: boolean;
|
|
64
|
+
|
|
55
65
|
// True to show the settings modal.
|
|
56
66
|
isSettingsOpen: boolean;
|
|
57
67
|
|
|
@@ -115,6 +125,14 @@ export type VZAction =
|
|
|
115
125
|
// * Sets whether the search tab is open.
|
|
116
126
|
| { type: 'set_is_search_open'; value: boolean }
|
|
117
127
|
|
|
128
|
+
// `set_is_ai_chat_open`
|
|
129
|
+
// * Sets whether the AI chat tab is open.
|
|
130
|
+
| { type: 'set_is_ai_chat_open'; value: boolean }
|
|
131
|
+
|
|
132
|
+
// `toggle_ai_chat_focused`
|
|
133
|
+
// * Toggles focused variable to trigger AI chat input focus
|
|
134
|
+
| { type: 'toggle_ai_chat_focused' }
|
|
135
|
+
|
|
118
136
|
// `set_search`
|
|
119
137
|
// * Sets the current search pattern
|
|
120
138
|
| { type: 'set_search'; value: string }
|
|
@@ -192,6 +210,8 @@ const reducers = [
|
|
|
192
210
|
setSearchFocusedIndexReducer,
|
|
193
211
|
toggleSearchFocusedReducer,
|
|
194
212
|
setIsSearchOpenReducer,
|
|
213
|
+
setIsAIChatOpenReducer,
|
|
214
|
+
toggleAIChatFocusedReducer,
|
|
195
215
|
setIsSettingsOpenReducer,
|
|
196
216
|
setIsDocOpenReducer,
|
|
197
217
|
editorNoLongerWantsFocusReducer,
|