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.
Files changed (52) hide show
  1. package/dist/assets/buildWorker-BZlya278.js +687 -0
  2. package/dist/assets/index-Cj-ERpBu.css +1 -0
  3. package/dist/assets/index-DD7vzp4U.js +364 -0
  4. package/dist/assets/{worker-D8p1JlHW.js → worker-1oQYaz-F.js} +251 -251
  5. package/dist/assets/worker-BfgPD8zR.js +125 -0
  6. package/dist/assets/{worker-k7HZ3t-V.js → worker-CoJaqtpi.js} +12 -12
  7. package/dist/index.html +2 -2
  8. package/dist/ot.js +180 -2
  9. package/dist/server/createServer.js +281 -0
  10. package/dist/server/index.js +6 -269
  11. package/package.json +14 -3
  12. package/src/client/CodeEditor/getOrCreateEditor.tsx +0 -14
  13. package/src/client/VZCodeContext/chatSessionHelpers.ts +17 -0
  14. package/src/client/VZCodeContext/useAIChatSession.ts +325 -0
  15. package/src/client/VZCodeContext/useVZCodeState.ts +23 -279
  16. package/src/client/VZSidebar/AIChatWrapper.tsx +85 -0
  17. package/src/client/VZSidebar/VisualEditor/VisualEditor.tsx +95 -208
  18. package/src/client/VZSidebar/VisualEditor/colorUtils.ts +39 -0
  19. package/src/client/VZSidebar/VisualEditor/status.ts +2 -40
  20. package/src/client/VZSidebar/VisualEditor/updateConfig.ts +10 -1
  21. package/src/client/VZSidebar/VisualEditor/utils.ts +49 -65
  22. package/src/client/VZSidebar/index.tsx +2 -2
  23. package/src/client/definitionJumpListeners.ts +47 -0
  24. package/src/client/useKeyboardShortcuts.ts +23 -28
  25. package/src/client/useOpenDirectories.ts +0 -1
  26. package/src/llm-streaming-server/README.md +5 -3
  27. package/src/llm-streaming-ui/README.md +44 -42
  28. package/src/llm-streaming-ui/components/ChatInput.tsx +6 -19
  29. package/src/llm-streaming-ui/components/DiffView.tsx +6 -24
  30. package/src/llm-streaming-ui/components/FileEditingIndicator.tsx +1 -1
  31. package/src/llm-streaming-ui/components/Message.tsx +11 -27
  32. package/src/llm-streaming-ui/components/MessageList.tsx +15 -29
  33. package/src/llm-streaming-ui/components/Spinner.scss +37 -0
  34. package/src/llm-streaming-ui/components/Spinner.tsx +59 -0
  35. package/src/llm-streaming-ui/components/bootstrap.ts +16 -0
  36. package/src/llm-streaming-ui/components/icons.tsx +68 -0
  37. package/src/llm-streaming-ui/components/index.tsx +34 -30
  38. package/src/llm-streaming-ui/index.ts +13 -0
  39. package/src/llm-streaming-ui/props.ts +137 -0
  40. package/src/ot.ts +221 -4
  41. package/src/server/createServer.ts +413 -0
  42. package/src/server/index.ts +8 -333
  43. package/dist/assets/buildWorker-DylWm2VX.js +0 -687
  44. package/dist/assets/index-Dyt9tpmu.css +0 -1
  45. package/dist/assets/index-nL6to42p.js +0 -364
  46. package/dist/assets/worker-b9bkZkXK.js +0 -116
  47. package/src/client/AIAssist/AIAssistCodeMirrorKeyMap.ts +0 -42
  48. package/src/client/AIAssist/generateFilesContext.ts +0 -25
  49. package/src/client/AIAssist/index.ts +0 -2
  50. package/src/client/CodeEditor/InteractiveWidgets/highlightWidgets.ts +0 -79
  51. /package/src/{client → llm-streaming-ui}/hooks/useAutoScroll.ts +0 -0
  52. /package/src/{client → llm-streaming-ui}/utils/scrollUtils.ts +0 -0
@@ -1,31 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import WebSocketJSONStream from '@teamwork/websocket-json-stream';
3
- import bodyParser from 'body-parser';
4
- import express from 'express';
5
- import fs from 'fs';
6
- import http from 'http';
7
2
  import open from 'open';
8
- import path from 'path';
9
- import ShareDB from 'sharedb';
10
- import { fileURLToPath } from 'url';
11
- import { WebSocketServer } from 'ws';
12
- import { json1Presence } from '../ot.js';
13
- import { computeInitialDocument } from './computeInitialDocument.js';
14
- import { handleAIAssist } from './handleAIAssist.js';
15
- import { handleAICopilot } from './handleAICopilot.js';
16
- import { handleAIChatMessage } from './handleAIChatMessage.js';
17
- import { isDirectory } from './isDirectory.js';
18
- import { createToken } from './livekit.js';
19
- import './setupEnv.js';
20
- // Import the image file utility
21
- const isImageFile = (fileName) => {
22
- return (fileName.match(/\.(png|jpg|jpeg|gif|bmp|svg|webp)$/i) !== null);
23
- };
24
- // The time in milliseconds by which auto-saving is debounced.
25
- const autoSaveDebounceTimeMS = 800;
26
- // The time in milliseconds by which auto-saving is throttled
27
- // when the user is interacting with the widgets in the editor.
28
- const throttleTimeMS = 100;
3
+ import { createVZCodeServer } from './createServer.js';
29
4
  // Helper function to get the port from command line arguments or use default.
30
5
  function getPortFromArgs(defaultPort = 3030) {
31
6
  const portArg = process.argv.find((arg) => arg.startsWith('--port='));
@@ -36,252 +11,14 @@ function getPortFromArgs(defaultPort = 3030) {
36
11
  }
37
12
  // Server port.
38
13
  const port = getPortFromArgs();
39
- const initialDocument = computeInitialDocument({
40
- // Use the current working directory to look for files.
41
- fullPath: process.cwd(),
14
+ const { ready, listen } = createVZCodeServer();
15
+ ready.catch((error) => {
16
+ console.error('Failed to initialize ShareDB document:', error);
42
17
  });
43
- // Register our custom OT type,
44
- // because it does not ship with ShareDB.
45
- ShareDB.types.register(json1Presence.type);
46
- const app = express();
47
- // Use ShareDB over WebSocket
48
- const shareDBBackend = new ShareDB({
49
- // Enable presence
50
- // See https://github.com/share/sharedb/blob/master/examples/rich-text-presence/server.js#L9
51
- presence: true,
52
- doNotForwardSendPresenceErrorsToClient: true,
53
- });
54
- const server = http.createServer(app);
55
- const wss = new WebSocketServer({ server });
56
- wss.on('connection', (ws) => {
57
- const clientStream = new WebSocketJSONStream(ws);
58
- shareDBBackend.listen(clientStream);
59
- // Prevent server crashes on errors.
60
- clientStream.on('error', (error) => {
61
- console.log('clientStream error: ' + error.message);
62
- });
63
- // Handle errors
64
- ws.on('error', (error) => {
65
- console.log('ws error: ' + error.message);
66
- });
67
- // Handle disconnections
68
- ws.on('close', () => {
69
- clientStream.end();
70
- });
71
- });
72
- // Serve static files
73
- const filename = fileURLToPath(import.meta.url);
74
- const dirname = path.dirname(filename);
75
- const dir = path.join(dirname, '..', '..', 'dist');
76
- app.use(express.static(dir));
77
- // Create the initial "document",
78
- // which is a representation of files on disk.
79
- const shareDBConnection = shareDBBackend.connect();
80
- const shareDBDoc = shareDBConnection.get('documents', '1');
81
- shareDBDoc.create(initialDocument, json1Presence.type.uri);
82
- // Handle AI Assist requests.
83
- app.post('/ai-assist', bodyParser.json(), handleAIAssist(shareDBDoc));
84
- // Handle AI Copilot requests.
85
- app.post('/ai-copilot', bodyParser.json(), handleAICopilot());
86
- // Handle AI Chat Message requests.
87
- app.post('/ai-chat-message', bodyParser.json(), handleAIChatMessage({
88
- shareDBDoc,
89
- onCreditDeduction: undefined,
90
- }));
91
- // Livekit Token Generator
92
- app.get('/livekit-token', async (req, res) => {
93
- const { room, username } = req.query;
94
- res.send(await createToken(room, username));
95
- });
96
- // The state of the document when files were last auto-saved.
97
- let previousDocument = initialDocument;
98
- // Saves the files that changed.
99
- const save = () => {
100
- const currentDocument = shareDBDoc.data;
101
- // Take a look at each file (key) previously and currently.
102
- const allKeys = Object.keys({
103
- ...currentDocument.files,
104
- ...previousDocument.files,
105
- });
106
- const directoriesToDelete = [];
107
- for (const key of allKeys) {
108
- const previous = previousDocument.files[key];
109
- const current = currentDocument.files[key];
110
- // If this file was neither created nor deleted...
111
- if (previous && current) {
112
- // Handle changing of text content.
113
- if (previous.text !== current.text) {
114
- if (isImageFile(current.name)) {
115
- // Write image files as binary from base64
116
- const buffer = Buffer.from(current.text, 'base64');
117
- fs.writeFileSync(current.name, buffer);
118
- }
119
- else {
120
- // Write non-image files as text
121
- fs.writeFileSync(current.name, current.text);
122
- }
123
- }
124
- // // Handle renaming files.
125
- // if (previous.name !== current.name) {
126
- // const previousPath = previous.name.split('/');
127
- // const currentPath = current.name.split('/');
128
- // // - If the path is length 1 for previous and current,
129
- // // then this should be true.
130
- // // - If the path length is the sane for previous and current,
131
- // // AND all the entries leading up to the last one are the same
132
- // // between previous and current, AND the last entry in the arrays
133
- // // (the file name itself) is different between previous and current
134
- // const onlyFileNameChanged =
135
- // (previousPath.length === 1 &&
136
- // currentPath.length === 1) ||
137
- // (previousPath.length === currentPath.length &&
138
- // previousPath
139
- // .slice(0, -1)
140
- // .every(
141
- // (val, index) => val === currentPath[index],
142
- // ) &&
143
- // previousPath.at(-1) !== currentPath.at(-1));
144
- // // This logic works if only the file name itself changes.
145
- // if (onlyFileNameChanged) {
146
- // fs.renameSync(previous.name, current.name);
147
- // }
148
- // {
149
- // // If we get here, then the directory may have been renamed,
150
- // // or the file has been moved between directories.
151
- // // If we get here, then the directory may have been renamed,
152
- // // or the file has been moved between directories.
153
- // const newDir = path.dirname(current.name);
154
- // // Check if the new directory exists, if not, create it
155
- // if (!fs.existsSync(newDir)) {
156
- // fs.mkdirSync(newDir, { recursive: true });
157
- // }
158
- // // Move the file to the new directory
159
- // fs.renameSync(previous.name, current.name);
160
- // }
161
- // }
162
- // Handle renaming files.
163
- if (previous.name !== current.name) {
164
- if (isDirectory(previous.name)) {
165
- // If the directory itself is being renamed,
166
- // Phase I: Ignore it, and get the files moved
167
- // Phase II: Keep track of these, and delete them after
168
- // all the files moved.
169
- // directoriesToDelete.push(previous.name)
170
- directoriesToDelete.push(previous.name);
171
- }
172
- else {
173
- const newDir = path.dirname(current.name);
174
- // Check if the new directory exists, if not, create it
175
- if (!fs.existsSync(newDir)) {
176
- fs.mkdirSync(newDir, { recursive: true });
177
- }
178
- // Move the file to the new directory
179
- fs.renameSync(previous.name, current.name);
180
- }
181
- }
182
- }
183
- // handle deleting files and directories.
184
- if (previous && !current) {
185
- const stats = fs.statSync(previous.name);
186
- //Check if the file path we are trying to delete is a directory
187
- if (!stats.isDirectory()) {
188
- fs.unlinkSync(previous.name);
189
- }
190
- else {
191
- //Performs directory deletion.
192
- fs.rm(previous.name, {
193
- recursive: true, //Makes sure that all files in directory are deleted.
194
- }, (error) => {
195
- if (error) {
196
- console.log(error);
197
- }
198
- });
199
- }
200
- }
201
- // Handle creating files and Directories.
202
- if (!previous && current) {
203
- //File Creation
204
- if (!isDirectory(current.name)) {
205
- if (isImageFile(current.name)) {
206
- // Write image files as binary from base64
207
- const buffer = Buffer.from(current.text, 'base64');
208
- fs.writeFileSync(current.name, buffer);
209
- }
210
- else {
211
- // Write non-image files as text
212
- fs.writeFileSync(current.name, current.text);
213
- }
214
- }
215
- else {
216
- fs.mkdirSync(current.name, { recursive: true });
217
- }
218
- }
219
- }
220
- // TODO deleted all directories under directoriesToDelete
221
- for (const dir of directoriesToDelete) {
222
- //Performs directory deletion.
223
- fs.rm(dir, {
224
- recursive: true, //Makes sure that all files in directory are deleted.
225
- }, (error) => {
226
- if (error) {
227
- console.log(error);
228
- }
229
- });
230
- }
231
- previousDocument = currentDocument;
232
- };
233
- // // Listen for when users modify files.
234
- // // Files get written to disk after `autoSaveDebounceTimeMS`
235
- // // milliseconds of inactivity.
236
- // let timeout;
237
- // shareDBDoc.subscribe(() => {
238
- // shareDBDoc.on('op', () => {
239
- // // console.log(shareDBDoc.data.isInteracting);
240
- // clearTimeout(timeout);
241
- // timeout = setTimeout(save, autoSaveDebounceTimeMS);
242
- // });
243
- // });
244
- let lastExecutedTime = Date.now();
245
- let lastChangeTimeout; // This timeout ensures the last change is saved
246
- // Function to throttle the saving
247
- function throttleSave() {
248
- const now = Date.now();
249
- const timeSinceLastExecution = now - lastExecutedTime;
250
- if (timeSinceLastExecution > throttleTimeMS) {
251
- save();
252
- lastExecutedTime = now;
253
- }
254
- else {
255
- // Clear the previous timeout and set a new one to save the last change
256
- clearTimeout(lastChangeTimeout);
257
- lastChangeTimeout = setTimeout(() => {
258
- save();
259
- lastExecutedTime = now;
260
- }, throttleTimeMS - timeSinceLastExecution);
261
- }
262
- }
263
- // Function to debounce the saving
264
- let debounceTimeout;
265
- function debounceSave() {
266
- clearTimeout(debounceTimeout);
267
- debounceTimeout = setTimeout(save, autoSaveDebounceTimeMS);
268
- }
269
- // Subscribe to listen for modifications
270
- shareDBDoc.subscribe(() => {
271
- shareDBDoc.on('op', () => {
272
- if (shareDBDoc.data.isInteracting) {
273
- throttleSave();
274
- }
275
- else {
276
- debounceSave();
277
- }
278
- });
279
- });
280
- server.listen(port, async () => {
281
- // Note: ngrok support can be added when the package is properly installed
18
+ listen(port).then((actualPort) => {
282
19
  // Sets the port to the one specified in the environment
283
20
  // variable (for development) or the default port.
284
- const livePort = process.env.EDITOR_PORT || port;
21
+ const livePort = process.env.EDITOR_PORT || actualPort;
285
22
  console.log(`EDITOR_PORT: ${process.env.EDITOR_PORT}`);
286
23
  console.log(`Editor is live at http://localhost:${livePort}`);
287
24
  open(`http://localhost:${livePort}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vzcode",
3
- "version": "2.34.0",
3
+ "version": "2.36.0",
4
4
  "description": "Multiplayer code editor system",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -13,6 +13,9 @@
13
13
  ],
14
14
  "scripts": {
15
15
  "test": "vitest run",
16
+ "test:e2e": "vitest run test/serverE2E.test.ts",
17
+ "e2e": "playwright test",
18
+ "e2e:headed": "playwright test --headed",
16
19
  "test-interactive": "cd test/sampleDirectories/playground && tsx ../../../src/server/index.ts",
17
20
  "prettier": "prettier {*.*,**/*.*} --write",
18
21
  "typecheck": "tsc --noEmit",
@@ -113,17 +116,22 @@
113
116
  "homepage": "https://github.com/vizhub-core/vzcode#readme",
114
117
  "dependencies": {
115
118
  "@codemirror/autocomplete": "^6.20.0",
119
+ "@codemirror/commands": "^6.11.1",
116
120
  "@codemirror/lang-css": "^6.3.1",
117
121
  "@codemirror/lang-html": "^6.4.11",
118
122
  "@codemirror/lang-javascript": "^6.2.4",
119
123
  "@codemirror/lang-json": "^6.0.2",
120
124
  "@codemirror/lang-markdown": "^6.5.0",
125
+ "@codemirror/language": "^6.13.1",
121
126
  "@codemirror/lint": "^6.9.2",
127
+ "@codemirror/search": "^6.7.2",
122
128
  "@codemirror/state": "^6.5.3",
123
129
  "@codemirror/theme-one-dark": "^6.1.3",
124
130
  "@codemirror/view": "^6.39.8",
131
+ "@dmsnell/diff-match-patch": "^1.1.0",
125
132
  "@langchain/core": "^1.1.8",
126
133
  "@langchain/openai": "^1.2.0",
134
+ "@lezer/common": "^1.5.4",
127
135
  "@lezer/highlight": "^1.2.3",
128
136
  "@livekit/components-react": "^2.9.17",
129
137
  "@replit/codemirror-indentation-markers": "^6.5.3",
@@ -155,7 +163,6 @@
155
163
  "d3-array": "^3.2.4",
156
164
  "d3-color": "^3.1.0",
157
165
  "diff": "^8.0.2",
158
- "@dmsnell/diff-match-patch": "^1.1.0",
159
166
  "diff2html": "3.4.52",
160
167
  "dotenv": "^17.2.3",
161
168
  "editcodewithai": "^2.4.0",
@@ -167,8 +174,8 @@
167
174
  "livekit-server-sdk": "^2.15.0",
168
175
  "llm-code-format": "^3.1.0",
169
176
  "lucide-react": "^0.562.0",
170
- "npm": "^11.7.0",
171
177
  "open": "^11.0.0",
178
+ "openai": "^6.9.1",
172
179
  "prettier-plugin-svelte": "^3.4.1",
173
180
  "react": "^18",
174
181
  "react-bootstrap": "^2.10.10",
@@ -184,8 +191,10 @@
184
191
  },
185
192
  "devDependencies": {
186
193
  "@eslint/js": "^9.39.2",
194
+ "@playwright/test": "^1.57.0",
187
195
  "@tauri-apps/cli": "^2.9.6",
188
196
  "@types/d3-color": "^3.1.3",
197
+ "@types/node": "^22.20.5",
189
198
  "@types/react": "^18",
190
199
  "@types/react-dom": "^18",
191
200
  "@typescript-eslint/eslint-plugin": "^8.51.0",
@@ -198,9 +207,11 @@
198
207
  "eslint-plugin-react": "^7.37.5",
199
208
  "eslint-plugin-react-hooks": "^7.0.1",
200
209
  "globals": "^17.0.0",
210
+ "livekit-client": "^2.16.0",
201
211
  "npm-check-updates": "^19.2.0",
202
212
  "prettier": "^3.7.4",
203
213
  "sass": "^1.97.1",
214
+ "svelte": "^5.20.1",
204
215
  "ts-node": "^10.9.2",
205
216
  "tsx": "^4.21.0",
206
217
  "typescript": "^5.9.3",
@@ -384,22 +384,8 @@ export const getOrCreateEditor = async ({
384
384
  widgets({ onInteract, customInteractRules }),
385
385
  );
386
386
 
387
- // TODO fix the bugginess in this one where
388
- // the highlight persists after the mouse leaves.
389
- // extensions.push(highlightWidgets);
390
-
391
387
  extensions.push(rotationIndicator);
392
388
 
393
- // extensions.push(
394
- // AIAssistCodeMirrorKeyMap({
395
- // shareDBDoc,
396
- // fileId,
397
- // tabList,
398
- // aiAssistEndpoint,
399
- // aiAssistOptions,
400
- // }),
401
- // );
402
-
403
389
  // Add the extension that provides indentation markers.
404
390
  extensions.push(
405
391
  indentationMarkers({
@@ -0,0 +1,17 @@
1
+ /** Pure AI chat behavior shared by the built-in session and unit tests. */
2
+ export const shouldReuseChatId = (
3
+ options?: Record<string, string>,
4
+ ): boolean =>
5
+ options?.isRetry === 'true' || options?.isUndo === 'true';
6
+
7
+ export const userMessageHistory = (
8
+ messages?: ReadonlyArray<{
9
+ role: string;
10
+ content: string;
11
+ }> | null,
12
+ ): string[] =>
13
+ messages
14
+ ? messages
15
+ .filter((message) => message.role === 'user')
16
+ .map((message) => message.content)
17
+ : [];