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.
Files changed (258) hide show
  1. package/README.md +79 -41
  2. package/dist/cli.js +2868 -0
  3. package/dist/handler.js +25119 -0
  4. package/dist/index.js +25110 -5
  5. package/package.json +66 -54
  6. package/dist/antigravity/oauth.d.ts +0 -30
  7. package/dist/antigravity/oauth.js +0 -170
  8. package/dist/claude/login.d.ts +0 -7
  9. package/dist/claude/login.js +0 -480
  10. package/dist/claude/menu-helpers.d.ts +0 -22
  11. package/dist/claude/menu-helpers.js +0 -281
  12. package/dist/claude/proxy-manager.d.ts +0 -11
  13. package/dist/claude/proxy-manager.js +0 -129
  14. package/dist/claude/proxy.d.ts +0 -1
  15. package/dist/claude/proxy.js +0 -733
  16. package/dist/constants.d.ts +0 -138
  17. package/dist/constants.js +0 -216
  18. package/dist/hooks/auto-update-checker/cache.d.ts +0 -2
  19. package/dist/hooks/auto-update-checker/cache.js +0 -70
  20. package/dist/hooks/auto-update-checker/checker.d.ts +0 -15
  21. package/dist/hooks/auto-update-checker/checker.js +0 -233
  22. package/dist/hooks/auto-update-checker/constants.d.ts +0 -8
  23. package/dist/hooks/auto-update-checker/constants.js +0 -22
  24. package/dist/hooks/auto-update-checker/index.d.ts +0 -33
  25. package/dist/hooks/auto-update-checker/index.js +0 -121
  26. package/dist/hooks/auto-update-checker/logging.d.ts +0 -2
  27. package/dist/hooks/auto-update-checker/logging.js +0 -8
  28. package/dist/hooks/auto-update-checker/types.d.ts +0 -24
  29. package/dist/hooks/auto-update-checker/types.js +0 -1
  30. package/dist/index.d.ts +0 -6
  31. package/dist/opencode/hooks/auto-update-checker/cache.d.ts +0 -2
  32. package/dist/opencode/hooks/auto-update-checker/cache.js +0 -70
  33. package/dist/opencode/hooks/auto-update-checker/checker.d.ts +0 -15
  34. package/dist/opencode/hooks/auto-update-checker/checker.js +0 -233
  35. package/dist/opencode/hooks/auto-update-checker/constants.d.ts +0 -8
  36. package/dist/opencode/hooks/auto-update-checker/constants.js +0 -22
  37. package/dist/opencode/hooks/auto-update-checker/index.d.ts +0 -33
  38. package/dist/opencode/hooks/auto-update-checker/index.js +0 -121
  39. package/dist/opencode/hooks/auto-update-checker/logging.d.ts +0 -2
  40. package/dist/opencode/hooks/auto-update-checker/logging.js +0 -8
  41. package/dist/opencode/hooks/auto-update-checker/types.d.ts +0 -24
  42. package/dist/opencode/hooks/auto-update-checker/types.js +0 -1
  43. package/dist/opencode/plugin.d.ts +0 -29
  44. package/dist/opencode/plugin.js +0 -2954
  45. package/dist/plugin/accounts.d.ts +0 -173
  46. package/dist/plugin/accounts.js +0 -966
  47. package/dist/plugin/auth.d.ts +0 -20
  48. package/dist/plugin/auth.js +0 -44
  49. package/dist/plugin/cache/index.d.ts +0 -4
  50. package/dist/plugin/cache/index.js +0 -4
  51. package/dist/plugin/cache/signature-cache.d.ts +0 -110
  52. package/dist/plugin/cache/signature-cache.js +0 -347
  53. package/dist/plugin/cache.d.ts +0 -43
  54. package/dist/plugin/cache.js +0 -180
  55. package/dist/plugin/cli.d.ts +0 -26
  56. package/dist/plugin/cli.js +0 -126
  57. package/dist/plugin/config/index.d.ts +0 -15
  58. package/dist/plugin/config/index.js +0 -15
  59. package/dist/plugin/config/loader.d.ts +0 -38
  60. package/dist/plugin/config/loader.js +0 -150
  61. package/dist/plugin/config/models.d.ts +0 -26
  62. package/dist/plugin/config/models.js +0 -95
  63. package/dist/plugin/config/schema.d.ts +0 -144
  64. package/dist/plugin/config/schema.js +0 -458
  65. package/dist/plugin/config/updater.d.ts +0 -76
  66. package/dist/plugin/config/updater.js +0 -205
  67. package/dist/plugin/core/streaming/index.d.ts +0 -2
  68. package/dist/plugin/core/streaming/index.js +0 -2
  69. package/dist/plugin/core/streaming/transformer.d.ts +0 -9
  70. package/dist/plugin/core/streaming/transformer.js +0 -301
  71. package/dist/plugin/core/streaming/types.d.ts +0 -28
  72. package/dist/plugin/core/streaming/types.js +0 -1
  73. package/dist/plugin/debug.d.ts +0 -93
  74. package/dist/plugin/debug.js +0 -375
  75. package/dist/plugin/errors.d.ts +0 -27
  76. package/dist/plugin/errors.js +0 -41
  77. package/dist/plugin/fingerprint.d.ts +0 -69
  78. package/dist/plugin/fingerprint.js +0 -137
  79. package/dist/plugin/image-saver.d.ts +0 -24
  80. package/dist/plugin/image-saver.js +0 -78
  81. package/dist/plugin/logger.d.ts +0 -35
  82. package/dist/plugin/logger.js +0 -67
  83. package/dist/plugin/logging-utils.d.ts +0 -22
  84. package/dist/plugin/logging-utils.js +0 -91
  85. package/dist/plugin/project.d.ts +0 -32
  86. package/dist/plugin/project.js +0 -229
  87. package/dist/plugin/quota.d.ts +0 -34
  88. package/dist/plugin/quota.js +0 -261
  89. package/dist/plugin/recovery/constants.d.ts +0 -21
  90. package/dist/plugin/recovery/constants.js +0 -42
  91. package/dist/plugin/recovery/index.d.ts +0 -11
  92. package/dist/plugin/recovery/index.js +0 -11
  93. package/dist/plugin/recovery/storage.d.ts +0 -23
  94. package/dist/plugin/recovery/storage.js +0 -340
  95. package/dist/plugin/recovery/types.d.ts +0 -115
  96. package/dist/plugin/recovery/types.js +0 -6
  97. package/dist/plugin/recovery.d.ts +0 -60
  98. package/dist/plugin/recovery.js +0 -360
  99. package/dist/plugin/refresh-queue.d.ts +0 -99
  100. package/dist/plugin/refresh-queue.js +0 -235
  101. package/dist/plugin/request-helpers.d.ts +0 -281
  102. package/dist/plugin/request-helpers.js +0 -2200
  103. package/dist/plugin/request.d.ts +0 -110
  104. package/dist/plugin/request.js +0 -1489
  105. package/dist/plugin/rotation.d.ts +0 -182
  106. package/dist/plugin/rotation.js +0 -364
  107. package/dist/plugin/search.d.ts +0 -31
  108. package/dist/plugin/search.js +0 -185
  109. package/dist/plugin/server.d.ts +0 -22
  110. package/dist/plugin/server.js +0 -306
  111. package/dist/plugin/storage.d.ts +0 -136
  112. package/dist/plugin/storage.js +0 -599
  113. package/dist/plugin/stores/signature-store.d.ts +0 -4
  114. package/dist/plugin/stores/signature-store.js +0 -24
  115. package/dist/plugin/thinking-recovery.d.ts +0 -89
  116. package/dist/plugin/thinking-recovery.js +0 -289
  117. package/dist/plugin/token.d.ts +0 -18
  118. package/dist/plugin/token.js +0 -127
  119. package/dist/plugin/transform/claude.d.ts +0 -79
  120. package/dist/plugin/transform/claude.js +0 -256
  121. package/dist/plugin/transform/cross-model-sanitizer.d.ts +0 -34
  122. package/dist/plugin/transform/cross-model-sanitizer.js +0 -224
  123. package/dist/plugin/transform/gemini.d.ts +0 -132
  124. package/dist/plugin/transform/gemini.js +0 -659
  125. package/dist/plugin/transform/index.d.ts +0 -14
  126. package/dist/plugin/transform/index.js +0 -9
  127. package/dist/plugin/transform/model-resolver.d.ts +0 -98
  128. package/dist/plugin/transform/model-resolver.js +0 -320
  129. package/dist/plugin/transform/types.d.ts +0 -110
  130. package/dist/plugin/transform/types.js +0 -1
  131. package/dist/plugin/types.d.ts +0 -95
  132. package/dist/plugin/types.js +0 -1
  133. package/dist/plugin/ui/ansi.d.ts +0 -31
  134. package/dist/plugin/ui/ansi.js +0 -45
  135. package/dist/plugin/ui/auth-menu.d.ts +0 -47
  136. package/dist/plugin/ui/auth-menu.js +0 -199
  137. package/dist/plugin/ui/confirm.d.ts +0 -1
  138. package/dist/plugin/ui/confirm.js +0 -14
  139. package/dist/plugin/ui/select.d.ts +0 -22
  140. package/dist/plugin/ui/select.js +0 -243
  141. package/dist/plugin/version.d.ts +0 -18
  142. package/dist/plugin/version.js +0 -79
  143. package/dist/src/antigravity/oauth.d.ts +0 -30
  144. package/dist/src/antigravity/oauth.js +0 -170
  145. package/dist/src/constants.d.ts +0 -138
  146. package/dist/src/constants.js +0 -216
  147. package/dist/src/hooks/auto-update-checker/cache.d.ts +0 -2
  148. package/dist/src/hooks/auto-update-checker/cache.js +0 -70
  149. package/dist/src/hooks/auto-update-checker/checker.d.ts +0 -15
  150. package/dist/src/hooks/auto-update-checker/checker.js +0 -233
  151. package/dist/src/hooks/auto-update-checker/constants.d.ts +0 -8
  152. package/dist/src/hooks/auto-update-checker/constants.js +0 -22
  153. package/dist/src/hooks/auto-update-checker/index.d.ts +0 -33
  154. package/dist/src/hooks/auto-update-checker/index.js +0 -121
  155. package/dist/src/hooks/auto-update-checker/logging.d.ts +0 -2
  156. package/dist/src/hooks/auto-update-checker/logging.js +0 -8
  157. package/dist/src/hooks/auto-update-checker/types.d.ts +0 -24
  158. package/dist/src/hooks/auto-update-checker/types.js +0 -1
  159. package/dist/src/index.d.ts +0 -6
  160. package/dist/src/index.js +0 -5
  161. package/dist/src/plugin/accounts.d.ts +0 -173
  162. package/dist/src/plugin/accounts.js +0 -966
  163. package/dist/src/plugin/auth.d.ts +0 -20
  164. package/dist/src/plugin/auth.js +0 -44
  165. package/dist/src/plugin/cache/index.d.ts +0 -4
  166. package/dist/src/plugin/cache/index.js +0 -4
  167. package/dist/src/plugin/cache/signature-cache.d.ts +0 -110
  168. package/dist/src/plugin/cache/signature-cache.js +0 -347
  169. package/dist/src/plugin/cache.d.ts +0 -43
  170. package/dist/src/plugin/cache.js +0 -180
  171. package/dist/src/plugin/cli.d.ts +0 -26
  172. package/dist/src/plugin/cli.js +0 -126
  173. package/dist/src/plugin/config/index.d.ts +0 -15
  174. package/dist/src/plugin/config/index.js +0 -15
  175. package/dist/src/plugin/config/loader.d.ts +0 -38
  176. package/dist/src/plugin/config/loader.js +0 -150
  177. package/dist/src/plugin/config/models.d.ts +0 -26
  178. package/dist/src/plugin/config/models.js +0 -95
  179. package/dist/src/plugin/config/schema.d.ts +0 -144
  180. package/dist/src/plugin/config/schema.js +0 -458
  181. package/dist/src/plugin/config/updater.d.ts +0 -76
  182. package/dist/src/plugin/config/updater.js +0 -205
  183. package/dist/src/plugin/core/streaming/index.d.ts +0 -2
  184. package/dist/src/plugin/core/streaming/index.js +0 -2
  185. package/dist/src/plugin/core/streaming/transformer.d.ts +0 -9
  186. package/dist/src/plugin/core/streaming/transformer.js +0 -301
  187. package/dist/src/plugin/core/streaming/types.d.ts +0 -28
  188. package/dist/src/plugin/core/streaming/types.js +0 -1
  189. package/dist/src/plugin/debug.d.ts +0 -93
  190. package/dist/src/plugin/debug.js +0 -375
  191. package/dist/src/plugin/errors.d.ts +0 -27
  192. package/dist/src/plugin/errors.js +0 -41
  193. package/dist/src/plugin/fingerprint.d.ts +0 -69
  194. package/dist/src/plugin/fingerprint.js +0 -137
  195. package/dist/src/plugin/image-saver.d.ts +0 -24
  196. package/dist/src/plugin/image-saver.js +0 -78
  197. package/dist/src/plugin/logger.d.ts +0 -35
  198. package/dist/src/plugin/logger.js +0 -67
  199. package/dist/src/plugin/logging-utils.d.ts +0 -22
  200. package/dist/src/plugin/logging-utils.js +0 -91
  201. package/dist/src/plugin/project.d.ts +0 -32
  202. package/dist/src/plugin/project.js +0 -229
  203. package/dist/src/plugin/quota.d.ts +0 -34
  204. package/dist/src/plugin/quota.js +0 -261
  205. package/dist/src/plugin/recovery/constants.d.ts +0 -21
  206. package/dist/src/plugin/recovery/constants.js +0 -42
  207. package/dist/src/plugin/recovery/index.d.ts +0 -11
  208. package/dist/src/plugin/recovery/index.js +0 -11
  209. package/dist/src/plugin/recovery/storage.d.ts +0 -23
  210. package/dist/src/plugin/recovery/storage.js +0 -340
  211. package/dist/src/plugin/recovery/types.d.ts +0 -115
  212. package/dist/src/plugin/recovery/types.js +0 -6
  213. package/dist/src/plugin/recovery.d.ts +0 -60
  214. package/dist/src/plugin/recovery.js +0 -360
  215. package/dist/src/plugin/refresh-queue.d.ts +0 -99
  216. package/dist/src/plugin/refresh-queue.js +0 -235
  217. package/dist/src/plugin/request-helpers.d.ts +0 -281
  218. package/dist/src/plugin/request-helpers.js +0 -2200
  219. package/dist/src/plugin/request.d.ts +0 -110
  220. package/dist/src/plugin/request.js +0 -1489
  221. package/dist/src/plugin/rotation.d.ts +0 -182
  222. package/dist/src/plugin/rotation.js +0 -364
  223. package/dist/src/plugin/search.d.ts +0 -31
  224. package/dist/src/plugin/search.js +0 -185
  225. package/dist/src/plugin/server.d.ts +0 -22
  226. package/dist/src/plugin/server.js +0 -306
  227. package/dist/src/plugin/storage.d.ts +0 -136
  228. package/dist/src/plugin/storage.js +0 -599
  229. package/dist/src/plugin/stores/signature-store.d.ts +0 -4
  230. package/dist/src/plugin/stores/signature-store.js +0 -24
  231. package/dist/src/plugin/thinking-recovery.d.ts +0 -89
  232. package/dist/src/plugin/thinking-recovery.js +0 -289
  233. package/dist/src/plugin/token.d.ts +0 -18
  234. package/dist/src/plugin/token.js +0 -127
  235. package/dist/src/plugin/transform/claude.d.ts +0 -79
  236. package/dist/src/plugin/transform/claude.js +0 -256
  237. package/dist/src/plugin/transform/cross-model-sanitizer.d.ts +0 -34
  238. package/dist/src/plugin/transform/cross-model-sanitizer.js +0 -224
  239. package/dist/src/plugin/transform/gemini.d.ts +0 -132
  240. package/dist/src/plugin/transform/gemini.js +0 -659
  241. package/dist/src/plugin/transform/index.d.ts +0 -14
  242. package/dist/src/plugin/transform/index.js +0 -9
  243. package/dist/src/plugin/transform/model-resolver.d.ts +0 -98
  244. package/dist/src/plugin/transform/model-resolver.js +0 -320
  245. package/dist/src/plugin/transform/types.d.ts +0 -110
  246. package/dist/src/plugin/transform/types.js +0 -1
  247. package/dist/src/plugin/types.d.ts +0 -95
  248. package/dist/src/plugin/types.js +0 -1
  249. package/dist/src/plugin/ui/ansi.d.ts +0 -31
  250. package/dist/src/plugin/ui/ansi.js +0 -45
  251. package/dist/src/plugin/ui/auth-menu.d.ts +0 -47
  252. package/dist/src/plugin/ui/auth-menu.js +0 -199
  253. package/dist/src/plugin/ui/confirm.d.ts +0 -1
  254. package/dist/src/plugin/ui/confirm.js +0 -14
  255. package/dist/src/plugin/ui/select.d.ts +0 -22
  256. package/dist/src/plugin/ui/select.js +0 -243
  257. package/dist/src/plugin/version.d.ts +0 -18
  258. package/dist/src/plugin/version.js +0 -79
@@ -1,89 +0,0 @@
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
- * Conversation state for thinking mode analysis
13
- */
14
- export interface ConversationState {
15
- /** True if we're in an incomplete tool use loop (ends with functionResponse) */
16
- inToolLoop: boolean;
17
- /** Index of first model message in current turn */
18
- turnStartIdx: number;
19
- /** Whether the TURN started with thinking */
20
- turnHasThinking: boolean;
21
- /** Index of last model message */
22
- lastModelIdx: number;
23
- /** Whether last model msg has thinking */
24
- lastModelHasThinking: boolean;
25
- /** Whether last model msg has tool calls */
26
- lastModelHasToolCalls: boolean;
27
- }
28
- /**
29
- * Analyzes conversation state to detect tool use loops and thinking mode issues.
30
- *
31
- * Key insight: A "turn" can span multiple assistant messages in a tool-use loop.
32
- * We need to find the TURN START (first assistant message after last real user message)
33
- * and check if THAT message had thinking, not just the last assistant message.
34
- */
35
- export declare function analyzeConversationState(contents: any[]): ConversationState;
36
- /**
37
- * Closes an incomplete tool loop by injecting synthetic messages to start a new turn.
38
- *
39
- * This is the "let it crash and start again" recovery mechanism.
40
- *
41
- * When we detect:
42
- * - We're in a tool loop (conversation ends with functionResponse)
43
- * - The tool call was made WITHOUT thinking (thinking was stripped/corrupted)
44
- * - We NOW want to enable thinking
45
- *
46
- * Instead of trying to fix the corrupted state, we:
47
- * 1. Strip ALL thinking blocks (removes any corrupted ones)
48
- * 2. Add synthetic MODEL message to complete the non-thinking turn
49
- * 3. Add synthetic USER message to start a NEW turn
50
- *
51
- * This allows Claude to generate fresh thinking for the new turn.
52
- */
53
- export declare function closeToolLoopForThinking(contents: any[]): any[];
54
- /**
55
- * Checks if conversation state requires tool loop closure for thinking recovery.
56
- *
57
- * Returns true if:
58
- * - We're in a tool loop (state.inToolLoop)
59
- * - The turn didn't start with thinking (state.turnHasThinking === false)
60
- *
61
- * This is the trigger for the "let it crash and start again" recovery.
62
- */
63
- export declare function needsThinkingRecovery(state: ConversationState): boolean;
64
- /**
65
- * Detects if a message looks like it was compacted from a thinking-enabled turn.
66
- *
67
- * This is a heuristic to distinguish between:
68
- * - "Never had thinking" (model didn't use thinking mode)
69
- * - "Thinking was stripped" (context compaction removed thinking blocks)
70
- *
71
- * Port of LLM-API-Key-Proxy's _looks_like_compacted_thinking_turn()
72
- *
73
- * Heuristics:
74
- * 1. Has functionCall parts (typical thinking flow produces tool calls)
75
- * 2. No thinking parts (thought: true)
76
- * 3. No text content before functionCall (thinking responses usually have text)
77
- *
78
- * @param msg - A single message from the conversation
79
- * @returns true if the message looks like thinking was stripped
80
- */
81
- export declare function looksLikeCompactedThinkingTurn(msg: any): boolean;
82
- /**
83
- * Checks if any message in the current turn looks like it was compacted.
84
- *
85
- * @param contents - Full conversation contents
86
- * @param turnStartIdx - Index of the first model message in current turn
87
- * @returns true if any model message in the turn looks compacted
88
- */
89
- export declare function hasPossibleCompactedThinking(contents: any[], turnStartIdx: number): boolean;
@@ -1,289 +0,0 @@
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
- // ============================================================================
13
- /**
14
- * Checks if a message part is a thinking/reasoning block.
15
- */
16
- function isThinkingPart(part) {
17
- if (!part || typeof part !== "object")
18
- return false;
19
- return (part.thought === true ||
20
- part.type === "thinking" ||
21
- part.type === "redacted_thinking");
22
- }
23
- /**
24
- * Checks if a message part is a function response (tool result).
25
- */
26
- function isFunctionResponsePart(part) {
27
- return part && typeof part === "object" && "functionResponse" in part;
28
- }
29
- /**
30
- * Checks if a message part is a function call.
31
- */
32
- function isFunctionCallPart(part) {
33
- return part && typeof part === "object" && "functionCall" in part;
34
- }
35
- /**
36
- * Checks if a message is a tool result container (user role with functionResponse).
37
- */
38
- function isToolResultMessage(msg) {
39
- if (!msg || msg.role !== "user")
40
- return false;
41
- const parts = msg.parts || [];
42
- return parts.some(isFunctionResponsePart);
43
- }
44
- /**
45
- * Checks if a message contains thinking/reasoning content.
46
- */
47
- function messageHasThinking(msg) {
48
- if (!msg || typeof msg !== "object")
49
- return false;
50
- if (Array.isArray(msg.parts)) {
51
- return msg.parts.some(isThinkingPart);
52
- }
53
- if (Array.isArray(msg.content)) {
54
- return msg.content.some((block) => block?.type === "thinking" || block?.type === "redacted_thinking");
55
- }
56
- return false;
57
- }
58
- /**
59
- * Checks if a message contains tool calls.
60
- */
61
- function messageHasToolCalls(msg) {
62
- if (!msg || typeof msg !== "object")
63
- return false;
64
- if (Array.isArray(msg.parts)) {
65
- return msg.parts.some(isFunctionCallPart);
66
- }
67
- // Anthropic format: content array with tool_use
68
- if (Array.isArray(msg.content)) {
69
- return msg.content.some((block) => block?.type === "tool_use");
70
- }
71
- return false;
72
- }
73
- // ============================================================================
74
- // ============================================================================
75
- /**
76
- * Analyzes conversation state to detect tool use loops and thinking mode issues.
77
- *
78
- * Key insight: A "turn" can span multiple assistant messages in a tool-use loop.
79
- * We need to find the TURN START (first assistant message after last real user message)
80
- * and check if THAT message had thinking, not just the last assistant message.
81
- */
82
- export function analyzeConversationState(contents) {
83
- const state = {
84
- inToolLoop: false,
85
- turnStartIdx: -1,
86
- turnHasThinking: false,
87
- lastModelIdx: -1,
88
- lastModelHasThinking: false,
89
- lastModelHasToolCalls: false,
90
- };
91
- if (!Array.isArray(contents) || contents.length === 0) {
92
- return state;
93
- }
94
- let lastRealUserIdx = -1;
95
- for (let i = 0; i < contents.length; i++) {
96
- const msg = contents[i];
97
- if (msg?.role === "user" && !isToolResultMessage(msg)) {
98
- lastRealUserIdx = i;
99
- }
100
- }
101
- for (let i = 0; i < contents.length; i++) {
102
- const msg = contents[i];
103
- const role = msg?.role;
104
- if (role === "model" || role === "assistant") {
105
- const hasThinking = messageHasThinking(msg);
106
- const hasToolCalls = messageHasToolCalls(msg);
107
- if (i > lastRealUserIdx && state.turnStartIdx === -1) {
108
- state.turnStartIdx = i;
109
- state.turnHasThinking = hasThinking;
110
- }
111
- state.lastModelIdx = i;
112
- state.lastModelHasToolCalls = hasToolCalls;
113
- state.lastModelHasThinking = hasThinking;
114
- }
115
- }
116
- if (contents.length > 0) {
117
- const lastMsg = contents[contents.length - 1];
118
- if (lastMsg?.role === "user" && isToolResultMessage(lastMsg)) {
119
- state.inToolLoop = true;
120
- }
121
- }
122
- return state;
123
- }
124
- // ============================================================================
125
- // ============================================================================
126
- /**
127
- * Strips all thinking blocks from messages.
128
- * Used before injecting synthetic messages to avoid invalid thinking patterns.
129
- */
130
- function stripAllThinkingBlocks(contents) {
131
- return contents.map((content) => {
132
- if (!content || typeof content !== "object")
133
- return content;
134
- if (Array.isArray(content.parts)) {
135
- const filteredParts = content.parts.filter((part) => !isThinkingPart(part));
136
- if (filteredParts.length === 0 && content.parts.length > 0) {
137
- return content;
138
- }
139
- return { ...content, parts: filteredParts };
140
- }
141
- if (Array.isArray(content.content)) {
142
- const filteredContent = content.content.filter((block) => block?.type !== "thinking" && block?.type !== "redacted_thinking");
143
- if (filteredContent.length === 0 && content.content.length > 0) {
144
- return content;
145
- }
146
- return { ...content, content: filteredContent };
147
- }
148
- return content;
149
- });
150
- }
151
- /**
152
- * Counts tool results at the end of the conversation.
153
- */
154
- function countTrailingToolResults(contents) {
155
- let count = 0;
156
- for (let i = contents.length - 1; i >= 0; i--) {
157
- const msg = contents[i];
158
- if (msg?.role === "user") {
159
- const parts = msg.parts || [];
160
- const functionResponses = parts.filter(isFunctionResponsePart);
161
- if (functionResponses.length > 0) {
162
- count += functionResponses.length;
163
- }
164
- else {
165
- break; // Real user message, stop counting
166
- }
167
- }
168
- else if (msg?.role === "model" || msg?.role === "assistant") {
169
- break; // Stop at the model that made the tool calls
170
- }
171
- }
172
- return count;
173
- }
174
- /**
175
- * Closes an incomplete tool loop by injecting synthetic messages to start a new turn.
176
- *
177
- * This is the "let it crash and start again" recovery mechanism.
178
- *
179
- * When we detect:
180
- * - We're in a tool loop (conversation ends with functionResponse)
181
- * - The tool call was made WITHOUT thinking (thinking was stripped/corrupted)
182
- * - We NOW want to enable thinking
183
- *
184
- * Instead of trying to fix the corrupted state, we:
185
- * 1. Strip ALL thinking blocks (removes any corrupted ones)
186
- * 2. Add synthetic MODEL message to complete the non-thinking turn
187
- * 3. Add synthetic USER message to start a NEW turn
188
- *
189
- * This allows Claude to generate fresh thinking for the new turn.
190
- */
191
- export function closeToolLoopForThinking(contents) {
192
- const strippedContents = stripAllThinkingBlocks(contents);
193
- const toolResultCount = countTrailingToolResults(strippedContents);
194
- let syntheticModelContent;
195
- if (toolResultCount === 0) {
196
- syntheticModelContent = "[Processing previous context.]";
197
- }
198
- else if (toolResultCount === 1) {
199
- syntheticModelContent = "[Tool execution completed.]";
200
- }
201
- else {
202
- syntheticModelContent = `[${toolResultCount} tool executions completed.]`;
203
- }
204
- const syntheticModel = {
205
- role: "model",
206
- parts: [{ text: syntheticModelContent }],
207
- };
208
- const syntheticUser = {
209
- role: "user",
210
- parts: [{ text: "[Continue]" }],
211
- };
212
- return [...strippedContents, syntheticModel, syntheticUser];
213
- }
214
- /**
215
- * Checks if conversation state requires tool loop closure for thinking recovery.
216
- *
217
- * Returns true if:
218
- * - We're in a tool loop (state.inToolLoop)
219
- * - The turn didn't start with thinking (state.turnHasThinking === false)
220
- *
221
- * This is the trigger for the "let it crash and start again" recovery.
222
- */
223
- export function needsThinkingRecovery(state) {
224
- return state.inToolLoop && !state.turnHasThinking;
225
- }
226
- // ============================================================================
227
- // ============================================================================
228
- /**
229
- * Detects if a message looks like it was compacted from a thinking-enabled turn.
230
- *
231
- * This is a heuristic to distinguish between:
232
- * - "Never had thinking" (model didn't use thinking mode)
233
- * - "Thinking was stripped" (context compaction removed thinking blocks)
234
- *
235
- * Port of LLM-API-Key-Proxy's _looks_like_compacted_thinking_turn()
236
- *
237
- * Heuristics:
238
- * 1. Has functionCall parts (typical thinking flow produces tool calls)
239
- * 2. No thinking parts (thought: true)
240
- * 3. No text content before functionCall (thinking responses usually have text)
241
- *
242
- * @param msg - A single message from the conversation
243
- * @returns true if the message looks like thinking was stripped
244
- */
245
- export function looksLikeCompactedThinkingTurn(msg) {
246
- if (!msg || typeof msg !== "object")
247
- return false;
248
- const parts = msg.parts || [];
249
- if (parts.length === 0)
250
- return false;
251
- const hasFunctionCall = parts.some((p) => p && typeof p === "object" && p.functionCall);
252
- if (!hasFunctionCall)
253
- return false;
254
- const hasThinking = parts.some((p) => p &&
255
- typeof p === "object" &&
256
- (p.thought === true || p.type === "thinking" || p.type === "redacted_thinking"));
257
- if (hasThinking)
258
- return false;
259
- const hasTextBeforeFunctionCall = parts.some((p, idx) => {
260
- if (!p || typeof p !== "object")
261
- return false;
262
- const firstFuncIdx = parts.findIndex((fp) => fp && typeof fp === "object" && fp.functionCall);
263
- if (idx >= firstFuncIdx)
264
- return false;
265
- return ("text" in p &&
266
- typeof p.text === "string" &&
267
- p.text.trim().length > 0 &&
268
- !p.thought);
269
- });
270
- return !hasTextBeforeFunctionCall;
271
- }
272
- /**
273
- * Checks if any message in the current turn looks like it was compacted.
274
- *
275
- * @param contents - Full conversation contents
276
- * @param turnStartIdx - Index of the first model message in current turn
277
- * @returns true if any model message in the turn looks compacted
278
- */
279
- export function hasPossibleCompactedThinking(contents, turnStartIdx) {
280
- if (!Array.isArray(contents) || turnStartIdx < 0)
281
- return false;
282
- for (let i = turnStartIdx; i < contents.length; i++) {
283
- const msg = contents[i];
284
- if (msg?.role === "model" && looksLikeCompactedThinkingTurn(msg)) {
285
- return true;
286
- }
287
- }
288
- return false;
289
- }
@@ -1,18 +0,0 @@
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>;
@@ -1,127 +0,0 @@
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
- }
@@ -1,79 +0,0 @@
1
- /**
2
- * Claude-specific Request Transformations
3
- *
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;