Repository navigation
Conversation
* 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>
…erve Responses status boundary Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…mpatibility.ts Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in upstream feature flag
merge-consecutive-same-role-messages(defaultfalseacross all upstreams) for upstreams that require strict role alternation and reject adjacent messages with the same role.Behavior
Runs inside
withRoleCompatibilityAppliedafter role-rewrite flags (such asrewrite-all-system-to-user,rewrite-system-to-developer,rewrite-developer-to-system, andrewrite-mid-conv-system-to-user) so newly adjacent messages produced by rewrites are also merged:packages/gateway/src/data-plane/chat/anthropic-messages/interceptors/apply-role-compatibility.ts): merges consecutiveuserand content-bearingsystemmessages (\n\nfor string + string; concatenating blocks when either side is an array). Leavesassistantmessages and directive-onlysystemmessages carryingoutput_configseparate.packages/gateway/src/data-plane/chat/openai-chat-completions/interceptors/apply-role-compatibility.ts): merges consecutiveuser,developer, andsystemmessages sharing the samename. Leavesassistantmessages and distinctnameboundaries separate.packages/gateway/src/data-plane/chat/openai-responses/interceptors/apply-role-compatibility.ts): merges consecutivemessageitems with roleuser,developer, orsystemand matchingphase. Leavesassistantmessages and non-message items (e.g.function_call) separate.packages/gateway/src/data-plane/chat/gemini-generate-content/interceptors/apply-role-compatibility.ts): merges consecutiveuser(including omittedrole),developer, andsystemcontentsentries by concatenatingparts. Leavesmodelandassistantturns separate.Verification
@floway-dev/upstream, all 7 upstream provider packages,@floway-dev/gateway, and@floway-dev/web).assistant/model/output_config/name/ non-message items), and composition with role-rewrite flags.