@lvce-editor/chat-tool-worker 8.4.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.
@@ -407,6 +407,9 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
407
407
  listen: listen$6,
408
408
  wrap: wrap$e
409
409
  };
410
+ const Error$3 = 1;
411
+ const Open = 2;
412
+ const Close = 3;
410
413
  const addListener = (emitter, type, callback) => {
411
414
  if ('addEventListener' in emitter) {
412
415
  emitter.addEventListener(type, callback);
@@ -501,6 +504,66 @@ const IpcParentWithMessagePort$1 = {
501
504
  signal: signal$1,
502
505
  wrap: wrap$5
503
506
  };
507
+ const stringifyCompact = value => {
508
+ return JSON.stringify(value);
509
+ };
510
+ const parse = content => {
511
+ if (content === 'undefined') {
512
+ return null;
513
+ }
514
+ try {
515
+ return JSON.parse(content);
516
+ } catch (error) {
517
+ throw new VError(error, 'failed to parse json');
518
+ }
519
+ };
520
+ const waitForWebSocketToBeOpen = webSocket => {
521
+ return getFirstEvent(webSocket, {
522
+ close: Close,
523
+ error: Error$3,
524
+ open: Open
525
+ });
526
+ };
527
+ const create$c = async ({
528
+ webSocket
529
+ }) => {
530
+ const firstWebSocketEvent = await waitForWebSocketToBeOpen(webSocket);
531
+ if (firstWebSocketEvent.type === Error$3) {
532
+ throw new IpcError(`WebSocket connection error`);
533
+ }
534
+ if (firstWebSocketEvent.type === Close) {
535
+ throw new IpcError('Websocket connection was immediately closed');
536
+ }
537
+ return webSocket;
538
+ };
539
+ class IpcParentWithWebSocket extends Ipc {
540
+ getData(event) {
541
+ return parse(event.data);
542
+ }
543
+ send(message) {
544
+ this._rawIpc.send(stringifyCompact(message));
545
+ }
546
+ sendAndTransfer(message) {
547
+ throw new Error('sendAndTransfer not supported');
548
+ }
549
+ dispose() {
550
+ this._rawIpc.close();
551
+ }
552
+ onClose(callback) {
553
+ this._rawIpc.addEventListener('close', callback);
554
+ }
555
+ onMessage(callback) {
556
+ this._rawIpc.addEventListener('message', callback);
557
+ }
558
+ }
559
+ const wrap = webSocket => {
560
+ return new IpcParentWithWebSocket(webSocket);
561
+ };
562
+ const IpcParentWithWebSocket$1 = {
563
+ __proto__: null,
564
+ create: create$c,
565
+ wrap
566
+ };
504
567
 
505
568
  class CommandNotFoundError extends Error {
506
569
  constructor(command) {
@@ -737,7 +800,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
737
800
  const errorProperty = getErrorProperty(error, prettyError);
738
801
  return create$1$1(id, errorProperty);
739
802
  };
740
- const create$9 = (message, result) => {
803
+ const create$b = (message, result) => {
741
804
  return {
742
805
  id: message.id,
743
806
  jsonrpc: Two$1,
@@ -746,7 +809,7 @@ const create$9 = (message, result) => {
746
809
  };
747
810
  const getSuccessResponse = (message, result) => {
748
811
  const resultProperty = result ?? null;
749
- return create$9(message, resultProperty);
812
+ return create$b(message, resultProperty);
750
813
  };
751
814
  const getErrorResponseSimple = (id, error) => {
752
815
  return {
@@ -840,7 +903,7 @@ const handleJsonRpcMessage = async (...args) => {
840
903
 
841
904
  const Two = '2.0';
842
905
 
843
- const create$8 = (method, params) => {
906
+ const create$a = (method, params) => {
844
907
  return {
845
908
  jsonrpc: Two,
846
909
  method,
@@ -848,7 +911,7 @@ const create$8 = (method, params) => {
848
911
  };
849
912
  };
850
913
 
851
- const create$7 = (id, method, params) => {
914
+ const create$9 = (id, method, params) => {
852
915
  const message = {
853
916
  id,
854
917
  jsonrpc: Two,
@@ -859,12 +922,12 @@ const create$7 = (id, method, params) => {
859
922
  };
860
923
 
861
924
  let id = 0;
862
- const create$6 = () => {
925
+ const create$8 = () => {
863
926
  return ++id;
864
927
  };
865
928
 
866
929
  const registerPromise = map => {
867
- const id = create$6();
930
+ const id = create$8();
868
931
  const {
869
932
  promise,
870
933
  resolve
@@ -881,7 +944,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
881
944
  id,
882
945
  promise
883
946
  } = registerPromise(callbacks);
884
- const message = create$7(id, method, params);
947
+ const message = create$9(id, method, params);
885
948
  if (useSendAndTransfer && ipc.sendAndTransfer) {
886
949
  ipc.sendAndTransfer(message);
887
950
  } else {
@@ -917,7 +980,7 @@ const createRpc = ipc => {
917
980
  * @deprecated
918
981
  */
919
982
  send(method, ...params) {
920
- const message = create$8(method, params);
983
+ const message = create$a(method, params);
921
984
  ipc.send(message);
922
985
  }
923
986
  };
@@ -957,7 +1020,7 @@ const listen$1 = async (module, options) => {
957
1020
  return ipc;
958
1021
  };
959
1022
 
960
- const create$5 = async ({
1023
+ const create$7 = async ({
961
1024
  commandMap,
962
1025
  isMessagePortOpen = true,
963
1026
  messagePort
@@ -975,7 +1038,7 @@ const create$5 = async ({
975
1038
  return rpc;
976
1039
  };
977
1040
 
978
- const create$4 = async ({
1041
+ const create$6 = async ({
979
1042
  commandMap,
980
1043
  isMessagePortOpen,
981
1044
  send
@@ -985,7 +1048,7 @@ const create$4 = async ({
985
1048
  port2
986
1049
  } = new MessageChannel();
987
1050
  await send(port1);
988
- return create$5({
1051
+ return create$7({
989
1052
  commandMap,
990
1053
  isMessagePortOpen,
991
1054
  messagePort: port2
@@ -1020,13 +1083,13 @@ const createSharedLazyRpc = factory => {
1020
1083
  };
1021
1084
  };
1022
1085
 
1023
- const create$3 = async ({
1086
+ const create$5 = async ({
1024
1087
  commandMap,
1025
1088
  isMessagePortOpen,
1026
1089
  send
1027
1090
  }) => {
1028
1091
  return createSharedLazyRpc(() => {
1029
- return create$4({
1092
+ return create$6({
1030
1093
  commandMap,
1031
1094
  isMessagePortOpen,
1032
1095
  send
@@ -1034,6 +1097,56 @@ const create$3 = async ({
1034
1097
  });
1035
1098
  };
1036
1099
 
1100
+ const Https = 'https:';
1101
+ const Ws = 'ws:';
1102
+ const Wss = 'wss:';
1103
+
1104
+ const getWebSocketProtocol = locationProtocol => {
1105
+ return locationProtocol === Https ? Wss : Ws;
1106
+ };
1107
+
1108
+ const getWebSocketUrl = (type, host, locationProtocol) => {
1109
+ const wsProtocol = getWebSocketProtocol(locationProtocol);
1110
+ return `${wsProtocol}//${host}/websocket/${type}`;
1111
+ };
1112
+
1113
+ const getHost = () => {
1114
+ return location.host;
1115
+ };
1116
+ const getProtocol = () => {
1117
+ return location.protocol;
1118
+ };
1119
+
1120
+ const create$4 = async ({
1121
+ commandMap,
1122
+ webSocket
1123
+ }) => {
1124
+ // TODO create a commandMap per rpc instance
1125
+ register(commandMap);
1126
+ const rawIpc = await IpcParentWithWebSocket$1.create({
1127
+ webSocket
1128
+ });
1129
+ const ipc = IpcParentWithWebSocket$1.wrap(rawIpc);
1130
+ handleIpc(ipc);
1131
+ const rpc = createRpc(ipc);
1132
+ return rpc;
1133
+ };
1134
+
1135
+ const create$3 = async ({
1136
+ commandMap,
1137
+ type
1138
+ }) => {
1139
+ const host = getHost();
1140
+ const protocol = getProtocol();
1141
+ const wsUrl = getWebSocketUrl(type, host, protocol);
1142
+ const webSocket = new WebSocket(wsUrl);
1143
+ const rpc = await create$4({
1144
+ commandMap,
1145
+ webSocket
1146
+ });
1147
+ return rpc;
1148
+ };
1149
+
1037
1150
  const create$2 = async ({
1038
1151
  commandMap,
1039
1152
  messagePort
@@ -1080,7 +1193,7 @@ const createMockRpc = ({
1080
1193
  };
1081
1194
 
1082
1195
  const rpcs = Object.create(null);
1083
- const set$3 = (id, rpc) => {
1196
+ const set$4 = (id, rpc) => {
1084
1197
  rpcs[id] = rpc;
1085
1198
  };
1086
1199
  const get = id => {
@@ -1113,7 +1226,7 @@ const create = rpcId => {
1113
1226
  const mockRpc = createMockRpc({
1114
1227
  commandMap
1115
1228
  });
1116
- set$3(rpcId, mockRpc);
1229
+ set$4(rpcId, mockRpc);
1117
1230
  // @ts-ignore
1118
1231
  mockRpc[Symbol.dispose] = () => {
1119
1232
  remove(rpcId);
@@ -1122,7 +1235,7 @@ const create = rpcId => {
1122
1235
  return mockRpc;
1123
1236
  },
1124
1237
  set(rpc) {
1125
- set$3(rpcId, rpc);
1238
+ set$4(rpcId, rpc);
1126
1239
  }
1127
1240
  };
1128
1241
  };
@@ -1131,57 +1244,87 @@ const Directory = 3;
1131
1244
  const File = 7;
1132
1245
  const Symlink = 9;
1133
1246
 
1247
+ const Electron = 2;
1248
+ const Remote = 3;
1249
+
1134
1250
  const ChatStorageWorker = 6003;
1135
1251
  const FileSystemWorker = 209;
1136
1252
  const RendererWorker = 1;
1253
+ const TerminalProcess = 7;
1137
1254
 
1138
1255
  const {
1139
- set: set$2
1256
+ set: set$3
1140
1257
  } = create(ChatStorageWorker);
1141
1258
 
1142
1259
  const {
1143
- invoke: invoke$1,
1144
- set: set$1
1260
+ invoke: invoke$2,
1261
+ set: set$2
1145
1262
  } = create(FileSystemWorker);
1146
1263
  const readDirWithFileTypes = async uri => {
1147
- return invoke$1('FileSystem.readDirWithFileTypes', uri);
1264
+ return invoke$2('FileSystem.readDirWithFileTypes', uri);
1148
1265
  };
1149
1266
  const readFile$1 = async uri => {
1150
- return invoke$1('FileSystem.readFile', uri);
1267
+ return invoke$2('FileSystem.readFile', uri);
1151
1268
  };
1152
1269
  const writeFile$1 = async (uri, content) => {
1153
- return invoke$1('FileSystem.writeFile', uri, content);
1270
+ return invoke$2('FileSystem.writeFile', uri, content);
1154
1271
  };
1155
1272
  const exists = async uri => {
1156
- return invoke$1('FileSystem.exists', uri);
1273
+ return invoke$2('FileSystem.exists', uri);
1157
1274
  };
1158
1275
 
1159
1276
  const {
1160
- invoke,
1277
+ invoke: invoke$1,
1161
1278
  invokeAndTransfer,
1162
- set
1279
+ set: set$1
1163
1280
  } = create(RendererWorker);
1281
+ const sendMessagePortToTerminalProcess = async (port, rpcId) => {
1282
+ const command = 'HandleMessagePortForTerminalProcess.handleMessagePortForTerminalProcess';
1283
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToTerminalProcess', port, command, rpcId);
1284
+ };
1164
1285
  const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
1165
1286
  const command = 'FileSystem.handleMessagePort';
1166
1287
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
1167
1288
  };
1168
1289
  const readFile = async uri => {
1169
- return invoke('FileSystem.readFile', uri);
1290
+ return invoke$1('FileSystem.readFile', uri);
1170
1291
  };
1171
1292
  const sendMessagePortToChatStorageWorker = async port => {
1172
1293
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToChatStorageWorker', port, 'HandleMessagePort.handleMessagePort');
1173
1294
  };
1174
1295
  const writeFile = async (uri, text) => {
1175
- await invoke('FileSystem.writeFile', uri, text);
1296
+ await invoke$1('FileSystem.writeFile', uri, text);
1176
1297
  };
1177
1298
  const getWorkspacePath = () => {
1178
- return invoke('Workspace.getPath');
1299
+ return invoke$1('Workspace.getPath');
1179
1300
  };
1180
1301
 
1302
+ const {
1303
+ invoke,
1304
+ set
1305
+ } = create(TerminalProcess);
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
+ };
1181
1320
  const getToolErrorPayload = error => {
1321
+ const rawCode = error && typeof error === 'object' ? Reflect.get(error, 'code') : undefined;
1182
1322
  const rawStack = error && typeof error === 'object' ? Reflect.get(error, 'stack') : undefined;
1183
1323
  return {
1184
1324
  error: String(error),
1325
+ ...(typeof rawCode === 'string' && rawCode.trim() ? {
1326
+ errorCode: rawCode
1327
+ } : {}),
1185
1328
  ...(typeof rawStack === 'string' && rawStack.trim() ? {
1186
1329
  errorStack: rawStack,
1187
1330
  stack: rawStack
@@ -1191,7 +1334,7 @@ const getToolErrorPayload = error => {
1191
1334
 
1192
1335
  const executeClosePreviewTool = async (_args, _options) => {
1193
1336
  try {
1194
- await invoke('Preview.close');
1337
+ await invoke$1('Preview.close');
1195
1338
  return {
1196
1339
  ok: true
1197
1340
  };
@@ -1208,19 +1351,15 @@ const isAbsoluteUri = value => {
1208
1351
  const executeCreateDirectoryTool = async (args, _options) => {
1209
1352
  const uri = typeof args.uri === 'string' ? args.uri : '';
1210
1353
  if (!uri || !isAbsoluteUri(uri)) {
1211
- return {
1212
- error: 'Invalid argument: uri must be an absolute URI.'
1213
- };
1354
+ return getInvalidUriErrorPayload('uri');
1214
1355
  }
1215
1356
  try {
1216
1357
  new URL(uri);
1217
1358
  } catch {
1218
- return {
1219
- error: 'Invalid argument: invalid URL.'
1220
- };
1359
+ return getInvalidUrlErrorPayload();
1221
1360
  }
1222
1361
  try {
1223
- await invoke('FileSystem.mkdir', uri);
1362
+ await invoke$1('FileSystem.mkdir', uri);
1224
1363
  return {
1225
1364
  ok: true,
1226
1365
  uri
@@ -1246,16 +1385,12 @@ const executeEditFileTool = async (args, _options) => {
1246
1385
  const end = typeof args.end === 'number' ? args.end : -1;
1247
1386
  const text = typeof args.text === 'string' ? args.text : '';
1248
1387
  if (!uri || !isAbsoluteUri(uri)) {
1249
- return {
1250
- error: 'Invalid argument: uri must be an absolute URI.'
1251
- };
1388
+ return getInvalidUriErrorPayload('uri');
1252
1389
  }
1253
1390
  try {
1254
1391
  new URL(uri);
1255
1392
  } catch {
1256
- return {
1257
- error: 'Invalid argument: invalid URL.'
1258
- };
1393
+ return getInvalidUrlErrorPayload();
1259
1394
  }
1260
1395
  if (!Number.isInteger(start) || start < 0) {
1261
1396
  return {
@@ -1499,9 +1634,7 @@ const executeGlobTool = async (args, _options) => {
1499
1634
  }
1500
1635
  const baseUri = typeof args.baseUri === 'string' ? args.baseUri : '';
1501
1636
  if (!baseUri || !isAbsoluteUri(baseUri)) {
1502
- return {
1503
- error: 'Invalid argument: baseUri must be an absolute URI.'
1504
- };
1637
+ return getInvalidUriErrorPayload('baseUri');
1505
1638
  }
1506
1639
  if (baseUri === PLACEHOLDER_WORKSPACE_URI || baseUri.startsWith(`${PLACEHOLDER_WORKSPACE_URI}/`)) {
1507
1640
  return {
@@ -1705,7 +1838,7 @@ const getSearchDir = (workspaceUri, includePattern) => {
1705
1838
  };
1706
1839
 
1707
1840
  const executeFileGrepSearch = async (workspaceUri, grepSearchArgs) => {
1708
- const result = await invoke('SearchProcess.invoke', 'TextSearch.search', {
1841
+ const result = await invoke$1('SearchProcess.invoke', 'TextSearch.search', {
1709
1842
  maxSearchResults: grepSearchArgs.maxResults,
1710
1843
  ripGrepArgs: getRipGrepArgs(grepSearchArgs),
1711
1844
  searchDir: getSearchDir(workspaceUri, grepSearchArgs.includePattern)
@@ -1757,7 +1890,7 @@ const executeMemoryGrepSearch = async (workspaceUri, grepSearchArgs, options) =>
1757
1890
  useRegularExpression: grepSearchArgs.isRegexp
1758
1891
  };
1759
1892
  try {
1760
- const result = await invoke('ExtensionHostTextSearch.textSearchMemory2', searchOptions.scheme, workspaceUri, grepSearchArgs.query, searchOptions, options.assetDir);
1893
+ const result = await invoke$1('ExtensionHostTextSearch.textSearchMemory2', searchOptions.scheme, workspaceUri, grepSearchArgs.query, searchOptions, options.assetDir);
1761
1894
  return {
1762
1895
  arguments: grepSearchArgs,
1763
1896
  result: formatLegacyMemorySearchResults(result.results || [], grepSearchArgs.outputFormat),
@@ -1767,7 +1900,7 @@ const executeMemoryGrepSearch = async (workspaceUri, grepSearchArgs, options) =>
1767
1900
  } : {})
1768
1901
  };
1769
1902
  } catch {
1770
- const legacyResults = await invoke('ExtensionHostTextSearch.textSearchMemory', searchOptions.scheme, workspaceUri, grepSearchArgs.query, searchOptions, options.assetDir);
1903
+ const legacyResults = await invoke$1('ExtensionHostTextSearch.textSearchMemory', searchOptions.scheme, workspaceUri, grepSearchArgs.query, searchOptions, options.assetDir);
1771
1904
  return {
1772
1905
  arguments: grepSearchArgs,
1773
1906
  result: isLegacyMemorySearchResult(legacyResults) ? formatLegacyMemorySearchResults(legacyResults, grepSearchArgs.outputFormat) : 'No matches found.',
@@ -1861,9 +1994,7 @@ const mapEntry = entry => ({
1861
1994
  const executeListFilesTool = async (args, _options) => {
1862
1995
  const uri = typeof args.uri === 'string' ? args.uri : '';
1863
1996
  if (!uri || !isAbsoluteUri(uri)) {
1864
- return {
1865
- error: 'Invalid argument: uri must be an absolute URI.'
1866
- };
1997
+ return getInvalidUriErrorPayload('uri');
1867
1998
  }
1868
1999
  if (uri === 'file:///workspace' || uri.startsWith('file:///workspace/')) {
1869
2000
  return {
@@ -1872,7 +2003,7 @@ const executeListFilesTool = async (args, _options) => {
1872
2003
  };
1873
2004
  }
1874
2005
  try {
1875
- const entries = await invoke('FileSystem.readDirWithFileTypes', uri);
2006
+ const entries = await invoke$1('FileSystem.readDirWithFileTypes', uri);
1876
2007
  return {
1877
2008
  entries: entries.map(mapEntry),
1878
2009
  uri
@@ -1888,12 +2019,10 @@ const executeListFilesTool = async (args, _options) => {
1888
2019
  const executeOpenEditorTool = async (args, _options) => {
1889
2020
  const uri = typeof args.uri === 'string' ? args.uri : '';
1890
2021
  if (!uri || !isAbsoluteUri(uri)) {
1891
- return {
1892
- error: 'Invalid argument: uri must be an absolute URI.'
1893
- };
2022
+ return getInvalidUriErrorPayload('uri');
1894
2023
  }
1895
2024
  try {
1896
- await invoke('Main.openUri', uri);
2025
+ await invoke$1('Main.openUri', uri);
1897
2026
  return {
1898
2027
  ok: true,
1899
2028
  uri
@@ -1909,12 +2038,10 @@ const executeOpenEditorTool = async (args, _options) => {
1909
2038
  const executeOpenPreviewTool = async (args, _options) => {
1910
2039
  const uri = typeof args.uri === 'string' ? args.uri : '';
1911
2040
  if (!uri || !isAbsoluteUri(uri)) {
1912
- return {
1913
- error: 'Invalid argument: uri must be an absolute URI.'
1914
- };
2041
+ return getInvalidUriErrorPayload('uri');
1915
2042
  }
1916
2043
  try {
1917
- await invoke('Preview.open', uri);
2044
+ await invoke$1('Preview.open', uri);
1918
2045
  return {
1919
2046
  ok: true,
1920
2047
  uri
@@ -1930,21 +2057,15 @@ const executeOpenPreviewTool = async (args, _options) => {
1930
2057
  const executeReadFileTool = async (args, _options) => {
1931
2058
  const uri = typeof args.uri === 'string' ? args.uri : '';
1932
2059
  if (!uri || !isAbsoluteUri(uri)) {
1933
- return {
1934
- error: 'Invalid argument: uri must be an absolute URI.'
1935
- };
2060
+ return getInvalidUriErrorPayload('uri');
1936
2061
  }
1937
2062
  try {
1938
2063
  const content = await readFile(uri);
1939
2064
  return {
1940
- content,
1941
- uri
2065
+ content
1942
2066
  };
1943
2067
  } catch (error) {
1944
- return {
1945
- ...getToolErrorPayload(error),
1946
- uri
1947
- };
2068
+ return getToolErrorPayload(error);
1948
2069
  }
1949
2070
  };
1950
2071
 
@@ -1952,24 +2073,18 @@ const executeRenameTool = async (args, _options) => {
1952
2073
  const oldUri = typeof args.oldUri === 'string' ? args.oldUri : '';
1953
2074
  const newUri = typeof args.newUri === 'string' ? args.newUri : '';
1954
2075
  if (!oldUri || !isAbsoluteUri(oldUri)) {
1955
- return {
1956
- error: 'Invalid argument: oldUri must be an absolute URI.'
1957
- };
2076
+ return getInvalidUriErrorPayload('oldUri');
1958
2077
  }
1959
2078
  if (!newUri || !isAbsoluteUri(newUri)) {
1960
- return {
1961
- error: 'Invalid argument: newUri must be an absolute URI.'
1962
- };
2079
+ return getInvalidUriErrorPayload('newUri');
1963
2080
  }
1964
2081
  if (!URL.canParse(oldUri) || !URL.canParse(newUri)) {
1965
- return {
1966
- error: 'Invalid argument: invalid URL.'
1967
- };
2082
+ return getInvalidUrlErrorPayload();
1968
2083
  }
1969
2084
  const oldUrl = new URL(oldUri);
1970
2085
  const newUrl = new URL(newUri);
1971
2086
  try {
1972
- await invoke('FileSystem.rename', oldUrl.toString(), newUrl.toString());
2087
+ await invoke$1('FileSystem.rename', oldUrl.toString(), newUrl.toString());
1973
2088
  return {
1974
2089
  newUri: newUrl.toString(),
1975
2090
  ok: true,
@@ -2079,13 +2194,17 @@ const executeRunInTerminalTool = async (args, _options) => {
2079
2194
  error: 'Invalid argument: options must include shell (string) and command (string).'
2080
2195
  };
2081
2196
  }
2082
- return {
2083
- output: {
2084
- exitCode: 0,
2085
- stderr: '',
2086
- stdout: `Mock output for "${runInTerminalOptions.command}" using shell "${runInTerminalOptions.shell}"`
2087
- }
2088
- };
2197
+ try {
2198
+ const workspaceUri = await getWorkspacePath();
2199
+ const result = await invoke('Terminal.executeShellCommand', {
2200
+ args: ['-c', runInTerminalOptions.command],
2201
+ cwd: workspaceUri,
2202
+ toSpawn: runInTerminalOptions.shell
2203
+ });
2204
+ return result;
2205
+ } catch (error) {
2206
+ return getToolErrorPayload(error);
2207
+ }
2089
2208
  };
2090
2209
 
2091
2210
  const getSearchOptions = args => {
@@ -2293,16 +2412,12 @@ const executeWriteFileTool = async (args, _options) => {
2293
2412
  const uri = typeof args.uri === 'string' ? args.uri : '';
2294
2413
  const content = typeof args.content === 'string' ? args.content : '';
2295
2414
  if (!uri || !isAbsoluteUri(uri)) {
2296
- return {
2297
- error: 'Invalid argument: uri must be an absolute URI.'
2298
- };
2415
+ return getInvalidUriErrorPayload('uri');
2299
2416
  }
2300
2417
  try {
2301
2418
  new URL(uri);
2302
2419
  } catch {
2303
- return {
2304
- error: 'Invalid argument: invalid URL.'
2305
- };
2420
+ return getInvalidUrlErrorPayload();
2306
2421
  }
2307
2422
  try {
2308
2423
  const exists$1 = await exists(uri);
@@ -2860,8 +2975,35 @@ const handleMessagePort = async port => {
2860
2975
  });
2861
2976
  };
2862
2977
 
2863
- const initialize = async () => {
2978
+ const send$2 = async port => {
2979
+ await sendMessagePortToTerminalProcess(port, 0);
2980
+ };
2981
+ const initializeTerminalProcessElectron = async () => {
2982
+ const rpc = await create$5({
2983
+ commandMap: commandMap,
2984
+ send: send$2
2985
+ });
2986
+ set(rpc);
2987
+ };
2988
+ const initializeTerminalProcessRemote = async () => {
2989
+ const rpc = await create$3({
2990
+ commandMap: commandMap,
2991
+ type: 'terminal-process'
2992
+ });
2993
+ set(rpc);
2994
+ };
2995
+ const initializeTerminalProcess = async platform => {
2996
+ if (platform === Electron) {
2997
+ return initializeTerminalProcessElectron();
2998
+ }
2999
+ if (platform === Remote) {
3000
+ return initializeTerminalProcessRemote();
3001
+ }
3002
+ };
3003
+
3004
+ const initialize = async platform => {
2864
3005
  // TODO
3006
+ await initializeTerminalProcess(platform);
2865
3007
  };
2866
3008
 
2867
3009
  const commandMap = {
@@ -2875,29 +3017,29 @@ const send$1 = async port => {
2875
3017
  await sendMessagePortToChatStorageWorker(port);
2876
3018
  };
2877
3019
  const initializeChatStorageWorker = async () => {
2878
- const rpc = await create$3({
3020
+ const rpc = await create$5({
2879
3021
  commandMap: commandMap,
2880
3022
  send: send$1
2881
3023
  });
2882
- set$2(rpc);
3024
+ set$3(rpc);
2883
3025
  };
2884
3026
 
2885
3027
  const send = async port => {
2886
3028
  await sendMessagePortToFileSystemWorker(port, 0);
2887
3029
  };
2888
3030
  const initializeFileSystemWorker = async () => {
2889
- const rpc = await create$3({
3031
+ const rpc = await create$5({
2890
3032
  commandMap: commandMap,
2891
3033
  send: send
2892
3034
  });
2893
- set$1(rpc);
3035
+ set$2(rpc);
2894
3036
  };
2895
3037
 
2896
3038
  const initializeRendererWorker = async () => {
2897
3039
  const rpc = await create$1({
2898
3040
  commandMap: commandMap
2899
3041
  });
2900
- set(rpc);
3042
+ set$1(rpc);
2901
3043
  };
2902
3044
 
2903
3045
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/chat-tool-worker",
3
- "version": "8.4.0",
3
+ "version": "8.6.0",
4
4
  "description": "Chat Tool Worker",
5
5
  "repository": {
6
6
  "type": "git",