Skip to content

refactor(chatCore): extrai resolução de endpoint/formato para leaf puro (#3501) - #4507

Merged
diegosouzapw merged 2 commits into
refactor/qg-chatcore-codexquotafrom
refactor/qg-chatcore-reqformat
Jun 21, 2026
Merged

diegosouzapw merged 2 commits into
refactor/qg-chatcore-codexquotafrom
refactor/qg-chatcore-reqformat

Conversation

@diegosouzapw

Copy link
Copy Markdown
Owner

O quê

Próximo incremento da decomposição do god-file chatCore.ts (QG v2 Fase 9 T5, #3501). Move o bloco de resolução de endpoint/formato do topo de handleChatCore para o novo leaf puro open-sse/handlers/chatCore/requestFormat.ts (resolveChatCoreRequestFormat), ao lado de resolveChatCoreRequestSetup (fase de request-setup).

Stacked sobre o #4492 (4º da cadeia #4477 → #4491 → #4492 → este). Base aponta para refactor/qg-chatcore-codexquota; o GitHub re-aponta a cadeia automaticamente conforme os pais mergeiam.

Como (preservação de comportamento)

  • Os 7 derivados (endpointPath / sourceFormat / isResponsesEndpoint / nativeCodexPassthrough / isDroidCLI / copilotCompatibleReasoning / clientResponseFormat) movem byte-idênticos para o leaf puro; o handler desestrutura o resultado, então todo uso downstream fica inalterado.
  • A função local isCopilotClient (usada só por esse bloco) vira helper privado do leaf.
  • Import órfão detectFormatFromEndpoint migra para o leaf (getTargetFormat permanece no import de provider.ts). shouldUseNativeCodexPassthrough e FORMATS seguem no handler (re-exportado / usado em 26 pontos).
  • Tipo via ReturnType<typeof resolveChatCoreRequestFormat> (sem anotação manual divergente).

Gates

  • file-size: chatCore.ts 5019→4993 (shrink −26, cruza abaixo de 5000); baseline ratchetado.
  • complexity: 1905 = baseline 1905 (neutro).
  • typecheck:core: exit 0.
  • Testes: tests/unit/chatcore-request-format.test.ts — 7 casos (incl. o downgrade OpenAI-Responses → OpenAI quando a forma Responses chega por endpoint não-/responses e não-Droid, e a supressão desse downgrade pelo Droid CLI; delegação do nativeCodexPassthrough; detecção Copilot por header/UA). chatcore-imports-cleanly ✓ + 207/207 na suíte chatcore + sse-auth (excluído só o translation-paths flaky pré-existente).

Extração de god-file sem mudança de comportamento em runtime.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors open-sse/handlers/chatCore.ts by extracting the endpoint and format resolution logic into a new module open-sse/handlers/chatCore/requestFormat.ts and adding corresponding unit tests. Feedback is provided to improve type safety by replacing an unsafe type assertion with the standard headers.entries() method when iterating over headers.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +27 to +31
if (headers instanceof Headers) {
for (const [key, value] of headers as unknown as Iterable<[string, string]>) {
if (isMatch(key) || isMatch(value)) return true;
}
} else if (headers && typeof headers === "object") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instead of using an unsafe type assertion (as unknown as Iterable<[string, string]>), you can use the standard headers.entries() method which returns an IterableIterator<[string, string]>. This is fully type-safe and cleaner.

  if (headers instanceof Headers) {
    for (const [key, value] of headers.entries()) {
      if (isMatch(key) || isMatch(value)) return true;
    }
  }

…3501)

Rebuilt onto release/v3.8.33. Extracts persistCodexQuotaState into a pure leaf (chatCore/codexQuota.ts). Integrated into release/v3.8.33.
@diegosouzapw
diegosouzapw changed the base branch from release/v3.8.33 to refactor/qg-chatcore-codexquota June 21, 2026 17:19
…ro (#3501)

Move o bloco de resolução de formato do topo de handleChatCore (endpointPath /
sourceFormat / isResponsesEndpoint / nativeCodexPassthrough / isDroidCLI /
copilotCompatibleReasoning / clientResponseFormat) para o novo leaf puro
open-sse/handlers/chatCore/requestFormat.ts (resolveChatCoreRequestFormat), ao
lado de resolveChatCoreRequestSetup (fase de request-setup). O handler agora
desestrutura o resultado, então todo uso downstream fica byte-idêntico.

A função local isCopilotClient (usada só por esse bloco) vira helper privado do
leaf; o import órfão detectFormatFromEndpoint migra junto (getTargetFormat
permanece no import de provider). shouldUseNativeCodexPassthrough e FORMATS
seguem importados no handler (re-exportado / usado em vários pontos).

chatCore.ts 5019->4993 (shrink -26, cruza abaixo de 5000); baseline file-size
ratchetado. complexity 1905=1905 (neutro). Coberto por
tests/unit/chatcore-request-format.test.ts (7 casos, incluindo o downgrade
OpenAI-Responses->OpenAI e sua supressão pelo Droid CLI).
@diegosouzapw
diegosouzapw force-pushed the refactor/qg-chatcore-reqformat branch from c0fd352 to ac7779e Compare June 21, 2026 17:20
@diegosouzapw
diegosouzapw merged commit 0f67eee into refactor/qg-chatcore-codexquota Jun 21, 2026
1 check passed
diegosouzapw added a commit that referenced this pull request Jun 21, 2026
…e by churn (#3501) (#4547)

Re-applies the endpoint/format (requestFormat.ts, #4507) and Claude effort-variant (claudeEffortVariant.ts, #4511) extractions that were orphaned from release/v3.8.33 by a parallel force-push. 19/19 chatCore tests pass.

Integrated into release/v3.8.33.
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
…ves orphaned from release by churn (diegosouzapw#3501) (diegosouzapw#4547)

Re-applies the endpoint/format (requestFormat.ts, diegosouzapw#4507) and Claude effort-variant (claudeEffortVariant.ts, diegosouzapw#4511) extractions that were orphaned from release/v3.8.33 by a parallel force-push. 19/19 chatCore tests pass.

Integrated into release/v3.8.33.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant