-
Notifications
You must be signed in to change notification settings - Fork 31
fix: Fixes dynamic loading of provider packages #989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@launchdarkly/browser size report |
|
@launchdarkly/js-sdk-common size report |
|
@launchdarkly/js-client-sdk-common size report |
|
@launchdarkly/js-client-sdk size report |
| // 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 |
There was a problem hiding this comment.
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.`, |
There was a problem hiding this comment.
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.
Note
Refactors
AIProviderFactoryto load providers via explicit dynamic imports and enhances creation-time error handling/logging.packages/sdk/server-ai/src/api/providers/AIProviderFactory.ts)require(package)+ class-name lookup with per-provider dynamic ESM imports via lambdas (openai,langchain,vercel)._createProvidersignature to acceptgetProviderClassfunction andproviderTypeinstead ofpackageName/providerClassName.providerTypeinstead of package name.Written by Cursor Bugbot for commit 730c0cb. This will update automatically on new commits. Configure here.