@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,102 @@
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.PackageModuleFactory = exports.PackageModule = void 0;
16
+ const util_node_1 = require("@proteinjs/util-node");
17
+ const PackageFunctions_1 = require("./PackageFunctions");
18
+ const path_1 = __importDefault(require("path"));
19
+ class PackageModule {
20
+ constructor(repoPath) {
21
+ this.repoPath = repoPath;
22
+ }
23
+ getName() {
24
+ return 'Package';
25
+ }
26
+ getSystemMessages() {
27
+ return [
28
+ `When generating code, prefer importing code from local packages`,
29
+ `Use the ${PackageFunctions_1.searchPackagesFunctionName} function on every package you plan to install to derermine if the package is in the local repo; if it is, calculate the relative path from the cwd package to the package being installed, use that path as the version when installing the package`,
30
+ // `When generating code, use the searchFiles function to find all file paths to index.ts files; these are the local apis we have access to`,
31
+ // `When generating import statements, use the searchFiles function to find all file paths to package.json files; if importing from a local package, make sure you import via its package if it is not a local file to the package we're generating code in`,
32
+ `When generating import statements from another package, do not use relative paths`,
33
+ ];
34
+ }
35
+ getFunctions() {
36
+ return [
37
+ ...PackageFunctions_1.packageFunctions,
38
+ (0, PackageFunctions_1.searchPackagesFunction)(this),
39
+ (0, PackageFunctions_1.searchLibrariesFunction)(this),
40
+ ];
41
+ }
42
+ getMessageModerators() {
43
+ return [];
44
+ }
45
+ /**
46
+ * @param keyword either the package name or some substring
47
+ * @return string[] of file paths
48
+ */
49
+ searchPackages(keyword) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ const matchingPackageJsonPaths = [];
52
+ const packageJsonFilePaths = yield util_node_1.Fs.getFilePathsMatchingGlob(this.repoPath, '**/package.json', ['**/node_modules/**', '**/dist/**']);
53
+ const packageJsonFileMap = yield util_node_1.Fs.readFiles(packageJsonFilePaths);
54
+ for (let packageJsonFilePath of Object.keys(packageJsonFileMap)) {
55
+ const packageJson = JSON.parse(packageJsonFileMap[packageJsonFilePath]);
56
+ if (packageJson.name.toLowerCase().includes(keyword.toLocaleLowerCase()))
57
+ matchingPackageJsonPaths.push(packageJsonFilePath);
58
+ }
59
+ return matchingPackageJsonPaths;
60
+ });
61
+ }
62
+ /**
63
+ * Search packages in repo for file names that include keyword
64
+ * @param keyword substring of file name to search for
65
+ * @returns all libraries in the repo matching the keyword
66
+ */
67
+ searchLibraries(keyword) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ const matchingLibraries = [];
70
+ const packageJsonFilePaths = yield util_node_1.Fs.getFilePathsMatchingGlob(this.repoPath, '**/package.json', ['**/node_modules/**', '**/dist/**']);
71
+ const packageJsonFileMap = yield util_node_1.Fs.readFiles(packageJsonFilePaths);
72
+ for (let packageJsonFilePath of Object.keys(packageJsonFileMap)) {
73
+ const packageJson = JSON.parse(packageJsonFileMap[packageJsonFilePath]);
74
+ const packageJsonFilePathParts = packageJsonFilePath.split(path_1.default.sep);
75
+ packageJsonFilePathParts.pop();
76
+ const packageDirectory = packageJsonFilePathParts.join(path_1.default.sep);
77
+ const srcFilePaths = yield util_node_1.Fs.getFilePathsMatchingGlob(path_1.default.join(packageDirectory, 'src'), '**/*.ts', ['**/node_modules/**', '**/dist/**']);
78
+ for (let srcFilePath of srcFilePaths) {
79
+ const fileNameWithExtension = path_1.default.basename(srcFilePath);
80
+ if (fileNameWithExtension.includes(keyword)) {
81
+ const fileName = path_1.default.basename(srcFilePath, path_1.default.extname(srcFilePath));
82
+ matchingLibraries.push({
83
+ fileName,
84
+ filePath: srcFilePath,
85
+ packageName: packageJson.name,
86
+ });
87
+ }
88
+ }
89
+ }
90
+ return matchingLibraries;
91
+ });
92
+ }
93
+ }
94
+ exports.PackageModule = PackageModule;
95
+ class PackageModuleFactory {
96
+ createModule(repoPath) {
97
+ return __awaiter(this, void 0, void 0, function* () {
98
+ return new PackageModule(repoPath);
99
+ });
100
+ }
101
+ }
102
+ exports.PackageModuleFactory = PackageModuleFactory;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessageHistory = void 0;
4
+ const util_1 = require("@proteinjs/util");
5
+ class MessageHistory {
6
+ constructor(params) {
7
+ this.logger = new util_1.Logger(this.constructor.name);
8
+ this.messages = [];
9
+ this.params = Object.assign({ maxMessages: 20 }, params);
10
+ }
11
+ getMessages() {
12
+ return this.messages;
13
+ }
14
+ toString() {
15
+ return this.messages.map(message => message.content).join('. ');
16
+ }
17
+ setMessages(messages) {
18
+ this.messages = messages;
19
+ this.prune();
20
+ return this;
21
+ }
22
+ push(messages) {
23
+ this.messages.push(...messages);
24
+ this.prune();
25
+ return this;
26
+ }
27
+ prune() {
28
+ if (this.params.enforceMessageLimit === false)
29
+ return;
30
+ let messageCount = 0;
31
+ const messagesToRemoveIndexes = [];
32
+ for (let i = this.messages.length - 1; i >= 0; i--) {
33
+ const message = this.messages[i];
34
+ if (message.role == 'system')
35
+ continue;
36
+ messageCount++;
37
+ if (messageCount > this.params.maxMessages)
38
+ messagesToRemoveIndexes.push(i);
39
+ }
40
+ this.messages = this.messages.filter((message, i) => !messagesToRemoveIndexes.includes(i));
41
+ this.logger.debug(`Pruned ${messagesToRemoveIndexes.length} messages`);
42
+ }
43
+ }
44
+ exports.MessageHistory = MessageHistory;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,54 @@
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.getConversationTemplateFunction = exports.getConversationTemplateFunctionName = exports.searchConversationTemplatesFunction = exports.searchConversationTemplatesFunctionName = void 0;
13
+ exports.searchConversationTemplatesFunctionName = 'searchConversationTemplates';
14
+ const searchConversationTemplatesFunction = (repo) => {
15
+ return {
16
+ definition: {
17
+ name: exports.searchConversationTemplatesFunctionName,
18
+ description: 'Get the conversation template names for templates matching the keyword',
19
+ parameters: {
20
+ type: 'object',
21
+ properties: {
22
+ keyword: {
23
+ type: 'string',
24
+ description: 'Search for conversation template names that match this keyword',
25
+ },
26
+ },
27
+ required: ['keyword']
28
+ },
29
+ },
30
+ call: (params) => __awaiter(void 0, void 0, void 0, function* () { return repo.searchConversationTemplates(params.keyword); }),
31
+ };
32
+ };
33
+ exports.searchConversationTemplatesFunction = searchConversationTemplatesFunction;
34
+ exports.getConversationTemplateFunctionName = 'getConversationTemplate';
35
+ const getConversationTemplateFunction = (repo) => {
36
+ return {
37
+ definition: {
38
+ name: exports.getConversationTemplateFunctionName,
39
+ description: 'Get the conversation template matching the name',
40
+ parameters: {
41
+ type: 'object',
42
+ properties: {
43
+ conversationTemplateName: {
44
+ type: 'string',
45
+ description: 'Get the conversation template that has this name',
46
+ },
47
+ },
48
+ required: ['conversationTemplateName']
49
+ },
50
+ },
51
+ call: (params) => __awaiter(void 0, void 0, void 0, function* () { return yield repo.getConversationTemplate(params.conversationTemplateName); }),
52
+ };
53
+ };
54
+ exports.getConversationTemplateFunction = getConversationTemplateFunction;
@@ -0,0 +1,80 @@
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.ConversationTemplateModuleFactory = exports.ConversationTemplateModule = void 0;
13
+ const util_1 = require("@proteinjs/util");
14
+ const CreatePackageConversationTemplate_1 = require("./createPackage/CreatePackageConversationTemplate");
15
+ const ConversationTemplateFunctions_1 = require("./ConversationTemplateFunctions");
16
+ const CreateCodeConversationTemplate_1 = require("./createCode/CreateCodeConversationTemplate");
17
+ const CreateAppTemplate_1 = require("./createApp/CreateAppTemplate");
18
+ const conversationTemplates = [
19
+ CreatePackageConversationTemplate_1.createPackageConversationTemplate,
20
+ CreateCodeConversationTemplate_1.createCodeConversationTemplate,
21
+ CreateAppTemplate_1.createAppTemplate,
22
+ ];
23
+ class ConversationTemplateModule {
24
+ constructor(params) {
25
+ this.logger = new util_1.Logger(this.constructor.name);
26
+ this.params = params;
27
+ }
28
+ getName() {
29
+ return 'Conversation Template';
30
+ }
31
+ searchConversationTemplates(keyword) {
32
+ this.logger.info(`Searching for conversation template, keyword: ${keyword}`);
33
+ const conversationNames = this.params.conversationTemplateKeywordIndex[keyword];
34
+ return conversationNames || [];
35
+ }
36
+ getConversationTemplate(conversationTemplateName) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ const conversationTemplate = this.params.conversationTemplates[conversationTemplateName];
39
+ if (!conversationTemplate)
40
+ return {};
41
+ const instructions = yield conversationTemplate.instructions();
42
+ return Object.assign(conversationTemplate, { instructions });
43
+ });
44
+ }
45
+ getSystemMessages() {
46
+ return [
47
+ `Whenever the user wants to create or talk about something, fisrt use the ${ConversationTemplateFunctions_1.searchConversationTemplatesFunctionName} function to identify if there are relevant conversation templates to use`,
48
+ `Use the ${ConversationTemplateFunctions_1.getConversationTemplateFunctionName} function to get the conversation template`,
49
+ `Once you've identified a conversation template that's relevant to the conversation, ask the user if they'd like to use that conversation template`,
50
+ `If they want to engage in the templated conversation, ask only the conversation template questions (template.questions), then use the user's answers to carry out the conversation template instructions (template.instructions)`,
51
+ ];
52
+ }
53
+ getFunctions() {
54
+ return [
55
+ (0, ConversationTemplateFunctions_1.searchConversationTemplatesFunction)(this),
56
+ (0, ConversationTemplateFunctions_1.getConversationTemplateFunction)(this),
57
+ ];
58
+ }
59
+ getMessageModerators() {
60
+ return [];
61
+ }
62
+ }
63
+ exports.ConversationTemplateModule = ConversationTemplateModule;
64
+ class ConversationTemplateModuleFactory {
65
+ createModule(repoPath) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const params = { conversationTemplates: {}, conversationTemplateKeywordIndex: {} };
68
+ for (let conversationTemplate of conversationTemplates) {
69
+ params.conversationTemplates[conversationTemplate.name] = conversationTemplate;
70
+ for (let keyword of conversationTemplate.keywords) {
71
+ if (!params.conversationTemplateKeywordIndex[keyword])
72
+ params.conversationTemplateKeywordIndex[keyword] = [];
73
+ params.conversationTemplateKeywordIndex[keyword].push(conversationTemplate.name);
74
+ }
75
+ }
76
+ return new ConversationTemplateModule(params);
77
+ });
78
+ }
79
+ }
80
+ exports.ConversationTemplateModuleFactory = ConversationTemplateModuleFactory;
@@ -0,0 +1,40 @@
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.createAppTemplate = void 0;
13
+ const createAppQuestions = [
14
+ {
15
+ text: 'What is the name of the app you want to create?',
16
+ },
17
+ {
18
+ text: 'Which directory would you like to create the app in?',
19
+ },
20
+ ];
21
+ const createAppInstructions = () => __awaiter(void 0, void 0, void 0, function* () {
22
+ // Here we would implement the instructions based on the user's answers to the questions
23
+ return [
24
+ 'create a directory for the app (if it doesnt already exist), with the same name as the app (replace ` ` with `-`)',
25
+ 'cloneAppTemplatePackages on the app directory',
26
+ 'update the package.json files of the packages you just cloned, set the package names to be app-name-ui and app-name-server',
27
+ `update the ui/src/Container.tsx and ui/src/SplashPage.tsx files to replace the occurrences of 'appName' with their app name in each file`,
28
+ 'npmInstall each newly cloned package',
29
+ 'runPackageScript(`build`, cwd) each newly cloned package',
30
+ 'describe the packages',
31
+ 'tell the user they can start the server by calling `npm run dev` in the server package',
32
+ ];
33
+ });
34
+ exports.createAppTemplate = {
35
+ name: 'Create App',
36
+ keywords: ['create', 'app', 'create app', 'create new app'],
37
+ description: 'This template will guide you through the process of creating a new app.',
38
+ questions: createAppQuestions,
39
+ instructions: createAppInstructions,
40
+ };
@@ -0,0 +1,51 @@
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.createCodeConversationTemplate = void 0;
13
+ const FsFunctions_1 = require("../../fs/conversation_fs/FsFunctions");
14
+ const PackageFunctions_1 = require("../../fs/package/PackageFunctions");
15
+ exports.createCodeConversationTemplate = {
16
+ name: 'Create code',
17
+ keywords: [
18
+ 'create code',
19
+ 'implement',
20
+ 'write code',
21
+ 'generate code',
22
+ 'write software',
23
+ 'build something',
24
+ ],
25
+ description: 'User and ai developing together',
26
+ questions: [],
27
+ instructions: () => __awaiter(void 0, void 0, void 0, function* () {
28
+ return [
29
+ `You are going to generate code for the user, follow these steps:`,
30
+ `1. Confirm the package they want to work in, if the user didn't already provide one`,
31
+ `1.a. Use the ${PackageFunctions_1.searchPackagesFunctionName} function to identify the package.json file path`,
32
+ `1.b. Use the ${FsFunctions_1.readFilesFunctionName} function to read the package.json file, reference this throughout the conversation in the fileSystem`,
33
+ `1.c. Set the cwd to the directory of the package.json file`,
34
+ `2. Ask for a file name to work in, if the user didn't alrady provide one`,
35
+ `2.a. Whenever the user wants to create a new source file, default to creating it in the package src/ folder`,
36
+ `2.b. Confirm the package-relative file path with the user. Only after the users confirms the path, create the file if it doesn't exist`,
37
+ `2.b.1. Use the ${FsFunctions_1.fileOrDirectoryExistsFunction.definition.name} function to confirm if a file exists`,
38
+ `3. Once working in a file, ask the user what they'd like to create`,
39
+ `3.a. If the user references a library, use the ${PackageFunctions_1.searchLibrariesFunctionName} function to identify local libraries that can be imported`,
40
+ `3.a.1. Confirm the library file name and package name with the user, if they provide a different library or package name, repeat step 3.a.`,
41
+ `3.a.2. Call the ${PackageFunctions_1.generateTypescriptDeclarationsFunction.definition.name} function to get the typescript declaration of the library file`,
42
+ `3.a.3. Use the typescript declaration and the package name to add the import statements to the top of the file`,
43
+ `3.a.4. Use the ${FsFunctions_1.readFilesFunctionName} function on the package.json if it's not in the fileSystem`,
44
+ `3.a.5. Check the pacakge.json dependencies, if the imported package is not already a dependency, use the ${PackageFunctions_1.installPackagesFunction.definition.name} function to install it`,
45
+ `3.a.5.a. Use the ${PackageFunctions_1.searchPackagesFunctionName} on the import package to derermine if it's in the local repo; if it is, calculate the relative path from the cwd package to the package being installed, use that path as the version when installing the package`,
46
+ `3.b. Generate the code the user asked to create, leveraging the imported library where appropriate`,
47
+ `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.`,
48
+ `4. Repeat 3. unless the user asks to switch packages or files`,
49
+ ];
50
+ })
51
+ };
@@ -0,0 +1,54 @@
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.createPackageConversationTemplate = void 0;
16
+ const util_node_1 = require("@proteinjs/util-node");
17
+ const path_1 = __importDefault(require("path"));
18
+ exports.createPackageConversationTemplate = {
19
+ name: 'Create Package',
20
+ keywords: [
21
+ 'package',
22
+ 'create package',
23
+ 'create',
24
+ 'create a package',
25
+ 'create a new package',
26
+ `new package`,
27
+ ],
28
+ description: 'Create a npm package',
29
+ questions: [
30
+ { text: `Which folder should the package be created in?` },
31
+ { text: `What should the package name be?` },
32
+ { text: `What should the package version be?`, optional: true },
33
+ { text: `Is this a typescript project?` },
34
+ { text: `Are there any default dependencies you'd like to include?`, optional: true },
35
+ ],
36
+ instructions: () => __awaiter(void 0, void 0, void 0, function* () {
37
+ const jestConfig = yield util_node_1.Fs.readFile(path_1.default.join(__dirname, `./jest.config.js`));
38
+ const tsConfig = yield util_node_1.Fs.readFile(path_1.default.join(__dirname, `./tsconfig.json`));
39
+ return [
40
+ `Create a new package.json with the provided name, version (if one wasn't provided, default to 0.1), and any default dependencies provided`,
41
+ `Create the package.json in the specified folder, do not create subfolders from the package name`,
42
+ `If the folder does not exist, create the folder`,
43
+ `Add these scripts to the package.json: "start": "node ./dist/index.js", "test": "jest"`,
44
+ `Add these dev dependencies to the package.json: jest`,
45
+ `If it's a typescript project, add these dev dependencies: @types/jest, ts-jest`,
46
+ `If it's a typescript project, add these scripts: "watch": "tsc -w -p ."`,
47
+ `Create an index file in the package root directory (choose extension based on if it's a typescript project or not)`,
48
+ `Create the following folders in the package directory: src, test`,
49
+ `Create a jest.config.js file in the test directory with the following content: ${jestConfig}`,
50
+ `Create a .gitignore file in the package directory that ignores the node_modules and dist directories`,
51
+ `If it's a typescript project, create a tsconfig.json file in the pakage directory with the following content: ${tsConfig}`,
52
+ ];
53
+ }),
54
+ };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ module.exports = {
3
+ preset: 'ts-jest',
4
+ testEnvironment: 'node',
5
+ transform: {
6
+ '^.+\\.tsx?$': 'ts-jest',
7
+ },
8
+ testMatch: ["**/?(*.)+(spec|test).ts"],
9
+ setupFiles: ['./test/setup'],
10
+ };
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2016",
4
+ "module": "commonjs",
5
+ "resolveJsonModule": true,
6
+ "allowJs": true,
7
+ "outDir": "./dist",
8
+ "esModuleInterop": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "strict": true,
11
+ "skipLibCheck": true
12
+ }
13
+ }
@@ -0,0 +1,17 @@
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
+ const KeywordToFilesIndexModule_1 = require("../src/fs/keyword_to_files_index/KeywordToFilesIndexModule");
13
+ test('Create keyword-files index', () => __awaiter(void 0, void 0, void 0, function* () {
14
+ // Example usage
15
+ const index = new KeywordToFilesIndexModule_1.KeywordToFilesIndexModuleFactory().createKeywordFilesIndex(`${process.cwd()}`);
16
+ console.log(JSON.stringify(index, null, 2));
17
+ }), 60000);
@@ -0,0 +1,16 @@
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
+ const OpenAi_1 = require("../../src/OpenAi");
13
+ test('generateList should return an array of numbers, counting to 10', () => __awaiter(void 0, void 0, void 0, function* () {
14
+ const numbers = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'];
15
+ expect((yield OpenAi_1.OpenAi.generateList([`Create a list of numbers spelled out, from 1 to 10`])).join(' ')).toBe(numbers.join(' '));
16
+ }));
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const OpenAi_1 = require("../../src/OpenAi");
4
+ const helloWorldCode = "console.log('hello world');";
5
+ const helloWorldWithTicksCode = "console.log('hello ```world');";
6
+ const logXCode = "const x = 'yo';\nconsole.log(x);";
7
+ const testOneBlock = "Sure! I'm a helpful chatbot.\n```typescript\n" + helloWorldCode + "\n```";
8
+ const testOneBlockWithExtraTicks = "Sure! I'm a helpful chatbot.\n```typescript\n" + helloWorldWithTicksCode + "\n```";
9
+ const testTwoBlocks = "Sure! I'm a helpful chatbot.\n```typescript\n" + helloWorldCode + "\n```\n\nI'm still really helpful.\n```typescript\n" + logXCode + "\n```\n\nMore unhelpful chat";
10
+ test('parseCodeFromMarkdown should parse 1 block of code', () => {
11
+ expect(OpenAi_1.OpenAi.parseCodeFromMarkdown(testOneBlock)).toBe(helloWorldCode);
12
+ });
13
+ test('parseCodeFromMarkdown should parse 1 block of code that contains ticks', () => {
14
+ expect(OpenAi_1.OpenAi.parseCodeFromMarkdown(testOneBlockWithExtraTicks)).toBe(helloWorldWithTicksCode);
15
+ });
16
+ test('parseCodeFromMarkdown should parse 1 block of code', () => {
17
+ expect(OpenAi_1.OpenAi.parseCodeFromMarkdown(testTwoBlocks)).toBe(helloWorldCode + '\n\n' + logXCode);
18
+ });
@@ -0,0 +1,29 @@
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
+ // test(`Return repo of the source files and the code they depend on`, async () => {
13
+ // const tableTemplatePath = require.resolve('conversation/src/table.ts');
14
+ // const repo = await new RepoFactory([tableTemplatePath]).create();
15
+ // console.log(JSON.stringify(Object.keys(repo.declarations), null, 2));
16
+ // }, 60000);
17
+ // test(`It should be able to reference code`, async () => {
18
+ // }, 60000);
19
+ // test(`Interpret all parameters of a function`, async () => {
20
+ // }, 60000);
21
+ // test(`Gather parameter data from the user`, async () => {
22
+ // const conversation = new Conversation();
23
+ // }, 60000);
24
+ // test(`Generate code from templates guided by user input`, async () => {
25
+ // }, 60000);
26
+ test(`Create repo`, () => __awaiter(void 0, void 0, void 0, function* () {
27
+ // console.log(JSON.stringify((await RepoFactory.createRepo(`${process.cwd()}`)).params, null, 4));
28
+ // console.log(JSON.stringify(await Fs.getFilesInDirectory(`${process.cwd()}`, ['node_modules', 'dist']), null, 4));
29
+ }), 60000);
@@ -0,0 +1 @@
1
+ "use strict";
package/index.ts ADDED
@@ -0,0 +1,11 @@
1
+ export * from './src/Sentence';
2
+ export * from './src/Paragraph';
3
+ export * from './src/OpenAi';
4
+ export * from './src/code_template/CodeTemplate';
5
+ export * from './src/Conversation';
6
+ export * from './src/CodegenConversation';
7
+ export * from './src/code_template/Code';
8
+ export * from './src/ConversationModule';
9
+ export * from './src/Function';
10
+ export * from './src/history/MessageModerator';
11
+ export * from './src/history/MessageHistory';
package/jest.config.js ADDED
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ preset: 'ts-jest',
3
+ testEnvironment: 'node',
4
+ transform: {
5
+ '^.+\\.tsx?$': 'ts-jest',
6
+ },
7
+ testMatch: ["**/?(*.)+(spec|test).ts"],
8
+ setupFiles: ['./test/setup'],
9
+ };
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@proteinjs/conversation",
3
+ "version": "1.0.1",
4
+ "main": "dist/index.js",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "scripts": {
9
+ "clean": "rm -rf dist/ node_modules/ package-lock.json",
10
+ "build": "tsc",
11
+ "watch": "tsc -w -p .",
12
+ "start": "node ./dist/index.js",
13
+ "test": "jest"
14
+ },
15
+ "devDependencies": {
16
+ "@jest/globals": "^29.6.4",
17
+ "@types/fs-extra": "11.0.1",
18
+ "@types/jest": "^29.5.4",
19
+ "@types/node": "20.5.9",
20
+ "@types/readline-sync": "1.4.4",
21
+ "jest": "^29.6.4",
22
+ "ts-jest": "^29.1.1"
23
+ },
24
+ "dependencies": {
25
+ "@proteinjs/util": "1.0.18",
26
+ "@proteinjs/util-node": "1.0.21",
27
+ "fs-extra": "11.1.1",
28
+ "openai": "4.4.0",
29
+ "readline-sync": "1.4.10",
30
+ "tiktoken": "1.0.11",
31
+ "typescript": "5.2.2"
32
+ },
33
+ "gitHead": "20fbdf62cdb42f62ce7972d7f7de91b9bfba3b31"
34
+ }