Skip to content

fix(provider): handle bundled @aws-sdk/credential-providers module fmt#276

Closed
agustif wants to merge 1 commit intoLatitudes-Dev:integrationfrom
agustif:fix/bedrock-credential-provider-import
Closed

fix(provider): handle bundled @aws-sdk/credential-providers module fmt#276
agustif wants to merge 1 commit intoLatitudes-Dev:integrationfrom
agustif:fix/bedrock-credential-provider-import

Conversation

@agustif
Copy link

@agustif agustif commented Jan 7, 2026

Fixes issue where fromNodeProviderChain is not a function when @aws-sdk/credential-providers is bundled by BunProc.install().

The bundled module exports all functions via default export, not as named exports. Update import to handle both bundled (default export) and unbundled (named exports) formats.

Also use bearer token as apiKey when available to avoid unnecessary credential provider import.

Greptile Summary

Fixed runtime error where fromNodeProviderChain was not a function when @aws-sdk/credential-providers is bundled by BunProc.install(). The bundled module exports functions via default export, while unbundled modules use named exports.

Key Changes:

  • Added fallback logic to handle both bundled (mod.default?.fromNodeProviderChain) and unbundled (mod.fromNodeProviderChain) module formats
  • Added error handling when fromNodeProviderChain cannot be found in either format
  • Optimized credential loading by using bearer token directly when available, avoiding unnecessary credential provider import
  • Added explicit dependency on @aws-sdk/credential-providers@3.964.0 in package.json

The fix aligns with the bundling behavior introduced in commit bb35723, where BunProc.install() uses Bun.build with packages: "bundle" to create single-file bundles for compiled binary compatibility.

Confidence Score: 5/5

  • This PR is safe to merge with no significant risks
  • The changes correctly handle a real runtime error, include proper error handling, optimize performance by avoiding unnecessary imports, and maintain backward compatibility with both bundled and unbundled module formats. The explicit dependency addition ensures version consistency.
  • No files require special attention

Important Files Changed

Filename Overview
packages/opencode/src/provider/provider.ts Added bundled module format support and bearer token optimization for AWS credentials
package.json Added explicit dependency on @aws-sdk/credential-providers version 3.964.0

Sequence Diagram

sequenceDiagram
    participant Provider as Provider.list()
    participant BunProc as BunProc.install()
    participant Module as credential-providers
    participant AWS as AWS Bedrock

    alt Bearer Token Available
        Provider->>Provider: Check awsBearerToken
        Provider->>Provider: Set providerOptions with bearer token
        Provider->>AWS: Use bearer token
    else No Bearer Token
        Provider->>BunProc: install credential-providers
        BunProc->>BunProc: Bundle module with Bun.build
        BunProc-->>Provider: Return bundled file path
        Provider->>Module: import bundled module
        Module-->>Provider: Return module (bundled format)
        Provider->>Provider: Extract fromNodeProviderChain
        Note over Provider: Try mod.default?.fromNodeProviderChain<br/>then mod.fromNodeProviderChain
        alt Function found
            Provider->>Module: fromNodeProviderChain(options)
            Module-->>Provider: Return credential provider
            Provider->>Provider: Set providerOptions.credentialProvider
            Provider->>AWS: Use credential provider chain
        else Function not found
            Provider->>Provider: Throw error
        end
    end
Loading

…rmat

Fixes issue where fromNodeProviderChain is not a function when
@aws-sdk/credential-providers is bundled by BunProc.install().

The bundled module exports all functions via default export, not as
named exports. Update import to handle both bundled (default export)
and unbundled (named exports) formats.

Also use bearer token as apiKey when available to avoid unnecessary
credential provider import.

Co-authored-by: opencode <opencode@opencode.ai>
@agustif agustif changed the title fix(provider): handle bundled @aws-sdk/credential-providers module fo… fix(provider): handle bundled @aws-sdk/credential-providers module fit Jan 7, 2026
@agustif agustif changed the title fix(provider): handle bundled @aws-sdk/credential-providers module fit fix(provider): handle bundled @aws-sdk/credential-providers module fmt Jan 7, 2026
@greptile-apps
Copy link

greptile-apps bot commented Jan 7, 2026

Greptile found no issues!

From now on, if a review finishes and we haven't found any issues, we will not post anything, but you can confirm that we reviewed your changes in the status check section.

This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR".

@shuv1337 shuv1337 closed this Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants