forked from NoeFabris/opencode-antigravity-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.ts
More file actions
266 lines (230 loc) · 8.65 KB
/
Copy pathschema.ts
File metadata and controls
266 lines (230 loc) · 8.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/**
* Configuration schema for opencode-antigravity-auth plugin.
*
* Config file locations (in priority order, highest wins):
* - Project: .opencode/antigravity.json
* - User: ~/.config/opencode/antigravity.json (Linux/Mac)
* %APPDATA%\opencode\antigravity.json (Windows)
*
* Environment variables always override config file values.
*/
import { z } from "zod";
/**
* Signature cache configuration for persisting thinking block signatures to disk.
*/
export const SignatureCacheConfigSchema = z.object({
/** Enable disk caching of signatures (default: true) */
enabled: z.boolean().default(true),
/** In-memory TTL in seconds (default: 3600 = 1 hour) */
memory_ttl_seconds: z.number().min(60).max(86400).default(3600),
/** Disk TTL in seconds (default: 172800 = 48 hours) */
disk_ttl_seconds: z.number().min(3600).max(604800).default(172800),
/** Background write interval in seconds (default: 60) */
write_interval_seconds: z.number().min(10).max(600).default(60),
});
/**
* Main configuration schema for the Antigravity OAuth plugin.
*/
export const AntigravityConfigSchema = z.object({
/** JSON Schema reference for IDE support */
$schema: z.string().optional(),
// =========================================================================
// General Settings
// =========================================================================
/**
* Suppress most toast notifications (rate limit, account switching, etc.)
* Recovery toasts are always shown regardless of this setting.
* Env override: OPENCODE_ANTIGRAVITY_QUIET=1
* @default false
*/
quiet_mode: z.boolean().default(false),
/**
* Enable debug logging to file.
* Env override: OPENCODE_ANTIGRAVITY_DEBUG=1
* @default false
*/
debug: z.boolean().default(false),
/**
* Custom directory for debug logs.
* Env override: OPENCODE_ANTIGRAVITY_LOG_DIR=/path/to/logs
* @default OS-specific config dir + "/antigravity-logs"
*/
log_dir: z.string().optional(),
// =========================================================================
// Thinking Blocks
// =========================================================================
/**
* Preserve thinking blocks for Claude models using signature caching.
*
* When false (default): Thinking blocks are stripped for reliability.
* When true: Full context preserved, but may encounter signature errors.
*
* Env override: OPENCODE_ANTIGRAVITY_KEEP_THINKING=1
* @default false
*/
keep_thinking: z.boolean().default(false),
// =========================================================================
// Session Recovery
// =========================================================================
/**
* Enable automatic session recovery from tool_result_missing errors.
* When enabled, shows a toast notification when recoverable errors occur.
*
* @default true
*/
session_recovery: z.boolean().default(true),
/**
* Automatically send a "continue" prompt after successful recovery.
* Only applies when session_recovery is enabled.
*
* When false: Only shows toast notification, user must manually continue.
* When true: Automatically sends "continue" to resume the session.
*
* @default true
*/
auto_resume: z.boolean().default(true),
/**
* Custom text to send when auto-resuming after recovery.
* Only used when auto_resume is enabled.
*
* @default "continue"
*/
resume_text: z.string().default("continue"),
// =========================================================================
// Signature Caching
// =========================================================================
/**
* Signature cache configuration for persisting thinking block signatures.
* Only used when keep_thinking is enabled.
*/
signature_cache: SignatureCacheConfigSchema.optional(),
// =========================================================================
// Empty Response Retry (ported from LLM-API-Key-Proxy)
// =========================================================================
/**
* Maximum retry attempts when Antigravity returns an empty response.
* Empty responses occur when no candidates/choices are returned.
*
* @default 4
*/
empty_response_max_attempts: z.number().min(1).max(10).default(4),
/**
* Delay in milliseconds between empty response retries.
*
* @default 2000
*/
empty_response_retry_delay_ms: z.number().min(500).max(10000).default(2000),
// =========================================================================
// Tool ID Recovery (ported from LLM-API-Key-Proxy)
// =========================================================================
/**
* Enable tool ID orphan recovery.
* When tool responses have mismatched IDs (due to context compaction),
* attempt to match them by function name or create placeholders.
*
* @default true
*/
tool_id_recovery: z.boolean().default(true),
// =========================================================================
// Tool Hallucination Prevention (ported from LLM-API-Key-Proxy)
// =========================================================================
/**
* Enable tool hallucination prevention for Claude models.
* When enabled, injects:
* - Parameter signatures into tool descriptions
* - System instruction with strict tool usage rules
*
* This helps prevent Claude from using parameter names from its training
* data instead of the actual schema.
*
* @default true
*/
claude_tool_hardening: z.boolean().default(true),
// =========================================================================
// Proactive Token Refresh (ported from LLM-API-Key-Proxy)
// =========================================================================
/**
* Enable proactive background token refresh.
* When enabled, tokens are refreshed in the background before they expire,
* ensuring requests never block on token refresh.
*
* @default true
*/
proactive_token_refresh: z.boolean().default(true),
/**
* Seconds before token expiry to trigger proactive refresh.
* Default is 30 minutes (1800 seconds).
*
* @default 1800
*/
proactive_refresh_buffer_seconds: z.number().min(60).max(7200).default(1800),
/**
* Interval between proactive refresh checks in seconds.
* Default is 5 minutes (300 seconds).
*
* @default 300
*/
proactive_refresh_check_interval_seconds: z.number().min(30).max(1800).default(300),
// =========================================================================
// Rate Limiting
// =========================================================================
/**
* Maximum time in seconds to wait when all accounts are rate-limited.
* If the minimum wait time across all accounts exceeds this threshold,
* the plugin fails fast with an error instead of hanging.
*
* Set to 0 to disable (wait indefinitely).
*
* @default 300 (5 minutes)
*/
max_rate_limit_wait_seconds: z.number().min(0).max(3600).default(300),
/**
* Enable quota fallback for Gemini models.
* When the preferred quota (gemini-cli or antigravity) is exhausted,
* try the alternate quota on the same account before switching accounts.
*
* Only applies when model is requested without explicit quota suffix.
* Explicit suffixes like `:antigravity` or `:gemini-cli` always use
* that specific quota and switch accounts if exhausted.
*
* @default false
*/
quota_fallback: z.boolean().default(false),
// =========================================================================
// Auto-Update
// =========================================================================
/**
* Enable automatic plugin updates.
* @default true
*/
auto_update: z.boolean().default(true),
});
export type AntigravityConfig = z.infer<typeof AntigravityConfigSchema>;
export type SignatureCacheConfig = z.infer<typeof SignatureCacheConfigSchema>;
/**
* Default configuration values.
*/
export const DEFAULT_CONFIG: AntigravityConfig = {
quiet_mode: false,
debug: false,
keep_thinking: false,
session_recovery: true,
auto_resume: true,
resume_text: "continue",
empty_response_max_attempts: 4,
empty_response_retry_delay_ms: 2000,
tool_id_recovery: true,
claude_tool_hardening: true,
proactive_token_refresh: true,
proactive_refresh_buffer_seconds: 1800,
proactive_refresh_check_interval_seconds: 300,
max_rate_limit_wait_seconds: 300,
quota_fallback: false,
auto_update: true,
signature_cache: {
enabled: true,
memory_ttl_seconds: 3600,
disk_ttl_seconds: 172800,
write_interval_seconds: 60,
},
};