dsh-antigravity-auth 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/lib/llm-adapter.js +257 -50
- package/lib/replay.js +2 -1
- package/lib/types/llm-adapter.d.ts.map +1 -1
- package/lib/types/replay.d.ts +1 -1
- package/lib/types/replay.d.ts.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.1.3] - 2026-08-31
|
|
6
|
+
|
|
7
|
+
- Restored reliable Claude Opus tool selection by preserving the complete DSH system prompt and applying the audited Claude tool instruction, strict parameter descriptions, and validated function-calling mode.
|
|
8
|
+
- Fixed Claude continuation after parallel tool execution by preserving call/response IDs, applying the safe thought-signature sentinel, dropping unsigned reasoning replay, and grouping correlated function responses.
|
|
9
|
+
- Mapped exact bounded Antigravity context-window overflow responses into DSH compaction recovery while retaining fail-closed parsing, timeout, response-size, frame-size, depth, and redaction limits.
|
|
10
|
+
|
|
5
11
|
## [0.1.2] - 2026-08-27
|
|
6
12
|
|
|
7
13
|
- Kept the Antigravity provider visible in DSH's stock model catalog during explicitly allowlisted transient live-discovery failures by falling back to the audited pinned text snapshot.
|
package/lib/llm-adapter.js
CHANGED
|
@@ -2,9 +2,9 @@ import { a as DEFAULT_PRIVATE_RESPONSE_HEADER_TIMEOUT_MS, d as privateStatusErro
|
|
|
2
2
|
import { ANTIGRAVITY_WIRE_ORIGIN } from "./wire-identity.js";
|
|
3
3
|
import { t as classifyPrivateFailure } from "./private-failure-B9vzUkQ7.js";
|
|
4
4
|
import { antigravityModelFamily, buildFunctionDeclarations, compatibleReplayState, createReplayState } from "./replay.js";
|
|
5
|
-
import { AgyRequestSessionStore, applyClaudeTransforms, applyGeminiTransforms, buildAgyAgentRequestMetadata, fnv1a64Signed, getPublicModelDefinitions, getResolverAliasMap, resolveModelWithTier } from "@cortexkit/antigravity-auth-core";
|
|
5
|
+
import { AgyRequestSessionStore, CLAUDE_DESCRIPTION_PROMPT, CLAUDE_TOOL_SYSTEM_INSTRUCTION, SKIP_THOUGHT_SIGNATURE, applyClaudeTransforms, applyGeminiTransforms, buildAgyAgentRequestMetadata, fnv1a64Signed, getPublicModelDefinitions, getResolverAliasMap, resolveModelWithTier } from "@cortexkit/antigravity-auth-core";
|
|
6
6
|
import { Buffer } from "node:buffer";
|
|
7
|
-
import { CallId, LlmAdapter, LlmError, ReasoningEffortId, resolveRetryPolicy } from "@deepseek-ai/dsh-llm";
|
|
7
|
+
import { CONTEXT_WINDOW_EXCEEDED_CODE, CallId, LlmAdapter, LlmError, ReasoningEffortId, resolveRetryPolicy } from "@deepseek-ai/dsh-llm";
|
|
8
8
|
//#region src/llm-adapter.ts
|
|
9
9
|
/** Public DSH LLM adapter for the single Antigravity provider route. */
|
|
10
10
|
const ANTIGRAVITY_PROVIDER = "google-antigravity";
|
|
@@ -14,6 +14,9 @@ const ANTIGRAVITY_AVAILABLE_MODELS_ENDPOINT = `${ANTIGRAVITY_WIRE_ORIGIN}/v1inte
|
|
|
14
14
|
const ANTIGRAVITY_LLM_ROUTE = ANTIGRAVITY_PROVIDER;
|
|
15
15
|
const MODEL_CATALOG_TTL_MS = 3e4;
|
|
16
16
|
const MAX_MODEL_CATALOG_BYTES = 262144;
|
|
17
|
+
const MAX_PROVIDER_ERROR_BYTES = 65536;
|
|
18
|
+
const MAX_PROVIDER_ERROR_FRAME_BYTES = 16384;
|
|
19
|
+
const MAX_PROVIDER_ERROR_JSON_DEPTH = 8;
|
|
17
20
|
const MAX_PROVIDER_PARTS = 4096;
|
|
18
21
|
/** Adapter that owns exactly one provider route and no fallback route. */
|
|
19
22
|
var AntigravityAdapter = class extends LlmAdapter {
|
|
@@ -157,6 +160,14 @@ var AntigravityAdapter = class extends LlmAdapter {
|
|
|
157
160
|
replayed = true;
|
|
158
161
|
continue;
|
|
159
162
|
}
|
|
163
|
+
if (response.status === 400 && await responseReportsContextWindowExceeded(response, {
|
|
164
|
+
...signal === void 0 ? {} : { signal },
|
|
165
|
+
idleTimeoutMs: this.options.idleTimeoutMs,
|
|
166
|
+
totalTimeoutMs: this.options.totalTimeoutMs,
|
|
167
|
+
maxResponseBytes: this.options.maxResponseBytes,
|
|
168
|
+
maxFrameBytes: this.options.maxFrameBytes
|
|
169
|
+
})) throw contextWindowExceededError(response.status);
|
|
170
|
+
await cancelResponse(response);
|
|
160
171
|
throw toLlmError(statusError);
|
|
161
172
|
}
|
|
162
173
|
try {
|
|
@@ -242,7 +253,7 @@ var AntigravityAdapter = class extends LlmAdapter {
|
|
|
242
253
|
usage
|
|
243
254
|
};
|
|
244
255
|
if (eventError !== void 0) {
|
|
245
|
-
yield finishChunk("error", safeProviderErrorCode(eventError.code), safeProviderStatus(eventError.status));
|
|
256
|
+
yield finishChunk("error", eventError.contextWindowExceeded === true ? CONTEXT_WINDOW_EXCEEDED_CODE : safeProviderErrorCode(eventError.code), safeProviderStatus(eventError.status));
|
|
246
257
|
return;
|
|
247
258
|
}
|
|
248
259
|
if (isAborted(options.signal)) {
|
|
@@ -549,10 +560,35 @@ async function buildAntigravityGeneratePayloadForAdapter(options, credential, se
|
|
|
549
560
|
requestType: "agent"
|
|
550
561
|
};
|
|
551
562
|
}
|
|
563
|
+
function groupClaudeFunctionResponses(contents, model) {
|
|
564
|
+
if (antigravityModelFamily(model) !== "claude") return contents;
|
|
565
|
+
const grouped = [];
|
|
566
|
+
let pendingResponses = [];
|
|
567
|
+
const flushResponses = () => {
|
|
568
|
+
if (pendingResponses.length === 0) return;
|
|
569
|
+
grouped.push({
|
|
570
|
+
role: "user",
|
|
571
|
+
parts: pendingResponses
|
|
572
|
+
});
|
|
573
|
+
pendingResponses = [];
|
|
574
|
+
};
|
|
575
|
+
for (const content of contents) {
|
|
576
|
+
const rawParts = Array.isArray(content.parts) ? content.parts : [];
|
|
577
|
+
const responseParts = rawParts.filter((part) => isRecord(part) && isRecord(part.functionResponse));
|
|
578
|
+
if (content.role === "user" && rawParts.length > 0 && responseParts.length === rawParts.length) {
|
|
579
|
+
pendingResponses.push(...responseParts);
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
flushResponses();
|
|
583
|
+
grouped.push(content);
|
|
584
|
+
}
|
|
585
|
+
flushResponses();
|
|
586
|
+
return grouped;
|
|
587
|
+
}
|
|
552
588
|
function buildPayloadFromContents(options, credential, contents) {
|
|
553
589
|
const wireModel = resolveWireModel(options.model);
|
|
554
|
-
const request = { contents };
|
|
555
|
-
if (options.system !== void 0 && options.system.trim().length > 0) request.systemInstruction = { parts: [{ text: options.system
|
|
590
|
+
const request = { contents: groupClaudeFunctionResponses(contents, options.model) };
|
|
591
|
+
if (options.system !== void 0 && options.system.trim().length > 0) request.systemInstruction = { parts: [{ text: options.system }] };
|
|
556
592
|
const generationConfig = {};
|
|
557
593
|
if (options.maxTokens !== void 0) generationConfig.maxOutputTokens = boundedInteger(options.maxTokens, 1, 1e6, "maxTokens");
|
|
558
594
|
if (options.temperature !== void 0) generationConfig.temperature = boundedNumber(options.temperature, -100, 100, "temperature");
|
|
@@ -565,19 +601,21 @@ function buildPayloadFromContents(options, credential, contents) {
|
|
|
565
601
|
}
|
|
566
602
|
const resolved = resolveModelWithTier(options.model, { cli_first: false });
|
|
567
603
|
const thinkingLevel = normalizeReasoningEffort(options.reasoningEffort) ?? resolved.thinkingLevel;
|
|
568
|
-
if (wireModel.toLowerCase().includes("claude"))
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
...resolved.thinkingBudget === void 0 ? {} : {
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
604
|
+
if (wireModel.toLowerCase().includes("claude")) {
|
|
605
|
+
applyClaudeToolHardening(request);
|
|
606
|
+
applyClaudeTransforms(request, {
|
|
607
|
+
model: wireModel,
|
|
608
|
+
...resolved.thinkingBudget === void 0 ? {} : { tierThinkingBudget: resolved.thinkingBudget },
|
|
609
|
+
...options.reasoningEffort === void 0 && resolved.thinkingBudget === void 0 ? {} : { normalizedThinking: {
|
|
610
|
+
includeThoughts: true,
|
|
611
|
+
...resolved.thinkingBudget === void 0 ? {} : { thinkingBudget: resolved.thinkingBudget }
|
|
612
|
+
} },
|
|
613
|
+
cleanJSONSchema: (value) => isRecord(value) ? value : {
|
|
614
|
+
type: "object",
|
|
615
|
+
properties: {}
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
} else applyGeminiTransforms(request, {
|
|
581
619
|
model: wireModel,
|
|
582
620
|
...thinkingLevel === void 0 ? {} : { tierThinkingLevel: thinkingLevel },
|
|
583
621
|
...resolved.thinkingBudget === void 0 ? {} : { tierThinkingBudget: resolved.thinkingBudget },
|
|
@@ -593,37 +631,115 @@ function buildPayloadFromContents(options, credential, contents) {
|
|
|
593
631
|
request
|
|
594
632
|
};
|
|
595
633
|
}
|
|
634
|
+
function applyClaudeToolHardening(request) {
|
|
635
|
+
if (!Array.isArray(request.tools) || request.tools.length === 0) return;
|
|
636
|
+
request.tools = request.tools.map((tool) => {
|
|
637
|
+
if (!isRecord(tool) || !Array.isArray(tool.functionDeclarations)) return tool;
|
|
638
|
+
return {
|
|
639
|
+
...tool,
|
|
640
|
+
functionDeclarations: tool.functionDeclarations.map((declaration) => hardenClaudeToolDeclaration(declaration))
|
|
641
|
+
};
|
|
642
|
+
});
|
|
643
|
+
const instructionPart = { text: CLAUDE_TOOL_SYSTEM_INSTRUCTION };
|
|
644
|
+
const existing = request.systemInstruction;
|
|
645
|
+
if (isRecord(existing) && Array.isArray(existing.parts)) {
|
|
646
|
+
if (existing.parts.some((part) => isRecord(part) && typeof part.text === "string" && part.text.includes("CRITICAL TOOL USAGE INSTRUCTIONS"))) return;
|
|
647
|
+
request.systemInstruction = {
|
|
648
|
+
...existing,
|
|
649
|
+
parts: [...existing.parts, instructionPart]
|
|
650
|
+
};
|
|
651
|
+
} else if (typeof existing === "string") request.systemInstruction = {
|
|
652
|
+
role: "user",
|
|
653
|
+
parts: [{ text: existing }, instructionPart]
|
|
654
|
+
};
|
|
655
|
+
else request.systemInstruction = {
|
|
656
|
+
role: "user",
|
|
657
|
+
parts: [instructionPart]
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
function hardenClaudeToolDeclaration(value) {
|
|
661
|
+
if (!isRecord(value)) return value;
|
|
662
|
+
const description = typeof value.description === "string" ? value.description : "";
|
|
663
|
+
if (description.includes("STRICT PARAMETERS:")) return value;
|
|
664
|
+
const schema = isRecord(value.parameters) ? value.parameters : void 0;
|
|
665
|
+
const properties = schema !== void 0 && isRecord(schema.properties) ? schema.properties : void 0;
|
|
666
|
+
if (properties === void 0 || Object.keys(properties).length === 0) return value;
|
|
667
|
+
const required = new Set(Array.isArray(schema?.required) ? schema.required.filter((item) => typeof item === "string") : []);
|
|
668
|
+
const parameters = Object.entries(properties).map(([name, property]) => {
|
|
669
|
+
const requiredHint = required.has(name) ? ", REQUIRED" : "";
|
|
670
|
+
return `${name} (${claudeToolTypeHint(property)}${requiredHint})`;
|
|
671
|
+
});
|
|
672
|
+
return {
|
|
673
|
+
...value,
|
|
674
|
+
description: description + CLAUDE_DESCRIPTION_PROMPT.replace("{params}", parameters.join(", "))
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
function claudeToolTypeHint(value) {
|
|
678
|
+
if (!isRecord(value)) return "unknown";
|
|
679
|
+
if (Array.isArray(value.enum)) return value.enum.length <= 5 ? `string ENUM[${value.enum.map((item) => JSON.stringify(item)).join(", ")}]` : `string ENUM[${value.enum.length} options]`;
|
|
680
|
+
const type = typeof value.type === "string" ? value.type : "unknown";
|
|
681
|
+
if (type === "array") {
|
|
682
|
+
if (!isRecord(value.items)) return "ARRAY";
|
|
683
|
+
const itemType = typeof value.items.type === "string" ? value.items.type : "unknown";
|
|
684
|
+
if (itemType !== "object") return `ARRAY_OF_${itemType.toUpperCase()}`;
|
|
685
|
+
if (!isRecord(value.items.properties)) return "ARRAY_OF_OBJECTS";
|
|
686
|
+
const nestedRequired = new Set(Array.isArray(value.items.required) ? value.items.required.filter((item) => typeof item === "string") : []);
|
|
687
|
+
return `ARRAY_OF_OBJECTS[${Object.entries(value.items.properties).map(([name, property]) => {
|
|
688
|
+
return `${name}: ${isRecord(property) && typeof property.type === "string" ? property.type : "unknown"}${nestedRequired.has(name) ? " REQUIRED" : ""}`;
|
|
689
|
+
}).join(", ")}]`;
|
|
690
|
+
}
|
|
691
|
+
if (type === "object" && isRecord(value.properties)) {
|
|
692
|
+
const nestedRequired = new Set(Array.isArray(value.required) ? value.required.filter((item) => typeof item === "string") : []);
|
|
693
|
+
return `object{${Object.entries(value.properties).map(([name, property]) => {
|
|
694
|
+
return `${name}: ${isRecord(property) && typeof property.type === "string" ? property.type : "unknown"}${nestedRequired.has(name) ? " REQUIRED" : ""}`;
|
|
695
|
+
}).join(", ")}}`;
|
|
696
|
+
}
|
|
697
|
+
return type;
|
|
698
|
+
}
|
|
596
699
|
function mapMessage(message, model, toolNames) {
|
|
597
700
|
const parts = [];
|
|
598
701
|
const replayBlocks = compatibleReplayState(message, "google-antigravity", model, contentKinds(message))?.blocks ?? [];
|
|
702
|
+
const isClaude = antigravityModelFamily(model) === "claude";
|
|
703
|
+
let replayIndex = 0;
|
|
704
|
+
let sawClaudeFunctionCall = false;
|
|
599
705
|
for (const block of message.content) {
|
|
600
|
-
const
|
|
601
|
-
const
|
|
706
|
+
const replayKind = block.type === "text" || block.type === "reasoning" || block.type === "tool-call" ? block.type : void 0;
|
|
707
|
+
const replayBlock = replayKind === void 0 ? void 0 : replayBlocks[replayIndex++];
|
|
708
|
+
const replaySignature = replayBlock !== void 0 && replayBlock.kind === replayKind ? replayBlock.signature : void 0;
|
|
709
|
+
const blockSignature = block.signature ?? block.thoughtSignature ?? replaySignature;
|
|
602
710
|
if (block.type === "text") {
|
|
603
711
|
if (block.text.length === 0 && message.content.length > 1) continue;
|
|
604
712
|
parts.push({
|
|
605
713
|
text: block.text,
|
|
606
714
|
...blockSignature === void 0 ? {} : { thoughtSignature: blockSignature }
|
|
607
715
|
});
|
|
608
|
-
} else if (block.type === "reasoning")
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
716
|
+
} else if (block.type === "reasoning") {
|
|
717
|
+
if (isClaude && blockSignature === void 0) continue;
|
|
718
|
+
parts.push({
|
|
719
|
+
text: block.text,
|
|
720
|
+
thought: true,
|
|
721
|
+
...blockSignature === void 0 ? {} : { thoughtSignature: blockSignature }
|
|
722
|
+
});
|
|
723
|
+
} else if (block.type === "tool-call") {
|
|
724
|
+
const callId = rememberToolName(toolNames, block.id, block.name);
|
|
725
|
+
const signature = isClaude ? sawClaudeFunctionCall ? void 0 : blockSignature ?? SKIP_THOUGHT_SIGNATURE : blockSignature;
|
|
726
|
+
sawClaudeFunctionCall ||= isClaude;
|
|
615
727
|
parts.push({
|
|
616
728
|
functionCall: {
|
|
729
|
+
...isClaude ? { id: callId } : {},
|
|
617
730
|
name: block.name,
|
|
618
731
|
args: parseJsonObject(block.arguments)
|
|
619
732
|
},
|
|
620
|
-
...
|
|
733
|
+
...signature === void 0 ? {} : { thoughtSignature: signature }
|
|
621
734
|
});
|
|
622
|
-
} else if (block.type === "tool-result")
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
735
|
+
} else if (block.type === "tool-result") {
|
|
736
|
+
const callId = requireToolCallId(block.toolCallId);
|
|
737
|
+
parts.push({ functionResponse: {
|
|
738
|
+
...isClaude ? { id: callId } : {},
|
|
739
|
+
name: requireToolName(toolNames, callId),
|
|
740
|
+
response: { content: blocksToText(block.content) }
|
|
741
|
+
} });
|
|
742
|
+
} else if (block.type === "image") throw new LlmError("Antigravity text requests do not accept unresolved image blocks", "UNSUPPORTED_MODALITY");
|
|
627
743
|
}
|
|
628
744
|
return {
|
|
629
745
|
role: message.role === "assistant" ? "model" : "user",
|
|
@@ -635,9 +751,14 @@ async function mapMessageWithAttachments(message, model, toolNames, attachments,
|
|
|
635
751
|
if (attachments === void 0) throw new LlmError("Antigravity image input requires the Host AttachmentStore", "UNSUPPORTED_MODALITY");
|
|
636
752
|
const replayBlocks = compatibleReplayState(message, "google-antigravity", model, contentKinds(message))?.blocks ?? [];
|
|
637
753
|
const parts = [];
|
|
754
|
+
const isClaude = antigravityModelFamily(model) === "claude";
|
|
755
|
+
let replayIndex = 0;
|
|
756
|
+
let sawClaudeFunctionCall = false;
|
|
638
757
|
for (const block of message.content) {
|
|
639
|
-
const
|
|
640
|
-
const
|
|
758
|
+
const replayKind = block.type === "text" || block.type === "reasoning" || block.type === "tool-call" ? block.type : void 0;
|
|
759
|
+
const replayBlock = replayKind === void 0 ? void 0 : replayBlocks[replayIndex++];
|
|
760
|
+
const replaySignature = replayBlock !== void 0 && replayBlock.kind === replayKind ? replayBlock.signature : void 0;
|
|
761
|
+
const blockSignature = block.signature ?? block.thoughtSignature ?? replaySignature;
|
|
641
762
|
if (block.type === "image") {
|
|
642
763
|
const stored = await attachments.readImage(block.attachment, signal);
|
|
643
764
|
parts.push({ inlineData: {
|
|
@@ -650,24 +771,33 @@ async function mapMessageWithAttachments(message, model, toolNames, attachments,
|
|
|
650
771
|
text: block.text,
|
|
651
772
|
...blockSignature === void 0 ? {} : { thoughtSignature: blockSignature }
|
|
652
773
|
});
|
|
653
|
-
} else if (block.type === "reasoning")
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
774
|
+
} else if (block.type === "reasoning") {
|
|
775
|
+
if (isClaude && blockSignature === void 0) continue;
|
|
776
|
+
parts.push({
|
|
777
|
+
text: block.text,
|
|
778
|
+
thought: true,
|
|
779
|
+
...blockSignature === void 0 ? {} : { thoughtSignature: blockSignature }
|
|
780
|
+
});
|
|
781
|
+
} else if (block.type === "tool-call") {
|
|
782
|
+
const callId = rememberToolName(toolNames, block.id, block.name);
|
|
783
|
+
const signature = isClaude ? sawClaudeFunctionCall ? void 0 : blockSignature ?? SKIP_THOUGHT_SIGNATURE : blockSignature;
|
|
784
|
+
sawClaudeFunctionCall ||= isClaude;
|
|
660
785
|
parts.push({
|
|
661
786
|
functionCall: {
|
|
787
|
+
...isClaude ? { id: callId } : {},
|
|
662
788
|
name: block.name,
|
|
663
789
|
args: parseJsonObject(block.arguments)
|
|
664
790
|
},
|
|
665
|
-
...
|
|
791
|
+
...signature === void 0 ? {} : { thoughtSignature: signature }
|
|
666
792
|
});
|
|
667
|
-
} else if (block.type === "tool-result")
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
793
|
+
} else if (block.type === "tool-result") {
|
|
794
|
+
const callId = requireToolCallId(block.toolCallId);
|
|
795
|
+
parts.push({ functionResponse: {
|
|
796
|
+
...isClaude ? { id: callId } : {},
|
|
797
|
+
name: requireToolName(toolNames, callId),
|
|
798
|
+
response: { content: blocksToText(block.content) }
|
|
799
|
+
} });
|
|
800
|
+
}
|
|
671
801
|
}
|
|
672
802
|
return {
|
|
673
803
|
role: message.role === "assistant" ? "model" : "user",
|
|
@@ -676,16 +806,21 @@ async function mapMessageWithAttachments(message, model, toolNames, attachments,
|
|
|
676
806
|
}
|
|
677
807
|
function rememberToolName(toolNames, callId, name) {
|
|
678
808
|
if (name.length === 0 || name.length > 256 || containsControl(name)) throw new LlmError("The tool call name is invalid", "INVALID_ARGS");
|
|
679
|
-
const id =
|
|
809
|
+
const id = requireToolCallId(callId);
|
|
680
810
|
const existing = toolNames.get(id);
|
|
681
811
|
if (existing !== void 0 && existing !== name) throw new LlmError("A tool call id was reused with a different name", "INVALID_ARGS");
|
|
682
812
|
toolNames.set(id, name);
|
|
813
|
+
return id;
|
|
683
814
|
}
|
|
684
815
|
function requireToolName(toolNames, callId) {
|
|
685
|
-
const name = toolNames.get(
|
|
816
|
+
const name = toolNames.get(requireToolCallId(callId));
|
|
686
817
|
if (name === void 0) throw new LlmError("A tool result did not match a prior tool call", "INVALID_ARGS");
|
|
687
818
|
return name;
|
|
688
819
|
}
|
|
820
|
+
function requireToolCallId(value) {
|
|
821
|
+
if (typeof value !== "string" || value.length === 0 || value.length > 512 || containsControl(value)) throw new LlmError("The tool call id is invalid", "INVALID_ARGS");
|
|
822
|
+
return value;
|
|
823
|
+
}
|
|
689
824
|
function normalizeReasoningEffort(value) {
|
|
690
825
|
if (value === void 0) return void 0;
|
|
691
826
|
const normalized = String(value).toLowerCase();
|
|
@@ -794,11 +929,83 @@ function parsePart(value) {
|
|
|
794
929
|
function errorDetails(value) {
|
|
795
930
|
const status = numberValue(value.status);
|
|
796
931
|
const code = stringValue(value.code);
|
|
932
|
+
const contextWindowExceeded = providerErrorReportsContextWindowExceeded(value, 0);
|
|
797
933
|
return {
|
|
798
934
|
...status === void 0 ? {} : { status },
|
|
799
|
-
...code === void 0 ? {} : { code }
|
|
935
|
+
...code === void 0 ? {} : { code },
|
|
936
|
+
...contextWindowExceeded ? { contextWindowExceeded: true } : {}
|
|
800
937
|
};
|
|
801
938
|
}
|
|
939
|
+
async function responseReportsContextWindowExceeded(response, options) {
|
|
940
|
+
try {
|
|
941
|
+
for await (const event of iteratePrivateSse(response, {
|
|
942
|
+
...options.signal === void 0 ? {} : { signal: options.signal },
|
|
943
|
+
idleTimeoutMs: options.idleTimeoutMs,
|
|
944
|
+
totalTimeoutMs: options.totalTimeoutMs,
|
|
945
|
+
maxBytes: Math.min(MAX_PROVIDER_ERROR_BYTES, options.maxResponseBytes),
|
|
946
|
+
maxFrameBytes: Math.min(MAX_PROVIDER_ERROR_FRAME_BYTES, options.maxFrameBytes)
|
|
947
|
+
})) if (providerErrorEnvelopeReportsContextWindowExceeded(event.data.replace(/^\)\]\}'(?:\r?\n)?/u, ""), 0)) return true;
|
|
948
|
+
return false;
|
|
949
|
+
} catch (error) {
|
|
950
|
+
if (error instanceof PrivateTransportError && error.code === "cancelled") throw toLlmError(error);
|
|
951
|
+
if (isAborted(options.signal)) throw new LlmError("The Antigravity request was cancelled", "CANCELLED");
|
|
952
|
+
return false;
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
function providerErrorReportsContextWindowExceeded(value, depth) {
|
|
956
|
+
if (depth > MAX_PROVIDER_ERROR_JSON_DEPTH) return false;
|
|
957
|
+
if (typeof value.message === "string") {
|
|
958
|
+
if (isExactContextWindowExceededMessage(value.message)) return true;
|
|
959
|
+
if (providerErrorEnvelopeReportsContextWindowExceeded(value.message, depth + 1)) return true;
|
|
960
|
+
}
|
|
961
|
+
return isRecord(value.error) && providerErrorReportsContextWindowExceeded(value.error, depth + 1);
|
|
962
|
+
}
|
|
963
|
+
function providerErrorEnvelopeReportsContextWindowExceeded(value, depth) {
|
|
964
|
+
if (depth > MAX_PROVIDER_ERROR_JSON_DEPTH || value.length === 0 || value.length > MAX_PROVIDER_ERROR_BYTES) return false;
|
|
965
|
+
const json = value.trim();
|
|
966
|
+
if (!json.startsWith("{") || !jsonDepthIsBounded(json, MAX_PROVIDER_ERROR_JSON_DEPTH)) return false;
|
|
967
|
+
try {
|
|
968
|
+
const parsed = JSON.parse(json);
|
|
969
|
+
return isRecord(parsed) && isRecord(parsed.error) ? providerErrorReportsContextWindowExceeded(parsed.error, depth + 1) : false;
|
|
970
|
+
} catch {
|
|
971
|
+
return false;
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
function isExactContextWindowExceededMessage(value) {
|
|
975
|
+
const match = /^prompt is too long: ([0-9]{1,16}) tokens > ([0-9]{1,16}) maximum$/u.exec(value);
|
|
976
|
+
const actual = match?.[1];
|
|
977
|
+
const maximum = match?.[2];
|
|
978
|
+
return actual !== void 0 && maximum !== void 0 && BigInt(actual) > BigInt(maximum);
|
|
979
|
+
}
|
|
980
|
+
function jsonDepthIsBounded(value, maxDepth) {
|
|
981
|
+
let depth = 0;
|
|
982
|
+
let inString = false;
|
|
983
|
+
let escaped = false;
|
|
984
|
+
for (const character of value) {
|
|
985
|
+
if (inString) {
|
|
986
|
+
if (escaped) escaped = false;
|
|
987
|
+
else if (character === "\\") escaped = true;
|
|
988
|
+
else if (character === "\"") inString = false;
|
|
989
|
+
continue;
|
|
990
|
+
}
|
|
991
|
+
if (character === "\"") {
|
|
992
|
+
inString = true;
|
|
993
|
+
continue;
|
|
994
|
+
}
|
|
995
|
+
if (character === "{" || character === "[") {
|
|
996
|
+
depth += 1;
|
|
997
|
+
if (depth > maxDepth) return false;
|
|
998
|
+
} else if (character === "}" || character === "]") {
|
|
999
|
+
depth -= 1;
|
|
1000
|
+
if (depth < 0) return false;
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
return depth === 0 && !inString && !escaped;
|
|
1004
|
+
}
|
|
1005
|
+
function contextWindowExceededError(status) {
|
|
1006
|
+
const message = "The Antigravity request exceeded the model context window";
|
|
1007
|
+
return status === void 0 ? new LlmError(message, CONTEXT_WINDOW_EXCEEDED_CODE) : new LlmError(message, CONTEXT_WINDOW_EXCEEDED_CODE, { status });
|
|
1008
|
+
}
|
|
802
1009
|
function parseUsage(value) {
|
|
803
1010
|
if (!isRecord(value)) return void 0;
|
|
804
1011
|
const input = numberValue(value.promptTokenCount ?? value.inputTokenCount);
|
package/lib/replay.js
CHANGED
|
@@ -24,7 +24,7 @@ function createReplayState(model, family, finish, blocks) {
|
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
/** Validate replay metadata before it can affect a later private request. */
|
|
27
|
-
function compatibleReplayState(message, provider, model,
|
|
27
|
+
function compatibleReplayState(message, provider, model, blockKinds) {
|
|
28
28
|
if (provider !== "google-antigravity" || message.role !== "assistant") return void 0;
|
|
29
29
|
const provenance = isRecord(message.source) ? message.source : void 0;
|
|
30
30
|
if (provenance !== void 0 && provenance.kind === "model" && (provenance.provider !== provider || provenance.model !== model)) return void 0;
|
|
@@ -42,6 +42,7 @@ function compatibleReplayState(message, provider, model, _blockKinds) {
|
|
|
42
42
|
...signature === void 0 ? {} : { signature }
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
+
if (blockKinds !== void 0 && (blocks.length !== blockKinds.length || blocks.some((block, index) => block.kind !== blockKinds[index]))) return void 0;
|
|
45
46
|
const finish = value.response.finish === void 0 ? void 0 : safeFinish(value.response.finish);
|
|
46
47
|
if (value.response.finish !== void 0 && finish === void 0) return void 0;
|
|
47
48
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llm-adapter.d.ts","sourceRoot":"","sources":["../../src/llm-adapter.ts"],"names":[],"mappings":"AAAA,wEAAwE;
|
|
1
|
+
{"version":3,"file":"llm-adapter.d.ts","sourceRoot":"","sources":["../../src/llm-adapter.ts"],"names":[],"mappings":"AAAA,wEAAwE;AAgBxE,OAAO,EAGL,UAAU,EAGV,kBAAkB,EACnB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,KAAK,EAEV,eAAe,EACf,YAAY,EACZ,eAAe,EACf,oBAAoB,EAGpB,WAAW,EAEZ,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AACxF,OAAO,EAWL,KAAK,gBAAgB,EACtB,MAAM,wBAAwB,CAAA;AAU/B,OAAO,KAAK,EAAgC,2BAA2B,EAAE,MAAM,oBAAoB,CAAA;AAEnG,eAAO,MAAM,oBAAoB,EAAG,oBAA6B,CAAA;AACjE,eAAO,MAAM,2BAA2B,sDAAiF,CAAA;AACzH,eAAO,MAAM,6BAA6B,wCAAmE,CAAA;AAC7G,eAAO,MAAM,qCAAqC,6CAAwE,CAAA;AAC1H,eAAO,MAAM,qBAAqB,sBAAuB,CAAA;AAQzD,MAAM,WAAW,+BAA+B;IAC9C,UAAU,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE;QAAE,Q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AoB;IAC3C,OAAO,CAAC,kBAAkB,CAAoB;IAC9C,OAAO,CAAC,WAAW,CAA6B;gBAEnB,cAAc,EAAE,yBAAyB;IAe7D,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe;IAK/C,mBAAmB,IAAI,UAAU,CAAC,OAAO,kBAAkB,CAAC;IAMrE,mFAAmF;IACnF,sBAAsB,IAAI,IAAI;IAQ9B,+EAA+E;IAC/E,eAAe,IAAI,2BAA2B;IAI9C,kFAAkF;IAC5E,YAAY,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,YAAY,UAAQ,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAWrF,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,YAAY,EAAE,CAAC;IAkBnG,OAAO,CAAC,oBAAoB;IAWb,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAqBlG,MAAM,CAAC,OAAO,EAAE,eAAe,GAAG,aAAa,CAAC,WAAW,CAAC;YAyE7D,cAAc;YAsFf,gBAAgB;IA0F9B,OAAO,CAAC,sBAAsB;YAQhB,cAAc;CAO7B;AA8MD,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAM7H"}
|
package/lib/types/replay.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export interface AntigravityReplayState extends ReplayEnvelope {
|
|
|
21
21
|
/** Keep only provider-issued signatures and bounded response facts. */
|
|
22
22
|
export declare function createReplayState(model: string, family: AntigravityReplayResponse['family'], finish: string | undefined, blocks: readonly AntigravityReplayBlock[]): AntigravityReplayState;
|
|
23
23
|
/** Validate replay metadata before it can affect a later private request. */
|
|
24
|
-
export declare function compatibleReplayState(message: Message, provider: string, model: string,
|
|
24
|
+
export declare function compatibleReplayState(message: Message, provider: string, model: string, blockKinds?: readonly ReplayBlockKind[]): AntigravityReplayState | undefined;
|
|
25
25
|
/** Return the block family without allowing a model alias to cross families. */
|
|
26
26
|
export declare function antigravityModelFamily(model: string): AntigravityReplayResponse['family'];
|
|
27
27
|
/** Convert DSH schemas to the small function-declaration subset accepted privately. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../../src/replay.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAE1E,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAEnD,eAAO,MAAM,0BAA0B,EAAG,CAAU,CAAA;AAIpD,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,WAAW,GAAG,WAAW,CAAA;AAEhE,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAA;IAC9B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,OAAO,EAAE,OAAO,0BAA0B,CAAA;IACnD,QAAQ,CAAC,QAAQ,EAAE,oBAAoB,CAAA;IACvC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAA;IAC5D,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CACzB;AAED,MAAM,WAAW,sBAAuB,SAAQ,cAAc;IAC5D,QAAQ,CAAC,QAAQ,EAAE,yBAAyB,CAAA;IAC5C,QAAQ,CAAC,MAAM,EAAE,SAAS,sBAAsB,EAAE,CAAA;CACnD;AAED,uEAAuE;AACvE,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,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