vzcode 0.46.0 → 0.48.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/dist/index.html CHANGED
@@ -24,8 +24,8 @@
24
24
  href="https://unpkg.com/boxicons@2.0.7/css/boxicons.min.css"
25
25
  rel="stylesheet"
26
26
  />
27
- <script type="module" crossorigin src="/assets/index-iJQOJ5Kf.js"></script>
28
- <link rel="stylesheet" crossorigin href="/assets/index-0U2uzpmH.css">
27
+ <script type="module" crossorigin src="/assets/index-ohy9XGuy.js"></script>
28
+ <link rel="stylesheet" crossorigin href="/assets/index-NqGS0RuC.css">
29
29
  </head>
30
30
  <body>
31
31
  <div id="root"></div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vzcode",
3
- "version": "0.46.0",
3
+ "version": "0.48.0",
4
4
  "description": "Multiplayer code editor system",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -69,13 +69,12 @@
69
69
  "@codemirror/lang-javascript": "^6.2.1",
70
70
  "@codemirror/lang-json": "^6.0.1",
71
71
  "@codemirror/lang-markdown": "^6.2.3",
72
- "@codemirror/state": "^6.3.3",
72
+ "@codemirror/state": "^6.4.0",
73
73
  "@codemirror/theme-one-dark": "^6.1.2",
74
- "@codemirror/view": "^6.22.3",
74
+ "@codemirror/view": "^6.23.0",
75
75
  "@lezer/highlight": "^1.2.0",
76
76
  "@replit/codemirror-indentation-markers": "^6.5.0",
77
77
  "@replit/codemirror-interact": "^6.3.0",
78
- "@replit/codemirror-minimap": "^0.5.2",
79
78
  "@replit/codemirror-vscode-keymap": "^6.0.2",
80
79
  "@teamwork/websocket-json-stream": "^2.0.0",
81
80
  "@typescript/vfs": "^1.5.0",
@@ -99,22 +98,22 @@
99
98
  "ignore": "^5.3.0",
100
99
  "json0-ot-diff": "^1.1.2",
101
100
  "ngrok": "^4.3.3",
102
- "open": "^10.0.1",
101
+ "open": "^10.0.2",
103
102
  "openai": "^4.24.1",
104
103
  "react": "^18.2.0",
105
104
  "react-bootstrap": "^2.9.2",
106
105
  "react-dom": "^18.2.0",
107
106
  "sharedb": "^4.1.2",
108
107
  "sharedb-client-browser": "^4.4.0",
109
- "vizhub-ui": "^3.14.0",
108
+ "vizhub-ui": "^3.15.0",
110
109
  "ws": "^8.16.0"
111
110
  },
112
111
  "devDependencies": {
113
- "@types/react": "^18.2.45",
112
+ "@types/react": "^18.2.46",
114
113
  "@types/react-dom": "^18.2.18",
115
114
  "@vitejs/plugin-react": "^4.2.1",
116
115
  "prettier": "^3.1.1",
117
- "sass": "^1.69.5",
116
+ "sass": "^1.69.6",
118
117
  "typescript": "^5.3.3",
119
118
  "vite": "^5.0.10",
120
119
  "vitest": "^1.1.0"
@@ -0,0 +1,27 @@
1
+ import { File } from '../../types';
2
+
3
+ const maxFileNameLength = 100;
4
+ const maxFileTextLength = 2000;
5
+
6
+ // Formats a file for the prompt.
7
+ export const formatFile = (
8
+ file: File,
9
+ truncateText = true,
10
+ ) => {
11
+ const nameTruncated = file.name
12
+ ?.substring(0, maxFileNameLength)
13
+ .trim();
14
+
15
+ const textTruncated = (
16
+ truncateText
17
+ ? file.text?.substring(0, maxFileTextLength)
18
+ : file.text
19
+ ).trim();
20
+
21
+ return [
22
+ '`' + nameTruncated + '`:',
23
+ '```',
24
+ textTruncated,
25
+ '```',
26
+ ].join('\n');
27
+ };
@@ -1,25 +1,25 @@
1
- import { File } from '../../types';
1
+ // import { File } from '../../types';
2
2
 
3
- const maxFileNameLength = 100;
4
- const maxFileTextLength = 2000;
3
+ // const maxFileNameLength = 100;
4
+ // const maxFileTextLength = 2000;
5
5
 
6
- export const generateFilesContext = async (
7
- goodFiles: Array<File>,
8
- ): Promise<string> => {
9
- const input = goodFiles
10
- .map((file) => {
11
- const nameSubstring = file.name
12
- ?.substring(0, maxFileNameLength)
13
- .trim();
6
+ // export const generateFilesContext = (
7
+ // goodFiles: Array<File>,
8
+ // ): string => {
9
+ // const input = goodFiles
10
+ // .map((file) => {
11
+ // const nameSubstring = file.name
12
+ // ?.substring(0, maxFileNameLength)
13
+ // .trim();
14
14
 
15
- const textSubstring = file.text
16
- ?.substring(0, maxFileTextLength)
17
- .trim();
15
+ // const textSubstring = file.text
16
+ // ?.substring(0, maxFileTextLength)
17
+ // .trim();
18
18
 
19
- // Generate Markdown that AI will understand.
20
- return `File \`${nameSubstring}\`:\n\`\`\`${textSubstring}\`\`\``;
21
- })
22
- .join('\n\n');
19
+ // // Generate Markdown that AI will understand.
20
+ // return `File \`${nameSubstring}\`:\n\`\`\`${textSubstring}\`\`\``;
21
+ // })
22
+ // .join('\n\n');
23
23
 
24
- return input;
25
- };
24
+ // return input;
25
+ // };
@@ -1,18 +1,19 @@
1
1
  import { EditorView } from 'codemirror';
2
2
  import {
3
+ File,
3
4
  FileId,
4
5
  ShareDBDoc,
5
6
  VZCodeContent,
6
7
  } from '../../types';
7
8
  import { TabState } from '../vzReducer';
8
- import { generateFilesContext } from './generateFilesContext';
9
- import {
10
- RequestId,
11
- generateRequestId,
12
- } from '../generateRequestId';
9
+ import { RequestId } from '../generateRequestId';
10
+ import { formatFile } from './formatFile';
13
11
 
14
12
  const debug = false;
15
13
 
14
+ // Enables inclusion of code from open tabs as context.
15
+ const enableTabContext = false;
16
+
16
17
  const defaultAIAssistEndpoint = '/ai-assist';
17
18
 
18
19
  export const startAIAssist = async ({
@@ -34,38 +35,64 @@ export const startAIAssist = async ({
34
35
  };
35
36
  aiStreamId: RequestId;
36
37
  }) => {
37
- const inputText =
38
- (await generateFilesContext(
39
- tabList.map(
40
- (tabState) =>
41
- shareDBDoc.data.files[tabState.fileId],
42
- ),
43
- )) +
44
- 'Current File:\n' +
45
- view.state.sliceDoc(0, view.state.selection.main.to);
38
+ const currentFileName =
39
+ shareDBDoc.data.files[fileId].name;
40
+
41
+ // Generate a version of the current file with a
42
+ // <FILL_ME> in the middle.
43
+ const prefix = view.state.sliceDoc(
44
+ 0,
45
+ view.state.selection.main.from,
46
+ );
47
+ const suffix = view.state.sliceDoc(
48
+ view.state.selection.main.to,
49
+ );
50
+ const combinedText = prefix + '<FILL_ME>' + suffix;
51
+ const currentFile = {
52
+ name: currentFileName,
53
+ text: combinedText,
54
+ };
46
55
 
47
56
  const insertionCursor = view.state.selection.main.to;
48
57
 
58
+ // The main prompt is the current file, plus the context files.
59
+ let inputText = formatFile(currentFile, false);
60
+
61
+ if (enableTabContext) {
62
+ inputText +=
63
+ '\n\n' +
64
+ tabList
65
+ .filter((tabState) => tabState.fileId !== fileId)
66
+ .map((tabState) =>
67
+ formatFile(
68
+ shareDBDoc.data.files[tabState.fileId],
69
+ ),
70
+ )
71
+ .join('\n\n');
72
+ }
73
+
49
74
  if (debug) {
50
- console.log('[startAIAssist] sending HTTP request:');
75
+ // console.log('[startAIAssist] sending HTTP request:');
76
+ // console.log(
77
+ // '[startAIAssist] aiAssistEndpoint:',
78
+ // aiAssistEndpoint,
79
+ // );
80
+ // console.log(
81
+ // '[startAIAssist] aiAssistOptions:',
82
+ // aiAssistOptions,
83
+ // );
51
84
  console.log(
52
- '[startAIAssist] aiAssistEndpoint:',
53
- aiAssistEndpoint,
54
- );
55
- console.log(
56
- '[startAIAssist] aiAssistOptions:',
57
- aiAssistOptions,
58
- );
59
- console.log('[startAIAssist] inputText:', inputText);
60
- console.log('[startAIAssist] fileId:', fileId);
61
- console.log(
62
- '[startAIAssist] insertionCursor:',
63
- insertionCursor,
64
- );
65
- console.log(
66
- '[startAIAssist] aiStreamId:',
67
- aiStreamId,
85
+ '[startAIAssist] inputText:\n`' + inputText + '`',
68
86
  );
87
+ // console.log('[startAIAssist] fileId:', fileId);
88
+ // console.log(
89
+ // '[startAIAssist] insertionCursor:',
90
+ // insertionCursor,
91
+ // );
92
+ // console.log(
93
+ // '[startAIAssist] aiStreamId:',
94
+ // aiStreamId,
95
+ // );
69
96
  }
70
97
 
71
98
  const response = await fetch(aiAssistEndpoint, {
@@ -11,7 +11,7 @@ import { css } from '@codemirror/lang-css';
11
11
  import { json1Sync } from 'codemirror-ot';
12
12
  import { autocompletion } from '@codemirror/autocomplete';
13
13
  import { indentationMarkers } from '@replit/codemirror-indentation-markers';
14
- import { showMinimap } from '@replit/codemirror-minimap';
14
+ // import { showMinimap } from '@replit/codemirror-minimap';
15
15
  import { vscodeKeymap } from '@replit/codemirror-vscode-keymap';
16
16
  import { Diagnostic, linter } from '@codemirror/lint';
17
17
  import { json1Presence, textUnicode } from '../../ot';
@@ -274,14 +274,16 @@ export const getOrCreateEditor = ({
274
274
 
275
275
  // Show the minimap
276
276
  // See https://github.com/replit/codemirror-minimap#usage
277
- extensions.push(
278
- showMinimap.compute(['doc'], () => ({
279
- create: () => ({
280
- dom: document.createElement('div'),
281
- }),
282
- // displayText: 'blocks',
283
- })),
284
- );
277
+ // This extension has poor performance, so it's disabled for now.
278
+ // extensions.push(
279
+ // showMinimap.compute(['doc'], () => ({
280
+ // create: () => ({
281
+ // dom: document.createElement('div'),
282
+ // }),
283
+ // // Without this, performance is terrible.
284
+ // displayText: 'blocks',
285
+ // })),
286
+ // );
285
287
 
286
288
  // VSCode keybindings
287
289
  // See https://github.com/replit/codemirror-vscode-keymap#usage
@@ -59,18 +59,28 @@ export const generateAIResponse = async ({
59
59
 
60
60
  shareDBDoc.on('op', accomodateDocChanges);
61
61
 
62
+ const messages = [
63
+ {
64
+ role: 'system',
65
+ content: [
66
+ 'You are an expert programmer.',
67
+ 'Your task is to output ONLY the code that replaces <FILL_ME> correctly.',
68
+ 'Do not add any markdown.',
69
+ 'Do not duplicate the code before or after <FILL_ME>.',
70
+ 'Do not make any changes outside of <FILL_ME>.',
71
+ ].join(' '),
72
+ },
73
+ { role: 'user', content: inputText },
74
+ ];
75
+
76
+ console.log('messages');
77
+ console.log(messages);
78
+
62
79
  streams[streamId] = await openai.chat.completions.create({
63
80
  // model: 'gpt-3.5-turbo',
64
81
  model: 'gpt-4',
65
82
 
66
- messages: [
67
- {
68
- role: 'system',
69
- content:
70
- 'Write typescript or javascript code to continue the current file, given the other files for context. Use // for comments.',
71
- },
72
- { role: 'user', content: inputText },
73
- ],
83
+ messages,
74
84
  stream: true,
75
85
  });
76
86