@lvce-editor/chat-tool-worker 7.6.0 → 7.8.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.
@@ -994,6 +994,94 @@ const executeClosePreviewTool = async (_args, _options) => {
994
994
  }
995
995
  };
996
996
 
997
+ const ABSOLUTE_URI_REGEX = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//;
998
+ const isAbsoluteUri = value => {
999
+ return ABSOLUTE_URI_REGEX.test(value);
1000
+ };
1001
+
1002
+ const executeCreateDirectoryTool = async (args, _options) => {
1003
+ const uri = typeof args.uri === 'string' ? args.uri : '';
1004
+ if (!uri || !isAbsoluteUri(uri)) {
1005
+ return {
1006
+ error: 'Invalid argument: uri must be an absolute URI.'
1007
+ };
1008
+ }
1009
+ try {
1010
+ new URL(uri);
1011
+ } catch {
1012
+ return {
1013
+ error: 'Invalid argument: invalid URL.'
1014
+ };
1015
+ }
1016
+ try {
1017
+ await invoke('FileSystem.mkdir', uri);
1018
+ return {
1019
+ ok: true,
1020
+ uri
1021
+ };
1022
+ } catch (error) {
1023
+ return {
1024
+ ...getToolErrorPayload(error),
1025
+ uri
1026
+ };
1027
+ }
1028
+ };
1029
+
1030
+ const applyTextEdit = (content, start, end, text) => {
1031
+ if (start > content.length || end > content.length) {
1032
+ throw new Error('Invalid argument: edit range is out of bounds.');
1033
+ }
1034
+ return `${content.slice(0, start)}${text}${content.slice(end)}`;
1035
+ };
1036
+
1037
+ const executeEditFileTool = async (args, _options) => {
1038
+ const uri = typeof args.uri === 'string' ? args.uri : '';
1039
+ const start = typeof args.start === 'number' ? args.start : -1;
1040
+ const end = typeof args.end === 'number' ? args.end : -1;
1041
+ const text = typeof args.text === 'string' ? args.text : '';
1042
+ if (!uri || !isAbsoluteUri(uri)) {
1043
+ return {
1044
+ error: 'Invalid argument: uri must be an absolute URI.'
1045
+ };
1046
+ }
1047
+ try {
1048
+ new URL(uri);
1049
+ } catch {
1050
+ return {
1051
+ error: 'Invalid argument: invalid URL.'
1052
+ };
1053
+ }
1054
+ if (!Number.isInteger(start) || start < 0) {
1055
+ return {
1056
+ error: 'Invalid argument: start must be a non-negative integer.'
1057
+ };
1058
+ }
1059
+ if (!Number.isInteger(end) || end < 0) {
1060
+ return {
1061
+ error: 'Invalid argument: end must be a non-negative integer.'
1062
+ };
1063
+ }
1064
+ if (start > end) {
1065
+ return {
1066
+ error: 'Invalid argument: start must be less than or equal to end.'
1067
+ };
1068
+ }
1069
+ try {
1070
+ const content = await readFile(uri);
1071
+ const nextContent = applyTextEdit(content, start, end, text);
1072
+ await writeFile(uri, nextContent);
1073
+ return {
1074
+ ok: true,
1075
+ uri
1076
+ };
1077
+ } catch (error) {
1078
+ return {
1079
+ ...getToolErrorPayload(error),
1080
+ uri
1081
+ };
1082
+ }
1083
+ };
1084
+
997
1085
  const executeGetWorkspaceUriTool = async (_args, _options) => {
998
1086
  try {
999
1087
  const workspaceUri = await getWorkspacePath();
@@ -1005,11 +1093,6 @@ const executeGetWorkspaceUriTool = async (_args, _options) => {
1005
1093
  }
1006
1094
  };
1007
1095
 
1008
- const ABSOLUTE_URI_REGEX = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//;
1009
- const isAbsoluteUri = value => {
1010
- return ABSOLUTE_URI_REGEX.test(value);
1011
- };
1012
-
1013
1096
  const executeListFilesTool = async (args, _options) => {
1014
1097
  const uri = typeof args.uri === 'string' ? args.uri : '';
1015
1098
  if (!uri || !isAbsoluteUri(uri)) {
@@ -1123,6 +1206,42 @@ const executeRenderHtmlTool = async (args, _options) => {
1123
1206
  };
1124
1207
  };
1125
1208
 
1209
+ const getRunInTerminalOptions = args => {
1210
+ const {
1211
+ options
1212
+ } = args;
1213
+ if (!options || typeof options !== 'object') {
1214
+ return undefined;
1215
+ }
1216
+ const candidate = options;
1217
+ const {
1218
+ command,
1219
+ shell
1220
+ } = candidate;
1221
+ if (typeof command !== 'string' || typeof shell !== 'string') {
1222
+ return undefined;
1223
+ }
1224
+ return {
1225
+ command,
1226
+ shell
1227
+ };
1228
+ };
1229
+ const executeRunInTerminalTool = async (args, _options) => {
1230
+ const runInTerminalOptions = getRunInTerminalOptions(args);
1231
+ if (!runInTerminalOptions) {
1232
+ return {
1233
+ error: 'Invalid argument: options must include shell (string) and command (string).'
1234
+ };
1235
+ }
1236
+ return {
1237
+ output: {
1238
+ exitCode: 0,
1239
+ stderr: '',
1240
+ stdout: `Mock output for "${runInTerminalOptions.command}" using shell "${runInTerminalOptions.shell}"`
1241
+ }
1242
+ };
1243
+ };
1244
+
1126
1245
  const getSearchOptions = args => {
1127
1246
  const {
1128
1247
  options
@@ -1228,6 +1347,9 @@ const executeChatTool = async (name, rawArguments, options) => {
1228
1347
  if (name === 'write_file') {
1229
1348
  return executeWriteFileTool(args);
1230
1349
  }
1350
+ if (name === 'edit_file') {
1351
+ return executeEditFileTool(args);
1352
+ }
1231
1353
  if (name === 'list_files') {
1232
1354
  return executeListFilesTool(args);
1233
1355
  }
@@ -1249,6 +1371,12 @@ const executeChatTool = async (name, rawArguments, options) => {
1249
1371
  if (name === 'search_text') {
1250
1372
  return executeSearchTextTool(args);
1251
1373
  }
1374
+ if (name === 'run_in_terminal') {
1375
+ return executeRunInTerminalTool(args);
1376
+ }
1377
+ if (name === 'create_directory') {
1378
+ return executeCreateDirectoryTool(args);
1379
+ }
1252
1380
  return {
1253
1381
  error: `Unknown tool: ${name}`
1254
1382
  };
@@ -1298,6 +1426,38 @@ const getWriteFileTool = () => {
1298
1426
  type: 'function'
1299
1427
  };
1300
1428
  };
1429
+ const getEditFileTool = () => {
1430
+ return {
1431
+ function: {
1432
+ description: 'Apply a targeted text edit to an existing file by character offsets. This reads the current file, applies the edit, and writes the updated result. Use this for small changes instead of rewriting the full file.',
1433
+ name: 'edit_file',
1434
+ parameters: {
1435
+ additionalProperties: false,
1436
+ properties: {
1437
+ end: {
1438
+ description: 'Zero-based end character offset (exclusive) in the current file content.',
1439
+ type: 'number'
1440
+ },
1441
+ start: {
1442
+ description: 'Zero-based start character offset (inclusive) in the current file content.',
1443
+ type: 'number'
1444
+ },
1445
+ text: {
1446
+ description: 'Replacement text inserted at the range [start, end).',
1447
+ type: 'string'
1448
+ },
1449
+ uri: {
1450
+ description: 'Absolute URI for the target file (for example `file://...`, `memfs://...`, or extension-provided file system URIs). Relative paths are not allowed.',
1451
+ type: 'string'
1452
+ }
1453
+ },
1454
+ required: ['uri', 'start', 'end', 'text'],
1455
+ type: 'object'
1456
+ }
1457
+ },
1458
+ type: 'function'
1459
+ };
1460
+ };
1301
1461
  const getListFilesTool = () => {
1302
1462
  return {
1303
1463
  function: {
@@ -1321,7 +1481,7 @@ const getListFilesTool = () => {
1321
1481
  const getGetWorkspaceUriTool = () => {
1322
1482
  return {
1323
1483
  function: {
1324
- 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.',
1484
+ description: 'Get the URI of the currently open workspace folder. Call this first before using list_files, read_file, write_file, edit_file, open_preview, or openEditor when you do not already have a concrete workspace URI.',
1325
1485
  name: 'getWorkspaceUri',
1326
1486
  parameters: {
1327
1487
  additionalProperties: false,
@@ -1455,8 +1615,57 @@ const getSearchTextTool = () => {
1455
1615
  type: 'function'
1456
1616
  };
1457
1617
  };
1618
+ const getRunInTerminalTool = () => {
1619
+ return {
1620
+ function: {
1621
+ description: 'Run a shell command in a terminal using the provided shell and command options.',
1622
+ name: 'run_in_terminal',
1623
+ parameters: {
1624
+ additionalProperties: false,
1625
+ properties: {
1626
+ options: {
1627
+ additionalProperties: false,
1628
+ properties: {
1629
+ command: {
1630
+ type: 'string'
1631
+ },
1632
+ shell: {
1633
+ type: 'string'
1634
+ }
1635
+ },
1636
+ required: ['shell', 'command'],
1637
+ type: 'object'
1638
+ }
1639
+ },
1640
+ required: ['options'],
1641
+ type: 'object'
1642
+ }
1643
+ },
1644
+ type: 'function'
1645
+ };
1646
+ };
1647
+ const getCreateDirectoryTool = () => {
1648
+ return {
1649
+ function: {
1650
+ description: 'Create a new directory at the given absolute URI (for example `file://...`, `memfs://...`, or extension-provided file system URIs). Do not pass a relative path.',
1651
+ name: 'create_directory',
1652
+ parameters: {
1653
+ additionalProperties: false,
1654
+ properties: {
1655
+ uri: {
1656
+ description: 'Absolute URI for the target directory (for example `file://...`, `memfs://...`, or extension-provided file system URIs). Relative paths are not allowed.',
1657
+ type: 'string'
1658
+ }
1659
+ },
1660
+ required: ['uri'],
1661
+ type: 'object'
1662
+ }
1663
+ },
1664
+ type: 'function'
1665
+ };
1666
+ };
1458
1667
  const getBasicChatTools = () => {
1459
- return [getReadFileTool(), getWriteFileTool(), getListFilesTool(), getGetWorkspaceUriTool(), getRenderHtmlTool(), getOpenPreviewTool(), getOpenEditorTool(), getClosePreviewTool(), getSearchTextTool()];
1668
+ return [getReadFileTool(), getWriteFileTool(), getEditFileTool(), getListFilesTool(), getGetWorkspaceUriTool(), getRenderHtmlTool(), getOpenPreviewTool(), getOpenEditorTool(), getClosePreviewTool(), getSearchTextTool(), getRunInTerminalTool(), getCreateDirectoryTool()];
1460
1669
  };
1461
1670
 
1462
1671
  const handleMessagePort = async port => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/chat-tool-worker",
3
- "version": "7.6.0",
3
+ "version": "7.8.0",
4
4
  "description": "Chat Tool Worker",
5
5
  "repository": {
6
6
  "type": "git",