Skip to content

Commit e35428a

Browse files
watany-devgithub-actions[bot]github-actionsCline Evaluation
authored
refactor(bedrock): remove the as any and use proper type (RooCodeInc#4127)
* v3.17.12 Release Notes * changeset version bump * Updating CHANGELOG.md format * Update CHANGELOG.md for version 3.17.12 * changelog language * changelog language * attribution --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions <[email protected]> Co-authored-by: Cline Evaluation <[email protected]> * fix typing --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions <[email protected]> Co-authored-by: Cline Evaluation <[email protected]>
1 parent 59a68c8 commit e35428a

File tree

2 files changed

+62
-9
lines changed

2 files changed

+62
-9
lines changed

src/api/providers/bedrock.ts

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
3992
export 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

src/shared/proto-conversions/state/settings-conversion.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ApiConfiguration } from "@shared/api"
1+
import { ApiConfiguration, ApiProvider, BedrockModelId } from "@shared/api"
22
import { ChatSettings } from "@shared/ChatSettings"
33
import {
44
ApiConfiguration as ProtoApiConfiguration,
@@ -122,7 +122,7 @@ export function convertProtoApiConfigurationToApiConfiguration(protoConfig: Prot
122122
// eslint-disable-next-line eslint-rules/no-protobuf-object-literals
123123
const config: ApiConfiguration = {
124124
// Core API fields
125-
apiProvider: protoConfig.apiProvider as any,
125+
apiProvider: protoConfig.apiProvider as ApiProvider,
126126
apiModelId: protoConfig.apiModelId,
127127
apiKey: protoConfig.apiKey,
128128

@@ -158,7 +158,7 @@ export function convertProtoApiConfigurationToApiConfiguration(protoConfig: Prot
158158

159159
// AWS Bedrock fields
160160
awsBedrockCustomSelected: protoConfig.awsBedrockCustomSelected,
161-
awsBedrockCustomModelBaseId: protoConfig.awsBedrockCustomModelBaseId as any,
161+
awsBedrockCustomModelBaseId: protoConfig.awsBedrockCustomModelBaseId as BedrockModelId | undefined,
162162
awsAccessKey: protoConfig.awsAccessKey,
163163
awsSecretKey: protoConfig.awsSecretKey,
164164
awsSessionToken: protoConfig.awsSessionToken,

0 commit comments

Comments
 (0)