* Shared branching used by both public factories. Constructs the adapter * classes directly so their constructors run the full auth cascade lazily * (config.apiKey → BEDROCK_API_KEY → AWS_BEARER_TOKEN_BEDROCK → SigV4). No * eager env-key fetch here, so `auth: 'sigv4'` never throws for a missing k
(
model: BedrockConverseModels,
config?: BedrockClientConfig & { api?: 'converse' | 'chat' | 'responses' },
)
| 64 | * Default path → Converse adapter; opt-in via `api: 'chat'` or `api: 'responses'`. |
| 65 | */ |
| 66 | function build( |
| 67 | model: BedrockConverseModels, |
| 68 | config?: BedrockClientConfig & { api?: 'converse' | 'chat' | 'responses' }, |
| 69 | ): AnyBedrockAdapter { |
| 70 | if (config?.api === 'responses') { |
| 71 | const rest = stripApi(config) |
| 72 | if (!isResponsesModel(model)) { |
| 73 | throw new Error( |
| 74 | `Model "${model}" is not available on the Bedrock Responses API. ` + |
| 75 | `Responses-capable models: ${BEDROCK_RESPONSES_MODELS.join(', ')}.`, |
| 76 | ) |
| 77 | } |
| 78 | return new BedrockResponsesTextAdapter(rest, model) |
| 79 | } |
| 80 | if (config?.api === 'chat') { |
| 81 | if (!isChatModel(model)) { |
| 82 | throw new Error( |
| 83 | `Model "${model}" is not available on the Bedrock Chat Completions API. ` + |
| 84 | `Chat-capable models: ${BEDROCK_CHAT_MODELS.join(', ')}.`, |
| 85 | ) |
| 86 | } |
| 87 | return new BedrockTextAdapter(stripApi(config), model) |
| 88 | } |
| 89 | // Default + explicit 'converse' |
| 90 | return new BedrockConverseTextAdapter(config ? stripApi(config) : {}, model) |
| 91 | } |
| 92 | |
| 93 | // --- createBedrockText: explicit key, overloaded on `api` --- |
| 94 | export function createBedrockText<TModel extends BedrockConverseModels>( |
no test coverage detected