editcodewithai 2.3.0 → 2.4.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/dist/fileUtils.d.ts +9 -2
- package/dist/fileUtils.js +16 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +10 -4
- package/dist/prompt.d.ts +2 -1
- package/dist/prompt.js +9 -7
- package/package.json +10 -10
package/dist/fileUtils.d.ts
CHANGED
|
@@ -5,9 +5,16 @@ import { VizFiles, VizFile, FileCollection } from "@vizhub/viz-types";
|
|
|
5
5
|
*/
|
|
6
6
|
export declare function shouldDeleteFile(file?: VizFile): boolean;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Checks if a filename is an image file based on extension
|
|
9
9
|
*/
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function isImageFile(fileName: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Processes files for the prompt by truncating large files and excluding images
|
|
13
|
+
*/
|
|
14
|
+
export declare function prepareFilesForPrompt(files: VizFiles): {
|
|
15
|
+
files: FileCollection;
|
|
16
|
+
imageFiles: string[];
|
|
17
|
+
};
|
|
11
18
|
/**
|
|
12
19
|
* Merges original files with changes from the LLM
|
|
13
20
|
*/
|
package/dist/fileUtils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.shouldDeleteFile = shouldDeleteFile;
|
|
4
|
+
exports.isImageFile = isImageFile;
|
|
4
5
|
exports.prepareFilesForPrompt = prepareFilesForPrompt;
|
|
5
6
|
exports.mergeFileChanges = mergeFileChanges;
|
|
6
7
|
exports.parseDiffs = parseDiffs;
|
|
@@ -19,11 +20,24 @@ function shouldDeleteFile(file) {
|
|
|
19
20
|
return file.text.trim() === "";
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
22
|
-
*
|
|
23
|
+
* Checks if a filename is an image file based on extension
|
|
24
|
+
*/
|
|
25
|
+
function isImageFile(fileName) {
|
|
26
|
+
const imageExtensions = /\.(png|jpg|jpeg|gif|bmp|svg|webp)$/i;
|
|
27
|
+
return imageExtensions.test(fileName);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Processes files for the prompt by truncating large files and excluding images
|
|
23
31
|
*/
|
|
24
32
|
function prepareFilesForPrompt(files) {
|
|
25
33
|
const result = {};
|
|
34
|
+
const imageFiles = [];
|
|
26
35
|
Object.values(files).forEach((file) => {
|
|
36
|
+
// Check if it's an image file
|
|
37
|
+
if (isImageFile(file.name)) {
|
|
38
|
+
imageFiles.push(file.name);
|
|
39
|
+
return; // Skip processing image files
|
|
40
|
+
}
|
|
27
41
|
// Example: truncate large files, etc.
|
|
28
42
|
result[file.name] = file.text
|
|
29
43
|
.split("\n")
|
|
@@ -31,7 +45,7 @@ function prepareFilesForPrompt(files) {
|
|
|
31
45
|
.map((line) => line.slice(0, 200))
|
|
32
46
|
.join("\n");
|
|
33
47
|
});
|
|
34
|
-
return result;
|
|
48
|
+
return { files: result, imageFiles };
|
|
35
49
|
}
|
|
36
50
|
/**
|
|
37
51
|
* Merges original files with changes from the LLM
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { PerformAiEditParams, PerformAiEditResult } from "./types";
|
|
2
2
|
import { PROMPT_TEMPLATE_VERSION, assembleFullPrompt, FORMAT_INSTRUCTIONS } from "./prompt";
|
|
3
3
|
import { getGenerationMetadata } from "./metadata";
|
|
4
|
-
import { prepareFilesForPrompt, mergeFileChanges, parseDiffs, applyDiffs, parseDiffFenced, parseUdiffs, applyUdiffs } from "./fileUtils";
|
|
4
|
+
import { prepareFilesForPrompt, mergeFileChanges, parseDiffs, applyDiffs, parseDiffFenced, parseUdiffs, applyUdiffs, isImageFile } from "./fileUtils";
|
|
5
5
|
export type { LlmFunction, PerformAiEditParams, PerformAiEditResult, EditFormat, } from "./types";
|
|
6
|
-
export { FORMAT_INSTRUCTIONS, mergeFileChanges, prepareFilesForPrompt, parseDiffs, applyDiffs, parseDiffFenced, parseUdiffs, applyUdiffs, assembleFullPrompt, getGenerationMetadata, PROMPT_TEMPLATE_VERSION, };
|
|
6
|
+
export { FORMAT_INSTRUCTIONS, mergeFileChanges, prepareFilesForPrompt, isImageFile, parseDiffs, applyDiffs, parseDiffFenced, parseUdiffs, applyUdiffs, assembleFullPrompt, getGenerationMetadata, PROMPT_TEMPLATE_VERSION, };
|
|
7
7
|
/**
|
|
8
8
|
* Core AI logic for:
|
|
9
9
|
* - Building the prompt (including context)
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PROMPT_TEMPLATE_VERSION = exports.getGenerationMetadata = exports.assembleFullPrompt = exports.applyUdiffs = exports.parseUdiffs = exports.parseDiffFenced = exports.applyDiffs = exports.parseDiffs = exports.prepareFilesForPrompt = exports.mergeFileChanges = exports.FORMAT_INSTRUCTIONS = void 0;
|
|
3
|
+
exports.PROMPT_TEMPLATE_VERSION = exports.getGenerationMetadata = exports.assembleFullPrompt = exports.applyUdiffs = exports.parseUdiffs = exports.parseDiffFenced = exports.applyDiffs = exports.parseDiffs = exports.isImageFile = exports.prepareFilesForPrompt = exports.mergeFileChanges = exports.FORMAT_INSTRUCTIONS = void 0;
|
|
4
4
|
exports.performAiEdit = performAiEdit;
|
|
5
5
|
const llm_code_format_1 = require("llm-code-format");
|
|
6
6
|
const prompt_1 = require("./prompt");
|
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "applyDiffs", { enumerable: true, get: function (
|
|
|
17
17
|
Object.defineProperty(exports, "parseDiffFenced", { enumerable: true, get: function () { return fileUtils_1.parseDiffFenced; } });
|
|
18
18
|
Object.defineProperty(exports, "parseUdiffs", { enumerable: true, get: function () { return fileUtils_1.parseUdiffs; } });
|
|
19
19
|
Object.defineProperty(exports, "applyUdiffs", { enumerable: true, get: function () { return fileUtils_1.applyUdiffs; } });
|
|
20
|
+
Object.defineProperty(exports, "isImageFile", { enumerable: true, get: function () { return fileUtils_1.isImageFile; } });
|
|
20
21
|
const debug = false;
|
|
21
22
|
/**
|
|
22
23
|
* Core AI logic for:
|
|
@@ -27,10 +28,15 @@ const debug = false;
|
|
|
27
28
|
*/
|
|
28
29
|
async function performAiEdit({ prompt, files, llmFunction, apiKey, editFormat = "whole", }) {
|
|
29
30
|
// 1. Format the existing files into the "markdown code block" format
|
|
30
|
-
const
|
|
31
|
-
const filesContext = (0, llm_code_format_1.formatMarkdownFiles)(
|
|
31
|
+
const preparedResult = (0, fileUtils_1.prepareFilesForPrompt)(files);
|
|
32
|
+
const filesContext = (0, llm_code_format_1.formatMarkdownFiles)(preparedResult.files);
|
|
32
33
|
// 2. Assemble the final prompt
|
|
33
|
-
const fullPrompt = (0, prompt_1.assembleFullPrompt)({
|
|
34
|
+
const fullPrompt = (0, prompt_1.assembleFullPrompt)({
|
|
35
|
+
filesContext,
|
|
36
|
+
prompt,
|
|
37
|
+
editFormat,
|
|
38
|
+
imageFiles: preparedResult.imageFiles,
|
|
39
|
+
});
|
|
34
40
|
debug && console.log("[performAiEdit] fullPrompt:", fullPrompt);
|
|
35
41
|
// 3. Invoke the model via the provided LLM function
|
|
36
42
|
const result = await llmFunction(fullPrompt);
|
package/dist/prompt.d.ts
CHANGED
|
@@ -4,8 +4,9 @@ export declare const FORMAT_INSTRUCTIONS: Record<EditFormat, string>;
|
|
|
4
4
|
/**
|
|
5
5
|
* Assembles the full prompt by combining task, files context, and formatting instructions
|
|
6
6
|
*/
|
|
7
|
-
export declare function assembleFullPrompt({ filesContext, prompt, editFormat, }: {
|
|
7
|
+
export declare function assembleFullPrompt({ filesContext, prompt, editFormat, imageFiles, }: {
|
|
8
8
|
filesContext: string;
|
|
9
9
|
prompt: string;
|
|
10
10
|
editFormat?: EditFormat;
|
|
11
|
+
imageFiles?: string[];
|
|
11
12
|
}): string;
|
package/dist/prompt.js
CHANGED
|
@@ -20,11 +20,6 @@ exports.FORMAT_INSTRUCTIONS = {
|
|
|
20
20
|
"Delete all unused files, but we need to keep `README.md`. ",
|
|
21
21
|
"Files can be deleted by setting their content to empty, for example:\n\n",
|
|
22
22
|
"**fileToDelete.js**\n\n```\n```\n\n",
|
|
23
|
-
"For D3 logic, make sure it remains idempotent (use data joins), ",
|
|
24
|
-
"and prefer function signatures like `someFunction(selection, options)` ",
|
|
25
|
-
"where `selection` is a D3 selection and `options` is an object. ",
|
|
26
|
-
'Only import from the top-level `"d3"` module, not from submodules ',
|
|
27
|
-
'(e.g. imports from `"d3-scale"` or `"d3-shape"` are not supported).\n\n',
|
|
28
23
|
].join(""),
|
|
29
24
|
diff: [
|
|
30
25
|
"## Formatting Instructions\n\n",
|
|
@@ -65,7 +60,14 @@ exports.FORMAT_INSTRUCTIONS = {
|
|
|
65
60
|
/**
|
|
66
61
|
* Assembles the full prompt by combining task, files context, and formatting instructions
|
|
67
62
|
*/
|
|
68
|
-
function assembleFullPrompt({ filesContext, prompt, editFormat = "whole", }) {
|
|
63
|
+
function assembleFullPrompt({ filesContext, prompt, editFormat = "whole", imageFiles = [], }) {
|
|
69
64
|
const FORMAT = exports.FORMAT_INSTRUCTIONS[editFormat];
|
|
70
|
-
|
|
65
|
+
// Add image files list if there are any
|
|
66
|
+
let imageFilesSection = "";
|
|
67
|
+
if (imageFiles.length > 0) {
|
|
68
|
+
imageFilesSection =
|
|
69
|
+
"\nImage files available:\n\n" +
|
|
70
|
+
imageFiles.map((fileName) => ` * \`${fileName}\``).join("\n");
|
|
71
|
+
}
|
|
72
|
+
return [TASK(prompt), FILES(filesContext), FORMAT + imageFilesSection].join("\n\n");
|
|
71
73
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "editcodewithai",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Edit Code With AI",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -40,22 +40,22 @@
|
|
|
40
40
|
},
|
|
41
41
|
"homepage": "https://github.com/vizhub-core/editcodewithai#readme",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@vizhub/viz-types": "^0.
|
|
44
|
-
"@vizhub/viz-utils": "^1.
|
|
45
|
-
"dotenv": "^17.2.
|
|
43
|
+
"@vizhub/viz-types": "^0.5.0",
|
|
44
|
+
"@vizhub/viz-utils": "^1.5.0",
|
|
45
|
+
"dotenv": "^17.2.2",
|
|
46
46
|
"llm-code-format": "^3.0.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@langchain/core": "^0.3.
|
|
50
|
-
"@langchain/openai": "^0.6.
|
|
51
|
-
"langchain": "^0.3.
|
|
49
|
+
"@langchain/core": "^0.3.73",
|
|
50
|
+
"@langchain/openai": "^0.6.11",
|
|
51
|
+
"langchain": "^0.3.32",
|
|
52
52
|
"cors": "^2.8.5",
|
|
53
53
|
"express": "^5.1.0",
|
|
54
|
-
"npm-check-updates": "^18.0.
|
|
54
|
+
"npm-check-updates": "^18.0.3",
|
|
55
55
|
"prettier": "^3.6.2",
|
|
56
|
-
"puppeteer": "^24.
|
|
56
|
+
"puppeteer": "^24.19.0",
|
|
57
57
|
"ts-node": "^10.9.2",
|
|
58
|
-
"typescript": "^5.
|
|
58
|
+
"typescript": "^5.9.2",
|
|
59
59
|
"vitest": "^3.2.4"
|
|
60
60
|
}
|
|
61
61
|
}
|