refactor(agent): decouple ai-proxy via factory injection pattern#1455
refactor(agent): decouple ai-proxy via factory injection pattern#1455
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>
2 new issues
|
…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 (8)
🛟 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>

Summary
@forestadmin/ai-proxyfrom hard dependency to optional peer dependency in@forestadmin/agentcreateAiProvider()factory inai-proxyfollowing the existingaddDataSource(createSqlDataSource(...))patternAiRouter/AiProviderDefinitioninterfaces indatasource-toolkit@forestadmin/ai-proxyimports from agent source code (duck-typed error handling instead ofinstanceof)Before:
After:
This eliminates ~6 langchain packages from the default install for users who don't use AI features.
Test plan
datasource-toolkit,ai-proxy,agent)datasource-toolkittests pass (457 tests)ai-proxytests pass (82 tests) including newcreateAiProvidertestagenttests pass (886 tests) with updated mocksai-proxyonly appears inpeerDependenciesof agent'spackage.json🤖 Generated with Claude Code