Skip to content

Conversation

@jsonbailey
Copy link
Contributor

@jsonbailey jsonbailey commented Nov 7, 2025

Note

Refactors AIProviderFactory to load providers via explicit dynamic imports and enhances creation-time error handling/logging.

  • AI Provider Loading (packages/sdk/server-ai/src/api/providers/AIProviderFactory.ts)
    • Replace require(package) + class-name lookup with per-provider dynamic ESM imports via lambdas (openai, langchain, vercel).
    • Change _createProvider signature to accept getProviderClass function and providerType instead of packageName/providerClassName.
    • Improve error handling: detect missing modules and log actionable install guidance; add warning when provider class not found.
    • Update debug/warn messages to reference providerType instead of package name.

Written by Cursor Bugbot for commit 730c0cb. This will update automatically on new commits. Configure here.

@jsonbailey jsonbailey requested a review from a team as a code owner November 7, 2025 22:52
@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2025

@launchdarkly/browser size report
This is the brotli compressed size of the ESM build.
Compressed size: 169118 bytes
Compressed size limit: 200000
Uncompressed size: 789399 bytes

@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2025

@launchdarkly/js-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 24988 bytes
Compressed size limit: 26000
Uncompressed size: 122411 bytes

@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2025

@launchdarkly/js-client-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 17636 bytes
Compressed size limit: 20000
Uncompressed size: 90259 bytes

@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2025

@launchdarkly/js-client-sdk size report
This is the brotli compressed size of the ESM build.
Compressed size: 21721 bytes
Compressed size limit: 25000
Uncompressed size: 74698 bytes

// eslint-disable-next-line import/no-extraneous-dependencies, global-require, import/no-dynamic-require
const { [providerClassName]: ProviderClass } = require(packageName);
// Use dynamic import to load the provider module
// This uses ESM resolution which can find packages in the user's node_modules
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should say this here, as the resolution will depend on the project configuration.

if (err.code === 'ERR_MODULE_NOT_FOUND' || err.message?.includes('Cannot find module')) {
logger?.warn(
`Error creating AIProvider for: ${aiConfig.provider?.name} with provider ${providerType}: ${err.message}. ` +
`Please install the required package with your preferred package manager.`,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Error Message: Don't Give Absolute Solutions (Bugbot Rules)

The error message instructs users to install the required package with their preferred package manager, but as noted in the PR discussion, the resolution depends on the project configuration and shouldn't be stated so definitively here.

Fix in Cursor Fix in Web

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.

3 participants