Skip to content

Commit b08c03b

Browse files
committed
Single channel extension bridge
1 parent a8f87d2 commit b08c03b

File tree

8 files changed

+144
-873
lines changed

8 files changed

+144
-873
lines changed

packages/cloud/src/bridge/BridgeOrchestrator.ts

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ import os from "os"
33

44
import {
55
type TaskProviderLike,
6-
type TaskLike,
76
type CloudUserInfo,
87
type ExtensionBridgeCommand,
9-
type TaskBridgeCommand,
108
type StaticAppProperties,
119
type GitProperties,
1210
ConnectionState,
@@ -16,7 +14,6 @@ import {
1614

1715
import { SocketTransport } from "./SocketTransport.js"
1816
import { ExtensionChannel } from "./ExtensionChannel.js"
19-
import { TaskChannel } from "./TaskChannel.js"
2017

2118
export interface BridgeOrchestratorOptions {
2219
userId: string
@@ -35,8 +32,6 @@ export interface BridgeOrchestratorOptions {
3532
export class BridgeOrchestrator {
3633
private static instance: BridgeOrchestrator | null = null
3734

38-
private static pendingTask: TaskLike | null = null
39-
4035
// Core
4136
private readonly userId: string
4237
private readonly socketBridgeUrl: string
@@ -50,7 +45,6 @@ export class BridgeOrchestrator {
5045
// Components
5146
private socketTransport: SocketTransport
5247
private extensionChannel: ExtensionChannel
53-
private taskChannel: TaskChannel
5448

5549
// Reconnection
5650
private readonly MAX_RECONNECT_ATTEMPTS = Infinity
@@ -153,22 +147,6 @@ export class BridgeOrchestrator {
153147
}
154148
}
155149

156-
/**
157-
* @TODO: What if subtasks also get spawned? We'd probably want deferred
158-
* subscriptions for those too.
159-
*/
160-
public static async subscribeToTask(task: TaskLike): Promise<void> {
161-
const instance = BridgeOrchestrator.instance
162-
163-
if (instance && instance.socketTransport.isConnected()) {
164-
console.log(`[BridgeOrchestrator#subscribeToTask] Subscribing to task ${task.taskId}`)
165-
await instance.subscribeToTask(task)
166-
} else {
167-
console.log(`[BridgeOrchestrator#subscribeToTask] Deferring subscription for task ${task.taskId}`)
168-
BridgeOrchestrator.pendingTask = task
169-
}
170-
}
171-
172150
private constructor(options: BridgeOrchestratorOptions) {
173151
this.userId = options.userId
174152
this.socketBridgeUrl = options.socketBridgeUrl
@@ -206,13 +184,6 @@ export class BridgeOrchestrator {
206184
provider: this.provider,
207185
isCloudAgent: this.isCloudAgent,
208186
})
209-
210-
this.taskChannel = new TaskChannel({
211-
instanceId: this.instanceId,
212-
appProperties: this.appProperties,
213-
gitProperties: this.gitProperties,
214-
isCloudAgent: this.isCloudAgent,
215-
})
216187
}
217188

218189
private setupSocketListeners() {
@@ -235,14 +206,6 @@ export class BridgeOrchestrator {
235206

236207
this.extensionChannel?.handleCommand(message)
237208
})
238-
239-
socket.on(TaskSocketEvents.RELAYED_COMMAND, (message: TaskBridgeCommand) => {
240-
console.log(
241-
`[BridgeOrchestrator] on(${TaskSocketEvents.RELAYED_COMMAND}) -> ${message.type} for ${message.taskId}`,
242-
)
243-
244-
this.taskChannel.handleCommand(message)
245-
})
246209
}
247210

248211
private async handleConnect() {
@@ -254,27 +217,10 @@ export class BridgeOrchestrator {
254217
}
255218

256219
await this.extensionChannel.onConnect(socket)
257-
await this.taskChannel.onConnect(socket)
258-
259-
if (BridgeOrchestrator.pendingTask) {
260-
console.log(
261-
`[BridgeOrchestrator#handleConnect] Subscribing to task ${BridgeOrchestrator.pendingTask.taskId}`,
262-
)
263-
264-
try {
265-
await this.subscribeToTask(BridgeOrchestrator.pendingTask)
266-
BridgeOrchestrator.pendingTask = null
267-
} catch (error) {
268-
console.error(
269-
`[BridgeOrchestrator#handleConnect] subscribeToTask() failed: ${error instanceof Error ? error.message : String(error)}`,
270-
)
271-
}
272-
}
273220
}
274221

275222
private handleDisconnect() {
276223
this.extensionChannel.onDisconnect()
277-
this.taskChannel.onDisconnect()
278224
}
279225

280226
private async handleReconnect() {
@@ -291,39 +237,6 @@ export class BridgeOrchestrator {
291237
this.setupSocketListeners()
292238

293239
await this.extensionChannel.onReconnect(socket)
294-
await this.taskChannel.onReconnect(socket)
295-
}
296-
297-
// Task API
298-
299-
public async subscribeToTask(task: TaskLike): Promise<void> {
300-
const socket = this.socketTransport.getSocket()
301-
302-
if (!socket || !this.socketTransport.isConnected()) {
303-
console.warn("[BridgeOrchestrator] Cannot subscribe to task: not connected. Will retry when connected.")
304-
this.taskChannel.addPendingTask(task)
305-
306-
if (
307-
this.connectionState === ConnectionState.DISCONNECTED ||
308-
this.connectionState === ConnectionState.FAILED
309-
) {
310-
await this.connect()
311-
}
312-
313-
return
314-
}
315-
316-
await this.taskChannel.subscribeToTask(task, socket)
317-
}
318-
319-
public async unsubscribeFromTask(taskId: string): Promise<void> {
320-
const socket = this.socketTransport.getSocket()
321-
322-
if (!socket) {
323-
return
324-
}
325-
326-
await this.taskChannel.unsubscribeFromTask(taskId, socket)
327240
}
328241

329242
// Shared API
@@ -339,10 +252,8 @@ export class BridgeOrchestrator {
339252

340253
public async disconnect(): Promise<void> {
341254
await this.extensionChannel.cleanup(this.socketTransport.getSocket())
342-
await this.taskChannel.cleanup(this.socketTransport.getSocket())
343255
await this.socketTransport.disconnect()
344256
BridgeOrchestrator.instance = null
345-
BridgeOrchestrator.pendingTask = null
346257
}
347258

348259
public async reconnect(): Promise<void> {

packages/cloud/src/bridge/ExtensionChannel.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,36 @@ export class ExtensionChannel extends BaseChannel<
174174
}
175175

176176
private setupListeners(): void {
177+
// private readonly eventMapping: readonly TaskEventMapping[] = [
178+
// {
179+
// from: RooCodeEventName.Message,
180+
// to: TaskBridgeEventName.Message,
181+
// createPayload: (task: TaskLike, data: { action: string; message: ClineMessage }) => ({
182+
// type: TaskBridgeEventName.Message,
183+
// taskId: task.taskId,
184+
// action: data.action,
185+
// message: data.message,
186+
// }),
187+
// },
188+
// {
189+
// from: RooCodeEventName.TaskModeSwitched,
190+
// to: TaskBridgeEventName.TaskModeSwitched,
191+
// createPayload: (task: TaskLike, mode: string) => ({
192+
// type: TaskBridgeEventName.TaskModeSwitched,
193+
// taskId: task.taskId,
194+
// mode,
195+
// }),
196+
// },
197+
// {
198+
// from: RooCodeEventName.TaskInteractive,
199+
// to: TaskBridgeEventName.TaskInteractive,
200+
// createPayload: (task: TaskLike, _taskId: string) => ({
201+
// type: TaskBridgeEventName.TaskInteractive,
202+
// taskId: task.taskId,
203+
// }),
204+
// },
205+
// ] as const
206+
177207
const eventMapping = [
178208
{ from: RooCodeEventName.TaskCreated, to: ExtensionBridgeEventName.TaskCreated },
179209
{ from: RooCodeEventName.TaskStarted, to: ExtensionBridgeEventName.TaskStarted },

0 commit comments

Comments
 (0)