vzcode 2.21.0 → 2.22.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 +359 -0
- package/dist/assets/{index-D6-he0oi.js → index-CfDs-dAu.js} +99 -99
- package/dist/assets/{index-fYq6iaqF.css → index-fSroLVgi.css} +1 -1
- package/dist/index.html +2 -2
- package/dist/llm-streaming-server/aiEditing.js +58 -0
- package/dist/llm-streaming-server/chatOperations.js +494 -0
- package/dist/llm-streaming-server/errorHandling.js +49 -0
- package/dist/llm-streaming-server/index.js +20 -0
- package/dist/llm-streaming-server/llmStreaming.js +265 -0
- package/dist/llm-streaming-server/validation.js +19 -0
- package/dist/server/aiChatHandler/index.js +5 -5
- package/package.json +35 -35
- package/src/client/CodeEditor/getOrCreateEditor.tsx +20 -13
- package/src/client/CodeEditor/index.tsx +3 -3
- package/src/client/VZSidebar/AIChat/styles.scss +38 -0
- package/src/client/VZSidebar/FileTypeIcon.tsx +1 -0
- package/src/client/VZSidebar/index.tsx +1 -1
- package/src/llm-streaming-server/README.md +71 -0
- package/src/llm-streaming-server/aiEditing.ts +102 -0
- package/src/llm-streaming-server/chatOperations.ts +655 -0
- package/src/llm-streaming-server/errorHandling.ts +66 -0
- package/src/llm-streaming-server/index.ts +51 -0
- package/src/llm-streaming-server/llmStreaming.ts +403 -0
- package/src/llm-streaming-server/validation.ts +24 -0
- package/src/llm-streaming-ui/README.md +103 -0
- package/src/llm-streaming-ui/components/ChatInput.tsx +237 -0
- package/src/llm-streaming-ui/components/DiffView.scss +173 -0
- package/src/llm-streaming-ui/components/DiffView.tsx +236 -0
- package/src/llm-streaming-ui/components/FileEditingIndicator.tsx +89 -0
- package/src/llm-streaming-ui/components/IndividualFileDiff.tsx +86 -0
- package/src/llm-streaming-ui/components/JumpToLatestButton.tsx +64 -0
- package/src/llm-streaming-ui/components/Message.tsx +145 -0
- package/src/llm-streaming-ui/components/MessageList.tsx +241 -0
- package/src/llm-streaming-ui/components/ThinkingScratchpad.tsx +42 -0
- package/src/llm-streaming-ui/components/TypingIndicator.tsx +19 -0
- package/src/llm-streaming-ui/components/index.tsx +388 -0
- package/src/llm-streaming-ui/components/styles.scss +831 -0
- package/src/llm-streaming-ui/components/useSpeechRecognition.ts +116 -0
- package/src/llm-streaming-ui/index.ts +34 -0
- package/src/server/aiChatHandler/index.ts +5 -5
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useState,
|
|
3
|
+
useEffect,
|
|
4
|
+
useCallback,
|
|
5
|
+
Dispatch,
|
|
6
|
+
SetStateAction,
|
|
7
|
+
} from 'react';
|
|
8
|
+
|
|
9
|
+
export interface UseSpeechRecognitionResult {
|
|
10
|
+
isSpeaking: boolean;
|
|
11
|
+
toggleSpeechRecognition: () => void;
|
|
12
|
+
stopSpeaking: () => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const useSpeechRecognition = (
|
|
16
|
+
onTranscriptChange: Dispatch<SetStateAction<string>>,
|
|
17
|
+
): UseSpeechRecognitionResult => {
|
|
18
|
+
const [isSpeaking, setIsSpeaking] =
|
|
19
|
+
useState<boolean>(false);
|
|
20
|
+
const [recognition, setRecognition] =
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
useState<SpeechRecognition | null>(null);
|
|
23
|
+
const [, setFinalTranscript] = useState<string>('');
|
|
24
|
+
|
|
25
|
+
// Speech recognition setup
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
// Check if browser supports SpeechRecognition
|
|
28
|
+
const SpeechRecognition =
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
window.SpeechRecognition ||
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
window.webkitSpeechRecognition;
|
|
33
|
+
|
|
34
|
+
if (SpeechRecognition) {
|
|
35
|
+
const recognitionInstance = new SpeechRecognition();
|
|
36
|
+
recognitionInstance.continuous = true;
|
|
37
|
+
recognitionInstance.interimResults = true;
|
|
38
|
+
|
|
39
|
+
recognitionInstance.onresult = (event) => {
|
|
40
|
+
let finalText = '';
|
|
41
|
+
let interimText = '';
|
|
42
|
+
|
|
43
|
+
// Process all results to separate final and interim text
|
|
44
|
+
for (let i = 0; i < event.results.length; i++) {
|
|
45
|
+
const result = event.results[i];
|
|
46
|
+
if (result.isFinal) {
|
|
47
|
+
finalText += result[0].transcript;
|
|
48
|
+
} else {
|
|
49
|
+
interimText += result[0].transcript;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Update our final transcript state
|
|
54
|
+
setFinalTranscript(finalText);
|
|
55
|
+
|
|
56
|
+
// Combine final and interim text and update the prompt
|
|
57
|
+
const fullTranscript = finalText + interimText;
|
|
58
|
+
onTranscriptChange(fullTranscript);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
recognitionInstance.onerror = (event) => {
|
|
62
|
+
console.error(
|
|
63
|
+
'Speech recognition error',
|
|
64
|
+
event.error,
|
|
65
|
+
);
|
|
66
|
+
setIsSpeaking(false);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
recognitionInstance.onend = () => {
|
|
70
|
+
setIsSpeaking(false);
|
|
71
|
+
// Reset final transcript when recognition ends
|
|
72
|
+
setFinalTranscript('');
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
setRecognition(recognitionInstance);
|
|
76
|
+
|
|
77
|
+
return () => {
|
|
78
|
+
recognitionInstance.abort();
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}, [onTranscriptChange]);
|
|
82
|
+
|
|
83
|
+
const toggleSpeechRecognition = useCallback(() => {
|
|
84
|
+
if (!recognition) {
|
|
85
|
+
console.error(
|
|
86
|
+
'Speech recognition not supported in this browser',
|
|
87
|
+
);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (isSpeaking) {
|
|
92
|
+
recognition.stop();
|
|
93
|
+
setIsSpeaking(false);
|
|
94
|
+
} else {
|
|
95
|
+
// Reset final transcript when starting new recognition
|
|
96
|
+
setFinalTranscript('');
|
|
97
|
+
recognition.start();
|
|
98
|
+
setIsSpeaking(true);
|
|
99
|
+
}
|
|
100
|
+
}, [isSpeaking, recognition]);
|
|
101
|
+
|
|
102
|
+
const stopSpeaking = useCallback(() => {
|
|
103
|
+
if (recognition && isSpeaking) {
|
|
104
|
+
recognition.stop();
|
|
105
|
+
setIsSpeaking(false);
|
|
106
|
+
// Reset final transcript when manually stopping
|
|
107
|
+
setFinalTranscript('');
|
|
108
|
+
}
|
|
109
|
+
}, [isSpeaking, recognition]);
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
isSpeaking,
|
|
113
|
+
toggleSpeechRecognition,
|
|
114
|
+
stopSpeaking,
|
|
115
|
+
};
|
|
116
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vizhub/llm-streaming-ui
|
|
3
|
+
*
|
|
4
|
+
* Client-side React UI components for displaying streaming AI edits and chat.
|
|
5
|
+
* This module provides functionality for:
|
|
6
|
+
* - Displaying AI chat messages with streaming support
|
|
7
|
+
* - Showing real-time diffs and code changes
|
|
8
|
+
* - Rendering thinking/reasoning scratchpads
|
|
9
|
+
* - Managing file editing indicators
|
|
10
|
+
* - Voice input support
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// Main AI Chat component
|
|
14
|
+
export { AIChat } from './components/index.js';
|
|
15
|
+
|
|
16
|
+
// Message display components
|
|
17
|
+
export { MessageList } from './components/MessageList.js';
|
|
18
|
+
export { Message } from './components/Message.js';
|
|
19
|
+
|
|
20
|
+
// Diff visualization components
|
|
21
|
+
export { DiffView } from './components/DiffView.js';
|
|
22
|
+
export { IndividualFileDiff } from './components/IndividualFileDiff.js';
|
|
23
|
+
|
|
24
|
+
// Status and indicator components
|
|
25
|
+
export { TypingIndicator } from './components/TypingIndicator.js';
|
|
26
|
+
export { ThinkingScratchpad } from './components/ThinkingScratchpad.js';
|
|
27
|
+
export { AIEditingStatusIndicator as FileEditingIndicator } from './components/FileEditingIndicator';
|
|
28
|
+
export { JumpToLatestButton } from './components/JumpToLatestButton.js';
|
|
29
|
+
|
|
30
|
+
// Input components
|
|
31
|
+
export { ChatInput } from './components/ChatInput.js';
|
|
32
|
+
|
|
33
|
+
// Custom hooks
|
|
34
|
+
export { useSpeechRecognition } from './components/useSpeechRecognition.js';
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { validateRequest } from '
|
|
1
|
+
import { validateRequest } from '../../llm-streaming-server/validation.js';
|
|
2
2
|
import {
|
|
3
3
|
ensureChatsExist,
|
|
4
4
|
ensureChatExists,
|
|
5
5
|
addUserMessage,
|
|
6
6
|
setAIStatus,
|
|
7
|
-
} from '
|
|
8
|
-
import { createLLMFunction } from '
|
|
9
|
-
import { performAIEditing } from '
|
|
7
|
+
} from '../../llm-streaming-server/chatOperations.js';
|
|
8
|
+
import { createLLMFunction } from '../../llm-streaming-server/llmStreaming.js';
|
|
9
|
+
import { performAIEditing } from '../../llm-streaming-server/aiEditing.js';
|
|
10
10
|
import {
|
|
11
11
|
handleError,
|
|
12
12
|
handleBackgroundError,
|
|
13
|
-
} from '
|
|
13
|
+
} from '../../llm-streaming-server/errorHandling.js';
|
|
14
14
|
import { createRunCodeFunction } from '../../runCode.js';
|
|
15
15
|
import { ShareDBDoc } from '../../types.js';
|
|
16
16
|
import { VizContent } from '@vizhub/viz-types';
|