vzcode 1.38.0 → 1.40.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.
Files changed (35) hide show
  1. package/dist/assets/{index-Cw7RI1uP.js → index-ubSLcdJf.js} +91 -91
  2. package/dist/index.html +1 -1
  3. package/package.json +9 -7
  4. package/src/client/CodeEditor/getOrCreateEditor.ts +0 -3
  5. package/src/client/CodeEditor/index.tsx +0 -1
  6. package/src/client/CodeEditor/json1PresenceDisplay.ts +28 -58
  7. package/src/client/VZCodeContext.tsx +11 -0
  8. package/src/client/VZSidebar/index.tsx +6 -0
  9. package/src/client/useKeyboardShortcuts.ts +7 -1
  10. package/src/client/usePresenceAutoFollow.ts +85 -0
  11. package/src/client/useRunCode.tsx +2 -16
  12. package/src/client/useSubmitOperation.ts +4 -11
  13. package/src/runCode.js +48 -0
  14. package/src/runCode.ts +58 -0
  15. package/src/server/aiChatHandler/aiEditing.ts +44 -0
  16. package/src/server/aiChatHandler/{chatOperations.js → chatOperations.ts} +135 -7
  17. package/src/server/aiChatHandler/{index.js → index.ts} +34 -30
  18. package/src/server/aiChatHandler/llmStreaming.ts +223 -0
  19. package/src/server/{generateAIResponse.js → generateAIResponse.ts} +3 -2
  20. package/src/server/{handleAIAssist.js → handleAIAssist.ts} +11 -4
  21. package/src/server/{index.js → index.ts} +31 -27
  22. package/src/submitOperation.js +16 -0
  23. package/src/submitOperation.ts +25 -0
  24. package/src/server/aiChatHandler/aiEditing.js +0 -42
  25. package/src/server/aiChatHandler/llmStreaming.js +0 -105
  26. /package/src/server/aiChatHandler/{errorHandling.js → errorHandling.ts} +0 -0
  27. /package/src/server/aiChatHandler/{validation.js → validation.ts} +0 -0
  28. /package/src/server/{computeInitialDocument.js → computeInitialDocument.ts} +0 -0
  29. /package/src/server/{config.js → config.ts} +0 -0
  30. /package/src/server/{featureFlags.js → featureFlags.ts} +0 -0
  31. /package/src/server/{handleAIChatMessage.js → handleAIChatMessage.ts} +0 -0
  32. /package/src/server/{handleAICopilot.js → handleAICopilot.ts} +0 -0
  33. /package/src/server/{isDirectory.js → isDirectory.ts} +0 -0
  34. /package/src/server/{livekit.js → livekit.ts} +0 -0
  35. /package/src/server/{setupEnv.js → setupEnv.ts} +0 -0
@@ -1,42 +0,0 @@
1
- import { performAiEdit } from 'editcodewithai';
2
- import {
3
- clearAIScratchpadAndStatus,
4
- updateFiles,
5
- setIsInteracting,
6
- } from './chatOperations.js';
7
-
8
- /**
9
- * Performs AI editing operations on the files
10
- */
11
- export const performAIEditing = async (
12
- shareDBDoc,
13
- chatId,
14
- content,
15
- files,
16
- llmFunction,
17
- ) => {
18
- const editResult = await performAiEdit({
19
- prompt: content,
20
- files,
21
- llmFunction,
22
- apiKey: process.env.VIZHUB_EDIT_WITH_AI_API_KEY,
23
- });
24
-
25
- // Clear the scratchpad and update status
26
- clearAIScratchpadAndStatus(
27
- shareDBDoc,
28
- chatId,
29
- 'Done editing with AI.',
30
- );
31
-
32
- // Apply AI edits to files
33
- updateFiles(shareDBDoc, editResult.changedFiles);
34
-
35
- // Wait for propagation
36
- await new Promise((resolve) => setTimeout(resolve, 100));
37
-
38
- // Unset isInteracting
39
- setIsInteracting(shareDBDoc, false);
40
-
41
- return editResult;
42
- };
@@ -1,105 +0,0 @@
1
- import { StreamingMarkdownParser } from 'llm-code-format';
2
- import { ChatOpenAI } from '@langchain/openai';
3
- import {
4
- updateAIStatus,
5
- updateAIScratchpad,
6
- } from './chatOperations.js';
7
-
8
- const debug = false;
9
-
10
- /**
11
- * Creates and configures the LLM function for streaming
12
- */
13
- export const createLLMFunction = (shareDBDoc, chatId) => {
14
- return async (fullPrompt) => {
15
- const chatModel = new ChatOpenAI({
16
- modelName:
17
- process.env.VIZHUB_EDIT_WITH_AI_MODEL_NAME ||
18
- 'anthropic/claude-sonnet-4',
19
- configuration: {
20
- apiKey: process.env.VIZHUB_EDIT_WITH_AI_API_KEY,
21
- baseURL: process.env.VIZHUB_EDIT_WITH_AI_BASE_URL,
22
- defaultHeaders: {
23
- 'HTTP-Referer': 'https://vizhub.com',
24
- 'X-Title': 'VizHub',
25
- },
26
- },
27
- streaming: true,
28
- });
29
-
30
- let fullContent = '';
31
- let generationId = '';
32
-
33
- // Track expected state to avoid race conditions
34
- let expectedAiScratchpad =
35
- shareDBDoc.data.chats[chatId]?.aiScratchpad || '';
36
-
37
- // Throttle updates to avoid "op too long" errors
38
- let lastUpdateTime = 0;
39
- const UPDATE_THROTTLE_MS = 100;
40
-
41
- // Define callbacks for streaming parser
42
- const callbacks = {
43
- onFileNameChange: (fileName, format) => {
44
- debug &&
45
- console.log(
46
- `File changed to: ${fileName} (${format})`,
47
- );
48
- updateAIStatus(
49
- shareDBDoc,
50
- chatId,
51
- 'Editing ' + fileName,
52
- );
53
- },
54
- onCodeLine: (line) => {
55
- debug && console.log(`Code line: ${line}`);
56
- },
57
- onNonCodeLine: (line) => {
58
- debug && console.log(`Comment/text: ${line}`);
59
- },
60
- };
61
-
62
- const parser = new StreamingMarkdownParser(callbacks);
63
-
64
- // Stream the response
65
- const stream = await chatModel.stream(fullPrompt);
66
- for await (const chunk of stream) {
67
- if (chunk.content) {
68
- const chunkContent = String(chunk.content);
69
- fullContent += chunkContent;
70
-
71
- // Throttle updates
72
- const now = Date.now();
73
- const shouldUpdate =
74
- now - lastUpdateTime >= UPDATE_THROTTLE_MS;
75
-
76
- if (shouldUpdate) {
77
- updateAIScratchpad(
78
- shareDBDoc,
79
- chatId,
80
- fullContent,
81
- );
82
- expectedAiScratchpad = fullContent;
83
- lastUpdateTime = now;
84
- }
85
-
86
- parser.processChunk(chunkContent);
87
- }
88
-
89
- if (!generationId && chunk.lc_kwargs?.id) {
90
- generationId = chunk.lc_kwargs.id;
91
- }
92
- }
93
- parser.flushRemaining();
94
-
95
- // Submit final update if there's pending content
96
- if (expectedAiScratchpad !== fullContent) {
97
- updateAIScratchpad(shareDBDoc, chatId, fullContent);
98
- }
99
-
100
- return {
101
- content: fullContent,
102
- generationId: generationId,
103
- };
104
- };
105
- };
File without changes
File without changes
File without changes
File without changes
File without changes