genaicode 0.0.37 → 0.1.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 (244) hide show
  1. package/bin/genaicode-dev.js +11 -0
  2. package/bin/genaicode.cjs +8 -1
  3. package/dist/ai-service/ai-studio.d.ts +5 -0
  4. package/dist/ai-service/ai-studio.js +135 -0
  5. package/dist/ai-service/ai-studio.js.map +1 -0
  6. package/dist/ai-service/anthropic.d.ts +5 -0
  7. package/dist/ai-service/anthropic.js +133 -0
  8. package/dist/ai-service/anthropic.js.map +1 -0
  9. package/dist/ai-service/chat-gpt.d.ts +5 -0
  10. package/dist/ai-service/chat-gpt.js +131 -0
  11. package/dist/ai-service/chat-gpt.js.map +1 -0
  12. package/dist/ai-service/common.d.ts +57 -0
  13. package/dist/ai-service/common.js +38 -0
  14. package/dist/ai-service/common.js.map +1 -0
  15. package/dist/ai-service/common.test.d.ts +1 -0
  16. package/dist/ai-service/common.test.js +85 -0
  17. package/dist/ai-service/common.test.js.map +1 -0
  18. package/dist/ai-service/dall-e.d.ts +14 -0
  19. package/dist/ai-service/dall-e.js +47 -0
  20. package/dist/ai-service/dall-e.js.map +1 -0
  21. package/dist/ai-service/vertex-ai-claude.d.ts +5 -0
  22. package/dist/ai-service/vertex-ai-claude.js +93 -0
  23. package/dist/ai-service/vertex-ai-claude.js.map +1 -0
  24. package/dist/ai-service/vertex-ai-imagen.d.ts +14 -0
  25. package/dist/ai-service/vertex-ai-imagen.js +74 -0
  26. package/dist/ai-service/vertex-ai-imagen.js.map +1 -0
  27. package/dist/ai-service/vertex-ai.d.ts +7 -0
  28. package/dist/ai-service/vertex-ai.js +147 -0
  29. package/dist/ai-service/vertex-ai.js.map +1 -0
  30. package/dist/cli/cli-options.d.ts +10 -0
  31. package/dist/cli/cli-options.js +124 -0
  32. package/dist/cli/cli-options.js.map +1 -0
  33. package/dist/cli/cli-options.test.d.ts +1 -0
  34. package/dist/cli/cli-options.test.js +34 -0
  35. package/dist/cli/cli-options.test.js.map +1 -0
  36. package/dist/cli/cli-params.d.ts +29 -0
  37. package/dist/cli/cli-params.js +103 -0
  38. package/dist/cli/cli-params.js.map +1 -0
  39. package/dist/cli/cli-params.test.d.ts +1 -0
  40. package/dist/cli/cli-params.test.js +38 -0
  41. package/dist/cli/cli-params.test.js.map +1 -0
  42. package/dist/cli/service-autodetect.d.ts +2 -0
  43. package/dist/cli/service-autodetect.js +17 -0
  44. package/dist/cli/service-autodetect.js.map +1 -0
  45. package/dist/cli/service-autodetect.test.d.ts +1 -0
  46. package/dist/cli/service-autodetect.test.js +38 -0
  47. package/dist/cli/service-autodetect.test.js.map +1 -0
  48. package/dist/cli/validate-cli-params.d.ts +18 -0
  49. package/dist/cli/validate-cli-params.js +128 -0
  50. package/dist/cli/validate-cli-params.js.map +1 -0
  51. package/dist/cli/validate-cli-params.test.d.ts +1 -0
  52. package/dist/cli/validate-cli-params.test.js +106 -0
  53. package/dist/cli/validate-cli-params.test.js.map +1 -0
  54. package/dist/files/file-utils.d.ts +2 -0
  55. package/dist/files/file-utils.js +7 -0
  56. package/dist/files/file-utils.js.map +1 -0
  57. package/dist/files/file-utils.test.d.ts +1 -0
  58. package/dist/files/file-utils.test.js +18 -0
  59. package/dist/files/file-utils.test.js.map +1 -0
  60. package/dist/files/find-files.d.ts +8 -0
  61. package/dist/files/find-files.js +76 -0
  62. package/dist/files/find-files.js.map +1 -0
  63. package/dist/files/read-files.d.ts +13 -0
  64. package/dist/files/read-files.js +61 -0
  65. package/dist/files/read-files.js.map +1 -0
  66. package/dist/files/read-files.test.d.ts +1 -0
  67. package/dist/files/read-files.test.js +89 -0
  68. package/dist/files/read-files.test.js.map +1 -0
  69. package/dist/files/temp-buffer.d.ts +2 -0
  70. package/dist/files/temp-buffer.js +12 -0
  71. package/dist/files/temp-buffer.js.map +1 -0
  72. package/dist/files/update-files.d.ts +5 -0
  73. package/dist/files/update-files.js +197 -0
  74. package/dist/files/update-files.js.map +1 -0
  75. package/dist/images/ensure-alpha.d.ts +1 -0
  76. package/dist/images/ensure-alpha.js +5 -0
  77. package/dist/images/ensure-alpha.js.map +1 -0
  78. package/dist/images/imgly-remove-background.d.ts +2 -0
  79. package/dist/images/imgly-remove-background.js +21 -0
  80. package/dist/images/imgly-remove-background.js.map +1 -0
  81. package/dist/images/resize-image.d.ts +19 -0
  82. package/dist/images/resize-image.js +22 -0
  83. package/dist/images/resize-image.js.map +1 -0
  84. package/dist/images/split-image.d.ts +18 -0
  85. package/dist/images/split-image.js +25 -0
  86. package/dist/images/split-image.js.map +1 -0
  87. package/dist/main/codegen.d.ts +2 -0
  88. package/dist/main/codegen.js +101 -0
  89. package/dist/main/codegen.js.map +1 -0
  90. package/dist/main/codegen.test.d.ts +2 -0
  91. package/dist/main/codegen.test.js +259 -0
  92. package/dist/main/codegen.test.js.map +1 -0
  93. package/dist/main/config-lib.d.ts +8 -0
  94. package/dist/main/config-lib.js +28 -0
  95. package/dist/main/config-lib.js.map +1 -0
  96. package/dist/main/config-lib.test.d.ts +1 -0
  97. package/dist/main/config-lib.test.js +64 -0
  98. package/dist/main/config-lib.test.js.map +1 -0
  99. package/dist/main/config.d.ts +5 -0
  100. package/{src → dist}/main/config.js +16 -22
  101. package/dist/main/config.js.map +1 -0
  102. package/dist/prompt/function-calling-validate.d.ts +3 -0
  103. package/dist/prompt/function-calling-validate.js +27 -0
  104. package/dist/prompt/function-calling-validate.js.map +1 -0
  105. package/dist/prompt/function-calling.d.ts +5 -0
  106. package/{src → dist}/prompt/function-calling.js +25 -24
  107. package/dist/prompt/function-calling.js.map +1 -0
  108. package/dist/prompt/function-defs/ask-question.d.ts +31 -0
  109. package/dist/prompt/function-defs/ask-question.js +32 -0
  110. package/dist/prompt/function-defs/ask-question.js.map +1 -0
  111. package/dist/prompt/function-defs/codegen-summary.d.ts +63 -0
  112. package/dist/prompt/function-defs/codegen-summary.js +80 -0
  113. package/dist/prompt/function-defs/codegen-summary.js.map +1 -0
  114. package/dist/prompt/function-defs/create-directory.d.ts +21 -0
  115. package/dist/prompt/function-defs/create-directory.js +22 -0
  116. package/dist/prompt/function-defs/create-directory.js.map +1 -0
  117. package/dist/prompt/function-defs/create-file.d.ts +25 -0
  118. package/dist/prompt/function-defs/create-file.js +26 -0
  119. package/dist/prompt/function-defs/create-file.js.map +1 -0
  120. package/dist/prompt/function-defs/delete-file.d.ts +21 -0
  121. package/dist/prompt/function-defs/delete-file.js +22 -0
  122. package/dist/prompt/function-defs/delete-file.js.map +1 -0
  123. package/dist/prompt/function-defs/download-file.d.ts +25 -0
  124. package/dist/prompt/function-defs/download-file.js +26 -0
  125. package/dist/prompt/function-defs/download-file.js.map +1 -0
  126. package/dist/prompt/function-defs/explanation.d.ts +17 -0
  127. package/dist/prompt/function-defs/explanation.js +18 -0
  128. package/dist/prompt/function-defs/explanation.js.map +1 -0
  129. package/dist/prompt/function-defs/generate-image.d.ts +48 -0
  130. package/dist/prompt/function-defs/generate-image.js +49 -0
  131. package/dist/prompt/function-defs/generate-image.js.map +1 -0
  132. package/dist/prompt/function-defs/get-image-assets.d.ts +20 -0
  133. package/dist/prompt/function-defs/get-image-assets.js +21 -0
  134. package/dist/prompt/function-defs/get-image-assets.js.map +1 -0
  135. package/dist/prompt/function-defs/get-source-code.d.ts +20 -0
  136. package/dist/prompt/function-defs/get-source-code.js +21 -0
  137. package/dist/prompt/function-defs/get-source-code.js.map +1 -0
  138. package/dist/prompt/function-defs/imgly-remove-background.d.ts +25 -0
  139. package/dist/prompt/function-defs/imgly-remove-background.js +26 -0
  140. package/dist/prompt/function-defs/imgly-remove-background.js.map +1 -0
  141. package/dist/prompt/function-defs/move-file.d.ts +25 -0
  142. package/dist/prompt/function-defs/move-file.js +26 -0
  143. package/dist/prompt/function-defs/move-file.js.map +1 -0
  144. package/dist/prompt/function-defs/patch-file.d.ts +25 -0
  145. package/dist/prompt/function-defs/patch-file.js +39 -0
  146. package/dist/prompt/function-defs/patch-file.js.map +1 -0
  147. package/dist/prompt/function-defs/resize-image.d.ts +36 -0
  148. package/dist/prompt/function-defs/resize-image.js +37 -0
  149. package/dist/prompt/function-defs/resize-image.js.map +1 -0
  150. package/dist/prompt/function-defs/split-image.d.ts +57 -0
  151. package/dist/prompt/function-defs/split-image.js +46 -0
  152. package/dist/prompt/function-defs/split-image.js.map +1 -0
  153. package/dist/prompt/function-defs/update-file.d.ts +25 -0
  154. package/dist/prompt/function-defs/update-file.js +26 -0
  155. package/dist/prompt/function-defs/update-file.js.map +1 -0
  156. package/dist/prompt/limits.d.ts +3 -0
  157. package/dist/prompt/limits.js +19 -0
  158. package/dist/prompt/limits.js.map +1 -0
  159. package/dist/prompt/limits.test.d.ts +1 -0
  160. package/dist/prompt/limits.test.js +35 -0
  161. package/dist/prompt/limits.test.js.map +1 -0
  162. package/dist/prompt/prompt-codegen.d.ts +4 -0
  163. package/dist/prompt/prompt-codegen.js +81 -0
  164. package/dist/prompt/prompt-codegen.js.map +1 -0
  165. package/dist/prompt/prompt-codegen.test.d.ts +1 -0
  166. package/dist/prompt/prompt-codegen.test.js +94 -0
  167. package/dist/prompt/prompt-codegen.test.js.map +1 -0
  168. package/dist/prompt/prompt-consts.d.ts +1 -0
  169. package/{src → dist}/prompt/prompt-consts.js +1 -0
  170. package/dist/prompt/prompt-consts.js.map +1 -0
  171. package/dist/prompt/prompt-service-ask-question.test.d.ts +3 -0
  172. package/dist/prompt/prompt-service-ask-question.test.js +146 -0
  173. package/dist/prompt/prompt-service-ask-question.test.js.map +1 -0
  174. package/dist/prompt/prompt-service.d.ts +13 -0
  175. package/dist/prompt/prompt-service.js +278 -0
  176. package/dist/prompt/prompt-service.js.map +1 -0
  177. package/dist/prompt/prompt-service.test.d.ts +1 -0
  178. package/dist/prompt/prompt-service.test.js +511 -0
  179. package/dist/prompt/prompt-service.test.js.map +1 -0
  180. package/dist/prompt/systemprompt.d.ts +2 -0
  181. package/dist/prompt/systemprompt.js +43 -0
  182. package/dist/prompt/systemprompt.js.map +1 -0
  183. package/dist/prompt/systemprompt.test.d.ts +2 -0
  184. package/dist/prompt/systemprompt.test.js +47 -0
  185. package/dist/prompt/systemprompt.test.js.map +1 -0
  186. package/package.json +13 -4
  187. package/bin/genaicode.js +0 -5
  188. package/src/ai-service/anthropic.js +0 -126
  189. package/src/ai-service/chat-gpt.js +0 -126
  190. package/src/ai-service/common.js +0 -49
  191. package/src/ai-service/common.test.js +0 -107
  192. package/src/ai-service/dall-e.js +0 -50
  193. package/src/ai-service/vertex-ai-claude.js +0 -99
  194. package/src/ai-service/vertex-ai-imagen.js +0 -78
  195. package/src/ai-service/vertex-ai.js +0 -156
  196. package/src/cli/cli-options.js +0 -132
  197. package/src/cli/cli-options.test.js +0 -50
  198. package/src/cli/cli-params.js +0 -114
  199. package/src/cli/cli-params.test.js +0 -43
  200. package/src/cli/service-autodetect.js +0 -11
  201. package/src/cli/service-autodetect.test.js +0 -43
  202. package/src/cli/validate-cli-params.js +0 -137
  203. package/src/cli/validate-cli-params.test.js +0 -134
  204. package/src/files/file-utils.js +0 -7
  205. package/src/files/file-utils.test.js +0 -21
  206. package/src/files/find-files.js +0 -86
  207. package/src/files/read-files.js +0 -65
  208. package/src/files/read-files.test.js +0 -103
  209. package/src/files/temp-buffer.js +0 -13
  210. package/src/files/update-files.js +0 -205
  211. package/src/images/ensure-alpha.js +0 -5
  212. package/src/images/imgly-remove-background.js +0 -23
  213. package/src/images/resize-image.js +0 -23
  214. package/src/images/split-image.js +0 -26
  215. package/src/main/codegen.js +0 -120
  216. package/src/main/codegen.test.js +0 -335
  217. package/src/main/config-lib.js +0 -33
  218. package/src/main/config-lib.test.js +0 -80
  219. package/src/prompt/function-calling-validate.js +0 -25
  220. package/src/prompt/function-defs/ask-question.js +0 -33
  221. package/src/prompt/function-defs/codegen-summary.js +0 -87
  222. package/src/prompt/function-defs/create-directory.js +0 -21
  223. package/src/prompt/function-defs/create-file.js +0 -26
  224. package/src/prompt/function-defs/delete-file.js +0 -21
  225. package/src/prompt/function-defs/download-file.js +0 -25
  226. package/src/prompt/function-defs/explanation.js +0 -17
  227. package/src/prompt/function-defs/generate-image.js +0 -51
  228. package/src/prompt/function-defs/get-image-assets.js +0 -21
  229. package/src/prompt/function-defs/get-source-code.js +0 -21
  230. package/src/prompt/function-defs/imgly-remove-background.js +0 -25
  231. package/src/prompt/function-defs/move-file.js +0 -25
  232. package/src/prompt/function-defs/patch-file.js +0 -39
  233. package/src/prompt/function-defs/resize-image.js +0 -36
  234. package/src/prompt/function-defs/split-image.js +0 -45
  235. package/src/prompt/function-defs/update-file.js +0 -26
  236. package/src/prompt/limits.js +0 -23
  237. package/src/prompt/limits.test.js +0 -40
  238. package/src/prompt/prompt-codegen.js +0 -106
  239. package/src/prompt/prompt-codegen.test.js +0 -116
  240. package/src/prompt/prompt-service-ask-question.test.js +0 -163
  241. package/src/prompt/prompt-service.js +0 -335
  242. package/src/prompt/prompt-service.test.js +0 -602
  243. package/src/prompt/systemprompt.js +0 -39
  244. package/src/prompt/systemprompt.test.js +0 -64
@@ -1,335 +0,0 @@
1
- /*eslint-disable no-import-assign*/
2
-
3
- import { describe, it, expect, beforeEach, vi } from 'vitest';
4
- import { runCodegen } from './codegen.js';
5
- import * as vertexAi from '../ai-service/vertex-ai.js';
6
- import * as chatGpt from '../ai-service/chat-gpt.js';
7
- import * as anthropic from '../ai-service/anthropic.js';
8
- import * as vertexAiClaude from '../ai-service/vertex-ai-claude.js';
9
- import * as updateFiles from '../files/update-files.js';
10
- import '../files/find-files.js';
11
- import * as cliParams from '../cli/cli-params.js';
12
- import * as cliOptions from '../cli/cli-options.js';
13
- import * as vertexAiImagen from '../ai-service/vertex-ai-imagen.js';
14
- import * as dallE from '../ai-service/dall-e.js';
15
- import './config.js';
16
-
17
- vi.mock('../ai-service/vertex-ai.js', () => ({ generateContent: vi.fn() }));
18
- vi.mock('../ai-service/chat-gpt.js', () => ({ generateContent: vi.fn() }));
19
- vi.mock('../ai-service/anthropic.js', () => ({ generateContent: vi.fn() }));
20
- vi.mock('../ai-service/vertex-ai-claude.js', () => ({ generateContent: vi.fn() }));
21
- vi.mock('../files/update-files.js');
22
- vi.mock('../cli/cli-params.js', () => ({
23
- requireExplanations: false,
24
- considerAllFiles: false,
25
- dependencyTree: false,
26
- explicitPrompt: false,
27
- allowFileCreate: false,
28
- allowFileDelete: false,
29
- allowDirectoryCreate: false,
30
- allowFileMove: false,
31
- verbosePrompt: false,
32
- vertexAiClaude: false,
33
- helpRequested: false,
34
- vision: false,
35
- imagen: false,
36
- temperature: 0.7,
37
- cheap: false,
38
- taskFile: undefined,
39
- disableInitialLint: undefined,
40
- askQuestion: undefined,
41
- }));
42
- vi.mock('../files/find-files.js', () => ({
43
- getSourceFiles: () => [],
44
- getImageAssetFiles: () => [],
45
- }));
46
- vi.mock('../cli/cli-options.js', () => ({
47
- printHelpMessage: vi.fn(),
48
- }));
49
- vi.mock('../ai-service/vertex-ai-imagen.js', () => ({ generateImage: vi.fn() }));
50
- vi.mock('../ai-service/dall-e.js', () => ({ generateImage: vi.fn() }));
51
- vi.mock('./config.js', () => ({
52
- rootDir: '/mocked/root/dir',
53
- rcConfig: {
54
- rootDir: '.',
55
- extensions: ['.js', '.ts', '.tsx', '.jsx'],
56
- },
57
- }));
58
-
59
- describe('runCodegen', () => {
60
- beforeEach(() => {
61
- vi.resetAllMocks();
62
- cliParams.anthropic = false;
63
- cliParams.chatGpt = false;
64
- cliParams.vertexAi = false;
65
- cliParams.vertexAiClaude = false;
66
- cliParams.dryRun = false;
67
- cliParams.helpRequested = false;
68
- cliParams.vision = false;
69
- cliParams.imagen = false;
70
- });
71
-
72
- it('should run codegen with Vertex AI by default', async () => {
73
- cliParams.vertexAi = true;
74
-
75
- const mockFunctionCalls = [
76
- { name: 'updateFile', args: { filePath: 'test.js', newContent: 'console.log("Hello");' } },
77
- ];
78
- vertexAi.generateContent.mockResolvedValueOnce(mockFunctionCalls);
79
-
80
- await runCodegen();
81
-
82
- expect(vertexAi.generateContent).toHaveBeenCalled();
83
- expect(updateFiles.updateFiles).toHaveBeenCalledWith(mockFunctionCalls);
84
- });
85
-
86
- it('should run codegen with ChatGPT when chatGpt flag is true', async () => {
87
- cliParams.chatGpt = true;
88
-
89
- const mockFunctionCalls = [{ name: 'createFile', args: { filePath: 'new.js', newContent: 'const x = 5;' } }];
90
- chatGpt.generateContent.mockResolvedValueOnce(mockFunctionCalls);
91
-
92
- await runCodegen();
93
-
94
- expect(chatGpt.generateContent).toHaveBeenCalled();
95
- expect(updateFiles.updateFiles).toHaveBeenCalledWith(mockFunctionCalls);
96
- });
97
-
98
- it('should run codegen with Anthropic when anthropic flag is true', async () => {
99
- cliParams.anthropic = true;
100
-
101
- const mockFunctionCalls = [{ name: 'deleteFile', args: { filePath: 'obsolete.js' } }];
102
- anthropic.generateContent.mockResolvedValueOnce(mockFunctionCalls);
103
-
104
- await runCodegen();
105
-
106
- expect(anthropic.generateContent).toHaveBeenCalled();
107
- expect(updateFiles.updateFiles).toHaveBeenCalledWith(mockFunctionCalls);
108
- });
109
-
110
- it('should not update files in dry run mode', async () => {
111
- cliParams.vertexAi = true;
112
- cliParams.dryRun = true;
113
-
114
- const mockFunctionCalls = [
115
- { name: 'updateFile', args: { filePath: 'test.js', newContent: 'console.log("Dry run");' } },
116
- ];
117
- vertexAi.generateContent.mockResolvedValueOnce(mockFunctionCalls);
118
-
119
- await runCodegen();
120
-
121
- expect(vertexAi.generateContent).toHaveBeenCalled();
122
- expect(updateFiles.updateFiles).not.toHaveBeenCalled();
123
- });
124
-
125
- it('should run codegen with Vertex AI Claude when vertexAiClaude flag is true', async () => {
126
- cliParams.vertexAiClaude = true;
127
-
128
- const mockFunctionCalls = [
129
- { name: 'updateFile', args: { filePath: 'test.js', newContent: 'console.log("Hello from Claude");' } },
130
- ];
131
- vertexAiClaude.generateContent.mockResolvedValueOnce(mockFunctionCalls);
132
-
133
- await runCodegen();
134
-
135
- expect(vertexAiClaude.generateContent).toHaveBeenCalled();
136
- expect(updateFiles.updateFiles).toHaveBeenCalledWith(mockFunctionCalls);
137
- });
138
-
139
- it('should pass the temperature parameter to the AI service', async () => {
140
- cliParams.vertexAi = true;
141
- cliParams.temperature = 0.5;
142
-
143
- const mockFunctionCalls = [
144
- { name: 'updateFile', args: { filePath: 'test.js', newContent: 'console.log("Temperature test");' } },
145
- ];
146
- vertexAi.generateContent.mockResolvedValueOnce(mockFunctionCalls);
147
-
148
- await runCodegen();
149
-
150
- expect(vertexAi.generateContent).toHaveBeenCalledWith(
151
- expect.anything(),
152
- expect.anything(),
153
- expect.anything(),
154
- 0.5,
155
- false,
156
- );
157
- expect(updateFiles.updateFiles).toHaveBeenCalledWith(mockFunctionCalls);
158
- });
159
-
160
- it('should print help message and not run codegen when --help option is provided', async () => {
161
- cliParams.helpRequested = true;
162
-
163
- await runCodegen();
164
-
165
- expect(cliOptions.printHelpMessage).toHaveBeenCalled();
166
- expect(vertexAi.generateContent).not.toHaveBeenCalled();
167
- expect(chatGpt.generateContent).not.toHaveBeenCalled();
168
- expect(anthropic.generateContent).not.toHaveBeenCalled();
169
- expect(vertexAiClaude.generateContent).not.toHaveBeenCalled();
170
- expect(updateFiles.updateFiles).not.toHaveBeenCalled();
171
- });
172
-
173
- it('should run codegen with vision when vision flag is true', async () => {
174
- cliParams.chatGpt = true;
175
- cliParams.vision = true;
176
-
177
- const mockFunctionCalls = [
178
- { name: 'updateFile', args: { filePath: 'test.js', newContent: 'console.log("Vision test");' } },
179
- ];
180
- chatGpt.generateContent.mockResolvedValueOnce(mockFunctionCalls);
181
-
182
- await runCodegen();
183
-
184
- expect(chatGpt.generateContent).toHaveBeenCalled();
185
- expect(updateFiles.updateFiles).toHaveBeenCalledWith(mockFunctionCalls);
186
- // Check if the generateContent function was called with the correct parameters
187
- expect(chatGpt.generateContent.mock.calls[0][0]).toEqual(
188
- expect.arrayContaining([
189
- expect.objectContaining({
190
- type: 'user',
191
- text: expect.stringContaining('I should also provide you with a summary of application image assets'),
192
- }),
193
- expect.objectContaining({
194
- type: 'assistant',
195
- text: expect.stringContaining('Please provide summary of application image assets.'),
196
- }),
197
- expect.objectContaining({
198
- type: 'user',
199
- functionResponses: [{ name: 'getImageAssets', content: expect.any(String) }],
200
- }),
201
- ]),
202
- );
203
- });
204
-
205
- it('should use Vertex AI Imagen when imagen flag is set to vertex-ai', async () => {
206
- cliParams.imagen = 'vertex-ai';
207
- cliParams.vertexAi = true;
208
-
209
- const mockCodegenSummary = [
210
- {
211
- name: 'codegenSummary',
212
- args: {
213
- fileUpdates: [{ path: 'test.js', updateToolName: 'updateFile' }],
214
- contextPaths: [],
215
- explanation: 'Mock summary with image generation failure',
216
- },
217
- },
218
- ];
219
- const mockFunctionCalls = [
220
- { name: 'generateImage', args: { prompt: 'A beautiful landscape', filePath: 'landscape.png', size: '512x512' } },
221
- ];
222
- vertexAi.generateContent.mockResolvedValueOnce(mockCodegenSummary);
223
- vertexAi.generateContent.mockResolvedValueOnce(mockFunctionCalls);
224
- vertexAiImagen.generateImage.mockResolvedValueOnce('mocked-image-data');
225
-
226
- await runCodegen();
227
-
228
- expect(vertexAi.generateContent).toHaveBeenCalled();
229
- expect(vertexAiImagen.generateImage).toHaveBeenCalledWith('A beautiful landscape', undefined, '512x512', false);
230
- expect(updateFiles.updateFiles).toHaveBeenCalledWith(mockFunctionCalls);
231
- });
232
-
233
- it('should use DALL-E when imagen flag is set to dall-e', async () => {
234
- cliParams.imagen = 'dall-e';
235
- cliParams.chatGpt = true;
236
-
237
- const mockCodegenSummary = [
238
- {
239
- name: 'codegenSummary',
240
- args: {
241
- fileUpdates: [{ path: 'test.js', updateToolName: 'updateFile' }],
242
- contextPaths: [],
243
- explanation: 'Mock summary with image generation failure',
244
- },
245
- },
246
- ];
247
- const mockFunctionCalls = [
248
- { name: 'generateImage', args: { prompt: 'A futuristic city', filePath: 'city.png', size: '1024x1024' } },
249
- ];
250
- chatGpt.generateContent.mockResolvedValueOnce(mockCodegenSummary);
251
- chatGpt.generateContent.mockResolvedValueOnce(mockFunctionCalls);
252
- dallE.generateImage.mockResolvedValueOnce('mocked-image-data');
253
-
254
- await runCodegen();
255
-
256
- expect(chatGpt.generateContent).toHaveBeenCalled();
257
- expect(dallE.generateImage).toHaveBeenCalledWith('A futuristic city', undefined, '1024x1024', false);
258
- expect(updateFiles.updateFiles).toHaveBeenCalledWith(mockFunctionCalls);
259
- });
260
-
261
- it('should throw an error when imagen flag is set but no AI service is specified', async () => {
262
- cliParams.imagen = 'vertex-ai';
263
-
264
- await expect(runCodegen()).rejects.toThrow('Please specify which AI service should be used');
265
- });
266
-
267
- it('should pass the cheap parameter to the AI service when --cheap flag is true', async () => {
268
- cliParams.vertexAi = true;
269
- cliParams.cheap = true;
270
-
271
- const mockFunctionCalls = [
272
- { name: 'updateFile', args: { filePath: 'test.js', newContent: 'console.log("Cheap test");' } },
273
- ];
274
- vertexAi.generateContent.mockResolvedValueOnce(mockFunctionCalls);
275
-
276
- await runCodegen();
277
-
278
- expect(vertexAi.generateContent).toHaveBeenCalledWith(
279
- expect.anything(),
280
- expect.anything(),
281
- expect.anything(),
282
- expect.anything(),
283
- true,
284
- );
285
- expect(updateFiles.updateFiles).toHaveBeenCalledWith(mockFunctionCalls);
286
- });
287
-
288
- it('should pass the cheap parameter to the image generation service when --cheap flag is true', async () => {
289
- cliParams.imagen = 'vertex-ai';
290
- cliParams.vertexAi = true;
291
- cliParams.cheap = true;
292
-
293
- const mockCodegenSummary = [
294
- {
295
- name: 'codegenSummary',
296
- args: {
297
- fileUpdates: [{ path: 'test.js', updateToolName: 'updateFile' }],
298
- contextPaths: [],
299
- explanation: 'Mock summary with cheap image generation',
300
- },
301
- },
302
- ];
303
- const mockFunctionCalls = [
304
- {
305
- name: 'generateImage',
306
- args: {
307
- prompt: 'A simple landscape',
308
- filePath: 'landscape.png',
309
- size: { width: 256, height: 256 },
310
- cheap: true,
311
- },
312
- },
313
- ];
314
- vertexAi.generateContent.mockResolvedValueOnce(mockCodegenSummary);
315
- vertexAi.generateContent.mockResolvedValueOnce(mockFunctionCalls);
316
- vertexAiImagen.generateImage.mockResolvedValueOnce('mocked-cheap-image-data');
317
-
318
- await runCodegen();
319
-
320
- expect(vertexAi.generateContent).toHaveBeenCalledWith(
321
- expect.anything(),
322
- expect.anything(),
323
- expect.anything(),
324
- expect.anything(),
325
- true,
326
- );
327
- expect(vertexAiImagen.generateImage).toHaveBeenCalledWith(
328
- 'A simple landscape',
329
- undefined,
330
- { width: 256, height: 256 },
331
- true,
332
- );
333
- expect(updateFiles.updateFiles).toHaveBeenCalledWith(mockFunctionCalls);
334
- });
335
- });
@@ -1,33 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import assert from 'node:assert';
4
-
5
- import { isAncestorDirectory } from '../files/file-utils.js';
6
-
7
- // This file contains project codegen configuration
8
- const CODEGENRC_FILENAME = '.genaicoderc';
9
-
10
- // Find .genaicoderc file
11
- export function findRcFile() {
12
- let rcFilePath = process.cwd();
13
- while (!fs.existsSync(path.join(rcFilePath, CODEGENRC_FILENAME))) {
14
- const parentDir = path.dirname(rcFilePath);
15
- if (parentDir === rcFilePath) {
16
- throw new Error(`${CODEGENRC_FILENAME} not found in any parent directory`);
17
- }
18
- rcFilePath = parentDir;
19
- }
20
- return path.join(rcFilePath, CODEGENRC_FILENAME);
21
- }
22
-
23
- // Read and parse .genaicoderc file
24
- export function parseRcFile(rcFilePath) {
25
- assert(fs.existsSync(rcFilePath), `${CODEGENRC_FILENAME} not found`);
26
- const rcConfig = JSON.parse(fs.readFileSync(rcFilePath, 'utf-8'));
27
- assert(rcConfig.rootDir, 'Root dir not configured');
28
-
29
- const rootDir = path.resolve(path.dirname(rcFilePath), rcConfig.rootDir);
30
- assert(isAncestorDirectory(path.dirname(rcFilePath), rootDir), 'Root dir is not located inside project directory');
31
-
32
- return { ...rcConfig, rootDir };
33
- }
@@ -1,80 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import fs from 'fs';
3
- import path from 'path';
4
- import { isAncestorDirectory } from '../files/file-utils.js';
5
- import { findRcFile, parseRcFile } from './config-lib';
6
-
7
- vi.mock('fs');
8
- vi.mock('path');
9
- vi.mock('../files/file-utils.js');
10
-
11
- const CODEGENRC_FILENAME = '.genaicoderc';
12
-
13
- // Mock data
14
- const mockRcContent = JSON.stringify({ rootDir: 'src' });
15
- const mockRootDir = '/project/src';
16
- const mockRcFilePath = `/project/${CODEGENRC_FILENAME}`;
17
-
18
- // Helper function to mock fs.existsSync
19
- function mockExistsSync(paths) {
20
- return (p) => paths.includes(p);
21
- }
22
-
23
- // Tests
24
-
25
- // Test for findRcFile
26
- describe('findRcFile', () => {
27
- it('should find .genaicoderc in the current or parent directories', () => {
28
- fs.existsSync.mockImplementation(mockExistsSync([mockRcFilePath]));
29
- path.dirname.mockImplementation((p) => (p === '/project' ? '/' : '/project'));
30
- path.join.mockImplementation((...args) => args.join('/'));
31
-
32
- const result = findRcFile();
33
- expect(result).toBe(mockRcFilePath);
34
- });
35
-
36
- it('should throw an error if .genaicoderc is not found', () => {
37
- fs.existsSync.mockReturnValue(false);
38
- path.dirname.mockImplementation((p) => (p === '/' ? '/' : '/project'));
39
-
40
- expect(() => findRcFile()).toThrowError(`${CODEGENRC_FILENAME} not found in any parent directory`);
41
- });
42
- });
43
-
44
- // Test for parseRcFile
45
- describe('parseRcFile', () => {
46
- it('should parse .genaicoderc and return config with rootDir', () => {
47
- fs.existsSync.mockReturnValue(true);
48
- fs.readFileSync.mockReturnValue(mockRcContent);
49
- path.resolve.mockImplementation((...args) => args.join('/'));
50
- path.dirname.mockReturnValue('/project');
51
- isAncestorDirectory.mockReturnValue(true);
52
-
53
- const result = parseRcFile(mockRcFilePath);
54
- expect(result).toEqual({ ...JSON.parse(mockRcContent), rootDir: mockRootDir });
55
- });
56
-
57
- it('should throw an error if .genaicoderc is missing', () => {
58
- fs.existsSync.mockReturnValue(false);
59
-
60
- expect(() => parseRcFile(mockRcFilePath)).toThrowError(`${CODEGENRC_FILENAME} not found`);
61
- });
62
-
63
- it('should throw an error if rootDir is not configured', () => {
64
- const invalidContent = JSON.stringify({});
65
- fs.existsSync.mockReturnValue(true);
66
- fs.readFileSync.mockReturnValue(invalidContent);
67
-
68
- expect(() => parseRcFile(mockRcFilePath)).toThrowError('Root dir not configured');
69
- });
70
-
71
- it('should throw an error if rootDir is not located inside project directory', () => {
72
- fs.existsSync.mockReturnValue(true);
73
- fs.readFileSync.mockReturnValue(mockRcContent);
74
- path.resolve.mockImplementation((...args) => args.join('/'));
75
- path.dirname.mockReturnValue('/project');
76
- isAncestorDirectory.mockReturnValue(false);
77
-
78
- expect(() => parseRcFile(mockRcFilePath)).toThrowError('Root dir is not located inside project directory');
79
- });
80
- });
@@ -1,25 +0,0 @@
1
- import { Validator } from 'jsonschema';
2
- import { functionDefs } from './function-calling.js';
3
-
4
- export function validateFunctionCall(call) {
5
- const validator = new Validator();
6
- const functionDef = functionDefs.find((def) => def.name === call.name);
7
-
8
- if (!functionDef) {
9
- return {
10
- errors: [
11
- {
12
- message: `Function "${call.name}" is not defined.`,
13
- },
14
- ],
15
- };
16
- }
17
-
18
- const validationResult = validator.validate(call.args, functionDef.parameters);
19
-
20
- if (validationResult.errors.length > 0) {
21
- return validationResult;
22
- }
23
-
24
- return undefined;
25
- }
@@ -1,33 +0,0 @@
1
- /**
2
- * Function definition for askQuestion
3
- */
4
- export const askQuestion = {
5
- name: 'askQuestion',
6
- description:
7
- 'If there is a need ask a question to the user to gather more information or clarification. Alternatively this function can be called also if there is no need to prompt the user with any question.',
8
- parameters: {
9
- type: 'object',
10
- properties: {
11
- content: {
12
- type: 'string',
13
- description:
14
- 'The message you want to display to the user, it can be either a question or a confirmation/ackoweledgment in case there is no intention to prompt the user.',
15
- },
16
- shouldPrompt: {
17
- type: 'boolean',
18
- description: 'Set to true if the intention is to get response from the user.',
19
- },
20
- promptNecessity: {
21
- type: 'number',
22
- minimum: 0,
23
- maximum: 100,
24
- description: 'How strong is the need to prompt the user? Higher value indicates a stronger need.',
25
- },
26
- stopCodegen: {
27
- type: 'boolean',
28
- description: 'If set to true, it will break the code generation process without error.',
29
- },
30
- },
31
- required: ['content', 'shouldPrompt', 'promptNecessity', 'stopCodegen'],
32
- },
33
- };
@@ -1,87 +0,0 @@
1
- import { temperature, cheap, vision } from '../../cli/cli-params.js';
2
-
3
- /**
4
- * Function definition for codegenSummary
5
- */
6
- export const codegenSummary = {
7
- name: 'codegenSummary',
8
- description:
9
- 'This function is called with a summary of proposed updates.' +
10
- 'Summary is a data structure(object) which contains:\n' +
11
- '- `fileUpdates`: list of proposed file updates that will be subject to subsequent code generation request\n' +
12
- '- `contextPaths`: list of file paths that make sense to use as a context for code generation requests.' +
13
- '- `explanation`: general explanation of planned code generation updates\n' +
14
- 'It is crticially important to adhere to the schema of parameters',
15
- parameters: {
16
- type: 'object',
17
- properties: {
18
- contextPaths: {
19
- type: 'array',
20
- description:
21
- 'An array of absolute paths of files that should be used to provide context for the following updates. Context files could be for example the dependencies, or files that depend on one of the files that we want to update in the next step.',
22
- items: {
23
- type: 'string',
24
- },
25
- },
26
- fileUpdates: {
27
- type: 'array',
28
- description: 'An array of proposed file updates, each update is an object with several properties.',
29
- items: {
30
- type: 'object',
31
- description:
32
- 'Proposed update of a file. The update is an object which contains properties like file path, update tool name, and few other important properties.',
33
- properties: {
34
- path: { type: 'string', description: 'An absolute path of the project file that will be updated' },
35
- updateToolName: {
36
- type: 'string',
37
- enum: [
38
- 'createFile',
39
- 'updateFile',
40
- 'patchFile',
41
- 'deleteFile',
42
- 'createDirectory',
43
- 'moveFile',
44
- 'generateImage',
45
- 'downloadFile',
46
- 'splitImage',
47
- 'resizeImage',
48
- 'imglyRemoveBackground',
49
- ],
50
- description: 'A name of the tool that will be used to perform the update.',
51
- },
52
- temperature: {
53
- type: 'number',
54
- description:
55
- 'Temperature parameter that will be used for LLM request. The value is adjusted to the characteristic of the update. If there is a need for a more creative solution, the value should be lower, but stil within [0.0, 2.0] range. The default value is: ' +
56
- temperature,
57
- },
58
- cheap: {
59
- type: 'boolean',
60
- description:
61
- 'true value means that the prompt will be executed with cheaper model, which work faster, but provides lower quality results, so please use it only in situation when lower quality results are acceptable for the prompt. The default value is: ' +
62
- !!cheap,
63
- },
64
- prompt: {
65
- type: 'string',
66
- description:
67
- 'Prompt that will be passed to the model request together with the tool request. It summarizes the planned changes for this particular file, so it should be detailed enough for the model to generate necessary changes.',
68
- },
69
- contextImageAssets: {
70
- type: 'array',
71
- description:
72
- 'A list of of absolute image asset paths that should be included to the context of LLM request.' +
73
- 'This parameter must be used if there is a need to analyze an image.',
74
- items: { type: 'string' },
75
- },
76
- },
77
- required: ['path', 'updateToolName', ...(vision ? ['contextImageAssets'] : [])],
78
- },
79
- },
80
- explanation: {
81
- type: 'string',
82
- description: 'Explanation of planned changes or explanation of reasoning for no code changes',
83
- },
84
- },
85
- required: ['fileUpdates', 'contextPaths'],
86
- },
87
- };
@@ -1,21 +0,0 @@
1
- /**
2
- * Function definition for createDirectory
3
- */
4
- export const createDirectory = {
5
- name: 'createDirectory',
6
- description: 'Create a new directory',
7
- parameters: {
8
- type: 'object',
9
- properties: {
10
- filePath: {
11
- type: 'string',
12
- description: 'The directory path to create.',
13
- },
14
- explanation: {
15
- type: 'string',
16
- description: 'The explanation of the reasoning behind creating this directory',
17
- },
18
- },
19
- required: ['filePath'],
20
- },
21
- };
@@ -1,26 +0,0 @@
1
- /**
2
- * Function definition for createFile
3
- */
4
- export const createFile = {
5
- name: 'createFile',
6
- description:
7
- 'Create a new file with specified content. The file will be created inside of project folder structure. This tool should not be used of creation if image files.',
8
- parameters: {
9
- type: 'object',
10
- properties: {
11
- filePath: {
12
- type: 'string',
13
- description: 'Path of the file that will be created, it must not be empty.',
14
- },
15
- newContent: {
16
- type: 'string',
17
- description: 'Content of the file that will be created, it must no be empty.',
18
- },
19
- explanation: {
20
- type: 'string',
21
- description: 'The explanation of the reasoning behind creating this file',
22
- },
23
- },
24
- required: ['filePath', 'newContent'],
25
- },
26
- };
@@ -1,21 +0,0 @@
1
- /**
2
- * Function definition for deleteFile
3
- */
4
- export const deleteFile = {
5
- name: 'deleteFile',
6
- description: 'Delete a specified file from the application source code.',
7
- parameters: {
8
- type: 'object',
9
- properties: {
10
- filePath: {
11
- type: 'string',
12
- description: 'The file path to delete.',
13
- },
14
- explanation: {
15
- type: 'string',
16
- description: 'The explanation of the reasoning behind deleting this file',
17
- },
18
- },
19
- required: ['filePath'],
20
- },
21
- };