Skip to content

Commit 12d1959

Browse files
authored
Switch to the UnifiedBridgeService (#6976)
1 parent 5f3c67f commit 12d1959

File tree

6 files changed

+101
-70
lines changed

6 files changed

+101
-70
lines changed

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/link-packages.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,54 @@ if (!unlink && watch) {
5858
}
5959
}
6060

61+
function generateNpmPackageJson(sourcePath, npmPath) {
62+
const npmDir = path.join(sourcePath, npmPath)
63+
const npmPackagePath = path.join(npmDir, "package.json")
64+
const npmMetadataPath = path.join(npmDir, "package.metadata.json")
65+
const monorepoPackagePath = path.join(sourcePath, "package.json")
66+
67+
if (fs.existsSync(npmPackagePath)) {
68+
console.log(` ✓ npm/package.json already exists`)
69+
return
70+
}
71+
72+
if (!fs.existsSync(npmMetadataPath)) {
73+
console.log(` ⚠ No package.metadata.json found, skipping npm package.json generation`)
74+
return
75+
}
76+
77+
try {
78+
console.log(` 📦 Generating npm/package.json...`)
79+
const monorepoPackage = JSON.parse(fs.readFileSync(monorepoPackagePath, "utf8"))
80+
const npmMetadata = JSON.parse(fs.readFileSync(npmMetadataPath, "utf8"))
81+
82+
const npmPackage = {
83+
...npmMetadata,
84+
type: "module",
85+
dependencies: monorepoPackage.dependencies || {},
86+
main: "./dist/index.cjs",
87+
module: "./dist/index.js",
88+
types: "./dist/index.d.ts",
89+
exports: {
90+
".": {
91+
types: "./dist/index.d.ts",
92+
import: "./dist/index.js",
93+
require: {
94+
types: "./dist/index.d.cts",
95+
default: "./dist/index.cjs",
96+
},
97+
},
98+
},
99+
files: ["dist"],
100+
}
101+
102+
fs.writeFileSync(npmPackagePath, JSON.stringify(npmPackage, null, 2) + "\n")
103+
console.log(` ✓ Generated npm/package.json for ${npmPackage.name}`)
104+
} catch (error) {
105+
console.error(` ✗ Failed to generate npm/package.json: ${error.message}`)
106+
}
107+
}
108+
61109
function linkPackage(pkg) {
62110
const sourcePath = path.resolve(__dirname, "..", pkg.sourcePath)
63111
const targetPath = path.resolve(__dirname, "..", pkg.targetPath)
@@ -78,6 +126,11 @@ function linkPackage(pkg) {
78126
}
79127
}
80128

129+
// If npmPath is specified, check if we need to generate package.json.
130+
if (pkg.npmPath) {
131+
generateNpmPackageJson(sourcePath, pkg.npmPath)
132+
}
133+
81134
// Create symlink.
82135
fs.rmSync(targetPath, { recursive: true, force: true })
83136
fs.mkdirSync(path.dirname(targetPath), { recursive: true })

src/core/task/Task.ts

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
isBlockingAsk,
3434
} from "@roo-code/types"
3535
import { TelemetryService } from "@roo-code/telemetry"
36-
import { CloudService, TaskBridgeService } from "@roo-code/cloud"
36+
import { CloudService, UnifiedBridgeService } from "@roo-code/cloud"
3737

3838
// api
3939
import { ApiHandler, ApiHandlerCreateMessageMetadata, buildApiHandler } from "../../api"
@@ -241,7 +241,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
241241

242242
// Task Bridge
243243
enableTaskBridge: boolean
244-
taskBridgeService: TaskBridgeService | null = null
244+
bridgeService: UnifiedBridgeService | null = null
245245

246246
// Streaming
247247
isWaitingForFirstChunk = false
@@ -980,19 +980,17 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
980980
// Start / Abort / Resume
981981

982982
private async startTask(task?: string, images?: string[]): Promise<void> {
983-
if (this.enableTaskBridge && CloudService.hasInstance()) {
984-
if (!this.taskBridgeService) {
985-
const bridgeConfig = await CloudService.instance.cloudAPI?.bridgeConfig().catch(() => undefined)
983+
if (this.enableTaskBridge) {
984+
try {
985+
this.bridgeService = this.bridgeService || UnifiedBridgeService.getInstance()
986986

987-
if (bridgeConfig) {
988-
this.taskBridgeService = await TaskBridgeService.createInstance({
989-
...bridgeConfig,
990-
})
987+
if (this.bridgeService) {
988+
await this.bridgeService.subscribeToTask(this)
991989
}
992-
}
993-
994-
if (this.taskBridgeService) {
995-
await this.taskBridgeService.subscribeToTask(this)
990+
} catch (error) {
991+
console.error(
992+
`[Task#startTask] subscribeToTask failed - ${error instanceof Error ? error.message : String(error)}`,
993+
)
996994
}
997995
}
998996

@@ -1047,19 +1045,17 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
10471045
}
10481046

10491047
private async resumeTaskFromHistory() {
1050-
if (this.enableTaskBridge && CloudService.hasInstance()) {
1051-
if (!this.taskBridgeService) {
1052-
const bridgeConfig = await CloudService.instance.cloudAPI?.bridgeConfig().catch(() => undefined)
1048+
if (this.enableTaskBridge) {
1049+
try {
1050+
this.bridgeService = this.bridgeService || UnifiedBridgeService.getInstance()
10531051

1054-
if (bridgeConfig) {
1055-
this.taskBridgeService = await TaskBridgeService.createInstance({
1056-
...bridgeConfig,
1057-
})
1052+
if (this.bridgeService) {
1053+
await this.bridgeService.subscribeToTask(this)
10581054
}
1059-
}
1060-
1061-
if (this.taskBridgeService) {
1062-
await this.taskBridgeService.subscribeToTask(this)
1055+
} catch (error) {
1056+
console.error(
1057+
`[Task#resumeTaskFromHistory] subscribeToTask failed - ${error instanceof Error ? error.message : String(error)}`,
1058+
)
10631059
}
10641060
}
10651061

@@ -1309,11 +1305,11 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
13091305
}
13101306

13111307
// Unsubscribe from TaskBridge service.
1312-
if (this.taskBridgeService) {
1313-
this.taskBridgeService
1308+
if (this.bridgeService) {
1309+
this.bridgeService
13141310
.unsubscribeFromTask(this.taskId)
13151311
.catch((error) => console.error("Error unsubscribing from task bridge:", error))
1316-
this.taskBridgeService = null
1312+
this.bridgeService = null
13171313
}
13181314

13191315
// Release any terminals associated with this task.

src/core/webview/ClineProvider.ts

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,75 +2134,58 @@ export class ClineProvider
21342134

21352135
/**
21362136
* Handle remote control enabled/disabled state changes
2137-
* Manages ExtensionBridgeService and TaskBridgeService lifecycle
2137+
* Manages UnifiedBridgeService lifecycle
21382138
*/
21392139
public async handleRemoteControlToggle(enabled: boolean) {
2140-
const {
2141-
CloudService: CloudServiceImport,
2142-
ExtensionBridgeService,
2143-
TaskBridgeService,
2144-
} = await import("@roo-code/cloud")
2140+
const { CloudService: CloudServiceImport, UnifiedBridgeService } = await import("@roo-code/cloud")
21452141

21462142
const userInfo = CloudServiceImport.instance.getUserInfo()
21472143

21482144
const bridgeConfig = await CloudServiceImport.instance.cloudAPI?.bridgeConfig().catch(() => undefined)
21492145

21502146
if (!bridgeConfig) {
2151-
this.log("[CloudService] Failed to get bridge config")
2147+
this.log("[ClineProvider#handleRemoteControlToggle] Failed to get bridge config")
21522148
return
21532149
}
21542150

2155-
ExtensionBridgeService.handleRemoteControlState(
2151+
await UnifiedBridgeService.handleRemoteControlState(
21562152
userInfo,
21572153
enabled,
21582154
{ ...bridgeConfig, provider: this },
21592155
(message: string) => this.log(message),
21602156
)
21612157

21622158
if (isRemoteControlEnabled(userInfo, enabled)) {
2163-
// Set up TaskBridgeService for the currently active task if one exists.
21642159
const currentTask = this.getCurrentCline()
21652160

2166-
if (currentTask && !currentTask.taskBridgeService && CloudService.hasInstance()) {
2161+
if (currentTask && !currentTask.bridgeService) {
21672162
try {
2168-
if (!currentTask.taskBridgeService) {
2169-
const bridgeConfig = await CloudService.instance.cloudAPI?.bridgeConfig().catch(() => undefined)
2170-
2171-
if (bridgeConfig) {
2172-
currentTask.taskBridgeService = await TaskBridgeService.createInstance({
2173-
...bridgeConfig,
2174-
})
2175-
}
2176-
}
2163+
currentTask.bridgeService = UnifiedBridgeService.getInstance()
21772164

2178-
if (currentTask.taskBridgeService) {
2179-
await currentTask.taskBridgeService.subscribeToTask(currentTask)
2165+
if (currentTask.bridgeService) {
2166+
await currentTask.bridgeService.subscribeToTask(currentTask)
21802167
}
2181-
2182-
this.log(`[TaskBridgeService] Subscribed current task ${currentTask.taskId} to TaskBridge`)
21832168
} catch (error) {
2184-
const message = `[TaskBridgeService#subscribeToTask] ${error instanceof Error ? error.message : String(error)}`
2169+
const message = `[ClineProvider#handleRemoteControlToggle] subscribeToTask failed - ${error instanceof Error ? error.message : String(error)}`
21852170
this.log(message)
21862171
console.error(message)
21872172
}
21882173
}
21892174
} else {
2190-
// Disconnect TaskBridgeService for all tasks in the stack.
21912175
for (const task of this.clineStack) {
2192-
if (task.taskBridgeService) {
2176+
if (task.bridgeService) {
21932177
try {
2194-
await task.taskBridgeService.unsubscribeFromTask(task.taskId)
2195-
task.taskBridgeService = null
2196-
this.log(`[TaskBridgeService] Unsubscribed task ${task.taskId} from TaskBridge`)
2178+
await task.bridgeService.unsubscribeFromTask(task.taskId)
2179+
task.bridgeService = null
21972180
} catch (error) {
2198-
const message = `[TaskBridgeService#unsubscribeFromTask] for task ${task.taskId}: ${error instanceof Error ? error.message : String(error)}`
2181+
const message = `[ClineProvider#handleRemoteControlToggle] unsubscribeFromTask failed - ${error instanceof Error ? error.message : String(error)}`
21992182
this.log(message)
22002183
console.error(message)
22012184
}
22022185
}
22032186
}
22042187

2205-
TaskBridgeService.resetInstance()
2188+
UnifiedBridgeService.resetInstance()
22062189
}
22072190
}
22082191

src/extension.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ try {
1212
console.warn("Failed to load environment variables:", e)
1313
}
1414

15-
import { CloudService, ExtensionBridgeService } from "@roo-code/cloud"
15+
import { CloudService, UnifiedBridgeService } from "@roo-code/cloud"
1616
import { TelemetryService, PostHogTelemetryClient } from "@roo-code/telemetry"
1717

1818
import "./utils/path" // Necessary to have access to String.prototype.toPosix.
@@ -141,7 +141,7 @@ export async function activate(context: vscode.ExtensionContext) {
141141
return
142142
}
143143

144-
ExtensionBridgeService.handleRemoteControlState(
144+
UnifiedBridgeService.handleRemoteControlState(
145145
userInfo,
146146
contextProxy.getValue("remoteControlEnabled"),
147147
{ ...bridgeConfig, provider },
@@ -280,11 +280,10 @@ export async function activate(context: vscode.ExtensionContext) {
280280
export async function deactivate() {
281281
outputChannel.appendLine(`${Package.name} extension deactivated`)
282282

283-
// Cleanup Extension Bridge service.
284-
const extensionBridgeService = ExtensionBridgeService.getInstance()
283+
const bridgeService = UnifiedBridgeService.getInstance()
285284

286-
if (extensionBridgeService) {
287-
await extensionBridgeService.disconnect()
285+
if (bridgeService) {
286+
await bridgeService.disconnect()
288287
}
289288

290289
await McpServerManager.cleanup(extensionContext)

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@
420420
"@mistralai/mistralai": "^1.3.6",
421421
"@modelcontextprotocol/sdk": "^1.9.0",
422422
"@qdrant/js-client-rest": "^1.14.0",
423-
"@roo-code/cloud": "^0.10.0",
423+
"@roo-code/cloud": "^0.11.0",
424424
"@roo-code/ipc": "workspace:^",
425425
"@roo-code/telemetry": "workspace:^",
426426
"@roo-code/types": "workspace:^",

0 commit comments

Comments
 (0)