antigravity-auth 1.6.0 → 1.7.0
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/README.md +79 -41
- package/dist/cli.js +2868 -0
- package/dist/handler.js +25119 -0
- package/dist/index.js +25110 -5
- package/package.json +66 -54
- package/dist/antigravity/oauth.d.ts +0 -30
- package/dist/antigravity/oauth.js +0 -170
- package/dist/claude/login.d.ts +0 -7
- package/dist/claude/login.js +0 -480
- package/dist/claude/menu-helpers.d.ts +0 -22
- package/dist/claude/menu-helpers.js +0 -281
- package/dist/claude/proxy-manager.d.ts +0 -11
- package/dist/claude/proxy-manager.js +0 -129
- package/dist/claude/proxy.d.ts +0 -1
- package/dist/claude/proxy.js +0 -733
- package/dist/constants.d.ts +0 -138
- package/dist/constants.js +0 -216
- package/dist/hooks/auto-update-checker/cache.d.ts +0 -2
- package/dist/hooks/auto-update-checker/cache.js +0 -70
- package/dist/hooks/auto-update-checker/checker.d.ts +0 -15
- package/dist/hooks/auto-update-checker/checker.js +0 -233
- package/dist/hooks/auto-update-checker/constants.d.ts +0 -8
- package/dist/hooks/auto-update-checker/constants.js +0 -22
- package/dist/hooks/auto-update-checker/index.d.ts +0 -33
- package/dist/hooks/auto-update-checker/index.js +0 -121
- package/dist/hooks/auto-update-checker/logging.d.ts +0 -2
- package/dist/hooks/auto-update-checker/logging.js +0 -8
- package/dist/hooks/auto-update-checker/types.d.ts +0 -24
- package/dist/hooks/auto-update-checker/types.js +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/opencode/hooks/auto-update-checker/cache.d.ts +0 -2
- package/dist/opencode/hooks/auto-update-checker/cache.js +0 -70
- package/dist/opencode/hooks/auto-update-checker/checker.d.ts +0 -15
- package/dist/opencode/hooks/auto-update-checker/checker.js +0 -233
- package/dist/opencode/hooks/auto-update-checker/constants.d.ts +0 -8
- package/dist/opencode/hooks/auto-update-checker/constants.js +0 -22
- package/dist/opencode/hooks/auto-update-checker/index.d.ts +0 -33
- package/dist/opencode/hooks/auto-update-checker/index.js +0 -121
- package/dist/opencode/hooks/auto-update-checker/logging.d.ts +0 -2
- package/dist/opencode/hooks/auto-update-checker/logging.js +0 -8
- package/dist/opencode/hooks/auto-update-checker/types.d.ts +0 -24
- package/dist/opencode/hooks/auto-update-checker/types.js +0 -1
- package/dist/opencode/plugin.d.ts +0 -29
- package/dist/opencode/plugin.js +0 -2954
- package/dist/plugin/accounts.d.ts +0 -173
- package/dist/plugin/accounts.js +0 -966
- package/dist/plugin/auth.d.ts +0 -20
- package/dist/plugin/auth.js +0 -44
- package/dist/plugin/cache/index.d.ts +0 -4
- package/dist/plugin/cache/index.js +0 -4
- package/dist/plugin/cache/signature-cache.d.ts +0 -110
- package/dist/plugin/cache/signature-cache.js +0 -347
- package/dist/plugin/cache.d.ts +0 -43
- package/dist/plugin/cache.js +0 -180
- package/dist/plugin/cli.d.ts +0 -26
- package/dist/plugin/cli.js +0 -126
- package/dist/plugin/config/index.d.ts +0 -15
- package/dist/plugin/config/index.js +0 -15
- package/dist/plugin/config/loader.d.ts +0 -38
- package/dist/plugin/config/loader.js +0 -150
- package/dist/plugin/config/models.d.ts +0 -26
- package/dist/plugin/config/models.js +0 -95
- package/dist/plugin/config/schema.d.ts +0 -144
- package/dist/plugin/config/schema.js +0 -458
- package/dist/plugin/config/updater.d.ts +0 -76
- package/dist/plugin/config/updater.js +0 -205
- package/dist/plugin/core/streaming/index.d.ts +0 -2
- package/dist/plugin/core/streaming/index.js +0 -2
- package/dist/plugin/core/streaming/transformer.d.ts +0 -9
- package/dist/plugin/core/streaming/transformer.js +0 -301
- package/dist/plugin/core/streaming/types.d.ts +0 -28
- package/dist/plugin/core/streaming/types.js +0 -1
- package/dist/plugin/debug.d.ts +0 -93
- package/dist/plugin/debug.js +0 -375
- package/dist/plugin/errors.d.ts +0 -27
- package/dist/plugin/errors.js +0 -41
- package/dist/plugin/fingerprint.d.ts +0 -69
- package/dist/plugin/fingerprint.js +0 -137
- package/dist/plugin/image-saver.d.ts +0 -24
- package/dist/plugin/image-saver.js +0 -78
- package/dist/plugin/logger.d.ts +0 -35
- package/dist/plugin/logger.js +0 -67
- package/dist/plugin/logging-utils.d.ts +0 -22
- package/dist/plugin/logging-utils.js +0 -91
- package/dist/plugin/project.d.ts +0 -32
- package/dist/plugin/project.js +0 -229
- package/dist/plugin/quota.d.ts +0 -34
- package/dist/plugin/quota.js +0 -261
- package/dist/plugin/recovery/constants.d.ts +0 -21
- package/dist/plugin/recovery/constants.js +0 -42
- package/dist/plugin/recovery/index.d.ts +0 -11
- package/dist/plugin/recovery/index.js +0 -11
- package/dist/plugin/recovery/storage.d.ts +0 -23
- package/dist/plugin/recovery/storage.js +0 -340
- package/dist/plugin/recovery/types.d.ts +0 -115
- package/dist/plugin/recovery/types.js +0 -6
- package/dist/plugin/recovery.d.ts +0 -60
- package/dist/plugin/recovery.js +0 -360
- package/dist/plugin/refresh-queue.d.ts +0 -99
- package/dist/plugin/refresh-queue.js +0 -235
- package/dist/plugin/request-helpers.d.ts +0 -281
- package/dist/plugin/request-helpers.js +0 -2200
- package/dist/plugin/request.d.ts +0 -110
- package/dist/plugin/request.js +0 -1489
- package/dist/plugin/rotation.d.ts +0 -182
- package/dist/plugin/rotation.js +0 -364
- package/dist/plugin/search.d.ts +0 -31
- package/dist/plugin/search.js +0 -185
- package/dist/plugin/server.d.ts +0 -22
- package/dist/plugin/server.js +0 -306
- package/dist/plugin/storage.d.ts +0 -136
- package/dist/plugin/storage.js +0 -599
- package/dist/plugin/stores/signature-store.d.ts +0 -4
- package/dist/plugin/stores/signature-store.js +0 -24
- package/dist/plugin/thinking-recovery.d.ts +0 -89
- package/dist/plugin/thinking-recovery.js +0 -289
- package/dist/plugin/token.d.ts +0 -18
- package/dist/plugin/token.js +0 -127
- package/dist/plugin/transform/claude.d.ts +0 -79
- package/dist/plugin/transform/claude.js +0 -256
- package/dist/plugin/transform/cross-model-sanitizer.d.ts +0 -34
- package/dist/plugin/transform/cross-model-sanitizer.js +0 -224
- package/dist/plugin/transform/gemini.d.ts +0 -132
- package/dist/plugin/transform/gemini.js +0 -659
- package/dist/plugin/transform/index.d.ts +0 -14
- package/dist/plugin/transform/index.js +0 -9
- package/dist/plugin/transform/model-resolver.d.ts +0 -98
- package/dist/plugin/transform/model-resolver.js +0 -320
- package/dist/plugin/transform/types.d.ts +0 -110
- package/dist/plugin/transform/types.js +0 -1
- package/dist/plugin/types.d.ts +0 -95
- package/dist/plugin/types.js +0 -1
- package/dist/plugin/ui/ansi.d.ts +0 -31
- package/dist/plugin/ui/ansi.js +0 -45
- package/dist/plugin/ui/auth-menu.d.ts +0 -47
- package/dist/plugin/ui/auth-menu.js +0 -199
- package/dist/plugin/ui/confirm.d.ts +0 -1
- package/dist/plugin/ui/confirm.js +0 -14
- package/dist/plugin/ui/select.d.ts +0 -22
- package/dist/plugin/ui/select.js +0 -243
- package/dist/plugin/version.d.ts +0 -18
- package/dist/plugin/version.js +0 -79
- package/dist/src/antigravity/oauth.d.ts +0 -30
- package/dist/src/antigravity/oauth.js +0 -170
- package/dist/src/constants.d.ts +0 -138
- package/dist/src/constants.js +0 -216
- package/dist/src/hooks/auto-update-checker/cache.d.ts +0 -2
- package/dist/src/hooks/auto-update-checker/cache.js +0 -70
- package/dist/src/hooks/auto-update-checker/checker.d.ts +0 -15
- package/dist/src/hooks/auto-update-checker/checker.js +0 -233
- package/dist/src/hooks/auto-update-checker/constants.d.ts +0 -8
- package/dist/src/hooks/auto-update-checker/constants.js +0 -22
- package/dist/src/hooks/auto-update-checker/index.d.ts +0 -33
- package/dist/src/hooks/auto-update-checker/index.js +0 -121
- package/dist/src/hooks/auto-update-checker/logging.d.ts +0 -2
- package/dist/src/hooks/auto-update-checker/logging.js +0 -8
- package/dist/src/hooks/auto-update-checker/types.d.ts +0 -24
- package/dist/src/hooks/auto-update-checker/types.js +0 -1
- package/dist/src/index.d.ts +0 -6
- package/dist/src/index.js +0 -5
- package/dist/src/plugin/accounts.d.ts +0 -173
- package/dist/src/plugin/accounts.js +0 -966
- package/dist/src/plugin/auth.d.ts +0 -20
- package/dist/src/plugin/auth.js +0 -44
- package/dist/src/plugin/cache/index.d.ts +0 -4
- package/dist/src/plugin/cache/index.js +0 -4
- package/dist/src/plugin/cache/signature-cache.d.ts +0 -110
- package/dist/src/plugin/cache/signature-cache.js +0 -347
- package/dist/src/plugin/cache.d.ts +0 -43
- package/dist/src/plugin/cache.js +0 -180
- package/dist/src/plugin/cli.d.ts +0 -26
- package/dist/src/plugin/cli.js +0 -126
- package/dist/src/plugin/config/index.d.ts +0 -15
- package/dist/src/plugin/config/index.js +0 -15
- package/dist/src/plugin/config/loader.d.ts +0 -38
- package/dist/src/plugin/config/loader.js +0 -150
- package/dist/src/plugin/config/models.d.ts +0 -26
- package/dist/src/plugin/config/models.js +0 -95
- package/dist/src/plugin/config/schema.d.ts +0 -144
- package/dist/src/plugin/config/schema.js +0 -458
- package/dist/src/plugin/config/updater.d.ts +0 -76
- package/dist/src/plugin/config/updater.js +0 -205
- package/dist/src/plugin/core/streaming/index.d.ts +0 -2
- package/dist/src/plugin/core/streaming/index.js +0 -2
- package/dist/src/plugin/core/streaming/transformer.d.ts +0 -9
- package/dist/src/plugin/core/streaming/transformer.js +0 -301
- package/dist/src/plugin/core/streaming/types.d.ts +0 -28
- package/dist/src/plugin/core/streaming/types.js +0 -1
- package/dist/src/plugin/debug.d.ts +0 -93
- package/dist/src/plugin/debug.js +0 -375
- package/dist/src/plugin/errors.d.ts +0 -27
- package/dist/src/plugin/errors.js +0 -41
- package/dist/src/plugin/fingerprint.d.ts +0 -69
- package/dist/src/plugin/fingerprint.js +0 -137
- package/dist/src/plugin/image-saver.d.ts +0 -24
- package/dist/src/plugin/image-saver.js +0 -78
- package/dist/src/plugin/logger.d.ts +0 -35
- package/dist/src/plugin/logger.js +0 -67
- package/dist/src/plugin/logging-utils.d.ts +0 -22
- package/dist/src/plugin/logging-utils.js +0 -91
- package/dist/src/plugin/project.d.ts +0 -32
- package/dist/src/plugin/project.js +0 -229
- package/dist/src/plugin/quota.d.ts +0 -34
- package/dist/src/plugin/quota.js +0 -261
- package/dist/src/plugin/recovery/constants.d.ts +0 -21
- package/dist/src/plugin/recovery/constants.js +0 -42
- package/dist/src/plugin/recovery/index.d.ts +0 -11
- package/dist/src/plugin/recovery/index.js +0 -11
- package/dist/src/plugin/recovery/storage.d.ts +0 -23
- package/dist/src/plugin/recovery/storage.js +0 -340
- package/dist/src/plugin/recovery/types.d.ts +0 -115
- package/dist/src/plugin/recovery/types.js +0 -6
- package/dist/src/plugin/recovery.d.ts +0 -60
- package/dist/src/plugin/recovery.js +0 -360
- package/dist/src/plugin/refresh-queue.d.ts +0 -99
- package/dist/src/plugin/refresh-queue.js +0 -235
- package/dist/src/plugin/request-helpers.d.ts +0 -281
- package/dist/src/plugin/request-helpers.js +0 -2200
- package/dist/src/plugin/request.d.ts +0 -110
- package/dist/src/plugin/request.js +0 -1489
- package/dist/src/plugin/rotation.d.ts +0 -182
- package/dist/src/plugin/rotation.js +0 -364
- package/dist/src/plugin/search.d.ts +0 -31
- package/dist/src/plugin/search.js +0 -185
- package/dist/src/plugin/server.d.ts +0 -22
- package/dist/src/plugin/server.js +0 -306
- package/dist/src/plugin/storage.d.ts +0 -136
- package/dist/src/plugin/storage.js +0 -599
- package/dist/src/plugin/stores/signature-store.d.ts +0 -4
- package/dist/src/plugin/stores/signature-store.js +0 -24
- package/dist/src/plugin/thinking-recovery.d.ts +0 -89
- package/dist/src/plugin/thinking-recovery.js +0 -289
- package/dist/src/plugin/token.d.ts +0 -18
- package/dist/src/plugin/token.js +0 -127
- package/dist/src/plugin/transform/claude.d.ts +0 -79
- package/dist/src/plugin/transform/claude.js +0 -256
- package/dist/src/plugin/transform/cross-model-sanitizer.d.ts +0 -34
- package/dist/src/plugin/transform/cross-model-sanitizer.js +0 -224
- package/dist/src/plugin/transform/gemini.d.ts +0 -132
- package/dist/src/plugin/transform/gemini.js +0 -659
- package/dist/src/plugin/transform/index.d.ts +0 -14
- package/dist/src/plugin/transform/index.js +0 -9
- package/dist/src/plugin/transform/model-resolver.d.ts +0 -98
- package/dist/src/plugin/transform/model-resolver.js +0 -320
- package/dist/src/plugin/transform/types.d.ts +0 -110
- package/dist/src/plugin/transform/types.js +0 -1
- package/dist/src/plugin/types.d.ts +0 -95
- package/dist/src/plugin/types.js +0 -1
- package/dist/src/plugin/ui/ansi.d.ts +0 -31
- package/dist/src/plugin/ui/ansi.js +0 -45
- package/dist/src/plugin/ui/auth-menu.d.ts +0 -47
- package/dist/src/plugin/ui/auth-menu.js +0 -199
- package/dist/src/plugin/ui/confirm.d.ts +0 -1
- package/dist/src/plugin/ui/confirm.js +0 -14
- package/dist/src/plugin/ui/select.d.ts +0 -22
- package/dist/src/plugin/ui/select.js +0 -243
- package/dist/src/plugin/version.d.ts +0 -18
- package/dist/src/plugin/version.js +0 -79
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
import type { GoogleSearchConfig } from "./transform/types";
|
|
2
|
-
/**
|
|
3
|
-
* Cleans a JSON schema for Antigravity API compatibility.
|
|
4
|
-
* Transforms unsupported features into description hints while preserving semantic information.
|
|
5
|
-
*
|
|
6
|
-
* Ported from CLIProxyAPI's CleanJSONSchemaForAntigravity (gemini_schema.go)
|
|
7
|
-
*/
|
|
8
|
-
export declare function cleanJSONSchemaForAntigravity(schema: any): any;
|
|
9
|
-
export interface AntigravityApiError {
|
|
10
|
-
code?: number;
|
|
11
|
-
message?: string;
|
|
12
|
-
status?: string;
|
|
13
|
-
[key: string]: unknown;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Minimal representation of Antigravity API responses we touch.
|
|
17
|
-
*/
|
|
18
|
-
export interface AntigravityApiBody {
|
|
19
|
-
response?: unknown;
|
|
20
|
-
error?: AntigravityApiError;
|
|
21
|
-
[key: string]: unknown;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Usage metadata exposed by Antigravity responses. Fields are optional to reflect partial payloads.
|
|
25
|
-
*/
|
|
26
|
-
export interface AntigravityUsageMetadata {
|
|
27
|
-
totalTokenCount?: number;
|
|
28
|
-
promptTokenCount?: number;
|
|
29
|
-
candidatesTokenCount?: number;
|
|
30
|
-
cachedContentTokenCount?: number;
|
|
31
|
-
thoughtsTokenCount?: number;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Normalized thinking configuration accepted by Antigravity.
|
|
35
|
-
*/
|
|
36
|
-
export interface ThinkingConfig {
|
|
37
|
-
thinkingBudget?: number;
|
|
38
|
-
includeThoughts?: boolean;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Default token budget for thinking/reasoning. 16000 tokens provides sufficient
|
|
42
|
-
* space for complex reasoning while staying within typical model limits.
|
|
43
|
-
*/
|
|
44
|
-
export declare const DEFAULT_THINKING_BUDGET = 16000;
|
|
45
|
-
/**
|
|
46
|
-
* Checks if a model name indicates thinking/reasoning capability.
|
|
47
|
-
* Models with "thinking", "gemini-3", or "opus" in their name support extended thinking.
|
|
48
|
-
*/
|
|
49
|
-
export declare function isThinkingCapableModel(modelName: string): boolean;
|
|
50
|
-
/**
|
|
51
|
-
* Extracts thinking configuration from various possible request locations.
|
|
52
|
-
* Supports both Gemini-style thinkingConfig and Anthropic-style thinking options.
|
|
53
|
-
*/
|
|
54
|
-
export declare function extractThinkingConfig(requestPayload: Record<string, unknown>, rawGenerationConfig: Record<string, unknown> | undefined, extraBody: Record<string, unknown> | undefined): ThinkingConfig | undefined;
|
|
55
|
-
/**
|
|
56
|
-
* Variant thinking config extracted from OpenCode's providerOptions.
|
|
57
|
-
*/
|
|
58
|
-
export interface VariantThinkingConfig {
|
|
59
|
-
/** Gemini 3 native thinking level (low/medium/high) */
|
|
60
|
-
thinkingLevel?: string;
|
|
61
|
-
/** Numeric thinking budget for Claude and Gemini 2.5 */
|
|
62
|
-
thinkingBudget?: number;
|
|
63
|
-
/** Whether to include thoughts in output */
|
|
64
|
-
includeThoughts?: boolean;
|
|
65
|
-
/** Google Search configuration */
|
|
66
|
-
googleSearch?: GoogleSearchConfig;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Extracts variant thinking config from OpenCode's providerOptions.
|
|
70
|
-
*
|
|
71
|
-
* All Antigravity models route through the Google provider, so we only check
|
|
72
|
-
* providerOptions.google. Supports two formats:
|
|
73
|
-
*
|
|
74
|
-
* 1. Gemini 3 native: { google: { thinkingLevel: "high", includeThoughts: true } }
|
|
75
|
-
* 2. Budget-based (Claude/Gemini 2.5): { google: { thinkingConfig: { thinkingBudget: 32000 } } }
|
|
76
|
-
*
|
|
77
|
-
* When providerOptions is missing or has no thinking config (common with OpenCode
|
|
78
|
-
* model variants), falls back to extracting from generationConfig directly:
|
|
79
|
-
* 3. generationConfig fallback: { thinkingConfig: { thinkingBudget: 8192 } }
|
|
80
|
-
*/
|
|
81
|
-
export declare function extractVariantThinkingConfig(providerOptions: Record<string, unknown> | undefined, generationConfig?: Record<string, unknown> | undefined): VariantThinkingConfig | undefined;
|
|
82
|
-
/**
|
|
83
|
-
* Determines the final thinking configuration based on model capabilities and user settings.
|
|
84
|
-
* For Claude thinking models, we keep thinking enabled even in multi-turn conversations.
|
|
85
|
-
* The filterUnsignedThinkingBlocks function will handle signature validation/restoration.
|
|
86
|
-
*/
|
|
87
|
-
export declare function resolveThinkingConfig(userConfig: ThinkingConfig | undefined, isThinkingModel: boolean, _isClaudeModel: boolean, _hasAssistantHistory: boolean): ThinkingConfig | undefined;
|
|
88
|
-
/**
|
|
89
|
-
* Filters thinking blocks from contents unless the signature matches our cache.
|
|
90
|
-
* Attempts to restore signatures from cache for thinking blocks that lack signatures.
|
|
91
|
-
*
|
|
92
|
-
* @param contents - The contents array from the request
|
|
93
|
-
* @param sessionId - Optional session ID for signature cache lookup
|
|
94
|
-
* @param getCachedSignatureFn - Optional function to retrieve cached signatures
|
|
95
|
-
*/
|
|
96
|
-
export declare function filterUnsignedThinkingBlocks(contents: any[], sessionId?: string, getCachedSignatureFn?: (sessionId: string, text: string) => string | undefined, isClaudeModel?: boolean): any[];
|
|
97
|
-
/**
|
|
98
|
-
* Filters thinking blocks from Anthropic-style messages[] payloads using cached signatures.
|
|
99
|
-
*/
|
|
100
|
-
export declare function filterMessagesThinkingBlocks(messages: any[], sessionId?: string, getCachedSignatureFn?: (sessionId: string, text: string) => string | undefined, isClaudeModel?: boolean): any[];
|
|
101
|
-
export declare function deepFilterThinkingBlocks(payload: unknown, sessionId?: string, getCachedSignatureFn?: (sessionId: string, text: string) => string | undefined, isClaudeModel?: boolean): unknown;
|
|
102
|
-
/**
|
|
103
|
-
* Transforms thinking/reasoning content in response parts to OpenCode's expected format.
|
|
104
|
-
* Handles both Gemini-style (thought: true) and Anthropic-style (type: "thinking") formats.
|
|
105
|
-
* Also extracts reasoning_content for Anthropic-style responses.
|
|
106
|
-
*/
|
|
107
|
-
export declare function transformThinkingParts(response: unknown): unknown;
|
|
108
|
-
/**
|
|
109
|
-
* Ensures thinkingConfig is valid: includeThoughts only allowed when budget > 0.
|
|
110
|
-
*/
|
|
111
|
-
export declare function normalizeThinkingConfig(config: unknown): ThinkingConfig | undefined;
|
|
112
|
-
/**
|
|
113
|
-
* Parses an Antigravity API body; handles array-wrapped responses the API sometimes returns.
|
|
114
|
-
*/
|
|
115
|
-
export declare function parseAntigravityApiBody(rawText: string): AntigravityApiBody | null;
|
|
116
|
-
/**
|
|
117
|
-
* Extracts usageMetadata from a response object, guarding types.
|
|
118
|
-
*/
|
|
119
|
-
export declare function extractUsageMetadata(body: AntigravityApiBody): AntigravityUsageMetadata | null;
|
|
120
|
-
/**
|
|
121
|
-
* Walks SSE lines to find a usage-bearing response chunk.
|
|
122
|
-
*/
|
|
123
|
-
export declare function extractUsageFromSsePayload(payload: string): AntigravityUsageMetadata | null;
|
|
124
|
-
/**
|
|
125
|
-
* Enhances 404 errors for Antigravity models with a direct preview-access message.
|
|
126
|
-
*/
|
|
127
|
-
export declare function rewriteAntigravityPreviewAccessError(body: AntigravityApiBody, status: number, requestedModel?: string): AntigravityApiBody | null;
|
|
128
|
-
/**
|
|
129
|
-
* Checks if a JSON response body represents an empty response.
|
|
130
|
-
*
|
|
131
|
-
* Empty responses occur when:
|
|
132
|
-
* - No candidates in Gemini format
|
|
133
|
-
* - No choices in OpenAI format
|
|
134
|
-
* - Candidates/choices exist but have no content
|
|
135
|
-
*
|
|
136
|
-
* @param text - The response body text (should be valid JSON)
|
|
137
|
-
* @returns true if the response is empty
|
|
138
|
-
*/
|
|
139
|
-
export declare function isEmptyResponseBody(text: string): boolean;
|
|
140
|
-
/**
|
|
141
|
-
* Checks if a streaming SSE response yielded zero meaningful chunks.
|
|
142
|
-
*
|
|
143
|
-
* This is used after consuming a streaming response to determine if retry is needed.
|
|
144
|
-
*/
|
|
145
|
-
export interface StreamingChunkCounter {
|
|
146
|
-
increment: () => void;
|
|
147
|
-
getCount: () => number;
|
|
148
|
-
hasContent: () => boolean;
|
|
149
|
-
}
|
|
150
|
-
export declare function createStreamingChunkCounter(): StreamingChunkCounter;
|
|
151
|
-
/**
|
|
152
|
-
* Checks if an SSE line contains meaningful content.
|
|
153
|
-
*
|
|
154
|
-
* @param line - A single SSE line (e.g., "data: {...}")
|
|
155
|
-
* @returns true if the line contains content worth counting
|
|
156
|
-
*/
|
|
157
|
-
export declare function isMeaningfulSseLine(line: string): boolean;
|
|
158
|
-
export declare function recursivelyParseJsonStrings(obj: unknown, skipParseKeys?: Set<string>, currentKey?: string): unknown;
|
|
159
|
-
/**
|
|
160
|
-
* Groups function calls with their responses, handling ID mismatches.
|
|
161
|
-
*
|
|
162
|
-
* This is a port of LLM-API-Key-Proxy's _fix_tool_response_grouping() function.
|
|
163
|
-
*
|
|
164
|
-
* When context compaction or other processes strip tool responses, the tool call
|
|
165
|
-
* IDs become orphaned. This function attempts to recover by:
|
|
166
|
-
*
|
|
167
|
-
* 1. Pass 1: Match by exact ID (normal case)
|
|
168
|
-
* 2. Pass 2: Match by function name (for ID mismatches)
|
|
169
|
-
* 3. Pass 3: Match "unknown_function" orphans or take first available
|
|
170
|
-
* 4. Fallback: Create placeholder responses for missing tool results
|
|
171
|
-
*
|
|
172
|
-
* @param contents - Array of Gemini-style content messages
|
|
173
|
-
* @returns Fixed contents array with matched tool responses
|
|
174
|
-
*/
|
|
175
|
-
export declare function fixToolResponseGrouping(contents: any[]): any[];
|
|
176
|
-
/**
|
|
177
|
-
* Checks if contents have any tool call/response ID mismatches.
|
|
178
|
-
*
|
|
179
|
-
* @param contents - Array of Gemini-style content messages
|
|
180
|
-
* @returns Object with mismatch details
|
|
181
|
-
*/
|
|
182
|
-
export declare function detectToolIdMismatches(contents: any[]): {
|
|
183
|
-
hasMismatches: boolean;
|
|
184
|
-
expectedIds: string[];
|
|
185
|
-
foundIds: string[];
|
|
186
|
-
missingIds: string[];
|
|
187
|
-
orphanIds: string[];
|
|
188
|
-
};
|
|
189
|
-
/**
|
|
190
|
-
* Find orphaned tool_use IDs (tool_use without matching tool_result).
|
|
191
|
-
* Works on Claude format messages.
|
|
192
|
-
*/
|
|
193
|
-
export declare function findOrphanedToolUseIds(messages: any[]): Set<string>;
|
|
194
|
-
/**
|
|
195
|
-
* Fix orphaned tool_use blocks in Claude format messages.
|
|
196
|
-
* Mirrors fixToolResponseGrouping() but for Claude's messages[] format.
|
|
197
|
-
*
|
|
198
|
-
* Claude format:
|
|
199
|
-
* - assistant message with content[]: { type: 'tool_use', id, name, input }
|
|
200
|
-
* - user message with content[]: { type: 'tool_result', tool_use_id, content }
|
|
201
|
-
*
|
|
202
|
-
* @param messages - Claude format messages array
|
|
203
|
-
* @returns Fixed messages with placeholder tool_results for orphans
|
|
204
|
-
*/
|
|
205
|
-
export declare function fixClaudeToolPairing(messages: any[]): any[];
|
|
206
|
-
/**
|
|
207
|
-
* Validate and fix tool pairing with fallback nuclear option.
|
|
208
|
-
* Defense in depth: tries gentle fix first, then nuclear removal.
|
|
209
|
-
*/
|
|
210
|
-
export declare function validateAndFixClaudeToolPairing(messages: any[]): any[];
|
|
211
|
-
/**
|
|
212
|
-
* Injects parameter signatures into tool descriptions.
|
|
213
|
-
* Port of LLM-API-Key-Proxy's _inject_signature_into_descriptions()
|
|
214
|
-
*
|
|
215
|
-
* This helps prevent tool hallucination by explicitly listing parameters
|
|
216
|
-
* in the description, making it harder for the model to hallucinate
|
|
217
|
-
* parameters from its training data.
|
|
218
|
-
*
|
|
219
|
-
* @param tools - Array of tool definitions (Gemini format)
|
|
220
|
-
* @param promptTemplate - Template for the signature (default: "\\n\\nSTRICT PARAMETERS: {params}.")
|
|
221
|
-
* @returns Modified tools array with signatures injected
|
|
222
|
-
*/
|
|
223
|
-
export declare function injectParameterSignatures(tools: any[], promptTemplate?: string): any[];
|
|
224
|
-
/**
|
|
225
|
-
* Injects a tool hardening system instruction into the request payload.
|
|
226
|
-
* Port of LLM-API-Key-Proxy's _inject_tool_hardening_instruction()
|
|
227
|
-
*
|
|
228
|
-
* @param payload - The Gemini request payload
|
|
229
|
-
* @param instructionText - The instruction text to inject
|
|
230
|
-
*/
|
|
231
|
-
export declare function injectToolHardeningInstruction(payload: Record<string, unknown>, instructionText: string): void;
|
|
232
|
-
/**
|
|
233
|
-
* Assigns IDs to functionCall parts and returns the pending call IDs by name.
|
|
234
|
-
* This is the first pass of tool ID assignment.
|
|
235
|
-
*
|
|
236
|
-
* @param contents - Gemini-style contents array
|
|
237
|
-
* @returns Object with modified contents and pending call IDs map
|
|
238
|
-
*/
|
|
239
|
-
export declare function assignToolIdsToContents(contents: any[]): {
|
|
240
|
-
contents: any[];
|
|
241
|
-
pendingCallIdsByName: Map<string, string[]>;
|
|
242
|
-
toolCallCounter: number;
|
|
243
|
-
};
|
|
244
|
-
/**
|
|
245
|
-
* Matches functionResponse IDs to their corresponding functionCall IDs.
|
|
246
|
-
* This is the second pass of tool ID assignment.
|
|
247
|
-
*
|
|
248
|
-
* @param contents - Gemini-style contents array
|
|
249
|
-
* @param pendingCallIdsByName - Map of function names to pending call IDs
|
|
250
|
-
* @returns Modified contents with matched response IDs
|
|
251
|
-
*/
|
|
252
|
-
export declare function matchResponseIdsToContents(contents: any[], pendingCallIdsByName: Map<string, string[]>): any[];
|
|
253
|
-
/**
|
|
254
|
-
* Applies all tool fixes to a request payload for Claude models.
|
|
255
|
-
* This includes:
|
|
256
|
-
* 1. Tool ID assignment for functionCalls
|
|
257
|
-
* 2. Response ID matching for functionResponses
|
|
258
|
-
* 3. Orphan recovery via fixToolResponseGrouping
|
|
259
|
-
* 4. Claude format pairing fix via validateAndFixClaudeToolPairing
|
|
260
|
-
*
|
|
261
|
-
* @param payload - Request payload object
|
|
262
|
-
* @param isClaude - Whether this is a Claude model request
|
|
263
|
-
* @returns Object with fix applied status
|
|
264
|
-
*/
|
|
265
|
-
export declare function applyToolPairingFixes(payload: Record<string, unknown>, isClaude: boolean): {
|
|
266
|
-
contentsFixed: boolean;
|
|
267
|
-
messagesFixed: boolean;
|
|
268
|
-
};
|
|
269
|
-
/**
|
|
270
|
-
* Creates a synthetic Claude SSE streaming response with error content.
|
|
271
|
-
*
|
|
272
|
-
* When returning HTTP 400/500 errors to OpenCode, the session becomes locked
|
|
273
|
-
* and the user cannot use /compact or other commands. This function creates
|
|
274
|
-
* a fake "successful" SSE response (200 OK) with the error message as text content,
|
|
275
|
-
* allowing the user to continue using the session.
|
|
276
|
-
*
|
|
277
|
-
* @param errorMessage - The error message to include in the response
|
|
278
|
-
* @param requestedModel - The model that was requested
|
|
279
|
-
* @returns A Response object with synthetic SSE stream
|
|
280
|
-
*/
|
|
281
|
-
export declare function createSyntheticErrorResponse(errorMessage: string, requestedModel?: string): Response;
|