@lvce-editor/chat-tool-worker 6.0.0 → 7.0.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 +125 -47
- package/package.json +1 -1
|
@@ -981,14 +981,25 @@ const getToolErrorPayload = error => {
|
|
|
981
981
|
};
|
|
982
982
|
};
|
|
983
983
|
|
|
984
|
+
const executeClosePreviewTool = async (_args, _options) => {
|
|
985
|
+
try {
|
|
986
|
+
await invoke('Preview.close');
|
|
987
|
+
return {
|
|
988
|
+
ok: true
|
|
989
|
+
};
|
|
990
|
+
} catch (error) {
|
|
991
|
+
return getToolErrorPayload(error);
|
|
992
|
+
}
|
|
993
|
+
};
|
|
994
|
+
|
|
984
995
|
const executeGetWorkspaceUriTool = async (_args, _options) => {
|
|
985
996
|
try {
|
|
986
997
|
const workspaceUri = await getWorkspacePath();
|
|
987
|
-
return
|
|
998
|
+
return {
|
|
988
999
|
workspaceUri
|
|
989
|
-
}
|
|
1000
|
+
};
|
|
990
1001
|
} catch (error) {
|
|
991
|
-
return
|
|
1002
|
+
return getToolErrorPayload(error);
|
|
992
1003
|
}
|
|
993
1004
|
};
|
|
994
1005
|
|
|
@@ -1000,21 +1011,42 @@ const isAbsoluteUri = value => {
|
|
|
1000
1011
|
const executeListFilesTool = async (args, _options) => {
|
|
1001
1012
|
const uri = typeof args.uri === 'string' ? args.uri : '';
|
|
1002
1013
|
if (!uri || !isAbsoluteUri(uri)) {
|
|
1003
|
-
return
|
|
1014
|
+
return {
|
|
1004
1015
|
error: 'Invalid argument: uri must be an absolute URI.'
|
|
1005
|
-
}
|
|
1016
|
+
};
|
|
1006
1017
|
}
|
|
1007
1018
|
try {
|
|
1008
1019
|
const entries = await invoke('FileSystem.readDirWithFileTypes', uri);
|
|
1009
|
-
return
|
|
1020
|
+
return {
|
|
1010
1021
|
entries,
|
|
1011
1022
|
uri
|
|
1012
|
-
}
|
|
1023
|
+
};
|
|
1013
1024
|
} catch (error) {
|
|
1014
|
-
return
|
|
1025
|
+
return {
|
|
1015
1026
|
...getToolErrorPayload(error),
|
|
1016
1027
|
uri
|
|
1017
|
-
}
|
|
1028
|
+
};
|
|
1029
|
+
}
|
|
1030
|
+
};
|
|
1031
|
+
|
|
1032
|
+
const executeOpenPreviewTool = async (args, _options) => {
|
|
1033
|
+
const uri = typeof args.uri === 'string' ? args.uri : '';
|
|
1034
|
+
if (!uri || !isAbsoluteUri(uri)) {
|
|
1035
|
+
return {
|
|
1036
|
+
error: 'Invalid argument: uri must be an absolute URI.'
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
try {
|
|
1040
|
+
await invoke('Preview.open', uri);
|
|
1041
|
+
return {
|
|
1042
|
+
ok: true,
|
|
1043
|
+
uri
|
|
1044
|
+
};
|
|
1045
|
+
} catch (error) {
|
|
1046
|
+
return {
|
|
1047
|
+
...getToolErrorPayload(error),
|
|
1048
|
+
uri
|
|
1049
|
+
};
|
|
1018
1050
|
}
|
|
1019
1051
|
};
|
|
1020
1052
|
|
|
@@ -1050,41 +1082,41 @@ const executeReadFileTool = async (args, _options) => {
|
|
|
1050
1082
|
const uri = typeof args.uri === 'string' ? args.uri : '';
|
|
1051
1083
|
if (uri) {
|
|
1052
1084
|
if (!isAbsoluteUri(uri)) {
|
|
1053
|
-
return
|
|
1085
|
+
return {
|
|
1054
1086
|
error: 'Invalid argument: uri must be an absolute URI.'
|
|
1055
|
-
}
|
|
1087
|
+
};
|
|
1056
1088
|
}
|
|
1057
1089
|
try {
|
|
1058
1090
|
const content = await readFile(uri);
|
|
1059
|
-
return
|
|
1091
|
+
return {
|
|
1060
1092
|
content,
|
|
1061
1093
|
uri
|
|
1062
|
-
}
|
|
1094
|
+
};
|
|
1063
1095
|
} catch (error) {
|
|
1064
|
-
return
|
|
1096
|
+
return {
|
|
1065
1097
|
...getToolErrorPayload(error),
|
|
1066
1098
|
uri
|
|
1067
|
-
}
|
|
1099
|
+
};
|
|
1068
1100
|
}
|
|
1069
1101
|
}
|
|
1070
1102
|
const filePath = typeof args.path === 'string' ? args.path : '';
|
|
1071
1103
|
if (!filePath || isPathTraversalAttempt(filePath)) {
|
|
1072
|
-
return
|
|
1104
|
+
return {
|
|
1073
1105
|
error: 'Access denied: path must be relative and stay within the open workspace folder.'
|
|
1074
|
-
}
|
|
1106
|
+
};
|
|
1075
1107
|
}
|
|
1076
1108
|
const normalizedPath = normalizeRelativePath(filePath);
|
|
1077
1109
|
try {
|
|
1078
1110
|
const content = await readFile(normalizedPath);
|
|
1079
|
-
return
|
|
1111
|
+
return {
|
|
1080
1112
|
content,
|
|
1081
1113
|
path: normalizedPath
|
|
1082
|
-
}
|
|
1114
|
+
};
|
|
1083
1115
|
} catch (error) {
|
|
1084
|
-
return
|
|
1116
|
+
return {
|
|
1085
1117
|
...getToolErrorPayload(error),
|
|
1086
1118
|
path: normalizedPath
|
|
1087
|
-
}
|
|
1119
|
+
};
|
|
1088
1120
|
}
|
|
1089
1121
|
};
|
|
1090
1122
|
|
|
@@ -1094,43 +1126,49 @@ const executeRenderHtmlTool = async (args, _options) => {
|
|
|
1094
1126
|
const css = typeof args.css === 'string' ? args.css : '';
|
|
1095
1127
|
const title = typeof args.title === 'string' ? args.title : '';
|
|
1096
1128
|
if (!html) {
|
|
1097
|
-
return
|
|
1129
|
+
return {
|
|
1098
1130
|
error: 'Missing required argument: html'
|
|
1099
|
-
}
|
|
1131
|
+
};
|
|
1100
1132
|
}
|
|
1101
1133
|
if (html.length > maxPayloadLength || css.length > maxPayloadLength) {
|
|
1102
|
-
return
|
|
1134
|
+
return {
|
|
1103
1135
|
error: 'Payload too large: keep html/css under 40,000 characters each.'
|
|
1104
|
-
}
|
|
1136
|
+
};
|
|
1105
1137
|
}
|
|
1106
|
-
return
|
|
1138
|
+
return {
|
|
1107
1139
|
css,
|
|
1108
1140
|
html,
|
|
1109
1141
|
ok: true,
|
|
1110
1142
|
title
|
|
1111
|
-
}
|
|
1143
|
+
};
|
|
1112
1144
|
};
|
|
1113
1145
|
|
|
1114
1146
|
const executeWriteFileTool = async (args, _options) => {
|
|
1115
|
-
const
|
|
1147
|
+
const uri = typeof args.uri === 'string' ? args.uri : '';
|
|
1116
1148
|
const content = typeof args.content === 'string' ? args.content : '';
|
|
1117
|
-
if (!
|
|
1118
|
-
return
|
|
1119
|
-
error: '
|
|
1120
|
-
}
|
|
1149
|
+
if (!uri || !isAbsoluteUri(uri)) {
|
|
1150
|
+
return {
|
|
1151
|
+
error: 'Invalid argument: uri must be an absolute URI.'
|
|
1152
|
+
};
|
|
1153
|
+
}
|
|
1154
|
+
try {
|
|
1155
|
+
new URL(uri);
|
|
1156
|
+
} catch {
|
|
1157
|
+
return {
|
|
1158
|
+
error: 'Invalid argument: invalid URL.'
|
|
1159
|
+
};
|
|
1121
1160
|
}
|
|
1122
|
-
const normalizedPath = normalizeRelativePath(filePath);
|
|
1123
1161
|
try {
|
|
1124
|
-
await writeFile(
|
|
1125
|
-
return
|
|
1162
|
+
await writeFile(uri, content);
|
|
1163
|
+
return {
|
|
1126
1164
|
ok: true,
|
|
1127
|
-
|
|
1128
|
-
}
|
|
1165
|
+
uri
|
|
1166
|
+
};
|
|
1129
1167
|
} catch (error) {
|
|
1130
|
-
return
|
|
1168
|
+
return {
|
|
1131
1169
|
...getToolErrorPayload(error),
|
|
1132
|
-
|
|
1133
|
-
}
|
|
1170
|
+
uri
|
|
1171
|
+
};
|
|
1134
1172
|
}
|
|
1135
1173
|
};
|
|
1136
1174
|
|
|
@@ -1166,9 +1204,15 @@ const executeChatTool = async (name, rawArguments, options) => {
|
|
|
1166
1204
|
if (name === 'render_html') {
|
|
1167
1205
|
return executeRenderHtmlTool(args);
|
|
1168
1206
|
}
|
|
1169
|
-
|
|
1207
|
+
if (name === 'open_preview') {
|
|
1208
|
+
return executeOpenPreviewTool(args);
|
|
1209
|
+
}
|
|
1210
|
+
if (name === 'close_preview') {
|
|
1211
|
+
return executeClosePreviewTool();
|
|
1212
|
+
}
|
|
1213
|
+
return {
|
|
1170
1214
|
error: `Unknown tool: ${name}`
|
|
1171
|
-
}
|
|
1215
|
+
};
|
|
1172
1216
|
};
|
|
1173
1217
|
|
|
1174
1218
|
const getReadFileTool = () => {
|
|
@@ -1194,7 +1238,7 @@ const getReadFileTool = () => {
|
|
|
1194
1238
|
const getWriteFileTool = () => {
|
|
1195
1239
|
return {
|
|
1196
1240
|
function: {
|
|
1197
|
-
description: 'Write UTF-8 text content to a file inside the currently open workspace folder.',
|
|
1241
|
+
description: 'Write UTF-8 text content to a file inside the currently open workspace folder. Only pass an absolute URI.',
|
|
1198
1242
|
name: 'write_file',
|
|
1199
1243
|
parameters: {
|
|
1200
1244
|
additionalProperties: false,
|
|
@@ -1203,12 +1247,12 @@ const getWriteFileTool = () => {
|
|
|
1203
1247
|
description: 'New UTF-8 text content to write to the file.',
|
|
1204
1248
|
type: 'string'
|
|
1205
1249
|
},
|
|
1206
|
-
|
|
1207
|
-
description: '
|
|
1250
|
+
uri: {
|
|
1251
|
+
description: 'Absolute file URI within the workspace (for example: file:///workspace/src/index.ts).',
|
|
1208
1252
|
type: 'string'
|
|
1209
1253
|
}
|
|
1210
1254
|
},
|
|
1211
|
-
required: ['
|
|
1255
|
+
required: ['uri', 'content'],
|
|
1212
1256
|
type: 'object'
|
|
1213
1257
|
}
|
|
1214
1258
|
},
|
|
@@ -1277,8 +1321,42 @@ const getRenderHtmlTool = () => {
|
|
|
1277
1321
|
type: 'function'
|
|
1278
1322
|
};
|
|
1279
1323
|
};
|
|
1324
|
+
const getOpenPreviewTool = () => {
|
|
1325
|
+
return {
|
|
1326
|
+
function: {
|
|
1327
|
+
description: 'Open the right-side preview for an HTML file URI inside the currently open workspace folder.',
|
|
1328
|
+
name: 'open_preview',
|
|
1329
|
+
parameters: {
|
|
1330
|
+
additionalProperties: false,
|
|
1331
|
+
properties: {
|
|
1332
|
+
uri: {
|
|
1333
|
+
description: 'Absolute HTML file URI within the workspace (for example: file:///workspace/index.html).',
|
|
1334
|
+
type: 'string'
|
|
1335
|
+
}
|
|
1336
|
+
},
|
|
1337
|
+
required: ['uri'],
|
|
1338
|
+
type: 'object'
|
|
1339
|
+
}
|
|
1340
|
+
},
|
|
1341
|
+
type: 'function'
|
|
1342
|
+
};
|
|
1343
|
+
};
|
|
1344
|
+
const getClosePreviewTool = () => {
|
|
1345
|
+
return {
|
|
1346
|
+
function: {
|
|
1347
|
+
description: 'Close the right-side preview if it is currently open.',
|
|
1348
|
+
name: 'close_preview',
|
|
1349
|
+
parameters: {
|
|
1350
|
+
additionalProperties: false,
|
|
1351
|
+
properties: {},
|
|
1352
|
+
type: 'object'
|
|
1353
|
+
}
|
|
1354
|
+
},
|
|
1355
|
+
type: 'function'
|
|
1356
|
+
};
|
|
1357
|
+
};
|
|
1280
1358
|
const getBasicChatTools = () => {
|
|
1281
|
-
return [getReadFileTool(), getWriteFileTool(), getListFilesTool(), getGetWorkspaceUriTool(), getRenderHtmlTool()];
|
|
1359
|
+
return [getReadFileTool(), getWriteFileTool(), getListFilesTool(), getGetWorkspaceUriTool(), getRenderHtmlTool(), getOpenPreviewTool(), getClosePreviewTool()];
|
|
1282
1360
|
};
|
|
1283
1361
|
|
|
1284
1362
|
const handleMessagePort = async port => {
|