@lvce-editor/chat-tool-worker 7.7.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.
- package/dist/chatToolWorkerMain.js +57 -6
- package/package.json +1 -1
|
@@ -994,6 +994,39 @@ 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
|
+
|
|
997
1030
|
const applyTextEdit = (content, start, end, text) => {
|
|
998
1031
|
if (start > content.length || end > content.length) {
|
|
999
1032
|
throw new Error('Invalid argument: edit range is out of bounds.');
|
|
@@ -1001,11 +1034,6 @@ const applyTextEdit = (content, start, end, text) => {
|
|
|
1001
1034
|
return `${content.slice(0, start)}${text}${content.slice(end)}`;
|
|
1002
1035
|
};
|
|
1003
1036
|
|
|
1004
|
-
const ABSOLUTE_URI_REGEX = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//;
|
|
1005
|
-
const isAbsoluteUri = value => {
|
|
1006
|
-
return ABSOLUTE_URI_REGEX.test(value);
|
|
1007
|
-
};
|
|
1008
|
-
|
|
1009
1037
|
const executeEditFileTool = async (args, _options) => {
|
|
1010
1038
|
const uri = typeof args.uri === 'string' ? args.uri : '';
|
|
1011
1039
|
const start = typeof args.start === 'number' ? args.start : -1;
|
|
@@ -1346,6 +1374,9 @@ const executeChatTool = async (name, rawArguments, options) => {
|
|
|
1346
1374
|
if (name === 'run_in_terminal') {
|
|
1347
1375
|
return executeRunInTerminalTool(args);
|
|
1348
1376
|
}
|
|
1377
|
+
if (name === 'create_directory') {
|
|
1378
|
+
return executeCreateDirectoryTool(args);
|
|
1379
|
+
}
|
|
1349
1380
|
return {
|
|
1350
1381
|
error: `Unknown tool: ${name}`
|
|
1351
1382
|
};
|
|
@@ -1613,8 +1644,28 @@ const getRunInTerminalTool = () => {
|
|
|
1613
1644
|
type: 'function'
|
|
1614
1645
|
};
|
|
1615
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
|
+
};
|
|
1616
1667
|
const getBasicChatTools = () => {
|
|
1617
|
-
return [getReadFileTool(), getWriteFileTool(), getEditFileTool(), getListFilesTool(), getGetWorkspaceUriTool(), getRenderHtmlTool(), getOpenPreviewTool(), getOpenEditorTool(), getClosePreviewTool(), getSearchTextTool(), getRunInTerminalTool()];
|
|
1668
|
+
return [getReadFileTool(), getWriteFileTool(), getEditFileTool(), getListFilesTool(), getGetWorkspaceUriTool(), getRenderHtmlTool(), getOpenPreviewTool(), getOpenEditorTool(), getClosePreviewTool(), getSearchTextTool(), getRunInTerminalTool(), getCreateDirectoryTool()];
|
|
1618
1669
|
};
|
|
1619
1670
|
|
|
1620
1671
|
const handleMessagePort = async port => {
|