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