vzcode 2.35.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 (44) 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/VZSidebar/AIChatWrapper.tsx +85 -0
  14. package/src/client/VZSidebar/VisualEditor/VisualEditor.tsx +13 -9
  15. package/src/client/VZSidebar/VisualEditor/colorUtils.ts +14 -0
  16. package/src/client/VZSidebar/index.tsx +2 -2
  17. package/src/client/useOpenDirectories.ts +0 -1
  18. package/src/llm-streaming-server/README.md +5 -3
  19. package/src/llm-streaming-ui/README.md +44 -42
  20. package/src/llm-streaming-ui/components/ChatInput.tsx +6 -19
  21. package/src/llm-streaming-ui/components/DiffView.tsx +6 -24
  22. package/src/llm-streaming-ui/components/FileEditingIndicator.tsx +1 -1
  23. package/src/llm-streaming-ui/components/Message.tsx +11 -27
  24. package/src/llm-streaming-ui/components/MessageList.tsx +15 -29
  25. package/src/llm-streaming-ui/components/Spinner.scss +37 -0
  26. package/src/llm-streaming-ui/components/Spinner.tsx +59 -0
  27. package/src/llm-streaming-ui/components/bootstrap.ts +16 -0
  28. package/src/llm-streaming-ui/components/icons.tsx +68 -0
  29. package/src/llm-streaming-ui/components/index.tsx +34 -30
  30. package/src/llm-streaming-ui/index.ts +13 -0
  31. package/src/llm-streaming-ui/props.ts +137 -0
  32. package/src/ot.ts +221 -4
  33. package/src/server/createServer.ts +413 -0
  34. package/src/server/index.ts +8 -333
  35. package/dist/assets/buildWorker-DylWm2VX.js +0 -687
  36. package/dist/assets/index-Dyt9tpmu.css +0 -1
  37. package/dist/assets/index-rg2Zvfo_.js +0 -364
  38. package/dist/assets/worker-b9bkZkXK.js +0 -116
  39. package/src/client/AIAssist/AIAssistCodeMirrorKeyMap.ts +0 -42
  40. package/src/client/AIAssist/generateFilesContext.ts +0 -25
  41. package/src/client/AIAssist/index.ts +0 -2
  42. package/src/client/CodeEditor/InteractiveWidgets/highlightWidgets.ts +0 -79
  43. /package/src/{client → llm-streaming-ui}/hooks/useAutoScroll.ts +0 -0
  44. /package/src/{client → llm-streaming-ui}/utils/scrollUtils.ts +0 -0
@@ -1,38 +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
-
21
- // Import the image file utility
22
- const isImageFile = (fileName) => {
23
- return (
24
- fileName.match(
25
- /\.(png|jpg|jpeg|gif|bmp|svg|webp)$/i,
26
- ) !== null
27
- );
28
- };
29
-
30
- // The time in milliseconds by which auto-saving is debounced.
31
- const autoSaveDebounceTimeMS = 800;
32
-
33
- // The time in milliseconds by which auto-saving is throttled
34
- // when the user is interacting with the widgets in the editor.
35
- const throttleTimeMS = 100;
3
+ import { createVZCodeServer } from './createServer.js';
36
4
 
37
5
  // Helper function to get the port from command line arguments or use default.
38
6
  function getPortFromArgs(defaultPort = 3030) {
@@ -48,312 +16,19 @@ function getPortFromArgs(defaultPort = 3030) {
48
16
  // Server port.
49
17
  const port = getPortFromArgs();
50
18
 
51
- const initialDocument = computeInitialDocument({
52
- // Use the current working directory to look for files.
53
- fullPath: process.cwd(),
54
- });
55
-
56
- // Register our custom OT type,
57
- // because it does not ship with ShareDB.
58
- ShareDB.types.register(json1Presence.type);
59
-
60
- const app = express();
61
-
62
- // Use ShareDB over WebSocket
63
- const shareDBBackend = new ShareDB({
64
- // Enable presence
65
- // See https://github.com/share/sharedb/blob/master/examples/rich-text-presence/server.js#L9
66
- presence: true,
67
- doNotForwardSendPresenceErrorsToClient: true,
68
- });
69
- const server = http.createServer(app);
70
- const wss = new WebSocketServer({ server });
71
- wss.on('connection', (ws) => {
72
- const clientStream = new WebSocketJSONStream(ws);
73
- shareDBBackend.listen(clientStream);
74
-
75
- // Prevent server crashes on errors.
76
- clientStream.on('error', (error) => {
77
- console.log('clientStream error: ' + error.message);
78
- });
79
-
80
- // Handle errors
81
- ws.on('error', (error) => {
82
- console.log('ws error: ' + error.message);
83
- });
84
-
85
- // Handle disconnections
86
- ws.on('close', () => {
87
- clientStream.end();
88
- });
89
- });
90
-
91
- // Serve static files
92
- const filename = fileURLToPath(import.meta.url);
93
- const dirname = path.dirname(filename);
94
- const dir = path.join(dirname, '..', '..', 'dist');
95
- app.use(express.static(dir));
96
-
97
- // Create the initial "document",
98
- // which is a representation of files on disk.
99
- const shareDBConnection = shareDBBackend.connect();
100
- const shareDBDoc = shareDBConnection.get('documents', '1');
101
-
102
- shareDBDoc.create(initialDocument, json1Presence.type.uri);
103
-
104
- // Handle AI Assist requests.
105
- app.post(
106
- '/ai-assist',
107
- bodyParser.json(),
108
- handleAIAssist(shareDBDoc),
109
- );
110
-
111
- // Handle AI Copilot requests.
112
- app.post(
113
- '/ai-copilot',
114
- bodyParser.json(),
115
- handleAICopilot(),
116
- );
117
-
118
- // Handle AI Chat Message requests.
119
- app.post(
120
- '/ai-chat-message',
121
- bodyParser.json(),
122
- handleAIChatMessage({
123
- shareDBDoc,
124
- onCreditDeduction: undefined,
125
- }),
126
- );
127
-
128
- // Livekit Token Generator
129
- app.get('/livekit-token', async (req, res) => {
130
- const { room, username } = req.query;
131
- res.send(await createToken(room, username));
132
- });
133
-
134
- // The state of the document when files were last auto-saved.
135
- let previousDocument = initialDocument;
136
-
137
- // Saves the files that changed.
138
- const save = () => {
139
- const currentDocument = shareDBDoc.data;
140
-
141
- // Take a look at each file (key) previously and currently.
142
- const allKeys = Object.keys({
143
- ...currentDocument.files,
144
- ...previousDocument.files,
145
- });
146
-
147
- const directoriesToDelete = [];
19
+ const { ready, listen } = createVZCodeServer();
148
20
 
149
- for (const key of allKeys) {
150
- const previous = previousDocument.files[key];
151
- const current = currentDocument.files[key];
152
-
153
- // If this file was neither created nor deleted...
154
- if (previous && current) {
155
- // Handle changing of text content.
156
- if (previous.text !== current.text) {
157
- if (isImageFile(current.name)) {
158
- // Write image files as binary from base64
159
- const buffer = Buffer.from(
160
- current.text,
161
- 'base64',
162
- );
163
- fs.writeFileSync(current.name, buffer);
164
- } else {
165
- // Write non-image files as text
166
- fs.writeFileSync(current.name, current.text);
167
- }
168
- }
169
-
170
- // // Handle renaming files.
171
- // if (previous.name !== current.name) {
172
-
173
- // const previousPath = previous.name.split('/');
174
- // const currentPath = current.name.split('/');
175
-
176
- // // - If the path is length 1 for previous and current,
177
- // // then this should be true.
178
- // // - If the path length is the sane for previous and current,
179
- // // AND all the entries leading up to the last one are the same
180
- // // between previous and current, AND the last entry in the arrays
181
- // // (the file name itself) is different between previous and current
182
- // const onlyFileNameChanged =
183
- // (previousPath.length === 1 &&
184
- // currentPath.length === 1) ||
185
- // (previousPath.length === currentPath.length &&
186
- // previousPath
187
- // .slice(0, -1)
188
- // .every(
189
- // (val, index) => val === currentPath[index],
190
- // ) &&
191
- // previousPath.at(-1) !== currentPath.at(-1));
192
-
193
- // // This logic works if only the file name itself changes.
194
- // if (onlyFileNameChanged) {
195
- // fs.renameSync(previous.name, current.name);
196
- // }
197
- // {
198
- // // If we get here, then the directory may have been renamed,
199
- // // or the file has been moved between directories.
200
- // // If we get here, then the directory may have been renamed,
201
- // // or the file has been moved between directories.
202
- // const newDir = path.dirname(current.name);
203
-
204
- // // Check if the new directory exists, if not, create it
205
- // if (!fs.existsSync(newDir)) {
206
- // fs.mkdirSync(newDir, { recursive: true });
207
- // }
208
-
209
- // // Move the file to the new directory
210
- // fs.renameSync(previous.name, current.name);
211
- // }
212
- // }
213
- // Handle renaming files.
214
- if (previous.name !== current.name) {
215
- if (isDirectory(previous.name)) {
216
- // If the directory itself is being renamed,
217
- // Phase I: Ignore it, and get the files moved
218
- // Phase II: Keep track of these, and delete them after
219
- // all the files moved.
220
- // directoriesToDelete.push(previous.name)
221
- directoriesToDelete.push(previous.name);
222
- } else {
223
- const newDir = path.dirname(current.name);
224
-
225
- // Check if the new directory exists, if not, create it
226
- if (!fs.existsSync(newDir)) {
227
- fs.mkdirSync(newDir, { recursive: true });
228
- }
229
-
230
- // Move the file to the new directory
231
- fs.renameSync(previous.name, current.name);
232
- }
233
- }
234
- }
235
-
236
- // handle deleting files and directories.
237
- if (previous && !current) {
238
- const stats = fs.statSync(previous.name);
239
- //Check if the file path we are trying to delete is a directory
240
- if (!stats.isDirectory()) {
241
- fs.unlinkSync(previous.name);
242
- } else {
243
- //Performs directory deletion.
244
- fs.rm(
245
- previous.name,
246
- {
247
- recursive: true, //Makes sure that all files in directory are deleted.
248
- },
249
- (error) => {
250
- if (error) {
251
- console.log(error);
252
- }
253
- },
254
- );
255
- }
256
- }
257
-
258
- // Handle creating files and Directories.
259
- if (!previous && current) {
260
- //File Creation
261
- if (!isDirectory(current.name)) {
262
- if (isImageFile(current.name)) {
263
- // Write image files as binary from base64
264
- const buffer = Buffer.from(
265
- current.text,
266
- 'base64',
267
- );
268
- fs.writeFileSync(current.name, buffer);
269
- } else {
270
- // Write non-image files as text
271
- fs.writeFileSync(current.name, current.text);
272
- }
273
- } else {
274
- fs.mkdirSync(current.name, { recursive: true });
275
- }
276
- }
277
- }
278
- // TODO deleted all directories under directoriesToDelete
279
-
280
- for (const dir of directoriesToDelete) {
281
- //Performs directory deletion.
282
- fs.rm(
283
- dir,
284
- {
285
- recursive: true, //Makes sure that all files in directory are deleted.
286
- },
287
- (error) => {
288
- if (error) {
289
- console.log(error);
290
- }
291
- },
292
- );
293
- }
294
-
295
- previousDocument = currentDocument;
296
- };
297
-
298
- // // Listen for when users modify files.
299
- // // Files get written to disk after `autoSaveDebounceTimeMS`
300
- // // milliseconds of inactivity.
301
- // let timeout;
302
- // shareDBDoc.subscribe(() => {
303
- // shareDBDoc.on('op', () => {
304
- // // console.log(shareDBDoc.data.isInteracting);
305
- // clearTimeout(timeout);
306
- // timeout = setTimeout(save, autoSaveDebounceTimeMS);
307
- // });
308
- // });
309
-
310
- let lastExecutedTime = Date.now();
311
- let lastChangeTimeout; // This timeout ensures the last change is saved
312
-
313
- // Function to throttle the saving
314
- function throttleSave() {
315
- const now = Date.now();
316
- const timeSinceLastExecution = now - lastExecutedTime;
317
-
318
- if (timeSinceLastExecution > throttleTimeMS) {
319
- save();
320
- lastExecutedTime = now;
321
- } else {
322
- // Clear the previous timeout and set a new one to save the last change
323
- clearTimeout(lastChangeTimeout);
324
- lastChangeTimeout = setTimeout(() => {
325
- save();
326
- lastExecutedTime = now;
327
- }, throttleTimeMS - timeSinceLastExecution);
328
- }
329
- }
330
-
331
- // Function to debounce the saving
332
- let debounceTimeout;
333
- function debounceSave() {
334
- clearTimeout(debounceTimeout);
335
- debounceTimeout = setTimeout(
336
- save,
337
- autoSaveDebounceTimeMS,
21
+ ready.catch((error) => {
22
+ console.error(
23
+ 'Failed to initialize ShareDB document:',
24
+ error,
338
25
  );
339
- }
340
-
341
- // Subscribe to listen for modifications
342
- shareDBDoc.subscribe(() => {
343
- shareDBDoc.on('op', () => {
344
- if (shareDBDoc.data.isInteracting) {
345
- throttleSave();
346
- } else {
347
- debounceSave();
348
- }
349
- });
350
26
  });
351
27
 
352
- server.listen(port, async () => {
353
- // Note: ngrok support can be added when the package is properly installed
28
+ listen(port).then((actualPort) => {
354
29
  // Sets the port to the one specified in the environment
355
30
  // variable (for development) or the default port.
356
- const livePort = process.env.EDITOR_PORT || port;
31
+ const livePort = process.env.EDITOR_PORT || actualPort;
357
32
  console.log(`EDITOR_PORT: ${process.env.EDITOR_PORT}`);
358
33
  console.log(
359
34
  `Editor is live at http://localhost:${livePort}`,