From 310a19c00151d75f3ee73c83b46fb574eb385813 Mon Sep 17 00:00:00 2001 From: Marcos Date: Wed, 15 Jul 2026 12:15:51 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Auto-deploy:=20BrainWind=20atual?= =?UTF-8?q?izado=20em=2015/07/2026=2012:15:51?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/lib/audit/runner.ts | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/app/src/lib/audit/runner.ts b/app/src/lib/audit/runner.ts index 4f86074..72b5a10 100644 --- a/app/src/lib/audit/runner.ts +++ b/app/src/lib/audit/runner.ts @@ -130,6 +130,7 @@ async function callMinimax( { role: 'user', content: userPrompt }, ], temperature: 0, + stream: true, response_format: { type: 'json_object' }, }; const response = await fetchWithTimeout(url, { @@ -144,11 +145,33 @@ async function callMinimax( const errText = await response.text(); throw new Error(`MiniMax HTTP ${response.status}: ${errText.substring(0, 100)}...`); } - const data = await response.json() as { choices?: { message?: { content?: string } }[]; error?: { message?: string } }; - if (data.error) throw new Error(`MiniMax error: ${data.error.message}`); - const content = data.choices?.[0]?.message?.content; - if (!content) throw new Error('MiniMax returned empty response'); - return content; + + if (!response.body) throw new Error('MiniMax response body is null'); + + const reader = response.body.getReader(); + const decoder = new TextDecoder('utf-8'); + let fullText = ''; + + while (true) { + const { done, value } = await reader.read(); + if (done) break; + const chunk = decoder.decode(value, { stream: true }); + const lines = chunk.split('\n').filter(l => l.trim().startsWith('data: ')); + for (const line of lines) { + const jsonStr = line.replace(/^data: /, '').trim(); + if (jsonStr === '[DONE]') continue; + try { + const parsed = JSON.parse(jsonStr); + const content = parsed.choices?.[0]?.delta?.content || ''; + fullText += content; + } catch (e) { + // ignore incomplete JSON + } + } + } + + if (!fullText) throw new Error('MiniMax returned empty streaming response'); + return fullText; } async function callOpenRouter(