mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-17 22:58:21 +00:00
fix(codex): align routed catalogs with actual routes
Anthropic fallbacks previously reused Antigravity defaults, leaking Gemini models into Claude-only groups. Composite aliases were also emitted with generic metadata and could be scheduled to accounts that did not own the exact mapping, while generated configs could default to a model absent from the downloaded catalog. Keep provider defaults separated, derive alias capabilities from unique upstream targets with conservative fallback, require exact mapping ownership during scheduling, filter media targets, and choose generated config defaults from the fetched catalog.
This commit is contained in:
8 files changed
+445
-23
No files matched your search
@@ -627,6 +627,29 @@ function downloadCodexModelManifest() {
|
||||
)
|
||||
}
|
||||
|
||||
const codexCatalogModelSlugs = computed(() => {
|
||||
if (!codexModelManifestContent.value) return []
|
||||
try {
|
||||
const payload: unknown = JSON.parse(codexModelManifestContent.value)
|
||||
if (typeof payload !== 'object' || payload === null || !('models' in payload)) return []
|
||||
const models = (payload as { models?: unknown }).models
|
||||
if (!Array.isArray(models)) return []
|
||||
return models.flatMap((model) => {
|
||||
if (typeof model !== 'object' || model === null || !('slug' in model)) return []
|
||||
const slug = (model as { slug?: unknown }).slug
|
||||
if (typeof slug !== 'string' || !slug.trim()) return []
|
||||
return [slug.trim()]
|
||||
})
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
})
|
||||
|
||||
function selectCodexCatalogModel(preferredModel: string): string {
|
||||
if (codexCatalogModelSlugs.value.includes(preferredModel)) return preferredModel
|
||||
return codexCatalogModelSlugs.value[0] || preferredModel
|
||||
}
|
||||
|
||||
const escapeHtml = (value: string) => value
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
@@ -884,10 +907,12 @@ function generateOpenAIFiles(baseUrl: string, apiKey: string): FileConfig[] {
|
||||
const isWindows = activeTab.value === 'windows'
|
||||
const configDir = isWindows ? '%userprofile%\\.codex' : '~/.codex'
|
||||
|
||||
const model = selectCodexCatalogModel('gpt-5.5')
|
||||
|
||||
// config.toml content
|
||||
const configContent = `model_provider = "OpenAI"
|
||||
model = "gpt-5.5"
|
||||
review_model = "gpt-5.5"
|
||||
model = "${model}"
|
||||
review_model = "${model}"
|
||||
model_reasoning_effort = "xhigh"
|
||||
disable_response_storage = true
|
||||
model_catalog_json = "${escapeTomlBasicString(codexModelCatalogPath.value)}"
|
||||
@@ -1087,6 +1112,7 @@ function generateGrokCodexFiles(baseUrl: string, apiKey: string): FileConfig[] {
|
||||
const shell = activeTab.value
|
||||
const isWindowsPath = shell === 'windows' || shell === 'cmd' || shell === 'powershell'
|
||||
const configDir = isWindowsPath ? '%userprofile%\\.codex' : '~/.codex'
|
||||
const model = selectCodexCatalogModel('grok-4.5')
|
||||
|
||||
let envPath: string
|
||||
let envContent: string
|
||||
@@ -1112,10 +1138,10 @@ function generateGrokCodexFiles(baseUrl: string, apiKey: string): FileConfig[] {
|
||||
# Switch model: grok-4.5 | grok-4.3 | grok-build-0.1 | grok-4.20-multi-agent-0309 (text / web_search)
|
||||
|
||||
model_provider = "sub2api"
|
||||
model = "grok-4.5"
|
||||
model = "${model}"
|
||||
model_catalog_json = "${escapeTomlBasicString(codexModelCatalogPath.value)}"
|
||||
# Optional:
|
||||
# review_model = "grok-4.5"
|
||||
# review_model = "${model}"
|
||||
# model_reasoning_effort = "medium"
|
||||
# model_context_window = 500000
|
||||
# disable_response_storage = true
|
||||
@@ -1156,7 +1182,8 @@ function generateRoutedCodexFiles(
|
||||
): FileConfig[] {
|
||||
const isWindows = activeTab.value === 'windows'
|
||||
const configDir = isWindows ? '%userprofile%\\.codex' : '~/.codex'
|
||||
const model = platform === 'deepseek' ? 'deepseek-v4-pro' : 'gpt-5.5'
|
||||
const preferredModel = platform === 'deepseek' ? 'deepseek-v4-pro' : 'gpt-5.5'
|
||||
const model = selectCodexCatalogModel(preferredModel)
|
||||
const label = platform === 'deepseek' ? 'DeepSeek' : 'Composite'
|
||||
const envContent = isWindows
|
||||
? `$env:SUB2API_API_KEY="${apiKey}"`
|
||||
@@ -1190,11 +1217,12 @@ supports_websockets = false`
|
||||
function generateOpenAIWsFiles(baseUrl: string, apiKey: string): FileConfig[] {
|
||||
const isWindows = activeTab.value === 'windows'
|
||||
const configDir = isWindows ? '%userprofile%\\.codex' : '~/.codex'
|
||||
const model = selectCodexCatalogModel('gpt-5.5')
|
||||
|
||||
// config.toml content with WebSocket v2
|
||||
const configContent = `model_provider = "OpenAI"
|
||||
model = "gpt-5.5"
|
||||
review_model = "gpt-5.5"
|
||||
model = "${model}"
|
||||
review_model = "${model}"
|
||||
model_reasoning_effort = "xhigh"
|
||||
disable_response_storage = true
|
||||
model_catalog_json = "${escapeTomlBasicString(codexModelCatalogPath.value)}"
|
||||
|
||||
@@ -618,10 +618,10 @@ describe('UseKeyModal', () => {
|
||||
const manifest = {
|
||||
models: [
|
||||
{
|
||||
slug: 'gpt-5.5',
|
||||
slug: 'claude-opus-4-8',
|
||||
default_reasoning_level: 'medium',
|
||||
supported_reasoning_levels: [{ effort: 'xhigh', description: 'Extra-high reasoning depth' }],
|
||||
input_modalities: ['text', 'image'],
|
||||
supported_reasoning_levels: [{ effort: 'max', description: 'Maximum reasoning depth' }],
|
||||
input_modalities: ['text'],
|
||||
model_messages: { instructions_template: 'Use the routed model.' }
|
||||
},
|
||||
{
|
||||
@@ -684,6 +684,13 @@ describe('UseKeyModal', () => {
|
||||
expect(wrapper.get('[data-testid="codex-model-catalog"]').text())
|
||||
.toContain('keys.useKeyModal.codexModelCatalog.download')
|
||||
|
||||
const loadedUnixConfig = wrapper.findAll('pre code')
|
||||
.map((code) => code.text())
|
||||
.find((content) => content.includes('[model_providers.sub2api]'))
|
||||
expect(loadedUnixConfig).toContain('model = "claude-opus-4-8"')
|
||||
expect(loadedUnixConfig).toContain('review_model = "claude-opus-4-8"')
|
||||
expect(loadedUnixConfig).not.toContain('model = "gpt-5.5"')
|
||||
|
||||
const downloadButton = wrapper.findAll('button').find((button) =>
|
||||
button.text().includes('keys.useKeyModal.codexModelCatalog.download')
|
||||
)
|
||||
@@ -705,4 +712,51 @@ describe('UseKeyModal', () => {
|
||||
'model_catalog_json = "%userprofile%\\\\.codex\\\\codex-models.json"'
|
||||
)
|
||||
})
|
||||
|
||||
// Scenario: the platform-preferred model remains selected when the downloaded catalog contains it.
|
||||
it('keeps the preferred Composite default when it exists in the catalog', async () => {
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
status: 200,
|
||||
json: async () => ({
|
||||
models: [
|
||||
{ slug: 'claude-opus-4-8' },
|
||||
{ slug: 'gpt-5.5' }
|
||||
]
|
||||
})
|
||||
}))
|
||||
|
||||
const wrapper = mount(UseKeyModal, {
|
||||
props: {
|
||||
show: true,
|
||||
apiKey: 'sk-composite-test',
|
||||
baseUrl: 'https://example.com/v1',
|
||||
platform: 'composite'
|
||||
},
|
||||
global: {
|
||||
stubs: {
|
||||
BaseDialog: {
|
||||
template: '<div><slot /><slot name="footer" /></div>'
|
||||
},
|
||||
Icon: {
|
||||
template: '<span />'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const codexTab = wrapper.findAll('button').find((button) =>
|
||||
button.text().includes('keys.useKeyModal.cliTabs.codexCli')
|
||||
)
|
||||
expect(codexTab).toBeDefined()
|
||||
await codexTab!.trigger('click')
|
||||
await wrapper.get('[data-testid="codex-model-catalog-fetch"]').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
const config = wrapper.findAll('pre code')
|
||||
.map((code) => code.text())
|
||||
.find((content) => content.includes('[model_providers.sub2api]'))
|
||||
expect(config).toContain('model = "gpt-5.5"')
|
||||
expect(config).toContain('review_model = "gpt-5.5"')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user