genaicode 0.0.37 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/bin/genaicode-dev.js +11 -0
- package/bin/genaicode.cjs +15 -1
- package/dist/ai-service/ai-studio.d.ts +6 -0
- package/dist/ai-service/ai-studio.js +135 -0
- package/dist/ai-service/ai-studio.js.map +1 -0
- package/dist/ai-service/anthropic.d.ts +6 -0
- package/dist/ai-service/anthropic.js +135 -0
- package/dist/ai-service/anthropic.js.map +1 -0
- package/dist/ai-service/chat-gpt.d.ts +5 -0
- package/dist/ai-service/chat-gpt.js +132 -0
- package/dist/ai-service/chat-gpt.js.map +1 -0
- package/dist/ai-service/common.d.ts +58 -0
- package/dist/ai-service/common.js +38 -0
- package/dist/ai-service/common.js.map +1 -0
- package/dist/ai-service/common.test.d.ts +1 -0
- package/dist/ai-service/common.test.js +85 -0
- package/dist/ai-service/common.test.js.map +1 -0
- package/dist/ai-service/dall-e.d.ts +14 -0
- package/dist/ai-service/dall-e.js +48 -0
- package/dist/ai-service/dall-e.js.map +1 -0
- package/dist/ai-service/vertex-ai-claude.d.ts +5 -0
- package/dist/ai-service/vertex-ai-claude.js +94 -0
- package/dist/ai-service/vertex-ai-claude.js.map +1 -0
- package/dist/ai-service/vertex-ai-imagen.d.ts +14 -0
- package/dist/ai-service/vertex-ai-imagen.js +77 -0
- package/dist/ai-service/vertex-ai-imagen.js.map +1 -0
- package/dist/ai-service/vertex-ai.d.ts +7 -0
- package/dist/ai-service/vertex-ai.js +142 -0
- package/dist/ai-service/vertex-ai.js.map +1 -0
- package/dist/cli/cli-options.d.ts +10 -0
- package/dist/cli/cli-options.js +124 -0
- package/dist/cli/cli-options.js.map +1 -0
- package/dist/cli/cli-options.test.d.ts +1 -0
- package/dist/cli/cli-options.test.js +34 -0
- package/dist/cli/cli-options.test.js.map +1 -0
- package/dist/cli/cli-params.d.ts +30 -0
- package/dist/cli/cli-params.js +109 -0
- package/dist/cli/cli-params.js.map +1 -0
- package/dist/cli/cli-params.test.d.ts +1 -0
- package/dist/cli/cli-params.test.js +38 -0
- package/dist/cli/cli-params.test.js.map +1 -0
- package/dist/cli/service-autodetect.d.ts +2 -0
- package/dist/cli/service-autodetect.js +17 -0
- package/dist/cli/service-autodetect.js.map +1 -0
- package/dist/cli/service-autodetect.test.d.ts +1 -0
- package/dist/cli/service-autodetect.test.js +38 -0
- package/dist/cli/service-autodetect.test.js.map +1 -0
- package/dist/cli/validate-cli-params.d.ts +18 -0
- package/dist/cli/validate-cli-params.js +129 -0
- package/dist/cli/validate-cli-params.js.map +1 -0
- package/dist/cli/validate-cli-params.test.d.ts +1 -0
- package/dist/cli/validate-cli-params.test.js +106 -0
- package/dist/cli/validate-cli-params.test.js.map +1 -0
- package/dist/files/file-utils.d.ts +2 -0
- package/dist/files/file-utils.js +7 -0
- package/dist/files/file-utils.js.map +1 -0
- package/dist/files/file-utils.test.d.ts +1 -0
- package/dist/files/file-utils.test.js +18 -0
- package/dist/files/file-utils.test.js.map +1 -0
- package/dist/files/find-files.d.ts +8 -0
- package/dist/files/find-files.js +76 -0
- package/dist/files/find-files.js.map +1 -0
- package/dist/files/read-files.d.ts +18 -0
- package/dist/files/read-files.js +66 -0
- package/dist/files/read-files.js.map +1 -0
- package/dist/files/read-files.test.d.ts +1 -0
- package/dist/files/read-files.test.js +88 -0
- package/dist/files/read-files.test.js.map +1 -0
- package/dist/files/temp-buffer.d.ts +2 -0
- package/dist/files/temp-buffer.js +12 -0
- package/dist/files/temp-buffer.js.map +1 -0
- package/dist/files/update-files.d.ts +6 -0
- package/dist/files/update-files.js +197 -0
- package/dist/files/update-files.js.map +1 -0
- package/dist/images/ensure-alpha.d.ts +1 -0
- package/dist/images/ensure-alpha.js +5 -0
- package/dist/images/ensure-alpha.js.map +1 -0
- package/dist/images/imgly-remove-background.d.ts +2 -0
- package/dist/images/imgly-remove-background.js +21 -0
- package/dist/images/imgly-remove-background.js.map +1 -0
- package/dist/images/resize-image.d.ts +19 -0
- package/dist/images/resize-image.js +22 -0
- package/dist/images/resize-image.js.map +1 -0
- package/dist/images/split-image.d.ts +18 -0
- package/dist/images/split-image.js +25 -0
- package/dist/images/split-image.js.map +1 -0
- package/dist/main/codegen-interactive-utils.d.ts +8 -0
- package/dist/main/codegen-interactive-utils.js +148 -0
- package/dist/main/codegen-interactive-utils.js.map +1 -0
- package/dist/main/codegen-interactive.d.ts +2 -0
- package/dist/main/codegen-interactive.js +68 -0
- package/dist/main/codegen-interactive.js.map +1 -0
- package/dist/main/codegen-types.d.ts +28 -0
- package/dist/main/codegen-types.js +2 -0
- package/dist/main/codegen-types.js.map +1 -0
- package/dist/main/codegen.d.ts +4 -0
- package/dist/main/codegen.js +164 -0
- package/dist/main/codegen.js.map +1 -0
- package/dist/main/codegen.test.d.ts +2 -0
- package/dist/main/codegen.test.js +273 -0
- package/dist/main/codegen.test.js.map +1 -0
- package/dist/main/config-lib.d.ts +16 -0
- package/dist/main/config-lib.js +28 -0
- package/dist/main/config-lib.js.map +1 -0
- package/dist/main/config-lib.test.d.ts +1 -0
- package/dist/main/config-lib.test.js +64 -0
- package/dist/main/config-lib.test.js.map +1 -0
- package/dist/main/config.d.ts +6 -0
- package/{src → dist}/main/config.js +28 -22
- package/dist/main/config.js.map +1 -0
- package/dist/main/interactive/codegen-interactive.d.ts +2 -0
- package/dist/main/interactive/codegen-interactive.js +55 -0
- package/dist/main/interactive/codegen-interactive.js.map +1 -0
- package/dist/main/interactive/codegen-interactive.test.d.ts +4 -0
- package/dist/main/interactive/codegen-interactive.test.js +77 -0
- package/dist/main/interactive/codegen-interactive.test.js.map +1 -0
- package/dist/main/interactive/codegen-worker.d.ts +3 -0
- package/dist/main/interactive/codegen-worker.js +47 -0
- package/dist/main/interactive/codegen-worker.js.map +1 -0
- package/dist/main/interactive/common.d.ts +5 -0
- package/dist/main/interactive/common.js +51 -0
- package/dist/main/interactive/common.js.map +1 -0
- package/dist/main/interactive/configure.d.ts +2 -0
- package/dist/main/interactive/configure.js +99 -0
- package/dist/main/interactive/configure.js.map +1 -0
- package/dist/main/interactive/error-handling.d.ts +4 -0
- package/dist/main/interactive/error-handling.js +49 -0
- package/dist/main/interactive/error-handling.js.map +1 -0
- package/dist/main/interactive/help.d.ts +1 -0
- package/dist/main/interactive/help.js +22 -0
- package/dist/main/interactive/help.js.map +1 -0
- package/dist/main/interactive/process-comments.d.ts +2 -0
- package/dist/main/interactive/process-comments.js +39 -0
- package/dist/main/interactive/process-comments.js.map +1 -0
- package/dist/main/interactive/select-ai-service.d.ts +2 -0
- package/dist/main/interactive/select-ai-service.js +27 -0
- package/dist/main/interactive/select-ai-service.js.map +1 -0
- package/dist/main/interactive/task-file.d.ts +2 -0
- package/dist/main/interactive/task-file.js +28 -0
- package/dist/main/interactive/task-file.js.map +1 -0
- package/dist/main/interactive/text-prompt.d.ts +2 -0
- package/dist/main/interactive/text-prompt.js +18 -0
- package/dist/main/interactive/text-prompt.js.map +1 -0
- package/dist/main/interactive/user-interrupt.d.ts +1 -0
- package/dist/main/interactive/user-interrupt.js +36 -0
- package/dist/main/interactive/user-interrupt.js.map +1 -0
- package/dist/main/interactive/worker-script.d.ts +1 -0
- package/dist/main/interactive/worker-script.js +24 -0
- package/dist/main/interactive/worker-script.js.map +1 -0
- package/dist/main/interactive/worker.d.ts +2 -0
- package/dist/main/interactive/worker.js +55 -0
- package/dist/main/interactive/worker.js.map +1 -0
- package/dist/prompt/function-calling-validate.d.ts +3 -0
- package/dist/prompt/function-calling-validate.js +33 -0
- package/dist/prompt/function-calling-validate.js.map +1 -0
- package/dist/prompt/function-calling.d.ts +5 -0
- package/{src → dist}/prompt/function-calling.js +25 -24
- package/dist/prompt/function-calling.js.map +1 -0
- package/dist/prompt/function-defs/ask-question.d.ts +65 -0
- package/dist/prompt/function-defs/ask-question.js +67 -0
- package/dist/prompt/function-defs/ask-question.js.map +1 -0
- package/dist/prompt/function-defs/codegen-summary.d.ts +63 -0
- package/dist/prompt/function-defs/codegen-summary.js +80 -0
- package/dist/prompt/function-defs/codegen-summary.js.map +1 -0
- package/dist/prompt/function-defs/create-directory.d.ts +21 -0
- package/dist/prompt/function-defs/create-directory.js +22 -0
- package/dist/prompt/function-defs/create-directory.js.map +1 -0
- package/dist/prompt/function-defs/create-file.d.ts +25 -0
- package/dist/prompt/function-defs/create-file.js +26 -0
- package/dist/prompt/function-defs/create-file.js.map +1 -0
- package/dist/prompt/function-defs/delete-file.d.ts +21 -0
- package/dist/prompt/function-defs/delete-file.js +22 -0
- package/dist/prompt/function-defs/delete-file.js.map +1 -0
- package/dist/prompt/function-defs/download-file.d.ts +25 -0
- package/dist/prompt/function-defs/download-file.js +26 -0
- package/dist/prompt/function-defs/download-file.js.map +1 -0
- package/dist/prompt/function-defs/explanation.d.ts +17 -0
- package/dist/prompt/function-defs/explanation.js +18 -0
- package/dist/prompt/function-defs/explanation.js.map +1 -0
- package/dist/prompt/function-defs/generate-image.d.ts +41 -0
- package/dist/prompt/function-defs/generate-image.js +42 -0
- package/dist/prompt/function-defs/generate-image.js.map +1 -0
- package/dist/prompt/function-defs/get-image-assets.d.ts +20 -0
- package/dist/prompt/function-defs/get-image-assets.js +21 -0
- package/dist/prompt/function-defs/get-image-assets.js.map +1 -0
- package/dist/prompt/function-defs/get-source-code.d.ts +20 -0
- package/dist/prompt/function-defs/get-source-code.js +21 -0
- package/dist/prompt/function-defs/get-source-code.js.map +1 -0
- package/dist/prompt/function-defs/imgly-remove-background.d.ts +25 -0
- package/dist/prompt/function-defs/imgly-remove-background.js +26 -0
- package/dist/prompt/function-defs/imgly-remove-background.js.map +1 -0
- package/dist/prompt/function-defs/move-file.d.ts +25 -0
- package/dist/prompt/function-defs/move-file.js +26 -0
- package/dist/prompt/function-defs/move-file.js.map +1 -0
- package/dist/prompt/function-defs/patch-file.d.ts +25 -0
- package/dist/prompt/function-defs/patch-file.js +39 -0
- package/dist/prompt/function-defs/patch-file.js.map +1 -0
- package/dist/prompt/function-defs/resize-image.d.ts +36 -0
- package/dist/prompt/function-defs/resize-image.js +37 -0
- package/dist/prompt/function-defs/resize-image.js.map +1 -0
- package/dist/prompt/function-defs/split-image.d.ts +57 -0
- package/dist/prompt/function-defs/split-image.js +46 -0
- package/dist/prompt/function-defs/split-image.js.map +1 -0
- package/dist/prompt/function-defs/update-file.d.ts +25 -0
- package/dist/prompt/function-defs/update-file.js +26 -0
- package/dist/prompt/function-defs/update-file.js.map +1 -0
- package/dist/prompt/limits.d.ts +3 -0
- package/dist/prompt/limits.js +19 -0
- package/dist/prompt/limits.js.map +1 -0
- package/dist/prompt/limits.test.d.ts +1 -0
- package/dist/prompt/limits.test.js +35 -0
- package/dist/prompt/limits.test.js.map +1 -0
- package/dist/prompt/prompt-codegen.d.ts +9 -0
- package/dist/prompt/prompt-codegen.js +90 -0
- package/dist/prompt/prompt-codegen.js.map +1 -0
- package/dist/prompt/prompt-codegen.test.d.ts +1 -0
- package/dist/prompt/prompt-codegen.test.js +98 -0
- package/dist/prompt/prompt-codegen.test.js.map +1 -0
- package/dist/prompt/prompt-consts.d.ts +1 -0
- package/{src → dist}/prompt/prompt-consts.js +1 -0
- package/dist/prompt/prompt-consts.js.map +1 -0
- package/dist/prompt/prompt-service-ask-question.test.d.ts +3 -0
- package/dist/prompt/prompt-service-ask-question.test.js +142 -0
- package/dist/prompt/prompt-service-ask-question.test.js.map +1 -0
- package/dist/prompt/prompt-service.d.ts +28 -0
- package/dist/prompt/prompt-service.js +163 -0
- package/dist/prompt/prompt-service.js.map +1 -0
- package/dist/prompt/prompt-service.test.d.ts +1 -0
- package/dist/prompt/prompt-service.test.js +531 -0
- package/dist/prompt/prompt-service.test.js.map +1 -0
- package/dist/prompt/steps/step-ask-question.d.ts +6 -0
- package/dist/prompt/steps/step-ask-question.js +82 -0
- package/dist/prompt/steps/step-ask-question.js.map +1 -0
- package/dist/prompt/steps/step-generate-image.d.ts +2 -0
- package/dist/prompt/steps/step-generate-image.js +29 -0
- package/dist/prompt/steps/step-generate-image.js.map +1 -0
- package/dist/prompt/steps/step-validate-recover.d.ts +13 -0
- package/dist/prompt/steps/step-validate-recover.js +51 -0
- package/dist/prompt/steps/step-validate-recover.js.map +1 -0
- package/dist/prompt/steps/step-verify-patch.d.ts +7 -0
- package/dist/prompt/steps/step-verify-patch.js +41 -0
- package/dist/prompt/steps/step-verify-patch.js.map +1 -0
- package/dist/prompt/steps/steps-types.d.ts +4 -0
- package/dist/prompt/steps/steps-types.js +6 -0
- package/dist/prompt/steps/steps-types.js.map +1 -0
- package/dist/prompt/systemprompt.d.ts +3 -0
- package/dist/prompt/systemprompt.js +47 -0
- package/dist/prompt/systemprompt.js.map +1 -0
- package/dist/prompt/systemprompt.test.d.ts +3 -0
- package/dist/prompt/systemprompt.test.js +46 -0
- package/dist/prompt/systemprompt.test.js.map +1 -0
- package/package.json +15 -5
- package/bin/genaicode.js +0 -5
- package/bin/vertex-monkey-patch.cjs +0 -33
- package/src/ai-service/anthropic.js +0 -126
- package/src/ai-service/chat-gpt.js +0 -126
- package/src/ai-service/common.js +0 -49
- package/src/ai-service/common.test.js +0 -107
- package/src/ai-service/dall-e.js +0 -50
- package/src/ai-service/vertex-ai-claude.js +0 -99
- package/src/ai-service/vertex-ai-imagen.js +0 -78
- package/src/ai-service/vertex-ai.js +0 -156
- package/src/cli/cli-options.js +0 -132
- package/src/cli/cli-options.test.js +0 -50
- package/src/cli/cli-params.js +0 -114
- package/src/cli/cli-params.test.js +0 -43
- package/src/cli/service-autodetect.js +0 -11
- package/src/cli/service-autodetect.test.js +0 -43
- package/src/cli/validate-cli-params.js +0 -137
- package/src/cli/validate-cli-params.test.js +0 -134
- package/src/files/file-utils.js +0 -7
- package/src/files/file-utils.test.js +0 -21
- package/src/files/find-files.js +0 -86
- package/src/files/read-files.js +0 -65
- package/src/files/read-files.test.js +0 -103
- package/src/files/temp-buffer.js +0 -13
- package/src/files/update-files.js +0 -205
- package/src/images/ensure-alpha.js +0 -5
- package/src/images/imgly-remove-background.js +0 -23
- package/src/images/resize-image.js +0 -23
- package/src/images/split-image.js +0 -26
- package/src/main/codegen.js +0 -120
- package/src/main/codegen.test.js +0 -335
- package/src/main/config-lib.js +0 -33
- package/src/main/config-lib.test.js +0 -80
- package/src/prompt/function-calling-validate.js +0 -25
- package/src/prompt/function-defs/ask-question.js +0 -33
- package/src/prompt/function-defs/codegen-summary.js +0 -87
- package/src/prompt/function-defs/create-directory.js +0 -21
- package/src/prompt/function-defs/create-file.js +0 -26
- package/src/prompt/function-defs/delete-file.js +0 -21
- package/src/prompt/function-defs/download-file.js +0 -25
- package/src/prompt/function-defs/explanation.js +0 -17
- package/src/prompt/function-defs/generate-image.js +0 -51
- package/src/prompt/function-defs/get-image-assets.js +0 -21
- package/src/prompt/function-defs/get-source-code.js +0 -21
- package/src/prompt/function-defs/imgly-remove-background.js +0 -25
- package/src/prompt/function-defs/move-file.js +0 -25
- package/src/prompt/function-defs/patch-file.js +0 -39
- package/src/prompt/function-defs/resize-image.js +0 -36
- package/src/prompt/function-defs/split-image.js +0 -45
- package/src/prompt/function-defs/update-file.js +0 -26
- package/src/prompt/limits.js +0 -23
- package/src/prompt/limits.test.js +0 -40
- package/src/prompt/prompt-codegen.js +0 -106
- package/src/prompt/prompt-codegen.test.js +0 -116
- package/src/prompt/prompt-service-ask-question.test.js +0 -163
- package/src/prompt/prompt-service.js +0 -335
- package/src/prompt/prompt-service.test.js +0 -602
- package/src/prompt/systemprompt.js +0 -39
- package/src/prompt/systemprompt.test.js +0 -64
package/src/main/codegen.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
2
|
-
import { exec } from 'child_process';
|
|
3
|
-
import util from 'util';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
dryRun,
|
|
7
|
-
chatGpt,
|
|
8
|
-
anthropic,
|
|
9
|
-
vertexAi,
|
|
10
|
-
vertexAiClaude,
|
|
11
|
-
disableInitialLint,
|
|
12
|
-
helpRequested,
|
|
13
|
-
imagen,
|
|
14
|
-
} from '../cli/cli-params.js';
|
|
15
|
-
import { validateCliParams } from '../cli/validate-cli-params.js';
|
|
16
|
-
import { generateContent as generateContentVertexAi } from '../ai-service/vertex-ai.js';
|
|
17
|
-
import { generateContent as generateContentGPT } from '../ai-service/chat-gpt.js';
|
|
18
|
-
import { generateContent as generateContentAnthropic } from '../ai-service/anthropic.js';
|
|
19
|
-
import { generateContent as generateContentVertexAiClaude } from '../ai-service/vertex-ai-claude.js';
|
|
20
|
-
import { generateImage as generateImageDallE } from '../ai-service/dall-e.js';
|
|
21
|
-
import { generateImage as generateImageVertexAi } from '../ai-service/vertex-ai-imagen.js';
|
|
22
|
-
|
|
23
|
-
import { promptService } from '../prompt/prompt-service.js';
|
|
24
|
-
import { updateFiles } from '../files/update-files.js';
|
|
25
|
-
import { rcConfig } from '../main/config.js';
|
|
26
|
-
import { getLintFixPrompt } from '../prompt/prompt-codegen.js';
|
|
27
|
-
import { printHelpMessage } from '../cli/cli-options.js';
|
|
28
|
-
|
|
29
|
-
const execPromise = util.promisify(exec);
|
|
30
|
-
|
|
31
|
-
/** Executes codegen */
|
|
32
|
-
export async function runCodegen() {
|
|
33
|
-
// Print to console the received parameters
|
|
34
|
-
console.log(`Received parameters: ${process.argv.slice(2).join(' ')}`);
|
|
35
|
-
|
|
36
|
-
validateCliParams();
|
|
37
|
-
|
|
38
|
-
// Handle --help option
|
|
39
|
-
if (helpRequested) {
|
|
40
|
-
printHelpMessage();
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (rcConfig.lintCommand && !disableInitialLint) {
|
|
45
|
-
try {
|
|
46
|
-
console.log(`Executing lint command: ${rcConfig.lintCommand}`);
|
|
47
|
-
await execPromise(rcConfig.lintCommand);
|
|
48
|
-
console.log('Lint command executed successfully');
|
|
49
|
-
} catch (error) {
|
|
50
|
-
console.log(
|
|
51
|
-
'Lint command failed. Aborting codegen, please fix lint issues before running codegen, or use --disable-initial-lint',
|
|
52
|
-
);
|
|
53
|
-
console.log('Lint errors:', error.stdout, error.stderr);
|
|
54
|
-
process.exit(1);
|
|
55
|
-
}
|
|
56
|
-
} else if (rcConfig.lintCommand && disableInitialLint) {
|
|
57
|
-
console.log('Initial lint was skipped.');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const generateContent = vertexAiClaude
|
|
61
|
-
? generateContentVertexAiClaude
|
|
62
|
-
: vertexAi
|
|
63
|
-
? generateContentVertexAi
|
|
64
|
-
: anthropic
|
|
65
|
-
? generateContentAnthropic
|
|
66
|
-
: chatGpt
|
|
67
|
-
? generateContentGPT
|
|
68
|
-
: assert(false, 'Please specify which AI service should be used');
|
|
69
|
-
|
|
70
|
-
const generateImage =
|
|
71
|
-
imagen === 'vertex-ai' ? generateImageVertexAi : imagen === 'dall-e' ? generateImageDallE : undefined;
|
|
72
|
-
|
|
73
|
-
console.log('Generating response');
|
|
74
|
-
let functionCalls = await promptService(generateContent, generateImage);
|
|
75
|
-
console.log('Received function calls:', functionCalls);
|
|
76
|
-
|
|
77
|
-
if (dryRun) {
|
|
78
|
-
console.log('Dry run mode, not updating files');
|
|
79
|
-
} else {
|
|
80
|
-
console.log('Update files');
|
|
81
|
-
await updateFiles(functionCalls.filter((call) => call.name !== 'explanation' && call.name !== 'getSourceCode'));
|
|
82
|
-
console.log('Initial updates applied');
|
|
83
|
-
|
|
84
|
-
// Check if lintCommand is specified in .genaicoderc
|
|
85
|
-
if (rcConfig.lintCommand) {
|
|
86
|
-
try {
|
|
87
|
-
console.log(`Executing lint command: ${rcConfig.lintCommand}`);
|
|
88
|
-
await execPromise(rcConfig.lintCommand);
|
|
89
|
-
console.log('Lint command executed successfully');
|
|
90
|
-
} catch (error) {
|
|
91
|
-
console.log('Lint command failed. Attempting to fix issues...');
|
|
92
|
-
|
|
93
|
-
// Prepare the lint error output for the second pass
|
|
94
|
-
const lintErrorPrompt = getLintFixPrompt(rcConfig.lintCommand, error.stdout, error.stderr);
|
|
95
|
-
|
|
96
|
-
console.log('Generating response for lint fixes');
|
|
97
|
-
const lintFixFunctionCalls = await promptService(generateContent, generateImage, lintErrorPrompt);
|
|
98
|
-
|
|
99
|
-
console.log('Received function calls for lint fixes:', lintFixFunctionCalls);
|
|
100
|
-
|
|
101
|
-
console.log('Applying lint fixes');
|
|
102
|
-
updateFiles(
|
|
103
|
-
lintFixFunctionCalls.filter((call) => call.name !== 'explanation' && call.name !== 'getSourceCode'),
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
// Run lint command again to verify fixes
|
|
107
|
-
try {
|
|
108
|
-
console.log(`Re-running lint command: ${rcConfig.lintCommand}`);
|
|
109
|
-
await execPromise(rcConfig.lintCommand);
|
|
110
|
-
console.log('Lint command executed successfully after fixes');
|
|
111
|
-
} catch (secondLintError) {
|
|
112
|
-
console.log('Lint command still failing after fixes. Manual intervention may be required.');
|
|
113
|
-
console.log('Lint errors:', secondLintError.stdout, secondLintError.stderr);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
console.log('Done!');
|
|
119
|
-
}
|
|
120
|
-
}
|
package/src/main/codegen.test.js
DELETED
|
@@ -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
|
-
});
|
package/src/main/config-lib.js
DELETED
|
@@ -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
|
-
};
|