@@ -3,10 +3,6 @@ import type { PluginState } from "../../state"
33import type { Logger } from "../../logger"
44import { cacheToolParametersFromMessages } from "../../state/tool-cache"
55
6- // ============================================================================
7- // Format-specific injection helpers (reuses OpenAI Chat logic)
8- // ============================================================================
9-
106function isNudgeMessage ( msg : any , nudgeText : string ) : boolean {
117 if ( typeof msg . content === 'string' ) {
128 return msg . content === nudgeText
@@ -18,7 +14,6 @@ function injectSynth(messages: any[], instruction: string, nudgeText: string): b
1814 for ( let i = messages . length - 1 ; i >= 0 ; i -- ) {
1915 const msg = messages [ i ]
2016 if ( msg . role === 'user' ) {
21- // Skip nudge messages - find real user message
2217 if ( isNudgeMessage ( msg , nudgeText ) ) continue
2318
2419 if ( typeof msg . content === 'string' ) {
@@ -73,27 +68,15 @@ function injectPrunableList(messages: any[], injection: string): boolean {
7368 return true
7469}
7570
76- // ============================================================================
77- // Format Descriptor
78- // ============================================================================
79-
8071/**
81- * Format descriptor for AWS Bedrock Converse API.
82- *
83- * Bedrock format characteristics:
84- * - Top-level `system` array for system messages
85- * - `messages` array with only 'user' and 'assistant' roles
86- * - `inferenceConfig` for model parameters (maxTokens, temperature, etc.)
87- * - Tool calls: `toolUse` blocks in assistant content with `toolUseId`
88- * - Tool results: `toolResult` blocks in user content with `toolUseId`
89- * - Cache points: `cachePoint` blocks that should be preserved
72+ * Bedrock uses top-level `system` array + `inferenceConfig` (distinguishes from OpenAI/Anthropic).
73+ * Tool calls: `toolUse` blocks in assistant content with `toolUseId`
74+ * Tool results: `toolResult` blocks in user content with `toolUseId`
9075 */
9176export const bedrockFormat : FormatDescriptor = {
9277 name : 'bedrock' ,
9378
9479 detect ( body : any ) : boolean {
95- // Bedrock has a top-level system array AND inferenceConfig (not model params in messages)
96- // This distinguishes it from OpenAI/Anthropic which put system in messages
9780 return (
9881 Array . isArray ( body . system ) &&
9982 body . inferenceConfig !== undefined &&
@@ -106,8 +89,7 @@ export const bedrockFormat: FormatDescriptor = {
10689 } ,
10790
10891 cacheToolParameters ( data : any [ ] , state : PluginState , logger ?: Logger ) : void {
109- // Bedrock stores tool calls in assistant message content as toolUse blocks
110- // We need to extract toolUseId and tool name for later correlation
92+ // Extract toolUseId and tool name from assistant toolUse blocks
11193 for ( const m of data ) {
11294 if ( m . role === 'assistant' && Array . isArray ( m . content ) ) {
11395 for ( const block of m . content ) {
@@ -125,7 +107,6 @@ export const bedrockFormat: FormatDescriptor = {
125107 }
126108 }
127109 }
128- // Also use the generic message caching for any compatible structures
129110 cacheToolParametersFromMessages ( data , state , logger )
130111 } ,
131112
@@ -145,7 +126,6 @@ export const bedrockFormat: FormatDescriptor = {
145126 const outputs : ToolOutput [ ] = [ ]
146127
147128 for ( const m of data ) {
148- // Bedrock tool results are in user messages as toolResult blocks
149129 if ( m . role === 'user' && Array . isArray ( m . content ) ) {
150130 for ( const block of m . content ) {
151131 if ( block . toolResult && block . toolResult . toolUseId ) {
@@ -170,13 +150,11 @@ export const bedrockFormat: FormatDescriptor = {
170150 for ( let i = 0 ; i < data . length ; i ++ ) {
171151 const m = data [ i ]
172152
173- // Tool results are in user messages as toolResult blocks
174153 if ( m . role === 'user' && Array . isArray ( m . content ) ) {
175154 let messageModified = false
176155 const newContent = m . content . map ( ( block : any ) => {
177156 if ( block . toolResult && block . toolResult . toolUseId ?. toLowerCase ( ) === toolIdLower ) {
178157 messageModified = true
179- // Replace the content array inside toolResult with pruned message
180158 return {
181159 ...block ,
182160 toolResult : {
0 commit comments