@lvce-editor/chat-tool-worker 7.8.0 → 7.9.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 +261 -1
- package/package.json +1 -1
|
@@ -1183,6 +1183,45 @@ const executeReadFileTool = async (args, _options) => {
|
|
|
1183
1183
|
}
|
|
1184
1184
|
};
|
|
1185
1185
|
|
|
1186
|
+
/* eslint-disable @cspell/spellchecker */
|
|
1187
|
+
/* eslint-disable e18e/prefer-url-canparse */
|
|
1188
|
+
const executeRenameTool = async (args, _options) => {
|
|
1189
|
+
const oldUri = typeof args.oldUri === 'string' ? args.oldUri : '';
|
|
1190
|
+
const newUri = typeof args.newUri === 'string' ? args.newUri : '';
|
|
1191
|
+
if (!oldUri || !isAbsoluteUri(oldUri)) {
|
|
1192
|
+
return {
|
|
1193
|
+
error: 'Invalid argument: oldUri must be an absolute URI.'
|
|
1194
|
+
};
|
|
1195
|
+
}
|
|
1196
|
+
if (!newUri || !isAbsoluteUri(newUri)) {
|
|
1197
|
+
return {
|
|
1198
|
+
error: 'Invalid argument: newUri must be an absolute URI.'
|
|
1199
|
+
};
|
|
1200
|
+
}
|
|
1201
|
+
try {
|
|
1202
|
+
new URL(oldUri);
|
|
1203
|
+
new URL(newUri);
|
|
1204
|
+
} catch {
|
|
1205
|
+
return {
|
|
1206
|
+
error: 'Invalid argument: invalid URL.'
|
|
1207
|
+
};
|
|
1208
|
+
}
|
|
1209
|
+
try {
|
|
1210
|
+
await invoke('FileSystem.rename', oldUri, newUri);
|
|
1211
|
+
return {
|
|
1212
|
+
newUri,
|
|
1213
|
+
ok: true,
|
|
1214
|
+
oldUri
|
|
1215
|
+
};
|
|
1216
|
+
} catch (error) {
|
|
1217
|
+
return {
|
|
1218
|
+
...getToolErrorPayload(error),
|
|
1219
|
+
newUri,
|
|
1220
|
+
oldUri
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
};
|
|
1224
|
+
|
|
1186
1225
|
const maxPayloadLength = 40_000;
|
|
1187
1226
|
const executeRenderHtmlTool = async (args, _options) => {
|
|
1188
1227
|
const html = typeof args.html === 'string' ? args.html : '';
|
|
@@ -1206,6 +1245,51 @@ const executeRenderHtmlTool = async (args, _options) => {
|
|
|
1206
1245
|
};
|
|
1207
1246
|
};
|
|
1208
1247
|
|
|
1248
|
+
const getRgArgs = args => {
|
|
1249
|
+
const {
|
|
1250
|
+
'-n': lineNumbers,
|
|
1251
|
+
output_mode,
|
|
1252
|
+
path,
|
|
1253
|
+
pattern
|
|
1254
|
+
} = args;
|
|
1255
|
+
if (typeof pattern !== 'string') {
|
|
1256
|
+
return undefined;
|
|
1257
|
+
}
|
|
1258
|
+
if (path !== undefined && typeof path !== 'string') {
|
|
1259
|
+
return undefined;
|
|
1260
|
+
}
|
|
1261
|
+
if (output_mode !== undefined && output_mode !== 'content' && output_mode !== 'files_with_matches' && output_mode !== 'count') {
|
|
1262
|
+
return undefined;
|
|
1263
|
+
}
|
|
1264
|
+
if (lineNumbers !== undefined && typeof lineNumbers !== 'boolean') {
|
|
1265
|
+
return undefined;
|
|
1266
|
+
}
|
|
1267
|
+
return {
|
|
1268
|
+
...(lineNumbers === undefined ? {} : {
|
|
1269
|
+
'-n': lineNumbers
|
|
1270
|
+
}),
|
|
1271
|
+
...(output_mode === undefined ? {} : {
|
|
1272
|
+
output_mode
|
|
1273
|
+
}),
|
|
1274
|
+
...(path === undefined ? {} : {
|
|
1275
|
+
path
|
|
1276
|
+
}),
|
|
1277
|
+
pattern
|
|
1278
|
+
};
|
|
1279
|
+
};
|
|
1280
|
+
const executeRgTool = async (args, _options) => {
|
|
1281
|
+
const rgArgs = getRgArgs(args);
|
|
1282
|
+
if (!rgArgs) {
|
|
1283
|
+
return {
|
|
1284
|
+
error: 'Invalid argument: rg requires pattern (string), optional path (string), optional output_mode ("content" | "files_with_matches" | "count"), and optional -n (boolean).'
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1287
|
+
return {
|
|
1288
|
+
arguments: rgArgs,
|
|
1289
|
+
result: 'No matches found.'
|
|
1290
|
+
};
|
|
1291
|
+
};
|
|
1292
|
+
|
|
1209
1293
|
const getRunInTerminalOptions = args => {
|
|
1210
1294
|
const {
|
|
1211
1295
|
options
|
|
@@ -1295,6 +1379,96 @@ const executeSearchTextTool = async (args, _options) => {
|
|
|
1295
1379
|
};
|
|
1296
1380
|
};
|
|
1297
1381
|
|
|
1382
|
+
const todoDbName = 'chat-tool-worker';
|
|
1383
|
+
const todoStoreName = 'state';
|
|
1384
|
+
const todoKey = 'todoList';
|
|
1385
|
+
const todoCacheName = 'chat-tool-worker-todo';
|
|
1386
|
+
const todoCacheRequest = new Request('https://chat-tool-worker.local/todo-list');
|
|
1387
|
+
let memoryTodoList = '';
|
|
1388
|
+
const setTodosInIndexedDb = async todos => {
|
|
1389
|
+
const db = await new Promise((resolve, reject) => {
|
|
1390
|
+
const openRequest = indexedDB.open(todoDbName, 1);
|
|
1391
|
+
openRequest.onupgradeneeded = () => {
|
|
1392
|
+
const nextDb = openRequest.result;
|
|
1393
|
+
if (!nextDb.objectStoreNames.contains(todoStoreName)) {
|
|
1394
|
+
nextDb.createObjectStore(todoStoreName);
|
|
1395
|
+
}
|
|
1396
|
+
};
|
|
1397
|
+
openRequest.onsuccess = () => {
|
|
1398
|
+
resolve(openRequest.result);
|
|
1399
|
+
};
|
|
1400
|
+
openRequest.onerror = () => {
|
|
1401
|
+
reject(openRequest.error ?? new Error('Failed to open IndexedDB'));
|
|
1402
|
+
};
|
|
1403
|
+
});
|
|
1404
|
+
await new Promise((resolve, reject) => {
|
|
1405
|
+
const transaction = db.transaction(todoStoreName, 'readwrite');
|
|
1406
|
+
transaction.objectStore(todoStoreName).put(todos, todoKey);
|
|
1407
|
+
transaction.oncomplete = () => {
|
|
1408
|
+
db.close();
|
|
1409
|
+
resolve();
|
|
1410
|
+
};
|
|
1411
|
+
transaction.onerror = () => {
|
|
1412
|
+
db.close();
|
|
1413
|
+
reject(transaction.error ?? new Error('Failed to persist todo list'));
|
|
1414
|
+
};
|
|
1415
|
+
transaction.onabort = () => {
|
|
1416
|
+
db.close();
|
|
1417
|
+
reject(transaction.error ?? new Error('Failed to persist todo list'));
|
|
1418
|
+
};
|
|
1419
|
+
});
|
|
1420
|
+
};
|
|
1421
|
+
const setTodosInCacheStorage = async todos => {
|
|
1422
|
+
const cache = await caches.open(todoCacheName);
|
|
1423
|
+
const payload = JSON.stringify({
|
|
1424
|
+
todos
|
|
1425
|
+
});
|
|
1426
|
+
await cache.put(todoCacheRequest, new Response(payload, {
|
|
1427
|
+
headers: {
|
|
1428
|
+
'content-type': 'application/json'
|
|
1429
|
+
}
|
|
1430
|
+
}));
|
|
1431
|
+
};
|
|
1432
|
+
const executeUpdateTodoTool = async (args, _options) => {
|
|
1433
|
+
const todos = typeof args.todos === 'string' ? args.todos : '';
|
|
1434
|
+
if (!todos) {
|
|
1435
|
+
return {
|
|
1436
|
+
error: 'Missing required argument: todos'
|
|
1437
|
+
};
|
|
1438
|
+
}
|
|
1439
|
+
try {
|
|
1440
|
+
if (typeof indexedDB !== 'undefined') {
|
|
1441
|
+
await setTodosInIndexedDb(todos);
|
|
1442
|
+
return {
|
|
1443
|
+
message: 'TODO list updated',
|
|
1444
|
+
ok: true,
|
|
1445
|
+
storage: 'indexeddb',
|
|
1446
|
+
todos
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
if (typeof caches !== 'undefined') {
|
|
1450
|
+
await setTodosInCacheStorage(todos);
|
|
1451
|
+
return {
|
|
1452
|
+
message: 'TODO list updated',
|
|
1453
|
+
ok: true,
|
|
1454
|
+
storage: 'cache',
|
|
1455
|
+
todos
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1458
|
+
const previousTodos = memoryTodoList;
|
|
1459
|
+
memoryTodoList = todos;
|
|
1460
|
+
return {
|
|
1461
|
+
message: 'TODO list updated',
|
|
1462
|
+
ok: true,
|
|
1463
|
+
previousTodos,
|
|
1464
|
+
storage: 'memory',
|
|
1465
|
+
todos
|
|
1466
|
+
};
|
|
1467
|
+
} catch (error) {
|
|
1468
|
+
return getToolErrorPayload(error);
|
|
1469
|
+
}
|
|
1470
|
+
};
|
|
1471
|
+
|
|
1298
1472
|
const executeWriteFileTool = async (args, _options) => {
|
|
1299
1473
|
const uri = typeof args.uri === 'string' ? args.uri : '';
|
|
1300
1474
|
const content = typeof args.content === 'string' ? args.content : '';
|
|
@@ -1347,6 +1521,9 @@ const executeChatTool = async (name, rawArguments, options) => {
|
|
|
1347
1521
|
if (name === 'write_file') {
|
|
1348
1522
|
return executeWriteFileTool(args);
|
|
1349
1523
|
}
|
|
1524
|
+
if (name === 'rename') {
|
|
1525
|
+
return executeRenameTool(args);
|
|
1526
|
+
}
|
|
1350
1527
|
if (name === 'edit_file') {
|
|
1351
1528
|
return executeEditFileTool(args);
|
|
1352
1529
|
}
|
|
@@ -1371,12 +1548,18 @@ const executeChatTool = async (name, rawArguments, options) => {
|
|
|
1371
1548
|
if (name === 'search_text') {
|
|
1372
1549
|
return executeSearchTextTool(args);
|
|
1373
1550
|
}
|
|
1551
|
+
if (name === 'rg') {
|
|
1552
|
+
return executeRgTool(args);
|
|
1553
|
+
}
|
|
1374
1554
|
if (name === 'run_in_terminal') {
|
|
1375
1555
|
return executeRunInTerminalTool(args);
|
|
1376
1556
|
}
|
|
1377
1557
|
if (name === 'create_directory') {
|
|
1378
1558
|
return executeCreateDirectoryTool(args);
|
|
1379
1559
|
}
|
|
1560
|
+
if (name === 'update_todo') {
|
|
1561
|
+
return executeUpdateTodoTool(args);
|
|
1562
|
+
}
|
|
1380
1563
|
return {
|
|
1381
1564
|
error: `Unknown tool: ${name}`
|
|
1382
1565
|
};
|
|
@@ -1426,6 +1609,30 @@ const getWriteFileTool = () => {
|
|
|
1426
1609
|
type: 'function'
|
|
1427
1610
|
};
|
|
1428
1611
|
};
|
|
1612
|
+
const getRenameTool = () => {
|
|
1613
|
+
return {
|
|
1614
|
+
function: {
|
|
1615
|
+
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).',
|
|
1616
|
+
name: 'rename',
|
|
1617
|
+
parameters: {
|
|
1618
|
+
additionalProperties: false,
|
|
1619
|
+
properties: {
|
|
1620
|
+
newUri: {
|
|
1621
|
+
description: 'Absolute target URI for the file or folder after renaming.',
|
|
1622
|
+
type: 'string'
|
|
1623
|
+
},
|
|
1624
|
+
oldUri: {
|
|
1625
|
+
description: 'Absolute source URI for the existing file or folder to rename.',
|
|
1626
|
+
type: 'string'
|
|
1627
|
+
}
|
|
1628
|
+
},
|
|
1629
|
+
required: ['oldUri', 'newUri'],
|
|
1630
|
+
type: 'object'
|
|
1631
|
+
}
|
|
1632
|
+
},
|
|
1633
|
+
type: 'function'
|
|
1634
|
+
};
|
|
1635
|
+
};
|
|
1429
1636
|
const getEditFileTool = () => {
|
|
1430
1637
|
return {
|
|
1431
1638
|
function: {
|
|
@@ -1615,6 +1822,39 @@ const getSearchTextTool = () => {
|
|
|
1615
1822
|
type: 'function'
|
|
1616
1823
|
};
|
|
1617
1824
|
};
|
|
1825
|
+
const getRgTool = () => {
|
|
1826
|
+
return {
|
|
1827
|
+
function: {
|
|
1828
|
+
description: 'Search text or regex in workspace files using ripgrep-style arguments and return matching results.',
|
|
1829
|
+
name: 'rg',
|
|
1830
|
+
parameters: {
|
|
1831
|
+
additionalProperties: false,
|
|
1832
|
+
properties: {
|
|
1833
|
+
'-n': {
|
|
1834
|
+
description: 'When true, include line numbers in the output.',
|
|
1835
|
+
type: 'boolean'
|
|
1836
|
+
},
|
|
1837
|
+
output_mode: {
|
|
1838
|
+
description: 'Result format to return.',
|
|
1839
|
+
enum: ['content', 'files_with_matches', 'count'],
|
|
1840
|
+
type: 'string'
|
|
1841
|
+
},
|
|
1842
|
+
path: {
|
|
1843
|
+
description: 'Optional file or directory path inside the current workspace to scope the search.',
|
|
1844
|
+
type: 'string'
|
|
1845
|
+
},
|
|
1846
|
+
pattern: {
|
|
1847
|
+
description: 'Text or regular expression pattern to search for.',
|
|
1848
|
+
type: 'string'
|
|
1849
|
+
}
|
|
1850
|
+
},
|
|
1851
|
+
required: ['pattern'],
|
|
1852
|
+
type: 'object'
|
|
1853
|
+
}
|
|
1854
|
+
},
|
|
1855
|
+
type: 'function'
|
|
1856
|
+
};
|
|
1857
|
+
};
|
|
1618
1858
|
const getRunInTerminalTool = () => {
|
|
1619
1859
|
return {
|
|
1620
1860
|
function: {
|
|
@@ -1664,8 +1904,28 @@ const getCreateDirectoryTool = () => {
|
|
|
1664
1904
|
type: 'function'
|
|
1665
1905
|
};
|
|
1666
1906
|
};
|
|
1907
|
+
const getUpdateTodoTool = () => {
|
|
1908
|
+
return {
|
|
1909
|
+
function: {
|
|
1910
|
+
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").',
|
|
1911
|
+
name: 'update_todo',
|
|
1912
|
+
parameters: {
|
|
1913
|
+
additionalProperties: false,
|
|
1914
|
+
properties: {
|
|
1915
|
+
todos: {
|
|
1916
|
+
description: 'Complete markdown checklist content to store as the current TODO list state.',
|
|
1917
|
+
type: 'string'
|
|
1918
|
+
}
|
|
1919
|
+
},
|
|
1920
|
+
required: ['todos'],
|
|
1921
|
+
type: 'object'
|
|
1922
|
+
}
|
|
1923
|
+
},
|
|
1924
|
+
type: 'function'
|
|
1925
|
+
};
|
|
1926
|
+
};
|
|
1667
1927
|
const getBasicChatTools = () => {
|
|
1668
|
-
return [getReadFileTool(), getWriteFileTool(), getEditFileTool(), getListFilesTool(), getGetWorkspaceUriTool(), getRenderHtmlTool(), getOpenPreviewTool(), getOpenEditorTool(), getClosePreviewTool(), getSearchTextTool(), getRunInTerminalTool(), getCreateDirectoryTool()];
|
|
1928
|
+
return [getReadFileTool(), getWriteFileTool(), getRenameTool(), getEditFileTool(), getListFilesTool(), getGetWorkspaceUriTool(), getRenderHtmlTool(), getOpenPreviewTool(), getOpenEditorTool(), getClosePreviewTool(), getSearchTextTool(), getRgTool(), getRunInTerminalTool(), getCreateDirectoryTool(), getUpdateTodoTool()];
|
|
1669
1929
|
};
|
|
1670
1930
|
|
|
1671
1931
|
const handleMessagePort = async port => {
|