@lvce-editor/chat-tool-worker 7.0.0 → 7.2.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.
- package/dist/chatToolWorkerMain.js +52 -57
- package/package.json +1 -1
|
@@ -1029,7 +1029,7 @@ const executeListFilesTool = async (args, _options) => {
|
|
|
1029
1029
|
}
|
|
1030
1030
|
};
|
|
1031
1031
|
|
|
1032
|
-
const
|
|
1032
|
+
const executeOpenEditorTool = async (args, _options) => {
|
|
1033
1033
|
const uri = typeof args.uri === 'string' ? args.uri : '';
|
|
1034
1034
|
if (!uri || !isAbsoluteUri(uri)) {
|
|
1035
1035
|
return {
|
|
@@ -1037,7 +1037,7 @@ const executeOpenPreviewTool = async (args, _options) => {
|
|
|
1037
1037
|
};
|
|
1038
1038
|
}
|
|
1039
1039
|
try {
|
|
1040
|
-
await invoke('
|
|
1040
|
+
await invoke('Main.openUri', uri);
|
|
1041
1041
|
return {
|
|
1042
1042
|
ok: true,
|
|
1043
1043
|
uri
|
|
@@ -1050,72 +1050,44 @@ const executeOpenPreviewTool = async (args, _options) => {
|
|
|
1050
1050
|
}
|
|
1051
1051
|
};
|
|
1052
1052
|
|
|
1053
|
-
const
|
|
1054
|
-
const
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
if (path.startsWith('/') || path.startsWith('\\')) {
|
|
1060
|
-
return true;
|
|
1061
|
-
}
|
|
1062
|
-
if (path.startsWith('file://')) {
|
|
1063
|
-
return true;
|
|
1064
|
-
}
|
|
1065
|
-
if (WINDOWS_ABSOLUTE_PATH_REGEX.test(path)) {
|
|
1066
|
-
return true;
|
|
1053
|
+
const executeOpenPreviewTool = async (args, _options) => {
|
|
1054
|
+
const uri = typeof args.uri === 'string' ? args.uri : '';
|
|
1055
|
+
if (!uri || !isAbsoluteUri(uri)) {
|
|
1056
|
+
return {
|
|
1057
|
+
error: 'Invalid argument: uri must be an absolute URI.'
|
|
1058
|
+
};
|
|
1067
1059
|
}
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1060
|
+
try {
|
|
1061
|
+
await invoke('Preview.open', uri);
|
|
1062
|
+
return {
|
|
1063
|
+
ok: true,
|
|
1064
|
+
uri
|
|
1065
|
+
};
|
|
1066
|
+
} catch (error) {
|
|
1067
|
+
return {
|
|
1068
|
+
...getToolErrorPayload(error),
|
|
1069
|
+
uri
|
|
1070
|
+
};
|
|
1077
1071
|
}
|
|
1078
|
-
return segments.join('/');
|
|
1079
1072
|
};
|
|
1080
1073
|
|
|
1081
1074
|
const executeReadFileTool = async (args, _options) => {
|
|
1082
1075
|
const uri = typeof args.uri === 'string' ? args.uri : '';
|
|
1083
|
-
if (uri) {
|
|
1084
|
-
if (!isAbsoluteUri(uri)) {
|
|
1085
|
-
return {
|
|
1086
|
-
error: 'Invalid argument: uri must be an absolute URI.'
|
|
1087
|
-
};
|
|
1088
|
-
}
|
|
1089
|
-
try {
|
|
1090
|
-
const content = await readFile(uri);
|
|
1091
|
-
return {
|
|
1092
|
-
content,
|
|
1093
|
-
uri
|
|
1094
|
-
};
|
|
1095
|
-
} catch (error) {
|
|
1096
|
-
return {
|
|
1097
|
-
...getToolErrorPayload(error),
|
|
1098
|
-
uri
|
|
1099
|
-
};
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
const filePath = typeof args.path === 'string' ? args.path : '';
|
|
1103
|
-
if (!filePath || isPathTraversalAttempt(filePath)) {
|
|
1076
|
+
if (!uri || !isAbsoluteUri(uri)) {
|
|
1104
1077
|
return {
|
|
1105
|
-
error: '
|
|
1078
|
+
error: 'Invalid argument: uri must be an absolute URI.'
|
|
1106
1079
|
};
|
|
1107
1080
|
}
|
|
1108
|
-
const normalizedPath = normalizeRelativePath(filePath);
|
|
1109
1081
|
try {
|
|
1110
|
-
const content = await readFile(
|
|
1082
|
+
const content = await readFile(uri);
|
|
1111
1083
|
return {
|
|
1112
1084
|
content,
|
|
1113
|
-
|
|
1085
|
+
uri
|
|
1114
1086
|
};
|
|
1115
1087
|
} catch (error) {
|
|
1116
1088
|
return {
|
|
1117
1089
|
...getToolErrorPayload(error),
|
|
1118
|
-
|
|
1090
|
+
uri
|
|
1119
1091
|
};
|
|
1120
1092
|
}
|
|
1121
1093
|
};
|
|
@@ -1207,6 +1179,9 @@ const executeChatTool = async (name, rawArguments, options) => {
|
|
|
1207
1179
|
if (name === 'open_preview') {
|
|
1208
1180
|
return executeOpenPreviewTool(args);
|
|
1209
1181
|
}
|
|
1182
|
+
if (name === 'openEditor') {
|
|
1183
|
+
return executeOpenEditorTool(args);
|
|
1184
|
+
}
|
|
1210
1185
|
if (name === 'close_preview') {
|
|
1211
1186
|
return executeClosePreviewTool();
|
|
1212
1187
|
}
|
|
@@ -1224,7 +1199,7 @@ const getReadFileTool = () => {
|
|
|
1224
1199
|
additionalProperties: false,
|
|
1225
1200
|
properties: {
|
|
1226
1201
|
uri: {
|
|
1227
|
-
description: 'Absolute file URI
|
|
1202
|
+
description: 'Absolute file URI for a real path inside the currently open workspace folder. Do not use placeholder URIs.',
|
|
1228
1203
|
type: 'string'
|
|
1229
1204
|
}
|
|
1230
1205
|
},
|
|
@@ -1248,7 +1223,7 @@ const getWriteFileTool = () => {
|
|
|
1248
1223
|
type: 'string'
|
|
1249
1224
|
},
|
|
1250
1225
|
uri: {
|
|
1251
|
-
description: 'Absolute file URI
|
|
1226
|
+
description: 'Absolute file URI for a real path inside the currently open workspace folder. Do not use placeholder URIs.',
|
|
1252
1227
|
type: 'string'
|
|
1253
1228
|
}
|
|
1254
1229
|
},
|
|
@@ -1268,7 +1243,7 @@ const getListFilesTool = () => {
|
|
|
1268
1243
|
additionalProperties: false,
|
|
1269
1244
|
properties: {
|
|
1270
1245
|
uri: {
|
|
1271
|
-
description: 'Absolute folder URI
|
|
1246
|
+
description: 'Absolute folder URI for a real path inside the currently open workspace folder. Do not use placeholder URIs.',
|
|
1272
1247
|
type: 'string'
|
|
1273
1248
|
}
|
|
1274
1249
|
},
|
|
@@ -1330,7 +1305,27 @@ const getOpenPreviewTool = () => {
|
|
|
1330
1305
|
additionalProperties: false,
|
|
1331
1306
|
properties: {
|
|
1332
1307
|
uri: {
|
|
1333
|
-
description: 'Absolute HTML file URI
|
|
1308
|
+
description: 'Absolute HTML file URI for a real path inside the currently open workspace folder. Do not use placeholder URIs.',
|
|
1309
|
+
type: 'string'
|
|
1310
|
+
}
|
|
1311
|
+
},
|
|
1312
|
+
required: ['uri'],
|
|
1313
|
+
type: 'object'
|
|
1314
|
+
}
|
|
1315
|
+
},
|
|
1316
|
+
type: 'function'
|
|
1317
|
+
};
|
|
1318
|
+
};
|
|
1319
|
+
const getOpenEditorTool = () => {
|
|
1320
|
+
return {
|
|
1321
|
+
function: {
|
|
1322
|
+
description: 'Open a file URI in the editor.',
|
|
1323
|
+
name: 'openEditor',
|
|
1324
|
+
parameters: {
|
|
1325
|
+
additionalProperties: false,
|
|
1326
|
+
properties: {
|
|
1327
|
+
uri: {
|
|
1328
|
+
description: 'Absolute file URI for a real path inside the currently open workspace folder. Do not use placeholder URIs.',
|
|
1334
1329
|
type: 'string'
|
|
1335
1330
|
}
|
|
1336
1331
|
},
|
|
@@ -1356,7 +1351,7 @@ const getClosePreviewTool = () => {
|
|
|
1356
1351
|
};
|
|
1357
1352
|
};
|
|
1358
1353
|
const getBasicChatTools = () => {
|
|
1359
|
-
return [getReadFileTool(), getWriteFileTool(), getListFilesTool(), getGetWorkspaceUriTool(), getRenderHtmlTool(), getOpenPreviewTool(), getClosePreviewTool()];
|
|
1354
|
+
return [getReadFileTool(), getWriteFileTool(), getListFilesTool(), getGetWorkspaceUriTool(), getRenderHtmlTool(), getOpenPreviewTool(), getOpenEditorTool(), getClosePreviewTool()];
|
|
1360
1355
|
};
|
|
1361
1356
|
|
|
1362
1357
|
const handleMessagePort = async port => {
|