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,340 +0,0 @@
1
- /**
2
- * Storage utilities for reading OpenCode's session data.
3
- *
4
- * Based on oh-my-opencode/src/hooks/session-recovery/storage.ts
5
- */
6
- import { existsSync, mkdirSync, readdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
7
- import { join } from "node:path";
8
- import { MESSAGE_STORAGE, PART_STORAGE, THINKING_TYPES, META_TYPES } from "./constants";
9
- // =============================================================================
10
- // =============================================================================
11
- export function generatePartId() {
12
- const timestamp = Date.now().toString(16);
13
- const random = Math.random().toString(36).substring(2, 10);
14
- return `prt_${timestamp}${random}`;
15
- }
16
- // =============================================================================
17
- // =============================================================================
18
- export function getMessageDir(sessionID) {
19
- if (!existsSync(MESSAGE_STORAGE))
20
- return "";
21
- const directPath = join(MESSAGE_STORAGE, sessionID);
22
- if (existsSync(directPath)) {
23
- return directPath;
24
- }
25
- try {
26
- for (const dir of readdirSync(MESSAGE_STORAGE)) {
27
- const sessionPath = join(MESSAGE_STORAGE, dir, sessionID);
28
- if (existsSync(sessionPath)) {
29
- return sessionPath;
30
- }
31
- }
32
- }
33
- catch {
34
- }
35
- return "";
36
- }
37
- // =============================================================================
38
- // =============================================================================
39
- export function readMessages(sessionID) {
40
- const messageDir = getMessageDir(sessionID);
41
- if (!messageDir || !existsSync(messageDir))
42
- return [];
43
- const messages = [];
44
- try {
45
- for (const file of readdirSync(messageDir)) {
46
- if (!file.endsWith(".json"))
47
- continue;
48
- try {
49
- const content = readFileSync(join(messageDir, file), "utf-8");
50
- messages.push(JSON.parse(content));
51
- }
52
- catch {
53
- continue;
54
- }
55
- }
56
- }
57
- catch {
58
- return [];
59
- }
60
- return messages.sort((a, b) => {
61
- const aTime = a.time?.created ?? 0;
62
- const bTime = b.time?.created ?? 0;
63
- if (aTime !== bTime)
64
- return aTime - bTime;
65
- return a.id.localeCompare(b.id);
66
- });
67
- }
68
- // =============================================================================
69
- // =============================================================================
70
- export function readParts(messageID) {
71
- const partDir = join(PART_STORAGE, messageID);
72
- if (!existsSync(partDir))
73
- return [];
74
- const parts = [];
75
- try {
76
- for (const file of readdirSync(partDir)) {
77
- if (!file.endsWith(".json"))
78
- continue;
79
- try {
80
- const content = readFileSync(join(partDir, file), "utf-8");
81
- parts.push(JSON.parse(content));
82
- }
83
- catch {
84
- continue;
85
- }
86
- }
87
- }
88
- catch {
89
- return [];
90
- }
91
- return parts;
92
- }
93
- // =============================================================================
94
- // =============================================================================
95
- export function hasContent(part) {
96
- if (THINKING_TYPES.has(part.type))
97
- return false;
98
- if (META_TYPES.has(part.type))
99
- return false;
100
- if (part.type === "text") {
101
- const textPart = part;
102
- return !!(textPart.text?.trim());
103
- }
104
- if (part.type === "tool" || part.type === "tool_use") {
105
- return true;
106
- }
107
- if (part.type === "tool_result") {
108
- return true;
109
- }
110
- return false;
111
- }
112
- export function messageHasContent(messageID) {
113
- const parts = readParts(messageID);
114
- return parts.some(hasContent);
115
- }
116
- // =============================================================================
117
- // =============================================================================
118
- export function injectTextPart(sessionID, messageID, text) {
119
- const partDir = join(PART_STORAGE, messageID);
120
- try {
121
- if (!existsSync(partDir)) {
122
- mkdirSync(partDir, { recursive: true });
123
- }
124
- const partId = generatePartId();
125
- const part = {
126
- id: partId,
127
- sessionID,
128
- messageID,
129
- type: "text",
130
- text,
131
- synthetic: true,
132
- };
133
- writeFileSync(join(partDir, `${partId}.json`), JSON.stringify(part, null, 2));
134
- return true;
135
- }
136
- catch {
137
- return false;
138
- }
139
- }
140
- // =============================================================================
141
- // =============================================================================
142
- export function findMessagesWithThinkingBlocks(sessionID) {
143
- const messages = readMessages(sessionID);
144
- const result = [];
145
- for (const msg of messages) {
146
- if (msg.role !== "assistant")
147
- continue;
148
- const parts = readParts(msg.id);
149
- const hasThinking = parts.some((p) => THINKING_TYPES.has(p.type));
150
- if (hasThinking) {
151
- result.push(msg.id);
152
- }
153
- }
154
- return result;
155
- }
156
- export function findMessagesWithThinkingOnly(sessionID) {
157
- const messages = readMessages(sessionID);
158
- const result = [];
159
- for (const msg of messages) {
160
- if (msg.role !== "assistant")
161
- continue;
162
- const parts = readParts(msg.id);
163
- if (parts.length === 0)
164
- continue;
165
- const hasThinking = parts.some((p) => THINKING_TYPES.has(p.type));
166
- const hasTextContent = parts.some(hasContent);
167
- if (hasThinking && !hasTextContent) {
168
- result.push(msg.id);
169
- }
170
- }
171
- return result;
172
- }
173
- export function findMessagesWithOrphanThinking(sessionID) {
174
- const messages = readMessages(sessionID);
175
- const result = [];
176
- for (let i = 0; i < messages.length; i++) {
177
- const msg = messages[i];
178
- if (!msg || msg.role !== "assistant")
179
- continue;
180
- const parts = readParts(msg.id);
181
- if (parts.length === 0)
182
- continue;
183
- const sortedParts = [...parts].sort((a, b) => a.id.localeCompare(b.id));
184
- const firstPart = sortedParts[0];
185
- if (!firstPart)
186
- continue;
187
- const firstIsThinking = THINKING_TYPES.has(firstPart.type);
188
- if (!firstIsThinking) {
189
- result.push(msg.id);
190
- }
191
- }
192
- return result;
193
- }
194
- export function prependThinkingPart(sessionID, messageID) {
195
- const partDir = join(PART_STORAGE, messageID);
196
- try {
197
- if (!existsSync(partDir)) {
198
- mkdirSync(partDir, { recursive: true });
199
- }
200
- const partId = "prt_0000000000_thinking";
201
- const part = {
202
- id: partId,
203
- sessionID,
204
- messageID,
205
- type: "thinking",
206
- thinking: "",
207
- synthetic: true,
208
- };
209
- writeFileSync(join(partDir, `${partId}.json`), JSON.stringify(part, null, 2));
210
- return true;
211
- }
212
- catch {
213
- return false;
214
- }
215
- }
216
- export function stripThinkingParts(messageID) {
217
- const partDir = join(PART_STORAGE, messageID);
218
- if (!existsSync(partDir))
219
- return false;
220
- let anyRemoved = false;
221
- try {
222
- for (const file of readdirSync(partDir)) {
223
- if (!file.endsWith(".json"))
224
- continue;
225
- try {
226
- const filePath = join(partDir, file);
227
- const content = readFileSync(filePath, "utf-8");
228
- const part = JSON.parse(content);
229
- if (THINKING_TYPES.has(part.type)) {
230
- unlinkSync(filePath);
231
- anyRemoved = true;
232
- }
233
- }
234
- catch {
235
- continue;
236
- }
237
- }
238
- }
239
- catch {
240
- return false;
241
- }
242
- return anyRemoved;
243
- }
244
- // =============================================================================
245
- // =============================================================================
246
- export function findEmptyMessages(sessionID) {
247
- const messages = readMessages(sessionID);
248
- const emptyIds = [];
249
- for (const msg of messages) {
250
- if (!messageHasContent(msg.id)) {
251
- emptyIds.push(msg.id);
252
- }
253
- }
254
- return emptyIds;
255
- }
256
- export function findEmptyMessageByIndex(sessionID, targetIndex) {
257
- const messages = readMessages(sessionID);
258
- const indicesToTry = [targetIndex, targetIndex - 1, targetIndex - 2];
259
- for (const idx of indicesToTry) {
260
- if (idx < 0 || idx >= messages.length)
261
- continue;
262
- const targetMsg = messages[idx];
263
- if (!targetMsg)
264
- continue;
265
- if (!messageHasContent(targetMsg.id)) {
266
- return targetMsg.id;
267
- }
268
- }
269
- return null;
270
- }
271
- export function findMessageByIndexNeedingThinking(sessionID, targetIndex) {
272
- const messages = readMessages(sessionID);
273
- if (targetIndex < 0 || targetIndex >= messages.length)
274
- return null;
275
- const targetMsg = messages[targetIndex];
276
- if (!targetMsg || targetMsg.role !== "assistant")
277
- return null;
278
- const parts = readParts(targetMsg.id);
279
- if (parts.length === 0)
280
- return null;
281
- const sortedParts = [...parts].sort((a, b) => a.id.localeCompare(b.id));
282
- const firstPart = sortedParts[0];
283
- if (!firstPart)
284
- return null;
285
- const firstIsThinking = THINKING_TYPES.has(firstPart.type);
286
- if (!firstIsThinking) {
287
- return targetMsg.id;
288
- }
289
- return null;
290
- }
291
- export function replaceEmptyTextParts(messageID, replacementText) {
292
- const partDir = join(PART_STORAGE, messageID);
293
- if (!existsSync(partDir))
294
- return false;
295
- let anyReplaced = false;
296
- try {
297
- for (const file of readdirSync(partDir)) {
298
- if (!file.endsWith(".json"))
299
- continue;
300
- try {
301
- const filePath = join(partDir, file);
302
- const content = readFileSync(filePath, "utf-8");
303
- const part = JSON.parse(content);
304
- if (part.type === "text") {
305
- const textPart = part;
306
- if (!textPart.text?.trim()) {
307
- textPart.text = replacementText;
308
- textPart.synthetic = true;
309
- writeFileSync(filePath, JSON.stringify(textPart, null, 2));
310
- anyReplaced = true;
311
- }
312
- }
313
- }
314
- catch {
315
- continue;
316
- }
317
- }
318
- }
319
- catch {
320
- return false;
321
- }
322
- return anyReplaced;
323
- }
324
- export function findMessagesWithEmptyTextParts(sessionID) {
325
- const messages = readMessages(sessionID);
326
- const result = [];
327
- for (const msg of messages) {
328
- const parts = readParts(msg.id);
329
- const hasEmptyTextPart = parts.some((p) => {
330
- if (p.type !== "text")
331
- return false;
332
- const textPart = p;
333
- return !textPart.text?.trim();
334
- });
335
- if (hasEmptyTextPart) {
336
- result.push(msg.id);
337
- }
338
- }
339
- return result;
340
- }
@@ -1,115 +0,0 @@
1
- /**
2
- * Types for session recovery.
3
- *
4
- * Based on oh-my-opencode/src/hooks/session-recovery/types.ts
5
- */
6
- export type ThinkingPartType = "thinking" | "redacted_thinking" | "reasoning";
7
- export type MetaPartType = "step-start" | "step-finish";
8
- export type ContentPartType = "text" | "tool" | "tool_use" | "tool_result";
9
- export interface StoredMessageMeta {
10
- id: string;
11
- sessionID: string;
12
- role: "user" | "assistant";
13
- parentID?: string;
14
- time?: {
15
- created: number;
16
- completed?: number;
17
- };
18
- error?: unknown;
19
- }
20
- export interface StoredTextPart {
21
- id: string;
22
- sessionID: string;
23
- messageID: string;
24
- type: "text";
25
- text: string;
26
- synthetic?: boolean;
27
- ignored?: boolean;
28
- }
29
- export interface StoredToolPart {
30
- id: string;
31
- sessionID: string;
32
- messageID: string;
33
- type: "tool";
34
- callID: string;
35
- tool: string;
36
- state: {
37
- status: "pending" | "running" | "completed" | "error";
38
- input: Record<string, unknown>;
39
- output?: string;
40
- error?: string;
41
- };
42
- }
43
- export interface StoredReasoningPart {
44
- id: string;
45
- sessionID: string;
46
- messageID: string;
47
- type: "reasoning";
48
- text: string;
49
- }
50
- export interface StoredStepPart {
51
- id: string;
52
- sessionID: string;
53
- messageID: string;
54
- type: "step-start" | "step-finish";
55
- }
56
- export type StoredPart = StoredTextPart | StoredToolPart | StoredReasoningPart | StoredStepPart | {
57
- id: string;
58
- sessionID: string;
59
- messageID: string;
60
- type: string;
61
- [key: string]: unknown;
62
- };
63
- export interface MessagePart {
64
- type: string;
65
- id?: string;
66
- text?: string;
67
- thinking?: string;
68
- name?: string;
69
- input?: Record<string, unknown>;
70
- callID?: string;
71
- }
72
- export interface MessageData {
73
- info?: {
74
- id?: string;
75
- role?: string;
76
- sessionID?: string;
77
- parentID?: string;
78
- error?: unknown;
79
- agent?: string;
80
- model?: {
81
- providerID: string;
82
- modelID: string;
83
- };
84
- system?: string;
85
- tools?: Record<string, boolean>;
86
- };
87
- parts?: MessagePart[];
88
- }
89
- export interface MessageInfo {
90
- id?: string;
91
- role?: string;
92
- sessionID?: string;
93
- parentID?: string;
94
- error?: unknown;
95
- }
96
- export interface ResumeConfig {
97
- sessionID: string;
98
- agent?: string;
99
- model?: {
100
- providerID: string;
101
- modelID: string;
102
- };
103
- }
104
- export type RecoveryErrorType = "tool_result_missing" | "thinking_block_order" | "thinking_disabled_violation" | null;
105
- export interface ToolUsePart {
106
- type: "tool_use";
107
- id: string;
108
- name: string;
109
- input: Record<string, unknown>;
110
- }
111
- export interface ToolResultPart {
112
- type: "tool_result";
113
- tool_use_id: string;
114
- content: string;
115
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * Types for session recovery.
3
- *
4
- * Based on oh-my-opencode/src/hooks/session-recovery/types.ts
5
- */
6
- export {};
@@ -1,60 +0,0 @@
1
- /**
2
- * Session recovery hook for handling recoverable errors.
3
- *
4
- * Supports:
5
- * - tool_result_missing: When ESC is pressed during tool execution
6
- * - thinking_block_order: When thinking blocks are corrupted/stripped
7
- * - thinking_disabled_violation: Thinking in non-thinking model
8
- *
9
- * Based on oh-my-opencode/src/hooks/session-recovery/index.ts
10
- */
11
- import type { AntigravityConfig } from "./config";
12
- import type { PluginClient } from "./types";
13
- import type { MessageInfo, RecoveryErrorType } from "./recovery/types";
14
- /**
15
- * Detect the type of recoverable error from an error object.
16
- */
17
- export declare function detectErrorType(error: unknown): RecoveryErrorType;
18
- /**
19
- * Check if an error is recoverable.
20
- */
21
- export declare function isRecoverableError(error: unknown): boolean;
22
- export declare function getRecoveryToastContent(errorType: RecoveryErrorType): {
23
- title: string;
24
- message: string;
25
- };
26
- export declare function getRecoverySuccessToast(): {
27
- title: string;
28
- message: string;
29
- };
30
- export declare function getRecoveryFailureToast(): {
31
- title: string;
32
- message: string;
33
- };
34
- export interface SessionRecoveryHook {
35
- /**
36
- * Main recovery handler. Performs the actual fix.
37
- * Returns true if recovery was successful.
38
- */
39
- handleSessionRecovery: (info: MessageInfo) => Promise<boolean>;
40
- /**
41
- * Check if the error is recoverable.
42
- */
43
- isRecoverableError: (error: unknown) => boolean;
44
- /**
45
- * Callback for when a session is being aborted for recovery.
46
- */
47
- setOnAbortCallback: (callback: (sessionID: string) => void) => void;
48
- /**
49
- * Callback for when recovery is complete (success or failure).
50
- */
51
- setOnRecoveryCompleteCallback: (callback: (sessionID: string) => void) => void;
52
- }
53
- export interface SessionRecoveryContext {
54
- client: PluginClient;
55
- directory: string;
56
- }
57
- /**
58
- * Create a session recovery hook with the given configuration.
59
- */
60
- export declare function createSessionRecoveryHook(ctx: SessionRecoveryContext, config: AntigravityConfig): SessionRecoveryHook | null;