@@ -107,6 +107,7 @@ export type TaskOptions = {
107107 apiConfiguration : ProviderSettings
108108 enableDiff ?: boolean
109109 enableCheckpoints ?: boolean
110+ enableTaskBridge ?: boolean
110111 fuzzyMatchThreshold ?: number
111112 consecutiveMistakeLimit ?: number
112113 task ?: string
@@ -118,7 +119,6 @@ export type TaskOptions = {
118119 parentTask ?: Task
119120 taskNumber ?: number
120121 onCreated ?: ( task : Task ) => void
121- enableTaskBridge ?: boolean
122122}
123123
124124export class Task extends EventEmitter < TaskEvents > implements TaskLike {
@@ -239,7 +239,8 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
239239 checkpointServiceInitializing = false
240240
241241 // Task Bridge
242- taskBridgeService ?: TaskBridgeService
242+ enableTaskBridge : boolean
243+ taskBridgeService : TaskBridgeService | null = null
243244
244245 // Streaming
245246 isWaitingForFirstChunk = false
@@ -264,6 +265,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
264265 apiConfiguration,
265266 enableDiff = false ,
266267 enableCheckpoints = true ,
268+ enableTaskBridge = false ,
267269 fuzzyMatchThreshold = 1.0 ,
268270 consecutiveMistakeLimit = DEFAULT_CONSECUTIVE_MISTAKE_LIMIT ,
269271 task,
@@ -274,7 +276,6 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
274276 parentTask,
275277 taskNumber = - 1 ,
276278 onCreated,
277- enableTaskBridge = false ,
278279 } : TaskOptions ) {
279280 super ( )
280281
@@ -313,6 +314,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
313314 this . globalStoragePath = provider . context . globalStorageUri . fsPath
314315 this . diffViewProvider = new DiffViewProvider ( this . cwd , this )
315316 this . enableCheckpoints = enableCheckpoints
317+ this . enableTaskBridge = enableTaskBridge
316318
317319 this . rootTask = rootTask
318320 this . parentTask = parentTask
@@ -352,11 +354,6 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
352354
353355 this . toolRepetitionDetector = new ToolRepetitionDetector ( this . consecutiveMistakeLimit )
354356
355- // Initialize TaskBridgeService only if enabled
356- if ( enableTaskBridge ) {
357- this . taskBridgeService = TaskBridgeService . getInstance ( )
358- }
359-
360357 onCreated ?.( this )
361358
362359 if ( startTask ) {
@@ -982,9 +979,20 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
982979 // Start / Abort / Resume
983980
984981 private async startTask ( task ?: string , images ?: string [ ] ) : Promise < void > {
985- if ( this . taskBridgeService ) {
986- await this . taskBridgeService . initialize ( )
987- await this . taskBridgeService . subscribeToTask ( this )
982+ if ( this . enableTaskBridge && CloudService . hasInstance ( ) ) {
983+ if ( ! this . taskBridgeService ) {
984+ const bridgeConfig = await CloudService . instance . cloudAPI ?. bridgeConfig ( )
985+
986+ if ( bridgeConfig ) {
987+ this . taskBridgeService = await TaskBridgeService . createInstance ( {
988+ ...bridgeConfig ,
989+ } )
990+ }
991+ }
992+
993+ if ( this . taskBridgeService ) {
994+ await this . taskBridgeService . subscribeToTask ( this )
995+ }
988996 }
989997
990998 // `conversationHistory` (for API) and `clineMessages` (for webview)
@@ -1038,9 +1046,20 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
10381046 }
10391047
10401048 private async resumeTaskFromHistory ( ) {
1041- if ( this . taskBridgeService ) {
1042- await this . taskBridgeService . initialize ( )
1043- await this . taskBridgeService . subscribeToTask ( this )
1049+ if ( this . enableTaskBridge && CloudService . hasInstance ( ) ) {
1050+ if ( ! this . taskBridgeService ) {
1051+ const bridgeConfig = await CloudService . instance . cloudAPI ?. bridgeConfig ( )
1052+
1053+ if ( bridgeConfig ) {
1054+ this . taskBridgeService = await TaskBridgeService . createInstance ( {
1055+ ...bridgeConfig ,
1056+ } )
1057+ }
1058+ }
1059+
1060+ if ( this . taskBridgeService ) {
1061+ await this . taskBridgeService . subscribeToTask ( this )
1062+ }
10441063 }
10451064
10461065 const modifiedClineMessages = await this . getSavedClineMessages ( )
@@ -1293,6 +1312,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
12931312 this . taskBridgeService
12941313 . unsubscribeFromTask ( this . taskId )
12951314 . catch ( ( error ) => console . error ( "Error unsubscribing from task bridge:" , error ) )
1315+ this . taskBridgeService = null
12961316 }
12971317
12981318 // Release any terminals associated with this task.
0 commit comments