@lvce-editor/chat-tool-worker 8.5.0 → 8.6.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 {
@@ -1987,9 +1994,7 @@ const mapEntry = entry => ({
1987
1994
  const executeListFilesTool = async (args, _options) => {
1988
1995
  const uri = typeof args.uri === 'string' ? args.uri : '';
1989
1996
  if (!uri || !isAbsoluteUri(uri)) {
1990
- return {
1991
- error: 'Invalid argument: uri must be an absolute URI.'
1992
- };
1997
+ return getInvalidUriErrorPayload('uri');
1993
1998
  }
1994
1999
  if (uri === 'file:///workspace' || uri.startsWith('file:///workspace/')) {
1995
2000
  return {
@@ -2014,9 +2019,7 @@ const executeListFilesTool = async (args, _options) => {
2014
2019
  const executeOpenEditorTool = async (args, _options) => {
2015
2020
  const uri = typeof args.uri === 'string' ? args.uri : '';
2016
2021
  if (!uri || !isAbsoluteUri(uri)) {
2017
- return {
2018
- error: 'Invalid argument: uri must be an absolute URI.'
2019
- };
2022
+ return getInvalidUriErrorPayload('uri');
2020
2023
  }
2021
2024
  try {
2022
2025
  await invoke$1('Main.openUri', uri);
@@ -2035,9 +2038,7 @@ const executeOpenEditorTool = async (args, _options) => {
2035
2038
  const executeOpenPreviewTool = async (args, _options) => {
2036
2039
  const uri = typeof args.uri === 'string' ? args.uri : '';
2037
2040
  if (!uri || !isAbsoluteUri(uri)) {
2038
- return {
2039
- error: 'Invalid argument: uri must be an absolute URI.'
2040
- };
2041
+ return getInvalidUriErrorPayload('uri');
2041
2042
  }
2042
2043
  try {
2043
2044
  await invoke$1('Preview.open', uri);
@@ -2056,21 +2057,15 @@ const executeOpenPreviewTool = async (args, _options) => {
2056
2057
  const executeReadFileTool = async (args, _options) => {
2057
2058
  const uri = typeof args.uri === 'string' ? args.uri : '';
2058
2059
  if (!uri || !isAbsoluteUri(uri)) {
2059
- return {
2060
- error: 'Invalid argument: uri must be an absolute URI.'
2061
- };
2060
+ return getInvalidUriErrorPayload('uri');
2062
2061
  }
2063
2062
  try {
2064
2063
  const content = await readFile(uri);
2065
2064
  return {
2066
- content,
2067
- uri
2065
+ content
2068
2066
  };
2069
2067
  } catch (error) {
2070
- return {
2071
- ...getToolErrorPayload(error),
2072
- uri
2073
- };
2068
+ return getToolErrorPayload(error);
2074
2069
  }
2075
2070
  };
2076
2071
 
@@ -2078,19 +2073,13 @@ const executeRenameTool = async (args, _options) => {
2078
2073
  const oldUri = typeof args.oldUri === 'string' ? args.oldUri : '';
2079
2074
  const newUri = typeof args.newUri === 'string' ? args.newUri : '';
2080
2075
  if (!oldUri || !isAbsoluteUri(oldUri)) {
2081
- return {
2082
- error: 'Invalid argument: oldUri must be an absolute URI.'
2083
- };
2076
+ return getInvalidUriErrorPayload('oldUri');
2084
2077
  }
2085
2078
  if (!newUri || !isAbsoluteUri(newUri)) {
2086
- return {
2087
- error: 'Invalid argument: newUri must be an absolute URI.'
2088
- };
2079
+ return getInvalidUriErrorPayload('newUri');
2089
2080
  }
2090
2081
  if (!URL.canParse(oldUri) || !URL.canParse(newUri)) {
2091
- return {
2092
- error: 'Invalid argument: invalid URL.'
2093
- };
2082
+ return getInvalidUrlErrorPayload();
2094
2083
  }
2095
2084
  const oldUrl = new URL(oldUri);
2096
2085
  const newUrl = new URL(newUri);
@@ -2423,16 +2412,12 @@ const executeWriteFileTool = async (args, _options) => {
2423
2412
  const uri = typeof args.uri === 'string' ? args.uri : '';
2424
2413
  const content = typeof args.content === 'string' ? args.content : '';
2425
2414
  if (!uri || !isAbsoluteUri(uri)) {
2426
- return {
2427
- error: 'Invalid argument: uri must be an absolute URI.'
2428
- };
2415
+ return getInvalidUriErrorPayload('uri');
2429
2416
  }
2430
2417
  try {
2431
2418
  new URL(uri);
2432
2419
  } catch {
2433
- return {
2434
- error: 'Invalid argument: invalid URL.'
2435
- };
2420
+ return getInvalidUrlErrorPayload();
2436
2421
  }
2437
2422
  try {
2438
2423
  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.6.0",
4
4
  "description": "Chat Tool Worker",
5
5
  "repository": {
6
6
  "type": "git",