@@ -35,6 +35,59 @@ interface ExtendedMetadata {
3535 }
3636}
3737
38+ // Define types for stream response content blocks
39+ interface ContentBlockStart {
40+ contentBlockIndex ?: number
41+ start ?: {
42+ type ?: string
43+ thinking ?: string
44+ }
45+ contentBlock ?: {
46+ type ?: string
47+ thinking ?: string
48+ }
49+ type ?: string
50+ thinking ?: string
51+ }
52+
53+ // Define types for stream response deltas
54+ interface ContentBlockDelta {
55+ contentBlockIndex ?: number
56+ delta ?: {
57+ type ?: string
58+ thinking ?: string
59+ text ?: string
60+ reasoningContent ?: {
61+ text ?: string
62+ }
63+ }
64+ }
65+
66+ // Define types for supported content types
67+ type SupportedContentType = "text" | "image" | "thinking"
68+
69+ interface ContentItem {
70+ type : SupportedContentType
71+ text ?: string
72+ source ?: {
73+ data : string | Buffer | Uint8Array
74+ media_type ?: string
75+ }
76+ }
77+
78+ // Define cache point type for AWS Bedrock
79+ interface CachePointContentBlock {
80+ cachePoint : {
81+ type : "default"
82+ }
83+ }
84+
85+ // Define provider options type based on AWS SDK patterns
86+ interface ProviderChainOptions {
87+ ignoreCache ?: boolean
88+ profile ?: string
89+ }
90+
3891// https://docs.anthropic.com/en/api/claude-on-amazon-bedrock
3992export class AwsBedrockHandler implements ApiHandler {
4093 private options : ApiHandlerOptions
@@ -107,7 +160,7 @@ export class AwsBedrockHandler implements ApiHandler {
107160 sessionToken ?: string
108161 } > {
109162 // Configure provider options
110- const providerOptions : any = { }
163+ const providerOptions : ProviderChainOptions = { }
111164 if ( this . options . awsUseProfile ) {
112165 // For profile-based auth, always use ignoreCache to detect credential file changes
113166 // This solves the AWS Identity Manager issue where credential files change externally
@@ -461,7 +514,7 @@ export class AwsBedrockHandler implements ApiHandler {
461514
462515 // Handle content block start - check if Bedrock uses Anthropic SDK format
463516 if ( chunk . contentBlockStart ) {
464- const blockStart = chunk . contentBlockStart as any
517+ const blockStart = chunk . contentBlockStart as ContentBlockStart
465518 const blockIndex = chunk . contentBlockStart . contentBlockIndex
466519
467520 // Check for thinking block in various possible formats
@@ -497,7 +550,7 @@ export class AwsBedrockHandler implements ApiHandler {
497550
498551 // Check if this is a thinking block
499552 const blockType = blockTypes . get ( blockIndex )
500- const delta = chunk . contentBlockDelta . delta as any
553+ const delta = chunk . contentBlockDelta . delta as ContentBlockDelta [ "delta" ]
501554
502555 // Handle thinking delta (Anthropic SDK format)
503556 if ( delta ?. type === "thinking_delta" || delta ?. thinking ) {
@@ -727,7 +780,7 @@ export class AwsBedrockHandler implements ApiHandler {
727780 }
728781
729782 // Log unsupported content types for debugging
730- console . warn ( `Unsupported content type: ${ ( item as any ) . type } ` )
783+ console . warn ( `Unsupported content type: ${ ( item as ContentItem ) . type } ` )
731784 return null
732785 } )
733786 . filter ( ( item ) : item is ContentBlock => item !== null )
@@ -771,7 +824,7 @@ export class AwsBedrockHandler implements ApiHandler {
771824 imageData = new Uint8Array ( Buffer . from ( base64Data , "base64" ) )
772825 } else if ( item . source . data && typeof item . source . data === "object" ) {
773826 // Try to convert to Uint8Array
774- imageData = new Uint8Array ( Buffer . from ( item . source . data as any ) )
827+ imageData = new Uint8Array ( Buffer . from ( item . source . data as Buffer | Uint8Array ) )
775828 } else {
776829 throw new Error ( "Unsupported image data format" )
777830 }
@@ -817,7 +870,7 @@ export class AwsBedrockHandler implements ApiHandler {
817870 cachePoint : {
818871 type : "default" ,
819872 } ,
820- } as any , // Type assertion needed for AWS SDK compatibility
873+ } as CachePointContentBlock , // Properly typed cache point for AWS SDK
821874 ]
822875 }
823876
0 commit comments