Skip to content

Commit b011b63

Browse files
authored
Identify cloud tasks in the extension bridge (#8539)
1 parent eeaafef commit b011b63

File tree

9 files changed

+31
-8
lines changed

9 files changed

+31
-8
lines changed

packages/cloud/src/CloudService.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ export class CloudService extends EventEmitter<CloudServiceEvents> implements Di
8383
return this._retryQueue
8484
}
8585

86+
private _isCloudAgent = false
87+
88+
public get isCloudAgent() {
89+
return this._isCloudAgent
90+
}
91+
8692
private constructor(context: ExtensionContext, log?: (...args: unknown[]) => void) {
8793
super()
8894

@@ -117,6 +123,7 @@ export class CloudService extends EventEmitter<CloudServiceEvents> implements Di
117123

118124
if (cloudToken && cloudToken.length > 0) {
119125
this._authService = new StaticTokenAuthService(this.context, cloudToken, this.log)
126+
this._isCloudAgent = true
120127
} else {
121128
this._authService = new WebAuthService(this.context, this.log)
122129
}
@@ -141,19 +148,19 @@ export class CloudService extends EventEmitter<CloudServiceEvents> implements Di
141148

142149
this._cloudAPI = new CloudAPI(this._authService, this.log)
143150

144-
// Initialize retry queue with auth header provider
151+
// Initialize retry queue with auth header provider.
145152
this._retryQueue = new RetryQueue(
146153
this.context,
147-
undefined, // Use default config
154+
undefined, // Use default config.
148155
this.log,
149156
() => {
150-
// Provide fresh auth headers for retries
157+
// Provide fresh auth headers for retries.
151158
const sessionToken = this._authService?.getSessionToken()
159+
152160
if (sessionToken) {
153-
return {
154-
Authorization: `Bearer ${sessionToken}`,
155-
}
161+
return { Authorization: `Bearer ${sessionToken}` }
156162
}
163+
157164
return undefined
158165
},
159166
)

packages/cloud/src/bridge/BaseChannel.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface BaseChannelOptions {
77
instanceId: string
88
appProperties: StaticAppProperties
99
gitProperties?: GitProperties
10+
isCloudAgent: boolean
1011
}
1112

1213
/**
@@ -22,11 +23,13 @@ export abstract class BaseChannel<TCommand = unknown, TEventName extends string
2223
protected readonly instanceId: string
2324
protected readonly appProperties: StaticAppProperties
2425
protected readonly gitProperties?: GitProperties
26+
protected readonly isCloudAgent: boolean
2527

2628
constructor(options: BaseChannelOptions) {
2729
this.instanceId = options.instanceId
2830
this.appProperties = options.appProperties
2931
this.gitProperties = options.gitProperties
32+
this.isCloudAgent = options.isCloudAgent
3033
}
3134

3235
/**

packages/cloud/src/bridge/BridgeOrchestrator.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export interface BridgeOrchestratorOptions {
2323
socketBridgeUrl: string
2424
token: string
2525
provider: TaskProviderLike
26-
sessionId?: string
26+
sessionId: string
27+
isCloudAgent: boolean
2728
}
2829

2930
/**
@@ -44,6 +45,7 @@ export class BridgeOrchestrator {
4445
private readonly instanceId: string
4546
private readonly appProperties: StaticAppProperties
4647
private readonly gitProperties?: GitProperties
48+
private readonly isCloudAgent?: boolean
4749

4850
// Components
4951
private socketTransport: SocketTransport
@@ -96,6 +98,7 @@ export class BridgeOrchestrator {
9698
if (!instance) {
9799
try {
98100
console.log(`[BridgeOrchestrator#connectOrDisconnect] Connecting...`)
101+
99102
// Populate telemetry properties before registering the instance.
100103
await options.provider.getTelemetryProperties()
101104

@@ -174,6 +177,7 @@ export class BridgeOrchestrator {
174177
this.instanceId = options.sessionId || crypto.randomUUID()
175178
this.appProperties = { ...options.provider.appProperties, hostname: os.hostname() }
176179
this.gitProperties = options.provider.gitProperties
180+
this.isCloudAgent = options.isCloudAgent
177181

178182
this.socketTransport = new SocketTransport({
179183
url: this.socketBridgeUrl,
@@ -200,12 +204,14 @@ export class BridgeOrchestrator {
200204
gitProperties: this.gitProperties,
201205
userId: this.userId,
202206
provider: this.provider,
207+
isCloudAgent: this.isCloudAgent,
203208
})
204209

205210
this.taskChannel = new TaskChannel({
206211
instanceId: this.instanceId,
207212
appProperties: this.appProperties,
208213
gitProperties: this.gitProperties,
214+
isCloudAgent: this.isCloudAgent,
209215
})
210216
}
211217

packages/cloud/src/bridge/ExtensionChannel.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export class ExtensionChannel extends BaseChannel<
4141
instanceId: options.instanceId,
4242
appProperties: options.appProperties,
4343
gitProperties: options.gitProperties,
44+
isCloudAgent: options.isCloudAgent,
4445
})
4546

4647
this.userId = options.userId
@@ -55,6 +56,7 @@ export class ExtensionChannel extends BaseChannel<
5556
lastHeartbeat: Date.now(),
5657
task: { taskId: "", taskStatus: TaskStatus.None },
5758
taskHistory: [],
59+
isCloudAgent: this.isCloudAgent,
5860
}
5961

6062
this.setupListeners()

packages/cloud/src/bridge/__tests__/ExtensionChannel.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ describe("ExtensionChannel", () => {
9595
appProperties,
9696
userId,
9797
provider: mockProvider,
98+
isCloudAgent: false,
9899
})
99100
})
100101

@@ -176,6 +177,7 @@ describe("ExtensionChannel", () => {
176177
appProperties,
177178
userId,
178179
provider: mockProvider,
180+
isCloudAgent: false,
179181
})
180182

181183
// Each event should have exactly 2 listeners (one from each channel)

packages/cloud/src/bridge/__tests__/TaskChannel.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ describe("TaskChannel", () => {
8888
taskChannel = new TaskChannel({
8989
instanceId,
9090
appProperties,
91+
isCloudAgent: false,
9192
})
9293
})
9394

packages/types/npm/package.metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@roo-code/types",
3-
"version": "1.82.0",
3+
"version": "1.83.0",
44
"description": "TypeScript type definitions for Roo Code.",
55
"publishConfig": {
66
"access": "public",

packages/types/src/cloud.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ export const extensionInstanceSchema = z.object({
411411
modes: z.array(z.object({ slug: z.string(), name: z.string() })).optional(),
412412
providerProfile: z.string().optional(),
413413
providerProfiles: z.array(z.object({ name: z.string(), provider: z.string().optional() })).optional(),
414+
isCloudAgent: z.boolean().optional(),
414415
})
415416

416417
export type ExtensionInstance = z.infer<typeof extensionInstanceSchema>

src/core/webview/ClineProvider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,6 +2343,7 @@ export class ClineProvider
23432343
...config,
23442344
provider: this,
23452345
sessionId: vscode.env.sessionId,
2346+
isCloudAgent: CloudService.instance.isCloudAgent,
23462347
})
23472348

23482349
const bridge = BridgeOrchestrator.getInstance()

0 commit comments

Comments
 (0)