opencode-antigravity-auth-mf 1.3.0-1

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.
Files changed (195) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +630 -0
  3. package/dist/index.d.ts +4 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +3 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/src/antigravity/oauth.d.ts +31 -0
  8. package/dist/src/antigravity/oauth.d.ts.map +1 -0
  9. package/dist/src/antigravity/oauth.js +168 -0
  10. package/dist/src/antigravity/oauth.js.map +1 -0
  11. package/dist/src/constants.d.ts +99 -0
  12. package/dist/src/constants.d.ts.map +1 -0
  13. package/dist/src/constants.js +135 -0
  14. package/dist/src/constants.js.map +1 -0
  15. package/dist/src/hooks/auto-update-checker/cache.d.ts +3 -0
  16. package/dist/src/hooks/auto-update-checker/cache.d.ts.map +1 -0
  17. package/dist/src/hooks/auto-update-checker/cache.js +71 -0
  18. package/dist/src/hooks/auto-update-checker/cache.js.map +1 -0
  19. package/dist/src/hooks/auto-update-checker/checker.d.ts +16 -0
  20. package/dist/src/hooks/auto-update-checker/checker.d.ts.map +1 -0
  21. package/dist/src/hooks/auto-update-checker/checker.js +237 -0
  22. package/dist/src/hooks/auto-update-checker/checker.js.map +1 -0
  23. package/dist/src/hooks/auto-update-checker/constants.d.ts +9 -0
  24. package/dist/src/hooks/auto-update-checker/constants.d.ts.map +1 -0
  25. package/dist/src/hooks/auto-update-checker/constants.js +23 -0
  26. package/dist/src/hooks/auto-update-checker/constants.js.map +1 -0
  27. package/dist/src/hooks/auto-update-checker/index.d.ts +34 -0
  28. package/dist/src/hooks/auto-update-checker/index.d.ts.map +1 -0
  29. package/dist/src/hooks/auto-update-checker/index.js +125 -0
  30. package/dist/src/hooks/auto-update-checker/index.js.map +1 -0
  31. package/dist/src/hooks/auto-update-checker/types.d.ts +25 -0
  32. package/dist/src/hooks/auto-update-checker/types.d.ts.map +1 -0
  33. package/dist/src/hooks/auto-update-checker/types.js +1 -0
  34. package/dist/src/hooks/auto-update-checker/types.js.map +1 -0
  35. package/dist/src/plugin/accounts.d.ts +86 -0
  36. package/dist/src/plugin/accounts.d.ts.map +1 -0
  37. package/dist/src/plugin/accounts.js +609 -0
  38. package/dist/src/plugin/accounts.js.map +1 -0
  39. package/dist/src/plugin/auth.d.ts +21 -0
  40. package/dist/src/plugin/auth.d.ts.map +1 -0
  41. package/dist/src/plugin/auth.js +46 -0
  42. package/dist/src/plugin/auth.js.map +1 -0
  43. package/dist/src/plugin/cache/index.d.ts +5 -0
  44. package/dist/src/plugin/cache/index.d.ts.map +1 -0
  45. package/dist/src/plugin/cache/index.js +5 -0
  46. package/dist/src/plugin/cache/index.js.map +1 -0
  47. package/dist/src/plugin/cache/signature-cache.d.ts +111 -0
  48. package/dist/src/plugin/cache/signature-cache.d.ts.map +1 -0
  49. package/dist/src/plugin/cache/signature-cache.js +375 -0
  50. package/dist/src/plugin/cache/signature-cache.js.map +1 -0
  51. package/dist/src/plugin/cache.d.ts +44 -0
  52. package/dist/src/plugin/cache.d.ts.map +1 -0
  53. package/dist/src/plugin/cache.js +200 -0
  54. package/dist/src/plugin/cache.js.map +1 -0
  55. package/dist/src/plugin/cli.d.ts +19 -0
  56. package/dist/src/plugin/cli.d.ts.map +1 -0
  57. package/dist/src/plugin/cli.js +59 -0
  58. package/dist/src/plugin/cli.js.map +1 -0
  59. package/dist/src/plugin/config/index.d.ts +16 -0
  60. package/dist/src/plugin/config/index.d.ts.map +1 -0
  61. package/dist/src/plugin/config/index.js +16 -0
  62. package/dist/src/plugin/config/index.js.map +1 -0
  63. package/dist/src/plugin/config/loader.d.ts +37 -0
  64. package/dist/src/plugin/config/loader.d.ts.map +1 -0
  65. package/dist/src/plugin/config/loader.js +206 -0
  66. package/dist/src/plugin/config/loader.js.map +1 -0
  67. package/dist/src/plugin/config/schema.d.ts +411 -0
  68. package/dist/src/plugin/config/schema.d.ts.map +1 -0
  69. package/dist/src/plugin/config/schema.js +339 -0
  70. package/dist/src/plugin/config/schema.js.map +1 -0
  71. package/dist/src/plugin/core/streaming/index.d.ts +3 -0
  72. package/dist/src/plugin/core/streaming/index.d.ts.map +1 -0
  73. package/dist/src/plugin/core/streaming/index.js +3 -0
  74. package/dist/src/plugin/core/streaming/index.js.map +1 -0
  75. package/dist/src/plugin/core/streaming/transformer.d.ts +10 -0
  76. package/dist/src/plugin/core/streaming/transformer.d.ts.map +1 -0
  77. package/dist/src/plugin/core/streaming/transformer.js +255 -0
  78. package/dist/src/plugin/core/streaming/transformer.js.map +1 -0
  79. package/dist/src/plugin/core/streaming/types.d.ts +35 -0
  80. package/dist/src/plugin/core/streaming/types.d.ts.map +1 -0
  81. package/dist/src/plugin/core/streaming/types.js +1 -0
  82. package/dist/src/plugin/core/streaming/types.js.map +1 -0
  83. package/dist/src/plugin/debug.d.ts +68 -0
  84. package/dist/src/plugin/debug.d.ts.map +1 -0
  85. package/dist/src/plugin/debug.js +325 -0
  86. package/dist/src/plugin/debug.js.map +1 -0
  87. package/dist/src/plugin/errors.d.ts +28 -0
  88. package/dist/src/plugin/errors.d.ts.map +1 -0
  89. package/dist/src/plugin/errors.js +42 -0
  90. package/dist/src/plugin/errors.js.map +1 -0
  91. package/dist/src/plugin/image-saver.d.ts +25 -0
  92. package/dist/src/plugin/image-saver.d.ts.map +1 -0
  93. package/dist/src/plugin/image-saver.js +86 -0
  94. package/dist/src/plugin/image-saver.js.map +1 -0
  95. package/dist/src/plugin/logger.d.ts +54 -0
  96. package/dist/src/plugin/logger.d.ts.map +1 -0
  97. package/dist/src/plugin/logger.js +120 -0
  98. package/dist/src/plugin/logger.js.map +1 -0
  99. package/dist/src/plugin/project.d.ts +33 -0
  100. package/dist/src/plugin/project.d.ts.map +1 -0
  101. package/dist/src/plugin/project.js +234 -0
  102. package/dist/src/plugin/project.js.map +1 -0
  103. package/dist/src/plugin/recovery/constants.d.ts +22 -0
  104. package/dist/src/plugin/recovery/constants.d.ts.map +1 -0
  105. package/dist/src/plugin/recovery/constants.js +43 -0
  106. package/dist/src/plugin/recovery/constants.js.map +1 -0
  107. package/dist/src/plugin/recovery/index.d.ts +12 -0
  108. package/dist/src/plugin/recovery/index.d.ts.map +1 -0
  109. package/dist/src/plugin/recovery/index.js +12 -0
  110. package/dist/src/plugin/recovery/index.js.map +1 -0
  111. package/dist/src/plugin/recovery/storage.d.ts +24 -0
  112. package/dist/src/plugin/recovery/storage.d.ts.map +1 -0
  113. package/dist/src/plugin/recovery/storage.js +354 -0
  114. package/dist/src/plugin/recovery/storage.js.map +1 -0
  115. package/dist/src/plugin/recovery/types.d.ts +116 -0
  116. package/dist/src/plugin/recovery/types.d.ts.map +1 -0
  117. package/dist/src/plugin/recovery/types.js +6 -0
  118. package/dist/src/plugin/recovery/types.js.map +1 -0
  119. package/dist/src/plugin/recovery.d.ts +61 -0
  120. package/dist/src/plugin/recovery.d.ts.map +1 -0
  121. package/dist/src/plugin/recovery.js +376 -0
  122. package/dist/src/plugin/recovery.js.map +1 -0
  123. package/dist/src/plugin/refresh-queue.d.ts +101 -0
  124. package/dist/src/plugin/refresh-queue.d.ts.map +1 -0
  125. package/dist/src/plugin/refresh-queue.js +244 -0
  126. package/dist/src/plugin/refresh-queue.js.map +1 -0
  127. package/dist/src/plugin/request-helpers.d.ts +278 -0
  128. package/dist/src/plugin/request-helpers.d.ts.map +1 -0
  129. package/dist/src/plugin/request-helpers.js +2268 -0
  130. package/dist/src/plugin/request-helpers.js.map +1 -0
  131. package/dist/src/plugin/request.d.ts +91 -0
  132. package/dist/src/plugin/request.d.ts.map +1 -0
  133. package/dist/src/plugin/request.js +1302 -0
  134. package/dist/src/plugin/request.js.map +1 -0
  135. package/dist/src/plugin/rotation.d.ts +168 -0
  136. package/dist/src/plugin/rotation.d.ts.map +1 -0
  137. package/dist/src/plugin/rotation.js +302 -0
  138. package/dist/src/plugin/rotation.js.map +1 -0
  139. package/dist/src/plugin/server.d.ts +23 -0
  140. package/dist/src/plugin/server.d.ts.map +1 -0
  141. package/dist/src/plugin/server.js +324 -0
  142. package/dist/src/plugin/server.js.map +1 -0
  143. package/dist/src/plugin/storage.d.ts +92 -0
  144. package/dist/src/plugin/storage.d.ts.map +1 -0
  145. package/dist/src/plugin/storage.js +417 -0
  146. package/dist/src/plugin/storage.js.map +1 -0
  147. package/dist/src/plugin/stores/signature-store.d.ts +5 -0
  148. package/dist/src/plugin/stores/signature-store.d.ts.map +1 -0
  149. package/dist/src/plugin/stores/signature-store.js +25 -0
  150. package/dist/src/plugin/stores/signature-store.js.map +1 -0
  151. package/dist/src/plugin/thinking-recovery.d.ts +90 -0
  152. package/dist/src/plugin/thinking-recovery.d.ts.map +1 -0
  153. package/dist/src/plugin/thinking-recovery.js +316 -0
  154. package/dist/src/plugin/thinking-recovery.js.map +1 -0
  155. package/dist/src/plugin/token.d.ts +19 -0
  156. package/dist/src/plugin/token.d.ts.map +1 -0
  157. package/dist/src/plugin/token.js +128 -0
  158. package/dist/src/plugin/token.js.map +1 -0
  159. package/dist/src/plugin/transform/claude.d.ts +80 -0
  160. package/dist/src/plugin/transform/claude.d.ts.map +1 -0
  161. package/dist/src/plugin/transform/claude.js +265 -0
  162. package/dist/src/plugin/transform/claude.js.map +1 -0
  163. package/dist/src/plugin/transform/cross-model-sanitizer.d.ts +35 -0
  164. package/dist/src/plugin/transform/cross-model-sanitizer.d.ts.map +1 -0
  165. package/dist/src/plugin/transform/cross-model-sanitizer.js +225 -0
  166. package/dist/src/plugin/transform/cross-model-sanitizer.js.map +1 -0
  167. package/dist/src/plugin/transform/gemini.d.ts +112 -0
  168. package/dist/src/plugin/transform/gemini.d.ts.map +1 -0
  169. package/dist/src/plugin/transform/gemini.js +409 -0
  170. package/dist/src/plugin/transform/gemini.js.map +1 -0
  171. package/dist/src/plugin/transform/index.d.ts +15 -0
  172. package/dist/src/plugin/transform/index.d.ts.map +1 -0
  173. package/dist/src/plugin/transform/index.js +14 -0
  174. package/dist/src/plugin/transform/index.js.map +1 -0
  175. package/dist/src/plugin/transform/model-resolver.d.ts +101 -0
  176. package/dist/src/plugin/transform/model-resolver.d.ts.map +1 -0
  177. package/dist/src/plugin/transform/model-resolver.js +356 -0
  178. package/dist/src/plugin/transform/model-resolver.js.map +1 -0
  179. package/dist/src/plugin/transform/types.d.ts +106 -0
  180. package/dist/src/plugin/transform/types.d.ts.map +1 -0
  181. package/dist/src/plugin/transform/types.js +1 -0
  182. package/dist/src/plugin/transform/types.js.map +1 -0
  183. package/dist/src/plugin/types.d.ts +96 -0
  184. package/dist/src/plugin/types.d.ts.map +1 -0
  185. package/dist/src/plugin/types.js +1 -0
  186. package/dist/src/plugin/types.js.map +1 -0
  187. package/dist/src/plugin/usage-reporter.d.ts +23 -0
  188. package/dist/src/plugin/usage-reporter.d.ts.map +1 -0
  189. package/dist/src/plugin/usage-reporter.js +43 -0
  190. package/dist/src/plugin/usage-reporter.js.map +1 -0
  191. package/dist/src/plugin.d.ts +8 -0
  192. package/dist/src/plugin.d.ts.map +1 -0
  193. package/dist/src/plugin.js +1708 -0
  194. package/dist/src/plugin.js.map +1 -0
  195. package/package.json +67 -0
@@ -0,0 +1,316 @@
1
+ /**
2
+ * Thinking Recovery Module
3
+ *
4
+ * Minimal implementation for recovering from corrupted thinking state.
5
+ * When Claude's conversation history gets corrupted (thinking blocks stripped/malformed),
6
+ * this module provides a "last resort" recovery by closing the current turn and starting fresh.
7
+ *
8
+ * Philosophy: "Let it crash and start again" - Instead of trying to fix corrupted state,
9
+ * we abandon the corrupted turn and let Claude generate fresh thinking.
10
+ */
11
+ // ============================================================================
12
+ // DETECTION HELPERS
13
+ // ============================================================================
14
+ /**
15
+ * Checks if a message part is a thinking/reasoning block.
16
+ */
17
+ function isThinkingPart(part) {
18
+ if (!part || typeof part !== "object")
19
+ return false;
20
+ return (part.thought === true ||
21
+ part.type === "thinking" ||
22
+ part.type === "redacted_thinking");
23
+ }
24
+ /**
25
+ * Checks if a message part is a function response (tool result).
26
+ */
27
+ function isFunctionResponsePart(part) {
28
+ return part && typeof part === "object" && "functionResponse" in part;
29
+ }
30
+ /**
31
+ * Checks if a message part is a function call.
32
+ */
33
+ function isFunctionCallPart(part) {
34
+ return part && typeof part === "object" && "functionCall" in part;
35
+ }
36
+ /**
37
+ * Checks if a message is a tool result container (user role with functionResponse).
38
+ */
39
+ function isToolResultMessage(msg) {
40
+ if (!msg || msg.role !== "user")
41
+ return false;
42
+ const parts = msg.parts || [];
43
+ return parts.some(isFunctionResponsePart);
44
+ }
45
+ /**
46
+ * Checks if a message contains thinking/reasoning content.
47
+ */
48
+ function messageHasThinking(msg) {
49
+ if (!msg || typeof msg !== "object")
50
+ return false;
51
+ // Gemini format: parts array
52
+ if (Array.isArray(msg.parts)) {
53
+ return msg.parts.some(isThinkingPart);
54
+ }
55
+ // Anthropic format: content array
56
+ if (Array.isArray(msg.content)) {
57
+ return msg.content.some((block) => block?.type === "thinking" || block?.type === "redacted_thinking");
58
+ }
59
+ return false;
60
+ }
61
+ /**
62
+ * Checks if a message contains tool calls.
63
+ */
64
+ function messageHasToolCalls(msg) {
65
+ if (!msg || typeof msg !== "object")
66
+ return false;
67
+ // Gemini format: parts array with functionCall
68
+ if (Array.isArray(msg.parts)) {
69
+ return msg.parts.some(isFunctionCallPart);
70
+ }
71
+ // Anthropic format: content array with tool_use
72
+ if (Array.isArray(msg.content)) {
73
+ return msg.content.some((block) => block?.type === "tool_use");
74
+ }
75
+ return false;
76
+ }
77
+ // ============================================================================
78
+ // CONVERSATION STATE ANALYSIS
79
+ // ============================================================================
80
+ /**
81
+ * Analyzes conversation state to detect tool use loops and thinking mode issues.
82
+ *
83
+ * Key insight: A "turn" can span multiple assistant messages in a tool-use loop.
84
+ * We need to find the TURN START (first assistant message after last real user message)
85
+ * and check if THAT message had thinking, not just the last assistant message.
86
+ */
87
+ export function analyzeConversationState(contents) {
88
+ const state = {
89
+ inToolLoop: false,
90
+ turnStartIdx: -1,
91
+ turnHasThinking: false,
92
+ lastModelIdx: -1,
93
+ lastModelHasThinking: false,
94
+ lastModelHasToolCalls: false,
95
+ };
96
+ if (!Array.isArray(contents) || contents.length === 0) {
97
+ return state;
98
+ }
99
+ // First pass: Find the last "real" user message (not a tool result)
100
+ let lastRealUserIdx = -1;
101
+ for (let i = 0; i < contents.length; i++) {
102
+ const msg = contents[i];
103
+ if (msg?.role === "user" && !isToolResultMessage(msg)) {
104
+ lastRealUserIdx = i;
105
+ }
106
+ }
107
+ // Second pass: Analyze conversation and find turn boundaries
108
+ for (let i = 0; i < contents.length; i++) {
109
+ const msg = contents[i];
110
+ const role = msg?.role;
111
+ if (role === "model" || role === "assistant") {
112
+ const hasThinking = messageHasThinking(msg);
113
+ const hasToolCalls = messageHasToolCalls(msg);
114
+ // Track if this is the turn start
115
+ if (i > lastRealUserIdx && state.turnStartIdx === -1) {
116
+ state.turnStartIdx = i;
117
+ state.turnHasThinking = hasThinking;
118
+ }
119
+ state.lastModelIdx = i;
120
+ state.lastModelHasToolCalls = hasToolCalls;
121
+ state.lastModelHasThinking = hasThinking;
122
+ }
123
+ }
124
+ // Determine if we're in a tool loop
125
+ // We're in a tool loop if the conversation ends with a tool result
126
+ if (contents.length > 0) {
127
+ const lastMsg = contents[contents.length - 1];
128
+ if (lastMsg?.role === "user" && isToolResultMessage(lastMsg)) {
129
+ state.inToolLoop = true;
130
+ }
131
+ }
132
+ return state;
133
+ }
134
+ // ============================================================================
135
+ // RECOVERY FUNCTIONS
136
+ // ============================================================================
137
+ /**
138
+ * Strips all thinking blocks from messages.
139
+ * Used before injecting synthetic messages to avoid invalid thinking patterns.
140
+ */
141
+ function stripAllThinkingBlocks(contents) {
142
+ return contents.map((content) => {
143
+ if (!content || typeof content !== "object")
144
+ return content;
145
+ // Handle Gemini-style parts
146
+ if (Array.isArray(content.parts)) {
147
+ const filteredParts = content.parts.filter((part) => !isThinkingPart(part));
148
+ // Keep at least one part to avoid empty messages
149
+ if (filteredParts.length === 0 && content.parts.length > 0) {
150
+ return content;
151
+ }
152
+ return { ...content, parts: filteredParts };
153
+ }
154
+ // Handle Anthropic-style content
155
+ if (Array.isArray(content.content)) {
156
+ const filteredContent = content.content.filter((block) => block?.type !== "thinking" && block?.type !== "redacted_thinking");
157
+ if (filteredContent.length === 0 && content.content.length > 0) {
158
+ return content;
159
+ }
160
+ return { ...content, content: filteredContent };
161
+ }
162
+ return content;
163
+ });
164
+ }
165
+ /**
166
+ * Counts tool results at the end of the conversation.
167
+ */
168
+ function countTrailingToolResults(contents) {
169
+ let count = 0;
170
+ for (let i = contents.length - 1; i >= 0; i--) {
171
+ const msg = contents[i];
172
+ if (msg?.role === "user") {
173
+ const parts = msg.parts || [];
174
+ const functionResponses = parts.filter(isFunctionResponsePart);
175
+ if (functionResponses.length > 0) {
176
+ count += functionResponses.length;
177
+ }
178
+ else {
179
+ break; // Real user message, stop counting
180
+ }
181
+ }
182
+ else if (msg?.role === "model" || msg?.role === "assistant") {
183
+ break; // Stop at the model that made the tool calls
184
+ }
185
+ }
186
+ return count;
187
+ }
188
+ /**
189
+ * Closes an incomplete tool loop by injecting synthetic messages to start a new turn.
190
+ *
191
+ * This is the "let it crash and start again" recovery mechanism.
192
+ *
193
+ * When we detect:
194
+ * - We're in a tool loop (conversation ends with functionResponse)
195
+ * - The tool call was made WITHOUT thinking (thinking was stripped/corrupted)
196
+ * - We NOW want to enable thinking
197
+ *
198
+ * Instead of trying to fix the corrupted state, we:
199
+ * 1. Strip ALL thinking blocks (removes any corrupted ones)
200
+ * 2. Add synthetic MODEL message to complete the non-thinking turn
201
+ * 3. Add synthetic USER message to start a NEW turn
202
+ *
203
+ * This allows Claude to generate fresh thinking for the new turn.
204
+ */
205
+ export function closeToolLoopForThinking(contents) {
206
+ // Strip any old/corrupted thinking first
207
+ const strippedContents = stripAllThinkingBlocks(contents);
208
+ // Count tool results from the end of the conversation
209
+ const toolResultCount = countTrailingToolResults(strippedContents);
210
+ // Build synthetic model message content based on tool count
211
+ let syntheticModelContent;
212
+ if (toolResultCount === 0) {
213
+ syntheticModelContent = "[Processing previous context.]";
214
+ }
215
+ else if (toolResultCount === 1) {
216
+ syntheticModelContent = "[Tool execution completed.]";
217
+ }
218
+ else {
219
+ syntheticModelContent = `[${toolResultCount} tool executions completed.]`;
220
+ }
221
+ // Step 1: Inject synthetic MODEL message to complete the non-thinking turn
222
+ const syntheticModel = {
223
+ role: "model",
224
+ parts: [{ text: syntheticModelContent }],
225
+ };
226
+ // Step 2: Inject synthetic USER message to start a NEW turn
227
+ const syntheticUser = {
228
+ role: "user",
229
+ parts: [{ text: "[Continue]" }],
230
+ };
231
+ return [...strippedContents, syntheticModel, syntheticUser];
232
+ }
233
+ /**
234
+ * Checks if conversation state requires tool loop closure for thinking recovery.
235
+ *
236
+ * Returns true if:
237
+ * - We're in a tool loop (state.inToolLoop)
238
+ * - The turn didn't start with thinking (state.turnHasThinking === false)
239
+ *
240
+ * This is the trigger for the "let it crash and start again" recovery.
241
+ */
242
+ export function needsThinkingRecovery(state) {
243
+ return state.inToolLoop && !state.turnHasThinking;
244
+ }
245
+ // ============================================================================
246
+ // COMPACTED THINKING TURN DETECTION (Ported from LLM-API-Key-Proxy)
247
+ // ============================================================================
248
+ /**
249
+ * Detects if a message looks like it was compacted from a thinking-enabled turn.
250
+ *
251
+ * This is a heuristic to distinguish between:
252
+ * - "Never had thinking" (model didn't use thinking mode)
253
+ * - "Thinking was stripped" (context compaction removed thinking blocks)
254
+ *
255
+ * Port of LLM-API-Key-Proxy's _looks_like_compacted_thinking_turn()
256
+ *
257
+ * Heuristics:
258
+ * 1. Has functionCall parts (typical thinking flow produces tool calls)
259
+ * 2. No thinking parts (thought: true)
260
+ * 3. No text content before functionCall (thinking responses usually have text)
261
+ *
262
+ * @param msg - A single message from the conversation
263
+ * @returns true if the message looks like thinking was stripped
264
+ */
265
+ export function looksLikeCompactedThinkingTurn(msg) {
266
+ if (!msg || typeof msg !== "object")
267
+ return false;
268
+ const parts = msg.parts || [];
269
+ if (parts.length === 0)
270
+ return false;
271
+ // Check if message has function calls
272
+ const hasFunctionCall = parts.some((p) => p && typeof p === "object" && p.functionCall);
273
+ if (!hasFunctionCall)
274
+ return false;
275
+ // Check for thinking blocks
276
+ const hasThinking = parts.some((p) => p &&
277
+ typeof p === "object" &&
278
+ (p.thought === true || p.type === "thinking" || p.type === "redacted_thinking"));
279
+ if (hasThinking)
280
+ return false;
281
+ // Check for text content (not thinking)
282
+ const hasTextBeforeFunctionCall = parts.some((p, idx) => {
283
+ if (!p || typeof p !== "object")
284
+ return false;
285
+ // Only check parts before the first functionCall
286
+ const firstFuncIdx = parts.findIndex((fp) => fp && typeof fp === "object" && fp.functionCall);
287
+ if (idx >= firstFuncIdx)
288
+ return false;
289
+ // Check for non-thinking text
290
+ return ("text" in p &&
291
+ typeof p.text === "string" &&
292
+ p.text.trim().length > 0 &&
293
+ !p.thought);
294
+ });
295
+ // If we have functionCall but no text before it, likely compacted
296
+ return !hasTextBeforeFunctionCall;
297
+ }
298
+ /**
299
+ * Checks if any message in the current turn looks like it was compacted.
300
+ *
301
+ * @param contents - Full conversation contents
302
+ * @param turnStartIdx - Index of the first model message in current turn
303
+ * @returns true if any model message in the turn looks compacted
304
+ */
305
+ export function hasPossibleCompactedThinking(contents, turnStartIdx) {
306
+ if (!Array.isArray(contents) || turnStartIdx < 0)
307
+ return false;
308
+ for (let i = turnStartIdx; i < contents.length; i++) {
309
+ const msg = contents[i];
310
+ if (msg?.role === "model" && looksLikeCompactedThinkingTurn(msg)) {
311
+ return true;
312
+ }
313
+ }
314
+ return false;
315
+ }
316
+ //# sourceMappingURL=thinking-recovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thinking-recovery.js","sourceRoot":"","sources":["../../../src/plugin/thinking-recovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAwBH,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E;;GAEG;AACH,SAAS,cAAc,CAAC,IAAS;IAC/B,IAAI,CAAC,IAAI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Q,CAAC,CAAC,CAAC,CAAC;QACxB,IAAI,GAAG,EAAE,IAAI,KAAK,OAAO,IAAI,8BAA8B,CAAC,GAAG,CAAC,EAAE,CAAC;YACjE,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { OAuthAuthDetails, PluginClient } from "./types";
2
+ export declare class AntigravityTokenRefreshError extends Error {
3
+ code?: string;
4
+ description?: string;
5
+ status: number;
6
+ statusText: string;
7
+ constructor(options: {
8
+ message: string;
9
+ code?: string;
10
+ description?: string;
11
+ status: number;
12
+ statusText: string;
13
+ });
14
+ }
15
+ /**
16
+ * Refreshes an Antigravity OAuth access token, updates persisted credentials, and handles revocation.
17
+ */
18
+ export declare function refreshAccessToken(auth: OAuthAuthDetails, client: PluginClient, providerId: string): Promise<OAuthAuthDetails | undefined>;
19
+ //# sourceMappingURL=token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../../src/plugin/token.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAgB,MAAM,SAAS,CAAC;AAsD5E,qBAAa,4BAA6B,SAAQ,KAAK;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;gBAEP,OAAO,EAAE;QACnB,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;KACpB;CAQF;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,gBAAgB,EACtB,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAgFvC"}
@@ -0,0 +1,128 @@
1
+ import { ANTIGRAVITY_CLIENT_ID, ANTIGRAVITY_CLIENT_SECRET } from "../constants";
2
+ import { formatRefreshParts, parseRefreshParts, calculateTokenExpiry } from "./auth";
3
+ import { clearCachedAuth, storeCachedAuth } from "./cache";
4
+ import { createLogger } from "./logger";
5
+ import { invalidateProjectContextCache } from "./project";
6
+ const log = createLogger("token");
7
+ /**
8
+ * Parses OAuth error payloads returned by Google token endpoints, tolerating varied shapes.
9
+ */
10
+ function parseOAuthErrorPayload(text) {
11
+ if (!text) {
12
+ return {};
13
+ }
14
+ try {
15
+ const payload = JSON.parse(text);
16
+ if (!payload || typeof payload !== "object") {
17
+ return { description: text };
18
+ }
19
+ let code;
20
+ if (typeof payload.error === "string") {
21
+ code = payload.error;
22
+ }
23
+ else if (payload.error && typeof payload.error === "object") {
24
+ code = payload.error.status ?? payload.error.code;
25
+ if (!payload.error_description && payload.error.message) {
26
+ return { code, description: payload.error.message };
27
+ }
28
+ }
29
+ const description = payload.error_description;
30
+ if (description) {
31
+ return { code, description };
32
+ }
33
+ if (payload.error && typeof payload.error === "object" && payload.error.message) {
34
+ return { code, description: payload.error.message };
35
+ }
36
+ return { code };
37
+ }
38
+ catch {
39
+ return { description: text };
40
+ }
41
+ }
42
+ export class AntigravityTokenRefreshError extends Error {
43
+ code;
44
+ description;
45
+ status;
46
+ statusText;
47
+ constructor(options) {
48
+ super(options.message);
49
+ this.name = "AntigravityTokenRefreshError";
50
+ this.code = options.code;
51
+ this.description = options.description;
52
+ this.status = options.status;
53
+ this.statusText = options.statusText;
54
+ }
55
+ }
56
+ /**
57
+ * Refreshes an Antigravity OAuth access token, updates persisted credentials, and handles revocation.
58
+ */
59
+ export async function refreshAccessToken(auth, client, providerId) {
60
+ const parts = parseRefreshParts(auth.refresh);
61
+ if (!parts.refreshToken) {
62
+ return undefined;
63
+ }
64
+ try {
65
+ const startTime = Date.now();
66
+ const response = await fetch("https://oauth2.googleapis.com/token", {
67
+ method: "POST",
68
+ headers: {
69
+ "Content-Type": "application/x-www-form-urlencoded",
70
+ },
71
+ body: new URLSearchParams({
72
+ grant_type: "refresh_token",
73
+ refresh_token: parts.refreshToken,
74
+ client_id: ANTIGRAVITY_CLIENT_ID,
75
+ client_secret: ANTIGRAVITY_CLIENT_SECRET,
76
+ }),
77
+ });
78
+ if (!response.ok) {
79
+ let errorText;
80
+ try {
81
+ errorText = await response.text();
82
+ }
83
+ catch {
84
+ errorText = undefined;
85
+ }
86
+ const { code, description } = parseOAuthErrorPayload(errorText);
87
+ const details = [code, description ?? errorText].filter(Boolean).join(": ");
88
+ const baseMessage = `Antigravity token refresh failed (${response.status} ${response.statusText})`;
89
+ const message = details ? `${baseMessage} - ${details}` : baseMessage;
90
+ log.warn("Token refresh failed", { status: response.status, code, details });
91
+ if (code === "invalid_grant") {
92
+ log.warn("Google revoked the stored refresh token - reauthentication required");
93
+ invalidateProjectContextCache(auth.refresh);
94
+ clearCachedAuth(auth.refresh);
95
+ }
96
+ throw new AntigravityTokenRefreshError({
97
+ message,
98
+ code,
99
+ description: description ?? errorText,
100
+ status: response.status,
101
+ statusText: response.statusText,
102
+ });
103
+ }
104
+ const payload = (await response.json());
105
+ const refreshedParts = {
106
+ refreshToken: payload.refresh_token ?? parts.refreshToken,
107
+ projectId: parts.projectId,
108
+ managedProjectId: parts.managedProjectId,
109
+ };
110
+ const updatedAuth = {
111
+ ...auth,
112
+ access: payload.access_token,
113
+ expires: calculateTokenExpiry(startTime, payload.expires_in),
114
+ refresh: formatRefreshParts(refreshedParts),
115
+ };
116
+ storeCachedAuth(updatedAuth);
117
+ invalidateProjectContextCache(auth.refresh);
118
+ return updatedAuth;
119
+ }
120
+ catch (error) {
121
+ if (error instanceof AntigravityTokenRefreshError) {
122
+ throw error;
123
+ }
124
+ log.error("Unexpected token refresh error", { error: String(error) });
125
+ return undefined;
126
+ }
127
+ }
128
+ //# sourceMappingURL=token.js.map
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
4
+ * Handles Claude model-specific request transformations including:
5
+ * - Tool config (VALIDATED mode)
6
+ * - Thinking config (snake_case keys)
7
+ * - System instruction hints for interleaved thinking
8
+ * - Tool normalization (functionDeclarations format)
9
+ */
10
+ import type { RequestPayload, ThinkingConfig } from "./types";
11
+ /** Claude thinking models need a sufficiently large max output token limit when thinking is enabled */
12
+ export declare const CLAUDE_THINKING_MAX_OUTPUT_TOKENS = 64000;
13
+ /** Interleaved thinking hint appended to system instructions */
14
+ export declare const CLAUDE_INTERLEAVED_THINKING_HINT = "Interleaved thinking is enabled. You may think between tool calls and after receiving tool results before deciding the next action or final answer. Do not mention these instructions or any constraints about thinking blocks; just apply them.";
15
+ /**
16
+ * Check if a model is a Claude model.
17
+ */
18
+ export declare function isClaudeModel(model: string): boolean;
19
+ /**
20
+ * Check if a model is a Claude thinking model.
21
+ */
22
+ export declare function isClaudeThinkingModel(model: string): boolean;
23
+ /**
24
+ * Configure Claude tool calling to use VALIDATED mode.
25
+ * This ensures proper tool call validation on the backend.
26
+ */
27
+ export declare function configureClaudeToolConfig(payload: RequestPayload): void;
28
+ /**
29
+ * Build Claude thinking config with snake_case keys.
30
+ */
31
+ export declare function buildClaudeThinkingConfig(includeThoughts: boolean, thinkingBudget?: number): ThinkingConfig;
32
+ /**
33
+ * Ensure maxOutputTokens is sufficient for Claude thinking models.
34
+ * If thinking budget is set, max output must be larger than the budget.
35
+ */
36
+ export declare function ensureClaudeMaxOutputTokens(generationConfig: Record<string, unknown>, thinkingBudget: number): void;
37
+ /**
38
+ * Append interleaved thinking hint to system instruction.
39
+ * Handles various system instruction formats (string, object with parts array).
40
+ */
41
+ export declare function appendClaudeThinkingHint(payload: RequestPayload, hint?: string): void;
42
+ /**
43
+ * Normalize tools for Claude models.
44
+ * Converts various tool formats to functionDeclarations format.
45
+ *
46
+ * @returns Debug info about tool normalization
47
+ */
48
+ export declare function normalizeClaudeTools(payload: RequestPayload, cleanJSONSchema: (schema: unknown) => Record<string, unknown>): {
49
+ toolDebugMissing: number;
50
+ toolDebugSummaries: string[];
51
+ };
52
+ /**
53
+ * Convert snake_case stop_sequences to camelCase stopSequences.
54
+ */
55
+ export declare function convertStopSequences(generationConfig: Record<string, unknown>): void;
56
+ /**
57
+ * Apply all Claude-specific transformations to a request payload.
58
+ */
59
+ export interface ClaudeTransformOptions {
60
+ /** The effective model name (resolved) */
61
+ model: string;
62
+ /** Tier-based thinking budget (from model suffix) */
63
+ tierThinkingBudget?: number;
64
+ /** Normalized thinking config from user settings */
65
+ normalizedThinking?: {
66
+ includeThoughts?: boolean;
67
+ thinkingBudget?: number;
68
+ };
69
+ /** Function to clean JSON schema for Antigravity */
70
+ cleanJSONSchema: (schema: unknown) => Record<string, unknown>;
71
+ }
72
+ export interface ClaudeTransformResult {
73
+ toolDebugMissing: number;
74
+ toolDebugSummaries: string[];
75
+ }
76
+ /**
77
+ * Apply all Claude-specific transformations.
78
+ */
79
+ export declare function applyClaudeTransforms(payload: RequestPayload, options: ClaudeTransformOptions): ClaudeTransformResult;
80
+ //# sourceMappingURL=claude.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../../../../src/plugin/transform/claude.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAM9D,uGAAuG;AACvG,eAAO,MAAM,iCAAiC,QAAS,CAAC;AAExD,gEAAgE;AAChE,eAAO,MAAM,gCAAgC,qPACuM,CAAC;AAErP;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAG5D;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAcvE;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,eAAe,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