Skip to content

Commit 14d5eba

Browse files
committed
PR feedback
1 parent a1f98f9 commit 14d5eba

File tree

4 files changed

+14
-22
lines changed

4 files changed

+14
-22
lines changed

packages/cloud/src/CloudAPI.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
type ShareResponse,
77
shareResponseSchema,
88
type CloudAgent,
9+
cloudAgentsResponseSchema,
910
} from "@roo-code/types"
1011

1112
import { getRooCodeApiUrl } from "./config.js"
@@ -144,11 +145,12 @@ export class CloudAPI {
144145
async getCloudAgents(): Promise<CloudAgent[]> {
145146
this.log("[CloudAPI] Fetching cloud agents")
146147

147-
const response = await this.request<{ success: boolean; data: CloudAgent[] }>("/api/cloud-agents", {
148+
const agents = await this.request<CloudAgent[]>("/api/cloud-agents", {
148149
method: "GET",
150+
parseResponse: (data) => cloudAgentsResponseSchema.parse(data).data,
149151
})
150152

151-
this.log("[CloudAPI] Cloud agents response:", response)
152-
return response.data || []
153+
this.log("[CloudAPI] Cloud agents response:", agents)
154+
return agents
153155
}
154156
}

packages/cloud/src/__tests__/CloudAPI.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe("CloudAPI", () => {
2727
{ id: "2", name: "Agent 2", type: "chat", icon: "chat" },
2828
]
2929

30-
// Mock successful response
30+
// Mock successful response with schema-compliant format
3131
;(global.fetch as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
3232
ok: true,
3333
json: async () => ({ success: true, data: mockAgents }),
@@ -66,11 +66,11 @@ describe("CloudAPI", () => {
6666
await expect(cloudAPI.getCloudAgents()).rejects.toThrow(AuthenticationError)
6767
})
6868

69-
it("should return empty array when data is missing", async () => {
70-
// Mock response with no data
69+
it("should return empty array when agents array is empty", async () => {
70+
// Mock response with empty agents array
7171
;(global.fetch as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
7272
ok: true,
73-
json: async () => ({ success: true }),
73+
json: async () => ({ success: true, data: [] }),
7474
})
7575

7676
const agents = await cloudAPI.getCloudAgents()

packages/types/src/cloud.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,8 @@ export interface CloudAgent {
739739
*/
740740

741741
export const cloudAgentsResponseSchema = z.object({
742-
agents: z.array(
742+
success: z.boolean(),
743+
data: z.array(
743744
z.object({
744745
id: z.string(),
745746
name: z.string(),

src/core/webview/webviewMessageHandler.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,24 +2470,13 @@ export const webviewMessageHandler = async (
24702470
`[getCloudAgents] Error fetching cloud agents: ${error instanceof Error ? error.message : String(error)}`,
24712471
)
24722472

2473-
// Check if it's an authentication error
2474-
const errorMessage = error instanceof Error ? error.message : String(error)
2475-
const isAuthError = errorMessage.includes("Authentication") || errorMessage.includes("401")
2476-
2477-
// Send empty array with error information
2473+
// Send response to stop loading state in UI
2474+
// The CloudAgents component will handle this gracefully by returning null
24782475
await provider.postMessageToWebview({
24792476
type: "cloudAgents",
24802477
agents: [],
2481-
error: errorMessage,
2478+
error: error instanceof Error ? error.message : String(error),
24822479
})
2483-
2484-
// If it's an authentication error, show a user-friendly message
2485-
if (isAuthError) {
2486-
vscode.window.showErrorMessage(
2487-
t("common:errors.auth_required_for_cloud_agents") ||
2488-
"Authentication required to access cloud agents",
2489-
)
2490-
}
24912480
}
24922481
break
24932482
}

0 commit comments

Comments
 (0)