feat: use antigravity.sendTextToChat native API for chat submission
This commit is contained in:
@@ -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;
|
|
||||||
|
|
||||||
// Method 1: Try opening chat with query parameter (fills + auto-focuses)
|
|
||||||
const chatOpenCommands = [
|
|
||||||
{ cmd: 'workbench.action.chat.open', args: { query: command.text } },
|
|
||||||
{ cmd: 'workbench.panel.chat.view.copilot.focus', args: undefined },
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const { cmd, args } of chatOpenCommands) {
|
|
||||||
try {
|
try {
|
||||||
await vscode.commands.executeCommand(cmd, args);
|
await vscode.commands.executeCommand('antigravity.sendTextToChat', true, command.text);
|
||||||
chatOpened = true;
|
console.log(`Gravity Bridge: ✅ sent via antigravity.sendTextToChat: "${command.text.substring(0, 50)}"`);
|
||||||
console.log(`Gravity Bridge: chat opened with "${cmd}"`);
|
|
||||||
break;
|
|
||||||
} 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) {
|
} catch (e) {
|
||||||
console.log(`Gravity Bridge: "${cmd}" failed: ${e}`);
|
console.log(`Gravity Bridge: antigravity.sendTextToChat failed: ${e}, trying fallback`);
|
||||||
}
|
// Fallback: open chat with query parameter
|
||||||
}
|
try {
|
||||||
if (!submitted) {
|
await vscode.commands.executeCommand('workbench.action.chat.open', { query: command.text });
|
||||||
console.log('Gravity Bridge: ⚠️ all submit methods failed — text pasted but not submitted');
|
console.log('Gravity Bridge: fallback to workbench.action.chat.open with query');
|
||||||
|
} catch (e2) {
|
||||||
|
console.error('Gravity Bridge: all chat send methods failed', e2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user