@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.
Files changed (76) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE +21 -0
  3. package/dist/index.js +27 -0
  4. package/dist/jest.config.js +10 -0
  5. package/dist/src/CodegenConversation.js +120 -0
  6. package/dist/src/Conversation.js +193 -0
  7. package/dist/src/ConversationModule.js +2 -0
  8. package/dist/src/Function.js +2 -0
  9. package/dist/src/OpenAi.js +209 -0
  10. package/dist/src/Paragraph.js +18 -0
  11. package/dist/src/Sentence.js +22 -0
  12. package/dist/src/code_template/Code.js +41 -0
  13. package/dist/src/code_template/CodeTemplate.js +39 -0
  14. package/dist/src/code_template/CodeTemplateModule.js +46 -0
  15. package/dist/src/code_template/Repo.js +127 -0
  16. package/dist/src/fs/conversation_fs/ConversationFsModerator.js +99 -0
  17. package/dist/src/fs/conversation_fs/ConversationFsModule.js +68 -0
  18. package/dist/src/fs/conversation_fs/FsFunctions.js +256 -0
  19. package/dist/src/fs/git/GitModule.js +45 -0
  20. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.js +65 -0
  21. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.js +89 -0
  22. package/dist/src/fs/package/PackageFunctions.js +214 -0
  23. package/dist/src/fs/package/PackageModule.js +102 -0
  24. package/dist/src/history/MessageHistory.js +44 -0
  25. package/dist/src/history/MessageModerator.js +2 -0
  26. package/dist/src/template/ConversationTemplate.js +2 -0
  27. package/dist/src/template/ConversationTemplateFunctions.js +54 -0
  28. package/dist/src/template/ConversationTemplateModule.js +80 -0
  29. package/dist/src/template/createApp/CreateAppTemplate.js +40 -0
  30. package/dist/src/template/createCode/CreateCodeConversationTemplate.js +51 -0
  31. package/dist/src/template/createPackage/CreatePackageConversationTemplate.js +54 -0
  32. package/dist/src/template/createPackage/jest.config.js +10 -0
  33. package/dist/src/template/createPackage/tsconfig.json +13 -0
  34. package/dist/test/createKeywordFilesIndex.test.js +17 -0
  35. package/dist/test/openai/openai.generateList.test.js +16 -0
  36. package/dist/test/openai/openai.parseCodeFromMarkdown.test.js +18 -0
  37. package/dist/test/repo/repo.test.js +29 -0
  38. package/dist/test/setup.js +1 -0
  39. package/index.ts +11 -0
  40. package/jest.config.js +9 -0
  41. package/package.json +34 -0
  42. package/src/CodegenConversation.ts +92 -0
  43. package/src/Conversation.ts +207 -0
  44. package/src/ConversationModule.ts +13 -0
  45. package/src/Function.ts +8 -0
  46. package/src/OpenAi.ts +212 -0
  47. package/src/Paragraph.ts +17 -0
  48. package/src/Sentence.ts +20 -0
  49. package/src/code_template/Code.ts +53 -0
  50. package/src/code_template/CodeTemplate.ts +39 -0
  51. package/src/code_template/CodeTemplateModule.ts +50 -0
  52. package/src/code_template/Repo.ts +156 -0
  53. package/src/fs/conversation_fs/ConversationFsModerator.ts +121 -0
  54. package/src/fs/conversation_fs/ConversationFsModule.ts +64 -0
  55. package/src/fs/conversation_fs/FsFunctions.ts +253 -0
  56. package/src/fs/git/GitModule.ts +39 -0
  57. package/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.ts +55 -0
  58. package/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.ts +90 -0
  59. package/src/fs/package/PackageFunctions.ts +210 -0
  60. package/src/fs/package/PackageModule.ts +106 -0
  61. package/src/history/MessageHistory.ts +57 -0
  62. package/src/history/MessageModerator.ts +6 -0
  63. package/src/template/ConversationTemplate.ts +12 -0
  64. package/src/template/ConversationTemplateFunctions.ts +43 -0
  65. package/src/template/ConversationTemplateModule.ts +83 -0
  66. package/src/template/createApp/CreateAppTemplate.ts +33 -0
  67. package/src/template/createCode/CreateCodeConversationTemplate.ts +41 -0
  68. package/src/template/createPackage/CreatePackageConversationTemplate.ts +42 -0
  69. package/src/template/createPackage/jest.config.js +9 -0
  70. package/src/template/createPackage/tsconfig.json +13 -0
  71. package/test/createKeywordFilesIndex.test.ts +7 -0
  72. package/test/openai/openai.generateList.test.ts +6 -0
  73. package/test/openai/openai.parseCodeFromMarkdown.test.ts +20 -0
  74. package/test/repo/repo.test.ts +33 -0
  75. package/test/setup.js +0 -0
  76. package/tsconfig.json +109 -0
@@ -0,0 +1,41 @@
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.Code = void 0;
13
+ const util_node_1 = require("@proteinjs/util-node");
14
+ class Code {
15
+ constructor(args) {
16
+ this.args = args;
17
+ }
18
+ generate() {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ if (this.args.imports)
21
+ this.addImports(this.args.imports, this.args.conversation);
22
+ return yield this.args.conversation.generateCode(this.args.description, 'gpt-4');
23
+ });
24
+ }
25
+ addImports(imports, conversation) {
26
+ conversation.addSystemMessagesToHistory([
27
+ this.declarationMessage(imports.map(d => d.sourceFilePath)),
28
+ this.importMessage(imports),
29
+ ]);
30
+ }
31
+ declarationMessage(tsFilePaths) {
32
+ const declarationMap = util_node_1.PackageUtil.generateTypescriptDeclarations({ tsFilePaths, includeDependencyDeclarations: true });
33
+ const declarations = Object.values(declarationMap).join('\n');
34
+ return `Assume the following code exists in other files:\n${declarations}`;
35
+ }
36
+ importMessage(imports) {
37
+ const importStatements = imports.map(i => `import { ${i.moduleNames.join(', ')} } from '${i.importPathFromGeneratedFile}'`);
38
+ return `Add the following imports:\n${importStatements}`;
39
+ }
40
+ }
41
+ exports.Code = Code;
@@ -0,0 +1,39 @@
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.CodeTemplate = void 0;
13
+ const util_1 = require("@proteinjs/util");
14
+ const util_node_1 = require("@proteinjs/util-node");
15
+ class CodeTemplate {
16
+ constructor(templateArgs) {
17
+ this.logger = new util_1.Logger(this.constructor.name);
18
+ this.templateArgs = templateArgs;
19
+ }
20
+ generate() {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ yield util_node_1.PackageUtil.installPackages(this.resolvePackages());
23
+ for (let sourceFile of this.sourceFiles()) {
24
+ const filePath = util_node_1.Fs.baseContainedJoin(this.templateArgs.srcPath, sourceFile.relativePath);
25
+ this.logger.info(`Generating source file: ${filePath}`);
26
+ const code = yield sourceFile.code.generate();
27
+ yield util_node_1.Fs.writeFiles([{ path: filePath, content: code }]);
28
+ this.logger.info(`Generated source file: ${filePath}`);
29
+ }
30
+ });
31
+ }
32
+ resolvePackages() {
33
+ const packages = this.templateArgs.replacePackages ? [] : this.dependencyPackages();
34
+ if (this.templateArgs.additionalPackages)
35
+ packages.push(...this.templateArgs.additionalPackages);
36
+ return packages;
37
+ }
38
+ }
39
+ exports.CodeTemplate = CodeTemplate;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CodeTemplateModule = void 0;
4
+ class CodeTemplateModule {
5
+ getName() {
6
+ return 'Code Template';
7
+ }
8
+ getSystemMessages() {
9
+ return [
10
+ `If they want to create a function/class/object using an API we are familiar with, we will ask the user for the required information to fill in all mandatory parameters and ask them if they want to provide optional parameter values`,
11
+ `Once we have gotten the values for all parameters, respond with '${CodeTemplateModule.CODE_RESPONSE}' followed by the code to instantiate/call the function/class/object with the user's responses for parameter values`,
12
+ `If you're generating a call to a class that extends Template, require that the user provide Template's constructor parameters as well and combine them into the parameters passed into the base class you're instantiating`,
13
+ `Make sure you ask for a srcPath and pass that in to the Template base class constructor arg`,
14
+ `Surround generated code (not including imports) with a self-executing, anonymous async function like this (async function() =>{})()`,
15
+ ];
16
+ }
17
+ getFunctions() {
18
+ return [];
19
+ }
20
+ getMessageModerators() {
21
+ return [];
22
+ }
23
+ }
24
+ exports.CodeTemplateModule = CodeTemplateModule;
25
+ CodeTemplateModule.CODE_RESPONSE = 'Code with user input:';
26
+ // if (response.includes(CodegenConversation.CODE_RESPONSE))
27
+ // await this.generateCode(response, conversation);
28
+ // private async generateCode(message: string, conversation: Conversation) {
29
+ // const code = OpenAi.parseCodeFromMarkdown(message);
30
+ // const srcPathToken = 'TOKEN';
31
+ // const responseSrcPath = await conversation.generateResponse([`Return the srcPath the user provided surrounded by the token ${srcPathToken}`], CodegenConversation.MODEL);
32
+ // const srcPath = responseSrcPath.replace(/["'`]/g, '').match(/TOKEN(.*?)TOKEN/)?.[1];
33
+ // if (!srcPath)
34
+ // throw new Error(`Failed to parse responseSrcPath: ${responseSrcPath}`);
35
+ // const codePath = path.join(process.cwd(), srcPath, 'template.ts');
36
+ // await fs.ensureFile(codePath);
37
+ // await fs.writeFile(codePath, code);
38
+ // console.log(`Wrote file: ${codePath}`);
39
+ // const command = 'node';
40
+ // const args = [codePath];
41
+ // const commandLog = `${command} ` + args.join(' ');
42
+ // console.info(`Running command: ${commandLog}`);
43
+ // await cmd(command, args, {OPENAI_API_KEY: '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'});
44
+ // console.info(`Ran command: ${commandLog}`);
45
+ // console.info(`Generated code from template: ${codePath}`);
46
+ // }
@@ -0,0 +1,127 @@
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 __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.RepoFactory = exports.Repo = void 0;
27
+ const util_1 = require("@proteinjs/util");
28
+ const util_node_1 = require("@proteinjs/util-node");
29
+ const promises_1 = __importDefault(require("fs/promises"));
30
+ const path_1 = __importDefault(require("path"));
31
+ class Repo {
32
+ constructor(params) {
33
+ this.logger = new util_1.Logger(this.constructor.name);
34
+ this.params = params;
35
+ }
36
+ packages() {
37
+ return this.params.packages;
38
+ }
39
+ slimPackages() {
40
+ return this.params.slimPackages;
41
+ }
42
+ tsFiles() {
43
+ return this.params.tsFiles;
44
+ }
45
+ keywordFilesIndex() {
46
+ return this.params.keywordFilesIndex;
47
+ }
48
+ searchFiles(params) {
49
+ this.logger.info(`Searching for file, keyword: ${params.keyword}`);
50
+ const filePaths = this.keywordFilesIndex()[params.keyword];
51
+ return filePaths || [];
52
+ }
53
+ getDeclarations(params) {
54
+ const queriedDeclarations = {};
55
+ for (let tsFilePath of params.tsFilePaths) {
56
+ queriedDeclarations[tsFilePath] = this.params.tsFiles[tsFilePath].declaration;
57
+ this.logger.info(`Accessed declaration: ${tsFilePath}`);
58
+ }
59
+ return queriedDeclarations;
60
+ }
61
+ }
62
+ exports.Repo = Repo;
63
+ class RepoFactory {
64
+ static createRepo(dir) {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ this.LOGGER.info(`Creating repo for dir: ${dir}`);
67
+ let repoParams = { packages: {}, slimPackages: {}, tsFiles: {}, keywordFilesIndex: {} };
68
+ function traverse(dir) {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ const childrenNames = yield promises_1.default.readdir(dir, { withFileTypes: true });
71
+ let hasPackageJson = childrenNames.some(dirent => dirent.name === 'package.json');
72
+ if (hasPackageJson) {
73
+ const packageContent = yield promises_1.default.readFile(path_1.default.join(dir, 'package.json'), 'utf-8');
74
+ const packageJSON = JSON.parse(packageContent);
75
+ repoParams.packages[packageJSON.name] = {
76
+ packageJSON: packageJSON,
77
+ dirPath: dir,
78
+ fileDescriptors: [],
79
+ tsFiles: {},
80
+ };
81
+ }
82
+ for (const dirent of childrenNames) {
83
+ if (!dirent.isDirectory())
84
+ continue;
85
+ // Exclude directories 'node_modules' and 'dist' right at the beginning
86
+ if (dirent.name.includes('node_modules') || dirent.name.includes('dist')) {
87
+ continue;
88
+ }
89
+ // Continue with the traversal if it's a directory
90
+ const childPath = path_1.default.join(dir, dirent.name);
91
+ yield traverse(childPath);
92
+ }
93
+ });
94
+ }
95
+ yield traverse(dir);
96
+ yield RepoFactory.loadFiles(repoParams);
97
+ Object.keys(repoParams.packages).forEach(packageName => {
98
+ const _a = repoParams.packages[packageName], { packageJSON, tsFiles } = _a, slimPackage = __rest(_a, ["packageJSON", "tsFiles"]);
99
+ repoParams.slimPackages[packageName] = slimPackage;
100
+ });
101
+ this.LOGGER.info(`Created repo for dir: ${dir}`);
102
+ return new Repo(repoParams);
103
+ });
104
+ }
105
+ static loadFiles(repoParams) {
106
+ return __awaiter(this, void 0, void 0, function* () {
107
+ for (let packageName of Object.keys(repoParams.packages)) {
108
+ this.LOGGER.info(`Loading files for package: ${packageName}`);
109
+ const dirPath = repoParams.packages[packageName].dirPath;
110
+ if (dirPath) {
111
+ repoParams.packages[packageName].fileDescriptors.push(...yield util_node_1.Fs.getFilesInDirectory(dirPath, ['node_modules', 'dist']));
112
+ for (let fileDescriptor of repoParams.packages[packageName].fileDescriptors) {
113
+ const typescriptDeclaration = util_node_1.PackageUtil.generateTypescriptDeclarations({ tsFilePaths: [fileDescriptor.path] })[fileDescriptor.path];
114
+ const tsFile = Object.assign({ declaration: typescriptDeclaration }, fileDescriptor);
115
+ repoParams.packages[packageName].tsFiles[fileDescriptor.path] = tsFile;
116
+ repoParams.tsFiles[fileDescriptor.path] = tsFile;
117
+ if (!repoParams.keywordFilesIndex[fileDescriptor.nameWithoutExtension])
118
+ repoParams.keywordFilesIndex[fileDescriptor.nameWithoutExtension] = [];
119
+ repoParams.keywordFilesIndex[fileDescriptor.nameWithoutExtension].push(fileDescriptor.path);
120
+ }
121
+ }
122
+ }
123
+ });
124
+ }
125
+ }
126
+ exports.RepoFactory = RepoFactory;
127
+ RepoFactory.LOGGER = new util_1.Logger('RepoFactory');
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConversationFsModerator = exports.ConversationFsFactory = void 0;
4
+ const util_1 = require("@proteinjs/util");
5
+ class ConversationFsFactory {
6
+ constructor(params) {
7
+ this.params = Object.assign({ maxFiles: 3, logLevel: 'info' }, params);
8
+ this.logger = new util_1.Logger(this.constructor.name, this.params.logLevel);
9
+ }
10
+ merge(existingFs, updates) {
11
+ for (let filePath of Object.keys(updates)) {
12
+ // if the file already exists in the fs
13
+ if (existingFs.fileContentMap[filePath]) {
14
+ this.logger.debug(`Updating existing file: ${filePath}`);
15
+ existingFs.fileContentMap[filePath] = updates[filePath];
16
+ const oldIndex = existingFs.order.findIndex(item => item == filePath);
17
+ existingFs.order.splice(oldIndex, 1);
18
+ existingFs.order.push(filePath);
19
+ continue;
20
+ }
21
+ // if we have less than the max number of files in the fs
22
+ if (Object.keys(existingFs.fileContentMap).length < this.params.maxFiles) {
23
+ this.logger.debug(`Adding new file (under limit): ${filePath}`);
24
+ existingFs.fileContentMap[filePath] = updates[filePath];
25
+ existingFs.order.push(filePath);
26
+ continue;
27
+ }
28
+ else {
29
+ this.logger.debug(`Adding new file (over limit): ${filePath}`);
30
+ const removedFilePath = existingFs.order.splice(0, 1)[0];
31
+ delete existingFs.fileContentMap[removedFilePath];
32
+ existingFs.fileContentMap[filePath] = updates[filePath];
33
+ existingFs.order.push(filePath);
34
+ }
35
+ }
36
+ return existingFs;
37
+ }
38
+ }
39
+ exports.ConversationFsFactory = ConversationFsFactory;
40
+ class ConversationFsModerator {
41
+ constructor(logLevel) {
42
+ this.logLevel = 'info';
43
+ if (logLevel)
44
+ this.logLevel = logLevel;
45
+ }
46
+ observe(messages) {
47
+ let conversationFileSystemMessageIndex = -1;
48
+ let conversationFileSystem;
49
+ let readFilesFunctionCallMessageIndexes = [];
50
+ let writeFilesFunctionCallMessageIndexes = [];
51
+ const readFilesConsolidatedOutput = {}; // newest version of file wins
52
+ for (let i = 0; i < messages.length; i++) {
53
+ const message = messages[i];
54
+ if (message.role == 'system' && message.content) {
55
+ let parsedContent;
56
+ try {
57
+ parsedContent = JSON.parse(message.content);
58
+ }
59
+ catch (error) { }
60
+ if (!parsedContent || !parsedContent['fileSystem'])
61
+ continue;
62
+ conversationFileSystem = parsedContent['fileSystem'];
63
+ conversationFileSystemMessageIndex = i;
64
+ continue;
65
+ }
66
+ if (message.role == 'function' && message.name == 'readFiles' && message.content) {
67
+ let parsedContent;
68
+ try {
69
+ parsedContent = JSON.parse(message.content);
70
+ }
71
+ catch (error) { }
72
+ if (!parsedContent)
73
+ continue;
74
+ for (let filePath of Object.keys(parsedContent)) {
75
+ readFilesConsolidatedOutput[filePath] = parsedContent[filePath];
76
+ }
77
+ readFilesFunctionCallMessageIndexes.push(i);
78
+ }
79
+ if (message.role == 'function' && message.name == 'writeFiles') {
80
+ writeFilesFunctionCallMessageIndexes.push(i);
81
+ }
82
+ }
83
+ if (conversationFileSystem) {
84
+ conversationFileSystem = new ConversationFsFactory({ logLevel: this.logLevel }).merge(conversationFileSystem, readFilesConsolidatedOutput);
85
+ const content = JSON.stringify({ fileSystem: conversationFileSystem });
86
+ messages[conversationFileSystemMessageIndex].content = content;
87
+ }
88
+ else {
89
+ conversationFileSystem = { fileContentMap: readFilesConsolidatedOutput, order: Object.keys(readFilesConsolidatedOutput) };
90
+ messages.push({ role: 'system', 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.` });
91
+ const content = JSON.stringify({ fileSystem: conversationFileSystem });
92
+ messages.push({ role: 'system', content });
93
+ }
94
+ const moderatedMessages = messages
95
+ .filter((message, i) => !readFilesFunctionCallMessageIndexes.includes(i) && !writeFilesFunctionCallMessageIndexes.includes(i));
96
+ return moderatedMessages;
97
+ }
98
+ }
99
+ exports.ConversationFsModerator = ConversationFsModerator;
@@ -0,0 +1,68 @@
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.ConversationFsModuleFactory = exports.ConversationFsModule = void 0;
13
+ const KeywordToFilesIndexFunctions_1 = require("../keyword_to_files_index/KeywordToFilesIndexFunctions");
14
+ const PackageFunctions_1 = require("../package/PackageFunctions");
15
+ const ConversationFsModerator_1 = require("./ConversationFsModerator");
16
+ const FsFunctions_1 = require("./FsFunctions");
17
+ class ConversationFsModule {
18
+ constructor(repoPath) {
19
+ this.recentlyAccessedFilePaths = [];
20
+ this.repoPath = repoPath;
21
+ }
22
+ getName() {
23
+ return 'Conversation Fs';
24
+ }
25
+ getSystemMessages() {
26
+ return [
27
+ `Assume the current working directory is: ${this.repoPath} unless specified by the user`,
28
+ `Pre-pend the current working directory as the base path to file paths when performing file operations, unless specified otherwise by the user`,
29
+ `If the user asks to change the cwd, do not create a new folder, just fail if it's not a valid path`,
30
+ `If the user wants to work in a package, use the ${PackageFunctions_1.searchPackagesFunctionName} function and take the directory from the package.json file path and make that the cwd`,
31
+ `You have access to code in a local repo, you can read and write code to and from the file system with the ${FsFunctions_1.readFilesFunctionName} function and the ${FsFunctions_1.writeFilesFunctionName} function`,
32
+ `Before writing to a file that already exists, read the file first and make your changes to its contents`,
33
+ `When reading/writing a file in a specified package, join the package directory with the relative path to form the file path`,
34
+ `When searching for source files, do not look in the dist or node_modules directories`,
35
+ `If you don't know a file path, don't try to guess it, use the ${KeywordToFilesIndexFunctions_1.searchFilesFunctionName} function to find it`,
36
+ `When searching for something (ie. a file to work with/in), unless more context is specified, use the ${PackageFunctions_1.searchLibrariesFunctionName} function first, then fall back to functions: ${PackageFunctions_1.searchPackagesFunctionName}, ${KeywordToFilesIndexFunctions_1.searchFilesFunctionName}`,
37
+ `After finding a file to work with, assume the user's following question pertains to that file and use ${FsFunctions_1.readFilesFunctionName} to read the file if needed`,
38
+ ];
39
+ }
40
+ getFunctions() {
41
+ return [
42
+ (0, FsFunctions_1.readFilesFunction)(this),
43
+ (0, FsFunctions_1.writeFilesFunction)(this),
44
+ (0, FsFunctions_1.getRecentlyAccessedFilePathsFunction)(this),
45
+ ...FsFunctions_1.fsFunctions
46
+ ];
47
+ }
48
+ getMessageModerators() {
49
+ return [
50
+ new ConversationFsModerator_1.ConversationFsModerator(),
51
+ ];
52
+ }
53
+ pushRecentlyAccessedFilePath(filePaths) {
54
+ this.recentlyAccessedFilePaths.push(...filePaths);
55
+ }
56
+ getRecentlyAccessedFilePaths() {
57
+ return this.recentlyAccessedFilePaths;
58
+ }
59
+ }
60
+ exports.ConversationFsModule = ConversationFsModule;
61
+ class ConversationFsModuleFactory {
62
+ createModule(repoPath) {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ return new ConversationFsModule(repoPath);
65
+ });
66
+ }
67
+ }
68
+ exports.ConversationFsModuleFactory = ConversationFsModuleFactory;