vzcode 2.34.0 → 2.36.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/dist/assets/buildWorker-BZlya278.js +687 -0
- package/dist/assets/index-Cj-ERpBu.css +1 -0
- package/dist/assets/index-DD7vzp4U.js +364 -0
- package/dist/assets/{worker-D8p1JlHW.js → worker-1oQYaz-F.js} +251 -251
- package/dist/assets/worker-BfgPD8zR.js +125 -0
- package/dist/assets/{worker-k7HZ3t-V.js → worker-CoJaqtpi.js} +12 -12
- package/dist/index.html +2 -2
- package/dist/ot.js +180 -2
- package/dist/server/createServer.js +281 -0
- package/dist/server/index.js +6 -269
- package/package.json +14 -3
- package/src/client/CodeEditor/getOrCreateEditor.tsx +0 -14
- package/src/client/VZCodeContext/chatSessionHelpers.ts +17 -0
- package/src/client/VZCodeContext/useAIChatSession.ts +325 -0
- package/src/client/VZCodeContext/useVZCodeState.ts +23 -279
- package/src/client/VZSidebar/AIChatWrapper.tsx +85 -0
- package/src/client/VZSidebar/VisualEditor/VisualEditor.tsx +95 -208
- package/src/client/VZSidebar/VisualEditor/colorUtils.ts +39 -0
- package/src/client/VZSidebar/VisualEditor/status.ts +2 -40
- package/src/client/VZSidebar/VisualEditor/updateConfig.ts +10 -1
- package/src/client/VZSidebar/VisualEditor/utils.ts +49 -65
- package/src/client/VZSidebar/index.tsx +2 -2
- package/src/client/definitionJumpListeners.ts +47 -0
- package/src/client/useKeyboardShortcuts.ts +23 -28
- package/src/client/useOpenDirectories.ts +0 -1
- package/src/llm-streaming-server/README.md +5 -3
- package/src/llm-streaming-ui/README.md +44 -42
- package/src/llm-streaming-ui/components/ChatInput.tsx +6 -19
- package/src/llm-streaming-ui/components/DiffView.tsx +6 -24
- package/src/llm-streaming-ui/components/FileEditingIndicator.tsx +1 -1
- package/src/llm-streaming-ui/components/Message.tsx +11 -27
- package/src/llm-streaming-ui/components/MessageList.tsx +15 -29
- package/src/llm-streaming-ui/components/Spinner.scss +37 -0
- package/src/llm-streaming-ui/components/Spinner.tsx +59 -0
- package/src/llm-streaming-ui/components/bootstrap.ts +16 -0
- package/src/llm-streaming-ui/components/icons.tsx +68 -0
- package/src/llm-streaming-ui/components/index.tsx +34 -30
- package/src/llm-streaming-ui/index.ts +13 -0
- package/src/llm-streaming-ui/props.ts +137 -0
- package/src/ot.ts +221 -4
- package/src/server/createServer.ts +413 -0
- package/src/server/index.ts +8 -333
- package/dist/assets/buildWorker-DylWm2VX.js +0 -687
- package/dist/assets/index-Dyt9tpmu.css +0 -1
- package/dist/assets/index-nL6to42p.js +0 -364
- package/dist/assets/worker-b9bkZkXK.js +0 -116
- package/src/client/AIAssist/AIAssistCodeMirrorKeyMap.ts +0 -42
- package/src/client/AIAssist/generateFilesContext.ts +0 -25
- package/src/client/AIAssist/index.ts +0 -2
- package/src/client/CodeEditor/InteractiveWidgets/highlightWidgets.ts +0 -79
- /package/src/{client → llm-streaming-ui}/hooks/useAutoScroll.ts +0 -0
- /package/src/{client → llm-streaming-ui}/utils/scrollUtils.ts +0 -0
|
@@ -101,38 +101,57 @@ export const renderSliderBackground = (
|
|
|
101
101
|
ctx.putImageData(imageData, 0, 0);
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
/**
|
|
105
|
+
* Widget paths are own-property paths through JSON objects. This parser is
|
|
106
|
+
* shared by reads, validation and writes to avoid accidental prototype access.
|
|
107
|
+
*/
|
|
108
|
+
export const splitEditablePropertyPath = (
|
|
107
109
|
path: string,
|
|
108
|
-
):
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
110
|
+
): string[] | null => {
|
|
111
|
+
if (typeof path !== 'string' || !path) return null;
|
|
112
|
+
const segments = path.split('.');
|
|
113
|
+
return segments.every(
|
|
114
|
+
(key) =>
|
|
115
|
+
key.length > 0 &&
|
|
116
|
+
key !== '__proto__' &&
|
|
117
|
+
key !== 'constructor' &&
|
|
118
|
+
key !== 'prototype',
|
|
119
|
+
)
|
|
120
|
+
? segments
|
|
121
|
+
: null;
|
|
122
|
+
};
|
|
118
123
|
|
|
119
|
-
|
|
120
|
-
|
|
124
|
+
export const getEditablePropertyValue = (
|
|
125
|
+
obj: unknown,
|
|
126
|
+
path: string,
|
|
127
|
+
): { found: boolean; value: unknown } => {
|
|
128
|
+
const keys = splitEditablePropertyPath(path);
|
|
129
|
+
if (!keys) return { found: false, value: undefined };
|
|
130
|
+
let current: unknown = obj;
|
|
121
131
|
for (const key of keys) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
// Type guard to ensure value is an object before accessing property
|
|
130
|
-
if (typeof value !== 'object') {
|
|
131
|
-
return undefined;
|
|
132
|
+
if (
|
|
133
|
+
current === null ||
|
|
134
|
+
typeof current !== 'object' ||
|
|
135
|
+
Array.isArray(current) ||
|
|
136
|
+
!Object.prototype.hasOwnProperty.call(current, key)
|
|
137
|
+
) {
|
|
138
|
+
return { found: false, value: undefined };
|
|
132
139
|
}
|
|
133
|
-
|
|
140
|
+
current = (current as Record<string, unknown>)[key];
|
|
134
141
|
}
|
|
135
|
-
return
|
|
142
|
+
return { found: true, value: current };
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// Read widget values using exactly the same safe path semantics as writes.
|
|
146
|
+
export const getNestedProperty = <T = unknown>(
|
|
147
|
+
obj: Record<string, unknown>,
|
|
148
|
+
path: string,
|
|
149
|
+
): T | undefined => {
|
|
150
|
+
const { found, value } = getEditablePropertyValue(
|
|
151
|
+
obj,
|
|
152
|
+
path,
|
|
153
|
+
);
|
|
154
|
+
return found ? (value as T) : undefined;
|
|
136
155
|
};
|
|
137
156
|
|
|
138
157
|
// Helper function to set nested property value using dot notation
|
|
@@ -143,47 +162,18 @@ export const setNestedProperty = <
|
|
|
143
162
|
path: string,
|
|
144
163
|
value: unknown,
|
|
145
164
|
): T => {
|
|
146
|
-
|
|
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)) {
|
|
165
|
+
const keys = splitEditablePropertyPath(path);
|
|
166
|
+
if (!keys)
|
|
162
167
|
throw new Error(
|
|
163
|
-
|
|
168
|
+
'Invalid or unsafe property path: ' + path,
|
|
164
169
|
);
|
|
165
|
-
}
|
|
166
170
|
|
|
167
171
|
const newObj = { ...obj };
|
|
168
172
|
let current: Record<string, unknown> = newObj;
|
|
169
173
|
|
|
170
|
-
// List of dangerous keys that could lead to prototype pollution
|
|
171
|
-
const dangerousKeys = [
|
|
172
|
-
'__proto__',
|
|
173
|
-
'constructor',
|
|
174
|
-
'prototype',
|
|
175
|
-
];
|
|
176
|
-
|
|
177
174
|
for (let i = 0; i < keys.length - 1; i++) {
|
|
178
175
|
const key = keys[i];
|
|
179
176
|
|
|
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
177
|
// Create nested object if it doesn't exist or isn't a plain object
|
|
188
178
|
if (
|
|
189
179
|
current[key] == null ||
|
|
@@ -200,13 +190,7 @@ export const setNestedProperty = <
|
|
|
200
190
|
current = current[key] as Record<string, unknown>;
|
|
201
191
|
}
|
|
202
192
|
|
|
203
|
-
// Guard against prototype pollution for the final key
|
|
204
193
|
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
194
|
|
|
211
195
|
// Set the final value
|
|
212
196
|
current[finalKey] = value;
|
|
@@ -32,7 +32,7 @@ import { MicSVG } from '../Icons/MicSVG';
|
|
|
32
32
|
import { sortFileTree } from '../sortFileTree';
|
|
33
33
|
import { SplitPaneResizeContext } from '../SplitPaneResizeContext';
|
|
34
34
|
import { VZCodeContext } from '../VZCodeContext';
|
|
35
|
-
import {
|
|
35
|
+
import { AIChatWrapper } from './AIChatWrapper';
|
|
36
36
|
import { Listing } from './Listing';
|
|
37
37
|
import { Search } from './Search';
|
|
38
38
|
import { DeleteConfirmationModal } from './DeleteConfirmationModal';
|
|
@@ -581,7 +581,7 @@ export const VZSidebar = ({
|
|
|
581
581
|
>
|
|
582
582
|
{isAIChatOpen ? (
|
|
583
583
|
<div className="sidebar-ai-chat">
|
|
584
|
-
<
|
|
584
|
+
<AIChatWrapper />
|
|
585
585
|
</div>
|
|
586
586
|
) : isSearchOpen ? (
|
|
587
587
|
<div className="sidebar-search">
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An editor owns the temporary Ctrl-hover and Ctrl-click listeners.
|
|
3
|
+
* Keeping their lifecycle together prevents stale DOM handlers when panes
|
|
4
|
+
* switch or VZCode is unmounted.
|
|
5
|
+
*/
|
|
6
|
+
export function createDefinitionJumpListeners(
|
|
7
|
+
target: EventTarget,
|
|
8
|
+
onHover: (event: MouseEvent) => void,
|
|
9
|
+
onClick: (event: MouseEvent) => void,
|
|
10
|
+
) {
|
|
11
|
+
let hovering = false;
|
|
12
|
+
let armed = false;
|
|
13
|
+
|
|
14
|
+
const hoverListener: EventListener = (event) => {
|
|
15
|
+
onHover(event as MouseEvent);
|
|
16
|
+
};
|
|
17
|
+
const clickListener: EventListener = (event) => {
|
|
18
|
+
armed = false;
|
|
19
|
+
target.removeEventListener('mousedown', clickListener);
|
|
20
|
+
onClick(event as MouseEvent);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
start() {
|
|
25
|
+
if (hovering) return;
|
|
26
|
+
hovering = true;
|
|
27
|
+
target.addEventListener('mouseover', hoverListener);
|
|
28
|
+
},
|
|
29
|
+
armClick() {
|
|
30
|
+
if (armed) return;
|
|
31
|
+
armed = true;
|
|
32
|
+
target.addEventListener('mousedown', clickListener);
|
|
33
|
+
},
|
|
34
|
+
stop() {
|
|
35
|
+
hovering = false;
|
|
36
|
+
armed = false;
|
|
37
|
+
target.removeEventListener(
|
|
38
|
+
'mouseover',
|
|
39
|
+
hoverListener,
|
|
40
|
+
);
|
|
41
|
+
target.removeEventListener(
|
|
42
|
+
'mousedown',
|
|
43
|
+
clickListener,
|
|
44
|
+
);
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -7,18 +7,13 @@ import { EditorState } from '@codemirror/state';
|
|
|
7
7
|
import { VizFileId } from '@vizhub/viz-types';
|
|
8
8
|
import { PaneId } from '../types';
|
|
9
9
|
import { editorCacheKey } from './useEditorCache';
|
|
10
|
+
import { createDefinitionJumpListeners } from './definitionJumpListeners';
|
|
10
11
|
|
|
11
12
|
/*
|
|
12
13
|
The following is a helpful resource for the following Code Mirror Syntax Tree methods below
|
|
13
14
|
https://lezer.codemirror.net/docs/ref/#common
|
|
14
15
|
*/
|
|
15
16
|
|
|
16
|
-
// Store the element in the current editor DOM to highlight, indicating a potential jump to definition is possible
|
|
17
|
-
let activeJumpingElement: HTMLSpanElement = null;
|
|
18
|
-
|
|
19
|
-
// Store the syntax node representing the destination within the syntax tree
|
|
20
|
-
let definingNode: SyntaxNode = null;
|
|
21
|
-
|
|
22
17
|
// Example nesting types for the specific language to find level in the syntax tree
|
|
23
18
|
const nestingTypes = new Set<string>([
|
|
24
19
|
'FunctionDeclaration',
|
|
@@ -207,6 +202,9 @@ export const useKeyboardShortcuts = ({
|
|
|
207
202
|
activeFileId,
|
|
208
203
|
activePaneId,
|
|
209
204
|
);
|
|
205
|
+
// Each mounted editor owns its jump target and listeners.
|
|
206
|
+
let activeJumpingElement: HTMLSpanElement | null = null;
|
|
207
|
+
let definingNode: SyntaxNode | null = null;
|
|
210
208
|
|
|
211
209
|
const handleKeyPress = (event: KeyboardEvent) => {
|
|
212
210
|
if (shouldTriggerRun(event)) {
|
|
@@ -245,10 +243,7 @@ export const useKeyboardShortcuts = ({
|
|
|
245
243
|
|
|
246
244
|
if (event.ctrlKey === true) {
|
|
247
245
|
// On holding CTRL key, search for a potential definition jump using mouse location
|
|
248
|
-
|
|
249
|
-
'mouseover',
|
|
250
|
-
handleMouseOver,
|
|
251
|
-
);
|
|
246
|
+
jumpListeners.start();
|
|
252
247
|
}
|
|
253
248
|
|
|
254
249
|
if (event.altKey === true) {
|
|
@@ -299,17 +294,11 @@ export const useKeyboardShortcuts = ({
|
|
|
299
294
|
if (activeJumpingElement) {
|
|
300
295
|
activeJumpingElement.style.cursor = 'initial';
|
|
301
296
|
activeJumpingElement.style.textDecoration = 'none';
|
|
302
|
-
activeJumpingElement =
|
|
297
|
+
activeJumpingElement = null;
|
|
298
|
+
definingNode = null;
|
|
303
299
|
}
|
|
304
300
|
|
|
305
|
-
|
|
306
|
-
'mouseover',
|
|
307
|
-
handleMouseOver,
|
|
308
|
-
);
|
|
309
|
-
document.removeEventListener(
|
|
310
|
-
'mousedown',
|
|
311
|
-
jumpToDefinitionHandler,
|
|
312
|
-
);
|
|
301
|
+
jumpListeners.stop();
|
|
313
302
|
};
|
|
314
303
|
|
|
315
304
|
const jumpToDefinitionHandler = (
|
|
@@ -332,8 +321,11 @@ export const useKeyboardShortcuts = ({
|
|
|
332
321
|
|
|
333
322
|
// Move current cursor and center view in the editor to destination node
|
|
334
323
|
|
|
335
|
-
const editor
|
|
336
|
-
|
|
324
|
+
const editor = editorCache.get(cacheKey)?.editor;
|
|
325
|
+
if (!editor) {
|
|
326
|
+
resetActiveJumpingElement();
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
337
329
|
const closestDefinition: SyntaxNode = definingNode;
|
|
338
330
|
|
|
339
331
|
editor.dispatch({
|
|
@@ -365,8 +357,8 @@ export const useKeyboardShortcuts = ({
|
|
|
365
357
|
return;
|
|
366
358
|
}
|
|
367
359
|
|
|
368
|
-
const editor
|
|
369
|
-
|
|
360
|
+
const editor = editorCache.get(cacheKey)?.editor;
|
|
361
|
+
if (!editor) return;
|
|
370
362
|
const tree = syntaxTree(editor.state);
|
|
371
363
|
const element = event.target as HTMLSpanElement;
|
|
372
364
|
|
|
@@ -423,19 +415,22 @@ export const useKeyboardShortcuts = ({
|
|
|
423
415
|
'underline';
|
|
424
416
|
|
|
425
417
|
// CTRL + Click: Jump to relative definition, which is removed on CTRL key release
|
|
426
|
-
|
|
427
|
-
'mousedown',
|
|
428
|
-
jumpToDefinitionHandler,
|
|
429
|
-
{ once: true },
|
|
430
|
-
);
|
|
418
|
+
jumpListeners.armClick();
|
|
431
419
|
}
|
|
432
420
|
}
|
|
433
421
|
};
|
|
434
422
|
|
|
423
|
+
const jumpListeners = createDefinitionJumpListeners(
|
|
424
|
+
document,
|
|
425
|
+
handleMouseOver,
|
|
426
|
+
jumpToDefinitionHandler,
|
|
427
|
+
);
|
|
428
|
+
|
|
435
429
|
document.addEventListener('keydown', handleKeyPress);
|
|
436
430
|
document.addEventListener('keyup', handleKeyRelease);
|
|
437
431
|
|
|
438
432
|
return () => {
|
|
433
|
+
resetActiveJumpingElement();
|
|
439
434
|
document.removeEventListener(
|
|
440
435
|
'keydown',
|
|
441
436
|
handleKeyPress,
|
|
@@ -2,7 +2,6 @@ import { useState, useCallback, useEffect } from 'react';
|
|
|
2
2
|
import type { Pane } from '../types';
|
|
3
3
|
import { VizContent } from '@vizhub/viz-types';
|
|
4
4
|
|
|
5
|
-
// TODO bring this feature back
|
|
6
5
|
// When a page is opened with an active file,
|
|
7
6
|
// make sure all the directories leading to that file
|
|
8
7
|
// are opened automatically.
|
|
@@ -27,9 +27,9 @@ This module is being extracted from VZCode's AI chat functionality to become a s
|
|
|
27
27
|
|
|
28
28
|
## Dependencies
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
Declared in `package.json`:
|
|
31
31
|
|
|
32
|
-
- `openai` - OpenAI SDK for LLM interactions
|
|
32
|
+
- `openai` - OpenAI SDK for LLM interactions (declared directly; also used transitively by `@langchain/openai`)
|
|
33
33
|
- `sharedb` - Real-time collaborative editing framework
|
|
34
34
|
- `llm-code-format` - Markdown parsing for code blocks
|
|
35
35
|
- `editcodewithai` - Code editing utilities
|
|
@@ -44,7 +44,9 @@ This module will eventually be:
|
|
|
44
44
|
3. Made framework-agnostic (can work with Express, Fastify, etc.)
|
|
45
45
|
4. Fully documented with usage examples
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
This module is being extracted into a standalone package
|
|
48
|
+
(`@vizhub/llm-streaming-server`). Follow the conventions in
|
|
49
|
+
`../llm-streaming-ui/README.md` when contributing.
|
|
48
50
|
|
|
49
51
|
## Usage (Current)
|
|
50
52
|
|
|
@@ -4,17 +4,23 @@ Client-side React UI components for displaying streaming AI edits and chat.
|
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
This module is
|
|
7
|
+
This module is a standalone, reusable React component library extracted
|
|
8
|
+
from VZCode's AI chat interface. It provides client-side UI for:
|
|
8
9
|
|
|
9
10
|
- **AI Chat Interface**: Main chat container component
|
|
10
|
-
- **Message Display**: Rendering user and
|
|
11
|
+
- **Message Display**: Rendering user and assistant messages with streaming support
|
|
11
12
|
- **Diff Visualization**: Showing code changes with syntax highlighting
|
|
12
13
|
- **Status Indicators**: Displaying AI thinking/reasoning and file editing status
|
|
13
14
|
- **Voice Input**: Speech recognition for voice-based chat input
|
|
14
15
|
|
|
15
|
-
##
|
|
16
|
+
## Status
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
The library is **decoupled** from VZCode. It does **not** import from
|
|
19
|
+
`src/client` and contains no reference to `VZCodeContext`. All
|
|
20
|
+
application state and callbacks are supplied via props.
|
|
21
|
+
|
|
22
|
+
VZCode binds those props using the `AIChatWrapper` component in
|
|
23
|
+
`src/client/VZSidebar/AIChatWrapper.tsx`.
|
|
18
24
|
|
|
19
25
|
## Components
|
|
20
26
|
|
|
@@ -36,68 +42,64 @@ This module is being extracted from VZCode's AI chat interface to become a stand
|
|
|
36
42
|
- `TypingIndicator.tsx` - Animated typing/loading indicator
|
|
37
43
|
- `ThinkingScratchpad.tsx` - AI reasoning/thinking display
|
|
38
44
|
- `JumpToLatestButton.tsx` - Button to scroll to latest message
|
|
45
|
+
- `Spinner.tsx` - Animated loading spinner
|
|
39
46
|
|
|
40
47
|
### Hooks
|
|
41
48
|
|
|
42
49
|
- `useSpeechRecognition.ts` - Voice input functionality
|
|
50
|
+
- `hooks/useAutoScroll.ts` - Auto-scroll behavior for the message list
|
|
51
|
+
|
|
52
|
+
### Support Modules
|
|
53
|
+
|
|
54
|
+
- `components/bootstrap.ts` - react-bootstrap component wrappers
|
|
55
|
+
- `components/icons.tsx` - Self-contained microphone icons
|
|
56
|
+
- `utils/scrollUtils.ts` - Diff scrolling and accessibility helpers
|
|
57
|
+
- `props.ts` - Public prop and callback types
|
|
43
58
|
|
|
44
59
|
### Styles
|
|
45
60
|
|
|
46
|
-
- `styles.scss` - Main component styles
|
|
47
|
-
- `DiffView.scss` - Diff viewer styles
|
|
61
|
+
- `components/styles.scss` - Main component styles
|
|
62
|
+
- `components/DiffView.scss` - Diff viewer styles
|
|
63
|
+
- `components/Spinner.scss` - Spinner styles
|
|
48
64
|
|
|
49
65
|
## Dependencies
|
|
50
66
|
|
|
51
|
-
Currently depends on:
|
|
52
|
-
|
|
53
67
|
- React and React hooks
|
|
54
|
-
-
|
|
55
|
-
- VZCode types: `../../types.js`
|
|
56
|
-
- VZCode utilities: `../../client/hooks/*`, `../../utils/*`
|
|
57
|
-
- Bootstrap components
|
|
68
|
+
- react-bootstrap
|
|
58
69
|
- diff2html for diff rendering
|
|
59
70
|
- react-markdown for message rendering
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
This module will eventually be:
|
|
64
|
-
|
|
65
|
-
1. Decoupled from VZCode-specific context and utilities
|
|
66
|
-
2. Published as `@vizhub/llm-streaming-ui` on npm
|
|
67
|
-
3. Made themeable and customizable
|
|
68
|
-
4. Provided with Storybook documentation
|
|
69
|
-
5. Fully typed with exported TypeScript interfaces
|
|
70
|
-
|
|
71
|
-
See the [main issue](https://github.com/vizhub-core/vzcode/issues/XXX) for the full extraction plan.
|
|
71
|
+
- `@vizhub/viz-types` for chat/content types
|
|
72
|
+
- Shared, framework-agnostic VZCode utilities: `../types.js`
|
|
73
|
+
and `../utils/fileDiff`
|
|
72
74
|
|
|
73
75
|
## Usage (Current)
|
|
74
76
|
|
|
75
|
-
|
|
77
|
+
`src/client/VZSidebar/index.tsx` renders `AIChatWrapper`, which passes
|
|
78
|
+
`VZCodeContext` state and callbacks into the standalone `AIChat`:
|
|
76
79
|
|
|
77
80
|
```typescript
|
|
78
|
-
import { AIChat } from '../../llm-streaming-ui
|
|
81
|
+
import { AIChat } from '../../llm-streaming-ui';
|
|
79
82
|
```
|
|
80
83
|
|
|
81
|
-
|
|
84
|
+
```tsx
|
|
85
|
+
<AIChat
|
|
86
|
+
content={content}
|
|
87
|
+
aiChatMode={aiChatMode}
|
|
88
|
+
handleSendMessage={handleSendMessage}
|
|
89
|
+
// ...chat state, callbacks, feature flags
|
|
90
|
+
/>
|
|
91
|
+
```
|
|
82
92
|
|
|
83
|
-
|
|
84
|
-
- Message sending handlers
|
|
85
|
-
- Auto-scroll configuration
|
|
93
|
+
See `AIChatProps` in `props.ts` for the full contract.
|
|
86
94
|
|
|
87
95
|
## Contributing
|
|
88
96
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
-
|
|
92
|
-
-
|
|
93
|
-
- Update component tests when modifying functionality
|
|
94
|
-
- Consider future consumers when adding new dependencies
|
|
95
|
-
- Document component props and behavior
|
|
97
|
+
- Keep the library free of imports from `src/client`
|
|
98
|
+
- Prefer props over context for all host interaction
|
|
99
|
+
- Add or update tests when changing behavior
|
|
100
|
+
- Document new props and side effects
|
|
96
101
|
|
|
97
102
|
## Theming
|
|
98
103
|
|
|
99
|
-
The components currently use VZCode's theming system via SCSS variables.
|
|
100
|
-
|
|
101
|
-
- CSS custom properties for theming
|
|
102
|
-
- Light/dark theme presets
|
|
103
|
-
- Customizable component styling
|
|
104
|
+
The components currently use VZCode's theming system via SCSS variables.
|
|
105
|
+
Future versions will provide CSS custom properties and theme presets.
|
|
@@ -9,20 +9,17 @@ import {
|
|
|
9
9
|
Button,
|
|
10
10
|
ButtonGroup,
|
|
11
11
|
ToggleButton,
|
|
12
|
-
} from '
|
|
13
|
-
import {
|
|
14
|
-
enableAskMode,
|
|
15
|
-
enableVoiceInput,
|
|
16
|
-
} from '../../client/featureFlags';
|
|
12
|
+
} from './bootstrap';
|
|
17
13
|
import { useSpeechRecognition } from './useSpeechRecognition';
|
|
18
|
-
import { MicSVG, MicOffSVG } from '
|
|
14
|
+
import { MicSVG, MicOffSVG } from './icons';
|
|
15
|
+
import type { ChatInputProps } from '../props';
|
|
19
16
|
|
|
20
17
|
/**
|
|
21
18
|
* Microphone toggle for voice typing. Purely presentational: the
|
|
22
19
|
* speech recognition state lives in `ChatInputComponent`, and is only
|
|
23
20
|
* ever instantiated when the user actually toggles the button.
|
|
24
21
|
*
|
|
25
|
-
* Rendered only when `enableVoiceInput` is set. See `
|
|
22
|
+
* Rendered only when `enableVoiceInput` is set. See `props`.
|
|
26
23
|
*/
|
|
27
24
|
const VoiceInputButton = ({
|
|
28
25
|
isSpeaking,
|
|
@@ -54,18 +51,6 @@ const VoiceInputButton = ({
|
|
|
54
51
|
);
|
|
55
52
|
};
|
|
56
53
|
|
|
57
|
-
interface ChatInputProps {
|
|
58
|
-
aiChatMessage: string;
|
|
59
|
-
setAIChatMessage: (message: string) => void;
|
|
60
|
-
onSendMessage: () => void;
|
|
61
|
-
focused: boolean;
|
|
62
|
-
aiChatMode: 'ask' | 'edit';
|
|
63
|
-
setAIChatMode: (mode: 'ask' | 'edit') => void;
|
|
64
|
-
navigateMessageHistoryUp: () => void;
|
|
65
|
-
navigateMessageHistoryDown: () => void;
|
|
66
|
-
resetMessageHistoryNavigation: () => void;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
54
|
const ChatInputComponent = ({
|
|
70
55
|
aiChatMessage,
|
|
71
56
|
setAIChatMessage,
|
|
@@ -76,6 +61,8 @@ const ChatInputComponent = ({
|
|
|
76
61
|
navigateMessageHistoryUp,
|
|
77
62
|
navigateMessageHistoryDown,
|
|
78
63
|
resetMessageHistoryNavigation,
|
|
64
|
+
enableAskMode = false,
|
|
65
|
+
enableVoiceInput = false,
|
|
79
66
|
}: ChatInputProps) => {
|
|
80
67
|
const inputRef = useRef<HTMLTextAreaElement>(null);
|
|
81
68
|
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import React, {
|
|
2
|
-
useContext,
|
|
3
2
|
useEffect,
|
|
4
3
|
useRef,
|
|
5
4
|
forwardRef,
|
|
6
5
|
useImperativeHandle,
|
|
7
6
|
} from 'react';
|
|
8
7
|
import {
|
|
9
|
-
UnifiedFilesDiff,
|
|
10
8
|
parseUnifiedDiffStats,
|
|
11
9
|
combineUnifiedDiffs,
|
|
12
10
|
isFileDeletion,
|
|
@@ -15,17 +13,12 @@ import {
|
|
|
15
13
|
import * as Diff2Html from 'diff2html';
|
|
16
14
|
import 'diff2html/bundles/css/diff2html.min.css';
|
|
17
15
|
import './DiffView.scss';
|
|
18
|
-
import { VZCodeContext } from '../../client/VZCodeContext';
|
|
19
16
|
import {
|
|
20
17
|
scrollToFirstDiff,
|
|
21
18
|
getHeaderOffset,
|
|
22
19
|
announceDiffSummary,
|
|
23
|
-
} from '
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
interface DiffViewProps {
|
|
27
|
-
diffData: UnifiedFilesDiff;
|
|
28
|
-
}
|
|
20
|
+
} from '../utils/scrollUtils';
|
|
21
|
+
import type { DiffViewProps } from '../props';
|
|
29
22
|
|
|
30
23
|
// Methods that can be called on DiffView from parent components
|
|
31
24
|
export interface DiffViewRef {
|
|
@@ -38,9 +31,7 @@ export interface DiffViewRef {
|
|
|
38
31
|
export const DiffView = forwardRef<
|
|
39
32
|
DiffViewRef,
|
|
40
33
|
DiffViewProps
|
|
41
|
-
>(({ diffData }, ref) => {
|
|
42
|
-
const { content, openTab, setIsAIChatOpen } =
|
|
43
|
-
useContext(VZCodeContext);
|
|
34
|
+
>(({ diffData, onOpenFile }, ref) => {
|
|
44
35
|
const diffContainerRef = useRef<HTMLDivElement>(null);
|
|
45
36
|
|
|
46
37
|
const allDiffs = Object.values(diffData).filter(
|
|
@@ -124,19 +115,10 @@ export const DiffView = forwardRef<
|
|
|
124
115
|
event.preventDefault();
|
|
125
116
|
event.stopPropagation();
|
|
126
117
|
|
|
127
|
-
console.log('File name clicked');
|
|
128
|
-
|
|
129
118
|
const fileName = target.textContent?.trim();
|
|
130
119
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const fileId = getFileId(content, fileName);
|
|
134
|
-
|
|
135
|
-
if (fileId) {
|
|
136
|
-
// Open the file tab and switch to files view
|
|
137
|
-
openTab({ fileId, isTransient: false });
|
|
138
|
-
setIsAIChatOpen(false);
|
|
139
|
-
}
|
|
120
|
+
if (fileName && onOpenFile) {
|
|
121
|
+
onOpenFile(fileName);
|
|
140
122
|
}
|
|
141
123
|
}
|
|
142
124
|
};
|
|
@@ -167,7 +149,7 @@ export const DiffView = forwardRef<
|
|
|
167
149
|
);
|
|
168
150
|
});
|
|
169
151
|
};
|
|
170
|
-
}, [diffHtml,
|
|
152
|
+
}, [diffHtml, onOpenFile]);
|
|
171
153
|
|
|
172
154
|
if (allDiffs.length === 0) {
|
|
173
155
|
return null;
|