@lvce-editor/chat-tool-worker 9.10.0 → 9.11.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 +63 -3
- package/package.json +1 -1
|
@@ -1208,18 +1208,21 @@ const {
|
|
|
1208
1208
|
} = create(TerminalProcess);
|
|
1209
1209
|
|
|
1210
1210
|
const INVALID_URI_ERROR_CODE = 'E_INVALID_URI';
|
|
1211
|
+
|
|
1211
1212
|
const getInvalidUriErrorPayload = argumentName => {
|
|
1212
1213
|
return {
|
|
1213
1214
|
error: `Invalid argument: ${argumentName} must be an absolute URI.`,
|
|
1214
1215
|
errorCode: INVALID_URI_ERROR_CODE
|
|
1215
1216
|
};
|
|
1216
1217
|
};
|
|
1218
|
+
|
|
1217
1219
|
const getInvalidUrlErrorPayload = () => {
|
|
1218
1220
|
return {
|
|
1219
1221
|
error: 'Invalid argument: invalid URL.',
|
|
1220
1222
|
errorCode: INVALID_URI_ERROR_CODE
|
|
1221
1223
|
};
|
|
1222
1224
|
};
|
|
1225
|
+
|
|
1223
1226
|
const getToolErrorPayload = error => {
|
|
1224
1227
|
const rawCode = error && typeof error === 'object' ? Reflect.get(error, 'code') : undefined;
|
|
1225
1228
|
const rawStack = error && typeof error === 'object' ? Reflect.get(error, 'stack') : undefined;
|
|
@@ -2557,10 +2560,67 @@ const getLineDiffStats = (beforeContent, afterContent) => {
|
|
|
2557
2560
|
};
|
|
2558
2561
|
};
|
|
2559
2562
|
|
|
2563
|
+
const validateWriteFileToolArgs = args => {
|
|
2564
|
+
if (!args || typeof args !== 'object') {
|
|
2565
|
+
return {
|
|
2566
|
+
ok: false,
|
|
2567
|
+
response: {
|
|
2568
|
+
error: 'Invalid argument: args must be an object.'
|
|
2569
|
+
}
|
|
2570
|
+
};
|
|
2571
|
+
}
|
|
2572
|
+
if (!('uri' in args)) {
|
|
2573
|
+
return {
|
|
2574
|
+
ok: false,
|
|
2575
|
+
response: {
|
|
2576
|
+
error: 'Missing required argument: uri'
|
|
2577
|
+
}
|
|
2578
|
+
};
|
|
2579
|
+
}
|
|
2580
|
+
if (!('content' in args)) {
|
|
2581
|
+
return {
|
|
2582
|
+
ok: false,
|
|
2583
|
+
response: {
|
|
2584
|
+
error: 'Missing required argument: content'
|
|
2585
|
+
}
|
|
2586
|
+
};
|
|
2587
|
+
}
|
|
2588
|
+
const candidate = args;
|
|
2589
|
+
if (typeof candidate.uri !== 'string') {
|
|
2590
|
+
return {
|
|
2591
|
+
ok: false,
|
|
2592
|
+
response: {
|
|
2593
|
+
error: 'Invalid argument: uri must be a string.'
|
|
2594
|
+
}
|
|
2595
|
+
};
|
|
2596
|
+
}
|
|
2597
|
+
if (typeof candidate.content !== 'string') {
|
|
2598
|
+
return {
|
|
2599
|
+
ok: false,
|
|
2600
|
+
response: {
|
|
2601
|
+
error: 'Invalid argument: content must be a string.'
|
|
2602
|
+
}
|
|
2603
|
+
};
|
|
2604
|
+
}
|
|
2605
|
+
return {
|
|
2606
|
+
args: {
|
|
2607
|
+
content: candidate.content,
|
|
2608
|
+
uri: candidate.uri
|
|
2609
|
+
},
|
|
2610
|
+
ok: true
|
|
2611
|
+
};
|
|
2612
|
+
};
|
|
2613
|
+
|
|
2560
2614
|
const executeWriteFileTool = async (args, _options) => {
|
|
2561
|
-
const
|
|
2562
|
-
|
|
2563
|
-
|
|
2615
|
+
const validatedArgs = validateWriteFileToolArgs(args);
|
|
2616
|
+
if (!validatedArgs.ok) {
|
|
2617
|
+
return validatedArgs.response;
|
|
2618
|
+
}
|
|
2619
|
+
const {
|
|
2620
|
+
content,
|
|
2621
|
+
uri
|
|
2622
|
+
} = validatedArgs.args;
|
|
2623
|
+
if (!isAbsoluteUri(uri)) {
|
|
2564
2624
|
return getInvalidUriErrorPayload('uri');
|
|
2565
2625
|
}
|
|
2566
2626
|
if (!isValidUri(uri)) {
|