-
Notifications
You must be signed in to change notification settings - Fork 835
feat(antigravity): Claude CCA wire fidelity #2070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yansigit
wants to merge
14
commits into
lidge-jun:dev
Choose a base branch
from
yansigit:feat/antigravity-cca-wire
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f725711
feat(antigravity): live quota RPC and geoblock classification
yansigit f3f8a51
fix(antigravity): harden quota interpretation and catalog fetch
yansigit 23ce6d2
fix(antigravity): preserve usable quota when summary fails
yansigit 396bd29
test(antigravity): assert quota RPC redirect policy
yansigit 2c45937
fix(antigravity): stop quota probe on terminal RPC errors
yansigit 2946115
fix(antigravity): drop last-good quota on terminal RPC and classify w…
yansigit b5b8a06
feat(antigravity): Claude CCA wire fidelity
yansigit 3f0e602
fix(google): retain CCA events and cap SSE frames correctly
yansigit 43b9b1f
fix(google): count raw SSE line bytes across UTF-8 chunk splits
yansigit b35ce84
test(google): account for Claude continuation nudge
yansigit 153e970
test(google): cover exact SSE cap and terminal CCA
yansigit f50f0b2
Fix CCA Claude prefill guard and pin flat-payload test contract
yansigit 2956980
fix(google): pair duplicate tool ids by occurrence and reject http CC…
yansigit f48a7e3
fix(google): keep one CCA tool exchange per raw id
yansigit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| const DAILY_ANTIGRAVITY_HOST = "https://daily-cloudcode-pa.googleapis.com"; | ||
| const PROD_ANTIGRAVITY_HOST = "https://cloudcode-pa.googleapis.com"; | ||
|
|
||
| /** | ||
| * Return the configured Antigravity endpoint and, for Google's known daily/prod hosts | ||
| * only, its daily/production peer. Custom baseUrl values stay single-host. | ||
| */ | ||
| export function antigravityHostCandidates(configuredBase: string): string[] { | ||
| const configured = configuredBase.replace(/\/+$/, ""); | ||
| if (configured === DAILY_ANTIGRAVITY_HOST) { | ||
| return [DAILY_ANTIGRAVITY_HOST, PROD_ANTIGRAVITY_HOST]; | ||
| } | ||
| if (configured === PROD_ANTIGRAVITY_HOST) { | ||
| return [PROD_ANTIGRAVITY_HOST, DAILY_ANTIGRAVITY_HOST]; | ||
| } | ||
| return [configured]; | ||
| } | ||
|
|
||
| /** OAuth bearer requests must not use a cleartext host, even if generic baseUrl config allows http. */ | ||
| export function isAntigravityHttpsHost(host: string): boolean { | ||
| try { | ||
| return new URL(host).protocol === "https:"; | ||
| } catch { | ||
| return false; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import type { | ||
| OcxAssistantMessage, | ||
| OcxMessage, | ||
| OcxToolCall, | ||
| OcxToolResultMessage, | ||
| } from "../types"; | ||
|
|
||
| function isAssistantToolCall(message: OcxMessage): message is OcxAssistantMessage { | ||
| return message.role === "assistant"; | ||
| } | ||
|
|
||
| function isToolResult(message: OcxMessage): message is OcxToolResultMessage { | ||
| return message.role === "toolResult"; | ||
| } | ||
|
|
||
| /** | ||
| * Repair incomplete tool exchanges before assigning provider-visible ids. | ||
| * | ||
| * CCA translates Gemini function calls and responses into Anthropic tool blocks, | ||
| * which requires both sides of every exchange. A result is valid only when its | ||
| * call appeared earlier in the history, and a call is valid only when a result | ||
| * appears later. Filtering the history first also prevents orphan results from | ||
| * reserving ids in the request-scoped allocator. | ||
| * | ||
| * The allocator maps one raw id to one wire id, so a second complete exchange | ||
| * that reuses the same raw id would serialize as a colliding pair. Keep only | ||
| * the first matched occurrence per raw id. | ||
| */ | ||
| export function repairGoogleToolPairs(messages: readonly OcxMessage[]): OcxMessage[] { | ||
| const pendingCalls = new Map<string, Array<{ messageIndex: number; partIndex: number }>>(); | ||
| const seenRawCallIds = new Set<string>(); | ||
| const matchedCallParts = new Set<string>(); | ||
| const matchedResultIndexes = new Set<number>(); | ||
|
|
||
| const enqueueCall = (id: string, messageIndex: number, partIndex: number) => { | ||
| if (seenRawCallIds.has(id)) return; | ||
| seenRawCallIds.add(id); | ||
| const queue = pendingCalls.get(id) ?? []; | ||
| queue.push({ messageIndex, partIndex }); | ||
| pendingCalls.set(id, queue); | ||
| }; | ||
|
|
||
| for (let messageIndex = 0; messageIndex < messages.length; messageIndex++) { | ||
| const message = messages[messageIndex]!; | ||
| if (isAssistantToolCall(message)) { | ||
| message.content.forEach((part, partIndex) => { | ||
| if (part.type !== "toolCall") return; | ||
| enqueueCall((part as OcxToolCall).id, messageIndex, partIndex); | ||
| }); | ||
| continue; | ||
| } | ||
| if (!isToolResult(message)) continue; | ||
| const queue = pendingCalls.get(message.toolCallId); | ||
| const slot = queue?.shift(); | ||
| if (!slot) continue; | ||
| matchedCallParts.add(`${slot.messageIndex}:${slot.partIndex}`); | ||
| matchedResultIndexes.add(messageIndex); | ||
| } | ||
|
|
||
| const repaired: OcxMessage[] = []; | ||
| for (const [messageIndex, message] of messages.entries()) { | ||
| if (isToolResult(message)) { | ||
| if (matchedResultIndexes.has(messageIndex)) repaired.push(message); | ||
| continue; | ||
| } | ||
| if (!isAssistantToolCall(message)) { | ||
| repaired.push(message); | ||
| continue; | ||
| } | ||
|
|
||
| const content = message.content.filter((part, partIndex) => | ||
| part.type !== "toolCall" || matchedCallParts.has(`${messageIndex}:${partIndex}`)); | ||
| if (content.length > 0) { | ||
| repaired.push(content.length === message.content.length ? message : { ...message, content }); | ||
| } | ||
| } | ||
| return repaired; | ||
| } | ||
|
|
||
| /** | ||
| * Claude interprets a final model turn as a prefilled assistant response. | ||
| * CCA expects the next turn to be generated instead, except when that model | ||
| * turn is the entire conversation and must remain as the initial context. | ||
| */ | ||
| export function stripTrailingClaudePrefill(contents: unknown[]): boolean { | ||
| let strippedModelTail = false; | ||
| while (contents.length >= 2) { | ||
| const last = contents[contents.length - 1]; | ||
| if (typeof last !== "object" || last === null || (last as { role?: unknown }).role !== "model") break; | ||
| contents.pop(); | ||
| strippedModelTail = true; | ||
| } | ||
| return strippedModelTail; | ||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.