vzcode 0.46.0 → 0.47.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,7 +24,7 @@
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>
27
+ <script type="module" crossorigin src="/assets/index-r3WFw-uS.js"></script>
28
28
  <link rel="stylesheet" crossorigin href="/assets/index-0U2uzpmH.css">
29
29
  </head>
30
30
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vzcode",
3
- "version": "0.46.0",
3
+ "version": "0.47.0",
4
4
  "description": "Multiplayer code editor system",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -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, {
@@ -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