fix: address codex review findings
This commit is contained in:
@@ -135,6 +135,19 @@ function carriesResponsesFileUrlInput(value: unknown): boolean {
|
||||
return Object.values(value).some((entry) => carriesResponsesFileUrlInput(entry));
|
||||
}
|
||||
|
||||
function shouldRefreshOauthResponsesRequest(input: {
|
||||
oauthProvider?: string;
|
||||
status: number;
|
||||
response: Response;
|
||||
rawErrText: string;
|
||||
}): boolean {
|
||||
if (input.status === 401) return true;
|
||||
if (input.status !== 403 || input.oauthProvider !== 'codex') return false;
|
||||
const authenticate = input.response.headers.get('www-authenticate') || '';
|
||||
const combined = `${authenticate}\n${input.rawErrText || ''}`;
|
||||
return /\b(invalid_token|expired_token|expired|invalid|unauthorized|account mismatch|authentication)\b/i.test(combined);
|
||||
}
|
||||
|
||||
type UsageSummary = ReturnType<typeof parseProxyUsage>;
|
||||
|
||||
export async function handleOpenAiResponsesSurfaceRequest(
|
||||
@@ -314,7 +327,12 @@ export async function handleOpenAiResponsesSurfaceRequest(
|
||||
dispatchRequest,
|
||||
});
|
||||
const tryRecover = async (ctx: Parameters<NonNullable<typeof endpointStrategy.tryRecover>>[0]) => {
|
||||
if ((ctx.response.status === 401 || ctx.response.status === 403) && oauth) {
|
||||
if (oauth && shouldRefreshOauthResponsesRequest({
|
||||
oauthProvider: oauth.provider,
|
||||
status: ctx.response.status,
|
||||
response: ctx.response,
|
||||
rawErrText: ctx.rawErrText || '',
|
||||
})) {
|
||||
try {
|
||||
const refreshed = await refreshOauthAccessTokenSingleflight(selected.account.id);
|
||||
selected.tokenValue = refreshed.accessToken;
|
||||
|
||||
Reference in New Issue
Block a user