@proteinjs/conversation 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/.eslintrc.js +20 -0
  2. package/.prettierignore +4 -0
  3. package/.prettierrc +8 -0
  4. package/CHANGELOG.md +18 -4
  5. package/LICENSE +21 -0
  6. package/dist/src/CodegenConversation.d.ts.map +1 -1
  7. package/dist/src/CodegenConversation.js +2 -2
  8. package/dist/src/CodegenConversation.js.map +1 -1
  9. package/dist/src/Conversation.d.ts.map +1 -1
  10. package/dist/src/Conversation.js +33 -17
  11. package/dist/src/Conversation.js.map +1 -1
  12. package/dist/src/Function.d.ts.map +1 -1
  13. package/dist/src/OpenAi.d.ts.map +1 -1
  14. package/dist/src/OpenAi.js +55 -38
  15. package/dist/src/OpenAi.js.map +1 -1
  16. package/dist/src/Paragraph.d.ts.map +1 -1
  17. package/dist/src/Paragraph.js +2 -1
  18. package/dist/src/Paragraph.js.map +1 -1
  19. package/dist/src/Sentence.d.ts.map +1 -1
  20. package/dist/src/Sentence.js +4 -2
  21. package/dist/src/Sentence.js.map +1 -1
  22. package/dist/src/code_template/Code.d.ts.map +1 -1
  23. package/dist/src/code_template/Code.js +6 -2
  24. package/dist/src/code_template/Code.js.map +1 -1
  25. package/dist/src/code_template/CodeTemplate.d.ts.map +1 -1
  26. package/dist/src/code_template/CodeTemplate.js +2 -1
  27. package/dist/src/code_template/CodeTemplate.js.map +1 -1
  28. package/dist/src/code_template/Repo.d.ts.map +1 -1
  29. package/dist/src/code_template/Repo.js +8 -4
  30. package/dist/src/code_template/Repo.js.map +1 -1
  31. package/dist/src/fs/conversation_fs/ConversationFsModerator.d.ts.map +1 -1
  32. package/dist/src/fs/conversation_fs/ConversationFsModerator.js +18 -7
  33. package/dist/src/fs/conversation_fs/ConversationFsModerator.js.map +1 -1
  34. package/dist/src/fs/conversation_fs/ConversationFsModule.d.ts.map +1 -1
  35. package/dist/src/fs/conversation_fs/ConversationFsModule.js +1 -3
  36. package/dist/src/fs/conversation_fs/ConversationFsModule.js.map +1 -1
  37. package/dist/src/fs/conversation_fs/FsFunctions.d.ts.map +1 -1
  38. package/dist/src/fs/conversation_fs/FsFunctions.js +15 -29
  39. package/dist/src/fs/conversation_fs/FsFunctions.js.map +1 -1
  40. package/dist/src/fs/git/GitModule.d.ts.map +1 -1
  41. package/dist/src/fs/git/GitModule.js.map +1 -1
  42. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.d.ts.map +1 -1
  43. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.js +2 -2
  44. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.js.map +1 -1
  45. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.d.ts.map +1 -1
  46. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.js +1 -3
  47. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.js.map +1 -1
  48. package/dist/src/fs/package/PackageFunctions.d.ts.map +1 -1
  49. package/dist/src/fs/package/PackageFunctions.js +20 -30
  50. package/dist/src/fs/package/PackageFunctions.js.map +1 -1
  51. package/dist/src/fs/package/PackageModule.d.ts.map +1 -1
  52. package/dist/src/fs/package/PackageModule.js +15 -8
  53. package/dist/src/fs/package/PackageModule.js.map +1 -1
  54. package/dist/src/history/MessageHistory.d.ts.map +1 -1
  55. package/dist/src/history/MessageHistory.js +6 -3
  56. package/dist/src/history/MessageHistory.js.map +1 -1
  57. package/dist/src/template/ConversationTemplate.d.ts.map +1 -1
  58. package/dist/src/template/ConversationTemplateFunctions.d.ts.map +1 -1
  59. package/dist/src/template/ConversationTemplateFunctions.js +2 -2
  60. package/dist/src/template/ConversationTemplateFunctions.js.map +1 -1
  61. package/dist/src/template/ConversationTemplateModule.d.ts.map +1 -1
  62. package/dist/src/template/ConversationTemplateModule.js +9 -7
  63. package/dist/src/template/ConversationTemplateModule.js.map +1 -1
  64. package/dist/src/template/createCode/CreateCodeConversationTemplate.d.ts.map +1 -1
  65. package/dist/src/template/createCode/CreateCodeConversationTemplate.js +2 -9
  66. package/dist/src/template/createCode/CreateCodeConversationTemplate.js.map +1 -1
  67. package/dist/src/template/createPackage/CreatePackageConversationTemplate.d.ts.map +1 -1
  68. package/dist/src/template/createPackage/CreatePackageConversationTemplate.js +1 -8
  69. package/dist/src/template/createPackage/CreatePackageConversationTemplate.js.map +1 -1
  70. package/dist/test/createKeywordFilesIndex.test.js.map +1 -1
  71. package/dist/test/openai/openai.generateList.test.js.map +1 -1
  72. package/dist/test/openai/openai.parseCodeFromMarkdown.test.js +7 -3
  73. package/dist/test/openai/openai.parseCodeFromMarkdown.test.js.map +1 -1
  74. package/dist/test/repo/repo.test.js.map +1 -1
  75. package/jest.config.js +2 -2
  76. package/package.json +9 -3
  77. package/src/CodegenConversation.ts +6 -4
  78. package/src/Conversation.ts +102 -33
  79. package/src/ConversationModule.ts +2 -2
  80. package/src/Function.ts +0 -1
  81. package/src/OpenAi.ts +128 -63
  82. package/src/Paragraph.ts +3 -2
  83. package/src/Sentence.ts +5 -3
  84. package/src/code_template/Code.ts +25 -19
  85. package/src/code_template/CodeTemplate.ts +8 -7
  86. package/src/code_template/CodeTemplateModule.ts +2 -2
  87. package/src/code_template/Repo.ts +25 -19
  88. package/src/fs/conversation_fs/ConversationFsModerator.ts +34 -20
  89. package/src/fs/conversation_fs/ConversationFsModule.ts +13 -7
  90. package/src/fs/conversation_fs/FsFunctions.ts +33 -44
  91. package/src/fs/git/GitModule.ts +2 -4
  92. package/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.ts +31 -31
  93. package/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.ts +19 -18
  94. package/src/fs/package/PackageFunctions.ts +34 -41
  95. package/src/fs/package/PackageModule.ts +33 -21
  96. package/src/history/MessageHistory.ts +7 -4
  97. package/src/history/MessageModerator.ts +1 -1
  98. package/src/template/ConversationTemplate.ts +9 -9
  99. package/src/template/ConversationTemplateFunctions.ts +8 -7
  100. package/src/template/ConversationTemplateModule.ts +24 -15
  101. package/src/template/createApp/CreateAppTemplate.ts +1 -1
  102. package/src/template/createCode/CreateCodeConversationTemplate.ts +9 -11
  103. package/src/template/createPackage/CreatePackageConversationTemplate.ts +2 -9
  104. package/src/template/createPackage/jest.config.js +2 -2
  105. package/test/createKeywordFilesIndex.test.ts +3 -3
  106. package/test/openai/openai.generateList.test.ts +5 -3
  107. package/test/openai/openai.parseCodeFromMarkdown.test.ts +10 -5
  108. package/test/repo/repo.test.ts +3 -4
  109. package/tsconfig.json +16 -20
@@ -1,4 +1,4 @@
1
- import { KeywordToFilesIndexModule } from './KeywordToFilesIndexModule'
1
+ import { KeywordToFilesIndexModule } from './KeywordToFilesIndexModule';
2
2
 
3
3
  export const searchFilesFunctionName = 'searchFiles';
4
4
  export const searchFilesFunction = (module: KeywordToFilesIndexModule) => {
@@ -11,10 +11,10 @@ export const searchFilesFunction = (module: KeywordToFilesIndexModule) => {
11
11
  properties: {
12
12
  keyword: {
13
13
  type: 'string',
14
- description: 'Search files for this keyword'
14
+ description: 'Search files for this keyword',
15
15
  },
16
16
  },
17
- required: ['keyword']
17
+ required: ['keyword'],
18
18
  },
19
19
  },
20
20
  call: async (params: { keyword: string }) => module.searchFiles(params),
@@ -23,33 +23,33 @@ export const searchFilesFunction = (module: KeywordToFilesIndexModule) => {
23
23
  `Only call functions that take in filePaths with valid file paths, if you don't know the valid file path try and search for it by keyword with the ${searchFilesFunctionName} function`,
24
24
  `If the user references a file in a package without providing a path, use the ${searchFilesFunctionName} function on the keyword to find potentially relevant files, and choose the one that references the package name in its path`,
25
25
  ],
26
- }
27
- }
26
+ };
27
+ };
28
28
 
29
29
  // {
30
- // definition: {
31
- // name: 'getDeclarations',
32
- // description: 'Get the typescript declarations of files',
33
- // parameters: {
34
- // type: 'object',
35
- // properties: {
36
- // tsFilePaths: {
37
- // type: 'array',
38
- // description: 'Paths to the files',
39
- // items: {
40
- // type: 'string',
41
- // },
42
- // },
43
- // includeDependencyDeclarations: {
44
- // type: 'boolean',
45
- // description: 'if true, returns declarations for input tsFilePaths and all dependencies. defaults to false.'
46
- // },
47
- // },
48
- // required: ['tsFilePaths']
49
- // },
50
- // },
51
- // call: async (params: { tsFilePaths: string[] }) => this.repo.getDeclarations(params),
52
- // instructions: [
53
- // `Favor calling getDeclarations over readFiles if full file content is not needed`,
54
- // ],
55
- // },
30
+ // definition: {
31
+ // name: 'getDeclarations',
32
+ // description: 'Get the typescript declarations of files',
33
+ // parameters: {
34
+ // type: 'object',
35
+ // properties: {
36
+ // tsFilePaths: {
37
+ // type: 'array',
38
+ // description: 'Paths to the files',
39
+ // items: {
40
+ // type: 'string',
41
+ // },
42
+ // },
43
+ // includeDependencyDeclarations: {
44
+ // type: 'boolean',
45
+ // description: 'if true, returns declarations for input tsFilePaths and all dependencies. defaults to false.'
46
+ // },
47
+ // },
48
+ // required: ['tsFilePaths']
49
+ // },
50
+ // },
51
+ // call: async (params: { tsFilePaths: string[] }) => this.repo.getDeclarations(params),
52
+ // instructions: [
53
+ // `Favor calling getDeclarations over readFiles if full file content is not needed`,
54
+ // ],
55
+ // },
@@ -6,9 +6,9 @@ import path from 'path';
6
6
  import { searchFilesFunction, searchFilesFunctionName } from './KeywordToFilesIndexFunctions';
7
7
 
8
8
  export type KeywordToFilesIndexModuleParams = {
9
- dir: string,
10
- keywordFilesIndex: { [keyword: string]: string[] /** file paths */ },
11
- }
9
+ dir: string;
10
+ keywordFilesIndex: { [keyword: string]: string[] /** file paths */ };
11
+ };
12
12
 
13
13
  export class KeywordToFilesIndexModule implements ConversationModule {
14
14
  private logger = new Logger(this.constructor.name);
@@ -35,9 +35,7 @@ export class KeywordToFilesIndexModule implements ConversationModule {
35
35
  }
36
36
 
37
37
  getFunctions(): Function[] {
38
- return [
39
- searchFilesFunction(this),
40
- ];
38
+ return [searchFilesFunction(this)];
41
39
  }
42
40
 
43
41
  getMessageModerators() {
@@ -50,7 +48,7 @@ export class KeywordToFilesIndexModuleFactory implements ConversationModuleFacto
50
48
 
51
49
  async createModule(repoPath: string): Promise<KeywordToFilesIndexModule> {
52
50
  this.logger.debug(`Creating module for repo: ${repoPath}`);
53
- let repoParams: KeywordToFilesIndexModuleParams = { keywordFilesIndex: {}, dir: repoPath };
51
+ const repoParams: KeywordToFilesIndexModuleParams = { keywordFilesIndex: {}, dir: repoPath };
54
52
  repoParams.keywordFilesIndex = await this.createKeywordFilesIndex(repoPath, ['**/node-typescript-parser/**']);
55
53
  this.logger.debug(`Created module for repo: ${repoPath}`);
56
54
  return new KeywordToFilesIndexModule(repoParams);
@@ -58,14 +56,17 @@ export class KeywordToFilesIndexModuleFactory implements ConversationModuleFacto
58
56
 
59
57
  /**
60
58
  * Create keyword-files index for the given base directory.
61
- *
59
+ *
62
60
  * @param baseDir - The directory to start the file search from.
63
61
  * @returns An index with keywords mapped to file paths.
64
62
  */
65
- async createKeywordFilesIndex(baseDir: string, globIgnorePatterns: string[] = []): Promise<{ [keyword: string]: string[] }> {
63
+ async createKeywordFilesIndex(
64
+ baseDir: string,
65
+ globIgnorePatterns: string[] = []
66
+ ): Promise<{ [keyword: string]: string[] }> {
66
67
  // Ensure the base directory has a trailing slash
67
68
  if (!baseDir.endsWith(path.sep)) {
68
- baseDir += path.sep;
69
+ baseDir += path.sep;
69
70
  }
70
71
 
71
72
  // Get all file paths, recursively, excluding node_modules and dist directories
@@ -75,14 +76,14 @@ export class KeywordToFilesIndexModuleFactory implements ConversationModuleFacto
75
76
 
76
77
  // Process each file path
77
78
  for (const filePath of filePaths) {
78
- const fileName = path.parse(filePath).name; // Get file name without extension
79
-
80
- if (!keywordFilesIndex[fileName]) {
81
- keywordFilesIndex[fileName] = [];
82
- }
83
-
84
- this.logger.debug(`fileName: ${fileName}, filePath: ${filePath}`);
85
- keywordFilesIndex[fileName].push(filePath);
79
+ const fileName = path.parse(filePath).name; // Get file name without extension
80
+
81
+ if (!keywordFilesIndex[fileName]) {
82
+ keywordFilesIndex[fileName] = [];
83
+ }
84
+
85
+ this.logger.debug(`fileName: ${fileName}, filePath: ${filePath}`);
86
+ keywordFilesIndex[fileName].push(filePath);
86
87
  }
87
88
 
88
89
  return keywordFilesIndex;
@@ -39,16 +39,15 @@ export const installPackagesFunction: Function = {
39
39
  cwdPath: {
40
40
  type: 'string',
41
41
  description: 'The directory to install packages in',
42
- }
42
+ },
43
43
  },
44
- required: ['packages', 'cwdPath']
44
+ required: ['packages', 'cwdPath'],
45
45
  },
46
46
  },
47
- call: async (params: { packages: Package[], cwdPath: string }) => await PackageUtil.installPackages(params.packages, params.cwdPath),
48
- instructions: [
49
- `To install a package, use the ${installPackagesFunctionName} function`,
50
- ],
51
- }
47
+ call: async (params: { packages: Package[]; cwdPath: string }) =>
48
+ await PackageUtil.installPackages(params.packages, params.cwdPath),
49
+ instructions: [`To install a package, use the ${installPackagesFunctionName} function`],
50
+ };
52
51
 
53
52
  export const runPackageScriptFunctionName = 'runPackageScript';
54
53
  const runPackageScriptFunction: Function = {
@@ -65,16 +64,17 @@ const runPackageScriptFunction: Function = {
65
64
  cwdPath: {
66
65
  type: 'string',
67
66
  description: 'If omitted, defaults to process.cwd',
68
- }
67
+ },
69
68
  },
70
- required: ['name']
69
+ required: ['name'],
71
70
  },
72
71
  },
73
- call: async (params: { name: string, cwdPath?: string }) => await PackageUtil.runPackageScript(params.name, params.cwdPath),
72
+ call: async (params: { name: string; cwdPath?: string }) =>
73
+ await PackageUtil.runPackageScript(params.name, params.cwdPath),
74
74
  instructions: [
75
75
  `To run a npm script (such as start, test, or watch), use the ${runPackageScriptFunctionName} function`,
76
76
  ],
77
- }
77
+ };
78
78
 
79
79
  export const searchPackagesFunctionName = 'searchPackages';
80
80
  export function searchPackagesFunction(packageModule: PackageModule) {
@@ -88,16 +88,14 @@ export function searchPackagesFunction(packageModule: PackageModule) {
88
88
  keyword: {
89
89
  type: 'string',
90
90
  description: 'Keyword to match package names',
91
- }
91
+ },
92
92
  },
93
- required: ['keyword']
93
+ required: ['keyword'],
94
94
  },
95
95
  },
96
96
  call: async (params: { keyword: string }) => await packageModule.searchPackages(params.keyword),
97
- instructions: [
98
- `To search for packages in the local repo, use the ${searchPackagesFunctionName} function`,
99
- ],
100
- }
97
+ instructions: [`To search for packages in the local repo, use the ${searchPackagesFunctionName} function`],
98
+ };
101
99
  }
102
100
 
103
101
  export const searchLibrariesFunctionName = 'searchLibraries';
@@ -112,16 +110,14 @@ export function searchLibrariesFunction(packageModule: PackageModule) {
112
110
  keyword: {
113
111
  type: 'string',
114
112
  description: 'Keyword to match file names',
115
- }
113
+ },
116
114
  },
117
- required: ['keyword']
115
+ required: ['keyword'],
118
116
  },
119
117
  },
120
118
  call: async (params: { keyword: string }) => await packageModule.searchLibraries(params.keyword),
121
- instructions: [
122
- `To search for libraries in the local repo, use the ${searchLibrariesFunctionName} function`,
123
- ],
124
- }
119
+ instructions: [`To search for libraries in the local repo, use the ${searchLibrariesFunctionName} function`],
120
+ };
125
121
  }
126
122
 
127
123
  export const generateTypescriptDeclarationsFunctionName = 'generateTypescriptDesclarations';
@@ -137,17 +133,17 @@ export const generateTypescriptDeclarationsFunction = {
137
133
  description: 'File paths to generate declarations for',
138
134
  items: {
139
135
  type: 'string',
140
- }
141
- }
136
+ },
137
+ },
142
138
  },
143
- required: ['tsFilePaths']
139
+ required: ['tsFilePaths'],
144
140
  },
145
141
  },
146
142
  call: async (params: { tsFilePaths: string[] }) => PackageUtil.generateTypescriptDeclarations(params),
147
143
  instructions: [
148
144
  `To generate typescript declarations for a local file, use the ${generateTypescriptDeclarationsFunctionName} function`,
149
145
  ],
150
- }
146
+ };
151
147
 
152
148
  export const npmInstallFunctionName = 'npmInstall';
153
149
  export const npmInstallFunction: Function = {
@@ -160,16 +156,14 @@ export const npmInstallFunction: Function = {
160
156
  cwdPath: {
161
157
  type: 'string',
162
158
  description: 'Directory to execute the command from',
163
- }
159
+ },
164
160
  },
165
- required: ['cwdPath']
161
+ required: ['cwdPath'],
166
162
  },
167
163
  },
168
164
  call: async (params: { cwdPath: string }) => await PackageUtil.npmInstall(params.cwdPath),
169
- instructions: [
170
- `To run npm install in a specific directory, use the ${npmInstallFunctionName} function`,
171
- ],
172
- }
165
+ instructions: [`To run npm install in a specific directory, use the ${npmInstallFunctionName} function`],
166
+ };
173
167
 
174
168
  export const uninstallPackagesFunctionName = 'uninstallPackages';
175
169
  export const uninstallPackagesFunction: Function = {
@@ -190,16 +184,15 @@ export const uninstallPackagesFunction: Function = {
190
184
  cwdPath: {
191
185
  type: 'string',
192
186
  description: 'The directory to uninstall packages from',
193
- }
187
+ },
194
188
  },
195
- required: ['packageNames', 'cwdPath']
189
+ required: ['packageNames', 'cwdPath'],
196
190
  },
197
191
  },
198
- call: async (params: { packageNames: string[], cwdPath: string }) => await PackageUtil.uninstallPackages(params.packageNames, params.cwdPath),
199
- instructions: [
200
- `To uninstall a package, use the ${uninstallPackagesFunctionName} function`,
201
- ],
202
- }
192
+ call: async (params: { packageNames: string[]; cwdPath: string }) =>
193
+ await PackageUtil.uninstallPackages(params.packageNames, params.cwdPath),
194
+ instructions: [`To uninstall a package, use the ${uninstallPackagesFunctionName} function`],
195
+ };
203
196
 
204
197
  export const packageFunctions: Function[] = [
205
198
  installPackagesFunction,
@@ -207,4 +200,4 @@ export const packageFunctions: Function[] = [
207
200
  generateTypescriptDeclarationsFunction,
208
201
  npmInstallFunction,
209
202
  uninstallPackagesFunction,
210
- ]
203
+ ];
@@ -1,21 +1,27 @@
1
1
  import { Fs } from '@proteinjs/util-node';
2
2
  import { ConversationModule, ConversationModuleFactory } from '../../ConversationModule';
3
3
  import { Function } from '../../Function';
4
- import { packageFunctions, searchLibrariesFunction, searchLibrariesFunctionName, searchPackagesFunction, searchPackagesFunctionName } from './PackageFunctions';
4
+ import {
5
+ packageFunctions,
6
+ searchLibrariesFunction,
7
+ searchLibrariesFunctionName,
8
+ searchPackagesFunction,
9
+ searchPackagesFunctionName,
10
+ } from './PackageFunctions';
5
11
  import path from 'path';
6
12
  import { searchFilesFunctionName } from '../keyword_to_files_index/KeywordToFilesIndexFunctions';
7
13
  import { readFilesFunctionName } from '../conversation_fs/FsFunctions';
8
14
 
9
15
  export type Library = {
10
- fileName: string,
11
- filePath: string,
12
- packageName: string,
13
- }
16
+ fileName: string;
17
+ filePath: string;
18
+ packageName: string;
19
+ };
14
20
 
15
21
  export type LibraryImport = {
16
- importStatements: string[],
17
- typescriptDeclaration: string,
18
- }
22
+ importStatements: string[];
23
+ typescriptDeclaration: string;
24
+ };
19
25
 
20
26
  export class PackageModule implements ConversationModule {
21
27
  private repoPath: string;
@@ -39,11 +45,7 @@ export class PackageModule implements ConversationModule {
39
45
  }
40
46
 
41
47
  getFunctions(): Function[] {
42
- return [
43
- ...packageFunctions,
44
- searchPackagesFunction(this),
45
- searchLibrariesFunction(this),
46
- ];
48
+ return [...packageFunctions, searchPackagesFunction(this), searchLibrariesFunction(this)];
47
49
  }
48
50
 
49
51
  getMessageModerators() {
@@ -56,12 +58,16 @@ export class PackageModule implements ConversationModule {
56
58
  */
57
59
  async searchPackages(keyword: string): Promise<string[]> {
58
60
  const matchingPackageJsonPaths: string[] = [];
59
- const packageJsonFilePaths = await Fs.getFilePathsMatchingGlob(this.repoPath, '**/package.json', ['**/node_modules/**', '**/dist/**']);
61
+ const packageJsonFilePaths = await Fs.getFilePathsMatchingGlob(this.repoPath, '**/package.json', [
62
+ '**/node_modules/**',
63
+ '**/dist/**',
64
+ ]);
60
65
  const packageJsonFileMap = await Fs.readFiles(packageJsonFilePaths);
61
- for (let packageJsonFilePath of Object.keys(packageJsonFileMap)) {
66
+ for (const packageJsonFilePath of Object.keys(packageJsonFileMap)) {
62
67
  const packageJson = JSON.parse(packageJsonFileMap[packageJsonFilePath]);
63
- if (packageJson.name.toLowerCase().includes(keyword.toLocaleLowerCase()))
68
+ if (packageJson.name.toLowerCase().includes(keyword.toLocaleLowerCase())) {
64
69
  matchingPackageJsonPaths.push(packageJsonFilePath);
70
+ }
65
71
  }
66
72
 
67
73
  return matchingPackageJsonPaths;
@@ -74,15 +80,21 @@ export class PackageModule implements ConversationModule {
74
80
  */
75
81
  async searchLibraries(keyword: string): Promise<Library[]> {
76
82
  const matchingLibraries: Library[] = [];
77
- const packageJsonFilePaths = await Fs.getFilePathsMatchingGlob(this.repoPath, '**/package.json', ['**/node_modules/**', '**/dist/**']);
83
+ const packageJsonFilePaths = await Fs.getFilePathsMatchingGlob(this.repoPath, '**/package.json', [
84
+ '**/node_modules/**',
85
+ '**/dist/**',
86
+ ]);
78
87
  const packageJsonFileMap = await Fs.readFiles(packageJsonFilePaths);
79
- for (let packageJsonFilePath of Object.keys(packageJsonFileMap)) {
88
+ for (const packageJsonFilePath of Object.keys(packageJsonFileMap)) {
80
89
  const packageJson = JSON.parse(packageJsonFileMap[packageJsonFilePath]);
81
90
  const packageJsonFilePathParts = packageJsonFilePath.split(path.sep);
82
91
  packageJsonFilePathParts.pop();
83
92
  const packageDirectory = packageJsonFilePathParts.join(path.sep);
84
- const srcFilePaths = await Fs.getFilePathsMatchingGlob(path.join(packageDirectory, 'src'), '**/*.ts', ['**/node_modules/**', '**/dist/**']);
85
- for (let srcFilePath of srcFilePaths) {
93
+ const srcFilePaths = await Fs.getFilePathsMatchingGlob(path.join(packageDirectory, 'src'), '**/*.ts', [
94
+ '**/node_modules/**',
95
+ '**/dist/**',
96
+ ]);
97
+ for (const srcFilePath of srcFilePaths) {
86
98
  const fileNameWithExtension = path.basename(srcFilePath);
87
99
  if (fileNameWithExtension.includes(keyword)) {
88
100
  const fileName = path.basename(srcFilePath, path.extname(srcFilePath));
@@ -103,4 +115,4 @@ export class PackageModuleFactory implements ConversationModuleFactory {
103
115
  async createModule(repoPath: string): Promise<PackageModule> {
104
116
  return new PackageModule(repoPath);
105
117
  }
106
- }
118
+ }
@@ -20,7 +20,7 @@ export class MessageHistory {
20
20
  }
21
21
 
22
22
  toString() {
23
- return this.messages.map(message => message.content).join('. ');
23
+ return this.messages.map((message) => message.content).join('. ');
24
24
  }
25
25
 
26
26
  setMessages(messages: ChatCompletionMessageParam[]): MessageHistory {
@@ -36,19 +36,22 @@ export class MessageHistory {
36
36
  }
37
37
 
38
38
  prune() {
39
- if (this.params.enforceMessageLimit === false)
39
+ if (this.params.enforceMessageLimit === false) {
40
40
  return;
41
+ }
41
42
 
42
43
  let messageCount = 0;
43
44
  const messagesToRemoveIndexes: number[] = [];
44
45
  for (let i = this.messages.length - 1; i >= 0; i--) {
45
46
  const message = this.messages[i];
46
- if (message.role == 'system')
47
+ if (message.role == 'system') {
47
48
  continue;
49
+ }
48
50
 
49
51
  messageCount++;
50
- if (messageCount > this.params.maxMessages)
52
+ if (messageCount > this.params.maxMessages) {
51
53
  messagesToRemoveIndexes.push(i);
54
+ }
52
55
  }
53
56
 
54
57
  this.messages = this.messages.filter((message, i) => !messagesToRemoveIndexes.includes(i));
@@ -3,4 +3,4 @@ import { ChatCompletionMessageParam } from 'openai/resources/chat';
3
3
  export interface MessageModerator {
4
4
  // given a set of messages, modify and return
5
5
  observe(messages: ChatCompletionMessageParam[]): ChatCompletionMessageParam[];
6
- }
6
+ }
@@ -1,12 +1,12 @@
1
1
  export type Question = {
2
- text: string,
3
- optional?: boolean,
4
- }
2
+ text: string;
3
+ optional?: boolean;
4
+ };
5
5
 
6
6
  export type ConversationTemplate = {
7
- name: string,
8
- keywords: string[],
9
- description: string,
10
- questions: Question[],
11
- instructions: () => Promise<string[]>,
12
- }
7
+ name: string;
8
+ keywords: string[];
9
+ description: string;
10
+ questions: Question[];
11
+ instructions: () => Promise<string[]>;
12
+ };
@@ -14,12 +14,12 @@ export const searchConversationTemplatesFunction = (repo: ConversationTemplateMo
14
14
  description: 'Search for conversation template names that match this keyword',
15
15
  },
16
16
  },
17
- required: ['keyword']
17
+ required: ['keyword'],
18
18
  },
19
19
  },
20
20
  call: async (params: { keyword: string }) => repo.searchConversationTemplates(params.keyword),
21
- }
22
- }
21
+ };
22
+ };
23
23
 
24
24
  export const getConversationTemplateFunctionName = 'getConversationTemplate';
25
25
  export const getConversationTemplateFunction = (repo: ConversationTemplateModule) => {
@@ -35,9 +35,10 @@ export const getConversationTemplateFunction = (repo: ConversationTemplateModule
35
35
  description: 'Get the conversation template that has this name',
36
36
  },
37
37
  },
38
- required: ['conversationTemplateName']
38
+ required: ['conversationTemplateName'],
39
39
  },
40
40
  },
41
- call: async (params: { conversationTemplateName: string }) => await repo.getConversationTemplate(params.conversationTemplateName),
42
- }
43
- }
41
+ call: async (params: { conversationTemplateName: string }) =>
42
+ await repo.getConversationTemplate(params.conversationTemplateName),
43
+ };
44
+ };
@@ -2,7 +2,12 @@ import { Logger } from '@proteinjs/util';
2
2
  import { ConversationTemplate } from './ConversationTemplate';
3
3
  import { createPackageConversationTemplate } from './createPackage/CreatePackageConversationTemplate';
4
4
  import { ConversationModule, ConversationModuleFactory } from '../ConversationModule';
5
- import { getConversationTemplateFunction, getConversationTemplateFunctionName, searchConversationTemplatesFunction, searchConversationTemplatesFunctionName } from './ConversationTemplateFunctions';
5
+ import {
6
+ getConversationTemplateFunction,
7
+ getConversationTemplateFunctionName,
8
+ searchConversationTemplatesFunction,
9
+ searchConversationTemplatesFunctionName,
10
+ } from './ConversationTemplateFunctions';
6
11
  import { createCodeConversationTemplate } from './createCode/CreateCodeConversationTemplate';
7
12
  import { createAppTemplate } from './createApp/CreateAppTemplate';
8
13
 
@@ -13,9 +18,9 @@ const conversationTemplates: ConversationTemplate[] = [
13
18
  ];
14
19
 
15
20
  export type ConversationTemplateModuleParams = {
16
- conversationTemplates: { [conversationTemplateName: string]: ConversationTemplate},
17
- conversationTemplateKeywordIndex: { [keyword: string]: string[] /** conversationTemplateNames */ }
18
- }
21
+ conversationTemplates: { [conversationTemplateName: string]: ConversationTemplate };
22
+ conversationTemplateKeywordIndex: { [keyword: string]: string[] /** conversationTemplateNames */ };
23
+ };
19
24
 
20
25
  export class ConversationTemplateModule implements ConversationModule {
21
26
  private logger = new Logger(this.constructor.name);
@@ -35,10 +40,13 @@ export class ConversationTemplateModule implements ConversationModule {
35
40
  return conversationNames || [];
36
41
  }
37
42
 
38
- async getConversationTemplate(conversationTemplateName: string): Promise<Omit<ConversationTemplate, 'instructions'> & { instructions: string[] }> {
43
+ async getConversationTemplate(
44
+ conversationTemplateName: string
45
+ ): Promise<Omit<ConversationTemplate, 'instructions'> & { instructions: string[] }> {
39
46
  const conversationTemplate = this.params.conversationTemplates[conversationTemplateName];
40
- if (!conversationTemplate)
47
+ if (!conversationTemplate) {
41
48
  return {} as any;
49
+ }
42
50
 
43
51
  const instructions = await conversationTemplate.instructions();
44
52
  return Object.assign(conversationTemplate, { instructions });
@@ -54,10 +62,7 @@ export class ConversationTemplateModule implements ConversationModule {
54
62
  }
55
63
 
56
64
  getFunctions() {
57
- return [
58
- searchConversationTemplatesFunction(this),
59
- getConversationTemplateFunction(this),
60
- ];
65
+ return [searchConversationTemplatesFunction(this), getConversationTemplateFunction(this)];
61
66
  }
62
67
 
63
68
  getMessageModerators() {
@@ -67,12 +72,16 @@ export class ConversationTemplateModule implements ConversationModule {
67
72
 
68
73
  export class ConversationTemplateModuleFactory implements ConversationModuleFactory {
69
74
  async createModule(repoPath: string) {
70
- const params: ConversationTemplateModuleParams = { conversationTemplates: {}, conversationTemplateKeywordIndex: {} };
71
- for (let conversationTemplate of conversationTemplates) {
75
+ const params: ConversationTemplateModuleParams = {
76
+ conversationTemplates: {},
77
+ conversationTemplateKeywordIndex: {},
78
+ };
79
+ for (const conversationTemplate of conversationTemplates) {
72
80
  params.conversationTemplates[conversationTemplate.name] = conversationTemplate;
73
- for (let keyword of conversationTemplate.keywords) {
74
- if (!params.conversationTemplateKeywordIndex[keyword])
81
+ for (const keyword of conversationTemplate.keywords) {
82
+ if (!params.conversationTemplateKeywordIndex[keyword]) {
75
83
  params.conversationTemplateKeywordIndex[keyword] = [];
84
+ }
76
85
 
77
86
  params.conversationTemplateKeywordIndex[keyword].push(conversationTemplate.name);
78
87
  }
@@ -80,4 +89,4 @@ export class ConversationTemplateModuleFactory implements ConversationModuleFact
80
89
 
81
90
  return new ConversationTemplateModule(params);
82
91
  }
83
- }
92
+ }
@@ -30,4 +30,4 @@ export const createAppTemplate: ConversationTemplate = {
30
30
  description: 'This template will guide you through the process of creating a new app.',
31
31
  questions: createAppQuestions,
32
32
  instructions: createAppInstructions,
33
- };
33
+ };
@@ -1,17 +1,15 @@
1
1
  import { fileOrDirectoryExistsFunction, readFilesFunctionName } from '../../fs/conversation_fs/FsFunctions';
2
- import { generateTypescriptDeclarationsFunction, installPackagesFunction, searchLibrariesFunctionName, searchPackagesFunctionName } from '../../fs/package/PackageFunctions';
2
+ import {
3
+ generateTypescriptDeclarationsFunction,
4
+ installPackagesFunction,
5
+ searchLibrariesFunctionName,
6
+ searchPackagesFunctionName,
7
+ } from '../../fs/package/PackageFunctions';
3
8
  import { ConversationTemplate } from '../ConversationTemplate';
4
9
 
5
10
  export const createCodeConversationTemplate: ConversationTemplate = {
6
11
  name: 'Create code',
7
- keywords: [
8
- 'create code',
9
- 'implement',
10
- 'write code',
11
- 'generate code',
12
- 'write software',
13
- 'build something',
14
- ],
12
+ keywords: ['create code', 'implement', 'write code', 'generate code', 'write software', 'build something'],
15
13
  description: 'User and ai developing together',
16
14
  questions: [],
17
15
  instructions: async () => {
@@ -37,5 +35,5 @@ export const createCodeConversationTemplate: ConversationTemplate = {
37
35
  `3.c. When writing the code to file, if updating an existing file, be sure to read the file first to not blow away existing code. Be sure to preserve comments as well.`,
38
36
  `4. Repeat 3. unless the user asks to switch packages or files`,
39
37
  ];
40
- }
41
- }
38
+ },
39
+ };
@@ -5,14 +5,7 @@ import tConfig from './tsconfig.json';
5
5
 
6
6
  export const createPackageConversationTemplate: ConversationTemplate = {
7
7
  name: 'Create Package',
8
- keywords: [
9
- 'package',
10
- 'create package',
11
- 'create',
12
- 'create a package',
13
- 'create a new package',
14
- `new package`,
15
- ],
8
+ keywords: ['package', 'create package', 'create', 'create a package', 'create a new package', `new package`],
16
9
  description: 'Create a npm package',
17
10
  questions: [
18
11
  { text: `Which folder should the package be created in?` },
@@ -39,4 +32,4 @@ export const createPackageConversationTemplate: ConversationTemplate = {
39
32
  `If it's a typescript project, create a tsconfig.json file in the pakage directory with the following content: ${tsConfig}`,
40
33
  ];
41
34
  },
42
- }
35
+ };
@@ -4,6 +4,6 @@ module.exports = {
4
4
  transform: {
5
5
  '^.+\\.tsx?$': 'ts-jest',
6
6
  },
7
- testMatch: ["**/?(*.)+(spec|test).ts"],
7
+ testMatch: ['**/?(*.)+(spec|test).ts'],
8
8
  setupFiles: ['./test/setup'],
9
- };
9
+ };