@proteinjs/conversation 1.0.5 → 1.0.7
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/.eslintrc.js +20 -0
- package/.prettierrc +8 -0
- package/CHANGELOG.md +7 -4
- package/LICENSE +21 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +40 -28
- package/dist/src/CodegenConversation.d.ts +11 -11
- package/dist/src/CodegenConversation.d.ts.map +1 -1
- package/dist/src/CodegenConversation.js +294 -180
- package/dist/src/CodegenConversation.js.map +1 -1
- package/dist/src/Conversation.d.ts +52 -49
- package/dist/src/Conversation.d.ts.map +1 -1
- package/dist/src/Conversation.js +480 -274
- package/dist/src/Conversation.js.map +1 -1
- package/dist/src/ConversationModule.d.ts +6 -6
- package/dist/src/ConversationModule.js +3 -3
- package/dist/src/Function.d.ts +4 -4
- package/dist/src/Function.d.ts.map +1 -1
- package/dist/src/Function.js +3 -3
- package/dist/src/OpenAi.d.ts +42 -10
- package/dist/src/OpenAi.d.ts.map +1 -1
- package/dist/src/OpenAi.js +496 -289
- package/dist/src/OpenAi.js.map +1 -1
- package/dist/src/Paragraph.d.ts +4 -4
- package/dist/src/Paragraph.d.ts.map +1 -1
- package/dist/src/Paragraph.js +17 -16
- package/dist/src/Paragraph.js.map +1 -1
- package/dist/src/Sentence.d.ts +4 -4
- package/dist/src/Sentence.d.ts.map +1 -1
- package/dist/src/Sentence.js +21 -19
- package/dist/src/Sentence.js.map +1 -1
- package/dist/src/code_template/Code.d.ts +15 -15
- package/dist/src/code_template/Code.d.ts.map +1 -1
- package/dist/src/code_template/Code.js +167 -69
- package/dist/src/code_template/Code.js.map +1 -1
- package/dist/src/code_template/CodeTemplate.d.ts +11 -11
- package/dist/src/code_template/CodeTemplate.d.ts.map +1 -1
- package/dist/src/code_template/CodeTemplate.js +169 -79
- package/dist/src/code_template/CodeTemplate.js.map +1 -1
- package/dist/src/code_template/CodeTemplateModule.d.ts +6 -6
- package/dist/src/code_template/CodeTemplateModule.js +28 -26
- package/dist/src/code_template/Repo.d.ts +34 -38
- package/dist/src/code_template/Repo.d.ts.map +1 -1
- package/dist/src/code_template/Repo.js +291 -191
- package/dist/src/code_template/Repo.js.map +1 -1
- package/dist/src/fs/conversation_fs/ConversationFsModerator.d.ts +12 -12
- package/dist/src/fs/conversation_fs/ConversationFsModerator.d.ts.map +1 -1
- package/dist/src/fs/conversation_fs/ConversationFsModerator.js +111 -98
- package/dist/src/fs/conversation_fs/ConversationFsModerator.js.map +1 -1
- package/dist/src/fs/conversation_fs/ConversationFsModule.d.ts +11 -11
- package/dist/src/fs/conversation_fs/ConversationFsModule.d.ts.map +1 -1
- package/dist/src/fs/conversation_fs/ConversationFsModule.js +204 -99
- package/dist/src/fs/conversation_fs/ConversationFsModule.js.map +1 -1
- package/dist/src/fs/conversation_fs/FsFunctions.d.ts +58 -62
- package/dist/src/fs/conversation_fs/FsFunctions.d.ts.map +1 -1
- package/dist/src/fs/conversation_fs/FsFunctions.js +414 -266
- package/dist/src/fs/conversation_fs/FsFunctions.js.map +1 -1
- package/dist/src/fs/git/GitModule.d.ts +8 -8
- package/dist/src/fs/git/GitModule.d.ts.map +1 -1
- package/dist/src/fs/git/GitModule.js +163 -74
- package/dist/src/fs/git/GitModule.js.map +1 -1
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.d.ts +16 -18
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.d.ts.map +1 -1
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.js +158 -58
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.js.map +1 -1
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.d.ts +27 -26
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.d.ts.map +1 -1
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.js +234 -133
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.js.map +1 -1
- package/dist/src/fs/package/PackageFunctions.d.ts +54 -60
- package/dist/src/fs/package/PackageFunctions.d.ts.map +1 -1
- package/dist/src/fs/package/PackageFunctions.js +366 -223
- package/dist/src/fs/package/PackageFunctions.js.map +1 -1
- package/dist/src/fs/package/PackageModule.d.ts +24 -24
- package/dist/src/fs/package/PackageModule.d.ts.map +1 -1
- package/dist/src/fs/package/PackageModule.js +292 -163
- package/dist/src/fs/package/PackageModule.js.map +1 -1
- package/dist/src/history/MessageHistory.d.ts +12 -12
- package/dist/src/history/MessageHistory.d.ts.map +1 -1
- package/dist/src/history/MessageHistory.js +52 -43
- package/dist/src/history/MessageHistory.js.map +1 -1
- package/dist/src/history/MessageModerator.d.ts +2 -2
- package/dist/src/history/MessageModerator.js +3 -3
- package/dist/src/template/ConversationTemplate.d.ts +8 -8
- package/dist/src/template/ConversationTemplate.d.ts.map +1 -1
- package/dist/src/template/ConversationTemplate.js +3 -3
- package/dist/src/template/ConversationTemplateFunctions.d.ts +33 -35
- package/dist/src/template/ConversationTemplateFunctions.d.ts.map +1 -1
- package/dist/src/template/ConversationTemplateFunctions.js +176 -75
- package/dist/src/template/ConversationTemplateFunctions.js.map +1 -1
- package/dist/src/template/ConversationTemplateModule.d.ts +51 -48
- package/dist/src/template/ConversationTemplateModule.d.ts.map +1 -1
- package/dist/src/template/ConversationTemplateModule.js +211 -114
- package/dist/src/template/ConversationTemplateModule.js.map +1 -1
- package/dist/src/template/createApp/CreateAppTemplate.d.ts +1 -1
- package/dist/src/template/createApp/CreateAppTemplate.js +151 -59
- package/dist/src/template/createCode/CreateCodeConversationTemplate.d.ts +1 -1
- package/dist/src/template/createCode/CreateCodeConversationTemplate.d.ts.map +1 -1
- package/dist/src/template/createCode/CreateCodeConversationTemplate.js +183 -74
- package/dist/src/template/createCode/CreateCodeConversationTemplate.js.map +1 -1
- package/dist/src/template/createPackage/CreatePackageConversationTemplate.d.ts +1 -1
- package/dist/src/template/createPackage/CreatePackageConversationTemplate.d.ts.map +1 -1
- package/dist/src/template/createPackage/CreatePackageConversationTemplate.js +174 -84
- package/dist/src/template/createPackage/CreatePackageConversationTemplate.js.map +1 -1
- package/dist/src/template/createPackage/tsconfig.json +11 -11
- package/dist/test/createKeywordFilesIndex.test.d.ts +1 -1
- package/dist/test/createKeywordFilesIndex.test.js +132 -41
- package/dist/test/createKeywordFilesIndex.test.js.map +1 -1
- package/dist/test/openai/openai.generateList.test.d.ts +1 -1
- package/dist/test/openai/openai.generateList.test.js +136 -47
- package/dist/test/openai/openai.generateList.test.js.map +1 -1
- package/dist/test/openai/openai.parseCodeFromMarkdown.test.d.ts +1 -1
- package/dist/test/openai/openai.parseCodeFromMarkdown.test.js +15 -10
- package/dist/test/openai/openai.parseCodeFromMarkdown.test.js.map +1 -1
- package/dist/test/repo/repo.test.d.ts +1 -1
- package/dist/test/repo/repo.test.js +127 -38
- package/dist/test/repo/repo.test.js.map +1 -1
- package/jest.config.js +2 -2
- package/package.json +11 -5
- package/src/CodegenConversation.ts +6 -4
- package/src/Conversation.ts +102 -33
- package/src/ConversationModule.ts +2 -2
- package/src/Function.ts +0 -1
- package/src/OpenAi.ts +128 -63
- package/src/Paragraph.ts +3 -2
- package/src/Sentence.ts +5 -3
- package/src/code_template/Code.ts +25 -19
- package/src/code_template/CodeTemplate.ts +8 -7
- package/src/code_template/CodeTemplateModule.ts +2 -2
- package/src/code_template/Repo.ts +25 -19
- package/src/fs/conversation_fs/ConversationFsModerator.ts +34 -20
- package/src/fs/conversation_fs/ConversationFsModule.ts +13 -7
- package/src/fs/conversation_fs/FsFunctions.ts +33 -44
- package/src/fs/git/GitModule.ts +2 -4
- package/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.ts +31 -31
- package/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.ts +19 -18
- package/src/fs/package/PackageFunctions.ts +34 -41
- package/src/fs/package/PackageModule.ts +33 -21
- package/src/history/MessageHistory.ts +7 -4
- package/src/history/MessageModerator.ts +1 -1
- package/src/template/ConversationTemplate.ts +9 -9
- package/src/template/ConversationTemplateFunctions.ts +8 -7
- package/src/template/ConversationTemplateModule.ts +24 -15
- package/src/template/createApp/CreateAppTemplate.ts +1 -1
- package/src/template/createCode/CreateCodeConversationTemplate.ts +9 -11
- package/src/template/createPackage/CreatePackageConversationTemplate.ts +2 -9
- package/src/template/createPackage/jest.config.js +2 -2
- package/test/createKeywordFilesIndex.test.ts +3 -3
- package/test/openai/openai.generateList.test.ts +5 -3
- package/test/openai/openai.parseCodeFromMarkdown.test.ts +10 -5
- package/test/repo/repo.test.ts +3 -4
- package/tsconfig.json +16 -20
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable no-empty */
|
|
1
2
|
import { LogLevel, Logger } from '@proteinjs/util';
|
|
2
3
|
import { FileContentMap } from '@proteinjs/util-node';
|
|
3
4
|
import { ChatCompletionMessageParam } from 'openai/resources/chat';
|
|
@@ -23,12 +24,12 @@ export class ConversationFsFactory {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
merge(existingFs: ConversationFs, updates: FileContentMap): ConversationFs {
|
|
26
|
-
for (
|
|
27
|
+
for (const filePath of Object.keys(updates)) {
|
|
27
28
|
// if the file already exists in the fs
|
|
28
29
|
if (existingFs.fileContentMap[filePath]) {
|
|
29
|
-
this.logger.debug(`Updating existing file: ${filePath}`)
|
|
30
|
+
this.logger.debug(`Updating existing file: ${filePath}`);
|
|
30
31
|
existingFs.fileContentMap[filePath] = updates[filePath];
|
|
31
|
-
const oldIndex = existingFs.order.findIndex(item => item == filePath);
|
|
32
|
+
const oldIndex = existingFs.order.findIndex((item) => item == filePath);
|
|
32
33
|
existingFs.order.splice(oldIndex, 1);
|
|
33
34
|
existingFs.order.push(filePath);
|
|
34
35
|
continue;
|
|
@@ -36,12 +37,12 @@ export class ConversationFsFactory {
|
|
|
36
37
|
|
|
37
38
|
// if we have less than the max number of files in the fs
|
|
38
39
|
if (Object.keys(existingFs.fileContentMap).length < this.params.maxFiles) {
|
|
39
|
-
this.logger.debug(`Adding new file (under limit): ${filePath}`)
|
|
40
|
+
this.logger.debug(`Adding new file (under limit): ${filePath}`);
|
|
40
41
|
existingFs.fileContentMap[filePath] = updates[filePath];
|
|
41
42
|
existingFs.order.push(filePath);
|
|
42
43
|
continue;
|
|
43
44
|
} else {
|
|
44
|
-
this.logger.debug(`Adding new file (over limit): ${filePath}`)
|
|
45
|
+
this.logger.debug(`Adding new file (over limit): ${filePath}`);
|
|
45
46
|
const removedFilePath = existingFs.order.splice(0, 1)[0];
|
|
46
47
|
delete existingFs.fileContentMap[removedFilePath];
|
|
47
48
|
existingFs.fileContentMap[filePath] = updates[filePath];
|
|
@@ -57,15 +58,16 @@ export class ConversationFsModerator implements MessageModerator {
|
|
|
57
58
|
private logLevel: LogLevel = 'info';
|
|
58
59
|
|
|
59
60
|
constructor(logLevel?: LogLevel) {
|
|
60
|
-
if (logLevel)
|
|
61
|
+
if (logLevel) {
|
|
61
62
|
this.logLevel = logLevel;
|
|
63
|
+
}
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
observe(messages: ChatCompletionMessageParam[]): ChatCompletionMessageParam[] {
|
|
65
67
|
let conversationFileSystemMessageIndex: number = -1;
|
|
66
|
-
let conversationFileSystem: ConversationFs|undefined;
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
let conversationFileSystem: ConversationFs | undefined;
|
|
69
|
+
const readFilesFunctionCallMessageIndexes: number[] = [];
|
|
70
|
+
const writeFilesFunctionCallMessageIndexes: number[] = [];
|
|
69
71
|
const readFilesConsolidatedOutput: FileContentMap = {}; // newest version of file wins
|
|
70
72
|
for (let i = 0; i < messages.length; i++) {
|
|
71
73
|
const message = messages[i];
|
|
@@ -74,8 +76,9 @@ export class ConversationFsModerator implements MessageModerator {
|
|
|
74
76
|
try {
|
|
75
77
|
parsedContent = JSON.parse(message.content);
|
|
76
78
|
} catch (error) {}
|
|
77
|
-
if (!parsedContent || !parsedContent['fileSystem'])
|
|
79
|
+
if (!parsedContent || !parsedContent['fileSystem']) {
|
|
78
80
|
continue;
|
|
81
|
+
}
|
|
79
82
|
|
|
80
83
|
conversationFileSystem = parsedContent['fileSystem'];
|
|
81
84
|
conversationFileSystemMessageIndex = i;
|
|
@@ -83,14 +86,15 @@ export class ConversationFsModerator implements MessageModerator {
|
|
|
83
86
|
}
|
|
84
87
|
|
|
85
88
|
if (message.role == 'function' && message.name == 'readFiles' && message.content) {
|
|
86
|
-
let parsedContent: any|undefined;
|
|
89
|
+
let parsedContent: any | undefined;
|
|
87
90
|
try {
|
|
88
91
|
parsedContent = JSON.parse(message.content);
|
|
89
92
|
} catch (error) {}
|
|
90
|
-
if (!parsedContent)
|
|
93
|
+
if (!parsedContent) {
|
|
91
94
|
continue;
|
|
95
|
+
}
|
|
92
96
|
|
|
93
|
-
for (
|
|
97
|
+
for (const filePath of Object.keys(parsedContent)) {
|
|
94
98
|
readFilesConsolidatedOutput[filePath] = parsedContent[filePath];
|
|
95
99
|
}
|
|
96
100
|
|
|
@@ -103,19 +107,29 @@ export class ConversationFsModerator implements MessageModerator {
|
|
|
103
107
|
}
|
|
104
108
|
|
|
105
109
|
if (conversationFileSystem) {
|
|
106
|
-
conversationFileSystem = new ConversationFsFactory({ logLevel: this.logLevel }).merge(
|
|
110
|
+
conversationFileSystem = new ConversationFsFactory({ logLevel: this.logLevel }).merge(
|
|
111
|
+
conversationFileSystem,
|
|
112
|
+
readFilesConsolidatedOutput
|
|
113
|
+
);
|
|
107
114
|
const content = JSON.stringify({ fileSystem: conversationFileSystem });
|
|
108
115
|
messages[conversationFileSystemMessageIndex].content = content;
|
|
109
116
|
} else {
|
|
110
|
-
conversationFileSystem = {
|
|
111
|
-
|
|
117
|
+
conversationFileSystem = {
|
|
118
|
+
fileContentMap: readFilesConsolidatedOutput,
|
|
119
|
+
order: Object.keys(readFilesConsolidatedOutput),
|
|
120
|
+
};
|
|
121
|
+
messages.push({
|
|
122
|
+
role: 'system',
|
|
123
|
+
content: `Whenever you make a call to readFiles, the file content will be loaded into the { fileSystem } object in the message history. Do not respond with fileSystem's content in a message.`,
|
|
124
|
+
});
|
|
112
125
|
const content = JSON.stringify({ fileSystem: conversationFileSystem });
|
|
113
126
|
messages.push({ role: 'system', content });
|
|
114
127
|
}
|
|
115
128
|
|
|
116
|
-
const moderatedMessages = messages
|
|
117
|
-
|
|
118
|
-
|
|
129
|
+
const moderatedMessages = messages.filter(
|
|
130
|
+
(message, i) =>
|
|
131
|
+
!readFilesFunctionCallMessageIndexes.includes(i) && !writeFilesFunctionCallMessageIndexes.includes(i)
|
|
132
|
+
);
|
|
119
133
|
return moderatedMessages;
|
|
120
134
|
}
|
|
121
|
-
}
|
|
135
|
+
}
|
|
@@ -3,7 +3,15 @@ import { Function } from '../../Function';
|
|
|
3
3
|
import { searchFilesFunctionName } from '../keyword_to_files_index/KeywordToFilesIndexFunctions';
|
|
4
4
|
import { searchLibrariesFunctionName, searchPackagesFunctionName } from '../package/PackageFunctions';
|
|
5
5
|
import { ConversationFsModerator } from './ConversationFsModerator';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
fsFunctions,
|
|
8
|
+
getRecentlyAccessedFilePathsFunction,
|
|
9
|
+
getRecentlyAccessedFilePathsFunctionName,
|
|
10
|
+
readFilesFunction,
|
|
11
|
+
readFilesFunctionName,
|
|
12
|
+
writeFilesFunction,
|
|
13
|
+
writeFilesFunctionName,
|
|
14
|
+
} from './FsFunctions';
|
|
7
15
|
|
|
8
16
|
export class ConversationFsModule implements ConversationModule {
|
|
9
17
|
private repoPath: string;
|
|
@@ -16,7 +24,7 @@ export class ConversationFsModule implements ConversationModule {
|
|
|
16
24
|
getName(): string {
|
|
17
25
|
return 'Conversation Fs';
|
|
18
26
|
}
|
|
19
|
-
|
|
27
|
+
|
|
20
28
|
getSystemMessages(): string[] {
|
|
21
29
|
return [
|
|
22
30
|
`Assume the current working directory is: ${this.repoPath} unless specified by the user`,
|
|
@@ -38,14 +46,12 @@ export class ConversationFsModule implements ConversationModule {
|
|
|
38
46
|
readFilesFunction(this),
|
|
39
47
|
writeFilesFunction(this),
|
|
40
48
|
getRecentlyAccessedFilePathsFunction(this),
|
|
41
|
-
...fsFunctions
|
|
49
|
+
...fsFunctions,
|
|
42
50
|
];
|
|
43
51
|
}
|
|
44
52
|
|
|
45
53
|
getMessageModerators() {
|
|
46
|
-
return [
|
|
47
|
-
new ConversationFsModerator(),
|
|
48
|
-
];
|
|
54
|
+
return [new ConversationFsModerator()];
|
|
49
55
|
}
|
|
50
56
|
|
|
51
57
|
pushRecentlyAccessedFilePath(filePaths: string[]) {
|
|
@@ -61,4 +67,4 @@ export class ConversationFsModuleFactory implements ConversationModuleFactory {
|
|
|
61
67
|
async createModule(repoPath: string): Promise<ConversationFsModule> {
|
|
62
68
|
return new ConversationFsModule(repoPath);
|
|
63
69
|
}
|
|
64
|
-
}
|
|
70
|
+
}
|
|
@@ -19,17 +19,15 @@ export function readFilesFunction(fsModule: ConversationFsModule) {
|
|
|
19
19
|
},
|
|
20
20
|
},
|
|
21
21
|
},
|
|
22
|
-
required: ['filePaths']
|
|
22
|
+
required: ['filePaths'],
|
|
23
23
|
},
|
|
24
24
|
},
|
|
25
25
|
call: async (params: { filePaths: string[] }) => {
|
|
26
26
|
fsModule.pushRecentlyAccessedFilePath(params.filePaths);
|
|
27
27
|
return await Fs.readFiles(params.filePaths);
|
|
28
28
|
},
|
|
29
|
-
instructions: [
|
|
30
|
-
|
|
31
|
-
],
|
|
32
|
-
}
|
|
29
|
+
instructions: [`To read files from the local file system, use the ${readFilesFunctionName} function`],
|
|
30
|
+
};
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
export const writeFilesFunctionName = 'writeFiles';
|
|
@@ -59,17 +57,15 @@ export function writeFilesFunction(fsModule: ConversationFsModule) {
|
|
|
59
57
|
},
|
|
60
58
|
},
|
|
61
59
|
},
|
|
62
|
-
required: ['files']
|
|
60
|
+
required: ['files'],
|
|
63
61
|
},
|
|
64
62
|
},
|
|
65
63
|
call: async (params: { files: File[] }) => {
|
|
66
|
-
fsModule.pushRecentlyAccessedFilePath(params.files.map(file => file.path));
|
|
64
|
+
fsModule.pushRecentlyAccessedFilePath(params.files.map((file) => file.path));
|
|
67
65
|
return await Fs.writeFiles(params.files);
|
|
68
66
|
},
|
|
69
|
-
instructions: [
|
|
70
|
-
|
|
71
|
-
],
|
|
72
|
-
}
|
|
67
|
+
instructions: [`To write files to the local file system, use the ${writeFilesFunctionName} function`],
|
|
68
|
+
};
|
|
73
69
|
}
|
|
74
70
|
|
|
75
71
|
export const getRecentlyAccessedFilePathsFunctionName = 'getRecentlyAccessedFilePaths';
|
|
@@ -85,7 +81,7 @@ export function getRecentlyAccessedFilePathsFunction(fsModule: ConversationFsMod
|
|
|
85
81
|
},
|
|
86
82
|
},
|
|
87
83
|
call: async () => fsModule.getRecentlyAccessedFilePaths(),
|
|
88
|
-
}
|
|
84
|
+
};
|
|
89
85
|
}
|
|
90
86
|
|
|
91
87
|
const createFolderFunctionName = 'createFolder';
|
|
@@ -101,14 +97,12 @@ const createFolderFunction: Function = {
|
|
|
101
97
|
description: 'Path of the new directory',
|
|
102
98
|
},
|
|
103
99
|
},
|
|
104
|
-
required: ['path']
|
|
100
|
+
required: ['path'],
|
|
105
101
|
},
|
|
106
102
|
},
|
|
107
103
|
call: async (params: { path: string }) => await Fs.createFolder(params.path),
|
|
108
|
-
instructions: [
|
|
109
|
-
|
|
110
|
-
],
|
|
111
|
-
}
|
|
104
|
+
instructions: [`To create a folder on the local file system, use the ${createFolderFunctionName} function`],
|
|
105
|
+
};
|
|
112
106
|
|
|
113
107
|
export const fileOrDirectoryExistsFunctionName = 'fileOrDirectoryExists';
|
|
114
108
|
export const fileOrDirectoryExistsFunction: Function = {
|
|
@@ -123,14 +117,14 @@ export const fileOrDirectoryExistsFunction: Function = {
|
|
|
123
117
|
description: 'Path of the file or directory',
|
|
124
118
|
},
|
|
125
119
|
},
|
|
126
|
-
required: ['path']
|
|
120
|
+
required: ['path'],
|
|
127
121
|
},
|
|
128
122
|
},
|
|
129
123
|
call: async (params: { path: string }) => await Fs.exists(params.path),
|
|
130
124
|
instructions: [
|
|
131
125
|
`To check if a file or folder exists on the local file system, use the ${fileOrDirectoryExistsFunctionName} function`,
|
|
132
126
|
],
|
|
133
|
-
}
|
|
127
|
+
};
|
|
134
128
|
|
|
135
129
|
export const getFilePathsMatchingGlobFunctionName = 'getFilePathsMatchingGlob';
|
|
136
130
|
const getFilePathsMatchingGlobFunction: Function = {
|
|
@@ -156,14 +150,13 @@ const getFilePathsMatchingGlobFunction: Function = {
|
|
|
156
150
|
},
|
|
157
151
|
},
|
|
158
152
|
},
|
|
159
|
-
required: ['dirPrefix', 'glob']
|
|
153
|
+
required: ['dirPrefix', 'glob'],
|
|
160
154
|
},
|
|
161
155
|
},
|
|
162
|
-
call: async (params: { dirPrefix: string
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
156
|
+
call: async (params: { dirPrefix: string; glob: string; globIgnorePatterns?: string[] }) =>
|
|
157
|
+
await Fs.getFilePathsMatchingGlob(params.dirPrefix, params.glob, params.globIgnorePatterns),
|
|
158
|
+
instructions: [`To get file paths matching a glob, use the ${getFilePathsMatchingGlobFunctionName} function`],
|
|
159
|
+
};
|
|
167
160
|
|
|
168
161
|
export const renameFunctionName = 'renameFileOrDirectory';
|
|
169
162
|
const renameFunction: Function = {
|
|
@@ -182,14 +175,12 @@ const renameFunction: Function = {
|
|
|
182
175
|
description: 'New name for the file or directory',
|
|
183
176
|
},
|
|
184
177
|
},
|
|
185
|
-
required: ['oldPath', 'newName']
|
|
178
|
+
required: ['oldPath', 'newName'],
|
|
186
179
|
},
|
|
187
180
|
},
|
|
188
|
-
call: async (params: { oldPath: string
|
|
189
|
-
instructions: [
|
|
190
|
-
|
|
191
|
-
],
|
|
192
|
-
}
|
|
181
|
+
call: async (params: { oldPath: string; newName: string }) => await Fs.rename(params.oldPath, params.newName),
|
|
182
|
+
instructions: [`To rename a file or directory, use the ${renameFunctionName} function`],
|
|
183
|
+
};
|
|
193
184
|
|
|
194
185
|
export const copyFunctionName = 'copyFileOrDirectory';
|
|
195
186
|
const copyFunction: Function = {
|
|
@@ -208,14 +199,13 @@ const copyFunction: Function = {
|
|
|
208
199
|
description: 'Destination path for the copied file or directory',
|
|
209
200
|
},
|
|
210
201
|
},
|
|
211
|
-
required: ['sourcePath', 'destinationPath']
|
|
202
|
+
required: ['sourcePath', 'destinationPath'],
|
|
212
203
|
},
|
|
213
204
|
},
|
|
214
|
-
call: async (params: { sourcePath: string
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
205
|
+
call: async (params: { sourcePath: string; destinationPath: string }) =>
|
|
206
|
+
await Fs.copy(params.sourcePath, params.destinationPath),
|
|
207
|
+
instructions: [`To copy a file or directory, use the ${copyFunctionName} function`],
|
|
208
|
+
};
|
|
219
209
|
|
|
220
210
|
export const moveFunctionName = 'moveFileOrDirectory';
|
|
221
211
|
const moveFunction: Function = {
|
|
@@ -234,14 +224,13 @@ const moveFunction: Function = {
|
|
|
234
224
|
description: 'Destination path for the moved file or directory',
|
|
235
225
|
},
|
|
236
226
|
},
|
|
237
|
-
required: ['sourcePath', 'destinationPath']
|
|
227
|
+
required: ['sourcePath', 'destinationPath'],
|
|
238
228
|
},
|
|
239
229
|
},
|
|
240
|
-
call: async (params: { sourcePath: string
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
230
|
+
call: async (params: { sourcePath: string; destinationPath: string }) =>
|
|
231
|
+
await Fs.move(params.sourcePath, params.destinationPath),
|
|
232
|
+
instructions: [`To move a file or directory, use the ${moveFunctionName} function`],
|
|
233
|
+
};
|
|
245
234
|
|
|
246
235
|
export const fsFunctions: Function[] = [
|
|
247
236
|
createFolderFunction,
|
|
@@ -250,4 +239,4 @@ export const fsFunctions: Function[] = [
|
|
|
250
239
|
renameFunction,
|
|
251
240
|
copyFunction,
|
|
252
241
|
moveFunction,
|
|
253
|
-
]
|
|
242
|
+
];
|
package/src/fs/git/GitModule.ts
CHANGED
|
@@ -22,9 +22,7 @@ export class GitModule implements ConversationModule {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
getFunctions(): Function[] {
|
|
25
|
-
return [
|
|
26
|
-
...gitFunctions,
|
|
27
|
-
];
|
|
25
|
+
return [...gitFunctions];
|
|
28
26
|
}
|
|
29
27
|
|
|
30
28
|
getMessageModerators() {
|
|
@@ -36,4 +34,4 @@ export class GitModuleFactory implements ConversationModuleFactory {
|
|
|
36
34
|
async createModule(repoPath: string): Promise<GitModule> {
|
|
37
35
|
return new GitModule(repoPath);
|
|
38
36
|
}
|
|
39
|
-
}
|
|
37
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { KeywordToFilesIndexModule } from './KeywordToFilesIndexModule'
|
|
1
|
+
import { KeywordToFilesIndexModule } from './KeywordToFilesIndexModule';
|
|
2
2
|
|
|
3
3
|
export const searchFilesFunctionName = 'searchFiles';
|
|
4
4
|
export const searchFilesFunction = (module: KeywordToFilesIndexModule) => {
|
|
@@ -11,10 +11,10 @@ export const searchFilesFunction = (module: KeywordToFilesIndexModule) => {
|
|
|
11
11
|
properties: {
|
|
12
12
|
keyword: {
|
|
13
13
|
type: 'string',
|
|
14
|
-
description: 'Search files for this keyword'
|
|
14
|
+
description: 'Search files for this keyword',
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
|
-
required: ['keyword']
|
|
17
|
+
required: ['keyword'],
|
|
18
18
|
},
|
|
19
19
|
},
|
|
20
20
|
call: async (params: { keyword: string }) => module.searchFiles(params),
|
|
@@ -23,33 +23,33 @@ export const searchFilesFunction = (module: KeywordToFilesIndexModule) => {
|
|
|
23
23
|
`Only call functions that take in filePaths with valid file paths, if you don't know the valid file path try and search for it by keyword with the ${searchFilesFunctionName} function`,
|
|
24
24
|
`If the user references a file in a package without providing a path, use the ${searchFilesFunctionName} function on the keyword to find potentially relevant files, and choose the one that references the package name in its path`,
|
|
25
25
|
],
|
|
26
|
-
}
|
|
27
|
-
}
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
28
|
|
|
29
29
|
// {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
30
|
+
// definition: {
|
|
31
|
+
// name: 'getDeclarations',
|
|
32
|
+
// description: 'Get the typescript declarations of files',
|
|
33
|
+
// parameters: {
|
|
34
|
+
// type: 'object',
|
|
35
|
+
// properties: {
|
|
36
|
+
// tsFilePaths: {
|
|
37
|
+
// type: 'array',
|
|
38
|
+
// description: 'Paths to the files',
|
|
39
|
+
// items: {
|
|
40
|
+
// type: 'string',
|
|
41
|
+
// },
|
|
42
|
+
// },
|
|
43
|
+
// includeDependencyDeclarations: {
|
|
44
|
+
// type: 'boolean',
|
|
45
|
+
// description: 'if true, returns declarations for input tsFilePaths and all dependencies. defaults to false.'
|
|
46
|
+
// },
|
|
47
|
+
// },
|
|
48
|
+
// required: ['tsFilePaths']
|
|
49
|
+
// },
|
|
50
|
+
// },
|
|
51
|
+
// call: async (params: { tsFilePaths: string[] }) => this.repo.getDeclarations(params),
|
|
52
|
+
// instructions: [
|
|
53
|
+
// `Favor calling getDeclarations over readFiles if full file content is not needed`,
|
|
54
|
+
// ],
|
|
55
|
+
// },
|
|
@@ -6,9 +6,9 @@ import path from 'path';
|
|
|
6
6
|
import { searchFilesFunction, searchFilesFunctionName } from './KeywordToFilesIndexFunctions';
|
|
7
7
|
|
|
8
8
|
export type KeywordToFilesIndexModuleParams = {
|
|
9
|
-
dir: string
|
|
10
|
-
keywordFilesIndex: { [keyword: string]: string[] /** file paths */ }
|
|
11
|
-
}
|
|
9
|
+
dir: string;
|
|
10
|
+
keywordFilesIndex: { [keyword: string]: string[] /** file paths */ };
|
|
11
|
+
};
|
|
12
12
|
|
|
13
13
|
export class KeywordToFilesIndexModule implements ConversationModule {
|
|
14
14
|
private logger = new Logger(this.constructor.name);
|
|
@@ -35,9 +35,7 @@ export class KeywordToFilesIndexModule implements ConversationModule {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
getFunctions(): Function[] {
|
|
38
|
-
return [
|
|
39
|
-
searchFilesFunction(this),
|
|
40
|
-
];
|
|
38
|
+
return [searchFilesFunction(this)];
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
getMessageModerators() {
|
|
@@ -50,7 +48,7 @@ export class KeywordToFilesIndexModuleFactory implements ConversationModuleFacto
|
|
|
50
48
|
|
|
51
49
|
async createModule(repoPath: string): Promise<KeywordToFilesIndexModule> {
|
|
52
50
|
this.logger.debug(`Creating module for repo: ${repoPath}`);
|
|
53
|
-
|
|
51
|
+
const repoParams: KeywordToFilesIndexModuleParams = { keywordFilesIndex: {}, dir: repoPath };
|
|
54
52
|
repoParams.keywordFilesIndex = await this.createKeywordFilesIndex(repoPath, ['**/node-typescript-parser/**']);
|
|
55
53
|
this.logger.debug(`Created module for repo: ${repoPath}`);
|
|
56
54
|
return new KeywordToFilesIndexModule(repoParams);
|
|
@@ -58,14 +56,17 @@ export class KeywordToFilesIndexModuleFactory implements ConversationModuleFacto
|
|
|
58
56
|
|
|
59
57
|
/**
|
|
60
58
|
* Create keyword-files index for the given base directory.
|
|
61
|
-
*
|
|
59
|
+
*
|
|
62
60
|
* @param baseDir - The directory to start the file search from.
|
|
63
61
|
* @returns An index with keywords mapped to file paths.
|
|
64
62
|
*/
|
|
65
|
-
async createKeywordFilesIndex(
|
|
63
|
+
async createKeywordFilesIndex(
|
|
64
|
+
baseDir: string,
|
|
65
|
+
globIgnorePatterns: string[] = []
|
|
66
|
+
): Promise<{ [keyword: string]: string[] }> {
|
|
66
67
|
// Ensure the base directory has a trailing slash
|
|
67
68
|
if (!baseDir.endsWith(path.sep)) {
|
|
68
|
-
|
|
69
|
+
baseDir += path.sep;
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
// Get all file paths, recursively, excluding node_modules and dist directories
|
|
@@ -75,14 +76,14 @@ export class KeywordToFilesIndexModuleFactory implements ConversationModuleFacto
|
|
|
75
76
|
|
|
76
77
|
// Process each file path
|
|
77
78
|
for (const filePath of filePaths) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
79
|
+
const fileName = path.parse(filePath).name; // Get file name without extension
|
|
80
|
+
|
|
81
|
+
if (!keywordFilesIndex[fileName]) {
|
|
82
|
+
keywordFilesIndex[fileName] = [];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
this.logger.debug(`fileName: ${fileName}, filePath: ${filePath}`);
|
|
86
|
+
keywordFilesIndex[fileName].push(filePath);
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
return keywordFilesIndex;
|
|
@@ -39,16 +39,15 @@ export const installPackagesFunction: Function = {
|
|
|
39
39
|
cwdPath: {
|
|
40
40
|
type: 'string',
|
|
41
41
|
description: 'The directory to install packages in',
|
|
42
|
-
}
|
|
42
|
+
},
|
|
43
43
|
},
|
|
44
|
-
required: ['packages', 'cwdPath']
|
|
44
|
+
required: ['packages', 'cwdPath'],
|
|
45
45
|
},
|
|
46
46
|
},
|
|
47
|
-
call: async (params: { packages: Package[]
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
47
|
+
call: async (params: { packages: Package[]; cwdPath: string }) =>
|
|
48
|
+
await PackageUtil.installPackages(params.packages, params.cwdPath),
|
|
49
|
+
instructions: [`To install a package, use the ${installPackagesFunctionName} function`],
|
|
50
|
+
};
|
|
52
51
|
|
|
53
52
|
export const runPackageScriptFunctionName = 'runPackageScript';
|
|
54
53
|
const runPackageScriptFunction: Function = {
|
|
@@ -65,16 +64,17 @@ const runPackageScriptFunction: Function = {
|
|
|
65
64
|
cwdPath: {
|
|
66
65
|
type: 'string',
|
|
67
66
|
description: 'If omitted, defaults to process.cwd',
|
|
68
|
-
}
|
|
67
|
+
},
|
|
69
68
|
},
|
|
70
|
-
required: ['name']
|
|
69
|
+
required: ['name'],
|
|
71
70
|
},
|
|
72
71
|
},
|
|
73
|
-
call: async (params: { name: string
|
|
72
|
+
call: async (params: { name: string; cwdPath?: string }) =>
|
|
73
|
+
await PackageUtil.runPackageScript(params.name, params.cwdPath),
|
|
74
74
|
instructions: [
|
|
75
75
|
`To run a npm script (such as start, test, or watch), use the ${runPackageScriptFunctionName} function`,
|
|
76
76
|
],
|
|
77
|
-
}
|
|
77
|
+
};
|
|
78
78
|
|
|
79
79
|
export const searchPackagesFunctionName = 'searchPackages';
|
|
80
80
|
export function searchPackagesFunction(packageModule: PackageModule) {
|
|
@@ -88,16 +88,14 @@ export function searchPackagesFunction(packageModule: PackageModule) {
|
|
|
88
88
|
keyword: {
|
|
89
89
|
type: 'string',
|
|
90
90
|
description: 'Keyword to match package names',
|
|
91
|
-
}
|
|
91
|
+
},
|
|
92
92
|
},
|
|
93
|
-
required: ['keyword']
|
|
93
|
+
required: ['keyword'],
|
|
94
94
|
},
|
|
95
95
|
},
|
|
96
96
|
call: async (params: { keyword: string }) => await packageModule.searchPackages(params.keyword),
|
|
97
|
-
instructions: [
|
|
98
|
-
|
|
99
|
-
],
|
|
100
|
-
}
|
|
97
|
+
instructions: [`To search for packages in the local repo, use the ${searchPackagesFunctionName} function`],
|
|
98
|
+
};
|
|
101
99
|
}
|
|
102
100
|
|
|
103
101
|
export const searchLibrariesFunctionName = 'searchLibraries';
|
|
@@ -112,16 +110,14 @@ export function searchLibrariesFunction(packageModule: PackageModule) {
|
|
|
112
110
|
keyword: {
|
|
113
111
|
type: 'string',
|
|
114
112
|
description: 'Keyword to match file names',
|
|
115
|
-
}
|
|
113
|
+
},
|
|
116
114
|
},
|
|
117
|
-
required: ['keyword']
|
|
115
|
+
required: ['keyword'],
|
|
118
116
|
},
|
|
119
117
|
},
|
|
120
118
|
call: async (params: { keyword: string }) => await packageModule.searchLibraries(params.keyword),
|
|
121
|
-
instructions: [
|
|
122
|
-
|
|
123
|
-
],
|
|
124
|
-
}
|
|
119
|
+
instructions: [`To search for libraries in the local repo, use the ${searchLibrariesFunctionName} function`],
|
|
120
|
+
};
|
|
125
121
|
}
|
|
126
122
|
|
|
127
123
|
export const generateTypescriptDeclarationsFunctionName = 'generateTypescriptDesclarations';
|
|
@@ -137,17 +133,17 @@ export const generateTypescriptDeclarationsFunction = {
|
|
|
137
133
|
description: 'File paths to generate declarations for',
|
|
138
134
|
items: {
|
|
139
135
|
type: 'string',
|
|
140
|
-
}
|
|
141
|
-
}
|
|
136
|
+
},
|
|
137
|
+
},
|
|
142
138
|
},
|
|
143
|
-
required: ['tsFilePaths']
|
|
139
|
+
required: ['tsFilePaths'],
|
|
144
140
|
},
|
|
145
141
|
},
|
|
146
142
|
call: async (params: { tsFilePaths: string[] }) => PackageUtil.generateTypescriptDeclarations(params),
|
|
147
143
|
instructions: [
|
|
148
144
|
`To generate typescript declarations for a local file, use the ${generateTypescriptDeclarationsFunctionName} function`,
|
|
149
145
|
],
|
|
150
|
-
}
|
|
146
|
+
};
|
|
151
147
|
|
|
152
148
|
export const npmInstallFunctionName = 'npmInstall';
|
|
153
149
|
export const npmInstallFunction: Function = {
|
|
@@ -160,16 +156,14 @@ export const npmInstallFunction: Function = {
|
|
|
160
156
|
cwdPath: {
|
|
161
157
|
type: 'string',
|
|
162
158
|
description: 'Directory to execute the command from',
|
|
163
|
-
}
|
|
159
|
+
},
|
|
164
160
|
},
|
|
165
|
-
required: ['cwdPath']
|
|
161
|
+
required: ['cwdPath'],
|
|
166
162
|
},
|
|
167
163
|
},
|
|
168
164
|
call: async (params: { cwdPath: string }) => await PackageUtil.npmInstall(params.cwdPath),
|
|
169
|
-
instructions: [
|
|
170
|
-
|
|
171
|
-
],
|
|
172
|
-
}
|
|
165
|
+
instructions: [`To run npm install in a specific directory, use the ${npmInstallFunctionName} function`],
|
|
166
|
+
};
|
|
173
167
|
|
|
174
168
|
export const uninstallPackagesFunctionName = 'uninstallPackages';
|
|
175
169
|
export const uninstallPackagesFunction: Function = {
|
|
@@ -190,16 +184,15 @@ export const uninstallPackagesFunction: Function = {
|
|
|
190
184
|
cwdPath: {
|
|
191
185
|
type: 'string',
|
|
192
186
|
description: 'The directory to uninstall packages from',
|
|
193
|
-
}
|
|
187
|
+
},
|
|
194
188
|
},
|
|
195
|
-
required: ['packageNames', 'cwdPath']
|
|
189
|
+
required: ['packageNames', 'cwdPath'],
|
|
196
190
|
},
|
|
197
191
|
},
|
|
198
|
-
call: async (params: { packageNames: string[]
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
192
|
+
call: async (params: { packageNames: string[]; cwdPath: string }) =>
|
|
193
|
+
await PackageUtil.uninstallPackages(params.packageNames, params.cwdPath),
|
|
194
|
+
instructions: [`To uninstall a package, use the ${uninstallPackagesFunctionName} function`],
|
|
195
|
+
};
|
|
203
196
|
|
|
204
197
|
export const packageFunctions: Function[] = [
|
|
205
198
|
installPackagesFunction,
|
|
@@ -207,4 +200,4 @@ export const packageFunctions: Function[] = [
|
|
|
207
200
|
generateTypescriptDeclarationsFunction,
|
|
208
201
|
npmInstallFunction,
|
|
209
202
|
uninstallPackagesFunction,
|
|
210
|
-
]
|
|
203
|
+
];
|