forked from boos/BoosAPI
fix: finish review-driven single-source cleanup
This commit is contained in:
@@ -92,6 +92,12 @@ describe('proxy route architecture boundaries', () => {
|
||||
expect(source).not.toContain('normalizeContentText(');
|
||||
});
|
||||
|
||||
it('keeps codex runtime header and prompt-cache derivation inside provider profiles', () => {
|
||||
const source = readSource('./upstreamEndpoint.ts');
|
||||
expect(source).not.toContain('buildCodexRuntimeHeaders(');
|
||||
expect(source).not.toContain('shouldInjectDerivedPromptCacheKey');
|
||||
});
|
||||
|
||||
it('keeps gemini runtime closure in transformer-owned helpers', () => {
|
||||
const source = readSource('./gemini.ts');
|
||||
const surfaceSource = readSource('../../proxy-core/surfaces/geminiSurface.ts');
|
||||
@@ -139,6 +145,23 @@ describe('proxy route architecture boundaries', () => {
|
||||
expect(surfaceSource).toContain('openAiResponsesTransformer.proxyStream.createSession(');
|
||||
});
|
||||
|
||||
it('keeps oauth refresh recovery and success bookkeeping behind shared surface helpers', () => {
|
||||
const chatSurfaceSource = readSource('../../proxy-core/surfaces/chatSurface.ts');
|
||||
const responsesSurfaceSource = readSource('../../proxy-core/surfaces/openAiResponsesSurface.ts');
|
||||
|
||||
expect(chatSurfaceSource).toContain('trySurfaceOauthRefreshRecovery(');
|
||||
expect(chatSurfaceSource).toContain('recordSurfaceSuccess(');
|
||||
expect(chatSurfaceSource).not.toContain('refreshOauthAccessTokenSingleflight(');
|
||||
expect(chatSurfaceSource).not.toContain('resolveProxyUsageWithSelfLogFallback(');
|
||||
expect(chatSurfaceSource).not.toContain('resolveProxyLogBilling(');
|
||||
|
||||
expect(responsesSurfaceSource).toContain('trySurfaceOauthRefreshRecovery(');
|
||||
expect(responsesSurfaceSource).toContain('recordSurfaceSuccess(');
|
||||
expect(responsesSurfaceSource).not.toContain('refreshOauthAccessTokenSingleflight(');
|
||||
expect(responsesSurfaceSource).not.toContain('resolveProxyUsageWithSelfLogFallback(');
|
||||
expect(responsesSurfaceSource).not.toContain('resolveProxyLogBilling(');
|
||||
});
|
||||
|
||||
it('keeps canonical transformer contracts imported from the transformer boundary only', () => {
|
||||
const chatSource = readSource('./chat.ts');
|
||||
const responsesSource = readSource('./responses.ts');
|
||||
|
||||
@@ -29,10 +29,7 @@ import {
|
||||
} from '../../transformers/shared/endpointCompatibility.js';
|
||||
import {
|
||||
buildClaudeRuntimeHeaders,
|
||||
buildCodexRuntimeHeaders,
|
||||
buildGeminiCliRuntimeHeaders,
|
||||
buildGeminiCliUserAgent,
|
||||
getInputHeader,
|
||||
headerValueToString,
|
||||
} from '../../proxy-core/providers/headerUtils.js';
|
||||
export {
|
||||
@@ -1234,7 +1231,10 @@ export function buildUpstreamEndpointRequest(input: {
|
||||
);
|
||||
const configuredResponsesBody = applyConfiguredPayloadRules(body);
|
||||
|
||||
if (providerProfile?.id === 'codex') {
|
||||
if (sitePlatform === 'codex') {
|
||||
if (providerProfile?.id !== 'codex') {
|
||||
throw new Error(`missing codex provider profile for platform: ${sitePlatform}`);
|
||||
}
|
||||
return providerProfile.prepareRequest({
|
||||
endpoint: 'responses',
|
||||
modelName: input.modelName,
|
||||
@@ -1254,39 +1254,14 @@ export function buildUpstreamEndpointRequest(input: {
|
||||
});
|
||||
}
|
||||
|
||||
const headers = sitePlatform === 'codex'
|
||||
? buildCodexRuntimeHeaders({
|
||||
baseHeaders: {
|
||||
...commonHeaders,
|
||||
...responsesHeaders,
|
||||
},
|
||||
providerHeaders: input.providerHeaders,
|
||||
explicitSessionId: asTrimmedString(input.codexExplicitSessionId) || null,
|
||||
continuityKey: asTrimmedString(input.codexSessionCacheKey) || null,
|
||||
})
|
||||
: ensureStreamAcceptHeader({
|
||||
...commonHeaders,
|
||||
...responsesHeaders,
|
||||
}, input.stream);
|
||||
const codexSessionId = sitePlatform === 'codex'
|
||||
? (getInputHeader(headers, 'session_id') || getInputHeader(headers, 'session-id'))
|
||||
: null;
|
||||
const shouldInjectDerivedPromptCacheKey = sitePlatform === 'codex'
|
||||
&& !!codexSessionId
|
||||
&& !asTrimmedString((configuredResponsesBody as Record<string, unknown>).prompt_cache_key)
|
||||
&& !asTrimmedString(input.codexExplicitSessionId)
|
||||
&& !!asTrimmedString(input.codexSessionCacheKey);
|
||||
const runtimeBody = shouldInjectDerivedPromptCacheKey
|
||||
? {
|
||||
...configuredResponsesBody,
|
||||
prompt_cache_key: codexSessionId,
|
||||
}
|
||||
: configuredResponsesBody;
|
||||
|
||||
const headers = ensureStreamAcceptHeader({
|
||||
...commonHeaders,
|
||||
...responsesHeaders,
|
||||
}, input.stream);
|
||||
return {
|
||||
path: resolveEndpointPath('responses'),
|
||||
headers,
|
||||
body: runtimeBody,
|
||||
body: configuredResponsesBody,
|
||||
runtime,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user