fix(gateway): run aider bridge non-interactively

This commit is contained in:
Rene Fichtmueller 2026-07-17 17:49:35 +02:00
parent 1f0a2a3966
commit 861457719b

View File

@ -21,6 +21,7 @@ interface RunningBridge {
} }
const runningBridges = new Map<string, RunningBridge>(); const runningBridges = new Map<string, RunningBridge>();
const PROMPT_ARG = '__LLM_GATEWAY_PROMPT__';
function extractCliContent(stdout: string): string { function extractCliContent(stdout: string): string {
let lastAgentMessage = ''; let lastAgentMessage = '';
@ -54,9 +55,11 @@ async function runCli(
): Promise<{ success: boolean; content?: string; error?: string }> { ): Promise<{ success: boolean; content?: string; error?: string }> {
return new Promise((resolve) => { return new Promise((resolve) => {
try { try {
const finalArgs = args.map((arg) => arg === PROMPT_ARG ? prompt : arg);
const promptPassedAsArg = args.includes(PROMPT_ARG);
const child = execFile( const child = execFile(
command, command,
args as string[], finalArgs,
{ timeout: timeoutMs, maxBuffer: 10 * 1024 * 1024 }, { timeout: timeoutMs, maxBuffer: 10 * 1024 * 1024 },
(err, stdout) => { (err, stdout) => {
if (err) { if (err) {
@ -66,7 +69,7 @@ async function runCli(
} }
} }
); );
if (child.stdin) { if (child.stdin && !promptPassedAsArg) {
child.stdin.write(prompt); child.stdin.write(prompt);
child.stdin.end(); child.stdin.end();
} }
@ -91,6 +94,21 @@ function buildCliInvocation(desc: SubscriptionDescriptor, model?: string): { cmd
return { cmd: 'gh', args: ['copilot', 'suggest', '--shell'] }; return { cmd: 'gh', args: ['copilot', 'suggest', '--shell'] };
} }
case 'inline-openai': { case 'inline-openai': {
if (desc.id === 'aider') {
const args = [
'--yes-always',
'--no-show-model-warnings',
'--no-check-update',
'--no-analytics',
'--no-pretty',
'--no-stream',
'--no-git',
'--no-gitignore',
];
if (model && model !== 'aider-default') args.push('--model', model);
args.push('--message', PROMPT_ARG);
return { cmd: 'aider', args };
}
// Generic OpenAI-compatible CLI (chatgpt-cli, gemini-cli with OpenAI compat) // Generic OpenAI-compatible CLI (chatgpt-cli, gemini-cli with OpenAI compat)
return { cmd: desc.command, args: model ? ['--model', model] : [] }; return { cmd: desc.command, args: model ? ['--model', model] : [] };
} }