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,71 @@
|
|
|
1
|
+
# LLM Streaming Server
|
|
2
|
+
|
|
3
|
+
Server-side library for streaming LLM responses with ShareDB integration.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This module is being extracted from VZCode's AI chat functionality to become a standalone, reusable library. It provides server-side functionality for:
|
|
8
|
+
|
|
9
|
+
- **LLM Streaming**: Creating and managing streaming LLM functions with OpenAI/OpenRouter
|
|
10
|
+
- **AI Code Editing**: Performing AI-assisted code transformations and edits
|
|
11
|
+
- **ShareDB Integration**: Managing chat operations and real-time collaboration
|
|
12
|
+
- **Request Validation**: Validating incoming AI chat requests
|
|
13
|
+
- **Error Handling**: Handling errors gracefully in streaming contexts
|
|
14
|
+
|
|
15
|
+
## Current Status
|
|
16
|
+
|
|
17
|
+
⚠️ **Work in Progress**: This is Phase 1 of the extraction plan. The files have been copied to this directory and imports have been updated, but the code is not yet decoupled from VZCode.
|
|
18
|
+
|
|
19
|
+
## Files
|
|
20
|
+
|
|
21
|
+
- `index.ts` - Main entry point exporting all public APIs
|
|
22
|
+
- `llmStreaming.ts` - Core LLM streaming functionality with OpenAI/OpenRouter
|
|
23
|
+
- `aiEditing.ts` - AI-assisted code editing operations
|
|
24
|
+
- `chatOperations.ts` - ShareDB chat operations (messages, events, streaming)
|
|
25
|
+
- `validation.ts` - Request validation utilities
|
|
26
|
+
- `errorHandling.ts` - Error handling for streaming contexts
|
|
27
|
+
|
|
28
|
+
## Dependencies
|
|
29
|
+
|
|
30
|
+
Currently depends on:
|
|
31
|
+
|
|
32
|
+
- `openai` - OpenAI SDK for LLM interactions
|
|
33
|
+
- `sharedb` - Real-time collaborative editing framework
|
|
34
|
+
- `llm-code-format` - Markdown parsing for code blocks
|
|
35
|
+
- `editcodewithai` - Code editing utilities
|
|
36
|
+
- VZCode utilities: `../types.js`, `../ot.js`, `../randomId.js`, etc.
|
|
37
|
+
|
|
38
|
+
## Future Plans
|
|
39
|
+
|
|
40
|
+
This module will eventually be:
|
|
41
|
+
|
|
42
|
+
1. Decoupled from VZCode-specific types and utilities
|
|
43
|
+
2. Published as `@vizhub/llm-streaming-server` on npm
|
|
44
|
+
3. Made framework-agnostic (can work with Express, Fastify, etc.)
|
|
45
|
+
4. Fully documented with usage examples
|
|
46
|
+
|
|
47
|
+
See the [main issue](https://github.com/vizhub-core/vzcode/issues/XXX) for the full extraction plan.
|
|
48
|
+
|
|
49
|
+
## Usage (Current)
|
|
50
|
+
|
|
51
|
+
Currently, this module is imported by `src/server/aiChatHandler/index.ts`:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { createLLMFunction } from '../../llm-streaming-server/llmStreaming.js';
|
|
55
|
+
import { performAIEditing } from '../../llm-streaming-server/aiEditing.js';
|
|
56
|
+
import {
|
|
57
|
+
ensureChatsExist,
|
|
58
|
+
ensureChatExists,
|
|
59
|
+
addUserMessage,
|
|
60
|
+
setAIStatus,
|
|
61
|
+
} from '../../llm-streaming-server/chatOperations.js';
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Contributing
|
|
65
|
+
|
|
66
|
+
As this module is being extracted, please:
|
|
67
|
+
|
|
68
|
+
- Keep changes minimal and focused
|
|
69
|
+
- Maintain backward compatibility with VZCode
|
|
70
|
+
- Update tests when modifying functionality
|
|
71
|
+
- Document any new dependencies or breaking changes
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assembleFullPrompt,
|
|
3
|
+
prepareFilesForPrompt,
|
|
4
|
+
} from 'editcodewithai';
|
|
5
|
+
import { formatMarkdownFiles } from 'llm-code-format';
|
|
6
|
+
import {
|
|
7
|
+
createFilesSnapshot,
|
|
8
|
+
generateFilesUnifiedDiff,
|
|
9
|
+
} from '../utils/fileDiff.js';
|
|
10
|
+
|
|
11
|
+
// Dev flag for waiting 1 second before starting the LLM function.
|
|
12
|
+
// Useful for debugging and testing purposes, e.g. checking the typing indicator.
|
|
13
|
+
const delayStart = false;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Performs AI chat without editing - just generates a response
|
|
17
|
+
*/
|
|
18
|
+
export const performAIChat = async ({
|
|
19
|
+
prompt,
|
|
20
|
+
shareDBDoc,
|
|
21
|
+
llmFunction,
|
|
22
|
+
}) => {
|
|
23
|
+
const { files } = prepareFilesForPrompt(
|
|
24
|
+
shareDBDoc.data.files,
|
|
25
|
+
);
|
|
26
|
+
const filesContext = formatMarkdownFiles(files);
|
|
27
|
+
|
|
28
|
+
// 2. Assemble the final prompt for Q&A mode
|
|
29
|
+
const fullPrompt = assembleFullPrompt({
|
|
30
|
+
filesContext,
|
|
31
|
+
prompt,
|
|
32
|
+
editFormat: 'whole',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (delayStart) {
|
|
36
|
+
await new Promise((resolve) =>
|
|
37
|
+
setTimeout(resolve, 1000),
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Call the LLM function which will handle streaming but won't edit files
|
|
42
|
+
const result = await llmFunction(fullPrompt);
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
content: result.content,
|
|
46
|
+
generationId: result.generationId,
|
|
47
|
+
diffData: {}, // No file changes in ask mode
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Performs AI editing operations using streaming with incremental OT operations
|
|
53
|
+
*/
|
|
54
|
+
export const performAIEditing = async ({
|
|
55
|
+
prompt,
|
|
56
|
+
shareDBDoc,
|
|
57
|
+
llmFunction,
|
|
58
|
+
runCode,
|
|
59
|
+
}) => {
|
|
60
|
+
// Capture the current state of files before editing
|
|
61
|
+
const beforeFiles = createFilesSnapshot(
|
|
62
|
+
shareDBDoc.data.files,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const { files } = prepareFilesForPrompt(
|
|
66
|
+
shareDBDoc.data.files,
|
|
67
|
+
);
|
|
68
|
+
const filesContext = formatMarkdownFiles(files);
|
|
69
|
+
|
|
70
|
+
// Assemble the final prompt
|
|
71
|
+
const fullPrompt = assembleFullPrompt({
|
|
72
|
+
filesContext,
|
|
73
|
+
prompt,
|
|
74
|
+
editFormat: 'whole',
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (delayStart) {
|
|
78
|
+
await new Promise((resolve) =>
|
|
79
|
+
setTimeout(resolve, 1000),
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Call the LLM function which will handle streaming, incremental file updates, and Prettier formatting
|
|
84
|
+
const result = await llmFunction(fullPrompt);
|
|
85
|
+
|
|
86
|
+
runCode();
|
|
87
|
+
|
|
88
|
+
// 4. Capture the state of files after editing and formatting, then generate diff
|
|
89
|
+
const afterFiles = createFilesSnapshot(
|
|
90
|
+
shareDBDoc.data.files,
|
|
91
|
+
);
|
|
92
|
+
const diffData = generateFilesUnifiedDiff(
|
|
93
|
+
beforeFiles,
|
|
94
|
+
afterFiles,
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
content: result.content,
|
|
99
|
+
generationId: result.generationId,
|
|
100
|
+
diffData,
|
|
101
|
+
};
|
|
102
|
+
};
|