@@ -513,47 +513,49 @@ function getModelProviderCondition(...providerIds: ProviderId[]) {
513513}
514514
515515/**
516- * Bedrock fields shown for one AWS authentication mode. A block saved before
517- * the mode existed has no `bedrockAuthMode` and keeps its access keys. Like
518- * {@link getModelProviderCondition}, the answer is folded into a single `model`
519- * clause, so blocks that wrap these fields in their own condition still can.
516+ * Whether a block's Bedrock call signs with a saved AWS credential. The one rule
517+ * behind both the fields a block shows and serializes and the credential its
518+ * call uses: only an explicit `bedrockAuthMode: 'credential'` selects one, so a
519+ * block saved before the mode existed (no `bedrockAuthMode`) keeps its access keys.
520+ */
521+ function usesSavedBedrockCredential ( values : { bedrockAuthMode ?: unknown } | undefined ) : boolean {
522+ return values ?. bedrockAuthMode === 'credential'
523+ }
524+
525+ /**
526+ * Bedrock fields shown for one AWS authentication mode, decided by
527+ * {@link usesSavedBedrockCredential}. Like {@link getModelProviderCondition}, the
528+ * answer is folded into a single `model` clause.
520529 */
521530function getBedrockAuthModeCondition ( mode : 'access_keys' | 'credential' ) {
522531 return ( values ?: Record < string , unknown > ) => {
523532 const model = typeof values ?. model === 'string' ? values . model : ''
524- const usesCredential = values ?. bedrockAuthMode === 'credential'
525533 return buildModelVisibilityCondition (
526534 model ,
527535 findProviderFromModel ( model . trim ( ) ) === 'bedrock' &&
528- usesCredential === ( mode === 'credential' )
536+ usesSavedBedrockCredential ( values ) === ( mode === 'credential' )
529537 )
530538 }
531539}
532540
533541/**
534542 * The saved AWS credential ID a block's Bedrock call signs with, or undefined
535- * when the block uses access keys. A block saved before the auth mode existed
536- * has no `bedrockAuthMode` and uses a credential only when one is set. A block
537- * set to a saved credential whose ID resolves blank (an empty reference) is
538- * refused, so its call never falls back to inline keys or the deployment's own
539- * AWS credentials.
543+ * when the block uses access keys (see {@link usesSavedBedrockCredential}). A
544+ * block set to a saved credential whose ID resolves blank (an empty reference)
545+ * is refused, so its call never falls back to inline keys or the deployment's
546+ * own AWS credentials.
540547 */
541- export function getSelectedBedrockCredential ( {
542- bedrockAuthMode,
543- bedrockCredential,
544- } : {
548+ export function getSelectedBedrockCredential ( values : {
545549 bedrockAuthMode ?: unknown
546550 bedrockCredential ?: unknown
547551} ) : string | undefined {
548- if ( bedrockAuthMode === 'access_keys' ) return undefined
549- const credentialId = typeof bedrockCredential === 'string' ? bedrockCredential . trim ( ) : ''
552+ if ( ! usesSavedBedrockCredential ( values ) ) return undefined
553+ const credentialId =
554+ typeof values . bedrockCredential === 'string' ? values . bedrockCredential . trim ( ) : ''
550555 if ( credentialId ) return credentialId
551- if ( bedrockAuthMode === 'credential' ) {
552- throw new Error (
553- 'Select an AWS credential for Bedrock, or switch AWS Authentication to access keys'
554- )
555- }
556- return undefined
556+ throw new Error (
557+ 'Select an AWS credential for Bedrock, or switch AWS Authentication to access keys'
558+ )
557559}
558560
559561/**
@@ -727,7 +729,8 @@ export const PROVIDER_CREDENTIAL_INPUTS = {
727729 } ,
728730 bedrockCredential : {
729731 type : 'string' ,
730- description : 'Saved AWS credential ID for Bedrock, used instead of access keys' ,
732+ description :
733+ "Saved AWS credential ID for Bedrock, used instead of access keys when bedrockAuthMode is 'credential'" ,
731734 } ,
732735} as const
733736
0 commit comments