@lvce-editor/chat-tool-worker 7.10.0 → 7.12.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.
@@ -407,6 +407,100 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
407
407
  listen: listen$6,
408
408
  wrap: wrap$e
409
409
  };
410
+ const addListener = (emitter, type, callback) => {
411
+ if ('addEventListener' in emitter) {
412
+ emitter.addEventListener(type, callback);
413
+ } else {
414
+ emitter.on(type, callback);
415
+ }
416
+ };
417
+ const removeListener = (emitter, type, callback) => {
418
+ if ('removeEventListener' in emitter) {
419
+ emitter.removeEventListener(type, callback);
420
+ } else {
421
+ emitter.off(type, callback);
422
+ }
423
+ };
424
+ const getFirstEvent = (eventEmitter, eventMap) => {
425
+ const {
426
+ promise,
427
+ resolve
428
+ } = Promise.withResolvers();
429
+ const listenerMap = Object.create(null);
430
+ const cleanup = value => {
431
+ for (const event of Object.keys(eventMap)) {
432
+ removeListener(eventEmitter, event, listenerMap[event]);
433
+ }
434
+ resolve(value);
435
+ };
436
+ for (const [event, type] of Object.entries(eventMap)) {
437
+ const listener = event => {
438
+ cleanup({
439
+ event,
440
+ type
441
+ });
442
+ };
443
+ addListener(eventEmitter, event, listener);
444
+ listenerMap[event] = listener;
445
+ }
446
+ return promise;
447
+ };
448
+ const Message$1 = 3;
449
+ const create$5$1 = async ({
450
+ isMessagePortOpen,
451
+ messagePort
452
+ }) => {
453
+ if (!isMessagePort(messagePort)) {
454
+ throw new IpcError('port must be of type MessagePort');
455
+ }
456
+ if (isMessagePortOpen) {
457
+ return messagePort;
458
+ }
459
+ const eventPromise = getFirstEvent(messagePort, {
460
+ message: Message$1
461
+ });
462
+ messagePort.start();
463
+ const {
464
+ event,
465
+ type
466
+ } = await eventPromise;
467
+ if (type !== Message$1) {
468
+ throw new IpcError('Failed to wait for ipc message');
469
+ }
470
+ if (event.data !== readyMessage) {
471
+ throw new IpcError('unexpected first message');
472
+ }
473
+ return messagePort;
474
+ };
475
+ const signal$1 = messagePort => {
476
+ messagePort.start();
477
+ };
478
+ class IpcParentWithMessagePort extends Ipc {
479
+ getData = getData$2;
480
+ send(message) {
481
+ this._rawIpc.postMessage(message);
482
+ }
483
+ sendAndTransfer(message) {
484
+ const transfer = getTransferrables(message);
485
+ this._rawIpc.postMessage(message, transfer);
486
+ }
487
+ dispose() {
488
+ this._rawIpc.close();
489
+ }
490
+ onMessage(callback) {
491
+ this._rawIpc.addEventListener('message', callback);
492
+ }
493
+ onClose(callback) {}
494
+ }
495
+ const wrap$5 = messagePort => {
496
+ return new IpcParentWithMessagePort(messagePort);
497
+ };
498
+ const IpcParentWithMessagePort$1 = {
499
+ __proto__: null,
500
+ create: create$5$1,
501
+ signal: signal$1,
502
+ wrap: wrap$5
503
+ };
410
504
 
411
505
  class CommandNotFoundError extends Error {
412
506
  constructor(command) {
@@ -643,7 +737,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
643
737
  const errorProperty = getErrorProperty(error, prettyError);
644
738
  return create$1$1(id, errorProperty);
645
739
  };
646
- const create$6 = (message, result) => {
740
+ const create$9 = (message, result) => {
647
741
  return {
648
742
  id: message.id,
649
743
  jsonrpc: Two$1,
@@ -652,7 +746,7 @@ const create$6 = (message, result) => {
652
746
  };
653
747
  const getSuccessResponse = (message, result) => {
654
748
  const resultProperty = result ?? null;
655
- return create$6(message, resultProperty);
749
+ return create$9(message, resultProperty);
656
750
  };
657
751
  const getErrorResponseSimple = (id, error) => {
658
752
  return {
@@ -746,7 +840,7 @@ const handleJsonRpcMessage = async (...args) => {
746
840
 
747
841
  const Two = '2.0';
748
842
 
749
- const create$5 = (method, params) => {
843
+ const create$8 = (method, params) => {
750
844
  return {
751
845
  jsonrpc: Two,
752
846
  method,
@@ -754,7 +848,7 @@ const create$5 = (method, params) => {
754
848
  };
755
849
  };
756
850
 
757
- const create$4 = (id, method, params) => {
851
+ const create$7 = (id, method, params) => {
758
852
  const message = {
759
853
  id,
760
854
  jsonrpc: Two,
@@ -765,12 +859,12 @@ const create$4 = (id, method, params) => {
765
859
  };
766
860
 
767
861
  let id = 0;
768
- const create$3 = () => {
862
+ const create$6 = () => {
769
863
  return ++id;
770
864
  };
771
865
 
772
866
  const registerPromise = map => {
773
- const id = create$3();
867
+ const id = create$6();
774
868
  const {
775
869
  promise,
776
870
  resolve
@@ -787,7 +881,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
787
881
  id,
788
882
  promise
789
883
  } = registerPromise(callbacks);
790
- const message = create$4(id, method, params);
884
+ const message = create$7(id, method, params);
791
885
  if (useSendAndTransfer && ipc.sendAndTransfer) {
792
886
  ipc.sendAndTransfer(message);
793
887
  } else {
@@ -823,7 +917,7 @@ const createRpc = ipc => {
823
917
  * @deprecated
824
918
  */
825
919
  send(method, ...params) {
826
- const message = create$5(method, params);
920
+ const message = create$8(method, params);
827
921
  ipc.send(message);
828
922
  }
829
923
  };
@@ -863,6 +957,83 @@ const listen$1 = async (module, options) => {
863
957
  return ipc;
864
958
  };
865
959
 
960
+ const create$5 = async ({
961
+ commandMap,
962
+ isMessagePortOpen = true,
963
+ messagePort
964
+ }) => {
965
+ // TODO create a commandMap per rpc instance
966
+ register(commandMap);
967
+ const rawIpc = await IpcParentWithMessagePort$1.create({
968
+ isMessagePortOpen,
969
+ messagePort
970
+ });
971
+ const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
972
+ handleIpc(ipc);
973
+ const rpc = createRpc(ipc);
974
+ messagePort.start();
975
+ return rpc;
976
+ };
977
+
978
+ const create$4 = async ({
979
+ commandMap,
980
+ isMessagePortOpen,
981
+ send
982
+ }) => {
983
+ const {
984
+ port1,
985
+ port2
986
+ } = new MessageChannel();
987
+ await send(port1);
988
+ return create$5({
989
+ commandMap,
990
+ isMessagePortOpen,
991
+ messagePort: port2
992
+ });
993
+ };
994
+
995
+ const createSharedLazyRpc = factory => {
996
+ let rpcPromise;
997
+ const getOrCreate = () => {
998
+ if (!rpcPromise) {
999
+ rpcPromise = factory();
1000
+ }
1001
+ return rpcPromise;
1002
+ };
1003
+ return {
1004
+ async dispose() {
1005
+ const rpc = await getOrCreate();
1006
+ await rpc.dispose();
1007
+ },
1008
+ async invoke(method, ...params) {
1009
+ const rpc = await getOrCreate();
1010
+ return rpc.invoke(method, ...params);
1011
+ },
1012
+ async invokeAndTransfer(method, ...params) {
1013
+ const rpc = await getOrCreate();
1014
+ return rpc.invokeAndTransfer(method, ...params);
1015
+ },
1016
+ async send(method, ...params) {
1017
+ const rpc = await getOrCreate();
1018
+ rpc.send(method, ...params);
1019
+ }
1020
+ };
1021
+ };
1022
+
1023
+ const create$3 = async ({
1024
+ commandMap,
1025
+ isMessagePortOpen,
1026
+ send
1027
+ }) => {
1028
+ return createSharedLazyRpc(() => {
1029
+ return create$4({
1030
+ commandMap,
1031
+ isMessagePortOpen,
1032
+ send
1033
+ });
1034
+ });
1035
+ };
1036
+
866
1037
  const create$2 = async ({
867
1038
  commandMap,
868
1039
  messagePort
@@ -909,7 +1080,7 @@ const createMockRpc = ({
909
1080
  };
910
1081
 
911
1082
  const rpcs = Object.create(null);
912
- const set$1 = (id, rpc) => {
1083
+ const set$3 = (id, rpc) => {
913
1084
  rpcs[id] = rpc;
914
1085
  };
915
1086
  const get = id => {
@@ -942,7 +1113,7 @@ const create = rpcId => {
942
1113
  const mockRpc = createMockRpc({
943
1114
  commandMap
944
1115
  });
945
- set$1(rpcId, mockRpc);
1116
+ set$3(rpcId, mockRpc);
946
1117
  // @ts-ignore
947
1118
  mockRpc[Symbol.dispose] = () => {
948
1119
  remove(rpcId);
@@ -951,20 +1122,38 @@ const create = rpcId => {
951
1122
  return mockRpc;
952
1123
  },
953
1124
  set(rpc) {
954
- set$1(rpcId, rpc);
1125
+ set$3(rpcId, rpc);
955
1126
  }
956
1127
  };
957
1128
  };
958
1129
 
1130
+ const ChatStorageWorker = 6003;
1131
+ const FileSystemWorker = 209;
959
1132
  const RendererWorker = 1;
960
1133
 
1134
+ const {
1135
+ set: set$2
1136
+ } = create(ChatStorageWorker);
1137
+
1138
+ const {
1139
+ set: set$1
1140
+ } = create(FileSystemWorker);
1141
+
961
1142
  const {
962
1143
  invoke,
1144
+ invokeAndTransfer,
963
1145
  set
964
1146
  } = create(RendererWorker);
1147
+ const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
1148
+ const command = 'FileSystem.handleMessagePort';
1149
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
1150
+ };
965
1151
  const readFile = async uri => {
966
1152
  return invoke('FileSystem.readFile', uri);
967
1153
  };
1154
+ const sendMessagePortToChatStorageWorker = async port => {
1155
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToChatStorageWorker', port, 'HandleMessagePort.handleMessagePort');
1156
+ };
968
1157
  const writeFile = async (uri, text) => {
969
1158
  await invoke('FileSystem.writeFile', uri, text);
970
1159
  };
@@ -1107,6 +1296,217 @@ const executeGlobTool = async (args, _options) => {
1107
1296
  };
1108
1297
  };
1109
1298
 
1299
+ const formatSearchProcessResults = results => {
1300
+ if (!results || results.length === 0) {
1301
+ return 'No matches found.';
1302
+ }
1303
+ let currentFile = '';
1304
+ const lines = [];
1305
+ for (const result of results) {
1306
+ if (result.type === 1) {
1307
+ currentFile = result.text;
1308
+ continue;
1309
+ }
1310
+ if (result.type === 2) {
1311
+ if (currentFile) {
1312
+ lines.push(`${currentFile}:${result.lineNumber}:${result.text}`);
1313
+ } else {
1314
+ lines.push(`${result.lineNumber}:${result.text}`);
1315
+ }
1316
+ }
1317
+ }
1318
+ if (lines.length === 0) {
1319
+ return 'No matches found.';
1320
+ }
1321
+ return lines.join('\n');
1322
+ };
1323
+
1324
+ const windowsDrivePathRegex = /^[a-zA-Z]:[\\/]/;
1325
+ const isAbsoluteFileSystemPath = value => {
1326
+ return value.startsWith('/') || windowsDrivePathRegex.test(value);
1327
+ };
1328
+
1329
+ const isFileUri = value => {
1330
+ return value.startsWith('file://');
1331
+ };
1332
+
1333
+ const getRipGrepArgs = ({
1334
+ includeIgnoredFiles,
1335
+ includePattern,
1336
+ isRegexp,
1337
+ query
1338
+ }) => {
1339
+ const ripGrepArgs = ['--hidden', '--no-require-git', '--smart-case', '--stats', '--json', '--threads', '1', '--ignore-case'];
1340
+ if (includeIgnoredFiles) {
1341
+ ripGrepArgs.push('--no-ignore');
1342
+ }
1343
+ if (includePattern && !isFileUri(includePattern) && !isAbsoluteFileSystemPath(includePattern)) {
1344
+ ripGrepArgs.push('--glob', includePattern);
1345
+ }
1346
+ if (isRegexp) {
1347
+ ripGrepArgs.push('--regexp', query);
1348
+ } else {
1349
+ ripGrepArgs.push('--fixed-strings', '--', query);
1350
+ }
1351
+ ripGrepArgs.push('.');
1352
+ return ripGrepArgs;
1353
+ };
1354
+
1355
+ const windowsPathWithLeadingSlashRegex = /^\/[a-zA-Z]:/;
1356
+ const getFilePathFromUri = uri => {
1357
+ const url = new URL(uri);
1358
+ const decodedPath = decodeURIComponent(url.pathname);
1359
+ if (windowsPathWithLeadingSlashRegex.test(decodedPath)) {
1360
+ return decodedPath.slice(1);
1361
+ }
1362
+ return decodedPath;
1363
+ };
1364
+
1365
+ const getScheme = uriOrPath => {
1366
+ if (!uriOrPath.includes('://')) {
1367
+ return '';
1368
+ }
1369
+ return new URL(uriOrPath).protocol.slice(0, -1);
1370
+ };
1371
+
1372
+ const getSearchDir = (workspaceUri, includePattern) => {
1373
+ if (!includePattern) {
1374
+ return getScheme(workspaceUri) === 'file' ? getFilePathFromUri(workspaceUri) : workspaceUri;
1375
+ }
1376
+ if (isFileUri(includePattern)) {
1377
+ return getFilePathFromUri(includePattern);
1378
+ }
1379
+ if (isAbsoluteFileSystemPath(includePattern)) {
1380
+ return includePattern;
1381
+ }
1382
+ return getScheme(workspaceUri) === 'file' ? getFilePathFromUri(workspaceUri) : workspaceUri;
1383
+ };
1384
+
1385
+ const executeFileGrepSearch = async (workspaceUri, grepSearchArgs) => {
1386
+ const result = await invoke('SearchProcess.invoke', 'TextSearch.search', {
1387
+ maxSearchResults: grepSearchArgs.maxResults,
1388
+ ripGrepArgs: getRipGrepArgs(grepSearchArgs),
1389
+ searchDir: getSearchDir(workspaceUri, grepSearchArgs.includePattern)
1390
+ });
1391
+ return {
1392
+ arguments: grepSearchArgs,
1393
+ result: formatSearchProcessResults(result.results),
1394
+ workspaceUri,
1395
+ ...(result.limitHit ? {
1396
+ warning: 'Search result limit reached.'
1397
+ } : {})
1398
+ };
1399
+ };
1400
+
1401
+ const formatLegacyMemorySearchResults = results => {
1402
+ const lines = [];
1403
+ for (const result of results) {
1404
+ const [path, matches] = result;
1405
+ for (const match of matches) {
1406
+ const preview = typeof match?.preview === 'string' ? match.preview : '';
1407
+ lines.push(preview ? `${path}: ${preview}` : path);
1408
+ }
1409
+ }
1410
+ if (lines.length === 0) {
1411
+ return 'No matches found.';
1412
+ }
1413
+ return lines.join('\n');
1414
+ };
1415
+
1416
+ const isLegacyMemorySearchResult = value => {
1417
+ return Array.isArray(value);
1418
+ };
1419
+
1420
+ const executeMemoryGrepSearch = async (workspaceUri, grepSearchArgs, options) => {
1421
+ const searchOptions = {
1422
+ exclude: '',
1423
+ include: grepSearchArgs.includePattern || '',
1424
+ isCaseSensitive: false,
1425
+ query: grepSearchArgs.query,
1426
+ root: workspaceUri,
1427
+ scheme: getScheme(workspaceUri),
1428
+ threads: 1,
1429
+ useRegularExpression: grepSearchArgs.isRegexp
1430
+ };
1431
+ try {
1432
+ const result = await invoke('ExtensionHostTextSearch.textSearchMemory2', searchOptions.scheme, workspaceUri, grepSearchArgs.query, searchOptions, options.assetDir);
1433
+ return {
1434
+ arguments: grepSearchArgs,
1435
+ result: formatLegacyMemorySearchResults(result.results || []),
1436
+ workspaceUri,
1437
+ ...(result.limitHit ? {
1438
+ warning: 'Search result limit reached.'
1439
+ } : {})
1440
+ };
1441
+ } catch {
1442
+ const legacyResults = await invoke('ExtensionHostTextSearch.textSearchMemory', searchOptions.scheme, workspaceUri, grepSearchArgs.query, searchOptions, options.assetDir);
1443
+ return {
1444
+ arguments: grepSearchArgs,
1445
+ result: isLegacyMemorySearchResult(legacyResults) ? formatLegacyMemorySearchResults(legacyResults) : 'No matches found.',
1446
+ workspaceUri
1447
+ };
1448
+ }
1449
+ };
1450
+
1451
+ const getGrepSearchArgs = args => {
1452
+ const {
1453
+ includeIgnoredFiles,
1454
+ includePattern,
1455
+ isRegexp,
1456
+ maxResults,
1457
+ query
1458
+ } = args;
1459
+ if (typeof query !== 'string' || typeof isRegexp !== 'boolean') {
1460
+ return undefined;
1461
+ }
1462
+ if (includePattern !== undefined && typeof includePattern !== 'string') {
1463
+ return undefined;
1464
+ }
1465
+ if (maxResults !== undefined && typeof maxResults !== 'number') {
1466
+ return undefined;
1467
+ }
1468
+ if (includeIgnoredFiles !== undefined && typeof includeIgnoredFiles !== 'boolean') {
1469
+ return undefined;
1470
+ }
1471
+ return {
1472
+ ...(includeIgnoredFiles === undefined ? {} : {
1473
+ includeIgnoredFiles
1474
+ }),
1475
+ ...(includePattern === undefined ? {} : {
1476
+ includePattern
1477
+ }),
1478
+ ...(maxResults === undefined ? {} : {
1479
+ maxResults
1480
+ }),
1481
+ isRegexp,
1482
+ query
1483
+ };
1484
+ };
1485
+
1486
+ const grepSearchArgumentError = 'Invalid argument: grep_search requires query (string), isRegexp (boolean), optional includePattern (string), optional maxResults (number), and optional includeIgnoredFiles (boolean).';
1487
+
1488
+ const executeGrepSearchTool = async (args, options) => {
1489
+ const grepSearchArgs = getGrepSearchArgs(args);
1490
+ if (!grepSearchArgs) {
1491
+ return {
1492
+ error: grepSearchArgumentError
1493
+ };
1494
+ }
1495
+ try {
1496
+ const workspaceUri = await getWorkspacePath();
1497
+ const scheme = getScheme(workspaceUri);
1498
+ if (scheme === '' || scheme === 'file') {
1499
+ return executeFileGrepSearch(workspaceUri, grepSearchArgs);
1500
+ }
1501
+ return executeMemoryGrepSearch(workspaceUri, grepSearchArgs, options);
1502
+ } catch (error) {
1503
+ return {
1504
+ ...getToolErrorPayload(error),
1505
+ arguments: grepSearchArgs
1506
+ };
1507
+ }
1508
+ };
1509
+
1110
1510
  const executeListFilesTool = async (args, _options) => {
1111
1511
  const uri = typeof args.uri === 'string' ? args.uri : '';
1112
1512
  if (!uri || !isAbsoluteUri(uri)) {
@@ -1540,6 +1940,8 @@ const executeChatTool = async (name, rawArguments, options) => {
1540
1940
  return executeGetWorkspaceUriTool();
1541
1941
  case 'glob':
1542
1942
  return executeGlobTool(args);
1943
+ case 'grep_search':
1944
+ return executeGrepSearchTool(args, options);
1543
1945
  case 'list_files':
1544
1946
  return executeListFilesTool(args);
1545
1947
  case 'open_preview':
@@ -1569,16 +1971,31 @@ const executeChatTool = async (name, rawArguments, options) => {
1569
1971
  }
1570
1972
  };
1571
1973
 
1572
- const getReadFileTool = () => {
1974
+ const getClosePreviewTool = () => {
1573
1975
  return {
1574
1976
  function: {
1575
- description: 'Read UTF-8 text content from a file inside the currently open workspace folder. Only pass an absolute URI.',
1576
- name: 'read_file',
1977
+ description: 'Close the right-side preview if it is currently open.',
1978
+ name: 'close_preview',
1979
+ parameters: {
1980
+ additionalProperties: false,
1981
+ properties: {},
1982
+ type: 'object'
1983
+ }
1984
+ },
1985
+ type: 'function'
1986
+ };
1987
+ };
1988
+
1989
+ const getCreateDirectoryTool = () => {
1990
+ return {
1991
+ function: {
1992
+ description: 'Create a new directory at the given absolute URI (for example `file://...`, `memfs://...`, or extension-provided file system URIs). Do not pass a relative path.',
1993
+ name: 'create_directory',
1577
1994
  parameters: {
1578
1995
  additionalProperties: false,
1579
1996
  properties: {
1580
1997
  uri: {
1581
- description: 'Absolute file URI for a real path inside the currently open workspace folder. Do not use placeholder URIs.',
1998
+ description: 'Absolute URI for the target directory (for example `file://...`, `memfs://...`, or extension-provided file system URIs). Relative paths are not allowed.',
1582
1999
  type: 'string'
1583
2000
  }
1584
2001
  },
@@ -1589,16 +2006,25 @@ const getReadFileTool = () => {
1589
2006
  type: 'function'
1590
2007
  };
1591
2008
  };
1592
- const getWriteFileTool = () => {
2009
+
2010
+ const getEditFileTool = () => {
1593
2011
  return {
1594
2012
  function: {
1595
- description: 'Write UTF-8 text content to a file for an absolute URI (for example `file://...`, `memfs://...`, or extension-provided file system URIs). Do not pass a relative path and do not use a `path` argument.',
1596
- name: 'write_file',
2013
+ description: 'Apply a targeted text edit to an existing file by character offsets. This reads the current file, applies the edit, and writes the updated result. Use this for small changes instead of rewriting the full file.',
2014
+ name: 'edit_file',
1597
2015
  parameters: {
1598
2016
  additionalProperties: false,
1599
2017
  properties: {
1600
- content: {
1601
- description: 'New UTF-8 text content to write to the file.',
2018
+ end: {
2019
+ description: 'Zero-based end character offset (exclusive) in the current file content.',
2020
+ type: 'number'
2021
+ },
2022
+ start: {
2023
+ description: 'Zero-based start character offset (inclusive) in the current file content.',
2024
+ type: 'number'
2025
+ },
2026
+ text: {
2027
+ description: 'Replacement text inserted at the range [start, end).',
1602
2028
  type: 'string'
1603
2029
  },
1604
2030
  uri: {
@@ -1606,69 +2032,87 @@ const getWriteFileTool = () => {
1606
2032
  type: 'string'
1607
2033
  }
1608
2034
  },
1609
- required: ['uri', 'content'],
2035
+ required: ['uri', 'start', 'end', 'text'],
1610
2036
  type: 'object'
1611
2037
  }
1612
2038
  },
1613
2039
  type: 'function'
1614
2040
  };
1615
2041
  };
1616
- const getRenameTool = () => {
2042
+
2043
+ const getGetWorkspaceUriTool = () => {
1617
2044
  return {
1618
2045
  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',
2046
+ description: 'Get the URI of the currently open workspace folder. Call this first before using list_files, read_file, write_file, edit_file, open_preview, or openEditor when you do not already have a concrete workspace URI.',
2047
+ name: 'getWorkspaceUri',
2048
+ parameters: {
2049
+ additionalProperties: false,
2050
+ properties: {},
2051
+ type: 'object'
2052
+ }
2053
+ },
2054
+ type: 'function'
2055
+ };
2056
+ };
2057
+
2058
+ const getGlobTool = () => {
2059
+ return {
2060
+ function: {
2061
+ description: 'Find files by glob pattern and return matching relative paths.',
2062
+ name: 'glob',
1621
2063
  parameters: {
1622
2064
  additionalProperties: false,
1623
2065
  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.',
2066
+ pattern: {
2067
+ description: 'Glob pattern to match files, for example `packages/e2e/src/*.ts`.',
1630
2068
  type: 'string'
1631
2069
  }
1632
2070
  },
1633
- required: ['oldUri', 'newUri'],
2071
+ required: ['pattern'],
1634
2072
  type: 'object'
1635
2073
  }
1636
2074
  },
1637
2075
  type: 'function'
1638
2076
  };
1639
2077
  };
1640
- const getEditFileTool = () => {
2078
+
2079
+ const getGrepSearchTool = () => {
1641
2080
  return {
1642
2081
  function: {
1643
- description: 'Apply a targeted text edit to an existing file by character offsets. This reads the current file, applies the edit, and writes the updated result. Use this for small changes instead of rewriting the full file.',
1644
- name: 'edit_file',
2082
+ description: "Do a fast text search in the workspace. Use this tool when you want to search with an exact string or regex. If you are not sure what words will appear in the workspace, prefer using regex patterns with alternation (|) or character classes to search for multiple potential words at once instead of making separate searches. For example, use 'function|method|procedure' to look for all of those words at once. Use includePattern to search within files matching a specific pattern, or in a specific file, using a relative path. Use 'includeIgnoredFiles' to include files normally ignored by .gitignore, other ignore files, and `files.exclude` and `search.exclude` settings. Warning: using this may cause the search to be slower, only set it when you want to search in ignored folders like node_modules or build outputs. Use this tool when you want to see an overview of a particular file, instead of using read_file many times to look for code within a file.\n\nIn a multi-root workspace, you can scope the search to a specific workspace folder by using the absolute path to the folder as the includePattern, e.g. /path/to/folder.",
2083
+ name: 'grep_search',
1645
2084
  parameters: {
1646
2085
  additionalProperties: false,
1647
2086
  properties: {
1648
- end: {
1649
- description: 'Zero-based end character offset (exclusive) in the current file content.',
1650
- type: 'number'
1651
- },
1652
- start: {
1653
- description: 'Zero-based start character offset (inclusive) in the current file content.',
1654
- type: 'number'
2087
+ includeIgnoredFiles: {
2088
+ description: 'Whether to include files that would normally be ignored according to .gitignore, other ignore files and `files.exclude` and `search.exclude` settings. Warning: using this may cause the search to be slower. Only set it when you want to search in ignored folders like node_modules or build outputs.',
2089
+ type: 'boolean'
1655
2090
  },
1656
- text: {
1657
- description: 'Replacement text inserted at the range [start, end).',
2091
+ includePattern: {
2092
+ description: 'Search files matching this glob pattern. Will be applied to the relative path of files within the workspace. To search recursively inside a folder, use a proper glob pattern like "src/folder/**". Do not use | in includePattern. Can also be an absolute path to a workspace folder to scope the search in a multi-root workspace.',
1658
2093
  type: 'string'
1659
2094
  },
1660
- uri: {
1661
- description: 'Absolute URI for the target file (for example `file://...`, `memfs://...`, or extension-provided file system URIs). Relative paths are not allowed.',
2095
+ isRegexp: {
2096
+ description: 'Whether the pattern is a regex.',
2097
+ type: 'boolean'
2098
+ },
2099
+ maxResults: {
2100
+ description: "The maximum number of results to return. Do not use this unless necessary, it can slow things down. By default, only some matches are returned. If you use this and don't see what you're looking for, you can try again with a more specific query or a larger maxResults.",
2101
+ type: 'number'
2102
+ },
2103
+ query: {
2104
+ description: "The pattern to search for in files in the workspace. Use regex with alternation (e.g., 'word1|word2|word3') or character classes to find multiple potential words in a single search. Be sure to set the isRegexp property properly to declare whether it's a regex or plain text pattern. Is case-insensitive.",
1662
2105
  type: 'string'
1663
2106
  }
1664
2107
  },
1665
- required: ['uri', 'start', 'end', 'text'],
2108
+ required: ['query', 'isRegexp'],
1666
2109
  type: 'object'
1667
2110
  }
1668
2111
  },
1669
2112
  type: 'function'
1670
2113
  };
1671
2114
  };
2115
+
1672
2116
  const getListFilesTool = () => {
1673
2117
  return {
1674
2118
  function: {
@@ -1689,48 +2133,28 @@ const getListFilesTool = () => {
1689
2133
  type: 'function'
1690
2134
  };
1691
2135
  };
1692
- const getGetWorkspaceUriTool = () => {
1693
- return {
1694
- function: {
1695
- description: 'Get the URI of the currently open workspace folder. Call this first before using list_files, read_file, write_file, edit_file, open_preview, or openEditor when you do not already have a concrete workspace URI.',
1696
- name: 'getWorkspaceUri',
1697
- parameters: {
1698
- additionalProperties: false,
1699
- properties: {},
1700
- type: 'object'
1701
- }
1702
- },
1703
- type: 'function'
1704
- };
1705
- };
1706
- const getRenderHtmlTool = () => {
2136
+
2137
+ const getOpenEditorTool = () => {
1707
2138
  return {
1708
2139
  function: {
1709
- description: 'Render custom HTML and optional CSS directly in the chat tool call list using native chat UI rendering. Use this for structured cards, tables, and small dashboards. After calling this tool, do not repeat the same HTML, data table, or long content again as plain text unless the user explicitly asks for a text-only version.',
1710
- name: 'render_html',
2140
+ description: 'Open a file URI in the editor.',
2141
+ name: 'openEditor',
1711
2142
  parameters: {
1712
2143
  additionalProperties: false,
1713
2144
  properties: {
1714
- css: {
1715
- description: 'Optional CSS string applied inside the preview document.',
1716
- type: 'string'
1717
- },
1718
- html: {
1719
- description: 'HTML string to render in the preview document.',
1720
- type: 'string'
1721
- },
1722
- title: {
1723
- description: 'Optional short title for the preview.',
2145
+ uri: {
2146
+ description: 'Absolute file URI for a real path inside the currently open workspace folder. Do not use placeholder URIs.',
1724
2147
  type: 'string'
1725
2148
  }
1726
2149
  },
1727
- required: ['html'],
2150
+ required: ['uri'],
1728
2151
  type: 'object'
1729
2152
  }
1730
2153
  },
1731
2154
  type: 'function'
1732
2155
  };
1733
2156
  };
2157
+
1734
2158
  const getOpenPreviewTool = () => {
1735
2159
  return {
1736
2160
  function: {
@@ -1751,11 +2175,12 @@ const getOpenPreviewTool = () => {
1751
2175
  type: 'function'
1752
2176
  };
1753
2177
  };
1754
- const getOpenEditorTool = () => {
2178
+
2179
+ const getReadFileTool = () => {
1755
2180
  return {
1756
2181
  function: {
1757
- description: 'Open a file URI in the editor.',
1758
- name: 'openEditor',
2182
+ description: 'Read UTF-8 text content from a file inside the currently open workspace folder. Only pass an absolute URI.',
2183
+ name: 'read_file',
1759
2184
  parameters: {
1760
2185
  additionalProperties: false,
1761
2186
  properties: {
@@ -1771,61 +2196,61 @@ const getOpenEditorTool = () => {
1771
2196
  type: 'function'
1772
2197
  };
1773
2198
  };
1774
- const getClosePreviewTool = () => {
2199
+
2200
+ const getRenameTool = () => {
1775
2201
  return {
1776
2202
  function: {
1777
- description: 'Close the right-side preview if it is currently open.',
1778
- name: 'close_preview',
2203
+ 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).',
2204
+ name: 'rename',
1779
2205
  parameters: {
1780
2206
  additionalProperties: false,
1781
- properties: {},
2207
+ properties: {
2208
+ newUri: {
2209
+ description: 'Absolute target URI for the file or folder after renaming.',
2210
+ type: 'string'
2211
+ },
2212
+ oldUri: {
2213
+ description: 'Absolute source URI for the existing file or folder to rename.',
2214
+ type: 'string'
2215
+ }
2216
+ },
2217
+ required: ['oldUri', 'newUri'],
1782
2218
  type: 'object'
1783
2219
  }
1784
2220
  },
1785
2221
  type: 'function'
1786
2222
  };
1787
2223
  };
1788
- const getSearchTextTool = () => {
2224
+
2225
+ const getRenderHtmlTool = () => {
1789
2226
  return {
1790
2227
  function: {
1791
- description: 'Search text in workspace files using query options and return matching results.',
1792
- name: 'search_text',
2228
+ description: 'Render custom HTML and optional CSS directly in the chat tool call list using native chat UI rendering. Use this for structured cards, tables, and small dashboards. After calling this tool, do not repeat the same HTML, data table, or long content again as plain text unless the user explicitly asks for a text-only version.',
2229
+ name: 'render_html',
1793
2230
  parameters: {
1794
2231
  additionalProperties: false,
1795
2232
  properties: {
1796
- options: {
1797
- additionalProperties: false,
1798
- properties: {
1799
- exclude: {
1800
- items: {
1801
- type: 'string'
1802
- },
1803
- type: 'array'
1804
- },
1805
- isRegex: {
1806
- type: 'boolean'
1807
- },
1808
- machWholeWord: {
1809
- type: 'boolean'
1810
- },
1811
- matchCase: {
1812
- type: 'boolean'
1813
- },
1814
- value: {
1815
- type: 'string'
1816
- }
1817
- },
1818
- required: ['value', 'isRegex', 'matchCase', 'machWholeWord', 'exclude'],
1819
- type: 'object'
2233
+ css: {
2234
+ description: 'Optional CSS string applied inside the preview document.',
2235
+ type: 'string'
2236
+ },
2237
+ html: {
2238
+ description: 'HTML string to render in the preview document.',
2239
+ type: 'string'
2240
+ },
2241
+ title: {
2242
+ description: 'Optional short title for the preview.',
2243
+ type: 'string'
1820
2244
  }
1821
2245
  },
1822
- required: ['options'],
2246
+ required: ['html'],
1823
2247
  type: 'object'
1824
2248
  }
1825
2249
  },
1826
2250
  type: 'function'
1827
2251
  };
1828
2252
  };
2253
+
1829
2254
  const getRgTool = () => {
1830
2255
  return {
1831
2256
  function: {
@@ -1859,6 +2284,7 @@ const getRgTool = () => {
1859
2284
  type: 'function'
1860
2285
  };
1861
2286
  };
2287
+
1862
2288
  const getRunInTerminalTool = () => {
1863
2289
  return {
1864
2290
  function: {
@@ -1888,68 +2314,97 @@ const getRunInTerminalTool = () => {
1888
2314
  type: 'function'
1889
2315
  };
1890
2316
  };
1891
- const getCreateDirectoryTool = () => {
2317
+
2318
+ const getSearchTextTool = () => {
1892
2319
  return {
1893
2320
  function: {
1894
- description: 'Create a new directory at the given absolute URI (for example `file://...`, `memfs://...`, or extension-provided file system URIs). Do not pass a relative path.',
1895
- name: 'create_directory',
2321
+ description: 'Search text in workspace files using query options and return matching results.',
2322
+ name: 'search_text',
1896
2323
  parameters: {
1897
2324
  additionalProperties: false,
1898
2325
  properties: {
1899
- uri: {
1900
- description: 'Absolute URI for the target directory (for example `file://...`, `memfs://...`, or extension-provided file system URIs). Relative paths are not allowed.',
1901
- type: 'string'
2326
+ options: {
2327
+ additionalProperties: false,
2328
+ properties: {
2329
+ exclude: {
2330
+ items: {
2331
+ type: 'string'
2332
+ },
2333
+ type: 'array'
2334
+ },
2335
+ isRegex: {
2336
+ type: 'boolean'
2337
+ },
2338
+ machWholeWord: {
2339
+ type: 'boolean'
2340
+ },
2341
+ matchCase: {
2342
+ type: 'boolean'
2343
+ },
2344
+ value: {
2345
+ type: 'string'
2346
+ }
2347
+ },
2348
+ required: ['value', 'isRegex', 'matchCase', 'machWholeWord', 'exclude'],
2349
+ type: 'object'
1902
2350
  }
1903
2351
  },
1904
- required: ['uri'],
2352
+ required: ['options'],
1905
2353
  type: 'object'
1906
2354
  }
1907
2355
  },
1908
2356
  type: 'function'
1909
2357
  };
1910
2358
  };
1911
- const getGlobTool = () => {
2359
+
2360
+ const getUpdateTodoTool = () => {
1912
2361
  return {
1913
2362
  function: {
1914
- description: 'Find files by glob pattern and return matching relative paths.',
1915
- name: 'glob',
2363
+ 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").',
2364
+ name: 'update_todo',
1916
2365
  parameters: {
1917
2366
  additionalProperties: false,
1918
2367
  properties: {
1919
- pattern: {
1920
- description: 'Glob pattern to match files, for example `packages/e2e/src/*.ts`.',
2368
+ todos: {
2369
+ description: 'Complete markdown checklist content to store as the current TODO list state.',
1921
2370
  type: 'string'
1922
2371
  }
1923
2372
  },
1924
- required: ['pattern'],
2373
+ required: ['todos'],
1925
2374
  type: 'object'
1926
2375
  }
1927
2376
  },
1928
2377
  type: 'function'
1929
2378
  };
1930
2379
  };
1931
- const getUpdateTodoTool = () => {
2380
+
2381
+ const getWriteFileTool = () => {
1932
2382
  return {
1933
2383
  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',
2384
+ description: 'Write UTF-8 text content to a file for an absolute URI (for example `file://...`, `memfs://...`, or extension-provided file system URIs). Do not pass a relative path and do not use a `path` argument.',
2385
+ name: 'write_file',
1936
2386
  parameters: {
1937
2387
  additionalProperties: false,
1938
2388
  properties: {
1939
- todos: {
1940
- description: 'Complete markdown checklist content to store as the current TODO list state.',
2389
+ content: {
2390
+ description: 'New UTF-8 text content to write to the file.',
2391
+ type: 'string'
2392
+ },
2393
+ uri: {
2394
+ description: 'Absolute URI for the target file (for example `file://...`, `memfs://...`, or extension-provided file system URIs). Relative paths are not allowed.',
1941
2395
  type: 'string'
1942
2396
  }
1943
2397
  },
1944
- required: ['todos'],
2398
+ required: ['uri', 'content'],
1945
2399
  type: 'object'
1946
2400
  }
1947
2401
  },
1948
2402
  type: 'function'
1949
2403
  };
1950
2404
  };
2405
+
1951
2406
  const getBasicChatTools = () => {
1952
- return [getReadFileTool(), getWriteFileTool(), getRenameTool(), getEditFileTool(), getListFilesTool(), getGetWorkspaceUriTool(), getRenderHtmlTool(), getOpenPreviewTool(), getOpenEditorTool(), getClosePreviewTool(), getSearchTextTool(), getRgTool(), getRunInTerminalTool(), getCreateDirectoryTool(), getGlobTool(), getUpdateTodoTool()];
2407
+ return [getReadFileTool(), getWriteFileTool(), getRenameTool(), getEditFileTool(), getListFilesTool(), getGetWorkspaceUriTool(), getRenderHtmlTool(), getOpenPreviewTool(), getOpenEditorTool(), getClosePreviewTool(), getSearchTextTool(), getRgTool(), getGrepSearchTool(), getRunInTerminalTool(), getCreateDirectoryTool(), getGlobTool(), getUpdateTodoTool()];
1953
2408
  };
1954
2409
 
1955
2410
  const handleMessagePort = async port => {
@@ -1965,6 +2420,28 @@ const commandMap = {
1965
2420
  'HandleMessagePort.handleMessagePort': handleMessagePort
1966
2421
  };
1967
2422
 
2423
+ const send$1 = async port => {
2424
+ await sendMessagePortToChatStorageWorker(port);
2425
+ };
2426
+ const initializeChatStorageWorker = async () => {
2427
+ const rpc = await create$3({
2428
+ commandMap: commandMap,
2429
+ send: send$1
2430
+ });
2431
+ set$2(rpc);
2432
+ };
2433
+
2434
+ const send = async port => {
2435
+ await sendMessagePortToFileSystemWorker(port, 0);
2436
+ };
2437
+ const initializeFileSystemWorker = async () => {
2438
+ const rpc = await create$3({
2439
+ commandMap: commandMap,
2440
+ send: send
2441
+ });
2442
+ set$1(rpc);
2443
+ };
2444
+
1968
2445
  const initializeRendererWorker = async () => {
1969
2446
  const rpc = await create$1({
1970
2447
  commandMap: commandMap
@@ -1973,7 +2450,7 @@ const initializeRendererWorker = async () => {
1973
2450
  };
1974
2451
 
1975
2452
  const listen = async () => {
1976
- await initializeRendererWorker();
2453
+ await Promise.all([initializeRendererWorker(), initializeFileSystemWorker(), initializeChatStorageWorker()]);
1977
2454
  };
1978
2455
 
1979
2456
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/chat-tool-worker",
3
- "version": "7.10.0",
3
+ "version": "7.12.0",
4
4
  "description": "Chat Tool Worker",
5
5
  "repository": {
6
6
  "type": "git",