@lvce-editor/chat-tool-worker 9.9.0 → 9.11.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/chatToolWorkerMain.js +242 -22
- package/package.json +1 -1
|
@@ -1208,18 +1208,21 @@ const {
|
|
|
1208
1208
|
} = create(TerminalProcess);
|
|
1209
1209
|
|
|
1210
1210
|
const INVALID_URI_ERROR_CODE = 'E_INVALID_URI';
|
|
1211
|
+
|
|
1211
1212
|
const getInvalidUriErrorPayload = argumentName => {
|
|
1212
1213
|
return {
|
|
1213
1214
|
error: `Invalid argument: ${argumentName} must be an absolute URI.`,
|
|
1214
1215
|
errorCode: INVALID_URI_ERROR_CODE
|
|
1215
1216
|
};
|
|
1216
1217
|
};
|
|
1218
|
+
|
|
1217
1219
|
const getInvalidUrlErrorPayload = () => {
|
|
1218
1220
|
return {
|
|
1219
1221
|
error: 'Invalid argument: invalid URL.',
|
|
1220
1222
|
errorCode: INVALID_URI_ERROR_CODE
|
|
1221
1223
|
};
|
|
1222
1224
|
};
|
|
1225
|
+
|
|
1223
1226
|
const getToolErrorPayload = error => {
|
|
1224
1227
|
const rawCode = error && typeof error === 'object' ? Reflect.get(error, 'code') : undefined;
|
|
1225
1228
|
const rawStack = error && typeof error === 'object' ? Reflect.get(error, 'stack') : undefined;
|
|
@@ -1538,7 +1541,7 @@ const normalizePattern = pattern => {
|
|
|
1538
1541
|
matchDirectories
|
|
1539
1542
|
};
|
|
1540
1543
|
};
|
|
1541
|
-
const joinUri = (baseUri, path) => {
|
|
1544
|
+
const joinUri$1 = (baseUri, path) => {
|
|
1542
1545
|
if (!path) {
|
|
1543
1546
|
return baseUri;
|
|
1544
1547
|
}
|
|
@@ -1572,13 +1575,13 @@ const getBaseUriError = args => {
|
|
|
1572
1575
|
return undefined;
|
|
1573
1576
|
};
|
|
1574
1577
|
const getDirectoryMatches = async (baseUri, globPart) => {
|
|
1575
|
-
const dirUri = joinUri(baseUri, globPart);
|
|
1578
|
+
const dirUri = joinUri$1(baseUri, globPart);
|
|
1576
1579
|
const entries = await readDirWithFileTypes(dirUri);
|
|
1577
1580
|
return entries.map(entry => globPart ? `${globPart}/${entry.name}` : entry.name);
|
|
1578
1581
|
};
|
|
1579
1582
|
const getRecursiveMatches = async (baseUri, baseDir, normalizedPattern) => {
|
|
1580
1583
|
const matches = [];
|
|
1581
|
-
const baseDirUri = joinUri(baseUri, baseDir);
|
|
1584
|
+
const baseDirUri = joinUri$1(baseUri, baseDir);
|
|
1582
1585
|
await traverseDirectory(baseDirUri, '', async (relativePath, entry) => {
|
|
1583
1586
|
if (entry.type !== File) {
|
|
1584
1587
|
return;
|
|
@@ -1591,7 +1594,7 @@ const getRecursiveMatches = async (baseUri, baseDir, normalizedPattern) => {
|
|
|
1591
1594
|
return matches;
|
|
1592
1595
|
};
|
|
1593
1596
|
const getDirectMatches = async (baseUri, baseDir, normalizedPattern) => {
|
|
1594
|
-
const dirUri = joinUri(baseUri, baseDir);
|
|
1597
|
+
const dirUri = joinUri$1(baseUri, baseDir);
|
|
1595
1598
|
const entries = await readDirWithFileTypes(dirUri);
|
|
1596
1599
|
const matches = [];
|
|
1597
1600
|
for (const entry of entries) {
|
|
@@ -2199,6 +2202,152 @@ const executeRunInTerminalTool = async (args, _options) => {
|
|
|
2199
2202
|
}
|
|
2200
2203
|
};
|
|
2201
2204
|
|
|
2205
|
+
const WORD_CHARACTER_REGEX = /\w/;
|
|
2206
|
+
const isWholeWordMatch = (text, startIndex, matchLength) => {
|
|
2207
|
+
const beforeChar = startIndex > 0 ? text[startIndex - 1] : ' ';
|
|
2208
|
+
const afterChar = startIndex + matchLength < text.length ? text[startIndex + matchLength] : ' ';
|
|
2209
|
+
return !WORD_CHARACTER_REGEX.test(beforeChar) && !WORD_CHARACTER_REGEX.test(afterChar);
|
|
2210
|
+
};
|
|
2211
|
+
const createSearchResult = (uri, lineNumber, column, text) => {
|
|
2212
|
+
return {
|
|
2213
|
+
column,
|
|
2214
|
+
line: lineNumber,
|
|
2215
|
+
text,
|
|
2216
|
+
uri
|
|
2217
|
+
};
|
|
2218
|
+
};
|
|
2219
|
+
const searchPlainText = (text, uri, options) => {
|
|
2220
|
+
const results = [];
|
|
2221
|
+
const lines = text.split('\n');
|
|
2222
|
+
const needle = options.matchCase ? options.value : options.value.toLowerCase();
|
|
2223
|
+
if (needle === '') {
|
|
2224
|
+
return results;
|
|
2225
|
+
}
|
|
2226
|
+
for (let lineNumber = 0; lineNumber < lines.length; lineNumber++) {
|
|
2227
|
+
const lineText = lines[lineNumber];
|
|
2228
|
+
const searchLineText = options.matchCase ? lineText : lineText.toLowerCase();
|
|
2229
|
+
let searchStartIndex = 0;
|
|
2230
|
+
while (searchStartIndex <= searchLineText.length) {
|
|
2231
|
+
const matchIndex = searchLineText.indexOf(needle, searchStartIndex);
|
|
2232
|
+
if (matchIndex === -1) {
|
|
2233
|
+
break;
|
|
2234
|
+
}
|
|
2235
|
+
if (!options.matchWholeWord || isWholeWordMatch(lineText, matchIndex, needle.length)) {
|
|
2236
|
+
results.push(createSearchResult(uri, lineNumber + 1, matchIndex + 1, lineText));
|
|
2237
|
+
}
|
|
2238
|
+
searchStartIndex = matchIndex + needle.length;
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
return results;
|
|
2242
|
+
};
|
|
2243
|
+
const searchRegExp = (text, uri, options) => {
|
|
2244
|
+
const results = [];
|
|
2245
|
+
const lines = text.split('\n');
|
|
2246
|
+
const flags = options.matchCase ? 'g' : 'gi';
|
|
2247
|
+
const regex = new RegExp(options.value, flags);
|
|
2248
|
+
for (let lineNumber = 0; lineNumber < lines.length; lineNumber++) {
|
|
2249
|
+
const lineText = lines[lineNumber];
|
|
2250
|
+
regex.lastIndex = 0;
|
|
2251
|
+
let match;
|
|
2252
|
+
while ((match = regex.exec(lineText)) !== null) {
|
|
2253
|
+
const matchedText = match[0];
|
|
2254
|
+
if (matchedText !== '' && (!options.matchWholeWord || isWholeWordMatch(lineText, match.index, matchedText.length))) {
|
|
2255
|
+
results.push(createSearchResult(uri, lineNumber + 1, match.index + 1, lineText));
|
|
2256
|
+
}
|
|
2257
|
+
if (matchedText === '') {
|
|
2258
|
+
regex.lastIndex++;
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
}
|
|
2262
|
+
return results;
|
|
2263
|
+
};
|
|
2264
|
+
const searchInText = (text, uri, options) => {
|
|
2265
|
+
if (options.isRegex) {
|
|
2266
|
+
return searchRegExp(text, uri, options);
|
|
2267
|
+
}
|
|
2268
|
+
return searchPlainText(text, uri, options);
|
|
2269
|
+
};
|
|
2270
|
+
|
|
2271
|
+
const joinUri = (baseUri, path) => {
|
|
2272
|
+
if (!path) {
|
|
2273
|
+
return baseUri;
|
|
2274
|
+
}
|
|
2275
|
+
return baseUri.endsWith('/') ? `${baseUri}${path}` : `${baseUri}/${path}`;
|
|
2276
|
+
};
|
|
2277
|
+
const isExcludedPath = (path, exclude) => {
|
|
2278
|
+
return exclude.some(pattern => matchesGlobPattern(path, pattern));
|
|
2279
|
+
};
|
|
2280
|
+
const readDirEntries = async (uri, relativePath) => {
|
|
2281
|
+
try {
|
|
2282
|
+
return await readDirWithFileTypes(uri);
|
|
2283
|
+
} catch (error) {
|
|
2284
|
+
if (relativePath === '') {
|
|
2285
|
+
throw error;
|
|
2286
|
+
}
|
|
2287
|
+
return undefined;
|
|
2288
|
+
}
|
|
2289
|
+
};
|
|
2290
|
+
const searchFileContents = async (entryUri, searchOptions) => {
|
|
2291
|
+
try {
|
|
2292
|
+
const content = await readFile$1(entryUri);
|
|
2293
|
+
return searchInText(content, entryUri, searchOptions);
|
|
2294
|
+
} catch {
|
|
2295
|
+
// Ignore unreadable files and continue with remaining matches.
|
|
2296
|
+
return [];
|
|
2297
|
+
}
|
|
2298
|
+
};
|
|
2299
|
+
const visitDirEntry = async (uri, relativePath, dirent, searchOptions, visit) => {
|
|
2300
|
+
const entryPath = relativePath ? `${relativePath}/${dirent.name}` : dirent.name;
|
|
2301
|
+
if (isExcludedPath(entryPath, searchOptions.exclude)) {
|
|
2302
|
+
return [];
|
|
2303
|
+
}
|
|
2304
|
+
const entryUri = joinUri(uri, dirent.name);
|
|
2305
|
+
if (dirent.type === Directory) {
|
|
2306
|
+
if (!shouldExcludeDir(dirent.name)) {
|
|
2307
|
+
await visit(entryUri, entryPath);
|
|
2308
|
+
}
|
|
2309
|
+
return [];
|
|
2310
|
+
}
|
|
2311
|
+
if (dirent.type === File) {
|
|
2312
|
+
return searchFileContents(entryUri, searchOptions);
|
|
2313
|
+
}
|
|
2314
|
+
return [];
|
|
2315
|
+
};
|
|
2316
|
+
const sortSearchResults = results => {
|
|
2317
|
+
return results.toSorted((left, right) => {
|
|
2318
|
+
const uriComparison = left.uri.localeCompare(right.uri);
|
|
2319
|
+
if (uriComparison !== 0) {
|
|
2320
|
+
return uriComparison;
|
|
2321
|
+
}
|
|
2322
|
+
if (left.line !== right.line) {
|
|
2323
|
+
return left.line - right.line;
|
|
2324
|
+
}
|
|
2325
|
+
if (left.column !== right.column) {
|
|
2326
|
+
return left.column - right.column;
|
|
2327
|
+
}
|
|
2328
|
+
return left.text.localeCompare(right.text);
|
|
2329
|
+
});
|
|
2330
|
+
};
|
|
2331
|
+
const searchTextManual = async (workspaceUri, searchOptions) => {
|
|
2332
|
+
const results = [];
|
|
2333
|
+
const visited = new Set();
|
|
2334
|
+
const visit = async (uri, relativePath) => {
|
|
2335
|
+
if (visited.has(uri)) {
|
|
2336
|
+
return;
|
|
2337
|
+
}
|
|
2338
|
+
visited.add(uri);
|
|
2339
|
+
const dirents = await readDirEntries(uri, relativePath);
|
|
2340
|
+
if (!dirents) {
|
|
2341
|
+
return;
|
|
2342
|
+
}
|
|
2343
|
+
for (const dirent of dirents) {
|
|
2344
|
+
results.push(...(await visitDirEntry(uri, relativePath, dirent, searchOptions, visit)));
|
|
2345
|
+
}
|
|
2346
|
+
};
|
|
2347
|
+
await visit(workspaceUri, '');
|
|
2348
|
+
return sortSearchResults(results);
|
|
2349
|
+
};
|
|
2350
|
+
|
|
2202
2351
|
const getSearchOptions = args => {
|
|
2203
2352
|
const {
|
|
2204
2353
|
options
|
|
@@ -2228,6 +2377,17 @@ const getSearchOptions = args => {
|
|
|
2228
2377
|
value
|
|
2229
2378
|
};
|
|
2230
2379
|
};
|
|
2380
|
+
const validateRegex = searchOptions => {
|
|
2381
|
+
if (!searchOptions.isRegex) {
|
|
2382
|
+
return undefined;
|
|
2383
|
+
}
|
|
2384
|
+
try {
|
|
2385
|
+
new RegExp(searchOptions.value);
|
|
2386
|
+
return undefined;
|
|
2387
|
+
} catch {
|
|
2388
|
+
return 'Invalid argument: options.value must be a valid regular expression.';
|
|
2389
|
+
}
|
|
2390
|
+
};
|
|
2231
2391
|
const executeSearchTextTool = async (args, _options) => {
|
|
2232
2392
|
const searchOptions = getSearchOptions(args);
|
|
2233
2393
|
if (!searchOptions) {
|
|
@@ -2235,21 +2395,21 @@ const executeSearchTextTool = async (args, _options) => {
|
|
|
2235
2395
|
error: 'Invalid argument: options must include value (string), isRegex (boolean), matchCase (boolean), matchWholeWord (boolean), and exclude (string[]).'
|
|
2236
2396
|
};
|
|
2237
2397
|
}
|
|
2238
|
-
const
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
}
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
}
|
|
2398
|
+
const regexError = validateRegex(searchOptions);
|
|
2399
|
+
if (regexError) {
|
|
2400
|
+
return {
|
|
2401
|
+
error: regexError
|
|
2402
|
+
};
|
|
2403
|
+
}
|
|
2404
|
+
try {
|
|
2405
|
+
const workspaceUri = await getWorkspacePath();
|
|
2406
|
+
const results = await searchTextManual(workspaceUri, searchOptions);
|
|
2407
|
+
return {
|
|
2408
|
+
results
|
|
2409
|
+
};
|
|
2410
|
+
} catch (error) {
|
|
2411
|
+
return getToolErrorPayload(error);
|
|
2412
|
+
}
|
|
2253
2413
|
};
|
|
2254
2414
|
|
|
2255
2415
|
const placeholderResponse = 'Hello From Sub agent - not yet implemented';
|
|
@@ -2400,10 +2560,67 @@ const getLineDiffStats = (beforeContent, afterContent) => {
|
|
|
2400
2560
|
};
|
|
2401
2561
|
};
|
|
2402
2562
|
|
|
2563
|
+
const validateWriteFileToolArgs = args => {
|
|
2564
|
+
if (!args || typeof args !== 'object') {
|
|
2565
|
+
return {
|
|
2566
|
+
ok: false,
|
|
2567
|
+
response: {
|
|
2568
|
+
error: 'Invalid argument: args must be an object.'
|
|
2569
|
+
}
|
|
2570
|
+
};
|
|
2571
|
+
}
|
|
2572
|
+
if (!('uri' in args)) {
|
|
2573
|
+
return {
|
|
2574
|
+
ok: false,
|
|
2575
|
+
response: {
|
|
2576
|
+
error: 'Missing required argument: uri'
|
|
2577
|
+
}
|
|
2578
|
+
};
|
|
2579
|
+
}
|
|
2580
|
+
if (!('content' in args)) {
|
|
2581
|
+
return {
|
|
2582
|
+
ok: false,
|
|
2583
|
+
response: {
|
|
2584
|
+
error: 'Missing required argument: content'
|
|
2585
|
+
}
|
|
2586
|
+
};
|
|
2587
|
+
}
|
|
2588
|
+
const candidate = args;
|
|
2589
|
+
if (typeof candidate.uri !== 'string') {
|
|
2590
|
+
return {
|
|
2591
|
+
ok: false,
|
|
2592
|
+
response: {
|
|
2593
|
+
error: 'Invalid argument: uri must be a string.'
|
|
2594
|
+
}
|
|
2595
|
+
};
|
|
2596
|
+
}
|
|
2597
|
+
if (typeof candidate.content !== 'string') {
|
|
2598
|
+
return {
|
|
2599
|
+
ok: false,
|
|
2600
|
+
response: {
|
|
2601
|
+
error: 'Invalid argument: content must be a string.'
|
|
2602
|
+
}
|
|
2603
|
+
};
|
|
2604
|
+
}
|
|
2605
|
+
return {
|
|
2606
|
+
args: {
|
|
2607
|
+
content: candidate.content,
|
|
2608
|
+
uri: candidate.uri
|
|
2609
|
+
},
|
|
2610
|
+
ok: true
|
|
2611
|
+
};
|
|
2612
|
+
};
|
|
2613
|
+
|
|
2403
2614
|
const executeWriteFileTool = async (args, _options) => {
|
|
2404
|
-
const
|
|
2405
|
-
|
|
2406
|
-
|
|
2615
|
+
const validatedArgs = validateWriteFileToolArgs(args);
|
|
2616
|
+
if (!validatedArgs.ok) {
|
|
2617
|
+
return validatedArgs.response;
|
|
2618
|
+
}
|
|
2619
|
+
const {
|
|
2620
|
+
content,
|
|
2621
|
+
uri
|
|
2622
|
+
} = validatedArgs.args;
|
|
2623
|
+
if (!isAbsoluteUri(uri)) {
|
|
2407
2624
|
return getInvalidUriErrorPayload('uri');
|
|
2408
2625
|
}
|
|
2409
2626
|
if (!isValidUri(uri)) {
|
|
@@ -2432,6 +2649,9 @@ const executeWriteFileTool = async (args, _options) => {
|
|
|
2432
2649
|
};
|
|
2433
2650
|
|
|
2434
2651
|
const parseToolArguments = rawArguments => {
|
|
2652
|
+
if (typeof rawArguments !== 'string' && (!rawArguments || typeof rawArguments !== 'object')) {
|
|
2653
|
+
return {};
|
|
2654
|
+
}
|
|
2435
2655
|
if (typeof rawArguments !== 'string') {
|
|
2436
2656
|
return rawArguments;
|
|
2437
2657
|
}
|