opencode-ag-auth 1.5.2

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 (235) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +749 -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 +171 -0
  10. package/dist/src/antigravity/oauth.js.map +1 -0
  11. package/dist/src/constants.d.ts +138 -0
  12. package/dist/src/constants.d.ts.map +1 -0
  13. package/dist/src/constants.js +220 -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 +173 -0
  36. package/dist/src/plugin/accounts.d.ts.map +1 -0
  37. package/dist/src/plugin/accounts.js +1035 -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 +27 -0
  56. package/dist/src/plugin/cli.d.ts.map +1 -0
  57. package/dist/src/plugin/cli.js +130 -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 +196 -0
  66. package/dist/src/plugin/config/loader.js.map +1 -0
  67. package/dist/src/plugin/config/models.d.ts +27 -0
  68. package/dist/src/plugin/config/models.d.ts.map +1 -0
  69. package/dist/src/plugin/config/models.js +70 -0
  70. package/dist/src/plugin/config/models.js.map +1 -0
  71. package/dist/src/plugin/config/schema.d.ts +133 -0
  72. package/dist/src/plugin/config/schema.d.ts.map +1 -0
  73. package/dist/src/plugin/config/schema.js +438 -0
  74. package/dist/src/plugin/config/schema.js.map +1 -0
  75. package/dist/src/plugin/config/updater.d.ts +55 -0
  76. package/dist/src/plugin/config/updater.d.ts.map +1 -0
  77. package/dist/src/plugin/config/updater.js +125 -0
  78. package/dist/src/plugin/config/updater.js.map +1 -0
  79. package/dist/src/plugin/core/streaming/index.d.ts +3 -0
  80. package/dist/src/plugin/core/streaming/index.d.ts.map +1 -0
  81. package/dist/src/plugin/core/streaming/index.js +3 -0
  82. package/dist/src/plugin/core/streaming/index.js.map +1 -0
  83. package/dist/src/plugin/core/streaming/transformer.d.ts +10 -0
  84. package/dist/src/plugin/core/streaming/transformer.d.ts.map +1 -0
  85. package/dist/src/plugin/core/streaming/transformer.js +271 -0
  86. package/dist/src/plugin/core/streaming/transformer.js.map +1 -0
  87. package/dist/src/plugin/core/streaming/types.d.ts +27 -0
  88. package/dist/src/plugin/core/streaming/types.d.ts.map +1 -0
  89. package/dist/src/plugin/core/streaming/types.js +1 -0
  90. package/dist/src/plugin/core/streaming/types.js.map +1 -0
  91. package/dist/src/plugin/debug.d.ts +94 -0
  92. package/dist/src/plugin/debug.d.ts.map +1 -0
  93. package/dist/src/plugin/debug.js +418 -0
  94. package/dist/src/plugin/debug.js.map +1 -0
  95. package/dist/src/plugin/errors.d.ts +28 -0
  96. package/dist/src/plugin/errors.d.ts.map +1 -0
  97. package/dist/src/plugin/errors.js +42 -0
  98. package/dist/src/plugin/errors.js.map +1 -0
  99. package/dist/src/plugin/fingerprint.d.ts +64 -0
  100. package/dist/src/plugin/fingerprint.d.ts.map +1 -0
  101. package/dist/src/plugin/fingerprint.js +125 -0
  102. package/dist/src/plugin/fingerprint.js.map +1 -0
  103. package/dist/src/plugin/image-saver.d.ts +25 -0
  104. package/dist/src/plugin/image-saver.d.ts.map +1 -0
  105. package/dist/src/plugin/image-saver.js +86 -0
  106. package/dist/src/plugin/image-saver.js.map +1 -0
  107. package/dist/src/plugin/logger.d.ts +54 -0
  108. package/dist/src/plugin/logger.d.ts.map +1 -0
  109. package/dist/src/plugin/logger.js +120 -0
  110. package/dist/src/plugin/logger.js.map +1 -0
  111. package/dist/src/plugin/project.d.ts +33 -0
  112. package/dist/src/plugin/project.d.ts.map +1 -0
  113. package/dist/src/plugin/project.js +234 -0
  114. package/dist/src/plugin/project.js.map +1 -0
  115. package/dist/src/plugin/proxy.d.ts +2 -0
  116. package/dist/src/plugin/proxy.d.ts.map +1 -0
  117. package/dist/src/plugin/proxy.js +20 -0
  118. package/dist/src/plugin/proxy.js.map +1 -0
  119. package/dist/src/plugin/quota.d.ts +35 -0
  120. package/dist/src/plugin/quota.d.ts.map +1 -0
  121. package/dist/src/plugin/quota.js +273 -0
  122. package/dist/src/plugin/quota.js.map +1 -0
  123. package/dist/src/plugin/recovery/constants.d.ts +22 -0
  124. package/dist/src/plugin/recovery/constants.d.ts.map +1 -0
  125. package/dist/src/plugin/recovery/constants.js +43 -0
  126. package/dist/src/plugin/recovery/constants.js.map +1 -0
  127. package/dist/src/plugin/recovery/index.d.ts +12 -0
  128. package/dist/src/plugin/recovery/index.d.ts.map +1 -0
  129. package/dist/src/plugin/recovery/index.js +12 -0
  130. package/dist/src/plugin/recovery/index.js.map +1 -0
  131. package/dist/src/plugin/recovery/storage.d.ts +24 -0
  132. package/dist/src/plugin/recovery/storage.d.ts.map +1 -0
  133. package/dist/src/plugin/recovery/storage.js +354 -0
  134. package/dist/src/plugin/recovery/storage.js.map +1 -0
  135. package/dist/src/plugin/recovery/types.d.ts +116 -0
  136. package/dist/src/plugin/recovery/types.d.ts.map +1 -0
  137. package/dist/src/plugin/recovery/types.js +6 -0
  138. package/dist/src/plugin/recovery/types.js.map +1 -0
  139. package/dist/src/plugin/recovery.d.ts +61 -0
  140. package/dist/src/plugin/recovery.d.ts.map +1 -0
  141. package/dist/src/plugin/recovery.js +378 -0
  142. package/dist/src/plugin/recovery.js.map +1 -0
  143. package/dist/src/plugin/refresh-queue.d.ts +101 -0
  144. package/dist/src/plugin/refresh-queue.d.ts.map +1 -0
  145. package/dist/src/plugin/refresh-queue.js +248 -0
  146. package/dist/src/plugin/refresh-queue.js.map +1 -0
  147. package/dist/src/plugin/request-helpers.d.ts +282 -0
  148. package/dist/src/plugin/request-helpers.d.ts.map +1 -0
  149. package/dist/src/plugin/request-helpers.js +2319 -0
  150. package/dist/src/plugin/request-helpers.js.map +1 -0
  151. package/dist/src/plugin/request.d.ts +93 -0
  152. package/dist/src/plugin/request.d.ts.map +1 -0
  153. package/dist/src/plugin/request.js +1352 -0
  154. package/dist/src/plugin/request.js.map +1 -0
  155. package/dist/src/plugin/rotation.d.ts +169 -0
  156. package/dist/src/plugin/rotation.d.ts.map +1 -0
  157. package/dist/src/plugin/rotation.js +328 -0
  158. package/dist/src/plugin/rotation.js.map +1 -0
  159. package/dist/src/plugin/search.d.ts +32 -0
  160. package/dist/src/plugin/search.d.ts.map +1 -0
  161. package/dist/src/plugin/search.js +195 -0
  162. package/dist/src/plugin/search.js.map +1 -0
  163. package/dist/src/plugin/server.d.ts +23 -0
  164. package/dist/src/plugin/server.d.ts.map +1 -0
  165. package/dist/src/plugin/server.js +324 -0
  166. package/dist/src/plugin/server.js.map +1 -0
  167. package/dist/src/plugin/storage.d.ts +136 -0
  168. package/dist/src/plugin/storage.d.ts.map +1 -0
  169. package/dist/src/plugin/storage.js +588 -0
  170. package/dist/src/plugin/storage.js.map +1 -0
  171. package/dist/src/plugin/stores/signature-store.d.ts +5 -0
  172. package/dist/src/plugin/stores/signature-store.d.ts.map +1 -0
  173. package/dist/src/plugin/stores/signature-store.js +25 -0
  174. package/dist/src/plugin/stores/signature-store.js.map +1 -0
  175. package/dist/src/plugin/thinking-recovery.d.ts +90 -0
  176. package/dist/src/plugin/thinking-recovery.d.ts.map +1 -0
  177. package/dist/src/plugin/thinking-recovery.js +316 -0
  178. package/dist/src/plugin/thinking-recovery.js.map +1 -0
  179. package/dist/src/plugin/token.d.ts +19 -0
  180. package/dist/src/plugin/token.d.ts.map +1 -0
  181. package/dist/src/plugin/token.js +128 -0
  182. package/dist/src/plugin/token.js.map +1 -0
  183. package/dist/src/plugin/transform/claude.d.ts +80 -0
  184. package/dist/src/plugin/transform/claude.d.ts.map +1 -0
  185. package/dist/src/plugin/transform/claude.js +265 -0
  186. package/dist/src/plugin/transform/claude.js.map +1 -0
  187. package/dist/src/plugin/transform/cross-model-sanitizer.d.ts +35 -0
  188. package/dist/src/plugin/transform/cross-model-sanitizer.d.ts.map +1 -0
  189. package/dist/src/plugin/transform/cross-model-sanitizer.js +225 -0
  190. package/dist/src/plugin/transform/cross-model-sanitizer.js.map +1 -0
  191. package/dist/src/plugin/transform/gemini.d.ts +100 -0
  192. package/dist/src/plugin/transform/gemini.d.ts.map +1 -0
  193. package/dist/src/plugin/transform/gemini.js +465 -0
  194. package/dist/src/plugin/transform/gemini.js.map +1 -0
  195. package/dist/src/plugin/transform/index.d.ts +15 -0
  196. package/dist/src/plugin/transform/index.d.ts.map +1 -0
  197. package/dist/src/plugin/transform/index.js +14 -0
  198. package/dist/src/plugin/transform/index.js.map +1 -0
  199. package/dist/src/plugin/transform/model-resolver.d.ts +104 -0
  200. package/dist/src/plugin/transform/model-resolver.d.ts.map +1 -0
  201. package/dist/src/plugin/transform/model-resolver.js +361 -0
  202. package/dist/src/plugin/transform/model-resolver.js.map +1 -0
  203. package/dist/src/plugin/transform/types.d.ts +111 -0
  204. package/dist/src/plugin/transform/types.d.ts.map +1 -0
  205. package/dist/src/plugin/transform/types.js +1 -0
  206. package/dist/src/plugin/transform/types.js.map +1 -0
  207. package/dist/src/plugin/types.d.ts +97 -0
  208. package/dist/src/plugin/types.d.ts.map +1 -0
  209. package/dist/src/plugin/types.js +1 -0
  210. package/dist/src/plugin/types.js.map +1 -0
  211. package/dist/src/plugin/ui/ansi.d.ts +32 -0
  212. package/dist/src/plugin/ui/ansi.d.ts.map +1 -0
  213. package/dist/src/plugin/ui/ansi.js +52 -0
  214. package/dist/src/plugin/ui/ansi.js.map +1 -0
  215. package/dist/src/plugin/ui/auth-menu.d.ts +33 -0
  216. package/dist/src/plugin/ui/auth-menu.d.ts.map +1 -0
  217. package/dist/src/plugin/ui/auth-menu.js +110 -0
  218. package/dist/src/plugin/ui/auth-menu.js.map +1 -0
  219. package/dist/src/plugin/ui/confirm.d.ts +2 -0
  220. package/dist/src/plugin/ui/confirm.d.ts.map +1 -0
  221. package/dist/src/plugin/ui/confirm.js +15 -0
  222. package/dist/src/plugin/ui/confirm.js.map +1 -0
  223. package/dist/src/plugin/ui/select.d.ts +23 -0
  224. package/dist/src/plugin/ui/select.d.ts.map +1 -0
  225. package/dist/src/plugin/ui/select.js +254 -0
  226. package/dist/src/plugin/ui/select.js.map +1 -0
  227. package/dist/src/plugin/version.d.ts +19 -0
  228. package/dist/src/plugin/version.d.ts.map +1 -0
  229. package/dist/src/plugin/version.js +80 -0
  230. package/dist/src/plugin/version.js.map +1 -0
  231. package/dist/src/plugin.d.ts +30 -0
  232. package/dist/src/plugin.d.ts.map +1 -0
  233. package/dist/src/plugin.js +3050 -0
  234. package/dist/src/plugin.js.map +1 -0
  235. package/package.json +68 -0
@@ -0,0 +1,438 @@
1
+ /**
2
+ * Configuration schema for opencode-ag-auth plugin.
3
+ *
4
+ * Config file locations (in priority order, highest wins):
5
+ * - Project: .opencode/antigravity.json
6
+ * - User: ~/.config/opencode/antigravity.json (Linux/Mac)
7
+ * %APPDATA%\opencode\antigravity.json (Windows)
8
+ *
9
+ * Environment variables always override config file values.
10
+ */
11
+ import { z } from "zod";
12
+ /**
13
+ * Account selection strategy for distributing requests across accounts.
14
+ *
15
+ * - `sticky`: Use same account until rate-limited. Preserves prompt cache.
16
+ * - `round-robin`: Rotate to next account on every request. Maximum throughput.
17
+ * - `hybrid` (default): Deterministic selection based on health score + token bucket + LRU freshness.
18
+ */
19
+ export const AccountSelectionStrategySchema = z.enum([
20
+ "sticky",
21
+ "round-robin",
22
+ "hybrid",
23
+ ]);
24
+ /**
25
+ * Toast notification scope for controlling which sessions show toasts.
26
+ *
27
+ * - `root_only` (default): Only show toasts for root sessions (no parentID).
28
+ * Subagents and background tasks won't show toast notifications.
29
+ * - `all`: Show toasts for all sessions including subagents and background tasks.
30
+ */
31
+ export const ToastScopeSchema = z.enum(["root_only", "all"]);
32
+ /**
33
+ * Scheduling mode for rate limit behavior.
34
+ *
35
+ * - `cache_first`: Wait for same account to recover (preserves prompt cache). Default.
36
+ * - `balance`: Switch account immediately on rate limit. Maximum availability.
37
+ * - `performance_first`: Round-robin distribution for maximum throughput.
38
+ */
39
+ export const SchedulingModeSchema = z.enum([
40
+ "cache_first",
41
+ "balance",
42
+ "performance_first",
43
+ ]);
44
+ /**
45
+ * Signature cache configuration for persisting thinking block signatures to disk.
46
+ */
47
+ export const SignatureCacheConfigSchema = z.object({
48
+ /** Enable disk caching of signatures (default: true) */
49
+ enabled: z.boolean().default(true),
50
+ /** In-memory TTL in seconds (default: 3600 = 1 hour) */
51
+ memory_ttl_seconds: z.number().min(60).max(86400).default(3600),
52
+ /** Disk TTL in seconds (default: 172800 = 48 hours) */
53
+ disk_ttl_seconds: z.number().min(3600).max(604800).default(172800),
54
+ /** Background write interval in seconds (default: 60) */
55
+ write_interval_seconds: z.number().min(10).max(600).default(60),
56
+ });
57
+ /**
58
+ * Main configuration schema for the Antigravity OAuth plugin.
59
+ */
60
+ export const AntigravityConfigSchema = z.object({
61
+ /** JSON Schema reference for IDE support */
62
+ $schema: z.string().optional(),
63
+ // =========================================================================
64
+ // General Settings
65
+ // =========================================================================
66
+ /**
67
+ * Suppress most toast notifications (rate limit, account switching, etc.)
68
+ * Recovery toasts are always shown regardless of this setting.
69
+ * Env override: OPENCODE_ANTIGRAVITY_QUIET=1
70
+ * @default false
71
+ */
72
+ quiet_mode: z.boolean().default(false),
73
+ /**
74
+ * Control which sessions show toast notifications.
75
+ *
76
+ * - `root_only` (default): Only root sessions show toasts.
77
+ * Subagents and background tasks will be silent (less spam).
78
+ * - `all`: All sessions show toasts including subagents and background tasks.
79
+ *
80
+ * Debug logging captures all toasts regardless of this setting.
81
+ * Env override: OPENCODE_ANTIGRAVITY_TOAST_SCOPE=all
82
+ * @default "root_only"
83
+ */
84
+ toast_scope: ToastScopeSchema.default("root_only"),
85
+ /**
86
+ * Enable debug logging to file.
87
+ * Env override: OPENCODE_ANTIGRAVITY_DEBUG=1
88
+ * @default false
89
+ */
90
+ debug: z.boolean().default(false),
91
+ /**
92
+ * Custom directory for debug logs.
93
+ * Env override: OPENCODE_ANTIGRAVITY_LOG_DIR=/path/to/logs
94
+ * @default OS-specific config dir + "/antigravity-logs"
95
+ */
96
+ log_dir: z.string().optional(),
97
+ // =========================================================================
98
+ // Thinking Blocks
99
+ // =========================================================================
100
+ /**
101
+ * Preserve thinking blocks for Claude models using signature caching.
102
+ *
103
+ * When false (default): Thinking blocks are stripped for reliability.
104
+ * When true: Full context preserved, but may encounter signature errors.
105
+ *
106
+ * Env override: OPENCODE_ANTIGRAVITY_KEEP_THINKING=1
107
+ * @default false
108
+ */
109
+ keep_thinking: z.boolean().default(false),
110
+ // =========================================================================
111
+ // Session Recovery
112
+ // =========================================================================
113
+ /**
114
+ * Enable automatic session recovery from tool_result_missing errors.
115
+ * When enabled, shows a toast notification when recoverable errors occur.
116
+ *
117
+ * @default true
118
+ */
119
+ session_recovery: z.boolean().default(true),
120
+ /**
121
+ * Automatically send a "continue" prompt after successful recovery.
122
+ * Only applies when session_recovery is enabled.
123
+ *
124
+ * When false: Only shows toast notification, user must manually continue.
125
+ * When true: Automatically sends "continue" to resume the session.
126
+ *
127
+ * @default false
128
+ */
129
+ auto_resume: z.boolean().default(false),
130
+ /**
131
+ * Custom text to send when auto-resuming after recovery.
132
+ * Only used when auto_resume is enabled.
133
+ *
134
+ * @default "continue"
135
+ */
136
+ resume_text: z.string().default("continue"),
137
+ // =========================================================================
138
+ // Signature Caching
139
+ // =========================================================================
140
+ /**
141
+ * Signature cache configuration for persisting thinking block signatures.
142
+ * Only used when keep_thinking is enabled.
143
+ */
144
+ signature_cache: SignatureCacheConfigSchema.optional(),
145
+ // =========================================================================
146
+ // Empty Response Retry (ported from LLM-API-Key-Proxy)
147
+ // =========================================================================
148
+ /**
149
+ * Maximum retry attempts when Antigravity returns an empty response.
150
+ * Empty responses occur when no candidates/choices are returned.
151
+ *
152
+ * @default 4
153
+ */
154
+ empty_response_max_attempts: z.number().min(1).max(10).default(4),
155
+ /**
156
+ * Delay in milliseconds between empty response retries.
157
+ *
158
+ * @default 2000
159
+ */
160
+ empty_response_retry_delay_ms: z.number().min(500).max(10000).default(2000),
161
+ // =========================================================================
162
+ // Tool ID Recovery (ported from LLM-API-Key-Proxy)
163
+ // =========================================================================
164
+ /**
165
+ * Enable tool ID orphan recovery.
166
+ * When tool responses have mismatched IDs (due to context compaction),
167
+ * attempt to match them by function name or create placeholders.
168
+ *
169
+ * @default true
170
+ */
171
+ tool_id_recovery: z.boolean().default(true),
172
+ // =========================================================================
173
+ // Tool Hallucination Prevention (ported from LLM-API-Key-Proxy)
174
+ // =========================================================================
175
+ /**
176
+ * Enable tool hallucination prevention for Claude models.
177
+ * When enabled, injects:
178
+ * - Parameter signatures into tool descriptions
179
+ * - System instruction with strict tool usage rules
180
+ *
181
+ * This helps prevent Claude from using parameter names from its training
182
+ * data instead of the actual schema.
183
+ *
184
+ * @default true
185
+ */
186
+ claude_tool_hardening: z.boolean().default(true),
187
+ // =========================================================================
188
+ // Proactive Token Refresh (ported from LLM-API-Key-Proxy)
189
+ // =========================================================================
190
+ /**
191
+ * Enable proactive background token refresh.
192
+ * When enabled, tokens are refreshed in the background before they expire,
193
+ * ensuring requests never block on token refresh.
194
+ *
195
+ * @default true
196
+ */
197
+ proactive_token_refresh: z.boolean().default(true),
198
+ /**
199
+ * Seconds before token expiry to trigger proactive refresh.
200
+ * Default is 30 minutes (1800 seconds).
201
+ *
202
+ * @default 1800
203
+ */
204
+ proactive_refresh_buffer_seconds: z.number().min(60).max(7200).default(1800),
205
+ /**
206
+ * Interval between proactive refresh checks in seconds.
207
+ * Default is 5 minutes (300 seconds).
208
+ *
209
+ * @default 300
210
+ */
211
+ proactive_refresh_check_interval_seconds: z
212
+ .number()
213
+ .min(30)
214
+ .max(1800)
215
+ .default(300),
216
+ // =========================================================================
217
+ // Rate Limiting
218
+ // =========================================================================
219
+ /**
220
+ * Maximum time in seconds to wait when all accounts are rate-limited.
221
+ * If the minimum wait time across all accounts exceeds this threshold,
222
+ * the plugin fails fast with an error instead of hanging.
223
+ *
224
+ * Set to 0 to disable (wait indefinitely).
225
+ *
226
+ * @default 300 (5 minutes)
227
+ */
228
+ max_rate_limit_wait_seconds: z.number().min(0).max(3600).default(300),
229
+ /**
230
+ * @deprecated Kept only for backward compatibility.
231
+ * This flag is ignored at runtime.
232
+ * Gemini requests always fall back between Antigravity and Gemini CLI quotas.
233
+ *
234
+ * @default false
235
+ */
236
+ quota_fallback: z.boolean().default(false),
237
+ /**
238
+ * Prefer gemini-cli routing before Antigravity for Gemini models.
239
+ *
240
+ * When false (default): Antigravity is tried first, then gemini-cli.
241
+ * When true: gemini-cli is tried first, then Antigravity.
242
+ *
243
+ * @default false
244
+ */
245
+ cli_first: z.boolean().default(false),
246
+ /**
247
+ * Strategy for selecting accounts when making requests.
248
+ * Env override: OPENCODE_ANTIGRAVITY_ACCOUNT_SELECTION_STRATEGY
249
+ * @default "hybrid"
250
+ */
251
+ account_selection_strategy: AccountSelectionStrategySchema.default("hybrid"),
252
+ /**
253
+ * Enable PID-based account offset for multi-session distribution.
254
+ *
255
+ * When enabled, different sessions (PIDs) will prefer different starting
256
+ * accounts, which helps distribute load when running multiple parallel agents.
257
+ *
258
+ * When disabled (default), accounts start from the same index, which preserves
259
+ * Anthropic's prompt cache across restarts (recommended for single-session use).
260
+ *
261
+ * Env override: OPENCODE_ANTIGRAVITY_PID_OFFSET_ENABLED=1
262
+ * @default false
263
+ */
264
+ pid_offset_enabled: z.boolean().default(false),
265
+ /**
266
+ * Switch to another account immediately on first rate limit (after 1s delay).
267
+ * When disabled, retries same account first, then switches on second rate limit.
268
+ *
269
+ * @default true
270
+ */
271
+ switch_on_first_rate_limit: z.boolean().default(true),
272
+ /**
273
+ * Scheduling mode for rate limit behavior.
274
+ *
275
+ * - `cache_first`: Wait for same account to recover (preserves prompt cache). Default.
276
+ * - `balance`: Switch account immediately on rate limit. Maximum availability.
277
+ * - `performance_first`: Round-robin distribution for maximum throughput.
278
+ *
279
+ * Env override: OPENCODE_ANTIGRAVITY_SCHEDULING_MODE
280
+ * @default "cache_first"
281
+ */
282
+ scheduling_mode: SchedulingModeSchema.default("cache_first"),
283
+ /**
284
+ * Maximum seconds to wait for same account in cache_first mode.
285
+ * If the account's rate limit reset time exceeds this, switch accounts.
286
+ *
287
+ * @default 60
288
+ */
289
+ max_cache_first_wait_seconds: z.number().min(5).max(300).default(60),
290
+ /**
291
+ * TTL in seconds for failure count expiration.
292
+ * After this period of no failures, consecutiveFailures resets to 0.
293
+ * This prevents old failures from permanently penalizing an account.
294
+ *
295
+ * @default 3600 (1 hour)
296
+ */
297
+ failure_ttl_seconds: z.number().min(60).max(7200).default(3600),
298
+ /**
299
+ * Default retry delay in seconds when API doesn't return a retry-after header.
300
+ * Lower values allow faster retries but may trigger more 429 errors.
301
+ *
302
+ * @default 60
303
+ */
304
+ default_retry_after_seconds: z.number().min(1).max(300).default(60),
305
+ /**
306
+ * Maximum backoff delay in seconds for exponential retry.
307
+ * This caps how long the exponential backoff can grow.
308
+ *
309
+ * @default 60
310
+ */
311
+ max_backoff_seconds: z.number().min(5).max(300).default(60),
312
+ /**
313
+ * Maximum random delay in milliseconds before each API request.
314
+ * Adds timing jitter to break predictable request cadence patterns.
315
+ * Set to 0 to disable request jitter.
316
+ *
317
+ * @default 0
318
+ */
319
+ request_jitter_max_ms: z.number().min(0).max(5000).default(0),
320
+ /**
321
+ * Soft quota threshold percentage (1-100).
322
+ * When an account's quota usage reaches this percentage, skip it during
323
+ * account selection (same as if it were rate-limited).
324
+ *
325
+ * Example: 90 means skip account when 90% of quota is used (10% remaining).
326
+ * Set to 100 to disable soft quota protection.
327
+ *
328
+ * @default 70
329
+ */
330
+ soft_quota_threshold_percent: z.number().min(1).max(100).default(70),
331
+ /**
332
+ * How often to refresh quota data in the background (in minutes).
333
+ * Quota is refreshed opportunistically after successful API requests.
334
+ * Set to 0 to disable automatic refresh (manual only via Check quotas).
335
+ *
336
+ * @default 15
337
+ */
338
+ quota_refresh_interval_minutes: z.number().min(0).max(60).default(15),
339
+ /**
340
+ * How long quota cache is considered fresh for threshold checks (in minutes).
341
+ * After this time, cache is stale and account is allowed (fail-open).
342
+ *
343
+ * "auto" = derive from refresh interval: max(2 * refresh_interval, 10)
344
+ *
345
+ * @default "auto"
346
+ */
347
+ soft_quota_cache_ttl_minutes: z
348
+ .union([z.literal("auto"), z.number().min(1).max(120)])
349
+ .default("auto"),
350
+ // =========================================================================
351
+ // Health Score (used by hybrid strategy)
352
+ // =========================================================================
353
+ health_score: z
354
+ .object({
355
+ initial: z.number().min(0).max(100).default(70),
356
+ success_reward: z.number().min(0).max(10).default(1),
357
+ rate_limit_penalty: z.number().min(-50).max(0).default(-10),
358
+ failure_penalty: z.number().min(-100).max(0).default(-20),
359
+ recovery_rate_per_hour: z.number().min(0).max(20).default(2),
360
+ min_usable: z.number().min(0).max(100).default(50),
361
+ max_score: z.number().min(50).max(100).default(100),
362
+ })
363
+ .optional(),
364
+ // =========================================================================
365
+ // Token Bucket (for hybrid strategy)
366
+ // =========================================================================
367
+ token_bucket: z
368
+ .object({
369
+ max_tokens: z.number().min(1).max(1000).default(50),
370
+ regeneration_rate_per_minute: z.number().min(0.1).max(60).default(6),
371
+ initial_tokens: z.number().min(1).max(1000).default(50),
372
+ })
373
+ .optional(),
374
+ // =========================================================================
375
+ // Auto-Update
376
+ // =========================================================================
377
+ /**
378
+ * Enable automatic plugin updates.
379
+ * @default true
380
+ */
381
+ auto_update: z.boolean().default(true),
382
+ });
383
+ /**
384
+ * Default configuration values.
385
+ */
386
+ export const DEFAULT_CONFIG = {
387
+ quiet_mode: false,
388
+ toast_scope: "root_only",
389
+ debug: false,
390
+ keep_thinking: false,
391
+ session_recovery: true,
392
+ auto_resume: true,
393
+ resume_text: "continue",
394
+ empty_response_max_attempts: 4,
395
+ empty_response_retry_delay_ms: 2000,
396
+ tool_id_recovery: true,
397
+ claude_tool_hardening: true,
398
+ proactive_token_refresh: true,
399
+ proactive_refresh_buffer_seconds: 1800,
400
+ proactive_refresh_check_interval_seconds: 300,
401
+ max_rate_limit_wait_seconds: 300,
402
+ quota_fallback: false,
403
+ cli_first: false,
404
+ account_selection_strategy: "hybrid",
405
+ pid_offset_enabled: false,
406
+ switch_on_first_rate_limit: true,
407
+ scheduling_mode: "cache_first",
408
+ max_cache_first_wait_seconds: 60,
409
+ failure_ttl_seconds: 3600,
410
+ default_retry_after_seconds: 60,
411
+ max_backoff_seconds: 60,
412
+ request_jitter_max_ms: 0,
413
+ soft_quota_threshold_percent: 90,
414
+ quota_refresh_interval_minutes: 15,
415
+ soft_quota_cache_ttl_minutes: "auto",
416
+ auto_update: true,
417
+ signature_cache: {
418
+ enabled: true,
419
+ memory_ttl_seconds: 3600,
420
+ disk_ttl_seconds: 172800,
421
+ write_interval_seconds: 60,
422
+ },
423
+ health_score: {
424
+ initial: 70,
425
+ success_reward: 1,
426
+ rate_limit_penalty: -10,
427
+ failure_penalty: -20,
428
+ recovery_rate_per_hour: 2,
429
+ min_usable: 50,
430
+ max_score: 100,
431
+ },
432
+ token_bucket: {
433
+ max_tokens: 50,
434
+ regeneration_rate_per_minute: 6,
435
+ initial_tokens: 50,
436
+ },
437
+ };
438
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../src/plugin/config/schema.ts"],"names":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EAAE,IAAI;IACtC,wCAAwC,EAAE,GAAG;IAC7C,2BAA2B,EAAE,GAAG;IAChC,cAAc,EAAE,KAAK;IACrB,SAAS,EAAE,KAAK;IAChB,0BAA0B,EAAE,QAAQ;IACpC,kBAAkB,EAAE,KAAK;IACzB,0BAA0B,EAAE,IAAI;IAChC,eAAe,EAAE,aAAa;IAC9B,4BAA4B,EAAE,EAAE;IAChC,mBAAmB,EAAE,IAAI;IACzB,2BAA2B,EAAE,EAAE;IAC/B,mBAAmB,EAAE,EAAE;IACvB,qBAAqB,EAAE,CAAC;IACxB,4BAA4B,EAAE,EAAE;IAChC,8BAA8B,EAAE,EAAE;IAClC,4BAA4B,EAAE,MAAM;IACpC,WAAW,EAAE,IAAI;IACjB,eAAe,EAAE;QACf,OAAO,EAAE,IAAI;QACb,kBAAkB,EAAE,IAAI;QACxB,gBAAgB,EAAE,MAAM;QACxB,sBAAsB,EAAE,EAAE;KAC3B;IACD,YAAY,EAAE;QACZ,OAAO,EAAE,EAAE;QACX,cAAc,EAAE,CAAC;QACjB,kBAAkB,EAAE,CAAC,EAAE;QACvB,eAAe,EAAE,CAAC,EAAE;QACpB,sBAAsB,EAAE,CAAC;QACzB,UAAU,EAAE,EAAE;QACd,SAAS,EAAE,GAAG;KACf;IACD,YAAY,EAAE;QACZ,UAAU,EAAE,EAAE;QACd,4BAA4B,EAAE,CAAC;QAC/B,cAAc,EAAE,EAAE;KACnB;CACF,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * OpenCode configuration file updater.
3
+ *
4
+ * Updates ~/.config/opencode/opencode.json(c) with plugin models.
5
+ */
6
+ export interface UpdateConfigResult {
7
+ success: boolean;
8
+ configPath: string;
9
+ error?: string;
10
+ }
11
+ export interface OpencodeConfig {
12
+ $schema?: string;
13
+ plugin?: string[];
14
+ provider?: {
15
+ google?: {
16
+ models?: Record<string, unknown>;
17
+ [key: string]: unknown;
18
+ };
19
+ [key: string]: unknown;
20
+ };
21
+ [key: string]: unknown;
22
+ }
23
+ export interface UpdateConfigOptions {
24
+ /** Override the config file path (for testing) */
25
+ configPath?: string;
26
+ }
27
+ /**
28
+ * Get the opencode config directory path.
29
+ */
30
+ export declare function getOpencodeConfigDir(): string;
31
+ /**
32
+ * Get the opencode config file path.
33
+ *
34
+ * Prefers opencode.jsonc when present so we update the active config file
35
+ * instead of creating a new opencode.json.
36
+ */
37
+ export declare function getOpencodeConfigPath(): string;
38
+ /**
39
+ * Updates the opencode configuration file with plugin models.
40
+ *
41
+ * This function:
42
+ * 1. Reads existing opencode.json/opencode.jsonc (or creates default structure)
43
+ * 2. Replaces `provider.google.models` with plugin models
44
+ * 3. Writes back to disk with proper formatting
45
+ *
46
+ * Preserves:
47
+ * - $schema and other top-level config keys
48
+ * - Non-google provider sections
49
+ * - Other settings within google provider (except models)
50
+ *
51
+ * @param options - Optional configuration (e.g., custom configPath for testing)
52
+ * @returns UpdateConfigResult with success status and path
53
+ */
54
+ export declare function updateOpencodeConfig(options?: UpdateConfigOptions): Promise<UpdateConfigResult>;
55
+ //# sourceMappingURL=updater.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updater.d.ts","sourceRoot":"","sources":["../../../../src/plugin/config/updater.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAWH,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE;QACT,MAAM,CAAC,EAAE;YACP,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACjC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;SACxB,CAAC;QACF,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;IACF,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,mBAAmB;IAClC,kDAAkD;IAClD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAoBD;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAG7C;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAa9C;AAMD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,kBAAkB,CAAC,CAoE7B"}
@@ -0,0 +1,125 @@
1
+ /**
2
+ * OpenCode configuration file updater.
3
+ *
4
+ * Updates ~/.config/opencode/opencode.json(c) with plugin models.
5
+ */
6
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
7
+ import { join, dirname } from "node:path";
8
+ import { homedir } from "node:os";
9
+ import { OPENCODE_MODEL_DEFINITIONS } from "./models";
10
+ // =============================================================================
11
+ // Constants
12
+ // =============================================================================
13
+ const PLUGIN_NAME = "opencode-ag-auth@latest";
14
+ const SCHEMA_URL = "https://opencode.ai/config.json";
15
+ const OPENCODE_JSON_FILENAME = "opencode.json";
16
+ const OPENCODE_JSONC_FILENAME = "opencode.jsonc";
17
+ function stripJsonCommentsAndTrailingCommas(json) {
18
+ return json
19
+ .replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (match, group) => (group ? "" : match))
20
+ .replace(/,(\s*[}\]])/g, "$1");
21
+ }
22
+ /**
23
+ * Get the opencode config directory path.
24
+ */
25
+ export function getOpencodeConfigDir() {
26
+ const xdgConfig = process.env.XDG_CONFIG_HOME || join(homedir(), ".config");
27
+ return join(xdgConfig, "opencode");
28
+ }
29
+ /**
30
+ * Get the opencode config file path.
31
+ *
32
+ * Prefers opencode.jsonc when present so we update the active config file
33
+ * instead of creating a new opencode.json.
34
+ */
35
+ export function getOpencodeConfigPath() {
36
+ const configDir = getOpencodeConfigDir();
37
+ const jsoncPath = join(configDir, OPENCODE_JSONC_FILENAME);
38
+ const jsonPath = join(configDir, OPENCODE_JSON_FILENAME);
39
+ if (existsSync(jsoncPath)) {
40
+ return jsoncPath;
41
+ }
42
+ if (existsSync(jsonPath)) {
43
+ return jsonPath;
44
+ }
45
+ return jsonPath;
46
+ }
47
+ // =============================================================================
48
+ // Main Function
49
+ // =============================================================================
50
+ /**
51
+ * Updates the opencode configuration file with plugin models.
52
+ *
53
+ * This function:
54
+ * 1. Reads existing opencode.json/opencode.jsonc (or creates default structure)
55
+ * 2. Replaces `provider.google.models` with plugin models
56
+ * 3. Writes back to disk with proper formatting
57
+ *
58
+ * Preserves:
59
+ * - $schema and other top-level config keys
60
+ * - Non-google provider sections
61
+ * - Other settings within google provider (except models)
62
+ *
63
+ * @param options - Optional configuration (e.g., custom configPath for testing)
64
+ * @returns UpdateConfigResult with success status and path
65
+ */
66
+ export async function updateOpencodeConfig(options = {}) {
67
+ const configPath = options.configPath ?? getOpencodeConfigPath();
68
+ try {
69
+ let config;
70
+ // Read existing config or create default
71
+ if (existsSync(configPath)) {
72
+ const content = readFileSync(configPath, "utf-8");
73
+ config = JSON.parse(stripJsonCommentsAndTrailingCommas(content));
74
+ }
75
+ else {
76
+ // Create default config structure
77
+ config = {
78
+ $schema: SCHEMA_URL,
79
+ plugin: [],
80
+ provider: {},
81
+ };
82
+ }
83
+ // Ensure $schema is set
84
+ if (!config.$schema) {
85
+ config.$schema = SCHEMA_URL;
86
+ }
87
+ // Ensure plugin array exists and contains our plugin
88
+ if (!Array.isArray(config.plugin)) {
89
+ config.plugin = [];
90
+ }
91
+ // Check if plugin is already in the list (any version)
92
+ const hasPlugin = config.plugin.some((p) => p.includes("opencode-ag-auth"));
93
+ if (!hasPlugin) {
94
+ config.plugin.push(PLUGIN_NAME);
95
+ }
96
+ // Ensure provider.google structure exists
97
+ if (!config.provider) {
98
+ config.provider = {};
99
+ }
100
+ if (!config.provider.google) {
101
+ config.provider.google = {};
102
+ }
103
+ // Replace google models with plugin models
104
+ config.provider.google.models = { ...OPENCODE_MODEL_DEFINITIONS };
105
+ // Ensure config directory exists
106
+ const configDir = dirname(configPath);
107
+ if (!existsSync(configDir)) {
108
+ mkdirSync(configDir, { recursive: true });
109
+ }
110
+ // Write config with proper formatting (2-space indent)
111
+ writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
112
+ return {
113
+ success: true,
114
+ configPath,
115
+ };
116
+ }
117
+ catch (error) {
118
+ return {
119
+ success: false,
120
+ configPath,
121
+ error: error instanceof Error ? error.message : String(error),
122
+ };
123
+ }
124
+ }
125
+ //# sourceMappingURL=updater.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updater.js","sourceRoot":"","sources":["../../../../src/plugin/config/updater.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AA8BtD,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF,MAAM,WAAW,GAAG,yBAAyB,CAAC;AAC9C,MAAM,UAAU,GAAG,iCAAiC,CAAC;AACrD,MAAM,sBAAsB,GAAG,eAAe,CAAC;AAC/C,MAAM,uBAAuB,GAAG,gBAAgB,CAAC;AAEjD,SAAS,kCAAkC,CAAC,IAAY;IACtD,OAAO,IAAI;SACR,OAAO,CACN,gDAAgD,EAChD,CAAC,KAAa,EAAE,KAAyB,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CACnE;SACA,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;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AO,CAAC,CAAC;QAEpE,OAAO;YACL,OAAO,EAAE,IAAI;YACb,UAAU;SACX,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,OAAO,EAAE,KAAK;YACd,UAAU;YACV,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;SAC9D,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './types';
2
+ export * from './transformer';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/plugin/core/streaming/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './types';
2
+ export * from './transformer';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/plugin/core/streaming/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { SignatureStore, StreamingCallbacks, StreamingOptions, ThoughtBuffer } from './types';
2
+ export declare function createThoughtBuffer(): ThoughtBuffer;
3
+ export declare function transformStreamingPayload(payload: string, transformThinkingParts?: (response: unknown) => unknown): string;
4
+ export declare function deduplicateThinkingText(response: unknown, sentBuffer: ThoughtBuffer, displayedThinkingHashes?: Set<string>): unknown;
5
+ export declare function transformSseLine(line: string, signatureStore: SignatureStore, thoughtBuffer: ThoughtBuffer, sentThinkingBuffer: ThoughtBuffer, callbacks: StreamingCallbacks, options: StreamingOptions, debugState: {
6
+ injected: boolean;
7
+ }): string;
8
+ export declare function cacheThinkingSignaturesFromResponse(response: unknown, signatureSessionKey: string, signatureStore: SignatureStore, thoughtBuffer: ThoughtBuffer, onCacheSignature?: (sessionKey: string, text: string, signature: string) => void): void;
9
+ export declare function createStreamingTransformer(signatureStore: SignatureStore, callbacks: StreamingCallbacks, options?: StreamingOptions): TransformStream<Uint8Array, Uint8Array>;
10
+ //# sourceMappingURL=transformer.d.ts.map