@lvce-editor/chat-tool-worker 9.1.0 → 9.3.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 +54 -126
- package/package.json +1 -1
|
@@ -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
|
|
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$
|
|
408
|
-
|
|
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
|
-
|
|
1054
|
+
type
|
|
1153
1055
|
}) => {
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
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(
|
|
1069
|
+
const ipc = await listen$1(IpcChildWithModuleWorker$1);
|
|
1170
1070
|
handleIpc(ipc);
|
|
1171
1071
|
const rpc = createRpc(ipc);
|
|
1172
1072
|
return rpc;
|
|
@@ -1423,9 +1323,24 @@ const executeEditFileTool = async (args, _options) => {
|
|
|
1423
1323
|
}
|
|
1424
1324
|
};
|
|
1425
1325
|
|
|
1326
|
+
const windowsDrivePathRegex$1 = /^[a-zA-Z]:[\\/]/;
|
|
1327
|
+
const isAbsoluteFileSystemPath = value => {
|
|
1328
|
+
return value.startsWith('/') || windowsDrivePathRegex$1.test(value);
|
|
1329
|
+
};
|
|
1330
|
+
|
|
1331
|
+
const windowsDrivePathRegex = /^[a-zA-Z]:[\\/]/;
|
|
1332
|
+
const normalizeWorkspaceUri = workspacePathOrUri => {
|
|
1333
|
+
if (!isAbsoluteFileSystemPath(workspacePathOrUri)) {
|
|
1334
|
+
return workspacePathOrUri;
|
|
1335
|
+
}
|
|
1336
|
+
const url = new URL('file:///');
|
|
1337
|
+
url.pathname = windowsDrivePathRegex.test(workspacePathOrUri) ? `/${workspacePathOrUri.replaceAll('\\', '/')}` : workspacePathOrUri;
|
|
1338
|
+
return url.href;
|
|
1339
|
+
};
|
|
1426
1340
|
const executeGetWorkspaceUriTool = async (_args, _options) => {
|
|
1427
1341
|
try {
|
|
1428
|
-
const
|
|
1342
|
+
const workspacePathOrUri = await getWorkspacePath();
|
|
1343
|
+
const workspaceUri = normalizeWorkspaceUri(workspacePathOrUri);
|
|
1429
1344
|
return {
|
|
1430
1345
|
workspaceUri
|
|
1431
1346
|
};
|
|
@@ -1778,11 +1693,6 @@ const formatSearchProcessResults = (results, outputFormat) => {
|
|
|
1778
1693
|
return formatGrepMatches(matches, outputFormat);
|
|
1779
1694
|
};
|
|
1780
1695
|
|
|
1781
|
-
const windowsDrivePathRegex = /^[a-zA-Z]:[\\/]/;
|
|
1782
|
-
const isAbsoluteFileSystemPath = value => {
|
|
1783
|
-
return value.startsWith('/') || windowsDrivePathRegex.test(value);
|
|
1784
|
-
};
|
|
1785
|
-
|
|
1786
1696
|
const isFileUri = value => {
|
|
1787
1697
|
return value.startsWith('file://');
|
|
1788
1698
|
};
|
|
@@ -2189,13 +2099,17 @@ const getRunInTerminalOptions = args => {
|
|
|
2189
2099
|
const candidate = options;
|
|
2190
2100
|
const {
|
|
2191
2101
|
command,
|
|
2102
|
+
explanation,
|
|
2103
|
+
goal,
|
|
2192
2104
|
shell
|
|
2193
2105
|
} = candidate;
|
|
2194
|
-
if (typeof command !== 'string' || typeof shell !== 'string') {
|
|
2106
|
+
if (typeof command !== 'string' || typeof explanation !== 'string' || typeof goal !== 'string' || typeof shell !== 'string') {
|
|
2195
2107
|
return undefined;
|
|
2196
2108
|
}
|
|
2197
2109
|
return {
|
|
2198
2110
|
command,
|
|
2111
|
+
explanation,
|
|
2112
|
+
goal,
|
|
2199
2113
|
shell
|
|
2200
2114
|
};
|
|
2201
2115
|
};
|
|
@@ -2203,7 +2117,7 @@ const executeRunInTerminalTool = async (args, _options) => {
|
|
|
2203
2117
|
const runInTerminalOptions = getRunInTerminalOptions(args);
|
|
2204
2118
|
if (!runInTerminalOptions) {
|
|
2205
2119
|
return {
|
|
2206
|
-
error: 'Invalid argument: options must include shell (string) and
|
|
2120
|
+
error: 'Invalid argument: options must include shell (string), command (string), explanation (string), and goal (string).'
|
|
2207
2121
|
};
|
|
2208
2122
|
}
|
|
2209
2123
|
try {
|
|
@@ -2853,13 +2767,23 @@ const getRunInTerminalTool = () => {
|
|
|
2853
2767
|
additionalProperties: false,
|
|
2854
2768
|
properties: {
|
|
2855
2769
|
command: {
|
|
2770
|
+
description: 'The shell command to execute.',
|
|
2771
|
+
type: 'string'
|
|
2772
|
+
},
|
|
2773
|
+
explanation: {
|
|
2774
|
+
description: 'Why this terminal command is being run.',
|
|
2775
|
+
type: 'string'
|
|
2776
|
+
},
|
|
2777
|
+
goal: {
|
|
2778
|
+
description: 'The higher-level objective this terminal command is meant to achieve.',
|
|
2856
2779
|
type: 'string'
|
|
2857
2780
|
},
|
|
2858
2781
|
shell: {
|
|
2782
|
+
description: 'The shell executable that should run the command.',
|
|
2859
2783
|
type: 'string'
|
|
2860
2784
|
}
|
|
2861
2785
|
},
|
|
2862
|
-
required: ['shell', 'command'],
|
|
2786
|
+
required: ['shell', 'command', 'explanation', 'goal'],
|
|
2863
2787
|
type: 'object'
|
|
2864
2788
|
}
|
|
2865
2789
|
},
|
|
@@ -2984,11 +2908,15 @@ const getBasicChatTools = () => {
|
|
|
2984
2908
|
return [getReadFileTool(), getWriteFileTool(), getRenameTool(), getEditFileTool(), getListFilesTool(), getGetWorkspaceUriTool(), getRenderHtmlTool(), getOpenPreviewTool(), getOpenEditorTool(), getClosePreviewTool(), getSearchTextTool(), getRgTool(), getGrepSearchTool(), getRunInTerminalTool(), getSpawnSubagentTool(), getCreateDirectoryTool(), getGlobTool(), getUpdateTodoTool()];
|
|
2985
2909
|
};
|
|
2986
2910
|
|
|
2987
|
-
const handleMessagePort = async port => {
|
|
2988
|
-
await create$
|
|
2911
|
+
const handleMessagePort = async (port, isRendererWorker = false) => {
|
|
2912
|
+
const rpc = await create$7({
|
|
2989
2913
|
commandMap: commandMap,
|
|
2914
|
+
isMessagePortOpen: true,
|
|
2990
2915
|
messagePort: port
|
|
2991
2916
|
});
|
|
2917
|
+
if (isRendererWorker) {
|
|
2918
|
+
set$1(rpc);
|
|
2919
|
+
}
|
|
2992
2920
|
};
|
|
2993
2921
|
|
|
2994
2922
|
const send$2 = async port => {
|
|
@@ -3002,7 +2930,7 @@ const initializeTerminalProcessElectron = async () => {
|
|
|
3002
2930
|
set(rpc);
|
|
3003
2931
|
};
|
|
3004
2932
|
const initializeTerminalProcessRemote = async () => {
|
|
3005
|
-
const rpc = await create$
|
|
2933
|
+
const rpc = await create$2({
|
|
3006
2934
|
commandMap: commandMap,
|
|
3007
2935
|
type: 'terminal-process'
|
|
3008
2936
|
});
|
|
@@ -3026,7 +2954,8 @@ const commandMap = {
|
|
|
3026
2954
|
'ChatTool.execute': executeChatTool,
|
|
3027
2955
|
'ChatTool.getTools': getBasicChatTools,
|
|
3028
2956
|
'ChatTool.initialize': initialize,
|
|
3029
|
-
'HandleMessagePort.handleMessagePort': handleMessagePort
|
|
2957
|
+
'HandleMessagePort.handleMessagePort': handleMessagePort,
|
|
2958
|
+
initialize: (_, port) => handleMessagePort(port, true)
|
|
3030
2959
|
};
|
|
3031
2960
|
|
|
3032
2961
|
const send$1 = async port => {
|
|
@@ -3052,10 +2981,9 @@ const initializeFileSystemWorker = async () => {
|
|
|
3052
2981
|
};
|
|
3053
2982
|
|
|
3054
2983
|
const initializeRendererWorker = async () => {
|
|
3055
|
-
|
|
2984
|
+
await create$1({
|
|
3056
2985
|
commandMap: commandMap
|
|
3057
2986
|
});
|
|
3058
|
-
set$1(rpc);
|
|
3059
2987
|
};
|
|
3060
2988
|
|
|
3061
2989
|
const listen = async () => {
|