feat: use antigravity.sendTextToChat native API for chat submission

This commit is contained in:
2026-03-07 16:09:05 +09:00
parent 7f81528c18
commit e4eb7565ea

View File

@@ -263,57 +263,22 @@ async function handleCommand(filePath: string) {
return; return;
} }
// General text: send to chat panel with query + submit // General text: use Antigravity native API to send to chat
let chatOpened = false; try {
await vscode.commands.executeCommand('antigravity.sendTextToChat', true, command.text);
// Method 1: Try opening chat with query parameter (fills + auto-focuses) console.log(`Gravity Bridge: ✅ sent via antigravity.sendTextToChat: "${command.text.substring(0, 50)}"`);
const chatOpenCommands = [ } catch (e) {
{ cmd: 'workbench.action.chat.open', args: { query: command.text } }, console.log(`Gravity Bridge: antigravity.sendTextToChat failed: ${e}, trying fallback`);
{ cmd: 'workbench.panel.chat.view.copilot.focus', args: undefined }, // Fallback: open chat with query parameter
];
for (const { cmd, args } of chatOpenCommands) {
try { try {
await vscode.commands.executeCommand(cmd, args); await vscode.commands.executeCommand('workbench.action.chat.open', { query: command.text });
chatOpened = true; console.log('Gravity Bridge: fallback to workbench.action.chat.open with query');
console.log(`Gravity Bridge: chat opened with "${cmd}"`); } catch (e2) {
break; console.error('Gravity Bridge: all chat send methods failed', e2);
} catch { /* try next */ }
}
if (chatOpened) {
await new Promise(resolve => setTimeout(resolve, 300));
// Paste text into chat input
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);
await new Promise(resolve => setTimeout(resolve, 300));
// Try to submit: carriage return, then keyboard Enter simulation
let submitted = false;
const submitMethods = [
{ cmd: 'type', args: { text: '\r' } }, // carriage return
{ cmd: 'default:Enter', args: undefined }, // Enter keybinding
{ cmd: 'type', args: { text: '\u000d' } }, // CR unicode
];
for (const { cmd, args } of submitMethods) {
try {
await vscode.commands.executeCommand(cmd, args);
console.log(`Gravity Bridge: ✅ Enter sent via "${cmd}"`);
submitted = true;
break;
} catch (e) {
console.log(`Gravity Bridge: "${cmd}" failed: ${e}`);
}
}
if (!submitted) {
console.log('Gravity Bridge: ⚠️ all submit methods failed — text pasted but not submitted');
} }
} }
// Always mark as consumed (no toast notification) // Always mark as consumed
command.consumed = true; command.consumed = true;
fs.writeFileSync(filePath, JSON.stringify(command, null, 2), 'utf-8'); fs.writeFileSync(filePath, JSON.stringify(command, null, 2), 'utf-8');
} catch (err) { } catch (err) {