vzcode 2.30.0 → 2.34.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 +8 -0
- package/dist/assets/{index-CD0x02Rq.js → index-nL6to42p.js} +137 -137
- package/dist/index.html +1 -1
- package/dist/llm-streaming-server/chatOperations.js +40 -10
- package/package.json +4 -2
- package/src/client/CodeEditor/getOrCreateEditor.tsx +6 -1
- package/src/client/CodeEditor/index.tsx +4 -0
- package/src/client/VZCodeContext/types.ts +12 -0
- package/src/client/VZCodeContext/useVZCodeState.ts +5 -1
- package/src/client/VZLeft.tsx +17 -2
- package/src/client/VZMiddle.tsx +12 -0
- package/src/client/VZSidebar/VisualEditor/VisualEditor.tsx +159 -174
- package/src/client/VZSidebar/VisualEditor/status.ts +150 -0
- package/src/client/VZSidebar/VisualEditor/updateConfig.ts +52 -0
- package/src/client/VZSidebar/VisualEditor/utils.ts +113 -0
- package/src/client/VZSidebar/index.tsx +23 -6
- package/src/client/aiChatButtonEvent.ts +61 -0
- package/src/client/index.ts +6 -0
- package/src/client/main.jsx +22 -0
- package/src/client/vzReducer/createInitialState.ts +8 -3
- package/src/llm-streaming-server/chatOperations.ts +53 -12
- package/src/llm-streaming-server/llmStreaming.ts +0 -3
- package/src/llm-streaming-ui/components/Message.tsx +0 -2
- package/src/types.ts +14 -0
|
@@ -100,3 +100,116 @@ export const renderSliderBackground = (
|
|
|
100
100
|
|
|
101
101
|
ctx.putImageData(imageData, 0, 0);
|
|
102
102
|
};
|
|
103
|
+
|
|
104
|
+
// Helper function to get nested property value using dot notation
|
|
105
|
+
export const getNestedProperty = <T = unknown>(
|
|
106
|
+
obj: Record<string, unknown>,
|
|
107
|
+
path: string,
|
|
108
|
+
): T | undefined => {
|
|
109
|
+
// Validate path to prevent empty strings, consecutive dots, or leading/trailing dots
|
|
110
|
+
if (
|
|
111
|
+
!path ||
|
|
112
|
+
path.includes('..') ||
|
|
113
|
+
path.startsWith('.') ||
|
|
114
|
+
path.endsWith('.')
|
|
115
|
+
) {
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const keys = path.split('.');
|
|
120
|
+
let value: unknown = obj;
|
|
121
|
+
for (const key of keys) {
|
|
122
|
+
// Skip empty keys that might result from splitting
|
|
123
|
+
if (!key) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
if (value === null || value === undefined) {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
// Type guard to ensure value is an object before accessing property
|
|
130
|
+
if (typeof value !== 'object') {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
value = (value as Record<string, unknown>)[key];
|
|
134
|
+
}
|
|
135
|
+
return value as T | undefined;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// Helper function to set nested property value using dot notation
|
|
139
|
+
export const setNestedProperty = <
|
|
140
|
+
T extends Record<string, unknown>,
|
|
141
|
+
>(
|
|
142
|
+
obj: T,
|
|
143
|
+
path: string,
|
|
144
|
+
value: unknown,
|
|
145
|
+
): T => {
|
|
146
|
+
// Validate path to prevent empty strings, consecutive dots, or leading/trailing dots
|
|
147
|
+
if (
|
|
148
|
+
!path ||
|
|
149
|
+
path.includes('..') ||
|
|
150
|
+
path.startsWith('.') ||
|
|
151
|
+
path.endsWith('.')
|
|
152
|
+
) {
|
|
153
|
+
throw new Error(
|
|
154
|
+
`Invalid property path "${path}" - path cannot be empty, contain consecutive dots, or have leading/trailing dots`,
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const keys = path.split('.');
|
|
159
|
+
|
|
160
|
+
// Check for empty keys
|
|
161
|
+
if (keys.some((key) => !key)) {
|
|
162
|
+
throw new Error(
|
|
163
|
+
`Invalid property path "${path}" - path contains empty segments`,
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const newObj = { ...obj };
|
|
168
|
+
let current: Record<string, unknown> = newObj;
|
|
169
|
+
|
|
170
|
+
// List of dangerous keys that could lead to prototype pollution
|
|
171
|
+
const dangerousKeys = [
|
|
172
|
+
'__proto__',
|
|
173
|
+
'constructor',
|
|
174
|
+
'prototype',
|
|
175
|
+
];
|
|
176
|
+
|
|
177
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
178
|
+
const key = keys[i];
|
|
179
|
+
|
|
180
|
+
// Guard against prototype pollution
|
|
181
|
+
if (dangerousKeys.includes(key)) {
|
|
182
|
+
throw new Error(
|
|
183
|
+
`Cannot set property "${key}" - potential prototype pollution`,
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Create nested object if it doesn't exist or isn't a plain object
|
|
188
|
+
if (
|
|
189
|
+
current[key] == null ||
|
|
190
|
+
typeof current[key] !== 'object' ||
|
|
191
|
+
Array.isArray(current[key])
|
|
192
|
+
) {
|
|
193
|
+
current[key] = {};
|
|
194
|
+
} else {
|
|
195
|
+
// Clone the nested object to avoid mutation
|
|
196
|
+
current[key] = {
|
|
197
|
+
...(current[key] as Record<string, unknown>),
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
current = current[key] as Record<string, unknown>;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Guard against prototype pollution for the final key
|
|
204
|
+
const finalKey = keys[keys.length - 1];
|
|
205
|
+
if (dangerousKeys.includes(finalKey)) {
|
|
206
|
+
throw new Error(
|
|
207
|
+
`Cannot set property "${finalKey}" - potential prototype pollution`,
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Set the final value
|
|
212
|
+
current[finalKey] = value;
|
|
213
|
+
|
|
214
|
+
return newObj;
|
|
215
|
+
};
|
|
@@ -40,14 +40,22 @@ import { useDragAndDrop } from './useDragAndDrop';
|
|
|
40
40
|
import { createAICopyPasteHandlers } from './aiCopyPaste';
|
|
41
41
|
import {
|
|
42
42
|
enableLiveKit,
|
|
43
|
-
enableAIChat,
|
|
43
|
+
enableAIChat as enableAIChatFeatureFlag,
|
|
44
44
|
} from '../featureFlags';
|
|
45
|
+
import { handleAIChatButtonClick } from '../aiChatButtonEvent';
|
|
45
46
|
import './styles.scss';
|
|
46
47
|
import { VisualEditor } from './VisualEditor';
|
|
47
48
|
|
|
48
49
|
const enableConnectionStatus = true;
|
|
49
50
|
|
|
50
51
|
export const VZSidebar = ({
|
|
52
|
+
// Host-provided override so consumers (e.g. VizHub Studio, which has
|
|
53
|
+
// its own top-bar "AI Edit" entry point) can hide the "Edit with AI"
|
|
54
|
+
// sidebar button. Defaults to the compile-time feature flag.
|
|
55
|
+
enableAIChat = enableAIChatFeatureFlag,
|
|
56
|
+
// When set, clicking the button dispatches this custom event instead
|
|
57
|
+
// of opening VZCode's built-in AI chat, letting the host handle it.
|
|
58
|
+
aiChatButtonEvent,
|
|
51
59
|
createFileTooltipText = (
|
|
52
60
|
<>
|
|
53
61
|
<strong>New file</strong>
|
|
@@ -135,6 +143,8 @@ export const VZSidebar = ({
|
|
|
135
143
|
voiceChatToolTipText?: React.ReactNode;
|
|
136
144
|
aiChatToolTipText?: React.ReactNode;
|
|
137
145
|
visualEditorToolTipText?: React.ReactNode;
|
|
146
|
+
enableAIChat?: boolean;
|
|
147
|
+
aiChatButtonEvent?: string;
|
|
138
148
|
}) => {
|
|
139
149
|
const {
|
|
140
150
|
files,
|
|
@@ -341,11 +351,17 @@ export const VZSidebar = ({
|
|
|
341
351
|
<i
|
|
342
352
|
id="ai-chat-icon"
|
|
343
353
|
className="icon-button icon-button-dark"
|
|
344
|
-
onClick={() =>
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
354
|
+
onClick={() =>
|
|
355
|
+
handleAIChatButtonClick({
|
|
356
|
+
aiChatButtonEvent,
|
|
357
|
+
target: window,
|
|
358
|
+
openAIChat: () => {
|
|
359
|
+
setIsAIChatOpen(true);
|
|
360
|
+
setIsSearchOpen(false);
|
|
361
|
+
setSidebarView(true); // Switch to AI chat view
|
|
362
|
+
},
|
|
363
|
+
})
|
|
364
|
+
}
|
|
349
365
|
>
|
|
350
366
|
<SparklesSVG />
|
|
351
367
|
</i>
|
|
@@ -411,6 +427,7 @@ export const VZSidebar = ({
|
|
|
411
427
|
setIsVisualEditorOpen(true);
|
|
412
428
|
setIsAIChatOpen(false);
|
|
413
429
|
setIsSearchOpen(false);
|
|
430
|
+
setSidebarView(false); // Switch to files view width for visual editor
|
|
414
431
|
}}
|
|
415
432
|
>
|
|
416
433
|
<AdjustmentSVG />
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-facing event emitted when the VZCode sidebar "Edit with AI"
|
|
3
|
+
* button is clicked in "emit" mode.
|
|
4
|
+
*
|
|
5
|
+
* A host opts in by passing `aiChatButtonEvent` to `VZSidebar` /
|
|
6
|
+
* `VZLeft`. When set, clicking `#ai-chat-icon` dispatches this event
|
|
7
|
+
* instead of opening VZCode's built-in AI chat panel, so the host can
|
|
8
|
+
* route the click to its own AI editing entry point (e.g. VizHub
|
|
9
|
+
* Studio's top-bar "AI Edit" action).
|
|
10
|
+
*
|
|
11
|
+
* The constant is exported so hosts don't hardcode the event name.
|
|
12
|
+
*/
|
|
13
|
+
export const AI_CHAT_BUTTON_EVENT =
|
|
14
|
+
'vzcode:ai-chat-button-click';
|
|
15
|
+
|
|
16
|
+
export interface AIChatButtonEventDetail {
|
|
17
|
+
source: 'vzcode-sidebar';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Dispatch the host-facing AI chat button event.
|
|
22
|
+
* Kept as a standalone function so it is unit-testable without a DOM.
|
|
23
|
+
*/
|
|
24
|
+
export function emitAIChatButtonEvent(
|
|
25
|
+
eventName: string,
|
|
26
|
+
target: EventTarget,
|
|
27
|
+
): void {
|
|
28
|
+
target.dispatchEvent(
|
|
29
|
+
new CustomEvent<AIChatButtonEventDetail>(eventName, {
|
|
30
|
+
bubbles: true,
|
|
31
|
+
composed: true,
|
|
32
|
+
detail: { source: 'vzcode-sidebar' },
|
|
33
|
+
}),
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Decide what clicking the sidebar AI chat button should do.
|
|
39
|
+
*
|
|
40
|
+
* - When `aiChatButtonEvent` is set, emit the event and leave all
|
|
41
|
+
* VZCode state untouched (the host owns the action).
|
|
42
|
+
* - Otherwise, fall back to opening VZCode's built-in AI chat.
|
|
43
|
+
*
|
|
44
|
+
* Extracted from the component so the branching is unit-testable
|
|
45
|
+
* without rendering or a real DOM.
|
|
46
|
+
*/
|
|
47
|
+
export function handleAIChatButtonClick({
|
|
48
|
+
aiChatButtonEvent,
|
|
49
|
+
target,
|
|
50
|
+
openAIChat,
|
|
51
|
+
}: {
|
|
52
|
+
aiChatButtonEvent?: string;
|
|
53
|
+
target: EventTarget;
|
|
54
|
+
openAIChat: () => void;
|
|
55
|
+
}): void {
|
|
56
|
+
if (aiChatButtonEvent) {
|
|
57
|
+
emitAIChatButtonEvent(aiChatButtonEvent, target);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
openAIChat();
|
|
61
|
+
}
|
package/src/client/index.ts
CHANGED
|
@@ -11,6 +11,12 @@ export { VZKeyboardShortcutsDoc } from './VZKeyboardShortcutsDoc';
|
|
|
11
11
|
export { VZResizer } from './VZResizer';
|
|
12
12
|
export { VZLeft } from './VZLeft';
|
|
13
13
|
export { VZMiddle } from './VZMiddle';
|
|
14
|
+
export {
|
|
15
|
+
AI_CHAT_BUTTON_EVENT,
|
|
16
|
+
emitAIChatButtonEvent,
|
|
17
|
+
handleAIChatButtonClick,
|
|
18
|
+
} from './aiChatButtonEvent';
|
|
19
|
+
export type { AIChatButtonEventDetail } from './aiChatButtonEvent';
|
|
14
20
|
export {
|
|
15
21
|
SplitPaneResizeProvider,
|
|
16
22
|
SplitPaneResizeContext,
|
package/src/client/main.jsx
CHANGED
|
@@ -3,6 +3,28 @@ import * as ReactDOM from 'react-dom/client';
|
|
|
3
3
|
import App from './App';
|
|
4
4
|
import { BrowserRouter } from 'react-router-dom';
|
|
5
5
|
|
|
6
|
+
// Global error handler to catch CodeMirror DOM position errors
|
|
7
|
+
// These can occur when CodeMirror instances are created but not yet
|
|
8
|
+
// attached to the DOM, or when presence indicators try to render
|
|
9
|
+
// on offscreen editor instances.
|
|
10
|
+
window.addEventListener('error', (event) => {
|
|
11
|
+
// Check if this is the specific CodeMirror posFromDOM/posAtDOM error
|
|
12
|
+
if (
|
|
13
|
+
event.error instanceof RangeError &&
|
|
14
|
+
event.error.message.includes(
|
|
15
|
+
'Trying to find position for a DOM position outside of the document',
|
|
16
|
+
)
|
|
17
|
+
) {
|
|
18
|
+
// Log the error for debugging purposes
|
|
19
|
+
console.log(
|
|
20
|
+
'Suppressed CodeMirror DOM position error:',
|
|
21
|
+
event.error,
|
|
22
|
+
);
|
|
23
|
+
// Prevent the error from being logged to console by returning true
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
6
28
|
ReactDOM.createRoot(document.getElementById('root')).render(
|
|
7
29
|
<BrowserRouter>
|
|
8
30
|
<App />
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { VZState } from '.';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Username,
|
|
4
|
+
VZInitialSidebarView,
|
|
5
|
+
} from '../../types';
|
|
3
6
|
import { ThemeLabel } from '../themes';
|
|
4
7
|
|
|
5
8
|
export const createInitialState = ({
|
|
6
9
|
defaultTheme,
|
|
7
10
|
initialUsername = 'Anonymous',
|
|
11
|
+
initialSidebarView = 'ai-chat',
|
|
8
12
|
}: {
|
|
9
13
|
defaultTheme: ThemeLabel;
|
|
10
14
|
initialUsername?: Username;
|
|
15
|
+
initialSidebarView?: VZInitialSidebarView;
|
|
11
16
|
}): VZState => ({
|
|
12
17
|
pane: {
|
|
13
18
|
id: 'root',
|
|
@@ -24,9 +29,9 @@ export const createInitialState = ({
|
|
|
24
29
|
focusedIndex: null,
|
|
25
30
|
focusedChildIndex: null,
|
|
26
31
|
},
|
|
27
|
-
isVisualEditorOpen:
|
|
32
|
+
isVisualEditorOpen: initialSidebarView === 'visual',
|
|
28
33
|
isSearchOpen: false,
|
|
29
|
-
isAIChatOpen:
|
|
34
|
+
isAIChatOpen: initialSidebarView === 'ai-chat',
|
|
30
35
|
aiChatFocused: false,
|
|
31
36
|
aiChatMode: 'edit',
|
|
32
37
|
isSettingsOpen: false,
|
|
@@ -335,30 +335,66 @@ export const finalizeAIMessage = (
|
|
|
335
335
|
};
|
|
336
336
|
|
|
337
337
|
/**
|
|
338
|
-
* Adds diff data to
|
|
338
|
+
* Adds diff data to a specific AI message by ID
|
|
339
|
+
* Phase 3 Fix: Use explicit message ID instead of assuming
|
|
340
|
+
* last message is AI, preventing bugs with rapid message sends
|
|
339
341
|
*/
|
|
340
342
|
export const addDiffToAIMessage = (
|
|
341
343
|
shareDBDoc: ShareDBDoc<VizContent>,
|
|
342
344
|
chatId: VizChatId,
|
|
343
345
|
diffData: any,
|
|
344
|
-
beforeCommitId?: string, // Commit ID before AI changes
|
|
346
|
+
beforeCommitId?: string, // Commit ID before AI changes
|
|
347
|
+
messageId?: string, // Explicit AI message ID to update
|
|
345
348
|
) => {
|
|
346
349
|
const chat = shareDBDoc.data.chats[chatId];
|
|
350
|
+
if (!chat || !chat.messages) {
|
|
351
|
+
console.warn(
|
|
352
|
+
`Chat ${chatId} not found or has no messages`,
|
|
353
|
+
);
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
|
|
347
357
|
const messages = [...chat.messages];
|
|
358
|
+
let targetMessageIndex = -1;
|
|
348
359
|
|
|
349
|
-
//
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
360
|
+
// Phase 3 Fix: Use explicit message ID if provided
|
|
361
|
+
if (messageId) {
|
|
362
|
+
targetMessageIndex = messages.findIndex(
|
|
363
|
+
(msg) => msg.id === messageId,
|
|
364
|
+
);
|
|
365
|
+
if (
|
|
366
|
+
targetMessageIndex === -1 ||
|
|
367
|
+
messages[targetMessageIndex].role !== 'assistant'
|
|
368
|
+
) {
|
|
369
|
+
console.warn(
|
|
370
|
+
`AI message with id ${messageId} not found in chat ${chatId}`,
|
|
371
|
+
);
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
} else {
|
|
375
|
+
// Fallback: Find the most recent AI message (safer than
|
|
376
|
+
// just assuming last message)
|
|
377
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
378
|
+
if (messages[i].role === 'assistant') {
|
|
379
|
+
targetMessageIndex = i;
|
|
380
|
+
break;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (targetMessageIndex === -1) {
|
|
385
|
+
console.warn(`No AI message found in chat ${chatId}`);
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Update the target message with diff data
|
|
391
|
+
if (targetMessageIndex >= 0) {
|
|
355
392
|
const newMessage = {
|
|
356
|
-
...messages[
|
|
393
|
+
...messages[targetMessageIndex],
|
|
357
394
|
diffData,
|
|
358
|
-
...(beforeCommitId && { beforeCommitId }),
|
|
395
|
+
...(beforeCommitId && { beforeCommitId }),
|
|
359
396
|
};
|
|
360
|
-
|
|
361
|
-
(messages[lastAIMessageIndex] as any) = newMessage;
|
|
397
|
+
(messages[targetMessageIndex] as any) = newMessage;
|
|
362
398
|
|
|
363
399
|
const messageOp = diff(shareDBDoc.data, {
|
|
364
400
|
...shareDBDoc.data,
|
|
@@ -373,6 +409,11 @@ export const addDiffToAIMessage = (
|
|
|
373
409
|
});
|
|
374
410
|
|
|
375
411
|
shareDBDoc.submitOp(messageOp);
|
|
412
|
+
|
|
413
|
+
DEBUG &&
|
|
414
|
+
console.log(
|
|
415
|
+
`addDiffToAIMessage: Successfully added diff to message ${targetMessageIndex} in chat ${chatId}`,
|
|
416
|
+
);
|
|
376
417
|
}
|
|
377
418
|
};
|
|
378
419
|
|
|
@@ -78,7 +78,6 @@ export const createLLMFunction = ({
|
|
|
78
78
|
},
|
|
79
79
|
});
|
|
80
80
|
|
|
81
|
-
|
|
82
81
|
let fullContent = '';
|
|
83
82
|
let generationId = '';
|
|
84
83
|
let currentEditingFileName = null;
|
|
@@ -253,8 +252,6 @@ export const createLLMFunction = ({
|
|
|
253
252
|
const chunks = [];
|
|
254
253
|
let reasoningContent = '';
|
|
255
254
|
|
|
256
|
-
|
|
257
|
-
|
|
258
255
|
// Configure reasoning tokens based on enableReasoningTokens flag
|
|
259
256
|
const requestConfig: any = {
|
|
260
257
|
model: modelName,
|
|
@@ -13,8 +13,6 @@ import { DiffView, DiffViewRef } from './DiffView';
|
|
|
13
13
|
import { UnifiedFilesDiff } from '../../utils/fileDiff';
|
|
14
14
|
import { enableDiffView } from '../../client/featureFlags';
|
|
15
15
|
|
|
16
|
-
const DEBUG = true;
|
|
17
|
-
|
|
18
16
|
interface MessageProps {
|
|
19
17
|
id: string;
|
|
20
18
|
role: 'user' | 'assistant';
|
package/src/types.ts
CHANGED
|
@@ -305,3 +305,17 @@ export interface StreamingChatMessage {
|
|
|
305
305
|
currentStatus?: string;
|
|
306
306
|
isComplete?: boolean;
|
|
307
307
|
}
|
|
308
|
+
|
|
309
|
+
/** Embedding hosts can choose which sidebar VZCode opens initially. */
|
|
310
|
+
export type VZInitialSidebarView =
|
|
311
|
+
| 'ai-chat'
|
|
312
|
+
| 'files'
|
|
313
|
+
| 'visual';
|
|
314
|
+
|
|
315
|
+
/** Reason a visualization cannot yet render visual-editor controls. */
|
|
316
|
+
export type VisualEditorEmptyReason =
|
|
317
|
+
| 'missing-config'
|
|
318
|
+
| 'invalid-config'
|
|
319
|
+
| 'missing-widgets'
|
|
320
|
+
| 'invalid-widgets'
|
|
321
|
+
| 'empty-widgets';
|