MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / constructor

Method constructor

src/api/providers/bedrock.ts:216–298  ·  view source on GitHub ↗
(options: ProviderSettings)

Source from the content-addressed store, hash-verified

214 private readonly providerName = "Bedrock"
215
216 constructor(options: ProviderSettings) {
217 super()
218 this.options = options
219 const region = this.options.awsRegion
220
221 // process the various user input options, be opinionated about the intent of the options
222 // and determine the model to use during inference and for cost calculations
223 // There are variations on ARN strings that can be entered making the conditional logic
224 // more involved than the non-ARN branch of logic
225 if (this.options.awsCustomArn) {
226 this.arnInfo = this.parseArn(this.options.awsCustomArn, region)
227
228 if (!this.arnInfo.isValid) {
229 logger.error("Invalid ARN format", {
230 ctx: "bedrock",
231 errorMessage: this.arnInfo.errorMessage,
232 })
233
234 // Throw a consistent error with a prefix that can be detected by callers
235 const errorMessage =
236 this.arnInfo.errorMessage ||
237 "Invalid ARN format. ARN should follow the pattern: arn:aws:bedrock:region:account-id:resource-type/resource-name"
238 throw new Error("INVALID_ARN_FORMAT:" + errorMessage)
239 }
240
241 if (this.arnInfo.region && this.arnInfo.region !== this.options.awsRegion) {
242 // Log if there's a region mismatch between the ARN and the region selected by the user
243 // We will use the ARNs region, so execution can continue, but log an info statement.
244 // Log a warning if there's a region mismatch between the ARN and the region selected by the user
245 // We will use the ARNs region, so execution can continue, but log an info statement.
246 logger.info(this.arnInfo.errorMessage, {
247 ctx: "bedrock",
248 selectedRegion: this.options.awsRegion,
249 arnRegion: this.arnInfo.region,
250 })
251
252 this.options.awsRegion = this.arnInfo.region
253 }
254
255 this.options.apiModelId = this.arnInfo.modelId
256 if (this.arnInfo.awsUseCrossRegionInference) this.options.awsUseCrossRegionInference = true
257 }
258
259 if (!this.options.modelTemperature) {
260 this.options.modelTemperature = BEDROCK_DEFAULT_TEMPERATURE
261 }
262
263 this.costModelConfig = this.getModel()
264
265 const clientConfig: BedrockRuntimeClientConfig = {
266 userAgentAppId: `ZooCode#${Package.version}`,
267 region: this.options.awsRegion,
268 // Add the endpoint configuration when specified and enabled
269 ...(this.options.awsBedrockEndpoint &&
270 this.options.awsBedrockEndpointEnabled && { endpoint: this.options.awsBedrockEndpoint }),
271 }
272
273 if (this.options.awsUseApiKey && this.options.awsApiKey) {

Callers

nothing calls this directly

Calls 4

parseArnMethod · 0.95
getModelMethod · 0.95
errorMethod · 0.65
infoMethod · 0.65

Tested by

no test coverage detected