@lvce-editor/chat-tool-worker 9.0.0 → 9.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.
@@ -267,45 +267,6 @@ const readyMessage = 'ready';
267
267
  const getData$2 = event => {
268
268
  return event.data;
269
269
  };
270
- const listen$8 = ({
271
- port
272
- }) => {
273
- return port;
274
- };
275
- const signal$9 = port => {
276
- port.postMessage(readyMessage);
277
- };
278
- class IpcChildWithMessagePort extends Ipc {
279
- getData(event) {
280
- return getData$2(event);
281
- }
282
- send(message) {
283
- this._rawIpc.postMessage(message);
284
- }
285
- sendAndTransfer(message) {
286
- const transfer = getTransferrables(message);
287
- this._rawIpc.postMessage(message, transfer);
288
- }
289
- dispose() {
290
- // ignore
291
- }
292
- onClose(callback) {
293
- // ignore
294
- }
295
- onMessage(callback) {
296
- this._rawIpc.addEventListener('message', callback);
297
- this._rawIpc.start();
298
- }
299
- }
300
- const wrap$g = port => {
301
- return new IpcChildWithMessagePort(port);
302
- };
303
- const IpcChildWithMessagePort$1 = {
304
- __proto__: null,
305
- listen: listen$8,
306
- signal: signal$9,
307
- wrap: wrap$g
308
- };
309
270
  const listen$7 = () => {
310
271
  // @ts-ignore
311
272
  if (typeof WorkerGlobalScope === 'undefined') {
@@ -342,70 +303,11 @@ class IpcChildWithModuleWorker extends Ipc {
342
303
  const wrap$f = global => {
343
304
  return new IpcChildWithModuleWorker(global);
344
305
  };
345
- const waitForFirstMessage = async port => {
346
- const {
347
- promise,
348
- resolve
349
- } = Promise.withResolvers();
350
- port.addEventListener('message', resolve, {
351
- once: true
352
- });
353
- const event = await promise;
354
- // @ts-ignore
355
- return event.data;
356
- };
357
- const listen$6 = async () => {
358
- const parentIpcRaw = listen$7();
359
- signal$8(parentIpcRaw);
360
- const parentIpc = wrap$f(parentIpcRaw);
361
- const firstMessage = await waitForFirstMessage(parentIpc);
362
- if (firstMessage.method !== 'initialize') {
363
- throw new IpcError('unexpected first message');
364
- }
365
- const type = firstMessage.params[0];
366
- if (type === 'message-port') {
367
- parentIpc.send({
368
- id: firstMessage.id,
369
- jsonrpc: '2.0',
370
- result: null
371
- });
372
- parentIpc.dispose();
373
- const port = firstMessage.params[1];
374
- return port;
375
- }
376
- return globalThis;
377
- };
378
- class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
379
- getData(event) {
380
- return getData$2(event);
381
- }
382
- send(message) {
383
- this._rawIpc.postMessage(message);
384
- }
385
- sendAndTransfer(message) {
386
- const transfer = getTransferrables(message);
387
- this._rawIpc.postMessage(message, transfer);
388
- }
389
- dispose() {
390
- if (this._rawIpc.close) {
391
- this._rawIpc.close();
392
- }
393
- }
394
- onClose(callback) {
395
- // ignore
396
- }
397
- onMessage(callback) {
398
- this._rawIpc.addEventListener('message', callback);
399
- this._rawIpc.start();
400
- }
401
- }
402
- const wrap$e = port => {
403
- return new IpcChildWithModuleWorkerAndMessagePort(port);
404
- };
405
- const IpcChildWithModuleWorkerAndMessagePort$1 = {
306
+ const IpcChildWithModuleWorker$1 = {
406
307
  __proto__: null,
407
- listen: listen$6,
408
- wrap: wrap$e
308
+ listen: listen$7,
309
+ signal: signal$8,
310
+ wrap: wrap$f
409
311
  };
410
312
  const Error$3 = 1;
411
313
  const Open = 2;
@@ -1149,16 +1051,14 @@ const create$3 = async ({
1149
1051
 
1150
1052
  const create$2 = async ({
1151
1053
  commandMap,
1152
- messagePort
1054
+ type
1153
1055
  }) => {
1154
- // TODO create a commandMap per rpc instance
1155
- register(commandMap);
1156
- const ipc = await listen$1(IpcChildWithMessagePort$1, {
1157
- port: messagePort
1056
+ return createSharedLazyRpc(() => {
1057
+ return create$3({
1058
+ commandMap,
1059
+ type
1060
+ });
1158
1061
  });
1159
- handleIpc(ipc);
1160
- const rpc = createRpc(ipc);
1161
- return rpc;
1162
1062
  };
1163
1063
 
1164
1064
  const create$1 = async ({
@@ -1166,7 +1066,7 @@ const create$1 = async ({
1166
1066
  }) => {
1167
1067
  // TODO create a commandMap per rpc instance
1168
1068
  register(commandMap);
1169
- const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
1069
+ const ipc = await listen$1(IpcChildWithModuleWorker$1);
1170
1070
  handleIpc(ipc);
1171
1071
  const rpc = createRpc(ipc);
1172
1072
  return rpc;
@@ -2015,21 +1915,16 @@ const executeListFilesTool = async (args, _options) => {
2015
1915
  }
2016
1916
  if (uri === 'file:///workspace' || uri.startsWith('file:///workspace/')) {
2017
1917
  return {
2018
- error: 'Invalid argument: uri must be a real workspace folder URI. Call getWorkspaceUri first and use the returned workspaceUri value.',
2019
- uri
1918
+ error: 'Invalid argument: uri must be a real workspace folder URI. Call getWorkspaceUri first and use the returned workspaceUri value.'
2020
1919
  };
2021
1920
  }
2022
1921
  try {
2023
1922
  const entries = await invoke$1('FileSystem.readDirWithFileTypes', uri);
2024
1923
  return {
2025
- entries: entries.map(mapEntry),
2026
- uri
1924
+ entries: entries.map(mapEntry)
2027
1925
  };
2028
1926
  } catch (error) {
2029
- return {
2030
- ...getToolErrorPayload(error),
2031
- uri
2032
- };
1927
+ return getToolErrorPayload(error);
2033
1928
  }
2034
1929
  };
2035
1930
 
@@ -2194,13 +2089,17 @@ const getRunInTerminalOptions = args => {
2194
2089
  const candidate = options;
2195
2090
  const {
2196
2091
  command,
2092
+ explanation,
2093
+ goal,
2197
2094
  shell
2198
2095
  } = candidate;
2199
- if (typeof command !== 'string' || typeof shell !== 'string') {
2096
+ if (typeof command !== 'string' || typeof explanation !== 'string' || typeof goal !== 'string' || typeof shell !== 'string') {
2200
2097
  return undefined;
2201
2098
  }
2202
2099
  return {
2203
2100
  command,
2101
+ explanation,
2102
+ goal,
2204
2103
  shell
2205
2104
  };
2206
2105
  };
@@ -2208,7 +2107,7 @@ const executeRunInTerminalTool = async (args, _options) => {
2208
2107
  const runInTerminalOptions = getRunInTerminalOptions(args);
2209
2108
  if (!runInTerminalOptions) {
2210
2109
  return {
2211
- error: 'Invalid argument: options must include shell (string) and command (string).'
2110
+ error: 'Invalid argument: options must include shell (string), command (string), explanation (string), and goal (string).'
2212
2111
  };
2213
2112
  }
2214
2113
  try {
@@ -2858,13 +2757,23 @@ const getRunInTerminalTool = () => {
2858
2757
  additionalProperties: false,
2859
2758
  properties: {
2860
2759
  command: {
2760
+ description: 'The shell command to execute.',
2761
+ type: 'string'
2762
+ },
2763
+ explanation: {
2764
+ description: 'Why this terminal command is being run.',
2765
+ type: 'string'
2766
+ },
2767
+ goal: {
2768
+ description: 'The higher-level objective this terminal command is meant to achieve.',
2861
2769
  type: 'string'
2862
2770
  },
2863
2771
  shell: {
2772
+ description: 'The shell executable that should run the command.',
2864
2773
  type: 'string'
2865
2774
  }
2866
2775
  },
2867
- required: ['shell', 'command'],
2776
+ required: ['shell', 'command', 'explanation', 'goal'],
2868
2777
  type: 'object'
2869
2778
  }
2870
2779
  },
@@ -2989,11 +2898,15 @@ const getBasicChatTools = () => {
2989
2898
  return [getReadFileTool(), getWriteFileTool(), getRenameTool(), getEditFileTool(), getListFilesTool(), getGetWorkspaceUriTool(), getRenderHtmlTool(), getOpenPreviewTool(), getOpenEditorTool(), getClosePreviewTool(), getSearchTextTool(), getRgTool(), getGrepSearchTool(), getRunInTerminalTool(), getSpawnSubagentTool(), getCreateDirectoryTool(), getGlobTool(), getUpdateTodoTool()];
2990
2899
  };
2991
2900
 
2992
- const handleMessagePort = async port => {
2993
- await create$2({
2901
+ const handleMessagePort = async (port, isRendererWorker = false) => {
2902
+ const rpc = await create$7({
2994
2903
  commandMap: commandMap,
2904
+ isMessagePortOpen: true,
2995
2905
  messagePort: port
2996
2906
  });
2907
+ if (isRendererWorker) {
2908
+ set$1(rpc);
2909
+ }
2997
2910
  };
2998
2911
 
2999
2912
  const send$2 = async port => {
@@ -3007,7 +2920,7 @@ const initializeTerminalProcessElectron = async () => {
3007
2920
  set(rpc);
3008
2921
  };
3009
2922
  const initializeTerminalProcessRemote = async () => {
3010
- const rpc = await create$3({
2923
+ const rpc = await create$2({
3011
2924
  commandMap: commandMap,
3012
2925
  type: 'terminal-process'
3013
2926
  });
@@ -3031,7 +2944,8 @@ const commandMap = {
3031
2944
  'ChatTool.execute': executeChatTool,
3032
2945
  'ChatTool.getTools': getBasicChatTools,
3033
2946
  'ChatTool.initialize': initialize,
3034
- 'HandleMessagePort.handleMessagePort': handleMessagePort
2947
+ 'HandleMessagePort.handleMessagePort': handleMessagePort,
2948
+ initialize: (_, port) => handleMessagePort(port, true)
3035
2949
  };
3036
2950
 
3037
2951
  const send$1 = async port => {
@@ -3057,10 +2971,9 @@ const initializeFileSystemWorker = async () => {
3057
2971
  };
3058
2972
 
3059
2973
  const initializeRendererWorker = async () => {
3060
- const rpc = await create$1({
2974
+ await create$1({
3061
2975
  commandMap: commandMap
3062
2976
  });
3063
- set$1(rpc);
3064
2977
  };
3065
2978
 
3066
2979
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/chat-tool-worker",
3
- "version": "9.0.0",
3
+ "version": "9.2.0",
4
4
  "description": "Chat Tool Worker",
5
5
  "repository": {
6
6
  "type": "git",