@lvce-editor/chat-tool-worker 7.11.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,158 @@ 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
+
1110
1451
  const getGrepSearchArgs = args => {
1111
1452
  const {
1112
1453
  includeIgnoredFiles,
@@ -1141,17 +1482,29 @@ const getGrepSearchArgs = args => {
1141
1482
  query
1142
1483
  };
1143
1484
  };
1144
- const executeGrepSearchTool = async (args, _options) => {
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) => {
1145
1489
  const grepSearchArgs = getGrepSearchArgs(args);
1146
1490
  if (!grepSearchArgs) {
1147
1491
  return {
1148
- error: 'Invalid argument: grep_search requires query (string), isRegexp (boolean), optional includePattern (string), optional maxResults (number), and optional includeIgnoredFiles (boolean).'
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
1149
1506
  };
1150
1507
  }
1151
- return {
1152
- arguments: grepSearchArgs,
1153
- result: 'No matches found.'
1154
- };
1155
1508
  };
1156
1509
 
1157
1510
  const executeListFilesTool = async (args, _options) => {
@@ -1588,7 +1941,7 @@ const executeChatTool = async (name, rawArguments, options) => {
1588
1941
  case 'glob':
1589
1942
  return executeGlobTool(args);
1590
1943
  case 'grep_search':
1591
- return executeGrepSearchTool(args);
1944
+ return executeGrepSearchTool(args, options);
1592
1945
  case 'list_files':
1593
1946
  return executeListFilesTool(args);
1594
1947
  case 'open_preview':
@@ -1618,16 +1971,31 @@ const executeChatTool = async (name, rawArguments, options) => {
1618
1971
  }
1619
1972
  };
1620
1973
 
1621
- const getReadFileTool = () => {
1974
+ const getClosePreviewTool = () => {
1622
1975
  return {
1623
1976
  function: {
1624
- description: 'Read UTF-8 text content from a file inside the currently open workspace folder. Only pass an absolute URI.',
1625
- 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',
1626
1994
  parameters: {
1627
1995
  additionalProperties: false,
1628
1996
  properties: {
1629
1997
  uri: {
1630
- 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.',
1631
1999
  type: 'string'
1632
2000
  }
1633
2001
  },
@@ -1638,16 +2006,25 @@ const getReadFileTool = () => {
1638
2006
  type: 'function'
1639
2007
  };
1640
2008
  };
1641
- const getWriteFileTool = () => {
2009
+
2010
+ const getEditFileTool = () => {
1642
2011
  return {
1643
2012
  function: {
1644
- 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.',
1645
- 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',
1646
2015
  parameters: {
1647
2016
  additionalProperties: false,
1648
2017
  properties: {
1649
- content: {
1650
- 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).',
1651
2028
  type: 'string'
1652
2029
  },
1653
2030
  uri: {
@@ -1655,69 +2032,87 @@ const getWriteFileTool = () => {
1655
2032
  type: 'string'
1656
2033
  }
1657
2034
  },
1658
- required: ['uri', 'content'],
2035
+ required: ['uri', 'start', 'end', 'text'],
1659
2036
  type: 'object'
1660
2037
  }
1661
2038
  },
1662
2039
  type: 'function'
1663
2040
  };
1664
2041
  };
1665
- const getRenameTool = () => {
2042
+
2043
+ const getGetWorkspaceUriTool = () => {
1666
2044
  return {
1667
2045
  function: {
1668
- 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).',
1669
- 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',
1670
2063
  parameters: {
1671
2064
  additionalProperties: false,
1672
2065
  properties: {
1673
- newUri: {
1674
- description: 'Absolute target URI for the file or folder after renaming.',
1675
- type: 'string'
1676
- },
1677
- oldUri: {
1678
- 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`.',
1679
2068
  type: 'string'
1680
2069
  }
1681
2070
  },
1682
- required: ['oldUri', 'newUri'],
2071
+ required: ['pattern'],
1683
2072
  type: 'object'
1684
2073
  }
1685
2074
  },
1686
2075
  type: 'function'
1687
2076
  };
1688
2077
  };
1689
- const getEditFileTool = () => {
2078
+
2079
+ const getGrepSearchTool = () => {
1690
2080
  return {
1691
2081
  function: {
1692
- 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.',
1693
- 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',
1694
2084
  parameters: {
1695
2085
  additionalProperties: false,
1696
2086
  properties: {
1697
- end: {
1698
- description: 'Zero-based end character offset (exclusive) in the current file content.',
1699
- type: 'number'
1700
- },
1701
- start: {
1702
- description: 'Zero-based start character offset (inclusive) in the current file content.',
1703
- 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'
1704
2090
  },
1705
- text: {
1706
- 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.',
1707
2093
  type: 'string'
1708
2094
  },
1709
- uri: {
1710
- 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.",
1711
2105
  type: 'string'
1712
2106
  }
1713
2107
  },
1714
- required: ['uri', 'start', 'end', 'text'],
2108
+ required: ['query', 'isRegexp'],
1715
2109
  type: 'object'
1716
2110
  }
1717
2111
  },
1718
2112
  type: 'function'
1719
2113
  };
1720
2114
  };
2115
+
1721
2116
  const getListFilesTool = () => {
1722
2117
  return {
1723
2118
  function: {
@@ -1738,48 +2133,28 @@ const getListFilesTool = () => {
1738
2133
  type: 'function'
1739
2134
  };
1740
2135
  };
1741
- const getGetWorkspaceUriTool = () => {
1742
- return {
1743
- function: {
1744
- 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.',
1745
- name: 'getWorkspaceUri',
1746
- parameters: {
1747
- additionalProperties: false,
1748
- properties: {},
1749
- type: 'object'
1750
- }
1751
- },
1752
- type: 'function'
1753
- };
1754
- };
1755
- const getRenderHtmlTool = () => {
2136
+
2137
+ const getOpenEditorTool = () => {
1756
2138
  return {
1757
2139
  function: {
1758
- 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.',
1759
- name: 'render_html',
2140
+ description: 'Open a file URI in the editor.',
2141
+ name: 'openEditor',
1760
2142
  parameters: {
1761
2143
  additionalProperties: false,
1762
2144
  properties: {
1763
- css: {
1764
- description: 'Optional CSS string applied inside the preview document.',
1765
- type: 'string'
1766
- },
1767
- html: {
1768
- description: 'HTML string to render in the preview document.',
1769
- type: 'string'
1770
- },
1771
- title: {
1772
- 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.',
1773
2147
  type: 'string'
1774
2148
  }
1775
2149
  },
1776
- required: ['html'],
2150
+ required: ['uri'],
1777
2151
  type: 'object'
1778
2152
  }
1779
2153
  },
1780
2154
  type: 'function'
1781
2155
  };
1782
2156
  };
2157
+
1783
2158
  const getOpenPreviewTool = () => {
1784
2159
  return {
1785
2160
  function: {
@@ -1800,11 +2175,12 @@ const getOpenPreviewTool = () => {
1800
2175
  type: 'function'
1801
2176
  };
1802
2177
  };
1803
- const getOpenEditorTool = () => {
2178
+
2179
+ const getReadFileTool = () => {
1804
2180
  return {
1805
2181
  function: {
1806
- description: 'Open a file URI in the editor.',
1807
- 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',
1808
2184
  parameters: {
1809
2185
  additionalProperties: false,
1810
2186
  properties: {
@@ -1820,61 +2196,61 @@ const getOpenEditorTool = () => {
1820
2196
  type: 'function'
1821
2197
  };
1822
2198
  };
1823
- const getClosePreviewTool = () => {
2199
+
2200
+ const getRenameTool = () => {
1824
2201
  return {
1825
2202
  function: {
1826
- description: 'Close the right-side preview if it is currently open.',
1827
- 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',
1828
2205
  parameters: {
1829
2206
  additionalProperties: false,
1830
- 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'],
1831
2218
  type: 'object'
1832
2219
  }
1833
2220
  },
1834
2221
  type: 'function'
1835
2222
  };
1836
2223
  };
1837
- const getSearchTextTool = () => {
2224
+
2225
+ const getRenderHtmlTool = () => {
1838
2226
  return {
1839
2227
  function: {
1840
- description: 'Search text in workspace files using query options and return matching results.',
1841
- 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',
1842
2230
  parameters: {
1843
2231
  additionalProperties: false,
1844
2232
  properties: {
1845
- options: {
1846
- additionalProperties: false,
1847
- properties: {
1848
- exclude: {
1849
- items: {
1850
- type: 'string'
1851
- },
1852
- type: 'array'
1853
- },
1854
- isRegex: {
1855
- type: 'boolean'
1856
- },
1857
- machWholeWord: {
1858
- type: 'boolean'
1859
- },
1860
- matchCase: {
1861
- type: 'boolean'
1862
- },
1863
- value: {
1864
- type: 'string'
1865
- }
1866
- },
1867
- required: ['value', 'isRegex', 'matchCase', 'machWholeWord', 'exclude'],
1868
- 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'
1869
2244
  }
1870
2245
  },
1871
- required: ['options'],
2246
+ required: ['html'],
1872
2247
  type: 'object'
1873
2248
  }
1874
2249
  },
1875
2250
  type: 'function'
1876
2251
  };
1877
2252
  };
2253
+
1878
2254
  const getRgTool = () => {
1879
2255
  return {
1880
2256
  function: {
@@ -1908,42 +2284,7 @@ const getRgTool = () => {
1908
2284
  type: 'function'
1909
2285
  };
1910
2286
  };
1911
- const getGrepSearchTool = () => {
1912
- return {
1913
- function: {
1914
- 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.",
1915
- name: 'grep_search',
1916
- parameters: {
1917
- additionalProperties: false,
1918
- properties: {
1919
- includeIgnoredFiles: {
1920
- 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.',
1921
- type: 'boolean'
1922
- },
1923
- includePattern: {
1924
- 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.',
1925
- type: 'string'
1926
- },
1927
- isRegexp: {
1928
- description: 'Whether the pattern is a regex.',
1929
- type: 'boolean'
1930
- },
1931
- maxResults: {
1932
- 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.",
1933
- type: 'number'
1934
- },
1935
- query: {
1936
- 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.",
1937
- type: 'string'
1938
- }
1939
- },
1940
- required: ['query', 'isRegexp'],
1941
- type: 'object'
1942
- }
1943
- },
1944
- type: 'function'
1945
- };
1946
- };
2287
+
1947
2288
  const getRunInTerminalTool = () => {
1948
2289
  return {
1949
2290
  function: {
@@ -1973,66 +2314,95 @@ const getRunInTerminalTool = () => {
1973
2314
  type: 'function'
1974
2315
  };
1975
2316
  };
1976
- const getCreateDirectoryTool = () => {
2317
+
2318
+ const getSearchTextTool = () => {
1977
2319
  return {
1978
2320
  function: {
1979
- 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.',
1980
- name: 'create_directory',
2321
+ description: 'Search text in workspace files using query options and return matching results.',
2322
+ name: 'search_text',
1981
2323
  parameters: {
1982
2324
  additionalProperties: false,
1983
2325
  properties: {
1984
- uri: {
1985
- description: 'Absolute URI for the target directory (for example `file://...`, `memfs://...`, or extension-provided file system URIs). Relative paths are not allowed.',
1986
- 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'
1987
2350
  }
1988
2351
  },
1989
- required: ['uri'],
2352
+ required: ['options'],
1990
2353
  type: 'object'
1991
2354
  }
1992
2355
  },
1993
2356
  type: 'function'
1994
2357
  };
1995
2358
  };
1996
- const getGlobTool = () => {
2359
+
2360
+ const getUpdateTodoTool = () => {
1997
2361
  return {
1998
2362
  function: {
1999
- description: 'Find files by glob pattern and return matching relative paths.',
2000
- 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',
2001
2365
  parameters: {
2002
2366
  additionalProperties: false,
2003
2367
  properties: {
2004
- pattern: {
2005
- 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.',
2006
2370
  type: 'string'
2007
2371
  }
2008
2372
  },
2009
- required: ['pattern'],
2373
+ required: ['todos'],
2010
2374
  type: 'object'
2011
2375
  }
2012
2376
  },
2013
2377
  type: 'function'
2014
2378
  };
2015
2379
  };
2016
- const getUpdateTodoTool = () => {
2380
+
2381
+ const getWriteFileTool = () => {
2017
2382
  return {
2018
2383
  function: {
2019
- 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").',
2020
- 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',
2021
2386
  parameters: {
2022
2387
  additionalProperties: false,
2023
2388
  properties: {
2024
- todos: {
2025
- 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.',
2026
2395
  type: 'string'
2027
2396
  }
2028
2397
  },
2029
- required: ['todos'],
2398
+ required: ['uri', 'content'],
2030
2399
  type: 'object'
2031
2400
  }
2032
2401
  },
2033
2402
  type: 'function'
2034
2403
  };
2035
2404
  };
2405
+
2036
2406
  const getBasicChatTools = () => {
2037
2407
  return [getReadFileTool(), getWriteFileTool(), getRenameTool(), getEditFileTool(), getListFilesTool(), getGetWorkspaceUriTool(), getRenderHtmlTool(), getOpenPreviewTool(), getOpenEditorTool(), getClosePreviewTool(), getSearchTextTool(), getRgTool(), getGrepSearchTool(), getRunInTerminalTool(), getCreateDirectoryTool(), getGlobTool(), getUpdateTodoTool()];
2038
2408
  };
@@ -2050,6 +2420,28 @@ const commandMap = {
2050
2420
  'HandleMessagePort.handleMessagePort': handleMessagePort
2051
2421
  };
2052
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
+
2053
2445
  const initializeRendererWorker = async () => {
2054
2446
  const rpc = await create$1({
2055
2447
  commandMap: commandMap
@@ -2058,7 +2450,7 @@ const initializeRendererWorker = async () => {
2058
2450
  };
2059
2451
 
2060
2452
  const listen = async () => {
2061
- await initializeRendererWorker();
2453
+ await Promise.all([initializeRendererWorker(), initializeFileSystemWorker(), initializeChatStorageWorker()]);
2062
2454
  };
2063
2455
 
2064
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.11.0",
3
+ "version": "7.12.0",
4
4
  "description": "Chat Tool Worker",
5
5
  "repository": {
6
6
  "type": "git",