-
Notifications
You must be signed in to change notification settings - Fork 9k
feat(gateway): add Concentrate AI provider with dynamic model discovery #2140
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
cb94011
feat(gateway): add Concentrate AI provider with dynamic model discovery
jatmn 16faa99
fix(concentrate): prompt for Concentrate API key in /provider instead…
jatmn 3e154c7
docs(concentrate): remove standalone setup guide to match other gateways
jatmn a843b37
fix(concentrate): dedicated-credential-only routing, env-only identit…
jatmn 1d5c66f
fix(concentrate): protect credentials on noncanonical urls
jatmn 90a1fb8
fix(concentrate): drop legacy keys on retargeted profiles
jatmn fae0c21
fix(concentrate): remove legacy generic keys on proxies
jatmn 6992d4b
fix(concentrate): reject noncanonical credential routes
jatmn 1ee6d09
fix(concentrate): validate env-only credentials
jatmn 1eb5aba
fix(concentrate): align env-only route validation
jatmn e88cbfa
fix(concentrate): clear headers before client setup
jatmn d30d8a9
test(validation): isolate Concentrate model env
jatmn a52cf2b
fix(concentrate): honor provider precedence and model defaults
jatmn fd93e09
test(concentrate): cover model resolution precedence
jatmn 922b285
fix(concentrate): preserve legacy model fallback
jatmn aa2bb4a
fix(concentrate): normalize early model selection
jatmn 3d6a601
fix(concentrate): validate and select rejected models safely
jatmn 48243f3
fix(concentrate): reset stale route state
jatmn 75aa0f2
fix(concentrate): preserve proxy profile capabilities
jatmn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import { describe, expect, test } from 'bun:test' | ||
|
|
||
| import concentrate from './concentrate.js' | ||
|
|
||
| const mapModel = concentrate.catalog?.discovery?.mapModel | ||
|
|
||
| describe('concentrate gateway', () => { | ||
| test('uses dynamic discovery and supports fallback auth', () => { | ||
| expect(concentrate.id).toBe('concentrate') | ||
| expect(concentrate.label).toBe('Concentrate') | ||
| expect(concentrate.category).toBe('aggregating') | ||
| expect(concentrate.defaultBaseUrl).toBe('https://api.concentrate.ai/v1') | ||
| expect(concentrate.defaultModel).toBe('deepseek-v4-flash') | ||
| expect(concentrate.supportsModelRouting).toBe(true) | ||
|
|
||
| expect(concentrate.setup.requiresAuth).toBe(true) | ||
| expect(concentrate.setup.authMode).toBe('api-key') | ||
| expect(concentrate.setup.credentialEnvVars).toEqual(['CONCENTRATE_API_KEY']) | ||
| expect(concentrate.setup.dedicatedCredentialsOnly).toBeUndefined() | ||
|
|
||
| expect(concentrate.catalog?.source).toBe('dynamic') | ||
| expect(concentrate.catalog?.discovery?.kind).toBe('openai-compatible') | ||
| expect(concentrate.catalog?.discovery?.requiresAuth).toBe(false) | ||
|
|
||
| expect(concentrate.validation?.kind).toBe('credential-env') | ||
| expect( | ||
| (concentrate.validation as { credentialEnvVars: string[] }).credentialEnvVars, | ||
| ).toEqual([ | ||
| 'CONCENTRATE_API_KEY', | ||
| 'OPENAI_API_KEYS', | ||
| 'OPENAI_API_KEY', | ||
| ]) | ||
|
|
||
| expect(mapModel).toBeDefined() | ||
| }) | ||
|
|
||
| test('mapModel keeps chat models and drops non-chat ids', () => { | ||
| if (!mapModel) throw new Error('mapModel missing') | ||
|
|
||
| expect( | ||
| mapModel({ | ||
| id: 'deepseek-v4-flash', | ||
| display_name: 'DeepSeek V4 Flash', | ||
| owned_by: 'deepseek', | ||
| max_input_tokens: 1_048_576, | ||
| max_tokens: 393_216, | ||
| }), | ||
| ).toEqual({ | ||
| id: 'deepseek-v4-flash', | ||
| apiName: 'deepseek-v4-flash', | ||
| label: 'DeepSeek V4 Flash', | ||
| contextWindow: 1_048_576, | ||
| maxOutputTokens: 393_216, | ||
| }) | ||
|
|
||
| expect( | ||
| mapModel({ | ||
| id: 'claude-sonnet-5', | ||
| display_name: 'Claude Sonnet 5', | ||
| owned_by: 'anthropic', | ||
| max_input_tokens: 200_000, | ||
| max_tokens: 64_000, | ||
| }), | ||
| ).toEqual({ | ||
| id: 'claude-sonnet-5', | ||
| apiName: 'claude-sonnet-5', | ||
| label: 'Claude Sonnet 5', | ||
| contextWindow: 200_000, | ||
| maxOutputTokens: 64_000, | ||
| }) | ||
|
|
||
| expect(mapModel({ id: 'redact-v1' })).toBeNull() | ||
| expect(mapModel({ id: 'gpt-oss-safeguard-120b' })).toBeNull() | ||
| expect(mapModel({ id: 'text-embedding-3-small' })).toBeNull() | ||
| expect(mapModel({ id: 'whisper-1' })).toBeNull() | ||
| expect(mapModel({})).toBeNull() | ||
| expect(mapModel(null)).toBeNull() | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import { defineGateway } from '../define.js' | ||
|
|
||
| const NON_CHAT_MODEL_PATTERN = | ||
| /redact|safeguard|embed|embedding|whisper|tts|dall-e|rerank|moderation|image-generation|video-generation|audio-generation/i | ||
|
|
||
| function isRecord(value: unknown): value is Record<string, unknown> { | ||
| return typeof value === 'object' && value !== null | ||
| } | ||
|
|
||
| function getTrimmedString( | ||
| record: Record<string, unknown>, | ||
| key: string, | ||
| ): string | undefined { | ||
| const value = record[key] | ||
| return typeof value === 'string' ? value.trim() : undefined | ||
| } | ||
|
|
||
| function getPositiveInteger(value: unknown): number | undefined { | ||
| if ( | ||
| typeof value === 'number' && | ||
| Number.isFinite(value) && | ||
| Number.isInteger(value) && | ||
| value > 0 | ||
| ) { | ||
| return value | ||
| } | ||
| return undefined | ||
| } | ||
|
|
||
| function mapConcentrateModel(raw: unknown) { | ||
| if (!isRecord(raw)) { | ||
| return null | ||
| } | ||
|
|
||
| const id = getTrimmedString(raw, 'id') | ||
| if (!id || NON_CHAT_MODEL_PATTERN.test(id)) { | ||
| return null | ||
| } | ||
|
|
||
| const displayName = getTrimmedString(raw, 'display_name') | ||
| const label = displayName || id | ||
| const contextWindow = getPositiveInteger(raw.max_input_tokens) | ||
| const maxOutputTokens = getPositiveInteger(raw.max_tokens) | ||
|
|
||
| return { | ||
| id, | ||
| apiName: id, | ||
| label, | ||
| ...(contextWindow !== undefined ? { contextWindow } : {}), | ||
| ...(maxOutputTokens !== undefined ? { maxOutputTokens } : {}), | ||
| } | ||
| } | ||
|
|
||
| export default defineGateway({ | ||
| id: 'concentrate', | ||
| label: 'Concentrate', | ||
| category: 'aggregating', | ||
| defaultBaseUrl: 'https://api.concentrate.ai/v1', | ||
| defaultModel: 'deepseek-v4-flash', | ||
| supportsModelRouting: true, | ||
| setup: { | ||
| requiresAuth: true, | ||
| authMode: 'api-key', | ||
| credentialEnvVars: ['CONCENTRATE_API_KEY'], | ||
| }, | ||
| startup: { | ||
| probeReadiness: 'openai-compatible-models', | ||
| }, | ||
| transportConfig: { | ||
| kind: 'openai-compatible', | ||
| openaiShim: { | ||
| supportsApiFormatSelection: false, | ||
| supportsAuthHeaders: false, | ||
| maxTokensField: 'max_tokens', | ||
| }, | ||
| }, | ||
| preset: { | ||
| id: 'concentrate', | ||
| description: 'Concentrate AI — 150+ models via OpenAI-compatible API', | ||
| vendorId: 'openai', | ||
| apiKeyEnvVars: ['CONCENTRATE_API_KEY'], | ||
| baseUrlEnvVars: ['CONCENTRATE_BASE_URL'], | ||
| modelEnvVars: ['CONCENTRATE_MODEL', 'OPENAI_MODEL'], | ||
| }, | ||
| validation: { | ||
| kind: 'credential-env', | ||
| routing: { | ||
| matchDefaultBaseUrl: true, | ||
| matchBaseUrlHosts: ['api.concentrate.ai'], | ||
| }, | ||
| credentialEnvVars: [ | ||
| 'CONCENTRATE_API_KEY', | ||
| 'OPENAI_API_KEYS', | ||
| 'OPENAI_API_KEY', | ||
| ], | ||
| missingCredentialMessage: | ||
| 'Concentrate auth is required. Set CONCENTRATE_API_KEY or OPENAI_API_KEY.', | ||
| }, | ||
| catalog: { | ||
| source: 'dynamic', | ||
| discovery: { | ||
| kind: 'openai-compatible', | ||
| requiresAuth: false, | ||
| mapModel: mapConcentrateModel, | ||
| }, | ||
| discoveryCacheTtl: '1d', | ||
| discoveryRefreshMode: 'startup', | ||
| allowManualRefresh: true, | ||
| }, | ||
| usage: { supported: false }, | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.