@lvce-editor/chat-tool-worker 7.1.0 → 7.3.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.
@@ -909,7 +909,7 @@ const createMockRpc = ({
909
909
  };
910
910
 
911
911
  const rpcs = Object.create(null);
912
- const set = (id, rpc) => {
912
+ const set$1 = (id, rpc) => {
913
913
  rpcs[id] = rpc;
914
914
  };
915
915
  const get = id => {
@@ -942,7 +942,7 @@ const create = rpcId => {
942
942
  const mockRpc = createMockRpc({
943
943
  commandMap
944
944
  });
945
- set(rpcId, mockRpc);
945
+ set$1(rpcId, mockRpc);
946
946
  // @ts-ignore
947
947
  mockRpc[Symbol.dispose] = () => {
948
948
  remove(rpcId);
@@ -951,7 +951,7 @@ const create = rpcId => {
951
951
  return mockRpc;
952
952
  },
953
953
  set(rpc) {
954
- set(rpcId, rpc);
954
+ set$1(rpcId, rpc);
955
955
  }
956
956
  };
957
957
  };
@@ -959,7 +959,9 @@ const create = rpcId => {
959
959
  const RendererWorker = 1;
960
960
 
961
961
  const {
962
- invoke} = create(RendererWorker);
962
+ invoke,
963
+ set
964
+ } = create(RendererWorker);
963
965
  const readFile = async uri => {
964
966
  return invoke('FileSystem.readFile', uri);
965
967
  };
@@ -1015,6 +1017,12 @@ const executeListFilesTool = async (args, _options) => {
1015
1017
  error: 'Invalid argument: uri must be an absolute URI.'
1016
1018
  };
1017
1019
  }
1020
+ if (uri === 'file:///workspace' || uri.startsWith('file:///workspace/')) {
1021
+ return {
1022
+ error: 'Invalid argument: uri must be a real workspace folder URI. Call getWorkspaceUri first and use the returned workspaceUri value.',
1023
+ uri
1024
+ };
1025
+ }
1018
1026
  try {
1019
1027
  const entries = await invoke('FileSystem.readDirWithFileTypes', uri);
1020
1028
  return {
@@ -1071,72 +1079,23 @@ const executeOpenPreviewTool = async (args, _options) => {
1071
1079
  }
1072
1080
  };
1073
1081
 
1074
- const WINDOWS_ABSOLUTE_PATH_REGEX = /^[a-zA-Z]:[\\/]/;
1075
- const PATH_SEGMENT_SPLIT_REGEX$1 = /[\\/]/;
1076
- const isPathTraversalAttempt = path => {
1077
- if (!path) {
1078
- return false;
1079
- }
1080
- if (path.startsWith('/') || path.startsWith('\\')) {
1081
- return true;
1082
- }
1083
- if (path.startsWith('file://')) {
1084
- return true;
1085
- }
1086
- if (WINDOWS_ABSOLUTE_PATH_REGEX.test(path)) {
1087
- return true;
1088
- }
1089
- const segments = path.split(PATH_SEGMENT_SPLIT_REGEX$1);
1090
- return segments.includes('..');
1091
- };
1092
-
1093
- const PATH_SEGMENT_SPLIT_REGEX = /[\\/]/;
1094
- const normalizeRelativePath = path => {
1095
- const segments = path.split(PATH_SEGMENT_SPLIT_REGEX).filter(segment => segment && segment !== '.');
1096
- if (segments.length === 0) {
1097
- return '.';
1098
- }
1099
- return segments.join('/');
1100
- };
1101
-
1102
1082
  const executeReadFileTool = async (args, _options) => {
1103
1083
  const uri = typeof args.uri === 'string' ? args.uri : '';
1104
- if (uri) {
1105
- if (!isAbsoluteUri(uri)) {
1106
- return {
1107
- error: 'Invalid argument: uri must be an absolute URI.'
1108
- };
1109
- }
1110
- try {
1111
- const content = await readFile(uri);
1112
- return {
1113
- content,
1114
- uri
1115
- };
1116
- } catch (error) {
1117
- return {
1118
- ...getToolErrorPayload(error),
1119
- uri
1120
- };
1121
- }
1122
- }
1123
- const filePath = typeof args.path === 'string' ? args.path : '';
1124
- if (!filePath || isPathTraversalAttempt(filePath)) {
1084
+ if (!uri || !isAbsoluteUri(uri)) {
1125
1085
  return {
1126
- error: 'Access denied: path must be relative and stay within the open workspace folder.'
1086
+ error: 'Invalid argument: uri must be an absolute URI.'
1127
1087
  };
1128
1088
  }
1129
- const normalizedPath = normalizeRelativePath(filePath);
1130
1089
  try {
1131
- const content = await readFile(normalizedPath);
1090
+ const content = await readFile(uri);
1132
1091
  return {
1133
1092
  content,
1134
- path: normalizedPath
1093
+ uri
1135
1094
  };
1136
1095
  } catch (error) {
1137
1096
  return {
1138
1097
  ...getToolErrorPayload(error),
1139
- path: normalizedPath
1098
+ uri
1140
1099
  };
1141
1100
  }
1142
1101
  };
@@ -1248,7 +1207,7 @@ const getReadFileTool = () => {
1248
1207
  additionalProperties: false,
1249
1208
  properties: {
1250
1209
  uri: {
1251
- description: 'Absolute file URI within the workspace (for example: file:///workspace/src/index.ts).',
1210
+ description: 'Absolute file URI for a real path inside the currently open workspace folder. Do not use placeholder URIs.',
1252
1211
  type: 'string'
1253
1212
  }
1254
1213
  },
@@ -1262,7 +1221,7 @@ const getReadFileTool = () => {
1262
1221
  const getWriteFileTool = () => {
1263
1222
  return {
1264
1223
  function: {
1265
- description: 'Write UTF-8 text content to a file inside the currently open workspace folder. Only pass an absolute URI.',
1224
+ 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.',
1266
1225
  name: 'write_file',
1267
1226
  parameters: {
1268
1227
  additionalProperties: false,
@@ -1272,7 +1231,7 @@ const getWriteFileTool = () => {
1272
1231
  type: 'string'
1273
1232
  },
1274
1233
  uri: {
1275
- description: 'Absolute file URI within the workspace (for example: file:///workspace/src/index.ts).',
1234
+ description: 'Absolute URI for the target file (for example `file://...`, `memfs://...`, or extension-provided file system URIs). Relative paths are not allowed.',
1276
1235
  type: 'string'
1277
1236
  }
1278
1237
  },
@@ -1286,13 +1245,13 @@ const getWriteFileTool = () => {
1286
1245
  const getListFilesTool = () => {
1287
1246
  return {
1288
1247
  function: {
1289
- description: 'List direct children (files and folders) for a folder URI inside the currently open workspace folder. Only pass an absolute URI.',
1248
+ description: 'List direct children (files and folders) for a folder URI inside the currently open workspace folder. If you do not already have a real workspace URI, call getWorkspaceUri first and then use that returned URI. Do not use placeholder URIs like file:///workspace.',
1290
1249
  name: 'list_files',
1291
1250
  parameters: {
1292
1251
  additionalProperties: false,
1293
1252
  properties: {
1294
1253
  uri: {
1295
- description: 'Absolute folder URI within the workspace (for example: file:///workspace/src).',
1254
+ description: 'Absolute folder URI for a real path inside the currently open workspace folder. If unknown, call getWorkspaceUri first and pass the returned workspaceUri value. Do not use placeholder URIs.',
1296
1255
  type: 'string'
1297
1256
  }
1298
1257
  },
@@ -1306,7 +1265,7 @@ const getListFilesTool = () => {
1306
1265
  const getGetWorkspaceUriTool = () => {
1307
1266
  return {
1308
1267
  function: {
1309
- description: 'Get the URI of the currently open workspace folder.',
1268
+ description: 'Get the URI of the currently open workspace folder. Call this first before using list_files, read_file, write_file, open_preview, or openEditor when you do not already have a concrete workspace URI.',
1310
1269
  name: 'getWorkspaceUri',
1311
1270
  parameters: {
1312
1271
  additionalProperties: false,
@@ -1354,7 +1313,7 @@ const getOpenPreviewTool = () => {
1354
1313
  additionalProperties: false,
1355
1314
  properties: {
1356
1315
  uri: {
1357
- description: 'Absolute HTML file URI within the workspace (for example: file:///workspace/index.html).',
1316
+ description: 'Absolute HTML file URI for a real path inside the currently open workspace folder. Do not use placeholder URIs.',
1358
1317
  type: 'string'
1359
1318
  }
1360
1319
  },
@@ -1374,7 +1333,7 @@ const getOpenEditorTool = () => {
1374
1333
  additionalProperties: false,
1375
1334
  properties: {
1376
1335
  uri: {
1377
- description: 'Absolute file URI to open in the editor (for example: file:///workspace/src/index.ts).',
1336
+ description: 'Absolute file URI for a real path inside the currently open workspace folder. Do not use placeholder URIs.',
1378
1337
  type: 'string'
1379
1338
  }
1380
1339
  },
@@ -1417,9 +1376,10 @@ const commandMap = {
1417
1376
  };
1418
1377
 
1419
1378
  const listen = async () => {
1420
- await create$1({
1379
+ const rpc = await create$1({
1421
1380
  commandMap: commandMap
1422
1381
  });
1382
+ set(rpc);
1423
1383
  };
1424
1384
 
1425
1385
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/chat-tool-worker",
3
- "version": "7.1.0",
3
+ "version": "7.3.0",
4
4
  "description": "Chat Tool Worker",
5
5
  "repository": {
6
6
  "type": "git",