feat(codex): align Search and execution protocol

This commit is contained in:
MMEXA
2026-07-12 03:04:15 +08:00
parent 59d37ae1dd
commit 2316df5c9a
121 changed files with 5141 additions and 543 deletions
@@ -9,6 +9,7 @@ const apiFormats = [
{ value: 'gemini:embedding', default_path: '/v1beta/models/{model}:embedContent' },
{ value: 'gemini:video', default_path: '/v1beta/models/{model}:predictLongRunning' },
{ value: 'openai:responses', default_path: '/v1/responses' },
{ value: 'openai:search', default_path: '/v1/alpha/search' },
{ value: 'openai:embedding', default_path: '/v1/embeddings' },
{ value: 'openai:rerank', default_path: '/v1/rerank' },
{ value: 'openai:image', default_path: '/v1/images/generations' },
@@ -75,6 +76,30 @@ describe('endpoint default paths', () => {
})).toBe('/responses')
})
it('uses the Search path relative to OpenAI and Codex api roots', () => {
expect(getDefaultEndpointBaseUrl({
apiFormat: 'openai:search',
baseUrl: 'https://api.openai.com',
})).toBe('https://api.openai.com/v1')
expect(getDefaultEndpointPath({
apiFormat: 'openai:search',
providerType: 'openai',
baseUrl: 'https://api.openai.com/v1',
apiFormats,
})).toBe('/alpha/search')
expect(getDefaultEndpointBaseUrl({
apiFormat: 'openai:search',
baseUrl: 'https://chatgpt.com/backend-api/codex',
})).toBe('https://chatgpt.com/backend-api/codex')
expect(getDefaultEndpointPath({
apiFormat: 'openai:search',
providerType: 'codex',
baseUrl: 'https://chatgpt.com/backend-api/codex',
apiFormats,
})).toBe('/alpha/search')
})
it('drops /v1 from API-root defaults because base URL is the API root', () => {
expect(getDefaultEndpointPath({
apiFormat: 'openai:chat',
@@ -0,0 +1,15 @@
import { describe, expect, it } from 'vitest'
import { fixedEndpointUpstreamStreamPolicy } from '../endpoint-protocol-policy'
describe('fixedEndpointUpstreamStreamPolicy', () => {
it('uses the fixed Codex transport mode for each protocol', () => {
expect(fixedEndpointUpstreamStreamPolicy('codex', 'openai:responses')).toBe('force_stream')
expect(fixedEndpointUpstreamStreamPolicy('codex', 'openai:search')).toBe('force_non_stream')
})
it('applies Search synchronization by format and keeps other formats configurable', () => {
expect(fixedEndpointUpstreamStreamPolicy('custom', 'openai:search')).toBe('force_non_stream')
expect(fixedEndpointUpstreamStreamPolicy('codex', 'openai:responses:compact')).toBeNull()
})
})