@lvce-editor/chat-tool-worker 8.5.0 → 8.7.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.
@@ -1304,10 +1304,27 @@ const {
1304
1304
  set
1305
1305
  } = create(TerminalProcess);
1306
1306
 
1307
+ const INVALID_URI_ERROR_CODE = 'E_INVALID_URI';
1308
+ const getInvalidUriErrorPayload = argumentName => {
1309
+ return {
1310
+ error: `Invalid argument: ${argumentName} must be an absolute URI.`,
1311
+ errorCode: INVALID_URI_ERROR_CODE
1312
+ };
1313
+ };
1314
+ const getInvalidUrlErrorPayload = () => {
1315
+ return {
1316
+ error: 'Invalid argument: invalid URL.',
1317
+ errorCode: INVALID_URI_ERROR_CODE
1318
+ };
1319
+ };
1307
1320
  const getToolErrorPayload = error => {
1321
+ const rawCode = error && typeof error === 'object' ? Reflect.get(error, 'code') : undefined;
1308
1322
  const rawStack = error && typeof error === 'object' ? Reflect.get(error, 'stack') : undefined;
1309
1323
  return {
1310
1324
  error: String(error),
1325
+ ...(typeof rawCode === 'string' && rawCode.trim() ? {
1326
+ errorCode: rawCode
1327
+ } : {}),
1311
1328
  ...(typeof rawStack === 'string' && rawStack.trim() ? {
1312
1329
  errorStack: rawStack,
1313
1330
  stack: rawStack
@@ -1334,16 +1351,12 @@ const isAbsoluteUri = value => {
1334
1351
  const executeCreateDirectoryTool = async (args, _options) => {
1335
1352
  const uri = typeof args.uri === 'string' ? args.uri : '';
1336
1353
  if (!uri || !isAbsoluteUri(uri)) {
1337
- return {
1338
- error: 'Invalid argument: uri must be an absolute URI.'
1339
- };
1354
+ return getInvalidUriErrorPayload('uri');
1340
1355
  }
1341
1356
  try {
1342
1357
  new URL(uri);
1343
1358
  } catch {
1344
- return {
1345
- error: 'Invalid argument: invalid URL.'
1346
- };
1359
+ return getInvalidUrlErrorPayload();
1347
1360
  }
1348
1361
  try {
1349
1362
  await invoke$1('FileSystem.mkdir', uri);
@@ -1372,16 +1385,12 @@ const executeEditFileTool = async (args, _options) => {
1372
1385
  const end = typeof args.end === 'number' ? args.end : -1;
1373
1386
  const text = typeof args.text === 'string' ? args.text : '';
1374
1387
  if (!uri || !isAbsoluteUri(uri)) {
1375
- return {
1376
- error: 'Invalid argument: uri must be an absolute URI.'
1377
- };
1388
+ return getInvalidUriErrorPayload('uri');
1378
1389
  }
1379
1390
  try {
1380
1391
  new URL(uri);
1381
1392
  } catch {
1382
- return {
1383
- error: 'Invalid argument: invalid URL.'
1384
- };
1393
+ return getInvalidUrlErrorPayload();
1385
1394
  }
1386
1395
  if (!Number.isInteger(start) || start < 0) {
1387
1396
  return {
@@ -1625,9 +1634,7 @@ const executeGlobTool = async (args, _options) => {
1625
1634
  }
1626
1635
  const baseUri = typeof args.baseUri === 'string' ? args.baseUri : '';
1627
1636
  if (!baseUri || !isAbsoluteUri(baseUri)) {
1628
- return {
1629
- error: 'Invalid argument: baseUri must be an absolute URI.'
1630
- };
1637
+ return getInvalidUriErrorPayload('baseUri');
1631
1638
  }
1632
1639
  if (baseUri === PLACEHOLDER_WORKSPACE_URI || baseUri.startsWith(`${PLACEHOLDER_WORKSPACE_URI}/`)) {
1633
1640
  return {
@@ -1837,9 +1844,7 @@ const executeFileGrepSearch = async (workspaceUri, grepSearchArgs) => {
1837
1844
  searchDir: getSearchDir(workspaceUri, grepSearchArgs.includePattern)
1838
1845
  });
1839
1846
  return {
1840
- arguments: grepSearchArgs,
1841
1847
  result: formatSearchProcessResults(result.results, grepSearchArgs.outputFormat),
1842
- workspaceUri,
1843
1848
  ...(result.limitHit ? {
1844
1849
  warning: 'Search result limit reached.'
1845
1850
  } : {})
@@ -1885,9 +1890,7 @@ const executeMemoryGrepSearch = async (workspaceUri, grepSearchArgs, options) =>
1885
1890
  try {
1886
1891
  const result = await invoke$1('ExtensionHostTextSearch.textSearchMemory2', searchOptions.scheme, workspaceUri, grepSearchArgs.query, searchOptions, options.assetDir);
1887
1892
  return {
1888
- arguments: grepSearchArgs,
1889
1893
  result: formatLegacyMemorySearchResults(result.results || [], grepSearchArgs.outputFormat),
1890
- workspaceUri,
1891
1894
  ...(result.limitHit ? {
1892
1895
  warning: 'Search result limit reached.'
1893
1896
  } : {})
@@ -1895,9 +1898,7 @@ const executeMemoryGrepSearch = async (workspaceUri, grepSearchArgs, options) =>
1895
1898
  } catch {
1896
1899
  const legacyResults = await invoke$1('ExtensionHostTextSearch.textSearchMemory', searchOptions.scheme, workspaceUri, grepSearchArgs.query, searchOptions, options.assetDir);
1897
1900
  return {
1898
- arguments: grepSearchArgs,
1899
- result: isLegacyMemorySearchResult(legacyResults) ? formatLegacyMemorySearchResults(legacyResults, grepSearchArgs.outputFormat) : 'No matches found.',
1900
- workspaceUri
1901
+ result: isLegacyMemorySearchResult(legacyResults) ? formatLegacyMemorySearchResults(legacyResults, grepSearchArgs.outputFormat) : 'No matches found.'
1901
1902
  };
1902
1903
  }
1903
1904
  };
@@ -1987,9 +1988,7 @@ const mapEntry = entry => ({
1987
1988
  const executeListFilesTool = async (args, _options) => {
1988
1989
  const uri = typeof args.uri === 'string' ? args.uri : '';
1989
1990
  if (!uri || !isAbsoluteUri(uri)) {
1990
- return {
1991
- error: 'Invalid argument: uri must be an absolute URI.'
1992
- };
1991
+ return getInvalidUriErrorPayload('uri');
1993
1992
  }
1994
1993
  if (uri === 'file:///workspace' || uri.startsWith('file:///workspace/')) {
1995
1994
  return {
@@ -2014,9 +2013,7 @@ const executeListFilesTool = async (args, _options) => {
2014
2013
  const executeOpenEditorTool = async (args, _options) => {
2015
2014
  const uri = typeof args.uri === 'string' ? args.uri : '';
2016
2015
  if (!uri || !isAbsoluteUri(uri)) {
2017
- return {
2018
- error: 'Invalid argument: uri must be an absolute URI.'
2019
- };
2016
+ return getInvalidUriErrorPayload('uri');
2020
2017
  }
2021
2018
  try {
2022
2019
  await invoke$1('Main.openUri', uri);
@@ -2035,9 +2032,7 @@ const executeOpenEditorTool = async (args, _options) => {
2035
2032
  const executeOpenPreviewTool = async (args, _options) => {
2036
2033
  const uri = typeof args.uri === 'string' ? args.uri : '';
2037
2034
  if (!uri || !isAbsoluteUri(uri)) {
2038
- return {
2039
- error: 'Invalid argument: uri must be an absolute URI.'
2040
- };
2035
+ return getInvalidUriErrorPayload('uri');
2041
2036
  }
2042
2037
  try {
2043
2038
  await invoke$1('Preview.open', uri);
@@ -2056,21 +2051,15 @@ const executeOpenPreviewTool = async (args, _options) => {
2056
2051
  const executeReadFileTool = async (args, _options) => {
2057
2052
  const uri = typeof args.uri === 'string' ? args.uri : '';
2058
2053
  if (!uri || !isAbsoluteUri(uri)) {
2059
- return {
2060
- error: 'Invalid argument: uri must be an absolute URI.'
2061
- };
2054
+ return getInvalidUriErrorPayload('uri');
2062
2055
  }
2063
2056
  try {
2064
2057
  const content = await readFile(uri);
2065
2058
  return {
2066
- content,
2067
- uri
2059
+ content
2068
2060
  };
2069
2061
  } catch (error) {
2070
- return {
2071
- ...getToolErrorPayload(error),
2072
- uri
2073
- };
2062
+ return getToolErrorPayload(error);
2074
2063
  }
2075
2064
  };
2076
2065
 
@@ -2078,19 +2067,13 @@ const executeRenameTool = async (args, _options) => {
2078
2067
  const oldUri = typeof args.oldUri === 'string' ? args.oldUri : '';
2079
2068
  const newUri = typeof args.newUri === 'string' ? args.newUri : '';
2080
2069
  if (!oldUri || !isAbsoluteUri(oldUri)) {
2081
- return {
2082
- error: 'Invalid argument: oldUri must be an absolute URI.'
2083
- };
2070
+ return getInvalidUriErrorPayload('oldUri');
2084
2071
  }
2085
2072
  if (!newUri || !isAbsoluteUri(newUri)) {
2086
- return {
2087
- error: 'Invalid argument: newUri must be an absolute URI.'
2088
- };
2073
+ return getInvalidUriErrorPayload('newUri');
2089
2074
  }
2090
2075
  if (!URL.canParse(oldUri) || !URL.canParse(newUri)) {
2091
- return {
2092
- error: 'Invalid argument: invalid URL.'
2093
- };
2076
+ return getInvalidUrlErrorPayload();
2094
2077
  }
2095
2078
  const oldUrl = new URL(oldUri);
2096
2079
  const newUrl = new URL(newUri);
@@ -2423,16 +2406,12 @@ const executeWriteFileTool = async (args, _options) => {
2423
2406
  const uri = typeof args.uri === 'string' ? args.uri : '';
2424
2407
  const content = typeof args.content === 'string' ? args.content : '';
2425
2408
  if (!uri || !isAbsoluteUri(uri)) {
2426
- return {
2427
- error: 'Invalid argument: uri must be an absolute URI.'
2428
- };
2409
+ return getInvalidUriErrorPayload('uri');
2429
2410
  }
2430
2411
  try {
2431
2412
  new URL(uri);
2432
2413
  } catch {
2433
- return {
2434
- error: 'Invalid argument: invalid URL.'
2435
- };
2414
+ return getInvalidUrlErrorPayload();
2436
2415
  }
2437
2416
  try {
2438
2417
  const exists$1 = await exists(uri);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/chat-tool-worker",
3
- "version": "8.5.0",
3
+ "version": "8.7.0",
4
4
  "description": "Chat Tool Worker",
5
5
  "repository": {
6
6
  "type": "git",