remoat 0.2.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 (200) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +297 -0
  3. package/dist/bin/cli.d.ts +2 -0
  4. package/dist/bin/cli.js +80 -0
  5. package/dist/bin/cli.js.map +1 -0
  6. package/dist/bin/commands/doctor.d.ts +1 -0
  7. package/dist/bin/commands/doctor.js +211 -0
  8. package/dist/bin/commands/doctor.js.map +1 -0
  9. package/dist/bin/commands/open.d.ts +1 -0
  10. package/dist/bin/commands/open.js +187 -0
  11. package/dist/bin/commands/open.js.map +1 -0
  12. package/dist/bin/commands/setup.d.ts +1 -0
  13. package/dist/bin/commands/setup.js +267 -0
  14. package/dist/bin/commands/setup.js.map +1 -0
  15. package/dist/bin/commands/start.d.ts +2 -0
  16. package/dist/bin/commands/start.js +39 -0
  17. package/dist/bin/commands/start.js.map +1 -0
  18. package/dist/bot/index.d.ts +2 -0
  19. package/dist/bot/index.js +1393 -0
  20. package/dist/bot/index.js.map +1 -0
  21. package/dist/commands/chatCommandHandler.d.ts +20 -0
  22. package/dist/commands/chatCommandHandler.js +30 -0
  23. package/dist/commands/chatCommandHandler.js.map +1 -0
  24. package/dist/commands/cleanupCommandHandler.d.ts +21 -0
  25. package/dist/commands/cleanupCommandHandler.js +40 -0
  26. package/dist/commands/cleanupCommandHandler.js.map +1 -0
  27. package/dist/commands/joinCommandHandler.d.ts +19 -0
  28. package/dist/commands/joinCommandHandler.js +27 -0
  29. package/dist/commands/joinCommandHandler.js.map +1 -0
  30. package/dist/commands/messageParser.d.ts +7 -0
  31. package/dist/commands/messageParser.js +29 -0
  32. package/dist/commands/messageParser.js.map +1 -0
  33. package/dist/commands/slashCommandHandler.d.ts +21 -0
  34. package/dist/commands/slashCommandHandler.js +105 -0
  35. package/dist/commands/slashCommandHandler.js.map +1 -0
  36. package/dist/commands/workspaceCommandHandler.d.ts +16 -0
  37. package/dist/commands/workspaceCommandHandler.js +29 -0
  38. package/dist/commands/workspaceCommandHandler.js.map +1 -0
  39. package/dist/database/chatSessionRepository.d.ts +59 -0
  40. package/dist/database/chatSessionRepository.js +110 -0
  41. package/dist/database/chatSessionRepository.js.map +1 -0
  42. package/dist/database/scheduleRepository.d.ts +60 -0
  43. package/dist/database/scheduleRepository.js +106 -0
  44. package/dist/database/scheduleRepository.js.map +1 -0
  45. package/dist/database/templateRepository.d.ts +51 -0
  46. package/dist/database/templateRepository.js +90 -0
  47. package/dist/database/templateRepository.js.map +1 -0
  48. package/dist/database/workspaceBindingRepository.d.ts +48 -0
  49. package/dist/database/workspaceBindingRepository.js +92 -0
  50. package/dist/database/workspaceBindingRepository.js.map +1 -0
  51. package/dist/index.d.ts +1 -0
  52. package/dist/index.js +11 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/middleware/auth.d.ts +5 -0
  55. package/dist/middleware/auth.js +14 -0
  56. package/dist/middleware/auth.js.map +1 -0
  57. package/dist/middleware/sanitize.d.ts +1 -0
  58. package/dist/middleware/sanitize.js +18 -0
  59. package/dist/middleware/sanitize.js.map +1 -0
  60. package/dist/services/antigravityLauncher.d.ts +7 -0
  61. package/dist/services/antigravityLauncher.js +94 -0
  62. package/dist/services/antigravityLauncher.js.map +1 -0
  63. package/dist/services/approvalDetector.d.ts +97 -0
  64. package/dist/services/approvalDetector.js +394 -0
  65. package/dist/services/approvalDetector.js.map +1 -0
  66. package/dist/services/assistantDomExtractor.d.ts +49 -0
  67. package/dist/services/assistantDomExtractor.js +340 -0
  68. package/dist/services/assistantDomExtractor.js.map +1 -0
  69. package/dist/services/autoAcceptService.d.ts +14 -0
  70. package/dist/services/autoAcceptService.js +81 -0
  71. package/dist/services/autoAcceptService.js.map +1 -0
  72. package/dist/services/cdpBridgeManager.d.ts +50 -0
  73. package/dist/services/cdpBridgeManager.js +355 -0
  74. package/dist/services/cdpBridgeManager.js.map +1 -0
  75. package/dist/services/cdpConnectionPool.d.ts +88 -0
  76. package/dist/services/cdpConnectionPool.js +235 -0
  77. package/dist/services/cdpConnectionPool.js.map +1 -0
  78. package/dist/services/cdpService.d.ts +214 -0
  79. package/dist/services/cdpService.js +1423 -0
  80. package/dist/services/cdpService.js.map +1 -0
  81. package/dist/services/chatSessionService.d.ts +89 -0
  82. package/dist/services/chatSessionService.js +738 -0
  83. package/dist/services/chatSessionService.js.map +1 -0
  84. package/dist/services/errorPopupDetector.d.ts +89 -0
  85. package/dist/services/errorPopupDetector.js +274 -0
  86. package/dist/services/errorPopupDetector.js.map +1 -0
  87. package/dist/services/modeService.d.ts +44 -0
  88. package/dist/services/modeService.js +74 -0
  89. package/dist/services/modeService.js.map +1 -0
  90. package/dist/services/modelService.d.ts +36 -0
  91. package/dist/services/modelService.js +64 -0
  92. package/dist/services/modelService.js.map +1 -0
  93. package/dist/services/planningDetector.d.ts +87 -0
  94. package/dist/services/planningDetector.js +321 -0
  95. package/dist/services/planningDetector.js.map +1 -0
  96. package/dist/services/processManager.d.ts +18 -0
  97. package/dist/services/processManager.js +62 -0
  98. package/dist/services/processManager.js.map +1 -0
  99. package/dist/services/progressSender.d.ts +20 -0
  100. package/dist/services/progressSender.js +65 -0
  101. package/dist/services/progressSender.js.map +1 -0
  102. package/dist/services/promptDispatcher.d.ts +38 -0
  103. package/dist/services/promptDispatcher.js +42 -0
  104. package/dist/services/promptDispatcher.js.map +1 -0
  105. package/dist/services/quotaService.d.ts +21 -0
  106. package/dist/services/quotaService.js +191 -0
  107. package/dist/services/quotaService.js.map +1 -0
  108. package/dist/services/responseMonitor.d.ts +129 -0
  109. package/dist/services/responseMonitor.js +996 -0
  110. package/dist/services/responseMonitor.js.map +1 -0
  111. package/dist/services/scheduleService.d.ts +58 -0
  112. package/dist/services/scheduleService.js +135 -0
  113. package/dist/services/scheduleService.js.map +1 -0
  114. package/dist/services/screenshotService.d.ts +55 -0
  115. package/dist/services/screenshotService.js +86 -0
  116. package/dist/services/screenshotService.js.map +1 -0
  117. package/dist/services/telegramTopicManager.d.ts +40 -0
  118. package/dist/services/telegramTopicManager.js +103 -0
  119. package/dist/services/telegramTopicManager.js.map +1 -0
  120. package/dist/services/titleGeneratorService.d.ts +32 -0
  121. package/dist/services/titleGeneratorService.js +114 -0
  122. package/dist/services/titleGeneratorService.js.map +1 -0
  123. package/dist/services/updateCheckService.d.ts +16 -0
  124. package/dist/services/updateCheckService.js +148 -0
  125. package/dist/services/updateCheckService.js.map +1 -0
  126. package/dist/services/userMessageDetector.d.ts +57 -0
  127. package/dist/services/userMessageDetector.js +222 -0
  128. package/dist/services/userMessageDetector.js.map +1 -0
  129. package/dist/services/workspaceService.d.ts +33 -0
  130. package/dist/services/workspaceService.js +65 -0
  131. package/dist/services/workspaceService.js.map +1 -0
  132. package/dist/ui/autoAcceptUi.d.ts +6 -0
  133. package/dist/ui/autoAcceptUi.js +22 -0
  134. package/dist/ui/autoAcceptUi.js.map +1 -0
  135. package/dist/ui/modeUi.d.ts +12 -0
  136. package/dist/ui/modeUi.js +40 -0
  137. package/dist/ui/modeUi.js.map +1 -0
  138. package/dist/ui/modelsUi.d.ts +12 -0
  139. package/dist/ui/modelsUi.js +101 -0
  140. package/dist/ui/modelsUi.js.map +1 -0
  141. package/dist/ui/projectListUi.d.ts +11 -0
  142. package/dist/ui/projectListUi.js +59 -0
  143. package/dist/ui/projectListUi.js.map +1 -0
  144. package/dist/ui/screenshotUi.d.ts +6 -0
  145. package/dist/ui/screenshotUi.js +28 -0
  146. package/dist/ui/screenshotUi.js.map +1 -0
  147. package/dist/ui/sessionPickerUi.d.ts +8 -0
  148. package/dist/ui/sessionPickerUi.js +32 -0
  149. package/dist/ui/sessionPickerUi.js.map +1 -0
  150. package/dist/ui/templateUi.d.ts +5 -0
  151. package/dist/ui/templateUi.js +44 -0
  152. package/dist/ui/templateUi.js.map +1 -0
  153. package/dist/utils/cdpPorts.d.ts +2 -0
  154. package/dist/utils/cdpPorts.js +6 -0
  155. package/dist/utils/cdpPorts.js.map +1 -0
  156. package/dist/utils/config.d.ts +14 -0
  157. package/dist/utils/config.js +12 -0
  158. package/dist/utils/config.js.map +1 -0
  159. package/dist/utils/configLoader.d.ts +23 -0
  160. package/dist/utils/configLoader.js +153 -0
  161. package/dist/utils/configLoader.js.map +1 -0
  162. package/dist/utils/htmlToTelegramMarkdown.d.ts +6 -0
  163. package/dist/utils/htmlToTelegramMarkdown.js +189 -0
  164. package/dist/utils/htmlToTelegramMarkdown.js.map +1 -0
  165. package/dist/utils/i18n.d.ts +3 -0
  166. package/dist/utils/i18n.js +78 -0
  167. package/dist/utils/i18n.js.map +1 -0
  168. package/dist/utils/imageHandler.d.ts +35 -0
  169. package/dist/utils/imageHandler.js +155 -0
  170. package/dist/utils/imageHandler.js.map +1 -0
  171. package/dist/utils/lockfile.d.ts +7 -0
  172. package/dist/utils/lockfile.js +117 -0
  173. package/dist/utils/lockfile.js.map +1 -0
  174. package/dist/utils/logger.d.ts +23 -0
  175. package/dist/utils/logger.js +85 -0
  176. package/dist/utils/logger.js.map +1 -0
  177. package/dist/utils/logo.d.ts +1 -0
  178. package/dist/utils/logo.js +14 -0
  179. package/dist/utils/logo.js.map +1 -0
  180. package/dist/utils/metadataExtractor.d.ts +5 -0
  181. package/dist/utils/metadataExtractor.js +16 -0
  182. package/dist/utils/metadataExtractor.js.map +1 -0
  183. package/dist/utils/pathUtils.d.ts +23 -0
  184. package/dist/utils/pathUtils.js +58 -0
  185. package/dist/utils/pathUtils.js.map +1 -0
  186. package/dist/utils/processLogBuffer.d.ts +17 -0
  187. package/dist/utils/processLogBuffer.js +108 -0
  188. package/dist/utils/processLogBuffer.js.map +1 -0
  189. package/dist/utils/streamMessageFormatter.d.ts +18 -0
  190. package/dist/utils/streamMessageFormatter.js +91 -0
  191. package/dist/utils/streamMessageFormatter.js.map +1 -0
  192. package/dist/utils/telegramFormatter.d.ts +37 -0
  193. package/dist/utils/telegramFormatter.js +445 -0
  194. package/dist/utils/telegramFormatter.js.map +1 -0
  195. package/dist/utils/voiceHandler.d.ts +23 -0
  196. package/dist/utils/voiceHandler.js +169 -0
  197. package/dist/utils/voiceHandler.js.map +1 -0
  198. package/locales/en.json +85 -0
  199. package/locales/ja.json +109 -0
  200. package/package.json +84 -0
@@ -0,0 +1,235 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CdpConnectionPool = void 0;
4
+ const logger_1 = require("../utils/logger");
5
+ const pathUtils_1 = require("../utils/pathUtils");
6
+ const cdpService_1 = require("./cdpService");
7
+ /**
8
+ * Pool that manages independent CdpService instances per workspace.
9
+ *
10
+ * Each workspace owns its own WebSocket / contexts / pendingCalls, so
11
+ * switching to workspace B while workspace A's ResponseMonitor is polling
12
+ * does not destroy A's WebSocket.
13
+ */
14
+ class CdpConnectionPool {
15
+ connections = new Map();
16
+ approvalDetectors = new Map();
17
+ errorPopupDetectors = new Map();
18
+ planningDetectors = new Map();
19
+ userMessageDetectors = new Map();
20
+ connectingPromises = new Map();
21
+ cdpOptions;
22
+ constructor(cdpOptions = {}) {
23
+ this.cdpOptions = cdpOptions;
24
+ }
25
+ /**
26
+ * Get a CdpService for the given workspace path.
27
+ * Creates a new connection and caches it if not already connected.
28
+ * Prevents concurrent connections via Promise locking.
29
+ *
30
+ * @param workspacePath Full path of the workspace
31
+ * @returns Connected CdpService
32
+ */
33
+ async getOrConnect(workspacePath) {
34
+ const projectName = this.extractProjectName(workspacePath);
35
+ // Return existing connection if available
36
+ const existing = this.connections.get(projectName);
37
+ if (existing) {
38
+ if (existing.isConnected()) {
39
+ try {
40
+ // Re-validate that the still-open window is actually bound to this workspace.
41
+ await existing.discoverAndConnectForWorkspace(workspacePath);
42
+ return existing;
43
+ }
44
+ catch {
45
+ // Connection dropped during re-validation; close WebSocket and clean up
46
+ existing.disconnect().catch(() => { });
47
+ this.connections.delete(projectName);
48
+ }
49
+ }
50
+ else {
51
+ // Stale disconnected entry (e.g. reconnect was disabled) — clean up
52
+ this.connections.delete(projectName);
53
+ }
54
+ }
55
+ // Wait for the pending connection promise if one exists (prevents concurrent connections)
56
+ const pending = this.connectingPromises.get(projectName);
57
+ if (pending) {
58
+ return pending;
59
+ }
60
+ // Start a new connection
61
+ const connectPromise = this.createAndConnect(workspacePath, projectName);
62
+ this.connectingPromises.set(projectName, connectPromise);
63
+ try {
64
+ const cdp = await connectPromise;
65
+ return cdp;
66
+ }
67
+ finally {
68
+ this.connectingPromises.delete(projectName);
69
+ }
70
+ }
71
+ /**
72
+ * Get a connected CdpService (read-only).
73
+ * Returns null if not connected.
74
+ */
75
+ getConnected(projectName) {
76
+ const cdp = this.connections.get(projectName);
77
+ if (cdp && cdp.isConnected()) {
78
+ return cdp;
79
+ }
80
+ return null;
81
+ }
82
+ /**
83
+ * Disconnect the specified workspace.
84
+ */
85
+ disconnectWorkspace(projectName) {
86
+ const cdp = this.connections.get(projectName);
87
+ if (cdp) {
88
+ cdp.disconnect().catch((err) => {
89
+ logger_1.logger.error(`[CdpConnectionPool] Error while disconnecting ${projectName}:`, err);
90
+ });
91
+ this.connections.delete(projectName);
92
+ }
93
+ const detector = this.approvalDetectors.get(projectName);
94
+ if (detector) {
95
+ detector.stop();
96
+ this.approvalDetectors.delete(projectName);
97
+ }
98
+ const errorPopupDetector = this.errorPopupDetectors.get(projectName);
99
+ if (errorPopupDetector) {
100
+ errorPopupDetector.stop();
101
+ this.errorPopupDetectors.delete(projectName);
102
+ }
103
+ const planningDetector = this.planningDetectors.get(projectName);
104
+ if (planningDetector) {
105
+ planningDetector.stop();
106
+ this.planningDetectors.delete(projectName);
107
+ }
108
+ const userMsgDetector = this.userMessageDetectors.get(projectName);
109
+ if (userMsgDetector) {
110
+ userMsgDetector.stop();
111
+ this.userMessageDetectors.delete(projectName);
112
+ }
113
+ }
114
+ /**
115
+ * Disconnect all workspace connections.
116
+ */
117
+ disconnectAll() {
118
+ for (const projectName of [...this.connections.keys()]) {
119
+ this.disconnectWorkspace(projectName);
120
+ }
121
+ }
122
+ /**
123
+ * Register an approval detector for a workspace.
124
+ */
125
+ registerApprovalDetector(projectName, detector) {
126
+ // Stop existing detector
127
+ const existing = this.approvalDetectors.get(projectName);
128
+ if (existing && existing.isActive()) {
129
+ existing.stop();
130
+ }
131
+ this.approvalDetectors.set(projectName, detector);
132
+ }
133
+ /**
134
+ * Get the approval detector for a workspace.
135
+ */
136
+ getApprovalDetector(projectName) {
137
+ return this.approvalDetectors.get(projectName);
138
+ }
139
+ /**
140
+ * Register an error popup detector for a workspace.
141
+ */
142
+ registerErrorPopupDetector(projectName, detector) {
143
+ // Stop existing detector
144
+ const existing = this.errorPopupDetectors.get(projectName);
145
+ if (existing && existing.isActive()) {
146
+ existing.stop();
147
+ }
148
+ this.errorPopupDetectors.set(projectName, detector);
149
+ }
150
+ /**
151
+ * Get the error popup detector for a workspace.
152
+ */
153
+ getErrorPopupDetector(projectName) {
154
+ return this.errorPopupDetectors.get(projectName);
155
+ }
156
+ /**
157
+ * Register a planning detector for a workspace.
158
+ */
159
+ registerPlanningDetector(projectName, detector) {
160
+ // Stop existing detector
161
+ const existing = this.planningDetectors.get(projectName);
162
+ if (existing && existing.isActive()) {
163
+ existing.stop();
164
+ }
165
+ this.planningDetectors.set(projectName, detector);
166
+ }
167
+ /**
168
+ * Get the planning detector for a workspace.
169
+ */
170
+ getPlanningDetector(projectName) {
171
+ return this.planningDetectors.get(projectName);
172
+ }
173
+ /**
174
+ * Register a user message detector for a workspace.
175
+ */
176
+ registerUserMessageDetector(projectName, detector) {
177
+ const existing = this.userMessageDetectors.get(projectName);
178
+ if (existing && existing.isActive()) {
179
+ existing.stop();
180
+ }
181
+ this.userMessageDetectors.set(projectName, detector);
182
+ }
183
+ /**
184
+ * Get the user message detector for a workspace.
185
+ */
186
+ getUserMessageDetector(projectName) {
187
+ return this.userMessageDetectors.get(projectName);
188
+ }
189
+ /**
190
+ * Return a list of workspace names with active connections.
191
+ */
192
+ getActiveWorkspaceNames() {
193
+ const active = [];
194
+ for (const [name, cdp] of this.connections) {
195
+ if (cdp.isConnected()) {
196
+ active.push(name);
197
+ }
198
+ }
199
+ return active;
200
+ }
201
+ /**
202
+ * Extract the project name from a workspace path.
203
+ */
204
+ extractProjectName(workspacePath) {
205
+ return (0, pathUtils_1.extractProjectNameFromPath)(workspacePath) || workspacePath;
206
+ }
207
+ /**
208
+ * Create a new CdpService and connect to the workspace.
209
+ */
210
+ async createAndConnect(workspacePath, projectName) {
211
+ // Disconnect old connection if exists
212
+ const old = this.connections.get(projectName);
213
+ if (old) {
214
+ await old.disconnect().catch(() => { });
215
+ this.connections.delete(projectName);
216
+ }
217
+ const cdp = new cdpService_1.CdpService(this.cdpOptions);
218
+ // Auto-cleanup on disconnect
219
+ cdp.on('disconnected', () => {
220
+ logger_1.logger.error(`[CdpConnectionPool] Workspace "${projectName}" disconnected`);
221
+ // Only remove from Map when reconnection fails
222
+ // (CdpService attempts reconnection internally, so we don't remove here)
223
+ });
224
+ cdp.on('reconnectFailed', () => {
225
+ logger_1.logger.error(`[CdpConnectionPool] Reconnection failed for workspace "${projectName}". Removing from pool`);
226
+ this.disconnectWorkspace(projectName);
227
+ });
228
+ // Connect to the workspace
229
+ await cdp.discoverAndConnectForWorkspace(workspacePath);
230
+ this.connections.set(projectName, cdp);
231
+ return cdp;
232
+ }
233
+ }
234
+ exports.CdpConnectionPool = CdpConnectionPool;
235
+ //# sourceMappingURL=cdpConnectionPool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cdpConnectionPool.js","sourceRoot":"","sources":["../../src/services/cdpConnectionPool.ts"],"names":[],"mappings":";;;AAAA,4CAAyC;AACzC,kDAAgE;AAChE,6CAA6D;AAM7D;;;;;;GAMG;AACH,MAAa,iBAAiB;IACT,WAAW,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC5C,iBAAiB,GAAG,IAAI,GAAG,EAA4B,CAAC;IACxD,mBAAmB,GAAG,IAAI,GAAG,EAA8B,CAAC;IAC5D,iBAAiB,GAAG,IAAI,GAAG,EAA4B,CAAC;IACxD,oBAAoB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KAAK,CAAC,0DAA0D,WAAW,uBAAuB,CAAC,CAAC;YAC3G,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;QAEH,2BAA2B;QAC3B,MAAM,GAAG,CAAC,8BAA8B,CAAC,aAAa,CAAC,CAAC;QACxD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;QAEvC,OAAO,GAAG,CAAC;IACf,CAAC;CACJ;AArPD,8CAqPC"}
@@ -0,0 +1,214 @@
1
+ import { EventEmitter } from 'events';
2
+ export interface CdpServiceOptions {
3
+ portsToScan?: number[];
4
+ cdpCallTimeout?: number;
5
+ /** Number of auto-reconnect attempts on disconnect. 0 = no reconnect. Default: 3 */
6
+ maxReconnectAttempts?: number;
7
+ /** Delay between reconnect attempts (ms). Default: 2000 */
8
+ reconnectDelayMs?: number;
9
+ }
10
+ export interface CdpContext {
11
+ id: number;
12
+ name: string;
13
+ url: string;
14
+ }
15
+ export interface InjectResult {
16
+ ok: boolean;
17
+ method?: string;
18
+ contextId?: number;
19
+ error?: string;
20
+ }
21
+ export interface ExtractedResponseImage {
22
+ name: string;
23
+ mimeType: string;
24
+ base64Data?: string;
25
+ url?: string;
26
+ }
27
+ /** UI sync operation result type (Step 9) */
28
+ export interface UiSyncResult {
29
+ ok: boolean;
30
+ /** Mode name set (on setUiMode success) */
31
+ mode?: string;
32
+ /** Model name set (on setUiModel success) */
33
+ model?: string;
34
+ error?: string;
35
+ }
36
+ export declare class CdpService extends EventEmitter {
37
+ private ports;
38
+ private isConnectedFlag;
39
+ private ws;
40
+ private contexts;
41
+ private pendingCalls;
42
+ private idCounter;
43
+ private cdpCallTimeout;
44
+ private targetUrl;
45
+ /** Number of auto-reconnect attempts on disconnect */
46
+ private maxReconnectAttempts;
47
+ /** Delay between reconnect attempts (ms) */
48
+ private reconnectDelayMs;
49
+ /** Current reconnect attempt count */
50
+ private reconnectAttemptCount;
51
+ /** Reconnecting flag (prevents double connections) */
52
+ private isReconnecting;
53
+ /** Currently connected workspace name */
54
+ private currentWorkspaceName;
55
+ /** Last requested workspace path (used for deterministic reconnect) */
56
+ private currentWorkspacePath;
57
+ /** Workspace switching flag (suppresses disconnected event) */
58
+ private isSwitchingWorkspace;
59
+ constructor(options?: CdpServiceOptions);
60
+ private getJson;
61
+ discoverTarget(): Promise<string>;
62
+ connect(): Promise<void>;
63
+ call(method: string, params?: any): Promise<any>;
64
+ disconnect(): Promise<void>;
65
+ /**
66
+ * Return the currently connected workspace name.
67
+ */
68
+ getCurrentWorkspaceName(): string | null;
69
+ /**
70
+ * Discover and connect to the workbench page for the specified workspace.
71
+ * Does nothing if already connected to the correct page.
72
+ *
73
+ * @param workspacePath Full workspace path (e.g., /home/user/Code/MyProject)
74
+ * @returns true on successful connection
75
+ */
76
+ discoverAndConnectForWorkspace(workspacePath: string): Promise<boolean>;
77
+ /**
78
+ * Verify whether the currently attached page still represents the expected workspace.
79
+ */
80
+ private verifyCurrentWorkspace;
81
+ private _discoverAndConnectForWorkspaceImpl;
82
+ /**
83
+ * Connect to the specified page (skip if already connected).
84
+ */
85
+ private connectToPage;
86
+ /**
87
+ * Connect to each workbench page via CDP to get document.title and detect workspace name.
88
+ * Fallback when /json/list titles are stale or incomplete.
89
+ *
90
+ * If the title is "Untitled (Workspace)", verify workspace folder path via CDP.
91
+ *
92
+ * @param workbenchPages List of workbench pages
93
+ * @param projectName Workspace directory name
94
+ * @param workspacePath Full workspace path (for folder path matching)
95
+ */
96
+ private probeWorkbenchPages;
97
+ /**
98
+ * Check if the currently connected page has the specified workspace folder open.
99
+ * In Antigravity (VS Code-based), info may be available from explorer views or APIs.
100
+ *
101
+ * Detects folder path via multiple approaches:
102
+ * 1. Check vscode.workspace.workspaceFolders via VS Code API
103
+ * 2. Check folder path display in DOM
104
+ * 3. Get workspace info from window.location.hash, etc.
105
+ */
106
+ private probeWorkspaceFolderPath;
107
+ /**
108
+ * Launch Antigravity and wait for a new workbench page to appear, then connect.
109
+ */
110
+ private launchAndConnectWorkspace;
111
+ private runCommand;
112
+ /**
113
+ * Quietly disconnect the existing connection (no reconnect attempts).
114
+ * Used during workspace switching.
115
+ *
116
+ * Important: ws.close() fires close event asynchronously, so all listeners
117
+ * must be removed first to prevent targetUrl reset and tryReconnect()
118
+ * from reconnecting to a different workbench.
119
+ */
120
+ private disconnectQuietly;
121
+ /**
122
+ * Reject all unresolved pending calls to prevent memory leaks.
123
+ * (Step 12: Error handling)
124
+ * @param error Error to pass to reject
125
+ */
126
+ private clearPendingCalls;
127
+ /**
128
+ * Attempt auto-reconnect after CDP disconnection.
129
+ * Fires 'reconnectFailed' event after maxReconnectAttempts failures.
130
+ * (Step 12: Error handling and timeout management)
131
+ */
132
+ private tryReconnect;
133
+ isConnected(): boolean;
134
+ getContexts(): CdpContext[];
135
+ /**
136
+ * Wait by polling until cascade-panel context becomes available.
137
+ * Right after Antigravity launch, contexts are created asynchronously even after Runtime.enable,
138
+ * so use this method to confirm readiness before DOM operations.
139
+ *
140
+ * @param timeoutMs Maximum wait time (ms). Default: 10000
141
+ * @param pollIntervalMs Polling interval (ms). Default: 500
142
+ * @returns true if cascade-panel context was found
143
+ */
144
+ waitForCascadePanelReady(timeoutMs?: number, pollIntervalMs?: number): Promise<boolean>;
145
+ getPrimaryContextId(): number | null;
146
+ /**
147
+ * Focus the chat input field.
148
+ */
149
+ private focusChatInput;
150
+ /**
151
+ * Select all text in the focused input and delete it to ensure a clean state.
152
+ * Uses Meta+A (select all) then Backspace (delete) via CDP key events.
153
+ */
154
+ private clearInputField;
155
+ /**
156
+ * Send Enter key to submit the message.
157
+ */
158
+ private pressEnterToSend;
159
+ /**
160
+ * Detect file input in the UI and attach the specified files.
161
+ */
162
+ private attachImageFiles;
163
+ /**
164
+ * Inject and send the specified text into Antigravity's chat input field.
165
+ *
166
+ * Strategy:
167
+ * 1. Focus editor via Runtime.evaluate
168
+ * 2. Input text via CDP Input.insertText
169
+ * 3. Send via CDP Input.dispatchKeyEvent(Enter)
170
+ *
171
+ * Using CDP Input API instead of DOM manipulation ensures reliable
172
+ * delivery to Cascade panel's React/framework event handlers.
173
+ */
174
+ injectMessage(text: string): Promise<InjectResult>;
175
+ /**
176
+ * Attach image files to the UI and send the specified text.
177
+ */
178
+ injectMessageWithImageFiles(text: string, imageFilePaths: string[]): Promise<InjectResult>;
179
+ /**
180
+ * Extract images from the latest AI response.
181
+ */
182
+ extractLatestResponseImages(maxImages?: number): Promise<ExtractedResponseImage[]>;
183
+ /**
184
+ * Get the currently selected mode from the Antigravity UI.
185
+ * Reads the mode toggle button text and maps it back to internal mode name.
186
+ *
187
+ * @returns Internal mode name (e.g., 'fast', 'plan') or null if not found
188
+ */
189
+ getCurrentMode(): Promise<string | null>;
190
+ /**
191
+ * Operate Antigravity UI mode dropdown to switch to the specified mode.
192
+ * Two-step approach:
193
+ * Step 1: Click mode toggle button ("Fast"/"Plan" + chevron icon) to open dropdown
194
+ * Step 2: Select the target mode option from dropdown
195
+ *
196
+ * @param modeName Mode name to set (e.g., 'fast', 'plan')
197
+ */
198
+ setUiMode(modeName: string): Promise<UiSyncResult>;
199
+ /**
200
+ * Dynamically retrieve the list of available models from the Antigravity UI.
201
+ */
202
+ getUiModels(): Promise<string[]>;
203
+ /**
204
+ * Get the currently selected model from the Antigravity UI.
205
+ */
206
+ getCurrentModel(): Promise<string | null>;
207
+ /**
208
+ * Operate Antigravity UI model dropdown to switch to the specified model.
209
+ * (Step 9: Model/mode switching UI sync)
210
+ *
211
+ * @param modelName Model name to set (e.g., 'gpt-4o', 'claude-3-opus')
212
+ */
213
+ setUiModel(modelName: string): Promise<UiSyncResult>;
214
+ }