fix: separate panel open and sendTextToChat with 1s delay, try true first

This commit is contained in:
2026-03-07 16:42:21 +09:00
parent 180dba18be
commit ae0fd78f7a

View File

@@ -264,29 +264,45 @@ async function handleCommand(filePath: string) {
} }
// General text: send to Antigravity chat // General text: send to Antigravity chat
// Method 1: antigravity.sendTextToChat (native API) // Step 1: Ensure agent panel is open
const openCmds = [
'antigravity.prioritized.chat.openNewConversation',
'workbench.panel.chat.view.copilot.focus',
];
for (const cmd of openCmds) {
try { try {
// Try opening the agent chat panel first await vscode.commands.executeCommand(cmd);
try { console.log(`Gravity Bridge: panel opened with "${cmd}"`);
await vscode.commands.executeCommand('antigravity.prioritized.chat.openNewConversation'); break;
await new Promise(resolve => setTimeout(resolve, 300)); } catch { /* try next */ }
} catch { /* panel may already be open */ } }
await vscode.commands.executeCommand('antigravity.sendTextToChat', false, command.text); // Step 2: Wait for panel to be ready
console.log(`Gravity Bridge: ✅ sent via sendTextToChat(false)`); await new Promise(resolve => setTimeout(resolve, 1000));
} catch (e1) {
console.log(`Gravity Bridge: sendTextToChat failed: ${e1}`); // Step 3: Try sending text via native API
// Method 2: focus chat panel + clipboard paste (proven to work for input) let sent = false;
for (const flag of [true, false]) {
try { try {
await vscode.commands.executeCommand('workbench.panel.chat.view.copilot.focus'); await vscode.commands.executeCommand('antigravity.sendTextToChat', flag, command.text);
await new Promise(resolve => setTimeout(resolve, 300)); console.log(`Gravity Bridge: ✅ sendTextToChat(${flag}) executed`);
const oldClipboard = await vscode.env.clipboard.readText(); sent = true;
break;
} catch (e) {
console.log(`Gravity Bridge: sendTextToChat(${flag}) error: ${e}`);
}
}
// Step 4: If native API didn't work, clipboard paste
if (!sent) {
try {
const oldClip = await vscode.env.clipboard.readText();
await vscode.env.clipboard.writeText(command.text); await vscode.env.clipboard.writeText(command.text);
await vscode.commands.executeCommand('editor.action.clipboardPasteAction'); await vscode.commands.executeCommand('editor.action.clipboardPasteAction');
await vscode.env.clipboard.writeText(oldClipboard); await vscode.env.clipboard.writeText(oldClip);
console.log('Gravity Bridge: ✅ pasted via clipboard (manual Enter needed)'); console.log('Gravity Bridge: clipboard paste fallback');
} catch (e2) { } catch (e) {
console.error('Gravity Bridge: all methods failed', e2); console.error('Gravity Bridge: all methods failed', e);
} }
} }