fix: try openNewConversation + sendTextToChat, clipboard paste as fallback

This commit is contained in:
2026-03-07 16:31:44 +09:00
parent c688812089
commit 180dba18be

View File

@@ -263,25 +263,30 @@ async function handleCommand(filePath: string) {
return;
}
// General text: use Antigravity native API to send to chat
// Try false first (plain text), then true (tagged text)
let sent = false;
for (const flag of [false, true]) {
// General text: send to Antigravity chat
// Method 1: antigravity.sendTextToChat (native API)
try {
// Try opening the agent chat panel first
try {
await vscode.commands.executeCommand('antigravity.sendTextToChat', flag, command.text);
console.log(`Gravity Bridge: ✅ sent via antigravity.sendTextToChat(${flag}): "${command.text.substring(0, 50)}"`);
sent = true;
break;
} catch (e) {
console.log(`Gravity Bridge: sendTextToChat(${flag}) failed: ${e}`);
}
}
if (!sent) {
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('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)
try {
await vscode.commands.executeCommand('workbench.action.chat.open', { query: command.text });
console.log('Gravity Bridge: fallback to workbench.action.chat.open with query');
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.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 chat send methods failed', e2);
console.error('Gravity Bridge: all methods failed', e2);
}
}