-
Notifications
You must be signed in to change notification settings - Fork 867
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
Closed
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1122f6e
feat(antigravity): live quota RPC and geoblock classification
yansigit 893dea8
fix(antigravity): harden quota interpretation and catalog fetch
yansigit 11685a5
fix(antigravity): preserve usable quota when summary fails
yansigit 21c601f
test(antigravity): assert quota RPC redirect policy
yansigit 5279149
fix(antigravity): stop quota probe on terminal RPC errors
yansigit 54c4f6a
fix(antigravity): drop last-good quota on terminal RPC and classify w…
yansigit 1948855
feat(antigravity): Claude CCA wire fidelity
yansigit bd80874
fix(google): retain CCA events and cap SSE frames correctly
yansigit dcb54d5
fix(google): count raw SSE line bytes across UTF-8 chunk splits
yansigit 79cb47c
test(google): account for Claude continuation nudge
yansigit 5f1aeba
test(google): cover exact SSE cap and terminal CCA
yansigit ae0a85d
Fix CCA Claude prefill guard and pin flat-payload test contract
yansigit 6673546
fix(google): pair duplicate tool ids by occurrence and reject http CC…
yansigit 5c4b278
fix(google): keep one CCA tool exchange per raw id
yansigit 66a1a5c
fix(google): keep unmatched AI Studio tool calls
yansigit f276d32
fix(google): reconcile CCA rebase onto quota-geoblock parent
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,105 @@ | ||
| 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. | ||
| * | ||
| * Direct Gemini and Vertex accept an unmatched trailing `functionCall`, so | ||
| * `dropUnmatchedCalls` is CCA-only. Orphan results are still dropped in every | ||
| * Google mode so they cannot reserve allocator slots or emit a lone | ||
| * `functionResponse`. | ||
| */ | ||
| export function repairGoogleToolPairs( | ||
| messages: readonly OcxMessage[], | ||
| opts: { dropUnmatchedCalls?: boolean } = {}, | ||
| ): OcxMessage[] { | ||
| const dropUnmatchedCalls = opts.dropUnmatchedCalls ?? true; | ||
| 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}`) | ||
| || !dropUnmatchedCalls); | ||
| 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.