@proteinjs/conversation 1.0.1
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/CHANGELOG.md +8 -0
- package/LICENSE +21 -0
- package/dist/index.js +27 -0
- package/dist/jest.config.js +10 -0
- package/dist/src/CodegenConversation.js +120 -0
- package/dist/src/Conversation.js +193 -0
- package/dist/src/ConversationModule.js +2 -0
- package/dist/src/Function.js +2 -0
- package/dist/src/OpenAi.js +209 -0
- package/dist/src/Paragraph.js +18 -0
- package/dist/src/Sentence.js +22 -0
- package/dist/src/code_template/Code.js +41 -0
- package/dist/src/code_template/CodeTemplate.js +39 -0
- package/dist/src/code_template/CodeTemplateModule.js +46 -0
- package/dist/src/code_template/Repo.js +127 -0
- package/dist/src/fs/conversation_fs/ConversationFsModerator.js +99 -0
- package/dist/src/fs/conversation_fs/ConversationFsModule.js +68 -0
- package/dist/src/fs/conversation_fs/FsFunctions.js +256 -0
- package/dist/src/fs/git/GitModule.js +45 -0
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.js +65 -0
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.js +89 -0
- package/dist/src/fs/package/PackageFunctions.js +214 -0
- package/dist/src/fs/package/PackageModule.js +102 -0
- package/dist/src/history/MessageHistory.js +44 -0
- package/dist/src/history/MessageModerator.js +2 -0
- package/dist/src/template/ConversationTemplate.js +2 -0
- package/dist/src/template/ConversationTemplateFunctions.js +54 -0
- package/dist/src/template/ConversationTemplateModule.js +80 -0
- package/dist/src/template/createApp/CreateAppTemplate.js +40 -0
- package/dist/src/template/createCode/CreateCodeConversationTemplate.js +51 -0
- package/dist/src/template/createPackage/CreatePackageConversationTemplate.js +54 -0
- package/dist/src/template/createPackage/jest.config.js +10 -0
- package/dist/src/template/createPackage/tsconfig.json +13 -0
- package/dist/test/createKeywordFilesIndex.test.js +17 -0
- package/dist/test/openai/openai.generateList.test.js +16 -0
- package/dist/test/openai/openai.parseCodeFromMarkdown.test.js +18 -0
- package/dist/test/repo/repo.test.js +29 -0
- package/dist/test/setup.js +1 -0
- package/index.ts +11 -0
- package/jest.config.js +9 -0
- package/package.json +34 -0
- package/src/CodegenConversation.ts +92 -0
- package/src/Conversation.ts +207 -0
- package/src/ConversationModule.ts +13 -0
- package/src/Function.ts +8 -0
- package/src/OpenAi.ts +212 -0
- package/src/Paragraph.ts +17 -0
- package/src/Sentence.ts +20 -0
- package/src/code_template/Code.ts +53 -0
- package/src/code_template/CodeTemplate.ts +39 -0
- package/src/code_template/CodeTemplateModule.ts +50 -0
- package/src/code_template/Repo.ts +156 -0
- package/src/fs/conversation_fs/ConversationFsModerator.ts +121 -0
- package/src/fs/conversation_fs/ConversationFsModule.ts +64 -0
- package/src/fs/conversation_fs/FsFunctions.ts +253 -0
- package/src/fs/git/GitModule.ts +39 -0
- package/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.ts +55 -0
- package/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.ts +90 -0
- package/src/fs/package/PackageFunctions.ts +210 -0
- package/src/fs/package/PackageModule.ts +106 -0
- package/src/history/MessageHistory.ts +57 -0
- package/src/history/MessageModerator.ts +6 -0
- package/src/template/ConversationTemplate.ts +12 -0
- package/src/template/ConversationTemplateFunctions.ts +43 -0
- package/src/template/ConversationTemplateModule.ts +83 -0
- package/src/template/createApp/CreateAppTemplate.ts +33 -0
- package/src/template/createCode/CreateCodeConversationTemplate.ts +41 -0
- package/src/template/createPackage/CreatePackageConversationTemplate.ts +42 -0
- package/src/template/createPackage/jest.config.js +9 -0
- package/src/template/createPackage/tsconfig.json +13 -0
- package/test/createKeywordFilesIndex.test.ts +7 -0
- package/test/openai/openai.generateList.test.ts +6 -0
- package/test/openai/openai.parseCodeFromMarkdown.test.ts +20 -0
- package/test/repo/repo.test.ts +33 -0
- package/test/setup.js +0 -0
- package/tsconfig.json +109 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.fsFunctions = exports.moveFunctionName = exports.copyFunctionName = exports.renameFunctionName = exports.getFilePathsMatchingGlobFunctionName = exports.fileOrDirectoryExistsFunction = exports.fileOrDirectoryExistsFunctionName = exports.getRecentlyAccessedFilePathsFunction = exports.getRecentlyAccessedFilePathsFunctionName = exports.writeFilesFunction = exports.writeFilesFunctionName = exports.readFilesFunction = exports.readFilesFunctionName = void 0;
|
|
13
|
+
const util_node_1 = require("@proteinjs/util-node");
|
|
14
|
+
exports.readFilesFunctionName = 'readFiles';
|
|
15
|
+
function readFilesFunction(fsModule) {
|
|
16
|
+
return {
|
|
17
|
+
definition: {
|
|
18
|
+
name: exports.readFilesFunctionName,
|
|
19
|
+
description: 'Get the content of files',
|
|
20
|
+
parameters: {
|
|
21
|
+
type: 'object',
|
|
22
|
+
properties: {
|
|
23
|
+
filePaths: {
|
|
24
|
+
type: 'array',
|
|
25
|
+
description: 'Paths to the files',
|
|
26
|
+
items: {
|
|
27
|
+
type: 'string',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
required: ['filePaths']
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
call: (params) => __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
fsModule.pushRecentlyAccessedFilePath(params.filePaths);
|
|
36
|
+
return yield util_node_1.Fs.readFiles(params.filePaths);
|
|
37
|
+
}),
|
|
38
|
+
instructions: [
|
|
39
|
+
`To read files from the local file system, use the ${exports.readFilesFunctionName} function`,
|
|
40
|
+
],
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
exports.readFilesFunction = readFilesFunction;
|
|
44
|
+
exports.writeFilesFunctionName = 'writeFiles';
|
|
45
|
+
function writeFilesFunction(fsModule) {
|
|
46
|
+
return {
|
|
47
|
+
definition: {
|
|
48
|
+
name: exports.writeFilesFunctionName,
|
|
49
|
+
description: 'Write files to the file system',
|
|
50
|
+
parameters: {
|
|
51
|
+
type: 'object',
|
|
52
|
+
properties: {
|
|
53
|
+
files: {
|
|
54
|
+
type: 'array',
|
|
55
|
+
description: 'Files to write',
|
|
56
|
+
items: {
|
|
57
|
+
type: 'object',
|
|
58
|
+
properties: {
|
|
59
|
+
path: {
|
|
60
|
+
type: 'string',
|
|
61
|
+
description: 'the file path',
|
|
62
|
+
},
|
|
63
|
+
content: {
|
|
64
|
+
type: 'string',
|
|
65
|
+
description: 'the content to write to the file',
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
required: ['files']
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
call: (params) => __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
fsModule.pushRecentlyAccessedFilePath(params.files.map(file => file.path));
|
|
76
|
+
return yield util_node_1.Fs.writeFiles(params.files);
|
|
77
|
+
}),
|
|
78
|
+
instructions: [
|
|
79
|
+
`To write files to the local file system, use the ${exports.writeFilesFunctionName} function`,
|
|
80
|
+
],
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
exports.writeFilesFunction = writeFilesFunction;
|
|
84
|
+
exports.getRecentlyAccessedFilePathsFunctionName = 'getRecentlyAccessedFilePaths';
|
|
85
|
+
function getRecentlyAccessedFilePathsFunction(fsModule) {
|
|
86
|
+
return {
|
|
87
|
+
definition: {
|
|
88
|
+
name: exports.getRecentlyAccessedFilePathsFunctionName,
|
|
89
|
+
description: 'Get paths of files accessed during this conversation, in order from oldest to newest',
|
|
90
|
+
parameters: {
|
|
91
|
+
type: 'object',
|
|
92
|
+
properties: {},
|
|
93
|
+
required: [],
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
call: () => __awaiter(this, void 0, void 0, function* () { return fsModule.getRecentlyAccessedFilePaths(); }),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
exports.getRecentlyAccessedFilePathsFunction = getRecentlyAccessedFilePathsFunction;
|
|
100
|
+
const createFolderFunctionName = 'createFolder';
|
|
101
|
+
const createFolderFunction = {
|
|
102
|
+
definition: {
|
|
103
|
+
name: createFolderFunctionName,
|
|
104
|
+
description: 'Create a folder/directory',
|
|
105
|
+
parameters: {
|
|
106
|
+
type: 'object',
|
|
107
|
+
properties: {
|
|
108
|
+
path: {
|
|
109
|
+
type: 'string',
|
|
110
|
+
description: 'Path of the new directory',
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
required: ['path']
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
call: (params) => __awaiter(void 0, void 0, void 0, function* () { return yield util_node_1.Fs.createFolder(params.path); }),
|
|
117
|
+
instructions: [
|
|
118
|
+
`To create a folder on the local file system, use the ${createFolderFunctionName} function`,
|
|
119
|
+
],
|
|
120
|
+
};
|
|
121
|
+
exports.fileOrDirectoryExistsFunctionName = 'fileOrDirectoryExists';
|
|
122
|
+
exports.fileOrDirectoryExistsFunction = {
|
|
123
|
+
definition: {
|
|
124
|
+
name: exports.fileOrDirectoryExistsFunctionName,
|
|
125
|
+
description: 'Check if a file or directory exists',
|
|
126
|
+
parameters: {
|
|
127
|
+
type: 'object',
|
|
128
|
+
properties: {
|
|
129
|
+
path: {
|
|
130
|
+
type: 'string',
|
|
131
|
+
description: 'Path of the file or directory',
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
required: ['path']
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
call: (params) => __awaiter(void 0, void 0, void 0, function* () { return yield util_node_1.Fs.exists(params.path); }),
|
|
138
|
+
instructions: [
|
|
139
|
+
`To check if a file or folder exists on the local file system, use the ${exports.fileOrDirectoryExistsFunctionName} function`,
|
|
140
|
+
],
|
|
141
|
+
};
|
|
142
|
+
exports.getFilePathsMatchingGlobFunctionName = 'getFilePathsMatchingGlob';
|
|
143
|
+
const getFilePathsMatchingGlobFunction = {
|
|
144
|
+
definition: {
|
|
145
|
+
name: exports.getFilePathsMatchingGlobFunctionName,
|
|
146
|
+
description: 'Get file paths matching a glob',
|
|
147
|
+
parameters: {
|
|
148
|
+
type: 'object',
|
|
149
|
+
properties: {
|
|
150
|
+
dirPrefix: {
|
|
151
|
+
type: 'string',
|
|
152
|
+
description: 'Directory to recursively search for files',
|
|
153
|
+
},
|
|
154
|
+
glob: {
|
|
155
|
+
type: 'string',
|
|
156
|
+
description: 'File matching pattern',
|
|
157
|
+
},
|
|
158
|
+
globIgnorePatterns: {
|
|
159
|
+
type: 'array',
|
|
160
|
+
description: 'Directories to ignore',
|
|
161
|
+
items: {
|
|
162
|
+
type: 'string',
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
required: ['dirPrefix', 'glob']
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
call: (params) => __awaiter(void 0, void 0, void 0, function* () { return yield util_node_1.Fs.getFilePathsMatchingGlob(params.dirPrefix, params.glob, params.globIgnorePatterns); }),
|
|
170
|
+
instructions: [
|
|
171
|
+
`To get file paths matching a glob, use the ${exports.getFilePathsMatchingGlobFunctionName} function`,
|
|
172
|
+
],
|
|
173
|
+
};
|
|
174
|
+
exports.renameFunctionName = 'renameFileOrDirectory';
|
|
175
|
+
const renameFunction = {
|
|
176
|
+
definition: {
|
|
177
|
+
name: exports.renameFunctionName,
|
|
178
|
+
description: 'Rename a file or directory',
|
|
179
|
+
parameters: {
|
|
180
|
+
type: 'object',
|
|
181
|
+
properties: {
|
|
182
|
+
oldPath: {
|
|
183
|
+
type: 'string',
|
|
184
|
+
description: 'Original path of the file or directory',
|
|
185
|
+
},
|
|
186
|
+
newName: {
|
|
187
|
+
type: 'string',
|
|
188
|
+
description: 'New name for the file or directory',
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
required: ['oldPath', 'newName']
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
call: (params) => __awaiter(void 0, void 0, void 0, function* () { return yield util_node_1.Fs.rename(params.oldPath, params.newName); }),
|
|
195
|
+
instructions: [
|
|
196
|
+
`To rename a file or directory, use the ${exports.renameFunctionName} function`,
|
|
197
|
+
],
|
|
198
|
+
};
|
|
199
|
+
exports.copyFunctionName = 'copyFileOrDirectory';
|
|
200
|
+
const copyFunction = {
|
|
201
|
+
definition: {
|
|
202
|
+
name: exports.copyFunctionName,
|
|
203
|
+
description: 'Copy a file or directory',
|
|
204
|
+
parameters: {
|
|
205
|
+
type: 'object',
|
|
206
|
+
properties: {
|
|
207
|
+
sourcePath: {
|
|
208
|
+
type: 'string',
|
|
209
|
+
description: 'Path of the source file or directory',
|
|
210
|
+
},
|
|
211
|
+
destinationPath: {
|
|
212
|
+
type: 'string',
|
|
213
|
+
description: 'Destination path for the copied file or directory',
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
required: ['sourcePath', 'destinationPath']
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
call: (params) => __awaiter(void 0, void 0, void 0, function* () { return yield util_node_1.Fs.copy(params.sourcePath, params.destinationPath); }),
|
|
220
|
+
instructions: [
|
|
221
|
+
`To copy a file or directory, use the ${exports.copyFunctionName} function`,
|
|
222
|
+
],
|
|
223
|
+
};
|
|
224
|
+
exports.moveFunctionName = 'moveFileOrDirectory';
|
|
225
|
+
const moveFunction = {
|
|
226
|
+
definition: {
|
|
227
|
+
name: exports.moveFunctionName,
|
|
228
|
+
description: 'Move a file or directory',
|
|
229
|
+
parameters: {
|
|
230
|
+
type: 'object',
|
|
231
|
+
properties: {
|
|
232
|
+
sourcePath: {
|
|
233
|
+
type: 'string',
|
|
234
|
+
description: 'Path of the source file or directory',
|
|
235
|
+
},
|
|
236
|
+
destinationPath: {
|
|
237
|
+
type: 'string',
|
|
238
|
+
description: 'Destination path for the moved file or directory',
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
required: ['sourcePath', 'destinationPath']
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
call: (params) => __awaiter(void 0, void 0, void 0, function* () { return yield util_node_1.Fs.move(params.sourcePath, params.destinationPath); }),
|
|
245
|
+
instructions: [
|
|
246
|
+
`To move a file or directory, use the ${exports.moveFunctionName} function`,
|
|
247
|
+
],
|
|
248
|
+
};
|
|
249
|
+
exports.fsFunctions = [
|
|
250
|
+
createFolderFunction,
|
|
251
|
+
exports.fileOrDirectoryExistsFunction,
|
|
252
|
+
getFilePathsMatchingGlobFunction,
|
|
253
|
+
renameFunction,
|
|
254
|
+
copyFunction,
|
|
255
|
+
moveFunction,
|
|
256
|
+
];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.GitModuleFactory = exports.GitModule = void 0;
|
|
13
|
+
const util_node_1 = require("@proteinjs/util-node");
|
|
14
|
+
class GitModule {
|
|
15
|
+
constructor(repoPath) {
|
|
16
|
+
this.repoPath = repoPath;
|
|
17
|
+
}
|
|
18
|
+
getName() {
|
|
19
|
+
return 'Git';
|
|
20
|
+
}
|
|
21
|
+
getSystemMessages() {
|
|
22
|
+
return [
|
|
23
|
+
`After we make code changes (write to files), ask the user if they'd like to commit and sync those changes`,
|
|
24
|
+
`If they want to commit, offer them 3 generated messages that summarize the changes to choose from, as well as the option to write a custom message`,
|
|
25
|
+
`The generated messages should be 1-3 sentences in length, and each generated option should be a different length of summary`,
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
getFunctions() {
|
|
29
|
+
return [
|
|
30
|
+
...util_node_1.gitFunctions,
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
getMessageModerators() {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.GitModule = GitModule;
|
|
38
|
+
class GitModuleFactory {
|
|
39
|
+
createModule(repoPath) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
return new GitModule(repoPath);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.GitModuleFactory = GitModuleFactory;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.searchFilesFunction = exports.searchFilesFunctionName = void 0;
|
|
13
|
+
exports.searchFilesFunctionName = 'searchFiles';
|
|
14
|
+
const searchFilesFunction = (module) => {
|
|
15
|
+
return {
|
|
16
|
+
definition: {
|
|
17
|
+
name: exports.searchFilesFunctionName,
|
|
18
|
+
description: 'Get file paths to files that contain keyword',
|
|
19
|
+
parameters: {
|
|
20
|
+
type: 'object',
|
|
21
|
+
properties: {
|
|
22
|
+
keyword: {
|
|
23
|
+
type: 'string',
|
|
24
|
+
description: 'Search files for this keyword'
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
required: ['keyword']
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
call: (params) => __awaiter(void 0, void 0, void 0, function* () { return module.searchFiles(params); }),
|
|
31
|
+
instructions: [
|
|
32
|
+
`If the user is trying to interact with a file, but does not provide a path, you can find file paths that match a keyword using the ${exports.searchFilesFunctionName} function`,
|
|
33
|
+
`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 ${exports.searchFilesFunctionName} function`,
|
|
34
|
+
`If the user references a file in a package without providing a path, use the ${exports.searchFilesFunctionName} function on the keyword to find potentially relevant files, and choose the one that references the package name in its path`,
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
exports.searchFilesFunction = searchFilesFunction;
|
|
39
|
+
// {
|
|
40
|
+
// definition: {
|
|
41
|
+
// name: 'getDeclarations',
|
|
42
|
+
// description: 'Get the typescript declarations of files',
|
|
43
|
+
// parameters: {
|
|
44
|
+
// type: 'object',
|
|
45
|
+
// properties: {
|
|
46
|
+
// tsFilePaths: {
|
|
47
|
+
// type: 'array',
|
|
48
|
+
// description: 'Paths to the files',
|
|
49
|
+
// items: {
|
|
50
|
+
// type: 'string',
|
|
51
|
+
// },
|
|
52
|
+
// },
|
|
53
|
+
// includeDependencyDeclarations: {
|
|
54
|
+
// type: 'boolean',
|
|
55
|
+
// description: 'if true, returns declarations for input tsFilePaths and all dependencies. defaults to false.'
|
|
56
|
+
// },
|
|
57
|
+
// },
|
|
58
|
+
// required: ['tsFilePaths']
|
|
59
|
+
// },
|
|
60
|
+
// },
|
|
61
|
+
// call: async (params: { tsFilePaths: string[] }) => this.repo.getDeclarations(params),
|
|
62
|
+
// instructions: [
|
|
63
|
+
// `Favor calling getDeclarations over readFiles if full file content is not needed`,
|
|
64
|
+
// ],
|
|
65
|
+
// },
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.KeywordToFilesIndexModuleFactory = exports.KeywordToFilesIndexModule = void 0;
|
|
16
|
+
const util_1 = require("@proteinjs/util");
|
|
17
|
+
const util_node_1 = require("@proteinjs/util-node");
|
|
18
|
+
const path_1 = __importDefault(require("path"));
|
|
19
|
+
const KeywordToFilesIndexFunctions_1 = require("./KeywordToFilesIndexFunctions");
|
|
20
|
+
class KeywordToFilesIndexModule {
|
|
21
|
+
constructor(params) {
|
|
22
|
+
this.logger = new util_1.Logger(this.constructor.name);
|
|
23
|
+
this.params = params;
|
|
24
|
+
}
|
|
25
|
+
getName() {
|
|
26
|
+
return 'Keyword to files index';
|
|
27
|
+
}
|
|
28
|
+
searchFiles(params) {
|
|
29
|
+
this.logger.info(`Searching for file, keyword: ${params.keyword}`);
|
|
30
|
+
const filePaths = this.params.keywordFilesIndex[params.keyword];
|
|
31
|
+
return filePaths || [];
|
|
32
|
+
}
|
|
33
|
+
getSystemMessages() {
|
|
34
|
+
return [
|
|
35
|
+
`If you're searching for something, use the ${KeywordToFilesIndexFunctions_1.searchFilesFunctionName} function to find a file matching the search string`,
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
getFunctions() {
|
|
39
|
+
return [
|
|
40
|
+
(0, KeywordToFilesIndexFunctions_1.searchFilesFunction)(this),
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
getMessageModerators() {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.KeywordToFilesIndexModule = KeywordToFilesIndexModule;
|
|
48
|
+
class KeywordToFilesIndexModuleFactory {
|
|
49
|
+
constructor() {
|
|
50
|
+
this.logger = new util_1.Logger(this.constructor.name);
|
|
51
|
+
}
|
|
52
|
+
createModule(repoPath) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
this.logger.debug(`Creating module for repo: ${repoPath}`);
|
|
55
|
+
let repoParams = { keywordFilesIndex: {}, dir: repoPath };
|
|
56
|
+
repoParams.keywordFilesIndex = yield this.createKeywordFilesIndex(repoPath, ['**/node-typescript-parser/**']);
|
|
57
|
+
this.logger.debug(`Created module for repo: ${repoPath}`);
|
|
58
|
+
return new KeywordToFilesIndexModule(repoParams);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Create keyword-files index for the given base directory.
|
|
63
|
+
*
|
|
64
|
+
* @param baseDir - The directory to start the file search from.
|
|
65
|
+
* @returns An index with keywords mapped to file paths.
|
|
66
|
+
*/
|
|
67
|
+
createKeywordFilesIndex(baseDir, globIgnorePatterns = []) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
// Ensure the base directory has a trailing slash
|
|
70
|
+
if (!baseDir.endsWith(path_1.default.sep)) {
|
|
71
|
+
baseDir += path_1.default.sep;
|
|
72
|
+
}
|
|
73
|
+
// Get all file paths, recursively, excluding node_modules and dist directories
|
|
74
|
+
const filePaths = yield util_node_1.Fs.getFilePaths(baseDir, ['**/node_modules/**', '**/dist/**', ...globIgnorePatterns]);
|
|
75
|
+
const keywordFilesIndex = {};
|
|
76
|
+
// Process each file path
|
|
77
|
+
for (const filePath of filePaths) {
|
|
78
|
+
const fileName = path_1.default.parse(filePath).name; // Get file name without extension
|
|
79
|
+
if (!keywordFilesIndex[fileName]) {
|
|
80
|
+
keywordFilesIndex[fileName] = [];
|
|
81
|
+
}
|
|
82
|
+
this.logger.debug(`fileName: ${fileName}, filePath: ${filePath}`);
|
|
83
|
+
keywordFilesIndex[fileName].push(filePath);
|
|
84
|
+
}
|
|
85
|
+
return keywordFilesIndex;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.KeywordToFilesIndexModuleFactory = KeywordToFilesIndexModuleFactory;
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.packageFunctions = exports.uninstallPackagesFunction = exports.uninstallPackagesFunctionName = exports.npmInstallFunction = exports.npmInstallFunctionName = exports.generateTypescriptDeclarationsFunction = exports.generateTypescriptDeclarationsFunctionName = exports.searchLibrariesFunction = exports.searchLibrariesFunctionName = exports.searchPackagesFunction = exports.searchPackagesFunctionName = exports.runPackageScriptFunctionName = exports.installPackagesFunction = exports.installPackagesFunctionName = void 0;
|
|
13
|
+
const util_node_1 = require("@proteinjs/util-node");
|
|
14
|
+
exports.installPackagesFunctionName = 'installPackages';
|
|
15
|
+
exports.installPackagesFunction = {
|
|
16
|
+
definition: {
|
|
17
|
+
name: exports.installPackagesFunctionName,
|
|
18
|
+
description: 'Get the content of files',
|
|
19
|
+
parameters: {
|
|
20
|
+
type: 'object',
|
|
21
|
+
properties: {
|
|
22
|
+
packages: {
|
|
23
|
+
type: 'array',
|
|
24
|
+
description: 'Packages to install',
|
|
25
|
+
items: {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
name: {
|
|
29
|
+
type: 'string',
|
|
30
|
+
description: 'Name of package',
|
|
31
|
+
},
|
|
32
|
+
version: {
|
|
33
|
+
type: 'string',
|
|
34
|
+
description: 'Version of package',
|
|
35
|
+
},
|
|
36
|
+
exactVersion: {
|
|
37
|
+
type: 'boolean',
|
|
38
|
+
description: 'If true, freeze the version so subsequent installs do not bump minor versions',
|
|
39
|
+
},
|
|
40
|
+
development: {
|
|
41
|
+
type: 'boolean',
|
|
42
|
+
description: 'If true, install as a dev dependency',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
required: ['name'],
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
cwdPath: {
|
|
49
|
+
type: 'string',
|
|
50
|
+
description: 'The directory to install packages in',
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
required: ['packages', 'cwdPath']
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
call: (params) => __awaiter(void 0, void 0, void 0, function* () { return yield util_node_1.PackageUtil.installPackages(params.packages, params.cwdPath); }),
|
|
57
|
+
instructions: [
|
|
58
|
+
`To install a package, use the ${exports.installPackagesFunctionName} function`,
|
|
59
|
+
],
|
|
60
|
+
};
|
|
61
|
+
exports.runPackageScriptFunctionName = 'runPackageScript';
|
|
62
|
+
const runPackageScriptFunction = {
|
|
63
|
+
definition: {
|
|
64
|
+
name: exports.runPackageScriptFunctionName,
|
|
65
|
+
description: 'Run `npm run x`, where `x` is an existing script in a package.json',
|
|
66
|
+
parameters: {
|
|
67
|
+
type: 'object',
|
|
68
|
+
properties: {
|
|
69
|
+
name: {
|
|
70
|
+
type: 'string',
|
|
71
|
+
description: 'Name of the script',
|
|
72
|
+
},
|
|
73
|
+
cwdPath: {
|
|
74
|
+
type: 'string',
|
|
75
|
+
description: 'If omitted, defaults to process.cwd',
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
required: ['name']
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
call: (params) => __awaiter(void 0, void 0, void 0, function* () { return yield util_node_1.PackageUtil.runPackageScript(params.name, params.cwdPath); }),
|
|
82
|
+
instructions: [
|
|
83
|
+
`To run a npm script (such as start, test, or watch), use the ${exports.runPackageScriptFunctionName} function`,
|
|
84
|
+
],
|
|
85
|
+
};
|
|
86
|
+
exports.searchPackagesFunctionName = 'searchPackages';
|
|
87
|
+
function searchPackagesFunction(packageModule) {
|
|
88
|
+
return {
|
|
89
|
+
definition: {
|
|
90
|
+
name: exports.searchPackagesFunctionName,
|
|
91
|
+
description: 'Get package.json file paths for package names that include the keyword',
|
|
92
|
+
parameters: {
|
|
93
|
+
type: 'object',
|
|
94
|
+
properties: {
|
|
95
|
+
keyword: {
|
|
96
|
+
type: 'string',
|
|
97
|
+
description: 'Keyword to match package names',
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
required: ['keyword']
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
call: (params) => __awaiter(this, void 0, void 0, function* () { return yield packageModule.searchPackages(params.keyword); }),
|
|
104
|
+
instructions: [
|
|
105
|
+
`To search for packages in the local repo, use the ${exports.searchPackagesFunctionName} function`,
|
|
106
|
+
],
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
exports.searchPackagesFunction = searchPackagesFunction;
|
|
110
|
+
exports.searchLibrariesFunctionName = 'searchLibraries';
|
|
111
|
+
function searchLibrariesFunction(packageModule) {
|
|
112
|
+
return {
|
|
113
|
+
definition: {
|
|
114
|
+
name: exports.searchLibrariesFunctionName,
|
|
115
|
+
description: 'Return libraries that match the keyword',
|
|
116
|
+
parameters: {
|
|
117
|
+
type: 'object',
|
|
118
|
+
properties: {
|
|
119
|
+
keyword: {
|
|
120
|
+
type: 'string',
|
|
121
|
+
description: 'Keyword to match file names',
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
required: ['keyword']
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
call: (params) => __awaiter(this, void 0, void 0, function* () { return yield packageModule.searchLibraries(params.keyword); }),
|
|
128
|
+
instructions: [
|
|
129
|
+
`To search for libraries in the local repo, use the ${exports.searchLibrariesFunctionName} function`,
|
|
130
|
+
],
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
exports.searchLibrariesFunction = searchLibrariesFunction;
|
|
134
|
+
exports.generateTypescriptDeclarationsFunctionName = 'generateTypescriptDesclarations';
|
|
135
|
+
exports.generateTypescriptDeclarationsFunction = {
|
|
136
|
+
definition: {
|
|
137
|
+
name: exports.generateTypescriptDeclarationsFunctionName,
|
|
138
|
+
description: 'Return the typescript declarations for the files',
|
|
139
|
+
parameters: {
|
|
140
|
+
type: 'object',
|
|
141
|
+
properties: {
|
|
142
|
+
tsFilePaths: {
|
|
143
|
+
type: 'array',
|
|
144
|
+
description: 'File paths to generate declarations for',
|
|
145
|
+
items: {
|
|
146
|
+
type: 'string',
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
required: ['tsFilePaths']
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
call: (params) => __awaiter(void 0, void 0, void 0, function* () { return util_node_1.PackageUtil.generateTypescriptDeclarations(params); }),
|
|
154
|
+
instructions: [
|
|
155
|
+
`To generate typescript declarations for a local file, use the ${exports.generateTypescriptDeclarationsFunctionName} function`,
|
|
156
|
+
],
|
|
157
|
+
};
|
|
158
|
+
exports.npmInstallFunctionName = 'npmInstall';
|
|
159
|
+
exports.npmInstallFunction = {
|
|
160
|
+
definition: {
|
|
161
|
+
name: exports.npmInstallFunctionName,
|
|
162
|
+
description: 'Run `npm install` in the specified directory',
|
|
163
|
+
parameters: {
|
|
164
|
+
type: 'object',
|
|
165
|
+
properties: {
|
|
166
|
+
cwdPath: {
|
|
167
|
+
type: 'string',
|
|
168
|
+
description: 'Directory to execute the command from',
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
required: ['cwdPath']
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
call: (params) => __awaiter(void 0, void 0, void 0, function* () { return yield util_node_1.PackageUtil.npmInstall(params.cwdPath); }),
|
|
175
|
+
instructions: [
|
|
176
|
+
`To run npm install in a specific directory, use the ${exports.npmInstallFunctionName} function`,
|
|
177
|
+
],
|
|
178
|
+
};
|
|
179
|
+
exports.uninstallPackagesFunctionName = 'uninstallPackages';
|
|
180
|
+
exports.uninstallPackagesFunction = {
|
|
181
|
+
definition: {
|
|
182
|
+
name: exports.uninstallPackagesFunctionName,
|
|
183
|
+
description: 'Uninstall packages',
|
|
184
|
+
parameters: {
|
|
185
|
+
type: 'object',
|
|
186
|
+
properties: {
|
|
187
|
+
packageNames: {
|
|
188
|
+
type: 'array',
|
|
189
|
+
description: 'Packages to uninstall',
|
|
190
|
+
items: {
|
|
191
|
+
type: 'string',
|
|
192
|
+
description: 'Name of package',
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
cwdPath: {
|
|
196
|
+
type: 'string',
|
|
197
|
+
description: 'The directory to uninstall packages from',
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
required: ['packageNames', 'cwdPath']
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
call: (params) => __awaiter(void 0, void 0, void 0, function* () { return yield util_node_1.PackageUtil.uninstallPackages(params.packageNames, params.cwdPath); }),
|
|
204
|
+
instructions: [
|
|
205
|
+
`To uninstall a package, use the ${exports.uninstallPackagesFunctionName} function`,
|
|
206
|
+
],
|
|
207
|
+
};
|
|
208
|
+
exports.packageFunctions = [
|
|
209
|
+
exports.installPackagesFunction,
|
|
210
|
+
runPackageScriptFunction,
|
|
211
|
+
exports.generateTypescriptDeclarationsFunction,
|
|
212
|
+
exports.npmInstallFunction,
|
|
213
|
+
exports.uninstallPackagesFunction,
|
|
214
|
+
];
|