From e4faf07a6df2ced2dc87730eb765879ccd64c90b Mon Sep 17 00:00:00 2001 From: Daniel Onyejesi Date: Tue, 24 Mar 2026 18:05:27 -0400 Subject: [PATCH] Fix Opus 4.6 thinking blocks, re-add Amazon Nova models - Opus 4.6 returns multiple content blocks (thinking + text); was only reading content[0] which was the thinking block (just '{') - Now iterates all blocks and extracts only type:'text' blocks - Added debug logging for Bedrock response structure - Re-added Nova Pro, Nova Lite, Nova Micro with correct region metadata --- src/utils/ai.js | 22 +++++++++++++++++++++- src/utils/models.js | 8 ++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/utils/ai.js b/src/utils/ai.js index 3f4ae99..36545eb 100644 --- a/src/utils/ai.js +++ b/src/utils/ai.js @@ -190,9 +190,29 @@ async function callBedrock(messages, model, temperature, maxTokens) { var response = await bedrockClient.send(command); var responseBody = JSON.parse(new TextDecoder().decode(response.body)); + // Debug: log response structure for troubleshooting + if (Array.isArray(responseBody.content)) { + console.log('[Bedrock] Model:', modelId, '| Blocks:', responseBody.content.map(function(b) { return b.type; }).join(', '), '| stop_reason:', responseBody.stop_reason); + } + + // Opus 4.6+ may return multiple content blocks (thinking + text). + // Extract all text blocks, skipping thinking blocks. + var textContent = ''; + if (Array.isArray(responseBody.content)) { + responseBody.content.forEach(function(block) { + if (block.type === 'text' && block.text) textContent += block.text; + }); + // Fallback: if no text blocks found, try first block + if (!textContent && responseBody.content[0]) { + textContent = responseBody.content[0].text || ''; + } + } else { + textContent = responseBody.content || ''; + } + return { success: true, - content: responseBody.content[0].text, + content: textContent, model: modelId, provider: 'bedrock', usage: { diff --git a/src/utils/models.js b/src/utils/models.js index 18e8c05..0ff74a5 100644 --- a/src/utils/models.js +++ b/src/utils/models.js @@ -46,6 +46,14 @@ var BEDROCK_MODELS = [ { id: 'anthropic/vendor-model-3.5-haiku', name: 'vendor model 3.5 Haiku', cost: '~$0.002', tag: 'VALUE', category: 'smart', bedrockId: 'anthropic.agent-config-3-5-haiku-20241022-v1:0', regions: ['us-west-2', 'us-east-1', 'us-east-2'] }, + // ── Amazon Nova (on-demand, fast + cheap) ── + { id: 'amazon/nova-pro', name: 'Amazon Nova Pro', cost: '~$0.008', tag: 'SMART', category: 'smart', + bedrockId: 'amazon.nova-pro-v1:0', regions: ['us-east-1', 'ap-southeast-2', 'ap-southeast-3', 'eu-west-2', 'me-central-1'] }, + { id: 'amazon/nova-lite', name: 'Amazon Nova Lite', cost: '~$0.001', tag: 'FAST', category: 'fast', + bedrockId: 'amazon.nova-lite-v1:0', regions: ['us-east-1', 'ap-northeast-1', 'ap-southeast-2', 'ap-southeast-3', 'eu-north-1', 'eu-west-2', 'me-central-1'] }, + { id: 'amazon/nova-micro', name: 'Amazon Nova Micro', cost: '~$0.0004', tag: 'CHEAPEST', category: 'fast', + bedrockId: 'amazon.nova-micro-v1:0', regions: ['us-east-1', 'ap-southeast-2', 'eu-west-2'] }, + // ── Meta Llama (on-demand, good for clinical summarisation) ── { id: 'meta/llama-4-maverick', name: 'Llama 4 Maverick', cost: '~$0.005', tag: 'NEW', category: 'smart', bedrockId: 'meta.llama4-maverick-17b-instruct-v1:0', regions: ['us-east-1', 'us-east-2', 'us-west-1', 'us-west-2'] },