-
Notifications
You must be signed in to change notification settings - Fork 10
refactor(agent): decouple ai-proxy via factory injection pattern #1455
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
…ateAiProvider) Move @forestadmin/ai-proxy from hard dependency to optional peer dependency by introducing a factory injection pattern. Users who need AI features now explicitly install ai-proxy and inject it via createAiProvider(), following the same pattern as addDataSource(createSqlDataSource(...)). This eliminates ~6 langchain packages from the default install for users who don't use AI features. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 new issue
|
…re multi-provider support
Change AiProviderDefinition interface from single name/provider to
providers: Array<{name, provider}> so that createAiProvider can later
accept variadic configs without breaking changes.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Bundle size impactBy making Dependencies removed from default install:
This represents a ~9% reduction of the total monorepo Users who need AI features simply add |
- Remove redundant .map() identity transform in schema generator - Add runtime validation for mcpServerConfigs before unsafe cast - Add JSDoc documenting AiRouter error contract - Fix lint/prettier formatting issues - Add tests for resolveMcpConfigs path (OAuth injection, backward compat, invalid input) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Coverage Impact ⬆️ Merging this pull request will increase total coverage on Modified Files with Diff Coverage (7)
🛟 Help
|
Replace inline `{ name: string; provider: string }` with a named
`AiProviderMeta` interface in datasource-toolkit. Use it consistently
in AiProviderDefinition, SchemaGenerator, and ForestSchema.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
eff659c to
adb2381
Compare
…r handling AIError and subclasses now extend BusinessError from datasource-toolkit (BadRequestError, NotFoundError, UnprocessableError). The agent's error middleware handles HTTP status mapping natively, removing the need for duck-typed status checks and error re-wrapping in the route handler. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
adb2381 to
b77d9af
Compare
Breaking change:
|
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Include the model name in AiProviderMeta alongside name and provider, so the schema metadata and agent logs accurately reflect the full AI configuration (provider, model, name). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Keep ai_llms schema payload consistent with main: only { name, provider }
are sent to the server. The model field remains in AiProviderMeta for
agent-side logging only.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Restore "Please call addAi()" guidance for AINotConfiguredError - Add error inheritance tests verifying correct BusinessError subclasses - Add missing tests: addAi logging, mcpServerConfigs null, error types - Improve error hierarchy comment with tree diagram Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Code Review SummaryReviewed 22 changed files across Result: No issues found ✅The refactoring cleanly decouples
🤖 Generated with Claude Code |
…der wrapper Keep router.ts unchanged from main. The OAuth token extraction and injection logic now lives in the createAiProvider wrapper instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…oxy route The route is only registered when addAi() is called, so this error path is unreachable. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use RouteArgs type assertion instead of any. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The agent no longer imports anything from ai-proxy at runtime. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| liana_version: string; | ||
| liana_features: Record<string, string> | null; | ||
| ai_llms?: Array<{ provider: string }> | null; | ||
| ai_llms?: Array<{ name: string; provider: string }> | null; |
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.
type was wrong
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Summary
createAiProvider()factory inai-proxyfollowing the existingaddDataSource(createSqlDataSource(...))patternAiRouter/AiProviderDefinitioninterfaces indatasource-toolkit@forestadmin/ai-proxyimports from agent source codecreateAiProviderwrapper@forestadmin/ai-proxyfully removed from agent dependencies (not even a peer dep)Before:
After:
This eliminates ~6 langchain packages from the default install for users who don't use AI features.
Multiple AI support (future)
When we need to support multiple AI configurations, only
createAiProviderneeds to change:No changes needed in agent -
addAialready acceptsAiProviderDefinitionwhich hasproviders: AiProviderMeta[]. TheRouteralready handles config selection via theai-namequery parameter.Test plan
datasource-toolkit,ai-proxy,agent)datasource-toolkittests passai-proxytests pass (99 tests) includingcreateAiProviderwrapper testsagenttests pass (883 tests)ai-proxynot present in agent package.json at allpackages/ai-proxy/src/router.tsGenerated with Claude Code