Skip to content

feat(upstream): hide flags that cannot apply to an upstream kind - #807

Open
yyyr-p wants to merge 7 commits into
Menci:mainfrom
yyyr-p:devin/1796210310-upstream-kind-feature-gating
Open

yyyr-p wants to merge 7 commits into
Menci:mainfrom
yyyr-p:devin/1796210310-upstream-kind-feature-gating

Conversation

@yyyr-p

@yyyr-p yyyr-p commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The upstream editor offered every optional flag on every upstream kind, including flags that can never take effect for that kind, and one (strip-billing-attribution on Claude Code) that always breaks billing. Each kind's exhaustive flag-defaults map can now mark a flag 'unavailable', and the gateway enforces that end-to-end. The dashboard adds no new control; it hides those flags.

type FlagDefault = boolean | 'unavailable';
type FlagDefaults = Readonly<Record<FlagId, FlagDefault>>; // still exhaustive per kind

// e.g. CLAUDE_CODE_DEFAULT_FLAGS
'strip-billing-attribution': 'unavailable',
'anthropic-messages-web-search-shim': false,

Because *_DEFAULT_FLAGS is exhaustive, adding a flag to the catalog fails to compile until every kind declares it on, off, or unavailable. Availability and defaults live in one map.

  • Resolution: resolveEffectiveFlags(defaults, layers) now takes the kind's defaults separately. An unavailable flag starts off and ignores every override layer (operator, client profile, per-model), so a stored override for it never takes effect.
  • Control plane: POST /api/upstreams and PATCH /api/upstreams/:id return 400 for flag_overrides that set an id from unavailableFlagIds(flagDefaultsForKind(kind)). Serialized records drop those ids from flag_overrides (withoutUnavailableFlags), so a dashboard round-trip clears stale values. flag_defaults carries 'unavailable' on the wire.
  • Web: FeatureFlagsEditor skips flags whose default is 'unavailable' at both the upstream and per-model level, and does not render a group left with no flags.
Kind Unavailable flags Reason
custom, azure none Endpoints and models are configured by the operator
copilot, kimi-code, ollama vendor-deepseek, vendor-qwen, vendor-mistral The kind never speaks those vendor dialects. Ollama's OpenAI-compatible routes bind requests into a fixed struct and convert them to its native API, so the dialect fields are dropped
chatgpt vendor-*, anthropic-messages-web-search-shim, rewrite-disallowed-mid-conv-system-to-user, openai-responses-store-false, usage-exclusive-cached-tokens Responses only: the Anthropic shim is unconditional on translated targets, and only the Anthropic Messages role step reads the disallowed-placement rewrite. Codex already forces store: false, and its usage follows the OpenAI convention
claude-code vendor-*, the openai-responses-* web-search, image-generation, compact, compact-decrypt, agent-message, standalone-tool-output and null-unresolved-namespace flags, rewrite-developer-to-system, rewrite-system-to-developer, strip-prompt-cache-key, usage-exclusive-cached-tokens, openai-responses-store-false, strip-billing-attribution Anthropic Messages only: each OpenAI Responses shim is forced on whenever the target is not Responses, and OpenAI fields and roles never reach the wire. Usage is metered natively, and stripping attribution breaks plan billing

Source-side shims (openai-responses-*, anthropic-messages-web-search-shim) act on the downstream request, but their flag only takes effect when the selected target natively speaks that protocol, e.g. if (ctx.targetApi === 'openaiResponses' && !flags.has(...)) return run(). On every other target the shim always engages. They are therefore hidden only on kinds whose models never expose that endpoint. openai-responses-collaboration-shim is gated by its flag alone, so it stays visible everywhere.

yyyr-p and others added 7 commits December 1, 2026 19:19
* Add upstream system-to-user role compatibility

Gate the rewrite behind rewrite-all-system-to-user. Preserve the original system and developer roles in <system_instruction> and <developer_instruction> tags, and declare those tags in the leading system instruction when needed.

* Send empty leading system instructions without role tags

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…reams (Menci#802)

Third-party relays and Claude Code pool resellers commonly enforce
Claude Code client checks: User-Agent, X-Stainless-*, x-app,
anthropic-beta, the billing header, metadata.user_id, and the identity
system blocks. The wire mimicry that satisfies those checks lived only
inside @floway-dev/upstream-claude-code, so a Custom upstream layered on
top of such a relay had no way to reuse it.

Move the OAuth-independent Claude Code wire profile into
@floway-dev/upstream/client-profiles: request detection, the pinned
header surface, the inbound header allowlist, the Anthropic Messages
mimicry chain (backfill required fields, synthesize metadata.user_id,
hoist caller system text, inject the billing, identity, and cached
template blocks), and the per-profile default flags. The Claude Code
subscription provider delegates to the shared layer and keeps OAuth,
quota, and account state local.

Expose the profile as clientProfile: 'claude-code' on Custom upstreams,
validated in provider config and the control-plane schema, preserved on
serialization, and clearable through PATCH. Genuine Claude Code-shaped
Messages requests pass through with their system blocks, anthropic-beta
opt-ins, and metadata intact. Other requests run the mimicry chain,
merge caller-requested beta tokens without duplicates, keep
ingressHeadersRules override precedence, and do not leak
profile-admitted headers into non-Messages protocols. The profile layers
strip-billing-attribution: false and
rewrite-disallowed-mid-conv-system-to-user: true beneath operator and
model overrides; enabling strip-billing-attribution removes the billing
block and claude-code-20250219 token. Cached auto-model flags are
recomputed when the profile changes.

The dashboard gains a Client profile selector with en and zh-Hans
strings, a warning when the profile is set without the Anthropic
Messages endpoint, and profile-aware defaults in both flag editors.
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…e rewrite on chatgpt

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@yyyr-p
yyyr-p marked this pull request as ready for review December 2, 2026 12:25
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