@proteinjs/conversation 1.0.6 → 1.0.8
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/.prettierignore +4 -0
- package/.prettierrc +8 -0
- package/CHANGELOG.md +18 -4
- package/LICENSE +21 -0
- package/dist/src/CodegenConversation.d.ts.map +1 -1
- package/dist/src/CodegenConversation.js +2 -2
- package/dist/src/CodegenConversation.js.map +1 -1
- package/dist/src/Conversation.d.ts.map +1 -1
- package/dist/src/Conversation.js +33 -17
- package/dist/src/Conversation.js.map +1 -1
- package/dist/src/Function.d.ts.map +1 -1
- package/dist/src/OpenAi.d.ts.map +1 -1
- package/dist/src/OpenAi.js +55 -38
- package/dist/src/OpenAi.js.map +1 -1
- package/dist/src/Paragraph.d.ts.map +1 -1
- package/dist/src/Paragraph.js +2 -1
- package/dist/src/Paragraph.js.map +1 -1
- package/dist/src/Sentence.d.ts.map +1 -1
- package/dist/src/Sentence.js +4 -2
- package/dist/src/Sentence.js.map +1 -1
- package/dist/src/code_template/Code.d.ts.map +1 -1
- package/dist/src/code_template/Code.js +6 -2
- package/dist/src/code_template/Code.js.map +1 -1
- package/dist/src/code_template/CodeTemplate.d.ts.map +1 -1
- package/dist/src/code_template/CodeTemplate.js +2 -1
- package/dist/src/code_template/CodeTemplate.js.map +1 -1
- package/dist/src/code_template/Repo.d.ts.map +1 -1
- package/dist/src/code_template/Repo.js +8 -4
- package/dist/src/code_template/Repo.js.map +1 -1
- package/dist/src/fs/conversation_fs/ConversationFsModerator.d.ts.map +1 -1
- package/dist/src/fs/conversation_fs/ConversationFsModerator.js +18 -7
- package/dist/src/fs/conversation_fs/ConversationFsModerator.js.map +1 -1
- package/dist/src/fs/conversation_fs/ConversationFsModule.d.ts.map +1 -1
- package/dist/src/fs/conversation_fs/ConversationFsModule.js +1 -3
- package/dist/src/fs/conversation_fs/ConversationFsModule.js.map +1 -1
- package/dist/src/fs/conversation_fs/FsFunctions.d.ts.map +1 -1
- package/dist/src/fs/conversation_fs/FsFunctions.js +15 -29
- package/dist/src/fs/conversation_fs/FsFunctions.js.map +1 -1
- package/dist/src/fs/git/GitModule.d.ts.map +1 -1
- package/dist/src/fs/git/GitModule.js.map +1 -1
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.d.ts.map +1 -1
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.js +2 -2
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.js.map +1 -1
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.d.ts.map +1 -1
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.js +1 -3
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.js.map +1 -1
- package/dist/src/fs/package/PackageFunctions.d.ts.map +1 -1
- package/dist/src/fs/package/PackageFunctions.js +20 -30
- package/dist/src/fs/package/PackageFunctions.js.map +1 -1
- package/dist/src/fs/package/PackageModule.d.ts.map +1 -1
- package/dist/src/fs/package/PackageModule.js +15 -8
- package/dist/src/fs/package/PackageModule.js.map +1 -1
- package/dist/src/history/MessageHistory.d.ts.map +1 -1
- package/dist/src/history/MessageHistory.js +6 -3
- package/dist/src/history/MessageHistory.js.map +1 -1
- package/dist/src/template/ConversationTemplate.d.ts.map +1 -1
- package/dist/src/template/ConversationTemplateFunctions.d.ts.map +1 -1
- package/dist/src/template/ConversationTemplateFunctions.js +2 -2
- package/dist/src/template/ConversationTemplateFunctions.js.map +1 -1
- package/dist/src/template/ConversationTemplateModule.d.ts.map +1 -1
- package/dist/src/template/ConversationTemplateModule.js +9 -7
- package/dist/src/template/ConversationTemplateModule.js.map +1 -1
- package/dist/src/template/createCode/CreateCodeConversationTemplate.d.ts.map +1 -1
- package/dist/src/template/createCode/CreateCodeConversationTemplate.js +2 -9
- package/dist/src/template/createCode/CreateCodeConversationTemplate.js.map +1 -1
- package/dist/src/template/createPackage/CreatePackageConversationTemplate.d.ts.map +1 -1
- package/dist/src/template/createPackage/CreatePackageConversationTemplate.js +1 -8
- package/dist/src/template/createPackage/CreatePackageConversationTemplate.js.map +1 -1
- package/dist/test/createKeywordFilesIndex.test.js.map +1 -1
- package/dist/test/openai/openai.generateList.test.js.map +1 -1
- package/dist/test/openai/openai.parseCodeFromMarkdown.test.js +7 -3
- package/dist/test/openai/openai.parseCodeFromMarkdown.test.js.map +1 -1
- package/dist/test/repo/repo.test.js.map +1 -1
- package/jest.config.js +2 -2
- package/package.json +9 -3
- 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,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
|
+
];
|
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
import { Fs } from '@proteinjs/util-node';
|
|
2
2
|
import { ConversationModule, ConversationModuleFactory } from '../../ConversationModule';
|
|
3
3
|
import { Function } from '../../Function';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
packageFunctions,
|
|
6
|
+
searchLibrariesFunction,
|
|
7
|
+
searchLibrariesFunctionName,
|
|
8
|
+
searchPackagesFunction,
|
|
9
|
+
searchPackagesFunctionName,
|
|
10
|
+
} from './PackageFunctions';
|
|
5
11
|
import path from 'path';
|
|
6
12
|
import { searchFilesFunctionName } from '../keyword_to_files_index/KeywordToFilesIndexFunctions';
|
|
7
13
|
import { readFilesFunctionName } from '../conversation_fs/FsFunctions';
|
|
8
14
|
|
|
9
15
|
export type Library = {
|
|
10
|
-
fileName: string
|
|
11
|
-
filePath: string
|
|
12
|
-
packageName: string
|
|
13
|
-
}
|
|
16
|
+
fileName: string;
|
|
17
|
+
filePath: string;
|
|
18
|
+
packageName: string;
|
|
19
|
+
};
|
|
14
20
|
|
|
15
21
|
export type LibraryImport = {
|
|
16
|
-
importStatements: string[]
|
|
17
|
-
typescriptDeclaration: string
|
|
18
|
-
}
|
|
22
|
+
importStatements: string[];
|
|
23
|
+
typescriptDeclaration: string;
|
|
24
|
+
};
|
|
19
25
|
|
|
20
26
|
export class PackageModule implements ConversationModule {
|
|
21
27
|
private repoPath: string;
|
|
@@ -39,11 +45,7 @@ export class PackageModule implements ConversationModule {
|
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
getFunctions(): Function[] {
|
|
42
|
-
return [
|
|
43
|
-
...packageFunctions,
|
|
44
|
-
searchPackagesFunction(this),
|
|
45
|
-
searchLibrariesFunction(this),
|
|
46
|
-
];
|
|
48
|
+
return [...packageFunctions, searchPackagesFunction(this), searchLibrariesFunction(this)];
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
getMessageModerators() {
|
|
@@ -56,12 +58,16 @@ export class PackageModule implements ConversationModule {
|
|
|
56
58
|
*/
|
|
57
59
|
async searchPackages(keyword: string): Promise<string[]> {
|
|
58
60
|
const matchingPackageJsonPaths: string[] = [];
|
|
59
|
-
const packageJsonFilePaths = await Fs.getFilePathsMatchingGlob(this.repoPath, '**/package.json', [
|
|
61
|
+
const packageJsonFilePaths = await Fs.getFilePathsMatchingGlob(this.repoPath, '**/package.json', [
|
|
62
|
+
'**/node_modules/**',
|
|
63
|
+
'**/dist/**',
|
|
64
|
+
]);
|
|
60
65
|
const packageJsonFileMap = await Fs.readFiles(packageJsonFilePaths);
|
|
61
|
-
for (
|
|
66
|
+
for (const packageJsonFilePath of Object.keys(packageJsonFileMap)) {
|
|
62
67
|
const packageJson = JSON.parse(packageJsonFileMap[packageJsonFilePath]);
|
|
63
|
-
if (packageJson.name.toLowerCase().includes(keyword.toLocaleLowerCase()))
|
|
68
|
+
if (packageJson.name.toLowerCase().includes(keyword.toLocaleLowerCase())) {
|
|
64
69
|
matchingPackageJsonPaths.push(packageJsonFilePath);
|
|
70
|
+
}
|
|
65
71
|
}
|
|
66
72
|
|
|
67
73
|
return matchingPackageJsonPaths;
|
|
@@ -74,15 +80,21 @@ export class PackageModule implements ConversationModule {
|
|
|
74
80
|
*/
|
|
75
81
|
async searchLibraries(keyword: string): Promise<Library[]> {
|
|
76
82
|
const matchingLibraries: Library[] = [];
|
|
77
|
-
const packageJsonFilePaths = await Fs.getFilePathsMatchingGlob(this.repoPath, '**/package.json', [
|
|
83
|
+
const packageJsonFilePaths = await Fs.getFilePathsMatchingGlob(this.repoPath, '**/package.json', [
|
|
84
|
+
'**/node_modules/**',
|
|
85
|
+
'**/dist/**',
|
|
86
|
+
]);
|
|
78
87
|
const packageJsonFileMap = await Fs.readFiles(packageJsonFilePaths);
|
|
79
|
-
for (
|
|
88
|
+
for (const packageJsonFilePath of Object.keys(packageJsonFileMap)) {
|
|
80
89
|
const packageJson = JSON.parse(packageJsonFileMap[packageJsonFilePath]);
|
|
81
90
|
const packageJsonFilePathParts = packageJsonFilePath.split(path.sep);
|
|
82
91
|
packageJsonFilePathParts.pop();
|
|
83
92
|
const packageDirectory = packageJsonFilePathParts.join(path.sep);
|
|
84
|
-
const srcFilePaths = await Fs.getFilePathsMatchingGlob(path.join(packageDirectory, 'src'), '**/*.ts', [
|
|
85
|
-
|
|
93
|
+
const srcFilePaths = await Fs.getFilePathsMatchingGlob(path.join(packageDirectory, 'src'), '**/*.ts', [
|
|
94
|
+
'**/node_modules/**',
|
|
95
|
+
'**/dist/**',
|
|
96
|
+
]);
|
|
97
|
+
for (const srcFilePath of srcFilePaths) {
|
|
86
98
|
const fileNameWithExtension = path.basename(srcFilePath);
|
|
87
99
|
if (fileNameWithExtension.includes(keyword)) {
|
|
88
100
|
const fileName = path.basename(srcFilePath, path.extname(srcFilePath));
|
|
@@ -103,4 +115,4 @@ export class PackageModuleFactory implements ConversationModuleFactory {
|
|
|
103
115
|
async createModule(repoPath: string): Promise<PackageModule> {
|
|
104
116
|
return new PackageModule(repoPath);
|
|
105
117
|
}
|
|
106
|
-
}
|
|
118
|
+
}
|
|
@@ -20,7 +20,7 @@ export class MessageHistory {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
toString() {
|
|
23
|
-
return this.messages.map(message => message.content).join('. ');
|
|
23
|
+
return this.messages.map((message) => message.content).join('. ');
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
setMessages(messages: ChatCompletionMessageParam[]): MessageHistory {
|
|
@@ -36,19 +36,22 @@ export class MessageHistory {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
prune() {
|
|
39
|
-
if (this.params.enforceMessageLimit === false)
|
|
39
|
+
if (this.params.enforceMessageLimit === false) {
|
|
40
40
|
return;
|
|
41
|
+
}
|
|
41
42
|
|
|
42
43
|
let messageCount = 0;
|
|
43
44
|
const messagesToRemoveIndexes: number[] = [];
|
|
44
45
|
for (let i = this.messages.length - 1; i >= 0; i--) {
|
|
45
46
|
const message = this.messages[i];
|
|
46
|
-
if (message.role == 'system')
|
|
47
|
+
if (message.role == 'system') {
|
|
47
48
|
continue;
|
|
49
|
+
}
|
|
48
50
|
|
|
49
51
|
messageCount++;
|
|
50
|
-
if (messageCount > this.params.maxMessages)
|
|
52
|
+
if (messageCount > this.params.maxMessages) {
|
|
51
53
|
messagesToRemoveIndexes.push(i);
|
|
54
|
+
}
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
this.messages = this.messages.filter((message, i) => !messagesToRemoveIndexes.includes(i));
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export type Question = {
|
|
2
|
-
text: string
|
|
3
|
-
optional?: boolean
|
|
4
|
-
}
|
|
2
|
+
text: string;
|
|
3
|
+
optional?: boolean;
|
|
4
|
+
};
|
|
5
5
|
|
|
6
6
|
export type ConversationTemplate = {
|
|
7
|
-
name: string
|
|
8
|
-
keywords: string[]
|
|
9
|
-
description: string
|
|
10
|
-
questions: Question[]
|
|
11
|
-
instructions: () => Promise<string[]
|
|
12
|
-
}
|
|
7
|
+
name: string;
|
|
8
|
+
keywords: string[];
|
|
9
|
+
description: string;
|
|
10
|
+
questions: Question[];
|
|
11
|
+
instructions: () => Promise<string[]>;
|
|
12
|
+
};
|
|
@@ -14,12 +14,12 @@ export const searchConversationTemplatesFunction = (repo: ConversationTemplateMo
|
|
|
14
14
|
description: 'Search for conversation template names that match this keyword',
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
|
-
required: ['keyword']
|
|
17
|
+
required: ['keyword'],
|
|
18
18
|
},
|
|
19
19
|
},
|
|
20
20
|
call: async (params: { keyword: string }) => repo.searchConversationTemplates(params.keyword),
|
|
21
|
-
}
|
|
22
|
-
}
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
23
|
|
|
24
24
|
export const getConversationTemplateFunctionName = 'getConversationTemplate';
|
|
25
25
|
export const getConversationTemplateFunction = (repo: ConversationTemplateModule) => {
|
|
@@ -35,9 +35,10 @@ export const getConversationTemplateFunction = (repo: ConversationTemplateModule
|
|
|
35
35
|
description: 'Get the conversation template that has this name',
|
|
36
36
|
},
|
|
37
37
|
},
|
|
38
|
-
required: ['conversationTemplateName']
|
|
38
|
+
required: ['conversationTemplateName'],
|
|
39
39
|
},
|
|
40
40
|
},
|
|
41
|
-
call: async (params: { conversationTemplateName: string }) =>
|
|
42
|
-
|
|
43
|
-
}
|
|
41
|
+
call: async (params: { conversationTemplateName: string }) =>
|
|
42
|
+
await repo.getConversationTemplate(params.conversationTemplateName),
|
|
43
|
+
};
|
|
44
|
+
};
|
|
@@ -2,7 +2,12 @@ import { Logger } from '@proteinjs/util';
|
|
|
2
2
|
import { ConversationTemplate } from './ConversationTemplate';
|
|
3
3
|
import { createPackageConversationTemplate } from './createPackage/CreatePackageConversationTemplate';
|
|
4
4
|
import { ConversationModule, ConversationModuleFactory } from '../ConversationModule';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
getConversationTemplateFunction,
|
|
7
|
+
getConversationTemplateFunctionName,
|
|
8
|
+
searchConversationTemplatesFunction,
|
|
9
|
+
searchConversationTemplatesFunctionName,
|
|
10
|
+
} from './ConversationTemplateFunctions';
|
|
6
11
|
import { createCodeConversationTemplate } from './createCode/CreateCodeConversationTemplate';
|
|
7
12
|
import { createAppTemplate } from './createApp/CreateAppTemplate';
|
|
8
13
|
|
|
@@ -13,9 +18,9 @@ const conversationTemplates: ConversationTemplate[] = [
|
|
|
13
18
|
];
|
|
14
19
|
|
|
15
20
|
export type ConversationTemplateModuleParams = {
|
|
16
|
-
conversationTemplates: { [conversationTemplateName: string]: ConversationTemplate}
|
|
17
|
-
conversationTemplateKeywordIndex: { [keyword: string]: string[] /** conversationTemplateNames */ }
|
|
18
|
-
}
|
|
21
|
+
conversationTemplates: { [conversationTemplateName: string]: ConversationTemplate };
|
|
22
|
+
conversationTemplateKeywordIndex: { [keyword: string]: string[] /** conversationTemplateNames */ };
|
|
23
|
+
};
|
|
19
24
|
|
|
20
25
|
export class ConversationTemplateModule implements ConversationModule {
|
|
21
26
|
private logger = new Logger(this.constructor.name);
|
|
@@ -35,10 +40,13 @@ export class ConversationTemplateModule implements ConversationModule {
|
|
|
35
40
|
return conversationNames || [];
|
|
36
41
|
}
|
|
37
42
|
|
|
38
|
-
async getConversationTemplate(
|
|
43
|
+
async getConversationTemplate(
|
|
44
|
+
conversationTemplateName: string
|
|
45
|
+
): Promise<Omit<ConversationTemplate, 'instructions'> & { instructions: string[] }> {
|
|
39
46
|
const conversationTemplate = this.params.conversationTemplates[conversationTemplateName];
|
|
40
|
-
if (!conversationTemplate)
|
|
47
|
+
if (!conversationTemplate) {
|
|
41
48
|
return {} as any;
|
|
49
|
+
}
|
|
42
50
|
|
|
43
51
|
const instructions = await conversationTemplate.instructions();
|
|
44
52
|
return Object.assign(conversationTemplate, { instructions });
|
|
@@ -54,10 +62,7 @@ export class ConversationTemplateModule implements ConversationModule {
|
|
|
54
62
|
}
|
|
55
63
|
|
|
56
64
|
getFunctions() {
|
|
57
|
-
return [
|
|
58
|
-
searchConversationTemplatesFunction(this),
|
|
59
|
-
getConversationTemplateFunction(this),
|
|
60
|
-
];
|
|
65
|
+
return [searchConversationTemplatesFunction(this), getConversationTemplateFunction(this)];
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
getMessageModerators() {
|
|
@@ -67,12 +72,16 @@ export class ConversationTemplateModule implements ConversationModule {
|
|
|
67
72
|
|
|
68
73
|
export class ConversationTemplateModuleFactory implements ConversationModuleFactory {
|
|
69
74
|
async createModule(repoPath: string) {
|
|
70
|
-
const params: ConversationTemplateModuleParams = {
|
|
71
|
-
|
|
75
|
+
const params: ConversationTemplateModuleParams = {
|
|
76
|
+
conversationTemplates: {},
|
|
77
|
+
conversationTemplateKeywordIndex: {},
|
|
78
|
+
};
|
|
79
|
+
for (const conversationTemplate of conversationTemplates) {
|
|
72
80
|
params.conversationTemplates[conversationTemplate.name] = conversationTemplate;
|
|
73
|
-
for (
|
|
74
|
-
if (!params.conversationTemplateKeywordIndex[keyword])
|
|
81
|
+
for (const keyword of conversationTemplate.keywords) {
|
|
82
|
+
if (!params.conversationTemplateKeywordIndex[keyword]) {
|
|
75
83
|
params.conversationTemplateKeywordIndex[keyword] = [];
|
|
84
|
+
}
|
|
76
85
|
|
|
77
86
|
params.conversationTemplateKeywordIndex[keyword].push(conversationTemplate.name);
|
|
78
87
|
}
|
|
@@ -80,4 +89,4 @@ export class ConversationTemplateModuleFactory implements ConversationModuleFact
|
|
|
80
89
|
|
|
81
90
|
return new ConversationTemplateModule(params);
|
|
82
91
|
}
|
|
83
|
-
}
|
|
92
|
+
}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { fileOrDirectoryExistsFunction, readFilesFunctionName } from '../../fs/conversation_fs/FsFunctions';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
generateTypescriptDeclarationsFunction,
|
|
4
|
+
installPackagesFunction,
|
|
5
|
+
searchLibrariesFunctionName,
|
|
6
|
+
searchPackagesFunctionName,
|
|
7
|
+
} from '../../fs/package/PackageFunctions';
|
|
3
8
|
import { ConversationTemplate } from '../ConversationTemplate';
|
|
4
9
|
|
|
5
10
|
export const createCodeConversationTemplate: ConversationTemplate = {
|
|
6
11
|
name: 'Create code',
|
|
7
|
-
keywords: [
|
|
8
|
-
'create code',
|
|
9
|
-
'implement',
|
|
10
|
-
'write code',
|
|
11
|
-
'generate code',
|
|
12
|
-
'write software',
|
|
13
|
-
'build something',
|
|
14
|
-
],
|
|
12
|
+
keywords: ['create code', 'implement', 'write code', 'generate code', 'write software', 'build something'],
|
|
15
13
|
description: 'User and ai developing together',
|
|
16
14
|
questions: [],
|
|
17
15
|
instructions: async () => {
|
|
@@ -37,5 +35,5 @@ export const createCodeConversationTemplate: ConversationTemplate = {
|
|
|
37
35
|
`3.c. When writing the code to file, if updating an existing file, be sure to read the file first to not blow away existing code. Be sure to preserve comments as well.`,
|
|
38
36
|
`4. Repeat 3. unless the user asks to switch packages or files`,
|
|
39
37
|
];
|
|
40
|
-
}
|
|
41
|
-
}
|
|
38
|
+
},
|
|
39
|
+
};
|
|
@@ -5,14 +5,7 @@ import tConfig from './tsconfig.json';
|
|
|
5
5
|
|
|
6
6
|
export const createPackageConversationTemplate: ConversationTemplate = {
|
|
7
7
|
name: 'Create Package',
|
|
8
|
-
keywords: [
|
|
9
|
-
'package',
|
|
10
|
-
'create package',
|
|
11
|
-
'create',
|
|
12
|
-
'create a package',
|
|
13
|
-
'create a new package',
|
|
14
|
-
`new package`,
|
|
15
|
-
],
|
|
8
|
+
keywords: ['package', 'create package', 'create', 'create a package', 'create a new package', `new package`],
|
|
16
9
|
description: 'Create a npm package',
|
|
17
10
|
questions: [
|
|
18
11
|
{ text: `Which folder should the package be created in?` },
|
|
@@ -39,4 +32,4 @@ export const createPackageConversationTemplate: ConversationTemplate = {
|
|
|
39
32
|
`If it's a typescript project, create a tsconfig.json file in the pakage directory with the following content: ${tsConfig}`,
|
|
40
33
|
];
|
|
41
34
|
},
|
|
42
|
-
}
|
|
35
|
+
};
|