@lvce-editor/chat-tool-worker 7.8.0 → 7.10.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 +323 -39
- package/package.json +1 -1
|
@@ -1093,6 +1093,20 @@ const executeGetWorkspaceUriTool = async (_args, _options) => {
|
|
|
1093
1093
|
}
|
|
1094
1094
|
};
|
|
1095
1095
|
|
|
1096
|
+
const executeGlobTool = async (args, _options) => {
|
|
1097
|
+
const pattern = typeof args.pattern === 'string' ? args.pattern : '';
|
|
1098
|
+
if (!pattern) {
|
|
1099
|
+
return {
|
|
1100
|
+
error: 'Invalid argument: pattern must be a non-empty string.'
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
const paths = ['./src/main.ts', './src/utils/search.ts', './test/Main.test.ts'];
|
|
1104
|
+
return {
|
|
1105
|
+
paths,
|
|
1106
|
+
pattern
|
|
1107
|
+
};
|
|
1108
|
+
};
|
|
1109
|
+
|
|
1096
1110
|
const executeListFilesTool = async (args, _options) => {
|
|
1097
1111
|
const uri = typeof args.uri === 'string' ? args.uri : '';
|
|
1098
1112
|
if (!uri || !isAbsoluteUri(uri)) {
|
|
@@ -1183,6 +1197,45 @@ const executeReadFileTool = async (args, _options) => {
|
|
|
1183
1197
|
}
|
|
1184
1198
|
};
|
|
1185
1199
|
|
|
1200
|
+
/* eslint-disable @cspell/spellchecker */
|
|
1201
|
+
/* eslint-disable e18e/prefer-url-canparse */
|
|
1202
|
+
const executeRenameTool = async (args, _options) => {
|
|
1203
|
+
const oldUri = typeof args.oldUri === 'string' ? args.oldUri : '';
|
|
1204
|
+
const newUri = typeof args.newUri === 'string' ? args.newUri : '';
|
|
1205
|
+
if (!oldUri || !isAbsoluteUri(oldUri)) {
|
|
1206
|
+
return {
|
|
1207
|
+
error: 'Invalid argument: oldUri must be an absolute URI.'
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
if (!newUri || !isAbsoluteUri(newUri)) {
|
|
1211
|
+
return {
|
|
1212
|
+
error: 'Invalid argument: newUri must be an absolute URI.'
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
try {
|
|
1216
|
+
new URL(oldUri);
|
|
1217
|
+
new URL(newUri);
|
|
1218
|
+
} catch {
|
|
1219
|
+
return {
|
|
1220
|
+
error: 'Invalid argument: invalid URL.'
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
try {
|
|
1224
|
+
await invoke('FileSystem.rename', oldUri, newUri);
|
|
1225
|
+
return {
|
|
1226
|
+
newUri,
|
|
1227
|
+
ok: true,
|
|
1228
|
+
oldUri
|
|
1229
|
+
};
|
|
1230
|
+
} catch (error) {
|
|
1231
|
+
return {
|
|
1232
|
+
...getToolErrorPayload(error),
|
|
1233
|
+
newUri,
|
|
1234
|
+
oldUri
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
};
|
|
1238
|
+
|
|
1186
1239
|
const maxPayloadLength = 40_000;
|
|
1187
1240
|
const executeRenderHtmlTool = async (args, _options) => {
|
|
1188
1241
|
const html = typeof args.html === 'string' ? args.html : '';
|
|
@@ -1206,6 +1259,51 @@ const executeRenderHtmlTool = async (args, _options) => {
|
|
|
1206
1259
|
};
|
|
1207
1260
|
};
|
|
1208
1261
|
|
|
1262
|
+
const getRgArgs = args => {
|
|
1263
|
+
const {
|
|
1264
|
+
'-n': lineNumbers,
|
|
1265
|
+
output_mode,
|
|
1266
|
+
path,
|
|
1267
|
+
pattern
|
|
1268
|
+
} = args;
|
|
1269
|
+
if (typeof pattern !== 'string') {
|
|
1270
|
+
return undefined;
|
|
1271
|
+
}
|
|
1272
|
+
if (path !== undefined && typeof path !== 'string') {
|
|
1273
|
+
return undefined;
|
|
1274
|
+
}
|
|
1275
|
+
if (output_mode !== undefined && output_mode !== 'content' && output_mode !== 'files_with_matches' && output_mode !== 'count') {
|
|
1276
|
+
return undefined;
|
|
1277
|
+
}
|
|
1278
|
+
if (lineNumbers !== undefined && typeof lineNumbers !== 'boolean') {
|
|
1279
|
+
return undefined;
|
|
1280
|
+
}
|
|
1281
|
+
return {
|
|
1282
|
+
...(lineNumbers === undefined ? {} : {
|
|
1283
|
+
'-n': lineNumbers
|
|
1284
|
+
}),
|
|
1285
|
+
...(output_mode === undefined ? {} : {
|
|
1286
|
+
output_mode
|
|
1287
|
+
}),
|
|
1288
|
+
...(path === undefined ? {} : {
|
|
1289
|
+
path
|
|
1290
|
+
}),
|
|
1291
|
+
pattern
|
|
1292
|
+
};
|
|
1293
|
+
};
|
|
1294
|
+
const executeRgTool = async (args, _options) => {
|
|
1295
|
+
const rgArgs = getRgArgs(args);
|
|
1296
|
+
if (!rgArgs) {
|
|
1297
|
+
return {
|
|
1298
|
+
error: 'Invalid argument: rg requires pattern (string), optional path (string), optional output_mode ("content" | "files_with_matches" | "count"), and optional -n (boolean).'
|
|
1299
|
+
};
|
|
1300
|
+
}
|
|
1301
|
+
return {
|
|
1302
|
+
arguments: rgArgs,
|
|
1303
|
+
result: 'No matches found.'
|
|
1304
|
+
};
|
|
1305
|
+
};
|
|
1306
|
+
|
|
1209
1307
|
const getRunInTerminalOptions = args => {
|
|
1210
1308
|
const {
|
|
1211
1309
|
options
|
|
@@ -1295,6 +1393,96 @@ const executeSearchTextTool = async (args, _options) => {
|
|
|
1295
1393
|
};
|
|
1296
1394
|
};
|
|
1297
1395
|
|
|
1396
|
+
const todoDbName = 'chat-tool-worker';
|
|
1397
|
+
const todoStoreName = 'state';
|
|
1398
|
+
const todoKey = 'todoList';
|
|
1399
|
+
const todoCacheName = 'chat-tool-worker-todo';
|
|
1400
|
+
const todoCacheRequest = new Request('https://chat-tool-worker.local/todo-list');
|
|
1401
|
+
let memoryTodoList = '';
|
|
1402
|
+
const setTodosInIndexedDb = async todos => {
|
|
1403
|
+
const db = await new Promise((resolve, reject) => {
|
|
1404
|
+
const openRequest = indexedDB.open(todoDbName, 1);
|
|
1405
|
+
openRequest.onupgradeneeded = () => {
|
|
1406
|
+
const nextDb = openRequest.result;
|
|
1407
|
+
if (!nextDb.objectStoreNames.contains(todoStoreName)) {
|
|
1408
|
+
nextDb.createObjectStore(todoStoreName);
|
|
1409
|
+
}
|
|
1410
|
+
};
|
|
1411
|
+
openRequest.onsuccess = () => {
|
|
1412
|
+
resolve(openRequest.result);
|
|
1413
|
+
};
|
|
1414
|
+
openRequest.onerror = () => {
|
|
1415
|
+
reject(openRequest.error ?? new Error('Failed to open IndexedDB'));
|
|
1416
|
+
};
|
|
1417
|
+
});
|
|
1418
|
+
await new Promise((resolve, reject) => {
|
|
1419
|
+
const transaction = db.transaction(todoStoreName, 'readwrite');
|
|
1420
|
+
transaction.objectStore(todoStoreName).put(todos, todoKey);
|
|
1421
|
+
transaction.oncomplete = () => {
|
|
1422
|
+
db.close();
|
|
1423
|
+
resolve();
|
|
1424
|
+
};
|
|
1425
|
+
transaction.onerror = () => {
|
|
1426
|
+
db.close();
|
|
1427
|
+
reject(transaction.error ?? new Error('Failed to persist todo list'));
|
|
1428
|
+
};
|
|
1429
|
+
transaction.onabort = () => {
|
|
1430
|
+
db.close();
|
|
1431
|
+
reject(transaction.error ?? new Error('Failed to persist todo list'));
|
|
1432
|
+
};
|
|
1433
|
+
});
|
|
1434
|
+
};
|
|
1435
|
+
const setTodosInCacheStorage = async todos => {
|
|
1436
|
+
const cache = await caches.open(todoCacheName);
|
|
1437
|
+
const payload = JSON.stringify({
|
|
1438
|
+
todos
|
|
1439
|
+
});
|
|
1440
|
+
await cache.put(todoCacheRequest, new Response(payload, {
|
|
1441
|
+
headers: {
|
|
1442
|
+
'content-type': 'application/json'
|
|
1443
|
+
}
|
|
1444
|
+
}));
|
|
1445
|
+
};
|
|
1446
|
+
const executeUpdateTodoTool = async (args, _options) => {
|
|
1447
|
+
const todos = typeof args.todos === 'string' ? args.todos : '';
|
|
1448
|
+
if (!todos) {
|
|
1449
|
+
return {
|
|
1450
|
+
error: 'Missing required argument: todos'
|
|
1451
|
+
};
|
|
1452
|
+
}
|
|
1453
|
+
try {
|
|
1454
|
+
if (typeof indexedDB !== 'undefined') {
|
|
1455
|
+
await setTodosInIndexedDb(todos);
|
|
1456
|
+
return {
|
|
1457
|
+
message: 'TODO list updated',
|
|
1458
|
+
ok: true,
|
|
1459
|
+
storage: 'indexeddb',
|
|
1460
|
+
todos
|
|
1461
|
+
};
|
|
1462
|
+
}
|
|
1463
|
+
if (typeof caches !== 'undefined') {
|
|
1464
|
+
await setTodosInCacheStorage(todos);
|
|
1465
|
+
return {
|
|
1466
|
+
message: 'TODO list updated',
|
|
1467
|
+
ok: true,
|
|
1468
|
+
storage: 'cache',
|
|
1469
|
+
todos
|
|
1470
|
+
};
|
|
1471
|
+
}
|
|
1472
|
+
const previousTodos = memoryTodoList;
|
|
1473
|
+
memoryTodoList = todos;
|
|
1474
|
+
return {
|
|
1475
|
+
message: 'TODO list updated',
|
|
1476
|
+
ok: true,
|
|
1477
|
+
previousTodos,
|
|
1478
|
+
storage: 'memory',
|
|
1479
|
+
todos
|
|
1480
|
+
};
|
|
1481
|
+
} catch (error) {
|
|
1482
|
+
return getToolErrorPayload(error);
|
|
1483
|
+
}
|
|
1484
|
+
};
|
|
1485
|
+
|
|
1298
1486
|
const executeWriteFileTool = async (args, _options) => {
|
|
1299
1487
|
const uri = typeof args.uri === 'string' ? args.uri : '';
|
|
1300
1488
|
const content = typeof args.content === 'string' ? args.content : '';
|
|
@@ -1341,45 +1529,44 @@ const parseToolArguments = rawArguments => {
|
|
|
1341
1529
|
|
|
1342
1530
|
const executeChatTool = async (name, rawArguments, options) => {
|
|
1343
1531
|
const args = parseToolArguments(rawArguments);
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1532
|
+
switch (name) {
|
|
1533
|
+
case 'close_preview':
|
|
1534
|
+
return executeClosePreviewTool();
|
|
1535
|
+
case 'create_directory':
|
|
1536
|
+
return executeCreateDirectoryTool(args);
|
|
1537
|
+
case 'edit_file':
|
|
1538
|
+
return executeEditFileTool(args);
|
|
1539
|
+
case 'getWorkspaceUri':
|
|
1540
|
+
return executeGetWorkspaceUriTool();
|
|
1541
|
+
case 'glob':
|
|
1542
|
+
return executeGlobTool(args);
|
|
1543
|
+
case 'list_files':
|
|
1544
|
+
return executeListFilesTool(args);
|
|
1545
|
+
case 'open_preview':
|
|
1546
|
+
return executeOpenPreviewTool(args);
|
|
1547
|
+
case 'openEditor':
|
|
1548
|
+
return executeOpenEditorTool(args);
|
|
1549
|
+
case 'read_file':
|
|
1550
|
+
return executeReadFileTool(args);
|
|
1551
|
+
case 'rename':
|
|
1552
|
+
return executeRenameTool(args);
|
|
1553
|
+
case 'render_html':
|
|
1554
|
+
return executeRenderHtmlTool(args);
|
|
1555
|
+
case 'rg':
|
|
1556
|
+
return executeRgTool(args);
|
|
1557
|
+
case 'run_in_terminal':
|
|
1558
|
+
return executeRunInTerminalTool(args);
|
|
1559
|
+
case 'search_text':
|
|
1560
|
+
return executeSearchTextTool(args);
|
|
1561
|
+
case 'update_todo':
|
|
1562
|
+
return executeUpdateTodoTool(args);
|
|
1563
|
+
case 'write_file':
|
|
1564
|
+
return executeWriteFileTool(args);
|
|
1565
|
+
default:
|
|
1566
|
+
return {
|
|
1567
|
+
error: `Unknown tool: ${name}`
|
|
1568
|
+
};
|
|
1379
1569
|
}
|
|
1380
|
-
return {
|
|
1381
|
-
error: `Unknown tool: ${name}`
|
|
1382
|
-
};
|
|
1383
1570
|
};
|
|
1384
1571
|
|
|
1385
1572
|
const getReadFileTool = () => {
|
|
@@ -1426,6 +1613,30 @@ const getWriteFileTool = () => {
|
|
|
1426
1613
|
type: 'function'
|
|
1427
1614
|
};
|
|
1428
1615
|
};
|
|
1616
|
+
const getRenameTool = () => {
|
|
1617
|
+
return {
|
|
1618
|
+
function: {
|
|
1619
|
+
description: 'Rename or move a file or folder from one absolute URI to another absolute URI (for example `file://...`, `memfs://...`, or extension-provided file system URIs).',
|
|
1620
|
+
name: 'rename',
|
|
1621
|
+
parameters: {
|
|
1622
|
+
additionalProperties: false,
|
|
1623
|
+
properties: {
|
|
1624
|
+
newUri: {
|
|
1625
|
+
description: 'Absolute target URI for the file or folder after renaming.',
|
|
1626
|
+
type: 'string'
|
|
1627
|
+
},
|
|
1628
|
+
oldUri: {
|
|
1629
|
+
description: 'Absolute source URI for the existing file or folder to rename.',
|
|
1630
|
+
type: 'string'
|
|
1631
|
+
}
|
|
1632
|
+
},
|
|
1633
|
+
required: ['oldUri', 'newUri'],
|
|
1634
|
+
type: 'object'
|
|
1635
|
+
}
|
|
1636
|
+
},
|
|
1637
|
+
type: 'function'
|
|
1638
|
+
};
|
|
1639
|
+
};
|
|
1429
1640
|
const getEditFileTool = () => {
|
|
1430
1641
|
return {
|
|
1431
1642
|
function: {
|
|
@@ -1615,6 +1826,39 @@ const getSearchTextTool = () => {
|
|
|
1615
1826
|
type: 'function'
|
|
1616
1827
|
};
|
|
1617
1828
|
};
|
|
1829
|
+
const getRgTool = () => {
|
|
1830
|
+
return {
|
|
1831
|
+
function: {
|
|
1832
|
+
description: 'Search text or regex in workspace files using ripgrep-style arguments and return matching results.',
|
|
1833
|
+
name: 'rg',
|
|
1834
|
+
parameters: {
|
|
1835
|
+
additionalProperties: false,
|
|
1836
|
+
properties: {
|
|
1837
|
+
'-n': {
|
|
1838
|
+
description: 'When true, include line numbers in the output.',
|
|
1839
|
+
type: 'boolean'
|
|
1840
|
+
},
|
|
1841
|
+
output_mode: {
|
|
1842
|
+
description: 'Result format to return.',
|
|
1843
|
+
enum: ['content', 'files_with_matches', 'count'],
|
|
1844
|
+
type: 'string'
|
|
1845
|
+
},
|
|
1846
|
+
path: {
|
|
1847
|
+
description: 'Optional file or directory path inside the current workspace to scope the search.',
|
|
1848
|
+
type: 'string'
|
|
1849
|
+
},
|
|
1850
|
+
pattern: {
|
|
1851
|
+
description: 'Text or regular expression pattern to search for.',
|
|
1852
|
+
type: 'string'
|
|
1853
|
+
}
|
|
1854
|
+
},
|
|
1855
|
+
required: ['pattern'],
|
|
1856
|
+
type: 'object'
|
|
1857
|
+
}
|
|
1858
|
+
},
|
|
1859
|
+
type: 'function'
|
|
1860
|
+
};
|
|
1861
|
+
};
|
|
1618
1862
|
const getRunInTerminalTool = () => {
|
|
1619
1863
|
return {
|
|
1620
1864
|
function: {
|
|
@@ -1664,8 +1908,48 @@ const getCreateDirectoryTool = () => {
|
|
|
1664
1908
|
type: 'function'
|
|
1665
1909
|
};
|
|
1666
1910
|
};
|
|
1911
|
+
const getGlobTool = () => {
|
|
1912
|
+
return {
|
|
1913
|
+
function: {
|
|
1914
|
+
description: 'Find files by glob pattern and return matching relative paths.',
|
|
1915
|
+
name: 'glob',
|
|
1916
|
+
parameters: {
|
|
1917
|
+
additionalProperties: false,
|
|
1918
|
+
properties: {
|
|
1919
|
+
pattern: {
|
|
1920
|
+
description: 'Glob pattern to match files, for example `packages/e2e/src/*.ts`.',
|
|
1921
|
+
type: 'string'
|
|
1922
|
+
}
|
|
1923
|
+
},
|
|
1924
|
+
required: ['pattern'],
|
|
1925
|
+
type: 'object'
|
|
1926
|
+
}
|
|
1927
|
+
},
|
|
1928
|
+
type: 'function'
|
|
1929
|
+
};
|
|
1930
|
+
};
|
|
1931
|
+
const getUpdateTodoTool = () => {
|
|
1932
|
+
return {
|
|
1933
|
+
function: {
|
|
1934
|
+
description: 'Update the active TODO checklist for the current chat session. Pass the full markdown checklist text with one item per line (for example "- [ ] Step one").',
|
|
1935
|
+
name: 'update_todo',
|
|
1936
|
+
parameters: {
|
|
1937
|
+
additionalProperties: false,
|
|
1938
|
+
properties: {
|
|
1939
|
+
todos: {
|
|
1940
|
+
description: 'Complete markdown checklist content to store as the current TODO list state.',
|
|
1941
|
+
type: 'string'
|
|
1942
|
+
}
|
|
1943
|
+
},
|
|
1944
|
+
required: ['todos'],
|
|
1945
|
+
type: 'object'
|
|
1946
|
+
}
|
|
1947
|
+
},
|
|
1948
|
+
type: 'function'
|
|
1949
|
+
};
|
|
1950
|
+
};
|
|
1667
1951
|
const getBasicChatTools = () => {
|
|
1668
|
-
return [getReadFileTool(), getWriteFileTool(), getEditFileTool(), getListFilesTool(), getGetWorkspaceUriTool(), getRenderHtmlTool(), getOpenPreviewTool(), getOpenEditorTool(), getClosePreviewTool(), getSearchTextTool(), getRunInTerminalTool(), getCreateDirectoryTool()];
|
|
1952
|
+
return [getReadFileTool(), getWriteFileTool(), getRenameTool(), getEditFileTool(), getListFilesTool(), getGetWorkspaceUriTool(), getRenderHtmlTool(), getOpenPreviewTool(), getOpenEditorTool(), getClosePreviewTool(), getSearchTextTool(), getRgTool(), getRunInTerminalTool(), getCreateDirectoryTool(), getGlobTool(), getUpdateTodoTool()];
|
|
1669
1953
|
};
|
|
1670
1954
|
|
|
1671
1955
|
const handleMessagePort = async port => {
|