vg-coder-cli 1.0.16 → 1.0.17
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/package.json
CHANGED
package/src/server/api-server.js
CHANGED
|
@@ -237,8 +237,13 @@ class ApiServer {
|
|
|
237
237
|
console.log(chalk.green(`✓ Bash execution completed in ${result.executionTime}ms`));
|
|
238
238
|
res.json(result);
|
|
239
239
|
} else {
|
|
240
|
+
// Check if it's a syntax error
|
|
241
|
+
const isSyntaxError = result.error === 'Syntax validation failed';
|
|
240
242
|
console.log(chalk.red(`✗ Bash execution failed: ${result.error || 'Exit code ' + result.exitCode}`));
|
|
241
|
-
res.status(400).json(
|
|
243
|
+
res.status(400).json({
|
|
244
|
+
...result,
|
|
245
|
+
syntaxError: isSyntaxError
|
|
246
|
+
});
|
|
242
247
|
}
|
|
243
248
|
|
|
244
249
|
} catch (error) {
|
|
@@ -383,10 +383,16 @@
|
|
|
383
383
|
<textarea id="execute-bash"
|
|
384
384
|
placeholder="mkdir -p $(dirname "src/test.js") cat <<'EOF' > src/test.js console.log('Hello World'); EOF"></textarea>
|
|
385
385
|
</div>
|
|
386
|
-
<
|
|
387
|
-
<
|
|
388
|
-
|
|
389
|
-
|
|
386
|
+
<div class="btn-group">
|
|
387
|
+
<button class="btn" onclick="testExecute()">
|
|
388
|
+
<span>▶️</span>
|
|
389
|
+
<span>Execute Script</span>
|
|
390
|
+
</button>
|
|
391
|
+
<button class="btn" onclick="executeFromClipboard()">
|
|
392
|
+
<span>📋</span>
|
|
393
|
+
<span>Execute from Clipboard</span>
|
|
394
|
+
</button>
|
|
395
|
+
</div>
|
|
390
396
|
<div class="response" id="execute-response"></div>
|
|
391
397
|
</div>
|
|
392
398
|
</div>
|
|
@@ -776,6 +782,65 @@ API sẽ:
|
|
|
776
782
|
resetButton(btn);
|
|
777
783
|
}
|
|
778
784
|
|
|
785
|
+
async function executeFromClipboard() {
|
|
786
|
+
const btn = event.target.closest('.btn');
|
|
787
|
+
|
|
788
|
+
showLoading(btn, '<span>📋</span><span>Execute from Clipboard</span>');
|
|
789
|
+
|
|
790
|
+
try {
|
|
791
|
+
// Read from clipboard
|
|
792
|
+
const clipboardText = await navigator.clipboard.readText();
|
|
793
|
+
|
|
794
|
+
// Check if clipboard is empty
|
|
795
|
+
if (!clipboardText || !clipboardText.trim()) {
|
|
796
|
+
showToast('⚠️ Clipboard trống! Vui lòng copy bash script trước.', 'error');
|
|
797
|
+
showResponse('execute-response', {
|
|
798
|
+
error: 'Clipboard is empty',
|
|
799
|
+
message: 'Please copy a bash script to clipboard first'
|
|
800
|
+
}, true);
|
|
801
|
+
resetButton(btn);
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
// Display clipboard content in textarea for reference
|
|
806
|
+
document.getElementById('execute-bash').value = clipboardText;
|
|
807
|
+
|
|
808
|
+
// Execute the script (API will validate syntax first)
|
|
809
|
+
const res = await fetch(`${API_BASE}/api/execute`, {
|
|
810
|
+
method: 'POST',
|
|
811
|
+
headers: { 'Content-Type': 'application/json' },
|
|
812
|
+
body: JSON.stringify({ bash: clipboardText })
|
|
813
|
+
});
|
|
814
|
+
const data = await res.json();
|
|
815
|
+
showResponse('execute-response', data, !res.ok || !data.success);
|
|
816
|
+
|
|
817
|
+
if (data.success) {
|
|
818
|
+
showToast('✅ Thực thi từ clipboard thành công!', 'success');
|
|
819
|
+
} else {
|
|
820
|
+
// Check if it's a syntax error
|
|
821
|
+
if (data.syntaxError) {
|
|
822
|
+
showToast('❌ Lỗi syntax! Kiểm tra bash script.', 'error');
|
|
823
|
+
} else {
|
|
824
|
+
showToast('❌ Thực thi thất bại!', 'error');
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
} catch (err) {
|
|
828
|
+
// Handle clipboard permission errors
|
|
829
|
+
if (err.name === 'NotAllowedError') {
|
|
830
|
+
showToast('❌ Không có quyền truy cập clipboard!', 'error');
|
|
831
|
+
showResponse('execute-response', {
|
|
832
|
+
error: 'Clipboard permission denied',
|
|
833
|
+
message: 'Please allow clipboard access in your browser settings'
|
|
834
|
+
}, true);
|
|
835
|
+
} else {
|
|
836
|
+
showResponse('execute-response', { error: err.message }, true);
|
|
837
|
+
showToast('❌ Lỗi: ' + err.message, 'error');
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
resetButton(btn);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
|
|
779
844
|
function showToast(message, type = 'success') {
|
|
780
845
|
const toast = document.getElementById('toast');
|
|
781
846
|
toast.textContent = message;
|
|
Binary file
|