genaicode 0.15.0 → 1.0.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 +0 -7
- package/dist/main/codegen.d.ts +1 -3
- package/dist/main/codegen.js +2 -19
- package/dist/main/codegen.js.map +1 -1
- package/dist/main/generate-content-functions.d.ts +3 -0
- package/dist/main/generate-content-functions.js +19 -0
- package/dist/main/generate-content-functions.js.map +1 -0
- package/dist/main/ui/backend/endpoints/generate-content-endpoint.js +2 -4
- package/dist/main/ui/backend/endpoints/generate-content-endpoint.js.map +1 -1
- package/dist/main/ui/backend/service.d.ts +1 -0
- package/dist/main/ui/backend/service.js +5 -1
- package/dist/main/ui/backend/service.js.map +1 -1
- package/dist/main/ui/frontend/assets/index-C_k1AhO2.js +3445 -0
- package/dist/main/ui/frontend/index.html +1 -1
- package/dist/prompt/dynamic-function-generator.d.ts +2 -0
- package/dist/prompt/dynamic-function-generator.js +58 -0
- package/dist/prompt/dynamic-function-generator.js.map +1 -0
- package/dist/vite-genaicode/code-transformer.d.ts +5 -0
- package/dist/vite-genaicode/code-transformer.js +83 -0
- package/dist/vite-genaicode/code-transformer.js.map +1 -0
- package/dist/vite-genaicode/constants.d.ts +3 -0
- package/dist/vite-genaicode/constants.js +4 -0
- package/dist/vite-genaicode/constants.js.map +1 -0
- package/dist/vite-genaicode/dynamic-function-generator.d.ts +2 -0
- package/dist/vite-genaicode/dynamic-function-generator.js +47 -0
- package/dist/vite-genaicode/dynamic-function-generator.js.map +1 -0
- package/dist/vite-genaicode/html-injector.d.ts +6 -0
- package/dist/vite-genaicode/html-injector.js +14 -0
- package/dist/vite-genaicode/html-injector.js.map +1 -0
- package/dist/vite-genaicode/server-manager.d.ts +26 -0
- package/dist/vite-genaicode/server-manager.js +91 -0
- package/dist/vite-genaicode/server-manager.js.map +1 -0
- package/dist/vite-genaicode/vite-genaicode-plugin.d.ts +11 -2
- package/dist/vite-genaicode/vite-genaicode-plugin.js +60 -65
- package/dist/vite-genaicode/vite-genaicode-plugin.js.map +1 -1
- package/package.json +4 -4
- package/dist/main/ui/frontend/assets/index-DAM_kJhM.js +0 -3445
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
<meta name="keywords" content="GenAIcode, AI, code generation, programming" />
|
|
8
8
|
<title>GenAIcode - AI-Powered Code Generation</title>
|
|
9
9
|
<link rel="icon" href="/assets/favicon-DvroFOpS.png" type="image/png" />
|
|
10
|
-
<script type="module" crossorigin src="/assets/index-
|
|
10
|
+
<script type="module" crossorigin src="/assets/index-C_k1AhO2.js"></script>
|
|
11
11
|
<link rel="stylesheet" crossorigin href="/assets/index-5QDg_0vR.css">
|
|
12
12
|
</head>
|
|
13
13
|
<body data-security-token="__SECURITY_TOKEN__">
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { AiServiceType, CodegenOptions } from '../main/codegen-types.js';
|
|
2
|
+
export declare function generateDynamicFunction(prompt: string, argsLength: number, functionName: string, aiService: AiServiceType, codegenOptions: CodegenOptions, callingFilePath?: string): Promise<string>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { getGenerateContentFunctions } from '../main/generate-content-functions.js';
|
|
3
|
+
import { ModelType } from '../ai-service/common-types.js';
|
|
4
|
+
import { getSystemPrompt } from './systemprompt.js';
|
|
5
|
+
import { rcConfig } from '../main/config.js';
|
|
6
|
+
export async function generateDynamicFunction(prompt, argsLength, functionName, aiService, codegenOptions, callingFilePath) {
|
|
7
|
+
try {
|
|
8
|
+
const generateContentFns = getGenerateContentFunctions();
|
|
9
|
+
if (!generateContentFns[aiService]) {
|
|
10
|
+
throw new Error(`AI service ${aiService} is not available`);
|
|
11
|
+
}
|
|
12
|
+
const generateContentFn = generateContentFns[aiService];
|
|
13
|
+
const argsSignature = Array.from({ length: argsLength })
|
|
14
|
+
.map((_, i) => `arg${i + 1}: any`)
|
|
15
|
+
.join(', ');
|
|
16
|
+
const baseSystemPrompt = getSystemPrompt(rcConfig, codegenOptions);
|
|
17
|
+
const systemPrompt = `${baseSystemPrompt}\nYou are a code generator. You must implement a pure JavaScript function that matches the user's intent.
|
|
18
|
+
The function MUST be named "${functionName}".
|
|
19
|
+
It MUST NOT be wrapped in markdown code blocks.
|
|
20
|
+
It MUST be a valid exported function declaration.
|
|
21
|
+
It MUST NOT contain any TypeScript syntax (no type annotations, interfaces, enums, etc.).
|
|
22
|
+
It MUST support the following argument signature: (${argsSignature}).`;
|
|
23
|
+
let userPrompt = `Implement a function that does the following: "${prompt}".`;
|
|
24
|
+
if (callingFilePath && fs.existsSync(callingFilePath)) {
|
|
25
|
+
const callingFileContent = fs.readFileSync(callingFilePath, 'utf-8');
|
|
26
|
+
userPrompt += `\n\nHere is the context of the file where this function will be called (\`${callingFilePath}\`):
|
|
27
|
+
\`\`\`javascript
|
|
28
|
+
${callingFileContent}
|
|
29
|
+
\`\`\`
|
|
30
|
+
Use this context to infer appropriate structure for the generated function.`;
|
|
31
|
+
}
|
|
32
|
+
const result = await generateContentFn([
|
|
33
|
+
{ type: 'systemPrompt', systemPrompt },
|
|
34
|
+
{ type: 'user', text: userPrompt },
|
|
35
|
+
], {
|
|
36
|
+
temperature: 0.1,
|
|
37
|
+
modelType: ModelType.DEFAULT,
|
|
38
|
+
expectedResponseType: { text: true, functionCall: false, media: false },
|
|
39
|
+
}, codegenOptions);
|
|
40
|
+
const textResponse = result.find((r) => r.type === 'text');
|
|
41
|
+
if (!textResponse || !textResponse.text) {
|
|
42
|
+
throw new Error('Failed to generate code: No text response from AI');
|
|
43
|
+
}
|
|
44
|
+
let code = textResponse.text.trim();
|
|
45
|
+
if (code.startsWith('```')) {
|
|
46
|
+
code = code.replace(/^```[a-z]*\n/, '').replace(/\n```$/, '');
|
|
47
|
+
}
|
|
48
|
+
if (!code.startsWith('export ')) {
|
|
49
|
+
code = 'export ' + code;
|
|
50
|
+
}
|
|
51
|
+
return code;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error('Error generating dynamic function:', error);
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=dynamic-function-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic-function-generator.js","sourceRoot":"","sources":["../../src/prompt/dynamic-function-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,2BAA2B,EAAE,MAAM,uCAAuC,CAAC;AACpF,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE1D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,MAAc,EACd,UAAkB,EAClB,YAAoB,EACpB,SAAwB,EACxB,cAA8B,EAC9B,eAAwB;IAExB,IAAI,CAAC;QACH,MAAM,kBAAkB,GAAG,2BAA2B,EAAE,CAAC;QACzD,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,cAAc,SAAS,mBAAmB,CAAC,CAAC;QAC9D,CAAC;QACD,MAAM,iBAAiB,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;QAExD,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;aACrD,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC;aACjC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEd,MAAM,gBAAgB,GAAG,eAAe,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;QAEnE,MAAM,YAAY,GAAG,GAAG,gBAAgB;8BACd,YAAY;;;;qDAIW,aAAa,IAAI,CAAC;QAEnE,IA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QAC1B,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;QAC3D,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import crypto from 'node:crypto';
|
|
4
|
+
export async function transformCode(code, id, codegenService, outDir) {
|
|
5
|
+
// Ignore node_modules and files that don't look like they use our generator
|
|
6
|
+
if (id.includes('node_modules') || !code.includes('genaicode:generator')) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
// Check if the file imports dynamicFunction
|
|
10
|
+
const importRegex = /import\s*{[^}]*\bdynamicFunction\b[^}]*}\s*from\s*['"][^'"]+['"]/;
|
|
11
|
+
if (!importRegex.test(code)) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
// Determine output path: use outDir if provided, otherwise fall back to src/
|
|
15
|
+
const outputPath = outDir
|
|
16
|
+
? path.resolve(outDir, 'genaicode-generated.js')
|
|
17
|
+
: path.resolve(process.cwd(), 'src/genaicode-generated.js');
|
|
18
|
+
// Ensure the output directory and file exist
|
|
19
|
+
if (!fs.existsSync(outputPath)) {
|
|
20
|
+
const dir = path.dirname(outputPath);
|
|
21
|
+
if (!fs.existsSync(dir)) {
|
|
22
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
23
|
+
}
|
|
24
|
+
fs.writeFileSync(outputPath, '// AUTO-GENERATED BY GENAICODE VITE PLUGIN - DO NOT EDIT\n\n', 'utf-8');
|
|
25
|
+
}
|
|
26
|
+
let generatedFileContent = fs.readFileSync(outputPath, 'utf-8');
|
|
27
|
+
let transformedCode = code;
|
|
28
|
+
const generatedFunctions = [];
|
|
29
|
+
// Find all dynamicFunction calls: dynamicFunction("prompt", arg1, arg2...)
|
|
30
|
+
const callRegex = /dynamicFunction\s*\(\s*(['"`])(.*?)\1\s*(?:,\s*(.*?))?\)/g;
|
|
31
|
+
let match;
|
|
32
|
+
while ((match = callRegex.exec(code)) !== null) {
|
|
33
|
+
const fullMatch = match[0];
|
|
34
|
+
const prompt = match[2];
|
|
35
|
+
const argsString = match[3];
|
|
36
|
+
// Calculate number of arguments (roughly)
|
|
37
|
+
let argsLength = 0;
|
|
38
|
+
if (argsString && argsString.trim().length > 0) {
|
|
39
|
+
argsLength = argsString.split(',').length;
|
|
40
|
+
}
|
|
41
|
+
// Generate a unique function name based on the prompt
|
|
42
|
+
const safePrompt = prompt.replace(/[^a-zA-Z0-9]/g, '_').substring(0, 20);
|
|
43
|
+
const hash = crypto.createHash('md5').update(prompt).digest('hex').substring(0, 8);
|
|
44
|
+
const funcName = `gen_${safePrompt}_${hash}`;
|
|
45
|
+
generatedFunctions.push(funcName);
|
|
46
|
+
// Check if the function implementation already exists in the generated file
|
|
47
|
+
if (!generatedFileContent.includes(`export function ${funcName}`)) {
|
|
48
|
+
console.log(`[GenAIcode] Generating dynamic function implementation for: "${prompt}"...`);
|
|
49
|
+
try {
|
|
50
|
+
const generatedCode = await codegenService.generateDynamicFunction(prompt, argsLength, funcName, id);
|
|
51
|
+
const formattedCode = `// Prompt: ${prompt}\n${generatedCode}\n`;
|
|
52
|
+
// Append to the physical file
|
|
53
|
+
fs.appendFileSync(outputPath, formattedCode, 'utf-8');
|
|
54
|
+
generatedFileContent += formattedCode;
|
|
55
|
+
console.log(`[GenAIcode] Appended ${funcName} to ${outputPath}`);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.error(`[GenAIcode] Failed to generate function for prompt: "${prompt}"`, error);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Replace the dynamicFunction call with the generated function name
|
|
62
|
+
const replacement = argsString ? `${funcName}(${argsString})` : `${funcName}()`;
|
|
63
|
+
transformedCode = transformedCode.replace(fullMatch, replacement);
|
|
64
|
+
}
|
|
65
|
+
if (generatedFunctions.length > 0) {
|
|
66
|
+
// Calculate relative path from the current source file to the generated file
|
|
67
|
+
const fileDir = path.dirname(id);
|
|
68
|
+
let relativePath = path.relative(fileDir, outputPath);
|
|
69
|
+
// Ensure it starts with ./
|
|
70
|
+
if (!relativePath.startsWith('.')) {
|
|
71
|
+
relativePath = './' + relativePath;
|
|
72
|
+
}
|
|
73
|
+
// Normalize to .js extension for ES module imports
|
|
74
|
+
relativePath = relativePath.replace(/\.ts$/, '.js');
|
|
75
|
+
const newImport = `import { ${[...new Set(generatedFunctions)].join(', ')} } from '${relativePath}';`;
|
|
76
|
+
transformedCode = transformedCode.replace(importRegex, newImport);
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
code: transformedCode,
|
|
80
|
+
map: null,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=code-transformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-transformer.js","sourceRoot":"","sources":["../../src/vite-genaicode/code-transformer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,MAAM,MAAM,aAAa,CAAC;AAGjC,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAY,EAAE,EAAU,EAAE,cAAuB,EAAE,MAAe;IACpG,4EAA4E;IAC5E,IAAI,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC,EAAE,CAAC;QACzE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,4CAA4C;IAC5C,MAAM,WAAW,GAAG,kEAAkE,CAAC;IACvF,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,6EAA6E;IAC7E,MAAM,UAAU,GAAG,M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G,QAAQ,IAAI,UAAU,GAAG,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,CAAC;QAChF,eAAe,GAAG,eAAe,CAAC,OAAO,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACpE,CAAC;IAED,IAAI,kBAAkB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClC,6EAA6E;QAC7E,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACjC,IAAI,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAEtD,2BAA2B;QAC3B,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAClC,YAAY,GAAG,IAAI,GAAG,YAAY,CAAC;QACrC,CAAC;QAED,mDAAmD;QACnD,YAAY,GAAG,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAEpD,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,IAAI,GAAG,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,YAAY,IAAI,CAAC;QACtG,eAAe,GAAG,eAAe,CAAC,OAAO,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IACpE,CAAC;IAED,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,GAAG,EAAE,IAAI;KACV,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/vite-genaicode/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC;AACnC,MAAM,CAAC,MAAM,iBAAiB,GAAG,oBAAoB,CAAC;AACtD,MAAM,CAAC,MAAM,2BAA2B,GAAG,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { getGenerateContentFunctions } from '../main/codegen.js';
|
|
2
|
+
import { ModelType } from '../ai-service/common-types.js';
|
|
3
|
+
export async function generateDynamicFunction(prompt, argsLength, functionName, aiService, codegenOptions) {
|
|
4
|
+
try {
|
|
5
|
+
const generateContentFns = getGenerateContentFunctions();
|
|
6
|
+
if (!generateContentFns[aiService]) {
|
|
7
|
+
throw new Error(`AI service ${aiService} is not available`);
|
|
8
|
+
}
|
|
9
|
+
const generateContentFn = generateContentFns[aiService];
|
|
10
|
+
const argsSignature = Array.from({ length: argsLength })
|
|
11
|
+
.map((_, i) => `arg${i + 1}: any`)
|
|
12
|
+
.join(', ');
|
|
13
|
+
const systemPrompt = `You are a code generator. You must implement a JavaScript/TypeScript function that matches the user's intent.
|
|
14
|
+
The function MUST be named "${functionName}".
|
|
15
|
+
It MUST NOT be wrapped in markdown code blocks.
|
|
16
|
+
It MUST be a valid exported function declaration.
|
|
17
|
+
It MUST support the following argument signature: (${argsSignature}).`;
|
|
18
|
+
const userPrompt = `Implement a function that does the following: "${prompt}".`;
|
|
19
|
+
const result = await generateContentFn([
|
|
20
|
+
{ type: 'systemPrompt', systemPrompt },
|
|
21
|
+
{ type: 'user', text: userPrompt },
|
|
22
|
+
], {
|
|
23
|
+
temperature: 0.1, // Low temperature for deterministic code generation
|
|
24
|
+
modelType: ModelType.DEFAULT,
|
|
25
|
+
expectedResponseType: { text: true, functionCall: false, media: false },
|
|
26
|
+
}, codegenOptions);
|
|
27
|
+
const textResponse = result.find((r) => r.type === 'text');
|
|
28
|
+
if (!textResponse || !textResponse.text) {
|
|
29
|
+
throw new Error('Failed to generate code: No text response from AI');
|
|
30
|
+
}
|
|
31
|
+
let code = textResponse.text.trim();
|
|
32
|
+
// Clean up markdown if the AI ignored the instruction
|
|
33
|
+
if (code.startsWith('```')) {
|
|
34
|
+
code = code.replace(/^```[a-z]*\n/, '').replace(/\n```$/, '');
|
|
35
|
+
}
|
|
36
|
+
// Ensure it's exported
|
|
37
|
+
if (!code.startsWith('export ')) {
|
|
38
|
+
code = 'export ' + code;
|
|
39
|
+
}
|
|
40
|
+
return code;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.error('Error generating dynamic function:', error);
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=dynamic-function-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic-function-generator.js","sourceRoot":"","sources":["../../src/vite-genaicode/dynamic-function-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAG1D,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,MAAc,EACd,UAAkB,EAClB,YAAoB,EACpB,SAAwB,EACxB,cAA8B;IAE9B,IAAI,CAAC;QACH,MAAM,kBAAkB,GAAG,2BAA2B,EAAE,CAAC;QACzD,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,cAAc,SAAS,mBAAmB,CAAC,CAAC;QAC9D,CAAC;QACD,MAAM,iBAAiB,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;QAExD,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;aACrD,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC;aACjC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEd,MAAM,YAAY,GAAG;8BACK,YAAY;;;qDAGW,aAAa,IAAI,CAAC;QAEnE,MAAM,UAAU,GAAG,kDAAkD,MAAM,IAAI,CAAC;QAEhF,MAAM,MAAM,GAAG,MAAM,iBAAiB,CACpC;YACE,EAAE,IAAI,EAAE,cAAc,EAAE,YAAY,EAAE;YACtC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE;SACnC,EACD;YACE,WAAW,EAAE,GAAG,EAAE,oDAAoD;YACtE,SAAS,EAAE,SAAS,CAAC,OAAO;YAC5B,oBAAoB,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE;SACxE,EACD,cAAc,CACf,CAAC;QAEF,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;QAC3D,IAAI,CAAC,YAAY,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACvE,CAAC;QAED,IAAI,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACpC,sDAAsD;QACtD,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3B,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAChE,CAAC;QAED,uBAAuB;QACvB,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YAChC,IAAI,GAAG,SAAS,GAAG,IAAI,CAAC;QAC1B,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;QAC3D,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function injectGenaicodeScript(html, options) {
|
|
2
|
+
const { genaicodePort, appContextEnabled, token, logBufferMaxSize } = options;
|
|
3
|
+
return html.replace('</body>', `<script type="module"
|
|
4
|
+
src="/vite-genaicode.js"
|
|
5
|
+
data-genaicode-port="${genaicodePort}"
|
|
6
|
+
${appContextEnabled
|
|
7
|
+
? `data-genaicode-token="${token || ''}"
|
|
8
|
+
data-genaicode-app-context-enabled="true"
|
|
9
|
+
data-genaicode-log-buffer-max-size="${logBufferMaxSize}"`
|
|
10
|
+
: ``}
|
|
11
|
+
>
|
|
12
|
+
</script>`);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=html-injector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-injector.js","sourceRoot":"","sources":["../../src/vite-genaicode/html-injector.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,qBAAqB,CACnC,IAAY,EACZ,OAKC;IAED,MAAM,EAAE,aAAa,EAAE,iBAAiB,EAAE,KAAK,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC;IAE9E,OAAO,IAAI,CAAC,OAAO,CACjB,SAAS,EACT;;yBAEqB,aAAa;IAElC,iBAAiB;QACf,CAAC,CAAC,yBAAyB,KAAK,IAAI,EAAE;;0CAEF,gBAAgB,GAAG;QACvD,CAAC,CAAC,EACN;;UAEQ,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Service } from '../main/ui/backend/service.js';
|
|
2
|
+
import { CodegenOptions, Plugin } from '../main/codegen-types.js';
|
|
3
|
+
export declare class GenaicodeServerManager {
|
|
4
|
+
private readonly options?;
|
|
5
|
+
private readonly config?;
|
|
6
|
+
private readonly pluginFilename?;
|
|
7
|
+
private codegenService?;
|
|
8
|
+
private codegenServer?;
|
|
9
|
+
private appContextEnabled?;
|
|
10
|
+
private initPromise;
|
|
11
|
+
private readonly genaicodePort;
|
|
12
|
+
private _outDir?;
|
|
13
|
+
constructor(options?: Partial<CodegenOptions> | undefined, config?: {
|
|
14
|
+
plugins?: Plugin[];
|
|
15
|
+
genaicodePort?: number;
|
|
16
|
+
logBufferMaxSize?: number;
|
|
17
|
+
} | undefined, pluginFilename?: string | undefined);
|
|
18
|
+
private start;
|
|
19
|
+
ensureService(port: number): Promise<void>;
|
|
20
|
+
close(): void;
|
|
21
|
+
get service(): Service | undefined;
|
|
22
|
+
get isAppContextEnabled(): boolean | undefined;
|
|
23
|
+
get port(): number;
|
|
24
|
+
set outDir(dir: string);
|
|
25
|
+
get outDir(): string | undefined;
|
|
26
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { serviceAutoDetect } from '../cli/service-autodetect.js';
|
|
2
|
+
import { stringToAiServiceType } from '../main/codegen-utils.js';
|
|
3
|
+
import { registerPlugin } from '../main/plugin-loader.js';
|
|
4
|
+
import { GENAICODE_PORT } from './constants.js';
|
|
5
|
+
export class GenaicodeServerManager {
|
|
6
|
+
options;
|
|
7
|
+
config;
|
|
8
|
+
pluginFilename;
|
|
9
|
+
codegenService;
|
|
10
|
+
codegenServer;
|
|
11
|
+
appContextEnabled;
|
|
12
|
+
initPromise = null;
|
|
13
|
+
genaicodePort;
|
|
14
|
+
_outDir;
|
|
15
|
+
constructor(options, config, pluginFilename) {
|
|
16
|
+
this.options = options;
|
|
17
|
+
this.config = config;
|
|
18
|
+
this.pluginFilename = pluginFilename;
|
|
19
|
+
this.genaicodePort = config?.genaicodePort ?? GENAICODE_PORT;
|
|
20
|
+
}
|
|
21
|
+
async start(port) {
|
|
22
|
+
try {
|
|
23
|
+
// Register inline plugins if provided
|
|
24
|
+
for (const plugin of this.config?.plugins ?? []) {
|
|
25
|
+
await registerPlugin(plugin, this.pluginFilename || '');
|
|
26
|
+
}
|
|
27
|
+
const { runCodegenUI } = await import('../main/ui/codegen-ui.js');
|
|
28
|
+
console.log('Starting GenAIcode in UI mode...');
|
|
29
|
+
const codegen = await runCodegenUI({
|
|
30
|
+
ui: true,
|
|
31
|
+
uiPort: this.genaicodePort,
|
|
32
|
+
uiFrameAncestors: port ? ['http://localhost:' + port] : undefined,
|
|
33
|
+
aiService: this.options?.aiService ?? stringToAiServiceType(serviceAutoDetect()),
|
|
34
|
+
isDev: false,
|
|
35
|
+
allowFileCreate: true,
|
|
36
|
+
allowFileDelete: true,
|
|
37
|
+
allowDirectoryCreate: true,
|
|
38
|
+
allowFileMove: true,
|
|
39
|
+
vision: true,
|
|
40
|
+
temperature: 0.7,
|
|
41
|
+
requireExplanations: true,
|
|
42
|
+
askQuestion: true,
|
|
43
|
+
historyEnabled: true,
|
|
44
|
+
conversationSummaryEnabled: true,
|
|
45
|
+
...this.options,
|
|
46
|
+
});
|
|
47
|
+
this.codegenService = codegen.service;
|
|
48
|
+
this.codegenServer = codegen.server;
|
|
49
|
+
const genaicodeConfig = await this.codegenService.getRcConfig();
|
|
50
|
+
if (typeof genaicodeConfig?.featuresEnabled?.appContext === 'undefined') {
|
|
51
|
+
genaicodeConfig.featuresEnabled = {
|
|
52
|
+
...genaicodeConfig.featuresEnabled,
|
|
53
|
+
appContext: true,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
this.appContextEnabled = genaicodeConfig.featuresEnabled?.appContext;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error('Failed to start GenAIcode UI:', error);
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async ensureService(port) {
|
|
64
|
+
if (!this.initPromise) {
|
|
65
|
+
this.initPromise = this.start(port);
|
|
66
|
+
}
|
|
67
|
+
await this.initPromise;
|
|
68
|
+
}
|
|
69
|
+
close() {
|
|
70
|
+
if (this.codegenServer) {
|
|
71
|
+
console.log('Stopping GenAIcode...');
|
|
72
|
+
this.codegenServer.close();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
get service() {
|
|
76
|
+
return this.codegenService;
|
|
77
|
+
}
|
|
78
|
+
get isAppContextEnabled() {
|
|
79
|
+
return this.appContextEnabled;
|
|
80
|
+
}
|
|
81
|
+
get port() {
|
|
82
|
+
return this.genaicodePort;
|
|
83
|
+
}
|
|
84
|
+
set outDir(dir) {
|
|
85
|
+
this._outDir = dir;
|
|
86
|
+
}
|
|
87
|
+
get outDir() {
|
|
88
|
+
return this._outDir;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=server-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-manager.js","sourceRoot":"","sources":["../../src/vite-genaicode/server-manager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,OAAO,sBAAsB;IASd;IACA;IACA;IAVX,cAAc,CAAW;IACzB,aAAa,CAAU;IACvB,iBAAiB,CAAW;IAC5B,WAAW,GAAyB,IAAI,CAAC;IAChC,aAAa,CAAS;IAC/B,OAAO,CAAU;IAEzB,YACmB,OAAiC,EACjC,MAAkF,EAClF,cAAuB;QAFvB,YAAO,GAAP,OAAO,CAA0B;QACjC,WAAM,GAAN,MAAM,CAA4E;QAClF,mBAAc,GAAd,cAAc,CAAS;QAExC,IAAI,CAAC,aAAa,GAAG,MAAM,EAAE,aAAa,IAAI,cAAc,CAAC;IAC/D,CAAC;IAEO,KAAK,CAAC,KAAK,CAAC,IAAY;QAC9B,IAAI,CAAC;YACH,sCAAsC;YACtC,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,MAAM,EAAE,OAAO,IAAI,EAAE,EAAE,CAAC;gBAChD,MAAM,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC;YAC1D,CAAC;YAED,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,MAAM,CAAC,0BAA0B,CAAC,CAAC;YAElE,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;YAEhD,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C,aAAa,CAAC,IAAY;QACrC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACtC,CAAC;QACD,MAAM,IAAI,CAAC,WAAW,CAAC;IACzB,CAAC;IAEM,KAAK;QACV,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACvB,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;YACrC,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED,IAAW,mBAAmB;QAC5B,OAAO,IAAI,CAAC,iBAAiB,CAAC;IAChC,CAAC;IAED,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED,IAAW,MAAM,CAAC,GAAW;QAC3B,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;IACrB,CAAC;IAED,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
import { ViteDevServer } from 'vite';
|
|
1
|
+
import { ResolvedConfig, ViteDevServer } from 'vite';
|
|
2
2
|
import { CodegenOptions, Plugin } from '../main/codegen-types.js';
|
|
3
3
|
export default function viteGenaicode(options?: Partial<CodegenOptions>, config?: {
|
|
4
|
-
plugins
|
|
4
|
+
plugins?: Plugin[];
|
|
5
5
|
genaicodePort?: number;
|
|
6
6
|
logBufferMaxSize?: number;
|
|
7
|
+
codeTransformer?: boolean;
|
|
7
8
|
}): {
|
|
8
9
|
name: string;
|
|
10
|
+
enforce: "pre";
|
|
11
|
+
configResolved(config: ResolvedConfig): void;
|
|
9
12
|
configureServer(server: ViteDevServer): void;
|
|
13
|
+
buildStart(): Promise<void>;
|
|
14
|
+
transform(code: string, id: string): Promise<{
|
|
15
|
+
code: string;
|
|
16
|
+
map: null;
|
|
17
|
+
} | null>;
|
|
10
18
|
transformIndexHtml(html: string): string;
|
|
11
19
|
resolveId(id: string): string | undefined;
|
|
20
|
+
load(id: string): "export function dynamicFunction() {\n console.warn('dynamicFunction was called but not transformed by GenAIcode plugin.');\n }" | undefined;
|
|
12
21
|
};
|
|
@@ -1,91 +1,86 @@
|
|
|
1
1
|
import { fileURLToPath } from 'url';
|
|
2
2
|
import { dirname } from 'path';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { VIRTUAL_MODULE_ID, GENERATOR_VIRTUAL_MODULE_ID } from './constants.js';
|
|
5
|
+
import { GenaicodeServerManager } from './server-manager.js';
|
|
6
|
+
import { transformCode } from './code-transformer.js';
|
|
7
|
+
import { injectGenaicodeScript } from './html-injector.js';
|
|
6
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
7
9
|
const __dirname = dirname(__filename);
|
|
8
|
-
|
|
10
|
+
let codeTransformerWarningLogged = false;
|
|
9
11
|
export default function viteGenaicode(options, config) {
|
|
10
|
-
|
|
11
|
-
let
|
|
12
|
-
const genaicodePort = config?.genaicodePort ?? GENAICODE_PORT;
|
|
13
|
-
let appContextEnabled;
|
|
14
|
-
async function start(port) {
|
|
15
|
-
try {
|
|
16
|
-
// Register inline plugins if provided
|
|
17
|
-
for (const plugin of config?.plugins ?? []) {
|
|
18
|
-
await registerPlugin(plugin, __filename);
|
|
19
|
-
}
|
|
20
|
-
const { runCodegenUI } = await import('../main/ui/codegen-ui.js');
|
|
21
|
-
console.log('Starting GenAIcode in UI mode...');
|
|
22
|
-
const codegen = await runCodegenUI({
|
|
23
|
-
ui: true,
|
|
24
|
-
uiPort: genaicodePort,
|
|
25
|
-
uiFrameAncestors: ['http://localhost:' + port],
|
|
26
|
-
aiService: options?.aiService ?? stringToAiServiceType(serviceAutoDetect()),
|
|
27
|
-
isDev: false,
|
|
28
|
-
allowFileCreate: true,
|
|
29
|
-
allowFileDelete: true,
|
|
30
|
-
allowDirectoryCreate: true,
|
|
31
|
-
allowFileMove: true,
|
|
32
|
-
vision: true,
|
|
33
|
-
temperature: 0.7,
|
|
34
|
-
requireExplanations: true,
|
|
35
|
-
askQuestion: true,
|
|
36
|
-
historyEnabled: true,
|
|
37
|
-
conversationSummaryEnabled: true,
|
|
38
|
-
...options,
|
|
39
|
-
});
|
|
40
|
-
codegenService = codegen.service;
|
|
41
|
-
codegenServer = codegen.server;
|
|
42
|
-
const genaicodeConfig = await codegenService.getRcConfig();
|
|
43
|
-
if (typeof genaicodeConfig?.featuresEnabled?.appContext === 'undefined') {
|
|
44
|
-
genaicodeConfig.featuresEnabled = {
|
|
45
|
-
...genaicodeConfig.featuresEnabled,
|
|
46
|
-
appContext: true,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
appContextEnabled = genaicodeConfig.featuresEnabled?.appContext;
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
console.error('Failed to start GenAIcode UI:', error);
|
|
53
|
-
throw error;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const virtualModuleId = '/vite-genaicode.js';
|
|
12
|
+
const serverManager = new GenaicodeServerManager(options, config, __filename);
|
|
13
|
+
let port;
|
|
57
14
|
return {
|
|
58
15
|
name: 'vite-genaicode',
|
|
16
|
+
enforce: 'pre',
|
|
17
|
+
configResolved(config) {
|
|
18
|
+
// Capture the resolved output directory so generated files land in dist/
|
|
19
|
+
const resolvedOutDir = path.resolve(config.root, config.build.outDir);
|
|
20
|
+
serverManager.outDir = resolvedOutDir;
|
|
21
|
+
},
|
|
59
22
|
configureServer(server) {
|
|
60
23
|
server.httpServer?.once('listening', () => {
|
|
61
24
|
const address = server.httpServer.address();
|
|
62
|
-
|
|
25
|
+
port = address.port;
|
|
26
|
+
serverManager.ensureService(address.port).catch((error) => {
|
|
63
27
|
console.error('Failed to start GenAIcode server:', error);
|
|
64
28
|
server.close();
|
|
65
29
|
});
|
|
66
30
|
});
|
|
67
31
|
server.httpServer?.on('close', () => {
|
|
68
|
-
|
|
69
|
-
codegenServer.close();
|
|
32
|
+
serverManager.close();
|
|
70
33
|
});
|
|
71
34
|
},
|
|
35
|
+
async buildStart() {
|
|
36
|
+
if (port) {
|
|
37
|
+
await serverManager.ensureService(port);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
console.warn('[GenAIcode] Could not determine dev server port. GenAIcode server may not start correctly.');
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
async transform(code, id) {
|
|
44
|
+
if (config?.codeTransformer !== true) {
|
|
45
|
+
if (!codeTransformerWarningLogged) {
|
|
46
|
+
console.info('[GenAIcode] Code transformer is disabled by default. Enable it by passing `codeTransformer: true` in the viteGenaicode plugin config.');
|
|
47
|
+
codeTransformerWarningLogged = true;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
if (!port) {
|
|
52
|
+
console.warn('[GenAIcode] Dev server port not available yet. Skipping code transformation for:', id);
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
await serverManager.ensureService(port);
|
|
56
|
+
const service = serverManager.service;
|
|
57
|
+
if (!service)
|
|
58
|
+
return null;
|
|
59
|
+
return transformCode(code, id, service, serverManager.outDir);
|
|
60
|
+
},
|
|
72
61
|
transformIndexHtml(html) {
|
|
73
62
|
const logBufferMaxSize = config?.logBufferMaxSize ?? 1000;
|
|
74
|
-
return html
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
data-genaicode-log-buffer-max-size="${logBufferMaxSize}"`
|
|
81
|
-
: ``}
|
|
82
|
-
>
|
|
83
|
-
</script>`);
|
|
63
|
+
return injectGenaicodeScript(html, {
|
|
64
|
+
genaicodePort: serverManager.port,
|
|
65
|
+
appContextEnabled: serverManager.isAppContextEnabled,
|
|
66
|
+
token: serverManager.service?.getToken(),
|
|
67
|
+
logBufferMaxSize,
|
|
68
|
+
});
|
|
84
69
|
},
|
|
85
70
|
resolveId(id) {
|
|
86
|
-
if (id ===
|
|
71
|
+
if (id === VIRTUAL_MODULE_ID) {
|
|
87
72
|
return __dirname + '/vite-genaicode-frontend.js';
|
|
88
73
|
}
|
|
74
|
+
if (id === GENERATOR_VIRTUAL_MODULE_ID) {
|
|
75
|
+
return '\0' + GENERATOR_VIRTUAL_MODULE_ID;
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
load(id) {
|
|
79
|
+
if (id === '\0' + GENERATOR_VIRTUAL_MODULE_ID) {
|
|
80
|
+
return `export function dynamicFunction() {
|
|
81
|
+
console.warn('dynamicFunction was called but not transformed by GenAIcode plugin.');
|
|
82
|
+
}`;
|
|
83
|
+
}
|
|
89
84
|
},
|
|
90
85
|
};
|
|
91
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-genaicode-plugin.js","sourceRoot":"","sources":["../../src/vite-genaicode/vite-genaicode-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"vite-genaicode-plugin.js","sourceRoot":"","sources":["../../src/vite-genaicode/vite-genaicode-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,IAAI,MAAM,MAAM,CAAC;AAIxB,OAAO,EAAE,iBAAiB,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CA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C7B,OAAO,SAAS,GAAG,6BAA6B,CAAC;YACnD,CAAC;YACD,IAAI,EAAE,KAAK,2BAA2B,EAAE,CAAC;gBACvC,OAAO,IAAI,GAAG,2BAA2B,CAAC;YAC5C,CAAC;QACH,CAAC;QAED,IAAI,CAAC,EAAU;YACb,IAAI,EAAE,KAAK,IAAI,GAAG,2BAA2B,EAAE,CAAC;gBAC9C,OAAO;;UAEL,CAAC;YACL,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "genaicode",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"author": "Grzegorz Tańczyk",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"@types/mime-types": "^2.1.4",
|
|
106
106
|
"@types/node": "^18.0.0",
|
|
107
107
|
"@types/styled-components": "^5.1.34",
|
|
108
|
-
"axios": "^1.
|
|
108
|
+
"axios": "^1.13.5",
|
|
109
109
|
"c12": "^3.3.3",
|
|
110
110
|
"cors": "^2.8.5",
|
|
111
111
|
"diff": "^5.2.2",
|
|
@@ -118,11 +118,11 @@
|
|
|
118
118
|
"inquirer-file-selector": "^0.4.0",
|
|
119
119
|
"jsonschema": "^1.4.1",
|
|
120
120
|
"mime-types": "^2.1.35",
|
|
121
|
-
"multer": "^2.
|
|
121
|
+
"multer": "^2.1.1",
|
|
122
122
|
"openai": "^5.16.0",
|
|
123
123
|
"please-upgrade-node": "^3.2.0",
|
|
124
124
|
"sharp": "^0.33.4",
|
|
125
|
-
"simple-git": "^3.
|
|
125
|
+
"simple-git": "^3.32.3",
|
|
126
126
|
"tar-stream": "^3.1.7",
|
|
127
127
|
"xml2js": "^0.6.2",
|
|
128
128
|
"zod": "^3.25.0"
|